[comp.unix.programmer] Reading termcap database other than termcap

wayne@cs.odu.edu (C Wayne Huling) (11/27/90)

  I have written a small program to accept the name of a printer and search
the printcap for the hostmachine.  I use the termcap routines supplied in the
Unix PRM.  Unfortunatly it reads from a environment set variable.  My problem
is if I set this variable "TERM" to be /etc/printcap and then run another
program that needs "TERM" to be /etc/termcap then it will bomb.  Is there any
way of setting the file to be read from internally?


		Wayne
--
--->  Sometimes I have evil thoughts......
--->        GC.    

mjr@hussar.dco.dec.com (Marcus J. Ranum) (11/27/90)

In article <WAYNE.90Nov26180444@forchammer.cs.odu.edu> wayne@cs.odu.edu (C Wayne Huling) writes:
>
>  I have written a small program to accept the name of a printer and search
>the printcap for the hostmachine.  I use the termcap routines supplied in the
>Unix PRM.  Unfortunatly it reads from a environment set variable.  My problem
>is if I set this variable "TERM" to be /etc/printcap and then run another
>program that needs "TERM" to be /etc/termcap then it will bomb.  Is there any
>way of setting the file to be read from internally?

	I have a hacked up copy of the printcap code from the BSD 'lpr'
command that implements a "caplib" library - generic "termcap" capabilities.
It differs from the "standard" termcap in that it wants to know the sizes
of the buffers passed to it, and checks for overflow. It also doesn't
support the egregious tc= kludge. There's no support for grabbing the
entry out of the environment, but that shouldn't be very hard at all.
[the way BSD does that also is a kludge - getting it out of the environment
or not should be done at a higher level than in capgetent(), IE: if there
is no XXXXCAP in the environment, *then* it uses capgetent(), etc]

	If anyone wants a copy, let me know.

mjr.
-- 
	Good software will grow smaller and faster as time goes by and
the code is improved and features that proved to be less useful are
weeded out.	[from the programming notebooks of a heretic, 1990]

root@tndsyd.oz (the main man) (11/29/90)

In article <WAYNE.90Nov26180444@forchammer.cs.odu.edu>, wayne@cs.odu.edu (C Wayne Huling) writes:
> 
>   I have written a small program to accept the name of a printer and search
> the printcap for the hostmachine.  I use the termcap routines supplied in the
> Unix PRM.  Unfortunatly it reads from a environment set variable.  My problem
> is if I set this variable "TERM" to be /etc/printcap and then run another
> program that needs "TERM" to be /etc/termcap then it will bomb.  Is there any
> way of setting the file to be read from internally?

You could do a:
	putenv("TERMCAP=/etc/printcap");

within your program before using terminfo or curses routines but
remember that if the program spawns a new process it will have this
in its environment.

By the way I assume you mean the TERMCAP environment variable and not
TERM since TERM specifies the terminal type and not the database location.


.===========================================================================.
|   ACSnet: berny@tndsyd.oz       UUCP: uunet!munnari.oz!tndsyd.oz.au!berny |
| INTERNET: berny@tndsyd.oz.au  DOMAIN: goodheart_berny@tandem.com          |
|   PSMAIL: smtpgate @comm(berny@tndsyd.oz@munnari.oz.au)                   |
|  FIDONET: berny@f614.n713.z3.fidonet.org@tndsyd.oz.au  (3:713/614.0)      |
`==========================================================================='
TANDEM Computers Incorporated 76 Berry St, North Sydney, NSW, 2060, Australia

hotte@sunrise.in-berlin.de (Horst Laumer) (11/29/90)

mjr@hussar.dco.dec.com (Marcus J. Ranum) writes:

>	I have a hacked up copy of the printcap code from the BSD 'lpr'
>command that implements a "caplib" library - generic "termcap" capabilities.
>It differs from the "standard" termcap in that it wants to know the sizes
>of the buffers passed to it, and checks for overflow. It also doesn't
>support the egregious tc= kludge. There's no support for grabbing the
>entry out of the environment, but that shouldn't be very hard at all.
>[the way BSD does that also is a kludge - getting it out of the environment
>or not should be done at a higher level than in capgetent(), IE: if there
>is no XXXXCAP in the environment, *then* it uses capgetent(), etc]

>	If anyone wants a copy, let me know.

I would be very interested in a copy. BTW, wouldn't it be good posting it ?
(Rich Salz and c.s.u., ok, ok)

thanks ahead
hl

-- 
============================================================================
Horst Laumer, Kantstrasse 107, D-1000 Berlin 12 ! Bang-Adress: 
Domain: hotte@sunrise.in-berlin.de              ! Junk-Food for Autorouters
Bang:   ...unido!fub!geminix!sunrise!hotte      ! -- me --

sjg@melb.bull.oz.au (Simon J Gerraty) (11/30/90)

In <WAYNE.90Nov26180444@forchammer.cs.odu.edu> wayne@cs.odu.edu (C Wayne Huling) writes:
>  I have written a small program to accept the name of a printer and search
>the printcap for the hostmachine.  I use the termcap routines supplied in the
>Unix PRM.  Unfortunatly it reads from a environment set variable.  My problem
>is if I set this variable "TERM" to be /etc/printcap and then run another
>program that needs "TERM" to be /etc/termcap then it will bomb.  Is there any
>way of setting the file to be read from internally?

I could not find any clean method of using the termcap routines
to handle files like /etc/printcap.  I ran into the same problem
that you have while writing a daemon to service remote printers
attached to terminal servers.  After some mucking about, I wrote
a simple library module to mimic (as far as I can tell) the
termcap routines but providing a more generalised mechanism.

Here is an extract:

/* NAME:
 *      cap.c - facility like termcap
 *
 * SYNOPSIS:
 *      int cap_getent(char *buf, char *name);
 *      int cap_getnum(char *id);
 *      int cap_getflag(char *id);
 *      char *cap_getstr(char *id, char **area);
 *
 * DESCRIPTION:
 *      This module provides a general analogy to the TERMCAP facility.
 *      If the variable _cap_database is not set, cap behaves like termcap.

It handles things like following tc=like entries.  If the "like"
entry is in the same file it is simply absorbed into the entity
being retrieved, otherwise the tc=like entry is left at the end.

The source is about 4k.  Let me know if you want a copy.
-- 
Simon J. Gerraty		<sjg@melb.bull.oz.au>

#include <disclaimer,_witty_comment>

peter@ficc.ferranti.com (Peter da Silva) (11/30/90)

Use the replacement termlib routines I recently posted to alt.sources
(mainly to help people porting "elvis"). Not only are the compatible,
but they support multicharacter sequences (:foo=...:), which really
helps when you're using termcap for other purposes and you want to avoid
really strained mnemonics.
-- 
Peter da Silva.   `-_-'
+1 713 274 5180.   'U`
peter@ferranti.com