diff options
Diffstat (limited to 'awk.h')
-rw-r--r-- | awk.h | 124 |
1 files changed, 71 insertions, 53 deletions
@@ -95,13 +95,11 @@ extern int errno; #include "missing_d/gawkbool.h" #endif -#include "mbsupport.h" /* defines MBS_SUPPORT */ - -#if MBS_SUPPORT /* We can handle multibyte strings. */ #include <wchar.h> #include <wctype.h> -#endif + +#include "mbsupport.h" /* defines stuff for DJGPP to fake MBS */ #ifdef STDC_HEADERS #include <float.h> @@ -395,10 +393,8 @@ typedef struct exp_node { size_t slen; long sref; int idx; -#if MBS_SUPPORT wchar_t *wsp; size_t wslen; -#endif } val; } sub; NODETYPE type; @@ -534,6 +530,11 @@ typedef struct exp_node { #define adepth sub.nodep.l.ll #define alevel sub.nodep.x.xl +/* Op_comment */ +#define comment_type sub.val.idx +#define EOL_COMMENT 1 +#define FULL_COMMENT 2 + /* --------------------------------lint warning types----------------------------*/ typedef enum lintvals { LINT_illegal, @@ -1105,11 +1106,7 @@ extern int exit_val; #define do_lint (do_flags & (DO_LINT_INVALID|DO_LINT_ALL)) #define do_lint_old (do_flags & DO_LINT_OLD) #endif -#if MBS_SUPPORT extern int gawk_mb_cur_max; -#else -#define gawk_mb_cur_max (1) -#endif #if defined (HAVE_GETGROUPS) && defined(NGROUPS_MAX) && NGROUPS_MAX > 0 extern GETGROUPS_T *groupset; @@ -1254,46 +1251,11 @@ DEREF(NODE *r) #define cant_happen() r_fatal("internal error line %d, file: %s", \ __LINE__, __FILE__) -#define emalloc(var,ty,x,str) (void)((var=(ty)malloc((size_t)(x))) ||\ - (fatal(_("%s: %s: can't allocate %ld bytes of memory (%s)"),\ - (str), #var, (long) (x), strerror(errno)),0)) -#define erealloc(var,ty,x,str) (void)((var = (ty)realloc((char *)var, (size_t)(x))) \ - ||\ - (fatal(_("%s: %s: can't allocate %ld bytes of memory (%s)"),\ - (str), #var, (long) (x), strerror(errno)),0)) +#define emalloc(var,ty,x,str) (void) (var = (ty) emalloc_real((size_t)(x), str, #var, __FILE__, __LINE__)) +#define erealloc(var,ty,x,str) (void) (var = (ty) erealloc_real((void *) var, (size_t)(x), str, #var, __FILE__, __LINE__)) #define efree(p) free(p) -static inline NODE * -force_string(NODE *s) -{ - if ((s->flags & STRCUR) != 0 - && (s->stfmt == -1 || s->stfmt == CONVFMTidx) - ) - return s; - return format_val(CONVFMT, CONVFMTidx, s); -} - -#ifdef GAWKDEBUG -#define unref r_unref -#define force_number str2number -#else /* not GAWKDEBUG */ - -static inline void -unref(NODE *r) -{ - if (r != NULL && --r->valref <= 0) - r_unref(r); -} - -static inline NODE * -force_number(NODE *n) -{ - return (n->flags & NUMCUR) ? n : str2number(n); -} - -#endif /* GAWKDEBUG */ - #define fatal set_loc(__FILE__, __LINE__), r_fatal extern jmp_buf fatal_tag; @@ -1419,10 +1381,8 @@ extern NODE *do_dcgettext(int nargs); extern NODE *do_dcngettext(int nargs); extern NODE *do_bindtextdomain(int nargs); extern NODE *do_div(int nargs); -#if MBS_SUPPORT extern int strncasecmpmbs(const unsigned char *, const unsigned char *, size_t); -#endif /* eval.c */ extern void PUSH_CODE(INSTRUCTION *cp); extern INSTRUCTION *POP_CODE(void); @@ -1608,7 +1568,6 @@ extern NODE *r_dupnode(NODE *n); extern NODE *make_str_node(const char *s, size_t len, int flags); extern void *more_blocks(int id); extern int parse_escape(const char **string_ptr); -#if MBS_SUPPORT extern NODE *str2wstr(NODE *n, size_t **ptr); extern NODE *wstr2str(NODE *n); #define force_wstring(n) str2wstr(n, NULL) @@ -1622,9 +1581,6 @@ extern wint_t btowc_cache[]; #define btowc_cache(x) btowc_cache[(x)&0xFF] extern void init_btowc_cache(); #define is_valid_character(b) (btowc_cache[(b)&0xFF] != WEOF) -#else -#define free_wstr(NODE) /* empty */ -#endif /* re.c */ extern Regexp *make_regexp(const char *s, size_t len, bool ignorecase, bool dfa, bool canfatal); extern int research(Regexp *rp, char *str, int start, size_t len, int flags); @@ -1793,3 +1749,65 @@ dupnode(NODE *n) return r_dupnode(n); } #endif + +static inline NODE * +force_string(NODE *s) +{ + if ((s->flags & STRCUR) != 0 + && (s->stfmt == -1 || s->stfmt == CONVFMTidx) + ) + return s; + return format_val(CONVFMT, CONVFMTidx, s); +} + +#ifdef GAWKDEBUG +#define unref r_unref +#define force_number str2number +#else /* not GAWKDEBUG */ + +static inline void +unref(NODE *r) +{ + if (r != NULL && --r->valref <= 0) + r_unref(r); +} + +static inline NODE * +force_number(NODE *n) +{ + return (n->flags & NUMCUR) ? n : str2number(n); +} + +#endif /* GAWKDEBUG */ + +static inline void * +emalloc_real(size_t count, const char *where, const char *var, const char *file, int line) +{ + void *ret; + + if (count == 0) + fatal("%s:%d: emalloc called with zero bytes", file, line); + + ret = (void *) malloc(count); + if (ret == NULL) + fatal(_("%s:%d:%s: %s: can't allocate %ld bytes of memory (%s)"), + file, line, where, var, (long) count, strerror(errno)); + + return ret; +} + +static inline void * +erealloc_real(void *ptr, size_t count, const char *where, const char *var, const char *file, int line) +{ + void *ret; + + if (count == 0) + fatal("%s:%d: erealloc called with zero bytes", file, line); + + ret = (void *) realloc(ptr, count); + if (ret == NULL) + fatal(_("%s:%d:%s: %s: can't reallocate %ld bytes of memory (%s)"), + file, line, where, var, (long) count, strerror(errno)); + + return ret; +} |