home *** CD-ROM | disk | FTP | other *** search
- /************************************************************
-
- SmartQuotes.c
-
- Preditor 3.0 extension.
-
- Replace quotes with smart quotes appropriately.
-
- © Copyright Evatac Software 1988-1995
- All rights reserved
-
- ************************************************************/
-
- #include "PreditorExtension.h"
-
- #include <SetupA4.h>
- #ifndef THINKC
- #include <A4Stuff.h>
- #else
- #define SetCurrentA4() 0; RememberA4()
- #define SetA4(x) SetUpA4()
- #endif
-
- #ifdef powerc
- ProcInfoType __procinfo = ExtensionUPPInfo;
- #endif
-
- static Boolean startNewQuote[256];
-
- /*
- * quoteInitStarts
- */
- static void quoteInitStarts(void)
- {
- short i;
-
- for (i = 0; i < 256; i++)
- startNewQuote[i] = false;
-
- startNewQuote[' '] = true;
- startNewQuote['('] = true;
- startNewQuote['{'] = true;
- startNewQuote['['] = true;
- startNewQuote['\t'] = true;
- startNewQuote['\r'] = true;
- startNewQuote[0xca] = true;
- startNewQuote[0xd2] = true;
- startNewQuote[0xd4] = true;
- }
-
- void main(
- ExternalCallbackBlock *callbacks,
- WindowRef window
- )
- {
- long saved_a4;
- Handle h;
- long i, len;
- Boolean changed = FALSE;
- unsigned char wasc, c, prevc;
-
- saved_a4 = SetCurrentA4();
-
- quoteInitStarts();
-
- extScanContents(callbacks, 0);
-
- len = extCharacterCount(callbacks);
-
- #ifdef DO_PROGRESS
- extStartProgress(callbacks, (char *) "\pConverting Quotes...", len, true);
- #endif
-
- for (i=0; i<len; i++) {
-
- #ifdef DO_PROGRESS
- if (extDoProgress(callbacks, i+1))
- break;
- #endif
-
- if (!extNextScanCharacter(callbacks, &c))
- break;
-
- wasc = c;
-
- if ((i == 0) || startNewQuote[prevc])
- {
- if (c == '"')
- c = '“';
- else if (c == '\'')
- c = '‘';
- }
- else
- {
- if (c == '"')
- c = '”';
- else if (c == '\'')
- c = '’';
- }
-
- if (c != wasc)
- {
- extSetSelection(callbacks, i, i+1);
- extInsert(callbacks, &c, 1);
- }
-
- prevc = c;
- }
-
- extDoneScan(callbacks);
-
- /*
- * Note: undo is handled automatically, since we want to
- * consider all quote replacements as "one" operation.
- */
-
- #ifdef DO_PROGRESS
- extDoneProgress(callbacks);
- #endif
-
- SetA4(saved_a4);
- }
-