Git init
[external/mawk.git] / mawk.h
1
2 /********************************************
3 mawk.h
4 copyright 1991-94, Michael D. Brennan
5
6 This is a source file for mawk, an implementation of
7 the AWK programming language.
8
9 Mawk is distributed without warranty under the terms of
10 the GNU General Public License, version 2, 1991.
11 ********************************************/
12
13
14 /*   $Log: mawk.h,v $
15  *   Revision 1.10  1996/08/25 19:31:04  mike
16  *   Added work-around for solaris strtod overflow bug.
17  *
18  * Revision 1.9  1995/06/18  19:42:21  mike
19  * Remove some redundant declarations and add some prototypes
20  *
21  * Revision 1.8  1995/06/18  19:17:48  mike
22  * Create a type Int which on most machines is an int, but on machines
23  * with 16bit ints, i.e., the PC is a long.  This fixes implicit assumption
24  * that int==long.
25  *
26  * Revision 1.7  1995/06/09  22:57:17  mike
27  * parse() no longer returns on error
28  *
29  * Revision 1.6  1994/12/13  00:09:55  mike
30  * rt_nr and rt_fnr for run-time error messages
31  *
32  * Revision 1.5  1994/12/11  23:25:09  mike
33  * -Wi option
34  *
35  * Revision 1.4  1994/12/11  22:14:18  mike
36  * remove THINK_C #defines.  Not a political statement, just no indication
37  * that anyone ever used it.
38  *
39  * Revision 1.3  1993/07/07  00:07:41  mike
40  * more work on 1.2
41  *
42  * Revision 1.2  1993/07/04  12:52:06  mike
43  * start on autoconfig changes
44  *
45 */
46
47
48 /*  mawk.h  */
49
50 #ifndef  MAWK_H
51 #define  MAWK_H   
52
53 #include  "nstd.h"
54 #include <stdio.h>
55 #include <unistd.h>
56 #include "types.h"
57
58 #ifdef   DEBUG
59 #define  YYDEBUG  1
60 extern  int   yydebug ;  /* print parse if on */
61 extern  int   dump_RE ;
62 #endif
63
64 extern  short  posix_space_flag , interactive_flag ;
65
66
67 /*----------------
68  *  GLOBAL VARIABLES
69  *----------------*/
70
71 /* a well known string */
72 extern STRING  null_str ;
73
74 #ifndef TEMPBUFF_GOES_HERE
75 #define EXTERN  extern
76 #else
77 #define EXTERN   /* empty */
78 #endif
79
80 /* a useful scratch area */
81 EXTERN  union {
82 STRING  *_split_buff[MAX_SPLIT] ;
83 char    _string_buff[MIN_SPRINTF] ;
84 } tempbuff ;
85
86 /* anonymous union */
87 #define  string_buff    tempbuff._string_buff
88 #define  split_buff     tempbuff._split_buff
89
90 #define  SPRINTF_SZ     sizeof(tempbuff)
91
92 /* help with casts */
93 extern int mpow2[] ;
94
95
96  /* these are used by the parser, scanner and error messages
97     from the compile  */
98
99 extern  char *pfile_name ; /* program input file */
100 extern  int current_token ;
101 extern  unsigned  token_lineno ; /* lineno of current token */
102 extern  unsigned  compile_error_count ;
103 extern  int  paren_cnt, brace_cnt ;
104 extern  int  print_flag, getline_flag ;
105 extern  short mawk_state ;
106 #define EXECUTION       1  /* other state is 0 compiling */
107
108
109 extern  char *progname ; /* for error messages */
110 extern  unsigned rt_nr , rt_fnr ; /* ditto */
111
112 /* macro to test the type of two adjacent cells */
113 #define TEST2(cp)  (mpow2[(cp)->type]+mpow2[((cp)+1)->type])
114
115 /* macro to get at the string part of a CELL */
116 #define string(cp) ((STRING *)(cp)->ptr)
117
118 #ifdef   DEBUG
119 #define cell_destroy(cp)  DB_cell_destroy(cp)
120 #else
121
122 #define cell_destroy(cp)   if ( (cp)->type >= C_STRING &&\
123                            -- string(cp)->ref_cnt == 0 )\
124                         zfree(string(cp),string(cp)->len+STRING_OH);else
125 #endif
126
127 /*  prototypes  */
128
129 void  PROTO( cast1_to_s, (CELL *) ) ;
130 void  PROTO( cast1_to_d, (CELL *) ) ;
131 void  PROTO( cast2_to_s, (CELL *) ) ;
132 void  PROTO( cast2_to_d, (CELL *) ) ;
133 void  PROTO( cast_to_RE, (CELL *) ) ;
134 void  PROTO( cast_for_split, (CELL *) ) ;
135 void  PROTO( check_strnum, (CELL *) ) ;
136 void  PROTO( cast_to_REPL, (CELL *) ) ;
137 Int   PROTO( d_to_I, (double)) ;
138
139 #define d_to_i(d)     ((int)d_to_I(d))
140
141
142 int   PROTO( test, (CELL *) ) ; /* test for null non-null */
143 CELL *PROTO( cellcpy, (CELL *, CELL *) ) ;
144 CELL *PROTO( repl_cpy, (CELL *, CELL *) ) ;
145 void  PROTO( DB_cell_destroy, (CELL *) ) ;
146 void  PROTO( overflow, (char *, unsigned) ) ;
147 void  PROTO( rt_overflow, (char *, unsigned) ) ;
148 void  PROTO( rt_error, ( char *, ...) ) ;
149 void  PROTO( mawk_exit, (int) ) __attribute__ ((noreturn)) ;
150 void PROTO( da, (INST *, FILE *)) ;
151 char *PROTO( str_str, (char*, char*, unsigned) ) ;
152 char *PROTO( rm_escape, (char *) ) ;
153 char *PROTO( re_pos_match, (char *, PTR, unsigned *) ) ;
154 int   PROTO( binmode, (void)) ;
155
156
157 void PROTO ( parse, (void) ) ;
158 int  PROTO ( yylex, (void) ) ;
159 int  PROTO( yyparse, (void) ) ;
160 void PROTO( yyerror, (char *) ) ;
161 void PROTO( scan_cleanup, (void)) ;
162
163 void PROTO( bozo, (char *) ) __attribute__ ((noreturn));
164 void PROTO( errmsg , (int, char*, ...) ) ;
165 void PROTO( compile_error, ( char *, ...) ) ;
166
167 void  PROTO( execute, (INST *, CELL *, CELL *) ) ;
168 char *PROTO( find_kw_str, (int) ) ;
169
170 #ifdef HAVE_STRTOD_OVF_BUG
171 double PROTO(strtod_with_ovf_bug, (const char*, char**)) ;
172 #define strtod  strtod_with_ovf_bug
173 #endif
174
175 #endif  /* MAWK_H */