]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Clean up command-line parsing. Add the undocumented
authordrh <>
Fri, 2 May 2025 23:50:30 +0000 (23:50 +0000)
committerdrh <>
Fri, 2 May 2025 23:50:30 +0000 (23:50 +0000)
-protocol option for debugging.

FossilOrigin-Name: 2a52b174e6e91cd7cfca0b20b39cdd231f377c7bc073f4223574556b94b16aa5

manifest
manifest.uuid
tool/sqlite3_rsync.c

index 3b78d8c88de981d9606167969d22fae7fac856cb..42c215830d1b3fdcf98629b2aa7a5a7dc3ecf7c7 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Now\sappears\sto\sbe\sworking.\s\sMore\stesting\sneeded.\s\sRefinement\sof\sthe\nversion-2\salgorithm\sneeded.
-D 2025-05-02T22:25:40.184
+C Clean\sup\scommand-line\sparsing.\s\sAdd\sthe\sundocumented\s\n-protocol\soption\sfor\sdebugging.
+D 2025-05-02T23:50:30.776
 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -2189,7 +2189,7 @@ F tool/spellsift.tcl 52b4b04dc4333c7ab024f09d9d66ed6b6f7c6eb00b38497a09f338fa55d
 F tool/split-sqlite3c.tcl 07e18a1d8cc3f6b3a4a1f3528e63c9b29a5c8a7bca0b8d394b231da464ce1247
 F tool/sqldiff.c 134be7866be19f8beb32043d5aea5657f01aaeae2df8d33d758ff722c78666b9
 F tool/sqlite3_analyzer.c.in 14f02cb5ec3c264cd6107d1f1dad77092b1cf440fc196c30b69ae87b56a1a43b
-F tool/sqlite3_rsync.c 7f61ac7b58fe7d0d5a6abbd1570c75bce9c160fc0d5b1b679b2213d03f047b27
+F tool/sqlite3_rsync.c 97ec284a12ccf4203ace717cb1943ac652e2723d86ef0acfca517b270516e85c
 F tool/sqltclsh.c.in 1bcc2e9da58fadf17b0bf6a50e68c1159e602ce057210b655d50bad5aaaef898
 F tool/sqltclsh.tcl 862f4cf1418df5e1315b5db3b5ebe88969e2a784525af5fbf9596592f14ed848
 F tool/src-verify.c d00f93263aa2fa6ba0cba0106d95458e6effb94fdb5fc634f56834f90c05bbb4
@@ -2207,8 +2207,8 @@ F tool/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd7227350
 F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
 F tool/warnings.sh 49a486c5069de041aedcbde4de178293e0463ae9918ecad7539eedf0ec77a139
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P c70330668690e7c3c55ae34137d5b2c91871432004b82b2b23a89fc3f1322a62
-R 68278fe558d911d1ca48d9ecb46d934b
+P cb035181d9fb5909696b8ec8f9c3eeb7a7dfb4b50e82e1d3f2d5ad150afcc0ff
+R d99c926bcfda0557c90ab8e625e5e88b
 U drh
-Z 92a9f6cb386b9d8c6c4ee41cda50ebec
+Z 1169e74b2b686e6aa9ef554d4d02a6d5
 # Remove this line to create a well-formed Fossil manifest.
index c81f190ec531538c2de7e7023b0a535e8515f283..12ac9e625895f8c91863b6a13e51526bce8c5b5e 100644 (file)
@@ -1 +1 @@
-cb035181d9fb5909696b8ec8f9c3eeb7a7dfb4b50e82e1d3f2d5ad150afcc0ff
+2a52b174e6e91cd7cfca0b20b39cdd231f377c7bc073f4223574556b94b16aa5
index 62f751ad34b88641ab297f50429bbc0d6bd14640..cc770ea922446119ea6f6ebb80733e8848efb64c 100644 (file)
@@ -1309,7 +1309,7 @@ static void originSide(SQLiteRsync *p){
   p->isReplica = 0;
   if( p->bCommCheck ){
     infoMsg(p, "origin  zOrigin=%Q zReplica=%Q isRemote=%d protocol=%d",
-               p->zOrigin, p->zReplica, p->isRemote, PROTOCOL_VERSION);
+               p->zOrigin, p->zReplica, p->isRemote, p->iProtocol);
     writeByte(p, ORIGIN_END);
     fflush(p->pOut);
   }else{
@@ -1335,13 +1335,12 @@ static void originSide(SQLiteRsync *p){
     if( p->nErr==0 ){
       /* Send the ORIGIN_BEGIN message */
       writeByte(p, ORIGIN_BEGIN);
-      writeByte(p, PROTOCOL_VERSION);
+      writeByte(p, p->iProtocol);
       writePow2(p, szPg);
       writeUint32(p, nPage);
       fflush(p->pOut);
       p->nPage = nPage;
       p->szPage = szPg;
-      p->iProtocol = PROTOCOL_VERSION;
       lockBytePage = (1<<30)/szPg + 1;
     }
   }
@@ -1691,7 +1690,7 @@ static void replicaSide(SQLiteRsync *p){
   p->isReplica = 1;
   if( p->bCommCheck ){
     infoMsg(p, "replica zOrigin=%Q zReplica=%Q isRemote=%d protocol=%d",
-               p->zOrigin, p->zReplica, p->isRemote, PROTOCOL_VERSION);
+               p->zOrigin, p->zReplica, p->isRemote, p->iProtocol);
     writeByte(p, REPLICA_END);
     fflush(p->pOut);
   }
@@ -1710,9 +1709,10 @@ static void replicaSide(SQLiteRsync *p){
         unsigned int nOPage = 0;
         unsigned int nRPage = 0, szRPage = 0;
         int rc = 0;
+        u8 iProtocol;
 
         closeDb(p);
-        p->iProtocol = readByte(p);
+        iProtocol = readByte(p);
         szOPage = readPow2(p);
         readUint32(p, &nOPage);
         if( p->zDebugFile ){
@@ -1720,18 +1720,19 @@ static void replicaSide(SQLiteRsync *p){
                        nOPage);
         }
         if( p->nErr ) break;
-        if( p->iProtocol>PROTOCOL_VERSION ){
+        if( iProtocol>p->iProtocol ){
           /* If the protocol version on the origin side is larger, send back
           ** a REPLICA_BEGIN message with the protocol version number of the
           ** replica side.  This gives the origin an opportunity to resend
           ** a new ORIGIN_BEGIN with a reduced protocol version. */
           writeByte(p, REPLICA_BEGIN);
-          writeByte(p, PROTOCOL_VERSION);
+          writeByte(p, p->iProtocol);
           if( p->zDebugFile ){
-            debugMessage(p, "-> REPLICA_BEGIN %u\n", PROTOCOL_VERSION);
+            debugMessage(p, "-> REPLICA_BEGIN %u\n", p->iProtocol);
           }
           break;
         }
+        p->iProtocol = iProtocol;
         p->nPage = nOPage;
         p->szPage = szOPage;
         rc = sqlite3_open(":memory:", &p->db);
@@ -2006,6 +2007,7 @@ int main(int argc, char const * const *argv){
 
 #define cli_opt_val cmdline_option_value(argc, argv, ++i)
   memset(&ctx, 0, sizeof(ctx));
+  ctx.iProtocol = PROTOCOL_VERSION;
   for(i=1; i<argc; i++){
     const char *z = argv[i];
     if( z[0]=='-' && z[1]=='-' && z[2]!=0 ) z++;
@@ -2029,6 +2031,20 @@ int main(int argc, char const * const *argv){
       zExe = cli_opt_val;
       continue;
     }
+    if( strcmp(z, "-wal-only")==0 ){
+      ctx.bWalOnly = 1;
+      continue;
+    }
+    if( strcmp(z, "-version")==0 ){
+      printf("%s\n", sqlite3_sourceid());
+      return 0;
+    }
+    if( strcmp(z, "-help")==0 || strcmp(z, "--help")==0
+     || strcmp(z, "-?")==0
+    ){
+      printf("%s", zUsage);
+      return 0;
+    }
     if( strcmp(z, "-logfile")==0 ){
       /* DEBUG OPTION:  --logfile FILENAME
       ** Cause all local output traffic to be duplicated in FILENAME */
@@ -2067,39 +2083,36 @@ int main(int argc, char const * const *argv){
       zRemoteDebugFile = cli_opt_val;
       continue;
     }
-    if( strcmp(z, "-wal-only")==0 ){
-      ctx.bWalOnly = 1;
+    if( strcmp(z, "-protocol")==0 ){
+      /* DEBUG OPTION:  --protocool N
+      ** Set the protocol version to N */
+      ctx.iProtocol = atoi(cli_opt_val);
+      if( ctx.iProtocol<1 ){
+        ctx.iProtocol = 1;
+      }else if( ctx.iProtocol>PROTOCOL_VERSION ){
+        ctx.iProtocol = PROTOCOL_VERSION;
+      }
       continue;
     }
-    if( strcmp(z, "-help")==0 || strcmp(z, "--help")==0
-     || strcmp(z, "-?")==0
-    ){
-      printf("%s", zUsage);
-      return 0;
+    if( strcmp(z,"-commcheck")==0 ){  /* DEBUG ONLY */
+      /* Run a communication check with the remote side.  Do not attempt
+      ** to exchange any database connection */
+      ctx.bCommCheck = 1;
+      continue;
     }
-    if( strcmp(z, "-version")==0 ){
-      printf("%s\n", sqlite3_sourceid());
+    if( strcmp(z,"-arg-escape-check")==0 ){  /* DEBUG ONLY */
+      /* Test the append_escaped_arg() routine by using it to render a
+      ** copy of the input command-line, assuming all arguments except
+      ** this one are filenames. */
+      sqlite3_str *pStr = sqlite3_str_new(0);
+      int k;
+      for(k=0; k<argc; k++){
+        append_escaped_arg(pStr, argv[k], i!=k);
+      }
+      printf("%s\n", sqlite3_str_value(pStr));
       return 0;
     }
-    if( z[0]=='-' ){
-      if( strcmp(z,"-commcheck")==0 ){  /* DEBUG ONLY */
-        /* Run a communication check with the remote side.  Do not attempt
-        ** to exchange any database connection */
-        ctx.bCommCheck = 1;
-        continue;
-      }
-      if( strcmp(z,"-arg-escape-check")==0 ){  /* DEBUG ONLY */
-        /* Test the append_escaped_arg() routine by using it to render a
-        ** copy of the input command-line, assuming all arguments except
-        ** this one are filenames. */
-        sqlite3_str *pStr = sqlite3_str_new(0);
-        int k;
-        for(k=0; k<argc; k++){
-          append_escaped_arg(pStr, argv[k], i!=k);
-        }
-        printf("%s\n", sqlite3_str_value(pStr));
-        return 0;
-      }
+    if( z[i]=='-' ){
       fprintf(stderr,
          "unknown option: \"%s\". Use --help for more detail.\n", z);
       return 1;