54 lines
1.2 KiB
C
54 lines
1.2 KiB
C
#include <stdio.h> /* fprintf(3), getc(3), putc(3), stderr, stdin, stdout */
|
|
#include <stdlib.h> /* exit(3) */
|
|
#include <sysexits.h> /* EX_OK, EX_USAGE, EX_SOFTWARE */
|
|
#include <unistd.h> /* getopt(3) */
|
|
|
|
/* Enable Unicode support using official Unicode library. */
|
|
#ifdef USE_ICU
|
|
# include <unicode/uchar.h>
|
|
/* UCHAR_MAX_VALUE, u_tolower(3), u_toupper(3) */
|
|
# include <unicode/umachine.h> /* UChar32 */
|
|
# include <unicode/ustdio.h> /* u_fgetc(3) */
|
|
#else
|
|
# include <ctype.h> /* tolower(3), toupper(3) */
|
|
#endif /* USE_ICU */
|
|
|
|
#define ASCII_MAX_VALUE 0x7F
|
|
|
|
int main(int argc, char *argv[]){
|
|
#ifdef USE_ICU
|
|
UChar32
|
|
#else
|
|
int
|
|
#endif
|
|
c; /* iterating over character stream */
|
|
|
|
if(argc > 1){
|
|
fprintf(stderr, "Usage: %s\n", argv[0]);
|
|
return EX_USAGE;
|
|
}
|
|
|
|
|
|
#ifdef USE_ICU
|
|
while((c = u_fgetc(stdin)) != U_EOF){
|
|
if(c <= UCHAR_MAX_VALUE && c >= 0)
|
|
# ifdef LOWERCASE
|
|
c = u_tolower(c);
|
|
# else
|
|
c = u_toupper(c);
|
|
# endif /* ifdef LOWERCASE */
|
|
u_fputc(c, stdout);
|
|
#else
|
|
while((c = getc(stdin)) != EOF){
|
|
if(c <= ASCII_MAX_VALUE && c >= 0)
|
|
# ifdef LOWERCASE
|
|
c = tolower(c);
|
|
# else
|
|
c = toupper(c);
|
|
# endif /* ifdef LOWERCASE */
|
|
putc(c, stdout);
|
|
#endif /* ifdef USE_ICU */
|
|
}
|
|
return EX_OK;
|
|
}
|