]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
Add "brief" option to rxgen
authorSimon Wilkinson <sxw@your-file-system.com>
Sun, 14 Feb 2010 10:01:14 +0000 (10:01 +0000)
committerDerrick Brashear <shadow@dementia.org>
Thu, 3 Feb 2011 11:25:40 +0000 (03:25 -0800)
Add a new -b option to rxgen that turns on "brief" output. This makes a
number of changes to the data definitions produced by rxgen so they can
be more easily used by the calling code.

The changes are:
   *) Use the new struct rx_opaque structure for all opaque data
      definitions, rather than defining each as a unique structure.
      This permits moving opaque data between rxgen structures to be
      performed by simple assignment.
   *) Use anonymous structures for internal definitions. Currently
      rxgen also uses the field name as the structure name, which
      prevents the use of a field name more than once within a
      source file.
   *) Don't embed the structure name within the names of the elements
      within the structure. This significantly reduces the length of
      assignment code, and makes for more readable callers.

Reviewed-on: http://gerrit.openafs.org/2585
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementia.org>
(cherry picked from commit 13ae3de3f6ce5de2395823ee5f862a863caf2e51)

Change-Id: I03adce371f17c8865b469b9b5cb94209395261c2
Reviewed-on: http://gerrit.openafs.org/3812
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementia.org>
src/rxgen/rpc_cout.c
src/rxgen/rpc_hout.c
src/rxgen/rpc_main.c
src/rxgen/rpc_parse.c
src/rxgen/rpc_util.h

index 8698eb0da8fb4bb68d578c6882a0675c7755afb3..2b874a584a63e4ddb6cffd4fc2bd8aeb41dcfd01 100644 (file)
@@ -250,11 +250,20 @@ print_ifstat(int indent, char *prefix, char *type, relation rel, char *amax,
                 print_ifarg("(caddr_t *)");
            }
            if (*objname == '&') {
-               f_print(fout, "%s.%s_val, (u_int *)%s.%s_len", objname, name,
-                       objname, name);
+               if (brief_flag) {
+                   f_print(fout, "%s.val, (u_int *)%s.len", objname, objname);
+               } else {
+                   f_print(fout, "%s.%s_val, (u_int *)%s.%s_len",
+                           objname, name, objname, name);
+               }
            } else {
-               f_print(fout, "&%s->%s_val, (u_int *)&%s->%s_len", objname,
-                       name, objname, name);
+               if (brief_flag) {
+                   f_print(fout, "&%s->val, (u_int *)&%s->len",
+                           objname, objname);
+               } else {
+                   f_print(fout, "&%s->%s_val, (u_int *)&%s->%s_len",
+                           objname, name, objname, name);
+               }
            }
        }
        print_ifarg(amax);
@@ -288,6 +297,7 @@ emit_union(definition * def)
     declaration *cs;
     char *object;
     char *format = "&objp->%s_u.%s";
+    char *briefformat = "&objp->u.%s";
 
     print_stat(&def->def.un.enum_decl);
     f_print(fout, "\tswitch (objp->%s) {\n", def->def.un.enum_decl.name);
@@ -298,7 +308,12 @@ emit_union(definition * def)
            object =
                alloc(strlen(def->def_name) + strlen(format) +
                      strlen(cs->name) + 1);
-           s_print(object, format, def->def_name, cs->name);
+
+           if (brief_flag)
+               s_print(object, briefformat, cs->name);
+           else
+               s_print(object, format, def->def_name, cs->name);
+
            print_ifstat(2, cs->prefix, cs->type, cs->rel, cs->array_max,
                         object, cs->name);
            free(object);
@@ -386,8 +401,15 @@ print_hout(declaration * dec)
        switch (dec->rel) {
        case REL_ARRAY:
            f_print(fout, "struct %s {\n", dec->name);
-           f_print(fout, "\tu_int %s_len;\n", dec->name);
-           f_print(fout, "\t%s%s *%s_val;\n", prefix, dec->type, dec->name);
+           if (brief_flag) {
+               f_print(fout, "\tu_int %s_len;\n", dec->name);
+               f_print(fout, "\t%s%s *%s_val;\n", prefix,
+                       dec->type, dec->name);
+           } else {
+               f_print(fout, "\tu_int %s_len;\n", dec->name);
+               f_print(fout, "\t%s%s *%s_val;\n", prefix,
+                       dec->type, dec->name);
+           }
            f_print(fout, "} %s", dec->name);
            break;
        default:
index 50d8c1ef58754407948f25896377b4adc3e59dd9..ac73b2c03565039f6e48039c24d392f00d01679a 100644 (file)
@@ -157,7 +157,11 @@ puniondef(definition * def)
     if (decl && !streq(decl->type, "void")) {
        pdeclaration(name, decl, 2);
     }
-    f_print(fout, "\t} %s_u;\n", name);
+    if (brief_flag) {
+       f_print(fout, "\t} u;\n");
+    } else {
+       f_print(fout, "\t} %s_u;\n", name);
+    }
     f_print(fout, "};\n");
     f_print(fout, "typedef struct %s %s;\n", name, name);
     STOREVAL(&uniondef_defined, def);
@@ -345,7 +349,7 @@ ptypedef(definition * def)
        if (streq(old, "string")) {
            old = "char";
            rel = REL_POINTER;
-       } else if (streq(old, "opaque")) {
+       } else if (!brief_flag && streq(old, "opaque")) {
            old = "char";
        } else if (streq(old, "bool")) {
            old = "bool_t";
@@ -358,10 +362,21 @@ ptypedef(definition * def)
        f_print(fout, "typedef ");
        switch (rel) {
        case REL_ARRAY:
-           f_print(fout, "struct %s {\n", name);
-           f_print(fout, "\tu_int %s_len;\n", name);
-           f_print(fout, "\t%s%s *%s_val;\n", prefix, old, name);
-           f_print(fout, "} %s", name);
+           if (brief_flag) {
+               if (streq(old, "opaque")) {
+                   f_print(fout, "struct rx_opaque %s", name);
+               } else {
+                   f_print(fout, "struct {\n");
+                   f_print(fout, "\tu_int len;\n");
+                   f_print(fout, "\t%s%s *val;\n", prefix, old);
+                   f_print(fout, "} %s", name);
+               }
+           } else {
+               f_print(fout, "struct %s {\n", name);
+               f_print(fout, "\tu_int %s_len;\n", name);
+               f_print(fout, "\t%s%s *%s_val;\n", prefix, old, name);
+               f_print(fout, "} %s", name);
+           }
            break;
        case REL_POINTER:
            f_print(fout, "%s%s *%s", prefix, old, name);
@@ -422,13 +437,27 @@ pdeclaration(char *name, declaration * dec, int tab)
            f_print(fout, "%s%s *%s", prefix, type, dec->name);
            break;
        case REL_ARRAY:
-           f_print(fout, "struct %s {\n", dec->name);
-           tabify(fout, tab);
-           f_print(fout, "\tu_int %s_len;\n", dec->name);
-           tabify(fout, tab);
-           f_print(fout, "\t%s%s *%s_val;\n", prefix, type, dec->name);
-           tabify(fout, tab);
-           f_print(fout, "} %s", dec->name);
+           if (brief_flag) {
+               if (streq(dec->type, "opaque")) {
+                   f_print(fout, "struct rx_opaque %s",dec->name);
+               } else {
+                   f_print(fout, "struct {\n");
+                   tabify(fout, tab);
+                   f_print(fout, "\tu_int len;\n");
+                   tabify(fout, tab);
+                   f_print(fout, "\t%s%s *val;\n", prefix, type);
+                   tabify(fout, tab);
+                   f_print(fout, "} %s", dec->name);
+               }
+           } else {
+               f_print(fout, "struct %s {\n", dec->name);
+               tabify(fout, tab);
+               f_print(fout, "\tu_int %s_len;\n", dec->name);
+               tabify(fout, tab);
+               f_print(fout, "\t%s%s *%s_val;\n", prefix, type, dec->name);
+               tabify(fout, tab);
+               f_print(fout, "} %s", dec->name);
+           }
            break;
        }
     }
index 7ae08933061db50541f614171694ad32da741efc..88cebbdaeee36ff4989769782e7f9b3de0cfcbcf 100644 (file)
@@ -59,6 +59,7 @@
 
 struct commandline {
     int ansic_flag;
+    int brief_flag;
     int cflag;
     int hflag;
     int lflag;
@@ -87,6 +88,7 @@ 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 */
@@ -173,7 +175,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);
@@ -471,6 +473,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");
@@ -515,6 +520,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, "#else       /* KERNEL */\n");
     f_print(fout, "#include <afs/param.h>\n");
     f_print(fout, "#include <afs/stds.h>\n");
@@ -524,6 +532,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");
@@ -675,6 +686,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");
+           }
        } else {
            f_print(fout, "#include <sys/types.h>\n");
            f_print(fout, "#include <rx/xdr.h>\n");
@@ -682,6 +696,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");
        }
     }
@@ -740,6 +757,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");
+           }
        } else {
            f_print(fout, "#include <sys/types.h>\n");
            f_print(fout, "#include <rx/xdr.h>\n");
@@ -747,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");
        }
     }
@@ -816,6 +839,7 @@ parseargs(int argc, char *argv[], struct commandline *cmd)
                case 'm':
                case 'C':
                case 'S':
+               case 'b':
                case 'r':
                case 'R':
                case 'k':
@@ -869,6 +893,7 @@ 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'];
index 5ebd08efc2cb7ff5e9902daa0459d7dba42ceeaf..eeb67634acf97a4ca4ae1fc1bff85fa9c433deb2 100644 (file)
@@ -1515,13 +1515,21 @@ ss_ProcSpecial_setup(definition * defp, int *somefrees)
                    *somefrees = 1;
                    switch (defp1->pc.rel) {
                    case REL_ARRAY:
-                       f_print(fout, "\n\t%s.%s_val = 0;",
-                               plist->pl.param_name, defp1->def_name);
-                       f_print(fout, "\n\t%s.%s_len = 0;",
-                               plist->pl.param_name, defp1->def_name);
                        plist->pl.string_name = alloc(40);
-                       s_print(plist->pl.string_name, "%s_val",
-                               defp1->def_name);
+                       if (brief_flag) {
+                           f_print(fout, "\n\t%s.val = 0;",
+                                   plist->pl.param_name);
+                           f_print(fout, "\n\t%s.len = 0;",
+                                   plist->pl.param_name);
+                           s_print(plist->pl.string_name, "val");
+                       } else {
+                           f_print(fout, "\n\t%s.%s_val = 0;",
+                                   plist->pl.param_name, defp1->def_name);
+                           f_print(fout, "\n\t%s.%s_len = 0;",
+                                   plist->pl.param_name, defp1->def_name);
+                           s_print(plist->pl.string_name, "%s_val",
+                                   defp1->def_name);
+                       }
                        break;
                    case REL_POINTER:
                        f_print(fout, "\n\t%s = 0;", plist->pl.param_name);
index 342c45abd3234be286692b5aafc2c43eee7dc6aa..2e316eaf90fccba53b559d6392662816ef3ccbc2 100644 (file)
@@ -58,6 +58,7 @@ extern char *OutFileFlag;
 extern char OutFile[];
 extern char Sflag, Cflag, hflag, cflag, kflag, uflag;
 extern char ansic_flag;
+extern char brief_flag;
 extern char zflag;
 extern char xflag;
 extern char yflag;