home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff226.lzh / Vlt / xprlib / comm-program / xprfuncs.c < prev   
C/C++ Source or Header  |  1989-06-25  |  5KB  |  238 lines

  1. /** xprfuncs.c
  2. *
  3. *   Call-back functions for eXternal PRotocol support
  4. *
  5. **/
  6. #include <functions.h>
  7. #include <exec/exec.h>
  8. #include <stdio.h>
  9. /*
  10. *   xproto.h is given in Appendix B
  11. */
  12. #include "xproto.h"
  13. /*
  14. *   xfer.h is a VLT private header file containing some information for
  15. *   file transfer protocols
  16. */
  17. #include "xfer.h"
  18.  
  19. /*
  20. *   These are the C versions of the interface
  21. */
  22. long        vlt_update(),  vlt_swrite(),  vlt_fread(),  vlt_fopen(),
  23.             vlt_fclose(),  vlt_gets(),    vlt_sread(),  vlt_chkabort();
  24. /*
  25. *   These are the assembly level glue functions, see vltface.asm
  26. */
  27. extern long avlt_update(), avlt_swrite(), avlt_fread(), avlt_fopen(),
  28.             avlt_fclose(), avlt_gets(),   avlt_sread(), avlt_chkabort();
  29.  
  30. /**
  31. *
  32. *   This function initializes an XPR_IO structure.
  33. *
  34. **/
  35. xpr_setup(IO)
  36. struct XPR_IO *IO;
  37. {
  38. /*
  39. *   NULL out all the functions we don't do yet.
  40. *   Fill the other ones with the addresses to the assembler glue version
  41. *   of the interface routines. See vltface.asm
  42. */
  43.    IO->xpr_filename  = NULL;
  44.    IO->xpr_fopen     = avlt_fopen;
  45.    IO->xpr_fclose    = avlt_fclose;
  46.    IO->xpr_fread     = avlt_fread;
  47.    IO->xpr_fwrite    = NULL;
  48.    IO->xpr_sread     = avlt_sread;
  49.    IO->xpr_swrite    = avlt_swrite;
  50.    IO->xpr_sflush    = NULL;
  51.    IO->xpr_update    = avlt_update;
  52.    IO->xpr_chkabort  = avlt_chkabort;
  53.    IO->xpr_chkmisc   = NULL;
  54.    IO->xpr_gets      = avlt_gets;
  55.    IO->xpr_setserial = NULL;
  56.    IO->xpr_ffirst    = NULL;
  57.    IO->xpr_fnext     = NULL;
  58.    IO->xpr_finfo     = NULL;
  59.    IO->xpr_reserved1 = NULL;
  60.    IO->xpr_reserved2 = NULL;
  61. /*
  62. *   Especially, NULL out the XPR private data field.
  63. */
  64.    IO->xpr_data      = NULL;
  65.  
  66.    return;
  67. }
  68.  
  69. /**
  70. *
  71. *   Interface to VLT's MsgDisplay() function.
  72. *
  73. **/
  74. /*
  75. *   These are formats for VLT's requester
  76. */
  77. static char *xprnamfmt = "%s\n%s\n\n\n\n";
  78. static char *filnamfmt = "\n\n%s\n\n\n";
  79. static char *blksizfmt = "\n\n\n\nBlock:  %6ld  --  Block Size:  %6ld\n";
  80. static char *errtimfmt = "\n\n\n\n\nErrors: %6ld  --  Timeouts:    %6ld";
  81. static char *delayfmt  = "\n\n\n\n\nPacket delay %ld";
  82. /*
  83. *   Below are some VLT globals to orchestrate the display
  84. */
  85. long xpr_blocks = 0L, xpr_blocksize = 0L, xpr_errors = 0L, xpr_timeouts = 0L;
  86. /*
  87. *   The function
  88. */
  89. long vlt_update(x)
  90. struct XPR_UPDATE *x;
  91. {
  92.    extern struct Window *mywindow;
  93.    extern char *XPR_Name;
  94. /*
  95. *   First time, determine the window size (50 chars wide, 5 lines tall).
  96. */
  97.    SetMsgWindow(mywindow, 50, 6);
  98. /*
  99. *   Use VLT's PostMsg function to display all the information.
  100. */
  101.    if (x->xpru_updatemask & XPRU_PROTOCOL) {
  102.       PostMsg(mywindow, xprnamfmt, XPR_Name, x->xpru_protocol);
  103.    }
  104.    if (x->xpru_updatemask & XPRU_MSG) {
  105.       PostMsg(mywindow, xprnamfmt, XPR_Name, x->xpru_msg);
  106.    }
  107.    if (x->xpru_updatemask & XPRU_ERRORMSG) {
  108.       PostMsg(mywindow, xprnamfmt, XPR_Name, x->xpru_errormsg);
  109.    }
  110.    if (x->xpru_updatemask & XPRU_FILENAME) {
  111.       PostMsg(mywindow, filnamfmt, x->xpru_filename);
  112.    }
  113.    if (x->xpru_updatemask & XPRU_PACKETDELAY) {
  114.       PostMsg(mywindow, delayfmt, x->xpru_packetdelay);
  115.    }
  116.    if (x->xpru_updatemask & (XPRU_BLOCKS | XPRU_BLOCKSIZE)) {
  117.       if (x->xpru_updatemask & XPRU_BLOCKS)    xpr_blocks    = x->xpru_blocks;
  118.       if (x->xpru_updatemask & XPRU_BLOCKSIZE) xpr_blocksize = x->xpru_blocksize;
  119.       PostMsg(mywindow, blksizfmt, xpr_blocks, xpr_blocksize);
  120.    }
  121.    if (x->xpru_updatemask & (XPRU_ERRORS | XPRU_TIMEOUTS)) {
  122.       if (x->xpru_updatemask & XPRU_ERRORS)   xpr_errors   = x->xpru_errors;
  123.       if (x->xpru_updatemask & XPRU_TIMEOUTS) xpr_timeouts = x->xpru_timeouts;
  124.       PostMsg(mywindow, errtimfmt, xpr_errors, xpr_timeouts);
  125.    }
  126.    return(0L);
  127. }
  128.  
  129. /**
  130. *
  131. *   Prompt the user for input
  132. *
  133. **/
  134. long vlt_gets(s, t)
  135. char *s, *t;
  136. {
  137. /*
  138. *   Use VLT's DoRequest() function
  139. */
  140.    return((long) DoRequest(mywindow, t, s, NULL, " Cancel "));
  141. }
  142.  
  143. /**
  144. *
  145. *   Write a string to the serial port
  146. *
  147. **/
  148. long vlt_swrite(s, n)
  149. char *s;
  150. long n;
  151. {
  152. /*
  153. *   Use VLT's SendString() function
  154. */
  155.    SendString(s, (int) n);
  156.    return(0L);
  157. }
  158.  
  159. /**
  160. *
  161. *   Read characters from the serial port
  162. *
  163. **/
  164. long vlt_sread(buff, length, micros)
  165. unsigned char *buff;
  166. long length, micros;
  167. {
  168.    extern int timeout;
  169.    long secs = 0L;
  170.  
  171.    if (buff == NULL) return(-1L);
  172. /*
  173. *   Convert timeout to seconds and micros if necessary
  174. */
  175.    if (micros) {
  176.       if (micros > 1000000L) {
  177.          secs   = micros / 1000000L;
  178.          micros = micros % 1000000L;
  179.       }
  180.    }
  181. /*
  182. *   Cheat! Only return a single character since we have such a nice
  183. *   readchar() function in VLT. One day I'll have to modify this to 
  184. *   save the odd microsecond...
  185. */
  186.    buff[0] = (unsigned char) readchar(secs, micros);
  187. /*
  188. *   VLT has a global called timeout. This comes in xfer.h.
  189. *   If the read was successful, return having read a single character.
  190. */
  191.    if (timeout == GOODREAD) return(1L);
  192. /*
  193. *   Else return error condition
  194. */
  195.    return(-1L);
  196. }
  197.  
  198. /**
  199. *
  200. *   Interfaces to stdio
  201. *
  202. **/
  203. long vlt_fopen(s, t)
  204. char *s, *t;
  205. {
  206.    return((long) fopen(s, t));
  207. }
  208.  
  209. long vlt_fclose(fp)
  210. FILE *fp;
  211. {
  212.    return((long) fclose(fp));
  213. }
  214.  
  215. long vlt_fread(buff, size, count, fp)
  216. char *buff;
  217. long size, count;
  218. FILE *fp;
  219. {
  220.    int res;
  221.    res = fread(buff, (int) size, (int) count, fp);
  222.    return((long) res);
  223. }
  224.  
  225. /**
  226. *
  227. *   Check for Abort
  228. *
  229. **/
  230. long vlt_chkabort()
  231. {
  232. /*
  233. *   VLT aborts its protocols when the escape key is pressed.
  234. *   CheckForKey loops over the UserPort messages looking for an escape.
  235. */
  236.    return((long) CheckForKey(69));
  237. }
  238.