r7075: added support for ARGV[] in ejs scripts
authorAndrew Tridgell <tridge@samba.org>
Sun, 29 May 2005 11:58:14 +0000 (11:58 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:17:12 +0000 (13:17 -0500)
(This used to be commit 3db568eb6bb383c4c1e1fd0c7f043a9914dcc3cc)

source4/scripting/ejs/smbscript.c

index c6b1b7a1927d221d851366a3a7dd4ce1f0a12571..33788851475c755806b7195183bc03993ca9b02f 100644 (file)
@@ -37,8 +37,11 @@ void ejs_exception(const char *reason)
        MprVar result;
        char *emsg;
        TALLOC_CTX *mem_ctx = talloc_new(NULL);
+       const char **argv_list = NULL;
+       struct MprVar v;
+       int i;
 
-       if (argc != 2) {
+       if (argc < 2) {
                fprintf(stderr, "Usage: %s <scriptfile>\n", argv[0]);
                exit(1);
        }
@@ -67,6 +70,14 @@ void ejs_exception(const char *reason)
                exit(1);
        }
 
+       /* setup ARGV[] in the ejs environment */
+       for (i=2;i<argc;i++) {
+               argv_list = str_list_add(argv_list, argv[i]);
+       }
+       v = mprList("ARGV", argv_list);
+       mprCreateProperty(ejsGetGlobalObject(eid), "ARGV", &v);
+
+       /* run the script */
        if (ejsEvalFile(eid, discard_const_p(char, argv[1]), &result,
                        &emsg) == -1) {
                fprintf(stderr, "smbscript: ejsEvalScript(): %s\n", emsg);