Re-add stderr usage
This commit spiritually reverts 392e05d
.
With debug messages and interpreter state sent to stderr and the actual
output of the program sent to stdout, it is easier to read both
independently. For instance, one can redirect stdout or stderr to
another terminal window to keep an eye on both outputs independently:
bin/modal examples/hello.modal >/dev/pts/5
This commit is contained in:
parent
f5cd5d3fa3
commit
42ab70b09d
16
src/modal.c
16
src/modal.c
|
@ -147,7 +147,7 @@ apply_rule(Rule *r, char *s)
|
|||
while(*s == ' ') s++;
|
||||
if(*s == ')' && *(dst_ - 1) == ' ') dst_--;
|
||||
}
|
||||
if(!quiet && r) printf("%02d %s\n", r->id, src_), ++r->refs;
|
||||
if(!quiet && r) fprintf(stderr, "%02d %s\n", r->id, src_), ++r->refs;
|
||||
return write_tail(s);
|
||||
}
|
||||
|
||||
|
@ -198,7 +198,7 @@ rewrite(void)
|
|||
cap = walk(s), r = find_rule(s, cap);
|
||||
if(r != NULL){
|
||||
if(!quiet)
|
||||
printf(">< (%s) (%s)\n", r->a, r->b);
|
||||
fprintf(stderr, ">< (%s) (%s)\n", r->a, r->b);
|
||||
r->a = 0;
|
||||
}
|
||||
while(*cap == ' ') cap++;
|
||||
|
@ -210,7 +210,7 @@ rewrite(void)
|
|||
s = parse_frag(&r->b, parse_frag(&r->a, s + 2));
|
||||
if(*r->a){
|
||||
if(!quiet)
|
||||
printf("<> (%s) (%s)\n", r->a, r->b);
|
||||
fprintf(stderr, "<> (%s) (%s)\n", r->a, r->b);
|
||||
rules_++;
|
||||
}
|
||||
while(*s == ' ') s++;
|
||||
|
@ -268,14 +268,14 @@ main(int argc, char **argv)
|
|||
while(*(--w) <= ' ') *w = 0;
|
||||
fclose(f);
|
||||
if(pr != pl)
|
||||
return !printf("Modal program imbalanced.\n");
|
||||
return !fprintf(stderr, "Modal program imbalanced.\n");
|
||||
while(rewrite() && ++rw)
|
||||
if(!cycles--) return !printf("Modal rewrites exceeded.\n");
|
||||
if(!cycles--) return !fprintf(stderr, "Modal rewrites exceeded.\n");
|
||||
if(!quiet) {
|
||||
while(rules_-- > rules)
|
||||
if(!rules_->refs && rules_->a)
|
||||
printf("-- Unused rule: %d <> (%s) (%s)\n", rules_->refs, rules_->a, rules_->b);
|
||||
printf(".. %s\nCompleted in %d rewrites.\n", src_, rw);
|
||||
fprintf(stderr, "-- Unused rule: %d <> (%s) (%s)\n", rules_->refs, rules_->a, rules_->b);
|
||||
fprintf(stderr, ".. %s\nCompleted in %d rewrites.\n", src_, rw);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue