<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:Arial;
        color:windowtext;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>I have a MarkupExpression I am putting together which reads
a given page, checks for a certain value, and if it doesn&#8217;t find it then
it writes the value to the end of the page.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>I am finding inconsistent results with it where often it
somehow writes the value *<b><span style='font-weight:bold'>before</span></b>*
the read, even though there&#8217;s no possibility that I can see that that
could happen based on my code.&nbsp; And the strangest thing is that I have all
this code heavily debugged both with MessageFmt[]/(:messages:) as well as using
straight echo statements.&nbsp; The WikiShEcho() function clearly is *<b><span
style='font-weight:bold'>NOT</span></b>* processing according to both types of
debugging statements and yet the value is getting written to the page before
the WikiShGrep tries to read it?!?!?&nbsp; <o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>Is there any kind of situation in which directives (like
markup expressions) get processed twice in a single browse of a page?&nbsp; Or
(more surprising) that echo statements could somehow be suppressed during an
earlier invocation of the MX?<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>I&#8217;m completely befuzzled by this &#8211; any hints
anybody could give would be greatly appreciated.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>-Peter<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>PS Below is the relevant section of code &#8211; if you want
to see more context the whole recipe is at pmwiki/cookbook/wikish &#8211; the function
is WikiShOnce().&nbsp; Again, I clearly see in my debug statements the fact
that WikiShGrep is being invoked and finding the value that shouldn&#8217;t get
written until 9 lines later in the WikiShEcho() call.&nbsp; I&#8217;m making up
random strings to write to the file, so it&#8217;s not like some other part of
the page would be writing the same values&#8230;&nbsp; (There are no loops in
this function, neither before nor after this section of code, and this function
is called directly by $MarkupExpr[] stuff&#8230;&nbsp; If the MX were being
called in some kind of &#8220;preview mode&#8221; that would explain the whole
thing, but I&#8217;ve never heard of such a thing and I don&#8217;t know how
the echo statements would be being suppressed&#8230;<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>&nbsp;&nbsp;&nbsp; WikiShGrep($pagename,
array('q'=&gt;true), array(&quot;^$pat$&quot;, $ControlPage));&nbsp; </span></font><font
size=2 face=Wingdings><span style='font-size:10.0pt;font-family:Wingdings'>&szlig;</span></font><font
size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'> here I read
the page and search for the value<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>&nbsp;&nbsp;&nbsp; if ($WikiShVars['STATUS'] == 0) {<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # If found then
we shouldn't run again - return false<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
$WikiShVars['STATUS'] = 1;<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;wdbg(4,&quot;$func:
Returning (a) with STATUS=&quot; . $WikiShVars['STATUS']);<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return($opt['r']
? '0' : '');<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>&nbsp;&nbsp;&nbsp; } else {<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # not found -
WRITE the pattern to $WikiShControlPage<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # if successful
write to $WikiShControlPage then return true<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WikiShEcho($pagename,
array('stdout'=&gt;$ControlPage, 'stdout_append'=&gt;true),
array(&quot;$pat&quot;)); </span></font><font size=2 face=Wingdings><span
style='font-size:10.0pt;font-family:Wingdings'>&szlig;</span></font><font
size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial'> here I
write the value to the page<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #
$WikiShVars['STATUS'] was set by echo - if it succeeded then we<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # succeed.&nbsp;
If it didn't succeed then we don't succeed.&nbsp; Thus no<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # need to check
it or set it.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
wdbg(4,&quot;$func: Returning (b) with STATUS=&quot; . $WikiShVars['STATUS']);<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return($opt['r']
? '1' : '');<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>&nbsp;&nbsp;&nbsp; }<o:p></o:p></span></font></p>

</div>

</body>

</html>