version 1.14, 2002/06/01 01:40:38 |
version 1.15, 2002/07/05 05:39:42 |
|
|
|
|
#define RPCGEN_VERSION "199506"/* This program's version (year & month) */ |
#define RPCGEN_VERSION "199506"/* This program's version (year & month) */ |
|
|
#include <stdio.h> |
|
#include <stdlib.h> |
|
#include <string.h> |
|
#include <sys/types.h> |
#include <sys/types.h> |
#ifdef __TURBOC__ |
|
#define MAXPATHLEN 80 |
|
#include <process.h> |
|
#include <dir.h> |
|
#else |
|
#include <sys/param.h> |
#include <sys/param.h> |
#include <sys/file.h> |
#include <sys/file.h> |
#endif |
#include <stdio.h> |
|
#include <stdlib.h> |
|
#include <string.h> |
|
#include <unistd.h> |
|
#include <stdlib.h> |
|
#include <ctype.h> |
#include <sys/stat.h> |
#include <sys/stat.h> |
#include "rpc_parse.h" |
#include "rpc_parse.h" |
#include "rpc_util.h" |
#include "rpc_util.h" |
|
|
static char *dos_cppfile = NULL; |
static char *dos_cppfile = NULL; |
#endif |
#endif |
|
|
static c_output(char *, char *, int, char *); |
static void c_output(char *, char *, int, char *); |
static h_output(char *, char *, int, char *); |
static void h_output(char *, char *, int, char *); |
static s_output(int, char **, char *, char *, int, char *, int, int); |
static void s_output(int, char **, char *, char *, int, char *, int, int); |
static l_output(char *, char *, int, char *); |
static void l_output(char *, char *, int, char *); |
static t_output(char *, char *, int, char *); |
static void t_output(char *, char *, int, char *); |
static svc_output(char *, char *, int, char *); |
static void svc_output(char *, char *, int, char *); |
static clnt_output(char *, char *, int, char *); |
static void clnt_output(char *, char *, int, char *); |
static do_registers(int, char **); |
static int do_registers(int, char **); |
static void addarg(char *); |
static void addarg(char *); |
static void putarg(int, char *); |
static void putarg(int, char *); |
static void clear_args(void); |
static void clear_args(void); |
static void checkfiles(char *, char *); |
static void checkfiles(char *, char *); |
static int parseargs(int, char **, struct commandline *); |
static int parseargs(int, char **, struct commandline *); |
static usage(void); |
static void usage(void); |
|
void c_initialize(void); |
|
|
|
|
int |
int |
main(argc, argv) |
main(argc, argv) |
int argc; |
int argc; |
|
|
file++; |
file++; |
|
|
res = alloc(strlen(file) + strlen(ext) + 1); |
res = alloc(strlen(file) + strlen(ext) + 1); |
if (res == NULL) |
if (res == NULL) { |
abort(); |
fprintf(stderr, "could not allocate memory\n"); |
|
exit(1); |
|
} |
p = strrchr(file, '.'); |
p = strrchr(file, '.'); |
if (p == NULL) |
if (p == NULL) |
p = file + strlen(file); |
p = file + strlen(file); |
|
|
|
|
} |
} |
|
|
static |
static void |
add_warning() |
add_warning() |
{ |
{ |
fprintf(fout, "/*\n"); |
fprintf(fout, "/*\n"); |
|
|
} |
} |
|
|
/* clear list of arguments */ |
/* clear list of arguments */ |
static void |
static void |
clear_args() |
clear_args() |
{ |
{ |
int i; |
int i; |
|
|
} |
} |
|
|
/* make sure that a CPP exists */ |
/* make sure that a CPP exists */ |
static void |
static void |
find_cpp() |
find_cpp() |
{ |
{ |
struct stat buf; |
struct stat buf; |
|
|
/* |
/* |
* Open input file with given define for C-preprocessor |
* Open input file with given define for C-preprocessor |
*/ |
*/ |
static |
static void |
open_input(infile, define) |
open_input(infile, define) |
char *infile; |
char *infile; |
char *define; |
char *define; |
|
|
NULL |
NULL |
}; |
}; |
|
|
static int |
static int |
check_nettype(name, list_to_check) |
check_nettype(name, list_to_check) |
char *name; |
char *name; |
char *list_to_check[]; |
char *list_to_check[]; |
|
|
* Compile into an XDR routine output file |
* Compile into an XDR routine output file |
*/ |
*/ |
|
|
static |
static void |
c_output(infile, define, extend, outfile) |
c_output(infile, define, extend, outfile) |
char *infile; |
char *infile; |
char *define; |
char *define; |
|
|
} else |
} else |
fprintf(fout, "#include <rpc/rpc.h>\n"); |
fprintf(fout, "#include <rpc/rpc.h>\n"); |
tell = ftell(fout); |
tell = ftell(fout); |
while (def = get_definition()) { |
while ((def = get_definition())) { |
emit(def); |
emit(def); |
} |
} |
if (extend && tell == ftell(fout)) { |
if (extend && tell == ftell(fout)) { |
|
|
} |
} |
|
|
|
|
c_initialize() |
void |
|
c_initialize(void) |
{ |
{ |
|
|
/* add all the starting basic types */ |
/* add all the starting basic types */ |
|
|
};\n"; |
};\n"; |
|
|
|
|
char * |
char * |
generate_guard(pathname) |
generate_guard(pathname) |
char *pathname; |
char *pathname; |
{ |
{ |
|
|
filename = strrchr(pathname, '/'); /* find last component */ |
filename = strrchr(pathname, '/'); /* find last component */ |
filename = ((filename == 0) ? pathname : filename + 1); |
filename = ((filename == 0) ? pathname : filename + 1); |
guard = strdup(filename); |
guard = strdup(filename); |
|
if (guard == NULL) { |
|
fprintf(stderr, "out of memory while processing %s\n", filename); |
|
crash(); |
|
} |
|
|
/* convert to upper case */ |
/* convert to upper case */ |
tmp = guard; |
tmp = guard; |
while (*tmp) { |
while (*tmp) { |
|
|
* Compile into an XDR header file |
* Compile into an XDR header file |
*/ |
*/ |
|
|
static |
static void |
h_output(infile, define, extend, outfile) |
h_output(infile, define, extend, outfile) |
char *infile; |
char *infile; |
char *define; |
char *define; |
|
|
|
|
tell = ftell(fout); |
tell = ftell(fout); |
/* print data definitions */ |
/* print data definitions */ |
while (def = get_definition()) { |
while ((def = get_definition())) { |
print_datadef(def); |
print_datadef(def); |
} |
} |
|
|
|
|
/* |
/* |
* Compile into an RPC service |
* Compile into an RPC service |
*/ |
*/ |
static |
static void |
s_output(argc, argv, infile, define, extend, outfile, nomain, netflag) |
s_output(argc, argv, infile, define, extend, outfile, nomain, netflag) |
int argc; |
int argc; |
char *argv[]; |
char *argv[]; |
|
|
if ((netflag || pmflag) && tirpcflag) { |
if ((netflag || pmflag) && tirpcflag) { |
fprintf(fout, "#include <netconfig.h>\n"); |
fprintf(fout, "#include <netconfig.h>\n"); |
} |
} |
if ( /* timerflag && */ tirpcflag) |
if (/* timerflag && */ tirpcflag) |
fprintf(fout, "#include <sys/resource.h> /* rlimit */\n"); |
fprintf(fout, "#include <sys/resource.h> /* rlimit */\n"); |
if (logflag || inetdflag || pmflag) { |
if (logflag || inetdflag || pmflag) { |
fprintf(fout, "#include <syslog.h>\n"); |
fprintf(fout, "#include <syslog.h>\n"); |
|
|
fprintf(fout, "\n#ifdef DEBUG\n#define RPC_SVC_FG\n#endif\n"); |
fprintf(fout, "\n#ifdef DEBUG\n#define RPC_SVC_FG\n#endif\n"); |
if (timerflag) |
if (timerflag) |
fprintf(fout, "\n#define _RPCSVC_CLOSEDOWN %s\n", svcclosetime); |
fprintf(fout, "\n#define _RPCSVC_CLOSEDOWN %s\n", svcclosetime); |
while (def = get_definition()) { |
while ((def = get_definition())) { |
foundprogram |= (def->def_kind == DEF_PROGRAM); |
foundprogram |= (def->def_kind == DEF_PROGRAM); |
} |
} |
if (extend && !foundprogram) { |
if (extend && !foundprogram) { |
|
|
/* |
/* |
* generate client side stubs |
* generate client side stubs |
*/ |
*/ |
static |
static void |
l_output(infile, define, extend, outfile) |
l_output(infile, define, extend, outfile) |
char *infile; |
char *infile; |
char *define; |
char *define; |
|
|
free(include); |
free(include); |
} else |
} else |
fprintf(fout, "#include <rpc/rpc.h>\n"); |
fprintf(fout, "#include <rpc/rpc.h>\n"); |
while (def = get_definition()) |
while ((def = get_definition())) |
foundprogram |= (def->def_kind == DEF_PROGRAM); |
foundprogram |= (def->def_kind == DEF_PROGRAM); |
|
|
if (extend && !foundprogram) { |
if (extend && !foundprogram) { |
|
|
/* |
/* |
* generate the dispatch table |
* generate the dispatch table |
*/ |
*/ |
static |
static void |
t_output(infile, define, extend, outfile) |
t_output(infile, define, extend, outfile) |
char *infile; |
char *infile; |
char *define; |
char *define; |
|
|
outfilename = extend ? extendfile(infile, outfile) : outfile; |
outfilename = extend ? extendfile(infile, outfile) : outfile; |
open_output(infile, outfilename); |
open_output(infile, outfilename); |
add_warning(); |
add_warning(); |
while (def = get_definition()) |
while ((def = get_definition())) |
foundprogram |= (def->def_kind == DEF_PROGRAM); |
foundprogram |= (def->def_kind == DEF_PROGRAM); |
|
|
if (extend && !foundprogram) { |
if (extend && !foundprogram) { |
|
|
} |
} |
|
|
/* sample routine for the server template */ |
/* sample routine for the server template */ |
static |
static void |
svc_output(infile, define, extend, outfile) |
svc_output(infile, define, extend, outfile) |
char *infile; |
char *infile; |
char *define; |
char *define; |
|
|
fprintf(fout, "#include <rpc/rpc.h>\n"); |
fprintf(fout, "#include <rpc/rpc.h>\n"); |
|
|
tell = ftell(fout); |
tell = ftell(fout); |
while (def = get_definition()) |
while ((def = get_definition())) |
write_sample_svc(def); |
write_sample_svc(def); |
|
|
if (extend && tell == ftell(fout)) |
if (extend && tell == ftell(fout)) |
|
|
|
|
|
|
/* sample main routine for client */ |
/* sample main routine for client */ |
static |
static void |
clnt_output(infile, define, extend, outfile) |
clnt_output(infile, define, extend, outfile) |
char *infile; |
char *infile; |
char *define; |
char *define; |
|
|
} else |
} else |
fprintf(fout, "#include <rpc/rpc.h>\n"); |
fprintf(fout, "#include <rpc/rpc.h>\n"); |
tell = ftell(fout); |
tell = ftell(fout); |
while (def = get_definition()) |
while ((def = get_definition())) |
has_program += write_sample_clnt(def); |
has_program += write_sample_clnt(def); |
|
|
if (has_program) |
if (has_program) |
|
|
* Perform registrations for service output |
* Perform registrations for service output |
* Return 0 if failed; 1 otherwise. |
* Return 0 if failed; 1 otherwise. |
*/ |
*/ |
static |
static int |
int |
|
do_registers(argc, argv) |
do_registers(argc, argv) |
int argc; |
int argc; |
char *argv[]; |
char *argv[]; |
|
|
case 'l': |
case 'l': |
case 'm': |
case 'm': |
case 't': |
case 't': |
if (flag[c]) |
if (flag[(unsigned char)c]) |
return (0); |
return (0); |
flag[c] = 1; |
flag[(unsigned char)c] = 1; |
break; |
break; |
case 'S': |
case 'S': |
/* |
/* |
|
|
else |
else |
return (0); |
return (0); |
|
|
if (flag[c]) |
if (flag[(unsigned char)c]) |
return (0); |
return (0); |
flag[c] = 1; |
flag[(unsigned char)c] = 1; |
break; |
break; |
case 'C': /* ANSI C syntax */ |
case 'C': /* ANSI C syntax */ |
Cflag = 1; |
Cflag = 1; |
|
|
if (argv[i][j - 1] != '-' || |
if (argv[i][j - 1] != '-' || |
argv[i][j + 1] != 0) |
argv[i][j + 1] != 0) |
return (0); |
return (0); |
flag[c] = 1; |
flag[(unsigned char)c] = 1; |
if (++i == argc) |
if (++i == argc) |
return (0); |
return (0); |
if (c == 's') { |
if (c == 's') { |
|
|
return (1); |
return (1); |
} |
} |
|
|
static |
static void |
usage() |
usage(void) |
{ |
{ |
fprintf(stderr, "usage: %s [-abACILNT] [-Dname[=value]] [-i lines] " |
fprintf(stderr, "usage: %s [-abACILNT] [-Dname[=value]] [-i lines] " |
"[-K seconds] infile\n", cmdname); |
"[-K seconds] infile\n", cmdname); |