From b06ab736333cbcf7fd411bd7c6badf3f12d75ac2 Mon Sep 17 00:00:00 2001 From: David Robillard <d@drobilla.net> Date: Tue, 25 Jan 2011 18:04:33 +0000 Subject: Add standard command line stuff (-h and -v). git-svn-id: http://svn.drobilla.net/serd/trunk@68 490d8e77-9747-427b-9fa3-0b8f29cee8a0 --- src/serdi.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/serdi.c b/src/serdi.c index 5ab5e440..fb104fbd 100644 --- a/src/serdi.c +++ b/src/serdi.c @@ -20,6 +20,7 @@ #include <string.h> #include "serd/serd.h" +#include "serd-config.h" // #define URI_DEBUG 1 @@ -177,12 +178,27 @@ event_end(void* handle, return serd_writer_end_anon(state->writer, node); } +int +print_version() +{ + printf("serdi " SERD_VERSION "\n"); + printf("Copyright (C) 2011 David Robillard <http://drobilla.net>.\n" + "\nLicense: GNU LGPL version 3 or later " + "<http://gnu.org/licenses/lgpl.html>.\n" + "This is free software; you are free to change and redistribute it." + "\nThere is NO WARRANTY, to the extent permitted by law.\n"); + return 0; +} + int print_usage(const char* name, bool error) { FILE* const os = error ? stderr : stdout; - fprintf(os, "Usage: %s INPUT [BASE_URI]\n", name); - fprintf(os, "Read and write RDF syntax.\n"); + fprintf(os, "Usage: %s [OPTION]... INPUT [BASE_URI]\n", name); + fprintf(os, "Read and write RDF syntax.\n\n"); + fprintf(os, " -h Display this help and exit\n"); + fprintf(os, " -o SYNTAX Output syntax (`turtle' or `ntriples')\n"); + fprintf(os, " -v Display version information and exit\n"); return error ? 1 : 0; } @@ -208,6 +224,10 @@ main(int argc, char** argv) if (argv[a][1] == '\0') { in_fd = stdin; break; + } else if (argv[a][1] == 'h') { + return print_usage(argv[0], false); + } else if (argv[a][1] == 'v') { + return print_version(); } else if (argv[a][1] == 'o') { if (++a == argc) { fprintf(stderr, "missing value for -i\n"); -- cgit v1.2.1