home *** CD-ROM | disk | FTP | other *** search
/ The UNIX CD Bookshelf / OREILLY_TUCB_UNIX_CD.iso / upt / examples / SOURCES / TAR / RSEPATCH. < prev    next >
Encoding:
Text File  |  1998-07-24  |  5.8 KB  |  238 lines

  1. *** create.c.orig    Mon Sep 14 17:19:28 1992
  2. --- create.c    Wed Oct 28 12:58:36 1992
  3. ***************
  4. *** 373,379 ****
  5.           
  6.           header_moved = 0;
  7.   
  8. - #ifdef BSD42
  9.           if (f_sparse_files) {
  10.           /*
  11.             * JK - This is the test for sparseness: whether the
  12. --- 373,378 ----
  13. ***************
  14. *** 384,393 ****
  15.            * at least one of those records in the file is just
  16.            * a useless hole.
  17.            */
  18.   #ifdef hpux    /* Nice of HPUX to gratuitiously change it, huh?  - mib */
  19. !                 if (hstat.st_size - (hstat.st_blocks * 1024) > 1024 )
  20.   #else
  21. !             if (hstat.st_size - (hstat.st_blocks * RECORDSIZE) > RECORDSIZE)
  22.   #endif
  23.                 {
  24.                   int    filesize = hstat.st_size;
  25. --- 383,398 ----
  26.            * at least one of those records in the file is just
  27.            * a useless hole.
  28.            */
  29. + #ifdef BSD42
  30.   #ifdef hpux    /* Nice of HPUX to gratuitiously change it, huh?  - mib */
  31. !                 if (hstat.st_size - (hstat.st_blocks * 1024) > 1024 
  32. ! #else
  33. !             if (hstat.st_size - (hstat.st_blocks * RECORDSIZE) > RECORDSIZE
  34. ! #endif
  35. !                             || check_sparse(p))
  36.   #else
  37. !                         if (check_sparse(p))
  38.   #endif
  39.                 {
  40.                   int    filesize = hstat.st_size;
  41. ***************
  42. *** 455,463 ****
  43. --- 460,470 ----
  44.                       
  45.               }
  46.           }
  47. + /*
  48.   #else
  49.           upperbound=SPARSE_IN_HDR-1;
  50.   #endif
  51. + */
  52.           
  53.           sizeleft = hstat.st_size;
  54.           /* Don't bother opening empty, world readable files. */
  55. *** tar.c.orig    Mon Sep 14 17:31:38 1992
  56. --- tar.c    Wed Oct 28 13:33:15 1992
  57. ***************
  58. *** 92,97 ****
  59. --- 92,100 ----
  60.   
  61.   extern FILE *msg_file;
  62.   
  63. + int    check_sparse();
  64. + void    add_sparse();
  65. + void    add_sparse_file();
  66.   int    check_exclude();
  67.   void    add_exclude();
  68.   void    add_exclude_file();
  69. ***************
  70. *** 184,189 ****
  71. --- 187,194 ----
  72.       {"portability",        0,    0,            'o'},
  73.       {"compress",        0,    &f_compress,        1},
  74.       {"compress-block",    0,    &f_compress,        2},
  75. +     {"sparse-list",        1,    0,            18},
  76. +     {"sparse-file",        1,    0,            19},
  77.       {"sparse",        0,    &f_sparse_files,    1},
  78.       {"tape-length",        1,    0,            'L'},
  79.       {"remove-files",    0,    &f_remove_files,    1},
  80. ***************
  81. *** 358,363 ****
  82. --- 363,378 ----
  83.               f_volno_file = optarg;
  84.               break;
  85.               
  86. +         case 18:
  87. +             f_sparse_files++;
  88. +             add_sparse_file(optarg);
  89. +             break;
  90. +             
  91. +         case 19:
  92. +             f_sparse_files++;
  93. +             add_sparse(optarg);
  94. +             break;
  95. +             
  96.           case 'g':    /* We are making a GNU dump; save
  97.                      directories at the beginning of
  98.                      the archive, and include in each
  99. ***************
  100. *** 704,709 ****
  101. --- 719,726 ----
  102.       --preserve-order    list of names to extract is sorted to match archive\n\
  103.   --same-owner        create extracted files with the same ownership \n\
  104.   -S, --sparse        handle sparse files efficiently\n\
  105. + --sparse-file FILE    treat FILE as sparse (implicit -S as well)\n\
  106. + --sparse-list FILE    treat files listed in FILE as sparse (implicit -S)\n\
  107.   -T, --files-from F    get names to extract or create from file F\n\
  108.   --null            -T reads null-terminated names, disable -C\n\
  109.   --totals            print total bytes written with --create\n\
  110. ***************
  111. *** 1394,1399 ****
  112. --- 1411,1534 ----
  113.           if(   (str=strstr(name,exclude[n]))
  114.               && (str==name || str[-1]=='/')
  115.              && str[strlen(exclude[n])]=='\0')
  116. +             return 1;
  117. +     }
  118. +     return 0;
  119. + }
  120. + char *s_buffer = 0;
  121. + int size_s_buffer;
  122. + int free_s_buffer;
  123. + char **sparse = 0;
  124. + int size_sparse = 0;
  125. + int free_sparse = 0;
  126. + char **re_sparse = 0;
  127. + int size_re_sparse = 0;
  128. + int free_re_sparse = 0;
  129. + void
  130. + add_sparse(name)
  131. + char *name;
  132. + {
  133. + /*    char *rname;*/
  134. + /*    char **tmp_ptr;*/
  135. +     int size_buf;
  136. +     un_quote_string(name);
  137. +     size_buf = strlen(name);
  138. +     if(s_buffer==0) {
  139. +         s_buffer = (char *)ck_malloc(size_buf+1024);
  140. +         free_s_buffer=1024;
  141. +     } else if(free_s_buffer<=size_buf) {
  142. +         char *old_s_buffer;
  143. +         char **tmp_ptr;
  144. +         old_s_buffer = s_buffer;
  145. +         s_buffer = (char *)ck_realloc(s_buffer,size_s_buffer+1024);
  146. +         free_s_buffer = 1024;
  147. +         for(tmp_ptr=sparse;tmp_ptr<sparse+size_sparse;tmp_ptr++)
  148. +             *tmp_ptr= s_buffer + ((*tmp_ptr) - old_s_buffer);
  149. +         for(tmp_ptr=re_sparse;tmp_ptr<re_sparse+size_re_sparse;tmp_ptr++)
  150. +             *tmp_ptr= s_buffer + ((*tmp_ptr) - old_s_buffer);
  151. +     }
  152. +     if(is_regex(name)) {
  153. +         if(free_re_sparse==0) {
  154. +             re_sparse= (char **)(re_sparse ? ck_realloc(re_sparse,(size_re_sparse+32)*sizeof(char *)) : ck_malloc(sizeof(char *)*32));
  155. +             free_re_sparse+=32;
  156. +         }
  157. +         re_sparse[size_re_sparse]=s_buffer+size_s_buffer;
  158. +         size_re_sparse++;
  159. +         free_re_sparse--;
  160. +     } else {
  161. +         if(free_sparse==0) {
  162. +             sparse=(char **)(sparse ? ck_realloc(sparse,(size_sparse+32)*sizeof(char *)) : ck_malloc(sizeof(char *)*32));
  163. +             free_sparse+=32;
  164. +         }
  165. +         sparse[size_sparse]=s_buffer+size_s_buffer;
  166. +         size_sparse++;
  167. +         free_sparse--;
  168. +     }
  169. +     strcpy(s_buffer+size_s_buffer,name);
  170. +     size_s_buffer+=size_buf+1;
  171. +     free_s_buffer-=size_buf+1;
  172. + }
  173. + void
  174. + add_sparse_file(file)
  175. + char *file;
  176. + {
  177. +     FILE *fp;
  178. +     char buf[1024];
  179. +     if(strcmp(file, "-"))
  180. +         fp=fopen(file,"r");
  181. +     else
  182. +         /* Let's hope the person knows what they're doing. */
  183. +         /* Using -X - -T - -f - will get you *REALLY* strange
  184. +            results. . . */
  185. +         fp=stdin;
  186. +     if(!fp) {
  187. +         msg_perror("can't open %s",file);
  188. +         exit(2);
  189. +     }
  190. +     while(fgets(buf,1024,fp)) {
  191. + /*        int size_buf;*/
  192. +         char *end_str;
  193. +         end_str=rindex(buf,'\n');
  194. +         if(end_str)
  195. +             *end_str='\0';
  196. +         add_sparse(buf);
  197. +     }
  198. +     fclose(fp);
  199. + }
  200. + /* Returns non-zero if the file 'name' should be treated as sparse */
  201. + int
  202. + check_sparse(name)
  203. + char *name;
  204. + {
  205. +     int n;
  206. +     char *str;
  207. +     extern char *strstr();
  208. +     for(n=0;n<size_re_sparse;n++) {
  209. +         if(fnmatch(re_sparse[n], name, FNM_TARPATH) == 0)
  210. +             return 1;
  211. +     }
  212. +     for(n=0;n<size_sparse;n++) {
  213. +         /* Accept the output from strstr only if it is the last
  214. +            part of the string.  There is certainly a faster way to
  215. +            do this. . . */
  216. +         if(   (str=strstr(name,sparse[n]))
  217. +             && (str==name || str[-1]=='/')
  218. +            && str[strlen(sparse[n])]=='\0')
  219.               return 1;
  220.       }
  221.       return 0;
  222.