PageRenderTime 73ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 1ms

/src/emacs.c

https://bitbucket.org/jsparkes/xemacs-gtk
C | 4802 lines | 2771 code | 517 blank | 1514 comment | 292 complexity | 7b4f9ec6ca1b41c6835967e1d35d1582 MD5 | raw file
Possible License(s): GPL-3.0, BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. /* XEmacs -- Fully extensible Emacs, running on Unix and other platforms.
  2. Copyright (C) 1985, 1986, 1987, 1992, 1993, 1994
  3. Free Software Foundation, Inc.
  4. Copyright (C) 1995 Sun Microsystems, Inc.
  5. Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2010 Ben Wing.
  6. This file is part of XEmacs.
  7. XEmacs is free software: you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation, either version 3 of the License, or (at your
  10. option) any later version.
  11. XEmacs is distributed in the hope that it will be useful, but WITHOUT
  12. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  14. for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */
  17. /* Synched up with: Mule 2.0, FSF 19.28. */
  18. /* This file has been Mule-ized, Ben Wing, 10-7-04. */
  19. /* Capsule summary of the various releases of Lucid Emacs/XEmacs and
  20. FSF/GNU Emacs. (Copied from the Internals Manual, where the
  21. canonical version lives.) Provided here for use in cross-referencing
  22. version releases and dates in comments, esp. in the authorship
  23. comments at the beginning of each file. More information about
  24. history can be found in the beginning of the Internals Manual and
  25. in the About page.
  26. -- A time line for Lucid Emacs/XEmacs is
  27. Version 19.0 shipped with Energize 1.0, April 1992.
  28. Version 19.1 released June 4, 1992.
  29. Version 19.2 released June 19, 1992.
  30. Version 19.3 released September 9, 1992.
  31. Version 19.4 released January 21, 1993.
  32. Version 19.5 released February 5, 1993. This was a repackaging of 19.4 with a
  33. few bug fixes and shipped with Energize 2.0. It was a trade-show giveaway
  34. and never released to the net.
  35. Version 19.6 released April 9, 1993.
  36. Version 19.7 was a repackaging of 19.6 with a few bug fixes and
  37. shipped with Energize 2.1. Never released to the net.
  38. Version 19.8 released September 6, 1993. (Epoch merger, preliminary I18N
  39. support)
  40. Version 19.9 released January 12, 1994. (Scrollbars, Athena.)
  41. Version 19.10 released May 27, 1994. Known as "Lucid Emacs" when
  42. shipped by Lucid, and as "XEmacs" when shipped by Sun; but Lucid
  43. went out of business a few days later and it's unclear very many
  44. copies of 19.10 were released by Lucid. (Last release by Jamie Zawinski.)
  45. Version 19.11 (first XEmacs) released September 13, 1994.
  46. Version 19.12 released June 23, 1995.
  47. Version 19.13 released September 1, 1995.
  48. Version 19.14 released June 23, 1996.
  49. Version 20.0 released February 9, 1997.
  50. Version 19.15 released March 28, 1997.
  51. Version 20.1 (not released to the net) April 15, 1997.
  52. Version 20.2 released May 16, 1997.
  53. Version 19.16 released October 31, 1997; retiring of v19 series.
  54. Version 20.3 (the first stable version of XEmacs 20.x) released November 30,
  55. 1997.
  56. Version 20.4 released February 28, 1998. (Jamie claims this version is the
  57. "first reasonably stable release with MULE support" and says that "XEmacs
  58. 'core' and 'packages' now packaged separately.")
  59. Version 21.0-pre5 released July 18, 1998. (Jamie says "Numbering scheme goes
  60. wonky due to switch to stable + unstable branches.")
  61. Version 21.0.60 released December 10, 1998. (The version naming scheme was
  62. changed at this point: [a] the second version number is odd for stable
  63. versions, even for beta versions; [b] a third version number is added,
  64. replacing the "beta xxx" ending for beta versions and allowing for
  65. periodic maintenance releases for stable versions. Therefore, 21.0 was
  66. never "officially" released; similarly for 21.2, etc.)
  67. Version 21.0.61 released January 4, 1999.
  68. Version 21.0.63 released February 3, 1999.
  69. Version 21.0.64 released March 1, 1999.
  70. Version 21.0.65 released March 5, 1999.
  71. Version 21.0.66 released March 12, 1999.
  72. Version 21.0.67 released March 25, 1999.
  73. Version 21.1.2 released May 14, 1999; on comp.emacs, May 28. (This is
  74. the followup to 21.0.67. The second version number was bumped to indicate
  75. the beginning of the "stable" series.)
  76. Version 21.1.3 released June 26, 1999.
  77. Version 21.1.4 released July 8, 1999.
  78. Version 21.1.6 released August 14, 1999. (There was no 21.1.5.)
  79. Version 21.1.7 released September 26, 1999.
  80. Version 21.1.8 released November 2, 1999.
  81. Version 21.1.9 released February 13, 2000.
  82. Version 21.1.10 released May 7, 2000.
  83. Version 21.1.10a released June 24, 2000.
  84. Version 21.1.11 released July 18, 2000.
  85. Version 21.1.12 released August 5, 2000.
  86. Version 21.1.13 released January 7, 2001.
  87. Version 21.1.14 released January 27, 2001.
  88. Version 21.2.9 released February 3, 1999.
  89. Version 21.2.10 released February 5, 1999.
  90. Version 21.2.11 released March 1, 1999.
  91. Version 21.2.12 released March 5, 1999.
  92. Version 21.2.13 released March 12, 1999.
  93. Version 21.2.14 released May 14, 1999.
  94. Version 21.2.15 released June 4, 1999.
  95. Version 21.2.16 released June 11, 1999.
  96. Version 21.2.17 released June 22, 1999.
  97. Version 21.2.18 released July 14, 1999.
  98. Version 21.2.19 released July 30, 1999.
  99. Version 21.2.20 released November 10, 1999.
  100. Version 21.2.21 released November 28, 1999.
  101. Version 21.2.22 released November 29, 1999.
  102. Version 21.2.23 released December 7, 1999.
  103. Version 21.2.24 released December 14, 1999.
  104. Version 21.2.25 released December 24, 1999.
  105. Version 21.2.26 released December 31, 1999.
  106. Version 21.2.27 released January 18, 2000.
  107. Version 21.2.28 released February 7, 2000.
  108. Version 21.2.29 released February 16, 2000.
  109. Version 21.2.30 released February 21, 2000.
  110. Version 21.2.31 released February 23, 2000.
  111. Version 21.2.32 released March 20, 2000.
  112. Version 21.2.33 released May 1, 2000.
  113. Version 21.2.34 released May 28, 2000.
  114. Version 21.2.35 released July 19, 2000.
  115. Version 21.2.36 released October 4, 2000.
  116. Version 21.2.37 released November 14, 2000.
  117. Version 21.2.38 released December 5, 2000.
  118. Version 21.2.39 released December 31, 2000.
  119. Version 21.2.40 released January 8, 2001.
  120. Version 21.2.41 "Polyhymnia" released January 17, 2001.
  121. Version 21.2.42 "Poseidon" released January 20, 2001.
  122. Version 21.2.43 "Terspichore" released January 26, 2001.
  123. Version 21.2.44 "Thalia" released February 8, 2001.
  124. Version 21.2.45 "Thelxepeia" released February 23, 2001.
  125. Version 21.2.46 "Urania" released March 21, 2001.
  126. Version 21.2.47 "Zephir" released April 14, 2001.
  127. Version 21.4.0 "Solid Vapor" released April 16, 2001.
  128. Version 21.4.1 "Copyleft" released April 19, 2001.
  129. Version 21.4.2 "Developer-Friendly Unix APIs" released May 10, 2001.
  130. Version 21.4.3 "Academic Rigor" released May 17, 2001.
  131. Version 21.4.4 "Artificial Intelligence" released July 28, 2001.
  132. Version 21.4.5 "Civil Service" released October 23, 2001.
  133. Version 21.4.6 "Common Lisp" released December 17, 2001.
  134. Version 21.4.7 "Economic Science" released May 4, 2002.
  135. Version 21.4.8 "Honest Recruiter" released May 9, 2002.
  136. Version 21.4.9 "Informed Management" released August 23, 2002.
  137. Version 21.4.10 "Military Intelligence" released November 2, 2002.
  138. Version 21.4.11 "Native Windows TTY Support" released January 3, 2003.
  139. Version 21.4.12 "Portable Code" released January 15, 2003.
  140. Version 21.4.13 "Rational FORTRAN" released May 25, 2003.
  141. Version 21.4.14 "Reasonable Discussion" released September 3, 2003.
  142. Version 21.4.15 "Security Through Obscurity" released February 2, 2004.
  143. Version 21.5.0 "alfalfa" released April 18, 2001.
  144. Version 21.5.1 "anise" released May 9, 2001.
  145. Version 21.5.2 "artichoke" released July 28, 2001.
  146. Version 21.5.3 "asparagus" released September 7, 2001.
  147. Version 21.5.4 "bamboo" released January 8, 2002.
  148. Version 21.5.5 "beets" released March 5, 2002.
  149. Version 21.5.6 "bok choi" released April 5, 2002.
  150. Version 21.5.7 "broccoflower" released July 2, 2002.
  151. Version 21.5.8 "broccoli" released July 27, 2002.
  152. Version 21.5.9 "brussels sprouts" released August 30, 2002.
  153. Version 21.5.10 "burdock" released January 4, 2003.
  154. Version 21.5.11 "cabbage" released February 16, 2003.
  155. Version 21.5.12 "carrot" released April 24, 2003.
  156. Version 21.5.13 "cauliflower" released May 10, 2003.
  157. Version 21.5.14 "cassava" released June 1, 2003.
  158. Version 21.5.15 "celery" released September 3, 2003.
  159. Version 21.5.16 "celeriac" released September 26, 2003.
  160. Version 21.5.17 "chayote" released March 22, 2004.
  161. Version 21.5.18 "chestnut" released October 22, 2004.
  162. -- A time line for GNU Emacs version 19 is
  163. version 19.7 (beta) (first beta release) released ??????; prob. late May 1993.
  164. version 19.8 (beta) released May 27, 1993.
  165. version 19.9 (beta) released May 27, 1993.
  166. version 19.10 (beta) released May 30, 1993.
  167. version 19.11 (beta) released June 1, 1993.
  168. version 19.12 (beta) released June 2, 1993.
  169. version 19.13 (beta) released June 8, 1993.
  170. version 19.14 (beta) released June 17, 1993.
  171. version 19.15 (beta) released June 19, 1993.
  172. version 19.16 (beta) released July 6, 1993.
  173. version 19.17 (beta) released late July, 1993.
  174. version 19.18 (beta) released August 9, 1993.
  175. version 19.19 (beta) released August 15, 1993.
  176. version 19.20 (beta) released November 17, 1993.
  177. version 19.21 (beta) released November 17, 1993.
  178. version 19.22 (beta) released November 28, 1993.
  179. version 19.23 (beta) released on comp.emacs, May 17, 1994.
  180. version 19.24 (beta) released May 16, 1994.
  181. version 19.25 (beta) released June 3, 1994.
  182. version 19.26 (beta) released September 11, 1994.
  183. version 19.27 (beta) released September 14, 1994.
  184. version 19.28 (first ``official'' release) released November 1, 1994.
  185. version 19.29 released June 21, 1995.
  186. version 19.30 released November 24, 1995.
  187. version 19.31 released May 25, 1996.
  188. version 19.32 released July 31, 1996.
  189. version 19.33 released August 11, 1996.
  190. version 19.34 released August 21, 1996; on comp.emacs, August 22.
  191. version 19.34b released September 6, 1996.
  192. -- A time line for GNU Emacs versions 20 and 21 is
  193. version 20.1 released September 17, 1997.
  194. version 20.2 released September 20, 1997.
  195. version 20.3 released August 19, 1998.
  196. version 20.4 released July 12, 1999; on comp.emacs, July 27.
  197. version 21.1 released October 20, 2001.
  198. Version 21.2 released March 16, 2002.
  199. Version 21.3 released March 19, 2003.
  200. -- A time line for GNU Emacs version 18 and older is
  201. GNU Emacs version 15 (15.34) was released sometime in 1984 or 1985 and
  202. shared some code with a version of Emacs written by James Gosling (the
  203. same James Gosling who later created the Java language).
  204. GNU Emacs version 16 (first released version was 16.56) was released on
  205. July 15, 1985. All Gosling code was removed due to potential copyright
  206. problems with the code.
  207. version 16.57: released on September 16, 1985.
  208. versions 16.58, 16.59: released on September 17, 1985.
  209. version 16.60: released on September 19, 1985. These later version 16's
  210. incorporated patches from the net, esp. for getting Emacs to work under
  211. System V.
  212. version 17.36 (first official v17 release) released on December 20, 1985.
  213. Included a TeX-able user manual. First official unpatched version that
  214. worked on vanilla System V machines.
  215. version 17.43 (second official v17 release) released on January 25, 1986.
  216. version 17.45 released on January 30, 1986.
  217. version 17.46 released on February 4, 1986.
  218. version 17.48 released on February 10, 1986.
  219. version 17.49 released on February 12, 1986.
  220. version 17.55 released on March 18, 1986.
  221. version 17.57 released on March 27, 1986.
  222. version 17.58 released on April 4, 1986.
  223. version 17.61 released on April 12, 1986.
  224. version 17.63 released on May 7, 1986.
  225. version 17.64 released on May 12, 1986.
  226. version 18.24 (a beta version) released on October 2, 1986.
  227. version 18.30 (a beta version) released on November 15, 1986.
  228. version 18.31 (a beta version) released on November 23, 1986.
  229. version 18.32 (a beta version) released on December 7, 1986.
  230. version 18.33 (a beta version) released on December 12, 1986.
  231. version 18.35 (a beta version) released on January 5, 1987.
  232. version 18.36 (a beta version) released on January 21, 1987.
  233. January 27, 1987: The Great Usenet Renaming. net.emacs is now comp.emacs.
  234. version 18.37 (a beta version) released on February 12, 1987.
  235. version 18.38 (a beta version) released on March 3, 1987.
  236. version 18.39 (a beta version) released on March 14, 1987.
  237. version 18.40 (a beta version) released on March 18, 1987.
  238. version 18.41 (the first ``official'' release) released on March 22, 1987.
  239. version 18.45 released on June 2, 1987.
  240. version 18.46 released on June 9, 1987.
  241. version 18.47 released on June 18, 1987.
  242. version 18.48 released on September 3, 1987.
  243. version 18.49 released on September 18, 1987.
  244. version 18.50 released on February 13, 1988.
  245. version 18.51 released on May 7, 1988.
  246. version 18.52 released on September 1, 1988.
  247. version 18.53 released on February 24, 1989.
  248. version 18.54 released on April 26, 1989.
  249. version 18.55 released on August 23, 1989. This is the earliest version
  250. that is still available by FTP.
  251. version 18.56 released on January 17, 1991.
  252. version 18.57 released late January, 1991.
  253. version 18.58 released ?????.
  254. version 18.59 released October 31, 1992.
  255. -- A time line for Epoch is
  256. Epoch 1.0 released December 14, 1989. (by Simon Kaplan, Chris Love, et al.)
  257. Epoch 2.0 released December 23, 1989.
  258. Epoch 3.1 released February 6, 1990.
  259. Epoch 3.2 released December[????] 11, 1990.
  260. Epoch 4.0 released August 27, 1990.
  261. */
  262. /* Sources for further information:
  263. -----------------------------------
  264. 1. Using XEmacs, Programming Elisp:
  265. -----------------------------------
  266. ;;; -- the XEmacs User's Manual (Access using the online Info browser:
  267. ;;; Use `Help->Info (Online Docs)->XEmacs User's Manual' (if
  268. ;;; there is such an entry); or get to the Info contents page
  269. ;;; using `Help->Info Contents' or `C-h i', and then
  270. ;;; *middle-click* the XEmacs link or move the cursor into the
  271. ;;; link and hit ENTER. This manual contains a great deal of
  272. ;;; documentation on customization: Scroll down to the
  273. ;;; Customization link and select it in the same fashion as for
  274. ;;; the XEmacs link just mentioned.)
  275. ;;; -- the XEmacs FAQ (`C-h F' for the local version; get either the
  276. ;;; local version or the very latest version off the net using
  277. ;;; the Help menu)
  278. ;;; -- the XEmacs Lisp Reference Manual, containing detailed
  279. ;;; documentation on Elisp. (Access using Info, just like for the
  280. ;;; XEmacs User's Manual.)
  281. ;;; -- the documentation strings for specific commands, functions,
  282. ;;; key sequences, and variables. NOTE: This is *not* the same
  283. ;;; information as in the XEmacs User's Manual or XEmacs Lisp
  284. ;;; Reference Manual! In general, the doc strings are more
  285. ;;; terse and more up-to-date than what is found in the manuals.
  286. ;;; Once you understand the general concepts, these doc strings
  287. ;;; should be your first point of reference for further
  288. ;;; info. (Access using menu entries under `Help->Commands,
  289. ;;; Variables, Keys' or using the keyboard: `C-h k' for a key
  290. ;;; sequence, `C-h f' for a named command or Elisp function,
  291. ;;; `C-h v' for a variable. There is various other useful
  292. ;;; information accessible similarly, such as `C-h a'
  293. ;;; ["Apropos", i.e. search for a command, function, or variable
  294. ;;; by name]; `C-h C-a' ["Apropos Docs", i.e. search through the
  295. ;;; text of the doc strings]; `C-h b' to list all key bindings;
  296. ;;; `C-h m' to describe the current major and minor modes; etc.
  297. ;;; Type `C-h ? ?' for a complete list.)
  298. ;;; -- Getting Started with XEmacs [aka the "New User's Guide"], a
  299. ;;; more introductory manual than the XEmacs User's Manual.
  300. ;;; (Access using Info, just like for the XEmacs User's Manual.
  301. ;;; There are some sections on customization here.)
  302. ;;; -- the XEmacs tutorial, a very simple introduction to XEmacs for
  303. ;;; total beginners. (`C-h t' for English; get the version in
  304. ;;; various languages from the Help menu)
  305. ;;; -- the XEmacs web site, www.xemacs.org.
  306. ;;; -- the XEmacs mailing lists (xemacs-FOO@xemacs.org;
  307. ;;; see http://www.xemacs.org/Lists/ for more info. Before
  308. ;;; posting, consider looking through the archives -- they go back
  309. ;;; years and there is a powerful searching interface. Currently
  310. ;;; the archives are at http://list-archive.xemacs.org/, but if
  311. ;;; this doesn't work, you can always access them through
  312. ;;; www.xemacs.org.)
  313. ;;; -- the XEmacs newsgroup, comp.emacs.xemacs. This is
  314. ;;; bi-directionally gatewayed with xemacs@xemacs.org. WARNING:
  315. ;;; The developers do not normally hang out on this newsgroup. If
  316. ;;; you need to contact them, use xemacs-beta@xemacs.org.
  317. ;;; -- the XEmacs internals manual, for those interested in working on
  318. ;;; the XEmacs C code. (Available through Info.)
  319. ;;; -- `Help->About XEmacs' to find out who the maintainers are.
  320. ---------------------
  321. 2. Developing XEmacs:
  322. ---------------------
  323. -- the internals manual, man/internals/internals.texi
  324. -- long comments at the head of certain files:
  325. emacs.c
  326. extents.c
  327. text.c
  328. text.h
  329. lisp.h
  330. redisplay.h
  331. dynarr.c
  332. blocktype.c
  333. eval.c
  334. event-Xt.c (sort of)
  335. event-stream.c (command event queue)
  336. frame.c
  337. intl-encap-win32.c
  338. keymap.c
  339. line-number.c (a little bit)
  340. menubar-msw.c (sort of)
  341. menubar-x.c (sort of)
  342. mule-canna.c (sort of)
  343. mule-ccl.c
  344. mule-coding.c (scattered in the file)
  345. mule-wnn.c (in japanese)
  346. ntheap.c (near the top)
  347. redisplay.c (various scattered)
  348. regex.c (various scattered)
  349. sysdep.c (maybe; wait_for_termination)
  350. unexec.c
  351. unicode.c
  352. gccache-x.c (a bit)
  353. #### review .h files; write a perl program to look for long comments
  354. throughout the files, ignoring stuff inside of DEFUN's.
  355. #### elsewhere?
  356. -- comments scattered throughout the sources (#### should be grouped
  357. together if feasible). For example, lrecord.h (pdump and object-
  358. creation), alloc.c (fixed-type allocation), etc. #### fill in.
  359. -- Ben's Architecting XEmacs web site.
  360. (http://www.xemacs.org/Architecting-XEmacs/index.html; #### should be
  361. integrated into the sources)
  362. -- Back discussions on xemacs-beta (#### The juiciest tidbits, esp.
  363. those with specific proposals, should be extracted and stuck in
  364. the source)
  365. -- README.* in the src/ directory (and maybe other directories)
  366. -- The ChangeLog files, sometimes.
  367. */
  368. /* Note: It is necessary to specify <config.h> and not "config.h" in
  369. order for the --srcdir type of compilation to work properly.
  370. Otherwise the config.h from the srcdir, rather than the one from
  371. the build dir, will be used. */
  372. #include <config.h>
  373. #include "lisp.h"
  374. #include "backtrace.h" /* run-emacs-from-temacs needs this */
  375. #include "buffer.h"
  376. #include "commands.h"
  377. #include "console.h"
  378. #include "process.h"
  379. #include "redisplay.h"
  380. #include "frame.h"
  381. #include "sysdep.h"
  382. #include "systty.h"
  383. #include "sysfile.h"
  384. #include "systime.h"
  385. #include "sysproc.h" /* for qxe_getpid() */
  386. #ifdef QUANTIFY
  387. #include <quantify.h>
  388. #endif
  389. #ifdef HAVE_SHLIB
  390. #include "sysdll.h"
  391. #endif
  392. #ifdef TOOLTALK
  393. #include TT_C_H_FILE
  394. #endif
  395. #ifdef WIN32_ANY
  396. #include "console-msw.h"
  397. #endif
  398. #ifdef DUMP_IN_EXEC
  399. #ifndef WIN32_NATIVE
  400. #include "dump-data.h"
  401. #endif
  402. #endif
  403. /* For PATH_EXEC */
  404. #include <paths.h>
  405. #if defined (HEAP_IN_DATA) && !defined (PDUMP)
  406. void report_sheap_usage (int die_if_pure_storage_exceeded);
  407. #endif
  408. #if !defined (SYSTEM_MALLOC) && !defined (DOUG_LEA_MALLOC)
  409. extern void *(*__malloc_hook)(size_t);
  410. extern void *(*__realloc_hook)(void *, size_t);
  411. extern void (*__free_hook)(void *);
  412. #endif /* not SYSTEM_MALLOC && not DOUG_LEA_MALLOC */
  413. /* Command line args from shell, as list of strings */
  414. Lisp_Object Vcommand_line_args;
  415. /* Set nonzero after XEmacs has started up the first time.
  416. Prevents reinitialization of the Lisp world and keymaps
  417. on subsequent starts. */
  418. int initialized;
  419. #ifdef DOUG_LEA_MALLOC
  420. # include <malloc.h>
  421. /* Preserves a pointer to the memory allocated that copies that
  422. static data inside glibc's malloc. */
  423. static void *malloc_state_ptr;
  424. #endif /* DOUG_LEA_MALLOC */
  425. # ifdef REL_ALLOC
  426. void r_alloc_reinit (void);
  427. # endif
  428. /* Variable whose value is symbol giving operating system type. */
  429. Lisp_Object Vsystem_type;
  430. /* Variable whose value is string giving configuration built for. */
  431. Lisp_Object Vsystem_configuration;
  432. /* Variable whose value is string containing the configuration options
  433. XEmacs was built with. */
  434. Lisp_Object Vsystem_configuration_options;
  435. /* Version numbers and strings */
  436. Lisp_Object Vemacs_major_version;
  437. Lisp_Object Vemacs_minor_version;
  438. Lisp_Object Vemacs_patch_level;
  439. Lisp_Object Vemacs_beta_version;
  440. Lisp_Object Vxemacs_codename;
  441. Lisp_Object Vxemacs_extra_name;
  442. Lisp_Object Vxemacs_release_date;
  443. /* The path under which XEmacs was invoked. */
  444. Lisp_Object Vinvocation_path;
  445. /* The name under which XEmacs was invoked, with any leading directory
  446. names discarded. */
  447. Lisp_Object Vinvocation_name;
  448. /* The directory name from which XEmacs was invoked. */
  449. Lisp_Object Vinvocation_directory;
  450. #if 0 /* FSFmacs */
  451. /* The directory name in which to find subdirs such as lisp and etc.
  452. nil means get them only from PATH_LOADSEARCH. */
  453. Lisp_Object Vinstallation_directory;
  454. #endif
  455. Lisp_Object Vemacs_program_name, Vemacs_program_version;
  456. Lisp_Object Vexec_path;
  457. Lisp_Object Vexec_directory, Vconfigure_exec_directory;
  458. Lisp_Object Vlisp_directory, Vconfigure_lisp_directory;
  459. Lisp_Object Vmule_lisp_directory, Vconfigure_mule_lisp_directory;
  460. Lisp_Object Vmodule_directory, Vconfigure_module_directory;
  461. Lisp_Object Vsite_module_directory, Vconfigure_site_module_directory;
  462. Lisp_Object Vconfigure_package_path;
  463. Lisp_Object Vconfigure_early_package_directories;
  464. Lisp_Object Vconfigure_late_package_directories;
  465. Lisp_Object Vconfigure_last_package_directories;
  466. Lisp_Object Vdata_directory, Vconfigure_data_directory;
  467. Lisp_Object Vdoc_directory, Vconfigure_doc_directory;
  468. Lisp_Object Vconfigure_lock_directory;
  469. Lisp_Object Vdata_directory_list;
  470. Lisp_Object Vconfigure_info_directory;
  471. Lisp_Object Vsite_directory, Vconfigure_site_directory;
  472. Lisp_Object Vconfigure_info_path;
  473. Lisp_Object Vinternal_error_checking;
  474. Lisp_Object Vmail_lock_methods, Vconfigure_mail_lock_method;
  475. /* The default base directory XEmacs is installed under. */
  476. Lisp_Object Vconfigure_exec_prefix_directory, Vconfigure_prefix_directory;
  477. /* If nonzero, set XEmacs to run at this priority. This is also used
  478. in child_setup and sys_suspend to make sure subshells run at normal
  479. priority. */
  480. Fixnum emacs_priority;
  481. /* Some FSF junk with running_asynch_code, to preserve the match
  482. data. Not necessary because we don't call process filters
  483. asynchronously (i.e. from within QUIT). */
  484. /* If non-zero, a window-system was specified on the command line. */
  485. int display_arg;
  486. /* Type of display specified. We cannot use a Lisp symbol here because
  487. Lisp symbols may not initialized at the time that we set this
  488. variable. */
  489. const Ascbyte *display_use;
  490. /* If non-zero, then the early error handler will only print the error
  491. message and exit. */
  492. int suppress_early_error_handler_backtrace;
  493. /* An address near the bottom of the stack.
  494. Tells GC how to save a copy of the stack. */
  495. Rawbyte *stack_bottom;
  496. #ifdef USG_SHARED_LIBRARIES
  497. /* If nonzero, this is the place to put the end of the writable segment
  498. at startup. */
  499. uintptr_t bss_end = 0;
  500. #endif
  501. /* Number of bytes of writable memory we can expect to be able to get:
  502. Leave this as an unsigned int because it could potentially be 4G */
  503. unsigned long lim_data;
  504. /* WARNING!
  505. Some LISP-visible command-line options are set by XEmacs _before_ the
  506. data is dumped in building a --pdump XEmacs, but used _after_ it is
  507. restored in normal operation. Thus the dump-time values overwrite the
  508. values XEmacs is getting at runtime. Such variables must be saved
  509. before loading the dumpfile, and restored afterward.
  510. Therefore these variables may not be initialized in vars_of_emacs().
  511. The save/restore is done immediately before and after pdump_load() in
  512. main_1(). See that function for the current list of protected variables.
  513. Note that saving/restoring is only necessary for a few variables that are
  514. o command line arguments effective at runtime (as opposed to dump-time),
  515. o parsed before pdump_load, and
  516. o exported to Lisp via a DEFVAR.
  517. */
  518. /* Nonzero means running XEmacs without interactive terminal. */
  519. int noninteractive;
  520. /* Value of Lisp variable `noninteractive'.
  521. Normally same as C variable `noninteractive'
  522. but nothing terrible happens if user sets this one.
  523. Shadowed from the pdumper by `noninteractive'. */
  524. int noninteractive1;
  525. /* Nonzero means don't perform site-lisp searches at startup */
  526. int inhibit_site_lisp;
  527. /* Nonzero means don't perform site-modules searches at startup */
  528. int inhibit_site_modules;
  529. /* Nonzero means don't load user-init or site-start file */
  530. int vanilla_inhibiting;
  531. /* Nonzero means don't respect early packages at startup */
  532. int inhibit_early_packages;
  533. /* Nonzero means don't respect any packages at startup -- act as if they
  534. don't exist. */
  535. int inhibit_all_packages;
  536. /* Nonzero means don't load package autoloads at startup */
  537. int inhibit_autoloads;
  538. /* Nonzero means don't load the dump file (ignored if not PDUMP) */
  539. int nodumpfile;
  540. /* Nonzero means print debug information about path searching */
  541. int debug_paths;
  542. /* Save argv and argc. */
  543. static Wexttext **initial_argv; /* #### currently unused */
  544. static int initial_argc; /* #### currently unused */
  545. static void sort_args (int argc, Wexttext **argv);
  546. Lisp_Object Qkill_emacs_hook;
  547. Lisp_Object Qsave_buffers_kill_emacs;
  548. Lisp_Object Qtemacs, Qdumping, Qrestarted, Qpdump, Qbatch;
  549. /* Nonzero if handling a fatal error already. */
  550. int fatal_error_in_progress;
  551. /* Nonzero means we're going down, so we better not run any hooks
  552. or do other non-essential stuff. */
  553. int preparing_for_armageddon;
  554. /* Nonzero means we're in an unstable situation and need to skip
  555. internal->external conversions, QUIT checking and such. This gets set
  556. during early startup, during shutdown, and when debug printing
  557. (i.e. called from a debugger such as gdb to print Lisp objects or
  558. backtraces). During printing we check for this, and during conversion
  559. we abort if we see this. */
  560. int inhibit_non_essential_conversion_operations;
  561. static JMP_BUF run_temacs_catch;
  562. static int run_temacs_argc;
  563. static Wexttext **run_temacs_argv;
  564. #ifdef _MSC_VER
  565. static DWORD mswindows_handle_hardware_exceptions (DWORD code);
  566. #endif
  567. #ifdef WIN32_NATIVE
  568. static DWORD CALLBACK wait_for_termination_signal (LPVOID handle);
  569. #endif
  570. /************************************************************************/
  571. /* Functions to handle arguments */
  572. /************************************************************************/
  573. /* Code for dealing with Lisp access to the Unix command line */
  574. static Lisp_Object
  575. make_arg_list_1 (int argc, Wexttext **argv, int skip_args)
  576. {
  577. Lisp_Object result = Qnil;
  578. REGISTER int i;
  579. for (i = argc - 1; i >= 0; i--)
  580. {
  581. if (i == 0 || i > skip_args)
  582. {
  583. #ifdef WIN32_NATIVE
  584. if (i == 0)
  585. {
  586. /* Do not trust to what crt0 has stuffed into argv[0] */
  587. Extbyte *full_exe_path;
  588. Lisp_Object fullpath;
  589. full_exe_path = mswindows_get_module_file_name ();
  590. assert (full_exe_path);
  591. fullpath = build_tstr_string (full_exe_path);
  592. xfree (full_exe_path);
  593. result = Fcons (fullpath, result);
  594. }
  595. else
  596. #endif
  597. result = Fcons (build_wext_string (argv[i],
  598. Qcommand_argument_encoding),
  599. result);
  600. }
  601. }
  602. return result;
  603. }
  604. Lisp_Object
  605. make_arg_list (int argc, Wexttext **argv)
  606. {
  607. return make_arg_list_1 (argc, argv, 0);
  608. }
  609. /* Calling functions are also responsible for calling free_argc_argv
  610. when they are done with the generated list. */
  611. void
  612. make_argc_argv (Lisp_Object argv_list, int *argc, Wexttext ***argv)
  613. {
  614. Lisp_Object next;
  615. int n = XFIXNUM (Flength (argv_list));
  616. REGISTER int i;
  617. *argv = xnew_array (Wexttext *, n + 1);
  618. for (i = 0, next = argv_list; i < n; i++, next = XCDR (next))
  619. {
  620. CHECK_STRING (XCAR (next));
  621. (*argv)[i] =
  622. (Wexttext *) LISP_STRING_TO_EXTERNAL_MALLOC
  623. (XCAR (next), Qcommand_argument_encoding);
  624. }
  625. (*argv) [n] = 0;
  626. *argc = i;
  627. }
  628. void
  629. free_argc_argv (Wexttext **argv)
  630. {
  631. int elt = 0;
  632. while (argv[elt])
  633. {
  634. xfree (argv[elt]);
  635. argv[elt] = 0;
  636. elt++;
  637. }
  638. xfree (argv);
  639. }
  640. static void
  641. init_cmdargs (int argc, Wexttext **argv, int skip_args)
  642. {
  643. initial_argv = argv;
  644. initial_argc = argc;
  645. Vcommand_line_args = make_arg_list_1 (argc, argv, skip_args);
  646. }
  647. DEFUN ("invocation-name", Finvocation_name, 0, 0, 0, /*
  648. Return the program name that was used to run XEmacs.
  649. Any directory names are omitted.
  650. */
  651. ())
  652. {
  653. return Fcopy_sequence (Vinvocation_name);
  654. }
  655. DEFUN ("invocation-directory", Finvocation_directory, 0, 0, 0, /*
  656. Return the directory name in which the Emacs executable was located.
  657. */
  658. ())
  659. {
  660. return Fcopy_sequence (Vinvocation_directory);
  661. }
  662. /* Test whether the next argument in ARGV matches SSTR or a prefix of LSTR
  663. (at least MINLEN characters; if MINLEN is 0, set to size of LSTR). If
  664. so, then if VALPTR is non-null (the argument is supposed to have a
  665. value) store in *VALPTR either the next argument or the portion of this
  666. one after the equal sign. ARGV is read starting at position *SKIPPTR;
  667. this index is advanced by the number of arguments used.
  668. Too bad we can't just use getopt for all of this, but we don't have
  669. enough information to do it right. */
  670. static int
  671. argmatch (Wexttext **argv, int argc, const Ascbyte *sstr, const Ascbyte *lstr,
  672. int minlen, Wexttext **valptr, int *skipptr)
  673. {
  674. Wexttext *p = NULL;
  675. Charcount arglen;
  676. Wexttext *arg;
  677. /* Don't access argv[argc]; give up in advance. */
  678. if (argc <= *skipptr + 1)
  679. return 0;
  680. arg = argv[*skipptr+1];
  681. if (arg == NULL)
  682. return 0;
  683. if (wext_strcmp_ascii (arg, sstr) == 0)
  684. {
  685. if (valptr != NULL)
  686. {
  687. *valptr = argv[*skipptr+2];
  688. *skipptr += 2;
  689. }
  690. else
  691. *skipptr += 1;
  692. return 1;
  693. }
  694. arglen = (valptr != NULL && (p = wext_strchr (arg, '=')) != NULL
  695. ? p - arg : (Charcount) wext_strlen (arg));
  696. if (lstr && !minlen)
  697. minlen = strlen (lstr);
  698. if (lstr == 0 || arglen < minlen ||
  699. wext_strncmp_ascii (arg, lstr, arglen) != 0)
  700. return 0;
  701. else if (valptr == NULL)
  702. {
  703. *skipptr += 1;
  704. return 1;
  705. }
  706. else if (p != NULL)
  707. {
  708. *valptr = p + 1;
  709. *skipptr += 1;
  710. return 1;
  711. }
  712. else if (argv[*skipptr + 2] != NULL)
  713. {
  714. *valptr = argv[*skipptr + 2];
  715. *skipptr += 2;
  716. return 1;
  717. }
  718. else
  719. {
  720. return 0;
  721. }
  722. }
  723. static void
  724. check_compatible_window_system (const Ascbyte *must)
  725. {
  726. if (display_use && strcmp (display_use, must))
  727. fatal ("Incompatible window system type `%s': `%s' already specified",
  728. must, display_use);
  729. display_use = must;
  730. }
  731. /************************************************************************/
  732. /* main and friends: XEmacs startup */
  733. /************************************************************************/
  734. /* Make stack traces always identify version + configuration */
  735. #define main_1 STACK_TRACE_EYE_CATCHER
  736. /* This function is not static, so that the compiler is less likely to
  737. inline it, which would make it not show up in stack traces.
  738. The restart argument is a flag that indicates that main_1 is now
  739. being called for the second time in this invocation of xemacs; this
  740. happens as a result of using `run-temacs' in the command line, when
  741. invoking a bare (without dumped data) XEmacs (i.e. `temacs' with
  742. the conventional dumper or `xemacs -nd' with the pdumper). See
  743. Frun_emacs_from_temacs().
  744. */
  745. DECLARE_DOESNT_RETURN (main_1 (int, Wexttext **, Wexttext **, int));
  746. DOESNT_RETURN
  747. main_1 (int argc, Wexttext **argv, Wexttext **UNUSED (envp), int restart)
  748. {
  749. Rawbyte stack_bottom_variable;
  750. int skip_args = 0;
  751. Lisp_Object load_me;
  752. #if (!defined (SYSTEM_MALLOC) && !defined (HAVE_LIBMCHECK) \
  753. && !defined (DOUG_LEA_MALLOC))
  754. /* Make sure that any libraries we link against haven't installed a
  755. hook for a gmalloc of a potentially incompatible version. */
  756. /* If we're using libmcheck, the hooks have already been initialized, */
  757. /* don't touch them. -slb */
  758. __malloc_hook = NULL;
  759. __realloc_hook = NULL;
  760. __free_hook = NULL;
  761. #endif /* not SYSTEM_MALLOC or HAVE_LIBMCHECK or DOUG_LEA_MALLOC */
  762. noninteractive = 0;
  763. display_use = NULL;
  764. inhibit_non_essential_conversion_operations = 1;
  765. #ifdef NEW_GC
  766. #ifndef PDUMP
  767. if (!initialized)
  768. #endif
  769. {
  770. if (!restart)
  771. {
  772. init_mc_allocator ();
  773. #ifdef ALLOC_TYPE_STATS
  774. init_lrecord_stats ();
  775. #endif /* ALLOC_TYPE_STATS */
  776. }
  777. }
  778. #endif /* NEW_GC */
  779. #if defined (LOSING_GCC_DESTRUCTOR_FREE_BUG)
  780. /* Prior to XEmacs 21, this was `#if 0'ed out. */
  781. /* I'm enabling this because it is the only reliable way I've found to */
  782. /* prevent a very annoying problem where GCC will attempt to free (3) */
  783. /* memory at exit() and cause a coredump. */
  784. init_free_hook ();
  785. #endif
  786. #define SHEBANG_PROGNAME_LENGTH \
  787. (int)((sizeof (WEXTSTRING (SHEBANG_PROGNAME)) - sizeof (WEXTSTRING (""))))
  788. #define SHEBANG_EXE_PROGNAME_LENGTH \
  789. (int)(sizeof (WEXTSTRING (SHEBANG_PROGNAME) WEXTSTRING (".exe")) \
  790. - sizeof (WEXTSTRING ("")))
  791. {
  792. int progname_len = wext_strlen (argv[0]);
  793. if (progname_len >= SHEBANG_PROGNAME_LENGTH)
  794. {
  795. if (!wext_strcmp_ascii (argv[0] +
  796. (progname_len - SHEBANG_PROGNAME_LENGTH),
  797. SHEBANG_PROGNAME)
  798. /* Allow trailing .exe. Don't check it, it could also be
  799. .com. */
  800. || (progname_len >= SHEBANG_EXE_PROGNAME_LENGTH &&
  801. !wext_strncmp_ascii
  802. (argv[0] + (progname_len - SHEBANG_EXE_PROGNAME_LENGTH),
  803. SHEBANG_PROGNAME,
  804. SHEBANG_PROGNAME_LENGTH)))
  805. {
  806. Wexttext **newarr = alloca_array (Wexttext *, argc + 2);
  807. int j;
  808. newarr[0] = argv[0];
  809. newarr[1] = (Wexttext *) WEXTSTRING ("--script");
  810. for (j = 1; j < argc; ++j)
  811. {
  812. newarr[j + 1] = argv[j];
  813. }
  814. argv = newarr;
  815. argc++;
  816. }
  817. }
  818. }
  819. sort_args (argc, argv);
  820. #if 0 /* defined (_SCO_DS)
  821. #### Turn this off, we already have another SCO_DS hack in main().
  822. */
  823. environ = envp;
  824. #endif
  825. /* Record (approximately) where the stack begins. */
  826. stack_bottom = &stack_bottom_variable;
  827. #ifdef USG_SHARED_LIBRARIES
  828. if (bss_end)
  829. brk ((void *) bss_end);
  830. #endif
  831. clearerr (stdin);
  832. #if defined (HAVE_MMAP) && defined (REL_ALLOC)
  833. /* ralloc can only be used if using the GNU memory allocator. */
  834. init_ralloc ();
  835. #elif defined (REL_ALLOC) && !defined (DOUG_LEA_MALLOC)
  836. if (initialized)
  837. init_ralloc ();
  838. #endif
  839. #ifdef HAVE_SOCKS
  840. if (initialized)
  841. SOCKSinit (argv[0]);
  842. #endif /* HAVE_SOCKS */
  843. #ifndef SYSTEM_MALLOC
  844. if (!initialized)
  845. /* Arrange to get warning messages as memory fills up. */
  846. memory_warnings (0, malloc_warning);
  847. #endif /* not SYSTEM_MALLOC */
  848. #ifdef SET_EMACS_PRIORITY
  849. if (emacs_priority != 0)
  850. nice (-emacs_priority);
  851. setuid (getuid ());
  852. #endif /* SET_EMACS_PRIORITY */
  853. /* NOTE NOTE NOTE: Keep the following args in sync with the big list of
  854. arguments below in standard_args[], with the help text in startup.el,
  855. and with the list of non-clobbered variables near where pdump_load()
  856. is called! */
  857. /* Handle the -sd/--show-dump-id switch, which means show the hex dump_id
  858. and quit */
  859. if (argmatch (argv, argc, "-sd", "--show-dump-id", 0, NULL, &skip_args))
  860. {
  861. #ifdef PDUMP
  862. printf ("%08x\n", dump_id);
  863. #else
  864. printf ("Portable dumper not configured; -sd just forces exit.\n");
  865. #endif
  866. exit (0);
  867. }
  868. /* Handle the -si/--show-inline-info switch, which means show the
  869. alignment and max size of the inline data and quit */
  870. if (argmatch (argv, argc, "-si", "--show-inline-info", 0, NULL, &skip_args))
  871. {
  872. #if defined (PDUMP) && defined (DUMP_IN_EXEC) && !defined (WIN32_NATIVE)
  873. /* #### We really should check for sizeof (size_t) > sizeof (long) */
  874. printf ("%lu %lu\n", (unsigned long) dumped_data_max_size (),
  875. (unsigned long) dumped_data_align_offset ());
  876. #else
  877. printf ("Portable dumper not configured for dumping into executable or windows native; -si just forces exit.\n");
  878. #endif
  879. exit (0);
  880. }
  881. /* Handle the --no-dump-file/-nd switch, which means don't load the dump
  882. file (ignored when not using pdump) */
  883. if (argmatch (argv, argc, "-nd", "--no-dump-file", 0, NULL, &skip_args))
  884. nodumpfile = 1;
  885. /* Handle the -batch switch, which means don't do interactive display. */
  886. if (argmatch (argv, argc, "-batch", "--batch", 0, NULL, &skip_args))
  887. {
  888. #if 0 /* I don't think this is correct. */
  889. inhibit_autoloads = 1;
  890. #endif
  891. noninteractive = 1;
  892. }
  893. {
  894. int count_before = skip_args;
  895. /* Handle the -script switch, which implies batch and vanilla. The -l
  896. part of its functionality is implemented in Lisp. */
  897. if (argmatch (argv, argc, "-script", "--script", 0, NULL,
  898. &skip_args))
  899. {
  900. noninteractive = 1;
  901. vanilla_inhibiting = 1;
  902. }
  903. /* Don't actually discard this argument. */
  904. skip_args = count_before;
  905. }
  906. #ifdef WIN32_NATIVE
  907. {
  908. /* Since we aren't a console application, we can't easily be terminated
  909. using ^C. (We aren't a console application to avoid Windows from
  910. automatically and unwantedly creating a console window for us. If
  911. only the Windows designers had some sense in them and didn't create
  912. this artificial console/non-console distinction!) Therefore, we set
  913. up a communication path with i.exe so that when a ^C is sent to it
  914. (using GenerateConsoleCtrlEvent), it in turn signals us to commit
  915. suicide. (This is cleaner than using TerminateProcess()). This
  916. makes (e.g.) the "Stop Build" command from VC++ correctly terminate
  917. XEmacs. */
  918. Wexttext *heventstr;
  919. if (argmatch (argv, argc, "-mswindows-termination-handle", 0, 0,
  920. &heventstr, &skip_args))
  921. {
  922. HANDLE hevent = (HANDLE) wext_atol (heventstr);
  923. DWORD unused;
  924. HANDLE h_thread = CreateThread (NULL, 0, wait_for_termination_signal,
  925. (void *) hevent, 0, &unused);
  926. CloseHandle (h_thread);
  927. }
  928. }
  929. /* Handle the -nuni switch, which forces XEmacs to use the ANSI
  930. versions of Unicode-split API's even on Windows NT, which has
  931. full Unicode support. This helps flush out problems in the code
  932. we've written to convert between ANSI and Unicode. */
  933. if (argmatch (argv, argc, "-nuni", "--no-unicode-lib-calls", 0, NULL,
  934. &skip_args))
  935. no_mswin_unicode_lib_calls = 1;
  936. #endif /* WIN32_NATIVE */
  937. if (argmatch (argv, argc, "-debug-paths", "--debug-paths",
  938. 0, NULL, &skip_args))
  939. debug_paths = 1;
  940. /* Handle (maybe partially) some inhibiting flags. Packages are searched
  941. prior to the rest of the command line being parsed in startup.el. */
  942. if (argmatch (argv, argc, "-no-packages", "--no-packages",
  943. 0, NULL, &skip_args))
  944. {
  945. inhibit_all_packages = 1;
  946. inhibit_early_packages = 1;
  947. vanilla_inhibiting = 1;
  948. }
  949. if (argmatch (argv, argc, "-no-early-packages", "--no-early-packages",
  950. 0, NULL, &skip_args))
  951. inhibit_early_packages = 1;
  952. #ifdef HAVE_SHLIB
  953. if (argmatch (argv, argc, "-no-site-modules", "--no-site-modules",
  954. 0, NULL, &skip_args))
  955. #endif
  956. inhibit_site_modules = 1;
  957. if (argmatch (argv, argc, "-vanilla", "--vanilla",
  958. 0, NULL, &skip_args))
  959. {
  960. inhibit_early_packages = 1;
  961. vanilla_inhibiting = 1;
  962. }
  963. if (argmatch (argv, argc, "-no-autoloads", "--no-autoloads",
  964. 0, NULL, &skip_args))
  965. {
  966. inhibit_autoloads = 1;
  967. inhibit_early_packages = 1;
  968. vanilla_inhibiting = 1;
  969. }
  970. /* Partially handle the -version and -help switches: they imply -batch,
  971. but are not removed from the list. */
  972. if (argmatch (argv, argc, "-help", "--help", 3, NULL, &skip_args))
  973. noninteractive = 1, skip_args--;
  974. if (argmatch (argv, argc, "-version", "--version", 3, NULL, &skip_args) ||
  975. argmatch (argv, argc, "-V", 0, 2, NULL, &skip_args))
  976. noninteractive = 1, skip_args--;
  977. /* Now, figure out which type of console is our first console. */
  978. if (noninteractive)
  979. display_use = "stream";
  980. if (argmatch (argv, argc, "-nw", "--no-windows", 0, NULL, &skip_args) ||
  981. argmatch (argv, argc, "-tty", "--use-tty", 0, NULL, &skip_args))
  982. {
  983. check_compatible_window_system ("tty");
  984. #ifndef HAVE_TTY
  985. fatal ("Sorry, this XEmacs was not compiled with TTY support");
  986. #endif
  987. }
  988. if (argmatch (argv, argc, "-x", "--use-x", 0, NULL, &skip_args))
  989. {
  990. check_compatible_window_system ("x");
  991. #ifndef HAVE_X_WINDOWS
  992. fatal ("Sorry, this XEmacs was not compiled with X support");
  993. #endif
  994. }
  995. if (argmatch (argv, argc, "-gtk", "--use-gtk", 0, NULL, &skip_args) ||
  996. argmatch (argv, argc, "-gnome", "--use-gnome", 0, NULL, &skip_args))
  997. {
  998. check_compatible_window_system ("gtk");
  999. #ifndef HAVE_GTK
  1000. fatal ("Sorry, this XEmacs was not compiled with GTK support");
  1001. #endif
  1002. }
  1003. if (argmatch (argv, argc, "-msw", "--use-ms-windows", 0, NULL, &skip_args))
  1004. {
  1005. check_compatible_window_system ("mswindows");
  1006. #ifndef HAVE_MS_WINDOWS
  1007. fatal ("Sorry, this XEmacs was not compiled with MS Windows support");
  1008. #endif
  1009. }
  1010. /* Handle other switches implying particular window systems: */
  1011. /* Handle the -t switch, which specifies filename to use as terminal */
  1012. {
  1013. Wexttext *term;
  1014. if (argmatch (argv, argc, "-t", "--terminal", 0, &term, &skip_args))
  1015. {
  1016. int fd;
  1017. check_compatible_window_system ("tty");
  1018. #ifndef HAVE_TTY
  1019. fatal ("Sorry, this XEmacs was not compiled with TTY support");
  1020. #endif
  1021. retry_close (0);
  1022. retry_close (1);
  1023. fd = wext_retry_open (term, O_RDWR | OPEN_BINARY, 2);
  1024. /* Conversions are not possible yet, and printing will be in
  1025. external format, so strerror() and ttyname() are OK. */
  1026. if (fd < 0 || dup (0) < 0)
  1027. fatal ("%s: %s", WEXTTEXT_TO_8_BIT (term), strerror (errno));
  1028. if (! isatty (0))
  1029. fatal ("%s: not a tty", WEXTTEXT_TO_8_BIT (term));
  1030. #if 0
  1031. stderr_out ("Using %s", ttyname (0));
  1032. #endif
  1033. stderr_out ("Using %s", WEXTTEXT_TO_8_BIT (term));
  1034. }
  1035. }
  1036. /* Stupid kludge to catch command-line display spec. We can't
  1037. handle this argument entirely in window-system-dependent code
  1038. because we don't even know which window-system-dependent code
  1039. to run until we've recognized this argument. */
  1040. {
  1041. #ifdef HAVE_X_WINDOWS
  1042. Wexttext *dpy = 0;
  1043. int count_before = skip_args;
  1044. if (argmatch (argv, argc, "-d", "--display", 3, &dpy, &skip_args) ||
  1045. argmatch (argv, argc, "-display", 0, 3, &dpy, &skip_args))
  1046. {
  1047. check_compatible_window_system ("x");
  1048. display_arg = 1;
  1049. }
  1050. /* If we have the form --display=NAME,
  1051. convert it into -d name.
  1052. This requires inserting a new element into argv. */
  1053. if (dpy != 0 && skip_args - count_before == 1)
  1054. {
  1055. Wexttext **new_ = xnew_array (Wexttext *, argc + 2);
  1056. int j;
  1057. for (j = 0; j < count_before + 1; j++)
  1058. new_[j] = argv[j];
  1059. new_[count_before + 1] = (Wexttext *) WEXTSTRING ("-d");
  1060. new_[count_before + 2] = dpy;
  1061. for (j = count_before + 2; j <argc; j++)
  1062. new_[j + 1] = argv[j];
  1063. argv = new_;
  1064. argc++;
  1065. }
  1066. /* Change --display to -d, when its arg is separate. */
  1067. else if (dpy != 0 && skip_args > count_before
  1068. && argv[count_before + 1][1] == '-')
  1069. argv[count_before + 1] = (Wexttext *) WEXTSTRING ("-d");
  1070. /* Don't actually discard this arg. */
  1071. skip_args = count_before;
  1072. #endif /* HAVE_X_WINDOWS */
  1073. }
  1074. /* If no switch telling us which window system to use, try other
  1075. possibilities: */
  1076. #if defined (HAVE_X_WINDOWS) || defined (HAVE_GTK)
  1077. if (!display_use)
  1078. {
  1079. Wexttext *dpy;
  1080. /* If there is a non-empty environment var DISPLAY, assume X or GTK,
  1081. but don't set `display_arg', which is only to be set if the
  1082. display was specified on the command line. */
  1083. if ((dpy = wext_getenv (WEXTSTRING ("DISPLAY"))) && dpy[0])
  1084. #ifdef HAVE_X_WINDOWS
  1085. /* #### Who gets precedence? X or GTK? For the moment, GTK support is
  1086. unstable so use X. Maybe eventually we will switch this. */
  1087. display_use = "x";
  1088. #else
  1089. display_use = "gtk";
  1090. #endif
  1091. }
  1092. #endif /* defined (HAVE_X_WINDOWS) || defined (HAVE_GTK) */
  1093. #ifdef HAVE_MS_WINDOWS
  1094. if (!display_use)
  1095. display_use = "mswindows";
  1096. #endif /* HAVE_MS_WINDOWS */
  1097. #ifdef HAVE_TTY
  1098. if (!display_use)
  1099. display_use = "tty";
  1100. #endif /* HAVE_MS_WINDOWS */
  1101. if (!display_use)
  1102. fatal ("No window systems and no TTY's in this XEmacs: Must specify "
  1103. "-batch");
  1104. noninteractive1 = noninteractive;
  1105. /****** Now initialize everything *******/
  1106. /* NOTE NOTE NOTE:
  1107. In the code below, there are three different states we are concerned
  1108. about:
  1109. "raw-temacs" == No dumped Lisp data present. `temacs', or (with pdump)
  1110. `xemacs -nd'.
  1111. "run-temacs" == We are restarting. run-emacs-from-temacs is called,
  1112. aka `run-temacs' on the command line.
  1113. "post-dump" == We are running an unexec()ed XEmacs, or we have loaded
  1114. dump data using pdump_load().
  1115. initialized==0 => raw-temacs
  1116. initialized!=0 && restart!=0 => run-temacs
  1117. initialized!=0 && restart==0 => post-dump
  1118. When post-pdump_load(), we need to reinitialize various structures.
  1119. This case is noted in the code below by
  1120. initialized +
  1121. !restart +
  1122. ifdef PDUMP.
  1123. In the comments below, "dump time" or "dumping" == raw-temacs.
  1124. "run time" == run-temacs or post-dump.
  1125. */
  1126. /* First, do really basic environment initialization -- catching signals
  1127. and the like. These functions have no dependence on any part of
  1128. the Lisp engine and need to be done both at dump time and at run time. */
  1129. init_signals_very_early ();
  1130. #ifdef NEW_GC
  1131. vdb_install_signal_handler ();
  1132. #endif /* NEW_GC */
  1133. init_data_very_early (); /* Catch math errors. */
  1134. init_floatfns_very_early (); /* Catch floating-point math errors. */
  1135. init_process_times_very_early (); /* Initialize our process timers.
  1136. As early as possible, of course,
  1137. so we can be fairly accurate. */
  1138. #ifdef HAVE_MS_WINDOWS
  1139. /* Depends on XEUNICODE_P */
  1140. init_mswindows_dde_very_early (); /* DDE needs to be initialized early so
  1141. that the client doesn't give up
  1142. waiting. */
  1143. #endif
  1144. /* Now initialize the Lisp engine and the like. Done only during
  1145. dumping. No dependence on anything that may be in the user's
  1146. environment when the dumped XEmacs is run.
  1147. We try to do things in an order that minimizes the non-obvious
  1148. dependencies between functions. */
  1149. /* purify_flag is set to indicate we are dumping (its name refers to
  1150. purespace, which no longer exists and was a way of marking some
  1151. areas read-only so they could be shared among many processes).
  1152. loadup.el will set to nil at end. */
  1153. purify_flag = 0;
  1154. #ifdef PDUMP
  1155. in_pdump = 0;
  1156. if (restart)
  1157. initialized = 1;
  1158. else if (nodumpfile)
  1159. {
  1160. initialized = 0;
  1161. purify_flag = 1;
  1162. }
  1163. else
  1164. {
  1165. /* Keep command options from getting stomped.
  1166. Some LISP-visible options are changed by XEmacs _after_ the data is
  1167. dumped in building a --pdump XEmacs, but _before_ it is restored in
  1168. normal operation. Thus the restored values overwrite the values
  1169. XEmacs is getting at run-time. Such variables must be saved here,
  1170. and restored after loading the dumped data.
  1171. (Remember: Only LISP-visible options that are set up to this point
  1172. need to be listed here.)
  1173. */
  1174. /* noninteractive1 is saved in noninteractive, which isn't
  1175. LISP-visible */
  1176. int inhibit_early_packages_save = inhibit_early_packages;
  1177. int inhibit_autoloads_save = inhibit_autoloads;
  1178. int inhibit_all_packages_save = inhibit_all_packages;
  1179. int vanilla_inhibiting_save = vanilla_inhibiting;
  1180. int debug_paths_save = debug_paths;
  1181. int inhibit_site_lisp_save = inhibit_site_lisp;
  1182. int inhibit_site_modules_save = inhibit_site_modules;
  1183. initialized = pdump_load (argv[0]);
  1184. /* Now unstomp everything */
  1185. noninteractive1 = noninteractive;
  1186. inhibit_early_packages = inhibit_early_packages_save;
  1187. inhibit_autoloads = inhibit_autoloads_save;
  1188. inhibit_all_packages = inhibit_all_packages_save;
  1189. vanilla_inhibiting = vanilla_inhibiting_save;
  1190. debug_paths = debug_paths_save;
  1191. inhibit_site_lisp = inhibit_site_lisp_save;
  1192. inhibit_site_modules = inhibit_site_modules_save;
  1193. if (initialized)
  1194. run_temacs_argc = -1;
  1195. else
  1196. purify_flag = 1;
  1197. }
  1198. #else /* not PDUMP */
  1199. if (!initialized)
  1200. purify_flag = 1;
  1201. #endif
  1202. init_alloc_early ();
  1203. init_gc_early ();
  1204. if (!initialized)
  1205. {
  1206. /* Initialize things so that new Lisp objects
  1207. can be created and objects can be staticpro'd.
  1208. Must be basically the very first thing done
  1209. because pretty much all of the initialization
  1210. routines below create new objects. */
  1211. init_alloc_once_early ();
  1212. init_gc_once_early ();
  1213. /* Initialize Qnil, Qt, Qunbound, and the
  1214. obarray. After this, symbols can be
  1215. interned. This depends on init_alloc_once_early(). */
  1216. init_symbols_once_early ();
  1217. /* Declare the basic symbols pertaining to errors,
  1218. So that DEFERROR*() can be called. */
  1219. init_errors_once_early ();
  1220. /* Make sure that opaque pointers can be created. */
  1221. init_opaque_once_early ();
  1222. /* Make sure that hash tables can be created. */
  1223. init_elhash_once_early ();
  1224. /* Make sure that eistrings can be crea…

Large files files are truncated, but you can click here to view the full file