mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-31 05:00:35 +00:00
Move expand_squiggle() from quakefs to sys, and rename to Sys_ExpandSquiggle.
Hopefully the final resting place of this function.
This commit is contained in:
parent
e9bd9a4baa
commit
42faad9015
5 changed files with 53 additions and 53 deletions
|
@ -384,21 +384,6 @@ void QFS_FilelistFill (filelist_t *list, const char *path, const char *ext,
|
|||
*/
|
||||
void QFS_FilelistFree (filelist_t *list);
|
||||
|
||||
|
||||
/** Expand leading "~/" in \a path to the user's home directory.
|
||||
On Linux-like systems, the user's home directory is obtained from the
|
||||
system, or failing that, the \c HOME environment variable.
|
||||
|
||||
On Windows systems, first the \c HOME environment variable is checked.
|
||||
If \c HOME is not set, \c WINDIR is used.
|
||||
|
||||
\param path the path to check for "~/"
|
||||
\return the expanded path
|
||||
\note It is the caller's responsibility to free the returned string.
|
||||
FIXME: rename to QFS_*
|
||||
*/
|
||||
char *expand_squiggle (const char *path);
|
||||
|
||||
//@}
|
||||
|
||||
#endif // __quakefs_h
|
||||
|
|
|
@ -125,4 +125,18 @@ int Sys_CreatePath (const char *path);
|
|||
|
||||
//@}
|
||||
|
||||
/** Expand leading "~/" in \a path to the user's home directory.
|
||||
On Linux-like systems, the user's home directory is obtained from the
|
||||
system, or failing that, the \c HOME environment variable.
|
||||
|
||||
On Windows systems, first the \c HOME environment variable is checked.
|
||||
If \c HOME is not set, \c WINDIR is used.
|
||||
|
||||
\param path the path to check for "~/"
|
||||
\return the expanded path
|
||||
\note It is the caller's responsibility to free the returned string.
|
||||
*/
|
||||
char *Sys_ExpandSquiggle (const char *path);
|
||||
|
||||
//@}
|
||||
#endif // __sys_h
|
||||
|
|
|
@ -649,7 +649,7 @@ Cmd_Exec_File (cbuf_t *cbuf, const char *path, int qfs)
|
|||
if (qfs) {
|
||||
QFS_FOpenFile (path, &file);
|
||||
} else {
|
||||
char *newpath = expand_squiggle (path);
|
||||
char *newpath = Sys_ExpandSquiggle (path);
|
||||
file = Qopen (newpath, "r");
|
||||
free (newpath);
|
||||
}
|
||||
|
|
|
@ -43,9 +43,6 @@ static __attribute__ ((used)) const char rcsid[] =
|
|||
#ifdef HAVE_IO_H
|
||||
# include <io.h>
|
||||
#endif
|
||||
#ifdef HAVE_PWD_H
|
||||
# include <pwd.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_MALLOC_H
|
||||
#include <malloc.h>
|
||||
|
@ -576,7 +573,7 @@ qfs_load_config (void)
|
|||
char *dirconf;
|
||||
|
||||
if (*fs_dirconf->string) {
|
||||
dirconf = expand_squiggle (fs_dirconf->string);
|
||||
dirconf = Sys_ExpandSquiggle (fs_dirconf->string);
|
||||
if (!(f = Qopen (dirconf, "rt")))
|
||||
Sys_DPrintf ("Could not load `%s', using builtin defaults\n",
|
||||
dirconf);
|
||||
|
@ -1246,38 +1243,6 @@ QFS_GamedirCallback (gamedir_callback_t *func)
|
|||
num_gamedir_callbacks++;
|
||||
}
|
||||
|
||||
char *
|
||||
expand_squiggle (const char *path)
|
||||
{
|
||||
char *home;
|
||||
|
||||
#ifndef _WIN32
|
||||
struct passwd *pwd_ent;
|
||||
#endif
|
||||
|
||||
if (strncmp (path, "~/", 2) != 0) {
|
||||
return strdup (path);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
// LordHavoc: first check HOME to duplicate previous version behavior
|
||||
// (also handy if someone wants it elsewhere than their windows directory)
|
||||
home = getenv ("HOME");
|
||||
if (!home || !home[0])
|
||||
home = getenv ("WINDIR");
|
||||
#else
|
||||
if ((pwd_ent = getpwuid (getuid ()))) {
|
||||
home = pwd_ent->pw_dir;
|
||||
} else
|
||||
home = getenv ("HOME");
|
||||
#endif
|
||||
|
||||
if (home)
|
||||
return nva ("%s%s", home, path + 1); // skip leading ~
|
||||
|
||||
return strdup (path);
|
||||
}
|
||||
|
||||
static void
|
||||
qfs_path_cvar (cvar_t *var)
|
||||
{
|
||||
|
@ -1304,7 +1269,7 @@ QFS_Init (const char *game)
|
|||
|
||||
Cmd_AddCommand ("path", qfs_path_f, "Show what paths Quake is using");
|
||||
|
||||
qfs_userpath = expand_squiggle (fs_userpath->string);
|
||||
qfs_userpath = Sys_ExpandSquiggle (fs_userpath->string);
|
||||
|
||||
qfs_load_config ();
|
||||
|
||||
|
|
|
@ -55,6 +55,9 @@ static __attribute__ ((used)) const char rcsid[] =
|
|||
#ifdef HAVE_SYS_MMAN_H
|
||||
# include <sys/mman.h>
|
||||
#endif
|
||||
#ifdef HAVE_PWD_H
|
||||
# include <pwd.h>
|
||||
#endif
|
||||
|
||||
#include <signal.h>
|
||||
#include <setjmp.h>
|
||||
|
@ -76,6 +79,7 @@ static __attribute__ ((used)) const char rcsid[] =
|
|||
#include "QF/dstring.h"
|
||||
#include "QF/sys.h"
|
||||
#include "QF/quakefs.h"
|
||||
#include "QF/va.h"
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
|
@ -775,3 +779,35 @@ Sys_CreatePath (const char *path)
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *
|
||||
Sys_ExpandSquiggle (const char *path)
|
||||
{
|
||||
char *home;
|
||||
|
||||
#ifndef _WIN32
|
||||
struct passwd *pwd_ent;
|
||||
#endif
|
||||
|
||||
if (strncmp (path, "~/", 2) != 0) {
|
||||
return strdup (path);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
// LordHavoc: first check HOME to duplicate previous version behavior
|
||||
// (also handy if someone wants it elsewhere than their windows directory)
|
||||
home = getenv ("HOME");
|
||||
if (!home || !home[0])
|
||||
home = getenv ("WINDIR");
|
||||
#else
|
||||
if ((pwd_ent = getpwuid (getuid ()))) {
|
||||
home = pwd_ent->pw_dir;
|
||||
} else
|
||||
home = getenv ("HOME");
|
||||
#endif
|
||||
|
||||
if (home)
|
||||
return nva ("%s%s", home, path + 1); // skip leading ~
|
||||
|
||||
return strdup (path);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue