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