diff options
author | dan <dan@noemail.net> | 2017-12-27 21:13:21 +0000 |
---|---|---|
committer | dan <dan@noemail.net> | 2017-12-27 21:13:21 +0000 |
commit | b5090e489784941c91e559cc23e5cbe497dab52c (patch) | |
tree | defe0bef6759db3a964e332e7d7402770f89081e /src | |
parent | 5a78b81b1b5b8ab70ab61feeac7407379e3efeee (diff) | |
download | sqlite-b5090e489784941c91e559cc23e5cbe497dab52c.tar.gz sqlite-b5090e489784941c91e559cc23e5cbe497dab52c.zip |
Improve the shell tool ".ar --list --verbose" command.
FossilOrigin-Name: b64681a644c419bb98d00980a6cb56ef5a0aff5ef5321955631f0b4c88aac283
Diffstat (limited to 'src')
-rw-r--r-- | src/shell.c.in | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/src/shell.c.in b/src/shell.c.in index 15a018bb9..f7edb53f0 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -4578,11 +4578,42 @@ static void arWhereClause( } /* +** Argument zMode must point to a buffer at least 11 bytes in size. This +** function populates this buffer with the string interpretation of +** the unix file mode passed as the second argument (e.g. "drwxr-xr-x"). +*/ +static void shellModeToString(char *zMode, int mode){ + int i; + + /* Magic numbers copied from [man 2 stat] */ + if( mode & 0040000 ){ + zMode[0] = 'd'; + }else if( (mode & 0120000)==0120000 ){ + zMode[0] = 'l'; + }else{ + zMode[0] = '-'; + } + + for(i=0; i<3; i++){ + int m = (mode >> ((2-i)*3)); + char *a = &zMode[1 + i*3]; + a[0] = (m & 0x4) ? 'r' : '-'; + a[1] = (m & 0x2) ? 'w' : '-'; + a[2] = (m & 0x1) ? 'x' : '-'; + } + zMode[10] = '\0'; +} + +/* ** Implementation of .ar "lisT" command. */ static int arListCommand(ShellState *p, sqlite3 *db, ArCommand *pAr){ - const char *zSql = "SELECT name FROM %s WHERE %s"; + const char *zSql = "SELECT %s FROM %s WHERE %s"; const char *zTbl = (pAr->bZip ? "zipfile(?)" : "sqlar"); + const char *azCols[] = { + "name", + "mode, sz, datetime(mtime, 'unixepoch'), name" + }; char *zWhere = 0; sqlite3_stmt *pSql = 0; @@ -4591,12 +4622,23 @@ static int arListCommand(ShellState *p, sqlite3 *db, ArCommand *pAr){ rc = arCheckEntries(db, pAr); arWhereClause(&rc, pAr, &zWhere); - shellPreparePrintf(db, &rc, &pSql, zSql, zTbl, zWhere); + shellPreparePrintf(db, &rc, &pSql, zSql, azCols[pAr->bVerbose], zTbl, zWhere); if( rc==SQLITE_OK && pAr->bZip ){ sqlite3_bind_text(pSql, 1, pAr->zFile, -1, SQLITE_TRANSIENT); } while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){ - raw_printf(p->out, "%s\n", sqlite3_column_text(pSql, 0)); + if( pAr->bVerbose ){ + char zMode[11]; + shellModeToString(zMode, sqlite3_column_int(pSql, 0)); + + raw_printf(p->out, "%s % 10d %s %s\n", zMode, + sqlite3_column_int(pSql, 1), + sqlite3_column_text(pSql, 2), + sqlite3_column_text(pSql, 3) + ); + }else{ + raw_printf(p->out, "%s\n", sqlite3_column_text(pSql, 0)); + } } shellFinalize(&rc, pSql); |