mceditor: massive use of edit_arg_t as function argument.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2024-02-23 13:07:34 +03:00
parent e79e76b72b
commit 258b52b2d1
8 changed files with 62 additions and 35 deletions

View File

@ -130,7 +130,7 @@ extern char *edit_window_close_char;
/*** declarations of public functions ************************************************************/ /*** declarations of public functions ************************************************************/
gboolean edit_add_window (WDialog * h, const WRect * r, const vfs_path_t * f, long fline); gboolean edit_add_window (WDialog * h, const WRect * r, const edit_arg_t * arg);
WEdit *edit_find_editor (const WDialog * h); WEdit *edit_find_editor (const WDialog * h);
gboolean edit_widget_is_editor (const Widget * w); gboolean edit_widget_is_editor (const Widget * w);
gboolean edit_drop_hotkey_menu (WDialog * h, int key); gboolean edit_drop_hotkey_menu (WDialog * h, int key);
@ -152,7 +152,7 @@ long edit_get_col (const WEdit * edit);
void edit_update_curs_row (WEdit * edit); void edit_update_curs_row (WEdit * edit);
void edit_update_curs_col (WEdit * edit); void edit_update_curs_col (WEdit * edit);
void edit_find_bracket (WEdit * edit); void edit_find_bracket (WEdit * edit);
gboolean edit_reload_line (WEdit * edit, const vfs_path_t * filename_vpath, long line); gboolean edit_reload_line (WEdit * edit, const edit_arg_t * arg);
void edit_set_codeset (WEdit * edit); void edit_set_codeset (WEdit * edit);
void edit_block_copy_cmd (WEdit * edit); void edit_block_copy_cmd (WEdit * edit);
@ -174,11 +174,11 @@ char *edit_get_write_filter (const vfs_path_t * write_name_vpath,
const vfs_path_t * filename_vpath); const vfs_path_t * filename_vpath);
gboolean edit_save_confirm_cmd (WEdit * edit); gboolean edit_save_confirm_cmd (WEdit * edit);
gboolean edit_save_as_cmd (WEdit * edit); gboolean edit_save_as_cmd (WEdit * edit);
WEdit *edit_init (WEdit * edit, const WRect * r, const vfs_path_t * filename_vpath, long line); WEdit *edit_init (WEdit * edit, const WRect * r, const edit_arg_t * arg);
gboolean edit_clean (WEdit * edit); gboolean edit_clean (WEdit * edit);
gboolean edit_ok_to_exit (WEdit * edit); gboolean edit_ok_to_exit (WEdit * edit);
gboolean edit_load_cmd (WDialog * h); gboolean edit_load_cmd (WDialog * h);
gboolean edit_load_file_from_filename (WDialog * h, const vfs_path_t * vpath, long line); gboolean edit_load_file_from_filename (WDialog * h, const edit_arg_t * arg);
gboolean edit_load_file_from_history (WDialog * h); gboolean edit_load_file_from_history (WDialog * h);
gboolean edit_load_syntax_file (WDialog * h); gboolean edit_load_syntax_file (WDialog * h);
gboolean edit_load_menu_file (WDialog * h); gboolean edit_load_menu_file (WDialog * h);
@ -266,7 +266,11 @@ int editcmd_dialog_raw_key_query (const char *heading, const char *query, gboole
static inline gboolean static inline gboolean
edit_reload (WEdit * edit, const vfs_path_t * filename_vpath) edit_reload (WEdit * edit, const vfs_path_t * filename_vpath)
{ {
return edit_reload_line (edit, filename_vpath, 0); edit_arg_t arg;
edit_arg_init (&arg, (vfs_path_t *) filename_vpath, 0);
return edit_reload_line (edit, &arg);
} }
#endif /* MC__EDIT_IMPL_H */ #endif /* MC__EDIT_IMPL_H */

View File

@ -2114,14 +2114,15 @@ edit_insert_file (WEdit * edit, const vfs_path_t * filename_vpath)
* Fill in the edit structure. Return NULL on failure. Pass edit as * Fill in the edit structure. Return NULL on failure. Pass edit as
* NULL to allocate a new structure. * NULL to allocate a new structure.
* *
* If line is 0, try to restore saved position. Otherwise put the * If arg is NULL or arg->line_number is 0, try to restore saved position. Otherwise put the
* cursor on that line and show it in the middle of the screen. * cursor on that line and show it in the middle of the screen.
*/ */
WEdit * WEdit *
edit_init (WEdit * edit, const WRect * r, const vfs_path_t * filename_vpath, long line) edit_init (WEdit * edit, const WRect * r, const edit_arg_t * arg)
{ {
gboolean to_free = FALSE; gboolean to_free = FALSE;
long line;
auto_syntax = TRUE; /* Resetting to auto on every invocation */ auto_syntax = TRUE; /* Resetting to auto on every invocation */
edit_options.line_state_width = edit_options.line_state ? LINE_STATE_WIDTH : 0; edit_options.line_state_width = edit_options.line_state ? LINE_STATE_WIDTH : 0;
@ -2164,7 +2165,7 @@ edit_init (WEdit * edit, const WRect * r, const vfs_path_t * filename_vpath, lon
edit->stat1.st_gid = getgid (); edit->stat1.st_gid = getgid ();
edit->stat1.st_mtime = 0; edit->stat1.st_mtime = 0;
edit->attrs_ok = (mc_fgetflags (filename_vpath, &edit->attrs) == 0); edit->attrs_ok = (mc_fgetflags (arg->file_vpath, &edit->attrs) == 0);
edit->over_col = 0; edit->over_col = 0;
edit->bracket = -1; edit->bracket = -1;
@ -2172,7 +2173,16 @@ edit_init (WEdit * edit, const WRect * r, const vfs_path_t * filename_vpath, lon
edit->force |= REDRAW_PAGE; edit->force |= REDRAW_PAGE;
/* set file name before load file */ /* set file name before load file */
edit_set_filename (edit, filename_vpath); if (arg != NULL)
{
edit_set_filename (edit, arg->file_vpath);
line = arg->line_number;
}
else
{
edit_set_filename (edit, NULL);
line = 0;
}
edit->undo_stack_size = START_STACK_SIZE; edit->undo_stack_size = START_STACK_SIZE;
edit->undo_stack_size_mask = START_STACK_SIZE - 1; edit->undo_stack_size_mask = START_STACK_SIZE - 1;
@ -2273,7 +2283,7 @@ edit_clean (WEdit * edit)
* @return TRUE on success, FALSE on failure. * @return TRUE on success, FALSE on failure.
*/ */
gboolean gboolean
edit_reload_line (WEdit * edit, const vfs_path_t * filename_vpath, long line) edit_reload_line (WEdit * edit, const edit_arg_t * arg)
{ {
Widget *w = WIDGET (edit); Widget *w = WIDGET (edit);
WEdit *e; WEdit *e;
@ -2284,7 +2294,7 @@ edit_reload_line (WEdit * edit, const vfs_path_t * filename_vpath, long line)
e->fullscreen = edit->fullscreen; e->fullscreen = edit->fullscreen;
e->loc_prev = edit->loc_prev; e->loc_prev = edit->loc_prev;
if (edit_init (e, &w->rect, filename_vpath, line) == NULL) if (edit_init (e, &w->rect, arg) == NULL)
{ {
g_free (e); g_free (e);
return FALSE; return FALSE;

View File

@ -78,7 +78,7 @@ extern edit_options_t edit_options;
void edit_stack_init (void); void edit_stack_init (void);
void edit_stack_free (void); void edit_stack_free (void);
gboolean edit_file (const vfs_path_t * file_vpath, long line); gboolean edit_file (const edit_arg_t * arg);
gboolean edit_files (const GList * files); gboolean edit_files (const GList * files);
edit_arg_t *edit_arg_vpath_new (vfs_path_t * file_vpath, long line_number); edit_arg_t *edit_arg_vpath_new (vfs_path_t * file_vpath, long line_number);

View File

@ -1058,9 +1058,11 @@ edit_load_cmd (WDialog * h)
if (exp != NULL && *exp != '\0') if (exp != NULL && *exp != '\0')
{ {
vfs_path_t *exp_vpath; vfs_path_t *exp_vpath;
edit_arg_t arg;
exp_vpath = vfs_path_from_str (exp); exp_vpath = vfs_path_from_str (exp);
ret = edit_load_file_from_filename (h, exp_vpath, 0); edit_arg_init (&arg, exp_vpath, 0);
ret = edit_load_file_from_filename (h, &arg);
vfs_path_free (exp_vpath, TRUE); vfs_path_free (exp_vpath, TRUE);
} }
@ -1081,13 +1083,13 @@ edit_load_cmd (WDialog * h)
*/ */
gboolean gboolean
edit_load_file_from_filename (WDialog * h, const vfs_path_t * vpath, long line) edit_load_file_from_filename (WDialog * h, const edit_arg_t * arg)
{ {
WRect r = WIDGET (h)->rect; WRect r = WIDGET (h)->rect;
rect_grow (&r, -1, 0); rect_grow (&r, -1, 0);
return edit_add_window (h, &r, vpath, line); return edit_add_window (h, &r, arg);
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -1108,9 +1110,11 @@ edit_load_file_from_history (WDialog * h)
if (exp != NULL && (action == CK_Edit || action == CK_Enter)) if (exp != NULL && (action == CK_Edit || action == CK_Enter))
{ {
vfs_path_t *exp_vpath; vfs_path_t *exp_vpath;
edit_arg_t arg;
exp_vpath = vfs_path_from_str (exp); exp_vpath = vfs_path_from_str (exp);
ret = edit_load_file_from_filename (h, exp_vpath, 0); edit_arg_init (&arg, exp_vpath, 0);
ret = edit_load_file_from_filename (h, &arg);
vfs_path_free (exp_vpath, TRUE); vfs_path_free (exp_vpath, TRUE);
} }
@ -1131,6 +1135,7 @@ edit_load_syntax_file (WDialog * h)
{ {
vfs_path_t *extdir_vpath; vfs_path_t *extdir_vpath;
int dir = 0; int dir = 0;
edit_arg_t arg;
gboolean ret = FALSE; gboolean ret = FALSE;
if (geteuid () == 0) if (geteuid () == 0)
@ -1153,11 +1158,15 @@ edit_load_syntax_file (WDialog * h)
user_syntax_file_vpath = mc_config_get_full_vpath (EDIT_SYNTAX_FILE); user_syntax_file_vpath = mc_config_get_full_vpath (EDIT_SYNTAX_FILE);
check_for_default (extdir_vpath, user_syntax_file_vpath); check_for_default (extdir_vpath, user_syntax_file_vpath);
ret = edit_load_file_from_filename (h, user_syntax_file_vpath, 0); edit_arg_init (&arg, user_syntax_file_vpath, 0);
ret = edit_load_file_from_filename (h, &arg);
vfs_path_free (user_syntax_file_vpath, TRUE); vfs_path_free (user_syntax_file_vpath, TRUE);
} }
else if (dir == 1) else if (dir == 1)
ret = edit_load_file_from_filename (h, extdir_vpath, 0); {
edit_arg_init (&arg, extdir_vpath, 0);
ret = edit_load_file_from_filename (h, &arg);
}
vfs_path_free (extdir_vpath, TRUE); vfs_path_free (extdir_vpath, TRUE);
@ -1177,6 +1186,7 @@ edit_load_menu_file (WDialog * h)
vfs_path_t *buffer_vpath; vfs_path_t *buffer_vpath;
vfs_path_t *menufile_vpath; vfs_path_t *menufile_vpath;
int dir; int dir;
edit_arg_t arg;
gboolean ret; gboolean ret;
query_set_sel (1); query_set_sel (1);
@ -1222,7 +1232,8 @@ edit_load_menu_file (WDialog * h)
return FALSE; return FALSE;
} }
ret = edit_load_file_from_filename (h, buffer_vpath, 0); edit_arg_init (&arg, buffer_vpath, 0);
ret = edit_load_file_from_filename (h, &arg);
vfs_path_free (buffer_vpath, TRUE); vfs_path_free (buffer_vpath, TRUE);
vfs_path_free (menufile_vpath, TRUE); vfs_path_free (menufile_vpath, TRUE);
@ -1982,8 +1993,7 @@ edit_load_forward_cmd (WEdit * edit)
edit_stack_iterator++; edit_stack_iterator++;
if (edit_history_moveto[edit_stack_iterator].file_vpath != NULL) if (edit_history_moveto[edit_stack_iterator].file_vpath != NULL)
return edit_reload_line (edit, edit_history_moveto[edit_stack_iterator].file_vpath, return edit_reload_line (edit, &edit_history_moveto[edit_stack_iterator]);
edit_history_moveto[edit_stack_iterator].line_number);
return FALSE; return FALSE;
} }
@ -2009,8 +2019,7 @@ edit_load_back_cmd (WEdit * edit)
edit_stack_iterator--; edit_stack_iterator--;
if (edit_history_moveto[edit_stack_iterator].file_vpath != NULL) if (edit_history_moveto[edit_stack_iterator].file_vpath != NULL)
return edit_reload_line (edit, edit_history_moveto[edit_stack_iterator].file_vpath, return edit_reload_line (edit, &edit_history_moveto[edit_stack_iterator]);
edit_history_moveto[edit_stack_iterator].line_number);
return FALSE; return FALSE;
} }

View File

@ -405,7 +405,7 @@ edit_dialog_command_execute (WDialog * h, long command)
switch (command) switch (command)
{ {
case CK_EditNew: case CK_EditNew:
edit_load_file_from_filename (h, NULL, 0); edit_load_file_from_filename (h, NULL);
break; break;
case CK_EditFile: case CK_EditFile:
edit_load_cmd (h); edit_load_cmd (h);
@ -1196,13 +1196,12 @@ edit_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event)
*/ */
gboolean gboolean
edit_file (const vfs_path_t * file_vpath, long line) edit_file (const edit_arg_t * arg)
{ {
edit_arg_t arg = { (vfs_path_t *) file_vpath, line };
GList *files; GList *files;
gboolean ok; gboolean ok;
files = g_list_prepend (NULL, &arg); files = g_list_prepend (NULL, (edit_arg_t *) arg);
ok = edit_files (files); ok = edit_files (files);
g_list_free (files); g_list_free (files);
@ -1269,10 +1268,9 @@ edit_files (const GList * files)
for (file = files; file != NULL; file = g_list_next (file)) for (file = files; file != NULL; file = g_list_next (file))
{ {
edit_arg_t *f = (edit_arg_t *) file->data;
gboolean f_ok; gboolean f_ok;
f_ok = edit_load_file_from_filename (edit_dlg, f->file_vpath, f->line_number); f_ok = edit_load_file_from_filename (edit_dlg, (const edit_arg_t *) file->data);
/* at least one file has been opened succefully */ /* at least one file has been opened succefully */
ok = ok || f_ok; ok = ok || f_ok;
} }
@ -1363,12 +1361,12 @@ edit_save_size (WEdit * edit)
*/ */
gboolean gboolean
edit_add_window (WDialog * h, const WRect * r, const vfs_path_t * f, long fline) edit_add_window (WDialog * h, const WRect * r, const edit_arg_t * arg)
{ {
WEdit *edit; WEdit *edit;
Widget *w; Widget *w;
edit = edit_init (NULL, r, f, fline); edit = edit_init (NULL, r, arg);
if (edit == NULL) if (edit == NULL)
return FALSE; return FALSE;

View File

@ -394,8 +394,7 @@ editcmd_dialog_select_definition_show (WEdit * edit, char *match_expr, GPtrArray
edit_stack_iterator++; edit_stack_iterator++;
edit_arg_assign (&edit_history_moveto[edit_stack_iterator], edit_arg_assign (&edit_history_moveto[edit_stack_iterator],
vfs_path_from_str ((char *) curr_def->fullpath), curr_def->line); vfs_path_from_str ((char *) curr_def->fullpath), curr_def->line);
edit_reload_line (edit, edit_history_moveto[edit_stack_iterator].file_vpath, edit_reload_line (edit, &edit_history_moveto[edit_stack_iterator]);
edit_history_moveto[edit_stack_iterator].line_number);
} }
} }

View File

@ -664,7 +664,11 @@ edit_file_at_line (const vfs_path_t * what_vpath, gboolean internal, long start_
#ifdef USE_INTERNAL_EDIT #ifdef USE_INTERNAL_EDIT
if (internal) if (internal)
edit_file (what_vpath, start_line); {
const edit_arg_t arg = { (vfs_path_t *) what_vpath, start_line };
edit_file (&arg);
}
else else
#endif /* USE_INTERNAL_EDIT */ #endif /* USE_INTERNAL_EDIT */
{ {

View File

@ -152,6 +152,7 @@ static void
my_setup (void) my_setup (void)
{ {
WRect r; WRect r;
edit_arg_t arg;
str_init_strings (NULL); str_init_strings (NULL);
@ -171,7 +172,9 @@ my_setup (void)
edit_options.filesize_threshold = (char *) "64M"; edit_options.filesize_threshold = (char *) "64M";
rect_init (&r, 0, 0, 24, 80); rect_init (&r, 0, 0, 24, 80);
test_edit = edit_init (NULL, &r, vfs_path_from_str ("test-data.txt"), 1); arg.file_vpath = vfs_path_from_str ("test-data.txt");
arg.line_number = 1;
test_edit = edit_init (NULL, &r, &arg);
memset (&owner, 0, sizeof (owner)); memset (&owner, 0, sizeof (owner));
group_add_widget (&owner, WIDGET (test_edit)); group_add_widget (&owner, WIDGET (test_edit));
edit_completion_dialog_show__init (); edit_completion_dialog_show__init ();