]>
Dogcows Code - chaz/tar/blob - src/tar.c
1 /* Tar -- a tape archiver.
2 Copyright (C) 1988 Free Software Foundation
4 This file is part of GNU Tar.
6 GNU Tar is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Tar is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Tar; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 * A tar (tape archiver) program.
23 * Written by John Gilmore, ihnp4!hoptoad!gnu, starting 25 Aug 85.
27 #include <sys/types.h> /* Needed for typedefs in tar.h */
32 * The following causes "tar.h" to produce definitions of all the
33 * global variables, rather than just "extern" declarations of them.
35 #define TAR_EXTERN /**/
40 #if defined(_POSIX_VERSION) || defined(DIRENT)
46 #define DP_NAMELEN(x) strlen((x)->d_name)
47 #endif /* _POSIX_VERSION or DIRENT */
48 #if !defined(_POSIX_VERSION) && !defined(DIRENT) && defined(BSD42)
50 #define DP_NAMELEN(x) (x)->d_namlen
51 #endif /* not _POSIX_VERSION and BSD42 */
54 #define DP_NAMELEN(x) (x)->d_namlen
57 #if defined(USG) && !defined(_POSIX_VERSION) && !defined(DIRENT)
59 #define DP_NAMELEN(x) strlen((x)->d_name)
60 #endif /* USG and not _POSIX_VERSION and not DIRENT */
63 * We should use a conversion routine that does reasonable error
64 * checking -- atoi doesn't. For now, punt. FIXME.
69 extern int getoldopt();
70 extern void read_and();
71 extern void list_archive();
72 extern void extract_archive();
73 extern void diff_archive();
74 extern void create_archive();
75 extern void update_archive();
76 extern void junk_archive();
79 extern time_t get_date();
83 static FILE *namef
; /* File to read names from */
84 static char **n_argv
; /* Argv used by name routines */
85 static int n_argc
; /* Argc used by name routines */
86 static char **n_ind
; /* Store an array of names */
87 static int n_indalloc
; /* How big is the array? */
88 static int n_indused
; /* How many entries does it have? */
89 static int n_indscan
; /* How many of the entries have we scanned? */
92 extern FILE *msg_file
;
96 void add_exclude_file();
105 char *un_quote_string();
113 #define DEFBLOCKING 20
117 #define DEF_AR_FILE "tar.out"
120 /* For long options that unconditionally set a single flag, we have getopt
121 do it. For the others, we share the code for the equivalent short
122 named option, the name of which is stored in the otherwise-unused `val'
123 field of the `struct option'; for long options that have no equivalent
124 short option, we use nongraphic characters as pseudo short option
125 characters, starting (for no particular reason) with character 10. */
127 struct option long_options
[] =
129 {"create", 0, 0, 'c'},
130 {"append", 0, 0, 'r'},
131 {"extract", 0, 0, 'x'},
134 {"update", 0, 0, 'u'},
135 {"catenate", 0, 0, 'A'},
136 {"concatenate", 0, 0, 'A'},
137 {"compare", 0, 0, 'd'},
139 {"delete", 0, 0, 14},
143 {"directory", 1, 0, 'C'},
144 {"record-number", 0, &f_sayblock
, 1},
145 {"files-from", 1, 0, 'T'},
146 {"label", 1, 0, 'V'},
147 {"exclude-from", 1, 0, 'X'},
148 {"exclude", 1, 0, 15},
150 {"block-size", 1, 0, 'b'},
151 {"version", 0, 0, 11},
152 {"verbose", 0, 0, 'v'},
153 {"totals", 0, &f_totals
, 1},
155 {"read-full-blocks", 0, &f_reblock
, 1},
156 {"starting-file", 1, 0, 'K'},
157 {"to-stdout", 0, &f_exstdout
, 1},
158 {"ignore-zeros", 0, &f_ignorez
, 1},
159 {"keep-old-files", 0, 0, 'k'},
160 {"uncompress", 0, &f_compress
, 1},
161 {"same-permissions", 0, &f_use_protection
, 1},
162 {"preserve-permissions",0, &f_use_protection
, 1},
163 {"modification-time", 0, &f_modified
, 1},
164 {"preserve", 0, 0, 10},
165 {"same-order", 0, &f_sorted_names
, 1},
166 {"same-owner", 0, &f_do_chown
, 1},
167 {"preserve-order", 0, &f_sorted_names
, 1},
169 {"newer", 1, 0, 'N'},
170 {"after-date", 1, 0, 'N'},
171 {"newer-mtime", 1, 0, 13},
172 {"incremental", 0, 0, 'G'},
173 {"listed-incremental", 1, 0, 'g'},
174 {"multi-volume", 0, &f_multivol
, 1},
175 {"info-script", 1, 0, 'F'},
176 {"absolute-paths", 0, &f_absolute_paths
, 1},
177 {"interactive", 0, &f_confirm
, 1},
178 {"confirmation", 0, &f_confirm
, 1},
180 {"verify", 0, &f_verify
, 1},
181 {"dereference", 0, &f_follow_links
, 1},
182 {"one-file-system", 0, &f_local_filesys
, 1},
183 {"old-archive", 0, 0, 'o'},
184 {"portability", 0, 0, 'o'},
185 {"compress", 0, &f_compress
, 1},
186 {"compress-block", 0, &f_compress
, 2},
187 {"sparse", 0, &f_sparse_files
, 1},
188 {"tape-length", 1, 0, 'L'},
194 * Main routine for tar.
201 extern char version_string
[];
203 tar
= argv
[0]; /* JF: was "tar" Set program name */
204 filename_terminator
= '\n';
210 name_init(argc
, argv
);
224 fprintf (stderr
, "Total bytes written: %d\n", tot_written
);
229 label_pattern
= (struct re_pattern_buffer
*)
230 ck_malloc (sizeof *label_pattern
);
231 err
= re_compile_pattern (f_volhdr
, strlen (f_volhdr
),
234 fprintf (stderr
,"Bad regular expression: %s\n",
242 read_and(extract_archive
);
247 label_pattern
= (struct re_pattern_buffer
*)
248 ck_malloc (sizeof *label_pattern
);
249 err
= re_compile_pattern (f_volhdr
, strlen (f_volhdr
),
252 fprintf (stderr
,"Bad regular expression: %s\n",
258 read_and(list_archive
);
266 read_and(diff_archive
);
269 fprintf(stderr
,"%s\n",version_string
);
272 msg("you must specify exactly one of the r, c, t, x, or d options\n");
273 fprintf(stderr
,"For more information, type ``%s +help''.\n",tar
);
282 * Parse the options for tar.
289 register int c
; /* Option letter */
292 /* Set default option values */
293 blocking
= DEFBLOCKING
; /* From Makefile */
294 ar_file
= getenv("TAPE"); /* From environment, or */
296 ar_file
= DEF_AR_FILE
; /* From Makefile */
299 while ((c
= getoldopt(argc
, argv
,
300 "-01234567Ab:BcC:df:F:g:GhikK:lL:mMN:oOpPrRsStT:uvV:wWxX:zZ",
301 long_options
, &ind
)) != EOF
) {
303 case 0: /* long options that set a single flag */
306 /* File name or non-parsed option */
313 case 10: /* preserve */
314 f_use_protection
= f_sorted_names
= 1;
317 if(cmd_mode
!=CMD_NONE
)
319 cmd_mode
=CMD_VERSION
;
322 printf("This is GNU tar, the tape archiving program.\n");
329 case 14: /* Delete in the archive */
330 if(cmd_mode
!=CMD_NONE
)
340 case 16: /* -T reads null terminated filenames. */
341 filename_terminator
= '\0';
344 case 'g': /* We are making a GNU dump; save
345 directories at the beginning of
346 the archive, and include in each
347 directory its contents */
364 /* JF this'll have to be modified for other
365 systems, of course! */
369 d
=getoldopt(argc
,argv
,"lmh");
371 sprintf(buf
,"/dev/rmt/%d%c",c
,d
);
378 if(d
=='l') add
=LOW_NUM
;
379 else if(d
=='m') add
=MID_NUM
;
380 else if(d
=='h') add
=HGH_NUM
;
383 sprintf(buf
,"/dev/rmt%d",add
+c
-'0');
389 case 'A': /* Arguments are tar files,
390 just cat them onto the end
392 if(cmd_mode
!=CMD_NONE
)
397 case 'b': /* Set blocking factor */
398 blocking
= intconv(optarg
);
401 case 'B': /* Try to reblock input */
402 f_reblock
++; /* For reading 4.2BSD pipes */
405 case 'c': /* Create an archive */
406 if(cmd_mode
!=CMD_NONE
)
414 msg_perror("Can't change directory to %d",optarg
);
418 case 'd': /* Find difference tape/disk */
419 if(cmd_mode
!=CMD_NONE
)
424 case 'f': /* Use ar_file for the archive */
429 /* Since -F is only useful with -M , make it implied */
430 f_run_script_at_end
++; /* run this script at the end */
431 info_script
= optarg
; /* of each tape */
435 case 'G': /* We are making a GNU dump; save
436 directories at the beginning of
437 the archive, and include in each
438 directory its contents */
446 f_follow_links
++; /* follow symbolic links */
450 f_ignorez
++; /* Ignore zero records (eofs) */
452 * This can't be the default, because Unix tar
453 * writes two records of zeros, then pads out the
454 * block with garbage.
458 case 'k': /* Don't overwrite files */
460 msg("can't keep old files on this system");
472 case 'l': /* When dumping directories, don't
473 dump files/subdirectories that are
474 on other filesystems. */
479 tape_length
= intconv (optarg
);
486 case 'M': /* Make Multivolume archive:
487 When we can't write any more
488 into the archive, re-open it,
489 and continue writing */
493 case 'N': /* Only write files newer than X */
496 new_time
=get_date(optarg
, (PTR
) 0);
499 case 'o': /* Generate old archive */
500 if(f_gnudump
/* || f_dironly */)
517 case 'r': /* Append files to the archive */
518 if(cmd_mode
!=CMD_NONE
)
524 f_sayblock
++; /* Print block #s for debug */
525 break; /* of bad tar archives */
528 f_sorted_names
++; /* Names to extr are sorted */
531 case 'S': /* deal with sparse files */
535 if(cmd_mode
!=CMD_NONE
)
538 f_verbose
++; /* "t" output == "cv" or "xv" */
546 case 'u': /* Append files to the archive that
547 aren't there, or are newer than the
548 copy in the archive */
549 if(cmd_mode
!=CMD_NONE
)
570 case 'x': /* Extract files from the archive */
571 if(cmd_mode
!=CMD_NONE
)
573 cmd_mode
=CMD_EXTRACT
;
578 add_exclude_file(optarg
);
581 case 'z': /* Easy to type */
582 case 'Z': /* Like the filename extension .Z */
588 msg("Unknown option. Use '%s +help' for a complete list of options.", tar
);
594 blocksize
= blocking
* RECORDSIZE
;
599 * Print as much help as the user's gonna get.
601 * We have to sprinkle in the KLUDGE lines because too many compilers
602 * cannot handle character strings longer than about 512 bytes. Yuk!
603 * In particular, MS-DOS and Xenix MSC and PDP-11 V7 Unix have this
609 puts("choose one of the following:");
612 +concatenate append tar files to an archive\n\
613 -c, +create create a new archive\n\
615 +compare find differences between archive and file system\n\
616 +delete delete from the archive (not for use on mag tapes!)\n\
617 -r, +append append files to the end of an archive\n\
618 -t, +list list the contents of an archive\n\
619 -u, +update only append files that are newer than copy in archive\n\
621 +get extract files from an archive\n",stdout
);
625 -b, +block-size N block size of Nx512 bytes (default N=%d)\n", DEFBLOCKING
);
627 -B, +read-full-blocks reblock as we read (for reading 4.2BSD pipes)\n\
628 -C, +directory DIR change to directory DIR\n\
629 ", stdout
); /* KLUDGE */ fprintf(stdout
, "\
630 -f, +file [HOSTNAME:]F use archive file or device F (default %s)\n",
631 DEF_AR_FILE
); fputs("\
632 -F, +info-script F run script at end of each tape (implies -M)\n\
633 -G, +incremental create/list/extract old GNU-format incremental backup\n\
634 -g, +listed-incremental F create/list/extract new GNU-format incremental backup\n\
635 -h, +dereference don't dump symlinks; dump the files they point to\n\
636 -i, +ignore-zeros ignore blocks of zeros in archive (normally mean EOF)\n\
637 -k, +keep-old-files keep existing files; don't overwrite them from archive\n\
638 -K, +starting-file FILE begin at FILE in the archive\n\
639 -l, +one-file-system stay in local file system when creating an archive\n\
640 -L, +tape-length LENGTH change tapes after writing LENGTH\n\
641 ", stdout
); /* KLUDGE */ fputs("\
642 -m, +modification-time don't extract file modified time\n\
643 -M, +multi-volume create/list/extract multi-volume archive\n\
644 -N, +after-date DATE,\n\
645 +newer DATE only store files newer than DATE\n\
647 +portability write a V7 format archive, rather than ANSI format\n\
648 -O, +to-stdout extract files to standard output\n\
649 -p, +same-permissions,\n\
650 +preserve-permissions extract all protection information\n\
651 -P, +absolute-paths don't strip leading `/'s from file names\n\
652 +preserve like -p -s\n\
653 ", stdout
); /* KLUDGE */ fputs("\
654 -R, +record-number show record number within archive with each message\n\
656 +preserve-order list of names to extract is sorted to match archive\n\
657 +same-order create extracted files with the same ownership \n\
658 -S, +sparse handle sparse files efficiently\n\
659 -T, +files-from F get names to extract or create from file F\n\
660 +null -T reads null-terminated names, disable -C\n\
661 +totals print total bytes written with +create\n\
662 -v, +verbose verbosely list files processed\n\
663 -V, +label NAME create archive with volume name NAME\n\
664 +version print tar program version number\n\
666 +confirmation ask for confirmation for every action\n\
667 ", stdout
); /* KLUDGE */ fputs("\
668 -W, +verify attempt to verify the archive after writing it\n\
669 +exclude FILE exclude file FILE\n\
670 -X, +exclude-from FILE exclude files listed in FILE\n\
671 -z, -Z, +compress,\n\
672 +uncompress filter the archive through compress\n\
673 -[0-7][lmh] specify drive and density\n\
681 if(n_indalloc
==n_indused
) {
683 n_ind
=(char **)(n_indused
? ck_realloc(n_ind
,n_indalloc
*sizeof(char *)) : ck_malloc(n_indalloc
*sizeof(char *)));
685 n_ind
[n_indused
++]=name
;
689 * Set up to gather file names for tar.
691 * They can either come from stdin or from argv.
694 name_init(argc
, argv
)
701 msg("too many args with -T option");
704 if (!strcmp(name_file
, "-")) {
707 namef
= fopen(name_file
, "r");
709 msg_perror("can't open file %s",name_file
);
714 /* Get file names from argv, after options. */
720 /* Read the next filename read from STREAM and null-terminate it.
721 Put it into BUFFER, reallocating and adjusting *PBUFFER_SIZE if necessary.
722 Return the new value for BUFFER, or NULL at end of file. */
725 read_name_from_file (buffer
, pbuffer_size
, stream
)
727 size_t *pbuffer_size
;
731 register int indx
= 0;
732 register size_t buffer_size
= *pbuffer_size
;
734 while ((c
= getc (stream
)) != EOF
&& c
!= filename_terminator
)
736 if (indx
== buffer_size
)
738 buffer_size
+= NAMSIZ
;
739 buffer
= ck_realloc (buffer
, buffer_size
+ 2);
743 if (indx
== 0 && c
== EOF
)
745 if (indx
== buffer_size
)
747 buffer_size
+= NAMSIZ
;
748 buffer
= ck_realloc (buffer
, buffer_size
+ 2);
751 *pbuffer_size
= buffer_size
;
756 * Get the next name from argv or the name file.
758 * Result is in static storage and can't be relied upon across two calls.
760 * If CHANGE_DIRS is non-zero, treat a filename of the form "-C" as
761 * meaning that the next filename is the name of a directory to change to.
762 * If `filename_terminator' is '\0', CHANGE_DIRS is effectively always 0.
766 name_next(change_dirs
)
769 static char *buffer
; /* Holding pattern */
770 static int buffer_siz
;
772 register char *q
= 0;
773 register int next_name_is_dir
= 0;
774 extern char *un_quote_string();
777 buffer
=ck_malloc(NAMSIZ
+2);
780 if (filename_terminator
== '\0')
784 if(n_indscan
<n_indused
)
785 p
=n_ind
[n_indscan
++];
786 else if (optind
< n_argc
)
787 /* Names come from argv, after options */
791 msg("Missing filename after -C");
795 /* JF trivial support for -C option. I don't know if
796 chdir'ing at this point is dangerous or not.
797 It seems to work, which is all I ask. */
798 if(change_dirs
&& !q
&& p
[0]=='-' && p
[1]=='C' && p
[2]=='\0') {
804 msg_perror("Can't chdir to %s",p
);
808 /* End of JF quick -C hack */
810 if(f_exclude
&& check_exclude(p
))
812 return un_quote_string(p
);
814 while (p
= read_name_from_file (buffer
, &buffer_siz
, namef
)) {
817 continue; /* Ignore empty lines. */
818 q
= p
+ strlen (p
) - 1;
819 while (q
> p
&& *q
== '/') /* Zap trailing "/"s. */
821 if (change_dirs
&& next_name_is_dir
== 0
822 && p
[0] == '-' && p
[1] == 'C' && p
[2] == '\0') {
823 next_name_is_dir
= 1;
826 if (next_name_is_dir
) {
828 msg_perror ("Can't change to directory %s", p
);
829 next_name_is_dir
= 0;
832 if(f_exclude
&& check_exclude(p
))
834 return un_quote_string(p
);
841 * Close the name file, if any.
847 if (namef
!= NULL
&& namef
!= stdin
) fclose(namef
);
852 * Gather names in a list for scanning.
853 * Could hash them later if we really care.
855 * If the names are already sorted to match the archive, we just
856 * read them one by one. name_gather reads the first one, and it
857 * is called by name_match as appropriate to read the next ones.
858 * At EOF, the last name read is just left in the buffer.
859 * This option lets users of small machines extract an arbitrary
860 * number of files by doing "tar t" and editing down the list of files.
866 static struct name
*namebuf
; /* One-name buffer */
868 static char *chdir_name
;
870 if (f_sorted_names
) {
873 namebuf
=(struct name
*)ck_malloc(sizeof(struct name
)+NAMSIZ
);
877 if(*p
=='-' && p
[1]=='C' && p
[2]=='\0') {
878 chdir_name
=name_next(0);
881 msg("Missing file name after -C");
884 namebuf
->change_dir
=chdir_name
;
886 namebuf
->length
= strlen(p
);
887 if (namebuf
->length
>= namelen
) {
888 namebuf
=(struct name
*)ck_realloc(namebuf
,sizeof(struct name
)+namebuf
->length
);
889 namelen
=namebuf
->length
;
891 strncpy(namebuf
->name
, p
, namebuf
->length
);
892 namebuf
->name
[ namebuf
->length
] = 0;
893 namebuf
->next
= (struct name
*)NULL
;
901 /* Non sorted names -- read them all in */
902 while (p
= name_next(0))
907 * Add a name to the namelist.
911 char *name
; /* pointer to name */
913 register int i
; /* Length of string */
914 register struct name
*p
; /* Current struct pointer */
915 static char *chdir_name
;
918 if(name
[0]=='-' && name
[1]=='C' && name
[2]=='\0') {
919 chdir_name
=name_next(0);
922 msg("Missing file name after -C");
925 if(chdir_name
[0]!='/') {
926 char *path
= ck_malloc(PATH_MAX
);
927 #if defined(__MSDOS__) || defined(USG) || defined(_POSIX_VERSION)
928 if(!getcwd(path
,PATH_MAX
))
929 msg("Couldn't get current directory.");
935 msg("Couldn't get current directory: %s",path
);
939 chdir_name
=new_name(path
,chdir_name
);
948 p
= (struct name
*)malloc((unsigned)(sizeof(struct name
) + i
));
951 p
= (struct name
*)malloc ((unsigned)(sizeof (struct name
)));
954 msg("cannot allocate mem for name '%s'.",name
);
956 msg("cannot allocate mem for chdir record.");
959 p
->next
= (struct name
*)NULL
;
964 strncpy(p
->name
, name
, i
);
965 p
->name
[i
] = '\0'; /* Null term */
970 p
->regexp
= 0; /* Assume not a regular expression */
971 p
->firstch
= 1; /* Assume first char is literal */
972 p
->change_dir
=chdir_name
;
973 p
->dir_contents
= 0; /* JF */
976 if (index(name
, '*') || index(name
, '[') || index(name
, '?')) {
977 p
->regexp
= 1; /* No, it's a regexp */
978 if (name
[0] == '*' || name
[0] == '[' || name
[0] == '?')
979 p
->firstch
= 0; /* Not even 1st char literal */
983 if (namelast
) namelast
->next
= p
;
985 if (!namelist
) namelist
= p
;
989 * Return nonzero if name P (from an archive) matches any name from
990 * the namelist, zero if not.
996 register struct name
*nlp
;
1000 if (0 == (nlp
= namelist
)) /* Empty namelist is easy */
1004 if (nlp
->change_dir
&& chdir (nlp
->change_dir
))
1005 msg_perror ("Can't change to directory %d", nlp
->change_dir
);
1010 for (; nlp
!= 0; nlp
= nlp
->next
) {
1011 /* If first chars don't match, quick skip */
1012 if (nlp
->firstch
&& nlp
->name
[0] != p
[0])
1015 /* Regular expressions (shell globbing, actually). */
1017 if (wildmat(p
, nlp
->name
)) {
1018 nlp
->found
= 1; /* Remember it matched */
1020 free((void *)namelist
);
1023 if(nlp
->change_dir
&& chdir(nlp
->change_dir
))
1024 msg_perror("Can't change to directory %s",nlp
->change_dir
);
1025 return 1; /* We got a match */
1030 /* Plain Old Strings */
1031 if (nlp
->length
<= len
/* Archive len >= specified */
1032 && (p
[nlp
->length
] == '\0' || p
[nlp
->length
] == '/')
1033 /* Full match on file/dirname */
1034 && strncmp(p
, nlp
->name
, nlp
->length
) == 0) /* Name compare */
1036 nlp
->found
= 1; /* Remember it matched */
1038 free((void *)namelist
);
1041 if(nlp
->change_dir
&& chdir(nlp
->change_dir
))
1042 msg_perror("Can't change to directory %s",nlp
->change_dir
);
1043 return 1; /* We got a match */
1048 * Filename from archive not found in namelist.
1049 * If we have the whole namelist here, just return 0.
1050 * Otherwise, read the next name in and compare it.
1051 * If this was the last name, namelist->found will remain on.
1052 * If not, we loop to compare the newly read name.
1054 if (f_sorted_names
&& namelist
->found
) {
1055 name_gather(); /* Read one more */
1056 if (!namelist
->found
) goto again
;
1063 * Print the names of things in the namelist that were not matched.
1068 register struct name
*nlp
,*next
;
1071 for (nlp
= namelist
; nlp
!= 0; nlp
= next
) {
1074 msg("%s not found in archive",nlp
->name
);
1077 * We could free() the list, but the process is about
1078 * to die anyway, so save some CPU time. Amigas and
1079 * other similarly broken software will need to waste
1083 if (!f_sorted_names
)
1087 namelist
= (struct name
*)NULL
;
1088 namelast
= (struct name
*)NULL
;
1090 if (f_sorted_names
) {
1091 while (0 != (p
= name_next(1)))
1092 msg("%s not found in archive", p
);
1096 /* These next routines were created by JF */
1104 /* This is like name_match(), except that it returns a pointer to the name
1105 it matched, and doesn't set ->found The caller will have to do that
1106 if it wants to. Oh, and if the namelist is empty, it returns 0, unlike
1107 name_match(), which returns TRUE */
1113 register struct name
*nlp
;
1117 if (0 == (nlp
= namelist
)) /* Empty namelist is easy */
1120 for (; nlp
!= 0; nlp
= nlp
->next
) {
1121 /* If first chars don't match, quick skip */
1122 if (nlp
->firstch
&& nlp
->name
[0] != p
[0])
1125 /* Regular expressions */
1127 if (wildmat(p
, nlp
->name
))
1128 return nlp
; /* We got a match */
1132 /* Plain Old Strings */
1133 if (nlp
->length
<= len
/* Archive len >= specified */
1134 && (p
[nlp
->length
] == '\0' || p
[nlp
->length
] == '/')
1135 /* Full match on file/dirname */
1136 && strncmp(p
, nlp
->name
, nlp
->length
) == 0) /* Name compare */
1137 return nlp
; /* We got a match */
1141 * Filename from archive not found in namelist.
1142 * If we have the whole namelist here, just return 0.
1143 * Otherwise, read the next name in and compare it.
1144 * If this was the last name, namelist->found will remain on.
1145 * If not, we loop to compare the newly read name.
1147 if (f_sorted_names
&& namelist
->found
) {
1148 name_gather(); /* Read one more */
1149 if (!namelist
->found
) goto again
;
1151 return (struct name
*) 0;
1154 /* This returns a name from the namelist which doesn't have ->found set.
1155 It sets ->found before returning, so successive calls will find and return
1156 all the non-found names in the namelist */
1158 struct name
*gnu_list_name
;
1164 gnu_list_name
= namelist
;
1165 while(gnu_list_name
&& gnu_list_name
->found
)
1166 gnu_list_name
=gnu_list_name
->next
;
1168 gnu_list_name
->found
++;
1169 if(gnu_list_name
->change_dir
)
1170 if(chdir(gnu_list_name
->change_dir
)<0)
1171 msg_perror("can't chdir to %s",gnu_list_name
->change_dir
);
1172 return gnu_list_name
->name
;
1183 for(n
=namelist
;n
;n
=n
->next
)
1193 path_buf
=(char *)malloc(strlen(path
)+strlen(name
)+2);
1195 msg("Can't allocate memory for name '%s/%s",path
,name
);
1198 (void) sprintf(path_buf
,"%s/%s",path
,name
);
1202 /* returns non-zero if the luser typed 'y' or 'Y', zero otherwise. */
1205 confirm(action
,file
)
1206 char *action
, *file
;
1209 static FILE *confirm_file
= 0;
1210 extern FILE *msg_file
;
1211 extern char TTY_NAME
[];
1213 fprintf(msg_file
,"%s %s?", action
, file
);
1216 confirm_file
= (archive
== 0) ? fopen(TTY_NAME
, "r") : stdin
;
1218 msg("Can't read confirmation from user");
1222 c
=getc(confirm_file
);
1223 for(nl
= c
; nl
!= '\n' && nl
!= EOF
; nl
= getc(confirm_file
))
1225 return (c
=='y' || c
=='Y');
1233 int size_exclude
= 0;
1234 int free_exclude
= 0;
1236 char **re_exclude
= 0;
1237 int size_re_exclude
= 0;
1238 int free_re_exclude
= 0;
1245 /* char **tmp_ptr;*/
1248 un_quote_string(name
);
1249 size_buf
= strlen(name
);
1252 x_buffer
= (char *)ck_malloc(size_buf
+1024);
1254 } else if(free_x_buffer
<=size_buf
) {
1258 old_x_buffer
= x_buffer
;
1259 x_buffer
= (char *)ck_realloc(x_buffer
,size_x_buffer
+1024);
1260 free_x_buffer
= 1024;
1261 for(tmp_ptr
=exclude
;tmp_ptr
<exclude
+size_exclude
;tmp_ptr
++)
1262 *tmp_ptr
= x_buffer
+ ((*tmp_ptr
) - old_x_buffer
);
1263 for(tmp_ptr
=re_exclude
;tmp_ptr
<re_exclude
+size_re_exclude
;tmp_ptr
++)
1264 *tmp_ptr
= x_buffer
+ ((*tmp_ptr
) - old_x_buffer
);
1267 if(is_regex(name
)) {
1268 if(free_re_exclude
==0) {
1269 re_exclude
= (char **)(re_exclude
? ck_realloc(re_exclude
,(size_re_exclude
+32)*sizeof(char *)) : ck_malloc(sizeof(char *)*32));
1270 free_re_exclude
+=32;
1272 re_exclude
[size_re_exclude
]=x_buffer
+size_x_buffer
;
1276 if(free_exclude
==0) {
1277 exclude
=(char **)(exclude
? ck_realloc(exclude
,(size_exclude
+32)*sizeof(char *)) : ck_malloc(sizeof(char *)*32));
1280 exclude
[size_exclude
]=x_buffer
+size_x_buffer
;
1284 strcpy(x_buffer
+size_x_buffer
,name
);
1285 size_x_buffer
+=size_buf
+1;
1286 free_x_buffer
-=size_buf
+1;
1290 add_exclude_file(file
)
1295 extern char *rindex();
1297 if(strcmp(file
, "-"))
1300 /* Let's hope the person knows what they're doing. */
1301 /* Using -X - -T - -f - will get you *REALLY* strange
1306 msg_perror("can't open %s",file
);
1309 while(fgets(buf
,1024,fp
)) {
1313 end_str
=rindex(buf
,'\n');
1326 return index(str
,'*') || index(str
,'[') || index(str
,'?');
1329 /* Returns non-zero if the file 'name' should not be added/extracted */
1336 extern char *strstr();
1338 for(n
=0;n
<size_re_exclude
;n
++) {
1339 if(wildmat(name
,re_exclude
[n
]))
1342 for(n
=0;n
<size_exclude
;n
++) {
1343 /* Accept the output from strstr only if it is the last
1344 part of the string. There is certainly a faster way to
1346 if( (str
=strstr(name
,exclude
[n
]))
1347 && (str
==name
|| str
[-1]=='/')
1348 && str
[strlen(exclude
[n
])]=='\0')
This page took 0.105353 seconds and 4 git commands to generate.