[comp.unix.programmer] Strange curses problem

dcook@spam.ua.oz (David Cook) (06/20/91)

Hello,
  here is a section of code I've been having trouble with,
in a program which uses curses.
(the problem is the same on SunOS 4.1.1/SPARC and OSx5.1/Pyramid 98xx,
using standard cc on both machines, ucb universe on the Pyramid -
the program works ok in att universe on the Pyramid )

The problem is, I am trying to display the array 'abroll' on the
screen, in a 6 row by 12 column format, evenly spaced.
The current behaviour is to print the first number in each column
in the correct place, and the other 5 appear around column 78 of the
same line as the first number . If I remove the commented out section 
of code, below, the program works.

 I have experimented with location and amount of
refresh(), but it seems to make no difference.
Could someone out there _please_ reduce my frustration, and
see the error that I'm missing (apart from the obvious one of
using curses in the first place :-) 

Also, I am seriously considering using termcap directly instead,
but I am not sure how to go about this, (I have RTFM, but I would
like some example code ), and would appreciate
some pointers in the right direction.

Thanks in advance,
     
  int l1,l2,abroll[12][6];

  initscr();
  crmode();
  nl();
  clear();

  for(l1=0;l1<12;l1++)
    for(l2=0;l2<6;l2++)
      {
	move(l2+6,l1*4+5);
        refresh();
        printw("%2d",abroll[l1][l2]);
	refresh();
/* when I include this commented out code, it works fine ... */
/*	move(23,1);
        refresh();
	printw(" debug : gxy(%d,%d) ",l1*4+4,l2+6);
	refresh();   */
	sleep(1);
     }

David T Cook | e-mail: dcook@spam.adelaide.edu.au | Phone: +61 8 228 5709
Assistant Computer Manager, Stats, Pure and Applied Maths LMG, Adelaide Uni
"The wonderful thing about USENET is that anyone can express their opinion."
"The worrying thing is that they _do_."

dcook@spam.ua.oz (David Cook) (06/25/91)

(I got no answer to this question from comp.unix.programmer,
so am re-posting to other groups. Maybe someone else knows
this problem .... )

Hello,
  Here is a section of code I've been having trouble with,
in a program which uses curses.
(the problem is the same on SunOS 4.1.1/SPARC and OSx5.1/Pyramid 98xx,
using standard cc on both machines, ucb universe on the Pyramid -
the program works ok in att universe on the Pyramid )

The problem is, I am trying to display the array 'abroll' on the
screen, in a 6 row by 12 column format, evenly spaced.
The current behaviour is to print the first number in each column
in the correct place, and the other 5 appear around column 78 of the
same line as the first number . If I remove the commented out section 
of code, below, the program works.

 I have experimented with location and amount of
refresh(), but it seems to make no difference.
Could someone out there _please_ reduce my frustration, and
see the error that I'm missing (apart from the obvious one of
using curses in the first place :-) 

Also, I am seriously considering using termcap directly instead,
but I am not sure how to go about this, (I have RTFM, but I would
like some example code ), and would appreciate
some pointers in the right direction.

Finally, if this is a known bug in BSD curses (a couple of people
have suggested this), is there a work-around/fix ?

Thanks in advance,
     
  int l1,l2,abroll[12][6];

  initscr();
  crmode();
  nl();
  clear();

  for(l1=0;l1<12;l1++)
    for(l2=0;l2<6;l2++)
      {
	move(l2+6,l1*4+5);
        refresh();
        printw("%2d",abroll[l1][l2]);
	refresh();
/* when I include this commented out code, it works fine ... */
/*	move(23,1);
        refresh();
	printw(" debug : gxy(%d,%d) ",l1*4+4,l2+6);
	refresh();   */
	sleep(1);
     }

David T Cook | e-mail: dcook@spam.adelaide.edu.au | Phone: +61 8 228 5709
Assistant Computer Manager, Stats, Pure and Applied Maths LMG, Adelaide Uni
"The wonderful thing about USENET is that anyone can express their opinion."
"The worrying thing is that they _do_."

bout@convex.com (David Boutilier) (06/26/91)

It works fine if you change nl() to nonl().

ross@emf780.den.mmc.com (Perry R. Ross) (06/26/91)

In article <883@spam.ua.oz> dcook@spam.ua.oz (David Cook) writes:
> [... deleted ...]
>Hello,
>  Here is a section of code I've been having trouble with,
>in a program which uses curses.
>(the problem is the same on SunOS 4.1.1/SPARC and OSx5.1/Pyramid 98xx,
>using standard cc on both machines, ucb universe on the Pyramid -
>the program works ok in att universe on the Pyramid )
>
>The problem is, I am trying to display the array 'abroll' on the
>screen, in a 6 row by 12 column format, evenly spaced.
>The current behaviour is to print the first number in each column
>in the correct place, and the other 5 appear around column 78 of the
>same line as the first number . If I remove the commented out section 
>of code, below, the program works.

I hesitate to post at all, since my experience with curses is
(thankfully) in the past.  But, since you say you haven't gotten
anything from the "experts", here goes (now watch the "experts" leap
up and flame me :)

My guess is that you are a victim of "cursor motion optimization",
which tries to minimize the number of characters that need to be sent
to your terminal to accomplish a cursor motion.  For example, if the cursor
only needs to go down one line and back two columns, curses will send the
"down line" character and two "backspace" characters.  When the cursor
has to go a long way, however, it is more efficient to just use the
absolute cursor position sequence.  Your commented code appears to
force absolute cursor positioning by making the cursor move a long
way.  The culprit here might be a bad termcap entry (or terminfo for
newer stuff -- I haven't used terminfo but I think the man page refers
back to the termcap capability names).  I would check the sequence for :do,
:le, :nd, and :up, which all move the cursor one line/column, also :ch, which
sets the cursor column without affecting the row (again, convert these
to terminfo names if that's what you're using).  If that checks out,
see if :pt appears in your entry, and try deleting it.  It tells curses
that your terminal has hardware tabs, which curses may try to use to move the
cursor.  I have seen :pt on a terminal that doesn't do tabs (or
doesn't do them right or needs to be setup via the :is or :if capability)
shift all your text to column 79.

Hope this helps!

>Could someone out there _please_ reduce my frustration, and
>see the error that I'm missing (apart from the obvious one of
>using curses in the first place :-) 
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Bingo. :)
-- 
-- Perry R. Ross (303)977-4371 | DISCLAIMER: Martin Marietta usually doesn't --
-- ross@emf780.den.mmc.com     | have a very high opinion of my opinions.    --
-------------------------------------------------------------------------------
-- "USER": a term computer professionals use when they mean "idiot".         --
--                                                             Dave Barry    --

dcook@spam.ua.oz (David Cook) (06/26/91)

In article <1991Jun25.211035.19132@convex.com> bout@convex.com (David Boutilier) writes:
>It works fine if you change nl() to nonl().

Ok. But WHY ?
In TFM for curses, I didn't see anything saying "you must have nonl()
set before using move()". I still think a terminal-independant
windowing package that has 'features' like that is buggy ..
(especially since SYS V curses gets it right with nl() )


David T Cook | e-mail: dcook@spam.adelaide.edu.au | Phone: +61 8 228 5709
Assistant Computer Manager, Stats, Pure and Applied Maths LMG, Adelaide Uni
"The wonderful thing about USENET is that anyone can express their opinion."
"The worrying thing is that they _do_."

mg@sbsvax.cs.uni-sb.de (Michael Greim) (06/26/91)

Hello,

In article <883@spam.ua.oz>, dcook@spam.ua.oz (David Cook) writes:
> (I got no answer to this question from comp.unix.programmer,
> so am re-posting to other groups. Maybe someone else knows
> this problem .... )
Maybe the reason why you did not get any answer is that your mail
address is wrong. Mail does not find "spam.ua.oz" and munnari.oz.au
says, it has no address record for "spam.oz.au" although the address was
correct and there is an entry in the nameserver.

> 
> Hello,
>   Here is a section of code I've been having trouble with,
[...]
> The current behaviour is to print the first number in each column
> in the correct place, and the other 5 appear around column 78 of the
> same line as the first number . If I remove the commented out section 
> of code, below, the program works.
> 
[...]

It seems that curses is using tabs to position the cursor to some
position on the screen, but there are no tabs set in your terminal.
Typical effect: the text is positioned at the right margin of the screen.
Try to set the tabs in your terminal, either by hand using the "setup"
feature of your terminal (if it has one), or by specifying a file
to load via tset (see manual about this).

	-mg
-- 
 .-. .-.  .-.  Michael Greim
(   X   )( __) e-mail : mg@cs.uni-sb.de
 \ / \ /  \ /  or     : ...!uunet!unido!sbsvax!mg
  ~   ~    ~

pckim@unisql.UUCP (Pyung-Chul Kim) (06/27/91)

In article <883@spam.ua.oz> dcook@spam.ua.oz (David Cook) writes:
> [some stuffs deleted ]
>The problem is, I am trying to display the array 'abroll' on the
>screen, in a 6 row by 12 column format, evenly spaced.
>The current behaviour is to print the first number in each column
>in the correct place, and the other 5 appear around column 78 of the
>same line as the first number . If I remove the commented out section 
>of code, below, the program works.
> [some stuffs deleted]

I cannot figure out the problem exactly, However,
it seems that crmode() (actually, replaced by cbreak()) followed by nl()
causes output as if the terminal doesn't map NEWLINE into NL/CR,
meanwhile, the terminal actually maps NL to NL/CR.
To see this, try following:
	% a.out > scriptsfile; stty -onlcr; cat scriptfile; stty onlcr
If you remove crmode() or nl(), or even change the position, i.e.,
nl() followed by crmode(), the program will work.
If you got what the exact solution is, please let me know.


-- 
Pyung-Chul Kim

UniSQL, Inc.
9390 Research Blvd., Kaleido II, Suite 220, Austin, TX 78759
Internet: execu!sequoia!unisql!pckim@cs.utexas.edu
UUCP: {uunet, cs.utexas.edu!execu}!sequoia!unisql!pckim
TEL: (512)343-7297 Ext. 332
FAX: (512)343-7383