| 1 |
/* |
| 2 |
* The Regina Rexx Interpreter |
| 3 |
* Copyright (C) 1992-1994 Anders Christensen <[email protected]> |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Library General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Library General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU Library General Public |
| 16 |
* License along with this library; if not, write to the Free |
| 17 |
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include "rexx.h" |
| 21 |
#include <stdio.h> |
| 22 |
|
| 23 |
static void set_line_nos( treenode *ptr, int lineno, int charno ) |
| 24 |
{ |
| 25 |
unsigned i=0 ; |
| 26 |
|
| 27 |
if (!ptr) |
| 28 |
return ; |
| 29 |
|
| 30 |
if (ptr->lineno >= 0) |
| 31 |
{ |
| 32 |
ptr->lineno = lineno ; |
| 33 |
ptr->charnr = charno ; |
| 34 |
} |
| 35 |
|
| 36 |
for (i=0; i<sizeof(ptr->p)/sizeof(ptr->p[0]); i++) |
| 37 |
if (ptr->p[i]) |
| 38 |
set_line_nos( ptr->p[i], lineno, charno ) ; |
| 39 |
|
| 40 |
if (ptr->next) |
| 41 |
set_line_nos( ptr->next, lineno, charno ) ; |
| 42 |
} |
| 43 |
|
| 44 |
/* Will do the "INTERPRET" work on a given streng. This function returns |
| 45 |
* either NULL on error or the result string of the interpretation. |
| 46 |
* The streng will be deleted. |
| 47 |
*/ |
| 48 |
streng *dointerpret( tsd_t *TSD, streng *string ) |
| 49 |
{ |
| 50 |
treenode *newtree ; |
| 51 |
nodeptr savecurrentnode ; |
| 52 |
streng *ptr; |
| 53 |
internal_parser_type parsing; |
| 54 |
int errpos=0; |
| 55 |
|
| 56 |
fetch_string( TSD, string, &parsing ); |
| 57 |
|
| 58 |
if (parsing.result != 0) |
| 59 |
{ |
| 60 |
Free_stringTSD(string) ; |
| 61 |
/* |
| 62 |
* get position from parent script if available and add it. |
| 63 |
* fixes bug 658542. |
| 64 |
*/ |
| 65 |
if ( TSD->currentnode ) |
| 66 |
{ |
| 67 |
errpos = TSD->currentnode->lineno; |
| 68 |
errpos = ( errpos > 0 ) ? errpos - 1 : 0 ; |
| 69 |
} |
| 70 |
exiterror( ERR_YACC_SYNTAX, 1, parsing.tline + errpos ) ; |
| 71 |
return NULL ; |
| 72 |
} |
| 73 |
|
| 74 |
newtree = parsing.root ; |
| 75 |
parsing.kill = string ; |
| 76 |
if (TSD->currentnode) |
| 77 |
set_line_nos( newtree, TSD->currentnode->lineno, TSD->currentnode->charnr ) ; |
| 78 |
|
| 79 |
/* Save and restore currentnode around interpret. It is set within |
| 80 |
* interpret and may result to illegal memory accesses in case of |
| 81 |
* errors if it is not restored, FGC |
| 82 |
*/ |
| 83 |
savecurrentnode = TSD->currentnode; |
| 84 |
ptr = interpret( TSD, newtree ) ; |
| 85 |
TSD->currentnode = savecurrentnode; |
| 86 |
#if 0 |
| 87 |
/* |
| 88 |
* FIXME: Always clean up the structure. newtree may be NULL in case |
| 89 |
* of an empty command where we still have to remove the |
| 90 |
* single empty line. I can't remember why we should destroy |
| 91 |
* it just in that case we have a newtree. What is a typical |
| 92 |
* other reason of not having newtree? |
| 93 |
* In either case, delete this comment and the "#if 0"-block |
| 94 |
* one year after now. Florian, 04.03.2004 |
| 95 |
*/ |
| 96 |
if (newtree) |
| 97 |
#endif |
| 98 |
DestroyInternalParsingTree( TSD, &parsing ) ; |
| 99 |
|
| 100 |
return ptr ; |
| 101 |
} |