[BACK]Return to rpc_tblout.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / rpcgen

Annotation of src/usr.bin/rpcgen/rpc_tblout.c, Revision 1.14

1.14    ! deraadt     1: /*     $OpenBSD: rpc_tblout.c,v 1.13 2010/09/01 14:43:34 millert Exp $ */
1.1       deraadt     2: /*     $NetBSD: rpc_tblout.c,v 1.3 1995/06/24 15:00:15 pk Exp $        */
1.13      millert     3:
1.1       deraadt     4: /*
1.13      millert     5:  * Copyright (c) 2010, Oracle America, Inc.
1.1       deraadt     6:  *
1.13      millert     7:  * Redistribution and use in source and binary forms, with or without
                      8:  * modification, are permitted provided that the following conditions are
                      9:  * met:
1.1       deraadt    10:  *
1.13      millert    11:  *     * Redistributions of source code must retain the above copyright
                     12:  *       notice, this list of conditions and the following disclaimer.
                     13:  *     * Redistributions in binary form must reproduce the above
                     14:  *       copyright notice, this list of conditions and the following
                     15:  *       disclaimer in the documentation and/or other materials
                     16:  *       provided with the distribution.
                     17:  *     * Neither the name of the "Oracle America, Inc." nor the names of its
                     18:  *       contributors may be used to endorse or promote products derived
                     19:  *       from this software without specific prior written permission.
1.1       deraadt    20:  *
1.13      millert    21:  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
                     22:  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
                     23:  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
                     24:  *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
                     25:  *   COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
                     26:  *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     27:  *   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
                     28:  *   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     29:  *   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
                     30:  *   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
                     31:  *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
                     32:  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1.1       deraadt    33:  */
                     34:
                     35: /*
                     36:  * rpc_tblout.c, Dispatch table outputter for the RPC protocol compiler
                     37:  */
                     38: #include <stdio.h>
1.10      deraadt    39: #include <stdlib.h>
1.1       deraadt    40: #include <string.h>
                     41: #include "rpc_parse.h"
                     42: #include "rpc_util.h"
                     43:
                     44: #define TABSIZE                8
                     45: #define TABCOUNT       5
                     46: #define TABSTOP                (TABSIZE*TABCOUNT)
                     47:
                     48: static char tabstr[TABCOUNT+1] = "\t\t\t\t\t";
                     49:
                     50: static char tbl_hdr[] = "struct rpcgen_table %s_table[] = {\n";
                     51: static char tbl_end[] = "};\n";
                     52:
                     53: static char null_entry[] = "\n\t(char *(*)())0,\n\
1.7       deraadt    54: \t(xdrproc_t) xdr_void,\t\t\t0,\n\
                     55: \t(xdrproc_t) xdr_void,\t\t\t0,\n";
1.1       deraadt    56:
                     57: static char tbl_nproc[] = "int %s_nproc =\n\tsizeof(%s_table)/sizeof(%s_table[0]);\n\n";
                     58:
1.8       millert    59: static void write_table(definition *);
                     60: static void printit(char *, char *);
1.1       deraadt    61:
                     62: void
                     63: write_tables()
                     64: {
1.7       deraadt    65:        definition *def;
1.6       deraadt    66:        list *l;
1.1       deraadt    67:
1.9       deraadt    68:        fprintf(fout, "\n");
1.1       deraadt    69:        for (l = defined; l != NULL; l = l->next) {
                     70:                def = (definition *) l->val;
1.7       deraadt    71:                if (def->def_kind == DEF_PROGRAM)
1.1       deraadt    72:                        write_table(def);
                     73:        }
                     74: }
                     75:
1.7       deraadt    76: static void
1.1       deraadt    77: write_table(def)
                     78:        definition *def;
                     79: {
                     80:        version_list *vp;
                     81:        proc_list *proc;
                     82:        int current;
                     83:        int expected;
                     84:        char progvers[100];
                     85:        int warning;
                     86:
                     87:        for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
                     88:                warning = 0;
1.9       deraadt    89:                snprintf(progvers, sizeof progvers, "%s_%s",
1.1       deraadt    90:                    locase(def->def_name), vp->vers_num);
                     91:                /* print the table header */
1.9       deraadt    92:                fprintf(fout, tbl_hdr, progvers);
1.1       deraadt    93:
                     94:                if (nullproc(vp->procs)) {
                     95:                        expected = 0;
                     96:                } else {
                     97:                        expected = 1;
1.9       deraadt    98:                        fprintf(fout, null_entry);
1.1       deraadt    99:                }
                    100:                for (proc = vp->procs; proc != NULL; proc = proc->next) {
                    101:                        current = atoi(proc->proc_num);
                    102:                        if (current != expected++) {
1.9       deraadt   103:                                fprintf(fout,
1.7       deraadt   104:                                    "\n/*\n * WARNING: table out of order\n */\n");
1.1       deraadt   105:                                if (warning == 0) {
1.9       deraadt   106:                                        fprintf(stderr,
1.7       deraadt   107:                                            "WARNING %s table is out of order\n",
1.1       deraadt   108:                                            progvers);
                    109:                                        warning = 1;
                    110:                                        nonfatalerrors = 1;
                    111:                                }
                    112:                                expected = current + 1;
                    113:                        }
1.9       deraadt   114:                        fprintf(fout, "\n\t(char *(*)())RPCGEN_ACTION(");
1.1       deraadt   115:
                    116:                        /* routine to invoke */
1.7       deraadt   117:                        if (!newstyle)
                    118:                                pvname_svc(proc->proc_name, vp->vers_num);
1.1       deraadt   119:                        else {
1.7       deraadt   120:                                if (newstyle)
1.9       deraadt   121:                                        fprintf(fout, "_");   /* calls internal func */
1.7       deraadt   122:                                pvname(proc->proc_name, vp->vers_num);
1.1       deraadt   123:                        }
1.9       deraadt   124:                        fprintf(fout, "),\n");
1.1       deraadt   125:
                    126:                        /* argument info */
1.7       deraadt   127:                        if (proc->arg_num > 1)
                    128:                                printit((char*) NULL, proc->args.argname);
                    129:                        else
                    130:                                /* do we have to do something special for newstyle */
                    131:                                printit(proc->args.decls->decl.prefix,
                    132:                                    proc->args.decls->decl.type);
1.1       deraadt   133:                        /* result info */
                    134:                        printit(proc->res_prefix, proc->res_type);
                    135:                }
                    136:
                    137:                /* print the table trailer */
1.9       deraadt   138:                fprintf(fout, tbl_end);
                    139:                fprintf(fout, tbl_nproc, progvers, progvers, progvers);
1.1       deraadt   140:        }
                    141: }
                    142:
1.7       deraadt   143: static void
1.1       deraadt   144: printit(prefix, type)
                    145:        char *prefix;
                    146:        char *type;
                    147: {
1.7       deraadt   148:        int len, tabs;
1.1       deraadt   149:
1.10      deraadt   150:        len = fprintf(fout, "\txdr_%s,", stringfix(type));
1.1       deraadt   151:        /* account for leading tab expansion */
                    152:        len += TABSIZE - 1;
                    153:        /* round up to tabs required */
                    154:        tabs = (TABSTOP - len + TABSIZE - 1)/TABSIZE;
1.9       deraadt   155:        fprintf(fout, "%s", &tabstr[TABCOUNT-tabs]);
1.1       deraadt   156:
                    157:        if (streq(type, "void")) {
1.9       deraadt   158:                fprintf(fout, "0");
1.1       deraadt   159:        } else {
1.9       deraadt   160:                fprintf(fout, "sizeof (");
1.1       deraadt   161:                /* XXX: should "follow" be 1 ??? */
                    162:                ptype(prefix, type, 0);
1.9       deraadt   163:                fprintf(fout, ")");
1.1       deraadt   164:        }
1.9       deraadt   165:        fprintf(fout, ",\n");
1.1       deraadt   166: }