Credited Christophe Boyaniqu for interactive patch to rm.
[oweals/busybox.git] / fbset.c
diff --git a/fbset.c b/fbset.c
index 845be8442fa3211c63496498250bd33acb099181..80711ec9f3f0cc3bae0283072b627ff14487ff45 100644 (file)
--- a/fbset.c
+++ b/fbset.c
  *     Geert Uytterhoeven (Geert.Uytterhoeven@cs.kuleuven.ac.be)
  */
 
-#include "busybox.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <errno.h>
 #include <ctype.h>
+#include <string.h>
 #include <sys/ioctl.h>
+#include "busybox.h"
 
 #define DEFAULTFBDEV  "/dev/fb0"
 #define DEFAULTFBMODE "/etc/fb.modes"
@@ -131,7 +132,7 @@ struct fb_var_screeninfo {
 };
 
 
-struct cmdoptions_t {
+static struct cmdoptions_t {
        char *name;
        unsigned char param_count;
        unsigned char code;
@@ -197,8 +198,7 @@ static int readmode(struct fb_var_screeninfo *base, const char *fn,
        char buf[256];
        char *p = buf;
 
-       if ((f = fopen(fn, "r")) == NULL)
-               perror_msg_and_die("readmode(fopen)");
+       f = xfopen(fn, "r");
        while (!feof(f)) {
                fgets(buf, sizeof(buf), f);
                if ((p = strstr(buf, "mode ")) || (p = strstr(buf, "mode\t"))) {
@@ -283,7 +283,7 @@ static int readmode(struct fb_var_screeninfo *base, const char *fn,
                }
        }
 #else
-       error_msg( "mode reading not compiled in\n");
+       error_msg( "mode reading not compiled in");
 #endif
        return 0;
 }
@@ -333,26 +333,6 @@ static void showmode(struct fb_var_screeninfo *v)
        printf("endmode\n\n");
 }
 
-static void fbset_usage(void)
-{
-#ifndef BB_FEATURE_TRIVIAL_HELP
-       int i;
-#endif
-
-#ifndef STANDALONE
-       fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
-                       BB_VER, BB_BT);
-#endif
-       fprintf(stderr, "Usage: fbset [options] [mode]\n");
-#ifndef BB_FEATURE_TRIVIAL_HELP
-       fprintf(stderr, "\nShows and modifies frame buffer device settings\n\n");
-       fprintf(stderr, "The following options are recognized:\n");
-       for (i = 0; g_cmdoptions[i].name; i++)
-               fprintf(stderr, "\t%s\n", g_cmdoptions[i].name);
-#endif
-       exit(-1);
-}
-
 #ifdef STANDALONE
 int main(int argc, char **argv)
 #else
@@ -374,10 +354,10 @@ extern int fbset_main(int argc, char **argv)
                for (i = 0; g_cmdoptions[i].name; i++) {
                        if (!strcmp(thisarg, g_cmdoptions[i].name)) {
                                if (argc - 1 < g_cmdoptions[i].param_count)
-                                       fbset_usage();
+                                       show_usage();
                                switch (g_cmdoptions[i].code) {
                                case CMD_HELP:
-                                       fbset_usage();
+                                       show_usage();
                                case CMD_FB:
                                        fbdev = argv[1];
                                        break;
@@ -422,7 +402,7 @@ extern int fbset_main(int argc, char **argv)
                                mode = *argv;
                                g_options |= OPT_READMODE;
                        } else {
-                               fbset_usage();
+                               show_usage();
                        }
                }
        }
@@ -433,7 +413,7 @@ extern int fbset_main(int argc, char **argv)
                perror_msg_and_die("fbset(ioctl)");
        if (g_options & OPT_READMODE) {
                if (!readmode(&var, modefile, mode)) {
-                       error_msg("Unknown video mode `%s'\n", mode);
+                       error_msg("Unknown video mode `%s'", mode);
                        return EXIT_FAILURE;
                }
        }