1 /* Miscellaneous declarations.
2 Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
4 This file is part of Wget.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* This file contains some declarations that don't fit anywhere else.
21 It also contains some useful includes, like the obnoxious TIME_H
28 # define NDEBUG /* To kill off assertions */
29 #endif /* not DEBUG */
33 # define PARAMS(args) args
35 # define PARAMS(args) ()
39 /* `gettext (FOO)' is long to write, so we use `_(FOO)'. If NLS is
40 unavailable, _(STRING) simply returns STRING. */
42 # define _(string) gettext (string)
43 # ifdef HAVE_LIBINTL_H
45 # endif /* HAVE_LIBINTL_H */
46 #else /* not HAVE_NLS */
47 # define _(string) string
48 #endif /* not HAVE_NLS */
50 /* I18N NOTE: You will notice that none of the DEBUG messages are
51 marked as translatable. This is intentional, for a few reasons:
53 1) The debug messages are not meant for the users to look at, but
54 for the developers; as such, they should be considered more like
55 source comments than real program output.
57 2) The messages are numerous, and yet they are random and frivolous
58 ("double yuck!" and such). There would be a lot of work with no
61 3) Finally, the debug messages are meant to be a clue for me to
62 debug problems with Wget. If I get them in a language I don't
63 understand, debugging will become a new challenge of its own! :-) */
66 /* Include these, so random files need not include them. */
70 #define DO_NOTHING do {} while (0)
72 /* Print X if debugging is enabled; a no-op otherwise. */
74 # define DEBUGP(x) do { debug_logprintf x; } while (0)
76 # define DEBUGP(x) DO_NOTHING
77 #endif /* not DEBUG */
79 /* Make gcc check for the format of logmsg() and debug_logmsg(). */
81 # define GCC_FORMAT_ATTR(a, b) __attribute__ ((format (printf, a, b)))
82 #else /* not __GNUC__ */
83 # define GCC_FORMAT_ATTR(a, b)
84 #endif /* not __GNUC__ */
86 /* These are from log.c, but they are used everywhere, so we declare
88 enum log_options { LOG_VERBOSE, LOG_NOTQUIET, LOG_NONVERBOSE, LOG_ALWAYS };
90 void logprintf PARAMS ((enum log_options, const char *, ...))
91 GCC_FORMAT_ATTR (2, 3);
92 void debug_logprintf PARAMS ((const char *, ...)) GCC_FORMAT_ATTR (1, 2);
93 void logputs PARAMS ((enum log_options, const char *));
95 /* Defined in `utils.c', but used literally everywhere. */
96 void *xmalloc PARAMS ((size_t));
97 void *xrealloc PARAMS ((void *, size_t));
98 char *xstrdup PARAMS ((const char *));
100 /* #### Find a better place for this. */
101 /* The log file to which Wget writes to after HUP. */
102 #define DEFAULT_LOGFILE "wget-log"
104 #define MD5_HASHLEN 16
106 /* Useful macros used across the code: */
108 /* Is the string a hpyhen-only? */
109 #define HYPHENP(x) (*(x) == '-' && !*((x) + 1))
111 /* The smaller value of the two. */
112 #define MINVAL(x, y) ((x) < (y) ? (x) : (y))
114 /* ASCII char -> HEX digit */
115 #define ASC2HEXD(x) (((x) >= '0' && (x) <= '9') ? \
116 ((x) - '0') : (toupper(x) - 'A' + 10))
118 /* HEX digit -> ASCII char */
119 #define HEXD2ASC(x) (((x) < 10) ? ((x) + '0') : ((x) - 10 + 'A'))
121 #define ARRAY_SIZE(array) (sizeof (array) / sizeof (*(array)))
123 /* Note that this much more elegant definition cannot be used:
125 #define STRDUP_ALLOCA(str) (strcpy ((char *)alloca (strlen (str) + 1), str))
127 This is because some compilers don't handle alloca() as argument to
128 function correctly. Gcc under Intel has been reported to offend in
131 #define STRDUP_ALLOCA(ptr, str) do { \
132 (ptr) = (char *)alloca (strlen (str) + 1); \
136 #define ALLOCA_ARRAY(type, len) ((type *) alloca ((len) * sizeof (type)))
138 #define XREALLOC_ARRAY(ptr, type, len) \
139 ((void) (ptr = (type *) xrealloc (ptr, (len) * sizeof (type))))
141 /* Generally useful if you want to avoid arbitrary size limits but
142 don't need a full dynamic array. Assumes that BASEVAR points to a
143 malloced array of TYPE objects (or possibly a NULL pointer, if
144 SIZEVAR is 0), with the total size stored in SIZEVAR. This macro
145 will realloc BASEVAR as necessary so that it can hold at least
146 NEEDED_SIZE objects. The reallocing is done by doubling, which
147 ensures constant amortized time per element. */
148 #define DO_REALLOC(basevar, sizevar, needed_size, type) do \
150 /* Avoid side-effectualness. */ \
151 long do_realloc_needed_size = (needed_size); \
152 long do_realloc_newsize = 0; \
153 while ((sizevar) < (do_realloc_needed_size)) { \
154 do_realloc_newsize = 2*(sizevar); \
155 if (do_realloc_newsize < 32) \
156 do_realloc_newsize = 32; \
157 (sizevar) = do_realloc_newsize; \
159 if (do_realloc_newsize) \
160 XREALLOC_ARRAY (basevar, type, do_realloc_newsize); \
163 /* Free FOO if it is non-NULL. */
164 #define FREE_MAYBE(foo) do { if (foo) free (foo); } while (0)
166 /* #### Hack: OPTIONS_DEFINED_HERE is defined in main.c. */
167 #ifndef OPTIONS_DEFINED_HERE
168 extern const char *exec_name;
172 /* Document-type flags */
175 TEXTHTML = 0x0001, /* document is of type text/html */
176 RETROKF = 0x0002, /* retrieval was OK */
177 HEAD_ONLY = 0x0004, /* only send the HEAD request */
178 SEND_NOCACHE = 0x0008, /* send Pragma: no-cache directive */
179 ACCEPTRANGES = 0x0010 /* Accept-ranges header was found */
182 /* Universal error type -- used almost everywhere.
183 This is, of course, utter crock. */
186 NOCONERROR, HOSTERR, CONSOCKERR, CONERROR,
187 CONREFUSED, NEWLOCATION, NOTENOUGHMEM, CONPORTERR,
188 BINDERR, BINDOK, LISTENERR, ACCEPTERR, ACCEPTOK,
189 CONCLOSED, FTPOK, FTPLOGINC, FTPLOGREFUSED, FTPPORTERR,
190 FTPNSFOD, FTPRETROK, FTPUNKNOWNTYPE, FTPRERR,
191 FTPREXC, FTPSRVERR, FTPRETRINT, FTPRESTFAIL,
192 URLOK, URLHTTP, URLFTP, URLFILE, URLUNKNOWN, URLBADPORT,
193 URLBADHOST, FOPENERR, FWRITEERR, HOK, HLEXC, HEOF,
194 HERR, RETROK, RECLEVELEXC, FTPACCDENIED, WRONGCODE,
195 FTPINVPASV, FTPNOPASV,
196 RETRFINISHED, READERR, TRYLIMEXC, URLBADPATTERN,
197 FILEBADFILE, RANGEERR, RETRBADPATTERN, RETNOTSUP,
198 ROBOTSOK, NOROBOTS, PROXERR, AUTHFAILED, QUOTEXC, WRITEFAILED
201 typedef unsigned char boolean;
209 /* So we can say strcmp(a, b) == EQ rather than strcmp(a, b) == 0 or
210 the really awful !strcmp(a, b). */