Permalink
Browse files

Adding list-style output to crange

On the odd chance you need to have a list of nodes instead of a cvs with
collapsed number ranges
  • Loading branch information...
1 parent 51fabd1 commit 5faa9b32301903e364d6a880b861fcdb7c4fdac2 @grierj grierj committed Jan 3, 2013
Showing with 31 additions and 2 deletions.
  1. +31 −2 libcrange/source/src/main.c
View
33 libcrange/source/src/main.c
@@ -12,13 +12,42 @@ int main(int argc, char const* const* argv)
{
apr_pool_t* pool;
struct range_request* rr;
+ const char **nodes;
+ int expand_flag = 0;
+ int c;
apr_app_initialize(&argc, &argv, NULL);
atexit(apr_terminate);
apr_pool_create(&pool, NULL);
- rr = range_expand(NULL, pool, argv[1]);
- printf("%s\n", range_request_compressed(rr));
+ while ((c = getopt (argc, argv, "e")) != -1) {
+ switch (c)
+ {
+ case 'e':
+ expand_flag = 1;
+ break;
+ case '?':
+ fprintf (stderr, "Usage: crange [-e] <range>\n\n");
+ return 1;
+ default:
+ abort ();
+ }
+ }
+
+ if (argc > 3) {
+ fprintf (stderr, "Usage: crange [-e] <range>\n\n");
+ return 1;
+ }
+
+ rr = range_expand(NULL, pool, argv[argc-1]);
+ if (expand_flag == 1) {
+ nodes = range_request_nodes(rr);
+ while (*nodes) {
+ printf("%s\n", *nodes++);
+ }
+ } else {
+ printf("%s\n", range_request_compressed(rr));
+ }
if (range_request_has_warnings(rr))
printf("%s\n", range_request_warnings(rr));

0 comments on commit 5faa9b3

Please sign in to comment.