home *** CD-ROM | disk | FTP | other *** search
- #include "IAExtractorExports.h"
-
- #include <string.h>
- #include <ctype.h>
-
- enum {kInText, kInTag};
-
- struct OpaqueIADocRef
- {
- // pointer to document accessor functions:
- // open, close, read, ...
- IADocAccessorPtr docAccessorPtr;
-
- // additional per-document info ...
- int scanState;
- };
-
- /* globals */
-
- IAAllocUPP gAllocProc = NULL;
- IAFreeUPP gFreeProc = NULL;
- IAIdleUPP gIdleProc = NULL;
-
-
- /* Implemented functions */
-
- IAResult IAPluginInit(IAPluginInitBlockPtr initBlock, IAPluginRef* outPluginRef)
- {
- /* get alloc, free, and idle procs */
- gAllocProc = initBlock->Alloc;
- gFreeProc = initBlock->Free;
- gIdleProc = initBlock->Idle;
-
- *outPluginRef = 0;
- return errIANoErr;
- }
-
- IAResult IAPluginTerm(IAPluginRef inPluginRef)
- {
- return errIANoErr;
- }
-
- IAResult IAGetExtractorVersion(IAPluginRef inPluginRef, UInt32* outPluginVersion)
- {
- *outPluginVersion = kIAExtractorVersion1;
- return errIANoErr;
- }
-
- IAResult IACountSupportedDocTypes(IAPluginRef inPluginRef, UInt32* outCount)
- {
- *outCount = 1;
- return errIANoErr;
- }
-
- IAResult IAGetIndSupportedDocType(IAPluginRef inPluginRef, UInt32 inIndex, char** outMIMEType)
- {
- if (inIndex != 1)
- return errIAParamErr;
-
- *outMIMEType = "x-text/demo";
- return errIANoErr;
- }
-
- IAResult IAOpenDocument(IAPluginRef inPluginRef, IADocAccessorPtr inAccessorPtr, IADocRef* outDoc)
- {
- IADocRef docRef =
- (IADocRef)CallIAAllocProc(gAllocProc, sizeof(*docRef));
-
- docRef->docAccessorPtr = inAccessorPtr;
- docRef->scanState = kInText;
-
- CallIADocumentAccessorOpen(inAccessorPtr);
-
- *outDoc = docRef;
- return errIANoErr;
- }
-
- IAResult IACloseDocument(IADocRef inDocRef)
- {
- CallIADocumentAccessorClose(inDocRef->docAccessorPtr);
- CallIAFreeProc(gFreeProc, inDocRef);
-
- return errIANoErr;
- }
-
- static void MyRemoveTagsFromBuffer(int* scanState, void* ioBuffer, UInt32* ioBufferSize)
- {
- char* r; char* w; char* re = ((char*)ioBuffer) + *ioBufferSize;
- for(r = w = (char*)ioBuffer; r < re; ++r) {
- switch (*r) {
- case '<': *scanState = kInTag; break;
- case '>': *scanState = kInText; break;
- default: if (*scanState == kInText) { *w++ = *r; }
- }
- }
- *ioBufferSize = (w - ioBuffer);
- }
-
- IAResult IAGetNextTextRun(IADocRef inDocRef, void* outBuffer, UInt32* ioBufferSize)
- {
- CallIADocumentAccessorRead(inDocRef->docAccessorPtr, outBuffer, ioBufferSize);
- MyRemoveTagsFromBuffer(&inDocRef->scanState, outBuffer, ioBufferSize);
- return errIANoErr;
- }
-
- IAResult IAGetTextRunInfo(IADocRef inDocRef, char** outEncoding, char** outLanguage)
- {
- *outEncoding = "x-mac-roman";
- *outLanguage = NULL;
- return errIANoErr;
- }
-