home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / libscsi1.zoo / LibScsi-0.01 / timeout.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-14  |  1.7 KB  |  96 lines

  1. /*
  2.  * timeout.c - Copyright Steve Woodford, August 1993.
  3.  *
  4.  * Parses a timeout string, as lifted from the SCSI.CNF file and
  5.  * writes the values found into the timeout structure for the
  6.  * specified SCSI target.
  7.  *
  8.  * If I recall, the argument 's' to Scsi_Set_Timeouts is modified...
  9.  */
  10.  
  11. #include <stdlib.h>
  12. #include <sys/types.h>
  13. #include <ctype.h>
  14. #include <sys/scsi.h>
  15. #include "libscsi.h"
  16.  
  17.  
  18. PRIVATE short   Break_Value(char **);
  19.  
  20.  
  21. PUBLIC  char *
  22. Scsi_Set_Timeouts(u_char id, char *s, Sc_Timeout *def)
  23. {
  24.     char    *p = s;
  25.     short    i, v,
  26.             *to,
  27.             *de = (short *)def;
  28.  
  29.     if ( s == (char *)0 )
  30.         return(s);
  31.  
  32.     if ( (id &= 0x07) > MAX_SCSI_ID )
  33.         return("Invalid Target Id");
  34.  
  35.     to = &(_Scsi_Timeouts[id & 0x07].st_normal);
  36.  
  37.     for (i = 0; *s; s++)
  38.     {
  39.         while ( *s && (*s != ',') )
  40.         {
  41.             if ( !isspace(*s) && ((*s < '0') || (*s > '9')) )
  42.                 return("Malformed Timeout String");
  43.             s++;
  44.         }
  45.         if ( *s )
  46.             i++;
  47.     }
  48.  
  49.     if ( i != ((sizeof(Sc_Timeout) / sizeof(short)) - 1) )
  50.         return("Invalid number of arguments");
  51.  
  52.     do {
  53.  
  54.         if ( (v = Break_Value(&p)) > 0 )
  55.             *to = v;
  56.         else if ( (de != (short *)0) && *de )
  57.             *to = *de;
  58.  
  59.         to++;
  60.  
  61.         if ( de != (short *)0 )
  62.             de++;
  63.  
  64.     } while (--i);
  65.  
  66.     return((char *)0);
  67. }
  68.  
  69. PRIVATE short
  70. Break_Value(char **p)
  71. {
  72.     char    *c = *p;
  73.     short    rv;
  74.  
  75.     if ( ! *c )
  76.         return(0);
  77.  
  78.     while ( isspace(*c) )
  79.         c++;
  80.  
  81.     if ( *c == ',' )
  82.     {
  83.         *p = &(c[1]);
  84.         return(0);
  85.     }
  86.  
  87.     for (*p = c; *c && (*c != ','); c++)
  88.         ;
  89.     if ( *c )
  90.         c++;
  91.  
  92.     rv = (short)atoi(*p);
  93.     *p = c;
  94.     return(rv);
  95. }
  96.