home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload
/
ShartewareOverload.cdr
/
progm
/
cpgms.zip
/
CCASE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1985-11-17
|
3KB
|
139 lines
#include "stdio.h"
#define END 0xff
#define ERROR 0
#define CPMEOF 0X1A
#define UPPER 0
#define LOWER 1
#define WORDS -1
#define NULL 0
#define DeSmet 1
char *documentation[] = {
"ccase changes the case of a sequential file.",
" ccase [flags] [file] [<file] [>file]",
"",
"Flags are single characters preceeded by '-':",
" -w 1st letter of each word is upper case",
" -u All letters are upper case",
" -l All letters are lower case",
"",
"Input is from the given file or stdin, if none given.",
"Output is to stdout. To print add >PRN: to your command.",
0 };
int tflg = 0;
main(argc, argv)
char *argv[];
{
register char *p;
register int c, i;
int nfile;
char tolower();
FILE *f;
if (argc == 2 && argv[1][0] == '?' && argv[1][1] == 0) {
help(documentation);
return;
}
nfile = argc-1;
for (i=1; i < argc; ++i) {
p = argv[i];
if (*p == '-') {
++p;
while (c = *p++) {
switch(tolower(c)) {
case '?':
help(documentation);
break;
case 'W':
case 'w':
tflg = WORDS;
break;
case 'U':
case 'u':
tflg = UPPER;
break;
case 'L':
case 'l':
tflg = LOWER;
break;
default:
usage("Unknown flag");
}
}
argv[i] = 0;
--nfile;
}
}
if (nfile == 0)
ccase(stdin, 0);
else if (nfile > 1)
usage("Too many filenames");
else
if ((f=fopen(p, "r")) == NULL)
cant(p);
else {
ccase(f, p);
fclose(f);
}
}
/*******************************************************/
usage(s)
char *s;
{
puts("?LIST-E-");
puts(s);
puts("\n");
puts("Usage: ccase [-wul] [file] [<file] [>file]. \n");
puts(" ccase ? for help\n");
exit(1);
}
/*******************************************************/
ccase(fp, fn)
FILE *fp; /* File to process */
char *fn; /* File name (for -f option) */
/*
* change the case of the input file to upper, lower, or words.
*/
{
char c, getc(), putc(), toupper(), tolower();
int iflg, isalpha();
iflg = 1;
while (((c = getc(fp)) != CPMEOF) && (c != END)) {
#if DeSmet
if (c == '\r')
continue;
#endif
if (tflg == UPPER)
putc(toupper(c),stdout);
else if (tflg == LOWER)
putc(tolower(c),stdout);
else {
if (iflg)
putc(toupper(c),stdout);
else
putc(tolower(c),stdout);
if (!isalpha(c))
iflg = 1;
else
iflg = 0;
}
}
}