aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/shell.c.in48
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);