home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 149.lha / dearc.c < prev    next >
C/C++ Source or Header  |  1988-04-25  |  4KB  |  148 lines

  1.  
  2. echo ; /* compiling and linking dearc.c .....
  3. LC -v dearc.c
  4. BLINK from lib:c.o, dearc.o LIB lib:lc.lib, lib:amiga.lib SC SD ND MAP dearc.map
  5. QUIT
  6. */
  7.  
  8. #include "stdio.h"
  9. #include "exec/types.h"
  10. #include <string.h>
  11. #include <stdlib.h>
  12. #include "dos.h"
  13. #include "proto/exec.h"
  14. #include "proto/dos.h"
  15.  
  16. int fp;
  17.  
  18. VOID MemCleanup (){}
  19.  
  20. char s[20];
  21. char command[80] = { "DELETE " };
  22.  
  23. char   path[166] = "";
  24. char   pathname[166 + 34 + 1] = "";
  25.  
  26. char   file_name[166 + 34 + 1 + 3] = "";
  27.  
  28. void main(argc, argv)
  29.   
  30.    int argc;
  31.    char *argv[];
  32.  
  33. {
  34.    int    result;
  35.    int    more;
  36.    int    *ip;
  37.    char   temp[4];
  38.    int    front;
  39.    char   ext[4];
  40.  
  41.    char   *cp;
  42.  
  43.    puts ( "\n       DE-arc utility v2.0 - TASP Group, INC.\n");
  44.  
  45.    if (( argc <= 1 ) || ( *argv[1] == '?' ))
  46.       {
  47.       puts("usage: dearc FILENAME.EXT \n");
  48.       puts("   where FILENAME.EXT = the arc file from which the"); 
  49.       puts("                        extracted files, this utility");
  50.       puts("                        will delete, came from."); 
  51.       puts("                        .EXT will default to .ARC "); 
  52.       exit ( TRUE );
  53.       }
  54.  
  55.   
  56.    result = strcpy ( &file_name[0], argv[1] ); 
  57.  
  58.    /* see if the user supplied an extension.  if not make it .arc */
  59.    if ( 0 == ( stcgfe ( &ext[0], &file_name[0] ) ) ) 
  60.       {
  61.       strmfe ( &file_name[0], &file_name[0], "ARC" );
  62.       }
  63.       
  64.    /* open the ARC file */
  65.    fp = Open(&file_name[0],MODE_OLDFILE);
  66.    if ( fp == 0 )
  67.       {
  68.       puts ( "Unable to open file" );
  69.       exit (FALSE); 
  70.       }
  71.  
  72.    /* extract the path portion of the input file name */
  73.    result = stcgfp ( &path, &file_name[0] );
  74.  
  75.    /* set up the command string */
  76.    cp = strcpy(&command[0],"DELETE ");
  77.    front = 0;
  78.  
  79.    /* get to the begining of the file */
  80.    result = Seek ( fp, 0, OFFSET_BEGINNING );
  81.  
  82.    /* pull out all the arced file's names and delete those
  83.       files in the directory that the arced file is in */
  84.    do 
  85.       {
  86.       more = FALSE;
  87.       result = Read(fp, &s[0], 1);
  88.  
  89.       /* the first byte had better be a hex 1A */
  90.       if (( s[0] == 26 ) && ( s[0] != EOF ))
  91.          {
  92.          result = Read(fp, &s[0], 1);
  93.  
  94.          /* the second byte should be something other than a zero */
  95.          if ( s[0] > 0 ) 
  96.             {
  97.             /* the next string is the file name max length = 12 bytes */
  98.             result = Read ( fp, &s[0], 13 );
  99.               
  100.             /* make a full pathname */
  101.             strmfp( &pathname[0], &path[0], &s[0] );
  102.                
  103.             /* create a delete command for AmigaDos */
  104.             cp = strcat( &command[0], &pathname[0]);
  105.                
  106.             /* show the user what we are doing */
  107.             puts ( &command[0] );     
  108.  
  109.             /* delete the file */
  110.             result = DeleteFile ( &pathname[0] );
  111.             if ( ! result ) 
  112.                {
  113.                puts ("\n ** file was not deleted ** ");
  114.                }
  115.  
  116.             /* set up the command for the next time */
  117.             command[7] = '\0';
  118.  
  119.             /* get the offset to the next file name.  Its in intel 
  120.                word format ( ie. low high ) */
  121.             result = Seek ( fp, ( front + 15 ), OFFSET_BEGINNING );
  122.             result = Read ( fp, &temp[3], 1 );
  123.             result = Read ( fp, &temp[2], 1 );
  124.             result = Read ( fp, &temp[1], 1 );
  125.             result = Read ( fp, &temp[0], 1 );
  126.             ip = (int * )&temp[0];
  127.  
  128.             /* next file  is at begining of this entry + header
  129.                overhead + offset */
  130.             front = front + 29 + *ip;
  131.  
  132.             result = Seek ( fp, front, OFFSET_BEGINNING );
  133.             more = TRUE;
  134.             }
  135.          }
  136.       else
  137.          {
  138.          puts ( "not an arc format file !" );
  139.          }
  140.       } while ( more );
  141.  
  142.       Close( fp );
  143.  
  144.    
  145.    exit(TRUE);
  146.  
  147. }
  148.