diff options
Diffstat (limited to 'src/nvim/ex_session.c')
-rw-r--r-- | src/nvim/ex_session.c | 56 |
1 files changed, 30 insertions, 26 deletions
diff --git a/src/nvim/ex_session.c b/src/nvim/ex_session.c index e907c45e79..cae9c18309 100644 --- a/src/nvim/ex_session.c +++ b/src/nvim/ex_session.c @@ -9,32 +9,36 @@ #include <assert.h> #include <inttypes.h> +#include <limits.h> #include <stdbool.h> -#include <stdlib.h> +#include <stdio.h> #include <string.h> #include "nvim/arglist.h" #include "nvim/ascii.h" #include "nvim/buffer.h" -#include "nvim/cursor.h" -#include "nvim/edit.h" #include "nvim/eval.h" +#include "nvim/ex_cmds_defs.h" #include "nvim/ex_docmd.h" #include "nvim/ex_getln.h" #include "nvim/ex_session.h" #include "nvim/file_search.h" #include "nvim/fileio.h" #include "nvim/fold.h" +#include "nvim/garray.h" +#include "nvim/gettext.h" #include "nvim/globals.h" -#include "nvim/keycodes.h" +#include "nvim/macros.h" #include "nvim/mapping.h" -#include "nvim/move.h" +#include "nvim/mark_defs.h" +#include "nvim/memory.h" +#include "nvim/message.h" #include "nvim/option.h" -#include "nvim/os/input.h" #include "nvim/os/os.h" -#include "nvim/os/time.h" #include "nvim/path.h" +#include "nvim/pos.h" #include "nvim/runtime.h" +#include "nvim/types.h" #include "nvim/vim.h" #include "nvim/window.h" @@ -211,22 +215,22 @@ static int ses_do_win(win_T *wp) /// @returns FAIL if writing fails. static int ses_arglist(FILE *fd, char *cmd, garray_T *gap, int fullname, unsigned *flagp) { - char_u *buf = NULL; - char_u *s; + char *buf = NULL; + char *s; if (fprintf(fd, "%s\n%s\n", cmd, "%argdel") < 0) { return FAIL; } for (int i = 0; i < gap->ga_len; i++) { // NULL file names are skipped (only happens when out of memory). - s = (char_u *)alist_name(&((aentry_T *)gap->ga_data)[i]); + s = alist_name(&((aentry_T *)gap->ga_data)[i]); if (s != NULL) { if (fullname) { buf = xmalloc(MAXPATHL); - (void)vim_FullName((char *)s, (char *)buf, MAXPATHL, false); + (void)vim_FullName(s, buf, MAXPATHL, false); s = buf; } - char *fname_esc = ses_escape_fname((char *)s, flagp); + char *fname_esc = ses_escape_fname(s, flagp); if (fprintf(fd, "$argadd %s\n", fname_esc) < 0) { xfree(fname_esc); xfree(buf); @@ -240,7 +244,7 @@ static int ses_arglist(FILE *fd, char *cmd, garray_T *gap, int fullname, unsigne } /// @return the buffer name for `buf`. -static char *ses_get_fname(buf_T *buf, unsigned *flagp) +static char *ses_get_fname(buf_T *buf, const unsigned *flagp) { // Use the short file name if the current directory is known at the time // the session file will be sourced. @@ -264,7 +268,7 @@ static char *ses_get_fname(buf_T *buf, unsigned *flagp) static int ses_fname(FILE *fd, buf_T *buf, unsigned *flagp, bool add_eol) { char *name = ses_get_fname(buf, flagp); - if (ses_put_fname(fd, (char_u *)name, flagp) == FAIL + if (ses_put_fname(fd, name, flagp) == FAIL || (add_eol && fprintf(fd, "\n") < 0)) { return FAIL; } @@ -299,9 +303,9 @@ static char *ses_escape_fname(char *name, unsigned *flagp) /// characters. /// /// @return FAIL if writing fails. -static int ses_put_fname(FILE *fd, char_u *name, unsigned *flagp) +static int ses_put_fname(FILE *fd, char *name, unsigned *flagp) { - char *p = ses_escape_fname((char *)name, flagp); + char *p = ses_escape_fname(name, flagp); bool retval = fputs(p, fd) < 0 ? FAIL : OK; xfree(p); return retval; @@ -523,7 +527,7 @@ static int put_view(FILE *fd, win_T *wp, int add_edit, unsigned *flagp, int curr if (wp->w_localdir != NULL && (flagp != &vop_flags || (*flagp & SSOP_CURDIR))) { if (fputs("lcd ", fd) < 0 - || ses_put_fname(fd, (char_u *)wp->w_localdir, flagp) == FAIL + || ses_put_fname(fd, wp->w_localdir, flagp) == FAIL || fprintf(fd, "\n") < 0) { return FAIL; } @@ -542,7 +546,7 @@ static int put_view(FILE *fd, win_T *wp, int add_edit, unsigned *flagp, int curr /// @param fd File descriptor to write to /// /// @return FAIL on error, OK otherwise. -static int makeopens(FILE *fd, char_u *dirnow) +static int makeopens(FILE *fd, char *dirnow) { int only_save_windows = true; int nr; @@ -581,7 +585,7 @@ static int makeopens(FILE *fd, char_u *dirnow) if (ssop_flags & SSOP_SESDIR) { PUTLINE_FAIL("exe \"cd \" . escape(expand(\"<sfile>:p:h\"), ' ')"); } else if (ssop_flags & SSOP_CURDIR) { - sname = home_replace_save(NULL, globaldir != NULL ? globaldir : (char *)dirnow); + sname = home_replace_save(NULL, globaldir != NULL ? globaldir : dirnow); char *fname_esc = ses_escape_fname(sname, &ssop_flags); if (fprintf(fd, "cd %s\n", fname_esc) < 0) { xfree(fname_esc); @@ -828,7 +832,7 @@ static int makeopens(FILE *fd, char_u *dirnow) // Take care of tab-local working directories if applicable if (tp->tp_localdir) { if (fputs("if exists(':tcd') == 2 | tcd ", fd) < 0 - || ses_put_fname(fd, (char_u *)tp->tp_localdir, &ssop_flags) == FAIL + || ses_put_fname(fd, tp->tp_localdir, &ssop_flags) == FAIL || fputs(" | endif\n", fd) < 0) { return FAIL; } @@ -956,11 +960,11 @@ void ex_mkrc(exarg_T *eap) } // When using 'viewdir' may have to create the directory. - if (using_vdir && !os_isdir((char *)p_vdir)) { + if (using_vdir && !os_isdir(p_vdir)) { vim_mkdir_emsg((const char *)p_vdir, 0755); } - fd = open_exfile((char_u *)fname, eap->forceit, WRITEBIN); + fd = open_exfile(fname, eap->forceit, WRITEBIN); if (fd != NULL) { if (eap->cmdidx == CMD_mkview) { flagp = &vop_flags; @@ -997,14 +1001,14 @@ void ex_mkrc(exarg_T *eap) failed = true; } if (eap->cmdidx == CMD_mksession) { - char_u *dirnow; // current directory + char *dirnow; // current directory dirnow = xmalloc(MAXPATHL); // // Change to session file's dir. // if (os_dirname(dirnow, MAXPATHL) == FAIL - || os_chdir((char *)dirnow) != 0) { + || os_chdir(dirnow) != 0) { *dirnow = NUL; } if (*dirnow != NUL && (ssop_flags & SSOP_SESDIR)) { @@ -1024,7 +1028,7 @@ void ex_mkrc(exarg_T *eap) if (*dirnow != NUL && ((ssop_flags & SSOP_SESDIR) || ((ssop_flags & SSOP_CURDIR) && globaldir != NULL))) { - if (os_chdir((char *)dirnow) != 0) { + if (os_chdir(dirnow) != 0) { emsg(_(e_prev_dir)); } shorten_fnames(true); @@ -1095,7 +1099,7 @@ static char *get_view_file(int c) len++; } } - char *retval = xmalloc(strlen(sname) + len + STRLEN(p_vdir) + 9); + char *retval = xmalloc(strlen(sname) + len + strlen(p_vdir) + 9); STRCPY(retval, p_vdir); add_pathsep(retval); char *s = retval + strlen(retval); |