regaux.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include "regexp.h"
  12. #include "regcomp.h"
  13. /*
  14. * save a new match in mp
  15. */
  16. extern void
  17. _renewmatch(Resub *mp, int ms, Resublist *sp)
  18. {
  19. int i;
  20. if(mp==0 || ms<=0)
  21. return;
  22. if(mp[0].sp==0 || sp->m[0].sp<mp[0].sp ||
  23. (sp->m[0].sp==mp[0].sp && sp->m[0].ep>mp[0].ep)){
  24. for(i=0; i<ms && i<NSUBEXP; i++)
  25. mp[i] = sp->m[i];
  26. for(; i<ms; i++)
  27. mp[i].sp = mp[i].ep = 0;
  28. }
  29. }
  30. /*
  31. * Note optimization in _renewthread:
  32. * *lp must be pending when _renewthread called; if *l has been looked
  33. * at already, the optimization is a bug.
  34. */
  35. extern Relist*
  36. _renewthread(Relist *lp, /* _relist to add to */
  37. Reinst *ip, /* instruction to add */
  38. int ms,
  39. Resublist *sep) /* pointers to subexpressions */
  40. {
  41. Relist *p;
  42. for(p=lp; p->inst; p++){
  43. if(p->inst == ip){
  44. if(sep->m[0].sp < p->se.m[0].sp){
  45. if(ms > 1)
  46. p->se = *sep;
  47. else
  48. p->se.m[0] = sep->m[0];
  49. }
  50. return 0;
  51. }
  52. }
  53. p->inst = ip;
  54. if(ms > 1)
  55. p->se = *sep;
  56. else
  57. p->se.m[0] = sep->m[0];
  58. (++p)->inst = 0;
  59. return p;
  60. }
  61. /*
  62. * same as renewthread, but called with
  63. * initial empty start pointer.
  64. */
  65. extern Relist*
  66. _renewemptythread(Relist *lp, /* _relist to add to */
  67. Reinst *ip, /* instruction to add */
  68. int ms,
  69. char *sp) /* pointers to subexpressions */
  70. {
  71. Relist *p;
  72. for(p=lp; p->inst; p++){
  73. if(p->inst == ip){
  74. if(sp < p->se.m[0].sp) {
  75. if(ms > 1)
  76. memset(&p->se, 0, sizeof(p->se));
  77. p->se.m[0].sp = sp;
  78. }
  79. return 0;
  80. }
  81. }
  82. p->inst = ip;
  83. if(ms > 1)
  84. memset(&p->se, 0, sizeof(p->se));
  85. p->se.m[0].sp = sp;
  86. (++p)->inst = 0;
  87. return p;
  88. }
  89. extern Relist*
  90. _rrenewemptythread(Relist *lp, /* _relist to add to */
  91. Reinst *ip, /* instruction to add */
  92. int ms,
  93. Rune *rsp) /* pointers to subexpressions */
  94. {
  95. Relist *p;
  96. for(p=lp; p->inst; p++){
  97. if(p->inst == ip){
  98. if(rsp < p->se.m[0].rsp) {
  99. if(ms > 1)
  100. memset(&p->se, 0, sizeof(p->se));
  101. p->se.m[0].rsp = rsp;
  102. }
  103. return 0;
  104. }
  105. }
  106. p->inst = ip;
  107. if(ms > 1)
  108. memset(&p->se, 0, sizeof(p->se));
  109. p->se.m[0].rsp = rsp;
  110. (++p)->inst = 0;
  111. return p;
  112. }