The following command makes vis(1) go through an infinite loop.
Code:
$ printf 'a\tb' | vis -F8
I discovered it while
looking through the code.
I am new to C and I was looking the code in order to learn C. I think I got a solution, I have to test it more, though.
Code:
int
foldit(char *chunk, int col, int max)
{
char *cp;
int newcol;
/*
* Keep track of column position. Insert hidden newline
* if this chunk puts us over the limit.
*/
newcol = 0;
for (cp = chunk; *cp; cp++) {
switch(*cp) {
case '\n':
case '\r':
newcol = col = 0;
break;
case '\t':
col = (col + 8) & ~07;
newcol = (newcol + 8) & ~07;
break;
case '\b':
col = col ? col - 1 : 0;
newcol = newcol ? newcol - 1 : 0;
break;
default:
col++;
newcol++;
}
}
if (col > (max - 2)) {
printf("\\\n");
col = newcol;
}
return (col);
}