[Coco] CRLF Program
John Donaldson
johnadonaldson at sbcglobal.net
Thu Oct 25 13:32:49 EDT 2012
________________________________
I did some search on the Internet for a OS9 program that will take a DOS text
file and convert it to OS9 format.
I found references for these
PCDOS
RSDOS
EATLF
FFIX
Don't know if they are C, Basic09 or what.
Then I cam across this article in a PDF
CRLF.c
A conversion program by James Jones
The following is a highly spedal purpose program
that I use to switch EOL from LF to CR when I've
snarfed Nux! [Unix) text files over to OS-9. NOTE:
we're talking updating the files *in place"'. This is a
Good Thing if that's what you want, because it
m!n;mizes fl.ailing about with deleting and rena.ming
and avoids a (perhaps trivial) amount of fragmentation
of the disk, but it's a Bad Thing if that's "'not'" what
you want, in which case copy first, then crif.
James Jones
Editors Note: In the following code, llnes that are too
long to fit within one of our columns are "wrapped",
and have a backslash ("\"J at the end of the first line
to indicate that the program llne continues on the next
physical line. Most C compllers should accept the
program exactly as shown here. If yours does not,
remove the backslash and append the following line to
the end.
Happy Programming!
/*
* crlf -- a bulk-mode LF->CR translator for REF
* files
*
* Hack to use two paths courtesy Peter Dibble;
* it is best in any case to read/write multiples
* of a sector, but given\ the use of the two
* paths, it is probably even more important
* because of record locking.
*
* -? option added by Scott McGee.
*/
#include <stdio.h>
#include <modes.h>
main (argc, argv)
int argc;
char *argv[];
{
int i;
int inpath, outpath;
/* if no filename is given show help */
if (argc == 1) ShowHelp();
/* if arg starts with '-' show help */
for (i = 1; i < argc; i++)
if (argv[i][0] == '-') ShowHelp();
for (i - 1; i < argc; i++) {
if ((inpath - open(argv[i], S_IREAD)) == -1) || (outpath = open(argv[i],
S_IWRITE)) == -1)
fprintf(stderr, "crlf: can't open %s\n", argv[i]);
else
DoCRLF(inpath, outpath);
if (inpath != -1)
close(inpath);
if (outpath != -1)
close (outpath);
}
}
#define HUNKSIZE (10 * 1024)
char Hunk[HUNKSIZE];
DoCRLF(inpath, outpath)
register int inpath;
register int outpath;
{
register char *HScan;
register int Qty;
while ((Qty = read(inpath, Hunk, HUNKSIZE)) > 0) {
for (HScan = &Hunk[Qty]; --HScan >= Hunk; ) {
if (*HScan == '\l')
*HScan = '\n';
}
write(outpath, Hunk, Qty);
}
}
ShowHelp()
{
fprintf(stderr, "crlf - a bulk-mode LF->CR translator for RBF files\n");
fprintf(stderr, " Usage: crlf <path> [<path>] \n");
fprintf(stderr, " crlf -? - Show this help message\n");
exit(O);
}
More information about the Coco
mailing list