1cdc9ddc6Sstephan /* 2cdc9ddc6Sstephan ** 2022-10-16 3cdc9ddc6Sstephan ** 4cdc9ddc6Sstephan ** The author disclaims copyright to this source code. In place of a 5cdc9ddc6Sstephan ** legal notice, here is a blessing: 6cdc9ddc6Sstephan ** 7cdc9ddc6Sstephan ** * May you do good and not evil. 8cdc9ddc6Sstephan ** * May you find forgiveness for yourself and forgive others. 9cdc9ddc6Sstephan ** * May you share freely, never taking more than you give. 10cdc9ddc6Sstephan ** 11cdc9ddc6Sstephan ************************************************************************* 12cdc9ddc6Sstephan ** This file simply outputs sqlite3 version information in JSON form, 13cdc9ddc6Sstephan ** intended for embedding in the sqlite3 JS API build. 14cdc9ddc6Sstephan */ 15cdc9ddc6Sstephan #include "sqlite3.h" 16*1b8c2467Sstephan #include <stdio.h> 17*1b8c2467Sstephan #include <string.h> 18*1b8c2467Sstephan 19*1b8c2467Sstephan static void usage(const char *zAppName){ 20*1b8c2467Sstephan puts("Emits version info about the sqlite3 it is built against."); 21*1b8c2467Sstephan printf("Usage: %s [--quote] --INFO-FLAG:\n\n", zAppName); 22*1b8c2467Sstephan puts(" --version Emit SQLITE_VERSION (3.X.Y)"); 23*1b8c2467Sstephan puts(" --version-number Emit SQLITE_VERSION_NUMBER (30XXYYZZ)"); 24*1b8c2467Sstephan puts(" --source-id Emit SQLITE_SOURCE_ID"); 25*1b8c2467Sstephan puts(" --json Emit all info in JSON form"); 26*1b8c2467Sstephan puts("\nThe non-JSON formats may be modified by:\n"); 27*1b8c2467Sstephan puts(" --quote Add double quotes around output."); 28*1b8c2467Sstephan } 29*1b8c2467Sstephan 30cdc9ddc6Sstephan int main(int argc, char const * const * argv){ 31*1b8c2467Sstephan int fJson = 0; 32*1b8c2467Sstephan int fVersion = 0; 33*1b8c2467Sstephan int fVersionNumber = 0; 34*1b8c2467Sstephan int fSourceInfo = 0; 35*1b8c2467Sstephan int fQuote = 0; 36*1b8c2467Sstephan int nFlags = 0; 37*1b8c2467Sstephan int i; 38*1b8c2467Sstephan 39*1b8c2467Sstephan for( i = 1; i < argc; ++i ){ 40*1b8c2467Sstephan const char * zArg = argv[i]; 41*1b8c2467Sstephan while('-'==*zArg) ++zArg; 42*1b8c2467Sstephan if( 0==strcmp("version", zArg) ){ 43*1b8c2467Sstephan fVersion = 1; 44*1b8c2467Sstephan }else if( 0==strcmp("version-number", zArg) ){ 45*1b8c2467Sstephan fVersionNumber = 1; 46*1b8c2467Sstephan }else if( 0==strcmp("source-id", zArg) ){ 47*1b8c2467Sstephan fSourceInfo = 1; 48*1b8c2467Sstephan }else if( 0==strcmp("json", zArg) ){ 49*1b8c2467Sstephan fJson = 1; 50*1b8c2467Sstephan }else if( 0==strcmp("quote", zArg) ){ 51*1b8c2467Sstephan fQuote = 1; 52*1b8c2467Sstephan --nFlags; 53*1b8c2467Sstephan }else{ 54*1b8c2467Sstephan printf("Unhandled flag: %s\n", argv[i]); 55*1b8c2467Sstephan usage(argv[0]); 56*1b8c2467Sstephan return 1; 57*1b8c2467Sstephan } 58*1b8c2467Sstephan ++nFlags; 59*1b8c2467Sstephan } 60*1b8c2467Sstephan 61*1b8c2467Sstephan if( 0==nFlags ) fJson = 1; 62*1b8c2467Sstephan if( fJson ){ 63cdc9ddc6Sstephan printf("{\"libVersion\": \"%s\", " 64cdc9ddc6Sstephan "\"libVersionNumber\": %d, " 65cdc9ddc6Sstephan "\"sourceId\": \"%s\"}"/*missing newline is intentional*/, 66cdc9ddc6Sstephan SQLITE_VERSION, 67cdc9ddc6Sstephan SQLITE_VERSION_NUMBER, 68cdc9ddc6Sstephan SQLITE_SOURCE_ID); 69*1b8c2467Sstephan }else{ 70*1b8c2467Sstephan if(fQuote) printf("%c", '"'); 71*1b8c2467Sstephan if( fVersion ){ 72*1b8c2467Sstephan printf("%s", SQLITE_VERSION); 73*1b8c2467Sstephan }else if( fVersionNumber ){ 74*1b8c2467Sstephan printf("%d", SQLITE_VERSION_NUMBER); 75*1b8c2467Sstephan }else if( fSourceInfo ){ 76*1b8c2467Sstephan printf("%s", SQLITE_SOURCE_ID); 77*1b8c2467Sstephan } 78*1b8c2467Sstephan if(fQuote) printf("%c", '"'); 79*1b8c2467Sstephan puts(""); 80*1b8c2467Sstephan } 81cdc9ddc6Sstephan return 0; 82cdc9ddc6Sstephan } 83