14e115012SGarrett Wollman /* 24e115012SGarrett Wollman * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 34e115012SGarrett Wollman * unrestricted use provided that this legend is included on all tape 44e115012SGarrett Wollman * media and as a part of the software program in whole or part. Users 54e115012SGarrett Wollman * may copy or modify Sun RPC without charge, but are not authorized 64e115012SGarrett Wollman * to license or distribute it to anyone else except as part of a product or 74e115012SGarrett Wollman * program developed by the user. 84e115012SGarrett Wollman * 94e115012SGarrett Wollman * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 104e115012SGarrett Wollman * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 114e115012SGarrett Wollman * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 124e115012SGarrett Wollman * 134e115012SGarrett Wollman * Sun RPC is provided with no support and without any obligation on the 144e115012SGarrett Wollman * part of Sun Microsystems, Inc. to assist in its use, correction, 154e115012SGarrett Wollman * modification or enhancement. 164e115012SGarrett Wollman * 174e115012SGarrett Wollman * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 184e115012SGarrett Wollman * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 194e115012SGarrett Wollman * OR ANY PART THEREOF. 204e115012SGarrett Wollman * 214e115012SGarrett Wollman * In no event will Sun Microsystems, Inc. be liable for any lost revenue 224e115012SGarrett Wollman * or profits or other special, indirect and consequential damages, even if 234e115012SGarrett Wollman * Sun has been advised of the possibility of such damages. 244e115012SGarrett Wollman * 254e115012SGarrett Wollman * Sun Microsystems, Inc. 264e115012SGarrett Wollman * 2550 Garcia Avenue 274e115012SGarrett Wollman * Mountain View, California 94043 284e115012SGarrett Wollman */ 29ff49530fSBill Paul 30ff49530fSBill Paul 31ff49530fSBill Paul #ident "@(#)rpc_main.c 1.21 94/04/25 SMI" 32ff49530fSBill Paul 334e115012SGarrett Wollman #ifndef lint 340e76f40dSPhilippe Charnier #if 0 35ff49530fSBill Paul static char sccsid[] = "@(#)rpc_main.c 1.30 89/03/30 (C) 1987 SMI"; 364e115012SGarrett Wollman #endif 370e76f40dSPhilippe Charnier static const char rcsid[] = 380e76f40dSPhilippe Charnier "$Id$"; 390e76f40dSPhilippe Charnier #endif 404e115012SGarrett Wollman 414e115012SGarrett Wollman /* 424e115012SGarrett Wollman * rpc_main.c, Top level of the RPC protocol compiler. 434e115012SGarrett Wollman * Copyright (C) 1987, Sun Microsystems, Inc. 444e115012SGarrett Wollman */ 454e115012SGarrett Wollman 460e76f40dSPhilippe Charnier #include <err.h> 470e76f40dSPhilippe Charnier #include <ctype.h> 484e115012SGarrett Wollman #include <stdio.h> 49ff49530fSBill Paul #include <string.h> 50ff49530fSBill Paul #include <unistd.h> 51ff49530fSBill Paul #include <sys/types.h> 52ff49530fSBill Paul #include <sys/param.h> 534e115012SGarrett Wollman #include <sys/file.h> 54ff49530fSBill Paul #include <sys/stat.h> 554e115012SGarrett Wollman #include "rpc_parse.h" 56ff49530fSBill Paul #include "rpc_util.h" 574e115012SGarrett Wollman #include "rpc_scan.h" 584e115012SGarrett Wollman 59ff49530fSBill Paul extern void write_sample_svc __P(( definition * )); 60ff49530fSBill Paul extern int write_sample_clnt __P(( definition * )); 61ff49530fSBill Paul extern void write_sample_clnt_main __P(( void )); 62526195adSJordan K. Hubbard extern void add_sample_msg __P(( void )); 63526195adSJordan K. Hubbard static void c_output __P(( char *, char *, int, char * )); 64526195adSJordan K. Hubbard static void h_output __P(( char *, char *, int, char * )); 65526195adSJordan K. Hubbard static void l_output __P(( char *, char *, int, char * )); 66526195adSJordan K. Hubbard static void t_output __P(( char *, char *, int, char * )); 67526195adSJordan K. Hubbard static void clnt_output __P(( char *, char *, int, char * )); 68526195adSJordan K. Hubbard 69526195adSJordan K. Hubbard void c_initialize __P(( void )); 704e115012SGarrett Wollman 71ff49530fSBill Paul #ifndef __FreeBSD__ 72ff49530fSBill Paul char * rindex(); 73ff49530fSBill Paul #endif 74ff49530fSBill Paul 75526195adSJordan K. Hubbard static void usage __P(( void )); 76526195adSJordan K. Hubbard static void options_usage __P (( void )); 77ff49530fSBill Paul static int do_registers __P(( int, char ** )); 78ff49530fSBill Paul static int parseargs __P(( int, char **, struct commandline * )); 79526195adSJordan K. Hubbard static void svc_output __P(( char *, char *, int, char * )); 80ff49530fSBill Paul static void mkfile_output __P(( struct commandline * )); 81526195adSJordan K. Hubbard static void s_output __P(( int, char **, char *, char *, int, char *, int, int )); 82ff49530fSBill Paul 83ff49530fSBill Paul #define EXTEND 1 /* alias for TRUE */ 84ff49530fSBill Paul #define DONT_EXTEND 0 /* alias for FALSE */ 85ff49530fSBill Paul 86ff49530fSBill Paul #define SVR4_CPP "/usr/ccs/lib/cpp" 87ff49530fSBill Paul #ifdef __FreeBSD__ 88ff49530fSBill Paul #define SUNOS_CPP "/usr/libexec/cpp" 89ff49530fSBill Paul #else 90ff49530fSBill Paul #define SUNOS_CPP "/usr/lib/cpp" 91ff49530fSBill Paul #endif 92ff49530fSBill Paul 93ff49530fSBill Paul static int cppDefined = 0; /* explicit path for C preprocessor */ 94ff49530fSBill Paul 95ff49530fSBill Paul static char *svcclosetime = "120"; 96ff49530fSBill Paul static char *CPP = SVR4_CPP; 974e115012SGarrett Wollman static char CPPFLAGS[] = "-C"; 98ff49530fSBill Paul static char pathbuf[MAXPATHLEN + 1]; 994e115012SGarrett Wollman static char *allv[] = { 1004e115012SGarrett Wollman "rpcgen", "-s", "udp", "-s", "tcp", 1014e115012SGarrett Wollman }; 1024e115012SGarrett Wollman static int allc = sizeof (allv)/sizeof (allv[0]); 103ff49530fSBill Paul static char *allnv[] = { 104ff49530fSBill Paul "rpcgen", "-s", "netpath", 105ff49530fSBill Paul }; 106ff49530fSBill Paul static int allnc = sizeof (allnv)/sizeof (allnv[0]); 107ff49530fSBill Paul 108ff49530fSBill Paul /* 109ff49530fSBill Paul * machinations for handling expanding argument list 110ff49530fSBill Paul */ 111ff49530fSBill Paul static void addarg(); /* add another argument to the list */ 112ff49530fSBill Paul static void putarg(); /* put argument at specified location */ 113ff49530fSBill Paul static void clear_args(); /* clear argument list */ 114ff49530fSBill Paul static void checkfiles(); /* check if out file already exists */ 1154e115012SGarrett Wollman 1164e115012SGarrett Wollman 117ff49530fSBill Paul 118ff49530fSBill Paul #define ARGLISTLEN 20 119ff49530fSBill Paul #define FIXEDARGS 2 120ff49530fSBill Paul 121ff49530fSBill Paul static char *arglist[ARGLISTLEN]; 122ff49530fSBill Paul static int argcount = FIXEDARGS; 123ff49530fSBill Paul 124ff49530fSBill Paul 125ff49530fSBill Paul int nonfatalerrors; /* errors */ 126ff49530fSBill Paul #ifdef __FreeBSD__ 127ff49530fSBill Paul int inetdflag = 0; /* Support for inetd is now the default */ 128ff49530fSBill Paul #else 129ff49530fSBill Paul int inetdflag; /* Support for inetd is now the default */ 130ff49530fSBill Paul #endif 131ff49530fSBill Paul int pmflag; /* Support for port monitors */ 132ff49530fSBill Paul int logflag; /* Use syslog instead of fprintf for errors */ 133ff49530fSBill Paul int tblflag; /* Support for dispatch table file */ 134ff49530fSBill Paul int mtflag = 0; /* Support for MT */ 135ff49530fSBill Paul #ifdef __FreeBSD__ 136ff49530fSBill Paul #define INLINE 0 137ff49530fSBill Paul #else 138ff49530fSBill Paul #define INLINE 5 139ff49530fSBill Paul #endif 140ff49530fSBill Paul /* length at which to start doing an inline */ 141ff49530fSBill Paul 142ff49530fSBill Paul int inline = INLINE; 143ff49530fSBill Paul /* 144ff49530fSBill Paul * Length at which to start doing an inline. INLINE = default 145ff49530fSBill Paul * if 0, no xdr_inline code 146ff49530fSBill Paul */ 147ff49530fSBill Paul 148ff49530fSBill Paul int indefinitewait; /* If started by port monitors, hang till it wants */ 149ff49530fSBill Paul int exitnow; /* If started by port monitors, exit after the call */ 150ff49530fSBill Paul int timerflag; /* TRUE if !indefinite && !exitnow */ 151ff49530fSBill Paul int newstyle; /* newstyle of passing arguments (by value) */ 152ff49530fSBill Paul int Cflag = 0; /* ANSI C syntax */ 153ff49530fSBill Paul int CCflag = 0; /* C++ files */ 154ff49530fSBill Paul static int allfiles; /* generate all files */ 155ff49530fSBill Paul #ifdef __FreeBSD__ 156ff49530fSBill Paul int tirpcflag = 0; /* generating code for tirpc, by default */ 157ff49530fSBill Paul #else 158ff49530fSBill Paul int tirpcflag = 1; /* generating code for tirpc, by default */ 159ff49530fSBill Paul #endif 160ff49530fSBill Paul xdrfunc *xdrfunc_head = NULL; /* xdr function list */ 161ff49530fSBill Paul xdrfunc *xdrfunc_tail = NULL; /* xdr function list */ 162ff49530fSBill Paul pid_t childpid; 163ff49530fSBill Paul 1644e115012SGarrett Wollman 165526195adSJordan K. Hubbard int 1664e115012SGarrett Wollman main(argc, argv) 1674e115012SGarrett Wollman int argc; 1684e115012SGarrett Wollman char *argv[]; 1694e115012SGarrett Wollman { 1704e115012SGarrett Wollman struct commandline cmd; 1714e115012SGarrett Wollman 172ff49530fSBill Paul (void) memset((char *)&cmd, 0, sizeof (struct commandline)); 173ff49530fSBill Paul clear_args(); 174ff49530fSBill Paul if (!parseargs(argc, argv, &cmd)) 175ff49530fSBill Paul usage(); 176ff49530fSBill Paul /* 177ff49530fSBill Paul * Only the client and server side stubs are likely to be customized, 178ff49530fSBill Paul * so in that case only, check if the outfile exists, and if so, 179ff49530fSBill Paul * print an error message and exit. 180ff49530fSBill Paul */ 181ff49530fSBill Paul if (cmd.Ssflag || cmd.Scflag || cmd.makefileflag) { 182ff49530fSBill Paul checkfiles(cmd.infile, cmd.outfile); 1834e115012SGarrett Wollman } 184ff49530fSBill Paul else 185ff49530fSBill Paul checkfiles(cmd.infile, NULL); 186ff49530fSBill Paul 1874e115012SGarrett Wollman if (cmd.cflag) { 188ff49530fSBill Paul c_output(cmd.infile, "-DRPC_XDR", DONT_EXTEND, cmd.outfile); 1894e115012SGarrett Wollman } else if (cmd.hflag) { 190ff49530fSBill Paul h_output(cmd.infile, "-DRPC_HDR", DONT_EXTEND, cmd.outfile); 1914e115012SGarrett Wollman } else if (cmd.lflag) { 192ff49530fSBill Paul l_output(cmd.infile, "-DRPC_CLNT", DONT_EXTEND, cmd.outfile); 193ff49530fSBill Paul } else if (cmd.sflag || cmd.mflag || (cmd.nflag)) { 194ff49530fSBill Paul s_output(argc, argv, cmd.infile, "-DRPC_SVC", DONT_EXTEND, 195ff49530fSBill Paul cmd.outfile, cmd.mflag, cmd.nflag); 196ff49530fSBill Paul } else if (cmd.tflag) { 197ff49530fSBill Paul t_output(cmd.infile, "-DRPC_TBL", DONT_EXTEND, cmd.outfile); 198ff49530fSBill Paul } else if (cmd.Ssflag) { 199ff49530fSBill Paul svc_output(cmd.infile, "-DRPC_SERVER", DONT_EXTEND, 200ff49530fSBill Paul cmd.outfile); 201ff49530fSBill Paul } else if (cmd.Scflag) { 202ff49530fSBill Paul clnt_output(cmd.infile, "-DRPC_CLIENT", DONT_EXTEND, 203ff49530fSBill Paul cmd.outfile); 204ff49530fSBill Paul } else if (cmd.makefileflag) { 205ff49530fSBill Paul mkfile_output(&cmd); 2064e115012SGarrett Wollman } else { 207ff49530fSBill Paul /* the rescans are required, since cpp may effect input */ 2084e115012SGarrett Wollman c_output(cmd.infile, "-DRPC_XDR", EXTEND, "_xdr.c"); 2094e115012SGarrett Wollman reinitialize(); 2104e115012SGarrett Wollman h_output(cmd.infile, "-DRPC_HDR", EXTEND, ".h"); 2114e115012SGarrett Wollman reinitialize(); 2124e115012SGarrett Wollman l_output(cmd.infile, "-DRPC_CLNT", EXTEND, "_clnt.c"); 2134e115012SGarrett Wollman reinitialize(); 214ff49530fSBill Paul if (inetdflag || !tirpcflag) 2154e115012SGarrett Wollman s_output(allc, allv, cmd.infile, "-DRPC_SVC", EXTEND, 216ff49530fSBill Paul "_svc.c", cmd.mflag, cmd.nflag); 217ff49530fSBill Paul else 218ff49530fSBill Paul s_output(allnc, allnv, cmd.infile, "-DRPC_SVC", 219ff49530fSBill Paul EXTEND, "_svc.c", cmd.mflag, cmd.nflag); 220ff49530fSBill Paul if (tblflag) { 221ff49530fSBill Paul reinitialize(); 222ff49530fSBill Paul t_output(cmd.infile, "-DRPC_TBL", EXTEND, "_tbl.i"); 2234e115012SGarrett Wollman } 2244e115012SGarrett Wollman 225ff49530fSBill Paul if (allfiles) { 226ff49530fSBill Paul reinitialize(); 227ff49530fSBill Paul svc_output(cmd.infile, "-DRPC_SERVER", EXTEND, 228ff49530fSBill Paul "_server.c"); 229ff49530fSBill Paul reinitialize(); 230ff49530fSBill Paul clnt_output(cmd.infile, "-DRPC_CLIENT", EXTEND, 231ff49530fSBill Paul "_client.c"); 232ff49530fSBill Paul 233ff49530fSBill Paul } 234ff49530fSBill Paul if (allfiles || (cmd.makefileflag == 1)){ 235ff49530fSBill Paul reinitialize(); 236ff49530fSBill Paul mkfile_output(&cmd); 237ff49530fSBill Paul } 238ff49530fSBill Paul 239ff49530fSBill Paul } 240ff49530fSBill Paul exit(nonfatalerrors); 241ff49530fSBill Paul /* NOTREACHED */ 242ff49530fSBill Paul } 243ff49530fSBill Paul 244ff49530fSBill Paul 2454e115012SGarrett Wollman /* 246ff49530fSBill Paul * add extension to filename 2474e115012SGarrett Wollman */ 2484e115012SGarrett Wollman static char * 249ff49530fSBill Paul #ifdef __FreeBSD__ 2505ec07232SNate Williams extendfile(path, ext) 2515ec07232SNate Williams char *path; 252ff49530fSBill Paul #else 253ff49530fSBill Paul extendfile(file, ext) 254ff49530fSBill Paul char *file; 255ff49530fSBill Paul #endif 2564e115012SGarrett Wollman char *ext; 2574e115012SGarrett Wollman { 2584e115012SGarrett Wollman char *res; 2594e115012SGarrett Wollman char *p; 260ff49530fSBill Paul #ifdef __FreeBSD__ 261ff49530fSBill Paul char *file; 2624e115012SGarrett Wollman 2635ec07232SNate Williams if ((file = rindex(path, '/')) == NULL) 2645ec07232SNate Williams file = path; 2655ec07232SNate Williams else 2665ec07232SNate Williams file++; 267ff49530fSBill Paul #endif 2684e115012SGarrett Wollman res = alloc(strlen(file) + strlen(ext) + 1); 2694e115012SGarrett Wollman if (res == NULL) { 2704e115012SGarrett Wollman abort(); 2714e115012SGarrett Wollman } 272ff49530fSBill Paul p = strrchr(file, '.'); 2734e115012SGarrett Wollman if (p == NULL) { 2744e115012SGarrett Wollman p = file + strlen(file); 2754e115012SGarrett Wollman } 2764e115012SGarrett Wollman (void) strcpy(res, file); 2774e115012SGarrett Wollman (void) strcpy(res + (p - file), ext); 2784e115012SGarrett Wollman return (res); 2794e115012SGarrett Wollman } 2804e115012SGarrett Wollman 2814e115012SGarrett Wollman /* 2824e115012SGarrett Wollman * Open output file with given extension 2834e115012SGarrett Wollman */ 284526195adSJordan K. Hubbard static void 2854e115012SGarrett Wollman open_output(infile, outfile) 2864e115012SGarrett Wollman char *infile; 2874e115012SGarrett Wollman char *outfile; 2884e115012SGarrett Wollman { 289ff49530fSBill Paul 2904e115012SGarrett Wollman if (outfile == NULL) { 2914e115012SGarrett Wollman fout = stdout; 2924e115012SGarrett Wollman return; 2934e115012SGarrett Wollman } 294ff49530fSBill Paul 2954e115012SGarrett Wollman if (infile != NULL && streq(outfile, infile)) { 2960e76f40dSPhilippe Charnier warnx("%s already exists. No output generated", infile); 2974e115012SGarrett Wollman crash(); 2984e115012SGarrett Wollman } 2994e115012SGarrett Wollman fout = fopen(outfile, "w"); 3004e115012SGarrett Wollman if (fout == NULL) { 3010e76f40dSPhilippe Charnier warn("unable to open %s", outfile); 3024e115012SGarrett Wollman crash(); 3034e115012SGarrett Wollman } 3044e115012SGarrett Wollman record_open(outfile); 305ff49530fSBill Paul 306526195adSJordan K. Hubbard return; 307ff49530fSBill Paul } 308ff49530fSBill Paul 309526195adSJordan K. Hubbard static void 310ff49530fSBill Paul add_warning() 311ff49530fSBill Paul { 312ff49530fSBill Paul f_print(fout, "/*\n"); 313ff49530fSBill Paul f_print(fout, " * Please do not edit this file.\n"); 314ff49530fSBill Paul f_print(fout, " * It was generated using rpcgen.\n"); 315ff49530fSBill Paul f_print(fout, " */\n\n"); 316ff49530fSBill Paul } 317ff49530fSBill Paul 318ff49530fSBill Paul /* clear list of arguments */ 319ff49530fSBill Paul static void clear_args() 320ff49530fSBill Paul { 321ff49530fSBill Paul int i; 322ff49530fSBill Paul for (i = FIXEDARGS; i < ARGLISTLEN; i++) 323ff49530fSBill Paul arglist[i] = NULL; 324ff49530fSBill Paul argcount = FIXEDARGS; 325ff49530fSBill Paul } 326ff49530fSBill Paul 327ff49530fSBill Paul /* make sure that a CPP exists */ 328ff49530fSBill Paul static void find_cpp() 329ff49530fSBill Paul { 330ff49530fSBill Paul struct stat buf; 331ff49530fSBill Paul 332ff49530fSBill Paul if (stat(CPP, &buf) < 0) { /* SVR4 or explicit cpp does not exist */ 333ff49530fSBill Paul if (cppDefined) { 3340e76f40dSPhilippe Charnier warnx("cannot find C preprocessor: %s", CPP); 335ff49530fSBill Paul crash(); 336ff49530fSBill Paul } else { /* try the other one */ 337ff49530fSBill Paul CPP = SUNOS_CPP; 338ff49530fSBill Paul if (stat(CPP, &buf) < 0) { /* can't find any cpp */ 3390e76f40dSPhilippe Charnier warnx("cannot find any C preprocessor (cpp)"); 340ff49530fSBill Paul crash(); 341ff49530fSBill Paul } 342ff49530fSBill Paul } 343ff49530fSBill Paul } 3444e115012SGarrett Wollman } 3454e115012SGarrett Wollman 3464e115012SGarrett Wollman /* 3474e115012SGarrett Wollman * Open input file with given define for C-preprocessor 3484e115012SGarrett Wollman */ 349526195adSJordan K. Hubbard static void 3504e115012SGarrett Wollman open_input(infile, define) 3514e115012SGarrett Wollman char *infile; 3524e115012SGarrett Wollman char *define; 3534e115012SGarrett Wollman { 3544e115012SGarrett Wollman int pd[2]; 3554e115012SGarrett Wollman 3564e115012SGarrett Wollman infilename = (infile == NULL) ? "<stdin>" : infile; 3574e115012SGarrett Wollman (void) pipe(pd); 358ff49530fSBill Paul switch (childpid = fork()) { 3594e115012SGarrett Wollman case 0: 360ff49530fSBill Paul find_cpp(); 361ff49530fSBill Paul putarg(0, CPP); 362ff49530fSBill Paul putarg(1, CPPFLAGS); 363ff49530fSBill Paul addarg(define); 364ff49530fSBill Paul if (infile) 365ff49530fSBill Paul addarg(infile); 366ff49530fSBill Paul addarg((char *)NULL); 3674e115012SGarrett Wollman (void) close(1); 3684e115012SGarrett Wollman (void) dup2(pd[1], 1); 3694e115012SGarrett Wollman (void) close(pd[0]); 370ff49530fSBill Paul execv(arglist[0], arglist); 3710e76f40dSPhilippe Charnier warn("execv"); 3724e115012SGarrett Wollman exit(1); 3734e115012SGarrett Wollman case -1: 3740e76f40dSPhilippe Charnier warn("fork"); 3754e115012SGarrett Wollman exit(1); 3764e115012SGarrett Wollman } 3774e115012SGarrett Wollman (void) close(pd[1]); 3784e115012SGarrett Wollman fin = fdopen(pd[0], "r"); 3794e115012SGarrett Wollman if (fin == NULL) { 3800e76f40dSPhilippe Charnier warn("%s", infilename); 3814e115012SGarrett Wollman crash(); 3824e115012SGarrett Wollman } 3834e115012SGarrett Wollman } 3844e115012SGarrett Wollman 385ff49530fSBill Paul /* valid tirpc nettypes */ 386ff49530fSBill Paul static char* valid_ti_nettypes[] = 387ff49530fSBill Paul { 388ff49530fSBill Paul "netpath", 389ff49530fSBill Paul "visible", 390ff49530fSBill Paul "circuit_v", 391ff49530fSBill Paul "datagram_v", 392ff49530fSBill Paul "circuit_n", 393ff49530fSBill Paul "datagram_n", 394ff49530fSBill Paul "udp", 395ff49530fSBill Paul "tcp", 396ff49530fSBill Paul "raw", 397ff49530fSBill Paul NULL 398ff49530fSBill Paul }; 399ff49530fSBill Paul 400ff49530fSBill Paul /* valid inetd nettypes */ 401ff49530fSBill Paul static char* valid_i_nettypes[] = 402ff49530fSBill Paul { 403ff49530fSBill Paul "udp", 404ff49530fSBill Paul "tcp", 405ff49530fSBill Paul NULL 406ff49530fSBill Paul }; 407ff49530fSBill Paul 408ff49530fSBill Paul static int check_nettype(name, list_to_check) 409ff49530fSBill Paul char* name; 410ff49530fSBill Paul char* list_to_check[]; 411ff49530fSBill Paul { 412ff49530fSBill Paul int i; 413ff49530fSBill Paul for (i = 0; list_to_check[i] != NULL; i++) { 414ff49530fSBill Paul if (strcmp(name, list_to_check[i]) == 0) { 415ff49530fSBill Paul return (1); 416ff49530fSBill Paul } 417ff49530fSBill Paul } 4180e76f40dSPhilippe Charnier warnx("illegal nettype :\'%s\'", name); 419ff49530fSBill Paul return (0); 420ff49530fSBill Paul } 421ff49530fSBill Paul 422ff49530fSBill Paul static char * 423ff49530fSBill Paul file_name(file, ext) 424ff49530fSBill Paul char *file; 425ff49530fSBill Paul char *ext; 426ff49530fSBill Paul { 427ff49530fSBill Paul char *temp; 428ff49530fSBill Paul temp = extendfile(file, ext); 429ff49530fSBill Paul 430ff49530fSBill Paul if (access(temp, F_OK) != -1) 431ff49530fSBill Paul return (temp); 432ff49530fSBill Paul else 433ff49530fSBill Paul return ((char *)" "); 434ff49530fSBill Paul 435ff49530fSBill Paul } 436ff49530fSBill Paul 437ff49530fSBill Paul 438526195adSJordan K. Hubbard static void 4394e115012SGarrett Wollman c_output(infile, define, extend, outfile) 4404e115012SGarrett Wollman char *infile; 4414e115012SGarrett Wollman char *define; 4424e115012SGarrett Wollman int extend; 4434e115012SGarrett Wollman char *outfile; 4444e115012SGarrett Wollman { 4454e115012SGarrett Wollman definition *def; 4464e115012SGarrett Wollman char *include; 4474e115012SGarrett Wollman char *outfilename; 4484e115012SGarrett Wollman long tell; 4494e115012SGarrett Wollman 450ff49530fSBill Paul c_initialize(); 4514e115012SGarrett Wollman open_input(infile, define); 4524e115012SGarrett Wollman outfilename = extend ? extendfile(infile, outfile) : outfile; 4534e115012SGarrett Wollman open_output(infile, outfilename); 454ff49530fSBill Paul add_warning(); 4554e115012SGarrett Wollman if (infile && (include = extendfile(infile, ".h"))) { 4564e115012SGarrett Wollman f_print(fout, "#include \"%s\"\n", include); 4574e115012SGarrett Wollman free(include); 458ff49530fSBill Paul /* .h file already contains rpc/rpc.h */ 459ff49530fSBill Paul } else 460ff49530fSBill Paul f_print(fout, "#include <rpc/rpc.h>\n"); 4614e115012SGarrett Wollman tell = ftell(fout); 462526195adSJordan K. Hubbard while ( (def = get_definition()) ) { 4634e115012SGarrett Wollman emit(def); 4644e115012SGarrett Wollman } 4654e115012SGarrett Wollman if (extend && tell == ftell(fout)) { 4664e115012SGarrett Wollman (void) unlink(outfilename); 4674e115012SGarrett Wollman } 4684e115012SGarrett Wollman } 4694e115012SGarrett Wollman 470ff49530fSBill Paul 471526195adSJordan K. Hubbard void 472ff49530fSBill Paul c_initialize() 473ff49530fSBill Paul { 474ff49530fSBill Paul 475ff49530fSBill Paul /* add all the starting basic types */ 476ff49530fSBill Paul add_type(1, "int"); 477ff49530fSBill Paul add_type(1, "long"); 478ff49530fSBill Paul add_type(1, "short"); 479ff49530fSBill Paul add_type(1, "bool"); 480ff49530fSBill Paul add_type(1, "u_int"); 481ff49530fSBill Paul add_type(1, "u_long"); 482ff49530fSBill Paul add_type(1, "u_short"); 483ff49530fSBill Paul 484ff49530fSBill Paul } 485ff49530fSBill Paul 486ff49530fSBill Paul char rpcgen_table_dcl[] = "struct rpcgen_table {\n\ 487ff49530fSBill Paul char *(*proc)(); \n\ 488ff49530fSBill Paul xdrproc_t xdr_arg; \n\ 489ff49530fSBill Paul unsigned len_arg; \n\ 490ff49530fSBill Paul xdrproc_t xdr_res; \n\ 491ff49530fSBill Paul unsigned len_res; \n\ 492ff49530fSBill Paul }; \n"; 493ff49530fSBill Paul 494ff49530fSBill Paul 495ff49530fSBill Paul char *generate_guard(pathname) 496ff49530fSBill Paul char* pathname; 497ff49530fSBill Paul { 498ff49530fSBill Paul char* filename, *guard, *tmp; 499ff49530fSBill Paul 500ff49530fSBill Paul filename = strrchr(pathname, '/'); /* find last component */ 501ff49530fSBill Paul filename = ((filename == 0) ? pathname : filename+1); 502ff49530fSBill Paul guard = strdup(filename); 503ff49530fSBill Paul /* convert to upper case */ 504ff49530fSBill Paul tmp = guard; 505ff49530fSBill Paul while (*tmp) { 506ff49530fSBill Paul if (islower(*tmp)) 507ff49530fSBill Paul *tmp = toupper(*tmp); 508ff49530fSBill Paul tmp++; 509ff49530fSBill Paul } 510ff49530fSBill Paul guard = extendfile(guard, "_H_RPCGEN"); 511ff49530fSBill Paul return (guard); 512ff49530fSBill Paul } 513ff49530fSBill Paul 5144e115012SGarrett Wollman /* 5154e115012SGarrett Wollman * Compile into an XDR header file 5164e115012SGarrett Wollman */ 517ff49530fSBill Paul 518ff49530fSBill Paul 519526195adSJordan K. Hubbard static void 5204e115012SGarrett Wollman h_output(infile, define, extend, outfile) 5214e115012SGarrett Wollman char *infile; 5224e115012SGarrett Wollman char *define; 5234e115012SGarrett Wollman int extend; 5244e115012SGarrett Wollman char *outfile; 5254e115012SGarrett Wollman { 5264e115012SGarrett Wollman definition *def; 5274e115012SGarrett Wollman char *outfilename; 5284e115012SGarrett Wollman long tell; 529ff49530fSBill Paul char *guard; 530ff49530fSBill Paul list *l; 531ff49530fSBill Paul xdrfunc *xdrfuncp; 532ff49530fSBill Paul int i; 5334e115012SGarrett Wollman 5344e115012SGarrett Wollman open_input(infile, define); 5354e115012SGarrett Wollman outfilename = extend ? extendfile(infile, outfile) : outfile; 5364e115012SGarrett Wollman open_output(infile, outfilename); 537ff49530fSBill Paul add_warning(); 538ff49530fSBill Paul if (outfilename || infile){ 539ff49530fSBill Paul guard = generate_guard(outfilename ? outfilename: infile); 540ff49530fSBill Paul } else 541ff49530fSBill Paul guard = "STDIN_"; 542ff49530fSBill Paul 543ff49530fSBill Paul f_print(fout, "#ifndef _%s\n#define _%s\n\n", guard, 544ff49530fSBill Paul guard); 545ff49530fSBill Paul 546ff49530fSBill Paul f_print(fout, "#include <rpc/rpc.h>\n"); 547ff49530fSBill Paul 548ff49530fSBill Paul if (mtflag) { 549ff49530fSBill Paul f_print(fout, "#include <synch.h>\n"); 550ff49530fSBill Paul f_print(fout, "#include <thread.h>\n"); 551ff49530fSBill Paul }; 552ff49530fSBill Paul 553ff49530fSBill Paul /* put the C++ support */ 554ff49530fSBill Paul if (Cflag && !CCflag){ 555ff49530fSBill Paul f_print(fout, "\n#ifdef __cplusplus\n"); 556ff49530fSBill Paul f_print(fout, "extern \"C\" {\n"); 557ff49530fSBill Paul f_print(fout, "#endif\n\n"); 558ff49530fSBill Paul } 559ff49530fSBill Paul 560ff49530fSBill Paul /* put in a typedef for quadprecision. Only with Cflag */ 561ff49530fSBill Paul 5624e115012SGarrett Wollman tell = ftell(fout); 563ff49530fSBill Paul 564ff49530fSBill Paul /* print data definitions */ 565526195adSJordan K. Hubbard while ( (def = get_definition()) ) { 5664e115012SGarrett Wollman print_datadef(def); 5674e115012SGarrett Wollman } 568ff49530fSBill Paul 569ff49530fSBill Paul /* 570ff49530fSBill Paul * print function declarations. 571ff49530fSBill Paul * Do this after data definitions because they might be used as 572ff49530fSBill Paul * arguments for functions 573ff49530fSBill Paul */ 574ff49530fSBill Paul for (l = defined; l != NULL; l = l->next) { 575ff49530fSBill Paul print_funcdef(l->val); 576ff49530fSBill Paul } 577ff49530fSBill Paul /* Now print all xdr func declarations */ 578ff49530fSBill Paul if (xdrfunc_head != NULL){ 579ff49530fSBill Paul 580ff49530fSBill Paul f_print(fout, 581ff49530fSBill Paul "\n/* the xdr functions */\n"); 582ff49530fSBill Paul 583ff49530fSBill Paul if (CCflag){ 584ff49530fSBill Paul f_print(fout, "\n#ifdef __cplusplus\n"); 585ff49530fSBill Paul f_print(fout, "extern \"C\" {\n"); 586ff49530fSBill Paul f_print(fout, "#endif\n"); 587ff49530fSBill Paul } 588ff49530fSBill Paul 589ff49530fSBill Paul if (!Cflag){ 590ff49530fSBill Paul xdrfuncp = xdrfunc_head; 591ff49530fSBill Paul while (xdrfuncp != NULL){ 592ff49530fSBill Paul print_xdr_func_def(xdrfuncp->name, 593ff49530fSBill Paul xdrfuncp->pointerp, 2); 594ff49530fSBill Paul xdrfuncp = xdrfuncp->next; 595ff49530fSBill Paul } 596ff49530fSBill Paul } else { 597ff49530fSBill Paul 598ff49530fSBill Paul for (i = 1; i < 3; i++){ 599ff49530fSBill Paul if (i == 1) 600ff49530fSBill Paul f_print(fout, "\n#if defined(__STDC__) || defined(__cplusplus)\n"); 601ff49530fSBill Paul 602ff49530fSBill Paul else 603ff49530fSBill Paul f_print(fout, "\n#else /* K&R C */\n"); 604ff49530fSBill Paul 605ff49530fSBill Paul xdrfuncp = xdrfunc_head; 606ff49530fSBill Paul while (xdrfuncp != NULL){ 607ff49530fSBill Paul print_xdr_func_def(xdrfuncp->name, 608ff49530fSBill Paul xdrfuncp->pointerp, i); 609ff49530fSBill Paul xdrfuncp = xdrfuncp->next; 610ff49530fSBill Paul } 611ff49530fSBill Paul } 612ff49530fSBill Paul f_print(fout, "\n#endif /* K&R C */\n"); 613ff49530fSBill Paul } 614ff49530fSBill Paul } 615ff49530fSBill Paul 6164e115012SGarrett Wollman if (extend && tell == ftell(fout)) { 6174e115012SGarrett Wollman (void) unlink(outfilename); 618ff49530fSBill Paul } else if (tblflag) { 619ff49530fSBill Paul f_print(fout, rpcgen_table_dcl); 6204e115012SGarrett Wollman } 621ff49530fSBill Paul 622ff49530fSBill Paul if (Cflag){ 623ff49530fSBill Paul f_print(fout, "\n#ifdef __cplusplus\n"); 624ff49530fSBill Paul f_print(fout, "}\n"); 625ff49530fSBill Paul f_print(fout, "#endif\n"); 626ff49530fSBill Paul } 627ff49530fSBill Paul 628ff49530fSBill Paul f_print(fout, "\n#endif /* !_%s */\n", guard); 6294e115012SGarrett Wollman } 6304e115012SGarrett Wollman 6314e115012SGarrett Wollman /* 6324e115012SGarrett Wollman * Compile into an RPC service 6334e115012SGarrett Wollman */ 634526195adSJordan K. Hubbard static void 635ff49530fSBill Paul s_output(argc, argv, infile, define, extend, outfile, nomain, netflag) 6364e115012SGarrett Wollman int argc; 6374e115012SGarrett Wollman char *argv[]; 6384e115012SGarrett Wollman char *infile; 6394e115012SGarrett Wollman char *define; 6404e115012SGarrett Wollman int extend; 6414e115012SGarrett Wollman char *outfile; 6424e115012SGarrett Wollman int nomain; 643ff49530fSBill Paul int netflag; 6444e115012SGarrett Wollman { 6454e115012SGarrett Wollman char *include; 6464e115012SGarrett Wollman definition *def; 647ff49530fSBill Paul int foundprogram = 0; 6484e115012SGarrett Wollman char *outfilename; 6494e115012SGarrett Wollman 6504e115012SGarrett Wollman open_input(infile, define); 6514e115012SGarrett Wollman outfilename = extend ? extendfile(infile, outfile) : outfile; 6524e115012SGarrett Wollman open_output(infile, outfilename); 653ff49530fSBill Paul add_warning(); 6544e115012SGarrett Wollman if (infile && (include = extendfile(infile, ".h"))) { 6554e115012SGarrett Wollman f_print(fout, "#include \"%s\"\n", include); 6564e115012SGarrett Wollman free(include); 657ff49530fSBill Paul } else 658ff49530fSBill Paul f_print(fout, "#include <rpc/rpc.h>\n"); 659ff49530fSBill Paul 660ff49530fSBill Paul f_print(fout, "#include <stdio.h>\n"); 661ff49530fSBill Paul f_print(fout, "#include <stdlib.h> /* getenv, exit */\n"); 662ff49530fSBill Paul if (Cflag) { 663ff49530fSBill Paul f_print (fout, 664ff49530fSBill Paul "#include <rpc/pmap_clnt.h> /* for pmap_unset */\n"); 665ff49530fSBill Paul f_print (fout, "#include <string.h> /* strcmp */\n"); 6664e115012SGarrett Wollman } 667ff49530fSBill Paul if (strcmp(svcclosetime, "-1") == 0) 668ff49530fSBill Paul indefinitewait = 1; 669ff49530fSBill Paul else if (strcmp(svcclosetime, "0") == 0) 670ff49530fSBill Paul exitnow = 1; 671ff49530fSBill Paul else if (inetdflag || pmflag) { 672ff49530fSBill Paul f_print(fout, "#include <signal.h>\n"); 673ff49530fSBill Paul timerflag = 1; 674ff49530fSBill Paul } 675ff49530fSBill Paul 676ff49530fSBill Paul if (!tirpcflag && inetdflag) 677ff49530fSBill Paul f_print(fout, "#include <sys/ttycom.h> /* TIOCNOTTY */\n"); 678ff49530fSBill Paul if (Cflag && (inetdflag || pmflag)) { 679ff49530fSBill Paul f_print(fout, "#ifdef __cplusplus\n"); 680ff49530fSBill Paul f_print(fout, 681ff49530fSBill Paul "#include <sysent.h> /* getdtablesize, open */\n"); 682ff49530fSBill Paul f_print(fout, "#endif /* __cplusplus */\n"); 683ff49530fSBill Paul if (tirpcflag) 684ff49530fSBill Paul f_print(fout, "#include <unistd.h> /* setsid */\n"); 685ff49530fSBill Paul } 686ff49530fSBill Paul if (tirpcflag) 687ff49530fSBill Paul f_print(fout, "#include <sys/types.h>\n"); 688ff49530fSBill Paul 689ff49530fSBill Paul f_print(fout, "#include <memory.h>\n"); 690ff49530fSBill Paul #ifdef __FreeBSD__ 691ff49530fSBill Paul if (tirpcflag) 692ff49530fSBill Paul #endif 693ff49530fSBill Paul f_print(fout, "#include <stropts.h>\n"); 694ff49530fSBill Paul if (inetdflag || !tirpcflag) { 695ff49530fSBill Paul f_print(fout, "#include <sys/socket.h>\n"); 696ff49530fSBill Paul f_print(fout, "#include <netinet/in.h>\n"); 697ff49530fSBill Paul } 698ff49530fSBill Paul 699ff49530fSBill Paul if ((netflag || pmflag) && tirpcflag && !nomain) { 700ff49530fSBill Paul f_print(fout, "#include <netconfig.h>\n"); 701ff49530fSBill Paul } 702ff49530fSBill Paul if (tirpcflag) 703ff49530fSBill Paul f_print(fout, "#include <sys/resource.h> /* rlimit */\n"); 704ff49530fSBill Paul if (logflag || inetdflag || pmflag) 705ff49530fSBill Paul f_print(fout, "#include <syslog.h>\n"); 706ff49530fSBill Paul 707ff49530fSBill Paul /* for ANSI-C */ 708ff49530fSBill Paul if (Cflag) 709ff49530fSBill Paul f_print(fout, 710ff49530fSBill Paul "\n#ifndef SIG_PF\n#define SIG_PF void(*)\ 711ff49530fSBill Paul (int)\n#endif\n"); 712ff49530fSBill Paul 713ff49530fSBill Paul f_print(fout, "\n#ifdef DEBUG\n#define RPC_SVC_FG\n#endif\n"); 714ff49530fSBill Paul if (timerflag) 715ff49530fSBill Paul f_print(fout, "\n#define _RPCSVC_CLOSEDOWN %s\n", 716ff49530fSBill Paul svcclosetime); 717526195adSJordan K. Hubbard while ( (def = get_definition()) ) { 7184e115012SGarrett Wollman foundprogram |= (def->def_kind == DEF_PROGRAM); 7194e115012SGarrett Wollman } 7204e115012SGarrett Wollman if (extend && !foundprogram) { 7214e115012SGarrett Wollman (void) unlink(outfilename); 7224e115012SGarrett Wollman return; 7234e115012SGarrett Wollman } 724ff49530fSBill Paul write_most(infile, netflag, nomain); 725ff49530fSBill Paul if (!nomain) { 726ff49530fSBill Paul if (!do_registers(argc, argv)) { 727ff49530fSBill Paul if (outfilename) 728ff49530fSBill Paul (void) unlink(outfilename); 729ff49530fSBill Paul usage(); 730ff49530fSBill Paul } 7314e115012SGarrett Wollman write_rest(); 7324e115012SGarrett Wollman } 7334e115012SGarrett Wollman } 7344e115012SGarrett Wollman 735ff49530fSBill Paul /* 736ff49530fSBill Paul * generate client side stubs 737ff49530fSBill Paul */ 738526195adSJordan K. Hubbard static void 7394e115012SGarrett Wollman l_output(infile, define, extend, outfile) 7404e115012SGarrett Wollman char *infile; 7414e115012SGarrett Wollman char *define; 7424e115012SGarrett Wollman int extend; 7434e115012SGarrett Wollman char *outfile; 7444e115012SGarrett Wollman { 7454e115012SGarrett Wollman char *include; 7464e115012SGarrett Wollman definition *def; 747ff49530fSBill Paul int foundprogram = 0; 7484e115012SGarrett Wollman char *outfilename; 7494e115012SGarrett Wollman 7504e115012SGarrett Wollman open_input(infile, define); 7514e115012SGarrett Wollman outfilename = extend ? extendfile(infile, outfile) : outfile; 7524e115012SGarrett Wollman open_output(infile, outfilename); 753ff49530fSBill Paul add_warning(); 754ff49530fSBill Paul if (Cflag) 755ff49530fSBill Paul f_print (fout, "#include <memory.h> /* for memset */\n"); 7564e115012SGarrett Wollman if (infile && (include = extendfile(infile, ".h"))) { 7574e115012SGarrett Wollman f_print(fout, "#include \"%s\"\n", include); 7584e115012SGarrett Wollman free(include); 759ff49530fSBill Paul } else 760ff49530fSBill Paul f_print(fout, "#include <rpc/rpc.h>\n"); 761526195adSJordan K. Hubbard while ( (def = get_definition()) ) { 7624e115012SGarrett Wollman foundprogram |= (def->def_kind == DEF_PROGRAM); 7634e115012SGarrett Wollman } 7644e115012SGarrett Wollman if (extend && !foundprogram) { 7654e115012SGarrett Wollman (void) unlink(outfilename); 7664e115012SGarrett Wollman return; 7674e115012SGarrett Wollman } 7684e115012SGarrett Wollman write_stubs(); 7694e115012SGarrett Wollman } 7704e115012SGarrett Wollman 7714e115012SGarrett Wollman /* 772ff49530fSBill Paul * generate the dispatch table 7734e115012SGarrett Wollman */ 774526195adSJordan K. Hubbard static void 775ff49530fSBill Paul t_output(infile, define, extend, outfile) 776ff49530fSBill Paul char *infile; 777ff49530fSBill Paul char *define; 778ff49530fSBill Paul int extend; 779ff49530fSBill Paul char *outfile; 780ff49530fSBill Paul { 781ff49530fSBill Paul definition *def; 782ff49530fSBill Paul int foundprogram = 0; 783ff49530fSBill Paul char *outfilename; 784ff49530fSBill Paul 785ff49530fSBill Paul open_input(infile, define); 786ff49530fSBill Paul outfilename = extend ? extendfile(infile, outfile) : outfile; 787ff49530fSBill Paul open_output(infile, outfilename); 788ff49530fSBill Paul add_warning(); 789526195adSJordan K. Hubbard while ( (def = get_definition()) ) { 790ff49530fSBill Paul foundprogram |= (def->def_kind == DEF_PROGRAM); 791ff49530fSBill Paul } 792ff49530fSBill Paul if (extend && !foundprogram) { 793ff49530fSBill Paul (void) unlink(outfilename); 794ff49530fSBill Paul return; 795ff49530fSBill Paul } 796ff49530fSBill Paul write_tables(); 797ff49530fSBill Paul } 798ff49530fSBill Paul 799ff49530fSBill Paul /* sample routine for the server template */ 800526195adSJordan K. Hubbard static void 801ff49530fSBill Paul svc_output(infile, define, extend, outfile) 802ff49530fSBill Paul char *infile; 803ff49530fSBill Paul char *define; 804ff49530fSBill Paul int extend; 805ff49530fSBill Paul char *outfile; 806ff49530fSBill Paul { 807ff49530fSBill Paul definition *def; 808ff49530fSBill Paul char *include; 809ff49530fSBill Paul char *outfilename; 810ff49530fSBill Paul long tell; 811ff49530fSBill Paul open_input(infile, define); 812ff49530fSBill Paul outfilename = extend ? extendfile(infile, outfile) : outfile; 813ff49530fSBill Paul checkfiles(infile, outfilename); 814ff49530fSBill Paul /* 815ff49530fSBill Paul * Check if outfile already exists. 816ff49530fSBill Paul * if so, print an error message and exit 817ff49530fSBill Paul */ 818ff49530fSBill Paul open_output(infile, outfilename); 819ff49530fSBill Paul add_sample_msg(); 820ff49530fSBill Paul 821ff49530fSBill Paul if (infile && (include = extendfile(infile, ".h"))) { 822ff49530fSBill Paul f_print(fout, "#include \"%s\"\n", include); 823ff49530fSBill Paul free(include); 824ff49530fSBill Paul } else 825ff49530fSBill Paul f_print(fout, "#include <rpc/rpc.h>\n"); 826ff49530fSBill Paul 827ff49530fSBill Paul tell = ftell(fout); 828526195adSJordan K. Hubbard while ( (def = get_definition()) ) { 829ff49530fSBill Paul write_sample_svc(def); 830ff49530fSBill Paul } 831ff49530fSBill Paul if (extend && tell == ftell(fout)) { 832ff49530fSBill Paul (void) unlink(outfilename); 833ff49530fSBill Paul } 834ff49530fSBill Paul } 835ff49530fSBill Paul 836ff49530fSBill Paul /* sample main routine for client */ 837526195adSJordan K. Hubbard static void 838ff49530fSBill Paul clnt_output(infile, define, extend, outfile) 839ff49530fSBill Paul char *infile; 840ff49530fSBill Paul char *define; 841ff49530fSBill Paul int extend; 842ff49530fSBill Paul char *outfile; 843ff49530fSBill Paul { 844ff49530fSBill Paul definition *def; 845ff49530fSBill Paul char *include; 846ff49530fSBill Paul char *outfilename; 847ff49530fSBill Paul long tell; 848ff49530fSBill Paul int has_program = 0; 849ff49530fSBill Paul 850ff49530fSBill Paul open_input(infile, define); 851ff49530fSBill Paul outfilename = extend ? extendfile(infile, outfile) : outfile; 852ff49530fSBill Paul checkfiles(infile, outfilename); 853ff49530fSBill Paul /* 854ff49530fSBill Paul * Check if outfile already exists. 855ff49530fSBill Paul * if so, print an error message and exit 856ff49530fSBill Paul */ 857ff49530fSBill Paul 858ff49530fSBill Paul open_output(infile, outfilename); 859ff49530fSBill Paul add_sample_msg(); 860ff49530fSBill Paul if (infile && (include = extendfile(infile, ".h"))) { 861ff49530fSBill Paul f_print(fout, "#include \"%s\"\n", include); 862ff49530fSBill Paul free(include); 863ff49530fSBill Paul } else 864ff49530fSBill Paul f_print(fout, "#include <rpc/rpc.h>\n"); 865ff49530fSBill Paul tell = ftell(fout); 866526195adSJordan K. Hubbard while ( (def = get_definition()) ) { 867ff49530fSBill Paul has_program += write_sample_clnt(def); 868ff49530fSBill Paul } 869ff49530fSBill Paul 870ff49530fSBill Paul if (has_program) 871ff49530fSBill Paul write_sample_clnt_main(); 872ff49530fSBill Paul 873ff49530fSBill Paul if (extend && tell == ftell(fout)) { 874ff49530fSBill Paul (void) unlink(outfilename); 875ff49530fSBill Paul } 876ff49530fSBill Paul } 877ff49530fSBill Paul 878ff49530fSBill Paul 879ff49530fSBill Paul static void mkfile_output(cmd) 880ff49530fSBill Paul struct commandline *cmd; 881ff49530fSBill Paul { 882ff49530fSBill Paul char *mkfilename, *clientname, *clntname, *xdrname, *hdrname; 883ff49530fSBill Paul char *servername, *svcname, *servprogname, *clntprogname; 884ff49530fSBill Paul char *temp; 885ff49530fSBill Paul 886ff49530fSBill Paul svcname = file_name(cmd->infile, "_svc.c"); 887ff49530fSBill Paul clntname = file_name(cmd->infile, "_clnt.c"); 888ff49530fSBill Paul xdrname = file_name(cmd->infile, "_xdr.c"); 889ff49530fSBill Paul hdrname = file_name(cmd->infile, ".h"); 890ff49530fSBill Paul 891ff49530fSBill Paul 892ff49530fSBill Paul if (allfiles){ 893ff49530fSBill Paul servername = extendfile(cmd->infile, "_server.c"); 894ff49530fSBill Paul clientname = extendfile(cmd->infile, "_client.c"); 895ff49530fSBill Paul }else{ 896ff49530fSBill Paul servername = " "; 897ff49530fSBill Paul clientname = " "; 898ff49530fSBill Paul } 899ff49530fSBill Paul servprogname = extendfile(cmd->infile, "_server"); 900ff49530fSBill Paul clntprogname = extendfile(cmd->infile, "_client"); 901ff49530fSBill Paul 902ff49530fSBill Paul if (allfiles){ 903ff49530fSBill Paul mkfilename = alloc(strlen("makefile.") + 904ff49530fSBill Paul strlen(cmd->infile) + 1); 905ff49530fSBill Paul temp = (char *)rindex(cmd->infile, '.'); 906ff49530fSBill Paul strcat(mkfilename, "makefile."); 907ff49530fSBill Paul (void) strncat(mkfilename, cmd->infile, 908ff49530fSBill Paul (temp - cmd->infile)); 909ff49530fSBill Paul } else 910ff49530fSBill Paul mkfilename = cmd->outfile; 911ff49530fSBill Paul 912ff49530fSBill Paul 913ff49530fSBill Paul checkfiles(NULL, mkfilename); 914ff49530fSBill Paul open_output(NULL, mkfilename); 915ff49530fSBill Paul 916ff49530fSBill Paul f_print(fout, "\n# This is a template makefile generated\ 917ff49530fSBill Paul by rpcgen \n"); 918ff49530fSBill Paul 919ff49530fSBill Paul f_print(fout, "\n# Parameters \n\n"); 920ff49530fSBill Paul 921ff49530fSBill Paul f_print(fout, "CLIENT = %s\nSERVER = %s\n\n", 922ff49530fSBill Paul clntprogname, servprogname); 923ff49530fSBill Paul f_print(fout, "SOURCES_CLNT.c = \nSOURCES_CLNT.h = \n"); 924ff49530fSBill Paul f_print(fout, "SOURCES_SVC.c = \nSOURCES_SVC.h = \n"); 925ff49530fSBill Paul f_print(fout, "SOURCES.x = %s\n\n", cmd->infile); 926ff49530fSBill Paul f_print(fout, "TARGETS_SVC.c = %s %s %s \n", 927ff49530fSBill Paul svcname, servername, xdrname); 928ff49530fSBill Paul f_print(fout, "TARGETS_CLNT.c = %s %s %s \n", 929ff49530fSBill Paul clntname, clientname, xdrname); 930ff49530fSBill Paul f_print(fout, "TARGETS = %s %s %s %s %s %s\n\n", 931ff49530fSBill Paul hdrname, xdrname, clntname, 932ff49530fSBill Paul svcname, clientname, servername); 933ff49530fSBill Paul 934ff49530fSBill Paul f_print(fout, "OBJECTS_CLNT = $(SOURCES_CLNT.c:%%.c=%%.o) \ 935ff49530fSBill Paul $(TARGETS_CLNT.c:%%.c=%%.o) "); 936ff49530fSBill Paul 937ff49530fSBill Paul f_print(fout, "\nOBJECTS_SVC = $(SOURCES_SVC.c:%%.c=%%.o) \ 938ff49530fSBill Paul $(TARGETS_SVC.c:%%.c=%%.o) "); 939ff49530fSBill Paul 940ff49530fSBill Paul 941ff49530fSBill Paul f_print(fout, "\n# Compiler flags \n"); 942ff49530fSBill Paul if (mtflag) 943ff49530fSBill Paul f_print(fout, "\nCPPFLAGS += -D_REENTRANT\nCFLAGS += -g \nLDLIBS += -lnsl -lthread\n"); 944ff49530fSBill Paul else 945ff49530fSBill Paul #ifdef __FreeBSD__ 946ff49530fSBill Paul f_print(fout, "\nCFLAGS += -g \nLDLIBS +=\n"); 947ff49530fSBill Paul #else 948ff49530fSBill Paul f_print(fout, "\nCFLAGS += -g \nLDLIBS += -lnsl\n"); 949ff49530fSBill Paul #endif 950ff49530fSBill Paul f_print(fout, "RPCGENFLAGS = \n"); 951ff49530fSBill Paul 952ff49530fSBill Paul f_print(fout, "\n# Targets \n\n"); 953ff49530fSBill Paul 954ff49530fSBill Paul f_print(fout, "all : $(CLIENT) $(SERVER)\n\n"); 955ff49530fSBill Paul f_print(fout, "$(TARGETS) : $(SOURCES.x) \n"); 956ff49530fSBill Paul f_print(fout, "\trpcgen $(RPCGENFLAGS) $(SOURCES.x)\n\n"); 957ff49530fSBill Paul f_print(fout, "$(OBJECTS_CLNT) : $(SOURCES_CLNT.c) $(SOURCES_CLNT.h) \ 958ff49530fSBill Paul $(TARGETS_CLNT.c) \n\n"); 959ff49530fSBill Paul 960ff49530fSBill Paul f_print(fout, "$(OBJECTS_SVC) : $(SOURCES_SVC.c) $(SOURCES_SVC.h) \ 961ff49530fSBill Paul $(TARGETS_SVC.c) \n\n"); 962ff49530fSBill Paul f_print(fout, "$(CLIENT) : $(OBJECTS_CLNT) \n"); 963ff49530fSBill Paul #ifdef __FreeBSD__ 964ff49530fSBill Paul f_print(fout, "\t$(CC) -o $(CLIENT) $(OBJECTS_CLNT) \ 965ff49530fSBill Paul $(LDLIBS) \n\n"); 966ff49530fSBill Paul #else 967ff49530fSBill Paul f_print(fout, "\t$(LINK.c) -o $(CLIENT) $(OBJECTS_CLNT) \ 968ff49530fSBill Paul $(LDLIBS) \n\n"); 969ff49530fSBill Paul #endif 970ff49530fSBill Paul f_print(fout, "$(SERVER) : $(OBJECTS_SVC) \n"); 971ff49530fSBill Paul #ifdef __FreeBSD__ 972ff49530fSBill Paul f_print(fout, "\t$(CC) -o $(SERVER) $(OBJECTS_SVC) $(LDLIBS)\n\n "); 973ff49530fSBill Paul f_print(fout, "clean:\n\t $(RM) -f core $(TARGETS) $(OBJECTS_CLNT) \ 974ff49530fSBill Paul $(OBJECTS_SVC) $(CLIENT) $(SERVER)\n\n"); 975ff49530fSBill Paul #else 976ff49530fSBill Paul f_print(fout, "\t$(LINK.c) -o $(SERVER) $(OBJECTS_SVC) $(LDLIBS)\n\n "); 977ff49530fSBill Paul f_print(fout, "clean:\n\t $(RM) core $(TARGETS) $(OBJECTS_CLNT) \ 978ff49530fSBill Paul $(OBJECTS_SVC) $(CLIENT) $(SERVER)\n\n"); 979ff49530fSBill Paul #endif 980ff49530fSBill Paul } 981ff49530fSBill Paul 982ff49530fSBill Paul 983ff49530fSBill Paul 984ff49530fSBill Paul /* 985ff49530fSBill Paul * Perform registrations for service output 986ff49530fSBill Paul * Return 0 if failed; 1 otherwise. 987ff49530fSBill Paul */ 988526195adSJordan K. Hubbard static int 989526195adSJordan K. Hubbard do_registers(argc, argv) 9904e115012SGarrett Wollman int argc; 9914e115012SGarrett Wollman char *argv[]; 9924e115012SGarrett Wollman { 9934e115012SGarrett Wollman int i; 9944e115012SGarrett Wollman 995ff49530fSBill Paul if (inetdflag || !tirpcflag) { 9964e115012SGarrett Wollman for (i = 1; i < argc; i++) { 9974e115012SGarrett Wollman if (streq(argv[i], "-s")) { 998ff49530fSBill Paul if (!check_nettype(argv[i + 1], 999ff49530fSBill Paul valid_i_nettypes)) 1000ff49530fSBill Paul return (0); 1001ff49530fSBill Paul write_inetd_register(argv[i + 1]); 10024e115012SGarrett Wollman i++; 10034e115012SGarrett Wollman } 10044e115012SGarrett Wollman } 1005ff49530fSBill Paul } else { 1006ff49530fSBill Paul for (i = 1; i < argc; i++) 1007ff49530fSBill Paul if (streq(argv[i], "-s")) { 1008ff49530fSBill Paul if (!check_nettype(argv[i + 1], 1009ff49530fSBill Paul valid_ti_nettypes)) 1010ff49530fSBill Paul return (0); 1011ff49530fSBill Paul write_nettype_register(argv[i + 1]); 1012ff49530fSBill Paul i++; 1013ff49530fSBill Paul } else if (streq(argv[i], "-n")) { 1014ff49530fSBill Paul write_netid_register(argv[i + 1]); 1015ff49530fSBill Paul i++; 1016ff49530fSBill Paul } 1017ff49530fSBill Paul } 1018ff49530fSBill Paul return (1); 1019ff49530fSBill Paul } 1020ff49530fSBill Paul 1021ff49530fSBill Paul /* 1022ff49530fSBill Paul * Add another argument to the arg list 1023ff49530fSBill Paul */ 1024ff49530fSBill Paul static void 1025ff49530fSBill Paul addarg(cp) 1026ff49530fSBill Paul char *cp; 1027ff49530fSBill Paul { 1028ff49530fSBill Paul if (argcount >= ARGLISTLEN) { 10290e76f40dSPhilippe Charnier warnx("too many defines"); 1030ff49530fSBill Paul crash(); 1031ff49530fSBill Paul /*NOTREACHED*/ 1032ff49530fSBill Paul } 1033ff49530fSBill Paul arglist[argcount++] = cp; 1034ff49530fSBill Paul 1035ff49530fSBill Paul } 1036ff49530fSBill Paul 1037ff49530fSBill Paul static void 1038ff49530fSBill Paul putarg(where, cp) 1039ff49530fSBill Paul char *cp; 1040ff49530fSBill Paul int where; 1041ff49530fSBill Paul { 1042ff49530fSBill Paul if (where >= ARGLISTLEN) { 10430e76f40dSPhilippe Charnier warnx("arglist coding error"); 1044ff49530fSBill Paul crash(); 1045ff49530fSBill Paul /*NOTREACHED*/ 1046ff49530fSBill Paul } 1047ff49530fSBill Paul arglist[where] = cp; 1048ff49530fSBill Paul } 1049ff49530fSBill Paul 1050ff49530fSBill Paul /* 1051ff49530fSBill Paul * if input file is stdin and an output file is specified then complain 1052ff49530fSBill Paul * if the file already exists. Otherwise the file may get overwritten 1053ff49530fSBill Paul * If input file does not exist, exit with an error 1054ff49530fSBill Paul */ 1055ff49530fSBill Paul 1056ff49530fSBill Paul static void 1057ff49530fSBill Paul checkfiles(infile, outfile) 1058ff49530fSBill Paul char *infile; 1059ff49530fSBill Paul char *outfile; 1060ff49530fSBill Paul { 1061ff49530fSBill Paul 1062ff49530fSBill Paul struct stat buf; 1063ff49530fSBill Paul 1064ff49530fSBill Paul if (infile) /* infile ! = NULL */ 1065ff49530fSBill Paul if (stat(infile, &buf) < 0) 1066ff49530fSBill Paul { 10670e76f40dSPhilippe Charnier warn("%s", infile); 1068ff49530fSBill Paul crash(); 1069ff49530fSBill Paul }; 1070ff49530fSBill Paul if (outfile) { 1071ff49530fSBill Paul if (stat(outfile, &buf) < 0) 1072ff49530fSBill Paul return; /* file does not exist */ 1073ff49530fSBill Paul else { 10740e76f40dSPhilippe Charnier warnx("file '%s' already exists and may be overwritten", outfile); 1075ff49530fSBill Paul crash(); 1076ff49530fSBill Paul } 1077ff49530fSBill Paul } 10784e115012SGarrett Wollman } 10794e115012SGarrett Wollman 10804e115012SGarrett Wollman /* 10814e115012SGarrett Wollman * Parse command line arguments 10824e115012SGarrett Wollman */ 1083526195adSJordan K. Hubbard static int 10844e115012SGarrett Wollman parseargs(argc, argv, cmd) 10854e115012SGarrett Wollman int argc; 10864e115012SGarrett Wollman char *argv[]; 10874e115012SGarrett Wollman struct commandline *cmd; 10884e115012SGarrett Wollman { 10894e115012SGarrett Wollman int i; 10904e115012SGarrett Wollman int j; 1091ff49530fSBill Paul char c, ch; 10924e115012SGarrett Wollman char flag[(1 << 8 * sizeof (char))]; 10934e115012SGarrett Wollman int nflags; 10944e115012SGarrett Wollman 10954e115012SGarrett Wollman cmd->infile = cmd->outfile = NULL; 10964e115012SGarrett Wollman if (argc < 2) { 10974e115012SGarrett Wollman return (0); 10984e115012SGarrett Wollman } 1099ff49530fSBill Paul allfiles = 0; 11004e115012SGarrett Wollman flag['c'] = 0; 11014e115012SGarrett Wollman flag['h'] = 0; 11024e115012SGarrett Wollman flag['l'] = 0; 11034e115012SGarrett Wollman flag['m'] = 0; 1104ff49530fSBill Paul flag['o'] = 0; 1105ff49530fSBill Paul flag['s'] = 0; 1106ff49530fSBill Paul flag['n'] = 0; 1107ff49530fSBill Paul flag['t'] = 0; 1108ff49530fSBill Paul flag['S'] = 0; 1109ff49530fSBill Paul flag['C'] = 0; 1110ff49530fSBill Paul flag['M'] = 0; 1111ff49530fSBill Paul 11124e115012SGarrett Wollman for (i = 1; i < argc; i++) { 11134e115012SGarrett Wollman if (argv[i][0] != '-') { 11144e115012SGarrett Wollman if (cmd->infile) { 11150e76f40dSPhilippe Charnier warnx("cannot specify more than one input file"); 11164e115012SGarrett Wollman return (0); 11174e115012SGarrett Wollman } 11184e115012SGarrett Wollman cmd->infile = argv[i]; 11194e115012SGarrett Wollman } else { 11204e115012SGarrett Wollman for (j = 1; argv[i][j] != 0; j++) { 11214e115012SGarrett Wollman c = argv[i][j]; 11224e115012SGarrett Wollman switch (c) { 1123ff49530fSBill Paul case 'a': 1124ff49530fSBill Paul allfiles = 1; 1125ff49530fSBill Paul break; 11264e115012SGarrett Wollman case 'c': 11274e115012SGarrett Wollman case 'h': 11284e115012SGarrett Wollman case 'l': 11294e115012SGarrett Wollman case 'm': 1130ff49530fSBill Paul case 't': 1131526195adSJordan K. Hubbard if (flag[(int)c]) { 11324e115012SGarrett Wollman return (0); 11334e115012SGarrett Wollman } 1134526195adSJordan K. Hubbard flag[(int)c] = 1; 11354e115012SGarrett Wollman break; 1136ff49530fSBill Paul case 'S': 1137ff49530fSBill Paul /* 1138ff49530fSBill Paul * sample flag: Ss or Sc. 1139ff49530fSBill Paul * Ss means set flag['S']; 1140ff49530fSBill Paul * Sc means set flag['C']; 1141ff49530fSBill Paul * Sm means set flag['M']; 1142ff49530fSBill Paul */ 1143ff49530fSBill Paul ch = argv[i][++j]; /* get next char */ 1144ff49530fSBill Paul if (ch == 's') 1145ff49530fSBill Paul ch = 'S'; 1146ff49530fSBill Paul else if (ch == 'c') 1147ff49530fSBill Paul ch = 'C'; 1148ff49530fSBill Paul else if (ch == 'm') 1149ff49530fSBill Paul ch = 'M'; 1150ff49530fSBill Paul else 1151ff49530fSBill Paul return (0); 1152ff49530fSBill Paul 1153526195adSJordan K. Hubbard if (flag[(int)ch]) { 1154ff49530fSBill Paul return (0); 1155ff49530fSBill Paul } 1156526195adSJordan K. Hubbard flag[(int)ch] = 1; 1157ff49530fSBill Paul break; 1158ff49530fSBill Paul case 'C': /* ANSI C syntax */ 1159ff49530fSBill Paul Cflag = 1; 1160ff49530fSBill Paul ch = argv[i][j+1]; /* get next char */ 1161ff49530fSBill Paul 1162ff49530fSBill Paul if (ch != 'C') 1163ff49530fSBill Paul break; 1164ff49530fSBill Paul CCflag = 1; 1165ff49530fSBill Paul break; 1166ff49530fSBill Paul case 'b': 1167ff49530fSBill Paul /* 1168ff49530fSBill Paul * Turn TIRPC flag off for 1169ff49530fSBill Paul * generating backward compatible 1170ff49530fSBill Paul * code 1171ff49530fSBill Paul */ 1172ff49530fSBill Paul #ifdef __FreeBSD__ 1173ff49530fSBill Paul tirpcflag = 1; 1174ff49530fSBill Paul #else 1175ff49530fSBill Paul tirpcflag = 0; 1176ff49530fSBill Paul #endif 1177ff49530fSBill Paul break; 1178ff49530fSBill Paul 1179ff49530fSBill Paul case 'I': 1180ff49530fSBill Paul inetdflag = 1; 1181ff49530fSBill Paul break; 1182ff49530fSBill Paul case 'N': 1183ff49530fSBill Paul newstyle = 1; 1184ff49530fSBill Paul break; 1185ff49530fSBill Paul case 'L': 1186ff49530fSBill Paul logflag = 1; 1187ff49530fSBill Paul break; 1188ff49530fSBill Paul case 'K': 1189ff49530fSBill Paul if (++i == argc) { 1190ff49530fSBill Paul return (0); 1191ff49530fSBill Paul } 1192ff49530fSBill Paul svcclosetime = argv[i]; 1193ff49530fSBill Paul goto nextarg; 1194ff49530fSBill Paul case 'T': 1195ff49530fSBill Paul tblflag = 1; 1196ff49530fSBill Paul break; 1197ff49530fSBill Paul case 'M': 1198ff49530fSBill Paul mtflag = 1; 1199ff49530fSBill Paul break; 1200ff49530fSBill Paul case 'i' : 1201ff49530fSBill Paul if (++i == argc) { 1202ff49530fSBill Paul return (0); 1203ff49530fSBill Paul } 1204ff49530fSBill Paul inline = atoi(argv[i]); 1205ff49530fSBill Paul goto nextarg; 1206ff49530fSBill Paul case 'n': 12074e115012SGarrett Wollman case 'o': 12084e115012SGarrett Wollman case 's': 12094e115012SGarrett Wollman if (argv[i][j - 1] != '-' || 12104e115012SGarrett Wollman argv[i][j + 1] != 0) { 12114e115012SGarrett Wollman return (0); 12124e115012SGarrett Wollman } 1213526195adSJordan K. Hubbard flag[(int)c] = 1; 12144e115012SGarrett Wollman if (++i == argc) { 12154e115012SGarrett Wollman return (0); 12164e115012SGarrett Wollman } 1217ff49530fSBill Paul if (c == 'o') { 12184e115012SGarrett Wollman if (cmd->outfile) { 12194e115012SGarrett Wollman return (0); 12204e115012SGarrett Wollman } 12214e115012SGarrett Wollman cmd->outfile = argv[i]; 12224e115012SGarrett Wollman } 12234e115012SGarrett Wollman goto nextarg; 1224ff49530fSBill Paul case 'D': 1225ff49530fSBill Paul if (argv[i][j - 1] != '-') { 1226ff49530fSBill Paul return (0); 1227ff49530fSBill Paul } 1228ff49530fSBill Paul (void) addarg(argv[i]); 1229ff49530fSBill Paul goto nextarg; 1230ff49530fSBill Paul case 'Y': 1231ff49530fSBill Paul if (++i == argc) { 1232ff49530fSBill Paul return (0); 1233ff49530fSBill Paul } 1234ff49530fSBill Paul (void) strcpy(pathbuf, argv[i]); 1235ff49530fSBill Paul (void) strcat(pathbuf, "/cpp"); 1236ff49530fSBill Paul CPP = pathbuf; 1237ff49530fSBill Paul cppDefined = 1; 1238ff49530fSBill Paul goto nextarg; 1239ff49530fSBill Paul 1240ff49530fSBill Paul 12414e115012SGarrett Wollman 12424e115012SGarrett Wollman default: 12434e115012SGarrett Wollman return (0); 12444e115012SGarrett Wollman } 12454e115012SGarrett Wollman } 12464e115012SGarrett Wollman nextarg: 12474e115012SGarrett Wollman ; 12484e115012SGarrett Wollman } 12494e115012SGarrett Wollman } 1250ff49530fSBill Paul 12514e115012SGarrett Wollman cmd->cflag = flag['c']; 12524e115012SGarrett Wollman cmd->hflag = flag['h']; 12534e115012SGarrett Wollman cmd->lflag = flag['l']; 12544e115012SGarrett Wollman cmd->mflag = flag['m']; 1255ff49530fSBill Paul cmd->nflag = flag['n']; 1256ff49530fSBill Paul cmd->sflag = flag['s']; 1257ff49530fSBill Paul cmd->tflag = flag['t']; 1258ff49530fSBill Paul cmd->Ssflag = flag['S']; 1259ff49530fSBill Paul cmd->Scflag = flag['C']; 1260ff49530fSBill Paul cmd->makefileflag = flag['M']; 1261ff49530fSBill Paul 1262ff49530fSBill Paul if (tirpcflag) { 1263ff49530fSBill Paul pmflag = inetdflag ? 0 : 1; 1264ff49530fSBill Paul /* pmflag or inetdflag is always TRUE */ 1265ff49530fSBill Paul if ((inetdflag && cmd->nflag)) { 1266ff49530fSBill Paul /* netid not allowed with inetdflag */ 12670e76f40dSPhilippe Charnier warnx("cannot use netid flag with inetd flag"); 1268ff49530fSBill Paul return (0); 1269ff49530fSBill Paul } 1270ff49530fSBill Paul } else { /* 4.1 mode */ 1271ff49530fSBill Paul pmflag = 0; /* set pmflag only in tirpcmode */ 1272ff49530fSBill Paul #ifndef __FreeBSD__ 1273ff49530fSBill Paul inetdflag = 1; /* inetdflag is TRUE by default */ 1274ff49530fSBill Paul #endif 1275ff49530fSBill Paul if (cmd->nflag) { /* netid needs TIRPC */ 12760e76f40dSPhilippe Charnier warnx("cannot use netid flag without TIRPC"); 1277ff49530fSBill Paul return (0); 1278ff49530fSBill Paul } 1279ff49530fSBill Paul } 1280ff49530fSBill Paul 1281ff49530fSBill Paul if (newstyle && (tblflag || cmd->tflag)) { 12820e76f40dSPhilippe Charnier warnx("cannot use table flags with newstyle"); 1283ff49530fSBill Paul return (0); 1284ff49530fSBill Paul } 1285ff49530fSBill Paul 1286ff49530fSBill Paul /* check no conflicts with file generation flags */ 1287ff49530fSBill Paul nflags = cmd->cflag + cmd->hflag + cmd->lflag + cmd->mflag + 1288ff49530fSBill Paul cmd->sflag + cmd->nflag + cmd->tflag + cmd->Ssflag + 1289ff49530fSBill Paul cmd->Scflag + cmd->makefileflag; 1290ff49530fSBill Paul 12914e115012SGarrett Wollman if (nflags == 0) { 12924e115012SGarrett Wollman if (cmd->outfile != NULL || cmd->infile == NULL) { 12934e115012SGarrett Wollman return (0); 12944e115012SGarrett Wollman } 1295ff49530fSBill Paul } else if (cmd->infile == NULL && 1296ff49530fSBill Paul (cmd->Ssflag || cmd->Scflag || cmd->makefileflag)) { 12970e76f40dSPhilippe Charnier warnx("\"infile\" is required for template generation flags"); 1298ff49530fSBill Paul return (0); 1299ff49530fSBill Paul } if (nflags > 1) { 13000e76f40dSPhilippe Charnier warnx("cannot have more than one file generation flag"); 13014e115012SGarrett Wollman return (0); 13024e115012SGarrett Wollman } 13034e115012SGarrett Wollman return (1); 13044e115012SGarrett Wollman } 1305ff49530fSBill Paul 1306526195adSJordan K. Hubbard static void 1307ff49530fSBill Paul usage() 1308ff49530fSBill Paul { 13090e76f40dSPhilippe Charnier f_print(stderr, "%s\n%s\n%s\n%s\n%s\n", 13100e76f40dSPhilippe Charnier "usage: rpcgen infile", 13110e76f40dSPhilippe Charnier " rpcgen [-abCLNTM] [-Dname[=value]] [-i size]\ 13120e76f40dSPhilippe Charnier [-I [-K seconds]] [-Y path] infile", 13130e76f40dSPhilippe Charnier " rpcgen [-c | -h | -l | -m | -t | -Sc | -Ss | -Sm]\ 13140e76f40dSPhilippe Charnier [-o outfile] [infile]", 13150e76f40dSPhilippe Charnier " rpcgen [-s nettype]* [-o outfile] [infile]", 13160e76f40dSPhilippe Charnier " rpcgen [-n netid]* [-o outfile] [infile]"); 1317ff49530fSBill Paul options_usage(); 1318ff49530fSBill Paul exit(1); 1319ff49530fSBill Paul } 1320ff49530fSBill Paul 1321526195adSJordan K. Hubbard static void 1322ff49530fSBill Paul options_usage() 1323ff49530fSBill Paul { 1324ff49530fSBill Paul f_print(stderr, "options:\n"); 1325ff49530fSBill Paul f_print(stderr, "-a\t\tgenerate all files, including samples\n"); 1326ff49530fSBill Paul f_print(stderr, "-b\t\tbackward compatibility mode (generates code\ 1327ff49530fSBill Paul for SunOS 4.X)\n"); 1328ff49530fSBill Paul f_print(stderr, "-c\t\tgenerate XDR routines\n"); 1329ff49530fSBill Paul f_print(stderr, "-C\t\tANSI C mode\n"); 1330ff49530fSBill Paul f_print(stderr, "-Dname[=value]\tdefine a symbol (same as #define)\n"); 1331ff49530fSBill Paul f_print(stderr, "-h\t\tgenerate header file\n"); 1332ff49530fSBill Paul f_print(stderr, "-i size\t\tsize at which to start generating\ 1333ff49530fSBill Paul inline code\n"); 1334ff49530fSBill Paul f_print(stderr, "-I\t\tgenerate code for inetd support in server\ 1335ff49530fSBill Paul (for SunOS 4.X)\n"); 1336ff49530fSBill Paul f_print(stderr, "-K seconds\tserver exits after K seconds of\ 1337ff49530fSBill Paul inactivity\n"); 1338ff49530fSBill Paul f_print(stderr, "-l\t\tgenerate client side stubs\n"); 1339ff49530fSBill Paul f_print(stderr, "-L\t\tserver errors will be printed to syslog\n"); 1340ff49530fSBill Paul f_print(stderr, "-m\t\tgenerate server side stubs\n"); 1341ff49530fSBill Paul f_print(stderr, "-M\t\tgenerate MT-safe code\n"); 1342ff49530fSBill Paul f_print(stderr, "-n netid\tgenerate server code that supports\ 1343ff49530fSBill Paul named netid\n"); 1344ff49530fSBill Paul f_print(stderr, "-N\t\tsupports multiple arguments and\ 1345ff49530fSBill Paul call-by-value\n"); 1346ff49530fSBill Paul f_print(stderr, "-o outfile\tname of the output file\n"); 1347ff49530fSBill Paul f_print(stderr, "-s nettype\tgenerate server code that supports named\ 1348ff49530fSBill Paul nettype\n"); 1349ff49530fSBill Paul f_print(stderr, "-Sc\t\tgenerate sample client code that uses remote\ 1350ff49530fSBill Paul procedures\n"); 1351ff49530fSBill Paul f_print(stderr, "-Ss\t\tgenerate sample server code that defines\ 1352ff49530fSBill Paul remote procedures\n"); 1353ff49530fSBill Paul f_print(stderr, "-Sm \t\tgenerate makefile template \n"); 1354ff49530fSBill Paul 1355ff49530fSBill Paul f_print(stderr, "-t\t\tgenerate RPC dispatch table\n"); 1356ff49530fSBill Paul f_print(stderr, "-T\t\tgenerate code to support RPC dispatch tables\n"); 1357ff49530fSBill Paul f_print(stderr, "-Y path\t\tpath where cpp is found\n"); 1358ff49530fSBill Paul exit(1); 1359ff49530fSBill Paul } 1360ff49530fSBill Paul 1361ff49530fSBill Paul #ifndef __FreeBSD__ 1362ff49530fSBill Paul char * 1363ff49530fSBill Paul rindex(sp, c) 1364ff49530fSBill Paul register char *sp, c; 1365ff49530fSBill Paul { 1366ff49530fSBill Paul register char *r; 1367ff49530fSBill Paul 1368ff49530fSBill Paul r = NULL; 1369ff49530fSBill Paul do { 1370ff49530fSBill Paul if (*sp == c) 1371ff49530fSBill Paul r = sp; 1372ff49530fSBill Paul } while (*sp++); 1373ff49530fSBill Paul return (r); 1374ff49530fSBill Paul } 1375ff49530fSBill Paul #endif 1376