/* @(#)rpc_main.c 2.2 88/08/01 4.0 RPCSRC */
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
* unrestricted use provided that this legend is included on all tape
* media and as a part of the software program in whole or part. Users
* may copy or modify Sun RPC without charge, but are not authorized
* to license or distribute it to anyone else except as part of a product or
* program developed by the user.
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
* Sun RPC is provided with no support and without any obligation on the
* part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
* Mountain View, California 94043
static char sccsid
[] = "@(#)rpc_main.c 1.7 87/06/24 (C) 1987 SMI";
* rpc_main.c, Top level of the RPC protocol compiler.
* Copyright (C) 1987, Sun Microsystems, Inc.
#define EXTEND 1 /* alias for TRUE */
static char CPP
[] = "/lib/cpp";
static char CPPFLAGS
[] = "-C";
"rpcgen", "-s", "udp", "-s", "tcp",
static int allc
= sizeof(allv
)/sizeof(allv
[0]);
if (!parseargs(argc
, argv
, &cmd
)) {
"usage: %s infile\n", cmdname
);
" %s [-c | -h | -l | -m] [-o outfile] [infile]\n",
" %s [-s udp|tcp]* [-o outfile] [infile]\n",
c_output(cmd
.infile
, "-DRPC_XDR", !EXTEND
, cmd
.outfile
);
h_output(cmd
.infile
, "-DRPC_HDR", !EXTEND
, cmd
.outfile
);
l_output(cmd
.infile
, "-DRPC_CLNT", !EXTEND
, cmd
.outfile
);
} else if (cmd
.sflag
|| cmd
.mflag
) {
s_output(argc
, argv
, cmd
.infile
, "-DRPC_SVC", !EXTEND
,
c_output(cmd
.infile
, "-DRPC_XDR", EXTEND
, "_xdr.c");
h_output(cmd
.infile
, "-DRPC_HDR", EXTEND
, ".h");
l_output(cmd
.infile
, "-DRPC_CLNT", EXTEND
, "_clnt.c");
s_output(allc
, allv
, cmd
.infile
, "-DRPC_SVC", EXTEND
,
* add extension to filename
res
= alloc(strlen(file
) + strlen(ext
) + 1);
(void) strcpy(res
, file
);
(void) strcpy(res
+ (p
- file
), ext
);
* Open output file with given extension
open_output(infile
, outfile
)
if (infile
!= NULL
&& streq(outfile
, infile
)) {
f_print(stderr
, "%s: output would overwrite %s\n", cmdname
,
fout
= fopen(outfile
, "w");
f_print(stderr
, "%s: unable to open ", cmdname
);
* Open input file with given define for C-preprocessor
open_input(infile
, define
)
infilename
= (infile
== NULL
) ? "<stdin>" : infile
;
execl(CPP
, CPP
, CPPFLAGS
, define
, infile
, NULL
);
fin
= fdopen(pd
[0], "r");
f_print(stderr
, "%s: ", cmdname
);
* Compile into an XDR routine output file
c_output(infile
, define
, extend
, outfile
)
open_input(infile
, define
);
outfilename
= extend
? extendfile(infile
, outfile
) : outfile
;
open_output(infile
, outfilename
);
f_print(fout
, "#include <rpc/rpc.h>\n");
if (infile
&& (include
= extendfile(infile
, ".h"))) {
f_print(fout
, "#include \"%s\"\n", include
);
while (def
= get_definition()) {
if (extend
&& tell
== ftell(fout
)) {
(void) unlink(outfilename
);
* Compile into an XDR header file
h_output(infile
, define
, extend
, outfile
)
open_input(infile
, define
);
outfilename
= extend
? extendfile(infile
, outfile
) : outfile
;
open_output(infile
, outfilename
);
while (def
= get_definition()) {
if (extend
&& tell
== ftell(fout
)) {
(void) unlink(outfilename
);
* Compile into an RPC service
s_output(argc
, argv
, infile
, define
, extend
, outfile
, nomain
)
open_input(infile
, define
);
outfilename
= extend
? extendfile(infile
, outfile
) : outfile
;
open_output(infile
, outfilename
);
f_print(fout
, "#include <stdio.h>\n");
f_print(fout
, "#include <rpc/rpc.h>\n");
if (infile
&& (include
= extendfile(infile
, ".h"))) {
f_print(fout
, "#include \"%s\"\n", include
);
while (def
= get_definition()) {
foundprogram
|= (def
->def_kind
== DEF_PROGRAM
);
if (extend
&& !foundprogram
) {
(void) unlink(outfilename
);
write_programs((char *)NULL
);
do_registers(argc
, argv
);
write_programs("static");
l_output(infile
, define
, extend
, outfile
)
open_input(infile
, define
);
outfilename
= extend
? extendfile(infile
, outfile
) : outfile
;
open_output(infile
, outfilename
);
f_print(fout
, "#include <rpc/rpc.h>\n");
if (infile
&& (include
= extendfile(infile
, ".h"))) {
f_print(fout
, "#include \"%s\"\n", include
);
while (def
= get_definition()) {
foundprogram
|= (def
->def_kind
== DEF_PROGRAM
);
if (extend
&& !foundprogram
) {
(void) unlink(outfilename
);
* Perform registrations for service output
for (i
= 1; i
< argc
; i
++) {
if (streq(argv
[i
], "-s")) {
write_register(argv
[i
+ 1]);
* Parse command line arguments
parseargs(argc
, argv
, cmd
)
char flag
[(1 << 8 * sizeof(char))];
cmd
->infile
= cmd
->outfile
= NULL
;
for (i
= 1; i
< argc
; i
++) {
for (j
= 1; argv
[i
][j
] != 0; j
++) {
if (argv
[i
][j
- 1] != '-' ||
if (!streq(argv
[i
], "udp") &&
!streq(argv
[i
], "tcp")) {
nflags
= cmd
->cflag
+ cmd
->hflag
+ cmd
->sflag
+ cmd
->lflag
+ cmd
->mflag
;
if (cmd
->outfile
!= NULL
|| cmd
->infile
== NULL
) {