[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Resource Fork



At 19:20 12/11/99 -0600, you wrote:

here is a bit of code:

sub ::ResToText
#
# given a filename,rtype,id return the text resource
# in an array of string
{
         local($file,$rtype,$id)=@_;
         local ($RFD,$perlRFD,$temp,$a);
         local($tempstr,$i,$j,$a,@b,@c);
         $perlRFD = CurResFile();
         if ( defined OpenResFile($file) )
         {
                 $RFD = CurResFile();
                 $temp = Get1Resource($rtype,$id);
                 if (!defined $temp) { die "OOOOOOOOPPS : error!!\n";}
                 $a = $temp->get;
                 dispose $temp;
                 CloseResFile($RFD);
                 UseResFile $perlRFD;
         }
         else
         {
                 print "no res in file $file READING\n";
         }

         @b = split(//,$a);
         $numstring = $b[1];
         for ($i=2 ; $i<=length($a) ; $i++)
         {
                 $lenstr = ord($b[$i]);
                 $tempstr = "";
                 for ($j = ($i+1) ; $j<=($lenstr+$i) ; $j++)
                 {
                         $tempstr = $tempstr.$b[$j];
                 }
                 $i=$j-1;
                 @c = (@c,$tempstr);
         }
         @c;
}
sub ::TextToRes
#
# given a filename,rtype,id, and text
# write the text as a rtype/id in filename rsc
{
         local($file,$rtype,$rid,@res)=@_;
         local ($perlRFD,$RFD,$id,$name,$type,$temp1,$temp2,$a);
         $perlRFD = CurResFile();
         $a = $#res;
         $a = chr($a);
         $a = chr(0).$a;
         foreach $r (@res)
         {
                 $a=$a.chr(length($r)).$r;
         }
         chop($a);

         if ( defined OpenResFile($file) )
         {
                 $RFD = CurResFile();
                 $temp2 = Get1Resource($rtype,$rid);
                 ($id, $type, $name) = GetResInfo($temp2);
                 if (!defined $temp2) { print "OOOOOOOOPPS : error!!\n";}
                 RemoveResource($temp2);
                 ReleaseResource($temp2);
                 $temp1 = new Handle($a) || die "bad handle";
                 AddResource($temp1, $type, $id, $name);
                 if ( ChangedResource($temp1) )
                 {
                 WriteResource $temp1;
                 }
                 else
                 {
                 die "Failed to changedResource";
                 }
                 dispose $temp1;
                 CloseResFile $RFD;
                 UseResFile($perlRFD);
         }
         else
         {
         print "no res in file $file \n";
         }
}






>Hi, I need to write a some stuff to the resource fork of some files
>made on a Linux Machine, so they don't really have a resource
>fork. Searching trhought the FAQ, it says that you can use the XFCNs
>of HyperCard, but I haven't found one suitable. Anybody wants to share
>some experiences about doing this? Thanks.
>
>
># ===== Want to unsubscribe from this list?
># ===== Send mail with body "unsubscribe" to macperl-request@macperl.org

Laurent BARDI 	Ingenieur Systemes & Reseaux
Centre National de la Recherche Scientifique
INSTITUT  de PHARMACOLOGIE et de BIOLOGIE STRUCTURALE
Tel : 05-61-17-54-39 		http://www.ipbs.fr/ (internal)
Fax : 05-61-17-59-94		lolo@ipbs.fr
CNRS-IPBS 205 Route de Narbonne 31400 TOULOUSE FRANCE

There is worse than to have not succeded :
Not to have  tried !
If it stinks, it's chemistry. If it moves, it's biology.
If it does not work, It's computer science.
To steal ideas from one person is plagiarism; to
steal from many is research


# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org