/* Capitalizes proper names */ /* See the copyright notice at the end of this file. */ #include #include typedef int bool; #define TRUE 1 #define FALSE 0 /* PROTOTYPES */ int main(int argc, char **argv); void deftables(bool *al, char *up, char *lo); /* Defines arrays that map each ISO Latin-1 character to its upper and lower case forms, respectively. */ void error (char *msg); /* Prints string $*msg$ to $stderr$ and stops. */ void programerror (char *msg, char *file, unsigned int line, char* proc); /* Prints string $file:line: (*proc) *msg$ to $stderr$ and stops. */ #define assert(test, msg) \ { if (!(test)) programerror((msg), __FILE__, __LINE__, __FUNCTION__); } /* If test is false, prints $*msg$ and stops. It is declared as a macro, rather than as a procedure, in order to avoid evaluating $msg$ when $test$ is true. */ /* IMPLEMENTATIONS */ int main(int argc, char **argv) { int c; bool al[256]; /* TRUE for letters */ char up[256]; /* Uppercase mapping table */ char lo[256]; /* Lowercase mapping table */ bool inword = FALSE; /* TRUE between 1st letter and end of name */ assert(argc == 1, "this program takes no parameters"); deftables(al, up, lo); while (TRUE) { c = getchar(); if (c == EOF) break; assert(((c >= 0) && (c <= 255)), "bizarre character in stdin"); if (al[c]) { /* Letter */ putchar((inword ? lo[c] : up[c])); inword = TRUE; } else { /* Non-letter */ inword = FALSE; putchar(c); } } /* DEBUG: printfiles(root); */ fclose(stdout); return 0; } void deftables(bool *al, char *up, char *lo) { int c; /* Default: */ for (c=0; c <= 255; c++) { al[c] = FALSE; up[c] = c; lo[c] = c; } for (c='A'; c <= 'Z'; c++) { al[c] = al[c+32] = TRUE; up[c+32] = c; lo[c] = c+32; } for (c=192; c <= 214; c++) { al[c] = al[c+32] = TRUE; up[c+32] = c; lo[c] = c+32; } for (c=216; c <= 222; c++) { al[c] = al[c+32] = TRUE; up[c+32] = c; lo[c] = c+32; } al[223] = TRUE; /* es-zet */ al[255] = TRUE; /* y-umlaut */ } void error (char *msg) { fprintf (stderr, "*** %s\n", msg); exit(1); } void programerror (char *msg, char *file, unsigned int line, char* proc) { fprintf (stderr, "*** %s:%u: (%s) %s\n", file, line, proc, msg); exit(1); }