1: #include "../h/rt.h"
   2: 
   3: /*
   4:  * x[i:j] - form a substring or list section of x.
   5:  */
   6: 
   7: sect(nargs, arg1v, arg3, arg2, arg1, arg0)
   8: int nargs;
   9: struct descrip arg1v, arg3, arg2, arg1, arg0;
  10:    {
  11:    register int i, j;
  12:    int t, typ1;
  13:    char sbuf[MAXSTRING];
  14:    long l1, l2;
  15:    extern char *alcstr();
  16: 
  17:    SetBound;
  18:    hneed(sizeof(struct b_tvsubs));              /* check heap */
  19: 
  20:    if (cvint(&arg2, &l1) == NULL)
  21:       runerr(101, &arg2);
  22:    if (cvint(&arg3, &l2) == NULL)
  23:       runerr(101, &arg3);
  24: 
  25:    arg1v = arg1;
  26:    DeRef(arg1)
  27: 
  28:    if (!QUAL(arg1) && TYPE(arg1) == T_LIST) {
  29:       i = cvpos(l1, BLKLOC(arg1)->list.cursize);
  30:       j = cvpos(l2, BLKLOC(arg1)->list.cursize);
  31:       if (i > j) {
  32:          t = i;
  33:          i = j;
  34:          j = t;
  35:          }
  36:       cplist(&arg1, &arg0, i, j);
  37:       ClearBound;
  38:       return;
  39:       }
  40: 
  41:    if ((typ1 = cvstr(&arg1, sbuf)) == NULL)
  42:       runerr(110, &arg1);
  43: 
  44:    i = cvpos(l1, STRLEN(arg1));
  45:    j = cvpos(l2, STRLEN(arg1));
  46:    if (i > j) {             /* convert section to substring */
  47:       t = i;
  48:       i = j;
  49:       j = t - j;
  50:       }
  51:    else
  52:       j = j - i;
  53: 
  54:    if (typ1 == 1) {         /* if string was created, */
  55:       sneed(j);             /*   just return a string */
  56:       STRLEN(arg0) = j;
  57:       STRLOC(arg0) = alcstr(STRLOC(arg1)+i-1, j);
  58:       }
  59:    else                 /* else make a substring tv */
  60:       mksubs(&arg1v, &arg1, i, j, &arg0);
  61:    ClearBound;
  62:    }
  63: 
  64: Opblockx(sect,4,":",3)

Defined functions

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