Deleted Added
full compact
pat_rep.c (76017) pat_rep.c (76351)
1/*-
2 * Copyright (c) 1992 Keith Muller.
3 * Copyright (c) 1992, 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Keith Muller of the University of California, San Diego.
8 *

--- 26 unchanged lines hidden (view full) ---

35 * SUCH DAMAGE.
36 */
37
38#ifndef lint
39#if 0
40static char sccsid[] = "@(#)pat_rep.c 8.2 (Berkeley) 4/18/94";
41#endif
42static const char rcsid[] =
1/*-
2 * Copyright (c) 1992 Keith Muller.
3 * Copyright (c) 1992, 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Keith Muller of the University of California, San Diego.
8 *

--- 26 unchanged lines hidden (view full) ---

35 * SUCH DAMAGE.
36 */
37
38#ifndef lint
39#if 0
40static char sccsid[] = "@(#)pat_rep.c 8.2 (Berkeley) 4/18/94";
41#endif
42static const char rcsid[] =
43 "$FreeBSD: head/bin/pax/pat_rep.c 76017 2001-04-26 08:37:00Z kris $";
43 "$FreeBSD: head/bin/pax/pat_rep.c 76351 2001-05-08 06:19:06Z kris $";
44#endif /* not lint */
45
46#include <sys/types.h>
47#include <sys/stat.h>
48#include <stdio.h>
49#include <string.h>
50#include <unistd.h>
51#include <stdlib.h>
44#endif /* not lint */
45
46#include <sys/types.h>
47#include <sys/stat.h>
48#include <stdio.h>
49#include <string.h>
50#include <unistd.h>
51#include <stdlib.h>
52#include <errno.h>
52#ifdef NET2_REGEX
53#include <regexp.h>
54#else
55#include <regex.h>
56#endif
57#include "pax.h"
58#include "pat_rep.h"
59#include "extern.h"

--- 163 unchanged lines hidden (view full) ---

223 * supplied to pax, all members in the archive will be selected (and the
224 * pattern match list is empty).
225 * Return:
226 * 0 if the pattern was added to the list, -1 otherwise
227 */
228
229#ifdef __STDC__
230int
53#ifdef NET2_REGEX
54#include <regexp.h>
55#else
56#include <regex.h>
57#endif
58#include "pax.h"
59#include "pat_rep.h"
60#include "extern.h"

--- 163 unchanged lines hidden (view full) ---

224 * supplied to pax, all members in the archive will be selected (and the
225 * pattern match list is empty).
226 * Return:
227 * 0 if the pattern was added to the list, -1 otherwise
228 */
229
230#ifdef __STDC__
231int
231pat_add(char *str)
232pat_add(char *str, char *chdname)
232#else
233int
233#else
234int
234pat_add(str)
235pat_add(str, chdname)
235 char *str;
236 char *str;
237 char *chdname;
236#endif
237{
238 register PATTERN *pt;
239
240 /*
241 * throw out the junk
242 */
243 if ((str == NULL) || (*str == '\0')) {

--- 11 unchanged lines hidden (view full) ---

255 return(-1);
256 }
257
258 pt->pstr = str;
259 pt->pend = NULL;
260 pt->plen = strlen(str);
261 pt->fow = NULL;
262 pt->flgs = 0;
238#endif
239{
240 register PATTERN *pt;
241
242 /*
243 * throw out the junk
244 */
245 if ((str == NULL) || (*str == '\0')) {

--- 11 unchanged lines hidden (view full) ---

257 return(-1);
258 }
259
260 pt->pstr = str;
261 pt->pend = NULL;
262 pt->plen = strlen(str);
263 pt->fow = NULL;
264 pt->flgs = 0;
265 pt->chdname = chdname;
266
263 if (pathead == NULL) {
264 pattail = pathead = pt;
265 return(0);
266 }
267 pattail->fow = pt;
268 pattail = pt;
269 return(0);
270}

--- 340 unchanged lines hidden (view full) ---

611 register int test;
612#endif
613{
614 register char c;
615 register char c2;
616 int negate;
617 int ok = 0;
618
267 if (pathead == NULL) {
268 pattail = pathead = pt;
269 return(0);
270 }
271 pattail->fow = pt;
272 pattail = pt;
273 return(0);
274}

--- 340 unchanged lines hidden (view full) ---

615 register int test;
616#endif
617{
618 register char c;
619 register char c2;
620 int negate;
621 int ok = 0;
622
619 if ((negate = (*pattern == '!')))
623 if ((negate = (*pattern == '!')) != 0)
620 ++pattern;
621
622 while ((c = *pattern++) != ']') {
623 /*
624 * Illegal pattern
625 */
626 if (c == '\0')
627 return (NULL);

--- 30 unchanged lines hidden (view full) ---

658int
659mod_name(arcn)
660 register ARCHD *arcn;
661#endif
662{
663 register int res = 0;
664
665 /*
624 ++pattern;
625
626 while ((c = *pattern++) != ']') {
627 /*
628 * Illegal pattern
629 */
630 if (c == '\0')
631 return (NULL);

--- 30 unchanged lines hidden (view full) ---

662int
663mod_name(arcn)
664 register ARCHD *arcn;
665#endif
666{
667 register int res = 0;
668
669 /*
670 * Strip off leading '/' if appropriate.
671 * Currently, this option is only set for the tar format.
672 */
673 if (rmleadslash && arcn->name[0] == '/') {
674 if (arcn->name[1] == '\0') {
675 arcn->name[0] = '.';
676 } else {
677 (void)memmove(arcn->name, &arcn->name[1],
678 strlen(arcn->name));
679 arcn->nlen--;
680 }
681 if (rmleadslash < 2) {
682 rmleadslash = 2;
683 paxwarn(0, "Removing leading / from absolute path names in the archive");
684 }
685 }
686 if (rmleadslash && arcn->ln_name[0] == '/' &&
687 (arcn->type == PAX_HLK || arcn->type == PAX_HRG)) {
688 if (arcn->ln_name[1] == '\0') {
689 arcn->ln_name[0] = '.';
690 } else {
691 (void)memmove(arcn->ln_name, &arcn->ln_name[1],
692 strlen(arcn->ln_name));
693 arcn->ln_nlen--;
694 }
695 if (rmleadslash < 2) {
696 rmleadslash = 2;
697 paxwarn(0, "Removing leading / from absolute path names in the archive");
698 }
699 }
700
701 /*
666 * IMPORTANT: We have a problem. what do we do with symlinks?
667 * Modifying a hard link name makes sense, as we know the file it
668 * points at should have been seen already in the archive (and if it
669 * wasn't seen because of a read error or a bad archive, we lose
670 * anyway). But there are no such requirements for symlinks. On one
671 * hand the symlink that refers to a file in the archive will have to
672 * be modified to so it will still work at its new location in the
673 * file system. On the other hand a symlink that points elsewhere (and

--- 24 unchanged lines hidden (view full) ---

698 if (iflag) {
699 /*
700 * perform interactive file rename, then map the link if any
701 */
702 if ((res = tty_rename(arcn)) != 0)
703 return(res);
704 if ((arcn->type == PAX_SLK) || (arcn->type == PAX_HLK) ||
705 (arcn->type == PAX_HRG))
702 * IMPORTANT: We have a problem. what do we do with symlinks?
703 * Modifying a hard link name makes sense, as we know the file it
704 * points at should have been seen already in the archive (and if it
705 * wasn't seen because of a read error or a bad archive, we lose
706 * anyway). But there are no such requirements for symlinks. On one
707 * hand the symlink that refers to a file in the archive will have to
708 * be modified to so it will still work at its new location in the
709 * file system. On the other hand a symlink that points elsewhere (and

--- 24 unchanged lines hidden (view full) ---

734 if (iflag) {
735 /*
736 * perform interactive file rename, then map the link if any
737 */
738 if ((res = tty_rename(arcn)) != 0)
739 return(res);
740 if ((arcn->type == PAX_SLK) || (arcn->type == PAX_HLK) ||
741 (arcn->type == PAX_HRG))
706 sub_name(arcn->ln_name, &(arcn->ln_nlen));
742 sub_name(arcn->ln_name, &(arcn->ln_nlen), sizeof(arcn->ln_name));
707 }
708 return(res);
709}
710
711/*
712 * tty_rename()
713 * Prompt the user for a replacement file name. A "." keeps the old name,
714 * a empty line skips the file, and an EOF on reading the tty, will cause

--- 55 unchanged lines hidden (view full) ---

770
771 /*
772 * ok the name changed. We may run into links that point at this
773 * file later. we have to remember where the user sent the file
774 * in order to repair any links.
775 */
776 tty_prnt("Processing continues, name changed to: %s\n", tmpname);
777 res = add_name(arcn->name, arcn->nlen, tmpname);
743 }
744 return(res);
745}
746
747/*
748 * tty_rename()
749 * Prompt the user for a replacement file name. A "." keeps the old name,
750 * a empty line skips the file, and an EOF on reading the tty, will cause

--- 55 unchanged lines hidden (view full) ---

806
807 /*
808 * ok the name changed. We may run into links that point at this
809 * file later. we have to remember where the user sent the file
810 * in order to repair any links.
811 */
812 tty_prnt("Processing continues, name changed to: %s\n", tmpname);
813 res = add_name(arcn->name, arcn->nlen, tmpname);
778 arcn->nlen = l_strncpy(arcn->name, tmpname, PAXPATHLEN+1);
779 arcn->name[PAXPATHLEN] = '\0';
814 arcn->nlen = l_strncpy(arcn->name, tmpname, sizeof(arcn->name) - 1);
815 arcn->name[arcn->nlen] = '\0';
780 if (res < 0)
781 return(-1);
782 return(0);
783}
784
785/*
786 * set_dest()
787 * fix up the file name and the link name (if any) so this file will land

--- 412 unchanged lines hidden ---
816 if (res < 0)
817 return(-1);
818 return(0);
819}
820
821/*
822 * set_dest()
823 * fix up the file name and the link name (if any) so this file will land

--- 412 unchanged lines hidden ---