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_util.c, Utility routines for the RPC protocol compiler 437c478bd9Sstevel@tonic-gate */ 447c478bd9Sstevel@tonic-gate #include <stdio.h> 45*61961e0fSrobinson #include <stdlib.h> 46*61961e0fSrobinson #include <unistd.h> 477c478bd9Sstevel@tonic-gate #include <ctype.h> 48*61961e0fSrobinson #include <string.h> 497c478bd9Sstevel@tonic-gate #include "rpc_scan.h" 507c478bd9Sstevel@tonic-gate #include "rpc_parse.h" 517c478bd9Sstevel@tonic-gate #include "rpc_util.h" 527c478bd9Sstevel@tonic-gate 53*61961e0fSrobinson extern void crash(void); 54*61961e0fSrobinson 55*61961e0fSrobinson static void printwhere(void); 56*61961e0fSrobinson 577c478bd9Sstevel@tonic-gate #define ARGEXT "argument" 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate char curline[MAXLINESIZE]; /* current read line */ 607c478bd9Sstevel@tonic-gate char *where = curline; /* current point in line */ 617c478bd9Sstevel@tonic-gate int linenum = 0; /* current line number */ 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate char *infilename; /* input filename */ 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate #define NFILES 15 667c478bd9Sstevel@tonic-gate char *outfiles[NFILES]; /* output file names */ 677c478bd9Sstevel@tonic-gate int nfiles; 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate FILE *fout; /* file pointer of current output */ 707c478bd9Sstevel@tonic-gate FILE *fin; /* file pointer of current input */ 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate list *defined; /* list of defined things */ 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate /* 757c478bd9Sstevel@tonic-gate * Reinitialize the world 767c478bd9Sstevel@tonic-gate */ 77*61961e0fSrobinson void 78*61961e0fSrobinson reinitialize(void) 797c478bd9Sstevel@tonic-gate { 80*61961e0fSrobinson (void) memset(curline, 0, MAXLINESIZE); 817c478bd9Sstevel@tonic-gate where = curline; 827c478bd9Sstevel@tonic-gate linenum = 0; 837c478bd9Sstevel@tonic-gate defined = NULL; 847c478bd9Sstevel@tonic-gate } 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate /* 877c478bd9Sstevel@tonic-gate * string equality 887c478bd9Sstevel@tonic-gate */ 89*61961e0fSrobinson int 90*61961e0fSrobinson streq(char *a, char *b) 917c478bd9Sstevel@tonic-gate { 927c478bd9Sstevel@tonic-gate return (strcmp(a, b) == 0); 937c478bd9Sstevel@tonic-gate } 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate /* 967c478bd9Sstevel@tonic-gate * find a value in a list 977c478bd9Sstevel@tonic-gate */ 987c478bd9Sstevel@tonic-gate definition * 99*61961e0fSrobinson findval(list *lst, char *val, int (*cmp)()) 1007c478bd9Sstevel@tonic-gate { 1017c478bd9Sstevel@tonic-gate for (; lst != NULL; lst = lst->next) { 102*61961e0fSrobinson if ((*cmp) (lst->val, val)) 1037c478bd9Sstevel@tonic-gate return (lst->val); 1047c478bd9Sstevel@tonic-gate } 1057c478bd9Sstevel@tonic-gate return (NULL); 1067c478bd9Sstevel@tonic-gate } 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate /* 1097c478bd9Sstevel@tonic-gate * store a value in a list 1107c478bd9Sstevel@tonic-gate */ 1117c478bd9Sstevel@tonic-gate void 112*61961e0fSrobinson storeval(list **lstp, definition *val) 1137c478bd9Sstevel@tonic-gate { 1147c478bd9Sstevel@tonic-gate list **l; 1157c478bd9Sstevel@tonic-gate list *lst; 1167c478bd9Sstevel@tonic-gate 117*61961e0fSrobinson for (l = lstp; *l != NULL; l = (list **)&(*l)->next); 118*61961e0fSrobinson lst = calloc(1, sizeof (list)); 1197c478bd9Sstevel@tonic-gate lst->val = val; 1207c478bd9Sstevel@tonic-gate lst->next = NULL; 1217c478bd9Sstevel@tonic-gate *l = lst; 1227c478bd9Sstevel@tonic-gate } 1237c478bd9Sstevel@tonic-gate 124*61961e0fSrobinson static int 125*61961e0fSrobinson findit(definition *def, char *type) 1267c478bd9Sstevel@tonic-gate { 1277c478bd9Sstevel@tonic-gate return (streq(def->def_name, type)); 1287c478bd9Sstevel@tonic-gate } 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate static char * 131*61961e0fSrobinson fixit(char *type, char *orig) 1327c478bd9Sstevel@tonic-gate { 1337c478bd9Sstevel@tonic-gate definition *def; 1347c478bd9Sstevel@tonic-gate 135*61961e0fSrobinson def = (definition *)FINDVAL(defined, type, findit); 136*61961e0fSrobinson if (def == NULL || def->def_kind != DEF_TYPEDEF) 1377c478bd9Sstevel@tonic-gate return (orig); 1387c478bd9Sstevel@tonic-gate switch (def->def.ty.rel) { 1397c478bd9Sstevel@tonic-gate case REL_VECTOR: 1407c478bd9Sstevel@tonic-gate if (streq(def->def.ty.old_type, "opaque")) 1417c478bd9Sstevel@tonic-gate return ("char"); 142*61961e0fSrobinson return (def->def.ty.old_type); 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate case REL_ALIAS: 1457c478bd9Sstevel@tonic-gate return (fixit(def->def.ty.old_type, orig)); 1467c478bd9Sstevel@tonic-gate default: 1477c478bd9Sstevel@tonic-gate return (orig); 1487c478bd9Sstevel@tonic-gate } 1497c478bd9Sstevel@tonic-gate } 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate char * 152*61961e0fSrobinson fixtype(char *type) 1537c478bd9Sstevel@tonic-gate { 1547c478bd9Sstevel@tonic-gate return (fixit(type, type)); 1557c478bd9Sstevel@tonic-gate } 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate char * 158*61961e0fSrobinson stringfix(char *type) 1597c478bd9Sstevel@tonic-gate { 160*61961e0fSrobinson if (streq(type, "string")) 1617c478bd9Sstevel@tonic-gate return ("wrapstring"); 162*61961e0fSrobinson return (type); 1637c478bd9Sstevel@tonic-gate } 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate void 166*61961e0fSrobinson ptype(char *prefix, char *type, int follow) 1677c478bd9Sstevel@tonic-gate { 1687c478bd9Sstevel@tonic-gate if (prefix != NULL) { 1697c478bd9Sstevel@tonic-gate if (streq(prefix, "enum")) { 1707c478bd9Sstevel@tonic-gate f_print(fout, "enum "); 1717c478bd9Sstevel@tonic-gate } else { 1727c478bd9Sstevel@tonic-gate f_print(fout, "struct "); 1737c478bd9Sstevel@tonic-gate } 1747c478bd9Sstevel@tonic-gate } 1757c478bd9Sstevel@tonic-gate if (streq(type, "bool")) { 1767c478bd9Sstevel@tonic-gate f_print(fout, "bool_t "); 1777c478bd9Sstevel@tonic-gate } else if (streq(type, "string")) { 1787c478bd9Sstevel@tonic-gate f_print(fout, "char *"); 1797c478bd9Sstevel@tonic-gate } else if (streq(type, "oneway")) { 1807c478bd9Sstevel@tonic-gate f_print(fout, "void "); 1817c478bd9Sstevel@tonic-gate } else { 1827c478bd9Sstevel@tonic-gate f_print(fout, "%s ", follow ? fixtype(type) : type); 1837c478bd9Sstevel@tonic-gate } 1847c478bd9Sstevel@tonic-gate } 1857c478bd9Sstevel@tonic-gate 186*61961e0fSrobinson static int 187*61961e0fSrobinson typedefed(definition *def, char *type) 1887c478bd9Sstevel@tonic-gate { 189*61961e0fSrobinson if (def->def_kind != DEF_TYPEDEF || def->def.ty.old_prefix != NULL) 1907c478bd9Sstevel@tonic-gate return (0); 191*61961e0fSrobinson return (streq(def->def_name, type)); 1927c478bd9Sstevel@tonic-gate } 1937c478bd9Sstevel@tonic-gate 194*61961e0fSrobinson int 195*61961e0fSrobinson isvectordef(char *type, relation rel) 1967c478bd9Sstevel@tonic-gate { 1977c478bd9Sstevel@tonic-gate definition *def; 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate for (;;) { 2007c478bd9Sstevel@tonic-gate switch (rel) { 2017c478bd9Sstevel@tonic-gate case REL_VECTOR: 2027c478bd9Sstevel@tonic-gate return (!streq(type, "string")); 2037c478bd9Sstevel@tonic-gate case REL_ARRAY: 2047c478bd9Sstevel@tonic-gate return (0); 2057c478bd9Sstevel@tonic-gate case REL_POINTER: 2067c478bd9Sstevel@tonic-gate return (0); 2077c478bd9Sstevel@tonic-gate case REL_ALIAS: 208*61961e0fSrobinson def = (definition *)FINDVAL(defined, type, typedefed); 2097c478bd9Sstevel@tonic-gate if (def == NULL) 2107c478bd9Sstevel@tonic-gate return (0); 2117c478bd9Sstevel@tonic-gate type = def->def.ty.old_type; 2127c478bd9Sstevel@tonic-gate rel = def->def.ty.rel; 2137c478bd9Sstevel@tonic-gate } 2147c478bd9Sstevel@tonic-gate } 2157c478bd9Sstevel@tonic-gate } 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate char * 218*61961e0fSrobinson locase(char *str) 2197c478bd9Sstevel@tonic-gate { 2207c478bd9Sstevel@tonic-gate char c; 2217c478bd9Sstevel@tonic-gate static char buf[100]; 2227c478bd9Sstevel@tonic-gate char *p = buf; 2237c478bd9Sstevel@tonic-gate 224*61961e0fSrobinson while (c = *str++) 2257c478bd9Sstevel@tonic-gate *p++ = (c >= 'A' && c <= 'Z') ? (c - 'A' + 'a') : c; 2267c478bd9Sstevel@tonic-gate *p = 0; 2277c478bd9Sstevel@tonic-gate return (buf); 2287c478bd9Sstevel@tonic-gate } 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gate void 231*61961e0fSrobinson pvname_svc(char *pname, char *vnum) 2327c478bd9Sstevel@tonic-gate { 2337c478bd9Sstevel@tonic-gate f_print(fout, "%s_%s_svc", locase(pname), vnum); 2347c478bd9Sstevel@tonic-gate } 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate void 237*61961e0fSrobinson pvname(char *pname, char *vnum) 2387c478bd9Sstevel@tonic-gate { 2397c478bd9Sstevel@tonic-gate f_print(fout, "%s_%s", locase(pname), vnum); 2407c478bd9Sstevel@tonic-gate } 2417c478bd9Sstevel@tonic-gate 2427c478bd9Sstevel@tonic-gate /* 2437c478bd9Sstevel@tonic-gate * print a useful (?) error message, and then die 2447c478bd9Sstevel@tonic-gate */ 2457c478bd9Sstevel@tonic-gate void 246*61961e0fSrobinson error(char *msg) 2477c478bd9Sstevel@tonic-gate { 2487c478bd9Sstevel@tonic-gate printwhere(); 2497c478bd9Sstevel@tonic-gate f_print(stderr, "%s, line %d: ", infilename, linenum); 2507c478bd9Sstevel@tonic-gate f_print(stderr, "%s\n", msg); 2517c478bd9Sstevel@tonic-gate crash(); 2527c478bd9Sstevel@tonic-gate } 2537c478bd9Sstevel@tonic-gate 2547c478bd9Sstevel@tonic-gate /* 2557c478bd9Sstevel@tonic-gate * Something went wrong, unlink any files that we may have created and then 2567c478bd9Sstevel@tonic-gate * die. 2577c478bd9Sstevel@tonic-gate */ 258*61961e0fSrobinson void 259*61961e0fSrobinson crash(void) 2607c478bd9Sstevel@tonic-gate { 2617c478bd9Sstevel@tonic-gate int i; 2627c478bd9Sstevel@tonic-gate 263*61961e0fSrobinson for (i = 0; i < nfiles; i++) 2647c478bd9Sstevel@tonic-gate (void) unlink(outfiles[i]); 2657c478bd9Sstevel@tonic-gate exit(1); 2667c478bd9Sstevel@tonic-gate } 2677c478bd9Sstevel@tonic-gate 2687c478bd9Sstevel@tonic-gate void 269*61961e0fSrobinson record_open(char *file) 2707c478bd9Sstevel@tonic-gate { 2717c478bd9Sstevel@tonic-gate if (nfiles < NFILES) { 2727c478bd9Sstevel@tonic-gate outfiles[nfiles++] = file; 273*61961e0fSrobinson return; 2747c478bd9Sstevel@tonic-gate } 275*61961e0fSrobinson f_print(stderr, "too many files!\n"); 276*61961e0fSrobinson crash(); 2777c478bd9Sstevel@tonic-gate } 2787c478bd9Sstevel@tonic-gate 2797c478bd9Sstevel@tonic-gate static char expectbuf[100]; 2807c478bd9Sstevel@tonic-gate static char *toktostr(); 2817c478bd9Sstevel@tonic-gate 2827c478bd9Sstevel@tonic-gate /* 2837c478bd9Sstevel@tonic-gate * error, token encountered was not the expected one 2847c478bd9Sstevel@tonic-gate */ 2857c478bd9Sstevel@tonic-gate void 286*61961e0fSrobinson expected1(tok_kind exp1) 2877c478bd9Sstevel@tonic-gate { 288*61961e0fSrobinson (void) snprintf(expectbuf, 289*61961e0fSrobinson sizeof (expectbuf), "expected '%s'", toktostr(exp1)); 2907c478bd9Sstevel@tonic-gate error(expectbuf); 2917c478bd9Sstevel@tonic-gate } 2927c478bd9Sstevel@tonic-gate 2937c478bd9Sstevel@tonic-gate /* 2947c478bd9Sstevel@tonic-gate * error, token encountered was not one of two expected ones 2957c478bd9Sstevel@tonic-gate */ 2967c478bd9Sstevel@tonic-gate void 297*61961e0fSrobinson expected2(tok_kind exp1, tok_kind exp2) 2987c478bd9Sstevel@tonic-gate { 299*61961e0fSrobinson (void) snprintf(expectbuf, 300*61961e0fSrobinson sizeof (expectbuf), "expected '%s' or '%s'", toktostr(exp1), 3017c478bd9Sstevel@tonic-gate toktostr(exp2)); 3027c478bd9Sstevel@tonic-gate error(expectbuf); 3037c478bd9Sstevel@tonic-gate } 3047c478bd9Sstevel@tonic-gate 3057c478bd9Sstevel@tonic-gate /* 3067c478bd9Sstevel@tonic-gate * error, token encountered was not one of 3 expected ones 3077c478bd9Sstevel@tonic-gate */ 3087c478bd9Sstevel@tonic-gate void 309*61961e0fSrobinson expected3(tok_kind exp1, tok_kind exp2, tok_kind exp3) 3107c478bd9Sstevel@tonic-gate { 311*61961e0fSrobinson (void) snprintf(expectbuf, 312*61961e0fSrobinson sizeof (expectbuf), "expected '%s', '%s' or '%s'", 313*61961e0fSrobinson toktostr(exp1), toktostr(exp2), toktostr(exp3)); 3147c478bd9Sstevel@tonic-gate error(expectbuf); 3157c478bd9Sstevel@tonic-gate } 3167c478bd9Sstevel@tonic-gate 3177c478bd9Sstevel@tonic-gate void 318*61961e0fSrobinson tabify(FILE *f, int tab) 3197c478bd9Sstevel@tonic-gate { 320*61961e0fSrobinson while (tab--) 3217c478bd9Sstevel@tonic-gate (void) fputc('\t', f); 3227c478bd9Sstevel@tonic-gate } 3237c478bd9Sstevel@tonic-gate 3247c478bd9Sstevel@tonic-gate static token tokstrings[] = { 3257c478bd9Sstevel@tonic-gate {TOK_IDENT, "identifier"}, 3267c478bd9Sstevel@tonic-gate {TOK_CONST, "const"}, 3277c478bd9Sstevel@tonic-gate {TOK_RPAREN, ")"}, 3287c478bd9Sstevel@tonic-gate {TOK_LPAREN, "("}, 3297c478bd9Sstevel@tonic-gate {TOK_RBRACE, "}"}, 3307c478bd9Sstevel@tonic-gate {TOK_LBRACE, "{"}, 3317c478bd9Sstevel@tonic-gate {TOK_LBRACKET, "["}, 3327c478bd9Sstevel@tonic-gate {TOK_RBRACKET, "]"}, 3337c478bd9Sstevel@tonic-gate {TOK_STAR, "*"}, 3347c478bd9Sstevel@tonic-gate {TOK_COMMA, ","}, 3357c478bd9Sstevel@tonic-gate {TOK_EQUAL, "="}, 3367c478bd9Sstevel@tonic-gate {TOK_COLON, ":"}, 3377c478bd9Sstevel@tonic-gate {TOK_SEMICOLON, ";"}, 3387c478bd9Sstevel@tonic-gate {TOK_UNION, "union"}, 3397c478bd9Sstevel@tonic-gate {TOK_STRUCT, "struct"}, 3407c478bd9Sstevel@tonic-gate {TOK_SWITCH, "switch"}, 3417c478bd9Sstevel@tonic-gate {TOK_CASE, "case"}, 3427c478bd9Sstevel@tonic-gate {TOK_DEFAULT, "default"}, 3437c478bd9Sstevel@tonic-gate {TOK_ENUM, "enum"}, 3447c478bd9Sstevel@tonic-gate {TOK_TYPEDEF, "typedef"}, 3457c478bd9Sstevel@tonic-gate {TOK_INT, "int"}, 3467c478bd9Sstevel@tonic-gate {TOK_SHORT, "short"}, 3477c478bd9Sstevel@tonic-gate {TOK_LONG, "long"}, 3487c478bd9Sstevel@tonic-gate {TOK_UNSIGNED, "unsigned"}, 3497c478bd9Sstevel@tonic-gate {TOK_DOUBLE, "double"}, 3507c478bd9Sstevel@tonic-gate {TOK_FLOAT, "float"}, 3517c478bd9Sstevel@tonic-gate {TOK_CHAR, "char"}, 3527c478bd9Sstevel@tonic-gate {TOK_STRING, "string"}, 3537c478bd9Sstevel@tonic-gate {TOK_OPAQUE, "opaque"}, 3547c478bd9Sstevel@tonic-gate {TOK_BOOL, "bool"}, 3557c478bd9Sstevel@tonic-gate {TOK_VOID, "void"}, 3567c478bd9Sstevel@tonic-gate {TOK_PROGRAM, "program"}, 3577c478bd9Sstevel@tonic-gate {TOK_VERSION, "version"}, 3587c478bd9Sstevel@tonic-gate {TOK_EOF, "??????"} 3597c478bd9Sstevel@tonic-gate }; 3607c478bd9Sstevel@tonic-gate 3617c478bd9Sstevel@tonic-gate static char * 362*61961e0fSrobinson toktostr(tok_kind kind) 3637c478bd9Sstevel@tonic-gate { 3647c478bd9Sstevel@tonic-gate token *sp; 3657c478bd9Sstevel@tonic-gate 3667c478bd9Sstevel@tonic-gate for (sp = tokstrings; sp->kind != TOK_EOF && sp->kind != kind; sp++); 3677c478bd9Sstevel@tonic-gate return (sp->str); 3687c478bd9Sstevel@tonic-gate } 3697c478bd9Sstevel@tonic-gate 370*61961e0fSrobinson static void 371*61961e0fSrobinson printbuf(void) 3727c478bd9Sstevel@tonic-gate { 3737c478bd9Sstevel@tonic-gate char c; 3747c478bd9Sstevel@tonic-gate int i; 3757c478bd9Sstevel@tonic-gate int cnt; 3767c478bd9Sstevel@tonic-gate 377*61961e0fSrobinson #define TABSIZE 4 3787c478bd9Sstevel@tonic-gate 379*61961e0fSrobinson for (i = 0; (c = curline[i]) != '\0'; i++) { 3807c478bd9Sstevel@tonic-gate if (c == '\t') { 3817c478bd9Sstevel@tonic-gate cnt = 8 - (i % TABSIZE); 3827c478bd9Sstevel@tonic-gate c = ' '; 3837c478bd9Sstevel@tonic-gate } else { 3847c478bd9Sstevel@tonic-gate cnt = 1; 3857c478bd9Sstevel@tonic-gate } 386*61961e0fSrobinson while (cnt--) 3877c478bd9Sstevel@tonic-gate (void) fputc(c, stderr); 3887c478bd9Sstevel@tonic-gate } 3897c478bd9Sstevel@tonic-gate } 3907c478bd9Sstevel@tonic-gate 391*61961e0fSrobinson static void 392*61961e0fSrobinson printwhere(void) 3937c478bd9Sstevel@tonic-gate { 3947c478bd9Sstevel@tonic-gate int i; 3957c478bd9Sstevel@tonic-gate char c; 3967c478bd9Sstevel@tonic-gate int cnt; 3977c478bd9Sstevel@tonic-gate 3987c478bd9Sstevel@tonic-gate printbuf(); 3997c478bd9Sstevel@tonic-gate for (i = 0; i < where - curline; i++) { 4007c478bd9Sstevel@tonic-gate c = curline[i]; 4017c478bd9Sstevel@tonic-gate if (c == '\t') { 4027c478bd9Sstevel@tonic-gate cnt = 8 - (i % TABSIZE); 4037c478bd9Sstevel@tonic-gate } else { 4047c478bd9Sstevel@tonic-gate cnt = 1; 4057c478bd9Sstevel@tonic-gate } 406*61961e0fSrobinson while (cnt--) 4077c478bd9Sstevel@tonic-gate (void) fputc('^', stderr); 4087c478bd9Sstevel@tonic-gate } 4097c478bd9Sstevel@tonic-gate (void) fputc('\n', stderr); 4107c478bd9Sstevel@tonic-gate } 4117c478bd9Sstevel@tonic-gate 4127c478bd9Sstevel@tonic-gate char * 413*61961e0fSrobinson make_argname(char *pname, char *vname) 4147c478bd9Sstevel@tonic-gate { 4157c478bd9Sstevel@tonic-gate char *name; 416*61961e0fSrobinson size_t nlen; 4177c478bd9Sstevel@tonic-gate 418*61961e0fSrobinson nlen = strlen(pname) + strlen(vname) + strlen(ARGEXT) + 3; 419*61961e0fSrobinson name = malloc(nlen); 420*61961e0fSrobinson if (name == NULL) { 421*61961e0fSrobinson (void) fprintf(stderr, "failed in malloc"); 4227c478bd9Sstevel@tonic-gate exit(1); 4237c478bd9Sstevel@tonic-gate } 424*61961e0fSrobinson (void) snprintf(name, nlen, "%s_%s_%s", locase(pname), vname, ARGEXT); 4257c478bd9Sstevel@tonic-gate return (name); 4267c478bd9Sstevel@tonic-gate } 4277c478bd9Sstevel@tonic-gate 4287c478bd9Sstevel@tonic-gate bas_type *typ_list_h; 4297c478bd9Sstevel@tonic-gate bas_type *typ_list_t; 4307c478bd9Sstevel@tonic-gate 431*61961e0fSrobinson void 432*61961e0fSrobinson add_type(int len, char *type) 4337c478bd9Sstevel@tonic-gate { 4347c478bd9Sstevel@tonic-gate bas_type *ptr; 4357c478bd9Sstevel@tonic-gate 436*61961e0fSrobinson if ((ptr = malloc(sizeof (bas_type))) == NULL) { 437*61961e0fSrobinson (void) fprintf(stderr, "failed in malloc"); 4387c478bd9Sstevel@tonic-gate exit(1); 4397c478bd9Sstevel@tonic-gate } 4407c478bd9Sstevel@tonic-gate 4417c478bd9Sstevel@tonic-gate ptr->name = type; 4427c478bd9Sstevel@tonic-gate ptr->length = len; 4437c478bd9Sstevel@tonic-gate ptr->next = NULL; 444*61961e0fSrobinson if (typ_list_t == NULL) { 4457c478bd9Sstevel@tonic-gate typ_list_t = ptr; 4467c478bd9Sstevel@tonic-gate typ_list_h = ptr; 447*61961e0fSrobinson } else { 4487c478bd9Sstevel@tonic-gate typ_list_t->next = ptr; 4497c478bd9Sstevel@tonic-gate typ_list_t = ptr; 450*61961e0fSrobinson } 4517c478bd9Sstevel@tonic-gate } 4527c478bd9Sstevel@tonic-gate 4537c478bd9Sstevel@tonic-gate 454*61961e0fSrobinson bas_type * 455*61961e0fSrobinson find_type(char *type) 4567c478bd9Sstevel@tonic-gate { 457*61961e0fSrobinson bas_type *ptr; 4587c478bd9Sstevel@tonic-gate 4597c478bd9Sstevel@tonic-gate ptr = typ_list_h; 460*61961e0fSrobinson while (ptr != NULL) { 4617c478bd9Sstevel@tonic-gate if (strcmp(ptr->name, type) == 0) 4627c478bd9Sstevel@tonic-gate return (ptr); 463*61961e0fSrobinson ptr = ptr->next; 464*61961e0fSrobinson } 4657c478bd9Sstevel@tonic-gate return (NULL); 4667c478bd9Sstevel@tonic-gate } 467