mirror of
https://github.com/reactos/reactos.git
synced 2025-04-25 16:10:29 +00:00
Cleanup freetypee lib
svn path=/trunk/; revision=39993
This commit is contained in:
parent
e5f6e4c0e8
commit
94c7a3392b
6 changed files with 0 additions and 1369 deletions
105
reactos/lib/3rdparty/freetype/ftfd/enable.c
vendored
105
reactos/lib/3rdparty/freetype/ftfd/enable.c
vendored
|
@ -1,105 +0,0 @@
|
|||
/*
|
||||
* PROJECT: ReactOS win32 subsystem
|
||||
* LICENSE: GPL - See COPYING in the top level directory
|
||||
* PURPOSE: GDI font driver for bitmap fonts
|
||||
* PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
|
||||
*/
|
||||
|
||||
#include "ftfd.h"
|
||||
|
||||
static DRVFN gadrvfn[] =
|
||||
{
|
||||
{INDEX_DrvEnablePDEV, (PFN)FtfdEnablePDEV},
|
||||
{INDEX_DrvCompletePDEV, (PFN)FtfdCompletePDEV},
|
||||
{INDEX_DrvDisablePDEV, (PFN)FtfdDisablePDEV},
|
||||
{INDEX_DrvLoadFontFile, (PFN)FtfdLoadFontFile},
|
||||
{INDEX_DrvUnloadFontFile, (PFN)FtfdUnloadFontFile},
|
||||
{INDEX_DrvQueryFontFile, (PFN)FtfdQueryFontFile},
|
||||
{INDEX_DrvQueryFontCaps, (PFN)FtfdQueryFontCaps},
|
||||
{INDEX_DrvQueryFontTree, (PFN)FtfdQueryFontTree},
|
||||
{INDEX_DrvQueryFont, (PFN)FtfdQueryFont},
|
||||
{INDEX_DrvFree, (PFN)FtfdFree},
|
||||
{INDEX_DrvQueryGlyphAttrs, (PFN)FtfdQueryGlyphAttrs},
|
||||
{INDEX_DrvQueryFontData, (PFN)FtfdQueryFontData},
|
||||
};
|
||||
|
||||
FT_Library gftlibrary;
|
||||
|
||||
|
||||
BOOL
|
||||
APIENTRY
|
||||
FtfdEnableDriver(
|
||||
ULONG iEngineVersion,
|
||||
ULONG cj,
|
||||
PDRVENABLEDATA pded)
|
||||
{
|
||||
FT_Error fterror;
|
||||
|
||||
DbgPrint("FtfdEnableDriver()\n");
|
||||
|
||||
/* Check parameter */
|
||||
if (cj < sizeof(DRVENABLEDATA))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Initialize freetype library */
|
||||
fterror = FT_Init_FreeType(&gftlibrary);
|
||||
if (fterror)
|
||||
{
|
||||
DbgPrint("an error occurred during library initialization: %ld.\n", fterror);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Fill DRVENABLEDATA */
|
||||
pded->c = sizeof(gadrvfn) / sizeof(DRVFN);
|
||||
pded->pdrvfn = gadrvfn;
|
||||
pded->iDriverVersion = DDI_DRIVER_VERSION_NT5;
|
||||
|
||||
/* Success */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
DHPDEV
|
||||
APIENTRY
|
||||
FtfdEnablePDEV(
|
||||
IN DEVMODEW *pdm,
|
||||
IN LPWSTR pwszLogAddress,
|
||||
IN ULONG cPat,
|
||||
OUT HSURF *phsurfPatterns,
|
||||
IN ULONG cjCaps,
|
||||
OUT ULONG *pdevcaps,
|
||||
IN ULONG cjDevInfo,
|
||||
OUT DEVINFO *pdi,
|
||||
IN HDEV hdev,
|
||||
IN LPWSTR pwszDeviceName,
|
||||
IN HANDLE hDriver)
|
||||
{
|
||||
DbgPrint("FtfdEnablePDEV(hdev=%p)\n", hdev);
|
||||
|
||||
|
||||
/* Return a dummy DHPDEV */
|
||||
return (PVOID)1;
|
||||
}
|
||||
|
||||
|
||||
VOID
|
||||
APIENTRY
|
||||
FtfdCompletePDEV(
|
||||
IN DHPDEV dhpdev,
|
||||
IN HDEV hdev)
|
||||
{
|
||||
DbgPrint("FtfdCompletePDEV()\n");
|
||||
/* Nothing to do */
|
||||
}
|
||||
|
||||
|
||||
VOID
|
||||
APIENTRY
|
||||
FtfdDisablePDEV(
|
||||
IN DHPDEV dhpdev)
|
||||
{
|
||||
DbgPrint("FtfdDisablePDEV()\n");
|
||||
/* Nothing to do */
|
||||
}
|
215
reactos/lib/3rdparty/freetype/ftfd/font.c
vendored
215
reactos/lib/3rdparty/freetype/ftfd/font.c
vendored
|
@ -1,215 +0,0 @@
|
|||
/*
|
||||
* PROJECT: ReactOS win32 subsystem
|
||||
* LICENSE: GPL - See COPYING in the top level directory
|
||||
* PURPOSE: GDI font driver for bitmap fonts
|
||||
* PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
|
||||
*/
|
||||
|
||||
#include "ftfd.h"
|
||||
|
||||
PVOID
|
||||
HackFixup(
|
||||
PVOID pvView,
|
||||
ULONG cjView)
|
||||
{
|
||||
CHAR *pc;
|
||||
CHAR c;
|
||||
|
||||
pc = EngAllocMem(0, cjView, 'tmp ');
|
||||
memcpy(pc, pvView, cjView);
|
||||
|
||||
c = *pc;
|
||||
*pc = 0;
|
||||
|
||||
return pc;
|
||||
}
|
||||
|
||||
/** Public Interface **********************************************************/
|
||||
|
||||
ULONG_PTR
|
||||
APIENTRY
|
||||
FtfdLoadFontFile(
|
||||
ULONG cFiles,
|
||||
ULONG_PTR *piFile,
|
||||
PVOID *ppvView,
|
||||
ULONG *pcjView,
|
||||
DESIGNVECTOR *pdv,
|
||||
ULONG ulLangID,
|
||||
ULONG ulFastCheckSum)
|
||||
{
|
||||
PVOID pvView;
|
||||
ULONG cjView, i;
|
||||
FT_Error fterror;
|
||||
FT_Face ftface;
|
||||
PFTFD_FILE pfile;
|
||||
|
||||
DbgPrint("FtfdLoadFontFile()\n");
|
||||
|
||||
/* Check parameters */
|
||||
if (cFiles != 1)
|
||||
{
|
||||
DbgPrint("Only 1 File is allowed, got %ld!\n", cFiles);
|
||||
return HFF_INVALID;
|
||||
}
|
||||
|
||||
/* Map the font file */
|
||||
if (!EngMapFontFileFD(*piFile, (PULONG*)&pvView, &cjView))
|
||||
{
|
||||
DbgPrint("Could not map font file!\n", cFiles);
|
||||
return HFF_INVALID;
|
||||
}
|
||||
|
||||
// HACK!!!
|
||||
pvView = HackFixup(pvView, cjView);
|
||||
|
||||
/* Look for faces in the file */
|
||||
for (i = 0; i < 100; i++)
|
||||
{
|
||||
fterror = FT_New_Memory_Face(gftlibrary, pvView, cjView, i, &ftface);
|
||||
if (fterror)
|
||||
{
|
||||
DbgPrint("Error reading font file (error code: %u)\n", fterror);
|
||||
break;
|
||||
}
|
||||
FT_Done_Face(ftface);
|
||||
}
|
||||
|
||||
/* Check whether we succeeded finding a face */
|
||||
if (i > 0)
|
||||
{
|
||||
pfile = EngAllocMem(0, sizeof(FTFD_FILE), 'dftF');
|
||||
if (pfile)
|
||||
{
|
||||
pfile->cNumFaces = i;
|
||||
pfile->iFile = *piFile;
|
||||
pfile->pvView = pvView;
|
||||
pfile->cjView = cjView;
|
||||
|
||||
DbgPrint("Success! Returning %ld faces\n", i);
|
||||
|
||||
return (ULONG_PTR)pfile;
|
||||
}
|
||||
}
|
||||
|
||||
DbgPrint("No faces found in file\n");
|
||||
|
||||
/* Unmap the file */
|
||||
EngUnmapFontFileFD(*piFile);
|
||||
|
||||
/* Failure! */
|
||||
return HFF_INVALID;
|
||||
|
||||
}
|
||||
|
||||
BOOL
|
||||
APIENTRY
|
||||
FtfdUnloadFontFile(
|
||||
IN ULONG_PTR iFile)
|
||||
{
|
||||
PFTFD_FILE pfile = (PFTFD_FILE)iFile;
|
||||
|
||||
DbgPrint("FtfdUnloadFontFile()\n");
|
||||
|
||||
// HACK!!!
|
||||
EngFreeMem(pfile->pvView);
|
||||
|
||||
/* Free the memory that was allocated for the font */
|
||||
EngFreeMem(pfile);
|
||||
|
||||
/* Unmap the font file */
|
||||
EngUnmapFontFileFD(pfile->iFile);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
LONG
|
||||
APIENTRY
|
||||
FtfdQueryFontFile(
|
||||
ULONG_PTR iFile,
|
||||
ULONG ulMode,
|
||||
ULONG cjBuf,
|
||||
ULONG *pulBuf)
|
||||
{
|
||||
PFTFD_FILE pfile = (PFTFD_FILE)iFile;
|
||||
|
||||
DbgPrint("FtfdQueryFontFile(ulMode=%ld)\n", ulMode);
|
||||
// DbgBreakPoint();
|
||||
|
||||
switch (ulMode)
|
||||
{
|
||||
case QFF_DESCRIPTION:
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
case QFF_NUMFACES:
|
||||
/* return the number of faces in the file */
|
||||
return pfile->cNumFaces;
|
||||
|
||||
}
|
||||
|
||||
return FD_ERROR;
|
||||
}
|
||||
|
||||
LONG
|
||||
APIENTRY
|
||||
FtfdQueryFontCaps(
|
||||
ULONG culCaps,
|
||||
ULONG *pulCaps)
|
||||
{
|
||||
DbgPrint("BmfdQueryFontCaps()\n");
|
||||
|
||||
/* We need room for 2 ULONGs */
|
||||
if (culCaps < 2)
|
||||
{
|
||||
return FD_ERROR;
|
||||
}
|
||||
|
||||
/* We only support 1 bpp */
|
||||
pulCaps[0] = 2;
|
||||
pulCaps[1] = QC_1BIT;
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
PVOID
|
||||
APIENTRY
|
||||
FtfdQueryFontTree(
|
||||
DHPDEV dhpdev,
|
||||
ULONG_PTR iFile,
|
||||
ULONG iFace,
|
||||
ULONG iMode,
|
||||
ULONG_PTR *pid)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PIFIMETRICS
|
||||
APIENTRY
|
||||
FtfdQueryFont(
|
||||
IN DHPDEV dhpdev,
|
||||
IN ULONG_PTR iFile,
|
||||
IN ULONG iFace,
|
||||
IN ULONG_PTR *pid)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
VOID
|
||||
APIENTRY
|
||||
FtfdFree(
|
||||
PVOID pv,
|
||||
ULONG_PTR id)
|
||||
{
|
||||
DbgPrint("FtfdFree()\n");
|
||||
if (id)
|
||||
{
|
||||
EngFreeMem((PVOID)id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
136
reactos/lib/3rdparty/freetype/ftfd/ftfd.h
vendored
136
reactos/lib/3rdparty/freetype/ftfd/ftfd.h
vendored
|
@ -1,136 +0,0 @@
|
|||
/*
|
||||
* PROJECT: ReactOS win32 subsystem
|
||||
* LICENSE: GPL - See COPYING in the top level directory
|
||||
* PURPOSE: GDI font driver for bitmap fonts
|
||||
* PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <windef.h>
|
||||
#include <wingdi.h>
|
||||
#include <winddi.h>
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
extern FT_Library gftlibrary;
|
||||
|
||||
/** Driver specific types *****************************************************/
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
PVOID pvView;
|
||||
ULONG cjView;
|
||||
ULONG_PTR iFile;
|
||||
ULONG cNumFaces;
|
||||
} FTFD_FILE, *PFTFD_FILE;
|
||||
|
||||
/** Function prototypes *******************************************************/
|
||||
|
||||
ULONG
|
||||
DbgPrint(IN PCHAR Format, IN ...);
|
||||
|
||||
static __inline__
|
||||
void
|
||||
DbgBreakPoint(void)
|
||||
{
|
||||
asm volatile ("int $3");
|
||||
}
|
||||
|
||||
DHPDEV
|
||||
APIENTRY
|
||||
FtfdEnablePDEV(
|
||||
IN DEVMODEW *pdm,
|
||||
IN LPWSTR pwszLogAddress,
|
||||
IN ULONG cPat,
|
||||
OUT HSURF *phsurfPatterns,
|
||||
IN ULONG cjCaps,
|
||||
OUT ULONG *pdevcaps,
|
||||
IN ULONG cjDevInfo,
|
||||
OUT DEVINFO *pdi,
|
||||
IN HDEV hdev,
|
||||
IN LPWSTR pwszDeviceName,
|
||||
IN HANDLE hDriver);
|
||||
|
||||
VOID
|
||||
APIENTRY
|
||||
FtfdCompletePDEV(
|
||||
IN DHPDEV dhpdev,
|
||||
IN HDEV hdev);
|
||||
|
||||
VOID
|
||||
APIENTRY
|
||||
FtfdDisablePDEV(
|
||||
IN DHPDEV dhpdev);
|
||||
|
||||
ULONG_PTR
|
||||
APIENTRY
|
||||
FtfdLoadFontFile(
|
||||
ULONG cFiles,
|
||||
ULONG_PTR *piFile,
|
||||
PVOID *ppvView,
|
||||
ULONG *pcjView,
|
||||
DESIGNVECTOR *pdv,
|
||||
ULONG ulLangID,
|
||||
ULONG ulFastCheckSum);
|
||||
|
||||
BOOL
|
||||
APIENTRY
|
||||
FtfdUnloadFontFile(
|
||||
IN ULONG_PTR iFile);
|
||||
|
||||
LONG
|
||||
APIENTRY
|
||||
FtfdQueryFontFile(
|
||||
ULONG_PTR iFile,
|
||||
ULONG ulMode,
|
||||
ULONG cjBuf,
|
||||
ULONG *pulBuf);
|
||||
|
||||
LONG
|
||||
APIENTRY
|
||||
FtfdQueryFontCaps(
|
||||
ULONG culCaps,
|
||||
ULONG *pulCaps);
|
||||
|
||||
PVOID
|
||||
APIENTRY
|
||||
FtfdQueryFontTree(
|
||||
DHPDEV dhpdev,
|
||||
ULONG_PTR iFile,
|
||||
ULONG iFace,
|
||||
ULONG iMode,
|
||||
ULONG_PTR *pid);
|
||||
|
||||
PIFIMETRICS
|
||||
APIENTRY
|
||||
FtfdQueryFont(
|
||||
IN DHPDEV dhpdev,
|
||||
IN ULONG_PTR iFile,
|
||||
IN ULONG iFace,
|
||||
IN ULONG_PTR *pid);
|
||||
|
||||
VOID
|
||||
APIENTRY
|
||||
FtfdFree(
|
||||
PVOID pv,
|
||||
ULONG_PTR id);
|
||||
|
||||
PFD_GLYPHATTR
|
||||
APIENTRY
|
||||
FtfdQueryGlyphAttrs(
|
||||
FONTOBJ *pfo,
|
||||
ULONG iMode);
|
||||
|
||||
LONG
|
||||
APIENTRY
|
||||
FtfdQueryFontData(
|
||||
DHPDEV dhpdev,
|
||||
FONTOBJ *pfo,
|
||||
ULONG iMode,
|
||||
HGLYPH hg,
|
||||
OUT GLYPHDATA *pgd,
|
||||
PVOID pv,
|
||||
ULONG cjSize);
|
||||
|
34
reactos/lib/3rdparty/freetype/ftfd/glyph.c
vendored
34
reactos/lib/3rdparty/freetype/ftfd/glyph.c
vendored
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* PROJECT: ReactOS win32 subsystem
|
||||
* LICENSE: GPL - See COPYING in the top level directory
|
||||
* PURPOSE: GDI font driver for bitmap fonts
|
||||
* PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
|
||||
*/
|
||||
|
||||
#include "ftfd.h"
|
||||
|
||||
|
||||
/** Public Interface **********************************************************/
|
||||
|
||||
PFD_GLYPHATTR
|
||||
APIENTRY
|
||||
FtfdQueryGlyphAttrs(
|
||||
FONTOBJ *pfo,
|
||||
ULONG iMode)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LONG
|
||||
APIENTRY
|
||||
FtfdQueryFontData(
|
||||
DHPDEV dhpdev,
|
||||
FONTOBJ *pfo,
|
||||
ULONG iMode,
|
||||
HGLYPH hg,
|
||||
OUT GLYPHDATA *pgd,
|
||||
PVOID pv,
|
||||
ULONG cjSize)
|
||||
{
|
||||
return FD_ERROR;
|
||||
}
|
137
reactos/lib/3rdparty/freetype/rosglue.c
vendored
137
reactos/lib/3rdparty/freetype/rosglue.c
vendored
|
@ -1,137 +0,0 @@
|
|||
/* $Id$
|
||||
*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: FreeType implementation for ReactOS
|
||||
* PURPOSE: Glue functions between FreeType
|
||||
* FILE: thirdparty/freetype/rosglue.c
|
||||
* PROGRAMMER: Ge van Geldorp (ge@gse.nl)
|
||||
* NOTES:
|
||||
*/
|
||||
|
||||
#include <windef.h>
|
||||
#include <wingdi.h>
|
||||
#include <winddi.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
#define TAG(A, B, C, D) (ULONG)(((A)<<0) + ((B)<<8) + ((C)<<16) + ((D)<<24))
|
||||
#define TAG_FREETYPE TAG('F', 'T', 'Y', 'P')
|
||||
|
||||
/*
|
||||
* First some generic routines
|
||||
*/
|
||||
|
||||
ULONG
|
||||
DbgPrint(IN PCCH Format, IN ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, Format);
|
||||
EngDebugPrint("ft2: ", (PCHAR)Format, args);
|
||||
va_end(args);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Memory allocation
|
||||
*
|
||||
* Because of realloc, we need to keep track of the size of the allocated
|
||||
* buffer (need to copy the old contents to the new buffer). So, allocate
|
||||
* extra space for a size_t, store the allocated size in there and return
|
||||
* the address just past it as the allocated buffer.
|
||||
*/
|
||||
|
||||
void *
|
||||
malloc(size_t Size)
|
||||
{
|
||||
void *Object;
|
||||
|
||||
Object = EngAllocMem(0, sizeof(size_t) + Size, TAG_FREETYPE);
|
||||
if (NULL != Object)
|
||||
{
|
||||
*((size_t *) Object) = Size;
|
||||
Object = (void *)((size_t *) Object + 1);
|
||||
}
|
||||
|
||||
return Object;
|
||||
}
|
||||
|
||||
void *
|
||||
realloc(void *Object, size_t Size)
|
||||
{
|
||||
void *NewObject;
|
||||
size_t CopySize;
|
||||
|
||||
NewObject = EngAllocMem(0, sizeof(size_t) + Size, TAG_FREETYPE);
|
||||
if (NULL != NewObject)
|
||||
{
|
||||
*((size_t *) NewObject) = Size;
|
||||
NewObject = (void *)((size_t *) NewObject + 1);
|
||||
CopySize = *((size_t *) Object - 1);
|
||||
if (Size < CopySize)
|
||||
{
|
||||
CopySize = Size;
|
||||
}
|
||||
memcpy(NewObject, Object, CopySize);
|
||||
EngFreeMem((size_t *) Object - 1);
|
||||
}
|
||||
|
||||
return NewObject;
|
||||
}
|
||||
|
||||
void
|
||||
free(void *Object)
|
||||
{
|
||||
EngFreeMem((size_t *) Object - 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* File I/O
|
||||
*
|
||||
* This is easy, we don't want FreeType to do any I/O. So return an
|
||||
* error on each I/O attempt. Note that errno is not being set, it is
|
||||
* not used by FreeType.
|
||||
*/
|
||||
|
||||
FILE *
|
||||
fopen(const char *FileName, const char *Mode)
|
||||
{
|
||||
DPRINT1("Freetype tries to open file %s\n", FileName);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
fseek(FILE *Stream, long Offset, int Origin)
|
||||
{
|
||||
DPRINT1("Doubleplus ungood: freetype shouldn't fseek!\n");
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
long
|
||||
ftell(FILE *Stream)
|
||||
{
|
||||
DPRINT1("Doubleplus ungood: freetype shouldn't ftell!\n");
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t
|
||||
fread(void *Buffer, size_t Size, size_t Count, FILE *Stream)
|
||||
{
|
||||
DPRINT1("Doubleplus ungood: freetype shouldn't fread!\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
fclose(FILE *Stream)
|
||||
{
|
||||
DPRINT1("Doubleplus ungood: freetype shouldn't fclose!\n");
|
||||
|
||||
return EOF;
|
||||
}
|
742
reactos/lib/3rdparty/freetype/sprintf.c
vendored
742
reactos/lib/3rdparty/freetype/sprintf.c
vendored
|
@ -1,742 +0,0 @@
|
|||
/*
|
||||
* PROGRAMMERS: David Welch
|
||||
* Eric Kohl
|
||||
*
|
||||
* TODO:
|
||||
* - Verify the implementation of '%Z'.
|
||||
*/
|
||||
|
||||
/*
|
||||
* linux/lib/vsprintf.c
|
||||
*
|
||||
* Copyright (C) 1991, 1992 Linus Torvalds
|
||||
*/
|
||||
|
||||
/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */
|
||||
/*
|
||||
* Wirzenius wrote this portably, Torvalds fucked it up :-)
|
||||
*/
|
||||
|
||||
#define WIN32_NO_STATUS
|
||||
#include <windows.h>
|
||||
#include <ndk/ntndk.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define ZEROPAD 1 /* pad with zero */
|
||||
#define SIGN 2 /* unsigned/signed long */
|
||||
#define PLUS 4 /* show plus */
|
||||
#define SPACE 8 /* space if plus */
|
||||
#define LEFT 16 /* left justified */
|
||||
#define SPECIAL 32 /* 0x */
|
||||
#define LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */
|
||||
#define REMOVEHEX 256 /* use 256 as remve 0x frim BASE 16 */
|
||||
typedef struct {
|
||||
unsigned int mantissal:32;
|
||||
unsigned int mantissah:20;
|
||||
unsigned int exponent:11;
|
||||
unsigned int sign:1;
|
||||
} double_t;
|
||||
|
||||
static
|
||||
__inline
|
||||
int
|
||||
_isinf(double __x)
|
||||
{
|
||||
union
|
||||
{
|
||||
double* __x;
|
||||
double_t* x;
|
||||
} x;
|
||||
|
||||
x.__x = &__x;
|
||||
return ( x.x->exponent == 0x7ff && ( x.x->mantissah == 0 && x.x->mantissal == 0 ));
|
||||
}
|
||||
|
||||
static
|
||||
__inline
|
||||
int
|
||||
_isnan(double __x)
|
||||
{
|
||||
union
|
||||
{
|
||||
double* __x;
|
||||
double_t* x;
|
||||
} x;
|
||||
x.__x = &__x;
|
||||
return ( x.x->exponent == 0x7ff && ( x.x->mantissah != 0 || x.x->mantissal != 0 ));
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
__inline
|
||||
int
|
||||
do_div(long long *n, int base)
|
||||
{
|
||||
int a;
|
||||
a = ((unsigned long long) *n) % (unsigned) base;
|
||||
*n = ((unsigned long long) *n) / (unsigned) base;
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
static int skip_atoi(const char **s)
|
||||
{
|
||||
int i=0;
|
||||
|
||||
while (isdigit(**s))
|
||||
i = i*10 + *((*s)++) - '0';
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
static char *
|
||||
number(char * buf, char * end, long long num, int base, int size, int precision, int type)
|
||||
{
|
||||
char c,sign,tmp[66];
|
||||
const char *digits;
|
||||
const char *small_digits = "0123456789abcdefghijklmnopqrstuvwxyz";
|
||||
const char *large_digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
int i;
|
||||
|
||||
digits = (type & LARGE) ? large_digits : small_digits;
|
||||
if (type & LEFT)
|
||||
type &= ~ZEROPAD;
|
||||
if (base < 2 || base > 36)
|
||||
return 0;
|
||||
c = (type & ZEROPAD) ? '0' : ' ';
|
||||
sign = 0;
|
||||
if (type & SIGN) {
|
||||
if (num < 0) {
|
||||
sign = '-';
|
||||
num = -num;
|
||||
size--;
|
||||
} else if (type & PLUS) {
|
||||
sign = '+';
|
||||
size--;
|
||||
} else if (type & SPACE) {
|
||||
sign = ' ';
|
||||
size--;
|
||||
}
|
||||
}
|
||||
|
||||
if ((type & SPECIAL) && ((type & REMOVEHEX) == 0)) {
|
||||
if (base == 16)
|
||||
size -= 2;
|
||||
|
||||
}
|
||||
i = 0;
|
||||
if ((num == 0) && (precision !=0))
|
||||
tmp[i++] = '0';
|
||||
else while (num != 0)
|
||||
tmp[i++] = digits[do_div(&num,base)];
|
||||
if (i > precision)
|
||||
precision = i;
|
||||
size -= precision;
|
||||
if (!(type&(ZEROPAD+LEFT))) {
|
||||
while(size-->0) {
|
||||
if (buf <= end)
|
||||
*buf = ' ';
|
||||
++buf;
|
||||
}
|
||||
}
|
||||
if (sign) {
|
||||
if (buf <= end)
|
||||
*buf = sign;
|
||||
++buf;
|
||||
}
|
||||
|
||||
if ((type & SPECIAL) && ((type & REMOVEHEX) == 0)) {
|
||||
if (base==16) {
|
||||
if (buf <= end)
|
||||
*buf = '0';
|
||||
++buf;
|
||||
if (buf <= end)
|
||||
*buf = digits[33];
|
||||
++buf;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(type & LEFT)) {
|
||||
while (size-- > 0) {
|
||||
if (buf <= end)
|
||||
*buf = c;
|
||||
++buf;
|
||||
}
|
||||
}
|
||||
while (i < precision--) {
|
||||
if (buf <= end)
|
||||
*buf = '0';
|
||||
++buf;
|
||||
}
|
||||
while (i-- > 0) {
|
||||
if (buf <= end)
|
||||
*buf = tmp[i];
|
||||
++buf;
|
||||
}
|
||||
while (size-- > 0) {
|
||||
if (buf <= end)
|
||||
*buf = ' ';
|
||||
++buf;
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
static char *
|
||||
numberf(char * buf, char * end, double num, int base, int size, int precision, int type)
|
||||
{
|
||||
char c,sign,tmp[66];
|
||||
const char *digits;
|
||||
const char *small_digits = "0123456789abcdefghijklmnopqrstuvwxyz";
|
||||
const char *large_digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
int i;
|
||||
long long x;
|
||||
|
||||
/* FIXME
|
||||
the float version of number is direcly copy of number
|
||||
*/
|
||||
|
||||
digits = (type & LARGE) ? large_digits : small_digits;
|
||||
if (type & LEFT)
|
||||
type &= ~ZEROPAD;
|
||||
if (base < 2 || base > 36)
|
||||
return 0;
|
||||
c = (type & ZEROPAD) ? '0' : ' ';
|
||||
sign = 0;
|
||||
if (type & SIGN) {
|
||||
if (num < 0) {
|
||||
sign = '-';
|
||||
num = -num;
|
||||
size--;
|
||||
} else if (type & PLUS) {
|
||||
sign = '+';
|
||||
size--;
|
||||
} else if (type & SPACE) {
|
||||
sign = ' ';
|
||||
size--;
|
||||
}
|
||||
}
|
||||
if (type & SPECIAL) {
|
||||
if (base == 16)
|
||||
size -= 2;
|
||||
else if (base == 8)
|
||||
size--;
|
||||
}
|
||||
i = 0;
|
||||
if (num == 0)
|
||||
tmp[i++] = '0';
|
||||
else while (num != 0)
|
||||
{
|
||||
x = num;
|
||||
tmp[i++] = digits[do_div(&x,base)];
|
||||
num=x;
|
||||
}
|
||||
if (i > precision)
|
||||
precision = i;
|
||||
size -= precision;
|
||||
if (!(type&(ZEROPAD+LEFT))) {
|
||||
while(size-->0) {
|
||||
if (buf <= end)
|
||||
*buf = ' ';
|
||||
++buf;
|
||||
}
|
||||
}
|
||||
if (sign) {
|
||||
if (buf <= end)
|
||||
*buf = sign;
|
||||
++buf;
|
||||
}
|
||||
if (type & SPECIAL) {
|
||||
if (base==8) {
|
||||
if (buf <= end)
|
||||
*buf = '0';
|
||||
++buf;
|
||||
} else if (base==16) {
|
||||
if (buf <= end)
|
||||
*buf = '0';
|
||||
++buf;
|
||||
if (buf <= end)
|
||||
*buf = digits[33];
|
||||
++buf;
|
||||
}
|
||||
}
|
||||
if (!(type & LEFT)) {
|
||||
while (size-- > 0) {
|
||||
if (buf <= end)
|
||||
*buf = c;
|
||||
++buf;
|
||||
}
|
||||
}
|
||||
while (i < precision--) {
|
||||
if (buf <= end)
|
||||
*buf = '0';
|
||||
++buf;
|
||||
}
|
||||
while (i-- > 0) {
|
||||
if (buf <= end)
|
||||
*buf = tmp[i];
|
||||
++buf;
|
||||
}
|
||||
while (size-- > 0) {
|
||||
if (buf <= end)
|
||||
*buf = ' ';
|
||||
++buf;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
static char*
|
||||
string(char* buf, char* end, const char* s, int len, int field_width, int precision, int flags)
|
||||
{
|
||||
int i;
|
||||
char c;
|
||||
|
||||
c = (flags & ZEROPAD) ? '0' : ' ';
|
||||
|
||||
if (s == NULL)
|
||||
{
|
||||
s = "<NULL>";
|
||||
len = 6;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (len == -1)
|
||||
{
|
||||
len = 0;
|
||||
while ((unsigned int)len < (unsigned int)precision && s[len])
|
||||
len++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((unsigned int)len > (unsigned int)precision)
|
||||
len = precision;
|
||||
}
|
||||
}
|
||||
if (!(flags & LEFT))
|
||||
while (len < field_width--)
|
||||
{
|
||||
if (buf <= end)
|
||||
*buf = c;
|
||||
++buf;
|
||||
}
|
||||
for (i = 0; i < len; ++i)
|
||||
{
|
||||
if (buf <= end)
|
||||
*buf = *s++;
|
||||
++buf;
|
||||
}
|
||||
while (len < field_width--)
|
||||
{
|
||||
if (buf <= end)
|
||||
*buf = ' ';
|
||||
++buf;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
static char*
|
||||
stringw(char* buf, char* end, const wchar_t* sw, int len, int field_width, int precision, int flags)
|
||||
{
|
||||
int i;
|
||||
char c;
|
||||
|
||||
c = (flags & ZEROPAD) ? '0' : ' ';
|
||||
|
||||
if (sw == NULL)
|
||||
{
|
||||
sw = L"<NULL>";
|
||||
len = 6;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (len == -1)
|
||||
{
|
||||
len = 0;
|
||||
while ((unsigned int)len < (unsigned int)precision && sw[len])
|
||||
len++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((unsigned int)len > (unsigned int)precision)
|
||||
len = precision;
|
||||
}
|
||||
}
|
||||
if (!(flags & LEFT))
|
||||
while (len < field_width--)
|
||||
{
|
||||
if (buf <= end)
|
||||
*buf = c;
|
||||
buf++;
|
||||
}
|
||||
for (i = 0; i < len; ++i)
|
||||
{
|
||||
if (buf <= end)
|
||||
*buf = (unsigned char)(*sw++);
|
||||
buf++;
|
||||
}
|
||||
while (len < field_width--)
|
||||
{
|
||||
if (buf <= end)
|
||||
*buf = ' ';
|
||||
buf++;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
int __cdecl _vsnprintf(char *buf, size_t cnt, const char *fmt, va_list args)
|
||||
{
|
||||
int len;
|
||||
unsigned long long num;
|
||||
double _double;
|
||||
|
||||
int base;
|
||||
char *str, *end;
|
||||
const char *s;
|
||||
const wchar_t *sw;
|
||||
|
||||
int flags; /* flags to number() */
|
||||
|
||||
int field_width; /* width of output field */
|
||||
int precision; /* min. # of digits for integers; max
|
||||
number of chars for from string */
|
||||
int qualifier; /* 'h', 'l', 'L', 'I' or 'w' for integer fields */
|
||||
|
||||
/* clear the string buffer with zero so we do not need NULL terment it at end */
|
||||
|
||||
str = buf;
|
||||
end = buf + cnt - 1;
|
||||
if (end < buf - 1) {
|
||||
end = ((char *) -1);
|
||||
cnt = end - buf + 1;
|
||||
}
|
||||
|
||||
for ( ; *fmt ; ++fmt) {
|
||||
if (*fmt != '%') {
|
||||
if (str <= end)
|
||||
*str = *fmt;
|
||||
++str;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* process flags */
|
||||
flags = 0;
|
||||
repeat:
|
||||
++fmt; /* this also skips first '%' */
|
||||
switch (*fmt) {
|
||||
case '-': flags |= LEFT; goto repeat;
|
||||
case '+': flags |= PLUS; goto repeat;
|
||||
case ' ': flags |= SPACE; goto repeat;
|
||||
case '#': flags |= SPECIAL; goto repeat;
|
||||
case '0': flags |= ZEROPAD; goto repeat;
|
||||
}
|
||||
|
||||
/* get field width */
|
||||
field_width = -1;
|
||||
if (isdigit(*fmt))
|
||||
field_width = skip_atoi(&fmt);
|
||||
else if (*fmt == '*') {
|
||||
++fmt;
|
||||
/* it's the next argument */
|
||||
field_width = va_arg(args, int);
|
||||
if (field_width < 0) {
|
||||
field_width = -field_width;
|
||||
flags |= LEFT;
|
||||
}
|
||||
}
|
||||
|
||||
/* get the precision */
|
||||
precision = -1;
|
||||
if (*fmt == '.') {
|
||||
++fmt;
|
||||
if (isdigit(*fmt))
|
||||
precision = skip_atoi(&fmt);
|
||||
else if (*fmt == '*') {
|
||||
++fmt;
|
||||
/* it's the next argument */
|
||||
precision = va_arg(args, int);
|
||||
}
|
||||
if (precision < 0)
|
||||
precision = 0;
|
||||
}
|
||||
|
||||
/* get the conversion qualifier */
|
||||
qualifier = -1;
|
||||
if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || *fmt == 'w') {
|
||||
qualifier = *fmt;
|
||||
++fmt;
|
||||
} else if (*fmt == 'I' && *(fmt+1) == '6' && *(fmt+2) == '4') {
|
||||
qualifier = *fmt;
|
||||
fmt += 3;
|
||||
} else if (*fmt == 'I' && *(fmt+1) == '3' && *(fmt+2) == '2') {
|
||||
qualifier = 'l';
|
||||
fmt += 3;
|
||||
} else if (*fmt == 'F' && *(fmt+1) == 'p') {
|
||||
fmt += 1;
|
||||
flags |= REMOVEHEX;
|
||||
}
|
||||
|
||||
/* default base */
|
||||
base = 10;
|
||||
|
||||
switch (*fmt) {
|
||||
case 'c': /* finished */
|
||||
if (qualifier == 'l' || qualifier == 'w') {
|
||||
wchar_t sw1[2];
|
||||
/* print unicode string */
|
||||
sw1[0] = (wchar_t) va_arg(args, int);
|
||||
sw1[1] = 0;
|
||||
str = stringw(str, end, (wchar_t *)&sw1, -1, field_width, precision, flags);
|
||||
} else {
|
||||
char s1[2];
|
||||
/* print ascii string */
|
||||
s1[0] = ( unsigned char) va_arg(args, int);
|
||||
s1[1] = 0;
|
||||
str = string(str, end, (char *)&s1, -1, field_width, precision, flags);
|
||||
}
|
||||
continue;
|
||||
|
||||
case 'C': /* finished */
|
||||
if (!(flags & LEFT))
|
||||
while (--field_width > 0) {
|
||||
if (str <= end)
|
||||
*str = ' ';
|
||||
++str;
|
||||
}
|
||||
if (qualifier == 'h') {
|
||||
if (str <= end)
|
||||
*str = (unsigned char) va_arg(args, int);
|
||||
++str;
|
||||
} else {
|
||||
if (str <= end)
|
||||
*str = (unsigned char)(wchar_t) va_arg(args, int);
|
||||
++str;
|
||||
}
|
||||
while (--field_width > 0) {
|
||||
if (str <= end)
|
||||
*str = ' ';
|
||||
++str;
|
||||
}
|
||||
continue;
|
||||
|
||||
case 's': /* finished */
|
||||
if (qualifier == 'l' || qualifier == 'w') {
|
||||
/* print unicode string */
|
||||
sw = va_arg(args, wchar_t *);
|
||||
str = stringw(str, end, sw, -1, field_width, precision, flags);
|
||||
} else {
|
||||
/* print ascii string */
|
||||
s = va_arg(args, char *);
|
||||
str = string(str, end, s, -1, field_width, precision, flags);
|
||||
}
|
||||
continue;
|
||||
|
||||
case 'S':
|
||||
if (qualifier == 'h') {
|
||||
/* print ascii string */
|
||||
s = va_arg(args, char *);
|
||||
str = string(str, end, s, -1, field_width, precision, flags);
|
||||
} else {
|
||||
/* print unicode string */
|
||||
sw = va_arg(args, wchar_t *);
|
||||
str = stringw(str, end, sw, -1, field_width, precision, flags);
|
||||
}
|
||||
continue;
|
||||
|
||||
case 'Z':
|
||||
if (qualifier == 'w') {
|
||||
/* print counted unicode string */
|
||||
PUNICODE_STRING pus = va_arg(args, PUNICODE_STRING);
|
||||
if ((pus == NULL) || (pus->Buffer == NULL)) {
|
||||
sw = NULL;
|
||||
len = -1;
|
||||
} else {
|
||||
sw = pus->Buffer;
|
||||
len = pus->Length / sizeof(WCHAR);
|
||||
}
|
||||
str = stringw(str, end, sw, len, field_width, precision, flags);
|
||||
} else {
|
||||
/* print counted ascii string */
|
||||
PANSI_STRING pus = va_arg(args, PANSI_STRING);
|
||||
if ((pus == NULL) || (pus->Buffer == NULL)) {
|
||||
s = NULL;
|
||||
len = -1;
|
||||
} else {
|
||||
s = pus->Buffer;
|
||||
len = pus->Length;
|
||||
}
|
||||
str = string(str, end, s, len, field_width, precision, flags);
|
||||
}
|
||||
continue;
|
||||
|
||||
case 'p':
|
||||
if ((flags & LARGE) == 0)
|
||||
flags |= LARGE;
|
||||
|
||||
if (field_width == -1) {
|
||||
field_width = 2 * sizeof(void *);
|
||||
flags |= ZEROPAD;
|
||||
}
|
||||
str = number(str, end,
|
||||
(ULONG_PTR) va_arg(args, void *), 16,
|
||||
field_width, precision, flags);
|
||||
continue;
|
||||
|
||||
case 'n':
|
||||
/* FIXME: What does C99 say about the overflow case here? */
|
||||
if (qualifier == 'l') {
|
||||
long * ip = va_arg(args, long *);
|
||||
*ip = (str - buf);
|
||||
} else {
|
||||
int * ip = va_arg(args, int *);
|
||||
*ip = (str - buf);
|
||||
}
|
||||
continue;
|
||||
|
||||
/* float number formats - set up the flags and "break" */
|
||||
case 'e':
|
||||
case 'E':
|
||||
case 'f':
|
||||
case 'g':
|
||||
case 'G':
|
||||
_double = (double)va_arg(args, double);
|
||||
if ( _isnan(_double) ) {
|
||||
s = "Nan";
|
||||
len = 3;
|
||||
while ( len > 0 ) {
|
||||
if (str <= end)
|
||||
*str = *s++;
|
||||
++str;
|
||||
len --;
|
||||
}
|
||||
} else if ( _isinf(_double) < 0 ) {
|
||||
s = "-Inf";
|
||||
len = 4;
|
||||
while ( len > 0 ) {
|
||||
if (str <= end)
|
||||
*str = *s++;
|
||||
++str;
|
||||
len --;
|
||||
}
|
||||
} else if ( _isinf(_double) > 0 ) {
|
||||
s = "+Inf";
|
||||
len = 4;
|
||||
while ( len > 0 ) {
|
||||
if (str <= end)
|
||||
*str = *s++;
|
||||
++str;
|
||||
len --;
|
||||
}
|
||||
} else {
|
||||
if ( precision == -1 )
|
||||
precision = 6;
|
||||
str = numberf(str, end, (int)_double, base, field_width, precision, flags);
|
||||
}
|
||||
|
||||
continue;
|
||||
|
||||
|
||||
/* integer number formats - set up the flags and "break" */
|
||||
case 'o':
|
||||
base = 8;
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
base = 2;
|
||||
break;
|
||||
|
||||
case 'X':
|
||||
flags |= LARGE;
|
||||
case 'x':
|
||||
base = 16;
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
case 'i':
|
||||
flags |= SIGN;
|
||||
case 'u':
|
||||
break;
|
||||
|
||||
default:
|
||||
if (*fmt) {
|
||||
if (str <= end)
|
||||
*str = *fmt;
|
||||
++str;
|
||||
} else
|
||||
--fmt;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (qualifier == 'I')
|
||||
num = va_arg(args, unsigned long long);
|
||||
else if (qualifier == 'l') {
|
||||
if (flags & SIGN)
|
||||
num = va_arg(args, long);
|
||||
else
|
||||
num = va_arg(args, unsigned long);
|
||||
}
|
||||
else if (qualifier == 'h') {
|
||||
if (flags & SIGN)
|
||||
num = va_arg(args, int);
|
||||
else
|
||||
num = va_arg(args, unsigned int);
|
||||
}
|
||||
else {
|
||||
if (flags & SIGN)
|
||||
num = va_arg(args, int);
|
||||
else
|
||||
num = va_arg(args, unsigned int);
|
||||
}
|
||||
str = number(str, end, num, base, field_width, precision, flags);
|
||||
}
|
||||
if (str <= end)
|
||||
*str = '\0';
|
||||
else if (cnt > 0)
|
||||
/* don't write out a null byte if the buf size is zero */
|
||||
*end = '\0';
|
||||
return str-buf;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
int sprintf(char * buf, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
int i;
|
||||
|
||||
va_start(args, fmt);
|
||||
i=_vsnprintf(buf,MAXLONG,fmt,args);
|
||||
va_end(args);
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
int _snprintf(char * buf, size_t cnt, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
int i;
|
||||
|
||||
va_start(args, fmt);
|
||||
i=_vsnprintf(buf,cnt,fmt,args);
|
||||
va_end(args);
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
int __cdecl vsprintf(char *buf, const char *fmt, va_list args)
|
||||
{
|
||||
return _vsnprintf(buf,MAXLONG,fmt,args);
|
||||
}
|
||||
|
||||
/* EOF */
|
Loading…
Reference in a new issue