[WASTE-list] Checking text files for styles

Marco Piovanelli marco.piovanelli at pobox.com
Sat Jul 1 03:35:55 EDT 2006


On Fri, 30 Jun 2006 12:09:26 -0500,
Terry (maillst at aol.com) wrote:



>I'm using WELoad to read a text file into a waste text box. I would

>also like to know if the file had any style information in it. I'm

>thinking I could set the style in the waste box, then see if the style

>changed after WELoad. That's pretty hackish, isn't it?


I think this is actually a promising approach.

You could apply a custom style to the empty document, and see
whether it's still around after WELoad(). If WELoad() applies
any style information (whether from RTF or from any styles
resources), the custom attribute will be wiped away as a side
effect.

Here's how you could code this:

Boolean foob = true;
Boolean isStyledFile = false;

// register a custom attribute
err = WERegisterCustomAttribute('foob', 0, sizeof(foob), typeBoolean, myWE);

// apply it
err = WESetOneAttribute(0, 0x7fffffff, 'foob', &foob, sizeof(foob), myWE);

// load the file
err = WELoad(0, 0, fileRef, 0, 0, 0, myWE);

// check to see if our custom style is still present
isStyledFile = (WEGetOneAttribute(0, 'foob', &foob, sizeof(foob),
myWE) != noErr);


>Alternatively, I could check if it's RTF by the extension and file type,


WELoad() will recognize an RTF file by sniffing its first few bytes,
even if it doesn't have an .rtf extension or an 'RTF ' file type.

Also, if you pass a pointer to an OSType variable initialized to '****'
(typeWildCard) in the fourth parameter to WELoad(), it will be set
to whatever file type is detected by WELoad() (RTF, TEXT, utxt, etc.)


>and also check for any old style resources. I'm not sure that covers it.


Checking for known resource types (styl, WEst, etc.) may work now,
but it may not be enough in the future, if WELoad is updated to
deal with additional rich formats like MS Word.


-- marco

--
It's not the data universe only, it's human conversation.
They want to turn it into a one-way flow that they have entirely
monetized. I look at the collective human mind as a kind of
ecosystem. They want to clear cut it. They want to go into the
rainforest of human thought and mow the thing down.



More information about the WASTE-list mailing list