Discarded tofrodos sources files that were accidentally kept around
This commit is contained in:
parent
1a260f04ce
commit
ae1454911c
26 changed files with 0 additions and 3459 deletions
|
@ -1,339 +0,0 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
675 Mass Ave, Cambridge, MA 02139, USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Library General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
Appendix: How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) 19yy <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) 19yy name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Library General
|
||||
Public License instead of this License.
|
|
@ -1,60 +0,0 @@
|
|||
Distribution file list and directory structure for Tofrodos
|
||||
http://www.thefreecountry.com/tofrodos/index.shtml
|
||||
Copyright 2002-2013 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.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 mkstemp() 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
|
Binary file not shown.
|
@ -1,429 +0,0 @@
|
|||
Tofrodos Ver 1.7.13
|
||||
Copyright 1996-2013 Christopher Heng. All rights reserved.
|
||||
----------------------------------------------------------
|
||||
|
||||
|
||||
Contents
|
||||
--------
|
||||
|
||||
1. What Is Tofrodos?
|
||||
2. How To Install Tofrodos
|
||||
3. Compiling Tofrodos In Linux, Mac OS X and Unix-type Systems
|
||||
4. Compiling Tofrodos In Msdos And Windows
|
||||
5. Porting To Other Systems
|
||||
6. History Of Changes
|
||||
7. Copyright And Contacting The Author
|
||||
|
||||
|
||||
1. What Is Tofrodos?
|
||||
--------------------
|
||||
|
||||
DOS text files traditionally have CR/LF (carriage return/line feed) pairs
|
||||
as their new line delimiters while Unix text files traditionally have
|
||||
LFs (line feeds) to terminate each line.
|
||||
|
||||
Tofrodos comprises two programs, "fromdos" and "todos", which convert
|
||||
ASCII and Unicode UTF-8 text files to and from these formats. Use "fromdos"
|
||||
to convert DOS text files to the Unix format, and "todos" to convert Unix
|
||||
text files to the DOS format.
|
||||
|
||||
|
||||
2. How To Install Tofrodos
|
||||
--------------------------
|
||||
|
||||
a. Windows 9x/ME/NT/2k/XP/Vista/7
|
||||
|
||||
The Tofrodos package comes with sources as well as precompiled
|
||||
executables (binaries) for the Windows console mode. If you
|
||||
want to install everything, just unpack the archive into
|
||||
a directory of your choice.
|
||||
|
||||
Alternatively, if you only want to use the executables and
|
||||
don't want to bother with the sources, just do the following
|
||||
from a Windows console (command prompt):
|
||||
|
||||
copy todos.exe {destination directory}\todos.exe
|
||||
copy fromdos.exe {destination directory}\fromdos.exe
|
||||
copy tofrodos.html {destination directory}\tofrodos.html
|
||||
|
||||
To read the manual, open the tofrodos.html file with a web browser.
|
||||
|
||||
If you work on the command line often, you might want to
|
||||
consider putting the directory where you placed the tofrodos
|
||||
executables in your PATH.
|
||||
|
||||
Note that if you prefer the names "dos2unix.exe" and
|
||||
"unix2dos.exe", just make a copy of "todos.exe" (or "fromdos.exe")
|
||||
under those names. Tofrodos automatically detects the name under
|
||||
which it is run, and will change its behaviour accordingly.
|
||||
(That is, "dos2unix" will convert files from the DOS format to
|
||||
the Unix format, and "unix2dos" will convert files from the
|
||||
Unix format to the DOS format.)
|
||||
|
||||
b. MSDOS/FreeDOS and Clones
|
||||
|
||||
You will need to compile the sources. See the section
|
||||
"Compiling Tofrodos in MSDOS and Windows", particularly
|
||||
the section on using OpenWatcom C/C++.
|
||||
|
||||
c. Linux, Mac OS X, Unix-type systems
|
||||
|
||||
See the section "Compiling Tofrodos in Linux, Mac OS X
|
||||
and Unix-type Systems"
|
||||
|
||||
d. Other systems
|
||||
|
||||
See the section "Porting to Other Systems".
|
||||
|
||||
|
||||
3. Compiling Tofrodos In Linux, Mac OS X and Unix-type Systems
|
||||
--------------------------------------------------------------
|
||||
|
||||
I've stopped distributing precompiled versions of Tofrodos for
|
||||
Linux for two main reasons. There are just too many distributions
|
||||
to compile for and it's a simple matter to do it yourself. The
|
||||
process is painless and fast, since the source code compiles
|
||||
out-of-the-box.
|
||||
|
||||
To compile everything, simply do the following:
|
||||
|
||||
cd src
|
||||
make all
|
||||
|
||||
You can then install by typing
|
||||
|
||||
make install
|
||||
|
||||
Since you're installing the binary and manual page into your
|
||||
system directories with this command, you'll need to be
|
||||
logged in as root (either directly, or via "su" or "sudo").
|
||||
(I know this is stating the obvious, but it's just in case
|
||||
you're new to installing programs.)
|
||||
|
||||
To install them somewhere other than /usr/bin and /usr/man/man1,
|
||||
redefine BINDIR and MANDIR for the binary and manual page
|
||||
destinations respectively. For example, to install the binaries
|
||||
in /usr/local/bin and the manual page in /usr/local/man/man1,
|
||||
do the following:
|
||||
|
||||
make BINDIR=/usr/local/bin MANDIR=/usr/local/man/man1 install
|
||||
|
||||
Note that Mac OS X does not have a specific directory for
|
||||
man pages. As such, simply typing "make install" will fail on
|
||||
that system. You will need to set MANDIR to some directory that
|
||||
you know exists.
|
||||
|
||||
To read the manual page after installation, simply type
|
||||
|
||||
man fromdos
|
||||
|
||||
If you've installed MANDIR to a non-standard location, so
|
||||
that the above does not work (such as you may have done
|
||||
on Mac OS X), just specify the path, for example:
|
||||
|
||||
man ./fromdos.1
|
||||
|
||||
There should be no errors or warnings in the compilation.
|
||||
|
||||
Note that if you prefer the names "dos2unix" and
|
||||
"unix2dos", just rename the binaries accordingly and you're done.
|
||||
Tofrodos automatically detects the name under which it is run,
|
||||
and will change its behaviour accordingly. That is, "dos2unix"
|
||||
will convert files from the DOS format to the Unix format,
|
||||
and "unix2dos" will convert files from the Unix format to the
|
||||
DOS format. No code changes are necessary.
|
||||
|
||||
|
||||
4. Compiling Tofrodos In MSDOS And Windows
|
||||
------------------------------------------
|
||||
|
||||
Tofrodos comes with binaries (executables) for the Windows console
|
||||
mode. However, if you prefer to recompile tofrodos yourself,
|
||||
there are a few makefiles you may use, depending on the compiler
|
||||
you have on your system.
|
||||
|
||||
To compile Tofrodos under MSDOS or Windows 9x/XP/Vista/7, simply use
|
||||
the appropriate makefile for your compiler or roll your own.
|
||||
|
||||
If you want a trouble-free compilation, you should probably use
|
||||
the Open Watcom C compiler (which is free), since that is the
|
||||
compiler I currently use for creating the precompiled binaries
|
||||
for Windows.
|
||||
|
||||
In case it's not clear from the above paragraph, please note
|
||||
that although I provide makefiles for a few other compilers, most
|
||||
of them were only tested with earlier versions of Tofrodos
|
||||
and not the current version.
|
||||
|
||||
Makefiles for use with the following compilers and their MAKE
|
||||
utilities are as follows:
|
||||
|
||||
makefile.wcc OpenWatcom C/C++ 1.9 and WMAKE.EXE (DOS 16/32 bit
|
||||
and Win32 targets)
|
||||
makefile.vs7 Visual Studio .NET 2003 and NMAKE.EXE (Win32 target)
|
||||
makefile.min MinGW 3.1.0 and mingw32-make.exe (Win32 target)
|
||||
Makefile Linux makefile. Do not use for Windows or DOS.
|
||||
|
||||
Note that the file Makefile is for use with the GNU C compiler and
|
||||
GNU make on a Linux system. Do not use it under Windows or MSDOS.
|
||||
To avoid using it by default, make sure you specify the makefile
|
||||
name on your compiler system's "make" command line.
|
||||
|
||||
These makefiles can probably be adapted for other compilers or other
|
||||
versions of the above compilers.
|
||||
|
||||
You can get free versions of most (if not all) of the supported
|
||||
compilers from
|
||||
http://www.thefreecountry.com/compilers/cpp.shtml
|
||||
|
||||
i. Recompiling with OpenWatcom C/C++
|
||||
|
||||
To recompile with OpenWatcom C/C++, copy the files
|
||||
src\startup\wildargv.c
|
||||
src\startup\initarg.h
|
||||
from your WATCOM directory to the src\lib subdirectory. For example, if
|
||||
you installed Watcom to c:\watcom, and you expanded the tofrodos
|
||||
package into d:\tofrodos, do the following:
|
||||
copy c:\watcom\src\startup\wildargv.c d:\tofrodos\src\lib
|
||||
copy c:\watcom\src\startup\initarg.h d:\tofrodos\src\lib
|
||||
|
||||
If you cannot find wildargv.c on your hard disk, you probably did not
|
||||
install the startup source code or have somehow deleted it. Just reinstall
|
||||
OpenWatcom again, this time with the necessary options.
|
||||
|
||||
To create a Windows console executable, the following command line can be
|
||||
used:
|
||||
cd src
|
||||
wmake -f makefile.wcc TARGET=Win32 all
|
||||
|
||||
To create the MSDOS executables, do the following:
|
||||
cd src
|
||||
wmake -f makefile.wcc TARGET=16bit all
|
||||
|
||||
Make sure you do a
|
||||
wmake -f makefile.wcc clean
|
||||
before compiling again for a different target or the response files
|
||||
and object files will be wrong for the new target.
|
||||
|
||||
Note that the included precompiled Windows executable was compiled
|
||||
with OpenWatcom 1.9.
|
||||
|
||||
ii. Recompiling with Visual C++
|
||||
|
||||
Visual C++ (from Visual Studio) can only create Win32 console
|
||||
executables. Use the following procedure to create todos.exe
|
||||
and fromdos.exe.
|
||||
|
||||
cd src
|
||||
nmake -f makefile.vc all
|
||||
|
||||
There should be no warnings or errors. Note that the latest
|
||||
version of tofrodos was not tested with Visual C++.
|
||||
|
||||
iii. Recompiling with MinGW
|
||||
|
||||
To compile with MinGW, use the GNU Make utility (mingw32-make.exe)
|
||||
with makefile.min as follows:
|
||||
|
||||
cd src
|
||||
mingw32-make -f makefile.min all
|
||||
|
||||
Note that the latest version of tofrodos was not tested with
|
||||
MinGW. However, since MinGW uses GCC, and I test all versions of
|
||||
tofrodos using GCC on Linux, it should theoretically work fine.
|
||||
|
||||
|
||||
5. Porting To Other Systems
|
||||
---------------------------
|
||||
|
||||
If you want to compile Tofrodos for a system other than Linux, MSDOS
|
||||
or Windows you may or may not have some work in store for you. The
|
||||
program is fairly trivial, so the work you need to do is probably
|
||||
(hopefully) minimal.
|
||||
|
||||
The first place to look into is probably the config.h file, where I
|
||||
tried to place as many system and compiler macros as I could bother.
|
||||
|
||||
If you are compiling on other Unix systems, tweaking the config.h file
|
||||
macros may well be all that you need to do. I have reports of success
|
||||
with people using it on HP-UX and others.
|
||||
|
||||
|
||||
6. History Of Changes
|
||||
---------------------
|
||||
|
||||
Dates given are the dates where the code base was finalised and do not
|
||||
necessarily refer to the date of public release.
|
||||
|
||||
Version 1.7.13 25 October 2013
|
||||
- [Hurd, NetBSD, FreeBSD kernel] Added support for Hurd,
|
||||
NetBSD and FreeBSD kernel (a system that uses the FreeBSD
|
||||
kernel, but is not necessarily the full FreeBSD system).
|
||||
As a side benefit, tofrodos is slightly more portable since
|
||||
it no longer depends on certain system-specific macros
|
||||
(namely MAXPATHLEN from sys/param.h).
|
||||
- [All] Tofrodos now displays information on what to do if
|
||||
it is not able to rename the temporary file back to the
|
||||
original filename after a successful conversion.
|
||||
- [All] The -a option is now documented as "deprecated",
|
||||
since you shouldn't use it unless you have an unusual
|
||||
text file that you're trying to fix.
|
||||
- [All] Minor improvements to the documentation.
|
||||
|
||||
Version 1.7.12 1 October 2012
|
||||
- [All] Under certain error conditions, Tofrodos may fail to
|
||||
remove the temporary files that it creates. This is now fixed.
|
||||
- [All] Fixed another bug where an exit code of 0, instead of 1,
|
||||
is returned under certain failure conditions.
|
||||
- [MSDOS] Although MSDOS is not a multitasking system, and
|
||||
thus should not need it, the DOS port of Tofrodos now also uses
|
||||
my implementation of mkstemp(). This simplifies maintenance
|
||||
since I have fewer code paths to test.
|
||||
- [Windows] Support for compiling the source code using
|
||||
DJGPP 2, Borland C/C++, LCC-Win32 and Digital Mars C has been
|
||||
removed. Please use one of the other supported compilers (eg,
|
||||
Open Watcom C, etc).
|
||||
- [All] The documentation now has information about the exit
|
||||
codes returned by Tofrodos.
|
||||
|
||||
Version 1.7.11 27 September 2012
|
||||
- [All] tofrodos now consistently returns an exit code of 1 when
|
||||
there's a failure. Previously, under certain error conditions,
|
||||
it could return an exit code of -1 (which is not a valid
|
||||
exit code for some operating systems).
|
||||
- [Windows] This version now includes an implementation of
|
||||
mkstemp() for Windows (when compiled with Open Watcom C),
|
||||
bringing the Windows (Open Watcom) port of tofrodos up to
|
||||
par with versions for systems like Linux and Mac OS X which
|
||||
provide mkstemp() in their C libraries. Hopefully, this will
|
||||
help those of you who run multiple instances of tofrodos at
|
||||
the same time in the same directory.
|
||||
- [Windows] Fixed a bug introduced in 1.7.9 where the Windows port
|
||||
of tofrodos always creates the temporary file in the current
|
||||
directory instead of the directory where the target file is.
|
||||
- [Mac OS X] The Mac OS X port of tofrodos now uses mkstemp() to
|
||||
create the temporary file the way it does on Linux.
|
||||
- [Mac OS X] Added more information in readme.txt for Mac users.
|
||||
- [All] Improved documentation about the -p and -b options.
|
||||
|
||||
Version 1.7.10 25 September 2012
|
||||
- Limited (beta) distribution only, not released for general use.
|
||||
If you have this version, please upgrade to 1.7.11.
|
||||
|
||||
Version 1.7.9 21 February 2011
|
||||
- [Windows, Linux, Mac OS X, Unix] The behaviour of the -b option
|
||||
(create backup file) has been changed to be more useful on systems
|
||||
with support for long filenames and an arbitrary number of file
|
||||
extensions (ie, all systems except MSDOS). It now backs up
|
||||
"filename.ext" as "filename.ext.bak" instead of "filename.bak".
|
||||
Note that with this version, the DOS version no longer behaves
|
||||
the same way (when the -b option is used) as the Windows, Linux,
|
||||
Mac OS X, *BSD and other Unix versions, since DOS systems have
|
||||
filename limitations. At least this way, we're not held back by
|
||||
the least common denominator (DOS), especially since few people
|
||||
use DOS nowadays.
|
||||
- [All] The documentation has been updated to explain the behaviour of
|
||||
the -b option in more detail.
|
||||
|
||||
Version 1.7.8 8 April 2008
|
||||
- [Mac OS X] Fixed corrupted portion of config.h that only shows up when
|
||||
compiling under Mac OS X (sorry - I don't know what happened)
|
||||
|
||||
Version 1.7.7 1 April 2008
|
||||
- [Mac OS X] Added support for compiling tofrodos under Mac OS X.
|
||||
- [FreeBSD] Added support for compiling tofrodos under FreeBSD.
|
||||
- [OpenBSD] Added support for compiling tofrodos under OpenBSD (not tested).
|
||||
- [All] Fixed typos in documentation (Unix man page and HTML version).
|
||||
|
||||
Version 1.7.6 15 March 2005
|
||||
- [All systems] New option: -l allows you to send the error messages to
|
||||
a log file. It's particularly convenient for systems with less powerful
|
||||
command line shells that do not allow you to easily redirect stderr.
|
||||
- [All systems] Fixed: all error and verbose messages are now sent to
|
||||
stderr or the error log file (if -l is given).
|
||||
- [Windows] Older versions of compilers like Borland 4.X and 5.0,
|
||||
Watcom 10.X and Visual C++ 6.0 no longer have makefiles. Use the latest
|
||||
versions; all these compilers are now available free of charge from
|
||||
their vendors so using the latest version to compile tofrodos should
|
||||
not be a great hardship.
|
||||
- [All systems] Other minor fixes.
|
||||
|
||||
Version 1.7 26 November 2003
|
||||
- [Linux/Unix] Bug fix: now handles symbolic link arguments correctly.
|
||||
This bug only affects Unix-type sytems (like Linux, FreeBSD, OpenBSD,
|
||||
etc).
|
||||
- [Linux] tofrodos now uses mkstemp() to create the temporary file to
|
||||
avoid a race between file name creation and opening which may occur
|
||||
when using mktemp(). If you use a non-Linux system, and have
|
||||
mkstemp(), you can take advantage of this by defining HAVE_MKSTEMP
|
||||
in config.h (defined by default for Linux only).
|
||||
- [Linux/Unix] "make install" now installs to /usr/bin by default (you
|
||||
can still change this easily) since Linux distributions using tofrodos
|
||||
appear to use this value. (Makes it easier for maintainers of those
|
||||
distributions.)
|
||||
- [All systems] Made some error messages a bit more informative.
|
||||
- [All systems] Verbose mode is slightly more informative.
|
||||
- [Windows] Added support for compiling with the MinGW (GNU) C Compiler
|
||||
on Win32 systems.
|
||||
- [All systems] Added an HTML version of the manual page. Useful for
|
||||
systems that don't have a built-in facility to read a man page (like
|
||||
MSDOS and Windows).
|
||||
|
||||
Version 1.6 1 July 2002
|
||||
Added support for LCC-Win32 and BCC 5.5
|
||||
|
||||
Version 1.5 19 June 2002
|
||||
Minor fixes to documentation.
|
||||
Added support for the Digital Mars C/C++ compiler (Win32 console mode)
|
||||
|
||||
Version 1.4 16 March 1999
|
||||
Fixed bug when using -b on a file not in the current directory.
|
||||
Added RPM support.
|
||||
|
||||
Version 1.3 8 October 1997
|
||||
Added new option (-p) to preserve file ownership and time.
|
||||
Added support for Win32 compilation and some compilers under DOS and
|
||||
Windows.
|
||||
|
||||
Version 1.2 5 April 1997
|
||||
(Internal version - not publicly released.)
|
||||
|
||||
Version 1.1 16 December 1996
|
||||
Fixed bug in creation of temporary filename on Linux.
|
||||
Fixed bug in creation of backup filename on Linux.
|
||||
|
||||
Version 1.0 22 June 1996 Initial version.
|
||||
|
||||
|
||||
7. Copyright And Contacting The Author
|
||||
--------------------------------------
|
||||
|
||||
The program and its accompanying files and documentation are
|
||||
Copyright 1996-2012 Christopher Heng. All rights reserved.
|
||||
They are distributed under the terms of the GNU General Public License
|
||||
Version 2, a copy of which is enclosed in this package in the file COPYING.
|
||||
|
||||
You can retrieve the latest version of tofrodos from the following
|
||||
website:
|
||||
http://www.thefreecountry.com/tofrodos/index.shtml
|
||||
|
||||
If you need to contact me, you can use the feedback form at the
|
||||
following URL:
|
||||
http://www.thefreecountry.com/feedback.php
|
||||
|
||||
While I generally like to hear from you if you are using this program,
|
||||
especially if you find any bugs in it, I make no promises about fixing
|
||||
anything or even replying. If you do contact me, please also let me have
|
||||
the following information:
|
||||
|
||||
1. The version of tofrodos that you are using;
|
||||
2. The operating system (and its version) on which you are
|
||||
running the program (eg, Debian Linux [Woody], or MSDOS 6.22,
|
||||
Windows 95/98/ME/NT/2k/XP/Vista/7, Mac OS/X with version number,
|
||||
or all of the above).
|
||||
If the bug only surfaces in one of the operating systems and not
|
||||
the other, please also note this.
|
||||
3. Any other information which you think might be relevant.
|
||||
|
||||
This will help me give you a more relevant reply (and also to trace
|
||||
whatever bugs that may be present).
|
|
@ -1,97 +0,0 @@
|
|||
# makefile.gcc Makefile for building with the GNU C compiler on Linux.
|
||||
# Copyright 1996-2012 by Christopher Heng. All rights reserved.
|
||||
|
||||
# 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
|
||||
|
||||
# programs
|
||||
CC = gcc
|
||||
CD = cd
|
||||
CP = cp
|
||||
GZIP = gzip
|
||||
INSTALL = install
|
||||
LN = ln
|
||||
LD = gcc
|
||||
MAKE = make
|
||||
MKDIR = mkdir
|
||||
MV = mv
|
||||
RM = rm -f
|
||||
|
||||
# flags
|
||||
CFLAGS = $(DEFINES) $(TFLAG) $(CDEBUG) -c -Wall
|
||||
GZIPFLAGS = -9
|
||||
INSTALLBINFLAGS = -m 755
|
||||
INSTALLDATAFLAGS = -m 644
|
||||
LDFLAGS = $(LDEBUG)
|
||||
LNFLAGS = -sf
|
||||
RMRECURFLAGS = -rf
|
||||
|
||||
# directories
|
||||
BINDIR = /usr/bin
|
||||
LIBDIR = lib
|
||||
MANDIR = /usr/man/man1
|
||||
|
||||
# filenames
|
||||
FROMDOS = fromdos
|
||||
FROMDOSMAN = fromdos.1
|
||||
FROMDOSTXT = fromdos.txt
|
||||
TODOS = todos
|
||||
ZIPSRCNAME = tfd.zip
|
||||
|
||||
# lists of filenames
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
|
||||
# real rules
|
||||
$(FROMDOS): $(OBJS)
|
||||
$(CC) $(LDFLAGS) -o $(FROMDOS) $(OBJS)
|
||||
|
||||
$(FROMDOSTXT): $(FROMDOSMAN)
|
||||
gtbl $(FROMDOSMAN) | groff -Tascii -mandoc | \
|
||||
troff -Tascii -mandoc | grotty > $@
|
||||
|
||||
$(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
|
|
@ -1,174 +0,0 @@
|
|||
/*
|
||||
config.h Handles system dependencies.
|
||||
Copyright (c) 1996-2013 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 will 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. 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 mkstemp(). On Unix systems, this is probably
|
||||
declared in <unistd.h>.
|
||||
|
||||
I have supplied my own mktemp.c and mktemp.h for use with the
|
||||
Open Watcom C (Windows/DOS) and Visual C++ (Windows) compilers
|
||||
that includes my implementation of mkstemp(). If your system
|
||||
does not have mkstemp(), you might try to see if you can use
|
||||
this. (It's in the lib directory.)
|
||||
|
||||
If your compiler has mkstemp() 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(__FreeBSD_kernel__) || \
|
||||
defined(__OpenBSD__) || defined(__NetBSD__) || defined(__GNU__)
|
||||
/* these systems seem to work like Linux. Note to self: __GNU__ == Hurd */
|
||||
#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
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#if !defined(UNIX)
|
||||
#define UNIX
|
||||
#endif
|
||||
#define HAVE_UNISTD_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(WIN32) || defined(MSDOS)
|
||||
#if !defined(HAVE_MKTEMP_H)
|
||||
#define HAVE_MKTEMP_H
|
||||
#endif
|
||||
#if !defined(MKTEMP_HEADER)
|
||||
#define MKTEMP_HEADER <mktemp.h>
|
||||
#endif
|
||||
#if !defined(HAVE_GETOPT_H)
|
||||
#define HAVE_GETOPT_H
|
||||
#endif
|
||||
#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
|
||||
|
||||
/* Microsoft's compiler havs S_IREAD and S_IWRITE in its sys/stat.h */
|
||||
/* but not S_IRUSR and S_IWUSR which I use. */
|
||||
#if defined(_MSC_VER)
|
||||
#define S_IRUSR S_IREAD
|
||||
#define S_IWUSR S_IWRITE
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_H_INCLUDED */
|
|
@ -1,68 +0,0 @@
|
|||
/*
|
||||
emsg.c Error message printing functions.
|
||||
Copyright (c) 2005-2012 by Christopher Heng. All rights reserved.
|
||||
|
||||
*/
|
||||
|
||||
/* 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 ;
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
/*
|
||||
emsg.h Error messages.
|
||||
Copyright 1996-2013 by Christopher Heng. All rights reserved.
|
||||
*/
|
||||
|
||||
#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 generate temporary filename 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 */
|
||||
#define EMSG_RENAMEBAK "Unable to save original file %s as %s.\n"\
|
||||
"Reason: %s\n"
|
||||
#define EMSG_RENAMETMP "Unable to rename temporary file %s back to %s after converting it.\n"\
|
||||
"Reason: %s\n"\
|
||||
"Please recover your converted file by manually renaming it back.\n"
|
||||
|
||||
/* 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
|
|
@ -1,126 +0,0 @@
|
|||
.TH tofrodos 1 "Version 1.7.13" "2013"
|
||||
.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 ASCII and Unicode UTF-8 text files from the DOS format to the Unix format, while
|
||||
.I todos
|
||||
converts them 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
|
||||
This option is deprecated. Do not use it unless you know what you're doing. By default,
|
||||
Tofrodos does the expected thing for text files. That is, when converting from
|
||||
DOS to Unix, it will remove carriage returns only if they are followed by line feeds.
|
||||
When converting from Unix to DOS, it will add carriage returns only if the linefeeds
|
||||
are not already preceeded by carriage returns. When Tofrodos is run on a normal text file that
|
||||
has already been converted, the resulting file should be identical to the original. However,
|
||||
if you use this option, the program will always remove carriage returns in the DOS to Unix mode
|
||||
and always add carriage returns in the Unix to DOS mode even if it is not appropriate.
|
||||
.TP
|
||||
.BI \-b
|
||||
Make a backup of original file. The original file with a
|
||||
.I .bak
|
||||
extension appended to the original filename, silently replacing any existing file of that name.
|
||||
For example, a file called "filename.ext" becomes "filename.ext.bak" replacing any existing file
|
||||
having the name "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 the program 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 Unix-type systems (like Linux). On Windows and MSDOS, it only
|
||||
preserves the file time. Note that on many Unix-type systems, including Linux, the file
|
||||
ownership will only be preserved if the program is run as root, otherwise it
|
||||
will just set the file time and silently fail the change of file
|
||||
ownership. On such systems, if you want a warning message when the file ownership
|
||||
cannot be changed, use \-v (the verbose flag) as well.
|
||||
.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 EXIT CODE
|
||||
Tofrodos terminates with an exit code of 0 on success and 1 on error.
|
||||
.PP
|
||||
If the program is invoked with multiple files on the command line, the default behaviour is to skip to the next
|
||||
file in the list if an error is encountered with any file. In such a case, the exit code returned will the
|
||||
status of the last file processed (ie, 0 on success, 1 on failure). If this is not desirable, use the \-e option,
|
||||
which will force the program to abort immediately with the appropriate exit code on encountering any error.
|
||||
.SH AUTHOR
|
||||
The program and its documentation are copyrighted (c) 1996-2013 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
|
|
@ -1,215 +0,0 @@
|
|||
/*
|
||||
init.c Initialisation functions.
|
||||
Copyright 1996-2013 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> /* fprintf() */
|
||||
#include <string.h> /* stricmp() */
|
||||
|
||||
#if defined(HAVE_UNISTD_H)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
/* our own headers */
|
||||
#include "emsg.h"
|
||||
#include "tofrodos.h"
|
||||
#include "utility.h"
|
||||
#include "version.h"
|
||||
|
||||
/* macros */
|
||||
#define HELPFMT "Usage: %s [options] [file...]\n"\
|
||||
"-a\t(Deprecated option, see manual for info.)\n"\
|
||||
"-b\tMake backup of original file (.bak).\n"\
|
||||
"-d\tConvert DOS to Unix.\n"\
|
||||
"-e\tAbort processing files on error in any file.\n"\
|
||||
"-f\tForce: convert even if file is not writeable.\n"\
|
||||
"-h\tDisplay help on usage and quit.\n"\
|
||||
"-l file\tLog most errors and verbose messages to <file>\n"\
|
||||
"-o\tOverwrite original file (no backup).\n"\
|
||||
"-p\tPreserve file owner and time.\n"\
|
||||
"-u\tConvert Unix to DOS.\n"\
|
||||
"-v\tVerbose.\n"\
|
||||
"-V\tShow version and quit.\n"
|
||||
#define OPTLIST "abdefhl:opuvV"
|
||||
#define VERFMT "%s Ver %d.%d.%d "\
|
||||
"Converts text files between DOS and Unix formats.\n"\
|
||||
"Copyright 1996-2013 Christopher Heng. "\
|
||||
"All rights reserved.\n"\
|
||||
"http://www.thefreecountry.com/tofrodos/index.shtml\n"
|
||||
|
||||
#if defined(MSDOS) || defined(WIN32)
|
||||
#if !defined(_MAX_NAME) || (_MAX_NAME < 260)
|
||||
#define MAXFILESIZE 260
|
||||
#else
|
||||
#define MAXFILESIZE _MAX_NAME
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(MSDOS)
|
||||
#define DIRSLASH '/'
|
||||
#endif
|
||||
|
||||
|
||||
/* local functions */
|
||||
static void showhelp ( void );
|
||||
static void showversion ( void );
|
||||
|
||||
/*
|
||||
init
|
||||
|
||||
Checks for correct operating system version (DOS only).
|
||||
Sets the default direction of conversion.
|
||||
Sets the signal traps.
|
||||
|
||||
Returns 0 on success, -1 on error.
|
||||
*/
|
||||
int init ( char * firstarg )
|
||||
{
|
||||
#if defined(MSDOS) || defined(WIN32)
|
||||
char filename[MAXFILESIZE];
|
||||
#else
|
||||
char * s ;
|
||||
#endif
|
||||
|
||||
#if defined(MSDOS)
|
||||
/* Check that we have the minimum version of DOS needed. */
|
||||
/* We only run on DOS 3.1 and above. */
|
||||
if (_osmajor < 3 ||
|
||||
(_osmajor == 3 && _osminor < 10)) {
|
||||
emsg( EMSG_WRONGDOSVER );
|
||||
return -1 ;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* set the name of the binary to set default direction of */
|
||||
/* conversion */
|
||||
#if defined(MSDOS) || defined(WIN32)
|
||||
/* got to extract the name from the full path and extension */
|
||||
_splitpath( firstarg, NULL, NULL, filename, NULL );
|
||||
progname = xstrdup( filename );
|
||||
#else /* neither MSDOS nor WIN32 - assume Unix */
|
||||
/* got to wipe out the path prefix if any */
|
||||
if ((s = strrchr( firstarg, DIRSLASH )) == NULL)
|
||||
progname = firstarg ;
|
||||
else { /* we got the last slash - let's get rid of it */
|
||||
progname = ++s ;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* set the default direction: Unless we are explicitly named */
|
||||
/* to convert in a particular direction, the default direction */
|
||||
/* depends on the system. If we are on a DOS system, it is to */
|
||||
/* convert from Unix to DOS. If we are on a Unix system, it */
|
||||
/* is to convert from DOS to Unix. */
|
||||
/* The default direction is set in tofrodos.c using a macro defined in tofrodos.h */
|
||||
if (!stricmp( progname, FROMDOSNAME ) ||
|
||||
!stricmp( progname, FROMDOSNAME2 ))
|
||||
direction = DOSTOUNIX ;
|
||||
else if (!stricmp( progname, TODOSNAME ) ||
|
||||
!stricmp( progname, TODOSNAME2 ))
|
||||
direction = UNIXTODOS ;
|
||||
|
||||
/* set the signal traps - we use the old Unix version 7 signal */
|
||||
/* mechanism since that is most portable to DOS. In any case, */
|
||||
/* we don't do anything sophisticated when we receive a signal */
|
||||
/* except cleaning up and quitting! */
|
||||
if (signal( SIGINT, sighandler ) == SIG_IGN)
|
||||
signal( SIGINT, SIG_IGN );
|
||||
if (signal( SIGTERM, sighandler ) == SIG_IGN)
|
||||
signal( SIGTERM, SIG_IGN );
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
/*
|
||||
parseargs
|
||||
|
||||
Parses the options.
|
||||
|
||||
Returns 0 on success, -1 on error.
|
||||
*/
|
||||
int parseargs ( int argc, char ** argv )
|
||||
{
|
||||
int c ;
|
||||
|
||||
while ((c = getopt( argc, argv, OPTLIST )) != -1) {
|
||||
switch( c ) {
|
||||
case 'a': /* force conversion of all \r\n to \n */
|
||||
alwaysconvert = 1 ;
|
||||
break ;
|
||||
case 'b': /* make backup of original file */
|
||||
overwrite = 0 ;
|
||||
break ;
|
||||
case 'd': /* DOS to Unix */
|
||||
direction = DOSTOUNIX ;
|
||||
break ;
|
||||
case 'e': /* abort processing list of files if */
|
||||
/* we encounter errors in any file in */
|
||||
/* a list of file names */
|
||||
abortonerr = 1 ;
|
||||
break ;
|
||||
case 'f': /* convert even if file is not writeable*/
|
||||
forcewrite = 1 ;
|
||||
break ;
|
||||
case 'h': /* display short usage screen and quit */
|
||||
showhelp() ;
|
||||
exit( EXIT_SUCCESS );
|
||||
break ;
|
||||
case 'l': /* log errors to filename */
|
||||
errorlogfilename = optarg ;
|
||||
break ;
|
||||
case 'o': /* overwrite original file (default) */
|
||||
overwrite = 1 ;
|
||||
break ;
|
||||
case 'p': /* preserve file owner and date */
|
||||
preserve = 1 ;
|
||||
break ;
|
||||
case 'u': /* Unix to DOS */
|
||||
direction = UNIXTODOS ;
|
||||
break ;
|
||||
case 'v': /* verbose */
|
||||
verbose = 1 ;
|
||||
break ;
|
||||
case 'V': /* show version and quit */
|
||||
showversion() ;
|
||||
exit( EXIT_SUCCESS );
|
||||
break ;
|
||||
default: /* error */
|
||||
return -1 ;
|
||||
}
|
||||
}
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
static void showversion ( void )
|
||||
{
|
||||
static int vershown ;
|
||||
|
||||
if (!vershown) {
|
||||
fprintf( stderr, VERFMT, VERSN_PROGNAME, VERSN_MAJOR, VERSN_MINOR, VERSN_PATCH );
|
||||
vershown = 1 ;
|
||||
}
|
||||
return ;
|
||||
}
|
||||
|
||||
/*
|
||||
showhelp
|
||||
|
||||
Display the short usage help screen.
|
||||
*/
|
||||
static void showhelp ( void )
|
||||
{
|
||||
showversion();
|
||||
fprintf( stderr, HELPFMT, progname );
|
||||
return ;
|
||||
}
|
|
@ -1,264 +0,0 @@
|
|||
/*
|
||||
getopt.c
|
||||
Copyright 1997-2013 by Christopher Heng. All rights reserved.
|
||||
|
||||
This code is released under the terms of the GNU General Public
|
||||
License Version 2. You should have received a copy of the GNU
|
||||
General Public License along with this program; if not, write to the
|
||||
Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
|
||||
USA.
|
||||
|
||||
The version of getopt() given here is based on the AT&T public
|
||||
domain source for getopt() given out at the 1985 UNIFORUM conference
|
||||
in Dallas. It has been modified as follows:
|
||||
|
||||
1. I support the newer optreset variable used in BSD 4.4.
|
||||
2. I support a non-standard optprogname which the user can use
|
||||
to set the program name to print. The AT&T version uses argv[0].
|
||||
Mine simply does not print a program name if optprogname is NULL.
|
||||
3. I support the use of '/' as the option switch character.
|
||||
4. I use a character pointer to track which character within an
|
||||
argument we are at for efficiency sake instead of the array
|
||||
integer index used in AT&T's implementation.
|
||||
5. Added Microsoft Windows GUI support. To enable this, just
|
||||
define GUI_APPLICATION to have the message displayed in a message
|
||||
box.
|
||||
6. It returns -1 instead of EOF.
|
||||
|
||||
This function is primarily designed for MSDOS and Windows, since those
|
||||
systems lack getopt(). Linux, BSD, and other Unix-type systems already
|
||||
have a fully-functioning and thoroughly-debugged version, so you should
|
||||
use the native versions on those systems instead. The error messages
|
||||
in this file also presuppose an MSDOS/Windows environment since they
|
||||
use '/' instead of '-' to describe the offending options.
|
||||
|
||||
See also list of differences in general in the documentation
|
||||
preceding the function itself.
|
||||
*/
|
||||
|
||||
#include <stdio.h> /* fprintf() */
|
||||
#include <string.h> /* strchr() */
|
||||
#include "getopt.h" /* our very own header */
|
||||
|
||||
/* system specific includes */
|
||||
#if defined(GUI_APPLICATION)
|
||||
#define STRICT
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning ( disable: 4514 4201 4214 )
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning ( default : 4201 4214 )
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* macros */
|
||||
#define OPT_SW1 '-' /* for Unix afficiondos */
|
||||
#define OPT_SW2 '/' /* MSDOS traditional switch character */
|
||||
|
||||
/* macros specific to systems */
|
||||
#if defined(GUI_APPLICATION) /* Windows version */
|
||||
#define MESSAGEMAX 128
|
||||
#define ERR_TITLE "Error"
|
||||
#define ERR_UNKNOWNOPT "Unknown option: /%c."
|
||||
#define ERR_OPTNEEDSARG "Option /%c requires an argument."
|
||||
#if !defined(MB_ICONERROR)
|
||||
/* define macro not defined in Win16's windows.h */
|
||||
#define MB_ICONERROR MB_ICONHAND
|
||||
#endif
|
||||
#else /* command line version */
|
||||
#define ERR_PREFIX "%s: "
|
||||
#define ERR_UNKNOWNOPT "Unknown option: /%c.\n"
|
||||
#define ERR_OPTNEEDSARG "Option /%c requires an argument.\n"
|
||||
#endif /* command line version macros */
|
||||
|
||||
/* global variables */
|
||||
char * optarg ; /* argument to option */
|
||||
int opterr = 1 ; /* 0 = don't print error msg, 1 = print */
|
||||
int optind = 1 ; /* next argument to parse */
|
||||
int optopt ; /* the current option */
|
||||
char * optprogname ;/* store program name here if you want the error */
|
||||
/* message spouter to issue the program name */
|
||||
int optreset ; /* 0 = continue processing, 1 = reset to start */
|
||||
|
||||
/* local functions */
|
||||
static void error_message ( char * s );
|
||||
|
||||
/*
|
||||
getopt
|
||||
|
||||
getopt() parses the command line given in the vector list,
|
||||
and returns the option character (if any) and the option
|
||||
argument in optarg.
|
||||
|
||||
argc, argv corresponds to the versions passed to main().
|
||||
optlist is the list of valid options. Options which must
|
||||
have arguments have a ':' suffixed to the option character
|
||||
in optlist. Needless to say, ':' cannot be a valid option
|
||||
character.
|
||||
|
||||
This function uses various globals: optarg, opterr, optind,
|
||||
optopt, optreset and optprogname to govern its actions.
|
||||
|
||||
optarg contain the argument to the option if the option is
|
||||
specified to have an argument.
|
||||
opterr If this is set to 1, an error message will
|
||||
be printed on stderr for bad options or missing arguments
|
||||
to options. The default is to print the error message.
|
||||
optind contains the next argv item which to be parsed. Defaults
|
||||
to 1 to skip over the program name in the standard
|
||||
argv[] passed to main().
|
||||
optopt always contains the option character which is returned on
|
||||
a valid option or which caused an error.
|
||||
optprogname (non-standard) Contains the program name to be printed
|
||||
prior to printing the error message.
|
||||
optreset Set this to 1 if you need to call getopt() after using
|
||||
it to parse a different argv list.
|
||||
|
||||
|
||||
The options "//", "/-", "--", and "-/" will terminate the
|
||||
list of options (unless one of those characters are themselves
|
||||
specified in the option list, optlist). The character ':'
|
||||
can never be an option. A solitary '-' or '/' will also cause
|
||||
getopt() to return -1.
|
||||
|
||||
Returns:
|
||||
|
||||
-1 No more options to parse.
|
||||
OPT_BADOPT An option character was encountered which
|
||||
was not in the list of valid options.
|
||||
OPT_BADARG An option was supposed to have an argument
|
||||
but was found without one.
|
||||
Otherwise, the option character is returned.
|
||||
|
||||
Differences from the Unix version:
|
||||
1. '?' can be a valid option, since we do not return '?' when
|
||||
there is an error. Unix getopt()s returns '?' when there is
|
||||
an error. We return OPT_BADOPT (which is equated to 0).
|
||||
2. the options are preceded by either '-' or '/' and the end
|
||||
of option list demarcator can be "--", "-/", "//" or "/-".
|
||||
Because our options begin with '/', filenames cannot begin
|
||||
with the '/' character else it would be interpreted as
|
||||
an option, unless you precede the file list with "--" to
|
||||
mark the end of options.
|
||||
3. We use optprogname to hold the program name to print
|
||||
when there is an error. If this is missing, no program name
|
||||
is printed. Some Unix versions print argv[0].
|
||||
4. Some Unix versions do not have optreset. This is present
|
||||
only in the later BSD versions. I have implemented it just in
|
||||
case I need it.
|
||||
5. Some Unix versions only return '?' when there is an error,
|
||||
not differentiating between an invalid option and a missing
|
||||
argument to an option. The version supplied with BSD 4.4
|
||||
returns ':' for the latter error. We follow the protocol of
|
||||
the BSD 4.4 version in this respect.
|
||||
7. A solitary '-' or '/' will cause -1 to be returned.
|
||||
According to the getopt manual page in BSD, this appears
|
||||
to be the behaviour in System V. This is the behaviour in
|
||||
Borland C/C++'s example getopt.c also.
|
||||
*/
|
||||
int getopt ( int argc, char * const * argv, const char * optlist )
|
||||
{
|
||||
static char nullstring[] = "" ;
|
||||
static char * curptr = nullstring ;
|
||||
char * s ;
|
||||
|
||||
if (optreset || *curptr == '\0') {
|
||||
/* either end of current arg or first time or user wants us */
|
||||
/* to treat this as first time */
|
||||
|
||||
/* got to restore this to zero for next iteration. Got to do */
|
||||
/* it here before we exit */
|
||||
optreset = 0 ;
|
||||
|
||||
/* get next (or first arg) */
|
||||
if(optind >= argc ||
|
||||
(*(curptr = argv[optind]) != OPT_SW1 && *curptr != OPT_SW2)) {
|
||||
curptr = nullstring ; /* reset */
|
||||
return -1;
|
||||
}
|
||||
/* got to set curptr since we could have got here by */
|
||||
/* optind < argc prior to curptr being set */
|
||||
curptr = argv[optind] ;
|
||||
/* check if user specified end of list of options */
|
||||
if (*++curptr == '\0' || /* solitary '-' */
|
||||
(*curptr == OPT_SW1 || *curptr == OPT_SW2)) { /* "--" */
|
||||
optind++; /* point to next argument */
|
||||
curptr = nullstring ; /* reset */
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
/* by the time we get here, we have skipped over the option */
|
||||
/* switch character */
|
||||
optopt = *curptr ;
|
||||
|
||||
if(optopt == ':' || /* need to trap this or problems will arise */
|
||||
(s = strchr( optlist, optopt )) == NULL) { /* no such option */
|
||||
if (opterr)
|
||||
error_message ( ERR_UNKNOWNOPT );
|
||||
/* skip erroneous option character */
|
||||
if (*++curptr == '\0') /* end of argument */
|
||||
optind++ ; /* go to next */
|
||||
/* curptr = nullstring ; */ /* but already pointing to a null */
|
||||
/* string */
|
||||
return OPT_BADOPT ;
|
||||
}
|
||||
if(*++s == ':') { /* argument expected */
|
||||
/* point to next argument - always done so might as well */
|
||||
/* do it before we test */
|
||||
optind++ ;
|
||||
/* is the argument at the end of current argument? */
|
||||
if(*++curptr != '\0') { /* yep */
|
||||
optarg = curptr ;
|
||||
curptr = nullstring ;
|
||||
/* optind already pointing to next argument for next round */
|
||||
}
|
||||
else if (optind < argc) /* optarg is in next argument */
|
||||
optarg = argv[optind++] ;
|
||||
/* since we use the next arg for our optarg, we needed to */
|
||||
/* point optind to the argument after that for next round */
|
||||
/* curptr already pointing to null byte */
|
||||
else { /* optarg not at end of current arg nor are there any */
|
||||
/* more args */
|
||||
if (opterr)
|
||||
error_message ( ERR_OPTNEEDSARG );
|
||||
return OPT_BADARG ;
|
||||
/* optind already pointing to next (nonexistant) argument */
|
||||
/* curptr already pointing to null byte */
|
||||
}
|
||||
}
|
||||
else { /* optarg is not expected */
|
||||
if (*++curptr == '\0') /* end of current argument */
|
||||
optind++ ; /* skip to next for next round */
|
||||
optarg = NULL; /* just in case */
|
||||
}
|
||||
return optopt ;
|
||||
}
|
||||
|
||||
/*
|
||||
error_message
|
||||
|
||||
System specific error message spouter. It prints the program
|
||||
name first if optprogname is not NULL.
|
||||
|
||||
References the global optopt.
|
||||
|
||||
Returns: nothing.
|
||||
*/
|
||||
static void error_message ( char * msgfmt )
|
||||
{
|
||||
#if defined(GUI_APPLICATION)
|
||||
char buf[MESSAGEMAX];
|
||||
char * title ;
|
||||
|
||||
sprintf( buf, msgfmt, optopt );
|
||||
title = (optprogname == NULL) ? ERR_TITLE : optprogname ;
|
||||
MessageBox( 0, buf, title, MB_ICONERROR | MB_OK );
|
||||
#else
|
||||
if (optprogname != NULL)
|
||||
fprintf( stderr, ERR_PREFIX, optprogname );
|
||||
fprintf( stderr, msgfmt, optopt );
|
||||
#endif
|
||||
return ;
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
getopt.h
|
||||
Copyright (c) 1996,1997 by Christopher Heng. All rights reserved.
|
||||
|
||||
$Id: getopt.h,v 1.1 2004/10/01 12:33:39 chris Exp $
|
||||
*/
|
||||
|
||||
#if !defined(GETOPT_H_INCLUDED)
|
||||
#define GETOPT_H_INCLUDED
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* macros for getopt() */
|
||||
#define OPT_BADOPT 0 /* error return code for getopt() */
|
||||
/* Note that EOF better not be zero! */
|
||||
#define OPT_BADARG ((int)':') /* no argument given when there should */
|
||||
/* be one! Note that ':' cannot be an */
|
||||
/* option! */
|
||||
|
||||
/* global variables for getopt() */
|
||||
extern char * optarg; /* argument if option has one */
|
||||
extern int opterr; /* 0 = don't print err msg, 1 = print */
|
||||
extern int optind; /* next argument to process */
|
||||
extern int optopt ; /* current option */
|
||||
extern char * optprogname; /* name of program to print before error msg */
|
||||
extern int optreset ; /* set by user to 1 if you want to reset getopt() */
|
||||
|
||||
/* global variables for gesubopt() */
|
||||
extern char * suboptarg ;
|
||||
|
||||
/* function declarations */
|
||||
extern int getopt (int argc, char * const * argv, const char * optlist );
|
||||
extern int getsubopt ( char ** optargp, char * const * optsp,
|
||||
char ** suboptvalp );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* GETOPT_H_INCLUDED */
|
|
@ -1,99 +0,0 @@
|
|||
/*
|
||||
mktemp.c Create a temporary file name.
|
||||
Copyright 1996-2012 by Christopher Heng. All rights reserved.
|
||||
|
||||
This code is released under the terms of the GNU General Public
|
||||
License Version 2. You should have received a copy of the GNU
|
||||
General Public License along with this program; if not, write to the
|
||||
Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
|
||||
USA.
|
||||
|
||||
Originally written for use in tofrodos, when compiled with
|
||||
Watcom 10.0, which did not have either mktemp() or mkstemp().
|
||||
Tofrodos can be found at
|
||||
http://www.thefreecountry.com/tofrodos/index.shtml
|
||||
*/
|
||||
|
||||
#include <errno.h> /* errno, ENOENT, EINVAL, EEXIST */
|
||||
#include <io.h> /* access() */
|
||||
#include <string.h> /* strlen(), strcmp() */
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h> /* O_IRUSR, O_IWUSR */
|
||||
#include <fcntl.h> /* open(), O_RDWR, O_CREAT, O_EXCL */
|
||||
#include "mktemp.h" /* our own header */
|
||||
|
||||
#define MAXVAL (65535u) /* unsigned is at least this (ANSI) */
|
||||
|
||||
/*
|
||||
mkstemp
|
||||
|
||||
Creates a temporary file using "templ" and returns a
|
||||
file descriptor opened using open(). The file is
|
||||
open for read and write binary (not text) access
|
||||
for the current user. The new filename is placed
|
||||
in "templ", overwriting its existing contents.
|
||||
|
||||
The file path in "templ" must have six trailing "X"s,
|
||||
ie, it must end with "XXXXXX".
|
||||
|
||||
On success, mkstemp() returns the file descriptor.
|
||||
On failure, it returns -1, and errno is set to
|
||||
EINVAL if "templ" does not end with "XXXXXX" on
|
||||
entry to the function, or EEXIST if no file could
|
||||
be created.
|
||||
|
||||
Function compatibility:
|
||||
O_BINARY is used in file creation. This flag
|
||||
only exists on Windows and MSDOS compilers.
|
||||
|
||||
Example:
|
||||
char tempfilename[] = "\\tmp\\myXXXXXX" ;
|
||||
int fd ;
|
||||
fd = mkstemp( tempfilename );
|
||||
*/
|
||||
int mkstemp ( char * templ )
|
||||
{
|
||||
static unsigned val ;
|
||||
static char fch = 'A' ;
|
||||
|
||||
char *s ;
|
||||
char *startp ;
|
||||
size_t len ;
|
||||
unsigned tval ;
|
||||
int fd ;
|
||||
int orig_errno ;
|
||||
|
||||
orig_errno = errno ;
|
||||
|
||||
/* do some sanity checks */
|
||||
/* make sure that templ is at least 6 characters long */
|
||||
/* and comprises the "XXXXXX" string at the end */
|
||||
if ((len = strlen(templ)) < 6 ||
|
||||
strcmp( (s = startp = templ + len - 6), MKTEMP_TEMPLATE )) {
|
||||
errno = EINVAL ;
|
||||
return -1 ;
|
||||
}
|
||||
for ( ; fch <= 'Z'; val = 0, fch++ ) {
|
||||
/* plug the first character */
|
||||
*startp = fch ;
|
||||
/* convert val to ascii */
|
||||
/* note that we skip the situation where val == MAXVAL */
|
||||
/* because if unsigned has a maximum value of MAXVAL */
|
||||
/* in an implementation, and we do a compare of */
|
||||
/* val <= MAXVAL, the test will always return true! */
|
||||
/* Our way, we have at least a cut-off point: MAXVAL. */
|
||||
for ( ; val < MAXVAL; ) {
|
||||
tval = val++ ;
|
||||
for (s = startp + 5; s > startp ; s--) {
|
||||
*s = (char) ((tval % 10) + '0') ;
|
||||
tval /= 10 ;
|
||||
}
|
||||
if ((fd = open( templ, O_CREAT | O_EXCL | O_BINARY | O_RDWR, S_IRUSR | S_IWUSR )) != -1) {
|
||||
errno = orig_errno ;
|
||||
return fd ;
|
||||
}
|
||||
}
|
||||
}
|
||||
errno = EEXIST ;
|
||||
return -1 ;
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/*
|
||||
mktemp.h Declares my mktemp() function.
|
||||
Copyright 1996-2012 by Christopher Heng. All rights reserved.
|
||||
|
||||
Originally written for use in tofrodos, when compiled with
|
||||
Watcom 10.0, which did not have either mktemp() or mkstemp().
|
||||
Tofrodos can be found at
|
||||
http://www.thefreecountry.com/tofrodos/index.shtml
|
||||
*/
|
||||
|
||||
#if !defined(MKTEMP_H_INCLUDED)
|
||||
#define MKTEMP_H_INCLUDED
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* macros */
|
||||
#define MKTEMP_TEMPLATE "XXXXXX"
|
||||
|
||||
/* functions declarations */
|
||||
extern int mkstemp ( char * templ );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,97 +0,0 @@
|
|||
# makefile.gcc Makefile for building with the GNU C compiler on Linux.
|
||||
# Copyright 1996-2012 by Christopher Heng. All rights reserved.
|
||||
|
||||
# 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
|
||||
|
||||
# programs
|
||||
CC = gcc
|
||||
CD = cd
|
||||
CP = cp
|
||||
GZIP = gzip
|
||||
INSTALL = install
|
||||
LN = ln
|
||||
LD = gcc
|
||||
MAKE = make
|
||||
MKDIR = mkdir
|
||||
MV = mv
|
||||
RM = rm -f
|
||||
|
||||
# flags
|
||||
CFLAGS = $(DEFINES) $(TFLAG) $(CDEBUG) -c -Wall
|
||||
GZIPFLAGS = -9
|
||||
INSTALLBINFLAGS = -m 755
|
||||
INSTALLDATAFLAGS = -m 644
|
||||
LDFLAGS = $(LDEBUG)
|
||||
LNFLAGS = -sf
|
||||
RMRECURFLAGS = -rf
|
||||
|
||||
# directories
|
||||
BINDIR = /usr/bin
|
||||
LIBDIR = lib
|
||||
MANDIR = /usr/man/man1
|
||||
|
||||
# filenames
|
||||
FROMDOS = fromdos
|
||||
FROMDOSMAN = fromdos.1
|
||||
FROMDOSTXT = fromdos.txt
|
||||
TODOS = todos
|
||||
ZIPSRCNAME = tfd.zip
|
||||
|
||||
# lists of filenames
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
|
||||
# real rules
|
||||
$(FROMDOS): $(OBJS)
|
||||
$(CC) $(LDFLAGS) -o $(FROMDOS) $(OBJS)
|
||||
|
||||
$(FROMDOSTXT): $(FROMDOSMAN)
|
||||
gtbl $(FROMDOSMAN) | groff -Tascii -mandoc | \
|
||||
troff -Tascii -mandoc | grotty > $@
|
||||
|
||||
$(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
|
|
@ -1,68 +0,0 @@
|
|||
# makefile.min Makefile for building with the MinGW (GNU) C Compiler.
|
||||
# Copyright (c) 1996-2005 by Christopher Heng. All rights reserved.
|
||||
|
||||
# $Id: makefile.min,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
|
||||
|
||||
# programs
|
||||
CC = gcc
|
||||
CD = cd
|
||||
CP = copy
|
||||
INSTALL = install
|
||||
LD = gcc
|
||||
|
||||
# flags
|
||||
CFLAGS = $(DEFINES) $(TFLAG) $(CDEBUG) -c -Wall
|
||||
GZIPFLAGS = -9
|
||||
LDFLAGS = $(LDEBUG)
|
||||
|
||||
# directories
|
||||
LIBDIR = lib
|
||||
|
||||
# filenames
|
||||
FROMDOS = fromdos.exe
|
||||
FROMDOSMAN = fromdos.1
|
||||
TODOS = todos.exe
|
||||
|
||||
# lists of filenames
|
||||
OBJS = emsg.o \
|
||||
init.o \
|
||||
tofrodos.o \
|
||||
utility.o
|
||||
|
||||
# implicit rules
|
||||
.c.o:
|
||||
$(CC) $(CFLAGS) $<
|
||||
|
||||
# user visible rules
|
||||
all: $(FROMDOS) $(TODOS)
|
||||
|
||||
# real rules
|
||||
$(FROMDOS): $(OBJS)
|
||||
$(CC) $(LDFLAGS) -o $(FROMDOS) $(OBJS)
|
||||
|
||||
$(TODOS): $(FROMDOS)
|
||||
$(CP) $(FROMDOS) $(TODOS)
|
||||
|
||||
# objects
|
||||
emsg.o: emsg.c config.h emsg.h tofrodos.h
|
||||
|
||||
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
|
|
@ -1,89 +0,0 @@
|
|||
# Makefile for use with Visual Studio .NET 2003 to generate Win32 binaries
|
||||
# Copyright 2005 by Christopher Heng. All rights reserved.
|
||||
|
||||
# To debug, just use the IDE. Sorry.
|
||||
|
||||
# Programs
|
||||
# Warning: the RM macro assumes that the del command accepts a "/y"
|
||||
# argument (yes to all prompts) and accepts multiple filenames for
|
||||
# deletion.
|
||||
CC = cl
|
||||
CP = copy
|
||||
LD = link
|
||||
RM = del /y
|
||||
ZIP = zip
|
||||
|
||||
# Flags
|
||||
CFLAGS = $(CFL1) $(CFL2)
|
||||
# /nologo - suppress startup banner
|
||||
# /Zi - debug - create program database
|
||||
# /W4 - warning level 4
|
||||
# /WX - treat warnings as errors
|
||||
# /02 - maximize speed (/Og /Oi /Ot /Oy /Gs /GF /Gy)
|
||||
# note that
|
||||
# /Og global optimizations (implied by /O2)
|
||||
# /Oi - enable intrinsic functions
|
||||
# /Ot - optimize speed
|
||||
# /Oy -
|
||||
# /Gs stack checking calls (for local variables)
|
||||
# /GF enable string pooling
|
||||
# /Gy function-level linking
|
||||
# /Ob1 - only expand __inline functions
|
||||
# /D "NDEBUG" /D "_CONSOLE" /D "WIN32" /D "_MBCS"
|
||||
# /ML - single threaded library
|
||||
# /Fo - output dir
|
||||
# /Fd - PDB dir
|
||||
# /I - include directory
|
||||
# /c - compile only
|
||||
CFL1 = /nologo /Zi /W4 /WX /O2 /Ob1 /D "NDEBUG" /D "_CONSOLE" /D "WIN32" /D "_MBCS" /ML
|
||||
CFL2 = /I "$(LIBDIR)" /Fo"$(BINDIR)\\" /Fd"$(BINDIR)\\" /c
|
||||
LDFLAGS = $(LDFL1) $(LDFL2) $(LDFL3) $(LDFL4)
|
||||
LDFL1 = /OUT:"$(FROMDOS)" /INCREMENTAL:NO /NOLOGO /DEBUG /PDB:"$(PDBFILE)"
|
||||
LDFL2 = /SUBSYSTEM:CONSOLE /OPT:REF /OPT:ICF /MACHINE:X86
|
||||
LDFL3 = odbc32.lib odbccp32.lib setargv.obj kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib
|
||||
LDFL4 = advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
|
||||
|
||||
# Directories
|
||||
BINDIR = .\bin
|
||||
LIBDIR = .\lib
|
||||
|
||||
# Files
|
||||
FROMDOS = $(BINDIR)\fromdos.exe
|
||||
TODOS = $(BINDIR)\todos.exe
|
||||
|
||||
OBJS = $(BINDIR)\emsg.obj \
|
||||
$(BINDIR)\init.obj \
|
||||
$(BINDIR)\getopt.obj \
|
||||
$(BINDIR)\mktemp.obj \
|
||||
$(BINDIR)\tofrodos.obj \
|
||||
$(BINDIR)\utility.obj
|
||||
PDBFILE = $(BINDIR)\fromdos.pdb
|
||||
|
||||
# Implicit rules
|
||||
.c{$(BINDIR)}.obj:
|
||||
$(CC) @<<
|
||||
$(CFLAGS) $<
|
||||
<<
|
||||
|
||||
# Rules
|
||||
all: $(FROMDOS) $(TODOS)
|
||||
|
||||
clean:
|
||||
$(RM) $(OBJS)
|
||||
|
||||
clobber: clean
|
||||
$(RM) $(FROMDOS) $(TODOS) $(PDBFILE)
|
||||
|
||||
$(FROMDOS): $(OBJS)
|
||||
$(LD) @<<
|
||||
$(LDFLAGS) $(OBJS)
|
||||
<<
|
||||
|
||||
$(TODOS): $(FROMDOS)
|
||||
$(CP) $(FROMDOS) $(TODOS)
|
||||
|
||||
$(BINDIR)\getopt.obj: $(LIBDIR)\getopt.c $(LIBDIR)\getopt.h
|
||||
$(CC) $(CFLAGS) $(LIBDIR)\getopt.c
|
||||
|
||||
$(BINDIR)\mktemp.obj: $(LIBDIR)\mktemp.c $(LIBDIR)\mktemp.h
|
||||
$(CC) $(CFLAGS) $(LIBDIR)\mktemp.c
|
|
@ -1,122 +0,0 @@
|
|||
# makefile.wcc Makefile for building with the Watcom and OpenWatcom C/C++ compiler.
|
||||
# Copyright 1996-2011 Christopher Heng. All rights reserved.
|
||||
|
||||
# Prevent checking for existence of targets after rule has been executed.
|
||||
.NOCHECK
|
||||
|
||||
# This makefile assumes you have wildargv.c in the lib subdirectory.
|
||||
# wildargv.c is not provided in the distribution. You should use
|
||||
# the one from watcom\src\startup\wildargv.c. This file expands
|
||||
# wildcards on the command line. You will also need initarg.h from
|
||||
# your watcom\src\startup directory as well; put it in the tofrodos
|
||||
# lib subdirectory.
|
||||
|
||||
# Define the following if you need
|
||||
#
|
||||
# DEBUG To add debugging information.
|
||||
# If you want fine-tune the amount of debugging info, you
|
||||
# can define CDEBUG to be the compiler option switch and
|
||||
# LDEBUG for the linker.
|
||||
# TARGET To determine the type of target
|
||||
# 32bit if you want a 32 bit DOS executable (using a DOS extender)
|
||||
# 16bit if you want a 16 bit DOS executable
|
||||
# Win32 if you want a Windows 32 bit console executable
|
||||
# The default is to generate a Win32 console executable.
|
||||
|
||||
!ifdef DEBUG
|
||||
!ifndef CDEBUG
|
||||
CDEBUG = -d2
|
||||
!endif
|
||||
!ifndef LDEBUG
|
||||
LDEBUG = d all
|
||||
!endif
|
||||
!endif
|
||||
|
||||
!ifeq TARGET 32bit
|
||||
CCBIN = wcc386
|
||||
!ifndef TCFLAGS
|
||||
TCFLAGS = -bt=DOS -mf -5r -fp3
|
||||
!endif
|
||||
!ifndef TLFLAGS
|
||||
TLFLAGS = sys dos4g
|
||||
!endif
|
||||
!else
|
||||
!ifeq TARGET 16bit
|
||||
CCBIN = wcc
|
||||
!ifndef TCFLAGS
|
||||
TCFLAGS = -ms -bt=DOS
|
||||
!endif
|
||||
!ifndef TLFLAGS
|
||||
TLFLAGS = sys dos
|
||||
!endif
|
||||
!else # Win32
|
||||
CCBIN = wcc386
|
||||
!ifndef TCFLAGS
|
||||
TCFLAGS = -bt=nt -6r -fp6
|
||||
!endif
|
||||
!ifndef TLFLAGS
|
||||
TLFLAGS = sys nt
|
||||
!endif
|
||||
!endif # if 16bit else Win32
|
||||
!endif # if 32bit else 16bit||Win32
|
||||
|
||||
# programs
|
||||
CC = $(CCBIN)
|
||||
LD = wlink
|
||||
LN = copy
|
||||
RM = del
|
||||
|
||||
# flags
|
||||
CFLAGS = -oxa -wx -fpi -zp1 -zq $(TCFLAGS) $(CINCFLAGS) $(CDEBUG)
|
||||
CINCFLAGS = -i=$(LIBDIR)
|
||||
COUTFLAG = /fo=
|
||||
LDFLAGS = $(TLFLAGS) op q,c,m,el $(LDEBUG)
|
||||
|
||||
# directories
|
||||
LIBDIR = lib
|
||||
SRCDIR = .
|
||||
|
||||
# filenames
|
||||
FROMDOS = fromdos.exe
|
||||
LDRESP = ldresp.rsp
|
||||
TODOS = todos.exe
|
||||
|
||||
# lists of filenames
|
||||
LIBOBJS = $(LIBDIR)\getopt.obj &
|
||||
$(LIBDIR)\mktemp.obj &
|
||||
$(LIBDIR)\wildargv.obj
|
||||
OBJS = emsg.obj &
|
||||
init.obj &
|
||||
tofrodos.obj &
|
||||
utility.obj
|
||||
|
||||
# implicit rules
|
||||
.c: $(SRCDIR);$(LIBDIR)
|
||||
.h: $(SRCDIR);$(LIBDIR)
|
||||
.c.obj: .AUTODEPEND
|
||||
$(CC) $(CFLAGS) $(COUTFLAG)$@ $[@
|
||||
|
||||
# user visible rules
|
||||
all: $(FROMDOS) $(TODOS)
|
||||
%null
|
||||
|
||||
clean:
|
||||
$(RM) $(OBJS) $(LIBOBJS)
|
||||
$(RM) *.map *.err
|
||||
$(RM) $(LDRESP) todos.exe fromdos.exe
|
||||
|
||||
clobber: clean
|
||||
|
||||
# real rules
|
||||
$(FROMDOS): $(OBJS) $(LIBOBJS) $(LDRESP)
|
||||
$(LD) @$(LDRESP)
|
||||
|
||||
$(TODOS): $(FROMDOS)
|
||||
$(LN) $(LNFLAGS) $(FROMDOS) $(TODOS)
|
||||
|
||||
# support rules
|
||||
$(LDRESP): $(__MAKEFILES__)
|
||||
%write $@ $(LDFLAGS)
|
||||
%append $@ name $(FROMDOS)
|
||||
for %i in ($(OBJS)) do @%append $@ file %i
|
||||
for %i in ($(LIBOBJS)) do @%append $@ file %i
|
|
@ -1,714 +0,0 @@
|
|||
/*
|
||||
tofrodos.c Converts text files between DOS and Unix formats.
|
||||
Copyright 1996-2013 Christopher Heng. All rights reserved.
|
||||
*/
|
||||
|
||||
/* this should always be first */
|
||||
#include "config.h"
|
||||
|
||||
/* standard headers */
|
||||
#include <errno.h> /* errno */
|
||||
#include <signal.h> /* signal() */
|
||||
#include <stdio.h> /* FILE functions */
|
||||
#include <stdlib.h> /* EXIT_SUCCESS, mkstemp() in some systems, ltoa() */
|
||||
#include <string.h> /* strrchr(), strlen(), strcpy(), strcat(), strerror() */
|
||||
#include <sys/stat.h> /* stat() */
|
||||
|
||||
#if defined(_MSC_VER) || defined(__WATCOMC__)
|
||||
#include <sys/utime.h>
|
||||
#else /* everybody else keeps this in the include directory */
|
||||
#if defined(UNIX)
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#include <utime.h>
|
||||
#endif
|
||||
|
||||
/* conditionally included headers */
|
||||
#if defined(MSDOS) || defined(WIN32)
|
||||
#include <fcntl.h> /* O_BINARY */
|
||||
#include <io.h> /* chmod(), setmode(), isatty() */
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_GETOPT_H)
|
||||
#include <getopt.h> /* optind, getopt() */
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_MKTEMP_H) && defined(MKTEMP_HEADER)
|
||||
#include MKTEMP_HEADER
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_UNISTD_H)
|
||||
#include <unistd.h> /* chmod(), mktemp(), isatty(), chown(), readlink(), mkstemp() in some systems, (getopt()) */
|
||||
#endif
|
||||
|
||||
/* our headers */
|
||||
#include "emsg.h"
|
||||
#include "tofrodos.h"
|
||||
#include "utility.h"
|
||||
#include "version.h"
|
||||
|
||||
/* macros */
|
||||
#define BAKEXT ".bak" /* backup file extension */
|
||||
#define MKTEMP_TEMPL "XXXXXX"
|
||||
#define NEWBUFSIZ 16384 /* buffer size for the files */
|
||||
|
||||
#if defined(MSDOS) || defined(WIN32)
|
||||
#define DIRSLASH '\\'
|
||||
#define DIRSLASHSTR "\\"
|
||||
#else
|
||||
#define DIRSLASH '/'
|
||||
#define DIRSLASHSTR "/"
|
||||
#endif
|
||||
|
||||
/* conditional macros */
|
||||
#if defined(MSDOS)
|
||||
#if !defined(_MAX_DIR) || (_MAX_DIR < 260) /* MAXDIRSIZE */
|
||||
#define MAXDIRSIZE 260
|
||||
#else
|
||||
#define MAXDIRSIZE _MAX_DIR
|
||||
#endif
|
||||
#if !defined(_MAX_NAME) || (_MAX_NAME < 260) /* MAXFILESIZE */
|
||||
#define MAXFILESIZE 260
|
||||
#else
|
||||
#define MAXFILESIZE _MAX_NAME
|
||||
#endif
|
||||
#if !defined(_MAX_PATH) || (_MAX_PATH < 260) /* MAXPATHSIZE */
|
||||
#define MAXPATHSIZE 260
|
||||
#else
|
||||
#define MAXPATHSIZE _MAX_PATH
|
||||
#endif
|
||||
#if !defined(_MAX_DRIVE)
|
||||
#define _MAX_DRIVE 3 /* for the benefit of djgpp */
|
||||
#endif
|
||||
#endif /* if defined(MSDOS) */
|
||||
|
||||
#if defined(MSDOS) || defined(WIN32)
|
||||
#define INFILEMODE "rb"
|
||||
#define OUTFILEMODE "wb"
|
||||
#else
|
||||
#define INFILEMODE "r"
|
||||
#define OUTFILEMODE "w"
|
||||
#endif
|
||||
|
||||
#if defined(MSDOS) || defined(WIN32)
|
||||
#define CURRENTDIR ".\\" /* not used in MSDOS though */
|
||||
#else /* Unix-type systems */
|
||||
#define CURRENTDIR "./"
|
||||
#endif
|
||||
|
||||
|
||||
/* global variables */
|
||||
int abortonerr ; /* 1 if should abort when there is error in any file */
|
||||
/* in a list of files, 0 carry on (default) */
|
||||
int alwaysconvert ; /* convert all \r\n to \r\r\n when direction */
|
||||
/* is UNIXTODOS, and delete all \r when direction is */
|
||||
/* DOSTOUNIX */
|
||||
int direction = DEFDIRECTION ; /* UNIXTODOS or DOSTOUNIX */
|
||||
int forcewrite ; /* convert even if file is not writeable */
|
||||
char * errorlogfilename ; /* name of error log file, NULL if we're printing to stderr */
|
||||
int preserve ; /* 1 if we are to preserve owner (Unix) and date (all) */
|
||||
char * progname = VERSN_PROGNAME ;/* name of binary (ie, argv[0]) */
|
||||
int overwrite = 1 ; /* 1 = overwrite original file, 0 = make backup */
|
||||
int verbose ;
|
||||
|
||||
/* local variables */
|
||||
static char * infilename = "stdin" ;
|
||||
static FILE * tempfp ;
|
||||
static char * tempfilename ;
|
||||
|
||||
/* local functions */
|
||||
#if !defined(UNIX)
|
||||
static int checkmode ( char * filename, unsigned short * origfilemodep,
|
||||
struct utimbuf * filetimebufp );
|
||||
#else
|
||||
static int checkmode ( char * filename, unsigned short * origfilemodep,
|
||||
struct utimbuf * filetimebufp, uid_t * ownerp, gid_t * groupp );
|
||||
#endif
|
||||
static int convert ( FILE * infp, FILE * outfp );
|
||||
static int openandconvert ( char * filename );
|
||||
#if !defined(UNIX)
|
||||
#define openandconvert_preamble openandconvert
|
||||
#else
|
||||
static int openandconvert_preamble ( char * filename );
|
||||
#endif
|
||||
|
||||
/*
|
||||
main
|
||||
|
||||
tofrodos converts ASCII text files to/from a DOS CR-LF deliminated
|
||||
form from/to a Unix LF deliminated form.
|
||||
|
||||
Usage: tofrodos [options] [file...]
|
||||
|
||||
Exit codes:
|
||||
EXIT_SUCCESS success (stdlib.h)
|
||||
EXIT_ERROR error (tofrodos.h)
|
||||
*/
|
||||
int main ( int argc, char ** argv )
|
||||
{
|
||||
int err ;
|
||||
|
||||
/* initialise and parse the options */
|
||||
if (init( argv[0] ) || parseargs( argc, argv ))
|
||||
return EXIT_ERROR ;
|
||||
|
||||
/* check if we are to convert from stdin */
|
||||
if (argc == optind) {
|
||||
if (isatty( fileno( stdin ) )) {
|
||||
/* stdin must be redirected else you should supply a */
|
||||
/* filename. */
|
||||
emsg( EMSG_NOFILENAME );
|
||||
return EXIT_ERROR ;
|
||||
}
|
||||
/* otherwise stdin has been redirected */
|
||||
#if defined(MSDOS) || defined(WIN32)
|
||||
/* need to make sure the input and output files are binary */
|
||||
/* on MSDOS and WIN32 */
|
||||
setmode( fileno( stdin ), O_BINARY );
|
||||
setmode( fileno( stdout ), O_BINARY );
|
||||
#endif
|
||||
return openandconvert( NULL ) ? EXIT_ERROR : EXIT_SUCCESS ;
|
||||
}
|
||||
|
||||
/* if we reach here, we have a (list?) of files to convert */
|
||||
/* (ignore stdin) */
|
||||
err = 0 ;
|
||||
while (optind < argc) {
|
||||
if (verbose)
|
||||
emsg( VERBOSE_CONVERTING, argv[optind] );
|
||||
if ((err = openandconvert_preamble( argv[optind] )) != 0 && abortonerr)
|
||||
return EXIT_ERROR ;
|
||||
optind++ ;
|
||||
}
|
||||
|
||||
return err ? EXIT_ERROR : EXIT_SUCCESS ;
|
||||
}
|
||||
|
||||
/*
|
||||
sighandler
|
||||
|
||||
Handles SIGINT and SIGTERM. Prints a message, closes and
|
||||
deletes the temporary files and quits with EXIT_ERROR.
|
||||
|
||||
It never returns (and Watcom C knows it).
|
||||
*/
|
||||
void sighandler ( int sig )
|
||||
{
|
||||
/* restore signal handler, in case we have the old unsafe behaviour */
|
||||
signal( sig, sighandler );
|
||||
|
||||
/* print error message for this only if verbose */
|
||||
if (verbose)
|
||||
emsg( EMSG_SIGNAL );
|
||||
|
||||
/* close the temporary file and delete it */
|
||||
if (tempfp != NULL) {
|
||||
fclose( tempfp );
|
||||
tempfp = NULL ;
|
||||
}
|
||||
if (tempfilename != NULL) {
|
||||
remove( tempfilename );
|
||||
tempfilename = NULL ;
|
||||
}
|
||||
|
||||
exit( EXIT_ERROR );
|
||||
}
|
||||
|
||||
/* ---------------------------- local functions --------------------- */
|
||||
/*
|
||||
checkmode
|
||||
|
||||
Checks that the file we are supposed to convert is indeed
|
||||
writeable. We don't really need for it to be writeable, since
|
||||
we actually open a new file and eventually delete the current
|
||||
file.
|
||||
|
||||
However, if a file is marked not-writeable, we should at least
|
||||
respect the user's choice and abort unless he flags the
|
||||
forcewrite flag.
|
||||
|
||||
At the same time we also save the current mode of the file
|
||||
so that we can set the converted file to the same mode. The
|
||||
value is saved in the variable pointed to by origfilemodep.
|
||||
|
||||
Returns: 0 on success, -1 on error.
|
||||
|
||||
If -1 is returned, it could mean one of few things:
|
||||
1) some component of the path was not valid (directory or the file
|
||||
itself) (DOS/Unix) or search permission was denied (Unix)
|
||||
2) the file is not readable
|
||||
3) the file is not writeable and forcewrite is zero.
|
||||
An error message is displayed on error.
|
||||
*/
|
||||
#if !defined(UNIX)
|
||||
static int checkmode ( char * filename, unsigned short * origfilemodep,
|
||||
struct utimbuf * filetimebufp )
|
||||
#else
|
||||
static int checkmode ( char * filename, unsigned short * origfilemodep,
|
||||
struct utimbuf * filetimebufp, uid_t * ownerp, gid_t * groupp )
|
||||
#endif
|
||||
{
|
||||
struct stat statbuf ;
|
||||
|
||||
/* get the file information */
|
||||
if (stat( filename, &statbuf )) {
|
||||
/* couldn't stat the file. */
|
||||
emsg( EMSG_ACCESSFILE, filename );
|
||||
return -1 ;
|
||||
}
|
||||
/* save the mode */
|
||||
*origfilemodep = statbuf.st_mode ;
|
||||
/* save the file times for restore later */
|
||||
filetimebufp->actime = statbuf.st_atime ;
|
||||
filetimebufp->modtime = statbuf.st_mtime ;
|
||||
#if defined(UNIX)
|
||||
/* save the owner and group id */
|
||||
*ownerp = statbuf.st_uid ;
|
||||
*groupp = statbuf.st_gid ;
|
||||
#endif
|
||||
/* check if file can be read - this is actually redundant for */
|
||||
/* DOS systems. */
|
||||
if (!(statbuf.st_mode & S_IRUSR)) { /* not readable */
|
||||
emsg( EMSG_NOTREADABLE, filename );
|
||||
return -1 ;
|
||||
}
|
||||
/* check if file can be written to, if forcewrite is 0 */
|
||||
if (!forcewrite && !(statbuf.st_mode & S_IWUSR)) { /* not writeable */
|
||||
emsg( EMSG_NOTWRITEABLE, filename );
|
||||
return -1 ;
|
||||
}
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
/*
|
||||
convert
|
||||
|
||||
Does the actual work of converting infp to outfp.
|
||||
|
||||
If direction is DOSTOUNIX, "\r\n" pairs will be converted to
|
||||
'\n'. However, standalone '\r' without a '\n' immediately
|
||||
following will not be eliminated unless alwaysconvert is
|
||||
nonzero.
|
||||
|
||||
If direction is UNIXTODOS, '\n' will be converted to "\r\n".
|
||||
However "\r\n" pairs are not converted to '\r\r\n' unless
|
||||
alwaysconvert is nonzero.
|
||||
|
||||
Returns 0 on success, -1 on error.
|
||||
*/
|
||||
static int convert ( FILE * infp, FILE * outfp )
|
||||
{
|
||||
int prevch ;
|
||||
int c ;
|
||||
|
||||
/* actually it is very simple to do the conversion in DOS/WIN32 */
|
||||
/* because the stdio library does this work automatically for */
|
||||
/* us. But since we want this program to work on Linux as */
|
||||
/* well, a little bit of work stands before us (but only a little). */
|
||||
|
||||
prevch = EOF ;
|
||||
|
||||
if (direction == UNIXTODOS) {
|
||||
/* basically we convert all newlines to "\r\n" unless */
|
||||
/* the file is already in "\r\n" format. The problem here */
|
||||
/* is when you have special situations like a Unix */
|
||||
/* text file with lines that have a '\r' just */
|
||||
/* before a '\n'. These lines will */
|
||||
/* not be converted to "\r\r\n" since the function */
|
||||
/* below assumes the line has already been converted. */
|
||||
/* To force the conversion of all \n to \r\n regardless */
|
||||
/* of preceding characters, set alwaysconvert to 1. */
|
||||
while ( (c = getc( infp )) != EOF ) {
|
||||
if (c == '\n' && (alwaysconvert || prevch != '\r')) {
|
||||
if (putc( '\r', outfp ) == EOF)
|
||||
break ;
|
||||
}
|
||||
/* always emit the current character */
|
||||
if (putc( c, outfp ) == EOF)
|
||||
break ;
|
||||
prevch = c ;
|
||||
}
|
||||
}
|
||||
else if (direction == DOSTOUNIX) {
|
||||
if (!alwaysconvert) {
|
||||
/* basically we withhold emitting any '\r' until we */
|
||||
/* are sure that the next character is not a '\n'. */
|
||||
/* If it is not, we emit the '\r', if it is, we */
|
||||
/* only emit the '\n'. */
|
||||
while ( (c = getc( infp )) != EOF ) {
|
||||
if (prevch == '\r') {
|
||||
/* '\r' is a special case because we don't */
|
||||
/* emit a '\r' until the next character */
|
||||
/* has been read */
|
||||
if (c == '\n') { /* a "\r\n" pair */
|
||||
/* discard previous '\r' and */
|
||||
/* just put the '\n' */
|
||||
if (putc( c, outfp ) == EOF)
|
||||
break ;
|
||||
}
|
||||
else { /* prevch was a standalone '\r' but the current char is not '\n' */
|
||||
/* emit the standalone '\r' */
|
||||
if (putc( '\r', outfp ) == EOF)
|
||||
break ;
|
||||
/* emit the current character if */
|
||||
/* it is not a '\r' */
|
||||
if (c != '\r') {
|
||||
if (putc( c, outfp ) == EOF)
|
||||
break ;
|
||||
}
|
||||
}
|
||||
}
|
||||
else { /* prevch was not '\r' */
|
||||
/* emit current character if it is not */
|
||||
/* a '\r' */
|
||||
if (c != '\r') {
|
||||
if (putc( c, outfp ) == EOF)
|
||||
break ;
|
||||
}
|
||||
}
|
||||
prevch = c ;
|
||||
}
|
||||
} /* alwaysconvert == 0 */
|
||||
else { /* eliminate all '\r' */
|
||||
while ((c = getc( infp )) != EOF) {
|
||||
if (c != '\r') {
|
||||
if (putc( c, outfp ) == EOF)
|
||||
break ;
|
||||
}
|
||||
/* else skip all carriage returns */
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
emsg( EMSG_INTERNAL, EINTNL_DIRECTION );
|
||||
return -1 ;
|
||||
}
|
||||
|
||||
/* if we reach here, either we've reached an EOF or an error */
|
||||
/* occurred. */
|
||||
if (!feof( infp )) { /* error */
|
||||
emsg( EMSG_CONVERT, infilename );
|
||||
return -1 ;
|
||||
}
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
#if defined(UNIX)
|
||||
/*
|
||||
openandconvert_preamble
|
||||
|
||||
On a Unix-type system (including Linux and BSD systems), it is
|
||||
possible for a given filename to be merely a symlink. This function
|
||||
obtains the real filename given the symlink, and calls
|
||||
openandconvert() with the real file name. It simply calls openandconvert()
|
||||
if the filename is not a symlink.
|
||||
|
||||
Note: this function only exists on Unix-type systems. On MSDOS and Windows,
|
||||
openandconvert_preamble() is merely a macro that resolves to
|
||||
openandconvert().
|
||||
|
||||
Returns: whatever openandconvert() returns. (0 on success, -1 on
|
||||
error. Error messages will be displayed on error before returning.
|
||||
*/
|
||||
static int openandconvert_preamble ( char * filename )
|
||||
{
|
||||
struct stat statbuf ;
|
||||
char * realfilepath ;
|
||||
int len ;
|
||||
int err ;
|
||||
|
||||
/* get the file information */
|
||||
if (lstat( filename, &statbuf )) {
|
||||
/* couldn't stat the file. */
|
||||
emsg( EMSG_ACCESSFILE, filename );
|
||||
return -1 ;
|
||||
}
|
||||
|
||||
if (S_ISLNK(statbuf.st_mode)) {
|
||||
/* get the real filename for symbolic links */
|
||||
/* Note: the S_ISLNK() macro is supposed to exist in sys/stat.h */
|
||||
/* Early Unices may not have this macro. If it does not exist, you */
|
||||
/* may have to define it yourself, a la S_ISDIR() and family. */
|
||||
/* eg, #define S_ISLNK(x) (((x) & S_IFMT) == S_IFLNK) */
|
||||
/* or something like that. */
|
||||
|
||||
/* for symbolic links, st_size contains the length of the pathname sans terminating null byte */
|
||||
if (statbuf.st_size == 0) {
|
||||
/* There's a report somewhere of a discovery that Mac OS X returns st_size == 0 for "/dev/stdin" when it
|
||||
is a symlink to "fd/0". I'm not sure if it is a valid report, but let's play it safe. */
|
||||
emsg ( EMSG_SYMLINK, filename );
|
||||
return -1 ;
|
||||
}
|
||||
realfilepath = xmalloc( statbuf.st_size + 1 );
|
||||
|
||||
if ((len = readlink( filename, realfilepath, statbuf.st_size )) != -1) {
|
||||
|
||||
/* got to null terminate the string - there is always space because */
|
||||
/* we passed readlink() the size of the buffer less 1. */
|
||||
realfilepath[len] = '\0' ;
|
||||
if (verbose) {
|
||||
emsg( VERBOSE_SYMLINKSRC, filename, realfilepath );
|
||||
}
|
||||
err = openandconvert( realfilepath );
|
||||
}
|
||||
else {
|
||||
emsg( EMSG_SYMLINK, filename );
|
||||
err = -1 ;
|
||||
}
|
||||
free ( realfilepath );
|
||||
return err ;
|
||||
}
|
||||
/* If we reach here, "filename" is not a symbolic link */
|
||||
return openandconvert( filename );
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
openandconvert
|
||||
|
||||
Called to open the files and convert the contents. If you want
|
||||
it to convert stdin to stdout, call it with NULL as the filename
|
||||
argument; otherwise pass the function the name of the input file.
|
||||
|
||||
Returns: 0 on success, -1 on error. Error messages will be
|
||||
displayed on error before returning.
|
||||
*/
|
||||
static int openandconvert ( char * filename )
|
||||
{
|
||||
FILE * infp ;
|
||||
FILE * outfp ;
|
||||
int err ;
|
||||
char * bakfilename ;
|
||||
unsigned short origfilemode ; /* file mode of original file */
|
||||
struct utimbuf filetimebuf ;
|
||||
int tempfiledes;
|
||||
#if defined(MSDOS)
|
||||
char drv[_MAX_DRIVE];
|
||||
char dir[MAXDIRSIZE];
|
||||
char fname[MAXFILESIZE];
|
||||
char tempname[MAXPATHSIZE];
|
||||
#else
|
||||
char * s ;
|
||||
char * t ;
|
||||
size_t len ;
|
||||
int replacech ;
|
||||
char c ;
|
||||
#endif
|
||||
#if defined(UNIX)
|
||||
uid_t ownerid ;
|
||||
gid_t groupid ;
|
||||
#endif
|
||||
#if NEWBUFSIZ > BUFSIZ
|
||||
char * inbufptr ;
|
||||
char * outbufptr ;
|
||||
#endif
|
||||
|
||||
/* make sure we initialise */
|
||||
bakfilename = NULL ;
|
||||
err = 0 ;
|
||||
|
||||
if (filename != NULL) { /* stdin is not redirected */
|
||||
|
||||
/* check for appropriate permissions on the file */
|
||||
/* also saves the mode in origfilemode */
|
||||
#if !defined(UNIX)
|
||||
if (checkmode( filename, &origfilemode, &filetimebuf ))
|
||||
return -1 ;
|
||||
#else
|
||||
if (checkmode( filename, &origfilemode, &filetimebuf,
|
||||
&ownerid, &groupid ))
|
||||
return -1 ;
|
||||
#endif
|
||||
|
||||
/* we need to create a temporary and backup filename (if */
|
||||
/* applicable) in the same directory */
|
||||
/* as our file. This is easy to do for DOS since we have the */
|
||||
/* _splitpath(), _makepath() functions. */
|
||||
#if defined(MSDOS)
|
||||
_splitpath( filename, drv, dir, fname, NULL );
|
||||
_makepath( tempname, drv, dir, MKTEMP_TEMPL, NULL );
|
||||
tempfilename = xstrdup( tempname );
|
||||
if (!overwrite) {
|
||||
_makepath( tempname, drv, dir, fname, BAKEXT );
|
||||
if (!strcmp( tempname, filename )) {
|
||||
emsg( EMSG_BAKFILENAME, filename );
|
||||
err = -1 ;
|
||||
goto err_freetempfn ;
|
||||
}
|
||||
bakfilename = xstrdup( tempname );
|
||||
}
|
||||
#else /* not MSDOS - ie, Linux, Windows, anything else */
|
||||
/* check if there is a path prefix */
|
||||
if ((s = strrchr( filename, DIRSLASH )) != NULL) {
|
||||
c = *++s ; /* save the character after the slash */
|
||||
*s = '\0';
|
||||
replacech = 1 ;
|
||||
len = strlen( filename ) ;
|
||||
t = filename ;
|
||||
}
|
||||
else {
|
||||
replacech = c = 0 ; /* c is initialized as well to suppress */
|
||||
/* the warning issued by gcc -Wall */
|
||||
len = sizeof(CURRENTDIR) - 1 ;
|
||||
t = CURRENTDIR ;
|
||||
}
|
||||
tempfilename = xmalloc( len + sizeof(MKTEMP_TEMPL) );
|
||||
strcpy( tempfilename, t ); /* add the path leading to filename */
|
||||
strcat( tempfilename, MKTEMP_TEMPL ); /* add the filename */
|
||||
if (replacech)
|
||||
*s = c ;
|
||||
if (!overwrite) {
|
||||
bakfilename = xmalloc( strlen( filename ) + sizeof( BAKEXT ) );
|
||||
strcpy( bakfilename, filename );
|
||||
strcat( bakfilename, BAKEXT ); /* append the extension to existing filename to create name of backup file */
|
||||
}
|
||||
#endif
|
||||
|
||||
/* create the temporary file */
|
||||
if ((tempfiledes = mkstemp( tempfilename )) == -1) {
|
||||
emsg( EMSG_NOTEMPNAME, filename );
|
||||
err = -1 ; /* redundant; defensive */
|
||||
err_freebakfn:
|
||||
if (!overwrite && bakfilename != NULL)
|
||||
free( bakfilename );
|
||||
#if defined(MSDOS)
|
||||
err_freetempfn:
|
||||
#endif
|
||||
free( tempfilename );
|
||||
tempfilename = NULL ;
|
||||
return -1 ;
|
||||
}
|
||||
|
||||
/* open the filename as the input file */
|
||||
if ((infp = fopen( filename, INFILEMODE )) == NULL) {
|
||||
emsg( EMSG_OPENFILE, filename );
|
||||
err = -1 ;
|
||||
goto err_freebakfn ;
|
||||
}
|
||||
/* associate the infilename with the filename for error */
|
||||
/* messages */
|
||||
infilename = filename ;
|
||||
|
||||
/* open the temp file as the output file */
|
||||
if ((tempfp = fdopen( tempfiledes, OUTFILEMODE )) == NULL) {
|
||||
close ( tempfiledes );
|
||||
remove ( tempfilename );
|
||||
emsg( EMSG_CREATETEMP, tempfilename, filename );
|
||||
fclose( infp );
|
||||
err = -1 ;
|
||||
goto err_freebakfn ;
|
||||
}
|
||||
outfp = tempfp ;
|
||||
|
||||
} /* if filename != NULL */
|
||||
else { /* filename == NULL, ie stdin is redirected */
|
||||
infp = stdin ;
|
||||
outfp = stdout ;
|
||||
|
||||
/* not needed, but we do this for the record, and for */
|
||||
/* fussy compilers */
|
||||
origfilemode = 0 ;
|
||||
memset( &filetimebuf, 0, sizeof( struct utimbuf ) );
|
||||
|
||||
#if defined(UNIX)
|
||||
ownerid = groupid = 0 ;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#if NEWBUFSIZ > BUFSIZ
|
||||
/* (don't use xmalloc() because if we can't get what we want, */
|
||||
/* we just don't bother, and go ahead with the minimum) */
|
||||
if ((inbufptr = malloc( NEWBUFSIZ )) != NULL)
|
||||
setvbuf( infp, inbufptr, _IOFBF, NEWBUFSIZ );
|
||||
if ((outbufptr = malloc( NEWBUFSIZ )) != NULL)
|
||||
setvbuf( outfp, outbufptr, _IOFBF, NEWBUFSIZ );
|
||||
#endif
|
||||
/* do the conversion */
|
||||
err = convert( infp, outfp );
|
||||
|
||||
/* close the files */
|
||||
fclose( infp );
|
||||
fclose( outfp );
|
||||
|
||||
if (tempfp != NULL) {
|
||||
/* remove the output file handle from the global to avoid */
|
||||
/* double attempts to close the same file */
|
||||
tempfp = NULL ;
|
||||
}
|
||||
|
||||
#if NEWBUFSIZ > BUFSIZ
|
||||
/* got to free buffers we allocated first */
|
||||
if (inbufptr != NULL)
|
||||
free( inbufptr );
|
||||
if (outbufptr != NULL)
|
||||
free( outbufptr );
|
||||
#endif
|
||||
|
||||
if (filename != NULL) { /* stdin was not redirected */
|
||||
|
||||
if (err) { /* there was an error */
|
||||
/* delete the temp file since we've already created it */
|
||||
remove ( tempfilename );
|
||||
goto err_freebakfn ;
|
||||
}
|
||||
|
||||
if (!overwrite) {
|
||||
#if defined(MSDOS) || defined(WIN32)
|
||||
/* delete any backup file of the same name first, since a rename() does not delete it automatically */
|
||||
/* on DOS and Windows */
|
||||
chmod( bakfilename, S_IRUSR|S_IWUSR ); /* make it writeable (in case it's not) so that it can be deleted */
|
||||
remove( bakfilename ); /* don't check for error returns since the file may not even exist in the first place */
|
||||
#endif
|
||||
/* rename the original file to the back up name */
|
||||
if (rename( filename, bakfilename )) {
|
||||
emsg( EMSG_RENAMEBAK, filename, bakfilename, strerror( errno ) );
|
||||
}
|
||||
}
|
||||
#if defined(MSDOS) || defined(WIN32) /* we need to delete the original file because a rename() operation will not */
|
||||
/* automatically delete it for us on DOS and Windows the way it does on POSIX systems */
|
||||
else { /* if we do not need to back up the original file */
|
||||
chmod( filename, S_IRUSR|S_IWUSR ); /* make it writeable (in case it's not) so that it can be deleted. */
|
||||
remove( filename ); /* delete the original file */
|
||||
/* we don't check for error returns for this, since any error message about its failure will just */
|
||||
/* confuse the user. "What? Why is it deleting my file?" If this fails, the next rename() will fail too */
|
||||
/* since rename() on Windows will not delete the target automatically, and the error message will from the */
|
||||
/* failed rename() will tell the user what happened. */
|
||||
}
|
||||
#endif
|
||||
|
||||
/* rename the temp file to the original file name */
|
||||
if (rename( tempfilename, filename )) {
|
||||
emsg( EMSG_RENAMETMP, tempfilename, filename, strerror( errno ) );
|
||||
}
|
||||
|
||||
/* remove the temp file name from the global for our */
|
||||
/* signal handler*/
|
||||
tempfilename = NULL ;
|
||||
|
||||
/* free memory we allocated */
|
||||
if (!overwrite && bakfilename != NULL)
|
||||
free( bakfilename );
|
||||
|
||||
if (preserve) {
|
||||
/* change to the original file time */
|
||||
utime( filename, &filetimebuf );
|
||||
#if defined(UNIX)
|
||||
/* Change the owner to the owner of the original file. */
|
||||
/* We ignore errors since the user might simply want */
|
||||
/* to use -p to set the file time, and not being root, */
|
||||
/* chown() will fail on Linux. However, we issue an error */
|
||||
/* message if the user wants verbosity. */
|
||||
if (chown( filename, ownerid, groupid ) && verbose)
|
||||
emsg( EMSG_CHOWN, filename );
|
||||
#endif
|
||||
}
|
||||
|
||||
/* change the file mode to reflect the original file mode */
|
||||
chmod( filename, origfilemode );
|
||||
|
||||
} /* stdin was not redirected */
|
||||
|
||||
return err ;
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
/*
|
||||
tofrodos.h Converts text files between DOS and Unix formats.
|
||||
Copyright (c) 1996-2005 by Christopher Heng. All rights reserved.
|
||||
|
||||
$Id: tofrodos.h,v 1.2 2005/03/06 05:40:49 chris Exp $
|
||||
*/
|
||||
|
||||
#if !defined(TOFRODOS_H_INCLUDED)
|
||||
#define TOFRODOS_H_INCLUDED
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* macros */
|
||||
#define UNIXTODOS 0 /* convert from Unix to DOS format */
|
||||
#define DOSTOUNIX 1 /* convert from DOS to Unix format */
|
||||
|
||||
#define EXIT_ERROR 1 /* exit code on error */
|
||||
#define FROMDOSNAME "fromdos"
|
||||
#define FROMDOSNAME2 "dos2unix"
|
||||
#define TODOSNAME "todos"
|
||||
#define TODOSNAME2 "unix2dos"
|
||||
|
||||
/* conditional macros - depends on system and/or compiler */
|
||||
#if defined(MSDOS) || defined(WIN32) /* MSDOS and WIN32 system */
|
||||
#define DEFDIRECTION UNIXTODOS
|
||||
#else /* all systems other than DOS */
|
||||
#define DEFDIRECTION DOSTOUNIX
|
||||
#endif
|
||||
|
||||
|
||||
/* global variables */
|
||||
extern int abortonerr ; /* 1 = abort list of files if error in any */
|
||||
extern int alwaysconvert ; /* convert all \r\n to \r\r\n when direction */
|
||||
/* is UNIXTODOS, and delete all \r when direction is */
|
||||
/* DOSTOUNIX */
|
||||
extern int direction ; /* UNIXTODOS or DOSTOUNIX */
|
||||
extern int forcewrite ; /* convert even if file is not writeable */
|
||||
extern char * errorlogfilename ; /* name of error log file, NULL if we're printing to stderr */
|
||||
extern int overwrite ; /* 1 = overwrite (default), 0 = make backup */
|
||||
extern int preserve ; /* 1 if we are to preserve owner (Unix) and date (all) */
|
||||
extern char * progname ; /* name of binary */
|
||||
extern int verbose ; /* 1 = be noisy, 0 = shut up */
|
||||
|
||||
/* function prototypes */
|
||||
extern int init ( char * firstarg );
|
||||
extern int parseargs ( int argc, char ** argv );
|
||||
#if defined(__WATCOMC__) /* sighandler() never returns */
|
||||
#pragma aux sighandler aborts
|
||||
#endif
|
||||
extern void sighandler ( int sig );
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,68 +0,0 @@
|
|||
/*
|
||||
utility.c Utility functions.
|
||||
Copyright (c) 1996,1997 by Christopher Heng. All rights reserved.
|
||||
|
||||
$Id: utility.c,v 1.3 2005/03/07 13:40:52 chris Exp $
|
||||
*/
|
||||
|
||||
/* this should always be first */
|
||||
#include "config.h"
|
||||
|
||||
/* standard headers */
|
||||
#include <string.h> /* strdup() */
|
||||
#include <stdlib.h> /* malloc() */
|
||||
|
||||
/* our headers */
|
||||
#include "emsg.h"
|
||||
#include "tofrodos.h"
|
||||
#include "utility.h"
|
||||
|
||||
/*
|
||||
errnomem
|
||||
|
||||
Display error message about being out of memory, and exits.
|
||||
It never returns.
|
||||
|
||||
WARNING: It must never return. All code assumes it does not
|
||||
return. Also in Watcom, we define it as a function which does
|
||||
not return (see utility.h) so that the optimiser can jump to
|
||||
this function (instead of calling it).
|
||||
*/
|
||||
void errnomem ( int exitcode )
|
||||
{
|
||||
emsg( EMSG_NOMEM );
|
||||
exit( exitcode );
|
||||
}
|
||||
|
||||
/*
|
||||
xmalloc
|
||||
|
||||
Does the same thing as malloc() except that it never returns
|
||||
a NULL pointer. It aborts with an error message on running
|
||||
out of memory.
|
||||
*/
|
||||
void * xmalloc ( size_t len )
|
||||
{
|
||||
void * ptr ;
|
||||
|
||||
if ((ptr = malloc( len )) == NULL)
|
||||
errnomem( EXIT_ERROR );
|
||||
return ptr ;
|
||||
}
|
||||
|
||||
/*
|
||||
xstrdup
|
||||
|
||||
Same as strdup(). Only, it never returns a NULL pointer.
|
||||
If memory could not be allocated, it exits with an error
|
||||
message.
|
||||
*/
|
||||
char * xstrdup ( const char * s )
|
||||
{
|
||||
char * t ;
|
||||
|
||||
if ((t = strdup( s )) == NULL)
|
||||
errnomem( EXIT_ERROR );
|
||||
return t ;
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
/*
|
||||
utility.h Utility functions.
|
||||
Copyright (c) 1996,1997 by Christopher Heng. All rights reserved.
|
||||
|
||||
$Id: utility.h,v 1.1 2004/10/01 12:33:39 chris Exp $
|
||||
*/
|
||||
|
||||
#if !defined(UTILITY_H_INCLUDED)
|
||||
#define UTILITY_H_INCLUDED
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* function declarations */
|
||||
#if defined(__WATCOMC__) /* errnomem() never returns */
|
||||
#pragma aux errnomem aborts
|
||||
#endif
|
||||
extern void errnomem ( int exitcode );
|
||||
extern void * xmalloc ( size_t len );
|
||||
extern char * xstrdup( const char * s );
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
|
@ -1,16 +0,0 @@
|
|||
/*
|
||||
version.h Version number header.
|
||||
Copyright 1996-2013 Christopher Heng. All rights reserved.
|
||||
*/
|
||||
|
||||
#if !defined(VERSION_H_INCLUDED)
|
||||
#define VERSION_H_INCLUDED
|
||||
|
||||
/* macros */
|
||||
#define VERSN_MAJOR 1
|
||||
#define VERSN_MINOR 7
|
||||
#define VERSN_PATCH 13
|
||||
|
||||
#define VERSN_PROGNAME "tofrodos"
|
||||
|
||||
#endif
|
Binary file not shown.
|
@ -1,182 +0,0 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<head>
|
||||
<!-- Copyright 1996-2013 Christopher Heng. All rights reserved. -->
|
||||
<title>tofrodos - Converts text files between MSDOS and Unix file formats</title>
|
||||
<style type="text/css">
|
||||
h1, h2, p { font-family: Arial, Helvetica, sans-serif ; }
|
||||
dt {
|
||||
font-family: Arial, Helvetica, sans-serif ;
|
||||
font-weight: bold ;
|
||||
}
|
||||
dd {
|
||||
font-family: Arial, Helvetica, sans-serif ;
|
||||
}
|
||||
span.programname {
|
||||
font-weight: bold ;
|
||||
}
|
||||
span.optionchar {
|
||||
font-weight: bold ;
|
||||
}
|
||||
span.filename {
|
||||
font-family: "Courier New", Courier, monospace ;
|
||||
}
|
||||
p.copyright {
|
||||
font-family: Arial, Helvetica, sans-serif ;
|
||||
font-size: 90% ;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>Tofrodos - Converts text files between MSDOS and Unix file formats</h1>
|
||||
|
||||
<h2>Synopsis</h2>
|
||||
|
||||
<p>
|
||||
<span class="programname">fromdos</span> [options] [<span class="filename">file...</span>]<br />
|
||||
<span class="programname">todos</span> [options] [<span class="filename">file...</span>]<br />
|
||||
</p>
|
||||
|
||||
<h2>Description</h2>
|
||||
|
||||
<p>
|
||||
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. <span class="programname">fromdos</span>
|
||||
converts ASCII and Unicode UTF-8 text files from the DOS format to the Unix format, while
|
||||
<span class="programname">todos</span>
|
||||
converts them from the Unix format to the DOS format.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
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.
|
||||
</p>
|
||||
|
||||
<h2>Options</h2>
|
||||
|
||||
<dl title="List of options available for Tofrodos">
|
||||
<dt>-a</dt>
|
||||
<dd>
|
||||
This option is deprecated. Do not use it unless you know what you're doing. By default,
|
||||
Tofrodos does the expected thing for text files. That is, when converting from
|
||||
DOS to Unix, it will remove carriage returns only if they are followed by line feeds.
|
||||
When converting from Unix to DOS, it will add carriage returns only if the linefeeds
|
||||
are not already preceeded by carriage returns. When Tofrodos is run on a normal text file that
|
||||
has already been converted, the resulting file should be identical to the original. However,
|
||||
if you use this option, the program will always remove carriage returns in the DOS to Unix mode
|
||||
and always add carriage returns in the Unix to DOS mode even if it is not appropriate.
|
||||
</dd>
|
||||
<dt>-b</dt>
|
||||
<dd>
|
||||
Make a backup of original file. The original file is renamed
|
||||
with a <span class="filename">.bak</span> extension appended to the original
|
||||
filename, silently replacing any existing file of that name. For example,
|
||||
"<span class="filename">filename.ext</span>" becomes
|
||||
"<span class="filename">filename.ext.bak</span>" replacing any existing file
|
||||
having the name "<span class="filename">filename.ext.bak</span>". 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 <span class="filename">.bak</span> extension. For example,
|
||||
"<span class="filename">filename.ext</span>" becomes "<span class="filename">filename.bak</span>".
|
||||
</dd>
|
||||
<dt>-d</dt>
|
||||
<dd>
|
||||
Convert from DOS to Unix. This forces the program to convert the file in
|
||||
a particular direction. By default, if the program is named
|
||||
<span class="programname">fromdos</span> or <span class="programname">dos2unix</span>
|
||||
it will assume that the input file is in a DOS format and convert it to
|
||||
a Unix format. If the program is named <span class="programname">todos</span> or
|
||||
<span class="programname">unix2dos</span> it will assume that the input file is in a Unix format and convert it to
|
||||
a DOS format. Using the <span class="optionchar">-d</span> option forces the program to convert from a DOS
|
||||
format to a Unix format regardless of how the program is named. Likewise, using the
|
||||
<span class="optionchar">-u</span> option forces the program to convert from a Unix format to a DOS format
|
||||
regardless of the name of the program.
|
||||
</dd>
|
||||
<dt>-e</dt>
|
||||
<dd>
|
||||
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.
|
||||
</dd>
|
||||
<dt>-f</dt>
|
||||
<dd>
|
||||
Force: convert even if the file is not writeable (read-only). By default,
|
||||
if the program 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.
|
||||
</dd>
|
||||
<dt>-h</dt>
|
||||
<dd>
|
||||
Display a short help screen on the program usage and quit.
|
||||
</dd>
|
||||
<dt>-l <logfile></dt>
|
||||
<dd>
|
||||
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.
|
||||
</dd>
|
||||
<dt>-o</dt>
|
||||
<dd>
|
||||
Overwrite the original file (no backup). This is the default.
|
||||
</dd>
|
||||
<dt>-p</dt>
|
||||
<dd>
|
||||
Preserve file ownership and time on Unix-type systems (like Linux). On Windows and MSDOS, it only
|
||||
preserves the file time. Note that on many Unix-type systems, including Linux, the file
|
||||
ownership will only be preserved if the program is run as root, otherwise it
|
||||
will just set the file time and silently fail the change of file
|
||||
ownership. On such systems, if you want a warning message when the file ownership
|
||||
cannot be changed, use <span class="optionchar">-v</span> (the verbose flag) as well.
|
||||
</dd>
|
||||
<dt>-u</dt>
|
||||
<dd>
|
||||
Convert from Unix to DOS. See the <span class="optionchar">-d</span> option above for more information.
|
||||
</dd>
|
||||
<dt>-v</dt>
|
||||
<dd>
|
||||
Verbose.
|
||||
</dd>
|
||||
<dt>-V</dt>
|
||||
<dd>
|
||||
Show version message and quit.
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<h2>Exit Code</h2>
|
||||
|
||||
<p>
|
||||
Tofrodos terminates with an exit code of 0 on success and 1 on error.
|
||||
</p>
|
||||
<p>
|
||||
If the program is invoked with multiple files on the command line, the default behaviour is to skip to the next
|
||||
file in the list if an error is encountered with any file. In such a case, the exit code returned will the
|
||||
status of the last file processed (ie, 0 on success, 1 on failure). If this is not desirable, use the
|
||||
<span class="optionchar">-e</span> option, which will force the program to abort immediately with the appropriate exit
|
||||
code on encountering any error.
|
||||
</p>
|
||||
|
||||
<h2>Author</h2>
|
||||
|
||||
<p>
|
||||
The program and its documentation are copyrighted © 1996-2013 by
|
||||
Christopher Heng. All rights reserved. They are distributed under
|
||||
the terms of the GNU General Public License Version 2.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The latest version of Tofrodos can be obtained from
|
||||
<a href="http://www.thefreecountry.com/tofrodos/index.shtml" target="_top">http://www.thefreecountry.com/tofrodos/index.shtml</a>.
|
||||
</p>
|
||||
|
||||
<hr />
|
||||
|
||||
<p class="copyright">
|
||||
Copyright © 1996-2013 Christopher Heng. All rights reserved.
|
||||
</p>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -1,23 +0,0 @@
|
|||
Begin4
|
||||
Title: tofrodos
|
||||
Version: 1.7.13
|
||||
Entered-date: 2013-10-25
|
||||
Description: DOS text files traditionally have CR/LF (carriage return
|
||||
and line feed) pairs as their new line delimiters while
|
||||
Unix text files traditionally have LFs (line feeds) to
|
||||
terminate each line.
|
||||
tofrodos comprises two programs, "fromdos" and "todos",
|
||||
which convert ASCII and Unicode UTF-8 text files to and from
|
||||
these formats.
|
||||
Keywords: todos, fromdos, unix2dos, dos2unix, text file, line feed,
|
||||
linefeed, newline, carriage return, CR, LF, conversion,
|
||||
convert, tofrodos, dostounix, unixtodos, dtou, utod, msdos,
|
||||
dos, DOS
|
||||
Author: Christopher Heng
|
||||
Maintained-by: Christopher Heng
|
||||
Primary-site: http://www.thefreecountry.com/tofrodos/index.shtml
|
||||
Alternate-site:
|
||||
Original-site:
|
||||
Platforms: Linux, Windows, Mac OS X, FreeBSD, OpenBSD, MSDOS, FreeDOS, Unix
|
||||
Copying-policy: GPL
|
||||
End
|
Loading…
Reference in a new issue