summaryrefslogtreecommitdiff
path: root/couchjs
diff options
context:
space:
mode:
authorRobert Newson <robert.newson@cloudant.com>2011-10-10 17:55:50 +0100
committerRobert Newson <robert.newson@cloudant.com>2011-10-10 19:04:54 +0100
commitcf630a2e87ac1b6eace26601dc5b7ffdb39273b2 (patch)
treefe5080dedf417b20112ed372d737eb8c3ca309ff /couchjs
parent6e6523d62beff627c444aec3d658ef1a5d534ff1 (diff)
parentda22c19f7a7fdfae015dfb0db93b5bd9453eae6c (diff)
Merge remote-tracking branch 'apache/1.1.x'
Diffstat (limited to 'couchjs')
-rw-r--r--couchjs/c_src/SConscript8
-rw-r--r--couchjs/c_src/help.h82
-rw-r--r--couchjs/c_src/util.c25
-rw-r--r--couchjs/c_src/util.h1
-rw-r--r--couchjs/js/util.js5
5 files changed, 110 insertions, 11 deletions
diff --git a/couchjs/c_src/SConscript b/couchjs/c_src/SConscript
index b014e2ec..a3e0cc07 100644
--- a/couchjs/c_src/SConscript
+++ b/couchjs/c_src/SConscript
@@ -13,6 +13,7 @@
# the License.
import os
import commands
+import subprocess
def require_lib(name):
if not conf.CheckLib(name):
@@ -86,6 +87,13 @@ if not env.GetOption('clean'):
conf.Define(vsn)
break
+ ## Define properties for -h / -V
+
+ vsn = subprocess.check_output(["git","describe","--match","1.*"])
+ conf.Define("PACKAGE_STRING", '"%s"' % vsn.rstrip())
+ conf.Define("PACKAGE_NAME", '"Cloudant BigCouch"')
+ conf.Define("PACKAGE_BUGREPORT", '"https://github.com/cloudant/bigcouch/issues"')
+
env = conf.Finish()
env.Program('couchjs', ['main.c', 'http.c', 'utf8.c', 'util.c'])
diff --git a/couchjs/c_src/help.h b/couchjs/c_src/help.h
new file mode 100644
index 00000000..84c83c06
--- /dev/null
+++ b/couchjs/c_src/help.h
@@ -0,0 +1,82 @@
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+#ifndef COUCHJS_HELP_H
+#define COUCHJS_HELP_H
+
+#include <libgen.h>
+
+#include "config.h"
+
+static const char VERSION_TEMPLATE[] =
+ "%s - %s\n"
+ "\n"
+ "Licensed under the Apache License, Version 2.0 (the \"License\"); you may "
+ "not use\n"
+ "this file except in compliance with the License. You may obtain a copy of"
+ "the\n"
+ "License at\n"
+ "\n"
+ " http://www.apache.org/licenses/LICENSE-2.0\n"
+ "\n"
+ "Unless required by applicable law or agreed to in writing, software "
+ "distributed\n"
+ "under the License is distributed on an \"AS IS\" BASIS, WITHOUT "
+ "WARRANTIES OR\n"
+ "CONDITIONS OF ANY KIND, either express or implied. See the License "
+ "for the\n"
+ "specific language governing permissions and limitations under the "
+ "License.\n";
+
+static const char USAGE_TEMPLATE[] =
+ "Usage: %s [FILE]\n"
+ "\n"
+ "The %s command runs the %s JavaScript interpreter.\n"
+ "\n"
+ "The exit status is 0 for success or 1 for failure.\n"
+ "\n"
+ "Options:\n"
+ "\n"
+ " -h display a short help message and exit\n"
+ " -V display version information and exit\n"
+ " -H enable %s cURL bindings (only avaiable\n"
+ " if package was built with cURL available)\n"
+ " -S SIZE specify that the interpreter should set the\n"
+ " the stack quota for JS contexts to SIZE bytes\n"
+ "\n"
+ "Report bugs at <%s>.\n";
+
+#define BASENAME basename((char*)argv[0])
+
+#define couch_version(basename) \
+ fprintf( \
+ stdout, \
+ VERSION_TEMPLATE, \
+ basename, \
+ PACKAGE_STRING)
+
+#define DISPLAY_VERSION couch_version(BASENAME)
+
+
+#define couch_usage(basename) \
+ fprintf( \
+ stdout, \
+ USAGE_TEMPLATE, \
+ basename, \
+ basename, \
+ PACKAGE_NAME, \
+ basename, \
+ PACKAGE_BUGREPORT)
+
+#define DISPLAY_USAGE couch_usage(BASENAME)
+
+#endif // Included help.h
diff --git a/couchjs/c_src/util.c b/couchjs/c_src/util.c
index f5ef3e82..bd7be4c9 100644
--- a/couchjs/c_src/util.c
+++ b/couchjs/c_src/util.c
@@ -13,6 +13,7 @@
#include <stdlib.h>
#include <string.h>
+#include "help.h"
#include "util.h"
#include "utf8.h"
@@ -77,15 +78,30 @@ couch_parse_args(int argc, const char* argv[])
args->stack_size = 8L * 1024L;
while(i < argc) {
- if(strcmp("--http", argv[i]) == 0) {
+ if(strcmp("-h", argv[i]) == 0) {
+ DISPLAY_USAGE;
+ exit(0);
+ } else if(strcmp("-V", argv[i]) == 0) {
+ DISPLAY_VERSION;
+ exit(0);
+ } else if(strcmp("-H", argv[i]) == 0) {
args->use_http = 1;
- } else if(strcmp("--stack-size", argv[i]) == 0) {
- args->stack_size = atoi(argv[i+1]);
+ } else if(strcmp("-S", argv[i]) == 0) {
+ args->stack_size = atoi(argv[++i]);
if(args->stack_size <= 0) {
fprintf(stderr, "Invalid stack size.\n");
exit(2);
}
+ } else if(strcmp("--", argv[i]) == 0) {
+ i++;
+ break;
} else {
+ break;
+ }
+ i++;
+ }
+
+ while(i < argc) {
args->script = slurp_file(args->script, argv[i]);
if(args->script_name == NULL) {
if(strcmp(argv[i], "-") == 0) {
@@ -96,12 +112,11 @@ couch_parse_args(int argc, const char* argv[])
} else {
args->script_name = "<multiple_files>";
}
- }
i++;
}
if(args->script_name == NULL || args->script == NULL) {
- fprintf(stderr, "No script provided.\n");
+ DISPLAY_USAGE;
exit(3);
}
diff --git a/couchjs/c_src/util.h b/couchjs/c_src/util.h
index 54ccdaa5..b082aa60 100644
--- a/couchjs/c_src/util.h
+++ b/couchjs/c_src/util.h
@@ -22,7 +22,6 @@ typedef struct {
char* script;
} couch_args;
-void couch_usage();
couch_args* couch_parse_args(int argc, const char* argv[]);
int couch_fgets(char* buf, int size, FILE* fp);
JSString* couch_readline(JSContext* cx, FILE* fp);
diff --git a/couchjs/js/util.js b/couchjs/js/util.js
index d498ee64..a7449315 100644
--- a/couchjs/js/util.js
+++ b/couchjs/js/util.js
@@ -63,11 +63,6 @@ var Couch = {
},
compileFunction : function(source, ddoc) {
if (!source) throw(["error","not_found","missing function"]);
- // Some newer SpiderMonkey's appear to not like evaluating
- // an anonymous function at global scope. Simple fix just
- // wraps the source with parens so the function object is
- // returned correctly.
- source = "(" + source + ")";
try {
if (sandbox) {
if (ddoc) {