[net.sources] vgrind for F77 plus bug fixes

wyatt@cfa.UUCP (Bill Wyatt) (01/07/85)

After noticing Eugene Miya's (eugene@ames) vgrindefs posting for f77
(posted in net.unix-wizards), I thought the equivalent from our site 
should be posted. I have found a few other bugs in the source for
vgrind that apply for any language:

  - If a procedure is not followed by an argument list at declaration
    (only happens for 'program' and 'subroutine' in Fortran or Ratfor, as
    far as I know), the procedure name is not copied into 'pname'.

  - If several files are vgrind'ed at once (as when using the index option),
    the last page of each file has the date of the *next* file. This is
    because the breakpage trap is erroneously executed after the next
    file is opened and its date read in.

I have diff'ed the modified source files (vgrindefs.src, vfontedpr.c, regexp.c,
and tmac.vgrind) against the standard (I believe) Berkeley source, and added
that output below, along with some extra comments.

I also modified the shell script vgrind.sh for our Imagen laser printer
(basically changing 'vtroff' to 'itroff'), but that one is more site-specific.

Bill Wyatt  {harvard,allegra,genrad,ihnp4}!wjh12!cfa!wyatt

***
FILE: vgrindefs.src
Added Fortran definitions, keywords. Since 'program' and 'subroutine'
need not be followed by argument lists, anything after \p must be optional.
so that 'end' is not confused lexically with 'end if', 'endif', etc.,
it is constrained to be followed by nothing except optional blanks.
'go' and 'to' are keywords so that 'goto' and 'go to' are equivalent.
Also, so that the words 'program', 'function', or 'subroutine' are not
seen inside comments, the pb and bb adds the ^\d at the beginning.
***
82a83,96
> fortran|fort|f:\
> 	:pb=^\d(program|subroutine|function)\d\p\d?\a?:\
> 	:bb=^\d(program|subroutine|function)\d\p\d?\a?:\
> 	:be=^\dend\d?$:\
> 	:cb=^(c|C|\*):ce=$:\
> 	:sb=':se=\e':oc:\
> 	:kw=assign backspace block character call close\
> 	common complex continue\
> 	data dimension do double\
> 	else end endfile endif entry equivalence external\
> 	format function go goto if implicit\
> 	include inquire integer intrinsic logical open\
> 	parameter pause precision print program\
> 	read real return save stop subroutine to write:
***
FILE: vfontedpr.c
This fixes the problem of getting the wrong date at the bottom
of the last page of a file listing when there are several files
being printed together. The first 'needbp' statement group is
inserted after the 'printf(".ds =F %s\n",fname);' statement
inside the 'if (!filter)' condition just before the main loop.
It in fact must go inside this construction *after* the point at which
the next file is opened, since the breakpage trap also prints the
bold file name at the top of the next page.
***
257a258,262
> 	    if (needbp) {
> 	        needbp = 0;
> 	        printf(".()\n");
> 	        printf(".bp\n");
> 	    }
266c271
< 	if (needbp) {
---
> 	if (needbp && filter) {
***
FILE: regexp.c
Here are the crucial changes to regexp.c - I have altered the expmatch
procedure (under case META) to allow a True value returned when
the \p or \a options are not followed by more strings to match. In
the \p case where no characters follow, a simple but inelegant copy
is used to determine the correct number of characters to copy into
the pname string.
***
1c1,3
< static char sccsid[] = "@(#)regexp.c	4.1	(Berkeley)	10/19/82";
---
> /*static char sccsid[] = "@(#)regexp.c	4.1	(Berkeley)	10/19/82";
> */
> static char sccsid[] = "@(#)regexp.c	4.1b  (Berkeley + cfa!wyatt) 01/02/85";
2a5,12
> /* Test version of 1/02/85
>    - Attempt at bug fix for Fortran language definition, where the program
>      procedure statement:
>      		program glop
>      does not copy "glop" into the pname field since there is no following
>      expression to match.
> */
> 
294a305,306
> #define isidchr(c) (isalnum(c) || (c) == '_')
> 
306a319
>     short int i;		/* temporary index */
399d411
< 
404,407d415
< 		    } else if (ptr != NIL && (*cs & OPT)) {
< 
< 			/* it was aoptional so no match is ok */
< 			return (ptr);
410,411c418,427
< 			/* not optional and we still matched */
< 			return (NIL);
---
> 			/*we matched but pointers unchanged -
> 			  check for procedure name with nothing
> 			  following or optional field */
> 		  	i=0;
> 			while (isidchr(s1[i]) )
> 				mstring[i] = s1[i++];
> 			mstring[i] = '\0';
> 			ptr += strlen(mstring);
> 			return ( strlen(mstring) | (*cs & OPT) | *cs == 0 
> 				? ptr : NIL );
413c429
< 		    if (!isalnum(*s1) && *s1 != '_')
---
> 		    if (!isidchr(*s1))
438c454
< 			/* it was aoptional so no match is ok */
---
> 			/* it was optional so no match is ok */
442,443c458,462
< 			/* not optional and we still matched */
< 			return (NIL);
---
> 			/* not optional and we still matched -
> 			  if non-zero length, must have been last
> 			  field or end of command descriptor */
> 			ptr += strlen(s1);
> 			return ( *cs == 0 | strlen(s1) ? ptr : NIL );
***
FILE: tmac.vgrind
Lastly, I like the text spaced over more than the default 1-inch left hand
margins (the better for punching holes), so I've added the following to
tmac.vgrind. Note that ll and lt are environment sensitive, while po is not.
***
10a11,16
> 'po 1.375i
> 'll 6.125i
> .ev 2
> 'lt 6.125i
> 'll 6.125i
> .ev

-- 
Bill  {harvard,genrad,allegra,ihnp4}!wjh12!cfa!wyatt