summaryrefslogtreecommitdiffstats
path: root/src/sordi.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2015-10-03 15:28:32 +0000
committerDavid Robillard <d@drobilla.net>2015-10-03 15:28:32 +0000
commitc1f30328a51929139ab7810b88b3dee83615ceac (patch)
tree1de50b66ee901e586d4926b9795462caaaa3ca67 /src/sordi.c
parent8bbac48a4cfb64251d8a67e4c01088c9151520f5 (diff)
downloadsord-c1f30328a51929139ab7810b88b3dee83615ceac.tar.gz
sord-c1f30328a51929139ab7810b88b3dee83615ceac.tar.bz2
sord-c1f30328a51929139ab7810b88b3dee83615ceac.zip
Show sordi errors in standard format
git-svn-id: http://svn.drobilla.net/sord/trunk@333 3d64ff67-21c5-427c-a301-fe4f08042e5a
Diffstat (limited to 'src/sordi.c')
-rw-r--r--src/sordi.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/sordi.c b/src/sordi.c
index 257315a..31ad0d0 100644
--- a/src/sordi.c
+++ b/src/sordi.c
@@ -28,6 +28,9 @@
#include "sord/sord.h"
#include "sord_config.h"
+#define SORDI_ERROR(msg) fprintf(stderr, "sordi: " msg);
+#define SORDI_ERRORF(fmt, ...) fprintf(stderr, "sordi: " fmt, __VA_ARGS__);
+
typedef struct {
SerdWriter* writer;
SerdEnv* env;
@@ -51,6 +54,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, "Load and re-serialise RDF data.\n");
fprintf(os, "Use - for INPUT to read from standard input.\n\n");
@@ -70,7 +74,7 @@ set_syntax(SerdSyntax* syntax, const char* name)
} else if (!strcmp(name, "ntriples")) {
*syntax = SERD_NTRIPLES;
} else {
- fprintf(stderr, "Unknown input format `%s'\n", name);
+ SORDI_ERRORF("unknown syntax `%s'\n", name);
return false;
}
return true;
@@ -117,29 +121,29 @@ main(int argc, char** argv)
break;
} else if (argv[a][1] == 'i') {
if (++a == argc) {
- fprintf(stderr, "Missing value for -i\n");
- return 1;
+ SORDI_ERROR("option requires an argument -- 'i'\n\n");
+ return print_usage(argv[0], true);
}
if (!set_syntax(&input_syntax, argv[a])) {
- return 1;
+ return print_usage(argv[0], true);
}
} else if (argv[a][1] == 'o') {
if (++a == argc) {
- fprintf(stderr, "Missing value for -o\n");
- return 1;
+ SORDI_ERROR("option requires an argument -- 'o'\n\n");
+ return print_usage(argv[0], true);
}
if (!set_syntax(&output_syntax, argv[a])) {
- return 1;
+ return print_usage(argv[0], true);
}
} else {
- fprintf(stderr, "Unknown option `%s'\n", argv[a]);
+ SORDI_ERRORF("invalid option -- '%s'\n", argv[a] + 1);
return print_usage(argv[0], true);
}
}
if (a == argc) {
- fprintf(stderr, "Missing input\n");
- return 1;
+ SORDI_ERROR("missing input\n");
+ return print_usage(argv[0], true);
}
const uint8_t* input = (const uint8_t*)argv[a++];
@@ -165,8 +169,8 @@ main(int argc, char** argv)
free(in_path);
if (!base_uri_node.buf) {
- fprintf(stderr, "Missing base URI\n");
- return 1;
+ SORDI_ERROR("missing base URI\n");
+ return print_usage(argv[0], true);
}
SordWorld* world = sord_world_new();