home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Fred Fish Collection 1.5
/
ffcollection-1-5-1992-11.iso
/
ff_disks
/
300-399
/
ff378.lzh
/
Adapt
/
adapt.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-10-10
|
3KB
|
137 lines
#include <exec/types.h>
#include <libraries/dos.h>
#include <exec/memory.h>
#include <clicodes.h>
void *AllocMem();
ULONG Length(name)
UBYTE *name;
{
struct Lock *lock, *Lock();
ULONG length = 0;
struct FileInfoBlock *info;
if(!(lock = Lock(name, ACCESS_READ))) return(0L);
if(!(info = (struct FileInfoBlock *)
AllocMem((LONG)(sizeof(struct FileInfoBlock)), 0L)))
{
UnLock(lock);
return(0L);
}
Examine(lock, info);
UnLock(lock);
length = info->fib_Size;
FreeMem(info, (LONG)(sizeof(struct FileInfoBlock)));
return(length);
}
main(argc, argv)
int argc;
char *argv[];
{
struct FileHandle *source, *dest, *Open();
UBYTE *from, *qmem, *zmem, *to;
BOOL change = FALSE, strcmp();
int tabsize = 0, atoi();
ULONG qlength, zlength, tab = 0, loop;
LONG bytes, Read(), Write();
if (argc < 3 || argc > 4 || !strcmp(argv[1], "?"))
{
CLITextColor3();
CLIStyleBold();
printf("\nAdapt ");
CLIStyleNormal();
CLITextColor1();
printf("- Version 2.2 by Lars Eggert in March 1990.\n");
printf("Converts the ASCII codes of German ´umlauts´ (äöüÄÖÜß)\n");
printf("in MS-DOS files into the right Amiga codes and can change\n");
printf("TABs into spaces.\n\n");
printf("Usage: ADAPT <source> <destination> [n]\n\n");
printf("Note: <source> and <destination> have to be given, whereas\n");
printf(" [n] is optional. The [n] parameter specifies the number\n");
printf(" of spaces one TAB shall have after converting.\n\n");
exit(0);
}
if(!strcmp(argv[1], argv[2]))
{
puts("Error: Same source and destination file!");
exit(20);
}
if(argc == 4)
{
change = TRUE;
tabsize = atoi(argv[3]);
}
if(!(qlength = Length(argv[1])))
{
puts("Error: Source not found or not enough memory to convert!");
exit(20);
}
if(!(source = Open(argv[1], MODE_OLDFILE)))
{
puts("Fehler: Source not found!");
exit(20);
}
if(!(qmem = AllocMem(qlength, 0L)))
{
puts("Fehler: Not enough memory!");
exit(20);
}
bytes = Read(source, qmem, qlength);
if(bytes < 0)
{
puts("Error: File read error!");
exit(20);
}
Close(source);
for(from = qmem; from <= (UBYTE *)(qmem+qlength); from++) if(*from == 9) ++tab;
zlength = qlength + tab*(tabsize-1);
if(!(to = zmem = AllocMem(zlength, 0L)))
{
puts("Fehler: Nicht genug Speicher!");
FreeMem(qmem, qlength);
exit(20);
}
for(from = qmem; from <= (UBYTE *)(qmem+qlength); from++)
{
switch(*from)
{
case 132: *(to++) = 'ä'; break;
case 148: *(to++) = 'ö'; break;
case 129: *(to++) = 'ü'; break;
case 142: *(to++) = 'Ä'; break;
case 153: *(to++) = 'Ö'; break;
case 154: *(to++) = 'Ü'; break;
case 225: *(to++) = 'ß'; break;
case 9: if(change) for(loop = 0; loop < tabsize; loop++) *(to++) = ' ';
else *to++ = *from;
break;
default: *to++ = *from; break;
}
}
if(!(dest = Open(argv[2], MODE_NEWFILE)))
{
puts("Error: Could not open destination file!");
FreeMem(qmem, qlength);
FreeMem(zmem,zlength);
exit(20);
}
bytes = Write(dest, zmem, zlength);
if(bytes != zlength)
{
puts("Error: Disk write error!");
FreeMem(qmem, qlength);
FreeMem(zmem, zlength);
Close(dest);
exit(20);
}
FreeMem(qmem, qlength);
FreeMem(zmem, zlength);
Close(dest);
exit(0);
}