aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--miscutils/fbsplash.c61
1 files changed, 24 insertions, 37 deletions
diff --git a/miscutils/fbsplash.c b/miscutils/fbsplash.c
index a40c585a0..2fc3fae13 100644
--- a/miscutils/fbsplash.c
+++ b/miscutils/fbsplash.c
@@ -97,7 +97,7 @@ static void fb_open(const char *strfb_device)
97 * Draw hollow rectangle on framebuffer 97 * Draw hollow rectangle on framebuffer
98 * \param nx1pos,ny1pos upper left position 98 * \param nx1pos,ny1pos upper left position
99 * \param nx2pos,ny2pos down right position 99 * \param nx2pos,ny2pos down right position
100 * \param nred24,ngreen24,nblue24 rgb color 100 * \param nred,ngreen,nblue rgb color
101 */ 101 */
102static void fb_drawrectangle(int nx1pos, int ny1pos, int nx2pos, int ny2pos, 102static void fb_drawrectangle(int nx1pos, int ny1pos, int nx2pos, int ny2pos,
103 unsigned char nred, unsigned char ngreen, unsigned char nblue) 103 unsigned char nred, unsigned char ngreen, unsigned char nblue)
@@ -135,7 +135,7 @@ static void fb_drawrectangle(int nx1pos, int ny1pos, int nx2pos, int ny2pos,
135 * Draw filled rectangle on framebuffer 135 * Draw filled rectangle on framebuffer
136 * \param nx1pos,ny1pos upper left position 136 * \param nx1pos,ny1pos upper left position
137 * \param nx2pos,ny2pos down right position 137 * \param nx2pos,ny2pos down right position
138 * \param nred24,ngreen24,nblue24 rgb color 138 * \param nred,ngreen,nblue rgb color
139 */ 139 */
140static void fb_drawfullrectangle(int nx1pos, int ny1pos, int nx2pos, int ny2pos, 140static void fb_drawfullrectangle(int nx1pos, int ny1pos, int nx2pos, int ny2pos,
141 unsigned char nred, unsigned char ngreen, unsigned char nblue) 141 unsigned char nred, unsigned char ngreen, unsigned char nblue)
@@ -165,11 +165,12 @@ static void fb_drawfullrectangle(int nx1pos, int ny1pos, int nx2pos, int ny2pos,
165 165
166/** 166/**
167 * Draw a progress bar on framebuffer 167 * Draw a progress bar on framebuffer
168 * \param nPercent percentage of loading 168 * \param percent percentage of loading
169 */ 169 */
170static void fb_drawprogressbar(unsigned nPercent) 170static void fb_drawprogressbar(unsigned percent)
171{ 171{
172 int i, left_x, top_y, width, height; 172 int i, left_x, top_y, width, height;
173
173 // outer box 174 // outer box
174 left_x = G.nbar_posx; 175 left_x = G.nbar_posx;
175 top_y = G.nbar_posy; 176 top_y = G.nbar_posy;
@@ -195,9 +196,9 @@ static void fb_drawprogressbar(unsigned nPercent)
195 left_x + width, top_y + height, 196 left_x + width, top_y + height,
196 G.nbar_colr, G.nbar_colg, G.nbar_colb); 197 G.nbar_colr, G.nbar_colg, G.nbar_colb);
197 198
198 if (nPercent > 0) { 199 if (percent > 0) {
199 // actual progress bar 200 // actual progress bar
200 width = width*nPercent/100; 201 width = width * percent / 100;
201 i = height; 202 i = height;
202 if (height == 0) 203 if (height == 0)
203 height++; // divide by 0 is bad 204 height++; // divide by 0 is bad
@@ -294,9 +295,9 @@ static void init(const char *ini_filename)
294 FILE *inifile; 295 FILE *inifile;
295 char *buf; 296 char *buf;
296 297
297 inifile = xfopen(ini_filename, "r"); 298 inifile = xfopen_stdin(ini_filename);
298 299
299 while ((buf = xmalloc_getline(inifile)) != NULL) { 300 while ((buf = xmalloc_fgetline(inifile)) != NULL) {
300 char *value_str; 301 char *value_str;
301 int val; 302 int val;
302 303
@@ -360,10 +361,8 @@ static void init(const char *ini_filename)
360int fbsplash_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 361int fbsplash_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
361int fbsplash_main(int argc ATTRIBUTE_UNUSED, char **argv) 362int fbsplash_main(int argc ATTRIBUTE_UNUSED, char **argv)
362{ 363{
363 char num_buf[16];
364 const char *fb_device, *ini_filename, *fifo_filename; 364 const char *fb_device, *ini_filename, *fifo_filename;
365 int fd = fd; // for compiler 365 FILE *fp = fp; // for compiler
366 int len, num;
367 bool bCursorOff; 366 bool bCursorOff;
368 367
369 INIT_G(); 368 INIT_G();
@@ -383,13 +382,8 @@ int fbsplash_main(int argc ATTRIBUTE_UNUSED, char **argv)
383 if (!G.image_filename) 382 if (!G.image_filename)
384 bb_show_usage(); 383 bb_show_usage();
385 384
386 if (fifo_filename) { 385 if (fifo_filename)
387 fd = STDIN_FILENO; 386 fp = xfopen_stdin(fifo_filename);
388 if (NOT_LONE_DASH(fifo_filename)) {
389 // open command fifo/pipe
390 fd = xopen(fifo_filename, O_RDONLY | O_NOCTTY);
391 }
392 }
393 387
394 fb_open(fb_device); 388 fb_open(fb_device);
395 389
@@ -401,44 +395,37 @@ int fbsplash_main(int argc ATTRIBUTE_UNUSED, char **argv)
401 fb_drawimage(); 395 fb_drawimage();
402 396
403 if (fifo_filename) { 397 if (fifo_filename) {
404 num = 0; 398 unsigned num;
405 goto draw_bar; 399 char *num_buf;
406 400
407 while (1) { 401 fb_drawprogressbar(0);
408 // block on read, waiting for some input 402 // Block on read, waiting for some input.
409 len = safe_read(fd, num_buf, sizeof(num_buf) - 1); 403 // Use of <stdio.h> style I/O allows to correctly
410 if (len <= 0) // EOF/error 404 // handle a case when we have many buffered lines
411 break; 405 // already in the pipe.
412 num_buf[len] = '\0'; 406 while ((num_buf = xmalloc_fgetline(fp)) != NULL) {
413 // parse command
414 if (strncmp(num_buf, "exit", 4) == 0) { 407 if (strncmp(num_buf, "exit", 4) == 0) {
415 DEBUG_MESSAGE("exit"); 408 DEBUG_MESSAGE("exit");
416 break; 409 break;
417 } 410 }
418 num = atoi(num_buf); 411 num = atoi(num_buf);
419 if (isdigit(num_buf[0]) && (num >= 0) && (num <= 100)) { 412 if (isdigit(num_buf[0]) && (num <= 100)) {
420#if DEBUG 413#if DEBUG
421 char strVal[10]; 414 char strVal[10];
422 sprintf(strVal, "%d", num); 415 sprintf(strVal, "%d", num);
423 DEBUG_MESSAGE(strVal); 416 DEBUG_MESSAGE(strVal);
424#endif 417#endif
425 draw_bar:
426 fb_drawprogressbar(num); 418 fb_drawprogressbar(num);
427 } 419 }
420 free(num_buf);
428 } 421 }
429 if (bCursorOff) { 422 if (bCursorOff) {
430 // restore cursor 423 // restore cursor
431 full_write(STDOUT_FILENO, "\x1b" "[?25h", 6); 424 full_write(STDOUT_FILENO, "\x1b" "[?25h", 6);
432 } 425 }
433 if (ENABLE_FEATURE_CLEAN_UP) 426 if (ENABLE_FEATURE_CLEAN_UP)
434 close(fd); 427 fclose(fp);
435 } 428 }
436 429
437#if DEBUG
438 if (ENABLE_FEATURE_CLEAN_UP)
439 if (G.bdebug_messages)
440 fclose(G.logfile_fd);
441#endif
442
443 return EXIT_SUCCESS; 430 return EXIT_SUCCESS;
444} 431}