Add rx security index enum
[openafs.git] / src / uss / lex.l
1 %{
2 /*
3  * Copyright 2000, International Business Machines Corporation and others.
4  * All Rights Reserved.
5  * 
6  * This software has been released under the terms of the IBM Public
7  * License.  For details, see the LICENSE file in the top-level source
8  * directory or online at http://www.openafs.org/dl/license10.html
9  */
10
11 #include <afsconfig.h>
12 #include <afs/param.h>
13
14 #include <string.h>
15
16 #include "y.tab.h"
17 #include "uss_common.h"
18 #include "uss_procs.h"
19 int line=1;
20 #ifdef DEBUG
21 #define dprint(x)       {fprintf(stderr, x); fflush(stderr);}
22 #else
23 #define dprint(x)
24 #endif
25 void Replace(char *in, char *out);
26 %}
27
28 /* definitions */
29 C       #[^\n]*
30 W       [ \t]+
31 L       [A-Za-z]
32 S       [\.A-Z0-9a-z/$][^ \t\n#=\^\!\|\(\)\{\};]*
33 Q       \"[^\"\n]*[\"\n]
34 INVAL   [^ADEFLSVGX# ]
35 EOL     [\n]
36
37 %%
38 {C}             {dprint(("got a comment\n"));}
39 ^{EOL}          {dprint(("got an empty line\n")); line++;}
40 ^{INVAL}        {uss_procs_PrintErr(line," Invalid command \n");}
41 ^[D]{W}         {dprint(("got a Dir\n"));return(DIR_TKN);}
42 ^[F]{W}         {dprint(("got a File\n"));return(FILE_TKN);}
43 ^[L]{W}         {dprint(("got a Link\n"));return(LINK_TKN);}
44 ^[S]{W}         {dprint(("got a Symlink\n"));return(SYMLINK_TKN);}
45 ^[E]{W}         {dprint(("got an Echo\n"));return(ECHO_TKN);}
46 ^[X]{W}         {dprint(("got an Exec\n"));return(EXEC_TKN);}
47 ^[V]{W}         {dprint(("got a Vol\n"));return(VOL_TKN);}
48 ^[G]{W}         {dprint(("got a Group Declaration\n"));return(GROUP_TKN);}
49 ^[A]{W}         {dprint(("got an Auth\n"));return(AUTH_TKN);}
50 ^[Y]{W}         {dprint(("got a Vol1\n"));return(VOL1_TKN);}
51 {S}             {dprint(("got a string(%s)\n", yytext));
52                  Replace(yytext, yylval.strval);
53                  return(STRING_TKN);
54                 }
55 {Q}             {dprint(("got a quote: '%s'\n", yytext));
56                  Replace(yytext, yylval.strval);
57                  return(STRING_TKN);
58                 }
59 {EOL}           {line++;
60                  return(EOL_TKN);};
61
62 %%
63
64 /*
65  * This routine copies the in buf to out and replaces every known
66  * variable, e.g. $user, $1, ... by its value.  This value either
67  * comes from main program, or the handling routine will figure it
68  * out.  If given a quoted string, it ignores the first double quote
69  * and replaces the second with a null.
70  */
71
72 void
73 Replace(char *in, char *out)
74 { /*Replace*/
75
76     char *in_text, *in_var, *out_cp, VarNo;
77     int n;
78     int isQuotedString;
79     char *nullP;
80     
81     if(in[0] == '"') {
82         /*
83          * Strip the opening quote, remember we're handling a
84          * quoted string
85          */
86         in_text = in+1;
87         isQuotedString = 1;
88     }
89     else {
90         in_text = in;
91         isQuotedString = 0;
92     }
93     out_cp = out;
94     
95     while ((in_var = strchr(in_text, '$')) != NULL) {
96         while(in_text < in_var)
97             *out_cp++ = *in_text++;
98         VarNo = *(in_var+1);
99         if(VarNo >= '0' && VarNo <= '9') {
100             /*In the 0-9 range*/
101             n = VarNo - '0';
102             if (n == 0) {
103                 fprintf(stderr,
104                         "$0 is the program name.  Please start from $1.\n");
105                 exit(-1);
106             }
107             if (n > uss_VarMax){
108                 fprintf(stderr,
109                         "Illegal variable number ($%d is the largest acceptable)\n",
110                         uss_VarMax);
111                 exit(-1);
112             }
113             
114             strcpy(out_cp, uss_Var[n]);
115             out_cp += strlen(uss_Var[n]);
116             in_text += 2;
117         }
118         
119         else if (strncmp(in_var, "$USER", 5) == 0) {
120             strcpy(out_cp, uss_User);
121             out_cp += strlen(uss_User);
122             in_text += 5;
123         }
124         
125         else if (strncmp(in_var, "$UID", 4) == 0) {
126             strcpy(out_cp, uss_Uid);
127             out_cp += strlen(uss_Uid);
128             in_text += 4;
129         }
130         
131         else if (strncmp(in_var, "$SERVER", 7) == 0) {
132             strcpy(out_cp, uss_Server);
133             out_cp += strlen(uss_Server);
134             in_text += 7;
135         }
136         
137         else if (strncmp(in_var, "$PART", 5) == 0) {
138             strcpy(out_cp, uss_Partition);
139             out_cp += strlen(uss_Partition);
140             in_text += 5;
141         }
142         
143         else if (strncmp(in_var, "$MTPT", 5) == 0) {
144             strcpy(out_cp, uss_MountPoint);
145             out_cp += strlen(uss_MountPoint);
146             in_text += 5;
147         }
148         
149         else if (strncmp(in_var, "$NAME", 5) == 0) {
150             strcpy(out_cp, uss_RealName);
151             out_cp += strlen(uss_RealName);
152             in_text += 5;
153         }
154         
155         else if (strncmp(in_var, "$AUTO", 5) == 0) {
156             /*Picks a dir with minimum entries*/
157             uss_procs_PickADir(out, out_cp /*, uss_Auto*/);
158             printf("debug: $AUTO = %s\n", uss_Auto);
159             strcpy(out_cp, uss_Auto);
160             out_cp += strlen(uss_Auto);
161             in_text += 5;
162         }
163         else if (strncmp(in_var, "$PWEXPIRES", 10) == 0) {
164             sprintf(out_cp, " %d ", uss_Expires);
165             out_cp += strlen(out_cp);
166             in_text += 10;
167         }
168         
169         else{
170             /*Unknown variable*/
171             fprintf(stderr,
172                     "Warning: unknown variable in config file: '%s'\n",
173                     in_var);
174             *out_cp++ = *in_text++;
175         }
176     }
177     
178     /*
179      * At this point, we've copied over the in buffer up to the point
180      * of the last variable instance, so copy over the rest. If this
181      * is a quoted string, we place the terminating null where the
182      * ending double quote is.
183      */
184     while(*in_text != '\0')
185         *out_cp++ = *in_text++;
186     
187     if (isQuotedString) {
188         nullP = strchr(out, '"');
189         if (nullP == NULL)
190             nullP = out_cp;
191     }
192     else
193         nullP = out_cp;
194     *nullP = '\0';
195
196 } /*Replace*/
197
198 int yywrap(void)
199 {
200 return(1);
201 }