[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.13

1.13    ! millert     1: /*     $OpenBSD: rpc_tblout.c,v 1.12 2009/10/27 23:59:42 deraadt 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 <sys/cdefs.h>
                     39: #include <stdio.h>
1.10      deraadt    40: #include <stdlib.h>
1.1       deraadt    41: #include <string.h>
                     42: #include "rpc_parse.h"
                     43: #include "rpc_util.h"
                     44:
                     45: #define TABSIZE                8
                     46: #define TABCOUNT       5
                     47: #define TABSTOP                (TABSIZE*TABCOUNT)
                     48:
                     49: static char tabstr[TABCOUNT+1] = "\t\t\t\t\t";
                     50:
                     51: static char tbl_hdr[] = "struct rpcgen_table %s_table[] = {\n";
                     52: static char tbl_end[] = "};\n";
                     53:
                     54: static char null_entry[] = "\n\t(char *(*)())0,\n\
1.7       deraadt    55: \t(xdrproc_t) xdr_void,\t\t\t0,\n\
                     56: \t(xdrproc_t) xdr_void,\t\t\t0,\n";
1.1       deraadt    57:
                     58: static char tbl_nproc[] = "int %s_nproc =\n\tsizeof(%s_table)/sizeof(%s_table[0]);\n\n";
                     59:
1.8       millert    60: static void write_table(definition *);
                     61: static void printit(char *, char *);
1.1       deraadt    62:
                     63: void
                     64: write_tables()
                     65: {
1.7       deraadt    66:        definition *def;
1.6       deraadt    67:        list *l;
1.1       deraadt    68:
1.9       deraadt    69:        fprintf(fout, "\n");
1.1       deraadt    70:        for (l = defined; l != NULL; l = l->next) {
                     71:                def = (definition *) l->val;
1.7       deraadt    72:                if (def->def_kind == DEF_PROGRAM)
1.1       deraadt    73:                        write_table(def);
                     74:        }
                     75: }
                     76:
1.7       deraadt    77: static void
1.1       deraadt    78: write_table(def)
                     79:        definition *def;
                     80: {
                     81:        version_list *vp;
                     82:        proc_list *proc;
                     83:        int current;
                     84:        int expected;
                     85:        char progvers[100];
                     86:        int warning;
                     87:
                     88:        for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
                     89:                warning = 0;
1.9       deraadt    90:                snprintf(progvers, sizeof progvers, "%s_%s",
1.1       deraadt    91:                    locase(def->def_name), vp->vers_num);
                     92:                /* print the table header */
1.9       deraadt    93:                fprintf(fout, tbl_hdr, progvers);
1.1       deraadt    94:
                     95:                if (nullproc(vp->procs)) {
                     96:                        expected = 0;
                     97:                } else {
                     98:                        expected = 1;
1.9       deraadt    99:                        fprintf(fout, null_entry);
1.1       deraadt   100:                }
                    101:                for (proc = vp->procs; proc != NULL; proc = proc->next) {
                    102:                        current = atoi(proc->proc_num);
                    103:                        if (current != expected++) {
1.9       deraadt   104:                                fprintf(fout,
1.7       deraadt   105:                                    "\n/*\n * WARNING: table out of order\n */\n");
1.1       deraadt   106:                                if (warning == 0) {
1.9       deraadt   107:                                        fprintf(stderr,
1.7       deraadt   108:                                            "WARNING %s table is out of order\n",
1.1       deraadt   109:                                            progvers);
                    110:                                        warning = 1;
                    111:                                        nonfatalerrors = 1;
                    112:                                }
                    113:                                expected = current + 1;
                    114:                        }
1.9       deraadt   115:                        fprintf(fout, "\n\t(char *(*)())RPCGEN_ACTION(");
1.1       deraadt   116:
                    117:                        /* routine to invoke */
1.7       deraadt   118:                        if (!newstyle)
                    119:                                pvname_svc(proc->proc_name, vp->vers_num);
1.1       deraadt   120:                        else {
1.7       deraadt   121:                                if (newstyle)
1.9       deraadt   122:                                        fprintf(fout, "_");   /* calls internal func */
1.7       deraadt   123:                                pvname(proc->proc_name, vp->vers_num);
1.1       deraadt   124:                        }
1.9       deraadt   125:                        fprintf(fout, "),\n");
1.1       deraadt   126:
                    127:                        /* argument info */
1.7       deraadt   128:                        if (proc->arg_num > 1)
                    129:                                printit((char*) NULL, proc->args.argname);
                    130:                        else
                    131:                                /* do we have to do something special for newstyle */
                    132:                                printit(proc->args.decls->decl.prefix,
                    133:                                    proc->args.decls->decl.type);
1.1       deraadt   134:                        /* result info */
                    135:                        printit(proc->res_prefix, proc->res_type);
                    136:                }
                    137:
                    138:                /* print the table trailer */
1.9       deraadt   139:                fprintf(fout, tbl_end);
                    140:                fprintf(fout, tbl_nproc, progvers, progvers, progvers);
1.1       deraadt   141:        }
                    142: }
                    143:
1.7       deraadt   144: static void
1.1       deraadt   145: printit(prefix, type)
                    146:        char *prefix;
                    147:        char *type;
                    148: {
1.7       deraadt   149:        int len, tabs;
1.1       deraadt   150:
1.10      deraadt   151:        len = fprintf(fout, "\txdr_%s,", stringfix(type));
1.1       deraadt   152:        /* account for leading tab expansion */
                    153:        len += TABSIZE - 1;
                    154:        /* round up to tabs required */
                    155:        tabs = (TABSTOP - len + TABSIZE - 1)/TABSIZE;
1.9       deraadt   156:        fprintf(fout, "%s", &tabstr[TABCOUNT-tabs]);
1.1       deraadt   157:
                    158:        if (streq(type, "void")) {
1.9       deraadt   159:                fprintf(fout, "0");
1.1       deraadt   160:        } else {
1.9       deraadt   161:                fprintf(fout, "sizeof (");
1.1       deraadt   162:                /* XXX: should "follow" be 1 ??? */
                    163:                ptype(prefix, type, 0);
1.9       deraadt   164:                fprintf(fout, ")");
1.1       deraadt   165:        }
1.9       deraadt   166:        fprintf(fout, ",\n");
1.1       deraadt   167: }