Merged in Soenke's changes for v1.1.5.

This commit is contained in:
gdr 1996-02-04 01:34:31 +00:00
parent cfa60026c9
commit e81ffa659a
13 changed files with 397 additions and 299 deletions

79
usr.orca.bin/udl/HISTORY Normal file
View File

@ -0,0 +1,79 @@
=============================================================================
udl - Convert EOL formats freely between MS-DOS (CR/LF), Unix/Amiga (LF),
and Apple (CR).
(c) 1993-1996 Soenke Behrens, Devin Reade
Version 1.1.5
=============================================================================
Udl converts text files between CR, LF and CR/LF (Apple, Unix and MS-DOS).
It is a very fast utility that ensures that the integrity of the file
cannot be compromised during the translation. It is also much easier
to use than tr(1).
================
Revision History:
================
v1.0.1
Tabs are left alone now. Also recognizes CR/LF (MeSsy-DOS).
v1.0.2
Does no longer read in the complete file, instead creates a temp
file in prefix 3/.
v1.0.3
Fixed a bug, allocated not enough mem for strncpy.
v1.1
Changed to use static GS/OS strings again. Made faster by factor
5.8.
v1.1.1
Cleaned the code up a bit, wrote a Makefile, all output by udl is
prefixed with the name it was invoked with.
v1.1.2
Sped up Apple <-> Unix conversion further (factor 1.5).
v1.1.2 (Unix)
(December 1993)
Modified source to produce a Unix version
v1.1.3
(Updated by Devin Reade, November 1994)
Added ability to recurse through directories (-R flag).
Changed behavior to ignore binary files rather than exiting.
Merged Unix and Apple IIgs versions.
No message is printed out when a binary file (or, in the IIgs
implementation, a non-TXT or non-SRC file) is encountered
unless the -v option is specified.
v1.1.4
(Soenke Behrens, Devin Reade, February 1995)
udl creates a temporary file in the directory of the
source file, not in /tmp. This reduces the likelihood of
data loss in the event of a system crash or powerdown.
udl now accepts something like "udl -R directory/" without
affixing an extra '/' to "directory/".
Fixed bug (via the BROKEN_DIRENT_STRUCT macro) that was causing
filename-munging on Solaris. It seems that the sys/stat.h header
file doesn't agree with the stat implementation.
Modified Makefile.gs to properly write the new executable over
the old resource fork for udl. The resource fork originates with
the file udl.r.
Added suggested defines to the README for various Unix platforms.
Man page changes, including grammar and the deletion of a bug that
no longer exists.
Fixed bug where invoking 'udl -u directory' would attempt to
deref a NULL pointer, causing either memory tromping (IIgs) or
a core dump (Unix).
Tested under SunOS 4.x, SunOS 5.x (Solaris), and AIX.
v1.1.5
(Soenke Behrens, Devin Reade, January 1996)
Changed source slightly to compile under djgpp (MS-DOS) and Linux,
linted source
Unix makefile changed by Devin Reade to automatically detect OS type

15
usr.orca.bin/udl/MANIFEST Normal file
View File

@ -0,0 +1,15 @@
History
Makefile.gs
Makefile.unx
Makefile.msd
Manifest
README
common.c
common.h
globals.c
udl.1
desribe.udl
udlgs.c
udl.rez
udlunix.c
udluse.c

View File

@ -1,10 +1,10 @@
#
# Makefile for udl
# Copyright (c) 1993-1996 Soenke Behrens
# Copyright (c) 1993-1996 Soenke Behrens, Devin G. Reade
#
# This makefile should be used with dmake.
#
# $Id: Makefile.gs,v 1.8 1996/01/22 01:01:30 gdr Exp $
# $Id: Makefile.gs,v 1.9 1996/02/04 01:34:23 gdr Exp $
#
# Where do we put the binaries and man page?
@ -42,7 +42,7 @@ udl.o: udlgs.c common.h
install:
cp -f udl $(BINDIR)
cp -f udl.1 $(MANDIR)
cp -f udl.1 $(MANDIR)/man1
help:
mkdir $@
@ -56,8 +56,5 @@ clean:
clobber: clean
-$(RM) -rf udl help
dist:
@echo "Sorry, automatic packing not supported yet"
common.o:: common.h
globals.o:: common.h

View File

@ -0,0 +1,43 @@
#
# Makefile for udl
# (c) 1993-1996 Soenke Behrens
#
# DJGPP is a gcc port
CC = gcc
# Where do we put the binaries and man page?
BINDIR = /djgpp/bin
MANDIR = /djgpp/man
# OS-dependant macros. See the README for an explanation of these.
DEFINES = -DREADDIR_RETURNS_DOT -DHAS_ATEXIT
INSTALL = cp -f
CFLAGS = $(DEFINES) -O2
#
# You should not have to modify anything beyond this point
#
OBJS = udl.o udluse.o common.o globals.o
udl: $(OBJS)
$(CC) $(LDFLAGS) -o udl $(OBJS) $(LDLIBS)
udl.o: udlunix.c common.h
$(CC) -c $(CFLAGS) -o udl.o udlunix.c
install:
$(INSTALL) udl $(DESTDIR)$(BINDIR)
$(INSTALL) udl.1 $(DESTDIR)$(MANDIR)
clean:
-rm *.o *~ core
clobber: clean
-rm udl
udluse.o common.o globals.o:: common.h

View File

@ -1,11 +1,11 @@
#
# Makefile for udl
# (c) 1993-1996 Soenke Behrens
# (c) 1993-1996 Soenke Behrens, Devin G. Reade
#
# $Id: Makefile.unx,v 1.7 1996/01/22 01:01:31 gdr Exp $
# $Id: Makefile.unx,v 1.8 1996/02/04 01:34:25 gdr Exp $
#
# $(CC) _must_ be an ANSI compiler.
# $(CC) _must_ be an ANSI compiler. Use gcc if your cc is not.
CC = cc
BINDIR = /usr/local/bin
MANDIR = /usr/local/man/man1
@ -62,7 +62,7 @@ udl.o: udlunix.c common.h
newudl.1: udl.1
@echo "creating newudl.1"; \
echo '/^.TH/ c\' > sed.script; \
echo '.TH UDL 1 "15 January 1996" "Version 1.15"\
echo '.TH UDL 1 "15 January 1996" "Version 1.1.5"\
"Commands and Applications"' >>sed.script; \
sed -f sed.script <udl.1 >newudl.1; \
rm -f sed.script

View File

@ -4,21 +4,39 @@ udl - Convert EOL formats freely between MS-DOS (CR/LF), Unix/Amiga (LF),
(c) 1993-1996 Soenke Behrens, Devin Reade
Version 1.15: $Id: README,v 1.8 1996/01/22 01:01:32 gdr Exp $
Version 1.1.5: $Id: README,v 1.9 1996/02/04 01:34:25 gdr Exp $
=============================================================================
Udl converts text files between CR, LF and CR/LF (Apple, Unix and MS-DOS).
It is a very fast utility that ensures that the integrity of the file
cannot be compromised during the translation. It is also much easier
to use than tr(1).
Udl converts text files between the various end-of-line conventions, i.e.
CR, LF, and CR/LF, used by the Apple IIgs, MS-DOS, Amiga, and Unix.
After conversion, the original file is replaced with the converted file.
Udl is known to run with ORCA/Shell 2.x, GNO/ME 2.x, and Unix.
Not only is udl faster and simpler than tr(1), but it saves a step in
the conversion process by automatically replacing the original file
after the conversion completes. Thus:
udl file
replaces the longer sequence of
tr '\012' '\015' < file > file.temp
mv file.temp file
Because it replaces the original file, udl makes every effort to ensure
that the conversion process cannot corrupt the original. The translation
process uses a temporary file and replaces the original only after the
translation has completed. In case of a machine crash or power-down, the
original file remains intact, unless the machine dies at precisely the
instant the update occurs. This problem exists for a manual file
replacement, as in:
mv file.temp file
so the risk is no greater.
=========
Compiling:
=========
There are two makefiles included:
Makefile.gs - for use on the Apple IIgs running GNO
Makefile.unx - for use with Unix systems.
Three makefiles are included:
Makefile.gs For use on the Apple IIgs running GNO
Makefile.unx For use with Unix systems
Makefile.msd For use with MS-DOS systems (djgpp)
Although udl on the IIgs can be run from either GNO or ORCA shells,
it cannot be built with the standard ORCA installation due to a lack
@ -39,11 +57,11 @@ Note that compilation of udl _requires_ an ANSI C compiler.
If you are compiling to a new system, add in another set of defines
and let us know about them.
Note that udl.c assumes that getopt() is declared in <unistd.h> and that
the function strdup() exists in <string.h>. You might have to change
these includes if that's not the case. Ensure you use cpp conditional
compilations to match your platform (and to avoid breaking the code for
other platforms).
Note that udlunix.c and udlgs.c assume that getopt() is declared in
<unistd.h> and that the function strdup() exists in <string.h>. You
might have to change these includes if that's not the case. Ensure you
use cpp conditional compilations to match your platform (and to avoid
breaking the code for other platforms).
============
Installation
@ -53,7 +71,7 @@ Apple IIgs with GNO
^^^^^^^^^^^^^^^^^^^
Type 'dmake install -f Makefile.gs'. By default this copies the binary
into "/usr/local/bin" and the man page into "/usr/local/man/man1". (You
_are_ using version 3.x of 'man', are you not? *blatent plug*) If you
_are_ using version 3.x of 'man', are you not? *blatant plug*) If you
don't like these locations, either modify the BINDIR and MANDIR
macros in the makefile or install the files by hand.
@ -120,6 +138,13 @@ The following are the DEFINES values for tested operating systems:
-DGNO -D_POSIX_C_SOURCE -D_POSIX_SOURCE -DHAS_ATEXIT
-DOVERFLOW_CHECK
MS-DOS: (use "make -f Makefile.msd")
^^^^^^
DJGPP: (tested with djgpp v2beta)
-DREADDIR_RETURNS_DOT -DHAS_ATEXIT
TESTED UNIX OS's: (use "make -f Makefile.unx")
^^^^^^^^^^^^^^^^
SunOS 4.x: (tested with gcc)
@ -137,94 +162,63 @@ The following are the DEFINES values for tested operating systems:
-DREADDIR_RETURNS_DOT -D_POSIX_C_SOURCE -D_POSIX_SOURCE
-DHAS_ATEXIT
================
Revision History:
================
=====
Files
=====
The following files are present in the udl package:
README This file
History Revision history
Makefile.gs make(1) script for GNO
Makefile.unx make(1) script for Unix
Makefile.msd make(1) script for MS-DOS
common.c Routines common to GNO and Unix versions
common.h Header file for common.c
globals.c Global variable definitions
udl.1 Man page for udl command
describe.udl short description of udl, FTP info
udlgs.c Apple IIgs specific routines
udl.rez Apple IIgs REZ source for resource fork
udlunix.c Unix specific routines
udluse.c Strings for invocation information
v1.01
Tabs are left alone now. Also recognizes CR/LF (MeSsy-DOS).
=====
Notes
=====
v1.02
Does no longer read in the complete file, instead creates a temp
file in prefix 3/.
If the machine crashes before udl has replaced the original file with
the converted file, the temporary file needs to be manually deleted.
The temporary file resides in the same directory as the source file
and has a name of the form:
UDLTMPXX
where XX is replaced by AA, AB and so on.
v1.03
Fixed a bug, allocated not enough mem for strncpy.
=========
Copyright
=========
v1.1
Changed to use static GS/OS strings again. Made faster by factor
5.8.
COPYRIGHT 1993-1996 by Soenke Behrens and Devin Reade
ALL RIGHTS RESERVED
v1.11
Cleaned the code up a bit, wrote a Makefile, all output by udl is
prefixed with the name it was invoked with.
This package may be redistributed so long as no fee is charged, the
authors' names remain, and all modifications are clearly marked as
such and the unmodified source is included.
v1.12
Sped up Apple <-> Unix conversion further (factor 1.5).
v1.12 (Unix)
(December 1993)
Modified source to produce a Unix version
v1.13
(Updated by Devin Reade, November 1994)
Added ability to recurse through directories (-R flag).
Changed behavior to ignore binary files rather than exiting.
Merged Unix and Apple IIgs versions.
No message is printed out when a binary file (or, in the IIgs
implementation, a non-TXT or non-SRC file) is encountered
unless the -v option is specified.
v1.14
(Soenke Behrens, Devin Reade, February 1995)
udl creates a temporary file in the directory of the
source file, not in /tmp. This reduces the likelihood of
data loss in the event of a system crash or powerdown.
udl now accepts something like "udl -R directory/" without
affixing an extra '/' to "directory/".
Fixed bug (via the BROKEN_DIRENT_STRUCT macro) that was causing
filename-munging on Solaris. It seems that the sys/stat.h header
file doesn't agree with the stat implementation.
Modified Makefile.gs to properly write the new executable over
the old resource fork for udl. The resource fork originates with
the file udl.r.
Added suggested defines to the README for various Unix platforms.
Man page changes, including grammar and the deletion of a bug that
no longer exists.
Fixed bug where invoking 'udl -u directory' would attempt to
deref a NULL pointer, causing either memory tromping (IIgs) or
a core dump (Unix).
Tested under SunOS 4.x, SunOS 5.x (Solaris), and AIX.
v1.15
(Devin Reade, January 1996)
Changed Makefile.unx to select what should be the proper
defines automatically, based on the result of `uname -sr`.
Added Linux defines.
Changed references and definition of "mktemp" to "Mktemp". There
is a discrepancy between the internal implementation and
other common Unix versions.
Added a section to this README on installation, and moved the
description of the DEFINES from the makefiles to here.
On the IIgs version, the resource fork is now created from a
resource source file that is compiled, rather than using
an interactive tool to create the resource fork.
Changed source filenames to use the 8.3 format in anticipation of
MS-DOS support. This does not affect the file names upon which
udl operates.
This program contains material from the Orca/C Run-Time Libraries,
Copyright 1987-1995 by Byte Works, Inc. Used with permission.
=======
Authors
=======
Original code by Soenke Behrens <sbehrens@contech.demon.co.uk>
with modifications and version-merging by Devin Reade <gdr@myrias.com>
with modifications and version-merging by Devin Reade <gdr@myrias.ab.ca>.
==========
Legalities:
==========
Soenke Behrens
sbehrens@contech.demon.co.uk
This program contains material from the Orca/C Run-Time Libraries,
copyright 1987-1996 by Byte Works, Inc. Used with permission.
Devin Reade
gdr@myrias.ab.ca
=============================================================================
January 1996
Version 1.1.5

View File

@ -4,7 +4,7 @@
*
* Routines common to both the Unix and Apple IIgs versions.
*
* $Id: common.c,v 1.8 1996/01/22 01:01:32 gdr Exp $
* $Id: common.c,v 1.9 1996/02/04 01:34:26 gdr Exp $
*
* Copyright (c) 1993-1995 Soenke Behrens, Devin Reade
*/
@ -54,49 +54,43 @@ void convert_gs(FILE *infile, FILE *outfile) {
in_bufend = in_buffer + my_fread(infile,BUFFERSIZE);
in_bufpos = in_buffer;
}
/* a = fgetc (infile); */
if(a == '\n') {
*out_bufpos = '\r';
if(a == LF) {
*out_bufpos = CR;
out_bufpos++;
if (out_bufpos == out_bufend) {
my_fwrite(out_buffer,outfile,BUFFERSIZE);
out_bufpos = out_buffer;
my_fwrite(out_buffer,outfile,BUFFERSIZE);
out_bufpos = out_buffer;
}
/* fputc('\r',outfile); */
} else if(a == '\r') {
*out_bufpos = '\r';
} else if(a == CR) {
*out_bufpos = CR;
out_bufpos++;
if (out_bufpos == out_bufend) {
my_fwrite(out_buffer,outfile,BUFFERSIZE);
out_bufpos = out_buffer;
my_fwrite(out_buffer,outfile,BUFFERSIZE);
out_bufpos = out_buffer;
}
/* fputc('\r',outfile); */
if (*in_bufpos == '\n' && file_remain != 0) {
in_bufpos++;
if (in_bufpos >= in_bufend) {
file_remain -= in_bufend - in_buffer;
in_bufend = in_buffer + my_fread(infile, BUFFERSIZE);
in_bufpos = in_buffer;
}
if (*in_bufpos == LF && file_remain != 0) {
in_bufpos++;
if (in_bufpos >= in_bufend) {
file_remain -= in_bufend - in_buffer;
in_bufend = in_buffer + my_fread(infile, BUFFERSIZE);
in_bufpos = in_buffer;
}
}
/* if ((a = fgetc (infile)) != '\n')
ungetc (a,infile); */
} else {
*out_bufpos = a;
out_bufpos++;
if (out_bufpos == out_bufend) {
my_fwrite(out_buffer,outfile,BUFFERSIZE);
out_bufpos = out_buffer;
my_fwrite(out_buffer,outfile,BUFFERSIZE);
out_bufpos = out_buffer;
}
/* fputc(a,outfile); */
}
}
/* Check for remainder in output buffer */
if (out_bufpos != out_buffer)
my_fwrite(out_buffer,outfile,out_bufpos - out_buffer);
my_fwrite(out_buffer,outfile,(int)(out_bufpos - out_buffer));
}
/*
@ -137,65 +131,57 @@ void convert_messy (FILE *infile, FILE *outfile) {
in_bufend = in_buffer + my_fread(infile, BUFFERSIZE);
in_bufpos = in_buffer;
}
/* a = fgetc (infile); */
if(a == '\n') {
*out_bufpos = '\r';
if(a == LF) {
*out_bufpos = CR;
out_bufpos++;
if (out_bufpos == out_bufend) {
my_fwrite(out_buffer,outfile,BUFFERSIZE);
out_bufpos = out_buffer;
my_fwrite(out_buffer,outfile,BUFFERSIZE);
out_bufpos = out_buffer;
}
/* fputc('\r',outfile); */
*out_bufpos = '\n';
*out_bufpos = LF;
out_bufpos++;
if (out_bufpos == out_bufend) {
my_fwrite(out_buffer,outfile,BUFFERSIZE);
out_bufpos = out_buffer;
my_fwrite(out_buffer,outfile,BUFFERSIZE);
out_bufpos = out_buffer;
}
/* fputc('\n',outfile); */
} else if(a == '\r') {
*out_bufpos = '\r';
} else if(a == CR) {
*out_bufpos = CR;
out_bufpos++;
if (out_bufpos == out_bufend) {
my_fwrite(out_buffer,outfile,BUFFERSIZE);
out_bufpos = out_buffer;
my_fwrite(out_buffer,outfile,BUFFERSIZE);
out_bufpos = out_buffer;
}
/* fputc('\r',outfile); */
*out_bufpos = '\n';
*out_bufpos = LF;
out_bufpos++;
if (out_bufpos == out_bufend) {
my_fwrite(out_buffer,outfile,BUFFERSIZE);
out_bufpos = out_buffer;
my_fwrite(out_buffer,outfile,BUFFERSIZE);
out_bufpos = out_buffer;
}
/* fputc('\n',outfile); */
if (*in_bufpos == '\n' && file_remain != 0) {
in_bufpos++;
if (*in_bufpos == LF && file_remain != 0) {
in_bufpos++;
if (in_bufpos >= in_bufend) {
file_remain -= in_bufend - in_buffer;
in_bufend = in_buffer + my_fread(infile, BUFFERSIZE);
in_bufpos = in_buffer;
}
if (in_bufpos >= in_bufend) {
file_remain -= in_bufend - in_buffer;
in_bufend = in_buffer + my_fread(infile, BUFFERSIZE);
in_bufpos = in_buffer;
}
}
/* if ((a = fgetc (infile)) != '\n')
ungetc (a,infile); */
} else {
*out_bufpos = a;
out_bufpos++;
if (out_bufpos == out_bufend) {
my_fwrite(out_buffer,outfile,BUFFERSIZE);
out_bufpos = out_buffer;
my_fwrite(out_buffer,outfile,BUFFERSIZE);
out_bufpos = out_buffer;
}
/* fputc(a,outfile); */
}
}
/* Check for remained in output buffer */
/* Check for remainder in output buffer */
if (out_bufpos != out_buffer)
my_fwrite(out_buffer,outfile,out_bufpos - out_buffer);
my_fwrite(out_buffer,outfile,(int)(out_bufpos - out_buffer));
}
/*
@ -236,41 +222,36 @@ void convert_tunix (FILE *infile, FILE *outfile) {
in_bufend = in_buffer + my_fread(infile, BUFFERSIZE);
in_bufpos = in_buffer;
}
/* a = fgetc (infile); */
if(a == '\r') {
*out_bufpos = '\n';
if(a == CR) {
*out_bufpos = LF;
out_bufpos++;
if (out_bufpos == out_bufend) {
my_fwrite(out_buffer,outfile,BUFFERSIZE);
out_bufpos = out_buffer;
my_fwrite(out_buffer,outfile,BUFFERSIZE);
out_bufpos = out_buffer;
}
/* fputc('\n',outfile); */
if (*in_bufpos == '\n' && file_remain != 0) {
in_bufpos++;
if (*in_bufpos == LF && file_remain != 0) {
in_bufpos++;
if (in_bufpos >= in_bufend) {
file_remain -= in_bufend - in_buffer;
in_bufend = in_buffer + my_fread(infile, BUFFERSIZE);
in_bufpos = in_buffer;
}
if (in_bufpos >= in_bufend) {
file_remain -= in_bufend - in_buffer;
in_bufend = in_buffer + my_fread(infile, BUFFERSIZE);
in_bufpos = in_buffer;
}
}
/* if ((a = fgetc (infile)) != '\n')
ungetc (a,infile); */
} else {
*out_bufpos = a;
out_bufpos++;
if (out_bufpos == out_bufend) {
my_fwrite(out_buffer,outfile,BUFFERSIZE);
out_bufpos = out_buffer;
my_fwrite(out_buffer,outfile,BUFFERSIZE);
out_bufpos = out_buffer;
}
/* fputc(a,outfile); */
}
}
/* Check for remainder in output buffer */
if (out_bufpos != out_buffer)
my_fwrite(out_buffer,outfile,out_bufpos - out_buffer);
my_fwrite(out_buffer,outfile,(int)(out_bufpos - out_buffer));
}
/*
@ -289,21 +270,17 @@ void convert_tunix (FILE *infile, FILE *outfile) {
int convert_fast_gs(FILE *infile, FILE *outfile) {
unsigned char a;
unsigned char *in_bufpos;
unsigned char *out_bufpos;
unsigned char *in_bufend;
unsigned char *out_bufend;
size_t file_remain;
enum file_format infile_type;
in_bufpos = in_buffer;
out_bufpos = out_buffer;
(void) fseek(infile,0L,SEEK_END);
file_remain = ftell(infile);
rewind(infile);
in_bufend = in_buffer + my_fread(infile,BUFFERSIZE);
out_bufend = out_buffer + BUFFERSIZE;
*in_bufend = '\0';
infile_type = get_file_format (in_buffer);
@ -312,7 +289,7 @@ int convert_fast_gs(FILE *infile, FILE *outfile) {
case apple:
if (verbose)
printf("%s: %s is already in Apple format, skipping.\n",
program_name,current_file);
program_name,current_file);
return (FALSE);
break;
@ -320,18 +297,18 @@ int convert_fast_gs(FILE *infile, FILE *outfile) {
/* Replace "in-vitro", so out_buffer isn't used */
while (file_remain != 0) {
a = *in_bufpos;
if (a == '\n')
*in_bufpos++ = '\r';
if (a == LF)
*in_bufpos++ = CR;
else if (a == '\0') { /* End of buffer reached */
/* Write changed buffer out */
my_fwrite(in_buffer,outfile,in_bufend - in_buffer);
/* And reload it */
file_remain -= in_bufend - in_buffer;
in_bufend = in_buffer + my_fread(infile, BUFFERSIZE);
*in_bufend = '\0';
in_bufpos = in_buffer;
/* Write changed buffer out */
my_fwrite(in_buffer,outfile,(int)(in_bufend - in_buffer));
/* And reload it */
file_remain -= in_bufend - in_buffer;
in_bufend = in_buffer + my_fread(infile, BUFFERSIZE);
*in_bufend = '\0';
in_bufpos = in_buffer;
} else in_bufpos++;
}
return (TRUE);
@ -367,22 +344,10 @@ int convert_fast_gs(FILE *infile, FILE *outfile) {
*/
int convert_fast_messy (FILE *infile, FILE *outfile) {
unsigned char *in_bufpos;
unsigned char *out_bufpos;
unsigned char *in_bufend;
unsigned char *out_bufend;
size_t file_remain;
enum file_format infile_type;
in_bufpos = in_buffer;
out_bufpos = out_buffer;
(void) fseek(infile,0L,SEEK_END);
file_remain = ftell(infile);
rewind(infile);
in_bufend = in_buffer + my_fread(infile, BUFFERSIZE);
out_bufend = out_buffer + BUFFERSIZE;
*in_bufend = '\0';
infile_type = get_file_format (in_buffer);
@ -391,7 +356,7 @@ int convert_fast_messy (FILE *infile, FILE *outfile) {
case dos:
if (verbose)
printf("%s: %s is already in MS-DOS format, skipping.\n",
program_name,current_file);
program_name,current_file);
return (FALSE);
break;
@ -429,21 +394,17 @@ int convert_fast_messy (FILE *infile, FILE *outfile) {
int convert_fast_tunix (FILE *infile, FILE *outfile) {
unsigned char a;
unsigned char *in_bufpos;
unsigned char *out_bufpos;
unsigned char *in_bufend;
unsigned char *out_bufend;
size_t file_remain;
enum file_format infile_type;
in_bufpos = in_buffer;
out_bufpos = out_buffer;
(void) fseek(infile,0L,SEEK_END);
file_remain = ftell(infile);
rewind(infile);
in_bufend = in_buffer + my_fread(infile, BUFFERSIZE);
out_bufend = out_buffer + BUFFERSIZE;
*in_bufend = '\0';
infile_type = get_file_format (in_buffer);
@ -452,7 +413,7 @@ int convert_fast_tunix (FILE *infile, FILE *outfile) {
case tunix:
if (verbose)
printf("%s: %s is already in Unix format, skipping.\n",
program_name,current_file);
program_name,current_file);
return (FALSE);
break;
@ -460,18 +421,18 @@ int convert_fast_tunix (FILE *infile, FILE *outfile) {
/* Replace "in-vitro", so out_buffer isn't used */
while (file_remain != 0) {
a = *in_bufpos;
if (a == '\r')
*in_bufpos++ = '\n';
if (a == CR)
*in_bufpos++ = LF;
else if (a == '\0'){ /* End of buffer reached */
/* Write changed buffer out */
my_fwrite(in_buffer,outfile,in_bufend - in_buffer);
/* Write changed buffer out */
my_fwrite(in_buffer,outfile,(int)(in_bufend - in_buffer));
/* And reload */
file_remain -= in_bufend - in_buffer;
in_bufend = in_buffer + my_fread(infile, BUFFERSIZE);
*in_bufend = '\0';
in_bufpos = in_buffer;
/* And reload */
file_remain -= in_bufend - in_buffer;
in_bufend = in_buffer + my_fread(infile, BUFFERSIZE);
*in_bufend = '\0';
in_bufpos = in_buffer;
} else in_bufpos++;
}
return (TRUE);
@ -509,26 +470,26 @@ int convert_fast_tunix (FILE *infile, FILE *outfile) {
enum file_format get_file_format (unsigned char *buffer) {
unsigned char c;
enum file_format result = 0;
enum file_format result = unknown;
while ((c = *buffer++) != '\0') {
if (c == '\n') {
if (c == LF) {
result = tunix;
break;
} else if (c == '\r') {
if (*buffer == '\n')
result = dos;
} else if (c == CR) {
if (*buffer == LF)
result = dos;
else
result = apple;
result = apple;
break;
}
}
if (result == 0) {
if (result == unknown) {
if (verbose)
printf("%s: No EOL found on the first %d bytes "
"of %s. Might be a binary file. File skipped\n",
program_name,BUFFERSIZE, current_file);
"of %s. Might be a binary file. File skipped\n",
program_name,BUFFERSIZE, current_file);
result = binary;
}
@ -570,7 +531,7 @@ FILE *tryopen (char *name, char *mode) {
int my_fread(FILE *infile, int howmuch) {
int result;
result = fread(in_buffer, 1, howmuch, infile);
result = (int)fread(in_buffer, 1, howmuch, infile);
if (ferror(infile)) {
fprintf(stderr,"%s: Error while reading data\n",program_name);
exit (EXIT_FAILURE);
@ -676,12 +637,17 @@ void build_file_list(char *file, short recurse) {
DIR *dir;
struct dirent *entry;
#ifdef __DJGPP__ /* chdir() doesn't accept dir names ending in '\\' */
if(file[strlen(file)-1] == '\\')
file[strlen(file)-1] = '/';
#endif
/* check for stack overflow */
recursionDepth++;
#ifdef OVERFLOW_CHECK
if ((recursionDepth * BYTES_PER_DEPTH + BASESIZE) > STACKSIZE) {
fprintf(stderr,"%s: Exceeded permitted nesting depth (%d levels)\n"
"Aborted.\n",program_name,recursionDepth);
"Aborted.\n",program_name,recursionDepth);
exit(EXIT_FAILURE);
}
#endif
@ -694,7 +660,7 @@ void build_file_list(char *file, short recurse) {
if (recurse && S_ISDIR(tstat.st_mode)) {
char tstr[2];
/*
* It is a directory. recurse through it.
*/
@ -721,45 +687,45 @@ void build_file_list(char *file, short recurse) {
/* recurse */
if ((dir = opendir(file)) == NULL) {
fprintf(stderr,"%s: Couldn't open %s. Directory skipped.\n",
program_name,currentDirectory);
program_name,currentDirectory);
} else {
if (chdir(file) !=0) {
fprintf(stderr,"couldn't cd to %s\n",currentDirectory);
exit (EXIT_FAILURE);
fprintf(stderr,"couldn't cd to %s\n",currentDirectory);
exit (EXIT_FAILURE);
}
#ifdef READDIR_RETURNS_DOT
entry = readdir(dir); /* for "." */
entry = readdir(dir); /* for ".." */
#endif
entry = readdir(dir); /* for ".." */
#endif
while ((entry = readdir(dir))!=NULL) {
/* ignore hidden files */
/* ignore hidden files */
#ifdef BROKEN_DIRENT_STRUCT
if (*(entry->d_name)!='.') build_file_list((entry->d_name)-2,1);
if (*(entry->d_name)!='.') build_file_list((entry->d_name)-2,1);
#else
if (*(entry->d_name)!='.') build_file_list(entry->d_name,1);
if (*(entry->d_name)!='.') build_file_list(entry->d_name,1);
#endif
}
if (*thisdir) {
if ((chdir(rootdir)!=0) || (chdir(thisdir)!=0)) {
fprintf(stderr,"couldn't cd to %s\n",thisdir);
exit (EXIT_FAILURE);
}
if ((chdir(rootdir)!=0) || (chdir(thisdir)!=0)) {
fprintf(stderr,"couldn't cd to %s\n",thisdir);
exit (EXIT_FAILURE);
}
} else {
if (chdir(rootdir)!=0) {
fprintf(stderr,"couldn't cd to calling directory\n");
exit (EXIT_FAILURE);
}
if (chdir(rootdir)!=0) {
fprintf(stderr,"couldn't cd to calling directory\n");
exit (EXIT_FAILURE);
}
}
}
/* restore our state */
strcpy(currentDirectory,thisdir);
free(thisdir);
} else if (S_ISREG(tstat.st_mode)) {
/* It is a normal file. Add it to the pathList */
@ -778,13 +744,13 @@ void add_to_pathList(char *thisdir, char *file) {
pathSlots += PATHLIST_QUANTUM;
#if BROKEN_REALLOC
if ((pathList==NULL) &&
((pathList = malloc((pathSlots+1) * sizeof(char *)))==NULL)) {
((pathList = malloc((pathSlots+1) * sizeof(char *)))==NULL)) {
fprintf(stderr,"%s: Couldn't expand pathList\n",program_name);
exit (EXIT_FAILURE);
} else {
if ((p = realloc(pathList, (pathSlots+1) * sizeof(char *)))==NULL) {
fprintf(stderr,"%s: Couldn't expand pathList\n",program_name);
exit (EXIT_FAILURE);
fprintf(stderr,"%s: Couldn't expand pathList\n",program_name);
exit (EXIT_FAILURE);
}
pathList = p;
}
@ -800,7 +766,7 @@ void add_to_pathList(char *thisdir, char *file) {
pathList[pathSlotsUsed] = malloc(strlen(thisdir)+strlen(file)+2);
if (pathList[pathSlotsUsed] == NULL) {
fprintf(stderr,"%s: Couldn't duplicate filename %s%c%s\n",program_name,
thisdir,dirbrk,file);
thisdir,dirbrk,file);
exit (EXIT_FAILURE);
}
if (*thisdir) {
@ -845,29 +811,29 @@ char *Mktemp(const char *base)
if (*st == '\0')
{
free (st);
if ((st = strdup("TXXXXXXX")) == NULL)
{
fprintf(stderr,"%s: memory allocation failure\n", program_name);
exit (EXIT_FAILURE);
}
free (st);
if ((st = strdup("TXXXXXXX")) == NULL)
{
fprintf(stderr,"%s: memory allocation failure\n", program_name);
exit (EXIT_FAILURE);
}
}
/* Replace all "X" with part of ID string */
for(p1 = st + strlen(st) - 1,p2 = &id[14];
p1 >= st && p2 >= id && *p1 == 'X';
p1--,p2--)
*p1 = *p2;
p1 >= st && p2 >= id && *p1 == 'X';
p1--,p2--)
*p1 = *p2;
/* Update ID string to "count" one further */
for(p1 = &id[14];p1 >= id;)
if(*p1 == 'Z')
{
*p1 = 'A';
p1--;
*p1 = 'A';
p1--;
} else {
*p1 += 1;
break;
*p1 += 1;
break;
}
/* Make sure the file name does not already exist */
@ -876,22 +842,22 @@ char *Mktemp(const char *base)
#endif
if (stat(st,&tstat) == 0)
{
free (st);
st = Mktemp (base);
free (st);
st = Mktemp (base);
}
#ifdef GNO
} else { /* ORCA/Shell doesn't like stat one little bit */
FILE *fp;
if ((fp = fopen(st,"r")) != NULL)
{
fclose(fp);
free (st);
st = Mktemp (base);
fclose(fp);
free (st);
st = Mktemp (base);
} else if ((fp = fopen(st,"a")) == NULL) {
free(st);
st = Mktemp (base);
free(st);
st = Mktemp (base);
} else {
fclose(fp);
fclose(fp);
}
}
#endif
@ -916,7 +882,7 @@ char *get_path (const char *name)
strcpy(filebuffer, name);
for (i = strlen(filebuffer) - 1; i > 0 && filebuffer[i] != dirbrk; i--)
for (i = (int)strlen(filebuffer) - 1; i > 0 && filebuffer[i] != dirbrk; i--)
; /* empty loop to find end of path in name */
if (i != 0)

View File

@ -4,7 +4,7 @@
*
* Header file for routines common to both the Unix and Apple IIgs versions.
*
* $Id: common.h,v 1.8 1996/01/22 01:01:33 gdr Exp $
* $Id: common.h,v 1.9 1996/02/04 01:34:27 gdr Exp $
*
* Copyright (c) 1993-1995 Soenke Behrens, Devin Reade
*/
@ -23,11 +23,16 @@
#define BUFFERSIZE 0x2000
#define PATHLIST_QUANTUM 20
#define UDL_VERSION "Version 1.14"
#define UDL_VERSION "Version 1.1.5"
#define STACKSIZE 2048
#define BYTES_PER_DEPTH 40
#define BASESIZE 700
/* define the equivalents of LF and CR that your compiler uses */
/* "Standard" settings should work for most systems */
#define LF '\n'
#define CR '\r'
#ifndef FALSE
# define FALSE 0
# define TRUE !FALSE
@ -44,7 +49,7 @@
# define EXIT(a) { cleanup(); exit(a); }
#endif
enum file_format { tunix = 1, dos, apple, binary };
enum file_format { unknown = 0, tunix = 1, dos, apple, binary };
/* Since udl is so small, I dare to use some globals :) */
extern char *program_name; /* How was udl invoked? */
@ -83,8 +88,9 @@ extern void cleanup (void);
extern void usage (void);
extern void build_file_list(char *file, short recurse);
extern void add_to_pathList(char *thisdir, char *file);
extern char *get_path(const char *name);
extern char *Mktemp(const char *base);
extern char *get_path(const char *name);
extern int needsgno(void);
/* not strictly necessary, but it cuts down on warnings from gcc */
@ -92,7 +98,7 @@ extern int needsgno(void);
extern char *getwd(char *);
#endif
#ifdef __GNUC__
#if defined (__GNUC__) && !defined (__DJGPP__)
extern char getopt(int, char **, char *);
#endif

View File

@ -4,7 +4,7 @@
*
* Contains definitions of global variables declared in common.h
*
* $Id: globals.c,v 1.5 1996/01/22 01:01:34 gdr Exp $
* $Id: globals.c,v 1.6 1996/02/04 01:34:28 gdr Exp $
*
* Copyright (c) 1993-1995 Soenke Behrens, Devin Reade
*/

View File

@ -1,7 +1,6 @@
.\" Copyright (c) 1993-1995 Soenke Behrens, Devin Reade
.\" $Id: udl.1,v 1.8 1996/01/22 01:01:34 gdr Exp $
.\" Copyright (c) 1993-1996 Soenke Behrens, Devin Reade
.\"
.TH UDL 1 "Commands and Applications" "21 January 1996" "Version 1.15"
.TH UDL 1 "Commands and Applications" "31 January 1996" "Version 1.1.5"
.SH NAME
udl - convert text files between different architectures
.SH SYNOPSIS
@ -76,7 +75,7 @@ one file). For conversions to or from MS-DOS
is always pedantic, so this only affects conversions from Unix to Apple
or vice versa. Being pedantic slows udl down by a factor of 1.5.
.SH LIMITATIONS
When running under Gno on the Apple IIgs, there is a limit to the nesting
When running under GNO on the Apple IIgs, there is a limit to the nesting
depth when recusing on subdirectories. This is because the routine that
is responsible for this behavior is itself recursive. The default 2k
stack size will allow about 33 levels of nested directories, so this limit
@ -92,4 +91,4 @@ Devin Reade <gdr@myrias.ab.ca>.
.SH VERSION
This is
.B udl
version 1.15.
version 1.1.5.

View File

@ -1,7 +1,7 @@
#include "Types.Rez"
resource rVersion (0x1, purgeable1, nocrossbank) {
{ 1, 1, 5, /* version 1.1.4 */
{ 1, 1, 5, /* version 1.1.5 */
release, /* development|alpha|beta|final|release */
0 /* non-final release number */
},

View File

@ -4,7 +4,7 @@
*
* Unix specific routines.
*
* $Id: udlunix.c,v 1.8 1996/01/22 01:01:35 gdr Exp $
* $Id: udlunix.c,v 1.9 1996/02/04 01:34:30 gdr Exp $
*
* Copyright (c) 1993-1995 Soenke Behrens, Devin Reade
*/
@ -15,7 +15,6 @@ extern char *strdup(const char *);
int main(int argc,char *argv[]) {
FILE *infile, *outfile;
char *p;
int Tunix = FALSE;
int Messy = FALSE;
int GS = FALSE;
@ -156,16 +155,16 @@ int main(int argc,char *argv[]) {
fprintf(stderr,"%s: memory allocation failure\n", program_name);
exit (EXIT_FAILURE);
}
if (verbose == TRUE) {
printf("%s: Working on %s\n",program_name,
current_file);
}
infile = tryopen(current_file,"rwb");
infile = tryopen(current_file,"r+b");
tempfile = Mktemp(strcat(get_path(current_file), "udltmpXX"));
outfile = tryopen(tempfile,"wb");
if (careful) {
converted = TRUE; /* always */

View File

@ -4,7 +4,7 @@
*
* Usage strings.
*
* $Id: udluse.c,v 1.8 1996/01/22 01:01:36 gdr Exp $
* $Id: udluse.c,v 1.9 1996/02/04 01:34:31 gdr Exp $
*
* Copyright (c) 1993-1995 Soenke Behrens, Devin Reade
*/
@ -14,7 +14,7 @@
#endif
char use1 [] =
"udl 1.15 by Soenke Behrens, Devin Reade\n"
"udl 1.1.5 by Soenke Behrens, Devin Reade\n"
"Usage: udl -u|g|m [-Rvp] file1 [file2 ...]\n\n"
"Options:\n"
" -u Convert file to use LF as EOL character.\n"