Skip to content

Commit 83932e6

Browse files
[[ RefactorSyntax ]] MCPrint::exec updated
1 parent a778174 commit 83932e6

2 files changed

Lines changed: 74 additions & 154 deletions

File tree

engine/src/cmds.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2028,10 +2028,10 @@ class MCPrint : public MCStatement
20282028
MCPrint();
20292029
virtual ~MCPrint();
20302030
virtual Parse_stat parse(MCScriptPoint &);
2031-
virtual Exec_stat exec(MCExecPoint &);
2031+
virtual void exec_ctxt(MCExecContext &ctxt);
20322032
virtual void compile(MCSyntaxFactoryRef);
20332033
private:
2034-
Exec_stat evaluate_src_rect(MCExecPoint& ep, MCPoint& r_from, MCPoint& r_to);
2034+
bool evaluate_src_rect(MCExecContext& ctxt, MCPoint& r_from, MCPoint& r_to);
20352035
};
20362036

20372037
class MCInclude: public MCStatement

engine/src/cmdsp.cpp

Lines changed: 72 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -287,41 +287,22 @@ Parse_stat MCPrint::parse(MCScriptPoint &sp)
287287
return PS_NORMAL;
288288
}
289289

290-
Exec_stat MCPrint::evaluate_src_rect(MCExecPoint& ep, MCPoint& r_from, MCPoint& r_to)
290+
bool MCPrint::evaluate_src_rect(MCExecContext& ctxt, MCPoint& r_from, MCPoint& r_to)
291291
{
292-
if (from -> eval(ep) != ES_NORMAL)
293-
{
294-
MCeerror -> add(EE_PRINT_CANTGETCOORD, line, pos);
295-
return ES_ERROR;
296-
}
297-
298-
MCPoint t_from;
299-
if (!ep . copyaslegacypoint(t_from))
300-
{
301-
MCeerror -> add(EE_PRINT_NAP, line, pos, ep.getsvalue());
302-
return ES_ERROR;
303-
}
292+
MCPoint t_from, t_to;
293+
if (!ctxt . EvalExprAsPoint(from, EE_PRINT_CANTGETCOORD, t_from))
294+
return false;
304295

305-
if (to -> eval(ep) != ES_NORMAL)
306-
{
307-
MCeerror -> add(EE_PRINT_CANTGETCOORD, line, pos);
308-
return ES_ERROR;
309-
}
310-
311-
MCPoint t_to;
312-
if (!ep . copyaslegacypoint(t_to))
313-
{
314-
MCeerror -> add(EE_PRINT_NAP, line, pos, ep . getsvalue());
315-
return ES_ERROR;
316-
}
296+
if (!ctxt . EvalExprAsPoint(to, EE_PRINT_CANTGETCOORD, t_to))
297+
return false;
317298

318-
r_from = t_from;
319-
r_to = t_to;
299+
r_from = t_from;
300+
r_to = t_to;
320301

321-
return ES_NORMAL;
302+
return true;
322303
}
323304

324-
Exec_stat MCPrint::exec(MCExecPoint &ep)
305+
void MCPrint::exec_ctxt(MCExecContext &ctxt)
325306
{
326307
#ifdef /* MCPrint */ LEGACY_EXEC
327308
if (MCsecuremode & MC_SECUREMODE_PRINT)
@@ -662,32 +643,15 @@ Exec_stat MCPrint::exec(MCExecPoint &ep)
662643
return t_exec_stat;
663644
#endif /* MCPrint */
664645

665-
666-
MCExecContext ctxt(ep);
667-
668646
if (mode == PM_ANCHOR)
669-
{
670-
if (from -> eval(ep) != ES_NORMAL)
671-
{
672-
MCeerror -> add(EE_DO_BADEXP, line, pos);
673-
return ES_ERROR;
674-
}
675-
676-
MCAutoStringRef t_name;
677-
/* UNCHECKED */ ep . copyasstringref(&t_name);
678-
679-
if (rect -> eval(ep) != ES_NORMAL)
680-
{
681-
MCeerror -> add(EE_PRINTANCHOR_BADLOCATION, line, pos);
682-
return ES_ERROR;
683-
}
647+
{
648+
MCAutoStringRef t_name;
649+
if (!ctxt . EvalExprAsStringRef(from, EE_DO_BADEXP, &t_name))
650+
return;
684651

685652
MCPoint t_location;
686-
if (!ep . copyaslegacypoint(t_location))
687-
{
688-
MCeerror -> add(EE_PRINTANCHOR_LOCATIONNAP, line, pos, ep . getsvalue());
689-
return ES_ERROR;
690-
}
653+
if (!ctxt . EvalExprAsPoint(rect, EE_PRINTANCHOR_BADLOCATION, t_location))
654+
return;
691655

692656
MCPrintingExecPrintAnchor(ctxt, *t_name, t_location);
693657
}
@@ -699,100 +663,71 @@ Exec_stat MCPrint::exec(MCExecPoint &ep)
699663
else if (mode == PM_LINK_URL)
700664
t_type = kMCPrinterLinkURI;
701665
else
702-
t_type = kMCPrinterLinkUnspecified;
703-
704-
if (to -> eval(ep) != ES_NORMAL)
705-
{
706-
MCeerror -> add(EE_PRINTLINK_BADDEST, line, pos);
707-
return ES_ERROR;
708-
}
666+
t_type = kMCPrinterLinkUnspecified;
709667

710668
MCAutoStringRef t_target;
711-
/* UNCHECKED */ ep . copyasstringref(&t_target);
712-
713-
if (rect -> eval(ep) != ES_NORMAL)
714-
{
715-
MCeerror -> add(EE_PRINTLINK_BADAREA, line, pos);
716-
return ES_ERROR;
717-
}
669+
if (!ctxt . EvalExprAsStringRef(to, EE_PRINTLINK_BADDEST, &t_target))
670+
return;
718671

719672
MCRectangle t_area;
720-
if (!ep . copyaslegacyrectangle(t_area))
721-
{
722-
MCeerror->add(EE_PRINTLINK_AREANAR, line, pos, ep . getsvalue());
723-
return ES_ERROR;
724-
}
673+
if (!ctxt . EvalExprAsRectangle(rect, EE_PRINTLINK_BADAREA, t_area))
674+
return;
725675

726676
MCPrintingExecPrintLink(ctxt, (int)t_type, *t_target, t_area);
727677
}
728678
else if (mode == PM_BOOKMARK || mode == PM_UNICODE_BOOKMARK)
729-
{
730-
if (from->eval(ep) != ES_NORMAL)
731-
{
732-
MCeerror->add(EE_PRINTBOOKMARK_BADTITLE, line, pos, ep.getsvalue());
733-
return ES_ERROR;
734-
}
735-
679+
{
736680
MCAutoValueRef t_title;
737-
if (mode != PM_UNICODE_BOOKMARK)
738-
/* UNCHECKED */ ep . copyasstringref((MCStringRef&)&t_title);
739-
else
740-
/* UNCHECKED */ ep . copyasdataref((MCDataRef&)&t_title);
681+
if (mode != PM_UNICODE_BOOKMARK)
682+
{
683+
if (!ctxt . EvalExprAsStringRef(from, EE_PRINTBOOKMARK_BADTITLE, (MCStringRef&)&t_title))
684+
return;
685+
}
686+
else
687+
{
688+
if (!ctxt . EvalExprAsDataRef(from, EE_PRINTBOOKMARK_BADTITLE, (MCDataRef&)&t_title))
689+
return;
690+
}
741691

742692
uint32_t t_level;
743-
t_level = 0;
744-
if (to != nil)
745-
{
746-
if (to->eval(ep) != ES_NORMAL ||
747-
ep.ton() != ES_NORMAL)
748-
{
749-
MCeerror->add(EE_PRINTBOOKMARK_BADLEVEL, line, pos, ep.getsvalue());
750-
return ES_ERROR;
751-
}
752-
else
753-
t_level = ep.getuint4();
754-
}
693+
if (!ctxt . EvalOptionalExprAsUInt(to, 0, EE_PRINTBOOKMARK_BADLEVEL, t_level))
694+
return;
755695

756696
MCPoint t_location;
757-
t_location . x = t_location . y = 0;
758-
if (rect != nil)
759-
{
760-
if (rect->eval(ep) != ES_NORMAL ||
761-
ep . copyaslegacypoint(t_location))
762-
{
763-
MCeerror->add(EE_PRINTBOOKMARK_BADAT, line, pos, ep.getsvalue());
764-
return ES_ERROR;
765-
}
766-
}
697+
t_location . x = t_location . y = 0;
698+
699+
MCPoint *t_location_ptr;
700+
t_location_ptr = &t_location;
701+
if (!ctxt . EvalOptionalExprAsPoint(rect, t_location_ptr, EE_PRINTBOOKMARK_BADAT, t_location_ptr))
702+
return;
767703

768704
bool t_initially_closed;
769705
t_initially_closed = false;
770706
if (initial_state != nil)
771707
{
772-
if (initial_state->eval(ep) != ES_NORMAL)
773-
{
774-
MCeerror->add(EE_PRINTBOOKMARK_BADINITIAL, line, pos, ep.getsvalue());
775-
return ES_ERROR;
776-
}
708+
MCAutoStringRef t_state;
709+
if (!ctxt . EvalExprAsStringRef(initial_state, EE_PRINTBOOKMARK_BADINITIAL, &t_state))
710+
return;
777711

778-
if (ep . getsvalue() == "closed")
712+
if (MCStringIsEqualToCString(*t_state, "closed", kMCCompareExact))
779713
t_initially_closed = true;
780-
else if (ep . getsvalue() == "open")
714+
else if (MCStringIsEqualToCString(*t_state, "open", kMCCompareExact))
781715
t_initially_closed = false;
782716
else
783717
{
784-
MCeerror->add(EE_PRINTBOOKMARK_BADINITIAL, line, pos, ep.getsvalue());
785-
return ES_ERROR;
718+
MCeerror->add(EE_PRINTBOOKMARK_BADINITIAL, line, pos, *t_state);
719+
ctxt . Throw();
720+
return;
786721
}
787722
}
788723
else
789724
t_initially_closed = bookmark_closed;
790725

791726

792727
if (mode != PM_UNICODE_BOOKMARK)
793-
MCPrintingExecPrintBookmark(ctxt, (MCStringRef)*t_title, t_location, t_level, t_initially_closed);
728+
MCPrintingExecPrintBookmark(ctxt, (MCStringRef)*t_title, t_location, t_level, t_initially_closed);
794729
else
795-
MCPrintingExecPrintUnicodeBookmark(ctxt, (MCDataRef)*t_title, t_location, t_level, t_initially_closed);
730+
MCPrintingExecPrintUnicodeBookmark(ctxt, (MCDataRef)*t_title, t_location, t_level, t_initially_closed);
796731
}
797732
else if (mode == PM_BREAK)
798733
{
@@ -806,19 +741,21 @@ Exec_stat MCPrint::exec(MCExecPoint &ep)
806741
{
807742
MCObject *optr;
808743
uint32_t parid;
809-
if (target -> getobj(ep, optr, parid, True) != ES_NORMAL || optr -> gettype() != CT_STACK)
744+
if (!target -> getobj(ctxt, optr, parid, True)
745+
|| optr -> gettype() != CT_STACK)
810746
{
811747
MCeerror -> add(EE_PRINT_NOTARGET, line, pos);
812-
return ES_ERROR;
748+
ctxt . Throw();
749+
return;
813750
}
814751

815752
t_stack = (MCStack *)optr;
816753
}
817754

818755
MCPoint t_area_from, t_area_to;
819756
if (from != nil &&
820-
evaluate_src_rect(ep, t_area_from, t_area_to) == ES_ERROR)
821-
return ES_ERROR;
757+
!evaluate_src_rect(ctxt, t_area_from, t_area_to))
758+
return;
822759

823760
if (from == nil)
824761
MCPrintingExecPrintAllCards(ctxt, t_stack, mode == PM_MARKED);
@@ -831,24 +768,26 @@ Exec_stat MCPrint::exec(MCExecPoint &ep)
831768
if (target != NULL)
832769
{
833770
uint32_t parid;
834-
if (target -> getobj(ep, t_object, parid, True) != ES_NORMAL)
771+
if (!target -> getobj(ctxt, t_object, parid, True))
835772
{
836773
MCeerror -> add(EE_PRINT_NOTARGET, line, pos);
837-
return ES_ERROR;
774+
ctxt . Throw();
775+
return;
838776
}
839777
if (t_object -> gettype() != CT_CARD && t_object -> gettype() != CT_STACK)
840778
{
841779
MCeerror -> add(EE_PRINT_NOTACARD, line, pos);
842-
return ES_ERROR;
780+
ctxt . Throw();
781+
return;
843782
}
844783
}
845784
else
846785
t_object = MCdefaultstackptr -> getcurcard();
847786

848787
MCPoint t_from, t_to;
849788
if (from != nil &&
850-
evaluate_src_rect(ep, t_from, t_to) == ES_ERROR)
851-
return ES_ERROR;
789+
!evaluate_src_rect(ctxt, t_from, t_to))
790+
return;
852791

853792
if (t_object -> gettype() == CT_STACK)
854793
{
@@ -866,18 +805,9 @@ Exec_stat MCPrint::exec(MCExecPoint &ep)
866805
}
867806
else
868807
{
869-
if (rect -> eval(ep) != ES_NORMAL)
870-
{
871-
MCeerror -> add(EE_PRINT_CANTGETRECT, line, pos);
872-
return ES_ERROR;
873-
}
874-
875-
MCRectangle t_dst_area;
876-
if (!ep . copyaslegacyrectangle(t_dst_area))
877-
{
878-
MCeerror->add(EE_PRINT_NAR, line, pos, ep . getsvalue());
879-
return ES_ERROR;
880-
}
808+
MCRectangle t_dst_area;
809+
if (!ctxt . EvalExprAsRectangle(rect, EE_PRINT_CANTGETRECT, t_dst_area))
810+
return;
881811

882812
if (from == nil)
883813
MCPrintingExecPrintCardIntoRect(ctxt, (MCCard *)t_object, t_dst_area);
@@ -887,30 +817,20 @@ Exec_stat MCPrint::exec(MCExecPoint &ep)
887817
}
888818
else if (mode == PM_SOME)
889819
{
890-
if (target -> eval(ep) != ES_NORMAL || ep . ton() != ES_NORMAL)
891-
{
892-
MCeerror -> add(EE_PRINT_CANTGETCOUNT, line, pos);
893-
return ES_ERROR;
894-
}
895-
896-
integer_t t_count;
897-
t_count = ep . getint4();
820+
integer_t t_count;
821+
if (!ctxt . EvalExprAsInt(target, EE_PRINT_CANTGETCOUNT, t_count))
822+
return;
898823

899824
MCPoint t_from, t_to;
900825
if (from != nil &&
901-
evaluate_src_rect(ep, t_from, t_to) == ES_ERROR)
902-
return ES_ERROR;
826+
!evaluate_src_rect(ctxt, t_from, t_to))
827+
return;
903828

904829
if (from == nil)
905830
MCPrintingExecPrintSomeCards(ctxt, t_count);
906831
else
907832
MCPrintingExecPrintRectOfSomeCards(ctxt, t_count, t_from, t_to);
908-
}
909-
910-
if (!ctxt . HasError())
911-
return ES_NORMAL;
912-
913-
return ctxt . Catch(line, pos);
833+
}
914834
}
915835

916836
void MCPrint::compile(MCSyntaxFactoryRef ctxt)

0 commit comments

Comments
 (0)