summaryrefslogtreecommitdiffabout
path: root/lex.l
Side-by-side diff
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
@@ -45,30 +45,30 @@ SPEC [:@\\]
:include: return INCLUDE;
^{IDENT} {
- line_begin ();
- line_add (yytext, yyleng);
+ line_begin();
+ line_add(yytext, yyleng);
line_finish ();
return LHS; }
{IDENT}@{IDENT} {
- line_begin ();
- line_add (yytext, yyleng);
- line_finish ();
+ line_begin();
+ line_add(yytext, yyleng);
+ line_finish();
return EMAIL; }
-{IDENT} { line_begin ();
- line_add (yytext, yyleng);
- line_finish ();
+{IDENT} { line_begin();
+ line_add(yytext, yyleng);
+ line_finish();
return IDENT; }
/* Quoted strings */
-\"[^\\"\n]*\" { line_begin ();
- line_add (yytext, yyleng);
- line_finish ();
+\"[^\\"\n]*\" { line_begin();
+ line_add(yytext, yyleng);
+ line_finish();
return STRING; }
-\"[^\\"\n]*\\. { BEGIN (STR);
- line_begin ();
- line_add_unescape (yytext + 1, yyleng - 1); }
-<STR>[^\\"\n]*\\. { line_add_unescape (yytext, yyleng); }
-<STR>[^\\"\n]*\" { BEGIN (INITIAL);
+\"[^\\"\n]*\\. { BEGIN(STR);
+ line_begin();
+ line_add_unescape(yytext + 1, yyleng - 1); }
+<STR>[^\\"\n]*\\. { line_add_unescape(yytext, yyleng); }
+<STR>[^\\"\n]*\" { BEGIN(INITIAL);
if (yyleng > 1)
- line_add (yytext, yyleng - 1);
- line_finish ();
+ line_add(yytext, yyleng - 1);
+ line_finish();
return STRING; }
/* Other characters */
@@ -78,5 +78,5 @@ SPEC [:@\\]
\n { line_num++; return EOL; }
, return yytext[0];
-. { error_at_line (0, 0, file_name, line_num,
+. { error_at_line(0, 0, file_name, line_num,
"Stray character %03o in alias file", yytext[0]);
error_count++; }
@@ -84,8 +84,8 @@ SPEC [:@\\]
int
-yywrap ()
+yywrap()
{
- fclose (yyin);
- return 1;
+ fclose(yyin);
+ return 1;
}
@@ -93,33 +93,32 @@ static char escape_transtab[] = "\\\\a\ab\bf\fn\nr\rt\t";
int
-unescape_char (int c)
+unescape_char(int c)
{
- char *p;
-
- for (p = escape_transtab; *p; p += 2)
- {
- if (*p == c)
- return p[1];
- }
- return c;
+ char *p;
+
+ for (p = escape_transtab; *p; p += 2) {
+ if (*p == c)
+ return p[1];
+ }
+ return c;
}
void
-line_add (char *text, size_t len)
+line_add(char *text, size_t len)
{
- obstack_grow (&string_stk, text, len);
+ obstack_grow(&string_stk, text, len);
}
void
-line_add_unescape (char *text, size_t len)
+line_add_unescape(char *text, size_t len)
{
- char c;
- obstack_grow (&string_stk, text, len - 2);
- c = unescape_char (text[len - 1]);
- obstack_1grow (&string_stk, c);
+ char c;
+ obstack_grow(&string_stk, text, len - 2);
+ c = unescape_char(text[len - 1]);
+ obstack_1grow(&string_stk, c);
}
void
-line_begin ()
+line_begin()
{
}
@@ -128,84 +127,81 @@ void
line_finish ()
{
- obstack_1grow (&string_stk, 0);
- yylval.string = obstack_finish (&string_stk);
+ obstack_1grow(&string_stk, 0);
+ yylval.string = obstack_finish(&string_stk);
}
void
-openaliases (char *name)
+openaliases(char *name)
{
- yyin = fopen (name, "r");
- if (!yyin)
- error (1, errno, "cannot open file `%s'", name);
- file_name = name;
- line_num = 0;
+ yyin = fopen (name, "r");
+ if (!yyin)
+ error(1, errno, "cannot open file `%s'", name);
+ file_name = name;
+ line_num = 0;
}
void
-openaliases_prefix (char *prefix, char *name)
+openaliases_prefix(char *prefix, char *name)
{
- char *fullname = NULL;
- struct stat st;
+ char *fullname = NULL;
+ struct stat st;
- if (stat (prefix, &st))
- error (1, errno, "cannot stat `%s'", prefix);
-
- if (!S_ISDIR (st.st_mode))
- {
- char *p = strrchr (prefix, '/');
- if (p)
- *p = 0;
- else
- prefix = ".";
- }
- asprintf (&fullname, "%s/%s", prefix, name);
- openaliases (fullname);
- free (fullname);
+ if (stat(prefix, &st))
+ error(1, errno, "cannot stat `%s'", prefix);
+
+ if (!S_ISDIR(st.st_mode)) {
+ char *p = strrchr(prefix, '/');
+ if (p)
+ *p = 0;
+ else
+ prefix = ".";
+ }
+ asprintf(&fullname, "%s/%s", prefix, name);
+ openaliases(fullname);
+ free(fullname);
}
void
-init_lex ()
+init_lex()
{
- obstack_init (&string_stk);
- yy_flex_debug = 0;
+ obstack_init(&string_stk);
+ yy_flex_debug = 0;
}
void
-lex_debug (int debug)
+lex_debug(int debug)
{
- yy_flex_debug = debug;
+ yy_flex_debug = debug;
}
void
-read_include (SLIST **plist, char *name)
+read_include(SLIST **plist, char *name)
{
- char *p;
- char buffer[256];
- FILE *fp = fopen (name, "r");
+ char *p;
+ char buffer[256];
+ FILE *fp = fopen(name, "r");
- if (!fp)
- {
- error_at_line (0, 0, file_name, line_num,
- "cannot open include file `%s': %s",
- name, strerror (errno));
- error_count++;
- return;
- }
-
- while (p = fgets (buffer, sizeof buffer, fp))
- {
- char *q;
+ if (!fp) {
+ error_at_line(0, 0, file_name, line_num,
+ "cannot open include file `%s': %s",
+ name, strerror(errno));
+ error_count++;
+ return;
+ }
+
+ while (p = fgets(buffer, sizeof buffer, fp)) {
+ char *q;
- while (*p && isspace (*p))
- p++;
- if (*p == '#')
- continue;
- for (q = p + strlen (p) - 1; q > p && isspace (*q); q--)
- ;
- q[1] = 0;
- if (*p)
- slist_add (plist, strdup (p));
- }
- fclose (fp);
+ while (*p && isspace(*p))
+ p++;
+ if (*p == '#')
+ continue;
+ for (q = p + strlen(p) - 1; q > p && isspace(*q); q--)
+ ;
+ q[1] = 0;
+ if (*p)
+ slist_add(plist, strdup(p));
+ }
+ fclose(fp);
}

Return to:

Send suggestions and report system problems to the System administrator.