home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CBM Funet Archive
/
cbm-funet-archive-2003.iso
/
cbm
/
programming
/
msdos
/
xa214f.lzh
/
xa214f
/
misc
/
uncpk.c
< prev
Wrap
C/C++ Source or Header
|
1997-01-03
|
4KB
|
177 lines
/*
XA65 - 6502 CROSS ASSEMBLER AND UTILITY SUITE
UNCPK - HANDLE CPK ARCHIVE FILES
cOPYRIGHT (c) 1997 aNDR{$e9} fACHAT (A.FACHAT@PHYSIK.TU-CHEMNITZ.DE)
tHIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
IT UNDER THE TERMS OF THE gnu gENERAL pUBLIC lICENSE AS PUBLISHED BY
THE fREE sOFTWARE fOUNDATION; EITHER VERSION 2 OF THE lICENSE, OR
(AT YOUR OPTION) ANY LATER VERSION.
tHIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
BUT without any warranty; WITHOUT EVEN THE IMPLIED WARRANTY OF
merchantability OR fitness for a particular purpose. sEE THE
gnu gENERAL pUBLIC lICENSE FOR MORE DETAILS.
yOU SHOULD HAVE RECEIVED A COPY OF THE gnu gENERAL pUBLIC lICENSE
ALONG WITH THIS PROGRAM; IF NOT, WRITE TO THE fREE sOFTWARE
fOUNDATION, iNC., 675 mASS aVE, cAMBRIDGE, ma 02139, usa.
*/
#INCLUDE <STDIO.H>
#INCLUDE <STRING.H>
#DEFINE MAX(A,B)(((A)>(B))?(A):(B))
#DEFINE MIN(A,B)(((A)<(B))?(A):(B))
file *FP;
CHAR NAME[100];
CHAR *S;
VOID USAGE(INT ER) {$7b}
PRINTF("UNCPK: HANDLE C64 ARCHIVES\N"
" UNCPK [X{$7c}L][V] ARCHIVE-NAME\N"
" UNCPK [A{$7c}C][V] ARCHIVE-NAME FILE1 [FILE2 [FILE3 ...]]\N");
EXIT(ER);
{$7d}
INT LIST=0,VERBOSE=0,ADD=0,CREATE=0;
INT MAIN(INT ARGC, CHAR *ARGV[]){$7b}
INT I,C,C2,FILEOK, NC;
SIZE_T N,N2;
file *FP,*FPO=null;
IF(ARGC<=1) {$7b}
USAGE(1);
{$7d}
IF(STRCHR(ARGV[1],(INT)'L')) {$7b}
LIST=1;
{$7d}
IF(STRCHR(ARGV[1],(INT)'V')) {$7b}
VERBOSE=1;
{$7d}
IF(STRCHR(ARGV[1],(INT)'A')) {$7b}
ADD=1;
{$7d}
IF(STRCHR(ARGV[1],(INT)'C')) {$7b}
CREATE=1;
{$7d}
IF(ADD{$7c}{$7c}CREATE) {$7b}
IF (ARGC<=3) {$7b}
USAGE(1);
{$7d}
IF(ADD) {$7b}
FPO=FOPEN(ARGV[2],"AB");
{$7d} ELSE
IF(CREATE) {$7b}
FPO=FOPEN(ARGV[2],"WB");
{$7d}
IF(FPO) {$7b}
IF(!ADD) FPUTC(1,FPO);/* vERSION bYTE */
FOR(I=3;I<ARGC;I++) {$7b}
IF(VERBOSE) PRINTF("%S\N",ARGV[I]);
FP=FOPEN(ARGV[I],"RB");
IF(FP) {$7b}
WHILE((S=STRCHR(ARGV[I],':'))) *S='/';
FPRINTF(FPO,"%S",ARGV[I]);
FPUTC(0,FPO);
C=FGETC(FP);
WHILE(C!=eof) {$7b}
N=1;
WHILE((C2=FGETC(FP))==C) {$7b}
N++;
{$7d}
WHILE(N) {$7b}
IF(N>=4 {$7c}{$7c} C==0XF7) {$7b}
N2=MIN(255,N);
FPRINTF(FPO,"\XF7%C%C",(CHAR)N2,(CHAR)C);
N-=N2;
{$7d} ELSE {$7b}
FPUTC(C,FPO);
N--;
{$7d}
{$7d}
C=C2;
{$7d}
FCLOSE(FP);
FPUTC(0XF7,FPO); FPUTC(0,FPO);
{$7d} ELSE {$7b}
FPRINTF(STDERR,"cOULDN'T OPEN FILE '%S' FOR READING!",ARGV[I]);
{$7d}
{$7d}
FCLOSE(FPO);
{$7d} ELSE {$7b}
FPRINTF(STDERR,"cOULDN'T OPEN FILE '%S' FOR WRITING!",ARGV[1]);
{$7d}
{$7d} ELSE {$7b}
IF (ARGC!=3) {$7b}
USAGE(1);
{$7d}
FP=FOPEN(ARGV[2],"RB");
IF(FP){$7b}
IF(FGETC(FP)==1){$7b}
DO{$7b}
/* READ NAME */
I=0;
WHILE((C=FGETC(FP))){$7b}
IF(C==eof) BREAK;
NAME[I++]=C;
{$7d}
NAME[I++]='\0';
IF(!C){$7b}/* END OF ARCHIVE ? */
WHILE((S=STRCHR(NAME,'/'))) *S=':';
IF(VERBOSE+LIST) PRINTF("%S\N",NAME);
IF(!LIST) {$7b}
FPO=FOPEN(NAME,"WB");
IF(!FPO) {$7b}
FPRINTF(STDERR,"cOULDN'T OPEN OUTPUT FILE %S !\N",NAME);
{$7d}
{$7d}
FILEOK=0;
WHILE((C=FGETC(FP))!=eof){$7b}
/* TEST IF 'COMPRESSED' */
IF(C==0XF7){$7b}
NC=FGETC(FP);
IF(!NC) {$7b}
FILEOK=1;
BREAK;
{$7d}
C=FGETC(FP);
IF(FPO) {$7b}/* EXTRACT */
IF(NC!=eof && C!=eof) {$7b}
NC &= 255;
WHILE(NC--) {$7b}
FPUTC(C,FPO);
{$7d}
{$7d}
{$7d}
{$7d} ELSE {$7b}
IF(FPO) {$7b}
FPUTC(C,FPO);
{$7d}
{$7d}
{$7d}
IF(FPO) {$7b}
FCLOSE(FPO);
FPO=null;
{$7d}
IF(!FILEOK) {$7b}
FPRINTF(STDERR,"uNEXPECTED END OF FILE!\N");
{$7d}
{$7d}
{$7d} WHILE(C!=eof);
{$7d} ELSE
FPRINTF(STDERR,"wRONG vERSION!\N");
FCLOSE(FP);
{$7d} ELSE {$7b}
FPRINTF(STDERR,"fILE %S NOT FOUND!\N",ARGV[1]);
{$7d}
{$7d}
RETURN(0);
{$7d}