Blame sunrpc/rpc_main.c

Packit 6c4009
/*
Packit 6c4009
 * From @(#)rpc_main.c 1.30 89/03/30
Packit 6c4009
 *
Packit 6c4009
 * Copyright (c) 2010, Oracle America, Inc.
Packit 6c4009
 * Redistribution and use in source and binary forms, with or without
Packit 6c4009
 * modification, are permitted provided that the following conditions are
Packit 6c4009
 * met:
Packit 6c4009
 *
Packit 6c4009
 *     * Redistributions of source code must retain the above copyright
Packit 6c4009
 *       notice, this list of conditions and the following disclaimer.
Packit 6c4009
 *     * Redistributions in binary form must reproduce the above
Packit 6c4009
 *       copyright notice, this list of conditions and the following
Packit 6c4009
 *       disclaimer in the documentation and/or other materials
Packit 6c4009
 *       provided with the distribution.
Packit 6c4009
 *     * Neither the name of the "Oracle America, Inc." nor the names of its
Packit 6c4009
 *       contributors may be used to endorse or promote products derived
Packit 6c4009
 *       from this software without specific prior written permission.
Packit 6c4009
 *
Packit 6c4009
 *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit 6c4009
 *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit 6c4009
 *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
Packit 6c4009
 *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
Packit 6c4009
 *   COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
Packit 6c4009
 *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit 6c4009
 *   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
Packit 6c4009
 *   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Packit 6c4009
 *   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
Packit 6c4009
 *   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
Packit 6c4009
 *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit 6c4009
 *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
/*
Packit 6c4009
 * rpc_main.c, Top level of the RPC protocol compiler.
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
#include <errno.h>
Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include <string.h>
Packit 6c4009
#include <unistd.h>
Packit 6c4009
#include <libintl.h>
Packit 6c4009
#include <locale.h>
Packit 6c4009
#include <ctype.h>
Packit 6c4009
#include <sys/types.h>
Packit 6c4009
#include <sys/param.h>
Packit 6c4009
#include <sys/file.h>
Packit 6c4009
#include <sys/stat.h>
Packit 6c4009
#include <sys/wait.h>
Packit 6c4009
#include "rpc_parse.h"
Packit 6c4009
#include "rpc_util.h"
Packit 6c4009
#include "rpc_scan.h"
Packit 6c4009
#include "proto.h"
Packit 6c4009
Packit 6c4009
#include "../version.h"
Packit 6c4009
#define PACKAGE _libc_intl_domainname
Packit 6c4009
Packit 6c4009
#define EXTEND	1		/* alias for TRUE */
Packit 6c4009
#define DONT_EXTEND	0	/* alias for FALSE */
Packit 6c4009
Packit 6c4009
struct commandline
Packit 6c4009
  {
Packit 6c4009
    int cflag;			/* xdr C routines */
Packit 6c4009
    int hflag;			/* header file */
Packit 6c4009
    int lflag;			/* client side stubs */
Packit 6c4009
    int mflag;			/* server side stubs */
Packit 6c4009
    int nflag;			/* netid flag */
Packit 6c4009
    int sflag;			/* server stubs for the given transport */
Packit 6c4009
    int tflag;			/* dispatch Table file */
Packit 6c4009
    int Ssflag;			/* produce server sample code */
Packit 6c4009
    int Scflag;			/* produce client sample code */
Packit 6c4009
    int makefileflag;		/* Generate a template Makefile */
Packit 6c4009
    const char *infile;		/* input module name */
Packit 6c4009
    const char *outfile;	/* output module name */
Packit 6c4009
  };
Packit 6c4009
Packit 6c4009
Packit 6c4009
static const char *cmdname;
Packit 6c4009
Packit 6c4009
static const char *svcclosetime = "120";
Packit 6c4009
static int cppDefined;	/* explicit path for C preprocessor */
Packit 6c4009
static const char *CPP = "/lib/cpp";
Packit 6c4009
static const char CPPFLAGS[] = "-C";
Packit 6c4009
static char *pathbuf;
Packit 6c4009
static int cpp_pid;
Packit 6c4009
static const char *allv[] =
Packit 6c4009
{
Packit 6c4009
  "rpcgen", "-s", "udp", "-s", "tcp"
Packit 6c4009
};
Packit 6c4009
static int allc = sizeof (allv) / sizeof (allv[0]);
Packit 6c4009
static const char *allnv[] =
Packit 6c4009
{
Packit 6c4009
  "rpcgen", "-s", "netpath",
Packit 6c4009
};
Packit 6c4009
static int allnc = sizeof (allnv) / sizeof (allnv[0]);
Packit 6c4009
Packit 6c4009
/*
Packit 6c4009
 * machinations for handling expanding argument list
Packit 6c4009
 */
Packit 6c4009
static void addarg (const char *);	/* add another argument to the list */
Packit 6c4009
static void putarg (int, const char *);		/* put argument at specified location */
Packit 6c4009
static void clear_args (void);	/* clear argument list */
Packit 6c4009
static void checkfiles (const char *, const char *);
Packit 6c4009
				       /* check if out file already exists */
Packit 6c4009
Packit 6c4009
static void clear_args (void);
Packit 6c4009
static char *extendfile (const char *file, const char *ext);
Packit 6c4009
static void open_output (const char *infile, const char *outfile);
Packit 6c4009
static void add_warning (void);
Packit 6c4009
static void clear_args (void);
Packit 6c4009
static void find_cpp (void);
Packit 6c4009
static void open_input (const char *infile, const char *define);
Packit 6c4009
static int check_nettype (const char *name, const char *list_to_check[]);
Packit 6c4009
static void c_output (const char *infile, const char *define,
Packit 6c4009
		      int extend, const char *outfile);
Packit 6c4009
static void h_output (const char *infile, const char *define,
Packit 6c4009
		      int extend, const char *outfile);
Packit 6c4009
static void s_output (int argc, const char *argv[], const char *infile,
Packit 6c4009
		      const char *define, int extend,
Packit 6c4009
		      const char *outfile, int nomain, int netflag);
Packit 6c4009
static void l_output (const char *infile, const char *define,
Packit 6c4009
		      int extend, const char *outfile);
Packit 6c4009
static void t_output (const char *infile, const char *define,
Packit 6c4009
		      int extend, const char *outfile);
Packit 6c4009
static void svc_output (const char *infile, const char *define,
Packit 6c4009
			int extend, const char *outfile);
Packit 6c4009
static void clnt_output (const char *infile, const char *define,
Packit 6c4009
			 int extend, const char *outfile);
Packit 6c4009
static void mkfile_output (struct commandline *cmd);
Packit 6c4009
static int do_registers (int argc, const char *argv[]);
Packit 6c4009
static void addarg (const char *cp);
Packit 6c4009
static void putarg (int whereto, const char *cp);
Packit 6c4009
static void checkfiles (const char *infile, const char *outfile);
Packit 6c4009
static int parseargs (int argc, const char *argv[], struct commandline *cmd);
Packit 6c4009
static void usage (FILE *stream, int status) __attribute__ ((noreturn));
Packit 6c4009
static void options_usage (FILE *stream, int status) __attribute__ ((noreturn));
Packit 6c4009
static void print_version (void);
Packit 6c4009
static void c_initialize (void);
Packit 6c4009
static char *generate_guard (const char *pathname);
Packit 6c4009
Packit 6c4009
Packit 6c4009
#define ARGLISTLEN	20
Packit 6c4009
#define FIXEDARGS         2
Packit 6c4009
Packit 6c4009
static const char *arglist[ARGLISTLEN];
Packit 6c4009
static int argcount = FIXEDARGS;
Packit 6c4009
Packit 6c4009
Packit 6c4009
int nonfatalerrors;		/* errors */
Packit 6c4009
int inetdflag /* = 1 */ ;	/* Support for inetd *//* is now the default */
Packit 6c4009
int pmflag;			/* Support for port monitors */
Packit 6c4009
int logflag;			/* Use syslog instead of fprintf for errors */
Packit 6c4009
int tblflag;			/* Support for dispatch table file */
Packit 6c4009
int mtflag;			/* Support for MT */
Packit 6c4009
Packit 6c4009
#define INLINE 3
Packit 6c4009
/*length at which to start doing an inline */
Packit 6c4009
Packit 6c4009
int inlineflag = INLINE;	/* length at which to start doing an inline. 3 = default
Packit 6c4009
				   if 0, no xdr_inline code */
Packit 6c4009
Packit 6c4009
int indefinitewait;		/* If started by port monitors, hang till it wants */
Packit 6c4009
int exitnow;			/* If started by port monitors, exit after the call */
Packit 6c4009
int timerflag;			/* TRUE if !indefinite && !exitnow */
Packit 6c4009
int newstyle;			/* newstyle of passing arguments (by value) */
Packit 6c4009
int Cflag = 1;			/* ANSI C syntax */
Packit 6c4009
int CCflag;			/* C++ files */
Packit 6c4009
static int allfiles;		/* generate all files */
Packit 6c4009
int tirpcflag;			/* generating code for tirpc, by default */
Packit 6c4009
xdrfunc *xdrfunc_head;		/* xdr function list */
Packit 6c4009
xdrfunc *xdrfunc_tail;		/* xdr function list */
Packit 6c4009
Packit 6c4009
int
Packit 6c4009
main (int argc, const char *argv[])
Packit 6c4009
{
Packit 6c4009
  struct commandline cmd;
Packit 6c4009
Packit 6c4009
  setlocale (LC_ALL, "");
Packit 6c4009
  textdomain (_libc_intl_domainname);
Packit 6c4009
Packit 6c4009
  (void) memset ((char *) &cmd, 0, sizeof (struct commandline));
Packit 6c4009
  clear_args ();
Packit 6c4009
  if (!parseargs (argc, argv, &cmd))
Packit 6c4009
    usage (stderr, 1);
Packit 6c4009
Packit 6c4009
  if (cmd.cflag || cmd.hflag || cmd.lflag || cmd.tflag || cmd.sflag ||
Packit 6c4009
      cmd.mflag || cmd.nflag || cmd.Ssflag || cmd.Scflag)
Packit 6c4009
    {
Packit 6c4009
      checkfiles (cmd.infile, cmd.outfile);
Packit 6c4009
    }
Packit 6c4009
  else
Packit 6c4009
    checkfiles (cmd.infile, NULL);
Packit 6c4009
Packit 6c4009
  if (cmd.cflag)
Packit 6c4009
    c_output (cmd.infile, "-DRPC_XDR", DONT_EXTEND, cmd.outfile);
Packit 6c4009
  else if (cmd.hflag)
Packit 6c4009
    h_output (cmd.infile, "-DRPC_HDR", DONT_EXTEND, cmd.outfile);
Packit 6c4009
  else if (cmd.lflag)
Packit 6c4009
    l_output (cmd.infile, "-DRPC_CLNT", DONT_EXTEND, cmd.outfile);
Packit 6c4009
  else if (cmd.sflag || cmd.mflag || (cmd.nflag))
Packit 6c4009
    s_output (argc, argv, cmd.infile, "-DRPC_SVC", DONT_EXTEND,
Packit 6c4009
	      cmd.outfile, cmd.mflag, cmd.nflag);
Packit 6c4009
  else if (cmd.tflag)
Packit 6c4009
    t_output (cmd.infile, "-DRPC_TBL", DONT_EXTEND, cmd.outfile);
Packit 6c4009
  else if (cmd.Ssflag)
Packit 6c4009
    svc_output (cmd.infile, "-DRPC_SERVER", DONT_EXTEND, cmd.outfile);
Packit 6c4009
  else if (cmd.Scflag)
Packit 6c4009
    clnt_output (cmd.infile, "-DRPC_CLIENT", DONT_EXTEND, cmd.outfile);
Packit 6c4009
  else if (cmd.makefileflag)
Packit 6c4009
    mkfile_output (&cmd);
Packit 6c4009
  else
Packit 6c4009
    {
Packit 6c4009
      /* the rescans are required, since cpp may effect input */
Packit 6c4009
      c_output (cmd.infile, "-DRPC_XDR", EXTEND, "_xdr.c");
Packit 6c4009
      reinitialize ();
Packit 6c4009
      h_output (cmd.infile, "-DRPC_HDR", EXTEND, ".h");
Packit 6c4009
      reinitialize ();
Packit 6c4009
      l_output (cmd.infile, "-DRPC_CLNT", EXTEND, "_clnt.c");
Packit 6c4009
      reinitialize ();
Packit 6c4009
      if (inetdflag || !tirpcflag)
Packit 6c4009
	s_output (allc, allv, cmd.infile, "-DRPC_SVC", EXTEND,
Packit 6c4009
		  "_svc.c", cmd.mflag, cmd.nflag);
Packit 6c4009
      else
Packit 6c4009
	s_output (allnc, allnv, cmd.infile, "-DRPC_SVC",
Packit 6c4009
		  EXTEND, "_svc.c", cmd.mflag, cmd.nflag);
Packit 6c4009
      if (tblflag)
Packit 6c4009
	{
Packit 6c4009
	  reinitialize ();
Packit 6c4009
	  t_output (cmd.infile, "-DRPC_TBL", EXTEND, "_tbl.i");
Packit 6c4009
	}
Packit 6c4009
      if (allfiles)
Packit 6c4009
	{
Packit 6c4009
	  reinitialize ();
Packit 6c4009
	  svc_output (cmd.infile, "-DRPC_SERVER", EXTEND, "_server.c");
Packit 6c4009
	  reinitialize ();
Packit 6c4009
	  clnt_output (cmd.infile, "-DRPC_CLIENT", EXTEND, "_client.c");
Packit 6c4009
	}
Packit 6c4009
      if (allfiles || (cmd.makefileflag == 1))
Packit 6c4009
	{
Packit 6c4009
	  reinitialize ();
Packit 6c4009
	  mkfile_output (&cmd);
Packit 6c4009
	}
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  return nonfatalerrors;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/*
Packit 6c4009
 * add extension to filename
Packit 6c4009
 */
Packit 6c4009
static char *
Packit 6c4009
extendfile (const char *file, const char *ext)
Packit 6c4009
{
Packit 6c4009
  char *res;
Packit 6c4009
  const char *p;
Packit 6c4009
Packit 6c4009
  res = alloc (strlen (file) + strlen (ext) + 1);
Packit 6c4009
  if (res == NULL)
Packit 6c4009
    abort ();
Packit 6c4009
  p = strrchr (file, '.');
Packit 6c4009
  if (p == NULL)
Packit 6c4009
    p = file + strlen (file);
Packit 6c4009
  strcpy (res, file);
Packit 6c4009
  strcpy (res + (p - file), ext);
Packit 6c4009
  return res;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/*
Packit 6c4009
 * Open output file with given extension
Packit 6c4009
 */
Packit 6c4009
static void
Packit 6c4009
open_output (const char *infile, const char *outfile)
Packit 6c4009
{
Packit 6c4009
  if (outfile == NULL)
Packit 6c4009
    {
Packit 6c4009
      fout = stdout;
Packit 6c4009
      return;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  if (infile != NULL && streq (outfile, infile))
Packit 6c4009
    {
Packit 6c4009
      fprintf (stderr, _ ("%s: output would overwrite %s\n"), cmdname,
Packit 6c4009
	       infile);
Packit 6c4009
      crash ();
Packit 6c4009
    }
Packit 6c4009
  fout = fopen (outfile, "w");
Packit 6c4009
  if (fout == NULL)
Packit 6c4009
    {
Packit 6c4009
      fprintf (stderr, _ ("%s: unable to open %s: %m\n"), cmdname, outfile);
Packit 6c4009
      crash ();
Packit 6c4009
    }
Packit 6c4009
  record_open (outfile);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* Close the output file and check for write errors.  */
Packit 6c4009
static void
Packit 6c4009
close_output (const char *outfile)
Packit 6c4009
{
Packit 6c4009
  if (fclose (fout) == EOF)
Packit 6c4009
    {
Packit 6c4009
      fprintf (stderr, _("%s: while writing output %s: %m"), cmdname,
Packit 6c4009
	       outfile ?: "<stdout>");
Packit 6c4009
      crash ();
Packit 6c4009
    }
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
static void
Packit 6c4009
add_warning (void)
Packit 6c4009
{
Packit 6c4009
  fprintf (fout, "/*\n");
Packit 6c4009
  fprintf (fout, " * Please do not edit this file.\n");
Packit 6c4009
  fprintf (fout, " * It was generated using rpcgen.\n");
Packit 6c4009
  fprintf (fout, " */\n\n");
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* clear list of arguments */
Packit 6c4009
static void
Packit 6c4009
clear_args (void)
Packit 6c4009
{
Packit 6c4009
  int i;
Packit 6c4009
  for (i = FIXEDARGS; i < ARGLISTLEN; ++i)
Packit 6c4009
    arglist[i] = NULL;
Packit 6c4009
  argcount = FIXEDARGS;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* make sure that a CPP exists */
Packit 6c4009
static void
Packit 6c4009
find_cpp (void)
Packit 6c4009
{
Packit 6c4009
  struct stat64 buf;
Packit 6c4009
Packit 6c4009
  if (stat64 (CPP, &buf) == 0)
Packit 6c4009
    return;
Packit 6c4009
Packit 6c4009
  if (cppDefined) /* user specified cpp but it does not exist */
Packit 6c4009
    {
Packit 6c4009
      fprintf (stderr, _ ("cannot find C preprocessor: %s\n"), CPP);
Packit 6c4009
      crash ();
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  /* fall back to system CPP */
Packit 6c4009
  CPP = "cpp";
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/*
Packit 6c4009
 * Open input file with given define for C-preprocessor
Packit 6c4009
 */
Packit 6c4009
static void
Packit 6c4009
open_input (const char *infile, const char *define)
Packit 6c4009
{
Packit 6c4009
  int pd[2];
Packit 6c4009
Packit 6c4009
  infilename = (infile == NULL) ? "<stdin>" : infile;
Packit 6c4009
  if (pipe (pd) != 0)
Packit 6c4009
    {
Packit 6c4009
      perror ("pipe");
Packit 6c4009
      exit (1);
Packit 6c4009
    }
Packit 6c4009
  cpp_pid = fork ();
Packit 6c4009
  switch (cpp_pid)
Packit 6c4009
    {
Packit 6c4009
    case 0:
Packit 6c4009
      find_cpp ();
Packit 6c4009
      putarg (0, CPP);
Packit 6c4009
      putarg (1, CPPFLAGS);
Packit 6c4009
      addarg (define);
Packit 6c4009
      if (infile)
Packit 6c4009
	addarg (infile);
Packit 6c4009
      addarg ((char *) NULL);
Packit 6c4009
      close (1);
Packit 6c4009
      dup2 (pd[1], 1);
Packit 6c4009
      close (pd[0]);
Packit 6c4009
      execvp (arglist[0], (char **) arglist);
Packit 6c4009
      if (errno == ENOENT)
Packit 6c4009
        {
Packit 6c4009
          fprintf (stderr, _ ("cannot find C preprocessor: %s\n"), CPP);
Packit 6c4009
          exit (1);
Packit 6c4009
        }
Packit 6c4009
      perror ("execvp");
Packit 6c4009
      exit (1);
Packit 6c4009
    case -1:
Packit 6c4009
      perror ("fork");
Packit 6c4009
      exit (1);
Packit 6c4009
    }
Packit 6c4009
  close (pd[1]);
Packit 6c4009
  fin = fdopen (pd[0], "r");
Packit 6c4009
  if (fin == NULL)
Packit 6c4009
    {
Packit 6c4009
      fprintf (stderr, "%s: ", cmdname);
Packit 6c4009
      perror (infilename);
Packit 6c4009
      crash ();
Packit 6c4009
    }
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* Close the connection to the C-preprocessor and check for successfull
Packit 6c4009
   termination.  */
Packit 6c4009
static void
Packit 6c4009
close_input (void)
Packit 6c4009
{
Packit 6c4009
  int status;
Packit 6c4009
Packit 6c4009
  fclose (fin);
Packit 6c4009
  /* Check the termination status.  */
Packit 6c4009
  if (waitpid (cpp_pid, &status, 0) < 0)
Packit 6c4009
    {
Packit 6c4009
      perror ("waitpid");
Packit 6c4009
      crash ();
Packit 6c4009
    }
Packit 6c4009
  if (WIFSIGNALED (status) || WEXITSTATUS (status) != 0)
Packit 6c4009
    {
Packit 6c4009
      if (WIFSIGNALED (status))
Packit 6c4009
	fprintf (stderr, _("%s: C preprocessor failed with signal %d\n"),
Packit 6c4009
		 cmdname, WTERMSIG (status));
Packit 6c4009
      else
Packit 6c4009
	fprintf (stderr, _("%s: C preprocessor failed with exit code %d\n"),
Packit 6c4009
		 cmdname, WEXITSTATUS (status));
Packit 6c4009
      crash ();
Packit 6c4009
    }
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* valid tirpc nettypes */
Packit 6c4009
static const char *valid_ti_nettypes[] =
Packit 6c4009
{
Packit 6c4009
  "netpath",
Packit 6c4009
  "visible",
Packit 6c4009
  "circuit_v",
Packit 6c4009
  "datagram_v",
Packit 6c4009
  "circuit_n",
Packit 6c4009
  "datagram_n",
Packit 6c4009
  "udp",
Packit 6c4009
  "tcp",
Packit 6c4009
  "raw",
Packit 6c4009
  NULL
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
/* valid inetd nettypes */
Packit 6c4009
static const char *valid_i_nettypes[] =
Packit 6c4009
{
Packit 6c4009
  "udp",
Packit 6c4009
  "tcp",
Packit 6c4009
  NULL
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
static int
Packit 6c4009
check_nettype (const char *name, const char *list_to_check[])
Packit 6c4009
{
Packit 6c4009
  int i;
Packit 6c4009
  for (i = 0; list_to_check[i] != NULL; i++)
Packit 6c4009
    {
Packit 6c4009
      if (strcmp (name, list_to_check[i]) == 0)
Packit 6c4009
	{
Packit 6c4009
	  return 1;
Packit 6c4009
	}
Packit 6c4009
    }
Packit 6c4009
  fprintf (stderr, _ ("illegal nettype: `%s'\n"), name);
Packit 6c4009
  return 0;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/*
Packit 6c4009
 * Compile into an XDR routine output file
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
static void
Packit 6c4009
c_output (const char *infile, const char *define, int extend,
Packit 6c4009
	  const char *outfile)
Packit 6c4009
{
Packit 6c4009
  definition *def;
Packit 6c4009
  char *include;
Packit 6c4009
  const char *outfilename;
Packit 6c4009
  long tell;
Packit 6c4009
Packit 6c4009
  c_initialize ();
Packit 6c4009
  open_input (infile, define);
Packit 6c4009
  outfilename = extend ? extendfile (infile, outfile) : outfile;
Packit 6c4009
  open_output (infile, outfilename);
Packit 6c4009
  add_warning ();
Packit 6c4009
  if (infile && (include = extendfile (infile, ".h")))
Packit 6c4009
    {
Packit 6c4009
      fprintf (fout, "#include \"%s\"\n", include);
Packit 6c4009
      free (include);
Packit 6c4009
      /* .h file already contains rpc/rpc.h */
Packit 6c4009
    }
Packit 6c4009
  else
Packit 6c4009
    fprintf (fout, "#include <rpc/rpc.h>\n");
Packit 6c4009
  tell = ftell (fout);
Packit 6c4009
  while ((def = get_definition ()) != NULL)
Packit 6c4009
    emit (def);
Packit 6c4009
Packit 6c4009
  if (extend && tell == ftell (fout))
Packit 6c4009
    unlink (outfilename);
Packit 6c4009
  close_input ();
Packit 6c4009
  close_output (outfilename);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
void
Packit 6c4009
c_initialize (void)
Packit 6c4009
{
Packit 6c4009
Packit 6c4009
  /* add all the starting basic types */
Packit 6c4009
Packit 6c4009
  add_type (1, "int");
Packit 6c4009
  add_type (1, "long");
Packit 6c4009
  add_type (1, "short");
Packit 6c4009
  add_type (1, "bool");
Packit 6c4009
Packit 6c4009
  add_type (1, "u_int");
Packit 6c4009
  add_type (1, "u_long");
Packit 6c4009
  add_type (1, "u_short");
Packit 6c4009
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
char rpcgen_table_dcl[] = "struct rpcgen_table {\n\
Packit 6c4009
	char	*(*proc)();\n\
Packit 6c4009
	xdrproc_t	xdr_arg;\n\
Packit 6c4009
	unsigned	len_arg;\n\
Packit 6c4009
	xdrproc_t	xdr_res;\n\
Packit 6c4009
	unsigned	len_res;\n\
Packit 6c4009
};\n";
Packit 6c4009
Packit 6c4009
Packit 6c4009
static char *
Packit 6c4009
generate_guard (const char *pathname)
Packit 6c4009
{
Packit 6c4009
  const char *filename;
Packit 6c4009
  char *guard, *tmp;
Packit 6c4009
Packit 6c4009
  filename = strrchr (pathname, '/');	/* find last component */
Packit 6c4009
  filename = ((filename == NULL) ? pathname : filename + 1);
Packit 6c4009
  guard = extendfile (filename, "_H_RPCGEN");
Packit 6c4009
  /* convert to upper case */
Packit 6c4009
  tmp = guard;
Packit 6c4009
  while (*tmp)
Packit 6c4009
    {
Packit 6c4009
      if (islower (*tmp))
Packit 6c4009
	*tmp = toupper (*tmp);
Packit 6c4009
      tmp++;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  return guard;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/*
Packit 6c4009
 * Compile into an XDR header file
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
Packit 6c4009
static void
Packit 6c4009
h_output (const char *infile, const char *define, int extend,
Packit 6c4009
	  const char *outfile)
Packit 6c4009
{
Packit 6c4009
  xdrfunc *xdrfuncp;
Packit 6c4009
  definition *def;
Packit 6c4009
  const char *ifilename;
Packit 6c4009
  const char *outfilename;
Packit 6c4009
  long tell;
Packit 6c4009
  char *guard;
Packit 6c4009
  list *l;
Packit 6c4009
Packit 6c4009
  open_input (infile, define);
Packit 6c4009
  outfilename = extend ? extendfile (infile, outfile) : outfile;
Packit 6c4009
  open_output (infile, outfilename);
Packit 6c4009
  add_warning ();
Packit 6c4009
  ifilename = (infile == NULL) ? "STDIN" : infile;
Packit 6c4009
  guard = generate_guard (outfilename ? outfilename : ifilename);
Packit 6c4009
Packit 6c4009
  fprintf (fout, "#ifndef _%s\n#define _%s\n\n", guard,
Packit 6c4009
	   guard);
Packit 6c4009
Packit 6c4009
  fprintf (fout, "#include <rpc/rpc.h>\n\n");
Packit 6c4009
Packit 6c4009
  if (mtflag)
Packit 6c4009
    {
Packit 6c4009
      fprintf (fout, "#include <pthread.h>\n");
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  /* put the C++ support */
Packit 6c4009
  if (Cflag && !CCflag)
Packit 6c4009
    {
Packit 6c4009
      fprintf (fout, "\n#ifdef __cplusplus\n");
Packit 6c4009
      fprintf (fout, "extern \"C\" {\n");
Packit 6c4009
      fprintf (fout, "#endif\n\n");
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  tell = ftell (fout);
Packit 6c4009
  /* print data definitions */
Packit 6c4009
  while ((def = get_definition ()) != NULL)
Packit 6c4009
    {
Packit 6c4009
      print_datadef (def);
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  /* print function declarations.
Packit 6c4009
     Do this after data definitions because they might be used as
Packit 6c4009
     arguments for functions */
Packit 6c4009
  for (l = defined; l != NULL; l = l->next)
Packit 6c4009
    {
Packit 6c4009
      print_funcdef (l->val);
Packit 6c4009
    }
Packit 6c4009
  /* Now  print all xdr func declarations */
Packit 6c4009
  if (xdrfunc_head != NULL)
Packit 6c4009
    {
Packit 6c4009
      fprintf (fout, "\n/* the xdr functions */\n");
Packit 6c4009
      if (CCflag)
Packit 6c4009
	{
Packit 6c4009
	  fprintf (fout, "\n#ifdef __cplusplus\n");
Packit 6c4009
	  fprintf (fout, "extern \"C\" {\n");
Packit 6c4009
	  fprintf (fout, "#endif\n");
Packit 6c4009
	}
Packit 6c4009
      if (!Cflag)
Packit 6c4009
	{
Packit 6c4009
	  xdrfuncp = xdrfunc_head;
Packit 6c4009
	  while (xdrfuncp != NULL)
Packit 6c4009
	    {
Packit 6c4009
	      print_xdr_func_def (xdrfuncp->name,
Packit 6c4009
				  xdrfuncp->pointerp, 2);
Packit 6c4009
	      xdrfuncp = xdrfuncp->next;
Packit 6c4009
	    }
Packit 6c4009
	}
Packit 6c4009
      else
Packit 6c4009
	{
Packit 6c4009
	  int i;
Packit 6c4009
Packit 6c4009
	  for (i = 1; i < 3; ++i)
Packit 6c4009
	    {
Packit 6c4009
	      if (i == 1)
Packit 6c4009
		fprintf (fout, "\n#if defined(__STDC__) || defined(__cplusplus)\n");
Packit 6c4009
	      else
Packit 6c4009
		fprintf (fout, "\n#else /* K&R C */\n");
Packit 6c4009
Packit 6c4009
	      xdrfuncp = xdrfunc_head;
Packit 6c4009
	      while (xdrfuncp != NULL)
Packit 6c4009
		{
Packit 6c4009
		  print_xdr_func_def (xdrfuncp->name,
Packit 6c4009
				      xdrfuncp->pointerp, i);
Packit 6c4009
		  xdrfuncp = xdrfuncp->next;
Packit 6c4009
		}
Packit 6c4009
	    }
Packit 6c4009
	  fprintf (fout, "\n#endif /* K&R C */\n");
Packit 6c4009
	}
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  if (extend && tell == ftell (fout))
Packit 6c4009
    {
Packit 6c4009
      unlink (outfilename);
Packit 6c4009
    }
Packit 6c4009
  else if (tblflag)
Packit 6c4009
    {
Packit 6c4009
      fprintf (fout, "%s", rpcgen_table_dcl);
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  if (Cflag)
Packit 6c4009
    {
Packit 6c4009
      fprintf (fout, "\n#ifdef __cplusplus\n");
Packit 6c4009
      fprintf (fout, "}\n");
Packit 6c4009
      fprintf (fout, "#endif\n");
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  fprintf (fout, "\n#endif /* !_%s */\n", guard);
Packit 6c4009
  free (guard);
Packit 6c4009
  close_input ();
Packit 6c4009
  close_output (outfilename);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/*
Packit 6c4009
 * Compile into an RPC service
Packit 6c4009
 */
Packit 6c4009
static void
Packit 6c4009
s_output (int argc, const char *argv[], const char *infile, const char *define,
Packit 6c4009
	  int extend, const char *outfile, int nomain, int netflag)
Packit 6c4009
{
Packit 6c4009
  char *include;
Packit 6c4009
  definition *def;
Packit 6c4009
  int foundprogram = 0;
Packit 6c4009
  const char *outfilename;
Packit 6c4009
Packit 6c4009
  open_input (infile, define);
Packit 6c4009
  outfilename = extend ? extendfile (infile, outfile) : outfile;
Packit 6c4009
  open_output (infile, outfilename);
Packit 6c4009
  add_warning ();
Packit 6c4009
  if (infile && (include = extendfile (infile, ".h")))
Packit 6c4009
    {
Packit 6c4009
      fprintf (fout, "#include \"%s\"\n", include);
Packit 6c4009
      free (include);
Packit 6c4009
    }
Packit 6c4009
  else
Packit 6c4009
    fprintf (fout, "#include <rpc/rpc.h>\n");
Packit 6c4009
Packit 6c4009
  fprintf (fout, "#include <stdio.h>\n");
Packit 6c4009
  fprintf (fout, "#include <stdlib.h>\n");
Packit 6c4009
  fprintf (fout, "#include <rpc/pmap_clnt.h>\n");
Packit 6c4009
  if (Cflag)
Packit 6c4009
    fprintf (fout, "#include <string.h>\n");
Packit 6c4009
  if (strcmp (svcclosetime, "-1") == 0)
Packit 6c4009
    indefinitewait = 1;
Packit 6c4009
  else if (strcmp (svcclosetime, "0") == 0)
Packit 6c4009
    exitnow = 1;
Packit 6c4009
  else if (inetdflag || pmflag)
Packit 6c4009
    {
Packit 6c4009
      fprintf (fout, "#include <signal.h>\n");
Packit 6c4009
      timerflag = 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  if (!tirpcflag && inetdflag)
Packit 6c4009
    fprintf (fout, "#include <sys/ioctl.h> /* ioctl, TIOCNOTTY */\n");
Packit 6c4009
  if (Cflag && (inetdflag || pmflag))
Packit 6c4009
    {
Packit 6c4009
      fprintf (fout, "#include <sys/types.h> /* open */\n");
Packit 6c4009
      fprintf (fout, "#include <sys/stat.h> /* open */\n");
Packit 6c4009
      fprintf (fout, "#include <fcntl.h> /* open */\n");
Packit 6c4009
      fprintf (fout, "#include <unistd.h> /* getdtablesize */\n");
Packit 6c4009
    }
Packit 6c4009
  if (tirpcflag && !(Cflag && (inetdflag || pmflag)))
Packit 6c4009
    fprintf (fout, "#include <sys/types.h>\n");
Packit 6c4009
Packit 6c4009
  fprintf (fout, "#include <memory.h>\n");
Packit 6c4009
  if (inetdflag || !tirpcflag)
Packit 6c4009
    {
Packit 6c4009
      fprintf (fout, "#include <sys/socket.h>\n");
Packit 6c4009
      fprintf (fout, "#include <netinet/in.h>\n");
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  if ((netflag || pmflag) && tirpcflag && !nomain)
Packit 6c4009
    {
Packit 6c4009
      fprintf (fout, "#include <netconfig.h>\n");
Packit 6c4009
    }
Packit 6c4009
  if ( /*timerflag && */ tirpcflag)
Packit 6c4009
    fprintf (fout, "#include <sys/resource.h> /* rlimit */\n");
Packit 6c4009
  if (logflag || inetdflag || pmflag)
Packit 6c4009
    {
Packit 6c4009
      fprintf (fout, "#include <syslog.h>\n");
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  /* for ANSI-C */
Packit 6c4009
  if (Cflag)
Packit 6c4009
    fprintf (fout, "\n#ifndef SIG_PF\n#define SIG_PF void(*)(int)\n#endif\n");
Packit 6c4009
Packit 6c4009
  if (timerflag)
Packit 6c4009
    fprintf (fout, "\n#define _RPCSVC_CLOSEDOWN %s\n", svcclosetime);
Packit 6c4009
  while ((def = get_definition ()) != NULL)
Packit 6c4009
    {
Packit 6c4009
      foundprogram |= (def->def_kind == DEF_PROGRAM);
Packit 6c4009
    }
Packit 6c4009
  if (extend && !foundprogram)
Packit 6c4009
    {
Packit 6c4009
      unlink (outfilename);
Packit 6c4009
      return;
Packit 6c4009
    }
Packit 6c4009
  write_most (infile, netflag, nomain);
Packit 6c4009
  if (!nomain)
Packit 6c4009
    {
Packit 6c4009
      if (!do_registers (argc, argv))
Packit 6c4009
	{
Packit 6c4009
	  if (outfilename)
Packit 6c4009
	    unlink (outfilename);
Packit 6c4009
	  usage (stderr, 1);
Packit 6c4009
	}
Packit 6c4009
      write_rest ();
Packit 6c4009
    }
Packit 6c4009
  close_input ();
Packit 6c4009
  close_output (outfilename);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/*
Packit 6c4009
 * generate client side stubs
Packit 6c4009
 */
Packit 6c4009
static void
Packit 6c4009
l_output (const char *infile, const char *define, int extend,
Packit 6c4009
	  const char *outfile)
Packit 6c4009
{
Packit 6c4009
  char *include;
Packit 6c4009
  definition *def;
Packit 6c4009
  int foundprogram = 0;
Packit 6c4009
  const char *outfilename;
Packit 6c4009
Packit 6c4009
  open_input (infile, define);
Packit 6c4009
  outfilename = extend ? extendfile (infile, outfile) : outfile;
Packit 6c4009
  open_output (infile, outfilename);
Packit 6c4009
  add_warning ();
Packit 6c4009
  if (Cflag)
Packit 6c4009
    fprintf (fout, "#include <memory.h> /* for memset */\n");
Packit 6c4009
  if (infile && (include = extendfile (infile, ".h")))
Packit 6c4009
    {
Packit 6c4009
      fprintf (fout, "#include \"%s\"\n", include);
Packit 6c4009
      free (include);
Packit 6c4009
    }
Packit 6c4009
  else
Packit 6c4009
    fprintf (fout, "#include <rpc/rpc.h>\n");
Packit 6c4009
  while ((def = get_definition ()) != NULL)
Packit 6c4009
    {
Packit 6c4009
      foundprogram |= (def->def_kind == DEF_PROGRAM);
Packit 6c4009
    }
Packit 6c4009
  if (extend && !foundprogram)
Packit 6c4009
    {
Packit 6c4009
      unlink (outfilename);
Packit 6c4009
      return;
Packit 6c4009
    }
Packit 6c4009
  write_stubs ();
Packit 6c4009
  close_input ();
Packit 6c4009
  close_output (outfilename);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/*
Packit 6c4009
 * generate the dispatch table
Packit 6c4009
 */
Packit 6c4009
static void
Packit 6c4009
t_output (const char *infile, const char *define, int extend,
Packit 6c4009
	  const char *outfile)
Packit 6c4009
{
Packit 6c4009
  definition *def;
Packit 6c4009
  int foundprogram = 0;
Packit 6c4009
  const char *outfilename;
Packit 6c4009
Packit 6c4009
  open_input (infile, define);
Packit 6c4009
  outfilename = extend ? extendfile (infile, outfile) : outfile;
Packit 6c4009
  open_output (infile, outfilename);
Packit 6c4009
  add_warning ();
Packit 6c4009
  while ((def = get_definition ()) != NULL)
Packit 6c4009
    {
Packit 6c4009
      foundprogram |= (def->def_kind == DEF_PROGRAM);
Packit 6c4009
    }
Packit 6c4009
  if (extend && !foundprogram)
Packit 6c4009
    {
Packit 6c4009
      unlink (outfilename);
Packit 6c4009
      return;
Packit 6c4009
    }
Packit 6c4009
  write_tables ();
Packit 6c4009
  close_input ();
Packit 6c4009
  close_output (outfilename);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* sample routine for the server template */
Packit 6c4009
static void
Packit 6c4009
svc_output (const char *infile, const char *define, int extend,
Packit 6c4009
	    const char *outfile)
Packit 6c4009
{
Packit 6c4009
  definition *def;
Packit 6c4009
  char *include;
Packit 6c4009
  const char *outfilename;
Packit 6c4009
  long tell;
Packit 6c4009
Packit 6c4009
  open_input (infile, define);
Packit 6c4009
  outfilename = extend ? extendfile (infile, outfile) : outfile;
Packit 6c4009
  checkfiles (infile, outfilename);
Packit 6c4009
  /*check if outfile already exists.
Packit 6c4009
     if so, print an error message and exit */
Packit 6c4009
  open_output (infile, outfilename);
Packit 6c4009
  add_sample_msg ();
Packit 6c4009
Packit 6c4009
  if (infile && (include = extendfile (infile, ".h")))
Packit 6c4009
    {
Packit 6c4009
      fprintf (fout, "#include \"%s\"\n", include);
Packit 6c4009
      free (include);
Packit 6c4009
    }
Packit 6c4009
  else
Packit 6c4009
    fprintf (fout, "#include <rpc/rpc.h>\n");
Packit 6c4009
Packit 6c4009
  tell = ftell (fout);
Packit 6c4009
  while ((def = get_definition ()) != NULL)
Packit 6c4009
    {
Packit 6c4009
      write_sample_svc (def);
Packit 6c4009
    }
Packit 6c4009
  if (extend && tell == ftell (fout))
Packit 6c4009
    {
Packit 6c4009
      unlink (outfilename);
Packit 6c4009
    }
Packit 6c4009
  close_input ();
Packit 6c4009
  close_output (outfilename);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* sample main routine for client */
Packit 6c4009
static void
Packit 6c4009
clnt_output (const char *infile, const char *define, int extend,
Packit 6c4009
	     const char *outfile)
Packit 6c4009
{
Packit 6c4009
  definition *def;
Packit 6c4009
  char *include;
Packit 6c4009
  const char *outfilename;
Packit 6c4009
  long tell;
Packit 6c4009
  int has_program = 0;
Packit 6c4009
Packit 6c4009
  open_input (infile, define);
Packit 6c4009
  outfilename = extend ? extendfile (infile, outfile) : outfile;
Packit 6c4009
  checkfiles (infile, outfilename);
Packit 6c4009
  /*check if outfile already exists.
Packit 6c4009
     if so, print an error message and exit */
Packit 6c4009
Packit 6c4009
  open_output (infile, outfilename);
Packit 6c4009
  add_sample_msg ();
Packit 6c4009
  if (infile && (include = extendfile (infile, ".h")))
Packit 6c4009
    {
Packit 6c4009
      fprintf (fout, "#include \"%s\"\n", include);
Packit 6c4009
      free (include);
Packit 6c4009
    }
Packit 6c4009
  else
Packit 6c4009
    fprintf (fout, "#include <rpc/rpc.h>\n");
Packit 6c4009
  tell = ftell (fout);
Packit 6c4009
  while ((def = get_definition ()) != NULL)
Packit 6c4009
    {
Packit 6c4009
      has_program += write_sample_clnt (def);
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  if (has_program)
Packit 6c4009
    write_sample_clnt_main ();
Packit 6c4009
Packit 6c4009
  if (extend && tell == ftell (fout))
Packit 6c4009
    {
Packit 6c4009
      unlink (outfilename);
Packit 6c4009
    }
Packit 6c4009
  close_input ();
Packit 6c4009
  close_output (outfilename);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
static const char space[] = " ";
Packit 6c4009
Packit 6c4009
static char *
Packit 6c4009
file_name (const char *file, const char *ext)
Packit 6c4009
{
Packit 6c4009
  char *temp;
Packit 6c4009
  temp = extendfile (file, ext);
Packit 6c4009
Packit 6c4009
  if (access (temp, F_OK) != -1)
Packit 6c4009
    return (temp);
Packit 6c4009
Packit 6c4009
  free (temp);
Packit 6c4009
  return (char *) space;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
static void
Packit 6c4009
mkfile_output (struct commandline *cmd)
Packit 6c4009
{
Packit 6c4009
  char *mkfilename;
Packit 6c4009
  char *clientname, *clntname, *xdrname, *hdrname;
Packit 6c4009
  char *servername, *svcname, *servprogname, *clntprogname;
Packit 6c4009
Packit 6c4009
  svcname = file_name (cmd->infile, "_svc.c");
Packit 6c4009
  clntname = file_name (cmd->infile, "_clnt.c");
Packit 6c4009
  xdrname = file_name (cmd->infile, "_xdr.c");
Packit 6c4009
  hdrname = file_name (cmd->infile, ".h");
Packit 6c4009
Packit 6c4009
  if (allfiles)
Packit 6c4009
    {
Packit 6c4009
      servername = extendfile (cmd->infile, "_server.c");
Packit 6c4009
      clientname = extendfile (cmd->infile, "_client.c");
Packit 6c4009
    }
Packit 6c4009
  else
Packit 6c4009
    {
Packit 6c4009
      servername = (char *) space;
Packit 6c4009
      clientname = (char *) space;
Packit 6c4009
    }
Packit 6c4009
  servprogname = extendfile (cmd->infile, "_server");
Packit 6c4009
  clntprogname = extendfile (cmd->infile, "_client");
Packit 6c4009
Packit 6c4009
  if (allfiles)
Packit 6c4009
    {
Packit 6c4009
      char *cp, *temp;
Packit 6c4009
Packit 6c4009
      mkfilename = alloc (strlen ("Makefile.") + strlen (cmd->infile) + 1);
Packit 6c4009
      if (mkfilename == NULL)
Packit 6c4009
	abort ();
Packit 6c4009
      temp = strrchr (cmd->infile, '.');
Packit 6c4009
      cp = stpcpy (mkfilename, "Makefile.");
Packit 6c4009
      if (temp != NULL)
Packit 6c4009
	*((char *) stpncpy (cp, cmd->infile, temp - cmd->infile)) = '\0';
Packit 6c4009
      else
Packit 6c4009
	stpcpy (cp, cmd->infile);
Packit 6c4009
Packit 6c4009
    }
Packit 6c4009
  else
Packit 6c4009
    mkfilename = (char *) cmd->outfile;
Packit 6c4009
Packit 6c4009
  checkfiles (NULL, mkfilename);
Packit 6c4009
  open_output (NULL, mkfilename);
Packit 6c4009
Packit 6c4009
  fprintf (fout, "\n# This is a template Makefile generated by rpcgen\n");
Packit 6c4009
Packit 6c4009
  f_print (fout, "\n# Parameters\n\n");
Packit 6c4009
Packit 6c4009
  f_print (fout, "CLIENT = %s\nSERVER = %s\n\n", clntprogname, servprogname);
Packit 6c4009
  f_print (fout, "SOURCES_CLNT.c = \nSOURCES_CLNT.h = \n");
Packit 6c4009
  f_print (fout, "SOURCES_SVC.c = \nSOURCES_SVC.h = \n");
Packit 6c4009
  f_print (fout, "SOURCES.x = %s\n\n", cmd->infile);
Packit 6c4009
  f_print (fout, "TARGETS_SVC.c = %s %s %s \n",
Packit 6c4009
	   svcname, servername, xdrname);
Packit 6c4009
  f_print (fout, "TARGETS_CLNT.c = %s %s %s \n",
Packit 6c4009
	   clntname, clientname, xdrname);
Packit 6c4009
  f_print (fout, "TARGETS = %s %s %s %s %s %s\n\n",
Packit 6c4009
	   hdrname, xdrname, clntname,
Packit 6c4009
	   svcname, clientname, servername);
Packit 6c4009
Packit 6c4009
  f_print (fout, "OBJECTS_CLNT = $(SOURCES_CLNT.c:%%.c=%%.o) \
Packit 6c4009
$(TARGETS_CLNT.c:%%.c=%%.o)");
Packit 6c4009
Packit 6c4009
  f_print (fout, "\nOBJECTS_SVC = $(SOURCES_SVC.c:%%.c=%%.o) \
Packit 6c4009
$(TARGETS_SVC.c:%%.c=%%.o)");
Packit 6c4009
Packit 6c4009
  f_print (fout, "\n# Compiler flags \n");
Packit 6c4009
  if (mtflag)
Packit 6c4009
    fprintf (fout, "\nCPPFLAGS += -D_REENTRANT\nCFLAGS += -g \nLDLIBS \
Packit 6c4009
+= -lnsl -lpthread \n ");
Packit 6c4009
  else
Packit 6c4009
    f_print (fout, "\nCFLAGS += -g \nLDLIBS += -lnsl\n");
Packit 6c4009
  f_print (fout, "RPCGENFLAGS = \n");
Packit 6c4009
Packit 6c4009
  f_print (fout, "\n# Targets \n\n");
Packit 6c4009
Packit 6c4009
  f_print (fout, "all : $(CLIENT) $(SERVER)\n\n");
Packit 6c4009
  f_print (fout, "$(TARGETS) : $(SOURCES.x) \n");
Packit 6c4009
  f_print (fout, "\trpcgen $(RPCGENFLAGS) $(SOURCES.x)\n\n");
Packit 6c4009
  f_print (fout, "$(OBJECTS_CLNT) : $(SOURCES_CLNT.c) $(SOURCES_CLNT.h) \
Packit 6c4009
$(TARGETS_CLNT.c) \n\n");
Packit 6c4009
Packit 6c4009
  f_print (fout, "$(OBJECTS_SVC) : $(SOURCES_SVC.c) $(SOURCES_SVC.h) \
Packit 6c4009
$(TARGETS_SVC.c) \n\n");
Packit 6c4009
  f_print (fout, "$(CLIENT) : $(OBJECTS_CLNT) \n");
Packit 6c4009
  f_print (fout, "\t$(LINK.c) -o $(CLIENT) $(OBJECTS_CLNT) \
Packit 6c4009
$(LDLIBS) \n\n");
Packit 6c4009
  f_print (fout, "$(SERVER) : $(OBJECTS_SVC) \n");
Packit 6c4009
  f_print (fout, "\t$(LINK.c) -o $(SERVER) $(OBJECTS_SVC) $(LDLIBS)\n\n ");
Packit 6c4009
  f_print (fout, "clean:\n\t $(RM) core $(TARGETS) $(OBJECTS_CLNT) \
Packit 6c4009
$(OBJECTS_SVC) $(CLIENT) $(SERVER)\n\n");
Packit 6c4009
  close_output (mkfilename);
Packit 6c4009
Packit 6c4009
  free (clntprogname);
Packit 6c4009
  free (servprogname);
Packit 6c4009
  if (servername != space)
Packit 6c4009
    free (servername);
Packit 6c4009
  if (clientname != space)
Packit 6c4009
    free (clientname);
Packit 6c4009
  if (mkfilename != (char *) cmd->outfile)
Packit 6c4009
    free (mkfilename);
Packit 6c4009
  if (svcname != space)
Packit 6c4009
    free (svcname);
Packit 6c4009
  if (clntname != space)
Packit 6c4009
    free (clntname);
Packit 6c4009
  if (xdrname != space)
Packit 6c4009
    free (xdrname);
Packit 6c4009
  if (hdrname != space)
Packit 6c4009
    free (hdrname);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/*
Packit 6c4009
 * Perform registrations for service output
Packit 6c4009
 * Return 0 if failed; 1 otherwise.
Packit 6c4009
 */
Packit 6c4009
static int
Packit 6c4009
do_registers (int argc, const char *argv[])
Packit 6c4009
{
Packit 6c4009
  int i;
Packit 6c4009
Packit 6c4009
  if (inetdflag || !tirpcflag)
Packit 6c4009
    {
Packit 6c4009
      for (i = 1; i < argc; i++)
Packit 6c4009
	{
Packit 6c4009
	  if (streq (argv[i], "-s"))
Packit 6c4009
	    {
Packit 6c4009
	      if (!check_nettype (argv[i + 1], valid_i_nettypes))
Packit 6c4009
		return 0;
Packit 6c4009
	      write_inetd_register (argv[i + 1]);
Packit 6c4009
	      i++;
Packit 6c4009
	    }
Packit 6c4009
	}
Packit 6c4009
    }
Packit 6c4009
  else
Packit 6c4009
    {
Packit 6c4009
      for (i = 1; i < argc; i++)
Packit 6c4009
	if (streq (argv[i], "-s"))
Packit 6c4009
	  {
Packit 6c4009
	    if (!check_nettype (argv[i + 1], valid_ti_nettypes))
Packit 6c4009
	      return 0;
Packit 6c4009
	    write_nettype_register (argv[i + 1]);
Packit 6c4009
	    i++;
Packit 6c4009
	  }
Packit 6c4009
	else if (streq (argv[i], "-n"))
Packit 6c4009
	  {
Packit 6c4009
	    write_netid_register (argv[i + 1]);
Packit 6c4009
	    i++;
Packit 6c4009
	  }
Packit 6c4009
    }
Packit 6c4009
  return 1;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/*
Packit 6c4009
 * Add another argument to the arg list
Packit 6c4009
 */
Packit 6c4009
static void
Packit 6c4009
addarg (const char *cp)
Packit 6c4009
{
Packit 6c4009
  if (argcount >= ARGLISTLEN)
Packit 6c4009
    {
Packit 6c4009
      fprintf (stderr, _("rpcgen: too many defines\n"));
Packit 6c4009
      crash ();
Packit 6c4009
      /*NOTREACHED */
Packit 6c4009
    }
Packit 6c4009
  arglist[argcount++] = cp;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
static void
Packit 6c4009
putarg (int whereto, const char *cp)
Packit 6c4009
{
Packit 6c4009
  if (whereto >= ARGLISTLEN)
Packit 6c4009
    {
Packit 6c4009
      fprintf (stderr, _("rpcgen: arglist coding error\n"));
Packit 6c4009
      crash ();
Packit 6c4009
      /*NOTREACHED */
Packit 6c4009
    }
Packit 6c4009
  arglist[whereto] = cp;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/*
Packit 6c4009
 * if input file is stdin and an output file is specified then complain
Packit 6c4009
 * if the file already exists. Otherwise the file may get overwritten
Packit 6c4009
 * If input file does not exist, exit with an error
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
static void
Packit 6c4009
checkfiles (const char *infile, const char *outfile)
Packit 6c4009
{
Packit 6c4009
  struct stat64 buf;
Packit 6c4009
Packit 6c4009
  if (infile)			/* infile ! = NULL */
Packit 6c4009
    if (stat64 (infile, &buf) < 0)
Packit 6c4009
      {
Packit 6c4009
	perror (infile);
Packit 6c4009
	crash ();
Packit 6c4009
      }
Packit 6c4009
  if (outfile)
Packit 6c4009
    {
Packit 6c4009
      if (stat64 (outfile, &buf) < 0)
Packit 6c4009
	return;			/* file does not exist */
Packit 6c4009
      else
Packit 6c4009
	{
Packit 6c4009
	  fprintf (stderr,
Packit 6c4009
		   /* TRANS: the file will not be removed; this is an
Packit 6c4009
		      TRANS: informative message.  */
Packit 6c4009
		   _("file `%s' already exists and may be overwritten\n"),
Packit 6c4009
		   outfile);
Packit 6c4009
	  crash ();
Packit 6c4009
	}
Packit 6c4009
    }
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/*
Packit 6c4009
 * Parse command line arguments
Packit 6c4009
 */
Packit 6c4009
static int
Packit 6c4009
parseargs (int argc, const char *argv[], struct commandline *cmd)
Packit 6c4009
{
Packit 6c4009
  int i;
Packit 6c4009
  int j;
Packit 6c4009
  int c;
Packit 6c4009
  char flag[(1 << 8 * sizeof (char))];
Packit 6c4009
  int nflags;
Packit 6c4009
Packit 6c4009
  cmdname = argv[0];
Packit 6c4009
  cmd->infile = cmd->outfile = NULL;
Packit 6c4009
  if (argc < 2)
Packit 6c4009
    {
Packit 6c4009
      return (0);
Packit 6c4009
    }
Packit 6c4009
  allfiles = 0;
Packit 6c4009
  flag['c'] = 0;
Packit 6c4009
  flag['h'] = 0;
Packit 6c4009
  flag['l'] = 0;
Packit 6c4009
  flag['m'] = 0;
Packit 6c4009
  flag['o'] = 0;
Packit 6c4009
  flag['s'] = 0;
Packit 6c4009
  flag['n'] = 0;
Packit 6c4009
  flag['t'] = 0;
Packit 6c4009
  flag['S'] = 0;
Packit 6c4009
  flag['C'] = 0;
Packit 6c4009
  flag['M'] = 0;
Packit 6c4009
Packit 6c4009
  for (i = 1; i < argc; i++)
Packit 6c4009
    {
Packit 6c4009
      if (argv[i][0] != '-')
Packit 6c4009
	{
Packit 6c4009
	  if (cmd->infile)
Packit 6c4009
	    {
Packit 6c4009
	      fprintf (stderr,
Packit 6c4009
		       _("Cannot specify more than one input file!\n"));
Packit 6c4009
	      return 0;
Packit 6c4009
	    }
Packit 6c4009
	  cmd->infile = argv[i];
Packit 6c4009
	}
Packit 6c4009
      else if (strcmp (argv[i], "--help") == 0)
Packit 6c4009
	usage (stdout, 0);
Packit 6c4009
      else if (strcmp (argv[i], "--version") == 0)
Packit 6c4009
	print_version ();
Packit 6c4009
      else
Packit 6c4009
	{
Packit 6c4009
	  for (j = 1; argv[i][j] != 0; j++)
Packit 6c4009
	    {
Packit 6c4009
	      c = argv[i][j];
Packit 6c4009
	      switch (c)
Packit 6c4009
		{
Packit 6c4009
		case 'a':
Packit 6c4009
		  allfiles = 1;
Packit 6c4009
		  break;
Packit 6c4009
		case 'c':
Packit 6c4009
		case 'h':
Packit 6c4009
		case 'l':
Packit 6c4009
		case 'm':
Packit 6c4009
		case 't':
Packit 6c4009
		  if (flag[c])
Packit 6c4009
		    return 0;
Packit 6c4009
		  flag[c] = 1;
Packit 6c4009
		  break;
Packit 6c4009
		case 'S':
Packit 6c4009
		  /* sample flag: Ss or Sc.
Packit 6c4009
		     Ss means set flag['S'];
Packit 6c4009
		     Sc means set flag['C'];
Packit 6c4009
		     Sm means set flag['M']; */
Packit 6c4009
 		  c = argv[i][++j];	/* get next char */
Packit 6c4009
		  if (c == 's')
Packit 6c4009
		    c = 'S';
Packit 6c4009
		  else if (c == 'c')
Packit 6c4009
		    c = 'C';
Packit 6c4009
		  else if (c == 'm')
Packit 6c4009
		    c = 'M';
Packit 6c4009
		  else
Packit 6c4009
		    return 0;
Packit 6c4009
Packit 6c4009
		  if (flag[c])
Packit 6c4009
		    return 0;
Packit 6c4009
		  flag[c] = 1;
Packit 6c4009
		  break;
Packit 6c4009
		case 'C':	/* ANSI C syntax */
Packit 6c4009
		  Cflag = 1;
Packit 6c4009
		  break;
Packit 6c4009
Packit 6c4009
		case 'k':  /* K&R C syntax */
Packit 6c4009
		  Cflag = 0;
Packit 6c4009
		  break;
Packit 6c4009
Packit 6c4009
		case 'b':  /* turn TIRPC flag off for
Packit 6c4009
			      generating backward compatible
Packit 6c4009
			   */
Packit 6c4009
		  tirpcflag = 0;
Packit 6c4009
		  break;
Packit 6c4009
Packit 6c4009
		case '5':  /* turn TIRPC flag on for
Packit 6c4009
			      generating SysVr4 compatible
Packit 6c4009
			   */
Packit 6c4009
		  tirpcflag = 1;
Packit 6c4009
		  break;
Packit 6c4009
		case 'I':
Packit 6c4009
		  inetdflag = 1;
Packit 6c4009
		  break;
Packit 6c4009
		case 'N':
Packit 6c4009
		  newstyle = 1;
Packit 6c4009
		  break;
Packit 6c4009
		case 'L':
Packit 6c4009
		  logflag = 1;
Packit 6c4009
		  break;
Packit 6c4009
		case 'K':
Packit 6c4009
		  if (++i == argc)
Packit 6c4009
		    {
Packit 6c4009
		      return (0);
Packit 6c4009
		    }
Packit 6c4009
		  svcclosetime = argv[i];
Packit 6c4009
		  goto nextarg;
Packit 6c4009
		case 'T':
Packit 6c4009
		  tblflag = 1;
Packit 6c4009
		  break;
Packit 6c4009
		case 'M':
Packit 6c4009
		  mtflag = 1;
Packit 6c4009
		  break;
Packit 6c4009
		case 'i':
Packit 6c4009
		  if (++i == argc)
Packit 6c4009
		    {
Packit 6c4009
		      return (0);
Packit 6c4009
		    }
Packit 6c4009
		  inlineflag = atoi (argv[i]);
Packit 6c4009
		  goto nextarg;
Packit 6c4009
		case 'n':
Packit 6c4009
		case 'o':
Packit 6c4009
		case 's':
Packit 6c4009
		  if (argv[i][j - 1] != '-' ||
Packit 6c4009
		      argv[i][j + 1] != 0)
Packit 6c4009
		    {
Packit 6c4009
		      return (0);
Packit 6c4009
		    }
Packit 6c4009
		  flag[c] = 1;
Packit 6c4009
		  if (++i == argc)
Packit 6c4009
		    {
Packit 6c4009
		      return (0);
Packit 6c4009
		    }
Packit 6c4009
		  if (c == 's')
Packit 6c4009
		    {
Packit 6c4009
		      if (!streq (argv[i], "udp") &&
Packit 6c4009
			  !streq (argv[i], "tcp"))
Packit 6c4009
			return 0;
Packit 6c4009
		    }
Packit 6c4009
		  else if (c == 'o')
Packit 6c4009
		    {
Packit 6c4009
		      if (cmd->outfile)
Packit 6c4009
			return 0;
Packit 6c4009
		      cmd->outfile = argv[i];
Packit 6c4009
		    }
Packit 6c4009
		  goto nextarg;
Packit 6c4009
		case 'D':
Packit 6c4009
		  if (argv[i][j - 1] != '-')
Packit 6c4009
		    return 0;
Packit 6c4009
		  addarg (argv[i]);
Packit 6c4009
		  goto nextarg;
Packit 6c4009
		case 'Y':
Packit 6c4009
		  if (++i == argc)
Packit 6c4009
		    return 0;
Packit 6c4009
		  {
Packit 6c4009
		    size_t len = strlen (argv[i]);
Packit 6c4009
		    pathbuf = malloc (len + 5);
Packit 6c4009
		    if (pathbuf == NULL)
Packit 6c4009
		      {
Packit 6c4009
			perror (cmdname);
Packit 6c4009
			crash ();
Packit 6c4009
		      }
Packit 6c4009
		    stpcpy (stpcpy (pathbuf,
Packit 6c4009
				    argv[i]),
Packit 6c4009
			    "/cpp");
Packit 6c4009
		    CPP = pathbuf;
Packit 6c4009
		    cppDefined = 1;
Packit 6c4009
		    goto nextarg;
Packit 6c4009
		  }
Packit 6c4009
Packit 6c4009
		default:
Packit 6c4009
		  return 0;
Packit 6c4009
		}
Packit 6c4009
	      }
Packit 6c4009
	nextarg:
Packit 6c4009
	  ;
Packit 6c4009
	}
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  cmd->cflag = flag['c'];
Packit 6c4009
  cmd->hflag = flag['h'];
Packit 6c4009
  cmd->lflag = flag['l'];
Packit 6c4009
  cmd->mflag = flag['m'];
Packit 6c4009
  cmd->nflag = flag['n'];
Packit 6c4009
  cmd->sflag = flag['s'];
Packit 6c4009
  cmd->tflag = flag['t'];
Packit 6c4009
  cmd->Ssflag = flag['S'];
Packit 6c4009
  cmd->Scflag = flag['C'];
Packit 6c4009
  cmd->makefileflag = flag['M'];
Packit 6c4009
Packit 6c4009
  if (tirpcflag)
Packit 6c4009
    {
Packit 6c4009
      pmflag = inetdflag ? 0 : 1;    /* pmflag or inetdflag is always TRUE */
Packit 6c4009
      if ((inetdflag && cmd->nflag))
Packit 6c4009
	{			/* netid not allowed with inetdflag */
Packit 6c4009
	  fprintf (stderr, _("Cannot use netid flag with inetd flag!\n"));
Packit 6c4009
	  return 0;
Packit 6c4009
	}
Packit 6c4009
    }
Packit 6c4009
  else
Packit 6c4009
    {				/* 4.1 mode */
Packit 6c4009
      pmflag = 0;		/* set pmflag only in tirpcmode */
Packit 6c4009
      if (cmd->nflag)
Packit 6c4009
	{			/* netid needs TIRPC */
Packit 6c4009
	  f_print (stderr, _("Cannot use netid flag without TIRPC!\n"));
Packit 6c4009
	  return (0);
Packit 6c4009
	}
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  if (newstyle && (tblflag || cmd->tflag))
Packit 6c4009
    {
Packit 6c4009
      f_print (stderr, _("Cannot use table flags with newstyle!\n"));
Packit 6c4009
      return (0);
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  /* check no conflicts with file generation flags */
Packit 6c4009
  nflags = cmd->cflag + cmd->hflag + cmd->lflag + cmd->mflag +
Packit 6c4009
    cmd->sflag + cmd->nflag + cmd->tflag + cmd->Ssflag + cmd->Scflag;
Packit 6c4009
Packit 6c4009
  if (nflags == 0)
Packit 6c4009
    {
Packit 6c4009
      if (cmd->outfile != NULL || cmd->infile == NULL)
Packit 6c4009
	{
Packit 6c4009
	  return (0);
Packit 6c4009
	}
Packit 6c4009
    }
Packit 6c4009
  else if (cmd->infile == NULL &&
Packit 6c4009
	   (cmd->Ssflag || cmd->Scflag || cmd->makefileflag))
Packit 6c4009
    {
Packit 6c4009
      fprintf (stderr,
Packit 6c4009
	       _("\"infile\" is required for template generation flags.\n"));
Packit 6c4009
      return 0;
Packit 6c4009
    }
Packit 6c4009
  if (nflags > 1)
Packit 6c4009
    {
Packit 6c4009
      fprintf (stderr, _("Cannot have more than one file generation flag!\n"));
Packit 6c4009
      return 0;
Packit 6c4009
    }
Packit 6c4009
  return 1;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
static void
Packit 6c4009
usage (FILE *stream, int status)
Packit 6c4009
{
Packit 6c4009
  fprintf (stream, _("usage: %s infile\n"), cmdname);
Packit 6c4009
  fprintf (stream, _("\t%s [-abkCLNTM][-Dname[=value]] [-i size] \
Packit 6c4009
[-I [-K seconds]] [-Y path] infile\n"), cmdname);
Packit 6c4009
  fprintf (stream, _("\t%s [-c | -h | -l | -m | -t | -Sc | -Ss | -Sm] \
Packit 6c4009
[-o outfile] [infile]\n"), cmdname);
Packit 6c4009
  fprintf (stream, _("\t%s [-s nettype]* [-o outfile] [infile]\n"), cmdname);
Packit 6c4009
  fprintf (stream, _("\t%s [-n netid]* [-o outfile] [infile]\n"), cmdname);
Packit 6c4009
  options_usage (stream, status);
Packit 6c4009
  exit (status);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
static void
Packit 6c4009
options_usage (FILE *stream, int status)
Packit 6c4009
{
Packit 6c4009
  f_print (stream, _("options:\n"));
Packit 6c4009
  f_print (stream, _("-a\t\tgenerate all files, including samples\n"));
Packit 6c4009
  f_print (stream, _("-b\t\tbackward compatibility mode (generates code for SunOS 4.1)\n"));
Packit 6c4009
  f_print (stream, _("-c\t\tgenerate XDR routines\n"));
Packit 6c4009
  f_print (stream, _("-C\t\tANSI C mode\n"));
Packit 6c4009
  f_print (stream, _("-Dname[=value]\tdefine a symbol (same as #define)\n"));
Packit 6c4009
  f_print (stream, _("-h\t\tgenerate header file\n"));
Packit 6c4009
  f_print (stream, _("-i size\t\tsize at which to start generating inline code\n"));
Packit 6c4009
  f_print (stream, _("-I\t\tgenerate code for inetd support in server (for SunOS 4.1)\n"));
Packit 6c4009
  f_print (stream, _("-K seconds\tserver exits after K seconds of inactivity\n"));
Packit 6c4009
  f_print (stream, _("-l\t\tgenerate client side stubs\n"));
Packit 6c4009
  f_print (stream, _("-L\t\tserver errors will be printed to syslog\n"));
Packit 6c4009
  f_print (stream, _("-m\t\tgenerate server side stubs\n"));
Packit 6c4009
  f_print (stream, _("-M\t\tgenerate MT-safe code\n"));
Packit 6c4009
  f_print (stream, _("-n netid\tgenerate server code that supports named netid\n"));
Packit 6c4009
  f_print (stream, _("-N\t\tsupports multiple arguments and call-by-value\n"));
Packit 6c4009
  f_print (stream, _("-o outfile\tname of the output file\n"));
Packit 6c4009
  f_print (stream, _("-s nettype\tgenerate server code that supports named nettype\n"));
Packit 6c4009
  f_print (stream, _("-Sc\t\tgenerate sample client code that uses remote procedures\n"));
Packit 6c4009
  f_print (stream, _("-Ss\t\tgenerate sample server code that defines remote procedures\n"));
Packit 6c4009
  f_print (stream, _("-Sm \t\tgenerate makefile template \n"));
Packit 6c4009
  f_print (stream, _("-t\t\tgenerate RPC dispatch table\n"));
Packit 6c4009
  f_print (stream, _("-T\t\tgenerate code to support RPC dispatch tables\n"));
Packit 6c4009
  f_print (stream, _("-Y path\t\tdirectory name to find C preprocessor (cpp)\n"));
Packit 6c4009
  f_print (stream, _("-5\t\tSysVr4 compatibility mode\n"));
Packit 6c4009
  f_print (stream, _("--help\t\tgive this help list\n"));
Packit 6c4009
  f_print (stream, _("--version\tprint program version\n"));
Packit 6c4009
Packit 6c4009
  f_print (stream, _("\n\
Packit 6c4009
For bug reporting instructions, please see:\n\
Packit 6c4009
%s.\n"), REPORT_BUGS_TO);
Packit 6c4009
  exit (status);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
static void
Packit 6c4009
print_version (void)
Packit 6c4009
{
Packit 6c4009
  printf ("rpcgen %s%s\n", PKGVERSION, VERSION);
Packit 6c4009
  exit (0);
Packit 6c4009
}