diff options
-rw-r--r-- | src/flexdef.h | 2 | ||||
-rw-r--r-- | src/main.c | 2 | ||||
-rw-r--r-- | src/scanopt.c | 11 |
3 files changed, 3 insertions, 12 deletions
diff --git a/src/flexdef.h b/src/flexdef.h index 3bbaea1..c111c51 100644 --- a/src/flexdef.h +++ b/src/flexdef.h @@ -44,8 +44,8 @@ #include <stdarg.h> #include <setjmp.h> #include <ctype.h> -#include <libgen.h> /* for XPG version of basename(3) */ #include <string.h> +#define BASENAME(p) strrchr(p, '/') ? strrchr(p, '/') + 1 : strrchr(p, '\\') ? strrchr(p, '\\') + 1 : p #include <math.h> #ifdef HAVE_ASSERT_H @@ -996,7 +996,7 @@ void flexinit (int argc, char **argv) flex_init_regex(); /* Enable C++ if program name ends with '+'. */ - program_name = basename (argv[0]); + program_name = BASENAME(argv[0]); if (program_name != NULL && program_name[strlen (program_name) - 1] == '+') diff --git a/src/scanopt.c b/src/scanopt.c index a475b6f..3162e9f 100644 --- a/src/scanopt.c +++ b/src/scanopt.c @@ -247,16 +247,7 @@ int scanopt_usage (scanopt_t *scanner, FILE *fp, const char *usage) fprintf (fp, "%s\n", usage); } else { - /* Find the basename of argv[0] */ - const char *p; - - p = s->argv[0] + strlen (s->argv[0]); - while (p != s->argv[0] && *p != '/') - --p; - if (*p == '/') - p++; - - fprintf (fp, _("Usage: %s [OPTIONS]...\n"), p); + fprintf (fp, _("Usage: %s [OPTIONS]...\n"), BASENAME(s->argv[0]) ); } fprintf (fp, "\n"); |