Blender  V2.59
Defines | Functions | Variables
path_util.c File Reference
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include "MEM_guardedalloc.h"
#include "DNA_userdef_types.h"
#include "BLI_fileops.h"
#include "BLI_path_util.h"
#include "BLI_string.h"
#include "BLI_storage.h"
#include "BLI_storage_types.h"
#include "BLI_utildefines.h"
#include "BKE_utildefines.h"
#include "BKE_blender.h"
#include "GHOST_Path-api.h"
#include <fnmatch.h>

Go to the source code of this file.

Defines

#define _GNU_SOURCE
#define UNIQUE_NAME_MAX   128
#define GIVE_STRADDR(data, offset)   ( ((char *)data) + offset )

Functions

static int add_win32_extension (char *name)
static char * blender_version_decimal (const int ver)
int BLI_stringdec (const char *string, char *head, char *tail, unsigned short *numlen)
void BLI_stringenc (char *string, const char *head, const char *tail, unsigned short numlen, int pic)
int BLI_split_name_num (char *left, int *nr, const char *name, const char delim)
void BLI_newname (char *name, int add)
int BLI_uniquename_cb (int(*unique_check)(void *, const char *), void *arg, const char defname[], char delim, char *name, short name_len)
static int uniquename_find_dupe (ListBase *list, void *vlink, const char *name, short name_offs)
static int uniquename_unique_check (void *arg, const char *name)
void BLI_uniquename (ListBase *list, void *vlink, const char defname[], char delim, short name_offs, short name_len)
void BLI_cleanup_path (const char *relabase, char *dir)
void BLI_cleanup_dir (const char *relabase, char *dir)
void BLI_cleanup_file (const char *relabase, char *dir)
void BLI_path_rel (char *file, const char *relfile)
int BLI_has_parent (char *path)
int BLI_parent_dir (char *path)
static int stringframe_chars (char *path, int *char_start, int *char_end)
static void ensure_digits (char *path, int digits)
int BLI_path_frame (char *path, int frame, int digits)
int BLI_path_frame_range (char *path, int sta, int end, int digits)
int BLI_path_abs (char *path, const char *basepath)
int BLI_path_cwd (char *path)
void BLI_splitdirstring (char *di, char *fi)
void BLI_getlastdir (const char *dir, char *last, const size_t maxlen)
const char * BLI_getDefaultDocumentFolder (void)
static int test_path (char *targetpath, const char *path_base, const char *path_sep, const char *folder_name)
static int test_env_path (char *path, const char *envvar)
static int get_path_local (char *targetpath, const char *folder_name, const char *subfolder_name, const int ver)
static int is_portable_install (void)
static int get_path_user (char *targetpath, const char *folder_name, const char *subfolder_name, const char *envvar, const int ver)
static int get_path_system (char *targetpath, const char *folder_name, const char *subfolder_name, const char *envvar, const int ver)
char * BLI_get_folder (int folder_id, const char *subfolder)
char * BLI_get_user_folder_notest (int folder_id, const char *subfolder)
char * BLI_get_folder_create (int folder_id, const char *subfolder)
char * BLI_get_folder_version (const int id, const int ver, const int do_check)
void BLI_setenv (const char *env, const char *val)
void BLI_setenv_if_new (const char *env, const char *val)
void BLI_clean (char *path)
void BLI_char_switch (char *string, char from, char to)
void BLI_make_exist (char *dir)
void BLI_make_existing_file (const char *name)
void BLI_make_file_string (const char *relabase, char *string, const char *dir, const char *file)
int BLI_testextensie (const char *str, const char *ext)
int BLI_testextensie_array (const char *str, const char **ext_array)
int BLI_testextensie_glob (const char *str, const char *ext_fnmatch)
int BLI_replace_extension (char *path, size_t maxlen, const char *ext)
void BLI_split_dirfile (const char *string, char *dir, char *file)
void BLI_join_dirfile (char *string, const size_t maxlen, const char *dir, const char *file)
char * BLI_path_basename (char *path)
int BKE_rebase_path (char *abs, size_t abs_len, char *rel, size_t rel_len, const char *base_dir, const char *src_dir, const char *dest_dir)
char * BLI_first_slash (char *string)
char * BLI_last_slash (const char *string)
int BLI_add_slash (char *string)
void BLI_del_slash (char *string)
void BLI_where_am_i (char *fullname, const size_t maxlen, const char *name)
void BLI_where_is_temp (char *fullname, const size_t maxlen, int usertemp)

Variables

char bprogname []

Detailed Description

Definition in file path_util.c.


Define Documentation

#define _GNU_SOURCE

Definition at line 62 of file path_util.c.

#define GIVE_STRADDR (   data,
  offset 
)    ( ((char *)data) + offset )

Definition at line 237 of file path_util.c.

Referenced by BLI_uniquename(), and uniquename_find_dupe().

#define UNIQUE_NAME_MAX   128

Definition at line 88 of file path_util.c.

Referenced by BLI_newname(), BLI_uniquename(), and BLI_uniquename_cb().


Function Documentation

static int add_win32_extension ( char *  name) [static]

Definition at line 1615 of file path_util.c.

References BLI_exist(), FILE_MAXDIR, and FILE_MAXFILE.

Referenced by BLI_where_am_i().

int BKE_rebase_path ( char *  abs,
size_t  abs_len,
char *  rel,
size_t  rel_len,
const char *  base_dir,
const char *  src_dir,
const char *  dest_dir 
)
static char * blender_version_decimal ( const int  ver) [static]

Definition at line 826 of file path_util.c.

Referenced by get_path_local(), get_path_system(), and get_path_user().

int BLI_add_slash ( char *  string)
void BLI_char_switch ( char *  string,
char  from,
char  to 
)

Change every from in string into to. The result will be in string

string The string to work on from The character to replace to The character to replace with

Definition at line 1200 of file path_util.c.

References NULL.

Referenced by BLI_clean(), BLI_make_exist(), BLI_path_abs(), BLI_path_rel(), and uri_from_filename().

void BLI_clean ( char *  path)

Definition at line 1187 of file path_util.c.

References BLI_char_switch(), BLI_strnlen(), and NULL.

Referenced by BLI_has_parent(), BLI_make_file_string(), and clean_paths().

void BLI_cleanup_dir ( const char *  relabase,
char *  dir 
)
void BLI_cleanup_file ( const char *  relabase,
char *  dir 
)

dir can be any input, like from buttons, and this function converts it to a regular full path. Also removes garbage from directory paths, like /../ or double slashes etc

Definition at line 401 of file path_util.c.

References BLI_cleanup_path(), and BLI_del_slash().

Referenced by BLI_bpathIterator_getPathExpanded(), makeFilesAbsolute(), and makeFilesRelative().

void BLI_cleanup_path ( const char *  relabase,
char *  dir 
)

Definition at line 299 of file path_util.c.

References BLI_path_abs().

Referenced by BLI_cleanup_dir(), BLI_cleanup_file(), BLI_path_abs(), and BLI_path_rel().

void BLI_del_slash ( char *  string)

Definition at line 1599 of file path_util.c.

Referenced by BLI_cleanup_file(), and file_panel_category().

char* BLI_first_slash ( char *  string)

Definition at line 1553 of file path_util.c.

char* BLI_get_folder ( int  folder_id,
const char *  subfolder 
)
char* BLI_get_folder_create ( int  folder_id,
const char *  subfolder 
)
char* BLI_get_folder_version ( const int  id,
const int  ver,
const int  do_check 
)
char* BLI_get_user_folder_notest ( int  folder_id,
const char *  subfolder 
)
const char* BLI_getDefaultDocumentFolder ( void  )

Definition at line 788 of file path_util.c.

References BLI_is_dir(), HRESULT, NULL, and S_OK.

Referenced by file_expand_directory().

void BLI_getlastdir ( const char *  dir,
char *  last,
const size_t  maxlen 
)

Definition at line 766 of file path_util.c.

References BLI_strncpy(), and NULL.

Referenced by file_panel_category().

int BLI_has_parent ( char *  path)

Definition at line 505 of file path_util.c.

References BLI_add_slash(), and BLI_clean().

Referenced by file_parent_exec().

void BLI_join_dirfile ( char *  string,
const size_t  maxlen,
const char *  dir,
const char *  file 
)
char* BLI_last_slash ( const char *  string)
void BLI_make_exist ( char *  dir)

Definition at line 1209 of file path_util.c.

References ALTSEP, BLI_char_switch(), BLI_is_dir(), and SEP.

Referenced by filelist_parent(), and filelist_read_library().

void BLI_make_existing_file ( const char *  name)
void BLI_make_file_string ( const char *  relabase,
char *  string,
const char *  dir,
const char *  file 
)
void BLI_newname ( char *  name,
int  add 
)

Definition at line 183 of file path_util.c.

References add(), BLI_stringdec(), BLI_stringenc(), KDL::exp(), i, and UNIQUE_NAME_MAX.

Referenced by file_filenum_exec(), and make_unique_prop_names().

int BLI_parent_dir ( char *  path)
int BLI_path_abs ( char *  path,
const char *  basepath 
)

Blender's path code replacement function. Bases path strings leading with "//" by the directory basepath, and replaces instances of '#' with the framenum. Results are written back into path.

path The path to convert basepath The directory to base relative paths with. framenum The framenumber to replace the frame code with.

Return values:
Returnstrue if the path was relative (started with "//").

Definition at line 618 of file path_util.c.

References BLI_char_switch(), BLI_cleanup_path(), BLI_last_slash(), BLI_strncpy(), FILE_MAX, NULL, and p.

Referenced by add_text(), BKE_add_image_file(), BKE_makepicstring(), BKE_rebase_path(), BL_MakeScreenShot(), BLI_bpathIterator_getPathExpanded(), BLI_cleanup_path(), bpy_lib_load(), cache_voxeldata(), checkPackedFile(), customdata_external_filename(), do_versions(), ED_fileselect_set_params(), file_browse_exec(), filepath_avi(), fluid_init_filepaths(), fluidsim_delete_until_lastframe(), fluidsim_read_cache(), get_brush_icon(), image_fix_relative_path(), image_load_image_file(), image_load_movie_file(), image_load_sequence_file(), main(), namebutton_cb(), newPackedFile(), ImagesExporter::operator()(), particles_fluid_step(), ptcache_path(), reload_sequence_new_file(), reopen_text(), save_envmap(), save_exec(), save_image_doit(), save_sequence_exec(), screenshot_exec(), seq_proxy_get_fname(), seq_render_strip(), sequencer_add_movie_strip(), sequencer_generic_invoke_path__internal(), sound_new_file(), space_image_file_exists_poll(), StartKetsjiShell(), text_file_modified(), text_ignore_modified(), txt_write_file(), and writePackedFile().

char* BLI_path_basename ( char *  path)
int BLI_path_cwd ( char *  path)

Definition at line 714 of file path_util.c.

References BLI_getwdN(), BLI_make_file_string(), BLI_strncpy(), FILE_MAXDIR, FILE_MAXFILE, and NULL.

Referenced by load_file(), main(), and run_python().

int BLI_path_frame ( char *  path,
int  frame,
int  digits 
)
int BLI_path_frame_range ( char *  path,
int  sta,
int  end,
int  digits 
)

Definition at line 602 of file path_util.c.

References ensure_digits(), FILE_MAX, and stringframe_chars().

Referenced by filepath_avi().

void BLI_path_rel ( char *  file,
const char *  relfile 
)
int BLI_replace_extension ( char *  path,
size_t  maxlen,
const char *  ext 
)
void BLI_setenv ( const char *  env,
const char *  val 
)

Definition at line 1156 of file path_util.c.

References MEM_freeN(), and MEM_mallocN().

Referenced by BLI_setenv_if_new(), main(), PyC_SetHomePath(), and set_env().

void BLI_setenv_if_new ( const char *  env,
const char *  val 
)

Only set an env var if already not there. Like Unix setenv(env, val, 0);

Definition at line 1180 of file path_util.c.

References BLI_setenv(), and NULL.

void BLI_split_dirfile ( const char *  string,
char *  dir,
char *  file 
)
int BLI_split_name_num ( char *  left,
int *  nr,
const char *  name,
const char  delim 
)
void BLI_splitdirstring ( char *  di,
char *  fi 
)
int BLI_stringdec ( const char *  string,
char *  head,
char *  tail,
unsigned short *  numlen 
)

Definition at line 97 of file path_util.c.

References BLI_last_slash(), and i.

Referenced by BLI_newname(), and image_load_sequence_file().

void BLI_stringenc ( char *  string,
const char *  head,
const char *  tail,
unsigned short  numlen,
int  pic 
)

Definition at line 143 of file path_util.c.

Referenced by an_stringenc(), BLI_newname(), and image_load_sequence_file().

int BLI_testextensie ( const char *  str,
const char *  ext 
)
int BLI_testextensie_array ( const char *  str,
const char **  ext_array 
)

Definition at line 1342 of file path_util.c.

References BLI_testextensie(), and i.

Referenced by BKE_add_image_extension(), BKE_add_image_file(), file_extension_type(), and IMB_ispic().

int BLI_testextensie_glob ( const char *  str,
const char *  ext_fnmatch 
)

Definition at line 1357 of file path_util.c.

References BLI_strncpy(), and FNM_CASEFOLD.

Referenced by filelist_setfiletypes().

void BLI_uniquename ( ListBase list,
void *  vlink,
const char  defname[],
char  delim,
short  name_offs,
short  name_len 
)
int BLI_uniquename_cb ( int(*)(void *, const char *)  unique_check,
void *  arg,
const char  defname[],
char  delim,
char *  name,
short  name_len 
)
void BLI_where_am_i ( char *  fullname,
const size_t  maxlen,
const char *  name 
)

Checks if name is a fully qualified filename to an executable. If not it searches $PATH for the file. On Windows it also adds the correct extension (.com .exe etc) from $PATHEXT if necessary. Also on Windows it translates the name to its 8.3 version to prevent problems with spaces and stuff. Final result is returned in fullname.

Parameters:
fullnameThe full path and full name of the executable
nameThe name of the executable (usually argv[0]) to be checked

Definition at line 1657 of file path_util.c.

References add_win32_extension(), BLI_exists(), BLI_getwdN(), BLI_join_dirfile(), BLI_last_slash(), BLI_strncpy(), FILE_MAX, FILE_MAXDIR, FILE_MAXFILE, NULL, and SEP.

Referenced by main().

void BLI_where_is_temp ( char *  fullname,
const size_t  maxlen,
int  usertemp 
)

Gets the temp directory when blender first runs. If the default path is not found, use try $TEMP

Also make sure the temp dir has a trailing slash

Parameters:
fullnameThe full path to the temp directory

Definition at line 1737 of file path_util.c.

References BLI_add_slash(), BLI_is_dir(), and BLI_strncpy().

Referenced by init_userdef_do_versions(), main(), and wm_init_userdef().

static void ensure_digits ( char *  path,
int  digits 
) [static]

Definition at line 569 of file path_util.c.

References BLI_last_slash(), and NULL.

Referenced by BLI_path_frame(), and BLI_path_frame_range().

static int get_path_local ( char *  targetpath,
const char *  folder_name,
const char *  subfolder_name,
const int  ver 
) [static]
static int get_path_system ( char *  targetpath,
const char *  folder_name,
const char *  subfolder_name,
const char *  envvar,
const int  ver 
) [static]
static int get_path_user ( char *  targetpath,
const char *  folder_name,
const char *  subfolder_name,
const char *  envvar,
const int  ver 
) [static]
static int is_portable_install ( void  ) [static]

Definition at line 905 of file path_util.c.

References BLENDER_VERSION, FILE_MAX, get_path_local(), and NULL.

Referenced by get_path_user().

static int stringframe_chars ( char *  path,
int *  char_start,
int *  char_end 
) [static]

Definition at line 537 of file path_util.c.

References i.

Referenced by BLI_path_frame(), and BLI_path_frame_range().

static int test_env_path ( char *  path,
const char *  envvar 
) [static]

Definition at line 861 of file path_util.c.

References BLI_is_dir(), BLI_strncpy(), FILE_MAX, and NULL.

Referenced by get_path_system(), and get_path_user().

static int test_path ( char *  targetpath,
const char *  path_base,
const char *  path_sep,
const char *  folder_name 
) [static]
static int uniquename_find_dupe ( ListBase list,
void *  vlink,
const char *  name,
short  name_offs 
) [static]

Definition at line 250 of file path_util.c.

References ListBase::first, GIVE_STRADDR, link(), and Link::next.

Referenced by uniquename_unique_check().

static int uniquename_unique_check ( void *  arg,
const char *  name 
) [static]

Definition at line 265 of file path_util.c.

References uniquename_find_dupe().

Referenced by BLI_uniquename().


Variable Documentation

char bprogname

Definition at line 118 of file GPG_ghost.cpp.

Referenced by BPY_python_start(), get_path_local(), get_path_system(), main(), and make_app_info().