GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
octave-config.in.cc
Go to the documentation of this file.
1 // %NO_EDIT_WARNING%
2 
3 ////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (C) 2008-2024 The Octave Project Developers
6 //
7 // See the file COPYRIGHT.md in the top-level directory of this
8 // distribution or <https://octave.org/copyright/>.
9 //
10 // This file is part of Octave.
11 //
12 // Octave is free software: you can redistribute it and/or modify it
13 // under the terms of the GNU General Public License as published by
14 // the Free Software Foundation, either version 3 of the License, or
15 // (at your option) any later version.
16 //
17 // Octave is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with Octave; see the file COPYING. If not, see
24 // <https://www.gnu.org/licenses/>.
25 //
26 ////////////////////////////////////////////////////////////////////////
27 
28 #if defined (HAVE_CONFIG_H)
29 # include "config.h"
30 #endif
31 
32 #include <string>
33 #include <map>
34 #include <iostream>
35 #include <algorithm>
36 #include <cstdlib>
37 
38 #if defined (OCTAVE_USE_WINDOWS_API)
39 # include <vector>
40 # include <locale>
41 # include <codecvt>
42 #endif
43 
44 #if ! defined (OCTAVE_PREFIX)
45 # define OCTAVE_PREFIX %OCTAVE_PREFIX%
46 #endif
47 
48 #if ! defined (OCTAVE_EXEC_PREFIX)
49 # define OCTAVE_EXEC_PREFIX %OCTAVE_EXEC_PREFIX%
50 #endif
51 
52 #ifndef OCTAVE_UNUSED
53 # define OCTAVE_UNUSED
54 #endif
55 
56 #include "shared-fcns.h"
57 
58 static std::map<std::string, std::string> vars;
59 
60 static std::string usage_msg = "usage: octave-config [options]";
61 
62 static std::string help_msg =
63  "\n"
64  "Options:\n"
65  "\n"
66  " -h, -?, --help Print this message.\n"
67  "\n"
68  " --m-site-dir Print the name of the directory where Octave\n"
69  " expects to find locally installed .m files.\n"
70  "\n"
71  " --oct-site-dir Print the name of the directory where Octave\n"
72  " expects to find locally installed .oct files.\n"
73  "\n"
74  " -p VAR, --print VAR Print the value of the given configuration\n"
75  " variable VAR. Recognized variables are:\n"
76  "\n"
77  " API_VERSION LOCALFCNFILEDIR\n"
78  " ARCHLIBDIR LOCALOCTFILEDIR\n"
79  " BINDIR LOCALSTARTUPFILEDIR\n"
80  " CANONICAL_HOST_TYPE LOCALVERARCHLIBDIR\n"
81  " DATADIR LOCALVERFCNFILEDIR\n"
82  " DATAROOTDIR LOCALVEROCTFILEDIR\n"
83  " DEFAULT_PAGER MAN1DIR\n"
84  " EXEC_PREFIX MAN1EXT\n"
85  " EXEEXT MANDIR\n"
86  " FCNFILEDIR OCTAVE_EXEC_HOME\n"
87  " IMAGEDIR OCTAVE_HOME\n"
88  " INCLUDEDIR OCTDATADIR\n"
89  " INFODIR OCTDOCDIR\n"
90  " INFOFILE OCTFILEDIR\n"
91  " LIBDIR OCTFONTSDIR\n"
92  " LIBEXECDIR OCTINCLUDEDIR\n"
93  " LOCALAPIARCHLIBDIR OCTLIBDIR\n"
94  " LOCALAPIFCNFILEDIR STARTUPFILEDIR\n"
95  " LOCALAPIOCTFILEDIR VERSION\n"
96  " LOCALARCHLIBDIR\n"
97  "\n"
98  " -v, --version Print the Octave version number.\n"
99  "\n";
100 
101 static void
102 initialize ()
103 {
104  set_octave_home ();
105 
106  vars["OCTAVE_HOME"] = Voctave_home;
107  vars["OCTAVE_EXEC_HOME"] = Voctave_exec_home;
108 
109  vars["API_VERSION"] = %OCTAVE_API_VERSION%;
110  vars["CANONICAL_HOST_TYPE"] = %OCTAVE_CANONICAL_HOST_TYPE%;
111  vars["DEFAULT_PAGER"] = %OCTAVE_DEFAULT_PAGER%;
112  vars["EXEEXT"] = %OCTAVE_EXEEXT%;
113  vars["MAN1EXT"] = %OCTAVE_MAN1EXT%;
114  vars["VERSION"] = %OCTAVE_VERSION%;
115 
116  vars["ARCHLIBDIR"] = prepend_octave_exec_home (%OCTAVE_ARCHLIBDIR%);
117  vars["BINDIR"] = prepend_octave_exec_home (%OCTAVE_BINDIR%);
118  vars["DATADIR"] = prepend_octave_home (%OCTAVE_DATADIR%);
119  vars["DATAROOTDIR"] = prepend_octave_home (%OCTAVE_DATAROOTDIR%);
120  vars["FCNFILEDIR"] = prepend_octave_home (%OCTAVE_FCNFILEDIR%);
121  vars["IMAGEDIR"] = prepend_octave_home (%OCTAVE_IMAGEDIR%);
122  vars["INCLUDEDIR"] = prepend_octave_home (%OCTAVE_INCLUDEDIR%);
123  vars["INFODIR"] = prepend_octave_home (%OCTAVE_INFODIR%);
124  vars["INFOFILE"] = prepend_octave_home (%OCTAVE_INFOFILE%);
125  vars["LIBDIR"] = prepend_octave_exec_home (%OCTAVE_LIBDIR%);
126  vars["LIBEXECDIR"] = prepend_octave_exec_home (%OCTAVE_LIBEXECDIR%);
127  vars["LOCALAPIARCHLIBDIR"] = prepend_octave_exec_home (%OCTAVE_LOCALAPIARCHLIBDIR%);
128  vars["LOCALAPIFCNFILEDIR"] = prepend_octave_home (%OCTAVE_LOCALAPIFCNFILEDIR%);
129  vars["LOCALAPIOCTFILEDIR"] = prepend_octave_exec_home (%OCTAVE_LOCALAPIOCTFILEDIR%);
130  vars["LOCALARCHLIBDIR"] = prepend_octave_exec_home (%OCTAVE_LOCALARCHLIBDIR%);
131  vars["LOCALFCNFILEDIR"] = prepend_octave_home (%OCTAVE_LOCALFCNFILEDIR%);
132  vars["LOCALOCTFILEDIR"] = prepend_octave_exec_home (%OCTAVE_LOCALOCTFILEDIR%);
133  vars["LOCALSTARTUPFILEDIR"] = prepend_octave_home (%OCTAVE_LOCALSTARTUPFILEDIR%);
134  vars["LOCALVERARCHLIBDIR"] = prepend_octave_exec_home (%OCTAVE_LOCALVERARCHLIBDIR%);
135  vars["LOCALVERFCNFILEDIR"] = prepend_octave_home (%OCTAVE_LOCALVERFCNFILEDIR%);
136  vars["LOCALVEROCTFILEDIR"] = prepend_octave_exec_home (%OCTAVE_LOCALVEROCTFILEDIR%);
137  vars["MAN1DIR"] = prepend_octave_home (%OCTAVE_MAN1DIR%);
138  vars["MANDIR"] = prepend_octave_home (%OCTAVE_MANDIR%);
139  vars["OCTDATADIR"] = prepend_octave_home (%OCTAVE_OCTDATADIR%);
140  vars["OCTDOCDIR"] = prepend_octave_home (%OCTAVE_OCTDOCDIR%);
141  vars["OCTFILEDIR"] = prepend_octave_exec_home (%OCTAVE_OCTFILEDIR%);
142  vars["OCTFONTSDIR"] = prepend_octave_home (%OCTAVE_OCTFONTSDIR%);
143  vars["OCTINCLUDEDIR"] = prepend_octave_home (%OCTAVE_OCTINCLUDEDIR%);
144  vars["OCTLIBDIR"] = prepend_octave_exec_home (%OCTAVE_OCTLIBDIR%);
145  vars["STARTUPFILEDIR"] = prepend_octave_home (%OCTAVE_STARTUPFILEDIR%);
146 }
147 
148 #if defined (OCTAVE_USE_WINDOWS_API) && defined (_UNICODE)
149 extern "C"
150 int
151 wmain (int argc, wchar_t **wargv)
152 {
153  static char **argv = new char * [argc + 1];
154  std::vector<std::string> argv_str;
155 
156  // convert wide character strings to multibyte UTF-8 strings
157  std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> wchar_conv;
158  for (int i_arg = 0; i_arg < argc; i_arg++)
159  argv_str.push_back (wchar_conv.to_bytes (wargv[i_arg]));
160 
161  // Get pointers to C strings not before vector is stable.
162  for (int i_arg = 0; i_arg < argc; i_arg++)
163  argv[i_arg] = &argv_str[i_arg][0];
164  argv[argc] = nullptr;
165 
166 #else
167 int
168 main (int argc, char **argv)
169 {
170 #endif
171  initialize ();
172 
173  if (argc == 1)
174  {
175  std::cout << usage_msg << std::endl;
176  return 1;
177  }
178 
179  for (int i = 1; i < argc; i++)
180  {
181  std::string arg (argv[i]);
182 
183  if (arg == "-h" || arg == "-?" || arg == "--help")
184  {
185  std::cout << usage_msg << std::endl;
186  std::cout << help_msg;
187  return 0;
188  }
189  else if (arg == "--m-site-dir")
190  std::cout << vars["LOCALVERFCNFILEDIR"] << std::endl;
191  else if (arg == "--oct-site-dir")
192  std::cout << vars["LOCALVEROCTFILEDIR"] << std::endl;
193  else if (arg == "-v" || arg == "--version")
194  std::cout << vars["VERSION"] << std::endl;
195  else if (arg == "-p" || arg == "--print")
196  {
197  if (i < argc-1)
198  {
199  arg = argv[++i];
200  std::cout << vars[arg] << std::endl;
201  }
202  else
203  {
204  std::cerr << "octave-config: " << arg
205  << " options requires argument" << std::endl;
206  return 1;
207  }
208  }
209  else
210  {
211  std::cerr << "octave-config: unrecognized argument " << arg
212  << std::endl;
213  return 1;
214  }
215  }
216 
217  return 0;
218 }
#define OCTAVE_OCTLIBDIR
Definition: default-defs.h:140
#define OCTAVE_LOCALSTARTUPFILEDIR
Definition: default-defs.h:172
#define OCTAVE_LOCALVERFCNFILEDIR
Definition: default-defs.h:104
#define OCTAVE_OCTINCLUDEDIR
Definition: default-defs.h:136
#define OCTAVE_LOCALAPIOCTFILEDIR
Definition: default-defs.h:92
#define OCTAVE_OCTDOCDIR
Definition: default-defs.h:124
#define OCTAVE_LIBEXECDIR
Definition: default-defs.h:68
#define OCTAVE_INFOFILE
Definition: default-defs.h:180
#define OCTAVE_LOCALVEROCTFILEDIR
Definition: default-defs.h:88
#define OCTAVE_OCTFONTSDIR
Definition: default-defs.h:132
#define OCTAVE_OCTDATADIR
Definition: default-defs.h:120
#define OCTAVE_FCNFILEDIR
Definition: default-defs.h:116
#define OCTAVE_MAN1EXT
Definition: default-defs.h:164
#define OCTAVE_LOCALOCTFILEDIR
Definition: default-defs.h:96
#define OCTAVE_LIBDIR
Definition: default-defs.h:64
#define OCTAVE_MANDIR
Definition: default-defs.h:156
#define OCTAVE_LOCALAPIARCHLIBDIR
Definition: default-defs.h:76
#define OCTAVE_STARTUPFILEDIR
Definition: default-defs.h:176
#define OCTAVE_INFODIR
Definition: default-defs.h:152
#define OCTAVE_INCLUDEDIR
Definition: default-defs.h:60
#define OCTAVE_DEFAULT_PAGER
Definition: default-defs.h:36
#define OCTAVE_OCTFILEDIR
Definition: default-defs.h:100
#define OCTAVE_LOCALARCHLIBDIR
Definition: default-defs.h:80
#define OCTAVE_LOCALVERARCHLIBDIR
Definition: default-defs.h:72
#define OCTAVE_IMAGEDIR
Definition: default-defs.h:168
#define OCTAVE_LOCALFCNFILEDIR
Definition: default-defs.h:112
#define OCTAVE_LOCALAPIFCNFILEDIR
Definition: default-defs.h:108
#define OCTAVE_MAN1DIR
Definition: default-defs.h:160
#define OCTAVE_DATADIR
Definition: default-defs.h:52
#define OCTAVE_DATAROOTDIR
Definition: default-defs.h:56
std::string prepend_octave_home(const std::string &s)
std::string prepend_octave_exec_home(const std::string &s)
#define OCTAVE_BINDIR
Definition: main.cc:71
#define OCTAVE_ARCHLIBDIR
Definition: main.cc:67
#define OCTAVE_VERSION
Definition: main.cc:63
int main(int argc, char **argv)
#define OCTAVE_CANONICAL_HOST_TYPE
Definition: version.h:53
#define OCTAVE_API_VERSION
Definition: version.h:49