# HG changeset patch # User Andre Renaud # Date 1330820269 21600 # Node ID 25617169cf49c49adf77b1aa9461d630e122d0c0 # Parent 8dc4aced2ffc87e5341d87fc5c60ebf606c45760 Add -A to ls diff -r 8dc4aced2ffc -r 25617169cf49 toys/ls.c --- a/toys/ls.c Sat Mar 03 18:17:26 2012 -0600 +++ b/toys/ls.c Sat Mar 03 18:17:49 2012 -0600 @@ -6,18 +6,19 @@ * * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html -USE_LS(NEWTOY(ls, "nRlF1a", TOYFLAG_BIN)) +USE_LS(NEWTOY(ls, "AnRlF1a", TOYFLAG_BIN)) config LS bool "ls" default n help - usage: ls [-l] [-F] [-a] [-1] [directory...] + usage: ls [-lFaA1] [directory...] list files - -F append a character as a file type indicator + -1 list one file per line -a list all files - -1 list one file per line + -A list all files except . and .. + -F append a character as a file type indicator -l show full details for each file */ @@ -37,13 +38,20 @@ #define FLAG_l 8 #define FLAG_R 16 #define FLAG_n 32 +#define FLAG_A 64 static int dir_filter(const struct dirent *d) { - /* Skip over the . & .. entries unless -a is given */ - if (!(toys.optflags & FLAG_a)) - if (d->d_name[0] == '.') + /* Skip over all '.*' entries, unless -a is given */ + if (!(toys.optflags & FLAG_a)) { + /* -A means show everything except the . & .. entries */ + if (toys.optflags & FLAG_A) { + if (strcmp(d->d_name, ".") == 0 || + strcmp(d->d_name, "..") == 0) + return 0; + } else if (d->d_name[0] == '.') return 0; + } return 1; }