another version of cpr

Richard A. Johnson raj at zeppo.UUCP
Fri Aug 26 11:54:50 AEST 1983


I tried the cpr (C print) program and noticed two problems.  First, and
mentioned in the manual page, structure declarations are treated like
functions (i.e., given extra white space after the '}').  Second, tabs
are always converted to exactly 8 spaces (this is annoying if you use tabs
to line up columns).

I fixed the first problem by looking for a ';' after the '}' (most structure
declarations that I have seen end with "};" whereas functions just end with
'}').  If there is a ';' there, the '}' is treated like any other character.
If not, then it is a function and given extra white space.

I fixed the second problem by substituting one space for the tab.  Then I add
more spaces, if necessary, until the next character position is a tab stop.

My fixes to cpr.c follow:

273c273,276
< 					bp = 1;
---
> 					if( *(l+1) == ';' )
> 						++l;
> 					else
> 						bp = 1;
613c616,617
<  *	of the tab character with 8 (eight) spaces.  The function returns
---
>  *	of the tab character with enough spaces to put the next character
>  *	at the next tab stop.  The function returns
633,634c637,639
< 			strcpy(&retstr[count], "        ");
< 			count += 7;
---
> 			retstr[count] = ' ';
> 			while (((count + 1) % 8) != 0)
> 				retstr[++count] = ' ';

Rich Johnson
BTL - Whippany
zeppo!raj



More information about the Comp.sources.unix mailing list