home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / zines / phrack2 / p50_16.txt < prev    next >
Encoding:
Text File  |  2003-06-11  |  1.8 KB  |  89 lines

  1.                                 .oO Phrack 50 Oo.
  2.  
  3.                             Volume Seven, Issue Fifty
  4.  
  5.                                      16 of 16
  6.  
  7.                       extract.c by Phrack Staff and sirsyko
  8.  
  9.  
  10. ---------------------8<------------CUT-HERE----------->8---------------------
  11.  
  12. /*  extract.c by Phrack Staff and sirsyko 
  13.  *
  14.  *  Phrack Magazine, 1997 
  15.  *
  16.  *  Extracts textfiles from a specially tagged flatfile into a hierarchical 
  17.  *  directory strcuture. Use to extract source code from any of the articles 
  18.  *  in Phrack Magazine (first appeared in Phrack 50).
  19.  *
  20.  *  gcc -o extract extract.c
  21.  *  
  22.  *  ./extract filename   
  23.  * 
  24.  */   
  25.  
  26.  
  27. #include <stdio.h>
  28. #include <sys/stat.h>
  29. #include <string.h>
  30.  
  31. int main(int argc, char **argv){ 
  32.  
  33.     char *s="<++> ",*e="<-->",b[256],*bp; 
  34.     FILE *f,*o = NULL; 
  35.     int l, n, i=0; 
  36.  
  37.     l = strlen(s); 
  38.     n = strlen(e); 
  39.  
  40.     if(argc<2) {
  41.         printf("Usage: %s <inputfile>\n",argv[0]);
  42.         exit(1); 
  43.     }
  44.  
  45.     if(! (f=fopen(argv[1], "r"))) {
  46.         printf("Could not open input file.\n");
  47.     exit(1);
  48.     }
  49.  
  50.     while(fgets(b, 256, f)){ 
  51.  
  52.         if(!strncmp (b, s, l)){ 
  53.         b[strlen(b)-1] = '\0'; 
  54.  
  55.         if((bp=strchr(b+l+1,'/')))
  56.             while (bp){ 
  57.             *bp='\0';
  58.             mkdir(b+l, 0700); 
  59.             *bp='/';
  60.             bp=strchr(bp+1,'/'); 
  61.         }
  62.         if((o = fopen(b+l, "w"))) 
  63.             printf("- Extracting %s\n",b+l);
  64.         else {
  65.         printf("Could not extract '%s'\n",b+l);
  66.         exit(1);
  67.         }
  68.     } 
  69.         else if(!strncmp (b, e, n)){
  70.         if(o) fclose(o);
  71.         else {
  72.             printf("Error closing file.\n");
  73.         exit(1);
  74.         }
  75.         } 
  76.         else if(o) {
  77.             fputs(b, o);
  78.             i++;
  79.         }
  80.     }
  81.     if(!i) printf("No extraction tags found.\n");
  82.     return(0);
  83. }
  84.  
  85. ---------------------8<------------CUT-HERE----------->8---------------------
  86.  
  87. EOF
  88.  
  89.