socsvn commit: r272113 - soc2014/seiya/bootsplash/sys/dev/fb

seiya at FreeBSD.org seiya at FreeBSD.org
Sat Aug 9 04:50:05 UTC 2014


Author: seiya
Date: Sat Aug  9 04:50:04 2014
New Revision: 272113
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272113

Log:
  use getenv_int() to simplify source code

Modified:
  soc2014/seiya/bootsplash/sys/dev/fb/bsplash.c

Modified: soc2014/seiya/bootsplash/sys/dev/fb/bsplash.c
==============================================================================
--- soc2014/seiya/bootsplash/sys/dev/fb/bsplash.c	Fri Aug  8 23:55:22 2014	(r272112)
+++ soc2014/seiya/bootsplash/sys/dev/fb/bsplash.c	Sat Aug  9 04:50:04 2014	(r272113)
@@ -87,16 +87,6 @@
 	/*
 	 *  get parameters from /boot/loader.conf
 	 */
-        // load "bsplash_background_y_origin"
-	if ((s = getenv("bsplash_background_y_origin")) == NULL) {
-		if (bootverbose)
-			printf("bsplash: cannot load \"bsplash_background_y_origin\"\n");
-		background_enabled = 0;
-	} else {
-		background_y_origin = strtol(s, NULL, 10);
-	}
-	freeenv(s);
-
         // load "bsplash_repeat_animation"
 	if ((s = getenv("bsplash_repeat_animation")) == NULL) {
 		if (bootverbose)
@@ -110,121 +100,44 @@
 	}
 	freeenv(s);
 
-        // load "bsplash_animation_y_origin"
-	if ((s = getenv("bsplash_animation_y_origin")) == NULL) {
-		if (bootverbose)
-			printf("bsplash: cannot load \"bsplash_animation_y_origin\"\n");
+	if (!getenv_int("bsplash_background_y_origin", &background_y_origin))
+		background_enabled = 0;
+	if (!getenv_int("bsplash_animation_y_origin", &animation_y_origin))
 		animation_enabled = 0;
-	} else {
-		animation_y_origin = strtol(s, NULL, 10);
-	}
-	freeenv(s);
-
-        // load "bsplash_animation_y"
-	if ((s = getenv("bsplash_animation_y")) == NULL) {
-		if (bootverbose)
-			printf("bsplash: cannot load \"bsplash_animation_y\"\n");
+	if (!getenv_int("bsplash_animation_x", &animation_x))
 		animation_enabled = 0;
-	} else {
-		animation_y = strtol(s, NULL, 10);
-	}
-	freeenv(s);
-
-        // load "bsplash_animation_x"
-	if ((s = getenv("bsplash_animation_x")) == NULL) {
-		if (bootverbose)
-			printf("bsplash: cannot load \"bsplash_animation_x\"\n");
+	if (!getenv_int("bsplash_animation_y", &animation_y))
 		animation_enabled = 0;
-	} else {
-		animation_x = strtol(s, NULL, 10);
-	}
-	freeenv(s);
-
-        // load "bsplash_animation_width"
-	if ((s = getenv("bsplash_animation_width")) == NULL) {
-		if (bootverbose)
-			printf("bsplash: cannot load \"bsplash_animation_width\"\n");
+	if (!getenv_int("bsplash_animation_width", &animation_width))
 		animation_enabled = 0;
-	} else {
-		animation_width = strtol(s, NULL, 10);
-	}
-	freeenv(s);
-
-        // load "bsplash_animation_height"
-	if ((s = getenv("bsplash_animation_height")) == NULL) {
-		if (bootverbose)
-			printf("bsplash: cannot load \"bsplash_animation_height\"\n");
+	if (!getenv_int("bsplash_animation_height", &animation_height))
 		animation_enabled = 0;
-	} else {
-		animation_height = strtol(s, NULL, 10);
-	}
-	freeenv(s);
-
-        // load "bsplash_progress_bar_y_origin"
-	if ((s = getenv("bsplash_progress_bar_y_origin")) == NULL) {
-		if (bootverbose)
-			printf("bsplash: cannot load \"bsplash_progress_bar_y_origin\"\n");
+	if (!getenv_int("bsplash_progress_bar_y_origin", &progress_bar_y_origin))
 		progress_bar_enabled = 0;
-	} else {
-		progress_bar_y_origin = strtol(s, NULL, 10);
-	}
-	freeenv(s);
-
-        // load "bsplash_progress_bar_y"
-	if ((s = getenv("bsplash_progress_bar_y")) == NULL) {
-		if (bootverbose)
-			printf("bsplash: cannot load \"bsplash_progress_bar_y\"\n");
+	if (!getenv_int("bsplash_progress_bar_x", &progress_bar_x))
 		progress_bar_enabled = 0;
-	} else {
-		progress_bar_y = strtol(s, NULL, 10);
-	}
-	freeenv(s);
-
-        // load "bsplash_progress_bar_x"
-	if ((s = getenv("bsplash_progress_bar_x")) == NULL) {
-		if (bootverbose)
-			printf("bsplash: cannot load \"bsplash_progress_bar_x\"\n");
+	if (!getenv_int("bsplash_progress_bar_y", &progress_bar_y))
 		progress_bar_enabled = 0;
-	} else {
-		progress_bar_x = strtol(s, NULL, 10);
-	}
-	freeenv(s);
-
-        // load "bsplash_progress_bar_height"
-	if ((s = getenv("bsplash_progress_bar_height")) == NULL) {
-		if (bootverbose)
-			printf("bsplash: cannot load \"bsplash_progress_bar_height\"\n");
+	if (!getenv_int("bsplash_progress_bar_width", &progress_bar_width))
 		progress_bar_enabled = 0;
-	} else {
-		progress_bar_height = strtol(s, NULL, 10);
-	}
-	freeenv(s);
-
-        // load "bsplash_progress_bar_width"
-	if ((s = getenv("bsplash_progress_bar_width")) == NULL) {
-		if (bootverbose)
-			printf("bsplash: cannot load \"bsplash_progress_bar_width\"\n");
+	if (!getenv_int("bsplash_progress_bar_height", &progress_bar_height))
 		progress_bar_enabled = 0;
-	} else {
-		progress_bar_width = strtol(s, NULL, 10);
-	}
-	freeenv(s);
 
 	/*
 	 *  for debugging
 	 */
 	if (bootverbose) {
-		printf("bsplash: background is %s, img_y=%d\n",
+		printf("bsplash: background is %s: img_y=%d\n",
 		    (background_enabled)? "enabled" : "disabled",
                     background_y_origin);
-		printf("bsplash: animation is %s (y,x)=(%d,%d), img_y=%d, height=%d, width=%d\n",
+		printf("bsplash: animation is %s: (y,x)=(%d,%d), img_y=%d, height=%d, width=%d\n",
 		    (animation_enabled)? "enabled" : "disabled",
 		    animation_y,
 		    animation_x,
 		    animation_y_origin,
 		    animation_height,
 		    animation_width);
-		printf("bsplash: progress bar is %s (y,x)=(%d,%d), img_y=%d, height=%d, width=%d\n",
+		printf("bsplash: progress bar is %s: (y,x)=(%d,%d), img_y=%d, height=%d, width=%d\n",
 		    (progress_bar_enabled)? "enabled" : "disabled",
 		    progress_bar_y,
 		    progress_bar_x,
@@ -354,18 +267,13 @@
 int
 bsplash_prompt_failure(const char *tag)
 {
-	char		env_name[64];
-	char		*s;
-	int		y_origin;
+	char	env[64];
+	int	y_origin;
 
-	snprintf(env_name, sizeof(env_name), "bsplash_%s_failure_y_origin", tag);
+	snprintf(env, sizeof(env), "bsplash_%s_failure_y_origin", tag);
 
-	if ((s = getenv((const char *) env_name)) == NULL) {
+	if (!getenv_int(env, &y_origin))
 		return 1;
-	} else {
-		y_origin = strtol(s, NULL, 10);
-	}
-	freeenv(s);
 
 	if (draw_bmp(&bmp_info, y_origin, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) != 0){
 		printf("bsplash: failed to draw BMP (tag: %s)\n", tag);


More information about the svn-soc-all mailing list