Commits

Anonymous committed f500adc

use memmove instead of shift_buf

Comments (0)

Files changed (1)

 	fflush(stdout);
 }
 
-void shift_buf(char *buf, int ind, int len, int delta)
-{
-	int i;
-
-	for (i = (delta > 0) ? len - 1 : ind ; i >= ind && i < len; i -= (delta > 0) ? 1 : -1)
-		buf[i + delta] = buf[i];
-}
-
 void run()
 {
 	static int escape = 0;
 					case '[' :
 						continue;
 					case '3' : // Delete
-						if (cur != len)
-							shift_buf(usrbuf, cur + 1, len--, -1);
+						if (cur != len) {
+							memmove(usrbuf + cur, usrbuf + cur + 1, len - cur - 1);
+							len--;
+						}
 						escape++;
 						break;
 					case '7' : cur = 0;   escape++;     break; // Home
 					case BACKSPACE :
 					case DEL :
 						if (cur != len)
-							shift_buf(usrbuf, cur, len, -1);
+							memmove(usrbuf + cur - 1, usrbuf + cur, len - cur);
 						cur = MAX(0, cur - 1);
 						len = MAX(0, len - 1);
 						break;
 						 for (; i >=0 && !strchr(word_separators, usrbuf[i]); i--)
 							 ;
 						 i++;
-						 shift_buf(usrbuf, cur, len, -(cur - i));
+						 memmove(usrbuf + i, usrbuf + cur, len - cur);
 						 len -= cur - i;
 						 cur = i;
 						 break;
 						 break;
 					default :
 						 if (cur != len)
-							 shift_buf(usrbuf, cur, len, 1);
+							 memmove(usrbuf + cur + 1, usrbuf + cur, len - cur);
 						 usrbuf[cur++] = c;
 						 len++;
 						 break;