rpc_scan.c (8874) | rpc_scan.c (12798) |
---|---|
1/* @(#)rpc_scan.c 2.1 88/08/01 4.0 RPCSRC */ | |
2/* 3 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 4 * unrestricted use provided that this legend is included on all tape 5 * media and as a part of the software program in whole or part. Users 6 * may copy or modify Sun RPC without charge, but are not authorized 7 * to license or distribute it to anyone else except as part of a product or 8 * program developed by the user. | 1/* 2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 3 * unrestricted use provided that this legend is included on all tape 4 * media and as a part of the software program in whole or part. Users 5 * may copy or modify Sun RPC without charge, but are not authorized 6 * to license or distribute it to anyone else except as part of a product or 7 * program developed by the user. |
9 * | 8 * |
10 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 11 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 12 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. | 9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 10 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. |
13 * | 12 * |
14 * Sun RPC is provided with no support and without any obligation on the 15 * part of Sun Microsystems, Inc. to assist in its use, correction, 16 * modification or enhancement. | 13 * Sun RPC is provided with no support and without any obligation on the 14 * part of Sun Microsystems, Inc. to assist in its use, correction, 15 * modification or enhancement. |
17 * | 16 * |
18 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 19 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 20 * OR ANY PART THEREOF. | 17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 19 * OR ANY PART THEREOF. |
21 * | 20 * |
22 * In no event will Sun Microsystems, Inc. be liable for any lost revenue 23 * or profits or other special, indirect and consequential damages, even if 24 * Sun has been advised of the possibility of such damages. | 21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue 22 * or profits or other special, indirect and consequential damages, even if 23 * Sun has been advised of the possibility of such damages. |
25 * | 24 * |
26 * Sun Microsystems, Inc. 27 * 2550 Garcia Avenue 28 * Mountain View, California 94043 29 */ | 25 * Sun Microsystems, Inc. 26 * 2550 Garcia Avenue 27 * Mountain View, California 94043 28 */ |
29 30#ident "@(#)rpc_scan.c 1.13 93/07/05 SMI" 31 |
|
30#ifndef lint | 32#ifndef lint |
31/*static char sccsid[] = "from: @(#)rpc_scan.c 1.6 87/06/24 (C) 1987 SMI";*/ 32static char rcsid[] = "$Id: rpc_scan.c,v 1.1 1994/08/07 18:01:34 wollman Exp $"; | 33static char sccsid[] = "@(#)rpc_scan.c 1.11 89/02/22 (C) 1987 SMI"; |
33#endif 34 35/* | 34#endif 35 36/* |
36 * rpc_scan.c, Scanner for the RPC protocol compiler 37 * Copyright (C) 1987, Sun Microsystems, Inc. | 37 * rpc_scan.c, Scanner for the RPC protocol compiler 38 * Copyright (C) 1987, Sun Microsystems, Inc. |
38 */ | 39 */ |
40 41#include <sys/wait.h> |
|
39#include <stdio.h> 40#include <ctype.h> | 42#include <stdio.h> 43#include <ctype.h> |
41#include <strings.h> | 44#include |
42#include "rpc_scan.h" | 45#include "rpc_scan.h" |
46#include "rpc_parse.h" |
|
43#include "rpc_util.h" 44 45#define startcomment(where) (where[0] == '/' && where[1] == '*') 46#define endcomment(where) (where[-1] == '*' && where[0] == '/') 47 48static int pushed = 0; /* is a token pushed */ 49static token lasttok; /* last token, if pushed */ 50 | 47#include "rpc_util.h" 48 49#define startcomment(where) (where[0] == '/' && where[1] == '*') 50#define endcomment(where) (where[-1] == '*' && where[0] == '/') 51 52static int pushed = 0; /* is a token pushed */ 53static token lasttok; /* last token, if pushed */ 54 |
51static int unget_token(), findstrconst(), findconst(), findkind(), cppline(), 52 directive(), printdirective(), docppline(); | 55static int unget_token __P(( token * )); 56static int findstrconst __P(( char **, char **)); 57static int findchrconst __P(( char **, char **)); 58static int findconst __P(( char **, char **)); 59static int findkind __P(( char **, token * )); 60static int cppline __P(( char * )); 61static int directive __P(( char * )); 62static int printdirective __P(( char * )); 63static int docppline __P(( char *, int *, char ** )); 64 |
53/* | 65/* |
54 * scan expecting 1 given token | 66 * scan expecting 1 given token |
55 */ 56void 57scan(expect, tokp) 58 tok_kind expect; 59 token *tokp; 60{ 61 get_token(tokp); 62 if (tokp->kind != expect) { 63 expected1(expect); 64 } 65} 66 67/* | 67 */ 68void 69scan(expect, tokp) 70 tok_kind expect; 71 token *tokp; 72{ 73 get_token(tokp); 74 if (tokp->kind != expect) { 75 expected1(expect); 76 } 77} 78 79/* |
68 * scan expecting 2 given tokens | 80 * scan expecting any of the 2 given tokens |
69 */ 70void 71scan2(expect1, expect2, tokp) 72 tok_kind expect1; 73 tok_kind expect2; 74 token *tokp; 75{ 76 get_token(tokp); 77 if (tokp->kind != expect1 && tokp->kind != expect2) { 78 expected2(expect1, expect2); 79 } 80} 81 82/* | 81 */ 82void 83scan2(expect1, expect2, tokp) 84 tok_kind expect1; 85 tok_kind expect2; 86 token *tokp; 87{ 88 get_token(tokp); 89 if (tokp->kind != expect1 && tokp->kind != expect2) { 90 expected2(expect1, expect2); 91 } 92} 93 94/* |
83 * scan expecting 3 given token | 95 * scan expecting any of the 3 given token |
84 */ 85void 86scan3(expect1, expect2, expect3, tokp) 87 tok_kind expect1; 88 tok_kind expect2; 89 tok_kind expect3; 90 token *tokp; 91{ 92 get_token(tokp); 93 if (tokp->kind != expect1 && tokp->kind != expect2 94 && tokp->kind != expect3) { 95 expected3(expect1, expect2, expect3); 96 } 97} 98 | 96 */ 97void 98scan3(expect1, expect2, expect3, tokp) 99 tok_kind expect1; 100 tok_kind expect2; 101 tok_kind expect3; 102 token *tokp; 103{ 104 get_token(tokp); 105 if (tokp->kind != expect1 && tokp->kind != expect2 106 && tokp->kind != expect3) { 107 expected3(expect1, expect2, expect3); 108 } 109} 110 |
99 | |
100/* | 111/* |
101 * scan expecting a constant, possibly symbolic | 112 * scan expecting a constant, possibly symbolic |
102 */ 103void 104scan_num(tokp) 105 token *tokp; 106{ 107 get_token(tokp); 108 switch (tokp->kind) { 109 case TOK_IDENT: 110 break; 111 default: 112 error("constant or identifier expected"); 113 } 114} 115 | 113 */ 114void 115scan_num(tokp) 116 token *tokp; 117{ 118 get_token(tokp); 119 switch (tokp->kind) { 120 case TOK_IDENT: 121 break; 122 default: 123 error("constant or identifier expected"); 124 } 125} 126 |
116 | |
117/* | 127/* |
118 * Peek at the next token | 128 * Peek at the next token |
119 */ 120void 121peek(tokp) 122 token *tokp; 123{ 124 get_token(tokp); 125 unget_token(tokp); 126} 127 | 129 */ 130void 131peek(tokp) 132 token *tokp; 133{ 134 get_token(tokp); 135 unget_token(tokp); 136} 137 |
128 | |
129/* | 138/* |
130 * Peek at the next token and scan it if it matches what you expect | 139 * Peek at the next token and scan it if it matches what you expect |
131 */ 132int 133peekscan(expect, tokp) 134 tok_kind expect; 135 token *tokp; 136{ 137 peek(tokp); 138 if (tokp->kind == expect) { 139 get_token(tokp); 140 return (1); 141 } 142 return (0); 143} 144 | 140 */ 141int 142peekscan(expect, tokp) 143 tok_kind expect; 144 token *tokp; 145{ 146 peek(tokp); 147 if (tokp->kind == expect) { 148 get_token(tokp); 149 return (1); 150 } 151 return (0); 152} 153 |
145 146 | |
147/* | 154/* |
148 * Get the next token, printing out any directive that are encountered. | 155 * Get the next token, printing out any directive that are encountered. |
149 */ 150void 151get_token(tokp) 152 token *tokp; 153{ 154 int commenting; | 156 */ 157void 158get_token(tokp) 159 token *tokp; 160{ 161 int commenting; |
155 | 162 int stat = 0; 163 164 |
156 if (pushed) { 157 pushed = 0; 158 *tokp = lasttok; 159 return; 160 } 161 commenting = 0; 162 for (;;) { 163 if (*where == 0) { 164 for (;;) { 165 if (!fgets(curline, MAXLINESIZE, fin)) { 166 tokp->kind = TOK_EOF; | 165 if (pushed) { 166 pushed = 0; 167 *tokp = lasttok; 168 return; 169 } 170 commenting = 0; 171 for (;;) { 172 if (*where == 0) { 173 for (;;) { 174 if (!fgets(curline, MAXLINESIZE, fin)) { 175 tokp->kind = TOK_EOF; |
176 /* now check if cpp returned non NULL value */ 177 waitpid(childpid, &stat, WUNTRACED); 178 if (stat > 0) { 179 /* Set return value from rpcgen */ 180 nonfatalerrors = stat >> 8; 181 } |
|
167 *where = 0; 168 return; 169 } 170 linenum++; 171 if (commenting) { 172 break; 173 } else if (cppline(curline)) { | 182 *where = 0; 183 return; 184 } 185 linenum++; 186 if (commenting) { 187 break; 188 } else if (cppline(curline)) { |
174 docppline(curline, &linenum, | 189 docppline(curline, &linenum, |
175 &infilename); 176 } else if (directive(curline)) { 177 printdirective(curline); 178 } else { 179 break; 180 } 181 } 182 where = curline; 183 } else if (isspace(*where)) { 184 while (isspace(*where)) { 185 where++; /* eat */ 186 } 187 } else if (commenting) { | 190 &infilename); 191 } else if (directive(curline)) { 192 printdirective(curline); 193 } else { 194 break; 195 } 196 } 197 where = curline; 198 } else if (isspace(*where)) { 199 while (isspace(*where)) { 200 where++; /* eat */ 201 } 202 } else if (commenting) { |
188 where++; 189 if (endcomment(where)) { 190 where++; 191 commenting--; | 203 for (where++; *where; where++) { 204 if (endcomment(where)) { 205 where++; 206 commenting--; 207 break; 208 } |
192 } 193 } else if (startcomment(where)) { 194 where += 2; 195 commenting++; 196 } else { 197 break; 198 } 199 } 200 201 /* | 209 } 210 } else if (startcomment(where)) { 211 where += 2; 212 commenting++; 213 } else { 214 break; 215 } 216 } 217 218 /* |
202 * 'where' is not whitespace, comment or directive Must be a token! | 219 * 'where' is not whitespace, comment or directive Must be a token! |
203 */ 204 switch (*where) { 205 case ':': 206 tokp->kind = TOK_COLON; 207 where++; 208 break; 209 case ';': 210 tokp->kind = TOK_SEMICOLON; --- 43 unchanged lines hidden (view full) --- 254 tokp->kind = TOK_RANGLE; 255 where++; 256 break; 257 258 case '"': 259 tokp->kind = TOK_STRCONST; 260 findstrconst(&where, &tokp->str); 261 break; | 220 */ 221 switch (*where) { 222 case ':': 223 tokp->kind = TOK_COLON; 224 where++; 225 break; 226 case ';': 227 tokp->kind = TOK_SEMICOLON; --- 43 unchanged lines hidden (view full) --- 271 tokp->kind = TOK_RANGLE; 272 where++; 273 break; 274 275 case '"': 276 tokp->kind = TOK_STRCONST; 277 findstrconst(&where, &tokp->str); 278 break; |
279 case '\'': 280 tokp->kind = TOK_CHARCONST; 281 findchrconst(&where, &tokp->str); 282 break; |
|
262 263 case '-': 264 case '0': 265 case '1': 266 case '2': 267 case '3': 268 case '4': 269 case '5': 270 case '6': 271 case '7': 272 case '8': 273 case '9': 274 tokp->kind = TOK_IDENT; 275 findconst(&where, &tokp->str); 276 break; 277 | 283 284 case '-': 285 case '0': 286 case '1': 287 case '2': 288 case '3': 289 case '4': 290 case '5': 291 case '6': 292 case '7': 293 case '8': 294 case '9': 295 tokp->kind = TOK_IDENT; 296 findconst(&where, &tokp->str); 297 break; 298 |
278 | |
279 default: 280 if (!(isalpha(*where) || *where == '_')) { 281 char buf[100]; 282 char *p; 283 284 s_print(buf, "illegal character in file: "); 285 p = buf + strlen(buf); 286 if (isprint(*where)) { 287 s_print(p, "%c", *where); 288 } else { 289 s_print(p, "%d", *where); 290 } 291 error(buf); 292 } 293 findkind(&where, tokp); 294 break; 295 } 296} 297 | 299 default: 300 if (!(isalpha(*where) || *where == '_')) { 301 char buf[100]; 302 char *p; 303 304 s_print(buf, "illegal character in file: "); 305 p = buf + strlen(buf); 306 if (isprint(*where)) { 307 s_print(p, "%c", *where); 308 } else { 309 s_print(p, "%d", *where); 310 } 311 error(buf); 312 } 313 findkind(&where, tokp); 314 break; 315 } 316} 317 |
298 299 | |
300static 301unget_token(tokp) 302 token *tokp; 303{ 304 lasttok = *tokp; 305 pushed = 1; 306} 307 | 318static 319unget_token(tokp) 320 token *tokp; 321{ 322 lasttok = *tokp; 323 pushed = 1; 324} 325 |
308 | |
309static 310findstrconst(str, val) 311 char **str; 312 char **val; 313{ 314 char *p; 315 int size; 316 --- 8 unchanged lines hidden (view full) --- 325 size = p - *str; 326 *val = alloc(size + 1); 327 (void) strncpy(*val, *str, size); 328 (*val)[size] = 0; 329 *str = p; 330} 331 332static | 326static 327findstrconst(str, val) 328 char **str; 329 char **val; 330{ 331 char *p; 332 int size; 333 --- 8 unchanged lines hidden (view full) --- 342 size = p - *str; 343 *val = alloc(size + 1); 344 (void) strncpy(*val, *str, size); 345 (*val)[size] = 0; 346 *str = p; 347} 348 349static |
350findchrconst(str, val) 351 char **str; 352 char **val; 353{ 354 char *p; 355 int size; 356 357 p = *str; 358 do { 359 *p++; 360 } while (*p && *p != '\''); 361 if (*p == 0) { 362 error("unterminated string constant"); 363 } 364 p++; 365 size = p - *str; 366 if (size != 3) { 367 error("empty char string"); 368 } 369 *val = alloc(size + 1); 370 (void) strncpy(*val, *str, size); 371 (*val)[size] = 0; 372 *str = p; 373} 374 375static |
|
333findconst(str, val) 334 char **str; 335 char **val; 336{ 337 char *p; 338 int size; 339 340 p = *str; --- 9 unchanged lines hidden (view full) --- 350 } 351 size = p - *str; 352 *val = alloc(size + 1); 353 (void) strncpy(*val, *str, size); 354 (*val)[size] = 0; 355 *str = p; 356} 357 | 376findconst(str, val) 377 char **str; 378 char **val; 379{ 380 char *p; 381 int size; 382 383 p = *str; --- 9 unchanged lines hidden (view full) --- 393 } 394 size = p - *str; 395 *val = alloc(size + 1); 396 (void) strncpy(*val, *str, size); 397 (*val)[size] = 0; 398 *str = p; 399} 400 |
358 359 | |
360static token symbols[] = { 361 {TOK_CONST, "const"}, 362 {TOK_UNION, "union"}, 363 {TOK_SWITCH, "switch"}, 364 {TOK_CASE, "case"}, 365 {TOK_DEFAULT, "default"}, 366 {TOK_STRUCT, "struct"}, 367 {TOK_TYPEDEF, "typedef"}, 368 {TOK_ENUM, "enum"}, 369 {TOK_OPAQUE, "opaque"}, 370 {TOK_BOOL, "bool"}, 371 {TOK_VOID, "void"}, 372 {TOK_CHAR, "char"}, 373 {TOK_INT, "int"}, 374 {TOK_UNSIGNED, "unsigned"}, 375 {TOK_SHORT, "short"}, 376 {TOK_LONG, "long"}, | 401static token symbols[] = { 402 {TOK_CONST, "const"}, 403 {TOK_UNION, "union"}, 404 {TOK_SWITCH, "switch"}, 405 {TOK_CASE, "case"}, 406 {TOK_DEFAULT, "default"}, 407 {TOK_STRUCT, "struct"}, 408 {TOK_TYPEDEF, "typedef"}, 409 {TOK_ENUM, "enum"}, 410 {TOK_OPAQUE, "opaque"}, 411 {TOK_BOOL, "bool"}, 412 {TOK_VOID, "void"}, 413 {TOK_CHAR, "char"}, 414 {TOK_INT, "int"}, 415 {TOK_UNSIGNED, "unsigned"}, 416 {TOK_SHORT, "short"}, 417 {TOK_LONG, "long"}, |
418 {TOK_HYPER, "hyper"}, |
|
377 {TOK_FLOAT, "float"}, 378 {TOK_DOUBLE, "double"}, | 419 {TOK_FLOAT, "float"}, 420 {TOK_DOUBLE, "double"}, |
421 {TOK_QUAD, "quadruple"}, |
|
379 {TOK_STRING, "string"}, 380 {TOK_PROGRAM, "program"}, 381 {TOK_VERSION, "version"}, 382 {TOK_EOF, "??????"}, 383}; 384 | 422 {TOK_STRING, "string"}, 423 {TOK_PROGRAM, "program"}, 424 {TOK_VERSION, "version"}, 425 {TOK_EOF, "??????"}, 426}; 427 |
385 | |
386static 387findkind(mark, tokp) 388 char **mark; 389 token *tokp; 390{ | 428static 429findkind(mark, tokp) 430 char **mark; 431 token *tokp; 432{ |
391 | |
392 int len; 393 token *s; 394 char *str; 395 396 str = *mark; 397 for (s = symbols; s->kind != TOK_EOF; s++) { 398 len = strlen(s->str); 399 if (strncmp(str, s->str, len) == 0) { --- 77 unchanged lines hidden --- | 433 int len; 434 token *s; 435 char *str; 436 437 str = *mark; 438 for (s = symbols; s->kind != TOK_EOF; s++) { 439 len = strlen(s->str); 440 if (strncmp(str, s->str, len) == 0) { --- 77 unchanged lines hidden --- |