1 /******************************************** 2 types.h 3 copyright 2009-2014,2016 Thomas E. Dickey 4 copyright 1991-1993,2014 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 * $MawkId: types.h,v 1.13 2016/09/27 00:59:29 tom Exp $ 15 */ 16 17 /* types.h */ 18 19 #ifndef MAWK_TYPES_H 20 #define MAWK_TYPES_H 21 22 #include "nstd.h" 23 #include "sizes.h" 24 25 /* CELL types */ 26 27 typedef enum { 28 C_NOINIT 29 ,C_DOUBLE 30 ,C_STRING 31 ,C_STRNUM 32 ,C_MBSTRN /*could be STRNUM, has not been checked */ 33 ,C_RE 34 ,C_SPACE /* split on space */ 35 ,C_SNULL /* split on the empty string */ 36 ,C_REPL /* a replacement string '\&' changed to & */ 37 ,C_REPLV /* a vector replacement -- broken on & */ 38 ,NUM_CELL_TYPES 39 } MAWK_CELL_TYPES; 40 41 /* these defines are used to check types for two 42 CELLs which are adjacent in memory */ 43 44 #define TWO_NOINITS (2*(1<<C_NOINIT)) 45 #define TWO_DOUBLES (2*(1<<C_DOUBLE)) 46 #define TWO_STRINGS (2*(1<<C_STRING)) 47 #define TWO_STRNUMS (2*(1<<C_STRNUM)) 48 #define TWO_MBSTRNS (2*(1<<C_MBSTRN)) 49 #define NOINIT_AND_DOUBLE ((1<<C_NOINIT)+(1<<C_DOUBLE)) 50 #define NOINIT_AND_STRING ((1<<C_NOINIT)+(1<<C_STRING)) 51 #define NOINIT_AND_STRNUM ((1<<C_NOINIT)+(1<<C_STRNUM)) 52 #define DOUBLE_AND_STRING ((1<<C_DOUBLE)+(1<<C_STRING)) 53 #define DOUBLE_AND_STRNUM ((1<<C_STRNUM)+(1<<C_DOUBLE)) 54 #define STRING_AND_STRNUM ((1<<C_STRING)+(1<<C_STRNUM)) 55 #define NOINIT_AND_MBSTRN ((1<<C_NOINIT)+(1<<C_MBSTRN)) 56 #define DOUBLE_AND_MBSTRN ((1<<C_DOUBLE)+(1<<C_MBSTRN)) 57 #define STRING_AND_MBSTRN ((1<<C_STRING)+(1<<C_MBSTRN)) 58 #define STRNUM_AND_MBSTRN ((1<<C_STRNUM)+(1<<C_MBSTRN)) 59 60 typedef unsigned char UChar; 61 62 typedef struct { 63 size_t len; 64 unsigned ref_cnt; 65 char str[2]; 66 } STRING; 67 68 /* number of bytes more than the characters to store a 69 string */ 70 #define STRING_OH (sizeof(STRING)-1) 71 72 typedef unsigned short VCount; 73 74 typedef struct cell { 75 short type; 76 VCount vcnt; /* only used if type == C_REPLV */ 77 PTR ptr; 78 double dval; 79 } CELL; 80 81 /* all builtins are passed the evaluation stack pointer and 82 return its new value, here is the type */ 83 typedef CELL *(*PF_CP) (CELL *); 84 85 /* an element of code (instruction) */ 86 typedef union { 87 int op; 88 PTR ptr; 89 } INST; 90 91 /* regex types */ 92 typedef int SType; 93 typedef size_t SLen; 94 95 #endif /* MAWK_TYPES_H */ 96