Reuse opts struct default values in the usage()

Reduce the chance of the default value printed being different from
the actual default value used.
Signed-off-by: 's avatarGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
parent 9e7f219c
......@@ -57,20 +57,39 @@
volatile int toStop = 0;
struct
{
char* clientid;
char* delimiter;
int maxdatalen;
int qos;
int retained;
char* username;
char* password;
char* host;
char* port;
int verbose;
int keepalive;
} opts =
{
"stdin-publisher", "\n", 100, 0, 0, NULL, NULL, "localhost", "1883", 0, 10
};
void usage()
{
printf("MQTT stdin publisher\n");
printf("Usage: stdinpub topicname <options>, where options are:\n");
printf(" --host <hostname> (default is localhost)\n");
printf(" --port <port> (default is 1883)\n");
printf(" --qos <qos> (default is 0)\n");
printf(" --retained (default is off)\n");
printf(" --host <hostname> (default is %s)\n", opts.host);
printf(" --port <port> (default is %s)\n", opts.port);
printf(" --qos <qos> (default is %d)\n", opts.qos);
printf(" --retained (default is %s)\n", opts.retained ? "on" : "off");
printf(" --delimiter <delim> (default is \\n)\n");
printf(" --clientid <clientid> (default is stdin-publisher)\n");
printf(" --maxdatalen <bytes> (default is 100)\n");
printf(" --clientid <clientid> (default is %s)\n", opts.clientid);
printf(" --maxdatalen <bytes> (default is %d)\n", opts.maxdatalen);
printf(" --username none\n");
printf(" --password none\n");
printf(" --keepalive <seconds> (default is 10 seconds)\n");
printf(" --keepalive <seconds> (default is %d seconds)\n", opts.keepalive);
exit(-1);
}
......@@ -92,25 +111,6 @@ void cfinish(int sig)
toStop = 1;
}
struct
{
char* clientid;
char* delimiter;
int maxdatalen;
int qos;
int retained;
char* username;
char* password;
char* host;
char* port;
int verbose;
int keepalive;
} opts =
{
"stdin-publisher", "\n", 100, 0, 0, NULL, NULL, "localhost", "1883", 0, 10
};
void getopts(int argc, char** argv);
int messageArrived(void* context, char* topicName, int topicLen, MQTTClient_message* m)
......
......@@ -56,17 +56,36 @@
volatile int toStop = 0;
struct
{
char* clientid;
char* delimiter;
int maxdatalen;
int qos;
int retained;
char* username;
char* password;
char* host;
char* port;
int verbose;
int keepalive;
} opts =
{
"stdin-publisher-async", "\n", 100, 0, 0, NULL, NULL, "localhost", "1883", 0, 10
};
void usage()
{
printf("MQTT stdin publisher\n");
printf("Usage: stdinpub topicname <options>, where options are:\n");
printf(" --host <hostname> (default is localhost)\n");
printf(" --port <port> (default is 1883)\n");
printf(" --qos <qos> (default is 0)\n");
printf(" --retained (default is off)\n");
printf(" --host <hostname> (default is %s)\n", opts.host);
printf(" --port <port> (default is %s)\n", opts.port);
printf(" --qos <qos> (default is %d)\n", opts.qos);
printf(" --retained (default is %s)\n", opts.retained ? "on" : "off");
printf(" --delimiter <delim> (default is \\n)\n");
printf(" --clientid <clientid> (default is stdin-publisher-async)\n");
printf(" --maxdatalen <bytes> (default is 100)\n");
printf(" --clientid <clientid> (default is %s)\n", opts.clientid);
printf(" --maxdatalen <bytes> (default is %d)\n", opts.maxdatalen);
printf(" --username none\n");
printf(" --password none\n");
printf(" --keepalive <seconds> (default is 10 seconds)\n");
......@@ -81,25 +100,6 @@ void cfinish(int sig)
toStop = 1;
}
struct
{
char* clientid;
char* delimiter;
int maxdatalen;
int qos;
int retained;
char* username;
char* password;
char* host;
char* port;
int verbose;
int keepalive;
} opts =
{
"stdin-publisher-async", "\n", 100, 0, 0, NULL, NULL, "localhost", "1883", 0, 10
};
void getopts(int argc, char** argv);
int messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* m)
......
......@@ -58,19 +58,37 @@
volatile int toStop = 0;
struct opts_struct
{
char* clientid;
int nodelimiter;
char* delimiter;
int qos;
char* username;
char* password;
char* host;
char* port;
int showtopics;
int keepalive;
} opts =
{
"stdout-subscriber", 0, "\n", 2, NULL, NULL, "localhost", "1883", 0, 10
};
void usage()
{
printf("MQTT stdout subscriber\n");
printf("Usage: stdoutsub topicname <options>, where options are:\n");
printf(" --host <hostname> (default is localhost)\n");
printf(" --port <port> (default is 1883)\n");
printf(" --qos <qos> (default is 2)\n");
printf(" --host <hostname> (default is %s)\n", opts.host);
printf(" --port <port> (default is %s)\n", opts.port);
printf(" --qos <qos> (default is %d)\n", opts.qos);
printf(" --delimiter <delim> (default is \\n)\n");
printf(" --clientid <clientid> (default is stdout-subscriber)\n");
printf(" --clientid <clientid> (default is %s)\n", opts.clientid);
printf(" --username none\n");
printf(" --password none\n");
printf(" --showtopics <on or off> (default is on if the topic has a wildcard, else off)\n");
printf(" --keepalive <seconds> (default is 10 seconds)\n");
printf(" --keepalive <seconds> (default is %d seconds)\n", opts.keepalive);
exit(-1);
}
......@@ -92,24 +110,6 @@ void cfinish(int sig)
toStop = 1;
}
struct opts_struct
{
char* clientid;
int nodelimiter;
char* delimiter;
int qos;
char* username;
char* password;
char* host;
char* port;
int showtopics;
int keepalive;
} opts =
{
"stdout-subscriber", 0, "\n", 2, NULL, NULL, "localhost", "1883", 0, 10
};
void getopts(int argc, char** argv);
int main(int argc, char** argv)
......
......@@ -92,11 +92,11 @@ void usage()
{
printf("MQTT stdout subscriber\n");
printf("Usage: stdoutsub topicname <options>, where options are:\n");
printf(" --host <hostname> (default is localhost)\n");
printf(" --port <port> (default is 1883)\n");
printf(" --qos <qos> (default is 2)\n");
printf(" --host <hostname> (default is %s)\n", opts.host);
printf(" --port <port> (default is %s)\n", opts.port);
printf(" --qos <qos> (default is %d)\n", opts.qos);
printf(" --delimiter <delim> (default is no delimiter)\n");
printf(" --clientid <clientid> (default is stdout-subscriber-async)\n");
printf(" --clientid <clientid> (default is %s)\n", opts.clientid);
printf(" --username none\n");
printf(" --password none\n");
printf(" --showtopics <on or off> (default is on if the topic has a wildcard, else off)\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment