File: octave-config.in.cc

package info (click to toggle)
octave 4.0.3-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 94,200 kB
  • ctags: 52,925
  • sloc: cpp: 316,850; ansic: 43,469; fortran: 23,670; sh: 13,805; yacc: 8,204; objc: 7,939; lex: 3,631; java: 2,127; makefile: 1,746; perl: 1,022; awk: 988
file content (177 lines) | stat: -rw-r--r-- 6,628 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// %NO_EDIT_WARNING%
/*

Copyright (C) 2008-2015 Michael Goffioul

This file is part of Octave.

Octave is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3 of the License, or (at your
option) any later version.

Octave is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with Octave; see the file COPYING.  If not, see
<http://www.gnu.org/licenses/>.

*/

#if defined (HAVE_CONFIG_H)
#include <config.h>
#endif

#include <string>
#include <map>
#include <iostream>
#include <algorithm>
#include <stdlib.h>

#ifndef OCTAVE_PREFIX
#define OCTAVE_PREFIX %OCTAVE_PREFIX%
#endif

#include "shared-fcns.h"

static std::map<std::string,std::string> vars;

static std::string usage_msg = "usage: octave-config [options]";

static std::string help_msg =
"\n"
"Options:\n"
"\n"
"  -h, -?, --help        Print this message.\n"
"\n"
"  --m-site-dir          Print the name of the directory where Octave\n"
"                        expects to find locally installed .m files.\n"
"\n"
"  --oct-site-dir        Print the name of the directory where Octave\n"
"                        expects to find locally installed .oct files.\n"
"\n"
"  -p VAR, --print VAR   Print the value of the given configuration\n"
"                        variable VAR.  Recognized variables are:\n"
"\n"
"                          API_VERSION            LOCALARCHLIBDIR\n"
"                          ARCHLIBDIR             LOCALFCNFILEDIR\n"
"                          BINDIR                 LOCALOCTFILEDIR\n"
"                          CANONICAL_HOST_TYPE    LOCALSTARTUPFILEDIR\n"
"                          DATADIR                LOCALVERARCHLIBDIR\n"
"                          DATAROOTDIR            LOCALVERFCNFILEDIR\n"
"                          DEFAULT_PAGER          LOCALVEROCTFILEDIR\n"
"                          EXEC_PREFIX            MAN1DIR\n"
"                          EXEEXT                 MAN1EXT\n"
"                          FCNFILEDIR             MANDIR\n"
"                          IMAGEDIR               OCTDATADIR\n"
"                          INCLUDEDIR             OCTFILEDIR\n"
"                          INFODIR                OCTINCLUDEDIR\n"
"                          INFOFILE               OCTLIBDIR\n"
"                          LIBDIR                 PREFIX\n"
"                          LIBEXECDIR             SHLEXT\n"
"                          LOCALAPIARCHLIBDIR     STARTUPFILEDIR\n"
"                          LOCALAPIFCNFILEDIR     VERSION\n"
"                          LOCALAPIOCTFILEDIR\n"
"\n"
"  -v, --version         Print the Octave version number.\n"
"\n";

static void
initialize (void)
{
  vars["OCTAVE_HOME"] = get_octave_home ();
  vars["PREFIX"] = OCTAVE_PREFIX;

  vars["API_VERSION"] = %OCTAVE_API_VERSION%;
  vars["CANONICAL_HOST_TYPE"] = %OCTAVE_CANONICAL_HOST_TYPE%;
  vars["DEFAULT_PAGER"] = %OCTAVE_DEFAULT_PAGER%;
  vars["MAN1EXT"] = %OCTAVE_MAN1EXT%;
  vars["VERSION"] = %OCTAVE_VERSION%;

  vars["ARCHLIBDIR"] = subst_octave_home (%OCTAVE_ARCHLIBDIR%);
  vars["BINDIR"] = subst_octave_home (%OCTAVE_BINDIR%);
  vars["DATADIR"] = subst_octave_home (%OCTAVE_DATADIR%);
  vars["DATAROOTDIR"] = subst_octave_home (%OCTAVE_DATAROOTDIR%);
  vars["EXEC_PREFIX"] = subst_octave_home (%OCTAVE_EXEC_PREFIX%);
  vars["EXEEXT"] = subst_octave_home (%OCTAVE_EXEEXT%);
  vars["FCNFILEDIR"] = subst_octave_home (%OCTAVE_FCNFILEDIR%);
  vars["IMAGEDIR"] = subst_octave_home (%OCTAVE_IMAGEDIR%);
  vars["INCLUDEDIR"] = subst_octave_home (%OCTAVE_INCLUDEDIR%);
  vars["INFODIR"] = subst_octave_home (%OCTAVE_INFODIR%);
  vars["INFOFILE"] = subst_octave_home (%OCTAVE_INFOFILE%);
  vars["LIBDIR"] = subst_octave_home (%OCTAVE_LIBDIR%);
  vars["LIBEXECDIR"] = subst_octave_home (%OCTAVE_LIBEXECDIR%);
  vars["LOCALAPIARCHLIBDIR"] = subst_octave_home (%OCTAVE_LOCALAPIARCHLIBDIR%);
  vars["LOCALAPIFCNFILEDIR"] = subst_octave_home (%OCTAVE_LOCALAPIFCNFILEDIR%);
  vars["LOCALAPIOCTFILEDIR"] = subst_octave_home (%OCTAVE_LOCALAPIOCTFILEDIR%);
  vars["LOCALARCHLIBDIR"] = subst_octave_home (%OCTAVE_LOCALARCHLIBDIR%);
  vars["LOCALFCNFILEDIR"] = subst_octave_home (%OCTAVE_LOCALFCNFILEDIR%);
  vars["LOCALOCTFILEDIR"] = subst_octave_home (%OCTAVE_LOCALOCTFILEDIR%);
  vars["LOCALSTARTUPFILEDIR"] = subst_octave_home (%OCTAVE_LOCALSTARTUPFILEDIR%);
  vars["LOCALVERARCHLIBDIR"] = subst_octave_home (%OCTAVE_LOCALVERARCHLIBDIR%);
  vars["LOCALVERFCNFILEDIR"] = subst_octave_home (%OCTAVE_LOCALVERFCNFILEDIR%);
  vars["LOCALVEROCTFILEDIR"] = subst_octave_home (%OCTAVE_LOCALVEROCTFILEDIR%);
  vars["MAN1DIR"] = subst_octave_home (%OCTAVE_MAN1DIR%);
  vars["MANDIR"] = subst_octave_home (%OCTAVE_MANDIR%);
  vars["OCTDATADIR"] = subst_octave_home (%OCTAVE_OCTDATADIR%);
  vars["OCTFILEDIR"] = subst_octave_home (%OCTAVE_OCTFILEDIR%);
  vars["OCTINCLUDEDIR"] = subst_octave_home (%OCTAVE_OCTINCLUDEDIR%);
  vars["OCTLIBDIR"] = subst_octave_home (%OCTAVE_OCTLIBDIR%);
  vars["SHLEXT"] = subst_octave_home (%OCTAVE_SHLEXT%);
  vars["STARTUPFILEDIR"] = subst_octave_home (%OCTAVE_STARTUPFILEDIR%);
}

int
main (int argc, char **argv)
{
  initialize ();

  if (argc == 1)
    {
      std::cout << usage_msg << std::endl;
      return 1;
    }

  for (int i = 1; i < argc; i++)
    {
      std::string arg (argv[i]);

      if (arg == "-h" || arg == "-?" || arg == "--help")
        {
          std::cout << usage_msg << std::endl;
          std::cout << help_msg;
          return 0;
        }
      else if (arg == "--m-site-dir")
        std::cout << vars["LOCALVERFCNFILEDIR"] << std::endl;
      else if (arg == "--oct-site-dir")
        std::cout << vars["LOCALVEROCTFILEDIR"] << std::endl;
      else if (arg == "-v" || arg == "--version")
        std::cout << vars["VERSION"] << std::endl;
      else if (arg == "-p" || arg == "--print")
        {
          if (i < argc-1)
            {
              arg = argv[++i];
              std::cout << vars[arg] << std::endl;
            }
          else
            {
              std::cerr << "octave-config: " << arg
                        << " options requires argument" << std::endl;
              return 1;
            }
        }
      else
        {
          std::cerr << "octave-config: unrecognized argument " << arg
                    << std::endl;
          return 1;
        }
    }

  return 0;
}