mirror of
https://github.com/MidnightCommander/mc
synced 2025-02-25 19:54:13 +03:00
Editor: reduce scope of some functions.
The edit_insert_column_of_text() function is used only in src/editor/editcmd.c file. Now it is static. Removed unneeded forward declarations. Moved static functions to static area in src/editor/editcmd.c Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
4b0032de28
commit
07612ac7b7
@ -262,8 +262,6 @@ int edit_save_block (WEdit * edit, const char *filename, long start, long finish
|
||||
int edit_save_block_cmd (WEdit * edit);
|
||||
int edit_insert_file_cmd (WEdit * edit);
|
||||
void edit_insert_over (WEdit * edit);
|
||||
void edit_insert_column_of_text (WEdit * edit, unsigned char *data, int size, int width,
|
||||
long *start_pos, long *end_pos, int *col1, int *col2);
|
||||
int edit_insert_column_of_text_from_file (WEdit * edit, int file,
|
||||
long *start_pos, long *end_pos, int *col1, int *col2);
|
||||
long edit_insert_file (WEdit * edit, const char *filename);
|
||||
|
@ -79,9 +79,6 @@ int search_create_bookmark = FALSE;
|
||||
/* queries on a save */
|
||||
int edit_confirm_save = 1;
|
||||
|
||||
static int edit_save_cmd (WEdit * edit);
|
||||
static unsigned char *edit_get_block (WEdit * edit, long start, long finish, int *l);
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#define space_width 1
|
||||
@ -1138,6 +1135,152 @@ edit_collect_completions (WEdit * edit, long start, gsize word_len,
|
||||
return max_len;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
edit_insert_column_of_text (WEdit * edit, unsigned char *data, int size, int width,
|
||||
long *start_pos, long *end_pos, int *col1, int *col2)
|
||||
{
|
||||
long cursor;
|
||||
int i, col;
|
||||
|
||||
cursor = edit->curs1;
|
||||
col = edit_get_col (edit);
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
if (data[i] != '\n')
|
||||
edit_insert (edit, data[i]);
|
||||
else
|
||||
{ /* fill in and move to next line */
|
||||
int l;
|
||||
long p;
|
||||
|
||||
if (edit_get_byte (edit, edit->curs1) != '\n')
|
||||
{
|
||||
l = width - (edit_get_col (edit) - col);
|
||||
while (l > 0)
|
||||
{
|
||||
edit_insert (edit, ' ');
|
||||
l -= space_width;
|
||||
}
|
||||
}
|
||||
for (p = edit->curs1;; p++)
|
||||
{
|
||||
if (p == edit->last_byte)
|
||||
{
|
||||
edit_cursor_move (edit, edit->last_byte - edit->curs1);
|
||||
edit_insert_ahead (edit, '\n');
|
||||
p++;
|
||||
break;
|
||||
}
|
||||
if (edit_get_byte (edit, p) == '\n')
|
||||
{
|
||||
p++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
edit_cursor_move (edit, edit_move_forward3 (edit, p, col, 0) - edit->curs1);
|
||||
l = col - edit_get_col (edit);
|
||||
while (l >= space_width)
|
||||
{
|
||||
edit_insert (edit, ' ');
|
||||
l -= space_width;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*col1 = col;
|
||||
*col2 = col + width;
|
||||
*start_pos = cursor;
|
||||
*end_pos = edit->curs1;
|
||||
edit_cursor_move (edit, cursor - edit->curs1);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
edit_macro_comparator (gconstpointer * macro1, gconstpointer * macro2)
|
||||
{
|
||||
const macros_t *m1 = (const macros_t *) macro1;
|
||||
const macros_t *m2 = (const macros_t *) macro2;
|
||||
|
||||
return m1->hotkey - m2->hotkey;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
edit_macro_sort_by_hotkey (void)
|
||||
{
|
||||
if (macros_list != NULL && macros_list->len != 0)
|
||||
g_array_sort (macros_list, (GCompareFunc) edit_macro_comparator);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static gboolean
|
||||
edit_get_macro (WEdit * edit, int hotkey, const macros_t ** macros, guint * indx)
|
||||
{
|
||||
const macros_t *array_start = &g_array_index (macros_list, struct macros_t, 0);
|
||||
macros_t *result;
|
||||
macros_t search_macro;
|
||||
|
||||
(void) edit;
|
||||
|
||||
search_macro.hotkey = hotkey;
|
||||
result = bsearch (&search_macro, macros_list->data, macros_list->len,
|
||||
sizeof (macros_t), (GCompareFunc) edit_macro_comparator);
|
||||
|
||||
if (result != NULL && result->macro != NULL)
|
||||
{
|
||||
*indx = (result - array_start);
|
||||
*macros = result;
|
||||
return TRUE;
|
||||
}
|
||||
*indx = 0;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** returns FALSE on error */
|
||||
|
||||
static gboolean
|
||||
edit_delete_macro (WEdit * edit, int hotkey)
|
||||
{
|
||||
mc_config_t *macros_config = NULL;
|
||||
const char *section_name = "editor";
|
||||
gchar *macros_fname;
|
||||
guint indx;
|
||||
char *keyname;
|
||||
const macros_t *macros = NULL;
|
||||
|
||||
/* clear array of actions for current hotkey */
|
||||
while (edit_get_macro (edit, hotkey, ¯os, &indx))
|
||||
{
|
||||
if (macros->macro != NULL)
|
||||
g_array_free (macros->macro, TRUE);
|
||||
macros = NULL;
|
||||
g_array_remove_index (macros_list, indx);
|
||||
edit_macro_sort_by_hotkey ();
|
||||
}
|
||||
|
||||
macros_fname = g_build_filename (mc_config_get_data_path (), MC_MACRO_FILE, (char *) NULL);
|
||||
macros_config = mc_config_init (macros_fname);
|
||||
g_free (macros_fname);
|
||||
|
||||
if (macros_config == NULL)
|
||||
return FALSE;
|
||||
|
||||
keyname = lookup_key_by_code (hotkey);
|
||||
while (mc_config_del_key (macros_config, section_name, keyname))
|
||||
;
|
||||
g_free (keyname);
|
||||
mc_config_save_file (macros_config, NULL);
|
||||
mc_config_deinit (macros_config);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
@ -1379,91 +1522,6 @@ edit_save_as_cmd (WEdit * edit)
|
||||
}
|
||||
|
||||
/* {{{ Macro stuff starts here */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
edit_macro_comparator (gconstpointer * macro1, gconstpointer * macro2)
|
||||
{
|
||||
const macros_t *m1 = (const macros_t *) macro1;
|
||||
const macros_t *m2 = (const macros_t *) macro2;
|
||||
|
||||
return m1->hotkey - m2->hotkey;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
edit_macro_sort_by_hotkey (void)
|
||||
{
|
||||
if (macros_list != NULL && macros_list->len != 0)
|
||||
g_array_sort (macros_list, (GCompareFunc) edit_macro_comparator);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static gboolean
|
||||
edit_get_macro (WEdit * edit, int hotkey, const macros_t ** macros, guint * indx)
|
||||
{
|
||||
const macros_t *array_start = &g_array_index (macros_list, struct macros_t, 0);
|
||||
macros_t *result;
|
||||
macros_t search_macro;
|
||||
|
||||
(void) edit;
|
||||
|
||||
search_macro.hotkey = hotkey;
|
||||
result = bsearch (&search_macro, macros_list->data, macros_list->len,
|
||||
sizeof (macros_t), (GCompareFunc) edit_macro_comparator);
|
||||
|
||||
if (result != NULL && result->macro != NULL)
|
||||
{
|
||||
*indx = (result - array_start);
|
||||
*macros = result;
|
||||
return TRUE;
|
||||
}
|
||||
*indx = 0;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** returns FALSE on error */
|
||||
|
||||
static gboolean
|
||||
edit_delete_macro (WEdit * edit, int hotkey)
|
||||
{
|
||||
mc_config_t *macros_config = NULL;
|
||||
const char *section_name = "editor";
|
||||
gchar *macros_fname;
|
||||
guint indx;
|
||||
char *keyname;
|
||||
const macros_t *macros = NULL;
|
||||
|
||||
/* clear array of actions for current hotkey */
|
||||
while (edit_get_macro (edit, hotkey, ¯os, &indx))
|
||||
{
|
||||
if (macros->macro != NULL)
|
||||
g_array_free (macros->macro, TRUE);
|
||||
macros = NULL;
|
||||
g_array_remove_index (macros_list, indx);
|
||||
edit_macro_sort_by_hotkey ();
|
||||
}
|
||||
|
||||
macros_fname = g_build_filename (mc_config_get_data_path (), MC_MACRO_FILE, (char *) NULL);
|
||||
macros_config = mc_config_init (macros_fname);
|
||||
g_free (macros_fname);
|
||||
|
||||
if (macros_config == NULL)
|
||||
return FALSE;
|
||||
|
||||
keyname = lookup_key_by_code (hotkey);
|
||||
while (mc_config_del_key (macros_config, section_name, keyname))
|
||||
;
|
||||
g_free (keyname);
|
||||
mc_config_save_file (macros_config, NULL);
|
||||
mc_config_deinit (macros_config);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
@ -1902,65 +1960,6 @@ edit_insert_over (WEdit * edit)
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
edit_insert_column_of_text (WEdit * edit, unsigned char *data, int size, int width,
|
||||
long *start_pos, long *end_pos, int *col1, int *col2)
|
||||
{
|
||||
long cursor;
|
||||
int i, col;
|
||||
|
||||
cursor = edit->curs1;
|
||||
col = edit_get_col (edit);
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
if (data[i] == '\n')
|
||||
{ /* fill in and move to next line */
|
||||
int l;
|
||||
long p;
|
||||
if (edit_get_byte (edit, edit->curs1) != '\n')
|
||||
{
|
||||
l = width - (edit_get_col (edit) - col);
|
||||
while (l > 0)
|
||||
{
|
||||
edit_insert (edit, ' ');
|
||||
l -= space_width;
|
||||
}
|
||||
}
|
||||
for (p = edit->curs1;; p++)
|
||||
{
|
||||
if (p == edit->last_byte)
|
||||
{
|
||||
edit_cursor_move (edit, edit->last_byte - edit->curs1);
|
||||
edit_insert_ahead (edit, '\n');
|
||||
p++;
|
||||
break;
|
||||
}
|
||||
if (edit_get_byte (edit, p) == '\n')
|
||||
{
|
||||
p++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
edit_cursor_move (edit, edit_move_forward3 (edit, p, col, 0) - edit->curs1);
|
||||
l = col - edit_get_col (edit);
|
||||
while (l >= space_width)
|
||||
{
|
||||
edit_insert (edit, ' ');
|
||||
l -= space_width;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
edit_insert (edit, data[i]);
|
||||
}
|
||||
*col1 = col;
|
||||
*col2 = col + width;
|
||||
*start_pos = cursor;
|
||||
*end_pos = edit->curs1;
|
||||
edit_cursor_move (edit, cursor - edit->curs1);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
edit_insert_column_of_text_from_file (WEdit * edit, int file,
|
||||
long *start_pos, long *end_pos, int *col1, int *col2)
|
||||
|
Loading…
x
Reference in New Issue
Block a user