X-Git-Url: http://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=progs%2Ftoe.c;h=abeffde18c487e05c68e1c6c08b4a4ddaaf7d692;hp=b7afb676b015ee234a3db4b053c4a8475dbcb5b4;hb=46722468f47c2b77b3987729b4bcf2321cccfd01;hpb=c633e5103a29a38532cf1925257b91cea33fd090 diff --git a/progs/toe.c b/progs/toe.c index b7afb676..abeffde1 100644 --- a/progs/toe.c +++ b/progs/toe.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2001,2002 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 * @@ -43,14 +43,14 @@ #include #include -MODULE_ID("$Id: toe.c,v 1.24 2000/09/09 19:52:35 tom Exp $") +MODULE_ID("$Id: toe.c,v 1.27 2002/10/06 01:22:05 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 @@ -65,13 +65,27 @@ ExitProgram(int code) GCC_NORETURN; } #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; } @@ -87,7 +101,7 @@ main(int argc, char *argv[]) int i, c; int code; - _nc_progname = _nc_basename(argv[0]); + _nc_progname = _nc_rootname(argv[0]); while ((c = getopt(argc, argv, "huv:UV")) != EOF) switch (c) { @@ -127,14 +141,15 @@ main(int argc, char *argv[]) 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); @@ -153,12 +168,12 @@ main(int argc, char *argv[]) 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) @@ -214,8 +229,8 @@ deschook(const char *cn, TERMTYPE * tp) 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; @@ -227,8 +242,8 @@ typelist(int eargc, char *eargv[], 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]); @@ -245,7 +260,9 @@ typelist(int eargc, char *eargv[], 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]; @@ -255,15 +272,15 @@ typelist(int eargc, char *eargv[], 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); }