home *** CD-ROM | disk | FTP | other *** search
- /*
- ** $Source: WB_2.1:homes/rkr/prog/sercli/src/RCS/sercli-config.c,v $
- ** $Author: rkr $
- ** $Revision: 1.7 $
- ** $Locker: rkr $
- ** $State: Exp $
- ** $Date: 1993/06/16 23:29:06 $
- **
- ** sercli (an Amiga .device <-> FIFO interface tool)
- ** Copyright (C) 1993 Richard Rauch
- **
- ** See /doc/sercli.doc and /COPYING for use and distribution license.
- **
- */
-
- #include "misc.h"
- #include "config.h"
- #include "sercli-config.h"
- #include "rexx.h"
-
- #include "keywords.h"
-
-
- /*
- ** Defaults
- ** Should move these to their respective areas... I.e., move
- ** {prog_id} to where FIFO stuff is handled, and the {ser_#?} stuff
- ** to serial.c...
- ** [{prog_id} used to be {FifoName}; now that it's changed, it
- ** belongs either here, or in the main code -- not necessarily
- ** w/FIFO handling.]
- **
- ** Or, alternatively, group all config stuff here (e.g., {alert_loc,
- ** alert_ser} )...
- **
- */
- char *prog_id = "sercli";
-
- char *ser_device_name = "serial.device";
-
- ULONG ser_device_unit = 0; /*** First available unit ***/
-
- ULONG ser_bps = 0; /*** 0's should be "use Prefs" ***/
- ULONG ser_write_bits = 8;
- ULONG ser_read_bits = 8;
- ULONG ser_stop_bits = 1;
- ULONG ser_7wire = 0;
- ULONG ser_xon_xoff = 0;
- ULONG ser_parity = 0;
-
- ULONG ser_exclusive = 0; /*** Not settable by prefs ***/
- ULONG ser_rad_boogie = 0;
-
-
- /*
- ** Reads in a file named in the global {config_file_name}.
- **
- ** Each line may contain an option of the form:
- **
- ** key: value
- **
- ** {key} must be the FIRST thing on a line (no spaces, tabs, etc,
- ** allowed).
- **
- ** Blank lines, lines beginning with tabs, or certain other chars, are
- ** considered comment lines (line-continuation is not supported, though it
- ** could be...)
- **
- **
- ** Action taken will vary...
- **
- */
- void read_sercli_config (void)
- {
- FILE *cfg_file;
-
- if (!(cfg_file = fopen (config_file_name, "r") ) )
- {
- if (alert_loc)
- printf ("couldn't open config file, {%s}!\n", config_file_name);
- }
- else
- {
- int lines_read = 0;
- char *line;
-
- while (line = get_line (cfg_file) )
- {
- char *tmp;
-
- ++lines_read;
- /*
- ** {tmp} is a handy var; it points to the first non-blank
- ** after the first colon in {line}.
- **
- */
- tmp = line;
- while ( (*tmp) && (*tmp++ != ':') )
- ;
-
- while ( (*tmp) && (*tmp == ' ') )
- ++tmp;
-
- switch (match (line, keywords) )
- {
- case OPTION_NOT_FOUND:
- if (alert_loc)
- printf ("line {%d}, unknown option {%s}.\n", lines_read, line);
- break;
-
- /*
- ** NOP...comment or empty line
- **
- */
- case OPTION_NULL:
- break;
-
-
- case ID_STRING:
- if (*tmp)
- prog_id = strdup (tmp);
- break;
-
-
- case DEVICE_NAME:
- if (*tmp)
- ser_device_name = strdup (tmp);
- break;
-
-
- case DEVICE_UNIT:
- if (*tmp)
- ser_device_unit = strtol (tmp, NULL, 0);
- else if (alert_loc)
- printf ("Invalid {device name} in line {%d}.\n", lines_read);
- break;
-
-
- case SER_BPS:
- if (*tmp)
- ser_bps = strtol (tmp, NULL, 0);
- else if (alert_loc)
- printf ("Invalid {bps} in line {%d}.\n", lines_read);
- break;
-
-
- case SER_BITS:
- if (*tmp)
- ser_read_bits = ser_write_bits = strtol (tmp, NULL, 0);
- else if (alert_loc)
- printf ("Invalid {bits} in line {%d}.\n", lines_read);
- break;
-
-
- case SER_STOP_BITS:
- if (*tmp)
- ser_stop_bits = strtol (tmp, NULL, 0);
- else if (alert_loc)
- printf ("Invalid {stop bits} in line {%d}.\n", lines_read);
- break;
-
-
- case SER_7WIRE:
- ser_7wire = 1;
- break;
-
-
- case SER_3WIRE:
- ser_7wire = 0;
- break;
-
-
- case SER_XON_XOFF:
- ser_xon_xoff = 1;
- break;
-
-
- case SER_NO_XON_XOFF:
- ser_xon_xoff = 0;
- break;
-
-
- case SER_SHARED:
- ser_exclusive = 0;
- break;
-
-
- case SER_EXCLUSIVE:
- ser_exclusive = 1;
- break;
-
-
- case SER_NO_RAD_BOOGIE:
- ser_rad_boogie = 0;
- break;
-
-
- case SER_RAD_BOOGIE:
- ser_rad_boogie = 1;
- break;
-
-
- case SER_NO_PARITY:
- ser_parity = 0;
- break;
-
-
- case SER_ODD_PARITY:
- ser_parity = 1;
- break;
-
-
- case SER_EVEN_PARITY:
- ser_parity = 2;
- break;
-
-
- case ALERT_LOC:
- alert_loc = 1;
- break;
-
-
- case ALERT_SER:
- alert_ser = 1;
- break;
-
-
- case NO_ALERT_LOC:
- alert_loc = 0;
- break;
-
-
- case NO_ALERT_SER:
- alert_ser = 0;
- break;
-
-
- default:
- if (alert_loc)
- printf ("line {%d}, {%s} not valid in config files.\n", lines_read, line);
- break;
- }
- }
-
- fclose (cfg_file);
- }
- }
-
-