2 /********************************************
4 copyright 1991-94, Michael D. Brennan
6 This is a source file for mawk, an implementation of
7 the AWK programming language.
9 Mawk is distributed without warranty under the terms of
10 the GNU General Public License, version 2, 1991.
11 ********************************************/
15 * Revision 1.10 1996/08/25 19:31:04 mike
16 * Added work-around for solaris strtod overflow bug.
18 * Revision 1.9 1995/06/18 19:42:21 mike
19 * Remove some redundant declarations and add some prototypes
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
26 * Revision 1.7 1995/06/09 22:57:17 mike
27 * parse() no longer returns on error
29 * Revision 1.6 1994/12/13 00:09:55 mike
30 * rt_nr and rt_fnr for run-time error messages
32 * Revision 1.5 1994/12/11 23:25:09 mike
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.
39 * Revision 1.3 1993/07/07 00:07:41 mike
42 * Revision 1.2 1993/07/04 12:52:06 mike
43 * start on autoconfig changes
60 extern int yydebug ; /* print parse if on */
64 extern short posix_space_flag , interactive_flag ;
71 /* a well known string */
72 extern STRING null_str ;
74 #ifndef TEMPBUFF_GOES_HERE
77 #define EXTERN /* empty */
80 /* a useful scratch area */
82 STRING *_split_buff[MAX_SPLIT] ;
83 char _string_buff[MIN_SPRINTF] ;
87 #define string_buff tempbuff._string_buff
88 #define split_buff tempbuff._split_buff
90 #define SPRINTF_SZ sizeof(tempbuff)
96 /* these are used by the parser, scanner and error messages
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 */
109 extern char *progname ; /* for error messages */
110 extern unsigned rt_nr , rt_fnr ; /* ditto */
112 /* macro to test the type of two adjacent cells */
113 #define TEST2(cp) (mpow2[(cp)->type]+mpow2[((cp)+1)->type])
115 /* macro to get at the string part of a CELL */
116 #define string(cp) ((STRING *)(cp)->ptr)
119 #define cell_destroy(cp) DB_cell_destroy(cp)
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
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)) ;
139 #define d_to_i(d) ((int)d_to_I(d))
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)) ;
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)) ;
163 void PROTO( bozo, (char *) ) __attribute__ ((noreturn));
164 void PROTO( errmsg , (int, char*, ...) ) ;
165 void PROTO( compile_error, ( char *, ...) ) ;
167 void PROTO( execute, (INST *, CELL *, CELL *) ) ;
168 char *PROTO( find_kw_str, (int) ) ;
170 #ifdef HAVE_STRTOD_OVF_BUG
171 double PROTO(strtod_with_ovf_bug, (const char*, char**)) ;
172 #define strtod strtod_with_ovf_bug