4ARC22.DOC

(20 KB) Pobierz

          ARC VERSION 2.20                                   PAGE - 41


          
          What Makes ARC Tick?

               The following  psuedo-code should  make it fairly clear
          as to  what ARC  is doing  when creating  or  extracting  an
          archive.  We  get  alot  of  questions  along  these  lines.
          Hopefully this section will answer some of them.

               But first  we'll define some of the terminology we will
          be using.

               The general format for the ARC command is:

                 ARC/XY/Z D:ARCNAME D:PARM1 D:PARM2 .....

               The command  line is  the command  that you typed in to
          get ARC  going. It  is simply  a series of character strings
          separated by  spaces. The  first  character  string  on  the
          command line,  ARC/XY, is of course the command. X and Y are
          called switches.  We'll call X switch one, Y switch two, and
          Z switch 3.

               The remaining  strings on  the command  line are called
          parameters. Thus D:ARCHNAME is parameter number one, D:PARM1
          is parameter  number two and so on. ARC allows for a maximum
          of ten  parameters (0-9) including the command itself, which
          is parameter number zero.

               Note that spaces are not allowed within a parameter, as
          ARC will interpret this as being two separate parameters. If
          you want  to specify  a file named "ONE TWO THREE", then you
          can do  one of  two  things.  You  could  specify  it  using
          wildcards as  "ONE?TWO?THREE",  or  you  could  use  shifted
          spaces instead  of spaces  in the  filename; ARC will change
          them to spaces and get the correct file.




          ARC VERSION 2.20                                   PAGE - 42


               When you hit RETURN, ARC does the following:

               
               
               GET switch 1
               
               TEST switch 1 for valid character... A,C,F,L,P or V
               IF   switch 1 is invalid then abort.
               
               GET  parameter 1
               IF   no parameter 1 THEN
                    abort.
               ELSE
                    add .arc extension to parameter 1 if req'd
                    IF   switch 1 is A or C THEN
                         open archive for write
                    ELSE
                         open archive for read
                    ENDIF
               ENDIF
               
               
               IF  switch 1 is an A or a C   then create archive.
               IF  switch 1 is an X, P, or V then extract archive.
               IF  switch 1 is an L          then archive directory.
               IF  switch 1 is an F          then fix XMODEM padding.




          ARC VERSION 2.20                                   PAGE - 43


               CREATE ARCHIVE

               WHILE still more parameters (2,3,4,...9)
               
                     Make a directory name ($d:xxxx) out of the
                      parameter and load the directory into RAM.
               
                     FOR  each filename in the directory
                          1) analyze the file
                          2) compress the file using
                             the best compressor.
                     NEXT file
               
                     NEXT parameter
               
               ENDWHILE
               
               Close archive
               STOP




          ARC VERSION 2.20                                   PAGE - 44


               
               
               
               Analyze the File.
               
               OPEN the file to be analyzed for read.
               
               SET  stored, packed, squeezed, squashed, and crunched
                    lengths to zero.
               SET  the checksum to zero.
               SET  the squeeze and squash frequency distributions
                    to zero.
               
               FOR  each byte in the file.
                    Increment the stored (original) length.
                    Adjust the checksum.
                    Adjust the squeeze frequency distribution.
                    IF output required for PACK THEN
                       Increment the packed files length.
                       Adjust the squash frequency distribution.
                       IF output required for CRUNCH THEN
                          Adjust the crunched files length.
               NEXT byte
               
               CLOSE input file
               
               Generate the squeeze Huffman codes and calculate
                        the squeezed file length as
                        sum(code length * frequency)+header
               Generate the squash  Huffman codes and calculate
                        the squashed file length as
                        sum(code length * frequency)+header
               
               Calculate which is the shortest length.
                        store, pack, squeeze, squash, or crunch.
               
               DONE analyzing the file.




          ARC VERSION 2.20                                   PAGE - 45


               
               
               
               Compress the file.
               
               Write the file header.
               
               If the file is packed then write the control character.
                  (always 254 for version 2.xx) Version 1.xx selects
                  the byte which occurs least often in the input file
                  as the control character.
               
               If the file is squeezed or squashed then write the
                  appropriate Huffman encoding table.
               
               OPEN the file to be compressed.
               
               FOR  each byte in the file.
                    GET the byte.
                    Compress the byte using selected method.
               NEXT byte
               
               CLOSE the input file.
               
               IF   crunching file then send end of file marker.
               IF   crunching in one pass then also send original
                    length and checksum. (both of which are not
                    known until now)
               
               
               DONE compressing file. Padd the compressed length to an
                    even multiple of 254 bytes and exit subroutine.




          ARC VERSION 2.20                                   PAGE - 46


               EXTRACT ARCHIVE
               
               Archive is open for read, so:
               
               WHILE NOT end of file
                     GET  header for this entry.
                     IF   no header, or error in header THEN abort.
                     IF   length of this block is < 254  THEN abort.
                              (this will ignore any XMODEM padding)
               
                     IF name in header matches any parameter 2-9 THEN
                          CALL extract file subroutine
                     ELSE
                          get number of blocks to skip from header
                          and skip that many blocks.
                     ENDIF
               
                     IF header checksum=new checksum THEN
                          PRINT "ok."
                     ELSE
                          PRINT "checksum error."
                     ENDIF
               
               ENDWHILE
               DONE extracting archive.
               
               EXTRACT FILE...Subroutine for EXTRACT ARCHIVE
               
               IF switch 1 is X THEN open file for write
               GET file's original length from archive header
               SET new checksum to zero
               
               WHILE original length > 0 DO
                    DEcompress a byte
                    ADJUST new checksum
               
                    IF switch 1 is X THEN write byte to output file
               
                    IF switch 1 is P THEN
                       IF switch 2 is P THEN convert ascii to petscii
                       IF switch 2 is A THEN convert petscii to ascii
                       IF switch 3 is P THEN
                          output to printer
                       ELSE
                          output to screen
                       ENDIF
                    ENDIF
                    DECrement original length
               END WHILE
               IF file open for write THEN close it
               RETURN from subroutine




          ARC VERSION 2.20                                   PAGE - 47


               
               
               FIX XMODEM PADDING
               
               
               Archive is open for read, so we know it exists.
               Close the archive.
               
               GET track,sector where archive starts from the
                   directory.
               
               GET track,sector
               IF  track link <> 0 THEN
                   GET track,sector=link
               ELSE
                   We're at the last block of the file so:
                   IF sector link = 255 THEN
                      PRINT "archive is ok."
                   ELSE
                      GET previous track,sector and change
                          link to 0,255
                      PRINT "archive has been repaired."
                   ENDIF
               ENDIF
               
               DONE fixing archive.




          ARC VERSION 2.20                                   PAGE - 48


               
               
               
               ARC TRICKS AND TIPS.

          1) Manipulating Archives.
          
               If ...
Zgłoś jeśli naruszono regulamin