diff options
author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-03-21 00:05:35 +0000 |
---|---|---|
committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-03-21 00:05:35 +0000 |
commit | aaddfc614a370d3187f041b0651edf0cb12f71dd (patch) | |
tree | a5b70f2f2ef7935058904840f38b4f4c45cbdf73 | |
parent | 03448ae0c29cab6c938fed7098b0c177a9009d51 (diff) | |
download | busybox-w32-aaddfc614a370d3187f041b0651edf0cb12f71dd.tar.gz busybox-w32-aaddfc614a370d3187f041b0651edf0cb12f71dd.tar.bz2 busybox-w32-aaddfc614a370d3187f041b0651edf0cb12f71dd.zip |
vi: remove Byte typedef and massive amount of casts.
also optimize many strlen() calls.
if (strlen(buf) <= 0) goto vc1 - ??!!
git-svn-id: svn://busybox.net/trunk/busybox@18188 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r-- | editors/vi.c | 869 |
1 files changed, 445 insertions, 424 deletions
diff --git a/editors/vi.c b/editors/vi.c index 77967fb02..bd169b09d 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
@@ -87,7 +87,9 @@ enum { | |||
87 | S_END_ALNUM = 5, // used in skip_thing() for moving "dot" | 87 | S_END_ALNUM = 5, // used in skip_thing() for moving "dot" |
88 | }; | 88 | }; |
89 | 89 | ||
90 | typedef unsigned char Byte; | 90 | /* vi.c expects chars to be unsigned. */ |
91 | /* busybox build system provides that, but it's better */ | ||
92 | /* to audit and fix the source */ | ||
91 | 93 | ||
92 | static int vi_setops; | 94 | static int vi_setops; |
93 | #define VI_AUTOINDENT 1 | 95 | #define VI_AUTOINDENT 1 |
@@ -112,21 +114,21 @@ static fd_set rfds; // use select() for small sleeps | |||
112 | static struct timeval tv; // use select() for small sleeps | 114 | static struct timeval tv; // use select() for small sleeps |
113 | static int rows, columns; // the terminal screen is this size | 115 | static int rows, columns; // the terminal screen is this size |
114 | static int crow, ccol, offset; // cursor is on Crow x Ccol with Horz Ofset | 116 | static int crow, ccol, offset; // cursor is on Crow x Ccol with Horz Ofset |
115 | static Byte *status_buffer; // mesages to the user | 117 | static char *status_buffer; // mesages to the user |
116 | #define STATUS_BUFFER_LEN 200 | 118 | #define STATUS_BUFFER_LEN 200 |
117 | static int have_status_msg; // is default edit status needed? | 119 | static int have_status_msg; // is default edit status needed? |
118 | static int last_status_cksum; // hash of current status line | 120 | static int last_status_cksum; // hash of current status line |
119 | static Byte *cfn; // previous, current, and next file name | 121 | static char *cfn; // previous, current, and next file name |
120 | static Byte *text, *end; // pointers to the user data in memory | 122 | static char *text, *end; // pointers to the user data in memory |
121 | static Byte *screen; // pointer to the virtual screen buffer | 123 | static char *screen; // pointer to the virtual screen buffer |
122 | static int screensize; // and its size | 124 | static int screensize; // and its size |
123 | static Byte *screenbegin; // index into text[], of top line on the screen | 125 | static char *screenbegin; // index into text[], of top line on the screen |
124 | static Byte *dot; // where all the action takes place | 126 | static char *dot; // where all the action takes place |
125 | static int tabstop; | 127 | static int tabstop; |
126 | static struct termios term_orig, term_vi; // remember what the cooked mode was | 128 | static struct termios term_orig, term_vi; // remember what the cooked mode was |
127 | static Byte erase_char; // the users erase character | 129 | static char erase_char; // the users erase character |
128 | static Byte last_input_char; // last char read from user | 130 | static char last_input_char; // last char read from user |
129 | static Byte last_forward_char; // last char searched for with 'f' | 131 | static char last_forward_char; // last char searched for with 'f' |
130 | 132 | ||
131 | #if ENABLE_FEATURE_VI_OPTIMIZE_CURSOR | 133 | #if ENABLE_FEATURE_VI_OPTIMIZE_CURSOR |
132 | static int last_row; // where the cursor was last moved to | 134 | static int last_row; // where the cursor was last moved to |
@@ -139,38 +141,38 @@ static int my_pid; | |||
139 | #endif | 141 | #endif |
140 | #if ENABLE_FEATURE_VI_DOT_CMD | 142 | #if ENABLE_FEATURE_VI_DOT_CMD |
141 | static int adding2q; // are we currently adding user input to q | 143 | static int adding2q; // are we currently adding user input to q |
142 | static Byte *last_modifying_cmd; // last modifying cmd for "." | 144 | static char *last_modifying_cmd; // last modifying cmd for "." |
143 | static Byte *ioq, *ioq_start; // pointer to string for get_one_char to "read" | 145 | static char *ioq, *ioq_start; // pointer to string for get_one_char to "read" |
144 | #endif | 146 | #endif |
145 | #if ENABLE_FEATURE_VI_DOT_CMD || ENABLE_FEATURE_VI_YANKMARK | 147 | #if ENABLE_FEATURE_VI_DOT_CMD || ENABLE_FEATURE_VI_YANKMARK |
146 | static Byte *modifying_cmds; // cmds that modify text[] | 148 | static char *modifying_cmds; // cmds that modify text[] |
147 | #endif | 149 | #endif |
148 | #if ENABLE_FEATURE_VI_READONLY | 150 | #if ENABLE_FEATURE_VI_READONLY |
149 | static int vi_readonly, readonly; | 151 | static int vi_readonly, readonly; |
150 | #endif | 152 | #endif |
151 | #if ENABLE_FEATURE_VI_YANKMARK | 153 | #if ENABLE_FEATURE_VI_YANKMARK |
152 | static Byte *reg[28]; // named register a-z, "D", and "U" 0-25,26,27 | 154 | static char *reg[28]; // named register a-z, "D", and "U" 0-25,26,27 |
153 | static int YDreg, Ureg; // default delete register and orig line for "U" | 155 | static int YDreg, Ureg; // default delete register and orig line for "U" |
154 | static Byte *mark[28]; // user marks points somewhere in text[]- a-z and previous context '' | 156 | static char *mark[28]; // user marks points somewhere in text[]- a-z and previous context '' |
155 | static Byte *context_start, *context_end; | 157 | static char *context_start, *context_end; |
156 | #endif | 158 | #endif |
157 | #if ENABLE_FEATURE_VI_SEARCH | 159 | #if ENABLE_FEATURE_VI_SEARCH |
158 | static Byte *last_search_pattern; // last pattern from a '/' or '?' search | 160 | static char *last_search_pattern; // last pattern from a '/' or '?' search |
159 | #endif | 161 | #endif |
160 | 162 | ||
161 | 163 | ||
162 | static void edit_file(Byte *); // edit one file | 164 | static void edit_file(char *); // edit one file |
163 | static void do_cmd(Byte); // execute a command | 165 | static void do_cmd(char); // execute a command |
164 | static void sync_cursor(Byte *, int *, int *); // synchronize the screen cursor to dot | 166 | static void sync_cursor(char *, int *, int *); // synchronize the screen cursor to dot |
165 | static Byte *begin_line(Byte *); // return pointer to cur line B-o-l | 167 | static char *begin_line(char *); // return pointer to cur line B-o-l |
166 | static Byte *end_line(Byte *); // return pointer to cur line E-o-l | 168 | static char *end_line(char *); // return pointer to cur line E-o-l |
167 | static Byte *prev_line(Byte *); // return pointer to prev line B-o-l | 169 | static char *prev_line(char *); // return pointer to prev line B-o-l |
168 | static Byte *next_line(Byte *); // return pointer to next line B-o-l | 170 | static char *next_line(char *); // return pointer to next line B-o-l |
169 | static Byte *end_screen(void); // get pointer to last char on screen | 171 | static char *end_screen(void); // get pointer to last char on screen |
170 | static int count_lines(Byte *, Byte *); // count line from start to stop | 172 | static int count_lines(char *, char *); // count line from start to stop |
171 | static Byte *find_line(int); // find begining of line #li | 173 | static char *find_line(int); // find begining of line #li |
172 | static Byte *move_to_col(Byte *, int); // move "p" to column l | 174 | static char *move_to_col(char *, int); // move "p" to column l |
173 | static int isblnk(Byte); // is the char a blank or tab | 175 | static int isblnk(char); // is the char a blank or tab |
174 | static void dot_left(void); // move dot left- dont leave line | 176 | static void dot_left(void); // move dot left- dont leave line |
175 | static void dot_right(void); // move dot right- dont leave line | 177 | static void dot_right(void); // move dot right- dont leave line |
176 | static void dot_begin(void); // move dot to B-o-l | 178 | static void dot_begin(void); // move dot to B-o-l |
@@ -180,27 +182,27 @@ static void dot_prev(void); // move dot to prev line B-o-l | |||
180 | static void dot_scroll(int, int); // move the screen up or down | 182 | static void dot_scroll(int, int); // move the screen up or down |
181 | static void dot_skip_over_ws(void); // move dot pat WS | 183 | static void dot_skip_over_ws(void); // move dot pat WS |
182 | static void dot_delete(void); // delete the char at 'dot' | 184 | static void dot_delete(void); // delete the char at 'dot' |
183 | static Byte *bound_dot(Byte *); // make sure text[0] <= P < "end" | 185 | static char *bound_dot(char *); // make sure text[0] <= P < "end" |
184 | static Byte *new_screen(int, int); // malloc virtual screen memory | 186 | static char *new_screen(int, int); // malloc virtual screen memory |
185 | static Byte *new_text(int); // malloc memory for text[] buffer | 187 | static char *new_text(int); // malloc memory for text[] buffer |
186 | static Byte *char_insert(Byte *, Byte); // insert the char c at 'p' | 188 | static char *char_insert(char *, char); // insert the char c at 'p' |
187 | static Byte *stupid_insert(Byte *, Byte); // stupidly insert the char c at 'p' | 189 | static char *stupid_insert(char *, char); // stupidly insert the char c at 'p' |
188 | static Byte find_range(Byte **, Byte **, Byte); // return pointers for an object | 190 | static char find_range(char **, char **, char); // return pointers for an object |
189 | static int st_test(Byte *, int, int, Byte *); // helper for skip_thing() | 191 | static int st_test(char *, int, int, char *); // helper for skip_thing() |
190 | static Byte *skip_thing(Byte *, int, int, int); // skip some object | 192 | static char *skip_thing(char *, int, int, int); // skip some object |
191 | static Byte *find_pair(Byte *, Byte); // find matching pair () [] {} | 193 | static char *find_pair(char *, char); // find matching pair () [] {} |
192 | static Byte *text_hole_delete(Byte *, Byte *); // at "p", delete a 'size' byte hole | 194 | static char *text_hole_delete(char *, char *); // at "p", delete a 'size' byte hole |
193 | static Byte *text_hole_make(Byte *, int); // at "p", make a 'size' byte hole | 195 | static char *text_hole_make(char *, int); // at "p", make a 'size' byte hole |
194 | static Byte *yank_delete(Byte *, Byte *, int, int); // yank text[] into register then delete | 196 | static char *yank_delete(char *, char *, int, int); // yank text[] into register then delete |
195 | static void show_help(void); // display some help info | 197 | static void show_help(void); // display some help info |
196 | static void rawmode(void); // set "raw" mode on tty | 198 | static void rawmode(void); // set "raw" mode on tty |
197 | static void cookmode(void); // return to "cooked" mode on tty | 199 | static void cookmode(void); // return to "cooked" mode on tty |
198 | static int mysleep(int); // sleep for 'h' 1/100 seconds | 200 | static int mysleep(int); // sleep for 'h' 1/100 seconds |
199 | static Byte readit(void); // read (maybe cursor) key from stdin | 201 | static char readit(void); // read (maybe cursor) key from stdin |
200 | static Byte get_one_char(void); // read 1 char from stdin | 202 | static char get_one_char(void); // read 1 char from stdin |
201 | static int file_size(const Byte *); // what is the byte size of "fn" | 203 | static int file_size(const char *); // what is the byte size of "fn" |
202 | static int file_insert(Byte *, Byte *, int); | 204 | static int file_insert(char *, char *, int); |
203 | static int file_write(Byte *, Byte *, Byte *); | 205 | static int file_write(char *, char *, char *); |
204 | static void place_cursor(int, int, int); | 206 | static void place_cursor(int, int, int); |
205 | static void screen_erase(void); | 207 | static void screen_erase(void); |
206 | static void clear_to_eol(void); | 208 | static void clear_to_eol(void); |
@@ -211,10 +213,10 @@ static void flash(int); // flash the terminal screen | |||
211 | static void show_status_line(void); // put a message on the bottom line | 213 | static void show_status_line(void); // put a message on the bottom line |
212 | static void psb(const char *, ...); // Print Status Buf | 214 | static void psb(const char *, ...); // Print Status Buf |
213 | static void psbs(const char *, ...); // Print Status Buf in standout mode | 215 | static void psbs(const char *, ...); // Print Status Buf in standout mode |
214 | static void ni(Byte *); // display messages | 216 | static void ni(const char *); // display messages |
215 | static int format_edit_status(void); // format file status on status line | 217 | static int format_edit_status(void); // format file status on status line |
216 | static void redraw(int); // force a full screen refresh | 218 | static void redraw(int); // force a full screen refresh |
217 | static void format_line(Byte*, Byte*, int); | 219 | static void format_line(char*, char*, int); |
218 | static void refresh(int); // update the terminal from screen[] | 220 | static void refresh(int); // update the terminal from screen[] |
219 | 221 | ||
220 | static void Indicate_Error(void); // use flash or beep to indicate error | 222 | static void Indicate_Error(void); // use flash or beep to indicate error |
@@ -222,13 +224,13 @@ static void Indicate_Error(void); // use flash or beep to indicate error | |||
222 | static void Hit_Return(void); | 224 | static void Hit_Return(void); |
223 | 225 | ||
224 | #if ENABLE_FEATURE_VI_SEARCH | 226 | #if ENABLE_FEATURE_VI_SEARCH |
225 | static Byte *char_search(Byte *, Byte *, int, int); // search for pattern starting at p | 227 | static char *char_search(char *, const char *, int, int); // search for pattern starting at p |
226 | static int mycmp(Byte *, Byte *, int); // string cmp based in "ignorecase" | 228 | static int mycmp(const char *, const char *, int); // string cmp based in "ignorecase" |
227 | #endif | 229 | #endif |
228 | #if ENABLE_FEATURE_VI_COLON | 230 | #if ENABLE_FEATURE_VI_COLON |
229 | static Byte *get_one_address(Byte *, int *); // get colon addr, if present | 231 | static char *get_one_address(char *, int *); // get colon addr, if present |
230 | static Byte *get_address(Byte *, int *, int *); // get two colon addrs, if present | 232 | static char *get_address(char *, int *, int *); // get two colon addrs, if present |
231 | static void colon(Byte *); // execute the "colon" mode cmds | 233 | static void colon(char *); // execute the "colon" mode cmds |
232 | #endif | 234 | #endif |
233 | #if ENABLE_FEATURE_VI_USE_SIGNALS | 235 | #if ENABLE_FEATURE_VI_USE_SIGNALS |
234 | static void winch_sig(int); // catch window size changes | 236 | static void winch_sig(int); // catch window size changes |
@@ -236,21 +238,21 @@ static void suspend_sig(int); // catch ctrl-Z | |||
236 | static void catch_sig(int); // catch ctrl-C and alarm time-outs | 238 | static void catch_sig(int); // catch ctrl-C and alarm time-outs |
237 | #endif | 239 | #endif |
238 | #if ENABLE_FEATURE_VI_DOT_CMD | 240 | #if ENABLE_FEATURE_VI_DOT_CMD |
239 | static void start_new_cmd_q(Byte); // new queue for command | 241 | static void start_new_cmd_q(char); // new queue for command |
240 | static void end_cmd_q(void); // stop saving input chars | 242 | static void end_cmd_q(void); // stop saving input chars |
241 | #else | 243 | #else |
242 | #define end_cmd_q() ((void)0) | 244 | #define end_cmd_q() ((void)0) |
243 | #endif | 245 | #endif |
244 | #if ENABLE_FEATURE_VI_SETOPTS | 246 | #if ENABLE_FEATURE_VI_SETOPTS |
245 | static void showmatching(Byte *); // show the matching pair () [] {} | 247 | static void showmatching(char *); // show the matching pair () [] {} |
246 | #endif | 248 | #endif |
247 | #if ENABLE_FEATURE_VI_YANKMARK || (ENABLE_FEATURE_VI_COLON && ENABLE_FEATURE_VI_SEARCH) || ENABLE_FEATURE_VI_CRASHME | 249 | #if ENABLE_FEATURE_VI_YANKMARK || (ENABLE_FEATURE_VI_COLON && ENABLE_FEATURE_VI_SEARCH) || ENABLE_FEATURE_VI_CRASHME |
248 | static Byte *string_insert(Byte *, Byte *); // insert the string at 'p' | 250 | static char *string_insert(char *, char *); // insert the string at 'p' |
249 | #endif | 251 | #endif |
250 | #if ENABLE_FEATURE_VI_YANKMARK | 252 | #if ENABLE_FEATURE_VI_YANKMARK |
251 | static Byte *text_yank(Byte *, Byte *, int); // save copy of "p" into a register | 253 | static char *text_yank(char *, char *, int); // save copy of "p" into a register |
252 | static Byte what_reg(void); // what is letter of current YDreg | 254 | static char what_reg(void); // what is letter of current YDreg |
253 | static void check_context(Byte); // remember context for '' command | 255 | static void check_context(char); // remember context for '' command |
254 | #endif | 256 | #endif |
255 | #if ENABLE_FEATURE_VI_CRASHME | 257 | #if ENABLE_FEATURE_VI_CRASHME |
256 | static void crash_dummy(); | 258 | static void crash_dummy(); |
@@ -278,10 +280,10 @@ int vi_main(int argc, char **argv) | |||
278 | my_pid = getpid(); | 280 | my_pid = getpid(); |
279 | #endif | 281 | #endif |
280 | #if ENABLE_FEATURE_VI_CRASHME | 282 | #if ENABLE_FEATURE_VI_CRASHME |
281 | (void) srand((long) my_pid); | 283 | srand((long) my_pid); |
282 | #endif | 284 | #endif |
283 | 285 | ||
284 | status_buffer = (Byte *)STATUS_BUFFER; | 286 | status_buffer = STATUS_BUFFER; |
285 | last_status_cksum = 0; | 287 | last_status_cksum = 0; |
286 | 288 | ||
287 | #if ENABLE_FEATURE_VI_READONLY | 289 | #if ENABLE_FEATURE_VI_READONLY |
@@ -298,7 +300,7 @@ int vi_main(int argc, char **argv) | |||
298 | } // init the yank regs | 300 | } // init the yank regs |
299 | #endif | 301 | #endif |
300 | #if ENABLE_FEATURE_VI_DOT_CMD || ENABLE_FEATURE_VI_YANKMARK | 302 | #if ENABLE_FEATURE_VI_DOT_CMD || ENABLE_FEATURE_VI_YANKMARK |
301 | modifying_cmds = (Byte *) "aAcCdDiIJoOpPrRsxX<>~"; // cmds modifying text[] | 303 | modifying_cmds = (char *) "aAcCdDiIJoOpPrRsxX<>~"; // cmds modifying text[] |
302 | #endif | 304 | #endif |
303 | 305 | ||
304 | // 1- process $HOME/.exrc file (not inplemented yet) | 306 | // 1- process $HOME/.exrc file (not inplemented yet) |
@@ -349,7 +351,7 @@ int vi_main(int argc, char **argv) | |||
349 | for (; optind < argc; optind++) { | 351 | for (; optind < argc; optind++) { |
350 | editing = 1; // 0=exit, 1=one file, 2+ =many files | 352 | editing = 1; // 0=exit, 1=one file, 2+ =many files |
351 | free(cfn); | 353 | free(cfn); |
352 | cfn = (Byte *) xstrdup(argv[optind]); | 354 | cfn = xstrdup(argv[optind]); |
353 | edit_file(cfn); | 355 | edit_file(cfn); |
354 | } | 356 | } |
355 | } | 357 | } |
@@ -358,22 +360,22 @@ int vi_main(int argc, char **argv) | |||
358 | return 0; | 360 | return 0; |
359 | } | 361 | } |
360 | 362 | ||
361 | static void edit_file(Byte * fn) | 363 | static void edit_file(char * fn) |
362 | { | 364 | { |
363 | Byte c; | 365 | char c; |
364 | int cnt, size, ch; | 366 | int cnt, size, ch; |
365 | 367 | ||
366 | #if ENABLE_FEATURE_VI_USE_SIGNALS | 368 | #if ENABLE_FEATURE_VI_USE_SIGNALS |
367 | int sig; | 369 | int sig; |
368 | #endif | 370 | #endif |
369 | #if ENABLE_FEATURE_VI_YANKMARK | 371 | #if ENABLE_FEATURE_VI_YANKMARK |
370 | static Byte *cur_line; | 372 | static char *cur_line; |
371 | #endif | 373 | #endif |
372 | 374 | ||
373 | rawmode(); | 375 | rawmode(); |
374 | rows = 24; | 376 | rows = 24; |
375 | columns = 80; | 377 | columns = 80; |
376 | ch= -1; | 378 | ch = -1; |
377 | if (ENABLE_FEATURE_VI_WIN_RESIZE) | 379 | if (ENABLE_FEATURE_VI_WIN_RESIZE) |
378 | get_terminal_width_height(0, &columns, &rows); | 380 | get_terminal_width_height(0, &columns, &rows); |
379 | new_screen(rows, columns); // get memory for virtual screen | 381 | new_screen(rows, columns); // get memory for virtual screen |
@@ -383,10 +385,10 @@ static void edit_file(Byte * fn) | |||
383 | new_text(size); // get a text[] buffer | 385 | new_text(size); // get a text[] buffer |
384 | screenbegin = dot = end = text; | 386 | screenbegin = dot = end = text; |
385 | if (fn != 0) { | 387 | if (fn != 0) { |
386 | ch= file_insert(fn, text, cnt); | 388 | ch = file_insert(fn, text, cnt); |
387 | } | 389 | } |
388 | if (ch < 1) { | 390 | if (ch < 1) { |
389 | (void) char_insert(text, '\n'); // start empty buf with dummy line | 391 | char_insert(text, '\n'); // start empty buf with dummy line |
390 | } | 392 | } |
391 | file_modified = 0; | 393 | file_modified = 0; |
392 | last_file_modified = -1; | 394 | last_file_modified = -1; |
@@ -422,7 +424,7 @@ static void edit_file(Byte * fn) | |||
422 | #if ENABLE_FEATURE_VI_DOT_CMD | 424 | #if ENABLE_FEATURE_VI_DOT_CMD |
423 | free(last_modifying_cmd); | 425 | free(last_modifying_cmd); |
424 | free(ioq_start); | 426 | free(ioq_start); |
425 | ioq = ioq_start = last_modifying_cmd = 0; | 427 | ioq = ioq_start = last_modifying_cmd = NULL; |
426 | adding2q = 0; | 428 | adding2q = 0; |
427 | #endif | 429 | #endif |
428 | redraw(FALSE); // dont force every col re-draw | 430 | redraw(FALSE); // dont force every col re-draw |
@@ -455,8 +457,7 @@ static void edit_file(Byte * fn) | |||
455 | crash_dummy(); // generate a random command | 457 | crash_dummy(); // generate a random command |
456 | } else { | 458 | } else { |
457 | crashme = 0; | 459 | crashme = 0; |
458 | dot = | 460 | dot = string_insert(text, "\n\n##### Ran out of text to work on. #####\n\n"); // insert the string |
459 | string_insert(text, (Byte *) "\n\n##### Ran out of text to work on. #####\n\n"); // insert the string | ||
460 | refresh(FALSE); | 461 | refresh(FALSE); |
461 | } | 462 | } |
462 | } | 463 | } |
@@ -473,7 +474,8 @@ static void edit_file(Byte * fn) | |||
473 | // These are commands that change text[]. | 474 | // These are commands that change text[]. |
474 | // Remember the input for the "." command | 475 | // Remember the input for the "." command |
475 | if (!adding2q && ioq_start == 0 | 476 | if (!adding2q && ioq_start == 0 |
476 | && strchr((char *) modifying_cmds, c) != NULL) { | 477 | && strchr(modifying_cmds, c) |
478 | ) { | ||
477 | start_new_cmd_q(c); | 479 | start_new_cmd_q(c); |
478 | } | 480 | } |
479 | #endif | 481 | #endif |
@@ -501,16 +503,16 @@ static void edit_file(Byte * fn) | |||
501 | 503 | ||
502 | //----- The Colon commands ------------------------------------- | 504 | //----- The Colon commands ------------------------------------- |
503 | #if ENABLE_FEATURE_VI_COLON | 505 | #if ENABLE_FEATURE_VI_COLON |
504 | static Byte *get_one_address(Byte * p, int *addr) // get colon addr, if present | 506 | static char *get_one_address(char * p, int *addr) // get colon addr, if present |
505 | { | 507 | { |
506 | int st; | 508 | int st; |
507 | Byte *q; | 509 | char *q; |
508 | 510 | ||
509 | #if ENABLE_FEATURE_VI_YANKMARK | 511 | #if ENABLE_FEATURE_VI_YANKMARK |
510 | Byte c; | 512 | char c; |
511 | #endif | 513 | #endif |
512 | #if ENABLE_FEATURE_VI_SEARCH | 514 | #if ENABLE_FEATURE_VI_SEARCH |
513 | Byte *pat, buf[BUFSIZ]; | 515 | char *pat, buf[BUFSIZ]; |
514 | #endif | 516 | #endif |
515 | 517 | ||
516 | *addr = -1; // assume no addr | 518 | *addr = -1; // assume no addr |
@@ -526,7 +528,7 @@ static Byte *get_one_address(Byte * p, int *addr) // get colon addr, if present | |||
526 | if (c >= 'a' && c <= 'z') { | 528 | if (c >= 'a' && c <= 'z') { |
527 | // we have a mark | 529 | // we have a mark |
528 | c = c - 'a'; | 530 | c = c - 'a'; |
529 | q = mark[(int) c]; | 531 | q = mark[(unsigned char) c]; |
530 | if (q != NULL) { // is mark valid | 532 | if (q != NULL) { // is mark valid |
531 | *addr = count_lines(text, q); // count lines | 533 | *addr = count_lines(text, q); // count lines |
532 | } | 534 | } |
@@ -541,7 +543,7 @@ static Byte *get_one_address(Byte * p, int *addr) // get colon addr, if present | |||
541 | *q++ = *p; | 543 | *q++ = *p; |
542 | *q = '\0'; | 544 | *q = '\0'; |
543 | } | 545 | } |
544 | pat = (Byte *) xstrdup((char *) buf); // save copy of pattern | 546 | pat = xstrdup(buf); // save copy of pattern |
545 | if (*p == '/') | 547 | if (*p == '/') |
546 | p++; | 548 | p++; |
547 | q = char_search(dot, pat, FORWARD, FULL); | 549 | q = char_search(dot, pat, FORWARD, FULL); |
@@ -555,7 +557,7 @@ static Byte *get_one_address(Byte * p, int *addr) // get colon addr, if present | |||
555 | q = begin_line(end - 1); | 557 | q = begin_line(end - 1); |
556 | *addr = count_lines(text, q); | 558 | *addr = count_lines(text, q); |
557 | } else if (isdigit(*p)) { // specific line number | 559 | } else if (isdigit(*p)) { // specific line number |
558 | sscanf((char *) p, "%d%n", addr, &st); | 560 | sscanf(p, "%d%n", addr, &st); |
559 | p += st; | 561 | p += st; |
560 | } else { // I don't reconise this | 562 | } else { // I don't reconise this |
561 | // unrecognised address- assume -1 | 563 | // unrecognised address- assume -1 |
@@ -564,7 +566,7 @@ static Byte *get_one_address(Byte * p, int *addr) // get colon addr, if present | |||
564 | return p; | 566 | return p; |
565 | } | 567 | } |
566 | 568 | ||
567 | static Byte *get_address(Byte *p, int *b, int *e) // get two colon addrs, if present | 569 | static char *get_address(char *p, int *b, int *e) // get two colon addrs, if present |
568 | { | 570 | { |
569 | //----- get the address' i.e., 1,3 'a,'b ----- | 571 | //----- get the address' i.e., 1,3 'a,'b ----- |
570 | // get FIRST addr, if present | 572 | // get FIRST addr, if present |
@@ -586,33 +588,34 @@ static Byte *get_address(Byte *p, int *b, int *e) // get two colon addrs, if pre | |||
586 | // get SECOND addr, if present | 588 | // get SECOND addr, if present |
587 | p = get_one_address(p, e); | 589 | p = get_one_address(p, e); |
588 | } | 590 | } |
589 | ga0: | 591 | ga0: |
590 | while (isblnk(*p)) | 592 | while (isblnk(*p)) |
591 | p++; // skip over trailing spaces | 593 | p++; // skip over trailing spaces |
592 | return p; | 594 | return p; |
593 | } | 595 | } |
594 | 596 | ||
595 | #if ENABLE_FEATURE_VI_SET && ENABLE_FEATURE_VI_SETOPTS | 597 | #if ENABLE_FEATURE_VI_SET && ENABLE_FEATURE_VI_SETOPTS |
596 | static void setops(const Byte *args, const char *opname, int flg_no, | 598 | static void setops(const char *args, const char *opname, int flg_no, |
597 | const char *short_opname, int opt) | 599 | const char *short_opname, int opt) |
598 | { | 600 | { |
599 | const char *a = (char *) args + flg_no; | 601 | const char *a = args + flg_no; |
600 | int l = strlen(opname) - 1; /* opname have + ' ' */ | 602 | int l = strlen(opname) - 1; /* opname have + ' ' */ |
601 | 603 | ||
602 | if (strncasecmp(a, opname, l) == 0 || | 604 | if (strncasecmp(a, opname, l) == 0 |
603 | strncasecmp(a, short_opname, 2) == 0) { | 605 | || strncasecmp(a, short_opname, 2) == 0 |
604 | if(flg_no) | 606 | ) { |
607 | if (flg_no) | ||
605 | vi_setops &= ~opt; | 608 | vi_setops &= ~opt; |
606 | else | 609 | else |
607 | vi_setops |= opt; | 610 | vi_setops |= opt; |
608 | } | 611 | } |
609 | } | 612 | } |
610 | #endif | 613 | #endif |
611 | 614 | ||
612 | static void colon(Byte * buf) | 615 | static void colon(char * buf) |
613 | { | 616 | { |
614 | Byte c, *orig_buf, *buf1, *q, *r; | 617 | char c, *orig_buf, *buf1, *q, *r; |
615 | Byte *fn, cmd[BUFSIZ], args[BUFSIZ]; | 618 | char *fn, cmd[BUFSIZ], args[BUFSIZ]; |
616 | int i, l, li, ch, b, e; | 619 | int i, l, li, ch, b, e; |
617 | int useforce = FALSE, forced = FALSE; | 620 | int useforce = FALSE, forced = FALSE; |
618 | struct stat st_buf; | 621 | struct stat st_buf; |
@@ -632,7 +635,7 @@ static void colon(Byte * buf) | |||
632 | // :!<cmd> // run <cmd> then return | 635 | // :!<cmd> // run <cmd> then return |
633 | // | 636 | // |
634 | 637 | ||
635 | if (strlen((char *) buf) <= 0) | 638 | if (!buf[0]) |
636 | goto vc1; | 639 | goto vc1; |
637 | if (*buf == ':') | 640 | if (*buf == ':') |
638 | buf++; // move past the ':' | 641 | buf++; // move past the ':' |
@@ -662,8 +665,8 @@ static void colon(Byte * buf) | |||
662 | // get any ARGuments | 665 | // get any ARGuments |
663 | while (isblnk(*buf)) | 666 | while (isblnk(*buf)) |
664 | buf++; | 667 | buf++; |
665 | strcpy((char *) args, (char *) buf); | 668 | strcpy(args, buf); |
666 | buf1 = (Byte*)last_char_is((char *)cmd, '!'); | 669 | buf1 = last_char_is(cmd, '!'); |
667 | if (buf1) { | 670 | if (buf1) { |
668 | useforce = TRUE; | 671 | useforce = TRUE; |
669 | *buf1 = '\0'; // get rid of ! | 672 | *buf1 = '\0'; // get rid of ! |
@@ -685,7 +688,7 @@ static void colon(Byte * buf) | |||
685 | li = e - b + 1; | 688 | li = e - b + 1; |
686 | } | 689 | } |
687 | // ------------ now look for the command ------------ | 690 | // ------------ now look for the command ------------ |
688 | i = strlen((char *) cmd); | 691 | i = strlen(cmd); |
689 | if (i == 0) { // :123CR goto line #123 | 692 | if (i == 0) { // :123CR goto line #123 |
690 | if (b >= 0) { | 693 | if (b >= 0) { |
691 | dot = find_line(b); // what line is #b | 694 | dot = find_line(b); // what line is #b |
@@ -693,31 +696,31 @@ static void colon(Byte * buf) | |||
693 | } | 696 | } |
694 | } | 697 | } |
695 | #if ENABLE_FEATURE_ALLOW_EXEC | 698 | #if ENABLE_FEATURE_ALLOW_EXEC |
696 | else if (strncmp((char *) cmd, "!", 1) == 0) { // run a cmd | 699 | else if (strncmp(cmd, "!", 1) == 0) { // run a cmd |
697 | // :!ls run the <cmd> | 700 | // :!ls run the <cmd> |
698 | (void) alarm(0); // wait for input- no alarms | 701 | alarm(0); // wait for input- no alarms |
699 | place_cursor(rows - 1, 0, FALSE); // go to Status line | 702 | place_cursor(rows - 1, 0, FALSE); // go to Status line |
700 | clear_to_eol(); // clear the line | 703 | clear_to_eol(); // clear the line |
701 | cookmode(); | 704 | cookmode(); |
702 | system((char*)(orig_buf+1)); // run the cmd | 705 | system(orig_buf + 1); // run the cmd |
703 | rawmode(); | 706 | rawmode(); |
704 | Hit_Return(); // let user see results | 707 | Hit_Return(); // let user see results |
705 | (void) alarm(3); // done waiting for input | 708 | alarm(3); // done waiting for input |
706 | } | 709 | } |
707 | #endif | 710 | #endif |
708 | else if (strncmp((char *) cmd, "=", i) == 0) { // where is the address | 711 | else if (strncmp(cmd, "=", i) == 0) { // where is the address |
709 | if (b < 0) { // no addr given- use defaults | 712 | if (b < 0) { // no addr given- use defaults |
710 | b = e = count_lines(text, dot); | 713 | b = e = count_lines(text, dot); |
711 | } | 714 | } |
712 | psb("%d", b); | 715 | psb("%d", b); |
713 | } else if (strncasecmp((char *) cmd, "delete", i) == 0) { // delete lines | 716 | } else if (strncasecmp(cmd, "delete", i) == 0) { // delete lines |
714 | if (b < 0) { // no addr given- use defaults | 717 | if (b < 0) { // no addr given- use defaults |
715 | q = begin_line(dot); // assume .,. for the range | 718 | q = begin_line(dot); // assume .,. for the range |
716 | r = end_line(dot); | 719 | r = end_line(dot); |
717 | } | 720 | } |
718 | dot = yank_delete(q, r, 1, YANKDEL); // save, then delete lines | 721 | dot = yank_delete(q, r, 1, YANKDEL); // save, then delete lines |
719 | dot_skip_over_ws(); | 722 | dot_skip_over_ws(); |
720 | } else if (strncasecmp((char *) cmd, "edit", i) == 0) { // Edit a file | 723 | } else if (strncasecmp(cmd, "edit", i) == 0) { // Edit a file |
721 | int sr; | 724 | int sr; |
722 | sr= 0; | 725 | sr= 0; |
723 | // don't edit, if the current file has been modified | 726 | // don't edit, if the current file has been modified |
@@ -725,10 +728,10 @@ static void colon(Byte * buf) | |||
725 | psbs("No write since last change (:edit! overrides)"); | 728 | psbs("No write since last change (:edit! overrides)"); |
726 | goto vc1; | 729 | goto vc1; |
727 | } | 730 | } |
728 | if (strlen((char*)args) > 0) { | 731 | if (args[0]) { |
729 | // the user supplied a file name | 732 | // the user supplied a file name |
730 | fn= args; | 733 | fn= args; |
731 | } else if (cfn != 0 && strlen((char*)cfn) > 0) { | 734 | } else if (cfn && cfn[0]) { |
732 | // no user supplied name- use the current filename | 735 | // no user supplied name- use the current filename |
733 | fn= cfn; | 736 | fn= cfn; |
734 | goto vc5; | 737 | goto vc5; |
@@ -739,13 +742,14 @@ static void colon(Byte * buf) | |||
739 | } | 742 | } |
740 | 743 | ||
741 | // see if file exists- if not, its just a new file request | 744 | // see if file exists- if not, its just a new file request |
742 | if ((sr=stat((char*)fn, &st_buf)) < 0) { | 745 | sr = stat(fn, &st_buf); |
746 | if (sr < 0) { | ||
743 | // This is just a request for a new file creation. | 747 | // This is just a request for a new file creation. |
744 | // The file_insert below will fail but we get | 748 | // The file_insert below will fail but we get |
745 | // an empty buffer with a file name. Then the "write" | 749 | // an empty buffer with a file name. Then the "write" |
746 | // command can do the create. | 750 | // command can do the create. |
747 | } else { | 751 | } else { |
748 | if ((st_buf.st_mode & (S_IFREG)) == 0) { | 752 | if ((st_buf.st_mode & S_IFREG) == 0) { |
749 | // This is not a regular file | 753 | // This is not a regular file |
750 | psbs("\"%s\" is not a regular file", fn); | 754 | psbs("\"%s\" is not a regular file", fn); |
751 | goto vc1; | 755 | goto vc1; |
@@ -759,7 +763,7 @@ static void colon(Byte * buf) | |||
759 | 763 | ||
760 | // There is a read-able regular file | 764 | // There is a read-able regular file |
761 | // make this the current file | 765 | // make this the current file |
762 | q = (Byte *) xstrdup((char *) fn); // save the cfn | 766 | q = xstrdup(fn); // save the cfn |
763 | free(cfn); // free the old name | 767 | free(cfn); // free the old name |
764 | cfn = q; // remember new cfn | 768 | cfn = q; // remember new cfn |
765 | 769 | ||
@@ -773,8 +777,8 @@ static void colon(Byte * buf) | |||
773 | 777 | ||
774 | if (ch < 1) { | 778 | if (ch < 1) { |
775 | // start empty buf with dummy line | 779 | // start empty buf with dummy line |
776 | (void) char_insert(text, '\n'); | 780 | char_insert(text, '\n'); |
777 | ch= 1; | 781 | ch = 1; |
778 | } | 782 | } |
779 | file_modified = 0; | 783 | file_modified = 0; |
780 | last_file_modified = -1; | 784 | last_file_modified = -1; |
@@ -803,20 +807,20 @@ static void colon(Byte * buf) | |||
803 | ((vi_readonly || readonly) ? " [Read only]" : ""), | 807 | ((vi_readonly || readonly) ? " [Read only]" : ""), |
804 | #endif | 808 | #endif |
805 | li, ch); | 809 | li, ch); |
806 | } else if (strncasecmp((char *) cmd, "file", i) == 0) { // what File is this | 810 | } else if (strncasecmp(cmd, "file", i) == 0) { // what File is this |
807 | if (b != -1 || e != -1) { | 811 | if (b != -1 || e != -1) { |
808 | ni((Byte *) "No address allowed on this command"); | 812 | ni("No address allowed on this command"); |
809 | goto vc1; | 813 | goto vc1; |
810 | } | 814 | } |
811 | if (strlen((char *) args) > 0) { | 815 | if (args[0]) { |
812 | // user wants a new filename | 816 | // user wants a new filename |
813 | free(cfn); | 817 | free(cfn); |
814 | cfn = (Byte *) xstrdup((char *) args); | 818 | cfn = xstrdup(args); |
815 | } else { | 819 | } else { |
816 | // user wants file status info | 820 | // user wants file status info |
817 | last_status_cksum = 0; // force status update | 821 | last_status_cksum = 0; // force status update |
818 | } | 822 | } |
819 | } else if (strncasecmp((char *) cmd, "features", i) == 0) { // what features are available | 823 | } else if (strncasecmp(cmd, "features", i) == 0) { // what features are available |
820 | // print out values of all features | 824 | // print out values of all features |
821 | place_cursor(rows - 1, 0, FALSE); // go to Status line, bottom of screen | 825 | place_cursor(rows - 1, 0, FALSE); // go to Status line, bottom of screen |
822 | clear_to_eol(); // clear the line | 826 | clear_to_eol(); // clear the line |
@@ -824,7 +828,7 @@ static void colon(Byte * buf) | |||
824 | show_help(); | 828 | show_help(); |
825 | rawmode(); | 829 | rawmode(); |
826 | Hit_Return(); | 830 | Hit_Return(); |
827 | } else if (strncasecmp((char *) cmd, "list", i) == 0) { // literal print line | 831 | } else if (strncasecmp(cmd, "list", i) == 0) { // literal print line |
828 | if (b < 0) { // no addr given- use defaults | 832 | if (b < 0) { // no addr given- use defaults |
829 | q = begin_line(dot); // assume .,. for the range | 833 | q = begin_line(dot); // assume .,. for the range |
830 | r = end_line(dot); | 834 | r = end_line(dot); |
@@ -845,10 +849,10 @@ static void colon(Byte * buf) | |||
845 | write1("$\r"); | 849 | write1("$\r"); |
846 | } else if (c < ' ' || c == 127) { | 850 | } else if (c < ' ' || c == 127) { |
847 | putchar('^'); | 851 | putchar('^'); |
848 | if(c == 127) | 852 | if (c == 127) |
849 | c = '?'; | 853 | c = '?'; |
850 | else | 854 | else |
851 | c += '@'; | 855 | c += '@'; |
852 | } | 856 | } |
853 | putchar(c); | 857 | putchar(c); |
854 | if (c_is_no_print) | 858 | if (c_is_no_print) |
@@ -858,8 +862,9 @@ static void colon(Byte * buf) | |||
858 | vc2: | 862 | vc2: |
859 | #endif | 863 | #endif |
860 | Hit_Return(); | 864 | Hit_Return(); |
861 | } else if ((strncasecmp((char *) cmd, "quit", i) == 0) || // Quit | 865 | } else if (strncasecmp(cmd, "quit", i) == 0 // Quit |
862 | (strncasecmp((char *) cmd, "next", i) == 0)) { // edit next file | 866 | || strncasecmp(cmd, "next", i) == 0 // edit next file |
867 | ) { | ||
863 | if (useforce) { | 868 | if (useforce) { |
864 | // force end of argv list | 869 | // force end of argv list |
865 | if (*cmd == 'q') { | 870 | if (*cmd == 'q') { |
@@ -884,9 +889,9 @@ static void colon(Byte * buf) | |||
884 | goto vc1; | 889 | goto vc1; |
885 | } | 890 | } |
886 | editing = 0; | 891 | editing = 0; |
887 | } else if (strncasecmp((char *) cmd, "read", i) == 0) { // read file into text[] | 892 | } else if (strncasecmp(cmd, "read", i) == 0) { // read file into text[] |
888 | fn = args; | 893 | fn = args; |
889 | if (strlen((char *) fn) <= 0) { | 894 | if (!fn[0]) { |
890 | psbs("No filename given"); | 895 | psbs("No filename given"); |
891 | goto vc1; | 896 | goto vc1; |
892 | } | 897 | } |
@@ -897,7 +902,7 @@ static void colon(Byte * buf) | |||
897 | if (b != 0) | 902 | if (b != 0) |
898 | q = next_line(q); | 903 | q = next_line(q); |
899 | #if ENABLE_FEATURE_VI_READONLY | 904 | #if ENABLE_FEATURE_VI_READONLY |
900 | l= readonly; // remember current files' status | 905 | l = readonly; // remember current files' status |
901 | #endif | 906 | #endif |
902 | ch = file_insert(fn, q, file_size(fn)); | 907 | ch = file_insert(fn, q, file_size(fn)); |
903 | #if ENABLE_FEATURE_VI_READONLY | 908 | #if ENABLE_FEATURE_VI_READONLY |
@@ -922,7 +927,7 @@ static void colon(Byte * buf) | |||
922 | dot += ch; | 927 | dot += ch; |
923 | file_modified++; | 928 | file_modified++; |
924 | } | 929 | } |
925 | } else if (strncasecmp((char *) cmd, "rewind", i) == 0) { // rewind cmd line args | 930 | } else if (strncasecmp(cmd, "rewind", i) == 0) { // rewind cmd line args |
926 | if (file_modified && ! useforce) { | 931 | if (file_modified && ! useforce) { |
927 | psbs("No write since last change (:rewind! overrides)"); | 932 | psbs("No write since last change (:rewind! overrides)"); |
928 | } else { | 933 | } else { |
@@ -959,7 +964,7 @@ static void colon(Byte * buf) | |||
959 | goto vc2; | 964 | goto vc2; |
960 | } | 965 | } |
961 | #if ENABLE_FEATURE_VI_SETOPTS | 966 | #if ENABLE_FEATURE_VI_SETOPTS |
962 | argp = (char *)args; | 967 | argp = args; |
963 | while (*argp) { | 968 | while (*argp) { |
964 | if (strncasecmp(argp, "no", 2) == 0) | 969 | if (strncasecmp(argp, "no", 2) == 0) |
965 | i = 2; // ":set noautoindent" | 970 | i = 2; // ":set noautoindent" |
@@ -969,7 +974,7 @@ static void colon(Byte * buf) | |||
969 | setops(argp, "showmatch ", i, "ic", VI_SHOWMATCH); | 974 | setops(argp, "showmatch ", i, "ic", VI_SHOWMATCH); |
970 | /* tabstopXXXX */ | 975 | /* tabstopXXXX */ |
971 | if (strncasecmp(argp + i, "tabstop=%d ", 7) == 0) { | 976 | if (strncasecmp(argp + i, "tabstop=%d ", 7) == 0) { |
972 | sscanf(strchr(argp + i, '='), "=%d", &ch); | 977 | sscanf(strchr(argp + i, '='), "tabstop=%d" + 7, &ch); |
973 | if (ch > 0 && ch < columns - 1) | 978 | if (ch > 0 && ch < columns - 1) |
974 | tabstop = ch; | 979 | tabstop = ch; |
975 | } | 980 | } |
@@ -981,8 +986,8 @@ static void colon(Byte * buf) | |||
981 | #endif /* FEATURE_VI_SETOPTS */ | 986 | #endif /* FEATURE_VI_SETOPTS */ |
982 | #endif /* FEATURE_VI_SET */ | 987 | #endif /* FEATURE_VI_SET */ |
983 | #if ENABLE_FEATURE_VI_SEARCH | 988 | #if ENABLE_FEATURE_VI_SEARCH |
984 | } else if (strncasecmp((char *) cmd, "s", 1) == 0) { // substitute a pattern with a replacement pattern | 989 | } else if (strncasecmp(cmd, "s", 1) == 0) { // substitute a pattern with a replacement pattern |
985 | Byte *ls, *F, *R; | 990 | char *ls, *F, *R; |
986 | int gflag; | 991 | int gflag; |
987 | 992 | ||
988 | // F points to the "find" pattern | 993 | // F points to the "find" pattern |
@@ -991,10 +996,10 @@ static void colon(Byte * buf) | |||
991 | gflag = 0; // global replace flag | 996 | gflag = 0; // global replace flag |
992 | c = orig_buf[1]; // what is the delimiter | 997 | c = orig_buf[1]; // what is the delimiter |
993 | F = orig_buf + 2; // start of "find" | 998 | F = orig_buf + 2; // start of "find" |
994 | R = (Byte *) strchr((char *) F, c); // middle delimiter | 999 | R = strchr(F, c); // middle delimiter |
995 | if (!R) goto colon_s_fail; | 1000 | if (!R) goto colon_s_fail; |
996 | *R++ = '\0'; // terminate "find" | 1001 | *R++ = '\0'; // terminate "find" |
997 | buf1 = (Byte *) strchr((char *) R, c); | 1002 | buf1 = strchr(R, c); |
998 | if (!buf1) goto colon_s_fail; | 1003 | if (!buf1) goto colon_s_fail; |
999 | *buf1++ = '\0'; // terminate "replace" | 1004 | *buf1++ = '\0'; // terminate "replace" |
1000 | if (*buf1 == 'g') { // :s/foo/bar/g | 1005 | if (*buf1 == 'g') { // :s/foo/bar/g |
@@ -1010,17 +1015,17 @@ static void colon(Byte * buf) | |||
1010 | e = b; // maybe :.s/foo/bar/ | 1015 | e = b; // maybe :.s/foo/bar/ |
1011 | for (i = b; i <= e; i++) { // so, :20,23 s \0 find \0 replace \0 | 1016 | for (i = b; i <= e; i++) { // so, :20,23 s \0 find \0 replace \0 |
1012 | ls = q; // orig line start | 1017 | ls = q; // orig line start |
1013 | vc4: | 1018 | vc4: |
1014 | buf1 = char_search(q, F, FORWARD, LIMITED); // search cur line only for "find" | 1019 | buf1 = char_search(q, F, FORWARD, LIMITED); // search cur line only for "find" |
1015 | if (buf1 != NULL) { | 1020 | if (buf1) { |
1016 | // we found the "find" pattern- delete it | 1021 | // we found the "find" pattern - delete it |
1017 | (void) text_hole_delete(buf1, buf1 + strlen((char *) F) - 1); | 1022 | text_hole_delete(buf1, buf1 + strlen(F) - 1); |
1018 | // inset the "replace" patern | 1023 | // inset the "replace" patern |
1019 | (void) string_insert(buf1, R); // insert the string | 1024 | string_insert(buf1, R); // insert the string |
1020 | // check for "global" :s/foo/bar/g | 1025 | // check for "global" :s/foo/bar/g |
1021 | if (gflag == 1) { | 1026 | if (gflag == 1) { |
1022 | if ((buf1 + strlen((char *) R)) < end_line(ls)) { | 1027 | if ((buf1 + strlen(R)) < end_line(ls)) { |
1023 | q = buf1 + strlen((char *) R); | 1028 | q = buf1 + strlen(R); |
1024 | goto vc4; // don't let q move past cur line | 1029 | goto vc4; // don't let q move past cur line |
1025 | } | 1030 | } |
1026 | } | 1031 | } |
@@ -1028,14 +1033,15 @@ static void colon(Byte * buf) | |||
1028 | q = next_line(ls); | 1033 | q = next_line(ls); |
1029 | } | 1034 | } |
1030 | #endif /* FEATURE_VI_SEARCH */ | 1035 | #endif /* FEATURE_VI_SEARCH */ |
1031 | } else if (strncasecmp((char *) cmd, "version", i) == 0) { // show software version | 1036 | } else if (strncasecmp(cmd, "version", i) == 0) { // show software version |
1032 | psb("%s", BB_VER " " BB_BT); | 1037 | psb("%s", BB_VER " " BB_BT); |
1033 | } else if (strncasecmp((char *) cmd, "write", i) == 0 // write text to file | 1038 | } else if (strncasecmp(cmd, "write", i) == 0 // write text to file |
1034 | || strncasecmp((char *) cmd, "wq", i) == 0 | 1039 | || strncasecmp(cmd, "wq", i) == 0 |
1035 | || strncasecmp((char *) cmd, "wn", i) == 0 | 1040 | || strncasecmp(cmd, "wn", i) == 0 |
1036 | || strncasecmp((char *) cmd, "x", i) == 0) { | 1041 | || strncasecmp(cmd, "x", i) == 0 |
1042 | ) { | ||
1037 | // is there a file name to write to? | 1043 | // is there a file name to write to? |
1038 | if (strlen((char *) args) > 0) { | 1044 | if (args[0]) { |
1039 | fn = args; | 1045 | fn = args; |
1040 | } | 1046 | } |
1041 | #if ENABLE_FEATURE_VI_READONLY | 1047 | #if ENABLE_FEATURE_VI_READONLY |
@@ -1080,7 +1086,7 @@ static void colon(Byte * buf) | |||
1080 | vc3:; | 1086 | vc3:; |
1081 | #endif | 1087 | #endif |
1082 | #if ENABLE_FEATURE_VI_YANKMARK | 1088 | #if ENABLE_FEATURE_VI_YANKMARK |
1083 | } else if (strncasecmp((char *) cmd, "yank", i) == 0) { // yank lines | 1089 | } else if (strncasecmp(cmd, "yank", i) == 0) { // yank lines |
1084 | if (b < 0) { // no addr given- use defaults | 1090 | if (b < 0) { // no addr given- use defaults |
1085 | q = begin_line(dot); // assume .,. for the range | 1091 | q = begin_line(dot); // assume .,. for the range |
1086 | r = end_line(dot); | 1092 | r = end_line(dot); |
@@ -1088,17 +1094,17 @@ static void colon(Byte * buf) | |||
1088 | text_yank(q, r, YDreg); | 1094 | text_yank(q, r, YDreg); |
1089 | li = count_lines(q, r); | 1095 | li = count_lines(q, r); |
1090 | psb("Yank %d lines (%d chars) into [%c]", | 1096 | psb("Yank %d lines (%d chars) into [%c]", |
1091 | li, strlen((char *) reg[YDreg]), what_reg()); | 1097 | li, strlen(reg[YDreg]), what_reg()); |
1092 | #endif | 1098 | #endif |
1093 | } else { | 1099 | } else { |
1094 | // cmd unknown | 1100 | // cmd unknown |
1095 | ni((Byte *) cmd); | 1101 | ni(cmd); |
1096 | } | 1102 | } |
1097 | vc1: | 1103 | vc1: |
1098 | dot = bound_dot(dot); // make sure "dot" is valid | 1104 | dot = bound_dot(dot); // make sure "dot" is valid |
1099 | return; | 1105 | return; |
1100 | #if ENABLE_FEATURE_VI_SEARCH | 1106 | #if ENABLE_FEATURE_VI_SEARCH |
1101 | colon_s_fail: | 1107 | colon_s_fail: |
1102 | psb(":s expression missing delimiters"); | 1108 | psb(":s expression missing delimiters"); |
1103 | #endif | 1109 | #endif |
1104 | } | 1110 | } |
@@ -1118,11 +1124,11 @@ static void Hit_Return(void) | |||
1118 | } | 1124 | } |
1119 | 1125 | ||
1120 | //----- Synchronize the cursor to Dot -------------------------- | 1126 | //----- Synchronize the cursor to Dot -------------------------- |
1121 | static void sync_cursor(Byte * d, int *row, int *col) | 1127 | static void sync_cursor(char * d, int *row, int *col) |
1122 | { | 1128 | { |
1123 | Byte *beg_cur; // begin and end of "d" line | 1129 | char *beg_cur; // begin and end of "d" line |
1124 | Byte *end_scr; // begin and end of screen | 1130 | char *end_scr; // begin and end of screen |
1125 | Byte *tp; | 1131 | char *tp; |
1126 | int cnt, ro, co; | 1132 | int cnt, ro, co; |
1127 | 1133 | ||
1128 | beg_cur = begin_line(d); // first char of cur line | 1134 | beg_cur = begin_line(d); // first char of cur line |
@@ -1133,7 +1139,7 @@ static void sync_cursor(Byte * d, int *row, int *col) | |||
1133 | // "d" is before top line on screen | 1139 | // "d" is before top line on screen |
1134 | // how many lines do we have to move | 1140 | // how many lines do we have to move |
1135 | cnt = count_lines(beg_cur, screenbegin); | 1141 | cnt = count_lines(beg_cur, screenbegin); |
1136 | sc1: | 1142 | sc1: |
1137 | screenbegin = beg_cur; | 1143 | screenbegin = beg_cur; |
1138 | if (cnt > (rows - 1) / 2) { | 1144 | if (cnt > (rows - 1) / 2) { |
1139 | // we moved too many lines. put "dot" in middle of screen | 1145 | // we moved too many lines. put "dot" in middle of screen |
@@ -1207,21 +1213,21 @@ static void sync_cursor(Byte * d, int *row, int *col) | |||
1207 | } | 1213 | } |
1208 | 1214 | ||
1209 | //----- Text Movement Routines --------------------------------- | 1215 | //----- Text Movement Routines --------------------------------- |
1210 | static Byte *begin_line(Byte * p) // return pointer to first char cur line | 1216 | static char *begin_line(char * p) // return pointer to first char cur line |
1211 | { | 1217 | { |
1212 | while (p > text && p[-1] != '\n') | 1218 | while (p > text && p[-1] != '\n') |
1213 | p--; // go to cur line B-o-l | 1219 | p--; // go to cur line B-o-l |
1214 | return p; | 1220 | return p; |
1215 | } | 1221 | } |
1216 | 1222 | ||
1217 | static Byte *end_line(Byte * p) // return pointer to NL of cur line line | 1223 | static char *end_line(char * p) // return pointer to NL of cur line line |
1218 | { | 1224 | { |
1219 | while (p < end - 1 && *p != '\n') | 1225 | while (p < end - 1 && *p != '\n') |
1220 | p++; // go to cur line E-o-l | 1226 | p++; // go to cur line E-o-l |
1221 | return p; | 1227 | return p; |
1222 | } | 1228 | } |
1223 | 1229 | ||
1224 | static inline Byte *dollar_line(Byte * p) // return pointer to just before NL line | 1230 | static inline char *dollar_line(char * p) // return pointer to just before NL line |
1225 | { | 1231 | { |
1226 | while (p < end - 1 && *p != '\n') | 1232 | while (p < end - 1 && *p != '\n') |
1227 | p++; // go to cur line E-o-l | 1233 | p++; // go to cur line E-o-l |
@@ -1231,7 +1237,7 @@ static inline Byte *dollar_line(Byte * p) // return pointer to just before NL li | |||
1231 | return p; | 1237 | return p; |
1232 | } | 1238 | } |
1233 | 1239 | ||
1234 | static Byte *prev_line(Byte * p) // return pointer first char prev line | 1240 | static char *prev_line(char * p) // return pointer first char prev line |
1235 | { | 1241 | { |
1236 | p = begin_line(p); // goto begining of cur line | 1242 | p = begin_line(p); // goto begining of cur line |
1237 | if (p[-1] == '\n' && p > text) | 1243 | if (p[-1] == '\n' && p > text) |
@@ -1240,7 +1246,7 @@ static Byte *prev_line(Byte * p) // return pointer first char prev line | |||
1240 | return p; | 1246 | return p; |
1241 | } | 1247 | } |
1242 | 1248 | ||
1243 | static Byte *next_line(Byte * p) // return pointer first char next line | 1249 | static char *next_line(char * p) // return pointer first char next line |
1244 | { | 1250 | { |
1245 | p = end_line(p); | 1251 | p = end_line(p); |
1246 | if (*p == '\n' && p < end - 1) | 1252 | if (*p == '\n' && p < end - 1) |
@@ -1249,9 +1255,9 @@ static Byte *next_line(Byte * p) // return pointer first char next line | |||
1249 | } | 1255 | } |
1250 | 1256 | ||
1251 | //----- Text Information Routines ------------------------------ | 1257 | //----- Text Information Routines ------------------------------ |
1252 | static Byte *end_screen(void) | 1258 | static char *end_screen(void) |
1253 | { | 1259 | { |
1254 | Byte *q; | 1260 | char *q; |
1255 | int cnt; | 1261 | int cnt; |
1256 | 1262 | ||
1257 | // find new bottom line | 1263 | // find new bottom line |
@@ -1262,9 +1268,9 @@ static Byte *end_screen(void) | |||
1262 | return q; | 1268 | return q; |
1263 | } | 1269 | } |
1264 | 1270 | ||
1265 | static int count_lines(Byte * start, Byte * stop) // count line from start to stop | 1271 | static int count_lines(char * start, char * stop) // count line from start to stop |
1266 | { | 1272 | { |
1267 | Byte *q; | 1273 | char *q; |
1268 | int cnt; | 1274 | int cnt; |
1269 | 1275 | ||
1270 | if (stop < start) { // start and stop are backwards- reverse them | 1276 | if (stop < start) { // start and stop are backwards- reverse them |
@@ -1281,9 +1287,9 @@ static int count_lines(Byte * start, Byte * stop) // count line from start to st | |||
1281 | return cnt; | 1287 | return cnt; |
1282 | } | 1288 | } |
1283 | 1289 | ||
1284 | static Byte *find_line(int li) // find begining of line #li | 1290 | static char *find_line(int li) // find begining of line #li |
1285 | { | 1291 | { |
1286 | Byte *q; | 1292 | char *q; |
1287 | 1293 | ||
1288 | for (q = text; li > 1; li--) { | 1294 | for (q = text; li > 1; li--) { |
1289 | q = next_line(q); | 1295 | q = next_line(q); |
@@ -1314,7 +1320,7 @@ static void dot_end(void) | |||
1314 | dot = end_line(dot); // return pointer to last char cur line | 1320 | dot = end_line(dot); // return pointer to last char cur line |
1315 | } | 1321 | } |
1316 | 1322 | ||
1317 | static Byte *move_to_col(Byte * p, int l) | 1323 | static char *move_to_col(char * p, int l) |
1318 | { | 1324 | { |
1319 | int co; | 1325 | int co; |
1320 | 1326 | ||
@@ -1345,7 +1351,7 @@ static void dot_prev(void) | |||
1345 | 1351 | ||
1346 | static void dot_scroll(int cnt, int dir) | 1352 | static void dot_scroll(int cnt, int dir) |
1347 | { | 1353 | { |
1348 | Byte *q; | 1354 | char *q; |
1349 | 1355 | ||
1350 | for (; cnt > 0; cnt--) { | 1356 | for (; cnt > 0; cnt--) { |
1351 | if (dir < 0) { | 1357 | if (dir < 0) { |
@@ -1376,10 +1382,10 @@ static void dot_skip_over_ws(void) | |||
1376 | 1382 | ||
1377 | static void dot_delete(void) // delete the char at 'dot' | 1383 | static void dot_delete(void) // delete the char at 'dot' |
1378 | { | 1384 | { |
1379 | (void) text_hole_delete(dot, dot); | 1385 | text_hole_delete(dot, dot); |
1380 | } | 1386 | } |
1381 | 1387 | ||
1382 | static Byte *bound_dot(Byte * p) // make sure text[0] <= P < "end" | 1388 | static char *bound_dot(char * p) // make sure text[0] <= P < "end" |
1383 | { | 1389 | { |
1384 | if (p >= end && end > text) { | 1390 | if (p >= end && end > text) { |
1385 | p = end - 1; | 1391 | p = end - 1; |
@@ -1405,7 +1411,7 @@ static Byte *bound_dot(Byte * p) // make sure text[0] <= P < "end" | |||
1405 | * DO NOT COUNT NEWLINE AS WHITESPACE | 1411 | * DO NOT COUNT NEWLINE AS WHITESPACE |
1406 | */ | 1412 | */ |
1407 | 1413 | ||
1408 | static Byte *new_screen(int ro, int co) | 1414 | static char *new_screen(int ro, int co) |
1409 | { | 1415 | { |
1410 | int li; | 1416 | int li; |
1411 | 1417 | ||
@@ -1421,7 +1427,7 @@ static Byte *new_screen(int ro, int co) | |||
1421 | return screen; | 1427 | return screen; |
1422 | } | 1428 | } |
1423 | 1429 | ||
1424 | static Byte *new_text(int size) | 1430 | static char *new_text(int size) |
1425 | { | 1431 | { |
1426 | if (size < 10240) | 1432 | if (size < 10240) |
1427 | size = 10240; // have a minimum size for new files | 1433 | size = 10240; // have a minimum size for new files |
@@ -1433,26 +1439,27 @@ static Byte *new_text(int size) | |||
1433 | } | 1439 | } |
1434 | 1440 | ||
1435 | #if ENABLE_FEATURE_VI_SEARCH | 1441 | #if ENABLE_FEATURE_VI_SEARCH |
1436 | static int mycmp(Byte * s1, Byte * s2, int len) | 1442 | static int mycmp(const char * s1, const char * s2, int len) |
1437 | { | 1443 | { |
1438 | int i; | 1444 | int i; |
1439 | 1445 | ||
1440 | i = strncmp((char *) s1, (char *) s2, len); | 1446 | i = strncmp(s1, s2, len); |
1441 | #if ENABLE_FEATURE_VI_SETOPTS | 1447 | #if ENABLE_FEATURE_VI_SETOPTS |
1442 | if (ignorecase) { | 1448 | if (ignorecase) { |
1443 | i = strncasecmp((char *) s1, (char *) s2, len); | 1449 | i = strncasecmp(s1, s2, len); |
1444 | } | 1450 | } |
1445 | #endif | 1451 | #endif |
1446 | return i; | 1452 | return i; |
1447 | } | 1453 | } |
1448 | 1454 | ||
1449 | static Byte *char_search(Byte * p, Byte * pat, int dir, int range) // search for pattern starting at p | 1455 | // search for pattern starting at p |
1456 | static char *char_search(char * p, const char * pat, int dir, int range) | ||
1450 | { | 1457 | { |
1451 | #ifndef REGEX_SEARCH | 1458 | #ifndef REGEX_SEARCH |
1452 | Byte *start, *stop; | 1459 | char *start, *stop; |
1453 | int len; | 1460 | int len; |
1454 | 1461 | ||
1455 | len = strlen((char *) pat); | 1462 | len = strlen(pat); |
1456 | if (dir == FORWARD) { | 1463 | if (dir == FORWARD) { |
1457 | stop = end - 1; // assume range is p - end-1 | 1464 | stop = end - 1; // assume range is p - end-1 |
1458 | if (range == LIMITED) | 1465 | if (range == LIMITED) |
@@ -1474,7 +1481,7 @@ static Byte *char_search(Byte * p, Byte * pat, int dir, int range) // search for | |||
1474 | } | 1481 | } |
1475 | // pattern not found | 1482 | // pattern not found |
1476 | return NULL; | 1483 | return NULL; |
1477 | #else /*REGEX_SEARCH */ | 1484 | #else /* REGEX_SEARCH */ |
1478 | char *q; | 1485 | char *q; |
1479 | struct re_pattern_buffer preg; | 1486 | struct re_pattern_buffer preg; |
1480 | int i; | 1487 | int i; |
@@ -1501,7 +1508,7 @@ static Byte *char_search(Byte * p, Byte * pat, int dir, int range) // search for | |||
1501 | // RANGE could be negative if we are searching backwards | 1508 | // RANGE could be negative if we are searching backwards |
1502 | range = q - p; | 1509 | range = q - p; |
1503 | 1510 | ||
1504 | q = (char *) re_compile_pattern(pat, strlen((char *) pat), &preg); | 1511 | q = re_compile_pattern(pat, strlen(pat), &preg); |
1505 | if (q != 0) { | 1512 | if (q != 0) { |
1506 | // The pattern was not compiled | 1513 | // The pattern was not compiled |
1507 | psbs("bad search pattern: \"%s\": %s", pat, q); | 1514 | psbs("bad search pattern: \"%s\": %s", pat, q); |
@@ -1528,7 +1535,7 @@ static Byte *char_search(Byte * p, Byte * pat, int dir, int range) // search for | |||
1528 | p = 0; | 1535 | p = 0; |
1529 | i = 0; // return NULL if pattern not found | 1536 | i = 0; // return NULL if pattern not found |
1530 | } | 1537 | } |
1531 | cs1: | 1538 | cs1: |
1532 | if (dir == FORWARD) { | 1539 | if (dir == FORWARD) { |
1533 | p = p + i; | 1540 | p = p + i; |
1534 | } else { | 1541 | } else { |
@@ -1539,7 +1546,7 @@ static Byte *char_search(Byte * p, Byte * pat, int dir, int range) // search for | |||
1539 | } | 1546 | } |
1540 | #endif /* FEATURE_VI_SEARCH */ | 1547 | #endif /* FEATURE_VI_SEARCH */ |
1541 | 1548 | ||
1542 | static Byte *char_insert(Byte * p, Byte c) // insert the char c at 'p' | 1549 | static char *char_insert(char * p, char c) // insert the char c at 'p' |
1543 | { | 1550 | { |
1544 | if (c == 22) { // Is this an ctrl-V? | 1551 | if (c == 22) { // Is this an ctrl-V? |
1545 | p = stupid_insert(p, '^'); // use ^ to indicate literal next | 1552 | p = stupid_insert(p, '^'); // use ^ to indicate literal next |
@@ -1554,7 +1561,7 @@ static Byte *char_insert(Byte * p, Byte c) // insert the char c at 'p' | |||
1554 | cmdcnt = 0; | 1561 | cmdcnt = 0; |
1555 | end_cmd_q(); // stop adding to q | 1562 | end_cmd_q(); // stop adding to q |
1556 | last_status_cksum = 0; // force status update | 1563 | last_status_cksum = 0; // force status update |
1557 | if ((p[-1] != '\n') && (dot>text)) { | 1564 | if ((p[-1] != '\n') && (dot > text)) { |
1558 | p--; | 1565 | p--; |
1559 | } | 1566 | } |
1560 | } else if (c == erase_char || c == 8 || c == 127) { // Is this a BS | 1567 | } else if (c == erase_char || c == 8 || c == 127) { // Is this a BS |
@@ -1565,7 +1572,7 @@ static Byte *char_insert(Byte * p, Byte c) // insert the char c at 'p' | |||
1565 | } | 1572 | } |
1566 | } else { | 1573 | } else { |
1567 | // insert a char into text[] | 1574 | // insert a char into text[] |
1568 | Byte *sp; // "save p" | 1575 | char *sp; // "save p" |
1569 | 1576 | ||
1570 | if (c == 13) | 1577 | if (c == 13) |
1571 | c = '\n'; // translate \r to \n | 1578 | c = '\n'; // translate \r to \n |
@@ -1576,7 +1583,7 @@ static Byte *char_insert(Byte * p, Byte c) // insert the char c at 'p' | |||
1576 | showmatching(sp); | 1583 | showmatching(sp); |
1577 | } | 1584 | } |
1578 | if (autoindent && c == '\n') { // auto indent the new line | 1585 | if (autoindent && c == '\n') { // auto indent the new line |
1579 | Byte *q; | 1586 | char *q; |
1580 | 1587 | ||
1581 | q = prev_line(p); // use prev line as templet | 1588 | q = prev_line(p); // use prev line as templet |
1582 | for (; isblnk(*q); q++) { | 1589 | for (; isblnk(*q); q++) { |
@@ -1588,7 +1595,7 @@ static Byte *char_insert(Byte * p, Byte c) // insert the char c at 'p' | |||
1588 | return p; | 1595 | return p; |
1589 | } | 1596 | } |
1590 | 1597 | ||
1591 | static Byte *stupid_insert(Byte * p, Byte c) // stupidly insert the char c at 'p' | 1598 | static char *stupid_insert(char * p, char c) // stupidly insert the char c at 'p' |
1592 | { | 1599 | { |
1593 | p = text_hole_make(p, 1); | 1600 | p = text_hole_make(p, 1); |
1594 | if (p != 0) { | 1601 | if (p != 0) { |
@@ -1599,9 +1606,9 @@ static Byte *stupid_insert(Byte * p, Byte c) // stupidly insert the char c at 'p | |||
1599 | return p; | 1606 | return p; |
1600 | } | 1607 | } |
1601 | 1608 | ||
1602 | static Byte find_range(Byte ** start, Byte ** stop, Byte c) | 1609 | static char find_range(char ** start, char ** stop, char c) |
1603 | { | 1610 | { |
1604 | Byte *save_dot, *p, *q; | 1611 | char *save_dot, *p, *q; |
1605 | int cnt; | 1612 | int cnt; |
1606 | 1613 | ||
1607 | save_dot = dot; | 1614 | save_dot = dot; |
@@ -1656,9 +1663,9 @@ static Byte find_range(Byte ** start, Byte ** stop, Byte c) | |||
1656 | return c; | 1663 | return c; |
1657 | } | 1664 | } |
1658 | 1665 | ||
1659 | static int st_test(Byte * p, int type, int dir, Byte * tested) | 1666 | static int st_test(char * p, int type, int dir, char * tested) |
1660 | { | 1667 | { |
1661 | Byte c, c0, ci; | 1668 | char c, c0, ci; |
1662 | int test, inc; | 1669 | int test, inc; |
1663 | 1670 | ||
1664 | inc = dir; | 1671 | inc = dir; |
@@ -1690,9 +1697,9 @@ static int st_test(Byte * p, int type, int dir, Byte * tested) | |||
1690 | return test; | 1697 | return test; |
1691 | } | 1698 | } |
1692 | 1699 | ||
1693 | static Byte *skip_thing(Byte * p, int linecnt, int dir, int type) | 1700 | static char *skip_thing(char * p, int linecnt, int dir, int type) |
1694 | { | 1701 | { |
1695 | Byte c; | 1702 | char c; |
1696 | 1703 | ||
1697 | while (st_test(p, type, dir, &c)) { | 1704 | while (st_test(p, type, dir, &c)) { |
1698 | // make sure we limit search to correct number of lines | 1705 | // make sure we limit search to correct number of lines |
@@ -1708,9 +1715,9 @@ static Byte *skip_thing(Byte * p, int linecnt, int dir, int type) | |||
1708 | } | 1715 | } |
1709 | 1716 | ||
1710 | // find matching char of pair () [] {} | 1717 | // find matching char of pair () [] {} |
1711 | static Byte *find_pair(Byte * p, Byte c) | 1718 | static char *find_pair(char * p, char c) |
1712 | { | 1719 | { |
1713 | Byte match, *q; | 1720 | char match, *q; |
1714 | int dir, level; | 1721 | int dir, level; |
1715 | 1722 | ||
1716 | match = ')'; | 1723 | match = ')'; |
@@ -1755,9 +1762,9 @@ static Byte *find_pair(Byte * p, Byte c) | |||
1755 | 1762 | ||
1756 | #if ENABLE_FEATURE_VI_SETOPTS | 1763 | #if ENABLE_FEATURE_VI_SETOPTS |
1757 | // show the matching char of a pair, () [] {} | 1764 | // show the matching char of a pair, () [] {} |
1758 | static void showmatching(Byte * p) | 1765 | static void showmatching(char * p) |
1759 | { | 1766 | { |
1760 | Byte *q, *save_dot; | 1767 | char *q, *save_dot; |
1761 | 1768 | ||
1762 | // we found half of a pair | 1769 | // we found half of a pair |
1763 | q = find_pair(p, *p); // get loc of matching char | 1770 | q = find_pair(p, *p); // get loc of matching char |
@@ -1768,7 +1775,7 @@ static void showmatching(Byte * p) | |||
1768 | save_dot = dot; // remember where we are | 1775 | save_dot = dot; // remember where we are |
1769 | dot = q; // go to new loc | 1776 | dot = q; // go to new loc |
1770 | refresh(FALSE); // let the user see it | 1777 | refresh(FALSE); // let the user see it |
1771 | (void) mysleep(40); // give user some time | 1778 | mysleep(40); // give user some time |
1772 | dot = save_dot; // go back to old loc | 1779 | dot = save_dot; // go back to old loc |
1773 | refresh(FALSE); | 1780 | refresh(FALSE); |
1774 | } | 1781 | } |
@@ -1776,9 +1783,9 @@ static void showmatching(Byte * p) | |||
1776 | #endif /* FEATURE_VI_SETOPTS */ | 1783 | #endif /* FEATURE_VI_SETOPTS */ |
1777 | 1784 | ||
1778 | // open a hole in text[] | 1785 | // open a hole in text[] |
1779 | static Byte *text_hole_make(Byte * p, int size) // at "p", make a 'size' byte hole | 1786 | static char *text_hole_make(char * p, int size) // at "p", make a 'size' byte hole |
1780 | { | 1787 | { |
1781 | Byte *src, *dest; | 1788 | char *src, *dest; |
1782 | int cnt; | 1789 | int cnt; |
1783 | 1790 | ||
1784 | if (size <= 0) | 1791 | if (size <= 0) |
@@ -1792,14 +1799,14 @@ static Byte *text_hole_make(Byte * p, int size) // at "p", make a 'size' byte ho | |||
1792 | memset(p, ' ', size); // clear new hole | 1799 | memset(p, ' ', size); // clear new hole |
1793 | end = end + size; // adjust the new END | 1800 | end = end + size; // adjust the new END |
1794 | file_modified++; // has the file been modified | 1801 | file_modified++; // has the file been modified |
1795 | thm0: | 1802 | thm0: |
1796 | return p; | 1803 | return p; |
1797 | } | 1804 | } |
1798 | 1805 | ||
1799 | // close a hole in text[] | 1806 | // close a hole in text[] |
1800 | static Byte *text_hole_delete(Byte * p, Byte * q) // delete "p" thru "q", inclusive | 1807 | static char *text_hole_delete(char * p, char * q) // delete "p" thru "q", inclusive |
1801 | { | 1808 | { |
1802 | Byte *src, *dest; | 1809 | char *src, *dest; |
1803 | int cnt, hole_size; | 1810 | int cnt, hole_size; |
1804 | 1811 | ||
1805 | // move forwards, from beginning | 1812 | // move forwards, from beginning |
@@ -1821,23 +1828,23 @@ static Byte *text_hole_delete(Byte * p, Byte * q) // delete "p" thru "q", inclus | |||
1821 | if (memmove(dest, src, cnt) != dest) { | 1828 | if (memmove(dest, src, cnt) != dest) { |
1822 | psbs("can't delete the character"); | 1829 | psbs("can't delete the character"); |
1823 | } | 1830 | } |
1824 | thd_atend: | 1831 | thd_atend: |
1825 | end = end - hole_size; // adjust the new END | 1832 | end = end - hole_size; // adjust the new END |
1826 | if (dest >= end) | 1833 | if (dest >= end) |
1827 | dest = end - 1; // make sure dest in below end-1 | 1834 | dest = end - 1; // make sure dest in below end-1 |
1828 | if (end <= text) | 1835 | if (end <= text) |
1829 | dest = end = text; // keep pointers valid | 1836 | dest = end = text; // keep pointers valid |
1830 | file_modified++; // has the file been modified | 1837 | file_modified++; // has the file been modified |
1831 | thd0: | 1838 | thd0: |
1832 | return dest; | 1839 | return dest; |
1833 | } | 1840 | } |
1834 | 1841 | ||
1835 | // copy text into register, then delete text. | 1842 | // copy text into register, then delete text. |
1836 | // if dist <= 0, do not include, or go past, a NewLine | 1843 | // if dist <= 0, do not include, or go past, a NewLine |
1837 | // | 1844 | // |
1838 | static Byte *yank_delete(Byte * start, Byte * stop, int dist, int yf) | 1845 | static char *yank_delete(char * start, char * stop, int dist, int yf) |
1839 | { | 1846 | { |
1840 | Byte *p; | 1847 | char *p; |
1841 | 1848 | ||
1842 | // make sure start <= stop | 1849 | // make sure start <= stop |
1843 | if (start > stop) { | 1850 | if (start > stop) { |
@@ -1902,42 +1909,42 @@ static void show_help(void) | |||
1902 | ); | 1909 | ); |
1903 | } | 1910 | } |
1904 | 1911 | ||
1905 | static inline void print_literal(Byte * buf, Byte * s) // copy s to buf, convert unprintable | 1912 | static inline void print_literal(char * buf, const char * s) // copy s to buf, convert unprintable |
1906 | { | 1913 | { |
1907 | Byte c, b[2]; | 1914 | unsigned char c; |
1915 | char b[2]; | ||
1908 | 1916 | ||
1909 | b[1] = '\0'; | 1917 | b[1] = '\0'; |
1910 | strcpy((char *) buf, ""); // init buf | 1918 | buf[0] = '\0'; |
1911 | if (strlen((char *) s) <= 0) | 1919 | if (!s[0]) |
1912 | s = (Byte *) "(NULL)"; | 1920 | s = "(NULL)"; |
1913 | for (; *s > '\0'; s++) { | 1921 | for (; *s; s++) { |
1914 | int c_is_no_print; | 1922 | int c_is_no_print; |
1915 | 1923 | ||
1916 | c = *s; | 1924 | c = *s; |
1917 | c_is_no_print = c > 127 && !Isprint(c); | 1925 | c_is_no_print = c > 127 && !Isprint(c); |
1918 | if (c_is_no_print) { | 1926 | if (c_is_no_print) { |
1919 | strcat((char *) buf, SOn); | 1927 | strcat(buf, SOn); |
1920 | c = '.'; | 1928 | c = '.'; |
1921 | } | 1929 | } |
1922 | if (c < ' ' || c == 127) { | 1930 | if (c < ' ' || c == 127) { |
1923 | strcat((char *) buf, "^"); | 1931 | strcat(buf, "^"); |
1924 | if(c == 127) | 1932 | if (c == 127) |
1925 | c = '?'; | 1933 | c = '?'; |
1926 | else | 1934 | else |
1927 | c += '@'; | 1935 | c += '@'; |
1928 | } | 1936 | } |
1929 | b[0] = c; | 1937 | b[0] = c; |
1930 | strcat((char *) buf, (char *) b); | 1938 | strcat(buf, b); |
1931 | if (c_is_no_print) | 1939 | if (c_is_no_print) |
1932 | strcat((char *) buf, SOs); | 1940 | strcat(buf, SOs); |
1933 | if (*s == '\n') { | 1941 | if (*s == '\n') |
1934 | strcat((char *) buf, "$"); | 1942 | strcat(buf, "$"); |
1935 | } | ||
1936 | } | 1943 | } |
1937 | } | 1944 | } |
1938 | 1945 | ||
1939 | #if ENABLE_FEATURE_VI_DOT_CMD | 1946 | #if ENABLE_FEATURE_VI_DOT_CMD |
1940 | static void start_new_cmd_q(Byte c) | 1947 | static void start_new_cmd_q(char c) |
1941 | { | 1948 | { |
1942 | // release old cmd | 1949 | // release old cmd |
1943 | free(last_modifying_cmd); | 1950 | free(last_modifying_cmd); |
@@ -1946,7 +1953,7 @@ static void start_new_cmd_q(Byte c) | |||
1946 | memset(last_modifying_cmd, '\0', BUFSIZ); // clear new cmd queue | 1953 | memset(last_modifying_cmd, '\0', BUFSIZ); // clear new cmd queue |
1947 | // if there is a current cmd count put it in the buffer first | 1954 | // if there is a current cmd count put it in the buffer first |
1948 | if (cmdcnt > 0) | 1955 | if (cmdcnt > 0) |
1949 | sprintf((char *) last_modifying_cmd, "%d%c", cmdcnt, c); | 1956 | sprintf(last_modifying_cmd, "%d%c", cmdcnt, c); |
1950 | else // just save char c onto queue | 1957 | else // just save char c onto queue |
1951 | last_modifying_cmd[0] = c; | 1958 | last_modifying_cmd[0] = c; |
1952 | adding2q = 1; | 1959 | adding2q = 1; |
@@ -1964,13 +1971,13 @@ static void end_cmd_q(void) | |||
1964 | #if ENABLE_FEATURE_VI_YANKMARK \ | 1971 | #if ENABLE_FEATURE_VI_YANKMARK \ |
1965 | || (ENABLE_FEATURE_VI_COLON && ENABLE_FEATURE_VI_SEARCH) \ | 1972 | || (ENABLE_FEATURE_VI_COLON && ENABLE_FEATURE_VI_SEARCH) \ |
1966 | || ENABLE_FEATURE_VI_CRASHME | 1973 | || ENABLE_FEATURE_VI_CRASHME |
1967 | static Byte *string_insert(Byte * p, Byte * s) // insert the string at 'p' | 1974 | static char *string_insert(char * p, char * s) // insert the string at 'p' |
1968 | { | 1975 | { |
1969 | int cnt, i; | 1976 | int cnt, i; |
1970 | 1977 | ||
1971 | i = strlen((char *) s); | 1978 | i = strlen(s); |
1972 | p = text_hole_make(p, i); | 1979 | p = text_hole_make(p, i); |
1973 | strncpy((char *) p, (char *) s, i); | 1980 | strncpy(p, s, i); |
1974 | for (cnt = 0; *s != '\0'; s++) { | 1981 | for (cnt = 0; *s != '\0'; s++) { |
1975 | if (*s == '\n') | 1982 | if (*s == '\n') |
1976 | cnt++; | 1983 | cnt++; |
@@ -1983,9 +1990,9 @@ static Byte *string_insert(Byte * p, Byte * s) // insert the string at 'p' | |||
1983 | #endif | 1990 | #endif |
1984 | 1991 | ||
1985 | #if ENABLE_FEATURE_VI_YANKMARK | 1992 | #if ENABLE_FEATURE_VI_YANKMARK |
1986 | static Byte *text_yank(Byte * p, Byte * q, int dest) // copy text into a register | 1993 | static char *text_yank(char * p, char * q, int dest) // copy text into a register |
1987 | { | 1994 | { |
1988 | Byte *t; | 1995 | char *t; |
1989 | int cnt; | 1996 | int cnt; |
1990 | 1997 | ||
1991 | if (q < p) { // they are backwards- reverse them | 1998 | if (q < p) { // they are backwards- reverse them |
@@ -1998,18 +2005,18 @@ static Byte *text_yank(Byte * p, Byte * q, int dest) // copy text into a registe | |||
1998 | free(t); // if already a yank register, free it | 2005 | free(t); // if already a yank register, free it |
1999 | t = xmalloc(cnt + 1); // get a new register | 2006 | t = xmalloc(cnt + 1); // get a new register |
2000 | memset(t, '\0', cnt + 1); // clear new text[] | 2007 | memset(t, '\0', cnt + 1); // clear new text[] |
2001 | strncpy((char *) t, (char *) p, cnt); // copy text[] into bufer | 2008 | strncpy(t, p, cnt); // copy text[] into bufer |
2002 | reg[dest] = t; | 2009 | reg[dest] = t; |
2003 | return p; | 2010 | return p; |
2004 | } | 2011 | } |
2005 | 2012 | ||
2006 | static Byte what_reg(void) | 2013 | static char what_reg(void) |
2007 | { | 2014 | { |
2008 | Byte c; | 2015 | char c; |
2009 | 2016 | ||
2010 | c = 'D'; // default to D-reg | 2017 | c = 'D'; // default to D-reg |
2011 | if (0 <= YDreg && YDreg <= 25) | 2018 | if (0 <= YDreg && YDreg <= 25) |
2012 | c = 'a' + (Byte) YDreg; | 2019 | c = 'a' + (char) YDreg; |
2013 | if (YDreg == 26) | 2020 | if (YDreg == 26) |
2014 | c = 'D'; | 2021 | c = 'D'; |
2015 | if (YDreg == 27) | 2022 | if (YDreg == 27) |
@@ -2017,13 +2024,13 @@ static Byte what_reg(void) | |||
2017 | return c; | 2024 | return c; |
2018 | } | 2025 | } |
2019 | 2026 | ||
2020 | static void check_context(Byte cmd) | 2027 | static void check_context(char cmd) |
2021 | { | 2028 | { |
2022 | // A context is defined to be "modifying text" | 2029 | // A context is defined to be "modifying text" |
2023 | // Any modifying command establishes a new context. | 2030 | // Any modifying command establishes a new context. |
2024 | 2031 | ||
2025 | if (dot < context_start || dot > context_end) { | 2032 | if (dot < context_start || dot > context_end) { |
2026 | if (strchr((char *) modifying_cmds, cmd) != NULL) { | 2033 | if (strchr(modifying_cmds, cmd) != NULL) { |
2027 | // we are trying to modify text[]- make this the current context | 2034 | // we are trying to modify text[]- make this the current context |
2028 | mark[27] = mark[26]; // move cur to prev | 2035 | mark[27] = mark[26]; // move cur to prev |
2029 | mark[26] = dot; // move local to cur | 2036 | mark[26] = dot; // move local to cur |
@@ -2034,9 +2041,9 @@ static void check_context(Byte cmd) | |||
2034 | } | 2041 | } |
2035 | } | 2042 | } |
2036 | 2043 | ||
2037 | static inline Byte *swap_context(Byte * p) // goto new context for '' command make this the current context | 2044 | static inline char *swap_context(char * p) // goto new context for '' command make this the current context |
2038 | { | 2045 | { |
2039 | Byte *tmp; | 2046 | char *tmp; |
2040 | 2047 | ||
2041 | // the current context is in mark[26] | 2048 | // the current context is in mark[26] |
2042 | // the previous context is in mark[27] | 2049 | // the previous context is in mark[27] |
@@ -2053,7 +2060,7 @@ static inline Byte *swap_context(Byte * p) // goto new context for '' command ma | |||
2053 | } | 2060 | } |
2054 | #endif /* FEATURE_VI_YANKMARK */ | 2061 | #endif /* FEATURE_VI_YANKMARK */ |
2055 | 2062 | ||
2056 | static int isblnk(Byte c) // is the char a blank or tab | 2063 | static int isblnk(char c) // is the char a blank or tab |
2057 | { | 2064 | { |
2058 | return (c == ' ' || c == '\t'); | 2065 | return (c == ' ' || c == '\t'); |
2059 | } | 2066 | } |
@@ -2117,7 +2124,7 @@ static void suspend_sig(int sig ATTRIBUTE_UNUSED) | |||
2117 | static void catch_sig(int sig) | 2124 | static void catch_sig(int sig) |
2118 | { | 2125 | { |
2119 | signal(SIGINT, catch_sig); | 2126 | signal(SIGINT, catch_sig); |
2120 | if(sig) | 2127 | if (sig) |
2121 | longjmp(restart, sig); | 2128 | longjmp(restart, sig); |
2122 | } | 2129 | } |
2123 | #endif /* FEATURE_VI_USE_SIGNALS */ | 2130 | #endif /* FEATURE_VI_USE_SIGNALS */ |
@@ -2139,59 +2146,59 @@ static int mysleep(int hund) // sleep for 'h' 1/100 seconds | |||
2139 | static int readed_for_parse; | 2146 | static int readed_for_parse; |
2140 | 2147 | ||
2141 | //----- IO Routines -------------------------------------------- | 2148 | //----- IO Routines -------------------------------------------- |
2142 | static Byte readit(void) // read (maybe cursor) key from stdin | 2149 | static char readit(void) // read (maybe cursor) key from stdin |
2143 | { | 2150 | { |
2144 | Byte c; | 2151 | char c; |
2145 | int n; | 2152 | int n; |
2146 | struct esc_cmds { | 2153 | struct esc_cmds { |
2147 | const char *seq; | 2154 | const char *seq; |
2148 | Byte val; | 2155 | char val; |
2149 | }; | 2156 | }; |
2150 | 2157 | ||
2151 | static const struct esc_cmds esccmds[] = { | 2158 | static const struct esc_cmds esccmds[] = { |
2152 | {"OA", (Byte) VI_K_UP}, // cursor key Up | 2159 | {"OA", VI_K_UP}, // cursor key Up |
2153 | {"OB", (Byte) VI_K_DOWN}, // cursor key Down | 2160 | {"OB", VI_K_DOWN}, // cursor key Down |
2154 | {"OC", (Byte) VI_K_RIGHT}, // Cursor Key Right | 2161 | {"OC", VI_K_RIGHT}, // Cursor Key Right |
2155 | {"OD", (Byte) VI_K_LEFT}, // cursor key Left | 2162 | {"OD", VI_K_LEFT}, // cursor key Left |
2156 | {"OH", (Byte) VI_K_HOME}, // Cursor Key Home | 2163 | {"OH", VI_K_HOME}, // Cursor Key Home |
2157 | {"OF", (Byte) VI_K_END}, // Cursor Key End | 2164 | {"OF", VI_K_END}, // Cursor Key End |
2158 | {"[A", (Byte) VI_K_UP}, // cursor key Up | 2165 | {"[A", VI_K_UP}, // cursor key Up |
2159 | {"[B", (Byte) VI_K_DOWN}, // cursor key Down | 2166 | {"[B", VI_K_DOWN}, // cursor key Down |
2160 | {"[C", (Byte) VI_K_RIGHT}, // Cursor Key Right | 2167 | {"[C", VI_K_RIGHT}, // Cursor Key Right |
2161 | {"[D", (Byte) VI_K_LEFT}, // cursor key Left | 2168 | {"[D", VI_K_LEFT}, // cursor key Left |
2162 | {"[H", (Byte) VI_K_HOME}, // Cursor Key Home | 2169 | {"[H", VI_K_HOME}, // Cursor Key Home |
2163 | {"[F", (Byte) VI_K_END}, // Cursor Key End | 2170 | {"[F", VI_K_END}, // Cursor Key End |
2164 | {"[1~", (Byte) VI_K_HOME}, // Cursor Key Home | 2171 | {"[1~", VI_K_HOME}, // Cursor Key Home |
2165 | {"[2~", (Byte) VI_K_INSERT}, // Cursor Key Insert | 2172 | {"[2~", VI_K_INSERT}, // Cursor Key Insert |
2166 | {"[4~", (Byte) VI_K_END}, // Cursor Key End | 2173 | {"[4~", VI_K_END}, // Cursor Key End |
2167 | {"[5~", (Byte) VI_K_PAGEUP}, // Cursor Key Page Up | 2174 | {"[5~", VI_K_PAGEUP}, // Cursor Key Page Up |
2168 | {"[6~", (Byte) VI_K_PAGEDOWN}, // Cursor Key Page Down | 2175 | {"[6~", VI_K_PAGEDOWN},// Cursor Key Page Down |
2169 | {"OP", (Byte) VI_K_FUN1}, // Function Key F1 | 2176 | {"OP", VI_K_FUN1}, // Function Key F1 |
2170 | {"OQ", (Byte) VI_K_FUN2}, // Function Key F2 | 2177 | {"OQ", VI_K_FUN2}, // Function Key F2 |
2171 | {"OR", (Byte) VI_K_FUN3}, // Function Key F3 | 2178 | {"OR", VI_K_FUN3}, // Function Key F3 |
2172 | {"OS", (Byte) VI_K_FUN4}, // Function Key F4 | 2179 | {"OS", VI_K_FUN4}, // Function Key F4 |
2173 | {"[15~", (Byte) VI_K_FUN5}, // Function Key F5 | 2180 | {"[15~", VI_K_FUN5}, // Function Key F5 |
2174 | {"[17~", (Byte) VI_K_FUN6}, // Function Key F6 | 2181 | {"[17~", VI_K_FUN6}, // Function Key F6 |
2175 | {"[18~", (Byte) VI_K_FUN7}, // Function Key F7 | 2182 | {"[18~", VI_K_FUN7}, // Function Key F7 |
2176 | {"[19~", (Byte) VI_K_FUN8}, // Function Key F8 | 2183 | {"[19~", VI_K_FUN8}, // Function Key F8 |
2177 | {"[20~", (Byte) VI_K_FUN9}, // Function Key F9 | 2184 | {"[20~", VI_K_FUN9}, // Function Key F9 |
2178 | {"[21~", (Byte) VI_K_FUN10}, // Function Key F10 | 2185 | {"[21~", VI_K_FUN10}, // Function Key F10 |
2179 | {"[23~", (Byte) VI_K_FUN11}, // Function Key F11 | 2186 | {"[23~", VI_K_FUN11}, // Function Key F11 |
2180 | {"[24~", (Byte) VI_K_FUN12}, // Function Key F12 | 2187 | {"[24~", VI_K_FUN12}, // Function Key F12 |
2181 | {"[11~", (Byte) VI_K_FUN1}, // Function Key F1 | 2188 | {"[11~", VI_K_FUN1}, // Function Key F1 |
2182 | {"[12~", (Byte) VI_K_FUN2}, // Function Key F2 | 2189 | {"[12~", VI_K_FUN2}, // Function Key F2 |
2183 | {"[13~", (Byte) VI_K_FUN3}, // Function Key F3 | 2190 | {"[13~", VI_K_FUN3}, // Function Key F3 |
2184 | {"[14~", (Byte) VI_K_FUN4}, // Function Key F4 | 2191 | {"[14~", VI_K_FUN4}, // Function Key F4 |
2185 | }; | 2192 | }; |
2186 | 2193 | ||
2187 | #define ESCCMDS_COUNT (sizeof(esccmds)/sizeof(struct esc_cmds)) | 2194 | #define ESCCMDS_COUNT (sizeof(esccmds)/sizeof(struct esc_cmds)) |
2188 | 2195 | ||
2189 | (void) alarm(0); // turn alarm OFF while we wait for input | 2196 | alarm(0); // turn alarm OFF while we wait for input |
2190 | fflush(stdout); | 2197 | fflush(stdout); |
2191 | n = readed_for_parse; | 2198 | n = readed_for_parse; |
2192 | // get input from User- are there already input chars in Q? | 2199 | // get input from User- are there already input chars in Q? |
2193 | if (n <= 0) { | 2200 | if (n <= 0) { |
2194 | ri0: | 2201 | ri0: |
2195 | // the Q is empty, wait for a typed char | 2202 | // the Q is empty, wait for a typed char |
2196 | n = read(0, readbuffer, BUFSIZ - 1); | 2203 | n = read(0, readbuffer, BUFSIZ - 1); |
2197 | if (n < 0) { | 2204 | if (n < 0) { |
@@ -2207,21 +2214,21 @@ static Byte readit(void) // read (maybe cursor) key from stdin | |||
2207 | editing = 0; | 2214 | editing = 0; |
2208 | errno = 0; | 2215 | errno = 0; |
2209 | } | 2216 | } |
2210 | if(n <= 0) | 2217 | if (n <= 0) |
2211 | return 0; // error | 2218 | return 0; // error |
2212 | if (readbuffer[0] == 27) { | 2219 | if (readbuffer[0] == 27) { |
2213 | // This is an ESC char. Is this Esc sequence? | 2220 | // This is an ESC char. Is this Esc sequence? |
2214 | // Could be bare Esc key. See if there are any | 2221 | // Could be bare Esc key. See if there are any |
2215 | // more chars to read after the ESC. This would | 2222 | // more chars to read after the ESC. This would |
2216 | // be a Function or Cursor Key sequence. | 2223 | // be a Function or Cursor Key sequence. |
2217 | FD_ZERO(&rfds); | 2224 | FD_ZERO(&rfds); |
2218 | FD_SET(0, &rfds); | 2225 | FD_SET(0, &rfds); |
2219 | tv.tv_sec = 0; | 2226 | tv.tv_sec = 0; |
2220 | tv.tv_usec = 50000; // Wait 5/100 seconds- 1 Sec=1000000 | 2227 | tv.tv_usec = 50000; // Wait 5/100 seconds- 1 Sec=1000000 |
2221 | 2228 | ||
2222 | // keep reading while there are input chars and room in buffer | 2229 | // keep reading while there are input chars and room in buffer |
2223 | while (select(1, &rfds, NULL, NULL, &tv) > 0 && n <= (BUFSIZ - 5)) { | 2230 | while (select(1, &rfds, NULL, NULL, &tv) > 0 && n <= (BUFSIZ - 5)) { |
2224 | // read the rest of the ESC string | 2231 | // read the rest of the ESC string |
2225 | int r = read(0, (void *) (readbuffer + n), BUFSIZ - n); | 2232 | int r = read(0, (void *) (readbuffer + n), BUFSIZ - n); |
2226 | if (r > 0) { | 2233 | if (r > 0) { |
2227 | n += r; | 2234 | n += r; |
@@ -2231,16 +2238,16 @@ static Byte readit(void) // read (maybe cursor) key from stdin | |||
2231 | readed_for_parse = n; | 2238 | readed_for_parse = n; |
2232 | } | 2239 | } |
2233 | c = readbuffer[0]; | 2240 | c = readbuffer[0]; |
2234 | if(c == 27 && n > 1) { | 2241 | if (c == 27 && n > 1) { |
2235 | // Maybe cursor or function key? | 2242 | // Maybe cursor or function key? |
2236 | const struct esc_cmds *eindex; | 2243 | const struct esc_cmds *eindex; |
2237 | 2244 | ||
2238 | for (eindex = esccmds; eindex < &esccmds[ESCCMDS_COUNT]; eindex++) { | 2245 | for (eindex = esccmds; eindex < &esccmds[ESCCMDS_COUNT]; eindex++) { |
2239 | int cnt = strlen(eindex->seq); | 2246 | int cnt = strlen(eindex->seq); |
2240 | 2247 | ||
2241 | if(n <= cnt) | 2248 | if (n <= cnt) |
2242 | continue; | 2249 | continue; |
2243 | if(strncmp(eindex->seq, (char *) readbuffer + 1, cnt)) | 2250 | if (strncmp(eindex->seq, readbuffer + 1, cnt)) |
2244 | continue; | 2251 | continue; |
2245 | // is a Cursor key- put derived value back into Q | 2252 | // is a Cursor key- put derived value back into Q |
2246 | c = eindex->val; | 2253 | c = eindex->val; |
@@ -2248,7 +2255,7 @@ static Byte readit(void) // read (maybe cursor) key from stdin | |||
2248 | n = cnt + 1; | 2255 | n = cnt + 1; |
2249 | break; | 2256 | break; |
2250 | } | 2257 | } |
2251 | if(eindex == &esccmds[ESCCMDS_COUNT]) { | 2258 | if (eindex == &esccmds[ESCCMDS_COUNT]) { |
2252 | /* defined ESC sequence not found, set only one ESC */ | 2259 | /* defined ESC sequence not found, set only one ESC */ |
2253 | n = 1; | 2260 | n = 1; |
2254 | } | 2261 | } |
@@ -2258,14 +2265,14 @@ static Byte readit(void) // read (maybe cursor) key from stdin | |||
2258 | // remove key sequence from Q | 2265 | // remove key sequence from Q |
2259 | readed_for_parse -= n; | 2266 | readed_for_parse -= n; |
2260 | memmove(readbuffer, readbuffer + n, BUFSIZ - n); | 2267 | memmove(readbuffer, readbuffer + n, BUFSIZ - n); |
2261 | (void) alarm(3); // we are done waiting for input, turn alarm ON | 2268 | alarm(3); // we are done waiting for input, turn alarm ON |
2262 | return c; | 2269 | return c; |
2263 | } | 2270 | } |
2264 | 2271 | ||
2265 | //----- IO Routines -------------------------------------------- | 2272 | //----- IO Routines -------------------------------------------- |
2266 | static Byte get_one_char(void) | 2273 | static char get_one_char(void) |
2267 | { | 2274 | { |
2268 | static Byte c; | 2275 | static char c; |
2269 | 2276 | ||
2270 | #if ENABLE_FEATURE_VI_DOT_CMD | 2277 | #if ENABLE_FEATURE_VI_DOT_CMD |
2271 | // ! adding2q && ioq == 0 read() | 2278 | // ! adding2q && ioq == 0 read() |
@@ -2291,7 +2298,7 @@ static Byte get_one_char(void) | |||
2291 | // adding STDIN chars to q | 2298 | // adding STDIN chars to q |
2292 | c = readit(); // get the users input | 2299 | c = readit(); // get the users input |
2293 | if (last_modifying_cmd != 0) { | 2300 | if (last_modifying_cmd != 0) { |
2294 | int len = strlen((char *) last_modifying_cmd); | 2301 | int len = strlen(last_modifying_cmd); |
2295 | if (len + 1 >= BUFSIZ) { | 2302 | if (len + 1 >= BUFSIZ) { |
2296 | psbs("last_modifying_cmd overrun"); | 2303 | psbs("last_modifying_cmd overrun"); |
2297 | } else { | 2304 | } else { |
@@ -2306,20 +2313,22 @@ static Byte get_one_char(void) | |||
2306 | return c; // return the char, where ever it came from | 2313 | return c; // return the char, where ever it came from |
2307 | } | 2314 | } |
2308 | 2315 | ||
2309 | static Byte *get_input_line(Byte * prompt) // get input line- use "status line" | 2316 | static char *get_input_line(const char * prompt) // get input line- use "status line" |
2310 | { | 2317 | { |
2311 | Byte buf[BUFSIZ]; | 2318 | static char *obufp; |
2312 | Byte c; | 2319 | |
2320 | char buf[BUFSIZ]; | ||
2321 | char c; | ||
2313 | int i; | 2322 | int i; |
2314 | static Byte *obufp = NULL; | ||
2315 | 2323 | ||
2316 | strcpy((char *) buf, (char *) prompt); | 2324 | strcpy(buf, prompt); |
2317 | last_status_cksum = 0; // force status update | 2325 | last_status_cksum = 0; // force status update |
2318 | place_cursor(rows - 1, 0, FALSE); // go to Status line, bottom of screen | 2326 | place_cursor(rows - 1, 0, FALSE); // go to Status line, bottom of screen |
2319 | clear_to_eol(); // clear the line | 2327 | clear_to_eol(); // clear the line |
2320 | write1((char *) prompt); // write out the :, /, or ? prompt | 2328 | write1(prompt); // write out the :, /, or ? prompt |
2321 | 2329 | ||
2322 | for (i = strlen((char *) buf); i < BUFSIZ;) { | 2330 | i = strlen(buf); |
2331 | while (i < BUFSIZ) { | ||
2323 | c = get_one_char(); // read user input | 2332 | c = get_one_char(); // read user input |
2324 | if (c == '\n' || c == '\r' || c == 27) | 2333 | if (c == '\n' || c == '\r' || c == 27) |
2325 | break; // is this end of input | 2334 | break; // is this end of input |
@@ -2341,26 +2350,26 @@ static Byte *get_input_line(Byte * prompt) // get input line- use "status line" | |||
2341 | } | 2350 | } |
2342 | refresh(FALSE); | 2351 | refresh(FALSE); |
2343 | free(obufp); | 2352 | free(obufp); |
2344 | obufp = (Byte *) xstrdup((char *) buf); | 2353 | obufp = xstrdup(buf); |
2345 | return obufp; | 2354 | return obufp; |
2346 | } | 2355 | } |
2347 | 2356 | ||
2348 | static int file_size(const Byte * fn) // what is the byte size of "fn" | 2357 | static int file_size(const char * fn) // what is the byte size of "fn" |
2349 | { | 2358 | { |
2350 | struct stat st_buf; | 2359 | struct stat st_buf; |
2351 | int cnt, sr; | 2360 | int cnt, sr; |
2352 | 2361 | ||
2353 | if (fn == 0 || strlen((char *)fn) <= 0) | 2362 | if (!fn || !fn[0]) |
2354 | return -1; | 2363 | return -1; |
2355 | cnt = -1; | 2364 | cnt = -1; |
2356 | sr = stat((char *) fn, &st_buf); // see if file exists | 2365 | sr = stat(fn, &st_buf); // see if file exists |
2357 | if (sr >= 0) { | 2366 | if (sr >= 0) { |
2358 | cnt = (int) st_buf.st_size; | 2367 | cnt = (int) st_buf.st_size; |
2359 | } | 2368 | } |
2360 | return cnt; | 2369 | return cnt; |
2361 | } | 2370 | } |
2362 | 2371 | ||
2363 | static int file_insert(Byte * fn, Byte * p, int size) | 2372 | static int file_insert(char * fn, char * p, int size) |
2364 | { | 2373 | { |
2365 | int fd, cnt; | 2374 | int fd, cnt; |
2366 | 2375 | ||
@@ -2368,7 +2377,7 @@ static int file_insert(Byte * fn, Byte * p, int size) | |||
2368 | #if ENABLE_FEATURE_VI_READONLY | 2377 | #if ENABLE_FEATURE_VI_READONLY |
2369 | readonly = FALSE; | 2378 | readonly = FALSE; |
2370 | #endif | 2379 | #endif |
2371 | if (fn == 0 || strlen((char*) fn) <= 0) { | 2380 | if (!fn || !fn[0]) { |
2372 | psbs("No filename given"); | 2381 | psbs("No filename given"); |
2373 | goto fi0; | 2382 | goto fi0; |
2374 | } | 2383 | } |
@@ -2390,13 +2399,13 @@ static int file_insert(Byte * fn, Byte * p, int size) | |||
2390 | #if ENABLE_FEATURE_VI_READONLY | 2399 | #if ENABLE_FEATURE_VI_READONLY |
2391 | if (vi_readonly) goto fi1; // do not try write-mode | 2400 | if (vi_readonly) goto fi1; // do not try write-mode |
2392 | #endif | 2401 | #endif |
2393 | fd = open((char *) fn, O_RDWR); // assume read & write | 2402 | fd = open(fn, O_RDWR); // assume read & write |
2394 | if (fd < 0) { | 2403 | if (fd < 0) { |
2395 | // could not open for writing- maybe file is read only | 2404 | // could not open for writing- maybe file is read only |
2396 | #if ENABLE_FEATURE_VI_READONLY | 2405 | #if ENABLE_FEATURE_VI_READONLY |
2397 | fi1: | 2406 | fi1: |
2398 | #endif | 2407 | #endif |
2399 | fd = open((char *) fn, O_RDONLY); // try read-only | 2408 | fd = open(fn, O_RDONLY); // try read-only |
2400 | if (fd < 0) { | 2409 | if (fd < 0) { |
2401 | psbs("\"%s\" %s", fn, "cannot open file"); | 2410 | psbs("\"%s\" %s", fn, "cannot open file"); |
2402 | goto fi0; | 2411 | goto fi0; |
@@ -2420,11 +2429,11 @@ static int file_insert(Byte * fn, Byte * p, int size) | |||
2420 | } | 2429 | } |
2421 | if (cnt >= size) | 2430 | if (cnt >= size) |
2422 | file_modified++; | 2431 | file_modified++; |
2423 | fi0: | 2432 | fi0: |
2424 | return cnt; | 2433 | return cnt; |
2425 | } | 2434 | } |
2426 | 2435 | ||
2427 | static int file_write(Byte * fn, Byte * first, Byte * last) | 2436 | static int file_write(char * fn, char * first, char * last) |
2428 | { | 2437 | { |
2429 | int fd, cnt, charcnt; | 2438 | int fd, cnt, charcnt; |
2430 | 2439 | ||
@@ -2434,14 +2443,14 @@ static int file_write(Byte * fn, Byte * first, Byte * last) | |||
2434 | } | 2443 | } |
2435 | charcnt = 0; | 2444 | charcnt = 0; |
2436 | // FIXIT- use the correct umask() | 2445 | // FIXIT- use the correct umask() |
2437 | fd = open((char *) fn, (O_WRONLY | O_CREAT | O_TRUNC), 0664); | 2446 | fd = open(fn, (O_WRONLY | O_CREAT | O_TRUNC), 0664); |
2438 | if (fd < 0) | 2447 | if (fd < 0) |
2439 | return -1; | 2448 | return -1; |
2440 | cnt = last - first + 1; | 2449 | cnt = last - first + 1; |
2441 | charcnt = write(fd, first, cnt); | 2450 | charcnt = write(fd, first, cnt); |
2442 | if (charcnt == cnt) { | 2451 | if (charcnt == cnt) { |
2443 | // good write | 2452 | // good write |
2444 | //file_modified= FALSE; // the file has not been modified | 2453 | //file_modified = FALSE; // the file has not been modified |
2445 | } else { | 2454 | } else { |
2446 | charcnt = 0; | 2455 | charcnt = 0; |
2447 | } | 2456 | } |
@@ -2468,9 +2477,9 @@ static void place_cursor(int row, int col, int opti) | |||
2468 | char *cm; | 2477 | char *cm; |
2469 | #if ENABLE_FEATURE_VI_OPTIMIZE_CURSOR | 2478 | #if ENABLE_FEATURE_VI_OPTIMIZE_CURSOR |
2470 | char cm2[BUFSIZ]; | 2479 | char cm2[BUFSIZ]; |
2471 | Byte *screenp; | 2480 | char *screenp; |
2472 | // char cm3[BUFSIZ]; | 2481 | // char cm3[BUFSIZ]; |
2473 | int Rrow= last_row; | 2482 | int Rrow = last_row; |
2474 | #endif | 2483 | #endif |
2475 | 2484 | ||
2476 | memset(cm1, '\0', BUFSIZ - 1); // clear the buffer | 2485 | memset(cm1, '\0', BUFSIZ - 1); // clear the buffer |
@@ -2481,9 +2490,10 @@ static void place_cursor(int row, int col, int opti) | |||
2481 | if (col >= columns) col = columns - 1; | 2490 | if (col >= columns) col = columns - 1; |
2482 | 2491 | ||
2483 | //----- 1. Try the standard terminal ESC sequence | 2492 | //----- 1. Try the standard terminal ESC sequence |
2484 | sprintf((char *) cm1, CMrc, row + 1, col + 1); | 2493 | sprintf(cm1, CMrc, row + 1, col + 1); |
2485 | cm= cm1; | 2494 | cm = cm1; |
2486 | if (! opti) goto pc0; | 2495 | if (!opti) |
2496 | goto pc0; | ||
2487 | 2497 | ||
2488 | #if ENABLE_FEATURE_VI_OPTIMIZE_CURSOR | 2498 | #if ENABLE_FEATURE_VI_OPTIMIZE_CURSOR |
2489 | //----- find the minimum # of chars to move cursor ------------- | 2499 | //----- find the minimum # of chars to move cursor ------------- |
@@ -2506,15 +2516,15 @@ static void place_cursor(int row, int col, int opti) | |||
2506 | strcat(cm2, "\r"); // start at col 0 | 2516 | strcat(cm2, "\r"); // start at col 0 |
2507 | // just send out orignal source char to get to correct place | 2517 | // just send out orignal source char to get to correct place |
2508 | screenp = &screen[row * columns]; // start of screen line | 2518 | screenp = &screen[row * columns]; // start of screen line |
2509 | strncat(cm2, (char* )screenp, col); | 2519 | strncat(cm2, screenp, col); |
2510 | 2520 | ||
2511 | //----- 3. Try some other way of moving cursor | 2521 | //----- 3. Try some other way of moving cursor |
2512 | //--------------------------------------------- | 2522 | //--------------------------------------------- |
2513 | 2523 | ||
2514 | // pick the shortest cursor motion to send out | 2524 | // pick the shortest cursor motion to send out |
2515 | cm= cm1; | 2525 | cm = cm1; |
2516 | if (strlen(cm2) < strlen(cm)) { | 2526 | if (strlen(cm2) < strlen(cm)) { |
2517 | cm= cm2; | 2527 | cm = cm2; |
2518 | } /* else if (strlen(cm3) < strlen(cm)) { | 2528 | } /* else if (strlen(cm3) < strlen(cm)) { |
2519 | cm= cm3; | 2529 | cm= cm3; |
2520 | } */ | 2530 | } */ |
@@ -2552,7 +2562,7 @@ static void flash(int h) | |||
2552 | { | 2562 | { |
2553 | standout_start(); // send "start reverse video" sequence | 2563 | standout_start(); // send "start reverse video" sequence |
2554 | redraw(TRUE); | 2564 | redraw(TRUE); |
2555 | (void) mysleep(h); | 2565 | mysleep(h); |
2556 | standout_end(); // send "end reverse video" sequence | 2566 | standout_end(); // send "end reverse video" sequence |
2557 | redraw(TRUE); | 2567 | redraw(TRUE); |
2558 | } | 2568 | } |
@@ -2577,12 +2587,13 @@ static void screen_erase(void) | |||
2577 | memset(screen, ' ', screensize); // clear new screen | 2587 | memset(screen, ' ', screensize); // clear new screen |
2578 | } | 2588 | } |
2579 | 2589 | ||
2580 | static int bufsum(unsigned char *buf, int count) | 2590 | static int bufsum(char *buf, int count) |
2581 | { | 2591 | { |
2582 | int sum = 0; | 2592 | int sum = 0; |
2583 | unsigned char *e = buf + count; | 2593 | char *e = buf + count; |
2594 | |||
2584 | while (buf < e) | 2595 | while (buf < e) |
2585 | sum += *buf++; | 2596 | sum += (unsigned char) *buf++; |
2586 | return sum; | 2597 | return sum; |
2587 | } | 2598 | } |
2588 | 2599 | ||
@@ -2600,10 +2611,10 @@ static void show_status_line(void) | |||
2600 | if (have_status_msg || ((cnt > 0 && last_status_cksum != cksum))) { | 2611 | if (have_status_msg || ((cnt > 0 && last_status_cksum != cksum))) { |
2601 | last_status_cksum= cksum; // remember if we have seen this line | 2612 | last_status_cksum= cksum; // remember if we have seen this line |
2602 | place_cursor(rows - 1, 0, FALSE); // put cursor on status line | 2613 | place_cursor(rows - 1, 0, FALSE); // put cursor on status line |
2603 | write1((char*)status_buffer); | 2614 | write1(status_buffer); |
2604 | clear_to_eol(); | 2615 | clear_to_eol(); |
2605 | if (have_status_msg) { | 2616 | if (have_status_msg) { |
2606 | if (((int)strlen((char*)status_buffer) - (have_status_msg - 1)) > | 2617 | if (((int)strlen(status_buffer) - (have_status_msg - 1)) > |
2607 | (columns - 1) ) { | 2618 | (columns - 1) ) { |
2608 | have_status_msg = 0; | 2619 | have_status_msg = 0; |
2609 | Hit_Return(); | 2620 | Hit_Return(); |
@@ -2622,9 +2633,9 @@ static void psbs(const char *format, ...) | |||
2622 | va_list args; | 2633 | va_list args; |
2623 | 2634 | ||
2624 | va_start(args, format); | 2635 | va_start(args, format); |
2625 | strcpy((char *) status_buffer, SOs); // Terminal standout mode on | 2636 | strcpy(status_buffer, SOs); // Terminal standout mode on |
2626 | vsprintf((char *) status_buffer + strlen((char *) status_buffer), format, args); | 2637 | vsprintf(status_buffer + strlen(status_buffer), format, args); |
2627 | strcat((char *) status_buffer, SOn); // Terminal standout mode off | 2638 | strcat(status_buffer, SOn); // Terminal standout mode off |
2628 | va_end(args); | 2639 | va_end(args); |
2629 | 2640 | ||
2630 | have_status_msg = 1 + sizeof(SOs) + sizeof(SOn) - 2; | 2641 | have_status_msg = 1 + sizeof(SOs) + sizeof(SOn) - 2; |
@@ -2636,15 +2647,15 @@ static void psb(const char *format, ...) | |||
2636 | va_list args; | 2647 | va_list args; |
2637 | 2648 | ||
2638 | va_start(args, format); | 2649 | va_start(args, format); |
2639 | vsprintf((char *) status_buffer, format, args); | 2650 | vsprintf(status_buffer, format, args); |
2640 | va_end(args); | 2651 | va_end(args); |
2641 | 2652 | ||
2642 | have_status_msg = 1; | 2653 | have_status_msg = 1; |
2643 | } | 2654 | } |
2644 | 2655 | ||
2645 | static void ni(Byte * s) // display messages | 2656 | static void ni(const char * s) // display messages |
2646 | { | 2657 | { |
2647 | Byte buf[BUFSIZ]; | 2658 | char buf[BUFSIZ]; |
2648 | 2659 | ||
2649 | print_literal(buf, s); | 2660 | print_literal(buf, s); |
2650 | psbs("\'%s\' is not implemented", buf); | 2661 | psbs("\'%s\' is not implemented", buf); |
@@ -2652,9 +2663,10 @@ static void ni(Byte * s) // display messages | |||
2652 | 2663 | ||
2653 | static int format_edit_status(void) // show file status on status line | 2664 | static int format_edit_status(void) // show file status on status line |
2654 | { | 2665 | { |
2655 | int cur, percent, ret, trunc_at; | ||
2656 | static int tot; | 2666 | static int tot; |
2657 | 2667 | ||
2668 | int cur, percent, ret, trunc_at; | ||
2669 | |||
2658 | // file_modified is now a counter rather than a flag. this | 2670 | // file_modified is now a counter rather than a flag. this |
2659 | // helps reduce the amount of line counting we need to do. | 2671 | // helps reduce the amount of line counting we need to do. |
2660 | // (this will cause a mis-reporting of modified status | 2672 | // (this will cause a mis-reporting of modified status |
@@ -2685,14 +2697,14 @@ static int format_edit_status(void) // show file status on status line | |||
2685 | trunc_at = columns < STATUS_BUFFER_LEN-1 ? | 2697 | trunc_at = columns < STATUS_BUFFER_LEN-1 ? |
2686 | columns : STATUS_BUFFER_LEN-1; | 2698 | columns : STATUS_BUFFER_LEN-1; |
2687 | 2699 | ||
2688 | ret = snprintf((char *) status_buffer, trunc_at+1, | 2700 | ret = snprintf(status_buffer, trunc_at+1, |
2689 | #if ENABLE_FEATURE_VI_READONLY | 2701 | #if ENABLE_FEATURE_VI_READONLY |
2690 | "%c %s%s%s %d/%d %d%%", | 2702 | "%c %s%s%s %d/%d %d%%", |
2691 | #else | 2703 | #else |
2692 | "%c %s%s %d/%d %d%%", | 2704 | "%c %s%s %d/%d %d%%", |
2693 | #endif | 2705 | #endif |
2694 | (cmd_mode ? (cmd_mode == 2 ? 'R':'I'):'-'), | 2706 | (cmd_mode ? (cmd_mode == 2 ? 'R':'I'):'-'), |
2695 | (cfn != 0 ? (char *) cfn : "No file"), | 2707 | (cfn != 0 ? cfn : "No file"), |
2696 | #if ENABLE_FEATURE_VI_READONLY | 2708 | #if ENABLE_FEATURE_VI_READONLY |
2697 | ((vi_readonly || readonly) ? " [Read-only]" : ""), | 2709 | ((vi_readonly || readonly) ? " [Read-only]" : ""), |
2698 | #endif | 2710 | #endif |
@@ -2717,12 +2729,12 @@ static void redraw(int full_screen) | |||
2717 | } | 2729 | } |
2718 | 2730 | ||
2719 | //----- Format a text[] line into a buffer --------------------- | 2731 | //----- Format a text[] line into a buffer --------------------- |
2720 | static void format_line(Byte *dest, Byte *src, int li) | 2732 | static void format_line(char *dest, char *src, int li) |
2721 | { | 2733 | { |
2722 | int co; | 2734 | int co; |
2723 | Byte c; | 2735 | char c; |
2724 | 2736 | ||
2725 | for (co= 0; co < MAX_SCR_COLS; co++) { | 2737 | for (co = 0; co < MAX_SCR_COLS; co++) { |
2726 | c= ' '; // assume blank | 2738 | c= ' '; // assume blank |
2727 | if (li > 0 && co == 0) { | 2739 | if (li > 0 && co == 0) { |
2728 | c = '~'; // not first line, assume Tilde | 2740 | c = '~'; // not first line, assume Tilde |
@@ -2745,9 +2757,9 @@ static void format_line(Byte *dest, Byte *src, int li) | |||
2745 | } | 2757 | } |
2746 | } else { | 2758 | } else { |
2747 | dest[co++] = '^'; | 2759 | dest[co++] = '^'; |
2748 | if(c == 127) | 2760 | if (c == 127) |
2749 | c = '?'; | 2761 | c = '?'; |
2750 | else | 2762 | else |
2751 | c += '@'; // make it visible | 2763 | c += '@'; // make it visible |
2752 | } | 2764 | } |
2753 | } | 2765 | } |
@@ -2767,11 +2779,12 @@ static void format_line(Byte *dest, Byte *src, int li) | |||
2767 | static void refresh(int full_screen) | 2779 | static void refresh(int full_screen) |
2768 | { | 2780 | { |
2769 | static int old_offset; | 2781 | static int old_offset; |
2782 | |||
2770 | int li, changed; | 2783 | int li, changed; |
2771 | Byte buf[MAX_SCR_COLS]; | 2784 | char buf[MAX_SCR_COLS]; |
2772 | Byte *tp, *sp; // pointer into text[] and screen[] | 2785 | char *tp, *sp; // pointer into text[] and screen[] |
2773 | #if ENABLE_FEATURE_VI_OPTIMIZE_CURSOR | 2786 | #if ENABLE_FEATURE_VI_OPTIMIZE_CURSOR |
2774 | int last_li= -2; // last line that changed- for optimizing cursor movement | 2787 | int last_li = -2; // last line that changed- for optimizing cursor movement |
2775 | #endif | 2788 | #endif |
2776 | 2789 | ||
2777 | if (ENABLE_FEATURE_VI_WIN_RESIZE) | 2790 | if (ENABLE_FEATURE_VI_WIN_RESIZE) |
@@ -2801,7 +2814,7 @@ static void refresh(int full_screen) | |||
2801 | } | 2814 | } |
2802 | // compare newly formatted buffer with virtual screen | 2815 | // compare newly formatted buffer with virtual screen |
2803 | // look forward for first difference between buf and screen | 2816 | // look forward for first difference between buf and screen |
2804 | for ( ; cs <= ce; cs++) { | 2817 | for (; cs <= ce; cs++) { |
2805 | if (buf[cs + offset] != sp[cs]) { | 2818 | if (buf[cs + offset] != sp[cs]) { |
2806 | changed = TRUE; // mark for redraw | 2819 | changed = TRUE; // mark for redraw |
2807 | break; | 2820 | break; |
@@ -2819,7 +2832,7 @@ static void refresh(int full_screen) | |||
2819 | 2832 | ||
2820 | // if horz offset has changed, force a redraw | 2833 | // if horz offset has changed, force a redraw |
2821 | if (offset != old_offset) { | 2834 | if (offset != old_offset) { |
2822 | re0: | 2835 | re0: |
2823 | changed = TRUE; | 2836 | changed = TRUE; |
2824 | } | 2837 | } |
2825 | 2838 | ||
@@ -2851,8 +2864,8 @@ static void refresh(int full_screen) | |||
2851 | 2864 | ||
2852 | // write line out to terminal | 2865 | // write line out to terminal |
2853 | { | 2866 | { |
2854 | int nic = ce-cs+1; | 2867 | int nic = ce - cs + 1; |
2855 | char *out = (char*)sp+cs; | 2868 | char *out = sp + cs; |
2856 | 2869 | ||
2857 | while (nic-- > 0) { | 2870 | while (nic-- > 0) { |
2858 | putchar(*out); | 2871 | putchar(*out); |
@@ -2898,14 +2911,15 @@ static void refresh(int full_screen) | |||
2898 | //--------------------------------------------------------------------- | 2911 | //--------------------------------------------------------------------- |
2899 | 2912 | ||
2900 | //----- Execute a Vi Command ----------------------------------- | 2913 | //----- Execute a Vi Command ----------------------------------- |
2901 | static void do_cmd(Byte c) | 2914 | static void do_cmd(char c) |
2902 | { | 2915 | { |
2903 | Byte c1, *p, *q, *msg, buf[9], *save_dot; | 2916 | const char *msg; |
2917 | char c1, *p, *q, buf[9], *save_dot; | ||
2904 | int cnt, i, j, dir, yf; | 2918 | int cnt, i, j, dir, yf; |
2905 | 2919 | ||
2906 | c1 = c; // quiet the compiler | 2920 | c1 = c; // quiet the compiler |
2907 | cnt = yf = dir = 0; // quiet the compiler | 2921 | cnt = yf = dir = 0; // quiet the compiler |
2908 | p = q = save_dot = msg = buf; // quiet the compiler | 2922 | msg = p = q = save_dot = buf; // quiet the compiler |
2909 | memset(buf, '\0', 9); // clear buf | 2923 | memset(buf, '\0', 9); // clear buf |
2910 | 2924 | ||
2911 | show_status_line(); | 2925 | show_status_line(); |
@@ -2949,7 +2963,7 @@ static void do_cmd(Byte c) | |||
2949 | goto dc1; | 2963 | goto dc1; |
2950 | } | 2964 | } |
2951 | 2965 | ||
2952 | key_cmd_mode: | 2966 | key_cmd_mode: |
2953 | switch (c) { | 2967 | switch (c) { |
2954 | //case 0x01: // soh | 2968 | //case 0x01: // soh |
2955 | //case 0x09: // ht | 2969 | //case 0x09: // ht |
@@ -3002,7 +3016,7 @@ key_cmd_mode: | |||
3002 | buf[1] = c + '@'; | 3016 | buf[1] = c + '@'; |
3003 | buf[2] = '\0'; | 3017 | buf[2] = '\0'; |
3004 | } | 3018 | } |
3005 | ni((Byte *) buf); | 3019 | ni(buf); |
3006 | end_cmd_q(); // stop adding to q | 3020 | end_cmd_q(); // stop adding to q |
3007 | case 0x00: // nul- ignore | 3021 | case 0x00: // nul- ignore |
3008 | break; | 3022 | break; |
@@ -3053,7 +3067,7 @@ key_cmd_mode: | |||
3053 | case 18: // ctrl-R force redraw | 3067 | case 18: // ctrl-R force redraw |
3054 | place_cursor(0, 0, FALSE); // put cursor in correct place | 3068 | place_cursor(0, 0, FALSE); // put cursor in correct place |
3055 | clear_to_eos(); // tel terminal to erase display | 3069 | clear_to_eos(); // tel terminal to erase display |
3056 | (void) mysleep(10); | 3070 | mysleep(10); |
3057 | screen_erase(); // erase the internal screen buffer | 3071 | screen_erase(); // erase the internal screen buffer |
3058 | last_status_cksum = 0; // force status update | 3072 | last_status_cksum = 0; // force status update |
3059 | refresh(TRUE); // this will redraw the entire display | 3073 | refresh(TRUE); // this will redraw the entire display |
@@ -3103,7 +3117,7 @@ key_cmd_mode: | |||
3103 | if (islower(c1)) { | 3117 | if (islower(c1)) { |
3104 | c1 = c1 - 'a'; | 3118 | c1 = c1 - 'a'; |
3105 | // get the b-o-l | 3119 | // get the b-o-l |
3106 | q = mark[(int) c1]; | 3120 | q = mark[(unsigned char) c1]; |
3107 | if (text <= q && q < end) { | 3121 | if (text <= q && q < end) { |
3108 | dot = q; | 3122 | dot = q; |
3109 | dot_begin(); // go to B-o-l | 3123 | dot_begin(); // go to B-o-l |
@@ -3140,7 +3154,7 @@ key_cmd_mode: | |||
3140 | break; | 3154 | break; |
3141 | } | 3155 | } |
3142 | // are we putting whole lines or strings | 3156 | // are we putting whole lines or strings |
3143 | if (strchr((char *) p, '\n') != NULL) { | 3157 | if (strchr(p, '\n') != NULL) { |
3144 | if (c == 'P') { | 3158 | if (c == 'P') { |
3145 | dot_begin(); // putting lines- Put above | 3159 | dot_begin(); // putting lines- Put above |
3146 | } | 3160 | } |
@@ -3203,7 +3217,8 @@ key_cmd_mode: | |||
3203 | if (cmdcnt-- > 1) { | 3217 | if (cmdcnt-- > 1) { |
3204 | do_cmd(';'); | 3218 | do_cmd(';'); |
3205 | } // repeat cnt | 3219 | } // repeat cnt |
3206 | if (last_forward_char == 0) break; | 3220 | if (last_forward_char == 0) |
3221 | break; | ||
3207 | q = dot + 1; | 3222 | q = dot + 1; |
3208 | while (q < end - 1 && *q != '\n' && *q != last_forward_char) { | 3223 | while (q < end - 1 && *q != '\n' && *q != last_forward_char) { |
3209 | q++; | 3224 | q++; |
@@ -3223,7 +3238,7 @@ key_cmd_mode: | |||
3223 | // Stuff the last_modifying_cmd back into stdin | 3238 | // Stuff the last_modifying_cmd back into stdin |
3224 | // and let it be re-executed. | 3239 | // and let it be re-executed. |
3225 | if (last_modifying_cmd != 0) { | 3240 | if (last_modifying_cmd != 0) { |
3226 | ioq = ioq_start = (Byte *) xstrdup((char *) last_modifying_cmd); | 3241 | ioq = ioq_start = xstrdup(last_modifying_cmd); |
3227 | } | 3242 | } |
3228 | break; | 3243 | break; |
3229 | #endif | 3244 | #endif |
@@ -3233,12 +3248,12 @@ key_cmd_mode: | |||
3233 | buf[0] = c; | 3248 | buf[0] = c; |
3234 | buf[1] = '\0'; | 3249 | buf[1] = '\0'; |
3235 | q = get_input_line(buf); // get input line- use "status line" | 3250 | q = get_input_line(buf); // get input line- use "status line" |
3236 | if (strlen((char *) q) == 1) | 3251 | if (q[0] && !q[1]) |
3237 | goto dc3; // if no pat re-use old pat | 3252 | goto dc3; // if no pat re-use old pat |
3238 | if (strlen((char *) q) > 1) { // new pat- save it and find | 3253 | if (q[0]) { // strlen(q) > 1: new pat- save it and find |
3239 | // there is a new pat | 3254 | // there is a new pat |
3240 | free(last_search_pattern); | 3255 | free(last_search_pattern); |
3241 | last_search_pattern = (Byte *) xstrdup((char *) q); | 3256 | last_search_pattern = xstrdup(q); |
3242 | goto dc3; // now find the pattern | 3257 | goto dc3; // now find the pattern |
3243 | } | 3258 | } |
3244 | // user changed mind and erased the "/"- do nothing | 3259 | // user changed mind and erased the "/"- do nothing |
@@ -3261,9 +3276,9 @@ key_cmd_mode: | |||
3261 | if (cmdcnt-- > 1) { | 3276 | if (cmdcnt-- > 1) { |
3262 | do_cmd(c); | 3277 | do_cmd(c); |
3263 | } // repeat cnt | 3278 | } // repeat cnt |
3264 | dc3: | 3279 | dc3: |
3265 | if (last_search_pattern == 0) { | 3280 | if (last_search_pattern == 0) { |
3266 | msg = (Byte *) "No previous regular expression"; | 3281 | msg = "No previous regular expression"; |
3267 | goto dc2; | 3282 | goto dc2; |
3268 | } | 3283 | } |
3269 | if (last_search_pattern[0] == '/') { | 3284 | if (last_search_pattern[0] == '/') { |
@@ -3274,11 +3289,11 @@ key_cmd_mode: | |||
3274 | dir = BACK; | 3289 | dir = BACK; |
3275 | p = dot - 1; | 3290 | p = dot - 1; |
3276 | } | 3291 | } |
3277 | dc4: | 3292 | dc4: |
3278 | q = char_search(p, last_search_pattern + 1, dir, FULL); | 3293 | q = char_search(p, last_search_pattern + 1, dir, FULL); |
3279 | if (q != NULL) { | 3294 | if (q != NULL) { |
3280 | dot = q; // good search, update "dot" | 3295 | dot = q; // good search, update "dot" |
3281 | msg = (Byte *) ""; | 3296 | msg = ""; |
3282 | goto dc2; | 3297 | goto dc2; |
3283 | } | 3298 | } |
3284 | // no pattern found between "dot" and "end"- continue at top | 3299 | // no pattern found between "dot" and "end"- continue at top |
@@ -3289,24 +3304,25 @@ key_cmd_mode: | |||
3289 | q = char_search(p, last_search_pattern + 1, dir, FULL); | 3304 | q = char_search(p, last_search_pattern + 1, dir, FULL); |
3290 | if (q != NULL) { // found something | 3305 | if (q != NULL) { // found something |
3291 | dot = q; // found new pattern- goto it | 3306 | dot = q; // found new pattern- goto it |
3292 | msg = (Byte *) "search hit BOTTOM, continuing at TOP"; | 3307 | msg = "search hit BOTTOM, continuing at TOP"; |
3293 | if (dir == BACK) { | 3308 | if (dir == BACK) { |
3294 | msg = (Byte *) "search hit TOP, continuing at BOTTOM"; | 3309 | msg = "search hit TOP, continuing at BOTTOM"; |
3295 | } | 3310 | } |
3296 | } else { | 3311 | } else { |
3297 | msg = (Byte *) "Pattern not found"; | 3312 | msg = "Pattern not found"; |
3298 | } | 3313 | } |
3299 | dc2: | 3314 | dc2: |
3300 | if (*msg) psbs("%s", msg); | 3315 | if (*msg) |
3316 | psbs("%s", msg); | ||
3301 | break; | 3317 | break; |
3302 | case '{': // {- move backward paragraph | 3318 | case '{': // {- move backward paragraph |
3303 | q = char_search(dot, (Byte *) "\n\n", BACK, FULL); | 3319 | q = char_search(dot, "\n\n", BACK, FULL); |
3304 | if (q != NULL) { // found blank line | 3320 | if (q != NULL) { // found blank line |
3305 | dot = next_line(q); // move to next blank line | 3321 | dot = next_line(q); // move to next blank line |
3306 | } | 3322 | } |
3307 | break; | 3323 | break; |
3308 | case '}': // }- move forward paragraph | 3324 | case '}': // }- move forward paragraph |
3309 | q = char_search(dot, (Byte *) "\n\n", FORWARD, FULL); | 3325 | q = char_search(dot, "\n\n", FORWARD, FULL); |
3310 | if (q != NULL) { // found blank line | 3326 | if (q != NULL) { // found blank line |
3311 | dot = next_line(q); // move to next blank line | 3327 | dot = next_line(q); // move to next blank line |
3312 | } | 3328 | } |
@@ -3329,26 +3345,28 @@ key_cmd_mode: | |||
3329 | } | 3345 | } |
3330 | break; | 3346 | break; |
3331 | case ':': // :- the colon mode commands | 3347 | case ':': // :- the colon mode commands |
3332 | p = get_input_line((Byte *) ":"); // get input line- use "status line" | 3348 | p = get_input_line(":"); // get input line- use "status line" |
3333 | #if ENABLE_FEATURE_VI_COLON | 3349 | #if ENABLE_FEATURE_VI_COLON |
3334 | colon(p); // execute the command | 3350 | colon(p); // execute the command |
3335 | #else | 3351 | #else |
3336 | if (*p == ':') | 3352 | if (*p == ':') |
3337 | p++; // move past the ':' | 3353 | p++; // move past the ':' |
3338 | cnt = strlen((char *) p); | 3354 | cnt = strlen(p); |
3339 | if (cnt <= 0) | 3355 | if (cnt <= 0) |
3340 | break; | 3356 | break; |
3341 | if (strncasecmp((char *) p, "quit", cnt) == 0 || | 3357 | if (strncasecmp(p, "quit", cnt) == 0 |
3342 | strncasecmp((char *) p, "q!", cnt) == 0) { // delete lines | 3358 | || strncasecmp(p, "q!", cnt) == 0 // delete lines |
3359 | ) { | ||
3343 | if (file_modified && p[1] != '!') { | 3360 | if (file_modified && p[1] != '!') { |
3344 | psbs("No write since last change (:quit! overrides)"); | 3361 | psbs("No write since last change (:quit! overrides)"); |
3345 | } else { | 3362 | } else { |
3346 | editing = 0; | 3363 | editing = 0; |
3347 | } | 3364 | } |
3348 | } else if (strncasecmp((char *) p, "write", cnt) == 0 | 3365 | } else if (strncasecmp(p, "write", cnt) == 0 |
3349 | || strncasecmp((char *) p, "wq", cnt) == 0 | 3366 | || strncasecmp(p, "wq", cnt) == 0 |
3350 | || strncasecmp((char *) p, "wn", cnt) == 0 | 3367 | || strncasecmp(p, "wn", cnt) == 0 |
3351 | || strncasecmp((char *) p, "x", cnt) == 0) { | 3368 | || strncasecmp(p, "x", cnt) == 0 |
3369 | ) { | ||
3352 | cnt = file_write(cfn, text, end - 1); | 3370 | cnt = file_write(cfn, text, end - 1); |
3353 | if (cnt < 0) { | 3371 | if (cnt < 0) { |
3354 | if (cnt == -1) | 3372 | if (cnt == -1) |
@@ -3357,18 +3375,19 @@ key_cmd_mode: | |||
3357 | file_modified = 0; | 3375 | file_modified = 0; |
3358 | last_file_modified = -1; | 3376 | last_file_modified = -1; |
3359 | psb("\"%s\" %dL, %dC", cfn, count_lines(text, end - 1), cnt); | 3377 | psb("\"%s\" %dL, %dC", cfn, count_lines(text, end - 1), cnt); |
3360 | if (p[0] == 'x' || p[1] == 'q' || p[1] == 'n' || | 3378 | if (p[0] == 'x' || p[1] == 'q' || p[1] == 'n' |
3361 | p[0] == 'X' || p[1] == 'Q' || p[1] == 'N') { | 3379 | || p[0] == 'X' || p[1] == 'Q' || p[1] == 'N' |
3380 | ) { | ||
3362 | editing = 0; | 3381 | editing = 0; |
3363 | } | 3382 | } |
3364 | } | 3383 | } |
3365 | } else if (strncasecmp((char *) p, "file", cnt) == 0 ) { | 3384 | } else if (strncasecmp(p, "file", cnt) == 0 ) { |
3366 | last_status_cksum = 0; // force status update | 3385 | last_status_cksum = 0; // force status update |
3367 | } else if (sscanf((char *) p, "%d", &j) > 0) { | 3386 | } else if (sscanf(p, "%d", &j) > 0) { |
3368 | dot = find_line(j); // go to line # j | 3387 | dot = find_line(j); // go to line # j |
3369 | dot_skip_over_ws(); | 3388 | dot_skip_over_ws(); |
3370 | } else { // unrecognised cmd | 3389 | } else { // unrecognised cmd |
3371 | ni((Byte *) p); | 3390 | ni(p); |
3372 | } | 3391 | } |
3373 | #endif /* !FEATURE_VI_COLON */ | 3392 | #endif /* !FEATURE_VI_COLON */ |
3374 | break; | 3393 | break; |
@@ -3377,7 +3396,7 @@ key_cmd_mode: | |||
3377 | cnt = count_lines(text, dot); // remember what line we are on | 3396 | cnt = count_lines(text, dot); // remember what line we are on |
3378 | c1 = get_one_char(); // get the type of thing to delete | 3397 | c1 = get_one_char(); // get the type of thing to delete |
3379 | find_range(&p, &q, c1); | 3398 | find_range(&p, &q, c1); |
3380 | (void) yank_delete(p, q, 1, YANKONLY); // save copy before change | 3399 | yank_delete(p, q, 1, YANKONLY); // save copy before change |
3381 | p = begin_line(p); | 3400 | p = begin_line(p); |
3382 | q = end_line(q); | 3401 | q = end_line(q); |
3383 | i = count_lines(p, q); // # of lines we are shifting | 3402 | i = count_lines(p, q); // # of lines we are shifting |
@@ -3386,16 +3405,16 @@ key_cmd_mode: | |||
3386 | // shift left- remove tab or 8 spaces | 3405 | // shift left- remove tab or 8 spaces |
3387 | if (*p == '\t') { | 3406 | if (*p == '\t') { |
3388 | // shrink buffer 1 char | 3407 | // shrink buffer 1 char |
3389 | (void) text_hole_delete(p, p); | 3408 | text_hole_delete(p, p); |
3390 | } else if (*p == ' ') { | 3409 | } else if (*p == ' ') { |
3391 | // we should be calculating columns, not just SPACE | 3410 | // we should be calculating columns, not just SPACE |
3392 | for (j = 0; *p == ' ' && j < tabstop; j++) { | 3411 | for (j = 0; *p == ' ' && j < tabstop; j++) { |
3393 | (void) text_hole_delete(p, p); | 3412 | text_hole_delete(p, p); |
3394 | } | 3413 | } |
3395 | } | 3414 | } |
3396 | } else if (c == '>') { | 3415 | } else if (c == '>') { |
3397 | // shift right -- add tab or 8 spaces | 3416 | // shift right -- add tab or 8 spaces |
3398 | (void) char_insert(p, '\t'); | 3417 | char_insert(p, '\t'); |
3399 | } | 3418 | } |
3400 | } | 3419 | } |
3401 | dot = find_line(cnt); // what line were we on | 3420 | dot = find_line(cnt); // what line were we on |
@@ -3462,7 +3481,7 @@ key_cmd_mode: | |||
3462 | //**** fall thru to ... 'i' | 3481 | //**** fall thru to ... 'i' |
3463 | case 'i': // i- insert before current char | 3482 | case 'i': // i- insert before current char |
3464 | case VI_K_INSERT: // Cursor Key Insert | 3483 | case VI_K_INSERT: // Cursor Key Insert |
3465 | dc_i: | 3484 | dc_i: |
3466 | cmd_mode = 1; // start insrting | 3485 | cmd_mode = 1; // start insrting |
3467 | break; | 3486 | break; |
3468 | case 'J': // J- join current and next lines together | 3487 | case 'J': // J- join current and next lines together |
@@ -3511,7 +3530,7 @@ key_cmd_mode: | |||
3511 | goto dc_i; | 3530 | goto dc_i; |
3512 | break; | 3531 | break; |
3513 | case 'R': // R- continuous Replace char | 3532 | case 'R': // R- continuous Replace char |
3514 | dc5: | 3533 | dc5: |
3515 | cmd_mode = 2; | 3534 | cmd_mode = 2; |
3516 | break; | 3535 | break; |
3517 | case 'X': // X- delete char before dot | 3536 | case 'X': // X- delete char before dot |
@@ -3632,24 +3651,24 @@ key_cmd_mode: | |||
3632 | if (c1 != 27) { | 3651 | if (c1 != 27) { |
3633 | // if CHANGING, not deleting, start inserting after the delete | 3652 | // if CHANGING, not deleting, start inserting after the delete |
3634 | if (c == 'c') { | 3653 | if (c == 'c') { |
3635 | strcpy((char *) buf, "Change"); | 3654 | strcpy(buf, "Change"); |
3636 | goto dc_i; // start inserting | 3655 | goto dc_i; // start inserting |
3637 | } | 3656 | } |
3638 | if (c == 'd') { | 3657 | if (c == 'd') { |
3639 | strcpy((char *) buf, "Delete"); | 3658 | strcpy(buf, "Delete"); |
3640 | } | 3659 | } |
3641 | #if ENABLE_FEATURE_VI_YANKMARK | 3660 | #if ENABLE_FEATURE_VI_YANKMARK |
3642 | if (c == 'y' || c == 'Y') { | 3661 | if (c == 'y' || c == 'Y') { |
3643 | strcpy((char *) buf, "Yank"); | 3662 | strcpy(buf, "Yank"); |
3644 | } | 3663 | } |
3645 | p = reg[YDreg]; | 3664 | p = reg[YDreg]; |
3646 | q = p + strlen((char *) p); | 3665 | q = p + strlen(p); |
3647 | for (cnt = 0; p <= q; p++) { | 3666 | for (cnt = 0; p <= q; p++) { |
3648 | if (*p == '\n') | 3667 | if (*p == '\n') |
3649 | cnt++; | 3668 | cnt++; |
3650 | } | 3669 | } |
3651 | psb("%s %d lines (%d chars) using [%c]", | 3670 | psb("%s %d lines (%d chars) using [%c]", |
3652 | buf, cnt, strlen((char *) reg[YDreg]), what_reg()); | 3671 | buf, cnt, strlen(reg[YDreg]), what_reg()); |
3653 | #endif | 3672 | #endif |
3654 | end_cmd_q(); // stop adding to q | 3673 | end_cmd_q(); // stop adding to q |
3655 | } | 3674 | } |
@@ -3739,10 +3758,10 @@ key_cmd_mode: | |||
3739 | break; | 3758 | break; |
3740 | } | 3759 | } |
3741 | 3760 | ||
3742 | dc1: | 3761 | dc1: |
3743 | // if text[] just became empty, add back an empty line | 3762 | // if text[] just became empty, add back an empty line |
3744 | if (end == text) { | 3763 | if (end == text) { |
3745 | (void) char_insert(text, '\n'); // start empty buf with dummy line | 3764 | char_insert(text, '\n'); // start empty buf with dummy line |
3746 | dot = text; | 3765 | dot = text; |
3747 | } | 3766 | } |
3748 | // it is OK for dot to exactly equal to end, otherwise check dot validity | 3767 | // it is OK for dot to exactly equal to end, otherwise check dot validity |
@@ -3770,14 +3789,15 @@ static int Ip = 97; // Insert command Probability | |||
3770 | static int Yp = 98; // Yank command Probability | 3789 | static int Yp = 98; // Yank command Probability |
3771 | static int Pp = 99; // Put command Probability | 3790 | static int Pp = 99; // Put command Probability |
3772 | static int M = 0, N = 0, I = 0, D = 0, Y = 0, P = 0, U = 0; | 3791 | static int M = 0, N = 0, I = 0, D = 0, Y = 0, P = 0, U = 0; |
3773 | char chars[20] = "\t012345 abcdABCD-=.$"; | 3792 | const char chars[20] = "\t012345 abcdABCD-=.$"; |
3774 | char *words[20] = { "this", "is", "a", "test", | 3793 | const char *const words[20] = { |
3794 | "this", "is", "a", "test", | ||
3775 | "broadcast", "the", "emergency", "of", | 3795 | "broadcast", "the", "emergency", "of", |
3776 | "system", "quick", "brown", "fox", | 3796 | "system", "quick", "brown", "fox", |
3777 | "jumped", "over", "lazy", "dogs", | 3797 | "jumped", "over", "lazy", "dogs", |
3778 | "back", "January", "Febuary", "March" | 3798 | "back", "January", "Febuary", "March" |
3779 | }; | 3799 | }; |
3780 | char *lines[20] = { | 3800 | const char *const lines[20] = { |
3781 | "You should have received a copy of the GNU General Public License\n", | 3801 | "You should have received a copy of the GNU General Public License\n", |
3782 | "char c, cm, *cmd, *cmd1;\n", | 3802 | "char c, cm, *cmd, *cmd1;\n", |
3783 | "generate a command by percentages\n", | 3803 | "generate a command by percentages\n", |
@@ -3835,7 +3855,7 @@ static void crash_dummy() | |||
3835 | // is there already a command running? | 3855 | // is there already a command running? |
3836 | if (readed_for_parse > 0) | 3856 | if (readed_for_parse > 0) |
3837 | goto cd1; | 3857 | goto cd1; |
3838 | cd0: | 3858 | cd0: |
3839 | startrbi = rbi = 0; | 3859 | startrbi = rbi = 0; |
3840 | sleeptime = 0; // how long to pause between commands | 3860 | sleeptime = 0; // how long to pause between commands |
3841 | memset(readbuffer, '\0', BUFSIZ); // clear the read buffer | 3861 | memset(readbuffer, '\0', BUFSIZ); // clear the read buffer |
@@ -3897,54 +3917,55 @@ static void crash_dummy() | |||
3897 | if (thing == 0) { // insert chars | 3917 | if (thing == 0) { // insert chars |
3898 | readbuffer[rbi++] = chars[((int) lrand48() % strlen(chars))]; | 3918 | readbuffer[rbi++] = chars[((int) lrand48() % strlen(chars))]; |
3899 | } else if (thing == 1) { // insert words | 3919 | } else if (thing == 1) { // insert words |
3900 | strcat((char *) readbuffer, words[(int) lrand48() % 20]); | 3920 | strcat(readbuffer, words[(int) lrand48() % 20]); |
3901 | strcat((char *) readbuffer, " "); | 3921 | strcat(readbuffer, " "); |
3902 | sleeptime = 0; // how fast to type | 3922 | sleeptime = 0; // how fast to type |
3903 | } else if (thing == 2) { // insert lines | 3923 | } else if (thing == 2) { // insert lines |
3904 | strcat((char *) readbuffer, lines[(int) lrand48() % 20]); | 3924 | strcat(readbuffer, lines[(int) lrand48() % 20]); |
3905 | sleeptime = 0; // how fast to type | 3925 | sleeptime = 0; // how fast to type |
3906 | } else { // insert multi-lines | 3926 | } else { // insert multi-lines |
3907 | strcat((char *) readbuffer, multilines[(int) lrand48() % 20]); | 3927 | strcat(readbuffer, multilines[(int) lrand48() % 20]); |
3908 | sleeptime = 0; // how fast to type | 3928 | sleeptime = 0; // how fast to type |
3909 | } | 3929 | } |
3910 | } | 3930 | } |
3911 | strcat((char *) readbuffer, "\033"); | 3931 | strcat(readbuffer, "\033"); |
3912 | } | 3932 | } |
3913 | readed_for_parse = strlen(readbuffer); | 3933 | readed_for_parse = strlen(readbuffer); |
3914 | cd1: | 3934 | cd1: |
3915 | totalcmds++; | 3935 | totalcmds++; |
3916 | if (sleeptime > 0) | 3936 | if (sleeptime > 0) |
3917 | (void) mysleep(sleeptime); // sleep 1/100 sec | 3937 | mysleep(sleeptime); // sleep 1/100 sec |
3918 | } | 3938 | } |
3919 | 3939 | ||
3920 | // test to see if there are any errors | 3940 | // test to see if there are any errors |
3921 | static void crash_test() | 3941 | static void crash_test() |
3922 | { | 3942 | { |
3923 | static time_t oldtim; | 3943 | static time_t oldtim; |
3944 | |||
3924 | time_t tim; | 3945 | time_t tim; |
3925 | char d[2], msg[BUFSIZ]; | 3946 | char d[2], msg[BUFSIZ]; |
3926 | 3947 | ||
3927 | msg[0] = '\0'; | 3948 | msg[0] = '\0'; |
3928 | if (end < text) { | 3949 | if (end < text) { |
3929 | strcat((char *) msg, "end<text "); | 3950 | strcat(msg, "end<text "); |
3930 | } | 3951 | } |
3931 | if (end > textend) { | 3952 | if (end > textend) { |
3932 | strcat((char *) msg, "end>textend "); | 3953 | strcat(msg, "end>textend "); |
3933 | } | 3954 | } |
3934 | if (dot < text) { | 3955 | if (dot < text) { |
3935 | strcat((char *) msg, "dot<text "); | 3956 | strcat(msg, "dot<text "); |
3936 | } | 3957 | } |
3937 | if (dot > end) { | 3958 | if (dot > end) { |
3938 | strcat((char *) msg, "dot>end "); | 3959 | strcat(msg, "dot>end "); |
3939 | } | 3960 | } |
3940 | if (screenbegin < text) { | 3961 | if (screenbegin < text) { |
3941 | strcat((char *) msg, "screenbegin<text "); | 3962 | strcat(msg, "screenbegin<text "); |
3942 | } | 3963 | } |
3943 | if (screenbegin > end - 1) { | 3964 | if (screenbegin > end - 1) { |
3944 | strcat((char *) msg, "screenbegin>end-1 "); | 3965 | strcat(msg, "screenbegin>end-1 "); |
3945 | } | 3966 | } |
3946 | 3967 | ||
3947 | if (strlen(msg) > 0) { | 3968 | if (msg[0]) { |
3948 | alarm(0); | 3969 | alarm(0); |
3949 | printf("\n\n%d: \'%c\' %s\n\n\n%s[Hit return to continue]%s", | 3970 | printf("\n\n%d: \'%c\' %s\n\n\n%s[Hit return to continue]%s", |
3950 | totalcmds, last_input_char, msg, SOs, SOn); | 3971 | totalcmds, last_input_char, msg, SOs, SOn); |
@@ -3957,7 +3978,7 @@ static void crash_test() | |||
3957 | } | 3978 | } |
3958 | tim = (time_t) time((time_t *) 0); | 3979 | tim = (time_t) time((time_t *) 0); |
3959 | if (tim >= (oldtim + 3)) { | 3980 | if (tim >= (oldtim + 3)) { |
3960 | sprintf((char *) status_buffer, | 3981 | sprintf(status_buffer, |
3961 | "Tot=%d: M=%d N=%d I=%d D=%d Y=%d P=%d U=%d size=%d", | 3982 | "Tot=%d: M=%d N=%d I=%d D=%d Y=%d P=%d U=%d size=%d", |
3962 | totalcmds, M, N, I, D, Y, P, U, end - text + 1); | 3983 | totalcmds, M, N, I, D, Y, P, U, end - text + 1); |
3963 | oldtim = tim; | 3984 | oldtim = tim; |