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 5*79777a7dSnakanon * Common Development and Distribution License (the "License"). 6*79777a7dSnakanon * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*79777a7dSnakanon * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* 277c478bd9Sstevel@tonic-gate * awk -- common header file. 287c478bd9Sstevel@tonic-gate * 297c478bd9Sstevel@tonic-gate * Copyright 1986, 1994 by Mortice Kern Systems Inc. All rights reserved. 307c478bd9Sstevel@tonic-gate * 317c478bd9Sstevel@tonic-gate * This version uses the POSIX.2 compatible <regex.h> routines. 327c478bd9Sstevel@tonic-gate * 337c478bd9Sstevel@tonic-gate * Based on MKS awk(1) ported to be /usr/xpg4/bin/awk with POSIX/XCU4 changes 347c478bd9Sstevel@tonic-gate * 357c478bd9Sstevel@tonic-gate */ 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #include <stdio.h> 407c478bd9Sstevel@tonic-gate #include <ctype.h> 417c478bd9Sstevel@tonic-gate #include <string.h> 427c478bd9Sstevel@tonic-gate #include <math.h> 437c478bd9Sstevel@tonic-gate #include <limits.h> 447c478bd9Sstevel@tonic-gate #include <stdlib.h> 457c478bd9Sstevel@tonic-gate #include <regex.h> 467c478bd9Sstevel@tonic-gate #include <errno.h> 477c478bd9Sstevel@tonic-gate #include <sys/types.h> 487c478bd9Sstevel@tonic-gate #include <locale.h> 497c478bd9Sstevel@tonic-gate #include <wchar.h> 507c478bd9Sstevel@tonic-gate #include <widec.h> 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate #define YYMAXDEPTH 300 /* Max # of productions (used by yacc) */ 537c478bd9Sstevel@tonic-gate #define YYSSIZE 300 /* Size of State/Value stacks (MKS YACC) */ 547c478bd9Sstevel@tonic-gate #define MAXDIGINT 19 /* Number of digits in an INT */ 557c478bd9Sstevel@tonic-gate #define FNULL ((FILE *)0) 567c478bd9Sstevel@tonic-gate #define NNULL ((NODE *)0) 577c478bd9Sstevel@tonic-gate #define SNULL ((STRING)0) 587c478bd9Sstevel@tonic-gate #define LARGE INT_MAX /* Large integer */ 597c478bd9Sstevel@tonic-gate #define NPFILE 32 /* Number of -[fl] options allowed */ 607c478bd9Sstevel@tonic-gate #define NRECUR 3000 /* Maximum recursion depth */ 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate #define M_LDATA 1 637c478bd9Sstevel@tonic-gate #ifdef M_LDATA 647c478bd9Sstevel@tonic-gate #define NLINE 20000 /* Longest input record */ 657c478bd9Sstevel@tonic-gate #define NFIELD 4000 /* Number of fields allowed */ 667c478bd9Sstevel@tonic-gate #define NBUCKET 1024 /* # of symtab buckets (power of 2) */ 677c478bd9Sstevel@tonic-gate #else 687c478bd9Sstevel@tonic-gate #define NLINE 2048 /* Longest input record */ 697c478bd9Sstevel@tonic-gate #define NFIELD 1024 /* Number of fields allowed */ 707c478bd9Sstevel@tonic-gate #define NBUCKET 256 /* # of symtab buckets (power of 2) */ 717c478bd9Sstevel@tonic-gate #endif 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate #define NSNODE 40 /* Number of cached nodes */ 747c478bd9Sstevel@tonic-gate #define NCONTEXT 50 /* Amount of context for error msgs */ 757c478bd9Sstevel@tonic-gate #define hashbuck(n) ((n)&(NBUCKET-1)) 767c478bd9Sstevel@tonic-gate #if BSD 777c478bd9Sstevel@tonic-gate /* 787c478bd9Sstevel@tonic-gate * A speedup for BSD. Use their routines which are 797c478bd9Sstevel@tonic-gate * already optimised. Note that BSD bcopy does not 807c478bd9Sstevel@tonic-gate * return a value. 817c478bd9Sstevel@tonic-gate */ 827c478bd9Sstevel@tonic-gate int bcmp(); 837c478bd9Sstevel@tonic-gate #define memcmp(b1, b2, n) bcmp(b1, b2, n) 847c478bd9Sstevel@tonic-gate void bcopy(); 857c478bd9Sstevel@tonic-gate #define memcpy(b1, b2, n) bcopy(b2, b1, (int)n) 867c478bd9Sstevel@tonic-gate #endif /* BSD */ 877c478bd9Sstevel@tonic-gate #define vlook(n) vlookup(n, 0) 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate /* 907c478bd9Sstevel@tonic-gate * Basic AWK internal types. 917c478bd9Sstevel@tonic-gate */ 927c478bd9Sstevel@tonic-gate typedef double REAL; 937c478bd9Sstevel@tonic-gate typedef long long INT; 947c478bd9Sstevel@tonic-gate typedef wchar_t *STRING; 957c478bd9Sstevel@tonic-gate typedef struct NODE *(*FUNCTION)(struct NODE *np); 96*79777a7dSnakanon typedef void *REGEXP; 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate /* 997c478bd9Sstevel@tonic-gate * Node in the AWK interpreter expression tree. 1007c478bd9Sstevel@tonic-gate */ 1017c478bd9Sstevel@tonic-gate typedef struct NODE { 102*79777a7dSnakanon ushort_t n_type; 1037c478bd9Sstevel@tonic-gate struct NODE *n_next; /* Symbol table/PARM link */ 104*79777a7dSnakanon ushort_t n_flags; /* Node flags, type */ 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate union { 1107c478bd9Sstevel@tonic-gate struct { 111*79777a7dSnakanon ushort_t N_hash; /* Full hash value */ 1127c478bd9Sstevel@tonic-gate struct NODE *N_alink; /* Array link */ 1137c478bd9Sstevel@tonic-gate union { 1147c478bd9Sstevel@tonic-gate struct { 1157c478bd9Sstevel@tonic-gate STRING N_string; 1167c478bd9Sstevel@tonic-gate size_t N_strlen; 1177c478bd9Sstevel@tonic-gate } n_str; 1187c478bd9Sstevel@tonic-gate INT N_int; 1197c478bd9Sstevel@tonic-gate REAL N_real; 1207c478bd9Sstevel@tonic-gate FUNCTION N_function; 1217c478bd9Sstevel@tonic-gate struct NODE *N_ufunc; 1227c478bd9Sstevel@tonic-gate } n_tun; 1237c478bd9Sstevel@tonic-gate wchar_t N_name[1]; 1247c478bd9Sstevel@tonic-gate } n_term; 1257c478bd9Sstevel@tonic-gate struct { 1267c478bd9Sstevel@tonic-gate struct NODE *N_left; 1277c478bd9Sstevel@tonic-gate struct NODE *N_right; 128*79777a7dSnakanon ushort_t N_lineno; 1297c478bd9Sstevel@tonic-gate } n_op; 1307c478bd9Sstevel@tonic-gate struct { 1317c478bd9Sstevel@tonic-gate struct NODE *N_left; /* Used for fliplist */ 1327c478bd9Sstevel@tonic-gate struct NODE *N_right; 1337c478bd9Sstevel@tonic-gate REGEXP N_regexp; /* Regular expression */ 1347c478bd9Sstevel@tonic-gate } n_re; 1357c478bd9Sstevel@tonic-gate } n_un; 1367c478bd9Sstevel@tonic-gate } NODE; 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate /* 1397c478bd9Sstevel@tonic-gate * Definitions to make the node access much easier. 1407c478bd9Sstevel@tonic-gate */ 1417c478bd9Sstevel@tonic-gate #define n_hash n_un.n_term.N_hash /* full hash value is sym tbl */ 1427c478bd9Sstevel@tonic-gate #define n_scope n_un.n_term.N_hash /* local variable scope level */ 1437c478bd9Sstevel@tonic-gate #define n_alink n_un.n_term.N_alink /* link to array list */ 1447c478bd9Sstevel@tonic-gate #define n_string n_un.n_term.n_tun.n_str.N_string 1457c478bd9Sstevel@tonic-gate #define n_strlen n_un.n_term.n_tun.n_str.N_strlen 1467c478bd9Sstevel@tonic-gate #define n_int n_un.n_term.n_tun.N_int 1477c478bd9Sstevel@tonic-gate #define n_real n_un.n_term.n_tun.N_real 1487c478bd9Sstevel@tonic-gate #define n_function n_un.n_term.n_tun.N_function 1497c478bd9Sstevel@tonic-gate #define n_ufunc n_un.n_term.n_tun.N_ufunc 1507c478bd9Sstevel@tonic-gate #define n_name n_un.n_term.N_name 1517c478bd9Sstevel@tonic-gate #define n_left n_un.n_op.N_left 1527c478bd9Sstevel@tonic-gate #define n_right n_un.n_op.N_right 1537c478bd9Sstevel@tonic-gate #define n_lineno n_un.n_op.N_lineno 1547c478bd9Sstevel@tonic-gate #define n_keywtype n_un.n_op.N_lineno 1557c478bd9Sstevel@tonic-gate #define n_regexp n_un.n_re.N_regexp 1567c478bd9Sstevel@tonic-gate /* 1577c478bd9Sstevel@tonic-gate * Compress the types that are actually used in the final tree 1587c478bd9Sstevel@tonic-gate * to save space in the intermediate file. Allows 1 byte to 1597c478bd9Sstevel@tonic-gate * represent all types 1607c478bd9Sstevel@tonic-gate */ 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate /* 1697c478bd9Sstevel@tonic-gate * n_flags bit assignments. 1707c478bd9Sstevel@tonic-gate */ 1717c478bd9Sstevel@tonic-gate #define FALLOC 0x01 /* Allocated node */ 1727c478bd9Sstevel@tonic-gate #define FSTATIC 0x00 /* Not allocated */ 1737c478bd9Sstevel@tonic-gate #define FMATCH 0x02 /* pattern,pattern (first part matches) */ 1747c478bd9Sstevel@tonic-gate #define FSPECIAL 0x04 /* Special pre-computed variable */ 1757c478bd9Sstevel@tonic-gate #define FINARRAY 0x08 /* NODE installed in N_alink array list */ 1767c478bd9Sstevel@tonic-gate #define FNOALLOC 0x10 /* mark node FALLOC, but don't malloc */ 1777c478bd9Sstevel@tonic-gate #define FSENSE 0x20 /* Sense if string looks like INT/REAL */ 1787c478bd9Sstevel@tonic-gate #define FSAVE (FSPECIAL|FINARRAY) /* assign leaves on */ 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate #define FINT 0x40 /* Node has integer type */ 1817c478bd9Sstevel@tonic-gate #define FREAL 0x80 /* Node has real type */ 1827c478bd9Sstevel@tonic-gate #define FSTRING 0x100 /* Node has string type */ 1837c478bd9Sstevel@tonic-gate #define FNONTOK 0x200 /* Node has non-token type */ 1847c478bd9Sstevel@tonic-gate #define FVINT 0x400 /* Node looks like an integer */ 1857c478bd9Sstevel@tonic-gate #define FVREAL 0x800 /* Node looks like a real number */ 1867c478bd9Sstevel@tonic-gate #define FLARRAY 0x1000 /* Local array node */ 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate /* 1897c478bd9Sstevel@tonic-gate * n_flags macros 1907c478bd9Sstevel@tonic-gate * These work when given an argument of np->n_flags 1917c478bd9Sstevel@tonic-gate */ 1927c478bd9Sstevel@tonic-gate #define isleaf(f) (!((f)&FNONTOK)) 1937c478bd9Sstevel@tonic-gate #define isstring(f) ((f)&FSTRING) 1947c478bd9Sstevel@tonic-gate #define isastring(f) (((f)&(FSTRING|FALLOC)) == (FSTRING|FALLOC)) 1957c478bd9Sstevel@tonic-gate #define isnumber(f) ((f)&(FINT|FVINT|FREAL|FVREAL)) 1967c478bd9Sstevel@tonic-gate #define isreal(f) ((f)&(FREAL|FVREAL)) 1977c478bd9Sstevel@tonic-gate #define isint(f) ((f)&(FINT|FVINT)) 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate /* 2007c478bd9Sstevel@tonic-gate * Prototype file size is defined in awksize.h 2017c478bd9Sstevel@tonic-gate */ 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate /* 2087c478bd9Sstevel@tonic-gate * Awkrun prototype default name 2097c478bd9Sstevel@tonic-gate */ 2107c478bd9Sstevel@tonic-gate #if defined(DOS) 2117c478bd9Sstevel@tonic-gate #if defined(__386__) 2127c478bd9Sstevel@tonic-gate #define AWK_PROTOTYPE M_ETCDIR(awkrunf.dos) 2137c478bd9Sstevel@tonic-gate #define AWK_LPROTOTYPE M_ETCDIR(awkrunf.dos) 2147c478bd9Sstevel@tonic-gate #else 2157c478bd9Sstevel@tonic-gate #define AWK_PROTOTYPE M_ETCDIR(awkrun.dos) 2167c478bd9Sstevel@tonic-gate #define AWK_LPROTOTYPE M_ETCDIR(awkrunl.dos) 2177c478bd9Sstevel@tonic-gate #endif 2187c478bd9Sstevel@tonic-gate #elif defined(OS2) 2197c478bd9Sstevel@tonic-gate #define AWK_PROTOTYPE M_ETCDIR(awkrun.os2) 2207c478bd9Sstevel@tonic-gate #elif defined(NT) 2217c478bd9Sstevel@tonic-gate #define AWK_PROTOTYPE M_ETCDIR(awkrun.nt) 2227c478bd9Sstevel@tonic-gate #else 2237c478bd9Sstevel@tonic-gate #define AWK_PROTOTYPE M_ETCDIR(awkrun.mod) 2247c478bd9Sstevel@tonic-gate #endif 2257c478bd9Sstevel@tonic-gate 2267c478bd9Sstevel@tonic-gate /* 2277c478bd9Sstevel@tonic-gate * This is a kludge that gets around a bug in compact & large 2287c478bd9Sstevel@tonic-gate * models under DOS. It also makes the generated 2297c478bd9Sstevel@tonic-gate * code faster even if there wasn't a bug. UNIX people: try 2307c478bd9Sstevel@tonic-gate * to ignore these noisy "near" declarations. 2317c478bd9Sstevel@tonic-gate */ 2327c478bd9Sstevel@tonic-gate #ifndef DOS 2337c478bd9Sstevel@tonic-gate #define near 2347c478bd9Sstevel@tonic-gate #endif 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate typedef wchar_t near *LOCCHARP; /* pointer to local strings */ 2377c478bd9Sstevel@tonic-gate /* 2387c478bd9Sstevel@tonic-gate * Form of builtin symbols 2397c478bd9Sstevel@tonic-gate * This should be a union because only one of r_ivalue 2407c478bd9Sstevel@tonic-gate * and r_svalue is needed, but (alas) unions cannot be 2417c478bd9Sstevel@tonic-gate * initialised. 2427c478bd9Sstevel@tonic-gate */ 2437c478bd9Sstevel@tonic-gate typedef struct RESERVED { 2447c478bd9Sstevel@tonic-gate LOCCHARP r_name; 2457c478bd9Sstevel@tonic-gate int r_type; /* Type of node */ 2467c478bd9Sstevel@tonic-gate INT r_ivalue; /* Integer value or wcslen(r_svalue) */ 2477c478bd9Sstevel@tonic-gate STRING r_svalue; /* String value */ 2487c478bd9Sstevel@tonic-gate } RESERVED; 2497c478bd9Sstevel@tonic-gate 2507c478bd9Sstevel@tonic-gate /* 2517c478bd9Sstevel@tonic-gate * Table of builtin functions. 2527c478bd9Sstevel@tonic-gate */ 2537c478bd9Sstevel@tonic-gate typedef struct RESFUNC { 2547c478bd9Sstevel@tonic-gate LOCCHARP rf_name; 2557c478bd9Sstevel@tonic-gate int rf_type; /* FUNC || GETLINE */ 2567c478bd9Sstevel@tonic-gate FUNCTION rf_func; /* Function pointer */ 2577c478bd9Sstevel@tonic-gate } RESFUNC; 2587c478bd9Sstevel@tonic-gate 2597c478bd9Sstevel@tonic-gate /* 2607c478bd9Sstevel@tonic-gate * Structure holding list of open files. 2617c478bd9Sstevel@tonic-gate */ 2627c478bd9Sstevel@tonic-gate typedef struct OFILE { 263*79777a7dSnakanon ushort_t f_mode; /* Open mode: WRITE, APPEND, PIPE */ 2647c478bd9Sstevel@tonic-gate FILE *f_fp; /* File pointer if open */ 2657c478bd9Sstevel@tonic-gate char *f_name; /* Remembered file name */ 2667c478bd9Sstevel@tonic-gate } OFILE; 2677c478bd9Sstevel@tonic-gate 2687c478bd9Sstevel@tonic-gate /* Global functions -- awk.y */ 2697c478bd9Sstevel@tonic-gate int yyparse(void); 2707c478bd9Sstevel@tonic-gate 2717c478bd9Sstevel@tonic-gate /* Global functions -- awk1.c */ 2727c478bd9Sstevel@tonic-gate #ifdef __WATCOMC__ 2737c478bd9Sstevel@tonic-gate #pragma aux yyerror aborts; 2747c478bd9Sstevel@tonic-gate #pragma aux awkerr aborts; 2757c478bd9Sstevel@tonic-gate #pragma aux awkperr aborts; 2767c478bd9Sstevel@tonic-gate #endif 2777c478bd9Sstevel@tonic-gate void yyerror(char *msg, ...); 2787c478bd9Sstevel@tonic-gate void awkerr(char *fmt, ...); 2797c478bd9Sstevel@tonic-gate void awkperr(char *fmt, ...); 2807c478bd9Sstevel@tonic-gate void uexit(NODE *); 2817c478bd9Sstevel@tonic-gate int yylex(void); 2827c478bd9Sstevel@tonic-gate NODE *renode(wchar_t *restr); 2837c478bd9Sstevel@tonic-gate wchar_t *emalloc(unsigned); 2847c478bd9Sstevel@tonic-gate wchar_t *erealloc(wchar_t *, unsigned); 2857c478bd9Sstevel@tonic-gate 2867c478bd9Sstevel@tonic-gate /* Global functions -- awk2.c */ 2877c478bd9Sstevel@tonic-gate void awk(void); 2887c478bd9Sstevel@tonic-gate void dobegin(void); 2897c478bd9Sstevel@tonic-gate void doend(int status); 2907c478bd9Sstevel@tonic-gate int nextrecord(wchar_t *buf, FILE *fp); 2917c478bd9Sstevel@tonic-gate wchar_t *defrecord(wchar_t *bp, int lim, FILE *fp); 2927c478bd9Sstevel@tonic-gate wchar_t *charrecord(wchar_t *bp, int lim, FILE *fp); 2937c478bd9Sstevel@tonic-gate wchar_t *multirecord(wchar_t *bp, int lim, FILE *fp); 2947c478bd9Sstevel@tonic-gate wchar_t *whitefield(wchar_t **endp); 2957c478bd9Sstevel@tonic-gate wchar_t *blackfield(wchar_t **endp); 2967c478bd9Sstevel@tonic-gate wchar_t *refield(wchar_t **endp); 2977c478bd9Sstevel@tonic-gate void s_print(NODE *np); 2987c478bd9Sstevel@tonic-gate void s_prf(NODE *np); 2997c478bd9Sstevel@tonic-gate size_t xprintf(NODE *np, FILE *fp, wchar_t **cp); 3007c478bd9Sstevel@tonic-gate void awkclose(OFILE *op); 3017c478bd9Sstevel@tonic-gate 3027c478bd9Sstevel@tonic-gate /* Global functions -- awk3.c */ 3037c478bd9Sstevel@tonic-gate void strassign(NODE *np, STRING string, int flags, size_t length); 3047c478bd9Sstevel@tonic-gate NODE *nassign(NODE *np, NODE *value); 3057c478bd9Sstevel@tonic-gate NODE *assign(NODE *np, NODE *value); 3067c478bd9Sstevel@tonic-gate void delarray(NODE *np); 3077c478bd9Sstevel@tonic-gate NODE *node(int type, NODE *left, NODE *right); 3087c478bd9Sstevel@tonic-gate NODE *intnode(INT i); 3097c478bd9Sstevel@tonic-gate NODE *realnode(REAL r); 3107c478bd9Sstevel@tonic-gate NODE *stringnode(STRING str, int aflag, size_t wcslen); 3117c478bd9Sstevel@tonic-gate NODE *vlookup(wchar_t *name, int nocreate); 3127c478bd9Sstevel@tonic-gate NODE *emptynode(int type, size_t nlength); 3137c478bd9Sstevel@tonic-gate void freenode(NODE *np); 3147c478bd9Sstevel@tonic-gate void execute(NODE *np); 3157c478bd9Sstevel@tonic-gate INT exprint(NODE *np); 3167c478bd9Sstevel@tonic-gate REAL exprreal(NODE *np); 3177c478bd9Sstevel@tonic-gate STRING exprstring(NODE *np); 3187c478bd9Sstevel@tonic-gate STRING strsave(wchar_t *string); 3197c478bd9Sstevel@tonic-gate NODE *exprreduce(NODE *np); 3207c478bd9Sstevel@tonic-gate NODE *getlist(NODE **npp); 3217c478bd9Sstevel@tonic-gate NODE *symwalk(int *buckp, NODE **npp); 3227c478bd9Sstevel@tonic-gate REGEXP getregexp(NODE *np); 3237c478bd9Sstevel@tonic-gate void addsymtab(NODE *np); 3247c478bd9Sstevel@tonic-gate void delsymtab(NODE *np, int fflag); 3257c478bd9Sstevel@tonic-gate NODE * finstall(LOCCHARP name, FUNCTION f, int type); 3267c478bd9Sstevel@tonic-gate void kinstall(LOCCHARP name, int type); 3277c478bd9Sstevel@tonic-gate void fieldsplit(void); 3287c478bd9Sstevel@tonic-gate void promote(NODE *); 3297c478bd9Sstevel@tonic-gate 3307c478bd9Sstevel@tonic-gate 3317c478bd9Sstevel@tonic-gate 3327c478bd9Sstevel@tonic-gate 3337c478bd9Sstevel@tonic-gate 3347c478bd9Sstevel@tonic-gate 3357c478bd9Sstevel@tonic-gate 3367c478bd9Sstevel@tonic-gate /* Global functions -- awk4.c */ 3377c478bd9Sstevel@tonic-gate NODE *f_exp(NODE *np); 3387c478bd9Sstevel@tonic-gate NODE *f_int(NODE *np); 3397c478bd9Sstevel@tonic-gate NODE *f_log(NODE *np); 3407c478bd9Sstevel@tonic-gate NODE *f_sqrt(NODE *np); 3417c478bd9Sstevel@tonic-gate NODE *f_getline(NODE *np); 3427c478bd9Sstevel@tonic-gate NODE *f_index(NODE *np); 3437c478bd9Sstevel@tonic-gate NODE *f_length(NODE *np); 3447c478bd9Sstevel@tonic-gate NODE *f_split(NODE *np); 3457c478bd9Sstevel@tonic-gate NODE *f_sprintf(NODE *np); 3467c478bd9Sstevel@tonic-gate NODE *f_substr(NODE *np); 3477c478bd9Sstevel@tonic-gate NODE *f_rand(NODE *np); 3487c478bd9Sstevel@tonic-gate NODE *f_srand(NODE *np); 3497c478bd9Sstevel@tonic-gate NODE *f_sin(NODE *np); 3507c478bd9Sstevel@tonic-gate NODE *f_cos(NODE *np); 3517c478bd9Sstevel@tonic-gate NODE *f_atan2(NODE *np); 3527c478bd9Sstevel@tonic-gate NODE *f_sub(NODE *np); 3537c478bd9Sstevel@tonic-gate NODE *f_gsub(NODE *np); 3547c478bd9Sstevel@tonic-gate NODE *f_match(NODE *np); 3557c478bd9Sstevel@tonic-gate NODE *f_system(NODE *np); 3567c478bd9Sstevel@tonic-gate NODE *f_ord(NODE *np); 3577c478bd9Sstevel@tonic-gate NODE *f_tolower(NODE *np); 3587c478bd9Sstevel@tonic-gate NODE *f_toupper(NODE *np); 3597c478bd9Sstevel@tonic-gate NODE *f_close(NODE *np); 3607c478bd9Sstevel@tonic-gate NODE *f_asort(NODE *np); 3617c478bd9Sstevel@tonic-gate 3627c478bd9Sstevel@tonic-gate /* In awk0.c */ 3637c478bd9Sstevel@tonic-gate 3647c478bd9Sstevel@tonic-gate 3657c478bd9Sstevel@tonic-gate 3667c478bd9Sstevel@tonic-gate extern wchar_t _null[]; 3677c478bd9Sstevel@tonic-gate extern char r[]; 3687c478bd9Sstevel@tonic-gate extern char w[]; 3697c478bd9Sstevel@tonic-gate extern wchar_t s_OFMT[]; 3707c478bd9Sstevel@tonic-gate extern wchar_t s_CONVFMT[]; 3717c478bd9Sstevel@tonic-gate extern wchar_t s_NR[]; 3727c478bd9Sstevel@tonic-gate extern wchar_t s_NF[]; 3737c478bd9Sstevel@tonic-gate extern wchar_t s_OFS[]; 3747c478bd9Sstevel@tonic-gate extern wchar_t s_ORS[]; 3757c478bd9Sstevel@tonic-gate extern wchar_t s_RS[]; 3767c478bd9Sstevel@tonic-gate extern wchar_t s_FS[]; 3777c478bd9Sstevel@tonic-gate extern wchar_t s_FNR[]; 3787c478bd9Sstevel@tonic-gate extern wchar_t s_SUBSEP[]; 3797c478bd9Sstevel@tonic-gate extern wchar_t s_ARGC[], s_ARGV[], s_ENVIRON[]; 3807c478bd9Sstevel@tonic-gate extern wchar_t s_FILENAME[], s_SYMTAB[]; 3817c478bd9Sstevel@tonic-gate extern wchar_t s_BEGIN[], s_END[], s_next[]; 3827c478bd9Sstevel@tonic-gate extern wchar_t _begin[], _end[]; 3837c478bd9Sstevel@tonic-gate extern wchar_t s_exp[], s_getline[], s_index[], s_int[], s_length[], s_log[]; 3847c478bd9Sstevel@tonic-gate extern wchar_t s_split[], s_sprintf[], s_sqrt[], s_substr[]; 3857c478bd9Sstevel@tonic-gate extern wchar_t s_rand[], s_srand[], s_sin[], s_cos[], s_atan2[]; 3867c478bd9Sstevel@tonic-gate extern wchar_t s_sub[], s_gsub[], s_match[], s_system[], s_ord[]; 3877c478bd9Sstevel@tonic-gate extern wchar_t s_toupper[], s_tolower[], s_asort[]; 3887c478bd9Sstevel@tonic-gate extern wchar_t s_close[]; 3897c478bd9Sstevel@tonic-gate extern wchar_t redelim; 3907c478bd9Sstevel@tonic-gate extern unsigned char inprint; 3917c478bd9Sstevel@tonic-gate extern unsigned char funparm; 3927c478bd9Sstevel@tonic-gate extern unsigned char splitdone; 3937c478bd9Sstevel@tonic-gate extern uint_t npattern; 3947c478bd9Sstevel@tonic-gate extern uint_t nfield; 3957c478bd9Sstevel@tonic-gate extern uint_t fcount; 3967c478bd9Sstevel@tonic-gate extern uint_t phase; 3977c478bd9Sstevel@tonic-gate extern uint_t running; 3987c478bd9Sstevel@tonic-gate extern uchar_t catterm; 3997c478bd9Sstevel@tonic-gate extern uint_t lexlast; 4007c478bd9Sstevel@tonic-gate extern uint_t lineno; 4017c478bd9Sstevel@tonic-gate extern uchar_t needsplit, needenviron, doing_begin, begin_getline; 402*79777a7dSnakanon extern ushort_t slevel; 403*79777a7dSnakanon extern ushort_t loopexit; 4047c478bd9Sstevel@tonic-gate extern wchar_t radixpoint; 4057c478bd9Sstevel@tonic-gate extern REGEXP resep; 4067c478bd9Sstevel@tonic-gate extern RESERVED reserved[]; 4077c478bd9Sstevel@tonic-gate extern RESFUNC resfuncs[]; 4087c478bd9Sstevel@tonic-gate extern long NIOSTREAM; /* Maximum open I/O streams */ 4097c478bd9Sstevel@tonic-gate extern OFILE *ofiles; 4107c478bd9Sstevel@tonic-gate extern wchar_t *linebuf; 4117c478bd9Sstevel@tonic-gate extern size_t lbuflen; 4127c478bd9Sstevel@tonic-gate extern char interr[]; 4137c478bd9Sstevel@tonic-gate extern char nomem[]; 4147c478bd9Sstevel@tonic-gate extern NODE *symtab[NBUCKET]; 4157c478bd9Sstevel@tonic-gate extern NODE *yytree; 4167c478bd9Sstevel@tonic-gate extern NODE *freelist; 4177c478bd9Sstevel@tonic-gate extern wchar_t *(*awkrecord)(wchar_t *, int, FILE *); 4187c478bd9Sstevel@tonic-gate extern wchar_t *(*awkfield)(wchar_t **); 4197c478bd9Sstevel@tonic-gate 4207c478bd9Sstevel@tonic-gate extern NODE *constant; 4217c478bd9Sstevel@tonic-gate extern NODE *const0; 4227c478bd9Sstevel@tonic-gate extern NODE *const1; 4237c478bd9Sstevel@tonic-gate extern NODE *constundef; 4247c478bd9Sstevel@tonic-gate extern NODE *field0; 4257c478bd9Sstevel@tonic-gate extern NODE *incNR; 4267c478bd9Sstevel@tonic-gate extern NODE *incFNR; 4277c478bd9Sstevel@tonic-gate extern NODE *clrFNR; 4287c478bd9Sstevel@tonic-gate extern NODE *ARGVsubi; 4297c478bd9Sstevel@tonic-gate extern NODE *varNR; 4307c478bd9Sstevel@tonic-gate extern NODE *varFNR; 4317c478bd9Sstevel@tonic-gate extern NODE *varNF; 4327c478bd9Sstevel@tonic-gate extern NODE *varOFMT; 4337c478bd9Sstevel@tonic-gate extern NODE *varCONVFMT; 4347c478bd9Sstevel@tonic-gate extern NODE *varOFS; 4357c478bd9Sstevel@tonic-gate extern NODE *varORS; 4367c478bd9Sstevel@tonic-gate extern NODE *varFS; 4377c478bd9Sstevel@tonic-gate extern NODE *varRS; 4387c478bd9Sstevel@tonic-gate extern NODE *varARGC; 4397c478bd9Sstevel@tonic-gate extern NODE *varSUBSEP; 4407c478bd9Sstevel@tonic-gate extern NODE *varENVIRON; 4417c478bd9Sstevel@tonic-gate extern NODE *varSYMTAB; 4427c478bd9Sstevel@tonic-gate extern NODE *varFILENAME; 4437c478bd9Sstevel@tonic-gate extern NODE *curnode; 4447c478bd9Sstevel@tonic-gate extern NODE *inc_oper; 4457c478bd9Sstevel@tonic-gate extern NODE *asn_oper; 4467c478bd9Sstevel@tonic-gate 4477c478bd9Sstevel@tonic-gate extern char *mbunconvert(wchar_t *); 4487c478bd9Sstevel@tonic-gate extern wchar_t *mbstowcsdup(char *); 4497c478bd9Sstevel@tonic-gate extern char *wcstombsdup(wchar_t *); 4507c478bd9Sstevel@tonic-gate extern void awkerr(char *, ...); 4517c478bd9Sstevel@tonic-gate /* 4527c478bd9Sstevel@tonic-gate * The following defines the expected max length in chars of a printed number. 4537c478bd9Sstevel@tonic-gate * This should be the longest expected size for any type of number 4547c478bd9Sstevel@tonic-gate * ie. float, long etc. This number is used to calculate the approximate 4557c478bd9Sstevel@tonic-gate * number of chars needed to hold the number. 4567c478bd9Sstevel@tonic-gate */ 4577c478bd9Sstevel@tonic-gate #ifdef M_NUMSIZE 4587c478bd9Sstevel@tonic-gate #define NUMSIZE M_NUMSIZE 4597c478bd9Sstevel@tonic-gate #else 4607c478bd9Sstevel@tonic-gate #define NUMSIZE 30 4617c478bd9Sstevel@tonic-gate #endif 4627c478bd9Sstevel@tonic-gate 4637c478bd9Sstevel@tonic-gate #define M_MB_L(s) L##s 4647c478bd9Sstevel@tonic-gate #ifdef __STDC__ 4657c478bd9Sstevel@tonic-gate #define ANSI(x) x 4667c478bd9Sstevel@tonic-gate #else 4677c478bd9Sstevel@tonic-gate #define const 4687c478bd9Sstevel@tonic-gate #define signed 4697c478bd9Sstevel@tonic-gate #define volatile 4707c478bd9Sstevel@tonic-gate #define ANSI(x) () 4717c478bd9Sstevel@tonic-gate #endif 4727c478bd9Sstevel@tonic-gate 4737c478bd9Sstevel@tonic-gate #define isWblank(x) (((x) == ' ' || (x) == '\t') ? 1 : 0) 4747c478bd9Sstevel@tonic-gate 4757c478bd9Sstevel@tonic-gate 4767c478bd9Sstevel@tonic-gate /* 4777c478bd9Sstevel@tonic-gate * Wide character version of regular expression functions. 4787c478bd9Sstevel@tonic-gate */ 4797c478bd9Sstevel@tonic-gate #define REGWMATCH_T int_regwmatch_t 4807c478bd9Sstevel@tonic-gate #define REGWCOMP int_regwcomp 4817c478bd9Sstevel@tonic-gate #define REGWEXEC int_regwexec 482*79777a7dSnakanon #define REGWFREE int_regwfree 483*79777a7dSnakanon #define REGWERROR int_regwerror 4847c478bd9Sstevel@tonic-gate #define REGWDOSUBA int_regwdosuba 4857c478bd9Sstevel@tonic-gate 4867c478bd9Sstevel@tonic-gate typedef struct { 4877c478bd9Sstevel@tonic-gate const wchar_t *rm_sp, *rm_ep; 4887c478bd9Sstevel@tonic-gate regoff_t rm_so, rm_eo; 4897c478bd9Sstevel@tonic-gate } int_regwmatch_t; 4907c478bd9Sstevel@tonic-gate 491*79777a7dSnakanon extern int int_regwcomp(REGEXP *, const wchar_t *); 492*79777a7dSnakanon extern int int_regwexec(REGEXP, const wchar_t *, size_t, 4937c478bd9Sstevel@tonic-gate int_regwmatch_t *, int); 494*79777a7dSnakanon extern void int_regwfree(REGEXP); 495*79777a7dSnakanon extern size_t int_regwerror(int, REGEXP, char *, size_t); 496*79777a7dSnakanon extern int int_regwdosuba(REGEXP, const wchar_t *, 4977c478bd9Sstevel@tonic-gate const wchar_t *, wchar_t **, int, int *); 498