PageRenderTime 23ms CodeModel.GetById 10ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/TeXmacs-1.0.7.11-src/src/System/Boot/init_upgrade.cpp

#
C++ | 158 lines | 120 code | 16 blank | 22 comment | 33 complexity | e9817243b28d2a76d96f71bcc6414e57 MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, MPL-2.0-no-copyleft-exception
  1
  2/******************************************************************************
  3* MODULE     : init_upgrade.cpp
  4* DESCRIPTION: initializations which are only necessary when
  5*              you just upgraded your TeXmacs distribution
  6* COPYRIGHT  : (C) 1999  Joris van der Hoeven
  7*******************************************************************************
  8* This software falls under the GNU general public license version 3 or later.
  9* It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
 10* in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
 11******************************************************************************/
 12
 13#include "boot.hpp"
 14#include "file.hpp"
 15#include "path.hpp"
 16#include "sys_utils.hpp"
 17#include "data_cache.hpp"
 18
 19/******************************************************************************
 20* Old style settings files
 21******************************************************************************/
 22
 23static string
 24line_read (string s, int& i) {
 25  int start= i, n= N(s);
 26  for (start=i; i<n; i++)
 27    if (s[i]=='\n') break;
 28  string r= s (start, i);
 29  if (i<n) i++;
 30  return r;
 31}
 32
 33void
 34get_old_settings (string s) {
 35  int i= 0, j;
 36  while (i<N(s)) {
 37    string l= line_read (s, i);
 38    for (j=0; j<N(l); j++)
 39      if (l[j] == '=') {
 40	string left = l (0, j);
 41	while ((j<N(l)) && ((l[j]=='=') || (l[j]==' '))) j++;
 42	string right= l (j, N(l));
 43	set_setting (left, right);
 44      }
 45  }
 46}
 47
 48/******************************************************************************
 49* Check for old Init.scm and Init-buffer.scm files
 50******************************************************************************/
 51
 52static void
 53init_upgrade_scheme () {
 54#ifndef OS_WIN32
 55  url u= "$TEXMACS_HOME_PATH/progs";
 56  string prgs= as_string (u);
 57  if (exists (u * "Init.scm") && (!exists (u * "my-init-texmacs.scm"))) {
 58    system ("sed 's/Init.scm/init-texmacs.scm/'", u * "Init.scm",
 59	    ">", u * "my-init-texmacs.scm");
 60    remove (u * "Init.scm");
 61  }
 62  if (exists (u * "Init-buffer.scm") && (!exists (u * "my-init-buffer.scm"))) {
 63    system ("sed 's/Init-buffer.scm/init-buffer.scm/'", u * "Init-buffer.scm",
 64	    ">", u * "my-init-buffer.scm");
 65    remove (u * "Init-buffer.scm");
 66  }
 67#endif
 68}
 69
 70/******************************************************************************
 71* Generate documentation about changes
 72******************************************************************************/
 73
 74static string
 75string_load (url u) {
 76  string s;
 77  (void) load_string (u, s, false);
 78  return s;
 79}
 80
 81static void
 82init_upgrade_doc (string install_version) {
 83  url from_dir= "$TEXMACS_PATH/doc/about/changes";
 84  url to= "$TEXMACS_HOME_PATH/doc/about/changes/changes-recent.en.tm";
 85  string s= string_load (from_dir * "changes-pre.en.ptm");
 86  if (version_inf (install_version, "0.3.3.24"))
 87    s << string_load (from_dir * "changes-1.en.ptm");
 88  if (version_inf_eq (install_version, "0.3.4.9"))
 89    s << string_load (from_dir * "changes-2.en.ptm");
 90  if (version_inf_eq (install_version, "1.0.0.4"))
 91    s << string_load (from_dir * "changes-3.en.ptm");
 92  if (version_inf_eq (install_version, "1.0.0.6"))
 93    s << string_load (from_dir * "changes-4.en.ptm");
 94  if (version_inf_eq (install_version, "1.0.0.11"))
 95    s << string_load (from_dir * "changes-5.en.ptm");
 96  if (version_inf_eq (install_version, "1.0.2.0"))
 97    s << string_load (from_dir * "changes-6.en.ptm");
 98  if (version_inf_eq (install_version, "1.0.2.6"))
 99    s << string_load (from_dir * "changes-7.en.ptm");
100  if (version_inf_eq (install_version, "1.0.2.8"))
101    s << string_load (from_dir * "changes-8.en.ptm");
102  if (version_inf_eq (install_version, "1.0.3.4"))
103    s << string_load (from_dir * "changes-9.en.ptm");
104  if (version_inf_eq (install_version, "1.0.4"))
105    s << string_load (from_dir * "changes-10.en.ptm");
106  if (version_inf_eq (install_version, "1.0.5.9"))
107    s << string_load (from_dir * "changes-11.en.ptm");
108  if (version_inf_eq (install_version, "1.0.5.9"))
109    s << string_load (from_dir * "changes-12.en.ptm");
110  if (version_inf_eq (install_version, "1.0.5.9"))
111    s << string_load (from_dir * "changes-13.en.ptm");
112  if (version_inf_eq (install_version, "1.0.6.2"))
113    s << string_load (from_dir * "changes-14.en.ptm");
114  if (version_inf_eq (install_version, "1.0.7.6"))
115    s << string_load (from_dir * "changes-15.en.ptm");
116  if (version_inf_eq (install_version, "1.0.7.7"))
117    s << string_load (from_dir * "changes-16.en.ptm");
118  if (version_inf_eq (install_version, "1.0.7.8"))
119    s << string_load (from_dir * "changes-17.en.ptm");
120  if (version_inf_eq (install_version, "1.0.7.9")) {
121    s << string_load (from_dir * "changes-18.en.ptm");
122    s << string_load (from_dir * "changes-post.en.ptm");
123    save_string (to, s, false);
124  }
125  else remove (to);
126}
127
128/******************************************************************************
129* Upgrading TeXmacs
130******************************************************************************/
131
132void
133init_upgrade () {
134  string install_version= get_setting ("VERSION");
135
136  cerr << HRULE;
137  cerr << "Your disk contains a configuration file for TeXmacs-";
138  cerr << install_version << ".\n";
139  cerr << "I will now perform the upgrade to version " TEXMACS_VERSION "\n";
140  cerr << HRULE;
141
142  url old_settings= "$TEXMACS_HOME_PATH/system" * url_wildcard ("TEX_PATHS*");
143  url new_settings= "$TEXMACS_HOME_PATH/system/settings.scm";
144  remove (old_settings);
145  remove (new_settings);
146
147  setup_texmacs ();
148  init_upgrade_scheme ();
149  init_upgrade_doc (install_version);
150
151  remove (url ("$TEXMACS_HOME_PATH/system/setup.scm"));
152  remove (url ("$TEXMACS_HOME_PATH/system/cache") * url_wildcard ("__*"));
153  remove (url ("$TEXMACS_HOME_PATH/system/cache/dir_cache.scm"));
154  remove (url ("$TEXMACS_HOME_PATH/system/cache/doc_cache"));
155  remove (url ("$TEXMACS_HOME_PATH/system/cache/file_cache"));
156  remove (url ("$TEXMACS_HOME_PATH/system/cache/stat_cache.scm"));
157  cache_refresh ();
158}