Annotation of 43BSDReno/usr.bin/find/misc.c, revision 1.1.1.1

1.1       root        1: /*-
                      2:  * Copyright (c) 1990 The Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * This code is derived from software contributed to Berkeley by
                      6:  * Cimarron D. Taylor of the University of California, Berkeley.
                      7:  *
                      8:  * Redistribution and use in source and binary forms are permitted provided
                      9:  * that: (1) source distributions retain this entire copyright notice and
                     10:  * comment, and (2) distributions including binaries display the following
                     11:  * acknowledgement:  ``This product includes software developed by the
                     12:  * University of California, Berkeley and its contributors'' in the
                     13:  * documentation or other materials provided with the distribution and in
                     14:  * all advertising materials mentioning features or use of this software.
                     15:  * Neither the name of the University nor the names of its contributors may
                     16:  * be used to endorse or promote products derived from this software without
                     17:  * specific prior written permission.
                     18:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
                     19:  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
                     20:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     21:  */
                     22: 
                     23: #ifndef lint
                     24: static char sccsid[] = "@(#)misc.c     5.2 (Berkeley) 5/12/90";
                     25: #endif /* not lint */
                     26: 
                     27: #include <sys/types.h>
                     28: #include <sys/stat.h>
                     29: #include <stdio.h>
                     30: #include "find.h"
                     31:  
                     32: /*
                     33:  * find_subst --
                     34:  *     Replace occurrences of {} in s1 with s2 and return the result string.
                     35:  */
                     36: find_subst(orig, store, path, len)
                     37:        char *orig, **store, *path;
                     38:        int len;
                     39: {
                     40:        register int plen;
                     41:        register char ch, *p;
                     42:        char *realloc(), *strerror();
                     43: 
                     44:        plen = strlen(path);
                     45:        for (p = *store; ch = *orig; ++orig)
                     46:                if (ch == '{' && orig[1] == '}') {
                     47:                        while ((p - *store) + plen > len)
                     48:                                if (!(*store = realloc(*store, len *= 2))) {
                     49:                                        (void)fprintf(stderr,
                     50:                                            "find: %s.\n", strerror(errno));
                     51:                                        exit(1);
                     52:                                }
                     53:                        bcopy(path, p, plen);
                     54:                        p += plen;
                     55:                        ++orig;
                     56:                } else
                     57:                        *p++ = ch;
                     58:        *p = '\0';
                     59: }
                     60: 
                     61: /*
                     62:  * find_queryuser --
                     63:  *     print a message to standard error and then read input from standard
                     64:  *     input. If the input is 'y' then 1 is returned.
                     65:  */
                     66: find_queryuser(argv)
                     67:        register char **argv;
                     68: {
                     69:        char buf[10];
                     70: 
                     71:        (void)fprintf(stderr, "\"%s", *argv);
                     72:        while (*++argv)
                     73:                (void)fprintf(stderr, " %s", *argv);
                     74:        (void)fprintf(stderr, "\"? ");
                     75:        (void)fflush(stderr);
                     76:        return(!fgets(buf, sizeof(buf), stdin) || buf[0] != 'y' ? 0 : 1);
                     77: }
                     78:  
                     79: /*
                     80:  * bad_arg --
                     81:  *     print out a bad argument message.
                     82:  */
                     83: void
                     84: bad_arg(option, error)
                     85:        char *option, *error;
                     86: {
                     87:        (void)fprintf(stderr, "find: %s: %s.\n", option, error);
                     88:        exit(1);
                     89: }
                     90:  
                     91: /*
                     92:  * emalloc --
                     93:  *     malloc with error checking.
                     94:  */
                     95: char *
                     96: emalloc(len)
                     97:        u_int len;
                     98: {
                     99:        char *p, *malloc(), *strerror();
                    100: 
                    101:        if (!(p = malloc(len))) {
                    102:                (void)fprintf(stderr, "find: %s.\n", strerror(errno));
                    103:                exit(1);
                    104:        }
                    105:        return(p);
                    106: }
                    107: 
                    108: usage()
                    109: {
                    110:        extern int deprecated;
                    111: 
                    112:        if (deprecated)
                    113:                (void)fprintf(stderr, "usage: find path-list expression\n");
                    114:        else
                    115:                (void)fprintf(stderr,
                    116:                    "usage: find [-dsx] -f path ... expression\n");
                    117:        exit(1);
                    118: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.