This commit was manufactured by cvs2svn to create tag 'v1_0_1'.

This commit is contained in:
cvs2git 1997-09-21 22:08:33 +00:00
commit ce659c58fd
17 changed files with 656 additions and 2239 deletions

32
usr.bin/catrez/Makefile Normal file
View File

@ -0,0 +1,32 @@
#
# This makefile is intended for use with dmake(1).
#
# It is adapted for catrez by Dave Tribby <tribby@cup.hp.com>
# from Devin Reade's makefile for splatprep
# destination directories
BINDIR = /usr/local/bin
MANDIR = /usr/man
DEFINES += -Dcatrez
STACK = -s768
CFLAGS += $(DEFINES) $(STACK) -w -v -O
LDFLAGS += -v
OBJS = catrez.o
catrez: $(OBJS) version.r
$(CC) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $@
catrez -v -d $@ version.r
install:
cp catrez $(BINDIR)
cp catrez.1 $(MANDIR)/man1
clean:
$(RM) -f *.o *.root *.r
clobber: clean
$(RM) -f catrez

74
usr.bin/catrez/README Normal file
View File

@ -0,0 +1,74 @@
catrez -- concatenate resource forks from files
DESCRIPTION
===========
catrez concatenates resources from multiple files into the resource fork of
a single file. (The data fork of the destination file is not modified.) This
is useful to programmers who create resources for a program in several
different files and need to combine them into the resource fork of the final
executable file.
See the man page for details.
NOTE -- version 1.0.1 fixes a problem found in 1.0: resources with the
"protected" attribute set were not copied correctly.
INSTALLATION
============
Method 1:
dmake install
Method 2:
cp catrez /usr/local/bin
cp catrez.1 /usr/man/man1
OTHER FILES
===========
The ORCA/C source file for catrez is included (catrez.c), as well as the
REZ source code (version.rez) and the "dmake" file (makefile.mk).
AUTHOR
======
Dave Tribby. Please send bug reports to <tribby@cup.hp.com>
THANKS
======
To Devin Reade and Soenke Behrens for their many contributions to the
Apple IIGS programming community that make creating programs easier.
Among their various tools, Devin's dmake and Soenke's occ have helped
me on many large and small programming projects.
To Steve Reeves (stever@gate.net) for finding a problem with resources
that have the protected attribute set, and sending the code to fix
the problem.
LEGAL
=====
Copyright 1996 by David M. Tribby
This software is provided as freeware (not public domain). You may distribute
it as long as you don't charge money for it (beyond your media costs), and you
don't try to claim it for your own. You must also keep this archive intact when
distributing the software.
For other distribution information, contact Dave Tribby <tribby@cup.hp.com>.
This program contains material from the ORCA/C Run-Time Libraries,
copyright 1987-1996 by Byte Works, Inc. Used with permission.
This program contains routines from the GNO/ME libraries, copyright
Procyon Enterprises, Inc.

59
usr.bin/catrez/catrez.1 Normal file
View File

@ -0,0 +1,59 @@
.TH catrez 1 "Commands and Applications" "27 July 1996" "Version 1.0"
.SH NAME
catrez \- concatenate resource forks from files
.SH SYNOPSIS
.B catrez
[
.I -v
]
[
.I -a
]
.RI "-d " dest_file
.I file1
[
.IR file2 ...
]
.SH DESCRIPTION
.B catrez
concatenates resources from multiple files into the resource fork of a
single file. (The data fork of the destination file is not modified.)
This is useful to programmers who create
resources for a program in several different files and need to combine
them into the resource fork of the final executable file.
.SH OPTIONS
.IP -v
Produce verbose output, including: the program version,
the name of each source file, the type & ID of each copied resource, and
whether a resource converter is required.
.IP -a
Append resources to the destination file rather than overwriting the
resource fork.
.IP "-d destfile"
Existing destination file name [required parameter].
.SH "GNO COMPATIBILITY"
.B catrez
will shut itself down if it receives any of the following signals:
SIGHUP (hang-up),
SIGINT (user keyboard interrupt),
SIGPIPE (writing to a pipe with no reader),
SIGALRM (alarm timer expiration), or
SIGTERM (kill). User signals (SIGUSR1 and SIGUSR2) are ignored.
.SH EXAMPLES
Append the resources from menu.r to the resource fork of progfile
.nf
catrez -a -d progfile menu.r
.fi
Combine several resource files and add to progfile
.nf
catrez -d progfile version.r menu.r window.r startup.r
.fi
.SH "RETURN VALUES"
.B catrez
returns zero on success, non-zero otherwise.
.SH AUTHOR
Dave Tribby <tribby@cup.hp.com>

466
usr.bin/catrez/catrez.c Normal file
View File

@ -0,0 +1,466 @@
/* ---------------------------------------------------------------------
*
* Concatenate resources multiple files into the resource fork of a file
*
* catrez [-v] [-a] -d destfile file1 [file2 ... ]
* where the options mean:
* -v verbose output
* -a append resources to destination rather than overwriting
* -d destfile the destination file name [required]
* file1 file2 ... the source file(s) [at least 1 required]
*
* Written by Dave Tribby (tribby@cup.hp.com) beginning 5-3-96
*
* ---------------------------------------------------------------------
*/
char *copyright = " Copyright 1996 by David M. Tribby\n";
char *prog_version = " Version 1.0.1 (%s)\n";
/* NOTE: if you need to compile this without code specific to gno, */
/* #define __NO_GNO__ */
#include <Types.h>
#include <Memory.h>
#include <GSOS.h>
#include <Resources.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <orca.h>
#ifndef __NO_GNO__
#include <GNO/gno.h>
#include <signal.h>
#endif
#pragma lint -1
/* #pragma debug 25 */ /* Only for development */
#pragma optimize 95 /* Bit 5 off due to defect in ORCA/C 2.1.0 */
/* Scheduling parameters */
int verboseflag = FALSE;
int appendflag = FALSE;
GSString255Ptr dest_filename = NULL;
Word dest_file_id = 0; /* GSOS file ID for destination */
int status_return = 0; /* Program return status */
int user_break = FALSE; /* TRUE if user hits break (GNO) */
/* Error message */
char *rezopenerr = "Error $%04X opening resource fork of %s\n";
/* Resources.h left out this one: don't pre-load when opening file */
#define noPreload 0x8000
#ifndef __NO_GNO__
/* Running under GNO or ORCA? */
int gnoactive;
/* ---------------------------------------------------------------------
*
* SigHandler
*
* Signal handler routine (only used under GNO)
* Don't do anything fancy; just terminate quickly after these sigs
*
*----------------------------------------------------------------------
*/
#pragma databank 1
void SigHandler(int sig, int code)
{
switch (sig) {
case SIGHUP: /* Hang-up */
case SIGINT: /* User keyboard interrupt */
case SIGPIPE: /* Writing to a pipe with no reader */
case SIGALRM: /* Alarm timer expiration */
case SIGTERM: /* Kill */
user_break = TRUE;
status_return = 1;
break;
}
} /* SigHandler */
#pragma databank 0
#endif
/* ---------------------------------------------------------------------
*
* Resource converter routine
*
* This routine copies a resource in and out of memory without
* modification. It is used for resources with the "converter"
* attribute bit set. Since catrez doesn't want any conversion
* to take place, it makes no modifications.
*
* See pp 45-21 to 45-26 in the Apple IIGS Toolbox Reference, Vol 3
*
* ---------------------------------------------------------------------
*/
#pragma databank 1
#pragma toolparms 1
pascal long NullConverter(
Word convertCommand, /* 0=read, 2=write, 4=size */
IORecPtrGS convertParam, /* read/write control block */
ResRefRecPtr resPointer) /* resource reference ptr */
{
long return_val = 0; /* Function return value */
int command_code; /* GS/OS command code */
if (convertCommand == 4) {
/* ReturnDiskSize */
return_val = GetHandleSize((Handle)resPointer->resHandle);
}
else {
/* Do the Read or Write */
if (convertCommand == 2)
command_code = 0x2013; /* Write */
else
command_code = 0x2012; /* Read */
/* Since the asm code for calling GS/OS was provided in */
/* the toolbox reference, insert it here. */
asm {
pei convertParam+2 ; Pointer to GS/OS
pei convertParam ; parameter block
pei command_code ; GS/OS read or write
jsl 0xE100B0 ; Call GS/OS
sta return_val ; Save error code
};
}
return return_val;
} /* NullConverter */
#pragma toolparms 0
#pragma databank 0
/* ---------------------------------------------------------------------
*
* AllDone
*
* Function called at completion of program; set by "atexit()"
*
* ---------------------------------------------------------------------
*/
void AllDone(void)
{
/* Make sure destination file is compacted */
if ( dest_file_id ) CompactResourceFile(0, dest_file_id);
/* Shut down the resource manager (which closes open resource files) */
ResourceShutDown();
} /* AllDone */
/* ---------------------------------------------------------------------
*
* CtoGS
*
* Turn C-string into a GS/OS input string
*
*
* ---------------------------------------------------------------------
*/
GSString255Ptr CtoGS(char *c_str)
{
GSString255Ptr gs_str;
/* Allocate memory for string, null char, & length word */
if (gs_str = (GSString255Ptr) malloc(strlen(c_str)+5)) {
/* Set length field and copy text */
gs_str->length = strlen(c_str);
strcpy(gs_str->text, c_str);
}
return gs_str;
} /* CtoGS */
/* ---------------------------------------------------------------------
*
* OpenDestination
*
* Open or create the destination file
*
* ---------------------------------------------------------------------
*/
Word OpenDestination(void)
{
int error;
static OpenRecGS open_rec = { 10, 0, NULL, readWriteEnable, 1};
static SetPositionRecGS eof_rec = { 3, 0, 0, 0 };
static RefNumRecGS close_rec = { 1 };
/* If append flag isn't set, remove existing resources (if any) */
if (!appendflag) {
/* Open resource fork of destination file */
open_rec.pathname = dest_filename;
OpenGS(&open_rec);
if (!toolerror()) {
/* Set EOF position at 0 */
eof_rec.refNum = open_rec.refNum;
SetEOFGS(&eof_rec);
/* Close the file */
close_rec.refNum = open_rec.refNum;
CloseGS(&close_rec);
}
}
/* Create destination file resource fork; no-op if file */
/* already exists and has a resource fork. */
/* Note: "unknown" file type (0) is used. */
CreateResourceFile(0, 0, readWriteEnable+renameEnable+destroyEnable,
(Pointer)dest_filename);
/* Open the destination file resource fork */
dest_file_id = OpenResourceFile(noPreload+readWriteEnable,
NULL, (Pointer)dest_filename);
if (error = toolerror()) {
printf(rezopenerr, error,dest_filename->text);
exit(2);
}
/* Only want to look at one file at a time */
SetResourceFileDepth(1);
} /* OpenDestination */
/* ---------------------------------------------------------------------
*
* CopyResources
*
* Copy resources from the named file to the destination file
*
* ---------------------------------------------------------------------
*/
void CopyResources(char *fname)
{
GSString255Ptr src_filename;
Word file_id;
int error;
Word type_index;
long rez_index;
Word rez_type;
long rez_ID;
Handle rez_handle;
Word rez_attr;
if (verboseflag) printf("\nSource file: %s \n", fname);
/* Turn C-string source file name into a GS/OS input string */
src_filename = CtoGS(fname);
/* Open the file's resource fork */
file_id = OpenResourceFile(noPreload+readEnable,
NULL, (Pointer)src_filename);
error = toolerror();
/* Done with the GS/OS string */
free(src_filename);
/* Cannot proceed if resource fork wasn't opened */
if (error) {
printf(rezopenerr, error,fname);
status_return = 1;
return;
}
/* Get resource information from the source file */
SetCurResourceFile(file_id);
/* Loop through resource types */
for (type_index=1; !user_break; type_index++) {
/* Get the next type; done when error code is set */
rez_type = GetIndType(type_index);
if (toolerror()) break;
if (verboseflag) printf(" Resource type %04X: ", rez_type);
/* Loop through IDs for this type */
for (rez_index=1; !user_break; rez_index++) {
/* Get the next ID for this type; done when error code is set */
rez_ID = GetIndResource(rez_type, rez_index);
if (toolerror()) break;
if (verboseflag) printf(" %7lX", rez_ID);
/* Special handling required if "converter" attribute is set */
rez_attr = GetResourceAttr(rez_type, rez_ID);
if (rez_attr & 0x0800) {
if (verboseflag) printf("\n");
printf("NOTE: Converter required: type %04X, ID %lX, file %s\n",
rez_type,rez_ID,fname);
/* Use the "null" converter to preserve raw format */
ResourceConverter((Pointer)&NullConverter,
rez_type, resLogApp+resLogIn);
}
/* Load the resource */
rez_handle = LoadResource(rez_type, rez_ID);
if (error = toolerror()) {
printf("\nError %04X loading type %04X, ID %lX, file %s\n",
error,rez_type,rez_ID,fname);
status_return = 1;
continue;
}
/* Detach resource from its file */
DetachResource(rez_type, rez_ID);
/* Temporarily reset to destination resource file */
SetCurResourceFile(dest_file_id);
/* Add resource to destination file, ignoring "protected" attribute */
AddResource(rez_handle, rez_attr & ~resProtected, rez_type, rez_ID);
if (error = toolerror()) {
printf("\nError %04X adding type %04X, ID %lX\n",
error,rez_type,rez_ID);
status_return = 1;
}
else {
/* Force it to disk */
WriteResource(rez_type, rez_ID);
if (error = toolerror()) {
printf("\nError %04X writing type %04X, ID %lX\n",
error,rez_type,rez_ID);
status_return = 1;
}
/* Set "protected" attribute again if necessary */
if (rez_attr & resProtected) {
SetResourceAttr(rez_attr, rez_type, rez_ID);
if (error = toolerror()) {
printf("\nError %04X setting attributes for type %04X, ID %lX\n",
error,rez_type,rez_ID);
status_return = 1;
}
}
}
/* Release the resource from memory */
ReleaseResource(-1, rez_type, rez_ID);
if (error = toolerror()) {
printf("\nError %04X releasing type %04X, ID %X\n",
error,rez_type,rez_ID);
status_return = 1;
}
/* Resume getting resource information from the source file */
SetCurResourceFile(file_id);
}
if (verboseflag) printf("\n");
}
/* Close the source file */
CloseResourceFile(file_id);
} /* CopyResources */
/*----------------------------------------------------------------------*/
int main (int argc, char **argv)
/*----------------------------------------------------------------------*/
{
int p_num; /* Parameter number */
int destfileprovided = FALSE;
char *illegal_opt="Warning: Illegal option %s ignored\n";
char *usage=
"Usage:\n\tcatrez [-v] [-a] -d dest_file file1 [file2 ...]\n";
#ifndef __NO_GNO__
/* Are we running under the GNO kernel? */
kernStatus();
gnoactive = (toolerror() == 0);
if ( gnoactive ) {
/* Install the GNO signal handlers */
signal(SIGHUP, SigHandler);
signal(SIGINT, SigHandler);
signal(SIGPIPE, SigHandler);
signal(SIGALRM, SigHandler);
signal(SIGTERM, SigHandler);
/* Ignore user signals (so they don't kill the program) */
signal(SIGUSR1, SIG_IGN);
signal(SIGUSR2, SIG_IGN);
}
#endif
/* If no parameters were provided, print the usage string */
if (argc < 2) {
printf(usage);
printf(copyright);
printf(prog_version, __DATE__);
return 0;
}
/* Parse the option parameters */
p_num = 1;
while ((p_num < argc) && (argv[p_num][0] == '-') ) {
if (strlen(argv[p_num]) > 2)
printf(illegal_opt, argv[p_num]);
else switch ( argv[p_num][1] ) {
case 'v':
verboseflag = TRUE;
printf("%s: ", argv[0]);
printf(prog_version, __DATE__);
break;
case 'a':
appendflag = TRUE;
break;
case 'd':
destfileprovided = TRUE;
p_num++;
if (p_num == argc) {
printf("Error: -d option requires a destination filename\n");
printf(usage);
return 1;
}
else {
dest_filename = CtoGS(argv[p_num]);
}
break;
default:
printf(illegal_opt, argv[p_num]);
}
p_num++;
}
if (!destfileprovided) {
printf("Error: No destination filename provided\n");
printf(usage);
return 1;
}
if (p_num == argc) {
printf("Error: No source filenames provided\n");
printf(usage);
return 1;
}
/* Start the resource manager */
ResourceStartUp(userid());
/* Set the cleanup function */
atexit(AllDone);
/* Open (or create) the destination file */
OpenDestination();
/* Open and copy each of the source files */
while ( (p_num < argc) && !user_break ) {
CopyResources(argv[p_num]);
p_num++;
}
/* Cleanup is done in atexit() */
return status_return;
}

View File

@ -0,0 +1,25 @@
/*
* Resources for catrez version and comments
* Written by Dave Tribby
*/
#include ":H1:Orca:Libraries:Rinclude:Types.rez"
// Version
resource rVersion (1, $0000) {
{1, 0, 1, release, 0},
verUS,
"catrez",
"Copyright 1996 by David M. Tribby"
};
// Comment Templates
resource rComment (1, $0000) {
"catrez v1.0.1\n"
"Shell program to concatenate resource forks of files\n"
"by Dave Tribby\n"
"Copyright 1996\n\n"
"Freeware: Distribute freely, but don't charge."
};

View File

@ -1,63 +0,0 @@
#
# Makefile for udl
# Copyright (c) 1993-1996 Soenke Behrens
#
# This makefile should be used with dmake.
#
# $Id: Makefile.gs,v 1.8 1996/01/22 01:01:30 gdr Exp $
#
# Where do we put the binaries and man page?
BINDIR = /usr/local/bin
MANDIR = /usr/local/man
# OS-dependant macros. See the README for an explanation of these.
DEFINES = -DGNO -D_POSIX_C_SOURCE -D_POSIX_SOURCE -DHAS_ATEXIT \
-DOVERFLOW_CHECK
# Use optimization and a 2k stack.
CFLAGS = $(DEFINES) -O -w -s2048
LDFLAGS = -s2048
# Depending on how you have your libraries set up, you may not need
# this next line. In that case, just comment it out.
LDLIBS = -l/usr/lib/gnulib
#
# You should not have to modify anything beyond this point
#
OBJS = udl.o udluse.o common.o globals.o
udl: $(OBJS) udl.r help/udl
$(CC) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $@
copyfork udl.r $@ -r
udl.o: udlgs.c common.h
$(CC) -c $(CFLAGS) -o udl.o udlgs.c
install:
cp -f udl $(BINDIR)
cp -f udl.1 $(MANDIR)
help:
mkdir $@
help/udl: udl.1 help
nroff -man udl.1 > $@
clean:
-$(RM) *.o *.root udl.r
clobber: clean
-$(RM) -rf udl help
dist:
@echo "Sorry, automatic packing not supported yet"
common.o:: common.h
globals.o:: common.h

View File

@ -1,94 +0,0 @@
#
# Makefile for udl
# (c) 1993-1996 Soenke Behrens
#
# $Id: Makefile.unx,v 1.7 1996/01/22 01:01:31 gdr Exp $
#
# $(CC) _must_ be an ANSI compiler.
CC = cc
BINDIR = /usr/local/bin
MANDIR = /usr/local/man/man1
INSTALL = /usr/bin/install
# These are arguments to $(INSTALL)
MODE644 = -m 644
MODE755 = -m 755
OWNER_GROUP = -o bin -g sys
# You should not have to modify anything beyond this point
##########################################################
#
# OS-dependant macros. See the README for an explanation of these.
#
DEFINES_AIX = -DBROKEN_REALLOC -D_POSIX_C_SOURCE -D_POSIX_SOURCE
DEFINES_Linux = -DREADDIR_RETURNS_DOT -D_POSIX_C_SOURCE -D_POSIX_SOURCE \
-DHAS_ATEXIT
DEFINES_Solaris = -DREADDIR_RETURNS_DOT -D_POSIX_C_SOURCE -D_POSIX_SOURCE \
-DBROKEN_DIRENT_STRUCT
LDLIBS_Solaris = -lucb
DEFINES_SunOS = -DREADDIR_RETURNS_DOT -D_POSIX_C_SOURCE -D_POSIX_SOURCE \
-DBROKEN_REALLOC
CFLAGS = $(DEFINES_$(OS)) -O
LDFLAGS = $(LDFLAGS_$(OS)) -s
LDLIBS = $(LDLIBS_$(OS))
OBJS = udl.o udluse.o common.o globals.o
build:
@os_string=`uname -sr | tr ' ' '_'`; \
case $$os_string in \
SunOS_4*) os=SunOS;; \
SunOS_5*) os=Solaris;; \
AIX*) os=AIX;; \
Linux*) os=Linux;; \
*) echo "don't know about OS $$os_string"; \
exit -1;; \
esac; \
$(MAKE) udl -f Makefile.unx OS=$$os
udl: $(OBJS)
$(CC) $(LDFLAGS) -o udl $(OBJS) $(LDLIBS)
udl.o: udlunix.c common.h
$(CC) -c $(CFLAGS) -o udl.o udlunix.c
newudl.1: udl.1
@echo "creating newudl.1"; \
echo '/^.TH/ c\' > sed.script; \
echo '.TH UDL 1 "15 January 1996" "Version 1.15"\
"Commands and Applications"' >>sed.script; \
sed -f sed.script <udl.1 >newudl.1; \
rm -f sed.script
install: newudl.1 udl
$(INSTALL) $(MODE755) $(OWNER_GROUP) udl $(BINDIR)
$(INSTALL) $(MODE644) $(OWNER_GROUP) newudl.1 $(MANDIR)/udl.1
rm -f newudl.1
clean:
-rm -f *.o *~ core
clobber: clean
-rm -rf udl newudl.1 help
dist: clobber
@echo "creating archive"; \
cwd=`pwd`; \
parent=`dirname $$cwd`; \
dir=`basename $$cwd`; \
cd $$parent; \
archive=$$dir.tar.Z; \
if [ -f $$archive ]; then \
echo "please move $$parent/$$archive out of the way, first"; \
exit -1; \
fi; \
tar -cf - $$dir | compress > $$archive
udluse.o common.o globals.o:: common.h

View File

@ -1,230 +0,0 @@
=============================================================================
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.15: $Id: README,v 1.8 1996/01/22 01:01:32 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).
=========
Compiling:
=========
There are two makefiles included:
Makefile.gs - for use on the Apple IIgs running GNO
Makefile.unx - for use with Unix systems.
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
of additional libraries.
The IIgs distribution should contain a binary of udl, including a
resource fork. Therefore, you should be able to skip straight to the
section on installation. For those who must know, however, building the
binaries under GNO should just be a matter of typing 'dmake -f Makefile.gs'.
If you are compiling on Unix operating systems that have been previously
tested, you should be able to just type 'make -f Makefile.unx'. This
will select the appropriate DEFINES for your system. For an explanation
the various DEFINES, see the section below on "DEFINES Definitions".
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).
============
Installation
============
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
don't like these locations, either modify the BINDIR and MANDIR
macros in the makefile or install the files by hand.
If you have describe(1) installed, you can update the udl(1) entry
with the file "describe.udl". See the descu(8) and descc(8) man pages
for details.
Apple IIgs with Orca/Shell
^^^^^^^^^^^^^^^^^^^^^^^^^^
Copy the following files to their respective destinations:
udl to 17
help/udl to 17/help
Unix systems
^^^^^^^^^^^^
Type 'make -f Makefile.unx install'. By default the binary will
go into /usr/local/bin and the man page into /usr/local/man/man1.
This assumes root access. If this does not match your plans and/or
access permissions, either copy the files by hand or change the
BINDIR, MANDIR, and OWNER_GROUP macros in the makefile.
===================
DEFINES Definitions
===================
If you have problems compiling or are porting udl to a new operating
system, define the following macros in the makefile as necessary.
They should be used as the value of $(DEFINES_$(OS)) where $(OS) is
your operating system as returned by `uname -sr | tr ' ' '_'`.
HAS_ATEXIT if your system has atexit()
_POSIX_C_SOURCE and _POSIX_SOURCE if your compiler is Posix compliant
READDIR_RETURNS_DOT if your direct readdir() function will return
entries for "." and "..". SunOS 4.x and 5.x (Solaris) are known to
do this.
BROKEN_REALLOC if your realloc() doesn't behave like malloc() when
passed a NULL pointer as the first argument.
BROKEN_DIRENT_STRUCT if you find that the first two letters of
filenames obtained during directory recursion (as shown when the
"-v" flag is used) seem to be missing. Some installations of
Solaris are known to do this.
GNO if you are compiling on the IIgs. This will allow for both
':' and '/' as pathname separators.
OVERFLOW_CHECK Udl uses one recursive subroutine. Define this if
you want to check for stack overflows for this routine (independent
of any compiler flags). Strongly recommended.
CHECK_STACK if you want stack usage to be displayed (IIgs only).
You will also have to specify -l/usr/lib/stack in LDFLAGS.
The following are the DEFINES values for tested operating systems:
APPLE IIGS: (use "dmake -f Makefile.gs")
^^^^^^^^^^
ORCA/Shell and GNO/ME: (tested with occ)
-DGNO -D_POSIX_C_SOURCE -D_POSIX_SOURCE -DHAS_ATEXIT
-DOVERFLOW_CHECK
TESTED UNIX OS's: (use "make -f Makefile.unx")
^^^^^^^^^^^^^^^^
SunOS 4.x: (tested with gcc)
-DREADDIR_RETURNS_DOT -DBROKEN_REALLOC
-D_POSIX_C_SOURCE -D_POSIX_SOURCE
SunOS 5.x (Solaris): (tested with SUNWspro cc)
-DREADDIR_RETURNS_DOT -DBROKEN_DIRENT_STRUCT
-D_POSIX_C_SOURCE -D_POSIX_SOURCE
AIX 3.2: (tested with xlc)
-DBROKEN_REALLOC -D_POSIX_C_SOURCE -D_POSIX_SOURCE
Linux 1.2.3: (tested with gcc)
-DREADDIR_RETURNS_DOT -D_POSIX_C_SOURCE -D_POSIX_SOURCE
-DHAS_ATEXIT
================
Revision History:
================
v1.01
Tabs are left alone now. Also recognizes CR/LF (MeSsy-DOS).
v1.02
Does no longer read in the complete file, instead creates a temp
file in prefix 3/.
v1.03
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.11
Cleaned the code up a bit, wrote a Makefile, all output by udl is
prefixed with the name it was invoked with.
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.
=======
Authors
=======
Original code by Soenke Behrens <sbehrens@contech.demon.co.uk>
with modifications and version-merging by Devin Reade <gdr@myrias.com>
==========
Legalities:
==========
This program contains material from the Orca/C Run-Time Libraries,
copyright 1987-1996 by Byte Works, Inc. Used with permission.
=============================================================================

View File

@ -1,928 +0,0 @@
/*
* udl - Convert EOL formats freely between MS-DOS (CR/LF), Unix/Amiga (LF),
* and Apple (CR).
*
* Routines common to both the Unix and Apple IIgs versions.
*
* $Id: common.c,v 1.8 1996/01/22 01:01:32 gdr Exp $
*
* Copyright (c) 1993-1995 Soenke Behrens, Devin Reade
*/
#ifdef GNO
#pragma noroot
#endif
#include "common.h"
extern char *strdup(const char *);
/*
* convert_gs() ... convert files to use CR as EOL
*
* Inputs:
* FILE *infile File to read from
* FILE *outfile File to write to
*
* Outputs:
* None
*/
void convert_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;
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;
while (file_remain != 0) {
a = *in_bufpos;
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;
}
/* a = fgetc (infile); */
if(a == '\n') {
*out_bufpos = '\r';
out_bufpos++;
if (out_bufpos == out_bufend) {
my_fwrite(out_buffer,outfile,BUFFERSIZE);
out_bufpos = out_buffer;
}
/* fputc('\r',outfile); */
} else if(a == '\r') {
*out_bufpos = '\r';
out_bufpos++;
if (out_bufpos == out_bufend) {
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 ((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;
}
/* fputc(a,outfile); */
}
}
/* Check for remainder in output buffer */
if (out_bufpos != out_buffer)
my_fwrite(out_buffer,outfile,out_bufpos - out_buffer);
}
/*
* convert_messy() ... convert files to use CR/LF as EOL
*
* Inputs:
* FILE *infile File to read from
* FILE *outfile File to write to
*
* Outputs:
* None
*/
void convert_messy (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;
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;
while (file_remain != 0) {
a = *in_bufpos;
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;
}
/* a = fgetc (infile); */
if(a == '\n') {
*out_bufpos = '\r';
out_bufpos++;
if (out_bufpos == out_bufend) {
my_fwrite(out_buffer,outfile,BUFFERSIZE);
out_bufpos = out_buffer;
}
/* fputc('\r',outfile); */
*out_bufpos = '\n';
out_bufpos++;
if (out_bufpos == out_bufend) {
my_fwrite(out_buffer,outfile,BUFFERSIZE);
out_bufpos = out_buffer;
}
/* fputc('\n',outfile); */
} else if(a == '\r') {
*out_bufpos = '\r';
out_bufpos++;
if (out_bufpos == out_bufend) {
my_fwrite(out_buffer,outfile,BUFFERSIZE);
out_bufpos = out_buffer;
}
/* fputc('\r',outfile); */
*out_bufpos = '\n';
out_bufpos++;
if (out_bufpos == out_bufend) {
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 >= 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;
}
/* fputc(a,outfile); */
}
}
/* Check for remained in output buffer */
if (out_bufpos != out_buffer)
my_fwrite(out_buffer,outfile,out_bufpos - out_buffer);
}
/*
* convert_tunix() ... convert files to use LF as EOL
*
* Inputs:
* FILE *infile File to read from
* FILE *outfile File to write to
*
* Outputs:
* None
*/
void convert_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;
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;
while (file_remain != 0) {
a = *in_bufpos;
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;
}
/* a = fgetc (infile); */
if(a == '\r') {
*out_bufpos = '\n';
out_bufpos++;
if (out_bufpos == out_bufend) {
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 >= 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;
}
/* fputc(a,outfile); */
}
}
/* Check for remainder in output buffer */
if (out_bufpos != out_buffer)
my_fwrite(out_buffer,outfile,out_bufpos - out_buffer);
}
/*
* convert_fast_gs() ... convert files to use CR as EOL
* Do not care about differing EOL chars in the same file,
* do not allow '\0' bytes, and replace in-vitro if possible.
*
* Inputs:
* FILE *infile File to read from
* FILE *outfile File to write to
*
* Outputs:
* int FALSE if no conversion took place, TRUE otherwise
*/
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);
switch (infile_type) {
case apple:
if (verbose)
printf("%s: %s is already in Apple format, skipping.\n",
program_name,current_file);
return (FALSE);
break;
case tunix:
/* Replace "in-vitro", so out_buffer isn't used */
while (file_remain != 0) {
a = *in_bufpos;
if (a == '\n')
*in_bufpos++ = '\r';
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;
} else in_bufpos++;
}
return (TRUE);
break;
case dos:
/* This I couldn't speed up, so use the existing thing */
convert_gs (infile, outfile);
return (TRUE);
break;
case binary:
return (FALSE);
break;
default:
fprintf(stderr,"%s: Fatal internal error\n",program_name);
exit (EXIT_FAILURE);
break;
} /* switch */
}
/*
* convert_fast_messy() ... convert files to use CR/LF as EOL
* Just check if it's already in DOS format.
*
* Inputs:
* FILE *infile File to read from
* FILE *outfile File to write to
*
* Outputs:
* int FALSE if no conversion took place, TRUE otherwise
*/
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);
switch (infile_type) {
case dos:
if (verbose)
printf("%s: %s is already in MS-DOS format, skipping.\n",
program_name,current_file);
return (FALSE);
break;
case tunix: /* drop through */
case apple:
/* Wasn't able to speed this up, call old routine */
convert_messy (infile, outfile);
return (TRUE);
break;
case binary:
return (FALSE);
break;
default:
fprintf(stderr,"%s: Fatal internal error\n",program_name);
exit (EXIT_FAILURE);
break;
} /* switch */
}
/*
* convert_fast_tunix() ... convert files to use LF as EOL
* Do not care about differing EOL chars in the same file,
* do not allow '\0' bytes, and replace in-vitro if possible.
*
* Inputs:
* FILE *infile File to read from
* FILE *outfile File to write to
*
* Outputs:
* int FALSE if no conversion took place, TRUE otherwise
*/
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);
switch (infile_type) {
case tunix:
if (verbose)
printf("%s: %s is already in Unix format, skipping.\n",
program_name,current_file);
return (FALSE);
break;
case apple:
/* Replace "in-vitro", so out_buffer isn't used */
while (file_remain != 0) {
a = *in_bufpos;
if (a == '\r')
*in_bufpos++ = '\n';
else if (a == '\0'){ /* End of buffer reached */
/* Write changed buffer out */
my_fwrite(in_buffer,outfile,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;
} else in_bufpos++;
}
return (TRUE);
break;
case dos:
/* Couldn't speed it up, so use old routine */
convert_tunix (infile, outfile);
return (TRUE);
break;
case binary:
return (FALSE);
break;
default:
fprintf(stderr,"%s: Fatal internal error\n", program_name);
exit (EXIT_FAILURE);
break;
} /* switch */
}
/*
* get_file_format() ... look at a buffer and find out what the EOL
* character is. If no EOL character is found, print an error message
* and exit.
*
* Inputs:
* unsigned char *buffer Buffer to search through, terminated
* by '\0'.
*
* Output:
* enum file_format tunix, dos, apple, or binary
*/
enum file_format get_file_format (unsigned char *buffer) {
unsigned char c;
enum file_format result = 0;
while ((c = *buffer++) != '\0') {
if (c == '\n') {
result = tunix;
break;
} else if (c == '\r') {
if (*buffer == '\n')
result = dos;
else
result = apple;
break;
}
}
if (result == 0) {
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);
result = binary;
}
return (result);
}
/*
* tryopen() ... try to open a file, exit if unsuccesful
*
* Inputs:
* char *name Name of file to be opened
* char *mode Mode string for fopen() call
*
* Output:
* FILE * File identifier of successful fopen()
*/
FILE *tryopen (char *name, char *mode) {
FILE *tmp;
if ((tmp = fopen(name,mode)) == NULL) {
fprintf(stderr,"%s: Unable to open file %s\n",program_name, name);
exit (EXIT_FAILURE);
} else
return (tmp);
}
/*
* my_fread() ... read data into global buffer and exit if I fail
*
* Inputs:
* FILE *infile File to read from
* int howmuch Number of bytes to read
*
* Output:
* int Number of bytes actually read
*/
int my_fread(FILE *infile, int howmuch) {
int result;
result = fread(in_buffer, 1, howmuch, infile);
if (ferror(infile)) {
fprintf(stderr,"%s: Error while reading data\n",program_name);
exit (EXIT_FAILURE);
}
return (result);
}
/*
* my_fwrite() ... write data from global buffer to file
*
* Inputs:
* unsigned char *buffer Buffer to write out
* FILE *outfile File to write to
* int howmuch Number of bytes to write
*
* Output:
* None
*/
void my_fwrite (unsigned char *buffer, FILE *outfile, int howmuch) {
fwrite(buffer, 1, howmuch, outfile);
if (ferror(outfile)) {
fprintf(stderr,"%s: Error while writing data\n",program_name);
exit (EXIT_FAILURE);
}
return;
}
/*
* cleanup() ... called in case of an exit(). Frees memory I allocated.
*
* Inputs:
* None
*
* Output:
* None
*/
void cleanup (void) {
char **p;
free (program_name);
free (current_file);
free (in_buffer);
free (out_buffer);
free (tempfile);
if (pathList) {
p = pathList;
while(*p) free(*p++);
free (pathList);
}
if (tempfile)
remove (tempfile);
}
/*
* usage() ... print out a usage string gotten from udluse.c
*
* Inputs:
* None
*
* Outputs:
* None
*/
void usage (void) {
extern char use1[]; /* from udluse.c */
#ifdef GNO
extern char use2[];
#endif
fprintf(stderr,"%s",use1);
#ifdef GNO
if(!needsgno())
fprintf(stderr,"%s",use2);
#endif
return;
}
/*
* build_file_list() build the list of files to process
*
* Precondition:
* file is the file name to be added to the pathList
* recurse if non-zero, directories will be recursed
*
* Postcondition:
* pathList will be a NULL-terminated array of strings. Each
* string is a partial pathname (relative to rootdir) of a file
* to convert.
*
* Note: This is a recursive routine that uses up (3 * sizeof(char *))
* bytes of stack with each level of subdirectories.
*/
void build_file_list(char *file, short recurse) {
char *thisdir;
DIR *dir;
struct dirent *entry;
/* 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);
exit(EXIT_FAILURE);
}
#endif
if (stat(file,&tstat)!=0) {
fprintf(stderr,"%s: Couldn't stat %s. File skipped\n",program_name,file);
--recursionDepth;
return;
}
if (recurse && S_ISDIR(tstat.st_mode)) {
char tstr[2];
/*
* It is a directory. recurse through it.
*/
/* save our state */
tstr[0] = dirbrk;
tstr[1] = '\0';
if (*currentDirectory) {
thisdir = strdup(currentDirectory);
} else {
thisdir = malloc(1);
if (thisdir != NULL) *thisdir='\0';
}
if (thisdir == NULL) {
perror("Couldn't duplicate current directory");
exit (EXIT_FAILURE);
}
if (*currentDirectory) strcat(currentDirectory,tstr);
strcat(currentDirectory,file);
if (currentDirectory[strlen(currentDirectory)-1] == dirbrk)
currentDirectory[strlen(currentDirectory)-1] = '\0';
/* recurse */
if ((dir = opendir(file)) == NULL) {
fprintf(stderr,"%s: Couldn't open %s. Directory skipped.\n",
program_name,currentDirectory);
} else {
if (chdir(file) !=0) {
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
while ((entry = readdir(dir))!=NULL) {
/* ignore hidden files */
#ifdef BROKEN_DIRENT_STRUCT
if (*(entry->d_name)!='.') build_file_list((entry->d_name)-2,1);
#else
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);
}
} else {
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 */
add_to_pathList(currentDirectory, file);
}
--recursionDepth;
return;
}
void add_to_pathList(char *thisdir, char *file) {
char **p;
/* expand the pathList if necessary */
if (pathSlotsUsed >= pathSlots) {
pathSlots += PATHLIST_QUANTUM;
#if BROKEN_REALLOC
if ((pathList==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);
}
pathList = p;
}
#else
if ((p = realloc(pathList,(pathSlots+1) * sizeof(char *)))==NULL) {
fprintf(stderr,"%s: Couldn't expand pathList\n",program_name);
exit (EXIT_FAILURE);
} else pathList = p;
#endif
}
/* add in the current directory and filename to the pathList */
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);
exit (EXIT_FAILURE);
}
if (*thisdir) {
sprintf(pathList[pathSlotsUsed],"%s%c%s",thisdir,dirbrk,file);
} else {
strcpy(pathList[pathSlotsUsed],file);
}
pathSlotsUsed++;
pathList[pathSlotsUsed] = NULL;
return;
}
/* Mktemp() construct a unique file name
*
* This routine is slightly different than the Unix standard one,
* thus the capitalization.
*
* Inputs:
* base Template to construct the name upon. It should
* be in the format "nameXXXXXX" where all "X" are replaced
* in such a way that the resulting name is unique. There
* should be at least one, at most 15 "X" in the base name.
* base may contain a full or partial path.
*
* Outputs:
* Mktemp() returns a pointer to a dynamically allocated string
* containing a unique file name.
*
*/
char *Mktemp(const char *base)
{
static char id[16] = "AAAAAAAAAAAAAAA";
char *p1,*p2,*st;
if ((st = malloc(strlen(base) + 1)) == NULL)
{
fprintf(stderr,"%s: memory allocation failure\n", program_name);
exit (EXIT_FAILURE);
}
st = strcpy(st,base);
if (*st == '\0')
{
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;
/* Update ID string to "count" one further */
for(p1 = &id[14];p1 >= id;)
if(*p1 == 'Z')
{
*p1 = 'A';
p1--;
} else {
*p1 += 1;
break;
}
/* Make sure the file name does not already exist */
#ifdef GNO
if (needsgno() == TRUE) {
#endif
if (stat(st,&tstat) == 0)
{
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);
} else if ((fp = fopen(st,"a")) == NULL) {
free(st);
st = Mktemp (base);
} else {
fclose(fp);
}
}
#endif
return st;
}
/* get_path() ... extract path from filename
*
* Inputs:
* name A file name containing a full, partial or no path.
*
* Outputs:
* Pointer to a string in static memory containing the path
* to the given file, or an empty string if "name" contained
* no path. The string can hold MAXPATHLEN characters.
*/
char *get_path (const char *name)
{
int i;
strcpy(filebuffer, name);
for (i = strlen(filebuffer) - 1; i > 0 && filebuffer[i] != dirbrk; i--)
; /* empty loop to find end of path in name */
if (i != 0)
++i;
filebuffer[i] = '\0';
return filebuffer;
}
/* End Of File */

View File

@ -1,99 +0,0 @@
/*
* udl - Convert EOL formats freely between MS-DOS (CR/LF), Unix/Amiga (LF),
* and Apple (CR).
*
* 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 $
*
* Copyright (c) 1993-1995 Soenke Behrens, Devin Reade
*/
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <dirent.h>
#define BUFFERSIZE 0x2000
#define PATHLIST_QUANTUM 20
#define UDL_VERSION "Version 1.14"
#define STACKSIZE 2048
#define BYTES_PER_DEPTH 40
#define BASESIZE 700
#ifndef FALSE
# define FALSE 0
# define TRUE !FALSE
#endif
#ifndef EXIT_FAILURE
# define EXIT_FAILURE 1
# define EXIT_SUCCESS 0
#endif
#ifdef HAS_ATEXIT
# define EXIT(a) exit(a)
#else
# define EXIT(a) { cleanup(); exit(a); }
#endif
enum file_format { tunix = 1, dos, apple, binary };
/* Since udl is so small, I dare to use some globals :) */
extern char *program_name; /* How was udl invoked? */
extern char *current_file; /* Name of current file */
extern char *tempfile; /* Name of temporary file */
extern unsigned char *in_buffer; /* My own buffering scheme instead of */
extern unsigned char *out_buffer; /* setvbuf() */
extern int verbose;
extern char filebuffer[MAXPATHLEN]; /* a scratch buffer for file names */
extern char currentDirectory[MAXPATHLEN];
extern char rootdir[MAXPATHLEN]; /* the initial directory */
extern struct stat tstat; /* temporary variable used to stat files */
extern int pathSlotsUsed; /* number of used and available slots in pathList,*/
extern int pathSlots; /* respectively. Both are initially zero. */
extern char **pathList; /* the list of files to process, given relative */
/* to the initial directory. Initially NULL, */
/* and NULL terminated. */
extern char dirbrk; /* the character used to separate parts of a path name */
extern int recursionDepth; /* levels of subdirectories that we've traversed */
extern int optind; /* part of getopt library */
extern int opterr;
/* Prototypes of functions in common.c */
extern void convert_gs (FILE *infile, FILE *outfile);
extern void convert_messy (FILE *infile, FILE *outfile);
extern void convert_tunix (FILE *infile, FILE *outfile);
extern int convert_fast_gs (FILE *infile, FILE *outfile);
extern int convert_fast_messy (FILE *infile, FILE *outfile);
extern int convert_fast_tunix (FILE *infile, FILE *outfile);
extern enum file_format get_file_format (unsigned char *buffer);
extern FILE *tryopen (char *file, char *mode);
extern int my_fread (FILE *infile, int howmuch);
extern void my_fwrite (unsigned char *buffer, FILE *outfile, int howmuch);
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 int needsgno(void);
/* not strictly necessary, but it cuts down on warnings from gcc */
#if defined(__GNUC__) || defined(_AIX)
extern char *getwd(char *);
#endif
#ifdef __GNUC__
extern char getopt(int, char **, char *);
#endif
/* End Of File */

View File

@ -1,9 +0,0 @@
Name: udl
Version: 1.15
Author: Soenke Behrens, Devin Reade
Contact: sbehrens@contech.demon.co.uk, gdr@myrias.ab.ca
Where: /usr/local/bin
FTP: ftp.cco.caltech.edu, grind.isca.uiowa.edu
Converts text between the CR, LF and CR/LF forms. Also available for Unix
machines, reasonably fast yet secure.

View File

@ -1,36 +0,0 @@
/*
* udl - Convert EOL formats freely between MS-DOS (CR/LF), Unix/Amiga (LF),
* and Apple (CR).
*
* Contains definitions of global variables declared in common.h
*
* $Id: globals.c,v 1.5 1996/01/22 01:01:34 gdr Exp $
*
* Copyright (c) 1993-1995 Soenke Behrens, Devin Reade
*/
#ifdef GNO
#pragma noroot
#endif
#include "common.h"
char *program_name; /* How was udl invoked? */
char *current_file; /* Name of current file */
char *tempfile; /* Name of temporary file */
unsigned char *in_buffer; /* My own buffering scheme instead of */
unsigned char *out_buffer; /* setvbuf() */
int verbose;
char filebuffer[MAXPATHLEN]; /* a scratch buffer for file names */
char currentDirectory[MAXPATHLEN];
char rootdir[MAXPATHLEN]; /* the initial directory */
struct stat tstat; /* temporary variable used to stat files */
int pathSlotsUsed; /* number of used and available slots in pathList,*/
int pathSlots; /* respectively. Both are initially zero. */
char **pathList; /* the list of files to process, given relative */
/* to the initial directory. Initially NULL, */
/* and NULL terminated. */
char dirbrk; /* the character used to separate parts of a path name */
int recursionDepth; /* levels of subdirectories that we've traversed */
/* End Of File */

View File

@ -1,95 +0,0 @@
.\" Copyright (c) 1993-1995 Soenke Behrens, Devin Reade
.\" $Id: udl.1,v 1.8 1996/01/22 01:01:34 gdr Exp $
.\"
.TH UDL 1 "Commands and Applications" "21 January 1996" "Version 1.15"
.SH NAME
udl - convert text files between different architectures
.SH SYNOPSIS
.BR udl
.BR -u | m | g
[
.B -Rvp
]
.I file1
[
.IR file2 " ..."
]
.SH DESCRIPTION
.B udl
converts files between different computer systems by changing the EOL
(End-Of-Line) character.
.PP
On the Apple IIgs,
.B udl
will skip any file that is not of type TXT or SRC.
No notice is given of this unless the
.B -v
flag is used.
Since Unix file systems do not have file types
.BR udl
is limited in the types of checks which it can carry out,
so the user must take care that
it is not invoked on object files or the like. On both platforms, if
.I file
appears to be a binary file (that is, no EOL is
found in the first part of the file) then
.I file
will be skipped.
Again, no notice is given of this unless the
.B -v
flag is used.
.PP
During file conversion
.B udl
creates a temporary file in the same directory as the original file.
The temporary file is close to or exactly the same size as the original
file.
.PP
When running under Byteworks' ORCA shell, the Orca shell wildcards
.BR =
and
.BR ?
are properly expanded in file names.
.SH OPTIONS
.IP \fB\-u\fP
Convert to use LF as EOL (Unix/Amiga).
.IP \fB\-m\fP
Convert to use CR/LF as EOL (MS-DOS).
.IP \fB\-g\fP
Convert to use CR as EOL (Apple).
.IP \fB\-p\fP
Be pedantic, only affects Unix<->Apple conversions, see below.
.IP \fB\-R\fP
Recurse through subdirectories.
.IP \fB\-v\fP
Be verbose, show the file udl is currently working on.
.PP
If you specify the
.B -p
switch,
.B udl
is pedantic while doing the conversion. This means: The input file may
contain bytes with a value of zero (0), and the input file may contain
different EOL characters (ie: MS-DOS and Unix style might be mixed in
one file). For conversions to or from MS-DOS
.B udl
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
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
should not normally be a problem. If the limit is exceeded,
.BR udl
will exit with an error message before any files are changed, and before
the stack actually overflows.
.SH BUGS
Bug reports should be directed to one of the two addresses below.
.SH AUTHOR
Soenke Behrens <sbehrens@contech.demon.co.uk> with contributions by
Devin Reade <gdr@myrias.ab.ca>.
.SH VERSION
This is
.B udl
version 1.15.

View File

@ -1,22 +0,0 @@
#include "Types.Rez"
resource rVersion (0x1, purgeable1, nocrossbank) {
{ 1, 1, 5, /* version 1.1.4 */
release, /* development|alpha|beta|final|release */
0 /* non-final release number */
},
verBritain,
"udl",
"Copyright 1993-1996,\n"
"S" $"9A" "nke Behrens, Devin Reade"
};
resource rComment (0x1) {
"Text File Conversion Program\n"
"Converts files between CR, CR/LF, and LF.\n"
"(Apple, MS-DOS, and Unix)"
};
resource rComment (0x2) {
"Requires ORCA/Shell or GNO/ME"
};

View File

@ -1,417 +0,0 @@
/*
* udl - Convert EOL formats freely between MS-DOS (CR/LF), Unix/Amiga (LF),
* and Apple (CR).
*
* Apple IIgs specific routines.
*
* $Id: udlgs.c,v 1.9 1996/02/04 01:34:29 gdr Exp $
*
* Copyright (c) 1993-1995 Soenke Behrens, Devin Reade
*/
#include <orca.h>
#include <shell.h>
#include <gsos.h>
#include <getopt.h>
#include "common.h"
#define QUITFLAG 0x4000 /* udl is restartable */
#define DIRECTORY 0x0F
/*
* Globals
*/
int theType, theAuxType; /* Hold type of current file */
Next_WildcardGSPB NextWild; /* for handling ORCA/Shell style wildcards */
Init_WildcardGSPB InitWild;
extern pascal void SystemQuitFlags (unsigned);
extern pascal void SystemQuitPath (GSString255Ptr);
extern int needsgno(void);
extern void begin_stack_check(void);
extern int end_stack_check(void);
/*
* Prototypes of functions in this file
*/
extern int CheckGSOSType (char *name);
extern void SetGSOSType (char *name, int type, int auxtype);
extern int right_shell_version (void);
int main(int argc,char *argv[]) {
FILE *infile, *outfile;
int Tunix = FALSE;
int Messy = FALSE;
int GS = FALSE;
int careful = FALSE;
int converted;
int c;
static GSString255 gsp;
static ResultBuf255 rsp;
int R_flag = FALSE;
char **p;
verbose = FALSE;
recursionDepth = 0;
program_name = NULL;
tempfile = NULL;
current_file = NULL;
NextWild.pathName = NULL;
in_buffer = out_buffer = NULL;
pathSlotsUsed = 0;
pathSlots = 0;
pathList = NULL;
*currentDirectory = '\0';
recursionDepth=0;
#ifdef CHECK_STACK
begin_stack_check();
#endif
/* In case of exit(), free the mem I allocated */
atexit (cleanup);
/* Make udl restartable */
SystemQuitFlags (QUITFLAG);
SystemQuitPath (NULL);
if (right_shell_version() == FALSE) {
fprintf(stderr,"%s requires at least ORCA/Shell 2.0"
" or GNO/ME 1.0\n", argv[0]);
exit (EXIT_FAILURE);
}
if ((program_name = strdup (argv[0])) == NULL) {
fprintf(stderr,"%s: memory allocation failure\n",argv[0]);
exit (EXIT_FAILURE);
}
if (argc < 3) {
usage();
exit (EXIT_FAILURE);
}
/* Get and process arguments */
optind = 0;
opterr = 1;
while ((c = getopt (argc, argv, "pvugmR")) != EOF) {
switch (c) {
case 'v':
verbose = TRUE;
break;
case 'p':
careful = TRUE;
break;
case 'u':
if (Tunix == TRUE || Messy == TRUE || GS == TRUE) {
fprintf(stderr, "%s: You may not "
"specify more than one conversion option\n",program_name);
exit (EXIT_FAILURE);
}
Tunix = TRUE;
break;
case 'm':
if (Tunix == TRUE || Messy == TRUE || GS == TRUE) {
fprintf(stderr, "%s: You may not "
"specify more than one conversion option\n",program_name);
exit (EXIT_FAILURE);
}
Messy = TRUE;
break;
case 'g':
if (Tunix == TRUE || Messy == TRUE || GS == TRUE) {
fprintf(stderr, "%s: You may not "
"specify more than one conversion option\n",program_name);
exit (EXIT_FAILURE);
}
GS = TRUE;
break;
case 'R':
R_flag++;
break;
case '?':
usage();
exit (EXIT_FAILURE);
default:
fprintf (stderr, "%s: Internal getopt error\n", program_name);
exit (EXIT_FAILURE);
break;
}
}
if (optind == argc) { /* no files specified */
usage();
exit (EXIT_FAILURE);
}
if (Tunix == FALSE && GS == FALSE && Messy == FALSE) {
fprintf(stderr,"%s: You have to specify a destination "
"format.\n",program_name);
exit (EXIT_FAILURE);
}
if (verbose == TRUE) {
printf ("%s version %s\n",program_name,UDL_VERSION);
}
if ((in_buffer = malloc(BUFFERSIZE+1)) == NULL ||
(out_buffer = malloc(BUFFERSIZE+1)) == NULL) {
fprintf(stderr,"%s: Unable to buffer files\n",program_name);
exit (EXIT_FAILURE);
}
/* Orca Shell: expand wildcards */
if (!needsgno()) {
NextWild.pCount = 1;
InitWild.pCount = 2;
rsp.bufSize = 259;
NextWild.pathName = &rsp;
InitWild.wFile = &gsp;
if (R_flag) {
InitWild.flags = 0x2000 | 0x1000;
} else {
InitWild.flags = 0;
}
dirbrk = ':'; /* enforced by NextWildcardGS */
/* loop through all command line args */
for (; optind < argc; optind++) {
size_t i;
int num_of_files;
i = strlen(argv[optind]);
strncpy (gsp.text,argv[optind],i);
gsp.length = i;
InitWildcardGS (&InitWild);
num_of_files = 0;
/* loop through all matches of wildcards */
for (;;) {
NextWildcardGS (&NextWild);
if (toolerror()) {
fprintf(stderr,"%s: Fatal internal error, "
"exiting\n", program_name);
exit (EXIT_FAILURE);
}
/* No further file found by NextWildcardGS */
if(!rsp.bufString.length)
break;
num_of_files++;
if((current_file = calloc(1,rsp.bufString.length + 1)) == NULL) {
fprintf(stderr,"%s: memory allocation failure\n",program_name);
exit (EXIT_FAILURE);
}
strncpy(current_file, rsp.bufString.text,rsp.bufString.length);
add_to_pathList("",current_file);
free(current_file);
current_file = NULL;
} /* for (;;) */
if (num_of_files == 0)
fprintf(stderr,"%s: No files found that match %s\n",
program_name,argv[optind]);
} /* for (; optind < argc; optind++) */
}
/* gsh or other Gno shell */
else {
/* save the directory we're in */
if (getwd(rootdir)==NULL) {
fprintf(stderr,"%s: Couldn't stat .\n",program_name);
exit (EXIT_FAILURE);
}
for (; optind<argc; optind++) {
/* set the directory separator character. */
dirbrk = (strchr(argv[optind],':')!=NULL) ? ':' : '/';
build_file_list(argv[optind],R_flag);
chdir(rootdir);
*currentDirectory = '\0';
}
}
/* files were all directories and no -R flag given */
if (!pathList) {
if (verbose) printf("%s: no files to process\n",program_name);
exit(EXIT_SUCCESS);
}
p = pathList;
while(*p) {
current_file = *p;
if (CheckGSOSType (current_file) == FALSE) {
p++;
continue;
}
if (verbose == TRUE) {
printf("%s: Working on %s\n",program_name,current_file);
}
infile = tryopen(current_file,"rwb");
tempfile = Mktemp(strcat(get_path(current_file), "udltmpXX"));
outfile = tryopen(tempfile,"wb");
if (careful) {
converted = TRUE; /* always */
if (GS)
convert_gs(infile,outfile);
else if (Tunix)
convert_tunix(infile,outfile);
else
convert_messy(infile,outfile);
} else {
if (GS)
converted = convert_fast_gs(infile,outfile);
else if (Tunix)
converted = convert_fast_tunix(infile,outfile);
else
converted = convert_fast_messy(infile,outfile);
}
if (fclose (infile) == EOF || fclose (outfile) == EOF) {
perror ("closing files");
exit (EXIT_FAILURE);
}
if (converted) { /* Temp file contains converted data */
if (remove (current_file) != 0) {
perror ("removing original file");
exit (EXIT_FAILURE);
}
if (rename (tempfile,current_file) != 0) {
perror ("cannot rename temporary file");
exit (EXIT_FAILURE);
}
} else
remove (tempfile);
free (tempfile); tempfile = NULL;
SetGSOSType (current_file, theType, theAuxType);
p++;
} /* end while */
#ifdef CHECK_STACK
fprintf(stderr,"stack usage: %d bytes\n",end_stack_check());
#endif
return (EXIT_SUCCESS);
}
/*
* CheckGSOSType() ... check if a file is of type TXT or SRC
*
* Inputs:
* char *name Name of file to check
*
* Outputs:
* int Boolean, TRUE if file type is TXT or SRC, FALSE otherwise
*/
int CheckGSOSType(char *name) {
#define TXT 0x04
#define SRC 0xB0
static GSString255 gst;
static FileInfoRecGS fir = {5};
size_t i;
i = strlen (name);
gst.length = i;
strncpy(gst.text,name,i);
fir.pathname = &gst;
GetFileInfoGS(&fir);
if (toolerror()) {
fprintf (stderr,"%s: GS/OS error on %s: 0x%04X\n",
program_name,name,toolerror());
exit (EXIT_FAILURE);
}
if ((fir.fileType != TXT) && (fir.fileType != SRC)) {
if (verbose && (fir.fileType != DIRECTORY))
fprintf(stderr,"%s: %s is not of type TXT or "
"SRC ... skipping\n",program_name,current_file);
return (FALSE);
} else {
theType = fir.fileType;
theAuxType = fir.auxType;
return (TRUE);
}
}
/*
* SetGSOSType() ... set file and auxtype of a file.
*
* Inputs:
* char *name Name of file to be affected
* int type File type it should be set to
* int auxtype Auxiliary type it should be set to
*
* Outputs:
* None
*/
void SetGSOSType (char *name, int type, int auxtype) {
static GSString255 gst;
static FileInfoRecGS fir = {4, NULL, 0xE3};
size_t i;
i = strlen (name);
gst.length = i;
strncpy(gst.text,name,i);
fir.pathname = &gst;
fir.fileType = type;
fir.auxType = auxtype;
SetFileInfoGS(&fir);
if (toolerror()) {
fprintf (stderr,"%s: GS/OS error on %s: 0x%04X\n",
program_name,name,toolerror());
exit (EXIT_FAILURE);
}
}
/*
* right_shell_version() ... check if at least ORCA/Shell 2.0 or
* GNO/ME 1.0 is active.
*
* Inputs:
* None
*
* Output:
* int Boolean, TRUE if shell is satisfactory, FALSE otherwise
*/
int right_shell_version (void) {
static VersionPB vpb;
VERSION(&vpb);
if (vpb.version[0] < '2' || strcmp (shellid(),"BYTEWRKS") != 0)
return FALSE;
else
return TRUE;
}
/* End Of File */

View File

@ -1,214 +0,0 @@
/*
* udl - Convert EOL formats freely between MS-DOS (CR/LF), Unix/Amiga (LF),
* and Apple (CR).
*
* Unix specific routines.
*
* $Id: udlunix.c,v 1.8 1996/01/22 01:01:35 gdr Exp $
*
* Copyright (c) 1993-1995 Soenke Behrens, Devin Reade
*/
#include "common.h"
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;
int careful = FALSE;
int converted;
int c;
int R_flag = FALSE;
verbose = FALSE;
program_name = NULL;
tempfile = NULL;
current_file = NULL;
in_buffer = out_buffer = NULL;
pathSlotsUsed = 0;
pathSlots = 0;
pathList = NULL;
*currentDirectory = '\0';
recursionDepth=0;
/* In case of exit(), free the mem I allocated */
#ifdef HAS_ATEXIT
atexit (cleanup);
#endif
if ((program_name = strdup (argv[0])) == NULL) {
fprintf(stderr,"%s: memory allocation failure\n",argv[0]);
exit (EXIT_FAILURE);
}
if (argc < 3) {
usage();
exit (EXIT_FAILURE);
}
/* Get and process arguments */
opterr = 1;
while ((c = getopt (argc, argv, "pvugmR")) != EOF) {
switch (c) {
case 'v':
verbose = TRUE;
break;
case 'p':
careful = TRUE;
break;
case 'u':
if (Tunix == TRUE || Messy == TRUE || GS == TRUE) {
fprintf(stderr, "%s: You may not "
"specify more than one conversion option\n",program_name);
exit (EXIT_FAILURE);
}
Tunix = TRUE;
break;
case 'm':
if (Tunix == TRUE || Messy == TRUE || GS == TRUE) {
fprintf(stderr, "%s: You may not specify more than one "
"conversion option\n",program_name);
exit (EXIT_FAILURE);
}
Messy = TRUE;
break;
case 'g':
if (Tunix == TRUE || Messy == TRUE || GS == TRUE) {
fprintf(stderr, "%s: You may not specify more than one "
"conversion option\n",program_name);
exit (EXIT_FAILURE);
}
GS = TRUE;
break;
case 'R':
R_flag++;
break;
case '?':
usage();
exit (EXIT_FAILURE);
default:
fprintf (stderr, "%s: Internal getopt error\n", program_name);
exit (EXIT_FAILURE);
break;
}
}
/* no files specified */
if (optind == argc) {
usage();
exit (EXIT_FAILURE);
}
if (Tunix == FALSE && GS == FALSE && Messy == FALSE) {
fprintf(stderr,"%s: You have to specify a destination "
"format.\n",program_name);
exit (EXIT_FAILURE);
}
if (verbose == TRUE) {
printf ("%s %s\n",program_name,UDL_VERSION);
}
/* Now process the files I got */
if ((in_buffer = malloc(BUFFERSIZE+1)) == NULL ||
(out_buffer = malloc(BUFFERSIZE+1)) == NULL) {
fprintf(stderr,"%s: Unable to buffer files\n",program_name);
exit (EXIT_FAILURE);
}
/* save the directory we're in */
if (getwd(rootdir)==NULL) {
fprintf(stderr,"%s: Couldn't stat .\n",program_name);
exit (EXIT_FAILURE);
}
/* set the directory separator character. */
dirbrk = '/';
/* build the list of files to process */
for (; optind<argc; optind++) {
build_file_list(argv[optind],R_flag);
chdir(rootdir);
*currentDirectory = '\0';
}
/* files were all directories and no -R flag given */
if (!pathList) {
if (verbose) printf("%s: no files to process\n",program_name);
exit(EXIT_SUCCESS);
}
for (c=0; pathList[c]; c++) {
if((current_file = strdup(pathList[c])) == NULL) {
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");
tempfile = Mktemp(strcat(get_path(current_file), "udltmpXX"));
outfile = tryopen(tempfile,"wb");
if (careful) {
converted = TRUE; /* always */
if (GS)
convert_gs(infile,outfile);
else if (Tunix)
convert_tunix(infile,outfile);
else
convert_messy(infile,outfile);
} else {
if (GS)
converted = convert_fast_gs(infile,outfile);
else if (Tunix)
converted = convert_fast_tunix(infile,outfile);
else
converted = convert_fast_messy(infile,outfile);
}
if (fclose (infile) == EOF || fclose (outfile) == EOF) {
perror ("closing files");
exit (EXIT_FAILURE);
}
if (converted) { /* Temp file contains converted data */
if (remove (current_file) != 0) {
perror ("removing original file");
exit (EXIT_FAILURE);
}
if (rename (tempfile,current_file) != 0) {
perror ("cannot rename temporary file");
exit (EXIT_FAILURE);
}
} else
remove (tempfile);
free (tempfile); tempfile = NULL;
free(current_file);
current_file = NULL;
} /* for (c=0; pathList[c]; c++) */
return (EXIT_SUCCESS);
}
/* End Of File */

View File

@ -1,32 +0,0 @@
/*
* udl - Convert EOL formats freely between MS-DOS (CR/LF), Unix/Amiga (LF),
* and Apple (CR).
*
* Usage strings.
*
* $Id: udluse.c,v 1.8 1996/01/22 01:01:36 gdr Exp $
*
* Copyright (c) 1993-1995 Soenke Behrens, Devin Reade
*/
#ifdef GNO
#pragma noroot
#endif
char use1 [] =
"udl 1.15 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"
" -g Convert file to use CR as EOL character.\n"
" -m Convert file to use LF/CR as EOL character.\n"
" -R Recurse through subdirectories.\n"
" -p Be pedantic.\n"
" -v Be verbose about it.\n\n"
"udl creates a temporary file in the directory of the original file.\n"
"The original file is overwritten after conversion.\n";
char use2 [] =
"\nFiles may contain ORCA/Shell style wildcards.\n";
/* End Of File */