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 33ff49530fSBill Paul static char sccsid[] = "@(#)rpc_util.c 1.11 89/02/22 (C) 1987 SMI"; 344e115012SGarrett Wollman #endif 354e115012SGarrett Wollman 364e115012SGarrett Wollman /* 374e115012SGarrett Wollman * rpc_util.c, Utility routines for the RPC protocol compiler 38ff49530fSBill Paul * Copyright (C) 1989, Sun Microsystems, Inc. 394e115012SGarrett Wollman */ 404e115012SGarrett Wollman #include <stdio.h> 41526195adSJordan K. Hubbard #include <string.h> 42ff49530fSBill Paul #include <ctype.h> 43526195adSJordan K. Hubbard #include <unistd.h> 444e115012SGarrett Wollman #include "rpc_scan.h" 454e115012SGarrett Wollman #include "rpc_parse.h" 464e115012SGarrett Wollman #include "rpc_util.h" 474e115012SGarrett Wollman 48ff49530fSBill Paul #define ARGEXT "argument" 49ff49530fSBill Paul 504e115012SGarrett Wollman char curline[MAXLINESIZE]; /* current read line */ 514e115012SGarrett Wollman char *where = curline; /* current point in line */ 524e115012SGarrett Wollman int linenum = 0; /* current line number */ 534e115012SGarrett Wollman 544e115012SGarrett Wollman char *infilename; /* input filename */ 554e115012SGarrett Wollman 56ff49530fSBill Paul #define NFILES 7 574e115012SGarrett Wollman char *outfiles[NFILES]; /* output file names */ 584e115012SGarrett Wollman int nfiles; 594e115012SGarrett Wollman 604e115012SGarrett Wollman FILE *fout; /* file pointer of current output */ 614e115012SGarrett Wollman FILE *fin; /* file pointer of current input */ 624e115012SGarrett Wollman 634e115012SGarrett Wollman list *defined; /* list of defined things */ 644e115012SGarrett Wollman 65526195adSJordan K. Hubbard static void printwhere __P(( void )); 664e115012SGarrett Wollman 674e115012SGarrett Wollman /* 684e115012SGarrett Wollman * Reinitialize the world 694e115012SGarrett Wollman */ 70526195adSJordan K. Hubbard void 714e115012SGarrett Wollman reinitialize() 724e115012SGarrett Wollman { 73ff49530fSBill Paul memset(curline, 0, MAXLINESIZE); 744e115012SGarrett Wollman where = curline; 754e115012SGarrett Wollman linenum = 0; 764e115012SGarrett Wollman defined = NULL; 774e115012SGarrett Wollman } 784e115012SGarrett Wollman 794e115012SGarrett Wollman /* 804e115012SGarrett Wollman * string equality 814e115012SGarrett Wollman */ 82526195adSJordan K. Hubbard int 834e115012SGarrett Wollman streq(a, b) 844e115012SGarrett Wollman char *a; 854e115012SGarrett Wollman char *b; 864e115012SGarrett Wollman { 874e115012SGarrett Wollman return (strcmp(a, b) == 0); 884e115012SGarrett Wollman } 894e115012SGarrett Wollman 904e115012SGarrett Wollman /* 914e115012SGarrett Wollman * find a value in a list 924e115012SGarrett Wollman */ 93ff49530fSBill Paul definition * 944e115012SGarrett Wollman findval(lst, val, cmp) 954e115012SGarrett Wollman list *lst; 964e115012SGarrett Wollman char *val; 974e115012SGarrett Wollman int (*cmp) (); 984e115012SGarrett Wollman 994e115012SGarrett Wollman { 1004e115012SGarrett Wollman for (; lst != NULL; lst = lst->next) { 1014e115012SGarrett Wollman if ((*cmp) (lst->val, val)) { 1024e115012SGarrett Wollman return (lst->val); 1034e115012SGarrett Wollman } 1044e115012SGarrett Wollman } 1054e115012SGarrett Wollman return (NULL); 1064e115012SGarrett Wollman } 1074e115012SGarrett Wollman 1084e115012SGarrett Wollman /* 1094e115012SGarrett Wollman * store a value in a list 1104e115012SGarrett Wollman */ 1114e115012SGarrett Wollman void 1124e115012SGarrett Wollman storeval(lstp, val) 1134e115012SGarrett Wollman list **lstp; 114ff49530fSBill Paul definition *val; 1154e115012SGarrett Wollman { 1164e115012SGarrett Wollman list **l; 1174e115012SGarrett Wollman list *lst; 1184e115012SGarrett Wollman 1194e115012SGarrett Wollman for (l = lstp; *l != NULL; l = (list **) & (*l)->next); 1204e115012SGarrett Wollman lst = ALLOC(list); 1214e115012SGarrett Wollman lst->val = val; 1224e115012SGarrett Wollman lst->next = NULL; 1234e115012SGarrett Wollman *l = lst; 1244e115012SGarrett Wollman } 1254e115012SGarrett Wollman 126526195adSJordan K. Hubbard static int 1274e115012SGarrett Wollman findit(def, type) 1284e115012SGarrett Wollman definition *def; 1294e115012SGarrett Wollman char *type; 1304e115012SGarrett Wollman { 1314e115012SGarrett Wollman return (streq(def->def_name, type)); 1324e115012SGarrett Wollman } 1334e115012SGarrett Wollman 1344e115012SGarrett Wollman static char * 1354e115012SGarrett Wollman fixit(type, orig) 1364e115012SGarrett Wollman char *type; 1374e115012SGarrett Wollman char *orig; 1384e115012SGarrett Wollman { 1394e115012SGarrett Wollman definition *def; 1404e115012SGarrett Wollman 1414e115012SGarrett Wollman def = (definition *) FINDVAL(defined, type, findit); 1424e115012SGarrett Wollman if (def == NULL || def->def_kind != DEF_TYPEDEF) { 1434e115012SGarrett Wollman return (orig); 1444e115012SGarrett Wollman } 1454e115012SGarrett Wollman switch (def->def.ty.rel) { 1464e115012SGarrett Wollman case REL_VECTOR: 147ff49530fSBill Paul if (streq(def->def.ty.old_type, "opaque")) 148ff49530fSBill Paul return ("char"); 149ff49530fSBill Paul else 1504e115012SGarrett Wollman return (def->def.ty.old_type); 151ff49530fSBill Paul 1524e115012SGarrett Wollman case REL_ALIAS: 1534e115012SGarrett Wollman return (fixit(def->def.ty.old_type, orig)); 1544e115012SGarrett Wollman default: 1554e115012SGarrett Wollman return (orig); 1564e115012SGarrett Wollman } 1574e115012SGarrett Wollman } 1584e115012SGarrett Wollman 1594e115012SGarrett Wollman char * 1604e115012SGarrett Wollman fixtype(type) 1614e115012SGarrett Wollman char *type; 1624e115012SGarrett Wollman { 1634e115012SGarrett Wollman return (fixit(type, type)); 1644e115012SGarrett Wollman } 1654e115012SGarrett Wollman 1664e115012SGarrett Wollman char * 1674e115012SGarrett Wollman stringfix(type) 1684e115012SGarrett Wollman char *type; 1694e115012SGarrett Wollman { 1704e115012SGarrett Wollman if (streq(type, "string")) { 1714e115012SGarrett Wollman return ("wrapstring"); 1724e115012SGarrett Wollman } else { 1734e115012SGarrett Wollman return (type); 1744e115012SGarrett Wollman } 1754e115012SGarrett Wollman } 1764e115012SGarrett Wollman 1774e115012SGarrett Wollman void 1784e115012SGarrett Wollman ptype(prefix, type, follow) 1794e115012SGarrett Wollman char *prefix; 1804e115012SGarrett Wollman char *type; 1814e115012SGarrett Wollman int follow; 1824e115012SGarrett Wollman { 1834e115012SGarrett Wollman if (prefix != NULL) { 1844e115012SGarrett Wollman if (streq(prefix, "enum")) { 1854e115012SGarrett Wollman f_print(fout, "enum "); 1864e115012SGarrett Wollman } else { 1874e115012SGarrett Wollman f_print(fout, "struct "); 1884e115012SGarrett Wollman } 1894e115012SGarrett Wollman } 1904e115012SGarrett Wollman if (streq(type, "bool")) { 1914e115012SGarrett Wollman f_print(fout, "bool_t "); 1924e115012SGarrett Wollman } else if (streq(type, "string")) { 1934e115012SGarrett Wollman f_print(fout, "char *"); 1944e115012SGarrett Wollman } else { 1954e115012SGarrett Wollman f_print(fout, "%s ", follow ? fixtype(type) : type); 1964e115012SGarrett Wollman } 1974e115012SGarrett Wollman } 1984e115012SGarrett Wollman 199526195adSJordan K. Hubbard static int 2004e115012SGarrett Wollman typedefed(def, type) 2014e115012SGarrett Wollman definition *def; 2024e115012SGarrett Wollman char *type; 2034e115012SGarrett Wollman { 2044e115012SGarrett Wollman if (def->def_kind != DEF_TYPEDEF || def->def.ty.old_prefix != NULL) { 2054e115012SGarrett Wollman return (0); 2064e115012SGarrett Wollman } else { 2074e115012SGarrett Wollman return (streq(def->def_name, type)); 2084e115012SGarrett Wollman } 2094e115012SGarrett Wollman } 2104e115012SGarrett Wollman 211526195adSJordan K. Hubbard int 2124e115012SGarrett Wollman isvectordef(type, rel) 2134e115012SGarrett Wollman char *type; 2144e115012SGarrett Wollman relation rel; 2154e115012SGarrett Wollman { 2164e115012SGarrett Wollman definition *def; 2174e115012SGarrett Wollman 2184e115012SGarrett Wollman for (;;) { 2194e115012SGarrett Wollman switch (rel) { 2204e115012SGarrett Wollman case REL_VECTOR: 2214e115012SGarrett Wollman return (!streq(type, "string")); 2224e115012SGarrett Wollman case REL_ARRAY: 2234e115012SGarrett Wollman return (0); 2244e115012SGarrett Wollman case REL_POINTER: 2254e115012SGarrett Wollman return (0); 2264e115012SGarrett Wollman case REL_ALIAS: 2274e115012SGarrett Wollman def = (definition *) FINDVAL(defined, type, typedefed); 2284e115012SGarrett Wollman if (def == NULL) { 2294e115012SGarrett Wollman return (0); 2304e115012SGarrett Wollman } 2314e115012SGarrett Wollman type = def->def.ty.old_type; 2324e115012SGarrett Wollman rel = def->def.ty.rel; 2334e115012SGarrett Wollman } 2344e115012SGarrett Wollman } 235526195adSJordan K. Hubbard 236526195adSJordan K. Hubbard return (0); 2374e115012SGarrett Wollman } 2384e115012SGarrett Wollman 239ff49530fSBill Paul char * 2404e115012SGarrett Wollman locase(str) 2414e115012SGarrett Wollman char *str; 2424e115012SGarrett Wollman { 2434e115012SGarrett Wollman char c; 2444e115012SGarrett Wollman static char buf[100]; 2454e115012SGarrett Wollman char *p = buf; 2464e115012SGarrett Wollman 247526195adSJordan K. Hubbard while ( (c = *str++) ) { 2484e115012SGarrett Wollman *p++ = (c >= 'A' && c <= 'Z') ? (c - 'A' + 'a') : c; 2494e115012SGarrett Wollman } 2504e115012SGarrett Wollman *p = 0; 2514e115012SGarrett Wollman return (buf); 2524e115012SGarrett Wollman } 2534e115012SGarrett Wollman 254ff49530fSBill Paul void 255ff49530fSBill Paul pvname_svc(pname, vnum) 256ff49530fSBill Paul char *pname; 257ff49530fSBill Paul char *vnum; 258ff49530fSBill Paul { 259ff49530fSBill Paul f_print(fout, "%s_%s_svc", locase(pname), vnum); 260ff49530fSBill Paul } 2614e115012SGarrett Wollman 2624e115012SGarrett Wollman void 2634e115012SGarrett Wollman pvname(pname, vnum) 2644e115012SGarrett Wollman char *pname; 2654e115012SGarrett Wollman char *vnum; 2664e115012SGarrett Wollman { 2674e115012SGarrett Wollman f_print(fout, "%s_%s", locase(pname), vnum); 2684e115012SGarrett Wollman } 2694e115012SGarrett Wollman 2704e115012SGarrett Wollman /* 2714e115012SGarrett Wollman * print a useful (?) error message, and then die 2724e115012SGarrett Wollman */ 2734e115012SGarrett Wollman void 2744e115012SGarrett Wollman error(msg) 2754e115012SGarrett Wollman char *msg; 2764e115012SGarrett Wollman { 2774e115012SGarrett Wollman printwhere(); 2784e115012SGarrett Wollman f_print(stderr, "%s, line %d: ", infilename, linenum); 2794e115012SGarrett Wollman f_print(stderr, "%s\n", msg); 2804e115012SGarrett Wollman crash(); 2814e115012SGarrett Wollman } 2824e115012SGarrett Wollman 2834e115012SGarrett Wollman /* 2844e115012SGarrett Wollman * Something went wrong, unlink any files that we may have created and then 2854e115012SGarrett Wollman * die. 2864e115012SGarrett Wollman */ 287526195adSJordan K. Hubbard void 2884e115012SGarrett Wollman crash() 2894e115012SGarrett Wollman { 2904e115012SGarrett Wollman int i; 2914e115012SGarrett Wollman 2924e115012SGarrett Wollman for (i = 0; i < nfiles; i++) { 2934e115012SGarrett Wollman (void) unlink(outfiles[i]); 2944e115012SGarrett Wollman } 2954e115012SGarrett Wollman exit(1); 2964e115012SGarrett Wollman } 2974e115012SGarrett Wollman 2984e115012SGarrett Wollman void 2994e115012SGarrett Wollman record_open(file) 3004e115012SGarrett Wollman char *file; 3014e115012SGarrett Wollman { 3024e115012SGarrett Wollman if (nfiles < NFILES) { 3034e115012SGarrett Wollman outfiles[nfiles++] = file; 3044e115012SGarrett Wollman } else { 3054e115012SGarrett Wollman f_print(stderr, "too many files!\n"); 3064e115012SGarrett Wollman crash(); 3074e115012SGarrett Wollman } 3084e115012SGarrett Wollman } 3094e115012SGarrett Wollman 3104e115012SGarrett Wollman static char expectbuf[100]; 3114e115012SGarrett Wollman static char *toktostr(); 3124e115012SGarrett Wollman 3134e115012SGarrett Wollman /* 3144e115012SGarrett Wollman * error, token encountered was not the expected one 3154e115012SGarrett Wollman */ 3164e115012SGarrett Wollman void 3174e115012SGarrett Wollman expected1(exp1) 3184e115012SGarrett Wollman tok_kind exp1; 3194e115012SGarrett Wollman { 3204e115012SGarrett Wollman s_print(expectbuf, "expected '%s'", 3214e115012SGarrett Wollman toktostr(exp1)); 3224e115012SGarrett Wollman error(expectbuf); 3234e115012SGarrett Wollman } 3244e115012SGarrett Wollman 3254e115012SGarrett Wollman /* 3264e115012SGarrett Wollman * error, token encountered was not one of two expected ones 3274e115012SGarrett Wollman */ 3284e115012SGarrett Wollman void 3294e115012SGarrett Wollman expected2(exp1, exp2) 3304e115012SGarrett Wollman tok_kind exp1, exp2; 3314e115012SGarrett Wollman { 3324e115012SGarrett Wollman s_print(expectbuf, "expected '%s' or '%s'", 3334e115012SGarrett Wollman toktostr(exp1), 3344e115012SGarrett Wollman toktostr(exp2)); 3354e115012SGarrett Wollman error(expectbuf); 3364e115012SGarrett Wollman } 3374e115012SGarrett Wollman 3384e115012SGarrett Wollman /* 3394e115012SGarrett Wollman * error, token encountered was not one of 3 expected ones 3404e115012SGarrett Wollman */ 3414e115012SGarrett Wollman void 3424e115012SGarrett Wollman expected3(exp1, exp2, exp3) 3434e115012SGarrett Wollman tok_kind exp1, exp2, exp3; 3444e115012SGarrett Wollman { 3454e115012SGarrett Wollman s_print(expectbuf, "expected '%s', '%s' or '%s'", 3464e115012SGarrett Wollman toktostr(exp1), 3474e115012SGarrett Wollman toktostr(exp2), 3484e115012SGarrett Wollman toktostr(exp3)); 3494e115012SGarrett Wollman error(expectbuf); 3504e115012SGarrett Wollman } 3514e115012SGarrett Wollman 3524e115012SGarrett Wollman void 3534e115012SGarrett Wollman tabify(f, tab) 3544e115012SGarrett Wollman FILE *f; 3554e115012SGarrett Wollman int tab; 3564e115012SGarrett Wollman { 3574e115012SGarrett Wollman while (tab--) { 3584e115012SGarrett Wollman (void) fputc('\t', f); 3594e115012SGarrett Wollman } 3604e115012SGarrett Wollman } 3614e115012SGarrett Wollman 3624e115012SGarrett Wollman 3634e115012SGarrett Wollman static token tokstrings[] = { 3644e115012SGarrett Wollman {TOK_IDENT, "identifier"}, 3654e115012SGarrett Wollman {TOK_CONST, "const"}, 3664e115012SGarrett Wollman {TOK_RPAREN, ")"}, 3674e115012SGarrett Wollman {TOK_LPAREN, "("}, 3684e115012SGarrett Wollman {TOK_RBRACE, "}"}, 3694e115012SGarrett Wollman {TOK_LBRACE, "{"}, 3704e115012SGarrett Wollman {TOK_LBRACKET, "["}, 3714e115012SGarrett Wollman {TOK_RBRACKET, "]"}, 3724e115012SGarrett Wollman {TOK_STAR, "*"}, 3734e115012SGarrett Wollman {TOK_COMMA, ","}, 3744e115012SGarrett Wollman {TOK_EQUAL, "="}, 3754e115012SGarrett Wollman {TOK_COLON, ":"}, 3764e115012SGarrett Wollman {TOK_SEMICOLON, ";"}, 3774e115012SGarrett Wollman {TOK_UNION, "union"}, 3784e115012SGarrett Wollman {TOK_STRUCT, "struct"}, 3794e115012SGarrett Wollman {TOK_SWITCH, "switch"}, 3804e115012SGarrett Wollman {TOK_CASE, "case"}, 3814e115012SGarrett Wollman {TOK_DEFAULT, "default"}, 3824e115012SGarrett Wollman {TOK_ENUM, "enum"}, 3834e115012SGarrett Wollman {TOK_TYPEDEF, "typedef"}, 3844e115012SGarrett Wollman {TOK_INT, "int"}, 3854e115012SGarrett Wollman {TOK_SHORT, "short"}, 3864e115012SGarrett Wollman {TOK_LONG, "long"}, 3874e115012SGarrett Wollman {TOK_UNSIGNED, "unsigned"}, 3884e115012SGarrett Wollman {TOK_DOUBLE, "double"}, 3894e115012SGarrett Wollman {TOK_FLOAT, "float"}, 3904e115012SGarrett Wollman {TOK_CHAR, "char"}, 3914e115012SGarrett Wollman {TOK_STRING, "string"}, 3924e115012SGarrett Wollman {TOK_OPAQUE, "opaque"}, 3934e115012SGarrett Wollman {TOK_BOOL, "bool"}, 3944e115012SGarrett Wollman {TOK_VOID, "void"}, 3954e115012SGarrett Wollman {TOK_PROGRAM, "program"}, 3964e115012SGarrett Wollman {TOK_VERSION, "version"}, 3974e115012SGarrett Wollman {TOK_EOF, "??????"} 3984e115012SGarrett Wollman }; 3994e115012SGarrett Wollman 4004e115012SGarrett Wollman static char * 4014e115012SGarrett Wollman toktostr(kind) 4024e115012SGarrett Wollman tok_kind kind; 4034e115012SGarrett Wollman { 4044e115012SGarrett Wollman token *sp; 4054e115012SGarrett Wollman 4064e115012SGarrett Wollman for (sp = tokstrings; sp->kind != TOK_EOF && sp->kind != kind; sp++); 4074e115012SGarrett Wollman return (sp->str); 4084e115012SGarrett Wollman } 4094e115012SGarrett Wollman 410526195adSJordan K. Hubbard static void 4114e115012SGarrett Wollman printbuf() 4124e115012SGarrett Wollman { 4134e115012SGarrett Wollman char c; 4144e115012SGarrett Wollman int i; 4154e115012SGarrett Wollman int cnt; 4164e115012SGarrett Wollman 4174e115012SGarrett Wollman # define TABSIZE 4 4184e115012SGarrett Wollman 419526195adSJordan K. Hubbard for (i = 0; (c = curline[i]); i++) { 4204e115012SGarrett Wollman if (c == '\t') { 4214e115012SGarrett Wollman cnt = 8 - (i % TABSIZE); 4224e115012SGarrett Wollman c = ' '; 4234e115012SGarrett Wollman } else { 4244e115012SGarrett Wollman cnt = 1; 4254e115012SGarrett Wollman } 4264e115012SGarrett Wollman while (cnt--) { 4274e115012SGarrett Wollman (void) fputc(c, stderr); 4284e115012SGarrett Wollman } 4294e115012SGarrett Wollman } 4304e115012SGarrett Wollman } 4314e115012SGarrett Wollman 432526195adSJordan K. Hubbard static void 4334e115012SGarrett Wollman printwhere() 4344e115012SGarrett Wollman { 4354e115012SGarrett Wollman int i; 4364e115012SGarrett Wollman char c; 4374e115012SGarrett Wollman int cnt; 4384e115012SGarrett Wollman 4394e115012SGarrett Wollman printbuf(); 4404e115012SGarrett Wollman for (i = 0; i < where - curline; i++) { 4414e115012SGarrett Wollman c = curline[i]; 4424e115012SGarrett Wollman if (c == '\t') { 4434e115012SGarrett Wollman cnt = 8 - (i % TABSIZE); 4444e115012SGarrett Wollman } else { 4454e115012SGarrett Wollman cnt = 1; 4464e115012SGarrett Wollman } 4474e115012SGarrett Wollman while (cnt--) { 4484e115012SGarrett Wollman (void) fputc('^', stderr); 4494e115012SGarrett Wollman } 4504e115012SGarrett Wollman } 4514e115012SGarrett Wollman (void) fputc('\n', stderr); 4524e115012SGarrett Wollman } 453ff49530fSBill Paul 454ff49530fSBill Paul char * 455ff49530fSBill Paul make_argname(pname, vname) 456ff49530fSBill Paul char *pname; 457ff49530fSBill Paul char *vname; 458ff49530fSBill Paul { 459ff49530fSBill Paul char *name; 460ff49530fSBill Paul 461ff49530fSBill Paul name = malloc(strlen(pname) + strlen(vname) + strlen(ARGEXT) + 3); 462ff49530fSBill Paul if (!name) { 463ff49530fSBill Paul fprintf(stderr, "failed in malloc"); 464ff49530fSBill Paul exit(1); 465ff49530fSBill Paul } 466ff49530fSBill Paul sprintf(name, "%s_%s_%s", locase(pname), vname, ARGEXT); 467ff49530fSBill Paul return (name); 468ff49530fSBill Paul } 469ff49530fSBill Paul 470ff49530fSBill Paul bas_type *typ_list_h; 471ff49530fSBill Paul bas_type *typ_list_t; 472ff49530fSBill Paul 473526195adSJordan K. Hubbard void 474ff49530fSBill Paul add_type(len, type) 475ff49530fSBill Paul int len; 476ff49530fSBill Paul char *type; 477ff49530fSBill Paul { 478ff49530fSBill Paul bas_type *ptr; 479ff49530fSBill Paul 480ff49530fSBill Paul if ((ptr = (bas_type *) malloc(sizeof (bas_type))) == 481ff49530fSBill Paul (bas_type *)NULL) { 482ff49530fSBill Paul fprintf(stderr, "failed in malloc"); 483ff49530fSBill Paul exit(1); 484ff49530fSBill Paul } 485ff49530fSBill Paul 486ff49530fSBill Paul ptr->name = type; 487ff49530fSBill Paul ptr->length = len; 488ff49530fSBill Paul ptr->next = NULL; 489ff49530fSBill Paul if (typ_list_t == NULL) 490ff49530fSBill Paul { 491ff49530fSBill Paul 492ff49530fSBill Paul typ_list_t = ptr; 493ff49530fSBill Paul typ_list_h = ptr; 494ff49530fSBill Paul } 495ff49530fSBill Paul else 496ff49530fSBill Paul { 497ff49530fSBill Paul typ_list_t->next = ptr; 498ff49530fSBill Paul typ_list_t = ptr; 499ff49530fSBill Paul }; 500ff49530fSBill Paul } 501ff49530fSBill Paul 502ff49530fSBill Paul 503ff49530fSBill Paul bas_type *find_type(type) 504ff49530fSBill Paul char *type; 505ff49530fSBill Paul { 506ff49530fSBill Paul bas_type * ptr; 507ff49530fSBill Paul 508ff49530fSBill Paul ptr = typ_list_h; 509ff49530fSBill Paul while (ptr != NULL) 510ff49530fSBill Paul { 511ff49530fSBill Paul if (strcmp(ptr->name, type) == 0) 512ff49530fSBill Paul return (ptr); 513ff49530fSBill Paul else 514ff49530fSBill Paul ptr = ptr->next; 515ff49530fSBill Paul }; 516ff49530fSBill Paul return (NULL); 517ff49530fSBill Paul } 518