1 /* @(#)rpc_util.c 2.1 88/08/01 4.0 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
31 static char sccsid
[] = "@(#)rpc_util.c 1.5 87/06/24 (C) 1987 SMI";
35 * rpc_util.c, Utility routines for the RPC protocol compiler
36 * Copyright (C) 1987, Sun Microsystems, Inc.
40 #include "rpc_parse.h"
43 char curline
[MAXLINESIZE
]; /* current read line */
44 char *where
= curline
; /* current point in line */
45 int linenum
= 0; /* current line number */
47 char *infilename
; /* input filename */
50 char *outfiles
[NFILES
]; /* output file names */
53 FILE *fout
; /* file pointer of current output */
54 FILE *fin
; /* file pointer of current input */
56 list
*defined
; /* list of defined things */
59 * Reinitialize the world
63 bzero(curline
, MAXLINESIZE
);
76 return (strcmp(a
, b
) == 0);
80 * find a value in a list
83 findval(lst
, val
, cmp
)
89 for (; lst
!= NULL
; lst
= lst
->next
) {
90 if ((*cmp
) (lst
->val
, val
)) {
98 * store a value in a list
108 for (l
= lstp
; *l
!= NULL
; l
= (list
**) & (*l
)->next
);
121 return (streq(def
->def_name
, type
));
132 def
= (definition
*) FINDVAL(defined
, type
, findit
);
133 if (def
== NULL
|| def
->def_kind
!= DEF_TYPEDEF
) {
136 switch (def
->def
.ty
.rel
) {
138 return (def
->def
.ty
.old_type
);
140 return (fixit(def
->def
.ty
.old_type
, orig
));
150 return (fixit(type
, type
));
157 if (streq(type
, "string")) {
158 return ("wrapstring");
165 ptype(prefix
, type
, follow
)
170 if (prefix
!= NULL
) {
171 if (streq(prefix
, "enum")) {
172 f_print(fout
, "enum ");
174 f_print(fout
, "struct ");
177 if (streq(type
, "bool")) {
178 f_print(fout
, "bool_t ");
179 } else if (streq(type
, "string")) {
180 f_print(fout
, "char *");
182 f_print(fout
, "%s ", follow
? fixtype(type
) : type
);
192 if (def
->def_kind
!= DEF_TYPEDEF
|| def
->def
.ty
.old_prefix
!= NULL
) {
195 return (streq(def
->def_name
, type
));
199 isvectordef(type
, rel
)
208 return (!streq(type
, "string"));
214 def
= (definition
*) FINDVAL(defined
, type
, typedefed
);
218 type
= def
->def
.ty
.old_type
;
219 rel
= def
->def
.ty
.rel
;
230 static char buf
[100];
234 *p
++ = (c
>= 'A' && c
<= 'Z') ? (c
- 'A' + 'a') : c
;
246 f_print(fout
, "%s_%s", locase(pname
), vnum
);
251 * print a useful (?) error message, and then die
258 f_print(stderr
, _("%s, line %d: "), infilename
, linenum
);
259 f_print(stderr
, "%s\n", msg
);
264 * Something went wrong, unlink any files that we may have created and then
271 for (i
= 0; i
< nfiles
; i
++) {
272 (void) unlink(outfiles
[i
]);
282 if (nfiles
< NFILES
) {
283 outfiles
[nfiles
++] = file
;
285 f_print(stderr
, _("too many files!\n"));
290 static char expectbuf
[100];
291 static char *toktostr();
294 * error, token encountered was not the expected one
300 s_print(expectbuf
, _("expected '%s'"),
306 * error, token encountered was not one of two expected ones
309 expected2(exp1
, exp2
)
312 s_print(expectbuf
, _("expected '%s' or '%s'"),
319 * error, token encountered was not one of 3 expected ones
322 expected3(exp1
, exp2
, exp3
)
323 tok_kind exp1
, exp2
, exp3
;
325 s_print(expectbuf
, _("expected '%s', '%s' or '%s'"),
338 (void) fputc('\t', f
);
344 static token tokstrings
[] = {
345 {TOK_IDENT
, "identifier"},
346 {TOK_CONST
, "const"},
357 {TOK_SEMICOLON
, ";"},
358 {TOK_UNION
, "union"},
359 {TOK_STRUCT
, "struct"},
360 {TOK_SWITCH
, "switch"},
362 {TOK_DEFAULT
, "default"},
364 {TOK_TYPEDEF
, "typedef"},
366 {TOK_SHORT
, "short"},
368 {TOK_UNSIGNED
, "unsigned"},
369 {TOK_DOUBLE
, "double"},
370 {TOK_FLOAT
, "float"},
372 {TOK_STRING
, "string"},
373 {TOK_OPAQUE
, "opaque"},
376 {TOK_PROGRAM
, "program"},
377 {TOK_VERSION
, "version"},
387 for (sp
= tokstrings
; sp
->kind
!= TOK_EOF
&& sp
->kind
!= kind
; sp
++);
402 for (i
= 0; c
= curline
[i
]; i
++) {
404 cnt
= 8 - (i
% TABSIZE
);
410 (void) fputc(c
, stderr
);
424 for (i
= 0; i
< where
- curline
; i
++) {
427 cnt
= 8 - (i
% TABSIZE
);
432 (void) fputc('^', stderr
);
435 (void) fputc('\n', stderr
);