1 /* @(#)rpc_util.c 1.2 87/11/24 3.9 RPCSRC */
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.
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.
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.
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.
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.
26 * Sun Microsystems, Inc.
28 * Mountain View, California 94043
32 * rpc_util.c, Utility routines for the RPC protocol compiler
33 * Copyright (C) 1987, Sun Microsystems, Inc.
35 #include <afsconfig.h>
36 #include <afs/param.h>
49 #include "rpc_parse.h"
52 char curline[MAXLINESIZE]; /* current read line */
53 char *where = curline; /* current point in line */
54 int linenum = 0; /* current line number */
56 char *infilename; /* input filename */
59 char *outfiles[NFILES]; /* output file names */
62 FILE *fout; /* file pointer of current output */
63 FILE *fin; /* file pointer of current input */
65 list *defined; /* list of defined things */
70 * Reinitialize the world
75 bzero(curline, MAXLINESIZE);
79 special_defined = typedef_defined = uniondef_defined = NULL;
81 master_opcodenumber= 99999;
82 master_highest_opcode = 0;
84 for(i=0;i<MAX_PACKAGES;i++) {
85 no_of_stat_funcs_header[i] = 0;
96 return (strcmp(a, b) == 0);
100 * find a value in a list
103 findval(lst, val, cmp)
109 for (; lst != NULL; lst = lst->next) {
110 if ((*cmp) (lst->val, val)) {
118 * store a value in a list
128 for (l = lstp; *l != NULL; l = (list **) & (*l)->next);
141 return (streq(def->def_name, type));
152 def = (definition *) FINDVAL(defined, type, findit);
153 if (def == NULL || def->def_kind != DEF_TYPEDEF) {
156 switch (def->def.ty.rel) {
158 return (def->def.ty.old_type);
160 return (fixit(def->def.ty.old_type, orig));
170 return (fixit(type, type));
177 if (streq(type, "string")) {
178 return ("wrapstring");
185 ptype(prefix, type, follow)
190 if (prefix != NULL) {
191 if (streq(prefix, "enum")) {
192 f_print(fout, "enum ");
194 f_print(fout, "struct ");
197 if (streq(type, "bool")) {
198 f_print(fout, "bool_t ");
199 } else if (streq(type, "string")) {
200 f_print(fout, "char *");
202 f_print(fout, "%s ", follow ? fixtype(type) : type);
212 if (def->def_kind != DEF_TYPEDEF || def->def.ty.old_prefix != NULL) {
215 return (streq(def->def_name, type));
219 isvectordef(type, rel)
228 return (!streq(type, "string"));
234 def = (definition *) FINDVAL(defined, type, typedefed);
238 type = def->def.ty.old_type;
239 rel = def->def.ty.rel;
250 static char buf[100];
254 *p++ = (c >= 'A' && c <= 'Z') ? (c - 'A' + 'a') : c;
266 f_print(fout, "%s_%s", locase(pname), vnum);
271 * print a useful (?) error message, and then die
278 f_print(stderr, "%s, line %d: ", infilename, linenum);
279 f_print(stderr, "%s\n", msg);
284 * Something went wrong, unlink any files that we may have created and then
291 for (i = 0; i < nfiles; i++) {
292 (void) unlink(outfiles[i]);
302 if (nfiles < NFILES) {
303 outfiles[nfiles++] = file;
305 f_print(stderr, "too many files!\n");
310 static char expectbuf[100];
311 static char *toktostr();
314 * error, token encountered was not the expected one
320 s_print(expectbuf, "expected '%s'",
326 * error, token encountered was not one of two expected ones
329 expected2(exp1, exp2)
332 s_print(expectbuf, "expected '%s' or '%s'",
339 * error, token encountered was not one of 3 expected ones
342 expected3(exp1, exp2, exp3)
343 tok_kind exp1, exp2, exp3;
345 s_print(expectbuf, "expected '%s', '%s' or '%s'",
354 * error, token encountered was not one of 4 expected ones
357 expected4(exp1,exp2,exp3,exp4)
358 tok_kind exp1,exp2,exp3,exp4;
360 sprintf(expectbuf,"expected '%s', '%s', '%s', or '%s'",
375 (void) fputc('\t', f);
381 static token tokstrings[] = {
382 {TOK_IDENT, "identifier"},
383 {TOK_CONST, "const"},
394 {TOK_SEMICOLON, ";"},
395 {TOK_UNION, "union"},
396 {TOK_STRUCT, "struct"},
397 {TOK_SWITCH, "switch"},
399 {TOK_DEFAULT, "default"},
401 {TOK_TYPEDEF, "typedef"},
403 {TOK_SHORT, "short"},
404 {TOK_INT32, "afs_int32"}, /* XXX */
405 {TOK_UNSIGNED, "unsigned"},
406 {TOK_DOUBLE, "double"},
407 {TOK_FLOAT, "float"},
409 {TOK_STRING, "string"},
410 {TOK_OPAQUE, "opaque"},
413 {TOK_PROGRAM, "program"},
414 {TOK_VERSION, "version"},
415 { TOK_PACKAGE, "package" },
416 { TOK_PREFIX, "prefix" },
417 { TOK_STATINDEX, "statindex" },
418 { TOK_SPECIAL, "special" },
419 { TOK_STARTINGOPCODE, "startingopcode" },
420 { TOK_CUSTOMIZED, "customized" },
421 { TOK_PROC, "proc" },
422 { TOK_SPLITPREFIX, "splitprefix" },
423 { TOK_SPLIT, "split" },
424 { TOK_MULTI, "multi" },
427 { TOK_INOUT, "INOUT" },
428 { TOK_AFSUUID, "afsUUID" },
438 for (sp = tokstrings; sp->kind != TOK_EOF && sp->kind != kind; sp++);
453 for (i = 0; c = curline[i]; i++) {
455 cnt = 8 - (i % TABSIZE);
461 (void) fputc(c, stderr);
475 for (i = 0; i < where - curline; i++) {
478 cnt = 8 - (i % TABSIZE);
483 (void) fputc('^', stderr);
486 (void) fputc('\n', stderr);