How to convert all COBOL reserved words in multiple files to upper case and all other words to lower case?

How to convert all COBOL reserved words in multiple files to upper case and all other words to lower case?

1

    May 19, 2017#1

    I have a bunch of COBOL programs that I would like to bulk edit. Specifically replacing any COBOL reserved words with their upper case equivalents, and any non-reserved words with lower case equivalents. I have the list of reserved words. Can UltraEdit do that?

    6,603548
    Grand MasterGrand Master
    6,603548

      May 20, 2017#2

      This can be done with UltraEdit using Perl regular expression Replace in Files.

      For example the Perl regular expression search string \<(abc|def|xyz)\> finds with option Match case NOT checked one of the 3 words in the OR expression within capturing group 1 being an entire word and with replace string \U\1\E the found words are converted to upper case.

      But please note that the number of words in OR is not unlimited. So perhaps you need multiple executions of this Perl regular expression replace in files with different lists of words depending on number of reserved COBOL words. I used in the past always 50 words at once in OR expression, but most likely there are much more possible.

      After converting all reserved COBOL words in all COBOL source files to upper case, one more Perl regular expression Replace in Files can be used to convert all other words to lower case. This must be done with a single replace. If the list of reserved works is too large for the search expression below, a work around solution would be necessary and I know already which one. But let us assume here on first reply the number of reserved words is not too large for a single Perl regular expression Replace in Files.

      The search string would be \<(\w+)\>(?<!ABC|DEF|XYZ) and the replace string \L\1\E for converting all non reserved words to lower case.

      On looking on cobol.uew it looks like COBOL interprets - as word character. In this case \w+ must be replaced by [\w\-]+ in search string.
      Best regards from an UC/UE/UES for Windows user from Austria

      115
      Power UserPower User
      115

        May 22, 2017#3

        Using commands instead of reserved words in my example as sometimes commands are not reserved words in other languages:

        For the conversion of reserved words to upper case I had a similar task for changing the case in IDL (Interactive Data Language not Interface Design Language) which has hundreds of command names and thousands of parameter names. IDL is a case-insensitive language but our local coding standards require different case between commands and variables when possible. However the standards came about after hundreds of IDL programs had already been written. I wrote a script to parse a file of the command names (obtained from my IDL wordfile) and a source code file. It would convert the command names to upper case but also protect the case of names found in comments and strings. This is particularly important in the case of file names stored in strings since we run on UNIX/LINUX systems.

        I didn't have a script for lower case conversion for non-command names but that is easily solved. First I would make a copy of my upper case script, remove almost all of the code except the protection for strings and comments, and force a conversion of all other words to lower case. I won't care if this script converts command names to the wrong case because after it runs I will then execute my convert to upper case script and it will take care of command namess at that point.

        6,603548
        Grand MasterGrand Master
        6,603548

          May 23, 2017#4

          Mick, that is a very good idea.

          MonkeyFarmer run first the Perl regular expression Replace in Files with search string \<(\w+)\> and replace string \L\1\E to convert all words to lower case and then run the other Perl regular expression Replace in Files to convert the reserved words to upper case with the search and replace string as suggested in my first post.
          Best regards from an UC/UE/UES for Windows user from Austria