Print this page
3731 Update nawk to version 20121220

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/awk/awk.h
          +++ new/usr/src/cmd/awk/awk.h
↓ open down ↓ 15 lines elided ↑ open up ↑
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
  24   24   */
  25   25  
  26      -/*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
  27      -/*        All Rights Reserved   */
       26 +/*
       27 + * Copyright (C) Lucent Technologies 1997
       28 + * All Rights Reserved
       29 + *
       30 + * Permission to use, copy, modify, and distribute this software and
       31 + * its documentation for any purpose and without fee is hereby
       32 + * granted, provided that the above copyright notice appear in all
       33 + * copies and that both that the copyright notice and this
       34 + * permission notice and warranty disclaimer appear in supporting
       35 + * documentation, and that the name Lucent Technologies or any of
       36 + * its entities not be used in advertising or publicity pertaining
       37 + * to distribution of the software without specific, written prior
       38 + * permission.
       39 + *
       40 + * LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
       41 + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
       42 + * IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
       43 + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
       44 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
       45 + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
       46 + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
       47 + * THIS SOFTWARE.
       48 + */
  28   49  
  29   50  #ifndef AWK_H
  30   51  #define AWK_H
  31   52  
  32   53  #include <sys/types.h>
       54 +#include <assert.h>
  33   55  #include <ctype.h>
  34   56  #include <stdio.h>
  35   57  #include <stdlib.h>
  36   58  #include <string.h>
  37   59  #include <libintl.h>
  38   60  #include <limits.h>
  39   61  
  40   62  typedef double  Awkfloat;
  41   63  typedef unsigned char uchar;
  42   64  
  43      -#define xfree(a)        { if ((a) != NULL) { free(a); a = NULL; } }
       65 +#define xfree(a)        { if ((a) != NULL) { free((void *)(a)); (a) = NULL; } }
  44   66  
  45   67  #define DEBUG
  46   68  #ifdef  DEBUG
  47   69                          /* uses have to be doubly parenthesized */
  48   70  #define dprintf(x)      if (dbg) (void) printf x
  49   71  #else
  50   72  #define dprintf(x)
  51   73  #endif
  52   74  
  53      -extern  char    errbuf[200];
  54      -extern  void    error(int, char *);
  55      -#define ERROR   (void) snprintf(errbuf, sizeof (errbuf),
  56      -/*CSTYLED*/
  57      -#define FATAL   ), error(1, errbuf)
  58      -/*CSTYLED*/
  59      -#define WARNING ), error(0, errbuf)
  60      -/*CSTYLED*/
  61      -#define SYNTAX  ), yyerror(errbuf)
  62      -/*CSTYLED*/
  63      -#define CONT    )
  64      -
  65   75  extern int      compile_time;   /* 1 if compiling, 0 if running */
       76 +extern int      safe;           /* 0 => unsafe, 1 => safe */
  66   77  
  67      -#define FLD_INCR        64
  68      -#define LINE_INCR       256
  69      -
  70      -/* ensure that there is extra 1 byte in the buffer */
  71      -#define expand_buf(p, n, r)     \
  72      -        if (*(n) == 0 || (r) >= (*(n) - 1)) r_expand_buf(p, n, r)
       78 +#define RECSIZE (8 * 1024)      /* sets limit on records, fields, etc., etc. */
  73   79  
  74   80  extern uchar    **FS;
  75   81  extern uchar    **RS;
  76   82  extern uchar    **ORS;
  77   83  extern uchar    **OFS;
  78   84  extern uchar    **OFMT;
  79   85  extern Awkfloat *NR;
  80   86  extern Awkfloat *FNR;
  81   87  extern Awkfloat *NF;
  82   88  extern uchar    **FILENAME;
↓ open down ↓ 11 lines elided ↑ open up ↑
  94  100  extern  int     patlen;         /* length.  set in b.c */
  95  101  
  96  102  /* Cell:  all information about a variable or constant */
  97  103  
  98  104  typedef struct Cell {
  99  105          uchar   ctype;          /* OCELL, OBOOL, OJUMP, etc. */
 100  106          uchar   csub;           /* CCON, CTEMP, CFLD, etc. */
 101  107          uchar   *nval;          /* name, for variables only */
 102  108          uchar   *sval;          /* string value */
 103  109          Awkfloat fval;          /* value as number */
 104      -        unsigned tval;
      110 +        int     tval;
 105  111                  /* type info: STR|NUM|ARR|FCN|FLD|CON|DONTFREE */
 106  112          struct Cell *cnext;     /* ptr to next if chained */
 107  113  } Cell;
 108  114  
 109      -typedef struct {                /* symbol table array */
      115 +typedef struct Array {          /* symbol table array */
 110  116          int     nelem;          /* elements in table right now */
 111  117          int     size;           /* size of tab */
 112  118          Cell    **tab;          /* hash table pointers */
 113  119  } Array;
 114  120  
 115  121  #define NSYMTAB 50      /* initial size of a symbol table */
 116  122  extern Array    *symtab, *makesymtab(int);
 117      -extern Cell     *setsymtab(uchar *, uchar *, Awkfloat, unsigned int, Array *);
 118      -extern Cell     *lookup(uchar *, Array *);
      123 +extern Cell     *setsymtab(const uchar *, const uchar *, Awkfloat,
      124 +    unsigned int, Array *);
      125 +extern Cell     *lookup(const uchar *, Array *);
 119  126  
 120  127  extern Cell     *recloc;        /* location of input record */
 121  128  extern Cell     *nrloc;         /* NR */
 122  129  extern Cell     *fnrloc;        /* FNR */
 123  130  extern Cell     *nfloc;         /* NF */
 124  131  extern Cell     *rstartloc;     /* RSTART */
 125  132  extern Cell     *rlengthloc;    /* RLENGTH */
 126  133  
 127  134  /* Cell.tval values: */
 128  135  #define NUM     01      /* number value is valid */
 129  136  #define STR     02      /* string value is valid */
 130  137  #define DONTFREE 04     /* string space is not freeable */
 131  138  #define CON     010     /* this is a constant */
 132  139  #define ARR     020     /* this is an array */
 133  140  #define FCN     040     /* this is a function name */
 134  141  #define FLD     0100    /* this is a field $1, $2, ... */
 135  142  #define REC     0200    /* this is $0 */
 136  143  
 137      -#define freeable(p)     (!((p)->tval & DONTFREE))
 138  144  
 139  145  extern Awkfloat setfval(Cell *, Awkfloat), getfval(Cell *), r_getfval(Cell *);
 140      -extern uchar    *setsval(Cell *, uchar *), *getsval(Cell *), *r_getsval(Cell *);
 141      -extern uchar    *tostring(uchar *), *tokname(int), *qstring(uchar *, int);
 142      -
 143      -#define getfval(p)      \
 144      -        (((p)->tval & (ARR|FLD|REC|NUM)) == NUM ? (p)->fval : r_getfval(p))
 145      -#define getsval(p)      \
 146      -        (((p)->tval & (ARR|FLD|REC|STR)) == STR ? (p)->sval : r_getsval(p))
      146 +extern  uchar   *setsval(Cell *, const uchar *);
      147 +extern  uchar   *getsval(Cell *);
      148 +extern  uchar   *tostring(const uchar *);
      149 +extern  uchar   *tokname(int);
      150 +extern  uchar   *qstring(const uchar *, int);
 147  151  
 148  152  /* function types */
 149  153  #define FLENGTH 1
 150  154  #define FSQRT   2
 151  155  #define FEXP    3
 152  156  #define FLOG    4
 153  157  #define FINT    5
 154  158  #define FSYSTEM 6
 155  159  #define FRAND   7
 156  160  #define FSRAND  8
 157  161  #define FSIN    9
 158  162  #define FCOS    10
 159  163  #define FATAN   11
 160  164  #define FTOUPPER 12
 161  165  #define FTOLOWER 13
      166 +#define FFLUSH  14
 162  167  
 163  168  /* Node:  parse tree is made of nodes, with Cell's at bottom */
 164  169  
 165  170  typedef struct Node {
 166  171          int     ntype;
 167  172          struct  Node *nnext;
 168  173          off_t lineno;
 169  174          int     nobj;
 170  175          struct Node *narg[1];
 171  176                  /* variable: actual size set by calling malloc */
↓ open down ↓ 11 lines elided ↑ open up ↑
 183  188  #define OJUMP   3
 184  189  
 185  190  /* Cell subtypes: csub */
 186  191  #define CFREE   7
 187  192  #define CCOPY   6
 188  193  #define CCON    5
 189  194  #define CTEMP   4
 190  195  #define CNAME   3
 191  196  #define CVAR    2
 192  197  #define CFLD    1
      198 +#define CUNK    0
 193  199  
 194  200  /* bool subtypes */
 195  201  #define BTRUE   11
 196  202  #define BFALSE  12
 197  203  
 198  204  /* jump subtypes */
 199  205  #define JEXIT   21
 200  206  #define JNEXT   22
 201  207  #define JBREAK  23
 202  208  #define JCONT   24
 203  209  #define JRET    25
      210 +#define JNEXTFILE       26
 204  211  
 205  212  /* node types */
 206  213  #define NVALUE  1
 207  214  #define NSTAT   2
 208  215  #define NEXPR   3
 209  216  #define NFIELD  4
 210  217  
 211  218  extern  Cell    *(*proctab[])(Node **, int);
 212  219  extern  Cell    *nullproc(Node **, int);
 213  220  extern  int     pairstack[], paircnt;
 214  221  
 215      -extern  Node    *stat1(int, Node *), *stat2(int, Node *, Node *);
      222 +extern  int     pgetc(void);
      223 +extern  Node    *stat1(int, Node *);
      224 +extern  Node    *stat2(int, Node *, Node *);
 216  225  extern  Node    *stat3(int, Node *, Node *, Node *);
 217  226  extern  Node    *stat4(int, Node *, Node *, Node *, Node *);
 218  227  extern  Node    *pa2stat(Node *, Node *, Node *);
 219      -extern  Node    *op1(int, Node *), *op2(int, Node *, Node *);
      228 +extern  Node    *op1(int, Node *);
      229 +extern  Node    *op2(int, Node *, Node *);
 220  230  extern  Node    *op3(int, Node *, Node *, Node *);
 221  231  extern  Node    *op4(int, Node *, Node *, Node *, Node *);
 222      -extern  Node    *linkum(Node *, Node *), *valtonode(Cell *, int);
      232 +extern  Node    *linkum(Node *, Node *);
      233 +extern  Node    *celltonode(Cell *, int);
 223  234  extern  Node    *rectonode(void), *exptostat(Node *);
 224  235  extern  Node    *makearr(Node *);
      236 +extern  Node    *itonp(int);
 225  237  
 226  238  #define notlegal(n)     \
 227  239          (n <= FIRSTTOKEN || n >= LASTTOKEN || proctab[n-FIRSTTOKEN] == nullproc)
 228  240  #define isvalue(n)      ((n)->ntype == NVALUE)
 229  241  #define isexpr(n)       ((n)->ntype == NEXPR)
 230  242  #define isjump(n)       ((n)->ctype == OJUMP)
 231  243  #define isexit(n)       ((n)->csub == JEXIT)
 232  244  #define isbreak(n)      ((n)->csub == JBREAK)
 233  245  #define iscont(n)       ((n)->csub == JCONT)
 234      -#define isnext(n)       ((n)->csub == JNEXT)
      246 +#define isnext(n)       ((n)->csub == JNEXT || (n)->csub == JNEXTFILE)
 235  247  #define isret(n)        ((n)->csub == JRET)
      248 +#define isrec(n)        ((n)->tval & REC)
      249 +#define isfld(n)        ((n)->tval & FLD)
 236  250  #define isstr(n)        ((n)->tval & STR)
 237  251  #define isnum(n)        ((n)->tval & NUM)
 238  252  #define isarr(n)        ((n)->tval & ARR)
 239      -#define isfunc(n)       ((n)->tval & FCN)
      253 +#define isfcn(n)        ((n)->tval & FCN)
 240  254  #define istrue(n)       ((n)->csub == BTRUE)
 241  255  #define istemp(n)       ((n)->csub == CTEMP)
      256 +#define isargument(n)   ((n)->nobj == ARG)
      257 +/* #define      freeable(p)     (!((p)->tval & DONTFREE)) */
      258 +#define freeable(p)     (((p)->tval & (STR|DONTFREE)) == STR)
 242  259  
 243      -#define NCHARS  (256+1)
      260 +#define NCHARS  (256+3)         /* 256 handles 8-bit chars; 128 does 7-bit */
      261 +                                /* watch out in match(), etc. */
 244  262  #define NSTATES 32
 245  263  
 246  264  typedef struct rrow {
 247      -        int     ltype;
 248      -        int     lval;
      265 +        long    ltype;  /* long avoids pointer warnings on 64-bit */
      266 +        union {
      267 +                int i;
      268 +                Node *np;
      269 +                uchar *up;
      270 +        } lval;         /* because Al stores a pointer in it! */
 249  271          int     *lfollow;
 250  272  } rrow;
 251  273  
 252  274  typedef struct fa {
      275 +        uchar   gototab[NSTATES][NCHARS];
      276 +        uchar   out[NSTATES];
 253  277          uchar   *restr;
      278 +        int     *posns[NSTATES];
 254  279          int     anchor;
 255  280          int     use;
 256      -        uchar   gototab[NSTATES][NCHARS];
 257      -        int     *posns[NSTATES];
 258      -        uchar   out[NSTATES];
 259  281          int     initstat;
 260  282          int     curstat;
 261  283          int     accept;
 262  284          int     reset;
 263      -        struct  rrow re[1];
      285 +        struct  rrow re[1]; /* variable: actual size set by calling malloc */
 264  286  } fa;
 265  287  
 266  288  /* b.c */
 267      -extern  fa      *makedfa(uchar *, int);
 268      -extern  int     nematch(fa *, uchar *);
 269      -extern  int     match(fa *, uchar *);
 270      -extern  int     pmatch(fa *, uchar *);
      289 +extern  fa      *makedfa(const uchar *, int);
      290 +extern  int     nematch(fa *, const uchar *);
      291 +extern  int     match(fa *, const uchar *);
      292 +extern  int     pmatch(fa *, const uchar *);
      293 +
      294 +/* lex.c */
      295 +extern  void    unput(int);
      296 +extern  void    unputstr(const char *);
      297 +extern  void    startreg(void);
 271  298  
 272  299  /* lib.c */
 273      -extern  int     isclvar(uchar *);
 274      -extern  int     is_number(uchar *);
      300 +extern  void    recinit(unsigned int);
      301 +extern  void    growfldtab(int);
      302 +extern  int     isclvar(const uchar *);
      303 +extern  int     is_number(const uchar *);
 275  304  extern  void    setclvar(uchar *);
 276  305  extern  int     readrec(uchar **, size_t *, FILE *);
 277  306  extern  void    bracecheck(void);
 278  307  extern  void    syminit(void);
 279  308  extern  void    yyerror(char *);
 280  309  extern  void    fldbld(void);
 281  310  extern  void    recbld(void);
 282      -extern  int     getrec(uchar **, size_t *);
      311 +extern  int     getrec(uchar **, size_t *, int);
 283  312  extern  Cell    *fieldadr(int);
 284  313  extern  void    newfld(int);
 285  314  extern  Cell    *getfld(int);
 286  315  extern  int     fldidx(Cell *);
 287      -extern  double  errcheck(double, char *);
      316 +extern  void    SYNTAX(const char *, ...);
      317 +extern  void    FATAL(const char *, ...) __attribute__((__noreturn__));
      318 +extern  void    WARNING(const char *, ...);
      319 +extern  void    error(void);
      320 +extern  double  errcheck(double, const char *);
 288  321  extern  void    fpecatch(int);
 289      -extern  void    init_buf(uchar **, size_t *, size_t);
 290      -extern  void    adjust_buf(uchar **, size_t);
 291      -extern  void    r_expand_buf(uchar **, size_t *, size_t);
      322 +extern  void    nextfile(void);
 292  323  
 293  324  extern  int     donefld;
 294  325  extern  int     donerec;
 295  326  extern  uchar   *record;
 296  327  extern  size_t  record_size;
 297  328  
 298  329  /* main.c */
 299  330  extern  int     dbg;
 300  331  extern  uchar   *cmdname;
 301  332  extern  uchar   *lexprog;
 302  333  extern  int     compile_time;
 303  334  extern  char    radixpoint;
      335 +extern  uchar   *cursource(void);
 304  336  
 305  337  /* tran.c */
 306  338  extern  void    syminit(void);
 307  339  extern  void    arginit(int, uchar **);
 308  340  extern  void    envinit(uchar **);
 309  341  extern  void    freesymtab(Cell *);
 310      -extern  void    freeelem(Cell *, uchar *);
      342 +extern  void    freeelem(Cell *, const uchar *);
 311  343  extern  void    funnyvar(Cell *, char *);
 312      -extern  int     hash(uchar *, int);
      344 +extern  int     hash(const uchar *, int);
 313  345  extern  Awkfloat *ARGC;
 314  346  
 315  347  /* run.c */
      348 +extern  int     adjbuf(uchar **, size_t *, int, int, uchar **, const char *);
 316  349  extern  void    run(Node *);
 317  350  
 318  351  extern  int     paircnt;
 319  352  extern  Node    *winner;
 320  353  
 321  354  #ifndef input
 322  355  extern  int     input(void);
 323  356  #endif
 324  357  extern  int     yyparse(void);
 325  358  extern  FILE    *yyin;
 326  359  extern  off_t   lineno;
 327  360  
      361 +/* parse.c */
      362 +extern  int     ptoi(void *);
      363 +extern  int     isarg(const uchar *);
      364 +extern  void    defn(Cell *, Node *, Node *);
      365 +
 328  366  /* proc */
 329  367  extern Cell *nullproc(Node **, int);
 330  368  extern Cell *program(Node **, int);
 331  369  extern Cell *boolop(Node **, int);
 332  370  extern Cell *relop(Node **, int);
 333  371  extern Cell *array(Node **, int);
 334  372  extern Cell *indirect(Node **, int);
 335  373  extern Cell *substr(Node **, int);
 336  374  extern Cell *sub(Node **, int);
 337  375  extern Cell *gsub(Node **, int);
 338  376  extern Cell *sindex(Node **, int);
 339      -extern Cell *a_sprintf(Node **, int);
      377 +extern Cell *awksprintf(Node **, int);
 340  378  extern Cell *arith(Node **, int);
 341  379  extern Cell *incrdecr(Node **, int);
 342  380  extern Cell *cat(Node **, int);
 343  381  extern Cell *pastat(Node **, int);
 344  382  extern Cell *dopa2(Node **, int);
 345  383  extern Cell *matchop(Node **, int);
 346  384  extern Cell *intest(Node **, int);
 347      -extern Cell *aprintf(Node **, int);
 348      -extern Cell *print(Node **, int);
      385 +extern Cell *awkprintf(Node **, int);
      386 +extern Cell *printstat(Node **, int);
 349  387  extern Cell *closefile(Node **, int);
 350      -extern Cell *delete(Node **, int);
      388 +extern Cell *awkdelete(Node **, int);
 351  389  extern Cell *split(Node **, int);
 352  390  extern Cell *assign(Node **, int);
 353  391  extern Cell *condexpr(Node **, int);
 354  392  extern Cell *ifstat(Node **, int);
 355  393  extern Cell *whilestat(Node **, int);
 356  394  extern Cell *forstat(Node **, int);
 357  395  extern Cell *dostat(Node **, int);
 358  396  extern Cell *instat(Node **, int);
 359  397  extern Cell *jump(Node **, int);
 360  398  extern Cell *bltin(Node **, int);
 361  399  extern Cell *call(Node **, int);
 362  400  extern Cell *arg(Node **, int);
 363  401  extern Cell *getnf(Node **, int);
 364      -extern Cell *getaline(Node **, int);
      402 +extern Cell *awkgetline(Node **, int);
 365  403  
 366  404  #endif /* AWK_H */
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX