macro.c
来自「功能强大的文本编辑器」· C语言 代码 · 共 2,088 行 · 第 1/5 页
C
2,088 行
else
{
macro_stack[stack_index].cntexe++;
}
}
if ((macro_stack[stack_index].repeat <= 0) || (dekr_repeat == 0))
{
stack_index--;
}
return macro_stack[stack_index].repeat; /* o.k. */
}
else
{
return -1; /* error */
}
} /* pop_macro_stack */
/* -FF- */
enum MACRO_STATUS get_macro_status (void)
{
return macro_stack[stack_index].status;
} /* get_macro_status */
int get_macro_nesting_level (void)
{
return stack_index;
} /* get_macro_nesting_level */
int get_save_mode_flag (void)
{
return macro_stack[stack_index + 1].save_mode_flag;
} /* get_macro_nesting_level */
long get_macro_cntexe (void)
{
return macro_stack [1].cntexe;
}
long get_macro_cntmac (void)
{
return macro_stack [1].cntmac;
}
/* -FF- */
int get_macro_key (void)
{
int key;
struct MACRO *macro;
static int start_flag, end_flag;
macro = macro_stack[stack_index].macro;
/* first key in modeless macro ? */
if ((macro->i_ptr == macro->sequence) &&
(macro->mode == 0))
{
if (start_flag == 0)
{
start_flag = 1;
return 0x1b; /* always perform additional <esc> as 1st key */
}
else
{
start_flag = 0;
}
}
/* now get macro key */
key = *macro->i_ptr; /* get key */
macro->i_ptr++;
if (key == SEQU_EM) /* end of non-modeless macro ? */
{
pop_macro_stack (macro, 1);
return SEQU_EM;
}
if (key == SEQU_MM) /* end of modeless macro ? */
{
if (end_flag == 0)
{
end_flag = 1;
macro->i_ptr--; /* get same code again */
return 0x1b; /* last command of each macro is <esc> */
}
else
{
end_flag = 0;
pop_macro_stack (macro, 1);
return SEQU_MM;
}
}
/* sonst */
return key;
} /* get_macro_key */
/* -FF- */
int put_macro_key (int key)
{
struct MACRO *macro;
macro = macro_stack[stack_index].macro;
*macro->i_ptr = key; /* put key */
macro->i_ptr++;
macro->length += sizeof (int);
if (macro->length >= (MACRO_SIZE-sizeof(int))) /* reached max. size ? */
{ /* force end of macro */
*macro->i_ptr = SEQU_MM; /* write new end of sequence */
macro->i_ptr++;
macro->length += sizeof (int); /* @@ */
macro = chain_macro (macro, 0);
pop_macro_stack (macro, 0);
return -1; /* abort */
}
else
{
return 0; /* o.k. */
}
} /* put_macro_key */
/* -FF- */
int delete_last_macro_key (void)
{
struct MACRO *macro;
int err_flag;
macro = macro_stack[stack_index].macro;
macro->i_ptr--;
/* macro->length -= sizeof (int); @@ */
err_flag = - (toupper(*macro->i_ptr) != 'M'); /* 0 = o.k. */
/* -1 = error */
*macro->i_ptr = SEQU_MM; /* write new end of sequence */
macro->i_ptr++;
/* macro->length += sizeof (int); @@ */
return err_flag;
} /* delete_last_macro_key */
/* -FF- */
int save_macro (char *macro_name)
{
struct MACRO *macro;
macro = get_macro_adress (macro_name);
if (macro == NULL)
{
return -1; /* error */
}
else
/* save macro in aedit format : */
/* "M<macro name>\BR<translated sequence>\MM" */
{
set_cursor_to (fc->lrow, REL_COLUMN);
/* macro name */
perform_key_insert ('M', 0); /* 'M' */
perform_string_insert (macro->name);
perform_string_insert ("\\BR");
/* translated sequence */
macro->i_ptr = macro->sequence;
while ((*macro->i_ptr != SEQU_MM) &&
(*macro->i_ptr != SEQU_EM))
{
perform_string_insert
(key_2_string (*macro->i_ptr));
macro->i_ptr++;
/* ggf. insert <cr> */
if (fc->column > (COLUMNS-5))
perform_insert_eol (); /* <cr> */
}
/* end of macro */
perform_string_insert
(key_2_string (*macro->i_ptr));
perform_key_insert (';', 0);
perform_insert_eol ();
return 0; /* o.k. */
}
} /* save_macro */
/* -FF- */
int insert_macro (void)
{
int change_flag, key_2;
show_status_line_2 ("Abort with ^C", 0, -2, 0);
set_cursor_to (fc->lrow, REL_COLUMN);
change_flag = 0;
while ((key_2 = get_1_key (0)) != 0x03)
{
change_flag = 1;
/* insert key or \-sequence */
if (key_2 == C_R)
perform_insert_eol ();
else
perform_string_insert (key_2_string (key_2));
/* ggf. insert <cr> */
if (fc->column > (COLUMNS-5))
{
update_rest_of_window (fc->lin_left, fc->lrow);
perform_insert_eol (); /* <cr> */
}
else
{
update_this_line (fc->lin_left, fc->lrow);
}
/* display */
if (fc->lrow >= MAX_ROW)
perform_view ();
else
perform_update (fc->buff_0, fc->byte_anz,
fc->left_col);
fc->change_flag = 1;
show_status_line_1 (get_line_1_text (), fc);
set_cursor_to (fc->lrow, REL_COLUMN);
}
return change_flag;
} /* insert_macro */
/* -FF- */
int list_macros (void)
{
int mac_num, ii, tab_diff;
int mf_ind, mf_min, mf_max, mf_act;
int row, line_len, end_index;
struct MACRO *act_buf;
long mac_size;
char line [81];
mac_num = 0;
mac_size = 0;
line_len = 0;
act_buf = top_of_macros;
/* 1. exec pathname */
printf ("\015\012");
printf ("exec path mbedit : \"%s\"\015\012", get_exe_path());
row = 2;
/* 2. syntax file pathname */
row += show_syntax_file();
if (row >= (w_bot[0] - STATUS_LINES - 2))
{
printf ("\015\012 hit any key to continue ... ");
get_1_key (0);
clear_screen ();
printf ("\015\012");
row = 1;
}
/* 3. macro file(s) pathname(s) */
printf ("\015\012");
printf ("loaded macro file(s):\015\012");
printf (" ind lev: pathname \015\012");
row += 3;
if (mac_count < 0)
{
printf (" <none> \015\012");
row++;
}
else
{
if (mac_count < MACRO_FILE_NO)
{
mf_min = 0;
mf_max = mac_count;
}
else
{
mf_min = mac_count - (MACRO_FILE_NO - 1);
mf_max = mac_count;
printf (" <incomplete list> \015\012");
row++;
}
for (mf_ind = mf_min ; mf_ind <= mf_max ; mf_ind++)
{
mf_act = mf_ind % MACRO_FILE_NO;
printf (" %2d (%d): \"%s\" \015\012",
mf_ind+1,
macro_level [mf_act],
macro_filename[mf_act]);
row++;
} /* for mm */
}
if (row >= (w_bot[0] - STATUS_LINES - 2))
{
printf ("\015\012 hit any key to continue ... ");
get_1_key (0);
clear_screen ();
printf ("\015\012");
row = 1;
}
/* 4. macro list */
printf ("\015\012");
printf ("list of macros [size in bytes]:\015\012");
row += 2;
/* loop for all macros */
while (act_buf != NULL)
{
/* prepare buffer */
sprintf (line, "%s [%d], ", act_buf->name, act_buf->length);
/* n blanks anhaengen anstatt <tab> (wg. mitzaehlen) */
end_index = strlen(line);
tab_diff = set.tabs - (end_index % set.tabs);
for (ii = end_index ; ii < (end_index + tab_diff) ; ii++)
{
line [ii ] = ' '; /* insert blank */
}
end_index += tab_diff;
line[end_index] = '\0'; /* new end of string */
/* new line ? */
if ((line_len + (int)strlen(line)) >= (COLUMNS-1))
{
printf ("\015\012");
row++;
line_len = 0; /* no of blanks in printf above */
/* ggf. pause */
if (row >= (w_bot[0] - STATUS_LINES - 2))
{
printf ("\015\012 hit any key to continue ... ");
get_1_key (0);
clear_screen ();
printf ("\015\012");
row = 1;
}
}
/* show macro name */
line_len += printf ("%s", line);
/* statistics */
mac_size += act_buf->length;
mac_num++;
/* next macro */
act_buf = act_buf->next_macro;
}
/* unterschrift */
printf ("\015\012\n Total Number of Macros = %d", mac_num);
printf ("\015\012 Total Size of Macros = %ld (Bytes dec.)\015\012", mac_size);
printf ("\015\012 hit any key to continue ... ");
get_1_key (0);
return mac_num;
} /* list_macros */
/* -FF- */
char *get_macro_filename (void)
{
return macro_filename[MAC_ACT_IND];
} /* get_macro_filename */
/* -FF- */
#if (WITH_E_DELIMIT)
#if (QSORT_FUNC_ANSI)
static int comp_chars (const void *ch1, const void *ch2)
#else
static int comp_chars (ch1, ch2)
const void *ch1;
const void *ch2;
#endif
{
return ((* (char *) ch1) -
(* (char *) ch2));
} /* comp_chars */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?