-#define FMT_AUTO 0
-#define FMT_LONG 1 /* one record per line, extended info */
-#define FMT_SINGLE 2 /* one record per line */
-#define FMT_ROWS 3 /* print across rows */
-#define FMT_COLUMNS 3 /* fill columns (same, since we don't sort) */
-
-#define TIME_MOD 0
-#define TIME_CHANGE 1
-#define TIME_ACCESS 2
-
-#define DISP_FTYPE 1 /* show character for file type */
-#define DISP_EXEC 2 /* show '*' if regular executable file */
-#define DISP_HIDDEN 4 /* show files starting . (except . and ..) */
-#define DISP_DOT 8 /* show . and .. */
-#define DISP_NUMERIC 16 /* numeric uid and gid */
-#define DISP_FULLTIME 32 /* show extended time display */
-#define DIR_NOLIST 64 /* show directory as itself, not contents */
-#define DISP_DIRNAME 128 /* show directory name (for internal use) */
-#define DIR_RECURSE 256 /* -R (not yet implemented) */
-
-static unsigned char display_fmt = FMT_AUTO;
-static unsigned short opts = 0;
-static unsigned short column = 0;
-
-#ifdef BB_FEATURE_AUTOWIDTH
-static unsigned short terminal_width = 0, column_width = 0;
-#else
-#define terminal_width TERMINAL_WIDTH
-#define column_width COLUMN_WIDTH
+/* what is the overall style of the listing */
+#define STYLE_AUTO (0)
+#define STYLE_COLUMNS (1U<<21) /* fill columns */
+#define STYLE_LONG (2U<<21) /* one record per line, extended info */
+#define STYLE_SINGLE (3U<<21) /* one record per line */
+
+#define STYLE_MASK STYLE_SINGLE
+#define STYLE_ONE_RECORD_FLAG STYLE_LONG
+
+/* 51306 lrwxrwxrwx 1 root root 2 May 11 01:43 /bin/view -> vi* */
+/* what file information will be listed */
+#define LIST_INO (1U<<0)
+#define LIST_BLOCKS (1U<<1)
+#define LIST_MODEBITS (1U<<2)
+#define LIST_NLINKS (1U<<3)
+#define LIST_ID_NAME (1U<<4)
+#define LIST_ID_NUMERIC (1U<<5)
+#define LIST_SIZE (1U<<6)
+#define LIST_DEV (1U<<7)
+#define LIST_DATE_TIME (1U<<8)
+#define LIST_FULLTIME (1U<<9)
+#define LIST_FILENAME (1U<<10)
+#define LIST_SYMLINK (1U<<11)
+#define LIST_FILETYPE (1U<<12)
+#define LIST_EXEC (1U<<13)
+
+#define LIST_MASK ((LIST_EXEC << 1) - 1)
+
+/* what files will be displayed */
+/* TODO -- We may be able to make DISP_NORMAL 0 to save a bit slot. */
+#define DISP_NORMAL (1U<<14) /* show normal filenames */
+#define DISP_DIRNAME (1U<<15) /* 2 or more items? label directories */
+#define DISP_HIDDEN (1U<<16) /* show filenames starting with . */
+#define DISP_DOT (1U<<17) /* show . and .. */
+#define DISP_NOLIST (1U<<18) /* show directory as itself, not contents */
+#define DISP_RECURSIVE (1U<<19) /* show directory and everything below it */
+#define DISP_ROWS (1U<<20) /* print across rows */
+
+#define DISP_MASK (((DISP_ROWS << 1) - 1) & ~(DISP_NORMAL - 1))
+
+#ifdef CONFIG_FEATURE_LS_SORTFILES
+/* how will the files be sorted */
+#define SORT_ORDER_FORWARD 0 /* sort in reverse order */
+#define SORT_ORDER_REVERSE (1U<<27) /* sort in reverse order */
+
+#define SORT_NAME 0 /* sort by file name */
+#define SORT_SIZE (1U<<28) /* sort by file size */
+#define SORT_ATIME (2U<<28) /* sort by last access time */
+#define SORT_CTIME (3U<<28) /* sort by last change time */
+#define SORT_MTIME (4U<<28) /* sort by last modification time */
+#define SORT_VERSION (5U<<28) /* sort by version */
+#define SORT_EXT (6U<<28) /* sort by file name extension */
+#define SORT_DIR (7U<<28) /* sort by file or directory */
+
+#define SORT_MASK (7U<<28)
+#endif
+
+#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
+/* which of the three times will be used */
+#define TIME_MOD 0
+#define TIME_CHANGE (1U<<23)
+#define TIME_ACCESS (1U<<24)
+
+#define TIME_MASK (3U<<23)
+#endif
+
+#ifdef CONFIG_FEATURE_LS_FOLLOWLINKS
+#define FOLLOW_LINKS (1U<<25)
+#endif
+#ifdef CONFIG_FEATURE_HUMAN_READABLE
+#define LS_DISP_HR (1U<<26)
+#endif
+
+#define LIST_SHORT (LIST_FILENAME)
+#define LIST_ISHORT (LIST_INO | LIST_FILENAME)
+#define LIST_LONG (LIST_MODEBITS | LIST_NLINKS | LIST_ID_NAME | LIST_SIZE | \
+ LIST_DATE_TIME | LIST_FILENAME | LIST_SYMLINK)
+#define LIST_ILONG (LIST_INO | LIST_LONG)
+
+#define SPLIT_DIR 1
+#define SPLIT_FILE 0
+#define SPLIT_SUBDIR 2
+
+#define TYPEINDEX(mode) (((mode) >> 12) & 0x0f)
+#define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)])
+
+#if defined(CONFIG_FEATURE_LS_FILETYPES) || defined(CONFIG_FEATURE_LS_COLOR)
+# define APPCHAR(mode) ("\0|\0\0/\0\0\0\0\0@\0=\0\0\0" [TYPEINDEX(mode)])
+#endif
+
+/* colored LS support by JaWi, janwillem.janssen@lxtreme.nl */
+#ifdef CONFIG_FEATURE_LS_COLOR
+static int show_color = 0;
+
+#define COLOR(mode) ("\000\043\043\043\042\000\043\043"\
+ "\000\000\044\000\043\000\000\040" [TYPEINDEX(mode)])
+#define ATTR(mode) ("\00\00\01\00\01\00\01\00"\
+ "\00\00\01\00\01\00\00\01" [TYPEINDEX(mode)])