home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / amiga / programm / 11744 < prev    next >
Encoding:
Text File  |  1992-07-28  |  3.9 KB  |  166 lines

  1. Newsgroups: comp.sys.amiga.programmer
  2. Path: sparky!uunet!darwin.sura.net!mips!sdd.hp.com!cs.utexas.edu!tamsun.tamu.edu!vpc1156
  3. From: vpc1156@tamsun.tamu.edu (Victor Paul Campano)
  4. Subject: Help me with this code?
  5. Message-ID: <1992Jul28.215944.9423@tamsun.tamu.edu>
  6. Organization: Texas A&M University, College Station
  7. Date: Tue, 28 Jul 1992 21:59:44 GMT
  8. Lines: 156
  9.  
  10. Hello.  I wrote the following code to combine several binary files together
  11. into an uncompressed archive and extract them later.  It works, except that
  12. executable files that get archived and then de-archived dont want to execute
  13. anymore.  Obviously this is some aspect of AmigaDOS I'm just not familiar
  14. with...
  15.  
  16. Could someone help me?
  17.  
  18. Thanks,
  19.  
  20. Thom
  21.  
  22. ***************************************************************************
  23. I am posting this for my friend, Thom, who lost USENET access recently.
  24. Replys to him may be made though this net address.
  25. ***************************************************************************
  26.  
  27.  
  28. #include <exec/types.h>
  29. #include <stdio.h>
  30. #include <exec/exec.h>
  31. #include <exec/memory.h>
  32. #include <fcntl.h>
  33.  
  34.  
  35. #define    BUFFER_SIZE    1024
  36.  
  37. void main(argc,argv)
  38. int argc;
  39. char *argv[];
  40. {
  41.  
  42. int input,output,i,j;
  43. long size;
  44. char filename[80],data[BUFFER_SIZE];
  45.  
  46. if (argc != 3 || (toupper(argv[1][0]) != 'A' &&
  47.           toupper(argv[1][0]) != 'L' &&
  48.           toupper(argv[1][0]) != 'X')) {
  49.    printf("USAGE:combine [alx] file1\n\n");
  50.    exit(30);
  51.    }
  52.  
  53. if (toupper(argv[1][0]) == 'A') {  /* add files to one big file */
  54.  
  55.    if ((output=(int)open(argv[2], O_WRONLY | O_CREAT | O_APPEND))==-1) {
  56.       printf("USAGE:combine [alx] file1\n\n");
  57.       exit(30);
  58.       }
  59.    
  60.    while(TRUE) {
  61.       scanf("%s",filename);
  62.  
  63.       if ((input=(int)open(filename, O_RDONLY))==-1)
  64.  
  65.          break;
  66.  
  67.  
  68.       write(output,filename,strlen(filename) + 1);  /* write filename + null */
  69.       lseek(input,0,2);   /* goto bottom,  */
  70.       size = tell(input); /* and get size. */      
  71.       lseek(input,0,0);   /* goto top.  */
  72.       write(output,(char *)&size,4); /* write out size of file */
  73.       while (size > 0) {
  74.          if (size > BUFFER_SIZE) {
  75.             read(input,data,BUFFER_SIZE);
  76.             write(output,data,BUFFER_SIZE);
  77.         size -= BUFFER_SIZE;
  78.             }
  79.          else {
  80.             read(input,data,size);
  81.             write(output,data,size);
  82.         size -= size;
  83.             }
  84.          }
  85.       close(output);
  86.       }
  87.    close(input);
  88.    }
  89. else if (toupper(argv[1][0]) == 'X') {        /* split files out of archive */
  90.  
  91.    if ((input=(int)open(argv[2], O_RDONLY))==-1) {
  92.       printf("USAGE:combine [alx] file1\n\n");
  93.       exit(30);
  94.       }
  95.    
  96.    while(TRUE) {
  97.       i = j = 0;
  98.       do {  /* get the next filename in the archive */
  99.          if (read(input,&(filename[i]),1) < 1)
  100.         goto exit_loop1;
  101.          } while (filename[i++] != 0);
  102.  
  103.       if ((output=(int)open(filename, O_TRUNC | O_WRONLY | O_CREAT))==-1)
  104.          break;
  105.  
  106.       read(input,(char *) &size,4);  /* read in length */
  107.  
  108.       while (size > 0) {
  109.          if (size > BUFFER_SIZE) {
  110.             read(input,data,BUFFER_SIZE);
  111.             write(output,data,BUFFER_SIZE);
  112.         size -= BUFFER_SIZE;
  113.             }
  114.          else {
  115.             read(input,data,size);
  116.             write(output,data,size);
  117.         size -= size;
  118.             }
  119.          }
  120.       close(output);
  121.       }
  122.    exit_loop1:
  123.    close(input);
  124.    }
  125.  
  126. else {        /* show files in archive */
  127.  
  128.    if ((input=(int)open(argv[2], O_RDONLY))==-1) {
  129.       printf("USAGE:combine [alx] file1\n\n");
  130.       exit(30);
  131.       }
  132.  
  133.    printf("  Filename                                    Size\n");
  134.    while(TRUE) {
  135.       i = j = 0;
  136.       do {  /* get the next filename in the archive */
  137.          if (read(input,&(filename[i]),1) < 1)
  138.         goto exit_loop2;
  139.          } while (filename[i++] != 0);
  140.  
  141.  
  142.       read(input,(char *) &size,4);  /* read in length */
  143.  
  144.       printf("%-45.45s %-d\n",filename,size);
  145.  
  146.       lseek(input,size,1); /* skip to next entry */
  147.  
  148.       }
  149.    exit_loop2:
  150.    close(input);
  151.    }
  152.  
  153.  
  154.  
  155.  
  156. }
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.