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

  1. head    1.7;
  2. access;
  3. symbols
  4.     sercli_v1_10:1.7
  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.7;
  12. comment    @**  @;
  13.  
  14.  
  15. 1.7
  16. date    93.06.16.23.29.06;    author rkr;    state Exp;
  17. branches;
  18. next    1.6;
  19.  
  20. 1.6
  21. date    93.06.06.10.34.37;    author rkr;    state Exp;
  22. branches;
  23. next    1.5;
  24.  
  25. 1.5
  26. date    93.06.06.10.26.32;    author rkr;    state Exp;
  27. branches;
  28. next    1.4;
  29.  
  30. 1.4
  31. date    91.12.20.09.43.42;    author rkr;    state Exp;
  32. branches;
  33. next    1.3;
  34.  
  35. 1.3
  36. date    91.12.10.02.48.08;    author rkr;    state Exp;
  37. branches;
  38. next    1.2;
  39.  
  40. 1.2
  41. date    91.12.02.10.51.26;    author rkr;    state Exp;
  42. branches;
  43. next    1.1;
  44.  
  45. 1.1
  46. date    91.11.28.08.25.15;    author rkr;    state Exp;
  47. branches;
  48. next    ;
  49.  
  50.  
  51. desc
  52. @sercli is a program to permit shell-like interface to the serial port,
  53. while also permitting easy config- and run-time-control over the way the
  54. serial port (or even _which_ serial port) is used.
  55.  
  56. @
  57.  
  58.  
  59. 1.7
  60. log
  61. @Added per-file copyright notice, as suggested by GPL.
  62. @
  63. text
  64. @/*
  65. **  $Source: WB_2.1:homes/rkr/prog/sercli/src/RCS/sercli-config.c,v $
  66. **  $Author: rkr $
  67. **  $Revision: 1.6 $
  68. **  $Locker:  $
  69. **  $State: Exp $
  70. **  $Date: 1993/06/06 10:34:37 $
  71. **
  72. **  sercli (an Amiga .device <-> FIFO interface tool)
  73. **  Copyright (C) 1993  Richard Rauch
  74. **
  75. **  See /doc/sercli.doc and /COPYING for use and distribution license.
  76. **
  77. */
  78.  
  79. #include "misc.h"
  80. #include "config.h"
  81. #include "sercli-config.h"
  82. #include "rexx.h"
  83.  
  84. #include "keywords.h"
  85.  
  86.  
  87. /*
  88. **  Defaults
  89. **    Should move these to their respective areas...    I.e., move
  90. **    {prog_id} to where FIFO stuff is handled, and the {ser_#?} stuff
  91. **    to serial.c...
  92. **        [{prog_id} used to be {FifoName}; now that it's changed, it
  93. **         belongs either here, or in the main code -- not necessarily
  94. **         w/FIFO handling.]
  95. **
  96. **    Or, alternatively, group all config stuff here (e.g., {alert_loc,
  97. **    alert_ser} )...
  98. **
  99. */
  100. char *prog_id = "sercli";
  101.  
  102. char *ser_device_name = "serial.device";
  103.  
  104. ULONG ser_device_unit = 0;  /*** First available unit ***/
  105.  
  106. ULONG ser_bps = 0;        /*** 0's should be "use Prefs" ***/
  107. ULONG ser_write_bits = 8;
  108. ULONG ser_read_bits = 8;
  109. ULONG ser_stop_bits = 1;
  110. ULONG ser_7wire = 0;
  111. ULONG ser_xon_xoff = 0;
  112. ULONG ser_parity = 0;
  113.  
  114. ULONG ser_exclusive = 0;    /*** Not settable by prefs ***/
  115. ULONG ser_rad_boogie = 0;
  116.  
  117.  
  118. /*
  119. **  Reads in a file named in the global {config_file_name}.
  120. **
  121. **  Each line may contain an option of the form:
  122. **
  123. **    key: value
  124. **
  125. **  {key} must be the FIRST thing on a line (no spaces, tabs, etc,
  126. **  allowed).
  127. **
  128. **  Blank lines, lines beginning with tabs, or certain other chars, are
  129. **  considered comment lines (line-continuation is not supported, though it
  130. **  could be...)
  131. **
  132. **
  133. **  Action taken will vary...
  134. **
  135. */
  136. void read_sercli_config (void)
  137. {
  138.     FILE *cfg_file;
  139.  
  140.     if (!(cfg_file = fopen (config_file_name, "r") ) )
  141.     {
  142.     if (alert_loc)
  143.         printf ("couldn't open config file, {%s}!\n", config_file_name);
  144.     }
  145.     else
  146.     {
  147.     int lines_read = 0;
  148.     char *line;
  149.  
  150.     while (line = get_line (cfg_file) )
  151.     {
  152.         char *tmp;
  153.  
  154.         ++lines_read;
  155.         /*
  156.         **    {tmp} is a handy var; it points to the first non-blank
  157.         **    after the first colon in {line}.
  158.         **
  159.         */
  160.         tmp = line;
  161.         while ( (*tmp) && (*tmp++ != ':') )
  162.         ;
  163.  
  164.         while ( (*tmp) && (*tmp == ' ') )
  165.         ++tmp;
  166.  
  167.         switch (match (line, keywords) )
  168.         {
  169.         case OPTION_NOT_FOUND:
  170.         if (alert_loc)
  171.             printf ("line {%d}, unknown option {%s}.\n", lines_read, line);
  172.         break;
  173.  
  174.         /*
  175.         **    NOP...comment or empty line
  176.         **
  177.         */
  178.         case OPTION_NULL:
  179.         break;
  180.  
  181.  
  182.         case ID_STRING:
  183.         if (*tmp)
  184.             prog_id = strdup (tmp);
  185.         break;
  186.  
  187.  
  188.         case DEVICE_NAME:
  189.         if (*tmp)
  190.             ser_device_name = strdup (tmp);
  191.         break;
  192.  
  193.  
  194.         case DEVICE_UNIT:
  195.         if (*tmp)
  196.             ser_device_unit = strtol (tmp, NULL, 0);
  197.         else if (alert_loc)
  198.             printf ("Invalid {device name} in line {%d}.\n", lines_read);
  199.         break;
  200.  
  201.  
  202.         case SER_BPS:
  203.         if (*tmp)
  204.             ser_bps = strtol (tmp, NULL, 0);
  205.         else if (alert_loc)
  206.             printf ("Invalid {bps} in line {%d}.\n", lines_read);
  207.         break;
  208.  
  209.  
  210.         case SER_BITS:
  211.         if (*tmp)
  212.             ser_read_bits = ser_write_bits = strtol (tmp, NULL, 0);
  213.         else if (alert_loc)
  214.             printf ("Invalid {bits} in line {%d}.\n", lines_read);
  215.         break;
  216.  
  217.  
  218.         case SER_STOP_BITS:
  219.         if (*tmp)
  220.             ser_stop_bits = strtol (tmp, NULL, 0);
  221.         else if (alert_loc)
  222.             printf ("Invalid {stop bits} in line {%d}.\n", lines_read);
  223.         break;
  224.  
  225.  
  226.         case SER_7WIRE:
  227.         ser_7wire = 1;
  228.         break;
  229.  
  230.  
  231.         case SER_3WIRE:
  232.         ser_7wire = 0;
  233.         break;
  234.  
  235.  
  236.         case SER_XON_XOFF:
  237.         ser_xon_xoff = 1;
  238.         break;
  239.  
  240.  
  241.         case SER_NO_XON_XOFF:
  242.         ser_xon_xoff = 0;
  243.         break;
  244.  
  245.  
  246.         case SER_SHARED:
  247.         ser_exclusive = 0;
  248.         break;
  249.  
  250.  
  251.         case SER_EXCLUSIVE:
  252.         ser_exclusive = 1;
  253.         break;
  254.  
  255.  
  256.         case SER_NO_RAD_BOOGIE:
  257.         ser_rad_boogie = 0;
  258.         break;
  259.  
  260.  
  261.         case SER_RAD_BOOGIE:
  262.         ser_rad_boogie = 1;
  263.         break;
  264.  
  265.  
  266.         case SER_NO_PARITY:
  267.         ser_parity = 0;
  268.         break;
  269.  
  270.  
  271.         case SER_ODD_PARITY:
  272.         ser_parity = 1;
  273.         break;
  274.  
  275.  
  276.         case SER_EVEN_PARITY:
  277.         ser_parity = 2;
  278.         break;
  279.  
  280.  
  281.         case ALERT_LOC:
  282.         alert_loc = 1;
  283.         break;
  284.  
  285.  
  286.         case ALERT_SER:
  287.         alert_ser = 1;
  288.         break;
  289.  
  290.  
  291.         case NO_ALERT_LOC:
  292.         alert_loc = 0;
  293.         break;
  294.  
  295.  
  296.         case NO_ALERT_SER:
  297.         alert_ser = 0;
  298.         break;
  299.  
  300.  
  301.         default:
  302.         if (alert_loc)
  303.             printf ("line {%d}, {%s} not valid in config files.\n", lines_read, line);
  304.         break;
  305.         }
  306.     }
  307.  
  308.     fclose (cfg_file);
  309.     }
  310. }
  311.  
  312. @
  313.  
  314.  
  315. 1.6
  316. log
  317. @Converted {rexx_name} to {prog_id}.  In many spots, then, deleted
  318. redundant {prog_id}.  (Well, in _some_ spots...)
  319. @
  320. text
  321. @d2 1
  322. a2 1
  323. **  $Source: WB_2.1:ho/RCS/sercli-config.c,v $
  324. d4 2
  325. a5 2
  326. **  $Revision: 1.5 $
  327. **  $Locker: rkr $
  328. d7 6
  329. a12 1
  330. **  $Date: 1993/06/06 10:26:32 $
  331. @
  332.  
  333.  
  334. 1.5
  335. log
  336. @Made {FidoName} refs to {prog_id}
  337. @
  338. text
  339. @d2 1
  340. a2 1
  341. **  $Source: WB_2.1:ho/rcs/sercli-config.c,v $
  342. d4 2
  343. a5 2
  344. **  $Revision: 1.4 $
  345. **  $Locker:  $
  346. d7 1
  347. a7 1
  348. **  $Date: 1991/12/20 09:43:42 $
  349. d116 1
  350. a116 4
  351.         {
  352.             prog_id = strdup (tmp);    /*** REDUNDANT! ***/
  353.             rexx_name = strdup (tmp);
  354.         }
  355. @
  356.  
  357.  
  358. 1.4
  359. log
  360. @*** empty log message ***
  361. @
  362. text
  363. @d2 1
  364. a2 1
  365. **  $Source: Workbench:personal/rkr/prog/sercli/src/rcs/sercli-config.c,v $
  366. d4 2
  367. a5 2
  368. **  $Revision: 1.3 $
  369. **  $Locker: rkr $
  370. d7 1
  371. a7 1
  372. **  $Date: 91/12/10 02:48:08 $
  373. d22 1
  374. a22 1
  375. **    {FifoName} to where FIFO stuff is handled, and the {ser_#?} stuff
  376. d24 3
  377. d32 1
  378. a32 1
  379. char *FifoName = "sercli";
  380. d117 1
  381. a117 1
  382.             FifoName = strdup (tmp);    /*** REDUNDANT! ***/
  383. @
  384.  
  385.  
  386. 1.3
  387. log
  388. @*** empty log message ***
  389. @
  390. text
  391. @d4 1
  392. a4 1
  393. **  $Revision: 1.2 $
  394. d7 1
  395. a7 1
  396. **  $Date: 91/12/02 10:51:26 $
  397. @
  398.  
  399.  
  400. 1.2
  401. log
  402. @*** empty log message ***
  403. @
  404. text
  405. @d7 1
  406. a7 1
  407. **  $Date: 91/12/02 10:42:03 $
  408. @
  409.  
  410.  
  411. 1.1
  412. log
  413. @Initial revision
  414. @
  415. text
  416. @d2 6
  417. a7 6
  418. **  $Source$
  419. **  $Author$
  420. **  $Revision$
  421. **  $Locker$
  422. **  $State$
  423. **  $Date$
  424. d239 2
  425. @
  426.