Fossil SCM

Update to the latest SQLite that contains split-column bug fixes. Add options to force column mode and colorization in the "fossil sys ls" command.

drh 2025-11-25 18:25 trunk
Commit 6ae9c9aa5b4e7efbe76f6ede2bcf54a98cf33009d82c66e65e94d789cd9e8c53
+8 -6
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -1990,19 +1990,19 @@
19901990
int k; /* Bytes in a VT100 code */
19911991
int n; /* Output column number */
19921992
const unsigned char *z = (const unsigned char*)zIn;
19931993
unsigned char c = 0;
19941994
1995
- if( zIn[0]==0 ){
1995
+ if( z[0]==0 ){
19961996
*pnThis = 0;
19971997
*pnWide = 0;
19981998
*piNext = 0;
19991999
return;
20002000
}
20012001
n = 0;
2002
- for(i=0; n<w; i++){
2003
- c = zIn[i];
2002
+ for(i=0; n<=w; i++){
2003
+ c = z[i];
20042004
if( c>=0xc0 ){
20052005
int u;
20062006
int len = sqlite3_qrf_decode_utf8(&z[i], &u);
20072007
int wcw = sqlite3_qrf_wcwidth(u);
20082008
if( wcw+n>w ) break;
@@ -2009,23 +2009,26 @@
20092009
i += len-1;
20102010
n += wcw;
20112011
continue;
20122012
}
20132013
if( c>=' ' ){
2014
+ if( n==w ) break;
20142015
n++;
20152016
continue;
20162017
}
20172018
if( c==0 || c=='\n' ) break;
2018
- if( c=='\r' && zIn[i+1]=='\n' ){ c = zIn[++i]; break; }
2019
+ if( c=='\r' && z[i+1]=='\n' ){ c = z[++i]; break; }
20192020
if( c=='\t' ){
20202021
int wcw = 8 - (n&7);
20212022
if( n+wcw>w ) break;
20222023
n += wcw;
20232024
continue;
20242025
}
20252026
if( c==0x1b && (k = qrfIsVt100(&z[i]))>0 ){
20262027
i += k-1;
2028
+ }else if( n==w ){
2029
+ break;
20272030
}else{
20282031
n++;
20292032
}
20302033
}
20312034
if( c==0 ){
@@ -33669,11 +33672,10 @@
3366933672
3367033673
if( (c=='t' && n>1 && cli_strncmp(azArg[0], "tables", n)==0)
3367133674
|| (c=='i' && (cli_strncmp(azArg[0], "indices", n)==0
3367233675
|| cli_strncmp(azArg[0], "indexes", n)==0) )
3367333676
){
33674
- int ii;
3367533677
sqlite3_stmt *pStmt;
3367633678
sqlite3_str *pSql;
3367733679
const char *zPattern = nArg>1 ? azArg[1] : 0;
3367833680
3367933681
open_db(p, 0);
@@ -33691,11 +33693,11 @@
3369133693
rc = 1;
3369233694
sqlite3_finalize(pStmt);
3369333695
goto meta_command_exit;
3369433696
}
3369533697
pSql = sqlite3_str_new(p->db);
33696
- for(ii=0; sqlite3_step(pStmt)==SQLITE_ROW; ii++){
33698
+ while( sqlite3_step(pStmt)==SQLITE_ROW ){
3369733699
const char *zDbName = (const char*)sqlite3_column_text(pStmt, 1);
3369833700
if( zDbName==0 ) continue;
3369933701
if( sqlite3_str_length(pSql) ){
3370033702
sqlite3_str_appendall(pSql, " UNION ALL ");
3370133703
}
3370233704
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -1990,19 +1990,19 @@
1990 int k; /* Bytes in a VT100 code */
1991 int n; /* Output column number */
1992 const unsigned char *z = (const unsigned char*)zIn;
1993 unsigned char c = 0;
1994
1995 if( zIn[0]==0 ){
1996 *pnThis = 0;
1997 *pnWide = 0;
1998 *piNext = 0;
1999 return;
2000 }
2001 n = 0;
2002 for(i=0; n<w; i++){
2003 c = zIn[i];
2004 if( c>=0xc0 ){
2005 int u;
2006 int len = sqlite3_qrf_decode_utf8(&z[i], &u);
2007 int wcw = sqlite3_qrf_wcwidth(u);
2008 if( wcw+n>w ) break;
@@ -2009,23 +2009,26 @@
2009 i += len-1;
2010 n += wcw;
2011 continue;
2012 }
2013 if( c>=' ' ){
 
2014 n++;
2015 continue;
2016 }
2017 if( c==0 || c=='\n' ) break;
2018 if( c=='\r' && zIn[i+1]=='\n' ){ c = zIn[++i]; break; }
2019 if( c=='\t' ){
2020 int wcw = 8 - (n&7);
2021 if( n+wcw>w ) break;
2022 n += wcw;
2023 continue;
2024 }
2025 if( c==0x1b && (k = qrfIsVt100(&z[i]))>0 ){
2026 i += k-1;
 
 
2027 }else{
2028 n++;
2029 }
2030 }
2031 if( c==0 ){
@@ -33669,11 +33672,10 @@
33669
33670 if( (c=='t' && n>1 && cli_strncmp(azArg[0], "tables", n)==0)
33671 || (c=='i' && (cli_strncmp(azArg[0], "indices", n)==0
33672 || cli_strncmp(azArg[0], "indexes", n)==0) )
33673 ){
33674 int ii;
33675 sqlite3_stmt *pStmt;
33676 sqlite3_str *pSql;
33677 const char *zPattern = nArg>1 ? azArg[1] : 0;
33678
33679 open_db(p, 0);
@@ -33691,11 +33693,11 @@
33691 rc = 1;
33692 sqlite3_finalize(pStmt);
33693 goto meta_command_exit;
33694 }
33695 pSql = sqlite3_str_new(p->db);
33696 for(ii=0; sqlite3_step(pStmt)==SQLITE_ROW; ii++){
33697 const char *zDbName = (const char*)sqlite3_column_text(pStmt, 1);
33698 if( zDbName==0 ) continue;
33699 if( sqlite3_str_length(pSql) ){
33700 sqlite3_str_appendall(pSql, " UNION ALL ");
33701 }
33702
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -1990,19 +1990,19 @@
1990 int k; /* Bytes in a VT100 code */
1991 int n; /* Output column number */
1992 const unsigned char *z = (const unsigned char*)zIn;
1993 unsigned char c = 0;
1994
1995 if( z[0]==0 ){
1996 *pnThis = 0;
1997 *pnWide = 0;
1998 *piNext = 0;
1999 return;
2000 }
2001 n = 0;
2002 for(i=0; n<=w; i++){
2003 c = z[i];
2004 if( c>=0xc0 ){
2005 int u;
2006 int len = sqlite3_qrf_decode_utf8(&z[i], &u);
2007 int wcw = sqlite3_qrf_wcwidth(u);
2008 if( wcw+n>w ) break;
@@ -2009,23 +2009,26 @@
2009 i += len-1;
2010 n += wcw;
2011 continue;
2012 }
2013 if( c>=' ' ){
2014 if( n==w ) break;
2015 n++;
2016 continue;
2017 }
2018 if( c==0 || c=='\n' ) break;
2019 if( c=='\r' && z[i+1]=='\n' ){ c = z[++i]; break; }
2020 if( c=='\t' ){
2021 int wcw = 8 - (n&7);
2022 if( n+wcw>w ) break;
2023 n += wcw;
2024 continue;
2025 }
2026 if( c==0x1b && (k = qrfIsVt100(&z[i]))>0 ){
2027 i += k-1;
2028 }else if( n==w ){
2029 break;
2030 }else{
2031 n++;
2032 }
2033 }
2034 if( c==0 ){
@@ -33669,11 +33672,10 @@
33672
33673 if( (c=='t' && n>1 && cli_strncmp(azArg[0], "tables", n)==0)
33674 || (c=='i' && (cli_strncmp(azArg[0], "indices", n)==0
33675 || cli_strncmp(azArg[0], "indexes", n)==0) )
33676 ){
 
33677 sqlite3_stmt *pStmt;
33678 sqlite3_str *pSql;
33679 const char *zPattern = nArg>1 ? azArg[1] : 0;
33680
33681 open_db(p, 0);
@@ -33691,11 +33693,11 @@
33693 rc = 1;
33694 sqlite3_finalize(pStmt);
33695 goto meta_command_exit;
33696 }
33697 pSql = sqlite3_str_new(p->db);
33698 while( sqlite3_step(pStmt)==SQLITE_ROW ){
33699 const char *zDbName = (const char*)sqlite3_column_text(pStmt, 1);
33700 if( zDbName==0 ) continue;
33701 if( sqlite3_str_length(pSql) ){
33702 sqlite3_str_appendall(pSql, " UNION ALL ");
33703 }
33704
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
1616
** if you want a wrapper to interface SQLite with your choice of programming
1717
** language. The code for the "sqlite3" command-line shell is also in a
1818
** separate file. This file contains only code for the core SQLite library.
1919
**
2020
** The content in this amalgamation comes from Fossil check-in
21
-** d4c1d3e30b774802a7abd5f61807a690fb5b with changes in files:
21
+** 5804ba4874cc41b11e8bb559d5533283c289 with changes in files:
2222
**
2323
**
2424
*/
2525
#ifndef SQLITE_AMALGAMATION
2626
#define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467467
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468468
** [sqlite_version()] and [sqlite_source_id()].
469469
*/
470470
#define SQLITE_VERSION "3.52.0"
471471
#define SQLITE_VERSION_NUMBER 3052000
472
-#define SQLITE_SOURCE_ID "2025-11-25 13:58:36 d4c1d3e30b774802a7abd5f61807a690fb5be7617459f3dbd7ec1efceb6125d7"
472
+#define SQLITE_SOURCE_ID "2025-11-25 18:20:33 5804ba4874cc41b11e8bb559d5533283c2895d2b13316830955663575567f911"
473473
#define SQLITE_SCM_BRANCH "trunk"
474474
#define SQLITE_SCM_TAGS ""
475
-#define SQLITE_SCM_DATETIME "2025-11-25T13:58:36.873Z"
475
+#define SQLITE_SCM_DATETIME "2025-11-25T18:20:33.534Z"
476476
477477
/*
478478
** CAPI3REF: Run-Time Library Version Numbers
479479
** KEYWORDS: sqlite3_version sqlite3_sourceid
480480
**
@@ -208070,11 +208070,11 @@
208070208070
int v;
208071208071
if( nVal>9 && 0==sqlite3_strnicmp(zVal, "nodesize=", 9) ){
208072208072
v = atoi(&zVal[9]);
208073208073
if( v>=24 && v<=p->nPgsz-35 ) p->nNodeSize = v;
208074208074
rc = SQLITE_OK;
208075
- }else if( nVal>11 && 0==sqlite3_strnicmp(zVal, "maxpending=", 9) ){
208075
+ }else if( nVal>11 && 0==sqlite3_strnicmp(zVal, "maxpending=", 11) ){
208076208076
v = atoi(&zVal[11]);
208077208077
if( v>=64 && v<=FTS3_MAX_PENDING_DATA ) p->nMaxPendingData = v;
208078208078
rc = SQLITE_OK;
208079208079
}else if( nVal>21 && 0==sqlite3_strnicmp(zVal,"test-no-incr-doclist=",21) ){
208080208080
p->bNoIncrDoclist = atoi(&zVal[21]);
@@ -261263,11 +261263,11 @@
261263261263
int nArg, /* Number of args */
261264261264
sqlite3_value **apUnused /* Function arguments */
261265261265
){
261266261266
assert( nArg==0 );
261267261267
UNUSED_PARAM2(nArg, apUnused);
261268
- sqlite3_result_text(pCtx, "fts5: 2025-11-25 13:58:36 d4c1d3e30b774802a7abd5f61807a690fb5be7617459f3dbd7ec1efceb6125d7", -1, SQLITE_TRANSIENT);
261268
+ sqlite3_result_text(pCtx, "fts5: 2025-11-25 18:20:33 5804ba4874cc41b11e8bb559d5533283c2895d2b13316830955663575567f911", -1, SQLITE_TRANSIENT);
261269261269
}
261270261270
261271261271
/*
261272261272
** Implementation of fts5_locale(LOCALE, TEXT) function.
261273261273
**
261274261274
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** d4c1d3e30b774802a7abd5f61807a690fb5b with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468 ** [sqlite_version()] and [sqlite_source_id()].
469 */
470 #define SQLITE_VERSION "3.52.0"
471 #define SQLITE_VERSION_NUMBER 3052000
472 #define SQLITE_SOURCE_ID "2025-11-25 13:58:36 d4c1d3e30b774802a7abd5f61807a690fb5be7617459f3dbd7ec1efceb6125d7"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2025-11-25T13:58:36.873Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -208070,11 +208070,11 @@
208070 int v;
208071 if( nVal>9 && 0==sqlite3_strnicmp(zVal, "nodesize=", 9) ){
208072 v = atoi(&zVal[9]);
208073 if( v>=24 && v<=p->nPgsz-35 ) p->nNodeSize = v;
208074 rc = SQLITE_OK;
208075 }else if( nVal>11 && 0==sqlite3_strnicmp(zVal, "maxpending=", 9) ){
208076 v = atoi(&zVal[11]);
208077 if( v>=64 && v<=FTS3_MAX_PENDING_DATA ) p->nMaxPendingData = v;
208078 rc = SQLITE_OK;
208079 }else if( nVal>21 && 0==sqlite3_strnicmp(zVal,"test-no-incr-doclist=",21) ){
208080 p->bNoIncrDoclist = atoi(&zVal[21]);
@@ -261263,11 +261263,11 @@
261263 int nArg, /* Number of args */
261264 sqlite3_value **apUnused /* Function arguments */
261265 ){
261266 assert( nArg==0 );
261267 UNUSED_PARAM2(nArg, apUnused);
261268 sqlite3_result_text(pCtx, "fts5: 2025-11-25 13:58:36 d4c1d3e30b774802a7abd5f61807a690fb5be7617459f3dbd7ec1efceb6125d7", -1, SQLITE_TRANSIENT);
261269 }
261270
261271 /*
261272 ** Implementation of fts5_locale(LOCALE, TEXT) function.
261273 **
261274
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** 5804ba4874cc41b11e8bb559d5533283c289 with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468 ** [sqlite_version()] and [sqlite_source_id()].
469 */
470 #define SQLITE_VERSION "3.52.0"
471 #define SQLITE_VERSION_NUMBER 3052000
472 #define SQLITE_SOURCE_ID "2025-11-25 18:20:33 5804ba4874cc41b11e8bb559d5533283c2895d2b13316830955663575567f911"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2025-11-25T18:20:33.534Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -208070,11 +208070,11 @@
208070 int v;
208071 if( nVal>9 && 0==sqlite3_strnicmp(zVal, "nodesize=", 9) ){
208072 v = atoi(&zVal[9]);
208073 if( v>=24 && v<=p->nPgsz-35 ) p->nNodeSize = v;
208074 rc = SQLITE_OK;
208075 }else if( nVal>11 && 0==sqlite3_strnicmp(zVal, "maxpending=", 11) ){
208076 v = atoi(&zVal[11]);
208077 if( v>=64 && v<=FTS3_MAX_PENDING_DATA ) p->nMaxPendingData = v;
208078 rc = SQLITE_OK;
208079 }else if( nVal>21 && 0==sqlite3_strnicmp(zVal,"test-no-incr-doclist=",21) ){
208080 p->bNoIncrDoclist = atoi(&zVal[21]);
@@ -261263,11 +261263,11 @@
261263 int nArg, /* Number of args */
261264 sqlite3_value **apUnused /* Function arguments */
261265 ){
261266 assert( nArg==0 );
261267 UNUSED_PARAM2(nArg, apUnused);
261268 sqlite3_result_text(pCtx, "fts5: 2025-11-25 18:20:33 5804ba4874cc41b11e8bb559d5533283c2895d2b13316830955663575567f911", -1, SQLITE_TRANSIENT);
261269 }
261270
261271 /*
261272 ** Implementation of fts5_locale(LOCALE, TEXT) function.
261273 **
261274
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.52.0"
150150
#define SQLITE_VERSION_NUMBER 3052000
151
-#define SQLITE_SOURCE_ID "2025-11-25 13:58:36 d4c1d3e30b774802a7abd5f61807a690fb5be7617459f3dbd7ec1efceb6125d7"
151
+#define SQLITE_SOURCE_ID "2025-11-25 18:20:33 5804ba4874cc41b11e8bb559d5533283c2895d2b13316830955663575567f911"
152152
#define SQLITE_SCM_BRANCH "trunk"
153153
#define SQLITE_SCM_TAGS ""
154
-#define SQLITE_SCM_DATETIME "2025-11-25T13:58:36.873Z"
154
+#define SQLITE_SCM_DATETIME "2025-11-25T18:20:33.534Z"
155155
156156
/*
157157
** CAPI3REF: Run-Time Library Version Numbers
158158
** KEYWORDS: sqlite3_version sqlite3_sourceid
159159
**
160160
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.52.0"
150 #define SQLITE_VERSION_NUMBER 3052000
151 #define SQLITE_SOURCE_ID "2025-11-25 13:58:36 d4c1d3e30b774802a7abd5f61807a690fb5be7617459f3dbd7ec1efceb6125d7"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2025-11-25T13:58:36.873Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
160
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.52.0"
150 #define SQLITE_VERSION_NUMBER 3052000
151 #define SQLITE_SOURCE_ID "2025-11-25 18:20:33 5804ba4874cc41b11e8bb559d5533283c2895d2b13316830955663575567f911"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2025-11-25T18:20:33.534Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
160
+58 -18
--- src/xsystem.c
+++ src/xsystem.c
@@ -88,10 +88,12 @@
8888
#define LS_MTIME 0x004 /* -t Sort by mtime, newest first */
8989
#define LS_SIZE 0x008 /* -S Sort by size, largest first */
9090
#define LS_COMMA 0x010 /* -m Comma-separated list */
9191
#define LS_DIRONLY 0x020 /* -d Show just directory name, not content */
9292
#define LS_ALL 0x040 /* -a Show all entries */
93
+#define LS_COLOR 0x080 /* Colorize the output */
94
+#define LS_COLUMNS 0x100 /* -C Split column output */
9395
9496
/* xWrite() callback from QRF
9597
*/
9698
static int xsystem_write(void *NotUsed, const char *zText, sqlite3_int64 n){
9799
fossil_puts(zText, 0, (int)n);
@@ -138,11 +140,11 @@
138140
for(i=0; i<nList; i++){
139141
char *zFile = zPrefix ? mprintf("%s/%s",zPrefix,azList[i]) : azList[i];
140142
int mode = file_mode(zFile, ExtFILE);
141143
sqlite3_int64 sz = file_size(zFile, ExtFILE);
142144
sqlite3_int64 mtime = file_mtime(zFile, ExtFILE);
143
- sqlite3_bind_text(pStmt, 1, zFile, -1, SQLITE_TRANSIENT);
145
+ sqlite3_bind_text(pStmt, 1, azList[i], -1, SQLITE_TRANSIENT);
144146
sqlite3_bind_int64(pStmt, 2, mtime);
145147
sqlite3_bind_int64(pStmt, 3, sz);
146148
sqlite3_bind_int(pStmt, 4, mode);
147149
sqlite3_bind_int64(pStmt, 5, strlen(zFile));
148150
/* TODO: wcwidth()------^^^^^^ */
@@ -173,11 +175,11 @@
173175
if( mFlags & LS_REVERSE ) i += 3;
174176
return zSortTypes[i];
175177
}
176178
177179
/*
178
-** colorize_fn(fn,mode)
180
+** color(fn,mode)
179181
**
180182
** SQL function to colorize a filename based on its mode.
181183
*/
182184
static void colorNameFunc(
183185
sqlite3_context *context,
@@ -201,12 +203,22 @@
201203
}
202204
sqlite3_str_appendall(pOut, zName);
203205
if( (iMode & 040100)!=0 ){
204206
sqlite3_str_appendall(pOut, "\033[0m");
205207
}
206
- sqlite3_result_text(context, sqlite3_str_finish(pOut), -1, sqlite3_free);
208
+ sqlite3_result_text(context, sqlite3_str_value(pOut), -1, SQLITE_TRANSIENT);
209
+ sqlite3_str_free(pOut);
210
+}
211
+/* Alternative implementation that does *not* introduce color */
212
+static void nocolorNameFunc(
213
+ sqlite3_context *context,
214
+ int argc,
215
+ sqlite3_value **argv
216
+){
217
+ sqlite3_result_value(context, argv[0]);
207218
}
219
+
208220
209221
210222
/*
211223
** Show ls output information for content in the LS table
212224
*/
@@ -213,11 +225,15 @@
213225
static void xsystem_ls_render(
214226
sqlite3 *db,
215227
int mFlags
216228
){
217229
sqlite3_stmt *pStmt;
218
- sqlite3_create_function(db, "color", 2, SQLITE_UTF8, 0, colorNameFunc,0,0);
230
+ if( mFlags & LS_COLOR ){
231
+ sqlite3_create_function(db, "color",2,SQLITE_UTF8,0,colorNameFunc,0,0);
232
+ }else{
233
+ sqlite3_create_function(db, "color",2,SQLITE_UTF8,0,nocolorNameFunc,0,0);
234
+ }
219235
if( (mFlags & LS_LONG)!=0 ){
220236
/* Long mode */
221237
char *zSql;
222238
int szSz = 8;
223239
sqlite3_prepare_v2(db, "SELECT length(max(size)) FROM ls", -1, &pStmt, 0);
@@ -295,14 +311,16 @@
295311
char *zSql;
296312
memset(&spec, 0, sizeof(spec));
297313
spec.iVersion = 1;
298314
spec.xWrite = xsystem_write;
299315
spec.eStyle = QRF_STYLE_Column;
300
- spec.bSplitColumn = QRF_Yes;
301316
spec.bTitles = QRF_No;
302317
spec.eEsc = QRF_No;
303
- spec.nScreenWidth = terminal_get_width(80);
318
+ if( mFlags & LS_COLUMNS ){
319
+ spec.nScreenWidth = terminal_get_width(80);
320
+ spec.bSplitColumn = QRF_Yes;
321
+ }
304322
zSql = mprintf("SELECT color(fn,mode) FROM ls ORDER BY %s",
305323
xsystem_ls_orderby(mFlags));
306324
sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
307325
fossil_free(zSql);
308326
sqlite3_format_query_result(pStmt, &spec, 0);
@@ -313,10 +331,12 @@
313331
314332
/* List files "ls"
315333
** Options:
316334
**
317335
** -a Show files that begin with "."
336
+** -C List by colums
337
+** --color=WHEN Colorize output?
318338
** -d Show just directory names, not content
319339
** -l Long listing
320340
** -m Comma-separated list
321341
** -r Reverse sort
322342
** -S Sort by size, largest first
@@ -327,10 +347,11 @@
327347
sqlite3 *db;
328348
sqlite3_stmt *pStmt = 0;
329349
int mFlags = 0;
330350
int nFile = 0;
331351
int nDir = 0;
352
+ int bAutoColor = 1;
332353
int needBlankLine = 0;
333354
rc = sqlite3_open(":memory:", &db);
334355
if( rc || db==0 ){
335356
fossil_fatal("Cannot open in-memory database");
336357
}
@@ -341,22 +362,35 @@
341362
fossil_fatal("Cannot prepare INSERT statement");
342363
}
343364
for(i=1; i<argc; i++){
344365
const char *z = argv[i];
345366
if( z[0]=='-' ){
346
- int k;
347
- for(k=1; z[k]; k++){
348
- switch( z[k] ){
349
- case 'a': mFlags |= LS_ALL; break;
350
- case 'd': mFlags |= LS_DIRONLY; break;
351
- case 'l': mFlags |= LS_LONG; break;
352
- case 'm': mFlags |= LS_COMMA; break;
353
- case 'r': mFlags |= LS_REVERSE; break;
354
- case 'S': mFlags |= LS_SIZE; break;
355
- case 't': mFlags |= LS_MTIME; break;
356
- default: {
357
- fossil_fatal("unknown option: -%c", z[k]);
367
+ if( z[1]=='-' ){
368
+ if( strncmp(z,"--color",7)==0 ){
369
+ if( z[7]==0 || strcmp(&z[7],"=always")==0 ){
370
+ mFlags |= LS_COLOR;
371
+ }else if( strcmp(&z[7],"=never")==0 ){
372
+ bAutoColor = 0;
373
+ }
374
+ }else{
375
+ fossil_fatal("unknown option: %s", z);
376
+ }
377
+ }else{
378
+ int k;
379
+ for(k=1; z[k]; k++){
380
+ switch( z[k] ){
381
+ case 'a': mFlags |= LS_ALL; break;
382
+ case 'd': mFlags |= LS_DIRONLY; break;
383
+ case 'l': mFlags |= LS_LONG; break;
384
+ case 'm': mFlags |= LS_COMMA; break;
385
+ case 'r': mFlags |= LS_REVERSE; break;
386
+ case 'S': mFlags |= LS_SIZE; break;
387
+ case 't': mFlags |= LS_MTIME; break;
388
+ case 'C': mFlags |= LS_COLUMNS; break;
389
+ default: {
390
+ fossil_fatal("unknown option: -%c", z[k]);
391
+ }
358392
}
359393
}
360394
}
361395
}else{
362396
if( (mFlags & LS_DIRONLY)==0 && file_isdir(z, ExtFILE)==1 ){
@@ -364,10 +398,14 @@
364398
}else{
365399
nFile++;
366400
xsystem_ls_insert(pStmt, z, mFlags);
367401
}
368402
}
403
+ }
404
+ if( fossil_isatty(1) ){
405
+ if( bAutoColor ) mFlags |= LS_COLOR;
406
+ mFlags |= LS_COLUMNS;
369407
}
370408
if( nFile>0 ){
371409
xsystem_ls_render(db, mFlags);
372410
needBlankLine = 1;
373411
}else if( nDir==0 ){
@@ -407,16 +445,18 @@
407445
},
408446
{ "ls", xsystem_ls,
409447
"[OPTIONS] [PATH] ...\n"
410448
"Options:\n"
411449
" -a Show files that begin with '.'\n"
450
+ " -C Split columns\n"
412451
" -d Show just directory names, not content\n"
413452
" -l Long listing\n"
414453
" -m Comma-separated list\n"
415454
" -r Reverse sort order\n"
416455
" -S Sort by size, largest first\n"
417456
" -t Sort by mtime, newest first\n"
457
+ " --color[=WHEN] Colorize output?\n"
418458
},
419459
{ "pwd", xsystem_pwd,
420460
"\n"
421461
"Show the Present Working Directory name\n"
422462
},
423463
--- src/xsystem.c
+++ src/xsystem.c
@@ -88,10 +88,12 @@
88 #define LS_MTIME 0x004 /* -t Sort by mtime, newest first */
89 #define LS_SIZE 0x008 /* -S Sort by size, largest first */
90 #define LS_COMMA 0x010 /* -m Comma-separated list */
91 #define LS_DIRONLY 0x020 /* -d Show just directory name, not content */
92 #define LS_ALL 0x040 /* -a Show all entries */
 
 
93
94 /* xWrite() callback from QRF
95 */
96 static int xsystem_write(void *NotUsed, const char *zText, sqlite3_int64 n){
97 fossil_puts(zText, 0, (int)n);
@@ -138,11 +140,11 @@
138 for(i=0; i<nList; i++){
139 char *zFile = zPrefix ? mprintf("%s/%s",zPrefix,azList[i]) : azList[i];
140 int mode = file_mode(zFile, ExtFILE);
141 sqlite3_int64 sz = file_size(zFile, ExtFILE);
142 sqlite3_int64 mtime = file_mtime(zFile, ExtFILE);
143 sqlite3_bind_text(pStmt, 1, zFile, -1, SQLITE_TRANSIENT);
144 sqlite3_bind_int64(pStmt, 2, mtime);
145 sqlite3_bind_int64(pStmt, 3, sz);
146 sqlite3_bind_int(pStmt, 4, mode);
147 sqlite3_bind_int64(pStmt, 5, strlen(zFile));
148 /* TODO: wcwidth()------^^^^^^ */
@@ -173,11 +175,11 @@
173 if( mFlags & LS_REVERSE ) i += 3;
174 return zSortTypes[i];
175 }
176
177 /*
178 ** colorize_fn(fn,mode)
179 **
180 ** SQL function to colorize a filename based on its mode.
181 */
182 static void colorNameFunc(
183 sqlite3_context *context,
@@ -201,12 +203,22 @@
201 }
202 sqlite3_str_appendall(pOut, zName);
203 if( (iMode & 040100)!=0 ){
204 sqlite3_str_appendall(pOut, "\033[0m");
205 }
206 sqlite3_result_text(context, sqlite3_str_finish(pOut), -1, sqlite3_free);
 
 
 
 
 
 
 
 
 
207 }
 
208
209
210 /*
211 ** Show ls output information for content in the LS table
212 */
@@ -213,11 +225,15 @@
213 static void xsystem_ls_render(
214 sqlite3 *db,
215 int mFlags
216 ){
217 sqlite3_stmt *pStmt;
218 sqlite3_create_function(db, "color", 2, SQLITE_UTF8, 0, colorNameFunc,0,0);
 
 
 
 
219 if( (mFlags & LS_LONG)!=0 ){
220 /* Long mode */
221 char *zSql;
222 int szSz = 8;
223 sqlite3_prepare_v2(db, "SELECT length(max(size)) FROM ls", -1, &pStmt, 0);
@@ -295,14 +311,16 @@
295 char *zSql;
296 memset(&spec, 0, sizeof(spec));
297 spec.iVersion = 1;
298 spec.xWrite = xsystem_write;
299 spec.eStyle = QRF_STYLE_Column;
300 spec.bSplitColumn = QRF_Yes;
301 spec.bTitles = QRF_No;
302 spec.eEsc = QRF_No;
303 spec.nScreenWidth = terminal_get_width(80);
 
 
 
304 zSql = mprintf("SELECT color(fn,mode) FROM ls ORDER BY %s",
305 xsystem_ls_orderby(mFlags));
306 sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
307 fossil_free(zSql);
308 sqlite3_format_query_result(pStmt, &spec, 0);
@@ -313,10 +331,12 @@
313
314 /* List files "ls"
315 ** Options:
316 **
317 ** -a Show files that begin with "."
 
 
318 ** -d Show just directory names, not content
319 ** -l Long listing
320 ** -m Comma-separated list
321 ** -r Reverse sort
322 ** -S Sort by size, largest first
@@ -327,10 +347,11 @@
327 sqlite3 *db;
328 sqlite3_stmt *pStmt = 0;
329 int mFlags = 0;
330 int nFile = 0;
331 int nDir = 0;
 
332 int needBlankLine = 0;
333 rc = sqlite3_open(":memory:", &db);
334 if( rc || db==0 ){
335 fossil_fatal("Cannot open in-memory database");
336 }
@@ -341,22 +362,35 @@
341 fossil_fatal("Cannot prepare INSERT statement");
342 }
343 for(i=1; i<argc; i++){
344 const char *z = argv[i];
345 if( z[0]=='-' ){
346 int k;
347 for(k=1; z[k]; k++){
348 switch( z[k] ){
349 case 'a': mFlags |= LS_ALL; break;
350 case 'd': mFlags |= LS_DIRONLY; break;
351 case 'l': mFlags |= LS_LONG; break;
352 case 'm': mFlags |= LS_COMMA; break;
353 case 'r': mFlags |= LS_REVERSE; break;
354 case 'S': mFlags |= LS_SIZE; break;
355 case 't': mFlags |= LS_MTIME; break;
356 default: {
357 fossil_fatal("unknown option: -%c", z[k]);
 
 
 
 
 
 
 
 
 
 
 
 
 
358 }
359 }
360 }
361 }else{
362 if( (mFlags & LS_DIRONLY)==0 && file_isdir(z, ExtFILE)==1 ){
@@ -364,10 +398,14 @@
364 }else{
365 nFile++;
366 xsystem_ls_insert(pStmt, z, mFlags);
367 }
368 }
 
 
 
 
369 }
370 if( nFile>0 ){
371 xsystem_ls_render(db, mFlags);
372 needBlankLine = 1;
373 }else if( nDir==0 ){
@@ -407,16 +445,18 @@
407 },
408 { "ls", xsystem_ls,
409 "[OPTIONS] [PATH] ...\n"
410 "Options:\n"
411 " -a Show files that begin with '.'\n"
 
412 " -d Show just directory names, not content\n"
413 " -l Long listing\n"
414 " -m Comma-separated list\n"
415 " -r Reverse sort order\n"
416 " -S Sort by size, largest first\n"
417 " -t Sort by mtime, newest first\n"
 
418 },
419 { "pwd", xsystem_pwd,
420 "\n"
421 "Show the Present Working Directory name\n"
422 },
423
--- src/xsystem.c
+++ src/xsystem.c
@@ -88,10 +88,12 @@
88 #define LS_MTIME 0x004 /* -t Sort by mtime, newest first */
89 #define LS_SIZE 0x008 /* -S Sort by size, largest first */
90 #define LS_COMMA 0x010 /* -m Comma-separated list */
91 #define LS_DIRONLY 0x020 /* -d Show just directory name, not content */
92 #define LS_ALL 0x040 /* -a Show all entries */
93 #define LS_COLOR 0x080 /* Colorize the output */
94 #define LS_COLUMNS 0x100 /* -C Split column output */
95
96 /* xWrite() callback from QRF
97 */
98 static int xsystem_write(void *NotUsed, const char *zText, sqlite3_int64 n){
99 fossil_puts(zText, 0, (int)n);
@@ -138,11 +140,11 @@
140 for(i=0; i<nList; i++){
141 char *zFile = zPrefix ? mprintf("%s/%s",zPrefix,azList[i]) : azList[i];
142 int mode = file_mode(zFile, ExtFILE);
143 sqlite3_int64 sz = file_size(zFile, ExtFILE);
144 sqlite3_int64 mtime = file_mtime(zFile, ExtFILE);
145 sqlite3_bind_text(pStmt, 1, azList[i], -1, SQLITE_TRANSIENT);
146 sqlite3_bind_int64(pStmt, 2, mtime);
147 sqlite3_bind_int64(pStmt, 3, sz);
148 sqlite3_bind_int(pStmt, 4, mode);
149 sqlite3_bind_int64(pStmt, 5, strlen(zFile));
150 /* TODO: wcwidth()------^^^^^^ */
@@ -173,11 +175,11 @@
175 if( mFlags & LS_REVERSE ) i += 3;
176 return zSortTypes[i];
177 }
178
179 /*
180 ** color(fn,mode)
181 **
182 ** SQL function to colorize a filename based on its mode.
183 */
184 static void colorNameFunc(
185 sqlite3_context *context,
@@ -201,12 +203,22 @@
203 }
204 sqlite3_str_appendall(pOut, zName);
205 if( (iMode & 040100)!=0 ){
206 sqlite3_str_appendall(pOut, "\033[0m");
207 }
208 sqlite3_result_text(context, sqlite3_str_value(pOut), -1, SQLITE_TRANSIENT);
209 sqlite3_str_free(pOut);
210 }
211 /* Alternative implementation that does *not* introduce color */
212 static void nocolorNameFunc(
213 sqlite3_context *context,
214 int argc,
215 sqlite3_value **argv
216 ){
217 sqlite3_result_value(context, argv[0]);
218 }
219
220
221
222 /*
223 ** Show ls output information for content in the LS table
224 */
@@ -213,11 +225,15 @@
225 static void xsystem_ls_render(
226 sqlite3 *db,
227 int mFlags
228 ){
229 sqlite3_stmt *pStmt;
230 if( mFlags & LS_COLOR ){
231 sqlite3_create_function(db, "color",2,SQLITE_UTF8,0,colorNameFunc,0,0);
232 }else{
233 sqlite3_create_function(db, "color",2,SQLITE_UTF8,0,nocolorNameFunc,0,0);
234 }
235 if( (mFlags & LS_LONG)!=0 ){
236 /* Long mode */
237 char *zSql;
238 int szSz = 8;
239 sqlite3_prepare_v2(db, "SELECT length(max(size)) FROM ls", -1, &pStmt, 0);
@@ -295,14 +311,16 @@
311 char *zSql;
312 memset(&spec, 0, sizeof(spec));
313 spec.iVersion = 1;
314 spec.xWrite = xsystem_write;
315 spec.eStyle = QRF_STYLE_Column;
 
316 spec.bTitles = QRF_No;
317 spec.eEsc = QRF_No;
318 if( mFlags & LS_COLUMNS ){
319 spec.nScreenWidth = terminal_get_width(80);
320 spec.bSplitColumn = QRF_Yes;
321 }
322 zSql = mprintf("SELECT color(fn,mode) FROM ls ORDER BY %s",
323 xsystem_ls_orderby(mFlags));
324 sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
325 fossil_free(zSql);
326 sqlite3_format_query_result(pStmt, &spec, 0);
@@ -313,10 +331,12 @@
331
332 /* List files "ls"
333 ** Options:
334 **
335 ** -a Show files that begin with "."
336 ** -C List by colums
337 ** --color=WHEN Colorize output?
338 ** -d Show just directory names, not content
339 ** -l Long listing
340 ** -m Comma-separated list
341 ** -r Reverse sort
342 ** -S Sort by size, largest first
@@ -327,10 +347,11 @@
347 sqlite3 *db;
348 sqlite3_stmt *pStmt = 0;
349 int mFlags = 0;
350 int nFile = 0;
351 int nDir = 0;
352 int bAutoColor = 1;
353 int needBlankLine = 0;
354 rc = sqlite3_open(":memory:", &db);
355 if( rc || db==0 ){
356 fossil_fatal("Cannot open in-memory database");
357 }
@@ -341,22 +362,35 @@
362 fossil_fatal("Cannot prepare INSERT statement");
363 }
364 for(i=1; i<argc; i++){
365 const char *z = argv[i];
366 if( z[0]=='-' ){
367 if( z[1]=='-' ){
368 if( strncmp(z,"--color",7)==0 ){
369 if( z[7]==0 || strcmp(&z[7],"=always")==0 ){
370 mFlags |= LS_COLOR;
371 }else if( strcmp(&z[7],"=never")==0 ){
372 bAutoColor = 0;
373 }
374 }else{
375 fossil_fatal("unknown option: %s", z);
376 }
377 }else{
378 int k;
379 for(k=1; z[k]; k++){
380 switch( z[k] ){
381 case 'a': mFlags |= LS_ALL; break;
382 case 'd': mFlags |= LS_DIRONLY; break;
383 case 'l': mFlags |= LS_LONG; break;
384 case 'm': mFlags |= LS_COMMA; break;
385 case 'r': mFlags |= LS_REVERSE; break;
386 case 'S': mFlags |= LS_SIZE; break;
387 case 't': mFlags |= LS_MTIME; break;
388 case 'C': mFlags |= LS_COLUMNS; break;
389 default: {
390 fossil_fatal("unknown option: -%c", z[k]);
391 }
392 }
393 }
394 }
395 }else{
396 if( (mFlags & LS_DIRONLY)==0 && file_isdir(z, ExtFILE)==1 ){
@@ -364,10 +398,14 @@
398 }else{
399 nFile++;
400 xsystem_ls_insert(pStmt, z, mFlags);
401 }
402 }
403 }
404 if( fossil_isatty(1) ){
405 if( bAutoColor ) mFlags |= LS_COLOR;
406 mFlags |= LS_COLUMNS;
407 }
408 if( nFile>0 ){
409 xsystem_ls_render(db, mFlags);
410 needBlankLine = 1;
411 }else if( nDir==0 ){
@@ -407,16 +445,18 @@
445 },
446 { "ls", xsystem_ls,
447 "[OPTIONS] [PATH] ...\n"
448 "Options:\n"
449 " -a Show files that begin with '.'\n"
450 " -C Split columns\n"
451 " -d Show just directory names, not content\n"
452 " -l Long listing\n"
453 " -m Comma-separated list\n"
454 " -r Reverse sort order\n"
455 " -S Sort by size, largest first\n"
456 " -t Sort by mtime, newest first\n"
457 " --color[=WHEN] Colorize output?\n"
458 },
459 { "pwd", xsystem_pwd,
460 "\n"
461 "Show the Present Working Directory name\n"
462 },
463

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button