home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / gnurx.zip / rx / rxstr.c < prev    next >
C/C++ Source or Header  |  1995-12-31  |  3KB  |  137 lines

  1. /***********************************************************
  2.  
  3. Copyright 1995 by Tom Lord
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the name of the copyright holder not be
  12. used in advertising or publicity pertaining to distribution of the
  13. software without specific, written prior permission.  
  14.  
  15. Tom Lord DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  16. INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  17. EVENT SHALL TOM LORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  18. CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  19. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  20. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  21. PERFORMANCE OF THIS SOFTWARE.
  22.  
  23. ******************************************************************/
  24.  
  25.  
  26.  
  27. #include "rxall.h"
  28. #include "rxstr.h"
  29.  
  30.  
  31.  
  32. #ifdef __STDC__
  33. enum rx_answers
  34. rx_str_vmfn (void * closure,
  35.          unsigned char ** burstp,
  36.          int * lenp,
  37.          int * offsetp,
  38.          int start, int end, int need)
  39. #else
  40. enum rx_answers
  41. rx_str_vmfn (closure, burstp, lenp, offsetp, start, end, need)
  42.      void * closure;
  43.      unsigned char ** burstp;
  44.      int * lenp;
  45.      int * offsetp;
  46.      int start;
  47.      int end;
  48.      int need;
  49. #endif
  50. {
  51.   struct rx_str_closure * strc;
  52.   strc = (struct rx_str_closure *)closure;
  53.  
  54.   if (   (need < 0)
  55.       || (need > strc->len))
  56.     return rx_no;
  57.  
  58.   *burstp = strc->str;
  59.   *lenp = strc->len;
  60.   *offsetp = 0;
  61.   return rx_yes;
  62. }
  63.  
  64. #ifdef __STDC__
  65. enum rx_answers
  66. rx_str_contextfn (void * closure,
  67.           int type, int start, int end,
  68.           struct rx_registers * regs)
  69. #else
  70. enum rx_answers
  71. rx_str_contextfn (closure, type, start, end, regs)
  72.      void * closure;
  73.      int type;
  74.      int start;
  75.      int end;
  76.      struct rx_registers * regs;
  77. #endif
  78. {
  79.   struct rx_str_closure * strc;
  80.  
  81.   strc = (struct rx_str_closure *)closure;
  82.   switch (type)
  83.     {
  84.     case '1': case '2': case '3': case '4': case '5':
  85.     case '6': case '7': case '8': case '9':
  86.       {
  87.     int cmp;
  88.     int regn;
  89.     regn = type - '0';
  90.     if (   (regs[regn].rm_so == -1)
  91.         || ((end - start) != (regs[regn].rm_eo - regs[regn].rm_so)))
  92.       return rx_no;
  93.     else
  94.       {
  95.         cmp = strncmp (strc->str + start,
  96.                strc->str + regs[regn].rm_so,
  97.                end - start);
  98.         return (!cmp
  99.             ? rx_yes
  100.             : rx_no);
  101.       }
  102.       }
  103.  
  104.     case '^':
  105.       {
  106.     return ((   (start == end)
  107.          && (   ((start == 0) && !strc->rules.not_bol)
  108.              || (   (start > 0)
  109.              && strc->rules.newline_anchor
  110.              && (strc->str[start - 1] == '\n'))))
  111.         ? rx_yes
  112.         : rx_no);
  113.       }
  114.  
  115.     case '$':
  116.       {
  117.     return ((   (start == end)
  118.          && (   ((start == strc->len) && !strc->rules.not_eol)
  119.              || (   (start < strc->len)
  120.              && strc->rules.newline_anchor
  121.              && (strc->str[start] == '\n'))))
  122.         ? rx_yes
  123.         : rx_no);
  124.       }
  125.  
  126.     case '<':
  127.     case '>':
  128.  
  129.     case 'B':
  130.     case 'b':
  131.  
  132.  
  133.     default:
  134.       return rx_bogus;
  135.     }
  136. }
  137.