3 * Copyright (c) 1995 - 2001 Kungliga Tekniska Högskolan
4 * (Royal Institute of Technology, Stockholm, Sweden).
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the Institute nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 * This is to handle the definition of this symbol in some AIX
42 * headers, which will conflict with the definition that lex will
43 * generate for it. It's only a problem for AIX lex.
67 static unsigned lineno;
69 static char filename[256];
71 static void parse_filename (char *s);
72 static void parse_lineno (char *s);
76 ^\#[ ][0-9]+[ ]\"[^\n\"]*\".*\n { parse_filename (yytext); }
77 ^\#line[ ][0-9]+[ ]\"[^\n\"]*\".*\n { parse_filename (yytext); }
78 ^\#[ ][0-9]+.*\n { parse_lineno (yytext); }
79 ^\#line[ ][0-9]+.*\n { parse_lineno (yytext); }
82 const { return T_CONST; }
83 enum { return T_ENUM; }
84 struct { return T_STRUCT; }
85 union { return T_UNION; }
86 switch { return T_SWITCH; }
87 case { return T_CASE; }
88 typedef { return T_TYPEDEF; }
89 unsigned { return T_UNSIGNED; }
90 long { return T_LONG; }
91 afs_int32 { return T_LONG; }
92 int32_t { return T_LONG; }
93 afs_int64 { return T_LONGLONG; }
94 int64_t { return T_LONGLONG; }
95 u_long { return T_ULONG; }
96 uint32_t { return T_ULONG; }
97 afs_uint32 { return T_ULONG; }
98 uint64_t { return T_ULONGLONG; }
99 afs_uint64 { return T_ULONGLONG; }
100 short { return T_SHORT; }
101 int16_t { return T_SHORT; }
102 u_short { return T_USHORT; }
103 uint16_t { return T_USHORT; }
104 int { return T_INT; }
105 u_char { return T_UCHAR; }
106 char { return T_CHAR; }
107 string { return T_STRING; }
108 opaque { return T_OPAQUE; }
109 package { return T_PACKAGE; }
110 prefix { return T_PREFIX; }
111 proc { return T_PROC; }
112 error-function { return T_ERROR_FUNCTION; }
113 split { return T_SPLIT; }
114 multi { return T_MULTI; }
116 OUT { return T_OUT; }
117 INOUT { return T_INOUT; }
118 ASIS { return T_ASIS; }
119 "["|"]"|[,:;=()<>]|"{"|"}"|"*" { return *yytext; }
120 ^\%[^\n]*$ { yylval.name = strdup (yytext+1); return T_VERBATIM; }
121 -?[0-9]+ { yylval.constant = atoi(yytext); return T_CONSTANT; }
122 0[Xx][0-9a-fA-F]+ { yylval.constant = (int)strtol(yytext+2, NULL, 0x10); return T_CONSTANT; }
123 [A-Za-z_][A-Za-z0-9_]* {
126 sym = findsym(yytext);
129 yylval.name = strdup(yytext);
131 } else if (sym->type == YDR_TCONST)
133 else if (sym->type == YDR_TTYPEDEF
134 || sym->type == YDR_TENUM
135 || sym->type == YDR_TSTRUCT)
138 error_message (0, "Ignoring \"%s\"\n", yytext);
142 . { error_message(0, "Ignoring char(%c)\n", *yytext); }
154 error_message (int errorp, char *format, ...)
158 va_start (args, format);
159 fprintf (stderr, "%s:%d: ", filename, lineno);
160 vfprintf (stderr, format, args);
167 parse_filename (char *s)
171 while (!isspace((unsigned char)*s))
173 while (isspace((unsigned char)*s))
177 d1 = strchr (s, '"') + 1;
178 d2 = strchr (d1, '"');
180 if (strcmp (d1, "") != 0)
181 strlcpy (filename, d1, sizeof(filename));
185 parse_lineno (char *s)
187 while (!isspace((unsigned char)*s))
189 while (isspace((unsigned char)*s))