Skip to contentSkip to conversation

fbset: send usage to stdout and fix its exit code

PATCH New Guillem Jover 1 participant 1 message Oct 9, 2006 Framebuffer layer

lore
Share & tools
lore
#0 lore raw

PATCH 3/7 fbset: send usage to stdout and fix its exit code

Hi,

This one makes Usage output to stdout instead of stderr, it also sends a proper exit code, depending if it has been called due to an error or the user asking for it via --help.

regards,
guillem

fbset.c renamed from fbset.c.orig +11 -8
Index: fbset.c
===================================================================
@@ -229,7 +229,7 @@ static void ModifyVideoMode(struct Video
 static void DisplayVModeInfo(struct VideoMode *vmode);
 static void DisplayFBInfo(struct fb_fix_screeninfo *fix);
 static int FillScanRates(struct VideoMode *vmode);
-static void Usage(void) __attribute__ ((noreturn));
+static void Usage(int status) __attribute__ ((noreturn));
 int main(int argc, char *argv[]);
 
 
@@ -829,10 +829,12 @@ static int FillScanRates(struct VideoMod
      *  Print the Usage Template and Exit
      */
 
-static void Usage(void)
+static void Usage(int status)
 {
     puts(VERSION);
-    Die("\nUsage: %s [options] [mode]\n\n"
+    printf(
+	"Usage: %s [options] [mode]\n"
+	"\n"
 	"Valid options:\n"
 	"  General options:\n"
 	"    -h, --help         : display this usage information\n"
@@ -887,6 +889,7 @@ static void Usage(void)
 	"    -step <value>      : step increment (in pixels or pixel lines)\n"
 	"                         (default is 8 horizontal, 2 vertical)\n",
 	ProgramName);
+	exit(status);
 }
 
 
@@ -910,7 +913,7 @@ int main(int argc, char *argv[])
     while (--argc > 0) {
 	argv++;
 	if (!strcmp(argv[0], "-h") || !strcmp(argv[0], "--help"))
-	    Usage();
+	    Usage(0);
 	else if (!strcmp(argv[0], "-v") || !strcmp(argv[0], "--verbose"))
 	    Opt_verbose = 1;
 	else if (!strcmp(argv[0], "-V") || !strcmp(argv[0], "--version"))
@@ -937,7 +940,7 @@ int main(int argc, char *argv[])
 		argc -= 5;
 		argv += 5;
 	    } else
-		Usage();
+		Usage(1);
 	} else if (!strcmp(argv[0], "-t") || !strcmp(argv[0], "--timings")) {
 	    if (argc > 7) {
 		Opt_pixclock = argv[1];
@@ -951,7 +954,7 @@ int main(int argc, char *argv[])
 		argc -= 7;
 		argv += 7;
 	    } else
-		Usage();
+		Usage(1);
 	} else if (!strcmp(argv[0], "-match")) {
 	    Opt_matchyres = argv[0];
 	    Opt_change = 1;
@@ -965,12 +968,12 @@ int main(int argc, char *argv[])
 		    Opt_change |= Options[i].change;
 		    argv++;
 		} else
-		    Usage();
+		    Usage(1);
 	    } else if (!Opt_modename) {
 		Opt_modename = argv[0];
 		Opt_change = 1;
 	    } else
-		Usage();
+		Usage(1);
 	}
     }
 

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

_______________________________________________
Linux-fbdev-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-fbdev-devel