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 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate/* 237c478bd9Sstevel@tonic-gate * Copyright (c) 1996, by Sun Microsystems, Inc. 247c478bd9Sstevel@tonic-gate * All rights reserved. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate#include <locale.h> 287c478bd9Sstevel@tonic-gate#include <euc.h> 297c478bd9Sstevel@tonic-gate#include <widec.h> 307c478bd9Sstevel@tonic-gate#define xfree(a) { if (a!=NULL) { yfree(a); a=NULL; } } 317c478bd9Sstevel@tonic-gate#define yfree free 327c478bd9Sstevel@tonic-gate#ifdef DEBUG 337c478bd9Sstevel@tonic-gate#define dprintf if (dbg) printf 347c478bd9Sstevel@tonic-gate#else 357c478bd9Sstevel@tonic-gate# define dprintf(x1, x2, x3, x4) 367c478bd9Sstevel@tonic-gate#endif 377c478bd9Sstevel@tonic-gate#define WC_VERY_SMALL ((wchar_t) 0x0001) 387c478bd9Sstevel@tonic-gate#define WC_VERY_LARGE ((wchar_t) ~0x0000) 397c478bd9Sstevel@tonic-gatetypedef double awkfloat; 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gateextern wchar_t **FS; 427c478bd9Sstevel@tonic-gateextern wchar_t **RS; 437c478bd9Sstevel@tonic-gateextern wchar_t **ORS; 447c478bd9Sstevel@tonic-gateextern wchar_t **OFS; 457c478bd9Sstevel@tonic-gateextern wchar_t **OFMT; 467c478bd9Sstevel@tonic-gateextern awkfloat *NR; 477c478bd9Sstevel@tonic-gateextern awkfloat *NF; 487c478bd9Sstevel@tonic-gateextern wchar_t **FILENAME; 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gateextern wchar_t record[]; 517c478bd9Sstevel@tonic-gateextern wchar_t L_NULL[]; 527c478bd9Sstevel@tonic-gateextern int dbg; 537c478bd9Sstevel@tonic-gateextern long long lineno; 547c478bd9Sstevel@tonic-gateextern int errorflag; 557c478bd9Sstevel@tonic-gateextern int donefld; /* 1 if record broken into fields */ 567c478bd9Sstevel@tonic-gateextern int donerec; /* 1 if record is valid (no fld has changed */ 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate/* CELL: all information about a variable or constant */ 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gatetypedef struct val { 617c478bd9Sstevel@tonic-gate char ctype; /* CELL, BOOL, JUMP, etc. */ 627c478bd9Sstevel@tonic-gate char csub; /* subtype of ctype */ 637c478bd9Sstevel@tonic-gate wchar_t *nval; /* name, for variables only */ 647c478bd9Sstevel@tonic-gate wchar_t *sval; /* string value */ 657c478bd9Sstevel@tonic-gate awkfloat fval; /* value as number */ 667c478bd9Sstevel@tonic-gate unsigned tval; /* type info */ 677c478bd9Sstevel@tonic-gate struct val *nextval; /* ptr to next if chained */ 687c478bd9Sstevel@tonic-gate} CELL; 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gateextern CELL *symtab[]; 717c478bd9Sstevel@tonic-gateextern CELL *setsymtab(), *lookup(), **makesymtab(); 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gateextern CELL *recloc; /* location of input record */ 747c478bd9Sstevel@tonic-gateextern CELL *nrloc; /* NR */ 757c478bd9Sstevel@tonic-gateextern CELL *nfloc; /* NF */ 767c478bd9Sstevel@tonic-gateextern CELL *maxmfld; /* pointer to CELL for maximum field assigned to */ 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate/* CELL.tval values: */ 797c478bd9Sstevel@tonic-gate#define STR 01 /* string value is valid */ 807c478bd9Sstevel@tonic-gate#define NUM 02 /* number value is valid */ 817c478bd9Sstevel@tonic-gate#define FLD 04 /* FLD means don't free string space */ 827c478bd9Sstevel@tonic-gate#define CON 010 /* this is a constant */ 837c478bd9Sstevel@tonic-gate#define ARR 020 /* this is an array */ 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gateawkfloat setfval(), getfval(); 867c478bd9Sstevel@tonic-gatewchar_t *setsval(), *getsval(); 877c478bd9Sstevel@tonic-gatewchar_t *tostring(), *tokname(); 887c478bd9Sstevel@tonic-gatechar *toeuccode(); 897c478bd9Sstevel@tonic-gatedouble log(), sqrt(), exp(), atof(); 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate/* function types */ 927c478bd9Sstevel@tonic-gate#define FLENGTH 1 937c478bd9Sstevel@tonic-gate#define FSQRT 2 947c478bd9Sstevel@tonic-gate#define FEXP 3 957c478bd9Sstevel@tonic-gate#define FLOG 4 967c478bd9Sstevel@tonic-gate#define FINT 5 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gatetypedef struct nd { 997c478bd9Sstevel@tonic-gate char ntype; 1007c478bd9Sstevel@tonic-gate char subtype; 1017c478bd9Sstevel@tonic-gate struct nd *nnext; 1027c478bd9Sstevel@tonic-gate int nobj; 103*4774dff6SToomas Soome struct nd *narg[]; 1047c478bd9Sstevel@tonic-gate} NODE; 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gateextern NODE *winner; 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate/* ctypes */ 1097c478bd9Sstevel@tonic-gate#define OCELL 1 1107c478bd9Sstevel@tonic-gate#define OBOOL 2 1117c478bd9Sstevel@tonic-gate#define OJUMP 3 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate/* CELL subtypes */ 1147c478bd9Sstevel@tonic-gate#define CCON 5 1157c478bd9Sstevel@tonic-gate#define CTEMP 4 1167c478bd9Sstevel@tonic-gate#define CNAME 3 1177c478bd9Sstevel@tonic-gate#define CVAR 2 1187c478bd9Sstevel@tonic-gate#define CFLD 1 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate/* bool subtypes */ 1217c478bd9Sstevel@tonic-gate#define BTRUE 1 1227c478bd9Sstevel@tonic-gate#define BFALSE 2 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate/* jump subtypes */ 1257c478bd9Sstevel@tonic-gate#define JEXIT 1 1267c478bd9Sstevel@tonic-gate#define JNEXT 2 1277c478bd9Sstevel@tonic-gate#define JBREAK 3 1287c478bd9Sstevel@tonic-gate#define JCONT 4 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate/* node types */ 1317c478bd9Sstevel@tonic-gate#define NVALUE 1 1327c478bd9Sstevel@tonic-gate#define NSTAT 2 1337c478bd9Sstevel@tonic-gate#define NEXPR 3 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gateextern CELL *(*proctab[])(); 1367c478bd9Sstevel@tonic-gateextern int pairstack[], paircnt; 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate#define cantexec(n) (n->ntype == NVALUE) 1397c478bd9Sstevel@tonic-gate#define notlegal(n) (n <= FIRSTTOKEN || n >= LASTTOKEN || \ 1407c478bd9Sstevel@tonic-gate proctab[n-FIRSTTOKEN]== nullproc) 1417c478bd9Sstevel@tonic-gate#define isexpr(n) (n->ntype == NEXPR) 1427c478bd9Sstevel@tonic-gate#define isjump(n) (n->ctype == OJUMP) 1437c478bd9Sstevel@tonic-gate#define isexit(n) (n->ctype == OJUMP && n->csub == JEXIT) 1447c478bd9Sstevel@tonic-gate#define isbreak(n) (n->ctype == OJUMP && n->csub == JBREAK) 1457c478bd9Sstevel@tonic-gate#define iscont(n) (n->ctype == OJUMP && n->csub == JCONT) 1467c478bd9Sstevel@tonic-gate#define isnext(n) (n->ctype == OJUMP && n->csub == JNEXT) 1477c478bd9Sstevel@tonic-gate#define isstr(n) (n->tval & STR) 1487c478bd9Sstevel@tonic-gate#define isnum(n) (n->tval & NUM) 1497c478bd9Sstevel@tonic-gate#define istrue(n) (n->ctype == OBOOL && n->csub == BTRUE) 1507c478bd9Sstevel@tonic-gate#define istemp(n) (n->ctype == OCELL && n->csub == CTEMP) 1517c478bd9Sstevel@tonic-gate#define isfld(n) (!donefld && n->csub==CFLD && n->ctype==OCELL && \ 1527c478bd9Sstevel@tonic-gate n->nval==0) 1537c478bd9Sstevel@tonic-gate#define isrec(n) (donefld && n->csub==CFLD && n->ctype==OCELL && \ 1547c478bd9Sstevel@tonic-gate n->nval!=0) 1557c478bd9Sstevel@tonic-gateextern CELL *nullproc(); 1567c478bd9Sstevel@tonic-gateextern CELL *relop(); 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate#define MAXSYM 50 1597c478bd9Sstevel@tonic-gate#define HAT 0177 /* matches ^ in regular expr */ 1607c478bd9Sstevel@tonic-gate /* watch out for mach dep */ 1617c478bd9Sstevel@tonic-gate/* 1627c478bd9Sstevel@tonic-gate * The code set number can be knew from actual character, but "b.c" 1637c478bd9Sstevel@tonic-gate * will use some pseudo codes. And that psedo code will not confirm 1647c478bd9Sstevel@tonic-gate * to rule of real code set. 1657c478bd9Sstevel@tonic-gate */ 1667c478bd9Sstevel@tonic-gatetypedef struct ccl_chars { 1677c478bd9Sstevel@tonic-gate unsigned short cc_ns; /* Code set Number */ 1687c478bd9Sstevel@tonic-gate wchar_t cc_cs; /* Actual character */ 1697c478bd9Sstevel@tonic-gate unsigned short cc_ne; 1707c478bd9Sstevel@tonic-gate wchar_t cc_ce; 1717c478bd9Sstevel@tonic-gate} ccl_chars_t; 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gateccl_chars_t *cclenter(); 174dc5a8425Srobbin 175*4774dff6SToomas Soomeextern void error(int, char *, ...); 176