14e115012SGarrett Wollman /* 24e115012SGarrett Wollman * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 34e115012SGarrett Wollman * unrestricted use provided that this legend is included on all tape 44e115012SGarrett Wollman * media and as a part of the software program in whole or part. Users 54e115012SGarrett Wollman * may copy or modify Sun RPC without charge, but are not authorized 64e115012SGarrett Wollman * to license or distribute it to anyone else except as part of a product or 74e115012SGarrett Wollman * program developed by the user. 84e115012SGarrett Wollman * 94e115012SGarrett Wollman * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 104e115012SGarrett Wollman * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 114e115012SGarrett Wollman * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 124e115012SGarrett Wollman * 134e115012SGarrett Wollman * Sun RPC is provided with no support and without any obligation on the 144e115012SGarrett Wollman * part of Sun Microsystems, Inc. to assist in its use, correction, 154e115012SGarrett Wollman * modification or enhancement. 164e115012SGarrett Wollman * 174e115012SGarrett Wollman * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 184e115012SGarrett Wollman * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 194e115012SGarrett Wollman * OR ANY PART THEREOF. 204e115012SGarrett Wollman * 214e115012SGarrett Wollman * In no event will Sun Microsystems, Inc. be liable for any lost revenue 224e115012SGarrett Wollman * or profits or other special, indirect and consequential damages, even if 234e115012SGarrett Wollman * Sun has been advised of the possibility of such damages. 244e115012SGarrett Wollman * 254e115012SGarrett Wollman * Sun Microsystems, Inc. 264e115012SGarrett Wollman * 2550 Garcia Avenue 274e115012SGarrett Wollman * Mountain View, California 94043 284e115012SGarrett Wollman */ 29ff49530fSBill Paul 30ff49530fSBill Paul #ident "@(#)rpc_util.c 1.14 93/07/05 SMI" 31ff49530fSBill Paul 324e115012SGarrett Wollman #ifndef lint 330e76f40dSPhilippe Charnier #if 0 34ff49530fSBill Paul static char sccsid[] = "@(#)rpc_util.c 1.11 89/02/22 (C) 1987 SMI"; 354e115012SGarrett Wollman #endif 360e76f40dSPhilippe Charnier static const char rcsid[] = 37c3aac50fSPeter Wemm "$FreeBSD$"; 380e76f40dSPhilippe Charnier #endif 394e115012SGarrett Wollman 404e115012SGarrett Wollman /* 414e115012SGarrett Wollman * rpc_util.c, Utility routines for the RPC protocol compiler 42ff49530fSBill Paul * Copyright (C) 1989, Sun Microsystems, Inc. 434e115012SGarrett Wollman */ 440e76f40dSPhilippe Charnier #include <err.h> 450e76f40dSPhilippe Charnier #include <ctype.h> 464e115012SGarrett Wollman #include <stdio.h> 47526195adSJordan K. Hubbard #include <string.h> 48526195adSJordan K. Hubbard #include <unistd.h> 494e115012SGarrett Wollman #include "rpc_scan.h" 504e115012SGarrett Wollman #include "rpc_parse.h" 514e115012SGarrett Wollman #include "rpc_util.h" 524e115012SGarrett Wollman 53ff49530fSBill Paul #define ARGEXT "argument" 54ff49530fSBill Paul 554e115012SGarrett Wollman char curline[MAXLINESIZE]; /* current read line */ 564e115012SGarrett Wollman char *where = curline; /* current point in line */ 574e115012SGarrett Wollman int linenum = 0; /* current line number */ 584e115012SGarrett Wollman 594e115012SGarrett Wollman char *infilename; /* input filename */ 604e115012SGarrett Wollman 61ff49530fSBill Paul #define NFILES 7 624e115012SGarrett Wollman char *outfiles[NFILES]; /* output file names */ 634e115012SGarrett Wollman int nfiles; 644e115012SGarrett Wollman 654e115012SGarrett Wollman FILE *fout; /* file pointer of current output */ 664e115012SGarrett Wollman FILE *fin; /* file pointer of current input */ 674e115012SGarrett Wollman 684e115012SGarrett Wollman list *defined; /* list of defined things */ 694e115012SGarrett Wollman 70d3cb5dedSWarner Losh static void printwhere( void ); 714e115012SGarrett Wollman 724e115012SGarrett Wollman /* 734e115012SGarrett Wollman * Reinitialize the world 744e115012SGarrett Wollman */ 75526195adSJordan K. Hubbard void 764e115012SGarrett Wollman reinitialize() 774e115012SGarrett Wollman { 78ff49530fSBill Paul memset(curline, 0, MAXLINESIZE); 794e115012SGarrett Wollman where = curline; 804e115012SGarrett Wollman linenum = 0; 814e115012SGarrett Wollman defined = NULL; 824e115012SGarrett Wollman } 834e115012SGarrett Wollman 844e115012SGarrett Wollman /* 854e115012SGarrett Wollman * string equality 864e115012SGarrett Wollman */ 87526195adSJordan K. Hubbard int 884e115012SGarrett Wollman streq(a, b) 894e115012SGarrett Wollman char *a; 904e115012SGarrett Wollman char *b; 914e115012SGarrett Wollman { 924e115012SGarrett Wollman return (strcmp(a, b) == 0); 934e115012SGarrett Wollman } 944e115012SGarrett Wollman 954e115012SGarrett Wollman /* 964e115012SGarrett Wollman * find a value in a list 974e115012SGarrett Wollman */ 98ff49530fSBill Paul definition * 994e115012SGarrett Wollman findval(lst, val, cmp) 1004e115012SGarrett Wollman list *lst; 1014e115012SGarrett Wollman char *val; 1024e115012SGarrett Wollman int (*cmp) (); 1034e115012SGarrett Wollman 1044e115012SGarrett Wollman { 1054e115012SGarrett Wollman for (; lst != NULL; lst = lst->next) { 1064e115012SGarrett Wollman if ((*cmp) (lst->val, val)) { 1074e115012SGarrett Wollman return (lst->val); 1084e115012SGarrett Wollman } 1094e115012SGarrett Wollman } 1104e115012SGarrett Wollman return (NULL); 1114e115012SGarrett Wollman } 1124e115012SGarrett Wollman 1134e115012SGarrett Wollman /* 1144e115012SGarrett Wollman * store a value in a list 1154e115012SGarrett Wollman */ 1164e115012SGarrett Wollman void 1174e115012SGarrett Wollman storeval(lstp, val) 1184e115012SGarrett Wollman list **lstp; 119ff49530fSBill Paul definition *val; 1204e115012SGarrett Wollman { 1214e115012SGarrett Wollman list **l; 1224e115012SGarrett Wollman list *lst; 1234e115012SGarrett Wollman 1244e115012SGarrett Wollman for (l = lstp; *l != NULL; l = (list **) & (*l)->next); 1254e115012SGarrett Wollman lst = ALLOC(list); 1264e115012SGarrett Wollman lst->val = val; 1274e115012SGarrett Wollman lst->next = NULL; 1284e115012SGarrett Wollman *l = lst; 1294e115012SGarrett Wollman } 1304e115012SGarrett Wollman 131526195adSJordan K. Hubbard static int 1324e115012SGarrett Wollman findit(def, type) 1334e115012SGarrett Wollman definition *def; 1344e115012SGarrett Wollman char *type; 1354e115012SGarrett Wollman { 1364e115012SGarrett Wollman return (streq(def->def_name, type)); 1374e115012SGarrett Wollman } 1384e115012SGarrett Wollman 1394e115012SGarrett Wollman static char * 1404e115012SGarrett Wollman fixit(type, orig) 1414e115012SGarrett Wollman char *type; 1424e115012SGarrett Wollman char *orig; 1434e115012SGarrett Wollman { 1444e115012SGarrett Wollman definition *def; 1454e115012SGarrett Wollman 1464e115012SGarrett Wollman def = (definition *) FINDVAL(defined, type, findit); 1474e115012SGarrett Wollman if (def == NULL || def->def_kind != DEF_TYPEDEF) { 1484e115012SGarrett Wollman return (orig); 1494e115012SGarrett Wollman } 1504e115012SGarrett Wollman switch (def->def.ty.rel) { 1514e115012SGarrett Wollman case REL_VECTOR: 152ff49530fSBill Paul if (streq(def->def.ty.old_type, "opaque")) 153ff49530fSBill Paul return ("char"); 154ff49530fSBill Paul else 1554e115012SGarrett Wollman return (def->def.ty.old_type); 156ff49530fSBill Paul 1574e115012SGarrett Wollman case REL_ALIAS: 1584e115012SGarrett Wollman return (fixit(def->def.ty.old_type, orig)); 1594e115012SGarrett Wollman default: 1604e115012SGarrett Wollman return (orig); 1614e115012SGarrett Wollman } 1624e115012SGarrett Wollman } 1634e115012SGarrett Wollman 1644e115012SGarrett Wollman char * 1654e115012SGarrett Wollman fixtype(type) 1664e115012SGarrett Wollman char *type; 1674e115012SGarrett Wollman { 1684e115012SGarrett Wollman return (fixit(type, type)); 1694e115012SGarrett Wollman } 1704e115012SGarrett Wollman 1714e115012SGarrett Wollman char * 1724e115012SGarrett Wollman stringfix(type) 1734e115012SGarrett Wollman char *type; 1744e115012SGarrett Wollman { 1754e115012SGarrett Wollman if (streq(type, "string")) { 1764e115012SGarrett Wollman return ("wrapstring"); 1774e115012SGarrett Wollman } else { 1784e115012SGarrett Wollman return (type); 1794e115012SGarrett Wollman } 1804e115012SGarrett Wollman } 1814e115012SGarrett Wollman 1824e115012SGarrett Wollman void 1834e115012SGarrett Wollman ptype(prefix, type, follow) 1844e115012SGarrett Wollman char *prefix; 1854e115012SGarrett Wollman char *type; 1864e115012SGarrett Wollman int follow; 1874e115012SGarrett Wollman { 1884e115012SGarrett Wollman if (prefix != NULL) { 1894e115012SGarrett Wollman if (streq(prefix, "enum")) { 1904e115012SGarrett Wollman f_print(fout, "enum "); 1914e115012SGarrett Wollman } else { 1924e115012SGarrett Wollman f_print(fout, "struct "); 1934e115012SGarrett Wollman } 1944e115012SGarrett Wollman } 1954e115012SGarrett Wollman if (streq(type, "bool")) { 1964e115012SGarrett Wollman f_print(fout, "bool_t "); 1974e115012SGarrett Wollman } else if (streq(type, "string")) { 1984e115012SGarrett Wollman f_print(fout, "char *"); 1994e115012SGarrett Wollman } else { 2004e115012SGarrett Wollman f_print(fout, "%s ", follow ? fixtype(type) : type); 2014e115012SGarrett Wollman } 2024e115012SGarrett Wollman } 2034e115012SGarrett Wollman 204526195adSJordan K. Hubbard static int 2054e115012SGarrett Wollman typedefed(def, type) 2064e115012SGarrett Wollman definition *def; 2074e115012SGarrett Wollman char *type; 2084e115012SGarrett Wollman { 2094e115012SGarrett Wollman if (def->def_kind != DEF_TYPEDEF || def->def.ty.old_prefix != NULL) { 2104e115012SGarrett Wollman return (0); 2114e115012SGarrett Wollman } else { 2124e115012SGarrett Wollman return (streq(def->def_name, type)); 2134e115012SGarrett Wollman } 2144e115012SGarrett Wollman } 2154e115012SGarrett Wollman 216526195adSJordan K. Hubbard int 2174e115012SGarrett Wollman isvectordef(type, rel) 2184e115012SGarrett Wollman char *type; 2194e115012SGarrett Wollman relation rel; 2204e115012SGarrett Wollman { 2214e115012SGarrett Wollman definition *def; 2224e115012SGarrett Wollman 2234e115012SGarrett Wollman for (;;) { 2244e115012SGarrett Wollman switch (rel) { 2254e115012SGarrett Wollman case REL_VECTOR: 2264e115012SGarrett Wollman return (!streq(type, "string")); 2274e115012SGarrett Wollman case REL_ARRAY: 2284e115012SGarrett Wollman return (0); 2294e115012SGarrett Wollman case REL_POINTER: 2304e115012SGarrett Wollman return (0); 2314e115012SGarrett Wollman case REL_ALIAS: 2324e115012SGarrett Wollman def = (definition *) FINDVAL(defined, type, typedefed); 2334e115012SGarrett Wollman if (def == NULL) { 2344e115012SGarrett Wollman return (0); 2354e115012SGarrett Wollman } 2364e115012SGarrett Wollman type = def->def.ty.old_type; 2374e115012SGarrett Wollman rel = def->def.ty.rel; 2384e115012SGarrett Wollman } 2394e115012SGarrett Wollman } 240526195adSJordan K. Hubbard 241526195adSJordan K. Hubbard return (0); 2424e115012SGarrett Wollman } 2434e115012SGarrett Wollman 244ff49530fSBill Paul char * 2454e115012SGarrett Wollman locase(str) 2464e115012SGarrett Wollman char *str; 2474e115012SGarrett Wollman { 2484e115012SGarrett Wollman char c; 2494e115012SGarrett Wollman static char buf[100]; 2504e115012SGarrett Wollman char *p = buf; 2514e115012SGarrett Wollman 252526195adSJordan K. Hubbard while ( (c = *str++) ) { 2534e115012SGarrett Wollman *p++ = (c >= 'A' && c <= 'Z') ? (c - 'A' + 'a') : c; 2544e115012SGarrett Wollman } 2554e115012SGarrett Wollman *p = 0; 2564e115012SGarrett Wollman return (buf); 2574e115012SGarrett Wollman } 2584e115012SGarrett Wollman 259ff49530fSBill Paul void 260ff49530fSBill Paul pvname_svc(pname, vnum) 261ff49530fSBill Paul char *pname; 262ff49530fSBill Paul char *vnum; 263ff49530fSBill Paul { 264ff49530fSBill Paul f_print(fout, "%s_%s_svc", locase(pname), vnum); 265ff49530fSBill Paul } 2664e115012SGarrett Wollman 2674e115012SGarrett Wollman void 2684e115012SGarrett Wollman pvname(pname, vnum) 2694e115012SGarrett Wollman char *pname; 2704e115012SGarrett Wollman char *vnum; 2714e115012SGarrett Wollman { 2724e115012SGarrett Wollman f_print(fout, "%s_%s", locase(pname), vnum); 2734e115012SGarrett Wollman } 2744e115012SGarrett Wollman 2754e115012SGarrett Wollman /* 2764e115012SGarrett Wollman * print a useful (?) error message, and then die 2774e115012SGarrett Wollman */ 2784e115012SGarrett Wollman void 2794e115012SGarrett Wollman error(msg) 2804e115012SGarrett Wollman char *msg; 2814e115012SGarrett Wollman { 2824e115012SGarrett Wollman printwhere(); 2830e76f40dSPhilippe Charnier warnx("%s, line %d: %s", infilename, linenum, msg); 2844e115012SGarrett Wollman crash(); 2854e115012SGarrett Wollman } 2864e115012SGarrett Wollman 2874e115012SGarrett Wollman /* 2884e115012SGarrett Wollman * Something went wrong, unlink any files that we may have created and then 2894e115012SGarrett Wollman * die. 2904e115012SGarrett Wollman */ 291526195adSJordan K. Hubbard void 2924e115012SGarrett Wollman crash() 2934e115012SGarrett Wollman { 2944e115012SGarrett Wollman int i; 2954e115012SGarrett Wollman 2964e115012SGarrett Wollman for (i = 0; i < nfiles; i++) { 2974e115012SGarrett Wollman (void) unlink(outfiles[i]); 2984e115012SGarrett Wollman } 2994e115012SGarrett Wollman exit(1); 3004e115012SGarrett Wollman } 3014e115012SGarrett Wollman 3024e115012SGarrett Wollman void 3034e115012SGarrett Wollman record_open(file) 3044e115012SGarrett Wollman char *file; 3054e115012SGarrett Wollman { 3064e115012SGarrett Wollman if (nfiles < NFILES) { 3074e115012SGarrett Wollman outfiles[nfiles++] = file; 3084e115012SGarrett Wollman } else { 3090e76f40dSPhilippe Charnier warnx("too many files"); 3104e115012SGarrett Wollman crash(); 3114e115012SGarrett Wollman } 3124e115012SGarrett Wollman } 3134e115012SGarrett Wollman 3144e115012SGarrett Wollman static char expectbuf[100]; 3154e115012SGarrett Wollman static char *toktostr(); 3164e115012SGarrett Wollman 3174e115012SGarrett Wollman /* 3184e115012SGarrett Wollman * error, token encountered was not the expected one 3194e115012SGarrett Wollman */ 3204e115012SGarrett Wollman void 3214e115012SGarrett Wollman expected1(exp1) 3224e115012SGarrett Wollman tok_kind exp1; 3234e115012SGarrett Wollman { 3244e115012SGarrett Wollman s_print(expectbuf, "expected '%s'", 3254e115012SGarrett Wollman toktostr(exp1)); 3264e115012SGarrett Wollman error(expectbuf); 3274e115012SGarrett Wollman } 3284e115012SGarrett Wollman 3294e115012SGarrett Wollman /* 3304e115012SGarrett Wollman * error, token encountered was not one of two expected ones 3314e115012SGarrett Wollman */ 3324e115012SGarrett Wollman void 3334e115012SGarrett Wollman expected2(exp1, exp2) 3344e115012SGarrett Wollman tok_kind exp1, exp2; 3354e115012SGarrett Wollman { 3364e115012SGarrett Wollman s_print(expectbuf, "expected '%s' or '%s'", 3374e115012SGarrett Wollman toktostr(exp1), 3384e115012SGarrett Wollman toktostr(exp2)); 3394e115012SGarrett Wollman error(expectbuf); 3404e115012SGarrett Wollman } 3414e115012SGarrett Wollman 3424e115012SGarrett Wollman /* 3434e115012SGarrett Wollman * error, token encountered was not one of 3 expected ones 3444e115012SGarrett Wollman */ 3454e115012SGarrett Wollman void 3464e115012SGarrett Wollman expected3(exp1, exp2, exp3) 3474e115012SGarrett Wollman tok_kind exp1, exp2, exp3; 3484e115012SGarrett Wollman { 3494e115012SGarrett Wollman s_print(expectbuf, "expected '%s', '%s' or '%s'", 3504e115012SGarrett Wollman toktostr(exp1), 3514e115012SGarrett Wollman toktostr(exp2), 3524e115012SGarrett Wollman toktostr(exp3)); 3534e115012SGarrett Wollman error(expectbuf); 3544e115012SGarrett Wollman } 3554e115012SGarrett Wollman 3564e115012SGarrett Wollman void 3574e115012SGarrett Wollman tabify(f, tab) 3584e115012SGarrett Wollman FILE *f; 3594e115012SGarrett Wollman int tab; 3604e115012SGarrett Wollman { 3614e115012SGarrett Wollman while (tab--) { 3624e115012SGarrett Wollman (void) fputc('\t', f); 3634e115012SGarrett Wollman } 3644e115012SGarrett Wollman } 3654e115012SGarrett Wollman 3664e115012SGarrett Wollman 3674e115012SGarrett Wollman static token tokstrings[] = { 3684e115012SGarrett Wollman {TOK_IDENT, "identifier"}, 3694e115012SGarrett Wollman {TOK_CONST, "const"}, 3704e115012SGarrett Wollman {TOK_RPAREN, ")"}, 3714e115012SGarrett Wollman {TOK_LPAREN, "("}, 3724e115012SGarrett Wollman {TOK_RBRACE, "}"}, 3734e115012SGarrett Wollman {TOK_LBRACE, "{"}, 3744e115012SGarrett Wollman {TOK_LBRACKET, "["}, 3754e115012SGarrett Wollman {TOK_RBRACKET, "]"}, 3764e115012SGarrett Wollman {TOK_STAR, "*"}, 3774e115012SGarrett Wollman {TOK_COMMA, ","}, 3784e115012SGarrett Wollman {TOK_EQUAL, "="}, 3794e115012SGarrett Wollman {TOK_COLON, ":"}, 3804e115012SGarrett Wollman {TOK_SEMICOLON, ";"}, 3814e115012SGarrett Wollman {TOK_UNION, "union"}, 3824e115012SGarrett Wollman {TOK_STRUCT, "struct"}, 3834e115012SGarrett Wollman {TOK_SWITCH, "switch"}, 3844e115012SGarrett Wollman {TOK_CASE, "case"}, 3854e115012SGarrett Wollman {TOK_DEFAULT, "default"}, 3864e115012SGarrett Wollman {TOK_ENUM, "enum"}, 3874e115012SGarrett Wollman {TOK_TYPEDEF, "typedef"}, 3884e115012SGarrett Wollman {TOK_INT, "int"}, 3894e115012SGarrett Wollman {TOK_SHORT, "short"}, 3904e115012SGarrett Wollman {TOK_LONG, "long"}, 3914e115012SGarrett Wollman {TOK_UNSIGNED, "unsigned"}, 3924e115012SGarrett Wollman {TOK_DOUBLE, "double"}, 3934e115012SGarrett Wollman {TOK_FLOAT, "float"}, 3944e115012SGarrett Wollman {TOK_CHAR, "char"}, 3954e115012SGarrett Wollman {TOK_STRING, "string"}, 3964e115012SGarrett Wollman {TOK_OPAQUE, "opaque"}, 3974e115012SGarrett Wollman {TOK_BOOL, "bool"}, 3984e115012SGarrett Wollman {TOK_VOID, "void"}, 3994e115012SGarrett Wollman {TOK_PROGRAM, "program"}, 4004e115012SGarrett Wollman {TOK_VERSION, "version"}, 4014e115012SGarrett Wollman {TOK_EOF, "??????"} 4024e115012SGarrett Wollman }; 4034e115012SGarrett Wollman 4044e115012SGarrett Wollman static char * 4054e115012SGarrett Wollman toktostr(kind) 4064e115012SGarrett Wollman tok_kind kind; 4074e115012SGarrett Wollman { 4084e115012SGarrett Wollman token *sp; 4094e115012SGarrett Wollman 4104e115012SGarrett Wollman for (sp = tokstrings; sp->kind != TOK_EOF && sp->kind != kind; sp++); 4114e115012SGarrett Wollman return (sp->str); 4124e115012SGarrett Wollman } 4134e115012SGarrett Wollman 414526195adSJordan K. Hubbard static void 4154e115012SGarrett Wollman printbuf() 4164e115012SGarrett Wollman { 4174e115012SGarrett Wollman char c; 4184e115012SGarrett Wollman int i; 4194e115012SGarrett Wollman int cnt; 4204e115012SGarrett Wollman 4214e115012SGarrett Wollman # define TABSIZE 4 4224e115012SGarrett Wollman 423526195adSJordan K. Hubbard for (i = 0; (c = curline[i]); i++) { 4244e115012SGarrett Wollman if (c == '\t') { 4254e115012SGarrett Wollman cnt = 8 - (i % TABSIZE); 4264e115012SGarrett Wollman c = ' '; 4274e115012SGarrett Wollman } else { 4284e115012SGarrett Wollman cnt = 1; 4294e115012SGarrett Wollman } 4304e115012SGarrett Wollman while (cnt--) { 4314e115012SGarrett Wollman (void) fputc(c, stderr); 4324e115012SGarrett Wollman } 4334e115012SGarrett Wollman } 4344e115012SGarrett Wollman } 4354e115012SGarrett Wollman 436526195adSJordan K. Hubbard static void 4374e115012SGarrett Wollman printwhere() 4384e115012SGarrett Wollman { 4394e115012SGarrett Wollman int i; 4404e115012SGarrett Wollman char c; 4414e115012SGarrett Wollman int cnt; 4424e115012SGarrett Wollman 4434e115012SGarrett Wollman printbuf(); 4444e115012SGarrett Wollman for (i = 0; i < where - curline; i++) { 4454e115012SGarrett Wollman c = curline[i]; 4464e115012SGarrett Wollman if (c == '\t') { 4474e115012SGarrett Wollman cnt = 8 - (i % TABSIZE); 4484e115012SGarrett Wollman } else { 4494e115012SGarrett Wollman cnt = 1; 4504e115012SGarrett Wollman } 4514e115012SGarrett Wollman while (cnt--) { 4524e115012SGarrett Wollman (void) fputc('^', stderr); 4534e115012SGarrett Wollman } 4544e115012SGarrett Wollman } 4554e115012SGarrett Wollman (void) fputc('\n', stderr); 4564e115012SGarrett Wollman } 457ff49530fSBill Paul 458ff49530fSBill Paul char * 459ff49530fSBill Paul make_argname(pname, vname) 460ff49530fSBill Paul char *pname; 461ff49530fSBill Paul char *vname; 462ff49530fSBill Paul { 463ff49530fSBill Paul char *name; 464ff49530fSBill Paul 465ff49530fSBill Paul name = malloc(strlen(pname) + strlen(vname) + strlen(ARGEXT) + 3); 4660e76f40dSPhilippe Charnier if (!name) 4670e76f40dSPhilippe Charnier errx(1, "failed in malloc"); 468ff49530fSBill Paul sprintf(name, "%s_%s_%s", locase(pname), vname, ARGEXT); 469ff49530fSBill Paul return (name); 470ff49530fSBill Paul } 471ff49530fSBill Paul 472ff49530fSBill Paul bas_type *typ_list_h; 473ff49530fSBill Paul bas_type *typ_list_t; 474ff49530fSBill Paul 475526195adSJordan K. Hubbard void 476ff49530fSBill Paul add_type(len, type) 477ff49530fSBill Paul int len; 478ff49530fSBill Paul char *type; 479ff49530fSBill Paul { 480ff49530fSBill Paul bas_type *ptr; 481ff49530fSBill Paul 4820e76f40dSPhilippe Charnier if ((ptr = (bas_type *) malloc(sizeof (bas_type))) == (bas_type *)NULL) 4830e76f40dSPhilippe Charnier errx(1, "failed in malloc"); 484ff49530fSBill Paul 485ff49530fSBill Paul ptr->name = type; 486ff49530fSBill Paul ptr->length = len; 487ff49530fSBill Paul ptr->next = NULL; 488ff49530fSBill Paul if (typ_list_t == NULL) 489ff49530fSBill Paul { 490ff49530fSBill Paul 491ff49530fSBill Paul typ_list_t = ptr; 492ff49530fSBill Paul typ_list_h = ptr; 493ff49530fSBill Paul } 494ff49530fSBill Paul else 495ff49530fSBill Paul { 496ff49530fSBill Paul typ_list_t->next = ptr; 497ff49530fSBill Paul typ_list_t = ptr; 498ff49530fSBill Paul }; 499ff49530fSBill Paul } 500ff49530fSBill Paul 501ff49530fSBill Paul 502ff49530fSBill Paul bas_type *find_type(type) 503ff49530fSBill Paul char *type; 504ff49530fSBill Paul { 505ff49530fSBill Paul bas_type * ptr; 506ff49530fSBill Paul 507ff49530fSBill Paul ptr = typ_list_h; 508ff49530fSBill Paul while (ptr != NULL) 509ff49530fSBill Paul { 510ff49530fSBill Paul if (strcmp(ptr->name, type) == 0) 511ff49530fSBill Paul return (ptr); 512ff49530fSBill Paul else 513ff49530fSBill Paul ptr = ptr->next; 514ff49530fSBill Paul }; 515ff49530fSBill Paul return (NULL); 516ff49530fSBill Paul } 517