155682Smarkm/* 2233294Sstas * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 3233294Sstas * unrestricted use provided that this legend is included on all tape 4233294Sstas * media and as a part of the software program in whole or part. Users 555682Smarkm * may copy or modify Sun RPC without charge, but are not authorized 6233294Sstas * to license or distribute it to anyone else except as part of a product or 7233294Sstas * program developed by the user. 8233294Sstas * 955682Smarkm * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 10233294Sstas * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 11233294Sstas * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 1255682Smarkm * 13233294Sstas * Sun RPC is provided with no support and without any obligation on the 14233294Sstas * part of Sun Microsystems, Inc. to assist in its use, correction, 15233294Sstas * modification or enhancement. 1655682Smarkm * 17233294Sstas * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 18233294Sstas * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 19233294Sstas * OR ANY PART THEREOF. 2055682Smarkm * 21233294Sstas * In no event will Sun Microsystems, Inc. be liable for any lost revenue 22233294Sstas * or profits or other special, indirect and consequential damages, even if 23233294Sstas * Sun has been advised of the possibility of such damages. 24233294Sstas * 25233294Sstas * Sun Microsystems, Inc. 26233294Sstas * 2550 Garcia Avenue 27233294Sstas * Mountain View, California 94043 28233294Sstas */ 29233294Sstas 30233294Sstas#if 0 31233294Sstas#ifndef lint 3255682Smarkm#ident "@(#)rpc_tblout.c 1.11 93/07/05 SMI" 3355682Smarkmstatic char sccsid[] = "@(#)rpc_tblout.c 1.4 89/02/22 (C) 1988 SMI"; 3455682Smarkm#endif 35178825Sdfr#endif 3655682Smarkm 3755682Smarkm#include <sys/cdefs.h> 3855682Smarkm__FBSDID("$FreeBSD$"); 3955682Smarkm 4055682Smarkm/* 4155682Smarkm * rpc_tblout.c, Dispatch table outputter for the RPC protocol compiler 4255682Smarkm * Copyright (C) 1989, Sun Microsystems, Inc. 4355682Smarkm */ 44178825Sdfr#include <err.h> 4555682Smarkm#include <stdio.h> 4655682Smarkm#include <string.h> 47178825Sdfr#include "rpc_parse.h" 4855682Smarkm#include "rpc_scan.h" 49178825Sdfr#include "rpc_util.h" 50178825Sdfr 51178825Sdfr#define TABSIZE 8 52178825Sdfr#define TABCOUNT 5 5372445Sassar#define TABSTOP (TABSIZE*TABCOUNT) 54178825Sdfr 5555682Smarkmstatic char tabstr[TABCOUNT+1] = "\t\t\t\t\t"; 56 57static char tbl_hdr[] = "struct rpcgen_table %s_table[] = {\n"; 58static char tbl_end[] = "};\n"; 59 60static char null_entry[] = "\n\t(char *(*)())0,\n\ 61 \t(xdrproc_t) xdr_void,\t\t\t0,\n\ 62 \t(xdrproc_t) xdr_void,\t\t\t0,\n"; 63 64 65static char tbl_nproc[] = "int %s_nproc =\n\tsizeof(%s_table)/sizeof(%s_table[0]);\n\n"; 66 67static void write_table( definition * ); 68static void printit(const char *, const char *); 69 70void 71write_tables(void) 72{ 73 list *l; 74 definition *def; 75 76 f_print(fout, "\n"); 77 for (l = defined; l != NULL; l = l->next) { 78 def = (definition *) l->val; 79 if (def->def_kind == DEF_PROGRAM) { 80 write_table(def); 81 } 82 } 83} 84 85static void 86write_table(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 fputs(null_entry, fout); 107 } 108 for (proc = vp->procs; proc != NULL; proc = proc->next) { 109 current = atoi(proc->proc_num); 110 if (current != expected++) { 111 f_print(fout, 112 "\n/*\n * WARNING: table out of order\n */\n"); 113 if (warning == 0) { 114 warnx("WARNING %s table is out of order", progvers); 115 warning = 1; 116 nonfatalerrors = 1; 117 } 118 expected = current + 1; 119 } 120 f_print(fout, "\n\t(char *(*)())RPCGEN_ACTION("); 121 122 /* routine to invoke */ 123 if( !newstyle ) 124 pvname_svc(proc->proc_name, vp->vers_num); 125 else { 126 if( newstyle ) 127 f_print( fout, "_"); /* calls internal func */ 128 pvname(proc->proc_name, vp->vers_num); 129 } 130 f_print(fout, "),\n"); 131 132 /* argument info */ 133 if( proc->arg_num > 1 ) 134 printit((char*) NULL, proc->args.argname ); 135 else 136 /* do we have to do something special for newstyle */ 137 printit( proc->args.decls->decl.prefix, 138 proc->args.decls->decl.type ); 139 /* result info */ 140 printit(proc->res_prefix, proc->res_type); 141 } 142 143 /* print the table trailer */ 144 fputs(tbl_end, fout); 145 f_print(fout, tbl_nproc, progvers, progvers, progvers); 146 } 147} 148 149static void 150printit(const char *prefix, const char *type) 151{ 152 int len; 153 int tabs; 154 155 156 len = fprintf(fout, "\txdr_%s,", stringfix(type)); 157 /* account for leading tab expansion */ 158 len += TABSIZE - 1; 159 /* round up to tabs required */ 160 tabs = (TABSTOP - len + TABSIZE - 1)/TABSIZE; 161 f_print(fout, "%s", &tabstr[TABCOUNT-tabs]); 162 163 if (streq(type, "void")) { 164 f_print(fout, "0"); 165 } else { 166 f_print(fout, "sizeof ( "); 167 /* XXX: should "follow" be 1 ??? */ 168 ptype(prefix, type, 0); 169 f_print(fout, ")"); 170 } 171 f_print(fout, ",\n"); 172} 173