aruu

[MIRROR] Actual replacement for Busybox | suckless
git clone https://git.daat.foo/aruu.git
Log | Files | Refs | README | LICENSE

options.c (1381B)


      1 /* copyright (c) 1985 ceriel J.H. jacobs */
      2 
      3 #include "options.h"
      4 #include "display.h"
      5 #include "in_all.h"
      6 #include "output.h"
      7 #include <ctype.h>
      8 
      9 int   cflag;
     10 int   uflag;
     11 int   nflag;
     12 int   qflag;
     13 char *startcomm;
     14 
     15 static int parsopt(char *s);
     16 
     17 /*
     18  * read the options. return the argv pointer following them if there were
     19  * no errors, otherwise return 0
     20  */
     21 
     22 char **
     23 readoptions(char **argv)
     24 {
     25   char **av = argv + 1;
     26   char  *p;
     27 
     28   if ((p = getenv("YAP")) != 0) {
     29     (void)parsopt(p);
     30   }
     31   while (*av && **av == '-') {
     32     if (parsopt(*av)) {
     33       /*
     34        * error in option
     35        */
     36       putline(*av);
     37       putline(": illegal option\n");
     38       return (char **)0;
     39     }
     40     av++;
     41   }
     42   if (*av && **av == '+') {
     43     /*
     44      * command in command line
     45      */
     46     startcomm = *av + 1;
     47     av++;
     48   }
     49   return av;
     50 }
     51 
     52 static int
     53 parsopt(char *s)
     54 {
     55   int i;
     56 
     57   if (*s == '-')
     58     s++;
     59   if (isdigit(*s)) {
     60     /*
     61      * pagesize option
     62      */
     63     i = 0;
     64     do {
     65       i = i * 10 + *s++ - '0';
     66     } while (isdigit(*s));
     67     if (i < MINPAGESIZE)
     68       i = MINPAGESIZE;
     69     pagesize = i;
     70   }
     71   while (*s) {
     72     switch (*s++) {
     73       case 'c':
     74         cflag++;
     75         break;
     76       case 'n':
     77         nflag++;
     78         break;
     79       case 'u':
     80         uflag++;
     81         break;
     82       case 'q':
     83         qflag++;
     84         break;
     85       default:
     86         return 1;
     87     }
     88   }
     89   return 0;
     90 }