Partially sync files.el from XEmacs 21.5 for wildcard support.
[sxemacs] / src / emacs.c
index c47e6a7..8feec5d 100644 (file)
@@ -3,7 +3,7 @@
    Free Software Foundation, Inc.
    Copyright (C) 1995 Sun Microsystems, Inc.
    Copyright (C) 2000, 2002 Ben Wing.
    Free Software Foundation, Inc.
    Copyright (C) 1995 Sun Microsystems, Inc.
    Copyright (C) 2000, 2002 Ben Wing.
-   Copyright (C) 2004 Steve Youngs.
+   Copyright (C) 2004, 2015 Steve Youngs.
 
 This file is part of SXEmacs
 
 
 This file is part of SXEmacs
 
@@ -174,7 +174,7 @@ version 18.59 released October 31, 1992.
 #include "sysdep.h"
 
 #include "syssignal.h"         /* Always include before systty.h */
 #include "sysdep.h"
 
 #include "syssignal.h"         /* Always include before systty.h */
-#include "ui/systty.h"
+#include "ui/TTY/systty.h"
 #include "sysfile.h"
 #include "systime.h"
 
 #include "sysfile.h"
 #include "systime.h"
 
@@ -229,10 +229,6 @@ extern void *GC_init(void);
 # endif
 #endif /* HAVE_BDWGC */
 
 # endif
 #endif /* HAVE_BDWGC */
 
-#if defined (HEAP_IN_DATA) && !defined(PDUMP)
-void report_sheap_usage(int die_if_pure_storage_exceeded);
-#endif
-
 #if !defined (SYSTEM_MALLOC) && !defined (DOUG_LEA_MALLOC)
 extern void *(*__malloc_hook) (size_t);
 extern void *(*__realloc_hook) (void *, size_t);
 #if !defined (SYSTEM_MALLOC) && !defined (DOUG_LEA_MALLOC)
 extern void *(*__malloc_hook) (size_t);
 extern void *(*__realloc_hook) (void *, size_t);
@@ -313,7 +309,7 @@ Lisp_Object Vconfigure_info_directory;
 Lisp_Object Vconfigure_info_path;
 Lisp_Object Vinternal_error_checking;
 Lisp_Object Vmail_lock_methods, Vconfigure_mail_lock_method;
 Lisp_Object Vconfigure_info_path;
 Lisp_Object Vinternal_error_checking;
 Lisp_Object Vmail_lock_methods, Vconfigure_mail_lock_method;
-Lisp_Object Vpath_separator;
+Lisp_Object Vpath_separator, Vuser_packages_topdir;
 
 /* The default base directory SXEmacs is installed under. */
 Lisp_Object Vconfigure_exec_prefix_directory, Vconfigure_prefix_directory;
 
 /* The default base directory SXEmacs is installed under. */
 Lisp_Object Vconfigure_exec_prefix_directory, Vconfigure_prefix_directory;
@@ -337,6 +333,12 @@ int display_arg;
    variable. */
 const char *display_use;
 
    variable. */
 const char *display_use;
 
+/* Directory specified on the command line for user packages
+   (early-packages).  We cannot use a Lisp symbol here because Lisp
+   symbols may not be initialised at the time that we set this. */
+const char *user_pkgd;
+int upkgd = 0;
+
 /* If non-zero, then the early error handler will only print the error
    message and exit. */
 int suppress_early_error_handler_backtrace;
 /* If non-zero, then the early error handler will only print the error
    message and exit. */
 int suppress_early_error_handler_backtrace;
@@ -825,9 +827,9 @@ make_docfile(int c, char **v)
        /* set up the program call */
        xstrncpy(mdocfile,
                 (char*)XSTRING_DATA(Vexec_directory),
        /* set up the program call */
        xstrncpy(mdocfile,
                 (char*)XSTRING_DATA(Vexec_directory),
-                XSTRING_LENGTH(Vexec_directory));
-       xstrncpy(mdocfile+XSTRING_LENGTH(Vexec_directory),
-                make_docfile_prog, countof(make_docfile_prog));
+                sizeof(mdocfile));
+       xstrncpy(mdocfile+edlen,
+                make_docfile_prog, sizeof(mdocfile)-edlen);
 
        /* find the --make-docfile option */
        for (p = v; *p; p++) {
 
        /* find the --make-docfile option */
        for (p = v; *p; p++) {
@@ -868,16 +870,16 @@ __sys_stk_sz(void)
 {
 /* return the stack size limit */
 #if defined HAVE_GETRLIMIT64
 {
 /* return the stack size limit */
 #if defined HAVE_GETRLIMIT64
-       struct rlimit64 foo;
-       (void)getrlimit64(RLIMIT_STACK, &foo);
+       struct rlimit64 rlim;
+       (void)getrlimit64(RLIMIT_STACK, &rlim);
 #elif defined HAVE_GETRLIMIT
 #elif defined HAVE_GETRLIMIT
-       struct rlimit foo;
-       (void)getrlimit(RLIMIT_STACK, &foo);
+       struct rlimit rlim;
+       (void)getrlimit(RLIMIT_STACK, &rlim);
 #else
        /* bollocks, maybe just a small one? 64k? */
 #else
        /* bollocks, maybe just a small one? 64k? */
-       struct {size_t rlim_cur;} foo = {65536};
+       struct {size_t rlim_cur;} rlim = {65536};
 #endif
 #endif
-       return foo.rlim_cur;
+       return rlim.rlim_cur;
 }
 
 
 }
 
 
@@ -1022,9 +1024,9 @@ DOESNT_RETURN main_1(int argc, char **argv, char **envp, int restart)
 
        /* Handle the -sd/--show-dump-id switch, which means show the hex
           dump_id and quit */
 
        /* Handle the -sd/--show-dump-id switch, which means show the hex
           dump_id and quit */
-       if (argmatch(argv, argc,
-                    "-sd", "--show-dump-id",
-                    9, NULL, &skip_args)) {
+       if (argmatch(argv, argc, "-show-dump-id", "--show-dump-id", 9,
+                    NULL, &skip_args)
+           || argmatch(argv, argc, "-sd", 0, 3, NULL, &skip_args)) {
 #ifdef PDUMP
                printf("%08x\n", dump_id);
 #else
 #ifdef PDUMP
                printf("%08x\n", dump_id);
 #else
@@ -1038,7 +1040,8 @@ DOESNT_RETURN main_1(int argc, char **argv, char **envp, int restart)
        {
                char *term;
                if (argmatch
        {
                char *term;
                if (argmatch
-                   (argv, argc, "-t", "--terminal", 4, &term, &skip_args)) {
+                   (argv, argc, "-terminal", "--terminal", 4, &term, &skip_args)
+                   || argmatch(argv, argc, "-t", 0, 2, &term, &skip_args)) {
                        int tdesc = -1;
 #ifdef HAVE_TTYNAME
                        stderr_out("Opening for terminal usage %s (current: %s)\n", term, ttyname(0));
                        int tdesc = -1;
 #ifdef HAVE_TTYNAME
                        stderr_out("Opening for terminal usage %s (current: %s)\n", term, ttyname(0));
@@ -1087,19 +1090,24 @@ DOESNT_RETURN main_1(int argc, char **argv, char **envp, int restart)
 
        /* Handle the --no-dump-file/-nd switch, which means don't
         * load the dump file (ignored when not using pdump) */
 
        /* Handle the --no-dump-file/-nd switch, which means don't
         * load the dump file (ignored when not using pdump) */
-       if (argmatch(argv, argc, "-nd", "--no-dump-file", 7,
-                    NULL, &skip_args)) {
+       if (argmatch(argv, argc, "-no-dump-file", "--no-dump-file", 7,
+                    NULL, &skip_args)
+           || argmatch(argv, argc, "-nd", 0, 3, NULL, &skip_args)) {
                nodumpfile = 1;
        }
 
                nodumpfile = 1;
        }
 
-       if (argmatch(argv, argc, "-ct", "--color-terminal", 5,
-                    NULL, &skip_args)) {
+       if (argmatch(argv, argc, "-color-terminal", "--color-terminal", 5,
+                    NULL, &skip_args)
+           || argmatch(argv, argc, "-ct", 0, 3, NULL, &skip_args)) {
                assume_colorterm = 1;
        }
 
        /* Handle -nw switch */
                assume_colorterm = 1;
        }
 
        /* Handle -nw switch */
-       if (argmatch(argv, argc, "-nw", "--no-windows", 6, NULL, &skip_args))
+       if (argmatch(argv, argc, "-no-windows", "--no-windows", 6, NULL,
+                    &skip_args)
+           || argmatch(argv, argc, "-nw", 0, 3, NULL, &skip_args)) {
                inhibit_window_system = 1;
                inhibit_window_system = 1;
+       }
 
        /* Handle the -batch switch, which means don't do interactive display */
        if (argmatch(argv, argc, "-batch", "--batch", 5, NULL, &skip_args)) {
 
        /* Handle the -batch switch, which means don't do interactive display */
        if (argmatch(argv, argc, "-batch", "--batch", 5, NULL, &skip_args)) {
@@ -1113,6 +1121,14 @@ DOESNT_RETURN main_1(int argc, char **argv, char **envp, int restart)
                     11, NULL, &skip_args))
                debug_paths = 1;
 
                     11, NULL, &skip_args))
                debug_paths = 1;
 
+       /* Handle -user-pkgs-directory */
+       char *pkgd;
+       if (argmatch(argv, argc, "-user-pkgs-directory", "--user-pkgs-directory",
+                    11, &pkgd, &skip_args)) {
+               user_pkgd = pkgd;
+               upkgd = 1;
+       }
+
        /* Partially handle -no-autoloads, -no-early-packages and -vanilla.
           Packages */
        /* are searched prior to the rest of the command line being parsed in */
        /* Partially handle -no-autoloads, -no-early-packages and -vanilla.
           Packages */
        /* are searched prior to the rest of the command line being parsed in */
@@ -1151,7 +1167,8 @@ DOESNT_RETURN main_1(int argc, char **argv, char **envp, int restart)
 
        /* Partially handle the -version and -help switches: they imply -batch,
           but are not removed from the list. */
 
        /* Partially handle the -version and -help switches: they imply -batch,
           but are not removed from the list. */
-       if (argmatch(argv, argc, "-help", "--help", 3, NULL, &skip_args))
+       if (argmatch(argv, argc, "-help", "--help", 3, NULL, &skip_args)
+           || argmatch(argv, argc, "-h", 0, 2, NULL, &skip_args))
                noninteractive = 1, skip_args--;
 
        if (argmatch(argv, argc, "-version", "--version", 3, NULL, &skip_args)
                noninteractive = 1, skip_args--;
 
        if (argmatch(argv, argc, "-version", "--version", 3, NULL, &skip_args)
@@ -1168,7 +1185,7 @@ DOESNT_RETURN main_1(int argc, char **argv, char **envp, int restart)
                display_use = "tty";
 
 #ifndef HAVE_TTY
                display_use = "tty";
 
 #ifndef HAVE_TTY
-       if (inhibit_window_system)
+       if (inhibit_window_system && !noninteractive)
                fatal("Sorry, this SXEmacs was not compiled with TTY support");
 #endif
 
                fatal("Sorry, this SXEmacs was not compiled with TTY support");
 #endif
 
@@ -2173,6 +2190,14 @@ DOESNT_RETURN main_1(int argc, char **argv, char **envp, int restart)
           of this stuff involves querying the current environment and needs
           to be done both at dump time and at run time. */
 
           of this stuff involves querying the current environment and needs
           to be done both at dump time and at run time. */
 
+       /* user-packages-topdir (early-packages) */
+       if (upkgd == 0) {
+               Vuser_packages_topdir = Qnil;
+       } else {
+               Vuser_packages_topdir = Ffile_name_as_directory
+                       (build_string(user_pkgd));
+       }
+
        init_initial_directory();       /* get the directory to use for the
                                           "*scratch*" buffer, etc. */
 
        init_initial_directory();       /* get the directory to use for the
                                           "*scratch*" buffer, etc. */
 
@@ -2237,6 +2262,16 @@ DOESNT_RETURN main_1(int argc, char **argv, char **envp, int restart)
                if (NILP(Vinvocation_directory))
                        Vinvocation_directory = Vinvocation_name;
 
                if (NILP(Vinvocation_directory))
                        Vinvocation_directory = Vinvocation_name;
 
+               /* kick double /s as we want a standard posix name */
+               for (unsigned char *p = XSTRING_DATA(Vinvocation_name),
+                            *q = p; ((*q = *p));) {
+                       if (*q++ == '/') {
+                               while (*++p == '/');
+                       } else {
+                               p++;
+                       }
+               }
+
                Vinvocation_name =
                    Ffile_name_nondirectory(Vinvocation_directory);
                Vinvocation_directory =
                Vinvocation_name =
                    Ffile_name_nondirectory(Vinvocation_directory);
                Vinvocation_directory =
@@ -2317,6 +2352,10 @@ static const struct standard_args standard_args[] = {
        {"-no-autoloads", "--no-autoloads", 50, 0},
        {"-no-site-file", "--no-site-file", 40, 0},
        {"-no-early-packages", "--no-early-packages", 35, 0},
        {"-no-autoloads", "--no-autoloads", 50, 0},
        {"-no-site-file", "--no-site-file", 40, 0},
        {"-no-early-packages", "--no-early-packages", 35, 0},
+       /* -user-pkgs-directory is actually handled in main_1() and
+          not in startup.el.  It is listed here because of the
+          priority given to this arg. */
+       {"-user-pkgs-directory", "--user-pkgs-directory", 30, 1},
        {"-u", "--user", 30, 1},
        {"-user", 0, 30, 1},
        {"-debug-init", "--debug-init", 20, 0},
        {"-u", "--user", 30, 1},
        {"-user", 0, 30, 1},
        {"-debug-init", "--debug-init", 20, 0},
@@ -2584,9 +2623,6 @@ Do not call this.  It will reinitialize your SXEmacs.  You'll be sorry.
        unbind_to(0, Qnil);     /* this closes loadup.el */
        purify_flag = 0;
        run_temacs_argc = nargs + 1;
        unbind_to(0, Qnil);     /* this closes loadup.el */
        purify_flag = 0;
        run_temacs_argc = nargs + 1;
-#if defined (HEAP_IN_DATA) && !defined(PDUMP)
-       report_sheap_usage(0);
-#endif
        LONGJMP(run_temacs_catch, 1);
        return Qnil;            /* not reached; warning suppression */
 }
        LONGJMP(run_temacs_catch, 1);
        return Qnil;            /* not reached; warning suppression */
 }
@@ -2996,10 +3032,6 @@ and announce itself normally when it is run.
        opurify = purify_flag;
        purify_flag = 0;
 
        opurify = purify_flag;
        purify_flag = 0;
 
-#if defined (HEAP_IN_DATA) && !defined(PDUMP)
-       report_sheap_usage(1);
-#endif
-
        clear_message();
 
        fflush(stderr);
        clear_message();
 
        fflush(stderr);
@@ -3459,6 +3491,12 @@ Set to non-nil when site-modules should not be searched at startup.
        inhibit_site_modules = 1;
 #endif
 
        inhibit_site_modules = 1;
 #endif
 
+       DEFVAR_LISP("user-packages-topdir", &Vuser_packages_topdir /*
+Top of the user's local package hierarchy.
+This is normally computed at run-time, but may be set via the
+`-user-pkgs-directory' command line argument.
+                                                                  */ );
+
        DEFVAR_INT("emacs-priority", &emacs_priority /*
 Priority for SXEmacs to run at.
 This value is effective only if set before SXEmacs is dumped,
        DEFVAR_INT("emacs-priority", &emacs_priority /*
 Priority for SXEmacs to run at.
 This value is effective only if set before SXEmacs is dumped,