c65c3e4ff58bb0fce85e62da8e69de095752f846
8 static void act_exit (void);
9 static void act_save (void);
10 static void act_exitsave (void);
11 static void act_top (void);
12 static void act_pgup (void);
13 static void act_up (void);
14 static void act_home (void);
15 static void act_left (void);
16 static void act_right (void);
17 static void act_end (void);
18 static void act_down (void);
19 static void act_pgdn (void);
20 static void act_bottom (void);
21 static void act_togins (void);
22 static void act_chmode (void);
23 extern void act_self_ins (void); /* this one must be external */
24 static void act_delete (void);
25 static void act_delch (void);
26 static void act_mark (void);
27 static void act_cut (void);
28 static void act_copy (void);
29 static void act_paste (void);
30 static void act_susp (void);
31 static void act_goto (void);
32 static void act_togstat (void);
33 static void act_search (void);
34 static void act_recentre (void);
35 static void act_width (void);
36 static void act_offset (void);
38 static void act_diagnostics (void);
41 keyact
parse_action (char *name
) {
43 "exit", "top-of-file", "page-up", "move-up",
44 "begin-line", "move-left", "move-right", "end-line",
45 "move-down", "page-down", "bottom-of-file", "toggle-insert",
46 "change-mode", "delete-left", "delete-right", "mark-place",
47 "cut", "copy", "paste", "suspend", "goto-position",
48 "toggle-status", "search", "save-file", "exit-and-save",
49 "screen-recentre", "new-width", "new-offset"
55 act_exit
, act_top
, act_pgup
, act_up
, act_home
, act_left
,
56 act_right
, act_end
, act_down
, act_pgdn
, act_bottom
,
57 act_togins
, act_chmode
, act_delete
, act_delch
, act_mark
,
58 act_cut
, act_copy
, act_paste
, act_susp
, act_goto
,
59 act_togstat
, act_search
, act_save
, act_exitsave
,
60 act_recentre
, act_width
, act_offset
67 for (i
=0; i
<sizeof(names
)/sizeof(*names
); i
++)
68 if (!strcmp(name
, names
[i
]))
73 static int begline(int x
) {
74 int y
= x
+ width
-offset
;
82 static int endline(int x
) {
83 int y
= x
+ width
-offset
;
92 static void act_exit(void) {
93 static char question
[] = "File is modified. Save before quitting? [yn] ";
97 display_moveto (display_rows
-1, 0);
98 display_clear_to_eol ();
99 display_set_colour (COL_MINIBUF
);
100 display_write_str (question
);
103 #if defined(unix) && !defined(GO32)
104 if (update_required
) {
106 display_moveto (display_rows
-1, 0);
107 display_clear_to_eol ();
108 display_set_colour (COL_MINIBUF
);
109 display_write_str (question
);
114 c
= display_getkey();
115 #if defined(unix) && !defined(GO32)
118 if (c
>= 'a' && c
<= 'z')
120 } while (c
!= 'Y' && c
!= 'N' && c
!= '\007');
124 return; /* couldn't save, so don't quit */
125 draw_scr(); /* update the ** on status line! */
126 } else if (c
== '\007') {
127 return; /* don't even quit */
133 static void act_save(void) {
134 static int backed_up
= FALSE
;
137 if (!backup_file()) {
139 strcpy (message
, "Unable to back up file!");
146 strcpy (message
, "Unable to save file!");
152 static void act_exitsave(void) {
154 draw_scr(); /* update ** on status line */
158 static void act_top (void) {
159 cur_pos
= top_pos
= 0;
160 edit_type
= !!edit_type
;
163 static void act_pgup(void) {
164 cur_pos
-= (scrlines
-1)*width
;
167 edit_type
= !!edit_type
;
169 if (top_pos
> cur_pos
)
170 top_pos
= begline(cur_pos
);
173 static void act_up(void) {
177 edit_type
= !!edit_type
;
179 if (top_pos
> cur_pos
)
180 top_pos
= begline(cur_pos
);
183 static void act_home(void) {
184 cur_pos
= begline(cur_pos
);
187 if (top_pos
> cur_pos
)
188 top_pos
= begline(cur_pos
);
189 edit_type
= !!edit_type
;
192 static void act_left(void) {
193 if (edit_type
== 2) {
198 edit_type
= 2*!!edit_type
;
201 edit_type
= !!edit_type
;
203 if (top_pos
> cur_pos
)
204 top_pos
= begline(cur_pos
);
208 static void act_right(void) {
211 if (edit_type
== 1) {
212 if (cur_pos
< file_size
)
217 if (cur_pos
> file_size
)
219 new_top
= cur_pos
- (scrlines
-1) * width
;
222 new_top
= begline(new_top
);
223 if (top_pos
< new_top
)
225 edit_type
= !!edit_type
;
229 static void act_end(void) {
232 cur_pos
= endline(cur_pos
);
233 edit_type
= !!edit_type
;
234 if (cur_pos
>= file_size
)
236 new_top
= cur_pos
- (scrlines
-1) * width
;
239 new_top
= begline(new_top
);
240 if (top_pos
< new_top
)
244 static void act_down(void) {
248 if (cur_pos
>= file_size
) {
250 edit_type
= !!edit_type
;
252 new_top
= cur_pos
- (scrlines
-1) * width
;
255 new_top
= begline(new_top
);
256 if (top_pos
< new_top
)
260 static void act_pgdn(void) {
263 cur_pos
+= (scrlines
-1) * width
;
264 if (cur_pos
>= file_size
) {
266 edit_type
= !!edit_type
;
268 new_top
= cur_pos
- (scrlines
-1) * width
;
271 new_top
= begline(new_top
);
272 if (top_pos
< new_top
)
276 static void act_bottom (void) {
280 edit_type
= !!edit_type
;
281 new_top
= cur_pos
- (scrlines
-1) * width
;
284 new_top
= begline(new_top
);
285 if (top_pos
< new_top
)
289 static void act_togins(void) {
290 if (look_mode
|| fix_mode
) {
292 sprintf(message
, "Can't engage Insert mode when in %s mode",
293 (look_mode ?
"LOOK" : "FIX"));
294 insert_mode
= FALSE
; /* safety! */
296 insert_mode
= !insert_mode
;
299 static void act_chmode(void) {
301 edit_type
= !edit_type
; /* 0 -> 1, [12] -> 0 */
302 else if (edit_type
== 0) /* just in case */
306 void act_self_ins(void) {
307 int insert
= insert_mode
;
312 strcpy (message
, "Can't modify file in LOOK mode");
317 if (last_char
>= '0' && last_char
<= '9')
319 else if (last_char
>= 'A' && last_char
<= 'F')
321 else if (last_char
>= 'a' && last_char
<= 'f')
325 strcpy(message
, "Not a valid character when in hex editing mode");
330 if ( (!insert
|| edit_type
== 2) && cur_pos
== file_size
) {
332 strcpy(message
, "End of file reached");
337 case 0: /* ascii mode */
340 case 1: /* hex, first digit */
344 buf_fetch_data(filedata
, &c
, 1, cur_pos
);
348 case 2: /* hex, second digit */
349 buf_fetch_data(filedata
, &c
, 1, cur_pos
);
357 buf_insert_data(filedata
, &c
, 1, cur_pos
);
360 } else if (cur_pos
< file_size
) {
361 buf_overwrite_data(filedata
, &c
, 1, cur_pos
);
365 strcpy(message
, "End of file reached");
370 static void act_delete(void) {
371 if (!insert_mode
|| (edit_type
!=2 && cur_pos
==0)) {
373 strcpy (message
, "Can't delete while not in Insert mode");
374 } else if (cur_pos
> 0 || edit_type
== 2) {
376 buf_delete (filedata
, 1, cur_pos
);
378 edit_type
= !!edit_type
;
383 static void act_delch(void) {
386 strcpy (message
, "Can't delete while not in Insert mode");
387 } else if (cur_pos
< file_size
) {
388 buf_delete (filedata
, 1, cur_pos
);
390 edit_type
= !!edit_type
;
395 static void act_mark (void) {
398 strcpy (message
, "Can't cut or paste in LOOK mode");
399 marking
= FALSE
; /* safety */
403 mark_point
= cur_pos
;
406 static void act_cut (void) {
407 long marktop
, marksize
;
409 if (!marking
|| mark_point
==cur_pos
) {
411 strcpy (message
, "Set mark first");
416 strcpy (message
, "Can't cut while not in Insert mode");
420 marksize
= mark_point
- cur_pos
;
423 marksize
= -marksize
;
426 buf_free (cutbuffer
);
427 cutbuffer
= buf_cut (filedata
, marksize
, marktop
);
428 file_size
-= marksize
;
432 if (top_pos
> cur_pos
)
433 top_pos
= begline(cur_pos
);
434 edit_type
= !!edit_type
;
439 static void act_copy (void) {
440 int marktop
, marksize
;
444 strcpy (message
, "Set mark first");
448 marksize
= mark_point
- cur_pos
;
451 marksize
= -marksize
;
454 buf_free (cutbuffer
);
455 cutbuffer
= buf_copy (filedata
, marksize
, marktop
);
459 static void act_paste (void) {
460 int cutsize
, new_top
;
462 cutsize
= buf_length (cutbuffer
);
464 if (cur_pos
+ cutsize
> file_size
) {
466 strcpy (message
, "Too close to end of file to paste");
469 buf_delete (filedata
, cutsize
, cur_pos
);
470 file_size
-= cutsize
;
472 buf_paste (filedata
, cutbuffer
, cur_pos
);
475 file_size
+= cutsize
;
476 edit_type
= !!edit_type
;
477 new_top
= cur_pos
- (scrlines
-1) * width
;
480 new_top
= begline(new_top
);
481 if (top_pos
< new_top
)
485 static void act_susp (void) {
489 static void act_goto (void) {
491 long position
, new_top
;
494 if (!get_str("Enter position to go to: ", buffer
, FALSE
))
495 return; /* user break */
497 position
= parse_num (buffer
, &error
);
500 strcpy (message
, "Unable to parse position value");
504 if (position
< 0 || position
> file_size
) {
506 strcpy (message
, "Position is outside bounds of file");
511 edit_type
= !!edit_type
;
512 new_top
= cur_pos
- (scrlines
-1) * width
;
515 new_top
= begline(new_top
);
516 if (top_pos
> cur_pos
)
517 top_pos
= begline(cur_pos
);
518 if (top_pos
< new_top
)
522 static void act_togstat (void) {
523 if (statfmt
== decstatus
)
529 static void act_search (void) {
531 int len
, posn
, dfapos
;
533 static unsigned char sblk
[SEARCH_BLK
];
534 static char withdef
[] = "Search for (default=last): ";
535 static char withoutdef
[] = "Search for: ";
539 if (!get_str(dfa ? withdef
: withoutdef
, buffer
, TRUE
))
540 return; /* user break */
541 if (!dfa
&& !*buffer
) {
542 strcpy (message
, "Search aborted.");
549 len
= parse_quoted (buffer
);
552 strcpy (message
, "Invalid escape sequence in search string");
555 dfa
= build_dfa (buffer
, len
);
560 for (posn
= cur_pos
+1; posn
< file_size
; posn
++) {
562 int size
= SEARCH_BLK
;
564 if (size
> file_size
-posn
)
565 size
= file_size
-posn
;
566 buf_fetch_data (filedata
, sblk
, size
, posn
);
570 dfapos
= dfa
[dfapos
][*q
++];
574 cur_pos
= posn
- len
;
575 edit_type
= !!edit_type
;
576 new_top
= cur_pos
- (scrlines
-1) * width
;
577 new_top
= begline(new_top
);
578 if (top_pos
< new_top
)
584 strcpy (message
, "Not found.");
587 static void act_recentre (void) {
588 top_pos
= cur_pos
- (display_rows
-2)/2 * width
;
591 top_pos
= begline(top_pos
);
594 static void act_width (void) {
601 sprintf (prompt
, "Enter screen width in bytes (now %d): ", width
);
602 if (!get_str (prompt
, buffer
, FALSE
))
604 w
= parse_num (buffer
, &error
);
607 strcpy (message
, "Unable to parse width value");
613 new_top
= cur_pos
- (scrlines
-1) * width
;
614 new_top
= begline(new_top
);
615 if (top_pos
< new_top
)
620 static void act_offset (void) {
627 sprintf (prompt
, "Enter start-of-file offset in bytes (now %d): ",
629 if (!get_str (prompt
, buffer
, FALSE
))
631 o
= parse_num (buffer
, &error
);
634 strcpy (message
, "Unable to parse offset value");
640 new_top
= cur_pos
- (scrlines
-1) * width
;
641 new_top
= begline(new_top
);
642 if (top_pos
< new_top
)
648 static void act_diagnostics(void)
650 extern void buffer_diagnostic(buffer
*buf
, char *title
);
652 buffer_diagnostic(filedata
, "filedata");
653 buffer_diagnostic(cutbuffer
, "cutbuffer");