URI:
       tt3.c - plan9port - [fork] Plan 9 from user space
  HTML git clone git://src.adamsgaard.dk/plan9port
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
       tt3.c (1830B)
       ---
            1 /* t3.c: interpret commands affecting whole table */
            2 # include "t.h"
            3 struct optstr {
            4         char        *optnam;
            5         int        *optadd;
            6 } options [] = {
            7         "expand", &expflg,
            8         "EXPAND", &expflg,
            9         "center", &ctrflg,
           10         "CENTER", &ctrflg,
           11         "box", &boxflg,
           12         "BOX", &boxflg,
           13         "allbox", &allflg,
           14         "ALLBOX", &allflg,
           15         "doublebox", &dboxflg,
           16         "DOUBLEBOX", &dboxflg,
           17         "frame", &boxflg,
           18         "FRAME", &boxflg,
           19         "doubleframe", &dboxflg,
           20         "DOUBLEFRAME", &dboxflg,
           21         "tab", &tab,
           22         "TAB", &tab,
           23         "linesize", &linsize,
           24         "LINESIZE", &linsize,
           25         "delim", &delim1,
           26         "DELIM", &delim1,
           27         0, 0};
           28 
           29 
           30 void
           31 getcomm(void)
           32 {
           33         char        line[200], *cp, nb[25], *t;
           34         struct optstr *lp;
           35         int        c, ci, found;
           36 
           37         for (lp = options; lp->optnam; lp++)
           38                 *(lp->optadd) = 0;
           39         texname = texstr[texct=0];
           40         tab = '\t';
           41         Bprint(&tabout, ".nr %d \\n(.s\n", LSIZE);
           42         gets1(line, sizeof(line));
           43         /* see if this is a command line */
           44         if (strchr(line, ';') == 0) {
           45                 backrest(line);
           46                 return;
           47         }
           48         for (cp = line; (c = *cp) != ';'; cp++) {
           49                 if (!letter(c))
           50                         continue;
           51                 found = 0;
           52                 for (lp = options; lp->optadd; lp++) {
           53                         if (prefix(lp->optnam, cp)) {
           54                                 *(lp->optadd) = 1;
           55                                 cp += strlen(lp->optnam);
           56                                 if (letter(*cp))
           57                                         error("Misspelled global option");
           58                                 while (*cp == ' ')
           59                                         cp++;
           60                                 t = nb;
           61                                 if ( *cp == '(')
           62                                         while ((ci = *++cp) != ')')
           63                                                 *t++ = ci;
           64                                 else
           65                                         cp--;
           66                                 *t++ = 0;
           67                                 *t = 0;
           68                                 if (lp->optadd == &tab) {
           69                                         if (nb[0])
           70                                                 *(lp->optadd) = nb[0];
           71                                 }
           72                                 if (lp->optadd == &linsize)
           73                                         Bprint(&tabout, ".nr %d %s\n", LSIZE, nb);
           74                                 if (lp->optadd == &delim1) {
           75                                         delim1 = nb[0];
           76                                         delim2 = nb[1];
           77                                 }
           78                                 found = 1;
           79                                 break;
           80                         }
           81                 }
           82                 if (!found)
           83                         error("Illegal option");
           84         }
           85         cp++;
           86         backrest(cp);
           87         return;
           88 }
           89 
           90 
           91 void
           92 backrest(char *cp)
           93 {
           94         char        *s;
           95 
           96         for (s = cp; *s; s++)
           97                 ;
           98         un1getc('\n');
           99         while (s > cp)
          100                 un1getc(*--s);
          101         return;
          102 }