rpc_hout.c (8874) | rpc_hout.c (12798) |
---|---|
1/* @(#)rpc_hout.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_hout.c 1.16 94/04/25 SMI" 31 |
|
30#ifndef lint | 32#ifndef lint |
31/*static char sccsid[] = "from: @(#)rpc_hout.c 1.6 87/07/28 (C) 1987 SMI";*/ 32static char rcsid[] = "$Id: rpc_hout.c,v 1.1 1994/08/07 18:01:30 wollman Exp $"; | 33static char sccsid[] = "@(#)rpc_hout.c 1.12 89/02/22 (C) 1987 SMI"; |
33#endif 34 | 34#endif 35 |
35static int pconstdef(), pstructdef(), puniondef(), pdefine(), pprogramdef(), 36 penumdef(), ptypedef(), pdeclaration(), undefined2(); 37 | |
38/* 39 * rpc_hout.c, Header file outputter for the RPC protocol compiler 40 * Copyright (C) 1987, Sun Microsystems, Inc. 41 */ 42#include <stdio.h> 43#include <ctype.h> | 36/* 37 * rpc_hout.c, Header file outputter for the RPC protocol compiler 38 * Copyright (C) 1987, Sun Microsystems, Inc. 39 */ 40#include <stdio.h> 41#include <ctype.h> |
44#include "rpc_util.h" | |
45#include "rpc_parse.h" | 42#include "rpc_parse.h" |
43#include "rpc_util.h" |
|
46 | 44 |
45void storexdrfuncdecl __P(( char *, int )); 46static int pconstdef __P(( definition * )); 47static int pstructdef __P(( definition * )); 48static int puniondef __P(( definition * )); 49static int pprogramdef __P(( definition * )); 50static int pstructdef __P(( definition * )); 51static int penumdef __P(( definition * )); 52static int ptypedef __P(( definition * )); 53static int pdefine __P(( char *, char * )); 54static int undefined2 __P(( char *, char * )); 55static int parglist __P(( proc_list *, char * )); |
|
47 | 56 |
57static char RESULT[] = "clnt_res"; 58 59 |
|
48/* 49 * Print the C-version of an xdr definition 50 */ 51void 52print_datadef(def) 53 definition *def; 54{ | 60/* 61 * Print the C-version of an xdr definition 62 */ 63void 64print_datadef(def) 65 definition *def; 66{ |
67 68 if (def->def_kind == DEF_PROGRAM) /* handle data only */ 69 return; 70 |
|
55 if (def->def_kind != DEF_CONST) { 56 f_print(fout, "\n"); 57 } 58 switch (def->def_kind) { 59 case DEF_STRUCT: 60 pstructdef(def); 61 break; 62 case DEF_UNION: --- 8 unchanged lines hidden (view full) --- 71 case DEF_PROGRAM: 72 pprogramdef(def); 73 break; 74 case DEF_CONST: 75 pconstdef(def); 76 break; 77 } 78 if (def->def_kind != DEF_PROGRAM && def->def_kind != DEF_CONST) { | 71 if (def->def_kind != DEF_CONST) { 72 f_print(fout, "\n"); 73 } 74 switch (def->def_kind) { 75 case DEF_STRUCT: 76 pstructdef(def); 77 break; 78 case DEF_UNION: --- 8 unchanged lines hidden (view full) --- 87 case DEF_PROGRAM: 88 pprogramdef(def); 89 break; 90 case DEF_CONST: 91 pconstdef(def); 92 break; 93 } 94 if (def->def_kind != DEF_PROGRAM && def->def_kind != DEF_CONST) { |
79 f_print(fout, "bool_t xdr_%s();\n", def->def_name); | 95 storexdrfuncdecl(def->def_name, 96 def->def_kind != DEF_TYPEDEF || 97 !isvectordef(def->def.ty.old_type, 98 def->def.ty.rel)); |
80 } | 99 } |
81 if (def->def_kind != DEF_CONST) { | 100} 101 102 103void 104print_funcdef(def) 105 definition *def; 106{ 107 switch (def->def_kind) { 108 case DEF_PROGRAM: |
82 f_print(fout, "\n"); | 109 f_print(fout, "\n"); |
110 pprogramdef(def); 111 break; 112 } 113} 114 115/* store away enough information to allow the XDR functions to be spat 116 out at the end of the file */ 117 118void 119storexdrfuncdecl(name, pointerp) 120char *name; 121int pointerp; 122{ 123 xdrfunc * xdrptr; 124 125 xdrptr = (xdrfunc *) malloc(sizeof (struct xdrfunc)); 126 127 xdrptr->name = name; 128 xdrptr->pointerp = pointerp; 129 xdrptr->next = NULL; 130 131 if (xdrfunc_tail == NULL){ 132 xdrfunc_head = xdrptr; 133 xdrfunc_tail = xdrptr; 134 } else { 135 xdrfunc_tail->next = xdrptr; 136 xdrfunc_tail = xdrptr; |
|
83 } | 137 } |
138 139 |
|
84} 85 | 140} 141 |
142void 143print_xdr_func_def(name, pointerp, i) 144char* name; 145int pointerp; 146int i; 147{ 148 if (i == 2) { 149 f_print(fout, "extern bool_t xdr_%s();\n", name); 150 return; 151 } 152 else 153 f_print(fout, "extern bool_t xdr_%s(XDR *, %s%s);\n", name, 154 name, pointerp ? "*" : ""); 155 156 157} 158 159 |
|
86static 87pconstdef(def) 88 definition *def; 89{ 90 pdefine(def->def_name, def->def.co); 91} 92 | 160static 161pconstdef(def) 162 definition *def; 163{ 164 pdefine(def->def_name, def->def.co); 165} 166 |
167/* print out the definitions for the arguments of functions in the 168 header file 169*/ |
|
93static | 170static |
171pargdef(def) 172 definition *def; 173{ 174 decl_list *l; 175 version_list *vers; 176 char *name; 177 proc_list *plist; 178 179 180 for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) { 181 for (plist = vers->procs; plist != NULL; 182 plist = plist->next) { 183 184 if (!newstyle || plist->arg_num < 2) { 185 continue; /* old style or single args */ 186 } 187 name = plist->args.argname; 188 f_print(fout, "struct %s {\n", name); 189 for (l = plist->args.decls; 190 l != NULL; l = l->next) { 191 pdeclaration(name, &l->decl, 1, 192 ";\n"); 193 } 194 f_print(fout, "};\n"); 195 f_print(fout, "typedef struct %s %s;\n", 196 name, name); 197 storexdrfuncdecl(name, 1); 198 f_print(fout, "\n"); 199 } 200 } 201} 202 203 204static |
|
94pstructdef(def) 95 definition *def; 96{ 97 decl_list *l; 98 char *name = def->def_name; 99 100 f_print(fout, "struct %s {\n", name); 101 for (l = def->def.st.decls; l != NULL; l = l->next) { | 205pstructdef(def) 206 definition *def; 207{ 208 decl_list *l; 209 char *name = def->def_name; 210 211 f_print(fout, "struct %s {\n", name); 212 for (l = def->def.st.decls; l != NULL; l = l->next) { |
102 pdeclaration(name, &l->decl, 1); | 213 pdeclaration(name, &l->decl, 1, ";\n"); |
103 } 104 f_print(fout, "};\n"); 105 f_print(fout, "typedef struct %s %s;\n", name, name); 106} 107 108static 109puniondef(def) 110 definition *def; --- 6 unchanged lines hidden (view full) --- 117 decl = &def->def.un.enum_decl; 118 if (streq(decl->type, "bool")) { 119 f_print(fout, "\tbool_t %s;\n", decl->name); 120 } else { 121 f_print(fout, "\t%s %s;\n", decl->type, decl->name); 122 } 123 f_print(fout, "\tunion {\n"); 124 for (l = def->def.un.cases; l != NULL; l = l->next) { | 214 } 215 f_print(fout, "};\n"); 216 f_print(fout, "typedef struct %s %s;\n", name, name); 217} 218 219static 220puniondef(def) 221 definition *def; --- 6 unchanged lines hidden (view full) --- 228 decl = &def->def.un.enum_decl; 229 if (streq(decl->type, "bool")) { 230 f_print(fout, "\tbool_t %s;\n", decl->name); 231 } else { 232 f_print(fout, "\t%s %s;\n", decl->type, decl->name); 233 } 234 f_print(fout, "\tunion {\n"); 235 for (l = def->def.un.cases; l != NULL; l = l->next) { |
125 pdeclaration(name, &l->case_decl, 2); | 236 if (l->contflag == 0) 237 pdeclaration(name, &l->case_decl, 2, ";\n"); |
126 } 127 decl = def->def.un.default_decl; 128 if (decl && !streq(decl->type, "void")) { | 238 } 239 decl = def->def.un.default_decl; 240 if (decl && !streq(decl->type, "void")) { |
129 pdeclaration(name, decl, 2); | 241 pdeclaration(name, decl, 2, ";\n"); |
130 } 131 f_print(fout, "\t} %s_u;\n", name); 132 f_print(fout, "};\n"); 133 f_print(fout, "typedef struct %s %s;\n", name, name); 134} 135 | 242 } 243 f_print(fout, "\t} %s_u;\n", name); 244 f_print(fout, "};\n"); 245 f_print(fout, "typedef struct %s %s;\n", name, name); 246} 247 |
136 137 | |
138static 139pdefine(name, num) 140 char *name; 141 char *num; 142{ | 248static 249pdefine(name, num) 250 char *name; 251 char *num; 252{ |
143 f_print(fout, "#define %s %s\n", name, num); | 253 f_print(fout, "#define\t%s %s\n", name, num); |
144} 145 146static 147puldefine(name, num) 148 char *name; 149 char *num; 150{ | 254} 255 256static 257puldefine(name, num) 258 char *name; 259 char *num; 260{ |
151 f_print(fout, "#define %s ((u_long)%s)\n", name, num); | 261 f_print(fout, "#define\t%s ((unsigned long)(%s))\n", name, num); |
152} 153 154static 155define_printed(stop, start) 156 proc_list *stop; 157 version_list *start; 158{ 159 version_list *vers; --- 7 unchanged lines hidden (view full) --- 167 return (1); 168 } 169 } 170 } 171 abort(); 172 /* NOTREACHED */ 173} 174 | 262} 263 264static 265define_printed(stop, start) 266 proc_list *stop; 267 version_list *start; 268{ 269 version_list *vers; --- 7 unchanged lines hidden (view full) --- 277 return (1); 278 } 279 } 280 } 281 abort(); 282 /* NOTREACHED */ 283} 284 |
285static 286pfreeprocdef(char * name, char *vers, int mode) 287{ 288 f_print(fout, "extern int "); 289 pvname(name, vers); 290 if (mode == 1) 291 f_print(fout,"_freeresult(SVCXPRT *, xdrproc_t, caddr_t);\n"); 292 else 293 f_print(fout,"_freeresult();\n"); |
|
175 | 294 |
295 296} 297 |
|
176static 177pprogramdef(def) 178 definition *def; 179{ 180 version_list *vers; 181 proc_list *proc; | 298static 299pprogramdef(def) 300 definition *def; 301{ 302 version_list *vers; 303 proc_list *proc; |
304 int i; 305 char *ext; |
|
182 | 306 |
307 pargdef(def); 308 |
|
183 puldefine(def->def_name, def->def.pr.prog_num); 184 for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) { | 309 puldefine(def->def_name, def->def.pr.prog_num); 310 for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) { |
311 if (tblflag) { 312 f_print(fout, 313 "extern struct rpcgen_table %s_%s_table[];\n", 314 locase(def->def_name), vers->vers_num); 315 f_print(fout, 316 "extern %s_%s_nproc;\n", 317 locase(def->def_name), vers->vers_num); 318 } |
|
185 puldefine(vers->vers_name, vers->vers_num); | 319 puldefine(vers->vers_name, vers->vers_num); |
186 for (proc = vers->procs; proc != NULL; proc = proc->next) { 187 if (!define_printed(proc, def->def.pr.versions)) { 188 puldefine(proc->proc_name, proc->proc_num); | 320 321 /* 322 * Print out 2 definitions, one for ANSI-C, another for 323 * old K & R C 324 */ 325 326 if(!Cflag){ 327 ext = "extern "; 328 for (proc = vers->procs; proc != NULL; 329 proc = proc->next) { 330 if (!define_printed(proc, 331 def->def.pr.versions)) { 332 puldefine(proc->proc_name, 333 proc->proc_num); 334 } 335 f_print(fout, "%s", ext); 336 pprocdef(proc, vers, NULL, 0, 2); 337 338 if (mtflag) { 339 f_print(fout, "%s", ext); 340 pprocdef(proc, vers, NULL, 1, 2); 341 } |
189 } | 342 } |
190 pprocdef(proc, vers); | 343 pfreeprocdef(def->def_name, vers->vers_num, 2); 344 345 } else { 346 for (i = 1; i < 3; i++){ 347 if (i == 1){ 348 f_print(fout, "\n#if defined(__STDC__) || defined(__cplusplus)\n"); 349 ext = "extern "; 350 }else{ 351 f_print(fout, "\n#else /* K&R C */\n"); 352 ext = "extern "; 353 } 354 355 for (proc = vers->procs; proc != NULL; 356 proc = proc->next) { 357 if (!define_printed(proc, 358 def->def.pr.versions)) { 359 puldefine(proc->proc_name, 360 proc->proc_num); 361 } 362 f_print(fout, "%s", ext); 363 pprocdef(proc, vers, "CLIENT *", 0, i); 364 f_print(fout, "%s", ext); 365 pprocdef(proc, vers, "struct svc_req *", 1, i); 366 } 367 pfreeprocdef(def->def_name, vers->vers_num, i); 368 } 369 f_print(fout, "#endif /* K&R C */\n"); |
191 } 192 } 193} 194 | 370 } 371 } 372} 373 |
195 196pprocdef(proc, vp) | 374pprocdef(proc, vp, addargtype, server_p, mode) |
197 proc_list *proc; 198 version_list *vp; | 375 proc_list *proc; 376 version_list *vp; |
377 char* addargtype; 378 int server_p; 379 int mode; |
|
199{ | 380{ |
200 f_print(fout, "extern "); 201 if (proc->res_prefix) { 202 if (streq(proc->res_prefix, "enum")) { 203 f_print(fout, "enum "); 204 } else { 205 f_print(fout, "struct "); | 381 if (mtflag) {/* Print MT style stubs */ 382 if (server_p) 383 f_print(fout, "bool_t "); 384 else 385 f_print(fout, "enum clnt_stat "); 386 } else { 387 ptype(proc->res_prefix, proc->res_type, 1); 388 f_print(fout, "* "); 389 } 390 if (server_p) 391 pvname_svc(proc->proc_name, vp->vers_num); 392 else 393 pvname(proc->proc_name, vp->vers_num); 394 395 /* 396 * mode 1 = ANSI-C, mode 2 = K&R C 397 */ 398 if ( mode == 1) 399 parglist(proc, addargtype); 400 else 401 f_print(fout, "();\n"); 402 403 404 405} 406 407 408 409/* print out argument list of procedure */ 410static 411parglist(proc, addargtype) 412 proc_list *proc; 413 char* addargtype; 414{ 415 decl_list *dl; 416 417 f_print(fout, "("); 418 if (proc->arg_num < 2 && newstyle && 419 streq(proc->args.decls->decl.type, "void")) { 420 /* 0 argument in new style: do nothing*/ 421 } 422 else { 423 for (dl = proc->args.decls; dl != NULL; dl = dl->next) { 424 ptype(dl->decl.prefix, dl->decl.type, 1); 425 if (!newstyle) 426 f_print(fout, "*"); 427 /* old style passes by reference */ 428 f_print(fout, ", "); |
206 } 207 } | 429 } 430 } |
208 if (streq(proc->res_type, "bool")) { 209 f_print(fout, "bool_t *"); 210 } else if (streq(proc->res_type, "string")) { 211 f_print(fout, "char **"); 212 } else { 213 f_print(fout, "%s *", fixtype(proc->res_type)); | 431 432 if (mtflag) { 433 ptype(proc->res_prefix, proc->res_type, 1); 434 f_print(fout, "*, "); |
214 } | 435 } |
215 pvname(proc->proc_name, vp->vers_num); 216 f_print(fout, "();\n"); | 436 437 f_print(fout, "%s);\n", addargtype); 438 |
217} 218 219static 220penumdef(def) 221 definition *def; 222{ 223 char *name = def->def_name; 224 enumval_list *l; --- 9 unchanged lines hidden (view full) --- 234 count = 1; 235 } else { 236 if (last == NULL) { 237 f_print(fout, " = %d", count++); 238 } else { 239 f_print(fout, " = %s + %d", last, count++); 240 } 241 } | 439} 440 441static 442penumdef(def) 443 definition *def; 444{ 445 char *name = def->def_name; 446 enumval_list *l; --- 9 unchanged lines hidden (view full) --- 456 count = 1; 457 } else { 458 if (last == NULL) { 459 f_print(fout, " = %d", count++); 460 } else { 461 f_print(fout, " = %s + %d", last, count++); 462 } 463 } |
242 f_print(fout, ",\n"); | 464 if (l->next) 465 f_print(fout, ",\n"); 466 else 467 f_print(fout, "\n"); |
243 } 244 f_print(fout, "};\n"); 245 f_print(fout, "typedef enum %s %s;\n", name, name); 246} 247 248static 249ptypedef(def) 250 definition *def; --- 29 unchanged lines hidden (view full) --- 280 case REL_POINTER: 281 f_print(fout, "%s%s *%s", prefix, old, name); 282 break; 283 case REL_VECTOR: 284 f_print(fout, "%s%s %s[%s]", prefix, old, name, 285 def->def.ty.array_max); 286 break; 287 case REL_ALIAS: | 468 } 469 f_print(fout, "};\n"); 470 f_print(fout, "typedef enum %s %s;\n", name, name); 471} 472 473static 474ptypedef(def) 475 definition *def; --- 29 unchanged lines hidden (view full) --- 505 case REL_POINTER: 506 f_print(fout, "%s%s *%s", prefix, old, name); 507 break; 508 case REL_VECTOR: 509 f_print(fout, "%s%s %s[%s]", prefix, old, name, 510 def->def.ty.array_max); 511 break; 512 case REL_ALIAS: |
288 f_print(fout, "%s%s %s", prefix, old, name); | 513 f_print(fout, "%s%s %s", prefix, old, name); |
289 break; 290 } 291 f_print(fout, ";\n"); 292 } 293} 294 | 514 break; 515 } 516 f_print(fout, ";\n"); 517 } 518} 519 |
295 296static 297pdeclaration(name, dec, tab) | 520pdeclaration(name, dec, tab, separator) |
298 char *name; 299 declaration *dec; 300 int tab; | 521 char *name; 522 declaration *dec; 523 int tab; |
524 char *separator; |
|
301{ 302 char buf[8]; /* enough to hold "struct ", include NUL */ 303 char *prefix; 304 char *type; 305 306 if (streq(dec->type, "void")) { 307 return; 308 } --- 27 unchanged lines hidden (view full) --- 336 case REL_POINTER: 337 f_print(fout, "%s%s *%s", prefix, type, dec->name); 338 break; 339 case REL_ARRAY: 340 f_print(fout, "struct {\n"); 341 tabify(fout, tab); 342 f_print(fout, "\tu_int %s_len;\n", dec->name); 343 tabify(fout, tab); | 525{ 526 char buf[8]; /* enough to hold "struct ", include NUL */ 527 char *prefix; 528 char *type; 529 530 if (streq(dec->type, "void")) { 531 return; 532 } --- 27 unchanged lines hidden (view full) --- 560 case REL_POINTER: 561 f_print(fout, "%s%s *%s", prefix, type, dec->name); 562 break; 563 case REL_ARRAY: 564 f_print(fout, "struct {\n"); 565 tabify(fout, tab); 566 f_print(fout, "\tu_int %s_len;\n", dec->name); 567 tabify(fout, tab); |
344 f_print(fout, "\t%s%s *%s_val;\n", prefix, type, dec->name); | 568 f_print(fout, 569 "\t%s%s *%s_val;\n", prefix, type, dec->name); |
345 tabify(fout, tab); 346 f_print(fout, "} %s", dec->name); 347 break; 348 } 349 } | 570 tabify(fout, tab); 571 f_print(fout, "} %s", dec->name); 572 break; 573 } 574 } |
350 f_print(fout, ";\n"); | 575 f_print(fout, separator); |
351} 352 | 576} 577 |
353 354 | |
355static 356undefined2(type, stop) 357 char *type; 358 char *stop; 359{ 360 list *l; 361 definition *def; 362 --- 12 unchanged lines hidden --- | 578static 579undefined2(type, stop) 580 char *type; 581 char *stop; 582{ 583 list *l; 584 definition *def; 585 --- 12 unchanged lines hidden --- |