I have a bunch of Fortran 77 files that use a non-standard structure notation (described here):
STRUCTURE /item/
INTEGER id
CHARACTER(LEN=200) description
REAL price
END STRUCTURE
This is apparently a syntax that was used by some old compilers but was later standardized in Fortran 90 to the following:
TYPE item
INTEGER id
CHARACTER(LEN=200) description
REAL price
END TYPE
What I want to do is use sed or some other appropriate tool to automatically process my source files to locate all uses of the old syntax and patch them to use the updated syntax (i.e. change all instances of “structure” to “type” and remove the slashes). I’m sure that I can build up some set of regular expressions to do this, but I’m not skilled enough in that art to get started.
On a side note, there is a similar incompatibility with record notation, also described in the link:
RECORD /item/ pear, store_catalog(100)
becomes:
TYPE(item) pear, store_catalog(100)
I assume similar techniques can be used to fix those instances also.
I’m not very familiar with Fortran syntax so I don’t know how to generalize this, but your example can be tackled with
Note the use of
%to separate the command (s, substitute), pattern and replacement. Normally you would use/, but that’s part of the pattern to be matched.Your
RECORDproblem should indeed have a similar solution.