// that compiles to 0 if everything else if turned off.
#define BB_UTILITY
//
-//This is where feature definitions go.
+//
+//
+// This is where feature definitions go. Generally speaking,
+// turning this stuff off makes things a bit smaller (and less
+// pretty/useful).
+//
+//
+//Enable init being called as /linuxrc
#define BB_FEATURE_LINUXRC
-/* Turning this off makes things a bit smaller (and less pretty) */
+// Use termios to manipulate the screen (more is much pretties with this on)
#define BB_FEATURE_USE_TERMIOS
-/* Turning this off makes things a bit smaller (and less pretty) */
+// calculate terminal & column widths
#define BB_FEATURE_AUTOWIDTH
-
-
-
-
+// show username/groupnames (bypasses libc6 NSS)
+#define BB_FEATURE_LS_USERNAME
+// show file timestamps
+#define BB_FEATURE_LS_TIMESTAMPS
+// enable ls -p and -F
+#define BB_FEATURE_LS_FILETYPES
* 1. requires lstat (BSD) - how do you do it without?
*/
-#define FEATURE_USERNAME /* show username/groupnames (bypasses libc6 NSS) */
-#define FEATURE_TIMESTAMPS /* show file timestamps */
-#define FEATURE_AUTOWIDTH /* calculate terminal & column widths */
-#define FEATURE_FILETYPECHAR /* enable -p and -F */
-
#define TERMINAL_WIDTH 80 /* use 79 if your terminal has linefold bug */
#define COLUMN_WIDTH 14 /* default if AUTOWIDTH not defined */
#define COLUMN_GAP 2 /* includes the file type char, if present */
#include <dirent.h>
#include <errno.h>
#include <stdio.h>
-#ifdef FEATURE_TIMESTAMPS
+#ifdef BB_FEATURE_LS_TIMESTAMPS
#include <time.h>
#endif
#define TYPEINDEX(mode) (((mode) >> 12) & 0x0f)
#define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)])
-#ifdef FEATURE_FILETYPECHAR
+#ifdef BB_FEATURE_LS_FILETYPES
#define APPCHAR(mode) ("\0|\0\0/\0\0\0\0\0@\0=\0\0\0" [TYPEINDEX(mode)])
#endif
static unsigned short opts = 0;
static unsigned short column = 0;
-#ifdef FEATURE_AUTOWIDTH
+#ifdef BB_FEATURE_AUTOWIDTH
static unsigned short terminal_width = 0, column_width = 0;
#else
#define terminal_width TERMINAL_WIDTH
#define column_width COLUMN_WIDTH
#endif
-#ifdef FEATURE_TIMESTAMPS
+#ifdef BB_FEATURE_LS_TIMESTAMPS
static unsigned char time_fmt = TIME_MOD;
#endif
#undef nspaces
}
-#ifdef FEATURE_FILETYPECHAR
+#ifdef BB_FEATURE_LS_FILETYPES
static char append_char(mode_t mode)
{
if (!(opts & DISP_FTYPE))
{
char scratch[PATH_MAX];
short len = strlen(name);
-#ifdef FEATURE_FILETYPECHAR
+#ifdef BB_FEATURE_LS_FILETYPES
char append = append_char(info->st_mode);
#endif
column=10;
writenum((long)info->st_nlink,(short)5);
fputs(" ", stdout);
-#ifdef FEATURE_USERNAME
+#ifdef BB_FEATURE_LS_USERNAME
if (!(opts & DISP_NUMERIC)) {
scratch[8]='\0';
my_getpwuid( scratch, info->st_uid);
#endif
writenum((long)info->st_uid,(short)0);
tab(16);
-#ifdef FEATURE_USERNAME
+#ifdef BB_FEATURE_LS_USERNAME
if (!(opts & DISP_NUMERIC)) {
scratch[8]='\0';
my_getgrgid( scratch, info->st_gid);
else
writenum((long)info->st_size,(short)8);
fputs(" ", stdout);
-#ifdef FEATURE_TIMESTAMPS
+#ifdef BB_FEATURE_LS_TIMESTAMPS
{
time_t cal;
char *string;
wr(" -> ", 4);
len = readlink(fullname, scratch, sizeof scratch);
if (len > 0) fwrite(scratch, 1, len, stdout);
-#ifdef FEATURE_FILETYPECHAR
+#ifdef BB_FEATURE_LS_FILETYPES
/* show type of destination */
if (opts & DISP_FTYPE) {
if (!stat(fullname, info)) {
}
#endif
}
-#ifdef FEATURE_FILETYPECHAR
+#ifdef BB_FEATURE_LS_FILETYPES
else if (append)
wr(&append, 1);
#endif
newline();
else {
if (nexttab + column_width > terminal_width
-#ifndef FEATURE_AUTOWIDTH
+#ifndef BB_FEATURE_AUTOWIDTH
|| nexttab + len >= terminal_width
#endif
)
tab(nexttab);
}
/* work out where next column starts */
-#ifdef FEATURE_AUTOWIDTH
+#ifdef BB_FEATURE_AUTOWIDTH
/* we know the calculated width is big enough */
nexttab = column + column_width + COLUMN_GAP;
#else
/* now write the data */
wr(name, len);
column = column + len;
-#ifdef FEATURE_FILETYPECHAR
+#ifdef BB_FEATURE_LS_FILETYPES
if (append)
wr(&append, 1), column++;
#endif
dir = opendir(name);
if (!dir) goto listerr;
-#ifdef FEATURE_AUTOWIDTH
+#ifdef BB_FEATURE_AUTOWIDTH
column_width = 0;
while ((entry = readdir(dir)) != NULL) {
short w = strlen(entry->d_name);
}
static const char ls_usage[] = "ls [-1a"
-#ifdef FEATURE_TIMESTAMPS
+#ifdef BB_FEATURE_LS_TIMESTAMPS
"c"
#endif
"d"
-#ifdef FEATURE_TIMESTAMPS
+#ifdef BB_FEATURE_LS_TIMESTAMPS
"e"
#endif
"ln"
-#ifdef FEATURE_FILETYPECHAR
+#ifdef BB_FEATURE_LS_FILETYPES
"p"
#endif
-#ifdef FEATURE_TIMESTAMPS
+#ifdef BB_FEATURE_LS_TIMESTAMPS
"u"
#endif
"xAC"
-#ifdef FEATURE_FILETYPECHAR
+#ifdef BB_FEATURE_LS_FILETYPES
"F"
#endif
#ifdef FEATURE_RECURSIVE
case '1': display_fmt = FMT_SINGLE; break;
case 'x': display_fmt = FMT_ROWS; break;
case 'C': display_fmt = FMT_COLUMNS; break;
-#ifdef FEATURE_FILETYPECHAR
+#ifdef BB_FEATURE_LS_FILETYPES
case 'p': opts |= DISP_FTYPE; break;
case 'F': opts |= DISP_FTYPE|DISP_EXEC; break;
#endif
#ifdef FEATURE_RECURSIVE
case 'R': opts |= DIR_RECURSE; break;
#endif
-#ifdef FEATURE_TIMESTAMPS
+#ifdef BB_FEATURE_LS_TIMESTAMPS
case 'u': time_fmt = TIME_ACCESS; break;
case 'c': time_fmt = TIME_CHANGE; break;
case 'e': opts |= DISP_FULLTIME; break;
display_fmt = isatty(fileno(stdout)) ? FMT_COLUMNS : FMT_SINGLE;
if (argi < argc - 1)
opts |= DISP_DIRNAME; /* 2 or more items? label directories */
-#ifdef FEATURE_AUTOWIDTH
+#ifdef BB_FEATURE_AUTOWIDTH
/* could add a -w option and/or TIOCGWINSZ call */
if (terminal_width < 1) terminal_width = TERMINAL_WIDTH;
* 1. requires lstat (BSD) - how do you do it without?
*/
-#define FEATURE_USERNAME /* show username/groupnames (bypasses libc6 NSS) */
-#define FEATURE_TIMESTAMPS /* show file timestamps */
-#define FEATURE_AUTOWIDTH /* calculate terminal & column widths */
-#define FEATURE_FILETYPECHAR /* enable -p and -F */
-
#define TERMINAL_WIDTH 80 /* use 79 if your terminal has linefold bug */
#define COLUMN_WIDTH 14 /* default if AUTOWIDTH not defined */
#define COLUMN_GAP 2 /* includes the file type char, if present */
#include <dirent.h>
#include <errno.h>
#include <stdio.h>
-#ifdef FEATURE_TIMESTAMPS
+#ifdef BB_FEATURE_LS_TIMESTAMPS
#include <time.h>
#endif
#define TYPEINDEX(mode) (((mode) >> 12) & 0x0f)
#define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)])
-#ifdef FEATURE_FILETYPECHAR
+#ifdef BB_FEATURE_LS_FILETYPES
#define APPCHAR(mode) ("\0|\0\0/\0\0\0\0\0@\0=\0\0\0" [TYPEINDEX(mode)])
#endif
static unsigned short opts = 0;
static unsigned short column = 0;
-#ifdef FEATURE_AUTOWIDTH
+#ifdef BB_FEATURE_AUTOWIDTH
static unsigned short terminal_width = 0, column_width = 0;
#else
#define terminal_width TERMINAL_WIDTH
#define column_width COLUMN_WIDTH
#endif
-#ifdef FEATURE_TIMESTAMPS
+#ifdef BB_FEATURE_LS_TIMESTAMPS
static unsigned char time_fmt = TIME_MOD;
#endif
#undef nspaces
}
-#ifdef FEATURE_FILETYPECHAR
+#ifdef BB_FEATURE_LS_FILETYPES
static char append_char(mode_t mode)
{
if (!(opts & DISP_FTYPE))
{
char scratch[PATH_MAX];
short len = strlen(name);
-#ifdef FEATURE_FILETYPECHAR
+#ifdef BB_FEATURE_LS_FILETYPES
char append = append_char(info->st_mode);
#endif
column=10;
writenum((long)info->st_nlink,(short)5);
fputs(" ", stdout);
-#ifdef FEATURE_USERNAME
+#ifdef BB_FEATURE_LS_USERNAME
if (!(opts & DISP_NUMERIC)) {
scratch[8]='\0';
my_getpwuid( scratch, info->st_uid);
#endif
writenum((long)info->st_uid,(short)0);
tab(16);
-#ifdef FEATURE_USERNAME
+#ifdef BB_FEATURE_LS_USERNAME
if (!(opts & DISP_NUMERIC)) {
scratch[8]='\0';
my_getgrgid( scratch, info->st_gid);
else
writenum((long)info->st_size,(short)8);
fputs(" ", stdout);
-#ifdef FEATURE_TIMESTAMPS
+#ifdef BB_FEATURE_LS_TIMESTAMPS
{
time_t cal;
char *string;
wr(" -> ", 4);
len = readlink(fullname, scratch, sizeof scratch);
if (len > 0) fwrite(scratch, 1, len, stdout);
-#ifdef FEATURE_FILETYPECHAR
+#ifdef BB_FEATURE_LS_FILETYPES
/* show type of destination */
if (opts & DISP_FTYPE) {
if (!stat(fullname, info)) {
}
#endif
}
-#ifdef FEATURE_FILETYPECHAR
+#ifdef BB_FEATURE_LS_FILETYPES
else if (append)
wr(&append, 1);
#endif
newline();
else {
if (nexttab + column_width > terminal_width
-#ifndef FEATURE_AUTOWIDTH
+#ifndef BB_FEATURE_AUTOWIDTH
|| nexttab + len >= terminal_width
#endif
)
tab(nexttab);
}
/* work out where next column starts */
-#ifdef FEATURE_AUTOWIDTH
+#ifdef BB_FEATURE_AUTOWIDTH
/* we know the calculated width is big enough */
nexttab = column + column_width + COLUMN_GAP;
#else
/* now write the data */
wr(name, len);
column = column + len;
-#ifdef FEATURE_FILETYPECHAR
+#ifdef BB_FEATURE_LS_FILETYPES
if (append)
wr(&append, 1), column++;
#endif
dir = opendir(name);
if (!dir) goto listerr;
-#ifdef FEATURE_AUTOWIDTH
+#ifdef BB_FEATURE_AUTOWIDTH
column_width = 0;
while ((entry = readdir(dir)) != NULL) {
short w = strlen(entry->d_name);
}
static const char ls_usage[] = "ls [-1a"
-#ifdef FEATURE_TIMESTAMPS
+#ifdef BB_FEATURE_LS_TIMESTAMPS
"c"
#endif
"d"
-#ifdef FEATURE_TIMESTAMPS
+#ifdef BB_FEATURE_LS_TIMESTAMPS
"e"
#endif
"ln"
-#ifdef FEATURE_FILETYPECHAR
+#ifdef BB_FEATURE_LS_FILETYPES
"p"
#endif
-#ifdef FEATURE_TIMESTAMPS
+#ifdef BB_FEATURE_LS_TIMESTAMPS
"u"
#endif
"xAC"
-#ifdef FEATURE_FILETYPECHAR
+#ifdef BB_FEATURE_LS_FILETYPES
"F"
#endif
#ifdef FEATURE_RECURSIVE
case '1': display_fmt = FMT_SINGLE; break;
case 'x': display_fmt = FMT_ROWS; break;
case 'C': display_fmt = FMT_COLUMNS; break;
-#ifdef FEATURE_FILETYPECHAR
+#ifdef BB_FEATURE_LS_FILETYPES
case 'p': opts |= DISP_FTYPE; break;
case 'F': opts |= DISP_FTYPE|DISP_EXEC; break;
#endif
#ifdef FEATURE_RECURSIVE
case 'R': opts |= DIR_RECURSE; break;
#endif
-#ifdef FEATURE_TIMESTAMPS
+#ifdef BB_FEATURE_LS_TIMESTAMPS
case 'u': time_fmt = TIME_ACCESS; break;
case 'c': time_fmt = TIME_CHANGE; break;
case 'e': opts |= DISP_FULLTIME; break;
display_fmt = isatty(fileno(stdout)) ? FMT_COLUMNS : FMT_SINGLE;
if (argi < argc - 1)
opts |= DISP_DIRNAME; /* 2 or more items? label directories */
-#ifdef FEATURE_AUTOWIDTH
+#ifdef BB_FEATURE_AUTOWIDTH
/* could add a -w option and/or TIOCGWINSZ call */
if (terminal_width < 1) terminal_width = TERMINAL_WIDTH;