Fun with descriptors, curses, and setupterm()

Fun with descriptors, curses, and setupterm()

Post by Orion Hen » Sat, 16 Mar 1996 04:00:00



I have a few questions about these three topics.  The situation is
this: I've got a program which writes to multiple terminals via
descriptors.  Currently I'm just using accept() to grab the
descriptor, do some set-up work with it, and then just read() and
write() to it.  This works fine, but I was hoping I could get more
control over the user's screen without having to learn vt100 codes -
namely, I want to use curses (which I have used in the past and am
somewhat familiar with).  Curses, however, mostly orients around
writing to the terminal to which a process is attached - no good for
me because my program usually isn't even attached to a terminal, and
I will be writing to 50 to 100 different terminals at a time
anyways.  A spin through the man page shows that newterm() does what
I want, except that it takes a FILE stream pointer rather than a
descriptor, and I know of no way to translate descriptor to FILE *.
I found that setupterm() takes only a descriptor, but the functions
this allows you access to are rather basic, so while this works, it
doesn't help me a whole lot (is setupterm() a part of termcap or
something?).
If, finally, I just can't use curses through a socket, or if it's
going to be too slow for a large number of connections (I really
need to minimize my processor usage if possible), then as a last
resort some sort of resource about vt-100 codes would be handy but I
haven't been able to find anything at all about this from my
standard places of referance.

Thanks in advance for any comments/ideas/answers...I will be
watching both email and follow-ups.

 
 
 

Fun with descriptors, curses, and setupterm()

Post by Matt Rya » Sat, 16 Mar 1996 04:00:00



> I will be writing to 50 to 100 different terminals at a time
> anyways.  A spin through the man page shows that newterm() does what
> I want, except that it takes a FILE stream pointer rather than a
> descriptor, and I know of no way to translate descriptor to FILE *.

fdopen() ???

Matt.

 
 
 

Fun with descriptors, curses, and setupterm()

Post by Ben Ry » Sun, 17 Mar 1996 04:00:00



Quote:

>I have a few questions about these three topics.  The situation is
>this: I've got a program which writes to multiple terminals via
>descriptors.  Currently I'm just using accept() to grab the
>descriptor, do some set-up work with it, and then just read() and
>write() to it.

I believe one of the curses initialisation functions allows you to supply as an argument
the terminal type. (It normally uses the TERM environment variable). If there is such a function
then you could pass the TERM setting of the remote terminal down your socket during your
'set-up work' phase and use it as the argument. (Telnet has to do something similiar to this).

My other thought is you may have to push a module onto the stream head. (Assuming your Unix is
System V based.) If there is a need to do this then it is related to making ioctl() calls work correctly.
(Curses needs raw mode etc.)
Hopefully someone will clarify if this is really neccessary.

----
Ben Ryan

 
 
 

Fun with descriptors, curses, and setupterm()

Post by Orion Hen » Wed, 27 Mar 1996 04:00:00


Okay I've been playing with this some - if you missed my original
post I was basically asking how to use curses (via newterm()) given
only a file descriptor to some remote machine.  I have sucessfully
been able to use setupterm() and set_curterm() to output to the
descriptor, so I know it can be done, but newterm() wants a FILE *
for the in and out streams.  fdopen() didn't work...the code looks
something like this:

SCREEN *scr;
FILE *in, *out;
int descriptor;

  if (!(in = fdopen(descriptor, "r")) ||
      !(out = fdopen(descriptor, "w")))
    return ERROR;

  scr = newterm(0, in, out);

I suppose it doesn't help that I don't know what that first argument
to newterm() is supposed to be - the man page just says "type" but
doesn't mention what this value should be.  I don't get any errors
from fdopen()ing the streams, but input and output through curses
don't work when I do this.  I've tried fooling with the second arg
of fdopen(), using w+ and a and a few others, but always the same
result.

Any insight appreciated.

 
 
 

Fun with descriptors, curses, and setupterm()

Post by Drazen Kac » Wed, 27 Mar 1996 04:00:00


: I want, except that it takes a FILE stream pointer rather than a
: descriptor, and I know of no way to translate descriptor to FILE *.

Man fdopen?
--
Life is a *ly transmitted disease.



 
 
 

1. Fun fun fun! :)

I upgraded xf 4.0 to xf 4.0.1 on my PPC running YDL 1.2 (redhat).  I
wanted the latest and greatest video driver... which seems to be very
nice, so far!!

Well, for anyone about to do this, be warned that the XF86Config file
has incorrect keyboard mappings for G4s, anyway.  You can copy the old
settings from the old config file, and you have to do some tweaking
since the config file format has changed, but I think it will be obvious
to you when you compare the two.

Good luck to anyone else out there who is getting ready to upgrade.  I
also upgraded gnome to helix-gnome last night...  that too was an
adventure.  But thanks to the many helpful people who read this
newsgroup, I was able to get through it!   :)

Thanks!

Mike J.

2. User Identity on a protected access

3. fun, fun fun

4. DSL: mysterious appearance of eth0 on routing table after long connection

5. KIllustrator: fun, fun, fun.

6. Is it worth upgrading from apache 1.3.6 to 1.3.11?

7. curses curses curses

8. The invisible mouse FIX!

9. Matrox Mystique ands X.

10. Ethernet card fun/APM fun

11. Need help with C (setupterm() function)

12. Where is setupterm() defined

13. Why doesn' setupterm() work in his context?