diff --git a/dice/src/dice.c b/dice/src/dice.c index 9a1994f..926733a 100644 --- a/dice/src/dice.c +++ b/dice/src/dice.c @@ -7,6 +7,8 @@ #include +static bool prefix = false; + static bool evaluate_expression(char const *s) { dice_expression_t e = dice_expression_new(); @@ -31,7 +33,11 @@ static bool evaluate_expression(char const *s) goto error; } - printf("%ld\n", result); + if (prefix) { + printf("%s: %ld\n", s, result); + } else { + printf("%ld\n", result); + } ret = true; @@ -43,9 +49,10 @@ error: int main(int ac, char **av) { - static char const *optstr = "e:"; + static char const *optstr = "e:p"; static struct option opts[] = { { "expression", required_argument, NULL, 'e' }, + { "prefix", no_argument, NULL, 'p' }, { NULL, 0, NULL, 0} }; @@ -64,6 +71,8 @@ int main(int ac, char **av) } } break; + case 'p': prefix = true; break; + default: { fprintf(stderr, "invalid option specified\n"); @@ -83,8 +92,8 @@ int main(int ac, char **av) for (i = optind; i < ac; i++) { fprintf(f, "%s", av[i]); - if (i < ac) { - fputc(' ', f); + if (i < ac-1) { + putc(' ', f); } }