1: #include "../h/rt.h"
   2: 
   3: /*
   4:  * =x - tab(match(x)).
   5:  * Reverses effects if resumed.
   6:  */
   7: 
   8: tabmat(nargs, oldsubj, arg1, arg0)
   9: int nargs;
  10: struct descrip oldsubj, arg1, arg0;
  11:    {
  12:    DclSave
  13:    register int l;
  14:    register char *s1, *s2;
  15:    int i, j;
  16:    char sbuf[MAXSTRING];
  17: 
  18:    SetBound;
  19:    /*
  20:     * x must be a string.
  21:     */
  22:    if (cvstr(&arg1,sbuf) == NULL)
  23:       runerr(103, &arg1);
  24: 
  25:    /*
  26:     * Make a copy of &subject and &pos.
  27:     */
  28:    oldsubj = k_subject;
  29:    i = k_pos;
  30: 
  31:    /*
  32:     * Fail if &subject[&pos:0] is not of sufficient length to contain x.
  33:     */
  34:    j = STRLEN(k_subject) - i + 1;
  35:    if (j < STRLEN(arg1))
  36:       fail();
  37: 
  38:    /*
  39:     * Get pointers to x (s1) and &subject (s2).  Compare them on a bytewise
  40:     *  basis and fail if s1 doesn't match s2 for *s1 characters.
  41:     */
  42:    s1 = STRLOC(arg1);
  43:    s2 = STRLOC(k_subject) + i - 1;
  44:    l = STRLEN(arg1);
  45:    while (l-- > 0) {
  46:       if (*s1++ != *s2++)
  47:          fail();
  48:       }
  49: 
  50:    /*
  51:     * Increment &pos to tab over the matched string and suspend the
  52:     *  matched string.
  53:     */
  54:    l = STRLEN(arg1);
  55:    k_pos += l;
  56:    arg0 = arg1;
  57:    suspend();
  58: 
  59:    /*
  60:     * tabmat has been resumed, restore &subject and &pos and fail.
  61:     */
  62:    k_subject = oldsubj;
  63:    k_pos = i;
  64:    fail();
  65:    }
  66: 
  67: Opblockx(tabmat,2,"=",1)

Defined functions

tabmat defined in line 8; used 1 times
  • in line 67
Last modified: 1984-11-18
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 319
Valid CSS Valid XHTML 1.0 Strict