Menu

Guardar pantalla antes de hacer un nuevo display

Anonymous
2023-02-23
2024-03-13
  • Anonymous

    Anonymous - 2023-02-23

    Hola, estoy trabajando con el tema de migrar desde Microfocus a Gnucobol, pero no puedo resolver el tema de poder guardar una screen o pantalla o consola antes de hacer un nuevo display, la idea es: hacer un display, luego guardar pantalla, hacer un segundo display y luego recuperar la pantalla anterior. Si tienen ayuda sobre esto les agradeceria, saludos.

     
  • Simon Sobisch

    Simon Sobisch - 2023-02-23

    translation by deepl.com:

    Save screen before making new display

    Hello, I am working with the issue of migrating from Microfocus to Gnucobol, but I can not solve the issue of being able to save a screen or screen or console before making a new display, the idea is: make a display, then save screen, make a second display and then recover the previous screen. If you have help on this I would appreciate it, greetings.

     
    • Ralph Linkletter

      It would be helpful for me to see the original Micro Focus code.

       
  • Vincent (Bryan) Coen

    If you are working with *nix (i.e., Linux) then the following code works :

    In working-storage :

    *>
    *> For saving and restoring screen for Tagname display lists (function keys F1).
    *> NOT tested using Windows & NOT likely to work.
    *>
      01  wScreenName            pic x(256).
      01  wInt                   binary-long.
    

    In Proc division :

     CA300-Save-Screen.
         move     z"flg-temp.scr"  to wScreenName.
         call     "scr_dump"    using wScreenName returning wInt.
    *>
     CA301-Restore-Screen.
         call     "scr_restore" using wScreenName returning wInt.
         call     "CBL_DELETE_FILE" using wScreenName.  *> Now delete z"flg-temp.scr".
    

    In proc div where required :

    perform CA300-Save-Screen .  *> To save current screen
    
        • do what you need in a new screen area - - - -

    and when finished to return to old screen :

    cobolfree `perform CA301-Restore-Screen.

    ---- continue with the old screen content ----.

    I have NOT tested this code when running under Windows and msys or similar but it should work using Win 11 and WSL.

     

    Last edit: Simon Sobisch 2025-08-11
    • Simon Sobisch

      Simon Sobisch - 2023-02-23

      Good old scrdump!

      Actually PDCurses implements that, too, so should work there as well [just note that the internal format changed between versions, so save to disk and restore only works with the same version].

      @zosralph: Wasn't there a MF routine for this? Could we map the call to this or is it too different?

      Note: in general you may need to additional store the old values from variables if you want to re-display/accept them and overwrite them in between.

       
      • Ralph Linkletter

        Chuck H. has written a bunch of subroutines that mimic the MF primitives.
        I am kind of at a loss without seeing the many various methods that MF uses for screen interaction.
        It would be nice to see a snippet of the existing MF COBOL code.
        Ralph

         
  • Anonymous

    Anonymous - 2023-02-23

    Hi,
    attached program saves and restores an entire screen and works fine on windows 10.
    They are the same indications as Vincent but you have a complete and commented program.

    Since GnuCOBOL doesn't have a function to do this, you need to use the "scr_dump" and "scr_restore" functions from the PDCURSES library.
    These functions save an entire screen to a disk file and restore it from disk file to the screen.

    GnuCOBOL lacks the possibility to save and then restore a portion (a rectangle) of the screen or even the whole screen.
    More generally, GnuCOBOL lacks the possibility of "reading" what is on the screen (characters and / or attributes such as color for example) and write just attributes on screen (ex colors).

    Other compilers have lot of functions such as

    CBL_SCR_SAVE 
    CBL_SCR_RESTORE
    CBL_READ_SCR_ATTRS
    CBL_READ_SCR_CHARS
    CBL_READ_SCR_CHATTRS
    ...
    

    See also at https://www.microfocus.com/documentation/visual-cobol/vc50all/EclWin/HRCLRHCALL10.html

     
    • Simon Sobisch

      Simon Sobisch - 2023-02-24

      GnuCOBOL lacks the possibility to save and then restore a portion (a rectangle) of the screen or even the whole screen.

      Has MF an option to (re-)store a rectangle? If yes: How?

      Note: CBL_SCR_SAVE and CBL_SCR_RESTORE could be easily added to screenio.c by calling those functions with a temporary file, reading it completely to memory and returning "a handle" to this.

      Question: Can you (re)store the screen with MF after the runtime is restarted (obviously not with those functions) ?

       
      • Ralph Linkletter

        Simon MF sort of supports a rectangle.
        The Y vector,of RowX, ColumnY will always be the maximum number of columns
        1 -> Max.
        Scoped by top line, bottom line

        Hence a rectangle

        Syntax:

        call "CBL_SCR_SAVE" using by value       flags
                                                 top-line
                                                 bottom-line
                                       returning handle.
        

        Parameters:

        Using call prototype (see Key) Picture
        flags cblt-x4-comp5 pic x(4) comp-5
        top-line cblt-x4-comp5 pic x(4) comp-5.
        bottom-line cblt-x4-comp5 pic x(4) comp-5.
        handle cblt-pointer usage pointer

        https://www.microfocus.com/documentation/visual-cobol/vc60/EclUNIX/HRCLRHCALL42.html

        Syntax:

        call NoReturnCode "CBL_SCR_RESTORE" using by value     flags
                                                               handle
        

        Parameters:

        Using call prototype (see Key) Picture
        flags cblt-x4-comp5 pic x(4) comp-5
        handle cblt-pointer usage pointer

        On Entry:

        • flags Currently, this must always be zero.
        • handle A "save-handle" previously returned by a call to the CBL_SCR_SAVE call-by-name routine. This handle can be NULL, in which case the call does nothing.

        https://www.microfocus.com/documentation/visual-cobol/vc60/EclUNIX/HRCLRHCALL40.html

         

        Last edit: Simon Sobisch 2023-02-24
        • Simon Sobisch

          Simon Sobisch - 2023-02-24

          MF sort of supports a rectangle.

          So If a restore is done, then the restore happens wherever the save originally was done from? In this case the handle would need to point to a memory area which has both the stored memory "data+attributes" along with the original upper-left corner.

          I think one of the following should work to save a part:
          * subwin -> for the rectangle
          * copywin -> to get the content of the main window into the subwindow
          * getwin -> to store the subwindow
          * delwin -> to delete the subwindow

          Then for restore:
          * subwin -> for the rectangle (obviously with the same size)
          * putwin -> to restore the subwindow
          * copywin -> to get the content of the subwindow into the main window
          * delwin -> to delete the subwindow
          * refresh -> to show the restore

          @dilodilo Could you please try tinkering with this?

           
          • Eugenio Di Lorenzo

            Unfortunately, although the issue has emerged several times, we still do not have the possibility to save and then restore a rectangular area of the screen (both the characters and the attributes).
            We can only save the entire screen to file and restore the entire screen from file.
            And in any case there is a bug ticket (n.946) related to this as in some cases restoring the entire screen may be creates problems to the DISPLAY that follows and does not work correctly.

            At this point, as suggested, I would like to try using the pdcurses functions but to call them from GnuCOBOL I need guidance from a C language expert.
            What is the GnuCOBOL syntax for:
            call static 'subwin' using ...
            call static 'copywin' using ...
            call static 'getwin' using ...
            call static 'delwin' using ...
            call static 'putwin' using ...

            sample from attached pdcurses documentation:

            Synopsis:

            WINDOW *subwin(WINDOW* orig, int nlines, int ncols,
                int begy, int begx);
            

            description

            subwin() creates a new sub-window within a window.  The
            dimensions of the sub-window are nlines lines and ncols columns.
            The sub-window is at position (begy, begx) on the screen.  This
            position is relative to the screen, and not to the window orig.
            The sub-window is made in the middle of the window orig, so that
            changes made to either window will affect both.  When using this
            routine, it will often be necessary to call touchwin() before
            calling wrefresh().
            

            See also

            https://sourceforge.net/p/gnucobol/discussion/lounge/thread/2577c752/?limit=50#b825/a7e7/bb7b/c465/0c2b

            https://sourceforge.net/p/gnucobol/discussion/help/thread/d06ddab28c/?limit=50#bf3e/5b58/bfb6/ef29/a170

             

            Last edit: Eugenio Di Lorenzo 2024-03-11
  • Ralph Linkletter

    Chuck did write most of these routines for support in GnuCOBOL
    Other compilers have lot of functions such as
    CBLSCRSAVE
    CBLSCRRESTORE
    CBLREADSCRATTRS
    CBLREADSCRCHARS
    CBLREADSCRCHATTRS*

    I suspect that MF / Fujitsu experience is required before the routines can be appreciated in GnuCOBOL.
    ...

     
    • Eugenio Di Lorenzo

      Great !
      The management of reading and writing from the screen (characters and attributes) is one of the main aspects of GnuCOBOL to improve.
      It would be very helpful if these routines were available for us to try!
      Especially the two most useful routines: CBL_READ_SCR_CHATTRS and CBL_WRITE_SCR_CHATTRS.

      It would also be useful to be able to call the functions of the pdcurses library that manage a WINDOW with a CALL. To understand which syntax to use in GnuCOBOL you need a person skilled in the C language.

      from pdcurses manual:

      DATA TYPES
      The following data types are declared:
      WINDOW pointer to screen representation
      SCREEN pointer to terminal descriptor
      bool boolean data type
      chtype representation of a character in a window
      cchart the wide-character equivalent of chtype
      attrt for WA-style attributes
      The actual WINDOW and SCREEN objects used to store information are created by the corresponding routines and a pointer to them is provided. All manipulation is through that pointer.

      . . .

      Name: window
      ** Synopsis:
      WINDOW newwin(int nlines, int ncols, int begy, int begx);
      WINDOW subwin(WINDOW orig, int nlines, int ncols, int begy, int begx);
      int delwin(WINDOW win);

       
      • Chuck Haatvedt

        Chuck Haatvedt - 2024-03-12

        Hello Eugenio,

        As Ralph mentioned, I did clone a number of the Fujitsu / MF CBL_* functions which deal with screen i/o. It is not the complete set of functions but it was enough for Ralph to create a screen and do keyboard interaction with it.

        here is a list of the function exposed as external entry points in my CWH_ROUTINES.C DLL.

          ADDAPI int ADDCALL  CWH_CREATE_SCR();
           ADDAPI int ADDCALL  CWH_CLEAR_SCR(void *a, void *b);
           ADDAPI int ADDCALL  CWH_WRITE_SCR_CHARS(void *a, void *b, void *c);
           ADDAPI int ADDCALL  CWH_WRITE_SCR_ATTRS(void *a, void *b, void *c);
           ADDAPI int ADDCALL  CWH_WRITE_SCR_CHARS_ATTR(void *a, void *b, void *c, void *d);
           ADDAPI int ADDCALL  CWH_WRITE_SCR_CHATTRS(void *a, void *b, void *c, void *d);
           ADDAPI void ADDCALL CWH_ALARM_SOUND();
           ADDAPI int ADDCALL  CWH_GET_SCR_SIZE(void *a, void *b);
           ADDAPI int ADDCALL  CWH_SET_CSR_POS(void *a);
           ADDAPI int ADDCALL  CWH_SET_CSR_SHAPE(void *a, void *b);
           ADDAPI int ADDCALL  CWH_READ_SCR_KEY(void *a, void *b);
           ADDAPI void ADDCALL CWH_CLOSE_WINDOW();
        
           ADDAPI void ADDCALL DUMP_HEX(void *source, int length);
        

        Note that I used the CWH prefix rather than CBL so as to not confuse them with the Fujitsu / MF routines. This could easily be changed. You can do a internet search to get the Fujitsu documentation for these functions. It should be the same as the MF documentation according to Ralph.

        here is the compile command to create the CWH-ROUTINES.DLL

        cobc -m cwh-routines.c -lpdcurses

        If you have any questions, post them here. Note that I'm on vacation in Portugal until May 10, so I may not have time to work on any enhancement requests until I get back home and have a week or so to catch up with things at home. Also I have some additional work I'm doing to get VISAM 2.2 working with GNUCOBOL 3.x along with ACCEPT_NUMERIC. So I'll have to prioritize my efforts.

        Ralph may have some examples of how to call these functions to create an interactive screen.

                  Chuck Haatvedt
        
         
  • Simon Sobisch

    Simon Sobisch - 2024-03-13

    Here's a quick hack of Chuck's routine (oh man, that's 2021?):

    • fixing some C issues, removing some unused code
    • also compiles on non win32
    • also allows to use ncurses -> compile with cobc cbl-scr-routines.c -A -DHAVE_NCURSES_H -lncursesw (or non "w" version, if not available); drops return codes for some ALT and CTRL modifiers
    • defaults to CBL_ names - if you want the CWH_ prefix, add -A -DCWH to the command line

    @zosralph @dilodilo could you try to check if this code works "as expected"? Could you try to create a test program to vet that, which we later could include into the GnuCOBOL "manual screen testing" testsuite?
    If it does work and is compatible to MF, then I'd work on integrating that into libcob's screenio, making it general available (possible for GnuCOBOL 3.3 if it works).
    This then would "only" leave the documentation part open (but that should not be too hard with the example program, which could also be added to the PG sample programs).

     

    Last edit: Simon Sobisch 2024-03-13
    • Ralph Linkletter

      If I recall use of these routines require the a prerequisite call to CWH_CREATE_SCR.
      This call acquires an internal "handle".
      I call "system" to indicate the size of the screen
      MOVE 'MODE CON: LINES=25 COLS=80' TO END-PARMS (or whatever x y scaling)
      CALL "SYSTEM" using END-PARMS
      The documentation is best found in the Fujitsu document - since Fujitsu speaks vanilla COBOL, whereas MF uses a bunch of type defs to describe parameters. I attached it.

       

      Last edit: Ralph Linkletter 2024-03-13
  • Chuck Haatvedt

    Chuck Haatvedt - 2024-03-13

    Simon,

    when I was working on my ACCEPT_NUMERIC code I found that the keycodes returned by linux terminals are different than returned by Windows console for some keys. So that may need to be addressed for the Linux usage of this code.

    Also, I did not take the time to make the code "production ready", so some clean up / documentation would probably be needed. There may be some debug code which needs to be adjusted as well.

               Chuck Haatvedt
    
     
    👍
    1

    Last edit: Chuck Haatvedt 2024-03-13
    • Simon Sobisch

      Simon Sobisch - 2024-03-13

      Concerning the different codes - ncures abides to the terminfo so it also depends how you configure that (for example to distinguish KEY_ENTER [I think that's PADENTER on pdcurses] from \10 [which is the return key]).
      But I'd be totally fine to say "the codes you get from CBL_READ_SCR_KEY is operating system depending - test both your development and target environment".
      For the "missing" control key returns- you already call keyname() in that function, I think that would also allow to map for those missing keys (with an "expensive" string comparison - but that's not such a big problem with screen input).

       
  • Anonymous

    Anonymous - 2024-03-13

    I open another thread to test these new routines.

     

Anonymous
Anonymous

Add attachments
Cancel