rejetto forum

The continuation of the subject on : BUG in build 239

Mars · 14 · 3851

0 Members and 1 Guest are viewing this topic.

Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2039
    • View Profile
Original post on this matter...

Quote
:D CENSURED :D

this was to make it possible to use pipe characters.
i disabled automatic updates while i find a solution.
this is not just a bug, it must be redesigned. it will take time.

Here is what I set up

1) parser.lib :      when found '%|%' , this exclude it as a valid MARKER_SEP
Quote
  procedure handleMacros();
    .....
    o:=0;
    q:=posEx(MARKER_QUOTE, fullMacro); // q points to _QUOTE
      repeat
      o:=posEx(MARKER_SEP, fullmacro, o+1);
      if o = 0 then break;
{start add by mars}  // when found '%|%' , this exclude it as a valid MARKER_SEP
      if (o>1) and (o<length(fullmacro)) then
        if (fullmacro[o]='|') and (fullmacro[o-1]='%')and (fullmacro[o+1]='%')then
           begin
           o:=o+1;
           continue;
           end;

{end add by mars}
      if (q > 0) and (q < o) then // this SEP is possibly quoted
        begin
        // update 'q' and 'u'
          repeat
          u:=posEx(MARKER_UNQUOTE, fullMacro, q);
.......   

2) main.pas
Quote
function noMacrosAllowed(s:string):string; inline;
begin result:=if_(not isAnyMacroIn(s), s) end; // prevent hack attempts

function macroQuoted(s:string):boolean;    //add by mars (necessary here)
begin
  s:=trim(s);
  result:=ansiStartsStr(MARKER_QUOTE, s) and ansiEndsStr(MARKER_UNQUOTE, s);
end;

function macroQuote(s:string):string;
var
  t: string;

..............

 end; // handleSymbol

//add by mars
  function replacepipe( src:string; old:string; new: string; macroTalk: boolean = false):string;
    var s: string;

    function oldInNew(t:string):string;
    var
       m:string;
       j:integer;
    begin
    if pos(old,new)=0 then
      result:=xtpl(t, [old , new])
    else
      repeat  // if 'old' is a substring of 'new' we don't substitute  'old' when we found 'new'
      j:=pos(new,t);
      m:=chop(new,t);  //we preserve the MARKER_QUOTE
      result:=result + xtpl(m, [old , new]) + if_(j>0,new,'');  //we preserve the 'new' string
      until src=''
    end; 

  begin
  if pos(old,src) > 0 then
    begin
    result:='';
    if not macrotalk then  //if talker is a macro then replace all pipe
      repeat       //we never replace the 'old' by 'new' into a quoted text {: text :} without a dequote
        s:=chop(pos('{:',src),0,src);  //we preserve the MARKER_QUOTE
        result:=result + oldInNew(s) + chop(pos(':}',src),0,src);  //we preserve the MARKER_UNQUOTE
      until src=''
      else result:=oldInNew(src);
    end
  else result:=src;   // no change needed
  end;
//replace pipe

var
  i64: int64;
  i: integer;
  r: Tdatetime;
  s: string;

.......

    // eventually remove trailing
    if pars.Count > 0 then
      begin
      p:=pars[pars.count-1];
      if ansiEndsText('/'+name, p) then
        begin
        setLength(p, length(p)-length(name)-1);
        pars[pars.count-1]:=p;
        end;
      end;

   if not(name = 'no pipe') and not(name = 'add to log') then    //add by mars
     for i := 0 to pars.count-1 do
       if not macroquoted(pars[ i ]) then pars[ i ]:=replacePipe(pars[ i ],'%|%','|');   //mod by mars

    // handle aliases

    if assigned(md.aliases) then

......

    if pars.Count < 1 then exit; // from here, only macros with parameters

    if name = 'no pipe' then
      result:=replacepipe(substr(fullMacro, '|'), '|', '%|%', TRUE);         //mod by mars

    if name = 'add to log' then
      begin
      try mainfrm.add2log(dequote(p), md.cd, stringToColor(par(1,'color')) );   //mod by mars
      except mainfrm.add2log(dequote(p), md.cd) end;        //mod by mars
      result:='';
      end;
........

 if name = 'delete' then
      spaceIf(moveToBin(uri2diskMaybe(p), isTrue(par('forced'))));      //mod by mars

......
if name = 'rename' then
      spaceIf(renameFile(uri2diskMaybe(p), uri2diskMaybeFolder(par(1)))); //mod by mars


    if name = 'move' then
      spaceIf(movefile(uri2diskMaybe(p), uri2diskMaybeFolder(par(1))));   //mod by mars


    if name = 'copy' then
      spaceIf(copyfile(uri2diskMaybe(p), uri2diskMaybeFolder(par(1))));   //mod by mars

one diff tpl and his result
Quote
<html>
{.add to log| 1) {.no pipe| this | must | works.}      pipe | is changed to %|%, but %|% not changed to %%|%%.}
{.add to log|{:2) {.no pipe| this | must | works.}    no change when quoted:}.}
{.add to log|3) %|% this %|% must %|% works      not converted in add to log.}
</html>



1)  this %|% must %|% works            pipe | is changed to %|%, but %|% not changed to %%|%%
2) {.no pipe| this | must | works.}      no change when 'quoted in add to log'
3) %|% this %|% must %|% works     not converted by 'add to log'



All the modifications are to be taken without correction, otherwise unwanted effects could appear in templates ;)
« Last Edit: May 21, 2009, 05:14:50 PM by mars »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13309
    • View Profile
{.if|%user%|%user% is king|you are nothing.}

will this work with your change?


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2039
    • View Profile
Après avoir longuement refléchi au sens caché de ta question  ;), j'ai fait un petit test avec ma version et tu ne pourras pas faire autrement que d'accepter toutes mes propositions , car la réponse est, malheureusement pour toi: yes avec un grand OOOUUUIIIIIIII :D


PLEASE Rejetto , do not make any change in my code , it works perfectly and has some possibility for the feature, thanks!
« Last Edit: May 21, 2009, 11:06:12 PM by mars »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13309
    • View Profile
in the while i had another idea
to use {:|:} instead of \p

Code: [Select]
    for i:=0 to pars.count-1 do
      pars[i]:=xtpl(pars[i], ['{:|:}','|']);
...
    if name = 'no pipe' then
      result:=xtpl(substr(fullMacro, '|'), ['|','{:|:}']);

very very simple solution.
on the bad side {:|:} is much uglier and awkward syntax than yours %|%

i downloaded latest SP french version with no luck.
i tried testing this script. maybe it's me. can you test it?

[request]
{.add to log|{.if|%user%|%user% is k%|%ng|you are nothing.}.}


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13309
    • View Profile
this works with my solution

[request]
{.add to log|{.no pipe|{.if|%user%|%user% is k{:|:}ng|anonymous.}.}.}


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2039
    • View Profile
espèce de petit gamin , si tu cherches la vilaine bête, tu vas me trouver. ;D

ce soir il est trop tard pour faire fonctionner mes neurones et en plus je n'ai pas accès à delphi (not at home), alors je vais devoir trouver une parade en y réfléchissant sans pouvoir faire des essais :-[

have a good night

je t'attends au virage pour voir ta solution et savoir si elle passera le cap de mes tests ;D

HAHA ;)


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13309
    • View Profile
haha :D
see you later

...all started because i wanted to be possible to make scripts like this
http://www.rejetto.com/forum/index.php?topic=6757.msg1043503#msg1043503
« Last Edit: May 21, 2009, 11:44:37 PM by rejetto »


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2039
    • View Profile
with build 240:

Quote
je t'attends au virage pour voir ta solution et savoir si elle passera le cap de mes tests

can you test this macro and decribe what append??

{set|macroreplace|{:{.add to log|{.no pipe|{.if|%user%|%user% is k{:|:}ng|anonymous.}.}:}.}

macroreplace become {.add to log|{.no pipe|{.if|%user%|%user% is k|ng|anonymous.}.} :'(

call {.^macroreplace.} then in the log you can see 'rejetto is k' or 'ng'  but not rejetto is k|ng  or anonymous

I know, I know: SHIT! :D

we have to replace the {:|:} in par[ i] only when he is out of internal macro , i must modify my last code to update the best solution. certainly i make talk to you for certain update ;)

« Last Edit: May 25, 2009, 07:28:30 PM by mars »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13309
    • View Profile
i lost more time fixing the wrong number of parenthesis than finding a solution to this :)
to delay the replacing of pipes use {.no pipe||.} instead of {:|:}

{.set|macroreplace|{:{.add to log|{.no pipe|{.if|%user%|%user% is k{.no pipe||.}ng|anonymous.}.}.}:}.}


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2039
    • View Profile
come back in previous post

about {:|:}, something was not clear.

a simple test with

[+upload-success]
{.if|true|{:{.if|true|{:{.add to log|done{:|:}clred|clgreen.}:}.}:}.}

It looked  done Instead of done|clred

macro log:
Quote
> if|true|{:{.if|true|{:{.add to log|done{:|:}clred|clgreen.}:}.}:}
 < {.if|true|{:{.add to log|done|clred|clgreen.}:}.}                                 <<---- the error begin here

 > if|true|{:{.add to log|done|clred|clgreen.}:}          
 < {.add to log|done|clred|clgreen.}

 > add to log|done|clred|clgreen
 <

 main.pas
Quote
function noMacrosAllowed(s:string):string; inline;
begin result:=if_(not isAnyMacroIn(s), s) end; // prevent hack attempts

function macroQuoted(s:string):boolean;    //add by mars (necessary here)
begin
  s:=trim(s);
  result:=ansiStartsStr(MARKER_QUOTE, s) and ansiEndsStr(MARKER_UNQUOTE, s);
end;


function macroQuote(s:string):string;
var
  t: string;

..............

    unnamedPars:=0;
    for i:=0 to pars.count-1 do
      begin
      if not macroquoted(pars[i]) then pars[i]:=xtpl(pars[i], ['{:|:}','|']);    
      if (i = unnamedPars) and (pos('=',pars[i]) = 0) then
        inc(unnamedPars);
      end;

new macro log
Quote
   > if|true|{:{.if|true|{:{.add to log|done{:|:}clred|clgreen.}:}.}:}
   < {.if|true|{:{.add to log|done{:|:}clred|clgreen.}:}.}

   > if|true|{:{.add to log|done{:|:}clred|clgreen.}:}
   < {.add to log|done{:|:}clred|clgreen.}

   > add to log|done{:|:}clred|clgreen                         <<<----- here all is correct
   <

this work perfectly in the template
Quote
{.set|macroreplace|{:{.add to log|{.no pipe|{.if|%user%|%user% is k{:|:}ng|anonymous.}.}.}:}.}
 or
{.set|macroreplace|{:{.add to log|{.if|%user%|{:%user% is k{:|:}ng:}|anonymous.}.}:}.}

with
{.^macroreplace.}



the last test
Quote
[request completed]
{.add to log|{.if|%user%|{:%user% is k{:|:}ng:}|you are nothing.}.}

A last small detail which has all its importance:
In this example, we do not want to estimate {.comment|example.}, but just to show it in the log

{.add to log|{:{.comment|example.}:}.}   give in the log {:{.comment|example.}:}  ,  It is not beautiful

Quote
   if name = 'add to log' then
      begin
      mainfrm.add2log(macrodequote(p), md.cd, stringToColorEx(par(1,'color'), clDefault));
      result:='';
      end;
{.add to log|{:{.comment|example.}:}.}   give in the log {.comment|example.}  ,  It is like that better without marker_quote

Here is of what to fill a new version.  ;)

« Last Edit: June 26, 2009, 09:11:24 AM by Mars »


Offline bacter

  • Operator
  • Tireless poster
  • *****
    • Posts: 681
    • View Profile
I fear you may throw stones, tomatoes and rotten eggs to me ...  ;)

but i understand that the actual macro-interpreter works from inner to outer more for historical than logical reasons. (Macro is grown to something much better and bigger than initial previsions were made). :)

So, seeing the problems that arise using this method, with the need of quoting and dequoting, i wonder if it would not be much simpler, to use a recursive left to right, outer to inner interpreter, who would make needless all that quote aud dequote. This would not present any compatibility problems with existing macros, as we can simply ignore {: . The algoritm to do this, is not to difficult, and perhaps the effort to change the interpreter would save a lot of time as macro is growing.

This would also simplify the use of special caracters with some \\, \n \#ad secuences, as this replacement is always the last step solving an expression.
your computer has no brain - use your own !


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2039
    • View Profile
 Effectively, I have just placed several orders, and in triplicate, you are deserving and still I am kind on the quantities. Pebbles arrive, as for eggs and for tommates they will have a little of delay because of lack of maturity .


Quote
This would also simplify the use of special caracters with some \\, \n \#ad secuences, as this replacement is always the last step solving an expression.


I do not make hfs, I am only following and adapting myself to needs.

My answer will be a big  NO  :D. We do not can use what what you propose because it is the syntax appropriate for UNIX, that  the character \ meets itself in files path, thus much more difficult to manage.

All these bothers will come to an end with the integration of the php in hfs. by waiting it will be necessary to wait. ;)
« Last Edit: June 26, 2009, 09:12:39 AM by Mars »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13309
    • View Profile
{.if|true|{:{.if|true|{:{.add to log|done{:|:}clred|clgreen.}:}.}:}.}

It looked  done Instead of done|clred

right, because the proper way to get this is
{.if|true|{:{.if|true|{:{.add to log|done{.no pipe||.}clred|clgreen.}:}.}:}.}

it works here!


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13309
    • View Profile
@bacter
i don't think the problem is inner-to-outer. All programming languages i know are. But their grammar is not just {..} and {::}. I have no other control structures, all is a command, even IF and WHILE. There's a parser, calling a command executor (just one command at time).
I don't see a way to get your suggestion real without changing the whole thing, mixing parser and executor to get control structures.