ha-0.999p+dfsg/0000755000175000001440000000000011032167165011720 5ustar magusersha-0.999p+dfsg/error.h0000644000175000001440000000510205705175724013232 0ustar magusers/*********************************************************************** This file is part of HA, a general purpose file archiver. Copyright (C) 1995 Harri Hirvola 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. ************************************************************************ HA error hadling ***********************************************************************/ #define ERR_UNKNOWN 1 /* Unknown error */ #define ERR_NOTIMP 2 /* Command not implemented */ #define ERR_ARCOPEN 3 /* Could not open archive */ #define ERR_MEM 4 /* Out of memory */ #define ERR_NOHA 5 /* Not a ha archive */ #define ERR_WRITE 6 /* Write error */ #define ERR_READ 7 /* Read error */ #define ERR_INT 8 /* Got signal... */ #define ERR_NOFILES 9 /* No files found */ #define ERR_REMOVE 10 /* Could not remove */ #define ERR_INVSW 11 /* Invalid switch */ #define ERR_TOONEW 12 /* Version identifier too high */ #define ERR_TOOOLD 13 /* Version identifier too old */ #define ERR_UNKMET 14 /* Unknown compression method */ #define ERR_SEEK 15 /* Lseek error */ #define ERR_OPEN 16 /* Could not open file */ #define ERR_MKDIR 17 /* Could not make directory */ #define ERR_CRC 18 /* CRC error */ #define ERR_WRITENN 19 /* Write error (no name) */ #define ERR_STAT 20 /* Stat failed */ #define ERR_DIROPEN 21 /* Open dir */ #define ERR_CORRUPTED 22 /* Corrupted archive */ #define ERR_SIZE 23 /* Wrong data type size */ #define ERR_HOW 24 /* How to handle */ #define ERR_RDLINK 25 /* Readlink() error */ #define ERR_MKLINK 26 /* Symlinklink() error */ #define ERR_MKFIFO 27 /* Mkfifo() error */ extern int inerror; /* Current error value */ extern int lasterror; /* Last error value */ void error(int fatal, int number, ...); ha-0.999p+dfsg/ha.c0000644000175000001440000004373505705214216012470 0ustar magusers/*********************************************************************** This file is part of HA, a general purpose file archiver. Copyright (C) 1995 Harri Hirvola 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. ************************************************************************ HA main program ***********************************************************************/ #include #include #include #include #include #include #include "error.h" #include "ha.h" #include "archive.h" #include "haio.h" #include "cpy.h" #include "asc.h" #include "hsc.h" /*********************************************************************** Commands */ #define ADD 'a' #define EXTRACT 'e' #define PEXTRACT 'x' #define FRESHEN 'f' #define UPDATE 'u' #define LIST 'l' #define DELETE 'd' #define TEST 't' #define INFO 'h' char *myname; int quiet=0,useattr=0,special=0; static unsigned ilen=0; static int fulllist=0,usepath=1,yes=0,touch=0,recurse=0,savedir=0,move=0; static char *defpat[]={ALLFILES}; static int metqueue[M_UNK+1]={M_UNK}; static int (*addthis)(char*, char*); static void dummy(void) { /* Do nothing */ } struct { char *name; void (*encode)(void); void (*decode)(void); void (*cleanup)(void); } method[]= { {"CPY",cpy,cpy,dummy}, {"ASC",asc_pack,asc_unpack,asc_cleanup}, {"HSC",hsc_pack,hsc_unpack,hsc_cleanup}, {"3"},{"4"},{"5"},{"6"},{"7"},{"8"},{"9"},{"10"},{"11"},{"12"},{"13"}, {"DIR"}, {"SPC"} }; static void banner(void) { fprintf(stderr,BANNER); fflush(stderr); } static unsigned getinfo(unsigned char *buf, unsigned blen) { static unsigned char *idat=infodat; unsigned i; for (i=0;i archive [files]" EXAMPLE "\n" "\n commands :" "\n a[sdqemr012] - Add files d[q] - Delete files" "\n e[aqty] - Extract files f[sdqemr012] - Freshen files" "\n l[f] - List files t[q] - Test files" "\n u[sdqemr012] - Update files x[aqty] -" " eXtract files with pathnames" "\n" "\n switches :" "\n 0,1,2 - try method (0-CPY,1-ASC,2-HSC)" "\n t - Touch files r - Recurse subdirs" "\n f - Full listing y -" " assume Yes on all questions" "\n m - Move files a -" " set system specific file Attributes" "\n e - Exclude pathnames s - find Special files" "\n q - Quiet operation d -" " make Directory entries" "\n" "\nType \"ha h | more\" to get more information about HA." "\n" ); fflush(stderr); if (ex) { cu_do(NULL); exit(ex); } } static int yesno(char *format, char *string) { int rep; if (yes || quiet) return 1; printf(format,string); fflush(stdout); for (rep=0;!rep;) { switch (rep=getchar()) { case 'Y' : case 'y' : case 'N' : case 'n' : case 'A' : case 'a' : break; default : rep=0; break; } } if (rep=='Y'||rep=='y') rep=1; else if (rep=='A'||rep=='a') rep=yes=1; else rep=0; return rep; } static void backstep(int len) { while (--len) putchar(0x08); } static void do_list(void) { U32B tcs,tos; unsigned files; Fheader *hd; arc_reset(); if ((hd=arc_seek())==NULL) error(1,ERR_NOFILES); printf("\n filename original compressed" " rate date time m"); if (fulllist) { printf("\n CRC-32 path"); md_listhdr(); } printf("\n=================================" "=========================================="); tcs=tos=files=0; for(;;) { if (hd->type==0xff) continue; if (fulllist && files) { printf("\n-------------------------" "--------------------------------------------------"); } printf("\n %-15s %-11" F_32B " %-11" F_32B " %3d.%d %% %s %s", hd->name,hd->olen,hd->clen, (hd->olen==0?100:(int)(100*hd->clen/hd->olen)), (hd->olen==0?0:(int)((1000*hd->clen/hd->olen)%10)), md_timestring(hd->time),method[hd->type].name); if (fulllist) { printf("\n %08" FX_32B " %s",hd->crc, *hd->path==0?"(none)":md_tomdpath(hd->path)); md_listdat(); } tcs+=hd->clen; tos+=hd->olen; ++files; if ((hd=arc_seek())==NULL) break; } printf("\n=============================" "=============================================="); printf("\n %-4d %-11" F_32B " %-11" F_32B " %3d.%d %%\n", files,tos,tcs,(tos==0?100:(int)(100*tcs/tos)), (tos==0?0:(int)((1000*tcs/tos)%10))); } static void do_extract(void) { Fheader *hd; char *ofname; unsigned char *sdata; int of,newdir; void *cumark; arc_reset(); if ((hd=arc_seek())==NULL) error(1,ERR_NOFILES); do { if (usepath) { makepath(hd->path); ofname=md_tomdpath(fullpath(hd->path,hd->name)); } else ofname=md_tomdpath(hd->name); switch(hd->type) { case M_SPECIAL: if (!access(ofname,F_OK)) { if (!yesno("\nOverwrite special file %s ? (y/n/a) ",ofname)) break; } if (!quiet) { printf("\nMaking SPC %s",ofname); backstep(strlen(ofname)+8); } if (hd->clen) { if ((sdata=malloc(hd->clen))==NULL) error(1,ERR_MEM,"do_extract()"); if (read(arcfile,sdata,hd->clen)!=hd->clen) error(1,ERR_READ,arcname); } else sdata=NULL; if (!md_mkspecial(ofname,hd->clen,sdata)) { if (sdata!=NULL) free(sdata); break; } if (sdata!=NULL) free(sdata); if (touch) md_setft(ofname,md_systime()); else md_setft(ofname,hd->time); if (!quiet) printf("DONE"); break; case M_DIR: if (!(newdir=access(ofname,F_OK)) && useattr) { if (!yesno("\nRemake directory %s ? (y/n/a) ",ofname)) break; } if (!quiet) { printf("\nMaking DIR %s",ofname); backstep(strlen(ofname)+8); } if (newdir) { if (mkdir(ofname,DEF_DIRATTR)<0) error(0,ERR_MKDIR,ofname); } if (touch) md_setft(ofname,md_systime()); else md_setft(ofname,hd->time); if (useattr) md_setfattrs(ofname); if (!quiet) printf("DONE"); break; default: of=open(ofname,O_WRONLY|O_BINARY|O_CREAT|O_EXCL,DEF_FILEATTR); if (of<0) { if (!yesno("\nOverwrite file %s ? (y/n/a) ",ofname)) continue; if (remove(ofname)<0) { error(0,ERR_REMOVE,ofname); continue; } if ((of=open(ofname,O_WRONLY|O_BINARY|O_CREAT|O_EXCL, DEF_FILEATTR))<0) error(0,ERR_OPEN,ofname); } setinput(arcfile,0,arcname); if (quiet) setoutput(of,CRCCALC,ofname); else setoutput(of,CRCCALC|PROGDISP,ofname); if (!quiet) { printf("\nUnpacking %s %s", method[hd->type].name,ofname); backstep(strlen(ofname)+8); } fflush(stdout); if (hd->olen!=0) { totalsize=hd->olen; cumark=cu_add(CU_FUNC,method[hd->type].cleanup); cu_add(CU_RMFILE|CU_CANRELAX,ofname,of); (*method[hd->type].decode)(); cu_relax(cumark); cu_do(cumark); } else if (!quiet) printf("100 %%"); fflush(stdout); close(of); if (hd->crc!=getcrc()) error(0,ERR_CRC,NULL); if (touch) md_setft(ofname,md_systime()); else md_setft(ofname,hd->time); if (useattr) md_setfattrs(ofname); break; } } while ((hd=arc_seek())!=NULL); if (!quiet) printf("\n"); } static void do_test(void) { Fheader *hd; char *ofname; void *cumark; arc_reset(); if ((hd=arc_seek())==NULL) error(1,ERR_NOFILES); do { ofname=md_tomdpath(fullpath(hd->path,hd->name)); switch(hd->type) { case M_DIR: if (!quiet) printf("\nTesting DIR DONE %s",ofname); break; case M_SPECIAL: if (!quiet) printf("\nTesting SPC DONE %s",ofname); break; default: setinput(arcfile,0,arcname); if (quiet) setoutput(-1,CRCCALC,"none ??"); else setoutput(-1,CRCCALC|PROGDISP,"none ??"); if (!quiet) { printf("\nTesting %s %s",method[hd->type].name,ofname); backstep(strlen(ofname)+8); fflush(stdout); } if (hd->olen!=0) { totalsize=hd->olen; cumark=cu_add(CU_FUNC,method[hd->type].cleanup); (*method[hd->type].decode)(); cu_do(cumark); } else if (!quiet) printf("100 %%"); fflush(stdout); if (hd->crc!=getcrc()) error(0,ERR_CRC,NULL); break; } } while ((hd=arc_seek())!=NULL); if (!quiet) printf("\n"); } static void do_delete(void) { Fheader *hd; arc_reset(); if ((hd=arc_seek())==NULL) error(1,ERR_NOFILES); do { if (!quiet) { printf("\nDeleting %s",md_tomdpath(fullpath(hd->path,hd->name))); fflush(stdout); } arc_delete(); } while ((hd=arc_seek())!=NULL); if (!quiet) printf("\n"); } static int adddir(char *path, char *name) { char *fullname; fullname=md_pconcat(0,path,name); if (!quiet) { printf("\nSaving DIR %s",fullname); backstep(strlen(fullname)+10); fflush(stdout); } arc_newfile(usepath?path:"",name); if (arc_adddir()){ if (!quiet) { printf(" DONE"); fflush(stdout); } if (move) cu_add(CU_RMDIR,fullname); free(fullname); return 1; } else { free(fullname); return 0; } } static int addspecial(char *path, char *name) { char *fullname; fullname=md_pconcat(0,path,name); if (!quiet) { printf("\nSaving SPC %s",fullname); backstep(strlen(fullname)+10); fflush(stdout); } arc_newfile(usepath?path:"",name); if (arc_addspecial(fullname)) { if (!quiet) { printf(" DONE"); fflush(stdout); } if (move) { if (remove(fullname)<0) { error(0,ERR_REMOVE,fullname); } } free(fullname); return 1; } else { free(fullname); return 0; } } static int addfile(char *path, char *name) { char *fullname; int i,best,inf; U32B bestsize; void *cumark; bestsize=totalsize=md_curfilesize(); best=M_CPY; arc_newfile(usepath?path:"",name); fullname=md_pconcat(0,path,name); if ((inf=open(fullname,O_RDONLY|O_BINARY))<0) { error(0,ERR_OPEN,fullname); free(fullname); return 0; } if (!quiet) printf("\n"); setoutput(arcfile,0,arcname); if (quiet) setinput(inf,CRCCALC,fullname); else setinput(inf,CRCCALC|PROGDISP,fullname); if (totalsize) { for (i=0;;) { arc_trynext(); cumark=cu_add(CU_FUNC,method[metqueue[i]].cleanup); if (!quiet) { printf("\rPacking %s %s", method[metqueue[i]].name,fullname); backstep(strlen(fullname)+10); fflush(stdout); } (*method[metqueue[i]].encode)(); cu_do(cumark); if (ocnttime>=md_curfiletime()) return 0; return 1; } static int updatetest(char *path, char *name) { Fheader *hd; char *ptab[1]; ptab[0]=fullpath(md_tohapath(path),name); patterns=ptab; patcnt=1; arc_reset(); if ((hd=arc_seek())!=NULL && hd->time>=md_curfiletime()) return 0; return 1; } static int addindir(char *path, char *pattern) { int found; char *newpath; DIR *dir; struct dirent *ent; void *cumark; found=0; if (*path) dir=opendir(path); else dir=opendir("."); if (dir==NULL) { error(0,ERR_DIROPEN,path); return found; } cumark=cu_getmark(); while ((ent=readdir(dir))!=NULL) { switch(md_filetype(path,md_strcase(ent->d_name))) { case T_DIR: if (savedir && addthis(path,ent->d_name)) found|=adddir(path,ent->d_name); if (!recurse) break; newpath=md_pconcat(1,path,ent->d_name); found|=addindir(newpath,pattern); free(newpath); break; case T_SPECIAL: if (!md_namecmp(pattern,ent->d_name) || !special) break; if (addthis(path,ent->d_name)) found|=addspecial(path,ent->d_name); break; case T_REGULAR: if (!md_namecmp(pattern,ent->d_name)) break; if (addthis(path,ent->d_name)) found|=addfile(path,ent->d_name); break; } } closedir(dir); cu_do(cumark); return found; } static void do_add(void) { int i,found; char *path,*pattern; for (found=i=0;i #include "ha.h" #include "haio.h" #include "error.h" #include "haio.h" #define uppdcrc(_crc,_c) _crc=(crctab[((int)(_crc)^(_c))&0xff]^((_crc)>>8)) #define CRCMASK 0xffffffffUL #define CRCP 0xEDB88320UL int infile,outfile; U32B crc; U32B crctab[256]; unsigned char ib[BLOCKLEN],ob[BLOCKLEN]; int ibl,ibf,obl; U32B icnt,ocnt,totalsize; unsigned char r_crc,w_crc,r_progdisp,w_progdisp; static int write_on,crctabok=0; static char *outname=NULL,*inname=NULL; void (*outspecial)(unsigned char *obuf, unsigned oblen); unsigned (*inspecial)(unsigned char *ibuf, unsigned iblen); static void makecrctab(void) { U16B i,j; U32B tv; for (i=0;i<256;i++) { tv=i; for (j=8;j>0;j--) { if (tv&1) tv=(tv>>1)^CRCP; else tv>>=1; } crctab[i]=tv; } } void setoutput(int fh, int mode, char *name) { outname=name; outspecial=NULL; if (fh>=0) write_on=1; else write_on=0; obl=0; ocnt=0; outfile=fh; w_crc=mode&CRCCALC; if (w_crc) { if (!crctabok) makecrctab(); crc=CRCMASK; } w_progdisp=mode&PROGDISP; } void setinput(int fh, int mode, char *name) { inname=name; inspecial=NULL; ibl=0; icnt=0; infile=fh; r_crc=mode&CRCCALC; if (r_crc) { if (!crctabok) makecrctab(); crc=CRCMASK; } r_progdisp=mode&PROGDISP; } U32B getcrc(void) { return crc^CRCMASK; } void clearcrc(void) { crc=CRCMASK; } void bread(void) { register S16B i; register unsigned char *ptr; if (inspecial!=NULL) { ibl=(*inspecial)(ib,BLOCKLEN); ibf=0; return; } else { ibl=read(infile,ib,BLOCKLEN); if (ibl<0) error(1,ERR_READ,inname); ibf=0; } if (ibl) { icnt+=ibl; if (r_progdisp) { printf("%3d %%\b\b\b\b\b", (int)(icnt*100/(totalsize==0?1:totalsize))); fflush(stdout); } if (r_crc) { for (i=0,ptr=ib;i #include #include #include #include "ha.h" #include "error.h" typedef void (*Voidfunc)(void); struct culist { union { Voidfunc func; struct { char *name; int handle; } fileinfo; } arg; struct culist *prev,*next; unsigned char flags; }; int skipemptypath=0,sloppymatch=1; static struct culist cuhead={{NULL},NULL,NULL,0}; char **patterns; unsigned patcnt; /********************************************************************** Size test */ void testsizes(void) { if (sizeof(U16B)!=2) error(0,ERR_SIZE,"U16B"); if (sizeof(S16B)!=2) error(0,ERR_SIZE,"S16B"); if (sizeof(U32B)!=4) error(0,ERR_SIZE,"U32B"); if (sizeof(S32B)!=4) error(0,ERR_SIZE,"S32B"); } /********************************************************************** Cleanup routines */ void *cu_add(unsigned char flags, ...) { struct culist *ptr,*mark; va_list vaptr; char *string; mark=cuhead.next; ptr=malloc(sizeof(struct culist)); if (ptr==NULL) error(1,ERR_MEM,"add_cleanup()"); ptr->flags=flags; va_start(vaptr,flags); if (flags&CU_FUNC) ptr->arg.func=va_arg(vaptr,Voidfunc); else if ((flags&CU_RMFILE) || (flags&CU_RMDIR)) { string=va_arg(vaptr,char *); if ((ptr->arg.fileinfo.name=malloc(strlen(string)+1))==NULL) error(0,ERR_MEM,"cu_add()"); strcpy(ptr->arg.fileinfo.name,string); if (!(flags&CU_RMDIR)) ptr->arg.fileinfo.handle=va_arg(vaptr,int); } va_end(vaptr); ptr->next=cuhead.next; if (cuhead.next!=NULL) cuhead.next->prev=ptr; ptr->prev=&cuhead; cuhead.next=ptr; return mark; } void *cu_getmark(void) { return cuhead.next; } void cu_relax(void *mark) { struct culist *ptr; for (ptr=cuhead.next;ptr!=NULL && ptr!=mark;ptr=ptr->next) { if (ptr->flags&CU_CANRELAX) ptr->flags|=CU_RELAXED; } } void cu_do(void *mark) { struct culist *ptr; for (ptr=cuhead.next;ptr!=NULL && ptr!=mark;) { if ((ptr->flags&CU_FUNC) && ptr->arg.func!=NULL) { if (!(ptr->flags&CU_RELAXED)) ptr->arg.func(); } else if ((ptr->flags&CU_RMFILE) && ptr->arg.fileinfo.name!=NULL) { close(ptr->arg.fileinfo.handle); if (!(ptr->flags&CU_RELAXED) && remove(ptr->arg.fileinfo.name)<0) { error(0,ERR_REMOVE,ptr->arg.fileinfo.name); } free(ptr->arg.fileinfo.name); } else if ((ptr->flags&CU_RMDIR) && ptr->arg.fileinfo.name!=NULL) { if (!(ptr->flags&CU_RELAXED)) rmdir(ptr->arg.fileinfo.name); free(ptr->arg.fileinfo.name); } cuhead.next=ptr->next; free(ptr); ptr=cuhead.next; } } /********************************************************************** Simple path handling */ char *getname(char *fullpath) { int i,j; static char *name=NULL; if (name!=NULL) free(name),name=NULL; for (i=j=strlen(fullpath);--i>=0;) { if ((unsigned char)fullpath[i]==0xff) { if ((name=malloc(j-i))==NULL) error(1,ERR_MEM,"getname()"); strcpy(name,fullpath+i+1); return name; } } return fullpath; } char *getpath(char *fullpath) { int i; static char *path=NULL; if (path!=NULL) free(path),path=NULL; for(i=strlen(fullpath);--i;) { if ((unsigned char)fullpath[i]==0xff) { if ((path=malloc(i+2))==NULL) error(1,ERR_MEM,"getpath()"); strncpy(path,fullpath,i+1); path[i+1]=0; return path; } } return ""; } char *fullpath(char *path, char *name) { static char *fullpath=NULL; int need_delim; if (fullpath!=NULL) free(fullpath),fullpath=NULL; if (path==NULL || *path==0) return name; if ((unsigned char)path[strlen(path)-1]!=0xff) need_delim=1; else need_delim=0; if ((fullpath=malloc(strlen(path)+strlen(name)+need_delim+1))==NULL) { error(1,ERR_MEM,"fullpath()"); } strcpy(fullpath,path); strcpy(fullpath+strlen(fullpath)+need_delim,name); if (need_delim) fullpath[strlen(fullpath)]=0xff; return fullpath; } void makepath(char *hapath) { char *last,*path; for (last=strchr(hapath,0xff);last!=NULL;last=strchr(last+1,0xff)) { *last=0; if (access((path=md_tomdpath(hapath)),F_OK)) { if (mkdir(path,DEF_DIRATTR)<0) error(0,ERR_MKDIR,path); } *last=0xff; } } /********************************************************************** General filename matching (for paths in ha format !) */ static int matchpattern(char *matchpath, char *matchpat, char *path, char *name) { if (((*matchpath==0 && skipemptypath && sloppymatch) || strcmp(matchpath,path)==0) && md_namecmp(matchpat,name)) return 1; return 0; } int match(char *path, char *name) { int i; char *fullhapath; for (i=0;i #include #include #include #include #define BETA "á" typedef short S16B; typedef unsigned short U16B; typedef long S32B; typedef unsigned long U32B; #define EXAMPLE "\n examples : ha a21r foo /bar/* , ha l foo , ha xy foo" #define ALLFILES "*" #define F_32B "ld" #define FX_32B "lX" #define O_BINARY 0 #define AO_FLAGS O_RDWR #define AO_RDOFLAGS O_RDONLY #define AC_FLAGS O_RDWR|O_CREAT,S_IREAD|S_IWRITE /* #define DEF_FILEATTR S_IREAD|S_IWRITE */ /* #define DEF_DIRATTR DEF_FILEATTR */ #define DEF_FILEATTR 0644 #define DEF_DIRATTR 0755 #define F_OK 0 #define md_curfilesize() filestat.st_size #define md_curfiletime() filestat.st_mtime #define md_strcase extern struct stat filestat; void md_init(void); /* char *md_strcase(char *s); */ char *md_arcname(char *name_req); void md_gethdr(int len, int mode); void md_puthdr(void); int md_newfile(void); int md_mkspecial(char *ofname,unsigned sdlen,unsigned char *sdata); int md_filetype(char *path,char *name); void md_listhdr(void); void md_listdat(void); char *md_timestring(unsigned long t); void md_truncfile(int fh, U32B len); char *md_tohapath(char *mdpath); char *md_tomdpath(char *hapath); char *md_strippath(char *mdfullpath); char *md_stripname(char *mdfullpath); char *md_pconcat(int delim, char *head, char *tail); int md_namecmp(char *pat, char *cmp); void md_setft(char *file,U32B time); void md_setfattrs(char *file); U32B md_systime(void); ha-0.999p+dfsg/grr/README.grr0000644000175000001440000000236205710036624014167 0ustar magusersThe files in this directory are necessary to compile under Linux, at least, with the default flat-directory structure of the ha_src.ha archive (0.999). To compile under Linux (or generic Unix): - rename makefile to makefile.foo and move grr/Makefile to the main directory - rename machine.h to machine.h.dos (not used) and move grr/machine.h to the main directory - possibly edit machine.h if some include files aren't in the locations I used (try compiling as-is first and see what breaks) - do "make ha" This worked fine for me (although it took some tinkering to figure out the correct machine.h for Unix). My Linux "ha" doesn't seem to recurse directories properly, but aside from that it works fine. Here's some magic for use with Darwin's file(1), version 3.14 or later: # HA archiver (Greg Roelofs, newt@uchicago.edu) 0 string HA HA archive data, >2 leshort x %u files, >4 byte&0x0f =0 first is type CPY >4 byte&0x0f =1 first is type ASC >4 byte&0x0f =2 first is type HSC >4 byte&0x0f =14 first is type DIR >4 byte&0x0f =0x0f first is type SPECIAL (There seems to be a bug in file 3.14 with regard to the last two "=" values; neither hex nor decimal works right. I haven't found the problem yet.) Greg Roelofs 95.01.20 ha-0.999p+dfsg/archive.c0000644000175000001440000002303205705175652013517 0ustar magusers/*********************************************************************** This file is part of HA, a general purpose file archiver. Copyright (C) 1995 Harri Hirvola 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. ************************************************************************ HA archive handling ***********************************************************************/ #include #include #include #include "error.h" #include "ha.h" #include "archive.h" #include "haio.h" #define STRING 32 int arcfile=-1; char *arcname=NULL; struct stat arcstat; static unsigned arccnt=0; static int dirty=0,addtries; static U32B nextheader=4,thisheader,arcsize,bestpos,trypos; static Fheader newhdr; static U32B getvalue(int len) { unsigned char buf[4]; U32B val; int i; if (read(arcfile,buf,len)!=len) error(1,ERR_READ,arcname); for (val=i=0;i>=8) buf[i]=(unsigned char) val&0xff; if (write(arcfile,&buf,len)!=len) error(1,ERR_WRITE,arcname); } static char *getstring(void) { char *sptr; int offset; if ((sptr=malloc(STRING))==NULL) error(1,ERR_MEM,"getstring()"); for (offset=0;;offset++) { if (read(arcfile,sptr+offset,1)!=1) error(1,ERR_READ,arcname); if (sptr[offset]==0) break; if ((offset&(STRING-1))==0) { if ((sptr=realloc(sptr,STRING))==NULL) error(1,ERR_MEM,"getstring()"); } } return sptr; } static void putstring(char *string) { int len; len=strlen(string)+1; if (write(arcfile,string,len)!=len) error(1,ERR_WRITE,arcname); } static Fheader *getheader(void) { static Fheader hd={0,0,0,0,0,0,NULL,NULL,0}; if ((hd.ver=getvalue(1))!=0xff) { hd.type=hd.ver&0xf; hd.ver>>=4; if (hd.ver>MYVER) error(1,ERR_TOONEW); if (hd.ver=M_UNK) error(1,ERR_UNKMET,hd.type); } hd.clen=getvalue(4); hd.olen=getvalue(4); hd.crc=getvalue(4); hd.time=getvalue(4); if (hd.path!=NULL) free(hd.path); hd.path=getstring(); if (hd.name!=NULL) free(hd.name); hd.name=getstring(); hd.mdilen=(unsigned)getvalue(1); hd.mylen=hd.mdilen+20+strlen(hd.path)+strlen(hd.name); md_gethdr(hd.mdilen,hd.type); return &hd; } static void putheader(Fheader *hd) { putvalue((hd->ver<<4)|hd->type,1); putvalue(hd->clen,4); putvalue(hd->olen,4); putvalue(hd->crc,4); putvalue(hd->time,4); putstring(hd->path); putstring(hd->name); putvalue(hd->mdilen,1); md_puthdr(); } static void arc_clean(void) { U32B ipos,opos,cpylen; int len; unsigned cnt; Fheader *hd; ipos=opos=4; for (cnt=arccnt;cnt;--cnt) { if (lseek(arcfile,ipos,SEEK_SET)<0) error(1,ERR_SEEK,"arc_clean()"); for (;;) { hd=getheader(); if (hd->ver!=0xff) break; ipos+=hd->clen+hd->mylen; if (lseek(arcfile,ipos,SEEK_SET)<0) error(1,ERR_SEEK,"arc_clean()"); } if (ipos==opos) ipos=opos+=hd->clen+hd->mylen; else { cpylen=hd->clen+hd->mylen; while (cpylen) { if (lseek(arcfile,ipos,SEEK_SET)<0) error(1,ERR_SEEK,"arc_clean()"); len=read(arcfile,ib,BLOCKLEN>cpylen?(unsigned)cpylen:BLOCKLEN); if (len<=0) error(1,ERR_READ,arcname); cpylen-=len; ipos+=len; if (lseek(arcfile,opos,SEEK_SET)<0) error(1,ERR_SEEK,"arc_clean()"); if (write(arcfile,ib,len)!=len) error(1,ERR_WRITE,arcname); opos+=len; } } } md_truncfile(arcfile,opos); } void arc_close(void) { if (arcfile>=0) { if (dirty) arc_clean(); close(arcfile); if (!arccnt) { if (remove(arcname)) error(1,ERR_REMOVE,arcname); } } } static U32B arc_scan(void) { U32B pos; unsigned i; Fheader *hd; pos=4; for (i=0;i=arcsize) { error(0,ERR_CORRUPTED); arccnt=i; return pos; } if (lseek(arcfile,pos,SEEK_SET)<0) error(1,ERR_SEEK,"arc_seek()"); hd=getheader(); pos+=hd->clen+hd->mylen; if (hd->ver==0xff) { dirty=1; --i; } } if (pos!=arcsize) dirty=1; return pos; } void arc_open(char *aname,int mode) { char id[2]; dirty=0; arcname=md_arcname(aname); if ((arcfile=open(arcname,(mode&ARC_RDO)?AO_RDOFLAGS:AO_FLAGS))>=0) { if (fstat(arcfile,&arcstat)!=0) error(1,ERR_STAT,arcname); arcsize=arcstat.st_size; if (read(arcfile,id,2)!=2 || id[0]!='H' || id[1]!='A') { error(1,ERR_NOHA,arcname); } arccnt=(unsigned)getvalue(2); arcsize=arc_scan(); if (!quiet) printf("\nArchive : %s (%d files)\n",arcname,arccnt); } else if ((mode&ARC_NEW) && (arcfile=open(arcname,AC_FLAGS))>=0) { if (fstat(arcfile,&arcstat)!=0) error(1,ERR_STAT,arcname); if (!quiet) printf("\nNew archive : %s\n",arcname); if (write(arcfile,"HA\000",4)!=4) error(1,ERR_WRITE,arcname); arccnt=0; arcsize=4; } else error(1,ERR_ARCOPEN,arcname); cu_add(CU_FUNC,arc_close); } void arc_reset(void) { nextheader=4; } Fheader *arc_seek(void) { static Fheader *hd; for (;;) { if (nextheader>=arcsize) return NULL; if (lseek(arcfile,nextheader,SEEK_SET)<0) error(1,ERR_SEEK,"arc_seek()"); hd=getheader(); thisheader=nextheader; nextheader+=hd->clen+hd->mylen; if (hd->ver==0xff) dirty=1; else if (match(hd->path,hd->name)) return hd; } } void arc_delete(void) { if (lseek(arcfile,thisheader,SEEK_SET)<0) error(1,ERR_SEEK,"arc_delete()"); if (write(arcfile,"\xff",1)!=1) error(1,ERR_WRITE,arcname); if (lseek(arcfile,2,SEEK_SET)<0) error(1,ERR_SEEK,"arc_delete()"); putvalue(--arccnt,2); dirty=1; } void arc_newfile(char *mdpath, char *name) { newhdr.ver=MYVER; newhdr.olen=md_curfilesize(); newhdr.time=md_curfiletime(); newhdr.path=md_tohapath(mdpath); newhdr.name=name; newhdr.mdilen=md_newfile(); newhdr.mylen=newhdr.mdilen+20+strlen(newhdr.path)+strlen(newhdr.name); bestpos=trypos=arcsize+newhdr.mylen; addtries=0; dirty|=2; } void arc_accept(int method) { bestpos=trypos; newhdr.type=method; trypos+=newhdr.clen=ocnt; newhdr.crc=getcrc(); } void arc_trynext(void) { if (lseek(arcfile,trypos,SEEK_SET)<0) error(1,ERR_SEEK,"arc_trynext()"); if (addtries++) dirty=1; } static void delold(void) { U32B pos,oldpos; unsigned i; Fheader *hd; pos=4; for (i=arccnt;i>0;--i) { if (pos>=arcsize) break; if (lseek(arcfile,pos,SEEK_SET)<0) error(1,ERR_SEEK,"delold()"); hd=getheader(); oldpos=pos; pos+=hd->clen+hd->mylen; if (hd->ver==0xff) { dirty=1; ++i; } else { if (!strcmp(md_strcase(hd->path),newhdr.path) && !strcmp(md_strcase(hd->name),newhdr.name)) { if (lseek(arcfile,oldpos,SEEK_SET)<0) error(1,ERR_SEEK,"delold()"); if (write(arcfile,"\xff",1)!=1) error(1,ERR_WRITE,arcname); dirty=1; --arccnt; } } } } int arc_addfile(void) { U32B basepos,len; int cplen; if ((basepos=arcsize+newhdr.mylen)!=bestpos) { if (lseek(arcfile,basepos,SEEK_SET)<0) error(1,ERR_SEEK,"arc_addfile()"); len=newhdr.clen; while (len) { if (lseek(arcfile,bestpos,SEEK_SET)<0) error(1,ERR_SEEK,"arc_addfile()"); cplen=BLOCKLEN>len?(int)len:BLOCKLEN; if (read(arcfile,ib,cplen)!=cplen) error(1,ERR_READ,arcname); len-=cplen; bestpos+=cplen; if (lseek(arcfile,basepos,SEEK_SET)<0) error(1,ERR_SEEK,"arc_addfile()"); if (write(arcfile,ib,cplen)!=cplen) error(1,ERR_WRITE,arcname); basepos+=cplen; } } if (lseek(arcfile,arcsize,SEEK_SET)<0) error(1,ERR_SEEK,"arc_addfile()"); putheader(&newhdr); dirty&=1; delold(); ++arccnt; arcsize+=newhdr.mylen+newhdr.clen; if (lseek(arcfile,2,SEEK_SET)<0) error(1,ERR_SEEK,"arc_addfile()"); putvalue(arccnt,2); return 1; } int arc_adddir(void) { newhdr.type=M_DIR; newhdr.olen=newhdr.clen=0; newhdr.crc=0; if (lseek(arcfile,arcsize,SEEK_SET)<0) error(1,ERR_SEEK,"arc_adddir()"); putheader(&newhdr); dirty&=1; delold(); ++arccnt; arcsize+=newhdr.mylen; if (lseek(arcfile,2,SEEK_SET)<0) error(1,ERR_SEEK,"arc_adddir()"); putvalue(arccnt,2); return 1; } int arc_addspecial(char *fullname) { unsigned char *sdata; newhdr.type=M_SPECIAL; newhdr.olen=newhdr.clen=md_special(fullname, &sdata); newhdr.crc=0; if (lseek(arcfile,arcsize,SEEK_SET)<0) error(1,ERR_SEEK,"arc_addspecial()"); putheader(&newhdr); if (newhdr.clen!=0) { if (lseek(arcfile,arcsize+newhdr.mylen,SEEK_SET)<0) error(1,ERR_SEEK,"arc_addspecial()"); if (write(arcfile,sdata,newhdr.clen)!=newhdr.clen) error(1,ERR_WRITE,arcname); } dirty&=1; delold(); ++arccnt; arcsize+=newhdr.mylen+newhdr.clen; if (lseek(arcfile,2,SEEK_SET)<0) error(1,ERR_SEEK,"arc_addspecial()"); putvalue(arccnt,2); return 1; } ha-0.999p+dfsg/makefile.nix0000644000175000001440000000324605705201722014220 0ustar magusers############################################################################ # This file is part of HA, a general purpose file archiver. # Copyright (C) 1995 Harri Hirvola # # 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. ############################################################################ # Makefile for HA/gcc ############################################################################ MCH = nix CC = gcc CPP = $(CC) -E CFLAGS = -Wall -O2 -c -I../$(MCH) -I../include LDFLAGS = -O2 MDEFINES = "CC=$(CC)" "CPP=$(CPP)" "CFLAGS=$(CFLAGS)" "DEFS=$(DEFS)" SUBDIRS = c $(MCH) include OBJS = c/*.o $(MCH)/*.o ha : subdirs $(CC) $(LDFLAGS) -o ha $(OBJS) subdirs: @for i in $(SUBDIRS); do (cd $$i && echo $$i && $(MAKE) $(MDEFINES)) || exit; done depend dep: @for i in $(SUBDIRS); do (cd $$i && $(MAKE) $(MDEFINES) dep) || exit; done clean: @for i in $(SUBDIRS); do (cd $$i && $(MAKE) clean) || exit; done rm -f .depend ha *.out *~ # # include a dependency file if one exists # ifeq (.depend,$(wildcard .depend)) include .depend endif ha-0.999p+dfsg/COPYING0000644000175000001440000004307605646201730012766 0ustar magusers GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave, Cambridge, MA 02139, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy 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. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. ha-0.999p+dfsg/asc.h0000644000175000001440000000224605705175734012656 0ustar magusers/*********************************************************************** This file is part of HA, a general purpose file archiver. Copyright (C) 1995 Harri Hirvola 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. ************************************************************************ HA ASC method ***********************************************************************/ /* ASC method packing function */ void asc_pack(void); /* ASC method unpacking function */ void asc_unpack(void); /* Cleanup for ASC method */ void asc_cleanup(void); ha-0.999p+dfsg/info.c0000644000175000001440000001475205705303644013034 0ustar magusersunsigned char infodat[]={ 0x0D,0x4E,0xE3,0x1B,0x05,0xFD,0x34,0x62,0x0D,0xFC,0x10,0x09,0x18,0xD5,0xFA,0xF9, 0x01,0x61,0x3D,0x21,0xAE,0x58,0x79,0x67,0x46,0x59,0xE0,0xDF,0x7C,0x07,0x93,0x49, 0x80,0xAB,0x40,0x76,0xFB,0x06,0xB8,0x5D,0xC3,0x03,0xA1,0x2A,0x40,0x8B,0xC2,0x50, 0x05,0x92,0xE8,0xAB,0x33,0xE6,0xB6,0x2B,0xC6,0xDC,0xB4,0xD1,0xA1,0x44,0xC1,0x6E, 0xA4,0x0B,0x76,0x86,0xC8,0x54,0x1B,0xE8,0x7B,0xA9,0xEA,0xE8,0x74,0xC5,0xC0,0xC4, 0x26,0xDF,0x56,0x7A,0x7E,0x01,0xE2,0x52,0xF1,0x9B,0xE6,0xE3,0x53,0xEB,0x28,0x84, 0x22,0x48,0x28,0x0E,0x75,0x75,0xCB,0x58,0xA4,0xB1,0x12,0x5B,0x01,0x3F,0x10,0x78, 0x8E,0x2A,0x00,0x1D,0xF3,0x3A,0x85,0x89,0x4B,0x29,0x3D,0x58,0x2A,0x5F,0x14,0xE5, 0x29,0x9C,0x54,0x43,0x66,0xC1,0xB9,0xFF,0x6A,0x19,0x8F,0x04,0x50,0x24,0x80,0x42, 0x65,0xDB,0x2F,0xDB,0x22,0x62,0xA7,0x60,0xB6,0x00,0xE2,0xF3,0x8B,0x4B,0x5D,0xCE, 0x84,0x34,0x25,0xAC,0x03,0xEE,0x88,0xF2,0x0A,0x13,0xA1,0x98,0x1A,0x45,0x4A,0x47, 0xE5,0x21,0x67,0x3C,0x0D,0x45,0x5D,0x98,0xEE,0xCE,0x4F,0x43,0x80,0x49,0x96,0xD8, 0x6B,0x4E,0x50,0xA1,0x1D,0xA3,0xF0,0xCC,0xF2,0xD4,0xBD,0x28,0x78,0xC0,0xBB,0x7B, 0xDA,0xA0,0x8C,0xE7,0xD2,0x81,0x40,0x4A,0xF5,0x68,0x70,0xB1,0xD8,0x3C,0xBD,0x49, 0x6A,0xBA,0xCA,0xB2,0x40,0x42,0x41,0x3F,0x4F,0xD7,0xA8,0xE0,0x80,0x62,0xDE,0x57, 0xAD,0x54,0x52,0x5C,0x43,0x2D,0x4D,0x02,0xED,0xED,0x27,0x80,0xCD,0x2D,0x6D,0x7C, 0xA4,0xEF,0xE2,0xDD,0xDC,0xA8,0x9C,0x6B,0x8E,0x67,0x71,0x75,0x7F,0x01,0xB7,0x46, 0x7B,0xA6,0xFA,0x6E,0xBD,0xC9,0x04,0xC6,0xC7,0xCB,0xFA,0xD5,0x6E,0xB1,0x98,0xF7, 0xB1,0x44,0x20,0x0E,0x56,0x68,0xA0,0x78,0x93,0x5C,0x13,0x15,0xCD,0xE5,0x04,0xD7, 0xA5,0x64,0x72,0xE2,0x99,0x5B,0x1A,0xD7,0x58,0x69,0xDA,0x0A,0x8B,0x31,0x52,0x9F, 0x36,0xE6,0x46,0xA7,0x18,0x22,0x82,0x9E,0x6C,0x9A,0x24,0x8B,0xDA,0xD2,0x12,0xBF, 0x3B,0xE7,0xE5,0x68,0x85,0x45,0x6E,0x55,0xEB,0x3D,0xF5,0x7E,0xA7,0x5F,0xCF,0x3E, 0x0A,0x37,0xC5,0x3E,0x2E,0x86,0x60,0xB7,0x83,0xB5,0x17,0xCA,0xB3,0x2E,0x9D,0xFB, 0x71,0x8D,0xF4,0xFE,0xA0,0xC6,0xC4,0xAE,0x1B,0xA6,0x8F,0x3B,0x38,0xD9,0x59,0xA9, 0xB8,0x42,0xF1,0xCF,0xA3,0xC0,0x81,0x95,0xE9,0xB0,0x99,0x62,0x0E,0xA7,0x42,0x8B, 0x73,0x86,0x0E,0xE6,0x9D,0xCC,0xE6,0x4F,0x81,0xCC,0xD5,0x08,0xC7,0x61,0x3B,0x39, 0xAE,0xB4,0xDB,0xAA,0xB4,0xC1,0x90,0xBF,0x5F,0x02,0x1A,0x70,0xB1,0xE4,0xB4,0x2E, 0xCA,0x99,0xE0,0xC0,0x0A,0x09,0x81,0x6D,0x4E,0xF3,0xD5,0x25,0x85,0x7F,0xAA,0x8F, 0x5C,0xC3,0x97,0x9E,0x1B,0x18,0x42,0xB6,0x81,0x2B,0x85,0xE2,0x12,0xEB,0x30,0x82, 0xC1,0x1E,0x81,0xD8,0xEF,0x5E,0xFC,0x5D,0xBF,0x8C,0x9B,0x75,0x81,0x8C,0xE9,0xC0, 0xE2,0x87,0x0F,0xFC,0x13,0x23,0x1D,0x59,0x3E,0x2E,0x35,0xC0,0xEF,0x74,0x89,0x9C, 0x89,0x2C,0x0A,0xA8,0x50,0x65,0x5E,0x5D,0xA3,0x84,0x47,0x53,0x8E,0x75,0x04,0x9E, 0x66,0x0F,0xAA,0x91,0x51,0x8F,0xB7,0x96,0x72,0x2A,0xA4,0xE8,0xFD,0xC4,0x60,0x7A, 0xE1,0x0D,0x82,0x7B,0x93,0xA6,0xC7,0x4D,0x73,0x17,0xA4,0xF1,0xD6,0x3B,0x15,0xCD, 0x69,0x70,0x8E,0xBF,0xBF,0x3A,0x97,0x7E,0x03,0x7E,0x9A,0x68,0xC0,0xD0,0xCC,0x6A, 0xCC,0xB7,0x77,0xEC,0x35,0xCE,0xA5,0xF5,0x99,0x36,0xFA,0x54,0x5D,0x89,0x86,0x72, 0x23,0xBB,0xEF,0x12,0x0D,0xF1,0xF4,0x66,0x62,0xF6,0x6B,0xCA,0xD2,0x01,0x0E,0x18, 0xC5,0xAE,0xD7,0xCA,0x58,0xB3,0x77,0xAD,0x57,0x65,0xE3,0xA6,0x45,0x7D,0x22,0xA9, 0xBD,0x75,0x1C,0x07,0x4E,0x39,0x76,0x0F,0x57,0x6A,0xFA,0x0F,0x8C,0x57,0xEE,0xED, 0x84,0x8D,0x70,0x64,0xA5,0x7F,0x78,0xD3,0xB5,0xC3,0x34,0x94,0x12,0x1F,0xD3,0x12, 0x87,0x45,0x1E,0x0C,0xAA,0x3E,0x7D,0x8F,0x14,0xA3,0x5D,0x79,0xA3,0x19,0xDF,0x63, 0x18,0xDB,0x7F,0x69,0xB0,0x32,0xEB,0xD9,0x38,0xCD,0x34,0xF4,0x70,0x8C,0xFE,0xF6, 0xB0,0xBA,0x78,0x51,0x2E,0x57,0xDE,0x75,0x63,0xFB,0xEC,0xB4,0x02,0x8F,0xBC,0x28, 0x0E,0x1F,0x4F,0xCB,0x8D,0x73,0x3E,0x59,0x5A,0x1F,0x11,0x71,0xF9,0x63,0xDB,0x8F, 0x89,0xE2,0x1C,0xA8,0xFC,0x55,0x94,0x4C,0x87,0x2B,0xCA,0xC9,0x44,0xE8,0xC9,0xA7, 0x30,0xCF,0x8B,0x31,0xBB,0x53,0xD3,0x10,0xE8,0xD5,0x87,0xBA,0x53,0x1C,0x10,0x69, 0xE6,0x59,0xEF,0x3B,0x9F,0xFA,0xE0,0xD8,0xDE,0xDF,0xBB,0x9C,0xD8,0x2C,0x45,0x79, 0x35,0x29,0xDD,0x3F,0xC7,0xA5,0xD2,0x24,0xA3,0xDE,0x2C,0x07,0x3B,0x6E,0xC6,0x4E, 0xE6,0xCD,0xE6,0x2C,0xF9,0x81,0xFA,0xC1,0x52,0x3F,0xA3,0xF2,0xD3,0xDA,0xDB,0xCE, 0x7B,0x96,0x27,0xFE,0x39,0x3F,0x2C,0xA2,0x8E,0xBA,0xE2,0xA1,0x6F,0xDD,0x79,0x50, 0x75,0x79,0x56,0x1E,0x8D,0x3E,0x39,0xAB,0x18,0x32,0x41,0xF0,0x9C,0x17,0x71,0x7F, 0x37,0x75,0xA3,0x11,0x57,0x51,0x4D,0x1E,0x69,0x20,0xD6,0xAC,0xEF,0xDC,0xDF,0xB5, 0xF6,0xCB,0x60,0xFF,0xB5,0x45,0x4C,0x60,0x03,0xFA,0x10,0xD2,0xD9,0xA5,0x63,0x22, 0xEC,0x37,0x20,0x4B,0x78,0x49,0x0E,0xDC,0x76,0xFE,0xE6,0xDA,0xF4,0x60,0x13,0x51, 0xB5,0x7B,0x78,0x58,0xA7,0xA5,0x0F,0x63,0xC4,0x5D,0xE6,0x36,0xD2,0x35,0xB2,0x39, 0xC4,0x1C,0x2F,0xD8,0x50,0xFD,0x73,0x93,0xAC,0xC5,0x73,0x68,0x5A,0xEE,0x4D,0x06, 0x77,0x0B,0x10,0x8F,0x5D,0xA8,0xD7,0x56,0xAC,0x6E,0xE1,0x7D,0x46,0x8C,0x33,0xD9, 0x21,0xC8,0xDA,0xDD,0xCA,0x5E,0x29,0x98,0x44,0x28,0x52,0x74,0x51,0x3A,0xBE,0xEC, 0xDC,0x6B,0xB3,0x64,0x25,0x51,0x5E,0x8B,0x5C,0xC0,0x9E,0xFD,0xE4,0xB2,0x4A,0x7E, 0x13,0x45,0x33,0x5C,0xED,0x71,0x5A,0xD9,0xF8,0x27,0xB2,0x35,0xC4,0x3B,0x2B,0x75, 0x60,0xE8,0x21,0xE2,0x3C,0x72,0x56,0x09,0x84,0x61,0x1C,0xF7,0xD2,0x99,0x84,0x04, 0xD0,0x1D,0x67,0xB3,0xCA,0x4E,0xFF,0x0F,0x8D,0xA2,0xBC,0x8C,0xA1,0x44,0x5E,0xFD, 0xAC,0x23,0x2B,0xFC,0x8B,0xB5,0xA7,0x56,0x58,0xE0,0x0B,0x75,0x6C,0xBB,0xDF,0x2B, 0x0D,0xE9,0x3A,0x32,0x8C,0x15,0x07,0x58,0x93,0x2D,0x2C,0xFB,0xEC,0xBE,0xC7,0x89, 0xC6,0xEC,0xA7,0x3E,0x74,0xB3,0x66,0xDA,0xE8,0xF1,0xD8,0x00,0x45,0x14,0x50,0x0F, 0x89,0x03,0x32,0x0E,0x37,0xBD,0xF5,0xAD,0xB0,0x40,0xD8,0x7D,0x89,0xE7,0x3D,0x78, 0x8F,0xC8,0xC7,0x71,0x19,0xFC,0x29,0xA9,0x44,0xC2,0x2D,0x45,0x17,0x0C,0xB1,0x2E, 0x38,0x5B,0x2C,0xF8,0x6B,0x7B,0x59,0xDF,0x48,0x42,0xEC,0x74,0x4D,0xC5,0xD2,0x56, 0xAB,0x68,0x3F,0x52,0x25,0xF0,0x32,0x9E,0x30,0x71,0x23,0xC1,0x4E,0x34,0xDD,0x46, 0x9C,0x92,0xC2,0x8B,0x9C,0x5C,0x3E,0x39,0xB4,0x74,0x11,0xDD,0xF3,0x85,0x78,0x75, 0xAB,0xB5,0xA4,0x20,0xE1,0x10,0x85,0x2B,0x8A,0xD4,0x91,0x7F,0xC6,0x1D,0xEE,0x27, 0x3B,0x6A,0x55,0x1F,0x79,0xB8,0x4F,0xBC,0xC6,0x00,0x44,0x6E,0xA1,0xFC,0xB2,0x78, 0x62,0x08,0x7D,0x27,0x64,0x09,0xD8,0x05,0xEC,0x14,0xC1,0xA0,0x00,0x14,0x1D,0x48, 0xF4,0xD6,0x6C,0xD4,0xD3,0x86,0xBC,0x6F,0x8D,0x67,0x62,0x2C,0x4C,0x67,0xBC,0xEA, 0x68,0x18,0x2D,0x07,0x09,0x8B,0xF9,0x68,0x55,0x8A,0x9A,0xD4,0x6A,0x1D,0x2B,0xEB, 0x78,0x8F,0x2B,0x56,0x51,0x11,0x98,0x20,0xEA,0xD6,0xC2,0x33,0x38,0x6E,0x93,0x73, 0x6E,0x43,0x89,0xFC,0xE8,0x2D,0x65,0xC4,0xC1,0xF4,0xC2,0x05,0x62,0x6A,0xA8,0xB5, 0x52,0x21,0x0F,0x28,0x9A,0xDD,0x5F,0xCD,0x16,0x9E,0x54,0xDC,0xFB,0x91,0xED,0x81, 0x8D,0x14,0x1B,0x47,0xDA,0x8C,0x1D,0x1D,0x64,0xEF,0x2B,0x0A,0xC1,0xA1,0x80,0x9B, 0xA7,0xD1,0x6A,0x17,0x7D,0xC7,0x04,0x6E,0x2D,0x8B,0x01,0x89,0xB6,0x2F,0x09,0xE8, 0x13,0xB9,0x16,0x80 }; unsigned infolen=1284; ha-0.999p+dfsg/info.txt0000644000175000001440000000674305705303614013427 0ustar magusers 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. About HA HA is a small file archiver utility. It's main goal is to offer maximum compression without fancy addons. Commands of MSDOS version General form of command line for HA is : ha [archive [search pattern list]] Command string starts with command character and includes optional switch characters. Available commands are: a[sdqemr012] Add files matching search pattern to archive. e[aqty] Extract files matching search pattern from archive. x[aqty] Extract files matching search pattern from archive using path information stored in archive. l[f] List files currently in archive. d[q] Delete files matching search pattern from archive. If archive does not contain any files after deletion it is removed. f[sdqemr012] Freshen files in archive. All files matching search pattern and newer than version already in archive are updated to archive. u[sdqemr012] Update files to archive. All files matching search pattern that are newer than version already in archive or are not yet in archive are updated to archive. t[q] Test files in archive. Available switches are: 0,1,2 Try compression method #. More than one can be specified. Methods are: 0-CPY Simple copying of files. 1-ASC Default method using sliding window dictionary followed by arithmetic coder. Offers quite good compression on wide variety of file types. 2-HSC Compression method based on finite context model and arithmetic coder. Quite slow for binary data, but offers very good compression especially for longer text files. y Assume answer yes on all questions. t Touch files when extracting. Sets file times to current machine time. r Recurse through subdirectories while searching for files matching search pattern. f Full listing of stored file information. m Move files when archiving. Files are removed from disk after they are successfully written to archive. a Set system specific file attributes when extracting files. s Find special files when archiving. e Do not store pathname information. q Quiet operation. d Make separate entries for directories. Saves information about empty directories, directory attributes etc. in archive. ha-0.999p+dfsg/acoder.bak0000644000175000001440000001247705705673002013651 0ustar magusers/*********************************************************************** This file is part of HA, a general purpose file archiver. Copyright (C) 1995 Harri Hirvola 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. ************************************************************************ HA arithmetic coder ***********************************************************************/ #include #include #include "ha.h" #include "haio.h" #include "acoder.h" static U16B h,l,v; static S16B s; static S16B gpat,ppat; /*********************************************************************** Bit I/O ***********************************************************************/ #define putbit(b) { ppat<<=1; \ if (b) ppat|=1; \ if (ppat&0x100) { \ putbyte(ppat&0xff); \ ppat=1; \ } \ } #define getbit(b) { gpat<<=1; \ if (!(gpat&0xff)) { \ gpat=getbyte(); \ if (gpat&0x100) gpat=0x100; \ else { \ gpat<<=1; \ gpat|=1; \ } \ } \ b|=(gpat&0x100)>>8; \ } /*********************************************************************** Arithmetic encoding ***********************************************************************/ #ifndef __BORLANDC__ void ac_out(U16B low, U16B high, U16B tot) { register U32B r; r=(U32B)(h-l)+1; h=(U16B)(r*high/tot-1)+l; l+=(U16B)(r*low/tot); if (!((h^l)&0x8000)) { putbit(l&0x8000); while(s) { --s; putbit(~l&0x8000); } l<<=1; h<<=1; h|=1; while (!((h^l)&0x8000)) { putbit(l&0x8000); l<<=1; h<<=1; h|=1; } } while ((l&0x4000)&&!(h&0x4000)) { ++s; l<<=1; l&=0x7fff; h<<=1; h|=0x8001; } } #else void ac_out(U16B low, U16B high, U16B tot) { asm { mov ax,h mov bx,l sub ax,bx add ax,1 mov cx,ax jc aco0 mul high jmp aco1 } aco0: asm { mov dx,high } aco1: asm { cmp dx,tot je aco2 div tot sub ax,1 jmp aco3 } aco2: asm { mov ax,0xffff } aco3: asm { add ax,bx mov h,ax mov ax,cx cmp ax,0 je aco4 mul low jmp aco5 } aco4: asm { mov dx,low } aco5: asm { div tot add l,ax } if (!((h^l)&0x8000)) { putbit(l&0x8000); while(s) { --s; putbit(~l&0x8000); } l<<=1; h<<=1; h|=1; while (!((h^l)&0x8000)) { putbit(l&0x8000); l<<=1; h<<=1; h|=1; } } while ((l&0x4000)&&!(h&0x4000)) { ++s; l<<=1; l&=0x7fff; h<<=1; h|=0x8001; } } #endif void ac_init_encode(void) { h=0xffff; l=s=0; ppat=1; } void ac_end_encode(void) { ++s; putbit(l&0x4000); while (s--) { putbit(~l&0x4000); } if (ppat==1) { flush(); return; } while(!(ppat&0x100)) ppat<<=1; putbyte(ppat&0xff); flush(); } /*********************************************************************** Arithmetic decoding ***********************************************************************/ #ifndef __BORLANDC__ void ac_in(U16B low, U16B high, U16B tot) { register U32B r; r=(U32B)(h-l)+1; h=(U16B)(r*high/tot-1)+l; l+=(U16B)(r*low/tot); while (!((h^l)&0x8000)) { l<<=1; h<<=1; h|=1; v<<=1; getbit(v); } while ((l&0x4000)&&!(h&0x4000)) { l<<=1; l&=0x7fff; h<<=1; h|=0x8001; v<<=1; v^=0x8000; getbit(v); } } U16B ac_threshold_val(U16B tot) { register U32B r; r=(U32B)(h-l)+1; return (U16B)((((U32B)(v-l)+1)*tot-1)/r); } #else void ac_in(U16B low, U16B high, U16B tot) { asm { mov ax,h mov bx,l sub ax,bx add ax,1 mov cx,ax jc aci0 mul high jmp aci1 } aci0: asm { mov dx,high } aci1: asm { cmp dx,tot je aci2 div tot sub ax,1 jmp aci3 } aci2: asm { mov ax,0xffff } aci3: asm { add ax,bx mov h,ax mov ax,cx cmp ax,0 je aci4 mul low jmp aci5 } aci4: asm { mov dx,low } aci5: asm { div tot add l,ax } while (!((h^l)&0x8000)) { l<<=1; h<<=1; h|=1; v<<=1; getbit(v); } while ((l&0x4000)&&!(h&0x4000)) { l<<=1; l&=0x7fff; h<<=1; h|=0x8001; v<<=1; v^=0x8000; getbit(v); } } U16B ac_threshold_val(U16B tot) { U16B rv; asm { mov ax,h sub ax,l add ax,1 jc atv1 mov cx,ax mov ax,v sub ax,l inc ax mul [tot] sub ax,1 sbb dx,0 div cx mov rv,ax jmp atv3 } atv1: asm { mov ax,v sub ax,l add ax,1 jc atv2 mul [tot] sub ax,1 sbb dx,0 mov rv,dx jmp atv3 } atv2: asm { mov ax,tot dec ax mov rv,dx } atv3: return rv; } #endif void ac_init_decode(void) { h=0xffff; l=0; gpat=0; v=getbyte()<<8; v|=0xff&getbyte(); } ha-0.999p+dfsg/hsc.h0000644000175000001440000000230605705175712012656 0ustar magusers/*********************************************************************** This file is part of HA, a general purpose file archiver. Copyright (C) 1995 Harri Hirvola 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. ************************************************************************ HA HSC method ***********************************************************************/ /* HSC method packing function */ void hsc_pack(void); /* HSC method unpacking function */ void hsc_unpack(void); /* Cleanup for HSC method */ void hsc_cleanup(void); /* Cleanup for error conditions */ ha-0.999p+dfsg/archive.h0000644000175000001440000000435005705175742013526 0ustar magusers/*********************************************************************** This file is part of HA, a general purpose file archiver. Copyright (C) 1995 Harri Hirvola 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. ************************************************************************ HA archive handling *************************************************************************/ #define MYVER 2 /* Version info in archives */ #define LOWVER 2 /* Lowest supported version */ enum {M_CPY=0,M_ASC,M_HSC,M_UNK,M_DIR=14,M_SPECIAL}; /* Method types */ #define ARC_OLD 0 /* Mode flags for arc_open() */ #define ARC_NEW 1 #define ARC_RDO 2 #define T_DIR 1 /* Types for file type check */ #define T_SPECIAL 2 #define T_SKIP 3 #define T_REGULAR 4 #define MSDOSMDH 1 /* Identifiers for machine */ #define UNIXMDH 2 /* specific header data */ typedef struct { /* Header of file in archive */ unsigned char type; unsigned char ver; U32B clen; U32B olen; U32B time; U32B crc; char *path; char *name; unsigned mdilen; unsigned mylen; } Fheader; extern int arcfile; /* Archive handle */ extern char *arcname; /* Archive name */ extern struct stat arcstat; /* Archive status (when opened) */ void arc_open(char *arcname, int mode); void arc_reset(void); Fheader *arc_seek(void); void arc_delete(void); void arc_newfile(char *mdpath, char *name); int arc_adddir(void); int arc_addspecial(char *fullname); void arc_accept(int method); void arc_trynext(void); int arc_addfile(void); ha-0.999p+dfsg/swdict.h0000644000175000001440000000267405705175706013411 0ustar magusers/*********************************************************************** This file is part of HA, a general purpose file archiver. Copyright (C) 1995 Harri Hirvola 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. ************************************************************************ HA sliding window dictionary ***********************************************************************/ void swd_init(U16B maxl, U16B bufl); /* maxl=max len to be found */ /* bufl=dictionary buffer len */ /* bufl+2*maxl-1<32768 !!! */ void swd_cleanup(void); void swd_accept(void); void swd_findbest(void); void swd_dinit(U16B bufl); void swd_dpair(U16B l, U16B p); void swd_dchar(S16B c); #define MINLEN 3 /* Minimum possible match lenght for this */ /* implementation */ extern U16B swd_bpos,swd_mlf; extern S16B swd_char; ha-0.999p+dfsg/haio.h0000644000175000001440000000324705705175716013032 0ustar magusers/*********************************************************************** This file is part of HA, a general purpose file archiver. Copyright (C) 1995 Harri Hirvola 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. ************************************************************************ HA I/O routines ***********************************************************************/ #define BLOCKLEN 8192 extern unsigned char ib[],ob[]; extern int ibl,ibf,obl; extern U32B icnt,ocnt,totalsize; #define getbyte() (ibl>0?(--ibl,ib[ibf++]):(bread(),(ibl>0?--ibl,ib[ibf++]:-1))) #define putbyte(c) {ob[obl++]=(c);if(obl==BLOCKLEN)bwrite();} #define flush() bwrite() #define CRCCALC 1 /* flag to setinput/setoutput */ #define PROGDISP 2 /* flog to setinput/setoutput */ extern void (*outspecial)(unsigned char *obuf, unsigned oblen); extern unsigned (*inspecial)(unsigned char *ibuf, unsigned iblen); void setoutput(int fh, int mode, char *name); void setinput(int fh, int mode, char *name); U32B getcrc(void); void clearcrc(void); void bread(void); void bwrite(void); ha-0.999p+dfsg/error.c0000644000175000001440000000473705705175636013244 0ustar magusers/*********************************************************************** This file is part of HA, a general purpose file archiver. Copyright (C) 1995 Harri Hirvola 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. ************************************************************************ HA error handling ***********************************************************************/ #include #include #include #include "ha.h" #include "error.h" int inerror=0,lasterror=0; char *error_string[]={ "Error in error handling !!!", "Unknown error", "Command %c not implemented", "Could not open archive %s", "Out of memory in %s", "%s is not a HA archive", "Write error on %s", "Read error on %s", "Got signal %d", "No files found", "Could not remove %s", "Invalid switch %c", "Archive needs newer version of HA", "Archive made with unsupported version", "Unknown compression method %d", "Lseek error in %s", "Could not open file %s", "Could not make directory %s", "CRC error", "Write error", "Could not get file status for %s", "Could not open directory %s", "Archive corrupted !", "Wrong size for %s", "Don't know how to handle %s", "Could not read symlink %s", "Could not link %s to %s", "Could not make fifo %s", }; void error(int fatal, int number, ...) { va_list argptr; fflush(stdout); if (inerror) { fprintf(stderr,"\n%s: ",myname); fprintf(stderr,error_string[0]); fprintf(stderr,"\n"); fflush(stderr); exit(inerror); } inerror=number; fprintf(stderr,"\n%s: ",myname); va_start(argptr,number); vfprintf(stderr,error_string[number],argptr); fprintf(stderr,"\n"); fflush(stderr); if (!fatal) { lasterror=inerror; inerror=0; return; } cu_do(NULL); exit(number); } ha-0.999p+dfsg/machine.h0000644000175000001440000000502605705276154013511 0ustar magusers/*********************************************************************** This file is part of HA, a general purpose file archiver. Copyright (C) 1995 Harri Hirvola 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. ************************************************************************ HA PC/bcc specific include file ***********************************************************************/ #include #include #include #include #include #include #define BETA "á" typedef int S16B; typedef unsigned U16B; typedef long S32B; typedef unsigned long U32B; #define EXAMPLE "\n examples : ha a21r foo \\bar\\*.* , ha l foo , ha xy foo" #define ALLFILES "*.*" #define F_32B "ld" #define FX_32B "lX" #define AO_FLAGS (O_RDWR|O_BINARY) #define AO_RDOFLAGS (O_RDONLY|O_BINARY) #define AC_FLAGS O_RDWR|O_BINARY|O_CREAT,S_IREAD|S_IWRITE #define DEF_FILEATTR S_IREAD|S_IWRITE #define DEF_DIRATTR DEF_FILEATTR #define F_OK 0 #define STDOUT_FILENO fileno(stdout) #define mkdir(a,b) mkdir(a) #define md_curfilesize() filestat.st_size #define md_curfiletime() filestat.st_mtime #define md_special(a,b) 0 /* Not needed in msdos */ extern struct stat filestat; void md_init(void); char *md_strcase(char *s); char *md_arcname(char *name_req); void md_gethdr(int len, int mode); void md_puthdr(void); int md_newfile(void); int md_mkspecial(char *ofname,unsigned sdlen,unsigned char *sdata); int md_filetype(char *path,char *name); void md_listhdr(void); void md_listdat(void); char *md_timestring(unsigned long t); void md_truncfile(int fh, U32B len); char *md_tohapath(char *mdpath); char *md_tomdpath(char *hapath); char *md_strippath(char *mdfullpath); char *md_stripname(char *mdfullpath); char *md_pconcat(int delim, char *head, char *tail); int md_namecmp(char *pat, char *cmp); void md_setft(char *file,U32B time); void md_setfattrs(char *file); U32B md_systime(void); ha-0.999p+dfsg/acoder.c0000644000175000001440000001311105706042060013313 0ustar magusers/*********************************************************************** This file is part of HA, a general purpose file archiver. Copyright (C) 1995 Harri Hirvola 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. ************************************************************************ HA arithmetic coder ***********************************************************************/ /*********************************************************************** This file contains some small changes made by Nico de Vries (AIP-NL) allowing it to be compiled with Borland C++ 3.1. ***********************************************************************/ #include #include #include "ha.h" #include "haio.h" #include "acoder.h" static U16B h,l,v; static S16B s; static S16B gpat,ppat; /*********************************************************************** Bit I/O ***********************************************************************/ #define putbit(b) { ppat<<=1; \ if (b) ppat|=1; \ if (ppat&0x100) { \ putbyte(ppat&0xff); \ ppat=1; \ } \ } #define getbit(b) { gpat<<=1; \ if (!(gpat&0xff)) { \ gpat=getbyte(); \ if (gpat&0x100) gpat=0x100; \ else { \ gpat<<=1; \ gpat|=1; \ } \ } \ b|=(gpat&0x100)>>8; \ } /*********************************************************************** Arithmetic encoding ***********************************************************************/ #ifndef __BORLANDC__ void ac_out(U16B low, U16B high, U16B tot) { register U32B r; r=(U32B)(h-l)+1; h=(U16B)(r*high/tot-1)+l; l+=(U16B)(r*low/tot); if (!((h^l)&0x8000)) { putbit(l&0x8000); while(s) { --s; putbit(~l&0x8000); } l<<=1; h<<=1; h|=1; while (!((h^l)&0x8000)) { putbit(l&0x8000); l<<=1; h<<=1; h|=1; } } while ((l&0x4000)&&!(h&0x4000)) { ++s; l<<=1; l&=0x7fff; h<<=1; h|=0x8001; } } #else void ac_out(U16B low, U16B high, U16B tot) { asm { mov ax,h mov bx,l sub ax,bx add ax,1 mov cx,ax jc aco0 mul high jmp aco1 } aco0: asm { mov dx,high } aco1: asm { cmp dx,tot je aco2 div tot sub ax,1 jmp aco3 } aco2: asm { mov ax,0xffff } aco3: asm { add ax,bx mov h,ax mov ax,cx cmp ax,0 je aco4 mul low jmp aco5 } aco4: asm { mov dx,low } aco5: asm { div tot add l,ax } if (!((h^l)&0x8000)) { putbit(l&0x8000); while(s) { --s; putbit(~l&0x8000); } l<<=1; h<<=1; h|=1; while (!((h^l)&0x8000)) { putbit(l&0x8000); l<<=1; h<<=1; h|=1; } } while ((l&0x4000)&&!(h&0x4000)) { ++s; l<<=1; l&=0x7fff; h<<=1; h|=0x8001; } } #endif void ac_init_encode(void) { h=0xffff; l=s=0; ppat=1; } void ac_end_encode(void) { ++s; putbit(l&0x4000); while (s--) { putbit(~l&0x4000); } if (ppat==1) { flush(); return; } while(!(ppat&0x100)) ppat<<=1; putbyte(ppat&0xff); flush(); } /*********************************************************************** Arithmetic decoding ***********************************************************************/ #ifndef __BORLANDC__ void ac_in(U16B low, U16B high, U16B tot) { register U32B r; r=(U32B)(h-l)+1; h=(U16B)(r*high/tot-1)+l; l+=(U16B)(r*low/tot); while (!((h^l)&0x8000)) { l<<=1; h<<=1; h|=1; v<<=1; getbit(v); } while ((l&0x4000)&&!(h&0x4000)) { l<<=1; l&=0x7fff; h<<=1; h|=0x8001; v<<=1; v^=0x8000; getbit(v); } } U16B ac_threshold_val(U16B tot) { register U32B r; r=(U32B)(h-l)+1; return (U16B)((((U32B)(v-l)+1)*tot-1)/r); } #else void ac_in(U16B low, U16B high, U16B tot) { asm { mov ax,h mov bx,l sub ax,bx add ax,1 mov cx,ax jc aci0 mul high jmp aci1 } aci0: asm { mov dx,high } aci1: asm { cmp dx,tot je aci2 div tot sub ax,1 jmp aci3 } aci2: asm { mov ax,0xffff } aci3: asm { add ax,bx mov h,ax mov ax,cx cmp ax,0 je aci4 mul low jmp aci5 } aci4: asm { mov dx,low } aci5: asm { div tot add l,ax } while (!((h^l)&0x8000)) { l<<=1; h<<=1; h|=1; v<<=1; getbit(v); } while ((l&0x4000)&&!(h&0x4000)) { l<<=1; l&=0x7fff; h<<=1; h|=0x8001; v<<=1; v^=0x8000; getbit(v); } } U16B ac_threshold_val(U16B tot) { U16B rv; asm { mov ax,h sub ax,l add ax,1 jc atv1 mov cx,ax mov ax,v sub ax,l inc ax mul [tot] sub ax,1 sbb dx,0 div cx mov rv,ax jmp atv3 } atv1: asm { mov ax,v sub ax,l add ax,1 jc atv2 mul [tot] sub ax,1 sbb dx,0 mov rv,dx jmp atv3 } atv2: asm { mov ax,tot dec ax mov rv,dx } atv3: return rv; } #endif void ac_init_decode(void) { h=0xffff; l=0; gpat=0; v=getbyte()<<8; v|=0xff&getbyte(); } ha-0.999p+dfsg/md_funcs.txt0000644000175000001440000000475105705034622014267 0ustar magusersHA MACHINE SPECIFIC FUNCTIONS (machine.c/machine.h) void md_init(void) Set up machine specific signal handling etc. char *md_strcase(char *s) Set case of string to internal format and return pointer to string. char *md_arcname(char *name_req) Construct archive name from requested name name_req and return pointer to it. void md_gethdr(int len) Read len bytes of machine specific header information from arcfile. void md_puthdr(void) Write machine specific header information to arcfile. int md_filetype(char *path,char *name) Return file type (T_SKIP, T_DIR, T_REGULAR or T_SPECIAL) for specified file and make it current file. This function is responsible of skiping over archive file when packing. int md_newfile(void) Setup machine specific header information for curren file and return length of header. int md_special(unsigned char **sdata) Point sdata to any data to be saved for special file (if any), and return lenght of the data. U32B md_curfilesize(void) Return file size for current file. U32B md_curfiletime(void) Returns file time for current file int md_mkspecial(char *ofname,unsigned sdlen,unsigned char *sdata) Make special file ofname using current machine specific header and sdlen bytes of information in sdata. Return zero on failure nozero on success. void md_setft(char *file,U32B time) Set filetime for file to time. void md_setfattrs(char *file) Set attributes (from machine specific heador) of file if useattr is nonzero. U32B md_systime() get system time. void md_listhdr(void) print feader for file attributes to stdout. void md_listdat(void) print attribute information from machine specific header. char *md_timestring(unsigned long t) Return pointer to string representin "unix time" t. void md_truncfile(int fh, U32B len) Truncate file pointed by handle fh to length len. char *md_tohapath(char *mdpath) Construct internal representation for path mdpath. char *md_tomdpath(char *hapath) Construct machine representation for path hapath. char *md_strippath(char *mdfullpath) Return path part of mdfullpath. char *md_stripname(char *mdfullpath) Return name part of mdfullpath. char *md_pconcat(int delim, char *head, char *tail) Construct path from head, tail. This function is supposed to malloc space for path. other parts of HA call free with returned pointer ! int md_namecmp(char *pat, char *cmp) Return nonzero if pattern pat matches filename cmp using wildcards in machine specific manner. ha-0.999p+dfsg/asc.c0000644000175000001440000002347105705175646012656 0ustar magusers/*********************************************************************** This file is part of HA, a general purpose file archiver. Copyright (C) 1995 Harri Hirvola 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. ************************************************************************ HA ASC method ***********************************************************************/ #include #include #include #include "ha.h" #include "haio.h" #include "asc.h" #include "swdict.h" #include "acoder.h" #include "error.h" #define POSCODES 31200 #define SLCODES 16 #define LLCODES 48 #define LLLEN 16 #define LLBITS 4 #define LLMASK (LLLEN-1) #define LENCODES (SLCODES+LLCODES*LLLEN) #define LTCODES (SLCODES+LLCODES) #define CTCODES 256 #define PTCODES 16 #define LTSTEP 8 #define MAXLT (750*LTSTEP) #define CTSTEP 1 #define MAXCT (1000*CTSTEP) #define PTSTEP 24 #define MAXPT (250*PTSTEP) #define TTSTEP 40 #define MAXTT (150*TTSTEP) #define TTORD 4 #define TTOMASK (TTORD-1); #define LCUTOFF (3*LTSTEP) #define CCUTOFF (3*CTSTEP) #define CPLEN 8 #define LPLEN 4 #define MINLENLIM 4096 static U16B ltab[2*LTCODES]; static U16B eltab[2*LTCODES]; static U16B ptab[2*PTCODES]; static U16B ctab[2*CTCODES]; static U16B ectab[2*CTCODES]; static U16B ttab[TTORD][2]; static U16B ccnt,pmax,npt; static U16B ces; static U16B les; static U16B ttcon; void asc_cleanup(void) { swd_cleanup(); } static void tabinit(U16B t[], U16B tl, U16B ival) { register U16B i,j; for (i=tl;i<2*tl;++i) t[i]=ival; for (i=tl-1,j=(tl<<1)-2;i;--i,j-=2) { t[i]=t[j]+t[j+1]; } } static void tscale(U16B t[], U16B tl) { register U16B i,j; for (i=(tl<<1)-1;i>=tl;--i) { if (t[i]>1) t[i]>>=1; } for (i=tl-1,j=(tl<<1)-2;i;--i,j-=2) { t[i]=t[j]+t[j+1]; } } static void tupd(U16B t[], U16B tl, U16B maxt, U16B step, U16B p) { register S16B i; for (i=p+tl;i;i>>=1) t[i]+=step; if (t[1]>=maxt) tscale(t,tl); } static void tzero(U16B t[], U16B tl, U16B p) { register S16B i,step; for (i=p+tl,step=t[i];i;i>>=1) t[i]-=step; } static void model_init(void) { register S16B i; ces=CTSTEP; les=LTSTEP; ccnt=0; ttcon=0; npt=pmax=1; for (i=0;i>=1; if (ttab[con][0]==0) ttab[con][0]=1; ttab[con][1]>>=1; if (ttab[con][1]==0) ttab[con][1]=1; } static void codepair(S16B l, S16B p) { register U16B i,j,lt,k,cf,tot; i=ttab[ttcon][0]+ttab[ttcon][1]; ac_out(ttab[ttcon][0],i,i+1); ttab[ttcon][1]+=TTSTEP; if (i>=MAXTT) ttscale(ttcon); ttcon=((ttcon<<1)|1)&TTOMASK; while (ccnt>pmax) { tupd(ptab,PTCODES,MAXPT,PTSTEP,npt++); pmax<<=1; } for (i=p,j=0;i;++j,i>>=1); cf=ptab[PTCODES+j]; tot=ptab[1]; for (lt=0,i=PTCODES+j;i;i>>=1) { if (i&1) lt+=ptab[i-1]; ptab[i]+=PTSTEP; } if (ptab[1]>=MAXPT) tscale(ptab,PTCODES); ac_out(lt,lt+cf,tot); if (p>1) { for (i=0x8000U;!(p&i);i>>=1); j=p&~i; if (i!=(pmax>>1)) ac_out(j,j+1,i); else ac_out(j,j+1,ccnt-(pmax>>1)); } i=l-MINLEN; if (i==LENCODES-1) i=SLCODES-1,j=0xffff; else if (i>LLBITS)+SLCODES; } if ((cf=ltab[LTCODES+i])==0) { ac_out(ltab[1],ltab[1]+les,ltab[1]+les); for (lt=0,k=LTCODES+i;k;k>>=1) { if (k&1) lt+=eltab[k-1]; ltab[k]+=LTSTEP; } if (ltab[1]>=MAXLT) tscale(ltab,LTCODES); ac_out(lt,lt+eltab[LTCODES+i],eltab[1]); tzero(eltab,LTCODES,i); if (eltab[1]!=0) les+=LTSTEP; else les=0; for (k=i<=LPLEN?0:i-LPLEN; k<(i+LPLEN>=LTCODES-1?LTCODES-1:i+LPLEN);++k) { if (eltab[LTCODES+k]) tupd(eltab,LTCODES,MAXLT,1,k); } } else { tot=ltab[1]+les; for (lt=0,k=LTCODES+i;k;k>>=1) { if (k&1) lt+=ltab[k-1]; ltab[k]+=LTSTEP; } if (ltab[1]>=MAXLT) tscale(ltab,LTCODES); ac_out(lt,lt+cf,tot); } if (ltab[LTCODES+i]==LCUTOFF) les-=LTSTEPPOSCODES) ccnt=POSCODES; } } static void codechar(S16B c) { register U16B i,lt,tot,cf; i=ttab[ttcon][0]+ttab[ttcon][1]; ac_out(0,ttab[ttcon][0],i+1); ttab[ttcon][0]+=TTSTEP; if (i>=MAXTT) ttscale(ttcon); ttcon=(ttcon<<1)&TTOMASK; if ((cf=ctab[CTCODES+c])==0) { ac_out(ctab[1],ctab[1]+ces,ctab[1]+ces); for (lt=0,i=CTCODES+c;i;i>>=1) { if (i&1) lt+=ectab[i-1]; ctab[i]+=CTSTEP; } if (ctab[1]>=MAXCT) tscale(ctab,CTCODES); ac_out(lt,lt+ectab[CTCODES+c],ectab[1]); tzero(ectab,CTCODES,c); if (ectab[1]!=0) ces+=CTSTEP; else ces=0; for (i=c<=CPLEN?0:c-CPLEN; i<(c+CPLEN>=CTCODES-1?CTCODES-1:c+CPLEN);++i) { if (ectab[CTCODES+i]) tupd(ectab,CTCODES,MAXCT,1,i); } } else { tot=ctab[1]+ces; for (lt=0,i=CTCODES+c;i;i>>=1) { if (i&1) lt+=ctab[i-1]; ctab[i]+=CTSTEP; } if (ctab[1]>=MAXCT) tscale(ctab,CTCODES); ac_out(lt,lt+cf,tot); } if (ctab[CTCODES+c]==CCUTOFF) ces-=CTSTEP=0;) { if (swd_mlf>MINLEN || (swd_mlf==MINLEN && swd_bposomlf) codechar(oc); else { swd_accept(); codepair(omlf,obpos); swd_findbest(); } } else { swd_mlf=MINLEN-1; codechar(swd_char); swd_findbest(); } } ac_out(ttab[ttcon][0]+ttab[ttcon][1], ttab[ttcon][0]+ttab[ttcon][1]+1,ttab[ttcon][0]+ttab[ttcon][1]+1); ac_end_encode(); asc_cleanup(); } void asc_unpack(void) { register U16B l,p,tv,i,lt; swd_dinit(POSCODES); unpack_init(); for (;;) { tv=ac_threshold_val(ttab[ttcon][0]+ttab[ttcon][1]+1); i=ttab[ttcon][0]+ttab[ttcon][1]; if (ttab[ttcon][0]>tv) { ac_in(0,ttab[ttcon][0],i+1); ttab[ttcon][0]+=TTSTEP; if (i>=MAXTT) ttscale(ttcon); ttcon=(ttcon<<1)&TTOMASK; tv=ac_threshold_val(ctab[1]+ces); if (tv>=ctab[1]) { ac_in(ctab[1],ctab[1]+ces,ctab[1]+ces); tv=ac_threshold_val(ectab[1]); for (l=2,lt=0;;) { if (lt+ectab[l]<=tv) { lt+=ectab[l]; ++l; } if (l>=CTCODES) { l-=CTCODES; break; } l<<=1; } ac_in(lt,lt+ectab[CTCODES+l],ectab[1]); tzero(ectab,CTCODES,l); if (ectab[1]!=0) ces+=CTSTEP; else ces=0; for (i=l=CTCODES-1?CTCODES-1:l+CPLEN);++i) { if (ectab[CTCODES+i]) tupd(ectab,CTCODES,MAXCT,1,i); } } else { for (l=2,lt=0;;) { if (lt+ctab[l]<=tv) { lt+=ctab[l]; l++; } if (l>=CTCODES) { l-=CTCODES; break; } l<<=1; } ac_in(lt,lt+ctab[CTCODES+l],ctab[1]+ces); } tupd(ctab,CTCODES,MAXCT,CTSTEP,l); if (ctab[CTCODES+l]==CCUTOFF) ces-=CTSTEPtv) { ac_in(ttab[ttcon][0],i,i+1); ttab[ttcon][1]+=TTSTEP; if (i>=MAXTT) ttscale(ttcon); ttcon=((ttcon<<1)|1)&TTOMASK; while (ccnt>pmax) { tupd(ptab,PTCODES,MAXPT,PTSTEP,npt++); pmax<<=1; } tv=ac_threshold_val(ptab[1]); for (p=2,lt=0;;) { if (lt+ptab[p]<=tv) { lt+=ptab[p]; p++; } if (p>=PTCODES) { p-=PTCODES; break; } p<<=1; } ac_in(lt,lt+ptab[PTCODES+p],ptab[1]); tupd(ptab,PTCODES,MAXPT,PTSTEP,p); if (p>1) { for (i=1;p;i<<=1,--p); i>>=1; if (i==(pmax>>1)) l=ccnt-(pmax>>1); else l=i; p=ac_threshold_val(l); ac_in(p,p+1,l); p+=i; } tv=ac_threshold_val(ltab[1]+les); if (tv>=ltab[1]) { ac_in(ltab[1],ltab[1]+les,ltab[1]+les); tv=ac_threshold_val(eltab[1]); for (l=2,lt=0;;) { if (lt+eltab[l]<=tv) { lt+=eltab[l]; ++l; } if (l>=LTCODES) { l-=LTCODES; break; } l<<=1; } ac_in(lt,lt+eltab[LTCODES+l],eltab[1]); tzero(eltab,LTCODES,l); if (eltab[1]!=0) les+=LTSTEP; else les=0; for (i=l=LTCODES-1?LTCODES-1:l+LPLEN);++i) { if (eltab[LTCODES+i]) tupd(eltab,LTCODES,MAXLT,1,i); } } else { for (l=2,lt=0;;) { if (lt+ltab[l]<=tv) { lt+=ltab[l]; ++l; } if (l>=LTCODES) { l-=LTCODES; break; } l<<=1; } ac_in(lt,lt+ltab[LTCODES+l],ltab[1]+les); } tupd(ltab,LTCODES,MAXLT,LTSTEP,l); if (ltab[LTCODES+l]==LCUTOFF) les-=LTSTEP=SLCODES) { i=ac_threshold_val(LLLEN); ac_in(i,i+1,LLLEN); l=((l-SLCODES)<POSCODES) ccnt=POSCODES; } swd_dpair(l,p); } else { ac_in(i,i+1,i+1); flush(); asc_cleanup(); return; } } } ha-0.999p+dfsg/cpy.c0000644000175000001440000000243005705175642012667 0ustar magusers/*********************************************************************** This file is part of HA, a general purpose file archiver. Copyright (C) 1995 Harri Hirvola 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. ************************************************************************ HA CPY method ***********************************************************************/ #include #include #include "ha.h" #include "cpy.h" #include "haio.h" void cpy(void) { register S16B c; register U32B cnt; if ((cnt=totalsize)==0) return; while ((c=getbyte())>=0) { putbyte(c); if (!--cnt) break; } flush(); } ha-0.999p+dfsg/hsc.c0000644000175000001440000004025005705175624012653 0ustar magusers/*********************************************************************** This file is part of HA, a general purpose file archiver. Copyright (C) 1995 Harri Hirvola 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. ************************************************************************ HA HSC method ***********************************************************************/ #include #include #include #include "ha.h" #include "haio.h" #include "acoder.h" #include "hsc.h" #include "error.h" #define IECLIM 32 /* initial escape counter upper limit */ #define NECLIM 5 /* no escape expected counter limit */ #define NECTLIM 4 /* */ #define NECMAX 10 /* no escape expected counter maximum */ #define MAXCLEN 4 /* assumed to be 4 in several places */ #define NUMCON 10000 /* number of contexts to remember */ #define NUMCFB 32760 /* number of frequencies to remember */ #define ESCTH 3 /* threshold for escape calculation */ #define MAXTVAL 8000 /* maximum frequency value */ #define RFMINI 4 /* initial refresh counter value */ #define HTLEN 16384 /* length of hash table */ #define NIL 0xffff /* NIL pointer in lists */ #define ESC 256 /* escape symbol */ typedef unsigned char Context[4]; /* model data */ static Context curcon; /* current context */ static U16B *ht=NULL; /* hash table */ static U16B *hp=NULL; /* hash list pointer array */ static Context *con=NULL; /* context array */ static unsigned char *cl=NULL; /* context length array */ static unsigned char *cc=NULL; /* character counts */ static U16B *ft=NULL; /* total frequency of context */ static unsigned char *fe=NULL; /* frequencys under ESCTH in context */ static U16B *elp=NULL; /* expire list previous pointer array */ static U16B *eln=NULL; /* expire list next pointer array */ static U16B elf,ell; /* first and last of expire list */ static unsigned char *rfm=NULL; /* refresh counter array */ static U16B *fa=NULL; /* frequency array */ static unsigned char *fc=NULL; /* character for frequency array */ static U16B *nb=NULL; /* next pointer for frequency array */ static U16B fcfbl; /* pointer to free frequency blocks */ static U16B nrel; /* context for frequency block release */ /* frequency mask system */ static unsigned char cmask[256]; /* masked characters */ static unsigned char cmstack[256]; /* stack of cmask[] entries to clear */ static S16B cmsp; /* pointer to cmstack */ /* escape propability modifying system variables */ static unsigned char nec; /* counter for no escape expected */ static unsigned char iec[MAXCLEN+1]; /* initial escape counters */ /* update stack variables */ static U16B usp; /* stack pointer */ static U16B cps[MAXCLEN+1]; /* context pointers */ static U16B as[MAXCLEN+1]; /* indexes to frequency array */ /* miscalneous */ static S16B dropcnt; /* counter for context len drop */ static unsigned char maxclen; /* current maximum length for context */ static U16B hrt[HTLEN]; /* semi random data for hashing */ static U16B hs[MAXCLEN+1]; /* hash stack for context search */ static S16B cslen; /* length of context to search */ /*********************************************************************** Cleanup routine ***********************************************************************/ void hsc_cleanup(void) { if (ht!=NULL) free(ht),ht=NULL; if (fc!=NULL) free(fc),fc=NULL; if (fa!=NULL) free(fa),fa=NULL; if (ft!=NULL) free(ft),ft=NULL; if (fe!=NULL) free(fe),fe=NULL; if (nb!=NULL) free(nb),nb=NULL; if (hp!=NULL) free(hp),hp=NULL; if (elp!=NULL) free(elp),elp=NULL; if (eln!=NULL) free(eln),eln=NULL; if (cl!=NULL) free(cl),cl=NULL; if (cc!=NULL) free(cc),cc=NULL; if (rfm!=NULL) free(rfm),rfm=NULL; if (con!=NULL) free(con),con=NULL; } /*********************************************************************** System initialization ***********************************************************************/ static U16B make_context(unsigned char cl, S16B c); static void init_model(void) { register S16B i; S32B z,l,h,t; ht=malloc(HTLEN*sizeof(*ht)); hp=malloc(NUMCON*sizeof(*hp)); elp=malloc(NUMCON*sizeof(*elp)); eln=malloc(NUMCON*sizeof(*eln)); cl=malloc(NUMCON*sizeof(*cl)); cc=malloc(NUMCON*sizeof(*cc)); ft=malloc(NUMCON*sizeof(*ft)); fe=malloc(NUMCON*sizeof(*fe)); rfm=malloc(NUMCON*sizeof(*rfm)); con=malloc(NUMCON*sizeof(*con)); fc=malloc(NUMCFB*sizeof(*fc)); fa=malloc(NUMCFB*sizeof(*fa)); nb=malloc(NUMCFB*sizeof(*nb)); if (hp==NULL || elp==NULL || eln==NULL || cl==NULL || rfm==NULL || con==NULL || cc==NULL || ft==NULL || fe==NULL || fc==NULL || fa==NULL || nb==NULL || ht==NULL) { hsc_cleanup(); error(1,ERR_MEM,"init_model()"); } maxclen=MAXCLEN; iec[0]=(IECLIM>>1); for (i=1;i<=MAXCLEN;++i) iec[i]=(IECLIM>>1)-1; dropcnt=NUMCON/4; nec=0; nrel=0; hs[0]=0; for (i=0;i0) z=t; else z=t+2147483647L; hrt[i]=(U16B)z&(HTLEN-1); } } static void init_pack(void) { init_model(); ac_init_encode(); } static void init_unpack(void) { init_model(); ac_init_decode(); } /*********************************************************************** Finite context model ***********************************************************************/ #define HASH(s,l,h) { \ h=0; \ if (l) h=hrt[s[0]]; \ if (l>1) h=hrt[(s[1]+h)&(HTLEN-1)]; \ if (l>2) h=hrt[(s[2]+h)&(HTLEN-1)]; \ if (l>3) h=hrt[(s[3]+h)&(HTLEN-1)]; \ } #define move_context(c) curcon[3]=curcon[2],curcon[2]=curcon[1], \ curcon[1]=curcon[0],curcon[0]=c static void release_cfblocks(void) { register U16B i,j,d; do { do if (++nrel==NUMCON) nrel=0; while (nb[nrel]==NIL); for (i=0;i<=usp;++i) if ((cps[i]&0x7fff)==nrel) break; } while (i<=usp); for (i=nb[nrel],d=fa[nrel];i!=NIL;i=nb[i]) if (fa[i]=MAXTVAL) { ++rfm[cp]; fe[cp]=ft[cp]=0; for (i=cp;i!=NIL;i=nb[i]) { if (fa[i]>1) { ft[cp]+=fa[i]>>=1; if (fa[i]=0;--i) { k=hs[i]; for (cp=ht[k];cp!=NIL;cp=hp[cp]) { if (cl[cp]==i) { switch (i) { case 4: if (curcon[3]!=con[cp][3]) break; case 3: if (curcon[2]!=con[cp][2]) break; case 2: if (curcon[1]!=con[cp][1]) break; case 1: if (curcon[0]!=con[cp][0]) break; case 0: cslen=i; return cp; } } } } return NIL; } static U16B find_longest(void) { hs[1]=hrt[curcon[0]]; hs[2]=hrt[(curcon[1]+hs[1])&(HTLEN-1)]; hs[3]=hrt[(curcon[2]+hs[2])&(HTLEN-1)]; hs[4]=hrt[(curcon[3]+hs[3])&(HTLEN-1)]; usp=0; while(cmsp) cmask[cmstack[--cmsp]]=0; cslen=MAXCLEN+1; return find_next(); } static U16B adj_escape_prob(U16B esc, U16B cp) { if (ft[cp]==1) return iec[cl[cp]]>=(IECLIM>>1)?2:1; if (cc[cp]==255) return 1; if (cc[cp] && ((cc[cp]+1)<<1)>=ft[cp]) { esc=(S16B)((S32B)esc*((cc[cp]+1)<<1)/ft[cp]); if (cc[cp]+1==ft[cp]) esc+=(cc[cp]+1)>>1; } return esc?esc:1; } static S16B code_first(U16B cp, S16B c) { register U16B i; register S16B sum,cf,tot,esc; sum=cf=0; for (i=cp;i!=NIL;i=nb[i]) { if (fc[i]==c) { cf=fa[i]; as[0]=i; break; } sum+=fa[i]; } tot=ft[cp]; esc=adj_escape_prob(fe[cp],cp); if (nec>=NECLIM) { if (tot<=NECTLIM && nec==NECMAX) { tot<<=2; sum<<=2; cf<<=2; } else { tot<<=1; sum<<=1; cf<<=1; } } usp=1; if (cf==0) { ac_out(tot,tot+esc,tot+esc); for (i=cp;i!=NIL;sum=i,i=nb[i]) { cmstack[cmsp++]=fc[i]; cmask[fc[i]]=1; } as[0]=sum; /* sum holds last i ! */ nec=0; if (ft[cp]==1 && iec[cl[cp]]=NECLIM) { if (tot<=NECTLIM && nec==NECMAX) sv=2; else sv=1; tot<<=sv; tv=ac_threshold_val(tot+esc)>>sv; for (c=cp,sum=0;;c=nb[c]) { if (c==NIL) break; if (sum+fa[c]<=tv) sum+=fa[c]; else { cf=fa[c]<=0;) { cp=find_longest(); ncmin=cp==NIL?0:cl[cp]+1; ncmax=maxclen+1; for(;;) { if (cp==NIL) { code_new(c); break; } if (code_byte(cp,c)) { el_movefront(cp); break; } cp=find_next(); } add_model(c); while (ncmax>ncmin) make_context(--ncmax,c); move_context(c); } cp=find_longest(); while (cp!=NIL) { code_byte(cp,ESC); cp=find_next(); } code_new(ESC); ac_end_encode(); hsc_cleanup(); } /*********************************************************************** Decoding ***********************************************************************/ void hsc_unpack(void) { S16B c; U16B cp; unsigned char ncmax,ncmin; init_unpack(); for (;;) { cp=find_longest(); ncmin=cp==NIL?0:cl[cp]+1; ncmax=maxclen+1; for(;;) { if (cp==NIL) { c=decode_new(); break; } if ((c=decode_byte(cp))!=ESC) { el_movefront(cp); break; } cp=find_next(); } if (c==ESC) break; add_model(c); while (ncmax>ncmin) make_context(--ncmax,c); putbyte(c); move_context(c); } flush(); hsc_cleanup(); } ha-0.999p+dfsg/acoder.h0000644000175000001440000000230405705175746013343 0ustar magusers/*********************************************************************** This file is part of HA, a general purpose file archiver. Copyright (C) 1995 Harri Hirvola 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. ************************************************************************ HA arithmetic coder ***********************************************************************/ void ac_init_encode(void); void ac_end_encode(void); void ac_init_decode(void); void ac_out(U16B low, U16B high, U16B tot); U16B ac_threshold_val(U16B tot); void ac_in(U16B low, U16B high, U16B tot); ha-0.999p+dfsg/makefile.bcc0000644000175000001440000000503505705115316014152 0ustar magusers############################################################################ # This file is part of HA, a general purpose file archiver. # Copyright (C) 1995 Harri Hirvola # # 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. ############################################################################ # Makefile for HA using bcc 4.0 on PC ############################################################################ MCH = pc INC = include C_SRC = c BCDIR = c:\apps\bc4 STARTUP = $(BCDIR)\lib\c0c.obj LIBS = $(BCDIR)\lib\cc.lib !ifdef PCASM COPT = -DPCASM -mc -O2 -c -K -w -n$: -I$(MCH) -I$(INC) -I$(BCDIR)\include !else COPT = -mc -O2 -c -K -w -n$: -I$(MCH) -I$(INC) -I$(BCDIR)\include !endif ASM = tasm AOPT = /zi LINK = tlink LOPT = /L$(C_SRC) !ifdef PCASM OBJS = ha.obj haio.obj archive.obj swdict.obj \ cpy.obj error.obj misc.obj asc.obj \ $(MCH)\machine.obj $(MCH)\info.obj $(MCH)\a_hsc.obj \ $(MCH)\a_acoder.obj $(MCH)\a_swdict.obj !else OBJS = ha.obj haio.obj archive.obj acoder.obj swdict.obj \ cpy.obj error.obj misc.obj hsc.obj acoder.obj asc.obj \ $(MCH)\machine.obj $(MCH)\info.obj !endif .path.obj = $(C_SRC) .path.c = $(C_SRC) .path.h = $(INC) .c.obj: bcc $(COPT) $*.c .asm.obj: bcc $(AOPT) $*.asm ha.exe : $(OBJS) tlink $(LOPT) @&&! $(STARTUP) $** $&.exe $&.map $(LIBS) ! $(MCH)\machine.obj: $(MCH)\machine.c $(MCH)\machine.h bcc $(COPT) $*.c $(MCH)\info.obj: $(MCH)\info.c bcc $(COPT) $*.c $(MCH)\info.c: $(MCH)\info.txt ha MAKEINFO $(MCH)\info.txt $(MCH)\info.c $(MCH)\a_acoder.obj: $(MCH)\a_acoder.asm tasm $(AOPT) $(MCH)\a_acoder.asm,$(MCH)\a_acoder.obj $(MCH)\a_swdict.obj: $(MCH)\a_swdict.asm tasm $(AOPT) $(MCH)\a_swdict.asm,$(MCH)\a_swdict.obj $(MCH)\a_hsc.obj: $(MCH)\a_hsc.asm tasm $(AOPT) $(MCH)\a_hsc.asm,$(MCH)\a_hsc.obj $(MCH)\a_asc.obj: $(MCH)\a_asc.asm tasm $(AOPT) $(MCH)\a_asc.asm,$(MCH)\a_asc.obj clean: del ha.exe del ha.map del $(C_SRC)\*.obj del $(MCH)\*.obj ha-0.999p+dfsg/cpy.h0000644000175000001440000000201205705175730012666 0ustar magusers/*********************************************************************** This file is part of HA, a general purpose file archiver. Copyright (C) 1995 Harri Hirvola 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. ************************************************************************ HA CPY method ***********************************************************************/ void cpy(void); ha-0.999p+dfsg/bin/0000755000175000001440000000000011032167171012465 5ustar magusersha-0.999p+dfsg/machine.c0000644000175000001440000002706005705175774013514 0ustar magusers/*********************************************************************** This file is part of HA, a general purpose file archiver. Copyright (C) 1995 Harri Hirvola 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. ************************************************************************ HA *nix specific routines ***********************************************************************/ #include #include #include #include #include #include #include "ha.h" #include "error.h" #include "archive.h" #define HA_ISVTX 0x0200 #define HA_ISGID 0x0400 #define HA_ISUID 0x0800 #define HA_IRUSR 0x0100 #define HA_IWUSR 0x0080 #define HA_IXUSR 0x0040 #define HA_IRGRP 0x0020 #define HA_IWGRP 0x0010 #define HA_IXGRP 0x0008 #define HA_IROTH 0x0004 #define HA_IWOTH 0x0002 #define HA_IXOTH 0x0001 #define HA_IFMT 0xf000 #define HA_IFIFO 0x1000 #define HA_IFCHR 0x2000 #define HA_IFDIR 0x4000 #define HA_IFBLK 0x6000 #define HA_IFREG 0x8000 #define HA_IFLNK 0xa000 #define HA_IFSOCK 0xc000 #define HA_ISDIR(m) ((m&HA_IFMT)==HA_IFDIR) #define HA_ISCHR(m) ((m&HA_IFMT)==HA_IFCHR) #define HA_ISBLK(m) ((m&HA_IFMT)==HA_IFBLK) #define HA_ISLNK(m) ((m&HA_IFMT)==HA_IFLNK) #define HA_ISFIFO(m) ((m&HA_IFMT)==HA_IFIFO) #define HA_ISSOCK(m) ((m&HA_IFMT)==HA_IFSOCK) typedef struct { unsigned mtype; unsigned attr; unsigned user; unsigned group; } Mdhd; #define MDHDLEN 7 /* Length of Mdhd in archive */ static Mdhd mdhd; struct stat filestat; static void sig_handler(int signo) { error(1,ERR_INT,signo); } void md_init(void) { signal(SIGINT,sig_handler); signal(SIGTERM,sig_handler); signal(SIGPIPE,sig_handler); signal(SIGQUIT,sig_handler); umask(0); } U32B md_systime(void) { return (U32B)time(NULL); } static mode_t md_tomdattr(U16B haattr) { mode_t mdattr; mdattr=0; if (haattr&HA_IRUSR) mdattr|=S_IRUSR; if (haattr&HA_IWUSR) mdattr|=S_IWUSR; if (haattr&HA_ISUID) mdattr|=S_ISUID; if (haattr&HA_IXUSR) mdattr|=S_IXUSR; if (haattr&HA_IRGRP) mdattr|=S_IRGRP; if (haattr&HA_IWGRP) mdattr|=S_IWGRP; if (haattr&HA_ISGID) mdattr|=S_ISGID; if (haattr&HA_IXGRP) mdattr|=S_IXGRP; if (haattr&HA_IROTH) mdattr|=S_IROTH; if (haattr&HA_IWOTH) mdattr|=S_IWOTH; #ifdef S_ISVTX if (haattr&HA_ISVTX) mdattr|=S_ISVTX; #endif if (haattr&HA_IXOTH) mdattr|=S_IXOTH; return mdattr; } static U16B md_tohaattr(mode_t mdattr) { U16B haattr; haattr=0; if (mdattr&S_IRUSR) haattr|=HA_IRUSR; if (mdattr&S_IWUSR) haattr|=HA_IWUSR; if (mdattr&S_ISUID) haattr|=HA_ISUID; if (mdattr&S_IXUSR) haattr|=HA_IXUSR; if (mdattr&S_IRGRP) haattr|=HA_IRGRP; if (mdattr&S_IWGRP) haattr|=HA_IWGRP; if (mdattr&S_ISGID) haattr|=HA_ISGID; if (mdattr&S_IXGRP) haattr|=HA_IXGRP; if (mdattr&S_IROTH) haattr|=HA_IROTH; if (mdattr&S_IWOTH) haattr|=HA_IWOTH; if (mdattr&S_IXOTH) haattr|=HA_IXOTH; #ifdef S_ISVTX if (mdattr&S_ISVTX) haattr|=HA_ISVTX; #endif if (S_ISDIR(mdattr)) haattr|=HA_IFDIR; else if (S_ISCHR(mdattr)) haattr|=HA_IFCHR; else if (S_ISBLK(mdattr)) haattr|=HA_IFBLK; #ifdef S_ISLNK else if (S_ISLNK(mdattr)) haattr|=HA_IFLNK; #endif #ifdef S_ISFIFO else if (S_ISFIFO(mdattr)) haattr|=HA_IFIFO; #endif #ifdef S_ISSOCK else if (S_ISSOCK(mdattr)) haattr|=HA_IFSOCK; #endif return haattr; } static char *attrstring(unsigned haattr) { static char as[11]; sprintf(as,"%c%c%c%c%c%c%c%c%c%c", HA_ISFIFO(haattr)?'f':HA_ISSOCK(haattr)?'s':HA_ISLNK(haattr)?'l': HA_ISDIR(haattr)?'d':HA_ISCHR(haattr)?'c':HA_ISBLK(haattr)?'b':'-', (haattr&HA_IRUSR)?'r':'-', (haattr&HA_IWUSR)?'w':'-', (haattr&HA_ISUID)?(haattr& HA_IXUSR)?'s':'S':(haattr&HA_IXUSR)?'x':'-', (haattr&HA_IRGRP)?'r':'-', (haattr&HA_IWGRP)?'w':'-', (haattr&HA_ISGID)?(haattr& HA_IXGRP)?'s':'S':(haattr&HA_IXGRP)?'x':'-', (haattr&HA_IROTH)?'r':'-', (haattr&HA_IWOTH)?'w':'-', (haattr&HA_ISVTX)?(haattr& HA_IXOTH)?'t':'T':(haattr&HA_IXOTH)?'x':'-' ); return as; } void md_gethdr(int len, int mode) { static int longest=0; static unsigned char *buf=NULL; if (len>longest) { if (buf!=NULL) buf=realloc(buf,len); else buf=malloc(len); if (buf==NULL) error(1,ERR_MEM,"md_gethdr()"); longest=len; } read(arcfile,buf,len); mdhd.mtype=buf[0]; if (mdhd.mtype==UNIXMDH) { mdhd.attr=buf[1]|(buf[2]<<8); mdhd.user=buf[3]|(buf[4]<<8); mdhd.group=buf[5]|(buf[6]<<8); } else { switch (mode) { case M_DIR: mdhd.attr=md_tohaattr(DEF_DIRATTR); mdhd.attr|=HA_IFDIR; break; default: mdhd.attr=md_tohaattr(DEF_FILEATTR); break; } } } void md_puthdr(void) { unsigned char buf[MDHDLEN]; buf[0]=UNIXMDH; buf[1]=mdhd.attr&0xff; buf[2]=(mdhd.attr>>8)&0xff; buf[3]=mdhd.user&0xff; buf[4]=(mdhd.user>>8)&0xff; buf[5]=mdhd.group&0xff; buf[6]=(mdhd.group>>8)&0xff; write(arcfile,buf,MDHDLEN); } int md_filetype(char *path, char *name) { char *fullpath; if (!strcmp(name,".") || !strcmp(name,"..")) return T_SKIP; fullpath=md_pconcat(0,path,name); if (lstat(fullpath,&filestat)<0) { error(0,ERR_STAT,fullpath); free(fullpath); return T_SKIP; } free(fullpath); if (filestat.st_ino==arcstat.st_ino) return T_SKIP; if (S_ISDIR(filestat.st_mode)) return T_DIR; if (S_ISREG(filestat.st_mode)) return T_REGULAR; return T_SPECIAL; } int md_newfile(void) { mdhd.attr=md_tohaattr(filestat.st_mode); mdhd.user=filestat.st_uid; mdhd.group=filestat.st_gid; return MDHDLEN; } int md_special(char *fullname, unsigned char **sdata) { static unsigned char *dat=NULL; int len; if (dat!=NULL) { free(dat); dat=NULL; } if (HA_ISCHR(mdhd.attr)||HA_ISBLK(mdhd.attr)) { if ((dat=malloc(sizeof(dev_t)))==NULL) error(1,ERR_MEM,"md_special()"); *(dev_t*)dat=filestat.st_rdev; *sdata=dat; return sizeof(dev_t); } if (HA_ISLNK(mdhd.attr)) { if ((dat=malloc(1024))==NULL) error(1,ERR_MEM,"md_special()"); if ((len=readlink(fullname,(char*)dat,1024))<0) error(1,ERR_RDLINK,fullname); dat[len]=0; *sdata=dat; return len+1; } else { *sdata=dat; return 0; } } int md_mkspecial(char *ofname,unsigned sdlen,unsigned char *sdata) { if (mdhd.mtype!=UNIXMDH) { error(0,ERR_HOW,ofname); return 0; } if (HA_ISCHR(mdhd.attr)) { mknod(ofname,md_tomdattr(mdhd.attr)|S_IFCHR,*(dev_t*)sdata); if (useattr) chown(ofname,mdhd.user,mdhd.group); return 1; } else if (HA_ISBLK(mdhd.attr)) { mknod(ofname,md_tomdattr(mdhd.attr)|S_IFBLK,*(dev_t*)sdata); if (useattr) chown(ofname,mdhd.user,mdhd.group); return 1; } #ifdef S_ISLNK else if (HA_ISLNK(mdhd.attr)) { if (symlink(ofname,(char*)sdata)<0) error(0,ERR_MKLINK,sdata,ofname); if (useattr) { chmod(ofname,md_tomdattr(mdhd.attr)); chown(ofname,mdhd.user,mdhd.group); } return 1; } #endif #ifdef S_ISFIFO else if (HA_ISFIFO(mdhd.attr)) { if (mkfifo(ofname,md_tomdattr(mdhd.attr))<0) error(0,ERR_MKFIFO,sdata,ofname); if (useattr) chown(ofname,mdhd.user,mdhd.group); return 1; } #endif error(0,ERR_HOW,ofname); return 0; } void md_setfattrs(char *file) { if (useattr) { chmod(file,md_tomdattr(mdhd.attr)); chown(file,mdhd.user,mdhd.group); } } void md_setft(char *file,U32B time) { struct utimbuf utb; utb.actime=time; utb.modtime=time; utime(file,&utb); } void md_listhdr(void) { printf("\n attr"); } void md_listdat(void) { printf("\n %s",attrstring(mdhd.attr)); } char *md_timestring(unsigned long t) { static char ts[22]; struct tm *tim; tim=localtime((long *)&t); sprintf(ts,"%04d-%02d-%02d %02d:%02d",tim->tm_year+1900,tim->tm_mon+1, tim->tm_mday,tim->tm_hour,tim->tm_min); return ts; } char *md_arcname(char *name_req) { int pos; char *newname; pos=strlen(name_req); if (pos>3 && tolower(name_req[pos-1])=='a' && tolower(name_req[pos-2])=='h' && name_req[pos-3]=='.') return name_req; if ((newname=malloc(pos+4))==NULL) error(1,ERR_MEM,"md_arcname()"); strcpy(newname,name_req); strcpy(newname+pos,".ha"); return newname; } void md_truncfile(int fh, U32B len) { ftruncate(fh,len); } char *md_tohapath(char *mdpath) { int i,j; static char *hapath=NULL; if (hapath!=NULL) free(hapath),hapath=NULL; j=strlen(mdpath); for (i=0;mdpath[i];++i) if (mdpath[i]!='.' && mdpath[i]!='/') break; while (i>0 && mdpath[i-1]=='.') --i; if (i==0) skipemptypath=1; else skipemptypath=0; if ((hapath=malloc(j+1-i))==NULL) error(1,ERR_MEM,"md_tohapath()"); strcpy(hapath,mdpath+i); for (i=0;hapath[i];++i) if (hapath[i]=='/') hapath[i]=0xff; return md_strcase(hapath); } char *md_tomdpath(char *hapath) { int i; static char *mdpath=NULL; if (mdpath!=NULL) free(mdpath),mdpath=NULL; if ((mdpath=malloc(strlen(hapath)+1))==NULL) error(1,ERR_MEM,"md_tomdpath()"); strcpy(mdpath,hapath); for (i=0;mdpath[i];++i) if ((unsigned char)mdpath[i]==0xff) mdpath[i]='/'; return mdpath; } char *md_strippath(char *mdfullpath) { int i; static char *plainpath=NULL; if (plainpath!=NULL) free(plainpath),plainpath=NULL; if ((plainpath=malloc(strlen(mdfullpath)+1))==NULL) error(1,ERR_MEM,"md_strippath()"); strcpy(plainpath,mdfullpath); for (i=strlen(plainpath)-1;i>=0;i--) { if (plainpath[i]=='/') break; } plainpath[i+1]=0; return plainpath; } char *md_stripname(char *mdfullpath) { int i; static char *plainname=NULL; if (plainname!=NULL) free(plainname),plainname=NULL; if ((plainname=malloc(strlen(mdfullpath)+1))==NULL) error(1,ERR_MEM,"md_stripname()"); for (i=strlen(mdfullpath)-1;i>0;i--) { if (mdfullpath[i]=='/') { i++; break; } } strcpy(plainname,mdfullpath+i); return plainname; } char *md_pconcat(int delim2, char *head, char *tail) { char *newpath; int headlen,delim1; delim1=0; if ((headlen=strlen(head))!=0) { if (head[headlen-1]!='/') delim1=1; } if ((newpath=malloc(headlen+strlen(tail)+delim2+delim1+1))==NULL) error(1,ERR_MEM,"md_pconcat()"); if (headlen!=0) strcpy(newpath,head); if (delim1) newpath[headlen]='/'; strcpy(newpath+headlen+delim1,tail); if (delim2) strcpy(newpath+strlen(newpath),"/"); return newpath; } int md_namecmp(char *pat, char *cmp) { if (*pat==0) return !*cmp; if (*pat=='?') { if (!*cmp) return 0; return md_namecmp(pat+1,cmp+1); } if (*pat=='*') { if (*(pat+1)==0) return 1; for (;*cmp;++cmp) { if (md_namecmp(pat+1,cmp)) return 1; } return 0; } if (*pat=='\\') { ++pat; if (*pat==0) return 0; } if (*pat==*cmp) return md_namecmp(pat+1,cmp+1); return 0; } ha-0.999p+dfsg/makefile0000644000175000001440000000210505705174704013425 0ustar magusers############################################################################ # This file is part of HA, a general purpose file archiver. # Copyright (C) 1995 Harri Hirvola # # 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. ############################################################################ # Makefile for HA includes ############################################################################ all: depend dep: clean: rm -f *~ ha-0.999p+dfsg/swdict.c0000644000175000001440000001043705705175614013376 0ustar magusers/*********************************************************************** This file is part of HA, a general purpose file archiver. Copyright (C) 1995 Harri Hirvola 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. ************************************************************************ HA sliding window dictionary ***********************************************************************/ #include #include #include "ha.h" #include "haio.h" #include "swdict.h" #include "error.h" #define HSIZE 16384 #define HSHIFT 3 #define HASH(p) ((b[p]^((b[p+1]^(b[p+2]<MAXCNT) cnt=MAXCNT; ptr=ll[bbf]=cr[i]; cr[i]=bbf; swd_char=b[bbf]; if ((start_len=swd_mlf)>=bbl) { if (bbl==0) swd_char=-1; best[bbf]=30000; } else { for (ref=b[bbf+swd_mlf-1];cnt--;ptr=ll[ptr]) { if (b[ptr+swd_mlf-1]==ref && b[ptr]==b[bbf] && b[ptr+1]==b[bbf+1]) { { register unsigned char *p1=b+ptr+3,*p2=b+bbf+3; for (i=3;istart_len) { if (swd_bposp) p=bbf-1-p; else p=cblen-1-p+bbf; while (l--) { b[bbf]=b[p]; putbyte(b[p]); if (++bbf==cblen) bbf=0; if (++p==cblen) p=0; } } void swd_dchar(S16B c) { b[bbf]=c; putbyte(c); if (++bbf==cblen) bbf=0; } ha-0.999p+dfsg/format0000644000175000001440000000104305474217732013142 0ustar magusersAll numbers are in LOHI byte order. HAFILE 0000 HA /* HA = identifier fo ha archive */ 0002 cnt /* cnt = number of files in archive */ 0004 HDR1 /* HDR = information for file */ . file1 . HDR2 . file2 . . . Header : 0000 ver<<4 | type /* type 0-CPY, 1-ASC, 2-HSC, 0xe-DIR 0xf-SPECIAL */ 0001 length compressed 0005 length original 0009 CRC 32 000D filetime 0011 path +n 00h +1 name +n 00h +1 Length of machine specific information +1 Machine specific information Machine specific information : 0000 type 0001 Information . . . ha-0.999p+dfsg/README0000644000175000001440000000445105705224134012604 0ustar magusersHA is an archiver which I released in january 1993 as version 0.98. After that I had plans to improve speed, archive handling etc. which would have required total rewrite of the code. For that I unfortunately could not find time. Because there has been quite considerably interest for internals of HA (especially for the HSC compression method) I decided to make a source level release from my current test version (0.999 beta) and place it under GNU General Public License. The sources for this version are not very consistent or clean, but everything should work. There are several improvements which should be made before this could be called version 1.0. Some of the most obvious of these are: - Compression methods should be coded in assembler for PC and using more efficient data structures for 32 bit platforms. Current version does some things only to overcome 64kB segments of 8086. - UNIX port has still some problems and is missing some things (for example a grouping operator in wildcard matches). - File handling is far from optimum. - Archive handling is not too clever either. - Testing should be done more thoroughly as there are many special cases in compression routines which get used very rarely. - Documentation of code and algorithms is totally missing. This archive (ha0999.zip) contains this readme, MSDOS executable ha.exe and source files for HA 0.999beta. Ha.exe is NOT compiled directly from included sources. Some critical parts of it were compiled from hand optimized versions of compiler output. It is somewhat faster than "pure C" version. MSDOS sources are for Borland C 4.0 but older versions of bcc should work. Makefile needs some editing as some paths are hardcoded in it. UNIX sources are not very generic. I have only tested this using Linux on PC and AIX on IBM6000. Only compiler and make utility that I have tested are GCC and GNU MAKE. Porting HA should be fairly easy as all machine specific code is in machine.h and machine.c under machine specific directories. Md_funcs.txt documents these functions. Examples can be found from pc and nix directories. Email address where I can be reached is "harri.hirvola@vaisala.infonet.com". My email addresses have not been very stable and I would not be very surprised if this one too is only valid for some months... Harri Hirvola