Lots of updates. Finished implementing BB_FEATURE_TRIVIAL_HELP

which lets you compile out most of the "--help" output, saving
up to 17k.

Renamed mnc to nc.
 -Erik
This commit is contained in:
Erik Andersen 2000-05-12 19:41:47 +00:00
parent 3d427ac5ef
commit 7ab9c7ee52
136 changed files with 1743 additions and 454 deletions

View File

@ -3,6 +3,8 @@
updated docs/busybox.pod accordingly. -beppu
* Added mktemp, contributed by Daniel Jacobowitz <dan@debian.org>
* Added setkeycodes, for those that have wierd keyboard buttons.
* Added cut and tr from minix, since due to the license change,
we can now use minix code. Minix tr saves 4k.
* Fix for ping warnings from Sascha Ziemann <szi@aibon.ping.de>
* Fixed update segfault
* Fixed mknod -- minor number was always 0
@ -18,9 +20,6 @@
* added a simple id implementation; doesn't support sup. groups yet
* logname used getlogin(3) which uses utmp. Now it doesn't.
* whoami used getpwuid(3) which uses libc NSS. Now it behaves.
* Due to the license change, I can now use minix code. Minux tr
replaces the BSD derived tr, saving 4k and eliminating bsearch(3)
from the list of used Libc symbols.
* Add support for "noatime" and "nodiratime" mount flags to mount.
* Changed 'umount -f' to mean force, and actually use umount2.
* Changed 'umount -l' to mean "Do not free loop device".
@ -29,6 +28,9 @@
* More doc updates
* cp -fa now works as expected for symlinks (it didn't before)
* zcat now works (wasn't working since option parsing was broken)
* Renamed "mnc" to the more correct "nc".
* Added BB_FEATURE_TRIVIAL_HELP which compiles out most all of the
help messages (i.e --help). Saves 17k over a full compile.
-Erik

View File

@ -26,7 +26,7 @@ export VERSION
# Set the following to `true' to make a debuggable build.
# Leave this set to `false' for production use.
# eg: `make DODEBUG=true tests'
DODEBUG = true
DODEBUG = false
# If you want a static binary, turn this on.
DOSTATIC = false

View File

@ -65,6 +65,9 @@ static const struct Applet applets[] = {
#ifdef BB_CP_MV
{"cp", cp_mv_main, _BB_DIR_BIN},
#endif
#ifdef BB_CUT
{"cut", cut_main, _BB_DIR_USR_BIN},
#endif
#ifdef BB_DATE
{"date", date_main, _BB_DIR_BIN},
#endif
@ -203,8 +206,8 @@ static const struct Applet applets[] = {
#ifdef BB_MKTEMP
{"mktemp", mktemp_main, _BB_DIR_BIN},
#endif
#ifdef BB_MNC
{"mnc", mnc_main, _BB_DIR_USR_BIN},
#ifdef BB_NC
{"nc", nc_main, _BB_DIR_USR_BIN},
#endif
#ifdef BB_MORE
{"more", more_main, _BB_DIR_BIN},

View File

@ -28,13 +28,17 @@
*/
#include "internal.h"
static const char gunzip_usage[] =
"gunzip [OPTION]... FILE\n\n"
"Uncompress FILE (or standard input if FILE is '-').\n\n"
"gunzip [OPTION]... FILE\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nUncompress FILE (or standard input if FILE is '-').\n\n"
"Options:\n"
"\t-c\tWrite output to standard output\n"
"\t-t\tTest compressed file integrity\n";
"\t-t\tTest compressed file integrity\n"
#endif
;
/* These defines are very important for BusyBox. Without these,
@ -43,8 +47,9 @@ static const char gunzip_usage[] =
#define SMALL_MEM
#define DYN_ALLOC
#define bb_need_name_too_long
#define BB_DECLARE_EXTERN
#define bb_need_memory_exhausted
#define bb_need_name_too_long
#include "messages.c"
@ -206,7 +211,7 @@ extern int method; /* compression method */
# define DECLARE(type, array, size) type * array
# define ALLOC(type, array, size) { \
array = (type*)calloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \
if (array == NULL) errorMsg("insufficient memory"); \
if (array == NULL) errorMsg(memory_exhausted, "gunzip"); \
}
# define FREE(array) {if (array != NULL) free(array), array=NULL;}
#else
@ -1053,7 +1058,7 @@ int in, out; /* input and output file descriptors */
int res = inflate();
if (res == 3) {
errorMsg("out of memory");
errorMsg(memory_exhausted, "gunzip");
} else if (res != 0) {
errorMsg("invalid compressed data--format violated");
}

View File

@ -30,6 +30,9 @@
*/
#include "internal.h"
#define BB_DECLARE_EXTERN
#define bb_need_memory_exhausted
#include "messages.c"
/* These defines are very important for BusyBox. Without these,
* huge chunks of ram are pre-allocated making the BusyBox bss
@ -39,12 +42,15 @@
static const char gzip_usage[] =
"gzip [OPTION]... FILE\n\n"
"Compress FILE with maximum compression.\n"
"gzip [OPTION]... FILE\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nCompress FILE with maximum compression.\n"
"When FILE is '-', reads standard input. Implies -c.\n\n"
"Options:\n"
"\t-c\tWrite output to standard output instead of FILE.gz\n";
"\t-c\tWrite output to standard output instead of FILE.gz\n"
#endif
;
/* I don't like nested includes, but the string and io functions are used
@ -121,7 +127,7 @@ extern int method; /* compression method */
# define DECLARE(type, array, size) type * array
# define ALLOC(type, array, size) { \
array = (type*)calloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \
if (array == NULL) errorMsg("insufficient memory"); \
if (array == NULL) errorMsg(memory_exhausted, "gzip"); \
}
# define FREE(array) {if (array != NULL) free(array), array=NULL;}
#else
@ -1778,7 +1784,6 @@ int part_nb; /* number of parts in .gz file */
long time_stamp; /* original time stamp (modification time) */
long ifile_size; /* input file size, -1 for devices (debug only) */
char *env; /* contents of GZIP env variable */
char **args = NULL; /* argv pointer if GZIP env variable defined */
char z_suffix[MAX_SUFFIX + 1]; /* default suffix (can be set with --suffix) */
int z_len; /* strlen(z_suffix) */
@ -3248,7 +3253,7 @@ char *env; /* name of environment variable */
nargv = (char **) calloc(*argcp + 1, sizeof(char *));
if (nargv == NULL)
errorMsg("out of memory");
errorMsg(memory_exhausted, "gzip");
oargv = *argvp;
*argvp = nargv;

View File

@ -60,8 +60,9 @@ static const char tar_usage[] =
#if defined BB_FEATURE_TAR_EXCLUDE
"[--exclude File] "
#endif
"[-f tarFile] [FILE] ...\n\n"
"Create, extract, or list files from a tar file. Note that\n"
"[-f tarFile] [FILE] ...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nCreate, extract, or list files from a tar file. Note that\n"
"this version of tar treats hard links as separate files.\n\n"
"Main operation mode:\n"
#ifdef BB_FEATURE_TAR_CREATE
@ -77,6 +78,7 @@ static const char tar_usage[] =
#endif
"\nInformative output:\n"
"\tv\t\tverbosely list files processed\n"
#endif
;
/* Tar file constants */

View File

@ -65,6 +65,9 @@ static const struct Applet applets[] = {
#ifdef BB_CP_MV
{"cp", cp_mv_main, _BB_DIR_BIN},
#endif
#ifdef BB_CUT
{"cut", cut_main, _BB_DIR_USR_BIN},
#endif
#ifdef BB_DATE
{"date", date_main, _BB_DIR_BIN},
#endif
@ -203,8 +206,8 @@ static const struct Applet applets[] = {
#ifdef BB_MKTEMP
{"mktemp", mktemp_main, _BB_DIR_BIN},
#endif
#ifdef BB_MNC
{"mnc", mnc_main, _BB_DIR_USR_BIN},
#ifdef BB_NC
{"nc", nc_main, _BB_DIR_USR_BIN},
#endif
#ifdef BB_MORE
{"more", more_main, _BB_DIR_BIN},

View File

@ -14,6 +14,7 @@
#define BB_CHVT
#define BB_CLEAR
#define BB_CP_MV
#define BB_CUT
#define BB_DATE
#define BB_DD
#define BB_DEALLOCVT
@ -60,7 +61,7 @@
#define BB_MKNOD
#define BB_MKSWAP
#define BB_MKTEMP
#define BB_MNC
#define BB_NC
#define BB_MORE
#define BB_MOUNT
#define BB_MT
@ -134,7 +135,7 @@
//
// This compiles out everything but the most
// trivial --help usage information (i.e. reduces binary size)
//#define BB_FEATURE_TRIVIAL_HELP
#define BB_FEATURE_TRIVIAL_HELP
//
// Use termios to manipulate the screen ('more' is prettier with this on)
//#define BB_FEATURE_USE_TERMIOS

View File

@ -22,8 +22,11 @@
#include <sys/ioctl.h>
#include <sys/kd.h>
static const char loadacm_usage[] = "loadacm\n\n"
"Loads an acm from standard input.\n";
static const char loadacm_usage[] = "loadacm\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nLoads an acm from standard input.\n"
#endif
;
typedef unsigned short unicode;

View File

@ -30,8 +30,11 @@
#define PSF_MAXMODE 0x03
#define PSF_SEPARATOR 0xFFFF
static const char loadfont_usage[] = "loadfont\n\n"
"Loads a console font from standard input.\n";
static const char loadfont_usage[] = "loadfont\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"Loads a console font from standard input.\n"
#endif
;
struct psf_header {
unsigned char magic1, magic2; /* Magic number */

View File

@ -29,8 +29,11 @@
#include <sys/ioctl.h>
static const char loadkmap_usage[] = "loadkmap\n\n"
"Loads a binary keyboard translation table from standard input.\n";
static const char loadkmap_usage[] = "loadkmap\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"Loads a binary keyboard translation table from standard input.\n"
#endif
;
int loadkmap_main(int argc, char **argv)

372
coreutils/cut.c Normal file
View File

@ -0,0 +1,372 @@
/* vi: set sw=4 ts=4: */
/*
* cut implementation for busybox
*
* Copyright (c) Michael J. Holme
*
* This version of cut is adapted from Minix cut and was modified
* by Erik Andersen <andersee@debian.org> to be used in busybox.
*
* 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
*
* Original copyright notice is retained at the end of this file.
*/
#include "internal.h"
#include <sys/types.h>
#include <ctype.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#define BB_DECLARE_EXTERN
#define bb_need_help
#include "messages.c"
#define MAX_FIELD 80 /* Pointers to the beginning of each field
* are stored in columns[], if a line holds
* more than MAX_FIELD columns the array
* boundary is exceed. But unlikely at 80 */
#define MAX_ARGS 32 /* Maximum number of fields following -f or
* -c switches */
int args[MAX_ARGS * 2];
int num_args;
/* Lots of new defines, should easen maintainance... */
#define DUMP_STDIN 0 /* define for mode: no options */
#define OPTIONF 1 /* define for mode: option -f */
#define OPTIONC 2 /* define for mode: option -c */
#define OPTIONB 3 /* define for mode: option -b */
#define NOTSET 0 /* option not selected */
#define SET 1 /* option selected */
/* Defines for the warnings */
#define DELIMITER_NOT_APPLICABLE 0
#define OVERRIDING_PREVIOUS_MODE 1
#define OPTION_NOT_APPLICABLE 2
#define UNKNOWN_OPTION 3
#define FILE_NOT_READABLE 4
/* Defines for the fatal errors */
#define SYNTAX_ERROR 101
#define POSITION_ERROR 102
#define LINE_TO_LONG_ERROR 103
#define RANGE_ERROR 104
#define MAX_FIELDS_EXEEDED_ERROR 105
#define MAX_ARGS_EXEEDED_ERROR 106
int mode; /* 0 = dump stdin to stdout, 1=-f, 2=-c */
char delim = '\t'; /* default delimiting character */
FILE *fd;
char *name;
char line[BUFSIZ];
int exit_status;
int cut_main(int argc, char **argv);
void warn(int warn_number, char *option);
void cuterror(int err);
void get_args(void);
void cut(void);
void warn(int warn_number, char *option)
{
static char *warn_msg[] = {
"%s: Option -d allowed only with -f\n",
"%s: -%s overrides earlier option\n",
"%s: -%s not allowed in current mode\n",
"%s: Cannot open %s\n"
};
fprintf(stderr, warn_msg[warn_number], name, option);
exit_status = warn_number + 1;
}
void cuterror(int err)
{
static char *err_mes[] = {
"%s: syntax error\n",
"%s: position must be >0\n",
"%s: line longer than BUFSIZ\n",
"%s: range must not decrease from left to right\n",
"%s: MAX_FIELD exceeded\n",
"%s: MAX_ARGS exceeded\n"
};
fprintf(stderr, err_mes[err - 101], name);
exit(err);
}
void get_args()
{
int i = 0;
int arg_ptr = 0;
int flag;
num_args = 0;
do {
if (num_args == MAX_ARGS)
cuterror(MAX_ARGS_EXEEDED_ERROR);
if (!isdigit(line[i]) && line[i] != '-')
cuterror(SYNTAX_ERROR);
args[arg_ptr] = 1;
args[arg_ptr + 1] = BUFSIZ;
flag = 1;
while (line[i] != ',' && line[i] != 0) {
if (isdigit(line[i])) {
args[arg_ptr] = 0;
while (isdigit(line[i]))
args[arg_ptr] = 10 * args[arg_ptr] + line[i++] - '0';
if (!args[arg_ptr])
cuterror(POSITION_ERROR);
arg_ptr++;
}
if (line[i] == '-') {
arg_ptr |= 1;
i++;
flag = 0;
}
}
if (flag && arg_ptr & 1)
args[arg_ptr] = args[arg_ptr - 1];
if (args[num_args * 2] > args[num_args * 2 + 1])
cuterror(RANGE_ERROR);
num_args++;
arg_ptr = num_args * 2;
}
while (line[i++]);
}
void cut()
{
int i, j, length, maxcol=0;
char *columns[MAX_FIELD];
while (fgets(line, BUFSIZ, fd)) {
length = strlen(line) - 1;
*(line + length) = 0;
switch (mode) {
case DUMP_STDIN:
printf("%s", line);
break;
case OPTIONF:
columns[maxcol++] = line;
for (i = 0; i < length; i++) {
if (*(line + i) == delim) {
*(line + i) = 0;
if (maxcol == MAX_FIELD)
cuterror(MAX_FIELDS_EXEEDED_ERROR);
columns[maxcol] = line + i + 1;
maxcol++;
}
}
if (maxcol != 1) {
for (i = 0; i < num_args; i++) {
for (j = args[i * 2]; j <= args[i * 2 + 1]; j++)
if (j <= maxcol) {
printf("%s", columns[j - 1]);
if (i != num_args - 1 || j != args[i * 2 + 1])
putchar(delim);
}
}
}
break;
case OPTIONC:
for (i = 0; i < num_args; i++) {
for (j = args[i * 2];
j <= (args[i * 2 + 1] >
length ? length : args[i * 2 + 1]); j++)
putchar(*(line + j - 1));
}
}
if (maxcol != 1)
putchar('\n');
}
}
int cut_main(int argc, char **argv)
{
int i = 1;
int numberFilenames = 0;
name = argv[0];
if (argc == 1 || strcmp(argv[1], dash_dash_help)==0)
usage( "cut [OPTION]... [FILE]...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nPrints selected fields from each input FILE to standard output.\n\n"
"Options:\n"
"\t-b LIST\tOutput only bytes from LIST\n"
"\t-c LIST\tOutput only characters from LIST\n"
"\t-d DELIM\tUse DELIM instead of tab as the field delimiter\n"
"\t-f N\tPrint only these fields\n"
"\t-n\tIgnored\n"
#endif
);
while (i < argc) {
if (argv[i][0] == '-') {
switch (argv[i++][1]) {
case 'd':
if (mode == OPTIONC || mode == OPTIONB)
warn(DELIMITER_NOT_APPLICABLE, "d");
delim = argv[i++][0];
break;
case 'f':
sprintf(line, "%s", argv[i++]);
if (mode == OPTIONC || mode == OPTIONB)
warn(OVERRIDING_PREVIOUS_MODE, "f");
mode = OPTIONF;
break;
case 'b':
sprintf(line, "%s", argv[i++]);
if (mode == OPTIONF || mode == OPTIONC)
warn(OVERRIDING_PREVIOUS_MODE, "b");
mode = OPTIONB;
break;
case 'c':
sprintf(line, "%s", argv[i++]);
if (mode == OPTIONF || mode == OPTIONB)
warn(OVERRIDING_PREVIOUS_MODE, "c");
mode = OPTIONC;
break;
case '\0': /* - means: read from stdin */
numberFilenames++;
break;
case 'n': /* needed for Posix, but no effect here */
if (mode != OPTIONB)
warn(OPTION_NOT_APPLICABLE, "n");
break;
default:
warn(UNKNOWN_OPTION, &(argv[i - 1][1]));
}
} else {
i++;
numberFilenames++;
}
}
/* Here follow the checks, if the selected options are reasonable. */
if (mode == OPTIONB) /* since in Minix char := byte */
mode = OPTIONC;
get_args();
if (numberFilenames != 0) {
i = 1;
while (i < argc) {
if (argv[i][0] == '-') {
switch (argv[i][1]) {
case 'f':
case 'c':
case 'b':
case 'd':
i += 2;
break;
case 'n':
case 'i':
case 's':
i++;
break;
case '\0':
fd = stdin;
i++;
cut();
break;
default:
i++;
}
} else {
if ((fd = fopen(argv[i++], "r")) == NULL) {
warn(FILE_NOT_READABLE, argv[i - 1]);
} else {
cut();
fclose(fd);
}
}
}
} else {
fd = stdin;
cut();
}
exit(exit_status);
}
/* cut - extract columns from a file or stdin. Author: Michael J. Holme
*
* Copyright 1989, Michael John Holme, All rights reserved.
* This code may be freely distributed, provided that this notice
* remains intact.
*
* V1.1: 6th September 1989
*
* Bugs, criticisms, etc,
* c/o Mark Powell
* JANET sq79@uk.ac.liv
* ARPA sq79%liv.ac.uk@nsfnet-relay.ac.uk
* UUCP ...!mcvax!ukc!liv.ac.uk!sq79
*-------------------------------------------------------------------------
* Changed for POSIX1003.2/Draft10 conformance
* Thomas Brupbacher (tobr@mw.lpc.ethz.ch), September 1990.
* Changes:
* - separation of error messages ( stderr) and output (stdout).
* - support for -b and -n (no effect, -b acts as -c)
* - support for -s
*-------------------------------------------------------------------------
*/
/*
* Copyright (c) 1987,1997, Prentice Hall
* All rights reserved.
*
* Redistribution and use of the MINIX operating system in source and
* binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* Neither the name of Prentice Hall nor the names of the software
* authors or contributors may be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND
* CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL PRENTICE HALL OR ANY AUTHORS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/

View File

@ -27,12 +27,15 @@
#include <stdio.h>
const char head_usage[] =
"head [OPTION] [FILE]...\n\n"
"Print first 10 lines of each FILE to standard output.\n"
"head [OPTION] [FILE]...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nPrint first 10 lines of each FILE to standard output.\n"
"With more than one FILE, precede each with a header giving the\n"
"file name. With no FILE, or when FILE is -, read standard input.\n\n"
"Options:\n" "\t-n NUM\t\tPrint first NUM lines instead of first 10\n";
"Options:\n" "\t-n NUM\t\tPrint first NUM lines instead of first 10\n"
#endif
;
int head(int len, FILE * src)
{
@ -109,4 +112,4 @@ int head_main(int argc, char **argv)
exit(0);
}
/* $Id: head.c,v 1.9 2000/04/13 01:18:56 erik Exp $ */
/* $Id: head.c,v 1.10 2000/05/12 19:41:47 erik Exp $ */

View File

@ -29,11 +29,14 @@
#include <sys/types.h>
static const char id_usage[] =
"id [OPTIONS]... [USERNAME]\n\n"
"Print information for USERNAME or the current user\n\n"
"id [OPTIONS]... [USERNAME]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nPrint information for USERNAME or the current user\n\n"
"\t-g\tprints only the group ID\n"
"\t-u\tprints only the user ID\n"
"\t-r\tprints the real user ID instead of the effective ID (with -ug)\n\n";
"\t-r\tprints the real user ID instead of the effective ID (with -ug)\n\n"
#endif
;
extern int id_main(int argc, char **argv)
{

View File

@ -7,7 +7,11 @@
extern int length_main(int argc, char **argv)
{
if (argc != 2 || **(argv + 1) == '-') {
usage("length string\n");
usage("length STRING\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nPrints out the length of the specified STRING.\n"
#endif
);
}
printf("%lu\n", (long)strlen(argv[1]));
return (TRUE);

View File

@ -32,13 +32,16 @@
#include <errno.h>
static const char ln_usage[] =
"ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n\n"
"Create a link named LINK_NAME or DIRECTORY to the specified TARGET\n\n"
"ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nCreate a link named LINK_NAME or DIRECTORY to the specified TARGET\n\n"
"Options:\n"
"\t-s\tmake symbolic links instead of hard links\n"
"\t-f\tremove existing destination files\n"
"\t-n\tno dereference symlinks - treat like normal file\n";
"\t-n\tno dereference symlinks - treat like normal file\n"
#endif
;
static int symlinkFlag = FALSE;
static int removeoldFlag = FALSE;

View File

@ -23,9 +23,11 @@
#include "internal.h"
#include <stdio.h>
static const char logname_usage[] = "logname\n\n"
"Print the name of the current user.\n";
static const char logname_usage[] = "logname\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nPrint the name of the current user.\n"
#endif
;
extern int logname_main(int argc, char **argv)
{

View File

@ -449,7 +449,9 @@ static const char ls_usage[] = "ls [-1a"
#ifdef BB_FEATURE_LS_FILETYPES
"F"
#endif
"] [filenames...]\n\n"
"] [filenames...]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nList directory contents\n\n"
"Options:\n"
"\t-a\tdo not hide entries starting with .\n"
#ifdef BB_FEATURE_LS_TIMESTAMPS
@ -474,6 +476,7 @@ static const char ls_usage[] = "ls [-1a"
"\t-C\tlist entries by columns\n"
#ifdef BB_FEATURE_LS_FILETYPES
"\t-F\tappend indicator (one of */=@|) to entries\n"
#endif
#endif
;

View File

@ -30,12 +30,15 @@
#include <errno.h>
static const char mkdir_usage[] =
"mkdir [OPTION] DIRECTORY...\n\n"
"Create the DIRECTORY(ies), if they do not already exist\n\n"
"mkdir [OPTION] DIRECTORY...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nCreate the DIRECTORY(ies), if they do not already exist\n\n"
"Options:\n"
"\t-m\tset permission mode (as in chmod), not rwxrwxrwx - umask\n"
"\t-p\tno error if existing, make parent directories as needed\n";
"\t-p\tno error if existing, make parent directories as needed\n"
#endif
;
static int parentFlag = FALSE;

View File

@ -26,11 +26,13 @@
#include <sys/stat.h>
#include <errno.h>
static const char mkfifo_usage[] = "mkfifo [OPTIONS] name\n\n"
"Creates a named pipe (identical to 'mknod name p')\n\n"
static const char mkfifo_usage[] = "mkfifo [OPTIONS] name\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nCreates a named pipe (identical to 'mknod name p')\n\n"
"Options:\n"
"\t-m\tcreate the pipe using the specified mode (default a=rw)\n";
"\t-m\tcreate the pipe using the specified mode (default a=rw)\n"
#endif
;
extern int mkfifo_main(int argc, char **argv)
{

View File

@ -28,14 +28,17 @@
#include <fcntl.h>
#include <unistd.h>
static const char mknod_usage[] = "mknod [OPTIONS] NAME TYPE MAJOR MINOR\n\n"
"Create a special file (block, character, or pipe).\n\n"
static const char mknod_usage[] = "mknod [OPTIONS] NAME TYPE MAJOR MINOR\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nCreate a special file (block, character, or pipe).\n\n"
"Options:\n"
"\t-m\tcreate the special file using the specified mode (default a=rw)\n\n"
"TYPEs include:\n"
"\tb:\tMake a block (buffered) device.\n"
"\tc or u:\tMake a character (un-buffered) device.\n"
"\tp:\tMake a named pipe. MAJOR and MINOR are ignored for named pipes.\n";
"\tp:\tMake a named pipe. MAJOR and MINOR are ignored for named pipes.\n"
#endif
;
int mknod_main(int argc, char **argv)
{

View File

@ -139,7 +139,12 @@ static void verify __P((char *s, char *end));
/* The value to return to the calling program. */
static int exit_status;
static const char printf_usage[] = "printf format [argument...]\n\nFormats and prints the given data.\n";
static const char printf_usage[] = "printf FORMAT [ARGUMENT...]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nFormats and prints ARGUMENT(s) according to FORMAT,\n"
"Where FORMAT controls the output exactly as in C printf.\n"
#endif
;
int printf_main(int argc, char **argv)
{

View File

@ -24,15 +24,14 @@
#include "internal.h"
#include <stdio.h>
#include <dirent.h>
#include <errno.h>
extern int pwd_main(int argc, char **argv)
{
char buf[BUFSIZ + 1];
if (getcwd(buf, sizeof(buf)) == NULL) {
perror("get working directory");
exit(FALSE);
}
if (getcwd(buf, sizeof(buf)) == NULL)
fatalError("pwd: %s", strerror(errno));
printf("%s\n", buf);
exit(TRUE);

View File

@ -29,12 +29,14 @@
#include <dirent.h>
#include <errno.h>
static const char *rm_usage = "rm [OPTION]... FILE...\n\n"
"Remove (unlink) the FILE(s).\n\n"
static const char *rm_usage = "rm [OPTION]... FILE...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nRemove (unlink) the FILE(s).\n\n"
"Options:\n"
"\t-f\t\tremove existing destinations, never prompt\n"
"\t-r or -R\tremove the contents of directories recursively\n";
"\t-r or -R\tremove the contents of directories recursively\n"
#endif
;
static int recursiveFlag = FALSE;

View File

@ -31,7 +31,11 @@ extern int rmdir_main(int argc, char **argv)
{
if (argc == 1 || **(argv + 1) == '-') {
usage
("rmdir [OPTION]... DIRECTORY...\n\nRemove the DIRECTORY(ies), if they are empty.\n");
("rmdir [OPTION]... DIRECTORY...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nRemove the DIRECTORY(ies), if they are empty.\n"
#endif
);
}
while (--argc > 0) {

View File

@ -24,7 +24,11 @@
#include "internal.h"
#include <stdio.h>
const char sleep_usage[] = "sleep N\n\n" "Pause for N seconds.\n";
const char sleep_usage[] = "sleep N\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nPause for N seconds.\n"
#endif
;
extern int sleep_main(int argc, char **argv)
{

View File

@ -33,7 +33,11 @@ static const char sort_usage[] = "sort [-n]"
#ifdef BB_FEATURE_SORT_REVERSE
" [-r]"
#endif
" [FILE]...\n\nSorts lines of text in the specified files\n";
" [FILE]...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nSorts lines of text in the specified files\n"
#endif
;
#ifdef BB_FEATURE_SORT_REVERSE
#define APPLY_REVERSE(x) (reverse ? -(x) : (x))
@ -300,4 +304,4 @@ int sort_main(int argc, char **argv)
exit(0);
}
/* $Id: sort.c,v 1.15 2000/04/17 04:22:09 beppu Exp $ */
/* $Id: sort.c,v 1.16 2000/05/12 19:41:47 erik Exp $ */

View File

@ -27,7 +27,11 @@
extern int sync_main(int argc, char **argv)
{
if (argc > 1 && **(argv + 1) == '-') {
usage("sync\n\nWrite all buffered filesystem blocks to disk.\n");
usage("sync\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nWrite all buffered filesystem blocks to disk.\n"
#endif
);
}
exit(sync());
}

View File

@ -47,6 +47,9 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <ctype.h>
#define BB_DECLARE_EXTERN
#define bb_need_help
#include "messages.c"
#define XWRITE(fd, buffer, n_bytes) \
@ -70,15 +73,18 @@ static int forever;
static int print_headers;
const char tail_usage[] =
"tail [OPTION] [FILE]...\n\n"
"Print last 10 lines of each FILE to standard output.\n"
"tail [OPTION] [FILE]...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nPrint last 10 lines of each FILE to standard output.\n"
"With more than one FILE, precede each with a header giving the\n"
"file name. With no FILE, or when FILE is -, read standard input.\n\n"
"Options:\n"
"\t-n NUM\t\tPrint last NUM lines instead of first 10\n"
"\t-f\t\tOutput data as the file grows. This version\n"
"\t\t\tof 'tail -f' supports only one file at a time.\n";
"\t\t\tof 'tail -f' supports only one file at a time.\n"
#endif
;
static void write_header(const char *filename)
@ -512,9 +518,9 @@ char *program_name;
static int have_read_stdin;
static const char tail_usage[] = "tail [OPTION]... [FILE]...\n\
\n\
Print last 10 lines of each FILE to standard output.\n\
static const char tail_usage[] = "tail [OPTION]... [FILE]...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nPrint last 10 lines of each FILE to standard output.\n\
With more than one FILE, precede each with a header giving the file name.\n\
With no FILE, or when FILE is -, read standard input.\n\
\n\
@ -523,11 +529,12 @@ With no FILE, or when FILE is -, read standard input.\n\
-n=N output the last N lines, instead of last 10\n\
-q never output headers giving file names\n\
-v always output headers giving file names\n\
--help display this help and exit\n\
\n\
If the first character of N (bytes or lines) is a `+', output begins with \n\
the Nth item from the start of each file, otherwise, print the last N items\n\
in the file. N bytes may be suffixed by k (x1024), b (x512), or m (1024^2).\n\n";
in the file. N bytes may be suffixed by k (x1024), b (x512), or m (1024^2).\n"
#endif
;
static void write_header(const char *filename, const char *comment)
{

View File

@ -27,12 +27,14 @@
#include <stdio.h>
static const char tee_usage[] =
"tee [OPTION]... [FILE]...\n\n"
"Copy standard input to each FILE, and also to standard output.\n\n"
"tee [OPTION]... [FILE]...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nCopy standard input to each FILE, and also to standard output.\n\n"
"Options:\n" "\t-a\tappend to the given FILEs, do not overwrite\n"
#if 0
"\t-i\tignore interrupt signals\n"
#endif
#endif
;
@ -131,4 +133,4 @@ int tee_main(int argc, char **argv)
exit(0);
}
/* $Id: tee.c,v 1.9 2000/04/13 01:18:56 erik Exp $ */
/* $Id: tee.c,v 1.10 2000/05/12 19:41:47 erik Exp $ */

View File

@ -39,6 +39,9 @@
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#define BB_DECLARE_EXTERN
#define bb_need_help
#include "messages.c"
/* test(1) accepts the following grammar:
oexpr ::= aexpr | aexpr "-o" oexpr ;
@ -185,11 +188,14 @@ test_main(int argc, char** argv)
fatalError("missing ]");
argv[argc] = NULL;
}
if (strcmp(argv[1], "--help") == 0) {
if (strcmp(argv[1], dash_dash_help) == 0) {
usage("test EXPRESSION\n"
"or [ EXPRESSION ]\n\n"
"Checks file types and compares values returning an exit\n"
"code determined by the value of EXPRESSION.\n");
"or [ EXPRESSION ]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nChecks file types and compares values returning an exit\n"
"code determined by the value of EXPRESSION.\n"
#endif
);
}
/* Implement special cases from POSIX.2, section 4.62.4 */

View File

@ -31,9 +31,11 @@
#include <errno.h>
static const char touch_usage[] = "touch [-c] file [file ...]\n\n"
"Update the last-modified date on the given file[s].\n";
static const char touch_usage[] = "touch [-c] file [file ...]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nUpdate the last-modified date on the given file[s].\n"
#endif
;

View File

@ -24,10 +24,13 @@
#include <stdio.h>
#include <sys/types.h>
static const char tty_usage[] = "tty\n\n"
"Print the file name of the terminal connected to standard input.\n\n"
static const char tty_usage[] = "tty\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nPrint the file name of the terminal connected to standard input.\n\n"
"Options:\n"
"\t-s\tprint nothing, only return an exit status\n";
"\t-s\tprint nothing, only return an exit status\n"
#endif
;
extern int tty_main(int argc, char **argv)
{

View File

@ -28,9 +28,12 @@
#include <errno.h>
static const char uniq_usage[] =
"uniq [OPTION]... [INPUT [OUTPUT]]\n\n"
"Discard all but one of successive identical lines from INPUT\n"
"(or standard input), writing to OUTPUT (or standard output).\n";
"uniq [OPTION]... [INPUT [OUTPUT]]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nDiscard all but one of successive identical lines from INPUT\n"
"(or standard input), writing to OUTPUT (or standard output).\n"
#endif
;
/* max chars in line */
#define UNIQ_MAX 4096
@ -184,4 +187,4 @@ int uniq_main(int argc, char **argv)
exit(0);
}
/* $Id: uniq.c,v 1.9 2000/04/17 16:16:10 erik Exp $ */
/* $Id: uniq.c,v 1.10 2000/05/12 19:41:47 erik Exp $ */

View File

@ -25,7 +25,11 @@
#include <stdlib.h>
#include <unistd.h>
const char usleep_usage[] = "usleep N\n\n" "Pause for N microseconds.\n";
const char usleep_usage[] = "usleep N\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nPause for N microseconds.\n"
#endif
;
extern int usleep_main(int argc, char **argv)
{

View File

@ -23,15 +23,18 @@
#include "internal.h"
#include <stdio.h>
static const char wc_usage[] = "wc [OPTION]... [FILE]...\n\n"
"Print line, word, and byte counts for each FILE, and a total line if\n"
static const char wc_usage[] = "wc [OPTION]... [FILE]...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nPrint line, word, and byte counts for each FILE, and a total line if\n"
"more than one FILE is specified. With no FILE, read standard input.\n\n"
"Options:\n"
"\t-c\tprint the byte counts\n"
"\t-l\tprint the newline counts\n"
"\t-L\tprint the length of the longest line\n"
"\t-w\tprint the word counts\n";
"\t-w\tprint the word counts\n"
#endif
;
static int total_lines, total_words, total_chars, max_length;
static int print_lines, print_words, print_chars, print_length;

View File

@ -24,8 +24,11 @@
#include <stdio.h>
#include <pwd.h>
static const char whoami_usage[] = "whoami\n\n"
"Prints the user name associated with the current effective user id.\n";
static const char whoami_usage[] = "whoami\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nPrints the user name associated with the current effective user id.\n"
#endif
;
extern int whoami_main(int argc, char **argv)
{

View File

@ -28,8 +28,11 @@ extern int yes_main(int argc, char **argv)
int i;
if (argc >=1 && *argv[1]=='-') {
usage("yes [OPTION]... [STRING]...\n\n"
"Repeatedly outputs a line with all specified STRING(s), or `y'.\n");
usage("yes [OPTION]... [STRING]...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nRepeatedly outputs a line with all specified STRING(s), or `y'.\n"
#endif
);
}
if (argc == 1) {

372
cut.c Normal file
View File

@ -0,0 +1,372 @@
/* vi: set sw=4 ts=4: */
/*
* cut implementation for busybox
*
* Copyright (c) Michael J. Holme
*
* This version of cut is adapted from Minix cut and was modified
* by Erik Andersen <andersee@debian.org> to be used in busybox.
*
* 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
*
* Original copyright notice is retained at the end of this file.
*/
#include "internal.h"
#include <sys/types.h>
#include <ctype.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#define BB_DECLARE_EXTERN
#define bb_need_help
#include "messages.c"
#define MAX_FIELD 80 /* Pointers to the beginning of each field
* are stored in columns[], if a line holds
* more than MAX_FIELD columns the array
* boundary is exceed. But unlikely at 80 */
#define MAX_ARGS 32 /* Maximum number of fields following -f or
* -c switches */
int args[MAX_ARGS * 2];
int num_args;
/* Lots of new defines, should easen maintainance... */
#define DUMP_STDIN 0 /* define for mode: no options */
#define OPTIONF 1 /* define for mode: option -f */
#define OPTIONC 2 /* define for mode: option -c */
#define OPTIONB 3 /* define for mode: option -b */
#define NOTSET 0 /* option not selected */
#define SET 1 /* option selected */
/* Defines for the warnings */
#define DELIMITER_NOT_APPLICABLE 0
#define OVERRIDING_PREVIOUS_MODE 1
#define OPTION_NOT_APPLICABLE 2
#define UNKNOWN_OPTION 3
#define FILE_NOT_READABLE 4
/* Defines for the fatal errors */
#define SYNTAX_ERROR 101
#define POSITION_ERROR 102
#define LINE_TO_LONG_ERROR 103
#define RANGE_ERROR 104
#define MAX_FIELDS_EXEEDED_ERROR 105
#define MAX_ARGS_EXEEDED_ERROR 106
int mode; /* 0 = dump stdin to stdout, 1=-f, 2=-c */
char delim = '\t'; /* default delimiting character */
FILE *fd;
char *name;
char line[BUFSIZ];
int exit_status;
int cut_main(int argc, char **argv);
void warn(int warn_number, char *option);
void cuterror(int err);
void get_args(void);
void cut(void);
void warn(int warn_number, char *option)
{
static char *warn_msg[] = {
"%s: Option -d allowed only with -f\n",
"%s: -%s overrides earlier option\n",
"%s: -%s not allowed in current mode\n",
"%s: Cannot open %s\n"
};
fprintf(stderr, warn_msg[warn_number], name, option);
exit_status = warn_number + 1;
}
void cuterror(int err)
{
static char *err_mes[] = {
"%s: syntax error\n",
"%s: position must be >0\n",
"%s: line longer than BUFSIZ\n",
"%s: range must not decrease from left to right\n",
"%s: MAX_FIELD exceeded\n",
"%s: MAX_ARGS exceeded\n"
};
fprintf(stderr, err_mes[err - 101], name);
exit(err);
}
void get_args()
{
int i = 0;
int arg_ptr = 0;
int flag;
num_args = 0;
do {
if (num_args == MAX_ARGS)
cuterror(MAX_ARGS_EXEEDED_ERROR);
if (!isdigit(line[i]) && line[i] != '-')
cuterror(SYNTAX_ERROR);
args[arg_ptr] = 1;
args[arg_ptr + 1] = BUFSIZ;
flag = 1;
while (line[i] != ',' && line[i] != 0) {
if (isdigit(line[i])) {
args[arg_ptr] = 0;
while (isdigit(line[i]))
args[arg_ptr] = 10 * args[arg_ptr] + line[i++] - '0';
if (!args[arg_ptr])
cuterror(POSITION_ERROR);
arg_ptr++;
}
if (line[i] == '-') {
arg_ptr |= 1;
i++;
flag = 0;
}
}
if (flag && arg_ptr & 1)
args[arg_ptr] = args[arg_ptr - 1];
if (args[num_args * 2] > args[num_args * 2 + 1])
cuterror(RANGE_ERROR);
num_args++;
arg_ptr = num_args * 2;
}
while (line[i++]);
}
void cut()
{
int i, j, length, maxcol=0;
char *columns[MAX_FIELD];
while (fgets(line, BUFSIZ, fd)) {
length = strlen(line) - 1;
*(line + length) = 0;
switch (mode) {
case DUMP_STDIN:
printf("%s", line);
break;
case OPTIONF:
columns[maxcol++] = line;
for (i = 0; i < length; i++) {
if (*(line + i) == delim) {
*(line + i) = 0;
if (maxcol == MAX_FIELD)
cuterror(MAX_FIELDS_EXEEDED_ERROR);
columns[maxcol] = line + i + 1;
maxcol++;
}
}
if (maxcol != 1) {
for (i = 0; i < num_args; i++) {
for (j = args[i * 2]; j <= args[i * 2 + 1]; j++)
if (j <= maxcol) {
printf("%s", columns[j - 1]);
if (i != num_args - 1 || j != args[i * 2 + 1])
putchar(delim);
}
}
}
break;
case OPTIONC:
for (i = 0; i < num_args; i++) {
for (j = args[i * 2];
j <= (args[i * 2 + 1] >
length ? length : args[i * 2 + 1]); j++)
putchar(*(line + j - 1));
}
}
if (maxcol != 1)
putchar('\n');
}
}
int cut_main(int argc, char **argv)
{
int i = 1;
int numberFilenames = 0;
name = argv[0];
if (argc == 1 || strcmp(argv[1], dash_dash_help)==0)
usage( "cut [OPTION]... [FILE]...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nPrints selected fields from each input FILE to standard output.\n\n"
"Options:\n"
"\t-b LIST\tOutput only bytes from LIST\n"
"\t-c LIST\tOutput only characters from LIST\n"
"\t-d DELIM\tUse DELIM instead of tab as the field delimiter\n"
"\t-f N\tPrint only these fields\n"
"\t-n\tIgnored\n"
#endif
);
while (i < argc) {
if (argv[i][0] == '-') {
switch (argv[i++][1]) {
case 'd':
if (mode == OPTIONC || mode == OPTIONB)
warn(DELIMITER_NOT_APPLICABLE, "d");
delim = argv[i++][0];
break;
case 'f':
sprintf(line, "%s", argv[i++]);
if (mode == OPTIONC || mode == OPTIONB)
warn(OVERRIDING_PREVIOUS_MODE, "f");
mode = OPTIONF;
break;
case 'b':
sprintf(line, "%s", argv[i++]);
if (mode == OPTIONF || mode == OPTIONC)
warn(OVERRIDING_PREVIOUS_MODE, "b");
mode = OPTIONB;
break;
case 'c':
sprintf(line, "%s", argv[i++]);
if (mode == OPTIONF || mode == OPTIONB)
warn(OVERRIDING_PREVIOUS_MODE, "c");
mode = OPTIONC;
break;
case '\0': /* - means: read from stdin */
numberFilenames++;
break;
case 'n': /* needed for Posix, but no effect here */
if (mode != OPTIONB)
warn(OPTION_NOT_APPLICABLE, "n");
break;
default:
warn(UNKNOWN_OPTION, &(argv[i - 1][1]));
}
} else {
i++;
numberFilenames++;
}
}
/* Here follow the checks, if the selected options are reasonable. */
if (mode == OPTIONB) /* since in Minix char := byte */
mode = OPTIONC;
get_args();
if (numberFilenames != 0) {
i = 1;
while (i < argc) {
if (argv[i][0] == '-') {
switch (argv[i][1]) {
case 'f':
case 'c':
case 'b':
case 'd':
i += 2;
break;
case 'n':
case 'i':
case 's':
i++;
break;
case '\0':
fd = stdin;
i++;
cut();
break;
default:
i++;
}
} else {
if ((fd = fopen(argv[i++], "r")) == NULL) {
warn(FILE_NOT_READABLE, argv[i - 1]);
} else {
cut();
fclose(fd);
}
}
}
} else {
fd = stdin;
cut();
}
exit(exit_status);
}
/* cut - extract columns from a file or stdin. Author: Michael J. Holme
*
* Copyright 1989, Michael John Holme, All rights reserved.
* This code may be freely distributed, provided that this notice
* remains intact.
*
* V1.1: 6th September 1989
*
* Bugs, criticisms, etc,
* c/o Mark Powell
* JANET sq79@uk.ac.liv
* ARPA sq79%liv.ac.uk@nsfnet-relay.ac.uk
* UUCP ...!mcvax!ukc!liv.ac.uk!sq79
*-------------------------------------------------------------------------
* Changed for POSIX1003.2/Draft10 conformance
* Thomas Brupbacher (tobr@mw.lpc.ethz.ch), September 1990.
* Changes:
* - separation of error messages ( stderr) and output (stdout).
* - support for -b and -n (no effect, -b acts as -c)
* - support for -s
*-------------------------------------------------------------------------
*/
/*
* Copyright (c) 1987,1997, Prentice Hall
* All rights reserved.
*
* Redistribution and use of the MINIX operating system in source and
* binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* Neither the name of Prentice Hall nor the names of the software
* authors or contributors may be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND
* CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL PRENTICE HALL OR ANY AUTHORS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/

View File

@ -488,7 +488,7 @@ Example:
Usage: free
Displays the amount of free and used memory in the system.
Displays the amount of free and used system memory.
Example:
@ -504,7 +504,7 @@ Example:
Usage: freeramdisk DEVICE
Free all memory used by the specified ramdisk.
Frees all memory used by the specified ramdisk.
Example:
@ -799,9 +799,9 @@ Example:
=item length
Usage: length string
Usage: length STRING
Prints out the length of the specified string.
Prints out the length of the specified STRING.
Example:
@ -1120,7 +1120,7 @@ Flags:
-t fs-type: Specify the filesystem type.
-w: Mount for reading and writing (default).
Options for use with the "-o" flag:
Options for use with the "B<-o>" flag:
async/sync: Writes are asynchronous / synchronous.
atime/noatime: Enable / disable updates to inode access times.
@ -1881,4 +1881,4 @@ Enrique Zanardi <ezanardi@ull.es>
=cut
# $Id: busybox.pod,v 1.29 2000/05/10 05:00:31 erik Exp $
# $Id: busybox.pod,v 1.30 2000/05/12 19:41:47 erik Exp $

View File

@ -38,8 +38,9 @@
#include <ctype.h>
static const char sed_usage[] =
"sed [-n] -e script [file...]\n\n"
"Allowed sed scripts come in the following form:\n"
"sed [-n] -e script [file...]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nAllowed sed scripts come in the following form:\n"
"\t'ADDR [!] COMMAND'\n\n"
"\twhere address ADDR can be:\n"
"\t NUMBER Match specified line number\n"
@ -58,8 +59,10 @@ static const char sed_usage[] =
#if defined BB_REGEXP
"This version of sed matches full regular expresions.\n";
#else
"This version of sed matches strings (not full regular expresions).\n";
"This version of sed matches strings (not full regular expresions).\n"
#endif
#endif
;
/* Flags & variables */

16
fbset.c
View File

@ -105,9 +105,9 @@ struct cmdoptions_t {
"-vsync", 1, CMD_VSYNC}, {
"-laced", 1, CMD_LACED}, {
"-double", 1, CMD_DOUBLE}, {
"--help", 0, CMD_HELP}, {
"-help", 0, CMD_HELP}, {
#ifdef BB_FEATURE_FBSET_FANCY
"--help", 0, CMD_HELP}, {
"-help", 0, CMD_HELP}, {
"-all", 0, CMD_ALL}, {
"-xres", 1, CMD_XRES}, {
"-yres", 1, CMD_YRES}, {
@ -115,7 +115,7 @@ struct cmdoptions_t {
"-vyres", 1, CMD_VYRES}, {
"-depth", 1, CMD_DEPTH}, {
"-match", 0, CMD_MATCH}, {
"--geometry", 5, CMD_GEOMETRY}, {
"-geometry", 5, CMD_GEOMETRY}, {
"-pixclock", 1, CMD_PIXCLOCK}, {
"-left", 1, CMD_LEFT}, {
"-right", 1, CMD_RIGHT}, {
@ -123,7 +123,7 @@ struct cmdoptions_t {
"-lower", 1, CMD_LOWER}, {
"-hslen", 1, CMD_HSLEN}, {
"-vslen", 1, CMD_VSLEN}, {
"--timings", 7, CMD_TIMING}, {
"-timings", 7, CMD_TIMING}, {
"-csync", 1, CMD_CSYNC}, {
"-gsync", 1, CMD_GSYNC}, {
"-extsync", 1, CMD_EXTSYNC}, {
@ -221,17 +221,21 @@ static void showmode(struct fb_var_screeninfo *v)
static void fbset_usage(void)
{
#ifndef BB_FEATURE_TRIVIAL_HELP
int i;
#endif
#ifndef STANDALONE
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
BB_VER, BB_BT);
#endif
fprintf(stderr, "Usage: fbset [options] [mode]\n\n");
fprintf(stderr, "Show and modify frame buffer device settings\n\n");
fprintf(stderr, "Usage: fbset [options] [mode]\n");
#ifndef BB_FEATURE_TRIVIAL_HELP
fprintf(stderr, "\nShows and modifies frame buffer device settings\n\n");
fprintf(stderr, "The following options are recognized:\n");
for (i = 0; g_cmdoptions[i].name; i++)
fprintf(stderr, "\t%s\n", g_cmdoptions[i].name);
#endif
exit(-1);
}

View File

@ -34,7 +34,11 @@ extern int fdflush_main(int argc, char **argv)
int fd;
if (argc <= 1 || **(++argv) == '-') {
usage("fdflush device\n\nForce floppy disk drive to detect disk change\n");
usage("fdflush DEVICE\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nForces floppy disk drive to detect disk change\n"
#endif
);
}
fd = open(*argv, 0);

9
find.c
View File

@ -33,13 +33,16 @@ static char *pattern = NULL;
static char *directory = ".";
static int dereferenceFlag = FALSE;
static const char find_usage[] = "find [PATH...] [EXPRESSION]\n\n"
"Search for files in a directory hierarchy. The default PATH is\n"
static const char find_usage[] = "find [PATH...] [EXPRESSION]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nSearch for files in a directory hierarchy. The default PATH is\n"
"the current directory; default EXPRESSION is '-print'\n\n"
"\nEXPRESSION may consist of:\n"
"\t-follow\t\tDereference symbolic links.\n"
"\t-name PATTERN\tFile name (leading directories removed) matches PATTERN.\n"
"\t-print\t\tprint the full file name followed by a newline to stdout.\n";
"\t-print\t\tprint the full file name followed by a newline to stdout.\n"
#endif
;
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)

View File

@ -33,13 +33,16 @@ static char *pattern = NULL;
static char *directory = ".";
static int dereferenceFlag = FALSE;
static const char find_usage[] = "find [PATH...] [EXPRESSION]\n\n"
"Search for files in a directory hierarchy. The default PATH is\n"
static const char find_usage[] = "find [PATH...] [EXPRESSION]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nSearch for files in a directory hierarchy. The default PATH is\n"
"the current directory; default EXPRESSION is '-print'\n\n"
"\nEXPRESSION may consist of:\n"
"\t-follow\t\tDereference symbolic links.\n"
"\t-name PATTERN\tFile name (leading directories removed) matches PATTERN.\n"
"\t-print\t\tprint the full file name followed by a newline to stdout.\n";
"\t-print\t\tprint the full file name followed by a newline to stdout.\n"
#endif
;
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)

View File

@ -41,8 +41,9 @@
#include <ctype.h>
static const char grep_usage[] =
"grep [OPTIONS]... PATTERN [FILE]...\n\n"
"Search for PATTERN in each FILE or standard input.\n\n"
"grep [OPTIONS]... PATTERN [FILE]...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nSearch for PATTERN in each FILE or standard input.\n\n"
"OPTIONS:\n"
"\t-h\tsuppress the prefixing filename on output\n"
"\t-i\tignore case distinctions\n"
@ -52,8 +53,10 @@ static const char grep_usage[] =
#if defined BB_REGEXP
"This version of grep matches full regular expresions.\n";
#else
"This version of grep matches strings (not regular expresions).\n";
"This version of grep matches strings (not regular expresions).\n"
#endif
#endif
;
static int match = FALSE, beQuiet = FALSE;

8
free.c
View File

@ -37,6 +37,14 @@ extern int free_main(int argc, char **argv)
info.sharedram/=DIVISOR;
info.bufferram/=DIVISOR;
if (argc > 1 && **(argv + 1) == '-') {
usage("free\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nDisplays the amount of free and used system memory\n"
#endif
);
}
printf("%6s%13s%13s%13s%13s%13s\n", "", "total", "used", "free",
"shared", "buffers");

View File

@ -34,8 +34,11 @@
static const char freeramdisk_usage[] =
"freeramdisk DEVICE\n\n"
"Free all memory used by the specified ramdisk.\n";
"freeramdisk DEVICE\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nFrees all memory used by the specified ramdisk.\n"
#endif
;
extern int
freeramdisk_main(int argc, char **argv)

View File

@ -198,9 +198,10 @@ static void show_usage(void)
{
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
BB_VER, BB_BT);
fprintf(stderr, "Usage: %s [-larvsmf] /dev/name\n\n", program_name);
fprintf(stderr, "Usage: %s [-larvsmf] /dev/name\n", program_name);
#ifndef BB_FEATURE_TRIVIAL_HELP
fprintf(stderr,
"Performs a consistency check for MINIX filesystems.\n\n");
"\nPerforms a consistency check for MINIX filesystems.\n\n");
fprintf(stderr, "OPTIONS:\n");
fprintf(stderr, "\t-l\tLists all filenames\n");
fprintf(stderr, "\t-r\tPerform interactive repairs\n");
@ -210,6 +211,7 @@ static void show_usage(void)
fprintf(stderr,
"\t-m\tActivates MINIX-like \"mode not cleared\" warnings\n");
fprintf(stderr, "\t-f\tForce file system check.\n\n");
#endif
leave(16);
}

9
grep.c
View File

@ -41,8 +41,9 @@
#include <ctype.h>
static const char grep_usage[] =
"grep [OPTIONS]... PATTERN [FILE]...\n\n"
"Search for PATTERN in each FILE or standard input.\n\n"
"grep [OPTIONS]... PATTERN [FILE]...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nSearch for PATTERN in each FILE or standard input.\n\n"
"OPTIONS:\n"
"\t-h\tsuppress the prefixing filename on output\n"
"\t-i\tignore case distinctions\n"
@ -52,8 +53,10 @@ static const char grep_usage[] =
#if defined BB_REGEXP
"This version of grep matches full regular expresions.\n";
#else
"This version of grep matches strings (not regular expresions).\n";
"This version of grep matches strings (not regular expresions).\n"
#endif
#endif
;
static int match = FALSE, beQuiet = FALSE;

View File

@ -28,13 +28,17 @@
*/
#include "internal.h"
static const char gunzip_usage[] =
"gunzip [OPTION]... FILE\n\n"
"Uncompress FILE (or standard input if FILE is '-').\n\n"
"gunzip [OPTION]... FILE\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nUncompress FILE (or standard input if FILE is '-').\n\n"
"Options:\n"
"\t-c\tWrite output to standard output\n"
"\t-t\tTest compressed file integrity\n";
"\t-t\tTest compressed file integrity\n"
#endif
;
/* These defines are very important for BusyBox. Without these,
@ -43,8 +47,9 @@ static const char gunzip_usage[] =
#define SMALL_MEM
#define DYN_ALLOC
#define bb_need_name_too_long
#define BB_DECLARE_EXTERN
#define bb_need_memory_exhausted
#define bb_need_name_too_long
#include "messages.c"
@ -206,7 +211,7 @@ extern int method; /* compression method */
# define DECLARE(type, array, size) type * array
# define ALLOC(type, array, size) { \
array = (type*)calloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \
if (array == NULL) errorMsg("insufficient memory"); \
if (array == NULL) errorMsg(memory_exhausted, "gunzip"); \
}
# define FREE(array) {if (array != NULL) free(array), array=NULL;}
#else
@ -1053,7 +1058,7 @@ int in, out; /* input and output file descriptors */
int res = inflate();
if (res == 3) {
errorMsg("out of memory");
errorMsg(memory_exhausted, "gunzip");
} else if (res != 0) {
errorMsg("invalid compressed data--format violated");
}

17
gzip.c
View File

@ -30,6 +30,9 @@
*/
#include "internal.h"
#define BB_DECLARE_EXTERN
#define bb_need_memory_exhausted
#include "messages.c"
/* These defines are very important for BusyBox. Without these,
* huge chunks of ram are pre-allocated making the BusyBox bss
@ -39,12 +42,15 @@
static const char gzip_usage[] =
"gzip [OPTION]... FILE\n\n"
"Compress FILE with maximum compression.\n"
"gzip [OPTION]... FILE\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nCompress FILE with maximum compression.\n"
"When FILE is '-', reads standard input. Implies -c.\n\n"
"Options:\n"
"\t-c\tWrite output to standard output instead of FILE.gz\n";
"\t-c\tWrite output to standard output instead of FILE.gz\n"
#endif
;
/* I don't like nested includes, but the string and io functions are used
@ -121,7 +127,7 @@ extern int method; /* compression method */
# define DECLARE(type, array, size) type * array
# define ALLOC(type, array, size) { \
array = (type*)calloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \
if (array == NULL) errorMsg("insufficient memory"); \
if (array == NULL) errorMsg(memory_exhausted, "gzip"); \
}
# define FREE(array) {if (array != NULL) free(array), array=NULL;}
#else
@ -1778,7 +1784,6 @@ int part_nb; /* number of parts in .gz file */
long time_stamp; /* original time stamp (modification time) */
long ifile_size; /* input file size, -1 for devices (debug only) */
char *env; /* contents of GZIP env variable */
char **args = NULL; /* argv pointer if GZIP env variable defined */
char z_suffix[MAX_SUFFIX + 1]; /* default suffix (can be set with --suffix) */
int z_len; /* strlen(z_suffix) */
@ -3248,7 +3253,7 @@ char *env; /* name of environment variable */
nargv = (char **) calloc(*argcp + 1, sizeof(char *));
if (nargv == NULL)
errorMsg("out of memory");
errorMsg(memory_exhausted, "gzip");
oargv = *argvp;
*argvp = nargv;

11
head.c
View File

@ -27,12 +27,15 @@
#include <stdio.h>
const char head_usage[] =
"head [OPTION] [FILE]...\n\n"
"Print first 10 lines of each FILE to standard output.\n"
"head [OPTION] [FILE]...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nPrint first 10 lines of each FILE to standard output.\n"
"With more than one FILE, precede each with a header giving the\n"
"file name. With no FILE, or when FILE is -, read standard input.\n\n"
"Options:\n" "\t-n NUM\t\tPrint first NUM lines instead of first 10\n";
"Options:\n" "\t-n NUM\t\tPrint first NUM lines instead of first 10\n"
#endif
;
int head(int len, FILE * src)
{
@ -109,4 +112,4 @@ int head_main(int argc, char **argv)
exit(0);
}
/* $Id: head.c,v 1.9 2000/04/13 01:18:56 erik Exp $ */
/* $Id: head.c,v 1.10 2000/05/12 19:41:47 erik Exp $ */

View File

@ -1,6 +1,6 @@
/* vi: set sw=4 ts=4: */
/*
* $Id: hostname.c,v 1.7 2000/02/08 19:58:47 erik Exp $
* $Id: hostname.c,v 1.8 2000/05/12 19:41:47 erik Exp $
* Mini hostname implementation for busybox
*
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
@ -31,15 +31,18 @@
#include <stdio.h>
static const char *hostname_usage =
"hostname [OPTION] {hostname | -F file}\n\n"
"Get or set the hostname or DNS domain name. If a hostname is given\n"
"hostname [OPTION] {hostname | -F file}\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nGet or set the hostname or DNS domain name. If a hostname is given\n"
"(or a file with the -F parameter), the host name will be set.\n\n"
"Options:\n"
"\t-s\t\tShort\n"
"\t-i\t\tAddresses for the hostname\n"
"\t-d\t\tDNS domain name\n"
"\t-F FILE\t\tUse the contents of FILE to specify the hostname\n";
"\t-F FILE\t\tUse the contents of FILE to specify the hostname\n"
#endif
;
void do_sethostname(char *s, int isfile)

9
id.c
View File

@ -29,11 +29,14 @@
#include <sys/types.h>
static const char id_usage[] =
"id [OPTIONS]... [USERNAME]\n\n"
"Print information for USERNAME or the current user\n\n"
"id [OPTIONS]... [USERNAME]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nPrint information for USERNAME or the current user\n\n"
"\t-g\tprints only the group ID\n"
"\t-u\tprints only the user ID\n"
"\t-r\tprints the real user ID instead of the effective ID (with -ug)\n\n";
"\t-r\tprints the real user ID instead of the effective ID (with -ug)\n\n"
#endif
;
extern int id_main(int argc, char **argv)
{

View File

@ -70,12 +70,15 @@ _syscall2(unsigned long, create_module, const char *, name, size_t, size)
static char m_filename[BUFSIZ + 1] = "\0";
static char m_fullName[BUFSIZ + 1] = "\0";
static const char insmod_usage[] =
"insmod [OPTION]... MODULE [symbol=value]...\n\n"
"Loads the specified kernel modules into the kernel.\n\n"
"insmod [OPTION]... MODULE [symbol=value]...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nLoads the specified kernel modules into the kernel.\n\n"
"Options:\n"
"\t-f\tForce module to load into the wrong kernel version.\n"
"\t-k\tMake module autoclean-able.\n";
"\t-k\tMake module autoclean-able.\n"
#endif
;
static int findNamedModule(const char *fileName, struct stat *statbuf)

View File

@ -100,11 +100,12 @@ extern int basename_main(int argc, char **argv);
extern int busybox_main(int argc, char** argv);
extern int block_device_main(int argc, char** argv);
extern int cat_main(int argc, char** argv);
extern int cp_mv_main(int argc, char** argv);
extern int chmod_chown_chgrp_main(int argc, char** argv);
extern int chroot_main(int argc, char** argv);
extern int chvt_main(int argc, char** argv);
extern int clear_main(int argc, char** argv);
extern int cp_mv_main(int argc, char** argv);
extern int cut_main(int argc, char** argv);
extern int date_main(int argc, char** argv);
extern int dd_main(int argc, char** argv);
extern int dirname_main(int argc, char** argv);
@ -151,7 +152,7 @@ extern int mkfs_minix_main(int argc, char **argv);
extern int mknod_main(int argc, char** argv);
extern int mkswap_main(int argc, char** argv);
extern int mktemp_main(int argc, char **argv);
extern int mnc_main(int argc, char** argv);
extern int nc_main(int argc, char** argv);
extern int more_main(int argc, char** argv);
extern int mount_main(int argc, char** argv);
extern int mt_main(int argc, char** argv);

18
kill.c
View File

@ -32,16 +32,22 @@
#include <unistd.h>
static const char *kill_usage =
"kill [-signal] process-id [process-id ...]\n\n"
"Send a signal (default is SIGTERM) to the specified process(es).\n\n"
"Options:\n" "\t-l\tList all signal names and numbers.\n\n";
"kill [-signal] process-id [process-id ...]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nSend a signal (default is SIGTERM) to the specified process(es).\n\n"
"Options:\n" "\t-l\tList all signal names and numbers.\n\n"
#endif
;
#ifdef BB_KILLALL
static const char *killall_usage =
"killall [-signal] process-name [process-name ...]\n\n"
"Send a signal (default is SIGTERM) to the specified process(es).\n\n"
"Options:\n" "\t-l\tList all signal names and numbers.\n\n";
"killall [-signal] process-name [process-name ...]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nSend a signal (default is SIGTERM) to the specified process(es).\n\n"
"Options:\n" "\t-l\tList all signal names and numbers.\n\n"
#endif
#endif
;
#define KILL 0
#define KILLALL 1

7
lash.c
View File

@ -127,8 +127,11 @@ static struct builtInCommand bltins[] = {
static const char shell_usage[] =
"sh [FILE]...\n\n" "The BusyBox command interpreter (shell).\n\n";
"sh [FILE]...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nlash: The BusyBox command interpreter (shell).\n\n"
#endif
;
static char cwd[1024];
static char *prompt = "# ";

View File

@ -7,7 +7,11 @@
extern int length_main(int argc, char **argv)
{
if (argc != 2 || **(argv + 1) == '-') {
usage("length string\n");
usage("length STRING\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nPrints out the length of the specified STRING.\n"
#endif
);
}
printf("%lu\n", (long)strlen(argv[1]));
return (TRUE);

9
ln.c
View File

@ -32,13 +32,16 @@
#include <errno.h>
static const char ln_usage[] =
"ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n\n"
"Create a link named LINK_NAME or DIRECTORY to the specified TARGET\n\n"
"ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nCreate a link named LINK_NAME or DIRECTORY to the specified TARGET\n\n"
"Options:\n"
"\t-s\tmake symbolic links instead of hard links\n"
"\t-f\tremove existing destination files\n"
"\t-n\tno dereference symlinks - treat like normal file\n";
"\t-n\tno dereference symlinks - treat like normal file\n"
#endif
;
static int symlinkFlag = FALSE;
static int removeoldFlag = FALSE;

View File

@ -22,8 +22,11 @@
#include <sys/ioctl.h>
#include <sys/kd.h>
static const char loadacm_usage[] = "loadacm\n\n"
"Loads an acm from standard input.\n";
static const char loadacm_usage[] = "loadacm\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nLoads an acm from standard input.\n"
#endif
;
typedef unsigned short unicode;

View File

@ -30,8 +30,11 @@
#define PSF_MAXMODE 0x03
#define PSF_SEPARATOR 0xFFFF
static const char loadfont_usage[] = "loadfont\n\n"
"Loads a console font from standard input.\n";
static const char loadfont_usage[] = "loadfont\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"Loads a console font from standard input.\n"
#endif
;
struct psf_header {
unsigned char magic1, magic2; /* Magic number */

View File

@ -29,8 +29,11 @@
#include <sys/ioctl.h>
static const char loadkmap_usage[] = "loadkmap\n\n"
"Loads a binary keyboard translation table from standard input.\n";
static const char loadkmap_usage[] = "loadkmap\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"Loads a binary keyboard translation table from standard input.\n"
#endif
;
int loadkmap_main(int argc, char **argv)

View File

@ -48,14 +48,17 @@ extern CODE facilitynames[];
#endif
static const char logger_usage[] =
"logger [OPTION]... [MESSAGE]\n\n"
"Write MESSAGE to the system log. If MESSAGE is '-', log stdin.\n\n"
"logger [OPTION]... [MESSAGE]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nWrite MESSAGE to the system log. If MESSAGE is '-', log stdin.\n\n"
"Options:\n"
"\t-s\tLog to stderr as well as the system log.\n"
"\t-t\tLog using the specified tag (defaults to user name).\n"
"\t-p\tEnter the message with the specified priority.\n"
"\t\tThis may be numerical or a ``facility.level'' pair.\n";
"\t\tThis may be numerical or a ``facility.level'' pair.\n"
#endif
;
/* Decode a symbolic name to a numeric value

View File

@ -23,9 +23,11 @@
#include "internal.h"
#include <stdio.h>
static const char logname_usage[] = "logname\n\n"
"Print the name of the current user.\n";
static const char logname_usage[] = "logname\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nPrint the name of the current user.\n"
#endif
;
extern int logname_main(int argc, char **argv)
{

5
ls.c
View File

@ -449,7 +449,9 @@ static const char ls_usage[] = "ls [-1a"
#ifdef BB_FEATURE_LS_FILETYPES
"F"
#endif
"] [filenames...]\n\n"
"] [filenames...]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nList directory contents\n\n"
"Options:\n"
"\t-a\tdo not hide entries starting with .\n"
#ifdef BB_FEATURE_LS_TIMESTAMPS
@ -474,6 +476,7 @@ static const char ls_usage[] = "ls [-1a"
"\t-C\tlist entries by columns\n"
#ifdef BB_FEATURE_LS_FILETYPES
"\t-F\tappend indicator (one of */=@|) to entries\n"
#endif
#endif
;

View File

@ -17,8 +17,9 @@
#include <sys/stat.h>
static const char makedevs_usage[] =
"makedevs NAME TYPE MAJOR MINOR FIRST LAST [s]\n\n"
"Creates a range of block or character special files\n\n"
"makedevs NAME TYPE MAJOR MINOR FIRST LAST [s]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nCreates a range of block or character special files\n\n"
"TYPEs include:\n"
"\tb:\tMake a block (buffered) device.\n"
"\tc or u:\tMake a character (un-buffered) device.\n"
@ -28,7 +29,9 @@ static const char makedevs_usage[] =
"If 's' is the last argument, the base device is created as well.\n\n"
"For example:\n"
"\tmakedevs /dev/ttyS c 4 66 2 63 -> ttyS2-ttyS63\n"
"\tmakedevs /dev/hda b 3 0 0 8 s -> hda,hda1-hda8\n";
"\tmakedevs /dev/hda b 3 0 0 8 s -> hda,hda1-hda8\n"
#endif
;
int makedevs_main(int argc, char **argv)
{

9
math.c
View File

@ -7,10 +7,13 @@
/* Tiny RPN calculator, because "expr" didn't give me bitwise operations. */
static const char math_usage[] = "math expression ...\n\n"
"This is a Tiny RPN calculator that understands the\n"
static const char math_usage[] = "math expression ...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nThis is a Tiny RPN calculator that understands the\n"
"following operations: +, -, /, *, and, or, not, eor.\n"
"i.e. 'math 2 2 add' -> 4, and 'math 8 8 \\* 2 2 + /' -> 16\n";
"i.e. 'math 2 2 add' -> 4, and 'math 8 8 \\* 2 2 + /' -> 16\n"
#endif
;
static double stack[100];
static unsigned int pointer;

View File

@ -26,6 +26,13 @@
* Perhaps this will make it simpler to internationalize also, and
* may make the binary slightly smaller.
*/
// TO use, do something like this
//
//#define BB_DECLARE_EXTERN
//#define bb_need_memory_exhausted
//#include "messages.c"
//
#ifndef _BB_MESSAGES_C
#define _BB_MESSAGES_C
@ -59,4 +66,9 @@ BB_DEF_MESSAGE(name_too_long, "%s: file name too long\n")
#if defined bb_need_io_error || ! defined BB_DECLARE_EXTERN
BB_DEF_MESSAGE(io_error, "%s: input/output error -- %s\n")
#endif
#if defined bb_need_help || ! defined BB_DECLARE_EXTERN
BB_DEF_MESSAGE(dash_dash_help, "--help")
#endif
#endif /* _BB_MESSAGES_C */

View File

@ -17,8 +17,9 @@
#include <sys/stat.h>
static const char makedevs_usage[] =
"makedevs NAME TYPE MAJOR MINOR FIRST LAST [s]\n\n"
"Creates a range of block or character special files\n\n"
"makedevs NAME TYPE MAJOR MINOR FIRST LAST [s]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nCreates a range of block or character special files\n\n"
"TYPEs include:\n"
"\tb:\tMake a block (buffered) device.\n"
"\tc or u:\tMake a character (un-buffered) device.\n"
@ -28,7 +29,9 @@ static const char makedevs_usage[] =
"If 's' is the last argument, the base device is created as well.\n\n"
"For example:\n"
"\tmakedevs /dev/ttyS c 4 66 2 63 -> ttyS2-ttyS63\n"
"\tmakedevs /dev/hda b 3 0 0 8 s -> hda,hda1-hda8\n";
"\tmakedevs /dev/hda b 3 0 0 8 s -> hda,hda1-hda8\n"
#endif
;
int makedevs_main(int argc, char **argv)
{

View File

@ -4,8 +4,11 @@
#include <sys/mtio.h>
#include <sys/fcntl.h>
static const char mt_usage[] = "mt [-f device] opcode value\n\n"
"Control magnetic tape drive operation\n";
static const char mt_usage[] = "mt [-f device] opcode value\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nControl magnetic tape drive operation\n"
#endif
;
struct mt_opcodes {
char *name;

View File

@ -35,12 +35,15 @@ _syscall2(int, bdflush, int, func, int, data);
#endif /* __GLIBC__ */
static char update_usage[] =
"update [options]\n\n"
"Periodically flushes filesystem buffers.\n\n"
"update [options]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nPeriodically flushes filesystem buffers.\n\n"
"Options:\n"
"\t-S\tforce use of sync(2) instead of flushing\n"
"\t-s SECS\tcall sync this often (default 30)\n"
"\t-f SECS\tflush some buffers this often (default 5)\n";
"\t-f SECS\tflush some buffers this often (default 5)\n"
#endif
;
static unsigned int sync_duration = 30;
static unsigned int flush_duration = 5;

View File

@ -30,12 +30,15 @@
#include <errno.h>
static const char mkdir_usage[] =
"mkdir [OPTION] DIRECTORY...\n\n"
"Create the DIRECTORY(ies), if they do not already exist\n\n"
"mkdir [OPTION] DIRECTORY...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nCreate the DIRECTORY(ies), if they do not already exist\n\n"
"Options:\n"
"\t-m\tset permission mode (as in chmod), not rwxrwxrwx - umask\n"
"\t-p\tno error if existing, make parent directories as needed\n";
"\t-p\tno error if existing, make parent directories as needed\n"
#endif
;
static int parentFlag = FALSE;

View File

@ -26,11 +26,13 @@
#include <sys/stat.h>
#include <errno.h>
static const char mkfifo_usage[] = "mkfifo [OPTIONS] name\n\n"
"Creates a named pipe (identical to 'mknod name p')\n\n"
static const char mkfifo_usage[] = "mkfifo [OPTIONS] name\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nCreates a named pipe (identical to 'mknod name p')\n\n"
"Options:\n"
"\t-m\tcreate the pipe using the specified mode (default a=rw)\n";
"\t-m\tcreate the pipe using the specified mode (default a=rw)\n"
#endif
;
extern int mkfifo_main(int argc, char **argv)
{

View File

@ -179,9 +179,10 @@ static volatile void show_usage()
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
BB_VER, BB_BT);
fprintf(stderr,
"Usage: %s [-c | -l filename] [-nXX] [-iXX] /dev/name [blocks]\n\n",
"Usage: %s [-c | -l filename] [-nXX] [-iXX] /dev/name [blocks]\n",
program_name);
fprintf(stderr, "Make a MINIX filesystem.\n\n");
#ifndef BB_FEATURE_TRIVIAL_HELP
fprintf(stderr, "\nMake a MINIX filesystem.\n\n");
fprintf(stderr, "OPTIONS:\n");
fprintf(stderr, "\t-c\t\tCheck the device for bad blocks\n");
fprintf(stderr,
@ -191,6 +192,7 @@ static volatile void show_usage()
fprintf(stderr,
"\t-l FILENAME\tRead the bad blocks list from FILENAME\n");
fprintf(stderr, "\t-v\t\tMake a Minix version 2 filesystem\n\n");
#endif
exit(16);
}

View File

@ -28,14 +28,17 @@
#include <fcntl.h>
#include <unistd.h>
static const char mknod_usage[] = "mknod [OPTIONS] NAME TYPE MAJOR MINOR\n\n"
"Create a special file (block, character, or pipe).\n\n"
static const char mknod_usage[] = "mknod [OPTIONS] NAME TYPE MAJOR MINOR\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nCreate a special file (block, character, or pipe).\n\n"
"Options:\n"
"\t-m\tcreate the special file using the specified mode (default a=rw)\n\n"
"TYPEs include:\n"
"\tb:\tMake a block (buffered) device.\n"
"\tc or u:\tMake a character (un-buffered) device.\n"
"\tp:\tMake a named pipe. MAJOR and MINOR are ignored for named pipes.\n";
"\tp:\tMake a named pipe. MAJOR and MINOR are ignored for named pipes.\n"
#endif
;
int mknod_main(int argc, char **argv)
{

View File

@ -49,13 +49,16 @@
static const char mkswap_usage[] =
"mkswap [-c] [-v0|-v1] device [block-count]\n\n"
"Prepare a disk partition to be used as a swap partition.\n\n"
"mkswap [-c] [-v0|-v1] device [block-count]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nPrepare a disk partition to be used as a swap partition.\n\n"
"Options:\n" "\t-c\t\tCheck for read-ability.\n"
"\t-v0\t\tMake version 0 swap [max 128 Megs].\n"
"\t-v1\t\tMake version 1 swap [big!] (default for kernels > 2.1.117).\n"
"\tblock-count\tNumber of block to use (default is entire partition).\n";
"\tblock-count\tNumber of block to use (default is entire partition).\n"
#endif
;
#ifndef _IO

View File

@ -70,12 +70,15 @@ _syscall2(unsigned long, create_module, const char *, name, size_t, size)
static char m_filename[BUFSIZ + 1] = "\0";
static char m_fullName[BUFSIZ + 1] = "\0";
static const char insmod_usage[] =
"insmod [OPTION]... MODULE [symbol=value]...\n\n"
"Loads the specified kernel modules into the kernel.\n\n"
"insmod [OPTION]... MODULE [symbol=value]...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nLoads the specified kernel modules into the kernel.\n\n"
"Options:\n"
"\t-f\tForce module to load into the wrong kernel version.\n"
"\t-k\tMake module autoclean-able.\n";
"\t-k\tMake module autoclean-able.\n"
#endif
;
static int findNamedModule(const char *fileName, struct stat *statbuf)

View File

@ -36,10 +36,13 @@ _syscall1(int, delete_module, const char *, name)
static const char rmmod_usage[] =
"rmmod [OPTION]... [MODULE]...\n\n"
"Unloads the specified kernel modules from the kernel.\n\n"
"Options:\n" "\t-a\tTry to remove all unused kernel modules.\n";
"rmmod [OPTION]... [MODULE]...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nUnloads the specified kernel modules from the kernel.\n\n"
"Options:\n"
"\t-a\tTry to remove all unused kernel modules.\n"
#endif
;

11
more.c
View File

@ -30,8 +30,15 @@
#include <fcntl.h>
#include <signal.h>
#include <sys/ioctl.h>
#define BB_DECLARE_EXTERN
#define bb_need_help
#include "messages.c"
static const char more_usage[] = "more [file ...]\n";
static const char more_usage[] = "more [FILE ...]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nMore is a filter for viewing FILE one screenful at a time.\n"
#endif
;
/* ED: sparc termios is broken: revert back to old termio handling. */
#ifdef BB_FEATURE_USE_TERMIOS
@ -92,7 +99,7 @@ extern int more_main(int argc, char **argv)
argv++;
if (argc > 0
&& (strcmp(*argv, "--help") == 0 || strcmp(*argv, "-h") == 0)) {
&& (strcmp(*argv, dash_dash_help) == 0 || strcmp(*argv, "-h") == 0)) {
usage(more_usage);
}
do {

18
mount.c
View File

@ -64,10 +64,12 @@ static int use_loop = FALSE;
extern const char mtab_file[]; /* Defined in utility.c */
static const char mount_usage[] = "\tmount [flags]\n"
"\tmount [flags] device directory [-o options,more-options]\n"
"\n" "Flags:\n"
"\t-a:\t\tMount all file systems in fstab.\n"
static const char mount_usage[] =
"mount [flags] device directory [-o options,more-options]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nMount a filesystem\n\n"
"Flags:\n"
"\t-a:\t\tMount all filesystems in fstab.\n"
#ifdef BB_MTAB
"\t-f:\t\t\"Fake\" mount. Add entry to mount table but don't mount it.\n"
"\t-n:\t\tDon't write a mount table entry.\n"
@ -88,8 +90,10 @@ static const char mount_usage[] = "\tmount [flags]\n"
"\tsuid/nosuid:\tAllow set-user-id-root programs / disallow them.\n"
"\tremount:\tRe-mount a currently-mounted filesystem, changing its flags.\n"
"\tro/rw:\t\tMount for read-only / read-write.\n"
"There are EVEN MORE flags that are specific to each filesystem.\n"
"You'll have to see the written documentation for those.\n";
"\nThere are EVEN MORE flags that are specific to each filesystem.\n"
"You'll have to see the written documentation for those.\n"
#endif
;
struct mount_options {
@ -451,7 +455,7 @@ extern int mount_main(int argc, char **argv)
fatalError( "\nCannot read /etc/fstab: %s\n", strerror (errno));
while ((m = getmntent(f)) != NULL) {
// If the file system isn't noauto,
// If the filesystem isn't noauto,
// and isn't swap or nfs, then mount it
if ((!strstr(m->mnt_opts, "noauto")) &&
(!strstr(m->mnt_type, "swap")) &&

7
mt.c
View File

@ -4,8 +4,11 @@
#include <sys/mtio.h>
#include <sys/fcntl.h>
static const char mt_usage[] = "mt [-f device] opcode value\n\n"
"Control magnetic tape drive operation\n";
static const char mt_usage[] = "mt [-f device] opcode value\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nControl magnetic tape drive operation\n"
#endif
;
struct mt_opcodes {
char *name;

View File

@ -1,5 +1,5 @@
/* vi: set sw=4 ts=4: */
/* mnc: mini-netcat - built from the ground up for LRP
/* nc: mini-netcat - built from the ground up for LRP
Copyright (C) 1998 Charles P. Wright
0.0.1 6K It works.
@ -40,11 +40,13 @@
#define BUFSIZE 100
static const char mnc_usage[] =
static const char nc_usage[] = "nc [IP] [port]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nNetcat opens a pipe to IP:port\n"
#endif
;
"mnc [IP] [port]\n\n" "mini-netcat opens a pipe to IP:port\n";
int mnc_main(int argc, char **argv)
int nc_main(int argc, char **argv)
{
int sfd;
int result;
@ -59,7 +61,7 @@ int mnc_main(int argc, char **argv)
argc--;
argv++;
if (argc < 2 || **(argv + 1) == '-') {
usage(mnc_usage);
usage(nc_usage);
}
sfd = socket(AF_INET, SOCK_STREAM, 0);

View File

@ -1,6 +1,6 @@
/* vi: set sw=4 ts=4: */
/*
* $Id: hostname.c,v 1.7 2000/02/08 19:58:47 erik Exp $
* $Id: hostname.c,v 1.8 2000/05/12 19:41:47 erik Exp $
* Mini hostname implementation for busybox
*
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
@ -31,15 +31,18 @@
#include <stdio.h>
static const char *hostname_usage =
"hostname [OPTION] {hostname | -F file}\n\n"
"Get or set the hostname or DNS domain name. If a hostname is given\n"
"hostname [OPTION] {hostname | -F file}\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nGet or set the hostname or DNS domain name. If a hostname is given\n"
"(or a file with the -F parameter), the host name will be set.\n\n"
"Options:\n"
"\t-s\t\tShort\n"
"\t-i\t\tAddresses for the hostname\n"
"\t-d\t\tDNS domain name\n"
"\t-F FILE\t\tUse the contents of FILE to specify the hostname\n";
"\t-F FILE\t\tUse the contents of FILE to specify the hostname\n"
#endif
;
void do_sethostname(char *s, int isfile)

133
networking/nc.c Normal file
View File

@ -0,0 +1,133 @@
/* vi: set sw=4 ts=4: */
/* nc: mini-netcat - built from the ground up for LRP
Copyright (C) 1998 Charles P. Wright
0.0.1 6K It works.
0.0.2 5K Smaller and you can also check the exit condition if you wish.
0.0.3 Uses select()
19980918 Busy Boxed! Dave Cinege
19990512 Uses Select. Charles P. Wright
19990513 Fixes stdin stupidity and uses buffers. Charles P. Wright
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 "internal.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#define BUFSIZE 100
static const char nc_usage[] = "nc [IP] [port]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nNetcat opens a pipe to IP:port\n"
#endif
;
int nc_main(int argc, char **argv)
{
int sfd;
int result;
int len;
char ch[BUFSIZE];
struct sockaddr_in address;
struct hostent *hostinfo;
fd_set readfds, testfds;
argc--;
argv++;
if (argc < 2 || **(argv + 1) == '-') {
usage(nc_usage);
}
sfd = socket(AF_INET, SOCK_STREAM, 0);
hostinfo = (struct hostent *) gethostbyname(*argv);
if (!hostinfo) {
exit(1);
}
address.sin_family = AF_INET;
address.sin_addr = *(struct in_addr *) *hostinfo->h_addr_list;
address.sin_port = htons(atoi(*(++argv)));
len = sizeof(address);
result = connect(sfd, (struct sockaddr *) &address, len);
if (result < 0) {
exit(2);
}
FD_ZERO(&readfds);
FD_SET(sfd, &readfds);
FD_SET(fileno(stdin), &readfds);
while (1) {
int fd;
int ofd;
int nread;
testfds = readfds;
result =
select(FD_SETSIZE, &testfds, (fd_set *) NULL, (fd_set *) NULL,
(struct timeval *) 0);
if (result < 1) {
exit(3);
}
for (fd = 0; fd < FD_SETSIZE; fd++) {
if (FD_ISSET(fd, &testfds)) {
int trn = 0;
int rn;
ioctl(fd, FIONREAD, &nread);
if (fd == sfd) {
if (nread == 0)
exit(0);
ofd = fileno(stdout);
} else {
ofd = sfd;
}
do {
rn = (BUFSIZE < nread - trn) ? BUFSIZE : nread - trn;
trn += rn;
read(fd, ch, rn);
write(ofd, ch, rn);
}
while (trn < nread);
}
}
}
}

View File

@ -41,7 +41,11 @@
| + find out how the real nslookup gets the default name server
*/
static const char nslookup_usage[] = "nslookup [HOST]\n\nQueries the nameserver for the IP address of the given HOST\n";
static const char nslookup_usage[] = "nslookup [HOST]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nQueries the nameserver for the IP address of the given HOST\n"
#endif
;
/* I have to see how the real nslookup does this.
@ -173,4 +177,4 @@ int nslookup_main(int argc, char **argv)
exit( TRUE);
}
/* $Id: nslookup.c,v 1.8 2000/05/02 00:07:56 erik Exp $ */
/* $Id: nslookup.c,v 1.9 2000/05/12 19:41:47 erik Exp $ */

View File

@ -1,6 +1,6 @@
/* vi: set sw=4 ts=4: */
/*
* $Id: ping.c,v 1.14 2000/04/25 23:24:55 erik Exp $
* $Id: ping.c,v 1.15 2000/05/12 19:41:47 erik Exp $
* Mini ping implementation for busybox
*
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
@ -90,7 +90,11 @@ static int in_cksum(unsigned short *buf, int sz)
/* simple version */
#ifdef BB_SIMPLE_PING
static const char *ping_usage = "ping host\n\n";
static const char *ping_usage = "ping host\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nSend ICMP ECHO_REQUEST packets to network hosts\n"
#endif
;
static char *hostname = NULL;
@ -179,12 +183,15 @@ extern int ping_main(int argc, char **argv)
#else
/* full(er) version */
static const char *ping_usage = "ping [OPTION]... host\n\n"
"Send ICMP ECHO_REQUEST packets to network hosts.\n\n"
static const char *ping_usage = "ping [OPTION]... host\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nSend ICMP ECHO_REQUEST packets to network hosts.\n\n"
"Options:\n"
"\t-c COUNT\tSend only COUNT pings.\n"
"\t-q\t\tQuiet mode, only displays output at start\n"
"\t\t\tand when finished.\n";
"\t\t\tand when finished.\n"
#endif
;
static char *hostname = NULL;
static struct sockaddr_in pingaddr;

View File

@ -1,5 +1,5 @@
/*
* $Id: telnet.c,v 1.2 2000/05/01 19:10:52 erik Exp $
* $Id: telnet.c,v 1.3 2000/05/12 19:41:47 erik Exp $
* Mini telnet implementation for busybox
*
* Copyright (C) 2000 by Randolph Chung <tausq@debian.org>
@ -46,7 +46,12 @@
static int STDIN = 0;
static int STDOUT = 1;
static const char *telnet_usage = "telnet host [port]\n\n";
static const char *telnet_usage = "telnet host [port]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nProvides interactive communication with another\n"
"networked host using the TELNET protocol\n"
#endif
;
static struct termios saved_tc;
static unsigned char options[NTELOPTS];
static char tr_state = 0; /* telnet send and receive state */

View File

@ -41,7 +41,11 @@
| + find out how the real nslookup gets the default name server
*/
static const char nslookup_usage[] = "nslookup [HOST]\n\nQueries the nameserver for the IP address of the given HOST\n";
static const char nslookup_usage[] = "nslookup [HOST]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nQueries the nameserver for the IP address of the given HOST\n"
#endif
;
/* I have to see how the real nslookup does this.
@ -173,4 +177,4 @@ int nslookup_main(int argc, char **argv)
exit( TRUE);
}
/* $Id: nslookup.c,v 1.8 2000/05/02 00:07:56 erik Exp $ */
/* $Id: nslookup.c,v 1.9 2000/05/12 19:41:47 erik Exp $ */

17
ping.c
View File

@ -1,6 +1,6 @@
/* vi: set sw=4 ts=4: */
/*
* $Id: ping.c,v 1.14 2000/04/25 23:24:55 erik Exp $
* $Id: ping.c,v 1.15 2000/05/12 19:41:47 erik Exp $
* Mini ping implementation for busybox
*
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
@ -90,7 +90,11 @@ static int in_cksum(unsigned short *buf, int sz)
/* simple version */
#ifdef BB_SIMPLE_PING
static const char *ping_usage = "ping host\n\n";
static const char *ping_usage = "ping host\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nSend ICMP ECHO_REQUEST packets to network hosts\n"
#endif
;
static char *hostname = NULL;
@ -179,12 +183,15 @@ extern int ping_main(int argc, char **argv)
#else
/* full(er) version */
static const char *ping_usage = "ping [OPTION]... host\n\n"
"Send ICMP ECHO_REQUEST packets to network hosts.\n\n"
static const char *ping_usage = "ping [OPTION]... host\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nSend ICMP ECHO_REQUEST packets to network hosts.\n\n"
"Options:\n"
"\t-c COUNT\tSend only COUNT pings.\n"
"\t-q\t\tQuiet mode, only displays output at start\n"
"\t\t\tand when finished.\n";
"\t\t\tand when finished.\n"
#endif
;
static char *hostname = NULL;
static struct sockaddr_in pingaddr;

View File

@ -139,7 +139,12 @@ static void verify __P((char *s, char *end));
/* The value to return to the calling program. */
static int exit_status;
static const char printf_usage[] = "printf format [argument...]\n\nFormats and prints the given data.\n";
static const char printf_usage[] = "printf FORMAT [ARGUMENT...]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nFormats and prints ARGUMENT(s) according to FORMAT,\n"
"Where FORMAT controls the output exactly as in C printf.\n"
#endif
;
int printf_main(int argc, char **argv)
{

View File

@ -37,6 +37,14 @@ extern int free_main(int argc, char **argv)
info.sharedram/=DIVISOR;
info.bufferram/=DIVISOR;
if (argc > 1 && **(argv + 1) == '-') {
usage("free\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nDisplays the amount of free and used system memory\n"
#endif
);
}
printf("%6s%13s%13s%13s%13s%13s\n", "", "total", "used", "free",
"shared", "buffers");

View File

@ -32,16 +32,22 @@
#include <unistd.h>
static const char *kill_usage =
"kill [-signal] process-id [process-id ...]\n\n"
"Send a signal (default is SIGTERM) to the specified process(es).\n\n"
"Options:\n" "\t-l\tList all signal names and numbers.\n\n";
"kill [-signal] process-id [process-id ...]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nSend a signal (default is SIGTERM) to the specified process(es).\n\n"
"Options:\n" "\t-l\tList all signal names and numbers.\n\n"
#endif
;
#ifdef BB_KILLALL
static const char *killall_usage =
"killall [-signal] process-name [process-name ...]\n\n"
"Send a signal (default is SIGTERM) to the specified process(es).\n\n"
"Options:\n" "\t-l\tList all signal names and numbers.\n\n";
"killall [-signal] process-name [process-name ...]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nSend a signal (default is SIGTERM) to the specified process(es).\n\n"
"Options:\n" "\t-l\tList all signal names and numbers.\n\n"
#endif
#endif
;
#define KILL 0
#define KILLALL 1

View File

@ -36,6 +36,9 @@
#include <fcntl.h>
#include <ctype.h>
#include <sys/ioctl.h>
#define BB_DECLARE_EXTERN
#define bb_need_help
#include "messages.c"
#if ! defined BB_FEATURE_USE_DEVPS_PATCH
@ -128,8 +131,13 @@ extern int ps_main(int argc, char **argv)
if (argc > 1 && strcmp(argv[1], "--help") == 0) {
usage ("ps\n\nReport process status\n\nThis version of ps accepts no options.\n");
if (argc > 1 && strcmp(argv[1], dash_dash_help) == 0) {
usage ("ps\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nReport process status\n"
"\nThis version of ps accepts no options.\n"
#endif
);
}
dir = opendir("/proc");

12
ps.c
View File

@ -36,6 +36,9 @@
#include <fcntl.h>
#include <ctype.h>
#include <sys/ioctl.h>
#define BB_DECLARE_EXTERN
#define bb_need_help
#include "messages.c"
#if ! defined BB_FEATURE_USE_DEVPS_PATCH
@ -128,8 +131,13 @@ extern int ps_main(int argc, char **argv)
if (argc > 1 && strcmp(argv[1], "--help") == 0) {
usage ("ps\n\nReport process status\n\nThis version of ps accepts no options.\n");
if (argc > 1 && strcmp(argv[1], dash_dash_help) == 0) {
usage ("ps\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nReport process status\n"
"\nThis version of ps accepts no options.\n"
#endif
);
}
dir = opendir("/proc");

7
pwd.c
View File

@ -24,15 +24,14 @@
#include "internal.h"
#include <stdio.h>
#include <dirent.h>
#include <errno.h>
extern int pwd_main(int argc, char **argv)
{
char buf[BUFSIZ + 1];
if (getcwd(buf, sizeof(buf)) == NULL) {
perror("get working directory");
exit(FALSE);
}
if (getcwd(buf, sizeof(buf)) == NULL)
fatalError("pwd: %s", strerror(errno));
printf("%s\n", buf);
exit(TRUE);

10
rm.c
View File

@ -29,12 +29,14 @@
#include <dirent.h>
#include <errno.h>
static const char *rm_usage = "rm [OPTION]... FILE...\n\n"
"Remove (unlink) the FILE(s).\n\n"
static const char *rm_usage = "rm [OPTION]... FILE...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nRemove (unlink) the FILE(s).\n\n"
"Options:\n"
"\t-f\t\tremove existing destinations, never prompt\n"
"\t-r or -R\tremove the contents of directories recursively\n";
"\t-r or -R\tremove the contents of directories recursively\n"
#endif
;
static int recursiveFlag = FALSE;

View File

@ -31,7 +31,11 @@ extern int rmdir_main(int argc, char **argv)
{
if (argc == 1 || **(argv + 1) == '-') {
usage
("rmdir [OPTION]... DIRECTORY...\n\nRemove the DIRECTORY(ies), if they are empty.\n");
("rmdir [OPTION]... DIRECTORY...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nRemove the DIRECTORY(ies), if they are empty.\n"
#endif
);
}
while (--argc > 0) {

11
rmmod.c
View File

@ -36,10 +36,13 @@ _syscall1(int, delete_module, const char *, name)
static const char rmmod_usage[] =
"rmmod [OPTION]... [MODULE]...\n\n"
"Unloads the specified kernel modules from the kernel.\n\n"
"Options:\n" "\t-a\tTry to remove all unused kernel modules.\n";
"rmmod [OPTION]... [MODULE]...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nUnloads the specified kernel modules from the kernel.\n\n"
"Options:\n"
"\t-a\tTry to remove all unused kernel modules.\n"
#endif
;

Some files were not shown because too many files have changed in this diff Show More