388aeac49b6f83b9d42b8a43995bc23ff27ed616
[openafs.git] / src / package / lex.l
1 %{
2
3 /*
4  * Copyright 2000, International Business Machines Corporation and others.
5  * All Rights Reserved.
6  * 
7  * This software has been released under the terms of the IBM Public
8  * License.  For details, see the LICENSE file in the top-level source
9  * directory or online at http://www.openafs.org/dl/license10.html
10  *
11  * lex.l:
12  *      Lexical definitions recognized by package, the AFS
13  *      workstation configuration facility.
14  */
15
16 #include <afsconfig.h>
17 #include <afs/param.h>
18
19 RCSID("$Header$");
20
21 #include <stdio.h>
22 #include <sys/types.h>
23 #include <sys/stat.h>
24
25 #include "globals.h"
26 #include "package.h"
27
28 #include "y.tab.h"
29
30 char *stash();
31 char *emalloc();
32
33 %}
34
35 /* definitions */
36 COM     #[^\n]*
37 W       [ \t]
38 D       [0-9]
39 L       [A-Za-z]
40 P       ("./"|"../"|"/")[^ \t\n#=\^\|\(\)\{\};]+
41 %%
42
43 {W}*{COM}       { dbgprint((stderr, "COMMENT\n"));
44                  return(COMMENT); }
45
46 ^{W}*\n         { dbgprint((stderr, "BLANKLINE\n"));
47                  return(BLANKLINE); }
48
49 {W}+            { dbgprint((stderr, "WHITESPACE\n"));
50                  return(WHITESPACE); }
51
52 ^{W}*{L}                {
53                   dbgprint((stderr, "FILETYPE %c\n", yytext[0]));
54                   switch(yytext[0])
55                     {
56                       case 'F' :
57                         return(REGTYPE);        /* regular file */
58                         break;
59                       case 'D' :
60                         return(DIRTYPE);        /* directory */
61                         break;
62                       case 'L' :
63                         return(LNKTYPE);        /* symbolic link */
64                         break;
65                       case 'B' :
66                         return(BLKTYPE);        /* block device */
67                         break;
68                       case 'C' :
69                         return(CHRTYPE);        /* character device */
70                         break;
71                       case 'S' :
72                         return(SOCKTYPE);       /* socket */
73                         break;
74                       case 'P' :
75                         return(PIPETYPE);       /* named pipe */
76                         break;
77                     }
78                 }
79
80 {L}             { dbgprint((stderr, "LETTER %c\n", yytext[0]));
81                  yylval.chval = yytext[0]; return(LETTER); }
82
83 {P}             { dbgprint((stderr, "PATHNAME %s\n", yytext));
84                  yylval.strval = stash(yytext); return(PATHNAME); }
85
86 \/              { dbgprint((stderr, "PATHNAME %s\n", yytext));
87                  yylval.strval = stash(yytext); return(PATHNAME); }
88
89 {D}             { dbgprint((stderr, "DIGIT %c\n", yytext[0]));
90                  yylval.usval = (u_short)(yytext[0] - '0'); return(DIGIT); }
91
92 \n              { dbgprint((stderr, "NEWLINE\n"));
93                  return(NEWLINE);}
94
95 %%
96
97 char *stash(s)
98 char *s;
99 /*
100  * Save string away in memory and return a pointer to it.  If
101  * no space could be found, quit with a fatal error.
102  */
103 {
104     char *strcpy();
105     char *ptr;
106
107     ptr = emalloc((unsigned)(strlen(s) + 1));
108     return(strcpy(ptr, s));
109 }