VERSION=0.29alpha1
BUILDTIME=$(shell date "+%Y%m%d-%H%M")
+DODEBUG=true
#This will choke on a non-debian system
ARCH=`uname -m | sed -e 's/i.86/i386/' | sed -e 's/sparc.*/sparc/'`
-STRIP= strip --remove-section=.note --remove-section=.comment busybox
-LDFLAGS= -s
-
# -D_GNU_SOURCE is needed because environ is used in init.c
-CFLAGS=-Wall -O2 -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE
-# For debugging only
-#CFLAGS=-Wall -g -D_GNU_SOURCE
+ifeq ($(DODEBUG),true)
+ CFLAGS=-Wall -g -D_GNU_SOURCE
+ STRIP=
+else
+ CFLAGS=-Wall -O2 -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE
+ STRIP= strip --remove-section=.note --remove-section=.comment busybox
+endif
+
+ifndef $(prefix)
+ prefix=`pwd`
+endif
+BINDIR=$(prefix)
+
+LDFLAGS= -s
LIBRARIES=-lc
OBJECTS=$(shell ./busybox.sh) utility.o
-
CFLAGS+= -DBB_VER='"$(VERSION)"'
CFLAGS+= -DBB_BT='"$(BUILDTIME)"'
-#all: busybox links
-all: busybox
+all: busybox links
+#all: busybox
busybox: $(OBJECTS)
$(CC) $(CFLAGS) $(LDFLAGS) -o busybox $(OBJECTS) $(LIBRARIES)
- #$(STRIP)
+ $(STRIP)
links:
- ./busybox.mkll | sort >busybox.links
force:
$(OBJECTS): busybox.def.h internal.h Makefile
+
+install: busybox
+ install.sh $(BINDIR)
+
int busybox_main(int argc, char **argv)
{
+ int col=0;
argc--;
argv++;
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n",
BB_VER, BB_BT);
fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
+ fprintf(stderr, "or\nUsage: [function] [arguments]...\n");
fprintf(stderr,
"\n\tMost people will create a symlink to busybox for each\n"
"\tfunction name, and busybox will act like whatever you invoke it as.\n");
fprintf(stderr, "\nCurrently defined functions:\n");
- if (a->name != 0) {
- fprintf(stderr, "%s", a->name);
- a++;
- }
while (a->name != 0) {
- fprintf(stderr, ", %s", a->name);
+ col+=fprintf(stderr, "%s%s", ((col==0)? "\t":", "), a->name);
a++;
+ if (col>60) {
+ fprintf(stderr, ",\n");
+ col=0;
+ }
}
fprintf(stderr, "\n\n");
exit(-1);
#Make busybox links list file
DF="busybox.def.h"
-MF="main.c"
+MF="busybox.c"
LIST="$(sed -n '/^#define/{s/^#define //p;}' $DF)"
- for def in ${LIST}; do
-
- set -- $(sed -n '/^#ifdef '$def'[ +| +].*/,/^#endif/{s/.*\/\///p; /^{ /{ s/^{ "//; s/",.*$//p;}; }' $MF)
- path=$1; shift
-
- for n in $@; do
- echo "$path/$n"
- done
+for def in ${LIST}; do
+ i=`sed -n 's/^#ifdef '$def'.*\/\/\(.*$\)/\/\1\//gp' $MF`
+ j=`sed -n '/^#ifdef '$def'.*/,/^#endif/{ s/.*\"\(.*\)\".*/\1/gp; }' $MF`
+ for k in $j; do
+ echo $i$k
done
+done
# undef LZW
#endif
-/* $Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $ */
+/* $Id: gzip.c,v 1.2 1999/10/06 20:25:32 andersen Exp $ */
/* tailor.h -- target dependent definitions
* Copyright (C) 1992-1993 Jean-loup Gailly.
* This is free software; you can redistribute it and/or modify it under the
* The target dependent functions should be defined in tailor.c.
*/
-/* $Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $ */
+/* $Id: gzip.c,v 1.2 1999/10/06 20:25:32 andersen Exp $ */
#if defined(__MSDOS__) && !defined(MSDOS)
# define MSDOS
#endif
#ifdef RCSID
-static char rcsid[] = "$Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
+static char rcsid[] = "$Id: gzip.c,v 1.2 1999/10/06 20:25:32 andersen Exp $";
#endif
/* ===========================================================================
#include <stdio.h>
#ifdef RCSID
-static char rcsid[] = "$Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
+static char rcsid[] = "$Id: gzip.c,v 1.2 1999/10/06 20:25:32 andersen Exp $";
#endif
/* ===========================================================================
*/
#ifdef RCSID
-static char rcsid[] = "$Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
+static char rcsid[] = "$Id: gzip.c,v 1.2 1999/10/06 20:25:32 andersen Exp $";
#endif
#include <ctype.h>
// int main (argc, argv)
// int argc;
// char **argv;
-int gzip_main(struct FileInfo * i, int argc, char * * argv)
+int gzip_main(int argc, char * * argv)
{
foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
if (foreground) {
#include <ctype.h>
#ifdef RCSID
-static char rcsid[] = "$Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
+static char rcsid[] = "$Id: gzip.c,v 1.2 1999/10/06 20:25:32 andersen Exp $";
#endif
/* ===========================================================================
*/
#ifdef RCSID
-static char rcsid[] = "$Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
+static char rcsid[] = "$Id: gzip.c,v 1.2 1999/10/06 20:25:32 andersen Exp $";
#endif
#include <ctype.h>
*/
#ifdef RCSID
-static char rcsid[] = "$Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
+static char rcsid[] = "$Id: gzip.c,v 1.2 1999/10/06 20:25:32 andersen Exp $";
#endif
#include <ctype.h>
static void writeTarFile(int fileCount, char ** fileTable);
static void writeTarBlock(const char * buf, int len);
static BOOL putOctal(char * cp, int len, long value);
-extern const char * modeString(int mode);
-extern const char * timeString(time_t timeVal);
-extern int fullWrite(int fd, const char * buf, int len);
-extern int fullRead(int fd, char * buf, int len);
extern int
-tar_main(struct FileInfo *unused, int argc, char ** argv)
+tar_main(int argc, char ** argv)
{
const char * options;
-/*
- * Return the standard ls-like mode string from a file mode.
- * This is static and so is overwritten on each call.
- */
-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';
-#ifdef S_ISLNK
- if (S_ISLNK(mode))
- buf[0] = 'l';
-#endif
-#ifdef S_ISSOCK
- if (S_ISSOCK(mode))
- buf[0] = 's';
-#endif
-
- /*
- * 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');
-
- return buf;
-}
-
-
-/*
- * 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.
- */
-const char *
-timeString(time_t timeVal)
-{
- time_t now;
- char * str;
- static char buf[26];
-
- time(&now);
-
- str = ctime(&timeVal);
-
- strcpy(buf, &str[4]);
- buf[12] = '\0';
-
- if ((timeVal > now) || (timeVal < now - 365*24*60*60L))
- {
- strcpy(&buf[7], &str[20]);
- buf[11] = '\0';
- }
-
- return buf;
-}
-
-
-
-/*
- * Write all of the supplied buffer out to a file.
- * This does multiple writes as necessary.
- * Returns the amount written, or -1 on an error.
- */
-int
-fullWrite(int fd, const char * buf, int len)
-{
- int cc;
- int total;
-
- total = 0;
-
- while (len > 0)
- {
- cc = write(fd, buf, len);
-
- if (cc < 0)
- return -1;
-
- buf += cc;
- total+= cc;
- len -= cc;
- }
-
- return total;
-}
-
-
-/*
- * Read all of the supplied buffer from a file.
- * This does multiple reads as necessary.
- * Returns the amount read, or -1 on an error.
- * A short read is returned on an end of file.
- */
-int
-fullRead(int fd, char * buf, int len)
-{
- int cc;
- int total;
-
- total = 0;
-
- while (len > 0)
- {
- cc = read(fd, buf, len);
-
- if (cc < 0)
- return -1;
-
- if (cc == 0)
- break;
-
- buf += cc;
- total+= cc;
- len -= cc;
- }
-
- return total;
-}
-
-
-
#endif
/* END CODE */
int busybox_main(int argc, char **argv)
{
+ int col=0;
argc--;
argv++;
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n",
BB_VER, BB_BT);
fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
+ fprintf(stderr, "or\nUsage: [function] [arguments]...\n");
fprintf(stderr,
"\n\tMost people will create a symlink to busybox for each\n"
"\tfunction name, and busybox will act like whatever you invoke it as.\n");
fprintf(stderr, "\nCurrently defined functions:\n");
- if (a->name != 0) {
- fprintf(stderr, "%s", a->name);
- a++;
- }
while (a->name != 0) {
- fprintf(stderr, ", %s", a->name);
+ col+=fprintf(stderr, "%s%s", ((col==0)? "\t":", "), a->name);
a++;
+ if (col>60) {
+ fprintf(stderr, ",\n");
+ col=0;
+ }
}
fprintf(stderr, "\n\n");
exit(-1);
#define BB_DATE
#define BB_DD
//#define BB_DESCEND
-//#define BB_DF
+#define BB_DF
#define BB_DMESG
//#define BB_DUTMP
//#define BB_DYADIC
#define BB_FALSE
//#define BB_FDFLUSH
-//#define BB_FIND
-//#define BB_FINDMOUNT
-//#define BB_GREP
+#define BB_FIND
+#define BB_GREP
////#define BB_HALT
//#define BB_INIT
//#define BB_KILL
////#define BB_SWAPOFF
//#define BB_SWAPON
//#define BB_SYNC
-//#define BB_TAR
+#define BB_TAR
//#define BB_TOUCH
#define BB_TRUE
//#define BB_UMOUNT
//#define BB_UPDATE
//#define BB_UTILITY
-//#define BB_ZCAT
-//#define BB_GZIP
+#define BB_ZCAT
+#define BB_GZIP
#Make busybox links list file
DF="busybox.def.h"
-MF="main.c"
+MF="busybox.c"
LIST="$(sed -n '/^#define/{s/^#define //p;}' $DF)"
- for def in ${LIST}; do
-
- set -- $(sed -n '/^#ifdef '$def'[ +| +].*/,/^#endif/{s/.*\/\///p; /^{ /{ s/^{ "//; s/",.*$//p;}; }' $MF)
- path=$1; shift
-
- for n in $@; do
- echo "$path/$n"
- done
+for def in ${LIST}; do
+ i=`sed -n 's/^#ifdef '$def'.*\/\/\(.*$\)/\/\1\//gp' $MF`
+ j=`sed -n '/^#ifdef '$def'.*/,/^#endif/{ s/.*\"\(.*\)\".*/\1/gp; }' $MF`
+ for k in $j; do
+ echo $i$k
done
+done
long blocks_percent_used;
if ( statfs(mountPoint, &s) != 0 ) {
- name_and_error(mountPoint);
+ perror(mountPoint);
return 1;
}
}
extern int
-df_main(struct FileInfo * i, int argc, char * * argv)
+df_main(int argc, char * * argv)
{
static const char header[] =
"Filesystem 1024-blocks Used Available Capacity Mounted on\n";
int status;
while ( argc > 1 ) {
- if ( (mountEntry = findMountPoint(argv[1], "/etc/mtab")) == 0
- && (mountEntry = findMountPoint(argv[1], "/proc/mounts")) == 0 )
+ if ( (mountEntry = findMountPoint(argv[1], "/proc/mounts")) == 0 )
{
- fprintf(stderr, "%s: can't find mount point.\n"
- ,argv[1]);
+ fprintf(stderr, "%s: can't find mount point.\n" ,argv[1]);
return 1;
}
status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
FILE * mountTable;
struct mntent * mountEntry;
- if ( (mountTable = setmntent("/etc/mtab", "r")) == 0
- && (mountTable = setmntent("/proc/mounts", "r")) == 0
- ) {
- name_and_error("/etc/mtab");
+ if ( (mountTable = setmntent("/proc/mounts", "r")) == 0) {
+ perror("/proc/mounts");
return 1;
}
return 0;
}
+
+
+
+
+/*
+ * Given a block device, find the mount table entry if that block device
+ * is mounted.
+ *
+ * Given any other file (or directory), find the mount table entry for its
+ * filesystem.
+ */
+extern struct mntent *
+findMountPoint(const char * name, const char * table)
+{
+ struct stat s;
+ dev_t mountDevice;
+ FILE * mountTable;
+ struct mntent * mountEntry;
+
+ if ( stat(name, &s) != 0 )
+ return 0;
+
+ if ( (s.st_mode & S_IFMT) == S_IFBLK )
+ mountDevice = s.st_rdev;
+ else
+ mountDevice = s.st_dev;
+
+
+ if ( (mountTable = setmntent(table, "r")) == 0 )
+ return 0;
+
+ while ( (mountEntry = getmntent(mountTable)) != 0 ) {
+ if ( strcmp(name, mountEntry->mnt_dir) == 0
+ || strcmp(name, mountEntry->mnt_fsname) == 0 ) /* String match. */
+ break;
+ if ( stat(mountEntry->mnt_fsname, &s) == 0
+ && s.st_rdev == mountDevice ) /* Match the device. */
+ break;
+ if ( stat(mountEntry->mnt_dir, &s) == 0
+ && s.st_dev == mountDevice ) /* Match the directory's mount point. */
+ break;
+ }
+ endmntent(mountTable);
+ return mountEntry;
+}
long blocks_percent_used;
if ( statfs(mountPoint, &s) != 0 ) {
- name_and_error(mountPoint);
+ perror(mountPoint);
return 1;
}
}
extern int
-df_main(struct FileInfo * i, int argc, char * * argv)
+df_main(int argc, char * * argv)
{
static const char header[] =
"Filesystem 1024-blocks Used Available Capacity Mounted on\n";
int status;
while ( argc > 1 ) {
- if ( (mountEntry = findMountPoint(argv[1], "/etc/mtab")) == 0
- && (mountEntry = findMountPoint(argv[1], "/proc/mounts")) == 0 )
+ if ( (mountEntry = findMountPoint(argv[1], "/proc/mounts")) == 0 )
{
- fprintf(stderr, "%s: can't find mount point.\n"
- ,argv[1]);
+ fprintf(stderr, "%s: can't find mount point.\n" ,argv[1]);
return 1;
}
status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
FILE * mountTable;
struct mntent * mountEntry;
- if ( (mountTable = setmntent("/etc/mtab", "r")) == 0
- && (mountTable = setmntent("/proc/mounts", "r")) == 0
- ) {
- name_and_error("/etc/mtab");
+ if ( (mountTable = setmntent("/proc/mounts", "r")) == 0) {
+ perror("/proc/mounts");
return 1;
}
return 0;
}
+
+
+
+
+/*
+ * Given a block device, find the mount table entry if that block device
+ * is mounted.
+ *
+ * Given any other file (or directory), find the mount table entry for its
+ * filesystem.
+ */
+extern struct mntent *
+findMountPoint(const char * name, const char * table)
+{
+ struct stat s;
+ dev_t mountDevice;
+ FILE * mountTable;
+ struct mntent * mountEntry;
+
+ if ( stat(name, &s) != 0 )
+ return 0;
+
+ if ( (s.st_mode & S_IFMT) == S_IFBLK )
+ mountDevice = s.st_rdev;
+ else
+ mountDevice = s.st_dev;
+
+
+ if ( (mountTable = setmntent(table, "r")) == 0 )
+ return 0;
+
+ while ( (mountEntry = getmntent(mountTable)) != 0 ) {
+ if ( strcmp(name, mountEntry->mnt_dir) == 0
+ || strcmp(name, mountEntry->mnt_fsname) == 0 ) /* String match. */
+ break;
+ if ( stat(mountEntry->mnt_fsname, &s) == 0
+ && s.st_rdev == mountDevice ) /* Match the device. */
+ break;
+ if ( stat(mountEntry->mnt_dir, &s) == 0
+ && s.st_dev == mountDevice ) /* Match the directory's mount point. */
+ break;
+ }
+ endmntent(mountTable);
+ return mountEntry;
+}
const char dmesg_usage[] = "dmesg";
int
-dmesg_main(struct FileInfo * info, int argc, char * * argv)
+dmesg_main(int argc, char * * argv)
{
char buf[4096];
break;
case '?':
default:
- usage(dmesg_usage);
+ fprintf(stderr, "%s\n", dmesg_usage);
exit(1);
}
}
argv += optind;
if (argc > 1) {
- usage(dmesg_usage);
+ fprintf(stderr, "%s\n", dmesg_usage);
exit(1);
}
+/*
+ * Mini find implementation for busybox
+ *
+ * Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <dirent.h>
+#include "internal.h"
+
+
+static char* pattern=NULL;
+static char* directory=NULL;
+int dereferenceFlag=FALSE;
+
+static const char find_usage[] = "find [path...] [expression]\n"
+"default path is the current directory; default expression is -print\n"
+"expression may consist of:\n";
+
+
+
+static int fileAction(const char *fileName)
+{
+ if (pattern==NULL)
+ fprintf(stdout, "%s\n", fileName);
+ else if (match(fileName, pattern) == TRUE)
+ fprintf(stdout, "%s\n", fileName);
+ return( TRUE);
+}
+
+static int dirAction(const char *fileName)
+{
+ DIR *dir;
+ struct dirent *entry;
+
+ if (pattern==NULL)
+ fprintf(stdout, "%s\n", fileName);
+ else if (match(fileName, pattern) == TRUE)
+ fprintf(stdout, "%s\n", fileName);
+
+ dir = opendir( fileName);
+ if (!dir) {
+ perror("Can't open directory");
+ exit(FALSE);
+ }
+ while ((entry = readdir(dir)) != NULL) {
+ char dirName[NAME_MAX];
+ sprintf(dirName, "%s/%s", fileName, entry->d_name);
+ recursiveAction( dirName, TRUE, dereferenceFlag, fileAction, dirAction);
+ }
+ return( TRUE);
+}
+
+int find_main(int argc, char **argv)
+{
+ if (argc <= 1) {
+ dirAction( ".");
+ }
+
+ /* peel off the "find" */
+ argc--;
+ argv++;
+
+ if (**argv != '-') {
+ directory=*argv;
+ argc--;
+ argv++;
+ }
+
+ /* Parse any options */
+ while (**argv == '-') {
+ int stopit=FALSE;
+ while (*++(*argv) && stopit==FALSE) switch (**argv) {
+ case 'f':
+ if (strcmp(*argv, "follow")==0) {
+ argc--;
+ argv++;
+ dereferenceFlag=TRUE;
+ }
+ break;
+ case 'n':
+ if (strcmp(*argv, "name")==0) {
+ if (argc-- > 1) {
+ pattern=*(++argv);
+ stopit=-TRUE;
+ } else {
+ fprintf(stderr, "Usage: %s\n", find_usage);
+ exit( FALSE);
+ }
+ }
+ break;
+ case '-':
+ /* Ignore all long options */
+ break;
+ default:
+ fprintf(stderr, "Usage: %s\n", find_usage);
+ exit( FALSE);
+ }
+ if (argc-- > 1)
+ argv++;
+ if (**argv != '-')
+ break;
+ else
+ break;
+ }
+
+ dirAction( directory);
+ exit(TRUE);
+}
+
+
+
+#ifdef foobar
+
#include "internal.h"
#include <errno.h>
#include <stdio.h>
return(0);
}
+
+
+#endif
+/*
+ * Mini find implementation for busybox
+ *
+ * Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <dirent.h>
+#include "internal.h"
+
+
+static char* pattern=NULL;
+static char* directory=NULL;
+int dereferenceFlag=FALSE;
+
+static const char find_usage[] = "find [path...] [expression]\n"
+"default path is the current directory; default expression is -print\n"
+"expression may consist of:\n";
+
+
+
+static int fileAction(const char *fileName)
+{
+ if (pattern==NULL)
+ fprintf(stdout, "%s\n", fileName);
+ else if (match(fileName, pattern) == TRUE)
+ fprintf(stdout, "%s\n", fileName);
+ return( TRUE);
+}
+
+static int dirAction(const char *fileName)
+{
+ DIR *dir;
+ struct dirent *entry;
+
+ if (pattern==NULL)
+ fprintf(stdout, "%s\n", fileName);
+ else if (match(fileName, pattern) == TRUE)
+ fprintf(stdout, "%s\n", fileName);
+
+ dir = opendir( fileName);
+ if (!dir) {
+ perror("Can't open directory");
+ exit(FALSE);
+ }
+ while ((entry = readdir(dir)) != NULL) {
+ char dirName[NAME_MAX];
+ sprintf(dirName, "%s/%s", fileName, entry->d_name);
+ recursiveAction( dirName, TRUE, dereferenceFlag, fileAction, dirAction);
+ }
+ return( TRUE);
+}
+
+int find_main(int argc, char **argv)
+{
+ if (argc <= 1) {
+ dirAction( ".");
+ }
+
+ /* peel off the "find" */
+ argc--;
+ argv++;
+
+ if (**argv != '-') {
+ directory=*argv;
+ argc--;
+ argv++;
+ }
+
+ /* Parse any options */
+ while (**argv == '-') {
+ int stopit=FALSE;
+ while (*++(*argv) && stopit==FALSE) switch (**argv) {
+ case 'f':
+ if (strcmp(*argv, "follow")==0) {
+ argc--;
+ argv++;
+ dereferenceFlag=TRUE;
+ }
+ break;
+ case 'n':
+ if (strcmp(*argv, "name")==0) {
+ if (argc-- > 1) {
+ pattern=*(++argv);
+ stopit=-TRUE;
+ } else {
+ fprintf(stderr, "Usage: %s\n", find_usage);
+ exit( FALSE);
+ }
+ }
+ break;
+ case '-':
+ /* Ignore all long options */
+ break;
+ default:
+ fprintf(stderr, "Usage: %s\n", find_usage);
+ exit( FALSE);
+ }
+ if (argc-- > 1)
+ argv++;
+ if (**argv != '-')
+ break;
+ else
+ break;
+ }
+
+ dirAction( directory);
+ exit(TRUE);
+}
+
+
+
+#ifdef foobar
+
#include "internal.h"
#include <errno.h>
#include <stdio.h>
return(0);
}
+
+
+#endif
extern int
-grep_main(struct FileInfo * unused, int argc, char ** argv)
+grep_main(int argc, char ** argv)
{
FILE * fp;
const char * word;
extern int
-grep_main(struct FileInfo * unused, int argc, char ** argv)
+grep_main(int argc, char ** argv)
{
FILE * fp;
const char * word;
# undef LZW
#endif
-/* $Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $ */
+/* $Id: gzip.c,v 1.2 1999/10/06 20:25:32 andersen Exp $ */
/* tailor.h -- target dependent definitions
* Copyright (C) 1992-1993 Jean-loup Gailly.
* This is free software; you can redistribute it and/or modify it under the
* The target dependent functions should be defined in tailor.c.
*/
-/* $Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $ */
+/* $Id: gzip.c,v 1.2 1999/10/06 20:25:32 andersen Exp $ */
#if defined(__MSDOS__) && !defined(MSDOS)
# define MSDOS
#endif
#ifdef RCSID
-static char rcsid[] = "$Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
+static char rcsid[] = "$Id: gzip.c,v 1.2 1999/10/06 20:25:32 andersen Exp $";
#endif
/* ===========================================================================
#include <stdio.h>
#ifdef RCSID
-static char rcsid[] = "$Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
+static char rcsid[] = "$Id: gzip.c,v 1.2 1999/10/06 20:25:32 andersen Exp $";
#endif
/* ===========================================================================
*/
#ifdef RCSID
-static char rcsid[] = "$Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
+static char rcsid[] = "$Id: gzip.c,v 1.2 1999/10/06 20:25:32 andersen Exp $";
#endif
#include <ctype.h>
// int main (argc, argv)
// int argc;
// char **argv;
-int gzip_main(struct FileInfo * i, int argc, char * * argv)
+int gzip_main(int argc, char * * argv)
{
foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
if (foreground) {
#include <ctype.h>
#ifdef RCSID
-static char rcsid[] = "$Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
+static char rcsid[] = "$Id: gzip.c,v 1.2 1999/10/06 20:25:32 andersen Exp $";
#endif
/* ===========================================================================
*/
#ifdef RCSID
-static char rcsid[] = "$Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
+static char rcsid[] = "$Id: gzip.c,v 1.2 1999/10/06 20:25:32 andersen Exp $";
#endif
#include <ctype.h>
*/
#ifdef RCSID
-static char rcsid[] = "$Id: gzip.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
+static char rcsid[] = "$Id: gzip.c,v 1.2 1999/10/06 20:25:32 andersen Exp $";
#endif
#include <ctype.h>
int recursiveAction(const char *fileName, BOOL recurse, BOOL followLinks,
int (*fileAction) (const char *fileName),
int (*dirAction) (const char *fileName));
+BOOL match(const char* text, const char * pattern);
+const char* timeString(time_t timeVal);
#endif
static void writeTarFile(int fileCount, char ** fileTable);
static void writeTarBlock(const char * buf, int len);
static BOOL putOctal(char * cp, int len, long value);
-extern const char * modeString(int mode);
-extern const char * timeString(time_t timeVal);
-extern int fullWrite(int fd, const char * buf, int len);
-extern int fullRead(int fd, char * buf, int len);
extern int
-tar_main(struct FileInfo *unused, int argc, char ** argv)
+tar_main(int argc, char ** argv)
{
const char * options;
-/*
- * Return the standard ls-like mode string from a file mode.
- * This is static and so is overwritten on each call.
- */
-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';
-#ifdef S_ISLNK
- if (S_ISLNK(mode))
- buf[0] = 'l';
-#endif
-#ifdef S_ISSOCK
- if (S_ISSOCK(mode))
- buf[0] = 's';
-#endif
-
- /*
- * 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');
-
- return buf;
-}
-
-
-/*
- * 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.
- */
-const char *
-timeString(time_t timeVal)
-{
- time_t now;
- char * str;
- static char buf[26];
-
- time(&now);
-
- str = ctime(&timeVal);
-
- strcpy(buf, &str[4]);
- buf[12] = '\0';
-
- if ((timeVal > now) || (timeVal < now - 365*24*60*60L))
- {
- strcpy(&buf[7], &str[20]);
- buf[11] = '\0';
- }
-
- return buf;
-}
-
-
-
-/*
- * Write all of the supplied buffer out to a file.
- * This does multiple writes as necessary.
- * Returns the amount written, or -1 on an error.
- */
-int
-fullWrite(int fd, const char * buf, int len)
-{
- int cc;
- int total;
-
- total = 0;
-
- while (len > 0)
- {
- cc = write(fd, buf, len);
-
- if (cc < 0)
- return -1;
-
- buf += cc;
- total+= cc;
- len -= cc;
- }
-
- return total;
-}
-
-
-/*
- * Read all of the supplied buffer from a file.
- * This does multiple reads as necessary.
- * Returns the amount read, or -1 on an error.
- * A short read is returned on an end of file.
- */
-int
-fullRead(int fd, char * buf, int len)
-{
- int cc;
- int total;
-
- total = 0;
-
- while (len > 0)
- {
- cc = read(fd, buf, len);
-
- if (cc < 0)
- return -1;
-
- if (cc == 0)
- break;
-
- buf += cc;
- total+= cc;
- len -= cc;
- }
-
- return total;
-}
-
-
-
#endif
/* END CODE */
const char dmesg_usage[] = "dmesg";
int
-dmesg_main(struct FileInfo * info, int argc, char * * argv)
+dmesg_main(int argc, char * * argv)
{
char buf[4096];
break;
case '?':
default:
- usage(dmesg_usage);
+ fprintf(stderr, "%s\n", dmesg_usage);
exit(1);
}
}
argv += optind;
if (argc > 1) {
- usage(dmesg_usage);
+ fprintf(stderr, "%s\n", dmesg_usage);
exit(1);
}
}
+/*
+ * 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.
+ */
+const char *
+timeString(time_t timeVal)
+{
+ time_t now;
+ char * str;
+ static char buf[26];
+
+ time(&now);
+
+ str = ctime(&timeVal);
+
+ strcpy(buf, &str[4]);
+ buf[12] = '\0';
+
+ if ((timeVal > now) || (timeVal < now - 365*24*60*60L))
+ {
+ strcpy(&buf[7], &str[20]);
+ buf[11] = '\0';
+ }
+
+ return buf;
+}
+
+
+/*
+ * Routine to see if a text string is matched by a wildcard pattern.
+ * Returns TRUE if the text is matched, or FALSE if it is not matched
+ * or if the pattern is invalid.
+ * * matches zero or more characters
+ * ? matches a single character
+ * [abc] matches 'a', 'b' or 'c'
+ * \c quotes character c
+ * Adapted from code written by Ingo Wilken.
+ */
+BOOL
+match(const char * text, const char * pattern)
+{
+ const char * retryPat;
+ const char * retryText;
+ int ch;
+ BOOL found;
+
+ retryPat = NULL;
+ retryText = NULL;
+
+ while (*text || *pattern)
+ {
+ ch = *pattern++;
+
+ switch (ch)
+ {
+ case '*':
+ retryPat = pattern;
+ retryText = text;
+ break;
+
+ case '[':
+ found = FALSE;
+
+ while ((ch = *pattern++) != ']')
+ {
+ if (ch == '\\')
+ ch = *pattern++;
+
+ if (ch == '\0')
+ return FALSE;
+
+ if (*text == ch)
+ found = TRUE;
+ }
+
+ if (!found)
+ {
+ pattern = retryPat;
+ text = ++retryText;
+ }
+
+ /* fall into next case */
+
+ case '?':
+ if (*text++ == '\0')
+ return FALSE;
+
+ break;
+
+ case '\\':
+ ch = *pattern++;
+
+ if (ch == '\0')
+ return FALSE;
+
+ /* fall into next case */
+
+ default:
+ if (*text == ch)
+ {
+ if (*text)
+ text++;
+ break;
+ }
+
+ if (*text)
+ {
+ pattern = retryPat;
+ text = ++retryText;
+ break;
+ }
+
+ return FALSE;
+ }
+
+ if (pattern == NULL)
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
/*
* Write all of the supplied buffer out to a file.
* This does multiple writes as necessary.
/* END CODE */
+
+
+
+
+
+
+
+
+
+
+
*/
#ifdef RCSID
-static char rcsid[] = "$Id: zcat.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
+static char rcsid[] = "$Id: zcat.c,v 1.2 1999/10/06 20:25:32 andersen Exp $";
#endif
#include <ctype.h>
* The target dependent functions should be defined in tailor.c.
*/
-/* $Id: zcat.c,v 1.1 1999/10/05 16:24:56 andersen Exp $ */
+/* $Id: zcat.c,v 1.2 1999/10/06 20:25:32 andersen Exp $ */
#define RECORD_IO 0
# undef LZW
#endif
-/* $Id: zcat.c,v 1.1 1999/10/05 16:24:56 andersen Exp $ */
+/* $Id: zcat.c,v 1.2 1999/10/06 20:25:32 andersen Exp $ */
/* #include "getopt.h" */
#define strequ(s1, s2) (strcmp((s1),(s2)) == 0)
/* ======================================================================== */
-int zcat_main (struct FileInfo * i, int argc, char * * argv)
+int zcat_main (int argc, char * * argv)
{
int file_count; /* number of files to precess */
*/
#ifdef RCSID
-static char rcsid[] = "$Id: zcat.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
+static char rcsid[] = "$Id: zcat.c,v 1.2 1999/10/06 20:25:32 andersen Exp $";
#endif
/* #include "crypt.h" */
*/
#ifdef RCSID
-static char rcsid[] = "$Id: zcat.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
+static char rcsid[] = "$Id: zcat.c,v 1.2 1999/10/06 20:25:32 andersen Exp $";
#endif
#include <ctype.h>
*/
#ifdef RCSID
-static char rcsid[] = "$Id: zcat.c,v 1.1 1999/10/05 16:24:56 andersen Exp $";
+static char rcsid[] = "$Id: zcat.c,v 1.2 1999/10/06 20:25:32 andersen Exp $";
#endif
#include <sys/types.h>