Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3e2bb288da | ||
|
|
add0158554 | ||
|
|
3d8dbe1ca0 | ||
|
|
50d6360771 | ||
|
|
fbb39c83b6 | ||
|
|
07e5297ca7 | ||
|
|
dc6301e7ca |
No files matched your search
@@ -1,3 +1,25 @@
|
||||
0.34
|
||||
* ls -l now displays lnik names outside the current directory,
|
||||
Patch thanks to Eric Delaunay
|
||||
* init now properly handles sparc serial consoles and does a
|
||||
better job of finding the real consol device rather than using
|
||||
/dev/console which doesn't support job control. Patch also
|
||||
thanks to Eric Delaunay.
|
||||
* more started to read from stdin after the last file was finished, and
|
||||
options were not parsed correctly (fix thanks to Eric Delaunay).
|
||||
* more will now use the terminal size if BB_FEATURE_AUTOWIDTH is on.
|
||||
* rm wouldn't remove a symlink unless the symlink was valid. This was
|
||||
a side effect of the busybox 0.32 recursiveAction() fix. Things
|
||||
should now work correctly.
|
||||
* grep wouldn't grep stdin. Now it does.
|
||||
* sed wouldn't sed stdin. Now it does.
|
||||
* sed was appending a \n to the end of lines with replacements.
|
||||
Now it doesn't do that.
|
||||
* ls -l now bypasses libc6 nss when displaying user/group names.
|
||||
Now uses my_getpwuid and my_getgrgid.
|
||||
|
||||
-Erik Andersen
|
||||
|
||||
0.33
|
||||
* Fixed a bug where init could hang instead of rebooting.
|
||||
* Removed some debugging noise from init.c
|
||||
@@ -8,6 +30,8 @@
|
||||
state the real root device name)
|
||||
* merged some redundant code from mtab.c/df.c into utility.c
|
||||
|
||||
-Erik Andersen
|
||||
|
||||
0.32
|
||||
* More changes -- many thanks to Lineo for paying me to work on
|
||||
busybox. If you have any problems please let me know ASAP
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
|
||||
PROG=busybox
|
||||
VERSION=0.33
|
||||
VERSION=0.34
|
||||
BUILDTIME=$(shell date "+%Y%m%d-%H%M")
|
||||
|
||||
# Comment out the following to make a debuggable build
|
||||
|
||||
+12
-3
@@ -35,6 +35,16 @@
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
|
||||
/* Note that tar.c expects TRUE and FALSE to be defined
|
||||
* exactly the opposite of how they are used everywhere else.
|
||||
* Some time this should be integrated a bit better, but this
|
||||
* does the job for now.
|
||||
*/
|
||||
#undef FALSE
|
||||
#undef TRUE
|
||||
#define FALSE ((int) 0)
|
||||
#define TRUE ((int) 1)
|
||||
|
||||
|
||||
static const char tar_usage[] =
|
||||
"tar -[cxtvOf] [tarFileName] [FILE] ...\n"
|
||||
@@ -169,10 +179,9 @@ extern int tar_main (int argc, char **argv)
|
||||
/*
|
||||
* Parse the options.
|
||||
*/
|
||||
options = *argv++;
|
||||
argc--;
|
||||
|
||||
if (**argv == '-') {
|
||||
options = (*argv++) + 1;
|
||||
argc--;
|
||||
for (; *options; options++) {
|
||||
switch (*options) {
|
||||
case 'f':
|
||||
|
||||
+13
-14
@@ -2,7 +2,6 @@
|
||||
* This file is parsed by sed. You MUST use single line comments.
|
||||
* IE //#define BB_BLAH
|
||||
*/
|
||||
|
||||
#define BB_BUSYBOX
|
||||
#define BB_CAT
|
||||
#define BB_CHMOD_CHOWN_CHGRP
|
||||
@@ -13,53 +12,53 @@
|
||||
#define BB_DD
|
||||
#define BB_DF
|
||||
#define BB_DMESG
|
||||
//#define BB_DUTMP
|
||||
//#define BB_FDFLUSH
|
||||
#define BB_DUTMP
|
||||
#define BB_FDFLUSH
|
||||
#define BB_FIND
|
||||
#define BB_FSCK_MINIX
|
||||
#define BB_MKFS_MINIX
|
||||
#define BB_CHVT
|
||||
#define BB_DEALLOCVT
|
||||
#define BB_GREP
|
||||
//#define BB_HALT
|
||||
#define BB_HALT
|
||||
#define BB_INIT
|
||||
#define BB_KILL
|
||||
//#define BB_LENGTH
|
||||
#define BB_LENGTH
|
||||
#define BB_LN
|
||||
#define BB_LOADFONT
|
||||
#define BB_LOADKMAP
|
||||
#define BB_LS
|
||||
//#define BB_MAKEDEVS
|
||||
//#define BB_MATH
|
||||
#define BB_MAKEDEVS
|
||||
#define BB_MATH
|
||||
#define BB_MKDIR
|
||||
#define BB_MKNOD
|
||||
#define BB_MKSWAP
|
||||
//#define BB_MNC
|
||||
#define BB_MNC
|
||||
#define BB_MORE
|
||||
#define BB_MOUNT
|
||||
//#define BB_MT
|
||||
//#define BB_MTAB
|
||||
#define BB_MT
|
||||
#define BB_MTAB
|
||||
#define BB_MV
|
||||
//#define BB_PRINTF
|
||||
#define BB_PRINTF
|
||||
#define BB_PS
|
||||
#define BB_PWD
|
||||
#define BB_REGEXP
|
||||
#define BB_REBOOT
|
||||
#define BB_RM
|
||||
#define BB_RMDIR
|
||||
//#define BB_SFDISK
|
||||
#define BB_SFDISK
|
||||
#define BB_SED
|
||||
#define BB_SLEEP
|
||||
#define BB_SWAPONOFF
|
||||
#define BB_SYNC
|
||||
#define BB_TAR
|
||||
#define BB_TOUCH
|
||||
//#define BB_TRUE_FALSE // Supplied by ash
|
||||
#define BB_TRUE_FALSE
|
||||
#define BB_UMOUNT
|
||||
#define BB_UPDATE
|
||||
#define BB_UNAME
|
||||
#define BB_ZCAT
|
||||
//#define BB_GZIP
|
||||
#define BB_GZIP
|
||||
// Don't turn BB_UTILITY off. It contains support code
|
||||
// that compiles to 0 if everything else if turned off.
|
||||
#define BB_UTILITY
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
Name: busybox
|
||||
Version: 0.32
|
||||
Version: 0.33
|
||||
Release: 1
|
||||
Group: System/Utilities
|
||||
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
|
||||
@@ -7,7 +7,7 @@ Copyright: GPL
|
||||
Packager : Erik Andersen <andersen@lineo.com>
|
||||
Conflicts: fileutils grep shellutils
|
||||
Buildroot: /tmp/%{Name}-%{Version}
|
||||
Source: busybox-0.32.tar.gz
|
||||
Source: busybox-%{Version}.tar.gz
|
||||
|
||||
%Description
|
||||
BusyBox is a suite of "tiny" Unix utilities in a multi-call binary. It
|
||||
|
||||
+18
-53
@@ -40,7 +40,7 @@
|
||||
* 1. requires lstat (BSD) - how do you do it without?
|
||||
*/
|
||||
|
||||
//#define FEATURE_USERNAME /* show username/groupnames (libc6 uses NSS) */
|
||||
#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 */
|
||||
@@ -64,10 +64,6 @@
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#ifdef FEATURE_USERNAME
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#endif
|
||||
#ifdef FEATURE_TIMESTAMPS
|
||||
#include <time.h>
|
||||
#endif
|
||||
@@ -83,27 +79,6 @@
|
||||
#define MINOR(dev) ((dev)&0xff)
|
||||
#endif
|
||||
|
||||
#define MODE1 "rwxrwxrwx"
|
||||
#define MODE0 "---------"
|
||||
#define SMODE1 "..s..s..t"
|
||||
#define SMODE0 "..S..S..T"
|
||||
|
||||
/* The 9 mode bits to test */
|
||||
|
||||
static const mode_t MBIT[] = {
|
||||
S_IRUSR, S_IWUSR, S_IXUSR,
|
||||
S_IRGRP, S_IWGRP, S_IXGRP,
|
||||
S_IROTH, S_IWOTH, S_IXOTH
|
||||
};
|
||||
|
||||
/* The special bits. If set, display SMODE0/1 instead of MODE0/1 */
|
||||
|
||||
static const mode_t SBIT[] = {
|
||||
0, 0, S_ISUID,
|
||||
0, 0, S_ISGID,
|
||||
0, 0, S_ISVTX
|
||||
};
|
||||
|
||||
#define FMT_AUTO 0
|
||||
#define FMT_LONG 1 /* one record per line, extended info */
|
||||
#define FMT_SINGLE 2 /* one record per line */
|
||||
@@ -206,7 +181,7 @@ static char append_char(mode_t mode)
|
||||
**
|
||||
**/
|
||||
|
||||
static void list_single(const char *name, struct stat *info)
|
||||
static void list_single(const char *name, struct stat *info, const char *fullname)
|
||||
{
|
||||
char scratch[PATH_MAX];
|
||||
short len = strlen(name);
|
||||
@@ -216,45 +191,35 @@ static void list_single(const char *name, struct stat *info)
|
||||
|
||||
if (display_fmt == FMT_LONG) {
|
||||
mode_t mode = info->st_mode;
|
||||
int i;
|
||||
|
||||
scratch[0] = TYPECHAR(mode);
|
||||
for (i=0; i<9; i++)
|
||||
if (mode & SBIT[i])
|
||||
scratch[i+1] = (mode & MBIT[i])
|
||||
? SMODE1[i]
|
||||
: SMODE0[i];
|
||||
else
|
||||
scratch[i+1] = (mode & MBIT[i])
|
||||
? MODE1[i]
|
||||
: MODE0[i];
|
||||
newline();
|
||||
wr(scratch, 10);
|
||||
wr(modeString(mode), 10);
|
||||
column=10;
|
||||
writenum((long)info->st_nlink,(short)4);
|
||||
writenum((long)info->st_nlink,(short)5);
|
||||
fputs(" ", stdout);
|
||||
#ifdef FEATURE_USERNAME
|
||||
if (!(opts & DISP_NUMERIC)) {
|
||||
struct passwd *pw = getpwuid(info->st_uid);
|
||||
if (pw)
|
||||
fputs(pw->pw_name, stdout);
|
||||
scratch[8]='\0';
|
||||
my_getpwuid( scratch, info->st_uid);
|
||||
if (*scratch)
|
||||
fputs(scratch, stdout);
|
||||
else
|
||||
writenum((long)info->st_uid,(short)0);
|
||||
} else
|
||||
#endif
|
||||
writenum((long)info->st_uid,(short)0);
|
||||
tab(24);
|
||||
tab(16);
|
||||
#ifdef FEATURE_USERNAME
|
||||
if (!(opts & DISP_NUMERIC)) {
|
||||
struct group *gr = getgrgid(info->st_gid);
|
||||
if (gr)
|
||||
fputs(gr->gr_name, stdout);
|
||||
scratch[8]='\0';
|
||||
my_getgrgid( scratch, info->st_gid);
|
||||
if (*scratch)
|
||||
fputs(scratch, stdout);
|
||||
else
|
||||
writenum((long)info->st_gid,(short)0);
|
||||
} else
|
||||
#endif
|
||||
writenum((long)info->st_gid,(short)0);
|
||||
tab(33);
|
||||
tab(17);
|
||||
if (S_ISBLK(mode) || S_ISCHR(mode)) {
|
||||
writenum((long)MAJOR(info->st_rdev),(short)3);
|
||||
fputs(", ", stdout);
|
||||
@@ -297,12 +262,12 @@ static void list_single(const char *name, struct stat *info)
|
||||
wr(name, len);
|
||||
if (S_ISLNK(mode)) {
|
||||
wr(" -> ", 4);
|
||||
len = readlink(name, scratch, sizeof scratch);
|
||||
len = readlink(fullname, scratch, sizeof scratch);
|
||||
if (len > 0) fwrite(scratch, 1, len, stdout);
|
||||
#ifdef FEATURE_FILETYPECHAR
|
||||
/* show type of destination */
|
||||
if (opts & DISP_FTYPE) {
|
||||
if (!stat(name, info)) {
|
||||
if (!stat(fullname, info)) {
|
||||
append = append_char(info->st_mode);
|
||||
if (append)
|
||||
fputc(append, stdout);
|
||||
@@ -372,7 +337,7 @@ static int list_item(const char *name)
|
||||
|
||||
if (!S_ISDIR(info.st_mode) ||
|
||||
(opts & DIR_NOLIST)) {
|
||||
list_single(name, &info);
|
||||
list_single(name, &info, name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -424,7 +389,7 @@ static int list_item(const char *name)
|
||||
strcpy(fnend, entry->d_name);
|
||||
if (lstat(fullname, &info))
|
||||
goto direrr; /* (shouldn't fail) */
|
||||
list_single(entry->d_name, &info);
|
||||
list_single(entry->d_name, &info, fullname);
|
||||
}
|
||||
closedir(dir);
|
||||
return 0;
|
||||
|
||||
+1
-1
@@ -84,7 +84,7 @@ extern int rm_main(int argc, char **argv)
|
||||
|
||||
while (argc-- > 0) {
|
||||
srcName = *(argv++);
|
||||
if (recursiveAction( srcName, recursiveFlag, TRUE, TRUE,
|
||||
if (recursiveAction( srcName, recursiveFlag, FALSE, TRUE,
|
||||
fileAction, dirAction) == FALSE) {
|
||||
exit( FALSE);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ static const char dutmp_usage[] = "dutmp\n"
|
||||
"\tDump file or stdin utmp file format to stdout, pipe delimited.\n"
|
||||
"\tdutmp /var/run/utmp\n";
|
||||
|
||||
static int dutmp_main (int argc, char **argv)
|
||||
extern int dutmp_main (int argc, char **argv)
|
||||
{
|
||||
|
||||
FILE *f = stdin;
|
||||
|
||||
+37
-35
@@ -45,9 +45,23 @@ static const char sed_usage[] =
|
||||
#else
|
||||
"This version of sed matches strings (not full regexps).\n";
|
||||
#endif
|
||||
|
||||
|
||||
static void do_sed(FILE *fp, char *needle, char *newNeedle, int ignoreCase, int printFlag, int quietFlag)
|
||||
{
|
||||
int foundOne=FALSE;
|
||||
char haystack[1024];
|
||||
|
||||
|
||||
while (fgets (haystack, 1023, fp)) {
|
||||
foundOne = replace_match(haystack, needle, newNeedle, ignoreCase);
|
||||
if (foundOne==TRUE && printFlag==TRUE) {
|
||||
fprintf(stdout, haystack);
|
||||
}
|
||||
if (quietFlag==FALSE) {
|
||||
fprintf(stdout, haystack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern int sed_main (int argc, char **argv)
|
||||
{
|
||||
@@ -56,11 +70,9 @@ extern int sed_main (int argc, char **argv)
|
||||
char *name;
|
||||
char *cp;
|
||||
int ignoreCase=FALSE;
|
||||
int foundOne=FALSE;
|
||||
int printFlag=FALSE;
|
||||
int quietFlag=FALSE;
|
||||
int stopNow;
|
||||
char *haystack;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
@@ -73,24 +85,23 @@ extern int sed_main (int argc, char **argv)
|
||||
cp = *argv++;
|
||||
stopNow=FALSE;
|
||||
|
||||
while (*++cp && stopNow==FALSE)
|
||||
while (*++cp && stopNow==FALSE) {
|
||||
switch (*cp) {
|
||||
case 'n':
|
||||
quietFlag = TRUE;
|
||||
break;
|
||||
case 'e':
|
||||
if (*(cp+1)==0 && --argc < 0) {
|
||||
fprintf(stderr, "A\n");
|
||||
usage( sed_usage);
|
||||
}
|
||||
cp = *argv++;
|
||||
if ( *++cp != 's')
|
||||
cp = *argv++;
|
||||
while( *cp ) {
|
||||
if (*cp == 's' && strlen(cp) > 3 && *(cp+1) == '/') {
|
||||
char* pos=needle=cp+2;
|
||||
for(;;) {
|
||||
pos = strchr(pos, '/');
|
||||
if (pos==NULL) {
|
||||
fprintf(stderr, "B\n");
|
||||
usage( sed_usage);
|
||||
}
|
||||
if (*(pos-1) == '\\') {
|
||||
@@ -104,7 +115,6 @@ extern int sed_main (int argc, char **argv)
|
||||
for(;;) {
|
||||
pos = strchr(pos, '/');
|
||||
if (pos==NULL) {
|
||||
fprintf(stderr, "C\n");
|
||||
usage( sed_usage);
|
||||
}
|
||||
if (*(pos-1) == '\\') {
|
||||
@@ -116,7 +126,6 @@ extern int sed_main (int argc, char **argv)
|
||||
*pos=0;
|
||||
if (pos+2 != 0) {
|
||||
while (*++pos) {
|
||||
fprintf(stderr, "pos='%s'\n", pos);
|
||||
switch (*pos) {
|
||||
case 'i':
|
||||
ignoreCase=TRUE;
|
||||
@@ -134,42 +143,35 @@ extern int sed_main (int argc, char **argv)
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
fprintf(stderr, "replace '%s' with '%s'\n", needle, newNeedle);
|
||||
//fprintf(stderr, "replace '%s' with '%s'\n", needle, newNeedle);
|
||||
stopNow=TRUE;
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "D\n");
|
||||
usage(sed_usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (argc-- > 0) {
|
||||
name = *argv++;
|
||||
if (argc==0) {
|
||||
do_sed( stdin, needle, newNeedle, ignoreCase, printFlag, quietFlag);
|
||||
} else {
|
||||
while (argc-- > 0) {
|
||||
name = *argv++;
|
||||
|
||||
fp = fopen (name, "r");
|
||||
if (fp == NULL) {
|
||||
perror (name);
|
||||
continue;
|
||||
fp = fopen (name, "r");
|
||||
if (fp == NULL) {
|
||||
perror (name);
|
||||
continue;
|
||||
}
|
||||
|
||||
do_sed( fp, needle, newNeedle, ignoreCase, printFlag, quietFlag);
|
||||
|
||||
if (ferror (fp))
|
||||
perror (name);
|
||||
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
haystack = (char*)malloc( 1024);
|
||||
while (fgets (haystack, 1023, fp)) {
|
||||
|
||||
foundOne = replace_match(haystack, needle, newNeedle, ignoreCase);
|
||||
if (foundOne==TRUE && printFlag==TRUE)
|
||||
fputs (haystack, stdout);
|
||||
if (quietFlag==FALSE)
|
||||
fputs (haystack, stdout);
|
||||
/* Avoid any mem leaks */
|
||||
free(haystack);
|
||||
haystack = (char*)malloc( BUF_SIZE);
|
||||
}
|
||||
|
||||
if (ferror (fp))
|
||||
perror (name);
|
||||
|
||||
fclose (fp);
|
||||
}
|
||||
exit( TRUE);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Name: busybox
|
||||
Version: 0.32
|
||||
Version: 0.33
|
||||
Release: 1
|
||||
Group: System/Utilities
|
||||
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
|
||||
@@ -7,7 +7,7 @@ Copyright: GPL
|
||||
Packager : Erik Andersen <andersen@lineo.com>
|
||||
Conflicts: fileutils grep shellutils
|
||||
Buildroot: /tmp/%{Name}-%{Version}
|
||||
Source: busybox-0.32.tar.gz
|
||||
Source: busybox-%{Version}.tar.gz
|
||||
|
||||
%Description
|
||||
BusyBox is a suite of "tiny" Unix utilities in a multi-call binary. It
|
||||
|
||||
+47
-37
@@ -40,21 +40,46 @@ static const char grep_usage[] =
|
||||
#if defined BB_REGEXP
|
||||
"This version of grep matches full regexps.\n";
|
||||
#else
|
||||
"This version of grep matches strings (not full regexps).\n";
|
||||
"This version of grep matches strings (not regexps).\n";
|
||||
#endif
|
||||
|
||||
|
||||
static void do_grep(FILE *fp, char* needle, char *fileName, int tellName, int ignoreCase, int tellLine)
|
||||
{
|
||||
char *cp;
|
||||
long line = 0;
|
||||
char haystack[BUF_SIZE];
|
||||
|
||||
while (fgets (haystack, sizeof (haystack), fp)) {
|
||||
line++;
|
||||
cp = &haystack[strlen (haystack) - 1];
|
||||
|
||||
if (*cp != '\n')
|
||||
fprintf (stderr, "%s: Line too long\n", fileName);
|
||||
|
||||
if (find_match(haystack, needle, ignoreCase) == TRUE) {
|
||||
if (tellName==TRUE)
|
||||
printf ("%s:", fileName);
|
||||
|
||||
if (tellLine==TRUE)
|
||||
printf ("%ld:", line);
|
||||
|
||||
fputs (haystack, stdout);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extern int grep_main (int argc, char **argv)
|
||||
{
|
||||
FILE *fp;
|
||||
char *needle;
|
||||
char *name;
|
||||
char *cp;
|
||||
int tellName=TRUE;
|
||||
char *needle;
|
||||
char *fileName;
|
||||
int tellName=FALSE;
|
||||
int ignoreCase=FALSE;
|
||||
int tellLine=FALSE;
|
||||
long line;
|
||||
char haystack[BUF_SIZE];
|
||||
|
||||
|
||||
ignoreCase = FALSE;
|
||||
tellLine = FALSE;
|
||||
@@ -76,7 +101,7 @@ extern int grep_main (int argc, char **argv)
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
tellName = FALSE;
|
||||
tellName = TRUE;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
@@ -91,39 +116,24 @@ extern int grep_main (int argc, char **argv)
|
||||
needle = *argv++;
|
||||
argc--;
|
||||
|
||||
while (argc-- > 0) {
|
||||
name = *argv++;
|
||||
if (argc==0) {
|
||||
do_grep( stdin, needle, "stdin", FALSE, ignoreCase, tellLine);
|
||||
} else {
|
||||
while (argc-- > 0) {
|
||||
fileName = *argv++;
|
||||
|
||||
fp = fopen (name, "r");
|
||||
if (fp == NULL) {
|
||||
perror (name);
|
||||
continue;
|
||||
}
|
||||
|
||||
line = 0;
|
||||
|
||||
while (fgets (haystack, sizeof (haystack), fp)) {
|
||||
line++;
|
||||
cp = &haystack[strlen (haystack) - 1];
|
||||
|
||||
if (*cp != '\n')
|
||||
fprintf (stderr, "%s: Line too long\n", name);
|
||||
|
||||
if (find_match(haystack, needle, ignoreCase) == TRUE) {
|
||||
if (tellName==TRUE)
|
||||
printf ("%s: ", name);
|
||||
|
||||
if (tellLine==TRUE)
|
||||
printf ("%ld: ", line);
|
||||
|
||||
fputs (haystack, stdout);
|
||||
fp = fopen (fileName, "r");
|
||||
if (fp == NULL) {
|
||||
perror (fileName);
|
||||
continue;
|
||||
}
|
||||
|
||||
do_grep( fp, needle, fileName, tellName, ignoreCase, tellLine);
|
||||
|
||||
if (ferror (fp))
|
||||
perror (fileName);
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
if (ferror (fp))
|
||||
perror (name);
|
||||
|
||||
fclose (fp);
|
||||
}
|
||||
exit( TRUE);
|
||||
}
|
||||
|
||||
@@ -40,21 +40,46 @@ static const char grep_usage[] =
|
||||
#if defined BB_REGEXP
|
||||
"This version of grep matches full regexps.\n";
|
||||
#else
|
||||
"This version of grep matches strings (not full regexps).\n";
|
||||
"This version of grep matches strings (not regexps).\n";
|
||||
#endif
|
||||
|
||||
|
||||
static void do_grep(FILE *fp, char* needle, char *fileName, int tellName, int ignoreCase, int tellLine)
|
||||
{
|
||||
char *cp;
|
||||
long line = 0;
|
||||
char haystack[BUF_SIZE];
|
||||
|
||||
while (fgets (haystack, sizeof (haystack), fp)) {
|
||||
line++;
|
||||
cp = &haystack[strlen (haystack) - 1];
|
||||
|
||||
if (*cp != '\n')
|
||||
fprintf (stderr, "%s: Line too long\n", fileName);
|
||||
|
||||
if (find_match(haystack, needle, ignoreCase) == TRUE) {
|
||||
if (tellName==TRUE)
|
||||
printf ("%s:", fileName);
|
||||
|
||||
if (tellLine==TRUE)
|
||||
printf ("%ld:", line);
|
||||
|
||||
fputs (haystack, stdout);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extern int grep_main (int argc, char **argv)
|
||||
{
|
||||
FILE *fp;
|
||||
char *needle;
|
||||
char *name;
|
||||
char *cp;
|
||||
int tellName=TRUE;
|
||||
char *needle;
|
||||
char *fileName;
|
||||
int tellName=FALSE;
|
||||
int ignoreCase=FALSE;
|
||||
int tellLine=FALSE;
|
||||
long line;
|
||||
char haystack[BUF_SIZE];
|
||||
|
||||
|
||||
ignoreCase = FALSE;
|
||||
tellLine = FALSE;
|
||||
@@ -76,7 +101,7 @@ extern int grep_main (int argc, char **argv)
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
tellName = FALSE;
|
||||
tellName = TRUE;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
@@ -91,39 +116,24 @@ extern int grep_main (int argc, char **argv)
|
||||
needle = *argv++;
|
||||
argc--;
|
||||
|
||||
while (argc-- > 0) {
|
||||
name = *argv++;
|
||||
if (argc==0) {
|
||||
do_grep( stdin, needle, "stdin", FALSE, ignoreCase, tellLine);
|
||||
} else {
|
||||
while (argc-- > 0) {
|
||||
fileName = *argv++;
|
||||
|
||||
fp = fopen (name, "r");
|
||||
if (fp == NULL) {
|
||||
perror (name);
|
||||
continue;
|
||||
}
|
||||
|
||||
line = 0;
|
||||
|
||||
while (fgets (haystack, sizeof (haystack), fp)) {
|
||||
line++;
|
||||
cp = &haystack[strlen (haystack) - 1];
|
||||
|
||||
if (*cp != '\n')
|
||||
fprintf (stderr, "%s: Line too long\n", name);
|
||||
|
||||
if (find_match(haystack, needle, ignoreCase) == TRUE) {
|
||||
if (tellName==TRUE)
|
||||
printf ("%s: ", name);
|
||||
|
||||
if (tellLine==TRUE)
|
||||
printf ("%ld: ", line);
|
||||
|
||||
fputs (haystack, stdout);
|
||||
fp = fopen (fileName, "r");
|
||||
if (fp == NULL) {
|
||||
perror (fileName);
|
||||
continue;
|
||||
}
|
||||
|
||||
do_grep( fp, needle, fileName, tellName, ignoreCase, tellLine);
|
||||
|
||||
if (ferror (fp))
|
||||
perror (fileName);
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
if (ferror (fp))
|
||||
perror (name);
|
||||
|
||||
fclose (fp);
|
||||
}
|
||||
exit( TRUE);
|
||||
}
|
||||
|
||||
@@ -88,8 +88,14 @@ void message(int device, char *fmt, ...)
|
||||
|
||||
/* Take full control of the log tty, and never close it.
|
||||
* It's mine, all mine! Muhahahaha! */
|
||||
if (log_fd==-1) {
|
||||
if ((log_fd = device_open(log, O_RDWR|O_NDELAY)) < 0) {
|
||||
if (log_fd < 0) {
|
||||
if (log == NULL) {
|
||||
/* don't even try to log, because there is no such console */
|
||||
log_fd = -2;
|
||||
/* log to main console instead */
|
||||
device = CONSOLE;
|
||||
}
|
||||
else if ((log_fd = device_open(log, O_RDWR|O_NDELAY)) < 0) {
|
||||
log_fd=-1;
|
||||
fprintf(stderr, "Bummer, can't write to log on %s!\r\n", log);
|
||||
fflush(stderr);
|
||||
@@ -97,7 +103,7 @@ void message(int device, char *fmt, ...)
|
||||
}
|
||||
}
|
||||
|
||||
if ( (device & LOG) && (log_fd != -1) ) {
|
||||
if ( (device & LOG) && (log_fd >= 0) ) {
|
||||
va_start(arguments, fmt);
|
||||
vdprintf(log_fd, fmt, arguments);
|
||||
va_end(arguments);
|
||||
@@ -180,25 +186,40 @@ static void console_init()
|
||||
int fd;
|
||||
int tried_devcons = 0;
|
||||
int tried_vtprimary = 0;
|
||||
struct serial_struct sr;
|
||||
char *s;
|
||||
|
||||
if ((s = getenv("CONSOLE")) != NULL) {
|
||||
console = s;
|
||||
/* Apparently the sparc does wierd things... */
|
||||
#if defined (__sparc__)
|
||||
if (strncmp( s, "/dev/tty", 8 )==0) {
|
||||
switch( s[8]) {
|
||||
case 'a':
|
||||
s=SERIAL_CON0;
|
||||
break;
|
||||
case 'b':
|
||||
s=SERIAL_CON1;
|
||||
}
|
||||
}
|
||||
}
|
||||
#if #cpu(sparc)
|
||||
/* sparc kernel supports console=tty[ab] parameter which is also
|
||||
* passed to init, so catch it here */
|
||||
else if ((s = getenv("console")) != NULL) {
|
||||
/* remap tty[ab] to /dev/ttyS[01] */
|
||||
if (strcmp( s, "ttya" )==0)
|
||||
console = SERIAL_CON0;
|
||||
else if (strcmp( s, "ttyb" )==0)
|
||||
console = SERIAL_CON1;
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
console = VT_CONSOLE;
|
||||
tried_devcons++;
|
||||
else {
|
||||
struct vt_stat vt;
|
||||
static char the_console[13];
|
||||
|
||||
console = the_console;
|
||||
/* 2.2 kernels: identify the real console backend and try to use it */
|
||||
if (ioctl(0,TIOCGSERIAL,&sr) == 0) {
|
||||
/* this is a serial console */
|
||||
snprintf( the_console, sizeof the_console, "/dev/ttyS%d", sr.line );
|
||||
}
|
||||
else if (ioctl(0, VT_GETSTATE, &vt) == 0) {
|
||||
/* this is linux virtual tty */
|
||||
snprintf( the_console, sizeof the_console, "/dev/tty%d", vt.v_active );
|
||||
} else {
|
||||
console = VT_CONSOLE;
|
||||
tried_devcons++;
|
||||
}
|
||||
}
|
||||
|
||||
while ((fd = open(console, O_RDONLY | O_NONBLOCK)) < 0) {
|
||||
@@ -219,8 +240,15 @@ static void console_init()
|
||||
if (fd < 0)
|
||||
/* Perhaps we should panic here? */
|
||||
console = "/dev/null";
|
||||
else
|
||||
else {
|
||||
/* check for serial console and disable logging to tty3 & running a
|
||||
* shell to tty2 */
|
||||
if (ioctl(0,TIOCGSERIAL,&sr) == 0) {
|
||||
log = NULL;
|
||||
second_console = NULL;
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
message(LOG, "console=%s\n", console );
|
||||
}
|
||||
|
||||
@@ -472,7 +500,7 @@ extern int init_main(int argc, char **argv)
|
||||
if (pid1 == 0 && tty0_commands) {
|
||||
pid1 = run(tty0_commands, console, wait_for_enter);
|
||||
}
|
||||
if (pid2 == 0 && tty1_commands) {
|
||||
if (pid2 == 0 && tty1_commands && second_console) {
|
||||
pid2 = run(tty1_commands, second_console, TRUE);
|
||||
}
|
||||
wpid = wait(&status);
|
||||
|
||||
+47
-19
@@ -88,8 +88,14 @@ void message(int device, char *fmt, ...)
|
||||
|
||||
/* Take full control of the log tty, and never close it.
|
||||
* It's mine, all mine! Muhahahaha! */
|
||||
if (log_fd==-1) {
|
||||
if ((log_fd = device_open(log, O_RDWR|O_NDELAY)) < 0) {
|
||||
if (log_fd < 0) {
|
||||
if (log == NULL) {
|
||||
/* don't even try to log, because there is no such console */
|
||||
log_fd = -2;
|
||||
/* log to main console instead */
|
||||
device = CONSOLE;
|
||||
}
|
||||
else if ((log_fd = device_open(log, O_RDWR|O_NDELAY)) < 0) {
|
||||
log_fd=-1;
|
||||
fprintf(stderr, "Bummer, can't write to log on %s!\r\n", log);
|
||||
fflush(stderr);
|
||||
@@ -97,7 +103,7 @@ void message(int device, char *fmt, ...)
|
||||
}
|
||||
}
|
||||
|
||||
if ( (device & LOG) && (log_fd != -1) ) {
|
||||
if ( (device & LOG) && (log_fd >= 0) ) {
|
||||
va_start(arguments, fmt);
|
||||
vdprintf(log_fd, fmt, arguments);
|
||||
va_end(arguments);
|
||||
@@ -180,25 +186,40 @@ static void console_init()
|
||||
int fd;
|
||||
int tried_devcons = 0;
|
||||
int tried_vtprimary = 0;
|
||||
struct serial_struct sr;
|
||||
char *s;
|
||||
|
||||
if ((s = getenv("CONSOLE")) != NULL) {
|
||||
console = s;
|
||||
/* Apparently the sparc does wierd things... */
|
||||
#if defined (__sparc__)
|
||||
if (strncmp( s, "/dev/tty", 8 )==0) {
|
||||
switch( s[8]) {
|
||||
case 'a':
|
||||
s=SERIAL_CON0;
|
||||
break;
|
||||
case 'b':
|
||||
s=SERIAL_CON1;
|
||||
}
|
||||
}
|
||||
}
|
||||
#if #cpu(sparc)
|
||||
/* sparc kernel supports console=tty[ab] parameter which is also
|
||||
* passed to init, so catch it here */
|
||||
else if ((s = getenv("console")) != NULL) {
|
||||
/* remap tty[ab] to /dev/ttyS[01] */
|
||||
if (strcmp( s, "ttya" )==0)
|
||||
console = SERIAL_CON0;
|
||||
else if (strcmp( s, "ttyb" )==0)
|
||||
console = SERIAL_CON1;
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
console = VT_CONSOLE;
|
||||
tried_devcons++;
|
||||
else {
|
||||
struct vt_stat vt;
|
||||
static char the_console[13];
|
||||
|
||||
console = the_console;
|
||||
/* 2.2 kernels: identify the real console backend and try to use it */
|
||||
if (ioctl(0,TIOCGSERIAL,&sr) == 0) {
|
||||
/* this is a serial console */
|
||||
snprintf( the_console, sizeof the_console, "/dev/ttyS%d", sr.line );
|
||||
}
|
||||
else if (ioctl(0, VT_GETSTATE, &vt) == 0) {
|
||||
/* this is linux virtual tty */
|
||||
snprintf( the_console, sizeof the_console, "/dev/tty%d", vt.v_active );
|
||||
} else {
|
||||
console = VT_CONSOLE;
|
||||
tried_devcons++;
|
||||
}
|
||||
}
|
||||
|
||||
while ((fd = open(console, O_RDONLY | O_NONBLOCK)) < 0) {
|
||||
@@ -219,8 +240,15 @@ static void console_init()
|
||||
if (fd < 0)
|
||||
/* Perhaps we should panic here? */
|
||||
console = "/dev/null";
|
||||
else
|
||||
else {
|
||||
/* check for serial console and disable logging to tty3 & running a
|
||||
* shell to tty2 */
|
||||
if (ioctl(0,TIOCGSERIAL,&sr) == 0) {
|
||||
log = NULL;
|
||||
second_console = NULL;
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
message(LOG, "console=%s\n", console );
|
||||
}
|
||||
|
||||
@@ -472,7 +500,7 @@ extern int init_main(int argc, char **argv)
|
||||
if (pid1 == 0 && tty0_commands) {
|
||||
pid1 = run(tty0_commands, console, wait_for_enter);
|
||||
}
|
||||
if (pid2 == 0 && tty1_commands) {
|
||||
if (pid2 == 0 && tty1_commands && second_console) {
|
||||
pid2 = run(tty1_commands, second_console, TRUE);
|
||||
}
|
||||
wpid = wait(&status);
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
* 1. requires lstat (BSD) - how do you do it without?
|
||||
*/
|
||||
|
||||
//#define FEATURE_USERNAME /* show username/groupnames (libc6 uses NSS) */
|
||||
#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 */
|
||||
@@ -64,10 +64,6 @@
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#ifdef FEATURE_USERNAME
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#endif
|
||||
#ifdef FEATURE_TIMESTAMPS
|
||||
#include <time.h>
|
||||
#endif
|
||||
@@ -83,27 +79,6 @@
|
||||
#define MINOR(dev) ((dev)&0xff)
|
||||
#endif
|
||||
|
||||
#define MODE1 "rwxrwxrwx"
|
||||
#define MODE0 "---------"
|
||||
#define SMODE1 "..s..s..t"
|
||||
#define SMODE0 "..S..S..T"
|
||||
|
||||
/* The 9 mode bits to test */
|
||||
|
||||
static const mode_t MBIT[] = {
|
||||
S_IRUSR, S_IWUSR, S_IXUSR,
|
||||
S_IRGRP, S_IWGRP, S_IXGRP,
|
||||
S_IROTH, S_IWOTH, S_IXOTH
|
||||
};
|
||||
|
||||
/* The special bits. If set, display SMODE0/1 instead of MODE0/1 */
|
||||
|
||||
static const mode_t SBIT[] = {
|
||||
0, 0, S_ISUID,
|
||||
0, 0, S_ISGID,
|
||||
0, 0, S_ISVTX
|
||||
};
|
||||
|
||||
#define FMT_AUTO 0
|
||||
#define FMT_LONG 1 /* one record per line, extended info */
|
||||
#define FMT_SINGLE 2 /* one record per line */
|
||||
@@ -206,7 +181,7 @@ static char append_char(mode_t mode)
|
||||
**
|
||||
**/
|
||||
|
||||
static void list_single(const char *name, struct stat *info)
|
||||
static void list_single(const char *name, struct stat *info, const char *fullname)
|
||||
{
|
||||
char scratch[PATH_MAX];
|
||||
short len = strlen(name);
|
||||
@@ -216,45 +191,35 @@ static void list_single(const char *name, struct stat *info)
|
||||
|
||||
if (display_fmt == FMT_LONG) {
|
||||
mode_t mode = info->st_mode;
|
||||
int i;
|
||||
|
||||
scratch[0] = TYPECHAR(mode);
|
||||
for (i=0; i<9; i++)
|
||||
if (mode & SBIT[i])
|
||||
scratch[i+1] = (mode & MBIT[i])
|
||||
? SMODE1[i]
|
||||
: SMODE0[i];
|
||||
else
|
||||
scratch[i+1] = (mode & MBIT[i])
|
||||
? MODE1[i]
|
||||
: MODE0[i];
|
||||
newline();
|
||||
wr(scratch, 10);
|
||||
wr(modeString(mode), 10);
|
||||
column=10;
|
||||
writenum((long)info->st_nlink,(short)4);
|
||||
writenum((long)info->st_nlink,(short)5);
|
||||
fputs(" ", stdout);
|
||||
#ifdef FEATURE_USERNAME
|
||||
if (!(opts & DISP_NUMERIC)) {
|
||||
struct passwd *pw = getpwuid(info->st_uid);
|
||||
if (pw)
|
||||
fputs(pw->pw_name, stdout);
|
||||
scratch[8]='\0';
|
||||
my_getpwuid( scratch, info->st_uid);
|
||||
if (*scratch)
|
||||
fputs(scratch, stdout);
|
||||
else
|
||||
writenum((long)info->st_uid,(short)0);
|
||||
} else
|
||||
#endif
|
||||
writenum((long)info->st_uid,(short)0);
|
||||
tab(24);
|
||||
tab(16);
|
||||
#ifdef FEATURE_USERNAME
|
||||
if (!(opts & DISP_NUMERIC)) {
|
||||
struct group *gr = getgrgid(info->st_gid);
|
||||
if (gr)
|
||||
fputs(gr->gr_name, stdout);
|
||||
scratch[8]='\0';
|
||||
my_getgrgid( scratch, info->st_gid);
|
||||
if (*scratch)
|
||||
fputs(scratch, stdout);
|
||||
else
|
||||
writenum((long)info->st_gid,(short)0);
|
||||
} else
|
||||
#endif
|
||||
writenum((long)info->st_gid,(short)0);
|
||||
tab(33);
|
||||
tab(17);
|
||||
if (S_ISBLK(mode) || S_ISCHR(mode)) {
|
||||
writenum((long)MAJOR(info->st_rdev),(short)3);
|
||||
fputs(", ", stdout);
|
||||
@@ -297,12 +262,12 @@ static void list_single(const char *name, struct stat *info)
|
||||
wr(name, len);
|
||||
if (S_ISLNK(mode)) {
|
||||
wr(" -> ", 4);
|
||||
len = readlink(name, scratch, sizeof scratch);
|
||||
len = readlink(fullname, scratch, sizeof scratch);
|
||||
if (len > 0) fwrite(scratch, 1, len, stdout);
|
||||
#ifdef FEATURE_FILETYPECHAR
|
||||
/* show type of destination */
|
||||
if (opts & DISP_FTYPE) {
|
||||
if (!stat(name, info)) {
|
||||
if (!stat(fullname, info)) {
|
||||
append = append_char(info->st_mode);
|
||||
if (append)
|
||||
fputc(append, stdout);
|
||||
@@ -372,7 +337,7 @@ static int list_item(const char *name)
|
||||
|
||||
if (!S_ISDIR(info.st_mode) ||
|
||||
(opts & DIR_NOLIST)) {
|
||||
list_single(name, &info);
|
||||
list_single(name, &info, name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -424,7 +389,7 @@ static int list_item(const char *name)
|
||||
strcpy(fnend, entry->d_name);
|
||||
if (lstat(fullname, &info))
|
||||
goto direrr; /* (shouldn't fail) */
|
||||
list_single(entry->d_name, &info);
|
||||
list_single(entry->d_name, &info, fullname);
|
||||
}
|
||||
closedir(dir);
|
||||
return 0;
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ static const char dutmp_usage[] = "dutmp\n"
|
||||
"\tDump file or stdin utmp file format to stdout, pipe delimited.\n"
|
||||
"\tdutmp /var/run/utmp\n";
|
||||
|
||||
static int dutmp_main (int argc, char **argv)
|
||||
extern int dutmp_main (int argc, char **argv)
|
||||
{
|
||||
|
||||
FILE *f = stdin;
|
||||
|
||||
@@ -25,7 +25,9 @@
|
||||
|
||||
|
||||
/* Turning this off makes things a bit smaller (and less pretty) */
|
||||
#define BB_MORE_TERM
|
||||
#define BB_FEATURE_USE_TERMIOS
|
||||
/* Turning this off makes things a bit smaller (and less pretty) */
|
||||
#define BB_FEATURE_AUTOWIDTH
|
||||
|
||||
|
||||
|
||||
@@ -33,19 +35,16 @@
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
static const char more_usage[] = "[file ...]";
|
||||
|
||||
|
||||
/* ED: sparc termios is broken: revert back to old termio handling. */
|
||||
#ifdef BB_MORE_TERM
|
||||
#ifdef BB_FEATURE_USE_TERMIOS
|
||||
|
||||
|
||||
#if defined (__sparc__)
|
||||
#if #cpu(sparc)
|
||||
# define USE_OLD_TERMIO
|
||||
# include <termio.h>
|
||||
# include <sys/ioctl.h>
|
||||
# define termios termio
|
||||
# define stty(fd,argp) ioctl(fd,TCSETAF,argp)
|
||||
#else
|
||||
@@ -58,24 +57,43 @@ static const char more_usage[] = "[file ...]";
|
||||
|
||||
void gotsig(int sig) {
|
||||
stty(fileno(cin), &initial_settings);
|
||||
fprintf(stdout, "\n");
|
||||
exit( TRUE);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define TERMINAL_WIDTH 79 /* not 80 in case terminal has linefold bug */
|
||||
#define TERMINAL_HEIGHT 24
|
||||
|
||||
|
||||
#if defined BB_FEATURE_AUTOWIDTH && ! defined USE_OLD_TERMIO
|
||||
static int terminal_width = 0, terminal_height = 0;
|
||||
#else
|
||||
#define terminal_width TERMINAL_WIDTH
|
||||
#define terminal_height TERMINAL_HEIGHT
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
extern int more_main(int argc, char **argv)
|
||||
{
|
||||
int c, lines=0, input=0;
|
||||
int next_page=0;
|
||||
struct stat st;
|
||||
FILE *file;
|
||||
#ifdef BB_FEATURE_AUTOWIDTH
|
||||
struct winsize win;
|
||||
#endif
|
||||
|
||||
if ( strcmp(*argv,"--help")==0 || strcmp(*argv,"-h")==0 ) {
|
||||
usage (more_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
while (argc >= 0) {
|
||||
if ( argc > 0 && (strcmp(*argv,"--help")==0 || strcmp(*argv,"-h")==0) ) {
|
||||
usage (more_usage);
|
||||
}
|
||||
do {
|
||||
if (argc==0) {
|
||||
file = stdin;
|
||||
}
|
||||
@@ -88,7 +106,7 @@ extern int more_main(int argc, char **argv)
|
||||
}
|
||||
fstat(fileno(file), &st);
|
||||
|
||||
#ifdef BB_MORE_TERM
|
||||
#ifdef BB_FEATURE_USE_TERMIOS
|
||||
cin = fopen("/dev/tty", "r");
|
||||
if (!cin)
|
||||
cin = fopen("/dev/console", "r");
|
||||
@@ -101,8 +119,18 @@ extern int more_main(int argc, char **argv)
|
||||
new_settings.c_lflag &= ~ICANON;
|
||||
new_settings.c_lflag &= ~ECHO;
|
||||
stty(fileno(cin), &new_settings);
|
||||
|
||||
|
||||
#ifdef BB_FEATURE_AUTOWIDTH
|
||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &win);
|
||||
if (win.ws_row > 4)
|
||||
terminal_height = win.ws_row - 2;
|
||||
if (win.ws_col > 0)
|
||||
terminal_width = win.ws_col - 1;
|
||||
#endif
|
||||
|
||||
(void) signal(SIGINT, gotsig);
|
||||
(void) signal(SIGQUIT, gotsig);
|
||||
(void) signal(SIGTERM, gotsig);
|
||||
|
||||
#endif
|
||||
while ((c = getc(file)) != EOF) {
|
||||
@@ -117,7 +145,7 @@ extern int more_main(int argc, char **argv)
|
||||
st.st_size);
|
||||
}
|
||||
len += fprintf(stdout, "%s",
|
||||
#ifdef BB_MORE_TERM
|
||||
#ifdef BB_FEATURE_USE_TERMIOS
|
||||
""
|
||||
#else
|
||||
"\n"
|
||||
@@ -127,34 +155,40 @@ extern int more_main(int argc, char **argv)
|
||||
fflush(stdout);
|
||||
input = getc( cin);
|
||||
|
||||
#ifdef BB_MORE_TERM
|
||||
#ifdef BB_FEATURE_USE_TERMIOS
|
||||
/* Erase the "More" message */
|
||||
while(len-- > 0)
|
||||
while(--len >= 0)
|
||||
putc('\b', stdout);
|
||||
while(len++ < 79)
|
||||
while(++len <= terminal_width)
|
||||
putc(' ', stdout);
|
||||
while(len-- > 0)
|
||||
while(--len >= 0)
|
||||
putc('\b', stdout);
|
||||
fflush(stdout);
|
||||
#endif
|
||||
|
||||
}
|
||||
if (input=='q')
|
||||
goto end;
|
||||
if (input==' ' && c == '\n' )
|
||||
next_page = 1;
|
||||
if ( c == '\n' && ++lines == 24 )
|
||||
next_page = 1;
|
||||
if (c == '\n' ) {
|
||||
switch(input) {
|
||||
case 'q':
|
||||
goto end;
|
||||
case '\n':
|
||||
/* increment by just one line if we are at
|
||||
* the end of this line*/
|
||||
next_page = 1;
|
||||
break;
|
||||
}
|
||||
if ( ++lines == terminal_height )
|
||||
next_page = 1;
|
||||
}
|
||||
putc(c, stdout);
|
||||
}
|
||||
fclose(file);
|
||||
fflush(stdout);
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
} while (--argc > 0);
|
||||
end:
|
||||
#ifdef BB_MORE_TERM
|
||||
#ifdef BB_FEATURE_USE_TERMIOS
|
||||
gotsig(0);
|
||||
#endif
|
||||
exit(TRUE);
|
||||
|
||||
+1
-1
@@ -74,7 +74,7 @@ static void parse_proc_status(char* S, proc_t* P)
|
||||
);
|
||||
else fprintf(stderr, "Internal error!\n");
|
||||
|
||||
/* For busybox, ignoring effecting, saved, etc */
|
||||
/* For busybox, ignoring effective, saved, etc */
|
||||
tmp = strstr (S,"Uid:");
|
||||
if(tmp) sscanf (tmp,
|
||||
"Uid:\t%d", &P->ruid);
|
||||
|
||||
@@ -74,7 +74,7 @@ static void parse_proc_status(char* S, proc_t* P)
|
||||
);
|
||||
else fprintf(stderr, "Internal error!\n");
|
||||
|
||||
/* For busybox, ignoring effecting, saved, etc */
|
||||
/* For busybox, ignoring effective, saved, etc */
|
||||
tmp = strstr (S,"Uid:");
|
||||
if(tmp) sscanf (tmp,
|
||||
"Uid:\t%d", &P->ruid);
|
||||
|
||||
@@ -50,7 +50,6 @@ extern int replace_match(char *haystack, char *needle, char *newNeedle, int igno
|
||||
} while (regexec(re, s, FALSE, ignoreCase) == TRUE);
|
||||
/* copy stuff from after the match */
|
||||
while ( (*d++ = *s++) ) {}
|
||||
d[-1] = '\n';
|
||||
d[0] = '\0';
|
||||
strcpy(haystack, buf);
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ extern int rm_main(int argc, char **argv)
|
||||
|
||||
while (argc-- > 0) {
|
||||
srcName = *(argv++);
|
||||
if (recursiveAction( srcName, recursiveFlag, TRUE, TRUE,
|
||||
if (recursiveAction( srcName, recursiveFlag, FALSE, TRUE,
|
||||
fileAction, dirAction) == FALSE) {
|
||||
exit( FALSE);
|
||||
}
|
||||
|
||||
@@ -45,9 +45,23 @@ static const char sed_usage[] =
|
||||
#else
|
||||
"This version of sed matches strings (not full regexps).\n";
|
||||
#endif
|
||||
|
||||
|
||||
static void do_sed(FILE *fp, char *needle, char *newNeedle, int ignoreCase, int printFlag, int quietFlag)
|
||||
{
|
||||
int foundOne=FALSE;
|
||||
char haystack[1024];
|
||||
|
||||
|
||||
while (fgets (haystack, 1023, fp)) {
|
||||
foundOne = replace_match(haystack, needle, newNeedle, ignoreCase);
|
||||
if (foundOne==TRUE && printFlag==TRUE) {
|
||||
fprintf(stdout, haystack);
|
||||
}
|
||||
if (quietFlag==FALSE) {
|
||||
fprintf(stdout, haystack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern int sed_main (int argc, char **argv)
|
||||
{
|
||||
@@ -56,11 +70,9 @@ extern int sed_main (int argc, char **argv)
|
||||
char *name;
|
||||
char *cp;
|
||||
int ignoreCase=FALSE;
|
||||
int foundOne=FALSE;
|
||||
int printFlag=FALSE;
|
||||
int quietFlag=FALSE;
|
||||
int stopNow;
|
||||
char *haystack;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
@@ -73,24 +85,23 @@ extern int sed_main (int argc, char **argv)
|
||||
cp = *argv++;
|
||||
stopNow=FALSE;
|
||||
|
||||
while (*++cp && stopNow==FALSE)
|
||||
while (*++cp && stopNow==FALSE) {
|
||||
switch (*cp) {
|
||||
case 'n':
|
||||
quietFlag = TRUE;
|
||||
break;
|
||||
case 'e':
|
||||
if (*(cp+1)==0 && --argc < 0) {
|
||||
fprintf(stderr, "A\n");
|
||||
usage( sed_usage);
|
||||
}
|
||||
cp = *argv++;
|
||||
if ( *++cp != 's')
|
||||
cp = *argv++;
|
||||
while( *cp ) {
|
||||
if (*cp == 's' && strlen(cp) > 3 && *(cp+1) == '/') {
|
||||
char* pos=needle=cp+2;
|
||||
for(;;) {
|
||||
pos = strchr(pos, '/');
|
||||
if (pos==NULL) {
|
||||
fprintf(stderr, "B\n");
|
||||
usage( sed_usage);
|
||||
}
|
||||
if (*(pos-1) == '\\') {
|
||||
@@ -104,7 +115,6 @@ extern int sed_main (int argc, char **argv)
|
||||
for(;;) {
|
||||
pos = strchr(pos, '/');
|
||||
if (pos==NULL) {
|
||||
fprintf(stderr, "C\n");
|
||||
usage( sed_usage);
|
||||
}
|
||||
if (*(pos-1) == '\\') {
|
||||
@@ -116,7 +126,6 @@ extern int sed_main (int argc, char **argv)
|
||||
*pos=0;
|
||||
if (pos+2 != 0) {
|
||||
while (*++pos) {
|
||||
fprintf(stderr, "pos='%s'\n", pos);
|
||||
switch (*pos) {
|
||||
case 'i':
|
||||
ignoreCase=TRUE;
|
||||
@@ -134,42 +143,35 @@ extern int sed_main (int argc, char **argv)
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
fprintf(stderr, "replace '%s' with '%s'\n", needle, newNeedle);
|
||||
//fprintf(stderr, "replace '%s' with '%s'\n", needle, newNeedle);
|
||||
stopNow=TRUE;
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "D\n");
|
||||
usage(sed_usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (argc-- > 0) {
|
||||
name = *argv++;
|
||||
if (argc==0) {
|
||||
do_sed( stdin, needle, newNeedle, ignoreCase, printFlag, quietFlag);
|
||||
} else {
|
||||
while (argc-- > 0) {
|
||||
name = *argv++;
|
||||
|
||||
fp = fopen (name, "r");
|
||||
if (fp == NULL) {
|
||||
perror (name);
|
||||
continue;
|
||||
fp = fopen (name, "r");
|
||||
if (fp == NULL) {
|
||||
perror (name);
|
||||
continue;
|
||||
}
|
||||
|
||||
do_sed( fp, needle, newNeedle, ignoreCase, printFlag, quietFlag);
|
||||
|
||||
if (ferror (fp))
|
||||
perror (name);
|
||||
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
haystack = (char*)malloc( 1024);
|
||||
while (fgets (haystack, 1023, fp)) {
|
||||
|
||||
foundOne = replace_match(haystack, needle, newNeedle, ignoreCase);
|
||||
if (foundOne==TRUE && printFlag==TRUE)
|
||||
fputs (haystack, stdout);
|
||||
if (quietFlag==FALSE)
|
||||
fputs (haystack, stdout);
|
||||
/* Avoid any mem leaks */
|
||||
free(haystack);
|
||||
haystack = (char*)malloc( BUF_SIZE);
|
||||
}
|
||||
|
||||
if (ferror (fp))
|
||||
perror (name);
|
||||
|
||||
fclose (fp);
|
||||
}
|
||||
exit( TRUE);
|
||||
}
|
||||
|
||||
@@ -35,6 +35,16 @@
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
|
||||
/* Note that tar.c expects TRUE and FALSE to be defined
|
||||
* exactly the opposite of how they are used everywhere else.
|
||||
* Some time this should be integrated a bit better, but this
|
||||
* does the job for now.
|
||||
*/
|
||||
#undef FALSE
|
||||
#undef TRUE
|
||||
#define FALSE ((int) 0)
|
||||
#define TRUE ((int) 1)
|
||||
|
||||
|
||||
static const char tar_usage[] =
|
||||
"tar -[cxtvOf] [tarFileName] [FILE] ...\n"
|
||||
@@ -169,10 +179,9 @@ extern int tar_main (int argc, char **argv)
|
||||
/*
|
||||
* Parse the options.
|
||||
*/
|
||||
options = *argv++;
|
||||
argc--;
|
||||
|
||||
if (**argv == '-') {
|
||||
options = (*argv++) + 1;
|
||||
argc--;
|
||||
for (; *options; options++) {
|
||||
switch (*options) {
|
||||
case 'f':
|
||||
|
||||
+61
-27
@@ -25,7 +25,9 @@
|
||||
|
||||
|
||||
/* Turning this off makes things a bit smaller (and less pretty) */
|
||||
#define BB_MORE_TERM
|
||||
#define BB_FEATURE_USE_TERMIOS
|
||||
/* Turning this off makes things a bit smaller (and less pretty) */
|
||||
#define BB_FEATURE_AUTOWIDTH
|
||||
|
||||
|
||||
|
||||
@@ -33,19 +35,16 @@
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
static const char more_usage[] = "[file ...]";
|
||||
|
||||
|
||||
/* ED: sparc termios is broken: revert back to old termio handling. */
|
||||
#ifdef BB_MORE_TERM
|
||||
#ifdef BB_FEATURE_USE_TERMIOS
|
||||
|
||||
|
||||
#if defined (__sparc__)
|
||||
#if #cpu(sparc)
|
||||
# define USE_OLD_TERMIO
|
||||
# include <termio.h>
|
||||
# include <sys/ioctl.h>
|
||||
# define termios termio
|
||||
# define stty(fd,argp) ioctl(fd,TCSETAF,argp)
|
||||
#else
|
||||
@@ -58,24 +57,43 @@ static const char more_usage[] = "[file ...]";
|
||||
|
||||
void gotsig(int sig) {
|
||||
stty(fileno(cin), &initial_settings);
|
||||
fprintf(stdout, "\n");
|
||||
exit( TRUE);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define TERMINAL_WIDTH 79 /* not 80 in case terminal has linefold bug */
|
||||
#define TERMINAL_HEIGHT 24
|
||||
|
||||
|
||||
#if defined BB_FEATURE_AUTOWIDTH && ! defined USE_OLD_TERMIO
|
||||
static int terminal_width = 0, terminal_height = 0;
|
||||
#else
|
||||
#define terminal_width TERMINAL_WIDTH
|
||||
#define terminal_height TERMINAL_HEIGHT
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
extern int more_main(int argc, char **argv)
|
||||
{
|
||||
int c, lines=0, input=0;
|
||||
int next_page=0;
|
||||
struct stat st;
|
||||
FILE *file;
|
||||
#ifdef BB_FEATURE_AUTOWIDTH
|
||||
struct winsize win;
|
||||
#endif
|
||||
|
||||
if ( strcmp(*argv,"--help")==0 || strcmp(*argv,"-h")==0 ) {
|
||||
usage (more_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
while (argc >= 0) {
|
||||
if ( argc > 0 && (strcmp(*argv,"--help")==0 || strcmp(*argv,"-h")==0) ) {
|
||||
usage (more_usage);
|
||||
}
|
||||
do {
|
||||
if (argc==0) {
|
||||
file = stdin;
|
||||
}
|
||||
@@ -88,7 +106,7 @@ extern int more_main(int argc, char **argv)
|
||||
}
|
||||
fstat(fileno(file), &st);
|
||||
|
||||
#ifdef BB_MORE_TERM
|
||||
#ifdef BB_FEATURE_USE_TERMIOS
|
||||
cin = fopen("/dev/tty", "r");
|
||||
if (!cin)
|
||||
cin = fopen("/dev/console", "r");
|
||||
@@ -101,8 +119,18 @@ extern int more_main(int argc, char **argv)
|
||||
new_settings.c_lflag &= ~ICANON;
|
||||
new_settings.c_lflag &= ~ECHO;
|
||||
stty(fileno(cin), &new_settings);
|
||||
|
||||
|
||||
#ifdef BB_FEATURE_AUTOWIDTH
|
||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &win);
|
||||
if (win.ws_row > 4)
|
||||
terminal_height = win.ws_row - 2;
|
||||
if (win.ws_col > 0)
|
||||
terminal_width = win.ws_col - 1;
|
||||
#endif
|
||||
|
||||
(void) signal(SIGINT, gotsig);
|
||||
(void) signal(SIGQUIT, gotsig);
|
||||
(void) signal(SIGTERM, gotsig);
|
||||
|
||||
#endif
|
||||
while ((c = getc(file)) != EOF) {
|
||||
@@ -117,7 +145,7 @@ extern int more_main(int argc, char **argv)
|
||||
st.st_size);
|
||||
}
|
||||
len += fprintf(stdout, "%s",
|
||||
#ifdef BB_MORE_TERM
|
||||
#ifdef BB_FEATURE_USE_TERMIOS
|
||||
""
|
||||
#else
|
||||
"\n"
|
||||
@@ -127,34 +155,40 @@ extern int more_main(int argc, char **argv)
|
||||
fflush(stdout);
|
||||
input = getc( cin);
|
||||
|
||||
#ifdef BB_MORE_TERM
|
||||
#ifdef BB_FEATURE_USE_TERMIOS
|
||||
/* Erase the "More" message */
|
||||
while(len-- > 0)
|
||||
while(--len >= 0)
|
||||
putc('\b', stdout);
|
||||
while(len++ < 79)
|
||||
while(++len <= terminal_width)
|
||||
putc(' ', stdout);
|
||||
while(len-- > 0)
|
||||
while(--len >= 0)
|
||||
putc('\b', stdout);
|
||||
fflush(stdout);
|
||||
#endif
|
||||
|
||||
}
|
||||
if (input=='q')
|
||||
goto end;
|
||||
if (input==' ' && c == '\n' )
|
||||
next_page = 1;
|
||||
if ( c == '\n' && ++lines == 24 )
|
||||
next_page = 1;
|
||||
if (c == '\n' ) {
|
||||
switch(input) {
|
||||
case 'q':
|
||||
goto end;
|
||||
case '\n':
|
||||
/* increment by just one line if we are at
|
||||
* the end of this line*/
|
||||
next_page = 1;
|
||||
break;
|
||||
}
|
||||
if ( ++lines == terminal_height )
|
||||
next_page = 1;
|
||||
}
|
||||
putc(c, stdout);
|
||||
}
|
||||
fclose(file);
|
||||
fflush(stdout);
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
} while (--argc > 0);
|
||||
end:
|
||||
#ifdef BB_MORE_TERM
|
||||
#ifdef BB_FEATURE_USE_TERMIOS
|
||||
gotsig(0);
|
||||
#endif
|
||||
exit(TRUE);
|
||||
|
||||
@@ -236,7 +236,30 @@ copyFile( const char *srcName, const char *destName,
|
||||
|
||||
|
||||
|
||||
#ifdef BB_TAR
|
||||
#if defined BB_TAR || defined BB_LS
|
||||
|
||||
#define TYPEINDEX(mode) (((mode) >> 12) & 0x0f)
|
||||
#define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)])
|
||||
|
||||
/* The special bits. If set, display SMODE0/1 instead of MODE0/1 */
|
||||
static const mode_t SBIT[] = {
|
||||
0, 0, S_ISUID,
|
||||
0, 0, S_ISGID,
|
||||
0, 0, S_ISVTX
|
||||
};
|
||||
|
||||
/* The 9 mode bits to test */
|
||||
static const mode_t MBIT[] = {
|
||||
S_IRUSR, S_IWUSR, S_IXUSR,
|
||||
S_IRGRP, S_IWGRP, S_IXGRP,
|
||||
S_IROTH, S_IWOTH, S_IXOTH
|
||||
};
|
||||
|
||||
#define MODE1 "rwxrwxrwx"
|
||||
#define MODE0 "---------"
|
||||
#define SMODE1 "..s..s..t"
|
||||
#define SMODE0 "..S..S..T"
|
||||
|
||||
/*
|
||||
* Return the standard ls-like mode string from a file mode.
|
||||
* This is static and so is overwritten on each call.
|
||||
@@ -245,64 +268,25 @@ const char *modeString(int mode)
|
||||
{
|
||||
static char buf[12];
|
||||
|
||||
strcpy(buf, "----------");
|
||||
|
||||
/*
|
||||
* Fill in the file type.
|
||||
*/
|
||||
if (S_ISDIR(mode))
|
||||
buf[0] = 'd';
|
||||
if (S_ISCHR(mode))
|
||||
buf[0] = 'c';
|
||||
if (S_ISBLK(mode))
|
||||
buf[0] = 'b';
|
||||
if (S_ISFIFO(mode))
|
||||
buf[0] = 'p';
|
||||
if (S_ISLNK(mode))
|
||||
buf[0] = 'l';
|
||||
if (S_ISSOCK(mode))
|
||||
buf[0] = 's';
|
||||
/*
|
||||
* Now fill in the normal file permissions.
|
||||
*/
|
||||
if (mode & S_IRUSR)
|
||||
buf[1] = 'r';
|
||||
if (mode & S_IWUSR)
|
||||
buf[2] = 'w';
|
||||
if (mode & S_IXUSR)
|
||||
buf[3] = 'x';
|
||||
if (mode & S_IRGRP)
|
||||
buf[4] = 'r';
|
||||
if (mode & S_IWGRP)
|
||||
buf[5] = 'w';
|
||||
if (mode & S_IXGRP)
|
||||
buf[6] = 'x';
|
||||
if (mode & S_IROTH)
|
||||
buf[7] = 'r';
|
||||
if (mode & S_IWOTH)
|
||||
buf[8] = 'w';
|
||||
if (mode & S_IXOTH)
|
||||
buf[9] = 'x';
|
||||
|
||||
/*
|
||||
* Finally fill in magic stuff like suid and sticky text.
|
||||
*/
|
||||
if (mode & S_ISUID)
|
||||
buf[3] = ((mode & S_IXUSR) ? 's' : 'S');
|
||||
if (mode & S_ISGID)
|
||||
buf[6] = ((mode & S_IXGRP) ? 's' : 'S');
|
||||
if (mode & S_ISVTX)
|
||||
buf[9] = ((mode & S_IXOTH) ? 't' : 'T');
|
||||
|
||||
int i;
|
||||
buf[0] = TYPECHAR(mode);
|
||||
for (i=0; i<9; i++) {
|
||||
if (mode & SBIT[i])
|
||||
buf[i+1] = (mode & MBIT[i])?
|
||||
SMODE1[i] : SMODE0[i];
|
||||
else
|
||||
buf[i+1] = (mode & MBIT[i])?
|
||||
MODE1[i] : MODE0[i];
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef BB_TAR
|
||||
/*
|
||||
* Get the time string to be used for a file.
|
||||
* This is down to the minute for new files, but only the date for old files.
|
||||
* The string is returned from a static buffer, and so is overwritten for
|
||||
* each call.
|
||||
* Return the standard ls-like time string from a time_t
|
||||
* This is static and so is overwritten on each call.
|
||||
*/
|
||||
const char *timeString(time_t timeVal)
|
||||
{
|
||||
@@ -325,7 +309,6 @@ const char *timeString(time_t timeVal)
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Write all of the supplied buffer out to a file.
|
||||
* This does multiple writes as necessary.
|
||||
@@ -415,8 +398,12 @@ recursiveAction(const char *fileName, int recurse, int followLinks, int depthFir
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
if ( (followLinks == FALSE) && (S_ISLNK(statbuf.st_mode)) )
|
||||
return (TRUE);
|
||||
if ( (followLinks == FALSE) && (S_ISLNK(statbuf.st_mode)) ) {
|
||||
if (fileAction == NULL)
|
||||
return (TRUE);
|
||||
else
|
||||
return (fileAction(fileName, &statbuf));
|
||||
}
|
||||
|
||||
if (recurse == FALSE) {
|
||||
if (S_ISDIR(statbuf.st_mode)) {
|
||||
|
||||
Reference in new issue
Block a user