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 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*61961e0fSrobinson */ 22*61961e0fSrobinson 23*61961e0fSrobinson /* 24*61961e0fSrobinson * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 257c478bd9Sstevel@tonic-gate * Use is subject to license terms. 267c478bd9Sstevel@tonic-gate */ 277c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 287c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 317c478bd9Sstevel@tonic-gate * The Regents of the University of California 327c478bd9Sstevel@tonic-gate * All Rights Reserved 337c478bd9Sstevel@tonic-gate * 347c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 357c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 367c478bd9Sstevel@tonic-gate * contributors. 377c478bd9Sstevel@tonic-gate */ 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate /* 427c478bd9Sstevel@tonic-gate * rpc_hout.c, Header file outputter for the RPC protocol compiler 437c478bd9Sstevel@tonic-gate */ 447c478bd9Sstevel@tonic-gate #include <stdio.h> 45*61961e0fSrobinson #include <stdlib.h> 467c478bd9Sstevel@tonic-gate #include <ctype.h> 477c478bd9Sstevel@tonic-gate #include "rpc_parse.h" 487c478bd9Sstevel@tonic-gate #include "rpc_util.h" 497c478bd9Sstevel@tonic-gate 50*61961e0fSrobinson extern void pprocdef(proc_list *, version_list *, char *, int, int); 51*61961e0fSrobinson extern void pdeclaration(char *, declaration *, int, char *); 527c478bd9Sstevel@tonic-gate 53*61961e0fSrobinson static void storexdrfuncdecl(char *, int); 54*61961e0fSrobinson static void pconstdef(definition *); 55*61961e0fSrobinson static void pstructdef(definition *); 56*61961e0fSrobinson static void puniondef(definition *); 57*61961e0fSrobinson static void pdefine(char *, char *); 58*61961e0fSrobinson static void pprogramdef(definition *); 59*61961e0fSrobinson static void parglist(proc_list *, char *); 60*61961e0fSrobinson static void penumdef(definition *); 61*61961e0fSrobinson static void ptypedef(definition *); 62*61961e0fSrobinson static uint_t undefined2(char *, char *); 637c478bd9Sstevel@tonic-gate 64*61961e0fSrobinson enum rpc_gvc { 657c478bd9Sstevel@tonic-gate PROGRAM, 667c478bd9Sstevel@tonic-gate VERSION, 677c478bd9Sstevel@tonic-gate PROCEDURE 687c478bd9Sstevel@tonic-gate }; 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate /* 717c478bd9Sstevel@tonic-gate * Print the C-version of an xdr definition 727c478bd9Sstevel@tonic-gate */ 737c478bd9Sstevel@tonic-gate void 74*61961e0fSrobinson print_datadef(definition *def) 757c478bd9Sstevel@tonic-gate { 767c478bd9Sstevel@tonic-gate if (def->def_kind == DEF_PROGRAM) /* handle data only */ 777c478bd9Sstevel@tonic-gate return; 787c478bd9Sstevel@tonic-gate 79*61961e0fSrobinson if (def->def_kind != DEF_CONST) 807c478bd9Sstevel@tonic-gate f_print(fout, "\n"); 817c478bd9Sstevel@tonic-gate switch (def->def_kind) { 827c478bd9Sstevel@tonic-gate case DEF_STRUCT: 837c478bd9Sstevel@tonic-gate pstructdef(def); 847c478bd9Sstevel@tonic-gate break; 857c478bd9Sstevel@tonic-gate case DEF_UNION: 867c478bd9Sstevel@tonic-gate puniondef(def); 877c478bd9Sstevel@tonic-gate break; 887c478bd9Sstevel@tonic-gate case DEF_ENUM: 897c478bd9Sstevel@tonic-gate penumdef(def); 907c478bd9Sstevel@tonic-gate break; 917c478bd9Sstevel@tonic-gate case DEF_TYPEDEF: 927c478bd9Sstevel@tonic-gate ptypedef(def); 937c478bd9Sstevel@tonic-gate break; 947c478bd9Sstevel@tonic-gate case DEF_PROGRAM: 957c478bd9Sstevel@tonic-gate pprogramdef(def); 967c478bd9Sstevel@tonic-gate break; 977c478bd9Sstevel@tonic-gate case DEF_CONST: 987c478bd9Sstevel@tonic-gate pconstdef(def); 997c478bd9Sstevel@tonic-gate break; 1007c478bd9Sstevel@tonic-gate } 101*61961e0fSrobinson if (def->def_kind != DEF_PROGRAM && def->def_kind != DEF_CONST) 1027c478bd9Sstevel@tonic-gate storexdrfuncdecl(def->def_name, def->def_kind != DEF_TYPEDEF || 1037c478bd9Sstevel@tonic-gate !isvectordef(def->def.ty.old_type, def->def.ty.rel)); 1047c478bd9Sstevel@tonic-gate } 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate void 1087c478bd9Sstevel@tonic-gate print_funcdef(definition *def) 1097c478bd9Sstevel@tonic-gate { 1107c478bd9Sstevel@tonic-gate switch (def->def_kind) { 1117c478bd9Sstevel@tonic-gate case DEF_PROGRAM: 1127c478bd9Sstevel@tonic-gate f_print(fout, "\n"); 1137c478bd9Sstevel@tonic-gate pprogramdef(def); 1147c478bd9Sstevel@tonic-gate break; 1157c478bd9Sstevel@tonic-gate } 1167c478bd9Sstevel@tonic-gate } 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate /* 1197c478bd9Sstevel@tonic-gate * store away enough information to allow the XDR functions to be spat 1207c478bd9Sstevel@tonic-gate * out at the end of the file 1217c478bd9Sstevel@tonic-gate */ 122*61961e0fSrobinson static void 1237c478bd9Sstevel@tonic-gate storexdrfuncdecl(char *name, int pointerp) 1247c478bd9Sstevel@tonic-gate { 1257c478bd9Sstevel@tonic-gate xdrfunc *xdrptr; 1267c478bd9Sstevel@tonic-gate 127*61961e0fSrobinson xdrptr = malloc(sizeof (struct xdrfunc)); 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate xdrptr->name = name; 1307c478bd9Sstevel@tonic-gate xdrptr->pointerp = pointerp; 1317c478bd9Sstevel@tonic-gate xdrptr->next = NULL; 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate if (xdrfunc_tail == NULL) { 1347c478bd9Sstevel@tonic-gate xdrfunc_head = xdrptr; 1357c478bd9Sstevel@tonic-gate xdrfunc_tail = xdrptr; 1367c478bd9Sstevel@tonic-gate } else { 1377c478bd9Sstevel@tonic-gate xdrfunc_tail->next = xdrptr; 1387c478bd9Sstevel@tonic-gate xdrfunc_tail = xdrptr; 1397c478bd9Sstevel@tonic-gate } 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate } 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate void 1457c478bd9Sstevel@tonic-gate print_xdr_func_def(char *name, int pointerp, int i) 1467c478bd9Sstevel@tonic-gate { 1477c478bd9Sstevel@tonic-gate if (i == 2) 1487c478bd9Sstevel@tonic-gate f_print(fout, "extern bool_t xdr_%s();\n", name); 1497c478bd9Sstevel@tonic-gate else 1507c478bd9Sstevel@tonic-gate f_print(fout, "extern bool_t xdr_%s(XDR *, %s%s);\n", name, 1517c478bd9Sstevel@tonic-gate name, pointerp ? "*" : ""); 1527c478bd9Sstevel@tonic-gate } 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate 155*61961e0fSrobinson static void 1567c478bd9Sstevel@tonic-gate pconstdef(definition *def) 1577c478bd9Sstevel@tonic-gate { 1587c478bd9Sstevel@tonic-gate pdefine(def->def_name, def->def.co); 1597c478bd9Sstevel@tonic-gate } 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate /* 1627c478bd9Sstevel@tonic-gate * print out the definitions for the arguments of functions in the 1637c478bd9Sstevel@tonic-gate * header file 1647c478bd9Sstevel@tonic-gate */ 165*61961e0fSrobinson static void 1667c478bd9Sstevel@tonic-gate pargdef(definition *def) 1677c478bd9Sstevel@tonic-gate { 1687c478bd9Sstevel@tonic-gate decl_list *l; 1697c478bd9Sstevel@tonic-gate version_list *vers; 1707c478bd9Sstevel@tonic-gate char *name; 1717c478bd9Sstevel@tonic-gate proc_list *plist; 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) { 174*61961e0fSrobinson for (plist = vers->procs; plist != NULL; plist = plist->next) { 175*61961e0fSrobinson if (!newstyle || plist->arg_num < 2) 1767c478bd9Sstevel@tonic-gate continue; /* old style or single args */ 1777c478bd9Sstevel@tonic-gate name = plist->args.argname; 1787c478bd9Sstevel@tonic-gate f_print(fout, "struct %s {\n", name); 179*61961e0fSrobinson for (l = plist->args.decls; l != NULL; l = l->next) 1807c478bd9Sstevel@tonic-gate pdeclaration(name, &l->decl, 1, ";\n"); 1817c478bd9Sstevel@tonic-gate f_print(fout, "};\n"); 182*61961e0fSrobinson f_print(fout, "typedef struct %s %s;\n", name, name); 1837c478bd9Sstevel@tonic-gate storexdrfuncdecl(name, 1); 1847c478bd9Sstevel@tonic-gate f_print(fout, "\n"); 1857c478bd9Sstevel@tonic-gate } 1867c478bd9Sstevel@tonic-gate } 1877c478bd9Sstevel@tonic-gate } 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate 190*61961e0fSrobinson static void 191*61961e0fSrobinson pstructdef(definition *def) 1927c478bd9Sstevel@tonic-gate { 1937c478bd9Sstevel@tonic-gate decl_list *l; 1947c478bd9Sstevel@tonic-gate char *name = def->def_name; 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate f_print(fout, "struct %s {\n", name); 197*61961e0fSrobinson for (l = def->def.st.decls; l != NULL; l = l->next) 1987c478bd9Sstevel@tonic-gate pdeclaration(name, &l->decl, 1, ";\n"); 1997c478bd9Sstevel@tonic-gate f_print(fout, "};\n"); 2007c478bd9Sstevel@tonic-gate f_print(fout, "typedef struct %s %s;\n", name, name); 2017c478bd9Sstevel@tonic-gate } 2027c478bd9Sstevel@tonic-gate 203*61961e0fSrobinson static void 204*61961e0fSrobinson puniondef(definition *def) 2057c478bd9Sstevel@tonic-gate { 2067c478bd9Sstevel@tonic-gate case_list *l; 2077c478bd9Sstevel@tonic-gate char *name = def->def_name; 2087c478bd9Sstevel@tonic-gate declaration *decl; 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate f_print(fout, "struct %s {\n", name); 2117c478bd9Sstevel@tonic-gate decl = &def->def.un.enum_decl; 212*61961e0fSrobinson if (streq(decl->type, "bool")) 2137c478bd9Sstevel@tonic-gate f_print(fout, "\tbool_t %s;\n", decl->name); 214*61961e0fSrobinson else 2157c478bd9Sstevel@tonic-gate f_print(fout, "\t%s %s;\n", decl->type, decl->name); 2167c478bd9Sstevel@tonic-gate f_print(fout, "\tunion {\n"); 2177c478bd9Sstevel@tonic-gate for (l = def->def.un.cases; l != NULL; l = l->next) { 2187c478bd9Sstevel@tonic-gate if (l->contflag == 0) 2197c478bd9Sstevel@tonic-gate pdeclaration(name, &l->case_decl, 2, ";\n"); 2207c478bd9Sstevel@tonic-gate } 2217c478bd9Sstevel@tonic-gate decl = def->def.un.default_decl; 222*61961e0fSrobinson if (decl && !streq(decl->type, "void")) 2237c478bd9Sstevel@tonic-gate pdeclaration(name, decl, 2, ";\n"); 2247c478bd9Sstevel@tonic-gate f_print(fout, "\t} %s_u;\n", name); 2257c478bd9Sstevel@tonic-gate f_print(fout, "};\n"); 2267c478bd9Sstevel@tonic-gate f_print(fout, "typedef struct %s %s;\n", name, name); 2277c478bd9Sstevel@tonic-gate } 2287c478bd9Sstevel@tonic-gate 229*61961e0fSrobinson static void 230*61961e0fSrobinson pdefine(char *name, char *num) 2317c478bd9Sstevel@tonic-gate { 2327c478bd9Sstevel@tonic-gate f_print(fout, "#define\t%s %s\n", name, num); 2337c478bd9Sstevel@tonic-gate } 2347c478bd9Sstevel@tonic-gate 235*61961e0fSrobinson static void 2367c478bd9Sstevel@tonic-gate puldefine(char *name, char *num, enum rpc_gvc which) 2377c478bd9Sstevel@tonic-gate { 2387c478bd9Sstevel@tonic-gate switch (which) { 2397c478bd9Sstevel@tonic-gate case PROGRAM: 2407c478bd9Sstevel@tonic-gate case VERSION: 2417c478bd9Sstevel@tonic-gate case PROCEDURE: 2427c478bd9Sstevel@tonic-gate f_print(fout, "#define\t%s\t%s\n", name, num); 2437c478bd9Sstevel@tonic-gate break; 2447c478bd9Sstevel@tonic-gate default: 2457c478bd9Sstevel@tonic-gate break; 2467c478bd9Sstevel@tonic-gate } 2477c478bd9Sstevel@tonic-gate } 2487c478bd9Sstevel@tonic-gate 249*61961e0fSrobinson static uint_t 2507c478bd9Sstevel@tonic-gate define_printed(proc_list *stop, version_list *start) 2517c478bd9Sstevel@tonic-gate { 2527c478bd9Sstevel@tonic-gate version_list *vers; 2537c478bd9Sstevel@tonic-gate proc_list *proc; 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate for (vers = start; vers != NULL; vers = vers->next) { 2567c478bd9Sstevel@tonic-gate for (proc = vers->procs; proc != NULL; proc = proc->next) { 257*61961e0fSrobinson if (proc == stop) 2587c478bd9Sstevel@tonic-gate return (0); 259*61961e0fSrobinson if (streq(proc->proc_name, stop->proc_name)) 2607c478bd9Sstevel@tonic-gate return (1); 2617c478bd9Sstevel@tonic-gate } 2627c478bd9Sstevel@tonic-gate } 2637c478bd9Sstevel@tonic-gate abort(); 2647c478bd9Sstevel@tonic-gate /* NOTREACHED */ 2657c478bd9Sstevel@tonic-gate } 2667c478bd9Sstevel@tonic-gate 267*61961e0fSrobinson static void 2687c478bd9Sstevel@tonic-gate pfreeprocdef(char *name, char *vers, int mode) 2697c478bd9Sstevel@tonic-gate { 2707c478bd9Sstevel@tonic-gate f_print(fout, "extern int "); 2717c478bd9Sstevel@tonic-gate pvname(name, vers); 2727c478bd9Sstevel@tonic-gate if (mode == 1) 2737c478bd9Sstevel@tonic-gate f_print(fout, "_freeresult(SVCXPRT *, xdrproc_t, caddr_t);\n"); 2747c478bd9Sstevel@tonic-gate else 2757c478bd9Sstevel@tonic-gate f_print(fout, "_freeresult();\n"); 2767c478bd9Sstevel@tonic-gate } 2777c478bd9Sstevel@tonic-gate 278*61961e0fSrobinson static void 279*61961e0fSrobinson pprogramdef(definition *def) 2807c478bd9Sstevel@tonic-gate { 2817c478bd9Sstevel@tonic-gate version_list *vers; 2827c478bd9Sstevel@tonic-gate proc_list *proc; 2837c478bd9Sstevel@tonic-gate int i; 2847c478bd9Sstevel@tonic-gate char *ext; 2857c478bd9Sstevel@tonic-gate 2867c478bd9Sstevel@tonic-gate pargdef(def); 2877c478bd9Sstevel@tonic-gate 2887c478bd9Sstevel@tonic-gate puldefine(def->def_name, def->def.pr.prog_num, PROGRAM); 2897c478bd9Sstevel@tonic-gate for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) { 2907c478bd9Sstevel@tonic-gate if (tblflag) { 2917c478bd9Sstevel@tonic-gate f_print(fout, 2927c478bd9Sstevel@tonic-gate "extern struct rpcgen_table %s_%s_table[];\n", 2937c478bd9Sstevel@tonic-gate locase(def->def_name), vers->vers_num); 2947c478bd9Sstevel@tonic-gate f_print(fout, 295*61961e0fSrobinson "extern int %s_%s_nproc;\n", 2967c478bd9Sstevel@tonic-gate locase(def->def_name), vers->vers_num); 2977c478bd9Sstevel@tonic-gate } 2987c478bd9Sstevel@tonic-gate puldefine(vers->vers_name, vers->vers_num, VERSION); 2997c478bd9Sstevel@tonic-gate 3007c478bd9Sstevel@tonic-gate /* 3017c478bd9Sstevel@tonic-gate * Print out 2 definitions, one for ANSI-C, another for 3027c478bd9Sstevel@tonic-gate * old K & R C 3037c478bd9Sstevel@tonic-gate */ 3047c478bd9Sstevel@tonic-gate 3057c478bd9Sstevel@tonic-gate if (!Cflag) { 3067c478bd9Sstevel@tonic-gate ext = "extern "; 3077c478bd9Sstevel@tonic-gate for (proc = vers->procs; proc != NULL; 3087c478bd9Sstevel@tonic-gate proc = proc->next) { 309*61961e0fSrobinson if (!define_printed(proc, def->def.pr.versions)) 3107c478bd9Sstevel@tonic-gate puldefine(proc->proc_name, 3117c478bd9Sstevel@tonic-gate proc->proc_num, PROCEDURE); 3127c478bd9Sstevel@tonic-gate f_print(fout, "%s", ext); 3137c478bd9Sstevel@tonic-gate pprocdef(proc, vers, NULL, 0, 2); 3147c478bd9Sstevel@tonic-gate 3157c478bd9Sstevel@tonic-gate if (mtflag) { 3167c478bd9Sstevel@tonic-gate f_print(fout, "%s", ext); 3177c478bd9Sstevel@tonic-gate pprocdef(proc, vers, NULL, 1, 2); 3187c478bd9Sstevel@tonic-gate } 3197c478bd9Sstevel@tonic-gate } 3207c478bd9Sstevel@tonic-gate pfreeprocdef(def->def_name, vers->vers_num, 2); 3217c478bd9Sstevel@tonic-gate } else { 3227c478bd9Sstevel@tonic-gate for (i = 1; i < 3; i++) { 3237c478bd9Sstevel@tonic-gate if (i == 1) { 3247c478bd9Sstevel@tonic-gate f_print(fout, "\n#if defined(__STDC__)" 3257c478bd9Sstevel@tonic-gate " || defined(__cplusplus)\n"); 3267c478bd9Sstevel@tonic-gate ext = "extern "; 3277c478bd9Sstevel@tonic-gate } else { 3287c478bd9Sstevel@tonic-gate f_print(fout, "\n#else /* K&R C */\n"); 3297c478bd9Sstevel@tonic-gate ext = "extern "; 3307c478bd9Sstevel@tonic-gate } 3317c478bd9Sstevel@tonic-gate 3327c478bd9Sstevel@tonic-gate for (proc = vers->procs; proc != NULL; 3337c478bd9Sstevel@tonic-gate proc = proc->next) { 3347c478bd9Sstevel@tonic-gate if (!define_printed(proc, 3357c478bd9Sstevel@tonic-gate def->def.pr.versions)) { 3367c478bd9Sstevel@tonic-gate puldefine(proc->proc_name, 3377c478bd9Sstevel@tonic-gate proc->proc_num, PROCEDURE); 3387c478bd9Sstevel@tonic-gate } 3397c478bd9Sstevel@tonic-gate f_print(fout, "%s", ext); 3407c478bd9Sstevel@tonic-gate pprocdef(proc, vers, "CLIENT *", 0, i); 3417c478bd9Sstevel@tonic-gate f_print(fout, "%s", ext); 3427c478bd9Sstevel@tonic-gate pprocdef(proc, vers, 3437c478bd9Sstevel@tonic-gate "struct svc_req *", 1, i); 3447c478bd9Sstevel@tonic-gate } 3457c478bd9Sstevel@tonic-gate pfreeprocdef(def->def_name, vers->vers_num, i); 3467c478bd9Sstevel@tonic-gate } 3477c478bd9Sstevel@tonic-gate f_print(fout, "#endif /* K&R C */\n"); 3487c478bd9Sstevel@tonic-gate } 3497c478bd9Sstevel@tonic-gate } 3507c478bd9Sstevel@tonic-gate } 3517c478bd9Sstevel@tonic-gate 352*61961e0fSrobinson void 353*61961e0fSrobinson pprocdef(proc_list *proc, version_list *vp, char *addargtype, int server_p, 354*61961e0fSrobinson int mode) 3557c478bd9Sstevel@tonic-gate { 3567c478bd9Sstevel@tonic-gate if (mtflag) { 3577c478bd9Sstevel@tonic-gate /* Print MT style stubs */ 3587c478bd9Sstevel@tonic-gate if (server_p) 3597c478bd9Sstevel@tonic-gate f_print(fout, "bool_t "); 3607c478bd9Sstevel@tonic-gate else 3617c478bd9Sstevel@tonic-gate f_print(fout, "enum clnt_stat "); 3627c478bd9Sstevel@tonic-gate } else { 3637c478bd9Sstevel@tonic-gate ptype(proc->res_prefix, proc->res_type, 1); 3647c478bd9Sstevel@tonic-gate f_print(fout, "* "); 3657c478bd9Sstevel@tonic-gate } 3667c478bd9Sstevel@tonic-gate if (server_p) 3677c478bd9Sstevel@tonic-gate pvname_svc(proc->proc_name, vp->vers_num); 3687c478bd9Sstevel@tonic-gate else 3697c478bd9Sstevel@tonic-gate pvname(proc->proc_name, vp->vers_num); 3707c478bd9Sstevel@tonic-gate 3717c478bd9Sstevel@tonic-gate /* 3727c478bd9Sstevel@tonic-gate * mode 1 = ANSI-C, mode 2 = K&R C 3737c478bd9Sstevel@tonic-gate */ 3747c478bd9Sstevel@tonic-gate if (mode == 1) 375*61961e0fSrobinson parglist(proc, addargtype); 3767c478bd9Sstevel@tonic-gate else 3777c478bd9Sstevel@tonic-gate f_print(fout, "();\n"); 3787c478bd9Sstevel@tonic-gate } 3797c478bd9Sstevel@tonic-gate 3807c478bd9Sstevel@tonic-gate /* print out argument list of procedure */ 381*61961e0fSrobinson static void 382*61961e0fSrobinson parglist(proc_list *proc, char *addargtype) 3837c478bd9Sstevel@tonic-gate { 3847c478bd9Sstevel@tonic-gate decl_list *dl; 3857c478bd9Sstevel@tonic-gate int oneway = streq(proc->res_type, "oneway"); 3867c478bd9Sstevel@tonic-gate 3877c478bd9Sstevel@tonic-gate f_print(fout, "("); 3887c478bd9Sstevel@tonic-gate if (proc->arg_num < 2 && newstyle && 3897c478bd9Sstevel@tonic-gate streq(proc->args.decls->decl.type, "void")) { 3907c478bd9Sstevel@tonic-gate /* 0 argument in new style: do nothing */ 391*61961e0fSrobinson /* EMPTY */ 3927c478bd9Sstevel@tonic-gate } else { 3937c478bd9Sstevel@tonic-gate for (dl = proc->args.decls; dl != NULL; dl = dl->next) { 3947c478bd9Sstevel@tonic-gate ptype(dl->decl.prefix, dl->decl.type, 1); 3957c478bd9Sstevel@tonic-gate if (!newstyle || (dl->decl.rel == REL_POINTER)) 3967c478bd9Sstevel@tonic-gate f_print(fout, "*"); 3977c478bd9Sstevel@tonic-gate /* old style passes by reference */ 3987c478bd9Sstevel@tonic-gate f_print(fout, ", "); 3997c478bd9Sstevel@tonic-gate } 4007c478bd9Sstevel@tonic-gate } 4017c478bd9Sstevel@tonic-gate 4027c478bd9Sstevel@tonic-gate if (mtflag && !oneway) { 4037c478bd9Sstevel@tonic-gate ptype(proc->res_prefix, proc->res_type, 1); 4047c478bd9Sstevel@tonic-gate f_print(fout, "*, "); 4057c478bd9Sstevel@tonic-gate } 4067c478bd9Sstevel@tonic-gate 4077c478bd9Sstevel@tonic-gate f_print(fout, "%s);\n", addargtype); 4087c478bd9Sstevel@tonic-gate } 4097c478bd9Sstevel@tonic-gate 410*61961e0fSrobinson static void 411*61961e0fSrobinson penumdef(definition *def) 4127c478bd9Sstevel@tonic-gate { 4137c478bd9Sstevel@tonic-gate char *name = def->def_name; 4147c478bd9Sstevel@tonic-gate enumval_list *l; 4157c478bd9Sstevel@tonic-gate char *last = NULL; 4167c478bd9Sstevel@tonic-gate int count = 0; 4177c478bd9Sstevel@tonic-gate 4187c478bd9Sstevel@tonic-gate f_print(fout, "enum %s {\n", name); 4197c478bd9Sstevel@tonic-gate for (l = def->def.en.vals; l != NULL; l = l->next) { 4207c478bd9Sstevel@tonic-gate f_print(fout, "\t%s", l->name); 4217c478bd9Sstevel@tonic-gate if (l->assignment) { 4227c478bd9Sstevel@tonic-gate f_print(fout, " = %s", l->assignment); 4237c478bd9Sstevel@tonic-gate last = l->assignment; 4247c478bd9Sstevel@tonic-gate count = 1; 4257c478bd9Sstevel@tonic-gate } else { 426*61961e0fSrobinson if (last == NULL) 4277c478bd9Sstevel@tonic-gate f_print(fout, " = %d", count++); 428*61961e0fSrobinson else 4297c478bd9Sstevel@tonic-gate f_print(fout, " = %s + %d", last, count++); 4307c478bd9Sstevel@tonic-gate } 4317c478bd9Sstevel@tonic-gate if (l->next) 4327c478bd9Sstevel@tonic-gate f_print(fout, ",\n"); 4337c478bd9Sstevel@tonic-gate else 4347c478bd9Sstevel@tonic-gate f_print(fout, "\n"); 4357c478bd9Sstevel@tonic-gate } 4367c478bd9Sstevel@tonic-gate f_print(fout, "};\n"); 4377c478bd9Sstevel@tonic-gate f_print(fout, "typedef enum %s %s;\n", name, name); 4387c478bd9Sstevel@tonic-gate } 4397c478bd9Sstevel@tonic-gate 440*61961e0fSrobinson static void 441*61961e0fSrobinson ptypedef(definition *def) 4427c478bd9Sstevel@tonic-gate { 4437c478bd9Sstevel@tonic-gate char *name = def->def_name; 4447c478bd9Sstevel@tonic-gate char *old = def->def.ty.old_type; 4457c478bd9Sstevel@tonic-gate char prefix[8]; /* enough to contain "struct ", including NUL */ 4467c478bd9Sstevel@tonic-gate relation rel = def->def.ty.rel; 4477c478bd9Sstevel@tonic-gate 4487c478bd9Sstevel@tonic-gate 4497c478bd9Sstevel@tonic-gate if (!streq(name, old)) { 4507c478bd9Sstevel@tonic-gate if (streq(old, "string")) { 4517c478bd9Sstevel@tonic-gate old = "char"; 4527c478bd9Sstevel@tonic-gate rel = REL_POINTER; 4537c478bd9Sstevel@tonic-gate } else if (streq(old, "opaque")) { 4547c478bd9Sstevel@tonic-gate old = "char"; 4557c478bd9Sstevel@tonic-gate } else if (streq(old, "bool")) { 4567c478bd9Sstevel@tonic-gate old = "bool_t"; 4577c478bd9Sstevel@tonic-gate } 458*61961e0fSrobinson if (undefined2(old, name) && def->def.ty.old_prefix) 459*61961e0fSrobinson (void) snprintf(prefix, sizeof (prefix), "%s ", 460*61961e0fSrobinson def->def.ty.old_prefix); 461*61961e0fSrobinson else 4627c478bd9Sstevel@tonic-gate prefix[0] = 0; 4637c478bd9Sstevel@tonic-gate f_print(fout, "typedef "); 4647c478bd9Sstevel@tonic-gate switch (rel) { 4657c478bd9Sstevel@tonic-gate case REL_ARRAY: 4667c478bd9Sstevel@tonic-gate f_print(fout, "struct {\n"); 4677c478bd9Sstevel@tonic-gate f_print(fout, "\tu_int %s_len;\n", name); 4687c478bd9Sstevel@tonic-gate f_print(fout, "\t%s%s *%s_val;\n", prefix, old, name); 4697c478bd9Sstevel@tonic-gate f_print(fout, "} %s", name); 4707c478bd9Sstevel@tonic-gate break; 4717c478bd9Sstevel@tonic-gate case REL_POINTER: 4727c478bd9Sstevel@tonic-gate f_print(fout, "%s%s *%s", prefix, old, name); 4737c478bd9Sstevel@tonic-gate break; 4747c478bd9Sstevel@tonic-gate case REL_VECTOR: 4757c478bd9Sstevel@tonic-gate f_print(fout, "%s%s %s[%s]", prefix, old, name, 4767c478bd9Sstevel@tonic-gate def->def.ty.array_max); 4777c478bd9Sstevel@tonic-gate break; 4787c478bd9Sstevel@tonic-gate case REL_ALIAS: 4797c478bd9Sstevel@tonic-gate f_print(fout, "%s%s %s", prefix, old, name); 4807c478bd9Sstevel@tonic-gate break; 4817c478bd9Sstevel@tonic-gate } 4827c478bd9Sstevel@tonic-gate f_print(fout, ";\n"); 4837c478bd9Sstevel@tonic-gate } 4847c478bd9Sstevel@tonic-gate } 4857c478bd9Sstevel@tonic-gate 486*61961e0fSrobinson void 487*61961e0fSrobinson pdeclaration(char *name, declaration *dec, int tab, char *separator) 4887c478bd9Sstevel@tonic-gate { 4897c478bd9Sstevel@tonic-gate char buf[8]; /* enough to hold "struct ", include NUL */ 4907c478bd9Sstevel@tonic-gate char *prefix; 4917c478bd9Sstevel@tonic-gate char *type; 4927c478bd9Sstevel@tonic-gate 493*61961e0fSrobinson if (streq(dec->type, "void")) 4947c478bd9Sstevel@tonic-gate return; 4957c478bd9Sstevel@tonic-gate tabify(fout, tab); 496*61961e0fSrobinson if (streq(dec->type, name) && !dec->prefix) 4977c478bd9Sstevel@tonic-gate f_print(fout, "struct "); 4987c478bd9Sstevel@tonic-gate if (streq(dec->type, "string")) { 4997c478bd9Sstevel@tonic-gate f_print(fout, "char *%s", dec->name); 5007c478bd9Sstevel@tonic-gate } else { 5017c478bd9Sstevel@tonic-gate prefix = ""; 5027c478bd9Sstevel@tonic-gate if (streq(dec->type, "bool")) { 5037c478bd9Sstevel@tonic-gate type = "bool_t"; 5047c478bd9Sstevel@tonic-gate } else if (streq(dec->type, "opaque")) { 5057c478bd9Sstevel@tonic-gate type = "char"; 5067c478bd9Sstevel@tonic-gate } else { 5077c478bd9Sstevel@tonic-gate if (dec->prefix) { 508*61961e0fSrobinson (void) snprintf(buf, sizeof (buf), 509*61961e0fSrobinson "%s ", dec->prefix); 5107c478bd9Sstevel@tonic-gate prefix = buf; 5117c478bd9Sstevel@tonic-gate } 5127c478bd9Sstevel@tonic-gate type = dec->type; 5137c478bd9Sstevel@tonic-gate } 5147c478bd9Sstevel@tonic-gate switch (dec->rel) { 5157c478bd9Sstevel@tonic-gate case REL_ALIAS: 5167c478bd9Sstevel@tonic-gate f_print(fout, "%s%s %s", prefix, type, dec->name); 5177c478bd9Sstevel@tonic-gate break; 5187c478bd9Sstevel@tonic-gate case REL_VECTOR: 5197c478bd9Sstevel@tonic-gate f_print(fout, "%s%s %s[%s]", prefix, type, dec->name, 5207c478bd9Sstevel@tonic-gate dec->array_max); 5217c478bd9Sstevel@tonic-gate break; 5227c478bd9Sstevel@tonic-gate case REL_POINTER: 5237c478bd9Sstevel@tonic-gate f_print(fout, "%s%s *%s", prefix, type, dec->name); 5247c478bd9Sstevel@tonic-gate break; 5257c478bd9Sstevel@tonic-gate case REL_ARRAY: 5267c478bd9Sstevel@tonic-gate f_print(fout, "struct {\n"); 5277c478bd9Sstevel@tonic-gate tabify(fout, tab); 5287c478bd9Sstevel@tonic-gate f_print(fout, "\tu_int %s_len;\n", dec->name); 5297c478bd9Sstevel@tonic-gate tabify(fout, tab); 5307c478bd9Sstevel@tonic-gate f_print(fout, 5317c478bd9Sstevel@tonic-gate "\t%s%s *%s_val;\n", prefix, type, dec->name); 5327c478bd9Sstevel@tonic-gate tabify(fout, tab); 5337c478bd9Sstevel@tonic-gate f_print(fout, "} %s", dec->name); 5347c478bd9Sstevel@tonic-gate break; 5357c478bd9Sstevel@tonic-gate } 5367c478bd9Sstevel@tonic-gate } 537*61961e0fSrobinson /* LINTED variable format */ 5387c478bd9Sstevel@tonic-gate f_print(fout, separator); 5397c478bd9Sstevel@tonic-gate } 5407c478bd9Sstevel@tonic-gate 541*61961e0fSrobinson static uint_t 542*61961e0fSrobinson undefined2(char *type, char *stop) 5437c478bd9Sstevel@tonic-gate { 5447c478bd9Sstevel@tonic-gate list *l; 5457c478bd9Sstevel@tonic-gate definition *def; 5467c478bd9Sstevel@tonic-gate 5477c478bd9Sstevel@tonic-gate for (l = defined; l != NULL; l = l->next) { 5487c478bd9Sstevel@tonic-gate def = (definition *) l->val; 5497c478bd9Sstevel@tonic-gate if (def->def_kind != DEF_PROGRAM) { 550*61961e0fSrobinson if (streq(def->def_name, stop)) 5517c478bd9Sstevel@tonic-gate return (1); 552*61961e0fSrobinson if (streq(def->def_name, type)) 5537c478bd9Sstevel@tonic-gate return (0); 5547c478bd9Sstevel@tonic-gate } 5557c478bd9Sstevel@tonic-gate } 5567c478bd9Sstevel@tonic-gate return (1); 5577c478bd9Sstevel@tonic-gate } 558