Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/tool/version-info.c # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / tool / version-info.c` 114 lines ยท 3409 bytes Raw Blame History 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 #ifdef TEST_VERSION 16 /*`3029003` `3039012`*/ 17 #define SQLITE_VERSION "X.Y.Z" 18 #define SQLITE_VERSION_NUMBER TEST_VERSION 19 #define SQLITE_SOURCE_ID "dummy" 20 #else 21 #include "sqlite3.h" 22 #endif 23 #include 24 #include 25 static void usage(const char *zAppName){ 26 puts("Emits version info about the sqlite3 it is built against."); 27 printf("Usage: %s [--quote] --INFO-FLAG:\n\n", zAppName); 28 puts(" --version Emit SQLITE_VERSION (3.X.Y)"); 29 puts(" --version-number Emit SQLITE_VERSION_NUMBER (30XXYYZZ)"); 30 puts(" --download-version Emit /download.html version number (3XXYYZZ)"); 31 puts(" --source-id Emit SQLITE_SOURCE_ID"); 32 puts(" --json Emit all info in JSON form"); 33 puts("\nThe non-JSON formats may be modified by:\n"); 34 puts(" --quote Add double quotes around output."); 35 } 36 37 int main(int argc, char const * const * argv){ 38 int fJson = 0; 39 int fVersion = 0; 40 int fVersionNumber = 0; 41 int fDlVersion = 0; 42 int dlVersion = 0; 43 int fSourceInfo = 0; 44 int fQuote = 0; 45 int nFlags = 0; 46 int i; 47 48 for( i = 1; i < argc; ++i ){ 49 const char * zArg = argv[i]; 50 while('-'==*zArg) ++zArg; 51 if( 0==strcmp("version", zArg) ){ 52 fVersion = 1; 53 }else if( 0==strcmp("version-number", zArg) ){ 54 fVersionNumber = 1; 55 }else if( 0==strcmp("download-version", zArg) ){ 56 fDlVersion = 1; 57 }else if( 0==strcmp("source-id", zArg) ){ 58 fSourceInfo = 1; 59 }else if( 0==strcmp("json", zArg) ){ 60 fJson = 1; 61 }else if( 0==strcmp("quote", zArg) ){ 62 fQuote = 1; 63 --nFlags; 64 }else{ 65 printf("Unhandled flag: %s\n", argv[i]); 66 usage(argv[0]); 67 return 1; 68 } 69 ++nFlags; 70 } 71 72 if( 0==nFlags ) fJson = 1; 73 74 { 75 const int v = SQLITE_VERSION_NUMBER; 76 int ver[4] = {0,0,0,0}; 77 ver[0] = (v / `1000000`) * `1000000`; 78 ver[1] = v % `1000000` / 100 * 1000; 79 ver[2] = v % 100 * 100; 80 dlVersion = ver[0] + ver[1] + ver[2] + ver[3]; 81 } 82 if( fJson ){ 83 printf("{\"libVersion\": \"%s\", " 84 "\"libVersionNumber\": %d, " 85 "\"sourceId\": \"%s\"," 86 "\"downloadVersion\": %d," 87 "\"scm\":{ " 88 "\"sha3-256\": \"%s\"," 89 "\"branch\": \"" SQLITE_SCM_BRANCH "\"," 90 "\"tags\": \"" SQLITE_SCM_TAGS "\"," 91 "\"datetime\": \"" SQLITE_SCM_DATETIME "\"" 92 "}" 93 "}"/*missing newline is intentional*/, 94 SQLITE_VERSION, 95 SQLITE_VERSION_NUMBER, 96 SQLITE_SOURCE_ID, 97 dlVersion, 98 SQLITE_SOURCE_ID+20); 99 }else{ 100 if(fQuote) printf("%c", '"'); 101 if( fVersion ){ 102 printf("%s", SQLITE_VERSION); 103 }else if( fVersionNumber ){ 104 printf("%d", SQLITE_VERSION_NUMBER); 105 }else if( fSourceInfo ){ 106 printf("%s", SQLITE_SOURCE_ID); 107 }else if( fDlVersion ){ 108 printf("%d", dlVersion); 109 } 110 if(fQuote) printf("%c", '"'); 111 puts(""); 112 } 113 return 0; 114 }