]> granicus.if.org Git - flex/commitdiff
scanner: #define BASENAME, remove #include libgen.h
authorJannick <thirdedition@gmx.net>
Mon, 17 Jul 2017 22:47:27 +0000 (00:47 +0200)
committerWill Estes <westes575@gmail.com>
Tue, 18 Jul 2017 01:12:44 +0000 (21:12 -0400)
src/flexdef.h
src/main.c
src/scanopt.c

index 3bbaea1b04aa3c1f5e3e40903c364aabca9efeb3..c111c516819b9c98223f3d34e39d56535531c0f0 100644 (file)
@@ -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
index 1f12cba990ae0bab874ebe3471cf502e67cfcfca..e3ca4407d15f033e37a0ea6d6caece7e5c563683 100644 (file)
@@ -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] == '+')
index a475b6f6e89a429299e7875fa0702963803cf790..3162e9fd62d0f72e0396e666211259dfe6bcad42 100644 (file)
@@ -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");