aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2015-10-03 15:28:17 +0000
committerDavid Robillard <d@drobilla.net>2015-10-03 15:28:17 +0000
commit2e8a0c16c39083e4ee0328eab4fa87f5b9c94069 (patch)
tree024c08fa1f7dfd92be85eb63a3bf5073d30f956e
parentaec46529233290f8274d137b795b4924f1db131a (diff)
downloadserd-2e8a0c16c39083e4ee0328eab4fa87f5b9c94069.tar.gz
serd-2e8a0c16c39083e4ee0328eab4fa87f5b9c94069.tar.bz2
serd-2e8a0c16c39083e4ee0328eab4fa87f5b9c94069.zip
Show serdi errors in standard format
git-svn-id: http://svn.drobilla.net/serd/trunk@493 490d8e77-9747-427b-9fa3-0b8f29cee8a0
-rw-r--r--NEWS4
-rw-r--r--src/serdi.c34
2 files changed, 24 insertions, 14 deletions
diff --git a/NEWS b/NEWS
index 46dc90df..e44439f7 100644
--- a/NEWS
+++ b/NEWS
@@ -9,9 +9,11 @@ serd (0.21.1) unstable;
* Fix serializing fractional decimals that would round up
* Add support for Turtle named inline nodes extension
* Report errors for invalid IRI characters and missing terminators
+ * Show serdi errors in standard format
* Fix warnings when building with ISO C++ compilers
+ * Upgrade to waf 1.8.14
- -- David Robillard <d@drobilla.net> Fri, 04 Sep 2015 16:27:23 -0400
+ -- David Robillard <d@drobilla.net> Sat, 03 Oct 2015 11:28:07 -0400
serd (0.20.0) stable;
diff --git a/src/serdi.c b/src/serdi.c
index 7568378d..116d311e 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -21,6 +21,9 @@
#include <stdlib.h>
#include <string.h>
+#define SERDI_ERROR(msg) fprintf(stderr, "serdi: " msg);
+#define SERDI_ERRORF(fmt, ...) fprintf(stderr, "serdi: " fmt, __VA_ARGS__);
+
typedef struct {
SerdEnv* env;
SerdWriter* writer;
@@ -41,6 +44,7 @@ static int
print_usage(const char* name, bool error)
{
FILE* const os = error ? stderr : stdout;
+ fprintf(os, "%s", error ? "\n" : "");
fprintf(os, "Usage: %s [OPTION]... INPUT [BASE_URI]\n", name);
fprintf(os, "Read and write RDF syntax.\n");
fprintf(os, "Use - for INPUT to read from standard input.\n\n");
@@ -68,17 +72,17 @@ set_syntax(SerdSyntax* syntax, const char* name)
} else if (!strcmp(name, "ntriples")) {
*syntax = SERD_NTRIPLES;
} else {
- fprintf(stderr, "Unknown input format `%s'\n", name);
+ SERDI_ERRORF("unknown syntax `%s'\n", name);
return false;
}
return true;
}
static int
-bad_arg(const char* name, char opt)
+missing_arg(const char* name, char opt)
{
- fprintf(stderr, "%s: Bad or missing value for -%c\n", name, opt);
- return 1;
+ SERDI_ERRORF("option requires an argument -- '%c'\n", opt);
+ return print_usage(name, true);
}
static SerdStatus
@@ -133,36 +137,40 @@ main(int argc, char** argv)
++a;
break;
} else if (argv[a][1] == 'i') {
- if (++a == argc || !set_syntax(&input_syntax, argv[a])) {
- return bad_arg(argv[0], 'i');
+ if (++a == argc) {
+ return missing_arg(argv[0], 'i');
+ } else if (!set_syntax(&input_syntax, argv[a])) {
+ return print_usage(argv[0], true);
}
} else if (argv[a][1] == 'o') {
- if (++a == argc || !set_syntax(&output_syntax, argv[a])) {
- return bad_arg(argv[0], 'o');
+ if (++a == argc) {
+ return missing_arg(argv[0], 'o');
+ } else if (!set_syntax(&output_syntax, argv[a])) {
+ return print_usage(argv[0], true);
}
} else if (argv[a][1] == 'p') {
if (++a == argc) {
- return bad_arg(argv[0], 'p');
+ return missing_arg(argv[0], 'p');
}
add_prefix = (const uint8_t*)argv[a];
} else if (argv[a][1] == 'c') {
if (++a == argc) {
- return bad_arg(argv[0], 'c');
+ return missing_arg(argv[0], 'c');
}
chop_prefix = (const uint8_t*)argv[a];
} else if (argv[a][1] == 'r') {
if (++a == argc) {
- return bad_arg(argv[0], 'r');
+ return missing_arg(argv[0], 'r');
}
root_uri = (const uint8_t*)argv[a];
} else {
- fprintf(stderr, "%s: Unknown option `%s'\n", argv[0], argv[a]);
+ SERDI_ERRORF("invalid option -- '%s'\n", argv[a] + 1);
return print_usage(argv[0], true);
}
}
if (a == argc) {
- fprintf(stderr, "%s: Missing input\n", argv[0]);
+ SERDI_ERROR("missing input\n");
return 1;
}