rpc_util.c (8874) | rpc_util.c (12798) |
---|---|
1/* @(#)rpc_util.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_util.c 1.14 93/07/05 SMI" 31 |
|
30#ifndef lint | 32#ifndef lint |
31/*static char sccsid[] = "from: @(#)rpc_util.c 1.5 87/06/24 (C) 1987 SMI";*/ 32static char rcsid[] = "$Id: rpc_util.c,v 1.1 1994/08/07 18:01:37 wollman Exp $"; | 33static char sccsid[] = "@(#)rpc_util.c 1.11 89/02/22 (C) 1987 SMI"; |
33#endif 34 35/* 36 * rpc_util.c, Utility routines for the RPC protocol compiler | 34#endif 35 36/* 37 * rpc_util.c, Utility routines for the RPC protocol compiler |
37 * Copyright (C) 1987, Sun Microsystems, Inc. | 38 * Copyright (C) 1989, Sun Microsystems, Inc. |
38 */ 39#include <stdio.h> | 39 */ 40#include <stdio.h> |
41#include <ctype.h> |
|
40#include "rpc_scan.h" 41#include "rpc_parse.h" 42#include "rpc_util.h" 43 | 42#include "rpc_scan.h" 43#include "rpc_parse.h" 44#include "rpc_util.h" 45 |
46#define ARGEXT "argument" 47 |
|
44char curline[MAXLINESIZE]; /* current read line */ | 48char curline[MAXLINESIZE]; /* current read line */ |
45char *where = curline; /* current point in line */ 46int linenum = 0; /* current line number */ | 49char *where = curline; /* current point in line */ 50int linenum = 0; /* current line number */ |
47 | 51 |
48char *infilename; /* input filename */ | 52char *infilename; /* input filename */ |
49 | 53 |
50#define NFILES 4 51char *outfiles[NFILES]; /* output file names */ | 54#define NFILES 7 55char *outfiles[NFILES]; /* output file names */ |
52int nfiles; 53 | 56int nfiles; 57 |
54FILE *fout; /* file pointer of current output */ 55FILE *fin; /* file pointer of current input */ | 58FILE *fout; /* file pointer of current output */ 59FILE *fin; /* file pointer of current input */ |
56 | 60 |
57list *defined; /* list of defined things */ | 61list *defined; /* list of defined things */ |
58 | 62 |
59static int printwhere(); | 63static int printwhere __P(( void )); |
60 61/* 62 * Reinitialize the world 63 */ 64reinitialize() 65{ | 64 65/* 66 * Reinitialize the world 67 */ 68reinitialize() 69{ |
66 bzero(curline, MAXLINESIZE); | 70 memset(curline, 0, MAXLINESIZE); |
67 where = curline; 68 linenum = 0; 69 defined = NULL; 70} 71 72/* 73 * string equality 74 */ 75streq(a, b) 76 char *a; 77 char *b; 78{ 79 return (strcmp(a, b) == 0); 80} 81 82/* 83 * find a value in a list 84 */ | 71 where = curline; 72 linenum = 0; 73 defined = NULL; 74} 75 76/* 77 * string equality 78 */ 79streq(a, b) 80 char *a; 81 char *b; 82{ 83 return (strcmp(a, b) == 0); 84} 85 86/* 87 * find a value in a list 88 */ |
85char * | 89definition * |
86findval(lst, val, cmp) 87 list *lst; 88 char *val; 89 int (*cmp) (); 90 91{ 92 for (; lst != NULL; lst = lst->next) { 93 if ((*cmp) (lst->val, val)) { --- 4 unchanged lines hidden (view full) --- 98} 99 100/* 101 * store a value in a list 102 */ 103void 104storeval(lstp, val) 105 list **lstp; | 90findval(lst, val, cmp) 91 list *lst; 92 char *val; 93 int (*cmp) (); 94 95{ 96 for (; lst != NULL; lst = lst->next) { 97 if ((*cmp) (lst->val, val)) { --- 4 unchanged lines hidden (view full) --- 102} 103 104/* 105 * store a value in a list 106 */ 107void 108storeval(lstp, val) 109 list **lstp; |
106 char *val; | 110 definition *val; |
107{ 108 list **l; 109 list *lst; 110 111 for (l = lstp; *l != NULL; l = (list **) & (*l)->next); 112 lst = ALLOC(list); 113 lst->val = val; 114 lst->next = NULL; 115 *l = lst; 116} 117 | 111{ 112 list **l; 113 list *lst; 114 115 for (l = lstp; *l != NULL; l = (list **) & (*l)->next); 116 lst = ALLOC(list); 117 lst->val = val; 118 lst->next = NULL; 119 *l = lst; 120} 121 |
118 | |
119static 120findit(def, type) 121 definition *def; 122 char *type; 123{ 124 return (streq(def->def_name, type)); 125} 126 | 122static 123findit(def, type) 124 definition *def; 125 char *type; 126{ 127 return (streq(def->def_name, type)); 128} 129 |
127 | |
128static char * 129fixit(type, orig) 130 char *type; 131 char *orig; 132{ 133 definition *def; 134 135 def = (definition *) FINDVAL(defined, type, findit); 136 if (def == NULL || def->def_kind != DEF_TYPEDEF) { 137 return (orig); 138 } 139 switch (def->def.ty.rel) { 140 case REL_VECTOR: | 130static char * 131fixit(type, orig) 132 char *type; 133 char *orig; 134{ 135 definition *def; 136 137 def = (definition *) FINDVAL(defined, type, findit); 138 if (def == NULL || def->def_kind != DEF_TYPEDEF) { 139 return (orig); 140 } 141 switch (def->def.ty.rel) { 142 case REL_VECTOR: |
141 return (def->def.ty.old_type); | 143 if (streq(def->def.ty.old_type, "opaque")) 144 return ("char"); 145 else 146 return (def->def.ty.old_type); 147 |
142 case REL_ALIAS: 143 return (fixit(def->def.ty.old_type, orig)); 144 default: 145 return (orig); 146 } 147} 148 149char * --- 31 unchanged lines hidden (view full) --- 181 f_print(fout, "bool_t "); 182 } else if (streq(type, "string")) { 183 f_print(fout, "char *"); 184 } else { 185 f_print(fout, "%s ", follow ? fixtype(type) : type); 186 } 187} 188 | 148 case REL_ALIAS: 149 return (fixit(def->def.ty.old_type, orig)); 150 default: 151 return (orig); 152 } 153} 154 155char * --- 31 unchanged lines hidden (view full) --- 187 f_print(fout, "bool_t "); 188 } else if (streq(type, "string")) { 189 f_print(fout, "char *"); 190 } else { 191 f_print(fout, "%s ", follow ? fixtype(type) : type); 192 } 193} 194 |
189 | |
190static 191typedefed(def, type) 192 definition *def; 193 char *type; 194{ 195 if (def->def_kind != DEF_TYPEDEF || def->def.ty.old_prefix != NULL) { 196 return (0); 197 } else { --- 21 unchanged lines hidden (view full) --- 219 return (0); 220 } 221 type = def->def.ty.old_type; 222 rel = def->def.ty.rel; 223 } 224 } 225} 226 | 195static 196typedefed(def, type) 197 definition *def; 198 char *type; 199{ 200 if (def->def_kind != DEF_TYPEDEF || def->def.ty.old_prefix != NULL) { 201 return (0); 202 } else { --- 21 unchanged lines hidden (view full) --- 224 return (0); 225 } 226 type = def->def.ty.old_type; 227 rel = def->def.ty.rel; 228 } 229 } 230} 231 |
227 228static char * | 232char * |
229locase(str) 230 char *str; 231{ 232 char c; 233 static char buf[100]; 234 char *p = buf; 235 236 while (c = *str++) { 237 *p++ = (c >= 'A' && c <= 'Z') ? (c - 'A' + 'a') : c; 238 } 239 *p = 0; 240 return (buf); 241} 242 | 233locase(str) 234 char *str; 235{ 236 char c; 237 static char buf[100]; 238 char *p = buf; 239 240 while (c = *str++) { 241 *p++ = (c >= 'A' && c <= 'Z') ? (c - 'A' + 'a') : c; 242 } 243 *p = 0; 244 return (buf); 245} 246 |
247void 248pvname_svc(pname, vnum) 249 char *pname; 250 char *vnum; 251{ 252 f_print(fout, "%s_%s_svc", locase(pname), vnum); 253} |
|
243 244void 245pvname(pname, vnum) 246 char *pname; 247 char *vnum; 248{ 249 f_print(fout, "%s_%s", locase(pname), vnum); 250} 251 | 254 255void 256pvname(pname, vnum) 257 char *pname; 258 char *vnum; 259{ 260 f_print(fout, "%s_%s", locase(pname), vnum); 261} 262 |
252 | |
253/* 254 * print a useful (?) error message, and then die 255 */ 256void 257error(msg) 258 char *msg; 259{ 260 printwhere(); --- 11 unchanged lines hidden (view full) --- 272 int i; 273 274 for (i = 0; i < nfiles; i++) { 275 (void) unlink(outfiles[i]); 276 } 277 exit(1); 278} 279 | 263/* 264 * print a useful (?) error message, and then die 265 */ 266void 267error(msg) 268 char *msg; 269{ 270 printwhere(); --- 11 unchanged lines hidden (view full) --- 282 int i; 283 284 for (i = 0; i < nfiles; i++) { 285 (void) unlink(outfiles[i]); 286 } 287 exit(1); 288} 289 |
280 | |
281void 282record_open(file) 283 char *file; 284{ 285 if (nfiles < NFILES) { 286 outfiles[nfiles++] = file; 287 } else { 288 f_print(stderr, "too many files!\n"); --- 49 unchanged lines hidden (view full) --- 338 int tab; 339{ 340 while (tab--) { 341 (void) fputc('\t', f); 342 } 343} 344 345 | 290void 291record_open(file) 292 char *file; 293{ 294 if (nfiles < NFILES) { 295 outfiles[nfiles++] = file; 296 } else { 297 f_print(stderr, "too many files!\n"); --- 49 unchanged lines hidden (view full) --- 347 int tab; 348{ 349 while (tab--) { 350 (void) fputc('\t', f); 351 } 352} 353 354 |
346 | |
347static token tokstrings[] = { | 355static token tokstrings[] = { |
348 {TOK_IDENT, "identifier"}, 349 {TOK_CONST, "const"}, 350 {TOK_RPAREN, ")"}, 351 {TOK_LPAREN, "("}, 352 {TOK_RBRACE, "}"}, 353 {TOK_LBRACE, "{"}, 354 {TOK_LBRACKET, "["}, 355 {TOK_RBRACKET, "]"}, 356 {TOK_STAR, "*"}, 357 {TOK_COMMA, ","}, 358 {TOK_EQUAL, "="}, 359 {TOK_COLON, ":"}, 360 {TOK_SEMICOLON, ";"}, 361 {TOK_UNION, "union"}, 362 {TOK_STRUCT, "struct"}, 363 {TOK_SWITCH, "switch"}, 364 {TOK_CASE, "case"}, 365 {TOK_DEFAULT, "default"}, 366 {TOK_ENUM, "enum"}, 367 {TOK_TYPEDEF, "typedef"}, 368 {TOK_INT, "int"}, 369 {TOK_SHORT, "short"}, 370 {TOK_LONG, "long"}, 371 {TOK_UNSIGNED, "unsigned"}, 372 {TOK_DOUBLE, "double"}, 373 {TOK_FLOAT, "float"}, 374 {TOK_CHAR, "char"}, 375 {TOK_STRING, "string"}, 376 {TOK_OPAQUE, "opaque"}, 377 {TOK_BOOL, "bool"}, 378 {TOK_VOID, "void"}, 379 {TOK_PROGRAM, "program"}, 380 {TOK_VERSION, "version"}, 381 {TOK_EOF, "??????"} | 356 {TOK_IDENT, "identifier"}, 357 {TOK_CONST, "const"}, 358 {TOK_RPAREN, ")"}, 359 {TOK_LPAREN, "("}, 360 {TOK_RBRACE, "}"}, 361 {TOK_LBRACE, "{"}, 362 {TOK_LBRACKET, "["}, 363 {TOK_RBRACKET, "]"}, 364 {TOK_STAR, "*"}, 365 {TOK_COMMA, ","}, 366 {TOK_EQUAL, "="}, 367 {TOK_COLON, ":"}, 368 {TOK_SEMICOLON, ";"}, 369 {TOK_UNION, "union"}, 370 {TOK_STRUCT, "struct"}, 371 {TOK_SWITCH, "switch"}, 372 {TOK_CASE, "case"}, 373 {TOK_DEFAULT, "default"}, 374 {TOK_ENUM, "enum"}, 375 {TOK_TYPEDEF, "typedef"}, 376 {TOK_INT, "int"}, 377 {TOK_SHORT, "short"}, 378 {TOK_LONG, "long"}, 379 {TOK_UNSIGNED, "unsigned"}, 380 {TOK_DOUBLE, "double"}, 381 {TOK_FLOAT, "float"}, 382 {TOK_CHAR, "char"}, 383 {TOK_STRING, "string"}, 384 {TOK_OPAQUE, "opaque"}, 385 {TOK_BOOL, "bool"}, 386 {TOK_VOID, "void"}, 387 {TOK_PROGRAM, "program"}, 388 {TOK_VERSION, "version"}, 389 {TOK_EOF, "??????"} |
382}; 383 384static char * 385toktostr(kind) 386 tok_kind kind; 387{ 388 token *sp; 389 390 for (sp = tokstrings; sp->kind != TOK_EOF && sp->kind != kind; sp++); 391 return (sp->str); 392} 393 | 390}; 391 392static char * 393toktostr(kind) 394 tok_kind kind; 395{ 396 token *sp; 397 398 for (sp = tokstrings; sp->kind != TOK_EOF && sp->kind != kind; sp++); 399 return (sp->str); 400} 401 |
394 395 | |
396static 397printbuf() 398{ 399 char c; 400 int i; 401 int cnt; 402 403# define TABSIZE 4 --- 6 unchanged lines hidden (view full) --- 410 cnt = 1; 411 } 412 while (cnt--) { 413 (void) fputc(c, stderr); 414 } 415 } 416} 417 | 402static 403printbuf() 404{ 405 char c; 406 int i; 407 int cnt; 408 409# define TABSIZE 4 --- 6 unchanged lines hidden (view full) --- 416 cnt = 1; 417 } 418 while (cnt--) { 419 (void) fputc(c, stderr); 420 } 421 } 422} 423 |
418 | |
419static 420printwhere() 421{ 422 int i; 423 char c; 424 int cnt; 425 426 printbuf(); --- 5 unchanged lines hidden (view full) --- 432 cnt = 1; 433 } 434 while (cnt--) { 435 (void) fputc('^', stderr); 436 } 437 } 438 (void) fputc('\n', stderr); 439} | 424static 425printwhere() 426{ 427 int i; 428 char c; 429 int cnt; 430 431 printbuf(); --- 5 unchanged lines hidden (view full) --- 437 cnt = 1; 438 } 439 while (cnt--) { 440 (void) fputc('^', stderr); 441 } 442 } 443 (void) fputc('\n', stderr); 444} |
445 446char * 447make_argname(pname, vname) 448 char *pname; 449 char *vname; 450{ 451 char *name; 452 453 name = malloc(strlen(pname) + strlen(vname) + strlen(ARGEXT) + 3); 454 if (!name) { 455 fprintf(stderr, "failed in malloc"); 456 exit(1); 457 } 458 sprintf(name, "%s_%s_%s", locase(pname), vname, ARGEXT); 459 return (name); 460} 461 462bas_type *typ_list_h; 463bas_type *typ_list_t; 464 465add_type(len, type) 466int len; 467char *type; 468{ 469 bas_type *ptr; 470 471 if ((ptr = (bas_type *) malloc(sizeof (bas_type))) == 472 (bas_type *)NULL) { 473 fprintf(stderr, "failed in malloc"); 474 exit(1); 475 } 476 477 ptr->name = type; 478 ptr->length = len; 479 ptr->next = NULL; 480 if (typ_list_t == NULL) 481 { 482 483 typ_list_t = ptr; 484 typ_list_h = ptr; 485 } 486 else 487 { 488 typ_list_t->next = ptr; 489 typ_list_t = ptr; 490 }; 491} 492 493 494bas_type *find_type(type) 495char *type; 496{ 497 bas_type * ptr; 498 499 ptr = typ_list_h; 500 while (ptr != NULL) 501 { 502 if (strcmp(ptr->name, type) == 0) 503 return (ptr); 504 else 505 ptr = ptr->next; 506 }; 507 return (NULL); 508} |
|