Deleted Added
full compact
rpc_scan.c (146833) rpc_scan.c (152398)
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.
8 *

--- 21 unchanged lines hidden (view full) ---

30#if 0
31#ifndef lint
32#ident "@(#)rpc_scan.c 1.13 93/07/05 SMI"
33static char sccsid[] = "@(#)rpc_scan.c 1.11 89/02/22 (C) 1987 SMI";
34#endif
35#endif
36
37#include <sys/cdefs.h>
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.
8 *

--- 21 unchanged lines hidden (view full) ---

30#if 0
31#ifndef lint
32#ident "@(#)rpc_scan.c 1.13 93/07/05 SMI"
33static char sccsid[] = "@(#)rpc_scan.c 1.11 89/02/22 (C) 1987 SMI";
34#endif
35#endif
36
37#include <sys/cdefs.h>
38__FBSDID("$FreeBSD: head/usr.bin/rpcgen/rpc_scan.c 146833 2005-05-31 20:00:29Z stefanf $");
38__FBSDID("$FreeBSD: head/usr.bin/rpcgen/rpc_scan.c 152398 2005-11-13 21:17:24Z dwmalone $");
39
40/*
41 * rpc_scan.c, Scanner for the RPC protocol compiler
42 * Copyright (C) 1987, Sun Microsystems, Inc.
43 */
44
45#include <sys/types.h>
46
47#include <sys/wait.h>
48#include <stdio.h>
49#include <ctype.h>
50#include <string.h>
39
40/*
41 * rpc_scan.c, Scanner for the RPC protocol compiler
42 * Copyright (C) 1987, Sun Microsystems, Inc.
43 */
44
45#include <sys/types.h>
46
47#include <sys/wait.h>
48#include <stdio.h>
49#include <ctype.h>
50#include <string.h>
51#include "rpc_scan.h"
52#include "rpc_parse.h"
51#include "rpc_parse.h"
52#include "rpc_scan.h"
53#include "rpc_util.h"
54
55#define startcomment(where) (where[0] == '/' && where[1] == '*')
56#define endcomment(where) (where[-1] == '*' && where[0] == '/')
57
58static int pushed = 0; /* is a token pushed */
59static token lasttok; /* last token, if pushed */
60
61static void unget_token( token * );
53#include "rpc_util.h"
54
55#define startcomment(where) (where[0] == '/' && where[1] == '*')
56#define endcomment(where) (where[-1] == '*' && where[0] == '/')
57
58static int pushed = 0; /* is a token pushed */
59static token lasttok; /* last token, if pushed */
60
61static void unget_token( token * );
62static void findstrconst( char **, char **);
63static void findchrconst( char **, char **);
64static void findconst( char **, char **);
62static void findstrconst(char **, const char **);
63static void findchrconst(char **, const char **);
64static void findconst(char **, const char **);
65static void findkind( char **, token * );
66static int cppline( char * );
67static int directive( char * );
68static void printdirective( char * );
65static void findkind( char **, token * );
66static int cppline( char * );
67static int directive( char * );
68static void printdirective( char * );
69static void docppline( char *, int *, char ** );
69static void docppline(char *, int *, const char **);
70
71/*
72 * scan expecting 1 given token
73 */
74void
70
71/*
72 * scan expecting 1 given token
73 */
74void
75scan(expect, tokp)
76 tok_kind expect;
77 token *tokp;
75scan(tok_kind expect, token *tokp)
78{
79 get_token(tokp);
80 if (tokp->kind != expect) {
81 expected1(expect);
82 }
83}
84
85/*
86 * scan expecting any of the 2 given tokens
87 */
88void
76{
77 get_token(tokp);
78 if (tokp->kind != expect) {
79 expected1(expect);
80 }
81}
82
83/*
84 * scan expecting any of the 2 given tokens
85 */
86void
89scan2(expect1, expect2, tokp)
90 tok_kind expect1;
91 tok_kind expect2;
92 token *tokp;
87scan2(tok_kind expect1, tok_kind expect2, token *tokp)
93{
94 get_token(tokp);
95 if (tokp->kind != expect1 && tokp->kind != expect2) {
96 expected2(expect1, expect2);
97 }
98}
99
100/*
101 * scan expecting any of the 3 given token
102 */
103void
88{
89 get_token(tokp);
90 if (tokp->kind != expect1 && tokp->kind != expect2) {
91 expected2(expect1, expect2);
92 }
93}
94
95/*
96 * scan expecting any of the 3 given token
97 */
98void
104scan3(expect1, expect2, expect3, tokp)
105 tok_kind expect1;
106 tok_kind expect2;
107 tok_kind expect3;
108 token *tokp;
99scan3(tok_kind expect1, tok_kind expect2, tok_kind expect3, token *tokp)
109{
110 get_token(tokp);
111 if (tokp->kind != expect1 && tokp->kind != expect2
112 && tokp->kind != expect3) {
113 expected3(expect1, expect2, expect3);
114 }
115}
116
117/*
118 * scan expecting a constant, possibly symbolic
119 */
120void
100{
101 get_token(tokp);
102 if (tokp->kind != expect1 && tokp->kind != expect2
103 && tokp->kind != expect3) {
104 expected3(expect1, expect2, expect3);
105 }
106}
107
108/*
109 * scan expecting a constant, possibly symbolic
110 */
111void
121scan_num(tokp)
122 token *tokp;
112scan_num(token *tokp)
123{
124 get_token(tokp);
125 switch (tokp->kind) {
126 case TOK_IDENT:
127 break;
128 default:
129 error("constant or identifier expected");
130 }
131}
132
133/*
134 * Peek at the next token
135 */
136void
113{
114 get_token(tokp);
115 switch (tokp->kind) {
116 case TOK_IDENT:
117 break;
118 default:
119 error("constant or identifier expected");
120 }
121}
122
123/*
124 * Peek at the next token
125 */
126void
137peek(tokp)
138 token *tokp;
127peek(token *tokp)
139{
140 get_token(tokp);
141 unget_token(tokp);
142}
143
144/*
145 * Peek at the next token and scan it if it matches what you expect
146 */
147int
128{
129 get_token(tokp);
130 unget_token(tokp);
131}
132
133/*
134 * Peek at the next token and scan it if it matches what you expect
135 */
136int
148peekscan(expect, tokp)
149 tok_kind expect;
150 token *tokp;
137peekscan(tok_kind expect, token *tokp)
151{
152 peek(tokp);
153 if (tokp->kind == expect) {
154 get_token(tokp);
155 return (1);
156 }
157 return (0);
158}
159
160/*
161 * Get the next token, printing out any directive that are encountered.
162 */
163void
138{
139 peek(tokp);
140 if (tokp->kind == expect) {
141 get_token(tokp);
142 return (1);
143 }
144 return (0);
145}
146
147/*
148 * Get the next token, printing out any directive that are encountered.
149 */
150void
164get_token(tokp)
165 token *tokp;
151get_token(token *tokp)
166{
167 int commenting;
168 int stat = 0;
169
170
171 if (pushed) {
172 pushed = 0;
173 *tokp = lasttok;

--- 143 unchanged lines hidden (view full) ---

317 error(buf);
318 }
319 findkind(&where, tokp);
320 break;
321 }
322}
323
324static void
152{
153 int commenting;
154 int stat = 0;
155
156
157 if (pushed) {
158 pushed = 0;
159 *tokp = lasttok;

--- 143 unchanged lines hidden (view full) ---

303 error(buf);
304 }
305 findkind(&where, tokp);
306 break;
307 }
308}
309
310static void
325unget_token(tokp)
326 token *tokp;
311unget_token(token *tokp)
327{
328 lasttok = *tokp;
329 pushed = 1;
330}
331
332static void
312{
313 lasttok = *tokp;
314 pushed = 1;
315}
316
317static void
333findstrconst(str, val)
334 char **str;
335 char **val;
318findstrconst(char **str, const char **val)
336{
337 char *p;
319{
320 char *p;
321 char *tmp;
338 int size;
339
340 p = *str;
341 do {
342 p++;
343 } while (*p && *p != '"');
344 if (*p == 0) {
345 error("unterminated string constant");
346 }
347 p++;
348 size = p - *str;
322 int size;
323
324 p = *str;
325 do {
326 p++;
327 } while (*p && *p != '"');
328 if (*p == 0) {
329 error("unterminated string constant");
330 }
331 p++;
332 size = p - *str;
349 *val = xmalloc(size + 1);
350 (void) strncpy(*val, *str, size);
351 (*val)[size] = 0;
333 tmp = xmalloc(size + 1);
334 (void) strncpy(tmp, *str, size);
335 tmp[size] = 0;
336 *val = tmp;
352 *str = p;
353}
354
355static void
337 *str = p;
338}
339
340static void
356findchrconst(str, val)
357 char **str;
358 char **val;
341findchrconst(char **str, const char **val)
359{
360 char *p;
342{
343 char *p;
344 char *tmp;
361 int size;
362
363 p = *str;
364 do {
365 p++;
366 } while (*p && *p != '\'');
367 if (*p == 0) {
368 error("unterminated string constant");
369 }
370 p++;
371 size = p - *str;
372 if (size != 3) {
373 error("empty char string");
374 }
345 int size;
346
347 p = *str;
348 do {
349 p++;
350 } while (*p && *p != '\'');
351 if (*p == 0) {
352 error("unterminated string constant");
353 }
354 p++;
355 size = p - *str;
356 if (size != 3) {
357 error("empty char string");
358 }
375 *val = xmalloc(size + 1);
376 (void) strncpy(*val, *str, size);
377 (*val)[size] = 0;
359 tmp = xmalloc(size + 1);
360 (void) strncpy(tmp, *str, size);
361 tmp[size] = 0;
362 *val = tmp;
378 *str = p;
379}
380
381static void
363 *str = p;
364}
365
366static void
382findconst(str, val)
383 char **str;
384 char **val;
367findconst(char **str, const char **val)
385{
386 char *p;
368{
369 char *p;
370 char *tmp;
387 int size;
388
389 p = *str;
390 if (*p == '0' && *(p + 1) == 'x') {
391 p++;
392 do {
393 p++;
394 } while (isxdigit(*p));
395 } else {
396 do {
397 p++;
398 } while (isdigit(*p));
399 }
400 size = p - *str;
371 int size;
372
373 p = *str;
374 if (*p == '0' && *(p + 1) == 'x') {
375 p++;
376 do {
377 p++;
378 } while (isxdigit(*p));
379 } else {
380 do {
381 p++;
382 } while (isdigit(*p));
383 }
384 size = p - *str;
401 *val = xmalloc(size + 1);
402 (void) strncpy(*val, *str, size);
403 (*val)[size] = 0;
385 tmp = xmalloc(size + 1);
386 (void) strncpy(tmp, *str, size);
387 tmp[size] = 0;
388 *val = tmp;
404 *str = p;
405}
406
407static token symbols[] = {
408 {TOK_CONST, "const"},
409 {TOK_UNION, "union"},
410 {TOK_SWITCH, "switch"},
411 {TOK_CASE, "case"},

--- 15 unchanged lines hidden (view full) ---

427 {TOK_QUAD, "quadruple"},
428 {TOK_STRING, "string"},
429 {TOK_PROGRAM, "program"},
430 {TOK_VERSION, "version"},
431 {TOK_EOF, "??????"},
432};
433
434static void
389 *str = p;
390}
391
392static token symbols[] = {
393 {TOK_CONST, "const"},
394 {TOK_UNION, "union"},
395 {TOK_SWITCH, "switch"},
396 {TOK_CASE, "case"},

--- 15 unchanged lines hidden (view full) ---

412 {TOK_QUAD, "quadruple"},
413 {TOK_STRING, "string"},
414 {TOK_PROGRAM, "program"},
415 {TOK_VERSION, "version"},
416 {TOK_EOF, "??????"},
417};
418
419static void
435findkind(mark, tokp)
436 char **mark;
437 token *tokp;
420findkind(char **mark, token *tokp)
438{
439 int len;
440 token *s;
421{
422 int len;
423 token *s;
441 char *str;
424 char *str, *tmp;
442
443 str = *mark;
444 for (s = symbols; s->kind != TOK_EOF; s++) {
445 len = strlen(s->str);
446 if (strncmp(str, s->str, len) == 0) {
447 if (!isalnum(str[len]) && str[len] != '_') {
448 tokp->kind = s->kind;
449 tokp->str = s->str;
450 *mark = str + len;
451 return;
452 }
453 }
454 }
455 tokp->kind = TOK_IDENT;
456 for (len = 0; isalnum(str[len]) || str[len] == '_'; len++);
425
426 str = *mark;
427 for (s = symbols; s->kind != TOK_EOF; s++) {
428 len = strlen(s->str);
429 if (strncmp(str, s->str, len) == 0) {
430 if (!isalnum(str[len]) && str[len] != '_') {
431 tokp->kind = s->kind;
432 tokp->str = s->str;
433 *mark = str + len;
434 return;
435 }
436 }
437 }
438 tokp->kind = TOK_IDENT;
439 for (len = 0; isalnum(str[len]) || str[len] == '_'; len++);
457 tokp->str = xmalloc(len + 1);
458 (void) strncpy(tokp->str, str, len);
459 tokp->str[len] = 0;
440 tmp = xmalloc(len + 1);
441 (void) strncpy(tmp, str, len);
442 tmp[len] = 0;
443 tokp->str = tmp;
460 *mark = str + len;
461}
462
463static int
444 *mark = str + len;
445}
446
447static int
464cppline(line)
465 char *line;
448cppline(char *line)
466{
467 return (line == curline && *line == '#');
468}
469
470static int
449{
450 return (line == curline && *line == '#');
451}
452
453static int
471directive(line)
472 char *line;
454directive(char *line)
473{
474 return (line == curline && *line == '%');
475}
476
477static void
455{
456 return (line == curline && *line == '%');
457}
458
459static void
478printdirective(line)
479 char *line;
460printdirective(char *line)
480{
481 f_print(fout, "%s", line + 1);
482}
483
484static void
461{
462 f_print(fout, "%s", line + 1);
463}
464
465static void
485docppline(line, lineno, fname)
486 char *line;
487 int *lineno;
488 char **fname;
466docppline(char *line, int *lineno, const char **fname)
489{
490 char *file;
491 int num;
492 char *p;
493
494 line++;
495 while (isspace(*line)) {
496 line++;

--- 27 unchanged lines hidden ---
467{
468 char *file;
469 int num;
470 char *p;
471
472 line++;
473 while (isspace(*line)) {
474 line++;

--- 27 unchanged lines hidden ---