/****************************************************************************
- * Copyright (c) 1998-2000 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2002,2005 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
****************************************************************************/
/*
#include <sys/stat.h>
#include <dump_entry.h>
-#include <term_entry.h>
-MODULE_ID("$Id: toe.c,v 1.22 2000/03/11 21:47:35 tom Exp $")
+MODULE_ID("$Id: toe.c,v 1.29 2005/09/25 00:39:43 tom Exp $")
#define isDotname(name) (!strcmp(name, ".") || !strcmp(name, ".."))
const char *_nc_progname;
static int typelist(int eargc, char *eargv[], bool,
- void (*)(const char *, TERMTYPE *));
+ void (*)(const char *, TERMTYPE *));
static void deschook(const char *, TERMTYPE *);
#if NO_LEAKS
}
#endif
+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);
+}
+
static char *
get_directory(char *path)
{
if (path != 0) {
- struct stat sb;
- if (stat(path, &sb) != 0
- || (sb.st_mode & S_IFMT) != S_IFDIR
+ if (!is_a_directory(path)
|| access(path, R_OK | X_OK) != 0)
path = 0;
}
int i, c;
int code;
- if ((_nc_progname = strrchr(argv[0], '/')) == 0)
- _nc_progname = argv[0];
- else
- _nc_progname++;
+ _nc_progname = _nc_rootname(argv[0]);
while ((c = getopt(argc, argv, "huv:UV")) != EOF)
switch (c) {
invert_dependencies = TRUE;
break;
case 'V':
- (void) fputs(NCURSES_VERSION, stdout);
- putchar('\n');
+ puts(curses_version());
ExitProgram(EXIT_SUCCESS);
default:
(void) fprintf(stderr, "usage: toe [-huUV] [-v n] [file...]\n");
if (direct_dependencies) {
ENTRY *qp;
- for_entry_list(qp)
+ for_entry_list(qp) {
if (qp->nuses) {
- int j;
+ int j;
- (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');
+ (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');
+ }
}
ExitProgram(EXIT_SUCCESS);
for (i = 0; i < rp->nuses; i++)
if (_nc_name_match(qp->tterm.term_names,
- rp->uses[i].name, "|")) {
+ rp->uses[i].name, "|")) {
if (matchcount++ == 0)
(void) printf("%s:",
- _nc_first_name(qp->tterm.term_names));
+ _nc_first_name(qp->tterm.term_names));
(void) printf(" %s",
- _nc_first_name(rp->tterm.term_names));
+ _nc_first_name(rp->tterm.term_names));
}
}
if (matchcount)
if ((eargv[j] = get_directory(personal)) != 0)
j++;
}
- if ((eargv[j] = get_directory(TERMINFO)) != 0)
+ if ((eargv[j] = get_directory(strcpy(personal, TERMINFO))) != 0)
j++;
}
eargv[j] = 0;
static int
typelist(int eargc, char *eargv[],
- bool verbosity,
- void (*hook) (const char *, TERMTYPE * tp))
+ bool verbosity,
+ void (*hook) (const char *, TERMTYPE * tp))
/* apply a function to each entry in given terminfo directories */
{
int i;
for (i = 0; i < eargc; i++) {
DIR *termdir;
- struct dirent *subdir;
+ DIRENT *subdir;
if ((termdir = opendir(eargv[i])) == 0) {
(void) fflush(stdout);
(void) fprintf(stderr,
- "%s: can't open terminfo directory %s\n",
- _nc_progname, eargv[i]);
+ "%s: can't open terminfo directory %s\n",
+ _nc_progname, eargv[i]);
return (EXIT_FAILURE);
} else if (verbosity)
(void) printf("#\n#%s:\n#\n", eargv[i]);
char buf[PATH_MAX];
char name_1[PATH_MAX];
DIR *entrydir;
- struct dirent *entry;
+ DIRENT *entry;
strncpy(name_1, subdir->d_name, len)[len] = '\0';
if (isDotname(name_1))
continue;
(void) sprintf(buf, "%s/%s/", eargv[i], name_1);
- chdir(buf);
+ if (chdir(buf) != 0)
+ continue;
+
entrydir = opendir(".");
while ((entry = readdir(entrydir)) != 0) {
char name_2[PATH_MAX];
len = NAMLEN(entry);
strncpy(name_2, entry->d_name, len)[len] = '\0';
- if (isDotname(name_2))
+ if (isDotname(name_2) || !is_a_file(name_2))
continue;
status = _nc_read_file_entry(name_2, <erm);
if (status <= 0) {
(void) fflush(stdout);
(void) fprintf(stderr,
- "toe: couldn't open terminfo file %s.\n",
- name_2);
+ "toe: couldn't open terminfo file %s.\n",
+ name_2);
return (EXIT_FAILURE);
}