diff options
Diffstat (limited to 'ext/wasm/version-info.c')
-rw-r--r-- | ext/wasm/version-info.c | 72 |
1 files changed, 64 insertions, 8 deletions
diff --git a/ext/wasm/version-info.c b/ext/wasm/version-info.c index cb5083a40..96c8e2dbe 100644 --- a/ext/wasm/version-info.c +++ b/ext/wasm/version-info.c @@ -12,15 +12,71 @@ ** This file simply outputs sqlite3 version information in JSON form, ** intended for embedding in the sqlite3 JS API build. */ -#include <stdio.h> #include "sqlite3.h" +#include <stdio.h> +#include <string.h> + +static void usage(const char *zAppName){ + puts("Emits version info about the sqlite3 it is built against."); + printf("Usage: %s [--quote] --INFO-FLAG:\n\n", zAppName); + puts(" --version Emit SQLITE_VERSION (3.X.Y)"); + puts(" --version-number Emit SQLITE_VERSION_NUMBER (30XXYYZZ)"); + puts(" --source-id Emit SQLITE_SOURCE_ID"); + puts(" --json Emit all info in JSON form"); + puts("\nThe non-JSON formats may be modified by:\n"); + puts(" --quote Add double quotes around output."); +} + int main(int argc, char const * const * argv){ - if(argc || argv){/*unused*/} - printf("{\"libVersion\": \"%s\", " - "\"libVersionNumber\": %d, " - "\"sourceId\": \"%s\"}"/*missing newline is intentional*/, - SQLITE_VERSION, - SQLITE_VERSION_NUMBER, - SQLITE_SOURCE_ID); + int fJson = 0; + int fVersion = 0; + int fVersionNumber = 0; + int fSourceInfo = 0; + int fQuote = 0; + int nFlags = 0; + int i; + + for( i = 1; i < argc; ++i ){ + const char * zArg = argv[i]; + while('-'==*zArg) ++zArg; + if( 0==strcmp("version", zArg) ){ + fVersion = 1; + }else if( 0==strcmp("version-number", zArg) ){ + fVersionNumber = 1; + }else if( 0==strcmp("source-id", zArg) ){ + fSourceInfo = 1; + }else if( 0==strcmp("json", zArg) ){ + fJson = 1; + }else if( 0==strcmp("quote", zArg) ){ + fQuote = 1; + --nFlags; + }else{ + printf("Unhandled flag: %s\n", argv[i]); + usage(argv[0]); + return 1; + } + ++nFlags; + } + + if( 0==nFlags ) fJson = 1; + if( fJson ){ + printf("{\"libVersion\": \"%s\", " + "\"libVersionNumber\": %d, " + "\"sourceId\": \"%s\"}"/*missing newline is intentional*/, + SQLITE_VERSION, + SQLITE_VERSION_NUMBER, + SQLITE_SOURCE_ID); + }else{ + if(fQuote) printf("%c", '"'); + if( fVersion ){ + printf("%s", SQLITE_VERSION); + }else if( fVersionNumber ){ + printf("%d", SQLITE_VERSION_NUMBER); + }else if( fSourceInfo ){ + printf("%s", SQLITE_SOURCE_ID); + } + if(fQuote) printf("%c", '"'); + puts(""); + } return 0; } |