[Message Prev][Message Next][Thread Prev][Thread Next][Message Index][Thread Index]
[MD:2833]Portable dumper
- X-ml-count: 2833
- Subject: [MD:2833]Portable dumper
- From: Yoshiki Hayashi <yoshiki@xxxxxxxxxx>
- Date: 18 Jan 2002 22:39:10 +0900
- User-agent: T-gnus/6.15.3 (based on Oort Gnus v0.03) (revision 06)
Yoshiki Hayashi <yoshiki@xxxxxxxxxx> writes:
> http://www.sodan.org/~penny/Meadow/1-75.diff.gz
>
> においてあります。20k くらいです。
今までの diff を全部もっている人は、74 と 75 の差分はこれで
す。
Index: src/emacs.c
===================================================================
--- src/emacs.c
+++ tmp.48920.00001 Fri Jan 18 22:37:49 2002
@@ -1017,7 +1017,7 @@
#ifdef PDUMP
else
{
- if (pdump_load ())
+ if (pdump_load (argv[0]))
{
fprintf (stderr, "emacs: failed to load dumped file\n");
exit (1);
Index: src/alloc.c
===================================================================
--- src/alloc.c
+++ tmp.48920.00001 Fri Jan 18 22:37:49 2002
@@ -3732,15 +3732,18 @@
while (0)
#endif
+static int pdump_open_dumped_file (char *argv0);
static void pdump_relocate_objects (long offset);
int
-pdump_load ()
+pdump_load (char *argv0)
{
int i;
- int fd = open ("emacs.dmp", O_RDONLY);
+ int fd;
char *ret;
long offset;
+ if ((fd = pdump_open_dumped_file (argv0)) < 0)
+ return 1;
read (fd, &pdump_header, sizeof (pdump_header));
lseek (fd, 0, SEEK_SET);
#ifdef HAVE_MMAP
@@ -3861,7 +3864,8 @@
case Lisp_Misc_Buffer_Local_Value:
case Lisp_Misc_Some_Buffer_Local_Value:
{
- struct Lisp_Buffer_Local_Value *ptr = (struct Lisp_Buffer_Local_Value *)obj_ptr;
+ struct Lisp_Buffer_Local_Value *ptr =
+ (struct Lisp_Buffer_Local_Value *)obj_ptr;
if (XMARKBIT (ptr->realvalue))
XUNMARK (ptr->realvalue);
obj_ptr += sizeof (struct Lisp_Buffer_Local_Value);
@@ -4022,7 +4026,8 @@
case Lisp_Misc_Buffer_Local_Value:
case Lisp_Misc_Some_Buffer_Local_Value:
{
- struct Lisp_Buffer_Local_Value *ptr = (struct Lisp_Buffer_Local_Value *)obj_ptr;
+ struct Lisp_Buffer_Local_Value *ptr =
+ (struct Lisp_Buffer_Local_Value *)obj_ptr;
PDUMP_RELOCATE (ptr->buffer, offset);
PDUMP_RELOCATE (ptr->frame, offset);
PDUMP_RELOCATE (ptr->realvalue, offset);
@@ -4347,6 +4352,151 @@
#endif
#endif /* PDUMP */
+
+/* dumped file search */
+#include <sys/param.h>
+#include <unistd.h>
+
+/* FIXME: this should be merged with emacs.c */
+#ifndef SEPCHAR
+#define SEPCHAR ':'
+#endif
+
+static int
+pdump_file_check_readable (char *filename)
+{
+ struct stat stat_buf;
+ /* fprintf(stderr, "trying dumped file %s...\n", filename); */
+ if (stat (filename, &stat_buf) == 0)
+ if ((stat_buf.st_mode & S_IRUSR) != 0)
+ {
+ /* fprintf(stderr, "trying dumped file %s... ok\n", filename); */
+ return 1;
+ }
+ /* fprintf(stderr, "trying dumped file %s... ng\n", filename); */
+ return 0;
+}
+
+static int
+pdump_find_exe_path (char *argv0, char *exe_path)
+{
+#ifdef WINDOWSNT
+ GetModuleFileName (NULL, exe_path, PATH_MAX);
+#else /* !WINDOWSNT */
+ char *w;
+ const char *dir, *p;
+
+ dir = argv0;
+ if (dir[0] == '-')
+ {
+ /* Emacs as a login shell, how religious! */
+ dir = getenv ("SHELL");
+ }
+
+ p = dir + strlen (dir);
+ while (p != dir && !IS_ANY_SEP (p[-1])) p--;
+
+ if (p != dir)
+ {
+ /* invocation-name includes a directory component -- presumably it
+ is relative to cwd, not $PATH */
+ strcpy (exe_path, dir);
+ }
+ else
+ {
+ const char *path = getenv ("PATH");
+ const char *name = p;
+ for (;;)
+ {
+ p = path;
+ while (*p && *p != SEPCHAR)
+ p++;
+ if (p == path)
+ {
+ exe_path[0] = '.';
+ w = exe_path + 1;
+ }
+ else
+ {
+ memcpy (exe_path, path, p - path);
+ w = exe_path + (p - path);
+ }
+ if (!IS_DIRECTORY_SEP (w[-1]))
+ {
+ *w++ = '/';
+ }
+ strcpy (w, name);
+
+ /* ### #$%$#^$^@%$^#%@$ ! */
+#ifdef access
+#undef access
+#endif
+
+ if (!access (exe_path, X_OK))
+ break;
+ if (!*p)
+ {
+ /* Oh well, let's have some kind of default */
+ sprintf (exe_path, "./%s", name);
+ break;
+ }
+ path = p+1;
+ }
+ }
+#endif /* WINDOWSNT */
+
+ return 1;
+}
+
+static int
+pdump_find_dumped_file (char *exe_path)
+{
+ char *w = exe_path + strlen (exe_path);
+
+ do
+ {
+ /* ### FIXME: the versioning and dump_id are not implemented yet */
+#if 0
+ sprintf (w, "-%s-%08x.dmp", EMACS_VERSION, dump_id);
+ if (pdump_file_check_readable (exe_path))
+ return 1;
+
+ sprintf (w, "-%08x.dmp", dump_id);
+ if (pdump_file_check_readable (exe_path))
+ return 1;
+
+#endif
+ sprintf (w, ".dmp");
+ if (pdump_file_check_readable (exe_path))
+ return 1;
+
+ do
+ w--;
+ while (w > exe_path
+ && !IS_DIRECTORY_SEP (*w)
+ && (*w != '-')
+ && (*w != '.'));
+ }
+ while (w > exe_path && !IS_DIRECTORY_SEP (*w));
+
+ /* ### FIXME: temporal logic; try to find fixed name `emacs.dmp' */
+ sprintf (w+1, "emacs.dmp");
+ if (pdump_file_check_readable (exe_path))
+ return 1;
+
+ return 0;
+}
+
+static int
+pdump_open_dumped_file (char *argv0)
+{
+ char path[PATH_MAX];
+ if (pdump_find_exe_path (argv0, path))
+ if (pdump_find_dumped_file (path))
+ return open (path, O_RDONLY);
+ return -1;
+}
+
/* Initialization */
--
Yoshiki Hayashi