Mercurial > hg > index.fcgi > rcg > rcg-1
changeset 8:5ab8d6c1a37c
add line coloring option
author | paulo@hit-nxdomain.opendns.com |
---|---|
date | Thu, 06 May 2010 23:21:30 -0700 |
parents | 0b9cf47655fe |
children | a367f80b847b |
files | rcg.c |
diffstat | 1 files changed, 17 insertions(+), 3 deletions(-) [+] |
line diff
1.1 --- a/rcg.c Thu May 06 23:15:40 2010 -0700 1.2 +++ b/rcg.c Thu May 06 23:21:30 2010 -0700 1.3 @@ -16,6 +16,8 @@ 1.4 const char *CLR_END = "m"; 1.5 const char *CLR_CLEAR = "\x1B[0m"; 1.6 1.7 +int colorLine = 0; 1.8 + 1.9 typedef enum _exit_code { 1.10 EXIT_OK, 1.11 EXIT_REALLOC_ERROR, 1.12 @@ -48,13 +50,16 @@ 1.13 { 1.14 static struct option long_options[] = 1.15 { 1.16 + { "line", 0, 0, 'l' }, 1.17 { 0, 0, 0, 0 }, 1.18 }; 1.19 1.20 int c; 1.21 int l; 1.22 - while ((c = getopt_long(argc, argv, "", long_options, &l)) >= 0) 1.23 + while ((c = getopt_long(argc, argv, "l", long_options, &l)) >= 0) 1.24 { 1.25 + if (c == 'l') 1.26 + colorLine = 1; 1.27 } 1.28 1.29 if (optind >= argc) 1.30 @@ -107,8 +112,17 @@ 1.31 if (!out) 1.32 exit(realloc_error()); 1.33 1.34 - so = rem[0].rm_so; 1.35 - eo = rem[0].rm_eo; 1.36 + if (colorLine) 1.37 + { 1.38 + so = 0; 1.39 + eo = out_len - 1; 1.40 + } 1.41 + else 1.42 + { 1.43 + so = rem[0].rm_so; 1.44 + eo = rem[0].rm_eo; 1.45 + } 1.46 + 1.47 int match_len = eo - so; 1.48 1.49 //fprintf(stderr, "%d %d \n", so, eo); //d// 20100327 PBA