From 0253adcab3157ec73cc96ad74b19faa2c87e067a Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 3 Jun 2005 07:47:06 +0000 Subject: r7213: 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. (This used to be commit 875c8164096e7334de25cc57ac4b8bdc39b9c46b) --- source4/lib/ejs/ejsParser.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'source4/lib/ejs/ejsParser.c') diff --git a/source4/lib/ejs/ejsParser.c b/source4/lib/ejs/ejsParser.c index 17fe0ce98a..942b08272e 100644 --- a/source4/lib/ejs/ejsParser.c +++ b/source4/lib/ejs/ejsParser.c @@ -67,6 +67,7 @@ static int parseId(Ejs *ep, int state, int flags, char **id, 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); @@ -80,6 +81,12 @@ int ejsParse(Ejs *ep, int state, int flags) mprAssert(ep); 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 */ @@ -140,6 +147,26 @@ int ejsParse(Ejs *ep, int state, int flags) return state; } +/******************************************************************************/ +/* + * 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 -- cgit