From af3ca562b93460476801d0f9c276240a13e300b4 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Wed, 18 Feb 2015 23:03:39 +0000 Subject: [PATCH] lolremez: fix wrong argument parsing and improve error messages. --- tools/lolremez/lolremez.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tools/lolremez/lolremez.cpp b/tools/lolremez/lolremez.cpp index 0df90e9b..de005f6e 100644 --- a/tools/lolremez/lolremez.cpp +++ b/tools/lolremez/lolremez.cpp @@ -24,8 +24,10 @@ using lol::real; using lol::String; -void FAIL() +void FAIL(char const *message) { + printf("Error: %s\n", message); + printf("\n"); printf("Usage:\n"); printf(" lolremez [-d degree] [-i xmin xmax] x-expression [x-error]\n"); printf("\n"); @@ -49,22 +51,21 @@ int main(int argc, char **argv) if (argv[i] == String("-d")) { if (i + 1 >= argc) - FAIL(); + FAIL("not enough arguments for -d"); degree = atoi(argv[++i]); } else if (argv[i] == String("-i")) { if (i + 2 >= argc) - FAIL(); + FAIL("not enough arguments for -i"); xmin = argv[++i]; xmax = argv[++i]; - i += 2; } else if (g) { - FAIL(); + FAIL("unknown argument"); } else if (f) { @@ -76,10 +77,11 @@ int main(int argc, char **argv) } } - if (!f || real(xmin) >= real(xmax)) - { - FAIL(); - } + if (!f) + FAIL("no function specified"); + + if (real(xmin) >= real(xmax)) + FAIL("invalid range"); remez_solver solver(degree, 20); solver.run(xmin, xmax, f, g);