* 1. requires lstat (BSD) - how do you do it without?
*/
-static const int TERMINAL_WIDTH = 80; /* use 79 if your terminal has linefold bug */
-static const int COLUMN_WIDTH = 14; /* default if AUTOWIDTH not defined */
-static const int COLUMN_GAP = 2; /* includes the file type char, if present */
+enum {
+ TERMINAL_WIDTH = 80, /* use 79 if terminal has linefold bug */
+ COLUMN_WIDTH = 14, /* default if AUTOWIDTH not defined */
+ COLUMN_GAP = 2, /* includes the file type char */
+};
+
/************************************************************************/
static unsigned short column = 0;
#ifdef BB_FEATURE_AUTOWIDTH
-static unsigned short terminal_width;
-static unsigned short column_width;
-static unsigned short tabstops;
+static unsigned short terminal_width = TERMINAL_WIDTH;
+static unsigned short column_width = COLUMN_WIDTH;
+static unsigned short tabstops = COLUMN_GAP;
#else
static unsigned short column_width = COLUMN_WIDTH;
#endif
((list_fmt & LIST_INO) ? 8 : 0) +
((list_fmt & LIST_BLOCKS) ? 5 : 0)
;
- if (column_width < len) column_width= len;
+ if (column_width < len)
+ column_width= len;
+ }
+ if (column_width >= 6)
+ ncols = (int)(terminal_width / (column_width + COLUMN_GAP));
+ else {
+ ncols = 1;
+ column_width = COLUMN_WIDTH;
}
- ncols= (int)(terminal_width / (column_width + COLUMN_GAP));
#else
ncols= TERMINAL_WIDTH;
#endif
break;
}
- nrows= nfiles / ncols;
+ if (ncols > 1) {
+ nrows = nfiles / ncols;
+ } else {
+ nrows = nfiles;
+ ncols = 1;
+ }
if ((nrows * ncols) < nfiles) nrows++; /* round up fractionals */
if (nrows > nfiles) nrows= nfiles;
case LIST_ID_NAME:
#ifdef BB_FEATURE_LS_USERNAME
my_getpwuid(scratch, dn->dstat.st_uid);
- if (*scratch)
- printf("%-8.8s ", scratch);
- else
- printf("%-8d ", dn->dstat.st_uid);
+ printf("%-8.8s ", scratch);
my_getgrgid(scratch, dn->dstat.st_gid);
- if (*scratch)
- printf("%-8.8s", scratch);
- else
- printf("%-8d", dn->dstat.st_gid);
+ printf("%-8.8s", scratch);
column += 17;
break;
#endif
* 1. requires lstat (BSD) - how do you do it without?
*/
-static const int TERMINAL_WIDTH = 80; /* use 79 if your terminal has linefold bug */
-static const int COLUMN_WIDTH = 14; /* default if AUTOWIDTH not defined */
-static const int COLUMN_GAP = 2; /* includes the file type char, if present */
+enum {
+ TERMINAL_WIDTH = 80, /* use 79 if terminal has linefold bug */
+ COLUMN_WIDTH = 14, /* default if AUTOWIDTH not defined */
+ COLUMN_GAP = 2, /* includes the file type char */
+};
+
/************************************************************************/
static unsigned short column = 0;
#ifdef BB_FEATURE_AUTOWIDTH
-static unsigned short terminal_width;
-static unsigned short column_width;
-static unsigned short tabstops;
+static unsigned short terminal_width = TERMINAL_WIDTH;
+static unsigned short column_width = COLUMN_WIDTH;
+static unsigned short tabstops = COLUMN_GAP;
#else
static unsigned short column_width = COLUMN_WIDTH;
#endif
((list_fmt & LIST_INO) ? 8 : 0) +
((list_fmt & LIST_BLOCKS) ? 5 : 0)
;
- if (column_width < len) column_width= len;
+ if (column_width < len)
+ column_width= len;
+ }
+ if (column_width >= 6)
+ ncols = (int)(terminal_width / (column_width + COLUMN_GAP));
+ else {
+ ncols = 1;
+ column_width = COLUMN_WIDTH;
}
- ncols= (int)(terminal_width / (column_width + COLUMN_GAP));
#else
ncols= TERMINAL_WIDTH;
#endif
break;
}
- nrows= nfiles / ncols;
+ if (ncols > 1) {
+ nrows = nfiles / ncols;
+ } else {
+ nrows = nfiles;
+ ncols = 1;
+ }
if ((nrows * ncols) < nfiles) nrows++; /* round up fractionals */
if (nrows > nfiles) nrows= nfiles;
case LIST_ID_NAME:
#ifdef BB_FEATURE_LS_USERNAME
my_getpwuid(scratch, dn->dstat.st_uid);
- if (*scratch)
- printf("%-8.8s ", scratch);
- else
- printf("%-8d ", dn->dstat.st_uid);
+ printf("%-8.8s ", scratch);
my_getgrgid(scratch, dn->dstat.st_gid);
- if (*scratch)
- printf("%-8.8s", scratch);
- else
- printf("%-8d", dn->dstat.st_gid);
+ printf("%-8.8s", scratch);
column += 17;
break;
#endif
myuser = getpwnam(name);
if (myuser==NULL)
- error_msg_and_die( "unknown username: %s\n", name);
+ return(-1);
return myuser->pw_uid;
}
mygroup = getgrnam(name);
if (mygroup==NULL)
- error_msg_and_die( "unknown group: %s\n", name);
+ return(-1);
return (mygroup->gr_gid);
}
myuser = getpwuid(uid);
if (myuser==NULL)
- error_msg_and_die( "unknown uid %ld\n", (long)uid);
-
- strcpy(name, myuser->pw_name);
+ sprintf(name, "%-8ld ", (long)uid);
+ else
+ strcpy(name, myuser->pw_name);
}
/* gets a groupname given a gid */
mygroup = getgrgid(gid);
if (mygroup==NULL)
- error_msg_and_die( "unknown gid %ld\n", (long)gid);
-
- strcpy(group, mygroup->gr_name);
+ sprintf(group, "%-8ld ", (long)gid);
+ else
+ strcpy(group, mygroup->gr_name);
}
#if defined BB_ID