Deleted Added
full compact
rpc_main.c (17142) rpc_main.c (27935)
1/*
2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
8 *

--- 17 unchanged lines hidden (view full) ---

26 * 2550 Garcia Avenue
27 * Mountain View, California 94043
28 */
29
30
31#ident "@(#)rpc_main.c 1.21 94/04/25 SMI"
32
33#ifndef lint
1/*
2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
8 *

--- 17 unchanged lines hidden (view full) ---

26 * 2550 Garcia Avenue
27 * Mountain View, California 94043
28 */
29
30
31#ident "@(#)rpc_main.c 1.21 94/04/25 SMI"
32
33#ifndef lint
34#if 0
34static char sccsid[] = "@(#)rpc_main.c 1.30 89/03/30 (C) 1987 SMI";
35#endif
35static char sccsid[] = "@(#)rpc_main.c 1.30 89/03/30 (C) 1987 SMI";
36#endif
37static const char rcsid[] =
38 "$Id$";
39#endif
36
37/*
38 * rpc_main.c, Top level of the RPC protocol compiler.
39 * Copyright (C) 1987, Sun Microsystems, Inc.
40 */
41
40
41/*
42 * rpc_main.c, Top level of the RPC protocol compiler.
43 * Copyright (C) 1987, Sun Microsystems, Inc.
44 */
45
46#include <err.h>
47#include <ctype.h>
42#include <stdio.h>
43#include <string.h>
44#include <unistd.h>
48#include <stdio.h>
49#include <string.h>
50#include <unistd.h>
45#include <ctype.h>
46#include <sys/types.h>
47#include <sys/param.h>
48#include <sys/file.h>
49#include <sys/stat.h>
50#include "rpc_parse.h"
51#include "rpc_util.h"
52#include "rpc_scan.h"
53

--- 28 unchanged lines hidden (view full) ---

82#ifdef __FreeBSD__
83#define SUNOS_CPP "/usr/libexec/cpp"
84#else
85#define SUNOS_CPP "/usr/lib/cpp"
86#endif
87
88static int cppDefined = 0; /* explicit path for C preprocessor */
89
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

--- 28 unchanged lines hidden (view full) ---

87#ifdef __FreeBSD__
88#define SUNOS_CPP "/usr/libexec/cpp"
89#else
90#define SUNOS_CPP "/usr/lib/cpp"
91#endif
92
93static int cppDefined = 0; /* explicit path for C preprocessor */
94
90
91static char *cmdname;
92
93static char *svcclosetime = "120";
94static char *CPP = SVR4_CPP;
95static char CPPFLAGS[] = "-C";
96static char pathbuf[MAXPATHLEN + 1];
97static char *allv[] = {
98 "rpcgen", "-s", "udp", "-s", "tcp",
99};
100static int allc = sizeof (allv)/sizeof (allv[0]);

--- 185 unchanged lines hidden (view full) ---

286{
287
288 if (outfile == NULL) {
289 fout = stdout;
290 return;
291 }
292
293 if (infile != NULL && streq(outfile, infile)) {
95static char *svcclosetime = "120";
96static char *CPP = SVR4_CPP;
97static char CPPFLAGS[] = "-C";
98static char pathbuf[MAXPATHLEN + 1];
99static char *allv[] = {
100 "rpcgen", "-s", "udp", "-s", "tcp",
101};
102static int allc = sizeof (allv)/sizeof (allv[0]);

--- 185 unchanged lines hidden (view full) ---

288{
289
290 if (outfile == NULL) {
291 fout = stdout;
292 return;
293 }
294
295 if (infile != NULL && streq(outfile, infile)) {
294 f_print(stderr, "%s: %s already exists. No output generated.\n",
295 cmdname, infile);
296 warnx("%s already exists. No output generated", infile);
296 crash();
297 }
298 fout = fopen(outfile, "w");
299 if (fout == NULL) {
297 crash();
298 }
299 fout = fopen(outfile, "w");
300 if (fout == NULL) {
300 f_print(stderr, "%s: unable to open ", cmdname);
301 perror(outfile);
301 warn("unable to open %s", outfile);
302 crash();
303 }
304 record_open(outfile);
305
306 return;
307}
308
309static void

--- 16 unchanged lines hidden (view full) ---

326
327/* make sure that a CPP exists */
328static void find_cpp()
329{
330 struct stat buf;
331
332 if (stat(CPP, &buf) < 0) { /* SVR4 or explicit cpp does not exist */
333 if (cppDefined) {
302 crash();
303 }
304 record_open(outfile);
305
306 return;
307}
308
309static void

--- 16 unchanged lines hidden (view full) ---

326
327/* make sure that a CPP exists */
328static void find_cpp()
329{
330 struct stat buf;
331
332 if (stat(CPP, &buf) < 0) { /* SVR4 or explicit cpp does not exist */
333 if (cppDefined) {
334 fprintf(stderr,
335 "cannot find C preprocessor: %s \n", CPP);
334 warnx("cannot find C preprocessor: %s", CPP);
336 crash();
337 } else { /* try the other one */
338 CPP = SUNOS_CPP;
339 if (stat(CPP, &buf) < 0) { /* can't find any cpp */
335 crash();
336 } else { /* try the other one */
337 CPP = SUNOS_CPP;
338 if (stat(CPP, &buf) < 0) { /* can't find any cpp */
340 fprintf(stderr,
341 "cannot find any C preprocessor (cpp)\n");
339 warnx("cannot find any C preprocessor (cpp)");
342 crash();
343 }
344 }
345 }
346}
347
348/*
349 * Open input file with given define for C-preprocessor

--- 15 unchanged lines hidden (view full) ---

365 addarg(define);
366 if (infile)
367 addarg(infile);
368 addarg((char *)NULL);
369 (void) close(1);
370 (void) dup2(pd[1], 1);
371 (void) close(pd[0]);
372 execv(arglist[0], arglist);
340 crash();
341 }
342 }
343 }
344}
345
346/*
347 * Open input file with given define for C-preprocessor

--- 15 unchanged lines hidden (view full) ---

363 addarg(define);
364 if (infile)
365 addarg(infile);
366 addarg((char *)NULL);
367 (void) close(1);
368 (void) dup2(pd[1], 1);
369 (void) close(pd[0]);
370 execv(arglist[0], arglist);
373 perror("execv");
371 warn("execv");
374 exit(1);
375 case -1:
372 exit(1);
373 case -1:
376 perror("fork");
374 warn("fork");
377 exit(1);
378 }
379 (void) close(pd[1]);
380 fin = fdopen(pd[0], "r");
381 if (fin == NULL) {
375 exit(1);
376 }
377 (void) close(pd[1]);
378 fin = fdopen(pd[0], "r");
379 if (fin == NULL) {
382 f_print(stderr, "%s: ", cmdname);
383 perror(infilename);
380 warn("%s", infilename);
384 crash();
385 }
386}
387
388/* valid tirpc nettypes */
389static char* valid_ti_nettypes[] =
390{
391 "netpath",

--- 21 unchanged lines hidden (view full) ---

413char* list_to_check[];
414{
415 int i;
416 for (i = 0; list_to_check[i] != NULL; i++) {
417 if (strcmp(name, list_to_check[i]) == 0) {
418 return (1);
419 }
420 }
381 crash();
382 }
383}
384
385/* valid tirpc nettypes */
386static char* valid_ti_nettypes[] =
387{
388 "netpath",

--- 21 unchanged lines hidden (view full) ---

410char* list_to_check[];
411{
412 int i;
413 for (i = 0; list_to_check[i] != NULL; i++) {
414 if (strcmp(name, list_to_check[i]) == 0) {
415 return (1);
416 }
417 }
421 f_print(stderr, "illegal nettype :\'%s\'\n", name);
418 warnx("illegal nettype :\'%s\'", name);
422 return (0);
423}
424
425static char *
426file_name(file, ext)
427char *file;
428char *ext;
429{

--- 594 unchanged lines hidden (view full) ---

1024/*
1025 * Add another argument to the arg list
1026 */
1027static void
1028addarg(cp)
1029 char *cp;
1030{
1031 if (argcount >= ARGLISTLEN) {
419 return (0);
420}
421
422static char *
423file_name(file, ext)
424char *file;
425char *ext;
426{

--- 594 unchanged lines hidden (view full) ---

1021/*
1022 * Add another argument to the arg list
1023 */
1024static void
1025addarg(cp)
1026 char *cp;
1027{
1028 if (argcount >= ARGLISTLEN) {
1032 f_print(stderr, "rpcgen: too many defines\n");
1029 warnx("too many defines");
1033 crash();
1034 /*NOTREACHED*/
1035 }
1036 arglist[argcount++] = cp;
1037
1038}
1039
1040static void
1041putarg(where, cp)
1042 char *cp;
1043 int where;
1044{
1045 if (where >= ARGLISTLEN) {
1030 crash();
1031 /*NOTREACHED*/
1032 }
1033 arglist[argcount++] = cp;
1034
1035}
1036
1037static void
1038putarg(where, cp)
1039 char *cp;
1040 int where;
1041{
1042 if (where >= ARGLISTLEN) {
1046 f_print(stderr, "rpcgen: arglist coding error\n");
1043 warnx("arglist coding error");
1047 crash();
1048 /*NOTREACHED*/
1049 }
1050 arglist[where] = cp;
1051}
1052
1053/*
1054 * if input file is stdin and an output file is specified then complain

--- 7 unchanged lines hidden (view full) ---

1062char *outfile;
1063{
1064
1065 struct stat buf;
1066
1067 if (infile) /* infile ! = NULL */
1068 if (stat(infile, &buf) < 0)
1069 {
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

--- 7 unchanged lines hidden (view full) ---

1059char *outfile;
1060{
1061
1062 struct stat buf;
1063
1064 if (infile) /* infile ! = NULL */
1065 if (stat(infile, &buf) < 0)
1066 {
1070 perror(infile);
1067 warn("%s", infile);
1071 crash();
1072 };
1073 if (outfile) {
1074 if (stat(outfile, &buf) < 0)
1075 return; /* file does not exist */
1076 else {
1068 crash();
1069 };
1070 if (outfile) {
1071 if (stat(outfile, &buf) < 0)
1072 return; /* file does not exist */
1073 else {
1077 f_print(stderr,
1078 "file '%s' already exists and may be overwritten\n",
1079 outfile);
1074 warnx("file '%s' already exists and may be overwritten", outfile);
1080 crash();
1081 }
1082 }
1083}
1084
1085/*
1086 * Parse command line arguments
1087 */

--- 4 unchanged lines hidden (view full) ---

1092 struct commandline *cmd;
1093{
1094 int i;
1095 int j;
1096 char c, ch;
1097 char flag[(1 << 8 * sizeof (char))];
1098 int nflags;
1099
1075 crash();
1076 }
1077 }
1078}
1079
1080/*
1081 * Parse command line arguments
1082 */

--- 4 unchanged lines hidden (view full) ---

1087 struct commandline *cmd;
1088{
1089 int i;
1090 int j;
1091 char c, ch;
1092 char flag[(1 << 8 * sizeof (char))];
1093 int nflags;
1094
1100 cmdname = argv[0];
1101 cmd->infile = cmd->outfile = NULL;
1102 if (argc < 2) {
1103 return (0);
1104 }
1105 allfiles = 0;
1106 flag['c'] = 0;
1107 flag['h'] = 0;
1108 flag['l'] = 0;

--- 4 unchanged lines hidden (view full) ---

1113 flag['t'] = 0;
1114 flag['S'] = 0;
1115 flag['C'] = 0;
1116 flag['M'] = 0;
1117
1118 for (i = 1; i < argc; i++) {
1119 if (argv[i][0] != '-') {
1120 if (cmd->infile) {
1095 cmd->infile = cmd->outfile = NULL;
1096 if (argc < 2) {
1097 return (0);
1098 }
1099 allfiles = 0;
1100 flag['c'] = 0;
1101 flag['h'] = 0;
1102 flag['l'] = 0;

--- 4 unchanged lines hidden (view full) ---

1107 flag['t'] = 0;
1108 flag['S'] = 0;
1109 flag['C'] = 0;
1110 flag['M'] = 0;
1111
1112 for (i = 1; i < argc; i++) {
1113 if (argv[i][0] != '-') {
1114 if (cmd->infile) {
1121 f_print(stderr,
1122 "Cannot specify more than one input file.\n");
1123
1115 warnx("cannot specify more than one input file");
1124 return (0);
1125 }
1126 cmd->infile = argv[i];
1127 } else {
1128 for (j = 1; argv[i][j] != 0; j++) {
1129 c = argv[i][j];
1130 switch (c) {
1131 case 'a':

--- 135 unchanged lines hidden (view full) ---

1267 cmd->Scflag = flag['C'];
1268 cmd->makefileflag = flag['M'];
1269
1270 if (tirpcflag) {
1271 pmflag = inetdflag ? 0 : 1;
1272 /* pmflag or inetdflag is always TRUE */
1273 if ((inetdflag && cmd->nflag)) {
1274 /* netid not allowed with inetdflag */
1116 return (0);
1117 }
1118 cmd->infile = argv[i];
1119 } else {
1120 for (j = 1; argv[i][j] != 0; j++) {
1121 c = argv[i][j];
1122 switch (c) {
1123 case 'a':

--- 135 unchanged lines hidden (view full) ---

1259 cmd->Scflag = flag['C'];
1260 cmd->makefileflag = flag['M'];
1261
1262 if (tirpcflag) {
1263 pmflag = inetdflag ? 0 : 1;
1264 /* pmflag or inetdflag is always TRUE */
1265 if ((inetdflag && cmd->nflag)) {
1266 /* netid not allowed with inetdflag */
1275 f_print(stderr, "Cannot use netid flag with inetd flag.\n");
1267 warnx("cannot use netid flag with inetd flag");
1276 return (0);
1277 }
1278 } else { /* 4.1 mode */
1279 pmflag = 0; /* set pmflag only in tirpcmode */
1280#ifndef __FreeBSD__
1281 inetdflag = 1; /* inetdflag is TRUE by default */
1282#endif
1283 if (cmd->nflag) { /* netid needs TIRPC */
1268 return (0);
1269 }
1270 } else { /* 4.1 mode */
1271 pmflag = 0; /* set pmflag only in tirpcmode */
1272#ifndef __FreeBSD__
1273 inetdflag = 1; /* inetdflag is TRUE by default */
1274#endif
1275 if (cmd->nflag) { /* netid needs TIRPC */
1284 f_print(stderr, "Cannot use netid flag without TIRPC.\n");
1276 warnx("cannot use netid flag without TIRPC");
1285 return (0);
1286 }
1287 }
1288
1289 if (newstyle && (tblflag || cmd->tflag)) {
1277 return (0);
1278 }
1279 }
1280
1281 if (newstyle && (tblflag || cmd->tflag)) {
1290 f_print(stderr, "Cannot use table flags with newstyle.\n");
1282 warnx("cannot use table flags with newstyle");
1291 return (0);
1292 }
1293
1294 /* check no conflicts with file generation flags */
1295 nflags = cmd->cflag + cmd->hflag + cmd->lflag + cmd->mflag +
1296 cmd->sflag + cmd->nflag + cmd->tflag + cmd->Ssflag +
1297 cmd->Scflag + cmd->makefileflag;
1298
1299 if (nflags == 0) {
1300 if (cmd->outfile != NULL || cmd->infile == NULL) {
1301 return (0);
1302 }
1303 } else if (cmd->infile == NULL &&
1304 (cmd->Ssflag || cmd->Scflag || cmd->makefileflag)) {
1283 return (0);
1284 }
1285
1286 /* check no conflicts with file generation flags */
1287 nflags = cmd->cflag + cmd->hflag + cmd->lflag + cmd->mflag +
1288 cmd->sflag + cmd->nflag + cmd->tflag + cmd->Ssflag +
1289 cmd->Scflag + cmd->makefileflag;
1290
1291 if (nflags == 0) {
1292 if (cmd->outfile != NULL || cmd->infile == NULL) {
1293 return (0);
1294 }
1295 } else if (cmd->infile == NULL &&
1296 (cmd->Ssflag || cmd->Scflag || cmd->makefileflag)) {
1305 f_print(stderr,
1306 "\"infile\" is required for template generation flags.\n");
1297 warnx("\"infile\" is required for template generation flags");
1307 return (0);
1308 } if (nflags > 1) {
1298 return (0);
1299 } if (nflags > 1) {
1309 f_print(stderr,
1310 "Cannot have more than one file generation flag.\n");
1300 warnx("cannot have more than one file generation flag");
1311 return (0);
1312 }
1313 return (1);
1314}
1315
1316static void
1317usage()
1318{
1301 return (0);
1302 }
1303 return (1);
1304}
1305
1306static void
1307usage()
1308{
1319 f_print(stderr, "usage: %s infile\n", cmdname);
1320 f_print(stderr,
1321 "\t%s [-abCLNTM] [-Dname[=value]] [-i size]\
1322[-I [-K seconds]] [-Y path] infile\n",
1323 cmdname);
1324 f_print(stderr,
1325 "\t%s [-c | -h | -l | -m | -t | -Sc | -Ss | -Sm]\
1326[-o outfile] [infile]\n",
1327 cmdname);
1328 f_print(stderr, "\t%s [-s nettype]* [-o outfile] [infile]\n", cmdname);
1329 f_print(stderr, "\t%s [-n netid]* [-o outfile] [infile]\n", cmdname);
1309 f_print(stderr, "%s\n%s\n%s\n%s\n%s\n",
1310 "usage: rpcgen infile",
1311 " rpcgen [-abCLNTM] [-Dname[=value]] [-i size]\
1312[-I [-K seconds]] [-Y path] infile",
1313 " rpcgen [-c | -h | -l | -m | -t | -Sc | -Ss | -Sm]\
1314[-o outfile] [infile]",
1315 " rpcgen [-s nettype]* [-o outfile] [infile]",
1316 " rpcgen [-n netid]* [-o outfile] [infile]");
1330 options_usage();
1331 exit(1);
1332}
1333
1334static void
1335options_usage()
1336{
1337 f_print(stderr, "options:\n");

--- 51 unchanged lines hidden ---
1317 options_usage();
1318 exit(1);
1319}
1320
1321static void
1322options_usage()
1323{
1324 f_print(stderr, "options:\n");

--- 51 unchanged lines hidden ---