/* * get a macro line argument * * char *tok; buffer to place argument */ int macarg(char *tok) { int savcle; /* buffer to store original clexec */ int status; savcle = clexec; /* save execution mode */ clexec = TRUE; /* get the argument */ status = nextarg("", tok, NSTRING, ctoec('\n')); clexec = savcle; /* restore execution mode */ return status; }
/* * find the value of a token * * char *token; token to evaluate */ char *getval(char *token) { int status; /* error return */ struct buffer *bp; /* temp buffer pointer */ int blen; /* length of buffer argument */ int distmp; /* temporary discmd flag */ static char buf[NSTRING]; /* string buffer for some returns */ switch (gettyp(token)) { case TKNUL: return ""; case TKARG: /* interactive argument */ strcpy(token, getval(&token[1])); distmp = discmd; /* echo it always! */ discmd = TRUE; status = getstring(token, buf, NSTRING, ctoec('\n')); discmd = distmp; if (status == ABORT) return errorm; return buf; case TKBUF: /* buffer contents fetch */ /* grab the right buffer */ strcpy(token, getval(&token[1])); bp = bfind(token, FALSE, 0); if (bp == NULL) return errorm; /* if the buffer is displayed, get the window vars instead of the buffer vars */ if (bp->b_nwnd > 0) { curbp->b_dotp = curwp->w_dotp; curbp->b_doto = curwp->w_doto; } /* make sure we are not at the end */ if (bp->b_linep == bp->b_dotp) return errorm; /* grab the line as an argument */ blen = bp->b_dotp->l_used - bp->b_doto; if (blen > NSTRING) blen = NSTRING; strncpy(buf, bp->b_dotp->l_text + bp->b_doto, blen); buf[blen] = 0; /* and step the buffer's line ptr ahead a line */ bp->b_dotp = bp->b_dotp->l_fp; bp->b_doto = 0; /* if displayed buffer, reset window ptr vars */ if (bp->b_nwnd > 0) { curwp->w_dotp = curbp->b_dotp; curwp->w_doto = 0; curwp->w_flag |= WFMOVE; } /* and return the spoils */ return buf; case TKVAR: return gtusr(token + 1); case TKENV: return gtenv(token + 1); case TKFUN: return gtfun(token + 1); case TKDIR: return errorm; case TKLBL: return errorm; case TKLIT: return token; case TKSTR: return token + 1; case TKCMD: return token; } return errorm; }