📄 mbedit.c
字号:
repeat_max);
/* total abort of editing ? */
if (end_of_edit == 1)
{
/* is macro "EXIT" already executed ? */
if (macro_exit)
{
return; /* yes ! don't do it again */
}
/* no ! check for macro "EXIT" */
macro_ex = get_macro_adress ("EXIT");
if (macro_ex != NULL)
{
push_macro_stack (macro_ex, MACRO_EXECUTE, 1L, mode_flag);
macro_exit = 1;
end_of_edit = -2;
}
else
{
return; /* normal exit of function */
}
}
/* end of macro "EXIT" ? */
if ((macro_exit) && (get_macro_nesting_level () == 0))
{
return;
}
/* check, if abort for loop */
abort_loop = 0; /* default */
if (end_of_edit < 0) /* last command not successfull */
abort_loop = 1;
if (ctrlc_active()) /* was ^C entered ? (ms/dos) */
{
abort_loop = 1;
reset_macro_stack ();
}
if (loc_key_pressed()) /* or user break ? */
{ /* with <esc> ? */
key_1 = loc_get_1_key(); /* from keyboard, not from macro */
if ((key_1 == 0x1b) || /* <esc> */
(key_1 == 0x03) || /* ^C (os/9, unix) */
(key_1 == EOF)) /* end of file */
{
abort_loop = 1;
}
/* else comment around "else" NEW !! 09.03.95 */
/* Put back key in any case ! */
/* <esc> in keyboard buffer is used for end of Find-String */
{
set_key_fifo (key_1); /* back to input buffer !! */
}
}
if (abort_loop)
{
if ((get_macro_status () == MACRO_EXECUTE) &&
(end_of_edit != -2)) /* Setup "Macro Execute" */
{
if (repeat_max != INFINITE)
stop_this_macro ();
}
break; /* leave for loop */
}
} /* for repeat_count */
/* fuer naechsten durchgang merken */
if (key_0 != KEY_TIMEOUT)
last_key_0 = key_0;
#if ((WITH_WINCH) && (ACT_OP_SYSTEM == WIN_32))
if (set_window_size ())
{
perform_view ();
}
#endif
} /* while end_of_edit */
return; /* hier kommt er nie hin ! */
} /* main_loop */
/* -FF- */
#if (WITH_WINCH == 2)
static int num_from_stream (FILE *fd, char *search_string, int *number)
{
int c1, result;
char *search;
search = search_string; /* set to begin of search string */
result = 0;
while ((c1 = fgetc (fd)) != EOF) /* read 1 char */
{
if (c1 == *search) /* does it match ? */
{ /* yes ! */
search++; /* incr. pointer */
if (*search == '\0') /* reached end of string ? */
{
result = fscanf (fd, "%d", number); /* read number from stream */
while ((c1 = fgetc (fd)) != EOF) /* read stream until EOF */
{
; /* empty loop */
}
return (result);
}
}
else
{ /* no ! */
search = search_string; /* set back to begin */
}
}
return result; /* nothing found */
} /* num_from_stream */
/* -FF- */
static int mb_tput (char *arg_str, int *number)
{
/* calculate the number of lines and columns of active window */
static int value, fall, ii, result;
static FILE *fd;
#define STR_NUM 2
struct WINDOW {
char *arg; /* command line argument */
char *str [STR_NUM]; /* search strings */
};
static struct WINDOW window [] = {"lines", "li#", "LINES=",
"cols" , "co#", "COLUMNS="};
#if (DOS_TEST)
#define FILENAME "tmp"
#define COMMAND_STRING "echo abcde:LINES=20:dhdhgfgf:co#80:dndnsdmn > tmp"
#else
#define TEST 0
#if TEST
#define COMMAND_STRING "cat /tmp/out"
#else
/* #define COMMAND_STRING "resize -u > /tmp/out; cat /tmp/out" */
#define COMMAND_STRING "resize -u"
#endif
#endif
/* default */
fall = -1; /* not defined */
/* which value is required ? */
for (ii = 0 ; ii < lengthof (window) ; ii++)
{
if (strcmp (arg_str, window[ii].arg) == 0)
{
fall = ii;
break;
}
}
/* fallunterscheidung */
if (fall != -1)
{
for (ii = 0 ; ii < STR_NUM ; ii++)
{
#if (DOS_TEST)
system (COMMAND_STRING);
fd = fopen (FILENAME, "r");
#else
fd = popen (COMMAND_STRING, "r");
#endif
if (fd)
{
result = num_from_stream (fd, window[fall].str[ii], &value);
pclose (fd);
if (result == 1)
{
*number = value;
break;
}
}
}
}
return (result);
} /* mb_tput */
#endif
/* -FF- */
#if (WITH_WINCH)
void cmd_winch (int sig_num)
{
#if (TEST_PRINT)
printf ("\n>>> cmd_winch: sig_num = %d \n", sig_num);
#endif
#if 0
#if (UNIX)
if ((signal(sig_num, SIG_IGN)) == SIG_ERR) /* ignore now */
syserr("signal sig_num, cmd_winch");
#endif
#endif
/* Now we have to set the number of lines and cols new ! */
set_window_size ();
resize_screen ();
#if (UNIX)
if ((signal(sig_num, cmd_winch)) == SIG_ERR) /* set it again */
syserr("signal sig_num, cmd_winch");
#endif
return;
} /* cmd_winch */
int set_window_size (void)
{
int new_lines, new_cols, change_flag = 0;
FILE *fd;
#define PATH_0 fileno(stdin) /* standard input */
fd; /* wg. compiler warning */
#if (TEST_PRINT)
printf ("\n>>> set_window_size: ROWS = %d, COLUMNS = %d \n",
ROWS, COLUMNS);
#endif
/* default values */
new_lines = ROWS;
new_cols = COLUMNS;
/* get the new number of lines and columns, using different methods */
/* cooked mode, signal OFF */
kb_echo_on ();
#if (WITH_WINCH == 1) /* use "tput" */
fd = popen ("tput lines", "r");
if (fd)
{
fscanf (fd, "%d", &new_lines);
pclose (fd);
}
fd = popen ("tput cols", "r");
if (fd)
{
fscanf (fd, "%d", &new_cols);
pclose (fd);
}
#endif /* 1 */
#if (WITH_WINCH == 2) /* use "mb_tput" */
mb_tput ("lines", &new_lines);
mb_tput ("cols" , &new_cols );
#endif /* 2 */
#if (WITH_WINCH == 3) /* use "ioctl" */
#ifdef TIOCGWINSZ
{
struct winsize win_size;
if( ioctl( fileno(stdin), TIOCGWINSZ, &win_size ) != -1 )
{
if ((win_size.ws_row != 0) &&
(win_size.ws_col != 0))
{
new_lines = (int)win_size.ws_row; /* Rows, in characters */
new_cols = (int)win_size.ws_col; /* Columns, in characters */
#if 0
win_size.ws_xpixel; /* Horizontal size, in pixels */
win_size.ws_ypixel; /* Vertical size, in pixels */
#endif
}
}
else
{
new_lines = INIT_ROWS; /* error: */
new_cols = INIT_COLUMNS; /* default values */
}
}
#endif
#endif /* 3 */
#if (WITH_WINCH == 4)
{
static char X11_tput [] = "eval `resize -u`;tput lines;tput cols";
static char Unix_tput [] = "tput lines;tput cols";
char * tput_cmd = getenv ("DISPLAY") ? X11_tput : Unix_tput;
fd = popen (tput_cmd, "r");
if (fd)
{
fscanf (fd, "%d", &new_lines);
fscanf (fd, "%d", &new_cols);
pclose (fd);
}
}
#endif /* 4 */
#if (WITH_WINCH == 5)
vb_getvsize (&new_cols, &new_lines);
#endif /* 5 */
#if (WITH_WINCH == 6)
{
#if (ACT_OP_SYSTEM == OS_9)
#ifndef fileno
#define fileno(p) ((p)->_fd)
#endif
#endif
#define CODE 0
static struct _sgs sgs; /* buffer for window control */
getstat (CODE, PATH_0, &sgs);
new_lines = sgs._sgs_page;
}
#endif /* 6 */
#if (WITH_WINCH == 7)
{
static char WIN32_tput [] = "mode con";
fd = _popen (WIN32_tput, "r");
if (fd)
{
static char parse[255];
while (fgets(parse, sizeof(parse), fd))
{
sscanf(parse, "Columns=%d", &new_cols);
sscanf(parse, "Spalten:%d", &new_cols);
sscanf(parse, "Spalten (COLS)=%d", &new_cols);
sscanf(parse, "Lines=%d", &new_lines);
sscanf(parse, "Zeilen:%d", &new_lines);
sscanf(parse, "Zeilen (LINES)=%d", &new_lines);
}
_pclose (fd);
}
}
#endif /* 7 */
#if (WITH_WINCH == 8)
{
get_screen_lin_col(&new_lines, &new_cols);
}
#endif /* 8 */
#if (WITH_WINCH == 9) /* QNX6 */
{
int t_lines, t_cols;
if (tcgetsize( PATH_0, &t_lines, &t_cols) == 0)
{
new_lines = t_lines; /* take over rows */
new_cols = t_cols; /* take over columns */
}
}
#endif /* 9 */
/* raw mode, signal ON */
kb_echo_off ();
#if (TEST_PRINT)
printf ("\n>>> set_window_size: new_lines = %d, new_cols = %d \n",
new_lines, new_cols);
#endif
/* limit new values */
new_lines = max (new_lines, STATUS_LINES + 1);
new_lines = min (new_lines, LIMIT_ROWS);
new_cols = max (new_cols, 1);
new_cols = min (new_cols, LIMIT_COLUMNS);
/* settings changed ? */
if ((COLUMNS != new_cols) ||
(ROWS != new_lines))
{
change_flag = 1;
}
/* take over */
COLUMNS = new_cols;
ROWS = new_lines;
limit_windows ();
return change_flag;
} /* set_window_size */
#endif
/* -FF- */
/* Modification History */
/* 20.11.92 - file erzeugt */
/* 23.11.92 - CR_CRLF */
/* 24.11.92 - init_mon_outp */
/* 25.11.92 - perform_key_... () */
/* 26.11.92 - get_total_lines () */
/* 27.11.92 - insert/exchange-mode */
/* 28.11.92 - display-ansteuerung speed-optimiert */
/* 29.11.92 - view command */
/* 30.11.92 - get_line_2_string () */
/* 01.12.92 - macro ' ' */
/* 02.12.92 - Find, Replace */
/* 04.12.92 - err_message () */
/* 05.12.92 - Again */
/* 06.12.92 - mbedit.c war ueber 2000 zeilen lang, */
/* 20.12.92 - loc_malloc other_fc erst bei command 'Other' (in switches.c) */
/* 21.12.92 - mbedit ohne <filename> */
/* 02.01.93 - show_status_line_2 ("Macro Create: End with 'M'", -2); */
/* 03.01.93 - Abort Macro Execution, if not successfull (e.g. at EOF) */
/* 05.01.93 - search_macro_file () */
/* 18.06.93 - execute macro "INIT" */
/* 21.07.93 - push_macro_stack (..., 1L, ...); (vorher 1) */
/* 27.07.93 - get_next_file_buffer (int direction) */
/* 28.07.93 - EOL --> EOLN */
/* 09.09.93 - init_file_control: fcl->find [0...1] = -1 */
/* 12.09.93 - DEMO_VERSION */
/* 12.09.93 - show_status_line_2 (..., ignore_batch) */
/* 14.09.93 - stop_this_macro(), only if not INFINTE */
/* 14.09.93 - display status line 2 only if ! MACRO_EXECUTE */
/* 14.09.93 - read given macro file or default (or none), but not both ! */
/* 15.09.93 - help invocation */
/* 29.09.93 - update_rest_of_window(), ...entire_window() */
/* 02.10.93 - init_file_control (..., int clear_flag) */
/* 18.10.93 - aufruf-bedingung von check_dirty_cursor() */
/* 04.11.93 - TEST_EOLN entfaellt */
/* 04.11.93 - wildcard_filename */
/* 06.11.93 - wildcard_filename --> disp_hnd.c */
/* 26.11.93 - bugfix: segmentation violation */
/* 29.11.93 - mb_ctype.h */
/* 06.12.93 - GRAFIK_OFF --> mon_outp.c */
/* 07.12.93 - ctrlchandler (int sig) */
/* 08.12.93 - ctrlchandler auch bei os/9 */
/* 08.12.93 - WITH_MOUSE */
/* 09.12.93 - mouse_moved */
/* 09.12.93 - mouse_driver_ok */
/* 13.12.93 - set_mouse_status () */
/* 07.01.94 - auto_shift, set_auto_shift () */
/* 12.05.94 - MACRO_TUNING */
/* 20.05.94 - mbedit # | last_again */
/* 21.05.94 - write_status_file(), read_status_file() */
/* 24.05.94 - bugfix */
/* 03.06.94 - WITH_WINCH, cmd_winch () */
/* 04.06.94 - set_window_size (): check, if values changed */
/* 06.06.94 - end of program: SIGALRM + SIGWINCH --> SIG_DFL */
/* 06.06.94 - end of program: reset_macro_stack () */
/* 07.06.94 - end of program: reset_macro_stack () ueberfluessig */
/* 07.06.94 - WITH_WINCH = 1, 2, 3 for different unix systems */
/* 08.06.94 - num_from_stream () */
/* 08.06.94 - resize_screen () after read_macro_file () */
/* 09.06.94 - TEST_PRINT */
/* 14.06.94 - resize_screen: nicht bei batch mode */
/* 21.07.94 - set_window_size() mit ioctl */
/* 31.08.94 - mbedit.c: take over new_lines + new_cols only, if != 0 */
/* 26.09.94 - hex_refresh_disp() */
/* 30.09.94 - WITH_WINCH 4 for SCO_UNIX */
/* 02.10.94 - get_1_datafile(): set fc->syntax_flag = f(filename extension) */
/* 05.10.94 - get_1_datafile(): set + reset fc->syntax_flag */
/* 07.10.94 - set_grafik_off (0); */
/* 22.01.95 - WITH_WINCH 5 for VGA */
/* 09.03.95 - mainloop(): put back <esc> key in any case */
/* 19.10.95 - set_window_size(): WITH_WINCH 6 (OS_9) */
/* 17.11.95 - syntax_global */
/* 23.01.96 - printf ("\015\012") anstatt printf ("\r\n") */
/* 05.09.98 - VAR_EOLN (var. end of line char.) */
/* 05.09.98 - get_var_eoln() */
/* 05.02.99 - get_1_datafile(): check R_OK, W_OK */
/* 19.02.99 - get_1_datafile(): check W_OK nicht bei os-9 */
/* 29.03.03 - get_1_datafile(): get_file_type() */
/* 17.04.03 - WITH_WINCH 7 (WIN_32) */
/* 11.02.04 - 'S'et 'H'ighbit 'A'uto */
/* 15.02.04 - QNX6: New ! */
/* 13.03.04 - disp_hnd.c: modifications for CSS (dashes in keywords) */
/* 24.03.04 - init_file_control(): set fc->e_delimit only if clear_flag */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -