# HG changeset patch # User paulo@hit-nxdomain.opendns.com # Date 1273213290 25200 # Node ID 5ab8d6c1a37c677423a3d3ae1086155cc2309b3d # Parent 0b9cf47655fe843cde25ba5040e06f54f5cd8d36 add line coloring option diff -r 0b9cf47655fe -r 5ab8d6c1a37c rcg.c --- a/rcg.c Thu May 06 23:15:40 2010 -0700 +++ b/rcg.c Thu May 06 23:21:30 2010 -0700 @@ -16,6 +16,8 @@ const char *CLR_END = "m"; const char *CLR_CLEAR = "\x1B[0m"; +int colorLine = 0; + typedef enum _exit_code { EXIT_OK, EXIT_REALLOC_ERROR, @@ -48,13 +50,16 @@ { static struct option long_options[] = { + { "line", 0, 0, 'l' }, { 0, 0, 0, 0 }, }; int c; int l; - while ((c = getopt_long(argc, argv, "", long_options, &l)) >= 0) + while ((c = getopt_long(argc, argv, "l", long_options, &l)) >= 0) { + if (c == 'l') + colorLine = 1; } if (optind >= argc) @@ -107,8 +112,17 @@ if (!out) exit(realloc_error()); - so = rem[0].rm_so; - eo = rem[0].rm_eo; + if (colorLine) + { + so = 0; + eo = out_len - 1; + } + else + { + so = rem[0].rm_so; + eo = rem[0].rm_eo; + } + int match_len = eo - so; //fprintf(stderr, "%d %d \n", so, eo); //d// 20100327 PBA