Changed internal editor to use vfs_path_t objects.

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
Slava Zanko 2011-11-08 22:44:38 +03:00
parent 12a9390524
commit db58cd9ca7
23 changed files with 463 additions and 344 deletions

View File

@ -1195,13 +1195,14 @@ list_append_unique (GList * list, char *text)
*/
void
load_file_position (const char *filename, long *line, long *column, off_t * offset,
load_file_position (const vfs_path_t * filename_vpath, long *line, long *column, off_t * offset,
GArray ** bookmarks)
{
char *fn;
FILE *f;
char buf[MC_MAXPATHLEN + 100];
const size_t len = strlen (filename);
const size_t len = vfs_path_len (filename_vpath);
char *filename;
/* defaults */
*line = 1;
@ -1217,6 +1218,7 @@ load_file_position (const char *filename, long *line, long *column, off_t * offs
/* prepare array for serialized bookmarks */
*bookmarks = g_array_sized_new (FALSE, FALSE, sizeof (size_t), MAX_SAVED_BOOKMARKS);
filename = vfs_path_to_str (filename_vpath);
while (fgets (buf, sizeof (buf), f) != NULL)
{
@ -1276,6 +1278,7 @@ load_file_position (const char *filename, long *line, long *column, off_t * offs
g_strfreev (pos_tokens);
}
g_free (filename);
fclose (f);
}
@ -1285,15 +1288,17 @@ load_file_position (const char *filename, long *line, long *column, off_t * offs
*/
void
save_file_position (const char *filename, long line, long column, off_t offset, GArray * bookmarks)
save_file_position (const vfs_path_t * filename_vpath, long line, long column, off_t offset,
GArray * bookmarks)
{
static size_t filepos_max_saved_entries = 0;
char *fn, *tmp_fn;
FILE *f, *tmp_f;
char buf[MC_MAXPATHLEN + 100];
size_t i;
const size_t len = strlen (filename);
const size_t len = vfs_path_len (filename_vpath);
gboolean src_error = FALSE;
char *filename;
if (filepos_max_saved_entries == 0)
filepos_max_saved_entries = mc_config_get_int (mc_main_config, CONFIG_APP_SECTION,
@ -1318,6 +1323,7 @@ save_file_position (const char *filename, long line, long column, off_t offset,
goto open_source_error;
}
filename = vfs_path_to_str (filename_vpath);
/* put the new record */
if (line != 1 || column != 0 || bookmarks != NULL)
{
@ -1345,6 +1351,7 @@ save_file_position (const char *filename, long line, long column, off_t offset,
}
write_position_error:
g_free (filename);
fclose (tmp_f);
open_source_error:
g_free (tmp_fn);

View File

@ -183,10 +183,10 @@ GList *list_append_unique (GList * list, char *text);
/* Position saving and restoring */
/* Load position for the given filename */
void load_file_position (const char *filename, long *line, long *column, off_t * offset,
GArray ** bookmarks);
void load_file_position (const vfs_path_t * filename_vpath, long *line, long *column,
off_t * offset, GArray ** bookmarks);
/* Save position for the given filename */
void save_file_position (const char *filename, long line, long column, off_t offset,
void save_file_position (const vfs_path_t * filename_vpath, long line, long column, off_t offset,
GArray * bookmarks);

View File

@ -1199,7 +1199,7 @@ vfs_path_tokens_count (const vfs_path_t * vpath)
*/
char *
vfs_path_tokens_get (const vfs_path_t * vpath, ssize_t start_position, size_t length)
vfs_path_tokens_get (const vfs_path_t * vpath, ssize_t start_position, ssize_t length)
{
GString *ret_tokens, *element_tokens;
int element_index;
@ -1211,6 +1211,9 @@ vfs_path_tokens_get (const vfs_path_t * vpath, ssize_t start_position, size_t le
if (length == 0)
length = tokens_count;
if (length < 0)
length = tokens_count + length;
if (start_position < 0)
start_position = (ssize_t) tokens_count + start_position;
@ -1279,7 +1282,7 @@ vfs_path_tokens_get (const vfs_path_t * vpath, ssize_t start_position, size_t le
*/
vfs_path_t *
vfs_path_vtokens_get (const vfs_path_t * vpath, ssize_t start_position, size_t length)
vfs_path_vtokens_get (const vfs_path_t * vpath, ssize_t start_position, ssize_t length)
{
char *str_tokens;
vfs_path_t *ret_vpath = NULL;

View File

@ -61,8 +61,8 @@ vfs_path_t *vfs_path_build_filename (const char *first_element, ...);
vfs_path_t *vfs_path_append_new (const vfs_path_t * vpath, const char *first_element, ...);
vfs_path_t *vfs_path_append_vpath_new (const vfs_path_t * first_vpath, ...);
size_t vfs_path_tokens_count (const vfs_path_t *);
char *vfs_path_tokens_get (const vfs_path_t * vpath, ssize_t start_position, size_t length);
vfs_path_t *vfs_path_vtokens_get (const vfs_path_t * vpath, ssize_t start_position, size_t length);
char *vfs_path_tokens_get (const vfs_path_t * vpath, ssize_t start_position, ssize_t length);
vfs_path_t *vfs_path_vtokens_get (const vfs_path_t * vpath, ssize_t start_position, ssize_t length);
vfs_path_element_t *vfs_path_get_by_index (const vfs_path_t * path, int element_index);
vfs_path_element_t *vfs_path_element_clone (const vfs_path_element_t * element);

View File

@ -2770,7 +2770,13 @@ dview_edit (WDiff * dview, int ord)
get_line_numbers (dview->a[ord], dview->skip_rows, &linenum, &lineofs);
h->modal = TRUE; /* not allow edit file in several editors */
do_edit_at_line (dview->file[ord], use_internal_edit, linenum);
{
vfs_path_t *tmp_vpath;
tmp_vpath = vfs_path_from_str (dview->file[ord]);
do_edit_at_line (tmp_vpath, use_internal_edit, linenum);
vfs_path_free (tmp_vpath);
}
h->modal = h_modal;
dview_redo (dview);
dview_update (dview);

View File

@ -145,7 +145,7 @@ typedef struct edit_search_options_t
typedef struct edit_stack_type
{
long line;
char *filename;
vfs_path_t *filename_vpath;
} edit_stack_type;
struct Widget;
@ -204,7 +204,7 @@ long edit_eol (WEdit * edit, long current);
void edit_update_curs_row (WEdit * edit);
void edit_update_curs_col (WEdit * edit);
void edit_find_bracket (WEdit * edit);
int edit_reload_line (WEdit * edit, const char *filename, long line);
int edit_reload_line (WEdit * edit, const vfs_path_t * filename_vpath, long line);
void edit_set_codeset (WEdit * edit);
void edit_block_copy_cmd (WEdit * edit);
@ -220,15 +220,17 @@ void edit_push_redo_action (WEdit * edit, long c, ...);
void edit_push_key_press (WEdit * edit);
void edit_insert_ahead (WEdit * edit, int c);
long edit_write_stream (WEdit * edit, FILE * f);
char *edit_get_write_filter (const vfs_path_t * write_name_vpath, const char *filename);
char *edit_get_write_filter (const vfs_path_t * write_name_vpath,
const vfs_path_t * filename_vpath);
int edit_save_confirm_cmd (WEdit * edit);
int edit_save_as_cmd (WEdit * edit);
WEdit *edit_init (WEdit * edit, int y, int x, int lines, int cols, const char *filename, long line);
WEdit *edit_init (WEdit * edit, int y, int x, int lines, int cols,
const vfs_path_t * filename_vpath, long line);
int edit_clean (WEdit * edit);
gboolean edit_ok_to_exit (WEdit * edit);
int edit_renew (WEdit * edit);
int edit_new_cmd (WEdit * edit);
int edit_reload (WEdit * edit, const char *filename);
int edit_reload (WEdit * edit, const vfs_path_t * filename_vpath);
int edit_load_cmd (WEdit * edit, edit_current_file_t what);
void edit_mark_cmd (WEdit * edit, int unmark);
void edit_mark_current_word_cmd (WEdit * edit);
@ -246,7 +248,7 @@ gboolean edit_insert_file_cmd (WEdit * edit);
void edit_insert_over (WEdit * edit);
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);
long edit_insert_file (WEdit * edit, const vfs_path_t * filename_vpath);
int edit_load_back_cmd (WEdit * edit);
int edit_load_forward_cmd (WEdit * edit);
void edit_block_process_cmd (WEdit * edit, int macro_number);
@ -281,7 +283,7 @@ void edit_begin_end_repeat_cmd (WEdit * edit);
void edit_paste_from_history (WEdit * edit);
void edit_set_filename (WEdit * edit, const char *name);
void edit_set_filename (WEdit * edit, const vfs_path_t * name_vpath);
void edit_load_syntax (WEdit * edit, char ***pnames, const char *type);
void edit_free_syntax_rules (WEdit * edit);

View File

@ -39,8 +39,8 @@ struct WEdit
{
Widget widget;
char *filename; /* Name of the file */
char *dir; /* NULL if filename is absolute */
vfs_path_t *filename_vpath; /* Name of the file */
vfs_path_t *dir_vpath; /* NULL if filename is absolute */
/* dynamic buffers and cursor position for editor: */
long curs1; /* position of the cursor from the beginning of the file. */
@ -106,14 +106,14 @@ struct WEdit
unsigned long undo_stack_size;
unsigned long undo_stack_size_mask;
unsigned long undo_stack_bottom;
unsigned int undo_stack_disable:1; /* If not 0, don't save events in the undo stack */
unsigned int undo_stack_disable:1; /* If not 0, don't save events in the undo stack */
unsigned long redo_stack_pointer;
long *redo_stack;
unsigned long redo_stack_size;
unsigned long redo_stack_size_mask;
unsigned long redo_stack_bottom;
unsigned int redo_stack_reset:1; /* If 1, need clear redo stack */
unsigned int redo_stack_reset:1; /* If 1, need clear redo stack */
struct stat stat1; /* Result of mc_fstat() on the file */
unsigned int skip_detach_prompt:1; /* Do not prompt whether to detach a file anymore */

View File

@ -248,24 +248,23 @@ edit_init_buffers (WEdit * edit)
*/
static int
edit_load_file_fast (WEdit * edit, const char *filename)
edit_load_file_fast (WEdit * edit, const vfs_path_t * filename_vpath)
{
long buf, buf2;
int file = -1;
int ret = 1;
vfs_path_t *vpath;
edit->curs2 = edit->last_byte;
buf2 = edit->curs2 >> S_EDIT_BUF_SIZE;
vpath = vfs_path_from_str (filename);
file = mc_open (vpath, O_RDONLY | O_BINARY);
vfs_path_free (vpath);
file = mc_open (filename_vpath, O_RDONLY | O_BINARY);
if (file == -1)
{
gchar *errmsg;
gchar *errmsg, *filename;
filename = vfs_path_to_str (filename_vpath);
errmsg = g_strdup_printf (_("Cannot open %s for reading"), filename);
g_free (filename);
edit_error_dialog (_("Error"), errmsg);
g_free (errmsg);
return 1;
@ -292,11 +291,16 @@ edit_load_file_fast (WEdit * edit, const char *filename)
ret = 0;
}
while (0);
if (ret)
if (ret != 0)
{
char *err_str = g_strdup_printf (_("Error reading %s"), filename);
edit_error_dialog (_("Error"), err_str);
g_free (err_str);
gchar *errmsg, *filename;
filename = vfs_path_to_str (filename_vpath);
errmsg = g_strdup_printf (_("Error reading %s"), filename);
g_free (filename);
edit_error_dialog (_("Error"), errmsg);
g_free (errmsg);
}
mc_close (file);
return ret;
@ -306,37 +310,45 @@ edit_load_file_fast (WEdit * edit, const char *filename)
/** Return index of the filter or -1 is there is no appropriate filter */
static int
edit_find_filter (const char *filename)
edit_find_filter (const vfs_path_t * filename_vpath)
{
size_t i, l, e;
char *filename;
if (filename == NULL)
if (filename_vpath == NULL)
return -1;
filename = vfs_path_to_str (filename_vpath);
l = strlen (filename);
for (i = 0; i < sizeof (all_filters) / sizeof (all_filters[0]); i++)
{
e = strlen (all_filters[i].extension);
if (l > e)
if (!strcmp (all_filters[i].extension, filename + l - e))
{
g_free (filename);
return i;
}
}
g_free (filename);
return -1;
}
/* --------------------------------------------------------------------------------------------- */
static char *
edit_get_filter (const char *filename)
edit_get_filter (const vfs_path_t * filename_vpath)
{
int i;
char *p, *quoted_name;
char *p, *quoted_name, *filename;
i = edit_find_filter (filename);
i = edit_find_filter (filename_vpath);
if (i < 0)
return NULL;
filename = vfs_path_to_str (filename_vpath);
quoted_name = name_quote (filename, 0);
g_free (filename);
p = g_strdup_printf (all_filters[i].read, quoted_name);
g_free (quoted_name);
return p;
@ -361,26 +373,27 @@ edit_insert_stream (WEdit * edit, FILE * f)
/** Open file and create it if necessary. Return 0 for success, 1 for error. */
static int
check_file_access (WEdit * edit, const char *filename, struct stat *st)
check_file_access (WEdit * edit, const vfs_path_t * filename_vpath, struct stat *st)
{
int file;
gchar *errmsg = NULL;
vfs_path_t *vpath;
/* Try opening an existing file */
vpath = vfs_path_from_str (filename);
file = mc_open (vpath, O_NONBLOCK | O_RDONLY | O_BINARY, 0666);
file = mc_open (filename_vpath, O_NONBLOCK | O_RDONLY | O_BINARY, 0666);
if (file < 0)
{
/*
* Try creating the file. O_EXCL prevents following broken links
* and opening existing files.
*/
file = mc_open (vpath, O_NONBLOCK | O_RDONLY | O_BINARY | O_CREAT | O_EXCL, 0666);
file = mc_open (filename_vpath, O_NONBLOCK | O_RDONLY | O_BINARY | O_CREAT | O_EXCL, 0666);
if (file < 0)
{
char *filename;
filename = vfs_path_to_str (filename_vpath);
errmsg = g_strdup_printf (_("Cannot open %s for reading"), filename);
g_free (filename);
goto cleanup;
}
else
@ -393,14 +406,22 @@ check_file_access (WEdit * edit, const char *filename, struct stat *st)
/* Check what we have opened */
if (mc_fstat (file, st) < 0)
{
char *filename;
filename = vfs_path_to_str (filename_vpath);
errmsg = g_strdup_printf (_("Cannot get size/permissions for %s"), filename);
g_free (filename);
goto cleanup;
}
/* We want to open regular files only */
if (!S_ISREG (st->st_mode))
{
char *filename;
filename = vfs_path_to_str (filename_vpath);
errmsg = g_strdup_printf (_("\"%s\" is not a regular file"), filename);
g_free (filename);
goto cleanup;
}
@ -412,11 +433,16 @@ check_file_access (WEdit * edit, const char *filename, struct stat *st)
edit->delete_file = 0;
if (st->st_size >= SIZE_LIMIT)
{
char *filename;
filename = vfs_path_to_str (filename_vpath);
errmsg = g_strdup_printf (_("File \"%s\" is too large"), filename);
g_free (filename);
}
cleanup:
(void) mc_close (file);
vfs_path_free (vpath);
if (errmsg != NULL)
{
@ -442,29 +468,29 @@ static int
edit_load_file (WEdit * edit)
{
int fast_load = 1;
vfs_path_t *vpath = vfs_path_from_str (edit->filename);
/* Cannot do fast load if a filter is used */
if (edit_find_filter (edit->filename) >= 0)
if (edit_find_filter (edit->filename_vpath) >= 0)
fast_load = 0;
/*
* VFS may report file size incorrectly, and slow load is not a big
* deal considering overhead in VFS.
*/
if (!vfs_file_is_local (vpath))
fast_load = 0;
vfs_path_free (vpath);
/*
* FIXME: line end translation should disable fast loading as well
* Consider doing fseek() to the end and ftell() for the real size.
*/
if (*edit->filename)
if (edit->filename_vpath != NULL)
{
/*
* VFS may report file size incorrectly, and slow load is not a big
* deal considering overhead in VFS.
*/
if (!vfs_file_is_local (edit->filename_vpath))
fast_load = 0;
/* If we are dealing with a real file, check that it exists */
if (check_file_access (edit, edit->filename, &edit->stat1))
if (check_file_access (edit, edit->filename_vpath, &edit->stat1))
return 1;
}
else
@ -478,17 +504,18 @@ edit_load_file (WEdit * edit)
if (fast_load)
{
edit->last_byte = edit->stat1.st_size;
edit_load_file_fast (edit, edit->filename);
edit_load_file_fast (edit, edit->filename_vpath);
/* If fast load was used, the number of lines wasn't calculated */
edit->total_lines = edit_count_lines (edit, 0, edit->last_byte);
}
else
{
edit->last_byte = 0;
if (*edit->filename)
if (edit->filename_vpath != NULL
&& *(vfs_path_get_by_index (edit->filename_vpath, 0)->path) != '\0')
{
edit->undo_stack_disable = 1;
if (edit_insert_file (edit, edit->filename) < 0)
if (edit_insert_file (edit, edit->filename_vpath) < 0)
{
edit_clean (edit);
return 1;
@ -506,19 +533,14 @@ edit_load_file (WEdit * edit)
static void
edit_load_position (WEdit * edit)
{
char *filename;
long line, column;
off_t offset;
vfs_path_t *vpath;
if (!edit->filename || !*edit->filename)
if (edit->filename_vpath == NULL
|| *(vfs_path_get_by_index (edit->filename_vpath, 0)->path) == '\0')
return;
vpath = vfs_path_from_str (edit->filename);
filename = vfs_path_to_str (vpath);
load_file_position (filename, &line, &column, &offset, &edit->serialized_bookmarks);
vfs_path_free (vpath);
g_free (filename);
load_file_position (edit->filename_vpath, &line, &column, &offset, &edit->serialized_bookmarks);
if (line > 0)
{
@ -544,22 +566,14 @@ edit_load_position (WEdit * edit)
static void
edit_save_position (WEdit * edit)
{
char *filename;
vfs_path_t *vpath;
if (edit->filename == NULL || *edit->filename == '\0')
if (edit->filename_vpath == NULL
|| *(vfs_path_get_by_index (edit->filename_vpath, 0)->path) == '\0')
return;
vpath = vfs_path_from_str (edit->filename);
filename = vfs_path_to_str (vpath);
book_mark_serialize (edit, BOOK_MARK_COLOR);
save_file_position (filename, edit->curs_line + 1, edit->curs_col, edit->curs1,
save_file_position (edit->filename_vpath, edit->curs_line + 1, edit->curs_col, edit->curs1,
edit->serialized_bookmarks);
edit->serialized_bookmarks = NULL;
g_free (filename);
vfs_path_free (vpath);
}
/* --------------------------------------------------------------------------------------------- */
@ -1863,7 +1877,7 @@ user_menu (WEdit * edit, const char *menu_file, int selected_entry)
{
long ins_len;
ins_len = edit_insert_file (edit, block_file);
ins_len = edit_insert_file (edit, block_file_vpath);
if (nomark == 0 && ins_len > 0)
edit_set_markers (edit, start_mark, start_mark + ins_len, 0, 0);
}
@ -1966,13 +1980,13 @@ edit_get_utf (WEdit * edit, long byte_index, int *char_width)
/* --------------------------------------------------------------------------------------------- */
char *
edit_get_write_filter (const vfs_path_t * write_name_vpath, const char *filename)
edit_get_write_filter (const vfs_path_t * write_name_vpath, const vfs_path_t * filename_vpath)
{
int i;
char *p, *writename;
vfs_path_element_t *path_element;
i = edit_find_filter (filename);
i = edit_find_filter (filename_vpath);
if (i < 0)
return NULL;
@ -2082,14 +2096,12 @@ edit_write_stream (WEdit * edit, FILE * f)
/* --------------------------------------------------------------------------------------------- */
/** inserts a file at the cursor, returns count of inserted bytes on success */
long
edit_insert_file (WEdit * edit, const char *filename)
edit_insert_file (WEdit * edit, const vfs_path_t * filename_vpath)
{
char *p = NULL;
char *p;
long ins_len = 0;
vfs_path_t *vpath;
vpath = vfs_path_from_str (filename);
p = edit_get_filter (filename);
p = edit_get_filter (filename_vpath);
if (p != NULL)
{
FILE *f;
@ -2122,6 +2134,7 @@ edit_insert_file (WEdit * edit, const char *filename)
ins_len = -1;
goto ret;
}
g_free (p);
}
else
{
@ -2130,12 +2143,13 @@ edit_insert_file (WEdit * edit, const char *filename)
int vertical_insertion = 0;
char *buf;
file = mc_open (vpath, O_RDONLY | O_BINARY);
file = mc_open (filename_vpath, O_RDONLY | O_BINARY);
if (file == -1)
{
ins_len = -1;
goto ret;
}
buf = g_malloc0 (TEMP_BUF_LEN);
blocklen = mc_read (file, buf, sizeof (VERTICAL_MAGIC));
if (blocklen > 0)
@ -2190,7 +2204,6 @@ edit_insert_file (WEdit * edit, const char *filename)
ret:
g_free (p);
vfs_path_free (vpath);
return ins_len;
}
@ -2204,7 +2217,8 @@ edit_insert_file (WEdit * edit, const char *filename)
*/
WEdit *
edit_init (WEdit * edit, int y, int x, int lines, int cols, const char *filename, long line)
edit_init (WEdit * edit, int y, int x, int lines, int cols, const vfs_path_t * filename_vpath,
long line)
{
gboolean to_free = FALSE;
@ -2262,7 +2276,7 @@ edit_init (WEdit * edit, int y, int x, int lines, int cols, const char *filename
edit->over_col = 0;
edit->bracket = -1;
edit->force |= REDRAW_PAGE;
edit_set_filename (edit, filename);
edit_set_filename (edit, filename_vpath);
edit->undo_stack_size = START_STACK_SIZE;
edit->undo_stack_size_mask = START_STACK_SIZE - 1;
@ -2331,7 +2345,7 @@ edit_clean (WEdit * edit)
/* File specified on the mcedit command line and never saved */
if (edit->delete_file)
unlink (edit->filename);
unlink (vfs_path_get_last_path_str (edit->filename_vpath));
edit_free_syntax_rules (edit);
book_mark_flush (edit, -1);
@ -2343,8 +2357,8 @@ edit_clean (WEdit * edit)
g_free (edit->undo_stack);
g_free (edit->redo_stack);
g_free (edit->filename);
g_free (edit->dir);
vfs_path_free (edit->filename_vpath);
vfs_path_free (edit->dir_vpath);
mc_search_free (edit->search);
edit->search = NULL;
@ -2368,7 +2382,7 @@ edit_renew (WEdit * edit)
int columns = edit->widget.cols;
edit_clean (edit);
return (edit_init (edit, y, x, lines, columns, "", 0) != NULL);
return (edit_init (edit, y, x, lines, columns, NULL, 0) != NULL);
}
/* --------------------------------------------------------------------------------------------- */
@ -2380,7 +2394,7 @@ edit_renew (WEdit * edit)
*/
int
edit_reload (WEdit * edit, const char *filename)
edit_reload (WEdit * edit, const vfs_path_t * filename_vpath)
{
WEdit *e;
int y = edit->widget.y;
@ -2390,7 +2404,7 @@ edit_reload (WEdit * edit, const char *filename)
e = g_malloc0 (sizeof (WEdit));
e->widget = edit->widget;
if (edit_init (e, y, x, lines, columns, filename, 0) == NULL)
if (edit_init (e, y, x, lines, columns, filename_vpath, 0) == NULL)
{
g_free (e);
return 0;
@ -2410,7 +2424,7 @@ edit_reload (WEdit * edit, const char *filename)
*/
int
edit_reload_line (WEdit * edit, const char *filename, long line)
edit_reload_line (WEdit * edit, const vfs_path_t * filename_vpath, long line)
{
WEdit *e;
int y = edit->widget.y;
@ -2420,7 +2434,7 @@ edit_reload_line (WEdit * edit, const char *filename, long line)
e = g_malloc0 (sizeof (WEdit));
e->widget = edit->widget;
if (edit_init (e, y, x, lines, columns, filename, line) == NULL)
if (edit_init (e, y, x, lines, columns, filename_vpath, line) == NULL)
{
g_free (e);
return 0;
@ -4332,7 +4346,7 @@ edit_stack_init (void)
{
for (edit_stack_iterator = 0; edit_stack_iterator < MAX_HISTORY_MOVETO; edit_stack_iterator++)
{
edit_history_moveto[edit_stack_iterator].filename = NULL;
edit_history_moveto[edit_stack_iterator].filename_vpath = NULL;
edit_history_moveto[edit_stack_iterator].line = -1;
}
@ -4345,7 +4359,7 @@ void
edit_stack_free (void)
{
for (edit_stack_iterator = 0; edit_stack_iterator < MAX_HISTORY_MOVETO; edit_stack_iterator++)
g_free (edit_history_moveto[edit_stack_iterator].filename);
vfs_path_free (edit_history_moveto[edit_stack_iterator].filename_vpath);
}
/* --------------------------------------------------------------------------------------------- */
@ -4374,7 +4388,7 @@ edit_unlock_file (WEdit * edit)
vfs_path_t *fullpath;
unsigned int ret;
fullpath = vfs_path_build_filename (edit->dir, edit->filename, (char *) NULL);
fullpath = vfs_path_append_vpath_new (edit->dir_vpath, edit->filename_vpath, (char *) NULL);
ret = unlock_file (fullpath);
vfs_path_free (fullpath);
@ -4389,7 +4403,7 @@ edit_lock_file (WEdit * edit)
vfs_path_t *fullpath;
unsigned int ret;
fullpath = vfs_path_build_filename (edit->dir, edit->filename, (char *) NULL);
fullpath = vfs_path_append_vpath_new (edit->dir_vpath, edit->filename_vpath, (char *) NULL);
ret = lock_file (fullpath);
vfs_path_free (fullpath);

View File

@ -61,9 +61,9 @@ extern int show_right_margin;
void edit_stack_init (void);
void edit_stack_free (void);
int edit_file (const char *_file, int line);
int edit_file (const vfs_path_t * _file_vpath, int line);
const char *edit_get_file_name (const WEdit * edit);
char *edit_get_file_name (const WEdit * edit);
int edit_get_curs_col (const WEdit * edit);
const char *edit_get_syntax_type (const WEdit * edit);

View File

@ -116,30 +116,28 @@ int edit_confirm_save = 1;
/* returns 0 on error, -1 on abort */
static int
edit_save_file (WEdit * edit, const char *filename)
edit_save_file (WEdit * edit, const vfs_path_t * filename_vpath)
{
char *p;
gchar *tmp;
long filelen = 0;
gchar *real_filename;
int this_save_mode, fd = -1;
vfs_path_t *real_filename_vpath;
vfs_path_t *savename_vpath = NULL;
const char *start_filename;
if (!filename)
return 0;
if (!*filename)
start_filename = vfs_path_get_by_index (filename_vpath, 0)->path;
if (filename_vpath == NULL || *start_filename == '\0')
return 0;
if (*filename != PATH_SEP && edit->dir)
if (*start_filename != PATH_SEP && edit->dir_vpath != NULL)
{
real_filename = concat_dir_and_file (edit->dir, filename);
real_filename_vpath = vfs_path_append_vpath_new (edit->dir_vpath, filename_vpath, NULL);
}
else
{
real_filename = g_strdup (filename);
real_filename_vpath = vfs_path_clone (filename_vpath);
}
real_filename_vpath = vfs_path_from_str (real_filename);
this_save_mode = option_save_mode;
if (this_save_mode != EDIT_QUICK_SAVE)
@ -177,7 +175,6 @@ edit_save_file (WEdit * edit, const char *filename)
edit->skip_detach_prompt = 1;
break;
default:
g_free (real_filename);
vfs_path_free (real_filename_vpath);
return -1;
}
@ -186,7 +183,6 @@ edit_save_file (WEdit * edit, const char *filename)
/* Prevent overwriting changes from other editor sessions. */
if (rv == 0 && edit->stat1.st_mtime != 0 && edit->stat1.st_mtime != sb.st_mtime)
{
/* The default action is "Cancel". */
query_set_sel (1);
@ -195,7 +191,6 @@ edit_save_file (WEdit * edit, const char *filename)
_("&Yes"), _("&Cancel"));
if (rv != 0)
{
g_free (real_filename);
vfs_path_free (real_filename_vpath);
return -1;
}
@ -205,22 +200,17 @@ edit_save_file (WEdit * edit, const char *filename)
if (this_save_mode != EDIT_QUICK_SAVE)
{
char *savedir, *saveprefix;
const char *slashpos;
slashpos = strrchr (real_filename, PATH_SEP);
if (slashpos)
{
savedir = g_strdup (real_filename);
savedir[slashpos - real_filename + 1] = '\0';
}
else
savedir = vfs_path_tokens_get (real_filename_vpath, 0, -1);
if (savedir == NULL)
savedir = g_strdup (".");
saveprefix = mc_build_filename (savedir, "cooledit", NULL);
g_free (savedir);
fd = mc_mkstemps (&savename_vpath, saveprefix, NULL);
g_free (saveprefix);
if (savename_vpath == NULL)
{
g_free (real_filename);
vfs_path_free (real_filename_vpath);
return 0;
}
@ -232,7 +222,7 @@ edit_save_file (WEdit * edit, const char *filename)
close (fd);
}
else
savename_vpath = vfs_path_from_str (real_filename);
savename_vpath = vfs_path_clone (real_filename_vpath);
(void) mc_chown (savename_vpath, edit->stat1.st_uid, edit->stat1.st_gid);
(void) mc_chmod (savename_vpath, edit->stat1.st_mode);
@ -242,7 +232,7 @@ edit_save_file (WEdit * edit, const char *filename)
goto error_save;
/* pipe save */
p = edit_get_write_filter (savename_vpath, real_filename);
p = edit_get_write_filter (savename_vpath, real_filename_vpath);
if (p != NULL)
{
FILE *file;
@ -373,7 +363,6 @@ edit_save_file (WEdit * edit, const char *filename)
if (mc_rename (savename_vpath, real_filename_vpath) == -1)
goto error_save;
g_free (real_filename);
vfs_path_free (real_filename_vpath);
vfs_path_free (savename_vpath);
return 1;
@ -382,7 +371,6 @@ edit_save_file (WEdit * edit, const char *filename)
* if (this_save_mode != EDIT_QUICK_SAVE)
* mc_unlink (savename);
*/
g_free (real_filename);
vfs_path_free (real_filename_vpath);
vfs_path_free (savename_vpath);
return 0;
@ -402,7 +390,7 @@ edit_check_newline (WEdit * edit)
/* --------------------------------------------------------------------------------------------- */
static char *
static vfs_path_t *
edit_get_save_file_as (WEdit * edit)
{
#define DLG_WIDTH 64
@ -410,7 +398,8 @@ edit_get_save_file_as (WEdit * edit)
static LineBreaks cur_lb = LB_ASIS;
char *filename = edit->filename;
char *filename = vfs_path_to_str (edit->filename_vpath);
char *filename_res;
const char *lb_names[LB_NAMES] = {
N_("&Do not change"),
@ -425,7 +414,7 @@ edit_get_save_file_as (WEdit * edit)
QUICK_RADIO (5, DLG_WIDTH, DLG_HEIGHT - 8, DLG_HEIGHT, LB_NAMES, lb_names, (int *) &cur_lb),
QUICK_LABEL (3, DLG_WIDTH, DLG_HEIGHT - 9, DLG_HEIGHT, N_("Change line breaks to:")),
QUICK_INPUT (3, DLG_WIDTH, DLG_HEIGHT - 11, DLG_HEIGHT, filename, DLG_WIDTH - 6, 0,
"save-as", &filename),
"save-as", &filename_res),
QUICK_LABEL (3, DLG_WIDTH, DLG_HEIGHT - 12, DLG_HEIGHT, N_("Enter file name:")),
QUICK_END
};
@ -439,12 +428,16 @@ edit_get_save_file_as (WEdit * edit)
if (quick_dialog (&Quick_options) != B_CANCEL)
{
char *fname;
vfs_path_t *ret_vpath;
edit->lb = cur_lb;
fname = tilde_expand (filename);
g_free (filename);
return fname;
fname = tilde_expand (filename_res);
g_free (filename_res);
ret_vpath = vfs_path_from_str (fname);
g_free (fname);
return ret_vpath;
}
g_free (filename);
return NULL;
@ -452,6 +445,8 @@ edit_get_save_file_as (WEdit * edit)
#undef DLG_HEIGHT
}
/* --------------------------------------------------------------------------------------------- */
/** returns 1 on success */
static int
@ -461,7 +456,7 @@ edit_save_cmd (WEdit * edit)
if (!edit->locked && !edit->delete_file)
save_lock = edit_lock_file (edit);
res = edit_save_file (edit, edit->filename);
res = edit_save_file (edit, edit->filename_vpath);
/* Maintain modify (not save) lock on failure */
if ((res > 0 && edit->locked) || save_lock)
@ -484,14 +479,15 @@ edit_save_cmd (WEdit * edit)
/** returns 1 on error */
static int
edit_load_file_from_filename (WEdit * edit, char *exp)
edit_load_file_from_filename (WEdit * edit, const vfs_path_t * exp_vpath)
{
int prev_locked = edit->locked;
char *prev_filename = g_strdup (edit->filename);
vfs_path_t *prev_filename;
if (!edit_reload (edit, exp))
prev_filename = vfs_path_clone (edit->filename_vpath);
if (!edit_reload (edit, exp_vpath))
{
g_free (prev_filename);
vfs_path_free (prev_filename);
return 1;
}
@ -499,11 +495,11 @@ edit_load_file_from_filename (WEdit * edit, char *exp)
{
vfs_path_t *fullpath;
fullpath = vfs_path_build_filename (edit->dir, prev_filename, (char *) NULL);
fullpath = vfs_path_append_vpath_new (edit->dir_vpath, prev_filename, (char *) NULL);
unlock_file (fullpath);
vfs_path_free (fullpath);
}
g_free (prev_filename);
vfs_path_free (prev_filename);
return 0;
}
@ -512,7 +508,7 @@ edit_load_file_from_filename (WEdit * edit, char *exp)
static void
edit_load_syntax_file (WEdit * edit)
{
char *extdir;
vfs_path_t *extdir_vpath;
int dir = 0;
if (geteuid () == 0)
@ -522,26 +518,28 @@ edit_load_syntax_file (WEdit * edit)
_("&User"), _("&System Wide"));
}
extdir = g_build_filename (mc_global.sysconfig_dir, "syntax", "Syntax", (char *) NULL);
if (!exist_file (extdir))
extdir_vpath =
vfs_path_build_filename (mc_global.sysconfig_dir, "syntax", "Syntax", (char *) NULL);
if (!exist_file (vfs_path_get_last_path_str (extdir_vpath)))
{
g_free (extdir);
extdir = g_build_filename (mc_global.share_data_dir, "syntax", "Syntax", (char *) NULL);
vfs_path_free (extdir_vpath);
extdir_vpath =
vfs_path_build_filename (mc_global.share_data_dir, "syntax", "Syntax", (char *) NULL);
}
if (dir == 0)
{
char *buffer;
vfs_path_t *user_syntax_file_vpath;
buffer = mc_config_get_full_path (EDIT_SYNTAX_FILE);
check_for_default (extdir, buffer);
edit_load_file_from_filename (edit, buffer);
g_free (buffer);
user_syntax_file_vpath = mc_config_get_full_vpath (EDIT_SYNTAX_FILE);
check_for_default (extdir_vpath, user_syntax_file_vpath);
edit_load_file_from_filename (edit, user_syntax_file_vpath);
vfs_path_free (user_syntax_file_vpath);
}
else if (dir == 1)
edit_load_file_from_filename (edit, extdir);
edit_load_file_from_filename (edit, extdir_vpath);
g_free (extdir);
vfs_path_free (extdir_vpath);
}
/* --------------------------------------------------------------------------------------------- */
@ -549,53 +547,54 @@ edit_load_syntax_file (WEdit * edit)
static void
edit_load_menu_file (WEdit * edit)
{
char *buffer;
char *menufile;
vfs_path_t *buffer_vpath;
vfs_path_t *menufile_vpath;
int dir = 0;
dir = query_dialog (_("Menu edit"),
_("Which menu file do you want to edit?"), D_NORMAL,
geteuid () != 0 ? 2 : 3, _("&Local"), _("&User"), _("&System Wide"));
menufile = concat_dir_and_file (mc_global.sysconfig_dir, EDIT_GLOBAL_MENU);
menufile_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, EDIT_GLOBAL_MENU, NULL);
if (!exist_file (menufile))
if (!exist_file (vfs_path_get_last_path_str (menufile_vpath)))
{
g_free (menufile);
menufile = concat_dir_and_file (mc_global.share_data_dir, EDIT_GLOBAL_MENU);
vfs_path_free (menufile_vpath);
menufile_vpath = vfs_path_build_filename (mc_global.share_data_dir, EDIT_GLOBAL_MENU, NULL);
}
switch (dir)
{
case 0:
buffer = g_strdup (EDIT_LOCAL_MENU);
check_for_default (menufile, buffer);
chmod (buffer, 0600);
buffer_vpath = vfs_path_from_str (EDIT_LOCAL_MENU);
check_for_default (menufile_vpath, buffer_vpath);
chmod (vfs_path_get_last_path_str (buffer_vpath), 0600);
break;
case 1:
buffer = mc_config_get_full_path (EDIT_HOME_MENU);
check_for_default (menufile, buffer);
buffer_vpath = mc_config_get_full_vpath (EDIT_HOME_MENU);
check_for_default (menufile_vpath, buffer_vpath);
break;
case 2:
buffer = concat_dir_and_file (mc_global.sysconfig_dir, EDIT_GLOBAL_MENU);
if (!exist_file (buffer))
buffer_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, EDIT_GLOBAL_MENU, NULL);
if (!exist_file (vfs_path_get_last_path_str (buffer_vpath)))
{
g_free (buffer);
buffer = concat_dir_and_file (mc_global.share_data_dir, EDIT_GLOBAL_MENU);
vfs_path_free (buffer_vpath);
buffer_vpath =
vfs_path_build_filename (mc_global.share_data_dir, EDIT_GLOBAL_MENU, NULL);
}
break;
default:
g_free (menufile);
vfs_path_free (menufile_vpath);
return;
}
edit_load_file_from_filename (edit, buffer);
edit_load_file_from_filename (edit, buffer_vpath);
g_free (buffer);
g_free (menufile);
vfs_path_free (buffer_vpath);
vfs_path_free (menufile_vpath);
}
/* --------------------------------------------------------------------------------------------- */
@ -1448,16 +1447,13 @@ menu_save_mode_cmd (void)
/* --------------------------------------------------------------------------------------------- */
void
edit_set_filename (WEdit * edit, const char *name)
edit_set_filename (WEdit * edit, const vfs_path_t * name_vpath)
{
g_free (edit->filename);
vfs_path_free (edit->filename_vpath);
edit->filename_vpath = vfs_path_clone (name_vpath);
if (name == NULL)
name = "";
edit->filename = tilde_expand (name);
if (edit->dir == NULL && !g_path_is_absolute (name))
edit->dir = vfs_get_current_dir ();
if (edit->dir_vpath == NULL)
edit->dir_vpath = vfs_path_clone (vfs_get_raw_current_dir ());
}
/* --------------------------------------------------------------------------------------------- */
@ -1468,32 +1464,25 @@ int
edit_save_as_cmd (WEdit * edit)
{
/* This heads the 'Save As' dialog box */
char *exp;
vfs_path_t *exp_vpath;
int save_lock = 0;
int different_filename = 0;
if (!edit_check_newline (edit))
return 0;
exp = edit_get_save_file_as (edit);
exp_vpath = edit_get_save_file_as (edit);
edit_push_undo_action (edit, KEY_PRESS + edit->start_display);
if (exp)
if (exp_vpath != NULL)
{
if (!*exp)
{
g_free (exp);
edit->force |= REDRAW_COMPLETELY;
return 0;
}
if (vfs_path_len (exp_vpath) == 0)
goto ret;
else
{
int rv;
vfs_path_t *exp_vpath;
exp_vpath = vfs_path_from_str (exp);
if (strcmp (edit->filename, exp))
if (vfs_path_cmp (edit->filename_vpath, exp_vpath) != 0)
{
int file;
@ -1508,12 +1497,7 @@ edit_save_as_cmd (WEdit * edit)
if (edit_query_dialog2
(_("Warning"),
_("A file already exists with this name"), _("&Overwrite"), _("&Cancel")))
{
edit->force |= REDRAW_COMPLETELY;
g_free (exp);
vfs_path_free (exp_vpath);
return 0;
}
goto ret;
}
else
{
@ -1537,7 +1521,7 @@ edit_save_as_cmd (WEdit * edit)
edit->stat1.st_mode |= S_IWRITE;
}
rv = edit_save_file (edit, exp);
rv = edit_save_file (edit, exp_vpath);
switch (rv)
{
case 1:
@ -1555,15 +1539,14 @@ edit_save_as_cmd (WEdit * edit)
edit->locked = edit_unlock_file (edit);
}
edit_set_filename (edit, exp);
edit_set_filename (edit, exp_vpath);
if (edit->lb != LB_ASIS)
edit_reload (edit, exp);
g_free (exp);
vfs_path_free (exp_vpath);
edit_reload (edit, exp_vpath);
edit->modified = 0;
edit->delete_file = 0;
if (different_filename)
edit_load_syntax (edit, NULL, edit->syntax_type);
vfs_path_free (exp_vpath);
edit->force |= REDRAW_COMPLETELY;
return 1;
default:
@ -1573,13 +1556,13 @@ edit_save_as_cmd (WEdit * edit)
/* Failed, so maintain modify (not save) lock */
if (save_lock)
unlock_file (exp_vpath);
g_free (exp);
vfs_path_free (exp_vpath);
edit->force |= REDRAW_COMPLETELY;
return 0;
break;
}
}
}
ret:
vfs_path_free (exp_vpath);
edit->force |= REDRAW_COMPLETELY;
return 0;
}
@ -1853,18 +1836,24 @@ edit_save_confirm_cmd (WEdit * edit)
{
gchar *f = NULL;
if (edit->filename_vpath == NULL)
return edit_save_as_cmd (edit);
if (!edit_check_newline (edit))
return 0;
if (edit_confirm_save)
{
f = g_strdup_printf (_("Confirm save file: \"%s\""), edit->filename);
if (edit_query_dialog2 (_("Save file"), f, _("&Save"), _("&Cancel")))
{
g_free (f);
return 0;
}
char *filename;
gboolean ok;
filename = vfs_path_to_str (edit->filename_vpath);
f = g_strdup_printf (_("Confirm save file: \"%s\""), filename);
g_free (filename);
ok = (edit_query_dialog2 (_("Save file"), f, _("&Save"), _("&Cancel")) == 0);
g_free (f);
if (!ok)
return 0;
}
return edit_save_cmd (edit);
}
@ -1897,8 +1886,6 @@ edit_new_cmd (WEdit * edit)
int
edit_load_cmd (WEdit * edit, edit_current_file_t what)
{
char *exp;
if (edit->modified
&& (edit_query_dialog2
(_("Warning"),
@ -1912,14 +1899,26 @@ edit_load_cmd (WEdit * edit, edit_current_file_t what)
switch (what)
{
case EDIT_FILE_COMMON:
exp = input_expand_dialog (_("Load"), _("Enter file name:"),
MC_HISTORY_EDIT_LOAD, edit->filename);
if (exp)
{
if (*exp)
edit_load_file_from_filename (edit, exp);
g_free (exp);
char *filename, *exp;
filename = vfs_path_to_str (edit->filename_vpath);
exp = input_expand_dialog (_("Load"), _("Enter file name:"),
MC_HISTORY_EDIT_LOAD, filename);
g_free (filename);
if (exp != NULL)
{
if (*exp != '\0')
{
vfs_path_t *exp_vpath;
exp_vpath = vfs_path_from_str (exp);
edit_load_file_from_filename (edit, exp_vpath);
vfs_path_free (exp_vpath);
}
g_free (exp);
}
}
break;
@ -2703,12 +2702,13 @@ edit_cut_to_X_buf_cmd (WEdit * edit)
void
edit_paste_from_X_buf_cmd (WEdit * edit)
{
gchar *tmp;
vfs_path_t *tmp;
/* try use external clipboard utility */
mc_event_raise (MCEVENT_GROUP_CORE, "clipboard_file_from_ext_clip", NULL);
tmp = mc_config_get_full_path (EDIT_CLIP_FILE);
tmp = mc_config_get_full_vpath (EDIT_CLIP_FILE);
edit_insert_file (edit, tmp);
g_free (tmp);
vfs_path_free (tmp);
}
@ -2806,7 +2806,7 @@ edit_save_block_cmd (WEdit * edit)
gboolean
edit_insert_file_cmd (WEdit * edit)
{
gchar *tmp;
char *tmp;
char *exp;
gboolean ret = FALSE;
@ -2819,7 +2819,12 @@ edit_insert_file_cmd (WEdit * edit)
if (exp != NULL && *exp != '\0')
{
ret = (edit_insert_file (edit, exp) >= 0);
vfs_path_t *exp_vpath;
exp_vpath = vfs_path_from_str (exp);
ret = (edit_insert_file (edit, exp_vpath) >= 0);
vfs_path_free (exp_vpath);
if (!ret)
edit_error_dialog (_("Insert file"), get_sys_error (_("Cannot insert file")));
}
@ -2890,9 +2895,14 @@ edit_sort_cmd (WEdit * edit)
if (edit_block_delete_cmd (edit))
return 1;
tmp = mc_config_get_full_path (EDIT_TEMP_FILE);
edit_insert_file (edit, tmp);
g_free (tmp);
{
vfs_path_t *tmp_vpath;
tmp_vpath = mc_config_get_full_vpath (EDIT_TEMP_FILE);
edit_insert_file (edit, tmp_vpath);
vfs_path_free (tmp_vpath);
}
return 0;
}
@ -2929,9 +2939,14 @@ edit_ext_cmd (WEdit * edit)
}
edit->force |= REDRAW_COMPLETELY;
tmp = mc_config_get_full_path (EDIT_TEMP_FILE);
edit_insert_file (edit, tmp);
g_free (tmp);
{
vfs_path_t *tmp_vpath;
tmp_vpath = mc_config_get_full_vpath (EDIT_TEMP_FILE);
edit_insert_file (edit, tmp_vpath);
vfs_path_free (tmp_vpath);
}
return 0;
}
@ -3144,9 +3159,9 @@ edit_load_forward_cmd (WEdit * edit)
return 1;
}
edit_stack_iterator++;
if (edit_history_moveto[edit_stack_iterator].filename)
if (edit_history_moveto[edit_stack_iterator].filename_vpath)
{
edit_reload_line (edit, edit_history_moveto[edit_stack_iterator].filename,
edit_reload_line (edit, edit_history_moveto[edit_stack_iterator].filename_vpath,
edit_history_moveto[edit_stack_iterator].line);
return 0;
}
@ -3180,9 +3195,9 @@ edit_load_back_cmd (WEdit * edit)
if (edit_stack_iterator > 0)
{
edit_stack_iterator--;
if (edit_history_moveto[edit_stack_iterator].filename)
if (edit_history_moveto[edit_stack_iterator].filename_vpath)
{
edit_reload_line (edit, edit_history_moveto[edit_stack_iterator].filename,
edit_reload_line (edit, edit_history_moveto[edit_stack_iterator].filename_vpath,
edit_history_moveto[edit_stack_iterator].line);
return 0;
}

View File

@ -526,24 +526,25 @@ editcmd_dialog_select_definition_show (WEdit * edit, char *match_expr, int max_l
{
if (edit_stack_iterator + 1 < MAX_HISTORY_MOVETO)
{
g_free (edit_history_moveto[edit_stack_iterator].filename);
if (edit->dir)
vfs_path_free (edit_history_moveto[edit_stack_iterator].filename_vpath);
if (edit->dir_vpath != NULL)
{
edit_history_moveto[edit_stack_iterator].filename =
g_strdup_printf ("%s/%s", edit->dir, edit->filename);
edit_history_moveto[edit_stack_iterator].filename_vpath =
vfs_path_append_vpath_new (edit->dir_vpath, edit->filename_vpath, NULL);
}
else
{
edit_history_moveto[edit_stack_iterator].filename = g_strdup (edit->filename);
edit_history_moveto[edit_stack_iterator].filename_vpath =
vfs_path_clone (edit->filename_vpath);
}
edit_history_moveto[edit_stack_iterator].line = edit->start_line +
edit->curs_row + 1;
edit_stack_iterator++;
g_free (edit_history_moveto[edit_stack_iterator].filename);
edit_history_moveto[edit_stack_iterator].filename =
g_strdup ((char *) curr_def->fullpath);
vfs_path_free (edit_history_moveto[edit_stack_iterator].filename_vpath);
edit_history_moveto[edit_stack_iterator].filename_vpath =
vfs_path_from_str ((char *) curr_def->fullpath);
edit_history_moveto[edit_stack_iterator].line = curr_def->line;
edit_reload_line (edit, edit_history_moveto[edit_stack_iterator].filename,
edit_reload_line (edit, edit_history_moveto[edit_stack_iterator].filename_vpath,
edit_history_moveto[edit_stack_iterator].line);
}
}

View File

@ -829,8 +829,9 @@ edit_status (WEdit * edit)
status_string (edit, status, status_size);
status_len = (int) str_term_width1 (status);
if (edit->filename)
fname = edit->filename;
if (edit->filename_vpath != NULL)
fname = vfs_path_get_last_path_str (edit->filename_vpath);
fname_len = str_term_width1 (fname);
if (fname_len < preferred_fname_len)
fname_len = preferred_fname_len;

View File

@ -101,10 +101,13 @@ edit_get_title (const Dlg_head * h, size_t len)
const WEdit *edit = (const WEdit *) find_widget_type (h, edit_callback);
const char *modified = edit->modified ? "(*) " : " ";
const char *file_label;
char *filename;
len -= 4;
file_label = str_term_trim (edit->filename, len - str_term_width1 (_("Edit: ")));
filename = vfs_path_to_str (edit->filename_vpath);
file_label = str_term_trim (filename, len - str_term_width1 (_("Edit: ")));
g_free (filename);
return g_strconcat (_("Edit: "), modified, file_label, (char *) NULL);
}
@ -354,7 +357,7 @@ edit_callback (Widget * w, widget_msg_t msg, int parm)
/* --------------------------------------------------------------------------------------------- */
int
edit_file (const char *_file, int line)
edit_file (const vfs_path_t * _file_vpath, int line)
{
static gboolean made_directory = FALSE;
Dlg_head *edit_dlg;
@ -376,7 +379,7 @@ edit_file (const char *_file, int line)
g_free (dir);
}
wedit = edit_init (NULL, 1, 0, LINES - 2, COLS, _file, line);
wedit = edit_init (NULL, 1, 0, LINES - 2, COLS, _file_vpath, line);
if (wedit == NULL)
return 0;
@ -411,10 +414,10 @@ edit_file (const char *_file, int line)
/* --------------------------------------------------------------------------------------------- */
const char *
char *
edit_get_file_name (const WEdit * edit)
{
return edit->filename;
return vfs_path_to_str (edit->filename_vpath);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -1505,18 +1505,20 @@ edit_load_syntax (WEdit * edit, char ***pnames, const char *type)
if (!option_syntax_highlighting && (!pnames || !*pnames))
return;
if (edit != NULL)
{
if (!edit->filename)
return;
if (!*edit->filename && !type)
return;
}
if (edit != NULL && edit->filename_vpath == NULL)
return;
f = mc_config_get_full_path (EDIT_SYNTAX_FILE);
if (edit != NULL)
r = edit_read_syntax_file (edit, pnames, f, edit->filename,
{
char *tmp_f;
tmp_f = vfs_path_to_str (edit->filename_vpath);
r = edit_read_syntax_file (edit, pnames, f, tmp_f,
get_first_editor_line (edit),
option_auto_syntax ? NULL : edit->syntax_type);
g_free (tmp_f);
}
else
r = edit_read_syntax_file (NULL, pnames, f, NULL, "", NULL);
if (r == -1)

View File

@ -195,9 +195,9 @@ do_view_cmd (gboolean normal)
/* --------------------------------------------------------------------------------------------- */
static inline void
do_edit (const char *what)
do_edit (const vfs_path_t * what_vpath)
{
do_edit_at_line (what, use_internal_edit, 0);
do_edit_at_line (what_vpath, use_internal_edit, 0);
}
/* --------------------------------------------------------------------------------------------- */
@ -813,18 +813,21 @@ view_filtered_cmd (void)
/* --------------------------------------------------------------------------------------------- */
void
do_edit_at_line (const char *what, gboolean internal, int start_line)
do_edit_at_line (const vfs_path_t * what_vpath, gboolean internal, int start_line)
{
static const char *editor = NULL;
#ifdef USE_INTERNAL_EDIT
if (internal)
edit_file (what, start_line);
edit_file (what_vpath, start_line);
else
#else
(void) start_line;
#endif /* USE_INTERNAL_EDIT */
{
char *what;
what = vfs_path_to_str (what_vpath);
if (editor == NULL)
{
editor = getenv ("EDITOR");
@ -832,6 +835,7 @@ do_edit_at_line (const char *what, gboolean internal, int start_line)
editor = get_default_editor ();
}
execute_with_vfs_arg (editor, what);
g_free (what);
}
if (mc_global.mc_run_mode == MC_RUN_FULL)
@ -851,7 +855,13 @@ void
edit_cmd (void)
{
if (regex_command (selection (current_panel)->fname, "Edit", NULL) == 0)
do_edit (selection (current_panel)->fname);
{
vfs_path_t *fname;
fname = vfs_path_from_str (selection (current_panel)->fname);
do_edit (fname);
vfs_path_free (fname);
}
}
/* --------------------------------------------------------------------------------------------- */
@ -861,7 +871,13 @@ void
edit_cmd_force_internal (void)
{
if (regex_command (selection (current_panel)->fname, "Edit", NULL) == 0)
do_edit_at_line (selection (current_panel)->fname, TRUE, 0);
{
vfs_path_t *fname;
fname = vfs_path_from_str (selection (current_panel)->fname);
do_edit_at_line (fname, TRUE, 0);
vfs_path_free (fname);
}
}
#endif
@ -1089,8 +1105,8 @@ unselect_cmd (void)
void
ext_cmd (void)
{
char *buffer;
char *extdir;
vfs_path_t *buffer_vpath;
vfs_path_t *extdir_vpath;
int dir;
dir = 0;
@ -1100,25 +1116,25 @@ ext_cmd (void)
_("Which extension file you want to edit?"), D_NORMAL, 2,
_("&User"), _("&System Wide"));
}
extdir = concat_dir_and_file (mc_global.sysconfig_dir, MC_LIB_EXT);
extdir_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_LIB_EXT, NULL);
if (dir == 0)
{
buffer = mc_config_get_full_path (MC_FILEBIND_FILE);
check_for_default (extdir, buffer);
do_edit (buffer);
g_free (buffer);
buffer_vpath = mc_config_get_full_vpath (MC_FILEBIND_FILE);
check_for_default (extdir_vpath, buffer_vpath);
do_edit (buffer_vpath);
vfs_path_free (buffer_vpath);
}
else if (dir == 1)
{
if (!exist_file (extdir))
if (!exist_file (vfs_path_get_last_path_str (extdir_vpath)))
{
g_free (extdir);
extdir = concat_dir_and_file (mc_global.share_data_dir, MC_LIB_EXT);
vfs_path_free (extdir_vpath);
extdir_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_LIB_EXT, NULL);
}
do_edit (extdir);
do_edit (extdir_vpath);
}
g_free (extdir);
vfs_path_free (extdir_vpath);
flush_extension_file ();
}
@ -1128,53 +1144,53 @@ ext_cmd (void)
void
edit_mc_menu_cmd (void)
{
char *buffer;
char *menufile;
vfs_path_t *buffer_vpath;
vfs_path_t *menufile_vpath;
int dir = 0;
dir = query_dialog (_("Menu edit"),
_("Which menu file do you want to edit?"),
D_NORMAL, geteuid ()? 2 : 3, _("&Local"), _("&User"), _("&System Wide"));
menufile = concat_dir_and_file (mc_global.sysconfig_dir, MC_GLOBAL_MENU);
menufile_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_MENU, NULL);
if (!exist_file (menufile))
if (!exist_file (vfs_path_get_last_path_str (menufile_vpath)))
{
g_free (menufile);
menufile = concat_dir_and_file (mc_global.share_data_dir, MC_GLOBAL_MENU);
vfs_path_free (menufile_vpath);
menufile_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_GLOBAL_MENU, NULL);
}
switch (dir)
{
case 0:
buffer = g_strdup (MC_LOCAL_MENU);
check_for_default (menufile, buffer);
chmod (buffer, 0600);
buffer_vpath = vfs_path_from_str (MC_LOCAL_MENU);
check_for_default (menufile_vpath, buffer_vpath);
chmod (vfs_path_get_last_path_str (buffer_vpath), 0600);
break;
case 1:
buffer = mc_config_get_full_path (MC_USERMENU_FILE);
check_for_default (menufile, buffer);
buffer_vpath = mc_config_get_full_vpath (MC_USERMENU_FILE);
check_for_default (menufile_vpath, buffer_vpath);
break;
case 2:
buffer = concat_dir_and_file (mc_global.sysconfig_dir, MC_GLOBAL_MENU);
if (!exist_file (buffer))
buffer_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_MENU, NULL);
if (!exist_file (vfs_path_get_last_path_str (buffer_vpath)))
{
g_free (buffer);
buffer = concat_dir_and_file (mc_global.share_data_dir, MC_GLOBAL_MENU);
vfs_path_free (buffer_vpath);
buffer_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_GLOBAL_MENU, NULL);
}
break;
default:
g_free (menufile);
vfs_path_free (menufile_vpath);
return;
}
do_edit (buffer);
do_edit (buffer_vpath);
g_free (buffer);
g_free (menufile);
vfs_path_free (buffer_vpath);
vfs_path_free (menufile_vpath);
}
/* --------------------------------------------------------------------------------------------- */
@ -1182,8 +1198,8 @@ edit_mc_menu_cmd (void)
void
edit_fhl_cmd (void)
{
char *buffer = NULL;
char *fhlfile = NULL;
vfs_path_t *buffer_vpath = NULL;
vfs_path_t *fhlfile_vpath = NULL;
int dir;
@ -1194,25 +1210,26 @@ edit_fhl_cmd (void)
_("Which highlighting file you want to edit?"), D_NORMAL, 2,
_("&User"), _("&System Wide"));
}
fhlfile = concat_dir_and_file (mc_global.sysconfig_dir, MC_FHL_INI_FILE);
fhlfile_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_FHL_INI_FILE, NULL);
if (dir == 0)
{
buffer = mc_config_get_full_path (MC_FHL_INI_FILE);
check_for_default (fhlfile, buffer);
do_edit (buffer);
g_free (buffer);
buffer_vpath = mc_config_get_full_vpath (MC_FHL_INI_FILE);
check_for_default (fhlfile_vpath, buffer_vpath);
do_edit (buffer_vpath);
vfs_path_free (buffer_vpath);
}
else if (dir == 1)
{
if (!exist_file (fhlfile))
if (!exist_file (vfs_path_get_last_path_str (fhlfile_vpath)))
{
g_free (fhlfile);
fhlfile = concat_dir_and_file (mc_global.sysconfig_dir, MC_FHL_INI_FILE);
vfs_path_free (fhlfile_vpath);
fhlfile_vpath =
vfs_path_build_filename (mc_global.sysconfig_dir, MC_FHL_INI_FILE, NULL);
}
do_edit (fhlfile);
do_edit (fhlfile_vpath);
}
g_free (fhlfile);
vfs_path_free (fhlfile_vpath);
/* refresh highlighting rules */
mc_fhl_free (&mc_filehighlight);

View File

@ -55,7 +55,7 @@ void view_cmd (void);
void view_file_cmd (void);
void view_raw_cmd (void);
void view_filtered_cmd (void);
void do_edit_at_line (const char *what, gboolean internal, int start_line);
void do_edit_at_line (const vfs_path_t * what_vpath, gboolean internal, int start_line);
void edit_cmd (void);
void edit_cmd_new (void);
#ifdef USE_INTERNAL_EDIT

View File

@ -1349,6 +1349,7 @@ find_do_view_edit (int unparsed_view, int edit, char *dir, char *file)
char *fullname = NULL;
const char *filename = NULL;
int line;
vfs_path_t *fullname_vpath;
if (content_pattern != NULL)
{
@ -1361,11 +1362,12 @@ find_do_view_edit (int unparsed_view, int edit, char *dir, char *file)
line = 0;
}
fullname = mc_build_filename (dir, filename, (char *) NULL);
fullname_vpath = vfs_path_build_filename (dir, filename, (char *) NULL);
if (edit)
do_edit_at_line (fullname, use_internal_edit, line);
do_edit_at_line (fullname_vpath, use_internal_edit, line);
else
view_file_at_line (fullname, unparsed_view, use_internal_view, line);
vfs_path_free (fullname_vpath);
g_free (fullname);
}

View File

@ -962,7 +962,13 @@ mc_maybe_editor_or_viewer (void)
{
#ifdef USE_INTERNAL_EDIT
case MC_RUN_EDITOR:
edit_file (mc_run_param0, mc_args__edit_start_line);
{
vfs_path_t *param_vpath;
param_vpath = vfs_path_from_str (mc_run_param0);
edit_file (param_vpath, mc_args__edit_start_line);
vfs_path_free (param_vpath);
}
break;
#endif /* USE_INTERNAL_EDIT */
case MC_RUN_VIEWER:

View File

@ -239,7 +239,13 @@ test_condition (WEdit * edit_widget, char *p, int *condition)
p = extract_arg (p, arg, sizeof (arg));
#ifdef USE_INTERNAL_EDIT
if (edit_widget != NULL)
*condition = mc_search (arg, edit_get_file_name (edit_widget), search_type) ? 1 : 0;
{
char *edit_filename;
edit_filename = edit_get_file_name (edit_widget);
*condition = mc_search (arg, edit_filename, search_type) ? 1 : 0;
g_free (edit_filename);
}
else
#endif
*condition = panel != NULL &&
@ -752,11 +758,11 @@ expand_format (struct WEdit *edit_widget, char c, gboolean do_quote)
return g_strdup ("");
panel = other_panel;
}
fname = panel->dir.list[panel->selected].fname;
fname = g_strdup (panel->dir.list[panel->selected].fname);
}
#ifdef USE_INTERNAL_EDIT
else if (mc_global.mc_run_mode == MC_RUN_EDITOR)
fname = (char *) edit_get_file_name (edit_widget);
fname = edit_get_file_name (edit_widget);
#endif
if (do_quote)
@ -770,9 +776,11 @@ expand_format (struct WEdit *edit_widget, char c, gboolean do_quote)
{
case 'f':
case 'p':
return (*quote_func) (fname, 0);
result = (*quote_func) (fname, 0);
goto ret;
case 'x':
return (*quote_func) (extension (fname), 0);
result = (*quote_func) (extension (fname), 0);
goto ret;
case 'd':
{
char *cwd;
@ -787,12 +795,16 @@ expand_format (struct WEdit *edit_widget, char c, gboolean do_quote)
g_free (cwd);
return qstr;
result = qstr;
goto ret;
}
case 'i': /* indent equal number cursor position in line */
#ifdef USE_INTERNAL_EDIT
if (edit_widget)
return g_strnfill (edit_get_curs_col (edit_widget), ' ');
{
result = g_strnfill (edit_get_curs_col (edit_widget), ' ');
goto ret;
}
#endif
break;
case 'y': /* syntax type */
@ -801,7 +813,10 @@ expand_format (struct WEdit *edit_widget, char c, gboolean do_quote)
{
const char *syntax_type = edit_get_syntax_type (edit_widget);
if (syntax_type != NULL)
return g_strdup (syntax_type);
{
result = g_strdup (syntax_type);
goto ret;
}
}
#endif
break;
@ -811,29 +826,43 @@ expand_format (struct WEdit *edit_widget, char c, gboolean do_quote)
#ifdef USE_INTERNAL_EDIT
if (edit_widget)
{
char *file = mc_config_get_full_path (EDIT_BLOCK_FILE);
fname = (*quote_func) (file, 0);
char *file;
file = mc_config_get_full_path (EDIT_BLOCK_FILE);
result = (*quote_func) (file, 0);
g_free (file);
return fname;
goto ret;
}
#endif
if (c_lc == 'b')
return strip_ext ((*quote_func) (fname, 0));
{
result = strip_ext ((*quote_func) (fname, 0));
goto ret;
}
break;
}
case 'n': /* strip extension in editor */
#ifdef USE_INTERNAL_EDIT
if (edit_widget)
return strip_ext ((*quote_func) (fname, 0));
{
result = strip_ext ((*quote_func) (fname, 0));
goto ret;
}
#endif
break;
case 'm': /* menu file name */
if (menu)
return (*quote_func) (menu, 0);
{
result = (*quote_func) (menu, 0);
goto ret;
}
break;
case 's':
if (!panel || !panel->marked)
return (*quote_func) (fname, 0);
{
result = (*quote_func) (fname, 0);
goto ret;
}
/* Fall through */
@ -844,7 +873,10 @@ expand_format (struct WEdit *edit_widget, char c, gboolean do_quote)
char *block, *tmp;
if (!panel)
return g_strdup ("");
{
result = g_strdup ("");
goto ret;
}
for (i = 0; i < panel->count; i++)
if (panel->dir.list[i].f.marked)
@ -862,11 +894,14 @@ expand_format (struct WEdit *edit_widget, char c, gboolean do_quote)
if (c_lc == 'u')
do_file_mark (panel, i, 0);
}
return block;
result = block;
goto ret;
} /* sub case block */
} /* switch */
result = g_strdup ("% ");
result[1] = c;
ret:
g_free (fname);
return result;
}

View File

@ -49,15 +49,24 @@
/* --------------------------------------------------------------------------------------------- */
int
check_for_default (const char *default_file, const char *file)
check_for_default (const vfs_path_t * default_file_vpath, const vfs_path_t * file_vpath)
{
char *file, *default_file;
file = vfs_path_to_str (file_vpath);
default_file = vfs_path_to_str (default_file_vpath);
if (!exist_file (file))
{
FileOpContext *ctx;
FileOpTotalContext *tctx;
if (!exist_file (default_file))
{
g_free (file);
g_free (default_file);
return -1;
}
ctx = file_op_context_new (OP_COPY);
tctx = file_op_total_context_new ();
@ -66,6 +75,8 @@ check_for_default (const char *default_file, const char *file)
file_op_total_context_destroy (tctx);
file_op_context_destroy (ctx);
}
g_free (file);
g_free (default_file);
return 0;
}

View File

@ -12,9 +12,8 @@
/*** declarations of public functions ************************************************************/
/* Check if the file exists. If not copy the default */
int check_for_default (const char *default_file, const char *file);
int check_for_default (const vfs_path_t * default_file_vpath, const vfs_path_t * file_vpath);
/*** inline functions ****************************************************************************/
#endif /* MC_SRC_UTIL_H */

View File

@ -234,15 +234,13 @@ mcview_done (mcview_t * view)
/* Save current file position */
if (mcview_remember_file_position && view->filename != NULL)
{
char *canon_fname;
vfs_path_t *vpath;
vpath = vfs_path_from_str (view->filename);
canon_fname = vfs_path_to_str (vpath);
save_file_position (canon_fname, -1, 0,
save_file_position (vpath, -1, 0,
view->hex_mode ? view->hex_cursor : view->dpy_start,
view->saved_bookmarks);
view->saved_bookmarks = NULL;
g_free (canon_fname);
vfs_path_free (vpath);
}

View File

@ -385,14 +385,12 @@ mcview_load (mcview_t * view, const char *command, const char *file, int start_l
if (mcview_remember_file_position && view->filename != NULL && start_line == 0)
{
char *canon_fname;
long line, col;
off_t new_offset, max_offset;
vfs_path_t *tmp_vpath;
tmp_vpath = vfs_path_from_str (view->filename);
canon_fname = vfs_path_to_str (tmp_vpath);
load_file_position (canon_fname, &line, &col, &new_offset, &view->saved_bookmarks);
load_file_position (tmp_vpath, &line, &col, &new_offset, &view->saved_bookmarks);
max_offset = mcview_get_filesize (view) - 1;
if (max_offset < 0)
new_offset = 0;
@ -405,7 +403,6 @@ mcview_load (mcview_t * view, const char *command, const char *file, int start_l
view->dpy_start = new_offset - new_offset % view->bytes_per_line;
view->hex_cursor = new_offset;
}
g_free (canon_fname);
vfs_path_free (tmp_vpath);
}
else if (start_line > 0)