~ubuntu-branches/ubuntu/hardy/texmacs/hardy

« back to all changes in this revision

Viewing changes to src/System/Boot/init_first.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ralf Treinen
  • Date: 2004-04-19 20:34:00 UTC
  • Revision ID: james.westby@ubuntu.com-20040419203400-g4e34ih0315wcn8v
Tags: upstream-1.0.3-R2
ImportĀ upstreamĀ versionĀ 1.0.3-R2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/******************************************************************************
 
3
* MODULE     : init_first.cpp
 
4
* DESCRIPTION: initializations for the first launch of TeXmacs
 
5
* COPYRIGHT  : (C) 1999  Joris van der Hoeven
 
6
*******************************************************************************
 
7
* This software falls under the GNU general public license and comes WITHOUT
 
8
* ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
 
9
* If you don't have this file, write to the Free Software Foundation, Inc.,
 
10
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
11
******************************************************************************/
 
12
 
 
13
#include "boot.hpp"
 
14
#include "file.hpp"
 
15
#include "path.hpp"
 
16
#include "sys_utils.hpp"
 
17
#include "tex_files.hpp"
 
18
#include "convert.hpp"
 
19
 
 
20
/******************************************************************************
 
21
* Determine installed programs
 
22
******************************************************************************/
 
23
 
 
24
static void
 
25
init_helper_binaries () {
 
26
  if (exists_in_path ("kpsepath")) {
 
27
    cerr << "TeXmacs] kpsepath works with your TeX distribution\n";
 
28
    set_setting ("KPSEPATH", "true");
 
29
  }
 
30
  else {
 
31
    cerr << "TeXmacs] kpsepath does not work with your TeX distribution\n";
 
32
    set_setting ("KPSEPATH", "false");
 
33
  }
 
34
 
 
35
  if (exists_in_path ("kpsewhich")) {
 
36
    cerr << "TeXmacs] kpsewhich works with your TeX distribution\n";
 
37
    set_setting ("KPSEWHICH", "true");
 
38
  }
 
39
  else {
 
40
    cerr << "TeXmacs] kpsewhich does not work with your TeX distribution\n";
 
41
    set_setting ("KPSEWHICH", "false");
 
42
  }
 
43
 
 
44
  if (exists_in_path ("mktextfm")) {
 
45
    cerr << "TeXmacs] mktextfm works with your TeX distribution\n";
 
46
    set_setting ("MAKETFM", "mktextfm");
 
47
  }
 
48
  else if (exists_in_path ("MakeTeXTFM")) {
 
49
    cerr << "TeXmacs] MakeTeXTFM works with your TeX distribution\n";
 
50
    set_setting ("MAKETFM", "MakeTeXTFM");
 
51
  }
 
52
  else {
 
53
    cerr << "TeXmacs] MakeTeXTFM does not work with your TeX distribution\n";
 
54
    set_setting ("MAKETFM", "false");
 
55
  }
 
56
 
 
57
  if (exists_in_path ("mktexpk")) {
 
58
    cerr << "TeXmacs] mktexpk works with your TeX distribution\n";
 
59
    set_setting ("MAKEPK", "mktexpk");
 
60
  }
 
61
  else if (exists_in_path ("MakeTeXPK")) {
 
62
    cerr << "TeXmacs] MakeTeXPK works with your TeX distribution\n";
 
63
    set_setting ("MAKEPK", "MakeTeXPK");
 
64
  }
 
65
  else {
 
66
    cerr << "TeXmacs] MakeTeXPK does not work with your TeX distribution\n";
 
67
    set_setting ("MAKEPK", "false");
 
68
  }
 
69
 
 
70
  if (exists_in_path ("texhash")) {
 
71
    cerr << "TeXmacs] texhash works with your TeX distribution\n";
 
72
    set_setting ("TEXHASH", "true");
 
73
  }
 
74
  else {
 
75
    cerr << "TeXmacs] texhash does not work with your TeX distribution\n";
 
76
    set_setting ("TEXHASH", "false");
 
77
  }
 
78
}
 
79
 
 
80
/******************************************************************************
 
81
* Heuristic determination of path with TeX files
 
82
******************************************************************************/
 
83
 
 
84
static void
 
85
locate (string name, url& p) {
 
86
#ifdef OS_WIN32
 
87
  (void) name; (void) p;
 
88
#else
 
89
  int start=0, i;
 
90
  string s= eval_system ("locate " * name);
 
91
  for (i=0; i<N(s); i++)
 
92
    if (s[i]=='\n') {
 
93
      int j;
 
94
      for (j=i-1; j>start; j--)
 
95
        if ((s[j] == '/') || (s[j] == '\\')) break;
 
96
      p= url_system (s (start, j)) | p;
 
97
      start= i+1;
 
98
    }
 
99
#endif
 
100
}
 
101
 
 
102
static void
 
103
search_sub_dirs_sub (url base, url u, url& tfm, url& pk, int status) {
 
104
  if (is_concat (u)) {
 
105
    if (u[1] == "tfm") status= 1;
 
106
    if (u[1] == "pk")  status= 2;
 
107
    search_sub_dirs_sub (base * u[1], u[2], tfm, pk, status);
 
108
  }
 
109
  if (is_or (u)) {
 
110
    search_sub_dirs_sub (base, u[2], tfm, pk, status);
 
111
    search_sub_dirs_sub (base, u[1], tfm, pk, status);
 
112
  }
 
113
  if ((status == 1) || (u == "tfm")) tfm= (base * u) | tfm;
 
114
  if ((status == 2) || (u == "pk" )) pk = (base * u) | pk;
 
115
}
 
116
 
 
117
static void
 
118
search_sub_dirs (url root, url& tfm, url& pk) {
 
119
  url dirs= complete (root * url_wildcard (), "dr");
 
120
  if (!is_none (dirs)) {
 
121
    cerr << "TeXmacs] found TeX directory " << root << "\n";
 
122
    search_sub_dirs_sub (url_here (), dirs, tfm, pk, 0);
 
123
  }
 
124
}
 
125
 
 
126
static void
 
127
init_heuristic_tex_paths () {
 
128
  // Not necessary if we can use kpsepath
 
129
  if (get_setting ("KPSEPATH") == "true") {
 
130
    set_setting ("TFM", "");
 
131
    set_setting ("PK", "");
 
132
    return;
 
133
  }
 
134
 
 
135
  // Try locate
 
136
  url tfm= url_none (), pk= url_none ();
 
137
  string test= eval_system ("locate cmr10.tfm");
 
138
  if (N(test) == 0)
 
139
    cerr << "TeXmacs] locate does not work; I will try something else\n";
 
140
  else {
 
141
    locate (".tfm", tfm);
 
142
    locate (".300pk", pk);
 
143
    locate (".360pk", pk);
 
144
    locate (".400pk", pk);
 
145
    locate (".600pk", pk);
 
146
    locate (".1200pk", pk);
 
147
    if (is_none (tfm)) cerr << "TeXmacs] I could not locate any tfm files\n";
 
148
    else cerr << "TeXmacs] located tfm files in " << tfm << "\n";
 
149
    if (is_none (pk)) cerr << "TeXmacs] I could not locate any pk files\n";
 
150
    else cerr << "TeXmacs] located pk files in " << pk << "\n";
 
151
  }
 
152
 
 
153
  // Try some 'standard' directories
 
154
#ifdef OS_WIN32
 
155
  search_sub_dirs (url_system ("c:\texmf"), tfm, pk);
 
156
  search_sub_dirs (url_system ("d:\texmf"), tfm, pk);
 
157
#else
 
158
  search_sub_dirs ("/usr/lib/tetex/fonts", tfm, pk);
 
159
  search_sub_dirs ("/usr/lib/texmf/fonts", tfm, pk);
 
160
  search_sub_dirs ("/var/texfonts", tfm, pk);
 
161
  search_sub_dirs ("/var/tmp/texfonts", tfm, pk);
 
162
  search_sub_dirs ("/usr/TeX/lib/texmf/fonts", tfm, pk);
 
163
  search_sub_dirs ("/usr/local/lib/texmf/fonts", tfm, pk);
 
164
  search_sub_dirs ("/usr/share/texmf/fonts", tfm, pk);
 
165
#endif
 
166
 
 
167
  // Does TeX work?
 
168
  if ((is_none (tfm) && (get_env ("TEX_TFM_PATH") == "")) ||
 
169
      (is_none (pk ) && (get_env ("TEX_PK_PATH" ) == ""))) {
 
170
    cerr << HRULE;
 
171
    cerr << "I could not find a TeX system on your system\n";
 
172
    cerr << "If you did install one, please set the system variables\n\n";
 
173
    cerr << "\tTEX_TFM_PATH\n";
 
174
    cerr << "\tTEX_PK_PATH\n\n";
 
175
    cerr << "with the paths where the tfm resp. pk file\n";
 
176
    cerr << "can be found on your system and restart TeXmacs\n";
 
177
    cerr << HRULE;
 
178
    exit (1);
 
179
  }
 
180
 
 
181
  // Done
 
182
  set_setting ("TFM", as_string (expand (factor (tfm))));
 
183
  set_setting ("PK", as_string (expand (factor (pk))));
 
184
}
 
185
 
 
186
/******************************************************************************
 
187
* Determine default TeX settings
 
188
******************************************************************************/
 
189
 
 
190
static bool
 
191
try_dpi (int dpi, int test) {
 
192
  cerr << "TeXmacs] Trying to create ecrm10." << test
 
193
       << "pk from " << dpi << " dpi\n";
 
194
  make_tex_pk ("ecrm10", test, dpi, "localfont");
 
195
  reset_pk_path ();
 
196
  if (!is_none (resolve_pk ("ecrm10." * as_string (test) * "pk"))) {
 
197
    set_setting ("DPI", as_string (dpi));
 
198
    set_setting ("EC", "true");
 
199
    cerr << "TeXmacs] Metafont works with " << dpi << " dpi ec-fonts\n";
 
200
    return true;
 
201
  }
 
202
 
 
203
  cerr << "TeXmacs] Trying to create cmr10." << test
 
204
       << "pk from " << dpi << " dpi\n";
 
205
  make_tex_pk ("cmr10", test, dpi, "localfont");
 
206
  reset_pk_path ();
 
207
  if (!is_none (resolve_pk ("cmr10." * as_string (test) * "pk"))) {
 
208
    set_setting ("DPI", as_string (dpi));
 
209
    cerr << "TeXmacs] Metafont works with " << dpi << " dpi cm-fonts\n";
 
210
    return true;
 
211
  }
 
212
 
 
213
  return false;
 
214
}
 
215
 
 
216
static void
 
217
init_default_tex_settings () {
 
218
  set_setting ("DPI", "300");
 
219
  set_setting ("EC", "false");
 
220
  if (get_setting ("MAKEPK") != "false") {
 
221
    if (try_dpi (300, 123));
 
222
    else if (try_dpi (600, 234));
 
223
    else if (try_dpi (1200, 345));
 
224
    else cerr << "TeXmacs] Your mktexpk/MakeTeXPK does not seem to work\n";
 
225
  }
 
226
}
 
227
 
 
228
/******************************************************************************
 
229
* First installation
 
230
******************************************************************************/
 
231
 
 
232
void
 
233
init_first () {
 
234
  url settings_file= "$TEXMACS_HOME_PATH/system/settings.scm";
 
235
  cerr << "Welcome to TeXmacs " TEXMACS_VERSION "\n";
 
236
  cerr << HRULE;
 
237
  cerr << "Since this seems to be the first time you run this\n";
 
238
  cerr << "version of TeXmacs, I will first analyze your system\n";
 
239
  cerr << "in order to set up some TeX paths in the correct way.\n";
 
240
  cerr << "This may take some seconds; the result can be found in\n\n";
 
241
  cerr << "\t" << settings_file << "\n\n";
 
242
  cerr << HRULE;
 
243
 
 
244
  set_setting ("VERSION", TEXMACS_VERSION);
 
245
  init_helper_binaries ();
 
246
  init_heuristic_tex_paths ();
 
247
  init_default_tex_settings ();
 
248
  
 
249
  string s= scheme_tree_to_block (texmacs_settings);
 
250
  if (save_string (settings_file, s) || load_string (settings_file, s)) {
 
251
    cerr << HRULE;
 
252
    cerr << "I could not save or reload the file\n\n";
 
253
    cerr << "\t" << settings_file << "\n\n";
 
254
    cerr << "Please give me full access control over this file and\n";
 
255
    cerr << "rerun 'TeXmacs'.\n";
 
256
    cerr << HRULE;
 
257
    exit (1);
 
258
  }
 
259
  
 
260
  cerr << HRULE;
 
261
  cerr << "Installation completed successfully !\n";
 
262
  cerr << "I will now start up the editor\n";
 
263
  cerr << HRULE;
 
264
}