HOME  NEWS  FORUM  DOWNLOAD  LINK
OpenCOBOL - an open-source COBOL compiler
Main Menu
Download
Documentation
Development
Who's Online
19 user(s) are online (4 user(s) are browsing Forum)

Members: 0
Guests: 19

more...
Powered by
SourceForge

Xoops

Creative Commons

OpenCOBOL Forum Index
   OpenCOBOL
     Terminal problems [solved] on debian/ubuntu - from seetho at forum.peoplecards.ca
Register To Post

Threaded | Newest First Previous Topic | Next Topic | Bottom
Poster Thread
btiffin
Posted on: 2012/2/22 18:24
Home away from home
Joined: 2008/6/7
From: CANADA
Posts: 1196
Terminal problems [solved] on debian/ubuntu - from seetho at forum.peoplecards.ca
from seetho

Hello,

It's been quite some time (~25yrs) since I last used COBOL (on a WANG VS100). I just stumbled upon OpenCOBOL recently and felt like picking it up again, especially to build some applications that are heavy on data entry screen. I currently use PERL and LISP so using ncurses is awkward to say the least, and I hate writing GUI apps - call me old fashion.

The first thing I tried was of course the short HELLO.COB sample program. No problems here. The trouble started when I modified the DISPLAY statement to:
DISPLAY
  "Hello world!" LINE 5 COL 5
END-DISPLAY


The program would compile normally, but when runned it would output nothing. This was on my Ubuntu 10.04/Gnome machine. The program was run under gnome-terminal. Suspecting some terminal problem I tried xterminal instead - nothing again. Then I switch out to a real (TTY) text terminal, and IT WORKS! I get my "Hello world!" displayed on line 5 and column 5 on the screen.

My gnome-terminal session is /dev/pts/0. It would seem that OpenCOBOL (at least on my PC) does not work well with pseudo terminals. If I did:
./hello >/dev/tty1

The output will appear on TTY1.

I tried recompiling OpenCOBOL 1.1 and ncurses 5.9 and still the same result. I even tried it on a freshly installed Debian 6.04 machine and still no go.

Googling did not turn up anything on this so I suspect that I'm the only one having this problem. Am I missing something?

Thanks.
btiffin
Posted on: 2012/2/23 4:21
Home away from home
Joined: 2008/6/7
From: CANADA
Posts: 1196
Re: Terminal problems on debian/ubuntu - from seetho at forum.peoplecards.ca
seetho,

It is actually working, but too fast to see.

Add
CALL "C$SLEEP" USING 3 END-CALL

just before any stop run, goback.

One of the "features" of curses, ncurses is initializing its own screen buffer. This uses stdscr in curses, not stdout.

This screen buffer disappears on curses run down and you see your terminal session with the ./hello and no stdout. Flickers fairly quickly. To quickly to notice. Sleeping before image exit will let you see the curses screen.

You've made me curious, I wonder if ncurses has an ease of use CALL "dump look of buffer to stdout"? Instead of suggesting people call SLEEP or ACCEPT to wait for return,

I looked quick...
scr_dump("filename") doesn't cut it, as it seems to dump the screen state, not the screen buffer.

An /extra anyone? A nice dump current screen to stdout using the curses library? It's build in, so no strange tectonics required.

Cheers,
Brian
human
Posted on: 2012/2/23 8:41
Home away from home
Joined: 2007/5/15
From: GERMANY
Posts: 1416
Re: Terminal problems on debian/ubuntu - from seetho at forum.peoplecards.ca
Hi Brian,

a "save curses screen before exit curses and dump it to stdout afterwards" would be really nice, but I'm very sure we have to patch libcob for that (because you can only output the screen to "real" stdout after exiting curses [which is done on cleanup in libcob] and need to save the contents before).

I've changed the code to always do something like
display ' '
end-display
display 'Press ENTER to exit the program'
end-display
accept dummyvar end-accept
before STOP RUN.

human
btiffin
Posted on: 2012/2/25 5:54
Home away from home
Joined: 2008/6/7
From: CANADA
Posts: 1196
Re: Terminal problems on debian/ubuntu - from seetho at forum.peoplecards.ca
Hi all,

It worked! Now I can continue my quest of trying to go back to being a COBOLER again. Hmmm... that sounded strangely like another profession that is much needed to keep the world on it's feet but much under-appreciated.

Anyway, in hindsight, I encountered this problem of disappearing stdscr before when I was learning ncurses years ago. I just forgot about it :mrgreen:. In fact it is documented in the book by Dan Gookin, Programmer's Guide to nCurses. Apparently the culprit is the rmcup "feature" in terminfo that restore the screen after program termination, thus throwing away what I just tried to display. Most software will wait around for user input or user command to terminate so this "feature" will normally not cause any problems. I read that you can remove it all together from terminfo to disable it or you could use xterm where there is a way to disable it at runtime.

Thanks for the help and thanks for OpenCOBOL.
--
seetho

p.s. my apologies for double posting earlier.

cross posted from forum.peoplecards.ca for seetho by btiffin
btiffin
Posted on: 2012/2/25 15:26
Home away from home
Joined: 2008/6/7
From: CANADA
Posts: 1196
Re: Terminal problems on debian/ubuntu - from seetho at forum.peoplecards.ca
Welcome to the world of OpenCOBOL seetho.

I'd be very interested to find out if there is a one-liner easy way to leave curses screen 'on display'. The refresh happens so fast, that many of us think things aren't working, (or forget the pause before rundown) and that's not great when you are writing a first cut Hello screen, or experimenting with features. I'm going to dig in a little, see if there isn't a semi-sane hint to give out to everyone. Your MCUP information is a hopeful sign.

Cheers,
Brian
cross post from forum.peoplecards.ca
btiffin
Posted on: 2012/2/27 4:18
Home away from home
Joined: 2008/6/7
From: CANADA
Posts: 1196
Re: Terminal problems on debian/ubuntu - from seetho at forum.peoplecards.ca
Yay, found.

https://blogs.oracle.com/samf/entry/smcup_rmcup_hate is a great article that discusses and sledge-hammer fixes the curses init screen clearing issue, leaving output on the stdout terminal, not an alternate screen.

I just did a (after just in case copying /usr/share/terminfo/x/xterm - find this filename out by running infocmp to stdout first)

$ infocmp >xterm.terminfo
$ vi xterm.terminfo
$ # get rid of smcup= and rmcup= upto and including the comma
$ tic xterm.terminfo

in my case, the temporary xterm.terminfo looked like
...
        rin=\E[%p1%dT, rmacs=\E(B, rmam=\E[?7l, rmcup=\E[?1049l,
        rmir=\E[4l, rmkx=\E[?1l\E>, rmm=\E[?1034l, rmso=\E[27m,
        rmul=\E[24m, rs1=\Ec, rs2=\E[!p\E[?3;4l\E[4l\E>, sc=\E7,
        setab=\E[4%p1%dm, setaf=\E[3%p1%dm,
        setb=\E[4%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m,
        setf=\E[3%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m,
        sgr=%?%p9%t\E(0%e\E(B%;\E[0%?%p6%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;%?%p7%t;8%;m,
        sgr0=\E(B\E[m, smacs=\E(0, smam=\E[?7h, smcup=\E[?1049h,

and becomes
        rin=\E[%p1%dT, rmacs=\E(B, rmam=\E[?7l,
        rmir=\E[4l, rmkx=\E[?1l\E>, rmm=\E[?1034l, rmso=\E[27m,
        rmul=\E[24m, rs1=\Ec, rs2=\E[!p\E[?3;4l\E[4l\E>, sc=\E7,
        setab=\E[4%p1%dm, setaf=\E[3%p1%dm,
        setb=\E[4%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m,
        setf=\E[3%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m,
        sgr=%?%p9%t\E(0%e\E(B%;\E[0%?%p6%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;%?%p7%t;8%;m,
        sgr0=\E(B\E[m, smacs=\E(0, smam=\E[?7h,
...

rmcup and smcup edited out.

After the tic command, these is now a shiny new local /home/btiffin/.terminfo/x/xterm compiled terminfo file that has no alternate terminal screen capabilities.

That also means, as long as you don't run the term info compiler, tic, as root /usr/share/terminfo/x/xterm is still the original, and a new local copy is made. tic will overwrite the system file if it can, will move on and create a local compiled file if it can't.

The script in Sam's blog, mentioned above, will alleviate doing this manually every time the system updates the terminfo database.

So now, this
       identification division.
       program-id. helloscreen.
       procedure division.
       display "Hello, world" at 0212 end-display
       display "Goodbye, smcup/rmcup" at 0313 end-display
       goback.
       end program helloscreen.


and the command below; which blanks the screen but now leaves output on stdout after goback.

[btiffin@home forum]$ ./helloscreen

           Hello, world
            Goodbye, smcup/rmcup



[btiffin@home forum]$                                  


Never worry about smcup/rmcup hate on curses init again. Not just OpenCOBOL and curses, but vi, less, man and any alternate screen application. For the win. This change effects old school TE TI termcap calls too, I think; did for my version of LESS without -X.

Umm, probably still won't allow screen section programs in pipes; as stdin, stdout are a little special with curses involved. Minor annoyance that won't come up as often. Piping screen interactive programs has always been laden in voodoo anyway.

For the win.

Cheers,
Brian
Threaded | Newest First Previous Topic | Next Topic | Top

Register To Post
 
Copyright (C) 2005 The OpenCOBOL Project. All rights reserved.
Powered by Xoops2 | PHP | MySQL | Apache
ocean-net