C
C. Gordon Liddy
Morris Dovey said:c gordon liddy wrote:
[re-ordered for thematic reasons]
It's March Madness. I'm faster than the wind and above the rim.You're welcome - it was satisfying to see you come up to speed
so quickly.
I came up with a result for the -v switch. The testfile is given here:
#include <stdio.h>
int main(void)
{
int c;
printf ("the quick brown fox\n");
for (c = 0; c <= 25; c ++) {
putchar(c);
}
printf ("jumps over\n");
for (c = 100; c <= 200; c ++) {
putchar(c);
}
printf ("the lazy dog\n");
return 0;
}
// gcc -o mkchars mkchars3.c
// mkchars >text52.txt
// catv8.c
#include <stdio.h>
int main(int argc, char **argv)
{
FILE *fp;
void filecopy(FILE *, FILE *);
if (argc < 2) printf("die");
else
while (--argc > 0)
if ((fp = fopen(*++argv, "rb")) == NULL)
{
printf("catv can't open %s\n", *argv);
return 1;
}
else
{
filecopy(fp, stdout);
fclose(fp);
}
return 0;
}
/*filecopy */
void filecopy(FILE *ifp, FILE *ofp)
{
int c;
int ch;
int result;
int ch1 = '^';
int ch2;
int ch3 = 'M';
while((ch=getc(ifp)) != EOF)
{
if (iscntrl(ch))
{
result = putchar(ch1);
if (result == EOF)
{
/* Failed, terminate the loop */
break;
}
if (ch == '\177')
{
/* ch is DEL, we want "^?" */
ch2 = '?';
}
else if(ch == 26)
{
/* we don't want ctrl-z coming out of here */
ch2 = '#';
}
else
{
/*
* ch is another control character.
* Transform 1 to 'A', 2 to 'B', etc. using
* our intimate knowledge of ASCII encoding.
*/
ch2 = ch | 0100;
}
/* Print as above */
result = putchar(ch2);
if (result == EOF)
{
break;
}
// outer brace of if (iscntrl(ch))
}
else if (!isascii(ch))
{
if (putchar('M') == EOF || putchar('-') == EOF)
break;
ch = toascii(ch);
putchar(ch);
}
else putchar(ch);
// outer brace of while control
}
// outer brace of function
}
// gcc -o catv catv8.c >text22.txt 2>text23.txt
// catv text42.txt >text43.txt
Can you see how this compares to running
cat -v text52.txt
?
Can you elaborate? For what I looked at -t option, it didn't seem so. ButSounds good. I wrote a version in which I hijacked the -t option
for defining tab stops (I used -t3 to replace tabs with spaces
for the code you saw) and I suspect that you'll find more handy
features to add.
then ....