GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
octave-config.in.cc
Go to the documentation of this file.
1// %NO_EDIT_WARNING%
2
3////////////////////////////////////////////////////////////////////////
4//
5// Copyright (C) 2008-2025 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
58static std::map<std::string, std::string> vars;
59
60static std::string usage_msg = "usage: octave-config [options]";
61
62static 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 LOCALARCHLIBDIR\n"
78 " ARCHLIBDIR LOCALFCNFILEDIR\n"
79 " BINDIR LOCALOCTFILEDIR\n"
80 " CANONICAL_HOST_TYPE LOCALSTARTUPFILEDIR\n"
81 " DATADIR LOCALVERARCHLIBDIR\n"
82 " DATAROOTDIR LOCALVERFCNFILEDIR\n"
83 " DEFAULT_PAGER LOCALVEROCTFILEDIR\n"
84 " EXEC_PREFIX MAN1DIR\n"
85 " EXEEXT MAN1EXT\n"
86 " FCNFILEDIR MANDIR\n"
87 " IMAGEDIR OCTAVE_EXEC_HOME\n"
88 " INCLUDEDIR OCTAVE_HOME\n"
89 " INFODIR OCTDATADIR\n"
90 " INFOFILE OCTDOCDIR\n"
91 " LIBDIR OCTFILEDIR\n"
92 " LIBEXECDIR OCTFONTSDIR\n"
93 " LOCALAPIARCHLIBDIR OCTINCLUDEDIR\n"
94 " LOCALAPIFCNFILEDIR OCTLIBDIR\n"
95 " LOCALAPIOCTFILEDIR STARTUPFILEDIR\n"
96 " LOCALAPIPKGDIR VERSION\n"
97 "\n"
98 " -v, --version Print the Octave version number.\n"
99 "\n";
100
101static void
102initialize ()
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["LOCALAPIPKGDIR"] = prepend_octave_exec_home (%OCTAVE_LOCALAPIPKGDIR%);
131 vars["LOCALARCHLIBDIR"] = prepend_octave_exec_home (%OCTAVE_LOCALARCHLIBDIR%);
132 vars["LOCALFCNFILEDIR"] = prepend_octave_home (%OCTAVE_LOCALFCNFILEDIR%);
133 vars["LOCALOCTFILEDIR"] = prepend_octave_exec_home (%OCTAVE_LOCALOCTFILEDIR%);
134 vars["LOCALSTARTUPFILEDIR"] = prepend_octave_home (%OCTAVE_LOCALSTARTUPFILEDIR%);
135 vars["LOCALVERARCHLIBDIR"] = prepend_octave_exec_home (%OCTAVE_LOCALVERARCHLIBDIR%);
136 vars["LOCALVERFCNFILEDIR"] = prepend_octave_home (%OCTAVE_LOCALVERFCNFILEDIR%);
137 vars["LOCALVEROCTFILEDIR"] = prepend_octave_exec_home (%OCTAVE_LOCALVEROCTFILEDIR%);
138 vars["MAN1DIR"] = prepend_octave_home (%OCTAVE_MAN1DIR%);
139 vars["MANDIR"] = prepend_octave_home (%OCTAVE_MANDIR%);
140 vars["OCTDATADIR"] = prepend_octave_home (%OCTAVE_OCTDATADIR%);
141 vars["OCTDOCDIR"] = prepend_octave_home (%OCTAVE_OCTDOCDIR%);
142 vars["OCTFILEDIR"] = prepend_octave_exec_home (%OCTAVE_OCTFILEDIR%);
143 vars["OCTFONTSDIR"] = prepend_octave_home (%OCTAVE_OCTFONTSDIR%);
144 vars["OCTINCLUDEDIR"] = prepend_octave_home (%OCTAVE_OCTINCLUDEDIR%);
145 vars["OCTLIBDIR"] = prepend_octave_exec_home (%OCTAVE_OCTLIBDIR%);
146 vars["STARTUPFILEDIR"] = prepend_octave_home (%OCTAVE_STARTUPFILEDIR%);
147}
148
149#if defined (OCTAVE_USE_WINDOWS_API) && defined (_UNICODE)
150extern "C"
151int
152wmain (int argc, wchar_t **wargv)
153{
154 static char **argv = new char * [argc + 1];
155 std::vector<std::string> argv_str;
156
157 // convert wide character strings to multibyte UTF-8 strings
158 std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> wchar_conv;
159 for (int i_arg = 0; i_arg < argc; i_arg++)
160 argv_str.push_back (wchar_conv.to_bytes (wargv[i_arg]));
161
162 // Get pointers to C strings not before vector is stable.
163 for (int i_arg = 0; i_arg < argc; i_arg++)
164 argv[i_arg] = &argv_str[i_arg][0];
165 argv[argc] = nullptr;
166
167#else
168int
169main (int argc, char **argv)
170{
171#endif
172 initialize ();
173
174 if (argc == 1)
175 {
176 std::cout << usage_msg << std::endl;
177 return 1;
178 }
179
180 for (int i = 1; i < argc; i++)
181 {
182 std::string arg (argv[i]);
183
184 if (arg == "-h" || arg == "-?" || arg == "--help")
185 {
186 std::cout << usage_msg << std::endl;
187 std::cout << help_msg;
188 return 0;
189 }
190 else if (arg == "--m-site-dir")
191 std::cout << vars["LOCALVERFCNFILEDIR"] << std::endl;
192 else if (arg == "--oct-site-dir")
193 std::cout << vars["LOCALVEROCTFILEDIR"] << std::endl;
194 else if (arg == "-v" || arg == "--version")
195 std::cout << vars["VERSION"] << std::endl;
196 else if (arg == "-p" || arg == "--print")
197 {
198 if (i < argc-1)
199 {
200 arg = argv[++i];
201 std::cout << vars[arg] << std::endl;
202 }
203 else
204 {
205 std::cerr << "octave-config: " << arg
206 << " options requires argument" << std::endl;
207 return 1;
208 }
209 }
210 else
211 {
212 std::cerr << "octave-config: unrecognized argument " << arg
213 << std::endl;
214 return 1;
215 }
216 }
217
218 return 0;
219}
program main
std::string prepend_octave_home(const std::string &s)
Definition defaults.cc:130
std::string prepend_octave_exec_home(const std::string &s)
Definition defaults.cc:136
#define OCTAVE_BINDIR
Definition main.in.cc:71
#define OCTAVE_ARCHLIBDIR
Definition main.in.cc:67
#define OCTAVE_VERSION
Definition main.in.cc:63