confirmCMD revisted (have a problem with literal <CRLF>)

Discuss and share scripts and script files...
Post Reply
MBaas
Posts: 529
Joined: 15 Feb 2016 21:08

confirmCMD revisted (have a problem with literal <CRLF>)

Post by MBaas »

While ago I came up with the confirmCMD macro which has been really useful for me. Now I had an idea: it's a bit tedious when working a file where I modify the command if I have to repeat those changes over and over again. Wouldn't it be nice if the last command that was confirmed would be saved and presented as a default next time I call confirmCMD?

This version does that (well, almost):

Code: Select all

function confirmCMD($ctxt,$cmd) {
    $configfile = resolvepath("%tmp%\" . $ctxt . "\" . gpc(,"base") . ".xy_cmd");
    if (exists($configfile)) {
        $content = readfile($configfile);
        // put last item into $c, the others info $items
        $c = gettoken($content,-1,<CRLF>);
        msg "c=" . $c;
        $items = formatlist($content . <CRLF> . $cmd,"d",<CRLF>);
    } else {
        $c = $cmd;
        $items = "";
        $content = "";
    }
    $c = input("Edit command","",$c,"s","cancel",,,$items);
    end $c == "cancel";
  
    $content = formatlist($content . $c . <CRLF>,"d",<CRLF>);
    writefile($configfile,$content,,"utf8bom");
    return $c;
}
So, this new syntax has two parameters: $ctxt defines a context, it's just a string variable describing what the command does. $cmd is the command. (To save the last command executed, we create file in %tmp% (in a subdir named $ctxt) which has the same base name as the current file.

When I look at that file after writefile (at the end of the macro) was executed, it contains the literal text "<CRLF>" instead of carriage return & linefeed. Why is that happening???
______________________________________________
Happy user ;-)

admin
Site Admin
Posts: 59751
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: confirmCMD revisted (have a problem with literal <CRLF>)

Post by admin »

it's lower case: <crlf>

MBaas
Posts: 529
Joined: 15 Feb 2016 21:08

Re: confirmCMD revisted (have a problem with literal <CRLF>)

Post by MBaas »

:oops: dang

Thanks!
______________________________________________
Happy user ;-)

Post Reply