14e115012SGarrett Wollman /* @(#)rpc_main.c 2.2 88/08/01 4.0 RPCSRC */ 24e115012SGarrett Wollman /* 34e115012SGarrett Wollman * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 44e115012SGarrett Wollman * unrestricted use provided that this legend is included on all tape 54e115012SGarrett Wollman * media and as a part of the software program in whole or part. Users 64e115012SGarrett Wollman * may copy or modify Sun RPC without charge, but are not authorized 74e115012SGarrett Wollman * to license or distribute it to anyone else except as part of a product or 84e115012SGarrett Wollman * program developed by the user. 94e115012SGarrett Wollman * 104e115012SGarrett Wollman * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 114e115012SGarrett Wollman * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 124e115012SGarrett Wollman * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 134e115012SGarrett Wollman * 144e115012SGarrett Wollman * Sun RPC is provided with no support and without any obligation on the 154e115012SGarrett Wollman * part of Sun Microsystems, Inc. to assist in its use, correction, 164e115012SGarrett Wollman * modification or enhancement. 174e115012SGarrett Wollman * 184e115012SGarrett Wollman * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 194e115012SGarrett Wollman * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 204e115012SGarrett Wollman * OR ANY PART THEREOF. 214e115012SGarrett Wollman * 224e115012SGarrett Wollman * In no event will Sun Microsystems, Inc. be liable for any lost revenue 234e115012SGarrett Wollman * or profits or other special, indirect and consequential damages, even if 244e115012SGarrett Wollman * Sun has been advised of the possibility of such damages. 254e115012SGarrett Wollman * 264e115012SGarrett Wollman * Sun Microsystems, Inc. 274e115012SGarrett Wollman * 2550 Garcia Avenue 284e115012SGarrett Wollman * Mountain View, California 94043 294e115012SGarrett Wollman */ 304e115012SGarrett Wollman #ifndef lint 314e115012SGarrett Wollman /*static char sccsid[] = "from: @(#)rpc_main.c 1.7 87/06/24 (C) 1987 SMI";*/ 325ec07232SNate Williams static char rcsid[] = "$Id: rpc_main.c,v 1.1 1994/08/07 18:01:31 wollman Exp $"; 334e115012SGarrett Wollman #endif 344e115012SGarrett Wollman 354e115012SGarrett Wollman /* 364e115012SGarrett Wollman * rpc_main.c, Top level of the RPC protocol compiler. 374e115012SGarrett Wollman * Copyright (C) 1987, Sun Microsystems, Inc. 384e115012SGarrett Wollman */ 394e115012SGarrett Wollman 404e115012SGarrett Wollman #include <stdio.h> 414e115012SGarrett Wollman #include <strings.h> 424e115012SGarrett Wollman #include <sys/file.h> 434e115012SGarrett Wollman #include "rpc_util.h" 444e115012SGarrett Wollman #include "rpc_parse.h" 454e115012SGarrett Wollman #include "rpc_scan.h" 464e115012SGarrett Wollman 474e115012SGarrett Wollman #define EXTEND 1 /* alias for TRUE */ 484e115012SGarrett Wollman 494e115012SGarrett Wollman struct commandline { 504e115012SGarrett Wollman int cflag; 514e115012SGarrett Wollman int hflag; 524e115012SGarrett Wollman int lflag; 534e115012SGarrett Wollman int sflag; 544e115012SGarrett Wollman int mflag; 554e115012SGarrett Wollman char *infile; 564e115012SGarrett Wollman char *outfile; 574e115012SGarrett Wollman }; 584e115012SGarrett Wollman 594e115012SGarrett Wollman static char *cmdname; 604e115012SGarrett Wollman static char CPP[] = "/usr/bin/cpp"; 614e115012SGarrett Wollman static char CPPFLAGS[] = "-C"; 624e115012SGarrett Wollman static char *allv[] = { 634e115012SGarrett Wollman "rpcgen", "-s", "udp", "-s", "tcp", 644e115012SGarrett Wollman }; 654e115012SGarrett Wollman static int allc = sizeof(allv)/sizeof(allv[0]); 664e115012SGarrett Wollman 674e115012SGarrett Wollman 684e115012SGarrett Wollman static int h_output(), c_output(), s_output(), l_output(), do_registers(), 694e115012SGarrett Wollman parseargs(); 704e115012SGarrett Wollman 714e115012SGarrett Wollman main(argc, argv) 724e115012SGarrett Wollman int argc; 734e115012SGarrett Wollman char *argv[]; 744e115012SGarrett Wollman 754e115012SGarrett Wollman { 764e115012SGarrett Wollman struct commandline cmd; 774e115012SGarrett Wollman 784e115012SGarrett Wollman if (!parseargs(argc, argv, &cmd)) { 794e115012SGarrett Wollman f_print(stderr, 804e115012SGarrett Wollman "usage: %s infile\n", cmdname); 814e115012SGarrett Wollman f_print(stderr, 824e115012SGarrett Wollman " %s [-c | -h | -l | -m] [-o outfile] [infile]\n", 834e115012SGarrett Wollman cmdname); 844e115012SGarrett Wollman f_print(stderr, 854e115012SGarrett Wollman " %s [-s udp|tcp]* [-o outfile] [infile]\n", 864e115012SGarrett Wollman cmdname); 874e115012SGarrett Wollman exit(1); 884e115012SGarrett Wollman } 894e115012SGarrett Wollman if (cmd.cflag) { 904e115012SGarrett Wollman c_output(cmd.infile, "-DRPC_XDR", !EXTEND, cmd.outfile); 914e115012SGarrett Wollman } else if (cmd.hflag) { 924e115012SGarrett Wollman h_output(cmd.infile, "-DRPC_HDR", !EXTEND, cmd.outfile); 934e115012SGarrett Wollman } else if (cmd.lflag) { 944e115012SGarrett Wollman l_output(cmd.infile, "-DRPC_CLNT", !EXTEND, cmd.outfile); 954e115012SGarrett Wollman } else if (cmd.sflag || cmd.mflag) { 964e115012SGarrett Wollman s_output(argc, argv, cmd.infile, "-DRPC_SVC", !EXTEND, 974e115012SGarrett Wollman cmd.outfile, cmd.mflag); 984e115012SGarrett Wollman } else { 994e115012SGarrett Wollman c_output(cmd.infile, "-DRPC_XDR", EXTEND, "_xdr.c"); 1004e115012SGarrett Wollman reinitialize(); 1014e115012SGarrett Wollman h_output(cmd.infile, "-DRPC_HDR", EXTEND, ".h"); 1024e115012SGarrett Wollman reinitialize(); 1034e115012SGarrett Wollman l_output(cmd.infile, "-DRPC_CLNT", EXTEND, "_clnt.c"); 1044e115012SGarrett Wollman reinitialize(); 1054e115012SGarrett Wollman s_output(allc, allv, cmd.infile, "-DRPC_SVC", EXTEND, 1064e115012SGarrett Wollman "_svc.c", cmd.mflag); 1074e115012SGarrett Wollman } 1084e115012SGarrett Wollman exit(0); 1094e115012SGarrett Wollman } 1104e115012SGarrett Wollman 1114e115012SGarrett Wollman /* 1125ec07232SNate Williams * strip path and add extension to filename 1134e115012SGarrett Wollman */ 1144e115012SGarrett Wollman static char * 1155ec07232SNate Williams extendfile(path, ext) 1165ec07232SNate Williams char *path; 1174e115012SGarrett Wollman char *ext; 1184e115012SGarrett Wollman { 1195ec07232SNate Williams char *file; 1204e115012SGarrett Wollman char *res; 1214e115012SGarrett Wollman char *p; 1224e115012SGarrett Wollman 1235ec07232SNate Williams if ((file = rindex(path, '/')) == NULL) 1245ec07232SNate Williams file = path; 1255ec07232SNate Williams else 1265ec07232SNate Williams file++; 1275ec07232SNate Williams 1284e115012SGarrett Wollman res = alloc(strlen(file) + strlen(ext) + 1); 1294e115012SGarrett Wollman if (res == NULL) { 1304e115012SGarrett Wollman abort(); 1314e115012SGarrett Wollman } 1324e115012SGarrett Wollman p = rindex(file, '.'); 1334e115012SGarrett Wollman if (p == NULL) { 1344e115012SGarrett Wollman p = file + strlen(file); 1354e115012SGarrett Wollman } 1364e115012SGarrett Wollman (void) strcpy(res, file); 1374e115012SGarrett Wollman (void) strcpy(res + (p - file), ext); 1384e115012SGarrett Wollman return (res); 1394e115012SGarrett Wollman } 1404e115012SGarrett Wollman 1414e115012SGarrett Wollman /* 1424e115012SGarrett Wollman * Open output file with given extension 1434e115012SGarrett Wollman */ 1444e115012SGarrett Wollman static 1454e115012SGarrett Wollman open_output(infile, outfile) 1464e115012SGarrett Wollman char *infile; 1474e115012SGarrett Wollman char *outfile; 1484e115012SGarrett Wollman { 1494e115012SGarrett Wollman if (outfile == NULL) { 1504e115012SGarrett Wollman fout = stdout; 1514e115012SGarrett Wollman return; 1524e115012SGarrett Wollman } 1534e115012SGarrett Wollman if (infile != NULL && streq(outfile, infile)) { 1544e115012SGarrett Wollman f_print(stderr, "%s: output would overwrite %s\n", cmdname, 1554e115012SGarrett Wollman infile); 1564e115012SGarrett Wollman crash(); 1574e115012SGarrett Wollman } 1584e115012SGarrett Wollman fout = fopen(outfile, "w"); 1594e115012SGarrett Wollman if (fout == NULL) { 1604e115012SGarrett Wollman f_print(stderr, "%s: unable to open ", cmdname); 1614e115012SGarrett Wollman perror(outfile); 1624e115012SGarrett Wollman crash(); 1634e115012SGarrett Wollman } 1644e115012SGarrett Wollman record_open(outfile); 1654e115012SGarrett Wollman } 1664e115012SGarrett Wollman 1674e115012SGarrett Wollman /* 1684e115012SGarrett Wollman * Open input file with given define for C-preprocessor 1694e115012SGarrett Wollman */ 1704e115012SGarrett Wollman static 1714e115012SGarrett Wollman open_input(infile, define) 1724e115012SGarrett Wollman char *infile; 1734e115012SGarrett Wollman char *define; 1744e115012SGarrett Wollman { 1754e115012SGarrett Wollman int pd[2]; 1764e115012SGarrett Wollman 1774e115012SGarrett Wollman infilename = (infile == NULL) ? "<stdin>" : infile; 1784e115012SGarrett Wollman (void) pipe(pd); 1794e115012SGarrett Wollman switch (fork()) { 1804e115012SGarrett Wollman case 0: 1814e115012SGarrett Wollman (void) close(1); 1824e115012SGarrett Wollman (void) dup2(pd[1], 1); 1834e115012SGarrett Wollman (void) close(pd[0]); 1844e115012SGarrett Wollman execl(CPP, CPP, CPPFLAGS, define, infile, NULL); 1854e115012SGarrett Wollman perror("execl"); 1864e115012SGarrett Wollman exit(1); 1874e115012SGarrett Wollman case -1: 1884e115012SGarrett Wollman perror("fork"); 1894e115012SGarrett Wollman exit(1); 1904e115012SGarrett Wollman } 1914e115012SGarrett Wollman (void) close(pd[1]); 1924e115012SGarrett Wollman fin = fdopen(pd[0], "r"); 1934e115012SGarrett Wollman if (fin == NULL) { 1944e115012SGarrett Wollman f_print(stderr, "%s: ", cmdname); 1954e115012SGarrett Wollman perror(infilename); 1964e115012SGarrett Wollman crash(); 1974e115012SGarrett Wollman } 1984e115012SGarrett Wollman } 1994e115012SGarrett Wollman 2004e115012SGarrett Wollman /* 2014e115012SGarrett Wollman * Compile into an XDR routine output file 2024e115012SGarrett Wollman */ 2034e115012SGarrett Wollman static 2044e115012SGarrett Wollman c_output(infile, define, extend, outfile) 2054e115012SGarrett Wollman char *infile; 2064e115012SGarrett Wollman char *define; 2074e115012SGarrett Wollman int extend; 2084e115012SGarrett Wollman char *outfile; 2094e115012SGarrett Wollman { 2104e115012SGarrett Wollman definition *def; 2114e115012SGarrett Wollman char *include; 2124e115012SGarrett Wollman char *outfilename; 2134e115012SGarrett Wollman long tell; 2144e115012SGarrett Wollman 2154e115012SGarrett Wollman open_input(infile, define); 2164e115012SGarrett Wollman outfilename = extend ? extendfile(infile, outfile) : outfile; 2174e115012SGarrett Wollman open_output(infile, outfilename); 2184e115012SGarrett Wollman f_print(fout, "#include <rpc/rpc.h>\n"); 2194e115012SGarrett Wollman if (infile && (include = extendfile(infile, ".h"))) { 2204e115012SGarrett Wollman f_print(fout, "#include \"%s\"\n", include); 2214e115012SGarrett Wollman free(include); 2224e115012SGarrett Wollman } 2234e115012SGarrett Wollman tell = ftell(fout); 2244e115012SGarrett Wollman while (def = get_definition()) { 2254e115012SGarrett Wollman emit(def); 2264e115012SGarrett Wollman } 2274e115012SGarrett Wollman if (extend && tell == ftell(fout)) { 2284e115012SGarrett Wollman (void) unlink(outfilename); 2294e115012SGarrett Wollman } 2304e115012SGarrett Wollman } 2314e115012SGarrett Wollman 2324e115012SGarrett Wollman /* 2334e115012SGarrett Wollman * Compile into an XDR header file 2344e115012SGarrett Wollman */ 2354e115012SGarrett Wollman static 2364e115012SGarrett Wollman h_output(infile, define, extend, outfile) 2374e115012SGarrett Wollman char *infile; 2384e115012SGarrett Wollman char *define; 2394e115012SGarrett Wollman int extend; 2404e115012SGarrett Wollman char *outfile; 2414e115012SGarrett Wollman { 2424e115012SGarrett Wollman definition *def; 2434e115012SGarrett Wollman char *outfilename; 2444e115012SGarrett Wollman long tell; 2454e115012SGarrett Wollman 2464e115012SGarrett Wollman open_input(infile, define); 2474e115012SGarrett Wollman outfilename = extend ? extendfile(infile, outfile) : outfile; 2484e115012SGarrett Wollman open_output(infile, outfilename); 2494e115012SGarrett Wollman tell = ftell(fout); 2504e115012SGarrett Wollman while (def = get_definition()) { 2514e115012SGarrett Wollman print_datadef(def); 2524e115012SGarrett Wollman } 2534e115012SGarrett Wollman if (extend && tell == ftell(fout)) { 2544e115012SGarrett Wollman (void) unlink(outfilename); 2554e115012SGarrett Wollman } 2564e115012SGarrett Wollman } 2574e115012SGarrett Wollman 2584e115012SGarrett Wollman /* 2594e115012SGarrett Wollman * Compile into an RPC service 2604e115012SGarrett Wollman */ 2614e115012SGarrett Wollman static 2624e115012SGarrett Wollman s_output(argc, argv, infile, define, extend, outfile, nomain) 2634e115012SGarrett Wollman int argc; 2644e115012SGarrett Wollman char *argv[]; 2654e115012SGarrett Wollman char *infile; 2664e115012SGarrett Wollman char *define; 2674e115012SGarrett Wollman int extend; 2684e115012SGarrett Wollman char *outfile; 2694e115012SGarrett Wollman int nomain; 2704e115012SGarrett Wollman { 2714e115012SGarrett Wollman char *include; 2724e115012SGarrett Wollman definition *def; 2734e115012SGarrett Wollman int foundprogram; 2744e115012SGarrett Wollman char *outfilename; 2754e115012SGarrett Wollman 2764e115012SGarrett Wollman open_input(infile, define); 2774e115012SGarrett Wollman outfilename = extend ? extendfile(infile, outfile) : outfile; 2784e115012SGarrett Wollman open_output(infile, outfilename); 2794e115012SGarrett Wollman f_print(fout, "#include <stdio.h>\n"); 2804e115012SGarrett Wollman f_print(fout, "#include <rpc/rpc.h>\n"); 2814e115012SGarrett Wollman if (infile && (include = extendfile(infile, ".h"))) { 2824e115012SGarrett Wollman f_print(fout, "#include \"%s\"\n", include); 2834e115012SGarrett Wollman free(include); 2844e115012SGarrett Wollman } 2854e115012SGarrett Wollman foundprogram = 0; 2864e115012SGarrett Wollman while (def = get_definition()) { 2874e115012SGarrett Wollman foundprogram |= (def->def_kind == DEF_PROGRAM); 2884e115012SGarrett Wollman } 2894e115012SGarrett Wollman if (extend && !foundprogram) { 2904e115012SGarrett Wollman (void) unlink(outfilename); 2914e115012SGarrett Wollman return; 2924e115012SGarrett Wollman } 2934e115012SGarrett Wollman if (nomain) { 2944e115012SGarrett Wollman write_programs((char *)NULL); 2954e115012SGarrett Wollman } else { 2964e115012SGarrett Wollman write_most(); 2974e115012SGarrett Wollman do_registers(argc, argv); 2984e115012SGarrett Wollman write_rest(); 2994e115012SGarrett Wollman write_programs("static"); 3004e115012SGarrett Wollman } 3014e115012SGarrett Wollman } 3024e115012SGarrett Wollman 3034e115012SGarrett Wollman static 3044e115012SGarrett Wollman l_output(infile, define, extend, outfile) 3054e115012SGarrett Wollman char *infile; 3064e115012SGarrett Wollman char *define; 3074e115012SGarrett Wollman int extend; 3084e115012SGarrett Wollman char *outfile; 3094e115012SGarrett Wollman { 3104e115012SGarrett Wollman char *include; 3114e115012SGarrett Wollman definition *def; 3124e115012SGarrett Wollman int foundprogram; 3134e115012SGarrett Wollman char *outfilename; 3144e115012SGarrett Wollman 3154e115012SGarrett Wollman open_input(infile, define); 3164e115012SGarrett Wollman outfilename = extend ? extendfile(infile, outfile) : outfile; 3174e115012SGarrett Wollman open_output(infile, outfilename); 3184e115012SGarrett Wollman f_print(fout, "#include <rpc/rpc.h>\n"); 3194e115012SGarrett Wollman if (infile && (include = extendfile(infile, ".h"))) { 3204e115012SGarrett Wollman f_print(fout, "#include \"%s\"\n", include); 3214e115012SGarrett Wollman free(include); 3224e115012SGarrett Wollman } 3234e115012SGarrett Wollman foundprogram = 0; 3244e115012SGarrett Wollman while (def = get_definition()) { 3254e115012SGarrett Wollman foundprogram |= (def->def_kind == DEF_PROGRAM); 3264e115012SGarrett Wollman } 3274e115012SGarrett Wollman if (extend && !foundprogram) { 3284e115012SGarrett Wollman (void) unlink(outfilename); 3294e115012SGarrett Wollman return; 3304e115012SGarrett Wollman } 3314e115012SGarrett Wollman write_stubs(); 3324e115012SGarrett Wollman } 3334e115012SGarrett Wollman 3344e115012SGarrett Wollman /* 3354e115012SGarrett Wollman * Perform registrations for service output 3364e115012SGarrett Wollman */ 3374e115012SGarrett Wollman static 3384e115012SGarrett Wollman do_registers(argc, argv) 3394e115012SGarrett Wollman int argc; 3404e115012SGarrett Wollman char *argv[]; 3414e115012SGarrett Wollman 3424e115012SGarrett Wollman { 3434e115012SGarrett Wollman int i; 3444e115012SGarrett Wollman 3454e115012SGarrett Wollman for (i = 1; i < argc; i++) { 3464e115012SGarrett Wollman if (streq(argv[i], "-s")) { 3474e115012SGarrett Wollman write_register(argv[i + 1]); 3484e115012SGarrett Wollman i++; 3494e115012SGarrett Wollman } 3504e115012SGarrett Wollman } 3514e115012SGarrett Wollman } 3524e115012SGarrett Wollman 3534e115012SGarrett Wollman /* 3544e115012SGarrett Wollman * Parse command line arguments 3554e115012SGarrett Wollman */ 3564e115012SGarrett Wollman static 3574e115012SGarrett Wollman parseargs(argc, argv, cmd) 3584e115012SGarrett Wollman int argc; 3594e115012SGarrett Wollman char *argv[]; 3604e115012SGarrett Wollman struct commandline *cmd; 3614e115012SGarrett Wollman 3624e115012SGarrett Wollman { 3634e115012SGarrett Wollman int i; 3644e115012SGarrett Wollman int j; 3654e115012SGarrett Wollman char c; 3664e115012SGarrett Wollman char flag[(1 << 8 * sizeof(char))]; 3674e115012SGarrett Wollman int nflags; 3684e115012SGarrett Wollman 3694e115012SGarrett Wollman cmdname = argv[0]; 3704e115012SGarrett Wollman cmd->infile = cmd->outfile = NULL; 3714e115012SGarrett Wollman if (argc < 2) { 3724e115012SGarrett Wollman return (0); 3734e115012SGarrett Wollman } 3744e115012SGarrett Wollman flag['c'] = 0; 3754e115012SGarrett Wollman flag['h'] = 0; 3764e115012SGarrett Wollman flag['s'] = 0; 3774e115012SGarrett Wollman flag['o'] = 0; 3784e115012SGarrett Wollman flag['l'] = 0; 3794e115012SGarrett Wollman flag['m'] = 0; 3804e115012SGarrett Wollman for (i = 1; i < argc; i++) { 3814e115012SGarrett Wollman if (argv[i][0] != '-') { 3824e115012SGarrett Wollman if (cmd->infile) { 3834e115012SGarrett Wollman return (0); 3844e115012SGarrett Wollman } 3854e115012SGarrett Wollman cmd->infile = argv[i]; 3864e115012SGarrett Wollman } else { 3874e115012SGarrett Wollman for (j = 1; argv[i][j] != 0; j++) { 3884e115012SGarrett Wollman c = argv[i][j]; 3894e115012SGarrett Wollman switch (c) { 3904e115012SGarrett Wollman case 'c': 3914e115012SGarrett Wollman case 'h': 3924e115012SGarrett Wollman case 'l': 3934e115012SGarrett Wollman case 'm': 3944e115012SGarrett Wollman if (flag[c]) { 3954e115012SGarrett Wollman return (0); 3964e115012SGarrett Wollman } 3974e115012SGarrett Wollman flag[c] = 1; 3984e115012SGarrett Wollman break; 3994e115012SGarrett Wollman case 'o': 4004e115012SGarrett Wollman case 's': 4014e115012SGarrett Wollman if (argv[i][j - 1] != '-' || 4024e115012SGarrett Wollman argv[i][j + 1] != 0) { 4034e115012SGarrett Wollman return (0); 4044e115012SGarrett Wollman } 4054e115012SGarrett Wollman flag[c] = 1; 4064e115012SGarrett Wollman if (++i == argc) { 4074e115012SGarrett Wollman return (0); 4084e115012SGarrett Wollman } 4094e115012SGarrett Wollman if (c == 's') { 4104e115012SGarrett Wollman if (!streq(argv[i], "udp") && 4114e115012SGarrett Wollman !streq(argv[i], "tcp")) { 4124e115012SGarrett Wollman return (0); 4134e115012SGarrett Wollman } 4144e115012SGarrett Wollman } else if (c == 'o') { 4154e115012SGarrett Wollman if (cmd->outfile) { 4164e115012SGarrett Wollman return (0); 4174e115012SGarrett Wollman } 4184e115012SGarrett Wollman cmd->outfile = argv[i]; 4194e115012SGarrett Wollman } 4204e115012SGarrett Wollman goto nextarg; 4214e115012SGarrett Wollman 4224e115012SGarrett Wollman default: 4234e115012SGarrett Wollman return (0); 4244e115012SGarrett Wollman } 4254e115012SGarrett Wollman } 4264e115012SGarrett Wollman nextarg: 4274e115012SGarrett Wollman ; 4284e115012SGarrett Wollman } 4294e115012SGarrett Wollman } 4304e115012SGarrett Wollman cmd->cflag = flag['c']; 4314e115012SGarrett Wollman cmd->hflag = flag['h']; 4324e115012SGarrett Wollman cmd->sflag = flag['s']; 4334e115012SGarrett Wollman cmd->lflag = flag['l']; 4344e115012SGarrett Wollman cmd->mflag = flag['m']; 4354e115012SGarrett Wollman nflags = cmd->cflag + cmd->hflag + cmd->sflag + cmd->lflag + cmd->mflag; 4364e115012SGarrett Wollman if (nflags == 0) { 4374e115012SGarrett Wollman if (cmd->outfile != NULL || cmd->infile == NULL) { 4384e115012SGarrett Wollman return (0); 4394e115012SGarrett Wollman } 4404e115012SGarrett Wollman } else if (nflags > 1) { 4414e115012SGarrett Wollman return (0); 4424e115012SGarrett Wollman } 4434e115012SGarrett Wollman return (1); 4444e115012SGarrett Wollman } 445