1 /*
2  *  gretl -- Gnu Regression, Econometrics and Time-series Library
3  *  Copyright (C) 2001 Allin Cottrell and Riccardo "Jack" Lucchetti
4  *
5  *  This program is free software: you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation, either version 3 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  *
18  */
19 
20 #ifndef GRETL_PATHS_H
21 #define GRETL_PATHS_H
22 
23 #include <sys/stat.h>
24 #include <dirent.h>
25 
26 typedef enum {
27     DATA_SEARCH,
28     DB_SEARCH,
29     FUNCS_SEARCH,
30     SCRIPT_SEARCH,
31     USER_SEARCH
32 } SearchType;
33 
34 typedef enum {
35     GRETL_CMDREF,
36     GRETL_FUNCREF,
37     GRETL_GUI_HELP,
38 } HelpPaths;
39 
40 typedef enum {
41     PKG_ALL,
42     PKG_SUBDIR,
43     PKG_TOPLEV
44 } PkgType;
45 
46 typedef struct ConfigPaths_ ConfigPaths;
47 
48 /* these are all the gretl paths which are recorded in
49    the gretl config file or Windows registry entries
50 */
51 
52 struct ConfigPaths_ {
53     char gretldir[MAXLEN];
54     char workdir[MAXLEN];
55 #if !defined(WIN32) || !defined(PKGBUILD)
56     char gnuplot[MAXLEN];
57 #endif
58     char x12a[MAXLEN];
59     char tramo[MAXLEN];
60     char rbinpath[MAXLEN];
61     char rlibpath[MAXLEN];
62     char oxlpath[MAXLEN];
63     char octpath[MAXLEN];
64     char statapath[MAXLEN];
65     char pypath[MAXLEN];
66     char jlpath[MAXLEN];
67     char lppath[MAXLEN];
68     char mpiexec[MAXLEN];
69     char mpi_hosts[MAXLEN];
70     char pngfont[128];
71     int no_dotdir;
72 };
73 
74 void set_string_table_written (void);
75 
76 int gretl_string_table_written (void);
77 
78 int gretl_path_prepend (char *file, const char *path);
79 
80 int gretl_normalize_path (char *path);
81 
82 int slash_terminate (char *path);
83 
84 int utf8_encoded (const char *s);
85 
86 FILE *gretl_fopen (const char *fname, const char *mode);
87 
88 int gretl_test_fopen (const char *fname, const char *mode);
89 
90 FILE *gretl_read_user_file (const char *fname);
91 
92 FILE *gretl_mktemp (char *pattern, const char *mode);
93 
94 int gretl_open (const char *pathname, int flags, int mode);
95 
96 int gretl_rename (const char *oldpath, const char *newpath);
97 
98 int gretl_remove (const char *path);
99 
100 gzFile gretl_gzopen (const char *fname, const char *mode);
101 
102 int gretl_stat (const char *fname, struct stat *buf);
103 
104 int gretl_file_exists (const char *fname);
105 
106 int gretl_mkdir (const char *path);
107 
108 int gretl_chdir (const char *path);
109 
110 GDir *gretl_opendir (const char *name);
111 
112 int gretl_deltree (const char *path);
113 
114 int gretl_setenv (const char *name, const char *value);
115 
116 int gretl_write_access (char *fname);
117 
118 int gretl_is_xml_file (const char *fname);
119 
120 int gretl_isdir (const char *path);
121 
122 char *gretl_addpath (char *fname, int script);
123 
124 int get_full_filename (const char *fname, char *fullname,
125 		       gretlopt opt);
126 
127 int fname_has_path (const char *fname);
128 
129 int has_system_prefix (const char *fname, SearchType stype);
130 
131 void show_paths (void);
132 
133 int gretl_set_paths (ConfigPaths *paths);
134 
135 int gretl_update_paths (ConfigPaths *cpaths, gretlopt opt);
136 
137 int gretl_set_path_by_name (const char *name, const char *path);
138 
139 char **get_plausible_search_dirs (SearchType stype, int *n_dirs);
140 
141 char *gretl_function_package_get_path (const char *name,
142 				       PkgType type);
143 
144 int get_package_data_path (const char *fname, char *fullname);
145 
146 void set_gretl_plugin_path (const char *path);
147 
148 const char *helpfile_path (int id, int cli, int en);
149 
150 int using_translated_helpfile (int id);
151 
152 const char *gretl_home (void);
153 
154 const char *gretl_bindir (void);
155 
156 const char *gretl_plugin_path (void);
157 
158 const char *gretl_dotdir (void);
159 
160 const char *gretl_workdir (void);
161 
162 const char *maybe_get_default_workdir (void);
163 
164 gchar *gretl_make_dotpath (const char *basename);
165 
166 const char *gretl_maybe_switch_dir (const char *fname);
167 
168 char *gretl_maybe_prepend_dir (char *fname);
169 
170 const char *gretl_gnuplot_path (void);
171 
172 const char *gretl_plotfile (void);
173 
174 void report_plot_written (PRN *prn);
175 
176 const char *gretl_binbase (void);
177 
178 const char *gretl_tramo (void);
179 
180 const char *gretl_tramo_dir (void);
181 
182 const char *gretl_x12_arima (void);
183 
184 const char *gretl_x12_arima_dir (void);
185 
186 int gretl_x12_is_x13 (void);
187 
188 const char *gretl_rbin_path (void);
189 
190 const char *gretl_rlib_path (void);
191 
192 const char *gretl_png_font (void);
193 
194 const char *gretl_oxl_path (void);
195 
196 const char *gretl_octave_path (void);
197 
198 const char *gretl_stata_path (void);
199 
200 const char *gretl_python_path (void);
201 
202 const char *gretl_julia_path (void);
203 
204 const char *gretl_lpsolve_path (void);
205 
206 const char *gretl_mpi_hosts (void);
207 
208 const char *gretl_mpiexec (void);
209 
210 const char *gretl_function_package_path (void);
211 
212 void gretl_set_script_dir (const char *s);
213 
214 void gretl_script_dirs_cleanup (void);
215 
216 char *gretl_prepend_homedir (const char *fname, int *err);
217 
218 void set_gretl_png_font (const char *s);
219 
220 void get_gretl_config_from_file (FILE *fp, ConfigPaths *cpaths,
221 				 char *dbproxy, int *use_proxy,
222 				 int *updated, gchar **gptheme);
223 
224 int gretl_path_compose (char *targ, int len,
225 			const char *s1,
226 			const char *s2);
227 
228 char *gretl_build_path (char *targ,
229 			const gchar *first_element,
230 			...);
231 
232 gretl_bundle *foreign_info (void);
233 
234 #ifdef WIN32
235 
236 void win32_set_gretldir (void);
237 
238 #else
239 
240 void get_gretl_rc_path (char *rcfile);
241 
242 int cli_read_rc (void);
243 
244 #endif
245 
246 #ifdef OS_OSX
247 
248 const char *gretl_app_support_dir (void);
249 
250 #endif
251 
252 #endif /* GRETL_PATHS_H */
253