summaryrefslogtreecommitdiffabout
path: root/lex.l
Unidiff
Diffstat (limited to 'lex.l') (more/less context) (ignore whitespace changes)
-rw-r--r--lex.l188
1 files changed, 92 insertions, 96 deletions
diff --git a/lex.l b/lex.l
index ba48a9c..c71d4b9 100644
--- a/lex.l
+++ b/lex.l
@@ -46,4 +46,4 @@ SPEC [:@\\]
46^{IDENT} { 46^{IDENT} {
47 line_begin (); 47 line_begin();
48 line_add (yytext, yyleng); 48 line_add(yytext, yyleng);
49 line_finish (); 49 line_finish ();
@@ -51,23 +51,23 @@ SPEC [:@\\]
51{IDENT}@{IDENT} { 51{IDENT}@{IDENT} {
52 line_begin (); 52 line_begin();
53 line_add (yytext, yyleng); 53 line_add(yytext, yyleng);
54 line_finish (); 54 line_finish();
55 return EMAIL; } 55 return EMAIL; }
56{IDENT} { line_begin (); 56{IDENT} { line_begin();
57 line_add (yytext, yyleng); 57 line_add(yytext, yyleng);
58 line_finish (); 58 line_finish();
59 return IDENT; } 59 return IDENT; }
60 /* Quoted strings */ 60 /* Quoted strings */
61\"[^\\"\n]*\" { line_begin (); 61\"[^\\"\n]*\" { line_begin();
62 line_add (yytext, yyleng); 62 line_add(yytext, yyleng);
63 line_finish (); 63 line_finish();
64 return STRING; } 64 return STRING; }
65\"[^\\"\n]*\\. { BEGIN (STR); 65\"[^\\"\n]*\\. { BEGIN(STR);
66 line_begin (); 66 line_begin();
67 line_add_unescape (yytext + 1, yyleng - 1); } 67 line_add_unescape(yytext + 1, yyleng - 1); }
68<STR>[^\\"\n]*\\. { line_add_unescape (yytext, yyleng); } 68<STR>[^\\"\n]*\\. { line_add_unescape(yytext, yyleng); }
69<STR>[^\\"\n]*\" { BEGIN (INITIAL); 69<STR>[^\\"\n]*\" { BEGIN(INITIAL);
70 if (yyleng > 1) 70 if (yyleng > 1)
71 line_add (yytext, yyleng - 1); 71 line_add(yytext, yyleng - 1);
72 line_finish (); 72 line_finish();
73 return STRING; } 73 return STRING; }
@@ -79,3 +79,3 @@ SPEC [:@\\]
79 ,return yytext[0]; 79 ,return yytext[0];
80. { error_at_line (0, 0, file_name, line_num, 80. { error_at_line(0, 0, file_name, line_num,
81 "Stray character %03o in alias file", yytext[0]); 81 "Stray character %03o in alias file", yytext[0]);
@@ -85,6 +85,6 @@ SPEC [:@\\]
85int 85int
86yywrap () 86yywrap()
87{ 87{
88 fclose (yyin); 88 fclose(yyin);
89 return 1; 89 return 1;
90} 90}
@@ -94,12 +94,11 @@ static char escape_transtab[] = "\\\\a\ab\bf\fn\nr\rt\t";
94int 94int
95unescape_char (int c) 95unescape_char(int c)
96{ 96{
97 char *p; 97 char *p;
98 98
99 for (p = escape_transtab; *p; p += 2) 99 for (p = escape_transtab; *p; p += 2) {
100 { 100 if (*p == c)
101 if (*p == c) 101 return p[1];
102 return p[1]; 102 }
103 } 103 return c;
104 return c;
105} 104}
@@ -107,5 +106,5 @@ unescape_char (int c)
107void 106void
108line_add (char *text, size_t len) 107line_add(char *text, size_t len)
109{ 108{
110 obstack_grow (&string_stk, text, len); 109 obstack_grow(&string_stk, text, len);
111} 110}
@@ -113,8 +112,8 @@ line_add (char *text, size_t len)
113void 112void
114line_add_unescape (char *text, size_t len) 113line_add_unescape(char *text, size_t len)
115{ 114{
116 char c; 115 char c;
117 obstack_grow (&string_stk, text, len - 2); 116 obstack_grow(&string_stk, text, len - 2);
118 c = unescape_char (text[len - 1]); 117 c = unescape_char(text[len - 1]);
119 obstack_1grow (&string_stk, c); 118 obstack_1grow(&string_stk, c);
120} 119}
@@ -122,3 +121,3 @@ line_add_unescape (char *text, size_t len)
122void 121void
123line_begin () 122line_begin()
124{ 123{
@@ -129,4 +128,4 @@ line_finish ()
129{ 128{
130 obstack_1grow (&string_stk, 0); 129 obstack_1grow(&string_stk, 0);
131 yylval.string = obstack_finish (&string_stk); 130 yylval.string = obstack_finish(&string_stk);
132} 131}
@@ -134,9 +133,9 @@ line_finish ()
134void 133void
135openaliases (char *name) 134openaliases(char *name)
136{ 135{
137 yyin = fopen (name, "r"); 136 yyin = fopen (name, "r");
138 if (!yyin) 137 if (!yyin)
139 error (1, errno, "cannot open file `%s'", name); 138 error(1, errno, "cannot open file `%s'", name);
140 file_name = name; 139 file_name = name;
141 line_num = 0; 140 line_num = 0;
142} 141}
@@ -144,21 +143,20 @@ openaliases (char *name)
144void 143void
145openaliases_prefix (char *prefix, char *name) 144openaliases_prefix(char *prefix, char *name)
146{ 145{
147 char *fullname = NULL; 146 char *fullname = NULL;
148 struct stat st; 147 struct stat st;
149 148
150 if (stat (prefix, &st)) 149 if (stat(prefix, &st))
151 error (1, errno, "cannot stat `%s'", prefix); 150 error(1, errno, "cannot stat `%s'", prefix);
152 151
153 if (!S_ISDIR (st.st_mode)) 152 if (!S_ISDIR(st.st_mode)) {
154 { 153 char *p = strrchr(prefix, '/');
155 char *p = strrchr (prefix, '/'); 154 if (p)
156 if (p) 155 *p = 0;
157 *p = 0; 156 else
158 else 157 prefix = ".";
159 prefix = "."; 158 }
160 } 159 asprintf(&fullname, "%s/%s", prefix, name);
161 asprintf (&fullname, "%s/%s", prefix, name); 160 openaliases(fullname);
162 openaliases (fullname); 161 free(fullname);
163 free (fullname);
164} 162}
@@ -166,6 +164,6 @@ openaliases_prefix (char *prefix, char *name)
166void 164void
167init_lex () 165init_lex()
168{ 166{
169 obstack_init (&string_stk); 167 obstack_init(&string_stk);
170 yy_flex_debug = 0; 168 yy_flex_debug = 0;
171} 169}
@@ -173,5 +171,5 @@ init_lex ()
173void 171void
174lex_debug (int debug) 172lex_debug(int debug)
175{ 173{
176 yy_flex_debug = debug; 174 yy_flex_debug = debug;
177} 175}
@@ -179,32 +177,30 @@ lex_debug (int debug)
179void 177void
180read_include (SLIST **plist, char *name) 178read_include(SLIST **plist, char *name)
181{ 179{
182 char *p; 180 char *p;
183 char buffer[256]; 181 char buffer[256];
184 FILE *fp = fopen (name, "r"); 182 FILE *fp = fopen(name, "r");
185 183
186 if (!fp) 184 if (!fp) {
187 { 185 error_at_line(0, 0, file_name, line_num,
188 error_at_line (0, 0, file_name, line_num, 186 "cannot open include file `%s': %s",
189 "cannot open include file `%s': %s", 187 name, strerror(errno));
190 name, strerror (errno)); 188 error_count++;
191 error_count++; 189 return;
192 return; 190 }
193 } 191
194 192 while (p = fgets(buffer, sizeof buffer, fp)) {
195 while (p = fgets (buffer, sizeof buffer, fp)) 193 char *q;
196 {
197 char *q;
198 194
199 while (*p && isspace (*p)) 195 while (*p && isspace(*p))
200 p++; 196 p++;
201 if (*p == '#') 197 if (*p == '#')
202 continue; 198 continue;
203 for (q = p + strlen (p) - 1; q > p && isspace (*q); q--) 199 for (q = p + strlen(p) - 1; q > p && isspace(*q); q--)
204 ; 200 ;
205 q[1] = 0; 201 q[1] = 0;
206 if (*p) 202 if (*p)
207 slist_add (plist, strdup (p)); 203 slist_add(plist, strdup(p));
208 } 204 }
209 fclose (fp); 205 fclose(fp);
210} 206}

Return to:

Send suggestions and report system problems to the System administrator.