Subject: Re: A solution for termcap lossage?
To: None <>
From: Christos Zoulas <>
List: tech-userlevel
Date: 04/21/1999 14:19:49
In article <199904211318.WAA05311@mallee.awadi> (Brett Lymn) writes:
>        Myself and Julian Coleman have been doing some work on
>upgrading the NetBSD curses library, hopefully to full POSIX
>compliance (no guarentee on when/if that will occur though).  One
>thing we have discussed is how to exceed the 1023 character limit
>imposed by the tgetent call as it is clear to us that this limit will
>cause us grief.  One approach is to create a new call that is
>functionally similar to tgetent but does not truncate the termcap
>entry but, rather, returns an malloc'ed buffer containing the complete
>entry - this is very easy to implement, I have already done so (the
>patch for libterm is available on request).

If you are going to fix the api, then fix all of it:

struct tinfo_t;	/* Opaque */

OLD:    int tgetent(char *bp, char *name);
NEW:	const tinfo_t *t_getent(const char *name);

OLD:	int tgetnum(char *id);
NEW:	int t_getnum(const tinfo_t *t, int *);

OLD:    int tgetflag(char *id);
NEW:    int t_getflag(const tinfo_t *t, const char *id);

OLD:    char *tgetstr(char *id, char **area);
NEW:	int t_getstr(const tinfo_t *t, const char *id, char *buf, size_t bufsz);

OLD:    char *tgoto(char *cm, int destcol, int destline);
NEW:	int t_goto(const tinfo_t *t, const char *cm, int destcol, int destline,
		   char *buf, size_t bufsz);

OLD:    void tputs(char *cp, int affcnt, void (*outc)(int));
NEW:	int t_puts(const tinfo_t *t, const char *cp, int affcnt, 
		   int (*outc)(void *arg), void *outcarg);

NEW:	void t_freeent(const tinfo_t *t);

So that everything is re-entrant does not depend on global variables,
the interface can be used with more than one terminal at a time, and
all errors can be caught.