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

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