diff options
author | larrybr <larrybr@noemail.net> | 2021-07-26 18:28:24 +0000 |
---|---|---|
committer | larrybr <larrybr@noemail.net> | 2021-07-26 18:28:24 +0000 |
commit | e40875d21123bcae130570624961109a07b54864 (patch) | |
tree | 0bc10918a7611c0afb30a9ef5c445225d2a2ac79 /tool/sqldiff.c | |
parent | 37407126777ade303ed954cbb2243a15fe26f1a0 (diff) | |
download | sqlite-e40875d21123bcae130570624961109a07b54864.tar.gz sqlite-e40875d21123bcae130570624961109a07b54864.zip |
Give sqldiff --visible-controls option to deal with non-graphic text content robustly across platforms
FossilOrigin-Name: 68d2373f5d578cf3aff9d1ac4b1ab3ac00b466e94e1eb516523fc7660dfc0549
Diffstat (limited to 'tool/sqldiff.c')
-rw-r--r-- | tool/sqldiff.c | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/tool/sqldiff.c b/tool/sqldiff.c index 9844cbadf..fea40b9fe 100644 --- a/tool/sqldiff.c +++ b/tool/sqldiff.c @@ -34,6 +34,7 @@ struct GlobalVars { int bSchemaOnly; /* Only show schema differences */ int bSchemaPK; /* Use the schema-defined PK, not the true PK */ int bHandleVtab; /* Handle fts3, fts4, fts5 and rtree vtabs */ + int bDarkCtl; /* Render controls in text as blob literals */ unsigned fDebug; /* Debug flags */ sqlite3 *db; /* The database connection */ } g; @@ -386,13 +387,39 @@ static void printQuoted(FILE *out, sqlite3_value *X){ fprintf(out, "NULL"); }else{ fprintf(out, "'"); - for(i=j=0; zArg[i]; i++){ - if( zArg[i]=='\'' ){ - fprintf(out, "%.*s'", i-j+1, &zArg[j]); - j = i+1; - } - } - fprintf(out, "%s'", &zArg[j]); + if( !g.bDarkCtl ){ + for(i=j=0; zArg[i]; i++){ + if( zArg[i]=='\'' ){ + fprintf(out, "%.*s'", i-j+1, &zArg[j]); + j = i+1; + } + } + fprintf(out, "%s'", &zArg[j]); + }else{ + int inctl = 0; + for(i=j=0; zArg[i]; i++){ + char c = zArg[i]; + int ctl = iscntrl(c); + if( ctl>inctl ){ + inctl = ctl; + fprintf(out, "%.*s'||X'%02x", i-j, &zArg[j], c); + j = i+1; + }else if( ctl ){ + fprintf(out, "%02x", c); + j = i+1; + }else{ + if( inctl ){ + inctl = 0; + fprintf(out, "'\n||'"); + } + if( c=='\'' ){ + fprintf(out, "%.*s'", i-j+1, &zArg[j]); + j = i+1; + } + } + } + fprintf(out, "%s'", &zArg[j]); + } } break; } @@ -1875,6 +1902,7 @@ static void showHelp(void){ " --table TAB Show only differences in table TAB\n" " --transaction Show SQL output inside a transaction\n" " --vtab Handle fts3, fts4, fts5 and rtree tables\n" +" --visible-controls Render controls in text as blob literals\n" ); } @@ -1948,6 +1976,9 @@ int main(int argc, char **argv){ if( strcmp(z,"vtab")==0 ){ g.bHandleVtab = 1; }else + if( strcmp(z, "visible-controls")==0 ){ + g.bDarkCtl = 1; + }else { cmdlineError("unknown option: %s", argv[i]); } |