bringing SDL 1.2.14 from vendor into the main branch
[AROS-Contrib.git] / regina / interp.c
blobd3c5b693ec8468b6b2c3ec53bfa5777464012a18
1 #ifndef lint
2 static char *RCSid = "$Id$";
3 #endif
5 /*
6 * The Regina Rexx Interpreter
7 * Copyright (C) 1992-1994 Anders Christensen <anders@pvv.unit.no>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the Free
21 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "rexx.h"
25 #include <stdio.h>
26 #include <ctype.h>
28 static void set_line_nos( treenode *ptr, int lineno, int charno )
30 int i=0 ;
32 if (!ptr)
33 return ;
35 if (ptr->lineno >= 0)
37 ptr->lineno = lineno ;
38 ptr->charnr = charno ;
41 for (i=0; i<sizeof(ptr->p)/sizeof(ptr->p[0]); i++)
42 if (ptr->p[i])
43 set_line_nos( ptr->p[i], lineno, charno ) ;
45 if (ptr->next)
46 set_line_nos( ptr->next, lineno, charno ) ;
49 /* Will do the "INTERPRET" work on a given streng. This function returns
50 * either NULL on error or the result string of the interpretation.
51 * The streng will be deleted.
53 streng *dointerpret( tsd_t *TSD, streng *string )
55 treenode *newtree ;
56 nodeptr savecurrentnode ;
57 streng *ptr;
58 internal_parser_type parsing;
60 fetch_string( TSD, string, &parsing );
62 if (parsing.result != 0)
64 Free_stringTSD(string) ;
65 exiterror( ERR_YACC_SYNTAX, 1, parsing.tline ) ;
66 return NULL ;
69 newtree = parsing.root ;
70 parsing.kill = string ;
71 if (TSD->currentnode)
72 set_line_nos( newtree, TSD->currentnode->lineno, TSD->currentnode->charnr ) ;
74 treadit( newtree ) ;
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;
83 if (newtree)
84 DestroyInternalParsingTree( TSD, &parsing ) ;
86 return ptr ;