Back to index

glibc  2.9
Classes | Defines | Functions | Variables
rpc_main.c File Reference
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <libintl.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include "rpc_parse.h"
#include "rpc_util.h"
#include "rpc_scan.h"
#include "proto.h"

Go to the source code of this file.

Classes

struct  commandline

Defines

#define EXTEND   1 /* alias for TRUE */
#define DONT_EXTEND   0 /* alias for FALSE */
#define SVR4_CPP   "/usr/ccs/lib/cpp"
#define SUNOS_CPP   "/lib/cpp"
#define ARGLISTLEN   20
#define FIXEDARGS   2
#define INLINE   3

Functions

static void addarg (const char *)
static void putarg (int, const char *)
static void clear_args (void)
static void checkfiles (const char *, const char *)
static char * extendfile (const char *file, const char *ext)
static void open_output (const char *infile, const char *outfile)
static void add_warning (void)
static void find_cpp (void)
static void open_input (const char *infile, const char *define)
static int check_nettype (const char *name, const char *list_to_check[])
static void c_output (const char *infile, const char *define, int extend, const char *outfile)
static void h_output (const char *infile, const char *define, int extend, const char *outfile)
static void s_output (int argc, const char *argv[], const char *infile, const char *define, int extend, const char *outfile, int nomain, int netflag)
static void l_output (const char *infile, const char *define, int extend, const char *outfile)
static void t_output (const char *infile, const char *define, int extend, const char *outfile)
static void svc_output (const char *infile, const char *define, int extend, const char *outfile)
static void clnt_output (const char *infile, const char *define, int extend, const char *outfile)
static void mkfile_output (struct commandline *cmd)
static int do_registers (int argc, const char *argv[])
static int parseargs (int argc, const char *argv[], struct commandline *cmd)
static void usage (void)
static void close_output (const char *outfile)
static void close_input (void)
void c_initialize (void)
static char * generate_guard (const char *pathname)
static char * file_name (const char *file, const char *ext)
static void options_usage (void)

Variables

static const char * cmdname
static const char * svcclosetime = "120"
static int cppDefined
static const char * CPP = SUNOS_CPP
static const char CPPFLAGS [] = "-C"
static char * pathbuf
static int cpp_pid
static const char * allv []
static int allc = sizeof (allv) / sizeof (allv[0])
static const char * allnv []
static int allnc = sizeof (allnv) / sizeof (allnv[0])
static const char * valid_ti_nettypes []
static const char * valid_i_nettypes []
char rpcgen_table_dcl []
static const char space [] = " "

Class Documentation

struct commandline

Definition at line 58 of file rpc_main.c.

Class Members
int cflag
int hflag
const char * infile
int lflag
int makefileflag
int mflag
int nflag
const char * outfile
int Scflag
int sflag
int Ssflag
int tflag

Define Documentation

#define ARGLISTLEN   20
#define DONT_EXTEND   0 /* alias for FALSE */

Definition at line 56 of file rpc_main.c.

#define EXTEND   1 /* alias for TRUE */

Definition at line 55 of file rpc_main.c.

#define FIXEDARGS   2
#define INLINE   3
#define SUNOS_CPP   "/lib/cpp"

Definition at line 78 of file rpc_main.c.

#define SVR4_CPP   "/usr/ccs/lib/cpp"

Definition at line 77 of file rpc_main.c.


Function Documentation

static void add_warning ( void  ) [static]

Definition at line 312 of file rpc_main.c.

{
  fprintf (fout, "/*\n");
  fprintf (fout, " * Please do not edit this file.\n");
  fprintf (fout, " * It was generated using rpcgen.\n");
  fprintf (fout, " */\n\n");
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void addarg ( const char *  cp) [static]

Definition at line 1122 of file rpc_main.c.

{
  if (argcount >= ARGLISTLEN)
    {
      fprintf (stderr, _("rpcgen: too many defines\n"));
      crash ();
      /*NOTREACHED */
    }
  arglist[argcount++] = cp;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void c_initialize ( void  )

Definition at line 501 of file rpc_main.c.

{

  /* add all the starting basic types */

  add_type (1, "int");
  add_type (1, "long");
  add_type (1, "short");
  add_type (1, "bool");

  add_type (1, "u_int");
  add_type (1, "u_long");
  add_type (1, "u_short");

}

Here is the call graph for this function:

Here is the caller graph for this function:

static void c_output ( const char *  infile,
const char *  define,
int  extend,
const char *  outfile 
) [static]

Definition at line 469 of file rpc_main.c.

{
  definition *def;
  char *include;
  const char *outfilename;
  long tell;

  c_initialize ();
  open_input (infile, define);
  outfilename = extend ? extendfile (infile, outfile) : outfile;
  open_output (infile, outfilename);
  add_warning ();
  if (infile && (include = extendfile (infile, ".h")))
    {
      fprintf (fout, "#include \"%s\"\n", include);
      free (include);
      /* .h file already contains rpc/rpc.h */
    }
  else
    fprintf (fout, "#include <rpc/rpc.h>\n");
  tell = ftell (fout);
  while ((def = get_definition ()) != NULL)
    emit (def);

  if (extend && tell == ftell (fout))
    unlink (outfilename);
  close_input ();
  close_output (outfilename);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int check_nettype ( const char *  name,
const char *  list_to_check[] 
) [static]

Definition at line 450 of file rpc_main.c.

{
  int i;
  for (i = 0; list_to_check[i] != NULL; i++)
    {
      if (strcmp (name, list_to_check[i]) == 0)
       {
         return 1;
       }
    }
  fprintf (stderr, _ ("illegal nettype: `%s'\n"), name);
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void checkfiles ( const char *  infile,
const char *  outfile 
) [static]

Definition at line 1152 of file rpc_main.c.

{
  struct stat buf;

  if (infile)               /* infile ! = NULL */
    if (stat (infile, &buf) < 0)
      {
       perror (infile);
       crash ();
      }
  if (outfile)
    {
      if (stat (outfile, &buf) < 0)
       return;                     /* file does not exist */
      else
       {
         fprintf (stderr,
                 /* TRANS: the file will not be removed; this is an
                    TRANS: informative message.  */
                 _("file `%s' already exists and may be overwritten\n"),
                 outfile);
         crash ();
       }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void clear_args ( void  ) [static]

Definition at line 322 of file rpc_main.c.

{
  int i;
  for (i = FIXEDARGS; i < ARGLISTLEN; ++i)
    arglist[i] = NULL;
  argcount = FIXEDARGS;
}

Here is the caller graph for this function:

static void clnt_output ( const char *  infile,
const char *  define,
int  extend,
const char *  outfile 
) [static]

Definition at line 908 of file rpc_main.c.

{
  definition *def;
  char *include;
  const char *outfilename;
  long tell;
  int has_program = 0;

  open_input (infile, define);
  outfilename = extend ? extendfile (infile, outfile) : outfile;
  checkfiles (infile, outfilename);
  /*check if outfile already exists.
     if so, print an error message and exit */

  open_output (infile, outfilename);
  add_sample_msg ();
  if (infile && (include = extendfile (infile, ".h")))
    {
      fprintf (fout, "#include \"%s\"\n", include);
      free (include);
    }
  else
    fprintf (fout, "#include <rpc/rpc.h>\n");
  tell = ftell (fout);
  while ((def = get_definition ()) != NULL)
    {
      has_program += write_sample_clnt (def);
    }

  if (has_program)
    write_sample_clnt_main ();

  if (extend && tell == ftell (fout))
    {
      unlink (outfilename);
    }
  close_input ();
  close_output (outfilename);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void close_input ( void  ) [static]

Definition at line 403 of file rpc_main.c.

{
  int status;

  fclose (fin);
  /* Check the termination status.  */
  if (waitpid (cpp_pid, &status, 0) < 0)
    {
      perror ("waitpid");
      crash ();
    }
  if (WIFSIGNALED (status) || WEXITSTATUS (status) != 0)
    {
      if (WIFSIGNALED (status))
       fprintf (stderr, _("%s: C preprocessor failed with signal %d\n"),
               cmdname, WTERMSIG (status));
      else
       fprintf (stderr, _("%s: C preprocessor failed with exit code %d\n"),
               cmdname, WEXITSTATUS (status));
      crash ();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void close_output ( const char *  outfile) [static]

Definition at line 301 of file rpc_main.c.

{
  if (fclose (fout) == EOF)
    {
      fprintf (stderr, _("%s: while writing output %s: %m"), cmdname,
              outfile ?: "<stdout>");
      crash ();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int do_registers ( int  argc,
const char *  argv[] 
) [static]

Definition at line 1082 of file rpc_main.c.

{
  int i;

  if (inetdflag || !tirpcflag)
    {
      for (i = 1; i < argc; i++)
       {
         if (streq (argv[i], "-s"))
           {
             if (!check_nettype (argv[i + 1], valid_i_nettypes))
              return 0;
             write_inetd_register (argv[i + 1]);
             i++;
           }
       }
    }
  else
    {
      for (i = 1; i < argc; i++)
       if (streq (argv[i], "-s"))
         {
           if (!check_nettype (argv[i + 1], valid_ti_nettypes))
             return 0;
           write_nettype_register (argv[i + 1]);
           i++;
         }
       else if (streq (argv[i], "-n"))
         {
           write_netid_register (argv[i + 1]);
           i++;
         }
    }
  return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char * extendfile ( const char *  file,
const char *  ext 
) [static]

Definition at line 256 of file rpc_main.c.

{
  char *res;
  const char *p;

  res = alloc (strlen (file) + strlen (ext) + 1);
  if (res == NULL)
    abort ();
  p = strrchr (file, '.');
  if (p == NULL)
    p = file + strlen (file);
  strcpy (res, file);
  strcpy (res + (p - file), ext);
  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char* file_name ( const char *  file,
const char *  ext 
) [static]

Definition at line 952 of file rpc_main.c.

{
  char *temp;
  temp = extendfile (file, ext);

  if (access (temp, F_OK) != -1)
    return (temp);

  free (temp);
  return (char *) space;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void find_cpp ( void  ) [static]

Definition at line 332 of file rpc_main.c.

{
  struct stat buf;

  if (stat (CPP, &buf) < 0)
    {                       /* /lib/cpp or explicit cpp does not exist */
      if (cppDefined)
       {
         fprintf (stderr, _ ("cannot find C preprocessor: %s \n"), CPP);
         crash ();
       }
      else
       {                    /* try the other one */
         CPP = SVR4_CPP;
         if (stat (CPP, &buf) < 0)
           {                /* can't find any cpp */
             fputs (_ ("cannot find any C preprocessor (cpp)\n"), stdout);
             crash ();
           }
       }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char* generate_guard ( const char *  pathname) [static]

Definition at line 527 of file rpc_main.c.

{
  const char *filename;
  char *guard, *tmp;

  filename = strrchr (pathname, '/');     /* find last component */
  filename = ((filename == NULL) ? pathname : filename + 1);
  guard = extendfile (filename, "_H_RPCGEN");
  /* convert to upper case */
  tmp = guard;
  while (*tmp)
    {
      if (islower (*tmp))
       *tmp = toupper (*tmp);
      tmp++;
    }

  return guard;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void h_output ( const char *  infile,
const char *  define,
int  extend,
const char *  outfile 
) [static]

Definition at line 553 of file rpc_main.c.

{
  xdrfunc *xdrfuncp;
  definition *def;
  const char *ifilename;
  const char *outfilename;
  long tell;
  char *guard;
  list *l;

  open_input (infile, define);
  outfilename = extend ? extendfile (infile, outfile) : outfile;
  open_output (infile, outfilename);
  add_warning ();
  ifilename = (infile == NULL) ? "STDIN" : infile;
  guard = generate_guard (outfilename ? outfilename : ifilename);

  fprintf (fout, "#ifndef _%s\n#define _%s\n\n", guard,
          guard);

  fprintf (fout, "#include <rpc/rpc.h>\n\n");

  if (mtflag)
    {
      fprintf (fout, "#include <pthread.h>\n");
    }

  /* put the C++ support */
  if (Cflag && !CCflag)
    {
      fprintf (fout, "\n#ifdef __cplusplus\n");
      fprintf (fout, "extern \"C\" {\n");
      fprintf (fout, "#endif\n\n");
    }

  tell = ftell (fout);
  /* print data definitions */
  while ((def = get_definition ()) != NULL)
    {
      print_datadef (def);
    }

  /* print function declarations.
     Do this after data definitions because they might be used as
     arguments for functions */
  for (l = defined; l != NULL; l = l->next)
    {
      print_funcdef (l->val);
    }
  /* Now  print all xdr func declarations */
  if (xdrfunc_head != NULL)
    {
      fprintf (fout, "\n/* the xdr functions */\n");
      if (CCflag)
       {
         fprintf (fout, "\n#ifdef __cplusplus\n");
         fprintf (fout, "extern \"C\" {\n");
         fprintf (fout, "#endif\n");
       }
      if (!Cflag)
       {
         xdrfuncp = xdrfunc_head;
         while (xdrfuncp != NULL)
           {
             print_xdr_func_def (xdrfuncp->name,
                              xdrfuncp->pointerp, 2);
             xdrfuncp = xdrfuncp->next;
           }
       }
      else
       {
         int i;

         for (i = 1; i < 3; ++i)
           {
             if (i == 1)
              fprintf (fout, "\n#if defined(__STDC__) || defined(__cplusplus)\n");
             else
              fprintf (fout, "\n#else /* K&R C */\n");

             xdrfuncp = xdrfunc_head;
             while (xdrfuncp != NULL)
              {
                print_xdr_func_def (xdrfuncp->name,
                                  xdrfuncp->pointerp, i);
                xdrfuncp = xdrfuncp->next;
              }
           }
         fprintf (fout, "\n#endif /* K&R C */\n");
       }
    }

  if (extend && tell == ftell (fout))
    {
      unlink (outfilename);
    }
  else if (tblflag)
    {
      fprintf (fout, rpcgen_table_dcl);
    }

  if (Cflag)
    {
      fprintf (fout, "\n#ifdef __cplusplus\n");
      fprintf (fout, "}\n");
      fprintf (fout, "#endif\n");
    }

  fprintf (fout, "\n#endif /* !_%s */\n", guard);
  free (guard);
  close_input ();
  close_output (outfilename);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void l_output ( const char *  infile,
const char *  define,
int  extend,
const char *  outfile 
) [static]

Definition at line 802 of file rpc_main.c.

{
  char *include;
  definition *def;
  int foundprogram = 0;
  const char *outfilename;

  open_input (infile, define);
  outfilename = extend ? extendfile (infile, outfile) : outfile;
  open_output (infile, outfilename);
  add_warning ();
  if (Cflag)
    fprintf (fout, "#include <memory.h> /* for memset */\n");
  if (infile && (include = extendfile (infile, ".h")))
    {
      fprintf (fout, "#include \"%s\"\n", include);
      free (include);
    }
  else
    fprintf (fout, "#include <rpc/rpc.h>\n");
  while ((def = get_definition ()) != NULL)
    {
      foundprogram |= (def->def_kind == DEF_PROGRAM);
    }
  if (extend && !foundprogram)
    {
      unlink (outfilename);
      return;
    }
  write_stubs ();
  close_input ();
  close_output (outfilename);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void mkfile_output ( struct commandline cmd) [static]

Definition at line 965 of file rpc_main.c.

{
  char *mkfilename;
  char *clientname, *clntname, *xdrname, *hdrname;
  char *servername, *svcname, *servprogname, *clntprogname;

  svcname = file_name (cmd->infile, "_svc.c");
  clntname = file_name (cmd->infile, "_clnt.c");
  xdrname = file_name (cmd->infile, "_xdr.c");
  hdrname = file_name (cmd->infile, ".h");

  if (allfiles)
    {
      servername = extendfile (cmd->infile, "_server.c");
      clientname = extendfile (cmd->infile, "_client.c");
    }
  else
    {
      servername = (char *) space;
      clientname = (char *) space;
    }
  servprogname = extendfile (cmd->infile, "_server");
  clntprogname = extendfile (cmd->infile, "_client");

  if (allfiles)
    {
      char *cp, *temp;

      mkfilename = alloc (strlen ("Makefile.") + strlen (cmd->infile) + 1);
      if (mkfilename == NULL)
       abort ();
      temp = rindex (cmd->infile, '.');
      cp = stpcpy (mkfilename, "Makefile.");
      if (temp != NULL)
       *((char *) stpncpy (cp, cmd->infile, temp - cmd->infile)) = '\0';
      else
       stpcpy (cp, cmd->infile);

    }
  else
    mkfilename = (char *) cmd->outfile;

  checkfiles (NULL, mkfilename);
  open_output (NULL, mkfilename);

  fprintf (fout, "\n# This is a template Makefile generated by rpcgen\n");

  f_print (fout, "\n# Parameters\n\n");

  f_print (fout, "CLIENT = %s\nSERVER = %s\n\n", clntprogname, servprogname);
  f_print (fout, "SOURCES_CLNT.c = \nSOURCES_CLNT.h = \n");
  f_print (fout, "SOURCES_SVC.c = \nSOURCES_SVC.h = \n");
  f_print (fout, "SOURCES.x = %s\n\n", cmd->infile);
  f_print (fout, "TARGETS_SVC.c = %s %s %s \n",
          svcname, servername, xdrname);
  f_print (fout, "TARGETS_CLNT.c = %s %s %s \n",
          clntname, clientname, xdrname);
  f_print (fout, "TARGETS = %s %s %s %s %s %s\n\n",
          hdrname, xdrname, clntname,
          svcname, clientname, servername);

  f_print (fout, "OBJECTS_CLNT = $(SOURCES_CLNT.c:%%.c=%%.o) \
$(TARGETS_CLNT.c:%%.c=%%.o)");

  f_print (fout, "\nOBJECTS_SVC = $(SOURCES_SVC.c:%%.c=%%.o) \
$(TARGETS_SVC.c:%%.c=%%.o)");

  f_print (fout, "\n# Compiler flags \n");
  if (mtflag)
    fprintf (fout, "\nCPPFLAGS += -D_REENTRANT\nCFLAGS += -g \nLDLIBS \
+= -lnsl -lpthread \n ");
  else
    f_print (fout, "\nCFLAGS += -g \nLDLIBS += -lnsl\n");
  f_print (fout, "RPCGENFLAGS = \n");

  f_print (fout, "\n# Targets \n\n");

  f_print (fout, "all : $(CLIENT) $(SERVER)\n\n");
  f_print (fout, "$(TARGETS) : $(SOURCES.x) \n");
  f_print (fout, "\trpcgen $(RPCGENFLAGS) $(SOURCES.x)\n\n");
  f_print (fout, "$(OBJECTS_CLNT) : $(SOURCES_CLNT.c) $(SOURCES_CLNT.h) \
$(TARGETS_CLNT.c) \n\n");

  f_print (fout, "$(OBJECTS_SVC) : $(SOURCES_SVC.c) $(SOURCES_SVC.h) \
$(TARGETS_SVC.c) \n\n");
  f_print (fout, "$(CLIENT) : $(OBJECTS_CLNT) \n");
  f_print (fout, "\t$(LINK.c) -o $(CLIENT) $(OBJECTS_CLNT) \
$(LDLIBS) \n\n");
  f_print (fout, "$(SERVER) : $(OBJECTS_SVC) \n");
  f_print (fout, "\t$(LINK.c) -o $(SERVER) $(OBJECTS_SVC) $(LDLIBS)\n\n ");
  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);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void open_input ( const char *  infile,
const char *  define 
) [static]

Definition at line 359 of file rpc_main.c.

{
  int pd[2];

  infilename = (infile == NULL) ? "<stdin>" : infile;
  if (pipe (pd) != 0)
    {
      perror ("pipe");
      exit (1);
    }
  cpp_pid = fork ();
  switch (cpp_pid)
    {
    case 0:
      find_cpp ();
      putarg (0, CPP);
      putarg (1, CPPFLAGS);
      addarg (define);
      if (infile)
       addarg (infile);
      addarg ((char *) NULL);
      close (1);
      dup2 (pd[1], 1);
      close (pd[0]);
      execv (arglist[0], (char **) arglist);
      perror ("execv");
      exit (1);
    case -1:
      perror ("fork");
      exit (1);
    }
  close (pd[1]);
  fin = fdopen (pd[0], "r");
  if (fin == NULL)
    {
      fprintf (stderr, "%s: ", cmdname);
      perror (infilename);
      crash ();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void open_output ( const char *  infile,
const char *  outfile 
) [static]

Definition at line 276 of file rpc_main.c.

{
  if (outfile == NULL)
    {
      fout = stdout;
      return;
    }

  if (infile != NULL && streq (outfile, infile))
    {
      fprintf (stderr, _ ("%s: output would overwrite %s\n"), cmdname,
              infile);
      crash ();
    }
  fout = fopen (outfile, "w");
  if (fout == NULL)
    {
      fprintf (stderr, _ ("%s: unable to open %s: %m\n"), cmdname, outfile);
      crash ();
    }
  record_open (outfile);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void options_usage ( void  ) [static]

Definition at line 1459 of file rpc_main.c.

{
  f_print (stderr, "options:\n");
  f_print (stderr, "-a\t\tgenerate all files, including samples\n");
  f_print (stderr, "-b\t\tbackward compatibility mode (generates code for SunOS 4.1)\n");
  f_print (stderr, "-c\t\tgenerate XDR routines\n");
  f_print (stderr, "-C\t\tANSI C mode\n");
  f_print (stderr, "-Dname[=value]\tdefine a symbol (same as #define)\n");
  f_print (stderr, "-h\t\tgenerate header file\n");
  f_print (stderr, "-i size\t\tsize at which to start generating inline code\n");
  f_print (stderr, "-I\t\tgenerate code for inetd support in server (for SunOS 4.1)\n");
  f_print (stderr, "-K seconds\tserver exits after K seconds of inactivity\n");
  f_print (stderr, "-l\t\tgenerate client side stubs\n");
  f_print (stderr, "-L\t\tserver errors will be printed to syslog\n");
  f_print (stderr, "-m\t\tgenerate server side stubs\n");
  f_print (stderr, "-M\t\tgenerate MT-safe code\n");
  f_print (stderr, "-n netid\tgenerate server code that supports named netid\n");
  f_print (stderr, "-N\t\tsupports multiple arguments and call-by-value\n");
  f_print (stderr, "-o outfile\tname of the output file\n");
  f_print (stderr, "-s nettype\tgenerate server code that supports named nettype\n");
  f_print (stderr, "-Sc\t\tgenerate sample client code that uses remote procedures\n");
  f_print (stderr, "-Ss\t\tgenerate sample server code that defines remote procedures\n");
  f_print (stderr, "-Sm \t\tgenerate makefile template \n");
  f_print (stderr, "-t\t\tgenerate RPC dispatch table\n");
  f_print (stderr, "-T\t\tgenerate code to support RPC dispatch tables\n");
  f_print (stderr, "-Y path\t\tdirectory name to find C preprocessor (cpp)\n");

  exit (1);
}

Here is the call graph for this function:

static int parseargs ( int  argc,
const char *  argv[],
struct commandline cmd 
) [static]

Definition at line 1182 of file rpc_main.c.

{
  int i;
  int j;
  int c;
  char flag[(1 << 8 * sizeof (char))];
  int nflags;

  cmdname = argv[0];
  cmd->infile = cmd->outfile = NULL;
  if (argc < 2)
    {
      return (0);
    }
  allfiles = 0;
  flag['c'] = 0;
  flag['h'] = 0;
  flag['l'] = 0;
  flag['m'] = 0;
  flag['o'] = 0;
  flag['s'] = 0;
  flag['n'] = 0;
  flag['t'] = 0;
  flag['S'] = 0;
  flag['C'] = 0;
  flag['M'] = 0;

  for (i = 1; i < argc; i++)
    {
      if (argv[i][0] != '-')
       {
         if (cmd->infile)
           {
             fprintf (stderr,
                     _("Cannot specify more than one input file!\n"));
             return 0;
           }
         cmd->infile = argv[i];
       }
      else
       {
         for (j = 1; argv[i][j] != 0; j++)
           {
             c = argv[i][j];
             switch (c)
              {
              case 'a':
                allfiles = 1;
                break;
              case 'c':
              case 'h':
              case 'l':
              case 'm':
              case 't':
                if (flag[c])
                  return 0;
                flag[c] = 1;
                break;
              case 'S':
                /* sample flag: Ss or Sc.
                   Ss means set flag['S'];
                   Sc means set flag['C'];
                   Sm means set flag['M']; */
                c = argv[i][++j];  /* get next char */
                if (c == 's')
                  c = 'S';
                else if (c == 'c')
                  c = 'C';
                else if (c == 'm')
                  c = 'M';
                else
                  return 0;

                if (flag[c])
                  return 0;
                flag[c] = 1;
                break;
              case 'C':     /* ANSI C syntax */
                Cflag = 1;
                break;

#ifdef __GNU_LIBRARY__
              case 'k':  /* K&R C syntax */
                Cflag = 0;
                break;

#endif
              case 'b':  /* turn TIRPC flag off for
                           generating backward compatible
                        */
                tirpcflag = 0;
                break;

#ifdef __GNU_LIBRARY__
              case '5':  /* turn TIRPC flag on for
                           generating SysVr4 compatible
                        */
                tirpcflag = 1;
                break;
#endif
              case 'I':
                inetdflag = 1;
                break;
              case 'N':
                newstyle = 1;
                break;
              case 'L':
                logflag = 1;
                break;
              case 'K':
                if (++i == argc)
                  {
                    return (0);
                  }
                svcclosetime = argv[i];
                goto nextarg;
              case 'T':
                tblflag = 1;
                break;
              case 'M':
                mtflag = 1;
                break;
              case 'i':
                if (++i == argc)
                  {
                    return (0);
                  }
                inlineflag = atoi (argv[i]);
                goto nextarg;
              case 'n':
              case 'o':
              case 's':
                if (argv[i][j - 1] != '-' ||
                    argv[i][j + 1] != 0)
                  {
                    return (0);
                  }
                flag[c] = 1;
                if (++i == argc)
                  {
                    return (0);
                  }
                if (c == 's')
                  {
                    if (!streq (argv[i], "udp") &&
                       !streq (argv[i], "tcp"))
                     return 0;
                  }
                else if (c == 'o')
                  {
                    if (cmd->outfile)
                     return 0;
                    cmd->outfile = argv[i];
                  }
                goto nextarg;
              case 'D':
                if (argv[i][j - 1] != '-')
                  return 0;
                addarg (argv[i]);
                goto nextarg;
              case 'Y':
                if (++i == argc)
                  return 0;
                {
                  size_t len = strlen (argv[i]);
                  pathbuf = malloc (len + 5);
                  if (pathbuf == NULL)
                    {
                     perror (cmdname);
                     crash ();
                    }
                  stpcpy (stpcpy (pathbuf,
                                argv[i]),
                         "/cpp");
                  CPP = pathbuf;
                  cppDefined = 1;
                  goto nextarg;
                }

              default:
                return 0;
              }
             }
       nextarg:
         ;
       }
    }

  cmd->cflag = flag['c'];
  cmd->hflag = flag['h'];
  cmd->lflag = flag['l'];
  cmd->mflag = flag['m'];
  cmd->nflag = flag['n'];
  cmd->sflag = flag['s'];
  cmd->tflag = flag['t'];
  cmd->Ssflag = flag['S'];
  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 */
      if ((inetdflag && cmd->nflag))
       {                    /* netid not allowed with inetdflag */
         fprintf (stderr, _("Cannot use netid flag with inetd flag!\n"));
         return 0;
       }
    }
  else
    {                       /* 4.1 mode */
      pmflag = 0;           /* set pmflag only in tirpcmode */
#ifndef __GNU_LIBRARY__
      inetdflag = 1;            /* inetdflag is TRUE by default */
#endif
      if (cmd->nflag)
       {                    /* netid needs TIRPC */
         f_print (stderr, _("Cannot use netid flag without TIRPC!\n"));
         return (0);
       }
    }

  if (newstyle && (tblflag || cmd->tflag))
    {
      f_print (stderr, _("Cannot use table flags with newstyle!\n"));
      return (0);
    }

  /* check no conflicts with file generation flags */
  nflags = cmd->cflag + cmd->hflag + cmd->lflag + cmd->mflag +
    cmd->sflag + cmd->nflag + cmd->tflag + cmd->Ssflag + cmd->Scflag;

  if (nflags == 0)
    {
      if (cmd->outfile != NULL || cmd->infile == NULL)
       {
         return (0);
       }
    }
  else if (cmd->infile == NULL &&
          (cmd->Ssflag || cmd->Scflag || cmd->makefileflag))
    {
      fprintf (stderr,
              _("\"infile\" is required for template generation flags.\n"));
      return 0;
    }
  if (nflags > 1)
    {
      fprintf (stderr, _("Cannot have more than one file generation flag!\n"));
      return 0;
    }
  return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void putarg ( int  whereto,
const char *  cp 
) [static]

Definition at line 1134 of file rpc_main.c.

{
  if (whereto >= ARGLISTLEN)
    {
      fprintf (stderr, _("rpcgen: arglist coding error\n"));
      crash ();
      /*NOTREACHED */
    }
  arglist[whereto] = cp;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void s_output ( int  argc,
const char *  argv[],
const char *  infile,
const char *  define,
int  extend,
const char *  outfile,
int  nomain,
int  netflag 
) [static]

Definition at line 672 of file rpc_main.c.

{
  char *include;
  definition *def;
  int foundprogram = 0;
  const char *outfilename;

  open_input (infile, define);
  outfilename = extend ? extendfile (infile, outfile) : outfile;
  open_output (infile, outfilename);
  add_warning ();
  if (infile && (include = extendfile (infile, ".h")))
    {
      fprintf (fout, "#include \"%s\"\n", include);
      free (include);
    }
  else
    fprintf (fout, "#include <rpc/rpc.h>\n");

  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 <string.h>\n");
  if (strcmp (svcclosetime, "-1") == 0)
    indefinitewait = 1;
  else if (strcmp (svcclosetime, "0") == 0)
    exitnow = 1;
  else if (inetdflag || pmflag)
    {
      fprintf (fout, "#include <signal.h>\n");
      timerflag = 1;
    }

  if (!tirpcflag && inetdflag)
#ifdef __GNU_LIBRARY__
    fprintf (fout, "#include <sys/ioctl.h> /* ioctl, TIOCNOTTY */\n");
#else
    fprintf (fout, "#include <sys/ttycom.h>/* TIOCNOTTY */\n");
#endif
  if (Cflag && (inetdflag || pmflag))
    {
#ifdef __GNU_LIBRARY__
      fprintf (fout, "#include <sys/types.h> /* open */\n");
      fprintf (fout, "#include <sys/stat.h> /* open */\n");
      fprintf (fout, "#include <fcntl.h> /* open */\n");
      fprintf (fout, "#include <unistd.h> /* getdtablesize */\n");
#else
      fprintf (fout, "#ifdef __cplusplus\n");
      fprintf (fout, "#include <sysent.h> /* getdtablesize, open */\n");
      fprintf (fout, "#endif /* __cplusplus */\n");
      if (tirpcflag)
       fprintf (fout, "#include <unistd.h> /* setsid */\n");
#endif
    }
#ifdef __GNU_LIBRARY__
  if (tirpcflag && !(Cflag && (inetdflag || pmflag)))
#else
  if (tirpcflag)
#endif
    fprintf (fout, "#include <sys/types.h>\n");

  fprintf (fout, "#include <memory.h>\n");
#ifndef __GNU_LIBRARY__
  fprintf (fout, "#include <stropts.h>\n");
#endif
  if (inetdflag || !tirpcflag)
    {
      fprintf (fout, "#include <sys/socket.h>\n");
      fprintf (fout, "#include <netinet/in.h>\n");
    }

  if ((netflag || pmflag) && tirpcflag && !nomain)
    {
      fprintf (fout, "#include <netconfig.h>\n");
    }
  if ( /*timerflag && */ tirpcflag)
    fprintf (fout, "#include <sys/resource.h> /* rlimit */\n");
  if (logflag || inetdflag || pmflag)
    {
#ifdef __GNU_LIBRARY__
      fprintf (fout, "#include <syslog.h>\n");
#else
      fprintf (fout, "#ifdef SYSLOG\n");
      fprintf (fout, "#include <syslog.h>\n");
      fprintf (fout, "#else\n");
      fprintf (fout, "#define LOG_ERR 1\n");
      fprintf (fout, "#define openlog(a, b, c)\n");
      fprintf (fout, "#endif\n");
#endif
    }

  /* for ANSI-C */
  if (Cflag)
    fprintf (fout, "\n#ifndef SIG_PF\n#define SIG_PF void(*)(int)\n#endif\n");

#ifndef __GNU_LIBRARY__
  fprintf (fout, "\n#ifdef DEBUG\n#define RPC_SVC_FG\n#endif\n");
#endif
  if (timerflag)
    fprintf (fout, "\n#define _RPCSVC_CLOSEDOWN %s\n", svcclosetime);
  while ((def = get_definition ()) != NULL)
    {
      foundprogram |= (def->def_kind == DEF_PROGRAM);
    }
  if (extend && !foundprogram)
    {
      unlink (outfilename);
      return;
    }
  write_most (infile, netflag, nomain);
  if (!nomain)
    {
      if (!do_registers (argc, argv))
       {
         if (outfilename)
           unlink (outfilename);
         usage ();
       }
      write_rest ();
    }
  close_input ();
  close_output (outfilename);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void svc_output ( const char *  infile,
const char *  define,
int  extend,
const char *  outfile 
) [static]

Definition at line 868 of file rpc_main.c.

{
  definition *def;
  char *include;
  const char *outfilename;
  long tell;

  open_input (infile, define);
  outfilename = extend ? extendfile (infile, outfile) : outfile;
  checkfiles (infile, outfilename);
  /*check if outfile already exists.
     if so, print an error message and exit */
  open_output (infile, outfilename);
  add_sample_msg ();

  if (infile && (include = extendfile (infile, ".h")))
    {
      fprintf (fout, "#include \"%s\"\n", include);
      free (include);
    }
  else
    fprintf (fout, "#include <rpc/rpc.h>\n");

  tell = ftell (fout);
  while ((def = get_definition ()) != NULL)
    {
      write_sample_svc (def);
    }
  if (extend && tell == ftell (fout))
    {
      unlink (outfilename);
    }
  close_input ();
  close_output (outfilename);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void t_output ( const char *  infile,
const char *  define,
int  extend,
const char *  outfile 
) [static]

Definition at line 841 of file rpc_main.c.

{
  definition *def;
  int foundprogram = 0;
  const char *outfilename;

  open_input (infile, define);
  outfilename = extend ? extendfile (infile, outfile) : outfile;
  open_output (infile, outfilename);
  add_warning ();
  while ((def = get_definition ()) != NULL)
    {
      foundprogram |= (def->def_kind == DEF_PROGRAM);
    }
  if (extend && !foundprogram)
    {
      unlink (outfilename);
      return;
    }
  write_tables ();
  close_input ();
  close_output (outfilename);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void usage ( void  ) [static]

Definition at line 135 of file rpc_main.c.

{
  struct commandline cmd;

  (void) memset ((char *) &cmd, 0, sizeof (struct commandline));
  clear_args ();
  if (!parseargs (argc, argv, &cmd))
    usage ();

  if (cmd.cflag || cmd.hflag || cmd.lflag || cmd.tflag || cmd.sflag ||
      cmd.mflag || cmd.nflag || cmd.Ssflag || cmd.Scflag)
    {
      checkfiles (cmd.infile, cmd.outfile);
    }
  else
    checkfiles (cmd.infile, NULL);

  if (cmd.cflag)
    c_output (cmd.infile, "-DRPC_XDR", DONT_EXTEND, cmd.outfile);
  else if (cmd.hflag)
    h_output (cmd.infile, "-DRPC_HDR", DONT_EXTEND, cmd.outfile);
  else if (cmd.lflag)
    l_output (cmd.infile, "-DRPC_CLNT", DONT_EXTEND, cmd.outfile);
  else if (cmd.sflag || cmd.mflag || (cmd.nflag))
    s_output (argc, argv, cmd.infile, "-DRPC_SVC", DONT_EXTEND,
             cmd.outfile, cmd.mflag, cmd.nflag);
  else if (cmd.tflag)
    t_output (cmd.infile, "-DRPC_TBL", DONT_EXTEND, cmd.outfile);
  else if (cmd.Ssflag)
    svc_output (cmd.infile, "-DRPC_SERVER", DONT_EXTEND, cmd.outfile);
  else if (cmd.Scflag)
    clnt_output (cmd.infile, "-DRPC_CLIENT", DONT_EXTEND, cmd.outfile);
  else if (cmd.makefileflag)
    mkfile_output (&cmd);
  else
    {
      /* the rescans are required, since cpp may effect input */
      c_output (cmd.infile, "-DRPC_XDR", EXTEND, "_xdr.c");
      reinitialize ();
      h_output (cmd.infile, "-DRPC_HDR", EXTEND, ".h");
      reinitialize ();
      l_output (cmd.infile, "-DRPC_CLNT", EXTEND, "_clnt.c");
      reinitialize ();
      if (inetdflag || !tirpcflag)
       s_output (allc, allv, cmd.infile, "-DRPC_SVC", EXTEND,
                "_svc.c", cmd.mflag, cmd.nflag);
      else
       s_output (allnc, allnv, cmd.infile, "-DRPC_SVC",
                EXTEND, "_svc.c", cmd.mflag, cmd.nflag);
      if (tblflag)
       {
         reinitialize ();
         t_output (cmd.infile, "-DRPC_TBL", EXTEND, "_tbl.i");
       }
      if (allfiles)
       {
         reinitialize ();
         svc_output (cmd.infile, "-DRPC_SERVER", EXTEND, "_server.c");
         reinitialize ();
         clnt_output (cmd.infile, "-DRPC_CLIENT", EXTEND, "_client.c");
       }
      if (allfiles || (cmd.makefileflag == 1))
       {
         reinitialize ();
         mkfile_output (&cmd);
       }
    }

  return nonfatalerrors;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

int allc = sizeof (allv) / sizeof (allv[0]) [static]

Definition at line 90 of file rpc_main.c.

int allnc = sizeof (allnv) / sizeof (allnv[0]) [static]

Definition at line 95 of file rpc_main.c.

const char* allnv[] [static]
Initial value:
{
  "rpcgen", "-s", "netpath",
}

Definition at line 91 of file rpc_main.c.

const char* allv[] [static]
Initial value:
{
  "rpcgen", "-s", "udp", "-s", "tcp"
}

Definition at line 86 of file rpc_main.c.

const char* cmdname [static]

Definition at line 75 of file rpc_main.c.

const char* CPP = SUNOS_CPP [static]

Definition at line 82 of file rpc_main.c.

int cpp_pid [static]

Definition at line 85 of file rpc_main.c.

int cppDefined [static]

Definition at line 81 of file rpc_main.c.

const char CPPFLAGS[] = "-C" [static]

Definition at line 83 of file rpc_main.c.

char* pathbuf [static]

Definition at line 84 of file rpc_main.c.

Initial value:
"struct rpcgen_table {\n\
       char   *(*proc)();\n\
       xdrproc_t     xdr_arg;\n\
       unsigned      len_arg;\n\
       xdrproc_t     xdr_res;\n\
       unsigned      len_res;\n\
};\n"

Definition at line 517 of file rpc_main.c.

const char space[] = " " [static]

Definition at line 949 of file rpc_main.c.

const char* svcclosetime = "120" [static]

Definition at line 80 of file rpc_main.c.

const char* valid_i_nettypes[] [static]
Initial value:
{
  "udp",
  "tcp",
  NULL
}

Definition at line 442 of file rpc_main.c.

const char* valid_ti_nettypes[] [static]
Initial value:
{
  "netpath",
  "visible",
  "circuit_v",
  "datagram_v",
  "circuit_n",
  "datagram_n",
  "udp",
  "tcp",
  "raw",
  NULL
}

Definition at line 427 of file rpc_main.c.