"\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;
"This version of grep matches strings (not full regexps).\n";
#endif
+int tellName=TRUE;
+int ignoreCase=FALSE;
+int tellLine=FALSE;
+
+static do_grep(char* needle, char* haystack )
+{
+ 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);
+ }
+ }
+}
+
extern int grep_main (int argc, char **argv)
{
char *needle;
char *name;
char *cp;
- int tellName=TRUE;
- int ignoreCase=FALSE;
- int tellLine=FALSE;
long line;
char haystack[BUF_SIZE];
needle = *argv++;
argc--;
+
while (argc-- > 0) {
+
+ if (argc==0) {
+ file = stdin;
+ }
+ else
+ file = fopen(*argv, "r");
+
+
name = *argv++;
fp = fopen (name, "r");
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);
- }
- }
-
if (ferror (fp))
perror (name);
"This version of grep matches strings (not full regexps).\n";
#endif
+int tellName=TRUE;
+int ignoreCase=FALSE;
+int tellLine=FALSE;
+
+static do_grep(char* needle, char* haystack )
+{
+ 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);
+ }
+ }
+}
+
extern int grep_main (int argc, char **argv)
{
char *needle;
char *name;
char *cp;
- int tellName=TRUE;
- int ignoreCase=FALSE;
- int tellLine=FALSE;
long line;
char haystack[BUF_SIZE];
needle = *argv++;
argc--;
+
while (argc-- > 0) {
+
+ if (argc==0) {
+ file = stdin;
+ }
+ else
+ file = fopen(*argv, "r");
+
+
name = *argv++;
fp = fopen (name, "r");
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);
- }
- }
-
if (ferror (fp))
perror (name);
if ((s = getenv("CONSOLE")) != NULL) {
console = s;
}
-#if defined (__sparc__)
+#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) {
if ((s = getenv("CONSOLE")) != NULL) {
console = s;
}
-#if defined (__sparc__)
+#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) {
"\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;
/* ED: sparc termios is broken: revert back to old termio handling. */
#ifdef BB_MORE_TERM
-
-#if defined (__sparc__)
+#if #cpu(sparc)
# define USE_OLD_TERMIO
# include <termio.h>
# include <sys/ioctl.h>
struct stat st;
FILE *file;
- 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;
}
stty(fileno(cin), &new_settings);
(void) signal(SIGINT, gotsig);
+ (void) signal(SIGQUIT, gotsig);
+ (void) signal(SIGTERM, gotsig);
+
#endif
while ((c = getc(file)) != EOF) {
}
if (input=='q')
goto end;
- if (input==' ' && c == '\n' )
+ if (input=='\n' && c == '\n' )
next_page = 1;
- if ( c == '\n' && ++lines == 24 )
+ if ( c == ' ' && ++lines == 24 )
next_page = 1;
putc(c, stdout);
}
fclose(file);
fflush(stdout);
- argc--;
argv++;
- }
+ } while (--argc > 0);
end:
#ifdef BB_MORE_TERM
gotsig(0);
/* ED: sparc termios is broken: revert back to old termio handling. */
#ifdef BB_MORE_TERM
-
-#if defined (__sparc__)
+#if #cpu(sparc)
# define USE_OLD_TERMIO
# include <termio.h>
# include <sys/ioctl.h>
struct stat st;
FILE *file;
- 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;
}
stty(fileno(cin), &new_settings);
(void) signal(SIGINT, gotsig);
+ (void) signal(SIGQUIT, gotsig);
+ (void) signal(SIGTERM, gotsig);
+
#endif
while ((c = getc(file)) != EOF) {
}
if (input=='q')
goto end;
- if (input==' ' && c == '\n' )
+ if (input=='\n' && c == '\n' )
next_page = 1;
- if ( c == '\n' && ++lines == 24 )
+ if ( c == ' ' && ++lines == 24 )
next_page = 1;
putc(c, stdout);
}
fclose(file);
fflush(stdout);
- argc--;
argv++;
- }
+ } while (--argc > 0);
end:
#ifdef BB_MORE_TERM
gotsig(0);