Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!ames!amdcad!cae780!hplabs!hplabsc!daemon From: daemon@hplabsc.UUCP Newsgroups: comp.mail.elm Subject: Re: Patch: filter suffers from tolower macro probs too Message-ID: <1921@hplabsc.HP.COM> Date: Tue, 2-Jun-87 00:41:28 EDT Article-I.D.: hplabsc.1921 Posted: Tue Jun 2 00:41:28 1987 Date-Received: Thu, 4-Jun-87 01:48:56 EDT Sender: daemon@hplabsc.HP.COM Reply-To: hplabs!rutgers!seismo!scgvaxd!ashtate!mmintl!pwa-b!cjsa!jeff (C. Jeffery Small) Organization: C. Jeffery Small and Associates - New Haven, CT Lines: 57 Approved: taylor@hplabs (with 'postmail') In article <1917@hplabsc.HP.COM>, jimb@dopey.AMD.COM (Jim Budler) writes: > > # define tolower(c) (isupper(c)? (c - 'A' + 'a') : c) > > seems to work. There has been much discussion concerning the usage of the toupper() & tolower() macros on various systems. This has got to be one of the items within "C" which varies most widely from machine to machine. I have seen at least six different styles of macro invocations and function calls for these operations on various machines. System-V.2 currently implements toupper() & tolower() as functions with _toupper() and _tolower() as [somewhat defective] macros. Jim's example above addresses the problem (on some systems) of passing an out-of-range character to the macro which then gets translated to a garbage value. The trouble with this example is that it breaks whenever the argument is anything other than a single character - since the argument "c" will be processed at least twice. For example: tolower('a'); or tolower('X'); both work fine, but ... tolower( getchar() ); gets translated to: isupper( getchar() ) ? (getchar() - 'A' + 'a') : getchar() ); which causes two calls to getchar to be made - yielding unexpected results. There are many other examples of complex argument constructs which cause the typical macro to fail (but will work OK on function calls!) To address this problem, I have developed the following two macros which can take the place of toupper() and tolower(). They will accept any argument and will return a sane (ie. expected) result. "_dumVAR_" is used to store an intermediate result which is what allows the macro to work without resorting to a function call. Note that these invocations simply include the test which isupper() & islower() would perform if included, as in Jim's example above. char _dumVAR_; #define UC(c) (((_dumVAR_ = (c)) >= 'a' && _dumVAR_ <= 'z') ? \ (_dumVAR_ - 'a' + 'A') : _dumVAR_) #define LC(c) (((_dumVAR_ = (c)) >= 'A' && _dumVAR_ <= 'Z') ? \ (_dumVAR_ - 'A' + 'a') : _dumVAR_) To use these macros in the elm system, place them in the sysdefs.h file and then edit the Makefile(s) to include the following defines on the compile lines: -Dtolower=LC -Dtoupper=UC -- Jeffery Small (203) 776-2000 UUCP: ihnp4!---\ C. Jeffery Small and Associates hsi!cjsa!jeff 123 York Street, New Haven, CT 06511 hao!noao!---/