[comp.sys.next] F2c translator modifications

guppy@henry.mit.edu (04/15/91)

Here are some modifications to the ATT f2c translator that I have been
using that increase the number of continuation lines and make using f2c
a bit more compatible with most unix f77 compilers. 

The first mod changes the number of allowed continuation lines from 
20 to 60, involving only the lex.c routine. See below...

The second mod changes the behavior of f2c when a routine or variable
has an embedded underscore, e.g. foo_bar.  For some reason the f2c authors
decided that such names should have two added underscores (foo_bar__) for the 
translated C routine rather than one (foo_bar_). Most fortran compilers for unix 
typically add one underscore to fortran symbols.  This extra underscore can cause 
headaches when mixing fortran and C for codes that must run under f2c and f77. 
Specifically, the f2c versions must be hacked to add __ while the f77 
version must have only _. The changes to make the f2c translation 
compatible with "standard" f77 compilers affect only misc.c and proc.c
and are outlined below.

Note that the f2c translator is all that is affected, not the libraries.



diffs for lex.c, misc.c and proc.c  ->  diff  (original code) (modified code)


These diffs change the number of continuation lines to 60.

lex.c ------------------------------------------------------------
66c66
< LOCAL char sbuf[1390];	/* Main buffer for Fortran source input.  The number
---
> LOCAL char sbuf[4030];	/* Main buffer for Fortran source input.  The number
70c70,71
< LOCAL char *send	= sbuf+20*66;
---
> /* hacked for 60 continuation lines  HHY 2/91 */
> LOCAL char *send	= sbuf+60*66;


These diffs change the way f2c makes names for fortran symbols that 
include an underscore.

misc.c ------------------------------------------------------------
352c352,354
< 	t = q->cvarname = mem(c + i + 1, 0);
---
> /* modified code that only adds one _ to each name HHY 4/91 */
> 	t = q->cvarname = mem(c + 1, 0);
354c356
< 	/* add __ to the end of any name containing _ */
---
> 	/* add _ to the end of any name */
357,361c359
< 	if (i) {
< 		t[0] = t[1] = '_';
< 		t[2] = 0;
< 		}
< 	else if (in_vector(s0) >= 0) {
---
> 	if (in_vector(s0) >= 0) {

proc.c ------------------------------------------------------------
1204,1208c1204,1206
< 		for(i = 0; c = *t = *s++; t++)
< 			if (c == '_')
< 				i = 1;
< 		if (i)
< 			*t++ = '_';
---
> /* modified code only adds one _ to each common name HHY 4/91 */
> 		for(i = 0; c = *t = *s++; t++);


*************************************************************************
I have not found any problems with these changes to f2c with a variety of
mixed codes, but you might want to save a copy of the original routines
(just in case)...

			Hal Youngren  guppy@henry.mit.edu