[comp.unix.programmer] CURSES

jham@mcs213k.cs.umr.edu (John Ham) (01/30/91)

Are there any source code examples of how to use 'curses' in C on
the RS/6000 with the 'pcc' compiler that I can ftp?  Our documentation
consists of two pages listing the functions, and suggesting a book
by Ken Arnold (which our library does not have).  All I want to do
is clear the screen, move to a specific row, column location, prompt
for input, grab input, and that's it.  Any help would be appreciated.
jham@cs.umr.edu

burroak@convex.cl.msu.edu (newell franks) (05/02/91)

I'm having a problem with switch(c) while programming with curses. The keys 
don't function as I thought they should. I am by no means an expert C
programmer, and I have only recently been introduced to curses, but I don't see
any syntax problems and the switch statements are pretty straight foward. I am
also not sure if I should use the raw() mode to do this kind of key
manipulation during the switch. Below is basically the switch code that I'm
using. The loop basically checks to see if the key being pressed is a special
key and if it is, it performs some special action.

NOTE: I'm running this on an HP9000/375 HP-UX 7.0 system. I only point this out
      because of some of the unique unsupported features of this compiler.


Any help or suggestions would be greatly appreciated. Please send E-mail to 
burroak@convex.cl.msu.edu.

Thanks,      Jeff 




for(;EVER;)
{
	move(a[field].y, a[field.x + offset);
	c = getch();
	switch(c) {

			case '\t':	field ++;
        	                        offset = 0;
 					move(a[field].y , a[field].x + offset);
					refresh();
					break;
			case '\r':	field ++;
        	                        offset = 0;
 					move(a[field].y , a[field].x + offset);
					refresh();
					break;

			case KEY_ENTER:	field ++;
        	                        offset = 0;
 					move(a[field].y , a[field].x + offset);
					refresh();
					break;
 
			case KEY_BACKSPACE:
			case KEY_DOWN:	field ++;
        	                        offset = 0;
 					move(a[field].y , a[field].x + offset);
					refresh();
					break;

			case KEY_UP:    
			case KEY_LEFT:
			case KEY_RIGHT:
			case KEY_HOME:
			case KEY_F(1):
			case KEY_F(2):
			case KEY_F(3):
			case KEY_F(4):
			case KEY_F(5):
			case KEY_F(6):
			case KEY_F(7):
			case KEY_F(8):
}

njacobs@kong.gsfc.nasa.gov (Nick Jacobs - EOS) (05/03/91)

In article <1991May1.192004.25227@msuinfo.cl.msu.edu> burroak@convex.cl.msu.edu (newell franks) writes:
>I'm having a problem with switch(c) while programming with curses. The keys 
>don't function as I thought they should. I am by no means an expert C

What exactly happens when you run the program? It's difficult to help
when you don't say what goes wrong.
BTW did you remember to call cbreak() and keypad( window, TRUE ) near
the beginning?

Nick Jacobs

allbery@NCoast.ORG (Brandon S. Allbery KB8JRR/AA) (05/03/91)

As quoted from <1991May1.192004.25227@msuinfo.cl.msu.edu> by burroak@convex.cl.msu.edu (newell franks):
+---------------
| I'm having a problem with switch(c) while programming with curses. The keys 
| don't function as I thought they should. I am by no means an expert C
| 
| 	c = getch();
| 	switch(c) {
| 			case KEY_BACKSPACE:
| 			case KEY_DOWN:	field ++;
+---------------

Dumb question:  how did you declare "c"?  It should be declared as type
"chtype" (declared by curses.h) --- "char" and "unsigned char" are too short,
as the special keys are given values greater than 256.

++Brandon
-- 
Me: Brandon S. Allbery			  Ham: KB8JRR/AA  10m,6m,2m,220,440,1.2
Internet: allbery@NCoast.ORG		       (restricted HF at present)
Delphi: ALLBERY				 AMPR: kb8jrr.AmPR.ORG [44.70.4.88]
uunet!usenet.ins.cwru.edu!ncoast!allbery       KB8JRR @ WA8BXN.OH

jgabriel@mtecv2.mty.itesm.mx (Juan Gabriel Ruiz Pinto) (05/04/91)

allbery@NCoast.ORG (Brandon S. Allbery KB8JRR/AA) writes:

>Dumb question:  how did you declare "c"?  It should be declared as type
>"chtype" (declared by curses.h) --- "char" and "unsigned char" are too short,
>as the special keys are given values greater than 256.

    I try this in a VAX-6310 running Ultrix 3.0 and I get an strange
  result. First of all I need to add the keypad(stdscr,TRUE) option,
  and when I compile the program with the 'cc' compiler, it doesn't
  return the correct KEY_* number, but if I compile the same program
  with the 'vcc' (Vax CC) compiler it works fine.
    Somebody could explain this?
-- 
Juan Gabriel Ruiz Pinto                   Internet:
Ing. Sistemas Electronicos                jgabriel@mtecv2.mty.itesm.mx
I.T.E.S.M. Campus Monterrey