COBOL
Posted: Fri May 20, 2005 5:59 pm
				
				Is there a feature to the COBOL functionality that handles copybook - i.e. will the editor open or display copybooks appear in the program body?
			Use this forum to ask for help, submit a bug report or make a suggestion.
https://www.zeusedit.com/phpBB3/
Code: Select all
123456789012... <- column line
           COPY RSPCODES.
061115     COPY EXCRESP2.
           COPY RSPCODES REPLACING ==:== BY ==DB2==.
061115     COPY EXCRESP2 REPLACING ==:== BY ==IN2==.
Code: Select all
061115*    COPY EXCRESP2 REPLACING ==:== BY ==IN2==.
061115D    COPY EXCRESP2 REPLACING ==:== BY ==IN2==.
This is now the View, File Open menu item.In my version, 3.96, the View, Open Include menu item no longer exists. Has it been rendered obsolete or is it called something else now?
There are several places to do this.Ok, but where do I specify the search path?
Looking at your examples, I'm not sure if there is a regular expression that can uniquely identify the file nameAlso, I'm thinking that I'll need a regular expression to correctly parse out the filename within the text on the line. Is that correct?

Code: Select all
           COPY RSPCODES.
061115     COPY RXCRESP2.
           COPY RSPCODES REPLACING ==:== BY ==DB2==.
061115     COPY EXCRESP2 REPLACING ==:== BY ==IN2==. 
Code: Select all
Essentially to parse out the filename correctly, everything other than the word following the word "COPY" should be ignored; that word is the filename which then needs to suffixed with one of ".cob", ".cbl", ".cbk", ".cpy", or ".txt". Zeus does not do any parsing, but rather it runs a regular expression search and then uses the result of that search to open the file.
  Zeus does not do any parsing, but rather it runs a regular expression search and then uses the result of that search to open the file.
Code: Select all
-- Option 1: Let the FileOpenInLine function do the work
function my_file_open_one()
  -- mark the current word
  local result = MarkWordCurrent()
  if result > 0 then
    --
    -- NOTE: If no file extension is provided then the FileOpenInLine will
    --       use the extension of the current file as it's best guess.
    --
    -- try to open the file
    FileOpenInLine()
  else
    message("Make sure the cursor is placed on the file name.")
    beep()
  end
end
-- Option 2: A more complex macro
function my_file_open_two()
  -- get the text
  local line_text = get_line_text()
  if string.len(line_text) > 0 then
    -- look the word copy + space + file name + a space or dot character
    local i1, i2, copy, copy_book = string.find(line_text, "(COPY%s)(%w*)([%s\.]+)")
    if copy_book ~= nil then
        -- use the current document path
        local path = macro_tag("$fdd")
        -- now the copybook has a path
        copy_book = path .. copy_book
        -- try the different extensions
        if     file_open(copy_book .. ".cob") == 1 then
        elseif file_open(copy_book .. ".cbl") == 1 then
        elseif file_open(copy_book .. ".cbk") == 1 then
        elseif file_open(copy_book .. ".cpy") == 1 then
        elseif file_open(copy_book .. ".txt") == 1 then
        else
            message("Unexpected error opening " .. copy_book .. " copy book!")
            beep()
        end
    else
      message("No file was found on this line.")
      beep()
    end
  else
    message("Place the cursor on the line that contains the file.")
    beep()
  end
end
function key_macro()
  -- macro only works for documents
  local document = is_document()
  if document > 0 then
    -- here is one option
    my_file_open_one()
    -- here is another option
    my_file_open_two()
  else
    message("This macro only works for document files!")
    beep()
  end
end
key_macro() -- run the macro