home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / c / compdem.zip / ETZIP.BAS < prev    next >
BASIC Source File  |  1993-02-16  |  8KB  |  209 lines

  1.     ' ETZIP.EXE
  2.     ' (C) Copyright 1992-1993 EllTech Development, Inc.
  3.     ' All rights reserved
  4.  
  5.     ' Be sure to link with the /STACK:4096 switch!
  6.  
  7.     ' =======================================================================
  8.     REM $INCLUDE: 'compress.bi'
  9.     REM $INCLUDE: 'compres2.bi'
  10.     REM $INCLUDE: 'etdecasm.bi'
  11.  
  12.     Version$ = "1.00"
  13.     Cmd$ = UCASE$(COMMAND$)
  14.  
  15.     PRINT
  16.     PRINT "ETZIP v"; Version$
  17.     PRINT "Data Compression Utility"
  18.     PRINT "(C) Copyright 1992-1993 EllTech Development, Inc."
  19.     PRINT "All rights reserved."
  20.     PRINT
  21.     PRINT "This utility demostrates some of the capabilities of EllTech's"
  22.     PRINT CHR$(34); "Compression Plus"; CHR$(34); " data compression library for QuickBASIC"
  23.     PRINT "PDS, and VBDOS programmers. For more information, contact "
  24.     PRINT "EllTech Development, Inc. at (404) 928-8960 or on CIS at 76220,2575."
  25.     PRINT
  26.  
  27.     IF LEN(Cmd$) = 0 THEN                                  'If no command line arguments were
  28.         GOTO ShowHelp                                      ' passed in, remind the user the
  29.     END IF                                                 ' program syntax.
  30.  
  31.     DIM Param$(1 TO 20, 0 TO 1)
  32.     Sep$ = " "
  33.     CALL EtParseCmdLine(Cmd$, Sep$, Param$(), Found%)     'Otherwise, parse out the command line
  34.  
  35.     IF Found% < 1 THEN                                     'zip file name is required
  36.         GOTO ShowHelp                                      'remedial reading :-)
  37.     END IF
  38.  
  39.     Pcnt% = 0
  40.     SpecCnt% = 0
  41.     REDIM Spec$(1 TO 10)
  42.     FOR I% = 1 TO Found%
  43.         SELECT CASE LEFT$(Param$(I%, 0), 1)
  44.             CASE "-", "/":                                 'this is a switch
  45.                 Switch$ = Switch$ + Param$(I%, 0)
  46.             CASE ELSE
  47.                 Pcnt% = Pcnt% + 1
  48.                 SELECT CASE Pcnt%
  49.                     CASE 1                                 'first non-switch is arc file name
  50.                         ArcFile$ = Param$(I%, 0)
  51.                     CASE IS >= 2                           'other non-switch params are file specs
  52.                         IF SpecCnt% < UBOUND(Spec$) THEN
  53.                             SpecCnt% = SpecCnt% + 1
  54.                             Spec$(SpecCnt%) = Param$(I%, 0)
  55.                         END IF
  56.                     CASE ELSE
  57.                 END SELECT
  58.         END SELECT
  59.     NEXT
  60.  
  61.     IF INSTR(ArcFile$, ".") = 0 THEN                       'default extension
  62.         ArcFile$ = ArcFile$ + ".zip"
  63.     END IF
  64.  
  65.     IsItThere% = EtFileExist%(ArcFile$)                    'check existence of archive file
  66.     IF NOT IsItThere% THEN
  67.         Status% = EtFileOpen(ArcFile$, 0, Handle%)             'check archive name
  68.         EtFileClose Handle%
  69.         IF Status% THEN
  70.             PRINT "Illegal File Name: "; ArcFile$              'sorry bad file name
  71.             GOTO ShowHelp                                      'remedial reading
  72.         ELSE
  73.             Temp% = EtFileDelete%(ArcFile$)                    'delete the one we opened
  74.         END IF
  75.     END IF
  76.  
  77.     IF SpecCnt% = 0 THEN
  78.         SpecCnt% = 1
  79.         Spec$(1) = "*.*"                                   'default spec
  80.     END IF
  81.  
  82.     IF INSTR(Switch$, "V") + INSTR(Switch$, "D") = 0 THEN      'if we're not viewing or deleting from an existing zip
  83.         BadSpec% = 0                                           'benefit of the doubt
  84.         FOR I% = 1 TO SpecCnt%
  85.             IF NOT EtFileExist%(Spec$(I%)) THEN                'any files for this  spec
  86.                 BadSpec% = BadSpec% + 1                        'its a BAD spec
  87.                 Spec$(I%) = ""                                 'clear it
  88.             END IF
  89.         NEXT
  90.  
  91.         IF SpecCnt% - BadSpec% < 1 THEN                        'nothing to do
  92.             PRINT "No Files to Archive: "; Spec$
  93.             GOTO ShowHelp
  94.         END IF
  95.     END IF
  96.  
  97.     IF INSTR(Switch$, "V") THEN
  98.         Status% = EtViewZip%(ArcFile$, Spec$())
  99.     ELSE
  100.         Status% = EtZipOpen%(ArcFile$, Mode%, Handle%)
  101.         IF Status% = 0 THEN
  102.             Status% = EtZip%(Handle%, Spec$(), Switch$)
  103.         END IF
  104.     END IF
  105.  
  106.     IF Status% = 0 AND INSTR(Switch$, "Z") THEN
  107.         Status% = EtFileOpen(ArcFile$, 0, Handle%)
  108.         IF Status% = 0 THEN
  109.             OldComment$ = EtZipComment$(Handle%, Status%)
  110.             IF LEN(OldComment$) AND Status% = 0 THEN
  111.                 PRINT
  112.                 PRINT "Old Comment:"; OldComment$
  113.             END IF
  114.             PRINT
  115.             IF EtRedirected2% THEN
  116.                 Bytes& = 1000
  117.                 Buffer$ = SPACE$(Bytes&)
  118.                 RedirHandle% = 0
  119.                 DO
  120.                     EtStringInfo Buffer$, Segment%, Offset%
  121.                     Status% = EtFileRead%(RedirHandle%, Segment%, Offset%, Bytes&)
  122.                     Comment$ = Comment$ + LEFT$(Buffer$, Bytes&)
  123.                 LOOP UNTIL Status%
  124.                 Status% = 0
  125.                 I% = INSTR(Comment$, CHR$(26))             'check for eof marker
  126.                 IF I% > 0 THEN
  127.                     Comment$ = LEFT$(Comment$, I% - 1)
  128.                 END IF
  129.                 DO                                         'remove lf from crlf
  130.                     I% = INSTR(Comment$, CHR$(13) + CHR$(10))
  131.                     IF I% > 0 THEN
  132.                         Comment$ = LEFT$(Comment$, I%) + MID$(Comment$, I% + 2)
  133.                     ELSE
  134.                         EXIT DO
  135.                     END IF
  136.                 LOOP
  137.             ELSE
  138.                 INPUT "Enter Zip Comment:", Comment$
  139.             END IF
  140.             IF LEN(Comment$) THEN
  141.                 Status% = EtZipNewComment%(Handle%, Comment$)
  142.             END IF
  143.         END IF
  144.     END IF
  145.  
  146.     IF Status% THEN
  147.         SELECT CASE Status%
  148.             CASE -1
  149.                 ArcType% = EtArcType%(Handle%, Status%)
  150.                 SELECT CASE ArcType%
  151.                     CASE 2:
  152.                         PRINT "Cannot Compress ARJ files ... Use -v to view"
  153.                     CASE 3:
  154.                         PRINT "Cannot Compress LZH files ... Use -v to view"
  155.                     CASE ELSE
  156.                         PRINT "Unrecognized File Format: "; ArcFile$
  157.                 END SELECT
  158.  
  159.             CASE -2
  160.                 PRINT "Error in Archive: "; ArcFile$
  161.             CASE -3
  162.                 PRINT "Unknown Compression Method"
  163.             CASE -4
  164.                 PRINT "Encrypted File"
  165.             CASE -5
  166.                 PRINT "CRC Error"
  167.             CASE -6
  168.                 PRINT "Archive Not Found"
  169.             CASE -7
  170.                 PRINT "No Files to Compress"
  171.             CASE -8
  172.                 PRINT "Errors Encountered"
  173.             CASE IS > 0
  174.                 PRINT "DOS Error : "; Status%
  175.             CASE ELSE
  176.                 PRINT "Error Status: "; Status%
  177.         END SELECT
  178.     ELSE
  179.         PRINT
  180.         PRINT "Operation Successful!"
  181.     END IF
  182.  
  183.     IF Handle% THEN
  184.         EtZipClose Handle%
  185.     END IF
  186.     GOTO AllDone
  187.  
  188. ShowHelp:
  189.     PRINT
  190.     PRINT "Syntax: EtZip [Switches] ArchiveFile FileSpec [FileSpec...]"
  191.     PRINT "ie:     EtZip -p Stuff.Zip *.*"
  192.     PRINT
  193.     PRINT "Valid Switches: -p  Store paths"
  194.     PRINT "                -d  Delete file from zip"
  195.     PRINT "                -v  View Zip Directory"
  196.     PRINT "                -z  Add/Edit Zip Comment"
  197.     PRINT "                -es Shrink only"
  198.     PRINT "                -ei Implode only"
  199.     PRINT "                -ec Scrunch only"
  200.     PRINT "                -eh Huffman only"
  201.     PRINT "                -em Mash only"
  202.     PRINT "                -et Store only"
  203.  
  204. AllDone:
  205.     END
  206.  
  207.  
  208.  
  209.