home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga MA Magazine 1998 #6
/
amigamamagazinepolishissue1998.iso
/
packery
/
xpk_source
/
shell
/
xup.c
< prev
Wrap
C/C++ Source or Header
|
1996-11-12
|
3KB
|
155 lines
#define NAME "xUp"
#define REVISION "1"
/* Routinesheader
Name: xUp
Author: SDI
Distribution: PD
Description: General XPK file-to-file unpacker
1.1 09.10.96 : fixed error with new 3.10 xpkmaster.library (A4 problem)
*/
#include "SDI_defines.h"
#define SDI_TO_ANSI
#include "SDI_ASM_STD_protos.h"
#include <pragma/exec_lib.h>
#include <pragma/dos_lib.h>
#include <pragma/xpkmaster_lib.h>
#ifdef __MAXON__
#define __asm
#define __saveds
#endif
struct Library *XpkBase = 0;
UBYTE errbuf[XPKERRMSGSIZE + 1]; /* +1 to make room for '\n'*/
ULONG __asm _saveds chunkfunc(register __a1 struct XpkProgress *prog)
{
ULONG out = Output();
UBYTE buf[120];
if(prog->xp_Type == XPKPROG_START)
Write(out, "\033[0 p", 5);
if(prog->xp_Type != XPKPROG_END)
sprintf(buf,
"\r%4s: %-8s (%3ld%% done, %2ld%% CF, %6ld cps) %s\033[K",
prog->xp_PackerName, prog->xp_Activity, prog->xp_Done,
prog->xp_CF, prog->xp_Speed, prog->xp_FileName);
else
sprintf(buf,
"\r%4s: %-8s (%3ldK, %2ld%% CF, %6ld cps) %s\033[K\n",
prog->xp_PackerName, prog->xp_Activity, prog->xp_ULen >> 10,
prog->xp_CF, prog->xp_Speed, prog->xp_FileName);
Write(out, buf, strlen(buf));
if(prog->xp_Type == XPKPROG_END)
Write(out, "\033[1 p", 5);
return SetSignal(0, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C;
}
struct Hook chunkhook = {{0}, (ULONG (*) ()) chunkfunc};
UBYTE namebuf[200];
STRPTR tempname(STRPTR name)
{
ULONG i = strlen(name);
CopyMem(name, namebuf, i);
for(name = namebuf + i; name > namebuf; name--)
if(name[-1] == '/' || name[-1] == ':')
break;
sprintf(name, "tmp%lx", &name);
return namebuf;
}
void end(STRPTR text)
{
if(text) Write(Output(), text, strlen(text));
if(XpkBase) CloseLibrary(XpkBase);
exit(text ? RETURN_ERROR : 0);
}
void main(int argc, char **argv)
{
LONG res, i = 1, suffix, len;
STRPTR password = 0;
if(!(XpkBase = OpenLibrary(XPKNAME, 0)))
end("Cannot open " XPKNAME "\n");
if(argc == 1 || !strcmp (argv[1], "?"))
end("Usage: " NAME " [-s][-p password] files\n");
if(i + 1 < argc && !strcmp(argv[i], "-p"))
password = argv[++i], i++;
for(; i < argc; i++)
{
tempname(argv[i]);
len = strlen(argv[i]);
suffix = 0;
if(len > 4 && !stricmp (argv[i] + len - 5, ".xpk"))
{
CopyMem(argv[i], namebuf, strlen(argv[i]));
namebuf[len - 5] = 0;
suffix = 1;
}
{
#ifdef __MAXON__ /* Maxon has no tagcall pragma now */
struct TagItem t[] = { /* and I don't want to use a link */
#else /* library */
if((res = XpkUnpackTags(
#endif
XPK_InName, (ULONG) argv[i],
XPK_FileName, (ULONG) argv[i],
XPK_OutName, (ULONG) namebuf,
XPK_ChunkHook, (ULONG) &chunkhook,
XPK_Password, (ULONG) password,
XPK_GetError, (ULONG) errbuf,
XPK_NoClobber, TRUE,
TAG_DONE
#ifdef __MAXON__
, 0 };
if((res = XpkUnpack(t
#endif
)) && res != XPKERR_NOTPACKED)
{
if(errbuf)
{
ULONG i = strlen(errbuf);
errbuf[i++] = '\n';
errbuf[i] = 0;
}
end(errbuf);
}
}
if(res)
{
Write(Output(), errbuf, strlen(errbuf));
Write(Output(), "\n", 1);
if(!DeleteFile(namebuf))
end("Cannot delete outfile\n");
}
else if(!suffix)
{
if(!DeleteFile(argv[i]))
end("Cannot delete input file\n");
if(!Rename(namebuf, argv[i]))
end("Cannot rename tempfile\n");
}
}
end(0);
}