At 9:41 am -0500 19/03/01, Ronald J Kimball wrote:

>I did provide sample code, in an earlier response to Alan.  The correct and
>robust approach is to start at the beginning of the string and process the
>sections in order.

(I had some difficulty getting that to work and revised it using 
'substr', which is not nearly so elegant but was a bit easier to 
debug.)

This takes that approach and works (up to a point):

#!perl
use Mac::LowMem;

$lmh = LMGetScrapHandle;
$str = $lmh->get;

# diagnostics...
     #print "$str\n\n";
     #@l = split(//, $str);
     #foreach (@l) {print ord($_), '|'}; print "\n\n";

while(length $str) {
     $key = substr($str, 0, 4);
         print $key, "/";
     $num   = substr($str, 4, 4);
     $len = unpack("L", $num);
         print "$len\n";
         print substr($str, 8, $len), "\n";
     $str = substr($str, 8+$len);
        #print $str, "\n";
}

However there is a nasty bug.

If the selected text ends on a boundary (a space or a newline) an 
arbitrary character (sometimes 0, sometimes 13, sometimes something 
strange) gets added to the end of the string but is _not_ included in 
the 'TEXT' count. Everything else that follows is then 'one out'.

So far as I can see it is a bug in LowMem. That being so and bearing in mind:

At 12:45 pm -0800 18/03/01, John W Baxter wrote:
>5.  The various LM... things related to the System Scrap are not supported
>in Carbon...the Carbon spec says to use the Scrap Manager APIs instead.
>Therefore, instead of LMGetScrapHandle one should use InfoScrap, for
>instance.

it seems we should not use LMGetScrapHandle.

For the time being at least, since the Scrap Manager API's are not 
ported to MacPerl, the only other option seems to be AppleScript.

The AppleEvent script I posted this morning seems to work pretty fast 
and presumably AppleScript works in conjunction with the Scrap 
Manager and is aware of all the pitfalls (?). For now that seems to 
be the way to go I think.

Many thanks to Bart, Ronald and John Baxter for their very 
interesting, informative and helpful contributions.

Alan Fry

Reply via email to