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