[comp.lang.fortran] Want to expand includes for listing...

anita@utastro.UUCP (Anita Cochran) (12/16/87)

I have a fortran code in which I use includes to include my common
blocks in various routines.  This gives the advantage that I can
change the common in only one file and it will upgrade all of the
dependent files (especially with a makefile).  But it is sometimes
handy to have a listing of the code.  Normally, I would just use lpr
to print a listing but then the listing would have things like
    include 'file.com'
instead of actually listing the common.  Does anyone know of a utility
or have a program or script to substitute the contents of an included
file into the appropriate place of a source so that it can be listed
(I have 4.2BSD UNIX)?  Surely, this is such a useful utility that someone
must have invented it before.  I have already tried calling the files
src.F and running f77 with the -F flag to run them through the preprocessor
but this leaves the source unchanged with the includes still in it.

Thanks in advance.

-- 
 Anita Cochran  uucp:  {noao, ut-sally, ut-ngp}!utastro!anita
                arpa:  anita@astro.as.utexas.edu  
                snail: Astronomy Dept., The Univ. of Texas, Austin, TX, 78712
                at&t:  (512) 471-1471

gwyn@brl-smoke.ARPA (Doug Gwyn ) (12/17/87)

In article <2317@utastro.UUCP> anita@utastro.UUCP (Anita Cochran) writes:
>    include 'file.com'
>...  Does anyone know of a utility
>or have a program or script to substitute the contents of an included
>file into the appropriate place of a source so that it can be listed

There is such an "include" processor in Software Tools by Kernighan &
Plauger (Addison-Wesley).

jerry@violet.berkeley.edu ( Jerry Berkman ) (12/18/87)

In article <2317@utastro.UUCP> anita@utastro.UUCP (Anita Cochran) writes:
>Normally, I would just use lpr
>to print a listing but then the listing would have things like
>    include 'file.com'
>instead of actually listing the common.  Does anyone know of a utility
>or have a program or script to substitute the contents of an included
>file into the appropriate place of a source so that it can be listed
>(I have 4.2BSD UNIX)?  Surely, this is such a useful utility that someone
>must have invented it before.  I have already tried calling the files
>src.F and running f77 with the -F flag to run them through the preprocessor
>but this leaves the source unchanged with the includes still in it.
>
>Thanks in advance.
>
>-- 
> Anita Cochran  uucp:  {noao, ut-sally, ut-ngp}!utastro!anita
>                arpa:  anita@astro.as.utexas.edu  
>                snail: Astronomy Dept., The Univ. of Texas, Austin, TX, 78712
>                at&t:  (512) 471-1471

The following commands work on Ultrix and 4.3 BSD:

more *.f | sed -e 's/^[ 	]*include/.so/' 	\
	-e /^\.so/s/\[\"\']//g
	| soelim

The first "-e" option looks for a line with "include" preceded only by
blanks and tabs.  It replaces that by ".so".  The second "-e" deletes
the characters " and ' .  So:

	include "files.com"

now is:

.so files.com

Then the UNIX "soelim" command, designed for use with nroff, replaces
the ".so" by the text.  This only expands one level of includes; if
your include files include other files, you will need to modify the
script.

This script does not worry about the unlikely possibility that the
program has lines with "i" in column 6 for continuation and
"nclude" in columns 7-12 in non-include statements.

	- Jerry Berkman