From: drh Date: Thu, 26 Feb 2015 14:27:16 +0000 (+0000) Subject: In the command-line shell, change the units on the ".width" separate from X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fheads%2Fcli-char-width;p=thirdparty%2Fsqlite.git In the command-line shell, change the units on the ".width" separate from bytes to characters. FossilOrigin-Name: b1a9e2916f5b4adef91c34563f71b98e79a10c12 --- diff --git a/manifest b/manifest index 54ad7184b2..2ecaa77f6d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Simplifications\sto\sthe\sdescription\sof\sthe\snByte\sparameter\sto\ssqlite3_prepare()\nand\sfriends. -D 2015-02-26T02:33:52.248 +C In\sthe\scommand-line\sshell,\schange\sthe\sunits\son\sthe\s".width"\sseparate\sfrom\nbytes\sto\scharacters. +D 2015-02-26T14:27:16.982 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -231,7 +231,7 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c f4d79e31ffa5820c2e3d1740baa5e9b190425f2b F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c e46cef4c224549b439384c88fc7f57ba064dad54 -F src/shell.c f06cca68a3f07e03d35d2f879375967169db6a61 +F src/shell.c c8a769c563b41b16196dfef675b008ba543a492f F src/sqlite.h.in 62d3997824038cc32335b04aaa18cc8f4c19e9be F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d @@ -1239,7 +1239,10 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 6d132e7a224ee68b5cefe9222944aac5760ffc20 -R 32aba763c92a19bba8ed1b93e2ee7564 +P 4bee8295e36fb61f903210b6d052ee9b8fb3b6d0 +R 143a1a32cdae3a721c8dd7822db13dda +T *branch * cli-char-width +T *sym-cli-char-width * +T -sym-trunk * U drh -Z b332eede7bc32b2767cceb08a9880768 +Z 9e05d9065c7895cfbe90dd1f0cc9db4d diff --git a/manifest.uuid b/manifest.uuid index 07f7cba1c2..a166b61bb2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4bee8295e36fb61f903210b6d052ee9b8fb3b6d0 \ No newline at end of file +b1a9e2916f5b4adef91c34563f71b98e79a10c12 \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 4aaa2d90ec..c45c95e8f1 100644 --- a/src/shell.c +++ b/src/shell.c @@ -788,6 +788,48 @@ static void interrupt_handler(int NotUsed){ } #endif +/* +** Return the length of a string in characters. Multibyte UTF8 characters +** count as a single character. +*/ +static int strlenChar(const char *z){ + int n = 0; + while( *z ){ + if( (0xc0&*(z++))!=0x80 ) n++; + } + return n; +} + +/* +** Print abs(w) characters of string "z" on FILE "out". +** +** w is in units of characters, not bytes! +** +** The output is always exactly abs(w) characters wide. If z contains +** more than abs(w) characters, it is truncated. If z contains fewer +** than abs(w) characters it is padded with spaces. Spaces are added +** on the right if w>0 (left justification) or on the left if w<0 +** (right justification). +*/ +static void outputFixedWidth(FILE *out, int w, const char *z){ + int n = strlenChar(z); + int absw = w<0 ? -w : w; + int i; + + if( n<=absw ){ + if( w<0 ) for(i=absw-n; i>0; i--) putc(' ', out); + fputs(z, out); + if( w>0 ) for(i=absw-n; i>0; i--) putc(' ', out); + }else{ + for(i=n=0; z[i]; i++){ + if( (z[i]&0xc0)==0x80 ) continue; + if( n==absw ) break; + n++; + } + fwrite(z, 1, i, out); + } +} + /* ** This is the callback routine that the shell ** invokes for each row of a query result. @@ -828,22 +870,17 @@ static int shell_callback( w = 0; } if( w==0 ){ - w = strlen30(azCol[i] ? azCol[i] : ""); + w = strlenChar(azCol[i] ? azCol[i] : ""); if( w<10 ) w = 10; - n = strlen30(azArg && azArg[i] ? azArg[i] : p->nullValue); + n = strlenChar(azArg && azArg[i] ? azArg[i] : p->nullValue); if( wactualWidth) ){ p->actualWidth[i] = w; } if( p->showHeader ){ - if( w<0 ){ - fprintf(p->out,"%*.*s%s",-w,-w,azCol[i], - i==nArg-1 ? p->rowSeparator : " "); - }else{ - fprintf(p->out,"%-*.*s%s",w,w,azCol[i], - i==nArg-1 ? p->rowSeparator : " "); - } + outputFixedWidth(p->out, w, azCol[i]); + fprintf(p->out, "%s", i==nArg-1 ? p->rowSeparator : " "); } } if( p->showHeader ){ @@ -870,7 +907,7 @@ static int shell_callback( w = 10; } if( p->mode==MODE_Explain && azArg[i] && strlen30(azArg[i])>w ){ - w = strlen30(azArg[i]); + w = strlenChar(azArg[i]); } if( i==1 && p->aiIndent && p->pStmt ){ if( p->iIndentnIndent ){ @@ -878,15 +915,8 @@ static int shell_callback( } p->iIndent++; } - if( w<0 ){ - fprintf(p->out,"%*.*s%s",-w,-w, - azArg[i] ? azArg[i] : p->nullValue, - i==nArg-1 ? p->rowSeparator : " "); - }else{ - fprintf(p->out,"%-*.*s%s",w,w, - azArg[i] ? azArg[i] : p->nullValue, - i==nArg-1 ? p->rowSeparator : " "); - } + outputFixedWidth(p->out, w, azArg[i] ? azArg[i] : p->nullValue); + fprintf(p->out, "%s", i==nArg-1 ? p->rowSeparator : " "); } break; }