~ubuntu-branches/ubuntu/warty/openafs/warty

« back to all changes in this revision

Viewing changes to src/uss/lex.c

  • Committer: Bazaar Package Importer
  • Author(s): Sam Hartman
  • Date: 2004-01-10 16:37:33 UTC
  • Revision ID: james.westby@ubuntu.com-20040110163733-jvr0n1uahshlb1uu
Tags: upstream-1.2.11
ImportĀ upstreamĀ versionĀ 1.2.11

Show diffs side-by-side

added added

removed removed

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