From db07c26b8c20840f0b073d6876abde3db2c60582 Mon Sep 17 00:00:00 2001 From: "D. Richard Hipp" Date: Sat, 6 Jan 2018 15:46:20 +0000 Subject: [PATCH] Improved output from ".schema --indent" when a column definition is followed by a comment. --- src/shell.c.in | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/shell.c.in b/src/shell.c.in index bb4428fbc5..c113bdb934 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -1412,6 +1412,22 @@ static void printSchemaLineN(FILE *out, char *z, int n, const char *zTail){ } /* +** Return true if string z[] has nothing but whitespace and comments to the +** end of the first line. +*/ +static int wsToEol(const char *z){ + int i; + for(i=0; z[i]; i++){ + if( z[i]=='\n' ) return 1; + if( IsSpace(z[i]) ) continue; + if( z[i]=='-' && z[i+1]=='-' ) return 1; + return 0; + } + return 1; +} + + +/* ** This is the callback routine that the shell ** invokes for each row of a query result. */ @@ -1550,13 +1566,15 @@ static int shell_callback( while( j>0 && IsSpace(z[j-1]) ){ j--; } z[j] = 0; if( strlen30(z)>=79 ){ - for(i=j=0; (c = z[i])!=0; i++){ + for(i=j=0; (c = z[i])!=0; i++){ /* Copy changes from z[i] back to z[j] */ if( c==cEnd ){ cEnd = 0; }else if( c=='"' || c=='\'' || c=='`' ){ cEnd = c; }else if( c=='[' ){ cEnd = ']'; + }else if( c=='-' && z[i+1]=='-' ){ + cEnd = '\n'; }else if( c=='(' ){ nParen++; }else if( c==')' ){ @@ -1567,7 +1585,9 @@ static int shell_callback( } } z[j++] = c; - if( nParen==1 && (c=='(' || c==',' || c=='\n') ){ + if( nParen==1 && cEnd==0 + && (c=='(' || c=='\n' || (c==',' && !wsToEol(z+i+1))) + ){ if( c=='\n' ) j--; printSchemaLineN(p->out, z, j, "\n "); j = 0; -- 2.11.4.GIT