Lines Matching +full:exact +full:- +full:len
1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
49 * copy (-rw). Both file name and link names are adjusted as required in these
68 * parses the -s replacement string; compiles the regular expression
79 * the list of replacement patterns; -1 otherwise.
96 return(-1); in rep_add()
105 return(-1); in rep_add()
114 return(-1); in rep_add()
118 if ((res = regcomp(&(rep->rcmp), str+1, 0)) != 0) { in rep_add()
119 regerror(res, &(rep->rcmp), rebuf, sizeof(rebuf)); in rep_add()
122 return(-1); in rep_add()
132 regfree(&rep->rcmp); in rep_add()
135 return(-1); in rep_add()
139 rep->nstr = pt1; in rep_add()
141 rep->flgs = 0; in rep_add()
150 rep->flgs |= GLOB; in rep_add()
154 rep->flgs |= PRNT; in rep_add()
157 regfree(&rep->rcmp); in rep_add()
161 return(-1); in rep_add()
169 rep->fow = NULL; in rep_add()
174 reptail->fow = rep; in rep_add()
187 * 0 if the pattern was added to the list, -1 otherwise
200 return(-1); in pat_add()
210 return(-1); in pat_add()
213 pt->pstr = str; in pat_add()
214 pt->pend = NULL; in pat_add()
215 pt->plen = strlen(str); in pat_add()
216 pt->fow = NULL; in pat_add()
217 pt->flgs = 0; in pat_add()
218 pt->chdname = chdnam; in pat_add()
224 pattail->fow = pt; in pat_add()
245 for (pt = pathead; pt != NULL; pt = pt->fow) { in pat_chk()
246 if (pt->flgs & MTCH) in pat_chk()
252 (void)fprintf(stderr, "%s\n", pt->pstr); in pat_chk()
259 * pattern as having selected an archive member. arcn->pat points at the
260 * pattern that was matched. arcn->pat is set in pat_match()
262 * NOTE: When the -c option is used, we are called when there was no match
264 * the logic). Now this seems really strange at first, but with -c we
268 * 0 if the pattern pointed at by arcn->pat was tagged as creating a
269 * match, -1 otherwise.
277 int len; in pat_sel() local
282 if ((pathead == NULL) || ((pt = arcn->pat) == NULL)) in pat_sel()
290 pt->flgs |= MTCH; in pat_sel()
296 * pattern, if the pattern matches a directory and we do not have -d in pat_sel()
299 * with -d, this pattern was already selected and we are done in pat_sel()
301 if (pt->flgs & DIR_MTCH) in pat_sel()
304 if (!dflag && ((pt->pend != NULL) || (arcn->type == PAX_DIR))) { in pat_sel()
307 * subtree matches but because of the -n only its children will in pat_sel()
309 * WATCH IT, the code assumes that pt->pend points in pat_sel()
310 * into arcn->name and arcn->name has not been modified. in pat_sel()
316 * so we can copy it. Future matches will be exact prefix match in pat_sel()
318 if (pt->pend != NULL) in pat_sel()
319 *pt->pend = '\0'; in pat_sel()
321 if ((pt->pstr = strdup(arcn->name)) == NULL) { in pat_sel()
323 if (pt->pend != NULL) in pat_sel()
324 *pt->pend = '/'; in pat_sel()
325 pt->pend = NULL; in pat_sel()
326 return(-1); in pat_sel()
332 if (pt->pend != NULL) { in pat_sel()
333 *pt->pend = '/'; in pat_sel()
334 pt->pend = NULL; in pat_sel()
336 pt->plen = strlen(pt->pstr); in pat_sel()
341 len = pt->plen - 1; in pat_sel()
342 if (*(pt->pstr + len) == '/') { in pat_sel()
343 *(pt->pstr + len) = '\0'; in pat_sel()
344 pt->plen = len; in pat_sel()
346 pt->flgs = DIR_MTCH | MTCH; in pat_sel()
347 arcn->pat = pt; in pat_sel()
354 * Seems kind of strange to do for a -c, but the pax spec is really in pat_sel()
355 * vague on the interaction of -c -n and -d. We assume that when -c in pat_sel()
357 * In effect we place the order of the flags as having -c last. in pat_sel()
361 while ((pt != NULL) && (pt != arcn->pat)) { in pat_sel()
362 ppt = &(pt->fow); in pat_sel()
363 pt = pt->fow; in pat_sel()
371 return(-1); in pat_sel()
373 *ppt = pt->fow; in pat_sel()
375 arcn->pat = NULL; in pat_sel()
382 * is found, arcn->pat is set to point at the potential pattern. Later if
387 * skipped and -1 if we are done with all patterns (and pax should quit
396 arcn->pat = NULL; in pat_match()
399 * if there are no more patterns and we have -n (and not -c) we are in pat_match()
404 return(-1); in pat_match()
417 if (pt->flgs & DIR_MTCH) { in pat_match()
420 * as we must have -n set for this (but not -d). We can in pat_match()
422 * an exact prefix match (no wildcards). in pat_match()
424 if ((arcn->name[pt->plen] == '/') && in pat_match()
425 (strncmp(pt->pstr, arcn->name, pt->plen) == 0)) in pat_match()
427 } else if (fn_match(pt->pstr, arcn->name, &pt->pend) == 0) in pat_match()
429 pt = pt->fow; in pat_match()
433 * return the result, remember that cflag (-c) inverts the sense of a in pat_match()
440 * We had a match, now when we invert the sense (-c) we reject this in pat_match()
444 arcn->pat = pt; in pat_match()
449 return(-1); in pat_match()
450 arcn->pat = NULL; in pat_match()
458 * skipped and -1 if we are done with all patterns (and pax should quit
474 * Ok we found an exact match in fn_match()
483 return(-1); in fn_match()
493 return (-1); in fn_match()
517 return (-1); in fn_match()
524 return (-1); in fn_match()
529 return (-1); in fn_match()
554 if ((*pattern == '-') && ((c2 = pattern[1]) != '\0') && in range_match()
576 * 0 continue to process file, 1 skip this file, -1 pax is finished
588 if (rmleadslash && arcn->name[0] == '/') { in mod_name()
589 if (arcn->name[1] == '\0') { in mod_name()
590 arcn->name[0] = '.'; in mod_name()
592 (void)memmove(arcn->name, &arcn->name[1], in mod_name()
593 strlen(arcn->name)); in mod_name()
594 arcn->nlen--; in mod_name()
601 if (rmleadslash && arcn->ln_name[0] == '/' && in mod_name()
602 (arcn->type == PAX_HLK || arcn->type == PAX_HRG)) { in mod_name()
603 if (arcn->ln_name[1] == '\0') { in mod_name()
604 arcn->ln_name[0] = '.'; in mod_name()
606 (void)memmove(arcn->ln_name, &arcn->ln_name[1], in mod_name()
607 strlen(arcn->ln_name)); in mod_name()
608 arcn->ln_nlen--; in mod_name()
628 * to be correct since it applies to a single file and is an exact in mod_name()
640 if ((res = rep_name(arcn->name, &(arcn->nlen), 1)) != 0) in mod_name()
643 if (((arcn->type == PAX_SLK) || (arcn->type == PAX_HLK) || in mod_name()
644 (arcn->type == PAX_HRG)) && in mod_name()
645 ((res = rep_name(arcn->ln_name, &(arcn->ln_nlen), 0)) != 0)) in mod_name()
655 if ((arcn->type == PAX_SLK) || (arcn->type == PAX_HLK) || in mod_name()
656 (arcn->type == PAX_HRG)) in mod_name()
657 sub_name(arcn->ln_name, &(arcn->ln_nlen), sizeof(arcn->ln_name)); in mod_name()
669 * 0 process this file, 1 skip this file, -1 we need to exit pax
692 return(-1); in tty_rename()
722 res = add_name(arcn->name, arcn->nlen, tmpname); in tty_rename()
723 arcn->nlen = l_strncpy(arcn->name, tmpname, sizeof(arcn->name) - 1); in tty_rename()
724 arcn->name[arcn->nlen] = '\0'; in tty_rename()
726 return(-1); in tty_rename()
733 * in the destination directory (used during copy() -rw).
735 * 0 if ok, -1 if failure (name too long)
741 if (fix_path(arcn->name, &(arcn->nlen), dest_dir, dir_len) < 0) in set_dest()
742 return(-1); in set_dest()
749 if ((arcn->type != PAX_HLK) && (arcn->type != PAX_HRG)) in set_dest()
752 if (fix_path(arcn->ln_name, &(arcn->ln_nlen), dest_dir, dir_len) < 0) in set_dest()
753 return(-1); in set_dest()
762 * 0 if ok, -1 if the final name is too long
771 int len; in fix_path() local
784 --dest; in fix_path()
786 if ((len = dest - or_name) > PAXPATHLEN) { in fix_path()
788 return(-1); in fix_path()
790 *or_len = len; in fix_path()
796 *dest-- = *src--; in fix_path()
797 src = dir_name + dir_len - 1; in fix_path()
803 *dest-- = *src--; in fix_path()
805 *(or_name + len) = '\0'; in fix_path()
817 * --Parameters--
865 if (regexec(&(pt->rcmp), inpt, MAXSUBEXP, pm, 0) != 0) in rep_name()
889 if ((res = resub(&(pt->rcmp),pm,inpt,pt->nstr,outpt,endpt)) in rep_name()
908 inpt += pm[0].rm_eo - pm[0].rm_so; in rep_name()
917 } while (pt->flgs & GLOB); in rep_name()
925 pt = pt->fow; in rep_name()
947 if (prnt && (pt->flgs & PRNT)) { in rep_name()
973 * -1 if error, or the number of characters added to the destination.
984 int len; in resub() local
989 subexcnt = rp->re_nsub; in resub()
1001 if ((len = *spt++ - '0') > subexcnt) in resub()
1002 return(-1); in resub()
1003 pmpt = pm + len; in resub()
1017 if ((pmpt->rm_so < 0) || (pmpt->rm_eo < 0) || in resub()
1018 ((len = pmpt->rm_eo - pmpt->rm_so) <= 0)) in resub()
1025 if (len > (destend - dpt)) in resub()
1026 len = destend - dpt; in resub()
1027 if (l_strncpy(dpt, orig + pmpt->rm_so, len) != len) in resub()
1028 return(-1); in resub()
1029 dpt += len; in resub()
1031 return(dpt - dest); in resub()