GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
octave-config.in.cc
Go to the documentation of this file.
1 // %NO_EDIT_WARNING%
2 /*
3 
4 Copyright (C) 2008-2017 Michael Goffioul
5 
6 This file is part of Octave.
7 
8 Octave is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with Octave; see the file COPYING. If not, see
20 <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if defined (HAVE_CONFIG_H)
25 # include "config.h"
26 #endif
27 
28 #include <string>
29 #include <map>
30 #include <iostream>
31 #include <algorithm>
32 #include <cstdlib>
33 
34 #if ! defined (OCTAVE_PREFIX)
35 # define OCTAVE_PREFIX %OCTAVE_PREFIX%
36 #endif
37 
38 #include "shared-fcns.h"
39 
40 static std::map<std::string,std::string> vars;
41 
42 static std::string usage_msg = "usage: octave-config [options]";
43 
45 "\n"
46 "Options:\n"
47 "\n"
48 " -h, -?, --help Print this message.\n"
49 "\n"
50 " --m-site-dir Print the name of the directory where Octave\n"
51 " expects to find locally installed .m files.\n"
52 "\n"
53 " --oct-site-dir Print the name of the directory where Octave\n"
54 " expects to find locally installed .oct files.\n"
55 "\n"
56 " -p VAR, --print VAR Print the value of the given configuration\n"
57 " variable VAR. Recognized variables are:\n"
58 "\n"
59 " API_VERSION LOCALARCHLIBDIR\n"
60 " ARCHLIBDIR LOCALFCNFILEDIR\n"
61 " BINDIR LOCALOCTFILEDIR\n"
62 " CANONICAL_HOST_TYPE LOCALSTARTUPFILEDIR\n"
63 " DATADIR LOCALVERARCHLIBDIR\n"
64 " DATAROOTDIR LOCALVERFCNFILEDIR\n"
65 " DEFAULT_PAGER LOCALVEROCTFILEDIR\n"
66 " EXEC_PREFIX MAN1DIR\n"
67 " EXEEXT MAN1EXT\n"
68 " FCNFILEDIR MANDIR\n"
69 " IMAGEDIR OCTDATADIR\n"
70 " INCLUDEDIR OCTFILEDIR\n"
71 " INFODIR OCTINCLUDEDIR\n"
72 " INFOFILE OCTLIBDIR\n"
73 " LIBDIR PREFIX\n"
74 " LIBEXECDIR STARTUPFILEDIR\n"
75 " LOCALAPIARCHLIBDIR VERSION\n"
76 " LOCALAPIFCNFILEDIR\n"
77 " LOCALAPIOCTFILEDIR\n"
78 "\n"
79 " -v, --version Print the Octave version number.\n"
80 "\n";
81 
82 static void
83 initialize (void)
84 {
85  vars["OCTAVE_HOME"] = get_octave_home ();
86  vars["PREFIX"] = OCTAVE_PREFIX;
87 
88  vars["API_VERSION"] = %OCTAVE_API_VERSION%;
89  vars["CANONICAL_HOST_TYPE"] = %OCTAVE_CANONICAL_HOST_TYPE%;
90  vars["DEFAULT_PAGER"] = %OCTAVE_DEFAULT_PAGER%;
91  vars["MAN1EXT"] = %OCTAVE_MAN1EXT%;
92  vars["VERSION"] = %OCTAVE_VERSION%;
93 
94  vars["ARCHLIBDIR"] = subst_octave_home (%OCTAVE_ARCHLIBDIR%);
95  vars["BINDIR"] = subst_octave_home (%OCTAVE_BINDIR%);
96  vars["DATADIR"] = subst_octave_home (%OCTAVE_DATADIR%);
97  vars["DATAROOTDIR"] = subst_octave_home (%OCTAVE_DATAROOTDIR%);
98  vars["EXEC_PREFIX"] = subst_octave_home (%OCTAVE_EXEC_PREFIX%);
99  vars["EXEEXT"] = subst_octave_home (%OCTAVE_EXEEXT%);
100  vars["FCNFILEDIR"] = subst_octave_home (%OCTAVE_FCNFILEDIR%);
101  vars["IMAGEDIR"] = subst_octave_home (%OCTAVE_IMAGEDIR%);
102  vars["INCLUDEDIR"] = subst_octave_home (%OCTAVE_INCLUDEDIR%);
103  vars["INFODIR"] = subst_octave_home (%OCTAVE_INFODIR%);
104  vars["INFOFILE"] = subst_octave_home (%OCTAVE_INFOFILE%);
105  vars["LIBDIR"] = subst_octave_home (%OCTAVE_LIBDIR%);
106  vars["LIBEXECDIR"] = subst_octave_home (%OCTAVE_LIBEXECDIR%);
107  vars["LOCALAPIARCHLIBDIR"] = subst_octave_home (%OCTAVE_LOCALAPIARCHLIBDIR%);
108  vars["LOCALAPIFCNFILEDIR"] = subst_octave_home (%OCTAVE_LOCALAPIFCNFILEDIR%);
109  vars["LOCALAPIOCTFILEDIR"] = subst_octave_home (%OCTAVE_LOCALAPIOCTFILEDIR%);
110  vars["LOCALARCHLIBDIR"] = subst_octave_home (%OCTAVE_LOCALARCHLIBDIR%);
111  vars["LOCALFCNFILEDIR"] = subst_octave_home (%OCTAVE_LOCALFCNFILEDIR%);
112  vars["LOCALOCTFILEDIR"] = subst_octave_home (%OCTAVE_LOCALOCTFILEDIR%);
113  vars["LOCALSTARTUPFILEDIR"] = subst_octave_home (%OCTAVE_LOCALSTARTUPFILEDIR%);
114  vars["LOCALVERARCHLIBDIR"] = subst_octave_home (%OCTAVE_LOCALVERARCHLIBDIR%);
115  vars["LOCALVERFCNFILEDIR"] = subst_octave_home (%OCTAVE_LOCALVERFCNFILEDIR%);
116  vars["LOCALVEROCTFILEDIR"] = subst_octave_home (%OCTAVE_LOCALVEROCTFILEDIR%);
117  vars["MAN1DIR"] = subst_octave_home (%OCTAVE_MAN1DIR%);
118  vars["MANDIR"] = subst_octave_home (%OCTAVE_MANDIR%);
119  vars["OCTDATADIR"] = subst_octave_home (%OCTAVE_OCTDATADIR%);
120  vars["OCTFILEDIR"] = subst_octave_home (%OCTAVE_OCTFILEDIR%);
121  vars["OCTINCLUDEDIR"] = subst_octave_home (%OCTAVE_OCTINCLUDEDIR%);
122  vars["OCTLIBDIR"] = subst_octave_home (%OCTAVE_OCTLIBDIR%);
123  vars["STARTUPFILEDIR"] = subst_octave_home (%OCTAVE_STARTUPFILEDIR%);
124 }
125 
126 int
127 main (int argc, char **argv)
128 {
129  initialize ();
130 
131  if (argc == 1)
132  {
133  std::cout << usage_msg << std::endl;
134  return 1;
135  }
136 
137  for (int i = 1; i < argc; i++)
138  {
139  std::string arg (argv[i]);
140 
141  if (arg == "-h" || arg == "-?" || arg == "--help")
142  {
143  std::cout << usage_msg << std::endl;
144  std::cout << help_msg;
145  return 0;
146  }
147  else if (arg == "--m-site-dir")
148  std::cout << vars["LOCALVERFCNFILEDIR"] << std::endl;
149  else if (arg == "--oct-site-dir")
150  std::cout << vars["LOCALVEROCTFILEDIR"] << std::endl;
151  else if (arg == "-v" || arg == "--version")
152  std::cout << vars["VERSION"] << std::endl;
153  else if (arg == "-p" || arg == "--print")
154  {
155  if (i < argc-1)
156  {
157  arg = argv[++i];
158  std::cout << vars[arg] << std::endl;
159  }
160  else
161  {
162  std::cerr << "octave-config: " << arg
163  << " options requires argument" << std::endl;
164  return 1;
165  }
166  }
167  else
168  {
169  std::cerr << "octave-config: unrecognized argument " << arg
170  << std::endl;
171  return 1;
172  }
173  }
174 
175  return 0;
176 }
static std::string get_octave_home(void)
Definition: shared-fcns.h:87
#define OCTAVE_FCNFILEDIR
Definition: defaults.h:70
#define OCTAVE_DATADIR
Definition: defaults.h:50
#define OCTAVE_LOCALVEROCTFILEDIR
Definition: defaults.h:138
static std::string subst_octave_home(const std::string &s)
Definition: shared-fcns.h:100
#define OCTAVE_LOCALFCNFILEDIR
Definition: defaults.h:114
int argc
Definition: load-save.cc:633
#define OCTAVE_LOCALSTARTUPFILEDIR
Definition: defaults.h:122
static void initialize(void)
#define OCTAVE_PREFIX
#define OCTAVE_LOCALARCHLIBDIR
Definition: defaults.h:110
#define OCTAVE_INFOFILE
Definition: defaults.h:86
#define OCTAVE_STARTUPFILEDIR
Definition: defaults.h:186
#define OCTAVE_OCTFILEDIR
Definition: defaults.h:158
#define OCTAVE_API_VERSION
Definition: version.h:45
#define OCTAVE_ARCHLIBDIR
Definition: main.cc:53
int main(int argc, char **argv)
#define OCTAVE_CANONICAL_HOST_TYPE
Definition: defaults.h:34
octave_value arg
Definition: pr-output.cc:3440
string_vector argv
Definition: load-save.cc:635
#define OCTAVE_DATAROOTDIR
Definition: defaults.h:54
#define OCTAVE_MAN1DIR
Definition: defaults.h:142
#define OCTAVE_OCTLIBDIR
Definition: defaults.h:174
static std::map< std::string, std::string > vars
#define OCTAVE_MANDIR
Definition: defaults.h:150
#define OCTAVE_DEFAULT_PAGER
Definition: defaults.h:38
#define OCTAVE_INCLUDEDIR
Definition: defaults.h:78
#define OCTAVE_BINDIR
Definition: main.cc:57
#define OCTAVE_IMAGEDIR
Definition: defaults.h:74
static std::string usage_msg
#define OCTAVE_LOCALAPIFCNFILEDIR
Definition: defaults.h:102
#define OCTAVE_LOCALOCTFILEDIR
Definition: defaults.h:118
#define OCTAVE_LOCALVERARCHLIBDIR
Definition: defaults.h:130
#define OCTAVE_LIBDIR
Definition: defaults.h:90
static std::string help_msg
#define OCTAVE_VERSION
Definition: main.cc:49
#define OCTAVE_OCTDATADIR
Definition: defaults.h:154
#define OCTAVE_LOCALAPIOCTFILEDIR
Definition: defaults.h:106
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
#define OCTAVE_EXEC_PREFIX
Definition: defaults.h:66
#define OCTAVE_MAN1EXT
Definition: defaults.h:146
#define OCTAVE_OCTINCLUDEDIR
Definition: defaults.h:170
#define OCTAVE_LOCALAPIARCHLIBDIR
Definition: defaults.h:126
#define OCTAVE_LIBEXECDIR
Definition: defaults.h:94
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854
#define OCTAVE_LOCALVERFCNFILEDIR
Definition: defaults.h:134
#define OCTAVE_INFODIR
Definition: defaults.h:82