2 * Copyright (C) 2009-2012 Erwin Waterlander
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice in the documentation and/or other materials provided with
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
20 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
21 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
23 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 /* define feature test macros for realpath() -- needed on */
28 /* systems that have S_ISLNK, but chicken/egg means we must */
29 /* define early, before including stdlib.h (or sys/stat.h) */
30 #define _XOPEN_SOURCE 500
32 /* similarly, instead of realpath we like to use, if */
33 /* available, the canonicalize_file_name() function, which */
34 /* is a GNU extension. We only ACTUALLY use the function if */
35 /* USE_CANONICALIZE_FILE_NAME is defined, but we don't define*/
36 /* that until later. So...define the feature test macro now. */
42 #define _(String) gettext (String)
43 #define gettext_noop(String) String
44 #define N_(String) gettext_noop (String)
48 #define _(String) (String)
49 #define N_(String) String
50 #define textdomain(Domain)
51 #define bindtextdomain(Package, Directory)
55 #if defined(__DJGPP__) || defined(__TURBOC__) /* DJGPP */
58 # if !defined(__MSYS__) && !defined(_MSC_VER)
62 #if !defined(__TURBOC__) && !defined(_MSC_VER)
71 # define strcmpi(s1, s2) strcasecmp(s1, s2)
75 # include <sys/utime.h>
89 #if (defined(__WATCOMC__) && defined(__NT__)) /* Watcom */
93 #if defined(__WATCOMC__) && defined(__I86__) /* Watcom C, 16 bit Intel */
97 #if defined(__WATCOMC__) && defined(__DOS__) /* Watcom C, 32 bit DOS */
101 #if defined(ENABLE_NLS) || (defined(D2U_UNICODE) && !defined(__MSDOS__) && !defined(_WIN32) && !defined(__OS2__))
102 /* setlocale() is also needed for nl_langinfo() */
106 #if defined(__TURBOC__) || defined(__DJGPP__) || defined(__MINGW32__) || defined(_MSC_VER)
107 /* Some compilers have no mkstemp().
108 * Use mktemp() instead.
109 * BORLANDC, DJGPP, MINGW32 */
113 #if defined(__TURBOC__) || defined(__DJGPP__) || defined(__MINGW32__) || defined(__WATCOMC__) || defined(_MSC_VER)
114 /* Some compilers have no chown(). */
118 /* Watcom C defines S_ISLNK */
123 /* Microsoft Visual C++ */
125 #define S_ISCHR( m ) (((m) & _S_IFMT) == _S_IFCHR)
126 #define S_ISDIR( m ) (((m) & _S_IFMT) == _S_IFDIR)
127 #define S_ISFIFO( m ) (((m) & _S_IFMT) == _S_IFIFO)
128 #define S_ISREG( m ) (((m) & _S_IFMT) == _S_IFREG)
129 #define NO_CHMOD 1 /* no chmod() available */
132 #if defined(__MSDOS__) || defined(_WIN32) || defined(__OS2__)
133 /* Systems without soft links use 'stat' instead of 'lstat'. */
139 #if defined(__MSDOS__) || defined(_WIN32) || defined(__OS2__)
140 /* On some systems rename() will always fail if target file already exists. */
141 #define NEED_REMOVE 1
144 #if defined(__MSDOS__) || defined(_WIN32) || defined(__CYGWIN__) || defined(__OS2__) /* DJGPP, MINGW32 and OS/2 */
145 /* required for setmode() and O_BINARY */
150 #if defined(__MSDOS__) || defined(_WIN32) || defined(__CYGWIN__) || defined(__OS2__)
158 #define BINARY_FILE 0x1
159 #define NO_REGFILE 0x2
160 #define WRONG_CODEPAGE 0x4
161 #define OUTPUTFILE_SYMLINK 0x8
162 #define INPUT_TARGET_NO_REGFILE 0x10
163 #define OUTPUT_TARGET_NO_REGFILE 0x20
164 #define LOCALE_NOT_UTF8 0x40
165 #define WCHAR_T_TOO_SMALL 0x80
166 #define UNICODE_CONVERSION_ERROR 0x100
168 #define CONVMODE_ASCII 0
169 #define CONVMODE_UTF16LE 1
170 #define CONVMODE_UTF16BE 2
171 #define CONVMODE_7BIT 3
172 #define CONVMODE_437 437
173 #define CONVMODE_850 850
174 #define CONVMODE_860 860
175 #define CONVMODE_863 863
176 #define CONVMODE_865 865
177 #define CONVMODE_1252 1252
179 #define FROMTO_DOS2UNIX 0
180 #define FROMTO_MAC2UNIX 1
181 #define FROMTO_UNIX2DOS 0
182 #define FROMTO_UNIX2MAC 1
184 #define SYMLINK_SKIP 0
185 #define SYMLINK_FOLLOW 1
186 #define SYMLINK_REPLACE 2
188 #define FILE_MBS 0 /* Multi-byte string or 8-bit char */
189 #define FILE_UTF16LE 1 /* UTF-16 Little Endian */
190 #define FILE_UTF16BE 2 /* UTF-16 Big Endian */
191 #define FILE_UTF8 3 /* UTF-8 */
195 int NewFile; /* is in new file mode? */
196 int Quiet; /* is in quiet mode? */
197 int KeepDate; /* should keep date stamp? */
198 int ConvMode; /* 0: ascii, 1: 7bit, 2: iso */
199 int FromToMode; /* 0: dos2unix/unix2dos, 1: mac2unix/unix2mac */
200 int NewLine; /* if TRUE, then additional newline */
201 int Force; /* if TRUE, force conversion of all files. */
202 int Follow; /* 0: skip symlink, 1: follow symbolic link, 2: replace symlink. */
204 int stdio_mode; /* if TRUE, stdio mode */
205 int error; /* an error occurred */
206 int bomtype; /* byte order mark */
207 int add_bom; /* 1: write BOM */
211 int symbolic_link(const char *path);
212 int regfile(char *path, int allowSymlinks, CFlag *ipFlag, char *progname);
213 int regfile_target(char *path, CFlag *ipFlag, char *progname);
214 void PrintUsage(char *progname);
215 void PrintBSDLicense(void);
216 void PrintVersion(char *progname);
218 void PrintLocaledir(char *localedir);
220 FILE* OpenInFile(char *ipFN);
221 FILE* OpenOutFile(int fd);
222 #if defined(__TURBOC__) || defined(__MSYS__)
223 char *dirname(char *path);
226 FILE* MakeTempFileFrom(const char *OutFN, char **fname_ret);
228 int MakeTempFileFrom(const char *OutFN, char **fname_ret);
230 int ResolveSymbolicLink(char *lFN, char **rFN, CFlag *ipFlag, char *progname);
231 FILE *read_bom (FILE *f, int *bomtype);
233 wint_t d2u_getwc(FILE *f, int bomtype);
234 wint_t d2u_ungetwc(wint_t wc, FILE *f, int bomtype);
235 wint_t d2u_putwc(wint_t wc, FILE *f, CFlag *ipFlag);