Skip to content

Commit 844395b

Browse files
committed
[[ Bug 17690 ]] Replace version number literals with defined constants
1 parent 757d98c commit 844395b

23 files changed

+218
-141
lines changed

engine/engine-sources.gypi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@
211211
'src/scrolbar.h',
212212
'src/sellst.h',
213213
'src/stack.h',
214+
'src/stackfileformat.h',
214215
'src/stacklst.h',
215216
'src/styledtext.h',
216217
'src/textbuffer.h',

engine/src/block.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
3838

3939
#include "exec-interface.h"
4040

41+
#include "stackfileformat.h"
42+
4143
#define IMAGE_BLOCK_LEADING 2
4244
static MCRectangle
4345
MCBlockMakeRectangle(double x, double y,
@@ -181,7 +183,7 @@ IO_stat MCBlock::load(IO_handle stream, uint32_t version, bool is_ext)
181183
// is a font record to read.
182184
if (flags & F_FONT)
183185
{
184-
if (version > 1300)
186+
if (version > kMCStackFileFormatVersion_1_3)
185187
{
186188
uint2 t_font_index;
187189
if ((stat = IO_read_uint2(&t_font_index, stream)) != IO_NORMAL)
@@ -242,7 +244,7 @@ IO_stat MCBlock::load(IO_handle stream, uint32_t version, bool is_ext)
242244
atts->backcolor = new MCColor;
243245
if ((stat = IO_read_mccolor(*atts->backcolor, stream)) != IO_NORMAL)
244246
return checkloadstat(stat);
245-
if (version < 2000 || flags & F_HAS_BACK_COLOR_NAME)
247+
if (version < kMCStackFileFormatVersion_2_0 || flags & F_HAS_BACK_COLOR_NAME)
246248
{
247249
// MW-2012-01-06: [[ Block Changes ]] We no longer use the backcolor name
248250
// so load, delete and unset the flag.
@@ -264,15 +266,15 @@ IO_stat MCBlock::load(IO_handle stream, uint32_t version, bool is_ext)
264266
if (flags & F_HAS_LINK)
265267
{
266268
// MW-2013-11-19: [[ UnicodeFileFormat ]] If sfv >= 7000, use unicode.
267-
if ((stat = IO_read_stringref_new(atts->linktext, stream, version >= 7000)) != IO_NORMAL)
269+
if ((stat = IO_read_stringref_new(atts->linktext, stream, version >= kMCStackFileFormatVersion_7_0)) != IO_NORMAL)
268270
return checkloadstat(stat);
269271
/* UNCHECKED */ MCValueInterAndRelease(atts -> linktext, atts -> linktext);
270272
}
271273

272274
if (flags & F_HAS_IMAGE)
273275
{
274276
// MW-2013-11-19: [[ UnicodeFileFormat ]] If sfv >= 7000, use unicode.
275-
if ((stat = IO_read_stringref_new(atts->imagesource, stream, version >= 7000)) != IO_NORMAL)
277+
if ((stat = IO_read_stringref_new(atts->imagesource, stream, version >= kMCStackFileFormatVersion_7_0)) != IO_NORMAL)
276278
return checkloadstat(stat);
277279
/* UNCHECKED */ MCValueInterAndRelease(atts -> imagesource, atts -> imagesource);
278280
}
@@ -282,7 +284,7 @@ IO_stat MCBlock::load(IO_handle stream, uint32_t version, bool is_ext)
282284
if (flags & F_HAS_METADATA)
283285
{
284286
// MW-2013-11-19: [[ UnicodeFileFormat ]] If sfv >= 7000, use unicode.
285-
if ((stat = IO_read_stringref_new(atts->metadata, stream, version >= 7000)) != IO_NORMAL)
287+
if ((stat = IO_read_stringref_new(atts->metadata, stream, version >= kMCStackFileFormatVersion_7_0)) != IO_NORMAL)
286288
return checkloadstat(stat);
287289
/* UNCHECKED */ MCValueInterAndRelease(atts -> metadata, atts -> metadata);
288290
}
@@ -340,7 +342,7 @@ IO_stat MCBlock::save(IO_handle stream, uint4 p_part, uint32_t p_version)
340342
// MW-2012-03-04: [[ StackFile5500 ]] If the block has metadata and 5.5 stackfile
341343
// format has been requested then this is an extended block.
342344
bool t_is_ext;
343-
if (p_version >= 5500 && getflag(F_HAS_METADATA))
345+
if (p_version >= kMCStackFileFormatVersion_5_5 && getflag(F_HAS_METADATA))
344346
t_is_ext = true;
345347
else
346348
t_is_ext = false;
@@ -369,7 +371,7 @@ IO_stat MCBlock::save(IO_handle stream, uint4 p_part, uint32_t p_version)
369371

370372
// The "has unicode" flag depends on whether the paragraph is native
371373
bool t_is_unicode;
372-
if (p_version < 7000 && MCStringIsNative(parent->GetInternalStringRef()))
374+
if (p_version < kMCStackFileFormatVersion_7_0 && MCStringIsNative(parent->GetInternalStringRef()))
373375
{
374376
t_is_unicode = false;
375377
flags &= ~F_HAS_UNICODE;
@@ -381,7 +383,7 @@ IO_stat MCBlock::save(IO_handle stream, uint4 p_part, uint32_t p_version)
381383
}
382384

383385
// SN-2014-12-04: [[ Bug 14149 ]] Add the F_HAS_TAB flag, for legacy saving
384-
if (p_version < 7000)
386+
if (p_version < kMCStackFileFormatVersion_7_0)
385387
{
386388
if (segment && segment != segment -> next())
387389
flags |= F_HAS_TAB;
@@ -438,11 +440,11 @@ IO_stat MCBlock::save(IO_handle stream, uint4 p_part, uint32_t p_version)
438440
// strings.
439441
// MW-2013-11-19: [[ UnicodeFileFormat ]] If sfv >= 7000, use unicode.
440442
if (flags & F_HAS_LINK)
441-
if ((stat = IO_write_stringref_new(atts->linktext, stream, p_version >= 7000)) != IO_NORMAL)
443+
if ((stat = IO_write_stringref_new(atts->linktext, stream, p_version >= kMCStackFileFormatVersion_7_0)) != IO_NORMAL)
442444
return stat;
443445
// MW-2013-11-19: [[ UnicodeFileFormat ]] If sfv >= 7000, use unicode.
444446
if (flags & F_HAS_IMAGE)
445-
if ((stat = IO_write_stringref_new(atts->imagesource, stream, p_version >= 7000)) != IO_NORMAL)
447+
if ((stat = IO_write_stringref_new(atts->imagesource, stream, p_version >= kMCStackFileFormatVersion_7_0)) != IO_NORMAL)
446448
return stat;
447449

448450
// MW-2012-03-04: [[ StackFile5500 ]] If this is an extended block then emit the
@@ -451,7 +453,7 @@ IO_stat MCBlock::save(IO_handle stream, uint4 p_part, uint32_t p_version)
451453
{
452454
// MW-2013-11-19: [[ UnicodeFileFormat ]] If sfv >= 7000, use unicode.
453455
if (flags & F_HAS_METADATA)
454-
if ((stat = IO_write_stringref_new(atts -> metadata, stream, p_version >= 7000)) != IO_NORMAL)
456+
if ((stat = IO_write_stringref_new(atts -> metadata, stream, p_version >= kMCStackFileFormatVersion_7_0)) != IO_NORMAL)
455457
return stat;
456458
}
457459

@@ -2073,7 +2075,7 @@ uint32_t measure_stringref(MCStringRef p_string, uint32_t p_version)
20732075
uint32_t t_additional_bytes = 0;
20742076

20752077

2076-
if (p_version < 7000)
2078+
if (p_version < kMCStackFileFormatVersion_7_0)
20772079
t_encoding = kMCStringEncodingNative;
20782080
else
20792081
t_encoding = kMCStringEncodingUTF8;
@@ -2084,7 +2086,7 @@ uint32_t measure_stringref(MCStringRef p_string, uint32_t p_version)
20842086
uint32_t t_length;
20852087
t_length = MCDataGetLength(*t_data);
20862088

2087-
if (p_version < 7000)
2089+
if (p_version < kMCStackFileFormatVersion_7_0)
20882090
{
20892091
// Full string is written in 5.5 format:
20902092
// - length is written as a uint2

engine/src/button.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
5252

5353
#include "exec.h"
5454

55+
#include "stackfileformat.h"
56+
5557
uint2 MCButton::mnemonicoffset = 1;
5658
MCRectangle MCButton::optionrect = {0, 0, 12, 8};
5759
uint4 MCButton::clicktime;
@@ -3569,7 +3571,7 @@ IO_stat MCButton::save(IO_handle stream, uint4 p_part, bool p_force_ext, uint32_
35693571
// we need to rely on the F_LABEL flag
35703572
if (flags & F_LABEL)
35713573
{
3572-
if (p_version < 7000)
3574+
if (p_version < kMCStackFileFormatVersion_7_0)
35733575
{
35743576
if ((stat = IO_write_stringref_legacy(label, stream, hasunicode())) != IO_NORMAL)
35753577
return stat;
@@ -3595,13 +3597,13 @@ IO_stat MCButton::save(IO_handle stream, uint4 p_part, bool p_force_ext, uint32_
35953597
return stat;
35963598
}
35973599
// MW-2013-11-19: [[ UnicodeFileFormat ]] If sfv >= 7000, use unicode.
3598-
if ((stat = IO_write_nameref_new(menuname, stream, p_version >= 7000)) != IO_NORMAL)
3600+
if ((stat = IO_write_nameref_new(menuname, stream, p_version >= kMCStackFileFormatVersion_7_0)) != IO_NORMAL)
35993601
return stat;
36003602
// MW-2013-11-19: [[ UnicodeFileFormat ]] If sfv >= 7000, use unicode; otherwise use
36013603
// legacy unicode output.
36023604
if (flags & F_MENU_STRING)
36033605
{
3604-
if (p_version < 7000)
3606+
if (p_version < kMCStackFileFormatVersion_7_0)
36053607
{
36063608
if ((stat = IO_write_stringref_legacy(menustring, stream, hasunicode())) != IO_NORMAL)
36073609
return stat;
@@ -3630,7 +3632,7 @@ IO_stat MCButton::save(IO_handle stream, uint4 p_part, bool p_force_ext, uint32_
36303632

36313633
// MW-2013-11-19: [[ UnicodeFileFormat ]] If sfv >= 7000, use unicode; otherwise use
36323634
// legacy unicode output.
3633-
if (p_version < 7000)
3635+
if (p_version < kMCStackFileFormatVersion_7_0)
36343636
{
36353637
if ((stat = IO_write_stringref_legacy(acceltext, stream, hasunicode())) != IO_NORMAL)
36363638
return stat;
@@ -3676,7 +3678,7 @@ IO_stat MCButton::load(IO_handle stream, uint32_t version)
36763678
if ((m_font_flags & FF_HAS_UNICODE_TAG) != 0)
36773679
m_font_flags |= FF_HAS_UNICODE;
36783680

3679-
if (version <= 2300)
3681+
if (version <= kMCStackFileFormatVersion_2_3)
36803682
{
36813683
uint4 iconid;
36823684
uint4 hiliteiconid = 0;
@@ -3719,7 +3721,7 @@ IO_stat MCButton::load(IO_handle stream, uint32_t version)
37193721
// legacy unicode output.
37203722
if (flags & F_LABEL)
37213723
{
3722-
if (version < 7000)
3724+
if (version < kMCStackFileFormatVersion_7_0)
37233725
{
37243726
if ((stat = IO_read_stringref_legacy(label, stream, hasunicode())) != IO_NORMAL)
37253727
return checkloadstat(stat);
@@ -3753,14 +3755,14 @@ IO_stat MCButton::load(IO_handle stream, uint32_t version)
37533755
}
37543756

37553757
// MW-2013-11-19: [[ UnicodeFileFormat ]] If sfv >= 7000, use unicode.
3756-
if ((stat = IO_read_nameref_new(menuname, stream, version >= 7000)) != IO_NORMAL)
3758+
if ((stat = IO_read_nameref_new(menuname, stream, version >= kMCStackFileFormatVersion_7_0)) != IO_NORMAL)
37573759
return checkloadstat(stat);
37583760

37593761
// MW-2013-11-19: [[ UnicodeFileFormat ]] If sfv >= 7000, use unicode; otherwise use
37603762
// legacy unicode output.
37613763
if (flags & F_MENU_STRING)
37623764
{
3763-
if (version < 7000)
3765+
if (version < kMCStackFileFormatVersion_7_0)
37643766
{
37653767
if ((stat = IO_read_stringref_legacy(menustring, stream, hasunicode())) != IO_NORMAL)
37663768
return checkloadstat(stat);
@@ -3793,7 +3795,7 @@ IO_stat MCButton::load(IO_handle stream, uint32_t version)
37933795

37943796
// MW-2013-11-19: [[ UnicodeFileFormat ]] If sfv >= 7000, use unicode; otherwise use
37953797
// legacy unicode output.
3796-
if (version < 7000)
3798+
if (version < kMCStackFileFormatVersion_7_0)
37973799
{
37983800
if ((stat = IO_read_stringref_legacy(acceltext, stream, hasunicode())) != IO_NORMAL)
37993801
return checkloadstat(stat);
@@ -3819,7 +3821,7 @@ IO_stat MCButton::load(IO_handle stream, uint32_t version)
38193821
return checkloadstat(stat);
38203822
if ((stat = IO_read_uint1(&mnemonic, stream)) != IO_NORMAL)
38213823
return checkloadstat(stat);
3822-
if (version <= 2000)
3824+
if (version <= kMCStackFileFormatVersion_2_0)
38233825
{
38243826
if (flags & F_DEFAULT)
38253827
rect = MCU_reduce_rect(rect, MOTIF_DEFAULT_WIDTH);

engine/src/card.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
6363

6464
#include "exec.h"
6565

66+
#include "stackfileformat.h"
67+
6668
MCRectangle MCCard::selrect;
6769
int2 MCCard::startx;
6870
int2 MCCard::starty;
@@ -3085,7 +3087,7 @@ IO_stat MCCard::load(IO_handle stream, uint32_t version)
30853087
//---- 2.7+:
30863088
// . F_OPAQUE is now valid - default true
30873089
// . ink is now valid - default GXcopy
3088-
if (version < 2700)
3090+
if (version < kMCStackFileFormatVersion_2_7)
30893091
{
30903092
flags |= F_OPAQUE;
30913093
ink = GXcopy;
@@ -3203,7 +3205,7 @@ IO_stat MCCard::save(IO_handle stream, uint4 p_part, bool p_force_ext, uint32_t
32033205
//---- 2.7+:
32043206
// . F_OPAQUE valid - must be true in older versions
32053207
// . ink valid - must be GXcopy in older versions
3206-
if (p_version < 2700)
3208+
if (p_version < kMCStackFileFormatVersion_2_7)
32073209
{
32083210
t_old_flags = flags;
32093211
t_old_ink = GXcopy;
@@ -3215,7 +3217,7 @@ IO_stat MCCard::save(IO_handle stream, uint4 p_part, bool p_force_ext, uint32_t
32153217
return stat;
32163218

32173219
//---- 2.7+
3218-
if (p_version < 2700)
3220+
if (p_version < kMCStackFileFormatVersion_2_7)
32193221
{
32203222
flags = t_old_flags;
32213223
ink = t_old_ink;

engine/src/dispatch.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
6161
#include "exec-interface.h"
6262
#include "graphics_util.h"
6363

64+
#include "stackfileformat.h"
65+
6466
#define UNLICENSED_TIME 6.0
6567
#ifdef _DEBUG_MALLOC_INC
6668
#define LICENSED_TIME 1.0
@@ -996,14 +998,14 @@ IO_stat MCDispatch::savestack(MCStack *sptr, const MCStringRef p_fname, uint32_t
996998
/* If no version was specified, assume that 8.0 format was requested */
997999
if (UINT32_MAX == p_version)
9981000
{
999-
p_version = 8000;
1001+
p_version = kMCStackFileFormatCurrentVersion;
10001002
}
10011003

10021004
/* If the stack doesn't contain widgets, and 8.0 format was requested,
10031005
* use 7.0 format. */
1004-
if (8000 == p_version && !sptr->haswidgets())
1006+
if (kMCStackFileFormatCurrentVersion == p_version && !sptr->haswidgets())
10051007
{
1006-
p_version = 7000;
1008+
p_version = kMCStackFileFormatVersion_7_0;
10071009
}
10081010

10091011
stat = dosavestack(sptr, p_fname, p_version);
@@ -1146,13 +1148,13 @@ IO_stat MCDispatch::dosavestack(MCStack *sptr, const MCStringRef p_fname, uint32
11461148
// MW-2012-03-04: [[ StackFile5500 ]] Work out what header to emit, and the size.
11471149
const char *t_header;
11481150
uint32_t t_header_size;
1149-
if (p_version >= 8000)
1151+
if (p_version >= kMCStackFileFormatVersion_8_0)
11501152
t_header = newheader8000, t_header_size = 8;
1151-
else if (p_version >= 7000)
1153+
else if (p_version >= kMCStackFileFormatVersion_7_0)
11521154
t_header = newheader7000, t_header_size = 8;
1153-
else if (p_version >= 5500)
1155+
else if (p_version >= kMCStackFileFormatVersion_5_5)
11541156
t_header = newheader5500, t_header_size = 8;
1155-
else if (p_version >= 2700)
1157+
else if (p_version >= kMCStackFileFormatVersion_2_7)
11561158
t_header = newheader, t_header_size = 8;
11571159
else
11581160
t_header = header, t_header_size = HEADERSIZE;

engine/src/eps.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
3434
#include "globals.h"
3535
#include "context.h"
3636

37+
#include "stackfileformat.h"
38+
3739
real8 MCEPS::xf;
3840
real8 MCEPS::yf;
3941

@@ -372,7 +374,7 @@ IO_stat MCEPS::load(IO_handle stream, uint32_t version)
372374
if ((stat = image->load(stream, version)) != IO_NORMAL)
373375
return checkloadstat(stat);
374376
}
375-
if (version > 1300)
377+
if (version > kMCStackFileFormatVersion_1_3)
376378
{
377379
if ((stat = IO_read_uint2(&curpage, stream)) != IO_NORMAL)
378380
return checkloadstat(stat);

engine/src/exec-array.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
3131
#include "exec.h"
3232
#include "exec-interface.h"
3333

34+
#include "stackfileformat.h"
35+
3436
////////////////////////////////////////////////////////////////////////////////
3537

3638
MC_EXEC_DEFINE_EVAL_METHOD(Arrays, Keys, 2)
@@ -756,7 +758,7 @@ void MCArraysEvalArrayEncode(MCExecContext& ctxt, MCArrayRef p_array, MCStringRe
756758

757759
// AL-2014-05-22: [[ Bug 12547 ]] Make arrayEncode encode in 7.0 format by default.
758760
bool t_legacy;
759-
t_legacy = p_version != nil && t_version . version < 7000;
761+
t_legacy = p_version != nil && t_version . version < kMCStackFileFormatVersion_7_0;
760762

761763
if (t_legacy)
762764
{

engine/src/exec-interface2.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
6161

6262
#include "objptr.h"
6363

64+
#include "stackfileformat.h"
65+
6466
#include "exec-interface.h"
6567
#include "resolution.h"
6668

@@ -571,7 +573,7 @@ void MCInterfaceStackFileVersionParse(MCExecContext& ctxt, MCStringRef p_input,
571573
// MW-2012-03-04: [[ StackFile5500 ]] Allow versions up to 5500 to be set.
572574
// MW-2013-12-05: [[ UnicodeFileFormat ]] Allow versions up to 7000 to be set.
573575
// MW-2014-12-17: [[ Widgets ]] Allow versions up to 8000 to be set.
574-
if (count < 2 || version < 2400 || version > 8000)
576+
if (count < 2 || version < kMCStackFileFormatMinimumExportVersion || version > kMCStackFileFormatCurrentVersion)
575577
{
576578
ctxt . LegacyThrow(EE_PROPERTY_STACKFILEBADVERSION);
577579
return;

engine/src/field.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
4747
#include "exec.h"
4848
#include "exec-interface.h"
4949

50+
#include "stackfileformat.h"
51+
5052
int2 MCField::clickx;
5153
int2 MCField::clicky;
5254
int2 MCField::goalx;
@@ -2693,7 +2695,7 @@ IO_stat MCField::load(IO_handle stream, uint32_t version)
26932695
if ((stat = IO_read_uint2(&tabs[i], stream)) != IO_NORMAL)
26942696
return checkloadstat(stat);
26952697
}
2696-
if (version <= 2000)
2698+
if (version <= kMCStackFileFormatVersion_2_0)
26972699
{
26982700
rect = MCU_reduce_rect(rect, MCfocuswidth);
26992701
if (flags & F_LIST_BEHAVIOR)

0 commit comments

Comments
 (0)