From d5899efe4a68c00b14f7b4e40042b60c86db4898 Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Sun, 24 Jul 2011 18:15:13 +0000 Subject: Scary-looking but otherwise harmless changes allow me to build for Windows. That is to say, with mingw32. This amounts to the following: (1) break compat.c into compat_strlcpy.c and compat_strlcat.c (2) add compat_getsubopt.c (from OpenBSD) and test-getsubopt.c (3) add test-strptime.c for HAVE_STRPTIME (4) add ifdef bits here and there, where necessary (5) remove some harmless unportable stuff (u_char, localtime_r) I've added the appropriate mdocml.zip target to the Makefile, too. --- Makefile | 48 +++++++++++++++++++------ compat.c | 95 -------------------------------------------------- compat_getsubopt.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++ compat_strlcat.c | 63 +++++++++++++++++++++++++++++++++ compat_strlcpy.c | 59 +++++++++++++++++++++++++++++++ config.h.post | 4 +++ man_hash.c | 12 +++---- man_validate.c | 5 +-- mandoc.c | 15 ++++---- mdoc_hash.c | 16 ++++----- mdoc_validate.c | 4 +-- out.c | 4 +-- preconv.c | 10 ++++-- test-getsubopt.c | 12 +++++++ test-strptime.c | 13 +++++++ 15 files changed, 327 insertions(+), 133 deletions(-) delete mode 100644 compat.c create mode 100644 compat_getsubopt.c create mode 100644 compat_strlcat.c create mode 100644 compat_strlcpy.c create mode 100644 test-getsubopt.c create mode 100644 test-strptime.c diff --git a/Makefile b/Makefile index ceeaab60..93959a6d 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,8 @@ VDATE = 24 July 2011 # UCS-4 value) should you define USE_WCHAR. If you define it and your # system DOESN'T support this, -Tlocale will produce garbage. # If you don't define it, -Tlocale is a synonym for -Tacsii. -CFLAGS += -g -DUSE_WCHAR -DHAVE_CONFIG_H -DVERSION="\"$(VERSION)\"" +CFLAGS += -DUSE_WCHAR +CFLAGS += -g -DHAVE_CONFIG_H -DVERSION="\"$(VERSION)\"" CFLAGS += -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings PREFIX = /usr/local BINDIR = $(PREFIX)/bin @@ -45,7 +46,9 @@ SRCS = Makefile \ att.in \ chars.c \ chars.in \ - compat.c \ + compat_getsubopt.c \ + compat_strlcat.c \ + compat_strlcpy.c \ config.h.post \ config.h.pre \ eqn.7 \ @@ -179,6 +182,13 @@ LIBMANDOC_LNS = $(LIBMAN_LNS) \ mandoc.ln \ read.ln +COMPAT_OBJS = compat_getsubopt.o \ + compat_strlcat.o \ + compat_strlcpy.o +COMPAT_LNS = compat_getsubopt.ln \ + compat_strlcat.ln \ + compat_strlcpy.ln + arch.o arch.ln: arch.in att.o att.ln: att.in chars.o chars.ln: chars.in @@ -193,6 +203,8 @@ $(LIBMDOC_OBJS) $(LIBMDOC_LNS): libmdoc.h $(LIBROFF_OBJS) $(LIBROFF_LNS): libroff.h $(LIBMANDOC_OBJS) $(LIBMANDOC_LNS): mandoc.h mdoc.h man.h libmandoc.h config.h +$(COMPAT_OBJS) $(COMPAT_LNS): config.h + MANDOC_HTML_OBJS = eqn_html.o \ html.o \ man_html.o \ @@ -234,8 +246,6 @@ $(MANDOC_HTML_OBJS) $(MANDOC_HTML_LNS): html.h $(MANDOC_TERM_OBJS) $(MANDOC_TERM_LNS): term.h $(MANDOC_OBJS) $(MANDOC_LNS): main.h mandoc.h mdoc.h man.h config.h out.h -compat.o compat.ln: config.h - MANDOCDB_OBJS = mandocdb.o MANDOCDB_LNS = mandocdb.ln @@ -319,8 +329,8 @@ clean: rm -f llib-lpreconv.ln $(PRECONV_LNS) rm -f mandoc $(MANDOC_OBJS) rm -f llib-lmandoc.ln $(MANDOC_LNS) - rm -f config.h config.log compat.o compat.ln - rm -f mdocml.tar.gz + rm -f config.h config.log $(COMPAT_OBJS) $(COMPAT_LNS) + rm -f mdocml.tar.gz mdocml.zip rm -f index.html $(INDEX_OBJS) install: all @@ -350,11 +360,11 @@ installwww: www $(INSTALL_DATA) mdocml.tar.gz $(PREFIX)/snapshots/mdocml-$(VERSION).tar.gz $(INSTALL_DATA) mdocml.md5 $(PREFIX)/snapshots/mdocml-$(VERSION).md5 -libmandoc.a: compat.o $(LIBMANDOC_OBJS) - $(AR) rs $@ compat.o $(LIBMANDOC_OBJS) +libmandoc.a: $(COMPAT_OBJS) $(LIBMANDOC_OBJS) + $(AR) rs $@ $(COMPAT_OBJS) $(LIBMANDOC_OBJS) -llib-llibmandoc.ln: compat.ln $(LIBMANDOC_LNS) - $(LINT) $(LINTFLAGS) -Clibmandoc compat.ln $(LIBMANDOC_LNS) +llib-llibmandoc.ln: $(COMPAT_LNS) $(LIBMANDOC_LNS) + $(LINT) $(LINTFLAGS) -Clibmandoc $(COMPAT_LNS) $(LIBMANDOC_LNS) mandoc: $(MANDOC_OBJS) libmandoc.a $(CC) -o $@ $(MANDOC_OBJS) libmandoc.a @@ -383,12 +393,30 @@ mdocml.tar.gz: $(SRCS) ( cd .dist/ && tar zcf ../$@ ./ ) rm -rf .dist/ +mdocml.zip: $(SRCS) + mkdir -p .win32/mdocml-$(VERSION)/ + $(INSTALL_SOURCE) $(SRCS) .win32 + cp .win32/Makefile .win32/Makefile.old + grep -v DUSE_WCHAR .win32/Makefile.old >.win32/Makefile + ( cd .win32; CC=i586-mingw32msvc-cc AR=i586-mingw32msvc-ar CFLAGS='-DOSNAME=\"Windows\"' make; \ + make install PREFIX=mdocml-$(VERSION) ; \ + zip -r ../$@ mdocml-$(VERSION) ) + rm -rf .win32 + index.html: $(INDEX_OBJS) config.h: config.h.pre config.h.post rm -f config.log ( cat config.h.pre; \ echo; \ + if $(CC) $(CFLAGS) -Werror -o test-strptime test-strptime.c >> config.log 2>&1; then \ + echo '#define HAVE_STRPTIME'; \ + rm test-strptime; \ + fi; \ + if $(CC) $(CFLAGS) -Werror -o test-getsubopt test-getsubopt.c >> config.log 2>&1; then \ + echo '#define HAVE_GETSUBOPT'; \ + rm test-getsubopt; \ + fi; \ if $(CC) $(CFLAGS) -Werror -o test-strlcat test-strlcat.c >> config.log 2>&1; then \ echo '#define HAVE_STRLCAT'; \ rm test-strlcat; \ diff --git a/compat.c b/compat.c deleted file mode 100644 index f00cc5c6..00000000 --- a/compat.c +++ /dev/null @@ -1,95 +0,0 @@ -/* $OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */ - -/* - * Copyright (c) 1998 Todd C. Miller - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include - -int dummy; /* To prevent an empty object file */ - -#ifndef HAVE_STRLCAT -/* - * Appends src to string dst of size siz (unlike strncat, siz is the - * full size of dst, not space left). At most siz-1 characters - * will be copied. Always NUL terminates (unless siz <= strlen(dst)). - * Returns strlen(src) + MIN(siz, strlen(initial dst)). - * If retval >= siz, truncation occurred. - */ -size_t -strlcat(char *dst, const char *src, size_t siz) -{ - char *d = dst; - const char *s = src; - size_t n = siz; - size_t dlen; - - /* Find the end of dst and adjust bytes left but don't go past end */ - while (n-- != 0 && *d != '\0') - d++; - dlen = d - dst; - n = siz - dlen; - - if (n == 0) - return(dlen + strlen(s)); - while (*s != '\0') { - if (n != 1) { - *d++ = *s; - n--; - } - s++; - } - *d = '\0'; - - return(dlen + (s - src)); /* count does not include NUL */ -} -#endif - -#ifndef HAVE_STRLCPY -/* - * Copy src to string dst of size siz. At most siz-1 characters - * will be copied. Always NUL terminates (unless siz == 0). - * Returns strlen(src); if retval >= siz, truncation occurred. - */ -size_t -strlcpy(char *dst, const char *src, size_t siz) -{ - char *d = dst; - const char *s = src; - size_t n = siz; - - /* Copy as many bytes as will fit */ - if (n != 0) { - while (--n != 0) { - if ((*d++ = *s++) == '\0') - break; - } - } - - /* Not enough room in dst, add NUL and traverse rest of src */ - if (n == 0) { - if (siz != 0) - *d = '\0'; /* NUL-terminate dst */ - while (*s++) - ; - } - - return(s - src - 1); /* count does not include NUL */ -} -#endif diff --git a/compat_getsubopt.c b/compat_getsubopt.c new file mode 100644 index 00000000..1a7ec6e8 --- /dev/null +++ b/compat_getsubopt.c @@ -0,0 +1,100 @@ +#ifdef HAVE_GETSUBOPT + +int dummy; + +#else + +/* $OpenBSD: getsubopt.c,v 1.4 2005/08/08 08:05:36 espie Exp $ */ + +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include +#include + +/* + * The SVID interface to getsubopt provides no way of figuring out which + * part of the suboptions list wasn't matched. This makes error messages + * tricky... The extern variable suboptarg is a pointer to the token + * which didn't match. + */ +char *suboptarg; + +int +getsubopt(char **optionp, char * const *tokens, char **valuep) +{ + int cnt; + char *p; + + suboptarg = *valuep = NULL; + + if (!optionp || !*optionp) + return(-1); + + /* skip leading white-space, commas */ + for (p = *optionp; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p); + + if (!*p) { + *optionp = p; + return(-1); + } + + /* save the start of the token, and skip the rest of the token. */ + for (suboptarg = p; + *++p && *p != ',' && *p != '=' && *p != ' ' && *p != '\t';); + + if (*p) { + /* + * If there's an equals sign, set the value pointer, and + * skip over the value part of the token. Terminate the + * token. + */ + if (*p == '=') { + *p = '\0'; + for (*valuep = ++p; + *p && *p != ',' && *p != ' ' && *p != '\t'; ++p); + if (*p) + *p++ = '\0'; + } else + *p++ = '\0'; + /* Skip any whitespace or commas after this token. */ + for (; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p); + } + + /* set optionp for next round. */ + *optionp = p; + + for (cnt = 0; *tokens; ++tokens, ++cnt) + if (!strcmp(suboptarg, *tokens)) + return(cnt); + return(-1); +} + +#endif diff --git a/compat_strlcat.c b/compat_strlcat.c new file mode 100644 index 00000000..ba9196da --- /dev/null +++ b/compat_strlcat.c @@ -0,0 +1,63 @@ +#ifdef HAVE_STRLCAT + +int dummy; + +#else + +/* $OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */ + +/* + * Copyright (c) 1998 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include + +/* + * Appends src to string dst of size siz (unlike strncat, siz is the + * full size of dst, not space left). At most siz-1 characters + * will be copied. Always NUL terminates (unless siz <= strlen(dst)). + * Returns strlen(src) + MIN(siz, strlen(initial dst)). + * If retval >= siz, truncation occurred. + */ +size_t +strlcat(char *dst, const char *src, size_t siz) +{ + char *d = dst; + const char *s = src; + size_t n = siz; + size_t dlen; + + /* Find the end of dst and adjust bytes left but don't go past end */ + while (n-- != 0 && *d != '\0') + d++; + dlen = d - dst; + n = siz - dlen; + + if (n == 0) + return(dlen + strlen(s)); + while (*s != '\0') { + if (n != 1) { + *d++ = *s; + n--; + } + s++; + } + *d = '\0'; + + return(dlen + (s - src)); /* count does not include NUL */ +} + +#endif diff --git a/compat_strlcpy.c b/compat_strlcpy.c new file mode 100644 index 00000000..f56f2d85 --- /dev/null +++ b/compat_strlcpy.c @@ -0,0 +1,59 @@ +#ifdef HAVE_STRLCPY + +int dummy; + +#else + +/* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */ + +/* + * Copyright (c) 1998 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include + +/* + * Copy src to string dst of size siz. At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns strlen(src); if retval >= siz, truncation occurred. + */ +size_t +strlcpy(char *dst, const char *src, size_t siz) +{ + char *d = dst; + const char *s = src; + size_t n = siz; + + /* Copy as many bytes as will fit */ + if (n != 0) { + while (--n != 0) { + if ((*d++ = *s++) == '\0') + break; + } + } + + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } + + return(s - src - 1); /* count does not include NUL */ +} + +#endif diff --git a/config.h.post b/config.h.post index 81c01b93..3cdf9a78 100644 --- a/config.h.post +++ b/config.h.post @@ -21,5 +21,9 @@ extern size_t strlcat(char *, const char *, size_t); #ifndef HAVE_STRLCPY extern size_t strlcpy(char *, const char *, size_t); #endif +#ifndef HAVE_GETSUBOPT +extern int getsubopt(char **, char * const *, char **); +extern char *suboptarg; +#endif #endif /* MANDOC_CONFIG_H */ diff --git a/man_hash.c b/man_hash.c index c52640e8..86c5c40a 100644 --- a/man_hash.c +++ b/man_hash.c @@ -1,4 +1,4 @@ -/* $Id: man_hash.c,v 1.24 2011/03/22 14:33:05 kristaps Exp $ */ +/* $Id: man_hash.c,v 1.25 2011/07/24 18:15:14 kristaps Exp $ */ /* * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons * @@ -33,7 +33,7 @@ #define HASH_DEPTH 6 #define HASH_ROW(x) do { \ - if (isupper((u_char)(x))) \ + if (isupper((unsigned char)(x))) \ (x) -= 65; \ else \ (x) -= 97; \ @@ -47,7 +47,7 @@ * macro (the integer value of the enum stored as a char to save a bit * of space). */ -static u_char table[26 * HASH_DEPTH]; +static unsigned char table[26 * HASH_DEPTH]; /* * XXX - this hash has global scope, so if intended for use as a library @@ -66,13 +66,13 @@ man_hash_init(void) for (i = 0; i < (int)MAN_MAX; i++) { x = man_macronames[i][0]; - assert(isalpha((u_char)x)); + assert(isalpha((unsigned char)x)); HASH_ROW(x); for (j = 0; j < HASH_DEPTH; j++) if (UCHAR_MAX == table[x + j]) { - table[x + j] = (u_char)i; + table[x + j] = (unsigned char)i; break; } @@ -89,7 +89,7 @@ man_hash_find(const char *tmp) if ('\0' == (x = tmp[0])) return(MAN_MAX); - if ( ! (isalpha((u_char)x))) + if ( ! (isalpha((unsigned char)x))) return(MAN_MAX); HASH_ROW(x); diff --git a/man_validate.c b/man_validate.c index 63d80129..1aeb703d 100644 --- a/man_validate.c +++ b/man_validate.c @@ -1,4 +1,4 @@ -/* $Id: man_validate.c,v 1.70 2011/07/08 09:34:06 kristaps Exp $ */ +/* $Id: man_validate.c,v 1.71 2011/07/24 18:15:14 kristaps Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010 Ingo Schwarze @@ -412,7 +412,8 @@ post_TH(CHKARGS) if (n && n->string) { for (p = n->string; '\0' != *p; p++) { /* Only warn about this once... */ - if (isalpha((u_char)*p) && ! isupper((u_char)*p)) { + if (isalpha((unsigned char)*p) && + ! isupper((unsigned char)*p)) { man_nmsg(m, n, MANDOCERR_UPPERCASE); break; } diff --git a/mandoc.c b/mandoc.c index 299b64f9..74c47db3 100644 --- a/mandoc.c +++ b/mandoc.c @@ -1,4 +1,4 @@ -/* $Id: mandoc.c,v 1.55 2011/07/21 23:30:39 kristaps Exp $ */ +/* $Id: mandoc.c,v 1.56 2011/07/24 18:15:14 kristaps Exp $ */ /* * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons * Copyright (c) 2011 Ingo Schwarze @@ -542,7 +542,10 @@ a2time(time_t *t, const char *fmt, const char *p) memset(&tm, 0, sizeof(struct tm)); + pp = NULL; +#ifdef HAVE_STRPTIME pp = strptime(p, fmt, &tm); +#endif if (NULL != pp && '\0' == *pp) { *t = mktime(&tm); return(1); @@ -554,12 +557,12 @@ a2time(time_t *t, const char *fmt, const char *p) static char * time2a(time_t t) { - struct tm tm; + struct tm *tm; char *buf, *p; size_t ssz; int isz; - localtime_r(&t, &tm); + tm = localtime(&t); /* * Reserve space: @@ -569,15 +572,15 @@ time2a(time_t t) */ p = buf = mandoc_malloc(10 + 4 + 4 + 1); - if (0 == (ssz = strftime(p, 10 + 1, "%B ", &tm))) + if (0 == (ssz = strftime(p, 10 + 1, "%B ", tm))) goto fail; p += (int)ssz; - if (-1 == (isz = snprintf(p, 4 + 1, "%d, ", tm.tm_mday))) + if (-1 == (isz = snprintf(p, 4 + 1, "%d, ", tm->tm_mday))) goto fail; p += isz; - if (0 == strftime(p, 4 + 1, "%Y", &tm)) + if (0 == strftime(p, 4 + 1, "%Y", tm)) goto fail; return(buf); diff --git a/mdoc_hash.c b/mdoc_hash.c index a1a03094..59a8d26a 100644 --- a/mdoc_hash.c +++ b/mdoc_hash.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_hash.c,v 1.17 2011/03/22 14:33:05 kristaps Exp $ */ +/* $Id: mdoc_hash.c,v 1.18 2011/07/24 18:15:14 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -31,7 +31,7 @@ #include "mandoc.h" #include "libmdoc.h" -static u_char table[27 * 12]; +static unsigned char table[27 * 12]; /* * XXX - this hash has global scope, so if intended for use as a library @@ -48,14 +48,14 @@ mdoc_hash_init(void) for (i = 0; i < (int)MDOC_MAX; i++) { p = mdoc_macronames[i]; - if (isalpha((u_char)p[1])) - major = 12 * (tolower((u_char)p[1]) - 97); + if (isalpha((unsigned char)p[1])) + major = 12 * (tolower((unsigned char)p[1]) - 97); else major = 12 * 26; for (j = 0; j < 12; j++) if (UCHAR_MAX == table[major + j]) { - table[major + j] = (u_char)i; + table[major + j] = (unsigned char)i; break; } @@ -70,11 +70,11 @@ mdoc_hash_find(const char *p) if (0 == p[0]) return(MDOC_MAX); - if ( ! isalpha((u_char)p[0]) && '%' != p[0]) + if ( ! isalpha((unsigned char)p[0]) && '%' != p[0]) return(MDOC_MAX); - if (isalpha((u_char)p[1])) - major = 12 * (tolower((u_char)p[1]) - 97); + if (isalpha((unsigned char)p[1])) + major = 12 * (tolower((unsigned char)p[1]) - 97); else if ('1' == p[1]) major = 12 * 26; else diff --git a/mdoc_validate.c b/mdoc_validate.c index e95b1d18..b8f277fa 100644 --- a/mdoc_validate.c +++ b/mdoc_validate.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_validate.c,v 1.170 2011/07/18 07:46:41 kristaps Exp $ */ +/* $Id: mdoc_validate.c,v 1.171 2011/07/24 18:15:14 kristaps Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2011 Ingo Schwarze @@ -2046,7 +2046,7 @@ post_dt(POST_ARGS) if (NULL != (nn = n->child)) for (p = nn->string; *p; p++) { - if (toupper((u_char)*p) == *p) + if (toupper((unsigned char)*p) == *p) continue; /* diff --git a/out.c b/out.c index eb679e64..6ae41fd1 100644 --- a/out.c +++ b/out.c @@ -1,4 +1,4 @@ -/* $Id: out.c,v 1.41 2011/07/17 15:24:25 kristaps Exp $ */ +/* $Id: out.c,v 1.42 2011/07/24 18:15:14 kristaps Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2011 Ingo Schwarze @@ -69,7 +69,7 @@ a2roffsu(const char *src, struct roffsu *dst, enum roffscale def) return(0); while (i < BUFSIZ) { - if ( ! isdigit((u_char)*src)) { + if ( ! isdigit((unsigned char)*src)) { if ('.' != *src) break; else if (hasd) diff --git a/preconv.c b/preconv.c index a53504ec..a0b2d641 100644 --- a/preconv.c +++ b/preconv.c @@ -1,4 +1,4 @@ -/* $Id: preconv.c,v 1.4 2011/05/26 21:13:07 kristaps Exp $ */ +/* $Id: preconv.c,v 1.5 2011/07/24 18:15:14 kristaps Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons * @@ -18,8 +18,10 @@ #include "config.h" #endif +#ifdef HAVE_MMAP #include #include +#endif #include #include @@ -244,10 +246,11 @@ static int read_whole_file(const char *f, int fd, struct buf *fb, int *with_mmap) { - struct stat st; size_t off; ssize_t ssz; +#ifdef HAVE_MMAP + struct stat st; if (-1 == fstat(fd, &st)) { perror(f); return(0); @@ -273,6 +276,7 @@ read_whole_file(const char *f, int fd, if (fb->buf != MAP_FAILED) return(1); } +#endif /* * If this isn't a regular file (like, say, stdin), then we must @@ -510,9 +514,11 @@ main(int argc, char *argv[]) rc = EXIT_SUCCESS; out: +#ifdef HAVE_MMAP if (map) munmap(b.buf, b.sz); else +#endif free(b.buf); if (fd > STDIN_FILENO) diff --git a/test-getsubopt.c b/test-getsubopt.c new file mode 100644 index 00000000..25e11246 --- /dev/null +++ b/test-getsubopt.c @@ -0,0 +1,12 @@ +#if defined(__linux__) || defined(__MINT__) +# define _GNU_SOURCE /* getsubopt() */ +#endif + +#include + +int +main(int argc, char **argv) +{ + getsubopt(argv, argv, argv); + return 0; +} diff --git a/test-strptime.c b/test-strptime.c new file mode 100644 index 00000000..976e9c80 --- /dev/null +++ b/test-strptime.c @@ -0,0 +1,13 @@ +#if defined(__linux__) || defined(__MINT__) +# define _GNU_SOURCE /* strptime(), getsubopt() */ +#endif + +#include + +int +main(int argc, char **argv) +{ + struct tm tm; + strptime(*argv, "%D", &tm); + return 0; +} -- cgit v1.2.3-56-ge451