use nullptr instead of NULL

This commit is contained in:
john30
2018-05-06 14:54:52 +02:00
parent dc12476bc1
commit 1c17f7c466
41 changed files with 625 additions and 626 deletions
+18 -18
View File
@@ -56,7 +56,7 @@ static struct options opt = {
8888, // port
0, // timeout
NULL, // args
nullptr, // args
0 // argCount
};
@@ -78,28 +78,28 @@ static char argpargsdoc[] = "\nCOMMAND [CMDOPT...]";
/** the definition of the known program arguments. */
static const struct argp_option argpoptions[] = {
{NULL, 0, NULL, 0, "Options:", 1 },
{"server", 's', "HOST", 0, "Connect to " PACKAGE " on HOST (name or IP) [localhost]", 0 },
{"port", 'p', "PORT", 0, "Connect to " PACKAGE " on PORT [8888]", 0 },
{"timeout", 't', "SECS", 0, "Timeout for connection to " PACKAGE ", 0 for none [0]", 0 },
{nullptr, 0, nullptr, 0, "Options:", 1 },
{"server", 's', "HOST", 0, "Connect to " PACKAGE " on HOST (name or IP) [localhost]", 0 },
{"port", 'p', "PORT", 0, "Connect to " PACKAGE " on PORT [8888]", 0 },
{"timeout", 't', "SECS", 0, "Timeout for connection to " PACKAGE ", 0 for none [0]", 0 },
{NULL, 0, NULL, 0, NULL, 0 },
{nullptr, 0, nullptr, 0, nullptr, 0 },
};
/**
* The program argument parsing function.
* @param key the key from @a argpoptions.
* @param arg the option argument, or NULL.
* @param arg the option argument, or nullptr.
* @param state the parsing state.
*/
error_t parse_opt(int key, char *arg, struct argp_state *state) {
struct options *opt = (struct options*)state->input;
char* strEnd = NULL;
char* strEnd = nullptr;
unsigned int value;
switch (key) {
// Device settings:
case 's': // --server=localhost
if (arg == NULL || arg[0] == 0) {
if (arg == nullptr || arg[0] == 0) {
argp_error(state, "invalid server");
return EINVAL;
}
@@ -107,7 +107,7 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
break;
case 'p': // --port=8888
value = strtoul(arg, &strEnd, 10);
if (strEnd == NULL || strEnd == arg || *strEnd != 0 || value < 1 || value > 65535) {
if (strEnd == nullptr || strEnd == arg || *strEnd != 0 || value < 1 || value > 65535) {
argp_error(state, "invalid port");
return EINVAL;
}
@@ -115,7 +115,7 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
break;
case 't': // --timeout=10
value = strtoul(arg, &strEnd, 10);
if (strEnd == NULL || strEnd == arg || *strEnd != 0 || value < 1 || value > 3600) {
if (strEnd == nullptr || strEnd == arg || *strEnd != 0 || value < 1 || value > 3600) {
argp_error(state, "invalid timeout");
return EINVAL;
}
@@ -173,13 +173,13 @@ string fetchData(ebusd::TCPSocket* socket, bool listening) {
while (true) {
#ifdef HAVE_PPOLL
// wait for new fd event
ret = ppoll(fds, nfds, &tdiff, NULL);
ret = ppoll(fds, nfds, &tdiff, nullptr);
#else
#ifdef HAVE_PSELECT
// set readfds to inital checkfds
fd_set readfds = checkfds;
// wait for new fd event
ret = pselect(maxfd + 1, &readfds, NULL, NULL, &tdiff, NULL);
ret = pselect(maxfd + 1, &readfds, nullptr, nullptr, &tdiff, nullptr);
#endif
#endif
@@ -248,8 +248,8 @@ bool connect(const char* host, uint16_t port, int timeout, char* const *args, in
TCPSocket* socket = client->connect(host, port, timeout);
bool ret;
bool once = args != NULL && argCount > 0;
ret = socket != NULL;
bool once = args != nullptr && argCount > 0;
ret = socket != nullptr;
if (ret) {
string message, sendmessage;
do {
@@ -263,7 +263,7 @@ bool connect(const char* host, uint16_t port, int timeout, char* const *args, in
if (i > 0) {
message += " ";
}
bool quote = strchr(args[i], ' ') != NULL && strchr(args[i], '"') == NULL;
bool quote = strchr(args[i], ' ') != nullptr && strchr(args[i], '"') == nullptr;
if (quote) {
message += "\"";
}
@@ -314,9 +314,9 @@ bool connect(const char* host, uint16_t port, int timeout, char* const *args, in
* @return the exit code.
*/
int main(int argc, char* argv[]) {
struct argp argp = { argpoptions, parse_opt, argpargsdoc, argpdoc, NULL, NULL, NULL };
struct argp argp = { argpoptions, parse_opt, argpargsdoc, argpdoc, nullptr, nullptr, nullptr };
setenv("ARGP_HELP_FMT", "no-dup-args-note", 0);
if (argp_parse(&argp, argc, argv, ARGP_IN_ORDER, NULL, &opt) != 0) {
if (argp_parse(&argp, argc, argv, ARGP_IN_ORDER, nullptr, &opt) != 0) {
return EINVAL;
}
bool success = connect(opt.server, opt.port, opt.timeout, opt.args, opt.argCount);
+12 -12
View File
@@ -83,25 +83,25 @@ static char argpargsdoc[] = "[DUMPFILE]";
/** the definition of the known program arguments. */
static const struct argp_option argpoptions[] = {
{"device", 'd', "DEV", 0, "Write to DEV (serial device) [/dev/ttyUSB60]", 0 },
{"time", 't', "USEC", 0, "Delay each byte by USEC us [10000]", 0 },
{"device", 'd', "DEV", 0, "Write to DEV (serial device) [/dev/ttyUSB60]", 0 },
{"time", 't', "USEC", 0, "Delay each byte by USEC us [10000]", 0 },
{NULL, 0, NULL, 0, NULL, 0 },
{nullptr, 0, nullptr, 0, nullptr, 0 },
};
/**
* The program argument parsing function.
* @param key the key from @a argpoptions.
* @param arg the option argument, or NULL.
* @param arg the option argument, or nullptr.
* @param state the parsing state.
*/
error_t parse_opt(int key, char *arg, struct argp_state *state) {
struct options *opt = (struct options*)state->input;
char* strEnd = NULL;
char* strEnd = nullptr;
switch (key) {
// Device settings:
case 'd': // --device=/dev/ttyUSB60
if (arg == NULL || arg[0] == 0) {
if (arg == nullptr || arg[0] == 0) {
argp_error(state, "invalid device");
return EINVAL;
}
@@ -109,14 +109,14 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
break;
case 't': // --time=10000
opt->time = (unsigned int)strtoul(arg, &strEnd, 10);
if (strEnd == NULL || strEnd == arg || *strEnd != 0 || opt->time < 1000 || opt->time > 100000000) {
if (strEnd == nullptr || strEnd == arg || *strEnd != 0 || opt->time < 1000 || opt->time > 100000000) {
argp_error(state, "invalid time");
return EINVAL;
}
break;
case ARGP_KEY_ARG:
if (state->arg_num == 0) {
if (arg == NULL || arg[0] == 0 || strcmp("/", arg) == 0) {
if (arg == nullptr || arg[0] == 0 || strcmp("/", arg) == 0) {
argp_error(state, "invalid dumpfile");
return EINVAL;
}
@@ -139,13 +139,13 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) {
* @return the exit code.
*/
int main(int argc, char* argv[]) {
struct argp argp = { argpoptions, parse_opt, argpargsdoc, argpdoc, NULL, NULL, NULL };
struct argp argp = { argpoptions, parse_opt, argpargsdoc, argpdoc, nullptr, nullptr, nullptr };
setenv("ARGP_HELP_FMT", "no-dup-args-note", 0);
if (argp_parse(&argp, argc, argv, ARGP_IN_ORDER, NULL, &opt) != 0) {
if (argp_parse(&argp, argc, argv, ARGP_IN_ORDER, nullptr, &opt) != 0) {
return EINVAL;
}
Device* device = Device::create(opt.device, false, false, NULL);
if (device == NULL) {
Device* device = Device::create(opt.device, false, false, false);
if (device == nullptr) {
cout << "unable to create device " << opt.device << endl;
return EINVAL;
}