diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-05-17 16:37:22 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-05-17 16:37:22 +0000 |
commit | cd5c7866e328b502d946485ad1886ce26cffabfa (patch) | |
tree | b0d636908765bba8b8d9bd26d0dd289299d17311 | |
parent | c8be5ee325a374525f503d11eccb5da3ee35a509 (diff) | |
download | busybox-w32-cd5c7866e328b502d946485ad1886ce26cffabfa.tar.gz busybox-w32-cd5c7866e328b502d946485ad1886ce26cffabfa.tar.bz2 busybox-w32-cd5c7866e328b502d946485ad1886ce26cffabfa.zip |
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
-rw-r--r-- | editors/awk.c | 138 | ||||
-rw-r--r-- | editors/vi.c | 10 |
2 files changed, 79 insertions, 69 deletions
diff --git a/editors/awk.c b/editors/awk.c index 2e67f67fb..9366a2398 100644 --- a/editors/awk.c +++ b/editors/awk.c | |||
@@ -89,7 +89,7 @@ typedef struct xhash_s { | |||
89 | /* Tree node */ | 89 | /* Tree node */ |
90 | typedef struct node_s { | 90 | typedef struct node_s { |
91 | uint32_t info; | 91 | uint32_t info; |
92 | unsigned short lineno; | 92 | unsigned lineno; |
93 | union { | 93 | union { |
94 | struct node_s *n; | 94 | struct node_s *n; |
95 | var *v; | 95 | var *v; |
@@ -402,7 +402,7 @@ static node *break_ptr, *continue_ptr; | |||
402 | static rstream *iF; | 402 | static rstream *iF; |
403 | static xhash *vhash, *ahash, *fdhash, *fnhash; | 403 | static xhash *vhash, *ahash, *fdhash, *fnhash; |
404 | static const char *programname; | 404 | static const char *programname; |
405 | static short lineno; | 405 | static int lineno; |
406 | static int is_f0_split; | 406 | static int is_f0_split; |
407 | static int nfields; | 407 | static int nfields; |
408 | static var *Fields; | 408 | static var *Fields; |
@@ -418,9 +418,10 @@ static struct { | |||
418 | uint32_t info; | 418 | uint32_t info; |
419 | char *string; | 419 | char *string; |
420 | double number; | 420 | double number; |
421 | short lineno; | 421 | int lineno; |
422 | int rollback; | 422 | int rollback; |
423 | } t; | 423 | } ttt; |
424 | /* It had even better name: 't'. Whoever knows what is it, please rename! */ | ||
424 | 425 | ||
425 | /* function prototypes */ | 426 | /* function prototypes */ |
426 | static void handle_special(var *); | 427 | static void handle_special(var *); |
@@ -577,8 +578,13 @@ static void skip_spaces(char **s) | |||
577 | { | 578 | { |
578 | char *p = *s; | 579 | char *p = *s; |
579 | 580 | ||
580 | while (*p == ' ' || *p == '\t' || | 581 | while (1) { |
581 | (*p == '\\' && *(p+1) == '\n' && (++p, ++t.lineno))) { | 582 | if (*p == '\\' && p[1] == '\n') { |
583 | p++; | ||
584 | ttt.lineno++; | ||
585 | } else if (*p != ' ' && *p != '\t') { | ||
586 | break; | ||
587 | } | ||
582 | p++; | 588 | p++; |
583 | } | 589 | } |
584 | *s = p; | 590 | *s = p; |
@@ -623,7 +629,7 @@ static xhash *iamarray(var *v) | |||
623 | while (a->type & VF_CHILD) | 629 | while (a->type & VF_CHILD) |
624 | a = a->x.parent; | 630 | a = a->x.parent; |
625 | 631 | ||
626 | if (! (a->type & VF_ARRAY)) { | 632 | if (!(a->type & VF_ARRAY)) { |
627 | a->type |= VF_ARRAY; | 633 | a->type |= VF_ARRAY; |
628 | a->x.array = hash_init(); | 634 | a->x.array = hash_init(); |
629 | } | 635 | } |
@@ -635,7 +641,7 @@ static void clear_array(xhash *array) | |||
635 | unsigned i; | 641 | unsigned i; |
636 | hash_item *hi, *thi; | 642 | hash_item *hi, *thi; |
637 | 643 | ||
638 | for (i=0; i<array->csize; i++) { | 644 | for (i = 0; i < array->csize; i++) { |
639 | hi = array->items[i]; | 645 | hi = array->items[i]; |
640 | while (hi) { | 646 | while (hi) { |
641 | thi = hi; | 647 | thi = hi; |
@@ -834,7 +840,7 @@ static void nvfree(var *v) | |||
834 | 840 | ||
835 | /* ------- awk program text parsing ------- */ | 841 | /* ------- awk program text parsing ------- */ |
836 | 842 | ||
837 | /* Parse next token pointed by global pos, place results into global t. | 843 | /* Parse next token pointed by global pos, place results into global ttt. |
838 | * If token isn't expected, give away. Return token class | 844 | * If token isn't expected, give away. Return token class |
839 | */ | 845 | */ |
840 | static uint32_t next_token(uint32_t expected) | 846 | static uint32_t next_token(uint32_t expected) |
@@ -849,31 +855,31 @@ static uint32_t next_token(uint32_t expected) | |||
849 | const uint32_t *ti; | 855 | const uint32_t *ti; |
850 | int l; | 856 | int l; |
851 | 857 | ||
852 | if (t.rollback) { | 858 | if (ttt.rollback) { |
853 | t.rollback = FALSE; | 859 | ttt.rollback = FALSE; |
854 | 860 | ||
855 | } else if (concat_inserted) { | 861 | } else if (concat_inserted) { |
856 | concat_inserted = FALSE; | 862 | concat_inserted = FALSE; |
857 | t.tclass = save_tclass; | 863 | ttt.tclass = save_tclass; |
858 | t.info = save_info; | 864 | ttt.info = save_info; |
859 | 865 | ||
860 | } else { | 866 | } else { |
861 | p = pos; | 867 | p = pos; |
862 | readnext: | 868 | readnext: |
863 | skip_spaces(&p); | 869 | skip_spaces(&p); |
864 | lineno = t.lineno; | 870 | lineno = ttt.lineno; |
865 | if (*p == '#') | 871 | if (*p == '#') |
866 | while (*p != '\n' && *p != '\0') p++; | 872 | while (*p != '\n' && *p != '\0') p++; |
867 | 873 | ||
868 | if (*p == '\n') | 874 | if (*p == '\n') |
869 | t.lineno++; | 875 | ttt.lineno++; |
870 | 876 | ||
871 | if (*p == '\0') { | 877 | if (*p == '\0') { |
872 | tc = TC_EOF; | 878 | tc = TC_EOF; |
873 | 879 | ||
874 | } else if (*p == '\"') { | 880 | } else if (*p == '\"') { |
875 | /* it's a string */ | 881 | /* it's a string */ |
876 | t.string = s = ++p; | 882 | ttt.string = s = ++p; |
877 | while (*p != '\"') { | 883 | while (*p != '\"') { |
878 | if (*p == '\0' || *p == '\n') | 884 | if (*p == '\0' || *p == '\n') |
879 | syntax_error(EMSG_UNEXP_EOS); | 885 | syntax_error(EMSG_UNEXP_EOS); |
@@ -885,7 +891,7 @@ static uint32_t next_token(uint32_t expected) | |||
885 | 891 | ||
886 | } else if ((expected & TC_REGEXP) && *p == '/') { | 892 | } else if ((expected & TC_REGEXP) && *p == '/') { |
887 | /* it's regexp */ | 893 | /* it's regexp */ |
888 | t.string = s = ++p; | 894 | ttt.string = s = ++p; |
889 | while (*p != '/') { | 895 | while (*p != '/') { |
890 | if (*p == '\0' || *p == '\n') | 896 | if (*p == '\0' || *p == '\n') |
891 | syntax_error(EMSG_UNEXP_EOS); | 897 | syntax_error(EMSG_UNEXP_EOS); |
@@ -902,7 +908,7 @@ static uint32_t next_token(uint32_t expected) | |||
902 | 908 | ||
903 | } else if (*p == '.' || isdigit(*p)) { | 909 | } else if (*p == '.' || isdigit(*p)) { |
904 | /* it's a number */ | 910 | /* it's a number */ |
905 | t.number = strtod(p, &p); | 911 | ttt.number = strtod(p, &p); |
906 | if (*p == '.') | 912 | if (*p == '.') |
907 | syntax_error(EMSG_UNEXP_TOKEN); | 913 | syntax_error(EMSG_UNEXP_TOKEN); |
908 | tc = TC_NUMBER; | 914 | tc = TC_NUMBER; |
@@ -925,7 +931,7 @@ static uint32_t next_token(uint32_t expected) | |||
925 | if ((tc & (expected | TC_WORD | TC_NEWLINE)) && | 931 | if ((tc & (expected | TC_WORD | TC_NEWLINE)) && |
926 | *tl == *p && strncmp(p, tl, l) == 0 && | 932 | *tl == *p && strncmp(p, tl, l) == 0 && |
927 | !((tc & TC_WORD) && isalnum_(*(p + l)))) { | 933 | !((tc & TC_WORD) && isalnum_(*(p + l)))) { |
928 | t.info = *ti; | 934 | ttt.info = *ti; |
929 | p += l; | 935 | p += l; |
930 | break; | 936 | break; |
931 | } | 937 | } |
@@ -940,7 +946,7 @@ static uint32_t next_token(uint32_t expected) | |||
940 | if (!isalnum_(*p)) | 946 | if (!isalnum_(*p)) |
941 | syntax_error(EMSG_UNEXP_TOKEN); | 947 | syntax_error(EMSG_UNEXP_TOKEN); |
942 | 948 | ||
943 | t.string = --p; | 949 | ttt.string = --p; |
944 | while (isalnum_(*(++p))) { | 950 | while (isalnum_(*(++p))) { |
945 | *(p-1) = *p; | 951 | *(p-1) = *p; |
946 | } | 952 | } |
@@ -968,14 +974,14 @@ static uint32_t next_token(uint32_t expected) | |||
968 | if ((ltclass&TC_CONCAT1) && (tc&TC_CONCAT2) && (expected&TC_BINOP)) { | 974 | if ((ltclass&TC_CONCAT1) && (tc&TC_CONCAT2) && (expected&TC_BINOP)) { |
969 | concat_inserted = TRUE; | 975 | concat_inserted = TRUE; |
970 | save_tclass = tc; | 976 | save_tclass = tc; |
971 | save_info = t.info; | 977 | save_info = ttt.info; |
972 | tc = TC_BINOP; | 978 | tc = TC_BINOP; |
973 | t.info = OC_CONCAT | SS | P(35); | 979 | ttt.info = OC_CONCAT | SS | P(35); |
974 | } | 980 | } |
975 | 981 | ||
976 | t.tclass = tc; | 982 | ttt.tclass = tc; |
977 | } | 983 | } |
978 | ltclass = t.tclass; | 984 | ltclass = ttt.tclass; |
979 | 985 | ||
980 | /* Are we ready for this? */ | 986 | /* Are we ready for this? */ |
981 | if (! (ltclass & expected)) | 987 | if (! (ltclass & expected)) |
@@ -985,7 +991,10 @@ static uint32_t next_token(uint32_t expected) | |||
985 | return ltclass; | 991 | return ltclass; |
986 | } | 992 | } |
987 | 993 | ||
988 | static void rollback_token(void) { t.rollback = TRUE; } | 994 | static void rollback_token(void) |
995 | { | ||
996 | ttt.rollback = TRUE; | ||
997 | } | ||
989 | 998 | ||
990 | static node *new_node(uint32_t info) | 999 | static node *new_node(uint32_t info) |
991 | { | 1000 | { |
@@ -1028,8 +1037,8 @@ static node *parse_expr(uint32_t iexp) | |||
1028 | sn.r.n = glptr = NULL; | 1037 | sn.r.n = glptr = NULL; |
1029 | xtc = TC_OPERAND | TC_UOPPRE | TC_REGEXP | iexp; | 1038 | xtc = TC_OPERAND | TC_UOPPRE | TC_REGEXP | iexp; |
1030 | 1039 | ||
1031 | while (! ((tc = next_token(xtc)) & iexp)) { | 1040 | while (!((tc = next_token(xtc)) & iexp)) { |
1032 | if (glptr && (t.info == (OC_COMPARE|VV|P(39)|2))) { | 1041 | if (glptr && (ttt.info == (OC_COMPARE|VV|P(39)|2))) { |
1033 | /* input redirection (<) attached to glptr node */ | 1042 | /* input redirection (<) attached to glptr node */ |
1034 | cn = glptr->l.n = new_node(OC_CONCAT|SS|P(37)); | 1043 | cn = glptr->l.n = new_node(OC_CONCAT|SS|P(37)); |
1035 | cn->a.n = glptr; | 1044 | cn->a.n = glptr; |
@@ -1040,17 +1049,17 @@ static node *parse_expr(uint32_t iexp) | |||
1040 | /* for binary and postfix-unary operators, jump back over | 1049 | /* for binary and postfix-unary operators, jump back over |
1041 | * previous operators with higher priority */ | 1050 | * previous operators with higher priority */ |
1042 | vn = cn; | 1051 | vn = cn; |
1043 | while ( ((t.info & PRIMASK) > (vn->a.n->info & PRIMASK2)) || | 1052 | while ( ((ttt.info & PRIMASK) > (vn->a.n->info & PRIMASK2)) || |
1044 | ((t.info == vn->info) && ((t.info & OPCLSMASK) == OC_COLON)) ) | 1053 | ((ttt.info == vn->info) && ((ttt.info & OPCLSMASK) == OC_COLON)) ) |
1045 | vn = vn->a.n; | 1054 | vn = vn->a.n; |
1046 | if ((t.info & OPCLSMASK) == OC_TERNARY) | 1055 | if ((ttt.info & OPCLSMASK) == OC_TERNARY) |
1047 | t.info += P(6); | 1056 | ttt.info += P(6); |
1048 | cn = vn->a.n->r.n = new_node(t.info); | 1057 | cn = vn->a.n->r.n = new_node(ttt.info); |
1049 | cn->a.n = vn->a.n; | 1058 | cn->a.n = vn->a.n; |
1050 | if (tc & TC_BINOP) { | 1059 | if (tc & TC_BINOP) { |
1051 | cn->l.n = vn; | 1060 | cn->l.n = vn; |
1052 | xtc = TC_OPERAND | TC_UOPPRE | TC_REGEXP; | 1061 | xtc = TC_OPERAND | TC_UOPPRE | TC_REGEXP; |
1053 | if ((t.info & OPCLSMASK) == OC_PGETLINE) { | 1062 | if ((ttt.info & OPCLSMASK) == OC_PGETLINE) { |
1054 | /* it's a pipe */ | 1063 | /* it's a pipe */ |
1055 | next_token(TC_GETLINE); | 1064 | next_token(TC_GETLINE); |
1056 | /* give maximum priority to this pipe */ | 1065 | /* give maximum priority to this pipe */ |
@@ -1067,7 +1076,7 @@ static node *parse_expr(uint32_t iexp) | |||
1067 | /* for operands and prefix-unary operators, attach them | 1076 | /* for operands and prefix-unary operators, attach them |
1068 | * to last node */ | 1077 | * to last node */ |
1069 | vn = cn; | 1078 | vn = cn; |
1070 | cn = vn->r.n = new_node(t.info); | 1079 | cn = vn->r.n = new_node(ttt.info); |
1071 | cn->a.n = vn; | 1080 | cn->a.n = vn; |
1072 | xtc = TC_OPERAND | TC_UOPPRE | TC_REGEXP; | 1081 | xtc = TC_OPERAND | TC_UOPPRE | TC_REGEXP; |
1073 | if (tc & (TC_OPERAND | TC_REGEXP)) { | 1082 | if (tc & (TC_OPERAND | TC_REGEXP)) { |
@@ -1078,11 +1087,11 @@ static node *parse_expr(uint32_t iexp) | |||
1078 | case TC_VARIABLE: | 1087 | case TC_VARIABLE: |
1079 | case TC_ARRAY: | 1088 | case TC_ARRAY: |
1080 | cn->info = OC_VAR; | 1089 | cn->info = OC_VAR; |
1081 | if ((v = hash_search(ahash, t.string)) != NULL) { | 1090 | if ((v = hash_search(ahash, ttt.string)) != NULL) { |
1082 | cn->info = OC_FNARG; | 1091 | cn->info = OC_FNARG; |
1083 | cn->l.i = v->x.aidx; | 1092 | cn->l.i = v->x.aidx; |
1084 | } else { | 1093 | } else { |
1085 | cn->l.v = newvar(t.string); | 1094 | cn->l.v = newvar(ttt.string); |
1086 | } | 1095 | } |
1087 | if (tc & TC_ARRAY) { | 1096 | if (tc & TC_ARRAY) { |
1088 | cn->info |= xS; | 1097 | cn->info |= xS; |
@@ -1095,18 +1104,18 @@ static node *parse_expr(uint32_t iexp) | |||
1095 | cn->info = OC_VAR; | 1104 | cn->info = OC_VAR; |
1096 | v = cn->l.v = xzalloc(sizeof(var)); | 1105 | v = cn->l.v = xzalloc(sizeof(var)); |
1097 | if (tc & TC_NUMBER) | 1106 | if (tc & TC_NUMBER) |
1098 | setvar_i(v, t.number); | 1107 | setvar_i(v, ttt.number); |
1099 | else | 1108 | else |
1100 | setvar_s(v, t.string); | 1109 | setvar_s(v, ttt.string); |
1101 | break; | 1110 | break; |
1102 | 1111 | ||
1103 | case TC_REGEXP: | 1112 | case TC_REGEXP: |
1104 | mk_re_node(t.string, cn, xzalloc(sizeof(regex_t)*2)); | 1113 | mk_re_node(ttt.string, cn, xzalloc(sizeof(regex_t)*2)); |
1105 | break; | 1114 | break; |
1106 | 1115 | ||
1107 | case TC_FUNCTION: | 1116 | case TC_FUNCTION: |
1108 | cn->info = OC_FUNC; | 1117 | cn->info = OC_FUNC; |
1109 | cn->r.f = newfunc(t.string); | 1118 | cn->r.f = newfunc(ttt.string); |
1110 | cn->l.n = condition(); | 1119 | cn->l.n = condition(); |
1111 | break; | 1120 | break; |
1112 | 1121 | ||
@@ -1135,7 +1144,7 @@ static node *chain_node(uint32_t info) | |||
1135 | { | 1144 | { |
1136 | node *n; | 1145 | node *n; |
1137 | 1146 | ||
1138 | if (! seq->first) | 1147 | if (!seq->first) |
1139 | seq->first = seq->last = new_node(0); | 1148 | seq->first = seq->last = new_node(0); |
1140 | 1149 | ||
1141 | if (seq->programname != programname) { | 1150 | if (seq->programname != programname) { |
@@ -1157,7 +1166,7 @@ static void chain_expr(uint32_t info) | |||
1157 | 1166 | ||
1158 | n = chain_node(info); | 1167 | n = chain_node(info); |
1159 | n->l.n = parse_expr(TC_OPTERM | TC_GRPTERM); | 1168 | n->l.n = parse_expr(TC_OPTERM | TC_GRPTERM); |
1160 | if (t.tclass & TC_GRPTERM) | 1169 | if (ttt.tclass & TC_GRPTERM) |
1161 | rollback_token(); | 1170 | rollback_token(); |
1162 | } | 1171 | } |
1163 | 1172 | ||
@@ -1196,7 +1205,7 @@ static void chain_group(void) | |||
1196 | 1205 | ||
1197 | if (c & TC_GRPSTART) { | 1206 | if (c & TC_GRPSTART) { |
1198 | while (next_token(TC_GRPSEQ | TC_GRPTERM) != TC_GRPTERM) { | 1207 | while (next_token(TC_GRPSEQ | TC_GRPTERM) != TC_GRPTERM) { |
1199 | if (t.tclass & TC_NEWLINE) continue; | 1208 | if (ttt.tclass & TC_NEWLINE) continue; |
1200 | rollback_token(); | 1209 | rollback_token(); |
1201 | chain_group(); | 1210 | chain_group(); |
1202 | } | 1211 | } |
@@ -1204,7 +1213,7 @@ static void chain_group(void) | |||
1204 | rollback_token(); | 1213 | rollback_token(); |
1205 | chain_expr(OC_EXEC | Vx); | 1214 | chain_expr(OC_EXEC | Vx); |
1206 | } else { /* TC_STATEMNT */ | 1215 | } else { /* TC_STATEMNT */ |
1207 | switch (t.info & OPCLSMASK) { | 1216 | switch (ttt.info & OPCLSMASK) { |
1208 | case ST_IF: | 1217 | case ST_IF: |
1209 | n = chain_node(OC_BR | Vx); | 1218 | n = chain_node(OC_BR | Vx); |
1210 | n->l.n = condition(); | 1219 | n->l.n = condition(); |
@@ -1236,7 +1245,7 @@ static void chain_group(void) | |||
1236 | case ST_FOR: | 1245 | case ST_FOR: |
1237 | next_token(TC_SEQSTART); | 1246 | next_token(TC_SEQSTART); |
1238 | n2 = parse_expr(TC_SEMICOL | TC_SEQTERM); | 1247 | n2 = parse_expr(TC_SEMICOL | TC_SEQTERM); |
1239 | if (t.tclass & TC_SEQTERM) { /* for-in */ | 1248 | if (ttt.tclass & TC_SEQTERM) { /* for-in */ |
1240 | if ((n2->info & OPCLSMASK) != OC_IN) | 1249 | if ((n2->info & OPCLSMASK) != OC_IN) |
1241 | syntax_error(EMSG_UNEXP_TOKEN); | 1250 | syntax_error(EMSG_UNEXP_TOKEN); |
1242 | n = chain_node(OC_WALKINIT | VV); | 1251 | n = chain_node(OC_WALKINIT | VV); |
@@ -1259,13 +1268,13 @@ static void chain_group(void) | |||
1259 | 1268 | ||
1260 | case OC_PRINT: | 1269 | case OC_PRINT: |
1261 | case OC_PRINTF: | 1270 | case OC_PRINTF: |
1262 | n = chain_node(t.info); | 1271 | n = chain_node(ttt.info); |
1263 | n->l.n = parse_expr(TC_OPTERM | TC_OUTRDR | TC_GRPTERM); | 1272 | n->l.n = parse_expr(TC_OPTERM | TC_OUTRDR | TC_GRPTERM); |
1264 | if (t.tclass & TC_OUTRDR) { | 1273 | if (ttt.tclass & TC_OUTRDR) { |
1265 | n->info |= t.info; | 1274 | n->info |= ttt.info; |
1266 | n->r.n = parse_expr(TC_OPTERM | TC_GRPTERM); | 1275 | n->r.n = parse_expr(TC_OPTERM | TC_GRPTERM); |
1267 | } | 1276 | } |
1268 | if (t.tclass & TC_GRPTERM) | 1277 | if (ttt.tclass & TC_GRPTERM) |
1269 | rollback_token(); | 1278 | rollback_token(); |
1270 | break; | 1279 | break; |
1271 | 1280 | ||
@@ -1281,7 +1290,7 @@ static void chain_group(void) | |||
1281 | 1290 | ||
1282 | /* delete, next, nextfile, return, exit */ | 1291 | /* delete, next, nextfile, return, exit */ |
1283 | default: | 1292 | default: |
1284 | chain_expr(t.info); | 1293 | chain_expr(ttt.info); |
1285 | } | 1294 | } |
1286 | } | 1295 | } |
1287 | } | 1296 | } |
@@ -1294,7 +1303,7 @@ static void parse_program(char *p) | |||
1294 | var *v; | 1303 | var *v; |
1295 | 1304 | ||
1296 | pos = p; | 1305 | pos = p; |
1297 | t.lineno = 1; | 1306 | ttt.lineno = 1; |
1298 | while ((tclass = next_token(TC_EOF | TC_OPSEQ | TC_GRPSTART | | 1307 | while ((tclass = next_token(TC_EOF | TC_OPSEQ | TC_GRPSTART | |
1299 | TC_OPTERM | TC_BEGIN | TC_END | TC_FUNCDECL)) != TC_EOF) { | 1308 | TC_OPTERM | TC_BEGIN | TC_END | TC_FUNCDECL)) != TC_EOF) { |
1300 | 1309 | ||
@@ -1313,11 +1322,11 @@ static void parse_program(char *p) | |||
1313 | } else if (tclass & TC_FUNCDECL) { | 1322 | } else if (tclass & TC_FUNCDECL) { |
1314 | next_token(TC_FUNCTION); | 1323 | next_token(TC_FUNCTION); |
1315 | pos++; | 1324 | pos++; |
1316 | f = newfunc(t.string); | 1325 | f = newfunc(ttt.string); |
1317 | f->body.first = NULL; | 1326 | f->body.first = NULL; |
1318 | f->nargs = 0; | 1327 | f->nargs = 0; |
1319 | while (next_token(TC_VARIABLE | TC_SEQTERM) & TC_VARIABLE) { | 1328 | while (next_token(TC_VARIABLE | TC_SEQTERM) & TC_VARIABLE) { |
1320 | v = findvar(ahash, t.string); | 1329 | v = findvar(ahash, ttt.string); |
1321 | v->x.aidx = (f->nargs)++; | 1330 | v->x.aidx = (f->nargs)++; |
1322 | 1331 | ||
1323 | if (next_token(TC_COMMA | TC_SEQTERM) & TC_SEQTERM) | 1332 | if (next_token(TC_COMMA | TC_SEQTERM) & TC_SEQTERM) |
@@ -1331,7 +1340,7 @@ static void parse_program(char *p) | |||
1331 | rollback_token(); | 1340 | rollback_token(); |
1332 | cn = chain_node(OC_TEST); | 1341 | cn = chain_node(OC_TEST); |
1333 | cn->l.n = parse_expr(TC_OPTERM | TC_EOF | TC_GRPSTART); | 1342 | cn->l.n = parse_expr(TC_OPTERM | TC_EOF | TC_GRPSTART); |
1334 | if (t.tclass & TC_GRPSTART) { | 1343 | if (ttt.tclass & TC_GRPSTART) { |
1335 | rollback_token(); | 1344 | rollback_token(); |
1336 | chain_group(); | 1345 | chain_group(); |
1337 | } else { | 1346 | } else { |
@@ -2087,7 +2096,6 @@ static var *evaluate(node *op, var *res) | |||
2087 | v1 = nvalloc(2); | 2096 | v1 = nvalloc(2); |
2088 | 2097 | ||
2089 | while (op) { | 2098 | while (op) { |
2090 | |||
2091 | opinfo = op->info; | 2099 | opinfo = op->info; |
2092 | opn = (short)(opinfo & OPNMASK); | 2100 | opn = (short)(opinfo & OPNMASK); |
2093 | lineno = op->lineno; | 2101 | lineno = op->lineno; |
@@ -2102,9 +2110,9 @@ static var *evaluate(node *op, var *res) | |||
2102 | 2110 | ||
2103 | switch (XC(opinfo & OPCLSMASK)) { | 2111 | switch (XC(opinfo & OPCLSMASK)) { |
2104 | 2112 | ||
2105 | /* -- iterative node type -- */ | 2113 | /* -- iterative node type -- */ |
2106 | 2114 | ||
2107 | /* test pattern */ | 2115 | /* test pattern */ |
2108 | case XC( OC_TEST ): | 2116 | case XC( OC_TEST ): |
2109 | if ((op1->info & OPCLSMASK) == OC_COMMA) { | 2117 | if ((op1->info & OPCLSMASK) == OC_COMMA) { |
2110 | /* it's range pattern */ | 2118 | /* it's range pattern */ |
@@ -2122,21 +2130,21 @@ static var *evaluate(node *op, var *res) | |||
2122 | } | 2130 | } |
2123 | break; | 2131 | break; |
2124 | 2132 | ||
2125 | /* just evaluate an expression, also used as unconditional jump */ | 2133 | /* just evaluate an expression, also used as unconditional jump */ |
2126 | case XC( OC_EXEC ): | 2134 | case XC( OC_EXEC ): |
2127 | break; | 2135 | break; |
2128 | 2136 | ||
2129 | /* branch, used in if-else and various loops */ | 2137 | /* branch, used in if-else and various loops */ |
2130 | case XC( OC_BR ): | 2138 | case XC( OC_BR ): |
2131 | op = istrue(L.v) ? op->a.n : op->r.n; | 2139 | op = istrue(L.v) ? op->a.n : op->r.n; |
2132 | break; | 2140 | break; |
2133 | 2141 | ||
2134 | /* initialize for-in loop */ | 2142 | /* initialize for-in loop */ |
2135 | case XC( OC_WALKINIT ): | 2143 | case XC( OC_WALKINIT ): |
2136 | hashwalk_init(L.v, iamarray(R.v)); | 2144 | hashwalk_init(L.v, iamarray(R.v)); |
2137 | break; | 2145 | break; |
2138 | 2146 | ||
2139 | /* get next array item */ | 2147 | /* get next array item */ |
2140 | case XC( OC_WALKNEXT ): | 2148 | case XC( OC_WALKNEXT ): |
2141 | op = hashwalk_next(L.v) ? op->a.n : op->r.n; | 2149 | op = hashwalk_next(L.v) ? op->a.n : op->r.n; |
2142 | break; | 2150 | break; |
@@ -2224,7 +2232,7 @@ static var *evaluate(node *op, var *res) | |||
2224 | case XC( OC_EXIT ): | 2232 | case XC( OC_EXIT ): |
2225 | awk_exit(L.d); | 2233 | awk_exit(L.d); |
2226 | 2234 | ||
2227 | /* -- recursive node type -- */ | 2235 | /* -- recursive node type -- */ |
2228 | 2236 | ||
2229 | case XC( OC_VAR ): | 2237 | case XC( OC_VAR ): |
2230 | L.v = op->l.v; | 2238 | L.v = op->l.v; |
@@ -2333,7 +2341,7 @@ static var *evaluate(node *op, var *res) | |||
2333 | setvar_i(res, L.i); | 2341 | setvar_i(res, L.i); |
2334 | break; | 2342 | break; |
2335 | 2343 | ||
2336 | /* simple builtins */ | 2344 | /* simple builtins */ |
2337 | case XC( OC_FBLTIN ): | 2345 | case XC( OC_FBLTIN ): |
2338 | switch (opn) { | 2346 | switch (opn) { |
2339 | 2347 | ||
@@ -2344,7 +2352,6 @@ static var *evaluate(node *op, var *res) | |||
2344 | case F_rn: | 2352 | case F_rn: |
2345 | R.d = (double)rand() / (double)RAND_MAX; | 2353 | R.d = (double)rand() / (double)RAND_MAX; |
2346 | break; | 2354 | break; |
2347 | |||
2348 | #if ENABLE_FEATURE_AWK_MATH | 2355 | #if ENABLE_FEATURE_AWK_MATH |
2349 | case F_co: | 2356 | case F_co: |
2350 | R.d = cos(L.d); | 2357 | R.d = cos(L.d); |
@@ -2374,7 +2381,6 @@ static var *evaluate(node *op, var *res) | |||
2374 | runtime_error(EMSG_NO_MATH); | 2381 | runtime_error(EMSG_NO_MATH); |
2375 | break; | 2382 | break; |
2376 | #endif | 2383 | #endif |
2377 | |||
2378 | case F_sr: | 2384 | case F_sr: |
2379 | R.d = (double)seed; | 2385 | R.d = (double)seed; |
2380 | seed = op1 ? (unsigned)L.d : (unsigned)time(NULL); | 2386 | seed = op1 ? (unsigned)L.d : (unsigned)time(NULL); |
@@ -2474,7 +2480,7 @@ static var *evaluate(node *op, var *res) | |||
2474 | } | 2480 | } |
2475 | break; | 2481 | break; |
2476 | 2482 | ||
2477 | /* concatenation (" ") and index joining (",") */ | 2483 | /* concatenation (" ") and index joining (",") */ |
2478 | case XC( OC_CONCAT ): | 2484 | case XC( OC_CONCAT ): |
2479 | case XC( OC_COMMA ): | 2485 | case XC( OC_COMMA ): |
2480 | opn = strlen(L.s) + strlen(R.s) + 2; | 2486 | opn = strlen(L.s) + strlen(R.s) + 2; |
diff --git a/editors/vi.c b/editors/vi.c index a103776d2..66b01e26b 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
@@ -111,8 +111,6 @@ static int last_file_modified = -1; | |||
111 | static int fn_start; // index of first cmd line file name | 111 | static int fn_start; // index of first cmd line file name |
112 | static int save_argc; // how many file names on cmd line | 112 | static int save_argc; // how many file names on cmd line |
113 | static int cmdcnt; // repetition count | 113 | static int cmdcnt; // repetition count |
114 | static fd_set rfds; // use select() for small sleeps | ||
115 | static struct timeval tv; // use select() for small sleeps | ||
116 | static int rows, columns; // the terminal screen is this size | 114 | static int rows, columns; // the terminal screen is this size |
117 | static int crow, ccol, offset; // cursor is on Crow x Ccol with Horz Ofset | 115 | static int crow, ccol, offset; // cursor is on Crow x Ccol with Horz Ofset |
118 | static char *status_buffer; // mesages to the user | 116 | static char *status_buffer; // mesages to the user |
@@ -279,7 +277,7 @@ int vi_main(int argc, char **argv) | |||
279 | #if ENABLE_FEATURE_VI_YANKMARK | 277 | #if ENABLE_FEATURE_VI_YANKMARK |
280 | int i; | 278 | int i; |
281 | #endif | 279 | #endif |
282 | #if defined(CONFIG_FEATURE_VI_USE_SIGNALS) || defined(CONFIG_FEATURE_VI_CRASHME) | 280 | #if ENABLE_FEATURE_VI_USE_SIGNALS || ENABLE_FEATURE_VI_CRASHME |
283 | my_pid = getpid(); | 281 | my_pid = getpid(); |
284 | #endif | 282 | #endif |
285 | #if ENABLE_FEATURE_VI_CRASHME | 283 | #if ENABLE_FEATURE_VI_CRASHME |
@@ -2142,6 +2140,9 @@ static void catch_sig(int sig) | |||
2142 | 2140 | ||
2143 | static int mysleep(int hund) // sleep for 'h' 1/100 seconds | 2141 | static int mysleep(int hund) // sleep for 'h' 1/100 seconds |
2144 | { | 2142 | { |
2143 | fd_set rfds; | ||
2144 | struct timeval tv; | ||
2145 | |||
2145 | // Don't hang- Wait 5/100 seconds- 1 Sec= 1000000 | 2146 | // Don't hang- Wait 5/100 seconds- 1 Sec= 1000000 |
2146 | fflush(stdout); | 2147 | fflush(stdout); |
2147 | FD_ZERO(&rfds); | 2148 | FD_ZERO(&rfds); |
@@ -2228,6 +2229,9 @@ static char readit(void) // read (maybe cursor) key from stdin | |||
2228 | if (n <= 0) | 2229 | if (n <= 0) |
2229 | return 0; // error | 2230 | return 0; // error |
2230 | if (readbuffer[0] == 27) { | 2231 | if (readbuffer[0] == 27) { |
2232 | fd_set rfds; | ||
2233 | struct timeval tv; | ||
2234 | |||
2231 | // This is an ESC char. Is this Esc sequence? | 2235 | // This is an ESC char. Is this Esc sequence? |
2232 | // Could be bare Esc key. See if there are any | 2236 | // Could be bare Esc key. See if there are any |
2233 | // more chars to read after the ESC. This would | 2237 | // more chars to read after the ESC. This would |