gretl_paths

gretl_paths

Functions

int gretl_path_prepend ()
int gretl_normalize_path ()
int slash_terminate ()
int utf8_encoded ()
FILE * gretl_fopen ()
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_file_exists ()
int gretl_mkdir ()
int gretl_chdir ()
GDir * gretl_opendir ()
int gretl_deltree ()
int gretl_setenv ()
int gretl_write_access ()
int gretl_is_xml_file ()
int gretl_isdir ()
char * gretl_addpath ()
int get_full_filename ()
int fname_has_path ()
int has_system_prefix ()
void show_paths ()
int gretl_set_paths ()
int gretl_update_paths ()
int gretl_set_path_by_name ()
char ** get_plausible_search_dirs ()
char * gretl_function_package_get_path ()
int get_package_data_path ()
void set_gretl_plugin_path ()
const char * helpfile_path ()
int using_translated_helpfile ()
const char * gretl_home ()
const char * gretl_bindir ()
const char * gretl_plugin_path ()
const char * gretl_dotdir ()
const char * gretl_workdir ()
const char * maybe_get_default_workdir ()
gchar * gretl_make_dotpath ()
const char * gretl_maybe_switch_dir ()
char * gretl_maybe_prepend_dir ()
const char * gretl_gnuplot_path ()
const char * 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_julia_path ()
const char * gretl_lpsolve_path ()
const char * gretl_mpi_hosts ()
const char * gretl_mpiexec ()
const char * gretl_function_package_path ()
void gretl_set_script_dir ()
void gretl_script_dirs_cleanup ()
char * gretl_prepend_homedir ()
void set_gretl_png_font ()
void get_gretl_config_from_file ()
int gretl_path_compose ()
char * gretl_build_path ()
gretl_bundle * foreign_info ()
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
struct ConfigPaths_

Description

Functions

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);

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.


utf8_encoded ()

int
utf8_encoded (const char *s);

The primary use of this function is to determine whether a filename can be passed to regular C-library functions on MS Windows: if it's in UTF-8 the answer is No -- unless it's in the ASCII subset of UTF-8.

Parameters

s

the string to examine.

 

Returns

non-zero if s validates as UTF-8 and contains bytes that are not printable ASCII, otherwise zero.


gretl_fopen ()

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

A wrapper for the C library's fopen(), using g_fopen() on Windows, and adding some error handling.

Parameters

fname

name of file to be opened.

 

mode

mode in which to open the file.

 

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(), using the associated GLib functions on Windows. On successful exit pattern holds the name of the newly created file.

Parameters

pattern

template for filename; must include "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,
            int mode);

A wrapper for the C library's open(), using GLib on Windows and adding some error handling.

Parameters

pathname

name of file to be opened.

 

flags

flags to pass to the system open().

 

mode

ignored unless flags contains O_CREAT or O_TMPFILE.

 

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(), using the GLib counterpart on Windows.

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 UTF-16.

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 (or NULL is OK if the caller just wants the return value from the stat call).

 

Returns

0 on success, non-zero on failure.


gretl_file_exists ()

int
gretl_file_exists (const char *fname);

Uses the C library's stat() function, 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.

 

Returns

1 if fname is the name of an existing file, otherwise 0.


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 UTF-16 on Windows.

Parameters

path

name of directory.

 

Returns

0 on success, non-zero on failure.


gretl_opendir ()

GDir *
gretl_opendir (const char *name);

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 UTF-16.

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 get_full_filename(). If fname does not already have a dot-extension we may also try adding an appropriate gretl extension in case no file is found.

Parameters

fname

on input, the initially given file name; on output a path may be prepended and/or a suffix may be appended. This variable must be of size at least MAXLEN bytes to allow for possible additions.

 

script

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

 

Returns

the path to the file that was found (in fname ), or NULL if no file could be found even allowing for prepending a path and/or adding a suffix.


get_full_filename ()

int
get_full_filename (const char *fname,
                   char *fullname,
                   gretlopt opt);

Includes elementary path-searching: try adding various paths to the given fname , if appropriate, and see if it can be opened. For internal gretl use.

Parameters

fname

input filename.

 

fullname

filename to be filled out: must be at least MAXLEN bytes.

 

opt

if OPT_S, treat as a script; if OPT_I we're responding to the "include" command; if OPT_W, pass fname through as is.

 

Returns

0 on success, non-zero on error.


fname_has_path ()

int
fname_has_path (const char *fname);

has_system_prefix ()

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

show_paths ()

void
show_paths (void);

gretl_set_paths ()

int
gretl_set_paths (ConfigPaths *paths);

gretl_update_paths ()

int
gretl_update_paths (ConfigPaths *cpaths,
                    gretlopt opt);

gretl_set_path_by_name ()

int
gretl_set_path_by_name (const char *name,
                        const char *path);

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 package that lives in its own subdirectory, 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.


get_package_data_path ()

int
get_package_data_path (int ci,
                       const char *fname,
                       char *fullname);

Looks for fname in association with the name of a function package, which must have been set previously using the --frompkg option with the "open" command.

Parameters

ci

index of the active command.

 

fname

the basename of the file whose full path is wanted.

 

fullname

location to which the full path should be written (should be at least FILENAME_MAX bytes).

 

Returns

0 on success, non-zero code on error.


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,
               int cli,
               int en);

using_translated_helpfile ()

int
using_translated_helpfile (int id);

gretl_home ()

const char *
gretl_home (void);

gretl_bindir ()

const char *
gretl_bindir (void);

gretl_plugin_path ()

const char *
gretl_plugin_path (void);

gretl_dotdir ()

const char *
gretl_dotdir (void);

gretl_workdir ()

const char *
gretl_workdir (void);

maybe_get_default_workdir ()

const char *
maybe_get_default_workdir (void);

Figures the full path to the default value of the user's gretl working directory; call this defdir .

If this defdir turns out to be the same as the current gretl working directory, as would be returned by gretl_workdir(), this function returns NULL, otherwise it returns the defdir value.

Returns

a path, or NULL.


gretl_make_dotpath ()

gchar *
gretl_make_dotpath (const char *basename);

gretl_maybe_switch_dir ()

const char *
gretl_maybe_switch_dir (const char *fname);

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 the user's gretl working directory. 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);

gretl_plotfile ()

const char *
gretl_plotfile (void);

report_plot_written ()

void
report_plot_written (PRN *prn);

gretl_binbase ()

const char *
gretl_binbase (void);

gretl_tramo ()

const char *
gretl_tramo (void);

gretl_tramo_dir ()

const char *
gretl_tramo_dir (void);

gretl_x12_arima ()

const char *
gretl_x12_arima (void);

gretl_x12_arima_dir ()

const char *
gretl_x12_arima_dir (void);

gretl_x12_is_x13 ()

int
gretl_x12_is_x13 (void);

gretl_rbin_path ()

const char *
gretl_rbin_path (void);

gretl_rlib_path ()

const char *
gretl_rlib_path (void);

gretl_png_font ()

const char *
gretl_png_font (void);

gretl_oxl_path ()

const char *
gretl_oxl_path (void);

gretl_octave_path ()

const char *
gretl_octave_path (void);

gretl_stata_path ()

const char *
gretl_stata_path (void);

gretl_python_path ()

const char *
gretl_python_path (void);

gretl_julia_path ()

const char *
gretl_julia_path (void);

gretl_lpsolve_path ()

const char *
gretl_lpsolve_path (void);

gretl_mpi_hosts ()

const char *
gretl_mpi_hosts (void);

gretl_mpiexec ()

const char *
gretl_mpiexec (void);

gretl_function_package_path ()

const char *
gretl_function_package_path (void);

gretl_set_script_dir ()

void
gretl_set_script_dir (const char *s);

gretl_script_dirs_cleanup ()

void
gretl_script_dirs_cleanup (void);

gretl_prepend_homedir ()

char *
gretl_prepend_homedir (const char *fname,
                       int *err);

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,
                            int *updated,
                            gchar **gptheme);

gretl_path_compose ()

int
gretl_path_compose (char *targ,
                    int len,
                    const char *s1,
                    const char *s2);

gretl_build_path ()

char *
gretl_build_path (char *targ,
                  const gchar *first_element,
                  ...);

Writes to targ a path composed of first_element plus any additional string arguments supplied before a terminating NULL. An appropriate separator is inserted between the components of the path.

Parameters

targ

target string to write to (must be pre-allocated).

 

first_element

first component of path.

 

Returns

the target string, targ .


foreign_info ()

gretl_bundle *
foreign_info (void);

win32_set_gretldir ()

void
win32_set_gretldir (void);

get_gretl_rc_path ()

void
get_gretl_rc_path (char *rcfile);

cli_read_rc ()

int
cli_read_rc (void);

gretl_app_support_dir ()

const char *
gretl_app_support_dir (void);

Types and Values

enum SearchType

Members

DATA_SEARCH

   

DB_SEARCH

   

FUNCS_SEARCH

   

SCRIPT_SEARCH

   

USER_SEARCH

   

enum HelpPaths

Members

GRETL_CMDREF

   

GRETL_FUNCREF

   

GRETL_GUI_HELP

   

enum PkgType

Members

PKG_ALL

   

PKG_SUBDIR

   

PKG_TOPLEV

   

ConfigPaths

typedef struct ConfigPaths_ ConfigPaths;

struct ConfigPaths_

struct ConfigPaths_ {
    char gretldir[MAXLEN];
    char workdir[MAXLEN];
#if !defined(WIN32) || !defined(PKGBUILD)
    char gnuplot[MAXLEN];
#endif
    char x12a[MAXLEN];
    char tramo[MAXLEN];
    char rbinpath[MAXLEN];
    char rlibpath[MAXLEN];
    char oxlpath[MAXLEN];
    char octpath[MAXLEN];
    char statapath[MAXLEN];
    char pypath[MAXLEN];
    char jlpath[MAXLEN];
    char lppath[MAXLEN];
    char mpiexec[MAXLEN];
    char mpi_hosts[MAXLEN];
    char pngfont[128];
    int no_dotdir;
};