home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / prog / utils / sercli.shr / sercli / src / rcs / sercli.c,v < prev    next >
Encoding:
Text File  |  1993-06-16  |  23.6 KB  |  1,412 lines

  1. head    1.13;
  2. access;
  3. symbols
  4.     sercli_v1_10:1.13
  5.     sercli_v1_9:1.6
  6.     sercli_v1_8:1.4
  7.     sercli_v1_7:1.3
  8.     sercli_v1_6:1.2
  9.     sercli_v1_5:1.1;
  10. locks
  11.     rkr:1.13;
  12. comment    @**  @;
  13.  
  14.  
  15. 1.13
  16. date    93.06.16.23.27.34;    author rkr;    state Exp;
  17. branches;
  18. next    1.12;
  19.  
  20. 1.12
  21. date    93.06.16.21.07.41;    author rkr;    state Exp;
  22. branches;
  23. next    1.11;
  24.  
  25. 1.11
  26. date    93.06.16.21.03.17;    author rkr;    state Exp;
  27. branches;
  28. next    1.10;
  29.  
  30. 1.10
  31. date    93.06.16.20.05.01;    author rkr;    state Exp;
  32. branches;
  33. next    1.9;
  34.  
  35. 1.9
  36. date    93.06.16.05.28.40;    author rkr;    state Exp;
  37. branches;
  38. next    1.8;
  39.  
  40. 1.8
  41. date    93.06.14.23.34.01;    author rkr;    state Exp;
  42. branches;
  43. next    1.7;
  44.  
  45. 1.7
  46. date    93.06.10.16.38.33;    author rkr;    state Exp;
  47. branches;
  48. next    1.6;
  49.  
  50. 1.6
  51. date    93.06.06.10.34.37;    author rkr;    state Exp;
  52. branches;
  53. next    1.5;
  54.  
  55. 1.5
  56. date    93.06.06.10.26.32;    author rkr;    state Exp;
  57. branches;
  58. next    1.4;
  59.  
  60. 1.4
  61. date    91.12.20.09.43.31;    author rkr;    state Exp;
  62. branches;
  63. next    1.3;
  64.  
  65. 1.3
  66. date    91.12.10.02.47.56;    author rkr;    state Exp;
  67. branches;
  68. next    1.2;
  69.  
  70. 1.2
  71. date    91.12.02.10.51.15;    author rkr;    state Exp;
  72. branches;
  73. next    1.1;
  74.  
  75. 1.1
  76. date    91.11.28.08.25.08;    author rkr;    state Exp;
  77. branches;
  78. next    ;
  79.  
  80.  
  81. desc
  82. @sercli is a program to permit shell-like interface to the serial port,
  83. while also permitting easy config- and run-time-control over the way the
  84. serial port (or even _which_ serial port) is used.
  85.  
  86. @
  87.  
  88.  
  89. 1.13
  90. log
  91. @Added per-file copyright notice, as suggested by GPL.
  92. @
  93. text
  94. @/*
  95. **  $Source: WB_2.1:homes/rkr/prog/sercli/src/RCS/sercli.c,v $
  96. **  $Author: rkr $
  97. **  $Revision: 1.12 $
  98. **  $Locker: rkr $
  99. **  $State: Exp $
  100. **  $Date: 1993/06/16 21:07:41 $
  101. **
  102. **  sercli (an Amiga .device <-> FIFO interface tool)
  103. **  Copyright (C) 1993  Richard Rauch
  104. **
  105. **  See /doc/sercli.doc and /COPYING for use and distribution license.
  106. **
  107. */
  108.  
  109. #include <exec/types.h>
  110. #include <exec/io.h>
  111. #include <exec/lists.h>
  112. #include <exec/memory.h>
  113. #include <exec/nodes.h>
  114. #include <exec/ports.h>
  115. #include <devices/serial.h>
  116. #include <devices/timer.h>
  117. #include <intuition/intuition.h>
  118. #include <intuition/intuitionbase.h>
  119. #include <libraries/dos.h>
  120.  
  121. #ifdef AZTEC_C
  122. #include <functions.h>
  123. #else
  124. #include <clib/alib_protos.h>
  125. #include <clib/dos_protos.h>
  126. #include <clib/exec_protos.h>
  127. #include <clib/intuition_protos.h>
  128. #endif
  129.  
  130. #include "defs.h"
  131. #include "ser_supp.h"
  132. #include "misc.h"
  133. #include "fifo.h"
  134. #include "config.h"
  135. #include "sercli-config.h"
  136. #include "rexx.h"
  137. #include "version.h"
  138.  
  139.  
  140. #define COPYRIGHT_NOTICE            \
  141. "\n"                                            \
  142. "$VER: " NAME " " VERSION " (" __DATE__")\n"    \
  143. "Copyright (C) 1991, 1993 by Richard Rauch.\n"  \
  144. "No warranty; distribute at will.\n"            \
  145. "(see doc/sercli.doc for more info)\n"          \
  146. "(see also the GNU General Public License)\n"   \
  147. "\n"
  148.  
  149.  
  150. #define SER_READ_MAX  512
  151. #define FIFO_BUF_SIZE (SER_READ_MAX * 4)
  152.  
  153. #define CTRL(x) (x ^ '@@')
  154.  
  155. #define dput(x) write_ser_str (x)   /*** for debugging only ***/
  156.  
  157. /*
  158. **  FIFO related globals.
  159. **
  160. */
  161. char *FifoSlav;      /* fifo_s    */
  162. char *FifoMast;      /* fifo_m    */
  163. char FifrIP;         /* read msg pending    */
  164. char FifwIP;         /* write msg pending   */
  165. long *FifoBase;
  166. Message RMsg;
  167. Message WMsg;
  168. MsgPort *FifoSink;
  169. void *FifoR;
  170. void *FifoW;
  171. ULONG pmask;
  172.  
  173. char *nether_name;        /***  who/what is on the other end...    ***/
  174.  
  175. int alert_ser = 0;
  176. int alert_loc = 1;
  177. char *config_file_name;
  178.  
  179.  
  180. /*
  181. **  Intuition/Window related globals
  182. **
  183. */
  184. NewWindow nw =
  185. {
  186.     0, 0, 0, 0,
  187.     0, 1,
  188.  
  189.     CLOSEWINDOW,    /*** IDCMP ***/
  190.  
  191.     NOCAREREFRESH | SMART_REFRESH | WINDOWCLOSE | WINDOWDEPTH
  192.     | WINDOWDRAG,   /*** Flags ***/
  193.  
  194.     NULL, NULL,
  195.     NULL,        /*** title ***/
  196.     NULL,
  197.     NULL,
  198.     0, 0, 0, 0,
  199.     WBENCHSCREEN
  200. };
  201. Window *win;
  202. char *window_title;  /*** Just use nw.Title??? ***/
  203. WORD win_width;
  204. WORD win_height;
  205. ULONG imask;
  206.  
  207.  
  208. ULONG wake_flags;   /*** Mask of bits to Wait() on. ***/
  209.  
  210.  
  211. static void clean_up (void);
  212. static void init (void);
  213.  
  214.  
  215. /*
  216. **  DICE (and maybe Lattice/SAS, dunno) uses a function, onbreak() to allow
  217. **  you to control what happens when a ^c occurs.
  218. **
  219. **  Aztec allows ^c checking to be turned off with a global flag variable.
  220. **
  221. **    ---rkr.
  222. **
  223. */
  224. #ifdef AZTEC_C
  225. extern long Enable_Abort;
  226. void onbreak (int (*brk) (void) ) {}
  227. #else
  228. long Enable_Abort;
  229. #endif
  230.  
  231.  
  232. void hex_dump (char *buf, size_t len)
  233. {
  234.     while (len--)
  235.     {
  236.     char c = *buf;
  237.     static char hex_chars [] =
  238.     {
  239.         '0', '1', '2', '3', '4', '5', '6', '7',
  240.         '8', '9', 'a', 'b', 'c', 'd', 'e', 'f',
  241.     };
  242.  
  243.     putchar (hex_chars [(c >> 4) & 0xf]);
  244.     putchar (hex_chars [ c       & 0xf]);
  245.  
  246.     if (len)
  247.     {
  248.         putchar (' ');
  249.         putchar (' ');
  250.     }
  251.  
  252.     ++buf;
  253.     }
  254. }
  255.  
  256.  
  257.  
  258. void on_error_ser (void *ptr)
  259. {
  260.     char *cmd;
  261.     char *err;
  262.     char err_buf [50];
  263.     IOExtSer *ior;
  264.     static char *serial_errors [] =
  265.     {
  266.     "not an error...",
  267.     "Device in use",
  268.     "unused",
  269.     "Invalid bps rate",
  270.     "Out of memory",
  271.     "Bad parameter",
  272.     "hardware data overrun (hmmm)",
  273.     "unused",
  274.     "unused",
  275.     "`ParityErr'",
  276.     "unused",
  277.     "`TimeErr'",
  278.     "BufOverflow'",
  279.     "No DSR",
  280.     "No CTS",
  281.     "`DetectedBreak'",
  282.     };
  283.  
  284.  
  285.     ior = ptr;
  286.  
  287.     printf
  288.     (
  289.     "\n***\nserial error on {%s}; %s/%d\n",
  290.     prog_id,
  291.     ser_device_name,
  292.     ser_device_unit
  293.     );
  294.  
  295.     switch (ior->IOSer.io_Command)
  296.     {
  297.     case CMD_WRITE:
  298.     cmd = "CMD_WRITE";
  299.     break;
  300.  
  301.     case CMD_READ:
  302.     cmd = "CMD_READ";
  303.     break;
  304.  
  305.     case SDCMD_QUERY:
  306.     cmd = "SDCMD_QUERY";
  307.     break;
  308.  
  309.     case SDCMD_SETPARAMS:
  310.     cmd = "SDCMD_SETPARAMS";
  311.     break;
  312.  
  313.     default:
  314.     cmd = "duh?";
  315.     break;
  316.     }
  317.  
  318.     if ( (ior->IOSer.io_Error > 0) && (ior->IOSer.io_Error < 16) )
  319.     err = serial_errors [ior->IOSer.io_Error];
  320.     else
  321.     {
  322.     err = err_buf;
  323.     sprintf (err_buf, "Unknown error number, %d", ior->IOSer.io_Error);
  324.     }
  325.  
  326.     printf
  327.     (
  328.     "{\n"
  329.     "\tio_Command       == %s\n"
  330.     "\tio_Flags         == 0x%08.8x\n"
  331.     "\tio_Error         == %d: %s\n"
  332.     "\tio_Actual        == %d\n"
  333.     "\tio_Length        == %d\n"
  334.     "\tio_Data          == 0x%x\n"
  335.     "\tio_ExtFlags      == 0x%08.8x\n"
  336.     "\tio_Baud          == %d\n"
  337.     "\tio_ReadLen       == %d\n"
  338.     "\tio_WriteLen      == %d\n"
  339.     "\tio_StopBits      == %d\n"
  340.     "\tio_SerFlags      == 0x%08.8x\n"
  341.     "\tio_Status        == %d\n"
  342.     "}\n",
  343.     cmd,
  344.     ior->IOSer.io_Flags,
  345.     ior->IOSer.io_Error, err,
  346.     ior->IOSer.io_Actual,
  347.     ior->IOSer.io_Length,
  348.     ior->IOSer.io_Data,
  349.     ior->io_ExtFlags,
  350.     ior->io_Baud,
  351.     ior->io_ReadLen,
  352.     ior->io_WriteLen,
  353.     ior->io_StopBits,
  354.     ior->io_SerFlags,
  355.     ior->io_Status
  356.     );
  357.  
  358.     printf ("io_Data contents == {");
  359.     hex_dump (ior->IOSer.io_Data, ior->IOSer.io_Length);
  360.     printf ("}\n\n");
  361. }
  362.  
  363.  
  364. void open_fifo (void)
  365. {
  366.     FifoSlav = malloc (strlen (prog_id) + 16);
  367.     FifoMast = malloc (strlen (prog_id) + 16);
  368.     if (!(FifoSlav && FifoMast) )
  369.     {
  370.     fprintf (stderr, "unable to allocate FIFO name-strings\n");
  371.     exit (10);
  372.     }
  373.     sprintf (FifoMast, "%s_m", prog_id);
  374.     sprintf (FifoSlav, "%s_s", prog_id);
  375.  
  376.     FifoSink = CreatePort (NULL, 0);
  377.     if (!FifoSink)
  378.     {
  379.     fprintf (stderr, "unable to create FifoSink FIFO port\n");
  380.     exit (10);
  381.     }
  382.  
  383.     /*
  384.      *    FIFOS
  385.      */
  386.  
  387.     FifoBase = OpenLibrary ("fifo.library", 0);
  388.     if (!FifoBase)
  389.     {
  390.     fprintf (stderr, "unable to open %s\n", FIFONAME);
  391.     exit (10);
  392.     }
  393.  
  394.     FifoW = OpenFifo (FifoMast, FIFO_BUF_SIZE, FIFOF_WRITE | FIFOF_NORMAL | FIFOF_NBIO);
  395.     if (FifoW == NULL)
  396.     {
  397.     fprintf (stderr, "unable to open fifo %s\n", FifoMast);
  398.     exit (10);
  399.     }
  400.  
  401.     FifoR = OpenFifo (FifoSlav, FIFO_BUF_SIZE, FIFOF_READ  | FIFOF_NORMAL | FIFOF_NBIO);
  402.     if (FifoR == NULL)
  403.     {
  404.     fprintf (stderr, "unable to open fifo %s\n", FifoSlav);
  405.     exit (10);
  406.     }
  407.     RMsg.mn_ReplyPort = FifoSink;
  408.     WMsg.mn_ReplyPort = FifoSink;
  409.  
  410.     pmask = 1 << FifoSink->mp_SigBit;
  411. }
  412.  
  413. void close_fifo (void)
  414. {
  415.     /*
  416.     **    Shut down the pending FIFO reads/writes.
  417.     **
  418.     */
  419.     if (FifrIP)
  420.     {
  421.     if (alert_loc)
  422.         printf ("shutting down `FifrIP' (FIFO: read ? pending)\n");
  423.     RequestFifo (FifoR, &RMsg, FREQ_ABORT);
  424.     WaitMsg (&RMsg);
  425.     FifrIP = 0;
  426.     }
  427.     if (FifwIP)
  428.     {
  429.     if (alert_loc)
  430.         printf ("shutting down `FifwIP' (FIFO: write ? pending)\n");
  431.     RequestFifo (FifoW, &WMsg, FREQ_ABORT);
  432.     WaitMsg (&WMsg);
  433.     FifwIP = 0;
  434.     }
  435.  
  436.     /*
  437.     **    Shut down the FIFO read/write streams.
  438.     **
  439.     */
  440.     if (FifoR)
  441.     {
  442.     if (alert_loc)
  443.         printf ("shutting down `FifoR' (FIFO: Read stream)\n");
  444.     CloseFifo (FifoR, FIFOF_EOF);
  445.     FifoR = NULL;
  446.     }
  447.     if (FifoW)
  448.     {
  449.     if (alert_loc)
  450.         printf ("shutting down `FifoW' (FIFO: Write stream)\n");
  451.     CloseFifo (FifoW, FIFOF_EOF);
  452.     FifoW = NULL;
  453.     }
  454.  
  455.     if (FifoBase)
  456.     {
  457.     if (alert_loc)
  458.         printf ("closing FifoBase (libs:fifo.library)\n");
  459.     CloseLibrary ( (struct Library *) FifoBase);
  460.     FifoBase = NULL;    /*** DANGEROUS; should make this auto-init! ***/
  461.     }
  462.  
  463.     if (FifoSink)
  464.     {
  465.     if (alert_loc)
  466.         printf ("releasing `FifoSink' (misc. FIFO: msg. rec. port)\n");
  467.     DeletePort (FifoSink);
  468.     FifoSink = NULL;
  469.     RMsg.mn_ReplyPort = FifoSink;
  470.     WMsg.mn_ReplyPort = FifoSink;
  471.  
  472.     }
  473.     if (FifoSlav)
  474.     {
  475.     free (FifoSlav);
  476.     FifoSlav = NULL;
  477.     }
  478.     if (FifoMast)
  479.     {
  480.     free (FifoMast);
  481.     FifoMast = NULL;
  482.     }
  483.     pmask = 0;
  484. }
  485.  
  486.  
  487. void clean_up (void)
  488. {
  489.     close_fifo ();
  490.     if (win)
  491.     {
  492.     if (alert_loc)
  493.         printf ("releasing `win' (Intuition Window)\n");
  494.     CloseWindow (win);
  495.     win = NULL;
  496.     }
  497.     close_rexx ();
  498.     close_ser ();
  499. }
  500.  
  501.  
  502. void init (void)
  503. {
  504.     read_sercli_config ();
  505.     set_error_handler (error_type_serial, on_error_ser);    /*** ignore old handler??? ***/
  506.  
  507.     onbreak (do_nothing);
  508.     atexit (clean_up);
  509.     Enable_Abort = 0;
  510.  
  511.     if (alert_loc)
  512.     printf (COPYRIGHT_NOTICE);
  513.  
  514.     open_ser ();
  515.     open_rexx ();
  516.  
  517.  
  518.     {
  519.     char
  520.         buf [256];
  521.     int
  522.         len;
  523.  
  524.     if (!nether_name)
  525.         nether_name = strdup ("no user");
  526.     len = sprintf
  527.     (
  528.         buf,
  529.         "%s: with {%s} id {%s}",
  530.         PROG_NAME,
  531.         nether_name,
  532.         prog_id
  533.     );
  534.     nw.Title = window_title = strdup (buf);         /*** just use nw.Title??? ***/
  535.  
  536.     win_width = nw.Width = GADGETS_WIDTH + (len * TEXT_WIDTH);
  537.     win_height = nw.Height = TEXT_HEIGHT + 2;
  538.  
  539.     win = OpenWindow (&nw);
  540.     }
  541.  
  542.     if (!win)
  543.     exit (10);
  544.  
  545.     open_fifo ();
  546.  
  547.     imask = 1 << win->UserPort->mp_SigBit;
  548. }
  549.  
  550.  
  551. void SendBreak (int c)
  552. {
  553.     char buf [256];
  554.     long fh;
  555.  
  556.     sprintf (buf, "FIFO:%s/%c", prog_id, c);
  557.     if (fh = Open (buf, 1005))
  558.     Close (fh);
  559. }
  560.  
  561. void set_wake_flags (void)
  562. {
  563.     wake_flags
  564.     = ser_read_reply_mask
  565.     | ser_write_reply_mask
  566.     | imask
  567.     | pmask
  568.     | rexx_mask;
  569. }
  570.  
  571. void send_eof (void)
  572. {
  573.     close_fifo ();
  574.     if (alert_ser)
  575.     write_ser_str ("\n<EOF>\n");
  576.     open_fifo ();
  577.     set_wake_flags ();
  578. }
  579.  
  580. int main (int argc, char *argv [])
  581. {
  582.     char *buf;
  583.     char *o_buf;
  584.     short notDone = 1;
  585.     short online = 0;    /*** have we told FIFO to send an EOF? ***/
  586.     short carrier = 0;    /*** connected? ***/
  587.  
  588.  
  589.     buf = malloc (SER_READ_MAX);
  590.     o_buf = malloc (SER_READ_MAX);
  591.     if (!(buf && o_buf) )
  592.     {
  593.     fprintf (stderr, "Could not allocate ser<->FIFO i/o buffers.\n");
  594.     exit (10);
  595.     }
  596.  
  597.     if (argc > 1)
  598.     config_file_name = argv [1];
  599.     else
  600.     config_file_name = "sercli_config";
  601.  
  602.     init ();
  603.  
  604.     /*
  605.     **    Begin by requesting asynch i/o from our FIFO and the .device
  606.     **
  607.     */
  608.     read_ser_asynch (buf, SER_READ_MAX);
  609.     RequestFifo (FifoR, &RMsg, FREQ_RPEND);
  610.     FifrIP = 1;
  611.  
  612.     set_wake_flags ();
  613.  
  614.     while (notDone)
  615.     {
  616.     ULONG mask;
  617.     IOExtSer *ser_status;
  618.  
  619.     mask = Wait (wake_flags);
  620. top:
  621.         ser_status = query_ser ();
  622.         carrier = !(ser_status->io_Status & 32);
  623.         if (carrier != online)
  624.         {
  625. fprintf (stderr, "--  NOTICE (%s): Carrier just changed to %d\n", prog_id, carrier);
  626. //  handle_error (error_type_serial, ser_status);
  627.             if (online)
  628.             send_eof ();
  629.             online = carrier;
  630.         }
  631.  
  632.     if (mask & imask)
  633.     {
  634.         IntuiMessage *im;
  635.  
  636.         while (im = (IntuiMessage *) GetMsg (win->UserPort) )
  637.         {
  638.         switch (im->Class)
  639.         {
  640.         case CLOSEWINDOW:
  641.             notDone = 0;
  642.             if (alert_ser)
  643.             write_ser_str
  644.             (
  645.                 "\a\nLocal window shut down!\n"
  646.                 "Closing serial.device...\n"
  647.             );
  648.  
  649.             if (alert_loc)
  650.             printf
  651.             (
  652.                 "Use\n"
  653.                 "\tremcli %s\n"
  654.                 "to wrap up session.\n"
  655.                 "Or re-launch sercli without creating a new shell.\n"
  656.                 "(May not work as I make further changes...)\n"
  657.                 "(Also note that DTR should go down on exit..)\n",
  658.                 prog_id
  659.             );
  660.             break;
  661.  
  662.         default:
  663.             dput ("\nhuh?\n");
  664.             break;
  665.         }
  666.         }
  667.     }
  668.  
  669.     if (mask & ser_read_reply_mask)
  670.     {
  671.         IOExtSer *ior;
  672.  
  673.         ior = (IOExtSer *) GetMsg (ser_read_reply_port);
  674.         if (ior)
  675.         {
  676.         char c;
  677.         ULONG count;
  678.         ULONG n;
  679.         ULONG read_len;
  680.  
  681.  
  682.         read_len = ior->IOSer.io_Actual;
  683.         if (read_len)
  684.         {
  685.             ULONG data_index;
  686.  
  687.             for
  688.             (
  689.             count = 0, data_index = 0;
  690.             data_index < read_len;
  691.             ++data_index, ++count
  692.             )
  693.             {
  694.             c = buf [count];
  695.             switch (c)
  696.             {
  697.                 /*
  698.                 **    (STUPID) <CR>/<LF> conversion.
  699.                 **
  700.                 */
  701.                 case '\x0d':
  702.                 o_buf [count] = '\n';
  703.                 break;
  704.  
  705.                 /*
  706.                 **    break detection...
  707.                 **
  708.                 */
  709.                 case CTRL ('C'):
  710.                 case CTRL ('D'):
  711.                 case CTRL ('E'):
  712.                 case CTRL ('F'):
  713.                 SendBreak (CTRL (c) );
  714.                 --count;
  715.                 break;
  716.  
  717.                 /*
  718.                 **    EOF conversion
  719.                 **
  720.                 */
  721.                 case CTRL ('\\'):
  722.                 send_eof ();
  723.                 break;
  724.  
  725.                 /*
  726.                 **    standard copy operation...
  727.                 **
  728.                 */
  729.                 default:
  730.                 o_buf [count] = c;
  731.                 break;
  732.             }
  733.             }
  734.         }
  735.  
  736.         read_ser_asynch (buf, SER_READ_MAX);
  737.         if (read_len && count)
  738.             n = WriteFifo (FifoW, o_buf, count);
  739.  
  740.         /*
  741.         **  This was borrowed from remcli.c in the fifodev2.lzh
  742.         **  archive.  I've zapped it out, as it really needs
  743.         **  further adaption to work.
  744.         **
  745.         **  This shouldn't be necessary, anyway, as (hopefully)
  746.         **  only typed input will be coming in through the serial
  747.         **  port.
  748.         **
  749.         **  if (n != count)
  750.         **  {
  751.         **    ser_to_fif_p = 1;
  752.         **    if (FifwIP == 0)
  753.         **    {
  754.         **        RequestFifo (FifoW, &WMsg, FREQ_WAVAIL);
  755.         **        FifwIP = 1;
  756.         **    }
  757.         **  }
  758.         **  else
  759.         **    do next read, set pending flag.
  760.         **
  761.         */
  762.         }
  763.     }
  764.  
  765.  
  766.     if (mask & ser_write_reply_mask)
  767.         clear_write_replies ();
  768.  
  769.  
  770.     if (mask & rexx_mask)
  771.         handle_rexx ();
  772.  
  773.  
  774.     if (mask & pmask)
  775.     {
  776.         Message *msg;
  777.  
  778.         while (msg = (Message *)GetMsg (FifoSink))
  779.         {
  780.         if (msg == (Message *)&RMsg)
  781.         {
  782.             char *ptr;
  783.             long n;
  784.  
  785.             FifrIP = 0;
  786.  
  787.             if ( (n = ReadFifo (FifoR, &ptr, 0) ) > 0)
  788.             {
  789.             if (n > 256)                /*  limit size      */
  790.                 n = 256;
  791.             write_ser_asynch (ptr, n);
  792.                             /*    clear N bytes    */
  793.             n = ReadFifo (FifoR, &ptr, n);
  794.             }
  795.             if (n < 0)                      /*  EOF */
  796.             {
  797.             if (alert_ser)
  798.                 write_ser_str
  799.                 (
  800.                 "\a\nFIFO EOF!\n"
  801.                 "Closing .device...\n"
  802.                 );
  803.             notDone = 0;
  804.             }
  805.             else
  806.             {
  807.             RequestFifo (FifoR, &RMsg, FREQ_RPEND);
  808.             FifrIP = 1;
  809.             }
  810.         }
  811.         else if (msg == (Message *)&WMsg)
  812.         {
  813.             /*
  814.             **    remcli.c uses this; I don't, so this entire
  815.             **    if()...else if()... construct could be removed.
  816.             **
  817.             **    However, if it becomes a problem, I could
  818.             **    conceivably want to reinstate it for flow-control,
  819.             **    so...here it is in token form.
  820.             **
  821.             */
  822.             if (alert_ser)
  823.             write_ser_str
  824.             (
  825.                 "\nHey, a WMsg came back!\n"
  826.                 "And I didn't even send one!\n\n"
  827.             );
  828.         }
  829.         goto top;
  830.         }
  831.     }
  832.     }
  833.     return (0);
  834. }
  835.  
  836. @
  837.  
  838.  
  839. 1.12
  840. log
  841. @Forgot `no warranty'.  *grin*
  842. @
  843. text
  844. @d4 1
  845. a4 1
  846. **  $Revision: 1.11 $
  847. d7 6
  848. a12 1
  849. **  $Date: 1993/06/16 21:03:17 $
  850. @
  851.  
  852.  
  853. 1.11
  854. log
  855. @Added ref. to the GPL in the copyright notice...
  856. @
  857. text
  858. @d4 1
  859. a4 1
  860. **  $Revision: 1.10 $
  861. d7 1
  862. a7 1
  863. **  $Date: 1993/06/16 20:05:01 $
  864. d46 1
  865. @
  866.  
  867.  
  868. 1.10
  869. log
  870. @Tried re-setting the {wake_flags} mask after shutting down FIFO (since
  871. the FifoSink message port was released)...well, to be precise,
  872. it is after re-opening the FIFO (when the port is reallocated).  No
  873. dice (pun not intended).
  874.  
  875. Also used to have a 1-second delay between the close_fifo() and
  876. open_fifo(); this did not seem to help (wonder if they would work in
  877. combination? *grin*).
  878.  
  879. Will have to look for other subtleties, I guess.
  880. @
  881. text
  882. @d4 1
  883. a4 1
  884. **  $Revision: 1.7 $
  885. d7 1
  886. a7 1
  887. **  $Date: 1993/06/10 16:38:33 $
  888. d47 1
  889. @
  890.  
  891.  
  892. 1.9
  893. log
  894. @created set_wake_flags() to reset the {wake_flags} var after
  895. doing things that _might_ change the signal numbers (e.g., after
  896. releasing the FIFO {FifoSink} message port).  This shouldn't
  897. help, but MIGHT.
  898. @
  899. text
  900. @d392 2
  901. a393 1
  902.     printf ("releasing `win' (Intuition Window)\n");
  903. a503 1
  904.  
  905. a676 1
  906. //        int n;        /*** UNUSED VAR ***/
  907. @
  908.  
  909.  
  910. 1.8
  911. log
  912. @Misc. fiddling with CD, FIFO EOF, ...I think that's about it.
  913. @
  914. text
  915. @d108 3
  916. d460 10
  917. d473 2
  918. a474 5
  919.     /* if (alert_ser) */
  920.     write_ser_str ("\n<EOF>");
  921.     Delay (50);
  922.     /* if (alert_ser) */
  923.     write_ser_str ("\n");
  924. d476 1
  925. a478 1
  926.  
  927. a485 1
  928.     ULONG wake_flags;    /*** Mask of bits to Wait() on. ***/
  929. d512 1
  930. a512 7
  931.  
  932.     wake_flags
  933.     = ser_read_reply_mask
  934.     | ser_write_reply_mask
  935.     | imask
  936.     | pmask
  937.     | rexx_mask;
  938. @
  939.  
  940.  
  941. 1.7
  942. log
  943. @Started adding CD support; moved FIFO: init/cleanup into seperate
  944. open_fifo()/close_fifo() functions; made close_fifo() clear out the
  945. global FIFO: status vars we keep (so that re-opening & re-closing
  946. won't result in Bad Things).
  947. @
  948. text
  949. @d4 2
  950. a5 2
  951. **  $Revision: 1.6 $
  952. **  $Locker:  $
  953. d7 1
  954. a7 1
  955. **  $Date: 1993/06/06 10:34:37 $
  956. d45 1
  957. a45 1
  958. "Copyright (C) 1991 by Richard Rauch.\n"        \
  959. d57 4
  960. a64 2
  961.  
  962.  
  963. a65 1
  964.  
  965. d68 1
  966. a68 3
  967.  
  968. MsgPort *IoSink;
  969.  
  970. a70 2
  971.  
  972. ULONG imask;
  973. a71 1
  974. ULONG wake_flags;
  975. a72 1
  976. char *config_file_name;
  977. a74 3
  978. void SendBreak (int);
  979.  
  980.  
  981. d77 1
  982. a78 2
  983. WORD win_width;
  984. WORD win_height;
  985. d80 4
  986. a100 1
  987.  
  988. d102 4
  989. a106 2
  990. char
  991.     *window_title;  /*** Just use nw.Title??? ***/
  992. d108 2
  993. a109 3
  994. static void
  995.     clean_up (void),
  996.     init (void);
  997. a110 2
  998. void
  999.     SendBreak (int c);
  1000. a111 1
  1001.  
  1002. d265 5
  1003. d273 6
  1004. a278 1
  1005.     IoSink = CreatePort (NULL, 0);
  1006. d288 1
  1007. a288 1
  1008.     exit (1);
  1009. d295 1
  1010. a295 1
  1011.     exit (1);
  1012. d302 1
  1013. a302 1
  1014.     exit(1);
  1015. d304 2
  1016. a305 2
  1017.     RMsg.mn_ReplyPort = IoSink;
  1018.     WMsg.mn_ReplyPort = IoSink;
  1019. d307 1
  1020. a307 1
  1021.     pmask = 1 << IoSink->mp_SigBit;
  1022. d312 4
  1023. d318 2
  1024. a319 1
  1025.     printf ("shutting down `FifrIP' (FIFO: read ? pending)\n");
  1026. d326 2
  1027. a327 1
  1028.     printf ("shutting down `FifwIP' (FIFO: write ? pending)\n");
  1029. d332 5
  1030. d339 2
  1031. a340 1
  1032.     printf ("shutting down `FifoR' (FIFO: Read stream)\n");
  1033. d346 2
  1034. a347 1
  1035.     printf ("shutting down `FifoW' (FIFO: Write stream)\n");
  1036. d351 1
  1037. d354 2
  1038. a355 1
  1039.     printf ("closing FifoBase (libs:fifo.library)\n");
  1040. d360 11
  1041. a370 1
  1042.     if (IoSink)
  1043. d372 2
  1044. a373 3
  1045.     printf ("releaseing `IoSink' (misc. FIFO: msg. rec. port)\n");
  1046.     DeletePort (IoSink);
  1047.     IoSink = NULL;
  1048. d375 5
  1049. d457 11
  1050. d474 3
  1051. a476 2
  1052.     short online = 0;
  1053.     short carrier = 0;
  1054. d482 2
  1055. d485 1
  1056. d496 1
  1057. a496 2
  1058.     **    Start the asynch i/o by reading up to {SER_READ_MAX} bytes from the
  1059.     **    serial port.
  1060. a499 4
  1061.  
  1062.     /*
  1063.     **    start async FIFO requests
  1064.     */
  1065. a510 1
  1066.  
  1067. d518 4
  1068. a521 4
  1069. //    ser_status = query_ser ();
  1070. //    carrier = !(ser_status->io_Status & 32);
  1071.     if (carrier != online)
  1072.     {
  1073. d523 6
  1074. a528 8
  1075. handle_error (error_type_serial, ser_status);
  1076.         if (online)
  1077.         {
  1078. //        close_fifo ();
  1079. //        open_fifo ();
  1080.         }
  1081.         online = carrier;
  1082.     }
  1083. d539 6
  1084. a544 5
  1085.             if (alert_ser) write_ser_str
  1086.             (
  1087.             "\a\nLocal window shut down!\n"
  1088.             "Closing serial.device...\n"
  1089.             );
  1090. d546 11
  1091. a556 10
  1092.             if (alert_loc) printf
  1093.             (
  1094.             "Use\n"
  1095.                 "\tremcli %s\n"
  1096.             "to wrap up session.\n"
  1097.             "Or re-launch sercli without creating a new shell.\n"
  1098.             "(May not work as I make further changes...)\n"
  1099.             "(Also note that DTR should go down on exit..)\n",
  1100.             prog_id
  1101.             );
  1102. d594 35
  1103. a628 27
  1104.             /*
  1105.             **  <CR>/<LF> conversion.
  1106.             **
  1107.             */
  1108.             case '\x0d':
  1109.                 o_buf [count] = '\n';
  1110.                 break;
  1111.  
  1112.             /*
  1113.             **  break detection...
  1114.             **
  1115.             */
  1116.             case CTRL ('C'):
  1117.             case CTRL ('D'):
  1118.             case CTRL ('E'):
  1119.             case CTRL ('F'):
  1120.                 SendBreak (CTRL (c) );
  1121.                 --count;
  1122.                 break;
  1123.  
  1124.             /*
  1125.             **  standard copy operation...
  1126.             **
  1127.             */
  1128.             default:
  1129.                 o_buf [count] = c;
  1130.                 break;
  1131. a632 1
  1132.  
  1133. d676 1
  1134. a676 1
  1135.         while (msg = (Message *)GetMsg (IoSink))
  1136. d695 6
  1137. a700 5
  1138.             if (alert_ser) write_ser_str
  1139.             (
  1140.                 "\a\nFIFO EOF!\n"
  1141.                 "Closing serial.device...\n"
  1142.             );
  1143. d720 6
  1144. a725 5
  1145.             if (alert_ser) write_ser_str
  1146.             (
  1147.             "\nHey, a WMsg came back!\n"
  1148.             "And I didn't even send one!\n\n"
  1149.             );
  1150. @
  1151.  
  1152.  
  1153. 1.6
  1154. log
  1155. @Converted {rexx_name} to {prog_id}.  In many spots, then, deleted
  1156. redundant {prog_id}.  (Well, in _some_ spots...)
  1157. @
  1158. text
  1159. @d2 1
  1160. a2 1
  1161. **  $Source: WB_2.1:ho/RCS/sercli.c,v $
  1162. d4 2
  1163. a5 2
  1164. **  $Revision: 1.5 $
  1165. **  $Locker: rkr $
  1166. d7 1
  1167. a7 1
  1168. **  $Date: 1993/06/06 10:26:32 $
  1169. a136 31
  1170. void clean_up (void)
  1171. {
  1172.     if (FifrIP)
  1173.     {
  1174.     RequestFifo (FifoR, &RMsg, FREQ_ABORT);
  1175.     WaitMsg (&RMsg);
  1176.     }
  1177.     if (FifwIP)
  1178.     {
  1179.     RequestFifo (FifoW, &WMsg, FREQ_ABORT);
  1180.     WaitMsg (&WMsg);
  1181.     }
  1182.     if (FifoR)
  1183.     CloseFifo (FifoR, FIFOF_EOF);
  1184.     if (FifoW)
  1185.     CloseFifo (FifoW, FIFOF_EOF);
  1186.     if (FifoBase)
  1187.     CloseLibrary ( (struct Library *) FifoBase);
  1188.  
  1189.     if (IoSink)
  1190.     DeletePort (IoSink);
  1191.  
  1192.     if (win)
  1193.     CloseWindow (win);
  1194.  
  1195.     close_rexx ();
  1196.     close_ser ();
  1197. }
  1198.  
  1199.  
  1200.  
  1201. d269 97
  1202. d410 1
  1203. a410 35
  1204.  
  1205.  
  1206.     FifoSlav = malloc (strlen (prog_id) + 16);
  1207.     FifoMast = malloc (strlen (prog_id) + 16);
  1208.     sprintf (FifoMast, "%s_m", prog_id);
  1209.     sprintf (FifoSlav, "%s_s", prog_id);
  1210.  
  1211.     IoSink = CreatePort (NULL, 0);
  1212.  
  1213.     /*
  1214.      *    FIFOS
  1215.      */
  1216.  
  1217.     FifoBase = OpenLibrary ("fifo.library", 0);
  1218.     if (!FifoBase)
  1219.     {
  1220.     fprintf (stderr, "unable to open %s\n", FIFONAME);
  1221.     exit (1);
  1222.     }
  1223.  
  1224.     FifoW = OpenFifo (FifoMast, FIFO_BUF_SIZE, FIFOF_WRITE | FIFOF_NORMAL | FIFOF_NBIO);
  1225.     if (FifoW == NULL)
  1226.     {
  1227.     fprintf (stderr, "unable to open fifo %s\n", FifoMast);
  1228.     exit (1);
  1229.     }
  1230.  
  1231.     FifoR = OpenFifo (FifoSlav, FIFO_BUF_SIZE, FIFOF_READ  | FIFOF_NORMAL | FIFOF_NBIO);
  1232.     if (FifoR == NULL)
  1233.     {
  1234.     fprintf (stderr, "unable to open fifo %s\n", FifoSlav);
  1235.     exit(1);
  1236.     }
  1237.     RMsg.mn_ReplyPort = IoSink;
  1238.     WMsg.mn_ReplyPort = IoSink;
  1239. a412 1
  1240.     pmask = 1 << IoSink->mp_SigBit;
  1241. a415 1
  1242.  
  1243. a426 1
  1244.  
  1245. d432 2
  1246. d474 1
  1247. d478 13
  1248. d627 1
  1249. a627 1
  1250.         int n;
  1251. @
  1252.  
  1253.  
  1254. 1.5
  1255. log
  1256. @Made {FidoName} refs to {prog_id}
  1257. @
  1258. text
  1259. @d2 1
  1260. a2 1
  1261. **  $Source: WB_2.1:ho/rcs/sercli.c,v $
  1262. d4 2
  1263. a5 2
  1264. **  $Revision: 1.4 $
  1265. **  $Locker:  $
  1266. d7 1
  1267. a7 1
  1268. **  $Date: 1991/12/20 09:43:31 $
  1269. d226 1
  1270. a226 1
  1271.     rexx_name,
  1272. d328 1
  1273. a328 1
  1274.         "%s: with {%s} fifo {%s}, rx {%s}",
  1275. d331 1
  1276. a331 2
  1277.         prog_id,
  1278.         rexx_name
  1279. @
  1280.  
  1281.  
  1282. 1.4
  1283. log
  1284. @**  Added range checking on io_Error in the serial error handler.
  1285. @
  1286. text
  1287. @d2 1
  1288. a2 1
  1289. **  $Source: Workbench:personal/rkr/prog/sercli/src/rcs/sercli.c,v $
  1290. d4 2
  1291. a5 2
  1292. **  $Revision: 1.3 $
  1293. **  $Locker: rkr $
  1294. d7 1
  1295. a7 1
  1296. **  $Date: 91/12/10 02:47:56 $
  1297. a56 1
  1298. /*** char *FifoName,    /*  fifo    */    /*** config'ed  ***/
  1299. d331 1
  1300. a331 1
  1301.         FifoName,
  1302. d347 4
  1303. a350 4
  1304.     FifoSlav = malloc (strlen (FifoName) + 16);
  1305.     FifoMast = malloc (strlen (FifoName) + 16);
  1306.     sprintf (FifoMast, "%s_m", FifoName);
  1307.     sprintf (FifoSlav, "%s_s", FifoName);
  1308. d392 1
  1309. a392 1
  1310.     sprintf (buf, "FIFO:%s/%c", FifoName, c);
  1311. d471 1
  1312. a471 1
  1313.             FifoName
  1314. @
  1315.  
  1316.  
  1317. 1.3
  1318. log
  1319. @**  Made sercli "startup-banner" automatically reflect version set in
  1320.     dmakefile, and also embed the date-compiled.
  1321.  
  1322.  
  1323. @
  1324. text
  1325. @d4 1
  1326. a4 1
  1327. **  $Revision: 1.2 $
  1328. d7 1
  1329. a7 1
  1330. **  $Date: 91/12/02 10:51:15 $
  1331. d199 1
  1332. d203 1
  1333. a203 1
  1334.     "NULL error!?!  _real_ problems here, bud...",
  1335. d255 7
  1336. a261 1
  1337.     err = serial_errors [ior->IOSer.io_Error];
  1338. @
  1339.  
  1340.  
  1341. 1.2
  1342. log
  1343. @**  Make "sercli_config", in the current dir, the default config file.
  1344.  
  1345.  
  1346. **  _Use_ the error-handling stuff.
  1347. @
  1348. text
  1349. @d7 1
  1350. a7 1
  1351. **  $Date: 91/12/02 10:44:51 $
  1352. d39 1
  1353. d42 5
  1354. a46 5
  1355. #define COPYRIGHT_NOTICE            \
  1356. "\n"                                        \
  1357. "sercli (v1.6)\n"                           \
  1358. "Copyright (C) 1991 by Richard Rauch.\n"    \
  1359. "(see doc/sercli.doc for more info)\n"      \
  1360. @
  1361.  
  1362.  
  1363. 1.1
  1364. log
  1365. @Initial revision
  1366. @
  1367. text
  1368. @d2 6
  1369. a7 6
  1370. **  $Source$
  1371. **  $Author$
  1372. **  $Revision$
  1373. **  $Locker$
  1374. **  $State$
  1375. **  $Date$
  1376. d43 1
  1377. a43 1
  1378. "sercli (v1.5)\n"                           \
  1379. a50 1
  1380. #define CONFIG_TEXT "_config"
  1381. d168 124
  1382. d297 1
  1383. a386 1
  1384.     {
  1385. a387 1
  1386.     }
  1387. a404 1
  1388.     {
  1389. a405 1
  1390.     }
  1391. d407 1
  1392. a407 5
  1393.     {
  1394.     config_file_name = malloc (strlen (argv [0]) + strlen (CONFIG_TEXT) + 1);
  1395.     strcpy (config_file_name, argv [0]);
  1396.     strcat (config_file_name, CONFIG_TEXT);
  1397.     }
  1398. d477 1
  1399. a477 1
  1400.         IO_Ext_Ser *ior;
  1401. d479 1
  1402. a479 1
  1403.         ior = (IO_Ext_Ser *) GetMsg (ser_read_reply_port);
  1404. d597 1
  1405. a597 1
  1406.             write_ser_str
  1407. d621 5
  1408. a625 2
  1409.             write_ser_str ("\nHey, a WMsg came back!\n");
  1410.             write_ser_str ("And I didn't even send one!\n\n");
  1411. @
  1412.