Build system: Move install definitions to include
[openafs.git] / src / rxgen / rpc_main.c
index 483f17f..3acc734 100644 (file)
@@ -6,59 +6,41 @@
  * may copy or modify Sun RPC without charge, but are not authorized
  * to license or distribute it to anyone else except as part of a product or
  * program developed by the user.
- * 
+ *
  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
- * 
+ *
  * Sun RPC is provided with no support and without any obligation on the
  * part of Sun Microsystems, Inc. to assist in its use, correction,
  * modification or enhancement.
- * 
+ *
  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  * OR ANY PART THEREOF.
- * 
+ *
  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  * or profits or other special, indirect and consequential damages, even if
  * Sun has been advised of the possibility of such damages.
- * 
+ *
  * Sun Microsystems, Inc.
  * 2550 Garcia Avenue
  * Mountain View, California  94043
  */
 
 /*
- * rpc_main.c, Top level of the RPC protocol compiler. 
- * Copyright (C) 1987, Sun Microsystems, Inc. 
+ * rpc_main.c, Top level of the RPC protocol compiler.
+ * Copyright (C) 1987, Sun Microsystems, Inc.
  */
 
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID
-    ("$Header$");
+#include <roken.h>
 
 #include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
 #include <ctype.h>
-#ifdef HAVE_STRING_H
-#include <string.h>
-#else
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-#endif
-#ifdef HAVE_SIGNAL_H
-#include <signal.h>
-#endif
-#ifdef HAVE_SYS_FILE_H
-#include <sys/file.h>
-#endif
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
+
 #include "rpc_scan.h"
 #include "rpc_parse.h"
 #include "rpc_util.h"
@@ -66,6 +48,8 @@ RCSID
 #define EXTEND 1               /* alias for TRUE */
 
 struct commandline {
+    int ansic_flag;
+    int brief_flag;
     int cflag;
     int hflag;
     int lflag;
@@ -93,22 +77,23 @@ int nincludes = 0;
 char *OutFileFlag = "";
 char OutFile[256];
 char Sflag = 0, Cflag = 0, hflag = 0, cflag = 0, kflag = 0, uflag = 0;
+char ansic_flag = 0;           /* If set, build ANSI C style prototypes */
+char brief_flag = 0;           /* If set, shorten names */
 char zflag = 0;                        /* If set, abort server stub if rpc call returns non-zero */
 char xflag = 0;                        /* if set, add stats code to stubs */
 char yflag = 0;                        /* if set, only emit function name arrays to xdr file */
 int debug = 0;
+static int pclose_fin = 0;
 static char *cmdname;
-#ifdef AFS_SUN5_ENV
-static char CPP[] = "/usr/ccs/lib/cpp";
-#elif defined(AFS_XBSD_ENV) || defined(AFS_DARWIN60_ENV)
-static char CPP[] = "/usr/bin/cpp";
-#elif defined(AFS_NT40_ENV)
-static char CPP[MAXCMDLINE];
-#elif defined(AFS_DARWIN_ENV)
-static char CPP[] = "cc -E";
+#ifdef AFS_NT40_ENV
+static char *CPP = NULL;
+#else /* AFS_NT40_ENV */
+#ifdef PATH_CPP
+static char CPP[] = PATH_CPP;
 #else
 static char CPP[] = "/lib/cpp";
 #endif
+#endif /* AFS_NT40_ENV */
 static char CPPFLAGS[] = "-C";
 
 #ifdef AFS_ALPHA_ENV
@@ -154,20 +139,18 @@ int
 main(int argc, char *argv[])
 {
     struct commandline cmd;
+
 #ifdef AFS_NT40_ENV
-    char *ep;
+    /* initialize CPP with the correct pre-processor for Windows */
+    CPP = getenv("RXGEN_CPPCMD");
+    if (!CPP)
+       CPP = "cl /EP /C /nologo";
+#endif /* AFS_NT40_ENV */
 
-    /* initialize CPP with the correct pre-processor on NT */
-    ep = getenv("RXGEN_CPPCMD");
-    if (ep)
-       strcpy(CPP, ep);
-    else
-       strcpy(CPP, "cl /EP /C /nologo");
-#endif
 #ifdef AFS_AIX32_ENV
     /*
-     * The following signal action for AIX is necessary so that in case of a 
-     * crash (i.e. core is generated) we can include the user's data section 
+     * The following signal action for AIX is necessary so that in case of a
+     * crash (i.e. core is generated) we can include the user's data section
      * in the core dump. Unfortunately, by default, only a partial core is
      * generated which, in many cases, isn't too useful.
      */
@@ -182,7 +165,7 @@ main(int argc, char *argv[])
     if (!parseargs(argc, argv, &cmd)) {
        f_print(stderr, "usage: %s infile\n", cmdname);
        f_print(stderr,
-               "       %s [-c | -h | -l | -m | -C | -S | -r | -k | -R | -p | -d | -z | -u] [-Pprefix] [-Idir] [-o outfile] [infile]\n",
+               "       %s [-c | -h | -l | -m | -C | -S | -r | -b | -k | -R | -p | -d | -z | -u] [-Pprefix] [-Idir] [-o outfile] [infile]\n",
                cmdname);
        f_print(stderr, "       %s [-s udp|tcp]* [-o outfile] [infile]\n",
                cmdname);
@@ -233,11 +216,17 @@ main(int argc, char *argv[])
            reinitialize();
        }
     }
+    if (fin && pclose_fin) {
+       /* the cpp command we called returned a non-zero exit status */
+       if (pclose(fin)) {
+           crash();
+       }
+    }
     exit(0);
 }
 
 /*
- * add extension to filename 
+ * add extension to filename
  */
 static char *
 extendfile(char *file, char *ext)
@@ -265,7 +254,7 @@ extendfile(char *file, char *ext)
 }
 
 /*
- * Open output file with given extension 
+ * Open output file with given extension
  */
 static void
 open_output(char *infile, char *outfile)
@@ -288,7 +277,7 @@ open_output(char *infile, char *outfile)
 }
 
 /*
- * Open input file with given define for C-preprocessor 
+ * Open input file with given define for C-preprocessor
  */
 static void
 open_input(char *infile, char *define)
@@ -323,6 +312,7 @@ open_input(char *infile, char *define)
        fin = popen(cpp_cmdline, "r");
        if (fin == NULL)
            perror("popen");
+       pclose_fin = 1;
 
     } else {
        if (infile == NULL) {
@@ -365,12 +355,16 @@ c_output(char *infile, char *define, int extend, char *outfile, int append)
     f_print(fout, "/* Machine generated file -- Do NOT edit */\n\n");
     if (xflag) {
        if (kflag) {
+           f_print(fout, "#include \"afsconfig.h\"\n");
            f_print(fout, "#include \"afs/param.h\"\n");
        } else {
+           f_print(fout, "#include <afsconfig.h>\n");
            f_print(fout, "#include <afs/param.h>\n");
+           f_print(fout, "#include <roken.h>\n");
        }
        f_print(fout, "#ifdef AFS_NT40_ENV\n");
        f_print(fout, "#define AFS_RXGEN_EXPORT __declspec(dllexport)\n");
+        f_print(fout, "#include <winsock2.h>\n");
        f_print(fout, "#endif /* AFS_NT40_ENV */\n");
     }
     if (currfile && (include = extendfile(currfile, ".h"))) {
@@ -389,7 +383,7 @@ c_output(char *infile, char *define, int extend, char *outfile, int append)
            f_print(fout, "#include \"netinet/in.h\"\n");
            f_print(fout, "#include \"h/time.h\"\n");
            f_print(fout, "#include \"rx/xdr.h\"\n");
-           f_print(fout, "#include \"rxgen_consts.h\"\n");
+           f_print(fout, "#include \"afs/rxgen_consts.h\"\n");
        } else {
            f_print(fout, "#include <rx/xdr.h>\n");
        }
@@ -422,8 +416,10 @@ c_output(char *infile, char *define, int extend, char *outfile, int append)
                }
            }
 
+
            f_print(fout, "\n};\n");
        }
+       er_Proc_CodeGeneration();
     }
 
     if (extend && tell == ftell(fout)) {
@@ -471,6 +467,9 @@ h_output(char *infile, char *define, int extend, char *outfile, int append)
     if (xflag) {
        f_print(fout, "#include \"rx/rx_globals.h\"\n");
     }
+    if (brief_flag) {
+       f_print(fout, "#include \"rx/rx_opaque.h\"\n");
+    }
     if (uflag)
        f_print(fout, "#include <ubik.h>\n");
     f_print(fout, "#else       /* UKERNEL */\n");
@@ -509,12 +508,15 @@ h_output(char *infile, char *define, int extend, char *outfile, int append)
     f_print(fout, "#include \"rx/xdr.h\"\n");
     f_print(fout, "#endif /* XDR_GETLONG */\n");
     f_print(fout, "#endif   /* UKERNEL */\n");
-    f_print(fout, "#include \"rxgen_consts.h\"\n");
+    f_print(fout, "#include \"afs/rxgen_consts.h\"\n");
     f_print(fout, "#include \"afs_osi.h\"\n");
     f_print(fout, "#include \"rx/rx.h\"\n");
     if (xflag) {
        f_print(fout, "#include \"rx/rx_globals.h\"\n");
     }
+    if (brief_flag) {
+       f_print(fout, "#include \"rx/rx_opaque.h\"\n");
+    }
     f_print(fout, "#else       /* KERNEL */\n");
     f_print(fout, "#include <afs/param.h>\n");
     f_print(fout, "#include <afs/stds.h>\n");
@@ -524,6 +526,9 @@ h_output(char *infile, char *define, int extend, char *outfile, int append)
     if (xflag) {
        f_print(fout, "#include <rx/rx_globals.h>\n");
     }
+    if (brief_flag) {
+       f_print(fout, "#include <rx/rx_opaque.h>\n");
+    }
     f_print(fout, "#include <afs/rxgen_consts.h>\n");
     if (uflag)
        f_print(fout, "#include <ubik.h>\n");
@@ -539,6 +544,7 @@ h_output(char *infile, char *define, int extend, char *outfile, int append)
     while ((def = get_definition())) {
        print_datadef(def);
     }
+    h_Proc_CodeGeneration();
     h_opcode_stats();
     hflag = 0;
     f_print(fout, "#endif      /* _RXGEN_%s_ */\n", uppercase(fullname));
@@ -615,7 +621,7 @@ l_output(char *infile, char *define, int extend, char *outfile)
 }
 
 /*
- * Perform registrations for service output 
+ * Perform registrations for service output
  */
 static void
 do_registers(int argc, char *argv[])
@@ -655,6 +661,9 @@ C_output(char *infile, char *define, int extend, char *outfile, int append)
        if (kflag) {
            f_print(fout, "#include \"%s\"\n\n", include);
        } else {
+           f_print(fout, "#include <afsconfig.h>\n");
+           f_print(fout, "#include <afs/param.h>\n");
+           f_print(fout, "#include <roken.h>\n");
            f_print(fout, "#include \"%s\"\n\n", include);
        }
        free(include);
@@ -668,12 +677,15 @@ C_output(char *infile, char *define, int extend, char *outfile, int append)
            f_print(fout, "#include \"h/time.h\"\n");
            f_print(fout, "#include \"rpc/types.h\"\n");
            f_print(fout, "#include \"rx/xdr.h\"\n");
-           f_print(fout, "#include \"rxgen_consts.h\"\n");
+           f_print(fout, "#include \"afs/rxgen_consts.h\"\n");
            f_print(fout, "#include \"afs/afs_osi.h\"\n");
            f_print(fout, "#include \"rx/rx.h\"\n");
            if (xflag) {
                f_print(fout, "#include \"rx/rx_globals.h\"\n");
            }
+           if (brief_flag) {
+               f_print(fout, "#include \"rx/rx_opaque.h\"\n");
+           }
        } else {
            f_print(fout, "#include <sys/types.h>\n");
            f_print(fout, "#include <rx/xdr.h>\n");
@@ -681,6 +693,9 @@ C_output(char *infile, char *define, int extend, char *outfile, int append)
            if (xflag) {
                f_print(fout, "#include <rx/rx_globals.h>\n");
            }
+           if (brief_flag) {
+               f_print(fout, "#include <rx/rx_opaque.h\"\n");
+           }
            f_print(fout, "#include <afs/rxgen_consts.h>\n");
        }
     }
@@ -720,6 +735,9 @@ S_output(char *infile, char *define, int extend, char *outfile, int append)
        if (kflag) {
            f_print(fout, "#include \"%s\"\n", include);
        } else {
+           f_print(fout, "#include <afsconfig.h>\n");
+           f_print(fout, "#include <afs/param.h>\n");
+           f_print(fout, "#include <roken.h>\n");
            f_print(fout, "#include \"%s\"\n\n", include);
        }
        free(include);
@@ -733,12 +751,15 @@ S_output(char *infile, char *define, int extend, char *outfile, int append)
            f_print(fout, "#include \"h/time.h\"\n");
            f_print(fout, "#include \"rpc/types.h\"\n");
            f_print(fout, "#include \"rx/xdr.h\"\n");
-           f_print(fout, "#include \"rxgen_consts.h\"\n");
+           f_print(fout, "#include \"afs/rxgen_consts.h\"\n");
            f_print(fout, "#include \"afs/afs_osi.h\"\n");
            f_print(fout, "#include \"rx/rx.h\"\n");
            if (xflag) {
                f_print(fout, "#include \"rx/rx_globals.h\"\n");
            }
+           if (brief_flag) {
+               f_print(fout, "#include \"rx/rx_opaque.h\"\n");
+           }
        } else {
            f_print(fout, "#include <sys/types.h>\n");
            f_print(fout, "#include <rx/xdr.h>\n");
@@ -746,6 +767,9 @@ S_output(char *infile, char *define, int extend, char *outfile, int append)
            if (xflag) {
                f_print(fout, "#include <rx/rx_globals.h>\n");
            }
+           if (brief_flag) {
+               f_print(fout, "#include <rx/rx_opaque.h>\n");
+           }
            f_print(fout, "#include <afs/rxgen_consts.h>\n");
        }
     }
@@ -780,7 +804,7 @@ uppercase(char *str)
 }
 
 /*
- * Parse command line arguments 
+ * Parse command line arguments
  */
 static int
 parseargs(int argc, char *argv[], struct commandline *cmd)
@@ -808,12 +832,14 @@ parseargs(int argc, char *argv[], struct commandline *cmd)
            for (j = 1; argv[i][j] != 0; j++) {
                c = argv[i][j];
                switch (c) {
+               case 'A':
                case 'c':
                case 'h':
                case 'l':
                case 'm':
                case 'C':
                case 'S':
+               case 'b':
                case 'r':
                case 'R':
                case 'k':
@@ -866,6 +892,8 @@ parseargs(int argc, char *argv[], struct commandline *cmd)
            ;
        }
     }
+    cmd->ansic_flag = ansic_flag = flag['A'];
+    cmd->brief_flag = brief_flag = flag['b'];
     cmd->cflag = cflag = flag['c'];
     cmd->hflag = hflag = flag['h'];
     cmd->sflag = flag['s'];