rejetto forum

modification of function dequote()

Mars · 4 · 4216

0 Members and 1 Guest are viewing this topic.

Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
There is a conflict in the procedure exec_ during the call to dequote, it is not the one of utilib.pas which is executed but that of main.pas with them MARKER_QUOTE.

I suggest you to rename the 'dequote' in main.pas by  'macrodequote' and move it at same place of 'macroquote'

you have to change all calls to 'dequote'  in procedure 'cbmacros'  by the 'macrodequote' excepted in the procedure exec_()

After that, there will not be possible confusion anymore

I take advantage of it to add a boolean function

Quote
function isAnyMacroIn(s:string):boolean; inline;
begin result:=pos(MARKER_OPEN, s) > 0 end;

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
begin
  s:=trim(s);
  result:=ansiStartsStr(MARKER_QUOTE, s) and ansiEndsStr(MARKER_UNQUOTE, s);
end;


function macroQuote(s:string):string;
var
  t: string;
begin
if not anyMacroMarkerIn(s) then
  begin
  result:=s;
  exit;
  end;
// an UNQUOTE would invalidate our quoting, so let's encode any of it
t:=MARKER_UNQUOTE;
replace(t, '&#'+intToStr(charToUnicode(t[1]))+';', 1,1);
result:=MARKER_QUOTE+xtpl(s, [MARKER_UNQUOTE, t])+MARKER_UNQUOTE
end; // macroQuote

function macrodequote(s:string):string;  //moved from dequote
begin
result:=s;
s:=trim(s);
if ansiStartsStr(MARKER_QUOTE, s) and ansiEndsStr(MARKER_UNQUOTE, s) then
  result:=copy(s, length(MARKER_QUOTE)+1, length(s)-length(MARKER_QUOTE)-length(MARKER_UNQUOTE) );
end; // macrodequote


function loadDescriptionFile(fn:string):string;
begin
result:=loadFile(fn);
if result = '' then
  result:=loadFile(fn+'\descript.ion');
if (result > '') and mainfrm.oemForIonChk.checked then
  OEMToCharBuff(@result[1], @result[1], length(result));
end; // loadDescription

Le premier qui me demande à quoi cela va servir, il n'a qu'à attendre la sortie de la build 240, c'est en rapport avec la macro 'no pipe'. Rejetto, j'espère que tu te montreras assez curieux pour me contacter: le problème du | est résolu et fonctionnel :D


j'allais oublier une dernière modification à main.pas.
Quote
    if name = 'add to log' then
      begin
      try mainfrm.add2log(macrodequote(p), md.cd, stringToColor(par(1,'color')) );
      except mainfrm.add2log(macrodequote(p), md.cd) end;
      result:='';
      end;

then  {.add to log|{:{.one macro.}:}.}   add      '{.one macro.}'   to the log  and not '{:{.one macro.}:}' or the reuslt of '{.one macro.}'  if you ommit the macroquote.


The second solution, the simplest but remaining ambigue
Quote
  procedure exec_();
  var
    s: string;
  begin
  s:=utilLib.dequote(par(1));     //marsmars
  if fileOrDirExists(s) then
    s:=quoteIfAnyChar(' ', s);
  try
    setVar(parEx('out'), captureExec(utilLib.dequote(p)+' '+s));      //marsmars
    spaceIf(TRUE);
  except spaceIf(exec(utilLib.dequote(p), s)) end;      //marsmars
  end; // exec_
« Last Edit: May 21, 2009, 10:20:31 PM by mars »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
i accept and apply the suggestion about dequote(),
but exec_() was actually meant to call macroDequote, and not utilLib.dequote()
it was a trick to let you use the pipe, because it is useful at command line. ;)

why you need to macrodequote on addToLog ?
who needs to log macros? :)


i'm interested in your suggestion to solve the pipe problem. sadly i have very little time these days :(.
write me an email if you like.

i have an idea that i don't know if it will be a problem: to automatically macroDequote all parameters.
i didn't test yet. maybe it's a crap with very bad side-effects, like my previous idea for \p :D. i don't know yet.
« Last Edit: May 21, 2009, 10:24:03 PM by rejetto »


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
tu veux vraiment te faire tirer les oreilles
 ;D
If you want to add the expression of a macro in 'add to log' without this is estimated, you are obliged to frame it between two marker_quote but these appear in the log, regrettably.

To add dequote() in 'add to log' allows to choose between the result or the expression of the macro

all the question is here! ;)

tu devrais t'intéresser en priorité à ce post
http://www.rejetto.com/forum/index.php?topic=7012.0

is not \p used as page jump, as \f to form feed?
« Last Edit: May 21, 2009, 10:32:42 PM by mars »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
i wonder if i can do something like this

    for i:=0 to pars.count-1 do
      pars[ i]:=macroDequote(pars[ i]);

it may be a nice or terrible thing, i don't know :D