home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / gnurx.zip / rx / rxbasic.c < prev    next >
C/C++ Source or Header  |  1995-12-31  |  3KB  |  110 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 "rxbasic.h"
  29. #include "rxunfa.h"
  30. #include "rxstr.h"
  31.  
  32.  
  33.  
  34.  
  35. int rx_basic_unfaniverse_delay = 64;
  36. struct rx_unfaniverse * rx_basic_uv = 0;
  37.  
  38.  
  39.  
  40. static int
  41. init_basic_once ()
  42. {
  43.   if (rx_basic_uv)
  44.     return 0;
  45.   rx_basic_uv = rx_make_unfaniverse (rx_basic_unfaniverse_delay);
  46.   return (rx_basic_uv ? 0 : -1);
  47. }
  48.  
  49.  
  50. static char * silly_hack = 0;
  51.  
  52. #ifdef __STDC__
  53. struct rx_solutions *
  54. rx_basic_make_solutions (struct rx_registers * regs,
  55.              struct rexp_node * expression,
  56.              struct rexp_node ** subexps,
  57.              int start, int end,
  58.              struct rx_context_rules * rules,
  59.              char * str)
  60. #else
  61. struct rx_solutions *
  62. rx_basic_make_solutions (regs, rexp, subexps, start, end, rules, str)
  63.      struct rx_registers * regs;
  64.      struct rexp_node * expression;
  65.      struct rexp_node ** subexps;
  66.      int start;
  67.      int end;
  68.      struct rx_context_rules * rules;
  69.      char * str;
  70. #endif
  71. {
  72.   struct rx_str_closure * closure;
  73.   if (init_basic_once ())
  74.     return 0;
  75.   if (silly_hack)
  76.     {
  77.       closure = (struct rx_str_closure *)silly_hack;
  78.       silly_hack = 0;
  79.     }
  80.   else
  81.     closure = (struct rx_str_closure *)malloc (sizeof (*closure));
  82.   if (!closure)
  83.     return 0;
  84.   closure->str = str;
  85.   closure->len = end;
  86.   closure->rules = *rules;
  87.   return rx_make_solutions (regs, rx_basic_uv, expression, subexps, 256,
  88.                 start, end, rx_str_vmfn, rx_str_contextfn,
  89.                 (void *)closure);
  90. }
  91.  
  92.  
  93.  
  94. #ifdef __STDC__
  95. void
  96. rx_basic_free_solutions (struct rx_solutions * solns)
  97. #else
  98.      void
  99.      rx_basic_free_solutions (solns)
  100.      struct rx_solutions * solns;
  101. #endif
  102. {
  103.   if (!silly_hack)
  104.     silly_hack = (char *)solns->closure;
  105.   else
  106.     free (solns->closure);
  107.   solns->closure = 0;
  108.   rx_free_solutions (solns);
  109. }
  110.