[comp.lang.c] moving upper case names to lower case -- Followups to comp.unix.questions

cline@sun.soe.clarkson.edu (Marshall Cline) (08/24/89)

>>In article <20672@adm.BRL.MIL> Leisner.Henr@xerox.com (Marty) writes:
>>>I'm looking for a good, clean way to move files from upper case names
>>>to lower case names. i.e. FOO.C to foo.c
>>>I could always right a C program, but there gotta be a better way.

>In article <9326@chinet.chi.il.us>, john@chinet.chi.il.us (John Mundt) writes:
>>#include <stdio.h>
>>#include <ctype.h>
>>main()
>>{	register int c;
>> 	while ((c = getchar()) != EOF) putchar(tolower(c));
>>}

In article <2336@oakhill.UUCP> stevenw@oakhill.UUCP (Steven Weintraub) writes:
>I should point out there is a risk in using tolower like this.  Some
>machines define tolower as ((c)-'A'+'a') (like some sun systems).
                                                     ^^^
The Gould UTX systems also do this ------------------
Ie: tolower() does exactly what TurboC calls _tolower() -- it _assumes_ its
arg is an upper case letter...

As an answer to the original question (converting files to lowercase),
a simple csh script will do:
	#! /bin/csh -f
	foreach file ($*)
		mv $file `echo $file | tr A-Z a-z`
	end

Marshall
--
	__________________________________________________________________
	Marshall P. Cline	Internet: cline@sun.soe.clarkson.edu
	ECE Department		Usenet:   uunet!sun.soe.clarkson.edu!cline
	Clarkson University	Bitnet:   BH0W@CLUTX
	Potsdam, NY  13676	AT&T:     315-268-6591

gwyn@smoke.BRL.MIL (Doug Gwyn) (08/25/89)

In article <CLINE.89Aug23151847@sun.clarkson.edu> cline@sun.soe.clarkson.edu (Marshall Cline) writes:
>In article <2336@oakhill.UUCP> stevenw@oakhill.UUCP (Steven Weintraub) writes:
>>I should point out there is a risk in using tolower like this.  Some
>>machines define tolower as ((c)-'A'+'a') (like some sun systems).
>The Gould UTX systems also do this ------------------

Basically, it's that way in BSD environments (evolved from 7th Ed. UNIX).
Both SunOS and UTX/32 have System V environments available, in which
tolower() behaves the way required by the C standard.

guy@auspex.auspex.com (Guy Harris) (08/25/89)

 >>I should point out there is a risk in using tolower like this.  Some
 >>machines define tolower as ((c)-'A'+'a') (like some sun systems).
 >                                                     ^^^
 >The Gould UTX systems also do this ------------------
 >Ie: tolower() does exactly what TurboC calls _tolower() -- it _assumes_ its
 >arg is an upper case letter...

"tolower()" was changed from a macro that doesn't check whether its
argument is upper-case to a function that checks whether its argument is
upper-case somewhere around System III or System V.  Systems still using
the older AT&T version of "tolower()" - which pretty much means
BSD-flavored systems - still have a "tolower()" that's an "unsafe"
macro. 

Most such systems have both BSD and System V environments; in the latter
environment, "tolower()" is a safe function and "_tolower()" is the
unsafe macro.  One exception is BSD itself; it has no System V
environment of that sort.  However, ANSI C specifies that "tolower()"
must be a safe function, which means BSD will probably change at some
point (4.4BSD?), and if the other systems continue to offer BSD
environments, they will possibly pick up that change (although the
adoption of standards such as ANSI C and POSIX will, with any luck,
reduce the number of differences between those environments
substantially and reduce the need for multiple environments of that
sort). 

>As an answer to the original question (converting files to lowercase),
>a simple csh script will do:

As long as you have a C shell on your system, which not all people do;
it's generally better to do things with Bourne shell scripts, as opposed
to C shell or Korn shell scripts, for that reason.