diff options
Diffstat (limited to 'editors')
-rw-r--r-- | editors/awk.c | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/editors/awk.c b/editors/awk.c index 17710e57e..9b4d4dc3d 100644 --- a/editors/awk.c +++ b/editors/awk.c | |||
@@ -852,7 +852,7 @@ static char *nextword(char **s) | |||
852 | static char nextchar(char **s) | 852 | static char nextchar(char **s) |
853 | { | 853 | { |
854 | char c, *pps; | 854 | char c, *pps; |
855 | 855 | again: | |
856 | c = *(*s)++; | 856 | c = *(*s)++; |
857 | pps = *s; | 857 | pps = *s; |
858 | if (c == '\\') | 858 | if (c == '\\') |
@@ -863,8 +863,11 @@ static char nextchar(char **s) | |||
863 | */ | 863 | */ |
864 | if (c == '\\' && *s == pps) { /* unrecognized \z? */ | 864 | if (c == '\\' && *s == pps) { /* unrecognized \z? */ |
865 | c = *(*s); /* yes, fetch z */ | 865 | c = *(*s); /* yes, fetch z */ |
866 | if (c) | 866 | if (c) { /* advance unless z = NUL */ |
867 | (*s)++; /* advance unless z = NUL */ | 867 | (*s)++; |
868 | if (c == '\n') /* \<newline>? eat it */ | ||
869 | goto again; | ||
870 | } | ||
868 | } | 871 | } |
869 | return c; | 872 | return c; |
870 | } | 873 | } |
@@ -886,7 +889,13 @@ static ALWAYS_INLINE int isalnum_(int c) | |||
886 | static double my_strtod(char **pp) | 889 | static double my_strtod(char **pp) |
887 | { | 890 | { |
888 | char *cp = *pp; | 891 | char *cp = *pp; |
889 | if (ENABLE_DESKTOP && cp[0] == '0') { | 892 | return strtod(cp, pp); |
893 | } | ||
894 | #if ENABLE_DESKTOP | ||
895 | static double my_strtod_or_hexoct(char **pp) | ||
896 | { | ||
897 | char *cp = *pp; | ||
898 | if (cp[0] == '0') { | ||
890 | /* Might be hex or octal integer: 0x123abc or 07777 */ | 899 | /* Might be hex or octal integer: 0x123abc or 07777 */ |
891 | char c = (cp[1] | 0x20); | 900 | char c = (cp[1] | 0x20); |
892 | if (c == 'x' || isdigit(cp[1])) { | 901 | if (c == 'x' || isdigit(cp[1])) { |
@@ -905,6 +914,9 @@ static double my_strtod(char **pp) | |||
905 | } | 914 | } |
906 | return strtod(cp, pp); | 915 | return strtod(cp, pp); |
907 | } | 916 | } |
917 | #else | ||
918 | # define my_strtod_or_hexoct(p) my_strtod(p) | ||
919 | #endif | ||
908 | 920 | ||
909 | /* -------- working with variables (set/get/copy/etc) -------- */ | 921 | /* -------- working with variables (set/get/copy/etc) -------- */ |
910 | 922 | ||
@@ -1018,6 +1030,7 @@ static double getvar_i(var *v) | |||
1018 | if (s && *s) { | 1030 | if (s && *s) { |
1019 | debug_printf_eval("getvar_i: '%s'->", s); | 1031 | debug_printf_eval("getvar_i: '%s'->", s); |
1020 | v->number = my_strtod(&s); | 1032 | v->number = my_strtod(&s); |
1033 | /* ^^^ hex/oct NOT allowed here! */ | ||
1021 | debug_printf_eval("%f (s:'%s')\n", v->number, s); | 1034 | debug_printf_eval("%f (s:'%s')\n", v->number, s); |
1022 | if (v->type & VF_USER) { | 1035 | if (v->type & VF_USER) { |
1023 | //TODO: skip_spaces() also skips backslash+newline, is it intended here? | 1036 | //TODO: skip_spaces() also skips backslash+newline, is it intended here? |
@@ -1129,10 +1142,10 @@ static uint32_t next_token(uint32_t expected) | |||
1129 | if (*p == '\0') { | 1142 | if (*p == '\0') { |
1130 | tc = TC_EOF; | 1143 | tc = TC_EOF; |
1131 | debug_printf_parse("%s: token found: TC_EOF\n", __func__); | 1144 | debug_printf_parse("%s: token found: TC_EOF\n", __func__); |
1132 | } else if (*p == '\"') { | 1145 | } else if (*p == '"') { |
1133 | /* it's a string */ | 1146 | /* it's a string */ |
1134 | char *s = t_string = ++p; | 1147 | char *s = t_string = ++p; |
1135 | while (*p != '\"') { | 1148 | while (*p != '"') { |
1136 | char *pp; | 1149 | char *pp; |
1137 | if (*p == '\0' || *p == '\n') | 1150 | if (*p == '\0' || *p == '\n') |
1138 | syntax_error(EMSG_UNEXP_EOS); | 1151 | syntax_error(EMSG_UNEXP_EOS); |
@@ -1170,7 +1183,8 @@ static uint32_t next_token(uint32_t expected) | |||
1170 | } else if (*p == '.' || isdigit(*p)) { | 1183 | } else if (*p == '.' || isdigit(*p)) { |
1171 | /* it's a number */ | 1184 | /* it's a number */ |
1172 | char *pp = p; | 1185 | char *pp = p; |
1173 | t_double = my_strtod(&pp); | 1186 | t_double = my_strtod_or_hexoct(&pp); |
1187 | /* ^^^ awk only allows hex/oct consts in _program_, not in _input_ */ | ||
1174 | p = pp; | 1188 | p = pp; |
1175 | if (*p == '.') | 1189 | if (*p == '.') |
1176 | syntax_error(EMSG_UNEXP_TOKEN); | 1190 | syntax_error(EMSG_UNEXP_TOKEN); |
@@ -3528,6 +3542,7 @@ static var *evaluate(node *op, var *res) | |||
3528 | i = (Ld == 0); | 3542 | i = (Ld == 0); |
3529 | break; | 3543 | break; |
3530 | } | 3544 | } |
3545 | debug_printf_eval("COMPARE result: %d\n", (i == 0) ^ (opn & 1)); | ||
3531 | setvar_i(res, (i == 0) ^ (opn & 1)); | 3546 | setvar_i(res, (i == 0) ^ (opn & 1)); |
3532 | break; | 3547 | break; |
3533 | } | 3548 | } |