a5b9e75
From 472396d694ae1d8b77f8b349ab13e387b9eae629 Mon Sep 17 00:00:00 2001
a5b9e75
From: "FeRD (Frank Dana)" <ferdnyc@gmail.com>
a5b9e75
Date: Thu, 11 Jul 2019 21:16:43 -0400
a5b9e75
Subject: [PATCH] Print URL for server, quiet option suppresses
a5b9e75
a5b9e75
This will display a line of text on stdout immediately after
a5b9e75
binding to the configured address and port:
a5b9e75
`Server running at http://<address>:<port>/`
a5b9e75
An option `-q` / `--quiet` is added, to suppress the output.
a5b9e75
---
a5b9e75
 src/chm_http.c | 18 +++++++++++++++---
a5b9e75
 1 file changed, 15 insertions(+), 3 deletions(-)
a5b9e75
a5b9e75
diff --git a/src/chm_http.c b/src/chm_http.c
a5b9e75
index 237e85a..84304f9 100644
a5b9e75
--- a/src/chm_http.c
a5b9e75
+++ b/src/chm_http.c
a5b9e75
@@ -51,13 +51,14 @@
a5b9e75
 
a5b9e75
 int config_port = 8080;
a5b9e75
 char config_bind[65536] = "127.0.0.1";
a5b9e75
+char config_quiet = 0;
a5b9e75
 
a5b9e75
 static void usage(const char *argv0)
a5b9e75
 {
a5b9e75
 #ifdef CHM_HTTP_SIMPLE
a5b9e75
-    fprintf(stderr, "usage: %s <filename>\n", argv0);
a5b9e75
+    fprintf(stderr, "usage: %s [--quiet] <filename>\n", argv0);
a5b9e75
 #else
a5b9e75
-    fprintf(stderr, "usage: %s [--port=PORT] [--bind=IP] <filename>\n", argv0);
a5b9e75
+    fprintf(stderr, "usage: %s [--quiet] [--port=PORT] [--bind=IP] <filename>\n", argv0);
a5b9e75
 #endif
a5b9e75
     exit(1);
a5b9e75
 }
a5b9e75
@@ -80,6 +81,7 @@ int main(int c, char **v)
a5b9e75
     {
a5b9e75
         { "port", required_argument, 0, 'p' },
a5b9e75
         { "bind", required_argument, 0, 'b' },
a5b9e75
+        { "quiet", no_argument, 0, 'q' },
a5b9e75
         { "help", no_argument, 0, 'h' },
a5b9e75
         { 0, 0, 0, 0 }
a5b9e75
     };
a5b9e75
@@ -87,7 +89,7 @@ int main(int c, char **v)
a5b9e75
     while (1) 
a5b9e75
     {
a5b9e75
         int o;
a5b9e75
-        o = getopt_long (c, v, "p:b:h", longopts, &optindex);
a5b9e75
+        o = getopt_long (c, v, "p:b:qh", longopts, &optindex);
a5b9e75
         if (o < 0) 
a5b9e75
         {
a5b9e75
             break;
a5b9e75
@@ -109,6 +111,10 @@ int main(int c, char **v)
a5b9e75
                 config_bind[65535] = '\0';
a5b9e75
                 break;
a5b9e75
 
a5b9e75
+            case 'q':
a5b9e75
+                config_quiet = 1;
a5b9e75
+                break;
a5b9e75
+
a5b9e75
             case 'h':
a5b9e75
                 usage (v[0]);
a5b9e75
                 break;
a5b9e75
@@ -182,6 +188,12 @@ static void chmhttp_server(const char *filename)
a5b9e75
         exit(3);
a5b9e75
     }
a5b9e75
 
a5b9e75
+    /* Display URL for server */
a5b9e75
+    if (!config_quiet)
a5b9e75
+    {
a5b9e75
+        printf("Server running at http://%s:%d/\n", config_bind, config_port);
a5b9e75
+    }
a5b9e75
+
a5b9e75
     /* listen for connections */
a5b9e75
     listen(server.socket, 75);
a5b9e75
     addrLen = sizeof(struct sockaddr);
a5b9e75
-- 
a5b9e75
2.21.0
a5b9e75