Deleted Added
full compact
rpc_parse.c (146833) rpc_parse.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_parse.c 1.12 93/07/05 SMI"
33static char sccsid[] = "@(#)rpc_parse.c 1.8 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_parse.c 1.12 93/07/05 SMI"
33static char sccsid[] = "@(#)rpc_parse.c 1.8 89/02/22 (C) 1987 SMI";
34#endif
35#endif
36
37#include <sys/cdefs.h>
38__FBSDID("$FreeBSD: head/usr.bin/rpcgen/rpc_parse.c 146833 2005-05-31 20:00:29Z stefanf $");
38__FBSDID("$FreeBSD: head/usr.bin/rpcgen/rpc_parse.c 152398 2005-11-13 21:17:24Z dwmalone $");
39
40/*
41 * rpc_parse.c, Parser for the RPC protocol compiler
42 * Copyright (C) 1987 Sun Microsystems, Inc.
43 */
44#include <stdio.h>
45#include <string.h>
46#include "rpc/types.h"
39
40/*
41 * rpc_parse.c, Parser for the RPC protocol compiler
42 * Copyright (C) 1987 Sun Microsystems, Inc.
43 */
44#include <stdio.h>
45#include <string.h>
46#include "rpc/types.h"
47#include "rpc_scan.h"
48#include "rpc_parse.h"
47#include "rpc_parse.h"
48#include "rpc_scan.h"
49#include "rpc_util.h"
50
51#define ARGNAME "arg"
52
49#include "rpc_util.h"
50
51#define ARGNAME "arg"
52
53extern char *make_argname( char *, char * );
54static void isdefined( definition * );
55static void def_struct( definition * );
56static void def_program( definition * );
57static void def_enum( definition * );
58static void def_const( definition * );
59static void def_union( definition * );
60static void def_typedef( definition * );
61static void get_declaration( declaration *, defkind );
62static void get_prog_declaration( declaration *, defkind, int );
53static void isdefined( definition * );
54static void def_struct( definition * );
55static void def_program( definition * );
56static void def_enum( definition * );
57static void def_const( definition * );
58static void def_union( definition * );
59static void def_typedef( definition * );
60static void get_declaration( declaration *, defkind );
61static void get_prog_declaration( declaration *, defkind, int );
63static void get_type( char **, char **, defkind );
64static void unsigned_dec( char ** );
62static void get_type(const char **, const char **, defkind);
63static void unsigned_dec(const char ** );
65
66/*
67 * return the next definition you see
68 */
69definition *
64
65/*
66 * return the next definition you see
67 */
68definition *
70get_definition()
69get_definition(void)
71{
72 definition *defp;
73 token tok;
74
75 defp = XALLOC(definition);
76 get_token(&tok);
77 switch (tok.kind) {
78 case TOK_STRUCT:

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

99 error("definition keyword expected");
100 }
101 scan(TOK_SEMICOLON, &tok);
102 isdefined(defp);
103 return (defp);
104}
105
106static void
70{
71 definition *defp;
72 token tok;
73
74 defp = XALLOC(definition);
75 get_token(&tok);
76 switch (tok.kind) {
77 case TOK_STRUCT:

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

98 error("definition keyword expected");
99 }
100 scan(TOK_SEMICOLON, &tok);
101 isdefined(defp);
102 return (defp);
103}
104
105static void
107isdefined(defp)
108 definition *defp;
106isdefined(definition *defp)
109{
110 STOREVAL(&defined, defp);
111}
112
113static void
107{
108 STOREVAL(&defined, defp);
109}
110
111static void
114def_struct(defp)
115 definition *defp;
112def_struct(definition *defp)
116{
117 token tok;
118 declaration dec;
119 decl_list *decls;
120 decl_list **tailp;
121
122 defp->def_kind = DEF_STRUCT;
123

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

134 scan(TOK_SEMICOLON, &tok);
135 peek(&tok);
136 } while (tok.kind != TOK_RBRACE);
137 get_token(&tok);
138 *tailp = NULL;
139}
140
141static void
113{
114 token tok;
115 declaration dec;
116 decl_list *decls;
117 decl_list **tailp;
118
119 defp->def_kind = DEF_STRUCT;
120

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

131 scan(TOK_SEMICOLON, &tok);
132 peek(&tok);
133 } while (tok.kind != TOK_RBRACE);
134 get_token(&tok);
135 *tailp = NULL;
136}
137
138static void
142def_program(defp)
143 definition *defp;
139def_program(definition *defp)
144{
145 token tok;
146 declaration dec;
147 decl_list *decls;
148 decl_list **tailp;
149 version_list *vlist;
150 version_list **vtailp;
151 proc_list *plist;

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

241 scan(TOK_EQUAL, &tok);
242 scan_num(&tok);
243 defp->def.pr.prog_num = tok.str;
244 *vtailp = NULL;
245}
246
247
248static void
140{
141 token tok;
142 declaration dec;
143 decl_list *decls;
144 decl_list **tailp;
145 version_list *vlist;
146 version_list **vtailp;
147 proc_list *plist;

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

237 scan(TOK_EQUAL, &tok);
238 scan_num(&tok);
239 defp->def.pr.prog_num = tok.str;
240 *vtailp = NULL;
241}
242
243
244static void
249def_enum(defp)
250 definition *defp;
245def_enum(definition *defp)
251{
252 token tok;
253 enumval_list *elist;
254 enumval_list **tailp;
255
256 defp->def_kind = DEF_ENUM;
257 scan(TOK_IDENT, &tok);
258 defp->def_name = tok.str;

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

271 }
272 *tailp = elist;
273 tailp = &elist->next;
274 } while (tok.kind != TOK_RBRACE);
275 *tailp = NULL;
276}
277
278static void
246{
247 token tok;
248 enumval_list *elist;
249 enumval_list **tailp;
250
251 defp->def_kind = DEF_ENUM;
252 scan(TOK_IDENT, &tok);
253 defp->def_name = tok.str;

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

266 }
267 *tailp = elist;
268 tailp = &elist->next;
269 } while (tok.kind != TOK_RBRACE);
270 *tailp = NULL;
271}
272
273static void
279def_const(defp)
280 definition *defp;
274def_const(definition *defp)
281{
282 token tok;
283
284 defp->def_kind = DEF_CONST;
285 scan(TOK_IDENT, &tok);
286 defp->def_name = tok.str;
287 scan(TOK_EQUAL, &tok);
288 scan2(TOK_IDENT, TOK_STRCONST, &tok);
289 defp->def.co = tok.str;
290}
291
292static void
275{
276 token tok;
277
278 defp->def_kind = DEF_CONST;
279 scan(TOK_IDENT, &tok);
280 defp->def_name = tok.str;
281 scan(TOK_EQUAL, &tok);
282 scan2(TOK_IDENT, TOK_STRCONST, &tok);
283 defp->def.co = tok.str;
284}
285
286static void
293def_union(defp)
294 definition *defp;
287def_union(definition *defp)
295{
296 token tok;
297 declaration dec;
298 case_list *cases;
299 case_list **tailp;
300 int flag;
301
302 defp->def_kind = DEF_UNION;

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

355 *defp->def.un.default_decl = dec;
356 scan(TOK_SEMICOLON, &tok);
357 scan(TOK_RBRACE, &tok);
358 } else {
359 defp->def.un.default_decl = NULL;
360 }
361}
362
288{
289 token tok;
290 declaration dec;
291 case_list *cases;
292 case_list **tailp;
293 int flag;
294
295 defp->def_kind = DEF_UNION;

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

348 *defp->def.un.default_decl = dec;
349 scan(TOK_SEMICOLON, &tok);
350 scan(TOK_RBRACE, &tok);
351 } else {
352 defp->def.un.default_decl = NULL;
353 }
354}
355
363static char* reserved_words[] =
356static const char *reserved_words[] =
364{
365 "array",
366 "bytes",
367 "destroy",
368 "free",
369 "getpos",
370 "inline",
371 "pointer",
372 "reference",
373 "setpos",
374 "sizeof",
375 "union",
376 "vector",
377 NULL
378 };
379
357{
358 "array",
359 "bytes",
360 "destroy",
361 "free",
362 "getpos",
363 "inline",
364 "pointer",
365 "reference",
366 "setpos",
367 "sizeof",
368 "union",
369 "vector",
370 NULL
371 };
372
380static char* reserved_types[] =
373static const char *reserved_types[] =
381{
382 "opaque",
383 "string",
384 NULL
385 };
386
387/*
388 * check that the given name is not one that would eventually result in
389 * xdr routines that would conflict with internal XDR routines.
390 */
391static void
374{
375 "opaque",
376 "string",
377 NULL
378 };
379
380/*
381 * check that the given name is not one that would eventually result in
382 * xdr routines that would conflict with internal XDR routines.
383 */
384static void
392check_type_name(name, new_type)
393int new_type;
394char* name;
385check_type_name(const char *name, int new_type)
395{
396 int i;
397 char tmp[100];
398
399 for (i = 0; reserved_words[i] != NULL; i++) {
400 if (strcmp(name, reserved_words[i]) == 0) {
401 sprintf(tmp,
402 "illegal (reserved) name :\'%s\' in type definition",

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

414 }
415 }
416 }
417}
418
419
420
421static void
386{
387 int i;
388 char tmp[100];
389
390 for (i = 0; reserved_words[i] != NULL; i++) {
391 if (strcmp(name, reserved_words[i]) == 0) {
392 sprintf(tmp,
393 "illegal (reserved) name :\'%s\' in type definition",

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

405 }
406 }
407 }
408}
409
410
411
412static void
422def_typedef(defp)
423 definition *defp;
413def_typedef(definition *defp)
424{
425 declaration dec;
426
427 defp->def_kind = DEF_TYPEDEF;
428 get_declaration(&dec, DEF_TYPEDEF);
429 defp->def_name = dec.name;
430 check_type_name(dec.name, 1);
431 defp->def.ty.old_prefix = dec.prefix;
432 defp->def.ty.old_type = dec.type;
433 defp->def.ty.rel = dec.rel;
434 defp->def.ty.array_max = dec.array_max;
435}
436
437static void
414{
415 declaration dec;
416
417 defp->def_kind = DEF_TYPEDEF;
418 get_declaration(&dec, DEF_TYPEDEF);
419 defp->def_name = dec.name;
420 check_type_name(dec.name, 1);
421 defp->def.ty.old_prefix = dec.prefix;
422 defp->def.ty.old_type = dec.type;
423 defp->def.ty.rel = dec.rel;
424 defp->def.ty.array_max = dec.array_max;
425}
426
427static void
438get_declaration(dec, dkind)
439 declaration *dec;
440 defkind dkind;
428get_declaration(declaration *dec, defkind dkind)
441{
442 token tok;
443
444 get_type(&dec->prefix, &dec->type, dkind);
445 dec->rel = REL_ALIAS;
446 if (streq(dec->type, "void")) {
447 return;
448 }

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

483 if (dec->rel != REL_ARRAY) {
484 error("variable-length array declaration expected");
485 }
486 }
487}
488
489
490static void
429{
430 token tok;
431
432 get_type(&dec->prefix, &dec->type, dkind);
433 dec->rel = REL_ALIAS;
434 if (streq(dec->type, "void")) {
435 return;
436 }

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

471 if (dec->rel != REL_ARRAY) {
472 error("variable-length array declaration expected");
473 }
474 }
475}
476
477
478static void
491get_prog_declaration(dec, dkind, num)
492 declaration *dec;
493 defkind dkind;
494 int num; /* arg number */
479get_prog_declaration(declaration *dec, defkind dkind, int num)
495{
496 token tok;
497 char name[10]; /* argument name */
498
499 if (dkind == DEF_PROGRAM) {
500 peek(&tok);
501 if (tok.kind == TOK_RPAREN) { /* no arguments */
502 dec->rel = REL_ALIAS;

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

557 dec->array_max = "~0"; /* unspecified size, use max */
558 }
559 }
560}
561
562
563
564static void
480{
481 token tok;
482 char name[10]; /* argument name */
483
484 if (dkind == DEF_PROGRAM) {
485 peek(&tok);
486 if (tok.kind == TOK_RPAREN) { /* no arguments */
487 dec->rel = REL_ALIAS;

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

542 dec->array_max = "~0"; /* unspecified size, use max */
543 }
544 }
545}
546
547
548
549static void
565get_type(prefixp, typep, dkind)
566 char **prefixp;
567 char **typep;
568 defkind dkind;
550get_type(const char **prefixp, const char **typep, defkind dkind)
569{
570 token tok;
571
572 *prefixp = NULL;
573 get_token(&tok);
574 switch (tok.kind) {
575 case TOK_IDENT:
576 *typep = tok.str;

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

615 *typep = tok.str;
616 break;
617 default:
618 error("expected type specifier");
619 }
620}
621
622static void
551{
552 token tok;
553
554 *prefixp = NULL;
555 get_token(&tok);
556 switch (tok.kind) {
557 case TOK_IDENT:
558 *typep = tok.str;

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

597 *typep = tok.str;
598 break;
599 default:
600 error("expected type specifier");
601 }
602}
603
604static void
623unsigned_dec(typep)
624 char **typep;
605unsigned_dec(const char **typep)
625{
626 token tok;
627
628 peek(&tok);
629 switch (tok.kind) {
630 case TOK_CHAR:
631 get_token(&tok);
632 *typep = "u_char";

--- 26 unchanged lines hidden ---
606{
607 token tok;
608
609 peek(&tok);
610 switch (tok.kind) {
611 case TOK_CHAR:
612 get_token(&tok);
613 *typep = "u_char";

--- 26 unchanged lines hidden ---