Remove #ifdefs TEMPDIRNAMES and add TEMPDIRNAMES for Windows

Vim does not define TEMPDIRNAMES for all systems, but it is defined for
all systems supported by Neovim.
Temporary directory names for Windows was obtained from GetTempPath()
function documentation at MSDN.
Additionally small renamings were performed.
This commit is contained in:
Pavel Platto 2014-06-19 00:58:04 +03:00 committed by Nicolas Hillegeer
parent ed10eb6fa9
commit edd7a8c5dd
8 changed files with 28 additions and 35 deletions

View File

@ -893,15 +893,11 @@ void ex_diffpatch(exarg_T *eap)
|| (os_chdir((char *)dirbuf) != 0)) { || (os_chdir((char *)dirbuf) != 0)) {
dirbuf[0] = NUL; dirbuf[0] = NUL;
} else { } else {
# ifdef TEMPDIRNAMES
if (vim_tempdir != NULL) { if (vim_tempdir != NULL) {
ignored = os_chdir((char *)vim_tempdir); ignored = os_chdir((char *)vim_tempdir);
} else { } else {
ignored = os_chdir("/tmp"); ignored = os_chdir("/tmp");
} }
# else
ignored = os_chdir("/tmp");
# endif // ifdef TEMPDIRNAMES
shorten_fnames(TRUE); shorten_fnames(TRUE);
} }
#endif // ifdef UNIX #endif // ifdef UNIX

View File

@ -5156,7 +5156,6 @@ void write_lnum_adjust(linenr_T offset)
curbuf->b_no_eol_lnum += offset; curbuf->b_no_eol_lnum += offset;
} }
#if defined(TEMPDIRNAMES) || defined(PROTO)
static long temp_count = 0; /* Temp filename counter. */ static long temp_count = 0; /* Temp filename counter. */
/* /*
@ -5184,9 +5183,6 @@ void vim_deltempdir(void)
} }
} }
#endif
#ifdef TEMPDIRNAMES
/* /*
* Directory "tempdir" was created. Expand this name to a full path and put * Directory "tempdir" was created. Expand this name to a full path and put
* it in "vim_tempdir". This avoids that using ":cd" would confuse us. * it in "vim_tempdir". This avoids that using ":cd" would confuse us.
@ -5203,7 +5199,6 @@ static void vim_settempdir(char_u *tempdir)
free(buf); free(buf);
} }
} }
#endif
/* /*
* vim_tempname(): Return a unique name that can be used for a temp file. * vim_tempname(): Return a unique name that can be used for a temp file.
@ -5218,10 +5213,9 @@ vim_tempname (
int extra_char /* char to use in the name instead of '?' */ int extra_char /* char to use in the name instead of '?' */
) )
{ {
char_u itmp[TEMPNAMELEN]; char_u itmp[TEMP_FILE_PATH_MAXLEN];
#ifdef TEMPDIRNAMES static const char *temp_dirs[] = TEMP_DIR_NAMES;
static char *(tempdirs[]) = {TEMPDIRNAMES};
int i; int i;
/* /*
@ -5233,11 +5227,11 @@ vim_tempname (
*/ */
if (vim_tempdir == NULL) { if (vim_tempdir == NULL) {
/* /*
* Try the entries in TEMPDIRNAMES to create the temp directory. * Try the entries in `TEMP_DIR_NAMES` to create the temp directory.
*/ */
for (i = 0; i < (int)(sizeof(tempdirs) / sizeof(char *)); ++i) { for (i = 0; i < (int)(sizeof(temp_dirs) / sizeof(char *)); ++i) {
/* expand $TMP, leave room for "/v1100000/999999999" */ /* expand $TMP, leave room for "/v1100000/999999999" */
expand_env((char_u *)tempdirs[i], itmp, TEMPNAMELEN - 20); expand_env((char_u *)temp_dirs[i], itmp, TEMP_FILE_PATH_MAXLEN - 20);
if (os_isdir(itmp)) { /* directory exists */ if (os_isdir(itmp)) { /* directory exists */
add_pathsep(itmp); add_pathsep(itmp);
@ -5259,19 +5253,6 @@ vim_tempname (
} }
return NULL; return NULL;
#else /* TEMPDIRNAMES */
char_u *p;
STRCPY(itmp, TEMPNAME);
if ((p = vim_strchr(itmp, '?')) != NULL)
*p = extra_char;
if (mktemp((char *)itmp) == NULL)
return NULL;
return vim_strsave(itmp);
#endif /* TEMPDIRNAMES */
} }
#if defined(BACKSLASH_IN_FILENAME) || defined(PROTO) #if defined(BACKSLASH_IN_FILENAME) || defined(PROTO)

View File

@ -536,10 +536,8 @@ EXTERN int ru_col; /* column for ruler */
EXTERN int ru_wid; /* 'rulerfmt' width of ruler when non-zero */ EXTERN int ru_wid; /* 'rulerfmt' width of ruler when non-zero */
EXTERN int sc_col; /* column for shown command */ EXTERN int sc_col; /* column for shown command */
#ifdef TEMPDIRNAMES
EXTERN char_u *vim_tempdir INIT(= NULL); /* Name of Vim's own temp dir. EXTERN char_u *vim_tempdir INIT(= NULL); /* Name of Vim's own temp dir.
Ends in a slash. */ Ends in a slash. */
#endif
/* /*
* When starting or exiting some things are done differently (e.g. screen * When starting or exiting some things are done differently (e.g. screen

View File

@ -589,9 +589,7 @@ void ml_close_all(int del_file)
ml_close(buf, del_file && ((buf->b_flags & BF_PRESERVED) == 0 ml_close(buf, del_file && ((buf->b_flags & BF_PRESERVED) == 0
|| vim_strchr(p_cpo, CPO_PRESERVE) == NULL)); || vim_strchr(p_cpo, CPO_PRESERVE) == NULL));
spell_delete_wordlist(); /* delete the internal wordlist */ spell_delete_wordlist(); /* delete the internal wordlist */
#ifdef TEMPDIRNAMES
vim_deltempdir(); /* delete created temp directory */ vim_deltempdir(); /* delete created temp directory */
#endif
} }
/* /*

View File

@ -7,10 +7,17 @@
#include "nvim/os/fs_defs.h" #include "nvim/os/fs_defs.h"
#include "nvim/vim.h" #include "nvim/vim.h"
#ifdef WIN32
# include "nvim/os/win_defs.h"
#else
# include "nvim/os/unix_defs.h"
#endif
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
# include "os/fs.h.generated.h" # include "os/fs.h.generated.h"
# include "os/mem.h.generated.h" # include "os/mem.h.generated.h"
# include "os/env.h.generated.h" # include "os/env.h.generated.h"
# include "os/users.h.generated.h" # include "os/users.h.generated.h"
#endif #endif
#endif // NVIM_OS_OS_H #endif // NVIM_OS_OS_H

7
src/nvim/os/unix_defs.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef NEOVIM_OS_UNIX_DEFS_H
#define NEOVIM_OS_UNIX_DEFS_H
#define TEMP_DIR_NAMES {"$TMPDIR", "/tmp", ".", "$HOME"}
#define TEMP_FILE_PATH_MAXLEN 256
#endif // NEOVIM_OS_UNIX_DEFS_H

9
src/nvim/os/win_defs.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef NEOVIM_OS_WIN_DEFS_H
#define NEOVIM_OS_WIN_DEFS_H
#include <windows.h>
#define TEMP_DIR_NAMES {"$TMP", "$TEMP", "$USERPROFILE", ""}
#define TEMP_FILE_PATH_MAXLEN _MAX_PATH
#endif // NEOVIM_OS_WIN_DEFS_H

View File

@ -204,9 +204,6 @@
"~/.nvim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,~/.nvim/after" "~/.nvim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,~/.nvim/after"
# endif # endif
# define TEMPDIRNAMES "$TMPDIR", "/tmp", ".", "$HOME"
# define TEMPNAMELEN 256
/* Special wildcards that need to be handled by the shell */ /* Special wildcards that need to be handled by the shell */
#define SPECIAL_WILDCHAR "`'{" #define SPECIAL_WILDCHAR "`'{"