home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / prog / utils / sercli.shr / sercli / src / sercli-config.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-16  |  4.3 KB  |  249 lines

  1. /*
  2. **  $Source: WB_2.1:homes/rkr/prog/sercli/src/RCS/sercli-config.c,v $
  3. **  $Author: rkr $
  4. **  $Revision: 1.7 $
  5. **  $Locker: rkr $
  6. **  $State: Exp $
  7. **  $Date: 1993/06/16 23:29:06 $
  8. **
  9. **  sercli (an Amiga .device <-> FIFO interface tool)
  10. **  Copyright (C) 1993  Richard Rauch
  11. **
  12. **  See /doc/sercli.doc and /COPYING for use and distribution license.
  13. **
  14. */
  15.  
  16. #include "misc.h"
  17. #include "config.h"
  18. #include "sercli-config.h"
  19. #include "rexx.h"
  20.  
  21. #include "keywords.h"
  22.  
  23.  
  24. /*
  25. **  Defaults
  26. **    Should move these to their respective areas...    I.e., move
  27. **    {prog_id} to where FIFO stuff is handled, and the {ser_#?} stuff
  28. **    to serial.c...
  29. **        [{prog_id} used to be {FifoName}; now that it's changed, it
  30. **         belongs either here, or in the main code -- not necessarily
  31. **         w/FIFO handling.]
  32. **
  33. **    Or, alternatively, group all config stuff here (e.g., {alert_loc,
  34. **    alert_ser} )...
  35. **
  36. */
  37. char *prog_id = "sercli";
  38.  
  39. char *ser_device_name = "serial.device";
  40.  
  41. ULONG ser_device_unit = 0;  /*** First available unit ***/
  42.  
  43. ULONG ser_bps = 0;        /*** 0's should be "use Prefs" ***/
  44. ULONG ser_write_bits = 8;
  45. ULONG ser_read_bits = 8;
  46. ULONG ser_stop_bits = 1;
  47. ULONG ser_7wire = 0;
  48. ULONG ser_xon_xoff = 0;
  49. ULONG ser_parity = 0;
  50.  
  51. ULONG ser_exclusive = 0;    /*** Not settable by prefs ***/
  52. ULONG ser_rad_boogie = 0;
  53.  
  54.  
  55. /*
  56. **  Reads in a file named in the global {config_file_name}.
  57. **
  58. **  Each line may contain an option of the form:
  59. **
  60. **    key: value
  61. **
  62. **  {key} must be the FIRST thing on a line (no spaces, tabs, etc,
  63. **  allowed).
  64. **
  65. **  Blank lines, lines beginning with tabs, or certain other chars, are
  66. **  considered comment lines (line-continuation is not supported, though it
  67. **  could be...)
  68. **
  69. **
  70. **  Action taken will vary...
  71. **
  72. */
  73. void read_sercli_config (void)
  74. {
  75.     FILE *cfg_file;
  76.  
  77.     if (!(cfg_file = fopen (config_file_name, "r") ) )
  78.     {
  79.     if (alert_loc)
  80.         printf ("couldn't open config file, {%s}!\n", config_file_name);
  81.     }
  82.     else
  83.     {
  84.     int lines_read = 0;
  85.     char *line;
  86.  
  87.     while (line = get_line (cfg_file) )
  88.     {
  89.         char *tmp;
  90.  
  91.         ++lines_read;
  92.         /*
  93.         **    {tmp} is a handy var; it points to the first non-blank
  94.         **    after the first colon in {line}.
  95.         **
  96.         */
  97.         tmp = line;
  98.         while ( (*tmp) && (*tmp++ != ':') )
  99.         ;
  100.  
  101.         while ( (*tmp) && (*tmp == ' ') )
  102.         ++tmp;
  103.  
  104.         switch (match (line, keywords) )
  105.         {
  106.         case OPTION_NOT_FOUND:
  107.         if (alert_loc)
  108.             printf ("line {%d}, unknown option {%s}.\n", lines_read, line);
  109.         break;
  110.  
  111.         /*
  112.         **    NOP...comment or empty line
  113.         **
  114.         */
  115.         case OPTION_NULL:
  116.         break;
  117.  
  118.  
  119.         case ID_STRING:
  120.         if (*tmp)
  121.             prog_id = strdup (tmp);
  122.         break;
  123.  
  124.  
  125.         case DEVICE_NAME:
  126.         if (*tmp)
  127.             ser_device_name = strdup (tmp);
  128.         break;
  129.  
  130.  
  131.         case DEVICE_UNIT:
  132.         if (*tmp)
  133.             ser_device_unit = strtol (tmp, NULL, 0);
  134.         else if (alert_loc)
  135.             printf ("Invalid {device name} in line {%d}.\n", lines_read);
  136.         break;
  137.  
  138.  
  139.         case SER_BPS:
  140.         if (*tmp)
  141.             ser_bps = strtol (tmp, NULL, 0);
  142.         else if (alert_loc)
  143.             printf ("Invalid {bps} in line {%d}.\n", lines_read);
  144.         break;
  145.  
  146.  
  147.         case SER_BITS:
  148.         if (*tmp)
  149.             ser_read_bits = ser_write_bits = strtol (tmp, NULL, 0);
  150.         else if (alert_loc)
  151.             printf ("Invalid {bits} in line {%d}.\n", lines_read);
  152.         break;
  153.  
  154.  
  155.         case SER_STOP_BITS:
  156.         if (*tmp)
  157.             ser_stop_bits = strtol (tmp, NULL, 0);
  158.         else if (alert_loc)
  159.             printf ("Invalid {stop bits} in line {%d}.\n", lines_read);
  160.         break;
  161.  
  162.  
  163.         case SER_7WIRE:
  164.         ser_7wire = 1;
  165.         break;
  166.  
  167.  
  168.         case SER_3WIRE:
  169.         ser_7wire = 0;
  170.         break;
  171.  
  172.  
  173.         case SER_XON_XOFF:
  174.         ser_xon_xoff = 1;
  175.         break;
  176.  
  177.  
  178.         case SER_NO_XON_XOFF:
  179.         ser_xon_xoff = 0;
  180.         break;
  181.  
  182.  
  183.         case SER_SHARED:
  184.         ser_exclusive = 0;
  185.         break;
  186.  
  187.  
  188.         case SER_EXCLUSIVE:
  189.         ser_exclusive = 1;
  190.         break;
  191.  
  192.  
  193.         case SER_NO_RAD_BOOGIE:
  194.         ser_rad_boogie = 0;
  195.         break;
  196.  
  197.  
  198.         case SER_RAD_BOOGIE:
  199.         ser_rad_boogie = 1;
  200.         break;
  201.  
  202.  
  203.         case SER_NO_PARITY:
  204.         ser_parity = 0;
  205.         break;
  206.  
  207.  
  208.         case SER_ODD_PARITY:
  209.         ser_parity = 1;
  210.         break;
  211.  
  212.  
  213.         case SER_EVEN_PARITY:
  214.         ser_parity = 2;
  215.         break;
  216.  
  217.  
  218.         case ALERT_LOC:
  219.         alert_loc = 1;
  220.         break;
  221.  
  222.  
  223.         case ALERT_SER:
  224.         alert_ser = 1;
  225.         break;
  226.  
  227.  
  228.         case NO_ALERT_LOC:
  229.         alert_loc = 0;
  230.         break;
  231.  
  232.  
  233.         case NO_ALERT_SER:
  234.         alert_ser = 0;
  235.         break;
  236.  
  237.  
  238.         default:
  239.         if (alert_loc)
  240.             printf ("line {%d}, {%s} not valid in config files.\n", lines_read, line);
  241.         break;
  242.         }
  243.     }
  244.  
  245.     fclose (cfg_file);
  246.     }
  247. }
  248.  
  249.