summaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--editors/awk.c21
-rw-r--r--editors/vi.c48
2 files changed, 39 insertions, 30 deletions
diff --git a/editors/awk.c b/editors/awk.c
index 571d68193..72eca245f 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -973,7 +973,12 @@ static uint32_t next_token(uint32_t expected)
973 973
974 } else if (*p == '.' || isdigit(*p)) { 974 } else if (*p == '.' || isdigit(*p)) {
975 /* it's a number */ 975 /* it's a number */
976 t_double = strtod(p, &p); 976#if ENABLE_DESKTOP
977 if (p[0] == '0' && (p[1] | 0x20) == 'x')
978 t_double = strtoll(p, &p, 0);
979 else
980#endif
981 t_double = strtod(p, &p);
977 if (*p == '.') 982 if (*p == '.')
978 syntax_error(EMSG_UNEXP_TOKEN); 983 syntax_error(EMSG_UNEXP_TOKEN);
979 tc = TC_NUMBER; 984 tc = TC_NUMBER;
@@ -2034,28 +2039,30 @@ static var *exec_builtin(node *op, var *res)
2034 setvar_p(res, s); 2039 setvar_p(res, s);
2035 break; 2040 break;
2036 2041
2042 /* Bitwise ops must assume that operands are unsigned. GNU Awk 3.1.5:
2043 * awk '{ print or(-1,1) }' gives "4.29497e+09", not "-2.xxxe+09" */
2037 case B_an: 2044 case B_an:
2038 setvar_i(res, (long)getvar_i(av[0]) & (long)getvar_i(av[1])); 2045 setvar_i(res, (unsigned long)getvar_i(av[0]) & (unsigned long)getvar_i(av[1]));
2039 break; 2046 break;
2040 2047
2041 case B_co: 2048 case B_co:
2042 setvar_i(res, ~(long)getvar_i(av[0])); 2049 setvar_i(res, ~(unsigned long)getvar_i(av[0]));
2043 break; 2050 break;
2044 2051
2045 case B_ls: 2052 case B_ls:
2046 setvar_i(res, (long)getvar_i(av[0]) << (long)getvar_i(av[1])); 2053 setvar_i(res, (unsigned long)getvar_i(av[0]) << (unsigned long)getvar_i(av[1]));
2047 break; 2054 break;
2048 2055
2049 case B_or: 2056 case B_or:
2050 setvar_i(res, (long)getvar_i(av[0]) | (long)getvar_i(av[1])); 2057 setvar_i(res, (unsigned long)getvar_i(av[0]) | (unsigned long)getvar_i(av[1]));
2051 break; 2058 break;
2052 2059
2053 case B_rs: 2060 case B_rs:
2054 setvar_i(res, (long)((unsigned long)getvar_i(av[0]) >> (unsigned long)getvar_i(av[1]))); 2061 setvar_i(res, (unsigned long)getvar_i(av[0]) >> (unsigned long)getvar_i(av[1]));
2055 break; 2062 break;
2056 2063
2057 case B_xo: 2064 case B_xo:
2058 setvar_i(res, (long)getvar_i(av[0]) ^ (long)getvar_i(av[1])); 2065 setvar_i(res, (unsigned long)getvar_i(av[0]) ^ (unsigned long)getvar_i(av[1]));
2059 break; 2066 break;
2060 2067
2061 case B_lo: 2068 case B_lo:
diff --git a/editors/vi.c b/editors/vi.c
index 27f2a3abd..02bdbb37b 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -147,10 +147,10 @@ struct globals {
147#endif 147#endif
148 148
149 smallint editing; // >0 while we are editing a file 149 smallint editing; // >0 while we are editing a file
150 // [code audit says "can be 0 or 1 only"] 150 // [code audit says "can be 0, 1 or 2 only"]
151 smallint cmd_mode; // 0=command 1=insert 2=replace 151 smallint cmd_mode; // 0=command 1=insert 2=replace
152 int file_modified; // buffer contents changed (counter, not flag!) 152 int file_modified; // buffer contents changed (counter, not flag!)
153 int last_file_modified; // = -1; 153 int last_file_modified; // = -1;
154 int fn_start; // index of first cmd line file name 154 int fn_start; // index of first cmd line file name
155 int save_argc; // how many file names on cmd line 155 int save_argc; // how many file names on cmd line
156 int cmdcnt; // repetition count 156 int cmdcnt; // repetition count
@@ -623,7 +623,7 @@ static void edit_file(char *fn)
623 // These are commands that change text[]. 623 // These are commands that change text[].
624 // Remember the input for the "." command 624 // Remember the input for the "." command
625 if (!adding2q && ioq_start == NULL 625 if (!adding2q && ioq_start == NULL
626 && strchr(modifying_cmds, c) 626 && c != '\0' && strchr(modifying_cmds, c)
627 ) { 627 ) {
628 start_new_cmd_q(c); 628 start_new_cmd_q(c);
629 } 629 }
@@ -645,8 +645,8 @@ static void edit_file(char *fn)
645 } 645 }
646 //------------------------------------------------------------------- 646 //-------------------------------------------------------------------
647 647
648 place_cursor(rows, 0, FALSE); // go to bottom of screen 648 place_cursor(rows - 1, 0, FALSE); // go to bottom of screen
649 clear_to_eol(); // Erase to end of line 649 clear_to_eol(); // erase to end of line
650 cookmode(); 650 cookmode();
651#undef cur_line 651#undef cur_line
652} 652}
@@ -2009,9 +2009,9 @@ static void start_new_cmd_q(char c)
2009{ 2009{
2010 // get buffer for new cmd 2010 // get buffer for new cmd
2011 // if there is a current cmd count put it in the buffer first 2011 // if there is a current cmd count put it in the buffer first
2012 if (cmdcnt > 0) 2012 if (cmdcnt > 0) {
2013 lmc_len = sprintf(last_modifying_cmd, "%d%c", cmdcnt, c); 2013 lmc_len = sprintf(last_modifying_cmd, "%d%c", cmdcnt, c);
2014 else { // just save char c onto queue 2014 } else { // just save char c onto queue
2015 last_modifying_cmd[0] = c; 2015 last_modifying_cmd[0] = c;
2016 lmc_len = 1; 2016 lmc_len = 1;
2017 } 2017 }
@@ -2157,21 +2157,21 @@ static void winch_sig(int sig UNUSED_PARAM)
2157//----- Come here when we get a continue signal ------------------- 2157//----- Come here when we get a continue signal -------------------
2158static void cont_sig(int sig UNUSED_PARAM) 2158static void cont_sig(int sig UNUSED_PARAM)
2159{ 2159{
2160 rawmode(); // terminal to "raw" 2160 rawmode(); // terminal to "raw"
2161 last_status_cksum = 0; // force status update 2161 last_status_cksum = 0; // force status update
2162 redraw(TRUE); // re-draw the screen 2162 redraw(TRUE); // re-draw the screen
2163 2163
2164 signal(SIGTSTP, suspend_sig); 2164 signal(SIGTSTP, suspend_sig);
2165 signal(SIGCONT, SIG_DFL); 2165 signal(SIGCONT, SIG_DFL);
2166 kill(my_pid, SIGCONT); 2166 kill(my_pid, SIGCONT); // huh? why? we are already "continued"...
2167} 2167}
2168 2168
2169//----- Come here when we get a Suspend signal ------------------- 2169//----- Come here when we get a Suspend signal -------------------
2170static void suspend_sig(int sig UNUSED_PARAM) 2170static void suspend_sig(int sig UNUSED_PARAM)
2171{ 2171{
2172 place_cursor(rows - 1, 0, FALSE); // go to bottom of screen 2172 place_cursor(rows - 1, 0, FALSE); // go to bottom of screen
2173 clear_to_eol(); // Erase to end of line 2173 clear_to_eol(); // erase to end of line
2174 cookmode(); // terminal to "cooked" 2174 cookmode(); // terminal to "cooked"
2175 2175
2176 signal(SIGCONT, cont_sig); 2176 signal(SIGCONT, cont_sig);
2177 signal(SIGTSTP, SIG_DFL); 2177 signal(SIGTSTP, SIG_DFL);
@@ -2247,18 +2247,20 @@ static char readit(void) // read (maybe cursor) key from stdin
2247 2247
2248 fflush(stdout); 2248 fflush(stdout);
2249 n = chars_to_parse; 2249 n = chars_to_parse;
2250 // get input from User- are there already input chars in Q? 2250 // get input from User - are there already input chars in Q?
2251 if (n <= 0) { 2251 if (n <= 0) {
2252 // the Q is empty, wait for a typed char 2252 // the Q is empty, wait for a typed char
2253 again:
2253 n = safe_read(STDIN_FILENO, readbuffer, sizeof(readbuffer)); 2254 n = safe_read(STDIN_FILENO, readbuffer, sizeof(readbuffer));
2254 if (n < 0) { 2255 if (n <= 0) {
2255 if (errno == EBADF || errno == EFAULT || errno == EINVAL 2256 place_cursor(rows - 1, 0, FALSE); // go to bottom of screen
2256 || errno == EIO) 2257 clear_to_eol(); // erase to end of line
2257 editing = 0; // want to exit 2258 cookmode(); // terminal to "cooked"
2258 errno = 0; 2259 bb_error_msg_and_die("can't read user input");
2259 } 2260 }
2260 if (n <= 0) 2261 /* elsewhere we can get very confused by NULs */
2261 return 0; // error 2262 if (readbuffer[0] == '\0')
2263 goto again;
2262 if (readbuffer[0] == 27) { 2264 if (readbuffer[0] == 27) {
2263 // This is an ESC char. Is this Esc sequence? 2265 // This is an ESC char. Is this Esc sequence?
2264 // Could be bare Esc key. See if there are any 2266 // Could be bare Esc key. See if there are any