home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / DEMO / RIM22 / MACROS / SEARCH.RM < prev    next >
Text File  |  1993-11-16  |  3KB  |  114 lines

  1. /*
  2. ** Macro module: search.rm - search functions
  3. **
  4. ** Copyright (C) 1993 Brian L. Smith
  5. ** Copyright (C) 1993 RimStar Technology, Inc.
  6. ** All rights reserved internationally.
  7. ** Unlicensed use is a violation of applicable laws.
  8. **
  9. ** This source code is provided to licensed users of RimStar's products
  10. ** for the purpose of allowing the user to customize and/or enhance RimStar's
  11. ** products. The source code remains the property of the copyright holders
  12. ** with all rights reserved internationally.
  13. ** Any modifications to the source code are considered derivative works and
  14. ** all rights thereto are reserved to the copyright holders except
  15. ** that the purchaser may use the derivitive work in the same manner
  16. ** as permitted by the license governing the unmodified product.
  17. ** Distribution in any manner of any part of the original source code,
  18. ** whether in source or object form, is expressly prohibited without the
  19. ** express written permission of the copyright holders.
  20. **
  21. */
  22.  
  23. #include "macro.h"
  24.  
  25. /*
  26. ** SearchSel - uses the current selection as a search string
  27. **        to search for the next/prev occurrence.
  28. */
  29. void
  30. SearchSel(int dir) {
  31.     SELECTION p;
  32.     char *string, chr, msg[20];
  33.     SHORT rc, type;
  34.     LONG offset, column, line, i, len;
  35.  
  36.     type = MarkQuerySel( &p );
  37.     if ( type < 1 || type > 4 || ( p.s_line != p.e_line ) ) {
  38.         if ( dir )
  39.             SearchForward();
  40.         else
  41.             SearchBackward();
  42.         return;
  43.     } else {
  44.         MarkEndSel();
  45.         MarkQuerySel( &p, 1 );
  46.         MarkRemoveSel();
  47.         PosAbs( p.s_line, p.s_column );
  48.         offset = BufQueryOffset();
  49.         len = ( p.e_column - p.s_column ) + 1L;
  50.         string = malloc(len+1L);
  51.         for ( i = 0; i < len; i++, offset++ ) {
  52.             chr = BufQueryChar(offset);
  53.             string[i] = chr;
  54.         }
  55.  
  56.         if ( dir ) {
  57.             PosNextChar();
  58.             rc = SrchFwd(string, 0, 1, 0);
  59.         } else {
  60.             PosPrevChar();
  61.             rc = SrchBack(string, 0, 1, 0);
  62.         }
  63.         if ( rc > 0 ) {
  64.             BufQueryPosition( &line, &column );
  65.             p.type = 1;
  66.             p.s_column = column;
  67.             p.s_line = p.e_line = line;
  68.             p.e_column = column + len - 1L;
  69.             MarkCreateSel( &p );
  70.         } else {
  71.             if ( dir )
  72.                 PosPrevChar();
  73.             else
  74.                 PosNextChar();
  75.             PopupMsgBox("Pattern not found", "Information",
  76.                 MB_OK | MB_ICONEXCLAMATION );
  77.         }
  78.         free(string);
  79.     }
  80. } /* end SearchSel() */
  81.  
  82.  
  83.  
  84. void
  85. SelWord() {
  86.     char *str = ",;:'\t {}[]()\n";
  87.  
  88.     while ( strchr(str, (BufQueryChar())) ) {
  89.         if ( PosPrevChar() )
  90.             break;
  91.     }
  92.     
  93.     while ( !strchr(str, (BufQueryChar()))    ) {
  94.         if ( PosPrevChar() )
  95.             break;
  96.     }
  97.     PosNextChar();
  98.     MarkBeginSel();
  99.  
  100.     while ( !strchr(str, (BufQueryChar())) ) {
  101.         if ( PosNextChar() )
  102.             break;
  103.     }
  104.     PosPrevChar();
  105.     MarkEndSel();
  106.  
  107. } /* end SelWord() */
  108.  
  109.  
  110.  
  111. /*
  112. ** End macro: Search.rm
  113. */
  114.