17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*a2f144d1SJordan Brown * Common Development and Distribution License (the "License"). 6*a2f144d1SJordan Brown * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 2061961e0fSrobinson */ 2161961e0fSrobinson 2261961e0fSrobinson /* 23*a2f144d1SJordan Brown * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 277c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 287c478bd9Sstevel@tonic-gate /* 297c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 307c478bd9Sstevel@tonic-gate * The Regents of the University of California 317c478bd9Sstevel@tonic-gate * All Rights Reserved 327c478bd9Sstevel@tonic-gate * 337c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 347c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 357c478bd9Sstevel@tonic-gate * contributors. 367c478bd9Sstevel@tonic-gate */ 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate /* 397c478bd9Sstevel@tonic-gate * rpc_tblout.c, Dispatch table outputter for the RPC protocol compiler 407c478bd9Sstevel@tonic-gate */ 417c478bd9Sstevel@tonic-gate #include <stdio.h> 427c478bd9Sstevel@tonic-gate #include <string.h> 437c478bd9Sstevel@tonic-gate #include "rpc_parse.h" 447c478bd9Sstevel@tonic-gate #include "rpc_util.h" 457c478bd9Sstevel@tonic-gate 4661961e0fSrobinson extern int nullproc(proc_list *); 4761961e0fSrobinson 4861961e0fSrobinson static void write_table(definition *); 4961961e0fSrobinson static void printit(char *, char *); 5061961e0fSrobinson 517c478bd9Sstevel@tonic-gate #define TABSIZE 8 527c478bd9Sstevel@tonic-gate #define TABCOUNT 5 537c478bd9Sstevel@tonic-gate #define TABSTOP (TABSIZE*TABCOUNT) 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate static char tabstr[TABCOUNT+1] = "\t\t\t\t\t"; 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate static char tbl_hdr[] = "struct rpcgen_table %s_table[] = {\n"; 587c478bd9Sstevel@tonic-gate static char tbl_end[] = "};\n"; 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate static char null_entry_b[] = "\n\t(char *(*)())0,\n" 617c478bd9Sstevel@tonic-gate " \t(xdrproc_t)xdr_void,\t\t\t0,\n" 627c478bd9Sstevel@tonic-gate " \t(xdrproc_t)xdr_void,\t\t\t0,\n"; 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate static char null_entry[] = "\n\t(void *(*)())0,\n" 657c478bd9Sstevel@tonic-gate " \t(xdrproc_t)xdr_void,\t\t\t0,\n" 667c478bd9Sstevel@tonic-gate " \t(xdrproc_t)xdr_void,\t\t\t0,\n"; 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate static char tbl_nproc[] = "int %s_nproc =\n\tsizeof(%s_table)" 707c478bd9Sstevel@tonic-gate "/sizeof(%s_table[0]);\n\n"; 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate void 7361961e0fSrobinson write_tables(void) 747c478bd9Sstevel@tonic-gate { 757c478bd9Sstevel@tonic-gate list *l; 767c478bd9Sstevel@tonic-gate definition *def; 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate f_print(fout, "\n"); 797c478bd9Sstevel@tonic-gate for (l = defined; l != NULL; l = l->next) { 807c478bd9Sstevel@tonic-gate def = (definition *)l->val; 817c478bd9Sstevel@tonic-gate if (def->def_kind == DEF_PROGRAM) { 827c478bd9Sstevel@tonic-gate write_table(def); 837c478bd9Sstevel@tonic-gate } 847c478bd9Sstevel@tonic-gate } 857c478bd9Sstevel@tonic-gate } 867c478bd9Sstevel@tonic-gate 8761961e0fSrobinson static void 8861961e0fSrobinson write_table(definition *def) 897c478bd9Sstevel@tonic-gate { 907c478bd9Sstevel@tonic-gate version_list *vp; 917c478bd9Sstevel@tonic-gate proc_list *proc; 927c478bd9Sstevel@tonic-gate int current; 937c478bd9Sstevel@tonic-gate int expected; 947c478bd9Sstevel@tonic-gate char progvers[100]; 957c478bd9Sstevel@tonic-gate int warning; 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { 987c478bd9Sstevel@tonic-gate warning = 0; 9961961e0fSrobinson (void) snprintf(progvers, sizeof (progvers), "%s_%s", 1007c478bd9Sstevel@tonic-gate locase(def->def_name), vp->vers_num); 1017c478bd9Sstevel@tonic-gate /* print the table header */ 1027c478bd9Sstevel@tonic-gate f_print(fout, tbl_hdr, progvers); 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate if (nullproc(vp->procs)) { 1057c478bd9Sstevel@tonic-gate expected = 0; 1067c478bd9Sstevel@tonic-gate } else { 1077c478bd9Sstevel@tonic-gate expected = 1; 1087c478bd9Sstevel@tonic-gate if (tirpcflag) 1097c478bd9Sstevel@tonic-gate f_print(fout, null_entry); 1107c478bd9Sstevel@tonic-gate else 1117c478bd9Sstevel@tonic-gate f_print(fout, null_entry_b); 1127c478bd9Sstevel@tonic-gate } 1137c478bd9Sstevel@tonic-gate for (proc = vp->procs; proc != NULL; proc = proc->next) { 1147c478bd9Sstevel@tonic-gate current = atoi(proc->proc_num); 1157c478bd9Sstevel@tonic-gate if (current != expected++) { 1167c478bd9Sstevel@tonic-gate f_print(fout, 1177c478bd9Sstevel@tonic-gate "\n/*\n * WARNING: table out of order\n */\n"); 1187c478bd9Sstevel@tonic-gate if (warning == 0) { 1197c478bd9Sstevel@tonic-gate f_print(stderr, 1207c478bd9Sstevel@tonic-gate "WARNING %s table is out of order\n", 1217c478bd9Sstevel@tonic-gate progvers); 1227c478bd9Sstevel@tonic-gate warning = 1; 1237c478bd9Sstevel@tonic-gate nonfatalerrors = 1; 1247c478bd9Sstevel@tonic-gate } 1257c478bd9Sstevel@tonic-gate expected = current + 1; 1267c478bd9Sstevel@tonic-gate } 1277c478bd9Sstevel@tonic-gate if (tirpcflag) 1287c478bd9Sstevel@tonic-gate f_print(fout, 1297c478bd9Sstevel@tonic-gate "\n\t(void *(*)())RPCGEN_ACTION("); 1307c478bd9Sstevel@tonic-gate else 1317c478bd9Sstevel@tonic-gate f_print(fout, 1327c478bd9Sstevel@tonic-gate "\n\t(char *(*)())RPCGEN_ACTION("); 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate /* routine to invoke */ 1357c478bd9Sstevel@tonic-gate if (Cflag && !newstyle) 1367c478bd9Sstevel@tonic-gate pvname_svc(proc->proc_name, vp->vers_num); 1377c478bd9Sstevel@tonic-gate else { 1387c478bd9Sstevel@tonic-gate if (newstyle) /* calls internal func */ 1397c478bd9Sstevel@tonic-gate f_print(fout, "_"); 1407c478bd9Sstevel@tonic-gate pvname(proc->proc_name, vp->vers_num); 1417c478bd9Sstevel@tonic-gate } 1427c478bd9Sstevel@tonic-gate f_print(fout, "),\n"); 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate /* argument info */ 1457c478bd9Sstevel@tonic-gate if (proc->arg_num > 1) 14661961e0fSrobinson printit(NULL, proc->args.argname); 1477c478bd9Sstevel@tonic-gate else 1487c478bd9Sstevel@tonic-gate /* do we have to do something special for newstyle */ 1497c478bd9Sstevel@tonic-gate printit(proc->args.decls->decl.prefix, 1507c478bd9Sstevel@tonic-gate proc->args.decls->decl.type); 1517c478bd9Sstevel@tonic-gate /* result info */ 1527c478bd9Sstevel@tonic-gate printit(proc->res_prefix, proc->res_type); 1537c478bd9Sstevel@tonic-gate } 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate /* print the table trailer */ 1567c478bd9Sstevel@tonic-gate f_print(fout, tbl_end); 1577c478bd9Sstevel@tonic-gate f_print(fout, tbl_nproc, progvers, progvers, progvers); 1587c478bd9Sstevel@tonic-gate } 1597c478bd9Sstevel@tonic-gate } 1607c478bd9Sstevel@tonic-gate 16161961e0fSrobinson static void 16261961e0fSrobinson printit(char *prefix, char *type) 1637c478bd9Sstevel@tonic-gate { 1647c478bd9Sstevel@tonic-gate int len; 1657c478bd9Sstevel@tonic-gate int tabs; 1667c478bd9Sstevel@tonic-gate 1677c478bd9Sstevel@tonic-gate 16861961e0fSrobinson if (streq(type, "oneway")) 1697c478bd9Sstevel@tonic-gate len = fprintf(fout, "\t(xdrproc_t)xdr_void,"); 17061961e0fSrobinson else 1717c478bd9Sstevel@tonic-gate len = fprintf(fout, "\t(xdrproc_t)xdr_%s,", stringfix(type)); 1727c478bd9Sstevel@tonic-gate /* account for leading tab expansion */ 1737c478bd9Sstevel@tonic-gate len += TABSIZE - 1; 1747c478bd9Sstevel@tonic-gate if (len >= TABSTOP) { 1757c478bd9Sstevel@tonic-gate f_print(fout, "\n"); 1767c478bd9Sstevel@tonic-gate len = 0; 1777c478bd9Sstevel@tonic-gate } 1787c478bd9Sstevel@tonic-gate /* round up to tabs required */ 1797c478bd9Sstevel@tonic-gate tabs = (TABSTOP - len + TABSIZE - 1)/TABSIZE; 1807c478bd9Sstevel@tonic-gate f_print(fout, "%s", &tabstr[TABCOUNT-tabs]); 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gate if (streq(type, "void") || streq(type, "oneway")) { 1837c478bd9Sstevel@tonic-gate f_print(fout, "0"); 1847c478bd9Sstevel@tonic-gate } else { 1857c478bd9Sstevel@tonic-gate f_print(fout, "sizeof ( "); 1867c478bd9Sstevel@tonic-gate /* XXX: should "follow" be 1 ??? */ 1877c478bd9Sstevel@tonic-gate ptype(prefix, type, 0); 1887c478bd9Sstevel@tonic-gate f_print(fout, ")"); 1897c478bd9Sstevel@tonic-gate } 1907c478bd9Sstevel@tonic-gate f_print(fout, ",\n"); 1917c478bd9Sstevel@tonic-gate } 192