More stuff
This commit is contained in:
parent
e674eb78e4
commit
f5a3838e2f
137
coreutils/ls.c
137
coreutils/ls.c
@ -1,137 +1,3 @@
|
|||||||
/*
|
|
||||||
* 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'
|
* tiny-ls.c version 0.1.0: A minimalist 'ls'
|
||||||
* Copyright (C) 1996 Brian Candler <B.Candler@pobox.com>
|
* Copyright (C) 1996 Brian Candler <B.Candler@pobox.com>
|
||||||
@ -571,7 +437,7 @@ listerr:
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char ls_usage[] = "ls [-1a"
|
static const char ls_usage[] = "ls [-1a"
|
||||||
#ifdef FEATURE_TIMESTAMPS
|
#ifdef FEATURE_TIMESTAMPS
|
||||||
"c"
|
"c"
|
||||||
#endif
|
#endif
|
||||||
@ -672,4 +538,3 @@ print_usage_message:
|
|||||||
exit( FALSE);
|
exit( FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
137
ls.c
137
ls.c
@ -1,137 +1,3 @@
|
|||||||
/*
|
|
||||||
* 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'
|
* tiny-ls.c version 0.1.0: A minimalist 'ls'
|
||||||
* Copyright (C) 1996 Brian Candler <B.Candler@pobox.com>
|
* Copyright (C) 1996 Brian Candler <B.Candler@pobox.com>
|
||||||
@ -571,7 +437,7 @@ listerr:
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char ls_usage[] = "ls [-1a"
|
static const char ls_usage[] = "ls [-1a"
|
||||||
#ifdef FEATURE_TIMESTAMPS
|
#ifdef FEATURE_TIMESTAMPS
|
||||||
"c"
|
"c"
|
||||||
#endif
|
#endif
|
||||||
@ -672,4 +538,3 @@ print_usage_message:
|
|||||||
exit( FALSE);
|
exit( FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
62
more.c
62
more.c
@ -27,22 +27,33 @@
|
|||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
|
|
||||||
static const char more_usage[] = "[file ...]";
|
static const char more_usage[] = "[file ...]";
|
||||||
|
|
||||||
|
|
||||||
|
/* ED: sparc termios is broken: revert back to old termio handling. */
|
||||||
#ifdef BB_MORE_TERM
|
#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;
|
FILE *cin;
|
||||||
struct termios initial_settings, new_settings;
|
struct termios initial_settings, new_settings;
|
||||||
|
|
||||||
void gotsig(int sig) {
|
void gotsig(int sig) {
|
||||||
tcsetattr(fileno(cin), TCSANOW, &initial_settings);
|
stty(fileno(cin), &initial_settings);
|
||||||
exit( TRUE);
|
exit( TRUE);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -50,13 +61,9 @@ static const char more_usage[] = "[file ...]";
|
|||||||
extern int more_main(int argc, char **argv)
|
extern int more_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int c, lines=0, input=0;
|
int c, lines=0, input=0;
|
||||||
int next_page=0, rows = 24;
|
int next_page=0;
|
||||||
#ifdef BB_MORE_TERM
|
|
||||||
int cols=79;
|
|
||||||
struct winsize win;
|
|
||||||
#endif
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
FILE *file = stdin;
|
FILE *file;
|
||||||
|
|
||||||
if ( strcmp(*argv,"--help")==0 || strcmp(*argv,"-h")==0 ) {
|
if ( strcmp(*argv,"--help")==0 || strcmp(*argv,"-h")==0 ) {
|
||||||
usage (more_usage);
|
usage (more_usage);
|
||||||
@ -64,39 +71,48 @@ extern int more_main(int argc, char **argv)
|
|||||||
argc--;
|
argc--;
|
||||||
argv++;
|
argv++;
|
||||||
|
|
||||||
while (argc-- > 0) {
|
while (argc >= 0) {
|
||||||
|
if (argc==0) {
|
||||||
|
file = stdin;
|
||||||
|
}
|
||||||
|
else
|
||||||
file = fopen(*argv, "r");
|
file = fopen(*argv, "r");
|
||||||
|
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
perror("Can't open file");
|
perror("Can't open file");
|
||||||
exit(FALSE);
|
exit(FALSE);
|
||||||
}
|
}
|
||||||
fstat(fileno(file), &st);
|
fstat(fileno(file), &st);
|
||||||
fprintf(stderr, "hi\n");
|
|
||||||
|
|
||||||
#ifdef BB_MORE_TERM
|
#ifdef BB_MORE_TERM
|
||||||
cin = fopen("/dev/tty", "r");
|
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);
|
tcgetattr(fileno(cin),&initial_settings);
|
||||||
|
#endif
|
||||||
new_settings = initial_settings;
|
new_settings = initial_settings;
|
||||||
new_settings.c_lflag &= ~ICANON;
|
new_settings.c_lflag &= ~ICANON;
|
||||||
new_settings.c_lflag &= ~ECHO;
|
new_settings.c_lflag &= ~ECHO;
|
||||||
tcsetattr(fileno(cin), TCSANOW, &new_settings);
|
stty(fileno(cin), &new_settings);
|
||||||
|
|
||||||
(void) signal(SIGINT, gotsig);
|
(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
|
#endif
|
||||||
while ((c = getc(file)) != EOF) {
|
while ((c = getc(file)) != EOF) {
|
||||||
if ( next_page ) {
|
if ( next_page ) {
|
||||||
int len=0;
|
int len=0;
|
||||||
next_page = 0;
|
next_page = 0;
|
||||||
lines=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 )),
|
(int) (100*( (double) ftell(file) / (double) st.st_size )),
|
||||||
st.st_size,
|
st.st_size);
|
||||||
|
}
|
||||||
|
len += fprintf(stdout, "%s",
|
||||||
#ifdef BB_MORE_TERM
|
#ifdef BB_MORE_TERM
|
||||||
""
|
""
|
||||||
#else
|
#else
|
||||||
@ -105,13 +121,13 @@ extern int more_main(int argc, char **argv)
|
|||||||
);
|
);
|
||||||
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
input = getc( stdin);
|
input = getc( cin);
|
||||||
|
|
||||||
#ifdef BB_MORE_TERM
|
#ifdef BB_MORE_TERM
|
||||||
/* Erase the "More" message */
|
/* Erase the "More" message */
|
||||||
while(len-- > 0)
|
while(len-- > 0)
|
||||||
putc('\b', stdout);
|
putc('\b', stdout);
|
||||||
while(len++ < cols)
|
while(len++ < 79)
|
||||||
putc(' ', stdout);
|
putc(' ', stdout);
|
||||||
while(len-- > 0)
|
while(len-- > 0)
|
||||||
putc('\b', stdout);
|
putc('\b', stdout);
|
||||||
@ -123,7 +139,7 @@ extern int more_main(int argc, char **argv)
|
|||||||
goto end;
|
goto end;
|
||||||
if (input==' ' && c == '\n' )
|
if (input==' ' && c == '\n' )
|
||||||
next_page = 1;
|
next_page = 1;
|
||||||
if ( c == '\n' && ++lines == (rows + 1) )
|
if ( c == '\n' && ++lines == 24 )
|
||||||
next_page = 1;
|
next_page = 1;
|
||||||
putc(c, stdout);
|
putc(c, stdout);
|
||||||
}
|
}
|
||||||
|
@ -27,22 +27,33 @@
|
|||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
|
|
||||||
static const char more_usage[] = "[file ...]";
|
static const char more_usage[] = "[file ...]";
|
||||||
|
|
||||||
|
|
||||||
|
/* ED: sparc termios is broken: revert back to old termio handling. */
|
||||||
#ifdef BB_MORE_TERM
|
#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;
|
FILE *cin;
|
||||||
struct termios initial_settings, new_settings;
|
struct termios initial_settings, new_settings;
|
||||||
|
|
||||||
void gotsig(int sig) {
|
void gotsig(int sig) {
|
||||||
tcsetattr(fileno(cin), TCSANOW, &initial_settings);
|
stty(fileno(cin), &initial_settings);
|
||||||
exit( TRUE);
|
exit( TRUE);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -50,13 +61,9 @@ static const char more_usage[] = "[file ...]";
|
|||||||
extern int more_main(int argc, char **argv)
|
extern int more_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int c, lines=0, input=0;
|
int c, lines=0, input=0;
|
||||||
int next_page=0, rows = 24;
|
int next_page=0;
|
||||||
#ifdef BB_MORE_TERM
|
|
||||||
int cols=79;
|
|
||||||
struct winsize win;
|
|
||||||
#endif
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
FILE *file = stdin;
|
FILE *file;
|
||||||
|
|
||||||
if ( strcmp(*argv,"--help")==0 || strcmp(*argv,"-h")==0 ) {
|
if ( strcmp(*argv,"--help")==0 || strcmp(*argv,"-h")==0 ) {
|
||||||
usage (more_usage);
|
usage (more_usage);
|
||||||
@ -64,39 +71,48 @@ extern int more_main(int argc, char **argv)
|
|||||||
argc--;
|
argc--;
|
||||||
argv++;
|
argv++;
|
||||||
|
|
||||||
while (argc-- > 0) {
|
while (argc >= 0) {
|
||||||
|
if (argc==0) {
|
||||||
|
file = stdin;
|
||||||
|
}
|
||||||
|
else
|
||||||
file = fopen(*argv, "r");
|
file = fopen(*argv, "r");
|
||||||
|
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
perror("Can't open file");
|
perror("Can't open file");
|
||||||
exit(FALSE);
|
exit(FALSE);
|
||||||
}
|
}
|
||||||
fstat(fileno(file), &st);
|
fstat(fileno(file), &st);
|
||||||
fprintf(stderr, "hi\n");
|
|
||||||
|
|
||||||
#ifdef BB_MORE_TERM
|
#ifdef BB_MORE_TERM
|
||||||
cin = fopen("/dev/tty", "r");
|
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);
|
tcgetattr(fileno(cin),&initial_settings);
|
||||||
|
#endif
|
||||||
new_settings = initial_settings;
|
new_settings = initial_settings;
|
||||||
new_settings.c_lflag &= ~ICANON;
|
new_settings.c_lflag &= ~ICANON;
|
||||||
new_settings.c_lflag &= ~ECHO;
|
new_settings.c_lflag &= ~ECHO;
|
||||||
tcsetattr(fileno(cin), TCSANOW, &new_settings);
|
stty(fileno(cin), &new_settings);
|
||||||
|
|
||||||
(void) signal(SIGINT, gotsig);
|
(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
|
#endif
|
||||||
while ((c = getc(file)) != EOF) {
|
while ((c = getc(file)) != EOF) {
|
||||||
if ( next_page ) {
|
if ( next_page ) {
|
||||||
int len=0;
|
int len=0;
|
||||||
next_page = 0;
|
next_page = 0;
|
||||||
lines=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 )),
|
(int) (100*( (double) ftell(file) / (double) st.st_size )),
|
||||||
st.st_size,
|
st.st_size);
|
||||||
|
}
|
||||||
|
len += fprintf(stdout, "%s",
|
||||||
#ifdef BB_MORE_TERM
|
#ifdef BB_MORE_TERM
|
||||||
""
|
""
|
||||||
#else
|
#else
|
||||||
@ -105,13 +121,13 @@ extern int more_main(int argc, char **argv)
|
|||||||
);
|
);
|
||||||
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
input = getc( stdin);
|
input = getc( cin);
|
||||||
|
|
||||||
#ifdef BB_MORE_TERM
|
#ifdef BB_MORE_TERM
|
||||||
/* Erase the "More" message */
|
/* Erase the "More" message */
|
||||||
while(len-- > 0)
|
while(len-- > 0)
|
||||||
putc('\b', stdout);
|
putc('\b', stdout);
|
||||||
while(len++ < cols)
|
while(len++ < 79)
|
||||||
putc(' ', stdout);
|
putc(' ', stdout);
|
||||||
while(len-- > 0)
|
while(len-- > 0)
|
||||||
putc('\b', stdout);
|
putc('\b', stdout);
|
||||||
@ -123,7 +139,7 @@ extern int more_main(int argc, char **argv)
|
|||||||
goto end;
|
goto end;
|
||||||
if (input==' ' && c == '\n' )
|
if (input==' ' && c == '\n' )
|
||||||
next_page = 1;
|
next_page = 1;
|
||||||
if ( c == '\n' && ++lines == (rows + 1) )
|
if ( c == '\n' && ++lines == 24 )
|
||||||
next_page = 1;
|
next_page = 1;
|
||||||
putc(c, stdout);
|
putc(c, stdout);
|
||||||
}
|
}
|
||||||
|
16
zcat.c
16
zcat.c
@ -59,7 +59,7 @@ static char *license_msg[] = {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef RCSID
|
#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
|
#endif
|
||||||
|
|
||||||
#include <ctype.h>
|
#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.
|
* 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
|
#define RECORD_IO 0
|
||||||
|
|
||||||
@ -436,7 +436,7 @@ extern int unlzw OF((int in, int out));
|
|||||||
# undef LZW
|
# undef LZW
|
||||||
#endif
|
#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" */
|
/* #include "getopt.h" */
|
||||||
|
|
||||||
@ -895,7 +895,7 @@ RETSIGTYPE abort_gzip()
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef RCSID
|
#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
|
#endif
|
||||||
|
|
||||||
/* #include "crypt.h" */
|
/* #include "crypt.h" */
|
||||||
@ -1021,7 +1021,7 @@ int unzip(in, out)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef RCSID
|
#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
|
#endif
|
||||||
|
|
||||||
#include <ctype.h>
|
#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;
|
extern int errno;
|
||||||
#endif
|
#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
|
* 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)
|
* 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,
|
0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
|
||||||
0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
|
0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
|
||||||
0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
|
0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
|
||||||
@ -1408,7 +1408,7 @@ ulg crc_32_tab[] = {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef RCSID
|
#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
|
#endif
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user