1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23: #include <config.h>
24: #include <signal.h>
25: #include <errno.h>
26: #include <stdio.h>
27:
28: #include <sys/types.h>
29: #include <sys/file.h>
30:
31: #ifdef VMS
32: #include <ssdef.h>
33: #endif
34:
35: #ifdef HAVE_UNISTD_H
36: #include <unistd.h>
37: #endif
38:
39: #ifdef BSD_SYSTEM
40: #include <sys/ioctl.h>
41: #endif
42:
43: #ifdef WINDOWSNT
44: #include <fcntl.h>
45: #include <windows.h>
46: #include "w32.h"
47: #include "w32heap.h"
48: #endif
49:
50: #include "lisp.h"
51: #include "commands.h"
52: #include "intervals.h"
53: #include "buffer.h"
54: #include "window.h"
55:
56: #include "systty.h"
57: #include "blockinput.h"
58: #include "syssignal.h"
59: #include "process.h"
60: #include "termhooks.h"
61: #include "keyboard.h"
62: #include "keymap.h"
63:
64: #ifdef HAVE_SETLOCALE
65: #include <locale.h>
66: #endif
67:
68: #ifdef HAVE_SETRLIMIT
69: #include <sys/time.h>
70: #include <sys/resource.h>
71: #endif
72:
73: #ifdef HAVE_PERSONALITY_LINUX32
74: #include <sys/personality.h>
75: #endif
76:
77: #ifndef O_RDWR
78: #define O_RDWR 2
79: #endif
80:
81: #ifdef HAVE_SETPGID
82: #if !defined (USG) || defined (BSD_PGRPS)
83: #undef setpgrp
84: #define setpgrp setpgid
85: #endif
86: #endif
87:
88: extern void malloc_warning P_ ((char *));
89: extern void set_time_zone_rule P_ ((char *));
90: #ifdef HAVE_INDEX
91: extern char *index P_ ((const char *, int));
92: #endif
93:
94:
95:
96: #ifdef USE_LSB_TAG
97: int gdb_use_lsb = 1;
98: #else
99: int gdb_use_lsb = 0;
100: #endif
101: #ifdef NO_UNION_TYPE
102: int gdb_use_union = 0;
103: #else
104: int gdb_use_union = 1;
105: #endif
106: EMACS_INT gdb_valbits = VALBITS;
107: EMACS_INT gdb_gctypebits = GCTYPEBITS;
108: #ifdef DATA_SEG_BITS
109: EMACS_INT gdb_data_seg_bits = DATA_SEG_BITS;
110: #else
111: EMACS_INT gdb_data_seg_bits = 0;
112: #endif
113: EMACS_INT PVEC_FLAG = PSEUDOVECTOR_FLAG;
114: EMACS_INT gdb_array_mark_flag = ARRAY_MARK_FLAG;
115:
116:
117: enum pvec_type gdb_pvec_type = PVEC_TYPE_MASK;
118:
119:
120: Lisp_Object Vcommand_line_args;
121:
122:
123:
124: Lisp_Object Vinvocation_name;
125:
126:
127: Lisp_Object Vinvocation_directory;
128:
129:
130:
131: Lisp_Object Vinstallation_directory;
132:
133:
134: Lisp_Object Vkill_emacs_hook;
135:
136:
137: Lisp_Object empty_string;
138:
139:
140: Lisp_Object Vpath_separator;
141:
142:
143:
144:
145: int initialized;
146:
147: #ifdef DOUG_LEA_MALLOC
148:
149:
150: void *malloc_state_ptr;
151:
152: extern void *malloc_get_state ();
153:
154: extern int malloc_set_state ();
155:
156:
157: int malloc_using_checking;
158: #endif
159:
160:
161: Lisp_Object Vsystem_type;
162:
163:
164: Lisp_Object Vsystem_configuration;
165:
166:
167:
168: Lisp_Object Vsystem_configuration_options;
169:
170: Lisp_Object Qfile_name_handler_alist;
171:
172:
173: Lisp_Object Vsystem_messages_locale;
174: Lisp_Object Vprevious_system_messages_locale;
175: Lisp_Object Vsystem_time_locale;
176: Lisp_Object Vprevious_system_time_locale;
177:
178:
179:
180: int inhibit_window_system;
181:
182:
183:
184:
185: EMACS_INT emacs_priority;
186:
187:
188:
189: int running_asynch_code;
190:
191: #ifdef BSD_PGRPS
192:
193: extern int inherited_pgroup;
194: #endif
195:
196: #ifdef HAVE_X_WINDOWS
197:
198: int display_arg;
199: #endif
200:
201:
202:
203: char *stack_bottom;
204:
205:
206: static void *my_heap_start;
207:
208:
209: static unsigned long heap_bss_diff;
210:
211:
212:
213: #define MAX_HEAP_BSS_DIFF (1024*1024)
214:
215:
216: #ifdef HAVE_WINDOW_SYSTEM
217: extern Lisp_Object Vwindow_system;
218: #endif
219:
220: extern Lisp_Object Vauto_save_list_file_name;
221:
222: extern Lisp_Object Vinhibit_redisplay;
223:
224: #ifdef USG_SHARED_LIBRARIES
225:
226:
227:
228: unsigned int bss_end = 0;
229: #endif
230:
231:
232:
233: int noninteractive;
234:
235:
236:
237:
238:
239: int noninteractive1;
240:
241:
242: char **initial_argv;
243: int initial_argc;
244:
245: static void sort_args ();
246: void syms_of_emacs ();
247:
248:
249:
250: #define USAGE1 "\
251: Usage: %s [OPTION-OR-FILENAME]...\n\
252: \n\
253: Run Emacs, the extensible, customizable, self-documenting real-time\n\
254: display editor. The recommended way to start Emacs for normal editing\n\
255: is with no options at all.\n\
256: \n\
257: Run M-x info RET m emacs RET m emacs invocation RET inside Emacs to\n\
258: read the main documentation for these command-line arguments.\n\
259: \n\
260: Initialization options:\n\
261: \n\
262: --batch do not do interactive display; implies -q\n\
263: --debug-init enable Emacs Lisp debugger for init file\n\
264: --display, -d DISPLAY use X server DISPLAY\n\
265: --multibyte, --no-unibyte inhibit the effect of EMACS_UNIBYTE\n\
266: --no-desktop do not load a saved desktop\n\
267: --no-init-file, -q load neither ~/.emacs nor default.el\n\
268: --no-shared-memory, -nl do not use shared memory\n\
269: --no-site-file do not load site-start.el\n\
270: --no-splash do not display a splash screen on startup\n\
271: --no-window-system, -nw do not communicate with X, ignoring $DISPLAY\n\
272: --quick, -Q equivalent to -q --no-site-file --no-splash\n\
273: --script FILE run FILE as an Emacs Lisp script\n\
274: --terminal, -t DEVICE use DEVICE for terminal I/O\n\
275: --unibyte, --no-multibyte run Emacs in unibyte mode\n\
276: --user, -u USER load ~USER/.emacs instead of your own\n\
277: \n%s"
278:
279: #define USAGE2 "\
280: Action options:\n\
281: \n\
282: FILE visit FILE using find-file\n\
283: +LINE FILE visit FILE using find-file, then go to line LINE\n\
284: +LINE:COLUMN FILE visit FILE using find-file, then go to line LINE,\n\
285: column COLUMN\n\
286: --directory, -L DIR add DIR to variable load-path\n\
287: --eval EXPR evaluate Emacs Lisp expression EXPR\n\
288: --execute EXPR evaluate Emacs Lisp expression EXPR\n\
289: --file FILE visit FILE using find-file\n\
290: --find-file FILE visit FILE using find-file\n\
291: --funcall, -f FUNC call Emacs Lisp function FUNC with no arguments\n\
292: --insert FILE insert contents of FILE into current buffer\n\
293: --kill exit without asking for confirmation\n\
294: --load, -l FILE load Emacs Lisp FILE using the load function\n\
295: --visit FILE visit FILE using find-file\n\
296: \n"
297:
298: #define USAGE3 "\
299: Display options:\n\
300: \n\
301: --background-color, -bg COLOR window background color\n\
302: --basic-display, -D disable many display features;\n\
303: used for debugging Emacs\n\
304: --border-color, -bd COLOR main border color\n\
305: --border-width, -bw WIDTH width of main border\n\
306: --color, --color=MODE override color mode for character terminals;\n\
307: MODE defaults to `auto', and can also\n\
308: be `never', `auto', `always',\n\
309: or a mode name like `ansi8'\n\
310: --cursor-color, -cr COLOR color of the Emacs cursor indicating point\n\
311: --font, -fn FONT default font; must be fixed-width\n\
312: --foreground-color, -fg COLOR window foreground color\n\
313: --fullheight, -fh make the first frame high as the screen\n\
314: --fullscreen, -fs make first frame fullscreen\n\
315: --fullwidth, -fw make the first frame wide as the screen\n\
316: --geometry, -g GEOMETRY window geometry\n\
317: --no-bitmap-icon, -nbi do not use picture of gnu for Emacs icon\n\
318: --iconic start Emacs in iconified state\n\
319: --internal-border, -ib WIDTH width between text and main border\n\
320: --line-spacing, -lsp PIXELS additional space to put between lines\n\
321: --mouse-color, -ms COLOR mouse cursor color in Emacs window\n\
322: --name NAME title for initial Emacs frame\n\
323: --no-blinking-cursor, -nbc disable blinking cursor\n\
324: --reverse-video, -r, -rv switch foreground and background\n\
325: --title, -T TITLE title for initial Emacs frame\n\
326: --vertical-scroll-bars, -vb enable vertical scroll bars\n\
327: --xrm XRESOURCES set additional X resources\n\
328: --help display this help and exit\n\
329: --version output version information and exit\n\
330: \n"
331:
332: #define USAGE4 "\
333: You can generally also specify long option names with a single -; for\n\
334: example, -batch as well as --batch. You can use any unambiguous\n\
335: abbreviation for a --option.\n\
336: \n\
337: Various environment variables and window system resources also affect\n\
338: Emacs' operation. See the main documentation.\n\
339: \n\
340: Report bugs to %s. First, please see the Bugs\n\
341: section of the Emacs manual or the file BUGS.\n"
342:
343: ^L
344:
345: int fatal_error_code;
346:
347:
348: int fatal_error_in_progress;
349:
350:
351:
352:
353: void (*fatal_error_signal_hook) P_ ((void));
354:
355: #ifdef HAVE_GTK_AND_PTHREAD
356:
357:
358:
359:
360: pthread_t main_thread;
361: #endif
362:
363:
364:
365: SIGTYPE
366: fatal_error_signal (sig)
367: int sig;
368: {
369: SIGNAL_THREAD_CHECK (sig);
370: fatal_error_code = sig;
371: signal (sig, SIG_DFL);
372:
373: TOTALLY_UNBLOCK_INPUT;
374:
375:
376: if (! fatal_error_in_progress)
377: {
378: fatal_error_in_progress = 1;
379:
380: shut_down_emacs (sig, 0, Qnil);
381: }
382:
383: #ifdef VMS
384: LIB$STOP (SS$_ABORT);
385: #else
386:
387:
388:
389:
390: #ifndef MSDOS
391: sigunblock (sigmask (fatal_error_code));
392: #endif
393:
394: if (fatal_error_signal_hook)
395: fatal_error_signal_hook ();
396:
397: kill (getpid (), fatal_error_code);
398: #endif
399: }
400:
401: #ifdef SIGDANGER
402:
403:
404: SIGTYPE
405: memory_warning_signal (sig)
406: int sig;
407: {
408: signal (sig, memory_warning_signal);
409: SIGNAL_THREAD_CHECK (sig);
410:
411: malloc_warning ("Operating system warns that virtual memory is running low.\n");
412:
413:
414: force_auto_save_soon ();
415: }
416: #endif
417:
418:
419:
420:
421:
422: #if ! defined (DOS_NT) && ! defined (NO_ABORT)
423:
424: #ifndef ABORT_RETURN_TYPE
425: #define ABORT_RETURN_TYPE void
426: #endif
427:
428: ABORT_RETURN_TYPE
429: abort ()
430: {
431: kill (getpid (), SIGABRT);
432:
433: exit (1);
434: }
435: #endif
436:
437: ^L
438:
439:
440: static void
441: init_cmdargs (argc, argv, skip_args)
442: int argc;
443: char **argv;
444: int skip_args;
445: {
446: register int i;
447: Lisp_Object name, dir, tem;
448: int count = SPECPDL_INDEX ();
449: Lisp_Object raw_name;
450:
451: initial_argv = argv;
452: initial_argc = argc;
453:
454: raw_name = build_string (argv[0]);
455:
456:
457:
458: tem = Ffind_file_name_handler (raw_name, Qt);
459: if (! NILP (tem))
460: raw_name = concat2 (build_string ("/:"), raw_name);
461:
462: Vinvocation_name = Ffile_name_nondirectory (raw_name);
463: Vinvocation_directory = Ffile_name_directory (raw_name);
464:
465:
466:
467: if (NILP (Vinvocation_directory))
468: {
469: Lisp_Object found;
470: int yes = openp (Vexec_path, Vinvocation_name,
471: Vexec_suffixes, &found, make_number (X_OK));
472: if (yes == 1)
473: {
474:
475:
476: tem = Ffind_file_name_handler (found, Qt);
477: if (! NILP (tem))
478: found = concat2 (build_string ("/:"), found);
479: Vinvocation_directory = Ffile_name_directory (found);
480: }
481: }
482:
483: if (!NILP (Vinvocation_directory)
484: && NILP (Ffile_name_absolute_p (Vinvocation_directory)))
485:
486:
487: Vinvocation_directory = Fexpand_file_name (Vinvocation_directory, Qnil);
488:
489: Vinstallation_directory = Qnil;
490:
491: if (!NILP (Vinvocation_directory))
492: {
493: dir = Vinvocation_directory;
494: name = Fexpand_file_name (Vinvocation_name, dir);
495: while (1)
496: {
497: Lisp_Object tem, lib_src_exists;
498: Lisp_Object etc_exists, info_exists;
499:
500:
501:
502:
503: tem = Fexpand_file_name (build_string ("lib-src"), dir);
504: lib_src_exists = Ffile_exists_p (tem);
505:
506: #ifdef MSDOS
507:
508:
509:
510: tem = Fexpand_file_name (build_string ("info"), dir);
511: info_exists = Ffile_exists_p (tem);
512: #else
513: info_exists = Qnil;
514: #endif
515:
516: if (!NILP (lib_src_exists) || !NILP (info_exists))
517: {
518: tem = Fexpand_file_name (build_string ("etc"), dir);
519: etc_exists = Ffile_exists_p (tem);
520: if (!NILP (etc_exists))
521: {
522: Vinstallation_directory
523: = Ffile_name_as_directory (dir);
524: break;
525: }
526: }
527:
528:
529: tem = Fexpand_file_name (build_string ("../lib-src"), dir);
530: lib_src_exists = Ffile_exists_p (tem);
531:
532:
533: #ifdef MSDOS
534:
535: tem = Fexpand_file_name (build_string ("../info"), dir);
536: info_exists = Ffile_exists_p (tem);
537: #else
538: info_exists = Qnil;
539: #endif
540:
541: if (!NILP (lib_src_exists) || !NILP (info_exists))
542: {
543: tem = Fexpand_file_name (build_string ("../etc"), dir);
544: etc_exists = Ffile_exists_p (tem);
545: if (!NILP (etc_exists))
546: {
547: tem = Fexpand_file_name (build_string (".."), dir);
548: Vinstallation_directory
549: = Ffile_name_as_directory (tem);
550: break;
551: }
552: }
553:
554:
555:
556: tem = Ffile_symlink_p (name);
557: if (!NILP (tem))
558: {
559: name = Fexpand_file_name (tem, dir);
560: dir = Ffile_name_directory (name);
561: }
562: else
563: break;
564: }
565: }
566:
567: Vcommand_line_args = Qnil;
568:
569: for (i = argc - 1; i >= 0; i--)
570: {
571: if (i == 0 || i > skip_args)
572:
573:
574:
575: Vcommand_line_args
576: = Fcons (make_unibyte_string (argv[i], strlen (argv[i])),
577: Vcommand_line_args);
578: }
579:
580: unbind_to (count, Qnil);
581: }
582:
583: DEFUN ("invocation-name", Finvocation_name, Sinvocation_name, 0, 0, 0,
584: doc:
585: )
586: ()
587: {
588: return Fcopy_sequence (Vinvocation_name);
589: }
590:
591: DEFUN ("invocation-directory", Finvocation_directory, Sinvocation_directory,
592: 0, 0, 0,
593: doc: )
594: ()
595: {
596: return Fcopy_sequence (Vinvocation_directory);
597: }
598:
599: ^L
600: #ifdef VMS
601: #ifdef LINK_CRTL_SHARE
602: #ifdef SHARABLE_LIB_BUG
603: extern noshare char **environ;
604: #endif
605: #endif
606: #endif
607:
608: #ifdef HAVE_TZSET
609:
610:
611: static char dump_tz[] = "UtC0";
612: #endif
613:
614: #ifndef ORDINARY_LINK
615: