📄 mbedit.c
字号:
search_macro = 0;
}
/* "macro(<filename>)" ACHTUNG !! keine blanks im string !! */
mk_len = strlen(MACRO_KENNUNG);
if (strnicmp (argv[ii], MACRO_KENNUNG, mk_len) == 0)
{
no_of_options++;
name_stt = &argv[ii][mk_len]; /* 1. char hinter '(' */
name_end = &argv[ii][mk_len];
while ((*name_end != ')') &&
(*name_end != '\0'))
{
name_end++;
}
*name_end = '\0';
/* build macro filename */
read_macro = 1;
}
}
/* introduction */
if (get_video_active (0))
{
show_intro ();
/* sleep (1); */
}
/* store path name of exe-file */
store_exe_path (argv [0]);
#if (DEMO_VERSION == 2)
/* calculate checksum */
if (!checksum_ok (argv [0]))
edit_version = 2;
#endif
/* get history file */
read_history_file ();
#if (WITH_SYNTAX_HIGHLIGHTING)
/* get file for syntax highlighting */
search_syntax_file();
#endif
#if (WITH_LAST_AGAIN)
read_status_file ();
/* option "-" invoked ? set list of filenames in argc, argv [] */
if (last_again)
{
/* set virtual command line arguments */
argc = mini_file_num + 1;
no_of_options = 0;
} /* if last_again */
#endif
/* read all data files from command line */
/* "mbedit <file 1> <file 2> ... <file n> [option1] [option2] [option3]" */
no_of_files = argc - no_of_options - 1;
no_of_files = min (no_of_files, MAX_FC_NUM); /* begrenzen */
set.file_num = max (set.file_num, no_of_files); /* ggf. erhoehen */
/* loop for arguments */
for (ii = 1 ; ii <= no_of_files ; ii++)
{
/* filename extrahieren */
#if (WITH_LAST_AGAIN)
if (last_again)
strncpy (fc->filename, mini_control[ii-1].filename, sizeof (fc->filename));
else
strncpy (fc->filename, argv[ii], sizeof (fc->filename));
#else
strncpy (fc->filename, argv[ii], sizeof (fc->filename));
#endif
/* ^^^^^^^ */
/* ACHTUNG ! Hier nicht memcpy verwenden, sonst possible */
/* segmentation violation, da ueber das ende von argv[ii] */
/* hinaus gelesen wird. Ob das gut geht, haengt von der */
/* Umgebung ab (z.B. Aufruf von shell oder fids) !! */
fc->filename [sizeof(fc->filename)-1] = '\0';
fc->view_only = view_only_flag;
fc->byte_anz = -1;
/* read data file */
ok_flag = get_1_datafile ();
/* get next file buffer */
if (no_of_files > 1)
{
ok_flag = get_next_file_buffer (1);
if (ok_flag < 0)
break; /* no more buffer, abort loop */
}
} /* for loop */
#if (WITH_LAST_AGAIN)
/* option "-" invoked ? set cursor position */
if (last_again)
{
for (ii = 0 ; ii < no_of_files ; ii++)
{
perform_move (mini_control[ii].byte_index);
fc->view_only = mini_control[ii].view_only;
exchange_file_control (no_of_files, 1);
}
} /* if last_again */
#endif
/* get macro file(s) */
if (read_macro)
{
read_macro_file (name_stt, 1);
}
else
{
if (search_macro)
search_macro_file ();
}
set.file_num = max (set.file_num, no_of_files); /* ggf. erhoehen */
/* prepare macro "INIT" for later execution */
macro_ex = get_macro_adress ("INIT");
if (macro_ex != NULL)
{
push_macro_stack (macro_ex, MACRO_EXECUTE, 1L, mode_flag);
}
/* activate mouse driver */
#if WITH_MOUSE
if (mouse_status)
{
if (get_video_active(0))
show_status_line_2 ("*** initializing mouse driver ***", 0, -2, 0);
mouse_driver_ok = 1 - MouStartup (COLUMNS, (ROWS-STATUS_LINES));
}
#endif
#if (WITH_WINCH)
set_window_size ();
#endif
/* activate # of rows + columns from: */
/* - set_window_size () or */
/* - read_macro_file () */
if (get_video_active(0))
resize_screen ();
/* call main loop */
#if (DEMO_VERSION)
#if (DEMO_VERSION == 2)
show_edit_message (edit_version - 1);
if (edit_version == 1)
main_loop ();
else
delete_datafile (argv[0]); /* executable program */
#else
show_edit_message (2);
main_loop ();
show_edit_message (3);
#endif
#else
main_loop ();
#endif
/* put back buffers */
for (ii = 0 ; ii < MAX_FC_NUM ; ii++)
{
fc = &file_control [ii];
if (fc->malloc_flag) loc_free (fc->buff_0);
}
/* write back history file */
write_history_file (1);
#if (WITH_LAST_AGAIN)
write_status_file ();
#endif
/* stop mouse driver */
#if WITH_MOUSE
if (mouse_driver_ok)
{
if (get_video_active(0))
show_status_line_2 ("*** stopping mouse driver ***", 0, -2, 0);
MouEnd ();
}
#endif
/* end of program */
push_attributes (); /* restore old screen colors */
if (get_video_active(0))
clear_screen ();
printf ("\015\012");
/* restore keyboard and signal status */
kb_echo_on ();
RestoreVideoContext ();
signal (SIGINT, SIG_DFL);
exit (0);
return (0);
} /* main */
/* -FF- */
/*-----------------*/
/* main loop */
/*-----------------*/
char * get_line_1_text (void)
{
if (get_macro_status () == MACRO_CREATE)
return ("<MACRO Create>");
else
return fc->filename;
} /* get_line_1_text */
/* mit einem langsamen vt-100-terminal ist das staendige updaten der */
/* status_line_1 zu aufwendig, hier wird statt dessen mit timeout */
/* gearbeitet (nur unter unix). */
#if (SLOW_TERMINAL)
static int jmpret;
static jmp_buf env;
#define OUT_TIME 1 /* sec. */
/* dummy routine fuer alarm handling */
static void key_time (void)
{
longjmp (env, KEY_TIMEOUT);
}
#endif
/* -FF- */
static int auto_shift;
void set_auto_shift (int flag)
{
/* call from macro.c */
auto_shift = flag;
return;
} /* set_auto_shift */
/* -FF- */
void resize_screen (void)
{
clear_screen ();
#if (!WITH_HEX_VIEW)
perform_view ();
#else
if ((mode_flag < 3) || (act_window))
{
perform_view ();
}
if (mode_flag >= 3)
{
show_status_line_1 (get_line_1_text (), fc);
show_status_line_2 (mode_text [mode_flag], 0, -2, 0);
hex_refresh_disp ();
}
#endif
#if WITH_MOUSE
MouSetMoveArea ( 0 , (byte) TOP_ROW,
(byte) (COLUMNS-1), (byte) MAX_ROW,
0);
#endif
return;
} /* resize_screen */
void limit_windows (void)
{
int upper, total;
upper = w_bot[1]; /* keep old ratio of windows */
total = w_bot[0];
w_bot[0] = ROWS - 1;
w_bot[2] = w_bot[0];
/* w_bot[1] = min (w_bot[1], w_bot[0]); */
w_bot[1] = (w_bot[0] * upper + total/2) /* keep const. ratio */
/ max (1, total); /* avoid division by zero */
w_top[2] = w_bot[1] + 1;
return;
} /* limit_windows */
/* -FF- */
static void main_loop (void)
{
/*
/ Hauptschleife: Endlosschleife zur Tastatur-Eingabe und Aufruf von
/ switch_key_0 (in switches.c), von wo die notwendigen Aktionen
/ aufgerufen werden.
/ Steuerung der Funktionen 'Again' und 'Repeat' (repeat_count, repeat_max).
/
/ Bedeutung der Variablen "end_of_edit":
/ 0 : Normalfall
/ 1 : End of Edit (nach "Quit Exit" oder "Quit Abort")
/ -1 : Repeatschleife und alle Macro-Sequenzen werden abgebrochen,
/ wenn Operation erfolglos (z.B. nach "Find": not found)
/ -2 : Repeatschleife wird abgebrochen bei Funktionen, die keine sinn-
/ volle Repeat-Verwendung haben (z.B. "Quit", "Set", "Jump", usw...)
*/
static int key_0 = 0;
static int key_1 = 0;
static int last_key_0 = 0;
static int end_of_edit = 0;
static int macro_exit = 0;
static enum MACRO_STATUS old_macro_status;
static int new_special, old_special;
struct MACRO *macro_ex; /* for "Macro Execute" */
int again_flag, abort_loop, delta;
long repeat_count, repeat_max;
#define INFINITE 0x7fffffff
/* sleep_msec(1000); test behaviour of startup sequence (e.g. macro "INIT") */
#if 0
/* anzeige speicherinhalt */
view_or_update ();
perform_update (fc->buff_0, fc->byte_anz, fc->left_col);
show_status_line_1 (fc->filename, fc);
#endif
line_2_flag = 1;
/* nearly endless loop */
while (end_of_edit != 1)
{
if (auto_shift)
{
delta = 0;
if (REL_COLUMN > (COLUMNS-1))
delta = REL_COLUMN - (COLUMNS-1);
if (REL_COLUMN < 0)
delta = REL_COLUMN;
if (delta)
{
fc->left_col += delta;
update_entire_window (fc->top_left);
}
}
/* update display ? */
/* ggf. display status line 1 */
if (!key_pressed ())
{
perform_update (fc->buff_0, fc->byte_anz, fc->left_col);
#if (!SLOW_TERMINAL)
show_status_line_1 (get_line_1_text (), fc);
#endif
}
/* ggf. display status line 2 */
#if 0
if (old_macro_status != MACRO_EXECUTE)
#endif
{
if (save_d.toggle == 1)
{
line_2_flag = 2;
show_status_line_2 ("Buffer Delete Find -find Jump Put", 0, -2, 0);
}
else
{
if (line_2_flag == 1)
{
show_status_line_2 (mode_text [mode_flag], 0, -2, 0);
line_2_flag = 0;
}
if (line_2_flag > 1)
line_2_flag--; /* ggf. dekr. */
}
}
old_macro_status = get_macro_status ();
/* set cursor */
if (get_video_active (0))
set_cursor_to (fc->lrow, REL_COLUMN);
#if (!SLOW_TERMINAL)
/* get next command */
key_0 = get_1_key (1);
#else
signal (SIGALRM, key_time); /* set signal handling */
alarm (OUT_TIME); /* set timeout: LSB 1 sec !! */
jmpret = setjmp (env);
/* get next command */
if (jmpret == 0)
key_0 = get_1_key (1);
else
key_0 = jmpret;
alarm (0); /* reset timeout */
if (key_0 == KEY_TIMEOUT)
{
show_status_line_1 (get_line_1_text (), fc);
set_cursor_to (fc->lrow, REL_COLUMN);
key_0 = get_1_key (1);
}
#endif
/* wiederholfaktor zusammensetzen */
repeat_max = 1; /* default */
if (mode_flag == 0)
{
if (key_0 == '/')
{
repeat_max = INFINITE;
line_2_flag = 1;
show_status_line_2 ("Repeat forever :", 0, -1, 0);
key_0 = get_1_key (1);
}
else
{
if ((key_0 >= '0') && (key_0 <= '9'))
{
repeat_max = key_0 - '0';
line_2_flag = 1;
repeat_max = get_line_2_repeat ("Repeat n times :",
repeat_max, &key_0);
}
}
}
/* ggf. cursor-position korrigieren */
old_special = new_special;
new_special = ((key_0 == KEY_UP) ||
(key_0 == KEY_DOWN) ||
(key_0 == KEY_HOME) ||
(key_0 == KEY_PGUP) ||
(key_0 == KEY_PGDN) ||
(key_0 == KEY_TIMEOUT));
if (((!new_special) && (old_special)) ||
(mouse_moved))
check_dirty_cursor ();
mouse_moved = 0;
/* Again ? */
if ((mode_flag == 0) && (toupper(key_0) == 'A'))
{
key_0 = last_key_0;
again_flag = 1;
}
else
{
again_flag = 0;
}
/* aufrufen */
for (repeat_count = 0 ;
repeat_count < max (1L, repeat_max) ;
repeat_count++)
{
end_of_edit = switch_key_0 (key_0, max (repeat_count, again_flag),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -