PROBLEMS WITH tgetent() AND tgetstr()

PROBLEMS WITH tgetent() AND tgetstr()

Post by Eskandar Ensa » Thu, 11 Nov 1993 09:13:55



Hello,

I am experiencing problems using tgetent() and tgetstr().  Has anyone had the
same problems as I have outlined in my program below?  I think it has something
to do with allocating memory for the second argument of tgetstr(*id, **area);
basically, my program exits with either code 012 or code 0364 under gdb.

/*
 * Compiled using: cc this_program.c -ltermcap
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

main()
{
        char  termcap[1024];
        char  *term = (char *)getenv("TERM");

        char  *area = (char *)malloc( 252);

        /* I was advised NOT to malloc the area pointer; however, when I do no
           allocate memory for it, my program exits with a Bus Error.  I also
           tried to declare it as area[1024], but I still got a Bus Error.
         */

        if(!term) strcpy(term, "unknown");

        tgetent(termcap, term);

        printf("\n%s\n%s\n", term, termcap);

        tgetstr("me", &area);

        /* If I do not debug my program, it appears that everything worked.
           Sure, I got my terminal attribues like I wanted, but there is an
           annoying (malloc-related?) side-effect: my program exits with a
           code other than 0 (zero) in gdb: "Program exited with code 0364".
         */

Quote:}

Thanks!  E-MAIL WOULD BE APPRECIATED...

- Eskandar

--
"Dance with the dead in my dreams
 Listen to their hollowed screams
 The dead have taken my soul
 Temptation's lost all control" -- Slayer (Dead Skin Mask)

 
 
 

PROBLEMS WITH tgetent() AND tgetstr()

Post by Nga T A W » Fri, 12 Nov 1993 13:55:32



>Hello,

>I am experiencing problems using tgetent() and tgetstr().  Has anyone had the
>same problems as I have outlined in my program below?  I think it has something
>to do with allocating memory for the second argument of tgetstr(*id, **area);
>basically, my program exits with either code 012 or code 0364 under gdb.

>/*
> * Compiled using: cc this_program.c -ltermcap
> */

>#include <stdio.h>
>#include <stdlib.h>
>#include <string.h>

>main()
>{
>    char  termcap[1024];
>    char  *term = (char *)getenv("TERM");

>    char  *area = (char *)malloc( 252);

>    /* I was advised NOT to malloc the area pointer; however, when I do no
>       allocate memory for it, my program exits with a Bus Error.  I also
>       tried to declare it as area[1024], but I still got a Bus Error.
>     */

>    if(!term) strcpy(term, "unknown");

>    tgetent(termcap, term);

>    printf("\n%s\n%s\n", term, termcap);

>    tgetstr("me", &area);

>    /* If I do not debug my program, it appears that everything worked.
>       Sure, I got my terminal attribues like I wanted, but there is an
>       annoying (malloc-related?) side-effect: my program exits with a
>       code other than 0 (zero) in gdb: "Program exited with code 0364".
>     */
>}

        Try adding a return statement.
        Hope this helps.

                                                        Alex Wan
                                                        =|:)>+<

--
WAN, Nga Ting Alex [Wan5 Ngaa5 Ting4]  | Internet:

University of Manitoba, Canada =|:)>+< | phone: (204) 261-9362
--------------------------------------------------------------------------------

 
 
 

PROBLEMS WITH tgetent() AND tgetstr()

Post by Jim Qui » Fri, 12 Nov 1993 21:51:45


Do this.

        char termcap[1024];
        char common[1024];
        char *area = common;
        char    *foo = 0;
        char    *bar = 0;

        . . .

        foo = tgetsr("foo", &area);
        bar = tgetsr("bar", &area);
        after calls to tgetstr the buffer 'common' will contain
        valueOfFoo\0valueOfBar\0. . . . . . .
        area will point to here ^ and marks the next unused entry
        in your local string heap 'common'.

So, area simply walks through a buffer and retains the value of
the place to put the next string.  Since termcap strings are variable
length this saves you from having to allocate a separate buffer for
each value you use.  You just need to store pointers (foo , bar) to
find the strings that in your common heap.

--
  ___ ___   mail: uunet!phcs!jq     PHCS, Inc. Advanced Technology Group

\_/ (_\/   Voice: (617) 861-5579   pronounced "Throat-Warbler Mangrove".
       )                                                  NeXTMail O.K.

 
 
 

1. tgetstr() problems & incomplete curses library

Hello,

I have noticed that using 'tgetstr( char *id, char **area)' results in
my programs exiting with either code 012 or 0360.  After some debugging, I
realized that it was [partly?] due to memory allocation problems -- the
program cannot successfully 'free( area)', where 'area' is a 'char *' pointer
declared as follows:

        char  *area = (char *)malloc( 252);

I successfully read the termcap entry under vt100 emulation:

        char  buffer[ 1024];

        tgetent( buffer, "vt100");

I then attempted to:

        tgetstr( "me", &area);   /* the code for all attributes off */

As expected, 'area' was incremented by the number of bytes contained in the
termcap entry for "me", plus an additional byte for the null character which
terminates the entry.  The string returned was correct: "ESC-[-m".

Then, when the program terminated (running under gdb), it exited with an
error code (012 _without_ explicitly calling 'free( area)' and 0360 when I
attempted to 'free( area)' myself before exiting.)

What could the problem be?

And to top this off, my curses library lacks attron(), attroff(), etc..., so
I can't even give up and use those functions instead -- I *REALLY* need help!

Thanks in advance!

- Eskandar

P.S.  Why doesn't NeXT update its libcurses.a (not to mention a whole bunch of
      other UNIXish C libraries) ???

--
"Dance with the dead in my dreams
 Listen to their hollowed screams
 The dead have taken my soul
 Temptation's lost all control" -- Slayer (Dead Skin Mask)

2. PATCH: ne2k-cbus support

3. egcs-1.1a & ssh-2.0.8 won't build: Where are tputs(), tgetent(), tgetstr() functions?

4. rsh in Redhat 6.0

5. Matrox Mystique ands X.

6. Concentric.net Connection

7. SysV version of tgetstr (etc)?

8. Help - Resolution Setup

9. tgetstr/tputs - Text attributes not behaving as documented in termcap

10. Unix Programming Books - Curses/tgetstr/tputs/terminal text wrap?

11. Getting rid of tgetent error in termcap-2.0.8

12. tgetent: warning: termcap entry too long

13. using tgetent()