| 1 |
/* |
| 2 |
* $LynxId: HTUtils.h,v 1.141 2025/07/22 00:18:23 tom Exp $ |
| 3 |
* |
| 4 |
* Utility macros for the W3 code library |
| 5 |
* MACROS FOR GENERAL USE |
| 6 |
* |
| 7 |
* See also: the system dependent file "www_tcp.h", which is included here. |
| 8 |
*/ |
| 9 |
|
| 10 |
#ifndef NO_LYNX_TRACE |
| 11 |
#define DEBUG /* Turns on trace; turn off for smaller binary */ |
| 12 |
#endif |
| 13 |
|
| 14 |
#ifndef HTUTILS_H |
| 15 |
#define HTUTILS_H |
| 16 |
|
| 17 |
#ifdef HAVE_CONFIG_H |
| 18 |
#include <lynx_cfg.h> /* generated by autoconf 'configure' script */ |
| 19 |
|
| 20 |
#ifdef HAVE_STDNORETURN_H |
| 21 |
#include <stdnoreturn.h> |
| 22 |
#undef GCC_NORETURN |
| 23 |
#define GCC_NORETURN _Noreturn |
| 24 |
#endif |
| 25 |
|
| 26 |
/* see AC_FUNC_ALLOCA macro */ |
| 27 |
#ifdef __GNUC__ |
| 28 |
# define alloca(size) __builtin_alloca(size) |
| 29 |
#else |
| 30 |
# ifdef _MSC_VER |
| 31 |
# include <malloc.h> |
| 32 |
# ifndef alloca |
| 33 |
# define alloca(size) _alloca(size) |
| 34 |
# endif |
| 35 |
# else |
| 36 |
# if HAVE_ALLOCA_H |
| 37 |
# include <alloca.h> |
| 38 |
# else |
| 39 |
# ifdef _AIX |
| 40 |
#pragma alloca |
| 41 |
# else |
| 42 |
# ifndef alloca /* predefined by HP cc +Olibcalls */ |
| 43 |
char *alloca(); |
| 44 |
|
| 45 |
# endif |
| 46 |
# endif |
| 47 |
# endif |
| 48 |
# endif |
| 49 |
#endif |
| 50 |
|
| 51 |
#include <sys/types.h> |
| 52 |
#include <stdio.h> |
| 53 |
|
| 54 |
#else /* HAVE_CONFIG_H */ |
| 55 |
|
| 56 |
#ifdef DJGPP |
| 57 |
#include <sys/config.h> /* pseudo-autoconf values for DJGPP libc/headers */ |
| 58 |
#define HAVE_TRUNCATE 1 |
| 59 |
#define HAVE_ALLOCA 1 |
| 60 |
#include <limits.h> |
| 61 |
#endif /* DJGPP */ |
| 62 |
|
| 63 |
#include <sys/types.h> |
| 64 |
#include <stdio.h> |
| 65 |
|
| 66 |
/* Explicit system-configure */ |
| 67 |
#ifdef VMS |
| 68 |
#define NO_SIZECHANGE |
| 69 |
|
| 70 |
#if defined(VAXC) && !defined(__DECC) |
| 71 |
#define NO_UNISTD_H /* DEC C has unistd.h, but not VAX C */ |
| 72 |
#endif |
| 73 |
|
| 74 |
#define NO_KEYPAD |
| 75 |
#define NO_UTMP |
| 76 |
|
| 77 |
#undef NO_FILIO_H |
| 78 |
#define NO_FILIO_H |
| 79 |
|
| 80 |
#define NOUSERS |
| 81 |
#define DISP_PARTIAL /* experimental */ |
| 82 |
#endif |
| 83 |
|
| 84 |
#if defined(VMS) || defined(_WINDOWS) |
| 85 |
#define HAVE_STDLIB_H 1 |
| 86 |
#endif |
| 87 |
|
| 88 |
/* Accommodate non-autoconf'd Makefile's (VMS, DJGPP, etc) */ |
| 89 |
|
| 90 |
#ifndef NO_ARPA_INET_H |
| 91 |
#define HAVE_ARPA_INET_H 1 |
| 92 |
#endif |
| 93 |
|
| 94 |
#ifndef NO_CBREAK |
| 95 |
#define HAVE_CBREAK 1 |
| 96 |
#endif |
| 97 |
|
| 98 |
#ifndef NO_CUSERID |
| 99 |
#define HAVE_CUSERID 1 |
| 100 |
#endif |
| 101 |
|
| 102 |
#ifndef NO_FILIO_H |
| 103 |
#define HAVE_SYS_FILIO_H 1 |
| 104 |
#endif |
| 105 |
|
| 106 |
#ifndef NO_GETCWD |
| 107 |
#define HAVE_GETCWD 1 |
| 108 |
#endif |
| 109 |
|
| 110 |
#ifndef USE_SLANG |
| 111 |
#ifndef NO_KEYPAD |
| 112 |
#define HAVE_KEYPAD 1 |
| 113 |
#endif |
| 114 |
#ifndef NO_TTYTYPE |
| 115 |
#define HAVE_TTYTYPE 1 |
| 116 |
#endif |
| 117 |
#endif /* USE_SLANG */ |
| 118 |
|
| 119 |
#ifndef NO_PUTENV |
| 120 |
#define HAVE_PUTENV 1 |
| 121 |
#endif |
| 122 |
|
| 123 |
#if !defined(NO_SIZECHANGE) && defined(UNIX) |
| 124 |
#define HAVE_SIZECHANGE 1 |
| 125 |
#endif |
| 126 |
|
| 127 |
#ifndef NO_UNISTD_H |
| 128 |
#undef HAVE_UNISTD_H |
| 129 |
#define HAVE_UNISTD_H 1 |
| 130 |
#endif |
| 131 |
|
| 132 |
#ifndef NO_UTMP |
| 133 |
#define HAVE_UTMP 1 |
| 134 |
#endif |
| 135 |
|
| 136 |
#endif /* HAVE_CONFIG_H */ |
| 137 |
|
| 138 |
#include <assert.h> |
| 139 |
|
| 140 |
/* suppress inadvertent use of gettext in makeuctb when cross-compiling */ |
| 141 |
#ifdef DONT_USE_GETTEXT |
| 142 |
#undef HAVE_GETTEXT |
| 143 |
#undef HAVE_LIBINTL_H |
| 144 |
#endif |
| 145 |
|
| 146 |
#ifndef HAVE_ICONV |
| 147 |
#undef USE_JAPANESEUTF8_SUPPORT |
| 148 |
#endif |
| 149 |
|
| 150 |
#ifndef lynx_srand |
| 151 |
#define lynx_srand srand |
| 152 |
#endif |
| 153 |
|
| 154 |
#ifndef lynx_rand |
| 155 |
#define lynx_rand rand |
| 156 |
#endif |
| 157 |
|
| 158 |
#if '0' != 48 |
| 159 |
#define NOT_ASCII |
| 160 |
#endif |
| 161 |
|
| 162 |
#if '0' == 240 |
| 163 |
#define EBCDIC |
| 164 |
#endif |
| 165 |
|
| 166 |
#ifndef LY_MAXPATH |
| 167 |
#define LY_MAXPATH 256 |
| 168 |
#endif |
| 169 |
|
| 170 |
#ifndef GCC_NORETURN |
| 171 |
#define GCC_NORETURN /* nothing */ |
| 172 |
#endif |
| 173 |
|
| 174 |
#ifndef GCC_UNUSED |
| 175 |
#define GCC_UNUSED /* nothing */ |
| 176 |
#endif |
| 177 |
|
| 178 |
#if defined(__GNUC__) && defined(_FORTIFY_SOURCE) |
| 179 |
#define USE_IGNORE_RC |
| 180 |
extern int ignore_unused; |
| 181 |
|
| 182 |
#define IGNORE_RC(func) ignore_unused = (int) func |
| 183 |
#else |
| 184 |
#define IGNORE_RC(func) (void) func |
| 185 |
#endif /* gcc workarounds */ |
| 186 |
|
| 187 |
#if defined(__CYGWIN32__) && ! defined(__CYGWIN__) |
| 188 |
#define __CYGWIN__ 1 |
| 189 |
#endif |
| 190 |
|
| 191 |
#if defined(__CYGWIN__) /* 1998/12/31 (Thu) 16:13:46 */ |
| 192 |
#ifdef USE_OPENSSL_INCL |
| 193 |
#define NOCRYPT /* workaround for openssl 1.0.1e bug */ |
| 194 |
#endif |
| 195 |
#include <windows.h> /* #include "windef.h" */ |
| 196 |
#define BOOLEAN_DEFINED |
| 197 |
#undef HAVE_POPEN /* FIXME: does this not work, or is it missing */ |
| 198 |
#undef small /* see <w32api/rpcndr.h> */ |
| 199 |
#endif |
| 200 |
|
| 201 |
#if defined(__DARWIN_NO_LONG_LONG) |
| 202 |
#undef HAVE_ATOLL |
| 203 |
#endif |
| 204 |
|
| 205 |
#if defined(HAVE_ATOLL) |
| 206 |
#define LYatoll(n) atoll(n) |
| 207 |
#else |
| 208 |
extern off_t LYatoll(const char *value); |
| 209 |
#endif |
| 210 |
|
| 211 |
/* cygwin, mingw32, etc. */ |
| 212 |
#ifdef FILE_DOES_NOT_EXIST |
| 213 |
#undef FILE_DOES_NOT_EXIST /* see <w32api/winnt.h> */ |
| 214 |
#endif |
| 215 |
|
| 216 |
/* |
| 217 |
* VS .NET 2003 includes winsock.h unconditionally from windows.h, |
| 218 |
* so we do not want to include windows.h if we want winsock2.h |
| 219 |
*/ |
| 220 |
#if defined(_WINDOWS) && !defined(__CYGWIN__) |
| 221 |
|
| 222 |
#ifndef __GNUC__ |
| 223 |
#pragma warning (disable : 4100) /* unreferenced formal parameter */ |
| 224 |
#pragma warning (disable : 4127) /* conditional expression is constant */ |
| 225 |
#pragma warning (disable : 4201) /* nameless struct/union */ |
| 226 |
#pragma warning (disable : 4214) /* bit field types other than int */ |
| 227 |
#pragma warning (disable : 4310) /* cast truncates constant value */ |
| 228 |
#pragma warning (disable : 4514) /* unreferenced inline function has been removed */ |
| 229 |
#pragma warning (disable : 4996) /* This function or variable may be unsafe. ... */ |
| 230 |
#endif |
| 231 |
|
| 232 |
#if defined(USE_WINSOCK2_H) && (_MSC_VER >= 1300) && (_MSC_VER < 1400) |
| 233 |
#include <winsock2.h> /* includes windows.h, in turn windef.h */ |
| 234 |
#else |
| 235 |
#include <windows.h> /* #include "windef.h" */ |
| 236 |
#endif |
| 237 |
|
| 238 |
#define BOOLEAN_DEFINED |
| 239 |
|
| 240 |
#if !_WIN_CC /* 1999/09/29 (Wed) 22:00:53 */ |
| 241 |
#include <dos.h> |
| 242 |
#endif |
| 243 |
|
| 244 |
#if defined(DECL_SLEEP) && defined(HAVE_CONFIG_H) |
| 245 |
# undef sleep |
| 246 |
# if defined(__MINGW32__) |
| 247 |
# define sleep(n) Sleep((n)*100) |
| 248 |
# else |
| 249 |
extern void sleep(unsigned __seconds); |
| 250 |
# endif |
| 251 |
#elif !defined(__MINGW32__) |
| 252 |
# undef sleep |
| 253 |
extern void sleep(unsigned __seconds); |
| 254 |
#endif |
| 255 |
|
| 256 |
#define popen _popen |
| 257 |
#define pclose _pclose |
| 258 |
|
| 259 |
#if defined(_MSC_VER) && (_MSC_VER > 0) |
| 260 |
typedef unsigned short mode_t; |
| 261 |
#endif |
| 262 |
|
| 263 |
#endif /* _WINDOWS */ |
| 264 |
|
| 265 |
#if defined(USE_DEFAULT_COLORS) && !defined(HAVE_USE_DEFAULT_COLORS) |
| 266 |
/* if we don't have use_default_colors() */ |
| 267 |
# undef USE_DEFAULT_COLORS |
| 268 |
#endif |
| 269 |
|
| 270 |
#ifndef USE_COLOR_STYLE |
| 271 |
/* it's useless for such setup */ |
| 272 |
# define NO_EMPTY_HREFLESS_A |
| 273 |
#endif |
| 274 |
|
| 275 |
#if defined(__EMX__) || defined(WIN_EX) || defined(HAVE_POPEN) |
| 276 |
# define CAN_CUT_AND_PASTE |
| 277 |
#endif |
| 278 |
|
| 279 |
#if defined(USE_SLANG) || (defined(USE_COLOR_STYLE) && defined(__EMX__)) |
| 280 |
# define USE_BLINK |
| 281 |
#endif |
| 282 |
|
| 283 |
#if defined(DOSPATH) || defined(__EMX__) |
| 284 |
# define USE_DOS_DRIVES /* we allow things like "c:" in paths */ |
| 285 |
#endif |
| 286 |
|
| 287 |
#if defined(UNIX) |
| 288 |
# if (defined(__BEOS__) || defined(__CYGWIN__) || defined(__DJGPP__) || defined(__EMX__) || defined(__MINGW32__)) |
| 289 |
# define SINGLE_USER_UNIX /* well, at least they try */ |
| 290 |
# else |
| 291 |
# define MULTI_USER_UNIX |
| 292 |
# endif |
| 293 |
#endif |
| 294 |
|
| 295 |
/* |
| 296 |
|
| 297 |
ERROR TYPE |
| 298 |
|
| 299 |
This is passed back when streams are aborted. It might be nice to have some structure |
| 300 |
of error messages, numbers, and recursive pointers to reasons. Currently this is a |
| 301 |
placeholder for something more sophisticated. |
| 302 |
|
| 303 |
*/ |
| 304 |
typedef void *HTError; /* Unused at present -- best definition? */ |
| 305 |
|
| 306 |
/* |
| 307 |
|
| 308 |
Standard C library for malloc() etc |
| 309 |
|
| 310 |
*/ |
| 311 |
#ifdef HAVE_STDLIB_H |
| 312 |
#include <stdlib.h> |
| 313 |
#endif |
| 314 |
|
| 315 |
#ifndef EXIT_SUCCESS |
| 316 |
#define EXIT_SUCCESS 0 |
| 317 |
#endif |
| 318 |
|
| 319 |
#ifndef EXIT_FAILURE |
| 320 |
#define EXIT_FAILURE 1 |
| 321 |
#endif |
| 322 |
|
| 323 |
#ifdef __EMX__ |
| 324 |
#include <unistd.h> /* should be re-include protected under EMX */ |
| 325 |
#define getcwd _getcwd2 |
| 326 |
#define chdir _chdir2 |
| 327 |
#endif |
| 328 |
|
| 329 |
#ifdef vax |
| 330 |
#ifdef unix |
| 331 |
#define ultrix /* Assume vax+unix=ultrix */ |
| 332 |
#endif /* unix */ |
| 333 |
#endif /* vax */ |
| 334 |
|
| 335 |
#ifndef VMS |
| 336 |
#ifndef ultrix |
| 337 |
|
| 338 |
#ifdef NeXT |
| 339 |
#include <libc.h> /* NeXT */ |
| 340 |
#endif /* NeXT */ |
| 341 |
|
| 342 |
#else /* ultrix: */ |
| 343 |
|
| 344 |
#include <malloc.h> |
| 345 |
#include <memory.h> |
| 346 |
|
| 347 |
#endif /* !ultrix */ |
| 348 |
#else /* VMS: */ |
| 349 |
|
| 350 |
#include <unixlib.h> |
| 351 |
#if defined(VAXC) && !defined(__DECC) |
| 352 |
#define malloc VAXC$MALLOC_OPT |
| 353 |
#define calloc VAXC$CALLOC_OPT |
| 354 |
#define free VAXC$FREE_OPT |
| 355 |
#define cfree VAXC$CFREE_OPT |
| 356 |
#define realloc VAXC$REALLOC_OPT |
| 357 |
#endif /* VAXC && !__DECC */ |
| 358 |
|
| 359 |
#endif /* !VMS */ |
| 360 |
|
| 361 |
#ifndef NULL |
| 362 |
#define NULL ((void *)0) |
| 363 |
#endif |
| 364 |
|
| 365 |
#define DeConst(p) (void *)(intptr_t)(p) |
| 366 |
|
| 367 |
#define isEmpty(s) ((s) == NULL || *(s) == 0) |
| 368 |
#define isEmptyS(s) ((s) == NULL || *(s) == NULL) |
| 369 |
#define non_empty(s) !isEmpty(s) |
| 370 |
#define non_emptyS(s) !isEmptyS(s) |
| 371 |
|
| 372 |
#define NonNull(s) (((s) != NULL) ? s : "") |
| 373 |
#define NONNULL(s) (((s) != NULL) ? s : "(null)") |
| 374 |
|
| 375 |
/* array/table size */ |
| 376 |
#define TABLESIZE(v) (sizeof(v)/sizeof(v[0])) |
| 377 |
|
| 378 |
#define typecalloc(cast) (cast *)calloc((size_t)1, sizeof(cast)) |
| 379 |
#define typecallocn(cast,ntypes) (cast *)calloc((size_t)(ntypes),sizeof(cast)) |
| 380 |
|
| 381 |
#define typeRealloc(cast,ptr,ntypes) (cast *)realloc(ptr, (size_t)(ntypes)*sizeof(cast)) |
| 382 |
|
| 383 |
#define typeMalloc(cast) (cast *)malloc(sizeof(cast)) |
| 384 |
#define typeMallocn(cast,ntypes) (cast *)malloc((size_t)(ntypes)*sizeof(cast)) |
| 385 |
|
| 386 |
/* |
| 387 |
|
| 388 |
OFTEN USED INTEGER MACROS |
| 389 |
|
| 390 |
Min and Max functions |
| 391 |
|
| 392 |
*/ |
| 393 |
#ifndef HTMIN |
| 394 |
#define HTMIN(a,b) ((a) <= (b) ? (a) : (b)) |
| 395 |
#define HTMAX(a,b) ((a) >= (b) ? (a) : (b)) |
| 396 |
#endif |
| 397 |
/* |
| 398 |
|
| 399 |
Booleans |
| 400 |
|
| 401 |
*/ |
| 402 |
/* Note: GOOD and BAD are already defined (differently) on RS6000 aix */ |
| 403 |
/* #define GOOD(status) ((status)38;1) VMS style status: test bit 0 */ |
| 404 |
/* #define BAD(status) (!GOOD(status)) Bit 0 set if OK, otherwise clear */ |
| 405 |
|
| 406 |
#ifndef _WINDOWS |
| 407 |
#ifndef BOOLEAN_DEFINED |
| 408 |
typedef char BOOLEAN; /* Logical value */ |
| 409 |
|
| 410 |
#ifndef CURSES |
| 411 |
#ifndef TRUE |
| 412 |
#define TRUE (BOOLEAN)1 |
| 413 |
#define FALSE (BOOLEAN)0 |
| 414 |
#endif |
| 415 |
#endif /* CURSES */ |
| 416 |
#endif /* BOOLEAN_DEFINED */ |
| 417 |
#define BOOLEAN_DEFINED |
| 418 |
#endif /* _WINDOWS */ |
| 419 |
|
| 420 |
#if defined(_MSC_VER) && (_MSC_VER >= 1300) |
| 421 |
/* it declares BOOL/BOOLEAN as BYTE/int */ |
| 422 |
#else |
| 423 |
#ifndef BOOL |
| 424 |
#define BOOL BOOLEAN |
| 425 |
#endif |
| 426 |
#endif |
| 427 |
|
| 428 |
#ifndef YES |
| 429 |
#define YES (BOOLEAN)1 |
| 430 |
#define NO (BOOLEAN)0 |
| 431 |
#endif |
| 432 |
|
| 433 |
#define STRING1PTR const char * |
| 434 |
#define STRING2PTR const char * const * |
| 435 |
|
| 436 |
extern BOOL LYOutOfMemory; /* Declared in LYexit.c - FM */ |
| 437 |
|
| 438 |
#define TCP_PORT 80 /* Allocated to http by Jon Postel/ISI 24-Jan-92 */ |
| 439 |
#define OLD_TCP_PORT 2784 /* Try the old one if no answer on 80 */ |
| 440 |
#define DNP_OBJ 80 /* This one doesn't look busy, but we must check */ |
| 441 |
/* That one was for decnet */ |
| 442 |
|
| 443 |
/* Inline Function WHITE: Is character c white space? */ |
| 444 |
/* For speed, include all control characters */ |
| 445 |
|
| 446 |
#define WHITE(c) ((UCH(TOASCII(c))) <= 32) |
| 447 |
|
| 448 |
/* Inline Function LYIsASCII: Is character c a traditional ASCII |
| 449 |
* character (i.e. <128) after converting from host character set. */ |
| 450 |
|
| 451 |
#define LYIsASCII(c) (TOASCII(UCH(c)) < 128) |
| 452 |
|
| 453 |
/* |
| 454 |
|
| 455 |
Success (>=0) and failure (<0) codes |
| 456 |
|
| 457 |
Some of the values are chosen to be HTTP-like, but status return values |
| 458 |
are generally not the response status from any specific protocol. |
| 459 |
|
| 460 |
*/ |
| 461 |
|
| 462 |
#define HT_PARSER_OTHER_CONTENT 701 /* tells SGML to change content model */ |
| 463 |
#define HT_PARSER_REOPEN_ELT 700 /* tells SGML parser to keep tag open */ |
| 464 |
#define HT_REDIRECTING 399 |
| 465 |
#define HT_PARTIAL_CONTENT 206 /* Partial Content */ |
| 466 |
#define HT_LOADED 200 /* Instead of a socket */ |
| 467 |
|
| 468 |
#define HT_OK 0 /* Generic success */ |
| 469 |
|
| 470 |
#define HT_ERROR -1 /* Generic failure */ |
| 471 |
#define HT_CANNOT_TRANSLATE -4 |
| 472 |
#define HT_BAD_EOF -12 /* Premature EOF */ |
| 473 |
#define HT_NO_CONNECTION -99 /* ERR no connection available - */ |
| 474 |
#define HT_NO_DATA -204 /* OK but no data was loaded - */ |
| 475 |
/* possibly other app started or forked */ |
| 476 |
#define HT_NO_ACCESS -401 /* Access not available */ |
| 477 |
#define HT_FORBIDDEN -403 /* Access forbidden */ |
| 478 |
#define HT_NOT_ACCEPTABLE -406 /* Not Acceptable */ |
| 479 |
#define HT_H_ERRNO_VALID -800 /* see h_errno for resolver error */ |
| 480 |
#define HT_INTERNAL -900 /* Weird -- should never happen. */ |
| 481 |
#define HT_INTERRUPTED -29998 |
| 482 |
#define HT_NOT_LOADED -29999 |
| 483 |
|
| 484 |
#ifndef va_arg |
| 485 |
# include <stdarg.h> |
| 486 |
#endif |
| 487 |
|
| 488 |
#define LYva_start(ap,format) va_start(ap,format) |
| 489 |
|
| 490 |
/* |
| 491 |
* GCC can be told that some functions are like printf (and do type-checking on |
| 492 |
* their parameters). |
| 493 |
*/ |
| 494 |
#ifndef GCC_PRINTFLIKE |
| 495 |
#if defined(GCC_PRINTF) && !defined(printf) && !defined(HAVE_LIBUTF8_H) |
| 496 |
#define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var))) |
| 497 |
#else |
| 498 |
#define GCC_PRINTFLIKE(fmt,var) /*nothing */ |
| 499 |
#endif |
| 500 |
#endif |
| 501 |
|
| 502 |
#include <HTString.h> /* String utilities */ |
| 503 |
|
| 504 |
/* |
| 505 |
|
| 506 |
Out Of Memory checking for malloc() return: |
| 507 |
|
| 508 |
*/ |
| 509 |
#ifndef __FILE__ |
| 510 |
#define __FILE__ "" |
| 511 |
#define __LINE__ "" |
| 512 |
#endif |
| 513 |
|
| 514 |
#include <LYexit.h> |
| 515 |
|
| 516 |
/* |
| 517 |
* Upper- and Lowercase macros |
| 518 |
* |
| 519 |
* The problem here is that toupper(x) is not defined officially unless |
| 520 |
* isupper(x) is. These macros are CERTAINLY needed on #if defined(pyr) || |
| 521 |
* define(mips) or BDSI platforms. For safefy, we make them mandatory. |
| 522 |
* |
| 523 |
* Note: Pyramid and Mips can't uppercase non-alpha. |
| 524 |
*/ |
| 525 |
#include <ctype.h> |
| 526 |
#include <string.h> |
| 527 |
|
| 528 |
#ifndef TOLOWER |
| 529 |
|
| 530 |
#ifdef USE_ASCII_CTYPES |
| 531 |
|
| 532 |
#define TOLOWER(c) ascii_tolower(UCH(c)) |
| 533 |
#define TOUPPER(c) ascii_toupper(UCH(c)) |
| 534 |
#define ISUPPER(c) ascii_isupper(UCH(c)) |
| 535 |
|
| 536 |
#else |
| 537 |
|
| 538 |
#define TOLOWER(c) (isupper(UCH(c)) ? tolower(UCH(c)) : UCH(c)) |
| 539 |
#define TOUPPER(c) (islower(UCH(c)) ? toupper(UCH(c)) : UCH(c)) |
| 540 |
#define ISUPPER(c) (isupper(UCH(c))) |
| 541 |
|
| 542 |
#endif |
| 543 |
|
| 544 |
#endif /* TOLOWER */ |
| 545 |
|
| 546 |
#define FREE(x) {if (x != NULL) {free((char *)x); x = NULL;}} |
| 547 |
|
| 548 |
/* |
| 549 |
|
| 550 |
The local equivalents of CR and LF |
| 551 |
|
| 552 |
We can check for these after net ascii text has been converted to the local |
| 553 |
representation. Similarly, we include them in strings to be sent as net ascii after |
| 554 |
translation. |
| 555 |
|
| 556 |
*/ |
| 557 |
#define LF FROMASCII('\012') /* ASCII line feed LOCAL EQUIVALENT */ |
| 558 |
#define CR FROMASCII('\015') /* Will be converted to ^M for transmission */ |
| 559 |
|
| 560 |
/* |
| 561 |
* Debug message control. |
| 562 |
*/ |
| 563 |
#ifdef NO_LYNX_TRACE |
| 564 |
#define WWW_TraceFlag 0 |
| 565 |
#define WWW_TraceMask 0 |
| 566 |
#define LYTraceLogFP 0 |
| 567 |
#else |
| 568 |
extern BOOLEAN WWW_TraceFlag; |
| 569 |
extern int WWW_TraceMask; |
| 570 |
#endif |
| 571 |
|
| 572 |
#define TRACE (WWW_TraceFlag) |
| 573 |
#define TRACE_bit(n) (TRACE && (WWW_TraceMask & (1 << n)) != 0) |
| 574 |
#define TRACE_SGML (TRACE_bit(0)) |
| 575 |
#define TRACE_STYLE (TRACE_bit(1)) |
| 576 |
#define TRACE_TRST (TRACE_bit(2)) |
| 577 |
#define TRACE_CFG (TRACE_bit(3)) |
| 578 |
#define TRACE_BSTRING (TRACE_bit(4)) |
| 579 |
#define TRACE_COOKIES (TRACE_bit(5)) |
| 580 |
#define TRACE_CHARSETS (TRACE_bit(6)) |
| 581 |
#define TRACE_GRIDTEXT (TRACE_bit(7)) |
| 582 |
#define TRACE_TIMING (TRACE_bit(8)) |
| 583 |
#define TRACE_HTPARSE (TRACE_bit(9)) |
| 584 |
|
| 585 |
/* |
| 586 |
* Get printing/scanning formats. |
| 587 |
*/ |
| 588 |
#if defined(HAVE_INTTYPES_H) |
| 589 |
#include <inttypes.h> |
| 590 |
#endif |
| 591 |
|
| 592 |
#define DigitsOf(type) (int)((sizeof(type)*8)/3) |
| 593 |
|
| 594 |
/* |
| 595 |
* Printing/scanning-formats for "off_t", as well as cast needed to fit. |
| 596 |
*/ |
| 597 |
#if defined(HAVE_LONG_LONG) && defined(HAVE_INTTYPES_H) && defined(SIZEOF_OFF_T) |
| 598 |
#if (SIZEOF_OFF_T == 8) && defined(PRId64) && defined(SCNd64) |
| 599 |
|
| 600 |
#define PRI_off_t PRId64 |
| 601 |
#define SCN_off_t SCNd64 |
| 602 |
#define CAST_off_t(n) (int64_t)(n) |
| 603 |
|
| 604 |
#elif (SIZEOF_OFF_T == 4) && defined(PRId32) |
| 605 |
|
| 606 |
#define PRI_off_t PRId32 |
| 607 |
#define SCN_off_t SCNd32 |
| 608 |
|
| 609 |
#if (SIZEOF_INT == 4) |
| 610 |
#define CAST_off_t(n) (int)(n) |
| 611 |
#elif (SIZEOF_LONG == 4) |
| 612 |
#define CAST_off_t(n) (long)(n) |
| 613 |
#else |
| 614 |
#define CAST_off_t(n) (int32_t)(n) |
| 615 |
#endif |
| 616 |
|
| 617 |
#endif |
| 618 |
#endif |
| 619 |
|
| 620 |
#ifndef PRI_off_t |
| 621 |
#define GUESS_PRI_off_t |
| 622 |
#if defined(SIZEOF_OFF_T) && defined(SIZEOF_LONG) && (SIZEOF_OFF_T == SIZEOF_LONG) |
| 623 |
#define PRI_off_t "ld" |
| 624 |
#define SCN_off_t "ld" |
| 625 |
#define CAST_off_t(n) (long)(n) |
| 626 |
#elif defined(HAVE_LONG_LONG) |
| 627 |
#define PRI_off_t "lld" |
| 628 |
#define SCN_off_t "lld" |
| 629 |
#define CAST_off_t(n) (long long)(n) |
| 630 |
#else |
| 631 |
#define PRI_off_t "ld" |
| 632 |
/* SCN_off_t requires workaround */ |
| 633 |
#define CAST_off_t(n) (long)(n) |
| 634 |
#endif |
| 635 |
#endif |
| 636 |
|
| 637 |
/* |
| 638 |
* MinGW-32 uses only 32-bit DLL, which limits printing. |
| 639 |
*/ |
| 640 |
#if defined(__MINGW32__) |
| 641 |
#undef PRI_off_t |
| 642 |
#undef CAST_off_t |
| 643 |
#define PRI_off_t "ld" |
| 644 |
#define CAST_off_t(n) (long)(n) |
| 645 |
#endif |
| 646 |
|
| 647 |
/* |
| 648 |
* Printing-format for "time_t", as well as cast needed to fit. |
| 649 |
*/ |
| 650 |
#if defined(HAVE_LONG_LONG) && defined(HAVE_INTTYPES_H) && defined(SIZEOF_TIME_T) |
| 651 |
#if (SIZEOF_TIME_T == 8) && defined(PRId64) |
| 652 |
|
| 653 |
#define PRI_time_t PRId64 |
| 654 |
#define SCN_time_t SCNd64 |
| 655 |
#define CAST_time_t(n) (int64_t)(n) |
| 656 |
|
| 657 |
#elif (SIZEOF_TIME_T == 4) && defined(PRId32) |
| 658 |
|
| 659 |
#define PRI_time_t PRId32 |
| 660 |
#define SCN_time_t SCNd32 |
| 661 |
|
| 662 |
#if (SIZEOF_INT == 4) |
| 663 |
#define CAST_time_t(n) (int)(n) |
| 664 |
#elif (SIZEOF_LONG == 4) |
| 665 |
#define CAST_time_t(n) (long)(n) |
| 666 |
#else |
| 667 |
#define CAST_time_t(n) (int32_t)(n) |
| 668 |
#endif |
| 669 |
|
| 670 |
#endif |
| 671 |
#endif |
| 672 |
|
| 673 |
#ifndef PRI_time_t |
| 674 |
#if defined(HAVE_LONG_LONG) && (SIZEOF_TIME_T > SIZEOF_LONG) |
| 675 |
#define PRI_time_t "lld" |
| 676 |
#define SCN_time_t "lld" |
| 677 |
#define CAST_time_t(n) (long long)(n) |
| 678 |
#else |
| 679 |
#define PRI_time_t "ld" |
| 680 |
#define SCN_time_t "ld" |
| 681 |
#define CAST_time_t(n) (long)(n) |
| 682 |
#endif |
| 683 |
#endif |
| 684 |
|
| 685 |
/* |
| 686 |
* Printing-format for "UCode_t". |
| 687 |
*/ |
| 688 |
#define PRI_UCode_t "lX" |
| 689 |
#define CAST_UCode_t(n) (unsigned long)(n) |
| 690 |
|
| 691 |
/* |
| 692 |
* Verbose-tracing. |
| 693 |
*/ |
| 694 |
#if defined(USE_VERTRACE) && !defined(LY_TRACELINE) |
| 695 |
#define LY_TRACELINE __LINE__ |
| 696 |
#endif |
| 697 |
|
| 698 |
#if defined(LY_TRACELINE) |
| 699 |
#define LY_SHOWWHERE fprintf( tfp, "%s: %d: ", __FILE__, LY_TRACELINE ), |
| 700 |
#else |
| 701 |
#define LY_SHOWWHERE /* nothing */ |
| 702 |
#endif |
| 703 |
|
| 704 |
#define CTRACE(p) ((void)((TRACE) && ( LY_SHOWWHERE fprintf p ))) |
| 705 |
#define CTRACE2(m,p) ((void)((m) && ( LY_SHOWWHERE fprintf p ))) |
| 706 |
#define tfp TraceFP() |
| 707 |
#define CTRACE_SLEEP(secs) if (TRACE && LYTraceLogFP == NULL) sleep((unsigned)secs) |
| 708 |
#define CTRACE_FLUSH(fp) if (TRACE) fflush(fp) |
| 709 |
|
| 710 |
#include <www_tcp.h> |
| 711 |
|
| 712 |
/* |
| 713 |
* We force this include-ordering since socks.h contains redefinitions of |
| 714 |
* functions that probably are prototyped via other includes. The socks.h |
| 715 |
* definitions have to be included everywhere, since they're making wrappers |
| 716 |
* for the stdio functions as well as the network functions. |
| 717 |
*/ |
| 718 |
#if defined(USE_SOCKS5) |
| 719 |
#define SOCKS4TO5 /* turn on the Rxxxx definitions used in Lynx */ |
| 720 |
#include <socks.h> |
| 721 |
|
| 722 |
/* |
| 723 |
* The AIX- and SOCKS4-specific definitions in socks.h are inconsistent. |
| 724 |
* Repair them so they're consistent (and usable). |
| 725 |
*/ |
| 726 |
#if defined(_AIX) && !defined(USE_SOCKS4_PREFIX) |
| 727 |
#undef Raccept |
| 728 |
#define Raccept accept |
| 729 |
#undef Rgetsockname |
| 730 |
#define Rgetsockname getsockname |
| 731 |
#undef Rgetpeername |
| 732 |
#define Rgetpeername getpeername |
| 733 |
#endif |
| 734 |
|
| 735 |
/* |
| 736 |
* Workaround for order-of-evaluation problem with gcc and socks5 headers |
| 737 |
* which breaks the Rxxxx names by attaching the prefix twice: |
| 738 |
*/ |
| 739 |
#ifdef INCLUDE_PROTOTYPES |
| 740 |
#undef Raccept |
| 741 |
#undef Rbind |
| 742 |
#undef Rconnect |
| 743 |
#undef Rlisten |
| 744 |
#undef Rselect |
| 745 |
#undef Rgetpeername |
| 746 |
#undef Rgetsockname |
| 747 |
#define Raccept accept |
| 748 |
#define Rbind bind |
| 749 |
#define Rconnect connect |
| 750 |
#define Rgetpeername getpeername |
| 751 |
#define Rgetsockname getsockname |
| 752 |
#define Rlisten listen |
| 753 |
#define Rselect select |
| 754 |
#endif |
| 755 |
|
| 756 |
#elif defined(SOCKS) |
| 757 |
#include <socks.h> |
| 758 |
#endif /* USE_SOCKS5 */ |
| 759 |
|
| 760 |
#ifdef HAVE_BSD_STDLIB_H |
| 761 |
#include <bsd/stdlib.h> /* prototype for arc4random.h */ |
| 762 |
#elif defined(HAVE_BSD_RANDOM_H) |
| 763 |
#include <bsd/random.h> /* prototype for arc4random.h */ |
| 764 |
#endif |
| 765 |
|
| 766 |
#ifdef HAVE_LIBDMALLOC |
| 767 |
#include <dmalloc.h> /* Gray Watson's library */ |
| 768 |
#define show_alloc() dmalloc_log_unfreed() |
| 769 |
#endif |
| 770 |
|
| 771 |
#ifdef HAVE_LIBDBMALLOC |
| 772 |
#include <dbmalloc.h> /* Conor Cahill's library */ |
| 773 |
#define show_alloc() malloc_dump(fileno(stderr)) |
| 774 |
#endif |
| 775 |
|
| 776 |
#ifndef show_alloc |
| 777 |
#define show_alloc() /* nothing */ |
| 778 |
#endif |
| 779 |
|
| 780 |
#include <userdefs.h> |
| 781 |
|
| 782 |
#ifdef __cplusplus |
| 783 |
extern "C" { |
| 784 |
#endif |
| 785 |
#ifndef TOLOWER |
| 786 |
#ifdef USE_ASCII_CTYPES |
| 787 |
extern int ascii_toupper(int); |
| 788 |
extern int ascii_tolower(int); |
| 789 |
extern int ascii_isupper(int); |
| 790 |
#endif |
| 791 |
#endif |
| 792 |
|
| 793 |
extern FILE *TraceFP(void); |
| 794 |
|
| 795 |
extern char *HTSkipToAt(char *host, int *gen_delims); |
| 796 |
extern void strip_userid(char *host, int warn); |
| 797 |
|
| 798 |
#ifdef __cplusplus |
| 799 |
} |
| 800 |
#endif |
| 801 |
#endif /* HTUTILS_H */ |