1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate * 22*7c478bd9Sstevel@tonic-gate * Copyright 2001 Sun Microsystems, Inc. All rights reserved. 23*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 24*7c478bd9Sstevel@tonic-gate */ 25*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 26*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 27*7c478bd9Sstevel@tonic-gate /* 28*7c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 29*7c478bd9Sstevel@tonic-gate * The Regents of the University of California 30*7c478bd9Sstevel@tonic-gate * All Rights Reserved 31*7c478bd9Sstevel@tonic-gate * 32*7c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 33*7c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 34*7c478bd9Sstevel@tonic-gate * contributors. 35*7c478bd9Sstevel@tonic-gate */ 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 38*7c478bd9Sstevel@tonic-gate 39*7c478bd9Sstevel@tonic-gate /* 40*7c478bd9Sstevel@tonic-gate * rpc_hout.c, Header file outputter for the RPC protocol compiler 41*7c478bd9Sstevel@tonic-gate */ 42*7c478bd9Sstevel@tonic-gate #include <stdio.h> 43*7c478bd9Sstevel@tonic-gate #include <ctype.h> 44*7c478bd9Sstevel@tonic-gate #include "rpc_parse.h" 45*7c478bd9Sstevel@tonic-gate #include "rpc_util.h" 46*7c478bd9Sstevel@tonic-gate 47*7c478bd9Sstevel@tonic-gate void storexdrfuncdecl(); 48*7c478bd9Sstevel@tonic-gate 49*7c478bd9Sstevel@tonic-gate static char RESULT[] = "clnt_res"; 50*7c478bd9Sstevel@tonic-gate 51*7c478bd9Sstevel@tonic-gate static enum rpc_gvc { 52*7c478bd9Sstevel@tonic-gate PROGRAM, 53*7c478bd9Sstevel@tonic-gate VERSION, 54*7c478bd9Sstevel@tonic-gate PROCEDURE 55*7c478bd9Sstevel@tonic-gate }; 56*7c478bd9Sstevel@tonic-gate 57*7c478bd9Sstevel@tonic-gate /* 58*7c478bd9Sstevel@tonic-gate * Print the C-version of an xdr definition 59*7c478bd9Sstevel@tonic-gate */ 60*7c478bd9Sstevel@tonic-gate void 61*7c478bd9Sstevel@tonic-gate print_datadef(def) 62*7c478bd9Sstevel@tonic-gate definition *def; 63*7c478bd9Sstevel@tonic-gate { 64*7c478bd9Sstevel@tonic-gate 65*7c478bd9Sstevel@tonic-gate if (def->def_kind == DEF_PROGRAM) /* handle data only */ 66*7c478bd9Sstevel@tonic-gate return; 67*7c478bd9Sstevel@tonic-gate 68*7c478bd9Sstevel@tonic-gate if (def->def_kind != DEF_CONST) { 69*7c478bd9Sstevel@tonic-gate f_print(fout, "\n"); 70*7c478bd9Sstevel@tonic-gate } 71*7c478bd9Sstevel@tonic-gate switch (def->def_kind) { 72*7c478bd9Sstevel@tonic-gate case DEF_STRUCT: 73*7c478bd9Sstevel@tonic-gate pstructdef(def); 74*7c478bd9Sstevel@tonic-gate break; 75*7c478bd9Sstevel@tonic-gate case DEF_UNION: 76*7c478bd9Sstevel@tonic-gate puniondef(def); 77*7c478bd9Sstevel@tonic-gate break; 78*7c478bd9Sstevel@tonic-gate case DEF_ENUM: 79*7c478bd9Sstevel@tonic-gate penumdef(def); 80*7c478bd9Sstevel@tonic-gate break; 81*7c478bd9Sstevel@tonic-gate case DEF_TYPEDEF: 82*7c478bd9Sstevel@tonic-gate ptypedef(def); 83*7c478bd9Sstevel@tonic-gate break; 84*7c478bd9Sstevel@tonic-gate case DEF_PROGRAM: 85*7c478bd9Sstevel@tonic-gate pprogramdef(def); 86*7c478bd9Sstevel@tonic-gate break; 87*7c478bd9Sstevel@tonic-gate case DEF_CONST: 88*7c478bd9Sstevel@tonic-gate pconstdef(def); 89*7c478bd9Sstevel@tonic-gate break; 90*7c478bd9Sstevel@tonic-gate } 91*7c478bd9Sstevel@tonic-gate if (def->def_kind != DEF_PROGRAM && def->def_kind != DEF_CONST) { 92*7c478bd9Sstevel@tonic-gate storexdrfuncdecl(def->def_name, def->def_kind != DEF_TYPEDEF || 93*7c478bd9Sstevel@tonic-gate !isvectordef(def->def.ty.old_type, def->def.ty.rel)); 94*7c478bd9Sstevel@tonic-gate } 95*7c478bd9Sstevel@tonic-gate } 96*7c478bd9Sstevel@tonic-gate 97*7c478bd9Sstevel@tonic-gate 98*7c478bd9Sstevel@tonic-gate void 99*7c478bd9Sstevel@tonic-gate print_funcdef(definition *def) 100*7c478bd9Sstevel@tonic-gate { 101*7c478bd9Sstevel@tonic-gate switch (def->def_kind) { 102*7c478bd9Sstevel@tonic-gate case DEF_PROGRAM: 103*7c478bd9Sstevel@tonic-gate f_print(fout, "\n"); 104*7c478bd9Sstevel@tonic-gate pprogramdef(def); 105*7c478bd9Sstevel@tonic-gate break; 106*7c478bd9Sstevel@tonic-gate } 107*7c478bd9Sstevel@tonic-gate } 108*7c478bd9Sstevel@tonic-gate 109*7c478bd9Sstevel@tonic-gate /* 110*7c478bd9Sstevel@tonic-gate * store away enough information to allow the XDR functions to be spat 111*7c478bd9Sstevel@tonic-gate * out at the end of the file 112*7c478bd9Sstevel@tonic-gate */ 113*7c478bd9Sstevel@tonic-gate void 114*7c478bd9Sstevel@tonic-gate storexdrfuncdecl(char *name, int pointerp) 115*7c478bd9Sstevel@tonic-gate { 116*7c478bd9Sstevel@tonic-gate xdrfunc *xdrptr; 117*7c478bd9Sstevel@tonic-gate 118*7c478bd9Sstevel@tonic-gate xdrptr = (xdrfunc *) malloc(sizeof (struct xdrfunc)); 119*7c478bd9Sstevel@tonic-gate 120*7c478bd9Sstevel@tonic-gate xdrptr->name = name; 121*7c478bd9Sstevel@tonic-gate xdrptr->pointerp = pointerp; 122*7c478bd9Sstevel@tonic-gate xdrptr->next = NULL; 123*7c478bd9Sstevel@tonic-gate 124*7c478bd9Sstevel@tonic-gate if (xdrfunc_tail == NULL) { 125*7c478bd9Sstevel@tonic-gate xdrfunc_head = xdrptr; 126*7c478bd9Sstevel@tonic-gate xdrfunc_tail = xdrptr; 127*7c478bd9Sstevel@tonic-gate } else { 128*7c478bd9Sstevel@tonic-gate xdrfunc_tail->next = xdrptr; 129*7c478bd9Sstevel@tonic-gate xdrfunc_tail = xdrptr; 130*7c478bd9Sstevel@tonic-gate } 131*7c478bd9Sstevel@tonic-gate 132*7c478bd9Sstevel@tonic-gate 133*7c478bd9Sstevel@tonic-gate } 134*7c478bd9Sstevel@tonic-gate 135*7c478bd9Sstevel@tonic-gate void 136*7c478bd9Sstevel@tonic-gate print_xdr_func_def(char *name, int pointerp, int i) 137*7c478bd9Sstevel@tonic-gate { 138*7c478bd9Sstevel@tonic-gate if (i == 2) 139*7c478bd9Sstevel@tonic-gate f_print(fout, "extern bool_t xdr_%s();\n", name); 140*7c478bd9Sstevel@tonic-gate else 141*7c478bd9Sstevel@tonic-gate f_print(fout, "extern bool_t xdr_%s(XDR *, %s%s);\n", name, 142*7c478bd9Sstevel@tonic-gate name, pointerp ? "*" : ""); 143*7c478bd9Sstevel@tonic-gate } 144*7c478bd9Sstevel@tonic-gate 145*7c478bd9Sstevel@tonic-gate 146*7c478bd9Sstevel@tonic-gate static 147*7c478bd9Sstevel@tonic-gate pconstdef(definition *def) 148*7c478bd9Sstevel@tonic-gate { 149*7c478bd9Sstevel@tonic-gate pdefine(def->def_name, def->def.co); 150*7c478bd9Sstevel@tonic-gate } 151*7c478bd9Sstevel@tonic-gate 152*7c478bd9Sstevel@tonic-gate /* 153*7c478bd9Sstevel@tonic-gate * print out the definitions for the arguments of functions in the 154*7c478bd9Sstevel@tonic-gate * header file 155*7c478bd9Sstevel@tonic-gate */ 156*7c478bd9Sstevel@tonic-gate static 157*7c478bd9Sstevel@tonic-gate pargdef(definition *def) 158*7c478bd9Sstevel@tonic-gate { 159*7c478bd9Sstevel@tonic-gate decl_list *l; 160*7c478bd9Sstevel@tonic-gate version_list *vers; 161*7c478bd9Sstevel@tonic-gate char *name; 162*7c478bd9Sstevel@tonic-gate proc_list *plist; 163*7c478bd9Sstevel@tonic-gate 164*7c478bd9Sstevel@tonic-gate for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) { 165*7c478bd9Sstevel@tonic-gate for (plist = vers->procs; plist != NULL; 166*7c478bd9Sstevel@tonic-gate plist = plist->next) { 167*7c478bd9Sstevel@tonic-gate 168*7c478bd9Sstevel@tonic-gate if (!newstyle || plist->arg_num < 2) { 169*7c478bd9Sstevel@tonic-gate continue; /* old style or single args */ 170*7c478bd9Sstevel@tonic-gate } 171*7c478bd9Sstevel@tonic-gate name = plist->args.argname; 172*7c478bd9Sstevel@tonic-gate f_print(fout, "struct %s {\n", name); 173*7c478bd9Sstevel@tonic-gate for (l = plist->args.decls; 174*7c478bd9Sstevel@tonic-gate l != NULL; l = l->next) { 175*7c478bd9Sstevel@tonic-gate pdeclaration(name, &l->decl, 1, ";\n"); 176*7c478bd9Sstevel@tonic-gate } 177*7c478bd9Sstevel@tonic-gate f_print(fout, "};\n"); 178*7c478bd9Sstevel@tonic-gate f_print(fout, "typedef struct %s %s;\n", 179*7c478bd9Sstevel@tonic-gate name, name); 180*7c478bd9Sstevel@tonic-gate storexdrfuncdecl(name, 1); 181*7c478bd9Sstevel@tonic-gate f_print(fout, "\n"); 182*7c478bd9Sstevel@tonic-gate } 183*7c478bd9Sstevel@tonic-gate } 184*7c478bd9Sstevel@tonic-gate } 185*7c478bd9Sstevel@tonic-gate 186*7c478bd9Sstevel@tonic-gate 187*7c478bd9Sstevel@tonic-gate static 188*7c478bd9Sstevel@tonic-gate pstructdef(def) 189*7c478bd9Sstevel@tonic-gate definition *def; 190*7c478bd9Sstevel@tonic-gate { 191*7c478bd9Sstevel@tonic-gate decl_list *l; 192*7c478bd9Sstevel@tonic-gate char *name = def->def_name; 193*7c478bd9Sstevel@tonic-gate 194*7c478bd9Sstevel@tonic-gate f_print(fout, "struct %s {\n", name); 195*7c478bd9Sstevel@tonic-gate for (l = def->def.st.decls; l != NULL; l = l->next) { 196*7c478bd9Sstevel@tonic-gate pdeclaration(name, &l->decl, 1, ";\n"); 197*7c478bd9Sstevel@tonic-gate } 198*7c478bd9Sstevel@tonic-gate f_print(fout, "};\n"); 199*7c478bd9Sstevel@tonic-gate f_print(fout, "typedef struct %s %s;\n", name, name); 200*7c478bd9Sstevel@tonic-gate } 201*7c478bd9Sstevel@tonic-gate 202*7c478bd9Sstevel@tonic-gate static 203*7c478bd9Sstevel@tonic-gate puniondef(def) 204*7c478bd9Sstevel@tonic-gate definition *def; 205*7c478bd9Sstevel@tonic-gate { 206*7c478bd9Sstevel@tonic-gate case_list *l; 207*7c478bd9Sstevel@tonic-gate char *name = def->def_name; 208*7c478bd9Sstevel@tonic-gate declaration *decl; 209*7c478bd9Sstevel@tonic-gate 210*7c478bd9Sstevel@tonic-gate f_print(fout, "struct %s {\n", name); 211*7c478bd9Sstevel@tonic-gate decl = &def->def.un.enum_decl; 212*7c478bd9Sstevel@tonic-gate if (streq(decl->type, "bool")) { 213*7c478bd9Sstevel@tonic-gate f_print(fout, "\tbool_t %s;\n", decl->name); 214*7c478bd9Sstevel@tonic-gate } else { 215*7c478bd9Sstevel@tonic-gate f_print(fout, "\t%s %s;\n", decl->type, decl->name); 216*7c478bd9Sstevel@tonic-gate } 217*7c478bd9Sstevel@tonic-gate f_print(fout, "\tunion {\n"); 218*7c478bd9Sstevel@tonic-gate for (l = def->def.un.cases; l != NULL; l = l->next) { 219*7c478bd9Sstevel@tonic-gate if (l->contflag == 0) 220*7c478bd9Sstevel@tonic-gate pdeclaration(name, &l->case_decl, 2, ";\n"); 221*7c478bd9Sstevel@tonic-gate } 222*7c478bd9Sstevel@tonic-gate decl = def->def.un.default_decl; 223*7c478bd9Sstevel@tonic-gate if (decl && !streq(decl->type, "void")) { 224*7c478bd9Sstevel@tonic-gate pdeclaration(name, decl, 2, ";\n"); 225*7c478bd9Sstevel@tonic-gate } 226*7c478bd9Sstevel@tonic-gate f_print(fout, "\t} %s_u;\n", name); 227*7c478bd9Sstevel@tonic-gate f_print(fout, "};\n"); 228*7c478bd9Sstevel@tonic-gate f_print(fout, "typedef struct %s %s;\n", name, name); 229*7c478bd9Sstevel@tonic-gate } 230*7c478bd9Sstevel@tonic-gate 231*7c478bd9Sstevel@tonic-gate static 232*7c478bd9Sstevel@tonic-gate pdefine(name, num) 233*7c478bd9Sstevel@tonic-gate char *name; 234*7c478bd9Sstevel@tonic-gate char *num; 235*7c478bd9Sstevel@tonic-gate { 236*7c478bd9Sstevel@tonic-gate f_print(fout, "#define\t%s %s\n", name, num); 237*7c478bd9Sstevel@tonic-gate } 238*7c478bd9Sstevel@tonic-gate 239*7c478bd9Sstevel@tonic-gate static 240*7c478bd9Sstevel@tonic-gate puldefine(char *name, char *num, enum rpc_gvc which) 241*7c478bd9Sstevel@tonic-gate { 242*7c478bd9Sstevel@tonic-gate switch (which) { 243*7c478bd9Sstevel@tonic-gate case PROGRAM: 244*7c478bd9Sstevel@tonic-gate case VERSION: 245*7c478bd9Sstevel@tonic-gate case PROCEDURE: 246*7c478bd9Sstevel@tonic-gate f_print(fout, "#define\t%s\t%s\n", name, num); 247*7c478bd9Sstevel@tonic-gate break; 248*7c478bd9Sstevel@tonic-gate default: 249*7c478bd9Sstevel@tonic-gate break; 250*7c478bd9Sstevel@tonic-gate } 251*7c478bd9Sstevel@tonic-gate } 252*7c478bd9Sstevel@tonic-gate 253*7c478bd9Sstevel@tonic-gate static 254*7c478bd9Sstevel@tonic-gate define_printed(proc_list *stop, version_list *start) 255*7c478bd9Sstevel@tonic-gate { 256*7c478bd9Sstevel@tonic-gate version_list *vers; 257*7c478bd9Sstevel@tonic-gate proc_list *proc; 258*7c478bd9Sstevel@tonic-gate 259*7c478bd9Sstevel@tonic-gate for (vers = start; vers != NULL; vers = vers->next) { 260*7c478bd9Sstevel@tonic-gate for (proc = vers->procs; proc != NULL; proc = proc->next) { 261*7c478bd9Sstevel@tonic-gate if (proc == stop) { 262*7c478bd9Sstevel@tonic-gate return (0); 263*7c478bd9Sstevel@tonic-gate } else if (streq(proc->proc_name, stop->proc_name)) { 264*7c478bd9Sstevel@tonic-gate return (1); 265*7c478bd9Sstevel@tonic-gate } 266*7c478bd9Sstevel@tonic-gate } 267*7c478bd9Sstevel@tonic-gate } 268*7c478bd9Sstevel@tonic-gate abort(); 269*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 270*7c478bd9Sstevel@tonic-gate } 271*7c478bd9Sstevel@tonic-gate 272*7c478bd9Sstevel@tonic-gate static 273*7c478bd9Sstevel@tonic-gate pfreeprocdef(char * name, char *vers, int mode) 274*7c478bd9Sstevel@tonic-gate { 275*7c478bd9Sstevel@tonic-gate f_print(fout, "extern int "); 276*7c478bd9Sstevel@tonic-gate pvname(name, vers); 277*7c478bd9Sstevel@tonic-gate if (mode == 1) 278*7c478bd9Sstevel@tonic-gate f_print(fout, "_freeresult(SVCXPRT *, xdrproc_t, caddr_t);\n"); 279*7c478bd9Sstevel@tonic-gate else 280*7c478bd9Sstevel@tonic-gate f_print(fout, "_freeresult();\n"); 281*7c478bd9Sstevel@tonic-gate 282*7c478bd9Sstevel@tonic-gate 283*7c478bd9Sstevel@tonic-gate } 284*7c478bd9Sstevel@tonic-gate 285*7c478bd9Sstevel@tonic-gate static 286*7c478bd9Sstevel@tonic-gate pprogramdef(def) 287*7c478bd9Sstevel@tonic-gate definition *def; 288*7c478bd9Sstevel@tonic-gate { 289*7c478bd9Sstevel@tonic-gate version_list *vers; 290*7c478bd9Sstevel@tonic-gate proc_list *proc; 291*7c478bd9Sstevel@tonic-gate int i; 292*7c478bd9Sstevel@tonic-gate char *ext; 293*7c478bd9Sstevel@tonic-gate 294*7c478bd9Sstevel@tonic-gate pargdef(def); 295*7c478bd9Sstevel@tonic-gate 296*7c478bd9Sstevel@tonic-gate puldefine(def->def_name, def->def.pr.prog_num, PROGRAM); 297*7c478bd9Sstevel@tonic-gate for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) { 298*7c478bd9Sstevel@tonic-gate if (tblflag) { 299*7c478bd9Sstevel@tonic-gate f_print(fout, 300*7c478bd9Sstevel@tonic-gate "extern struct rpcgen_table %s_%s_table[];\n", 301*7c478bd9Sstevel@tonic-gate locase(def->def_name), vers->vers_num); 302*7c478bd9Sstevel@tonic-gate f_print(fout, 303*7c478bd9Sstevel@tonic-gate "extern %s_%s_nproc;\n", 304*7c478bd9Sstevel@tonic-gate locase(def->def_name), vers->vers_num); 305*7c478bd9Sstevel@tonic-gate } 306*7c478bd9Sstevel@tonic-gate puldefine(vers->vers_name, vers->vers_num, VERSION); 307*7c478bd9Sstevel@tonic-gate 308*7c478bd9Sstevel@tonic-gate /* 309*7c478bd9Sstevel@tonic-gate * Print out 2 definitions, one for ANSI-C, another for 310*7c478bd9Sstevel@tonic-gate * old K & R C 311*7c478bd9Sstevel@tonic-gate */ 312*7c478bd9Sstevel@tonic-gate 313*7c478bd9Sstevel@tonic-gate if (!Cflag) { 314*7c478bd9Sstevel@tonic-gate ext = "extern "; 315*7c478bd9Sstevel@tonic-gate for (proc = vers->procs; proc != NULL; 316*7c478bd9Sstevel@tonic-gate proc = proc->next) { 317*7c478bd9Sstevel@tonic-gate if (!define_printed(proc, 318*7c478bd9Sstevel@tonic-gate def->def.pr.versions)) { 319*7c478bd9Sstevel@tonic-gate puldefine(proc->proc_name, 320*7c478bd9Sstevel@tonic-gate proc->proc_num, PROCEDURE); 321*7c478bd9Sstevel@tonic-gate } 322*7c478bd9Sstevel@tonic-gate f_print(fout, "%s", ext); 323*7c478bd9Sstevel@tonic-gate pprocdef(proc, vers, NULL, 0, 2); 324*7c478bd9Sstevel@tonic-gate 325*7c478bd9Sstevel@tonic-gate if (mtflag) { 326*7c478bd9Sstevel@tonic-gate f_print(fout, "%s", ext); 327*7c478bd9Sstevel@tonic-gate pprocdef(proc, vers, NULL, 1, 2); 328*7c478bd9Sstevel@tonic-gate } 329*7c478bd9Sstevel@tonic-gate } 330*7c478bd9Sstevel@tonic-gate pfreeprocdef(def->def_name, vers->vers_num, 2); 331*7c478bd9Sstevel@tonic-gate } else { 332*7c478bd9Sstevel@tonic-gate for (i = 1; i < 3; i++) { 333*7c478bd9Sstevel@tonic-gate if (i == 1) { 334*7c478bd9Sstevel@tonic-gate f_print(fout, "\n#if defined(__STDC__)" 335*7c478bd9Sstevel@tonic-gate " || defined(__cplusplus)\n"); 336*7c478bd9Sstevel@tonic-gate ext = "extern "; 337*7c478bd9Sstevel@tonic-gate } else { 338*7c478bd9Sstevel@tonic-gate f_print(fout, "\n#else /* K&R C */\n"); 339*7c478bd9Sstevel@tonic-gate ext = "extern "; 340*7c478bd9Sstevel@tonic-gate } 341*7c478bd9Sstevel@tonic-gate 342*7c478bd9Sstevel@tonic-gate for (proc = vers->procs; proc != NULL; 343*7c478bd9Sstevel@tonic-gate proc = proc->next) { 344*7c478bd9Sstevel@tonic-gate if (!define_printed(proc, 345*7c478bd9Sstevel@tonic-gate def->def.pr.versions)) { 346*7c478bd9Sstevel@tonic-gate puldefine(proc->proc_name, 347*7c478bd9Sstevel@tonic-gate proc->proc_num, PROCEDURE); 348*7c478bd9Sstevel@tonic-gate } 349*7c478bd9Sstevel@tonic-gate f_print(fout, "%s", ext); 350*7c478bd9Sstevel@tonic-gate pprocdef(proc, vers, "CLIENT *", 0, i); 351*7c478bd9Sstevel@tonic-gate f_print(fout, "%s", ext); 352*7c478bd9Sstevel@tonic-gate pprocdef(proc, vers, 353*7c478bd9Sstevel@tonic-gate "struct svc_req *", 1, i); 354*7c478bd9Sstevel@tonic-gate } 355*7c478bd9Sstevel@tonic-gate pfreeprocdef(def->def_name, vers->vers_num, i); 356*7c478bd9Sstevel@tonic-gate } 357*7c478bd9Sstevel@tonic-gate f_print(fout, "#endif /* K&R C */\n"); 358*7c478bd9Sstevel@tonic-gate } 359*7c478bd9Sstevel@tonic-gate } 360*7c478bd9Sstevel@tonic-gate } 361*7c478bd9Sstevel@tonic-gate 362*7c478bd9Sstevel@tonic-gate pprocdef(proc, vp, addargtype, server_p, mode) 363*7c478bd9Sstevel@tonic-gate proc_list *proc; 364*7c478bd9Sstevel@tonic-gate version_list *vp; 365*7c478bd9Sstevel@tonic-gate char *addargtype; 366*7c478bd9Sstevel@tonic-gate int server_p; 367*7c478bd9Sstevel@tonic-gate int mode; 368*7c478bd9Sstevel@tonic-gate { 369*7c478bd9Sstevel@tonic-gate if (mtflag) { 370*7c478bd9Sstevel@tonic-gate /* Print MT style stubs */ 371*7c478bd9Sstevel@tonic-gate if (server_p) 372*7c478bd9Sstevel@tonic-gate f_print(fout, "bool_t "); 373*7c478bd9Sstevel@tonic-gate else 374*7c478bd9Sstevel@tonic-gate f_print(fout, "enum clnt_stat "); 375*7c478bd9Sstevel@tonic-gate } else { 376*7c478bd9Sstevel@tonic-gate ptype(proc->res_prefix, proc->res_type, 1); 377*7c478bd9Sstevel@tonic-gate f_print(fout, "* "); 378*7c478bd9Sstevel@tonic-gate } 379*7c478bd9Sstevel@tonic-gate if (server_p) 380*7c478bd9Sstevel@tonic-gate pvname_svc(proc->proc_name, vp->vers_num); 381*7c478bd9Sstevel@tonic-gate else 382*7c478bd9Sstevel@tonic-gate pvname(proc->proc_name, vp->vers_num); 383*7c478bd9Sstevel@tonic-gate 384*7c478bd9Sstevel@tonic-gate /* 385*7c478bd9Sstevel@tonic-gate * mode 1 = ANSI-C, mode 2 = K&R C 386*7c478bd9Sstevel@tonic-gate */ 387*7c478bd9Sstevel@tonic-gate if (mode == 1) 388*7c478bd9Sstevel@tonic-gate parglist(proc, addargtype, server_p); 389*7c478bd9Sstevel@tonic-gate else 390*7c478bd9Sstevel@tonic-gate f_print(fout, "();\n"); 391*7c478bd9Sstevel@tonic-gate 392*7c478bd9Sstevel@tonic-gate 393*7c478bd9Sstevel@tonic-gate 394*7c478bd9Sstevel@tonic-gate } 395*7c478bd9Sstevel@tonic-gate 396*7c478bd9Sstevel@tonic-gate 397*7c478bd9Sstevel@tonic-gate 398*7c478bd9Sstevel@tonic-gate /* print out argument list of procedure */ 399*7c478bd9Sstevel@tonic-gate static 400*7c478bd9Sstevel@tonic-gate parglist(proc, addargtype, server_p) 401*7c478bd9Sstevel@tonic-gate proc_list *proc; 402*7c478bd9Sstevel@tonic-gate char *addargtype; 403*7c478bd9Sstevel@tonic-gate int server_p; 404*7c478bd9Sstevel@tonic-gate { 405*7c478bd9Sstevel@tonic-gate decl_list *dl; 406*7c478bd9Sstevel@tonic-gate int oneway = streq(proc->res_type, "oneway"); 407*7c478bd9Sstevel@tonic-gate 408*7c478bd9Sstevel@tonic-gate f_print(fout, "("); 409*7c478bd9Sstevel@tonic-gate if (proc->arg_num < 2 && newstyle && 410*7c478bd9Sstevel@tonic-gate streq(proc->args.decls->decl.type, "void")) { 411*7c478bd9Sstevel@tonic-gate /* 0 argument in new style: do nothing */ 412*7c478bd9Sstevel@tonic-gate } else { 413*7c478bd9Sstevel@tonic-gate for (dl = proc->args.decls; dl != NULL; dl = dl->next) { 414*7c478bd9Sstevel@tonic-gate ptype(dl->decl.prefix, dl->decl.type, 1); 415*7c478bd9Sstevel@tonic-gate if (!newstyle || (dl->decl.rel == REL_POINTER)) 416*7c478bd9Sstevel@tonic-gate f_print(fout, "*"); 417*7c478bd9Sstevel@tonic-gate /* old style passes by reference */ 418*7c478bd9Sstevel@tonic-gate f_print(fout, ", "); 419*7c478bd9Sstevel@tonic-gate } 420*7c478bd9Sstevel@tonic-gate } 421*7c478bd9Sstevel@tonic-gate 422*7c478bd9Sstevel@tonic-gate if (mtflag && !oneway) { 423*7c478bd9Sstevel@tonic-gate ptype(proc->res_prefix, proc->res_type, 1); 424*7c478bd9Sstevel@tonic-gate f_print(fout, "*, "); 425*7c478bd9Sstevel@tonic-gate } 426*7c478bd9Sstevel@tonic-gate 427*7c478bd9Sstevel@tonic-gate f_print(fout, "%s);\n", addargtype); 428*7c478bd9Sstevel@tonic-gate 429*7c478bd9Sstevel@tonic-gate } 430*7c478bd9Sstevel@tonic-gate 431*7c478bd9Sstevel@tonic-gate static 432*7c478bd9Sstevel@tonic-gate penumdef(def) 433*7c478bd9Sstevel@tonic-gate definition *def; 434*7c478bd9Sstevel@tonic-gate { 435*7c478bd9Sstevel@tonic-gate char *name = def->def_name; 436*7c478bd9Sstevel@tonic-gate enumval_list *l; 437*7c478bd9Sstevel@tonic-gate char *last = NULL; 438*7c478bd9Sstevel@tonic-gate int count = 0; 439*7c478bd9Sstevel@tonic-gate 440*7c478bd9Sstevel@tonic-gate f_print(fout, "enum %s {\n", name); 441*7c478bd9Sstevel@tonic-gate for (l = def->def.en.vals; l != NULL; l = l->next) { 442*7c478bd9Sstevel@tonic-gate f_print(fout, "\t%s", l->name); 443*7c478bd9Sstevel@tonic-gate if (l->assignment) { 444*7c478bd9Sstevel@tonic-gate f_print(fout, " = %s", l->assignment); 445*7c478bd9Sstevel@tonic-gate last = l->assignment; 446*7c478bd9Sstevel@tonic-gate count = 1; 447*7c478bd9Sstevel@tonic-gate } else { 448*7c478bd9Sstevel@tonic-gate if (last == NULL) { 449*7c478bd9Sstevel@tonic-gate f_print(fout, " = %d", count++); 450*7c478bd9Sstevel@tonic-gate } else { 451*7c478bd9Sstevel@tonic-gate f_print(fout, " = %s + %d", last, count++); 452*7c478bd9Sstevel@tonic-gate } 453*7c478bd9Sstevel@tonic-gate } 454*7c478bd9Sstevel@tonic-gate if (l->next) 455*7c478bd9Sstevel@tonic-gate f_print(fout, ",\n"); 456*7c478bd9Sstevel@tonic-gate else 457*7c478bd9Sstevel@tonic-gate f_print(fout, "\n"); 458*7c478bd9Sstevel@tonic-gate } 459*7c478bd9Sstevel@tonic-gate f_print(fout, "};\n"); 460*7c478bd9Sstevel@tonic-gate f_print(fout, "typedef enum %s %s;\n", name, name); 461*7c478bd9Sstevel@tonic-gate } 462*7c478bd9Sstevel@tonic-gate 463*7c478bd9Sstevel@tonic-gate static 464*7c478bd9Sstevel@tonic-gate ptypedef(def) 465*7c478bd9Sstevel@tonic-gate definition *def; 466*7c478bd9Sstevel@tonic-gate { 467*7c478bd9Sstevel@tonic-gate char *name = def->def_name; 468*7c478bd9Sstevel@tonic-gate char *old = def->def.ty.old_type; 469*7c478bd9Sstevel@tonic-gate char prefix[8]; /* enough to contain "struct ", including NUL */ 470*7c478bd9Sstevel@tonic-gate relation rel = def->def.ty.rel; 471*7c478bd9Sstevel@tonic-gate 472*7c478bd9Sstevel@tonic-gate 473*7c478bd9Sstevel@tonic-gate if (!streq(name, old)) { 474*7c478bd9Sstevel@tonic-gate if (streq(old, "string")) { 475*7c478bd9Sstevel@tonic-gate old = "char"; 476*7c478bd9Sstevel@tonic-gate rel = REL_POINTER; 477*7c478bd9Sstevel@tonic-gate } else if (streq(old, "opaque")) { 478*7c478bd9Sstevel@tonic-gate old = "char"; 479*7c478bd9Sstevel@tonic-gate } else if (streq(old, "bool")) { 480*7c478bd9Sstevel@tonic-gate old = "bool_t"; 481*7c478bd9Sstevel@tonic-gate } 482*7c478bd9Sstevel@tonic-gate if (undefined2(old, name) && def->def.ty.old_prefix) { 483*7c478bd9Sstevel@tonic-gate s_print(prefix, "%s ", def->def.ty.old_prefix); 484*7c478bd9Sstevel@tonic-gate } else { 485*7c478bd9Sstevel@tonic-gate prefix[0] = 0; 486*7c478bd9Sstevel@tonic-gate } 487*7c478bd9Sstevel@tonic-gate f_print(fout, "typedef "); 488*7c478bd9Sstevel@tonic-gate switch (rel) { 489*7c478bd9Sstevel@tonic-gate case REL_ARRAY: 490*7c478bd9Sstevel@tonic-gate f_print(fout, "struct {\n"); 491*7c478bd9Sstevel@tonic-gate f_print(fout, "\tu_int %s_len;\n", name); 492*7c478bd9Sstevel@tonic-gate f_print(fout, "\t%s%s *%s_val;\n", prefix, old, name); 493*7c478bd9Sstevel@tonic-gate f_print(fout, "} %s", name); 494*7c478bd9Sstevel@tonic-gate break; 495*7c478bd9Sstevel@tonic-gate case REL_POINTER: 496*7c478bd9Sstevel@tonic-gate f_print(fout, "%s%s *%s", prefix, old, name); 497*7c478bd9Sstevel@tonic-gate break; 498*7c478bd9Sstevel@tonic-gate case REL_VECTOR: 499*7c478bd9Sstevel@tonic-gate f_print(fout, "%s%s %s[%s]", prefix, old, name, 500*7c478bd9Sstevel@tonic-gate def->def.ty.array_max); 501*7c478bd9Sstevel@tonic-gate break; 502*7c478bd9Sstevel@tonic-gate case REL_ALIAS: 503*7c478bd9Sstevel@tonic-gate f_print(fout, "%s%s %s", prefix, old, name); 504*7c478bd9Sstevel@tonic-gate break; 505*7c478bd9Sstevel@tonic-gate } 506*7c478bd9Sstevel@tonic-gate f_print(fout, ";\n"); 507*7c478bd9Sstevel@tonic-gate } 508*7c478bd9Sstevel@tonic-gate } 509*7c478bd9Sstevel@tonic-gate 510*7c478bd9Sstevel@tonic-gate pdeclaration(name, dec, tab, separator) 511*7c478bd9Sstevel@tonic-gate char *name; 512*7c478bd9Sstevel@tonic-gate declaration *dec; 513*7c478bd9Sstevel@tonic-gate int tab; 514*7c478bd9Sstevel@tonic-gate char *separator; 515*7c478bd9Sstevel@tonic-gate { 516*7c478bd9Sstevel@tonic-gate char buf[8]; /* enough to hold "struct ", include NUL */ 517*7c478bd9Sstevel@tonic-gate char *prefix; 518*7c478bd9Sstevel@tonic-gate char *type; 519*7c478bd9Sstevel@tonic-gate 520*7c478bd9Sstevel@tonic-gate if (streq(dec->type, "void")) { 521*7c478bd9Sstevel@tonic-gate return; 522*7c478bd9Sstevel@tonic-gate } 523*7c478bd9Sstevel@tonic-gate tabify(fout, tab); 524*7c478bd9Sstevel@tonic-gate if (streq(dec->type, name) && !dec->prefix) { 525*7c478bd9Sstevel@tonic-gate f_print(fout, "struct "); 526*7c478bd9Sstevel@tonic-gate } 527*7c478bd9Sstevel@tonic-gate if (streq(dec->type, "string")) { 528*7c478bd9Sstevel@tonic-gate f_print(fout, "char *%s", dec->name); 529*7c478bd9Sstevel@tonic-gate } else { 530*7c478bd9Sstevel@tonic-gate prefix = ""; 531*7c478bd9Sstevel@tonic-gate if (streq(dec->type, "bool")) { 532*7c478bd9Sstevel@tonic-gate type = "bool_t"; 533*7c478bd9Sstevel@tonic-gate } else if (streq(dec->type, "opaque")) { 534*7c478bd9Sstevel@tonic-gate type = "char"; 535*7c478bd9Sstevel@tonic-gate } else { 536*7c478bd9Sstevel@tonic-gate if (dec->prefix) { 537*7c478bd9Sstevel@tonic-gate s_print(buf, "%s ", dec->prefix); 538*7c478bd9Sstevel@tonic-gate prefix = buf; 539*7c478bd9Sstevel@tonic-gate } 540*7c478bd9Sstevel@tonic-gate type = dec->type; 541*7c478bd9Sstevel@tonic-gate } 542*7c478bd9Sstevel@tonic-gate switch (dec->rel) { 543*7c478bd9Sstevel@tonic-gate case REL_ALIAS: 544*7c478bd9Sstevel@tonic-gate f_print(fout, "%s%s %s", prefix, type, dec->name); 545*7c478bd9Sstevel@tonic-gate break; 546*7c478bd9Sstevel@tonic-gate case REL_VECTOR: 547*7c478bd9Sstevel@tonic-gate f_print(fout, "%s%s %s[%s]", prefix, type, dec->name, 548*7c478bd9Sstevel@tonic-gate dec->array_max); 549*7c478bd9Sstevel@tonic-gate break; 550*7c478bd9Sstevel@tonic-gate case REL_POINTER: 551*7c478bd9Sstevel@tonic-gate f_print(fout, "%s%s *%s", prefix, type, dec->name); 552*7c478bd9Sstevel@tonic-gate break; 553*7c478bd9Sstevel@tonic-gate case REL_ARRAY: 554*7c478bd9Sstevel@tonic-gate f_print(fout, "struct {\n"); 555*7c478bd9Sstevel@tonic-gate tabify(fout, tab); 556*7c478bd9Sstevel@tonic-gate f_print(fout, "\tu_int %s_len;\n", dec->name); 557*7c478bd9Sstevel@tonic-gate tabify(fout, tab); 558*7c478bd9Sstevel@tonic-gate f_print(fout, 559*7c478bd9Sstevel@tonic-gate "\t%s%s *%s_val;\n", prefix, type, dec->name); 560*7c478bd9Sstevel@tonic-gate tabify(fout, tab); 561*7c478bd9Sstevel@tonic-gate f_print(fout, "} %s", dec->name); 562*7c478bd9Sstevel@tonic-gate break; 563*7c478bd9Sstevel@tonic-gate } 564*7c478bd9Sstevel@tonic-gate } 565*7c478bd9Sstevel@tonic-gate f_print(fout, separator); 566*7c478bd9Sstevel@tonic-gate } 567*7c478bd9Sstevel@tonic-gate 568*7c478bd9Sstevel@tonic-gate static 569*7c478bd9Sstevel@tonic-gate undefined2(type, stop) 570*7c478bd9Sstevel@tonic-gate char *type; 571*7c478bd9Sstevel@tonic-gate char *stop; 572*7c478bd9Sstevel@tonic-gate { 573*7c478bd9Sstevel@tonic-gate list *l; 574*7c478bd9Sstevel@tonic-gate definition *def; 575*7c478bd9Sstevel@tonic-gate 576*7c478bd9Sstevel@tonic-gate for (l = defined; l != NULL; l = l->next) { 577*7c478bd9Sstevel@tonic-gate def = (definition *) l->val; 578*7c478bd9Sstevel@tonic-gate if (def->def_kind != DEF_PROGRAM) { 579*7c478bd9Sstevel@tonic-gate if (streq(def->def_name, stop)) { 580*7c478bd9Sstevel@tonic-gate return (1); 581*7c478bd9Sstevel@tonic-gate } else if (streq(def->def_name, type)) { 582*7c478bd9Sstevel@tonic-gate return (0); 583*7c478bd9Sstevel@tonic-gate } 584*7c478bd9Sstevel@tonic-gate } 585*7c478bd9Sstevel@tonic-gate } 586*7c478bd9Sstevel@tonic-gate return (1); 587*7c478bd9Sstevel@tonic-gate } 588