Subject: Re: tgetnum - bug or feature?
To: None <current-users@NetBSD.ORG>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: current-users
Date: 04/22/1997 06:54:39
-----BEGIN PGP SIGNED MESSAGE-----

> I've got a piece of code, many moons old, which does something like
> 	width = tgetnum("co");
> This has worked forever.

> Suddenly, it is dumping core.

> Study reveals that running tgetent() before doing this fixes the core
> dump.  No other system I currently have access to requires me to run
> tgetent first.

I am totally astonished that you would even _consider_ calling tgetnum
without having first called tgetent; I am also astonished that it works
anywhere.

> The documentation (which looks fairly pre-ANSI) does not seem to hint
> at a definitive answer.

Nothing _definitive_, perhaps, but the phrasing certainly says to me
that you have to call tgetent first:

	The tgetent function extracts the entry for terminal name into
	the buffer at bp.  The bp argument should be a character buffer
	of size 1024 and must be retained through all subsequent calls
	to tgetnum, tgetflag, and tgetstr.

No hint is given of what happens if you call one of the last three
without having given libtermcap a buffer to use via tgetent.  I'm not a
bit surprised it cores.

> Bug?  Feature?  I could go either way on this, although I slightly
> prefer the behavior I get elsewhere, where tget* all work on the
> current terminal type unless I run tgetent to look at a different
> one.

IMO "elsewhere" is being surprisingly tolerant, letting you get away
without tgetent.

					der Mouse

			       mouse@rodents.montreal.qc.ca
		     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B

-----BEGIN PGP SIGNATURE-----
Version: 2.6.3ia
Charset: latin1

iQCVAwUBM1yY3tiXPKPXYL91AQHQLQP/e32/l+Bh3y7sHLGDMdB8JRP8PT6/llGS
Rp2dpuRze5NOVeD3dkp4OlC2g7nZ+R4/zkIXePb02vcC3USwXitVAjKIy3h7RoU7
q2/BPUAjr0NeqSOzRfHDsAz8neHV93UQ+ao+DYAfXLGTK40D5p63wnTNfu9S+FeK
heAJMOrEI2Y=
=c+/v
-----END PGP SIGNATURE-----