view src/syswindows.h @ 5353:38e24b8be4ea

Improve the lexical scoping in #'block, #'return-from. lisp/ChangeLog addition: 2011-02-07 Aidan Kehoe <kehoea@parhasard.net> * bytecomp.el: * bytecomp.el (byte-compile-initial-macro-environment): Shadow `block', `return-from' here, we implement them differently when byte-compiling. * bytecomp.el (byte-compile-active-blocks): New. * bytecomp.el (byte-compile-block-1): New. * bytecomp.el (byte-compile-return-from-1): New. * bytecomp.el (return-from-1): New. * bytecomp.el (block-1): New. These are two aliases that exist to have their own associated byte-compile functions, which functions implement `block' and `return-from'. * cl-extra.el (cl-macroexpand-all): Fix a bug here when macros in the environment have been compiled. * cl-macs.el (block): * cl-macs.el (return): * cl-macs.el (return-from): Be more careful about lexical scope in these macros. * cl.el: * cl.el ('cl-block-wrapper): Removed. * cl.el ('cl-block-throw): Removed. These aren't needed in code generated by this XEmacs. They shouldn't be needed in code generated by XEmacs 21.4, but if it turns out the packages do need them, we can put them back. 2011-01-30 Mike Sperber <mike@xemacs.org> * font-lock.el (font-lock-fontify-pending-extents): Don't fail if `font-lock-mode' is unset, which can happen in the middle of `revert-buffer'. 2011-01-23 Aidan Kehoe <kehoea@parhasard.net> * cl-macs.el (delete): * cl-macs.el (delq): * cl-macs.el (remove): * cl-macs.el (remq): Don't use the compiler macro if these functions were given the wrong number of arguments, as happens in lisp-tests.el. * cl-seq.el (remove, remq): Removed. I added these to subr.el, and forgot to remove them from here. 2011-01-22 Aidan Kehoe <kehoea@parhasard.net> * bytecomp.el (byte-compile-setq, byte-compile-set): Remove kludge allowing keywords' values to be set, all the code that does that is gone. * cl-compat.el (elt-satisfies-test-p): * faces.el (set-face-parent): * faces.el (face-doc-string): * gtk-font-menu.el: * gtk-font-menu.el (gtk-reset-device-font-menus): * msw-font-menu.el: * msw-font-menu.el (mswindows-reset-device-font-menus): * package-get.el (package-get-installedp): * select.el (select-convert-from-image-data): * sound.el: * sound.el (load-sound-file): * x-font-menu.el (x-reset-device-font-menus-core): Don't quote keywords, they're self-quoting, and the win from backward-compatibility is sufficiently small now that the style problem overrides it. 2011-01-22 Aidan Kehoe <kehoea@parhasard.net> * cl-macs.el (block, return-from): Require that NAME be a symbol in these macros, as always documented in the #'block docstring and as required by Common Lisp. * descr-text.el (unidata-initialize-unihan-database): Correct the use of non-symbols in #'block and #'return-from in this function. 2011-01-15 Aidan Kehoe <kehoea@parhasard.net> * cl-extra.el (concatenate): Accept more complicated TYPEs in this function, handing the sequences over to #'coerce if we don't understand them here. * cl-macs.el (inline): Don't proclaim #'concatenate as inline, its compiler macro is more useful than doing that. 2011-01-11 Aidan Kehoe <kehoea@parhasard.net> * subr.el (delete, delq, remove, remq): Move #'remove, #'remq here, they don't belong in cl-seq.el; move #'delete, #'delq here from fns.c, implement them in terms of #'delete*, allowing support for sequences generally. * update-elc.el (do-autoload-commands): Use #'delete*, not #'delq here, now the latter's no longer dumped. * cl-macs.el (delete, delq): Add compiler macros transforming #'delete and #'delq to #'delete* calls. 2011-01-10 Aidan Kehoe <kehoea@parhasard.net> * dialog.el (make-dialog-box): Correct a misplaced parenthesis here, thank you Mats Lidell in 87zkr9gqrh.fsf@mail.contactor.se ! 2011-01-02 Aidan Kehoe <kehoea@parhasard.net> * dialog.el (make-dialog-box): * list-mode.el (display-completion-list): These functions used to use cl-parsing-keywords; change them to use defun* instead, fixing the build. (Not sure what led to me not including this change in d1b17a33450b!) 2011-01-02 Aidan Kehoe <kehoea@parhasard.net> * cl-macs.el (define-star-compiler-macros): Make sure the form has ITEM and LIST specified before attempting to change to calls with explicit tests; necessary for some tests in lisp-tests.el to compile correctly. (stable-union, stable-intersection): Add compiler macros for these functions, in the same way we do for most of the other functions in cl-seq.el. 2011-01-01 Aidan Kehoe <kehoea@parhasard.net> * cl-macs.el (dolist, dotimes, do-symbols, macrolet) (symbol-macrolet): Define these macros with defmacro* instead of parsing the argument list by hand, for the sake of style and readability; use backquote where appropriate, instead of calling #'list and and friends, for the same reason. 2010-12-30 Aidan Kehoe <kehoea@parhasard.net> * x-misc.el (device-x-display): Provide this function, documented in the Lispref for years, but not existing previously. Thank you Julian Bradfield, thank you Jeff Mincy. 2010-12-30 Aidan Kehoe <kehoea@parhasard.net> * cl-seq.el: Move the heavy lifting from this file to C. Dump the cl-parsing-keywords macro, but don't use defun* for the functions we define that do take keywords, dynamic scope lossage makes that not practical. * subr.el (sort, fillarray): Move these aliases here. (map-plist): #'nsublis is now built-in, but at this point #'eql isn't necessarily available as a test; use #'eq. * obsolete.el (cl-delete-duplicates): Make this available for old compiler macros and old code. (memql): Document that this is equivalent to #'member*, and worse. * cl.el (adjoin, subst): Removed. These are in C. 2010-12-30 Aidan Kehoe <kehoea@parhasard.net> * simple.el (assoc-ignore-case): Remove a duplicate definition of this function (it's already in subr.el). * iso8859-1.el (char-width): On non-Mule, make this function equivalent to that produced by (constantly 1), but preserve its docstring. * subr.el (subst-char-in-string): Define this in terms of #'substitute, #'nsubstitute. (string-width): Define this using #'reduce and #'char-width. (char-width): Give this a simpler definition, it makes far more sense to check for mule at load time and redefine, as we do in iso8859-1.el. (store-substring): Implement this in terms of #'replace, now #'replace is cheap. 2010-12-30 Aidan Kehoe <kehoea@parhasard.net> * update-elc.el (lisp-files-needed-for-byte-compilation) (lisp-files-needing-early-byte-compilation): cl-macs belongs in the former, not the latter, it is as fundamental as bytecomp.el. 2010-12-30 Aidan Kehoe <kehoea@parhasard.net> * cl.el: Provde the Common Lisp program-error, type-error as error symbols. This doesn't nearly go far enough for anyone using the Common Lisp errors. 2010-12-29 Aidan Kehoe <kehoea@parhasard.net> * cl-macs.el (delete-duplicates): If the form has an incorrect number of arguments, don't attempt a compiler macroexpansion. 2010-12-29 Aidan Kehoe <kehoea@parhasard.net> * cl-macs.el (cl-safe-expr-p): Forms that start with the symbol lambda are also safe. 2010-12-29 Aidan Kehoe <kehoea@parhasard.net> * cl-macs.el (= < > <= >=): For these functions' compiler macros, the optimisation is safe even if the first and the last arguments have side effects, since they're only used the once. 2010-12-29 Aidan Kehoe <kehoea@parhasard.net> * cl-macs.el (inline-side-effect-free-compiler-macros): Unroll a loop here at macro-expansion time, so these compiler macros are compiled. Use #'eql instead of #'eq in a couple of places for better style. 2010-12-29 Aidan Kehoe <kehoea@parhasard.net> * cl-extra.el (notany, notevery): Avoid some dynamic scope stupidity with local variable names in these functions, when they weren't prefixed with cl-; go into some more detail in the doc strings. 2010-12-29 Aidan Kehoe <kehoea@parhasard.net> * byte-optimize.el (side-effect-free-fns): #'remove, #'remq are free of side-effects. (side-effect-and-error-free-fns): Drop dot, dot-marker from the list. 2010-11-17 Aidan Kehoe <kehoea@parhasard.net> * cl-extra.el (coerce): In the argument list, name the first argument OBJECT, not X; the former name was always used in the doc string and is clearer. Handle vector type specifications which include the length of the target sequence, error if there's a mismatch. * cl-macs.el (cl-make-type-test): Handle type specifications starting with the symbol 'eql. 2010-11-14 Aidan Kehoe <kehoea@parhasard.net> * cl-macs.el (eql): Don't remove the byte-compile property of this symbol. That was necessary to override a bug in bytecomp.el where #'eql was confused with #'eq, which bug we no longer have. If neither expression is constant, don't attempt to handle the expression in this compiler macro, leave it to byte-compile-eql, which produces better code anyway. * bytecomp.el (eq): #'eql is not the function associated with the byte-eq byte code. (byte-compile-eql): Add an explicit compile method for this function, for cases where the cl-macs compiler macro hasn't reduced it to #'eq or #'equal. 2010-10-25 Aidan Kehoe <kehoea@parhasard.net> Add compiler macros and compilation sanity-checking for various functions that take keywords. * byte-optimize.el (side-effect-free-fns): #'symbol-value is side-effect free and not error free. * bytecomp.el (byte-compile-normal-call): Check keyword argument lists for sanity; store information about the positions where keyword arguments start using the new byte-compile-keyword-start property. * cl-macs.el (cl-const-expr-val): Take a new optional argument, cl-not-constant, defaulting to nil, in this function; return it if the expression is not constant. (cl-non-fixnum-number-p): Make this into a separate function, we want to pass it to #'every. (eql): Use it. (define-star-compiler-macros): Use the same code to generate the member*, assoc* and rassoc* compiler macros; special-case some code in #'add-to-list in subr.el. (remove, remq): Add compiler macros for these two functions, in preparation for #'remove being in C. (define-foo-if-compiler-macros): Transform (remove-if-not ...) calls to (remove ... :if-not) at compile time, which will be a real win once the latter is in C. (define-substitute-if-compiler-macros) (define-subst-if-compiler-macros): Similarly for these functions. (delete-duplicates): Change this compiler macro to use #'plists-equal; if we don't have information about the type of SEQUENCE at compile time, don't bother attempting to inline the call, the function will be in C soon enough. (equalp): Remove an old commented-out compiler macro for this, if we want to see it it's in version control. (subst-char-in-string): Transform this to a call to nsubstitute or nsubstitute, if that is appropriate. * cl.el (ldiff): Don't call setf here, this makes for a load-time dependency problem in cl-macs.el 2010-06-14 Stephen J. Turnbull <stephen@xemacs.org> * term/vt100.el: Refer to XEmacs, not GNU Emacs, in permissions. * term/bg-mouse.el: * term/sup-mouse.el: Put copyright notice in canonical "Copyright DATE AUTHOR" form. Refer to XEmacs, not GNU Emacs, in permissions. * site-load.el: Add permission boilerplate. * mule/canna-leim.el: * alist.el: Refer to XEmacs, not APEL/this program, in permissions. * mule/canna-leim.el: Remove my copyright, I've assigned it to the FSF. 2010-06-14 Stephen J. Turnbull <stephen@xemacs.org> * gtk.el: * gtk-widget-accessors.el: * gtk-package.el: * gtk-marshal.el: * gtk-compose.el: * gnome.el: Add copyright notice based on internal evidence. 2010-06-14 Stephen J. Turnbull <stephen@xemacs.org> * easymenu.el: Add reference to COPYING to permission notice. * gutter.el: * gutter-items.el: * menubar-items.el: Fix typo "Xmacs" in permissions notice. 2010-06-14 Stephen J. Turnbull <stephen@xemacs.org> * auto-save.el: * font.el: * fontconfig.el: * mule/kinsoku.el: Add "part of XEmacs" text to permission notice. 2010-10-14 Aidan Kehoe <kehoea@parhasard.net> * byte-optimize.el (side-effect-free-fns): * cl-macs.el (remf, getf): * cl-extra.el (tailp, cl-set-getf, cl-do-remf): * cl.el (ldiff, endp): Tighten up Common Lisp compatibility for #'ldiff, #'endp, #'tailp; add circularity checking for the first two. #'cl-set-getf and #'cl-do-remf were Lisp implementations of #'plist-put and #'plist-remprop; change the names to aliases, changes the macros that use them to using #'plist-put and #'plist-remprop directly. 2010-10-12 Aidan Kehoe <kehoea@parhasard.net> * abbrev.el (fundamental-mode-abbrev-table, global-abbrev-table): Create both these abbrev tables using the usual #'define-abbrev-table calls, rather than attempting to special-case them. * cl-extra.el: Force cl-macs to be loaded here, if cl-extra.el is being loaded interpreted. Previously other, later files would redundantly call (load "cl-macs") when interpreted, it's more reasonable to do it here, once. * cmdloop.el (read-quoted-char-radix): Use defcustom here, we don't have any dump-order dependencies that would prevent that. * custom.el (eval-when-compile): Don't load cl-macs when interpreted or when byte-compiling, rely on cl-extra.el in the former case and the appropriate entry in bytecomp-load-hook in the latter. Get rid of custom-declare-variable-list, we have no dump-time dependencies that would require it. * faces.el (eval-when-compile): Don't load cl-macs when interpreted or when byte-compiling. * packages.el: Remove some inaccurate comments. * post-gc.el (cleanup-simple-finalizers): Use #'delete-if-not here, now the order of preloaded-file-list has been changed to make it available. * subr.el (custom-declare-variable-list): Remove. No need for it. Also remove a stub define-abbrev-table from this file, given the current order of preloaded-file-list there's no need for it. 2010-10-10 Aidan Kehoe <kehoea@parhasard.net> * bytecomp.el (byte-compile-constp) Forms quoted with FUNCTION are also constant. (byte-compile-initial-macro-environment): In #'the, if FORM is constant and does not match TYPE, warn at byte-compile time. 2010-10-10 Aidan Kehoe <kehoea@parhasard.net> * backquote.el (bq-vector-contents, bq-list*): Remove; the former is equivalent to (append VECTOR nil), the latter to (list* ...). (bq-process-2): Use (append VECTOR nil) instead of using #'bq-vector-contents to convert to a list. (bq-process-1): Now we use list* instead of bq-list * subr.el (list*): Moved from cl.el, since it is now required to be available the first time a backquoted form is encountered. * cl.el (list*): Move to subr.el. 2010-09-16 Aidan Kehoe <kehoea@parhasard.net> * test-harness.el (Check-Message): Add an omitted comma here, thank you the buildbot. 2010-09-16 Aidan Kehoe <kehoea@parhasard.net> * hash-table.el (hash-table-key-list, hash-table-value-list) (hash-table-key-value-alist, hash-table-key-value-plist): Remove some useless #'nreverse calls in these files; our hash tables have no order, it's not helpful to pretend they do. * behavior.el (read-behavior): Do the same in this file, in some code evidently copied from hash-table.el. 2010-09-16 Aidan Kehoe <kehoea@parhasard.net> * info.el (Info-insert-dir): * format.el (format-deannotate-region): * files.el (cd, save-buffers-kill-emacs): Use #'some, #'every and related functions for applying boolean operations to lists, instead of rolling our own ones that cons and don't short-circuit. 2010-09-16 Aidan Kehoe <kehoea@parhasard.net> * bytecomp.el (byte-compile-initial-macro-environment): * cl-macs.el (the): Rephrase the docstring, make its implementation when compiling files a little nicer. 2010-09-16 Aidan Kehoe <kehoea@parhasard.net> * descr-text.el (unidata-initialize-unicodedata-database) (unidata-initialize-unihan-database, describe-char-unicode-data) (describe-char-unicode-data): Wrap calls to the database functions with (with-fboundp ...), avoiding byte compile warnings on builds without support for the database functions. (describe-char): (reduce #'max ...), not (apply #'max ...), no need to cons needlessly. (describe-char): Remove a redundant lambda wrapping #'extent-properties. (describe-char-unicode-data): Call #'nsubst when replacing "" with nil in the result of #'split-string, instead of consing inside mapcar. 2010-09-16 Aidan Kehoe <kehoea@parhasard.net> * x-faces.el (x-available-font-sizes): * specifier.el (let-specifier): * package-ui.el (pui-add-required-packages): * msw-faces.el (mswindows-available-font-sizes): * modeline.el (modeline-minor-mode-menu): * minibuf.el (minibuf-directory-files): Replace the O2N (delq nil (mapcar (lambda (W) (and X Y)) Z)) with the ON (mapcan (lambda (W) (and X (list Y))) Z) in these files. 2010-09-16 Aidan Kehoe <kehoea@parhasard.net> * cl-macs.el (= < > <= >=): When these functions are handed more than two arguments, and those arguments have no side effects, transform to a series of two argument calls, avoiding funcall in the byte-compiled code. * mule/mule-cmds.el (finish-set-language-environment): Take advantage of this change in a function called 256 times at startup. 2010-09-16 Aidan Kehoe <kehoea@parhasard.net> * bytecomp.el (byte-compile-function-form, byte-compile-quote) (byte-compile-quote-form): Warn at compile time, and error at runtime, if a (quote ...) or a (function ...) form attempts to quote more than one object. 2010-09-16 Aidan Kehoe <kehoea@parhasard.net> * byte-optimize.el (byte-optimize-apply): Transform (apply 'nconc (mapcar ...)) to (mapcan ...); warn about use of the first idiom. * update-elc.el (do-autoload-commands): * packages.el (packages-find-package-library-path): * frame.el (frame-list): * extents.el (extent-descendants): * etags.el (buffer-tag-table-files): * dumped-lisp.el (preloaded-file-list): * device.el (device-list): * bytecomp-runtime.el (proclaim-inline, proclaim-notinline) Use #'mapcan, not (apply #'nconc (mapcar ...) in all these files. * bytecomp-runtime.el (eval-when-compile, eval-and-compile): In passing, mention that these macros also evaluate the body when interpreted. tests/ChangeLog addition: 2011-02-07 Aidan Kehoe <kehoea@parhasard.net> * automated/lisp-tests.el: Test lexical scope for `block', `return-from'; add a Known-Bug-Expect-Failure for a contorted example that fails when byte-compiled.
author Aidan Kehoe <kehoea@parhasard.net>
date Mon, 07 Feb 2011 12:01:24 +0000
parents 32e1ae4c1e3a
children 3889ef128488 308d34e9f07d
line wrap: on
line source

/* Copyright (C) 2000 Free Software Foundation, Inc.
   Copyright (C) 2000, 2001, 2002, 2004, 2010 Ben Wing.

This file is part of XEmacs.

XEmacs is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.

XEmacs is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with XEmacs; see the file COPYING.  If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.  */

/* Synched up with: Not in FSF. */

#ifndef INCLUDED_syswindows_h_
#define INCLUDED_syswindows_h_

/* Authorship:

   Current primary author: Ben Wing <ben@xemacs.org>
   
   Created May 2000 by Andy Piper.
   Windows-Mule stuff added by Ben Wing, 2000-2001.
   September 2001 Ben Wing reorganized and included nt.h and ntheap.h into
   this file; comments in those files say:
      * Adapted for XEmacs by David Hobley <david@spook-le0.cia.com.au>
      * Sync'ed with Emacs 19.34.6 by Marc Paquette <marcpa@cam.org>
        (Note: Sync messages from Marc Paquette may indicate
        incomplete synching, so beware.)
      (in ntheap.h only) Geoff Voelker (voelker@cs.washington.edu) 7-29-94

*/

/* See win32.c for info about the different Windows files in XEmacs. */

/* 
   A capsule introduction to Windows-related build flags:

   See also: (Info-goto-node "(internals)Windows Build Flags")

   1. Operating-system level:
   --------------------------

   `CYGWIN'	Compiled for Cygwin.  Cygwin provides a full Unix-like
		environment under Windows.  Applications compiled for Cygwin
		are linked with CYGWIN1.DLL, which provides the POSIX
		emulation.

		Corresponding s/ file: s/cygwin32.h

   `MINGW'	Compiled for MinGW.  MinGW is a Unix-like environment under
		Windows that allows for the use of `gcc' to create fully
		native Windows applications that link with the normal
		Microsoft C-runtime library (e.g. MSVCRT.DLL), and don't
		require a special POSIX-emulation DLL (e.g. CYGWIN1.DLL).
		Conversely, the only POSIX-like services available are
		those in MSVCRT.DLL, which isn't much.  Essentially, coding
		for MinGW is identical to coding for native Windows using
		Visual C++ or the like, whereas coding for Cygwin is like
		coding for Linux, but with the additional possibility of
		making Win32-API calls.  Additional confusion comes from
		the fact that you can use the Cygwin environment and
		compilers to build a MINGW application (e.g. by passing the
		`-mno-cygwin' command-line argument to `gcc').

		Corresponding s/ file: s/mingw32.h

   (none)	There's no flag to indicate that you are specifically
		targetting native Windows and not doing this with MINGW.
		Presumably this means you're using Visual C++.

		Corresponding s/ file: s/windowsnt.h

   `WIN32_ANY'	Any of the above three environments.

		Corresponding s/ file: s/win32-common.h

   `WIN32_NATIVE'
		Native Windows target, either MinGW or Visual C++.
                That is, not Cygwin.

		Corresponding s/ file: s/win32-native.h


   2. Compiler level:
   ------------------

   `__GNUC__'	Defined whenever compiling with gcc (Cygwin or MinGW).

   `_MSC_VER'	Defined whenever compiling with Visual C++.

   `CYGWIN_HEADERS'
		Defined whenever using Cygwin-style header files rather
		than Visual C++ headers.  Currently this means the same
		as "Cygwin or MinGW" and the same as "compiling with gcc".
		This applies especially to the header files in
		/usr/include/w32api, which is a free replacement for the
		standard Visual C++ headers for the Win32 API.


   3. Window-system level:
   -----------------------

   `HAVE_MS_WINDOWS'
		MS Windows native windowing system (anything related to the
		appearance of the graphical screen).  May or may not apply
		to any of VC++, MinGW, or Cygwin.  For example, it's
		definitely possible to compile XEmacs under Cygwin with
		support for X-Windows frames and TTY frames, but no
		native MS Windows frames.  It may also be possible to do that
		under MinGW or (less likely, but feasible) Visual C++.
   
   `HAVE_X_WINDOWS'
		Support for X-Windows frames, regardless of whether under
		MS Windows.  You can certainly compile XEmacs with support
		for X-Windows frames when running on MS Windows, using Cygwin.

   `HAVE_GTK', `HAVE_TTY'
		Likewise.  All are available on MS Windows with Cygwin.

    Note further that more than one of these can be defined at the same time.
    In fact, in general, it's possible to compile with support for all of
    these at the same time.



   Here is a table mapping from GNU Emacs constants to XEmacs constants for
   use in porting code.
 

   Old Constant       New Constant
   ---------------------------------------------------------------
   `WINDOWSNT'        `WIN32_NATIVE'
   `WIN32'            `WIN32_NATIVE'
   `_WIN32'           `WIN32_NATIVE'
   `HAVE_WIN32'       `WIN32_NATIVE'
   `DOS_NT'           `WIN32_NATIVE'
   `HAVE_NTGUI'       `WIN32_NATIVE', unless it ends up already bracketed
                      by this
   `HAVE_FACES'       always true
   `MSDOS'            determine whether this code is really specific to
                      MS-DOS (and not Windows - e.g. DJGPP code); if so,
                      delete the code; otherwise, convert to `WIN32_NATIVE'
                      (we do not support MS-DOS w/DOS Extender under XEmacs)
   `__CYGWIN__'       `CYGWIN'
   `__CYGWIN32__'     `CYGWIN'
   `__MINGW32__'      `MINGW'

*/

/* ------------------------- Basic includes ------------------------- */

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif

#ifdef CYGWIN_HEADERS
# ifndef _WIN32_IE
#  define _WIN32_IE 0x0400
# endif

BEGIN_C_DECLS

#if 0 /* breaks the build, as of GCC 3.4.4 or earlier, since the prototype
         is now declared static */
/* Fucking GCC complains about "no previous prototype" for inline
   functions.  DUH!  See DECLARE_INLINE_HEADER. */
extern __inline void *GetCurrentFiber (void);
extern __inline void *GetFiberData (void);
#endif

END_C_DECLS

#endif

/* Defines for COM so it's usable in both C and C++.  XECOMCALLn() calls a
   method with the specified number of parameters.  XECOMID() surrounds a
   class or interface name when passed to CoCreateInstance, a
   QueryInterface method, or the like. */
#ifdef __cplusplus
#define XECOMCALL0(cl, meth) ((cl)->meth ())
#define XECOMCALL1(cl, meth, a1) ((cl)->meth (a1))
#define XECOMCALL2(cl, meth, a1, a2) ((cl)->meth (a1, a2))
#define XECOMCALL3(cl, meth, a1, a2, a3) ((cl)->meth (a1, a2, a3))
#define XECOMCALL4(cl, meth, a1, a2, a3, a4) ((cl)->meth (a1, a2, a3, a4))
#define XECOMID(id) (id)
#else
#define XECOMCALL0(cl, meth) ((cl)->lpVtbl->meth (cl))
#define XECOMCALL1(cl, meth, a1) ((cl)->lpVtbl->meth (cl, a1))
#define XECOMCALL2(cl, meth, a1, a2) ((cl)->lpVtbl->meth (cl, a1, a2))
#define XECOMCALL3(cl, meth, a1, a2, a3) ((cl)->lpVtbl->meth (cl, a1, a2, a3))
#define XECOMCALL4(cl, meth, a1, a2, a3, a4) \
		((cl)->lpVtbl->meth (cl, a1, a2, a3, a4))
#define XECOMID(id) (&(id))
#endif		

#define OEMRESOURCE /* Define OCR_ and friend constants */
#include <windows.h>

#include <aclapi.h>

#if defined (WIN32_LEAN_AND_MEAN)
# ifdef HAVE_X_WINDOWS
/* Christ almighty.  The problems you get when combining two large code bases,
   neither with any respect for namespace purity. */
#  undef Status
# endif
# include <winspool.h>
# ifdef HAVE_X_WINDOWS
#  define Status int
# endif
# include <mmsystem.h>
# include <shlobj.h>
# include <shellapi.h>
# include <ddeml.h>
#endif

#include <lmaccess.h> /* next three for NetUserEnum and friends */
#include <lmapibuf.h>
#include <lmerr.h>
#include <lmcons.h> /* for UNLEN and possibly other constants */

#include <cderr.h>
#include <commdlg.h>

#ifdef NEED_MSWINDOWS_COMMCTRL
#include <commctrl.h>
#endif
#ifdef NEED_MSWINDOWS_OBJBASE
#include <objbase.h>
#endif
#ifdef NEED_MSWINDOWS_SHLOBJ
#include <shlobj.h>
#endif

#include <zmouse.h> /* WHEEL_PAGESCROLL under Cygwin */

#include <wchar.h>

/* ------------------------- Cygwin header brokenness ---------------------- */

#ifdef CYGWIN_HEADERS

#include <cygwin/stat.h> /* for struct stat */
#include <w32api.h> /* for version info */
#include <sys/cygwin.h> /* path conversion functions */

/* Test for a specific version of w32api */
#define W32API_VER(major,minor) (((major) << 16) + (minor))
#define W32API_INSTALLED_VER \
  W32API_VER (__W32API_MAJOR_VERSION, __W32API_MINOR_VERSION)

/* Various brokennesses in various versions of Cygwin */

/* windows.h defines. */
#ifndef SPI_GETWHEELSCROLLLINES
#define SPI_GETWHEELSCROLLLINES 104
#endif

/* commctrl.h defines. */
#ifndef TB_SETIMAGELIST
#define TB_SETIMAGELIST (WM_USER + 48)
#endif
#ifndef TB_GETIMAGELIST
#define TB_GETIMAGELIST (WM_USER + 49)
#endif
#ifndef TB_SETDISABLEDIMAGELIST
#define TB_SETDISABLEDIMAGELIST (WM_USER + 54)
#endif
#ifndef TB_GETDISABLEDIMAGELIST
#define TB_GETDISABLEDIMAGELIST (WM_USER + 55)
#endif
#ifndef TB_SETPADDING
#define TB_SETPADDING   (WM_USER + 87)
#endif
#ifndef TB_GETBUTTONINFOA
#define TB_GETBUTTONINFOA  (WM_USER + 65)
#endif
#ifndef TB_GETBUTTONINFOW
#define TB_GETBUTTONINFOW  (WM_USER + 63)
#endif
#ifndef TB_SETBUTTONINFOA
#define TB_SETBUTTONINFOA  (WM_USER + 66)
#endif
#ifndef TB_SETBUTTONINFOW
#define TB_SETBUTTONINFOW  (WM_USER + 64)
#endif
#ifndef TB_INSERTBUTTONA
#define TB_INSERTBUTTONA  (WM_USER + 21)
#endif
#ifndef TB_INSERTBUTTONW
#define TB_INSERTBUTTONW  (WM_USER + 67)
#endif
#ifndef TB_ADDBUTTONSA
#define TB_ADDBUTTONSA  (WM_USER + 20)
#endif
#ifndef TB_ADDBUTTONSW
#define TB_ADDBUTTONSW  (WM_USER + 68)
#endif
#ifndef LVM_SETBKIMAGEA
#define LVM_SETBKIMAGEA  (LVM_FIRST + 68)
#endif
#ifndef LVM_SETBKIMAGEW
#define LVM_SETBKIMAGEW  (LVM_FIRST + 138)
#endif
#ifndef LVM_GETBKIMAGEA
#define LVM_GETBKIMAGEA  (LVM_FIRST + 69)
#endif
#ifndef LVM_GETBKIMAGEW
#define LVM_GETBKIMAGEW  (LVM_FIRST + 139)
#endif
#ifndef WC_COMBOBOXEXW
#define WC_COMBOBOXEXW L"ComboBoxEx32"
#endif
#ifndef CBEM_INSERTITEMA
#define CBEM_INSERTITEMA  (WM_USER + 1)
#endif
#ifndef CBEM_INSERTITEMW
#define CBEM_INSERTITEMW  (WM_USER + 11)
#endif
#ifndef CBEM_SETITEMA
#define CBEM_SETITEMA  (WM_USER + 5)
#endif
#ifndef CBEM_SETITEMW
#define CBEM_SETITEMW  (WM_USER + 12)
#endif
#ifndef CBEM_GETITEMA
#define CBEM_GETITEMA  (WM_USER + 4)
#endif
#ifndef CBEM_GETITEMW
#define CBEM_GETITEMW  (WM_USER + 13)
#endif
#ifndef HDN_GETDISPINFOA
#define HDN_GETDISPINFOA        (HDN_FIRST - 9)
#endif
#ifndef HDN_GETDISPINFOW
#define HDN_GETDISPINFOW        (HDN_FIRST - 29)
#endif
#ifndef TBN_GETDISPINFOA
#define TBN_GETDISPINFOA        (TBN_FIRST - 16)
#endif
#ifndef TBN_GETDISPINFOW
#define TBN_GETDISPINFOW        (TBN_FIRST - 17)
#endif
#ifndef TBN_GETINFOTIPA
#define TBN_GETINFOTIPA         (TBN_FIRST - 18)
#endif
#ifndef TBN_GETINFOTIPW
#define TBN_GETINFOTIPW         (TBN_FIRST - 19)
#endif
#ifndef TTN_GETDISPINFOA
#define TTN_GETDISPINFOA        (TTN_FIRST - 0)
#endif
#ifndef TTN_GETDISPINFOW
#define TTN_GETDISPINFOW        (TTN_FIRST - 10)
#endif

#if (_WIN32_IE >= 0x0400)

#ifndef LVN_GETINFOTIPA
#define LVN_GETINFOTIPA         (LVN_FIRST - 57)
#endif
#ifndef LVN_GETINFOTIPW
#define LVN_GETINFOTIPW         (LVN_FIRST - 58)
#endif
#ifndef TVN_GETINFOTIPA
#define TVN_GETINFOTIPA         (TVN_FIRST - 13)
#endif
#ifndef TVN_GETINFOTIPW
#define TVN_GETINFOTIPW         (TVN_FIRST - 14)
#endif
#ifndef CBEN_GETDISPINFOA
#define CBEN_GETDISPINFOA       (CBEN_FIRST - 0)
#endif
#ifndef CBEN_GETDISPINFOW
#define CBEN_GETDISPINFOW       (CBEN_FIRST - 7)
#endif
#ifndef CBEN_DRAGBEGINA
#define CBEN_DRAGBEGINA			 (CBEN_FIRST - 8)
#endif
#ifndef CBEN_DRAGBEGINW
#define CBEN_DRAGBEGINW			 (CBEN_FIRST - 9)
#endif

#endif /* (_WIN32_IE >= 0x0400) */

#ifndef CBEN_ENDEDITA
#define CBEN_ENDEDITA            (CBEN_FIRST - 5)
#endif
#ifndef CBEN_ENDEDITW
#define CBEN_ENDEDITW            (CBEN_FIRST - 6)
#endif

#ifndef CBEMAXSTRLEN
#define CBEMAXSTRLEN 260
#endif

#ifndef NMCBEENDEDIT

typedef struct
{
  NMHDR hdr;
  BOOL fChanged;
  int iNewSelection;
  WCHAR szText[CBEMAXSTRLEN];
  int iWhy;
} NMCBEENDEDITW, *LPNMCBEENDEDITW, *PNMCBEENDEDITW;

typedef struct
{
  NMHDR hdr;
  BOOL fChanged;
  int iNewSelection;
  char szText[CBEMAXSTRLEN];
  int iWhy;
} NMCBEENDEDITA, *LPNMCBEENDEDITA,*PNMCBEENDEDITA;

#endif /* not NMCBEENDEDIT */

#if (_WIN32_IE >= 0x0400)

#ifndef NMCBEDRAGBEGIN

typedef struct
{
  NMHDR hdr;
  int   iItemid;
  WCHAR szText[CBEMAXSTRLEN];
} NMCBEDRAGBEGINW, *LPNMCBEDRAGBEGINW, *PNMCBEDRAGBEGINW;

typedef struct
{
  NMHDR hdr;
  int   iItemid;
  char szText[CBEMAXSTRLEN];
} NMCBEDRAGBEGINA, *LPNMCBEDRAGBEGINA, *PNMCBEDRAGBEGINA;

#endif /* not NMCBEDRAGBEGIN */

typedef struct tagNMDATETIMEFORMATA
{
  NMHDR nmhdr;
  LPCSTR  pszFormat;
  SYSTEMTIME st;
  LPCSTR pszDisplay;
  CHAR szDisplay[64];
} NMDATETIMEFORMATA, FAR * LPNMDATETIMEFORMATA;

typedef struct tagNMDATETIMEFORMATW
{
  NMHDR nmhdr;
  LPCWSTR pszFormat;
  SYSTEMTIME st;
  LPCWSTR pszDisplay;
  WCHAR szDisplay[64];
} NMDATETIMEFORMATW, FAR * LPNMDATETIMEFORMATW;

#if W32API_INSTALLED_VER < W32API_VER(2,2)

typedef struct tagNMTTDISPIFNOA
{
  NMHDR hdr;
  LPSTR lpszText;
  char szText[80];
  HINSTANCE hinst;
  UINT uFlags;
#if (_WIN32_IE >= 0x0300)
  LPARAM lParam;
#endif
} NMTTDISPINFOA, FAR *LPNMTTDISPINFOA;

typedef struct tagNMTTDISPINFOW
{
  NMHDR hdr;
  LPWSTR lpszText;
  WCHAR szText[80];
  HINSTANCE hinst;
  UINT uFlags;
#if (_WIN32_IE >= 0x0300)
  LPARAM lParam;
#endif
} NMTTDISPINFOW, FAR *LPNMTTDISPINFOW;

#endif /* W32API_INSTALLED_VER < W32API_VER(2,2) */

#endif /* (_WIN32_IE >= 0x0400) */

/* shlobj.h defines */
#ifndef BFFM_VALIDATEFAILEDA
#define BFFM_VALIDATEFAILEDA    3
#endif
#ifndef BFFM_VALIDATEFAILEDW
#define BFFM_VALIDATEFAILEDW    4
#endif
#ifndef BFFM_SETSELECTIONA
#define BFFM_SETSELECTIONA      (WM_USER + 102)
#endif
#ifndef BFFM_SETSELECTIONW
#define BFFM_SETSELECTIONW      (WM_USER + 103)
#endif
#ifndef BFFM_SETSTATUSTEXTA
#define BFFM_SETSTATUSTEXTA     (WM_USER + 100)
#endif
#ifndef BFFM_SETSTATUSTEXTW
#define BFFM_SETSTATUSTEXTW     (WM_USER + 104)
#endif
#ifndef SHARD_PATHA
#define SHARD_PATHA     2
#endif
#ifndef SHARD_PATHW
#define SHARD_PATHW     3
#endif
#ifndef SHCNF_PATHA
#define SHCNF_PATHA     1
#endif
#ifndef SHCNF_PATHW
#define SHCNF_PATHW     5
#endif
#ifndef SHCNF_PRINTERA
#define SHCNF_PRINTERA     2
#endif
#ifndef SHCNF_PRINTERW
#define SHCNF_PRINTERW     6
#endif
#ifndef BFFM_VALIDATEFAILED
#ifdef UNICODE
#define BFFM_VALIDATEFAILED BFFM_VALIDATEFAILEDW
#else
#define BFFM_VALIDATEFAILED BFFM_VALIDATEFAILEDA
#endif
#endif

/* winnls.h defines */
#ifndef MAC_CHARSET
#define MAC_CHARSET 		77
#endif
#ifndef LOCALE_RETURN_NUMBER
#define LOCALE_RETURN_NUMBER	0x20000000
#endif

/* OEM resources */
#ifndef OCR_ICOCUR
#define OCR_ICOCUR          32647
#define OIC_SAMPLE          32512
#define OIC_HAND            32513
#define OIC_QUES            32514
#define OIC_BANG            32515
#define OIC_NOTE            32516
#define OIC_WINLOGO         32517
#endif

/* More Cygwin stupidity: Current w32api's winuser.h has IME message
   constants and they conflict with imm.h. (NOTE: Currently fixed, but
   I'm sure the problems were present post 1.0.) */
#undef WM_IME_STARTCOMPOSITION
#undef WM_IME_ENDCOMPOSITION
#undef WM_IME_COMPOSITION
#undef WM_IME_KEYLAST
#undef WM_IME_SETCONTEXT
#undef WM_IME_NOTIFY
#undef WM_IME_CONTROL
#undef WM_IME_COMPOSITIONFULL
#undef WM_IME_SELECT
#undef WM_IME_CHAR
#undef WM_IME_KEYDOWN
#undef WM_IME_KEYUP

#include <imm.h>

#if W32API_INSTALLED_VER < W32API_VER(2,4)
typedef struct _SHQUERYRBINFO
{
  DWORD cbSize;
  __int64 i64Size;
  __int64 i64NumItems;
} SHQUERYRBINFO, *LPSHQUERYRBINFO;
#endif

typedef LPCDLGTEMPLATE LPCDLGTEMPLATEW;
typedef LPCDLGTEMPLATE LPCDLGTEMPLATEA;

#else /* !CYGWIN_HEADERS */

#define W32API_VER(major,minor) 0
#define W32API_INSTALLED_VER 0

/* Some types that show up in Cygwin headers but not in Visual Studio headers,
   and cause problems if we used Cygwin headers to generate
   intl-auto-encap-win32.[ch]. */
typedef LPCVOID PCVOID;

#endif /* CYGWIN_HEADERS */

/* Not in VC 6 */
#ifndef BIF_NEWDIALOGSTYLE
#define BIF_NEWDIALOGSTYLE 64
#endif

#if defined (CYGWIN) && (CYGWIN_VERSION_DLL_COMBINED < 190)

/* All but wcscmp and wcslen left out of Cygwin headers -- but present
   in /usr/include/mingw/string.h! */
wchar_t* wcscat (wchar_t*, const wchar_t*);
wchar_t* wcschr (const wchar_t*, wchar_t);
int	wcscoll (const wchar_t*, const wchar_t*);
wchar_t* wcscpy (wchar_t*, const wchar_t*);
wchar_t* wcsdup (const wchar_t*);
size_t	wcscspn (const wchar_t*, const wchar_t*);
/* Note: No wcserror in CRTDLL. */
wchar_t* wcsncat (wchar_t*, const wchar_t*, size_t);
int	wcsncmp (const wchar_t*, const wchar_t*, size_t);
wchar_t* wcsncpy (wchar_t*, const wchar_t*, size_t);
wchar_t* wcspbrk (const wchar_t*, const wchar_t*);
wchar_t* wcsrchr (const wchar_t*, wchar_t);
size_t	wcsspn (const wchar_t*, const wchar_t*);
wchar_t* wcsstr (const wchar_t*, const wchar_t*);
wchar_t* wcstok (wchar_t*, const wchar_t*);
size_t	wcsxfrm (wchar_t*, const wchar_t*, size_t);

#endif /* CYGWIN */

/* ------------------------- Unicode encapsulation ------------------------- */

/* See intl-win32.c for more information about Unicode-encapsulation */

#define ERROR_WHEN_NONINTERCEPTED_FUNS_USED

#include "intl-auto-encap-win32.h"

/* would be encapsulatable but for parsing problems */

#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef DefWindowProc
#define DefWindowProc error use qxeDefWindowProc or DefWindowProcA/DefWindowProcW
#endif
LRESULT qxeDefWindowProc (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);

#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef CallWindowProc
#define CallWindowProc error use qxeCallWindowProc or CallWindowProcA/CallWindowProcW
#endif
LRESULT qxeCallWindowProc (WNDPROC lpPrevWndFunc, HWND hWnd, UINT Msg,
			   WPARAM wParam, LPARAM lParam);

#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef DefDlgProc
#define DefDlgProc error use qxeDefDlgProc or DefDlgProcA/DefDlgProcW
#endif
LRESULT qxeDefDlgProc (HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam);

#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef SetWindowsHook
#define SetWindowsHook error use qxeSetWindowsHook or SetWindowsHookA/SetWindowsHookW
#endif
HHOOK qxeSetWindowsHook (int nFilterType, HOOKPROC pfnFilterProc);

#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef DefMDIChildProc
#define DefMDIChildProc error use qxeDefMDIChildProc or DefMDIChildProcA/DefMDIChildProcW
#endif
LRESULT qxeDefMDIChildProc (HWND hWnd, UINT uMsg, WPARAM wParam,
			    LPARAM lParam);

#undef GetEnvironmentStrings
#undef GetEnvironmentStringsA
#define GetEnvironmentStringsA GetEnvironmentStrings
Extbyte * qxeGetEnvironmentStrings (void);

/* would be encapsulatable but for Cygwin problems */

#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef DdeCreateStringHandle
#define DdeCreateStringHandle error use qxeDdeCreateStringHandle or DdeCreateStringHandleA/DdeCreateStringHandleW
#endif
HSZ qxeDdeCreateStringHandle (DWORD idInst, const Extbyte * psz, int iCodePage);

#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef RegConnectRegistry
#define RegConnectRegistry error use qxeRegConnectRegistry or RegConnectRegistryA/RegConnectRegistryW
#endif
LONG qxeRegConnectRegistry (const Extbyte * lpMachineName, HKEY hKey, PHKEY phkResult);

#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef ExtractIconEx
#define ExtractIconEx error use qxeExtractIconEx or ExtractIconExA/ExtractIconExW
#endif
UINT qxeExtractIconEx (const Extbyte * lpszFile, int nIconIndex, HICON FAR * phiconLarge, HICON FAR * phiconSmall, UINT nIcons);

#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef GetICMProfile
#define GetICMProfile error use qxeGetICMProfile or GetICMProfileA/GetICMProfileW
#endif
BOOL qxeGetICMProfile (HDC arg1, LPDWORD arg2, Extbyte * arg3);

#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef UpdateICMRegKey
#define UpdateICMRegKey error use qxeUpdateICMRegKey or UpdateICMRegKeyA/UpdateICMRegKeyW
#endif
BOOL qxeUpdateICMRegKey (DWORD arg1, Extbyte * arg2, Extbyte * arg3, UINT arg4);

/* would be encapsulatable but for header changes in different versions of VC++ */

#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef EnumResourceTypes
#define EnumResourceTypes error_use_qxeEnumResourceTypes_or_EnumResourceTypesA_and_EnumResourceTypesW
#endif
#if MSC_VERSION >= 1300
BOOL qxeEnumResourceTypes (HMODULE hModule, ENUMRESTYPEPROCW lpEnumFunc, LONG lParam);
#else
BOOL qxeEnumResourceTypes (HMODULE hModule, ENUMRESTYPEPROC lpEnumFunc, LONG lParam);
#endif

#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef EnumResourceNames
#define EnumResourceNames error_use_qxeEnumResourceNames_or_EnumResourceNamesA_and_EnumResourceNamesW
#endif
#if MSC_VERSION >= 1300
BOOL qxeEnumResourceNames (HMODULE hModule, const Extbyte * lpType, ENUMRESNAMEPROCW lpEnumFunc, LONG lParam);
#else
BOOL qxeEnumResourceNames (HMODULE hModule, const Extbyte * lpType, ENUMRESNAMEPROC lpEnumFunc, LONG lParam);
#endif

#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef EnumResourceLanguages
#define EnumResourceLanguages error_use_qxeEnumResourceLanguages_or_EnumResourceLanguagesA_and_EnumResourceLanguagesW
#endif
#if MSC_VERSION >= 1300
BOOL qxeEnumResourceLanguages (HMODULE hModule, const Extbyte * lpType, const Extbyte * lpName, ENUMRESLANGPROCW lpEnumFunc, LONG lParam);
#else
BOOL qxeEnumResourceLanguages (HMODULE hModule, const Extbyte * lpType, const Extbyte * lpName, ENUMRESLANGPROC lpEnumFunc, LONG lParam);
#endif

/* files */
#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef FindFirstFile
#define FindFirstFile error use qxeFindFirstFile or FindFirstFileA/FindFirstFileW
#endif
HANDLE qxeFindFirstFile (const Extbyte *lpFileName,
			 WIN32_FIND_DATAW *lpFindFileData);

#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef FindNextFile
#define FindNextFile error use qxeFindNextFile or FindNextFileA/FindNextFileW
#endif
BOOL qxeFindNextFile (HANDLE hFindFile, WIN32_FIND_DATAW *lpFindFileData);

/* shell */
#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef SHGetFileInfo
#define SHGetFileInfo error use qxeSHGetFileInfo or SHGetFileInfoA/SHGetFileInfoW
#endif
DWORD qxeSHGetFileInfo (const Extbyte *pszPath, DWORD dwFileAttributes,
			SHFILEINFOW *psfi, UINT cbFileInfo, UINT uFlags);

#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef SHBrowseForFolder
#define SHBrowseForFolder error use qxeSHBrowseForFolder or SHBrowseForFolderA/SHBrowseForFolderW
#endif
LPITEMIDLIST qxeSHBrowseForFolder (LPBROWSEINFOW lpbi);

/* Not Unicode-split */
VOID qxeSHAddToRecentDocs (UINT uFlags, LPCVOID pv);

/* Not Unicode-split */
VOID qxeSHChangeNotify (LONG wEventId, UINT uFlags, LPCVOID dwItem1,
			LPCVOID dwItem2);

#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef SHGetDataFromIDList
#define SHGetDataFromIDList error use qxeSHGetDataFromIDList or SHGetDataFromIDListA/SHGetDataFromIDListW
#endif
HRESULT qxeSHGetDataFromIDList (IShellFolder *psf, LPCITEMIDLIST pidl,
				int nFormat, PVOID pv, int cb);

/* devmode */
#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef CreateDC
#define CreateDC error use qxeCreateDC or CreateDCA/CreateDCW
#endif
HDC qxeCreateDC (const Extbyte *lpszDriver, const Extbyte *lpszDevice,
		 const Extbyte *lpszOutput, CONST DEVMODEW *lpInitData);

#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef ResetDC
#define ResetDC error use qxeResetDC or ResetDCA/ResetDCW
#endif
HDC qxeResetDC (HDC hdc, CONST DEVMODEW *lpInitData);

#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef OpenPrinter
#define OpenPrinter error use qxeOpenPrinter or OpenPrinterA/OpenPrinterW
#endif
DWORD qxeOpenPrinter (Extbyte *pPrinterName, LPHANDLE phPrinter,
		      LPPRINTER_DEFAULTSW pDefaultconst);

#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef DocumentProperties
#define DocumentProperties error use qxeDocumentProperties or DocumentPropertiesA/DocumentPropertiesW
#endif
LONG qxeDocumentProperties (HWND hWnd, HANDLE hPrinter, Extbyte *pDeviceName,
			    DEVMODEW *pDevModeOutput, DEVMODEW *pDevModeInput,
			    DWORD fMode);

#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef PrintDlg
#define PrintDlg error use qxePrintDlg or PrintDlgA/PrintDlgW
#endif
BOOL qxePrintDlg (PRINTDLGW *lppd);

#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef PageSetupDlg
#define PageSetupDlg error use qxePageSetupDlg or PageSetupDlgA/PageSetupDlgW
#endif
BOOL qxePageSetupDlg (PAGESETUPDLGW *lppd);

/* fonts */

#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef EnumFontFamiliesEx
#define EnumFontFamiliesEx error use qxeEnumFontFamiliesEx or EnumFontFamiliesExA/EnumFontFamiliesExW
#endif
int qxeEnumFontFamiliesEx (HDC hdc, LOGFONTW *lpLogfont,
			   FONTENUMPROCW lpEnumFontFamProc, LPARAM lParam,
			   DWORD dwFlags);

#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef CreateFontIndirect
#define CreateFontIndirect error use qxeCreateFontIndirect or CreateFontIndirectA/CreateFontIndirectW
#endif
HFONT qxeCreateFontIndirect (CONST LOGFONTW *lplf);

#if defined (HAVE_MS_WINDOWS)
#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef ImmSetCompositionFont
#define ImmSetCompositionFont error use qxeImmSetCompositionFont or ImmSetCompositionFontA/ImmSetCompositionFontW
#endif
BOOL qxeImmSetCompositionFont (HIMC imc, LOGFONTW *lplf);
#endif /* defined (HAVE_MS_WINDOWS) */

#if defined (HAVE_MS_WINDOWS)
#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef ImmGetCompositionFont
#define ImmGetCompositionFont error use qxeImmGetCompositionFont or ImmGetCompositionFontA/ImmGetCompositionFontW
#endif
BOOL qxeImmGetCompositionFont (HIMC imc, LOGFONTW *lplf);
#endif /* defined (HAVE_MS_WINDOWS) */

#if defined (HAVE_MS_WINDOWS)
#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef ImmSetCompositionString
#define ImmSetCompositionString error_use_qxeImmSetCompositionString_or_ImmSetCompositionStringA_and_ImmSetCompositionStringW
#endif
#if MSC_VERSION >= 1300
BOOL qxeImmSetCompositionString (HIMC arg1, DWORD dwIndex, LPVOID lpComp, DWORD arg4, LPCVOID lpRead, DWORD arg6);
#else
BOOL qxeImmSetCompositionString (HIMC arg1, DWORD dwIndex, LPCVOID lpComp, DWORD arg4, LPCVOID lpRead, DWORD arg6);
#endif
#endif /* defined (HAVE_MS_WINDOWS) */

#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef GetObject
#define GetObject error use qxeGetObject or GetObjectA/GetObjectW
#endif
int qxeGetObject (HGDIOBJ hgdiobj, int cbBuffer, LPVOID lpvObject);

#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef GetTextMetrics
#define GetTextMetrics error use qxeGetTextMetrics or GetTextMetricsA/GetTextMetricsW
#endif
BOOL qxeGetTextMetrics (HDC hdc, LPTEXTMETRICW lptm);

/* COMMCTRL.H */

#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef SendMessage
#define SendMessage error use qxeSendMessage or SendMessageA/SendMessageW
#endif
LRESULT qxeSendMessage (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);

/* windows */

#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef RegisterClass
#define RegisterClass error use qxeRegisterClass or RegisterClassA/RegisterClassW
#endif
ATOM qxeRegisterClass (CONST WNDCLASSW * lpWndClass);

#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef UnregisterClass
#define UnregisterClass error use qxeUnregisterClass or UnregisterClassA/UnregisterClassW
#endif
BOOL qxeUnregisterClass (const Extbyte * lpClassName, HINSTANCE hInstance);

#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef RegisterClassEx
#define RegisterClassEx error use qxeRegisterClassEx or RegisterClassExA/RegisterClassExW
#endif
ATOM qxeRegisterClassEx (CONST WNDCLASSEXW * arg1);

#ifdef ERROR_WHEN_NONINTERCEPTED_FUNS_USED
#undef CreateWindow
#define CreateWindow error use qxeCreateWindow or CreateWindowA/CreateWindowW
#endif
#define qxeCreateWindow(lpClassName, lpWindowName, dwStyle, x, y,	     \
                        nWidth, nHeight, hWndParent, hMenu, hInstance,	     \
			lpParam)					     \
  qxeCreateWindowEx (0L, lpClassName, lpWindowName, dwStyle, x, y,	     \
                     nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)

/* ------------------------- Unicode conversion ------------------------- */

/* Set early in command-line processing, when -nuni or
   --no-unicode-lib-calls is seen. */
extern int no_mswin_unicode_lib_calls;
/* Set early, in init_win32_very_very_early(). */
extern int mswindows_windows9x_p;
#define XEUNICODE_P (!mswindows_windows9x_p && !no_mswin_unicode_lib_calls)

#define XELPTSTR LPWSTR
#define XELPCTSTR LPCWSTR

#define XETCHAR_SIZE (XEUNICODE_P ? sizeof (WCHAR) : sizeof (CHAR))
#define MAX_XETCHAR_SIZE sizeof (WCHAR)
#define XETEXT1(arg) (XEUNICODE_P ? ((char *) (L##arg)) : (arg))
/* We need to do this indirection in case ARG is also a manifest constant.
   I don't really understand why. --ben */
#define XETEXT(arg) XETEXT1(arg)
#define XECOPY_TCHAR(ptr, ch) \
  (XEUNICODE_P ? (* (LPWSTR) (ptr) = L##ch) : (* (LPSTR) (ptr) = (ch)))
#define qxetcslen(arg) \
  (XEUNICODE_P ? wcslen ((wchar_t *) arg) : strlen (arg))
#define qxetcsbytelen(arg) \
  (XEUNICODE_P ? wcslen ((wchar_t *) arg) * XETCHAR_SIZE : strlen (arg))
#define qxetcscmp(s1, s2) \
  (XEUNICODE_P ? wcscmp ((wchar_t *) s1, (wchar_t *) s2) \
   : strcmp (s1, s2))
#define qxetcscpy(s1, s2) \
  (XEUNICODE_P ? (char *) wcscpy ((wchar_t *) s1, (wchar_t *) s2) \
   : strcpy (s1, s2))
#define qxetcsncpy(s1, s2, n) \
  (XEUNICODE_P ? (char *) wcsncpy ((wchar_t *) s1, (wchar_t *) s2, n) \
   : strncpy (s1, s2, n))
#define qxetcschr(s, ch) \
  (XEUNICODE_P ? (char *) wcschr ((wchar_t *) s, (WCHAR) ch) \
   : strchr (s, ch))
#define qxetcsrchr(s, ch) \
  (XEUNICODE_P ? (char *) wcsrchr ((wchar_t *) s, (WCHAR) ch) \
   : strrchr (s, ch))
#define qxetcsdup(s) \
  (XEUNICODE_P ? (char *) wcsdup ((wchar_t *) s) \
   : xstrdup (s))

#define ITEXT_TO_TSTR(in) ITEXT_TO_EXTERNAL (in, Qmswindows_tstr)
#define LISP_STRING_TO_TSTR(in) LISP_STRING_TO_EXTERNAL (in, Qmswindows_tstr)
#define TSTR_TO_ITEXT(in) EXTERNAL_TO_ITEXT (in, Qmswindows_tstr)
#define TSTR_TO_ITEXT_MALLOC(in) \
  EXTERNAL_TO_ITEXT_MALLOC (in, Qmswindows_tstr)

#define build_tstr_string(in) \
  make_extstring (in, qxetcsbytelen ((Extbyte *) in), Qmswindows_tstr)

#define MAX_ANSI_CHAR_LEN 1
#define MAX_UNICODE_CHAR_LEN 2

DECLARE_INLINE_HEADER (int ansi_char_to_text (int ch, Extbyte *t))
{
  ch &= 0xFF;
  t[0] = ch;
  return 1;
}

DECLARE_INLINE_HEADER (int unicode_char_to_text (int ch, Extbyte *t))
{
  t[0] = ch & 0xFF;
  t[1] = (ch >> 8) & 0xFF;
  return 2;
}

Extbyte *convert_multibyte_to_unicode_malloc (const Extbyte *src,
					      Bytecount n,
					      int cp, Bytecount *size_out);
Extbyte *convert_unicode_to_multibyte_malloc (const Extbyte *src,
					      Bytecount n,
					      int cp, Bytecount *size_out);
Ibyte *convert_multibyte_to_internal_malloc (const Extbyte *src,
					       Bytecount n,
					       int cp, Bytecount *size_out);
void convert_multibyte_to_unicode_dynarr (const Extbyte *src, Bytecount n,
					  int cp, unsigned_char_dynarr *dst);
void convert_unicode_to_multibyte_dynarr (const Extbyte *src, Bytecount n,
					  int cp, unsigned_char_dynarr *dst);

Bytecount unicode_multibyte_convert_size (const char *srctext, const void *src,
					  Bytecount src_size, int to_unicode,
					  int cp);
void *unicode_multibyte_convert_copy_data (const char *srctext,
					   void *alloca_data);

/* NOTE: If you make two invocations of the following functions in the same
   subexpression and use the exact same expression for the source in both
   cases, you will lose.  In this unlikely case, you may get an abort, and
   need to rewrite the code.

   We need to use ALLOCA_FUNCALL_OK here, see NEW_DFC in text.h.
*/

#ifdef WEXTTEXT_IS_WIDE
#define MULTIBYTE_TO_WEXTTEXT(str)					 \
  ((Wexttext *)								 \
   unicode_multibyte_convert_copy_data					 \
   (#str, ALLOCA_FUNCALL_OK (unicode_multibyte_convert_size		 \
			     (#str, str, strlen (str) + 1, 1, CP_ACP))))

#define WEXTTEXT_TO_MULTIBYTE(str)					\
  ((Extbyte *)								\
   unicode_multibyte_convert_copy_data					\
   (#str, ALLOCA_FUNCALL_OK (unicode_multibyte_convert_size		\
			     (#str, str,				\
			      (wcslen (str) + 1) * sizeof (WCHAR), 0,	\
			      CP_ACP))))
#else
#define MULTIBYTE_TO_WEXTTEXT(str) ((Wexttext *) (str))
#define WEXTTEXT_TO_MULTIBYTE(str) ((Extbyte *) (str))
#endif

/* #### mbstowcs() uses MB_ERR_INVALID_CHARS in addition to MB_PRECOMPOSED.
   Should we do this?  But then we have to handle errors.
   #### Do we already check for invalid sequences in the coding system? */
#define MBTOWC_OPTIONS MB_PRECOMPOSED /* | MB_ERR_INVALID_CHARS */
  /* The following options are what wcstombs() uses in the CRT.  It uses
     NULL in place of "~". */
#define WCTOMB_OPTIONS WC_COMPOSITECHECK | WC_SEPCHARS
#define WCTOMB_INVALID_STRING "~"

/* ------------------------- Other Mule stuff ------------------------- */

LCID mswindows_current_locale (void);
int mswindows_locale_to_code_page (LCID lcid);
int mswindows_locale_to_oem_code_page (LCID lcid);

/* ------------------------- Filename conversion ------------------------- */

#ifdef CYGWIN

/* We should just remove the Windows 9x support */

#define CCP_POSIX_TO_WIN_T \
  (XEUNICODE_P ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A)
#define CCP_WIN_T_TO_POSIX \
  (XEUNICODE_P ? CCP_WIN_W_TO_POSIX : CCP_WIN_A_TO_POSIX)

#endif

#ifdef HAVE_CYGWIN_CONV_PATH
#define LOCAL_FILE_FORMAT_TO_TSTR(path, out)				\
do {									\
  const Ibyte *lfftt = (path);						\
  const Extbyte **lffttout = (const Extbyte **) &(out);			\
  if (isalpha (lfftt[0]) && (IS_DEVICE_SEP (lfftt[1])))			\
    PATHNAME_CONVERT_OUT_TSTR (lfftt, *lffttout);			\
  else									\
    {									\
      int lfftt_size;							\
      Extbyte *lfftt_utf8_path;						\
      Extbyte *lfftt_tstr_path;						\
									\
      PATHNAME_CONVERT_OUT_UTF_8 (lfftt, lfftt_utf8_path);		\
      lfftt_size = cygwin_conv_path (CCP_POSIX_TO_WIN_T | CCP_RELATIVE,	\
				     lfftt_utf8_path, NULL, 0);		\
      lfftt_tstr_path = alloca_extbytes (lfftt_size);			\
      cygwin_conv_path (CCP_POSIX_TO_WIN_T | CCP_RELATIVE,		\
			lfftt_utf8_path, lfftt_tstr_path, lfftt_size);	\
      *lffttout = lfftt_tstr_path;					\
    }									\
} while (0)
#define TSTR_TO_LOCAL_FILE_FORMAT(path, out)				\
do {									\
  const Extbyte *ttlff = (path);					\
  int ttlff_size;							\
  Extbyte *ttlff_utf8_path;						\
									\
  ttlff_size = cygwin_conv_path (CCP_WIN_T_TO_POSIX | CCP_RELATIVE,	\
				 ttlff, NULL, 0);			\
  ttlff_utf8_path = alloca_extbytes (ttlff_size);			\
  cygwin_conv_path (CCP_WIN_T_TO_POSIX | CCP_RELATIVE,			\
		    ttlff, ttlff_utf8_path, ttlff_size);		\
  (out) = EXTERNAL_TO_ITEXT (ttlff_utf8_path, Qutf_8);			\
} while (0)
#else /* not HAVE_CYGWIN_CONV_PATH */
#define LOCAL_FILE_FORMAT_TO_TSTR(path, out)		\
do {							\
  const Ibyte *lfftt;					\
  const Extbyte **lffttout = (const Extbyte **) &(out);	\
							\
  LOCAL_FILE_FORMAT_TO_INTERNAL_MSWIN (path, lfftt);	\
  PATHNAME_CONVERT_OUT_TSTR (lfftt, *lffttout);		\
} while (0)
#define TSTR_TO_LOCAL_FILE_FORMAT(path, out)		\
do {							\
  const Ibyte *ttlff;					\
							\
  ttlff = TSTR_TO_ITEXT (path);				\
  INTERNAL_MSWIN_TO_LOCAL_FILE_FORMAT (ttlff, out);	\
} while (0)
#endif /* (not) HAVE_CYGWIN_CONV_PATH */

#define LISP_LOCAL_FILE_FORMAT_TO_TSTR(path, out) \
  LOCAL_FILE_FORMAT_TO_TSTR (XSTRING_DATA (path), out)
/* Convert from local file format, as used in XEmacs, to valid win32
   filenames as can be given to Windows API routines.  Under native XEmacs,
   this is a no-op, but under Cygwin, the local names look different --
   Cygwin mount points, forward slashes, etc.  Currently, under Cygwin, we
   actually allow local names to be of both formats, i.e. Cygwin or Win32
   native.  So we check to see if we have Win32 native already (a cheesy
   check, look for letter plus colon at beginning of name) and do nothing
   in that case. */

#ifdef HAVE_CYGWIN_CONV_PATH
/* When Cygwin uses UTF-8, we can't just manipulate internal-format data
   with its routines because it will mangle the high bytes, so we need to
   convert to UTF-8 first, then to Win32 TSTR format (i.e. UTF-16, on
   Windows NT), then back to internal format.  Routines that want external
   format should avoid this by using LISP_LOCAL_FILE_FORMAT_TO_TSTR().
   Same thing applies going the other direction. */
#define LOCAL_FILE_FORMAT_TO_INTERNAL_MSWIN(path, pathout)	\
do								\
  {								\
    const Extbyte *lfftiwp;					\
								\
    LOCAL_FILE_FORMAT_TO_TSTR (path, lfftiwp);			\
    (pathout) = TSTR_TO_ITEXT (lfftiwp);			\
  }								\
while (0)
#define INTERNAL_MSWIN_TO_LOCAL_FILE_FORMAT(path, pathout)	\
do {								\
  const Extbyte *iwtlffp;					\
  iwtlffp = ITEXT_TO_TSTR (path);				\
  TSTR_TO_LOCAL_FILE_FORMAT (iwtlffp, pathout);			\
} while (0)
#elif defined (CYGWIN)
#define LOCAL_FILE_FORMAT_TO_INTERNAL_MSWIN(path, pathout)		\
do {									\
  /* NOTE: It is a bit evil that here and below we are passing		\
     internal-format data to a function that (nominally) should work	\
     with external-format data.  But in point of fact, the Cygwin	\
     conversion functions are *NOT* localized, and will fail if they	\
     get 7-bit ISO2022-encoded data.  We know that our internal format	\
     is ASCII-compatible, and so these functions will work fine with	\
     this data (maybe ...  not when Cygwin uses UTF-8) */		\
  const Ibyte *lfftiwp = (path);					\
  if (isalpha (lfftiwp[0]) && (IS_DEVICE_SEP (lfftiwp[1])))		\
    (pathout) = lfftiwp;						\
  else									\
    {									\
      int lfftiw2 =							\
        cygwin_posix_to_win32_path_list_buf_size ((char *) lfftiwp);	\
      (pathout) = alloca_ibytes (lfftiw2);				\
      cygwin_posix_to_win32_path_list ((char *) lfftiwp, (char *) pathout); \
    }									\
} while (0)
#define INTERNAL_MSWIN_TO_LOCAL_FILE_FORMAT(path, pathout)		\
do {									\
  const Ibyte *wtlff1 = (path);						\
  int wtlff2 =								\
    cygwin_win32_to_posix_path_list_buf_size ((char *) wtlff1);		\
  Ibyte *wtlff3 = alloca_ibytes (wtlff2);				\
  cygwin_win32_to_posix_path_list ((char *) wtlff1, (char *) wtlff3);	\
  (pathout) = wtlff3;							\
} while (0)
#else /* not defined (CYGWIN) */
#define LOCAL_FILE_FORMAT_TO_INTERNAL_MSWIN(path, pathout)	\
do {								\
  (pathout) = (path);						\
} while (0)
#define INTERNAL_MSWIN_TO_LOCAL_FILE_FORMAT(path, pathout)	\
do {								\
  (pathout) = (path);						\
} while (0)
#endif /* (not) defined (CYGWIN) */

Lisp_Object tstr_to_local_file_format (Extbyte *pathout);

/* Convert a local-format file name or URL in internal format into a Win32
   file name or URL in tstr format. */

#ifdef CYGWIN

#define LISP_LOCAL_FILE_FORMAT_MAYBE_URL_TO_TSTR(lispstr, pathout)	\
do									\
{									\
  Ibyte *lffmutt_fname1;						\
  Ibyte *lffmutt_pathint = XSTRING_DATA (lispstr);			\
									\
  if ((lffmutt_fname1 = qxestrchr (lffmutt_pathint, ':')) != NULL	\
      && *++lffmutt_fname1 == '/' && *++lffmutt_fname1 == '/')		\
    {									\
      /* If URL style file, the innards may have Cygwin mount points and \
	 the like.  so separate out the innards, process them, and put back \
	 together. */							\
      if (qxestrncasecmp_ascii (lffmutt_pathint, "file://", 7) == 0)	\
	{								\
	  Ibyte *lffmutt_path1, *lffmutt_path2;				\
	  LOCAL_FILE_FORMAT_TO_INTERNAL_MSWIN (lffmutt_pathint + 7,	\
                                               lffmutt_path1);		\
	  if (lffmutt_path1 == lffmutt_pathint + 7) /* Optimization */	\
	    lffmutt_path2 = lffmutt_pathint;				\
	  else								\
	    {								\
	      lffmutt_path2 = alloca_ibytes (7 + qxestrlen (lffmutt_path1) \
					       + 1);			\
	      qxestrncpy (lffmutt_path2, lffmutt_pathint, 7);		\
	      qxestrcpy (lffmutt_path2 + 7, lffmutt_path1);		\
	    }								\
	  (pathout) = ITEXT_TO_TSTR (lffmutt_path2);			\
	}								\
      else								\
	/* A straight URL, just convert */				\
	(pathout) = LISP_STRING_TO_TSTR (lispstr);			\
    }									\
  else									\
    /* Not URL-style, must be a straight filename. */			\
    LISP_LOCAL_FILE_FORMAT_TO_TSTR (lispstr, pathout);			\
} while (0)

#else /* not CYGWIN */

  /* URL's (and everything else) are already in the right format */
#define LISP_LOCAL_FILE_FORMAT_MAYBE_URL_TO_TSTR(lispstr, pathout) \
   LISP_LOCAL_FILE_FORMAT_TO_TSTR (lispstr, pathout)

#endif /* not CYGWIN */


Ibyte *urlify_filename (Ibyte *filename);
Ibyte *mswindows_canonicalize_filename (Ibyte *name);
#define MSWINDOWS_NORMALIZE_FILENAME(name) \
  IBYTE_STRING_TO_ALLOCA (mswindows_canonicalize_filename (name), name)

/* ------------------- Functions needed dynamic binding ------------------- */

typedef BOOL (WINAPI *pfSwitchToThread_t) (VOID);

typedef NET_API_STATUS (NET_API_FUNCTION *pfNetUserEnum_t)
     (LPCWSTR, DWORD, DWORD, LPBYTE *, DWORD, LPDWORD, LPDWORD, LPDWORD);
typedef NET_API_STATUS (NET_API_FUNCTION *pfNetApiBufferFree_t) (LPVOID);

extern pfSwitchToThread_t xSwitchToThread;

extern pfNetUserEnum_t xNetUserEnum;
extern pfNetApiBufferFree_t xNetApiBufferFree;

/* --------- Useful routines for manipulating memory-mapped files -------- */

typedef struct file_data
{
  const Ibyte  *name;
  unsigned long  size;
  HANDLE         file;
  HANDLE         file_mapping;
  void           *file_base;
} file_data;

#define OFFSET_TO_RVA(var,section)			\
	  (section->VirtualAddress +			\
	   ((DWORD)(var) - section->PointerToRawData))

#define RVA_TO_OFFSET(var,section)			\
	  (section->PointerToRawData +			\
	   ((DWORD)(var) - section->VirtualAddress))

#define RVA_TO_PTR(var,section,filedata)		\
	  ((void *)(RVA_TO_OFFSET(var,section) +	\
		    (char *)(filedata).file_base))

int open_input_file (file_data *p_file, const Ibyte *name);
int open_output_file (file_data *p_file, const Ibyte *name,
		      unsigned long size);
void close_file_data (file_data *p_file);

/* ------------------------- Heap related stuff ------------------------- */

#ifdef WIN32_NATIVE

#define get_reserved_heap_size()	reserved_heap_size
#define get_committed_heap_size()	(get_data_end () - get_data_start ())
#define get_heap_start()		get_data_start ()
#define get_heap_end()			get_data_end ()
#define get_page_size()			sysinfo_cache.dwPageSize
#define get_allocation_unit()		sysinfo_cache.dwAllocationGranularity
#define get_processor_type()		sysinfo_cache.dwProcessorType
#define get_nt_major_version()  	nt_major_version
#define get_nt_minor_version()  	nt_minor_version

unsigned char *get_data_start (void);
unsigned char *get_data_end (void);
extern unsigned long  data_region_size;
extern unsigned long  reserved_heap_size;
extern SYSTEM_INFO    sysinfo_cache;
extern int    	      nt_major_version;
extern int    	      nt_minor_version;

/* To prevent zero-initialized variables from being placed into the bss
   section, use non-zero values to represent an uninitialized state.  */
#define UNINIT_PTR ((unsigned char*) 0xF0A0F0A0)
#define UNINIT_LONG (0xF0A0F0A0L)

/* Recreate the heap created during dumping.  */
void recreate_heap (Extbyte *executable_path);

/* Round the heap to this size.  */
void round_heap (unsigned long size);

/* Load in the dumped .bss section.  */
void read_in_bss (Extbyte *name);

/* Map in the dumped heap.  */
void map_in_heap (Extbyte *name);

/* Cache system info, e.g., the NT page size.  */
void cache_system_info (void);

/* Round ADDRESS up to be aligned with ALIGN.  */
unsigned char *round_to_next (unsigned char *address, 
			      unsigned long align);
#endif /* WIN32_NATIVE */

/* ------------------------- Misc prototypes ------------------------- */

#ifdef WIN32_NATIVE
DECLARE_INLINE_HEADER (int strcasecmp (const char *a, const char *b))
{
  return qxestrcasecmp ((const Ibyte *) a, (const Ibyte *) b);
}
#endif /* WIN32_NATIVE */

/* in nt.c */
int mswindows_access (const Ibyte *path, int mode);
int mswindows_link (const Ibyte *old, const Ibyte *new_);
int mswindows_rename (const Ibyte *oldname, const Ibyte *newname);
int mswindows_unlink (const Ibyte *path);
int mswindows_stat (const Ibyte *path, struct stat *buf);
int mswindows_fstat (int desc, struct stat *buf);
time_t mswindows_convert_time (FILETIME ft);
int mswindows_is_executable (const Ibyte *filename);
void mswindows_executable_type (const Ibyte *filename, int *is_dos_app,
				int *is_cygnus_app);
Ibyte *mswindows_getdcwd (int drivelet);

/* in process-nt.c */
extern int mswindows_compare_env (const void *strp1, const void *strp2);

/* in win32.c */
Extbyte *mswindows_get_module_file_name (void);
void mswindows_output_last_error (const Ascbyte *frob);
DECLARE_DOESNT_RETURN (mswindows_report_process_error (const Ascbyte *reason,
						       Lisp_Object data,
						       int errnum));
Lisp_Object mswindows_lisp_error (int errnum);
Ibyte *mswindows_read_link (const Ibyte *fname);

/* in intl-win32.c */
extern Lisp_Object Qmswindows_tstr, Qmswindows_unicode;
extern Lisp_Object Qmswindows_multibyte, Qmswindows_multibyte_to_unicode;

#endif /* INCLUDED_syswindows_h_ */