home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 October: Mac OS SDK / Dev.CD Oct 00 SDK1.toast / Development Kits / Mac OS / Find By Content (FBC) Extractor / DemoExtractor / DemoExtractor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-08-11  |  2.5 KB  |  112 lines  |  [TEXT/CWIE]

  1. #include "IAExtractorExports.h"
  2.  
  3. #include <string.h>
  4. #include <ctype.h>
  5.  
  6. enum {kInText, kInTag};
  7.  
  8. struct OpaqueIADocRef
  9. {
  10.     // pointer to document accessor functions:
  11.     // open, close, read, ...
  12.     IADocAccessorPtr    docAccessorPtr;
  13.  
  14.     // additional per-document info ...
  15.     int scanState;
  16. };
  17.  
  18. /* globals */
  19.  
  20. IAAllocUPP gAllocProc = NULL;
  21. IAFreeUPP gFreeProc = NULL;
  22. IAIdleUPP gIdleProc = NULL;
  23.  
  24.  
  25. /* Implemented functions */
  26.  
  27. IAResult IAPluginInit(IAPluginInitBlockPtr initBlock, IAPluginRef* outPluginRef)
  28. {
  29.     /* get alloc, free, and idle procs */
  30.     gAllocProc = initBlock->Alloc;
  31.     gFreeProc = initBlock->Free;
  32.     gIdleProc = initBlock->Idle;
  33.  
  34.     *outPluginRef = 0;
  35.     return errIANoErr;
  36. }
  37.  
  38. IAResult IAPluginTerm(IAPluginRef inPluginRef)
  39. {
  40.     return errIANoErr;
  41. }
  42.  
  43. IAResult IAGetExtractorVersion(IAPluginRef inPluginRef, UInt32* outPluginVersion)
  44. {
  45.     *outPluginVersion = kIAExtractorVersion1;
  46.     return errIANoErr;
  47. }
  48.  
  49. IAResult IACountSupportedDocTypes(IAPluginRef inPluginRef, UInt32* outCount)
  50. {
  51.     *outCount = 1;
  52.     return errIANoErr;
  53. }
  54.  
  55. IAResult IAGetIndSupportedDocType(IAPluginRef inPluginRef, UInt32 inIndex, char** outMIMEType)
  56. {
  57.     if (inIndex != 1)
  58.         return errIAParamErr;
  59.  
  60.     *outMIMEType = "x-text/demo";
  61.     return errIANoErr;
  62. }
  63.  
  64. IAResult IAOpenDocument(IAPluginRef inPluginRef, IADocAccessorPtr inAccessorPtr, IADocRef* outDoc)
  65. {
  66.     IADocRef docRef =
  67.         (IADocRef)CallIAAllocProc(gAllocProc, sizeof(*docRef));
  68.  
  69.     docRef->docAccessorPtr = inAccessorPtr;
  70.     docRef->scanState = kInText;
  71.     
  72.     CallIADocumentAccessorOpen(inAccessorPtr);
  73.  
  74.     *outDoc = docRef;
  75.     return errIANoErr;
  76. }
  77.  
  78. IAResult IACloseDocument(IADocRef inDocRef)
  79. {
  80.     CallIADocumentAccessorClose(inDocRef->docAccessorPtr);
  81.     CallIAFreeProc(gFreeProc, inDocRef);
  82.  
  83.     return errIANoErr;
  84. }
  85.  
  86. static void MyRemoveTagsFromBuffer(int* scanState, void* ioBuffer, UInt32* ioBufferSize)
  87. {
  88.     char* r; char* w; char* re = ((char*)ioBuffer) + *ioBufferSize;
  89.     for(r = w = (char*)ioBuffer; r < re; ++r) {
  90.         switch (*r) {
  91.             case '<': *scanState = kInTag; break;
  92.             case '>': *scanState = kInText; break;
  93.             default: if (*scanState == kInText) { *w++ = *r; }
  94.         }
  95.     }
  96.     *ioBufferSize = (w - ioBuffer);
  97. }
  98.  
  99. IAResult IAGetNextTextRun(IADocRef inDocRef, void* outBuffer, UInt32* ioBufferSize)
  100. {
  101.     CallIADocumentAccessorRead(inDocRef->docAccessorPtr, outBuffer, ioBufferSize);
  102.     MyRemoveTagsFromBuffer(&inDocRef->scanState, outBuffer, ioBufferSize);
  103.     return errIANoErr;
  104. }
  105.  
  106. IAResult IAGetTextRunInfo(IADocRef inDocRef, char** outEncoding, char** outLanguage)
  107. {
  108.     *outEncoding = "x-mac-roman";
  109.     *outLanguage = NULL;
  110.     return errIANoErr;
  111. }
  112.