1
0

more cleaning

This commit is contained in:
dtb
2022-09-18 00:34:03 -04:00
parent fbdaf55d1c
commit 05c3fad56e
8 changed files with 0 additions and 0 deletions

73
lowercase/lowercase.c Normal file
View File

@@ -0,0 +1,73 @@
#include <ascii.h> /* ASCII_MAX_VALUE */
#include <stdbool.h> /* bool */
#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) */
# include <unicode/umachine.h> /* UChar32 */
# include <unicode/ustdio.h> /* u_fgetc(3) */
#endif /* USE_ICU */
#define PROGRAM_NAME "lowercase"
void
usage(char *name){
fprintf(stderr, "Usage: %s (-f)\n", name);
exit(EX_USAGE);
}
int main(int argc, char *argv[]){
#ifdef USE_ICU
UChar32
#else
int
#endif
c; /* iterating over character stream */
int d; /* iterating over getopt */
bool force;
force = false;
while((d = getopt(argc, argv, "f")) != -1)
switch(d){
case 'f':
force = true;
break;
case '?':
usage(argv[0] != NULL ? argv[0] : PROGRAM_NAME);
break;
}
if(argv[optind] != NULL) /* don't accept arguments */
usage(argv[0] != NULL ? argv[0] : PROGRAM_NAME);
#ifdef USE_ICU
while((c = u_fgetc(stdin)) != U_EOF){
#else
while((c = getc(stdin)) != EOF){
#endif
if(c <= ASCII_MAX_VALUE)
c += ('a' - 'A') * (c >= 'A' && c <= 'Z');
#ifdef USE_ICU
else if(c <= UCHAR_MAX_VALUE)
c = u_tolower(c);
#endif
else if(!force){ /* past supported */
fprintf(
stderr,
"%s: Sorry, extra-ASCII characters are not yet"
" supported!\n",
argv[0] != NULL ? argv[0] : PROGRAM_NAME
);
return EX_SOFTWARE;
}
#ifdef USE_ICU
u_fputc(c, stdout);
#else
putc(c, stdout);
#endif
}
return EX_OK;
}