This repository was archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathexecpt.h
More file actions
565 lines (506 loc) · 13 KB
/
execpt.h
File metadata and controls
565 lines (506 loc) · 13 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
/* Copyright (C) 2003-2015 LiveCode Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode 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 LiveCode. If not see <http://www.gnu.org/licenses/>. */
//
// Script class declarations
//
#ifndef EXECPOINT_H
#define EXECPOINT_H
#ifndef __MC_VARIABLE__
#include "variable.h"
#endif
#define EP_PAD 256
#define EP_MASK 0xFFFFFF00
class MCExecPoint
{
MCObject *curobj;
// MW-2009-01-30: [[ Inherited parentScripts ]]
// We store a reference to the parentScript use which is the current context
// so we can retrieve the correct script locals. If this is NULL, then we
// are not in parentScript context.
MCParentScriptUse *parentscript;
MCHandlerlist *curhlist;
MCHandler *curhandler;
MCVariableValue *array;
char *buffer;
uint4 size;
MCString svalue;
real8 nvalue;
Value_format format;
uint2 nffw;
uint2 nftrailing;
uint2 nfforce;
uint2 cutoff;
uint2 line;
Boolean convertoctals;
Boolean casesensitive;
Boolean wholematches;
Boolean usesystemdate;
Boolean useunicode;
Boolean deletearray;
char itemdel;
char columndel;
char linedel;
char rowdel;
public:
MCExecPoint()
{
memset(this, 0, sizeof(MCExecPoint));
itemdel = ',';
columndel = '\t';
linedel = '\n';
rowdel = '\n';
nffw = 8;
nftrailing = 6;
cutoff = 35;
}
MCExecPoint(const MCExecPoint &ep)
{
*this = ep;
array = NULL;
deletearray = False;
buffer = NULL;
size = 0;
}
MCExecPoint(MCObject *object, MCHandlerlist *hlist, MCHandler *handler)
{
memset(this, 0, sizeof(MCExecPoint));
curobj = object;
curhlist = hlist;
curhandler = handler;
itemdel = ',';
columndel = '\t';
linedel = '\n';
rowdel = '\n';
nffw = 8;
nftrailing = 6;
cutoff = 35;
}
void restore(const MCExecPoint &ep)
{
curobj = ep.curobj;
curhlist = ep.curhlist;
curhandler = ep.curhandler;
}
~MCExecPoint()
{
delete buffer;
if (deletearray)
delete array;
}
void sethlist(MCHandlerlist *hl)
{
curhlist = hl;
}
void sethandler(MCHandler *newhandler)
{
curhandler = newhandler;
}
// Return a pointer to the array value contained in the exec-point
MCVariableValue *getarray(void)
{
// MW-2014-03-12: [[ Bug 11867 ]] If the format is array return the array
// pointer. Otherwise return nil (since array is not necessarily set to
// nil if it changes format).
if (format == VF_ARRAY)
return array;
return nil;
}
Boolean getdeletearray()
{
return deletearray;
}
// Take the current array value of the ExecPoint away from it
void takearray(MCVariableValue*& r_array, Boolean& r_delete)
{
r_array = array;
r_delete = deletearray;
array = NULL;
deletearray = False;
}
// Set the current exec-points value to the given array, if d is
// true, then this will manage the lifetime.
void setarray(MCVariableValue *a, Boolean d);
Boolean isempty(void) const
{
return format == VF_UNDEFINED || format != VF_ARRAY && format != VF_NUMBER && svalue . getlength() == 0;
}
Value_format getformat()
{
return format;
}
void setsvalue(const MCString &s)
{
svalue = s;
format = VF_STRING;
}
void setnvalue(const real8 &n)
{
nvalue = n;
format = VF_NUMBER;
}
void setnvalue(uint4 n)
{
nvalue = (real8)n;
format = VF_NUMBER;
}
void setnvalue(int4 n)
{
nvalue = (real8)n;
format = VF_NUMBER;
}
void setnvalue(uint2 n)
{
nvalue = (real8)n;
format = VF_NUMBER;
}
void setnvalue(int2 n)
{
nvalue = (real8)n;
format = VF_NUMBER;
}
void setboth(const MCString &s, const real8 &n)
{
svalue = s;
nvalue = n;
format = VF_BOTH;
}
void clear();
char *getbuffer(uint4 newsize);
uint4 getbuffersize()
{
return size;
}
void setbuffer(char *s, uint4 l)
{
buffer = s;
size = l;
}
Boolean changed()
{
return svalue.getstring() == buffer;
}
void copysvalue(const char *s, uint4 l);
void copysvalue(const char *s) {copysvalue(s, strlen(s));}
// Ensure that there is a string value available and the exec-point owns it.
void grabsvalue();
// Ensure that the execpoint owns its array (if it has one)
void grabarray();
// Take the memory pointed to by buffer as the value, and set the execpoint to a string
void grabbuffer(char *p_buffer, uint4 p_length);
// Ensure that the execpoint owns its value
void grab(void);
void setint(int4);
void setuint(uint4);
void setint64(int64_t);
void setuint64(uint64_t);
void setr8(real8 n, uint2 fw, uint2 trailing, uint2 force);
Exec_stat getreal8(real8 &, uint2, uint2, Exec_errors);
Exec_stat getuint2(uint2 &, uint2, uint2, Exec_errors);
Exec_stat getint4(int4 &, uint2, uint2, Exec_errors);
Exec_stat getuint4(uint4 &, uint2, uint2, Exec_errors);
Exec_stat getboolean(Boolean &, uint2, uint2, Exec_errors);
Exec_stat ntos();
Exec_stat ston();
void lower();
void upper();
// MW-2007-07-03: [[ Bug 5123 ]] - Strict array checking modification
Exec_stat tos()
{
return format == VF_NUMBER ? ntos() : (format != VF_ARRAY ? ES_NORMAL : ES_ERROR);
}
// MW-2007-07-03: [[ Bug 5123 ]] - Strict array checking modification
Exec_stat ton()
{
return format == VF_STRING ? ston() : (format != VF_ARRAY ? ES_NORMAL : ES_ERROR);
}
// MW-2007-07-03: [[ Bug 5123 ]] - Strict array checking modification
Exec_stat tona(void)
{
return format == VF_STRING ? ston() : ES_NORMAL;
}
// Ensure that the value in the ExecPoint is a NUL-terminated string and return
// a pointer to it.
const char *getcstring(void);
// Ensure that the value in the ExecPoint is NUL-terminated then return it as
// a MCString.
const MCString& getsvalue0(void)
{
getcstring();
return svalue;
}
const MCString &getsvalue()
{
if (format==VF_NUMBER)
tos();
return svalue;
}
real8 getnvalue() const
{
return nvalue;
}
uint4 getuint4() const
{
return (uint4)(nvalue < 0.0 ? 0 : nvalue + 0.5);
}
uint2 getuint2() const
{
return (uint2)(nvalue < 0.0 ? 0 : nvalue + 0.5);
}
int4 getint4() const
{
return (int4)(nvalue < 0.0?nvalue - 0.5:nvalue + 0.5);
}
int64_t getint8() const
{
return (int4)(nvalue < 0.0?nvalue - 0.5:nvalue + 0.5);
}
uint64_t getuint8() const
{
return (uint4)(nvalue < 0.0?nvalue - 0.5:nvalue + 0.5);
}
void setstrlen()
{
svalue.set(buffer, strlen(buffer));
format = VF_STRING;
}
void setlength(uint4 l)
{
svalue.set(buffer, l);
format = VF_STRING;
}
MCObject *getobj() const
{
return curobj;
}
MCHandlerlist *gethlist() const
{
return curhlist;
}
MCHandler *gethandler() const
{
return curhandler;
}
uint2 getnffw() const
{
return nffw;
}
uint2 getnftrailing() const
{
return nftrailing;
}
uint2 getnfforce() const
{
return nfforce;
}
Boolean getcasesensitive() const
{
return casesensitive;
}
uint2 getcutoff() const
{
return cutoff;
}
Boolean getconvertoctals() const
{
return convertoctals;
}
char getitemdel() const
{
return itemdel;
}
char getcolumndel() const
{
return columndel;
}
char getrowdel() const
{
return rowdel;
}
char getlinedel()
{
return linedel;
}
Boolean getwholematches() const
{
return wholematches;
}
Boolean getusesystemdate() const
{
return usesystemdate;
}
Boolean getuseunicode() const
{
return useunicode;
}
Exec_stat setcasesensitive(uint2 line, uint2 pos)
{
return getboolean(casesensitive, line, pos, EE_PROPERTY_NAB);
}
Exec_stat setcutoff(uint2 line, uint2 pos)
{
return getuint2(cutoff, line, pos, EE_PROPERTY_NOTANUM);
}
Exec_stat setconvertoctals(uint2 line, uint2 pos)
{
return getboolean(convertoctals, line, pos, EE_PROPERTY_NAB);
}
Exec_stat setusesystemdate(uint2 line, uint2 pos)
{
return getboolean(usesystemdate, line, pos, EE_PROPERTY_NAB);
}
Exec_stat setuseunicode(uint2 line, uint2 pos)
{
return getboolean(useunicode, line, pos, EE_PROPERTY_NAB);
}
Exec_stat setitemdel(uint2 line, uint2 pos);
Exec_stat setcolumndel(uint2 line, uint2 pos);
Exec_stat setlinedel(uint2 line, uint2 pos);
Exec_stat setrowdel(uint2 line, uint2 pos);
Exec_stat setwholematches(uint2 line, uint2 pos)
{
return getboolean(wholematches, line, pos, EE_PROPERTY_NAB);
}
void setobj(MCObject *p_object)
{
curobj = p_object;
}
void setline(uint2 l)
{
line = l;
}
uint2 getline()
{
return line;
}
MCParentScriptUse *getparentscript(void) const
{
return parentscript;
}
void setparentscript(MCParentScriptUse *obj)
{
parentscript = obj;
}
void setnumberformat();
void insert(const MCString &, uint4 s, uint4 e);
uint1 *pad(char value, uint4 count);
void substring(uint4 s, uint4 e);
void tail(uint4 s);
Boolean usingbuffer();
void fill(uint4 s, char c, uint4 n);
void texttobinary();
void binarytotext();
void parseURL(Url_type &urltype, const char *&hostname, const char *&rname, uint4 &port, const char *&auth);
void utf16toutf8(void);
void utf8toutf16(void);
void utf16tonative(void);
void nativetoutf16(void);
void utf8tonative(void);
void nativetoutf8(void);
// MW-2012-02-16: [[ IntrinsicUnicode ]] Maps the content to unicode or native
// depending on 'want_unicode'. Content is assumed to be in unicode if 'is_unicode'
// is true; otherwise it is assumed to be native.
void mapunicode(bool is_unicode, bool want_unicode);
// MW-2011-06-22: [[ SERVER ]] Provides augmented functionality for finding
// variables if there is no handler (i.e. global server scope).
Parse_stat findvar(MCNameRef p_name, MCVarref** r_var);
//////////
void setstaticcstring(const char *string);
void setstaticchars(const char *string, uindex_t length);
void setstaticbytes(const void *bytes, uindex_t length);
void setstaticmcstring(const MCString& string);
void setempty(void);
void setcstring(const char *string);
void setmcstring(const MCString& string);
void setstringf(const char *spec, ...);
void setchars(const char *string, uindex_t length);
void setchar(char character);
void setbytes(const void *bytes, uindex_t length);
void setbyte(uint8_t byte);
void setboolean(Boolean value);
void setpoint(int16_t x, int16_t y);
void setrectangle(int32_t left, int32_t top, int32_t right, int32_t bottom);
void setrectangle(const MCRectangle& rect);
void setrectangle(const MCRectangle32& rect);
void setcolor(uint32_t r, uint32_t g, uint32_t b);
void setcolor(const MCColor& color);
void setcolor(const MCColor& color, const char *colorname);
void setpixel(uint32_t pixel);
void setnewline(void);
void appendcstring(const char *string);
void appendmcstring(const MCString& string);
void appendstringf(const char *spec, ...);
void appendchars(const char *string, uindex_t length);
void appendchar(char character);
void appendunichars(const uint2 *string, uindex_t length);
void appendunichar(uint2 character);
void appendbytes(const void *bytes, uindex_t length);
void appendbyte(uint8_t byte);
void appenduint(uint32_t integer);
void appendint(int32_t integer);
void appendreal(double real);
void appendnewline(void);
void appendnewline(bool unicode);
void concatcstring(const char *string, Exec_concat sep, bool first);
void concatchars(const char *chars, uindex_t count, Exec_concat sep, bool first);
void concatmcstring(const MCString& string, Exec_concat sep, bool first);
void concatuint(uint32_t value, Exec_concat sep, bool first);
void concatint(int32_t value, Exec_concat sep, bool first);
void concatreal(double real, Exec_concat sep, bool first);
void replacechar(char from, char to);
void setnameref_unsafe(MCNameRef name);
void appendnameref(MCNameRef name);
void concatnameref(MCNameRef name, Exec_concat sep, bool first);
bool copyasnameref(MCNameRef& name);
// Attempts to convert the contents of the ep from UTF-16 to native,
// returning true if successful and replacing the contents.
bool trytoconvertutf16tonative();
// SN-2015-06-03: [[ Bug 11277 ]] Refactor similar functions from MCHandler
// and MCHandlerlist
static void deletestatements(MCStatement *p_statements);
Exec_stat eval(MCExecPoint &ep);
Exec_stat doscript(MCExecPoint &ep, uint2 line, uint2 pos);
private:
void dounicodetomultibyte(bool p_native, bool p_reverse);
void concat(uint4 n, Exec_concat, Boolean);
void concat(int4 n, Exec_concat, Boolean);
void concat(const MCString &, Exec_concat, Boolean);
};
inline void MCExecPoint::utf16toutf8(void)
{
dounicodetomultibyte(false, false);
}
inline void MCExecPoint::utf8toutf16(void)
{
dounicodetomultibyte(false, true);
}
inline void MCExecPoint::utf16tonative(void)
{
dounicodetomultibyte(true, false);
}
inline void MCExecPoint::nativetoutf16(void)
{
dounicodetomultibyte(true, true);
}
inline void MCExecPoint::utf8tonative(void)
{
utf8toutf16();
utf16tonative();
}
inline void MCExecPoint::nativetoutf8(void)
{
nativetoutf16();
utf16toutf8();
}
#ifndef __MC_VARIABLE_IMPLEMENTATION__
#include "variable_impl.h"
#endif
#endif