rpc_tblout.c revision 149682
1226031Sstas/* 2226031Sstas * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 3226031Sstas * unrestricted use provided that this legend is included on all tape 4226031Sstas * media and as a part of the software program in whole or part. Users 5226031Sstas * may copy or modify Sun RPC without charge, but are not authorized 6226031Sstas * to license or distribute it to anyone else except as part of a product or 7226031Sstas * program developed by the user. 8226031Sstas * 9226031Sstas * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 10226031Sstas * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 11226031Sstas * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 12226031Sstas * 13226031Sstas * Sun RPC is provided with no support and without any obligation on the 14226031Sstas * part of Sun Microsystems, Inc. to assist in its use, correction, 15226031Sstas * modification or enhancement. 16226031Sstas * 17226031Sstas * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 18226031Sstas * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 19226031Sstas * OR ANY PART THEREOF. 20226031Sstas * 21226031Sstas * In no event will Sun Microsystems, Inc. be liable for any lost revenue 22226031Sstas * or profits or other special, indirect and consequential damages, even if 23226031Sstas * Sun has been advised of the possibility of such damages. 24226031Sstas * 25226031Sstas * Sun Microsystems, Inc. 26226031Sstas * 2550 Garcia Avenue 27226031Sstas * Mountain View, California 94043 28226031Sstas */ 29226031Sstas 30226031Sstas#if 0 31226031Sstas#ifndef lint 32226031Sstas#ident "@(#)rpc_tblout.c 1.11 93/07/05 SMI" 33226031Sstasstatic char sccsid[] = "@(#)rpc_tblout.c 1.4 89/02/22 (C) 1988 SMI"; 34226031Sstas#endif 35226031Sstas#endif 36226031Sstas 37226031Sstas#include <sys/cdefs.h> 38226031Sstas__FBSDID("$FreeBSD: head/usr.bin/rpcgen/rpc_tblout.c 149682 2005-08-31 20:45:15Z stefanf $"); 39226031Sstas 40226031Sstas/* 41226031Sstas * rpc_tblout.c, Dispatch table outputter for the RPC protocol compiler 42226031Sstas * Copyright (C) 1989, Sun Microsystems, Inc. 43226031Sstas */ 44226031Sstas#include <err.h> 45226031Sstas#include <stdio.h> 46226031Sstas#include <string.h> 47226031Sstas#include "rpc_parse.h" 48226031Sstas#include "rpc_scan.h" 49226031Sstas#include "rpc_util.h" 50226031Sstas 51226031Sstas#define TABSIZE 8 52226031Sstas#define TABCOUNT 5 53226031Sstas#define TABSTOP (TABSIZE*TABCOUNT) 54226031Sstas 55226031Sstasstatic char tabstr[TABCOUNT+1] = "\t\t\t\t\t"; 56226031Sstas 57226031Sstasstatic char tbl_hdr[] = "struct rpcgen_table %s_table[] = {\n"; 58226031Sstasstatic char tbl_end[] = "};\n"; 59226031Sstas 60226031Sstasstatic char null_entry[] = "\n\t(char *(*)())0,\n\ 61226031Sstas \t(xdrproc_t) xdr_void,\t\t\t0,\n\ 62226031Sstas \t(xdrproc_t) xdr_void,\t\t\t0,\n"; 63226031Sstas 64226031Sstas 65226031Sstasstatic char tbl_nproc[] = "int %s_nproc =\n\tsizeof(%s_table)/sizeof(%s_table[0]);\n\n"; 66226031Sstas 67226031Sstasextern int nullproc( proc_list * ); 68226031Sstasstatic void write_table( definition * ); 69226031Sstasstatic void printit( char *, char * ); 70226031Sstas 71226031Sstasvoid 72226031Sstaswrite_tables() 73226031Sstas{ 74226031Sstas list *l; 75226031Sstas definition *def; 76226031Sstas 77226031Sstas f_print(fout, "\n"); 78226031Sstas for (l = defined; l != NULL; l = l->next) { 79226031Sstas def = (definition *) l->val; 80226031Sstas if (def->def_kind == DEF_PROGRAM) { 81226031Sstas write_table(def); 82226031Sstas } 83226031Sstas } 84226031Sstas} 85226031Sstas 86226031Sstasstatic void 87226031Sstaswrite_table(def) 88226031Sstas definition *def; 89226031Sstas{ 90226031Sstas version_list *vp; 91226031Sstas proc_list *proc; 92226031Sstas int current; 93226031Sstas int expected; 94226031Sstas char progvers[100]; 95226031Sstas int warning; 96226031Sstas 97226031Sstas for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { 98226031Sstas warning = 0; 99226031Sstas s_print(progvers, "%s_%s", 100226031Sstas locase(def->def_name), vp->vers_num); 101226031Sstas /* print the table header */ 102226031Sstas f_print(fout, tbl_hdr, progvers); 103226031Sstas 104226031Sstas if (nullproc(vp->procs)) { 105226031Sstas expected = 0; 106226031Sstas } else { 107226031Sstas expected = 1; 108226031Sstas f_print(fout, null_entry); 109226031Sstas } 110226031Sstas for (proc = vp->procs; proc != NULL; proc = proc->next) { 111226031Sstas current = atoi(proc->proc_num); 112226031Sstas if (current != expected++) { 113226031Sstas f_print(fout, 114226031Sstas "\n/*\n * WARNING: table out of order\n */\n"); 115226031Sstas if (warning == 0) { 116226031Sstas warnx("WARNING %s table is out of order", progvers); 117226031Sstas warning = 1; 118226031Sstas nonfatalerrors = 1; 119226031Sstas } 120226031Sstas expected = current + 1; 121226031Sstas } 122226031Sstas f_print(fout, "\n\t(char *(*)())RPCGEN_ACTION("); 123226031Sstas 124226031Sstas /* routine to invoke */ 125226031Sstas if( Cflag && !newstyle ) 126226031Sstas pvname_svc(proc->proc_name, vp->vers_num); 127226031Sstas else { 128226031Sstas if( newstyle ) 129226031Sstas f_print( fout, "_"); /* calls internal func */ 130226128Sstas pvname(proc->proc_name, vp->vers_num); 131226128Sstas } 132226128Sstas f_print(fout, "),\n"); 133226128Sstas 134226031Sstas /* argument info */ 135226031Sstas if( proc->arg_num > 1 ) 136226031Sstas printit((char*) NULL, proc->args.argname ); 137226031Sstas else 138226031Sstas /* do we have to do something special for newstyle */ 139226031Sstas printit( proc->args.decls->decl.prefix, 140226031Sstas proc->args.decls->decl.type ); 141226031Sstas /* result info */ 142226031Sstas printit(proc->res_prefix, proc->res_type); 143226031Sstas } 144226031Sstas 145226031Sstas /* print the table trailer */ 146226031Sstas f_print(fout, tbl_end); 147226031Sstas f_print(fout, tbl_nproc, progvers, progvers, progvers); 148226031Sstas } 149226031Sstas} 150226031Sstas 151226031Sstasstatic void 152226031Sstasprintit(prefix, type) 153 char *prefix; 154 char *type; 155{ 156 int len; 157 int tabs; 158 159 160 len = fprintf(fout, "\txdr_%s,", stringfix(type)); 161 /* account for leading tab expansion */ 162 len += TABSIZE - 1; 163 /* round up to tabs required */ 164 tabs = (TABSTOP - len + TABSIZE - 1)/TABSIZE; 165 f_print(fout, "%s", &tabstr[TABCOUNT-tabs]); 166 167 if (streq(type, "void")) { 168 f_print(fout, "0"); 169 } else { 170 f_print(fout, "sizeof ( "); 171 /* XXX: should "follow" be 1 ??? */ 172 ptype(prefix, type, 0); 173 f_print(fout, ")"); 174 } 175 f_print(fout, ",\n"); 176} 177