| 1 | /*  GNU SED, a batch stream editor. | 
|---|
| 2 | Copyright (C) 1998-2022 Free Software Foundation, Inc. | 
|---|
| 3 |  | 
|---|
| 4 | This program is free software; you can redistribute it and/or modify | 
|---|
| 5 | it under the terms of the GNU General Public License as published by | 
|---|
| 6 | the Free Software Foundation; either version 2, or (at your option) | 
|---|
| 7 | any later version. | 
|---|
| 8 |  | 
|---|
| 9 | This program is distributed in the hope that it will be useful, | 
|---|
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 12 | GNU General Public License for more details. | 
|---|
| 13 |  | 
|---|
| 14 | You should have received a copy of the GNU General Public License | 
|---|
| 15 | along with this program; If not, see <https://www.gnu.org/licenses/>. */ | 
|---|
| 16 |  | 
|---|
| 17 | #ifndef BASICDEFS_H | 
|---|
| 18 | #define BASICDEFS_H | 
|---|
| 19 |  | 
|---|
| 20 | #include <alloca.h> | 
|---|
| 21 | #include <wchar.h> | 
|---|
| 22 | #include <locale.h> | 
|---|
| 23 | #include <wctype.h> | 
|---|
| 24 | #include <stdbool.h> | 
|---|
| 25 |  | 
|---|
| 26 | #include <gettext.h> | 
|---|
| 27 | #define N_(String) gettext_noop(String) | 
|---|
| 28 | #define _(String) gettext(String) | 
|---|
| 29 |  | 
|---|
| 30 | /* type countT is used to keep track of line numbers, etc. */ | 
|---|
| 31 | typedef unsigned long countT; | 
|---|
| 32 |  | 
|---|
| 33 | #include "xalloc.h" | 
|---|
| 34 |  | 
|---|
| 35 | /* some basic definitions to avoid undue promulgating of  ugliness */ | 
|---|
| 36 | #define REALLOC(x,n,t)   ((t *)xnrealloc((void *)(x),(n),sizeof(t))) | 
|---|
| 37 | #define MEMDUP(x,n,t)    ((t *)xmemdup((x),(n)*sizeof(t))) | 
|---|
| 38 | #define OB_MALLOC(o,n,t) ((t *)(void *)obstack_alloc(o,(n)*sizeof(t))) | 
|---|
| 39 |  | 
|---|
| 40 | #define obstack_chunk_alloc  xzalloc | 
|---|
| 41 | #define obstack_chunk_free   free | 
|---|
| 42 |  | 
|---|
| 43 | #define STREQ(a, b) (strcmp (a, b) == 0) | 
|---|
| 44 | #define STREQ_LEN(a, b, n) (strncmp (a, b, n) == 0) | 
|---|
| 45 | #define STRPREFIX(a, b) (strncmp (a, b, strlen (b)) == 0) | 
|---|
| 46 |  | 
|---|
| 47 | /* MAX_PATH is not defined in some platforms, most notably GNU/Hurd. | 
|---|
| 48 | In that case we define it here to some constant.  Note however that | 
|---|
| 49 | this relies in the fact that sed does reallocation if a buffer | 
|---|
| 50 | needs to be larger than PATH_MAX.  */ | 
|---|
| 51 | #ifndef PATH_MAX | 
|---|
| 52 | # define PATH_MAX 200 | 
|---|
| 53 | #endif | 
|---|
| 54 |  | 
|---|
| 55 | /* handle misdesigned <ctype.h> macros (snarfed from lib/regex.c) */ | 
|---|
| 56 | /* Jim Meyering writes: | 
|---|
| 57 |  | 
|---|
| 58 | "... Some ctype macros are valid only for character codes that | 
|---|
| 59 | isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when | 
|---|
| 60 | using /bin/cc or gcc but without giving an ansi option).  So, all | 
|---|
| 61 | ctype uses should be through macros like ISPRINT...  If | 
|---|
| 62 | STDC_HEADERS is defined, then autoconf has verified that the ctype | 
|---|
| 63 | macros don't need to be guarded with references to isascii. ... | 
|---|
| 64 | Defining isascii to 1 should let any compiler worth its salt | 
|---|
| 65 | eliminate the && through constant folding." | 
|---|
| 66 | Solaris defines some of these symbols so we must undefine them first. */ | 
|---|
| 67 |  | 
|---|
| 68 | #undef ISASCII | 
|---|
| 69 | #if defined STDC_HEADERS || (!defined isascii && !defined HAVE_ISASCII) | 
|---|
| 70 | # define ISASCII(c) 1 | 
|---|
| 71 | #else | 
|---|
| 72 | # define ISASCII(c) isascii(c) | 
|---|
| 73 | #endif | 
|---|
| 74 |  | 
|---|
| 75 | #if defined isblank || defined HAVE_ISBLANK | 
|---|
| 76 | # define ISBLANK(c) (ISASCII (c) && isblank (c)) | 
|---|
| 77 | #else | 
|---|
| 78 | # define ISBLANK(c) ((c) == ' ' || (c) == '\t') | 
|---|
| 79 | #endif | 
|---|
| 80 |  | 
|---|
| 81 | #undef ISPRINT | 
|---|
| 82 | #define ISPRINT(c) (ISASCII (c) && isprint (c)) | 
|---|
| 83 | #define ISDIGIT(c) (ISASCII (c) && isdigit ((unsigned char) (c))) | 
|---|
| 84 | #define ISALNUM(c) (ISASCII (c) && isalnum (c)) | 
|---|
| 85 | #define ISALPHA(c) (ISASCII (c) && isalpha (c)) | 
|---|
| 86 | #define ISCNTRL(c) (ISASCII (c) && iscntrl (c)) | 
|---|
| 87 | #define ISLOWER(c) (ISASCII (c) && islower (c)) | 
|---|
| 88 | #define ISPUNCT(c) (ISASCII (c) && ispunct (c)) | 
|---|
| 89 | #define ISSPACE(c) (ISASCII (c) && isspace (c)) | 
|---|
| 90 | #define ISUPPER(c) (ISASCII (c) && isupper (c)) | 
|---|
| 91 | #define ISXDIGIT(c) (ISASCII (c) && isxdigit (c)) | 
|---|
| 92 |  | 
|---|
| 93 | #ifndef initialize_main | 
|---|
| 94 | # ifdef __EMX__ | 
|---|
| 95 | #  define initialize_main(argcp, argvp) \ | 
|---|
| 96 | { _response (argcp, argvp); _wildcard (argcp, argvp); } | 
|---|
| 97 | # else /* NOT __EMX__ */ | 
|---|
| 98 | #  define initialize_main(argcp, argvp) | 
|---|
| 99 | # endif | 
|---|
| 100 | #endif | 
|---|
| 101 |  | 
|---|
| 102 | #endif /*!BASICDEFS_H*/ | 
|---|