/*
* From @(#)rpc_main.c 1.30 89/03/30 (C) 1987 SMI;
*/
-const char main_rcsid[] =
- "$Id$";
/*
* rpc_main.c, Top level of the RPC protocol compiler.
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+#include <libintl.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/param.h>
#define SUNOS_CPP "/lib/cpp"
static const char *svcclosetime = "120";
-static int cppDefined = 0; /* explicit path for C preprocessor */
+static int cppDefined; /* explicit path for C preprocessor */
static const char *CPP = SUNOS_CPP;
-static char CPPFLAGS[] = "-C";
+static const char CPPFLAGS[] = "-C";
static char *pathbuf;
static int cpp_pid;
static const char *allv[] =
{
- "rpcgen", "-s", "udp", "-s", "tcp",
+ "rpcgen", "-s", "udp", "-s", "tcp"
};
static int allc = sizeof (allv) / sizeof (allv[0]);
static const char *allnv[] =
static void putarg (int whereto, const char *cp);
static void checkfiles (const char *infile, const char *outfile);
static int parseargs (int argc, const char *argv[], struct commandline *cmd);
-static void usage (void);
-static void options_usage (void);
+static void usage (void) __attribute__ ((noreturn));
+static void options_usage (void) __attribute__ ((noreturn));
static void c_initialize (void);
static char *generate_guard (const char *pathname);
#ifdef __GNU_LIBRARY__
int Cflag = 1; /* ANSI C syntax */
#else
-int Cflag = 0; /* ANSI C/C++ syntax */
+int Cflag; /* ANSI C/C++ syntax */
#endif
-int CCflag = 0; /* C++ files */
+int CCflag; /* C++ files */
static int allfiles; /* generate all files */
#ifdef __GNU_LIBRARY__
-int tirpcflag = 0; /* generating code for tirpc, by default */
+int tirpcflag; /* generating code for tirpc, by default */
#else
int tirpcflag = 1; /* generating code for tirpc, by default */
#endif
-xdrfunc *xdrfunc_head = NULL; /* xdr function list */
-xdrfunc *xdrfunc_tail = NULL; /* xdr function list */
+xdrfunc *xdrfunc_head; /* xdr function list */
+xdrfunc *xdrfunc_tail; /* xdr function list */
int
main (int argc, const char *argv[])
mkfile_output (&cmd);
}
}
- exit (nonfatalerrors);
- /* NOTREACHED */
+
+ return nonfatalerrors;
}
/*
fout = fopen (outfile, "w");
if (fout == NULL)
{
- fprintf (stderr, _ ("%s: unable to open "), cmdname);
- perror (outfile);
+ fprintf (stderr, _ ("%s: unable to open %s: %m\n"), cmdname, outfile);
crash ();
}
record_open (outfile);
{
if (fclose (fout) == EOF)
{
- fprintf (stderr, _("%s: while writing output: "), cmdname);
- perror (outfile ?: "<stdout>");
+ fprintf (stderr, _("%s: while writing output %s: %m"), cmdname,
+ outfile ?: "<stdout>");
crash ();
}
}
return 1;
}
}
- fprintf (stderr, _ ("illegal nettype :\'%s\'\n"), name);
+ fprintf (stderr, _ ("illegal nettype :`%s'\n"), name);
return 0;
}
filename = strrchr (pathname, '/'); /* find last component */
filename = ((filename == NULL) ? pathname : filename + 1);
- guard = strdup (filename);
+ guard = extendfile (filename, "_H_RPCGEN");
/* convert to upper case */
tmp = guard;
while (*tmp)
tmp++;
}
- guard = extendfile (guard, "_H_RPCGEN");
return guard;
}
}
fprintf (fout, "\n#endif /* !_%s */\n", guard);
+ free (guard);
close_input ();
close_output (outfilename);
}
fprintf (fout, "#include <stdio.h>\n");
fprintf (fout, "#include <stdlib.h>\n");
+ fprintf (fout, "#include <rpc/pmap_clnt.h>\n");
if (Cflag)
- {
- fprintf (fout, "#include <rpc/pmap_clnt.h>\n");
- fprintf (fout, "#include <string.h>\n");
- }
+ fprintf (fout, "#include <string.h>\n");
if (strcmp (svcclosetime, "-1") == 0)
indefinitewait = 1;
else if (strcmp (svcclosetime, "0") == 0)
close_output (outfilename);
}
+static const char space[] = " ";
+
static char *
file_name (const char *file, const char *ext)
{
if (access (temp, F_OK) != -1)
return (temp);
- else
- return ((char *) " ");
+
+ free (temp);
+ return (char *) space;
}
static void
mkfile_output (struct commandline *cmd)
{
char *mkfilename;
- const char *clientname, *clntname, *xdrname, *hdrname;
- const char *servername, *svcname, *servprogname, *clntprogname;
- char *temp;
+ char *clientname, *clntname, *xdrname, *hdrname;
+ char *servername, *svcname, *servprogname, *clntprogname;
svcname = file_name (cmd->infile, "_svc.c");
clntname = file_name (cmd->infile, "_clnt.c");
}
else
{
- servername = " ";
- clientname = " ";
+ servername = (char *) space;
+ clientname = (char *) space;
}
servprogname = extendfile (cmd->infile, "_server");
clntprogname = extendfile (cmd->infile, "_client");
if (allfiles)
{
- mkfilename = alloc (strlen ("Makefile.") +
- strlen (cmd->infile) + 1);
- temp = (char *) rindex (cmd->infile, '.');
- strcat (mkfilename, "Makefile.");
- strncat (mkfilename, cmd->infile,
- (temp - cmd->infile));
+ char *cp, *temp;
+
+ mkfilename = alloc (strlen ("Makefile.") + strlen (cmd->infile) + 1);
+ if (mkfilename == NULL)
+ abort ();
+ temp = rindex (cmd->infile, '.');
+ cp = stpcpy (mkfilename, "Makefile.");
+ strncpy (cp, cmd->infile, (temp - cmd->infile));
}
else
mkfilename = (char *) cmd->outfile;
f_print (fout, "clean:\n\t $(RM) core $(TARGETS) $(OBJECTS_CLNT) \
$(OBJECTS_SVC) $(CLIENT) $(SERVER)\n\n");
close_output (mkfilename);
+
+ free (clntprogname);
+ free (servprogname);
+ if (servername != space)
+ free (servername);
+ if (clientname != space)
+ free (clientname);
+ if (mkfilename != (char *) cmd->outfile)
+ free (mkfilename);
+ if (svcname != space)
+ free (svcname);
+ if (clntname != space)
+ free (clntname);
+ if (xdrname != space)
+ free (xdrname);
+ if (hdrname != space)
+ free (hdrname);
}
/*
else
{
fprintf (stderr,
- _("file '%s' already exists and may be overwritten\n"),
+ /* TRANS: the file will not be removed; this is an
+ TRANS: informative message. */
+ _("file `%s' already exists and may be overwritten\n"),
outfile);
crash ();
}
cmd->Scflag = flag['C'];
cmd->makefileflag = flag['M'];
+#ifndef _RPC_THREAD_SAFE_
+ if (mtflag || newstyle)
+ {
+ /* glibc doesn't support these flags. */
+ f_print (stderr,
+ _("This implementation doesn't support newstyle or MT-safe code!\n"));
+ return (0);
+ }
+#endif
if (tirpcflag)
{
pmflag = inetdflag ? 0 : 1; /* pmflag or inetdflag is always TRUE */
static void
usage (void)
{
- fprintf (stderr, _("usage: %s infile\n"), cmdname);
+ fprintf (stderr, _("usage: %s infile\n"), cmdname);
fprintf (stderr, _("\t%s [-abkCLNTM][-Dname[=value]] [-i size] \
[-I [-K seconds]] [-Y path] infile\n"), cmdname);
fprintf (stderr, _("\t%s [-c | -h | -l | -m | -t | -Sc | -Ss | -Sm] \