1999-08-24 01:06:48 +00:00
|
|
|
/****************************************************************************
|
2002-05-21 05:30:25 +00:00
|
|
|
* Copyright (c) 1998,2000,2001 Free Software Foundation, Inc. *
|
1999-08-24 01:06:48 +00:00
|
|
|
* *
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a *
|
|
|
|
* copy of this software and associated documentation files (the *
|
|
|
|
* "Software"), to deal in the Software without restriction, including *
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish, *
|
|
|
|
* distribute, distribute with modifications, sublicense, and/or sell *
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is *
|
|
|
|
* furnished to do so, subject to the following conditions: *
|
|
|
|
* *
|
|
|
|
* The above copyright notice and this permission notice shall be included *
|
|
|
|
* in all copies or substantial portions of the Software. *
|
|
|
|
* *
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
|
|
|
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
|
|
|
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
|
|
|
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
|
|
|
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
|
|
|
* *
|
|
|
|
* Except as contained in this notice, the name(s) of the above copyright *
|
|
|
|
* holders shall not be used in advertising or otherwise to promote the *
|
|
|
|
* sale, use or other dealings in this Software without prior written *
|
|
|
|
* authorization. *
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
|
|
|
|
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* toe.c --- table of entries report generator
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <progs.priv.h>
|
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include <dump_entry.h>
|
|
|
|
#include <term_entry.h>
|
|
|
|
|
2002-05-21 05:30:25 +00:00
|
|
|
MODULE_ID("$Id: toe.c,v 1.26 2001/06/16 11:00:41 tom Exp $")
|
2000-07-03 09:24:12 +00:00
|
|
|
|
|
|
|
#define isDotname(name) (!strcmp(name, ".") || !strcmp(name, ".."))
|
1999-08-24 01:06:48 +00:00
|
|
|
|
|
|
|
const char *_nc_progname;
|
|
|
|
|
|
|
|
static int typelist(int eargc, char *eargv[], bool,
|
2002-05-21 05:30:25 +00:00
|
|
|
void (*)(const char *, TERMTYPE *));
|
1999-08-24 01:06:48 +00:00
|
|
|
static void deschook(const char *, TERMTYPE *);
|
|
|
|
|
|
|
|
#if NO_LEAKS
|
|
|
|
#undef ExitProgram
|
2000-07-03 09:24:12 +00:00
|
|
|
static void
|
|
|
|
ExitProgram(int code) GCC_NORETURN;
|
|
|
|
static void ExitProgram(int code)
|
1999-08-24 01:06:48 +00:00
|
|
|
{
|
2000-07-03 09:24:12 +00:00
|
|
|
_nc_free_entries(_nc_head);
|
|
|
|
_nc_leaks_dump_entry();
|
|
|
|
_nc_free_and_exit(code);
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-05-21 05:30:25 +00:00
|
|
|
static bool
|
|
|
|
is_a_file(char *path)
|
|
|
|
{
|
|
|
|
struct stat sb;
|
|
|
|
return (stat(path, &sb) == 0
|
|
|
|
&& (sb.st_mode & S_IFMT) == S_IFREG);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
is_a_directory(char *path)
|
|
|
|
{
|
|
|
|
struct stat sb;
|
|
|
|
return (stat(path, &sb) == 0
|
|
|
|
&& (sb.st_mode & S_IFMT) == S_IFDIR);
|
|
|
|
}
|
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
static char *
|
|
|
|
get_directory(char *path)
|
|
|
|
{
|
|
|
|
if (path != 0) {
|
2002-05-21 05:30:25 +00:00
|
|
|
if (!is_a_directory(path)
|
2000-07-03 09:24:12 +00:00
|
|
|
|| access(path, R_OK | X_OK) != 0)
|
|
|
|
path = 0;
|
|
|
|
}
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
1999-08-24 01:06:48 +00:00
|
|
|
{
|
2000-07-03 09:24:12 +00:00
|
|
|
bool direct_dependencies = FALSE;
|
|
|
|
bool invert_dependencies = FALSE;
|
|
|
|
bool header = FALSE;
|
|
|
|
int i, c;
|
|
|
|
int code;
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2002-05-21 05:30:25 +00:00
|
|
|
_nc_progname = _nc_rootname(argv[0]);
|
1999-08-24 01:06:48 +00:00
|
|
|
|
|
|
|
while ((c = getopt(argc, argv, "huv:UV")) != EOF)
|
2000-07-03 09:24:12 +00:00
|
|
|
switch (c) {
|
1999-08-24 01:06:48 +00:00
|
|
|
case 'h':
|
|
|
|
header = TRUE;
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
direct_dependencies = TRUE;
|
|
|
|
break;
|
|
|
|
case 'v':
|
2000-07-03 09:24:12 +00:00
|
|
|
set_trace_level(atoi(optarg));
|
1999-08-24 01:06:48 +00:00
|
|
|
break;
|
|
|
|
case 'U':
|
|
|
|
invert_dependencies = TRUE;
|
|
|
|
break;
|
|
|
|
case 'V':
|
2000-10-11 07:31:01 +00:00
|
|
|
puts(curses_version());
|
1999-08-24 01:06:48 +00:00
|
|
|
ExitProgram(EXIT_SUCCESS);
|
|
|
|
default:
|
2000-07-03 09:24:12 +00:00
|
|
|
(void) fprintf(stderr, "usage: toe [-huUV] [-v n] [file...]\n");
|
1999-08-24 01:06:48 +00:00
|
|
|
ExitProgram(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
if (direct_dependencies || invert_dependencies) {
|
|
|
|
if (freopen(argv[optind], "r", stdin) == 0) {
|
1999-08-24 01:06:48 +00:00
|
|
|
(void) fflush(stdout);
|
|
|
|
fprintf(stderr, "%s: can't open %s\n", _nc_progname, argv[optind]);
|
|
|
|
ExitProgram(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* parse entries out of the source file */
|
|
|
|
_nc_set_source(argv[optind]);
|
2000-07-03 09:24:12 +00:00
|
|
|
_nc_read_entry_source(stdin, 0, FALSE, FALSE, NULLHOOK);
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* maybe we want a direct-dependency listing? */
|
2000-07-03 09:24:12 +00:00
|
|
|
if (direct_dependencies) {
|
|
|
|
ENTRY *qp;
|
1999-08-24 01:06:48 +00:00
|
|
|
|
|
|
|
for_entry_list(qp)
|
2000-07-03 09:24:12 +00:00
|
|
|
if (qp->nuses) {
|
|
|
|
int j;
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
(void) printf("%s:", _nc_first_name(qp->tterm.term_names));
|
|
|
|
for (j = 0; j < qp->nuses; j++)
|
|
|
|
(void) printf(" %s", qp->uses[j].name);
|
|
|
|
putchar('\n');
|
|
|
|
}
|
1999-08-24 01:06:48 +00:00
|
|
|
|
|
|
|
ExitProgram(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* maybe we want a reverse-dependency listing? */
|
2000-07-03 09:24:12 +00:00
|
|
|
if (invert_dependencies) {
|
|
|
|
ENTRY *qp, *rp;
|
|
|
|
int matchcount;
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
for_entry_list(qp) {
|
1999-08-24 01:06:48 +00:00
|
|
|
matchcount = 0;
|
2000-07-03 09:24:12 +00:00
|
|
|
for_entry_list(rp) {
|
1999-08-24 01:06:48 +00:00
|
|
|
if (rp->nuses == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (i = 0; i < rp->nuses; i++)
|
2000-07-03 09:24:12 +00:00
|
|
|
if (_nc_name_match(qp->tterm.term_names,
|
2002-05-21 05:30:25 +00:00
|
|
|
rp->uses[i].name, "|")) {
|
1999-08-24 01:06:48 +00:00
|
|
|
if (matchcount++ == 0)
|
|
|
|
(void) printf("%s:",
|
2002-05-21 05:30:25 +00:00
|
|
|
_nc_first_name(qp->tterm.term_names));
|
1999-08-24 01:06:48 +00:00
|
|
|
(void) printf(" %s",
|
2002-05-21 05:30:25 +00:00
|
|
|
_nc_first_name(rp->tterm.term_names));
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (matchcount)
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
ExitProgram(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we get this far, user wants a simple terminal type listing.
|
|
|
|
*/
|
|
|
|
if (optind < argc) {
|
2000-07-03 09:24:12 +00:00
|
|
|
code = typelist(argc - optind, argv + optind, header, deschook);
|
1999-08-24 01:06:48 +00:00
|
|
|
} else {
|
2000-07-03 09:24:12 +00:00
|
|
|
char *home, *eargv[3];
|
|
|
|
char personal[PATH_MAX];
|
|
|
|
int j;
|
1999-08-24 01:06:48 +00:00
|
|
|
|
|
|
|
j = 0;
|
2000-07-03 09:24:12 +00:00
|
|
|
if ((eargv[j] = get_directory(getenv("TERMINFO"))) != 0) {
|
|
|
|
j++;
|
|
|
|
} else {
|
|
|
|
if ((home = getenv("HOME")) != 0) {
|
1999-08-24 01:06:48 +00:00
|
|
|
(void) sprintf(personal, PRIVATE_INFO, home);
|
2000-07-03 09:24:12 +00:00
|
|
|
if ((eargv[j] = get_directory(personal)) != 0)
|
|
|
|
j++;
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
2000-10-11 07:31:01 +00:00
|
|
|
if ((eargv[j] = get_directory(strcpy(personal, TERMINFO))) != 0)
|
2000-07-03 09:24:12 +00:00
|
|
|
j++;
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
2000-07-03 09:24:12 +00:00
|
|
|
eargv[j] = 0;
|
1999-08-24 01:06:48 +00:00
|
|
|
|
|
|
|
code = typelist(j, eargv, header, deschook);
|
|
|
|
}
|
|
|
|
|
|
|
|
ExitProgram(code);
|
|
|
|
}
|
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
static void
|
|
|
|
deschook(const char *cn, TERMTYPE * tp)
|
1999-08-24 01:06:48 +00:00
|
|
|
/* display a description for the type */
|
|
|
|
{
|
|
|
|
const char *desc;
|
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
if ((desc = strrchr(tp->term_names, '|')) == 0)
|
1999-08-24 01:06:48 +00:00
|
|
|
desc = "(No description)";
|
|
|
|
else
|
|
|
|
++desc;
|
|
|
|
|
|
|
|
(void) printf("%-10s\t%s\n", cn, desc);
|
|
|
|
}
|
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
static int
|
|
|
|
typelist(int eargc, char *eargv[],
|
2002-05-21 05:30:25 +00:00
|
|
|
bool verbosity,
|
|
|
|
void (*hook) (const char *, TERMTYPE * tp))
|
1999-08-24 01:06:48 +00:00
|
|
|
/* apply a function to each entry in given terminfo directories */
|
|
|
|
{
|
2000-07-03 09:24:12 +00:00
|
|
|
int i;
|
1999-08-24 01:06:48 +00:00
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
for (i = 0; i < eargc; i++) {
|
|
|
|
DIR *termdir;
|
1999-08-24 01:06:48 +00:00
|
|
|
struct dirent *subdir;
|
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
if ((termdir = opendir(eargv[i])) == 0) {
|
1999-08-24 01:06:48 +00:00
|
|
|
(void) fflush(stdout);
|
|
|
|
(void) fprintf(stderr,
|
2002-05-21 05:30:25 +00:00
|
|
|
"%s: can't open terminfo directory %s\n",
|
|
|
|
_nc_progname, eargv[i]);
|
2000-07-03 09:24:12 +00:00
|
|
|
return (EXIT_FAILURE);
|
|
|
|
} else if (verbosity)
|
1999-08-24 01:06:48 +00:00
|
|
|
(void) printf("#\n#%s:\n#\n", eargv[i]);
|
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
while ((subdir = readdir(termdir)) != 0) {
|
|
|
|
size_t len = NAMLEN(subdir);
|
|
|
|
char buf[PATH_MAX];
|
|
|
|
char name_1[PATH_MAX];
|
|
|
|
DIR *entrydir;
|
1999-08-24 01:06:48 +00:00
|
|
|
struct dirent *entry;
|
|
|
|
|
|
|
|
strncpy(name_1, subdir->d_name, len)[len] = '\0';
|
2000-07-03 09:24:12 +00:00
|
|
|
if (isDotname(name_1))
|
1999-08-24 01:06:48 +00:00
|
|
|
continue;
|
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
(void) sprintf(buf, "%s/%s/", eargv[i], name_1);
|
2002-05-21 05:30:25 +00:00
|
|
|
if (chdir(buf) != 0)
|
|
|
|
continue;
|
|
|
|
|
1999-08-24 01:06:48 +00:00
|
|
|
entrydir = opendir(".");
|
2000-07-03 09:24:12 +00:00
|
|
|
while ((entry = readdir(entrydir)) != 0) {
|
|
|
|
char name_2[PATH_MAX];
|
|
|
|
TERMTYPE lterm;
|
|
|
|
char *cn;
|
|
|
|
int status;
|
1999-08-24 01:06:48 +00:00
|
|
|
|
|
|
|
len = NAMLEN(entry);
|
|
|
|
strncpy(name_2, entry->d_name, len)[len] = '\0';
|
2002-05-21 05:30:25 +00:00
|
|
|
if (isDotname(name_2) || !is_a_file(name_2))
|
1999-08-24 01:06:48 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
status = _nc_read_file_entry(name_2, <erm);
|
2000-07-03 09:24:12 +00:00
|
|
|
if (status <= 0) {
|
1999-08-24 01:06:48 +00:00
|
|
|
(void) fflush(stdout);
|
|
|
|
(void) fprintf(stderr,
|
2002-05-21 05:30:25 +00:00
|
|
|
"toe: couldn't open terminfo file %s.\n",
|
|
|
|
name_2);
|
2000-07-03 09:24:12 +00:00
|
|
|
return (EXIT_FAILURE);
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* only visit things once, by primary name */
|
|
|
|
cn = _nc_first_name(lterm.term_names);
|
2000-07-03 09:24:12 +00:00
|
|
|
if (!strcmp(cn, name_2)) {
|
1999-08-24 01:06:48 +00:00
|
|
|
/* apply the selected hook function */
|
2000-07-03 09:24:12 +00:00
|
|
|
(*hook) (cn, <erm);
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
|
|
|
if (lterm.term_names) {
|
|
|
|
free(lterm.term_names);
|
2000-07-03 09:24:12 +00:00
|
|
|
lterm.term_names = 0;
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
|
|
|
if (lterm.str_table) {
|
|
|
|
free(lterm.str_table);
|
2000-07-03 09:24:12 +00:00
|
|
|
lterm.str_table = 0;
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir(entrydir);
|
|
|
|
}
|
|
|
|
closedir(termdir);
|
|
|
|
}
|
|
|
|
|
2000-07-03 09:24:12 +00:00
|
|
|
return (EXIT_SUCCESS);
|
1999-08-24 01:06:48 +00:00
|
|
|
}
|