gretl_paths

gretl_paths

Functions

void set_string_table_written ()
int gretl_string_table_written ()
int gretl_path_prepend ()
int gretl_normalize_path ()
int slash_terminate ()
void set_stdio_use_utf8 ()
int get_stdio_use_utf8 ()
int string_is_utf8 ()
FILE * gretl_fopen ()
FILE * gretl_fopen_with_recode ()
int gretl_test_fopen ()
FILE * gretl_read_user_file ()
FILE * gretl_mktemp ()
int gretl_open ()
int gretl_rename ()
int gretl_remove ()
gzFile gretl_gzopen ()
int gretl_stat ()
int gretl_mkdir ()
int gretl_chdir ()
DIR * gretl_opendir ()
int gretl_deltree ()
int gretl_setenv ()
int gretl_write_access ()
int gretl_is_xml_file ()
int gretl_isdir ()
char * gretl_addpath ()
int getopenfile ()
int fname_has_path ()
int has_system_prefix ()
void show_paths ()
int gretl_set_paths ()
int gretl_update_paths ()
char ** get_plausible_search_dirs ()
char * gretl_function_package_get_path ()
void set_gretl_plugin_path ()
const char * helpfile_path ()
const char * gretl_home ()
const char * gretl_lib_path ()
const char * gretl_dotdir ()
const char * gretl_workdir ()
const char * gretl_default_workdir ()
const char * maybe_get_default_workdir ()
char * gretl_make_dotpath ()
int set_gretl_work_dir ()
const char * gretl_maybe_switch_dir ()
char * gretl_maybe_prepend_dir ()
const char * gretl_gnuplot_path ()
const char * gretl_plotfile ()
char * set_gretl_plotfile ()
void report_plot_written ()
const char * gretl_binbase ()
const char * gretl_tramo ()
const char * gretl_tramo_dir ()
const char * gretl_x12_arima ()
const char * gretl_x12_arima_dir ()
int gretl_x12_is_x13 ()
const char * gretl_rbin_path ()
const char * gretl_rlib_path ()
const char * gretl_png_font ()
const char * gretl_oxl_path ()
const char * gretl_octave_path ()
const char * gretl_stata_path ()
const char * gretl_python_path ()
const char * gretl_mpi_hosts ()
const char * gretl_mpiexec ()
const char * gretl_current_dir ()
void gretl_set_current_dir ()
void set_gretl_png_font ()
void get_gretl_config_from_file ()
void win32_set_gretldir ()
void get_gretl_rc_path ()
int cli_read_rc ()
const char * gretl_app_support_dir ()

Types and Values

enum SearchType
enum HelpPaths
enum PkgType
typedef ConfigPaths

Object Hierarchy


Description

Functions

set_string_table_written ()

void
set_string_table_written (void);


gretl_string_table_written ()

int
gretl_string_table_written (void);

Returns


gretl_path_prepend ()

int
gretl_path_prepend (char *file,
                    const char *path);

Creates a path string by prepending path , plus an appropriate separator if needed, to file . The result is written back into file : this variable is assumed to have storage for at least MAXLEN characters.

Parameters

file

target filename.

 

path

path to prepend.

 

Returns

0 on success, or 1 if the final path string would exceed MAXLEN characters (including nul-termination).


gretl_normalize_path ()

int
gretl_normalize_path (char *path);

Returns


slash_terminate ()

int
slash_terminate (char *path);

Check whether path is already slash-terminated, and if not, append a SLASH; path should be a large enough array to accept an extra byte.

Parameters

path

path string.

 

Returns

1 if a slash was appended, otherwise 0.


set_stdio_use_utf8 ()

void
set_stdio_use_utf8 (void);

Sets gretl's internal state so as to ensure that filenames are given in UTF-8 when passed to functions such as the C library's fopen().


get_stdio_use_utf8 ()

int
get_stdio_use_utf8 (void);

Returns

1 if filenames should be in UTF-8 when passed to the C library's fopen() and friends, otherwise 0.


string_is_utf8 ()

int
string_is_utf8 (const unsigned char *s);

Returns


gretl_fopen ()

FILE *
gretl_fopen (const char *fname,
             const char *mode);

A wrapper for the C library's fopen(), making allowance for the possibility that fname has to be converted from UTF-8 to the locale encoding or vice versa.

Parameters

fname

name of file to be opened.

 

mode

mode in which to open the file.

 

Returns

file pointer, or NULL on failure.


gretl_fopen_with_recode ()

FILE *
gretl_fopen_with_recode (const char *fname,
                         const char *mode,
                         char **recoded_fname);

A wrapper for the C library's fopen(), making allowance for the possibility that fname has to be converted from UTF-8 to the locale encoding or vice versa. If conversion is carried out, the newly allocated recoded filename is returned via the last argument (otherwise that argument is not touched).

Parameters

fname

name of file to be opened.

 

mode

mode in which to open the file.

 

recoded_fname

location to receive recoded filename, if recoding is needed.

 

Returns

file pointer, or NULL on failure.


gretl_test_fopen ()

int
gretl_test_fopen (const char *fname,
                  const char *mode);

Attempts to open fname in the given mode; if the opening is successful the stream is then closed.

Parameters

fname

name of file to be opened.

 

mode

mode as used with fopen().

 

Returns

0 on success, -1 on filename encoding failure, or the system errno on failure of fopen().


gretl_read_user_file ()

FILE *
gretl_read_user_file (const char *fname);

Attempts to open fname in read-only mode. If the file is not found when the name is used "as is", we use gretl_maybe_prepend_dir() to prepend the user's gretl working directory and try again.

Parameters

fname

name of file to open.

 

Returns

file pointer, or NULL on failure.


gretl_mktemp ()

FILE *
gretl_mktemp (char *pattern,
              const char *mode);

A wrapper for the combination of mkstemp() and fdopen(), making allowance for the possibility that template has to be converted from UTF-8 to the locale encoding or vice versa. On successful exit template holds the name of the newly created file.

Parameters

pattern

template for filename; must end with "XXXXXX".

 

mode

e.g. "w" for text use or "wb" for binary mode.

 

Returns

file pointer, or NULL on failure.


gretl_open ()

int
gretl_open (const char *pathname,
            int flags);

A wrapper for the C library's open(), making allowance for the possibility that pathname has to be converted from UTF-8 to the locale encoding or vice versa.

Parameters

pathname

name of file to be opened.

 

flags

flags to pass to the system open().

 

Returns

new file descriptor, or -1 on error.


gretl_rename ()

int
gretl_rename (const char *oldpath,
              const char *newpath);

A wrapper for the C library's rename(), making allowance for the possibility that oldpath and/or newpath have to be converted from UTF-8 to the locale encoding or vice versa.

Parameters

oldpath

name of file to be opened.

 

newpath

new name to give the file.

 

Returns

0 on success, non-zero on failure.


gretl_remove ()

int
gretl_remove (const char *path);

A wrapper for remove(), making allowance for the possibility that path has to be converted from UTF-8 to the locale encoding or vice versa.

Parameters

path

name of file or directory to remove.

 

Returns

0 on sucess, non-zero on failure.


gretl_gzopen ()

gzFile
gretl_gzopen (const char *fname,
              const char *mode);

A wrapper for zlib's gzopen(), making allowance for the possibility that fname has to be converted from UTF-8 to the locale encoding or vice versa.

Parameters

fname

name of gzipped file to be opened.

 

mode

mode in which to open the file.

 

Returns

pointer to gzip stream, or NULL on failure.


gretl_stat ()

int
gretl_stat (const char *fname,
            struct stat *buf);

A wrapper for the C library's stat(), making allowance for the possibility that fname has to be converted from UTF-8 to the locale encoding or vice versa.

Parameters

fname

name of file to be examined.

 

buf

pointer to a C struct stat.

 

Returns

0 on success, non-zero on failure.


gretl_mkdir ()

int
gretl_mkdir (const char *path);

Calls the underlying library function to create the specified directory with mode 0755. If the directory in question already exists, this does not count as an error.

Parameters

path

name of directory to be created.

 

Returns

0 on success, non-zero on error.


gretl_chdir ()

int
gretl_chdir (const char *path);

A wrapper for POSIX chdir(), making allowance for the possibility that path has to be converted from UTF-8 to the locale encoding or vice versa.

Parameters

path

name of directory.

 

Returns

0 on sucess, non-zero on failure.


gretl_opendir ()

DIR *
gretl_opendir (const char *name);

Returns


gretl_deltree ()

int
gretl_deltree (const char *path);

Carries out recursive deletion of the specified directory.

Parameters

path

name of directory to be deleted.

 

Returns

0 on success, non-zero on error.


gretl_setenv ()

int
gretl_setenv (const char *name,
              const char *value);

Cross-platform wrapper for setenv().

Parameters

name

name of variable to be set.

 

value

value to set.

 

Returns

0 on success, non-zero on failure.


gretl_write_access ()

int
gretl_write_access (char *fname);

Parameters

fname

name of file to test.

 

Returns

0 on success (meaning that the current user has write access to fname ), non-zero on failure.


gretl_is_xml_file ()

int
gretl_is_xml_file (const char *fname);

Parameters

fname

name of file to test.

 

Returns

1 if fname appears to be a (possibly gzipped) XML file, otherwise 0.


gretl_isdir ()

int
gretl_isdir (const char *path);

A test for whether or not path is the name of a directory, allowing for the possibility that path has to be converted from UTF-8 to the locale encoding or vice versa.

Parameters

path

path to check.

 

Returns

1 if path is the name of a directory, else 0.


gretl_addpath ()

char *
gretl_addpath (char *fname,
               int script);

Elementary path-searching: try adding various paths to the given fname and see if it can be opened. Usually called by getopenfile(). If fname does not have a dot-extension we may also try adding an appropriate gretl extension in case no file is found.

Parameters

fname

the initially given file name.

 

script

if non-zero, suppose the file we're looking for is a hansl script.

 

Returns

the full name of the file that was found, or NULL if no file could be found.


getopenfile ()

int
getopenfile (const char *line,
             char *fname,
             gretlopt opt);

Elementary path-searching: try adding various paths to the given fname and see if it can be opened.

Parameters

line

command line (e.g. "open foo").

 

fname

filename to be filled out.

 

opt

if includes OPT_W, treat as web filename and don't try to add path; if OPT_S, treat as a script; if OPT_I we're responding to the "include" command.

 

Returns

0 on successful parsing of line , 1 on error.


fname_has_path ()

int
fname_has_path (const char *fname);

Returns


has_system_prefix ()

int
has_system_prefix (const char *fname,
                   SearchType stype);

Returns


show_paths ()

void
show_paths (void);


gretl_set_paths ()

int
gretl_set_paths (ConfigPaths *paths);

Returns


gretl_update_paths ()

int
gretl_update_paths (ConfigPaths *cpaths,
                    gretlopt opt);

Returns


get_plausible_search_dirs ()

char **
get_plausible_search_dirs (SearchType stype,
                           int *n_dirs);

Parameters

stype

DATA_SEARCH for data file packages, DB_SEARCH for gretl databases, FUNCS_SEARCH for function packages, or SCRIPT_SEARCH for hansl scripts.

 

n_dirs

location to receive the number of directories.

 

Returns

an array of plausible search paths, depending on the type of search. The array should be freed when you are done with it, using strings_array_free().


gretl_function_package_get_path ()

char *
gretl_function_package_get_path (const char *name,
                                 PkgType type);

Searches a list of directories in which we might expect to find function packages, and, if the package in question is found, returns a newly allocated string holding the full path to the package's gfn file. Public (system) directories are searched first, then directories in the user's filespace.

Parameters

name

the name of the package to find, without the .gfn extension.

 

type

PKG_SUBDIR for a recognized gretl "addon", PKG_TOPLEV for a package file not in a subdirectory, or PKG_ALL for a package that may be at either level.

 

Returns

allocated path on success, otherwise NULL.


set_gretl_plugin_path ()

void
set_gretl_plugin_path (const char *path);

For use by third-party code: the purpose of this function is to ensure that libgretl can find its plugins.

prefix , if given, should be the path under which the plugins are installed. On a unix-type system this might be, for example, /usr/local/lib/gretl-gtk2; on MS Windows it might be c:\program files\gretl\plugins.

Parameters

path

path to the gretl plugins.

 

helpfile_path ()

const char *
helpfile_path (int id);

Returns


gretl_home ()

const char *
gretl_home (void);

Returns


gretl_lib_path ()

const char *
gretl_lib_path (void);

Returns


gretl_dotdir ()

const char *
gretl_dotdir (void);

Returns


gretl_workdir ()

const char *
gretl_workdir (void);

Returns


gretl_default_workdir ()

const char *
gretl_default_workdir (void);

Returns

the full path to the default value of the user's gretl working directory, or NULL if it happens that this path cannot be determined, or is not writable by the current user.


maybe_get_default_workdir ()

const char *
maybe_get_default_workdir (void);

Acts like gretl_default_workdir(), except that this function returns NULL if the default working directory is the same as the current gretl working directory, as returned by gretl_workdir().

Returns

a path, or NULL.


gretl_make_dotpath ()

char *
gretl_make_dotpath (const char *basename);

Returns


set_gretl_work_dir ()

int
set_gretl_work_dir (const char *path);

Returns


gretl_maybe_switch_dir ()

const char *
gretl_maybe_switch_dir (const char *fname);

Returns


gretl_maybe_prepend_dir ()

char *
gretl_maybe_prepend_dir (char *fname);

If fname starts with the construction "~/" to indicate the user's HOME, replace this with the full path to that directory. Otherwise, if fname is not already an absolute path, prepend either the gretl "shelldir" or the user's gretl working directory, depending on whether or USE_CWD is set. Otherwise do nothing.

Parameters

fname

the original filename, which should be in a location of length FILENAME_MAX.

 

Returns

the possibly modified filename.


gretl_gnuplot_path ()

const char *
gretl_gnuplot_path (void);

Returns


gretl_plotfile ()

const char *
gretl_plotfile (void);

Returns


set_gretl_plotfile ()

char *
set_gretl_plotfile (const char *fname);

Returns


report_plot_written ()

void
report_plot_written (PRN *prn);


gretl_binbase ()

const char *
gretl_binbase (void);

Returns


gretl_tramo ()

const char *
gretl_tramo (void);

Returns


gretl_tramo_dir ()

const char *
gretl_tramo_dir (void);

Returns


gretl_x12_arima ()

const char *
gretl_x12_arima (void);

Returns


gretl_x12_arima_dir ()

const char *
gretl_x12_arima_dir (void);

Returns


gretl_x12_is_x13 ()

int
gretl_x12_is_x13 (void);

Returns


gretl_rbin_path ()

const char *
gretl_rbin_path (void);

Returns


gretl_rlib_path ()

const char *
gretl_rlib_path (void);

Returns


gretl_png_font ()

const char *
gretl_png_font (void);

Returns


gretl_oxl_path ()

const char *
gretl_oxl_path (void);

Returns


gretl_octave_path ()

const char *
gretl_octave_path (void);

Returns


gretl_stata_path ()

const char *
gretl_stata_path (void);

Returns


gretl_python_path ()

const char *
gretl_python_path (void);

Returns


gretl_mpi_hosts ()

const char *
gretl_mpi_hosts (void);

Returns


gretl_mpiexec ()

const char *
gretl_mpiexec (void);

Returns


gretl_current_dir ()

const char *
gretl_current_dir (void);

Returns


gretl_set_current_dir ()

void
gretl_set_current_dir (const char *s);


set_gretl_png_font ()

void
set_gretl_png_font (const char *s);


get_gretl_config_from_file ()

void
get_gretl_config_from_file (FILE *fp,
                            ConfigPaths *cpaths,
                            char *dbproxy,
                            int *use_proxy);


win32_set_gretldir ()

void
win32_set_gretldir (const char *progname);


get_gretl_rc_path ()

void
get_gretl_rc_path (char *rcfile);


cli_read_rc ()

int
cli_read_rc (void);

Returns


gretl_app_support_dir ()

const char *
gretl_app_support_dir (void);

Returns

Types and Values

enum SearchType

Members

DATA_SEARCH

   

DB_SEARCH

   

FUNCS_SEARCH

   

SCRIPT_SEARCH

   

USER_SEARCH

   

enum HelpPaths

Members

GRETL_HELPFILE

   

GRETL_CMD_HELPFILE

   

GRETL_CLI_HELPFILE

   

enum PkgType

Members

PKG_ALL

   

PKG_SUBDIR

   

PKG_TOPLEV

   

ConfigPaths

typedef struct ConfigPaths_ ConfigPaths;