Commit 9f42b89c authored by David Pilling's avatar David Pilling Committed by ROOL
Browse files

Import of ARJ compressor module

Admin:
  Special thanks to David Pilling for allowing the sources to SparkFS to be
  published.
  These are the sources to ARJ 1.50 as received from David, imported with
  a standard CModule component layout and so are unlikely to build in their
  current form.

Version 1.50. Tagged as 'SparkARJ-1_50'
parents
s/** gitlab-language=armasm linguist-language=armasm linguist-detectable=true
c/** gitlab-language=c linguist-language=c linguist-detectable=true
h/** gitlab-language=c linguist-language=c linguist-detectable=true
cmhg/** gitlab-language=cmhg linguist-language=cmhg linguist-detectable=true
All files in this distribution are released under the
Common Development and Distribution License (CDDL).
--------------------------------------------------------------------
COMMON DEVELOPMENT AND DISTRIBUTION LICENSE Version 1.0
1. Definitions.
1.1. "Contributor" means each individual or entity that creates
or contributes to the creation of Modifications.
1.2. "Contributor Version" means the combination of the Original
Software, prior Modifications used by a Contributor (if any),
and the Modifications made by that particular Contributor.
1.3. "Covered Software" means (a) the Original Software, or (b)
Modifications, or (c) the combination of files containing
Original Software with files containing Modifications, in
each case including portions thereof.
1.4. "Executable" means the Covered Software in any form other
than Source Code.
1.5. "Initial Developer" means the individual or entity that first
makes Original Software available under this License.
1.6. "Larger Work" means a work which combines Covered Software or
portions thereof with code not governed by the terms of this
License.
1.7. "License" means this document.
1.8. "Licensable" means having the right to grant, to the maximum
extent possible, whether at the time of the initial grant or
subsequently acquired, any and all of the rights conveyed
herein.
1.9. "Modifications" means the Source Code and Executable form of
any of the following:
A. Any file that results from an addition to, deletion from or
modification of the contents of a file containing Original
Software or previous Modifications;
B. Any new file that contains any part of the Original
Software or previous Modifications; or
C. Any new file that is contributed or otherwise made
available under the terms of this License.
1.10. "Original Software" means the Source Code and Executable
form of computer software code that is originally released
under this License.
1.11. "Patent Claims" means any patent claim(s), now owned or
hereafter acquired, including without limitation, method,
process, and apparatus claims, in any patent Licensable by
grantor.
1.12. "Source Code" means (a) the common form of computer software
code in which modifications are made and (b) associated
documentation included in or with such code.
1.13. "You" (or "Your") means an individual or a legal entity
exercising rights under, and complying with all of the terms
of, this License. For legal entities, "You" includes any
entity which controls, is controlled by, or is under common
control with You. For purposes of this definition,
"control" means (a) the power, direct or indirect, to cause
the direction or management of such entity, whether by
contract or otherwise, or (b) ownership of more than fifty
percent (50%) of the outstanding shares or beneficial
ownership of such entity.
2. License Grants.
2.1. The Initial Developer Grant.
Conditioned upon Your compliance with Section 3.1 below and
subject to third party intellectual property claims, the Initial
Developer hereby grants You a world-wide, royalty-free,
non-exclusive license:
(a) under intellectual property rights (other than patent or
trademark) Licensable by Initial Developer, to use,
reproduce, modify, display, perform, sublicense and
distribute the Original Software (or portions thereof),
with or without Modifications, and/or as part of a Larger
Work; and
(b) under Patent Claims infringed by the making, using or
selling of Original Software, to make, have made, use,
practice, sell, and offer for sale, and/or otherwise
dispose of the Original Software (or portions thereof).
(c) The licenses granted in Sections 2.1(a) and (b) are
effective on the date Initial Developer first distributes
or otherwise makes the Original Software available to a
third party under the terms of this License.
(d) Notwithstanding Section 2.1(b) above, no patent license is
granted: (1) for code that You delete from the Original
Software, or (2) for infringements caused by: (i) the
modification of the Original Software, or (ii) the
combination of the Original Software with other software
or devices.
2.2. Contributor Grant.
Conditioned upon Your compliance with Section 3.1 below and
subject to third party intellectual property claims, each
Contributor hereby grants You a world-wide, royalty-free,
non-exclusive license:
(a) under intellectual property rights (other than patent or
trademark) Licensable by Contributor to use, reproduce,
modify, display, perform, sublicense and distribute the
Modifications created by such Contributor (or portions
thereof), either on an unmodified basis, with other
Modifications, as Covered Software and/or as part of a
Larger Work; and
(b) under Patent Claims infringed by the making, using, or
selling of Modifications made by that Contributor either
alone and/or in combination with its Contributor Version
(or portions of such combination), to make, use, sell,
offer for sale, have made, and/or otherwise dispose of:
(1) Modifications made by that Contributor (or portions
thereof); and (2) the combination of Modifications made by
that Contributor with its Contributor Version (or portions
of such combination).
(c) The licenses granted in Sections 2.2(a) and 2.2(b) are
effective on the date Contributor first distributes or
otherwise makes the Modifications available to a third
party.
(d) Notwithstanding Section 2.2(b) above, no patent license is
granted: (1) for any code that Contributor has deleted
from the Contributor Version; (2) for infringements caused
by: (i) third party modifications of Contributor Version,
or (ii) the combination of Modifications made by that
Contributor with other software (except as part of the
Contributor Version) or other devices; or (3) under Patent
Claims infringed by Covered Software in the absence of
Modifications made by that Contributor.
3. Distribution Obligations.
3.1. Availability of Source Code.
Any Covered Software that You distribute or otherwise make
available in Executable form must also be made available in Source
Code form and that Source Code form must be distributed only under
the terms of this License. You must include a copy of this
License with every copy of the Source Code form of the Covered
Software You distribute or otherwise make available. You must
inform recipients of any such Covered Software in Executable form
as to how they can obtain such Covered Software in Source Code
form in a reasonable manner on or through a medium customarily
used for software exchange.
3.2. Modifications.
The Modifications that You create or to which You contribute are
governed by the terms of this License. You represent that You
believe Your Modifications are Your original creation(s) and/or
You have sufficient rights to grant the rights conveyed by this
License.
3.3. Required Notices.
You must include a notice in each of Your Modifications that
identifies You as the Contributor of the Modification. You may
not remove or alter any copyright, patent or trademark notices
contained within the Covered Software, or any notices of licensing
or any descriptive text giving attribution to any Contributor or
the Initial Developer.
3.4. Application of Additional Terms.
You may not offer or impose any terms on any Covered Software in
Source Code form that alters or restricts the applicable version
of this License or the recipients' rights hereunder. You may
choose to offer, and to charge a fee for, warranty, support,
indemnity or liability obligations to one or more recipients of
Covered Software. However, you may do so only on Your own behalf,
and not on behalf of the Initial Developer or any Contributor.
You must make it absolutely clear that any such warranty, support,
indemnity or liability obligation is offered by You alone, and You
hereby agree to indemnify the Initial Developer and every
Contributor for any liability incurred by the Initial Developer or
such Contributor as a result of warranty, support, indemnity or
liability terms You offer.
3.5. Distribution of Executable Versions.
You may distribute the Executable form of the Covered Software
under the terms of this License or under the terms of a license of
Your choice, which may contain terms different from this License,
provided that You are in compliance with the terms of this License
and that the license for the Executable form does not attempt to
limit or alter the recipient's rights in the Source Code form from
the rights set forth in this License. If You distribute the
Covered Software in Executable form under a different license, You
must make it absolutely clear that any terms which differ from
this License are offered by You alone, not by the Initial
Developer or Contributor. You hereby agree to indemnify the
Initial Developer and every Contributor for any liability incurred
by the Initial Developer or such Contributor as a result of any
such terms You offer.
3.6. Larger Works.
You may create a Larger Work by combining Covered Software with
other code not governed by the terms of this License and
distribute the Larger Work as a single product. In such a case,
You must make sure the requirements of this License are fulfilled
for the Covered Software.
4. Versions of the License.
4.1. New Versions.
Sun Microsystems, Inc. is the initial license steward and may
publish revised and/or new versions of this License from time to
time. Each version will be given a distinguishing version number.
Except as provided in Section 4.3, no one other than the license
steward has the right to modify this License.
4.2. Effect of New Versions.
You may always continue to use, distribute or otherwise make the
Covered Software available under the terms of the version of the
License under which You originally received the Covered Software.
If the Initial Developer includes a notice in the Original
Software prohibiting it from being distributed or otherwise made
available under any subsequent version of the License, You must
distribute and make the Covered Software available under the terms
of the version of the License under which You originally received
the Covered Software. Otherwise, You may also choose to use,
distribute or otherwise make the Covered Software available under
the terms of any subsequent version of the License published by
the license steward.
4.3. Modified Versions.
When You are an Initial Developer and You want to create a new
license for Your Original Software, You may create and use a
modified version of this License if You: (a) rename the license
and remove any references to the name of the license steward
(except to note that the license differs from this License); and
(b) otherwise make it clear that the license contains terms which
differ from this License.
5. DISCLAIMER OF WARRANTY.
COVERED SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS"
BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED
SOFTWARE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR
PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND
PERFORMANCE OF THE COVERED SOFTWARE IS WITH YOU. SHOULD ANY
COVERED SOFTWARE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE
INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY
NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF
WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF
ANY COVERED SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS
DISCLAIMER.
6. TERMINATION.
6.1. This License and the rights granted hereunder will terminate
automatically if You fail to comply with terms herein and fail to
cure such breach within 30 days of becoming aware of the breach.
Provisions which, by their nature, must remain in effect beyond
the termination of this License shall survive.
6.2. If You assert a patent infringement claim (excluding
declaratory judgment actions) against Initial Developer or a
Contributor (the Initial Developer or Contributor against whom You
assert such claim is referred to as "Participant") alleging that
the Participant Software (meaning the Contributor Version where
the Participant is a Contributor or the Original Software where
the Participant is the Initial Developer) directly or indirectly
infringes any patent, then any and all rights granted directly or
indirectly to You by such Participant, the Initial Developer (if
the Initial Developer is not the Participant) and all Contributors
under Sections 2.1 and/or 2.2 of this License shall, upon 60 days
notice from Participant terminate prospectively and automatically
at the expiration of such 60 day notice period, unless if within
such 60 day period You withdraw Your claim with respect to the
Participant Software against such Participant either unilaterally
or pursuant to a written agreement with Participant.
6.3. In the event of termination under Sections 6.1 or 6.2 above,
all end user licenses that have been validly granted by You or any
distributor hereunder prior to termination (excluding licenses
granted to You by any distributor) shall survive termination.
7. LIMITATION OF LIABILITY.
UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT
(INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE
INITIAL DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF
COVERED SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE
LIABLE TO ANY PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT
LIMITATION, DAMAGES FOR LOST PROFITS, LOSS OF GOODWILL, WORK
STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER
COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN
INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF
LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL
INJURY RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT
APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO
NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR
CONSEQUENTIAL DAMAGES, SO THIS EXCLUSION AND LIMITATION MAY NOT
APPLY TO YOU.
8. U.S. GOVERNMENT END USERS.
The Covered Software is a "commercial item," as that term is
defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial
computer software" (as that term is defined at 48
C.F.R. 252.227-7014(a)(1)) and "commercial computer software
documentation" as such terms are used in 48 C.F.R. 12.212
(Sept. 1995). Consistent with 48 C.F.R. 12.212 and 48
C.F.R. 227.7202-1 through 227.7202-4 (June 1995), all
U.S. Government End Users acquire Covered Software with only those
rights set forth herein. This U.S. Government Rights clause is in
lieu of, and supersedes, any other FAR, DFAR, or other clause or
provision that addresses Government rights in computer software
under this License.
9. MISCELLANEOUS.
This License represents the complete agreement concerning subject
matter hereof. If any provision of this License is held to be
unenforceable, such provision shall be reformed only to the extent
necessary to make it enforceable. This License shall be governed
by the law of the jurisdiction specified in a notice contained
within the Original Software (except to the extent applicable law,
if any, provides otherwise), excluding such jurisdiction's
conflict-of-law provisions. Any litigation relating to this
License shall be subject to the jurisdiction of the courts located
in the jurisdiction and venue specified in a notice contained
within the Original Software, with the losing party responsible
for costs, including, without limitation, court costs and
reasonable attorneys' fees and expenses. The application of the
United Nations Convention on Contracts for the International Sale
of Goods is expressly excluded. Any law or regulation which
provides that the language of a contract shall be construed
against the drafter shall not apply to this License. You agree
that You alone are responsible for compliance with the United
States export administration regulations (and the export control
laws and regulation of any other countries) when You use,
distribute or otherwise make available any Covered Software.
10. RESPONSIBILITY FOR CLAIMS.
As between Initial Developer and the Contributors, each party is
responsible for claims and damages arising, directly or
indirectly, out of its utilization of rights under this License
and You agree to work with Initial Developer and Contributors to
distribute such responsibility on an equitable basis. Nothing
herein is intended or shall be deemed to constitute any admission
of liability.
--------------------------------------------------------------------
NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND
DISTRIBUTION LICENSE (CDDL)
For Covered Software in this distribution, this License shall
be governed by the laws of England and Wales (excluding
conflict-of-law provisions). Any disputes arising here from
shall be exclusively subject to the juristiction of the courts
of England and Wales.
/* (1.50)
*
* This file is automatically maintained by srccommit, do not edit manually.
*
*/
#define Module_MajorVersion_CMHG 1.50
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 31 Jan 2023
#define Module_MajorVersion "1.50"
#define Module_Version 150
#define Module_MinorVersion ""
#define Module_Date "31 Jan 2023"
#define Module_ApplicationDate "31-Jan-23"
#define Module_ComponentName "SparkARJ"
#define Module_FullVersion "1.50"
#define Module_HelpVersion "1.50 (31 Jan 2023)"
#define Module_LibraryVersionInfo "1:50"
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "Licence").
* You may not use this file except in compliance with the Licence.
*
* You can obtain a copy of the licence at
* RiscOS/Sources/FileSys/ImageFS/SparkFS/Codecs/SparkARJ/LICENCE.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the Licence file. If applicable, add the
* following below this CDDL HEADER, with the fields enclosed by
* brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1992 David Pilling. All rights reserved.
* Use is subject to license terms.
*/
/*->c.arcs */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "h.kernel"
#include "h.swis"
#include "^.Shared.h.zflex"
#include "$.SparkFS.h.common"
#include "^.Shared.h.sfs"
#include "^.Shared.h.sarcfs"
#include "^.Shared.h.zbuffer"
#include "^.Shared.h.err"
#include "h.convert"
#include "h.cat"
#include "h.arcs"
#include "h.unpack"
#include "h.pack"
#include "h.arj"
/*****************************************************************************/
static _kernel_oserror * openarcdatafile(archive * arc,int fn)
{
_kernel_oserror * err;
err=openarc(arc,'r');
return(err);
}
static _kernel_oserror * closearcdatafile(archive * arc)
{
_kernel_oserror * err;
err=closearc(arc);
return(err);
}
/****************************************************************************/
/* sequence should be */
/* 1 ensure enough memory for decompression code */
/* 2 ensure enough memory for destination */
/* 3 ensure enough memory for source */
/* output can be one of two things */
/* 1 output to a fixed memory address */
/* 2 output to a filestructure */
static char bitsbyte;
#define XMEM 1
#define XFILE 2
_kernel_oserror * loadfile(linkblock * linkb)
{
_kernel_oserror * err;
int sfh;
int dfh;
char * srcbuffer;
char * destbuffer;
buffer srcb;
buffer destb;
int dlen;
int slen;
archive * arc;
int fn;
arc =linkb->openload.arc;
fn =linkb->openload.fn;
slen=linkb->loadfile.slen;
dlen=linkb->loadfile.dlen;
dfh =linkb->loadfile.dfh;
srcbuffer=linkb->loadfile.src;
destbuffer=linkb->loadfile.dest;
sfh=arc->fh;
if(arc->hdr[fn].hdrver!=0)
{
initbuff(&srcb,srcbuffer,arc->hdr[fn].size,slen,sfh);
srcb.flags=BCODE;
err=initsrcbuffer(&srcb);
if(!err)
{
initbuff(&destb,destbuffer,arc->hdr[fn].length,dlen,dfh);
if(!err) err=unpack(arc,fn,&srcb,&destb);
}
}
else
{
if(!dfh)
{
err=readblock(&linkb->loadfile.dest,sfh,arc->hdr[fn].length,
COPYCRC|COPYDECODE);
}
else
{
err=copyfile(sfh,dfh,arc->hdr[fn].length,COPYCRC|COPYDECODE);
}
}
return(err);
}
_kernel_oserror * openload(linkblock * linkb)
{
_kernel_oserror * err;
archive * arc;
int fn;
arc=linkb->openload.arc;
fn =linkb->openload.fn;
err=openarcdatafile(arc,fn);
if(!err)
{
err=lineupdata(arc,fn);
if(!err) err=openunpack(arc,fn);
if(err) closearcdatafile(arc);
}
linkb->openload.slen=arc->hdr[fn].size;
linkb->openload.dlen=arc->hdr[fn].length;
return(err);
}
_kernel_oserror * closeload(linkblock * linkb)
{
_kernel_oserror * err;
archive * arc;
int fn;
arc=linkb->closeload.arc;
fn =linkb->closeload.fn;
closeunpack();
err=closearcdatafile(arc);
return(err);
}
/*****************************************************************************/
/* save chunk of memory, dest is file handle to write it to */
static _kernel_oserror * savearcfilesub(heads * hdr,int sfh,char * start)
{
_kernel_oserror * err;
int dest;
char * srcbuff;
char * destbuff;
buffer srcb;
buffer destb;
int sbsize;
int dbsize;
srcbuff=destbuff=NULL;
setcode();
if(hdr->hdrver==0)
{
err=open(arcpath,'w',&dest);
/* writefilehdr(dest,hdr->hdrver,hdr->name); */
if(start)
{
srcbuff=start;
err=writeblock(&start,dest,hdr->length,COPYCRC|COPYCODE);
}
else
{
err=copyfile(sfh,dest,hdr->length,COPYCRC|COPYCODE);
}
hdr->crc=copycrc;
hdr->size=copylen;
if(!err) err=close(dest);
else close(dest);
}
else
{
err=buff_alloc((flex_ptr)&destbuff,DEFPACKSIZE,&dbsize);
if(!err) err=openpack(cxmethod,cxbits);
if(!err)
{
err=open(arcpath,'w',&dest);
if(!err)
{
if(!err)
{
if(start)
{
srcbuff=start;
initbuff(&srcb,srcbuff,hdr->length,hdr->length,0);
}
else
{
err=buff_alloc((flex_ptr)&srcbuff,DEFPACKSIZE,&sbsize);
if(!err) initbuff(&srcb,srcbuff,hdr->length,sbsize,sfh);
}
if(!err)
{
srcb.flags=BCRC;
initsrcbuffer(&srcb);
initbuff(&destb,destbuff,-1,dbsize,dest);
destb.flags=BCODE;
/* writefilehdr(dest,hdr->hdrver,hdr->name); */
err=pack(hdr,&srcb,&destb);
hdr->crc=srcb.crc;
if(!start) flex_free((flex_ptr)&srcbuff);
}
}
if(!err) err=close(dest);
else close(dest);
}
deb("closepack");
closepack();
}
if(destbuff) {flex_free((flex_ptr)&destbuff);deb("free destbuff");}
}
closecode();
return(err);
}
_kernel_oserror * savefile(linkblock * linkb)
{
_kernel_oserror * err;
archive * arc;
heads * hdr;
int ins;
int ind;
int ow;
int sfh;
char * start;
int nx;
arc=linkb->savefile.arc;
hdr=linkb->savefile.hdr;
ins=linkb->savefile.ins;
ind=linkb->savefile.ind;
ow =linkb->savefile.ow;
sfh=linkb->savefile.sfh;
start=linkb->savefile.src;
if(ow) nx=arc->hdr[ins].fp;
/* else nx=nextfilenumber(arc); */
/* err=checkpath(arc->name,nx,!ow); */
if(!err)
{ /* first try to compress the file */
hdr->hdrver=cxmethod|128;
err=savearcfilesub(hdr,sfh,start);
if(!err)
{ /* now see if compression suceeded */
if(hdr->size>hdr->length && ((cxmethod & 0x7F)!=0)) /* failed */
{ /* so have a go at just storing */
hdr->hdrver=0|128;
err=savearcfilesub(hdr,sfh,start);
}
}
if(!ow) err=insentry(arc,ins,ind,1);
if(!err)
{
hdr->fp=nx;
arc->hdr[ins]=*hdr;
/* err=writesp2cat(arc->name,arc,ow?ins:-1); */
}
}
return(err);
}
_kernel_oserror * opensave(linkblock * linkb)
{
_kernel_oserror * err;
linkb=linkb;
err=NULL;
return(err);
}
_kernel_oserror * closesave(linkblock * linkb)
{
_kernel_oserror * err;
linkb=linkb;
err=NULL;
return(err);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "Licence").
* You may not use this file except in compliance with the Licence.
*
* You can obtain a copy of the licence at
* RiscOS/Sources/FileSys/ImageFS/SparkFS/Codecs/SparkARJ/LICENCE.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the Licence file. If applicable, add the
* following below this CDDL HEADER, with the fields enclosed by
* brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1992 David Pilling. All rights reserved.
* Use is subject to license terms.
*/
/*->c.arjcat */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include "h.kernel"
#include "h.swis"
#include "^.Shared.h.zflex"
#include "$.SparkFS.h.common"
#include "^.Shared.h.sfs"
#include "^.Shared.h.sarcfs"
#include "^.Shared.h.zbuffer"
#include "^.Shared.h.zmsdos"
#include "^.Shared.h.zfile"
#include "^.Shared.h.err"
#include "h.arcs"
#include "h.convert"
#include "h.arj"
#include "h.arjint"
/*****************************************************************************/
#define get_crc() get_longword()
#define fget_crc(f) fget_longword(f)
#define setup_get(PTR) (get_ptr = (PTR))
#define get_byte() ((uchar)(*get_ptr++ & 0xff))
UCRC crc;
ushort bitbuf;
long compsize;
long origsize;
uchar subbitbuf;
uchar header[HEADERSIZE_MAX];
char arc_name[FNAME_MAX];
int bitcount;
int file_type;
static char * hdr_filename;
static char * hdr_comment;
static ushort headersize;
static uchar first_hdr_size;
static uchar arj_nbr;
static uchar arj_x_nbr;
static uchar host_os;
static uchar arj_flags;
static short amethod;
static uint file_mode;
static ulong time_stamp;
static short entry_pos;
static ushort host_data;
static uchar *get_ptr;
static UCRC file_crc;
static UCRC header_crc;
static _kernel_oserror * xskip(archive * arc)
{
return(seekrelarc(arc,(int)compsize));
}
static int fget_byte(archive * arc)
{
int temp;
temp=0;
readarc(arc,&temp,1);
return(temp);
}
static uint fget_word(archive * arc)
{
int b0;
int b1;
b0=fget_byte(arc);
b1=fget_byte(arc);
return((b1<<8)+b0);
}
static ulong fget_longword(archive * arc)
{
ulong b0, b1, b2, b3;
b0 = fget_byte(arc);
b1 = fget_byte(arc);
b2 = fget_byte(arc);
b3 = fget_byte(arc);
return (b3 << 24) + (b2 << 16) + (b1 << 8) + b0;
}
static uint get_word(void)
{
uint b0, b1;
b0 = get_byte();
b1 = get_byte();
return (b1 << 8) + b0;
}
static ulong get_longword(void)
{
ulong b0, b1, b2, b3;
b0 = get_byte();
b1 = get_byte();
b2 = get_byte();
b3 = get_byte();
return (b3 << 24) + (b2 << 16) + (b1 << 8) + b0;
}
static void fread_crc(uchar * p,int n,archive * arc)
{
readarc(arc,p,n);
origsize += n;
/* crc_buf((char *)p, n); */
}
static _kernel_oserror * read_header(archive * arc,int * iseof)
{
_kernel_oserror * err;
ushort extheadersize;
ushort header_id;
err=NULL;
header_id=fget_word(arc);
if(header_id!=HEADER_ID) err=geterror(mb_sfserr_BadArc);
else
{
headersize=fget_word(arc);
if(headersize==0)
{
*iseof=1;
return(err);
}
if(headersize>HEADERSIZE_MAX) err=geterror(mb_sfserr_BadArc);
else
{
crc=CRC_MASK;
fread_crc(header,(int)headersize,arc);
header_crc=fget_crc(arc);
/* if((crc^CRC_MASK)!=header_crc) err=geterror(mb_sfserr_BadArc);
else */
{
setup_get(header);
first_hdr_size=get_byte();
arj_nbr=get_byte();
arj_x_nbr=get_byte();
host_os=get_byte();
arj_flags=get_byte();
amethod=get_byte();
file_type=get_byte();
(void)get_byte();
time_stamp=get_longword();
compsize=get_longword();
origsize=get_longword();
file_crc=get_crc();
entry_pos=get_word();
file_mode=get_word();
host_data=get_word();
hdr_filename=(char *)&header[first_hdr_size];
hdr_comment=(char *)&header[first_hdr_size+strlen(hdr_filename)+1];
/* if extheadersize == 0 then no CRC */
/* otherwise read extheader data and read 4 bytes for CRC */
while((extheadersize=fget_word(arc))!=0)
{
err=seekrelarc(arc,extheadersize+4);
if(err) break;
}
}
}
}
return(err);
}
_kernel_oserror * listhdrs(archive * arc)
{
_kernel_oserror * err;
int eof;
int fn;
int fpos;
int time;
int date;
eof=0;
err=NULL;
while(!eof)
{
err=tellarc(arc,&fpos);
if(err) break;
err=read_header(arc,&eof);
if(err) break;
if(eof) break;
if(file_type!=2)
{
err=addzhdr(arc,hdr_filename,&fn);
if(err) break;
arc->hdr[fn].fp=fpos;
arc->hdr[fn].size=(int)compsize;
arc->hdr[fn].length=(int)origsize;
arc->hdr[fn].dirn=-1;
date=(unsigned short)(time_stamp>>16);
time=(unsigned short)(time_stamp);
genloadexec(arc,fn,date,time);
arc->hdr[fn].acc=DEFATT;
arc->hdr[fn].load|=extype(hdr_filename)<<8;
arc->hdr[fn].crc=(int)file_crc;
arc->hdr[fn].hdrver=amethod;
err=xskip(arc);
if(err) break;
}
}
return(err);
}
_kernel_oserror * lineupdata(archive * arc,int fn)
{
_kernel_oserror * err;
heads * ahdr;
int sfh;
int eof;
err=NULL;
ahdr=&arc->hdr[fn];
sfh=arc->fh;
err=seek(sfh,ahdr->fp);
eof=0;
err=read_header(arc,&eof);
return(err);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "Licence").
* You may not use this file except in compliance with the Licence.
*
* You can obtain a copy of the licence at
* RiscOS/Sources/FileSys/ImageFS/SparkFS/Codecs/SparkARJ/LICENCE.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the Licence file. If applicable, add the
* following below this CDDL HEADER, with the fields enclosed by
* brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1992 David Pilling. All rights reserved.
* Use is subject to license terms.
*/
/*->c.cat */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include "h.kernel"
#include "h.swis"
#include "^.Shared.h.zflex"
#include "$.SparkFS.h.common"
#include "^.Shared.h.sfs"
#include "^.Shared.h.sarcfs"
#include "^.Shared.h.zbuffer"
#include "^.Shared.h.zmsdos"
#include "^.Shared.h.zfile"
#include "^.Shared.h.err"
#include "h.arcs"
#include "h.convert"
#include "h.arj"
#include "h.cat"
char arcpath[256];
char arcname[256];
/****************************************************************************/
_kernel_oserror * setnofiles(archive * arc,int n)
{
_kernel_swi_regs rx;
rx.r[0]=UTILSETNO;
rx.r[1]=(int)arc;
rx.r[2]=n;
return(_kernel_swi(UTILSWI,&rx,&rx));
}
_kernel_oserror * insentry(archive * arc,int fn,int ind,int size)
{
_kernel_swi_regs rx;
rx.r[0]=UTILINS;
rx.r[1]=(int)arc;
rx.r[2]=fn;
rx.r[3]=ind;
rx.r[4]=size;
return(_kernel_swi(UTILSWI,&rx,&rx));
}
void rementry(archive * arc,int fn,int size)
{
_kernel_swi_regs rx;
rx.r[0]=UTILREM;
rx.r[1]=(int)arc;
rx.r[2]=fn;
rx.r[3]=0;
rx.r[4]=size;
_kernel_swi(UTILSWI,&rx,&rx);
}
/*****************************************************************************/
/* load the catalogue for an archive */
_kernel_oserror * loadcat(archive * arc)
{
_kernel_oserror * err;
err=openarc(arc,'r');
if(!err)
{
err=initzhdrs(arc,ZDEFN,ZDEFSTR);
if(!err)
{
err=listhdrs(arc);
if(!err)
{
err=generatezfile(arc);
}
trashzhdrs();
}
if(err) closearc(arc);
else err=closearc(arc);
}
return(err);
}
_kernel_oserror * loadarchive(linkblock * linkb)
{
int i;
_kernel_oserror * err;
archive * arc;
arc =linkb->loadcat.arc;
i=fexistsarc(arc);
if(i==1 || i==3)
{
arc->type=ARJ;
arc->ro=1;
err=loadcat(arc);
}
else
{
err=geterror(mb_sfserr_NotFound);
}
if(!err) err=setstamparc(arc);
return(err);
}
_kernel_oserror * validate(linkblock * block)
{
_kernel_oserror * err;
archive * arc;
fstat f;
int code;
err=NULL;
arc=block->validate.arc;
code=fexistsarc(arc);
if(code)
{
if(code!=1 && code!=3) block->validate.ok=0;
else
{
err=statarc(arc,&f);
if(!err)
{
block->validate.ok=(f.exec==arc->timelo) && ((f.load & 0xFF)==arc->timehi);
}
}
}
else err=geterror(mb_sfserr_NotFound);
return(err);
}
_kernel_oserror * diropen(linkblock * block)
{
_kernel_oserror * err;
err=NULL;
return(err);
}
/* update given catalogue entry */
_kernel_oserror * updatecat(archive * arc,int fn)
{
_kernel_oserror * err;
err=NULL;
return(err);
}
_kernel_oserror * deletefile(linkblock * linkb)
{
_kernel_oserror * err;
archive * arc;
int fn;
int oldnum;
int maxnum;
err=NULL;
arc=linkb->deletefile.arc;
fn =linkb->deletefile.fn;
switch(arc->type)
{
}
return(err);
}
_kernel_oserror * createfile(linkblock * linkb)
{
_kernel_oserror * err;
archive * arc;
heads * hdr;
int ins;
int ind;
int ow;
int nx;
int dest;
err=NULL;
arc=linkb->createdir.arc;
hdr=linkb->createdir.hdr;
ins=linkb->createdir.ins;
ind=linkb->createdir.ind;
ow =linkb->createdir.ow;
switch(arc->type)
{
}
return(err);
}
_kernel_oserror * createdir(linkblock * linkb)
{
_kernel_oserror * err;
archive * arc;
heads * hdr;
int ins;
int ind;
int ow;
err=NULL;
arc=linkb->createdir.arc;
hdr=linkb->createdir.hdr;
ins=linkb->createdir.ins;
ind=linkb->createdir.ind;
ow =linkb->createdir.ow;
switch(arc->type)
{
}
return(err);
}
_kernel_oserror * renamex(linkblock * linkb)
{
_kernel_oserror * err;
archive * arc;
int fn1;
int fn2;
int ind;
int size;
char * name;
int i;
err=NULL;
arc =linkb->rename.arc;
fn1 =linkb->rename.fn1;
fn2 =linkb->rename.fn2;
ind =linkb->rename.ind;
size=linkb->rename.size;
name=linkb->rename.name;
switch(arc->type)
{
}
return(err);
}
_kernel_oserror * archiveflush(linkblock * block)
{
block=block;
return(NULL);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "Licence").
* You may not use this file except in compliance with the Licence.
*
* You can obtain a copy of the licence at
* RiscOS/Sources/FileSys/ImageFS/SparkFS/Codecs/SparkARJ/LICENCE.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the Licence file. If applicable, add the
* following below this CDDL HEADER, with the fields enclosed by
* brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1992 David Pilling. All rights reserved.
* Use is subject to license terms.
*/
/*->c.convert */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "h.kernel"
#include "h.swis"
#include "^.Shared.h.zflex"
#include "$.SparkFS.h.common"
#include "^.Shared.h.sfs"
#include "^.Shared.h.zbuffer"
#include "$.SparkFS.FS.h.RMInfo"
#include "^.Shared.h.sinterface"
#include "^.Shared.h.err"
#include "h.arcs"
#include "h.unpack"
#include "h.pack"
#include "h.cat"
#include "h.convert"
/*****************************************************************************/
_kernel_oserror * create(linkblock * block)
{
_kernel_oserror * err;
archive * arc;
int type;
char * p;
char * name;
err=NULL;
arc=block->create.arc;
name=arc->name;
type=arc->type;
switch(type)
{
}
return(err);
}
/* global variables */
int cxmethod=0;
int cxbits=0;
int cxcode=0;
char cxpassword[32];
_kernel_oserror * method(linkblock * block)
{
_kernel_oserror * err;
int method;
method=block->method.compressiontype;
err=NULL;
return(err);
}
_kernel_oserror * info(linkblock * block)
{
_kernel_oserror * err;
block->info.archivetypes=archivetypes;
block->info.compressiontypes=compressiontypes;
block->info.codetypes=codetypes;
block->info.conversiontypes=conversiontypes;
block->info.modulebase=(char*)Image_RO_Base;
err=NULL;
return(err);
}
_kernel_oserror * convert(linkblock * block)
{
_kernel_oserror * err;
err=NULL;
block=block;
return(err);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "Licence").
* You may not use this file except in compliance with the Licence.
*
* You can obtain a copy of the licence at
* RiscOS/Sources/FileSys/ImageFS/SparkFS/Codecs/SparkARJ/LICENCE.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the Licence file. If applicable, add the
* following below this CDDL HEADER, with the fields enclosed by
* brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1992 David Pilling. All rights reserved.
* Use is subject to license terms.
*/
/*->c.main */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <ctype.h>
#include <time.h>
#include <locale.h>
#include "h.kernel"
#include "h.swis"
#include "^.Shared.h.zflex"
#include "$.SparkFS.h.common"
#include "^.Shared.h.sfs"
#include "^.Shared.h.zbuffer"
#include "^.Shared.h.sinterface"
#include "^.Shared.h.err"
#include "h.arcs"
#include "h.cat"
#include "h.convert"
#include "h.main"
/****************************************************************************/
static flink link=
{
veneer_updatecat,
veneer_loadarchive,
veneer_deletefile,
veneer_createdir,
veneer_createfile,
veneer_loadfile,
veneer_savefile,
veneer_opensave,
veneer_closesave,
veneer_openload,
veneer_closeload,
veneer_rename,
veneer_create,
veneer_convert,
veneer_info,
veneer_method,
veneer_validate,
veneer_diropen,
veneer_flush
};
static void ARJ_finalise(void)
{
_kernel_swi_regs rx;
rx.r[0]=REMLINK;
rx.r[1]=(int)&link;
_kernel_swi(LINKSWI,&rx,&rx);
}
static _kernel_oserror * initlink(void * pw)
{
_kernel_oserror * err;
_kernel_swi_regs rx;
rx.r[0]=ADDLINK;
rx.r[1]=(int)&link;
rx.r[2]=(int)pw;
rx.r[3]=COMPATIBLE;
err=_kernel_swi(LINKSWI,&rx,&rx);
return(err);
}
_kernel_oserror * ARJ_initialise(char * cmd_tail,int podule_base,void * pw)
{
_kernel_oserror * err;
cmd_tail=NULL;
podule_base=0;
err=initlink(pw);
atexit(ARJ_finalise);
return(NULL);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "Licence").
* You may not use this file except in compliance with the Licence.
*
* You can obtain a copy of the licence at
* RiscOS/Sources/FileSys/ImageFS/SparkFS/Codecs/SparkARJ/LICENCE.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the Licence file. If applicable, add the
* following below this CDDL HEADER, with the fields enclosed by
* brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1992 David Pilling. All rights reserved.
* Use is subject to license terms.
*/
/*->c.pack */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "h.kernel"
#include "h.swis"
#include "^.Shared.h.zflex"
#include "$.SparkFS.h.common"
#include "^.Shared.h.zbuffer"
#include "^.Shared.h.sfs"
#include "^.Shared.h.err"
#include "h.convert"
#include "h.cat"
#include "h.arcs"
#include "h.unpack"
#include "h.pack"
void closepack(void)
{
}
_kernel_oserror * openpack(int method,int bits)
{
_kernel_oserror * err;
err=NULL;
return(err);
}
_kernel_oserror * pack(heads * hdr,buffer * src,buffer * dest)
{
_kernel_oserror * err;
err=NULL;
return(err);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "Licence").
* You may not use this file except in compliance with the Licence.
*
* You can obtain a copy of the licence at
* RiscOS/Sources/FileSys/ImageFS/SparkFS/Codecs/SparkARJ/LICENCE.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the Licence file. If applicable, add the
* following below this CDDL HEADER, with the fields enclosed by
* brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1992 David Pilling. All rights reserved.
* Use is subject to license terms.
*/
/*->c.unpack */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "h.kernel"
#include "h.swis"
#include "^.Shared.h.zflex"
#include "$.SparkFS.h.common"
#include "^.Shared.h.sfs"
#include "^.Shared.h.zbuffer"
#include "^.Shared.h.zmsdos"
#include "^.Shared.h.zfile"
#include "^.Shared.h.err"
#include "h.convert"
#include "h.cat"
#include "h.arcs"
#include "h.arj"
#include "h.arjint"
#include "h.unpack"
/*****************************************************************************/
#define UCHAR_MAX (255)
#define CHAR_BIT (8)
#define THRESHOLD 3
#define DDICSIZ 26624
#define MAXDICBIT 16
#define MATCHBIT 8
#define MAXMATCH 256
#define NC (UCHAR_MAX + MAXMATCH + 2 - THRESHOLD)
#define NP (MAXDICBIT + 1)
#define CBIT 9
#define NT (CODE_BIT + 3)
#define PBIT 5
#define TBIT 5
#if NT > NP
#define NPT NT
#else
#define NPT NP
#endif
#define CTABLESIZE 4096
#define STRTP 9
#define STOPP 13
#define STRTL 0
#define STOPL 7
/* Local variables */
static uchar *text = NULL;
static short getlen;
static short getbuf;
static ushort * left;
static ushort * right;
static uchar * c_len;
static uchar * pt_len;
static ushort * c_table;
static ushort * pt_table;
static ushort blocksize;
static buffer * dest;
static buffer * src;
static void fwrite_txt_crc(uchar * text,int r)
{
dumpblock(dest,(char*)text,r);
}
static int getc_unp(buffer * src)
{
if(src->p<src->end) return(*src->p++);
else
{
fillsrcbuffer(src);
if(src->p<src->end) return(*src->p++);
else return(EOF);
}
}
static void fillbuf(int n) /* Shift bitbuf n bits left, read n bits */
{
bitbuf = (bitbuf << n) & 0xFFFF; /* lose the first n bits */
while(n>bitcount)
{
bitbuf |= subbitbuf << (n -= bitcount);
if (compsize != 0)
{
compsize--;
subbitbuf = (uchar) getc_unp(src);
}
else
subbitbuf = 0;
bitcount = CHAR_BIT;
}
bitbuf |= subbitbuf >> (bitcount -= n);
}
static void init_getbits()
{
bitbuf = 0;
subbitbuf = 0;
bitcount = 0;
fillbuf(2 * CHAR_BIT);
}
static ushort getbits(int n)
{
ushort x;
x=bitbuf>>(2*CHAR_BIT-n);
fillbuf(n);
return(x);
}
/* Huffman decode routines */
static void make_table(int nchar,uchar * bitlen,int tablebits,ushort * table)
{
ushort count[17], weight[17], start[18], *p;
uint i, k, len, ch, jutbits, avail, nextcode, mask;
for (i = 1; i <= 16; i++)
count[i] = 0;
for (i = 0; (int)i < nchar; i++)
count[bitlen[i]]++;
start[1] = 0;
for (i = 1; i <= 16; i++)
start[i + 1] = start[i] + (count[i] << (16 - i));
if (start[17] != (ushort) (1 << 16)) return;
/* error(M_BADTABLE, ""); */
jutbits = 16 - tablebits;
for (i = 1; (int)i <= tablebits; i++)
{
start[i] >>= jutbits;
weight[i] = 1 << (tablebits - i);
}
while (i <= 16)
{
weight[i] = 1 << (16 - i);
i++;
}
i = start[tablebits + 1] >> jutbits;
if (i != (ushort) (1 << 16))
{
k = 1 << tablebits;
while (i != k)
table[i++] = 0;
}
avail = nchar;
mask = 1 << (15 - tablebits);
for (ch = 0; (int)ch < nchar; ch++)
{
if ((len = bitlen[ch]) == 0)
continue;
k = start[len];
nextcode = k + weight[len];
if ((int)len <= tablebits)
{
for (i = start[len]; i < nextcode; i++)
table[i] = ch;
}
else
{
p = &table[k >> jutbits];
i = len - tablebits;
while (i != 0)
{
if (*p == 0)
{
right[avail] = left[avail] = 0;
*p = avail++;
}
if (k & mask)
p = &right[*p];
else
p = &left[*p];
k <<= 1;
i--;
}
*p = ch;
}
start[len] = nextcode;
}
}
static void read_pt_len(int nn,int nbit,int i_special)
{
int i, n;
short c;
ushort mask;
n = getbits(nbit);
if (n == 0)
{
c = getbits(nbit);
for (i = 0; i < nn; i++)
pt_len[i] = 0;
for (i = 0; i < 256; i++)
pt_table[i] = c;
}
else
{
i = 0;
while (i < n)
{
c = bitbuf >> (13);
if (c == 7)
{
mask = 1 << (12);
while (mask & bitbuf)
{
mask >>= 1;
c++;
}
}
fillbuf((c < 7) ? 3 : (int)(c - 3));
pt_len[i++] = (uchar)c;
if (i == i_special)
{
c = getbits(2);
while (--c >= 0)
pt_len[i++] = 0;
}
}
while (i < nn)
pt_len[i++] = 0;
make_table(nn, pt_len, 8, pt_table);
}
}
static void read_c_len(void)
{
short i, c, n;
ushort mask;
n = getbits(CBIT);
if (n == 0)
{
c = getbits(CBIT);
for (i = 0; i < NC; i++)
c_len[i] = 0;
for (i = 0; i < CTABLESIZE; i++)
c_table[i] = c;
}
else
{
i = 0;
while (i < n)
{
c = pt_table[bitbuf >> (8)];
if (c >= NT)
{
mask = 1 << (7);
do
{
if (bitbuf & mask)
c = right[c];
else
c = left[c];
mask >>= 1;
} while (c >= NT);
}
fillbuf((int)(pt_len[c]));
if (c <= 2)
{
if (c == 0)
c = 1;
else if (c == 1)
c = getbits(4) + 3;
else
c = getbits(CBIT) + 20;
while (--c >= 0)
c_len[i++] = 0;
}
else
c_len[i++] = (uchar)(c - 2);
}
while (i < NC)
c_len[i++] = 0;
make_table(NC, c_len, 12, c_table);
}
}
static ushort decode_c(void)
{
ushort j, mask;
if (blocksize == 0)
{
blocksize = getbits(16);
read_pt_len(NT, TBIT, 3);
read_c_len();
read_pt_len(NP, PBIT, -1);
}
blocksize--;
j = c_table[bitbuf >> 4];
if (j >= NC)
{
mask = 1 << (3);
do
{
if (bitbuf & mask)
j = right[j];
else
j = left[j];
mask >>= 1;
} while (j >= NC);
}
fillbuf((int)(c_len[j]));
return j;
}
static ushort decode_p(void)
{
ushort j, mask;
j = pt_table[bitbuf >> (8)];
if (j >= NP)
{
mask = 1 << (7);
do
{
if (bitbuf & mask)
j = right[j];
else
j = left[j];
mask >>= 1;
} while (j >= NP);
}
fillbuf((int)(pt_len[j]));
if (j != 0)
{
j--;
j = (1 << j) + getbits((int)j);
}
return j;
}
static void
decode_start()
{
blocksize = 0;
init_getbits();
}
static void decode(void)
{
short i;
short j;
short c;
short r;
long count;
decode_start();
count = 0;
r = 0;
while (count < origsize)
{
if ((c = decode_c()) <= UCHAR_MAX)
{
text[r] = (uchar) c;
count++;
if (++r >= DDICSIZ)
{
r = 0;
fwrite_txt_crc(text, DDICSIZ);
}
}
else
{
j = c - (UCHAR_MAX + 1 - THRESHOLD);
count += j;
i = decode_p();
if ((i = r - i - 1) < 0)
i += DDICSIZ;
if (r > i && r < DDICSIZ - MAXMATCH - 1)
{
while (--j >= 0)
text[r++] = text[i++];
}
else
{
while (--j >= 0)
{
text[r] = text[i];
if (++r >= DDICSIZ)
{
r = 0;
fwrite_txt_crc(text, DDICSIZ);
}
if (++i >= DDICSIZ)
i = 0;
}
}
}
}
if (r != 0)
fwrite_txt_crc(text, r);
}
/* Macros */
#define BFIL {getbuf|=bitbuf>>getlen;fillbuf(CODE_BIT-getlen);getlen=CODE_BIT;}
#define GETBIT(c) {if(getlen<=0)BFIL c=(getbuf&0x8000)!=0;getbuf<<=1;getlen--;}
#define BPUL(l) {getbuf<<=l;getlen-=l;}
#define GETBITS(c,l) {if(getlen<l)BFIL c=(ushort)getbuf>>(CODE_BIT-l);BPUL(l)}
static short
decode_ptr()
{
short c;
short width;
short plus;
short pwr;
plus = 0;
pwr = 1 << (STRTP);
for (width = (STRTP); width < (STOPP) ; width++)
{
GETBIT(c);
if (c == 0)
break;
plus += pwr;
pwr <<= 1;
}
if (width != 0)
GETBITS(c, width);
c += plus;
return c;
}
static short
decode_len()
{
short c;
short width;
short plus;
short pwr;
plus = 0;
pwr = 1 << (STRTL);
for (width = (STRTL); width < (STOPL) ; width++)
{
GETBIT(c);
if (c == 0)
break;
plus += pwr;
pwr <<= 1;
}
if (width != 0)
GETBITS(c, width);
c += plus;
return c;
}
static void decode_f(void)
{
short i;
short j;
short c;
short r;
short pos;
long count;
init_getbits();
getlen = getbuf = 0;
count = 0;
r = 0;
while (count < origsize)
{
c = decode_len();
if (c == 0)
{
GETBITS(c, CHAR_BIT);
text[r] = (uchar)c;
count++;
if (++r >= DDICSIZ)
{
r = 0;
fwrite_txt_crc(text, DDICSIZ);
}
}
else
{
j = c - 1 + THRESHOLD;
count += j;
pos = decode_ptr();
if ((i = r - pos - 1) < 0)
i += DDICSIZ;
while (j-- > 0)
{
text[r] = text[i];
if (++r >= DDICSIZ)
{
r = 0;
fwrite_txt_crc(text, DDICSIZ);
}
if (++i >= DDICSIZ)
i = 0;
}
}
}
if (r != 0)
fwrite_txt_crc(text, r);
}
/*****************************************************************************/
void closeunpack(void)
{
if(text) flex_free((flex_ptr)&text);
if(c_table) flex_free((flex_ptr)&c_table);
if(pt_table) flex_free((flex_ptr)&pt_table);
if(left) flex_free((flex_ptr)&left);
if(right) flex_free((flex_ptr)&right);
if(c_len) flex_free((flex_ptr)&c_len);
if(pt_len) flex_free((flex_ptr)&pt_len);
}
_kernel_oserror * openunpack(archive * arc,int fn)
{
_kernel_oserror * err;
err=NULL;
if(arc->hdr[fn].hdrver)
{
err=flex_alloc((flex_ptr)&text,DDICSIZ);
if(!err) err=flex_alloc((flex_ptr)&c_table,CTABLESIZE*sizeof(*c_table));
if(!err) err=flex_alloc((flex_ptr)&pt_table,256*sizeof(*pt_table));
if(!err) err=flex_alloc((flex_ptr)&left,(2*NC-1)*sizeof(*left));
if(!err) err=flex_alloc((flex_ptr)&right,(2*NC-1)*sizeof(*right));
if(!err) err=flex_alloc((flex_ptr)&c_len,NC*sizeof(*c_len));
if(!err) err=flex_alloc((flex_ptr)&pt_len,NPT*sizeof(*pt_len));
if(err) closeunpack();
}
return(err);
}
_kernel_oserror * unpack(archive * arc,int fn,buffer * xsrc,buffer * xdest)
{
_kernel_oserror * err;
err=NULL;
src=xsrc;
dest=xdest;
crc=CRC_MASK;
switch(arc->hdr[fn].hdrver)
{
case 1:
case 2:
case 3:
decode();
break;
case 4:
decode_f();
break;
default:
err=geterror(mb_sfserr_NonMethod);
break;
}
if(!err) err=dumpdestbuffer(dest);
/* if ((crc ^ CRC_MASK) == file_crc) printf(M_CRCOK); */
return(err);
}
;
; CDDL HEADER START
;
; The contents of this file are subject to the terms of the
; Common Development and Distribution License (the "Licence").
; You may not use this file except in compliance with the Licence.
;
; You can obtain a copy of the licence at
; RiscOS/Sources/FileSys/ImageFS/SparkFS/Codecs/SparkARJ/LICENCE.
; See the Licence for the specific language governing permissions
; and limitations under the Licence.
;
; When distributing Covered Code, include this CDDL HEADER in each
; file and include the Licence file. If applicable, add the
; following below this CDDL HEADER, with the fields enclosed by
; brackets "[]" replaced with your own identifying information:
; Portions Copyright [yyyy] [name of copyright owner]
;
; CDDL HEADER END
;
; Copyright 1992 David Pilling. All rights reserved.
; Use is subject to license terms.
;
;->cmhg.ARJ
;
initialisation-code: ARJ_initialise
; service-call-handler: ARJ_service
title-string: ARJ
help-string: ARJ 1.50
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "Licence").
* You may not use this file except in compliance with the Licence.
*
* You can obtain a copy of the licence at
* RiscOS/Sources/FileSys/ImageFS/SparkFS/Codecs/SparkARJ/LICENCE.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the Licence file. If applicable, add the
* following below this CDDL HEADER, with the fields enclosed by
* brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1992 David Pilling. All rights reserved.
* Use is subject to license terms.
*/
/*->h.arcs */
#define CXNONE 0
#define CXCRUNCH 8
#define CXSQUASH 9
#define CXCOMPRESS 127
#define CXCOMPRESSZ 128
#define GARBLE 1
#define DESCODE 2
extern void initbuff(buffer * b,char * data,int len,int size,int fh);
extern _kernel_oserror * loadarcfile(archive * arc,int fn,int fs,char * dest);
extern _kernel_oserror * savearcfile(archive * arc,
heads * hdr,int fs,char * start);
extern _kernel_oserror * loadfile(linkblock * linkb);
extern _kernel_oserror * loadfile(linkblock * linkb);
extern _kernel_oserror * savefile(linkblock * linkb);
extern _kernel_oserror * opensave(linkblock * linkb);
extern _kernel_oserror * closesave(linkblock * linkb);
extern _kernel_oserror * openload(linkblock * linkb);
extern _kernel_oserror * closeload(linkblock * linkb);
extern _kernel_oserror * lineupdata(archive * arc,int fn);
extern _kernel_oserror * setstamparc(archive * arc);
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "Licence").
* You may not use this file except in compliance with the Licence.
*
* You can obtain a copy of the licence at
* RiscOS/Sources/FileSys/ImageFS/SparkFS/Codecs/SparkARJ/LICENCE.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the Licence file. If applicable, add the
* following below this CDDL HEADER, with the fields enclosed by
* brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1992 David Pilling. All rights reserved.
* Use is subject to license terms.
*/
/*->h.arj */
extern _kernel_oserror * listhdrs(archive * arc);
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "Licence").
* You may not use this file except in compliance with the Licence.
*
* You can obtain a copy of the licence at
* RiscOS/Sources/FileSys/ImageFS/SparkFS/Codecs/SparkARJ/LICENCE.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the Licence file. If applicable, add the
* following below this CDDL HEADER, with the fields enclosed by
* brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1992 David Pilling. All rights reserved.
* Use is subject to license terms.
*/
/*->h.arjint */
typedef unsigned char uchar; /* 8 bits or more */
typedef unsigned int uint; /* 16 - 32 bits or more */
typedef unsigned short ushort; /* 16 bits or more */
typedef unsigned long ulong; /* 32 bits or more */
#define USHRT_BIT (CHAR_BIT * sizeof(ushort))
#define FNAME_MAX 512
/* ********************************************************* */
/*
* Structure of archive block (low order byte first):
*
* 2 header id (comment and local file) = 0xEA60 or 60000U
* 2 basic header size (from 'first_hdr_size' thru 'comment' below)
* = first_hdr_size + strlen(filename) + 1 + strlen(comment) + 1
* = 0 if end of archive
*
* 1 first_hdr_size (size up to 'extra data')
* 1 archiver version number
* 1 minimum archiver version to extract
* 1 host OS (0 = MSDOS, 1 = PRIMOS, 2 = UNIX, 3 = AMIGA, 4 = MAC-OS)
* (5 = OS/2, 6 = APPLE GS, 7 = ATARI ST, 8 = NEXT)
* (9 = VAX VMS)
* 1 arj flags (0x01 = GARBLED_FLAG, 0x02 = RESERVED)
* (0x04 = VOLUME_FLAG, 0x08 = EXTFILE_FLAG)
* (0x10 = PATHSYM_FLAG, 0x20 = BACKUP_FLAG)
* 1 method (0 = stored, 1 = compressed most ... 4 compressed fastest)
* 1 file type (0 = binary, 1 = text, 2 = comment header)
* (3 = directory, 4 = volume label)
* 1 reserved
* 4 date time stamp modified
* 4 compressed size
* 4 original size
* 4 original file's CRC
* 2 entryname position in filename
* 2 file access mode
* 2 host data
* ? extra data
* 4 bytes for extended file position
*
* ? filename (null-terminated)
* ? comment (null-terminated)
*
* 4 basic header CRC
*
* 2 1st extended header size (0 if none)
* ? 1st extended header
* 4 1st extended header's CRC (not present if 0 extended header size)
* ...
* ? compressed file
*
* ********************************************************* */
/* ********************************************************* */
/* */
/* Time stamp format: */
/* */
/* 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 */
/* |<---- year-1980 --->|<- month ->|<--- day ---->| */
/* */
/* 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 */
/* |<--- hour --->|<---- minute --->|<- second/2 ->| */
/* */
/* ********************************************************* */
#define CODE_BIT 16
#define NULL_CHAR '\0'
#define MAXMETHOD 4
#define ARJ_VERSION 3
#define ARJ_X_VERSION 3 /* decoder version */
#define ARJ_X1_VERSION 1
#define DEFAULT_METHOD 1
#define DEFAULT_TYPE 0 /* if type_sw is selected */
#define HEADER_ID 0xEA60
#define HEADER_ID_HI 0xEA
#define HEADER_ID_LO 0x60
#define FIRST_HDR_SIZE 30
#define FIRST_HDR_SIZE_V 34
#define COMMENT_MAX 2048
#define HEADERSIZE_MAX (FIRST_HDR_SIZE + 10 + FNAME_MAX + COMMENT_MAX)
#define BINARY_TYPE 0 /* This must line up with binary/text strings */
#define TEXT_TYPE 1
#define COMMENT_TYPE 2
#define DIR_TYPE 3
#define LABEL_TYPE 4
#define GARBLE_FLAG 0x01
#define VOLUME_FLAG 0x04
#define EXTFILE_FLAG 0x08
#define PATHSYM_FLAG 0x10
#define BACKUP_FLAG 0x20
typedef ulong UCRC; /* CRC-32 */
#define CRC_MASK 0xFFFFFFFFL
#define ARJ_PATH_CHAR '/'
#define FA_RDONLY 0x01 /* Read only attribute */
#define FA_HIDDEN 0x02 /* Hidden file */
#define FA_SYSTEM 0x04 /* System file */
#define FA_LABEL 0x08 /* Volume label */
#define FA_DIREC 0x10 /* Directory */
#define FA_ARCH 0x20 /* Archive */
/* Timestamp macros */
#define get_tx(m,d,h,n) (((ulong)m<<21)+((ulong)d<<16)+((ulong)h<<11)+(n<<5))
#define get_tstamp(y,m,d,h,n,s) ((((ulong)(y-1980))<<25)+get_tx(m,d,h,n)+(s/2))
#define ts_year(ts) ((uint)((ts >> 25) & 0x7f) + 1980)
#define ts_month(ts) ((uint)(ts >> 21) & 0x0f) /* 1..12 means Jan..Dec */
#define ts_day(ts) ((uint)(ts >> 16) & 0x1f) /* 1..31 means 1st..31st */
#define ts_hour(ts) ((uint)(ts >> 11) & 0x1f)
#define ts_min(ts) ((uint)(ts >> 5) & 0x3f)
#define ts_sec(ts) ((uint)((ts & 0x1f) * 2))
/* unarj.c */
extern long origsize;
extern long compsize;
extern UCRC crc;
extern ushort bitbuf;
extern uchar subbitbuf;
extern uchar header[HEADERSIZE_MAX];
extern char arc_name[FNAME_MAX];
extern int bitcount;
extern int file_type;
extern int error_count;
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "Licence").
* You may not use this file except in compliance with the Licence.
*
* You can obtain a copy of the licence at
* RiscOS/Sources/FileSys/ImageFS/SparkFS/Codecs/SparkARJ/LICENCE.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the Licence file. If applicable, add the
* following below this CDDL HEADER, with the fields enclosed by
* brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1992 David Pilling. All rights reserved.
* Use is subject to license terms.
*/
/*->h.cat */
extern char arcpath[256];
extern char arcname[256];
extern _kernel_oserror * setnofiles(archive * arc,int n);
extern _kernel_oserror * writesp2cat(char * name,archive * arc,int fn);
extern _kernel_oserror * writehdr(archive * arc,int fn);
extern _kernel_oserror * updatecat(archive * arc,int fn);
extern _kernel_oserror * loadcat(archive * arc);
extern _kernel_oserror * loadarchive(linkblock * linkb);
extern _kernel_oserror * validate(linkblock * linkb);
extern _kernel_oserror * diropen(linkblock * block);
extern int nextfilenumber(archive * arc);
extern int maxfilenumber(archive * arc,int * fn);
extern int emptydir(archive * arc,int n);
extern _kernel_oserror * deletedir(archive * arc,int maxnum);
extern _kernel_oserror * writefilehdr(int fh,int hdrver,char * name);
extern void calcdirlens(archive * arc);
extern _kernel_oserror * writearcmark(archive * arc);
extern _kernel_oserror * initcat(archive * arc,char * name);
extern _kernel_oserror * deletefile(linkblock * linkb);
extern _kernel_oserror * createfile(linkblock * linkb);
extern _kernel_oserror * createdir(linkblock * linkb);
extern _kernel_oserror * insentry(archive * arc,int fn,int ind,int size);
extern void rementry(archive * arc,int fn,int size);
extern _kernel_oserror * renamex(linkblock * linkb);
extern _kernel_oserror * archiveflush(linkblock * block);
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "Licence").
* You may not use this file except in compliance with the Licence.
*
* You can obtain a copy of the licence at
* RiscOS/Sources/FileSys/ImageFS/SparkFS/Codecs/SparkARJ/LICENCE.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the Licence file. If applicable, add the
* following below this CDDL HEADER, with the fields enclosed by
* brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1992 David Pilling. All rights reserved.
* Use is subject to license terms.
*/
/*->h.convert */
extern int cxmethod;
extern int cxbits;
extern int cxcode;
extern char cxpassword[32];
extern _kernel_oserror * checkpath(char * name,int fp,int make);
extern _kernel_oserror * openfile(char * name,int fp,int mode,int * fh);
extern _kernel_oserror * makeflatpack(char * args[]);
extern _kernel_oserror * makepcflatpack(char * args[]);
extern _kernel_oserror * expandflatpack(char * args[]);
extern _kernel_oserror * openfiler(char * args[]);
extern _kernel_oserror * sparkfsmethod(char * args[],int argc);
extern _kernel_oserror * sparkfsencrypt(char * args[],int argc);
extern _kernel_oserror * compressfile(char * args[]);
extern _kernel_oserror * uncompressfile(char * args[]);
extern _kernel_oserror * create(linkblock * block);
extern _kernel_oserror * method(linkblock * block);
extern _kernel_oserror * info(linkblock * block);
extern _kernel_oserror * convert(linkblock * block);
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "Licence").
* You may not use this file except in compliance with the Licence.
*
* You can obtain a copy of the licence at
* RiscOS/Sources/FileSys/ImageFS/SparkFS/Codecs/SparkARJ/LICENCE.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the Licence file. If applicable, add the
* following below this CDDL HEADER, with the fields enclosed by
* brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1992 David Pilling. All rights reserved.
* Use is subject to license terms.
*/
/*->h.main */
extern _kernel_oserror * ARJ_initialise(char * cmd_tail,int podule_base,
void * pw);
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "Licence").
* You may not use this file except in compliance with the Licence.
*
* You can obtain a copy of the licence at
* RiscOS/Sources/FileSys/ImageFS/SparkFS/Codecs/SparkARJ/LICENCE.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the Licence file. If applicable, add the
* following below this CDDL HEADER, with the fields enclosed by
* brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1992 David Pilling. All rights reserved.
* Use is subject to license terms.
*/
/*->h.pack */
extern void closepack(void);
extern _kernel_oserror * openpack(int method,int bits);
extern _kernel_oserror * pack(heads * hdr,buffer * src,buffer * dest);
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "Licence").
* You may not use this file except in compliance with the Licence.
*
* You can obtain a copy of the licence at
* RiscOS/Sources/FileSys/ImageFS/SparkFS/Codecs/SparkARJ/LICENCE.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the Licence file. If applicable, add the
* following below this CDDL HEADER, with the fields enclosed by
* brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1992 David Pilling. All rights reserved.
* Use is subject to license terms.
*/
/*->h.unpack */
extern _kernel_oserror * unpack(archive * arc,int fn,buffer * src,
buffer * dest);
extern _kernel_oserror * openunpack(archive * arc,int fn);
extern void closeunpack(void);
extern _kernel_oserror * fillsrcbuffer(buffer * src);
extern _kernel_oserror * unpacksetup(int cxmode,int bits);
extern _kernel_oserror * unpackcx(buffer * src,buffer * dest);
;
; CDDL HEADER START
;
; The contents of this file are subject to the terms of the
; Common Development and Distribution License (the "Licence").
; You may not use this file except in compliance with the Licence.
;
; You can obtain a copy of the licence at
; RiscOS/Sources/FileSys/ImageFS/SparkFS/Codecs/SparkARJ/LICENCE.
; See the Licence for the specific language governing permissions
; and limitations under the Licence.
;
; When distributing Covered Code, include this CDDL HEADER in each
; file and include the Licence file. If applicable, add the
; following below this CDDL HEADER, with the fields enclosed by
; brackets "[]" replaced with your own identifying information:
; Portions Copyright [yyyy] [name of copyright owner]
;
; CDDL HEADER END
;
; Copyright 1992 David Pilling. All rights reserved.
; Use is subject to license terms.
;
;->s.info
EXPORT archivetypes
EXPORT compressiontypes
EXPORT codetypes
EXPORT conversiontypes
AREA |C$$data|
ReadOnly * 1
Private * 2
AnyPublic * -3
AnyLocal * -2
ListEnd * -1
archivetypes
DCD &00000009
DCD &DDC
DCD ReadOnly
DCD AnyLocal
DCD ListEnd
DCD AnyLocal
DCD ListEnd
DCB "ARJ",0
DCB "new/arj",0
ALIGN
DCD ListEnd
compressiontypes
DCD ListEnd
codetypes
DCD &00000000
DCD Private
DCB "None",0,0,0,0
DCD ListEnd
conversiontypes
DCD ListEnd
END
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment