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

  1. head    1.9;
  2. access;
  3. symbols
  4.     sercli_v1_10:1.9
  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.9;
  12. comment    @**  @;
  13.  
  14.  
  15. 1.9
  16. date    93.06.16.23.29.30;    author rkr;    state Exp;
  17. branches;
  18. next    1.8;
  19.  
  20. 1.8
  21. date    93.06.11.10.24.44;    author rkr;    state Exp;
  22. branches;
  23. next    1.7;
  24.  
  25. 1.7
  26. date    93.06.10.16.43.21;    author rkr;    state Exp;
  27. branches;
  28. next    1.6;
  29.  
  30. 1.6
  31. date    93.06.06.10.34.37;    author rkr;    state Exp;
  32. branches;
  33. next    1.5;
  34.  
  35. 1.5
  36. date    93.06.06.10.26.32;    author rkr;    state Exp;
  37. branches;
  38. next    1.4;
  39.  
  40. 1.4
  41. date    91.12.20.09.43.45;    author rkr;    state Exp;
  42. branches;
  43. next    1.3;
  44.  
  45. 1.3
  46. date    91.12.10.02.48.11;    author rkr;    state Exp;
  47. branches;
  48. next    1.2;
  49.  
  50. 1.2
  51. date    91.12.02.10.51.29;    author rkr;    state Exp;
  52. branches;
  53. next    1.1;
  54.  
  55. 1.1
  56. date    91.11.28.08.25.17;    author rkr;    state Exp;
  57. branches;
  58. next    ;
  59.  
  60.  
  61. desc
  62. @sercli is a program to permit shell-like interface to the serial port,
  63. while also permitting easy config- and run-time-control over the way the
  64. serial port (or even _which_ serial port) is used.
  65.  
  66. @
  67.  
  68.  
  69. 1.9
  70. log
  71. @Added per-file copyright notice, as suggested by GPL.
  72.  
  73. Also will now only create the ARexx port if RexxSysBase was opened;
  74. this should make it able to run correctly on ARexxless systems.
  75. @
  76. text
  77. @/*
  78. **  $Source: WB_2.1:homes/rkr/prog/sercli/src/RCS/rexx.c,v $
  79. **  $Author: rkr $
  80. **  $Revision: 1.8 $
  81. **  $Locker: rkr $
  82. **  $State: Exp $
  83. **  $Date: 1993/06/11 10:24:44 $
  84. **
  85. **  sercli (an Amiga .device <-> FIFO interface tool)
  86. **  Copyright (C) 1993  Richard Rauch
  87. **
  88. **  See /doc/sercli.doc and /COPYING for use and distribution license.
  89. **
  90. */
  91.  
  92. #include <rexx/errors.h>
  93.  
  94. #include <clib/alib_protos.h>
  95. #include <clib/exec_protos.h>
  96. #include <clib/intuition_protos.h>
  97. #include <clib/rexxsyslib_protos.h>
  98.  
  99. #include <stdio.h>
  100. #include <stdlib.h>
  101. #include <string.h>
  102.  
  103. #include "config.h"
  104. #include "defs.h"
  105. #include "rexx.h"
  106. #include "keywords.h"
  107. #include "sercli-config.h"
  108. #include "ser_supp.h"
  109.  
  110. void *RexxSysBase;  /*** screwey `struct RxsLib' name, if you care ***/
  111.  
  112. MsgPort *rexx_port;
  113.  
  114. ULONG rexx_mask;
  115.  
  116. static RexxMsg *rm;
  117.  
  118. /*
  119. **  Reply to an ARexx message.
  120. **
  121. **  Args:
  122. **    {rm}    - The ARexx msg to reply to
  123. **    {rc}    - Result1 to send back
  124. **    {res}    - Result2 to send back
  125. **
  126. **  NOTE that according to ARexx documentation, you should only set {res}
  127. **  when {rc} is 0.  rexx_reply() makes NO such checks!
  128. **
  129. **  {rm} isn't really needed in this context, since we only have the global
  130. **  {rm}, but it's a bit more flexible this way (should probably stick
  131. **  {rm}s in more of the function parameter lists...).
  132. **
  133. */
  134. void rexx_reply (RexxMsg *rm, LONG rc, char *res)
  135. {
  136.     rm->rm_Result1 = rc;
  137.     if ( (rm->rm_Action & RXFF_RESULT) && (res) )
  138.     rm->rm_Result2 = CreateArgstring (res, strlen (res) );
  139.     ReplyMsg ( (Message *)rm);
  140. }
  141.  
  142.  
  143. /*
  144. **  Creates an ARexx port.
  145. **
  146. **  Does NOT open the arexx libraries; that will be handled by autoinit
  147. **  code (if Dillon hasn't yet put auto support for ARexx in, I'll add
  148. **  that...
  149. **
  150. **  Basically, creates a port with {prog_id} (a global; that global
  151. **  defaults to "sercli" but can be set before this function is called...
  152. **  In the current context (i.e., the sercli program) it may be set by
  153. **  read_sercli_config() when reading in a config file with an appropriate
  154. **  config line...).
  155. **
  156. */
  157. void open_rexx (void)
  158. {
  159.     if (RexxSysBase)
  160.     {
  161.     Forbid ();
  162.     {
  163.         if (FindPort (prog_id) )
  164.         exit (10);
  165.         rexx_port = CreatePort (prog_id, 1);
  166.     }
  167.     Permit ();
  168.     rexx_mask = 1 << (rexx_port->mp_SigBit);
  169.     }
  170. }
  171.  
  172.  
  173. /*
  174. **  Closes down the ARexx port.
  175. **
  176. **  Like open_rexx(), close_rexx() does not deal with the libraries (and
  177. **  for analogous reasons).
  178. **
  179. */
  180. void close_rexx (void)
  181. {
  182.     if (rexx_port)
  183.     {
  184.     RemPort (rexx_port);
  185.  
  186.     while (rm = (RexxMsg *) GetMsg (rexx_port) )
  187.         rexx_reply (rm, RC_ERROR, NULL);
  188.  
  189.     DeletePort (rexx_port);
  190.     rexx_port = NULL;
  191.     rexx_mask = 0;
  192.     }
  193. }
  194.  
  195.  
  196. /*
  197. **  Handles all ARexx messages that accumulate at {rexx_port}.
  198. **
  199. **  The {rexx_port} is a global, as is {rm} (the {RexxMsg *}).
  200. **
  201. */
  202. void handle_rexx (void)
  203. {
  204.     int ser_soft_param = 0;
  205.     int ser_hard_param = 0;
  206.  
  207.     while (rm = (RexxMsg *)GetMsg (rexx_port) )
  208.     {
  209.     char *line;
  210.     char *result = 0;
  211.     char *tmp;
  212.     LONG rc = RC_OK;
  213.  
  214.     line = tmp = rm->rm_Args [0];
  215.     while ( (*tmp) && (*tmp++ != ':') )
  216.         ;
  217.  
  218.     while ( (*tmp) && (*tmp == ' ') )
  219.         ++tmp;
  220.  
  221.     switch (match (line, keywords) )
  222.     {
  223.     case OPTION_NOT_FOUND:
  224.         rc = RC_ERROR;
  225.         break;
  226.  
  227.  
  228.     case OPTION_COMMENT:
  229.         break;
  230.  
  231.     /*
  232.     **  General:
  233.     **    Add support to return the "old" values for these serial
  234.     **    param controls?
  235.     **
  236.     **    Or else call ser_soft_set() from each & return the result
  237.     **    of that?
  238.     **
  239.     */
  240.     case SER_BPS:
  241.         if (*tmp)
  242.         {
  243.         ser_bps = strtol (tmp, NULL, 0);
  244.         ser_soft_param = 1;
  245.         }
  246.         else if (alert_loc)
  247.         printf ("Invalid {bps} in rexx msg: {%s}\n", line);
  248.         break;
  249.  
  250.  
  251.     case SER_BITS:
  252.         if (*tmp)
  253.         {
  254.         ser_read_bits = ser_write_bits = strtol (tmp, NULL, 0);
  255.         ser_soft_param = 1;
  256.         }
  257.         else if (alert_loc)
  258.         printf ("Invalid {bits} in rexx msg {%s}.\n", line);
  259.         break;
  260.  
  261.  
  262.     case SER_STOP_BITS:
  263.         if (*tmp)
  264.         {
  265.         ser_stop_bits = strtol (tmp, NULL, 0);
  266.         ser_soft_param = 1;
  267.         }
  268.         else if (alert_loc)
  269.         printf ("Invalid {stop bits} in rexx msg {%s}.\n", line);
  270.         break;
  271.  
  272.  
  273.     case SER_7WIRE:
  274.         ser_7wire = 1;
  275.         ser_hard_param = 1;
  276.         break;
  277.  
  278.  
  279.     case SER_3WIRE:
  280.         ser_7wire = 0;
  281.         ser_hard_param = 1;
  282.         break;
  283.  
  284.  
  285.     case SER_XON_XOFF:
  286.         ser_xon_xoff = 1;
  287.         ser_soft_param = 1; /*** hard?? ***/
  288.         break;
  289.  
  290.  
  291.     case SER_NO_XON_XOFF:
  292.         ser_xon_xoff = 0;
  293.         ser_soft_param = 1; /*** hard?? ***/
  294.         break;
  295.  
  296.  
  297.     case SER_SHARED:
  298.         ser_exclusive = 0;
  299.         ser_hard_param = 1;
  300.         break;
  301.  
  302.  
  303.     case SER_EXCLUSIVE:
  304.         ser_exclusive = 1;
  305.         ser_hard_param = 1;
  306.         break;
  307.  
  308.  
  309.     case SER_NO_RAD_BOOGIE:
  310.         ser_rad_boogie = 0;
  311.         ser_hard_param = 1;
  312.         break;
  313.  
  314.  
  315.     case SER_RAD_BOOGIE:
  316.         ser_rad_boogie = 1;
  317.         ser_hard_param = 1;
  318.         break;
  319.  
  320.  
  321.     case SER_NO_PARITY:
  322.         ser_parity = 0;
  323.         ser_soft_param = 1;
  324.         break;
  325.  
  326.  
  327.     case SER_ODD_PARITY:
  328.         ser_parity = 1;
  329.         ser_soft_param = 1;
  330.         break;
  331.  
  332.  
  333.     case SER_EVEN_PARITY:
  334.         ser_parity = 2;
  335.         ser_soft_param = 1;
  336.         break;
  337.  
  338.  
  339.     case SET_WINDOW_TITLE:
  340.     {
  341.         char buf [256];
  342.  
  343.         int len;
  344.  
  345.         if (nether_name)
  346.         free (nether_name);
  347.  
  348.         /*
  349.         **    return old title; gets freed on way out...
  350.         **
  351.         */
  352.         result = window_title;        /*** Just use nw.Title??? ***/
  353.         nether_name = strdup (tmp);
  354.         len = sprintf
  355.         (
  356.         buf,
  357.         "sercli: with {%s} id {%s}",
  358.         nether_name,
  359.         prog_id
  360.         );
  361.         window_title = strdup (buf);        /*** Just use nw.Title??? ***/
  362.         SetWindowTitles (win, window_title, (UBYTE *)~0);
  363.  
  364.         rc = RC_OK;
  365.         break;
  366.     }
  367.  
  368.  
  369.     case SET_WINDOW_SIZE:
  370.     {
  371.         int new_width;
  372.         int new_height;
  373.  
  374.         rc = RC_ERROR;
  375.  
  376.         sscanf (tmp, "%d %d", &new_width, &new_height);
  377.         if ( (new_width > 0) && (new_height > 0) )
  378.         {
  379.         char buf [256];
  380.  
  381.         SizeWindow (win, new_width - win_width, new_height - win_height);
  382.  
  383.         sprintf (buf, "%d %d", win_width, win_height);
  384.         result = strdup (buf);
  385.  
  386.         win_width = new_width;
  387.         win_height = new_height;
  388.  
  389.         rc = RC_OK;
  390.         }
  391.         break;
  392.     }
  393.  
  394.  
  395.     case ALERT_LOC:
  396.         alert_loc = 1;
  397.         break;
  398.  
  399.  
  400.     case ALERT_SER:
  401.         alert_ser = 1;
  402.         break;
  403.  
  404.  
  405.     case NO_ALERT_LOC:
  406.         alert_loc = 0;
  407.         break;
  408.  
  409.  
  410.     case NO_ALERT_SER:
  411.         alert_ser = 0;
  412.         break;
  413.  
  414.  
  415.     case SER_QUERY:
  416.         /*
  417.         **    Not really and "error," but this'll do the job for now.
  418.         **
  419.         */
  420.         handle_error (error_type_serial, query_ser () );
  421.         break;
  422.  
  423.  
  424.     default:
  425.         if (alert_loc)
  426.         printf ("rexx command {%s} not implemented.\n", line);
  427.         rc = RC_ERROR;
  428.         break;
  429.     }
  430.  
  431.     rexx_reply (rm, rc, result);
  432.     if (result)
  433.         free (result);
  434.     }
  435.  
  436.     if (ser_hard_param)
  437.     {
  438.     close_ser ();
  439.     open_ser ();
  440.     }
  441.     else if (ser_soft_param)
  442.     set_ser_soft ();
  443. }
  444.  
  445. @
  446.  
  447.  
  448. 1.8
  449. log
  450. @Oops; forgot about rexx_mask -- shouldn't matter, but just to be safe,
  451. it's cleared now during rexx_close().
  452. @
  453. text
  454. @d4 1
  455. a4 1
  456. **  $Revision: 1.7 $
  457. d7 1
  458. a7 1
  459. **  $Date: 1993/06/10 16:43:21 $
  460. d9 5
  461. d34 1
  462. a62 1
  463.  
  464. d83 1
  465. a83 1
  466.     Forbid ();
  467. d85 8
  468. a92 4
  469.     if (FindPort (prog_id) )
  470.         exit (10);
  471.  
  472.     rexx_port = CreatePort (prog_id, 1);
  473. a93 2
  474.     Permit ();
  475.     rexx_mask = 1 << (rexx_port->mp_SigBit);
  476. a265 1
  477. //        char *cptr;     /*** UNUSED VAR ***/
  478. @
  479.  
  480.  
  481. 1.7
  482. log
  483. @In close_rexx(), clear global info so that multiple opens/closes can
  484. be handled correctly & safely.
  485. @
  486. text
  487. @d4 2
  488. a5 2
  489. **  $Revision: 1.6 $
  490. **  $Locker:  $
  491. d7 1
  492. a7 1
  493. **  $Date: 1993/06/06 10:34:37 $
  494. d108 1
  495. @
  496.  
  497.  
  498. 1.6
  499. log
  500. @Converted {rexx_name} to {prog_id}.  In many spots, then, deleted
  501. redundant {prog_id}.  (Well, in _some_ spots...)
  502. @
  503. text
  504. @d2 1
  505. a2 1
  506. **  $Source: WB_2.1:ho/RCS/rexx.c,v $
  507. d4 2
  508. a5 2
  509. **  $Revision: 1.5 $
  510. **  $Locker: rkr $
  511. d7 1
  512. a7 1
  513. **  $Date: 1993/06/06 10:26:32 $
  514. d107 1
  515. d258 1
  516. a258 1
  517.         char *cptr;
  518. @
  519.  
  520.  
  521. 1.5
  522. log
  523. @Made {FidoName} refs to {prog_id}
  524. @
  525. text
  526. @d2 1
  527. a2 1
  528. **  $Source: WB_2.1:ho/rcs/rexx.c,v $
  529. d4 2
  530. a5 2
  531. **  $Revision: 1.4 $
  532. **  $Locker:  $
  533. d7 1
  534. a7 1
  535. **  $Date: 1991/12/20 09:43:45 $
  536. a33 2
  537. char *rexx_name = "sercli";
  538.  
  539. d69 1
  540. a69 1
  541. **  Basically, creates a port with {rexx_name} (a global; that global
  542. d80 1
  543. a80 1
  544.     if (FindPort (rexx_name) )
  545. d83 1
  546. a83 1
  547.     rexx_port = CreatePort (rexx_name, 1);
  548. d273 1
  549. a273 1
  550.         "sercli: with {%s} fifo {%s}, rx {%s}",
  551. d275 1
  552. a275 2
  553.         prog_id,
  554.         rexx_name
  555. @
  556.  
  557.  
  558. 1.4
  559. log
  560. @*** empty log message ***
  561. @
  562. text
  563. @d2 1
  564. a2 1
  565. **  $Source: Workbench:personal/rkr/prog/sercli/src/rcs/rexx.c,v $
  566. d4 2
  567. a5 2
  568. **  $Revision: 1.3 $
  569. **  $Locker: rkr $
  570. d7 1
  571. a7 1
  572. **  $Date: 91/12/10 02:48:11 $
  573. d277 1
  574. a277 1
  575.         FifoName,
  576. @
  577.  
  578.  
  579. 1.3
  580. log
  581. @**  set {ser_hard_param = 1} for changes of rad boogie (_not_ a soft
  582.     param!)
  583.  
  584.  
  585. **  Added "ser query" ARexx command.
  586.  
  587.  
  588. @
  589. text
  590. @d4 1
  591. a4 1
  592. **  $Revision: 1.2 $
  593. d7 1
  594. a7 1
  595. **  $Date: 91/12/02 10:51:29 $
  596. @
  597.  
  598.  
  599. 1.2
  600. log
  601. @*** empty log message ***
  602. @
  603. text
  604. @d7 1
  605. a7 1
  606. **  $Date: 91/12/02 10:42:06 $
  607. d228 1
  608. a228 1
  609.         ser_soft_param = 1;
  610. d234 1
  611. a234 1
  612.         ser_soft_param = 1;
  613. d331 9
  614. @
  615.  
  616.  
  617. 1.1
  618. log
  619. @Initial revision
  620. @
  621. text
  622. @d2 6
  623. a7 6
  624. **  $Source$
  625. **  $Author$
  626. **  $Revision$
  627. **  $Locker$
  628. **  $State$
  629. **  $Date$
  630. d352 1
  631. a352 1
  632.     ser_soft_set ();
  633. @
  634.