home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume3
/
rename.sh
< prev
next >
Wrap
Text File
|
1989-02-03
|
25KB
|
1,040 lines
Path: xanth!mcnc!ncsuvx!lll-winken!lll-tis!ames!necntc!ncoast!allbery
From: gandalf@csli.stanford.edu (Juergen Wagner)
Newsgroups: comp.sources.misc
Subject: v03i041: File renaming utility
Message-ID: <8805281852.AA06643@uunet.UU.NET>
Date: 28 May 88 18:51:50 GMT
Sender: allbery@ncoast.UUCP
Reply-To: gandalf@csli.stanford.edu (Juergen Wagner)
Organization: Center for the Study of Language and Information, Stanford U.
Lines: 1026
Approved: allbery@ncoast.UUCP
comp.sources.misc: Volume 3, Issue 41
Submitted-By: "Juergen Wagner" <gandalf@csli.stanford.edu>
Archive-Name: rename.sh
Here comes a file renaming utility. I know, there are nifty shell scripts
and weird sed commands to achieve the same (not to speak of 'tr'). Yet, I
wrote this program to deal with some file renaming problems I had when I
moved several files from VMS and MSDOS to Unix. Anyway, use it if you can,
otherwise...
To unpack the archive, just strip off everything above the "#! /bin/sh" line,
and feed it into /bin/sh. The archive will unpack into a directory "rename".
Just invoking "make" will compile the stuff.
I have compiled the program under Ultrix, BSD4.2, SunOS3.[2-4]. Oh, I mean,
"compiled successfully"! Any bug reports please to gandalf@csli.stanford.edu.
Comments, etc. also to this address. Please consider that I get lotsa e-mail
every day, so try to keep the messages concise.
Enjoy,
Juergen "Gandalf" Wagner, gandalf@csli.stanford.edu
Center for the Study of Language and Information (CSLI), Stanford CA
#! /bin/sh
#
# Archive 'rename.1of1' created by Juergen Wagner at csli
# Date is Sat May 28 11:10:58 1988
#
# This is a shell archive. Remove anything before this line
# then unpack it by saving it in a file and feeding it into sh.
# (Files unpacked will be owned by you and have default permissions).
#
# This archive contains the following files: (use them wisely)
# ./rename/rename.c (4912 bytes)
# ./rename/Makefile (477 bytes)
# ./rename/utils.h (1182 bytes)
# ./rename/gandalf/err.h (443 bytes)
# ./rename/gandalf/file.h (530 bytes)
# ./rename/gandalf/getopt.h (106 bytes)
# ./rename/gandalf/pwd.h (402 bytes)
# ./rename/gandalf/strings.h (627 bytes)
# ./rename/err.c (2220 bytes)
# ./rename/strings.c (2313 bytes)
# ./rename/confirm.c (771 bytes)
# ./rename/enter (3345 bytes)
# ./rename/rename.man (1284 bytes)
#
if `test ! -d ./rename`
then
mkdir ./rename
echo "Create directory ./rename"
fi
if `test ! -s ./rename/rename.c`
then
echo "Extracting ./rename/rename.c"
sed 's/^X//' > ./rename/rename.c << 'foo_bar_and_baz'
X/*
X * Copyright by Juergen Wagner (gandalf@csli.stanford.edu)
X *
X * This file is *NOT* in the public domain. The copyright remains with
X * the author.
X *
X * This file may be copied and redistributed in any form provided that
X * this copyright notice is not changed or removed. It must, however, not
X * be used in any licensed software without the author's consent.
X *
X * Any software containing this file as a whole, or parts of it, has to be
X * distributed free of charge (possibly with a reasonable fee for copying and
X * shipping), and machine-readable sources of this file have to be made
X * accessible.
X *
X */
X
X/*
X * $Compile: cc $CFLAGSD -o rename rename.c ${JWLIB}
X *
X * rename reps.. files...
X *
X * Rename a group of files by applying a set of textual
X * replacements.
X * -v verbose
X * -i ask before overwriting files
X * -l lowercase
X * -t remove trailing dots
X * -<n> cut first <n> chars
X * old=new replace `old' by `new'
X * old= delete `old'
X * ^prefix prefix
X * =suffix suffix
X *
X * Juergen Wagner, Fraunhofer-Institute IAO, Stuttgart
X * Thu Mar 5 19:33:18 MET 1987
X *
X */
X# include <utils.h>
X
X# define MAXREPS 32
X
Xstatic int nreps = 0;
Xstatic char verbose = FALSE;
Xstatic char safe = FALSE;
Xstatic char lower = FALSE;
Xstatic char nodot = FALSE;
Xstatic int start = 0;
Xstatic char *prefix = NULL;
Xstatic char *suffix = NULL;
Xstatic char *reps[MAXREPS][2];
Xstatic int repl[MAXREPS];
Xstatic char *pos;
Xstatic char buffer[MAXPATHLEN];
X
Xstatic char *new_name();
X
X# ifdef STANDALONE
Xmain(argc,argv)
X# else
Xrename_main(argc,argv)
X# endif
Xint argc;
Xchar **argv;
X{
X char *new;
X
X /* Check args */
X# ifdef STANDALONE
X progname = *argv;
X# endif
X argc--;
X while (argc > 0) {
X argc--; argv++;
X if (strcmp("-v",*argv) == 0) {
X verbose = TRUE;
X } else if (strcmp("-i",*argv) == 0) {
X safe = TRUE;
X } else if (strcmp("-l",*argv) == 0) {
X lower = TRUE;
X } else if (strcmp("-t",*argv) == 0) {
X nodot = TRUE;
X } else if ((argv[0][0] == '-') && isdigit(argv[0][1])) {
X start = atoi(*argv + 1);
X if ((start < 0) || (start > 32)) start = 0;
X } else if (argv[0][0] == '^') {
X /* The prefix string */
X if (prefix) usage("Two prefixes??");
X prefix = &argv[0][1];
X } else if (argv[0][0] == '=') {
X /* The suffix string */
X if (suffix) usage("Two suffixes??");
X suffix = &argv[0][1];
X } else if ((pos=index(*argv,'=')) != (char *) 0) {
X if (nreps == MAXREPS) usage("Too many replacements!");
X reps[nreps][0] = *argv;
X reps[nreps][1] = pos+1;
X *pos = '\0';
X repl[nreps] = strlen(reps[nreps][0]);
X nreps++;
X } else {
X if (strcmp(*argv,"--")) {
X argc++;
X } else argv++;
X break;
X }
X }
X
X if (!prefix) prefix = "";
X if (!suffix) suffix = "";
X
X /* Process files (do renaming) */
X if (argc <= 0) usage("No files??");
X if ((nreps == 0) && (*prefix == '\0') && (*suffix == '\0')
X && !lower && !nodot && (start == 0)) {
X usage("No modifications specified");
X }
X
X while (argc > 0) {
X new = new_name(*argv);
X if (!new) {
X fprintf(stderr,"rename: can't rename %s\n",*argv);
X } else if (rename_file(*argv,new)) {
X PWarn(1,"%s",*argv);
X } else if (verbose) {
X printf("Renamed %s to %s\n",*argv,new);
X }
X argc--; argv++;
X }
X exit(0);
X}
X
Xstatic usage(msg)
Xchar *msg;
X{
X Error(1, "%s\nUsage: %s [-i|-v|-l|-t|-<n>|old=new|^pre|=post] files...\n",
X msg, progname);
X /*NOTREACHED*/
X}
X
Xstatic char *new_name(oldname)
Xchar *oldname;
X{
X int i;
X char *ptr, *name;
X
X oldname = name = Copy(oldname,0);
X
X if (start < strlen(name)) {
X name = name + start;
X } else {
X fprintf(stderr,"Too many chars cut off: %d of %s\n", start, name);
X return("");
X }
X
X if (lower) {
X if ((ptr = rindex(name,'/')) == NULL) ptr = name;
X Tolower(ptr);
X }
X
X if (nodot && (name[i = strlen(name)-1] == '.')) name[i] = '\0';
X
X strcpy(buffer,prefix);
X ptr = buffer + strlen(prefix);
X
X do {
X for (i=0; i<nreps; i++) {
X if (strncmp(name,reps[i][0],repl[i]) == 0) {
X strcpy(ptr,reps[i][1]);
X ptr = ptr + strlen(reps[i][1]);
X name = name + repl[i];
X break;
X }
X }
X if (i == nreps) {
X *ptr = *name;
X ptr++; name++;
X }
X } while (*name);
X
X free(oldname);
X strcpy(ptr,suffix);
X return(buffer);
X}
X
Xstatic rename_file(old,new)
Xchar *old, *new;
X{
X if (!strlen(new)) {
X fprintf(stderr,"Null name for %s\n",old);
X return(0);
X }
X if (StrEqual(old,".") || StrEqual(old,"..")) {
X fprintf(stderr, "Can't rename '.' or '..'\n");
X return(0);
X }
X if (StrEqual(new,".") || StrEqual(new,"..")) {
X fprintf(stderr, "Can't rename to '.' or '..'\n");
X return(0);
X }
X if (StrEqual(old,new)) {
X fprintf(stderr,"rename: %s unchanged\n",old);
X return(0);
X }
X if (safe && (access(new, F_OK) == 0)) {
X printf("Replace %s by %s? ",old,new);
X if (confirm()) return(0);
X }
X
X return(rename(old,new));
X}
foo_bar_and_baz
else
echo "will not overwrite ./rename/rename.c"
fi
if `test ! -s ./rename/Makefile`
then
echo "Extracting ./rename/Makefile"
sed 's/^X//' > ./rename/Makefile << 'foo_bar_and_baz'
XPROG = rename.o
X# Usually, these come from my private C library
XOBJS = confirm.o err.o strings.o
X
X# I have those in my environment, so I don't have to specify them every time.
XCFLAGS = -O -I. -DSTANDALONE
XLDFLAGS = -O -z -s
XBINDIR = /usr/local/bin
X
X#---
X
Xall: rename
X
Xinstall: rename
X enter -d $(BINDIR) rename
Xnew:
X make veryclean
X make install
X
Xclean:
X rm -f *.o core
X
Xveryclean:
X rm -f *.o core rename
X
X#---
X
Xrename: $(PROG) $(OBJS)
X cc $(LDFLAGS) -o rename $(PROG) $(OBJS)
foo_bar_and_baz
else
echo "will not overwrite ./rename/Makefile"
fi
if `test ! -s ./rename/utils.h`
then
echo "Extracting ./rename/utils.h"
sed 's/^X//' > ./rename/utils.h << 'foo_bar_and_baz'
X/*
X**
X** Include File for libutils.a
X** Juergen Wagner, FhG-IAO, March 1987
X** Juergen Wagner, CSLI Stanford, April 1988
X**
X*/
X
X# ifndef LIBUTILS_HDR_included
X# define LIBUTILS_HDR_included
X
X# include <stdio.h>
X# include <signal.h>
X# include <ctype.h>
X# ifndef isgraph
X# define isgraph(c) ((_ctype_+1)[c]&(_P|_U|_L|_N))
X# endif isgraph
X# include <sys/param.h>
X
X# include <errno.h>
X# if defined(vax) && !defined(ultrix)
X/* Also very strange: Ultrix and SunOS define errno extern, BSD does not */
Xextern int errno;
X# endif
Xextern int sys_nerr;
Xextern char *sys_errlist[];
X
X# include <sys/stat.h>
X# include <sys/ioctl.h>
X# include <sys/file.h>
X
X# undef MAYBE
X# undef TRUE
X# undef FALSE
X
X# define FALSE 0
X# define TRUE 1
X# define MAYBE 2
X
X# define NIL(type) ((type) 0)
X# define ALLOC(size,type) ((type *) Calloc(size,sizeof(type)))
X
X# define IDENTITY(x) x
X# define CAT(x,y) IDENTITY(x)y
X
Xtypedef union {
X char u_char;
X short u_short;
X int u_int;
X float u_float;
X double u_double;
X char *u_ptr;
X} CObject;
X
X# include <gandalf/err.h>
X# include <gandalf/file.h>
X# include <gandalf/getopt.h>
X# include <gandalf/pwd.h>
X# include <gandalf/strings.h>
X
X# undef min
X# undef max
X
X# endif
foo_bar_and_baz
else
echo "will not overwrite ./rename/utils.h"
fi
if `test ! -d ./rename/gandalf`
then
mkdir ./rename/gandalf
echo "Create directory ./rename/gandalf"
fi
if `test ! -s ./rename/gandalf/err.h`
then
echo "Extracting ./rename/gandalf/err.h"
sed 's/^X//' > ./rename/gandalf/err.h << 'foo_bar_and_baz'
X/*
X * Errors and warnings
X */
X
Xextern void PrintMsg(); /* PrintMsg(flg, errno, exitcode, msg, args) */
Xextern void Error(); /* Error(flag, msg, args..) */
Xextern void Warn(); /* Warn(flag, msg, args..) */
Xextern void PError(); /* PError(flag, msg, args..) */
Xextern void PWarn(); /* PWarn(flag, msg, args..) */
X
Xextern void PrintMsgHook(/*fn, arg*/);
Xextern void PrintStrings(/*file, strings*/);
X
Xextern char *progname;
X
Xextern int confirm();
foo_bar_and_baz
else
echo "will not overwrite ./rename/gandalf/err.h"
fi
if `test ! -s ./rename/gandalf/file.h`
then
echo "Extracting ./rename/gandalf/file.h"
sed 's/^X//' > ./rename/gandalf/file.h << 'foo_bar_and_baz'
X/*
X** File Access Functions
X*/
X
Xextern int FCat();
Xextern int CopyFile();
X
Xextern char *ExpandName();
X
Xextern int exists(), isdir();
Xextern char *which(), *which_d(), *which_l();
X
Xextern int readlinks();
Xextern char *rmpath(), *rmname(), *rm_butsuffix();
Xextern char *getfs();
X
Xextern int stat(), lstat(), fstat();
Xextern int MapDir();
X
X#define FTW_F 1 /* A file */
X#define FTW_D 2 /* A directory */
X#define FTW_DNR 3 /* A directory that couldn't be read */
X#define FTW_NS 4 /* A stat() failure */
X
Xextern int sftw();
foo_bar_and_baz
else
echo "will not overwrite ./rename/gandalf/file.h"
fi
if `test ! -s ./rename/gandalf/getopt.h`
then
echo "Extracting ./rename/gandalf/getopt.h"
sed 's/^X//' > ./rename/gandalf/getopt.h << 'foo_bar_and_baz'
X/*
X** Extract Options from argv
X*/
X
Xextern char *optarg;
Xextern int optind, opterr;
X
Xextern int getopt();
foo_bar_and_baz
else
echo "will not overwrite ./rename/gandalf/getopt.h"
fi
if `test ! -s ./rename/gandalf/pwd.h`
then
echo "Extracting ./rename/gandalf/pwd.h"
sed 's/^X//' > ./rename/gandalf/pwd.h << 'foo_bar_and_baz'
X/*
X** Header File Describing the /etc/passwd Structure
X*/
X
Xstruct passwd {
X char *pw_name;
X char *pw_passwd;
X int pw_uid;
X int pw_gid;
X int pw_quota;
X char *pw_comment;
X char *pw_gecos;
X char *pw_dir;
X char *pw_shell;
X};
X
Xextern struct passwd *getpwent(), *getpwuid(), *getpwnam();
Xextern int setpwent(), endpwent();
Xextern void setpwfile();
Xextern char *getfullname();
Xextern int getuserid(/*name*/);
foo_bar_and_baz
else
echo "will not overwrite ./rename/gandalf/pwd.h"
fi
if `test ! -s ./rename/gandalf/strings.h`
then
echo "Extracting ./rename/gandalf/strings.h"
sed 's/^X//' > ./rename/gandalf/strings.h << 'foo_bar_and_baz'
X/*
X** String Manipulations
X*/
X
Xextern char *Copy();
Xextern char *Toupper(), *Tolower();
Xextern char *StrCopy();
Xextern char *Malloc(), *Calloc();
X
X# define StrAppend(s1,s2) strcat(Copy((s1),strlen(s2)), s2)
X# define StrEqual(s1,s2) (!strcmp((s1),(s2)))
X
Xextern int match();
X
Xextern char
X *strcpy(), *strncpy(),
X *strcat(), *strncat(),
X *strchr(), *strrchr(),
X *index(), *rindex(),
X *strpbrk(),
X *strtok();
Xextern int
X strcmp(), strncmp(),
X strlen(),
X strspn(), strcspn();
X
Xextern char *malloc(), *calloc(), *alloca();
Xextern char *valloc();
Xextern char *realloc();
Xextern void free(), cfree();
X
Xextern char *getenv();
foo_bar_and_baz
else
echo "will not overwrite ./rename/gandalf/strings.h"
fi
if `test ! -s ./rename/err.c`
then
echo "Extracting ./rename/err.c"
sed 's/^X//' > ./rename/err.c << 'foo_bar_and_baz'
X/*
X * Copyright by Juergen Wagner (gandalf@csli.stanford.edu)
X *
X * This file is *NOT* in the public domain. The copyright remains with
X * the author.
X *
X * This file may be copied and redistributed in any form provided that
X * this copyright notice is not changed or removed. It must, however, not
X * be used in any licensed software without the author's consent.
X *
X * Any software containing this file as a whole, or parts of it, has to be
X * distributed free of charge (possibly with a reasonable fee for copying and
X * shipping), and machine-readable sources of this file have to be made
X * accessible.
X *
X */
X
X/*
X * Package to signal errors and warnings
X * File: Libs/unix/err.c
X *
X */
X
X# include <sys/types.h>
X# include <stdio.h>
X# include <varargs.h>
Xextern int errno;
X
X# define DEFUN(fn,errc,exitc) \
X /*VARARGS*/ \
X void fn(va_alist) \
X va_dcl \
X { \
X va_list args; \
X char *msg; \
X int flag; \
X\
X va_start(args); \
X flag = va_arg(args, int); \
X msg = va_arg(args, char *); \
X PrintMsg(flag, errc, exitc, msg, args); \
X va_end(args); \
X }
X
Xchar *progname = "";
Xstatic int (*printmsg_hook_fn)() = NULL;
Xstatic caddr_t printmsg_hook_fn_arg;
X
Xstatic char *beep()
X{
X return("\007");
X}
X
Xvoid PrintMsg(flag, errcode, exitcode, msg, args)
Xint flag, errcode, exitcode;
Xchar *msg;
Xva_list args;
X{
X extern int sys_nerr;
X extern char *sys_errlist[];
X char *type;
X
X if (flag) {
X type = (exitcode >= 0) ? "fatal error" : "warning";
X fprintf(stderr, "%s: (%s)%s ", progname, type, beep());
X vfprintf(stderr, msg, args);
X fprintf(stderr, "\n");
X if ((errcode >= 0) && (sys_nerr > errcode)) {
X fprintf(stderr, " errcode: %s\n",
X sys_errlist[errcode]);
X }
X if (printmsg_hook_fn)
X printmsg_hook_fn(errcode, exitcode,
X printmsg_hook_fn_arg);
X if (exitcode >= 0)
X exit(exitcode);
X /*NOTREACHED*/
X }
X}
X
XDEFUN(PError,errno,1)
XDEFUN(PWarn,errno,-1)
XDEFUN(Error,-1,1)
XDEFUN(Warn,-1,-1)
X
Xvoid PrintMsgHook(fn, arg)
Xint (*fn)();
Xcaddr_t arg;
X{
X printmsg_hook_fn = fn;
X printmsg_hook_fn_arg = arg;
X}
X
Xvoid PrintStrings(f,strings)
XFILE *f;
Xchar **strings;
X{
X while (*strings) {
X fputs(*strings, f);
X putc('\n', f);
X strings++;
X }
X}
foo_bar_and_baz
else
echo "will not overwrite ./rename/err.c"
fi
if `test ! -s ./rename/strings.c`
then
echo "Extracting ./rename/strings.c"
sed 's/^X//' > ./rename/strings.c << 'foo_bar_and_baz'
X/*
X * Copyright by Juergen Wagner (gandalf@csli.stanford.edu)
X *
X * This file is *NOT* in the public domain. The copyright remains with
X * the author.
X *
X * This file may be copied and redistributed in any form provided that
X * this copyright notice is not changed or removed. It must, however, not
X * be used in any licensed software without the author's consent.
X *
X * Any software containing this file as a whole, or parts of it, has to be
X * distributed free of charge (possibly with a reasonable fee for copying and
X * shipping), and machine-readable sources of this file have to be made
X * accessible.
X *
X */
X
X# include <sys/param.h>
X# include <ctype.h>
X# include <gandalf/strings.h>
X
X/*****************************************************************
X** **
X** String Operations **
X** **
X*****************************************************************/
X
Xchar *Copy(string, extra)
Xchar *string;
Xint extra;
X{
X char *new;
X
X new = malloc(strlen(string)+extra+1);
X if (new == (char *) 0) {
X perror("Copy(malloc)");
X exit(1);
X }
X return( strcpy(new,string) );
X}
X
Xchar *Toupper(string)
Xchar *string;
X{
X register char *s;
X
X for (s = string; *s != '\0'; s++) {
X if (isalpha(*s) && islower(*s)) *s = toupper(*s);
X }
X return(string);
X}
X
Xchar *Tolower(string)
Xchar *string;
X{
X register char *s;
X
X for (s = string; *s != '\0'; s++) {
X if (isalpha(*s) && isupper(*s)) *s = tolower(*s);
X }
X return(string);
X}
X
Xchar *StrCopy(string,c)
Xchar *string, c;
X{
X register char *s;
X register int i;
X
X s = index(string,c);
X if (s == NULL) return(NULL);
X
X i = s - string;
X s = strncpy(Malloc(i + 1), string, i);
X s[i] = '\0';
X return(s);
X}
X
Xchar *Mkstring(n,c)
Xint n;
Xchar c;
X{
X char *string = Malloc(n+1);
X char *pos = string;
X
X for (; n > 0; n--) *(pos++) = c;
X *pos = '\0';
X return(string);
X}
X
X/*****************************************************************
X** **
X** Memory Management **
X** **
X*****************************************************************/
X
Xchar *Malloc(n)
Xint n;
X{
X char *new;
X
X new = malloc(n);
X Error(!new, "can't allocate another %d bytes", n);
X return(new);
X}
X
Xchar *Calloc(n,size)
Xint n, size;
X{
X char *new;
X
X new = calloc(n,size);
X Error(!new, "can't allocate another %d %d-byte segments", n, size);
X return(new);
X}
foo_bar_and_baz
else
echo "will not overwrite ./rename/strings.c"
fi
if `test ! -s ./rename/confirm.c`
then
echo "Extracting ./rename/confirm.c"
sed 's/^X//' > ./rename/confirm.c << 'foo_bar_and_baz'
X/*
X * Copyright by Juergen Wagner (gandalf@csli.stanford.edu)
X *
X * This file is *NOT* in the public domain. The copyright remains with
X * the author.
X *
X * This file may be copied and redistributed in any form provided that
X * this copyright notice is not changed or removed. It must, however, not
X * be used in any licensed software without the author's consent.
X *
X * Any software containing this file as a whole, or parts of it, has to be
X * distributed free of charge (possibly with a reasonable fee for copying and
X * shipping), and machine-readable sources of this file have to be made
X * accessible.
X *
X */
X
X# include <stdio.h>
X# include <ctype.h>
X
Xint confirm()
X{
X int c;
X
X while (!isprint(c = getchar()));
X while (!isspace(getchar()));
X return(c == 'y');
X}
foo_bar_and_baz
else
echo "will not overwrite ./rename/confirm.c"
fi
if `test ! -s ./rename/enter`
then
echo "Extracting ./rename/enter"
sed 's/^X//' > ./rename/enter << 'foo_bar_and_baz'
X#! /bin/csh
X#
X# Copyright by Juergen Wagner (gandalf@csli.stanford.edu)
X#
X# This file is *NOT* in the public domain. The copyright remains with
X# the author.
X#
X# This file may be copied and redistributed in any form provided that
X# this copyright notice is not changed or removed. It must, however, not
X# be used in any licensed software without the author's consent.
X#
X# Any software containing this file as a whole, or parts of it, has to be
X# distributed free of charge (possibly with a reasonable fee for copying and
X# shipping), and machine-readable sources of this file have to be made
X# accessible.
X#
X#
X
X#
X# Install Files (symlinks or copying)
X# Juergen Wagner, March 1987
X#
X# enter [ -s ] [ -d <dir> ] [ -f <origfile> ] [ -g <group> ]
X# [ -c ] [ -p <owner> ] [ -h ] <linknames>
X#
X
X#set echo
Xif ( "x$1" == "x" ) then
X echo 'usage: enter [ -s ] [ -d <dir> ] [ -f <origfile> ]'
X echo ' [ -c ] [ -p <owner> ] [ -h ] <linknames>'
X exit
Xendif
X
Xset strip = ""
Xset dest = ${BINDIR}
Xset perm = 755
Xset group = ""
Xset cmd = "ln -s"
Xset prefix = ""
Xset file = ""
X
Xwhile (1)
X if ( $#argv == 0 ) break
X switch ( "$argv[1]" )
X # Strip file?
X case "-s":
X set strip = "y"
X breaksw
X # Destination directory?
X case "-d":
X shift
X set dest = "$argv[1]"
X breaksw
X # Filename specification?
X case "-f":
X shift
X set file = "$argv[1]"
X if ( "$file" =~ *~ ) then
X echo "enter: I refuse to install backup files: $file"
X exit 0
X endif
X breaksw
X # Permission
X case "-p":
X shift
X set perm = "$argv[1]"
X breaksw
X # Set group
X case "-g":
X shift
X set group = "$argv[1]"
X breaksw
X # Hide file
X case "-h":
X set prefix = '.'
X breaksw
X # Copy instead of linking
X case "-c":
X set cmd = cp
X breaksw
X # File names
X default:
X break
X endsw
X shift
Xend
X
Xif ( "${file}" != "" ) then
X # If multiple links to a single file, strip it now
X if ( "${strip}" == "y" ) strip ${file}
X # Same for protection and group
X if ( "x$group" != "x" ) chgrp ${group} ${file}
X if ( "x$perm" != "x-" ) chmod -f ${perm} ${file}
Xendif
X
Xforeach new ( $argv[1-] )
X # Determine the name of the old file
X if ( "x$file" == "x" ) then
X set oldfile = "${new}"
X else
X set oldfile = "${file}"
X endif
X # Check if the old file exists and is readable
X if ( ! -r "${oldfile}" ) then
X echo " File ${oldfile} does not exist."
X continue
X endif
X # Pathname of installed file
X set newfile = "${dest}/${prefix}${new:t}"
X rm -f ${newfile}
X # Do not install backup files
X if ( "x$new" =~ *~ ) then
X echo " Ignored: backup file $new"
X continue
X endif
X # Establish link and chmod to executable/readable for world
X $cmd `pwd`/${oldfile} ${newfile}
X # Check if link/copy really exists
X if ( ! -r ${newfile} ) then
X echo " Install failed: ${oldfile} => ${newfile}"
X continue
X endif
X if ( "${file}" == "" ) then
X # Change group?
X if ( "x$group" != "x" ) chgrp ${group} ${newfile}
X # Change protection bits?
X if ( "x$perm" != "x-" ) chmod -f ${perm} ${newfile}
X # Strip file?
X if ( "${strip}" == "y" ) strip ${newfile}
X endif
X if ( "${newfile:t}" == "${oldfile:t}" ) then
X echo " Installed ${oldfile} in directory ${dest}"
X else
X echo " Installed: ${oldfile} => ${newfile}"
X endif
Xend
X
Xexit 0
foo_bar_and_baz
else
echo "will not overwrite ./rename/enter"
fi
if `test ! -s ./rename/rename.man`
then
echo "Extracting ./rename/rename.man"
sed 's/^X//' > ./rename/rename.man << 'foo_bar_and_baz'
X.TH RENAME 1J "5th March, 1987"
X.SH NAME
Xrename - change the names of a set of files
X.SH SYNOPSIS
X.I rename
Xspecs... files...
X.SH DESCRIPTION
X.PP
XRename will change the names of all the given files according to the
Xreplacement instructions and flags supplied in
X.I specs.
XThe following options are available:
X.IP -i
X(interactive) will prompt the user if the resulting file already exists.
X.IP -v
X(verbose) produces a verbose protocol of what the program does.
X.IP -l
X(lowercase) coerces all characters to lowercase characters before any
Xsubstitutions are performed.
X.IP -t
X(trailing dot) remove any trailing dots from the file names before any
Xsubstitutions are performed.
X.IP -\fIn\fP
X(cut chars) cut the first
X.I n
Xcharacters off the original filename before any substitutions are performed.
X.PP
XThe valid replacement specifications are
X.IP old=new
XReplace all occurrences of
X.I old
Xin a file name by the string
X.I new
X(no recursive substitutions, replacement is done left to right).
X.IP string=
XDelete the substring
X.I string
Xin all file names.
X.IP ^prefix
XUse this prefix for all file names.
X.IP =suffix
XAppend this suffix to all file names.
X
X.SH AUTHOR
XJuergen Wagner, CSLI, Stanford University (gandalf@csli.stanford.edu,
Xformerly at Fraunhofer-Institute IAO, Stuttgart, FRG)foo_bar_and_baz
else
echo "will not overwrite ./rename/rename.man"
fi
echo "Finished archive 1 of 1"
# if you want to concatenate archives, remove anything after this line
cat < /dev/null > rename.1of1_done
MISSING=""
for I in 1 ; do
if [ ! -f rename.${I}of1_done ]
then
MISSING="${MISSING} ${I}"
fi
done
cp $0 /usr/tmp; rm -f $0
if [ "${MISSING}" = "" ]
then
echo "You have unpacked the entire archive (1 pieces)."
echo 'See file "rename/rename.man" for instructions.'
rm -f rename.[0-9]*of1_done
echo Archive files now reside on /usr/tmp.
if [ -f ./.install ]
then
echo -n 'Starting up installation. Ok (y/n) ? '
read ANSWER
if [ "$ANSWER" = y ]
then
exec sh .install
fi
fi
else
echo You still need to unpack the following pieces:
echo " " ${MISSING}
fi
exit 0