]> git.kaiwu.me - njs.git/commitdiff
Improved help desrcription of njs shell.
authorDmitry Volyntsev <xeioex@nginx.com>
Fri, 20 Jul 2018 17:11:02 +0000 (20:11 +0300)
committerDmitry Volyntsev <xeioex@nginx.com>
Fri, 20 Jul 2018 17:11:02 +0000 (20:11 +0300)
njs/njs_core.h
njs/njs_shell.c
nxt/auto/os
nxt/nxt_unix.h [new file with mode: 0644]

index 11c9cc9d33bbc3637dc933da0842d107edec8dd1..ea6d37262de82d1ec241eeb83990df7d4fcef17a 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <nxt_auto_config.h>
 
+#include <nxt_unix.h>
 #include <nxt_types.h>
 #include <nxt_clang.h>
 #include <nxt_alignment.h>
index ffcd8a2563d0d487ad35cd7c459652a58e977aaf..8053ac21c22a4ec2765e8e9871cd337b32bb3145 100644 (file)
@@ -150,6 +150,14 @@ njs_get_options(njs_opts_t *opts, int argc, char** argv)
     char     *p;
     nxt_int_t  i, ret;
 
+    static const char  help[] =
+        "Interactive njs shell.\n"
+        "\n"
+        "Options:\n"
+        "  -v              print njs version and exit.\n"
+        "  -d              print disassembled code.\n"
+        "  <filename> | -  run code from a file or stdin.\n";
+
     ret = NXT_DONE;
 
     for (i = 1; i < argc; i++) {
@@ -165,24 +173,24 @@ njs_get_options(njs_opts_t *opts, int argc, char** argv)
         p++;
 
         switch (*p) {
+        case '?':
+        case 'h':
+            (void) write(STDIN_FILENO, help, nxt_length(help));
+            return ret;
+
         case 'd':
             opts->disassemble = 1;
             break;
 
+        case 'v':
         case 'V':
             opts->version = 1;
             break;
 
         default:
-            fprintf(stderr, "Unknown argument: \"%s\"\n", argv[i]);
-            ret = NXT_ERROR;
-
-            /* Fall through. */
-
-        case 'h':
-        case '?':
-            printf("Usage: %s [<file>|-] [-dV]\n", argv[0]);
-            return ret;
+            fprintf(stderr, "Unknown argument: \"%s\" "
+                    "try \"%s -h\" for available options\n", argv[i], argv[0]);
+            return NXT_ERROR;
         }
     }
 
index 6726f0db9d417c8de88ec28477bb5124a64f6ba9..e4f6d26aa813c319d711cf8a5ab46754db8549ea 100644 (file)
@@ -9,6 +9,7 @@ NXT_SYSTEM=`uname -s 2>/dev/null`
 case "$NXT_SYSTEM" in
 
     Linux)
+        nxt_define=NXT_LINUX . ${NXT_AUTO}define
         NXT_SYSTEM_VERSION=`uname -r 2>/dev/null`
         # Linux uname -p can return "unknown".
         NXT_SYSTEM_PLATFORM=`uname -m 2>/dev/null`
diff --git a/nxt/nxt_unix.h b/nxt/nxt_unix.h
new file mode 100644 (file)
index 0000000..bf45fd1
--- /dev/null
@@ -0,0 +1,23 @@
+
+/*
+ * Copyright (C) Dmitry Volyntsev
+ * Copyright (C) NGINX, Inc.
+ */
+
+
+#ifndef _NXT_UNIX_H_INCLUDED_
+#define _NXT_UNIX_H_INCLUDED_
+
+#if (NXT_LINUX)
+
+#ifdef _FORTIFY_SOURCE
+/*
+ * _FORTIFY_SOURCE
+ *     does not allow to use "(void) write()";
+ */
+#undef _FORTIFY_SOURCE
+#endif
+
+#endif /* NXT_LINUX */
+
+#endif /* _NXT_UNIX_H_INCLUDED_ */