vi: remove two globals
awk: some 'lineno' vars were shorts, made them ints (code got smaller) awk: rename global t to global ttt. still an awful name, but at least you can grep for it now. function old new delta ttt - 28 +28 mysleep 104 120 +16 readit 408 418 +10 lineno 2 4 +2 parse_program 338 339 +1 evaluate 6446 6445 -1 syntax_error 25 23 -2 next_token 917 915 -2 new_node 26 24 -2 tv 16 8 -8 skip_spaces 68 53 -15 t 28 - -28 rfds 128 - -128 ------------------------------------------------------------------------------ (add/remove: 1/2 grow/shrink: 4/6 up/down: 57/-186) Total: -129 bytes
This commit is contained in:
parent
c8be5ee325
commit
cd5c7866e3
138
editors/awk.c
138
editors/awk.c
@ -89,7 +89,7 @@ typedef struct xhash_s {
|
|||||||
/* Tree node */
|
/* Tree node */
|
||||||
typedef struct node_s {
|
typedef struct node_s {
|
||||||
uint32_t info;
|
uint32_t info;
|
||||||
unsigned short lineno;
|
unsigned lineno;
|
||||||
union {
|
union {
|
||||||
struct node_s *n;
|
struct node_s *n;
|
||||||
var *v;
|
var *v;
|
||||||
@ -402,7 +402,7 @@ static node *break_ptr, *continue_ptr;
|
|||||||
static rstream *iF;
|
static rstream *iF;
|
||||||
static xhash *vhash, *ahash, *fdhash, *fnhash;
|
static xhash *vhash, *ahash, *fdhash, *fnhash;
|
||||||
static const char *programname;
|
static const char *programname;
|
||||||
static short lineno;
|
static int lineno;
|
||||||
static int is_f0_split;
|
static int is_f0_split;
|
||||||
static int nfields;
|
static int nfields;
|
||||||
static var *Fields;
|
static var *Fields;
|
||||||
@ -418,9 +418,10 @@ static struct {
|
|||||||
uint32_t info;
|
uint32_t info;
|
||||||
char *string;
|
char *string;
|
||||||
double number;
|
double number;
|
||||||
short lineno;
|
int lineno;
|
||||||
int rollback;
|
int rollback;
|
||||||
} t;
|
} ttt;
|
||||||
|
/* It had even better name: 't'. Whoever knows what is it, please rename! */
|
||||||
|
|
||||||
/* function prototypes */
|
/* function prototypes */
|
||||||
static void handle_special(var *);
|
static void handle_special(var *);
|
||||||
@ -577,8 +578,13 @@ static void skip_spaces(char **s)
|
|||||||
{
|
{
|
||||||
char *p = *s;
|
char *p = *s;
|
||||||
|
|
||||||
while (*p == ' ' || *p == '\t' ||
|
while (1) {
|
||||||
(*p == '\\' && *(p+1) == '\n' && (++p, ++t.lineno))) {
|
if (*p == '\\' && p[1] == '\n') {
|
||||||
|
p++;
|
||||||
|
ttt.lineno++;
|
||||||
|
} else if (*p != ' ' && *p != '\t') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
*s = p;
|
*s = p;
|
||||||
@ -623,7 +629,7 @@ static xhash *iamarray(var *v)
|
|||||||
while (a->type & VF_CHILD)
|
while (a->type & VF_CHILD)
|
||||||
a = a->x.parent;
|
a = a->x.parent;
|
||||||
|
|
||||||
if (! (a->type & VF_ARRAY)) {
|
if (!(a->type & VF_ARRAY)) {
|
||||||
a->type |= VF_ARRAY;
|
a->type |= VF_ARRAY;
|
||||||
a->x.array = hash_init();
|
a->x.array = hash_init();
|
||||||
}
|
}
|
||||||
@ -635,7 +641,7 @@ static void clear_array(xhash *array)
|
|||||||
unsigned i;
|
unsigned i;
|
||||||
hash_item *hi, *thi;
|
hash_item *hi, *thi;
|
||||||
|
|
||||||
for (i=0; i<array->csize; i++) {
|
for (i = 0; i < array->csize; i++) {
|
||||||
hi = array->items[i];
|
hi = array->items[i];
|
||||||
while (hi) {
|
while (hi) {
|
||||||
thi = hi;
|
thi = hi;
|
||||||
@ -834,7 +840,7 @@ static void nvfree(var *v)
|
|||||||
|
|
||||||
/* ------- awk program text parsing ------- */
|
/* ------- awk program text parsing ------- */
|
||||||
|
|
||||||
/* Parse next token pointed by global pos, place results into global t.
|
/* Parse next token pointed by global pos, place results into global ttt.
|
||||||
* If token isn't expected, give away. Return token class
|
* If token isn't expected, give away. Return token class
|
||||||
*/
|
*/
|
||||||
static uint32_t next_token(uint32_t expected)
|
static uint32_t next_token(uint32_t expected)
|
||||||
@ -849,31 +855,31 @@ static uint32_t next_token(uint32_t expected)
|
|||||||
const uint32_t *ti;
|
const uint32_t *ti;
|
||||||
int l;
|
int l;
|
||||||
|
|
||||||
if (t.rollback) {
|
if (ttt.rollback) {
|
||||||
t.rollback = FALSE;
|
ttt.rollback = FALSE;
|
||||||
|
|
||||||
} else if (concat_inserted) {
|
} else if (concat_inserted) {
|
||||||
concat_inserted = FALSE;
|
concat_inserted = FALSE;
|
||||||
t.tclass = save_tclass;
|
ttt.tclass = save_tclass;
|
||||||
t.info = save_info;
|
ttt.info = save_info;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
p = pos;
|
p = pos;
|
||||||
readnext:
|
readnext:
|
||||||
skip_spaces(&p);
|
skip_spaces(&p);
|
||||||
lineno = t.lineno;
|
lineno = ttt.lineno;
|
||||||
if (*p == '#')
|
if (*p == '#')
|
||||||
while (*p != '\n' && *p != '\0') p++;
|
while (*p != '\n' && *p != '\0') p++;
|
||||||
|
|
||||||
if (*p == '\n')
|
if (*p == '\n')
|
||||||
t.lineno++;
|
ttt.lineno++;
|
||||||
|
|
||||||
if (*p == '\0') {
|
if (*p == '\0') {
|
||||||
tc = TC_EOF;
|
tc = TC_EOF;
|
||||||
|
|
||||||
} else if (*p == '\"') {
|
} else if (*p == '\"') {
|
||||||
/* it's a string */
|
/* it's a string */
|
||||||
t.string = s = ++p;
|
ttt.string = s = ++p;
|
||||||
while (*p != '\"') {
|
while (*p != '\"') {
|
||||||
if (*p == '\0' || *p == '\n')
|
if (*p == '\0' || *p == '\n')
|
||||||
syntax_error(EMSG_UNEXP_EOS);
|
syntax_error(EMSG_UNEXP_EOS);
|
||||||
@ -885,7 +891,7 @@ static uint32_t next_token(uint32_t expected)
|
|||||||
|
|
||||||
} else if ((expected & TC_REGEXP) && *p == '/') {
|
} else if ((expected & TC_REGEXP) && *p == '/') {
|
||||||
/* it's regexp */
|
/* it's regexp */
|
||||||
t.string = s = ++p;
|
ttt.string = s = ++p;
|
||||||
while (*p != '/') {
|
while (*p != '/') {
|
||||||
if (*p == '\0' || *p == '\n')
|
if (*p == '\0' || *p == '\n')
|
||||||
syntax_error(EMSG_UNEXP_EOS);
|
syntax_error(EMSG_UNEXP_EOS);
|
||||||
@ -902,7 +908,7 @@ static uint32_t next_token(uint32_t expected)
|
|||||||
|
|
||||||
} else if (*p == '.' || isdigit(*p)) {
|
} else if (*p == '.' || isdigit(*p)) {
|
||||||
/* it's a number */
|
/* it's a number */
|
||||||
t.number = strtod(p, &p);
|
ttt.number = strtod(p, &p);
|
||||||
if (*p == '.')
|
if (*p == '.')
|
||||||
syntax_error(EMSG_UNEXP_TOKEN);
|
syntax_error(EMSG_UNEXP_TOKEN);
|
||||||
tc = TC_NUMBER;
|
tc = TC_NUMBER;
|
||||||
@ -925,7 +931,7 @@ static uint32_t next_token(uint32_t expected)
|
|||||||
if ((tc & (expected | TC_WORD | TC_NEWLINE)) &&
|
if ((tc & (expected | TC_WORD | TC_NEWLINE)) &&
|
||||||
*tl == *p && strncmp(p, tl, l) == 0 &&
|
*tl == *p && strncmp(p, tl, l) == 0 &&
|
||||||
!((tc & TC_WORD) && isalnum_(*(p + l)))) {
|
!((tc & TC_WORD) && isalnum_(*(p + l)))) {
|
||||||
t.info = *ti;
|
ttt.info = *ti;
|
||||||
p += l;
|
p += l;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -940,7 +946,7 @@ static uint32_t next_token(uint32_t expected)
|
|||||||
if (!isalnum_(*p))
|
if (!isalnum_(*p))
|
||||||
syntax_error(EMSG_UNEXP_TOKEN);
|
syntax_error(EMSG_UNEXP_TOKEN);
|
||||||
|
|
||||||
t.string = --p;
|
ttt.string = --p;
|
||||||
while (isalnum_(*(++p))) {
|
while (isalnum_(*(++p))) {
|
||||||
*(p-1) = *p;
|
*(p-1) = *p;
|
||||||
}
|
}
|
||||||
@ -968,14 +974,14 @@ static uint32_t next_token(uint32_t expected)
|
|||||||
if ((ltclass&TC_CONCAT1) && (tc&TC_CONCAT2) && (expected&TC_BINOP)) {
|
if ((ltclass&TC_CONCAT1) && (tc&TC_CONCAT2) && (expected&TC_BINOP)) {
|
||||||
concat_inserted = TRUE;
|
concat_inserted = TRUE;
|
||||||
save_tclass = tc;
|
save_tclass = tc;
|
||||||
save_info = t.info;
|
save_info = ttt.info;
|
||||||
tc = TC_BINOP;
|
tc = TC_BINOP;
|
||||||
t.info = OC_CONCAT | SS | P(35);
|
ttt.info = OC_CONCAT | SS | P(35);
|
||||||
}
|
}
|
||||||
|
|
||||||
t.tclass = tc;
|
ttt.tclass = tc;
|
||||||
}
|
}
|
||||||
ltclass = t.tclass;
|
ltclass = ttt.tclass;
|
||||||
|
|
||||||
/* Are we ready for this? */
|
/* Are we ready for this? */
|
||||||
if (! (ltclass & expected))
|
if (! (ltclass & expected))
|
||||||
@ -985,7 +991,10 @@ static uint32_t next_token(uint32_t expected)
|
|||||||
return ltclass;
|
return ltclass;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rollback_token(void) { t.rollback = TRUE; }
|
static void rollback_token(void)
|
||||||
|
{
|
||||||
|
ttt.rollback = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static node *new_node(uint32_t info)
|
static node *new_node(uint32_t info)
|
||||||
{
|
{
|
||||||
@ -1028,8 +1037,8 @@ static node *parse_expr(uint32_t iexp)
|
|||||||
sn.r.n = glptr = NULL;
|
sn.r.n = glptr = NULL;
|
||||||
xtc = TC_OPERAND | TC_UOPPRE | TC_REGEXP | iexp;
|
xtc = TC_OPERAND | TC_UOPPRE | TC_REGEXP | iexp;
|
||||||
|
|
||||||
while (! ((tc = next_token(xtc)) & iexp)) {
|
while (!((tc = next_token(xtc)) & iexp)) {
|
||||||
if (glptr && (t.info == (OC_COMPARE|VV|P(39)|2))) {
|
if (glptr && (ttt.info == (OC_COMPARE|VV|P(39)|2))) {
|
||||||
/* input redirection (<) attached to glptr node */
|
/* input redirection (<) attached to glptr node */
|
||||||
cn = glptr->l.n = new_node(OC_CONCAT|SS|P(37));
|
cn = glptr->l.n = new_node(OC_CONCAT|SS|P(37));
|
||||||
cn->a.n = glptr;
|
cn->a.n = glptr;
|
||||||
@ -1040,17 +1049,17 @@ static node *parse_expr(uint32_t iexp)
|
|||||||
/* for binary and postfix-unary operators, jump back over
|
/* for binary and postfix-unary operators, jump back over
|
||||||
* previous operators with higher priority */
|
* previous operators with higher priority */
|
||||||
vn = cn;
|
vn = cn;
|
||||||
while ( ((t.info & PRIMASK) > (vn->a.n->info & PRIMASK2)) ||
|
while ( ((ttt.info & PRIMASK) > (vn->a.n->info & PRIMASK2)) ||
|
||||||
((t.info == vn->info) && ((t.info & OPCLSMASK) == OC_COLON)) )
|
((ttt.info == vn->info) && ((ttt.info & OPCLSMASK) == OC_COLON)) )
|
||||||
vn = vn->a.n;
|
vn = vn->a.n;
|
||||||
if ((t.info & OPCLSMASK) == OC_TERNARY)
|
if ((ttt.info & OPCLSMASK) == OC_TERNARY)
|
||||||
t.info += P(6);
|
ttt.info += P(6);
|
||||||
cn = vn->a.n->r.n = new_node(t.info);
|
cn = vn->a.n->r.n = new_node(ttt.info);
|
||||||
cn->a.n = vn->a.n;
|
cn->a.n = vn->a.n;
|
||||||
if (tc & TC_BINOP) {
|
if (tc & TC_BINOP) {
|
||||||
cn->l.n = vn;
|
cn->l.n = vn;
|
||||||
xtc = TC_OPERAND | TC_UOPPRE | TC_REGEXP;
|
xtc = TC_OPERAND | TC_UOPPRE | TC_REGEXP;
|
||||||
if ((t.info & OPCLSMASK) == OC_PGETLINE) {
|
if ((ttt.info & OPCLSMASK) == OC_PGETLINE) {
|
||||||
/* it's a pipe */
|
/* it's a pipe */
|
||||||
next_token(TC_GETLINE);
|
next_token(TC_GETLINE);
|
||||||
/* give maximum priority to this pipe */
|
/* give maximum priority to this pipe */
|
||||||
@ -1067,7 +1076,7 @@ static node *parse_expr(uint32_t iexp)
|
|||||||
/* for operands and prefix-unary operators, attach them
|
/* for operands and prefix-unary operators, attach them
|
||||||
* to last node */
|
* to last node */
|
||||||
vn = cn;
|
vn = cn;
|
||||||
cn = vn->r.n = new_node(t.info);
|
cn = vn->r.n = new_node(ttt.info);
|
||||||
cn->a.n = vn;
|
cn->a.n = vn;
|
||||||
xtc = TC_OPERAND | TC_UOPPRE | TC_REGEXP;
|
xtc = TC_OPERAND | TC_UOPPRE | TC_REGEXP;
|
||||||
if (tc & (TC_OPERAND | TC_REGEXP)) {
|
if (tc & (TC_OPERAND | TC_REGEXP)) {
|
||||||
@ -1078,11 +1087,11 @@ static node *parse_expr(uint32_t iexp)
|
|||||||
case TC_VARIABLE:
|
case TC_VARIABLE:
|
||||||
case TC_ARRAY:
|
case TC_ARRAY:
|
||||||
cn->info = OC_VAR;
|
cn->info = OC_VAR;
|
||||||
if ((v = hash_search(ahash, t.string)) != NULL) {
|
if ((v = hash_search(ahash, ttt.string)) != NULL) {
|
||||||
cn->info = OC_FNARG;
|
cn->info = OC_FNARG;
|
||||||
cn->l.i = v->x.aidx;
|
cn->l.i = v->x.aidx;
|
||||||
} else {
|
} else {
|
||||||
cn->l.v = newvar(t.string);
|
cn->l.v = newvar(ttt.string);
|
||||||
}
|
}
|
||||||
if (tc & TC_ARRAY) {
|
if (tc & TC_ARRAY) {
|
||||||
cn->info |= xS;
|
cn->info |= xS;
|
||||||
@ -1095,18 +1104,18 @@ static node *parse_expr(uint32_t iexp)
|
|||||||
cn->info = OC_VAR;
|
cn->info = OC_VAR;
|
||||||
v = cn->l.v = xzalloc(sizeof(var));
|
v = cn->l.v = xzalloc(sizeof(var));
|
||||||
if (tc & TC_NUMBER)
|
if (tc & TC_NUMBER)
|
||||||
setvar_i(v, t.number);
|
setvar_i(v, ttt.number);
|
||||||
else
|
else
|
||||||
setvar_s(v, t.string);
|
setvar_s(v, ttt.string);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TC_REGEXP:
|
case TC_REGEXP:
|
||||||
mk_re_node(t.string, cn, xzalloc(sizeof(regex_t)*2));
|
mk_re_node(ttt.string, cn, xzalloc(sizeof(regex_t)*2));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TC_FUNCTION:
|
case TC_FUNCTION:
|
||||||
cn->info = OC_FUNC;
|
cn->info = OC_FUNC;
|
||||||
cn->r.f = newfunc(t.string);
|
cn->r.f = newfunc(ttt.string);
|
||||||
cn->l.n = condition();
|
cn->l.n = condition();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1135,7 +1144,7 @@ static node *chain_node(uint32_t info)
|
|||||||
{
|
{
|
||||||
node *n;
|
node *n;
|
||||||
|
|
||||||
if (! seq->first)
|
if (!seq->first)
|
||||||
seq->first = seq->last = new_node(0);
|
seq->first = seq->last = new_node(0);
|
||||||
|
|
||||||
if (seq->programname != programname) {
|
if (seq->programname != programname) {
|
||||||
@ -1157,7 +1166,7 @@ static void chain_expr(uint32_t info)
|
|||||||
|
|
||||||
n = chain_node(info);
|
n = chain_node(info);
|
||||||
n->l.n = parse_expr(TC_OPTERM | TC_GRPTERM);
|
n->l.n = parse_expr(TC_OPTERM | TC_GRPTERM);
|
||||||
if (t.tclass & TC_GRPTERM)
|
if (ttt.tclass & TC_GRPTERM)
|
||||||
rollback_token();
|
rollback_token();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1196,7 +1205,7 @@ static void chain_group(void)
|
|||||||
|
|
||||||
if (c & TC_GRPSTART) {
|
if (c & TC_GRPSTART) {
|
||||||
while (next_token(TC_GRPSEQ | TC_GRPTERM) != TC_GRPTERM) {
|
while (next_token(TC_GRPSEQ | TC_GRPTERM) != TC_GRPTERM) {
|
||||||
if (t.tclass & TC_NEWLINE) continue;
|
if (ttt.tclass & TC_NEWLINE) continue;
|
||||||
rollback_token();
|
rollback_token();
|
||||||
chain_group();
|
chain_group();
|
||||||
}
|
}
|
||||||
@ -1204,7 +1213,7 @@ static void chain_group(void)
|
|||||||
rollback_token();
|
rollback_token();
|
||||||
chain_expr(OC_EXEC | Vx);
|
chain_expr(OC_EXEC | Vx);
|
||||||
} else { /* TC_STATEMNT */
|
} else { /* TC_STATEMNT */
|
||||||
switch (t.info & OPCLSMASK) {
|
switch (ttt.info & OPCLSMASK) {
|
||||||
case ST_IF:
|
case ST_IF:
|
||||||
n = chain_node(OC_BR | Vx);
|
n = chain_node(OC_BR | Vx);
|
||||||
n->l.n = condition();
|
n->l.n = condition();
|
||||||
@ -1236,7 +1245,7 @@ static void chain_group(void)
|
|||||||
case ST_FOR:
|
case ST_FOR:
|
||||||
next_token(TC_SEQSTART);
|
next_token(TC_SEQSTART);
|
||||||
n2 = parse_expr(TC_SEMICOL | TC_SEQTERM);
|
n2 = parse_expr(TC_SEMICOL | TC_SEQTERM);
|
||||||
if (t.tclass & TC_SEQTERM) { /* for-in */
|
if (ttt.tclass & TC_SEQTERM) { /* for-in */
|
||||||
if ((n2->info & OPCLSMASK) != OC_IN)
|
if ((n2->info & OPCLSMASK) != OC_IN)
|
||||||
syntax_error(EMSG_UNEXP_TOKEN);
|
syntax_error(EMSG_UNEXP_TOKEN);
|
||||||
n = chain_node(OC_WALKINIT | VV);
|
n = chain_node(OC_WALKINIT | VV);
|
||||||
@ -1259,13 +1268,13 @@ static void chain_group(void)
|
|||||||
|
|
||||||
case OC_PRINT:
|
case OC_PRINT:
|
||||||
case OC_PRINTF:
|
case OC_PRINTF:
|
||||||
n = chain_node(t.info);
|
n = chain_node(ttt.info);
|
||||||
n->l.n = parse_expr(TC_OPTERM | TC_OUTRDR | TC_GRPTERM);
|
n->l.n = parse_expr(TC_OPTERM | TC_OUTRDR | TC_GRPTERM);
|
||||||
if (t.tclass & TC_OUTRDR) {
|
if (ttt.tclass & TC_OUTRDR) {
|
||||||
n->info |= t.info;
|
n->info |= ttt.info;
|
||||||
n->r.n = parse_expr(TC_OPTERM | TC_GRPTERM);
|
n->r.n = parse_expr(TC_OPTERM | TC_GRPTERM);
|
||||||
}
|
}
|
||||||
if (t.tclass & TC_GRPTERM)
|
if (ttt.tclass & TC_GRPTERM)
|
||||||
rollback_token();
|
rollback_token();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1281,7 +1290,7 @@ static void chain_group(void)
|
|||||||
|
|
||||||
/* delete, next, nextfile, return, exit */
|
/* delete, next, nextfile, return, exit */
|
||||||
default:
|
default:
|
||||||
chain_expr(t.info);
|
chain_expr(ttt.info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1294,7 +1303,7 @@ static void parse_program(char *p)
|
|||||||
var *v;
|
var *v;
|
||||||
|
|
||||||
pos = p;
|
pos = p;
|
||||||
t.lineno = 1;
|
ttt.lineno = 1;
|
||||||
while ((tclass = next_token(TC_EOF | TC_OPSEQ | TC_GRPSTART |
|
while ((tclass = next_token(TC_EOF | TC_OPSEQ | TC_GRPSTART |
|
||||||
TC_OPTERM | TC_BEGIN | TC_END | TC_FUNCDECL)) != TC_EOF) {
|
TC_OPTERM | TC_BEGIN | TC_END | TC_FUNCDECL)) != TC_EOF) {
|
||||||
|
|
||||||
@ -1313,11 +1322,11 @@ static void parse_program(char *p)
|
|||||||
} else if (tclass & TC_FUNCDECL) {
|
} else if (tclass & TC_FUNCDECL) {
|
||||||
next_token(TC_FUNCTION);
|
next_token(TC_FUNCTION);
|
||||||
pos++;
|
pos++;
|
||||||
f = newfunc(t.string);
|
f = newfunc(ttt.string);
|
||||||
f->body.first = NULL;
|
f->body.first = NULL;
|
||||||
f->nargs = 0;
|
f->nargs = 0;
|
||||||
while (next_token(TC_VARIABLE | TC_SEQTERM) & TC_VARIABLE) {
|
while (next_token(TC_VARIABLE | TC_SEQTERM) & TC_VARIABLE) {
|
||||||
v = findvar(ahash, t.string);
|
v = findvar(ahash, ttt.string);
|
||||||
v->x.aidx = (f->nargs)++;
|
v->x.aidx = (f->nargs)++;
|
||||||
|
|
||||||
if (next_token(TC_COMMA | TC_SEQTERM) & TC_SEQTERM)
|
if (next_token(TC_COMMA | TC_SEQTERM) & TC_SEQTERM)
|
||||||
@ -1331,7 +1340,7 @@ static void parse_program(char *p)
|
|||||||
rollback_token();
|
rollback_token();
|
||||||
cn = chain_node(OC_TEST);
|
cn = chain_node(OC_TEST);
|
||||||
cn->l.n = parse_expr(TC_OPTERM | TC_EOF | TC_GRPSTART);
|
cn->l.n = parse_expr(TC_OPTERM | TC_EOF | TC_GRPSTART);
|
||||||
if (t.tclass & TC_GRPSTART) {
|
if (ttt.tclass & TC_GRPSTART) {
|
||||||
rollback_token();
|
rollback_token();
|
||||||
chain_group();
|
chain_group();
|
||||||
} else {
|
} else {
|
||||||
@ -2087,7 +2096,6 @@ static var *evaluate(node *op, var *res)
|
|||||||
v1 = nvalloc(2);
|
v1 = nvalloc(2);
|
||||||
|
|
||||||
while (op) {
|
while (op) {
|
||||||
|
|
||||||
opinfo = op->info;
|
opinfo = op->info;
|
||||||
opn = (short)(opinfo & OPNMASK);
|
opn = (short)(opinfo & OPNMASK);
|
||||||
lineno = op->lineno;
|
lineno = op->lineno;
|
||||||
@ -2102,9 +2110,9 @@ static var *evaluate(node *op, var *res)
|
|||||||
|
|
||||||
switch (XC(opinfo & OPCLSMASK)) {
|
switch (XC(opinfo & OPCLSMASK)) {
|
||||||
|
|
||||||
/* -- iterative node type -- */
|
/* -- iterative node type -- */
|
||||||
|
|
||||||
/* test pattern */
|
/* test pattern */
|
||||||
case XC( OC_TEST ):
|
case XC( OC_TEST ):
|
||||||
if ((op1->info & OPCLSMASK) == OC_COMMA) {
|
if ((op1->info & OPCLSMASK) == OC_COMMA) {
|
||||||
/* it's range pattern */
|
/* it's range pattern */
|
||||||
@ -2122,21 +2130,21 @@ static var *evaluate(node *op, var *res)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* just evaluate an expression, also used as unconditional jump */
|
/* just evaluate an expression, also used as unconditional jump */
|
||||||
case XC( OC_EXEC ):
|
case XC( OC_EXEC ):
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* branch, used in if-else and various loops */
|
/* branch, used in if-else and various loops */
|
||||||
case XC( OC_BR ):
|
case XC( OC_BR ):
|
||||||
op = istrue(L.v) ? op->a.n : op->r.n;
|
op = istrue(L.v) ? op->a.n : op->r.n;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* initialize for-in loop */
|
/* initialize for-in loop */
|
||||||
case XC( OC_WALKINIT ):
|
case XC( OC_WALKINIT ):
|
||||||
hashwalk_init(L.v, iamarray(R.v));
|
hashwalk_init(L.v, iamarray(R.v));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* get next array item */
|
/* get next array item */
|
||||||
case XC( OC_WALKNEXT ):
|
case XC( OC_WALKNEXT ):
|
||||||
op = hashwalk_next(L.v) ? op->a.n : op->r.n;
|
op = hashwalk_next(L.v) ? op->a.n : op->r.n;
|
||||||
break;
|
break;
|
||||||
@ -2224,7 +2232,7 @@ static var *evaluate(node *op, var *res)
|
|||||||
case XC( OC_EXIT ):
|
case XC( OC_EXIT ):
|
||||||
awk_exit(L.d);
|
awk_exit(L.d);
|
||||||
|
|
||||||
/* -- recursive node type -- */
|
/* -- recursive node type -- */
|
||||||
|
|
||||||
case XC( OC_VAR ):
|
case XC( OC_VAR ):
|
||||||
L.v = op->l.v;
|
L.v = op->l.v;
|
||||||
@ -2333,7 +2341,7 @@ static var *evaluate(node *op, var *res)
|
|||||||
setvar_i(res, L.i);
|
setvar_i(res, L.i);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* simple builtins */
|
/* simple builtins */
|
||||||
case XC( OC_FBLTIN ):
|
case XC( OC_FBLTIN ):
|
||||||
switch (opn) {
|
switch (opn) {
|
||||||
|
|
||||||
@ -2344,7 +2352,6 @@ static var *evaluate(node *op, var *res)
|
|||||||
case F_rn:
|
case F_rn:
|
||||||
R.d = (double)rand() / (double)RAND_MAX;
|
R.d = (double)rand() / (double)RAND_MAX;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#if ENABLE_FEATURE_AWK_MATH
|
#if ENABLE_FEATURE_AWK_MATH
|
||||||
case F_co:
|
case F_co:
|
||||||
R.d = cos(L.d);
|
R.d = cos(L.d);
|
||||||
@ -2374,7 +2381,6 @@ static var *evaluate(node *op, var *res)
|
|||||||
runtime_error(EMSG_NO_MATH);
|
runtime_error(EMSG_NO_MATH);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
case F_sr:
|
case F_sr:
|
||||||
R.d = (double)seed;
|
R.d = (double)seed;
|
||||||
seed = op1 ? (unsigned)L.d : (unsigned)time(NULL);
|
seed = op1 ? (unsigned)L.d : (unsigned)time(NULL);
|
||||||
@ -2474,7 +2480,7 @@ static var *evaluate(node *op, var *res)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* concatenation (" ") and index joining (",") */
|
/* concatenation (" ") and index joining (",") */
|
||||||
case XC( OC_CONCAT ):
|
case XC( OC_CONCAT ):
|
||||||
case XC( OC_COMMA ):
|
case XC( OC_COMMA ):
|
||||||
opn = strlen(L.s) + strlen(R.s) + 2;
|
opn = strlen(L.s) + strlen(R.s) + 2;
|
||||||
|
10
editors/vi.c
10
editors/vi.c
@ -111,8 +111,6 @@ static int last_file_modified = -1;
|
|||||||
static int fn_start; // index of first cmd line file name
|
static int fn_start; // index of first cmd line file name
|
||||||
static int save_argc; // how many file names on cmd line
|
static int save_argc; // how many file names on cmd line
|
||||||
static int cmdcnt; // repetition count
|
static int cmdcnt; // repetition count
|
||||||
static fd_set rfds; // use select() for small sleeps
|
|
||||||
static struct timeval tv; // use select() for small sleeps
|
|
||||||
static int rows, columns; // the terminal screen is this size
|
static int rows, columns; // the terminal screen is this size
|
||||||
static int crow, ccol, offset; // cursor is on Crow x Ccol with Horz Ofset
|
static int crow, ccol, offset; // cursor is on Crow x Ccol with Horz Ofset
|
||||||
static char *status_buffer; // mesages to the user
|
static char *status_buffer; // mesages to the user
|
||||||
@ -279,7 +277,7 @@ int vi_main(int argc, char **argv)
|
|||||||
#if ENABLE_FEATURE_VI_YANKMARK
|
#if ENABLE_FEATURE_VI_YANKMARK
|
||||||
int i;
|
int i;
|
||||||
#endif
|
#endif
|
||||||
#if defined(CONFIG_FEATURE_VI_USE_SIGNALS) || defined(CONFIG_FEATURE_VI_CRASHME)
|
#if ENABLE_FEATURE_VI_USE_SIGNALS || ENABLE_FEATURE_VI_CRASHME
|
||||||
my_pid = getpid();
|
my_pid = getpid();
|
||||||
#endif
|
#endif
|
||||||
#if ENABLE_FEATURE_VI_CRASHME
|
#if ENABLE_FEATURE_VI_CRASHME
|
||||||
@ -2142,6 +2140,9 @@ static void catch_sig(int sig)
|
|||||||
|
|
||||||
static int mysleep(int hund) // sleep for 'h' 1/100 seconds
|
static int mysleep(int hund) // sleep for 'h' 1/100 seconds
|
||||||
{
|
{
|
||||||
|
fd_set rfds;
|
||||||
|
struct timeval tv;
|
||||||
|
|
||||||
// Don't hang- Wait 5/100 seconds- 1 Sec= 1000000
|
// Don't hang- Wait 5/100 seconds- 1 Sec= 1000000
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
FD_ZERO(&rfds);
|
FD_ZERO(&rfds);
|
||||||
@ -2228,6 +2229,9 @@ static char readit(void) // read (maybe cursor) key from stdin
|
|||||||
if (n <= 0)
|
if (n <= 0)
|
||||||
return 0; // error
|
return 0; // error
|
||||||
if (readbuffer[0] == 27) {
|
if (readbuffer[0] == 27) {
|
||||||
|
fd_set rfds;
|
||||||
|
struct timeval tv;
|
||||||
|
|
||||||
// This is an ESC char. Is this Esc sequence?
|
// This is an ESC char. Is this Esc sequence?
|
||||||
// Could be bare Esc key. See if there are any
|
// Could be bare Esc key. See if there are any
|
||||||
// more chars to read after the ESC. This would
|
// more chars to read after the ESC. This would
|
||||||
|
Loading…
Reference in New Issue
Block a user