regaux.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include "regexp.h"
  4. #include "regcomp.h"
  5. /*
  6. * Machine state
  7. */
  8. Relist* _relist[2];
  9. Relist* _reliste[2];
  10. int _relistsize = LISTINCREMENT;
  11. /*
  12. * save a new match in mp
  13. */
  14. extern void
  15. _renewmatch(Resub *mp, int ms, Resublist *sp)
  16. {
  17. int i;
  18. if(mp==0 || ms<=0)
  19. return;
  20. if(mp[0].s.sp==0 || sp->m[0].s.sp<mp[0].s.sp ||
  21. (sp->m[0].s.sp==mp[0].s.sp && sp->m[0].e.ep>mp[0].e.ep)){
  22. for(i=0; i<ms && i<NSUBEXP; i++)
  23. mp[i] = sp->m[i];
  24. for(; i<ms; i++)
  25. mp[i].s.sp = mp[i].e.ep = 0;
  26. }
  27. }
  28. /*
  29. * Note optimization in _renewthread:
  30. * *lp must be pending when _renewthread called; if *l has been looked
  31. * at already, the optimization is a bug.
  32. */
  33. extern Relist*
  34. _renewthread(Relist *lp, /* _relist to add to */
  35. Reinst *ip, /* instruction to add */
  36. Resublist *sep) /* pointers to subexpressions */
  37. {
  38. Relist *p;
  39. for(p=lp; p->inst; p++){
  40. if(p->inst == ip){
  41. if((sep)->m[0].s.sp < p->se.m[0].s.sp)
  42. p->se = *sep;
  43. return 0;
  44. }
  45. }
  46. p->inst = ip;
  47. p->se = *sep;
  48. (++p)->inst = 0;
  49. return p;
  50. }