rpc_main.c (7c478bd9) | rpc_main.c (61961e0f) |
---|---|
1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * --- 5 unchanged lines hidden (view full) --- 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ | 1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * --- 5 unchanged lines hidden (view full) --- 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ |
22 |
|
22/* 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 27/* All Rights Reserved */ 28/* 29 * University Copyright- Copyright (c) 1982, 1986, 1988 --- 7 unchanged lines hidden (view full) --- 37 38#pragma ident "%Z%%M% %I% %E% SMI" 39 40/* 41 * rpc_main.c, Top level of the RPC protocol compiler. 42 */ 43 44#include <stdio.h> | 23/* 24 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 25 * Use is subject to license terms. 26 */ 27/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 28/* All Rights Reserved */ 29/* 30 * University Copyright- Copyright (c) 1982, 1986, 1988 --- 7 unchanged lines hidden (view full) --- 38 39#pragma ident "%Z%%M% %I% %E% SMI" 40 41/* 42 * rpc_main.c, Top level of the RPC protocol compiler. 43 */ 44 45#include <stdio.h> |
46#include <stdlib.h> |
|
45#include <string.h> | 47#include <string.h> |
48#include <strings.h> |
|
46#include <unistd.h> | 49#include <unistd.h> |
50#include <ctype.h> |
|
47#include <sys/types.h> 48#include <sys/param.h> 49#include <sys/file.h> 50#include <sys/stat.h> 51#include "rpc_parse.h" 52#include "rpc_util.h" 53#include "rpc_scan.h" 54 55 | 51#include <sys/types.h> 52#include <sys/param.h> 53#include <sys/file.h> 54#include <sys/stat.h> 55#include "rpc_parse.h" 56#include "rpc_util.h" 57#include "rpc_scan.h" 58 59 |
56extern void write_sample_svc(); 57int write_sample_clnt(); 58void write_sample_clnt_main(); 59char *rindex(); | 60extern void write_sample_svc(definition *); 61extern int write_sample_clnt(definition *); 62extern void write_sample_clnt_main(void); 63extern void reinitialize(void); 64extern void crash(void); 65extern void add_type(int, char *); 66extern void add_sample_msg(void); |
60 | 67 |
61static int svc_output(); 62static void mkfile_output(); | 68static void svc_output(char *, char *, int, char *); 69static void clnt_output(char *, char *, int, char *); 70static void c_output(char *, char *, int, char *); 71static void mkfile_output(struct commandline *); 72static void c_initialize(void); 73static void h_output(char *, char *, int, char *); 74static void s_output(int, char *[], char *, char *, int, char *, int, int); 75static void l_output(char *, char *, int, char *); 76static void t_output(char *, char *, int, char *); 77static int do_registers(int, char *[]); 78static uint_t parseargs(int, char *[], struct commandline *); 79static void usage(void); 80static void version_info(void); 81static void options_usage(void); |
63 | 82 |
64#define EXTEND 1 /* alias for TRUE */ | 83#define EXTEND 1 /* alias for TRUE */ |
65#define DONT_EXTEND 0 /* alias for FALSE */ 66 67#define SUNOS_CPP "/usr/lib/cpp" 68static int cppDefined = 0; /* explicit path for C preprocessor */ 69 70 71static char *cmdname; 72 --- 8 unchanged lines hidden (view full) --- 81static char *allnv[] = { 82 "rpcgen", "-s", "netpath", 83}; 84static int allnc = sizeof (allnv)/sizeof (allnv[0]); 85 86/* 87 * machinations for handling expanding argument list 88 */ | 84#define DONT_EXTEND 0 /* alias for FALSE */ 85 86#define SUNOS_CPP "/usr/lib/cpp" 87static int cppDefined = 0; /* explicit path for C preprocessor */ 88 89 90static char *cmdname; 91 --- 8 unchanged lines hidden (view full) --- 100static char *allnv[] = { 101 "rpcgen", "-s", "netpath", 102}; 103static int allnc = sizeof (allnv)/sizeof (allnv[0]); 104 105/* 106 * machinations for handling expanding argument list 107 */ |
89static void addarg(); /* add another argument to the list */ 90static void putarg(); /* put argument at specified location */ 91static void clear_args(); /* clear argument list */ 92static void checkfiles(); /* check if out file already exists */ | 108static void addarg(char *); /* add another argument to the list */ 109static void putarg(int, char *); /* put argument at specified location */ 110static void clear_args(void); /* clear argument list */ 111static void checkfiles(char *, char *); /* check if out file already exists */ |
93 94 | 112 113 |
95 | |
96#define ARGLISTLEN 20 97#define FIXEDARGS 2 98 99static char *arglist[ARGLISTLEN]; 100static int argcount = FIXEDARGS; 101 102 103int nonfatalerrors; /* errors */ --- 21 unchanged lines hidden (view full) --- 125int CCflag = 0; /* C++ files */ 126static int allfiles; /* generate all files */ 127int tirpcflag = 1; /* generating code for tirpc, by default */ 128xdrfunc *xdrfunc_head = NULL; /* xdr function list */ 129xdrfunc *xdrfunc_tail = NULL; /* xdr function list */ 130pid_t childpid; 131 132 | 114#define ARGLISTLEN 20 115#define FIXEDARGS 2 116 117static char *arglist[ARGLISTLEN]; 118static int argcount = FIXEDARGS; 119 120 121int nonfatalerrors; /* errors */ --- 21 unchanged lines hidden (view full) --- 143int CCflag = 0; /* C++ files */ 144static int allfiles; /* generate all files */ 145int tirpcflag = 1; /* generating code for tirpc, by default */ 146xdrfunc *xdrfunc_head = NULL; /* xdr function list */ 147xdrfunc *xdrfunc_tail = NULL; /* xdr function list */ 148pid_t childpid; 149 150 |
133main(argc, argv) 134 int argc; 135 char *argv[]; | 151int 152main(int argc, char *argv[]) |
136{ 137 struct commandline cmd; 138 | 153{ 154 struct commandline cmd; 155 |
139 (void) memset((char *)&cmd, 0, sizeof (struct commandline)); | 156 (void) memset(&cmd, 0, sizeof (struct commandline)); |
140 clear_args(); 141 if (!parseargs(argc, argv, &cmd)) 142 usage(); 143 /* 144 * Only the client and server side stubs are likely to be customized, 145 * so in that case only, check if the outfile exists, and if so, 146 * print an error message and exit. 147 */ | 157 clear_args(); 158 if (!parseargs(argc, argv, &cmd)) 159 usage(); 160 /* 161 * Only the client and server side stubs are likely to be customized, 162 * so in that case only, check if the outfile exists, and if so, 163 * print an error message and exit. 164 */ |
148 if (cmd.Ssflag || cmd.Scflag || cmd.makefileflag) { | 165 if (cmd.Ssflag || cmd.Scflag || cmd.makefileflag) |
149 checkfiles(cmd.infile, cmd.outfile); | 166 checkfiles(cmd.infile, cmd.outfile); |
150 } | |
151 else 152 checkfiles(cmd.infile, NULL); 153 154 if (cmd.cflag) { 155 c_output(cmd.infile, "-DRPC_XDR", DONT_EXTEND, cmd.outfile); 156 } else if (cmd.hflag) { 157 h_output(cmd.infile, "-DRPC_HDR", DONT_EXTEND, cmd.outfile); 158 } else if (cmd.lflag) { --- 22 unchanged lines hidden (view full) --- 181 if (inetdflag || !tirpcflag) 182 s_output(allc, allv, cmd.infile, "-DRPC_SVC", EXTEND, 183 "_svc.c", cmd.mflag, cmd.nflag); 184 else 185 s_output(allnc, allnv, cmd.infile, "-DRPC_SVC", 186 EXTEND, "_svc.c", cmd.mflag, cmd.nflag); 187 if (tblflag) { 188 reinitialize(); | 167 else 168 checkfiles(cmd.infile, NULL); 169 170 if (cmd.cflag) { 171 c_output(cmd.infile, "-DRPC_XDR", DONT_EXTEND, cmd.outfile); 172 } else if (cmd.hflag) { 173 h_output(cmd.infile, "-DRPC_HDR", DONT_EXTEND, cmd.outfile); 174 } else if (cmd.lflag) { --- 22 unchanged lines hidden (view full) --- 197 if (inetdflag || !tirpcflag) 198 s_output(allc, allv, cmd.infile, "-DRPC_SVC", EXTEND, 199 "_svc.c", cmd.mflag, cmd.nflag); 200 else 201 s_output(allnc, allnv, cmd.infile, "-DRPC_SVC", 202 EXTEND, "_svc.c", cmd.mflag, cmd.nflag); 203 if (tblflag) { 204 reinitialize(); |
189 t_output(cmd.infile, "-DRPC_TBL", EXTEND, "_tbl.i"); | 205 t_output(cmd.infile, "-DRPC_TBL", EXTEND, "_tbl.i"); |
190 } 191 192 if (allfiles) { 193 reinitialize(); 194 svc_output(cmd.infile, "-DRPC_SERVER", EXTEND, 195 "_server.c"); 196 reinitialize(); 197 clnt_output(cmd.infile, "-DRPC_CLIENT", EXTEND, 198 "_client.c"); 199 200 } 201 if (allfiles || (cmd.makefileflag == 1)) { 202 reinitialize(); 203 mkfile_output(&cmd); 204 } 205 206 } | 206 } 207 208 if (allfiles) { 209 reinitialize(); 210 svc_output(cmd.infile, "-DRPC_SERVER", EXTEND, 211 "_server.c"); 212 reinitialize(); 213 clnt_output(cmd.infile, "-DRPC_CLIENT", EXTEND, 214 "_client.c"); 215 216 } 217 if (allfiles || (cmd.makefileflag == 1)) { 218 reinitialize(); 219 mkfile_output(&cmd); 220 } 221 222 } |
207 exit(nonfatalerrors); 208 /* NOTREACHED */ | 223 return (nonfatalerrors); |
209} 210 211 212/* 213 * add extension to filename 214 */ 215static char * | 224} 225 226 227/* 228 * add extension to filename 229 */ 230static char * |
216extendfile(file, ext) 217 char *file; 218 char *ext; | 231extendfile(char *file, char *ext) |
219{ 220 char *res; 221 char *p; 222 | 232{ 233 char *res; 234 char *p; 235 |
223 res = alloc(strlen(file) + strlen(ext) + 1); 224 if (res == NULL) { | 236 res = malloc(strlen(file) + strlen(ext) + 1); 237 if (res == NULL) |
225 abort(); | 238 abort(); |
226 } | |
227 p = strrchr(file, '.'); | 239 p = strrchr(file, '.'); |
228 if (p == NULL) { | 240 if (p == NULL) |
229 p = file + strlen(file); | 241 p = file + strlen(file); |
230 } | |
231 (void) strcpy(res, file); 232 (void) strcpy(res + (p - file), ext); 233 return (res); 234} 235 236/* 237 * Open output file with given extension 238 */ | 242 (void) strcpy(res, file); 243 (void) strcpy(res + (p - file), ext); 244 return (res); 245} 246 247/* 248 * Open output file with given extension 249 */ |
239static 240open_output(infile, outfile) 241 char *infile; 242 char *outfile; | 250static void 251open_output(char *infile, char *outfile) |
243{ 244 245 if (outfile == NULL) { 246 fout = stdout; 247 return; 248 } 249 250 if (infile != NULL && streq(outfile, infile)) { --- 6 unchanged lines hidden (view full) --- 257 f_print(stderr, "%s: unable to open ", cmdname); 258 perror(outfile); 259 crash(); 260 } 261 record_open(outfile); 262 263} 264 | 252{ 253 254 if (outfile == NULL) { 255 fout = stdout; 256 return; 257 } 258 259 if (infile != NULL && streq(outfile, infile)) { --- 6 unchanged lines hidden (view full) --- 266 f_print(stderr, "%s: unable to open ", cmdname); 267 perror(outfile); 268 crash(); 269 } 270 record_open(outfile); 271 272} 273 |
265static 266add_warning() | 274static void 275add_warning(void) |
267{ 268 f_print(fout, "/*\n"); 269 f_print(fout, " * Please do not edit this file.\n"); 270 f_print(fout, " * It was generated using rpcgen.\n"); 271 f_print(fout, " */\n\n"); 272} 273 274/* clear list of arguments */ | 276{ 277 f_print(fout, "/*\n"); 278 f_print(fout, " * Please do not edit this file.\n"); 279 f_print(fout, " * It was generated using rpcgen.\n"); 280 f_print(fout, " */\n\n"); 281} 282 283/* clear list of arguments */ |
275static void clear_args() | 284static void 285clear_args(void) |
276{ 277 int i; | 286{ 287 int i; |
288 |
|
278 for (i = FIXEDARGS; i < ARGLISTLEN; i++) 279 arglist[i] = NULL; 280 argcount = FIXEDARGS; 281} 282 283/* make sure that a CPP exists */ | 289 for (i = FIXEDARGS; i < ARGLISTLEN; i++) 290 arglist[i] = NULL; 291 argcount = FIXEDARGS; 292} 293 294/* make sure that a CPP exists */ |
284static void find_cpp() | 295static void 296find_cpp(void) |
285{ 286 struct stat buf; 287 288 if (stat(CPP, &buf) < 0) { /* SVR4 or explicit cpp does not exist */ 289 if (cppDefined) { | 297{ 298 struct stat buf; 299 300 if (stat(CPP, &buf) < 0) { /* SVR4 or explicit cpp does not exist */ 301 if (cppDefined) { |
290 fprintf(stderr, | 302 (void) fprintf(stderr, |
291 "cannot find C preprocessor: %s \n", CPP); 292 crash(); 293 } else { /* try the other one */ 294 CPP = SUNOS_CPP; 295 if (stat(CPP, &buf) < 0) { /* can't find any cpp */ | 303 "cannot find C preprocessor: %s \n", CPP); 304 crash(); 305 } else { /* try the other one */ 306 CPP = SUNOS_CPP; 307 if (stat(CPP, &buf) < 0) { /* can't find any cpp */ |
296 fprintf(stderr, | 308 (void) fprintf(stderr, |
297 "cannot find any C preprocessor (cpp)\n"); 298 crash(); 299 } 300 } 301 } 302} 303 304/* 305 * Open input file with given define for C-preprocessor 306 */ | 309 "cannot find any C preprocessor (cpp)\n"); 310 crash(); 311 } 312 } 313 } 314} 315 316/* 317 * Open input file with given define for C-preprocessor 318 */ |
307static 308open_input(infile, define) 309 char *infile; 310 char *define; | 319static void 320open_input(char *infile, char *define) |
311{ 312 int pd[2]; 313 314 infilename = (infile == NULL) ? "<stdin>" : infile; 315 (void) pipe(pd); 316 switch (childpid = fork()) { 317 case 0: 318 find_cpp(); 319 putarg(0, CPP); 320 putarg(1, CPPFLAGS); 321 addarg(define); 322 if (infile) 323 addarg(infile); 324 addarg((char *)NULL); 325 (void) close(1); 326 (void) dup2(pd[1], 1); 327 (void) close(pd[0]); | 321{ 322 int pd[2]; 323 324 infilename = (infile == NULL) ? "<stdin>" : infile; 325 (void) pipe(pd); 326 switch (childpid = fork()) { 327 case 0: 328 find_cpp(); 329 putarg(0, CPP); 330 putarg(1, CPPFLAGS); 331 addarg(define); 332 if (infile) 333 addarg(infile); 334 addarg((char *)NULL); 335 (void) close(1); 336 (void) dup2(pd[1], 1); 337 (void) close(pd[0]); |
328 execv(arglist[0], arglist); | 338 (void) execv(arglist[0], arglist); |
329 perror("execv"); 330 exit(1); | 339 perror("execv"); 340 exit(1); |
341 /* NOTREACHED */ |
|
331 case -1: 332 perror("fork"); 333 exit(1); 334 } 335 (void) close(pd[1]); 336 fin = fdopen(pd[0], "r"); 337 if (fin == NULL) { 338 f_print(stderr, "%s: ", cmdname); 339 perror(infilename); 340 crash(); 341 } 342} 343 344/* valid tirpc nettypes */ | 342 case -1: 343 perror("fork"); 344 exit(1); 345 } 346 (void) close(pd[1]); 347 fin = fdopen(pd[0], "r"); 348 if (fin == NULL) { 349 f_print(stderr, "%s: ", cmdname); 350 perror(infilename); 351 crash(); 352 } 353} 354 355/* valid tirpc nettypes */ |
345static char *valid_ti_nettypes[] = 346{ | 356static char *valid_ti_nettypes[] = { |
347 "netpath", 348 "visible", 349 "circuit_v", 350 "datagram_v", 351 "circuit_n", 352 "datagram_n", 353 "udp", 354 "tcp", 355 "raw", 356 NULL | 357 "netpath", 358 "visible", 359 "circuit_v", 360 "datagram_v", 361 "circuit_n", 362 "datagram_n", 363 "udp", 364 "tcp", 365 "raw", 366 NULL |
357 }; | 367}; |
358 359/* valid inetd nettypes */ | 368 369/* valid inetd nettypes */ |
360static char *valid_i_nettypes[] = 361{ | 370static char *valid_i_nettypes[] = { |
362 "udp", 363 "tcp", 364 NULL | 371 "udp", 372 "tcp", 373 NULL |
365 }; | 374}; |
366 | 375 |
367static int check_nettype(name, list_to_check) 368char *name; 369char *list_to_check[]; | 376static int 377check_nettype(char *name, char *list_to_check[]) |
370{ 371 int i; 372 for (i = 0; list_to_check[i] != NULL; i++) { 373 if (strcmp(name, list_to_check[i]) == 0) { 374 return (1); 375 } 376 } 377 f_print(stderr, "illegal nettype :\'%s\'\n", name); 378 return (0); 379} 380 381static char * | 378{ 379 int i; 380 for (i = 0; list_to_check[i] != NULL; i++) { 381 if (strcmp(name, list_to_check[i]) == 0) { 382 return (1); 383 } 384 } 385 f_print(stderr, "illegal nettype :\'%s\'\n", name); 386 return (0); 387} 388 389static char * |
382file_name(file, ext) 383char *file; 384char *ext; | 390file_name(char *file, char *ext) |
385{ 386 char *temp; 387 temp = extendfile(file, ext); 388 389 if (access(temp, F_OK) != -1) 390 return (temp); 391 else 392 return ((char *)" "); | 391{ 392 char *temp; 393 temp = extendfile(file, ext); 394 395 if (access(temp, F_OK) != -1) 396 return (temp); 397 else 398 return ((char *)" "); |
393 | |
394} 395 396 | 399} 400 401 |
397static 398c_output(infile, define, extend, outfile) 399 char *infile; 400 char *define; 401 int extend; 402 char *outfile; | 402static void 403c_output(char *infile, char *define, int extend, char *outfile) |
403{ 404 definition *def; 405 char *include; 406 char *outfilename; 407 long tell; 408 409 c_initialize(); 410 open_input(infile, define); 411 outfilename = extend ? extendfile(infile, outfile) : outfile; 412 open_output(infile, outfilename); 413 add_warning(); 414 if (infile && (include = extendfile(infile, ".h"))) { 415 f_print(fout, "#include \"%s\"\n", include); 416 free(include); 417 /* .h file already contains rpc/rpc.h */ 418 } else 419 f_print(fout, "#include <rpc/rpc.h>\n"); 420 /* | 404{ 405 definition *def; 406 char *include; 407 char *outfilename; 408 long tell; 409 410 c_initialize(); 411 open_input(infile, define); 412 outfilename = extend ? extendfile(infile, outfile) : outfile; 413 open_output(infile, outfilename); 414 add_warning(); 415 if (infile && (include = extendfile(infile, ".h"))) { 416 f_print(fout, "#include \"%s\"\n", include); 417 free(include); 418 /* .h file already contains rpc/rpc.h */ 419 } else 420 f_print(fout, "#include <rpc/rpc.h>\n"); 421 /* |
421 * Include malloc.h to support mem_alloc calls. | 422 * Include stdlib.h to support mem_alloc calls. |
422 */ 423 f_print(fout, "\n#ifndef _KERNEL\n"); | 423 */ 424 f_print(fout, "\n#ifndef _KERNEL\n"); |
424 f_print(fout, "#include <malloc.h>\n"); | 425 f_print(fout, "#include <stdlib.h>\n"); |
425 f_print(fout, "#endif /* !_KERNEL */\n\n"); 426 tell = ftell(fout); 427 while (def = get_definition()) { 428 emit(def); 429 } 430 if (extend && tell == ftell(fout)) { 431 (void) unlink(outfilename); 432 } 433} 434 435 | 426 f_print(fout, "#endif /* !_KERNEL */\n\n"); 427 tell = ftell(fout); 428 while (def = get_definition()) { 429 emit(def); 430 } 431 if (extend && tell == ftell(fout)) { 432 (void) unlink(outfilename); 433 } 434} 435 436 |
436c_initialize() | 437static void 438c_initialize(void) |
437{ | 439{ |
438 | |
439 /* 440 * add all the starting basic types. 441 * We may need to add some derived types 442 * if we need to generate INLINE macros. 443 * These types are defined in rpc/types.h 444 */ 445 add_type(1, "int"); 446 add_type(1, "long"); 447 add_type(1, "short"); 448 add_type(1, "bool"); 449 add_type(1, "u_int"); 450 add_type(1, "u_long"); 451 add_type(1, "u_short"); 452 add_type(1, "rpcprog_t"); 453 add_type(1, "rpcvers_t"); 454 add_type(1, "rpcproc_t"); 455 add_type(1, "rpcprot_t"); 456 add_type(1, "rpcport_t"); | 440 /* 441 * add all the starting basic types. 442 * We may need to add some derived types 443 * if we need to generate INLINE macros. 444 * These types are defined in rpc/types.h 445 */ 446 add_type(1, "int"); 447 add_type(1, "long"); 448 add_type(1, "short"); 449 add_type(1, "bool"); 450 add_type(1, "u_int"); 451 add_type(1, "u_long"); 452 add_type(1, "u_short"); 453 add_type(1, "rpcprog_t"); 454 add_type(1, "rpcvers_t"); 455 add_type(1, "rpcproc_t"); 456 add_type(1, "rpcprot_t"); 457 add_type(1, "rpcport_t"); |
457 | |
458} 459 460char rpcgen_table_dcl1[] = "struct rpcgen_table {\n"; 461 462char rpcgen_table_dcl2[] = "\txdrproc_t\txdr_arg;\n" 463 "\tunsigned\tlen_arg;\n" 464 "\txdrproc_t\txdr_res;\n" 465 "\tunsigned\tlen_res;\n" 466 "};\n"; 467 468char rpcgen_table_proc[] = "\tvoid\t*(*proc)();\n"; 469 470char rpcgen_table_proc_b[] = "\tchar\t*(*proc)();\n"; 471 472 473char * | 458} 459 460char rpcgen_table_dcl1[] = "struct rpcgen_table {\n"; 461 462char rpcgen_table_dcl2[] = "\txdrproc_t\txdr_arg;\n" 463 "\tunsigned\tlen_arg;\n" 464 "\txdrproc_t\txdr_res;\n" 465 "\tunsigned\tlen_res;\n" 466 "};\n"; 467 468char rpcgen_table_proc[] = "\tvoid\t*(*proc)();\n"; 469 470char rpcgen_table_proc_b[] = "\tchar\t*(*proc)();\n"; 471 472 473char * |
474generate_guard(pathname) 475 char *pathname; | 474generate_guard(char *pathname) |
476{ 477 char *filename, *guard, *tmp; 478 479 filename = strrchr(pathname, '/'); /* find last component */ 480 filename = ((filename == 0) ? pathname : filename+1); 481 guard = extendfile(filename, "_H_RPCGEN"); 482 483 /* --- 20 unchanged lines hidden (view full) --- 504 return (guard); 505} 506 507/* 508 * Compile into an XDR header file 509 */ 510 511 | 475{ 476 char *filename, *guard, *tmp; 477 478 filename = strrchr(pathname, '/'); /* find last component */ 479 filename = ((filename == 0) ? pathname : filename+1); 480 guard = extendfile(filename, "_H_RPCGEN"); 481 482 /* --- 20 unchanged lines hidden (view full) --- 503 return (guard); 504} 505 506/* 507 * Compile into an XDR header file 508 */ 509 510 |
512static 513h_output(infile, define, extend, outfile) 514 char *infile; 515 char *define; 516 int extend; 517 char *outfile; | 511static void 512h_output(char *infile, char *define, int extend, char *outfile) |
518{ 519 definition *def; 520 char *outfilename; 521 long tell; 522 char *guard; 523 list *l; 524 xdrfunc *xdrfuncp; 525 int i; 526 527 open_input(infile, define); 528 outfilename = extend ? extendfile(infile, outfile) : outfile; 529 open_output(infile, outfilename); 530 add_warning(); | 513{ 514 definition *def; 515 char *outfilename; 516 long tell; 517 char *guard; 518 list *l; 519 xdrfunc *xdrfuncp; 520 int i; 521 522 open_input(infile, define); 523 outfilename = extend ? extendfile(infile, outfile) : outfile; 524 open_output(infile, outfilename); 525 add_warning(); |
531 if (outfilename || infile) { | 526 if (outfilename || infile) |
532 guard = generate_guard(outfilename ? outfilename: infile); | 527 guard = generate_guard(outfilename ? outfilename: infile); |
533 } else | 528 else |
534 guard = "STDIN_"; 535 | 529 guard = "STDIN_"; 530 |
536 f_print(fout, "#ifndef _%s\n#define _%s\n\n", guard, 537 guard); | 531 f_print(fout, "#ifndef _%s\n#define _%s\n\n", guard, guard); |
538 539 f_print(fout, "#include <rpc/rpc.h>\n"); 540 541 if (mtflag) { 542 f_print(fout, "#ifndef _KERNEL\n"); 543 f_print(fout, "#include <synch.h>\n"); 544 f_print(fout, "#include <thread.h>\n"); 545 f_print(fout, "#endif /* !_KERNEL */\n"); --- 6 unchanged lines hidden (view full) --- 552 f_print(fout, "#endif\n\n"); 553 } 554 555 /* put in a typedef for quadprecision. Only with Cflag */ 556 557 tell = ftell(fout); 558 559 /* print data definitions */ | 532 533 f_print(fout, "#include <rpc/rpc.h>\n"); 534 535 if (mtflag) { 536 f_print(fout, "#ifndef _KERNEL\n"); 537 f_print(fout, "#include <synch.h>\n"); 538 f_print(fout, "#include <thread.h>\n"); 539 f_print(fout, "#endif /* !_KERNEL */\n"); --- 6 unchanged lines hidden (view full) --- 546 f_print(fout, "#endif\n\n"); 547 } 548 549 /* put in a typedef for quadprecision. Only with Cflag */ 550 551 tell = ftell(fout); 552 553 /* print data definitions */ |
560 while (def = get_definition()) { | 554 while (def = get_definition()) |
561 print_datadef(def); | 555 print_datadef(def); |
562 } | |
563 564 /* 565 * print function declarations. 566 * Do this after data definitions because they might be used as 567 * arguments for functions 568 */ | 556 557 /* 558 * print function declarations. 559 * Do this after data definitions because they might be used as 560 * arguments for functions 561 */ |
569 for (l = defined; l != NULL; l = l->next) { | 562 for (l = defined; l != NULL; l = l->next) |
570 print_funcdef(l->val); | 563 print_funcdef(l->val); |
571 } | |
572 /* Now print all xdr func declarations */ 573 if (xdrfunc_head != NULL) { | 564 /* Now print all xdr func declarations */ 565 if (xdrfunc_head != NULL) { |
566 f_print(fout, "\n/* the xdr functions */\n"); |
|
574 | 567 |
575 f_print(fout, 576 "\n/* the xdr functions */\n"); 577 | |
578 if (CCflag) { | 568 if (CCflag) { |
579 f_print(fout, "\n#ifdef __cplusplus\n"); 580 f_print(fout, "extern \"C\" {\n"); 581 f_print(fout, "#endif\n"); 582 } | 569 f_print(fout, "\n#ifdef __cplusplus\n"); 570 f_print(fout, "extern \"C\" {\n"); 571 f_print(fout, "#endif\n"); 572 } |
583 584 if (!Cflag) { 585 xdrfuncp = xdrfunc_head; 586 while (xdrfuncp != NULL) { 587 print_xdr_func_def(xdrfuncp->name, | 573 574 if (!Cflag) { 575 xdrfuncp = xdrfunc_head; 576 while (xdrfuncp != NULL) { 577 print_xdr_func_def(xdrfuncp->name, |
588 xdrfuncp->pointerp, 2); | 578 xdrfuncp->pointerp, 2); |
589 xdrfuncp = xdrfuncp->next; 590 } 591 } else { | 579 xdrfuncp = xdrfuncp->next; 580 } 581 } else { |
592 | |
593 for (i = 1; i < 3; i++) { 594 if (i == 1) | 582 for (i = 1; i < 3; i++) { 583 if (i == 1) |
595 f_print(fout, "\n#if defined(__STDC__) || defined(__cplusplus)\n"); 596 | 584 f_print(fout, 585"\n#if defined(__STDC__) || defined(__cplusplus)\n"); |
597 else 598 f_print(fout, "\n#else /* K&R C */\n"); 599 600 xdrfuncp = xdrfunc_head; 601 while (xdrfuncp != NULL) { 602 print_xdr_func_def(xdrfuncp->name, | 586 else 587 f_print(fout, "\n#else /* K&R C */\n"); 588 589 xdrfuncp = xdrfunc_head; 590 while (xdrfuncp != NULL) { 591 print_xdr_func_def(xdrfuncp->name, |
603 xdrfuncp->pointerp, i); | 592 xdrfuncp->pointerp, i); |
604 xdrfuncp = xdrfuncp->next; 605 } 606 } | 593 xdrfuncp = xdrfuncp->next; 594 } 595 } |
607 f_print(fout, "\n#endif /* K&R C */\n"); | 596 f_print(fout, "\n#endif /* K&R C */\n"); |
608 } 609 } 610 611 if (extend && tell == ftell(fout)) { 612 (void) unlink(outfilename); 613 } else if (tblflag) { 614 f_print(fout, rpcgen_table_dcl1); 615 if (tirpcflag) --- 10 unchanged lines hidden (view full) --- 626 } 627 628 f_print(fout, "\n#endif /* !_%s */\n", guard); 629} 630 631/* 632 * Compile into an RPC service 633 */ | 597 } 598 } 599 600 if (extend && tell == ftell(fout)) { 601 (void) unlink(outfilename); 602 } else if (tblflag) { 603 f_print(fout, rpcgen_table_dcl1); 604 if (tirpcflag) --- 10 unchanged lines hidden (view full) --- 615 } 616 617 f_print(fout, "\n#endif /* !_%s */\n", guard); 618} 619 620/* 621 * Compile into an RPC service 622 */ |
634static 635s_output(argc, argv, infile, define, extend, outfile, nomain, netflag) 636 int argc; 637 char *argv[]; 638 char *infile; 639 char *define; 640 int extend; 641 char *outfile; 642 int nomain; 643 int netflag; | 623static void 624s_output(int argc, char *argv[], char *infile, char *define, int extend, 625 char *outfile, int nomain, int netflag) |
644{ 645 char *include; 646 definition *def; 647 int foundprogram = 0; 648 char *outfilename; 649 650 open_input(infile, define); 651 outfilename = extend ? extendfile(infile, outfile) : outfile; --- 13 unchanged lines hidden (view full) --- 665 f_print(fout, 666 "#include <rpc/pmap_clnt.h> /* for pmap_unset */\n"); 667 f_print(fout, "#include <string.h> /* strcmp */\n"); 668 } 669 if (strcmp(svcclosetime, "-1") == 0) 670 indefinitewait = 1; 671 else if (strcmp(svcclosetime, "0") == 0) 672 exitnow = 1; | 626{ 627 char *include; 628 definition *def; 629 int foundprogram = 0; 630 char *outfilename; 631 632 open_input(infile, define); 633 outfilename = extend ? extendfile(infile, outfile) : outfile; --- 13 unchanged lines hidden (view full) --- 647 f_print(fout, 648 "#include <rpc/pmap_clnt.h> /* for pmap_unset */\n"); 649 f_print(fout, "#include <string.h> /* strcmp */\n"); 650 } 651 if (strcmp(svcclosetime, "-1") == 0) 652 indefinitewait = 1; 653 else if (strcmp(svcclosetime, "0") == 0) 654 exitnow = 1; |
673 else if (inetdflag || pmflag) { | 655 else if (inetdflag || pmflag) |
674 timerflag = 1; | 656 timerflag = 1; |
675 } | |
676 677 if (!tirpcflag && inetdflag) 678 f_print(fout, "#include <sys/termios.h> /* TIOCNOTTY */\n"); | 657 658 if (!tirpcflag && inetdflag) 659 f_print(fout, "#include <sys/termios.h> /* TIOCNOTTY */\n"); |
679 if (Cflag && (inetdflag || pmflag)) { | 660 if (Cflag && (inetdflag || pmflag)) |
680 if (tirpcflag) 681 f_print(fout, "#include <unistd.h> /* setsid */\n"); | 661 if (tirpcflag) 662 f_print(fout, "#include <unistd.h> /* setsid */\n"); |
682 } | |
683 if (tirpcflag) 684 f_print(fout, "#include <sys/types.h>\n"); 685 686 f_print(fout, "#include <memory.h>\n"); 687 f_print(fout, "#include <stropts.h>\n"); 688 if (inetdflag || !tirpcflag) { 689 f_print(fout, "#include <sys/socket.h>\n"); 690 f_print(fout, "#include <netinet/in.h>\n"); 691 f_print(fout, "#include <rpc/svc_soc.h>\n"); 692 } 693 | 663 if (tirpcflag) 664 f_print(fout, "#include <sys/types.h>\n"); 665 666 f_print(fout, "#include <memory.h>\n"); 667 f_print(fout, "#include <stropts.h>\n"); 668 if (inetdflag || !tirpcflag) { 669 f_print(fout, "#include <sys/socket.h>\n"); 670 f_print(fout, "#include <netinet/in.h>\n"); 671 f_print(fout, "#include <rpc/svc_soc.h>\n"); 672 } 673 |
694 if ((netflag || pmflag) && tirpcflag && !nomain) { | 674 if ((netflag || pmflag) && tirpcflag && !nomain) |
695 f_print(fout, "#include <netconfig.h>\n"); | 675 f_print(fout, "#include <netconfig.h>\n"); |
696 } | |
697 if (tirpcflag) 698 f_print(fout, "#include <sys/resource.h> /* rlimit */\n"); 699 if (logflag || inetdflag || pmflag) 700 f_print(fout, "#include <syslog.h>\n"); 701 702 /* for ANSI-C */ 703 if (Cflag) 704 f_print(fout, 705 "\n#ifndef SIG_PF\n#define SIG_PF void(*)\ 706(int)\n#endif\n"); 707 708 f_print(fout, "\n#ifdef DEBUG\n#define RPC_SVC_FG\n#endif\n"); 709 if (timerflag) 710 f_print(fout, "\n#define _RPCSVC_CLOSEDOWN %s\n", 711 svcclosetime); | 676 if (tirpcflag) 677 f_print(fout, "#include <sys/resource.h> /* rlimit */\n"); 678 if (logflag || inetdflag || pmflag) 679 f_print(fout, "#include <syslog.h>\n"); 680 681 /* for ANSI-C */ 682 if (Cflag) 683 f_print(fout, 684 "\n#ifndef SIG_PF\n#define SIG_PF void(*)\ 685(int)\n#endif\n"); 686 687 f_print(fout, "\n#ifdef DEBUG\n#define RPC_SVC_FG\n#endif\n"); 688 if (timerflag) 689 f_print(fout, "\n#define _RPCSVC_CLOSEDOWN %s\n", 690 svcclosetime); |
712 while (def = get_definition()) { | 691 while (def = get_definition()) |
713 foundprogram |= (def->def_kind == DEF_PROGRAM); | 692 foundprogram |= (def->def_kind == DEF_PROGRAM); |
714 } | |
715 if (extend && !foundprogram) { 716 (void) unlink(outfilename); 717 return; 718 } 719 write_most(infile, netflag, nomain); 720 if (!nomain) { 721 if (!do_registers(argc, argv)) { 722 if (outfilename) 723 (void) unlink(outfilename); 724 usage(); 725 } 726 write_rest(); 727 } 728} 729 730/* 731 * generate client side stubs 732 */ | 693 if (extend && !foundprogram) { 694 (void) unlink(outfilename); 695 return; 696 } 697 write_most(infile, netflag, nomain); 698 if (!nomain) { 699 if (!do_registers(argc, argv)) { 700 if (outfilename) 701 (void) unlink(outfilename); 702 usage(); 703 } 704 write_rest(); 705 } 706} 707 708/* 709 * generate client side stubs 710 */ |
733static 734l_output(infile, define, extend, outfile) 735 char *infile; 736 char *define; 737 int extend; 738 char *outfile; | 711static void 712l_output(char *infile, char *define, int extend, char *outfile) |
739{ 740 char *include; 741 definition *def; 742 int foundprogram = 0; 743 char *outfilename; 744 745 open_input(infile, define); 746 outfilename = extend ? extendfile(infile, outfile) : outfile; --- 7 unchanged lines hidden (view full) --- 754 } else 755 f_print(fout, "#include <rpc/rpc.h>\n"); 756 757 f_print(fout, "#ifndef _KERNEL\n"); 758 f_print(fout, "#include <stdio.h>\n"); 759 f_print(fout, "#include <stdlib.h> /* getenv, exit */\n"); 760 f_print(fout, "#endif /* !_KERNEL */\n"); 761 | 713{ 714 char *include; 715 definition *def; 716 int foundprogram = 0; 717 char *outfilename; 718 719 open_input(infile, define); 720 outfilename = extend ? extendfile(infile, outfile) : outfile; --- 7 unchanged lines hidden (view full) --- 728 } else 729 f_print(fout, "#include <rpc/rpc.h>\n"); 730 731 f_print(fout, "#ifndef _KERNEL\n"); 732 f_print(fout, "#include <stdio.h>\n"); 733 f_print(fout, "#include <stdlib.h> /* getenv, exit */\n"); 734 f_print(fout, "#endif /* !_KERNEL */\n"); 735 |
762 while (def = get_definition()) { | 736 while (def = get_definition()) |
763 foundprogram |= (def->def_kind == DEF_PROGRAM); | 737 foundprogram |= (def->def_kind == DEF_PROGRAM); |
764 } | |
765 if (extend && !foundprogram) { 766 (void) unlink(outfilename); 767 return; 768 } 769 write_stubs(); 770} 771 772/* 773 * generate the dispatch table 774 */ | 738 if (extend && !foundprogram) { 739 (void) unlink(outfilename); 740 return; 741 } 742 write_stubs(); 743} 744 745/* 746 * generate the dispatch table 747 */ |
775static 776t_output(infile, define, extend, outfile) 777 char *infile; 778 char *define; 779 int extend; 780 char *outfile; | 748static void 749t_output(char *infile, char *define, int extend, char *outfile) |
781{ 782 definition *def; 783 int foundprogram = 0; 784 char *outfilename; 785 786 open_input(infile, define); 787 outfilename = extend ? extendfile(infile, outfile) : outfile; 788 open_output(infile, outfilename); --- 4 unchanged lines hidden (view full) --- 793 if (extend && !foundprogram) { 794 (void) unlink(outfilename); 795 return; 796 } 797 write_tables(); 798} 799 800/* sample routine for the server template */ | 750{ 751 definition *def; 752 int foundprogram = 0; 753 char *outfilename; 754 755 open_input(infile, define); 756 outfilename = extend ? extendfile(infile, outfile) : outfile; 757 open_output(infile, outfilename); --- 4 unchanged lines hidden (view full) --- 762 if (extend && !foundprogram) { 763 (void) unlink(outfilename); 764 return; 765 } 766 write_tables(); 767} 768 769/* sample routine for the server template */ |
801static 802svc_output(infile, define, extend, outfile) 803 char *infile; 804 char *define; 805 int extend; 806 char *outfile; | 770static void 771svc_output(char *infile, char *define, int extend, char *outfile) |
807{ 808 definition *def; 809 char *include; 810 char *outfilename; 811 long tell; 812 open_input(infile, define); 813 outfilename = extend ? extendfile(infile, outfile) : outfile; 814 checkfiles(infile, outfilename); --- 11 unchanged lines hidden (view full) --- 826 f_print(fout, "#include <rpc/rpc.h>\n"); 827 } 828 829 f_print(fout, "#include <stdio.h>\n"); 830 f_print(fout, "#include <stdlib.h> /* getenv, exit */\n"); 831 f_print(fout, "#include <signal.h>\n"); 832 833 tell = ftell(fout); | 772{ 773 definition *def; 774 char *include; 775 char *outfilename; 776 long tell; 777 open_input(infile, define); 778 outfilename = extend ? extendfile(infile, outfile) : outfile; 779 checkfiles(infile, outfilename); --- 11 unchanged lines hidden (view full) --- 791 f_print(fout, "#include <rpc/rpc.h>\n"); 792 } 793 794 f_print(fout, "#include <stdio.h>\n"); 795 f_print(fout, "#include <stdlib.h> /* getenv, exit */\n"); 796 f_print(fout, "#include <signal.h>\n"); 797 798 tell = ftell(fout); |
834 while (def = get_definition()) { | 799 while (def = get_definition()) |
835 write_sample_svc(def); | 800 write_sample_svc(def); |
836 } 837 if (extend && tell == ftell(fout)) { | 801 if (extend && tell == ftell(fout)) |
838 (void) unlink(outfilename); | 802 (void) unlink(outfilename); |
839 } | |
840} 841 842/* sample main routine for client */ | 803} 804 805/* sample main routine for client */ |
843static 844clnt_output(infile, define, extend, outfile) 845 char *infile; 846 char *define; 847 int extend; 848 char *outfile; | 806static void 807clnt_output(char *infile, char *define, int extend, char *outfile) |
849{ 850 definition *def; 851 char *include; 852 char *outfilename; 853 long tell; 854 int has_program = 0; 855 856 open_input(infile, define); --- 11 unchanged lines hidden (view full) --- 868 free(include); 869 } else 870 f_print(fout, "#include <rpc/rpc.h>\n"); 871 872 f_print(fout, "#include <stdio.h>\n"); 873 f_print(fout, "#include <stdlib.h> /* getenv, exit */\n"); 874 875 tell = ftell(fout); | 808{ 809 definition *def; 810 char *include; 811 char *outfilename; 812 long tell; 813 int has_program = 0; 814 815 open_input(infile, define); --- 11 unchanged lines hidden (view full) --- 827 free(include); 828 } else 829 f_print(fout, "#include <rpc/rpc.h>\n"); 830 831 f_print(fout, "#include <stdio.h>\n"); 832 f_print(fout, "#include <stdlib.h> /* getenv, exit */\n"); 833 834 tell = ftell(fout); |
876 while (def = get_definition()) { | 835 while (def = get_definition()) |
877 has_program += write_sample_clnt(def); | 836 has_program += write_sample_clnt(def); |
878 } | |
879 880 if (has_program) 881 write_sample_clnt_main(); 882 | 837 838 if (has_program) 839 write_sample_clnt_main(); 840 |
883 if (extend && tell == ftell(fout)) { | 841 if (extend && tell == ftell(fout)) |
884 (void) unlink(outfilename); | 842 (void) unlink(outfilename); |
885 } | |
886} 887 888 | 843} 844 845 |
889static void mkfile_output(cmd) 890struct commandline *cmd; | 846static void 847mkfile_output(struct commandline *cmd) |
891{ 892 char *mkfilename, *clientname, *clntname, *xdrname, *hdrname; 893 char *servername, *svcname, *servprogname, *clntprogname; 894 char *temp; 895 896 svcname = file_name(cmd->infile, "_svc.c"); 897 clntname = file_name(cmd->infile, "_clnt.c"); 898 xdrname = file_name(cmd->infile, "_xdr.c"); --- 6 unchanged lines hidden (view full) --- 905 } else { 906 servername = " "; 907 clientname = " "; 908 } 909 servprogname = extendfile(cmd->infile, "_server"); 910 clntprogname = extendfile(cmd->infile, "_client"); 911 912 if (allfiles) { | 848{ 849 char *mkfilename, *clientname, *clntname, *xdrname, *hdrname; 850 char *servername, *svcname, *servprogname, *clntprogname; 851 char *temp; 852 853 svcname = file_name(cmd->infile, "_svc.c"); 854 clntname = file_name(cmd->infile, "_clnt.c"); 855 xdrname = file_name(cmd->infile, "_xdr.c"); --- 6 unchanged lines hidden (view full) --- 862 } else { 863 servername = " "; 864 clientname = " "; 865 } 866 servprogname = extendfile(cmd->infile, "_server"); 867 clntprogname = extendfile(cmd->infile, "_client"); 868 869 if (allfiles) { |
913 mkfilename = alloc(strlen("makefile.") + | 870 mkfilename = malloc(strlen("makefile.") + |
914 strlen(cmd->infile) + 1); 915 if (mkfilename == NULL) { 916 f_print(stderr, "Out of memory!\n"); 917 return; 918 } 919 temp = (char *)rindex(cmd->infile, '.'); | 871 strlen(cmd->infile) + 1); 872 if (mkfilename == NULL) { 873 f_print(stderr, "Out of memory!\n"); 874 return; 875 } 876 temp = (char *)rindex(cmd->infile, '.'); |
920 strcpy(mkfilename, "makefile."); | 877 (void) strcpy(mkfilename, "makefile."); |
921 (void) strncat(mkfilename, cmd->infile, 922 (temp - cmd->infile)); 923 } else 924 mkfilename = cmd->outfile; 925 926 927 checkfiles(NULL, mkfilename); 928 open_output(NULL, mkfilename); --- 46 unchanged lines hidden (view full) --- 975$(LDLIBS) \n\n"); 976 f_print(fout, "$(SERVER) : $(OBJECTS_SVC) \n"); 977 f_print(fout, "\t$(LINK.c) -o $(SERVER) $(OBJECTS_SVC) $(LDLIBS)\n\n "); 978 f_print(fout, "clean:\n\t $(RM) core $(TARGETS) $(OBJECTS_CLNT) \ 979$(OBJECTS_SVC) $(CLIENT) $(SERVER)\n\n"); 980} 981 982 | 878 (void) strncat(mkfilename, cmd->infile, 879 (temp - cmd->infile)); 880 } else 881 mkfilename = cmd->outfile; 882 883 884 checkfiles(NULL, mkfilename); 885 open_output(NULL, mkfilename); --- 46 unchanged lines hidden (view full) --- 932$(LDLIBS) \n\n"); 933 f_print(fout, "$(SERVER) : $(OBJECTS_SVC) \n"); 934 f_print(fout, "\t$(LINK.c) -o $(SERVER) $(OBJECTS_SVC) $(LDLIBS)\n\n "); 935 f_print(fout, "clean:\n\t $(RM) core $(TARGETS) $(OBJECTS_CLNT) \ 936$(OBJECTS_SVC) $(CLIENT) $(SERVER)\n\n"); 937} 938 939 |
983 | |
984/* 985 * Perform registrations for service output 986 * Return 0 if failed; 1 otherwise. 987 */ 988static int | 940/* 941 * Perform registrations for service output 942 * Return 0 if failed; 1 otherwise. 943 */ 944static int |
989do_registers(argc, argv) 990 int argc; 991 char *argv[]; | 945do_registers(int argc, char *argv[]) |
992{ 993 int i; 994 995 if (inetdflag || !tirpcflag) { 996 for (i = 1; i < argc; i++) { 997 if (streq(argv[i], "-s")) { 998 if (!check_nettype(argv[i + 1], 999 valid_i_nettypes)) --- 17 unchanged lines hidden (view full) --- 1017 } 1018 return (1); 1019} 1020 1021/* 1022 * Add another argument to the arg list 1023 */ 1024static void | 946{ 947 int i; 948 949 if (inetdflag || !tirpcflag) { 950 for (i = 1; i < argc; i++) { 951 if (streq(argv[i], "-s")) { 952 if (!check_nettype(argv[i + 1], 953 valid_i_nettypes)) --- 17 unchanged lines hidden (view full) --- 971 } 972 return (1); 973} 974 975/* 976 * Add another argument to the arg list 977 */ 978static void |
1025addarg(cp) 1026 char *cp; | 979addarg(char *cp) |
1027{ 1028 if (argcount >= ARGLISTLEN) { 1029 f_print(stderr, "rpcgen: too many defines\n"); 1030 crash(); 1031 /*NOTREACHED*/ 1032 } 1033 arglist[argcount++] = cp; | 980{ 981 if (argcount >= ARGLISTLEN) { 982 f_print(stderr, "rpcgen: too many defines\n"); 983 crash(); 984 /*NOTREACHED*/ 985 } 986 arglist[argcount++] = cp; |
1034 | |
1035} 1036 1037static void | 987} 988 989static void |
1038putarg(where, cp) 1039 char *cp; 1040 int where; | 990putarg(int where, char *cp) |
1041{ 1042 if (where >= ARGLISTLEN) { 1043 f_print(stderr, "rpcgen: arglist coding error\n"); 1044 crash(); 1045 /*NOTREACHED*/ 1046 } 1047 arglist[where] = cp; 1048} 1049 1050/* 1051 * if input file is stdin and an output file is specified then complain 1052 * if the file already exists. Otherwise the file may get overwritten 1053 * If input file does not exist, exit with an error 1054 */ | 991{ 992 if (where >= ARGLISTLEN) { 993 f_print(stderr, "rpcgen: arglist coding error\n"); 994 crash(); 995 /*NOTREACHED*/ 996 } 997 arglist[where] = cp; 998} 999 1000/* 1001 * if input file is stdin and an output file is specified then complain 1002 * if the file already exists. Otherwise the file may get overwritten 1003 * If input file does not exist, exit with an error 1004 */ |
1055 | |
1056static void | 1005static void |
1057checkfiles(infile, outfile) 1058char *infile; 1059char *outfile; | 1006checkfiles(char *infile, char *outfile) |
1060{ | 1007{ |
1061 | |
1062 struct stat buf; 1063 | 1008 struct stat buf; 1009 |
1064 if (infile) /* infile ! = NULL */ 1065 if (stat(infile, &buf) < 0) 1066 { | 1010 if (infile) { /* infile ! = NULL */ 1011 if (stat(infile, &buf) < 0) { |
1067 perror(infile); 1068 crash(); | 1012 perror(infile); 1013 crash(); |
1069 }; | 1014 } 1015 } |
1070 if (outfile) { 1071 if (stat(outfile, &buf) < 0) 1072 return; /* file does not exist */ | 1016 if (outfile) { 1017 if (stat(outfile, &buf) < 0) 1018 return; /* file does not exist */ |
1073 else { 1074 f_print(stderr, 1075 "file '%s' already exists and may be overwritten\n", 1076 outfile); 1077 crash(); 1078 } | 1019 f_print(stderr, 1020 "file '%s' already exists and may be overwritten\n", 1021 outfile); 1022 crash(); |
1079 } 1080} 1081 1082/* 1083 * Parse command line arguments 1084 */ | 1023 } 1024} 1025 1026/* 1027 * Parse command line arguments 1028 */ |
1085static 1086parseargs(argc, argv, cmd) 1087 int argc; 1088 char *argv[]; 1089 struct commandline *cmd; | 1029static uint_t 1030parseargs(int argc, char *argv[], struct commandline *cmd) |
1090{ 1091 int i; 1092 int j; 1093 char c, ch; 1094 char flag[(1 << 8 * sizeof (char))]; 1095 int nflags; 1096 1097 cmdname = argv[0]; 1098 cmd->infile = cmd->outfile = NULL; | 1031{ 1032 int i; 1033 int j; 1034 char c, ch; 1035 char flag[(1 << 8 * sizeof (char))]; 1036 int nflags; 1037 1038 cmdname = argv[0]; 1039 cmd->infile = cmd->outfile = NULL; |
1099 if (argc < 2) { | 1040 if (argc < 2) |
1100 return (0); | 1041 return (0); |
1101 } | |
1102 allfiles = 0; 1103 flag['c'] = 0; 1104 flag['h'] = 0; 1105 flag['l'] = 0; 1106 flag['m'] = 0; 1107 flag['o'] = 0; 1108 flag['s'] = 0; 1109 flag['n'] = 0; --- 18 unchanged lines hidden (view full) --- 1128 case 'a': 1129 allfiles = 1; 1130 break; 1131 case 'c': 1132 case 'h': 1133 case 'l': 1134 case 'm': 1135 case 't': | 1042 allfiles = 0; 1043 flag['c'] = 0; 1044 flag['h'] = 0; 1045 flag['l'] = 0; 1046 flag['m'] = 0; 1047 flag['o'] = 0; 1048 flag['s'] = 0; 1049 flag['n'] = 0; --- 18 unchanged lines hidden (view full) --- 1068 case 'a': 1069 allfiles = 1; 1070 break; 1071 case 'c': 1072 case 'h': 1073 case 'l': 1074 case 'm': 1075 case 't': |
1136 if (flag[c]) { | 1076 if (flag[c]) |
1137 return (0); | 1077 return (0); |
1138 } | |
1139 flag[c] = 1; 1140 break; 1141 case 'S': 1142 /* 1143 * sample flag: Ss or Sc. 1144 * Ss means set flag['S']; 1145 * Sc means set flag['C']; 1146 * Sm means set flag['M']; 1147 */ 1148 ch = argv[i][++j]; /* get next char */ 1149 if (ch == 's') 1150 ch = 'S'; 1151 else if (ch == 'c') 1152 ch = 'C'; 1153 else if (ch == 'm') 1154 ch = 'M'; 1155 else 1156 return (0); 1157 | 1078 flag[c] = 1; 1079 break; 1080 case 'S': 1081 /* 1082 * sample flag: Ss or Sc. 1083 * Ss means set flag['S']; 1084 * Sc means set flag['C']; 1085 * Sm means set flag['M']; 1086 */ 1087 ch = argv[i][++j]; /* get next char */ 1088 if (ch == 's') 1089 ch = 'S'; 1090 else if (ch == 'c') 1091 ch = 'C'; 1092 else if (ch == 'm') 1093 ch = 'M'; 1094 else 1095 return (0); 1096 |
1158 if (flag[ch]) { | 1097 if (flag[ch]) |
1159 return (0); | 1098 return (0); |
1160 } | |
1161 flag[ch] = 1; 1162 break; 1163 case 'C': /* ANSI C syntax */ 1164 Cflag = 1; 1165 ch = argv[i][j+1]; /* get next char */ 1166 1167 if (ch != 'C') 1168 break; --- 13 unchanged lines hidden (view full) --- 1182 break; 1183 case 'N': 1184 newstyle = 1; 1185 break; 1186 case 'L': 1187 logflag = 1; 1188 break; 1189 case 'K': | 1099 flag[ch] = 1; 1100 break; 1101 case 'C': /* ANSI C syntax */ 1102 Cflag = 1; 1103 ch = argv[i][j+1]; /* get next char */ 1104 1105 if (ch != 'C') 1106 break; --- 13 unchanged lines hidden (view full) --- 1120 break; 1121 case 'N': 1122 newstyle = 1; 1123 break; 1124 case 'L': 1125 logflag = 1; 1126 break; 1127 case 'K': |
1190 if (++i == argc) { | 1128 if (++i == argc) |
1191 return (0); | 1129 return (0); |
1192 } | |
1193 svcclosetime = argv[i]; 1194 goto nextarg; 1195 case 'T': 1196 tblflag = 1; 1197 break; 1198 case 'A': 1199 mtauto = 1; | 1130 svcclosetime = argv[i]; 1131 goto nextarg; 1132 case 'T': 1133 tblflag = 1; 1134 break; 1135 case 'A': 1136 mtauto = 1; |
1200 /* fall through */ | 1137 /* FALLTHRU */ |
1201 case 'M': 1202 mtflag = 1; 1203 break; 1204 case 'i' : | 1138 case 'M': 1139 mtflag = 1; 1140 break; 1141 case 'i' : |
1205 if (++i == argc) { | 1142 if (++i == argc) |
1206 return (0); | 1143 return (0); |
1207 } | |
1208 inlinelen = atoi(argv[i]); 1209 goto nextarg; 1210 case 'n': 1211 case 'o': 1212 case 's': 1213 if (argv[i][j - 1] != '-' || | 1144 inlinelen = atoi(argv[i]); 1145 goto nextarg; 1146 case 'n': 1147 case 'o': 1148 case 's': 1149 if (argv[i][j - 1] != '-' || |
1214 argv[i][j + 1] != 0) { | 1150 argv[i][j + 1] != 0) |
1215 return (0); | 1151 return (0); |
1216 } | |
1217 flag[c] = 1; | 1152 flag[c] = 1; |
1218 if (++i == argc) { | 1153 if (++i == argc) |
1219 return (0); | 1154 return (0); |
1220 } | |
1221 if (c == 'o') { | 1155 if (c == 'o') { |
1222 if (cmd->outfile) { | 1156 if (cmd->outfile) |
1223 return (0); | 1157 return (0); |
1224 } | |
1225 cmd->outfile = argv[i]; 1226 } 1227 goto nextarg; 1228 case 'D': | 1158 cmd->outfile = argv[i]; 1159 } 1160 goto nextarg; 1161 case 'D': |
1229 if (argv[i][j - 1] != '-') { | 1162 if (argv[i][j - 1] != '-') |
1230 return (0); | 1163 return (0); |
1231 } | |
1232 (void) addarg(argv[i]); 1233 goto nextarg; 1234 case 'v': 1235 version_info(); 1236 return (0); 1237 case 'Y': | 1164 (void) addarg(argv[i]); 1165 goto nextarg; 1166 case 'v': 1167 version_info(); 1168 return (0); 1169 case 'Y': |
1238 if (++i == argc) { | 1170 if (++i == argc) |
1239 return (0); | 1171 return (0); |
1240 } | |
1241 (void) strcpy(pathbuf, argv[i]); 1242 (void) strcat(pathbuf, "/cpp"); 1243 CPP = pathbuf; 1244 cppDefined = 1; 1245 goto nextarg; 1246 case 'r': 1247 rflag = !rflag; 1248 break; --- 23 unchanged lines hidden (view full) --- 1272 "Cannot use -I flag without -b flag.\n"); 1273 return (0); 1274 } 1275 pmflag = 1; 1276 } else { /* 4.1 mode */ 1277 pmflag = 0; /* set pmflag only in tirpcmode */ 1278 inetdflag = 1; /* inetdflag is TRUE by default */ 1279 if (cmd->nflag) { /* netid needs TIRPC */ | 1172 (void) strcpy(pathbuf, argv[i]); 1173 (void) strcat(pathbuf, "/cpp"); 1174 CPP = pathbuf; 1175 cppDefined = 1; 1176 goto nextarg; 1177 case 'r': 1178 rflag = !rflag; 1179 break; --- 23 unchanged lines hidden (view full) --- 1203 "Cannot use -I flag without -b flag.\n"); 1204 return (0); 1205 } 1206 pmflag = 1; 1207 } else { /* 4.1 mode */ 1208 pmflag = 0; /* set pmflag only in tirpcmode */ 1209 inetdflag = 1; /* inetdflag is TRUE by default */ 1210 if (cmd->nflag) { /* netid needs TIRPC */ |
1280 f_print(stderr, "Cannot use netid flag without TIRPC.\n"); | 1211 f_print(stderr, 1212 "Cannot use netid flag without TIRPC.\n"); |
1281 return (0); 1282 } 1283 } 1284 1285 if (newstyle && (tblflag || cmd->tflag)) { 1286 f_print(stderr, "Cannot use table flags with newstyle.\n"); 1287 return (0); 1288 } 1289 1290 /* check no conflicts with file generation flags */ 1291 nflags = cmd->cflag + cmd->hflag + cmd->lflag + cmd->mflag + 1292 cmd->sflag + cmd->nflag + cmd->tflag + cmd->Ssflag + 1293 cmd->Scflag + cmd->makefileflag; 1294 1295 if (nflags == 0) { | 1213 return (0); 1214 } 1215 } 1216 1217 if (newstyle && (tblflag || cmd->tflag)) { 1218 f_print(stderr, "Cannot use table flags with newstyle.\n"); 1219 return (0); 1220 } 1221 1222 /* check no conflicts with file generation flags */ 1223 nflags = cmd->cflag + cmd->hflag + cmd->lflag + cmd->mflag + 1224 cmd->sflag + cmd->nflag + cmd->tflag + cmd->Ssflag + 1225 cmd->Scflag + cmd->makefileflag; 1226 1227 if (nflags == 0) { |
1296 if (cmd->outfile != NULL || cmd->infile == NULL) { | 1228 if (cmd->outfile != NULL || cmd->infile == NULL) |
1297 return (0); | 1229 return (0); |
1298 } | |
1299 } else if (cmd->infile == NULL && 1300 (cmd->Ssflag || cmd->Scflag || cmd->makefileflag)) { 1301 f_print(stderr, "\"infile\" is required for template" 1302 " generation flags.\n"); 1303 return (0); | 1230 } else if (cmd->infile == NULL && 1231 (cmd->Ssflag || cmd->Scflag || cmd->makefileflag)) { 1232 f_print(stderr, "\"infile\" is required for template" 1233 " generation flags.\n"); 1234 return (0); |
1304 } if (nflags > 1) { | 1235 } 1236 if (nflags > 1) { |
1305 f_print(stderr, 1306 "Cannot have more than one file generation flag.\n"); 1307 return (0); 1308 } 1309 return (1); 1310} 1311 | 1237 f_print(stderr, 1238 "Cannot have more than one file generation flag.\n"); 1239 return (0); 1240 } 1241 return (1); 1242} 1243 |
1312static 1313usage() | 1244static void 1245usage(void) |
1314{ 1315 f_print(stderr, "%s (%d.%d)\n", cmdname, RPCGEN_MAJOR, RPCGEN_MINOR); 1316 f_print(stderr, "usage: %s infile\n", cmdname); 1317 f_print(stderr, "\t%s [-abCLNTMA] [-Dname[=value]] [-i size]" 1318 " [-I [-K seconds]] [-Y path] infile\n", cmdname); 1319 f_print(stderr, "\t%s [-c | -h | -l | -m | -t | -Sc | -Ss | -Sm]" 1320 " [-o outfile] [infile]\n", cmdname); 1321 f_print(stderr, "\t%s [-s nettype]* [-o outfile] [infile]\n", cmdname); 1322 f_print(stderr, "\t%s [-n netid]* [-o outfile] [infile]\n", cmdname); 1323 options_usage(); 1324 exit(1); 1325} 1326 | 1246{ 1247 f_print(stderr, "%s (%d.%d)\n", cmdname, RPCGEN_MAJOR, RPCGEN_MINOR); 1248 f_print(stderr, "usage: %s infile\n", cmdname); 1249 f_print(stderr, "\t%s [-abCLNTMA] [-Dname[=value]] [-i size]" 1250 " [-I [-K seconds]] [-Y path] infile\n", cmdname); 1251 f_print(stderr, "\t%s [-c | -h | -l | -m | -t | -Sc | -Ss | -Sm]" 1252 " [-o outfile] [infile]\n", cmdname); 1253 f_print(stderr, "\t%s [-s nettype]* [-o outfile] [infile]\n", cmdname); 1254 f_print(stderr, "\t%s [-n netid]* [-o outfile] [infile]\n", cmdname); 1255 options_usage(); 1256 exit(1); 1257} 1258 |
1327static 1328version_info() | 1259static void 1260version_info(void) |
1329{ 1330 f_print(stderr, "%s %d.%d\n", cmdname, RPCGEN_MAJOR, RPCGEN_MINOR); 1331 exit(1); 1332} 1333 | 1261{ 1262 f_print(stderr, "%s %d.%d\n", cmdname, RPCGEN_MAJOR, RPCGEN_MINOR); 1263 exit(1); 1264} 1265 |
1334static 1335options_usage() | 1266static void 1267options_usage(void) |
1336{ 1337 f_print(stderr, "options:\n"); 1338 f_print(stderr, "-a\t\tgenerate all files, including samples\n"); 1339 f_print(stderr, "-A\t\tgenerate code to enable automatic MT mode\n"); 1340 f_print(stderr, "-b\t\tbackward compatibility mode (generates code" 1341 " for SunOS 4.X)\n"); 1342 f_print(stderr, "-c\t\tgenerate XDR routines\n"); 1343 f_print(stderr, "-C\t\tANSI C mode\n"); --- 23 unchanged lines hidden (view full) --- 1367 f_print(stderr, "-Sm \t\tgenerate makefile template \n"); 1368 1369 f_print(stderr, "-t\t\tgenerate RPC dispatch table\n"); 1370 f_print(stderr, "-T\t\tgenerate code to support RPC dispatch tables\n"); 1371 f_print(stderr, "-v\t\tprint version information and exit\n"); 1372 f_print(stderr, "-Y path\t\tpath where cpp is found\n"); 1373 exit(1); 1374} | 1268{ 1269 f_print(stderr, "options:\n"); 1270 f_print(stderr, "-a\t\tgenerate all files, including samples\n"); 1271 f_print(stderr, "-A\t\tgenerate code to enable automatic MT mode\n"); 1272 f_print(stderr, "-b\t\tbackward compatibility mode (generates code" 1273 " for SunOS 4.X)\n"); 1274 f_print(stderr, "-c\t\tgenerate XDR routines\n"); 1275 f_print(stderr, "-C\t\tANSI C mode\n"); --- 23 unchanged lines hidden (view full) --- 1299 f_print(stderr, "-Sm \t\tgenerate makefile template \n"); 1300 1301 f_print(stderr, "-t\t\tgenerate RPC dispatch table\n"); 1302 f_print(stderr, "-T\t\tgenerate code to support RPC dispatch tables\n"); 1303 f_print(stderr, "-v\t\tprint version information and exit\n"); 1304 f_print(stderr, "-Y path\t\tpath where cpp is found\n"); 1305 exit(1); 1306} |
1375 1376 1377char * 1378rindex(sp, c) 1379 register char *sp, c; 1380{ 1381 register char *r; 1382 1383 r = NULL; 1384 do { 1385 if (*sp == c) 1386 r = sp; 1387 } while (*sp++); 1388 return (r); 1389} | |