Path: utzoo!utgpu!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!zardoz.cpd.com!anacom1!jim From: jim@anacom1.UUCP (Jim Bacon) Newsgroups: alt.sources.wanted Subject: Re: lowercase routine. Message-ID: <374@anacom1.UUCP> Date: 10 Sep 90 07:25:27 GMT References: <745@babcock.cerc.wvu.wvnet.edu> Reply-To: jim@anacom1.UUCP (Jim Bacon, CPD Manager) Organization: Anacom CPD, Anaheim, CA Lines: 139 In article mdb@ESD.3Com.COM (Mark D. Baushke) writes: >On 7 Sep 90 15:31:31 GMT, pac@cathedral.cerc.wvu.wvnet.edu (Michael A. >Packer) said: > >Michael> does anyone have a routine which can be compiled on UNIX that >Michael> will read the current directory and convert all upcase names >Michael> to lowercase? > >Michael> if there was a file called >Michael> READ.ME it would simply be converted to read.me > >Michael> maybe some kind of script ??? > >A perl script perhaps? See below. >-- >Mark D. Baushke >mdb@ESD.3Com.COM > Here is a quick one I wrote to do the job a couple of years ago in C. It might be useful to Michael (or others, like me :-) ) if perl is not available. (I know, I know, just haven't had time to follow the pacthes.) ---------------- cut here ---------------- #! /bin/sh # This is a shell archive. Remove anything before this line, then feed it # into a shell via "sh file" or similar. To overwrite existing files, # type "sh file -c". # The tool that generated this appeared in the comp.sources.unix newsgroup; # send mail to comp-sources-unix@uunet.uu.net if you want that tool. # If this archive is complete, you will see the following message at the end: # "End of shell archive." # Contents: mvlc.c # Wrapped by jim@anacom1 on Mon Sep 10 00:15:52 1990 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'mvlc.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'mvlc.c'\" else echo shar: Extracting \"'mvlc.c'\" \(1697 characters\) sed "s/^X//" >'mvlc.c' <<'END_OF_FILE' X/* X* mvlc - move lowercase X* v1.0 8/20/88 X* written by Jim Bacon, anacom1!jim X* X* Convert an all uppercase filename to lowercase. Names with lowercase X* letters will be ignored as will filenames which already have lowercase X* equivilents present. Original filename will be removed from the X* directory if conversion is sucessful. X* X* Usage - mvlc [FOOBAR.FIL] X*/ X X#include X#include X#include X#include X#include X#include X X#define TRUE 1 X Xint mv_lower(); Xchar *convert(); X Xmain(argc,argv) X int argc; X char *argv[]; X{ Xint i; Xchar *lc_name; Xstruct stat sbuf; X X if ( argc == 1 ) X { X fprintf(stderr,"usage: mvlc file ...\n"); X exit(2); X } X X for ( i=1; i < argc; i++ ) X { X if ( stat(argv[i],&sbuf) ) X fprintf(stderr,"%s: stat() failed, errno %d\n", X argv[i],errno); X else if ( sbuf.st_mode & 0070000 ) X fprintf(stderr,"%s: not a regular file\n",argv[i]); X else if ( lc_name = convert(argv[i]) ) X mv_lower(argv[i],lc_name); X } X X} X Xchar *convert(uc_name) X char uc_name[]; X{ Xstatic char lc_name[BUFSIZ]; Xchar *fname; Xint i,all_uc = TRUE; X X strcpy(lc_name,uc_name); X fname = strrchr(uc_name,'/'); X for ( i = fname ? ++fname - uc_name : 0; X uc_name[i] && (all_uc = !islower(uc_name[i])); i++ ) X lc_name[i] = tolower(uc_name[i]); X lc_name[i] = '\0'; X Xreturn(all_uc ? lc_name : NULL); X} X Xint mv_lower(uc_name,lc_name) X char *uc_name,*lc_name; X{ Xint mv_err; X X if ( mv_err = link(uc_name,lc_name) ) X fprintf(stderr,"%s: link() to %s failed, errno %d\n", X uc_name,lc_name,errno); X else if ( mv_err = unlink(uc_name) ) X fprintf(stderr,"%s: unlink() failed, errno %d\n", X uc_name,errno); X Xreturn(mv_err); X} END_OF_FILE echo shar: NEWLINE appended to \"'mvlc.c'\" if test 1698 -ne `wc -c <'mvlc.c'`; then echo shar: \"'mvlc.c'\" unpacked with wrong size! fi # end of 'mvlc.c' fi echo shar: End of shell archive. exit 0 -- Jim Bacon | "A computer's attention span is only Anacom General Corp., CA | as long as its extension cord." jim@anacom1.cpd.com | zardoz!anacom1!jim | Anon