AP_HAL: allow getopt_cpp on QURT

avoid using stderr
This commit is contained in:
Andrew Tridgell 2015-12-29 19:10:46 +11:00
parent ea1e3f4928
commit dafc9b4c6b

View File

@ -36,12 +36,19 @@
*/
#include <AP_HAL/AP_HAL.h>
#if HAL_OS_POSIX_IO && CONFIG_HAL_BOARD != HAL_BOARD_QURT
#if HAL_OS_POSIX_IO
#include "getopt_cpp.h"
#include <stdio.h>
#include <string.h>
#if CONFIG_HAL_BOARD == HAL_BOARD_QURT
#define GETOPT_ERROR(...) HAP_printf(__FILE__, __LINE__, __VA_ARGS__)
#else
#define GETOPT_ERROR(...) fprintf(stderr, __VA_ARGS__)
#endif
/*
constructor
*/
@ -117,10 +124,10 @@ int GetOptLong::getoption(void)
{
if (optstring[0] == ':')
return BADARG;
if (opterr)
fprintf(stderr,
"%s: option requires an argument -- %s\n",
argv[0], place);
if (opterr) {
GETOPT_ERROR("%s: option requires an argument -- %s\n",
argv[0], place);
}
place = "";
optind++;
return BADCH;
@ -151,9 +158,9 @@ int GetOptLong::getoption(void)
}
}
if (opterr && optstring[0] != ':')
fprintf(stderr,
"%s: illegal option -- %s\n", argv[0], place);
if (opterr && optstring[0] != ':') {
GETOPT_ERROR("%s: illegal option -- %s\n", argv[0], place);
}
place = "";
optind++;
return BADCH;
@ -168,9 +175,9 @@ int GetOptLong::getoption(void)
{
if (!*place)
++optind;
if (opterr && *optstring != ':')
fprintf(stderr,
"%s: illegal option -- %c\n", argv[0], optopt);
if (opterr && *optstring != ':') {
GETOPT_ERROR("%s: illegal option -- %c\n", argv[0], optopt);
}
return BADCH;
}
@ -189,10 +196,10 @@ int GetOptLong::getoption(void)
place = "";
if (*optstring == ':')
return BADARG;
if (opterr)
fprintf(stderr,
"%s: option requires an argument -- %c\n",
argv[0], optopt);
if (opterr) {
GETOPT_ERROR("%s: option requires an argument -- %c\n",
argv[0], optopt);
}
return BADCH;
}
else