Reading termcap database other than termcap
Simon J Gerraty
sjg at melb.bull.oz.au
Fri Nov 30 09:36:25 AEST 1990
In <WAYNE.90Nov26180444 at forchammer.cs.odu.edu> wayne at 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 at melb.bull.oz.au>
#include <disclaimer,_witty_comment>
More information about the Comp.unix.programmer
mailing list