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