diff options
Diffstat (limited to 'miscutils')
-rw-r--r-- | miscutils/beep.c | 4 | ||||
-rw-r--r-- | miscutils/fbsplash.c | 74 | ||||
-rw-r--r-- | miscutils/microcom.c | 4 |
3 files changed, 40 insertions, 42 deletions
diff --git a/miscutils/beep.c b/miscutils/beep.c index c17cbfdad..b0ee7ea25 100644 --- a/miscutils/beep.c +++ b/miscutils/beep.c | |||
@@ -79,11 +79,11 @@ int beep_main(int argc, char **argv) | |||
79 | } | 79 | } |
80 | while (rep) { | 80 | while (rep) { |
81 | //bb_info_msg("rep[%d] freq=%d, length=%d, delay=%d", rep, freq, length, delay); | 81 | //bb_info_msg("rep[%d] freq=%d, length=%d, delay=%d", rep, freq, length, delay); |
82 | xioctl(speaker, KIOCSOUND, (void*)(long)tickrate_div_freq); | 82 | xioctl(speaker, KIOCSOUND, (void*)(uintptr_t)tickrate_div_freq); |
83 | usleep(1000 * length); | 83 | usleep(1000 * length); |
84 | ioctl(speaker, KIOCSOUND, (void*)0); | 84 | ioctl(speaker, KIOCSOUND, (void*)0); |
85 | if (--rep) | 85 | if (--rep) |
86 | usleep(delay); | 86 | usleep(1000 * delay); |
87 | } | 87 | } |
88 | } | 88 | } |
89 | 89 | ||
diff --git a/miscutils/fbsplash.c b/miscutils/fbsplash.c index 4560bb2e9..5974006bb 100644 --- a/miscutils/fbsplash.c +++ b/miscutils/fbsplash.c | |||
@@ -84,7 +84,7 @@ static void fb_open(const char *strfb_device) | |||
84 | // map the device in memory | 84 | // map the device in memory |
85 | G.addr = mmap(NULL, | 85 | G.addr = mmap(NULL, |
86 | G.scr_var.xres * G.scr_var.yres | 86 | G.scr_var.xres * G.scr_var.yres |
87 | * BYTES_PER_PIXEL /*(G.scr_var.bits_per_pixel / 8)*/ , | 87 | * BYTES_PER_PIXEL /*(G.scr_var.bits_per_pixel / 8)*/, |
88 | PROT_WRITE, MAP_SHARED, fbfd, 0); | 88 | PROT_WRITE, MAP_SHARED, fbfd, 0); |
89 | if (G.addr == MAP_FAILED) | 89 | if (G.addr == MAP_FAILED) |
90 | bb_perror_msg_and_die("mmap"); | 90 | bb_perror_msg_and_die("mmap"); |
@@ -121,7 +121,7 @@ static void fb_drawrectangle(void) | |||
121 | // vertical lines | 121 | // vertical lines |
122 | ptr1 = (DATA*)(G.addr + (G.nbar_posy * G.scr_var.xres + G.nbar_posx) * BYTES_PER_PIXEL); | 122 | ptr1 = (DATA*)(G.addr + (G.nbar_posy * G.scr_var.xres + G.nbar_posx) * BYTES_PER_PIXEL); |
123 | ptr2 = (DATA*)(G.addr + (G.nbar_posy * G.scr_var.xres + G.nbar_posx + G.nbar_width - 1) * BYTES_PER_PIXEL); | 123 | ptr2 = (DATA*)(G.addr + (G.nbar_posy * G.scr_var.xres + G.nbar_posx + G.nbar_width - 1) * BYTES_PER_PIXEL); |
124 | cnt = G.nbar_height - 1 /* HUH?! G.nbar_posy + G.nbar_height - 1 - G.nbar_posy*/; | 124 | cnt = G.nbar_height - 1; |
125 | do { | 125 | do { |
126 | *ptr1 = thispix; ptr1 += G.scr_var.xres; | 126 | *ptr1 = thispix; ptr1 += G.scr_var.xres; |
127 | *ptr2 = thispix; ptr2 += G.scr_var.xres; | 127 | *ptr2 = thispix; ptr2 += G.scr_var.xres; |
@@ -216,70 +216,69 @@ static void fb_drawprogressbar(unsigned percent) | |||
216 | */ | 216 | */ |
217 | static void fb_drawimage(void) | 217 | static void fb_drawimage(void) |
218 | { | 218 | { |
219 | char *head, *ptr; | ||
220 | FILE *theme_file; | 219 | FILE *theme_file; |
220 | char *read_ptr; | ||
221 | unsigned char *pixline; | 221 | unsigned char *pixline; |
222 | unsigned i, j, width, height, line_size; | 222 | unsigned i, j, width, height, line_size; |
223 | 223 | ||
224 | if (LONE_DASH(G.image_filename)) | 224 | if (LONE_DASH(G.image_filename)) { |
225 | theme_file = stdin; | 225 | theme_file = stdin; |
226 | else { | 226 | } else { |
227 | int fd = open_zipped(G.image_filename); | 227 | int fd = open_zipped(G.image_filename); |
228 | if (fd < 0) | 228 | if (fd < 0) |
229 | bb_simple_perror_msg_and_die(G.image_filename); | 229 | bb_simple_perror_msg_and_die(G.image_filename); |
230 | theme_file = xfdopen_for_read(fd); | 230 | theme_file = xfdopen_for_read(fd); |
231 | } | 231 | } |
232 | head = xmalloc(256); | ||
233 | 232 | ||
234 | /* parse ppm header | 233 | /* Parse ppm header: |
235 | * - A ppm image’s magic number is the two characters "P6". | 234 | * - Magic: two characters "P6". |
236 | * - Whitespace (blanks, TABs, CRs, LFs). | 235 | * - Whitespace (blanks, TABs, CRs, LFs). |
237 | * - A width, formatted as ASCII characters in decimal. | 236 | * - A width, formatted as ASCII characters in decimal. |
238 | * - Whitespace. | 237 | * - Whitespace. |
239 | * - A height, again in ASCII decimal. | 238 | * - A height, ASCII decimal. |
240 | * - Whitespace. | 239 | * - Whitespace. |
241 | * - The maximum color value (Maxval), again in ASCII decimal. Must be | 240 | * - The maximum color value, ASCII decimal, in 0..65535 |
242 | * less than 65536. | ||
243 | * - Newline or other single whitespace character. | 241 | * - Newline or other single whitespace character. |
242 | * (we support newline only) | ||
244 | * - A raster of Width * Height pixels in triplets of rgb | 243 | * - A raster of Width * Height pixels in triplets of rgb |
245 | * in pure binary by 1 (or not implemented 2) bytes. | 244 | * in pure binary by 1 or 2 bytes. (we support only 1 byte) |
246 | */ | 245 | */ |
246 | #define concat_buf bb_common_bufsiz1 | ||
247 | read_ptr = concat_buf; | ||
247 | while (1) { | 248 | while (1) { |
248 | if (fgets(head, 256, theme_file) == NULL | 249 | int w, h, max_color_val; |
249 | /* do not overrun the buffer */ | 250 | int rem = concat_buf + sizeof(concat_buf) - read_ptr; |
250 | || strlen(bb_common_bufsiz1) >= sizeof(bb_common_bufsiz1) - 256) | 251 | if (rem < 2 |
252 | || fgets(read_ptr, rem, theme_file) == NULL | ||
253 | ) { | ||
251 | bb_error_msg_and_die("bad PPM file '%s'", G.image_filename); | 254 | bb_error_msg_and_die("bad PPM file '%s'", G.image_filename); |
252 | 255 | } | |
253 | ptr = memchr(skip_whitespace(head), '#', 256); | 256 | read_ptr = strchrnul(read_ptr, '#'); |
254 | if (ptr != NULL) | 257 | *read_ptr = '\0'; /* ignore #comments */ |
255 | *ptr = 0; /* ignore comments */ | 258 | if (sscanf(concat_buf, "P6 %u %u %u", &w, &h, &max_color_val) == 3 |
256 | strcat(bb_common_bufsiz1, head); | 259 | && max_color_val <= 255 |
257 | // width, height, max_color_val | 260 | ) { |
258 | if (sscanf(bb_common_bufsiz1, "P6 %u %u %u", &width, &height, &i) == 3 | 261 | width = w; /* w is on stack, width may be in register */ |
259 | && i <= 255) | 262 | height = h; |
260 | break; | 263 | break; |
261 | /* If we do not find a signature throughout the whole file then | 264 | } |
262 | we will diagnose this via EOF on read in the head of the loop. */ | ||
263 | } | 265 | } |
264 | 266 | ||
265 | if (ENABLE_FEATURE_CLEAN_UP) | ||
266 | free(head); | ||
267 | if (width != G.scr_var.xres || height != G.scr_var.yres) | ||
268 | bb_error_msg_and_die("PPM %dx%d does not match screen %dx%d", | ||
269 | width, height, G.scr_var.xres, G.scr_var.yres); | ||
270 | line_size = width*3; | 267 | line_size = width*3; |
268 | pixline = xmalloc(line_size); | ||
269 | |||
271 | if (width > G.scr_var.xres) | 270 | if (width > G.scr_var.xres) |
272 | width = G.scr_var.xres; | 271 | width = G.scr_var.xres; |
273 | if (height > G.scr_var.yres) | 272 | if (height > G.scr_var.yres) |
274 | height = G.scr_var.yres; | 273 | height = G.scr_var.yres; |
275 | |||
276 | pixline = xmalloc(line_size); | ||
277 | for (j = 0; j < height; j++) { | 274 | for (j = 0; j < height; j++) { |
278 | unsigned char *pixel = pixline; | 275 | unsigned char *pixel; |
279 | DATA *src = (DATA *)(G.addr + j * G.scr_fix.line_length); | 276 | DATA *src; |
280 | 277 | ||
281 | if (fread(pixline, 1, line_size, theme_file) != line_size) | 278 | if (fread(pixline, 1, line_size, theme_file) != line_size) |
282 | bb_error_msg_and_die("bad PPM file '%s'", G.image_filename); | 279 | bb_error_msg_and_die("bad PPM file '%s'", G.image_filename); |
280 | pixel = pixline; | ||
281 | src = (DATA *)(G.addr + j * G.scr_fix.line_length); | ||
283 | for (i = 0; i < width; i++) { | 282 | for (i = 0; i < width; i++) { |
284 | unsigned thispix; | 283 | unsigned thispix; |
285 | thispix = (((unsigned)pixel[0] << 8) & 0xf800) | 284 | thispix = (((unsigned)pixel[0] << 8) & 0xf800) |
@@ -289,8 +288,7 @@ static void fb_drawimage(void) | |||
289 | pixel += 3; | 288 | pixel += 3; |
290 | } | 289 | } |
291 | } | 290 | } |
292 | if (ENABLE_FEATURE_CLEAN_UP) | 291 | free(pixline); |
293 | free(pixline); | ||
294 | fclose(theme_file); | 292 | fclose(theme_file); |
295 | } | 293 | } |
296 | 294 | ||
@@ -301,7 +299,7 @@ static void fb_drawimage(void) | |||
301 | */ | 299 | */ |
302 | static void init(const char *cfg_filename) | 300 | static void init(const char *cfg_filename) |
303 | { | 301 | { |
304 | static const char const param_names[] ALIGN1 = | 302 | static const char param_names[] ALIGN1 = |
305 | "BAR_WIDTH\0" "BAR_HEIGHT\0" | 303 | "BAR_WIDTH\0" "BAR_HEIGHT\0" |
306 | "BAR_LEFT\0" "BAR_TOP\0" | 304 | "BAR_LEFT\0" "BAR_TOP\0" |
307 | "BAR_R\0" "BAR_G\0" "BAR_B\0" | 305 | "BAR_R\0" "BAR_G\0" "BAR_B\0" |
@@ -312,7 +310,7 @@ static void init(const char *cfg_filename) | |||
312 | char *token[2]; | 310 | char *token[2]; |
313 | parser_t *parser = config_open2(cfg_filename, xfopen_stdin); | 311 | parser_t *parser = config_open2(cfg_filename, xfopen_stdin); |
314 | while (config_read(parser, token, 2, 2, "#=", | 312 | while (config_read(parser, token, 2, 2, "#=", |
315 | (PARSE_NORMAL | PARSE_MIN_DIE) & ~(PARSE_TRIM | PARSE_COLLAPSE))) { | 313 | (PARSE_NORMAL | PARSE_MIN_DIE) & ~(PARSE_TRIM | PARSE_COLLAPSE))) { |
316 | unsigned val = xatoi_u(token[1]); | 314 | unsigned val = xatoi_u(token[1]); |
317 | int i = index_in_strings(param_names, token[0]); | 315 | int i = index_in_strings(param_names, token[0]); |
318 | if (i < 0) | 316 | if (i < 0) |
diff --git a/miscutils/microcom.c b/miscutils/microcom.c index 9a7a41d53..0fb51d2e8 100644 --- a/miscutils/microcom.c +++ b/miscutils/microcom.c | |||
@@ -119,7 +119,7 @@ int microcom_main(int argc UNUSED_PARAM, char **argv) | |||
119 | nfd = 2; | 119 | nfd = 2; |
120 | // Not safe_poll: we want to exit on signal | 120 | // Not safe_poll: we want to exit on signal |
121 | while (!bb_got_signal && poll(pfd, nfd, timeout) > 0) { | 121 | while (!bb_got_signal && poll(pfd, nfd, timeout) > 0) { |
122 | if (nfd > 1 && (pfd[1].revents & POLLIN)) { | 122 | if (nfd > 1 && pfd[1].revents) { |
123 | char c; | 123 | char c; |
124 | // read from stdin -> write to device | 124 | // read from stdin -> write to device |
125 | if (safe_read(STDIN_FILENO, &c, 1) < 1) { | 125 | if (safe_read(STDIN_FILENO, &c, 1) < 1) { |
@@ -143,7 +143,7 @@ int microcom_main(int argc UNUSED_PARAM, char **argv) | |||
143 | safe_poll(pfd, 1, delay); | 143 | safe_poll(pfd, 1, delay); |
144 | skip_write: ; | 144 | skip_write: ; |
145 | } | 145 | } |
146 | if (pfd[0].revents & POLLIN) { | 146 | if (pfd[0].revents) { |
147 | #define iobuf bb_common_bufsiz1 | 147 | #define iobuf bb_common_bufsiz1 |
148 | ssize_t len; | 148 | ssize_t len; |
149 | // read from device -> write to stdout | 149 | // read from device -> write to stdout |