Don't use strings directly in calls to usage(). This is in preparation

for their extraction to a separate file.
This commit is contained in:
Matt Kraai
2000-07-14 23:28:47 +00:00
parent 464c5de00d
commit 3bd8bd89ee
31 changed files with 325 additions and 293 deletions

View File

@@ -206,6 +206,19 @@ void cut()
}
}
const char cut_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 CHAR\tUse CHAR instead of tab as the field delimiter\n"
"\t-s\tOnly output Lines if the include DELIM\n"
"\t-f N\tPrint only these fields\n"
"\t-n\tIgnored\n"
#endif
;
int cut_main(int argc, char **argv)
{
@@ -213,18 +226,7 @@ int cut_main(int argc, char **argv)
int numberFilenames = 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 CHAR\tUse CHAR instead of tab as the field delimiter\n"
"\t-s\tOnly output Lines if the include DELIM\n"
"\t-f N\tPrint only these fields\n"
"\t-n\tIgnored\n"
#endif
);
usage(cut_usage);
while (i < argc) {
if (argv[i][0] == '-') {

View File

@@ -23,17 +23,19 @@
#include "internal.h"
#include <stdio.h>
const char dirname_usage[] =
"dirname [FILENAME ...]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nStrips non-directory suffix from FILENAME\n"
#endif
;
extern int dirname_main(int argc, char **argv)
{
char* s;
if ((argc < 2) || (**(argv + 1) == '-')) {
usage("dirname [FILENAME ...]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nStrips non-directory suffix from FILENAME\n"
#endif
);
}
if ((argc < 2) || (**(argv + 1) == '-'))
usage(dirname_usage);
argv++;
s=*argv+strlen(*argv)-1;

View File

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

View File

@@ -26,17 +26,17 @@
#include <stdio.h>
#include <errno.h>
const char rmdir_usage[] =
"rmdir [OPTION]... DIRECTORY...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nRemove the DIRECTORY(ies), if they are empty.\n"
#endif
;
extern int rmdir_main(int argc, char **argv)
{
if (argc == 1 || **(argv + 1) == '-') {
usage
("rmdir [OPTION]... DIRECTORY...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nRemove the DIRECTORY(ies), if they are empty.\n"
#endif
);
}
if (argc == 1 || **(argv + 1) == '-')
usage(rmdir_usage);
while (--argc > 0) {
if (rmdir(*(++argv)) == -1) {

View File

@@ -24,14 +24,16 @@
#include "internal.h"
#include <stdio.h>
const char sync_usage[] =
"sync\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nWrite all buffered filesystem blocks to disk.\n"
#endif
;
extern int sync_main(int argc, char **argv)
{
if (argc > 1 && **(argv + 1) == '-') {
usage("sync\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nWrite all buffered filesystem blocks to disk.\n"
#endif
);
}
if (argc > 1 && **(argv + 1) == '-')
usage(sync_usage);
return(sync());
}

View File

@@ -178,6 +178,15 @@ static int test_eaccess();
static int is_a_group_member();
static void initialize_group_array();
const char test_usage[] =
"test 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
;
extern int
test_main(int argc, char** argv)
{
@@ -188,15 +197,8 @@ test_main(int argc, char** argv)
fatalError("missing ]\n");
argv[argc] = NULL;
}
if (strcmp(argv[1], dash_dash_help) == 0) {
usage("test 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
);
}
if (strcmp(argv[1], dash_dash_help) == 0)
usage(test_usage);
/* Implement special cases from POSIX.2, section 4.62.4 */
switch (argc) {

View File

@@ -23,17 +23,19 @@
#include "internal.h"
#include <stdio.h>
const char yes_usage[] =
"yes [OPTION]... [STRING]...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nRepeatedly outputs a line with all specified STRING(s), or `y'.\n"
#endif
;
extern int yes_main(int argc, char **argv)
{
int i;
if (argc >= 2 && *argv[1] == '-') {
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 >= 2 && *argv[1] == '-')
usage(yes_usage);
if (argc == 1) {
while (1)