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