summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2016-07-04 20:04:38 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2016-07-04 21:30:34 +0900
commit49f19a1cb207e148a5d4057f848fbd58edcbccd9 (patch)
tree38ac5c0282f85178edad5999652b707d4e771354
parent8b5d5a5a8d45ff25d1ac7a11e02d2a51f77440a5 (diff)
eina btlog - add -n option to not use color escapes
-rw-r--r--src/bin/eina/eina_btlog.c43
1 files changed, 36 insertions, 7 deletions
diff --git a/src/bin/eina/eina_btlog.c b/src/bin/eina/eina_btlog.c
index 2d05151b35..2513d5c416 100644
--- a/src/bin/eina/eina_btlog.c
+++ b/src/bin/eina/eina_btlog.c
@@ -69,6 +69,7 @@ struct _Translation_Desc
69}; 69};
70 70
71static Translate_Func _translate = NULL; 71static Translate_Func _translate = NULL;
72static Eina_Bool color = EINA_TRUE;
72 73
73static void 74static void
74path_split(const char *path, char **dir, char **file) 75path_split(const char *path, char **dir, char **file)
@@ -290,7 +291,7 @@ _translation_function_detect(const Translation_Desc *desc)
290} 291}
291 292
292int 293int
293main(void) 294main(int argc, char **argv)
294{ 295{
295 Eina_List *btl = NULL, *l; 296 Eina_List *btl = NULL, *l;
296 char buf[4096]; 297 char buf[4096];
@@ -319,6 +320,18 @@ main(void)
319 320
320 eina_init(); 321 eina_init();
321 322
323 for (i = 1; i < argc; i++)
324 {
325 if (!strcmp(argv[i], "-h"))
326 {
327 printf("Usage: eina_btlog [-n]\n"
328 " -n Do not use color escape codes\n");
329 eina_shutdown();
330 return 0;
331 }
332 else if (!strcmp(argv[i], "-n")) color = EINA_FALSE;
333 }
334
322 if (!_translation_function_detect(desc)) 335 if (!_translation_function_detect(desc))
323 { 336 {
324 EINA_LOG_CRIT("Fail to determine a program to translate backtrace " 337 EINA_LOG_CRIT("Fail to determine a program to translate backtrace "
@@ -353,15 +366,23 @@ main(void)
353 { 366 {
354 len = strlen(bt->bin_dir); 367 len = strlen(bt->bin_dir);
355 for (i = 0; i < (cols[0] - len); i++) printf(" "); 368 for (i = 0; i < (cols[0] - len); i++) printf(" ");
356 printf("\033[34m%s\033[01m\033[36m/\033[37m%s\033[0m", 369 if (color)
357 bt->bin_dir, bt->bin_name); 370 printf("\033[34m%s\033[01m\033[36m/\033[37m%s\033[0m",
371 bt->bin_dir, bt->bin_name);
372 else
373 printf("%s/%s",
374 bt->bin_dir, bt->bin_name);
358 len = strlen(bt->bin_name); 375 len = strlen(bt->bin_name);
359 for (i = 0; i < (cols[1] - len); i++) printf(" "); 376 for (i = 0; i < (cols[1] - len); i++) printf(" ");
360 printf(" | "); 377 printf(" | ");
361 len = strlen(bt->file_dir); 378 len = strlen(bt->file_dir);
362 for (i = 0; i < (cols[2] - len); i++) printf(" "); 379 for (i = 0; i < (cols[2] - len); i++) printf(" ");
363 printf("\033[34m%s\033[01m\033[36m/\033[37m%s\033[0m", 380 if (color)
364 bt->file_dir, bt->file_name); 381 printf("\033[34m%s\033[01m\033[36m/\033[37m%s\033[0m",
382 bt->file_dir, bt->file_name);
383 else
384 printf("%s/%s",
385 bt->file_dir, bt->file_name);
365 len = strlen(bt->file_name); 386 len = strlen(bt->file_name);
366 for (i = 0; i < (cols[3] - len); i++) printf(" "); 387 for (i = 0; i < (cols[3] - len); i++) printf(" ");
367 388
@@ -369,8 +390,16 @@ main(void)
369 snprintf(buf, sizeof(buf), "%i", bt->line); 390 snprintf(buf, sizeof(buf), "%i", bt->line);
370 len = strlen(buf); 391 len = strlen(buf);
371 for (i = 0; i < (cols[4] - len); i++) printf(" "); 392 for (i = 0; i < (cols[4] - len); i++) printf(" ");
372 printf("\033[01m\033[33m%s\033[0m @ \033[32m%s\033[36m()", buf, bt->func_name); 393 if (color)
373 printf("\033[0m\n"); 394 {
395 printf("\033[01m\033[33m%s\033[0m @ \033[32m%s\033[36m()", buf, bt->func_name);
396 printf("\033[0m\n");
397 }
398 else
399 {
400 printf("%s @ %s()", buf, bt->func_name);
401 printf("\n");
402 }
374 } 403 }
375 return 0; 404 return 0;
376} 405}