some improvements on the dice command

This commit is contained in:
Florian Stinglmayr 2019-08-25 15:36:14 +02:00
parent 8c77114c01
commit 0f24c60a4e

View File

@ -7,6 +7,8 @@
#include <dice.h>
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;
}
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);
}
}