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