0

I would like to open a .4gl file in VI terminal and write to it, this is the code I have currently:

 let p_command = "test -f ", MTGENDIR CLIPPED,"/",p_prog clipped,".4gl"
      run p_command returning p_status

      let p_command = "vi ",p_prog clipped,".4gl"
      --let p_command = "w ",p_prog clipped,".4gl"
      --let p_command = ":w ",p_prog clipped,".4gl"
      run p_command

This is the error I get in the debugger once it gets to the step vi and then it hangs:

(fgldb) next
376       let p_command = "vi ",p_prog clipped,".4gl"
(fgldb) next
377       run p_command
(fgldb) next
Vim: Warning: Output is not to a terminal
Vim: Warning: Input is not from a terminal

if i try writing with the commented code above (w or :w) it crashes and display this error:

The DVM process crashed. Please contact FourJs support.
DVM has encountered a problem. Execution of 'mt_gen' stopped

Is there any other way i can write to .4gl file in Genero?

  • 1
    Using `vim` (or `vi`) from within a program is odd, especially if you want to programmatically control what the editor does. It's one thing to run it 'hands free' as far as the I4GL program is concerned, with the user doing what they will with normal terminal interaction, but to have the program tell `vim` what to do is decidedly non-trivial and unorthodox. You'd probably have to get involved with pipes, pseudo-terminal and other esoteric features, which would mean C code functions added to your I4GL/Genero program. You should, most likely, rethink what you are doing. – Jonathan Leffler Jan 07 '21 at 19:07
  • 1
    This has at least some of the characteristics of an [XY Problem](http://mywiki.wooledge.org/XyProblem). Can you explain what you are hoping to achieve — at a high-level, not necessarily a description of how to use `vim` to achieve it, whatever "it" is. – Jonathan Leffler Jan 07 '21 at 19:08

1 Answers1

1

To answer the very last sentence "Is there any other way I can write to .4gl file in Genero?" then you can use base.Channel class to write to a file ...

MAIN
    DEFINE ch base.Channel

    LET ch = base.Channel.create()
    CALL ch.openFile("example.4gl","w")
    CALL ch.writeLine("MAIN")
    CALL ch.writeLine("    DISPLAY 'Hello World'")
    CALL ch.writeLine("END MAIN")
    CALL ch.close()
END MAIN

... the key bit being the use of base.Channel.openFile and w (or a) as the opening mode http://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_ClassChannel_openFile.html

Alternatively you can build up the file inside a STRING or base.StringBuffer variable and use the TEXT writeFile method http://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_datatypes_TEXT_writeFile.html ...

MAIN 
    DEFINE s STRING
    DEFINE t TEXT

   LET s = 
      "MAIN", ASCII(13),
      "    DISPLAY 'Hello World'", ASCII(13),
      "END MAIN"

   LOCATE t IN MEMORY
   LET t = s
   CALL t.writeFile("example2.4gl")
END MAIN

I'm not sure why you think you need vi/vim in your solution to write to a .4gl file.

fourjs.reuben
  • 286
  • 3
  • 3