home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 419b.lha / GNU_Awk_v2.10_Beta / awk.h < prev    next >
C/C++ Source or Header  |  1990-10-01  |  21KB  |  708 lines

  1. /*
  2.  * awk.h -- Definitions for gawk. 
  3.  *
  4.  * Copyright (C) 1986 Free Software Foundation Written by Paul Rubin, August
  5.  * 1986 
  6.  *
  7.  * $Log:    awk.h,v $
  8.  * Revision 1.38  89/03/31  13:15:47  david
  9.  * MSDOS support and more function prototypes
  10.  * 
  11.  * Revision 1.37  89/03/30  10:18:22  david
  12.  * fixed up #if around vfprintf define
  13.  * 
  14.  * Revision 1.36  89/03/29  14:18:19  david
  15.  * delinting
  16.  * move struct redirect and IOBUF here
  17.  * fix WHOLELINE
  18.  * 
  19.  * Revision 1.35  89/03/24  15:56:35  david
  20.  * merge HASHNODE and AHASH into NODE
  21.  * 
  22.  * Revision 1.34  89/03/22  21:01:54  david
  23.  * support for new newnode(); delete obsolete member in struct search
  24.  * 
  25.  * Revision 1.33  89/03/21  19:25:06  david
  26.  * bring some prototypes up to date
  27.  * 
  28.  * Revision 1.32  89/03/21  11:10:44  david
  29.  * major cleanup
  30.  * rearrange NODE structure for space efficiency
  31.  * add MEMDEBUG stuff for finding memory leaks
  32.  * add STREQN define
  33.  * 
  34.  * Revision 1.31  89/03/15  21:53:55  david
  35.  * changes from Arnold: case-insensitive matching, BELL, delete obstack, cleanup
  36.  * 
  37.  * Revision 1.30  89/03/15  21:28:32  david
  38.  * add free_result to free return from tree_eval
  39.  * 
  40.  * Revision 1.29  88/12/15  12:52:10  david
  41.  * casetable made static elsewhere
  42.  * 
  43.  * Revision 1.28  88/12/14  10:50:21  david
  44.  * change FREE_TEMP macro to free_temp
  45.  * 
  46.  * Revision 1.27  88/12/13  22:20:09  david
  47.  * macro-front-end tree_eval, force_string and force_number
  48.  * 
  49.  * Revision 1.25  88/12/08  15:57:11  david
  50.  * added some #ifdef'd out debugging code
  51.  * 
  52.  * Revision 1.24  88/12/07  19:58:37  david
  53.  * changes for printing current source file in error messages
  54.  * 
  55.  * Revision 1.23  88/12/01  15:07:10  david
  56.  * changes to accomodate source line numbers in error messages
  57.  * 
  58.  * Revision 1.22  88/11/30  15:14:59  david
  59.  * FREE_ONE_REFERENCE macro merged inot do_deref()
  60.  * 
  61.  * Revision 1.21  88/11/29  15:17:01  david
  62.  * minor movement
  63.  * 
  64.  * Revision 1.20  88/11/23  21:36:00  david
  65.  * Arnold: portability addition
  66.  * 
  67.  * Revision 1.19  88/11/22  15:51:23  david
  68.  * changed order of elements in NODE decl. for better packing on sparc and 
  69.  * similar machines
  70.  * 
  71.  * Revision 1.18  88/11/22  13:45:15  david
  72.  * Arnold: changes for case-insensitive matching
  73.  * 
  74.  * Revision 1.17  88/11/15  10:15:28  david
  75.  * Arnold: move a bunch of #include's here
  76.  * 
  77.  * Revision 1.16  88/11/14  21:50:26  david
  78.  * Arnold: get sprintf() declaration right; correct STREQ macro
  79.  * 
  80.  * Revision 1.15  88/11/14  21:24:50  david
  81.  * added extern decl. for field_num
  82.  * 
  83.  * Revision 1.14  88/11/03  15:21:03  david
  84.  * extended flags defines; made force_number safe; added TEMP_FREE define
  85.  * 
  86.  * Revision 1.13  88/11/01  12:52:18  david
  87.  * allowed for vprintf code in awk5.c
  88.  * 
  89.  * Revision 1.12  88/11/01  12:07:27  david
  90.  * cleanup; additions of external declarations; added variable name to node;
  91.  * moved flags from sub.val to node proper
  92.  * 
  93.  * Revision 1.11  88/10/19  21:54:29  david
  94.  * safe_malloc to be used by obstack_alloc
  95.  * Node_val to replace other value types (to be done)
  96.  * emalloc and erealloc macros
  97.  * 
  98.  * Revision 1.10  88/10/17  19:52:50  david
  99.  * Arnold: fix cant_happen(); improve VPRINTF; purge FAST
  100.  * 
  101.  * Revision 1.9  88/10/13  22:02:47  david
  102.  * added some external declarations to make life easier
  103.  * #define VPRINTF for portable variable arg list handling
  104.  * 
  105.  * Revision 1.8  88/10/11  22:19:05  david
  106.  * added external decl.
  107.  * 
  108.  * Revision 1.7  88/06/05  22:15:40  david
  109.  * deleted level member from hashnode structure
  110.  * 
  111.  * Revision 1.6  88/06/05  22:05:25  david
  112.  * added cnt member to NODE structure (doesn't add to size, since val member 
  113.  * dominates)
  114.  * 
  115.  * Revision 1.5  88/05/31  09:29:14  david
  116.  * expunge Node_local_var
  117.  * 
  118.  * Revision 1.4  88/05/27  11:04:07  david
  119.  * changed AWKNUM to double to correspond to nawk
  120.  * 
  121.  * Revision 1.3  88/05/13  22:07:56  david
  122.  * moved some defines here from elsewhere
  123.  * 
  124.  * Revision 1.2  88/05/04  12:17:04  david
  125.  * make_for_loop() now returns a NODE *
  126.  * 
  127.  * Revision 1.1  88/04/08  15:15:25  david
  128.  * Initial revision
  129.  *  Revision 1.6  88/04/08  14:48:25  david changes from Arnold
  130.  * Robbins 
  131.  *
  132.  * Revision 1.5  88/03/23  22:17:23  david mostly delinting -- a couple of bug
  133.  * fixes 
  134.  *
  135.  * Revision 1.4  88/03/18  21:00:05  david Baseline -- hoefully all the
  136.  * functionality of the new awk added. Just debugging and tuning to do. 
  137.  *
  138.  * Revision 1.3  87/11/19  14:34:12  david added a bunch of new Node types added
  139.  * a new union entry to the expnode structure to accomodate function
  140.  * parameter names added a level variable to the symbol structure to keep
  141.  * track of function nesting level 
  142.  *
  143.  * Revision 1.2  87/10/29  21:48:32  david added Node_in_array NODETYPE 
  144.  *
  145.  * Revision 1.1  87/10/27  15:23:07  david Initial revision 
  146.  *
  147.  */
  148.  
  149. /*
  150.  * GAWK is distributed in the hope that it will be useful, but WITHOUT ANY
  151.  * WARRANTY.  No author or distributor accepts responsibility to anyone for
  152.  * the consequences of using it or for whether it serves any particular
  153.  * purpose or works at all, unless he says so in writing. Refer to the GAWK
  154.  * General Public License for full details. 
  155.  *
  156.  * Everyone is granted permission to copy, modify and redistribute GAWK, but
  157.  * only under the conditions described in the GAWK General Public License.  A
  158.  * copy of this license is supposed to have been given to you along with GAWK
  159.  * so you can know your rights and responsibilities.  It should be in a file
  160.  * named COPYING.  Among other things, the copyright notice and this notice
  161.  * must be preserved on all copies. 
  162.  *
  163.  * In other words, go ahead and share GAWK, but don't try to stop anyone else
  164.  * from sharing it farther.  Help stamp out software hoarding! 
  165.  */
  166.  
  167. /* ------------------------------ Includes ------------------------------ */
  168. #include <stdio.h>
  169. #include <ctype.h>
  170. #include <setjmp.h>
  171. #if defined(AMIGA) && defined(LATTICE)
  172.    /* rlp900927 -- <varargs.h>, <sys/types.h> and <sys/stat.h>
  173.                    not available in 5.05 */
  174.    /* rlp900927 -- use my own hacked version of varargs.h */
  175. #include "varargs.h"
  176. #else
  177. #include <varargs.h>
  178. #include <sys/types.h>
  179. #include <sys/stat.h>
  180. #endif
  181. #include <errno.h>
  182.  
  183. #include "regex.h"
  184.  
  185. /* ------------------- System Functions, Variables, etc ------------------- */
  186. /* nasty nasty SunOS-ism */
  187. #ifdef sparc
  188. #include <alloca.h>
  189. #ifdef lint
  190. extern char *alloca();
  191. #endif
  192. #else
  193. #ifdef __STDC__
  194. extern void *alloca();
  195. #else
  196. extern char *alloca();
  197. #endif
  198. #endif
  199. #if defined(USG) || defined(MSDOS)
  200. extern int sprintf();
  201. #define index    strchr
  202. #define rindex    strrchr
  203. #define bcmp    memcmp
  204. #define bcopy(s,d,l) memcpy((d),(s),(l))
  205. #define bzero(p,l) memset((p),0,(l))
  206. /* nasty nasty berkelixm */
  207. #define _setjmp    setjmp
  208. #define _longjmp    longjmp
  209. #else    /* not USG */
  210. extern char *sprintf();
  211. #endif
  212. /*
  213.  * if you don't have vprintf, but you are BSD, the version defined in
  214.  * awk5.c should do the trick.  Otherwise, use this and cross your fingers.
  215.  */
  216. #if defined(NOVPRINTF) && defined(HASDOPRNT)
  217. #define vfprintf(fp,fmt,arg)    _doprnt((fmt), (arg), (fp))
  218. #endif
  219.  
  220. #ifdef __STDC__
  221. extern void *malloc(unsigned), *realloc(void *, unsigned);
  222. extern void free(char *);
  223. extern char *getenv(char *);
  224.  
  225. extern char *strcpy(char *, char *), *strcat(char *, char *), *strncpy(char *, char *, int);
  226. extern char *index(char *, int);
  227.  
  228. extern double atof(char *);
  229. #else
  230. extern char *malloc(), *realloc();
  231. extern void free();
  232. extern char *getenv();
  233.  
  234. extern char *strcpy(), *strcat(), *strncpy();
  235. extern char *index();
  236.  
  237. extern double atof();
  238. #endif
  239.  
  240. extern int errno;
  241. extern char *sys_errlist[];
  242.  
  243. /* ------------------ Constants, Structures, Typedefs  ------------------ */
  244. #define AWKNUM    double
  245.  
  246. typedef enum {
  247.     /* illegal entry == 0 */
  248.     Node_illegal,        /* 0 */
  249.  
  250.     /* binary operators  lnode and rnode are the expressions to work on */
  251.     Node_times,        /* 1 */
  252.     Node_quotient,        /* 2 */
  253.     Node_mod,        /* 3 */
  254.     Node_plus,        /* 4 */
  255.     Node_minus,        /* 5 */
  256.     Node_cond_pair,        /* 6: conditional pair (see Node_line_range) */
  257.     Node_subscript,        /* 7 */
  258.     Node_concat,        /* 8 */
  259.  
  260.     /* unary operators   subnode is the expression to work on */
  261.     Node_preincrement,    /* 9 */
  262.     Node_predecrement,    /* 10 */
  263.     Node_postincrement,    /* 11 */
  264.     Node_postdecrement,    /* 12 */
  265.     Node_unary_minus,    /* 13 */
  266.     Node_field_spec,    /* 14 */
  267.  
  268.     /* assignments   lnode is the var to assign to, rnode is the exp */
  269.     Node_assign,        /* 15 */
  270.     Node_assign_times,    /* 16 */
  271.     Node_assign_quotient,    /* 17 */
  272.     Node_assign_mod,    /* 18 */
  273.     Node_assign_plus,    /* 19 */
  274.     Node_assign_minus,    /* 20 */
  275.  
  276.     /* boolean binaries   lnode and rnode are expressions */
  277.     Node_and,        /* 21 */
  278.     Node_or,        /* 22 */
  279.  
  280.     /* binary relationals   compares lnode and rnode */
  281.     Node_equal,        /* 23 */
  282.     Node_notequal,        /* 24 */
  283.     Node_less,        /* 25 */
  284.     Node_greater,        /* 26 */
  285.     Node_leq,        /* 27 */
  286.     Node_geq,        /* 28 */
  287.  
  288.     /* unary relationals   works on subnode */
  289.     Node_not,        /* 29 */
  290.  
  291.     /* match ops (binary)   work on lnode and rnode ??? */
  292.     Node_match,        /* 30 */
  293.     Node_nomatch,        /* 31 */
  294.  
  295.     /* data items */
  296.     Node_string,        /* deprecated: 32 has stlen, stptr, and stref */
  297.     Node_temp_string,    /* deprecated: 33 has stlen, stptr, and stref */
  298.     Node_number,        /* deprecated: 34 has numbr */
  299.  
  300.     /* program structures */
  301.     Node_rule_list,        /* 35 lnode is a rule, rnode is rest of list */
  302.     Node_rule_node,        /* 36 lnode is an conditional, rnode is
  303.                  * statement */
  304.     Node_statement_list,    /* 37 lnode is a statement, rnode is more
  305.                  * list */
  306.     Node_if_branches,    /* 38 lnode is to run on true, rnode on false */
  307.     Node_expression_list,    /* 39 lnode is an exp, rnode is more list */
  308.     Node_param_list,    /* 40 lnode is a variable, rnode is more list */
  309.  
  310.     /* keywords */
  311.     Node_K_BEGIN,        /* 41 no stuff */
  312.     Node_K_END,        /* 42 ditto */
  313.     Node_K_if,        /* 43 lnode is conditonal, rnode is
  314.                  * if_branches */
  315.     Node_K_while,        /* 44 lnode is condtional, rnode is stuff to
  316.                  * run */
  317.     Node_K_for,        /* 45 lnode is for_struct, rnode is stuff to
  318.                  * run */
  319.     Node_K_arrayfor,    /* 46 lnode is for_struct, rnode is stuff to
  320.                  * run */
  321.     Node_K_break,        /* 47 no subs */
  322.     Node_K_continue,    /* 48 no stuff */
  323.     Node_K_print,        /* 49 lnode is exp_list, rnode is redirect */
  324.     Node_K_printf,        /* 50 lnode is exp_list, rnode is redirect */
  325.     Node_K_next,        /* 51 no subs */
  326.     Node_K_exit,        /* 52 subnode is return value, or NULL */
  327.     Node_K_do,        /* 53 lnode is conditional, rnode is stuff to
  328.                  * run */
  329.     Node_K_return,        /* 54 */
  330.     Node_K_delete,        /* 55 */
  331.  
  332.     /* I/O redirection for print statements */
  333.     Node_redirect_output,    /* 56 subnode is where to redirect */
  334.     Node_redirect_append,    /* 57 subnode is where to redirect */
  335.     Node_redirect_pipe,    /* 58 subnode is where to redirect */
  336.     Node_redirect_pipein,    /* 59 subnode is where to redirect */
  337.     Node_redirect_input,    /* 60 subnode is where to redirect */
  338.  
  339.     /* Variables */
  340.     Node_var,        /* 61 rnode is value, lnode is array stuff */
  341.     Node_var_array,        /* 62 array is ptr to elements, asize num of
  342.                  * eles */
  343.  
  344.     /* Builtins   subnode is explist to work on, proc is func to call */
  345.     Node_builtin,        /* 63 */
  346.  
  347.     /*
  348.      * pattern: conditional ',' conditional ;  lnode of Node_line_range
  349.      * is the two conditionals (Node_cond_pair), other word (rnode place)
  350.      * is a flag indicating whether or not this range has been entered.
  351.      */
  352.     Node_line_range,    /* 64 */
  353.  
  354.     /*
  355.      * boolean test of membership in array lnode is string-valued
  356.      * expression rnode is array name 
  357.      */
  358.     Node_in_array,        /* 65 */
  359.     Node_K_function,    /* 66 lnode is statement list, rnode is
  360.                  * func_params */
  361.     Node_func,        /* 67 lnode is param. list, rnode is
  362.                  * statement list */
  363.     Node_func_call,        /* 68 lnode is name, rnode is expression list */
  364.     Node_K_getline,        /* 69 */
  365.     Node_sub,        /* 70 */
  366.     Node_gsub,        /* 71 */
  367.     Node_K_match,        /* 72 */
  368.     Node_cond_exp,        /* 73 lnode is conditonal, rnode is
  369.                  * if_branches */
  370.     Node_exp,        /* 74 */
  371.     Node_assign_exp,    /* 75 */
  372.     Node_regex,        /* 76 */
  373.     Node_str_num,        /* deprecated: 77 both string and numeric
  374.                  * values are valid
  375.                  */
  376.     Node_val,        /* 78 node is a value - type given by bits in
  377.                  * status - to replace Node_string, Node_num,
  378.                  * Node_temp_str and Node_str_num
  379.                  */
  380.     Node_hashnode,
  381.     Node_ahash,
  382. } NODETYPE;
  383.  
  384. typedef struct exp_node {
  385.     union {
  386.         struct {
  387.             union {
  388.                 struct exp_node *lptr;
  389.                 char *param_name;
  390.                 char *retext;
  391.                 struct exp_node *nextnode;
  392.             } l;
  393.             union {
  394.                 struct exp_node *rptr;
  395.                 struct exp_node *(*pptr) ();
  396.                 struct re_pattern_buffer *preg;
  397.                 struct for_loop_header *hd;
  398.                 struct exp_node **av;
  399.                 int r_ent;    /* range entered */
  400.             } r;
  401.             char *name;
  402.             short number;
  403.             unsigned char recase;
  404.         } nodep;
  405.         struct {
  406.             AWKNUM fltnum;    /* this is here for optimal packing of
  407.                      * the structure on many machines
  408.                      */
  409.             char *sp;
  410.             short slen;
  411.             unsigned char sref;
  412.         } val;
  413.         struct {
  414.             struct exp_node *next;
  415.             char *name;
  416.             int length;
  417.             struct exp_node *value;
  418.         } hash;
  419. #define    hnext    sub.hash.next
  420. #define    hname    sub.hash.name
  421. #define    hlength    sub.hash.length
  422. #define    hvalue    sub.hash.value
  423.         struct {
  424.             struct exp_node *next;
  425.             struct exp_node *name;
  426.             struct exp_node *value;
  427.         } ahash;
  428. #define    ahnext    sub.ahash.next
  429. #define    ahname    sub.ahash.name
  430. #define    ahvalue    sub.ahash.value
  431.     } sub;
  432.     NODETYPE type;
  433.     unsigned char flags;
  434. #                define    MEM    0x7
  435. #                define    MALLOC    1    /* can be free'd */
  436. #                define    TEMP    2    /* should be free'd */
  437. #                define    PERM    4    /* can't be free'd */
  438. #                define    VAL    0x18
  439. #                define    NUM    8
  440. #                define    STR    16
  441. } NODE;
  442.  
  443. #define lnode    sub.nodep.l.lptr
  444. #define nextp    sub.nodep.l.nextnode
  445. #define rnode    sub.nodep.r.rptr
  446. #define varname    sub.nodep.name
  447. #define source_file    sub.nodep.name
  448. #define    source_line    sub.nodep.number
  449. #define    param_cnt    sub.nodep.number
  450. #define param    sub.nodep.l.param_name
  451.  
  452. #define subnode    lnode
  453. #define proc    sub.nodep.r.pptr
  454.  
  455. #define reexp    lnode
  456. #define rereg    sub.nodep.r.preg
  457. #define re_case sub.nodep.recase
  458. #define re_text sub.nodep.l.retext
  459.  
  460. #define forsub    lnode
  461. #define forloop    rnode->sub.nodep.r.hd
  462.  
  463. #define stptr    sub.val.sp
  464. #define stlen    sub.val.slen
  465. #define stref    sub.val.sref
  466. #define    valstat    flags
  467.  
  468. #define numbr    sub.val.fltnum
  469.  
  470. #define var_value lnode
  471. #define var_array sub.nodep.r.av
  472.  
  473. #define condpair lnode
  474. #define triggered sub.nodep.r.r_ent
  475.  
  476. #define HASHSIZE 101
  477.  
  478. typedef struct for_loop_header {
  479.     NODE *init;
  480.     NODE *cond;
  481.     NODE *incr;
  482. } FOR_LOOP_HEADER;
  483.  
  484. /* for "for(iggy in foo) {" */
  485. struct search {
  486.     int numleft;
  487.     NODE **arr_ptr;
  488.     NODE *bucket;
  489.     NODE *retval;
  490. };
  491.  
  492. /* for faster input, bypass stdio */
  493. typedef struct iobuf {
  494.     int fd;
  495.     char *buf;
  496.     char *off;
  497.     int size;    /* this will be determined by an fstat() call */
  498.     int cnt;
  499.     char *secbuf;
  500.     int secsiz;
  501. } IOBUF;
  502.  
  503. /*
  504.  * structure used to dynamically maintain a linked-list of open files/pipes
  505.  */
  506. struct redirect {
  507.     int flag;
  508. #        define        RED_FILE    1
  509. #        define        RED_PIPE    2
  510. #        define        RED_READ    4
  511. #        define        RED_WRITE    8
  512. #        define        RED_APPEND    16
  513.     char *value;
  514.     FILE *fp;
  515.     IOBUF *iop;
  516.     long offset;        /* used for dynamic management of open files */
  517.     struct redirect *prev;
  518.     struct redirect *next;
  519. };
  520.  
  521. /* longjmp return codes, must be nonzero */
  522. /* Continue means either for loop/while continue, or next input record */
  523. #define TAG_CONTINUE 1
  524. /* Break means either for/while break, or stop reading input */
  525. #define TAG_BREAK 2
  526. /* Return means return from a function call; leave value in ret_node */
  527. #define    TAG_RETURN 3
  528.  
  529. #ifdef MSDOS
  530. #define HUGE    0x7fff
  531. #else
  532. #define HUGE    0x7fffffff
  533. #endif
  534.  
  535. /* -------------------------- External variables -------------------------- */
  536. /* gawk builtin variables */
  537. extern NODE *FS_node, *NF_node, *RS_node, *NR_node;
  538. extern NODE *FILENAME_node, *OFS_node, *ORS_node, *OFMT_node;
  539. extern NODE *FNR_node, *RLENGTH_node, *RSTART_node, *SUBSEP_node;
  540. extern NODE *IGNORECASE_node;
  541.  
  542. extern NODE **stack_ptr;
  543. extern NODE *Nnull_string;
  544. extern NODE *deref;
  545. extern NODE **fields_arr;
  546. extern int sourceline;
  547. extern char *source;
  548. extern NODE *expression_value;
  549.  
  550. extern NODE *variables[];
  551.  
  552. extern NODE *_t;    /* used as temporary in tree_eval */
  553. extern NODE *_result;    /* Ditto */
  554.  
  555. extern NODE *nextfree;
  556. extern NODE *lastfree;
  557.  
  558. extern char *myname;
  559.  
  560. extern int node0_valid;
  561. extern int field_num;
  562. extern int strict;
  563.  
  564. /* ------------------------- Pseudo-functions ------------------------- */
  565. #define is_identchar(c) (isalnum(c) || (c) == '_')
  566.  
  567. #define    tree_eval(t)    (_result = (_t = (t),(_t) == NULL ? Nnull_string : \
  568.             ((_t)->type == Node_val ? (_t) : r_tree_eval((_t)))))
  569.  
  570. #define    free_temp(n)    if ((n)->flags&TEMP) { deref = (n); do_deref(); } else
  571. #define    free_result()    if (_result) free_temp(_result); else
  572.  
  573. /*
  574.  * the loop_tag_valid variable allows continue/break-out-of-context to be
  575.  * caught and diagnosed
  576.  */
  577. #define PUSH_BINDING(stack, x, val) (bcopy ((char *)(x), (char *)(stack), sizeof (jmp_buf)), val++)
  578. #define RESTORE_BINDING(stack, x, val) (bcopy ((char *)(stack), (char *)(x), sizeof (jmp_buf)), val--)
  579.  
  580. #define    cant_happen()    fatal("line %d, file: %s; bailing out", \
  581.                 __LINE__, __FILE__);
  582. #ifdef MEMDEBUG
  583. #define memmsg(x,y,z,zz)    fprintf(stderr, "malloc: %s: %s: %d %0x\n", z, x, y, zz)
  584. #define free(s)    fprintf(stderr, "free: s: %0x\n", s), do_free(s)
  585. #else
  586. #define memmsg(x,y,z,zz)
  587. #endif
  588.  
  589. #define    emalloc(var,ty,x,str)    if ((var = (ty) malloc((unsigned)(x))) == NULL)\
  590.                     fatal("%s: %s: can't allocate memory (%s)",\
  591.                     (str), "var", sys_errlist[errno]); else\
  592.                     memmsg("var", x, str, var)
  593. #define    erealloc(var,ty,x,str)    if((var=(ty)realloc((char *)var,\
  594.                         (unsigned)(x)))==NULL)\
  595.                     fatal("%s: %s: can't allocate memory (%s)",\
  596.                     (str), "var", sys_errlist[errno]); else\
  597.                     memmsg("re: var", x, str, var)
  598. #ifdef DEBUG
  599. #define    force_number    r_force_number
  600. #define    force_string    r_force_string
  601. #else
  602. #ifdef lint
  603. extern AWKNUM force_number();
  604. #endif
  605. #ifdef MSDOS
  606. extern double _msc51bug;
  607. #define    force_number(n)    (_msc51bug=(_t = (n),(_t->flags & NUM) ? _t->numbr : r_force_number(_t)))
  608. #else
  609. #define    force_number(n)    (_t = (n),(_t->flags & NUM) ? _t->numbr : r_force_number(_t))
  610. #endif
  611. #define    force_string(s)    (_t = (s),(_t->flags & STR) ? _t : r_force_string(_t))
  612. #endif
  613.  
  614. #define    STREQ(a,b)    (*(a) == *(b) && strcmp((a), (b)) == 0)
  615. #define    STREQN(a,b,n)    ((n) && *(a) == *(b) && strncmp((a), (b), (n)) == 0)
  616.  
  617. #define    WHOLELINE    (node0_valid ? fields_arr[0] : *get_field(0,0))
  618.  
  619. /* ------------- Function prototypes or defs (as appropriate) ------------- */
  620. #ifdef __STDC__
  621. extern    int devopen(char *, char *);
  622. extern    struct re_pattern_buffer *make_regexp(NODE *, int);
  623. extern    struct re_pattern_buffer *mk_re_parse(char *, int);
  624. extern    NODE *variable(char *);
  625. extern    NODE *install(NODE **, char *, NODE *);
  626. extern    NODE *lookup(NODE **, char *);
  627. extern    NODE *make_name(char *, NODETYPE);
  628. extern    int interpret(NODE *);
  629. extern    NODE *r_tree_eval(NODE *);
  630. extern    void assign_number(NODE **, double);
  631. extern    int cmp_nodes(NODE *, NODE *);
  632. extern    char *get_fs(void);
  633. extern    struct redirect *redirect(NODE *, int *);
  634. extern    int flush_io(void);
  635. extern    void print_simple(NODE *, FILE *);
  636. /* extern    void warning(char *,...); */
  637. /* extern    void fatal(char *,...); */
  638. extern    void set_record(char *, int);
  639. extern    NODE **get_field(int, int);
  640. extern    NODE **get_lhs(NODE *, int);
  641. extern    void do_deref(void );
  642. extern    struct search *assoc_scan(NODE *);
  643. extern    struct search *assoc_next(struct search *);
  644. extern    NODE **assoc_lookup(NODE *, NODE *);
  645. extern    double r_force_number(NODE *);
  646. extern    NODE *r_force_string(NODE *);
  647. extern    NODE *newnode(NODETYPE);
  648. extern    NODE *dupnode(NODE *);
  649. extern    NODE *make_number(double);
  650. extern    NODE *tmp_number(double);
  651. extern    NODE *make_string(char *, int);
  652. extern    NODE *tmp_string(char *, int);
  653. extern    char *re_compile_pattern(char *, int, struct re_pattern_buffer *);
  654. extern    int re_search(struct re_pattern_buffer *, char *, int, int, int, struct re_registers *);
  655.  
  656. #else
  657. extern    int devopen();
  658. extern    struct re_pattern_buffer *make_regexp();
  659. extern    struct re_pattern_buffer *mk_re_parse();
  660. extern    NODE *variable();
  661. extern    NODE *install();
  662. extern    NODE *lookup();
  663. extern    int interpret();
  664. extern    NODE *r_tree_eval();
  665. extern    void assign_number();
  666. extern    int cmp_nodes();
  667. extern    char *get_fs();
  668. extern    struct redirect *redirect();
  669. extern    int flush_io();
  670. extern    void print_simple();
  671. extern    void warning();
  672. extern    void fatal();
  673. extern    void set_record();
  674. extern    NODE **get_field();
  675. extern    NODE **get_lhs();
  676. extern    void do_deref();
  677. extern    struct search *assoc_scan();
  678. extern    struct search *assoc_next();
  679. extern    NODE **assoc_lookup();
  680. extern    double r_force_number();
  681. extern    NODE *r_force_string();
  682. extern    NODE *newnode();
  683. extern    NODE *dupnode();
  684. extern    NODE *make_number();
  685. extern    NODE *tmp_number();
  686. extern    NODE *make_string();
  687. extern    NODE *tmp_string();
  688. extern    char *re_compile_pattern();
  689. extern    int re_search();
  690. #endif
  691.  
  692. /* Figure out what '\a' really is. */
  693. #ifdef __STDC__
  694. #define BELL    '\a'        /* sure makes life easy, don't it? */
  695. #else
  696. #    if 'z' - 'a' == 25    /* ascii */
  697. #        if 'a' != 97    /* machine is dumb enough to use mark parity */
  698. #            define BELL    '\207'
  699. #        else
  700. #            define BELL    '\07'
  701. #        endif
  702. #    else
  703. #        define BELL    '\057'
  704. #    endif
  705. #endif
  706.  
  707. extern char casetable[];    /* for case-independent regexp matching */
  708.