diff options
-rw-r--r-- | coreutils/ls.c | 137 | ||||
-rw-r--r-- | ls.c | 137 | ||||
-rw-r--r-- | more.c | 62 | ||||
-rw-r--r-- | util-linux/more.c | 62 | ||||
-rw-r--r-- | zcat.c | 16 |
5 files changed, 88 insertions, 326 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c index a8e7e04..0cde196 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -1,138 +1,4 @@ /* - * Mini ls 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 - * - */ - -// I started writing a newer small one, but it isn't done yet.... -// -Erik -#if fooBar - -#include <stdio.h> -#include <unistd.h> -#include <dirent.h> -#include "internal.h" - - -static const char ls_usage[] = "ls [OPTION]... [FILE]...\n" -"List information about the FILEs (the current directory by default).\n"; - -int oneFlag=FALSE; -int allFlag=FALSE; -int directoryFlag=FALSE; -int longFlag=FALSE; -int typeFlag=FALSE; -int dereferenceFlag=FALSE; -int recursiveFlag=FALSE; - -static int fileAction(const char *fileName) -{ - if ( allFlag==FALSE && ((strcmp(fileName, "..") == 0) - || (strcmp(fileName, ".") == 0)) ) { - return( TRUE); - } - //struct stat statBuf; - //if (stat(fileName, &statBuf) > 0) { - fprintf(stdout, "%s\n", fileName); - return( TRUE); - //} - //else { -// perror(fileName); -// return( FALSE); -// } -} - -static int dirAction(const char *fileName) -{ - DIR *dir; - struct dirent *entry; - - fprintf(stdout, "%s\n", fileName); - - dir = opendir( fileName); - if (!dir) { - perror("Can't open directory"); - exit(FALSE); - } - while ((entry = readdir(dir)) != NULL) { - recursiveAction( entry->d_name, recursiveFlag, dereferenceFlag, FALSE, fileAction, dirAction); - } - return( TRUE); -} - -int ls_main(int argc, char **argv) -{ - if (argc <= 1) { - char buf[NAME_MAX]; - getcwd( buf, NAME_MAX); - dirAction( buf); - } - - /* peel of the "ls" */ - argc--; - argv++; - - /* Parse any options */ - while (**argv == '-') { - while (*++(*argv)) switch (**argv) { - case '1': - oneFlag = TRUE; - break; - case 'a': - allFlag = TRUE; - break; - case 'd': - directoryFlag = TRUE; - break; - case 'l': - longFlag = TRUE; - break; - case 'F': - typeFlag = TRUE; - break; - case 'L': - dereferenceFlag = TRUE; - break; - case 'R': - recursiveFlag = TRUE; - break; - default: - usage (ls_usage); - } - argc--; - argv++; - } - - /* Ok, ready to do the deed now */ - fprintf(stderr, "B\n"); - while (argc-- > 1) { - fprintf(stderr, "C\n"); - recursiveAction( *argv, recursiveFlag, dereferenceFlag, fileAction, dirAction); - } - exit(TRUE); -} - - - -#else - - -/* * tiny-ls.c version 0.1.0: A minimalist 'ls' * Copyright (C) 1996 Brian Candler <B.Candler@pobox.com> * @@ -571,7 +437,7 @@ listerr: return 1; } -const char ls_usage[] = "ls [-1a" +static const char ls_usage[] = "ls [-1a" #ifdef FEATURE_TIMESTAMPS "c" #endif @@ -672,4 +538,3 @@ print_usage_message: exit( FALSE); } -#endif @@ -1,138 +1,4 @@ /* - * Mini ls 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 - * - */ - -// I started writing a newer small one, but it isn't done yet.... -// -Erik -#if fooBar - -#include <stdio.h> -#include <unistd.h> -#include <dirent.h> -#include "internal.h" - - -static const char ls_usage[] = "ls [OPTION]... [FILE]...\n" -"List information about the FILEs (the current directory by default).\n"; - -int oneFlag=FALSE; -int allFlag=FALSE; -int directoryFlag=FALSE; -int longFlag=FALSE; -int typeFlag=FALSE; -int dereferenceFlag=FALSE; -int recursiveFlag=FALSE; - -static int fileAction(const char *fileName) -{ - if ( allFlag==FALSE && ((strcmp(fileName, "..") == 0) - || (strcmp(fileName, ".") == 0)) ) { - return( TRUE); - } - //struct stat statBuf; - //if (stat(fileName, &statBuf) > 0) { - fprintf(stdout, "%s\n", fileName); - return( TRUE); - //} - //else { -// perror(fileName); -// return( FALSE); -// } -} - -static int dirAction(const char *fileName) -{ - DIR *dir; - struct dirent *entry; - - fprintf(stdout, "%s\n", fileName); - - dir = opendir( fileName); - if (!dir) { - perror("Can't open directory"); - exit(FALSE); - } - while ((entry = readdir(dir)) != NULL) { - recursiveAction( entry->d_name, recursiveFlag, dereferenceFlag, FALSE, fileAction, dirAction); - } - return( TRUE); -} - -int ls_main(int argc, char **argv) -{ - if (argc <= 1) { - char buf[NAME_MAX]; - getcwd( buf, NAME_MAX); - dirAction( buf); - } - - /* peel of the "ls" */ - argc--; - argv++; - - /* Parse any options */ - while (**argv == '-') { - while (*++(*argv)) switch (**argv) { - case '1': - oneFlag = TRUE; - break; - case 'a': - allFlag = TRUE; - break; - case 'd': - directoryFlag = TRUE; - break; - case 'l': - longFlag = TRUE; - break; - case 'F': - typeFlag = TRUE; - break; - case 'L': - dereferenceFlag = TRUE; - break; - case 'R': - recursiveFlag = TRUE; - break; - default: - usage (ls_usage); - } - argc--; - argv++; - } - - /* Ok, ready to do the deed now */ - fprintf(stderr, "B\n"); - while (argc-- > 1) { - fprintf(stderr, "C\n"); - recursiveAction( *argv, recursiveFlag, dereferenceFlag, fileAction, dirAction); - } - exit(TRUE); -} - - - -#else - - -/* * tiny-ls.c version 0.1.0: A minimalist 'ls' * Copyright (C) 1996 Brian Candler <B.Candler@pobox.com> * @@ -571,7 +437,7 @@ listerr: return 1; } -const char ls_usage[] = "ls [-1a" +static const char ls_usage[] = "ls [-1a" #ifdef FEATURE_TIMESTAMPS "c" #endif @@ -672,4 +538,3 @@ print_usage_message: exit( FALSE); } -#endif @@ -27,22 +27,33 @@ #include "internal.h" #include <stdio.h> +#include <fcntl.h> #include <signal.h> static const char more_usage[] = "[file ...]"; +/* ED: sparc termios is broken: revert back to old termio handling. */ #ifdef BB_MORE_TERM - #include <termios.h> - #include <signal.h> - #include <sys/ioctl.h> + + +#if defined (__sparc__) +# define USE_OLD_TERMIO +# include <termio.h> +# include <sys/ioctl.h> +# define termios termio +# define stty(fd,argp) ioctl(fd,TCSETAF,argp) +#else +# include <termios.h> +# define stty(fd,argp) tcsetattr(fd,TCSANOW,argp) +#endif FILE *cin; struct termios initial_settings, new_settings; void gotsig(int sig) { - tcsetattr(fileno(cin), TCSANOW, &initial_settings); + stty(fileno(cin), &initial_settings); exit( TRUE); } #endif @@ -50,13 +61,9 @@ static const char more_usage[] = "[file ...]"; extern int more_main(int argc, char **argv) { int c, lines=0, input=0; - int next_page=0, rows = 24; -#ifdef BB_MORE_TERM - int cols=79; - struct winsize win; -#endif + int next_page=0; struct stat st; - FILE *file = stdin; + FILE *file; if ( strcmp(*argv,"--help")==0 || strcmp(*argv,"-h")==0 ) { usage (more_usage); @@ -64,39 +71,48 @@ extern int more_main(int argc, char **argv) argc--; argv++; - while (argc-- > 0) { + while (argc >= 0) { + if (argc==0) { + file = stdin; + } + else file = fopen(*argv, "r"); + if (file == NULL) { perror("Can't open file"); exit(FALSE); } fstat(fileno(file), &st); - fprintf(stderr, "hi\n"); #ifdef BB_MORE_TERM cin = fopen("/dev/tty", "r"); + if (!cin) + cin = fopen("/dev/console", "r"); +#ifdef USE_OLD_TERMIO + ioctl(fileno(cin),TCGETA,&initial_settings); +#else tcgetattr(fileno(cin),&initial_settings); +#endif new_settings = initial_settings; new_settings.c_lflag &= ~ICANON; new_settings.c_lflag &= ~ECHO; - tcsetattr(fileno(cin), TCSANOW, &new_settings); + stty(fileno(cin), &new_settings); (void) signal(SIGINT, gotsig); - ioctl(STDOUT_FILENO, TIOCGWINSZ, &win); - if (win.ws_row > 4) rows = win.ws_row - 2; - if (win.ws_col > 0) cols = win.ws_col - 1; - - #endif while ((c = getc(file)) != EOF) { if ( next_page ) { int len=0; next_page = 0; lines=0; - len = fprintf(stdout, "--More-- (%d%% of %ld bytes)%s", + len = fprintf(stdout, "--More-- "); + if (file != stdin) { + len += fprintf(stdout, "(%d%% of %ld bytes)", (int) (100*( (double) ftell(file) / (double) st.st_size )), - st.st_size, + st.st_size); + } + len += fprintf(stdout, "%s", #ifdef BB_MORE_TERM "" #else @@ -105,13 +121,13 @@ extern int more_main(int argc, char **argv) ); fflush(stdout); - input = getc( stdin); + input = getc( cin); #ifdef BB_MORE_TERM /* Erase the "More" message */ while(len-- > 0) putc('\b', stdout); - while(len++ < cols) + while(len++ < 79) putc(' ', stdout); while(len-- > 0) putc('\b', stdout); @@ -123,7 +139,7 @@ extern int more_main(int argc, char **argv) goto end; if (input==' ' && c == '\n' ) next_page = 1; - if ( c == '\n' && ++lines == (rows + 1) ) + if ( c == '\n' && ++lines == 24 ) next_page = 1; putc(c, stdout); } diff --git a/util-linux/more.c b/util-linux/more.c index 772d51b..745ae2b 100644 --- a/util-linux/more.c +++ b/util-linux/more.c @@ -27,22 +27,33 @@ #include "internal.h" #include <stdio.h> +#include <fcntl.h> #include <signal.h> static const char more_usage[] = "[file ...]"; +/* ED: sparc termios is broken: revert back to old termio handling. */ #ifdef BB_MORE_TERM - #include <termios.h> - #include <signal.h> - #include <sys/ioctl.h> + + +#if defined (__sparc__) +# define USE_OLD_TERMIO +# include <termio.h> +# include <sys/ioctl.h> +# define termios termio +# define stty(fd,argp) ioctl(fd,TCSETAF,argp) +#else +# include <termios.h> +# define stty(fd,argp) tcsetattr(fd,TCSANOW,argp) +#endif FILE *cin; struct termios initial_settings, new_settings; void gotsig(int sig) { - tcsetattr(fileno(cin), TCSANOW, &initial_settings); + stty(fileno(cin), &initial_settings); exit( TRUE); } #endif @@ -50,13 +61,9 @@ static const char more_usage[] = "[file ...]"; extern int more_main(int argc, char **argv) { int c, lines=0, input=0; - int next_page=0, rows = 24; -#ifdef BB_MORE_TERM - int cols=79; - struct winsize win; -#endif + int next_page=0; struct stat st; - FILE *file = stdin; + FILE *file; if ( strcmp(*argv,"--help")==0 || strcmp(*argv,"-h")==0 ) { usage (more_usage); @@ -64,39 +71,48 @@ extern int more_main(int argc, char **argv) argc--; argv++; - while (argc-- > 0) { + while (argc >= 0) { + if (argc==0) { + file = stdin; + } + else file = fopen(*argv, "r"); + if (file == NULL) { perror("Can't open file"); exit(FALSE); } fstat(fileno(file), &st); - fprintf(stderr, "hi\n"); #ifdef BB_MORE_TERM cin = fopen("/dev/tty", "r"); + if (!cin) + cin = fopen("/dev/console", "r"); +#ifdef USE_OLD_TERMIO + ioctl(fileno(cin),TCGETA,&initial_settings); +#else tcgetattr(fileno(cin),&initial_settings); +#endif new_settings = initial_settings; new_settings.c_lflag &= ~ICANON; new_settings.c_lflag &= ~ECHO; - tcsetattr(fileno(cin), TCSANOW, &new_settings); + stty(fileno(cin), &new_settings); (void) signal(SIGINT, gotsig); - ioctl(STDOUT_FILENO, TIOCGWINSZ, &win); - if (win.ws_row > 4) rows = win.ws_row - 2; - if (win.ws_col > 0) cols = win.ws_col - 1; - - #endif while ((c = getc(file)) != EOF) { if ( next_page ) { int len=0; next_page = 0; lines=0; - len = fprintf(stdout, "--More-- (%d%% of %ld bytes)%s", + len = fprintf(stdout, "--More-- "); + if (file != stdin) { + len += fprintf(stdout, "(%d%% of %ld bytes)", (int) (100*( (double) ftell(file) / (double) st.st_size )), - st.st_size, + st.st_size); + } + len += fprintf(stdout, "%s", #ifdef BB_MORE_TERM "" #else @@ -105,13 +121,13 @@ extern int more_main(int argc, char **argv) ); fflush(stdout); - input = getc( stdin); + input = getc( cin); #ifdef BB_MORE_TERM /* Erase the "More" message */ while(len-- > 0) putc('\b', stdout); - while(len++ < cols) + while(len++ < 79) putc(' ', stdout); while(len-- > 0) putc('\b', stdout); @@ -123,7 +139,7 @@ extern int more_main(int argc, char **argv) goto end; if (input==' ' && c == '\n' ) next_page = 1; - if ( c == '\n' && ++lines == (rows + 1) ) + if ( c == '\n' && ++lines == 24 ) next_page = 1; putc(c, stdout); } @@ -59,7 +59,7 @@ static char *license_msg[] = { */ #ifdef RCSID -static char rcsid[] = "$Id: zcat.c,v 1.3 1999/10/19 20:03:34 andersen Exp $"; +static char rcsid[] = "$Id: zcat.c,v 1.4 1999/10/19 22:26:25 andersen Exp $"; #endif #include <ctype.h> @@ -80,7 +80,7 @@ static char rcsid[] = "$Id: zcat.c,v 1.3 1999/10/19 20:03:34 andersen Exp $"; * The target dependent functions should be defined in tailor.c. */ -/* $Id: zcat.c,v 1.3 1999/10/19 20:03:34 andersen Exp $ */ +/* $Id: zcat.c,v 1.4 1999/10/19 22:26:25 andersen Exp $ */ #define RECORD_IO 0 @@ -436,7 +436,7 @@ extern int unlzw OF((int in, int out)); # undef LZW #endif -/* $Id: zcat.c,v 1.3 1999/10/19 20:03:34 andersen Exp $ */ +/* $Id: zcat.c,v 1.4 1999/10/19 22:26:25 andersen Exp $ */ /* #include "getopt.h" */ @@ -895,7 +895,7 @@ RETSIGTYPE abort_gzip() */ #ifdef RCSID -static char rcsid[] = "$Id: zcat.c,v 1.3 1999/10/19 20:03:34 andersen Exp $"; +static char rcsid[] = "$Id: zcat.c,v 1.4 1999/10/19 22:26:25 andersen Exp $"; #endif /* #include "crypt.h" */ @@ -1021,7 +1021,7 @@ int unzip(in, out) */ #ifdef RCSID -static char rcsid[] = "$Id: zcat.c,v 1.3 1999/10/19 20:03:34 andersen Exp $"; +static char rcsid[] = "$Id: zcat.c,v 1.4 1999/10/19 22:26:25 andersen Exp $"; #endif #include <ctype.h> @@ -1041,7 +1041,7 @@ static char rcsid[] = "$Id: zcat.c,v 1.3 1999/10/19 20:03:34 andersen Exp $"; extern int errno; #endif -extern ulg crc_32_tab[]; /* crc table, defined below */ +const ulg crc_32_tab[]; /* crc table, defined below */ /* =========================================================================== * Run a set of bytes through the crc shift register. If s is a NULL @@ -1255,7 +1255,7 @@ voidp xmalloc (size) /* ======================================================================== * Table of CRC-32's of all single-byte values (made by makecrc.c) */ -ulg crc_32_tab[] = { +const ulg crc_32_tab[] = { 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L, 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L, @@ -1408,7 +1408,7 @@ ulg crc_32_tab[] = { */ #ifdef RCSID -static char rcsid[] = "$Id: zcat.c,v 1.3 1999/10/19 20:03:34 andersen Exp $"; +static char rcsid[] = "$Id: zcat.c,v 1.4 1999/10/19 22:26:25 andersen Exp $"; #endif #include <sys/types.h> |