forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecpt.cpp
More file actions
1025 lines (890 loc) · 22.3 KB
/
Copy pathexecpt.cpp
File metadata and controls
1025 lines (890 loc) · 22.3 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
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright (C) 2003-2013 Runtime Revolution 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/>. */
#include "prefix.h"
#include "globdefs.h"
#include "parsedef.h"
#include "filedefs.h"
#include "objdefs.h"
#include "object.h"
#include "execpt.h"
#include "mcerror.h"
#include "util.h"
#include "globals.h"
#include "handler.h"
#include "hndlrlst.h"
#include "osspec.h"
#include "unicode.h"
void MCExecPoint::clear()
{
format = VF_STRING;
svalue.set(buffer, 0);
if (deletearray)
{
delete array;
array = NULL;
}
}
void MCExecPoint::setarray(MCVariableValue *a, Boolean d)
{
clear();
array = a;
deletearray = d;
format = VF_ARRAY;
}
char *MCExecPoint::getbuffer(uint4 l)
{
if (size < l)
{
delete buffer;
size = l + EP_PAD & EP_MASK;
buffer = new char[size];
}
return buffer;
}
void MCExecPoint::copysvalue(const char *s, uint4 l)
{
memcpy(getbuffer(l), s, l);
svalue.set(buffer, l);
format = VF_STRING;
}
void MCExecPoint::grabsvalue()
{
if (format == VF_NUMBER)
tos();
if (svalue.getstring() != buffer)
{
uint4 l = svalue.getlength();
memmove(getbuffer(l), svalue.getstring(), l);
svalue.set(buffer, l);
}
}
void MCExecPoint::grabarray()
{
// MW-2008-06-16: Only grab the array if we don't own it (deletearray == False).
if (!deletearray)
{
array = new MCVariableValue(*array);
deletearray = True;
}
}
void MCExecPoint::grabbuffer(char *p_buffer, uint4 p_length)
{
if (buffer != NULL)
delete buffer;
if (deletearray)
{
delete array;
deletearray = False;
}
buffer = p_buffer;
size = p_length;
svalue . set(buffer, size);
format = VF_STRING;
}
void MCExecPoint::grab(void)
{
if (format == VF_ARRAY)
grabarray();
else if (format != VF_NUMBER && svalue . getstring() != buffer)
{
uint4 l = svalue.getlength();
memmove(getbuffer(l), svalue.getstring(), l);
svalue.set(buffer, l);
}
}
void MCExecPoint::setint(int4 i)
{
sprintf(getbuffer(U4L), "%d", i);
svalue.set(buffer, strlen(buffer));
nvalue = (real8)i;
format = VF_BOTH;
}
void MCExecPoint::setuint(uint4 i)
{
sprintf(getbuffer(U4L), "%u", i);
svalue.set(buffer, strlen(buffer));
nvalue = (real8)i;
format = VF_BOTH;
}
void MCExecPoint::setint64(int64_t i)
{
sprintf(getbuffer(U8L), "%lld", i);
svalue.set(buffer, strlen(buffer));
nvalue = (real8)i;
format = VF_BOTH;
}
void MCExecPoint::setuint64(uint64_t i)
{
sprintf(getbuffer(U8L), "%llu", i);
svalue.set(buffer, strlen(buffer));
nvalue = (real8)i;
format = VF_BOTH;
}
void MCExecPoint::setr8(real8 n, uint2 fw, uint2 trailing, uint2 force)
{
sprintf(getbuffer(R8L), "%0*.*f", fw, trailing, n);
MCU_strip(buffer, trailing, force);
svalue.set(buffer, strlen(buffer));
nvalue = n;
format = VF_BOTH;
}
Exec_stat MCExecPoint::getreal8(real8 &d, uint2 l, uint2 p, Exec_errors e)
{
if (format == VF_STRING)
if (ston() != ES_NORMAL)
{
MCeerror->add
(EE_VARIABLE_NAN, l, p, svalue);
MCeerror->add
(e, l, p, svalue);
return ES_ERROR;
}
d = nvalue;
return ES_NORMAL;
}
Exec_stat MCExecPoint::getuint2(uint2 &d, uint2 l, uint2 p, Exec_errors e)
{
if (format == VF_STRING)
if (ston() != ES_NORMAL)
{
MCeerror->add
(EE_VARIABLE_NAN, l, p, svalue);
MCeerror->add
(e, l, p, svalue);
return ES_ERROR;
}
if (nvalue < 0.0)
d = (uint2)(nvalue - 0.5);
else
d = (uint2)(nvalue + 0.5);
return ES_NORMAL;
}
Exec_stat MCExecPoint::getint4(int4 &d, uint2 l, uint2 p, Exec_errors e)
{
if (format == VF_STRING)
if (ston() != ES_NORMAL)
{
MCeerror->add
(EE_VARIABLE_NAN, l, p, svalue);
MCeerror->add
(e, l, p, svalue);
return ES_ERROR;
}
if (nvalue < 0.0)
d = (int4)(nvalue - 0.5);
else
d = (int4)(nvalue + 0.5);
return ES_NORMAL;
}
Exec_stat MCExecPoint::getuint4(uint4 &d, uint2 l, uint2 p, Exec_errors e)
{
if (format == VF_STRING)
if (ston() != ES_NORMAL)
{
MCeerror->add
(EE_VARIABLE_NAN, l, p, svalue);
MCeerror->add
(e, l, p, svalue);
return ES_ERROR;
}
if (nvalue < 0.0)
d = (uint4)(nvalue - 0.5);
else
d = (uint4)(nvalue + 0.5);
return ES_NORMAL;
}
Exec_stat MCExecPoint::getboolean(Boolean &d, uint2 l, uint2 p, Exec_errors e)
{
if (format == VF_UNDEFINED || format == VF_NUMBER
|| !MCU_stob(svalue, d))
{
if (format == VF_UNDEFINED)
clear();
if (format == VF_NUMBER)
tos();
MCeerror->add(e, l, p, svalue);
return ES_ERROR;
}
return ES_NORMAL;
}
Exec_stat MCExecPoint::ntos()
{
if (nvalue == BAD_NUMERIC)
return ES_ERROR;
uint4 length = MCU_r8tos(buffer, size, nvalue, nffw, nftrailing, nfforce);
svalue.set(buffer, length);
format = VF_BOTH;
return ES_NORMAL;
}
Exec_stat MCExecPoint::ston()
{
if (svalue.getlength() == 0)
nvalue = 0.0;
else
if (!MCU_stor8(svalue, nvalue, convertoctals))
return ES_ERROR;
format = VF_BOTH;
return ES_NORMAL;
}
void MCExecPoint::lower()
{
uint4 length = svalue.getlength();
MCU_lower(getbuffer(length), svalue);
svalue.set(buffer, length);
}
void MCExecPoint::upper()
{
uint4 length = svalue.getlength();
MCU_upper(getbuffer(length), svalue);
svalue.set(buffer, length);
}
// MW-2007-07-03: [[ Bug 5123 ]] - Strict array checking modification
Exec_stat MCExecPoint::setitemdel(uint2 l, uint2 p)
{
if (tos() != ES_NORMAL || svalue.getlength() != 1)
{
MCeerror->add
(EE_VARIABLE_NAC, l, p, svalue);
return ES_ERROR;
}
itemdel = svalue.getstring()[0];
return ES_NORMAL;
}
// MW-2007-07-03: [[ Bug 5123 ]] - Strict array checking modification
Exec_stat MCExecPoint::setcolumndel(uint2 l, uint2 p)
{
if (tos() != ES_NORMAL || svalue.getlength() != 1)
{
MCeerror->add(EE_VARIABLE_NAC, l, p, svalue);
return ES_ERROR;
}
columndel = svalue.getstring()[0];
return ES_NORMAL;
}
// MW-2007-07-03: [[ Bug 5123 ]] - Strict array checking modification
Exec_stat MCExecPoint::setrowdel(uint2 l, uint2 p)
{
if (tos() != ES_NORMAL || svalue.getlength() != 1)
{
MCeerror->add(EE_VARIABLE_NAC, l, p, svalue);
return ES_ERROR;
}
rowdel = svalue.getstring()[0];
return ES_NORMAL;
}
// MW-2007-07-03: [[ Bug 5123 ]] - Strict array checking modification
Exec_stat MCExecPoint::setlinedel(uint2 l, uint2 p)
{
if (tos() != ES_NORMAL || svalue.getlength() != 1)
{
MCeerror->add(EE_VARIABLE_NAC, l, p, svalue);
return ES_ERROR;
}
linedel = svalue.getstring()[0];
return ES_NORMAL;
}
void MCExecPoint::setnumberformat()
{
MCU_setnumberformat(svalue, nffw, nftrailing, nfforce);
}
void MCExecPoint::concat(const MCString &two, Exec_concat ec, Boolean first)
{
if (format == VF_NUMBER)
tos();
uint4 oldlength = svalue.getlength();
uint4 newlength = oldlength + two.getlength();
if (!first && ec != EC_NONE)
newlength++;
if (newlength > size)
{
// MW-2012-01-25: [[ Bug 9956 ]] Small optimization to improve large
// concatenations. Using 'realloc' means that no copying of data is
// needed in the best cases.
size = newlength + EP_PAD & EP_MASK;
if (svalue.getstring() != buffer)
{
char *newbuffer = new char[size];
memcpy(newbuffer, svalue.getstring(), oldlength);
delete buffer;
buffer = newbuffer;
}
else
{
char *newbuffer = (char *)realloc(buffer, size);
if (newbuffer == nil)
return;
buffer = newbuffer;
}
svalue.setstring(buffer);
}
else
if (svalue.getstring() != buffer)
{
memmove(buffer, svalue.getstring(), oldlength);
svalue.setstring(buffer);
}
if (!first)
switch (ec)
{
case EC_NONE:
break;
case EC_SPACE:
buffer[oldlength++] = ' ';
break;
case EC_COMMA:
buffer[oldlength++] = ',';
break;
case EC_NULL:
buffer[oldlength++] = '\0';
break;
case EC_RETURN:
buffer[oldlength++] = '\n';
break;
// MW-2009-06-17: Can now concatenate with tab into an EP.
case EC_TAB:
buffer[oldlength++] = '\t';
break;
}
if (two.getlength() == 1)
buffer[oldlength] = two.getstring()[0];
else
memcpy(&buffer[oldlength], two.getstring(), two.getlength());
svalue.setlength(newlength);
format = VF_STRING;
}
void MCExecPoint::concat(uint4 n, Exec_concat ec, Boolean first)
{
char buffer[U4L];
sprintf(buffer, "%u", n);
concat(buffer, ec, first);
}
void MCExecPoint::concat(int4 n, Exec_concat ec, Boolean first)
{
char buffer[I4L];
sprintf(buffer, "%d", n);
concat(buffer, ec, first);
}
void MCExecPoint::insert(const MCString &istring, uint4 s, uint4 e)
{
if (format == VF_NUMBER)
tos();
uint4 oldlength = svalue.getlength();
uint4 ilength = istring.getlength();
uint4 newlength = oldlength - (e - s) + ilength;
const char *sptr = svalue.getstring();
const char *isptr = istring.getstring();
char *oldbuffer = NULL;
if (newlength > size || sptr >= buffer && sptr < buffer + newlength
|| isptr >= buffer && isptr < buffer + newlength)
{
oldbuffer = buffer;
size = newlength + EP_PAD & EP_MASK;
buffer = new char[size];
memcpy(buffer, sptr, s);
memcpy(&buffer[s], isptr, ilength);
memcpy(&buffer[s + ilength], &sptr[e], oldlength - e);
}
else
{
memmove(buffer, sptr, s);
memmove(&buffer[s], isptr, ilength);
memmove(&buffer[s + ilength], &sptr[e], oldlength - e);
}
delete oldbuffer;
svalue.set(buffer, newlength);
format = VF_STRING;
}
uint1 *MCExecPoint::pad(char value, uint4 count)
{
uint4 oldlength = svalue.getlength();
uint4 newlength = oldlength + count;
if (newlength > size)
{
size = newlength + EP_PAD & EP_MASK;
char *newbuffer = new char[size];
memcpy(newbuffer, svalue.getstring(), oldlength);
delete buffer;
buffer = newbuffer;
svalue.setstring(buffer);
}
else
if (svalue.getstring() != buffer)
{
memmove(buffer, svalue.getstring(), oldlength);
svalue.setstring(buffer);
}
memset(buffer + oldlength, value, count);
svalue.setlength(newlength);
return (uint1 *)buffer + oldlength;
}
void MCExecPoint::substring(uint4 s, uint4 e)
{
svalue.set(&svalue.getstring()[s], e - s);
format = VF_STRING;
}
void MCExecPoint::tail(uint4 s)
{
svalue.set(svalue.getstring() + s, svalue.getlength() - s);
format = VF_STRING;
}
Boolean MCExecPoint::usingbuffer()
{
return svalue.getstring() >= buffer && svalue.getstring() < buffer + size;
}
void MCExecPoint::fill(uint4 s, char c, uint4 n)
{
uint4 oldlength = svalue.getlength();
uint4 newlength = oldlength + n;
if (newlength > size)
{
size = newlength + EP_PAD & EP_MASK;
char *newbuffer = new char[size];
memcpy(newbuffer, svalue.getstring(), s);
memcpy(newbuffer + s + n, svalue.getstring() + s, oldlength - s);
delete buffer;
buffer = newbuffer;
svalue.setstring(buffer);
}
else
{
if (svalue.getstring() != buffer)
{
memmove(buffer, svalue.getstring(), oldlength);
svalue.setstring(buffer);
}
memmove(buffer + s + n, buffer + s, oldlength - s);
}
memset(buffer + s, c, n);
svalue.setlength(newlength);
}
void MCExecPoint::texttobinary()
{
grabsvalue();
char *sptr = buffer;
char *dptr = buffer;
uint4 l = svalue.getlength();
char *eptr = buffer + l;
while (sptr < eptr)
{
if (*sptr == '\r')
{
if (sptr < eptr - 1 && *(sptr + 1) == '\n')
l--;
else
*dptr++ = '\n';
sptr++;
}
else
if (!*sptr)
{
*dptr++ = ' ';
sptr++;
}
else
*dptr++ = *sptr++;
}
svalue.set(buffer, l);
}
void MCExecPoint::binarytotext()
{
if (format == VF_NUMBER)
tos();
#ifdef __CRLF__
uint4 pad = 0;
const char *sptr = svalue.getstring();
uint4 i;
for (i = 0 ; i < svalue.getlength() ; i++)
if (*sptr++ == '\n')
pad++;
if (pad != 0)
{
uint4 newsize = svalue.getlength() + pad;
char *newbuffer = new char[newsize];
sptr = svalue.getstring() + svalue.getlength();
char *dptr = newbuffer + newsize;
while (dptr > newbuffer)
{
*--dptr = *--sptr;
if (*sptr == '\n')
*--dptr = '\r';
}
delete buffer;
buffer = newbuffer;
size = newsize;
svalue.set(buffer, newsize);
format = VF_STRING;
}
#elif defined __CR__
grabsvalue();
char *sptr = buffer;
uint4 i;
for (i = 0 ; i < svalue.getlength() ; i++)
{
if (*sptr == '\n')
*sptr = '\r';
sptr++;
}
format = VF_STRING;
#endif
}
const char *MCExecPoint::getcstring(void)
{
pad('\0', 1);
svalue . set(svalue . getstring(), svalue . getlength() - 1);
return svalue . getstring();
}
// MW-2011-06-22: [[ SERVER ]] Provides augmented functionality for finding
// variables if there is no handler (i.e. global server scope).
Parse_stat MCExecPoint::findvar(MCNameRef p_name, MCVarref** r_var)
{
Parse_stat t_stat;
t_stat = PS_ERROR;
if (curhandler != NULL)
t_stat = curhandler -> findvar(p_name, r_var);
else if (curhlist != NULL)
{
// MW-2011-08-23: [[ UQL ]] We are searching in global context, so do include UQLs.
t_stat = curhlist -> findvar(p_name, false, r_var);
}
return t_stat;
}
///////////////////////////////////////////////////////////////////////////////
extern int UnicodeToUTF8(const uint2 *p_source_str, int p_source, char *p_dest_str, int p_dest);
extern int UTF8ToUnicode(const char *p_source_str, int p_source, uint2 *p_dest_str, int p_dest);
static int NativeToUnicode(const char *p_source_str, int p_source, uint2 *p_dest_str, int p_dest)
{
if (p_dest_str == NULL)
return p_source * 2;
for(int i = 0; i < p_source; i++)
p_dest_str[i] = MCUnicodeMapFromNative(p_source_str[i]);
return p_source * 2;
}
void MCExecPoint::dounicodetomultibyte(bool p_native, bool p_reverse)
{
const char *t_input;
t_input = getsvalue() . getstring();
uint4 t_input_length;
t_input_length = getsvalue() . getlength();
uint4 t_output_length;
if (p_reverse)
{
if (p_native)
t_output_length = NativeToUnicode(t_input, t_input_length, NULL, 0);
else
t_output_length = UTF8ToUnicode(t_input, t_input_length, NULL, 0);
}
else
{
if (p_native)
MCS_unicodetomultibyte(t_input, t_input_length, NULL, 0, t_output_length, LCH_ROMAN);
else
t_output_length = UnicodeToUTF8((uint2 *)t_input, t_input_length, NULL, 0);
}
char *t_buffer;
uint4 t_buffer_length;
t_buffer_length = (t_output_length + EP_PAD) & EP_MASK;
t_buffer = new char[t_buffer_length];
if (p_reverse)
{
if (p_native)
t_output_length = NativeToUnicode(t_input, t_input_length, (uint2 *)t_buffer, t_output_length);
else
t_output_length = UTF8ToUnicode(t_input, t_input_length, (uint2 *)t_buffer, t_output_length);
}
else
{
if (p_native)
MCS_unicodetomultibyte(t_input, t_input_length, t_buffer, t_output_length, t_output_length, LCH_ROMAN);
else
t_output_length = UnicodeToUTF8((uint2 *)t_input, t_input_length, t_buffer, t_output_length);
}
delete buffer;
buffer = t_buffer;
size = t_buffer_length;
svalue . set(buffer, t_output_length);
}
// MW-2012-02-16: [[ IntrinsicUnicode ]] Switches the encoding of the ep to
// unicode if 'to_unicode' is true, native otherwise. If the current encoding
// matches (is_unicode) then nothing happens.
void MCExecPoint::mapunicode(bool p_is_unicode, bool p_to_unicode)
{
if (p_is_unicode == p_to_unicode)
return;
if (p_to_unicode)
nativetoutf16();
else
utf16tonative();
}
///////////////////////////////////////////////////////////////////////////////
void MCExecPoint::setempty(void)
{
clear();
}
/////////
void MCExecPoint::setstaticcstring(const char *p_string)
{
setsvalue(p_string);
}
void MCExecPoint::setstaticbytes(const void *p_bytes, uindex_t p_length)
{
setsvalue(MCString((const char *)p_bytes, p_length));
}
void MCExecPoint::setstaticmcstring(const MCString& p_mcstring)
{
setsvalue(p_mcstring);
}
/////////
void MCExecPoint::setcstring(const char *p_cstring)
{
copysvalue(p_cstring, strlen(p_cstring));
}
void MCExecPoint::setmcstring(const MCString& p_mcstring)
{
copysvalue(p_mcstring . getstring(), p_mcstring . getlength());
}
void MCExecPoint::setchars(const char *p_cstring, uindex_t p_length)
{
copysvalue(p_cstring, p_length);
}
void MCExecPoint::setchar(char p_char)
{
copysvalue(&p_char, 1);
}
void MCExecPoint::setstringf(const char *p_spec, ...)
{
va_list t_args;
int t_count;
#if defined(_HAS_VSCPRINTF)
va_start(t_args, p_spec);
t_count = _vscprintf(p_spec, t_args);
va_end(t_args);
#elif defined(_HAS_VSNPRINTF)
va_start(t_args, p_spec);
t_count = vsnprintf(nil, 0, p_spec, t_args);
va_end(t_args);
#else
#error MCExecPoint::setstringf not implemented
#endif
va_start(t_args, p_spec);
vsprintf(getbuffer(t_count + 1), p_spec, t_args);
va_end(t_args);
setstrlen();
}
/////////
void MCExecPoint::setboolean(Boolean p_value)
{
setsvalue(p_value ? MCtruemcstring : MCfalsemcstring);
}
void MCExecPoint::setpoint(int16_t x, int16_t y)
{
sprintf(getbuffer(I2L * 2 + 2), "%d,%d", x, y);
setstrlen();
}
void MCExecPoint::setrectangle(const MCRectangle& p_rect)
{
sprintf(getbuffer(I4L * 4 + 4), "%d,%d,%d,%d", p_rect . x, p_rect . y, p_rect . x + p_rect . width, p_rect . y + p_rect . height);
setstrlen();
}
void MCExecPoint::setrectangle(const MCRectangle32& p_rect)
{
sprintf(getbuffer(I4L * 4 + 4), "%d,%d,%d,%d", p_rect . x, p_rect . y, p_rect . x + p_rect . width, p_rect . y + p_rect . height);
setstrlen();
}
void MCExecPoint::setrectangle(int32_t p_left, int32_t p_top, int32_t p_right, int32_t p_bottom)
{
sprintf(getbuffer(I4L * 4 + 4), "%d,%d,%d,%d", p_left, p_top, p_right, p_bottom);
setstrlen();
}
void MCExecPoint::setcolor(const MCColor& p_color, const char *p_color_name)
{
if (p_color_name != nil)
copysvalue(p_color_name);
else
setcolor(p_color);
}
void MCExecPoint::setcolor(const MCColor& p_color)
{
setcolor(p_color . red >> 8, p_color . green >> 8, p_color . blue >> 8);
}
void MCExecPoint::setcolor(uint32_t r, uint32_t g, uint32_t b)
{
sprintf(getbuffer(U1L * 3 + 3), "%u,%u,%u", r & 0xff, g & 0xff, b & 0xff);
setstrlen();
}
void MCExecPoint::setpixel(uint32_t p_pixel)
{
setcolor((p_pixel >> 16) & 0xFF, (p_pixel >> 8) & 0xFF, (p_pixel >> 0) & 0xFF);
}
////////
void MCExecPoint::appendcstring(const char *p_string)
{
concat(p_string, EC_NONE, True);
}
void MCExecPoint::appendmcstring(const MCString& p_string)
{
concat(p_string, EC_NONE, True);
}
void MCExecPoint::appendstringf(const char *p_spec, ...)
{
va_list t_args;
int t_count;
#if defined(_HAS_VSCPRINTF)
va_start(t_args, p_spec);
t_count = _vscprintf(p_spec, t_args);
va_end(t_args);
#elif defined(_HAS_VSNPRINTF)
va_start(t_args, p_spec);
t_count = vsnprintf(nil, 0, p_spec, t_args);
va_end(t_args);
#else
#error MCExecPoint::setstringf not implemented
#endif
if (t_count < 256)
{
char t_buffer[256];
va_start(t_args, p_spec);
vsprintf(t_buffer, p_spec, t_args);
va_end(t_args);
concat(t_buffer, EC_NONE, True);
}
else
{
char *t_buffer;
t_buffer = (char *)malloc(t_count + 1);
if (t_buffer != nil)
{
va_start(t_args, p_spec);
vsprintf(t_buffer, p_spec, t_args);
va_end(t_args);
concat(t_buffer, EC_NONE, True);
free(t_buffer);
}
}
}
void MCExecPoint::appendchars(const char *p_chars, uindex_t p_count)
{
concat(MCString(p_chars, p_count), EC_NONE, True);
}
void MCExecPoint::appendchar(char p_char)
{
appendchars(&p_char, 1);
}
void MCExecPoint::appendbytes(const void *p_bytes, uindex_t p_count)
{
concat(MCString((const char *)p_bytes, p_count), EC_NONE, True);
}
void MCExecPoint::appendbyte(uint8_t p_byte)
{
appendbytes(&p_byte, 1);
}
void MCExecPoint::appenduint(uint32_t p_integer)
{
concat(p_integer, EC_NONE, True);
}
void MCExecPoint::appendint(int32_t p_integer)
{
concat(p_integer, EC_NONE, True);
}
void MCExecPoint::appendnewline(void)
{
appendchar('\n');
}
/////////
void MCExecPoint::appendnewline(bool unicode)
{
if (!unicode)
appendchar('\n');
else
{
uint2 t_char;
t_char = 10;
appendbytes(&t_char, 2);
}
}
/////////
void MCExecPoint::concatcstring(const char *p_string, Exec_concat p_sep, bool p_first)
{
if (p_string == nil)
p_string = "";
concat(MCString(p_string, strlen(p_string)), p_sep, p_first);
}
void MCExecPoint::concatchars(const char *p_chars, uindex_t p_count, Exec_concat p_sep, bool p_first)
{
concat(MCString(p_chars, p_count), p_sep, p_first);
}
void MCExecPoint::concatmcstring(const MCString& p_string, Exec_concat p_sep, bool p_first)
{
concat(p_string, p_sep, p_first);
}
void MCExecPoint::concatuint(uint32_t p_value, Exec_concat p_sep, bool p_first)
{
concat(p_value, p_sep, p_first);
}
void MCExecPoint::concatint(int32_t p_value, Exec_concat p_sep, bool p_first)
{
concat(p_value, p_sep, p_first);
}
void MCExecPoint::concatreal(double p_value, Exec_concat p_sep, bool p_first)
{
char *t_buffer;
uint32_t t_buffer_size;
t_buffer = nil;
t_buffer_size = 0;
uint32_t t_length;
t_length = MCU_r8tos(t_buffer, t_buffer_size, p_value, nffw, nftrailing, nfforce);
concat(MCString(t_buffer, t_length), p_sep, p_first);
delete[] t_buffer;
}
/////////
void MCExecPoint::replacechar(char p_from, char p_to)
{
grabsvalue();
for(uint32_t i = 0; i < svalue . getlength(); i++)
if (buffer[i] == p_from)
buffer[i] = p_to;
}
/////////
void MCExecPoint::setnameref_unsafe(MCNameRef p_name)
{
setstaticmcstring(MCNameGetOldString(p_name));
}
void MCExecPoint::concatnameref(MCNameRef p_name, Exec_concat p_sep, bool p_first)
{
concatmcstring(MCNameGetOldString(p_name), p_sep, p_first);
}
bool MCExecPoint::copyasnameref(MCNameRef& r_name)
{
return MCNameCreateWithOldString(getsvalue(), r_name);
}
// Assumes the contents of the ep is UTF-16 and attempts conversion to native. If
// successful, the new contents is native and the method returns true, otherwise
// false and the contents remains unchanged.