hey: Added -h and --help for usage text.
* Didn't do anything before that. * Removed some useless comments. * This file could really need a cleanup.
This commit is contained in:
+41
-36
@@ -175,9 +175,9 @@ parse(BMessenger& the_application, int argc, char *argv[], int32 argapp)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!silent) {
|
if (!silent) {
|
||||||
printf("error 0x%8" B_PRIx32 "\n",
|
printf("error 0x%8" B_PRIx32 "\n",
|
||||||
the_reply.FindInt32("error"));
|
the_reply.FindInt32("error"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
@@ -239,43 +239,49 @@ parse(BMessenger& the_application, int argc, char *argv[], int32 argapp)
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
usage(int exitCode)
|
||||||
|
{
|
||||||
|
fprintf(exitCode == EXIT_SUCCESS ? stdout : stderr,
|
||||||
|
"hey %s, written by Attila Mezei ([email protected])\n"
|
||||||
|
"usage: hey [-s][-o] <app|signature|teamid> [let <specifier> do] <verb> <specifier_1> <of\n"
|
||||||
|
" <specifier_n>>* [to <value>] [with name=<value> [and name=<value>]*]\n"
|
||||||
|
"where <verb> : DO|GET|SET|COUNT|CREATE|DELETE|GETSUITES|QUIT|SAVE|LOAD|'what'\n"
|
||||||
|
" <specifier> : [the] <property_name> [ <index> | name | \"name\" | '\"name\"' ]\n"
|
||||||
|
" <index> : int | -int | '['int']' | '['-int']' | '['startint to end']'\n"
|
||||||
|
" <value> : \"string\" | <integer> | <float> | bool(value) | int8(value)\n"
|
||||||
|
" | int16(value) | int32(value) | float(value) | double(value)\n"
|
||||||
|
" | BPoint(x,y) | BRect(l,t,r,b) | rgb_color(r,g,b,a) | file(path)\n"
|
||||||
|
"options: -s: silent\n"
|
||||||
|
" -o: output result to stdout for easy parsing\n\n", VERSION);
|
||||||
|
exit(exitCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
BApplication app("application/x-amezei-hey");
|
BApplication app("application/x-amezei-hey");
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2)
|
||||||
fprintf(stderr, "hey %s, written by Attila Mezei ([email protected])\n" \
|
usage(1);
|
||||||
"usage: hey [-s][-o] <app|signature|teamid> [let <specifier> do] <verb> <specifier_1> <of\n" \
|
|
||||||
" <specifier_n>>* [to <value>] [with name=<value> [and name=<value>]*]\n" \
|
|
||||||
"where <verb> : DO|GET|SET|COUNT|CREATE|DELETE|GETSUITES|QUIT|SAVE|LOAD|'what'\n" \
|
|
||||||
" <specifier> : [the] <property_name> [ <index> | name | \"name\" | '\"name\"' ]\n" \
|
|
||||||
" <index> : int | -int | '['int']' | '['-int']' | '['startint to end']'\n" \
|
|
||||||
" <value> : \"string\" | <integer> | <float> | bool(value) | int8(value)\n" \
|
|
||||||
" | int16(value) | int32(value) | float(value) | double(value)\n" \
|
|
||||||
" | BPoint(x,y) | BRect(l,t,r,b) | rgb_color(r,g,b,a) | file(path)\n" \
|
|
||||||
"options: -s: silent\n" \
|
|
||||||
" -o: output result to stdout for easy parsing\n\n", VERSION);
|
|
||||||
// Updated Usage string to reflect "do", "the", bare -index, and '"name"' changes below
|
|
||||||
// -- [email protected] 1999-11-03
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32 argapp = 1;
|
int32 argapp = 1;
|
||||||
silent = false;
|
silent = false;
|
||||||
output = false;
|
output = false;
|
||||||
|
|
||||||
// Updated option mechanism --SS
|
// Updated option mechanism
|
||||||
for (int i = 0; i < argc; i++) {
|
for (int i = 0; i < argc; i++) {
|
||||||
if (strcmp(argv[i], "-s") == 0 || strcmp(argv[i], "-S") == 0) {
|
if (strcmp(argv[i], "-s") == 0 || strcmp(argv[i], "-S") == 0) {
|
||||||
silent = true;
|
silent = true;
|
||||||
argapp++;
|
argapp++;
|
||||||
}
|
} else if (strcmp(argv[i], "-o") == 0 || strcmp(argv[i], "-O") == 0) {
|
||||||
if (strcmp(argv[i], "-o") == 0 || strcmp(argv[i], "-O") == 0) {
|
|
||||||
output = true;
|
output = true;
|
||||||
argapp++;
|
argapp++;
|
||||||
}
|
} else if (strcmp(argv[1], "-h") == 0
|
||||||
|
|| strcmp(argv[1], "--help") == 0)
|
||||||
|
usage(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// find the application
|
// find the application
|
||||||
@@ -352,8 +358,9 @@ HeyInterpreterThreadHook(void* arg)
|
|||||||
status_t
|
status_t
|
||||||
Hey(BMessenger* target, const char* arg, BMessage* reply)
|
Hey(BMessenger* target, const char* arg, BMessage* reply)
|
||||||
{
|
{
|
||||||
BList argv; // number of tokens is now limited only by memory -- [email protected] 1999-11-03
|
BList argv;
|
||||||
char* tokens = new char[strlen(arg)*2];
|
char* tokens = new char[strlen(arg) * 2];
|
||||||
|
// number of tokens is limited only by memory
|
||||||
char* currentToken = tokens;
|
char* currentToken = tokens;
|
||||||
int32 tokenNdex = 0;
|
int32 tokenNdex = 0;
|
||||||
int32 argNdex = 0;
|
int32 argNdex = 0;
|
||||||
@@ -387,7 +394,7 @@ Hey(BMessenger* target, const char* arg, BMessage* reply)
|
|||||||
|
|
||||||
int32 argx = 0;
|
int32 argx = 0;
|
||||||
status_t ret = Hey(target, (char **)argv.Items(), &argx, argv.CountItems() - 1, reply);
|
status_t ret = Hey(target, (char **)argv.Items(), &argx, argv.CountItems() - 1, reply);
|
||||||
// This used to be "return Hey(...);"---so tokens wasn't delete'd. -- [email protected] 1999-11-03
|
// This used to be "return Hey(...);"---so tokens wasn't delete'd.
|
||||||
delete[] tokens;
|
delete[] tokens;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -413,7 +420,6 @@ Hey(BMessenger* target, char* argv[], int32* argx, int32 argc, BMessage* reply)
|
|||||||
bool direct_what = false;
|
bool direct_what = false;
|
||||||
BMessage the_message;
|
BMessage the_message;
|
||||||
if (strcasecmp(argv[*argx], "let") == 0) {
|
if (strcasecmp(argv[*argx], "let") == 0) {
|
||||||
// added "let" -- [email protected] 31may2000
|
|
||||||
BMessage get_target (B_GET_PROPERTY);
|
BMessage get_target (B_GET_PROPERTY);
|
||||||
get_target.AddSpecifier ("Messenger");
|
get_target.AddSpecifier ("Messenger");
|
||||||
// parse the specifiers
|
// parse the specifiers
|
||||||
@@ -445,10 +451,9 @@ Hey(BMessenger* target, char* argv[], int32* argx, int32 argc, BMessage* reply)
|
|||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (strcasecmp(argv[*argx], "do") == 0) {
|
if (strcasecmp(argv[*argx], "do") == 0)
|
||||||
// added "do" -- [email protected] 1999-11-03
|
|
||||||
the_message.what = B_EXECUTE_PROPERTY;
|
the_message.what = B_EXECUTE_PROPERTY;
|
||||||
} else if (strcasecmp(argv[*argx], "get") == 0)
|
else if (strcasecmp(argv[*argx], "get") == 0)
|
||||||
the_message.what = B_GET_PROPERTY;
|
the_message.what = B_GET_PROPERTY;
|
||||||
else if (strcasecmp(argv[*argx], "set") == 0)
|
else if (strcasecmp(argv[*argx], "set") == 0)
|
||||||
the_message.what = B_SET_PROPERTY;
|
the_message.what = B_SET_PROPERTY;
|
||||||
@@ -533,7 +538,7 @@ Hey(BMessenger* target, char* argv[], int32* argx, int32 argc, BMessage* reply)
|
|||||||
if (strcmp(vinfo[vinfo_index].name,
|
if (strcmp(vinfo[vinfo_index].name,
|
||||||
argv[*argx]) == 0) {
|
argv[*argx]) == 0) {
|
||||||
found = true;
|
found = true;
|
||||||
the_message.what =
|
the_message.what =
|
||||||
vinfo[vinfo_index].value;
|
vinfo[vinfo_index].value;
|
||||||
#if TEST_VALUEINFO>0
|
#if TEST_VALUEINFO>0
|
||||||
printf("FOUND COMMAND \"%s\" = %lX\n",
|
printf("FOUND COMMAND \"%s\" = %lX\n",
|
||||||
@@ -687,7 +692,7 @@ add_specifier(BMessage *to_message, char *argv[], int32 *argx, int32 argc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (strcasecmp(property, "the") == 0) {
|
if (strcasecmp(property, "the") == 0) {
|
||||||
// skip "the", read real property -- [email protected] 1999-11-03
|
// skip "the", read real property
|
||||||
property = argv[*argx];
|
property = argv[*argx];
|
||||||
if (property == NULL)
|
if (property == NULL)
|
||||||
return B_BAD_SCRIPT_SYNTAX;
|
return B_BAD_SCRIPT_SYNTAX;
|
||||||
@@ -770,7 +775,7 @@ add_specifier(BMessage *to_message, char *argv[], int32 *argx, int32 argc)
|
|||||||
// if it contains only digits, it will be an index...
|
// if it contains only digits, it will be an index...
|
||||||
bool index_spec = true;
|
bool index_spec = true;
|
||||||
bool reverse = specifier[0] == '-';
|
bool reverse = specifier[0] == '-';
|
||||||
// accept bare reverse-index-specs -- [email protected] 1999-11-03
|
// accept bare reverse-index-specs
|
||||||
size_t speclen = strlen(specifier);
|
size_t speclen = strlen(specifier);
|
||||||
for (int32 i = (reverse ? 1 : 0); i < (int32)speclen; ++i) {
|
for (int32 i = (reverse ? 1 : 0); i < (int32)speclen; ++i) {
|
||||||
if (specifier[i] < '0' || specifier[i] > '9') {
|
if (specifier[i] < '0' || specifier[i] > '9') {
|
||||||
@@ -781,7 +786,7 @@ add_specifier(BMessage *to_message, char *argv[], int32 *argx, int32 argc)
|
|||||||
|
|
||||||
if (index_spec) {
|
if (index_spec) {
|
||||||
if (reverse) {
|
if (reverse) {
|
||||||
// Copied from above -- [email protected] 1999-11-03
|
// Copied from above
|
||||||
BMessage revspec(B_REVERSE_INDEX_SPECIFIER);
|
BMessage revspec(B_REVERSE_INDEX_SPECIFIER);
|
||||||
revspec.AddString("property", property);
|
revspec.AddString("property", property);
|
||||||
revspec.AddInt32("index", atol(specifier + 1));
|
revspec.AddInt32("index", atol(specifier + 1));
|
||||||
@@ -789,8 +794,8 @@ add_specifier(BMessage *to_message, char *argv[], int32 *argx, int32 argc)
|
|||||||
} else
|
} else
|
||||||
to_message->AddSpecifier(property, atol(specifier));
|
to_message->AddSpecifier(property, atol(specifier));
|
||||||
} else {
|
} else {
|
||||||
// Allow any name by counting an initial " as a literal-string indicator
|
// Allow any name by counting an initial " as a literal-string
|
||||||
// -- [email protected] 1999-11-03
|
// indicator
|
||||||
if (specifier[0] == '\"') {
|
if (specifier[0] == '\"') {
|
||||||
if (specifier[speclen - 1] == '\"')
|
if (specifier[speclen - 1] == '\"')
|
||||||
specifier[speclen - 1] = '\0';
|
specifier[speclen - 1] = '\0';
|
||||||
|
|||||||
Reference in New Issue
Block a user