1*fb3ef04dSDag-Erling Smørgrav /* 2*fb3ef04dSDag-Erling Smørgrav * Copyright (c) 2012 - 2015 Tony Finch <dot@dotat.at> 3*fb3ef04dSDag-Erling Smørgrav * 4*fb3ef04dSDag-Erling Smørgrav * Redistribution and use in source and binary forms, with or without 5*fb3ef04dSDag-Erling Smørgrav * modification, are permitted provided that the following conditions 6*fb3ef04dSDag-Erling Smørgrav * are met: 7*fb3ef04dSDag-Erling Smørgrav * 1. Redistributions of source code must retain the above copyright 8*fb3ef04dSDag-Erling Smørgrav * notice, this list of conditions and the following disclaimer. 9*fb3ef04dSDag-Erling Smørgrav * 2. Redistributions in binary form must reproduce the above copyright 10*fb3ef04dSDag-Erling Smørgrav * notice, this list of conditions and the following disclaimer in the 11*fb3ef04dSDag-Erling Smørgrav * documentation and/or other materials provided with the distribution. 12*fb3ef04dSDag-Erling Smørgrav * 13*fb3ef04dSDag-Erling Smørgrav * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14*fb3ef04dSDag-Erling Smørgrav * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15*fb3ef04dSDag-Erling Smørgrav * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16*fb3ef04dSDag-Erling Smørgrav * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17*fb3ef04dSDag-Erling Smørgrav * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18*fb3ef04dSDag-Erling Smørgrav * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19*fb3ef04dSDag-Erling Smørgrav * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20*fb3ef04dSDag-Erling Smørgrav * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21*fb3ef04dSDag-Erling Smørgrav * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22*fb3ef04dSDag-Erling Smørgrav * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23*fb3ef04dSDag-Erling Smørgrav * SUCH DAMAGE. 24*fb3ef04dSDag-Erling Smørgrav */ 25*fb3ef04dSDag-Erling Smørgrav 26*fb3ef04dSDag-Erling Smørgrav /* Stop being stupid about POSIX functions */ 27*fb3ef04dSDag-Erling Smørgrav #define _CRT_SECURE_NO_WARNINGS 28*fb3ef04dSDag-Erling Smørgrav #define _SCL_SECURE_NO_WARNINGS 29*fb3ef04dSDag-Erling Smørgrav #define _CRT_NONSTDC_NO_WARNINGS 30*fb3ef04dSDag-Erling Smørgrav 31*fb3ef04dSDag-Erling Smørgrav #include <ctype.h> 32*fb3ef04dSDag-Erling Smørgrav #include <errno.h> 33*fb3ef04dSDag-Erling Smørgrav #include <stdarg.h> 34*fb3ef04dSDag-Erling Smørgrav #include <stdio.h> 35*fb3ef04dSDag-Erling Smørgrav #include <stdint.h> 36*fb3ef04dSDag-Erling Smørgrav #include <stdlib.h> 37*fb3ef04dSDag-Erling Smørgrav #include <string.h> 38*fb3ef04dSDag-Erling Smørgrav 39*fb3ef04dSDag-Erling Smørgrav /* Windows POSIX-flavoured headers */ 40*fb3ef04dSDag-Erling Smørgrav 41*fb3ef04dSDag-Erling Smørgrav #include <sys/stat.h> 42*fb3ef04dSDag-Erling Smørgrav #include <fcntl.h> 43*fb3ef04dSDag-Erling Smørgrav #include <io.h> 44*fb3ef04dSDag-Erling Smørgrav 45*fb3ef04dSDag-Erling Smørgrav #define stat _stat 46*fb3ef04dSDag-Erling Smørgrav 47*fb3ef04dSDag-Erling Smørgrav /* fake stdbool.h */ 48*fb3ef04dSDag-Erling Smørgrav #define true 1 49*fb3ef04dSDag-Erling Smørgrav #define false 0 50*fb3ef04dSDag-Erling Smørgrav #define bool int 51*fb3ef04dSDag-Erling Smørgrav 52*fb3ef04dSDag-Erling Smørgrav /* used by err.c and getopt.c */ 53*fb3ef04dSDag-Erling Smørgrav #define _getprogname() "unifdef" 54*fb3ef04dSDag-Erling Smørgrav 55*fb3ef04dSDag-Erling Smørgrav /* 56*fb3ef04dSDag-Erling Smørgrav * The snprintf() workaround is unnecessary in Visual Studio 2015 or later 57*fb3ef04dSDag-Erling Smørgrav * but dogma dictates that #if directives are not allowed inside unifdef. 58*fb3ef04dSDag-Erling Smørgrav */ 59*fb3ef04dSDag-Erling Smørgrav #define snprintf c99_snprintf 60*fb3ef04dSDag-Erling Smørgrav 61*fb3ef04dSDag-Erling Smørgrav /* win32.c */ 62*fb3ef04dSDag-Erling Smørgrav int replace(const char *oldname, const char *newname); 63*fb3ef04dSDag-Erling Smørgrav FILE *mktempmode(char *tmp, int mode); 64*fb3ef04dSDag-Erling Smørgrav FILE *fbinmode(FILE *fp); 65*fb3ef04dSDag-Erling Smørgrav int c99_snprintf(char *buf, size_t buflen, const char *format, ...); 66*fb3ef04dSDag-Erling Smørgrav 67*fb3ef04dSDag-Erling Smørgrav /* err.c */ 68*fb3ef04dSDag-Erling Smørgrav void err(int, const char *, ...); 69*fb3ef04dSDag-Erling Smørgrav void verr(int, const char *, va_list); 70*fb3ef04dSDag-Erling Smørgrav void errc(int, int, const char *, ...); 71*fb3ef04dSDag-Erling Smørgrav void verrc(int, int, const char *, va_list); 72*fb3ef04dSDag-Erling Smørgrav void errx(int, const char *, ...); 73*fb3ef04dSDag-Erling Smørgrav void verrx(int, const char *, va_list); 74*fb3ef04dSDag-Erling Smørgrav void warn(const char *, ...); 75*fb3ef04dSDag-Erling Smørgrav void vwarn(const char *, va_list); 76*fb3ef04dSDag-Erling Smørgrav void warnc(int, const char *, ...); 77*fb3ef04dSDag-Erling Smørgrav void vwarnc(int, const char *, va_list); 78*fb3ef04dSDag-Erling Smørgrav void warnx(const char *, ...); 79*fb3ef04dSDag-Erling Smørgrav void vwarnx(const char *, va_list); 80*fb3ef04dSDag-Erling Smørgrav 81*fb3ef04dSDag-Erling Smørgrav /* getopt.c */ 82*fb3ef04dSDag-Erling Smørgrav int getopt(int nargc, char *nargv[], const char *ostr); 83*fb3ef04dSDag-Erling Smørgrav extern int opterr, optind, optopt, optreset; 84*fb3ef04dSDag-Erling Smørgrav extern char *optarg; 85