1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
/* Line source definitions
*
* A line source is a mechanism for reading source text. The tokenizer
* reads its input from a line source. This is the basic class
* definition; individual line sources will define the functions and
* class data needed.
*/
#ifndef GLK_TADS_TADS2_LINE_SOURCE
#define GLK_TADS_TADS2_LINE_SOURCE
#include "glk/tads/tads2/lib.h"
#include "glk/tads/tads2/object.h"
namespace Glk {
namespace TADS {
namespace TADS2 {
/**
* Line source superclass structure
*/
struct lindef {
int (*lingetp)(lindef *lin); /* get next line */
void (*linclsp)(lindef *lin); /* close line source */
void (*linppos)(lindef *lin, char *buf, uint buflen);
/* write printable rep of position to buf (for error reporting) */
void (*linglop)(lindef *lin, uchar *buf);
/* generate a line record for an OPCLINE instruction */
int (*linwrtp)(lindef *lin, osfildef *fp);
/* write line source information to binary file; TRUE ==> error */
void (*lincmpp)(lindef *lin, uchar *buf);
/* give location of compiled code for current line to line source */
void (*linactp)(lindef *lin); /* activate for dbg */
void (*lindisp)(lindef *lin); /* disactivate */
void (*lintellp)(lindef *lin, uchar *pos); /* get position */
void (*linseekp)(lindef *lin, uchar *pos); /* seek */
int (*linreadp)(lindef *lin, uchar *buf, uint siz); /* fread */
void (*linpaddp)(lindef *lin, uchar *pos, long delta);
/* add an offset to a position value */
int (*linqtopp)(lindef *lin, uchar *pos); /* at top? */
int (*lingetsp)(lindef *lin, uchar *buf, uint siz); /* get line */
void (*linnamp)(lindef *lin, char *buf); /* get source name */
void (*linfindp)(lindef *lin, char *buf, objnum *objp,
uint *ofsp); /* find nearest line record */
void (*lingotop)(lindef *lin, int where); /* seek global */
long (*linofsp)(lindef *lin); /* byte offset in line source */
void (*linrenp)(lindef *lin, objnum oldnum, objnum newnum);
/* renumber an object (for "modify") */
void (*lindelp)(lindef *lin, objnum objn);
/* delete an object (for "replace") */
ulong (*linlnump)(lindef *lin); /* get the current line number */
#define LINGOTOP OSFSK_SET /* go to top of line source */
#define LINGOEND OSFSK_END /* go to end of line source */
lindef *linpar; /* parent of current line source */
lindef *linnxt; /* next line in line source chain */
int linid; /* serial number of line source (for debugger) */
char *linbuf; /* pointer to current line */
ushort linflg; /* flags */
#define LINFEOF 0x01 /* line source is at end of file */
#define LINFMORE 0x02 /* there's more to the line than linlen */
#define LINFDBG 0x04 /* debug record already generated for line */
#define LINFNOINC 0x08 /* ignore # directives from this line source */
#define LINFCMODE 0x10 /* line source is parsed in C-mode */
ushort linlen; /* length of the line */
ushort linlln; /* length of line record generated by lingloc */
};
/**
* Maximum allowed value for linlln, in bytes. This allows subsystems
* that need to maintain local copies of seek locations to know how big
* an area to allocate for them.
*/
#define LINLLNMAX 20
/* macros to cover calls to functions */
#define linget(lin) ((*((lindef *)(lin))->lingetp)((lindef *)(lin)))
#define lincls(lin) ((*((lindef *)(lin))->linclsp)((lindef *)(lin)))
#define linppos(lin, buf, buflen) \
((*((lindef *)(lin))->linppos)((lindef *)(lin), buf, buflen))
#define linglop(lin, buf) ((*((lindef *)(lin))->linglop)(lin, buf))
#define linwrt(lin, fp) ((*((lindef *)(lin))->linwrtp)(lin, fp))
#define lincmpinf(lin, buf) ((*((lindef *)(lin))->lincmpp)(lin, buf))
#define linactiv(lin) ((*((lindef *)(lin))->linactp)(lin))
#define lindisact(lin) ((*((lindef *)(lin))->lindisp)(lin))
#define lintell(lin, pos) ((*((lindef *)(lin))->lintellp)(lin, pos))
#define linseek(lin, pos) ((*((lindef *)(lin))->linseekp)(lin, pos))
#define linread(lin, buf, siz) ((*((lindef *)(lin))->linreadp)(lin, buf, siz))
#define linpadd(lin, pos, delta) \
((*((lindef *)(lin))->linpaddp)(lin, pos, delta))
#define linqtop(lin, pos) ((*((lindef *)(lin))->linqtopp)(lin, pos))
#define lingets(lin, buf, siz) ((*((lindef *)(lin))->lingetsp)(lin, buf, siz))
#define linnam(lin, buf) ((*((lindef *)(lin))->linnamp)(lin, buf))
#define linlnum(lin) ((*((lindef *)(lin))->linlnump)(lin))
#define linfind(lin, buf, objp, ofsp) \
((*((lindef *)(lin))->linfindp)(lin, buf, objp, ofsp))
#define lingoto(lin, where) ((*((lindef *)(lin))->lingotop)(lin, where))
#define linofs(lin) ((*((lindef *)(lin))->linofsp)(lin))
#define linrenum(lin, oldnum, newnum) \
((*((lindef *)(lin))->linrenp)(lin, oldnum, newnum))
#define lindelnum(lin, objn) ((*((lindef *)(lin))->lindelp)(lin, objn))
} // End of namespace TADS2
} // End of namespace TADS
} // End of namespace Glk
#endif
|