version-info.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 <stdio.h>
  24. #include <string.h>
  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. int main(int argc, char const * const * argv){
  37. int fJson = 0;
  38. int fVersion = 0;
  39. int fVersionNumber = 0;
  40. int fDlVersion = 0;
  41. int dlVersion = 0;
  42. int fSourceInfo = 0;
  43. int fQuote = 0;
  44. int nFlags = 0;
  45. int i;
  46. for( i = 1; i < argc; ++i ){
  47. const char * zArg = argv[i];
  48. while('-'==*zArg) ++zArg;
  49. if( 0==strcmp("version", zArg) ){
  50. fVersion = 1;
  51. }else if( 0==strcmp("version-number", zArg) ){
  52. fVersionNumber = 1;
  53. }else if( 0==strcmp("download-version", zArg) ){
  54. fDlVersion = 1;
  55. }else if( 0==strcmp("source-id", zArg) ){
  56. fSourceInfo = 1;
  57. }else if( 0==strcmp("json", zArg) ){
  58. fJson = 1;
  59. }else if( 0==strcmp("quote", zArg) ){
  60. fQuote = 1;
  61. --nFlags;
  62. }else{
  63. printf("Unhandled flag: %s\n", argv[i]);
  64. usage(argv[0]);
  65. return 1;
  66. }
  67. ++nFlags;
  68. }
  69. if( 0==nFlags ) fJson = 1;
  70. {
  71. const int v = SQLITE_VERSION_NUMBER;
  72. int ver[4] = {0,0,0,0};
  73. ver[0] = (v / 1000000) * 1000000;
  74. ver[1] = v % 1000000 / 100 * 1000;
  75. ver[2] = v % 100 * 100;
  76. dlVersion = ver[0] + ver[1] + ver[2] + ver[3];
  77. }
  78. if( fJson ){
  79. printf("{\"libVersion\": \"%s\", "
  80. "\"libVersionNumber\": %d, "
  81. "\"sourceId\": \"%s\","
  82. "\"downloadVersion\": %d}"/*missing newline is intentional*/,
  83. SQLITE_VERSION,
  84. SQLITE_VERSION_NUMBER,
  85. SQLITE_SOURCE_ID,
  86. dlVersion);
  87. }else{
  88. if(fQuote) printf("%c", '"');
  89. if( fVersion ){
  90. printf("%s", SQLITE_VERSION);
  91. }else if( fVersionNumber ){
  92. printf("%d", SQLITE_VERSION_NUMBER);
  93. }else if( fSourceInfo ){
  94. printf("%s", SQLITE_SOURCE_ID);
  95. }else if( fDlVersion ){
  96. printf("%d", dlVersion);
  97. }
  98. if(fQuote) printf("%c", '"');
  99. puts("");
  100. }
  101. return 0;
  102. }