Source file: /~heha/hsn/UNI-T/

#pragma once

#if defined(UNICODE) && defined(_M_IX86)

# include <windows.h>

EXTERN_C LONG GnulWinVersion;
# define GnulIsAnsi() (GnulWinVersion<0)

/* This initialization for a UNICODE Win32 program, that changes all necessary
 * entry points to ANSI versions if necessary.
 * Parameters:
 *  hModule: The module handle. All external references to functions that
 *           contain small letters and end with capital letter "W"
 *           (the Windows style) are automatically changed to entries
 *           ending with letter "A".
 *           Required. Cannot be 0.
 *  fromto:  A list of pairs of zero-terminated ASCII strings that list
 *           non-Windows-style wide-character and ANSI version function names,
 *           e.g. "_snwprintf\0" "_snprintf\0" "swscanf\0" "sscanf\0",
 *           terminated with a two zero characters. (The C compiler will
 *           automatically do this when you use the notation above.)
 *           Optional, use NULL if not used.
 *  list:    A list of pointers to zero-terminated wide-character strings,
 *           terminated by a NULL pointer.
 *           This list should point to all constant strings that must be
 *           changed to ANSI strings for proper processing.
 *           Optional, use NULL if not used.
 * Return value:
 *  none
 * Notes:
 *  All wide-character entry points change to their ANSI counterparts
 *  when Windows 9x/Me is detected. Otherwise, this function does nothing.
 *  If you need wide-character entry points in Windows 9x/Me,
 *  mostly ExtTextOutW (that really can process wide characters),
 *  you must save the function pointer before calling GnulInit().
 *  You can freely use ANSI function pointers on NT platforms,
 *  these are never affected.
 *  In some cases you still need platform-dependent code.
 *  Use the GnulIsAnsi() macro for this type of platform detection.
 *  For GnulInit() testing on NT machines, define GNULTEST in your project.
 *  In this case, Win9x/Me will be "detected", and you can see whether
 *  your program will run correctly on Win9x/Me machines.
 *  Define GNULNOFROMTO to suppress code generation for the <fromto> parameter.
 *  This saves some bytes of code.
 *  Define GNULNOLIST to suppress code generation for the <list> parameter.
 *  This also saves some bytes of code.

EXTERN_C void WINAPI GnulInit(HINSTANCE hModule, PCSTR fromto, const PCWSTR *list);

# ifdef UNICODE
#  define GnulIsAnsi() FALSE
# else
#  define GnulIsAnsi() TRUE
# endif
// This default will ensure successful compilation in all other cases:
// * Non-IX86 machines where Win9x/Me does not run
// * ANSI compilations, useful for debugging
// * Win16 compilations, where no distinct API sets exist
# define GnulInit(a,b,c)

// returns the actual size of a TCHAR
#define sizeofTCHAR (GnulIsAnsi() ? 1 : 2)	/* multiplication factor */
// returns the shiftleft constant for sizeof multiplication of current TCHAR
#define shiftTCHAR (GnulIsAnsi() ? 0 : 1)	/* shiftleft count */
// returns the pointer to indexed character
#define addrTCHAR(p,i) (GnulIsAnsi() ? (LPTSTR)(((LPSTR)(p))+(i)) : (p)+(i)))
// returns an indexed character out of a string
#define getTCHAR(p,i) (GnulIsAnsi() ? ((LPCSTR)(p))[(i)] : (p)[(i)]))
// sets (replaces) an indexed character into a string
#define putTCHAR(p,i,c) (GnulIsAnsi() ? ((LPSTR)(p))[(i)]=(c) : (p)[(i)]))=(c))
// calculates pointer difference in characters
#define diffTCHAR(p1,p2) (GnulIsAnsi(?) ? (LPCSTR)(p1)-(LPCSTR)(p2) : (p1)-(p2))
Detected encoding: ASCII (7 bit)2