Return to BSD News archive
Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!bunyip.cc.uq.oz.au!munnari.oz.au!constellation!convex!convex!news.duke.edu!news-feed-1.peachnet.edu!gatech!howland.reston.ans.net!EU.net!Germany.EU.net!netmbx.de!zrz.TU-Berlin.DE!cs.tu-berlin.de!klier From: klier@cs.tu-berlin.de (Jan Klier) Newsgroups: comp.os.386bsd.development Subject: Patch for rpcgen: adding the -D option Date: 23 May 1994 05:33:29 GMT Organization: Technical University of Berlin, Germany Lines: 224 Message-ID: <2rpf79$ino@news.cs.tu-berlin.de> NNTP-Posting-Host: jet.cs.tu-berlin.de Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Summary: Making rpcgen compatible to Sun: pass -D option to cpp Keywords: RPCGEN PATCH Following is a patch to the rpcgen compiler shipped with FreeBSD-1.1-R. The rpcgen compiler puts every input thru the preprocessor and thus also accepts all preprocessor directives in the input (as described in the man page). The version shipped with FreeBSD lacks the possibility to use some of the preprocessor commandline options and pass them on to the preprocessor, particularly the -D option, which is often used within makefiles to configure the source files. Such a possibility is available in the rpcgen versions that are currently shipped with sun workstations, making it difficult to port some software developed on a sun to FreeBSD. The patch below adds the -D option to the rpcgen compiler and passes it to the commandline of the preprocessor. The patched file is /usr/src/usr.bin/rpcgen/rpc_main.c. jan *************************************************************************** --- rpc_main.c.orig Sun May 22 17:23:24 1994 +++ rpc_main.c Sun May 22 19:04:48 1994 @@ -54,6 +54,8 @@ int mflag; char *infile; char *outfile; + int ndefs; + char **defs; }; static char *cmdname; @@ -87,22 +89,22 @@ exit(1); } if (cmd.cflag) { - c_output(cmd.infile, "-DRPC_XDR", !EXTEND, cmd.outfile); + c_output(cmd.infile, "-DRPC_XDR", cmd.ndefs, cmd.defs, !EXTEND, cmd.outfile); } else if (cmd.hflag) { - h_output(cmd.infile, "-DRPC_HDR", !EXTEND, cmd.outfile); + h_output(cmd.infile, "-DRPC_HDR", cmd.ndefs, cmd.defs, !EXTEND, cmd.outfile); } else if (cmd.lflag) { - l_output(cmd.infile, "-DRPC_CLNT", !EXTEND, cmd.outfile); + l_output(cmd.infile, "-DRPC_CLNT", cmd.ndefs, cmd.defs, !EXTEND, cmd.outfile); } else if (cmd.sflag || cmd.mflag) { - s_output(argc, argv, cmd.infile, "-DRPC_SVC", !EXTEND, + s_output(argc, argv, cmd.infile, "-DRPC_SVC", cmd.ndefs, cmd.defs, !EXTEND, cmd.outfile, cmd.mflag); } else { - c_output(cmd.infile, "-DRPC_XDR", EXTEND, "_xdr.c"); + c_output(cmd.infile, "-DRPC_XDR", cmd.ndefs, cmd.defs, EXTEND, "_xdr.c"); reinitialize(); - h_output(cmd.infile, "-DRPC_HDR", EXTEND, ".h"); + h_output(cmd.infile, "-DRPC_HDR", cmd.ndefs, cmd.defs, EXTEND, ".h"); reinitialize(); - l_output(cmd.infile, "-DRPC_CLNT", EXTEND, "_clnt.c"); + l_output(cmd.infile, "-DRPC_CLNT", cmd.ndefs, cmd.defs, EXTEND, "_clnt.c"); reinitialize(); - s_output(allc, allv, cmd.infile, "-DRPC_SVC", EXTEND, + s_output(allc, allv, cmd.infile, "-DRPC_SVC", cmd.ndefs, cmd.defs, EXTEND, "_svc.c", cmd.mflag); } exit(0); @@ -162,11 +164,15 @@ * Open input file with given define for C-preprocessor */ static -open_input(infile, define) +open_input(infile, define, ndefs, defs) char *infile; char *define; + int ndefs; + char **defs; { - int pd[2]; + int pd[2]; + char** argv; + int i; infilename = (infile == NULL) ? "<stdin>" : infile; (void) pipe(pd); @@ -175,7 +181,17 @@ (void) close(1); (void) dup2(pd[1], 1); (void) close(pd[0]); - execl(CPP, CPP, CPPFLAGS, define, infile, NULL); + + argv = (char**) malloc((ndefs + 5) * sizeof(char*)); + argv[0] = CPP; + argv[1] = CPPFLAGS; + argv[2] = define; + for(i=0;i<ndefs;i++) + argv[i+3] = defs[i]; + argv[i+3] = infilename; + argv[i+4] = NULL; + + execv(CPP, argv); perror("execl"); exit(1); case -1: @@ -195,9 +211,11 @@ * Compile into an XDR routine output file */ static -c_output(infile, define, extend, outfile) +c_output(infile, define, ndefs, defs, extend, outfile) char *infile; char *define; + int ndefs; + char **defs; int extend; char *outfile; { @@ -206,7 +224,7 @@ char *outfilename; long tell; - open_input(infile, define); + open_input(infile, define, ndefs, defs); outfilename = extend ? extendfile(infile, outfile) : outfile; open_output(infile, outfilename); f_print(fout, "#include <rpc/rpc.h>\n"); @@ -227,9 +245,11 @@ * Compile into an XDR header file */ static -h_output(infile, define, extend, outfile) +h_output(infile, define, ndefs, defs, extend, outfile) char *infile; char *define; + int ndefs; + char **defs; int extend; char *outfile; { @@ -237,7 +257,7 @@ char *outfilename; long tell; - open_input(infile, define); + open_input(infile, define, ndefs, defs); outfilename = extend ? extendfile(infile, outfile) : outfile; open_output(infile, outfilename); tell = ftell(fout); @@ -253,11 +273,13 @@ * Compile into an RPC service */ static -s_output(argc, argv, infile, define, extend, outfile, nomain) +s_output(argc, argv, infile, define, ndefs, defs, extend, outfile, nomain) int argc; char *argv[]; char *infile; char *define; + int ndefs; + char **defs; int extend; char *outfile; int nomain; @@ -267,7 +289,7 @@ int foundprogram; char *outfilename; - open_input(infile, define); + open_input(infile, define, ndefs, defs); outfilename = extend ? extendfile(infile, outfile) : outfile; open_output(infile, outfilename); f_print(fout, "#include <stdio.h>\n"); @@ -295,9 +317,11 @@ } static -l_output(infile, define, extend, outfile) +l_output(infile, define, ndefs, defs, extend, outfile) char *infile; char *define; + int ndefs; + char **defs; int extend; char *outfile; { @@ -306,7 +330,7 @@ int foundprogram; char *outfilename; - open_input(infile, define); + open_input(infile, define, ndefs, defs); outfilename = extend ? extendfile(infile, outfile) : outfile; open_output(infile, outfilename); f_print(fout, "#include <rpc/rpc.h>\n"); @@ -361,6 +385,8 @@ int nflags; cmdname = argv[0]; + cmd->ndefs = 0; + cmd->defs = NULL; cmd->infile = cmd->outfile = NULL; if (argc < 2) { return (0); @@ -390,6 +416,21 @@ } flag[c] = 1; break; + + case 'D': + if (argv[i][j - 1] != '-' || + argv[i][j + 1] == 0) { + return (0); + } + if (cmd->ndefs == 0) + cmd->defs = (char**) malloc(sizeof(char*)*10); + else if (cmd->ndefs % 10 == 0) + cmd->defs = (char**) realloc(cmd->defs, + (cmd->ndefs + 10) * sizeof(char*)); + cmd->defs[cmd->ndefs] = strdup(argv[i]); + cmd->ndefs++; + goto nextarg; + case 'o': case 's': if (argv[i][j - 1] != '-' || -- *********** Freedom is inversely proportional to security ****************** Jan Klier Berlin, Germany e-mail: klier@cs.tu-berlin.de CIS: 100022,1700 Jan.Klier@ipk.fhg.de 100022.1700@compuserve.com