home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / internet-tools / ipdial / source / sanaconfig.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-09  |  3.0 KB  |  114 lines

  1. /**
  2. ***  IPDial - SanaConfig.c
  3. ***
  4. ***  Tries to parse a SANA configuration file in ENV:sana2/.
  5. ***
  6. ***
  7. ***  This program is free software; you can redistribute it and/or modify
  8. ***  it under the terms of the GNU General Public License as published by
  9. ***  the Free Software Foundation; either version 2 of the License, or
  10. ***  (at your option) any later version.
  11. ***
  12. ***  This program is distributed in the hope that it will be useful,
  13. ***  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ***  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. ***  GNU General Public License for more details.
  16. ***
  17. ***  You should have received a copy of the GNU General Public License
  18. ***  along with this program; if not, write to the Free Software
  19. ***  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. ***
  21. ***  Authors: Jochen Wiedmann <wiedmann@neckar-alb.de>
  22. ***           Stefan Gybas <cab@studbox.uni-stuttgart.de>
  23. **/
  24.  
  25.  
  26.  
  27. /**
  28. ***  Include files
  29. **/
  30. #ifndef IPDIAL_H
  31. #include "IPDial.h"
  32. #endif
  33.  
  34.  
  35. /*** ReadSanaConfig() function
  36. ***
  37. ***  read device, unit, baud and handshake from SANA configuration file
  38. **/
  39. STRPTR ReadSanaConfig(STRPTR SanaDevName)
  40. {
  41.   FILE *ConfigFile;
  42.   UWORD linenum=0;
  43.   struct {
  44.       STRPTR device;
  45.       ULONG *unit;
  46.       ULONG *baud;
  47.       ULONG  rtscts;
  48.       ULONG  xonxoff;
  49.       STRPTR *crap;                    /* to filter out other options */
  50.   } SanaArgs;
  51.  
  52.   SanaArgs.device  = NULL;
  53.   SanaArgs.unit    = NULL;
  54.   SanaArgs.baud    = NULL;
  55.   SanaArgs.rtscts  = 0;
  56.   SanaArgs.xonxoff = 0;
  57.   SanaArgs.crap    = NULL;
  58.  
  59.   /* Create name of config file and open it */
  60.  
  61.   sprintf(ScratchBuffer,"ENV:sana2/%s.config", SanaDevName);
  62.   if(ConfigFile = fopen((char *) ScratchBuffer, "r"))
  63.   {
  64.     while(fgets((char *) ScratchBuffer, ScBufSize, ConfigFile))
  65.     {
  66.       linenum++;
  67.  
  68.       /* Skip empty or comment lines */
  69.  
  70.       if(*ScratchBuffer == '#' || *ScratchBuffer == '\r' || *ScratchBuffer == '\n')
  71.         continue;
  72.  
  73.       /* Not a comment: parse line */
  74.  
  75.       if (!StrReadArgs( ScratchBuffer,
  76.                         (LONG *) &SanaArgs,
  77.                         (STRPTR) "DEVICE/A,UNIT/A/N,BAUD/A/N,RTSCTS=7WIRE/S,XONXOFF/S,CRAP/M"))
  78.       {
  79.         fprintf(stderr, "Error in SANA config file line %d\n", linenum);
  80.         CleanupAndExit(10);
  81.       }
  82.  
  83.       if (SanaArgs.rtscts & SanaArgs.xonxoff)
  84.       {
  85.         fprintf(stderr, "Error in SANA config file: 7WIRE and XONXOFF both set\n");
  86.         CleanupAndExit(10);
  87.       }
  88.  
  89.       if (SanaArgs.rtscts)
  90.       {
  91.         SerialOpen(SanaArgs.device, *SanaArgs.unit, *SanaArgs.baud, (STRPTR)"7WIRE");
  92.       }
  93.       else if (SanaArgs.xonxoff)
  94.       {
  95.         SerialOpen(SanaArgs.device, *SanaArgs.unit, *SanaArgs.baud, (STRPTR)"XONXOFF");
  96.       }
  97.       else
  98.       {
  99.         SerialOpen(SanaArgs.device, *SanaArgs.unit, *SanaArgs.baud, (STRPTR)"NONE");
  100.       }
  101.  
  102.       SerialSetBaud(*SanaArgs.baud);
  103.       break;
  104.     }
  105.   }
  106.   else
  107.   {
  108.     fprintf(stderr, "SANA config file %s not found\n", ScratchBuffer);
  109.     CleanupAndExit(10);
  110.   }
  111.   fclose(ConfigFile);
  112.   return(SanaArgs.device);
  113. }
  114.