home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Demos / Evatac Software / Preditor 3.0 / Tools / Extension Module Builder / Examples / Rotate 13 / Rotate13.c next >
Encoding:
C/C++ Source or Header  |  1995-08-28  |  1.1 KB  |  63 lines  |  [TEXT/TCEd]

  1. /************************************************************
  2.  
  3.     Rotate13.c
  4.     
  5.     Preditor 3.0 extension.
  6.     
  7.     Perform the Rot-13 operation on the selected text.
  8.  
  9.     © Copyright Evatac Software  1988-1995
  10.     All rights reserved
  11.  
  12. ************************************************************/
  13.  
  14. #include "PreditorExtension.h"
  15.  
  16. #include <SetupA4.h>
  17. #ifndef THINKC
  18. #include <A4Stuff.h>
  19. #else
  20. #define SetCurrentA4()    0; RememberA4()
  21. #define SetA4(x)        SetUpA4()
  22. #endif
  23.  
  24. #ifdef powerc
  25. ProcInfoType __procinfo = ExtensionUPPInfo;
  26. #endif
  27.  
  28. void main(
  29.     ExternalCallbackBlock        *callbacks,
  30.     WindowRef                    window
  31.     )
  32. {
  33.     long             saved_a4;
  34.     Handle            hdl;
  35.     unsigned char    *ptr;
  36.     long            length;
  37.  
  38.     saved_a4 = SetCurrentA4();
  39.     
  40.     if ((hdl = extCopy(callbacks)) != nil) {
  41.  
  42.         length = GetHandleSize(hdl);
  43.     
  44.         ptr = (unsigned char *) *hdl;
  45.  
  46.         while (length-- > 0) {
  47.  
  48.             if (*ptr >= 'A' && *ptr <= 'Z')
  49.                 *ptr = ((*ptr - 'A' + 13) % 26) + 'A';
  50.             else if (*ptr >= 'a' && *ptr <= 'z')
  51.                 *ptr = ((*ptr - 'a' + 13) % 26) + 'a';
  52.             
  53.             ptr++;
  54.         }
  55.     }
  56.  
  57.     extPaste(callbacks, hdl);
  58.     
  59.     DisposeHandle(hdl);
  60.  
  61.     SetA4(saved_a4);
  62. }
  63.