fujii
katu2****@k-fin*****
2007年 11月 12日 (月) 20:23:15 JST
diff -urN /home/katufj/cvsroot/emacs/lib-src/makefile.w32-in ./emacs/lib-src/makefile.w32-in --- /home/katufj/cvsroot/emacs/lib-src/makefile.w32-in 2007-11-03 06:30:33.201400000 +0900 +++ ./emacs/lib-src/makefile.w32-in 2007-11-11 16:54:18.890759500 +0900 @@ -148,7 +148,7 @@ w32.o w32bdf.o w32console.o w32fns.o w32heap.o w32inevt.o \ w32menu.o w32proc.o w32reg.o w32select.o w32term.o w32xfns.o \ dispnew.o frame.o scroll.o xdisp.o window.o \ - charset.o coding.o category.o ccl.o \ + charset.o coding.o category.o ccl.o character.o \ cm.o term.o xfaces.o \ emacs.o keyboard.o macros.o keymap.o sysdep.o \ buffer.o filelock.o insdel.o marker.o \ diff -urN /home/katufj/cvsroot/emacs/lisp/international/w32-ime.el ./emacs/lisp/international/w32-ime.el --- /home/katufj/cvsroot/emacs/lisp/international/w32-ime.el 1970-01-01 09:00:00.000000000 +0900 +++ ./emacs/lisp/international/w32-ime.el 2007-11-10 10:13:00.628759700 +0900 @@ -0,0 +1,226 @@ +;;;;; w32-ime.el ---- Meadow features for NTEmacs. +;; +;; Author H.Miyashita +;; +;;;;; + +(defgroup W32-IME nil + "w32-ime" + :group 'emacs) + +(defvar w32-last-selection nil + "It is stored the last data from Emacs.") + +;---------- + +(defvar w32-ime-on-hook nil + "Functions to eval when IME is turned on at least. +Even if IME state is not changed, these functiona are maybe called.") +(defvar w32-ime-off-hook nil + "Functions to eval when IME is turned off at least. +Even if IME state is not changed, these functiona are maybe called.") +(defvar w32-ime-buffer-switch-p t + "If this variable is nil, IME control when buffer is switched is disabled.") +(defvar w32-ime-show-mode-line t + "When t, mode line indicates IME state.") +(defvar w32-ime-mode-line-state-indicator "[O]" + "This is shown at the mode line. It is regarded as state of ime.") +(make-variable-buffer-local 'w32-ime-mode-line-state-indicator) +(put 'w32-ime-mode-line-state-indicator 'permanent-local t) +(defvar w32-ime-mode-line-state-indicator-list '("-" "[|]" "[O]") + "List of IME state indicator string.") +(defvar w32-ime-mode-line-format-original nil + "Original mode line format.") + +;; +;; Section: IME +;; + +;; ;; This is temporal solution. In the future, we will prepare +;; ;; dynamic configuration. +;; (defvar w32-ime-coding-system-language-environment-alist +;; '(("Japanese" . japanese-shift-jis) +;; ("Chinese-GB" . chinese-iso-8bit) +;; ("Chinese-BIG5" . chinese-big5) +;; ("Korean" . korean-iso-8bit))) + +;; +;; IME state indicator +;; +(global-set-key [kanji] 'ignore) +(global-set-key [compend] 'ignore) + +(defun wrap-function-to-control-ime + (function interactive-p interactive-arg &optional suffix) + "Wrap FUNCTION, and IME control is enabled when FUNCTION is called. +An original function is saved to FUNCTION-SUFFIX when suffix is string. +If SUFFIX is nil, \"-original\" is added. " + (let ((original-function + (intern (concat (symbol-name function) + (if suffix suffix "-original"))))) + (cond + ((not (fboundp original-function)) + (fset original-function + (symbol-function function)) + (fset function + (list + 'lambda '(&rest arguments) + (when interactive-p + (list 'interactive interactive-arg)) + (`(cond + ((and (ime-get-mode) + (equal current-input-method "W32-IME")) + (ime-force-off) + (unwind-protect + (apply '(, original-function) arguments) + (when (and (not (ime-get-mode)) + (equal current-input-method "W32-IME")) + (ime-force-on)))) + (t + (apply '(, original-function) + arguments)))))))))) + +(defvar w32-ime-toroku-region-yomigana nil + "* if this variable is string, toroku-region regard this value as yomigana.") + +(defun w32-ime-toroku-region (begin end) + (interactive "r") + (let ((string (buffer-substring begin end)) + (w32-ime-buffer-switch-p nil) + (reading w32-ime-toroku-region-yomigana)) + (unless (stringp reading) + (w32-set-ime-mode 'hiragana) + (setq reading + (read-multilingual-string + (format "Input reading of \"%s\": " string) nil "W32-IME"))) + (w32-ime-register-word-dialog reading string))) + +;; for IME management system. + +(defun w32-ime-sync-state (window) + (when w32-ime-buffer-switch-p + (with-current-buffer (window-buffer window) + (let* ((frame (window-frame window)) + (ime-state (ime-get-mode))) + (cond + ((and (not ime-state) + (equal current-input-method "W32-IME")) + (ime-force-on nil) + (run-hooks 'w32-ime-on-hook)) + ((and ime-state + (not (equal current-input-method "W32-IME"))) +;;; (when (= (w32-ime-undetermined-string-length) 0) + (ime-force-off nil) + (run-hooks 'w32-ime-off-hook))))))) + +(defun w32-ime-set-selected-window-buffer-hook (oldbuf newwin newbuf) + (w32-ime-sync-state newwin)) + +(defun w32-ime-select-window-hook (old new) + (w32-ime-sync-state new)) + +(defun w32-ime-mode-line-update () + (cond + (w32-ime-show-mode-line + (unless (window-minibuffer-p (selected-window)) + (setq w32-ime-mode-line-state-indicator + (nth (if (ime-get-mode) 1 2) + w32-ime-mode-line-state-indicator-list)))) + (t + (setq w32-ime-mode-line-state-indicator + (nth 0 w32-ime-mode-line-state-indicator-list)))) + (force-mode-line-update)) + +(defun w32-ime-init-mode-line-display () + (unless (member 'w32-ime-mode-line-state-indicator mode-line-format) + (setq w32-ime-mode-line-format-original + (default-value 'mode-line-format)) + (if (and (stringp (car mode-line-format)) + (string= (car mode-line-format) "-")) + (setq-default mode-line-format + (cons "" + (cons 'w32-ime-mode-line-state-indicator + (cdr mode-line-format)))) + (setq-default mode-line-format + (cons "" + (cons 'w32-ime-mode-line-state-indicator + mode-line-format)))) + (force-mode-line-update t))) + +;; (defun w32-ime-toggle () +;; (interactive) +;; (if (equal current-input-method "W32-IME") +;; (inactivate-input-method) +;; (activate-input-method "W32-IME"))) + +(defun w32-ime-initialize () +;; (cond +;; ((and (eq system-type 'windows-nt) +;; (eq window-system 'w32) +;; (featurep 'w32-ime)) +;; (let ((coding-system +;; (assoc-string current-language-environment +;; w32-ime-coding-system-language-environment-alist +;; t))) +;; (w32-ime-init-mode-line-display) +;; (w32-ime-mode-line-update) +;; (add-hook 'select-window-functions +;; 'w32-ime-select-window-hook) +;; (add-hook 'set-selected-window-buffer-functions +;; 'w32-ime-set-selected-window-buffer-hook) +;; (define-key global-map [kanji] 'w32-ime-toggle) +;; (define-key global-map [kanji] 'toggle-input-method) +;; (if coding-system +;; (set-keyboard-coding-system (cdr coding-system))))))) + (when (and (eq system-type 'windows-nt) + (eq window-system 'w32) + (featurep 'w32-ime)) + (w32-ime-init-mode-line-display) + (w32-ime-mode-line-update) + (add-hook 'select-window-functions + 'w32-ime-select-window-hook) + (add-hook 'set-selected-window-buffer-functions + 'w32-ime-set-selected-window-buffer-hook) + (define-key global-map [kanji] 'toggle-input-method) + (set-keyboard-coding-system 'utf-8))) + +(defun w32-ime-uninitialize () + (when (and (eq system-type 'windows-nt) + (eq window-system 'w32) + (featurep 'w32-ime)) + (setq-default mode-line-format + w32-ime-mode-line-format-original) + (force-mode-line-update t) + (remove-hook 'select-window-functions + 'w32-ime-select-window-hook) + (remove-hook 'set-selected-window-buffer-functions + 'w32-ime-set-selected-window-buffer-hook) + (define-key global-map [kanji] 'ignore))) + +(defun w32-ime-exit-from-minibuffer () + (inactivate-input-method) + (when (<= (minibuffer-depth) 1) + (remove-hook 'minibuffer-exit-hook 'w32-ime-exit-from-minibuffer))) + +(defun w32-ime-state-switch (&optional arg) + (if arg + (progn + (setq inactivate-current-input-method-function + 'w32-ime-state-switch) + (run-hooks 'input-method-activate-hook) + (run-hooks 'w32-ime-on-hook) + (setq describe-current-input-method-function nil) + (when (eq (selected-window) (minibuffer-window)) + (add-hook 'minibuffer-exit-hook 'w32-ime-exit-from-minibuffer)) + (ime-force-on)) + (setq current-input-method nil) + (run-hooks 'input-method-inactivate-hook) + (run-hooks 'w32-ime-off-hook) + (setq describe-current-input-method-function nil) + (ime-force-off)) + (w32-ime-mode-line-update)) + +(register-input-method "W32-IME" "Japanese" 'w32-ime-state-switch "" + "W32 System IME") + +(provide 'w32-ime) diff -urN /home/katufj/cvsroot/emacs/lisp/loadup.el ./emacs/lisp/loadup.el --- /home/katufj/cvsroot/emacs/lisp/loadup.el 2007-11-03 06:30:35.744200000 +0900 +++ ./emacs/lisp/loadup.el 2007-11-10 07:42:09.227959700 +0900 @@ -198,6 +198,8 @@ (load "term/w32-win") (load "ls-lisp") (load "disp-table") ; needed to setup ibm-pc char set, see internal.el + (and (boundp 'ime-control) + (load "international/w32-ime")) (load "dos-w32") (load "w32-fns"))) (if (eq system-type 'ms-dos) diff -urN /home/katufj/cvsroot/emacs/lisp/makefile.w32-in ./emacs/lisp/makefile.w32-in --- /home/katufj/cvsroot/emacs/lisp/makefile.w32-in 2007-10-04 06:12:28.690745700 +0900 +++ ./emacs/lisp/makefile.w32-in 2007-11-11 16:37:42.955559500 +0900 @@ -27,13 +27,13 @@ SQUOTE=' # ' -lisp = $(CURDIR) -srcdir = $(CURDIR)/.. +lisp=. +srcdir=./.. # You can specify a different executable on the make command line, # e.g. "make EMACS=../src/emacs ...". -EMACS = $(THISDIR)/../bin/emacs.exe +EMACS = ../bin/emacs.exe # Command line flags for Emacs. This must include --multibyte, # otherwise some files will not compile. diff -urN /home/katufj/cvsroot/emacs/nt/configure.bat ./emacs/nt/configure.bat --- /home/katufj/cvsroot/emacs/nt/configure.bat 2007-10-21 10:13:29.107369700 +0900 +++ ./emacs/nt/configure.bat 2007-11-10 14:05:17.878159700 +0900 @@ -89,6 +89,9 @@ set doldflags= set sep1= set sep2= +set unew32ime= +set winver= +set switch_char= - rem ---------------------------------------------------------------------- rem Handle arguments. @@ -108,6 +111,7 @@ if "%1" == "--without-gif" goto withoutgif if "%1" == "--without-tiff" goto withouttiff if "%1" == "--without-xpm" goto withoutxpm +if "%1" == "--enable-w32-ime" goto withime if "%1" == "" goto checkutils :usage echo Usage: configure [options] @@ -125,6 +129,7 @@ echo. --without-gif do not use giflib or libungif echo. --without-tiff do not use libtiff echo. --without-xpm do not use libXpm +echo. --enable-w32-ime build with w32 input method editor goto end rem ---------------------------------------------------------------------- :setprefix @@ -135,11 +140,13 @@ rem ---------------------------------------------------------------------- :withgcc set COMPILER=gcc +set switch_char= - shift goto again rem ---------------------------------------------------------------------- :withmsvc set COMPILER=cl +set switch_char=/ shift goto again rem ---------------------------------------------------------------------- @@ -212,6 +219,14 @@ goto again rem ---------------------------------------------------------------------- + +:withime +set usercflags=%usercflags%%sep1%%switch_char%DUSE_W32_IME +set sep1= %nothing% +shift +goto again + +rem ---------------------------------------------------------------------- rem Check that necessary utilities (cp and rm) are present. :checkutils echo Checking for 'cp'... @@ -220,7 +235,7 @@ echo Checking for 'rm'... rm junk.bat if exist junk.bat goto needrm -goto checkcompiler +goto checkversion :needcp echo You need 'cp' (the Unix file copy program) to build Emacs. goto end @@ -230,6 +245,39 @@ goto end rem ---------------------------------------------------------------------- +rem Check for Windows Version. +rem _WIN32_WINDOWS and _WIN32_WINNT are automatically defined by WINVER. + +:checkversion +echo Checking for Windows Version ... + +ver > junk.txt + +findstr "6000" junk.txt > NUL +if errorlevel 0 goto WVISTA + +findstr "XP" junk.txt > NUL +if errorlevel 0 goto WXP + +findstr "2000" junk.txt > NUL +if errorlevel 0 goto W2K + +:WNT +set usercflags=%usercflags%%sep1%%switch_char%DWINVER=0x0400 +goto ver_end + +:WVISTA +set usercflags=%usercflags%%sep1%%switch_char%DWINVER=0x0606 +goto ver_end +:WXP +set usercflags=%usercflags%%sep1%%switch_char%DWINVER=0x0501 +goto ver_end +:W2k +set usercflags=%usercflags%%sep1%%switch_char%DWINVER=0x0500 +:ver_end +rm -f junk.txt + +rem ---------------------------------------------------------------------- rem Auto-detect compiler if not specified, and validate GCC if chosen. :checkcompiler if (%COMPILER%)==(cl) goto compilercheckdone @@ -304,6 +352,7 @@ :gccOk set COMPILER=gcc +set switch_char=- echo Using 'gcc' rm -f junk.c junk.o Rem It is not clear what GCC version began supporting -mtune @@ -325,6 +374,7 @@ :clOk set COMPILER=cl +set switch_char=/ rm -f junk.c junk.obj echo Using 'MSVC' @@ -356,7 +406,7 @@ echo The failed program was: >>config.log type junk.c >>config.log set HAVE_PNG= -goto :pngDone +goto pngDone :havePng echo ...PNG header available, building with PNG support. @@ -379,7 +429,7 @@ echo The failed program was: >>config.log type junk.c >>config.log set HAVE_JPEG= -goto :jpegDone +goto jpegDone :haveJpeg echo ...JPEG header available, building with JPEG support. @@ -402,7 +452,7 @@ echo The failed program was: >>config.log type junk.c >>config.log set HAVE_GIF= -goto :gifDone +goto gifDone :haveGif echo ...GIF header available, building with GIF support. @@ -425,7 +475,7 @@ echo The failed program was: >>config.log type junk.c >>config.log set HAVE_TIFF= -goto :tiffDone +goto tiffDone :haveTiff echo ...TIFF header available, building with TIFF support. @@ -449,7 +499,7 @@ echo The failed program was: >>config.log type junk.c >>config.log set HAVE_XPM= -goto :xpmDone +goto xpmDone :haveXpm echo ...XPM header available, building with XPM support. @@ -459,6 +509,32 @@ rm -f junk.c junk.obj junk.err junk.out rem ---------------------------------------------------------------------- +rem check for RECONVERTSTRING +rem + +echo checking for RECONVERTSTRING... + +echo #include "windows.h" >junk.c +echo #include "imm.h" >>junk.c +echo main(){RECONVERTSTRING x;} >>junk.c + +%COMPILER% %usercflags% %mingwflag% -c junk.c -o junk.obj >>config.log 2>&1 +if exist junk.obj goto haveReconvertstring + +echo ...RECONVERTSTRING isn't defined. +echo The failed program was: >>config.log +type junk.c >>config.log +set HAVE_RECONVERTSTRING= +goto recoverstringDone + +:haveReconvertstring +echo ...RECONVERTSTRING is defined. +set HAVE_RECONVERTSTRING=1 + +:recoverstringDone +rm -f junk.c junk.obj + +rem ---------------------------------------------------------------------- :genmakefiles echo Generating makefiles if %COMPILER% == gcc set MAKECMD=gmake @@ -481,6 +557,7 @@ if (%docflags%)==(Y) echo USER_CFLAGS=%usercflags%>>config.settings for %%v in (%userldflags%) do if not (%%v)==() set doldflags=Y if (%doldflags%)==(Y) echo USER_LDFLAGS=%userldflags%>>config.settings +if (%usew32ime%) == (Y) echo USE_W32IME=1 >>config.settings echo # End of settings from configure.bat>>config.settings echo. >>config.settings @@ -494,6 +571,7 @@ if not "(%HAVE_GIF%)" == "()" echo #define HAVE_GIF 1 >>config.tmp if not "(%HAVE_TIFF%)" == "()" echo #define HAVE_TIFF 1 >>config.tmp if not "(%HAVE_XPM%)" == "()" echo #define HAVE_XPM 1 >>config.tmp +if not "(%HAVE_RECONVERTSTRING%)" == "()" echo #define HAVE_RECONVERTSTRING 1 >>config.tmp echo /* End of settings from configure.bat. */ >>config.tmp Rem See if fc.exe returns a meaningful exit status. If it does, we diff -urN /home/katufj/cvsroot/emacs/nt/gmake.defs ./emacs/nt/gmake.defs --- /home/katufj/cvsroot/emacs/nt/gmake.defs 2007-10-15 18:59:09.213565400 +0900 +++ ./emacs/nt/gmake.defs 2007-11-11 16:51:57.570359500 +0900 @@ -84,9 +84,9 @@ # remedied before putting this cygpath kludge back in. # Convert CURDIR to native file name, if in Cygwin format -#ifeq "$(shell cygpath $(CURDIR))" "$(CURDIR)" -#CURDIR := $(shell cygpath -m $(CURDIR)) -#endif +ifeq "$(shell cygpath $(CURDIR))" "$(CURDIR)" +CURDIR := $(shell cygpath -m $(CURDIR)) +endif THISDIR = . diff -urN /home/katufj/cvsroot/emacs/src/Makefile.in ./emacs/src/Makefile.in --- /home/katufj/cvsroot/emacs/src/Makefile.in 2007-11-03 06:30:43.076200000 +0900 +++ ./emacs/src/Makefile.in 2007-11-04 09:02:43.544959600 +0900 @@ -573,7 +573,7 @@ #endif #endif -#ifdef CYGWIN +#if defined (CYGWIN) && ! defined (CYGWIN_ON_VISTA) CYGWIN_OBJ = sheap.o #endif @@ -654,7 +654,7 @@ should not be told about. */ #ifdef CYGWIN /* Cygwin differs because of its unexec(). */ -otherobj= $(termcapobj) $(gmallocobj) $(rallocobj) lastfile.o vm-limit.o $(widgetobj) $(LIBOBJS) +otherobj= $(termcapobj) $(mallocobj) $(widgetobj) $(LIBOBJS) #else otherobj= $(termcapobj) lastfile.o $(mallocobj) $(widgetobj) $(LIBOBJS) #endif @@ -965,6 +965,9 @@ #ifdef HAVE_SHM LC_ALL=C $(RUN_TEMACS) -nl -batch -l loadup dump #else /* ! defined (HAVE_SHM) */ +#if defined(CYGWIN) && defined (CYGWIN_ON_VISTA) + -./addscncw $(RUN_TEMACS) HEAP_NAME EHEAP_RSV_SIZE +#endif /* defined (CYGWIN) && defined (CYGWIN_ON_VISTA) */ LC_ALL=C $(RUN_TEMACS) -batch -l loadup dump #endif /* ! defined (HAVE_SHM) */ #endif /* ! defined (CANNOT_DUMP) */ @@ -991,7 +994,11 @@ #define MAKE_PARALLEL #endif +#if defined (CYGWIN) && defined (CYGWIN_ON_VISTA) +temacs${EXEEXT}: MAKE_PARALLEL $(LOCALCPP) $(STARTFILES) stamp-oldxmenu ${obj} ${otherobj} OBJECTS_MACHINE prefix-args${EXEEXT} addscncw${EXEEXT} +#else temacs${EXEEXT}: MAKE_PARALLEL $(LOCALCPP) $(STARTFILES) stamp-oldxmenu ${obj} ${otherobj} OBJECTS_MACHINE prefix-args${EXEEXT} +#endif echo "${obj} ${otherobj} " OBJECTS_MACHINE > buildobj.lst $(LD) YMF_PASS_LDFLAGS (${STARTFLAGS} ${TEMACS_LDFLAGS}) $(LDFLAGS) \ -o temacs ${STARTFILES} ${obj} ${otherobj} \ @@ -1003,6 +1010,11 @@ prefix-args${EXEEXT}: prefix-args.c $(config_h) $(CC) $(ALL_CFLAGS) $(LDFLAGS) ${srcdir}/prefix-args.c -o prefix-args +#if defined (CYGWIN) && defined (CYGWIN_ON_VISTA) +addscncw${EXEEXT}: addscncw.cc unexcygwin.hh $(config_h) + g++ -O addscncw.cc -o addscncw +#endif + /* Do not lose if this was not defined. */ #ifndef OLDXMENU_OPTIONS #define OLDXMENU_OPTIONS @@ -1370,6 +1382,9 @@ #ifdef HAVE_SHM $(RUN_TEMACS) -nl -batch -l loadup bootstrap #else /* ! defined (HAVE_SHM) */ +#if defined (CYGWIN) && defined (CYGWIN_ON_VISTA) + ./addscncw $(RUN_TEMACS) HEAP_NAME EHEAP_RSV_SIZE +#endif $(RUN_TEMACS) --batch --load loadup bootstrap #endif /* ! defined (HAVE_SHM) */ mv -f emacs${EXEEXT} bootstrap-emacs${EXEEXT} diff -urN /home/katufj/cvsroot/emacs/src/addscncw.cc ./emacs/src/addscncw.cc --- /home/katufj/cvsroot/emacs/src/addscncw.cc 1970-01-01 09:00:00.000000000 +0900 +++ ./emacs/src/addscncw.cc 2007-11-07 18:49:11.381750000 +0900 @@ -0,0 +1,156 @@ +// +// Add heap section in temacs.exe +// + +// #include <config.h> +#include <stdio.h> +#include <fcntl.h> +#include <unistd.h> +#include <iostream.h> +#include <windows.h> +#include <windowsx.h> +#include <sys/cygwin.h> +#include "./unexcygwin.hh" + +SectionHeader +SectionHeader::InvalidSection; + +pchar +FileData::FileName (cpchar base_name) +{ + strcpy (FileName (), base_name); + + int len (strlen (FileName ())); + if (len < sizeof (_EXE) || + stricmp (cpchar (FileName () + (len - (sizeof (_EXE) - 1))), _EXE) != 0) + strcat (FileName (), _EXE); + + return FileName (); +} + +FileData::FileData (cpchar fname) +{ + BaseAddress (NULL); + FileSize (0); + FileChanged (False); + + FileHandle (open (FileName (fname), O_RDWR | O_BINARY, 0755)); + if (FileHandle () < 0) + { + cerr << "Failed to open " << FileName () << "\n"; + return; + } + FileSize (pImageHeader (GetModuleHandle (NULL))->SizeOfHeaders ()); + BaseAddress (pvoid (malloc (FileSize ()))); + if (BaseAddress () == NULL) + { + cerr << "Failed to allocate memory for file " << FileName () << "\n"; + return; + } + lseek (FileHandle (), 0L, SEEK_SET); + if (read (FileHandle (), BaseAddress (), FileSize ()) != FileSize ()) + { + close (FileHandle ()); + free (BaseAddress ()); + FileHandle (-1); + BaseAddress (NULL); + return; + } +} + +FileData::~FileData () +{ + if (FileHandle () >= 0) + { + if (FileChanged () == True) + { + lseek (FileHandle (), 0L, SEEK_SET); + write (FileHandle (), BaseAddress (), FileSize ()); + } + close (FileHandle ()); + } + if (BaseAddress () != NULL) + free (BaseAddress ()); +} + +Bool +FileData::FixUpImageHeader (cpchar scn_name, ulong scn_size) +{ + if (strlen (scn_name) > S_NAME_LEN) + { + cerr << "Section Name " << scn_name << " is too long.\n"; + cerr << "Mximam Section name length is " << S_NAME_LEN << " ASCII characters.\n"; + return False; + } + + rImageHeader img_hdr (this->ImageHeader ()); + + if (img_hdr.InvalidImageHeaderP () == True) + { + cerr << "Invalid ImageHeader.\n"; + return False; + } + + if (img_hdr[scn_name].InvalidSectionP () == False) + { + cerr << "Already existed " << scn_name << " section\n"; + return False; + } + + int heap_scn (-1); + int nscns (img_hdr.NumberOfSections ()); + scn_size *= (1024 * 1024); + + img_hdr.NumberOfSections ()++; + + for (int i = nscns - 1; i >= 0; i--) + { + if (! (img_hdr [i].SectionFlags () & IMAGE_SCN_LNK_REMOVE)) + { + heap_scn = i + 1; + break; + } + img_hdr [i + 1] = img_hdr [i]; + img_hdr [i + 1].VirtualAddress () += scn_size; + } + + int unstriped_last_scn (heap_scn - 1); + + img_hdr.SizeOfImage () += scn_size; + + bzero (pvoid (&(img_hdr [heap_scn])), sizeof (img_hdr [heap_scn])); + + img_hdr [heap_scn].SectionName (scn_name); + img_hdr [heap_scn].VirtualSize (scn_size); + img_hdr [heap_scn].VirtualAddress (RoundUp (img_hdr [unstriped_last_scn].VirtualAddress () + + img_hdr [unstriped_last_scn].VirtualSize (), + img_hdr.SectionAlignment ())); + img_hdr [heap_scn].SectionFlags (IMAGE_SCN_CNT_UNINITIALIZED_DATA | + IMAGE_SCN_MEM_READ | + IMAGE_SCN_MEM_WRITE); + + FileChanged (True); + + return True; +} + +int +main (int argc, cpchar argv[], cpchar envp[]) +{ + if (argc != 4) + { + cout << "Usage: addscncw exe-file-name section-name section-size-in-mb\n"; + exit (0); + } + + FileData file (argv [1]); + + if (file.InvalidFileDataP () != False) + exit (-1); + + if (file.FixUpImageHeader (argv [2], ulong (atoi (argv [3]))) == False) + exit (-1); + + return 0; +} + diff -urN /home/katufj/cvsroot/emacs/src/emacs.c ./emacs/src/emacs.c --- /home/katufj/cvsroot/emacs/src/emacs.c 2007-11-09 20:41:45.127969900 +0900 +++ ./emacs/src/emacs.c 2007-11-10 07:03:43.157959700 +0900 @@ -86,6 +86,13 @@ #endif #endif +#if defined (CYGWIN) && defined (CYGWIN_ON_VISTA) /* patch 07.11.5 by K.Fujii */ +extern int _data_start__; +extern int _data_end__; +extern int _bss_start__; +extern int _bss_end__; +#endif + extern void malloc_warning P_ ((char *)); extern void set_time_zone_rule P_ ((char *)); #ifdef HAVE_INDEX @@ -824,13 +831,20 @@ if (!initialized) { +#if !defined (CYGWIN) || ! defined (CYGWIN_ON_VISTA) /* patch + 07.10.28, 07.11.5 by K.Fujii. */ extern char my_endbss[]; extern char *my_endbss_static; +#endif if (my_heap_start == 0) my_heap_start = sbrk (0); +#if defined (CYGWIN) && defined (CYGWIN_ON_VISTA) /* patch 07.10.28, 07.11.05 by K.Fujii. */ + heap_bss_diff = (char *)my_heap_start - (char *)(&_bss_end__); +#else heap_bss_diff = (char *)my_heap_start - max (my_endbss, my_endbss_static); +#endif } #ifdef LINUX_SBRK_BUG @@ -1306,6 +1320,11 @@ CANNOT_DUMP is defined. */ syms_of_keyboard (); +#if defined(CYGWIN) && defined (CYGWIN_ON_VISTA) && defined(DEBUG_CYGWIN_ON_VISTA) /* patch + 07.10.28 by K.Fujii */ + syms_of_cygwin_debug_on_vista (); +#endif + #ifdef MAC_OS8 /* init_window_once calls make_terminal_frame which on Mac OS creates a full-fledge output_mac type frame. This does not @@ -2273,7 +2292,12 @@ #ifndef WINDOWSNT /* On Windows, this was done before dumping, and that once suffices. Meanwhile, my_edata is not valid on Windows. */ +# if defined (CYGWIN) && defined (CYGWIN_ON_VISTA) /* patch 07.10.28, + 07.11.05 by K.Fujii */ + memory_warnings (&_data_end__, malloc_warning); +# else memory_warnings (my_edata, malloc_warning); +# endif #endif /* not WINDOWSNT */ #endif #if !defined (SYSTEM_MALLOC) && defined (HAVE_GTK_AND_PTHREAD) && !defined SYNC_INPUT @@ -2289,8 +2313,13 @@ #ifdef USE_MMAP_FOR_BUFFERS mmap_set_vars (0); #endif +#if defined (CYGWIN) && defined (CYGWIN_ON_VISTA) /* patch 07.10.28, 07.11.5 by K.Fujii */ + unexec (SDATA (filename), + !NILP (symfile) ? SDATA (symfile) : NULL, &_data_start__, &_bss_start__, NULL); +#else unexec (SDATA (filename), !NILP (symfile) ? SDATA (symfile) : 0, my_edata, 0, 0); +#endif #ifdef USE_MMAP_FOR_BUFFERS mmap_set_vars (1); #endif diff -urN /home/katufj/cvsroot/emacs/src/fileio.c ./emacs/src/fileio.c --- /home/katufj/cvsroot/emacs/src/fileio.c 2007-10-27 17:39:52.737353800 +0900 +++ ./emacs/src/fileio.c 2007-11-01 17:34:43.905400000 +0900 @@ -6556,6 +6556,88 @@ return val; } +#ifdef CYGWIN /* patch 07.10.24 by K.Fujii */ +#include <sys/cygwin.h> +#ifndef MAX_PATH +#define MAX_PATH FILENAME_MAX +#endif + +DEFUN ("cygwin-conv-to-posix-path", Fcygwin_conv_to_posix_path, Scygwin_conv_to_posix_path, + 1, 1, 0, + doc: /* Convert W32 path to Cygwin's POSIX path. */) + (win32_path) + Lisp_Object win32_path; +{ + char nbuf [MAX_PATH]; + int multibyte; + Lisp_Object posix_path; + + CHECK_STRING (win32_path); + + if (multibyte = STRING_MULTIBYTE (win32_path)) + win32_path = ENCODE_FILE (win32_path); + cygwin_conv_to_posix_path (SDATA (win32_path), nbuf); + posix_path = make_unibyte_string (nbuf, strlen (nbuf)); + if (multibyte) + posix_path = DECODE_FILE (posix_path); + + return posix_path; +} + +DEFUN ("cygwin-conv-to-win32-path", Fcygwin_conv_to_win32_path, Scygwin_conv_to_win32_path, + 1, 1, 0, + doc: /* Convert Cygwin's POSIX path to Win32 path. */) + (posix_path) + Lisp_Object posix_path; +{ + char nbuf [MAX_PATH]; + Lisp_Object win32_path; + + CHECK_STRING (posix_path); + + posix_path = ENCODE_FILE (posix_path); + cygwin_conv_to_win32_path (SDATA (posix_path), nbuf); + win32_path = make_unibyte_string (nbuf, strlen (nbuf)); + + return DECODE_FILE (win32_path); +} + +DEFUN ("cygwin-conv-to-full-posix-path", Fcygwin_conv_to_full_posix_path, Scygwin_conv_to_full_posix_path, + 1, 1, 0, + doc: /* Convert Win32 path to Cygwin's POSIX full path. */) + (win32_path) + Lisp_Object win32_path; +{ + char nbuf [MAX_PATH]; + Lisp_Object posix_path; + + CHECK_STRING (win32_path); + + win32_path = ENCODE_FILE (win32_path); + cygwin_conv_to_full_posix_path (SDATA (win32_path), nbuf); + posix_path = make_unibyte_string (nbuf, strlen (nbuf)); + + return DECODE_FILE (posix_path); +} + +DEFUN ("cygwin-conv-to-full-win32-path", Fcygwin_conv_to_full_win32_path, Scygwin_conv_to_full_win32_path, + 1, 1, 0, + doc: /* Convert Cygwin's POSIX path to Win32 full path. */) + (posix_path) + Lisp_Object posix_path; +{ + char nbuf [MAX_PATH]; + Lisp_Object win32_path; + + CHECK_STRING (posix_path); + + posix_path = ENCODE_FILE (posix_path); + cygwin_conv_to_full_win32_path (SDATA (posix_path), nbuf); + win32_path = make_unibyte_string (nbuf, strlen (nbuf)); + + return DECODE_FILE (win32_path); +} +#endif /* not CYGWIN */ void init_fileio_once () @@ -6885,6 +6967,13 @@ #ifdef HAVE_SYNC defsubr (&Sunix_sync); #endif + +#ifdef CYGWIN /* patch 07.10.24 by K.Fujii */ + defsubr (&Scygwin_conv_to_posix_path); + defsubr (&Scygwin_conv_to_win32_path); + defsubr (&Scygwin_conv_to_full_posix_path); + defsubr (&Scygwin_conv_to_full_win32_path); +#endif /* not CYGWIN */ } /* arch-tag: 64ba3fd7-f844-4fb2-ba4b-427eb928786c diff -urN /home/katufj/cvsroot/emacs/src/frame.c ./emacs/src/frame.c --- /home/katufj/cvsroot/emacs/src/frame.c 2007-11-03 06:30:43.949800000 +0900 +++ ./emacs/src/frame.c 2007-11-10 08:19:29.637559700 +0900 @@ -2798,6 +2798,10 @@ has an `x-frame-parameter' property which is an integer in Lisp that is an index in this table. */ +#ifdef USE_W32_IME +extern void x_set_ime_font (struct frame *, Lisp_Object, Lisp_Object); +#endif + struct frame_parm_table { char *name; Lisp_Object *variable; @@ -2813,6 +2817,9 @@ {"cursor-color", &Qcursor_color}, {"cursor-type", &Qcursor_type}, {"font", 0}, +#ifdef USE_W32_IME + {"ime-font", &Qime_font}, +#endif {"foreground-color", 0}, {"icon-name", &Qicon_name}, {"icon-type", &Qicon_type}, diff -urN /home/katufj/cvsroot/emacs/src/frame.h ./emacs/src/frame.h --- /home/katufj/cvsroot/emacs/src/frame.h 2007-10-27 17:39:52.924553800 +0900 +++ ./emacs/src/frame.h 2007-11-10 08:25:08.797159700 +0900 @@ -991,6 +991,9 @@ extern Lisp_Object Qbuffer_predicate, Qbuffer_list, Qburied_buffer_list; extern Lisp_Object Qcursor_color, Qcursor_type; extern Lisp_Object Qfont; +#ifdef USE_W32_IME +extern Lisp_Object Qime_font; +#endif extern Lisp_Object Qbackground_color, Qforeground_color; extern Lisp_Object Qicon, Qicon_name, Qicon_type, Qicon_left, Qicon_top; extern Lisp_Object Qinternal_border_width; diff -urN /home/katufj/cvsroot/emacs/src/gmalloc.c ./emacs/src/gmalloc.c --- /home/katufj/cvsroot/emacs/src/gmalloc.c 2007-10-04 06:13:14.944745700 +0900 +++ ./emacs/src/gmalloc.c 2007-10-17 22:11:45.642971200 +0900 @@ -401,10 +401,18 @@ /* How to really get more memory. */ #if defined(CYGWIN) +# if defined (CYGWIN_ON_VISTA) +extern __ptr_t cygwin_morecore PP ((__malloc_ptrdiff_t __size)); +# else extern __ptr_t bss_sbrk PP ((ptrdiff_t __size)); extern int bss_sbrk_did_unexec; +# endif #endif +#if defined (CYGWIN) && defined (CYGWIN_ON_VISTA) +__ptr_t (*__morecore) PP ((__malloc_ptrdiff_t __size)) = cygwin_morecore; +#else __ptr_t (*__morecore) PP ((__malloc_ptrdiff_t __size)) = __default_morecore; +#endif /* Debugging hook for `malloc'. */ __ptr_t (*__malloc_hook) PP ((__malloc_size_t __size)); @@ -1741,7 +1749,7 @@ __malloc_ptrdiff_t increment; { __ptr_t result; -#if defined(CYGWIN) +#if defined(CYGWIN) && !defined (CYGWIN_ON_VISTA) if (!bss_sbrk_did_unexec) { return bss_sbrk (increment); diff -urN /home/katufj/cvsroot/emacs/src/keyboard.c ./emacs/src/keyboard.c --- /home/katufj/cvsroot/emacs/src/keyboard.c 2007-11-10 14:37:17.717959700 +0900 +++ ./emacs/src/keyboard.c 2007-11-11 13:41:51.989159500 +0900 @@ -9109,6 +9109,13 @@ volatile Lisp_Object from_string; volatile int count = SPECPDL_INDEX (); + /* To control IME ( by himi ) */ +#ifdef USE_W32_IME + extern Lisp_Object Fime_force_on (), Fime_force_off (), Fime_get_mode (); + Lisp_Object VIME_command_off_flag = Qnil; + Lisp_Object IME_command_loop_flag = Qnil; +#endif + /* How many keys there are in the current key sequence. */ volatile int t; @@ -9267,6 +9274,12 @@ keybuf[0..mock_input] holds the sequence we should reread. */ replay_sequence: +#ifdef USE_W32_IME +/* If key sequences are to replay, IME_loop_flag should not be set. + Because event has never been occured. (by himi 96.10.13) */ + IME_command_loop_flag = Qnil; +#endif + starting_buffer = current_buffer; first_unbound = bufsize + 1; @@ -9399,6 +9412,16 @@ goto replay_sequence; } +#ifdef USE_W32_IME + if (!NILP (IME_command_loop_flag) && NILP (VIME_command_off_flag)) + { + VIME_command_off_flag = Fime_get_mode (); + if (!NILP (VIME_command_off_flag)) + Fime_force_off (Qnil); + } + IME_command_loop_flag = Qt; +#endif + if (t >= bufsize) error ("Key sequence too long"); @@ -10134,6 +10157,12 @@ ? defs[first_binding] : Qnil); + /* to control IME (by himi) */ +#ifdef USE_W32_IME + if (!NILP (VIME_command_off_flag)) + Fime_force_on (Qnil); +#endif + unread_switch_frame = delayed_switch_frame; unbind_to (count, Qnil); diff -urN /home/katufj/cvsroot/emacs/src/ldscript.cwx ./emacs/src/ldscript.cwx --- /home/katufj/cvsroot/emacs/src/ldscript.cwx 1970-01-01 09:00:00.000000000 +0900 +++ ./emacs/src/ldscript.cwx 2007-11-01 17:35:51.531400000 +0900 @@ -0,0 +1,202 @@ +/* Linker script, for GNU Emacs on Cygwin. Copyed Cygwin's default ldscript. */ +OUTPUT_FORMAT(pei-i386) +SEARCH_DIR("/usr/i686-pc-cygwin/lib"); SEARCH_DIR("/usr/local/lib"); SEARCH_DIR("/usr/lib"); SEARCH_DIR("/usr/lib/w32api"); +SECTIONS +{ + /* Make the virtual address and file offset synced if the alignment is + lower than the target page size. */ + . = SIZEOF_HEADERS; + . = ALIGN(__section_alignment__); + .text __image_base__ + ( __section_alignment__ < 0x1000 ? . : __section_alignment__ ) : + { + *(.init) + *(.text) + *(SORT(.text$*)) + *(.glue_7t) + *(.glue_7) + ___CTOR_LIST__ = .; __CTOR_LIST__ = . ; + LONG (-1);*(.ctors); *(.ctor); *(SORT(.ctors.*)); LONG (0); + ___DTOR_LIST__ = .; __DTOR_LIST__ = . ; + LONG (-1); *(.dtors); *(.dtor); *(SORT(.dtors.*)); LONG (0); + *(.fini) + /* ??? Why is .gcc_exc here? */ + *(.gcc_exc) + PROVIDE (etext = .); + *(.gcc_except_table) + } + /* The Cygwin32 library uses a section to avoid copying certain data + on fork. This used to be named ".data". The linker used + to include this between __data_start__ and __data_end__, but that + breaks building the cygwin32 dll. Instead, we name the section + ".data_cygwin_nocopy" and explictly include it after __data_end__. */ + .data BLOCK(__section_alignment__) : + { + __data_start__ = . ; + *(.data) + *(.data2) + *(SORT(.data$*)) + *(.jcr) + __data_end__ = . ; + *(.data_cygwin_nocopy) + } + .bss BLOCK(__section_alignment__) : + { + __bss_start__ = . ; + *(.bss) + *(COMMON) + __bss_end__ = . ; + } + .rdata BLOCK(__section_alignment__) : + { + *(.rdata) + *(SORT(.rdata$*)) + *(.eh_frame) + ___RUNTIME_PSEUDO_RELOC_LIST__ = .; + __RUNTIME_PSEUDO_RELOC_LIST__ = .; + *(.rdata_runtime_pseudo_reloc) + ___RUNTIME_PSEUDO_RELOC_LIST_END__ = .; + __RUNTIME_PSEUDO_RELOC_LIST_END__ = .; + } + .pdata BLOCK(__section_alignment__) : + { + *(.pdata) + } + .edata BLOCK(__section_alignment__) : + { + *(.edata) + } + /DISCARD/ : + { + *(.debug$S) + *(.debug$T) + *(.debug$F) + *(.drectve) + } + .idata BLOCK(__section_alignment__) : + { + /* This cannot currently be handled with grouped sections. + See pe.em:sort_sections. */ + SORT(*)(.idata$2) + SORT(*)(.idata$3) + /* These zeroes mark the end of the import list. */ + LONG (0); LONG (0); LONG (0); LONG (0); LONG (0); + SORT(*)(.idata$4) + SORT(*)(.idata$5) + SORT(*)(.idata$6) + SORT(*)(.idata$7) + } + .CRT BLOCK(__section_alignment__) : + { + ___crt_xc_start__ = . ; + *(SORT(.CRT$XC*)) /* C initialization */ + ___crt_xc_end__ = . ; + ___crt_xi_start__ = . ; + *(SORT(.CRT$XI*)) /* C++ initialization */ + ___crt_xi_end__ = . ; + ___crt_xl_start__ = . ; + *(SORT(.CRT$XL*)) /* TLS callbacks */ + /* ___crt_xl_end__ is defined in the TLS Directory support code */ + ___crt_xp_start__ = . ; + *(SORT(.CRT$XP*)) /* Pre-termination */ + ___crt_xp_end__ = . ; + ___crt_xt_start__ = . ; + *(SORT(.CRT$XT*)) /* Termination */ + ___crt_xt_end__ = . ; + } + .tls BLOCK(__section_alignment__) : + { + ___tls_start__ = . ; + *(.tls) + *(.tls$) + *(SORT(.tls$*)) + ___tls_end__ = . ; + } + .endjunk BLOCK(__section_alignment__) : + { + /* end is deprecated, don't use it */ + PROVIDE (end = .); + PROVIDE ( _end = .); + __end__ = .; + } + .rsrc BLOCK(__section_alignment__) : + { + *(.rsrc) + *(SORT(.rsrc$*)) + } + .reloc BLOCK(__section_alignment__) : + { + *(.reloc) + } + .stab BLOCK(__section_alignment__) (NOLOAD) : + { + *(.stab) + } + .stabstr BLOCK(__section_alignment__) (NOLOAD) : + { + *(.stabstr) + } + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section. Unlike other targets that fake this by putting the + section VMA at 0, the PE format will not allow it. */ + /* DWARF 1.1 and DWARF 2. */ + .debug_aranges BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_aranges) + } + .debug_pubnames BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_pubnames) + } + /* DWARF 2. */ + .debug_info BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_info) *(.gnu.linkonce.wi.*) + } + .debug_abbrev BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_abbrev) + } + .debug_line BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_line) + } + .debug_frame BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_frame) + } + .debug_str BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_str) + } + .debug_loc BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_loc) + } + .debug_macinfo BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_macinfo) + } + /* SGI/MIPS DWARF 2 extensions. */ + .debug_weaknames BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_weaknames) + } + .debug_funcnames BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_funcnames) + } + .debug_typenames BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_typenames) + } + .debug_varnames BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_varnames) + } + /* DWARF 3. */ + .debug_ranges BLOCK(__section_alignment__) (NOLOAD) : + { + *(.debug_ranges) + } +} diff -urN /home/katufj/cvsroot/emacs/src/mem-limits.h ./emacs/src/mem-limits.h --- /home/katufj/cvsroot/emacs/src/mem-limits.h 2007-10-04 06:13:17.768345700 +0900 +++ ./emacs/src/mem-limits.h 2007-10-15 21:08:16.918965400 +0900 @@ -19,6 +19,17 @@ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#ifdef CYGWIN +extern int _data_start__; +extern int _data_end__; +extern int _bss_start__; +extern int _bss_end__; +#define DATA_START &_data_start__ +#define DATA_END &_data_end__ +#define BSS_START &_bss_start__ +#define BSS_END &_bss_start__ +#endif + #ifdef MSDOS #include <dpmi.h> extern int etext; diff -urN /home/katufj/cvsroot/emacs/src/s/cygwin.h ./emacs/src/s/cygwin.h --- /home/katufj/cvsroot/emacs/src/s/cygwin.h 2007-10-04 06:13:24.850745700 +0900 +++ ./emacs/src/s/cygwin.h 2007-11-06 18:39:06.010153500 +0900 @@ -1,3 +1,5 @@ +/* -*- Mode: C ; coding: euc-japan-unix -*- */ + /* Template for system description header files. This file describes the parameters that system description files should define or not. @@ -114,16 +116,218 @@ #define CYGWIN 1 #define PENDING_OUTPUT_COUNT(FILE) ((FILE)->_p - (FILE)->_bf._base) + #define GETPGRP_NO_ARG 1 #define SYSV_SYSTEM_DIR 1 #define LIB_STANDARD_LIBSRC -#define UNEXEC unexcw.o +/* #define UNEXEC unexcw.o */ #define POSIX_SIGNALS 1 -/* force the emacs image to start high in memory, so dll relocation - can put things in low memory without causing all sorts of grief for - emacs lisp pointers */ -#define DATA_SEG_BITS 0x20000000 -#define LINKER $(CC) -Wl,--image-base,DATA_SEG_BITS + +/* patch 07.7.20, 07.8.20, 07.09.04 by K.Fujii */ +#define DEBUG_CYGWIN_ON_VISTA 1 + +#define CYGWIN_ON_VISTA 1 +#define HEAP_NAME .emheap +#define _HEAP_NAME_ ".emheap" +#define EHEAP_RSV_SIZE 16 +/* +以下の表は Windows Vista での emacs.exe の 仮想メモりー map の一部です。 + +00000000 Free 00010000 +00010000 Mapped 00010000 1 -RW- + 00010000 Mapped 00010000 -RW- -- +00020000 Mapped 00001000 1 -RW- + 00020000 Mapped 00001000 -RW- -- +00021000 Free 0000F000 +00030000 Private 00100000 3 -RW- Thread Stack + 00030000 Reserve 000E4000 -RW- -- + 00114000 Private 00001000 -RW- G- + 00115000 Private 0001B000 -RW- -- +00130000 Mapped 00004000 1 -R-- + 00130000 Mapped 00004000 -R-- -- +00134000 Free 0000C000 +00140000 Mapped 00041000 1 -R-- + 00140000 Mapped 00041000 -R-- -- +00181000 Free 0000F000 +00190000 Private 00020000 2 -RW- + 00190000 Private 00001000 -RW- -- + 00191000 Reserve 0001F000 -RW- -- +001B0000 Private 00040000 2 -RW- + 001B0000 Private 00001000 -RW- -- + 001B1000 Reserve 0003F000 -RW- -- +001F0000 Private 00001000 1 -RW- + 001F0000 Private 00001000 -RW- -- +001F1000 Free 0000F000 +00200000 Private 00100000 2 -RW- Default Process Heap + 00200000 Private 00031000 -RW- -- + 00231000 Reserve 000CF000 -RW- -- +00300000 Mapped 0037E000 1 -R-- + 00300000 Mapped 0037E000 -R-- -- +0067E000 Free 00002000 +00680000 Private 00100000 3 -RW- Thread Stack + 00680000 Reserve 000FB000 -RW- -- + 0077B000 Private 00001000 -RW- G- + 0077C000 Private 00004000 -RW- -- +00780000 Private 00001000 1 -RW- + 00780000 Private 00001000 -RW- -- +00781000 Free 0000F000 +00790000 Mapped 00001000 1 -R-- + 00790000 Mapped 00001000 -R-- -- +00791000 Free 0005F000 +007F0000 Private 00040000 2 -RW- + 007F0000 Private 00001000 -RW- -- + 007F1000 Reserve 0003F000 -RW- -- +00830000 Private 00010000 2 -RW- + 00830000 Private 00009000 -RW- -- + 00839000 Reserve 00007000 -RW- -- +00840000 Mapped 000C8000 4 -R-- + 00840000 Mapped 00004000 -R-- -- + 00844000 Reserve 000BC000 -R-- -- + 00900000 Mapped 00003000 -R-- -- + 00903000 Reserve 00005000 -R-- -- +00908000 Free 00008000 +00910000 Mapped 00103000 1 -R-- + 00910000 Mapped 00103000 -R-- -- +00A13000 Free 0001D000 +00A30000 Private 00040000 2 -RW- + 00A30000 Private 0001E000 -RW- -- + 00A4E000 Reserve 00022000 -RW- -- +00A70000 Mapped 0037E000 1 -R-- + 00A70000 Mapped 0037E000 -R-- -- +00DEE000 Free 00002000 +00DF0000 Mapped 00300000 2 -R-- + 00DF0000 Mapped 0005E000 -R-- -- + 00E4E000 Reserve 002A2000 -R-- -- +010F0000 Free 000E0000 +011D0000 Private 00010000 2 -RW- + 011D0000 Private 00008000 -RW- -- + 011D8000 Reserve 00008000 -RW- -- +011E0000 Private 00100000 2 -RW- + 011E0000 Private 00012000 -RW- -- + 011F2000 Reserve 000EE000 -RW- -- +012E0000 Private 00010000 2 -RW- + 012E0000 Private 00001000 -RW- -- + 012E1000 Reserve 0000F000 -RW- -- +012F0000 Free 00030000 +01320000 Private 00010000 2 -RW- + 01320000 Private 00001000 -RW- -- + 01321000 Reserve 0000F000 -RW- -- +01330000 Private 00100000 3 -RW- Thread Stack + 01330000 Reserve 000FB000 -RW- -- + 0142B000 Private 00001000 -RW- G- + 0142C000 Private 00004000 -RW- -- +01430000 Private 00100000 3 -RW- Thread Stack + 01430000 Reserve 000FB000 -RW- -- + 0152B000 Private 00001000 -RW- G- + 0152C000 Private 00004000 -RW- -- +01530000 Private 00100000 3 -RW- Thread Stack + 01530000 Reserve 000FB000 -RW- -- + 0162B000 Private 00001000 -RW- G- + 0162C000 Private 00004000 -RW- -- +01630000 Free 009D0000 +02000000 Image 00720000 77 ERWC ImageBase emacs.exe + 02000000 Image 00001000 -R-- -- ImageHeader + 02001000 Image 0003A000 ERWC -- .text section + 0203B000 Image 00001000 ERW- -- + 0203C000 Image 00038000 ERWC -- + 02074000 Image 00001000 ERW- -- + 02075000 Image 00002000 ERWC -- + 02077000 Image 00002000 ERW- -- + 02079000 Image 00008000 ERWC -- + 02081000 Image 00001000 ERW- -- + 02082000 Image 00009000 ERWC -- + 0208B000 Image 00002000 ERW- -- + 0208D000 Image 000C3000 ERWC -- + 02150000 Image 00004000 ERW- -- + 02154000 Image 00003000 ERWC -- + 02157000 Image 00002000 ERW- -- + 02159000 Image 00002000 ERWC -- + 0215B000 Image 00001000 -RW- -- .data and .emdata(.bss) section + 0215C000 Image 00004000 -RWC -- + 02160000 Image 00001000 -RW- -- + 02161000 Image 00121000 -RWC -- + 02282000 Image 00005000 -RW- -- + 02287000 Image 0002A000 -RWC -- + 022B1000 Image 0000D000 -RW- -- + 022BE000 Image 0001A000 -R-- -- .rdata section + 022D8000 Image 00001000 -RWC -- .idata section + 022D9000 Image 00002000 -RW- -- + 022DB000 Image 00002000 -RWC -- + 022DD000 Image 00008000 -RW- -- .eheap section + 022E5000 Image 00004000 -RWC -- + 022E9000 Image 00003000 -RW- -- + 022EC000 Image 00001000 -RWC -- + 022ED000 Image 0001C000 -RW- -- + 02309000 Image 00007000 -RWC -- + 02310000 Image 0001B000 -RW- -- + 0232B000 Image 00001000 -RWC -- + 0232C000 Image 00003000 -RW- -- + 0232F000 Image 00001000 -RWC -- + 02330000 Image 00001000 -RW- -- + 02331000 Image 0000F000 -RWC -- + 02340000 Image 00004000 -RW- -- + 02344000 Image 00010000 -RWC -- + 02354000 Image 0000D000 -RW- -- + 02361000 Image 0000F000 -RWC -- + 02370000 Image 0005C000 -RW- -- + 023CC000 Image 00004000 -RWC -- + 023D0000 Image 00024000 -RW- -- + 023F4000 Image 0000C000 -RWC -- + 02400000 Image 00024000 -RW- -- + 02424000 Image 0000C000 -RWC -- + 02430000 Image 0000A000 -RW- -- + 0243A000 Image 00006000 -RWC -- + 02440000 Image 00014000 -RW- -- + 02454000 Image 0000C000 -RWC -- + 02460000 Image 00051000 -RW- -- + 024B1000 Image 0000F000 -RWC -- + 024C0000 Image 00021000 -RW- -- + 024E1000 Image 0000F000 -RWC -- + 024F0000 Image 00021000 -RW- -- + 02511000 Image 0000F000 -RWC -- + 02520000 Image 00021000 -RW- -- + 02541000 Image 0000F000 -RWC -- + 02550000 Image 00021000 -RW- -- + 02571000 Image 0000F000 -RWC -- + 02580000 Image 00021000 -RW- -- + 025A1000 Image 0000F000 -RWC -- + 025B0000 Image 00021000 -RW- -- + 025D1000 Image 0000F000 -RWC -- + 025E0000 Image 00021000 -RW- -- + 02601000 Image 0000F000 -RWC -- + 02610000 Image 00021000 -RW- -- + 02631000 Image 0000F000 -RWC -- + 02640000 Image 00021000 -RW- -- + 02661000 Image 0000F000 -RWC -- + 02670000 Image 00051000 -RW- -- + 026C1000 Image 0000F000 -RWC -- + 026D0000 Image 00032000 -RW- -- + 02702000 Image 0001E000 -RWC -- +02720000 Private 18500000 3 ---- heap + 02720000 Reserve 00500000 ---- -- heap_slop_in_mb 5MB + 02C20000 Private 00690000 -RW- -- heap_chunk_in_mb 384MB(default) + 032B0000 Reserve 17970000 ---- -- +1AC20000 Free 41260000 + +以下 cygwin と win32 の dll が続きますが, それは省略します。 + +emacs.exe の image-base の前に,多くの断片的な memory や thread の +stack が散在しており, 標準の image-base(0x00400000) ではこれらが +.exe file の image の直後に配置されることになります。 それが Vista では +heap_slop_in_mb を必要にし, そして様々な不安定要因となっているようです。 + */ +#define IMAGE_BASE 0x02000000 +#define STACK_RESERVE 0x00100000 +#define LINKER $(CC) -Wl,--script=./ldscript.cwx,--image-base,IMAGE_BASE,--stack,STACK_RESERVE +#define USE_CRT_DLL 1 + +#ifdef CYGWIN_ON_VISTA +# define UNEXEC unexcygwin.o +#else +# define UNEXEC unexcw.o +#endif + +/* end of patch */ /* Use terminfo instead of termcap. Fewer environment variables to go wrong, more terminal types. */ @@ -134,7 +338,7 @@ /*#define HAVE_VFORK*/ /* Xaw3d causes problems -- might have been fixed by NARROWPROTO above, but I haven't tried it */ -/*#undef HAVE_XAW3D*/ +/* #undef HAVE_XAW3D 1 */ /* vfork() interacts badly with setsid(), causing ptys to fail to change their controlling terminal */ diff -urN /home/katufj/cvsroot/emacs/src/unexcygwin.c ./emacs/src/unexcygwin.c --- /home/katufj/cvsroot/emacs/src/unexcygwin.c 1970-01-01 09:00:00.000000000 +0900 +++ ./emacs/src/unexcygwin.c 2007-11-10 10:47:58.558559700 +0900 @@ -0,0 +1,859 @@ +/* -*- Mode: C ; coding: euc-japan-unix -*- */ + +/* unexec() support for Cygwin; */ + +#include <config.h> +#include <lisp.h> +#include <stdio.h> +#include <fcntl.h> +#include <a.out.h> +#include <unistd.h> +#include <w32api/windows.h> +#include <w32api/windowsx.h> +#include <sys/cygwin.h> + +#ifndef OPTIMAIZE +#define OPTIMAIZE 1 +#endif + +/* #define UNEXCW_DEBUG 1 */ + +#if (UNEXCW_DEBUG > 0) +/* Dumper program version. */ +# define DUMPER_MAJOR 6 +# define DUMPER_MINOR 1 +#endif + +#ifdef IMAGE_BASE +# define ModuleHandle (HMODULE)IMAGE_BASE +#else +# define ModuleHandle GetModuleHandle(NULL) +#endif + +#define _EXE_ ".exe" + +#define CYGSOL_CYGWIN (LPTSTR)"Software\\Cygnus Solutions\\Cygwin" +/* reserved memory size of befor heap, for fork() REG_DWORD */ +#define HEAP_SLOP (LPTSTR)"heap_slop_in_mb" +/* heap reserved size. if not defined 384. REG_DWORD */ +#define HEAP_CHUNK (LPTSTR)"heap_chunk_in_mb" + + +/* +** header for Windows executable files +*/ +typedef struct +{ + FILHDR file_hdr; + PEAOUTHDR aout_hdr; + SCNHDR scn_hdr [1]; +} ImageHeader, *lpImageHeader; + +/* Section Name length. */ +#define S_NAME_LEN (8) + +typedef struct +{ + char file_name [MAX_PATH]; /* file name */ + unsigned long size; /* file size */ + long allocated_size; + int fd; /* file handle */ + union { + unsigned char *FileBase; + lpImageHeader ImageHdr; + } u; +} FileData, *lpFileData; + +#define SYMTABSZ(f) ((f)->size - (f)->u.ImageHdr->file_hdr.f_symptr) + +/* see gmalloc.c */ +extern void *(*__morecore) (size_t size); +extern void *__default_morecore (size_t size); +/* see ralloc.c */ +extern void *(*real_morecore) (size_t size); + +static unsigned char *emheap_base = NULL; +static unsigned char *emheap_ptr = NULL; +static unsigned char *emheap_limit = NULL; +#define _HEAP_START emheap_base +#define _HEAP_END emheap_ptr +#define _HEAP_LIMIT emheap_limit +#define _HEAP_RSERVED_SIZE ((unsigned long)emheap_limit - (unsigned long)emheap_base) + +static void init_cygwin_morecore (void); +void *cygwin_morecore (size_t size); +static int fixup_executable (lpFileData out, lpFileData in); +unsigned long GetRegKeyCygwinSubkeyValue (LPTSTR lpSubKeyName); +static char *exe_name (const char *base, char *exe); +static int open_in_file (lpFileData in, const char *name); +static int open_out_file (lpFileData out, const char *name, unsigned long size); +static void close_file_data (lpFileData f); +static SCNHDR *find_section_by_name (const char *name, lpImageHeader img_hdr); +static int check_imgheader (lpImageHeader src); +int unexec (const char *outname, const char *inname, void *start_data, void *start_bss, void *entry_address); + +#define _HEAP_SIZE ((unsigned long)_HEAP_END - (unsigned long)_HEAP_START) + +/* cygwin's ld.exe add labels for fork(). */ +extern int _data_start__; /* start of .data section label. */ +extern int _data_end__; /* end of .data section label. */ +extern int _bss_start__; /* start of .bss section label. */ +extern int _bss_end__; /* end of .bss section label. */ + +#define _DATA_START (unsigned long)(&_data_start__) +#define _DATA_END (unsigned long)(&_data_end__) +#define _DATA_SIZE (_DATA_END - _DATA_START) +#define _BSS_START (unsigned long)(&_bss_start__) +#define _BSS_END (unsigned long)(&_bss_end__) +#define _BSS_SIZE (_BSS_END - _BSS_START) + +#define _RDATA ".rdata" +#define _IDATA ".idata" +#ifdef _HEAP_NAME_ +# define _EHEAP _HEAP_NAME_ +#else +# define _EHEAP ".eheap" +#endif +#define _STAB ".stab" +#define _STABSTR ".stabstr" +#define _EMDATA ".emdata" + +#define EXTR_SIZE1(s) (RoundUp(_BSS_SIZE,(s)->u.ImageHdr->aout_hdr.FileAlignment)) +#define EXTR_SIZE(s) (EXTR_SIZE1(s) + _HEAP_RSERVED_SIZE) + +#if defined(__GNUC__) && defined(OPTIMIZE) +static __inline__ unsigned long +RoundUp (unsigned long x, unsigned long align) +{ + return (x + (align - 1) & ~(align - 1)); +} + +static __inline__ + +unsigned long +new_file_size (lpFileData src) +{ + /* add rounduped file alignment of .bss section raw data size. */ + return (src->size + EXTR_SIZE (src)); +} + +static __inline__ +unsigned long +Max (unsigned long a, unsigned long b) +{ + return (a > b ? a : b); +} + +static __inline__ +unsigned long +Min (unsigned long a, unsigned long b) +{ + return (a < b ? a : b); +} + +#else +# define RoundUp(x, a) (unsigned long)(((unsigned long)(x) + \ + ((unsigned long)(a) - 1)) & \ + ~((unsigned long)(a) - 1)) +# define new_file_size(s) (unsigned long)((s)->size + EXTR_SIZE(s)) +# define Max(a, b) ((unsigned long)(a) > (unsigned long)(b) ? (unsigned long)(a) : (unsigned long)(b)) +# define Min(a, b) ((unsigned long)(a) < (unsigned long)(b) ? (unsigned long)(a) : (unsigned long)(b)) +#endif + +static +void +init_cygwin_morecore (void) +{ + lpImageHeader img_hdr = (lpImageHeader) ModuleHandle; + SCNHDR *heap_scn = find_section_by_name (_EHEAP, img_hdr); + + if (heap_scn == NULL) + abort (); + _HEAP_START = _HEAP_END = (void *)(img_hdr->aout_hdr.ImageBase + + heap_scn->s_vaddr); + _HEAP_LIMIT = (void *)((unsigned long)_HEAP_START + heap_scn->s_paddr); +} + +void *cygwin_morecore (size_t size) +{ + long result = (long)size; + void *ret; + + if (_HEAP_START == NULL) + init_cygwin_morecore (); + + if (result == 0) + ret = (void *)_HEAP_END; + else if (result < 0) + { + result = -result; + if (_HEAP_END - result < _HEAP_START) + return NULL; + _HEAP_END -= result; + ret = (void *)_HEAP_END; + } + else + { + if (_HEAP_END + result > _HEAP_LIMIT) + return NULL; + + ret = (void *)_HEAP_END; + _HEAP_END += result; + } + + return ret; +} + +void cygwin_premain0 (int argc, char **argv, struct per_process *proc) +{ + if (_HEAP_START != NULL) /* only after dump. */ + { + proc->data_end = (void *)_BSS_END; + proc->bss_start = (void *)_HEAP_START; + proc->bss_end = (void *)_HEAP_END; + } +} + + +/* + Get REG sub-key value in "Software\Cygnus Solutions\Cygwin". + If notfoundef return 0; +*/ + +unsigned long +GetRegKeyCygwinSubkeyValue (LPTSTR lpSubKeyName) +{ + DWORD cbData; + LONG dwRetValue; + DWORD lpdwType; + DWORD lpdwValue = 0; + HKEY hkey; + + dwRetValue = RegOpenKeyEx (HKEY_CURRENT_USER, + CYGSOL_CYGWIN, + 0, + KEY_READ, + &hkey); + if (dwRetValue == ERROR_SUCCESS) + { + lpdwType = REG_DWORD; + cbData = sizeof (DWORD); + dwRetValue = RegQueryValueEx (hkey, + lpSubKeyName, + NULL, + &lpdwType, + (LPBYTE)&lpdwValue, + &cbData); + RegCloseKey (hkey); + if (dwRetValue == ERROR_SUCCESS && + lpdwType == REG_DWORD) + return lpdwValue; + } + dwRetValue = RegOpenKeyEx (HKEY_LOCAL_MACHINE, + CYGSOL_CYGWIN, + 0, + KEY_READ, + &hkey); + if (dwRetValue == ERROR_SUCCESS) + { + lpdwType = REG_DWORD; + cbData = sizeof (DWORD); + dwRetValue = RegQueryValueEx (hkey, + lpSubKeyName, + NULL, + &lpdwType, + (LPBYTE)&lpdwValue, + &cbData); + RegCloseKey (hkey); + if (dwRetValue == ERROR_SUCCESS && + lpdwType == REG_DWORD) + return lpdwValue; + } + return 0L; +} + +/* + append '.exe' and convert POSX path to Win32 path. + */ +static +char * +exe_name (const char *base, char *exe) +{ + int len; + + strcpy (exe, base); + len = strlen (exe); + if (len < sizeof (_EXE_) || + stricmp (exe + (len - (sizeof (_EXE_) - 1)), _EXE_) != 0) + /* append '.exe' */ + strcat (exe, _EXE_); + + return exe; +} + +#define ALLOCATION_ALIGN (64 * 1024) +#define ALLOCATION_SIZE(sz) RoundUp ((sz), ALLOCATION_ALIGN) + +static +int +open_in_file (lpFileData in, const char *name) +{ + struct stat _stbuf; + int ret = TRUE; + + in->u.FileBase = NULL; + in->size = in->allocated_size = 0; + + in->fd = open (exe_name (name, in->file_name), O_RDONLY | O_BINARY, 0755); + if (in->fd < 0) + { + fprintf (stderr, "Failed to open in file %s.\n", name); + return FALSE; + } + if (fstat (in->fd, &_stbuf) == -1) + { + fprintf (stderr, "Failed to fstat for get file size, %s.\n", name); + ret = FALSE; + goto label_close_file; + } + in->size = _stbuf.st_size; + in->u.FileBase = (unsigned char*)sbrk (ALLOCATION_SIZE (in->size)); + if (in->u.FileBase <= 0) + { + fprintf (stderr, "Failed to allocation memory for file %s.\n", name); + ret = FALSE; + goto label_close_file; + } + in->allocated_size = -(ALLOCATION_SIZE (in->size)); + if (read (in->fd, in->u.FileBase, in->size) != in->size) + { + sbrk (in->allocated_size); + fprintf (stderr, "Failed to read in file %s.\n", name); + ret = FALSE; + } + label_close_file: + close (in->fd); + in->fd = -1; + + return ret; +} + +static +int +open_out_file (lpFileData out, const char *name, unsigned long size) +{ + out->u.FileBase = NULL; + out->size = out->allocated_size = 0; + + out->fd = open (exe_name (name, out->file_name), + O_RDWR | O_TRUNC | O_CREAT | O_BINARY, 0755); + if (out->fd < 0) + { + fprintf (stderr, "Failed to create out file %s.\n", name); + return FALSE; + } + out->u.FileBase = (unsigned char*)sbrk (ALLOCATION_SIZE (size)); + if (out->u.FileBase <= 0) + { + close (out->fd); + out->fd = -1; + fprintf (stderr, "Failed to allocation memory for out file %s.\n", name); + return FALSE; + } + out->allocated_size = -(ALLOCATION_SIZE (size)); + + return TRUE; +} + +/* + getting section header pointor to section name. +*/ +static +SCNHDR * +find_section_by_name (const char *name, lpImageHeader img_hdr) +{ + int i, nscn, len; + + len = strlen (name); + /* too long section name S_NAME_LEN */ + if (len > S_NAME_LEN) + return NULL; + + /* Compare '\0' character + section name is not ASCIZ strings. not use strcmp(). + */ + if (len < S_NAME_LEN) + len++; + + nscn = (int)(img_hdr->file_hdr.f_nscns); + + for (i = 0; i < nscn; i++) + { + if (! strncmp (img_hdr->scn_hdr[i].s_name, name, len)) + return &(img_hdr->scn_hdr [i]); + } + + return NULL; +} + +static +int +check_imgheader (lpImageHeader src) +{ + char *scn_names [] = { _TEXT, _DATA, _BSS, _EHEAP, NULL }; + int i; + + if (src->file_hdr.e_magic != DOSMAGIC) + { + fprintf (stderr, "0x%04x is invalid dos magic!\n", + src->file_hdr.e_magic); + return FALSE; + } + if (src->file_hdr.nt_signature != NT_SIGNATURE) + { + fprintf (stderr, + "0x%04x is invalid nt sigunature\n", + src->file_hdr.nt_signature); + return FALSE; + } + for (i = 0; scn_names [i] != NULL; i++) + { + if (find_section_by_name (scn_names [i], src) == NULL) + { + fprintf (stderr, "Not founde %s section!\n", scn_names [i]); + return FALSE; + } + } + + return TRUE; +} + + +/* + Fixup output execunable, and image header. + */ +static +int +fixup_executable (lpFileData out, lpFileData in) +{ + lpImageHeader dst = out->u.ImageHdr; + lpImageHeader src = in->u.ImageHdr; + int i, nscns, ret = TRUE; + void *(*save_morecore) (size_t) = __morecore; + void *(*save_real_morecore) (size_t) = real_morecore; + unsigned long adjusting; + + /* cygwin_morecore() only used before dump. */ + if (__morecore == cygwin_morecore) + __morecore = __default_morecore; + else if (real_morecore == cygwin_morecore) + real_morecore = __default_morecore; + +#if (UNEXCW_DEBUG > 0) + fprintf (stderr, "Dumper Version %d.%d\n", + DUMPER_MAJOR, DUMPER_MINOR); +#endif + + if ((ret = check_imgheader (src)) == TRUE) + { + /* copyed ImageHeader */ + bcopy ((void *)src, (void *)dst, src->aout_hdr.SizeOfHeaders); + + + /* Fixup .eheap size to used size. */ + adjusting = (_HEAP_RSERVED_SIZE - + RoundUp (_HEAP_SIZE, + dst->aout_hdr.SectionAlignment)); + dst->aout_hdr.SizeOfImage -= adjusting; + + /* Reset Initialized data and Uninitialized data bytes. */ + dst->aout_hdr.dsize = 0; + dst->aout_hdr.bsize = 0; + out->size = dst->aout_hdr.SizeOfHeaders; + nscns = src->file_hdr.f_nscns; + + for (i = 0; i < nscns; i++) + { + void *svaddr; /* copy source pointor. */ + + /* copy from memory image */ + svaddr = (void *)(src->scn_hdr [i].s_vaddr + src->aout_hdr.ImageBase); + + /* If .bss section? */ + if (svaddr == (void *)_BSS_START) + { + /* section name convert `.bss' to `.emdata' */ + strncpy (dst->scn_hdr [i].s_name, _EMDATA, S_NAME_LEN); + dst->scn_hdr [i].s_size = RoundUp (dst->scn_hdr [i].s_paddr, + dst->aout_hdr.FileAlignment); + dst->scn_hdr [i].s_flags &= ~(IMAGE_SCN_CNT_UNINITIALIZED_DATA); + dst->scn_hdr [i].s_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA; + } + /* If .data section? */ + else if (svaddr == (void *)_DATA_START) + ; + /* If .eheap section? */ + else if (svaddr == (void *)_HEAP_START) + { + dst->scn_hdr [i].s_paddr = RoundUp (_HEAP_SIZE, + dst->aout_hdr.SectionAlignment); + dst->scn_hdr [i].s_size = dst->scn_hdr [i].s_paddr; + dst->scn_hdr [i].s_flags &= ~(IMAGE_SCN_CNT_UNINITIALIZED_DATA); + dst->scn_hdr [i].s_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA; + } + /* If other sections? */ + else + { + /* copy from file image */ + svaddr = (void *)(in->u.FileBase + src->scn_hdr [i].s_scnptr); + + if (dst->scn_hdr[i].s_flags & IMAGE_SCN_LNK_REMOVE) /* .stab or .stabstr */ + dst->scn_hdr [i].s_vaddr -= adjusting; + } + + dst->scn_hdr [i].s_scnptr = out->size; + + /* recounte initialized and uninitialized data bytes. */ + if (dst->scn_hdr [i].s_flags & IMAGE_SCN_CNT_INITIALIZED_DATA) + dst->aout_hdr.dsize += dst->scn_hdr [i].s_size; + else if (dst->scn_hdr [i].s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) + dst->aout_hdr.bsize += dst->scn_hdr [i].s_size; + +#if 0 /* s_relptr and s_lnnoptr is always zero on cygwin. we not + need checking */ + /* adjustment s_relptr and s_lnnoptr */ + if (dst->scn_hdr [i].s_relptr != 0) + dst->scn_hdr [i].s_relptr += + out->size - src->scn_hdr [i].s_scnptr; + if (dst->scn_hdr [i].s_lnnoptr != 0) + dst->scn_hdr [i].s_lnnoptr += + out->size - src->scn_hdr [i].s_scnptr; +#endif + + bcopy (svaddr, + (void *)(out->u.FileBase + dst->scn_hdr [i].s_scnptr), + dst->scn_hdr [i].s_size); +#if (UNEXCW_DEBUG > 0) + fprintf (stderr, "Dumped %.8s section:S[%08X]:E[%08X]:O[%08X]:B[%08X]\n", + src->scn_hdr [i].s_name, + src->aout_hdr.ImageBase + src->scn_hdr [i].s_vaddr, + src->aout_hdr.ImageBase + src->scn_hdr [i].s_vaddr + src->scn_hdr [i].s_paddr, + src->scn_hdr[i].s_scnptr, + src->scn_hdr[i].s_paddr); + fprintf (stderr, "-----> %.8s section:S[%08X]:E[%08X]:O[%08X]:B[%08X]\n", + dst->scn_hdr[i].s_name, + dst->aout_hdr.ImageBase + dst->scn_hdr[i].s_vaddr, + dst->aout_hdr.ImageBase + dst->scn_hdr[i].s_vaddr + dst->scn_hdr [i].s_paddr, + dst->scn_hdr [i].s_scnptr, + dst->scn_hdr [i].s_paddr); +#endif + + /* next s_scnptr */ + out->size += dst->scn_hdr [i].s_size; + } + + /* adjustment of symbol tabel position. */ + if (dst->file_hdr.f_symptr != 0) + { + dst->file_hdr.f_symptr = out->size; + out->size += SYMTABSZ (in); + bcopy ((void*)(in->u.FileBase + src->file_hdr.f_symptr), + (void*)(out->u.FileBase + dst->file_hdr.f_symptr), + SYMTABSZ (in)); +#if (UNEXCW_DEBUG > 0) + fprintf (stderr, "Dumped Symbol Tabel : Offset 0x%08x, %ld bytes.\n", + src->file_hdr.f_symptr, + SYMTABSZ (in)); + fprintf (stderr, "-----> Symbol Tabel : Offset 0x%08x, %ld bytes.\n", + dst->file_hdr.f_symptr, + SYMTABSZ (in)); +#endif + } + + if (write (out->fd, out->u.FileBase, out->size) != out->size) + { + ret = FALSE; + fprintf (stderr, "Failed to write file %s.\n", out->file_name); + } + } + + close (out->fd); + sbrk (out->allocated_size + in->allocated_size); + + if (__morecore != save_morecore) + __morecore = save_morecore; + if (real_morecore != save_real_morecore) + real_morecore = save_real_morecore; + + return ret; +} + +int +unexec (const char *outname, + const char *inname, + void *start_data, + void *start_bss, + void *entry_address) +{ + FileData in, out; + char *error; + + if (open_in_file (&in, inname) == FALSE) + exit (-1); + + /* open input file. */ + if (open_out_file (&out, outname, new_file_size (&in)) == FALSE) + exit (-1); + + /* dumping sections(.text, .data, .rdata, .bss, .idata etc.) and heap. */ + if (fixup_executable (&out, &in) == FALSE) + exit (-1); + + return 0; +} + +#ifdef DEBUG_CYGWIN_ON_VISTA +/* + under code CopyRighted Jeferey Richter. + *** NOT GPL **** +*/ +/*** end of not GPL ******/ + +DEFUN ("cygwin-image-header-dump", + Fcygwin_image_header_dump, Scygwin_image_header_dump, + 0, 0, 0, + doc: /* dumed executable file ImageHeaders. */) + () +{ + lpImageHeader img_hdr = (lpImageHeader)ModuleHandle; + Lisp_Object _buf = Fget_buffer_create (build_string ("*ImageHeaderDump*")); + int i, j; + char buf [1024]; + unsigned char *p = (unsigned char *)img_hdr; + + Fset_buffer (_buf); + + /* binaly hex dump */ + insert_string ("Hex dumped:\n"); + insert_string (" : +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F : 0123456789ABCDEF\n"); + for (i = 0; i < img_hdr->aout_hdr.SizeOfHeaders; i += 16) + { + sprintf (buf, "%08x : %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x : ", + img_hdr->aout_hdr.ImageBase + i, + *(p+i), *(p+i+1), *(p+i+2), *(p+i+3), *(p+i+4), *(p+i+5), *(p+i+6), *(p+i+7), + *(p+i+8), *(p+i+9), *(p+i+10), *(p+i+11), *(p+i+12), *(p+i+13), *(p+i+14), *(p+i+15)); + insert_string (buf); + for (j = 0; j < 16; j++) + insert_char ((*(p + i + j) >= 0x20 && *(p + i + j) < 0x7f ? *(p + i + j) : '.')); + insert_char ('\n'); + } + + /* file header */ + insert_string ("\n\nstruct external_PE_filehdr:\n"); + insert_string (" /* DOS header fields */\n"); + sprintf (buf, " unsigned short e_magic = 0x%04x; /* Magic number, 0x5a4d */\n", + img_hdr->file_hdr.e_magic); + insert_string (buf); + sprintf (buf, " unsigned short e_cblp = 0x%04x; /* Bytes on last page of file, 0x90 */\n", + img_hdr->file_hdr.e_cblp); + insert_string (buf); + sprintf (buf, " unsigned short e_cp = 0x%04x; /* Pages in file, 0x3 */\n", + img_hdr->file_hdr.e_cp); + insert_string (buf); + sprintf (buf, " unsigned short e_crlc = 0x%04x; /* Relocations, 0x0 */\n", + img_hdr->file_hdr.e_crlc); + insert_string (buf); + sprintf (buf, " unsigned short e_cparhdr = 0x%04x; /* Size of header in paragraphs, 0x4 */\n", + img_hdr->file_hdr.e_cparhdr); + insert_string (buf); + sprintf (buf, " unsigned short e_minalloc = 0x%04x; /* Minimum extra paragraphs needed, 0x0 */\n", + img_hdr->file_hdr.e_minalloc); + insert_string (buf); + sprintf (buf, " unsigned short e_maxalloc = 0x%04x; /* Maximum extra paragraphs needed, 0xFFFF */\n", + img_hdr->file_hdr.e_maxalloc); + insert_string (buf); + sprintf (buf, " unsigned short e_ss = 0x%04x; /* Initial (relative) SS value, 0x0\n", + img_hdr->file_hdr.e_ss); + insert_string (buf); + sprintf (buf, " unsigned short e_sp = 0x%04x; /* Initial SP value, 0xb8 */\n", + img_hdr->file_hdr.e_sp); + insert_string (buf); + sprintf (buf, " unsigned short e_csum = 0x%04x; /* Checksum, 0x0 */\n", + img_hdr->file_hdr.e_csum); + insert_string (buf); + sprintf (buf, " unsigned short e_ip = 0x%04x; /* Initial IP value, 0x0 */\n", + img_hdr->file_hdr.e_ip); + insert_string (buf); + sprintf (buf, " unsigned short e_cs = 0x%04x; /* Initial (relative) CS value, 0x0 */\n", + img_hdr->file_hdr.e_cs); + insert_string (buf); + sprintf (buf, " unsigned short e_lfarlc = 0x%04x; /* File address of relocation hable, 0x40 */\n", + img_hdr->file_hdr.e_lfarlc); + insert_string (buf); + sprintf (buf, " unsigned short e_ovno = 0x%04x; /* Overlay number, 0x0 */\n", + img_hdr->file_hdr.e_ovno); + insert_string (buf); + insert_string (" char e_res [4][2]; /* Reserved words, all 0x0 */\n"); + sprintf (buf, " unsigned short e_oemid = 0x%04x; /* OEM identifier (for e_oeminfo), 0x0 */\n", + img_hdr->file_hdr.e_oemid); + insert_string (buf); + sprintf (buf, " unsigned short e_oeminfo = 0x%04x; /* OEM information; e_oemid specific, 0x0 */\n", + img_hdr->file_hdr.e_oeminfo); + insert_string (buf); + insert_string (" char e_res2 [10][2]; /* Reserved words, all 0x0 */\n"); + sprintf (buf, " unsigned long e_lfanew = 0x%08x; /* File address of new exe header, 0x80 */\n", + img_hdr->file_hdr.e_lfanew); + insert_string (buf); + insert_string (" char dos_message[16][4]; /* other stuff, always follow DOS header */\n"); + sprintf (buf, " unsigned long nt_signature = 0x%08x; /* required NT signature, 0x4550 */\n", + img_hdr->file_hdr.nt_signature); + insert_string (buf); + insert_string (" /* From standard header */\n"); + sprintf (buf, " unsigned short f_magic = 0x%04x; /* magic number */\n", + img_hdr->file_hdr.f_magic); + insert_string (buf); + sprintf (buf, " unsigned short f_nscns = 0x%04x; /* number of sections */\n", + img_hdr->file_hdr.f_nscns); + insert_string (buf); + sprintf (buf, " unsigned long f_timdat = 0x%08x; /* time & date stamp */\n", + img_hdr->file_hdr.f_timdat); + insert_string (buf); + sprintf (buf, " unsigned long f_symptr = 0x%08x; /* file pointer to symtab */\n", + img_hdr->file_hdr.f_symptr); + insert_string (buf); + sprintf (buf, " unsigned long f_nsyms = 0x%08x; /* number of symtab entries */\n", + img_hdr->file_hdr.f_nsyms); + insert_string (buf); + sprintf (buf, " unsigned short f_opthdr = 0x%04x; /* sizeof(optinal hdr) */\n", + img_hdr->file_hdr.f_opthdr); + insert_string (buf); + sprintf (buf, " unsigned short f_flags = 0x%04x; /* flags */\n", + img_hdr->file_hdr.f_flags); + + /* aout header */ + insert_string ("\nstruct PEAOUTHDR:\n"); + sprintf (buf, " unsigned short magic = 0x%04x; /* type of file */\n", + img_hdr->aout_hdr.magic); + insert_string (buf); + sprintf (buf, " unsigned short vstamp = 0x%04x; /* version stamp */\n", + img_hdr->aout_hdr.vstamp); + insert_string (buf); + sprintf (buf, " unsigned long tsize = 0x%08x; /* text size in bytes, padded to FW bdry */\n", + img_hdr->aout_hdr.tsize); + insert_string (buf); + sprintf (buf, " unsigned long dsize = 0x%08x; /* initialized data \" \" */\n", + img_hdr->aout_hdr.dsize); + insert_string (buf); + sprintf (buf, " unsigned long bsize = 0x%08x; /* uninitialized data \" \" */\n", + img_hdr->aout_hdr.bsize); + insert_string (buf); + sprintf (buf, " unsigned long entry = 0x%08x; /* entry pt. */\n", + img_hdr->aout_hdr.entry); + insert_string (buf); + sprintf (buf, " unsigned long text_start = 0x%08x; /* base of text used for this file */\n", + img_hdr->aout_hdr.text_start); + insert_string (buf); + sprintf (buf, " unsigned long data_start = 0x%08x; /* base of data used for this file */\n", + img_hdr->aout_hdr.data_start); + insert_string (" /* NT extra fields */\n"); + sprintf (buf, " unsigned long ImageBase = 0x%08x;\n", + img_hdr->aout_hdr.ImageBase); + insert_string (buf); + sprintf (buf, " unsigned long SectionAlignment = 0x%08x;\n", + img_hdr->aout_hdr.SectionAlignment); + insert_string (buf); + sprintf (buf, " unsigned long FileAlignment = 0x%08x;\n", + img_hdr->aout_hdr.FileAlignment); + insert_string (buf); + sprintf (buf, " unsigned short MajorOperatingSystemVersion = 0x%04x;\n", + img_hdr->aout_hdr.MajorOperatingSystemVersion); + insert_string (buf); + sprintf (buf, " unsigned short MinorOperatingSystemVersion = 0x%04x;\n", + img_hdr->aout_hdr.MinorOperatingSystemVersion); + insert_string (buf); + sprintf (buf, " unsigned short MajorImageVersion = 0x%04x;\n", + img_hdr->aout_hdr.MajorImageVersion); + insert_string (buf); + sprintf (buf, " unsigned short MinorImageVersion = 0x%04x;\n", + img_hdr->aout_hdr.MinorImageVersion); + insert_string (buf); + sprintf (buf, " unsigned short MajorSubsystemVersion = 0x%04x;\n", + img_hdr->aout_hdr.MajorSubsystemVersion); + insert_string (buf); + sprintf (buf, " unsigned short MinorSubsystemVersion = 0x%04x;\n", + img_hdr->aout_hdr.MinorSubsystemVersion); + insert_string (buf); + insert_string (" char Reservod1 [4];\n"); + sprintf (buf, " unsigned long SizeOfImage = 0x%08x;\n", + img_hdr->aout_hdr.SizeOfImage); + insert_string (buf); + sprintf (buf, " unsigned long SizeOfHeaders = 0x%08x;\n", + img_hdr->aout_hdr.SizeOfHeaders); + insert_string (buf); + sprintf (buf, " unsigned long CheckSum = 0x%08x;\n", + img_hdr->aout_hdr.CheckSum); + insert_string (buf); + sprintf (buf, " unsigned short Subsystem = 0x%04x;\n", + img_hdr->aout_hdr.Subsystem); + insert_string (buf); + sprintf (buf, " unsigned short DllCharacteristics = 0x%04x;\n", + img_hdr->aout_hdr.DllCharacteristics); + insert_string (buf); + sprintf (buf, " unsigned long SizeOfStackReserve = 0x%08x;\n", + img_hdr->aout_hdr.SizeOfStackReserve); + insert_string (buf); + sprintf (buf, " unsigned long SizeOfStackCommit = 0x%08x;\n", + img_hdr->aout_hdr.SizeOfStackCommit); + insert_string (buf); + sprintf (buf, " unsigned long SizeOfHeapReserve = 0x%08x;\n", + img_hdr->aout_hdr.SizeOfHeapReserve); + insert_string (buf); + sprintf (buf, " unsigned long SizeOfHeapCommit = 0x%08x;\n", + img_hdr->aout_hdr.SizeOfHeapCommit); + insert_string (buf); + sprintf (buf, " unsigned long LoaderFlags = 0x%08x;\n", + img_hdr->aout_hdr.LoaderFlags); + insert_string (buf); + sprintf (buf, " unsigned long NumberOfRvaAndSizes = 0x%08x;\n", + img_hdr->aout_hdr.NumberOfRvaAndSizes); + insert_string (buf); + insert_string (" char DataDirectory [16][2][4]; /* 16 entries, 2 elements/entry, 4 chars */\n"); + + insert_string ("\nstruct external_scnhdr:\n"); + + for (i = 0; i < img_hdr->file_hdr.f_nscns; i++) + { + sprintf (buf, "scn_hdr[%d] :\n", i); + insert_string (buf); + sprintf (buf, " char s_name [%d] = \"%.8s\"\n", S_NAME_LEN, img_hdr->scn_hdr [i].s_name); + insert_string (buf); + sprintf (buf, " unsigned long s_paddr = 0x%08x\n", img_hdr->scn_hdr [i].s_paddr); + insert_string (buf); + sprintf (buf, " unsigned long s_vaddr = 0x%08x\n", img_hdr->scn_hdr [i].s_vaddr); + insert_string (buf); + sprintf (buf, " unsigned long s_size = 0x%08x\n", img_hdr->scn_hdr [i].s_size); + insert_string (buf); + sprintf (buf, " unsigned long s_scnptr = 0x%08x\n", img_hdr->scn_hdr [i].s_scnptr); + insert_string (buf); + sprintf (buf, " unsigned long s_relptr = 0x%08x\n", img_hdr->scn_hdr [i].s_relptr); + insert_string (buf); + sprintf (buf, " unsigned long s_lnnoptr = 0x%08x\n", img_hdr->scn_hdr [i].s_lnnoptr); + insert_string (buf); + sprintf (buf, " unsigned short s_nreloc = 0x%04x\n", img_hdr->scn_hdr [i].s_nreloc); + insert_string (buf); + insert_string (buf); + sprintf (buf, " unsigned long s_flags = 0x%08x\n", img_hdr->scn_hdr [i].s_flags); + insert_string (buf); + } + + return Qnil; +} + +void +syms_of_cygwin_debug_on_vista (void) +{ + /* defsubr (&Scygwin_vmmap); */ + defsubr (&Scygwin_image_header_dump); +} + +#endif /* DEBUG_CYGWIN_ON_VISTA */ diff -urN /home/katufj/cvsroot/emacs/src/unexcygwin.hh ./emacs/src/unexcygwin.hh --- /home/katufj/cvsroot/emacs/src/unexcygwin.hh 1970-01-01 09:00:00.000000000 +0900 +++ ./emacs/src/unexcygwin.hh 2007-11-08 19:54:26.560000000 +0900 @@ -0,0 +1,186 @@ +#ifndef UNEXCYGWIN_H +#define UNEXCYGWIN_H +#include <a.out.h> + +typedef enum { True = -1, False } Bool; +typedef unsigned long ulong; +typedef unsigned long& rulong; +typedef unsigned long* plong; +typedef unsigned short ushort; +typedef unsigned short& rushort; +typedef unsigned short* pushort; +typedef char* pchar; +typedef unsigned char uchar; +typedef unsigned char* puchar; +typedef const char* cpchar; +typedef const unsigned char* cpuchar; +typedef void* pvoid; + +#undef _EXE +#undef _TEXT +#undef _DATA +#undef _RDATA +#undef _BSS +#undef _IDATA +#undef _STAB +#undef _STABSTR + +const pchar _EXE (pchar (".exe")); +const pchar _TEXT (pchar (".text")); +const pchar _DATA (pchar (".data")); +const pchar _RDATA (pchar (".rdata")); +const pchar _BSS (pchar (".bss")); +const pchar _IDATA (pchar (".idata")); +const pchar _STAB (pchar (".stab")); +const pchar _STABSTR (pchar (".stabstr")); +const int S_NAME_LEN (8); + +template <class t1, class t2> +t1 RoundUp (t1 x, t2 align) +{ + return ((x + (t1 (align) - 1)) & ~(t1 (align) - 1)); +} + +template <class t1, class t2> +t1 Max (t1 a, t2 b) +{ + return (a > t1 (b) ? a : t1 (b)); +} + +template <class t1, class t2> +t1 Min (t1 a, t2 b) +{ + return (a < t1 (b) ? a : t1 (b)); +} + +typedef class SectionHeader +{ + static class SectionHeader InvalidSection; + char s_name [S_NAME_LEN]; + ulong s_paddr; + ulong s_vaddr; + ulong s_size; + ulong s_scnptr; + ulong s_relptr; + ulong s_lnnoptr; + ushort s_nreloc; + ushort s_nlnno; + ulong s_flags; + +public: + SectionHeader (void) { return; } + ~SectionHeader () { return; } + + pchar SectionName (void) { return s_name; } + pchar SectionName (cpchar name) { strncpy (s_name, name, sizeof (s_name)); return s_name; } + rulong VirtualSize (void) { return s_paddr; } + rulong VirtualSize (ulong size) { return VirtualSize () = size; } + rulong VirtualAddress (void) { return s_vaddr; } + rulong VirtualAddress (ulong vaddr) { return VirtualAddress () = vaddr; } + rulong RawDataSize (void) { return s_size; } + rulong RawDataSize (ulong size) { return RawDataSize () = size; } + rulong PointerOfSection (void) { return s_scnptr; } + rulong PointerOfSection (ulong ptr) { return PointerOfSection () = ptr; } + rulong PointerOfReloc (void) { return s_relptr; } + rulong PointerOfReloc (ulong ptr) { return PointerOfReloc () = ptr; } + rulong PointerOfLinenumber (void) { return s_lnnoptr; } + rulong PointerOfLinenumber (ulong ptr) { return PointerOfLinenumber () = ptr; } + rushort NumberOfRelocs (void) { return s_nreloc; } + rushort NumberOfRelocs (ushort num) { return NumberOfRelocs () = num; } + rushort NumberOfLinenumbers (void) { return s_nlnno; } + rushort NumberOfLinenumbers (ushort num) { return NumberOfLinenumbers () = num; } + rulong SectionFlags (void) { return s_flags; } + rulong SectionFlags (ulong flag) { return SectionFlags () = flag; } + Bool InvalidSectionP (void) { return (this == &InvalidSection ? True : False); } + SectionHeader* InvalidSectionHeader (void) { return &InvalidSection; } +} SectionHeader, *pSectionHeader, &rSectionHeader; + + +typedef class ImageHeader +{ + FILHDR file_hdr; + PEAOUTHDR aout_hdr; + SectionHeader scn_hdr[1]; + + FILHDR& FileHeader (void) { return file_hdr; } + PEAOUTHDR& AoutHeader (void) { return aout_hdr; } + rSectionHeader ScnHeader (int idx) { return scn_hdr [idx]; } +public: + ImageHeader (void) { return; } + ~ImageHeader () { return; } + + // FILE HEADER + rushort NumberOfSections (void) { return FileHeader ().f_nscns; } + rushort NumberOfSections (ushort num) { return NumberOfSections () = num; } + ushort DosMagic (void) { return FileHeader ().e_magic; } + ulong NtSignature (void) { return FileHeader ().nt_signature; } + + // PEAOUTHDR + ulong ImageBase (void) { return AoutHeader ().ImageBase; } + ulong SectionAlignment (void) { return AoutHeader ().SectionAlignment; } + ulong FileAlignment (void) { return AoutHeader ().FileAlignment; } + rulong SizeOfImage (void) { return AoutHeader ().SizeOfImage; } + rulong SizeOfImage (ulong size) { return SizeOfImage () = size; } + ulong SizeOfHeaders (void) { return AoutHeader ().SizeOfHeaders; } + + // SECTION HEADER + rSectionHeader operator [] (int index) { + if (index >= 0 && index < NumberOfSections ()) + return ScnHeader (index); + return *(ScnHeader (0).InvalidSectionHeader ()); + } + rSectionHeader operator [] (cpchar name) { + int len (strlen (name)); + if (len > S_NAME_LEN) return *(ScnHeader (0).InvalidSectionHeader ()); + if (len < S_NAME_LEN) len++; + for (int i = 0; i < NumberOfSections (); i++) + { + if (! strncmp (cpchar(ScnHeader (i).SectionName ()), name, len)) + return ScnHeader (i); + } + return *(ScnHeader (0).InvalidSectionHeader ()); + } + Bool InvalidImageHeaderP (void) { + return ((DosMagic () != DOSMAGIC || + NtSignature () != NT_SIGNATURE || + this->operator [] (_TEXT).InvalidSectionP () == True || + this->operator [] (_DATA).InvalidSectionP () == True || + this->operator [] (_BSS).InvalidSectionP () == True) ? True : False); + } + pvoid OffsetToVirtualAddress (ulong offset) { return pvoid (offset + ImageBase ()); } + ulong VirtualAddressToOffset (pvoid vaddr) { return ulong (vaddr) - ImageBase (); } +} ImageHeader, *pImageHeader, &rImageHeader; + +typedef class FileData +{ + char file_name [MAX_PATH]; + ulong file_size; + Bool chenged; + int fd; + pvoid FileBase; + + pchar FileName (void) { return file_name; } + pchar FileName (cpchar base_name); + int FileHandle (void) { return fd; } + int FileHandle (int fh) { return (fd = fh); } + pvoid BaseAddress (void) { return FileBase; } + pvoid BaseAddress (pvoid addr) { return (FileBase = addr); } + pvoid OffsetToVirtualAddress (ulong off) { return pvoid (ulong (BaseAddress ()) + off); } + ulong VirtualAddressToOffset (pvoid vaddr) { return ulong (vaddr) - ulong (BaseAddress ()); } + ulong FileSize (ulong size) { file_size = size; } + ulong FileSize (void) { return file_size; } + Bool FileChanged (void) { return chenged; } + Bool FileChanged (Bool chg) { return (chenged = chg); } + rImageHeader ImageHeader (void) { return *(pImageHeader (BaseAddress ())); } +public: + Bool InvalidFileDataP (void) { + return ((FileHandle () < 0 || + FileSize () <= 0 || + BaseAddress () == NULL) ? True : False); + } + FileData (cpchar fname); + ~FileData (); + Bool FixUpImageHeader (cpchar scn_name, ulong scn_size); +} FileData; + +#endif /* not UNEXCYGWIN_H */ diff -urN /home/katufj/cvsroot/emacs/src/vm-limit.c ./emacs/src/vm-limit.c --- /home/katufj/cvsroot/emacs/src/vm-limit.c 2007-10-04 06:13:19.999145700 +0900 +++ ./emacs/src/vm-limit.c 2007-10-15 23:13:04.125565400 +0900 @@ -59,6 +59,24 @@ static unsigned long lim_data; +#if defined(CYGWIN) /* patch 07.08.08 by K.Fujii */ +extern unsigned long GetRegKeyCygwinSubkeyValue (const unsigned char *); +#define CYGWIN_DEFAULT_HEAP_SIZE_IN_MB 384 +#define DATA_SIZE ((unsigned long)BSS_END - (unsigned long)DATA_START) + +static +void +get_lim_data () +{ + unsigned long cyg_heap_lim_in_mb = + GetRegKeyCygwinSubkeyValue ((const unsigned char *)"heap_chunk_in_mb"); + + if (! cyg_heap_lim_in_mb) + cyg_heap_lim_in_mb = CYGWIN_DEFAULT_HEAP_SIZE_IN_MB; + lim_data = ((cyg_heap_lim_in_mb * (1024 * 1024)) + + DATA_SIZE); +} +#else #ifdef NO_LIM_DATA static void get_lim_data () @@ -138,6 +156,7 @@ #endif /* not WINDOWSNT */ #endif /* not USG */ #endif /* not NO_LIM_DATA */ +#endif /* not CYGWIN */ /* Verify amount of memory available, complaining if we're near the end. */ diff -urN /home/katufj/cvsroot/emacs/src/w32.c ./emacs/src/w32.c --- /home/katufj/cvsroot/emacs/src/w32.c 2007-10-27 17:39:54.671753800 +0900 +++ ./emacs/src/w32.c 2007-11-10 08:39:06.111559700 +0900 @@ -4018,18 +4018,18 @@ + strlen (load_path)); sprintf (buffer, - "The Emacs Windows initialization file \"%s.el\" " - "could not be found in your Emacs installation. " - "Emacs checked the following directories for this file:\n" - "\n%s\n\n" - "When Emacs cannot find this file, it usually means that it " - "was not installed properly, or its distribution file was " - "not unpacked properly.\nSee the README.W32 file in the " - "top-level Emacs directory for more information.", + TEXT ("The Emacs Windows initialization file \"%s.el\" " + "could not be found in your Emacs installation. " + "Emacs checked the following directories for this file:\n" + "\n%s\n\n" + "When Emacs cannot find this file, it usually means that it " + "was not installed properly, or its distribution file was " + "not unpacked properly.\nSee the README.W32 file in the " + "top-level Emacs directory for more information."), init_file_name, load_path); MessageBox (NULL, buffer, - "Emacs Abort Dialog", + TEXT ("Emacs Abort Dialog"), MB_OK | MB_ICONEXCLAMATION | MB_TASKMODAL); /* Use the low-level Emacs abort. */ #undef abort diff -urN /home/katufj/cvsroot/emacs/src/w32bdf.c ./emacs/src/w32bdf.c --- /home/katufj/cvsroot/emacs/src/w32bdf.c 2007-10-04 06:13:20.139545700 +0900 +++ ./emacs/src/w32bdf.c 2007-11-10 08:55:19.489159700 +0900 @@ -44,8 +44,8 @@ /* about 96 characters */ #define BDF_BITMAP_HEAP_INITIAL_SIZE (64 * 96) -HANDLE hbdf_cp_heap = INVALID_HANDLE_VALUE; -HANDLE hbdf_bmp_heap = INVALID_HANDLE_VALUE; +HANDLE hbdf_cp_heap = NULL /* why INVALID_HANDLE_VALUE? */; +HANDLE hbdf_bmp_heap = NULL /* why INVALID_HANDLE_VALUE? */; void w32_free_bdf_font(bdffont *fontp); bdffont *w32_init_bdf_font(char *filename); @@ -242,9 +242,9 @@ BY_HANDLE_FILE_INFORMATION fileinfo; int i; - if (hbdf_cp_heap == INVALID_HANDLE_VALUE) + if (hbdf_cp_heap == NULL /* INVALID_HANDLE_VALUE */) hbdf_cp_heap = HeapCreate(0, BDF_CODEPOINT_HEAP_INITIAL_SIZE, 0); - if (hbdf_bmp_heap == INVALID_HANDLE_VALUE) + if (hbdf_bmp_heap == NULL /* INVALID_HANDLE_VALUE */) hbdf_bmp_heap = HeapCreate(0, BDF_BITMAP_HEAP_INITIAL_SIZE, 0); if (!hbdf_cp_heap || !hbdf_bmp_heap) @@ -261,7 +261,8 @@ error("Fail to open BDF file"); } hfilemap = CreateFileMapping(hfile, NULL, PAGE_READONLY, 0, 0, NULL); - if (hfilemap == INVALID_HANDLE_VALUE) + if (hfilemap == NULL /* CreateFileMapping () error return NULL, not + INVALID_HANDLE_VALUE */) { CloseHandle(hfile); error("Can't map font"); @@ -828,7 +829,8 @@ size = fileinfo.nFileSizeLow; hfilemap = CreateFileMapping (hfile, NULL, PAGE_READONLY, 0, 0, NULL); - if (hfilemap == INVALID_HANDLE_VALUE) + if (hfilemap == NULL /* CreateFileMapping () error return NULL, not + INVALID_HANDLE_VALUE */) { CloseHandle (hfile); return 0; diff -urN /home/katufj/cvsroot/emacs/src/w32fns.c ./emacs/src/w32fns.c --- /home/katufj/cvsroot/emacs/src/w32fns.c 2007-11-10 14:37:18.217159700 +0900 +++ ./emacs/src/w32fns.c 2007-11-11 15:18:50.430359500 +0900 @@ -56,6 +56,15 @@ #include <winspool.h> #include <objbase.h> +#ifdef USE_W32_IME +#include <imm.h> +#include <dde.h> + +#ifndef HAVE_NTGUI +#include <windows.h> +#endif +#endif + #include <dlgs.h> #define FILE_NAME_TEXT_FIELD edt1 @@ -69,6 +78,11 @@ extern void w32_free_menu_strings P_ ((HWND)); extern XCharStruct *w32_per_char_metric P_ ((XFontStruct *, wchar_t *, int)); +#ifdef RECONVERSION +extern LRESULT w32_get_ime_reconversion_length (); +extern BOOL w32_get_ime_reconversion_string (HWND, WPARAM, RECONVERTSTRING*); +#endif + extern int quit_char; extern char *lispy_function_keys[]; @@ -202,6 +216,15 @@ Lisp_Object Qnone; Lisp_Object Qsuppress_icon; Lisp_Object Qundefined_color; + +#ifdef USE_W32_IME +Lisp_Object Qime_font; +static int IME_event_off_count; +#ifndef HAVE_NTGUI +HWND hwndConsole; +#endif +#endif + Lisp_Object Qcancel_timer; Lisp_Object Qhyper; Lisp_Object Qsuper; @@ -425,7 +448,19 @@ void x_set_tool_bar_lines P_ ((struct frame *, Lisp_Object, Lisp_Object)); static void x_edge_detection P_ ((struct frame *, struct image *, Lisp_Object, Lisp_Object)); - +#ifdef USE_W32_IME +void x_set_ime_font P_ ((struct frame *, Lisp_Object, Lisp_Object)); +void w32_get_ime_logfont P_ ((HWND)); +static void w32_set_ime_conv_window P_ ((struct frame *)); +static void w32_set_ime_status P_ ((HWND, int)); +static int w32_get_ime_status P_ ((HWND)); +static int w32_set_ime_mode P_ ((HWND, int, int)); +void w32_ime_control_init P_ ((void)); +static void w32_set_ime_font P_ ((HWND, LPLOGFONT)); +static BOOL w32_get_ime_composition_string P_ ((HWND)); +static LRESULT CALLBACK conversion_agent_wndproc P_ ((HWND, UINT, WPARAM, LPARAM)); +static int initialize_conversion_agent P_ (()); +#endif @@ -2009,14 +2044,14 @@ Cursor w32_load_cursor (LPCTSTR name) { - /* Try first to load cursor from application resource. */ - Cursor cursor = LoadImage ((HINSTANCE) GetModuleHandle(NULL), - name, IMAGE_CURSOR, 0, 0, - LR_DEFAULTCOLOR | LR_DEFAULTSIZE | LR_SHARED); - if (!cursor) + /* Try first to load a shared predefined cursor. */ + Cursor cursor = LoadImage (NULL, name, IMAGE_CURSOR, 0, 0, + LR_DEFAULTCOLOR | LR_DEFAULTSIZE | LR_SHARED); + if (!cursor) { - /* Then try to load a shared predefined cursor. */ - cursor = LoadImage (NULL, name, IMAGE_CURSOR, 0, 0, + /* Then try to load cursor from application resource. */ + cursor = LoadImage ((HINSTANCE) GetModuleHandle(NULL), + name, IMAGE_CURSOR, 0, 0, LR_DEFAULTCOLOR | LR_DEFAULTSIZE | LR_SHARED); } return cursor; @@ -3914,8 +3949,69 @@ return retval; } +#ifdef USE_W32_IME + case WM_IME_NOTIFY: + if (wParam == IMN_SETOPENSTATUS) + { + if (!IME_event_off_count) + my_post_msg (&wmsg, hwnd, WM_MULE_IME_STATUS, 0, 0); + else + IME_event_off_count--; + } + goto dflt; + + case WM_IME_STARTCOMPOSITION: + { + W32Msg wmsg; + my_post_msg (&wmsg, hwnd, WM_MULE_IMM_SET_COMPOSITION_FONT, 0, 0); + goto dflt; + } + + case WM_MULE_IMM_SET_COMPOSITION_FONT_REPLY: + w32_set_ime_conv_window ((struct frame *) wParam); + w32_set_ime_font (hwnd, (LPLOGFONT) lParam); + break; + + case WM_IME_ENDCOMPOSITION: + goto dflt; + + case WM_IME_COMPOSITION: + { + if (lParam & GCS_RESULTSTR) + { + if (w32_get_ime_composition_string (hwnd)) + return 0; + else + break; + } + goto dflt; + } + + case WM_MULE_IMM_SET_CONVERSION_WINDOW: + w32_set_ime_conv_window ((struct frame *) wParam); + break; + +#ifdef RECONVERSION + case WM_IME_REQUEST: + if (wParam == IMR_RECONVERTSTRING) + if (lParam) + return w32_get_ime_reconversion_string (hwnd, wParam, + (RECONVERTSTRING*) lParam); + else + return w32_get_ime_reconversion_length (); + goto dflt; +#endif +#endif /* USE_W32_IME */ default: + +#ifdef USE_W32_IME + { + if (MESSAGE_IMM_COM_P(msg)) + return conversion_agent_wndproc (hwnd, msg, wParam, lParam); + } +#endif + /* Check for messages registered at runtime. */ if (msg == msh_mousewheel) { @@ -4310,6 +4406,12 @@ x_default_parameter (f, parameters, Qfont, font, "font", "Font", RES_TYPE_STRING); +#ifdef USE_W32_IME + /* fix me. I don't know how to get a font name.*/ + x_default_parameter (f, parameters, Qime_font, font, + "ime-font", "IME-Font", RES_TYPE_STRING); +#endif + } x_default_parameter (f, parameters, Qborder_width, make_number (2), @@ -8011,6 +8113,943 @@ /*********************************************************************** + Input Method Editor + ***********************************************************************/ +#ifdef USE_W32_IME +#define MAX_CONVAGENT 100 + +typedef struct conversion_agent { + HIMC himc; + HWND hwnd; +} conversion_agent; + +static conversion_agent agent[MAX_CONVAGENT]; +static int conversion_agent_num = -1; + +BOOL fIME = FALSE; + +typedef BOOL (WINAPI *IMMGETOPENSTATUSPROC)(HIMC); +IMMGETOPENSTATUSPROC ImmGetOpenStatusProc; + +typedef BOOL (WINAPI *IMMSETOPENSTATUSPROC)(HIMC, BOOL); +IMMSETOPENSTATUSPROC ImmSetOpenStatusProc; + +typedef HWND (WINAPI *IMMGETDEFAULTIMEWNDPROC)(HWND); +IMMGETDEFAULTIMEWNDPROC ImmGetDefaultIMEWndProc; + +typedef LONG (WINAPI *IMMGETCOMPOSITIONSTRINGPROC) + (HIMC, DWORD, LPVOID, DWORD); +IMMGETCOMPOSITIONSTRINGPROC ImmGetCompositionStringProc; + +typedef LONG (WINAPI *IMMSETCOMPOSITIONSTRINGPROC) + (HIMC, DWORD, LPCVOID, DWORD, LPCVOID, DWORD); +IMMSETCOMPOSITIONSTRINGPROC ImmSetCompositionStringProc; + +typedef BOOL (WINAPI *IMMSETCOMPOSITIONFONTPROC) (HIMC, LPLOGFONTA); +IMMSETCOMPOSITIONFONTPROC ImmSetCompositionFontProc; + +typedef HIMC (WINAPI *IMMGETCONTEXTPROC)(HWND); +IMMGETCONTEXTPROC ImmGetContextProc; + +typedef BOOL (WINAPI *IMMGETCONVERSIONSTATUSPROC)(HIMC, LPDWORD, LPDWORD); +IMMGETCONVERSIONSTATUSPROC ImmGetConversionStatusProc; + +typedef BOOL (WINAPI *IMMSETCONVERSIONSTATUSPROC)(HIMC, DWORD, DWORD); +IMMSETCONVERSIONSTATUSPROC ImmSetConversionStatusProc; + +typedef BOOL (WINAPI *IMMGETCONVERSIONLISTPROC) + (HKL, HIMC, LPCTSTR, LPCANDIDATELIST, DWORD, UINT); +IMMGETCONVERSIONLISTPROC ImmGetConversionListProc; + +typedef BOOL (WINAPI *IMMCONFIGUREIMEPROC)(HKL, HWND, DWORD, LPVOID); +IMMCONFIGUREIMEPROC ImmConfigureIMEProc; + +typedef BOOL (WINAPI *IMMNOTIFYIMEPROC)(HIMC, DWORD, DWORD, DWORD); +IMMNOTIFYIMEPROC ImmNotifyIMEProc; + +typedef BOOL (WINAPI *IMMRELEASECONTEXTPROC)(HWND, HIMC); +IMMRELEASECONTEXTPROC ImmReleaseContextProc; + +typedef HIMC (WINAPI *IMMCREATECONTEXTPROC)(void); +IMMCREATECONTEXTPROC ImmCreateContextProc; + +typedef BOOL (WINAPI *IMMDESTROYCONTEXTPROC)(HIMC); +IMMDESTROYCONTEXTPROC ImmDestroyContextProc; + +typedef BOOL (WINAPI *IMMASSOCIATECONTEXTPROC) (HWND, HIMC); +IMMASSOCIATECONTEXTPROC ImmAssociateContextProc; + +typedef BOOL (WINAPI *IMMGETCANDIDATELISTPROC) + (HIMC, DWORD, LPCANDIDATELIST, DWORD); +IMMGETCANDIDATELISTPROC ImmGetCandidateListProc; + +typedef BOOL (WINAPI *IMMGETCANDIDATELISTCOUNTPROC) (HIMC, LPDWORD); +IMMGETCANDIDATELISTCOUNTPROC ImmGetCandidateListCountProc; + +typedef BOOL (WINAPI *IMMGETHOTKEYPROC)(DWORD, LPUINT, LPUINT, LPHKL); +IMMGETHOTKEYPROC ImmGetHotKeyProc; + +Lisp_Object Vime_control; + +static void +w32_set_ime_conv_window (f) + struct frame *f; +{ + if (fIME && !NILP (Vime_control)) + { + HWND IMEhwnd; + COMPOSITIONFORM compform; + struct window *w = XWINDOW (FRAME_SELECTED_WINDOW (f)); + + IMEhwnd = (ImmGetDefaultIMEWndProc)(FRAME_W32_WINDOW (f)); + compform.dwStyle = CFS_RECT; + + compform.ptCurrentPos.x = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x); + + compform.ptCurrentPos.y = WINDOW_TO_FRAME_PIXEL_Y (w, w->phys_cursor.y); + + compform.rcArea.left = (WINDOW_BOX_LEFT_EDGE_X (w) + + WINDOW_LEFT_MARGIN_WIDTH (w) + + WINDOW_LEFT_FRINGE_WIDTH (w)); + + compform.rcArea.top = (WINDOW_TOP_EDGE_Y (w) + + WINDOW_HEADER_LINE_HEIGHT (w)); + + compform.rcArea.right = (WINDOW_BOX_RIGHT_EDGE_X (w) + - WINDOW_RIGHT_MARGIN_WIDTH (w) + - WINDOW_RIGHT_FRINGE_WIDTH (w)); + + compform.rcArea.bottom = (WINDOW_BOTTOM_EDGE_Y (w) + - WINDOW_MODE_LINE_HEIGHT (w)); + + SendMessage(IMEhwnd, WM_IME_CONTROL, (WPARAM)IMC_SETCOMPOSITIONWINDOW, + (LPARAM)(&compform)); + } +} + +static void +w32_set_ime_status (hwnd, openp) + HWND hwnd; + int openp; +{ + HIMC himc; + + himc = (ImmGetContextProc) (hwnd); + (ImmSetOpenStatusProc) (himc, openp); + (ImmReleaseContextProc) (hwnd, himc); +} + +static int +w32_get_ime_status (hwnd) + HWND hwnd; +{ + HIMC himc; + int ret; + + himc = (ImmGetContextProc) (hwnd); + ret = (ImmGetOpenStatusProc) (himc); + (ImmReleaseContextProc) (hwnd, himc); + + return ret; +} + +static int +w32_set_ime_mode (hwnd, mode, mask) + HWND hwnd; + int mode; + int mask; +{ + HIMC himc; + DWORD cmode, smode; + + himc = (ImmGetContextProc) (hwnd); + if (!(ImmGetConversionStatusProc) (himc, &cmode, &smode)) + return 0; + + cmode = (cmode & (~mask)) | (mode & mask); + + (ImmSetConversionStatusProc) (himc, cmode, smode); + (ImmReleaseContextProc) (hwnd, himc); + + return 1; +} + +static BOOL +w32_get_ime_composition_string (hwnd) + HWND hwnd; +{ + HIMC hIMC; + int size; + HANDLE himestr; +#ifdef _UNICODE + LPWSTR lpstr; +#else + LPSTR lpstr; +#endif + + struct frame *f; + + hIMC = (ImmGetContextProc) (hwnd); + if (!hIMC) + return FALSE; + + size = (ImmGetCompositionStringProc) (hIMC, GCS_RESULTSTR, NULL, 0); +#ifdef _UNICODE + size += sizeof (WCHAR); +#else + size += sizeof (CHAR); +#endif + himestr = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, size); + if (!himestr) + abort (); + + (ImmGetCompositionStringProc) (hIMC, GCS_RESULTSTR, himestr, size); + (ImmReleaseContextProc) (hwnd, hIMC); + { + W32Msg wmsg; + f = SELECTED_FRAME (); + my_post_msg (&wmsg, hwnd, WM_MULE_IME_REPORT, + (WPARAM) himestr, (LPARAM) f); + } + return TRUE; +} + +#ifdef RECONVERSION +LRESULT +w32_get_ime_reconversion_length () +{ + int len, pt, pt_byte, start, end; + Lisp_Object str, point; + LRESULT lResult = 0; +#ifdef _UNICODE + int pos; + WCHAR *uc_code, *s; +#else + struct coding_system coding; +#endif + + pt = PT; + pt_byte = PT_BYTE; + + if (!NILP (current_buffer->read_only)) + return 0; + + if (!NILP (current_buffer->mark_active) + && !NILP (Vtransient_mark_mode)) + { + if (marker_position (current_buffer->mark) < PT) + { + start = marker_position (current_buffer->mark); + point = Fpoint (); + end = PT; + } + else + { + start = PT; + point = Fpoint (); + end = marker_position (current_buffer->mark); + } + } + else + { + if (NILP (Feobp ())) + Fforward_char (make_number (1)); + Fforward_word (make_number (-1)); + start = PT; + point = Fpoint (); + Fforward_word (make_number (1)); + end = PT; + } + str = make_buffer_string (start, end, 1); + if (!NILP (Ftext_property_any (make_number (0), + Flength (str), + intern ("read-only"), + Qt, + str))) + { + SET_PT_BOTH (pt, pt_byte); + return FALSE; /* Cannot signal here */ + } +#ifdef _UNICODE + uc_code = (WCHAR *) alloca ((SCHARS (str) + 1) * sizeof (WCHAR)); + s = uc_code; + for (pos = start; pos < end; pos++) + *s++ = (WCHAR) FETCH_CHAR (CHAR_TO_BYTE (pos)); + *s = (WCHAR) '\0'; + len = (lstrlenW (uc_code) + 1) * sizeof (WCHAR); +#else + str = Fdecode_coding_region (start, end, Vlocale_coding_system, Qt); + setup_coding_system (Fcheck_coding_system (Vlocale_coding_system), + &coding); + coding.mode |= (CODING_MODE_SAFE_ENCODING | CODING_MODE_LAST_BLOCK); + coding.common_flags &= ~CODING_ANNOTATION_MASK; + + coding.dst_bytes = SCHARS (str) * 2; + coding.destination = (unsigned char *) xmalloc (coding.dst_bytes + 1); + encode_coding_object (&coding, str, 0, 0, SCHARS (str), SBYTES (str), Qnil); + + len = coding.produced + 1; + xfree (coding.destination); +#endif + SET_PT_BOTH (pt, pt_byte); + + /* Return need size on reconverted string */ + lResult = sizeof (RECONVERTSTRING) + len; + return lResult; +} + +BOOL +w32_get_ime_reconversion_string (hwnd, wParam, reconv) + HWND hwnd; + WPARAM wParam; + RECONVERTSTRING *reconv; +{ + HIMC hIMC; + int len, result, start, end; + Lisp_Object str, point; + struct w32_display_info *dpyinfo = &one_w32_display_info; + struct frame *f = x_window_to_frame (dpyinfo, hwnd); +#ifdef _UNICODE + int pos; + WCHAR *uc_code, *s; +#else + struct coding_system coding; +#endif + + if (!NILP (current_buffer->mark_active) + && !NILP (Vtransient_mark_mode)) + { + if (marker_position (current_buffer->mark) < PT) + { + start = marker_position (current_buffer->mark); + point = Fpoint (); + end = PT; + } + else + { + start = PT; + point = Fpoint (); + end = marker_position (current_buffer->mark); + } + } + else + { + if (NILP (Feobp ())) + Fforward_char (make_number (1)); + Fforward_word (make_number (-1)); + start = PT; + point = Fpoint (); + Fforward_word (make_number (1)); + end = PT; + } + +#ifdef _UNICODE + str = make_buffer_string (start, end, 0); + uc_code = (WCHAR *) alloca ((SCHARS (str) + 1) * sizeof (WCHAR)); + s = uc_code; + for (pos = start; pos < end; pos++) + *s++ = (WCHAR) FETCH_CHAR (CHAR_TO_BYTE (pos)); + *s = (WCHAR) '\0'; + len = lstrlenW (uc_code) + 1; + Fgoto_char (point); + + hIMC = (ImmGetContextProc) (hwnd); + if (!hIMC) + { + return FALSE; + } + + memcpy ((LPSTR) reconv + sizeof (RECONVERTSTRING), + uc_code, len * sizeof (WCHAR)); +#else + str = Fdecode_coding_region (start, end, Vlocale_coding_system, Qt); + setup_coding_system (Fcheck_coding_system (Vlocale_coding_system), + &coding); + coding.mode |= (CODING_MODE_SAFE_ENCODING | CODING_MODE_LAST_BLOCK); + coding.common_flags &= ~CODING_ANNOTATION_MASK; + + coding.dst_bytes = SCHARS (str) * 2; + coding.destination = (unsigned char *) xmalloc (coding.dst_bytes + 1); + encode_coding_object (&coding, str, 0, 0, SCHARS (str), SBYTES (str), Qnil); + coding.destination[coding.produced] = '\0'; + len = coding.produced; + Fgoto_char (point); + + hIMC = (ImmGetContextProc) (hwnd); + if (!hIMC) + { + xfree (coding.destination); + return FALSE; + } + strcpy ((LPSTR) reconv + sizeof (RECONVERTSTRING), coding.destination); + xfree (coding.destination); +#endif + reconv->dwStrLen = len; + reconv->dwStrOffset = sizeof (RECONVERTSTRING); + reconv->dwCompStrLen = len; + reconv->dwCompStrOffset = 0; + + /* Reconverted area is all of selected strings. */ + reconv->dwTargetStrLen = len; + reconv->dwTargetStrOffset = 0; + +#if 0 + /* Automatically adjust RECONVERTSTRING if not selected. */ + if (NILP (current_buffer->mark_active)) + (ImmSetCompositionStringProc) (hIMC, + SCS_QUERYRECONVERTSTRING, + (LPCVOID) reconv, + reconv->dwSize, + NULL, 0 ); +#endif + if ((ImmSetCompositionStringProc) (hIMC, + SCS_SETRECONVERTSTRING, + (LPCVOID) reconv, + reconv->dwSize, + NULL, 0)) + { + /* Delete the selected area. */ + del_range (start, end); + /* Set the position of candidate list dialog. */ + w32_set_ime_conv_window (f); + result = TRUE; + } + else + result = FALSE; + + (ImmReleaseContextProc) (hwnd, hIMC); + return result; +} +#endif /* RECONVERSION */ + +void +w32_ime_control_init (void) +{ + HMODULE hImm32; + HMODULE hUser32; + + hImm32 = GetModuleHandle ("IMM32.DLL"); + if (!hImm32) + hImm32 = LoadLibrary ("IMM32.DLL"); + + fIME = FALSE; + Vime_control = Qnil; + IME_event_off_count = 0; + + if (hImm32) + { + ImmGetOpenStatusProc = + (IMMGETOPENSTATUSPROC) + GetProcAddress (hImm32, + "ImmGetOpenStatus"); + ImmSetOpenStatusProc = + (IMMSETOPENSTATUSPROC) + GetProcAddress (hImm32, + "ImmSetOpenStatus"); + ImmGetDefaultIMEWndProc = + (IMMGETDEFAULTIMEWNDPROC) + GetProcAddress (hImm32, + "ImmGetDefaultIMEWnd"); + ImmGetContextProc = + (IMMGETCONTEXTPROC) + GetProcAddress (hImm32, + "ImmGetContext"); + ImmGetConversionStatusProc = + (IMMGETCONVERSIONSTATUSPROC) + GetProcAddress (hImm32, + "ImmGetConversionStatus"); + ImmSetConversionStatusProc = + (IMMSETCONVERSIONSTATUSPROC) + GetProcAddress (hImm32, + "ImmSetConversionStatus"); + ImmNotifyIMEProc = + (IMMNOTIFYIMEPROC) + GetProcAddress (hImm32, + "ImmNotifyIME"); + ImmReleaseContextProc = + (IMMRELEASECONTEXTPROC) + GetProcAddress (hImm32, + "ImmReleaseContext"); + ImmCreateContextProc = + (IMMCREATECONTEXTPROC) + GetProcAddress (hImm32, + "ImmCreateContext"); + ImmDestroyContextProc = + (IMMDESTROYCONTEXTPROC) + GetProcAddress (hImm32, + "ImmDestroyContext"); + ImmAssociateContextProc = + (IMMASSOCIATECONTEXTPROC) + GetProcAddress (hImm32, + "ImmAssociateContext"); + ImmGetHotKeyProc = + (IMMGETHOTKEYPROC) + GetProcAddress (hImm32, + "ImmGetHotKey"); +#ifdef _UNICODE + ImmGetCompositionStringProc = + (IMMGETCOMPOSITIONSTRINGPROC) + GetProcAddress (hImm32, "ImmGetCompositionStringW"); + ImmSetCompositionStringProc = + (IMMSETCOMPOSITIONSTRINGPROC) + GetProcAddress (hImm32, "ImmSetCompositionStringW"); + ImmSetCompositionFontProc = + (IMMSETCOMPOSITIONFONTPROC) + GetProcAddress (hImm32, "ImmSetCompositionFontW"); + ImmGetConversionListProc = + (IMMGETCONVERSIONLISTPROC) + GetProcAddress (hImm32, + "ImmGetConversionListW"); + ImmConfigureIMEProc = + (IMMCONFIGUREIMEPROC) + GetProcAddress (hImm32, + "ImmConfigureIMEW"); + ImmGetCandidateListProc = + (IMMGETCANDIDATELISTPROC) + GetProcAddress (hImm32, + "ImmGetCandidateListW"); + ImmGetCandidateListCountProc = + (IMMGETCANDIDATELISTCOUNTPROC) + GetProcAddress (hImm32, + "ImmGetCandidateListCountW"); +#else + ImmGetCompositionStringProc = + (IMMGETCOMPOSITIONSTRINGPROC) + GetProcAddress (hImm32, "ImmGetCompositionStringA"); + ImmSetCompositionStringProc = + (IMMSETCOMPOSITIONSTRINGPROC) + GetProcAddress (hImm32, "ImmSetCompositionStringA"); + ImmSetCompositionFontProc = + (IMMSETCOMPOSITIONFONTPROC) + GetProcAddress (hImm32, "ImmSetCompositionFontA"); + ImmGetConversionListProc = + (IMMGETCONVERSIONLISTPROC) + GetProcAddress (hImm32, + "ImmGetConversionListA"); + ImmConfigureIMEProc = + (IMMCONFIGUREIMEPROC) + GetProcAddress (hImm32, + "ImmConfigureIMEA"); + ImmGetCandidateListProc = + (IMMGETCANDIDATELISTPROC) + GetProcAddress (hImm32, + "ImmGetCandidateListA"); + ImmGetCandidateListCountProc = + (IMMGETCANDIDATELISTCOUNTPROC) + GetProcAddress (hImm32, + "ImmGetCandidateListCountA"); +#endif + + if (ImmGetOpenStatusProc && + ImmSetOpenStatusProc && + ImmGetDefaultIMEWndProc && + ImmGetCompositionStringProc && + ImmSetCompositionStringProc && + ImmSetCompositionFontProc && + ImmGetContextProc && + ImmGetConversionStatusProc && + ImmSetConversionStatusProc && + ImmGetConversionListProc && + ImmConfigureIMEProc && + ImmNotifyIMEProc && + ImmReleaseContextProc && + ImmCreateContextProc && + ImmDestroyContextProc && + ImmAssociateContextProc && + ImmGetCandidateListProc && + ImmGetCandidateListCountProc && + ImmGetHotKeyProc) + { + fIME = TRUE; + Vime_control = Qt; + } + } +} + +#ifdef HAVE_NTGUI +static void +w32_set_ime_font (hwnd, psetlf) + HWND hwnd; + LPLOGFONT psetlf; +{ + HIMC himc; + if (fIME && psetlf && !NILP (Vime_control)) + { + himc = (ImmGetContextProc) (hwnd); + if (!himc) + return; + (ImmSetCompositionFontProc) (himc, psetlf); + (ImmReleaseContextProc) (hwnd, himc); + } +} +#endif /* HAVE_NTGUI */ + +/* From here, communication programs to make IME a conversion machine. */ +static HIMC +immcontext (context) + Lisp_Object context; +{ + if (NUMBERP (context)) + return agent[XFASTINT (context)].himc; + else + return ((((unsigned long) XCAR (context)) << 16) | + (((unsigned long) XCDR (context)) & 0xffff)); +} + +static LRESULT CALLBACK +conversion_agent_wndproc (HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) +/* HWND hwnd; + UINT message; + WPARAM wparam; + LPARAM lparam; */ +{ + HIMC himc, holdimc; + + switch (message) + { + case WM_CREATE: + himc = (ImmCreateContextProc) (); + holdimc = (ImmAssociateContextProc) (hwnd, himc); + SetWindowLong (hwnd, 0, himc); + SetWindowLong (hwnd, 4, holdimc); + break; + + case WM_DESTROY: + holdimc = GetWindowLong (hwnd, 4); + himc = (ImmAssociateContextProc) (hwnd, holdimc); + (ImmDestroyContextProc) (himc); + break; + + case WM_MULE_IMM_SET_STATUS: + w32_set_ime_status (hwnd, (int) wparam); + break; + + case WM_MULE_IMM_GET_STATUS: + return w32_get_ime_status (hwnd); + + case WM_MULE_IMM_SET_MODE: + return w32_set_ime_mode (hwnd, (int) wparam, (int) lparam); + + case WM_MULE_IMM_GET_COMPOSITION_STRING: + return w32_get_ime_composition_string (hwnd); + + default: + return DefWindowProc (hwnd, message, wparam, lparam); + } + return 0; +} + +static int +initialize_conversion_agent () +{ + int i; + WNDCLASS wc; + + for (i = 0;i < MAX_CONVAGENT;i++) + { + agent[i].hwnd = 0; + agent[i].himc = 0; + } + + wc.style = 0; + wc.lpfnWndProc = conversion_agent_wndproc; + wc.cbClsExtra = 0; + wc.cbWndExtra = sizeof(long) * 2; + wc.hInstance = hinst; + wc.hIcon = NULL; + wc.hCursor = NULL; + wc.hbrBackground = NULL; + wc.lpszMenuName = NULL; + wc.lpszClassName = CONVAGENT_CLASS; + + if (!RegisterClass (&wc)) + return 0; + + return 1; +} + + +/* + Emacs Lisp function entries +*/ + +DEFUN ("ime-force-on", Fime_force_on, Sime_force_on, 0, 1, 0, + doc: /* Force status of IME open. */) + (eventp) + Lisp_Object eventp; +{ + if (fIME && !NILP (Vime_control)) + { + HIMC himc; + HWND hwnd; + + if (!NILP (Fime_get_mode ())) + return Qnil; +#ifdef HAVE_NTGUI + if (NILP (eventp)) + IME_event_off_count++; + hwnd = FRAME_W32_WINDOW (SELECTED_FRAME ()); +#else + hwnd = hwndConsole; +#endif + SendMessage (hwnd, WM_MULE_IMM_SET_STATUS, 1, 0); + } + return Qnil; +} + +DEFUN ("ime-force-off", Fime_force_off, Sime_force_off, 0, 1, 0, + doc: /* Force status of IME close. */) + (eventp) + Lisp_Object eventp; +{ + if (fIME && !NILP (Vime_control)) + { + HIMC himc; + HWND hwnd; + + if (NILP (Fime_get_mode ())) + return Qnil; +#ifdef HAVE_NTGUI + if (NILP (eventp)) + IME_event_off_count++; + hwnd = FRAME_W32_WINDOW (SELECTED_FRAME ()); +#else + hwnd = hwndConsole; +#endif + SendMessage (hwnd, WM_MULE_IMM_SET_STATUS, 0, 0); + } + return Qnil; +} + +DEFUN ("ime-get-mode", Fime_get_mode, Sime_get_mode, 0, 0, "", + doc: /* Get IME status. +t means status of IME is open. nil means it is close. */) + () +{ + if (fIME && !NILP (Vime_control)) + { + HWND hwnd; + int result; + +#ifdef HAVE_NTGUI + hwnd = FRAME_W32_WINDOW (SELECTED_FRAME ()); +#else + hwnd = hwndConsole; +#endif + result = SendMessage (hwnd, WM_MULE_IMM_GET_STATUS, 0, 0); + + return result ? Qt : Qnil; + } + else + return Qnil; +} + +DEFUN ("w32-set-ime-mode", + Fw32_set_ime_mode, + Sw32_set_ime_mode, 1, 2, 0, + doc: /* Set IME mode to MODE. If FRAME is omitted, the selected frame is used. */) + (mode, frame) + Lisp_Object mode, frame; +{ + FRAME_PTR f; + + if (NILP (frame)) + { + f = SELECTED_FRAME (); + } + else + { + CHECK_FRAME (frame); + f = XFRAME (frame); + } + if (fIME && !NILP (Vime_control)) + { + HWND hwnd; + int ret; + int newmode, mask; + + newmode = 0; + mask = 0; + + hwnd = FRAME_W32_WINDOW (f); + + if (EQ (mode, intern ("katakana"))) + { + newmode |= IME_CMODE_KATAKANA; + mask |= IME_CMODE_KATAKANA; + } + else if (EQ (mode, intern ("hiragana"))) + { + newmode &= ~IME_CMODE_KATAKANA; + mask |= IME_CMODE_KATAKANA; + } + else if (EQ (mode, intern ("kanji"))) + { + newmode |= IME_CMODE_HANJACONVERT; + mask |= IME_CMODE_HANJACONVERT; + } + else if (EQ (mode, intern ("nokanji"))) + { + newmode &= ~IME_CMODE_HANJACONVERT; + mask |= IME_CMODE_HANJACONVERT; + } + else if (EQ (mode, intern ("code"))) + { + newmode |= IME_CMODE_CHARCODE; + mask |= IME_CMODE_CHARCODE; + } + else if (EQ (mode, intern ("nocode"))) + { + newmode &= ~IME_CMODE_CHARCODE; + mask |= IME_CMODE_CHARCODE; + } + else if (EQ (mode, intern ("noconvert"))) + { + newmode |= IME_CMODE_NOCONVERSION; + mask |= IME_CMODE_NOCONVERSION; + } + else if (EQ (mode, intern ("convert"))) + { + newmode &= ~IME_CMODE_NOCONVERSION; + mask |= IME_CMODE_NOCONVERSION; + } + else + error ("unknown mode!!"); + + ret = SendMessage (hwnd, WM_MULE_IMM_SET_MODE, + (WPARAM) newmode, (LPARAM) mask); + + if (!ret) + return Qnil; + + return Qt; + } + return Qnil; +} + +DEFUN ("w32-ime-register-word-dialog", + Fw32_ime_register_word_dialog, + Sw32_ime_register_word_dialog, 2, 2, 0, + doc: /* Open IME regist word dialog. */) + (reading, word) + Lisp_Object reading, word; +{ + HKL hkl; + int reading_len, word_len; + REGISTERWORD regword; + Lisp_Object encoded_reading, encoded_word; + + CHECK_STRING (reading); + CHECK_STRING (word); + + if (fIME && !NILP (Vime_control) && ImmConfigureIMEProc) + { + hkl = GetKeyboardLayout (0); + encoded_reading = Fencode_coding_string (reading, + Vlocale_coding_system, + Qnil); + reading_len = SBYTES (encoded_reading); + regword.lpReading = SDATA (encoded_reading); + + encoded_word = Fencode_coding_string (word, + Vlocale_coding_system, + Qnil); + word_len = SBYTES (encoded_word); + regword.lpWord = SDATA (encoded_word); + (ImmConfigureIMEProc) (hkl, FRAME_W32_WINDOW (SELECTED_FRAME ()), + IME_CONFIG_REGISTERWORD, ®word); + } + return Qnil; +} + +void +x_set_ime_font (f, arg, oldval) + struct frame *f; + Lisp_Object arg, oldval; +{ + LOGFONT lf; + + CHECK_STRING (arg); + + if (!x_to_w32_font (SDATA (arg), &lf)) + error ("Font `%s' is not defined", SDATA (arg)); + SendMessage (FRAME_W32_WINDOW(f), + WM_MULE_IMM_SET_COMPOSITION_FONT, + (WPARAM) f, (LPARAM) &lf); +} + +void +w32_get_ime_logfont (hwnd) + HWND hwnd; +{ + struct face *face, *dflt_face; + struct frame *f; + struct window *w; + struct w32_display_info *dpyinfo = &one_w32_display_info; + LOGFONT dflt_lf, lf; + Lisp_Object ime_font; + char *font_string; + int pos, pos_byte, c, face_id, dummy; + + f = x_window_to_frame (dpyinfo, hwnd); + + if (PT <= BEGV || PT > ZV) + { + ime_font = Fframe_parameter (Qnil, Qime_font); + if (!NILP (ime_font)) + font_string = SDATA (ime_font); + else + { + dflt_face = FACE_FROM_ID (f, DEFAULT_FACE_ID); + font_string = dflt_face->font_name; + } + } + else + { + pos = PT - 1; + /* This code is from Finternal_char_font(). */ + pos_byte = CHAR_TO_BYTE (pos); + c = FETCH_CHAR (pos_byte); + w = XWINDOW (FRAME_ROOT_WINDOW (f)); + + face_id = face_at_buffer_position (w, pos, -1, -1, &dummy, pos + 100, 0); + face = FACE_FROM_ID (f, face_id); + + face_id = FACE_FOR_CHAR (f, FACE_FROM_ID (f, face_id), c); + face = FACE_FROM_ID (f, face_id); + font_string = face->font_name; + } + + x_to_w32_font (font_string, &f->output_data.w32->ime_logfont); + + if (!(f->output_data.w32->ime_logfont.lfCharSet == SHIFTJIS_CHARSET + || f->output_data.w32->ime_logfont.lfCharSet == HANGEUL_CHARSET + || f->output_data.w32->ime_logfont.lfCharSet == CHINESEBIG5_CHARSET + || f->output_data.w32->ime_logfont.lfCharSet == GB2312_CHARSET)) + { + ime_font = Fframe_parameter (Qnil, Qime_font); + + if (!NILP (ime_font)) + { + int len; + + font_string = SDATA (ime_font); + x_to_w32_font (font_string, &dflt_lf); + + f->output_data.w32->ime_logfont.lfCharSet = dflt_lf.lfCharSet; + len = strlen (dflt_lf.lfFaceName); + strncpy (f->output_data.w32->ime_logfont.lfFaceName, dflt_lf.lfFaceName, LF_FACESIZE); + f->output_data.w32->ime_logfont.lfFaceName[len] = '\0'; + } + } + + /* Calculate the width automatically, otherwise it is too wide. */ + f->output_data.w32->ime_logfont.lfWidth = 0; +} +#endif /* USE_W32_IME */ + + +/*********************************************************************** w32 specialized functions ***********************************************************************/ @@ -8609,6 +9648,9 @@ x_set_cursor_color, x_set_cursor_type, x_set_font, +#ifdef USE_W32_IME + x_set_ime_font, +#endif x_set_foreground_color, x_set_icon_name, x_set_icon_type, @@ -8648,6 +9690,10 @@ staticpro (&Qsuppress_icon); Qundefined_color = intern ("undefined-color"); staticpro (&Qundefined_color); +#ifdef USE_V32_IME + Qime_font = intern ("ime-font"); + staticpro (&Qime_font); +#endif Qcancel_timer = intern ("cancel-timer"); staticpro (&Qcancel_timer); @@ -8957,6 +10003,11 @@ versions of Windows) characters. */); Vw32_charset_info_alist = Qnil; +#ifdef USE_W32_IME + DEFVAR_LISP ("ime-control", &Vime_control, "IME control flag"); + Vime_control = Qnil; +#endif + staticpro (&Qw32_charset_ansi); Qw32_charset_ansi = intern ("w32-charset-ansi"); staticpro (&Qw32_charset_symbol); @@ -9061,6 +10112,13 @@ defsubr (&Sw32_toggle_lock_key); defsubr (&Sw32_window_exists_p); defsubr (&Sw32_find_bdf_fonts); +#ifdef USE_W32_IME + defsubr (&Sw32_set_ime_mode); + defsubr (&Sw32_ime_register_word_dialog); + defsubr (&Sime_force_on); + defsubr (&Sime_force_off); + defsubr (&Sime_get_mode); +#endif defsubr (&Sfile_system_info); defsubr (&Sdefault_printer_name); @@ -9133,14 +10191,18 @@ { int button; button = MessageBox (NULL, - "A fatal error has occurred!\n\n" - "Would you like to attach a debugger?\n\n" - "Select YES to debug, NO to abort Emacs" #if __GNUC__ - "\n\n(type \"gdb -p <emacs-PID>\" and\n" - "\"continue\" inside GDB before clicking YES.)" + TEXT ("A fatal error has occurred!\n\n" + "Would you like to attach a debugger?\n\n" + "Select YES to debug, NO to abort Emacs" + "\n\n(type \"gdb -p <emacs-PID>\" and\n" + "\"continue\" inside GDB before clicking YES.)") +#else + TEXT ("A fatal error has occurred!\n\n" + "Would you like to attach a debugger?\n\n" + "Select YES to debug, NO to abort Emacs") #endif - , "Emacs Abort Dialog", + , TEXT ("Emacs Abort Dialog"), MB_ICONEXCLAMATION | MB_TASKMODAL | MB_SETFOREGROUND | MB_YESNO); switch (button) diff -urN /home/katufj/cvsroot/emacs/src/w32term.c ./emacs/src/w32term.c --- /home/katufj/cvsroot/emacs/src/w32term.c 2007-11-10 14:37:18.513559700 +0900 +++ ./emacs/src/w32term.c 2007-11-11 16:13:59.517959500 +0900 @@ -31,6 +31,7 @@ #include "w32heap.h" #include "w32term.h" #include "w32bdf.h" + #include <shellapi.h> #include "systty.h" @@ -4816,6 +4817,80 @@ check_visibility = 1; break; +#ifdef USE_W32_IME + case WM_MULE_IME_STATUS: + f = x_window_to_frame (dpyinfo, msg.msg.hwnd); + + if (f && !f->iconified && f->visible) + { + inev.kind = NON_ASCII_KEYSTROKE_EVENT; + inev.code = VK_KANJI; + inev.modifiers = 0; + XSETFRAME (inev.frame_or_window, f); + inev.timestamp = msg.msg.time; + } + break; + + case WM_MULE_IME_REPORT: + { +#ifdef _UNICODE + LPWSTR lpStr; +#else + LPSTR lpStr; +#endif + struct input_event buf; + HANDLE hw32_ime_string = (HANDLE) msg.msg.wParam; + + f = (struct frame *) msg.msg.lParam; + if (f && !f->iconified && f->visible) + { +#ifdef _UNICODE + lpStr = (LPWSTR) hw32_ime_string; +#else + lpStr = (LPSTR) hw32_ime_string; +#endif + while(lpStr) + { + EVENT_INIT (buf); + XSETFRAME (buf.frame_or_window, f); + buf.timestamp = msg.msg.time; + buf.modifiers = 0; + if (*lpStr) + { + if (*lpStr < 0x80) + buf.kind = ASCII_KEYSTROKE_EVENT; + else + buf.kind = MULTIBYTE_CHAR_KEYSTROKE_EVENT; + buf.code = *lpStr; + kbd_buffer_store_event (&buf); + lpStr++; + } + else + { + buf.kind = NON_ASCII_KEYSTROKE_EVENT; + buf.code = VK_COMPEND; + kbd_buffer_store_event (&buf); + break; + } + } + HeapFree (GetProcessHeap (), 0, (LPVOID) hw32_ime_string); + } + } + break; + + case WM_MULE_IMM_SET_COMPOSITION_FONT: + { + extern w32_get_ime_logfont (HWND); + f = x_window_to_frame (dpyinfo, msg.msg.hwnd); + w32_get_ime_logfont (msg.msg.hwnd); + + PostMessage (msg.msg.hwnd, WM_MULE_IMM_SET_COMPOSITION_FONT_REPLY, + (LPARAM) f, + (WPARAM) &f->output_data.w32->ime_logfont); + break; + } +#endif /* USE_W32_IME */ + default: /* Check for messages registered at runtime. */ if (msg.msg.message == msh_mousewheel) @@ -5166,6 +5241,11 @@ struct frame *f = XFRAME (WINDOW_FRAME (w)); HWND hwnd = FRAME_W32_WINDOW (f); +#ifdef USE_W32_IME + if (f == FRAME_W32_DISPLAY_INFO (f)->x_highlight_frame) + PostMessage (hwnd, + WM_MULE_IMM_SET_CONVERSION_WINDOW, (WPARAM) f, 0); +#endif w32_system_caret_x = WINDOW_TEXT_TO_FRAME_PIXEL_X (w, w->phys_cursor.x); w32_system_caret_y @@ -5398,21 +5478,6 @@ } -/*********************************************************************** - TODO: W32 Input Methods - ***********************************************************************/ -/* Listing missing functions from xterm.c helps diff stay in step. - -xim_destroy_callback (xim, client_data, call_data) -xim_open_dpy (dpyinfo, resource_name) -struct xim_inst_t -xim_instantiate_callback (display, client_data, call_data) -xim_initialize (dpyinfo, resource_name) -xim_close_dpy (dpyinfo) - - */ - - /* Calculate the absolute position in frame F from its current recorded position values and gravity. */ @@ -6623,6 +6688,9 @@ && SystemParametersInfo (SPI_GETFONTSMOOTHINGTYPE, 0, &smoothing_type, 0) && smoothing_type == FE_FONTSMOOTHINGCLEARTYPE; } +#ifdef USE_W32_IME + w32_ime_control_init(); +#endif } void diff -urN /home/katufj/cvsroot/emacs/src/w32term.h ./emacs/src/w32term.h --- /home/katufj/cvsroot/emacs/src/w32term.h 2007-11-10 14:37:18.607159700 +0900 +++ ./emacs/src/w32term.h 2007-11-11 15:41:00.829559500 +0900 @@ -399,6 +399,11 @@ /* The background for which the above relief GCs were set up. They are changed only when a different background is involved. */ unsigned long relief_background; + +#ifdef USE_W32_IME + /* logfont for IME */ + LOGFONT ime_logfont; +#endif }; extern struct w32_output w32term_display; @@ -617,6 +622,8 @@ #endif /* WM_MOUSEHWHEEL */ #ifndef WM_APPCOMMAND #define WM_APPCOMMAND 0x319 +#endif +#ifndef GET_APPCOMMAND_LPARAM #define GET_APPCOMMAND_LPARAM(lParam) (HIWORD(lParam) & 0x7fff) #endif @@ -643,6 +650,102 @@ #define WM_EMACS_SETCURSOR (WM_EMACS_START + 19) #define WM_EMACS_END (WM_EMACS_START + 20) +#ifdef USE_W32_IME +#ifndef VK_KANJI +#define VK_KANJI 0x19 +#endif +#ifndef VK_KANA +#define VK_KANA 0x15 +#endif +#define VK_COMPEND 0x1A + +#ifdef RECONVERSION +#ifndef WM_IME_REQUEST +#define WM_IME_REQUEST 0x288 +#endif +#ifndef IMR_COMPOSITIONWINDOW +#define IMR_COMPOSITIONWINDOW 0x0001 +#endif +#ifndef IMR_CANDIDATEWINDOW +#define IMR_CANDIDATEWINDOW 0x0002 +#endif +#ifdef IMR_COMPOSITIONFONT +#define IMR_COMPOSITIONFONT 0x0003 +#endif +#ifndef IMR_RECONVERTSTRING +#define IMR_RECONVERTSTRING 0x0004 +#endif +#ifndef IMR_CONFIRMRECONVERTSTRING +#define IMR_CONFIRMRECONVERTSTRING 0x0005 +#endif +#endif + +/* For internal communications + from window procedure to event loop. */ +#define WM_MULE_IME_REPORT (WM_USER+2200) +#define WM_MULE_IME_STATUS (WM_USER+2201) + +/* For internal communications + from main thread to window procedure. */ +#define WM_MULE_IMM_MESSAGE_START (WM_USER+2300) +#define WM_MULE_IMM_SET_STATUS (WM_USER+2300) +#define WM_MULE_IMM_GET_STATUS (WM_USER+2301) +#if 0 +#define WM_MULE_IMM_DEAL_WITH_CONTEXT (WM_USER+2302) +#define WM_MULE_IMM_SET_COMPOSITION_STRING (WM_USER+2303) +#endif +#define WM_MULE_IMM_GET_COMPOSITION_STRING (WM_USER+2304) +#define WM_MULE_IMM_SET_MODE (WM_USER+2305) +#if 0 +#define WM_MULE_IMM_NOTIFY (WM_USER+2310) +#define WM_MULE_IMM_GET_UNDETERMINED_STRING_LENGTH (WM_USER+2320) +#endif +#define WM_MULE_IMM_MESSAGE_END (WM_USER+2399) +#define MESSAGE_IMM_COM_P(message) \ + (((message) >= WM_MULE_IMM_MESSAGE_START) && \ + ((message) <= WM_MULE_IMM_MESSAGE_END)) + +#if 0 +/* For synchronization + to create conversion agent + between main thread and event loop. */ +#define WM_MULE_IME_CREATE_AGENT (WM_USER+2400) +#define WM_MULE_IME_CREATE_AGENT_REPLY (WM_USER+2401) +#define WM_MULE_IME_DESTROY_AGENT (WM_USER+2402) +#define WM_MULE_IME_DESTROY_AGENT_REPLY (WM_USER+2403) +#endif +#define CONVAGENT_CLASS "ConvAgent" + +#define WM_MULE_IMM_SET_COMPOSITION_FONT (WM_USER+2404) +#define WM_MULE_IMM_SET_COMPOSITION_FONT_REPLY (WM_USER+2405) + +#define WM_MULE_IMM_SET_CONVERSION_WINDOW (WM_USER+2406) +#if 0 +#define WM_MULE_IMM_SET_CONVERSION_WINDOW_REPLY (WM_USER+2407) +#endif + +#ifdef RECONVERSION +#ifndef HAVE_RECONVERTSTRING +typedef struct tagRECONVERTSTRING { + DWORD dwSize; + DWORD dwVersion; + DWORD dwStrLen; + DWORD dwStrOffset; + DWORD dwCompStrLen; + DWORD dwCompStrOffset; + DWORD dwTargetStrLen; + DWORD dwTargetStrOffset; +} RECONVERTSTRING, *PRECONVERTSTRING; +#endif +#ifndef SCS_SETRECONVERTSTRING +#define SCS_SETRECONVERTSTRING 0x00010000 +#endif +#ifndef SCS_QUERYRECONVERTSTRING +#define SCS_QUERYRECONVERTSTRING 0x00020000 +#endif +#endif /* RECONVERSION */ +#endif /* USE_W32_IME */ + #define WND_FONTWIDTH_INDEX (0) #define WND_LINEHEIGHT_INDEX (4) #define WND_BORDER_INDEX (8) @@ -757,6 +860,32 @@ EXFUN (Fx_display_color_p, 1); EXFUN (Fx_display_grayscale_p, 1); +#ifdef USE_W32_IME +/* + You should avoid using this method to send message to the + message thread if possible. Although this method guarantee + message reachablity even when message thread has no window, + you must deal with any messages sent by this method + both in the thread message loop(W32read_socket) and + in the window procedure(normally w32_WndProc). +*/ +#define SEND_MSGTHREAD_INFORM_MESSAGE(message, wparam, lparam) \ + do { \ + if (FRAME_W32_WINDOW(SELECTED_FRAME()) != NULL) \ + SendMessage(FRAME_W32_WINDOW(SELECTED_FRAME()), (message), \ + (wparam), (lparam)); \ + else \ + while (!PostThreadMessage (dwWindowsThreadId, (message), \ + (wparam), (lparam))) \ + sleep(1); \ + }while(0) + +#define WAIT_REPLY_MESSAGE(ret, msgno) \ + do { \ + GetMessage ((ret), NULL, 0, 0); \ + } while((ret)->message != (msgno)) +#endif /* USE_W32_IME */ + #define FONT_TYPE_FOR_UNIBYTE(font, ch) \ ((font)->bdf ? BDF_1D_FONT : ANSI_FONT) diff -urN /home/katufj/cvsroot/emacs/src/window.c ./emacs/src/window.c --- /home/katufj/cvsroot/emacs/src/window.c 2007-10-27 17:39:55.826153800 +0900 +++ ./emacs/src/window.c 2007-11-10 10:08:43.415959700 +0900 @@ -232,6 +232,13 @@ static int inhibit_frame_unsplittable; #endif /* 0 */ +#ifdef USE_W32_IME +Lisp_Object Vset_selected_window_buffer_functions; +Lisp_Object Qset_selected_window_buffer_functions; +Lisp_Object Vselect_window_functions; +Lisp_Object Qselect_window_functions; +#endif + extern EMACS_INT scroll_margin; extern Lisp_Object Qwindow_scroll_functions, Vwindow_scroll_functions; @@ -3440,6 +3447,19 @@ } set_window_buffer (window, buffer, 1, !NILP (keep_margins)); + +#ifdef USE_W32_IME + if (! NILP (Vset_selected_window_buffer_functions)) + { + Lisp_Object temp[4]; + temp[0] = Qset_selected_window_buffer_functions; + temp[1] = tem; + temp[2] = window; + temp[3] = buffer; + Frun_hook_with_args (4, temp); + } +#endif + return Qnil; } @@ -3461,6 +3481,9 @@ register struct window *w; register struct window *ow; struct frame *sf; +#ifdef USE_W32_IME + Lisp_Object oldwin = selected_window; +#endif CHECK_LIVE_WINDOW (window); @@ -3524,6 +3547,12 @@ } windows_or_buffers_changed++; + +#ifdef USE_W32_IME + if (!NILP (Vselect_window_functions)) + run_hook_with_args_2 (Qselect_window_functions, oldwin, window); +#endif + return window; } @@ -7338,6 +7367,16 @@ Qwindow_configuration_change_hook = intern ("window-configuration-change-hook"); +#ifdef USE_W32_IME + staticpro (&Qset_selected_window_buffer_functions); + Qset_selected_window_buffer_functions + = intern ("set-selected-window-buffer-functions"); + + staticpro (&Qselect_window_functions); + Qselect_window_functions + = intern ("select-window-functions"); +#endif + Qwindowp = intern ("windowp"); staticpro (&Qwindowp); @@ -7559,6 +7598,21 @@ The selected frame is the one whose configuration has changed. */); Vwindow_configuration_change_hook = Qnil; +#ifdef USE_W32_IME + DEFVAR_LISP ("select-window-functions", &Vselect_window_functions, + doc: /* "This is a hook when select-window is called. +The hook is called with two arguments OLD-WINDOW and NEW-WINDOW. */); + Vselect_window_functions = Qnil; + + DEFVAR_LISP ("set-selected-window-buffer-functions", + &Vset_selected_window_buffer_functions, + doc: /* "This is a hook when set-selected-window-buffer is called. +This is called with three arguments +OLD-BUFFER, NEW-WINDOW and NEW-BUFFER. +If NEW-WINDOW is first being set up, OLD-BUFFER is t. */); + Vset_selected_window_buffer_functions = Qnil; +#endif + defsubr (&Sselected_window); defsubr (&Sminibuffer_window); defsubr (&Swindow_minibuffer_p); -------------- next part -------------- HTMLの添付ファイルを保管しました... Télécharger