GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
octave-config.cc
Go to the documentation of this file.
1 // DO NOT EDIT! Generated automatically by subst-config-vals.
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 "/usr/local"
46 #endif
47 
48 #if ! defined (OCTAVE_EXEC_PREFIX)
49 # define OCTAVE_EXEC_PREFIX "/usr/local"
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"] = "api-v59";
110  vars["CANONICAL_HOST_TYPE"] = "x86_64-pc-linux-gnu";
111  vars["DEFAULT_PAGER"] = "less";
112  vars["EXEEXT"] = "";
113  vars["MAN1EXT"] = ".1";
114  vars["VERSION"] = "9.1.0";
115 
116  vars["ARCHLIBDIR"] = prepend_octave_exec_home ("libexec/octave/9.1.0/exec/x86_64-pc-linux-gnu");
117  vars["BINDIR"] = prepend_octave_exec_home ("bin");
118  vars["DATADIR"] = prepend_octave_home ("share");
119  vars["DATAROOTDIR"] = prepend_octave_home ("share");
120  vars["FCNFILEDIR"] = prepend_octave_home ("share/octave/9.1.0/m");
121  vars["IMAGEDIR"] = prepend_octave_home ("share/octave/9.1.0/imagelib");
122  vars["INCLUDEDIR"] = prepend_octave_home ("include");
123  vars["INFODIR"] = prepend_octave_home ("share/info");
124  vars["INFOFILE"] = prepend_octave_home ("share/info/octave.info");
125  vars["LIBDIR"] = prepend_octave_exec_home ("lib");
126  vars["LIBEXECDIR"] = prepend_octave_exec_home ("libexec");
127  vars["LOCALAPIARCHLIBDIR"] = prepend_octave_exec_home ("libexec/octave/api-v59/site/exec/x86_64-pc-linux-gnu");
128  vars["LOCALAPIFCNFILEDIR"] = prepend_octave_home ("share/octave/site/api-v59/m");
129  vars["LOCALAPIOCTFILEDIR"] = prepend_octave_exec_home ("lib/octave/site/oct/api-v59/x86_64-pc-linux-gnu");
130  vars["LOCALARCHLIBDIR"] = prepend_octave_exec_home ("libexec/octave/site/exec/x86_64-pc-linux-gnu");
131  vars["LOCALFCNFILEDIR"] = prepend_octave_home ("share/octave/site/m");
132  vars["LOCALOCTFILEDIR"] = prepend_octave_exec_home ("lib/octave/site/oct/x86_64-pc-linux-gnu");
133  vars["LOCALSTARTUPFILEDIR"] = prepend_octave_home ("share/octave/site/m/startup");
134  vars["LOCALVERARCHLIBDIR"] = prepend_octave_exec_home ("libexec/octave/9.1.0/site/exec/x86_64-pc-linux-gnu");
135  vars["LOCALVERFCNFILEDIR"] = prepend_octave_home ("share/octave/9.1.0/site/m");
136  vars["LOCALVEROCTFILEDIR"] = prepend_octave_exec_home ("lib/octave/9.1.0/site/oct/x86_64-pc-linux-gnu");
137  vars["MAN1DIR"] = prepend_octave_home ("share/man/man1");
138  vars["MANDIR"] = prepend_octave_home ("share/man");
139  vars["OCTDATADIR"] = prepend_octave_home ("share/octave/9.1.0/data");
140  vars["OCTDOCDIR"] = prepend_octave_home ("share/octave/9.1.0/doc");
141  vars["OCTFILEDIR"] = prepend_octave_exec_home ("lib/octave/9.1.0/oct/x86_64-pc-linux-gnu");
142  vars["OCTFONTSDIR"] = prepend_octave_home ("share/octave/9.1.0/fonts");
143  vars["OCTINCLUDEDIR"] = prepend_octave_home ("include/octave-9.1.0/octave");
144  vars["OCTLIBDIR"] = prepend_octave_exec_home ("lib/octave/9.1.0");
145  vars["STARTUPFILEDIR"] = prepend_octave_home ("share/octave/9.1.0/m/startup");
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 }
std::string prepend_octave_home(const std::string &s)
std::string prepend_octave_exec_home(const std::string &s)
int main(int argc, char **argv)