api-example.c: add a -o option for output pure message
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
diff --git a/api-example.c b/api-example.c
index 13b8f2d..9bd4479 100644
--- a/api-example.c
+++ b/api-example.c
@@ -145,6 +145,7 @@
static const char SEPARATOR = '|';
static const char COMMA = ',';
static const char EQ = '=';
+static int ONLY = 0;
void display(char *buf)
{
@@ -242,9 +243,12 @@ int callapi(char *command, char *host, short int port)
buf[p] = '\0';
}
- printf("Reply was '%s'\n", buf);
-
- display(buf);
+ if (ONLY)
+ printf("%s\n", buf);
+ else {
+ printf("Reply was '%s'\n", buf);
+ display(buf);
+ }
}
CLOSESOCKET(sock);
@@ -274,6 +278,7 @@ int main(int argc, char *argv[])
char *host = "127.0.0.1";
short int port = 4028;
char *ptr;
+ int i = 1;
if (argc > 1)
if (strcmp(argv[1], "-?") == 0
@@ -283,20 +288,26 @@ int main(int argc, char *argv[])
return 1;
}
- if (argc > 1) {
- ptr = trim(argv[1]);
+ if (argc > 1)
+ if (strcmp(argv[1], "-o") == 0) {
+ ONLY = 1;
+ i = 2;
+ }
+
+ if (argc > i) {
+ ptr = trim(argv[i++]);
if (strlen(ptr) > 0)
command = ptr;
}
- if (argc > 2) {
- ptr = trim(argv[2]);
+ if (argc > i) {
+ ptr = trim(argv[i++]);
if (strlen(ptr) > 0)
host = ptr;
}
- if (argc > 3) {
- ptr = trim(argv[3]);
+ if (argc > i) {
+ ptr = trim(argv[i]);
if (strlen(ptr) > 0)
port = atoi(ptr);
}