home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Brotikasten
/
BROTCD01.iso
/
amiga
/
unp00.lha
/
UnP00.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-10-01
|
3KB
|
166 lines
/***********************/
/* */
/* UnP00 v1.0 */
/* ⌐ 1994 David Kinder */
/* */
/* Compile with: */
/* DCC -mi -r UnP00.c */
/* */
/***********************/
#include <ctype.h>
#include <string.h>
#include <exec/memory.h>
#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/intuition.h>
struct RDArgs *rdargs;
struct Remember *memkey;
struct List *list;
struct AnchorPath *anchor;
extern struct Library *IntuitionBase;
LONG args[1];
UBYTE ver[] = "$VER:UnP00 1.0 (1.10.94)";
void quit(void);
void error(LONG code);
void storename(void);
void convert(void);
main()
{
LONG match;
if (((struct DosLibrary *)DOSBase)->dl_lib.lib_Version < 36) quit();
if ((list = AllocRemember(&memkey,sizeof(struct List),MEMF_CLEAR)) == NULL)
quit();
NewList(list);
if ((anchor = AllocRemember(&memkey,sizeof(struct AnchorPath)+256,
MEMF_CLEAR|MEMF_PUBLIC)) == NULL) quit();
anchor->ap_BreakBits = SIGBREAKF_CTRL_C;
anchor->ap_Strlen = 255;
if ((rdargs = AllocDosObject(DOS_RDARGS,NULL)) == NULL) quit();
if (ReadArgs("C64FILE/A",args,rdargs) == NULL) error(IoErr());
match = MatchFirst((STRPTR)args[0],anchor);
while (match == 0)
{
storename();
match = MatchNext(anchor);
}
MatchEnd(anchor);
if (match != ERROR_NO_MORE_ENTRIES) error(match);
convert();
quit();
}
void error(LONG code)
{
PrintFault(code,NULL);
quit();
}
void quit()
{
FreeRemember(&memkey,TRUE);
if (rdargs)
{
FreeArgs(rdargs);
FreeDosObject(DOS_RDARGS,rdargs);
}
exit(0);
}
void storename()
{
struct Node *node;
UBYTE *name;
if (node = AllocRemember(&memkey,sizeof(struct Node),MEMF_CLEAR))
{
if (name = AllocRemember(&memkey,strlen(anchor->ap_Buf),MEMF_CLEAR))
{
strcpy(name,anchor->ap_Buf);
node->ln_Name = name;
AddTail(list,node);
}
}
}
void convert()
{
char buffer[17];
struct Node *node;
LONG ch,i,all;
BPTR from,to,lock;
Printf("UnP00 v1.0 ⌐ 1994 David Kinder\n\n");
all = FALSE;
node = list->lh_Head;
while (node->ln_Succ != NULL)
{
from = 0; to = 0;
if (CheckSignal(SIGBREAKF_CTRL_C) != 0) error(ERROR_BREAK);
Printf("Opening \"%s\"... ",node->ln_Name);
Flush(Output());
if ((from = Open(node->ln_Name,MODE_OLDFILE)) == 0)
{
PrintFault(IoErr(),NULL);
goto end;
}
FRead(from,buffer,8,1);
if (strcmp(buffer,"C64File") != 0)
{
Printf("not a C64Neu .P00 data file\n");
goto end;
}
FRead(from,buffer,18,1);
Printf("\n");
for (i = 0; i < 18; i++) *(buffer + i) = tolower(*(buffer + i));
if (all == FALSE)
{
if ((lock = Lock(buffer,ACCESS_READ)) != 0)
{
UnLock(lock);
Printf("Output file \"%s\" exists. Overwrite (y/n/a)? ",buffer);
Flush(Output());
ch = FGetC(Input());
Flush(Input());
switch (ch)
{
case 'y':
break;
case 'a':
all = TRUE;
break;
default:
goto end;
break;
}
}
}
Printf("Writing \"%s\"... ",buffer);
Flush(Output());
if ((to = Open(buffer,MODE_NEWFILE)) == 0)
{
PrintFault(IoErr(),NULL);
goto end;
}
do
{
ch = FGetC(from);
if (ch != -1) FPutC(to,ch);
}
while (ch != -1);
Printf("\n");
end:
if (to) Close(to);
if (from) Close(from);
node = node->ln_Succ;
}
}