Commit 68e50cb7 authored by Markus Koschany's avatar Markus Koschany

Imported Upstream version 1.7.9.debian.1

parents
This diff is collapsed.
Distribution file list and directory structure
Copyright (c) 2002-2008 by Christopher Heng. All rights reserved.
-----------------------------------------------------------------
# Main directory
todos.exe precompiled Win32 console application
fromdos.exe precompiled Win32 console application
readme.txt Read this file first
filelist.txt You're currently reading this file
tofrodos.html Tofrodos manual (HTML)
tofrodos.lsm Brief information about tofrodos (for
the Linux Software Map)
COPYING Text file containing the GNU General Public License v2
# source code and makefiles
src\
config.h Change variables here if you're porting tofrodos
emsg.c Error message logging and display function
emsg.h Error messages header
tofrodos.h Main header
utility.h Utility functions header
version.h Version number header
utility.c Utility functions
tofrodos.c Main program and functions
init.c Initialization functions
fromdos.1 Linux/Unix man page for tofrodos
# Makefiles for other MSDOS/Windows compilers
makefile.bc Borland C++ 4.5x/5.0x Makefile
makefile.dj2 DJGPP 2.X Makefile
makefile.dm Digital Mars Makefile
makefile.lcc LCC-Win32 Makefile
makefile.min MinGW Makefile
makefile.wcc Watcom Makefile
makefile.vs7 Visual Studio .NET 2003 makefile
# Makefiles for Linux
Makefile Linux makefile
makefile.gcc Duplicate of Makefile
# Miscellaneous source files (for MSDOS/Windows compilation)
src\lib\
mktemp.c mktemp() for deficient systems
mktemp.h
getopt.c getopt() for deficient systems
getopt.h
# Empty Directories for "make" to use for various platforms/targets
src\bin
src\lib\bin
This diff is collapsed.
# makefile.gcc Makefile for building with the GNU C compiler on Linux.
# Copyright (c) 1996-2005 by Christopher Heng. All rights reserved.
# $Id: makefile.gcc,v 1.2 2005/03/06 05:40:49 chris Exp $ /*
# This makefile requires the GNU make to work (we use the GNU extensions).
# Define the following if you need
#
# DEBUG to add debugging information, eg "make DEBUG=1 all"
ifdef DEBUG
CDEBUG = -g
LDEBUG = -g
else
CDEBUG = -O2
LDEBUG = -s
endif
ifndef VERSTR
VERSTR = 0.0
endif
# programs
CC = gcc
CD = cd
CP = cp
GZIP = gzip
INSTALL = install
LN = ln
LD = gcc
MAKE = make
MKDIR = mkdir
MV = mv
RM = rm -f
TAR = tar
ZIP = zip
# flags
CFLAGS = $(DEFINES) $(TFLAG) $(CDEBUG) -c -Wall
GZIPFLAGS = -9
INSTALLBINFLAGS = -m 755
INSTALLDATAFLAGS = -m 644
LDFLAGS = $(LDEBUG)
LNFLAGS = -sf
RMRECURFLAGS = -rf
TARFLAGS = cvf
ZIPSRCFLAGS = -r -9
# directories
BINDIR = /usr/bin
DISTDIR = tofrodos-$(VERSTR)
LIBDIR = lib
LIBDISTDIR = $(DISTDIR)/lib
MANDIR = /usr/man/man1
# filenames
FROMDOS = fromdos
FROMDOSMAN = fromdos.1
FROMDOSTXT = fromdos.txt
TARGZNAME = $(TARNAME).gz
TARNAME = tofrodos-$(VERSTR).tar
TODOS = todos
ZIPSRCNAME = tfd.zip
# lists of filenames
DISTFILES = config.h \
copying \
emsg.c \
emsg.h \
fromdos \
init.c \
makefile.bc \
makefile.gcc \
makefile.vc \
makefile.wcc \
readme.txt \
todos16.exe \
todos32.exe \
tofrodos.c \
tofrodos.h \
tofrodos.lsm \
utility.c \
utility.h \
version.h \
$(FROMDOSMAN)
LIBDISTFILES = $(LIBDIR)/getopt.c \
$(LIBDIR)/getopt.h \
$(LIBDIR)/mktemp.c \
$(LIBDIR)/mktemp.h
OBJS = emsg.o \
init.o \
tofrodos.o \
utility.o
# implicit rules
.c.o:
$(CC) $(CFLAGS) $<
# user visible rules
all: $(FROMDOS) $(TODOS)
clean:
$(RM) $(OBJS)
clobber: clean
$(RM) $(FROMDOS) $(TODOS)
dist: $(DISTFILES) $(DISTDIR) $(LIBDISTDIR)
$(CP) $(DISTFILES) $(DISTDIR)
$(CP) $(LIBDISTFILES) $(LIBDISTDIR)
$(MV) $(DISTDIR)/makefile.gcc $(DISTDIR)/Makefile
$(MV) $(DISTDIR)/copying $(DISTDIR)/COPYING
$(MV) $(DISTDIR)/readme.txt $(DISTDIR)/README.TXT
($(CD) $(DISTDIR) ; $(LN) $(LNFLAGS) fromdos todos)
distclean: clobber
$(RM) $(RMRECURFLAGS) $(DISTDIR)
install: installman
$(INSTALL) $(INSTALLBINFLAGS) $(FROMDOS) $(BINDIR)
($(CD) $(BINDIR) ; $(LN) $(LNFLAGS) fromdos todos)
installman: $(FROMDOSMAN)
$(INSTALL) $(INSTALLDATAFLAGS) $(FROMDOSMAN) $(MANDIR)
($(CD) $(MANDIR) ; $(LN) $(LNFLAGS) fromdos.1 todos.1)
save:
$(ZIP) $(ZIPSRCFLAGS) $(ZIPSRCNAME) *
tardist: $(TARGZNAME)
# real rules
$(DISTDIR):
$(MKDIR) $(DISTDIR)
$(FROMDOS): $(OBJS)
$(CC) $(LDFLAGS) -o $(FROMDOS) $(OBJS)
$(FROMDOSTXT): $(FROMDOSMAN)
gtbl $(FROMDOSMAN) | groff -Tascii -mandoc | \
troff -Tascii -mandoc | grotty > $@
$(LIBDISTDIR):
$(MKDIR) $(LIBDISTDIR)
$(TARGZNAME): dist
$(TAR) $(TARFLAGS) $(TARNAME) $(DISTDIR)
$(GZIP) $(GZIPFLAGS) $(TARNAME)
$(TODOS): $(FROMDOS)
$(LN) $(LNFLAGS) $(FROMDOS) $(TODOS)
# objects
init.o: init.c config.h emsg.h tofrodos.h utility.h version.h
tofrodos.o: tofrodos.c config.h emsg.h tofrodos.h utility.h version.h
utility.o: utility.c config.h emsg.h tofrodos.h utility.h
# The following information is for the information of the maintainer of
# the package only.
# To make the distribution tar file, you need to define VERSTR to the
# version number. Eg, for a version 1.0 release, define VERSTR=1.0
# Hence a make command line would read
# make VERSTR=1.0 tardist
# If VERSTR is not defined at any time, it defaults to 0.0 (to remind
# you that you forgot something!).
#
# Before making tardist, you need to compile in DOS first.
/*
config.h Handles system dependencies.
Copyright (c) 1996-2008 by Christopher Heng. All rights reserved.
*/
/*
You need an ANSI C compiler. I assume this everywhere. If you
have a pre-ANSI C compiler, it's likely that you have to make
a lot of changes to the sources that you might as well just
rewrite the program. It *is* afterall a trivial program.
I have not specifically designed this program so that it is
portable across systems. The comments below might help if you
are using anything other than the compilers I used to develop
the program. Note that the comments and macros in this file
about system dependencies are not necessarily exhaustive.
1. These macros are defined for the following systems:
System Macros defined
------ --------------
LINUX LINUX, UNIX
MSDOS MSDOS
WIN32 WIN32
2. You need a getopt() implementation. It must support the
usual behaviour of the Unix getopt(), plus the variables
optind, opterr, and optarg.
If your system has the header <getopt.h>, define HAVE_GETOPT_H.
I have defined this for the systems I compile for.
I have supplied my own version of getopt.c and getopt.h in
the lib subdirectory since most MSDOS and Win32 compilers do
not have getopt() in their libraries.
3. If your system has <unistd.h>, define HAVE_UNISTD_H. This is
usually relevant only for Unix systems, although the DJGPP GNU C
compiler has that as well. If you don't have unistd.h, you may
have to declare some standard Unix functions that are usually
found there, such as chown(), chmod(), etc.
4. Note that on MSDOS systems, you will need _splitpath()
and _makepath(). If you use DJGPP, you probably can get away
with defining _splitpath() to call fnsplit(), etc (which I have
done below). Otherwise, you will need to roll your own version.
I think all the commercial MSDOS C compilers have these functions.
5. You will also need stricmp() and strnicmp() on MSDOS or
strcasecmp() or strncasecmp() on Unix. If you have stricmp() and/or
strnicmp() on a Unix system, define HAVE_STRICMP and/or
HAVE_STRNICMP respectively. I assume stricmp() for all non-Unix
systems so if you are neither compiling for Unix or MSDOS, you
better check out my macros below. If you have a Unix system,
defining UNIX here will cause the compiler to use strcasecmp()
and strncasecmp().
6. You will need a mktemp(). On Unix systems, this is probably
declared in <unistd.h>.
Digital Mars declares mktemp() in io.h.
Borland declares mktemp() in dir.h. If you are writing or using
a replacement mktemp() you should put the prototype in a
header called mktemp.h and define HAVE_MKTEMP_H.
Visual C++ declares mktemp() in io.h.
I have supplied my own mktemp.c and mktemp.h for use with
Watcom C/C++ 10.X since these versions of the compiler do not
have mktemp().
If your compiler has mktemp() declared somewhere else (other
than unistd.h on Unix), define MKTEMP_HEADER to be the name
of the header, eg <whatever.h> (include the angle brackets or
double quotes), and HAVE_MKTEMP_H to force inclusion of the
header in the relevant files.
7. tofrodos.c assumes utime.h exists in <sys/utime.h> for
Microsoft's compiler and Watcom C/C++ (which tries to emulate
Microsoft's compiler closely). It assumes that all other compilers
keep utime.h in the standard include directories which are accessible
simply by including <utime.h>. I must confess I have not bothered to
keep this system dependent setting in this file, only noting it here
for completeness. If you find that you have to tweak this for your
system, please let me know.
*/
#if !defined(CONFIG_H_INCLUDED)
#define CONFIG_H_INCLUDED
#if defined(__cplusplus)
extern "C" {
#endif
/* define the systems */
#if defined(__linux__) /* (predefined) */
#if !defined(LINUX)
#define LINUX
#endif
#if !defined(UNIX)
#define UNIX /* make sure this is defined */
#endif
#endif
#if defined(__FreeBSD__) || defined(__OpenBSD__) /* seems to work like Linux... */
#if !defined(LINUX)
#define LINUX
#endif
#if !defined(UNIX)
#define UNIX /* make sure this is defined */
#endif
#endif
#if defined(__MSDOS__)
#if !defined(MSDOS)
#define MSDOS /* make sure this is defined */
#endif
#endif
#if defined(__WIN32__) || defined(__NT__) || defined(_WIN32)
#if !defined(WIN32)
#define WIN32
#endif
#if defined(__BORLANDC__) && defined(MSDOS) /* Borland always defines MSDOS */
#undef MSDOS
#endif
#endif
#if defined(__APPLE__)
#if !defined(UNIX)
#define UNIX
#endif
#define HAVE_UNISTD_H
#define MAXPATHLEN_HEADER <sys/param.h>
#endif
/* define what headers we have (based on the systems) */
#if defined(LINUX)
#define HAVE_GETOPT_H
#define HAVE_UNISTD_H
#endif
#if defined(__WATCOMC__) /* this works on my system only */
#if !defined(HAVE_GETOPT_H)
#define HAVE_GETOPT_H
#endif
#if !defined(HAVE_MKTEMP_H)
#define HAVE_MKTEMP_H
#endif
#if !defined(MKTEMP_HEADER)
#define MKTEMP_HEADER <mktemp.h>
#endif
#endif
#if defined(__BORLANDC__) /* Borland declares mktemp() in dir.h */
#if !defined(HAVE_GETOPT_H)
#define HAVE_GETOPT_H
#endif
#if !defined(HAVE_MKTEMP_H)
#define HAVE_MKTEMP_H
#endif
#if !defined(MKTEMP_HEADER)
#define MKTEMP_HEADER <dir.h>
#endif
#endif
#if defined(__SC__) /* Digital Mars declares mktemp() in <io.h> */
#if !defined(HAVE_GETOPT_H)
#define HAVE_GETOPT_H
#endif
#endif
#if defined(__LCC__) /* LCC-Win32 compiler declares mktemp() in io.h */
#if !defined(HAVE_GETOPT_H)
#define HAVE_GETOPT_H
#endif
#endif
#if defined(_MSC_VER) /* Visual C++ declares mktemp() in <io.h> */
/* which is already included for other reasons. */
#if !defined(HAVE_GETOPT_H)
#define HAVE_GETOPT_H
#endif
#endif
#if defined(__DJGPP__) || defined(__GO32__)
#define HAVE_UNISTD_H /* djgpp has unistd.h which also defines getopt() */
#endif
#if defined(__MINGW32__)
#define HAVE_GETOPT_H
#endif
/* if we are in Unix define stricmp to be strcasecmp and strnicmp to */
/* be strncasecmp. I'm not sure if all Unices have these, but Linux */
/* does. */
#if defined(UNIX)
#if !defined(HAVE_STRICMP)
#define stricmp strcasecmp
#endif
#if !defined(HAVE_STRNICMP)
#define strnicmp strncasecmp
#endif
#endif
/* if you are using a Unix-type system that has the function mkstemp() */
/* define HAVE_MKSTEMP here. If not, just leave it undefined; */
/* mktemp() will be used instead. */
#if defined(LINUX)
#define HAVE_MKSTEMP
#endif
/* Borland, Digital Mars, LCC-Win32, Microsoft's compiler have */
/* S_IREAD and S_IWRITE in their sys/stat.h instead of S_IRUSR */
/* and S_IWUSR which are used by the Unix and Watcom compilers. */
/* Borland's 4.52 compiler however defines these in its 32 bit */
/* compiler. Since I can't be sure which versions have already */
/* defined these, I define it for all Borland 32 bit targets. */
#if defined(_MSC_VER) || defined(__SC__) || defined(__LCC__) || (defined(__BORLANDC__) && !defined(__FLAT__))
#define S_IRUSR S_IREAD
#define S_IWUSR S_IWRITE
#endif
/* This block is for Unix-type systems only. It is not relevant to */
/* MSDOS and Windows systems. */
/* Basically we need to have MAXPATHLEN defined somewhere. This is */
/* the maximum size that a pathname can be, and it is used to allocate */
/* storage for a pathname we construct in the program. In BSD systems */
/* and Linux systems, MAXPATHLEN is defined in <sys/param.h>. If your */
/* system has MAXPATHLEN defined somewhere, put the header name in */
/* MAXPATHLEN_HEADER (eg, you can try checking your <limits.h> */
/* and <sys/param.h> to see if MAXPATHLEN is there). If not, you will just */
/* have to create some sort of value for MAXPATHLEN by defining it below. */
/* Note: I realize that there are ways around */
/* this need for a constant value, but I can't be bothered to implement it. */
/* You might also want to try using pathconf() in a test program to find out */
/* if your system returns any sensible value for _PC_PATH_MAX. If all else */
/* fails, you might want to consider the Linux value of 4096 for MAXPATHLEN. */
/* That is, add a line like */
/* #define MAXPATHLEN 4096 */
/* below. */
#if defined(LINUX)
#define MAXPATHLEN_HEADER <sys/param.h>
#endif
/* End of block that is relevant for Unix-type systems only */
/* djgpp does not have _splitpath() and _makepath(), but they do have */
/* functional equivalents which are declared in <dir.h> */
#if defined(__DJGPP__) || defined(__GO32__)
#define _splitpath fnsplit
#define _makepath fnmerge
#endif
/* Later versions of LCC-Win32 no longer declares utime() */
#if defined(__LCC__)
#define utime(a,b) _utime(a,b)
#endif
#if defined(__cplusplus)
}
#endif
#endif /* CONFIG_H_INCLUDED */
/*
emsg.c Initialisation functions.
Copyright (c) 2005 by Christopher Heng. All rights reserved.
$Id: emsg.c,v 1.3 2005/03/14 14:18:40 chris Exp $
*/
/* this should always be first */
#include "config.h"
/* standard headers */
#include <stdarg.h> /* va_arg and family */
#include <stdio.h> /* fprintf(), fopen(), fclose() */
#include <stdlib.h> /* atexit() */
/* our own headers */
#include "emsg.h"
#include "tofrodos.h"
/* macros */
#if defined(MSDOS) || (WINDOWS)
#define ERROR_LOG_MODE "at"
#else
#define ERROR_LOG_MODE "a"
#endif
/* data local to this file */
static FILE * errorfp ;
/* local functions */
static void close_error_file ( void ) ;
void emsg ( char * message, ... )
{
va_list argp ;
if (errorfp == NULL) {
if (errorlogfilename == NULL) {
errorfp = stderr ;
}
else {
errorfp = fopen ( errorlogfilename, ERROR_LOG_MODE );
if (errorfp == NULL) {
fprintf( stderr, EMSG_ERRORLOG, progname, errorlogfilename );
errorfp = stderr ;
}
else {
/* close error file on exit (not needed, but just being pedantically neat) */
atexit( close_error_file ); /* ignore errors */
}
}
}
fprintf( errorfp, "%s: ", progname );
va_start( argp, message );
vfprintf( errorfp, message, argp );
va_end( argp );
return ;
}
static void close_error_file ( void )
{
/* there's no need to check for stderr, since we should not have set this function */
/* on exit() if only stderr were used */
if (errorfp != NULL) {
fclose( errorfp );
}
return ;
}
/*
emsg.h Error messages.
Copyright (c) 1996-2003 by Christopher Heng. All rights reserved.
$Id: emsg.h,v 1.4 2005/03/14 14:18:40 chris Exp $
*/
#if !defined(EMSG_H_INCLUDED)
#define EMSG_H_INCLUDED
#if defined(__cplusplus)
extern "C" {
#endif
/* macros */
#define EMSG_BAKFILENAME "File cannot have a .bak extension "\
"when used with -b flag.\n"
#define EMSG_CONVERT "File read/write error while "\
"converting %s.\n"
#define EMSG_INTERNAL "Internal error: %s.\n"
#define EMSG_NOFILENAME "Need to specify filename or redirect "\
"stdin.\n"
#define EMSG_NOMEM "Insufficient memory to run program.\n"
#define EMSG_NOTEMPNAME "Unable to create temporary file for converting %s.\n"
#define EMSG_OPENFILE "Unable to open file %s.\n"
#define EMSG_SIGNAL "Terminated by user.\n"
#define EMSG_WRONGDOSVER "Requires DOS 3.1 and above.\n"
#define EMSG_ACCESSFILE "Unable to access file %s.\n"
#define EMSG_NOTREADABLE "No read permission for %s.\n"
#define EMSG_NOTWRITEABLE "No write permission for %s. Use -f to force conversion.\n"
#define EMSG_CHOWN "Unable to change ownership of %s.\n"
#define EMSG_SYMLINK "Unable to dereference symbolic link %s.\n"
#define EMSG_CREATETEMP "Unable to create temporary file %s for converting %s.\n"
#define EMSG_ERRORLOG "%s: Unable to create error log file %s. Defaulting to stderr.\n" /* special case with progname */
/* internal error macros */
#define EINTNL_DIRECTION "unknown direction"
/* verbose messages */
#define VERBOSE_CONVERTING "Converting %s\n"
#define VERBOSE_SYMLINKSRC "%s resolves to %s\n"
/* function declarations */
extern void emsg ( char * message, ... );
#if defined(__cplusplus)
}
#endif
#endif
.TH tofrodos 1 "Version 1.7.9" "2011"
.SH NAME
tofrodos
\- Converts text files between DOS and Unix formats.
.SH SYNOPSIS
.B fromdos
[
.I options
] [file...]
.br
.B todos
[
.I options
] [file...]
.br
.SH DESCRIPTION
DOS text files traditionally have carriage return and line feed pairs
as their newline characters while Unix text files have the line feed
as their newline character.
.I fromdos
converts text files from the DOS format to the Unix format, while
.I todos
converts text files from the Unix format to the DOS format.
.PP
The programs accept multiple filenames and wildcards as their arguments.
You may also use them in a pipe.
If either program finds its input redirected, it will process stdin
and place the output on stdout.
.SH OPTIONS
.TP
.BI \-a
Always convert. If converting from DOS to Unix, this option will
cause the program to remove ALL carriage returns. The default is to
remove carriage returns only if they are followed by line feeds.
If converting from
Unix to DOS, this option will cause the program to convert ALL
linefeeds to carriage return pairs. The default is to convert linefeeds
only if they are not already preceded by a carriage return.
.TP
.BI \-b
Make a backup of original file. The original
file is renamed with the original filename and a
.I .bak
extension. For example, a file called "filename.ext" becomes "filename.ext.bak".
Important: the program behaves differently if it is compiled for DOS (as compared to being compiled for Windows, Linux,
Mac OS X or other systems). In view of the filename restrictions present on DOS, the DOS executable
will strip the original file extension, if any, from the file
before appending the
.I .bak
extension. For example, "filename.ext" becomes "filename.bak".
.TP
.BI \-d
Convert from DOS to Unix. This forces the program to convert the file in
a particular direction. By default, if the program is named
.I fromdos
or
.I dos2unix,
it will assume that the input file is in a DOS format and convert it to
a Unix format. If the program is named
.I todos
or
.I unix2dos,
it will assume that the input file is in a Unix format and convert it to
a DOS format. Using the
.I \-d
option forces the program to convert from a DOS format
to a Unix format regardless of how the program is named. Likewise, using the
.I \-u
option forces the program to convert from a Unix format to a DOS format
regardless of the name of the program.
.TP
.BI \-e
Abort processing on any error in any file. Normally, the program will
simply skip to process the next file on the command line when it encounters
any errors. This option causes it to abort on errors.
.TP
.BI \-f
Force: convert even if the file is not writeable (read-only). By default,
if
.I fromdos
or
.I todos
finds that the file does not have write permission, it will not process
that file. This option forces the conversion even if the file is read-only.
.TP
.BI \-h
Display a short help screen on the program usage and quit.
.TP
.BI \-l <logfile>
Log error messages to <logfile>. Note that if your command line has an
error, such as when you specify an unknown option, the error message for the
command line option error will be issued to stderr instead and not logged.
.TP
.BI \-o
Overwrite the original file (no backup). This is the default.
.TP
.BI \-p
Preserve file ownership and time. On systems like Linux, the file
ownership will only be preserved if the user is root, otherwise it
will just set the file time and silently fail the change of file
ownership. If you want a warning message when the file ownership
cannot be changed, use \-v.
.TP
.BI \-u
Convert from Unix to DOS. See the
.I \-d
option above for more information.
.TP
.BI \-v
Verbose.
.TP
.BI \-V
Show version message and quit.
.SH AUTHOR
The program and its documentation are copyrighted (c) 1996-2008 by
Christopher Heng. All rights reserved. They are distributed under
the terms of the GNU General Public License Version 2.
.PP
The latest version of tofrodos can be obtained from
.br
http://www.thefreecountry.com/tofrodos/index.shtml
/*
init.c Initialisation functions.
Copyright 1996-2011 Christopher Heng. All rights reserved.
*/
/* this should always be first */
#include "config.h"
/* standard headers */
#if defined(HAVE_GETOPT_H)
#include <getopt.h> /* getopt() (what else?) */
#endif
#include <signal.h> /* signal() (surprise!) */
#include <stdlib.h> /* _splitpath(), _MAX_FNAME, exit, EXIT_SUCCESS */
#include <stdio.h> /* EOF */
#include <string.h> /* stricmp() */
#if defined(HAVE_UNISTD_H)
#include <unistd.h>
#endif
#if defined(__DJGPP__) || defined(__GO32__)
#include <dir.h>
#endif
/* our own headers */
#include "emsg.h"
#include "tofrodos.h"
#include "utility.h"
#include "version.h"
/* macros */