2 * The Regina Rexx Interpreter
3 * Copyright (C) 1992-1994 Anders Christensen <anders@pvv.unit.no>
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.
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.
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.
23 static void set_line_nos( treenode
*ptr
, int lineno
, int charno
)
32 ptr
->lineno
= lineno
;
33 ptr
->charnr
= charno
;
36 for (i
=0; i
<sizeof(ptr
->p
)/sizeof(ptr
->p
[0]); i
++)
38 set_line_nos( ptr
->p
[i
], lineno
, charno
) ;
41 set_line_nos( ptr
->next
, lineno
, charno
) ;
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.
48 streng
*dointerpret( tsd_t
*TSD
, streng
*string
)
51 nodeptr savecurrentnode
;
53 internal_parser_type parsing
;
56 fetch_string( TSD
, string
, &parsing
);
58 if (parsing
.result
!= 0)
60 Free_stringTSD(string
) ;
62 * get position from parent script if available and add it.
65 errpos
= TSD
->currentnode
->lineno
;
66 errpos
= ( errpos
> 0 ) ? errpos
- 1 : 0 ;
67 exiterror( ERR_YACC_SYNTAX
, 1, parsing
.tline
+ errpos
) ;
71 newtree
= parsing
.root
;
72 parsing
.kill
= string
;
74 set_line_nos( newtree
, TSD
->currentnode
->lineno
, TSD
->currentnode
->charnr
) ;
76 /* Save and restore currentnode around interpret. It is set within
77 * interpret and may result to illegal memory accesses in case of
78 * errors if it is not restored, FGC
80 savecurrentnode
= TSD
->currentnode
;
81 ptr
= interpret( TSD
, newtree
) ;
82 TSD
->currentnode
= savecurrentnode
;
85 * FIXME: Always clean up the structure. newtree may be NULL in case
86 * of an empty command where we still have to remove the
87 * single empty line. I can't remember why we should destroy
88 * it just in that case we have a newtree. What is a typical
89 * other reason of not having newtree?
90 * In either case, delete this comment and the "#if 0"-block
91 * one year after now. Florian, 04.03.2004
95 DestroyInternalParsingTree( TSD
, &parsing
) ;