Greetings:
With the following code, I have 3 problems:
1. ./client -psecret works, but, ./client --password=secret does not;
2. After calling load_defaults, the argument vector is getting parsed,
but, it's not making it into the switch processing. The values
from my global char *password = NULL values are being used;
3. Compiler warnings related to the struct variables. I've also tried:
{"password", optional_argument, 0, "p"},
with the same result. I didn't see anything in getopt.h that would
explain this. Using the one from sampdb/capi used in Paul's book.
main.c:38: warning: initialization makes integer from pointer without a cast
Can anyone see where the error(s) is/are?
Full source is at http://az.dedserius.com/main.c/
<begin code>
#include "getopt.h"
const char *groups[] = { "btimeshell", "client", NULL }; /* btime defaults in
.my.cnf */
struct option long_options[] =
{
{"password", optional_argument, NULL, "p"},
{"version", no_argument, NULL, "v"},
{0,0,0,0}
};
int main(int argc, char *argv[])
{
char *password = NULL; /* MySQL password */
const char* usage="Usage: btimeshell [OPTIONS]\n \
-p --password Set password you use for BTime\n \
-v --version Display btimeshell version information and exit\n\n";
int i, opt, option_index; /* getopt options */
my_init();
load_defaults ("my", groups, &argc, &argv);
printf ("Modified argument vector after load_defaults():\n");
for (i = 0; i < argc; i++)
printf ("arg %d: %s\n", i, argv[i]);
while ((opt = getopt_long (argc, argv, "T::H::u::C::B::p::vhstr",
long_options, &option_index)) != EOF)
/* This is the actual opt call in the program. The additional options have
been removed for brevity */
{
switch (opt)
{
case 'p':
/* Set MySQL password */
password = optarg;
break;
case 'v':
/* Print version */
fprintf(stderr, "%s%s%s\n\n", boldon,
BTIME_SHELL_CLIENT, boldoff);
break;
default:
break;
}
}
<end code>
Regards,
Van
--
=================================================================
Linux rocks!!! http://www.dedserius.com/
=================================================================
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php