svn commit: samba r7213 - in branches/SAMBA_4_0/source/lib/ejs: .
tpot at samba.org
tpot at samba.org
Fri Jun 3 07:47:07 GMT 2005
Author: tpot
Date: 2005-06-03 07:47:06 +0000 (Fri, 03 Jun 2005)
New Revision: 7213
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=7213
Log:
Add a small bit to the ejs parser to ignore a #!/path/to/interpreter
as the first line of the script. This allows smbscript to be used as an
interpreter.
Modified:
branches/SAMBA_4_0/source/lib/ejs/ejs.c
branches/SAMBA_4_0/source/lib/ejs/ejsInternal.h
branches/SAMBA_4_0/source/lib/ejs/ejsLex.c
branches/SAMBA_4_0/source/lib/ejs/ejsParser.c
Changeset:
Modified: branches/SAMBA_4_0/source/lib/ejs/ejs.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ejs/ejs.c 2005-06-03 07:03:26 UTC (rev 7212)
+++ branches/SAMBA_4_0/source/lib/ejs/ejs.c 2005-06-03 07:47:06 UTC (rev 7213)
@@ -418,8 +418,10 @@
endlessLoopTest = NULL;
ep->exitStatus = 0;
+ ejsParse(ep, EJS_STATE_BEGIN, EJS_FLAGS_EXE); /* Skip over #! */
+
do {
- state = ejsParse(ep, EJS_STATE_BEGIN, EJS_FLAGS_EXE);
+ state = ejsParse(ep, EJS_STATE_STMT, EJS_FLAGS_EXE);
if (state == EJS_STATE_RET) {
state = EJS_STATE_EOF;
Modified: branches/SAMBA_4_0/source/lib/ejs/ejsInternal.h
===================================================================
--- branches/SAMBA_4_0/source/lib/ejs/ejsInternal.h 2005-06-03 07:03:26 UTC (rev 7212)
+++ branches/SAMBA_4_0/source/lib/ejs/ejsInternal.h 2005-06-03 07:47:06 UTC (rev 7213)
@@ -100,7 +100,7 @@
#define EJS_TOK_IN 26 /* in */
#define EJS_TOK_FUNCTION 27 /* function */
#define EJS_TOK_NUMBER 28 /* Number */
-
+#define EJS_TOK_HASHBANG 29 /* #!/path/to/interpreter */
/*
* Expression operators
*/
@@ -150,9 +150,8 @@
#define EJS_STATE_DEC 18 /* Declaration statement */
#define EJS_STATE_DEC_DONE 19
#define EJS_STATE_RET 20 /* Return statement */
+#define EJS_STATE_BEGIN 21 /* Start of script */
-#define EJS_STATE_BEGIN EJS_STATE_STMT
-
/*
* General parsing flags.
*/
Modified: branches/SAMBA_4_0/source/lib/ejs/ejsLex.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ejs/ejsLex.c 2005-06-03 07:03:26 UTC (rev 7212)
+++ branches/SAMBA_4_0/source/lib/ejs/ejsLex.c 2005-06-03 07:47:06 UTC (rev 7213)
@@ -674,6 +674,26 @@
inputPutback(ep, c);
return EJS_TOK_NUMBER;
+ case '#':
+ if (ip->lineNumber == 1) {
+ if ((c = inputGetc(ep)) < 0) {
+ ejsError(ep, "Syntax Error");
+ return EJS_TOK_ERR;
+ }
+ if (c != '!') {
+ ejsError(ep, "Syntax Error");
+ return EJS_TOK_ERR;
+ }
+ while ((c = inputGetc(ep)) != -1) {
+ if (c == '\r' || c == '\n')
+ break;
+ tokenAddChar(ep, c);
+ }
+ return EJS_TOK_HASHBANG;
+ }
+
+ /* Fall through to default handling */
+
default:
/*
* Identifiers or a function names
Modified: branches/SAMBA_4_0/source/lib/ejs/ejsParser.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ejs/ejsParser.c 2005-06-03 07:03:26 UTC (rev 7212)
+++ branches/SAMBA_4_0/source/lib/ejs/ejsParser.c 2005-06-03 07:47:06 UTC (rev 7213)
@@ -67,6 +67,7 @@
static int parseInc(Ejs *ep, int state, int flags);
static int parseIf(Ejs *ep, int state, int flags, int *done);
static int parseStmt(Ejs *ep, int state, int flags);
+static int parseHashBang(Ejs *ep, int state, int flags);
static void removeNewlines(Ejs *ep, int state);
static void updateResult(Ejs *ep, int state, int flags, MprVar *vp);
@@ -81,6 +82,12 @@
switch (state) {
/*
+ * The very start of a script.
+ */
+ case EJS_STATE_BEGIN:
+ state = parseHashBang(ep, state, flags);
+ break;
+ /*
* Any statement, function arguments or conditional expressions
*/
case EJS_STATE_STMT:
@@ -142,6 +149,26 @@
/******************************************************************************/
/*
+ * Parse a #!/path/to/interpreter line which we just throw away.
+ */
+
+static int parseHashBang(Ejs *ep, int state, int flags)
+{
+ int tid;
+
+ /* Look for #! */
+
+ tid = ejsLexGetToken(ep, state);
+
+ if (tid != EJS_TOK_HASHBANG) {
+ ejsLexPutbackToken(ep, tid, ep->token);
+ }
+
+ return EJS_STATE_STMT;
+}
+
+/******************************************************************************/
+/*
* Parse any statement including functions and simple relational operations
*/
More information about the samba-cvs
mailing list