| 1 |
/* |
| 2 |
* $LynxId: HTString.h,v 1.45 2025/01/08 00:30:50 tom Exp $ |
| 3 |
* String handling for libwww |
| 4 |
* STRINGS |
| 5 |
* |
| 6 |
* Case-independent string comparison and allocations with copies etc |
| 7 |
*/ |
| 8 |
#ifndef HTSTRING_H |
| 9 |
#define HTSTRING_H |
| 10 |
|
| 11 |
#ifndef HTUTILS_H |
| 12 |
#include <HTUtils.h> |
| 13 |
#endif /* HTUTILS_H */ |
| 14 |
|
| 15 |
#ifdef __cplusplus |
| 16 |
extern "C" { |
| 17 |
#endif |
| 18 |
extern const char *HTLibraryVersion; /* String for help screen etc */ |
| 19 |
|
| 20 |
/* |
| 21 |
* EBCDIC string comparison using ASCII collating sequence |
| 22 |
*/ |
| 23 |
#ifdef NOT_ASCII |
| 24 |
extern int AS_casecomp(const char *a, const char *b); |
| 25 |
extern int AS_ncmp(const char *a, const char *b, unsigned int n); |
| 26 |
|
| 27 |
#define AS_cmp( a, b ) ( AS_ncmp( ( a ), ( b ), -1 ) ) |
| 28 |
|
| 29 |
#else |
| 30 |
#define AS_casecomp( a, b ) ( strcasecomp( ( a ), ( b ) ) ) |
| 31 |
#define AS_ncmp( a, b, c ) ( StrNCmp( ( a ), ( b ), ( c ) ) ) |
| 32 |
#define AS_cmp strcmp |
| 33 |
|
| 34 |
#endif /* NOT_ASCII */ |
| 35 |
|
| 36 |
#define StrNCat(a,b,c) strncat((a),(b),(size_t)(c)) |
| 37 |
#define StrNCpy(a,b,c) strncpy((a),(b),(size_t)(c)) |
| 38 |
#define StrNCmp(a,b,c) strncmp((a),(b),(size_t)(c)) |
| 39 |
|
| 40 |
#define MemCpy(a,b,c) memcpy((a),(b),(size_t)(c)) |
| 41 |
#define MemCmp(a,b,c) memcmp((a),(b),(size_t)(c)) |
| 42 |
|
| 43 |
/* |
| 44 |
* Workaround for glibc header defect combined with -Wlogical-op warnings |
| 45 |
*/ |
| 46 |
#define StrChr (strchr) |
| 47 |
|
| 48 |
/* |
| 49 |
* Case-insensitive string comparison |
| 50 |
* |
| 51 |
* The usual routines (comp instead of cmp) had some problem. |
| 52 |
*/ |
| 53 |
extern int strcasecomp(const char *a, const char *b); |
| 54 |
extern int strncasecomp(const char *a, const char *b, int n); |
| 55 |
|
| 56 |
extern int strcasecomp8(const char *a, const char *b); |
| 57 |
extern int strncasecomp8(const char *a, const char *b, int n); |
| 58 |
|
| 59 |
extern int strcasecomp_asterisk(const char *a, const char *b); |
| 60 |
|
| 61 |
/* |
| 62 |
* strcasecomp8 and strncasecomp8 are variants of strcasecomp and |
| 63 |
* strncasecomp, but use 8bit upper/lower case information from the |
| 64 |
* current display charset |
| 65 |
*/ |
| 66 |
|
| 67 |
/* |
| 68 |
* Malloced string manipulation |
| 69 |
*/ |
| 70 |
#define StrAllocCopy(dest, src) HTSACopy (&(dest), src) |
| 71 |
#define StrAllocCat(dest, src) HTSACat (&(dest), src) |
| 72 |
extern char *HTSACopy(char **dest, const char *src); |
| 73 |
extern char *HTSACat(char **dest, const char *src); |
| 74 |
|
| 75 |
/* |
| 76 |
* optimized for heavily realloc'd strings in temp objects |
| 77 |
*/ |
| 78 |
#define StrAllocCopy_extra(dest, src) HTSACopy_extra (&(dest), src) |
| 79 |
#define FREE_extra(x) {if (x != NULL) {HTSAFree_extra(x); x = NULL;}} |
| 80 |
#define Clear_extra(x) {if (x != NULL) {*x = '\0';}} |
| 81 |
extern char *HTSACopy_extra(char **dest, const char *src); |
| 82 |
extern void HTSAFree_extra(char *s); |
| 83 |
|
| 84 |
/* |
| 85 |
* Next word or quoted string |
| 86 |
*/ |
| 87 |
extern char *HTNextField(char **pstr); |
| 88 |
|
| 89 |
/* A more general parser - kw */ |
| 90 |
extern char *HTNextTok(char **pstr, |
| 91 |
const char *delims, const char *bracks, char *found); |
| 92 |
|
| 93 |
extern char *HTSprintf(char **pstr, const char *fmt, ...) GCC_PRINTFLIKE(2,3); |
| 94 |
extern char *HTSprintf0(char **pstr, const char *fmt, ...) GCC_PRINTFLIKE(2,3); |
| 95 |
|
| 96 |
/* |
| 97 |
* Provide a way to check at runtime (LY_TEST_FMTS==1) or compile-time |
| 98 |
* (LY_TEST_FMTS==2) for the translated messages. |
| 99 |
*/ |
| 100 |
#ifndef LY_TEST_FMTS |
| 101 |
#define LY_TEST_FMTS 0 |
| 102 |
#endif |
| 103 |
|
| 104 |
#if LY_TEST_FMTS > 1 |
| 105 |
#define HT_FMT(expected,actual) expected |
| 106 |
#elif LY_TEST_FMTS > 0 |
| 107 |
extern const char *LYtextFmts(const char *s_expect, const char *s_actual); |
| 108 |
#define HT_FMT(expected,actual) LYtextFmts(expected,actual) |
| 109 |
#else |
| 110 |
#define HT_FMT(expected,actual) actual |
| 111 |
#endif |
| 112 |
|
| 113 |
/* |
| 114 |
* Use this macro for translatable-strings which are used as printf-formats. |
| 115 |
*/ |
| 116 |
#define LY_MSG(msg) HT_FMT(msg,gettext(msg)) |
| 117 |
|
| 118 |
#if defined(LY_FIND_LEAKS) /* private otherwise */ |
| 119 |
extern char *StrAllocVsprintf(char **pstr, |
| 120 |
size_t len, |
| 121 |
const char *fmt, |
| 122 |
va_list *ap); |
| 123 |
#endif |
| 124 |
|
| 125 |
#if defined(__CYGWIN__) |
| 126 |
#define USE_QUOTED_PARAMETER 2 /* single and double-quoting */ |
| 127 |
#elif defined(DOSPATH) |
| 128 |
#define USE_QUOTED_PARAMETER 1 /* double-quoting only */ |
| 129 |
#elif (defined(VMS) || defined(__EMX__)) |
| 130 |
#define USE_QUOTED_PARAMETER 0 /* no quoting */ |
| 131 |
#else |
| 132 |
#define USE_QUOTED_PARAMETER 2 /* single and double-quoting */ |
| 133 |
#endif |
| 134 |
|
| 135 |
#if USE_QUOTED_PARAMETER |
| 136 |
extern char *HTQuoteParameter(const char *parameter); |
| 137 |
extern void HTAddXpand(char **result, const char *command, int number, const char *parameter); |
| 138 |
|
| 139 |
#else |
| 140 |
#define HTQuoteParameter(parameter) parameter /* simplify ifdef'ing */ |
| 141 |
#define HTAddXpand(result,command,number,parameter) HTAddParam(result,command,number,parameter) |
| 142 |
#endif |
| 143 |
|
| 144 |
extern int HTCountCommandArgs(const char *command); |
| 145 |
extern void HTAddToCmd(char **result, const char *command, int number, const char *string); |
| 146 |
extern void HTAddParam(char **result, const char *command, int number, const char *parameter); |
| 147 |
extern void HTEndParam(char **result, const char *command, int number); |
| 148 |
|
| 149 |
/* Force an option, with leading blanks, to be appended without quoting them */ |
| 150 |
#define HTOptParam(result, command, number, parameter) HTSACat(result, parameter) |
| 151 |
|
| 152 |
/* Binary copy and concat */ |
| 153 |
typedef struct { |
| 154 |
char *str; |
| 155 |
int len; |
| 156 |
} bstring; |
| 157 |
|
| 158 |
extern void HTSABAlloc(bstring **dest, int len); |
| 159 |
extern void HTSABCopy(bstring **dest, const char *src, int len); |
| 160 |
extern void HTSABCopy0(bstring **dest, const char *src); |
| 161 |
extern void HTSABCat(bstring **dest, const char *src, int len); |
| 162 |
extern void HTSABCat0(bstring **dest, const char *src); |
| 163 |
extern BOOL HTSABEql(bstring *a, bstring *b); |
| 164 |
extern void HTSABFree(bstring **ptr); |
| 165 |
|
| 166 |
#define BStrLen(s) (((s) != NULL) ? (s)->len : 0) |
| 167 |
#define BStrData(s) (((s) != NULL) ? (s)->str : NULL) |
| 168 |
|
| 169 |
#define BINEQ(a,b) (HTSABEql(a,b)) /* like STREQ() */ |
| 170 |
|
| 171 |
#define isBEmpty(p) ((p) == NULL || BStrData(p) == NULL || BStrLen(p) == 0) |
| 172 |
|
| 173 |
#define BStrAlloc(d,n) HTSABAlloc( &(d), n) |
| 174 |
#define BStrCopy(d,s) HTSABCopy( &(d), BStrData(s), BStrLen(s)) |
| 175 |
#define BStrCopy0(d,s) HTSABCopy0( &(d), s) |
| 176 |
#define BStrCopy1(d,s,n) HTSABCopy( &(d), s, n) |
| 177 |
#define BStrCat(d,s) HTSABCat( &(d), BStrData(s), BStrLen(s)) |
| 178 |
#define BStrCat0(d,s) HTSABCat0( &(d), s) |
| 179 |
#define BStrFree(d) HTSABFree( &(d)) |
| 180 |
|
| 181 |
extern bstring *HTBprintf(bstring **pstr, const char *fmt, ...) GCC_PRINTFLIKE(2,3); |
| 182 |
|
| 183 |
extern void trace_bstring(bstring *data); |
| 184 |
extern void trace_bstring2(const char *text, int size); |
| 185 |
|
| 186 |
#ifdef __cplusplus |
| 187 |
} |
| 188 |
#endif |
| 189 |
#endif /* HTSTRING_H */ |