Code Comments
Programming Forum and web based access to our favorite programming groups.I'm running MicroFocus COBOL 4.0 on UnixWare 2.1.3. I'm thinking about a change to every program which would involve searching for some text that each program has (a section name) and then inserting a MOVE command 2 lines down. As I'm running on UNIX is SED a good option (N.B. I've not used it before) or would clc groupies all prefer to use a COBOL program to convert other COBOL programs?! David L. P.S. There will be other mass changes in the future so that whichever technique is used will be employed again.
Post Follow-up to this messageIn article <a9026f4e.0406080249.5d26b437@posting.google.com>, david@quantumcat.demon.co.uk (David Latimer) writes: > > I'm thinking about a change to every program which would involve > searching for some text that each program has (a section name) and > then inserting a MOVE command 2 lines down. > > As I'm running on UNIX is SED a good option (N.B. I've not used it > before) or would clc groupies all prefer to use a COBOL program to > convert other COBOL programs?! That's "sed". Native Unix filesystems are case-sensitive. Personally, I'd probably use awk, partly because IMO it's better- suited for editing files where the changes are some distance from the search text (two lines down, in this case), but mostly because I've used it more often than sed, so I know more of its features and quirks. Which suggests that the answer to your question might be to use the tool you know, unless you have good reason to suspect that the effort spent in learning a new tool is worthwhile. There are, of course, many reasons to learn a new programming language (which is in effect what you're contemplating), but it may be that none of them are compelling in this case. Many Unix programmers, by the way, would use Perl for this. It's what Perl was designed for, more or less - text file processing. (I wouldn't, because I think Perl is rarely worth the effort or aesthetic trauma, but some are very fond of it.) -- Michael Wojcik michael.wojcik@microfocus.com How can I sing with love in my bosom? Unclean, immature and unseasonable salmon. -- Basil Bunting
Post Follow-up to this messagedavid@quantumcat.demon.co.uk (David Latimer) wrote: >I'm running MicroFocus COBOL 4.0 on UnixWare 2.1.3. > >I'm thinking about a change to every program which would involve >searching for some text that each program has (a section name) and >then inserting a MOVE command 2 lines down. > >As I'm running on UNIX is SED a good option (N.B. I've not used it >before) or would clc groupies all prefer to use a COBOL program to >convert other COBOL programs?! Clc groupies don't agree on anything. This is a religious issue. I have and would do it in Cobol .. because I could do it in a hour and it would look beautiful. Others might use sed or awk or Perl, which would look yucky.
Post Follow-up to this messageI would (and have) used sed to do this - it's the simplest way among the options available for what you want to do. We use sed and perl scripts every day on our Cobol source, originally on AIX, and now on Windows using Cygwin. We have a sed script that we run on screen section source generated from Acucobol's Acubench to add and subtract a few clauses. We have a perl script that I wrote that executes before the compiler that does some source checking to enforce some standards and catch some common mistakes. "David Latimer" <david@quantumcat.demon.co.uk> wrote in message news:a9026f4e.0406080249.5d26b437@posting.google.com... > I'm running MicroFocus COBOL 4.0 on UnixWare 2.1.3. > > I'm thinking about a change to every program which would involve > searching for some text that each program has (a section name) and > then inserting a MOVE command 2 lines down. > > As I'm running on UNIX is SED a good option (N.B. I've not used it > before) or would clc groupies all prefer to use a COBOL program to > convert other COBOL programs?! > > David L. > > P.S. There will be other mass changes in the future so that whichever > technique is used will be employed again.
Post Follow-up to this messagerobert.deletethis@wagner.net (Robert Wagner) wrote > Clc groupies don't agree on anything. This is a religious issue. I have an d > would do it in Cobol .. because I could do it in a hour and it would look > beautiful. > > Others might use sed or awk or Perl, which would look yucky. Well, _you_ certainly treat it as a religious issue. I'm an atheist and would use whatever is appropriate whether that be Cobol, sed, Python or Java. Functionality is far more important that what RW thinks is 'beautiful'. If sed does it then do that.
Post Follow-up to this messageWell at the risk of adding fuel to the fire here, I would strongly recommend
looking at awk for
this. Not because it is pretty or because of some religious affiliation. :)
Avoid "sed" because it is designed to edit a stream of data very well, but d
oes not lend itself
well to repetitive tasks and/or to more complex programming. Basically, it
is great for editing
reports on the way to the printer, or chomping on HTML on the way back to th
e browser, but
for doing things where the rules are a little more complex than a straight u
p substation,
well, awk is a better tool. It was designed to do exactly what you want to d
o in fact.
I any case, here is a little sample awk program and input that I think comes
close to doing what
you want done. There may be errors in the example code, I typed it in so any
mistakes are
almost certainly the result of my typing and not the awk program.
Also, there are slightly more elegant ways to do this, but this is the easie
st way to quickly understand. :) I did add more than
the program actually needs to give you a feel for the structure of an awk pr
ogram. They can get pretty complex and do some amazing
text transforms with very little effort.
Here is the awk program. Put it in a file called something like "test.awk".
It will simply add a line to the Working Storage
section of the input file.
****************************** CUT HERE ********************************
BEGIN {
ignorecase
}
/WORKING-STORAGE SECTION\./ {
print $0
getline
print $0
getline
print $0
print " *ADD USER NAME HERE"
print " 01 WS-USER-NAME PIC X(4) VALUE 'PAUL'."
print ""
}
## Default rule - print the line!
/^./ {
print $0
}
/* Do this after all input is processed */
END {
print " * File processed by awk\n"
**************************** CUT HERE ************************
And here is a test input file. (Mistakes, if any, are typos! :) Put this int
o a file (test.cbl?)
and run the awk program with the following command.
awk -f test.awk test.cbl
The output will show on your screen. You can use standard UNIX stuff to redi
rect it to a file,
or you can do the file manipulations inside the awk program if you want to.
**************************** CUT HERE *****************************
INDENTIFICATION DIVISION.
PROGRAM-ID. AWKTEST.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-USER-CHOICE PIC X(1).
PROCEDURE DIVISION.
START-PROGRAM.
DISPLAY 'HELLO ' WS-USER-NAME
ACCEPT WS-USER-CHOICE
GOBACK.
*********************** CUT HERE ************************************
"Richard" <riplin@Azonic.co.nz> wrote in message news:217e491a.0406082224.6c4dcd30@posting.
google.com...
> robert.deletethis@wagner.net (Robert Wagner) wrote
>
>
> Well, _you_ certainly treat it as a religious issue.
>
> I'm an atheist and would use whatever is appropriate whether that be
> Cobol, sed, Python or Java.
>
> Functionality is far more important that what RW thinks is
> 'beautiful'.
>
> If sed does it then do that.
Post Follow-up to this messageThanks Paul, It's great to be be presented with code that I can practice on. I look forward to meeting this particular UNIX utility! David "Paul Raulersonv" <pkrauleson@verizon.net> wrote in message news:<KjGxc.120$tA6.66@nwrddc03 .gnilink.net>... > Well at the risk of adding fuel to the fire here, I would strongly recommend looki ng at awk for this.
Post Follow-up to this messagedavid@quantumcat.demon.co.uk (David Latimer) wrote:
Hi David,
>I'm thinking about a change to every program which would involve
>searching for some text that each program has (a section name) and
>then inserting a MOVE command 2 lines down.
I simply use my editor (VIM) for these kind of tasks. Maybe your
editor has some means of recording keystrokes and writing them to a
file for further use? Then *show* it what to do once and let it repeat
the work on other programs. This way you don't have to learn any new
language.
Since MF Cobol wasn't (isn't?) able to debug object code, I used a
small script to find problems that only occured in object code:
/PROCEDURE DIVISION.*\.
:.,$ s/^.\{6}\ \([A-Z\-0-9]*\)\.$/\0^M DISPLAY "\1".
This inserts a DISPLAY "Paragraph-Name" as the first statement in each
paragraph. I still use a similar script to trace event driven GUI
programs.
A solution to your problem could look like this:
/^.\{6} FOOBAR SECTION\.
:normal jjO MOVE A TO B^[
:wq
Search for FOOBAR SECTION.
go two lines down and insert a new line above the cursor with MOVE A
TO B
Write & Quit
In 1996 I added a new file exception handling to about 150 Source
files written by different programmers with a single script containing
editor commands. Today, VIM has a full featured script language with
control structures like if/then/else or while...
> As I'm running on UNIX is SED a good option
Maybe you already use the right tool every day...
Kind regards
Sven
Post Follow-up to this messageDavid Latimer wrote: ..... > I'm thinking about a change to every program which would involve > searching for some text that each program has (a section name) and > then inserting a MOVE command 2 lines down. ...... > P.S. There will be other mass changes in the future so that whichever > technique is used will be employed again. This sort of job is a natural for SNOBOL4. Others have put their $0.02 in for COBOL, sed, Awk, Perl, .... but this is the sort of thing that SNOBOL4 was designed for and has proved to be excellent for through the years. I've used SNOBOL4 for many things, many of them small once- off utilities to make a bad situation workable, but some big ones too. I once wrote a program in SNOBOL4 (Asymbolize -- it's in the SHARE Library) to make it possible to extend a very big I.B.M. 360 assembler program. The problem was that all the references to registers in the assembler source were coded in numerics, not with symbols, so that the references to registers did not show up in the assembler cross-reference listing, and one could noy discover all the uses of the several machine registers. My program replaced all the uses of numerics used to indicate registers (not offsets and constants, e.g.) by assembly-time variables; during assembly, these could be substituted for by ordinary symbols which would show up in the cross-reference. SNOBOL4 is rich in the ability to set up patterns and to match character strings against them, taking actions as the match proceeds or fails, or after a whole pattern match has succeeded. It has the built-in ability to create and look up in tables such as dictionaries and symbol tables, and it's easy to write whole compilers in SNOBOL4 (as has been done in many compiler-writing courses). Do visit http://www.snobol4.com ; there, you can get on the SNOBOL4 mailing list, buy one of the excellent SPITBOL compilers for SNOBOL4, or download a free copy of the sample Vanilla SNOBOL4 system (it's adequate for many small jobs!). The documentation that's included in the Vanilla SNOBOL4 system is a really great introduction to SNOBOL4, and the documentation that comes with SPITBOL is superb. There are also links at the site to other implementations of SNOBOL4, and a library of contributed programs in and connected with SNOBOL4. All the best! John. -- John H. Lindsay jlin_DELETE_THIS_SPAM_ZOT_dsay@kingston.net 48 Fairway Hill Crescent, Kingston, Ontario, Canada, K7M 2B4.
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.