4343*/
4444
4545#include "form3.h"
46+ #include "comtool.h"
4647
4748/*
4849 com1commands are the commands of which only part of the word has to
@@ -566,10 +567,13 @@ int CompileStatement(UBYTE *in)
566567 First the test on the order of the statements.
567568 This is relatively new (2.2c) and may cause some problems with old
568569 programs. Hence the first error message should explain!
570+
571+ Positions of declaration statements with the WITHAUTO flag and
572+ ModuleOption statements for $-variables have been relaxed from v4.2.
569573*/
570574 if ( AP .PreAssignFlag == 0 && AM .OldOrderFlag == 0 ) {
571575 if ( AP .PreInsideLevel ) {
572- if ( k -> type != STATEMENT && k -> type != MIXED ) {
576+ if ( k -> type != STATEMENT && k -> type != MIXED && ( k -> type != DECLARATION || !( k -> flags & WITHAUTO )) ) {
573577 MesPrint ("&Only executable and print statements are allowed in an %#inside/%#endinside construction" );
574578 return (-1 );
575579 }
@@ -582,14 +586,36 @@ int CompileStatement(UBYTE *in)
582586 if ( TestTables () ) error1 = 1 ;
583587 }
584588 }
589+ /*
590+ * Exception rules of the ordering:
591+ * - mixed statements
592+ * - declaration statements with the WITHAUTO flag
593+ * - the Format statement
594+ * - the ModuleOption statement for $-variables
595+ */
585596 if ( k -> type == MIXED ) {
586597 if ( AC .compiletype <= DEFINITION ) {
587598 AC .compiletype = STATEMENT ;
588599 }
589600 }
601+ else if ( k -> type == DECLARATION && (k -> flags & WITHAUTO ) ) {
602+ if ( AC .compiletype < DECLARATION ) {
603+ AC .compiletype = DECLARATION ;
604+ }
605+ }
590606 else if ( k -> type > AC .compiletype ) {
591- if ( StrCmp ((UBYTE * )(k -> name ),(UBYTE * )"format" ) != 0 )
592- AC .compiletype = k -> type ;
607+ if ( k -> type == TOOUTPUT && (StrCmp ((UBYTE * )(k -> name ),(UBYTE * )"format" ) == 0 ) )
608+ goto skip_new_compiletype ;
609+ if ( k -> type == ATENDOFMODULE && (StrCmp ((UBYTE * )(k -> name ),(UBYTE * )"moduleoption" ) == 0 ) ) {
610+ UBYTE * ss = s ;
611+ SkipSpaces (& ss );
612+ if ( ConsumeOption (& ss ,"local" ) ||
613+ ConsumeOption (& ss ,"maximum" ) ||
614+ ConsumeOption (& ss ,"minimum" ) ||
615+ ConsumeOption (& ss ,"sum" ) ) goto skip_new_compiletype ;
616+ }
617+ AC .compiletype = k -> type ;
618+ skip_new_compiletype :;
593619 }
594620 else if ( k -> type < AC .compiletype ) {
595621 switch ( k -> type ) {
0 commit comments