Changeset 7416d46a for tools/repeat.c


Ignore:
Timestamp:
Jan 30, 2018, 3:54:32 PM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
633a642
Parents:
f792cb8 (diff), 42be3c3 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/repeat.c

    rf792cb8 r7416d46a  
    2626                if(print_iterations) {
    2727                        printf("\r%d / %d", i, repetitions);
     28                        fflush(stdout);
    2829                }
    2930                int retcode = run();
     
    4748        fprintf(out, "Repeat CMD N times\n\n");
    4849        fprintf(out, "\t-h,--help\tprint this usage message\n");
    49         fprintf(out, "\t-s\tstop on error\n");
    50         fprintf(out, "\t-i\toutput iterations instead of CMD stdout\n");
    51         fprintf(out, "\t-x\tprint CMD before running it\n");
     50        fprintf(out, "\t-s\t\tstop on error\n");
     51        fprintf(out, "\t-i\t\toutput iterations instead of CMD stdout\n");
     52        fprintf(out, "\t-x\t\tprint CMD before running it\n");
     53        fprintf(out, "\t-a FILE\t\tredirect output of command to append to FILE\n");
     54        fprintf(out, "\t-r FILE\t\tredirect output of command to FILE\n");
    5255        exit(code);
    5356}
     
    5558char ** cmd_to_run = NULL;
    5659bool print_cmd = false;
     60bool redirect = false;
     61bool redirect_append = false;
     62char * redirect_to = "/dev/null";
    5763pid_t child_pid = 0;
    5864
     
    7379
    7480        int c;
    75         while ( (c = getopt_long( argc, argv, "hsxi", long_opts, &long_index)) != -1 ) {
     81        while ( (c = getopt_long( argc, argv, "ahirsx", long_opts, &long_index)) != -1 ) {
    7682                switch ( c ) {
    7783                        case Help:
     
    8793                        case 'i':
    8894                                print_iterations = true;
     95                                break;
     96                        case 'a':
     97                                if(redirect) { fprintf(stderr, "Cannot have -a and -r\n"); error(); }
     98                                redirect_append = true;
     99                                redirect_to = argv[optind];
     100                                optind++;
     101                                break;
     102                        case 'r':
     103                                if(redirect_append) { fprintf(stderr, "Cannot have -a and -r\n"); error(); }
     104                                redirect = true;
     105                                redirect_to = argv[optind];
     106                                optind++;
    89107                                break;
    90108                        default:
     
    142160                        printf("\n");
    143161                }
    144                 if(print_iterations) {
     162                if(print_iterations || redirect || redirect_append) {
    145163                        __attribute__((unused)) FILE * ignore =
    146                                 freopen("/dev/null", "w", stdout);
     164                                freopen(redirect_to, redirect_append ? "a" : "w" , stdout);
    147165                }
    148166                execvp ( *cmd_to_run, cmd_to_run);
Note: See TracChangeset for help on using the changeset viewer.