11590Srgrimes/*- 21590Srgrimes * Copyright (c) 1990, 1993, 1994 31590Srgrimes * The Regents of the University of California. All rights reserved. 41590Srgrimes * 51590Srgrimes * This code is derived from software contributed to Berkeley by 61590Srgrimes * Cimarron D. Taylor of the University of California, Berkeley. 71590Srgrimes * 81590Srgrimes * Redistribution and use in source and binary forms, with or without 91590Srgrimes * modification, are permitted provided that the following conditions 101590Srgrimes * are met: 111590Srgrimes * 1. Redistributions of source code must retain the above copyright 121590Srgrimes * notice, this list of conditions and the following disclaimer. 131590Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 141590Srgrimes * notice, this list of conditions and the following disclaimer in the 151590Srgrimes * documentation and/or other materials provided with the distribution. 161590Srgrimes * 4. Neither the name of the University nor the names of its contributors 171590Srgrimes * may be used to endorse or promote products derived from this software 181590Srgrimes * without specific prior written permission. 191590Srgrimes * 201590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 211590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 221590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 231590Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 241590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 251590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 261590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 271590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 281590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 291590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 301590Srgrimes * SUCH DAMAGE. 311590Srgrimes */ 321590Srgrimes 33207705Sdelphij#ifndef lint 34207705Sdelphij#if 0 35207705Sdelphijstatic char sccsid[] = "@(#)misc.c 8.2 (Berkeley) 4/1/94"; 36207705Sdelphij#else 37207705Sdelphij#endif 38207705Sdelphij#endif /* not lint */ 39207705Sdelphij 4093604Sobrien#include <sys/cdefs.h> 4193604Sobrien__FBSDID("$FreeBSD$"); 421590Srgrimes 431590Srgrimes#include <sys/types.h> 441590Srgrimes#include <sys/stat.h> 451590Srgrimes 461590Srgrimes#include <err.h> 47200462Sdelphij#include <errno.h> 481590Srgrimes#include <fts.h> 491590Srgrimes#include <stdio.h> 501590Srgrimes#include <stdlib.h> 511590Srgrimes#include <string.h> 521590Srgrimes 531590Srgrimes#include "find.h" 548874Srgrimes 551590Srgrimes/* 561590Srgrimes * brace_subst -- 571590Srgrimes * Replace occurrences of {} in s1 with s2 and return the result string. 581590Srgrimes */ 591590Srgrimesvoid 60116333Smarkmbrace_subst(char *orig, char **store, char *path, int len) 611590Srgrimes{ 6291400Sdwmalone int plen; 6391400Sdwmalone char ch, *p; 641590Srgrimes 651590Srgrimes plen = strlen(path); 661590Srgrimes for (p = *store; (ch = *orig) != '\0'; ++orig) 671590Srgrimes if (ch == '{' && orig[1] == '}') { 681590Srgrimes while ((p - *store) + plen > len) 691590Srgrimes if (!(*store = realloc(*store, len *= 2))) 701590Srgrimes err(1, NULL); 711590Srgrimes memmove(p, path, plen); 721590Srgrimes p += plen; 731590Srgrimes ++orig; 741590Srgrimes } else 751590Srgrimes *p++ = ch; 761590Srgrimes *p = '\0'; 771590Srgrimes} 781590Srgrimes 791590Srgrimes/* 801590Srgrimes * queryuser -- 811590Srgrimes * print a message to standard error and then read input from standard 82144526Stjr * input. If the input is an affirmative response (according to the 83144526Stjr * current locale) then 1 is returned. 841590Srgrimes */ 851590Srgrimesint 86116333Smarkmqueryuser(char *argv[]) 871590Srgrimes{ 88144526Stjr char *p, resp[256]; 891590Srgrimes 901590Srgrimes (void)fprintf(stderr, "\"%s", *argv); 911590Srgrimes while (*++argv) 921590Srgrimes (void)fprintf(stderr, " %s", *argv); 931590Srgrimes (void)fprintf(stderr, "\"? "); 941590Srgrimes (void)fflush(stderr); 951590Srgrimes 96144526Stjr if (fgets(resp, sizeof(resp), stdin) == NULL) 97144526Stjr *resp = '\0'; 98144526Stjr if ((p = strchr(resp, '\n')) != NULL) 99144526Stjr *p = '\0'; 100144526Stjr else { 1011590Srgrimes (void)fprintf(stderr, "\n"); 1021590Srgrimes (void)fflush(stderr); 1031590Srgrimes } 104144526Stjr return (rpmatch(resp) == 1); 1051590Srgrimes} 106