1: #include "../h/rt.h" 2: 3: /* 4: * mksubs - form a substring. var is a descriptor for the string from 5: * which the substring is to be formed. var may be a variable. val 6: * is a dereferenced version of val. The descriptor for the resulting 7: * substring is placed in *result. The substring starts at position 8: * i and extends for j characters. 9: */ 10: 11: struct descrip mksubs(var, val, i, j, result) 12: register struct descrip *var, *val, *result; 13: int i, j; 14: { 15: extern struct b_tvsubs *alcsubs(); 16: 17: if (QUAL(*var) || !VAR(*var)) { 18: /* 19: * var isn't a variable, just form a descriptor that points into 20: * the string named by val. 21: */ 22: STRLEN(*result) = j; 23: STRLOC(*result) = STRLOC(*val) + i - 1; 24: return; 25: } 26: 27: if (TVAR(*var)) { 28: /* 29: * var is a trapped variable. If it is a substring trapped variable, 30: * adjust the position and make var the substrung string. For other 31: * trapped variables, don't do anything. 32: */ 33: switch (TYPE(*var)) { 34: case T_TVSUBS: 35: i += BLKLOC(*var)->tvsubs.sspos - 1; 36: var = &BLKLOC(*var)->tvsubs.ssvar; 37: break; 38: 39: default: 40: break; 41: } 42: } 43: 44: /* 45: * Make a substring trapped variable by passing the buck to alcsubs. 46: */ 47: result->type = D_TVSUBS; 48: BLKLOC(*result) = (union block *) alcsubs(j, i, var); 49: return; 50: }