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

1.11    ! weingart    1: /*     $OpenBSD: rpc_tblout.c,v 1.10 2002/07/05 05:39:42 deraadt Exp $ */
1.1       deraadt     2: /*     $NetBSD: rpc_tblout.c,v 1.3 1995/06/24 15:00:15 pk Exp $        */
                      3: /*
                      4:  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
                      5:  * unrestricted use provided that this legend is included on all tape
                      6:  * media and as a part of the software program in whole or part.  Users
                      7:  * may copy or modify Sun RPC without charge, but are not authorized
                      8:  * to license or distribute it to anyone else except as part of a product or
                      9:  * program developed by the user or with the express written consent of
                     10:  * Sun Microsystems, Inc.
                     11:  *
                     12:  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
                     13:  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
                     14:  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
                     15:  *
                     16:  * Sun RPC is provided with no support and without any obligation on the
                     17:  * part of Sun Microsystems, Inc. to assist in its use, correction,
                     18:  * modification or enhancement.
                     19:  *
                     20:  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
                     21:  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
                     22:  * OR ANY PART THEREOF.
                     23:  *
                     24:  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
                     25:  * or profits or other special, indirect and consequential damages, even if
                     26:  * Sun has been advised of the possibility of such damages.
                     27:  *
                     28:  * Sun Microsystems, Inc.
                     29:  * 2550 Garcia Avenue
                     30:  * Mountain View, California  94043
                     31:  */
                     32:
                     33: #ifndef lint
1.11    ! weingart   34: static const char sccsid[] = "@(#)rpc_tblout.c 1.4 89/02/22 (C) 1988 SMI";
1.1       deraadt    35: #endif
                     36:
                     37: /*
                     38:  * rpc_tblout.c, Dispatch table outputter for the RPC protocol compiler
                     39:  */
                     40: #include <sys/cdefs.h>
                     41: #include <stdio.h>
1.10      deraadt    42: #include <stdlib.h>
1.1       deraadt    43: #include <string.h>
                     44: #include "rpc_parse.h"
                     45: #include "rpc_util.h"
                     46:
                     47: #define TABSIZE                8
                     48: #define TABCOUNT       5
                     49: #define TABSTOP                (TABSIZE*TABCOUNT)
                     50:
                     51: static char tabstr[TABCOUNT+1] = "\t\t\t\t\t";
                     52:
                     53: static char tbl_hdr[] = "struct rpcgen_table %s_table[] = {\n";
                     54: static char tbl_end[] = "};\n";
                     55:
                     56: static char null_entry[] = "\n\t(char *(*)())0,\n\
1.7       deraadt    57: \t(xdrproc_t) xdr_void,\t\t\t0,\n\
                     58: \t(xdrproc_t) xdr_void,\t\t\t0,\n";
1.1       deraadt    59:
                     60: static char tbl_nproc[] = "int %s_nproc =\n\tsizeof(%s_table)/sizeof(%s_table[0]);\n\n";
                     61:
1.8       millert    62: static void write_table(definition *);
                     63: static void printit(char *, char *);
1.1       deraadt    64:
                     65: void
                     66: write_tables()
                     67: {
1.7       deraadt    68:        definition *def;
1.6       deraadt    69:        list *l;
1.1       deraadt    70:
1.9       deraadt    71:        fprintf(fout, "\n");
1.1       deraadt    72:        for (l = defined; l != NULL; l = l->next) {
                     73:                def = (definition *) l->val;
1.7       deraadt    74:                if (def->def_kind == DEF_PROGRAM)
1.1       deraadt    75:                        write_table(def);
                     76:        }
                     77: }
                     78:
1.7       deraadt    79: static void
1.1       deraadt    80: write_table(def)
                     81:        definition *def;
                     82: {
                     83:        version_list *vp;
                     84:        proc_list *proc;
                     85:        int current;
                     86:        int expected;
                     87:        char progvers[100];
                     88:        int warning;
                     89:
                     90:        for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
                     91:                warning = 0;
1.9       deraadt    92:                snprintf(progvers, sizeof progvers, "%s_%s",
1.1       deraadt    93:                    locase(def->def_name), vp->vers_num);
                     94:                /* print the table header */
1.9       deraadt    95:                fprintf(fout, tbl_hdr, progvers);
1.1       deraadt    96:
                     97:                if (nullproc(vp->procs)) {
                     98:                        expected = 0;
                     99:                } else {
                    100:                        expected = 1;
1.9       deraadt   101:                        fprintf(fout, null_entry);
1.1       deraadt   102:                }
                    103:                for (proc = vp->procs; proc != NULL; proc = proc->next) {
                    104:                        current = atoi(proc->proc_num);
                    105:                        if (current != expected++) {
1.9       deraadt   106:                                fprintf(fout,
1.7       deraadt   107:                                    "\n/*\n * WARNING: table out of order\n */\n");
1.1       deraadt   108:                                if (warning == 0) {
1.9       deraadt   109:                                        fprintf(stderr,
1.7       deraadt   110:                                            "WARNING %s table is out of order\n",
1.1       deraadt   111:                                            progvers);
                    112:                                        warning = 1;
                    113:                                        nonfatalerrors = 1;
                    114:                                }
                    115:                                expected = current + 1;
                    116:                        }
1.9       deraadt   117:                        fprintf(fout, "\n\t(char *(*)())RPCGEN_ACTION(");
1.1       deraadt   118:
                    119:                        /* routine to invoke */
1.7       deraadt   120:                        if (!newstyle)
                    121:                                pvname_svc(proc->proc_name, vp->vers_num);
1.1       deraadt   122:                        else {
1.7       deraadt   123:                                if (newstyle)
1.9       deraadt   124:                                        fprintf(fout, "_");   /* calls internal func */
1.7       deraadt   125:                                pvname(proc->proc_name, vp->vers_num);
1.1       deraadt   126:                        }
1.9       deraadt   127:                        fprintf(fout, "),\n");
1.1       deraadt   128:
                    129:                        /* argument info */
1.7       deraadt   130:                        if (proc->arg_num > 1)
                    131:                                printit((char*) NULL, proc->args.argname);
                    132:                        else
                    133:                                /* do we have to do something special for newstyle */
                    134:                                printit(proc->args.decls->decl.prefix,
                    135:                                    proc->args.decls->decl.type);
1.1       deraadt   136:                        /* result info */
                    137:                        printit(proc->res_prefix, proc->res_type);
                    138:                }
                    139:
                    140:                /* print the table trailer */
1.9       deraadt   141:                fprintf(fout, tbl_end);
                    142:                fprintf(fout, tbl_nproc, progvers, progvers, progvers);
1.1       deraadt   143:        }
                    144: }
                    145:
1.7       deraadt   146: static void
1.1       deraadt   147: printit(prefix, type)
                    148:        char *prefix;
                    149:        char *type;
                    150: {
1.7       deraadt   151:        int len, tabs;
1.1       deraadt   152:
1.10      deraadt   153:        len = fprintf(fout, "\txdr_%s,", stringfix(type));
1.1       deraadt   154:        /* account for leading tab expansion */
                    155:        len += TABSIZE - 1;
                    156:        /* round up to tabs required */
                    157:        tabs = (TABSTOP - len + TABSIZE - 1)/TABSIZE;
1.9       deraadt   158:        fprintf(fout, "%s", &tabstr[TABCOUNT-tabs]);
1.1       deraadt   159:
                    160:        if (streq(type, "void")) {
1.9       deraadt   161:                fprintf(fout, "0");
1.1       deraadt   162:        } else {
1.9       deraadt   163:                fprintf(fout, "sizeof (");
1.1       deraadt   164:                /* XXX: should "follow" be 1 ??? */
                    165:                ptype(prefix, type, 0);
1.9       deraadt   166:                fprintf(fout, ")");
1.1       deraadt   167:        }
1.9       deraadt   168:        fprintf(fout, ",\n");
1.1       deraadt   169: }