core: add a preliminary core commandline parser component. please note that temporarily linux cli may depend on gtk--we should change it to a bare glibc dependency.
win32: add glib. this is a rather behemoth checkin, but I think it will be worth it, as it is a necessary step for unification of some of the linux and windows parts.
This commit is contained in:
parent
7b4804b878
commit
2d622d98e0
|
@ -1,5 +1,7 @@
|
|||
include $(top_srcdir)/src/desmume.mk
|
||||
|
||||
AM_CPPFLAGS += $(SDL_CFLAGS) $(GTK_CFLAGS) $(GTHREAD_CFLAGS)
|
||||
|
||||
EXTRA_DIST = build.bat instruction_tabdef.inc thumb_tabdef.inc fs-linux.cpp fs-windows.cpp \
|
||||
matrix_sse2-x64.asm matrix_sse2-x86.asm
|
||||
if HAVE_GDB_STUB
|
||||
|
@ -14,8 +16,8 @@ libdesmume_a_SOURCES = \
|
|||
arm_instructions.cpp arm_instructions.h \
|
||||
bios.cpp bios.h bits.h cp15.cpp cp15.h \
|
||||
cflash.cpp cflash.h fs.h \
|
||||
common.cpp common.h \
|
||||
debug.cpp debug.h \
|
||||
common.cpp common.h commandline.h commandline.cpp \
|
||||
debug.cpp debug.h driver.h \
|
||||
Disassembler.cpp Disassembler.h \
|
||||
dscard.h fat.h FIFO.cpp FIFO.h \
|
||||
GPU_osd.cpp GPU_osd.h \
|
||||
|
|
|
@ -118,7 +118,7 @@ std::string RomName = ""; //Stores the name of the Rom currently loaded in me
|
|||
* Known Usage:
|
||||
* LoadRom
|
||||
**/
|
||||
void SetRomName(char *filename)
|
||||
void SetRomName(const char *filename)
|
||||
{
|
||||
std::string str = filename;
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
extern u8 gba_header_data_0x04[156];
|
||||
const char* GetRomName(); //adelikat: return the name of the Rom currently loaded
|
||||
void SetRomName(char *filename);
|
||||
void SetRomName(const char *filename);
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
|
|
|
@ -45,6 +45,8 @@
|
|||
#include "dTool.h"
|
||||
#include "desmume_config.h"
|
||||
|
||||
#include "commandline.h"
|
||||
|
||||
#ifdef GDB_STUB
|
||||
#include "gdbstub.h"
|
||||
#endif
|
||||
|
@ -327,9 +329,9 @@ static u16 Cur_Keypad = 0;
|
|||
static u16 gdk_shift_pressed = 0;
|
||||
u16 Keypad_Temp[NB_KEYS];
|
||||
|
||||
struct configured_features {
|
||||
int load_slot;
|
||||
|
||||
class configured_features : public CommandLine
|
||||
{
|
||||
public:
|
||||
int disable_sound;
|
||||
int engine_3d;
|
||||
int disable_limiter;
|
||||
|
@ -340,7 +342,6 @@ struct configured_features {
|
|||
|
||||
int firmware_language;
|
||||
|
||||
const char *nds_file;
|
||||
const char *cflash_disk_image_file;
|
||||
#ifdef HAVE_TIMEOUT
|
||||
int timeout;
|
||||
|
@ -350,8 +351,6 @@ struct configured_features {
|
|||
static void
|
||||
init_configured_features( struct configured_features *config)
|
||||
{
|
||||
config->load_slot = 0;
|
||||
|
||||
config->arm9_gdb_port = 0;
|
||||
config->arm7_gdb_port = 0;
|
||||
|
||||
|
@ -361,7 +360,6 @@ init_configured_features( struct configured_features *config)
|
|||
|
||||
config->disable_limiter = 0;
|
||||
|
||||
config->nds_file = NULL;
|
||||
config->savetype = 0;
|
||||
|
||||
config->cflash_disk_image_file = NULL;
|
||||
|
@ -379,7 +377,6 @@ fill_configured_features( struct configured_features *config,
|
|||
int argc, char ** argv)
|
||||
{
|
||||
GOptionEntry options[] = {
|
||||
{ "load-slot", 0, 0, G_OPTION_ARG_INT, &config->load_slot, "Loads savegame from slot NUM", "NUM"},
|
||||
{ "disable-sound", 0, 0, G_OPTION_ARG_NONE, &config->disable_sound, "Disables the sound emulation", NULL},
|
||||
{ "disable-limiter", 0, 0, G_OPTION_ARG_NONE, &config->disable_limiter, "Disables the 60fps limiter", NULL},
|
||||
{ "3d-engine", 0, 0, G_OPTION_ARG_INT, &config->engine_3d, "Select 3d rendering engine. Available engines:\n"
|
||||
|
@ -416,29 +413,18 @@ fill_configured_features( struct configured_features *config,
|
|||
#endif
|
||||
{ NULL }
|
||||
};
|
||||
GOptionContext *ctx;
|
||||
GError *error = NULL;
|
||||
|
||||
ctx = g_option_context_new ("");
|
||||
g_option_context_add_main_entries (ctx, options, "options");
|
||||
g_option_context_add_group (ctx, gtk_get_option_group (TRUE));
|
||||
g_option_context_parse (ctx, &argc, &argv, &error);
|
||||
g_option_context_free (ctx);
|
||||
config->loadCommonOptions();
|
||||
g_option_context_add_main_entries (config->ctx, options, "options");
|
||||
g_option_context_add_group (config->ctx, gtk_get_option_group (TRUE));
|
||||
config->parse(argc,argv);
|
||||
|
||||
if (error) {
|
||||
g_printerr("Error parsing command line arguments: %s\n", error->message);
|
||||
g_error_free (error);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (argc == 2)
|
||||
config->nds_file = argv[1];
|
||||
if (argc > 2)
|
||||
if(!config->validate())
|
||||
goto error;
|
||||
|
||||
if (config->savetype < 0 || config->savetype > 6) {
|
||||
g_printerr("Accepted savetypes are from 0 to 6.\n");
|
||||
goto error;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (config->firmware_language < -1 || config->firmware_language > 5) {
|
||||
|
@ -446,10 +432,6 @@ fill_configured_features( struct configured_features *config,
|
|||
goto error;
|
||||
}
|
||||
|
||||
if (config->load_slot < 0 || config->load_slot > 10) {
|
||||
g_printerr("I only know how to load from slots 1-10, 0 means 'do not load savegame' and is default\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (config->engine_3d != 0 && config->engine_3d != 1
|
||||
#if defined(HAVE_LIBOSMESA)
|
||||
|
@ -479,8 +461,8 @@ fill_configured_features( struct configured_features *config,
|
|||
return 1;
|
||||
|
||||
error:
|
||||
g_printerr("USAGE: %s [options] [nds-file]\n", argv[0]);
|
||||
g_printerr("USAGE: %s --help - for help\n", argv[0]);
|
||||
config->errorHelp(argv[0]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1808,8 +1790,8 @@ common_gtk_main( struct configured_features *my_config)
|
|||
mmu_select_savetype(my_config->savetype, &backupmemorytype, &backupmemorysize);
|
||||
|
||||
/* Command line arg */
|
||||
if( my_config->nds_file != NULL) {
|
||||
if(Open( my_config->nds_file, bad_glob_cflash_disk_image_file) >= 0) {
|
||||
if( my_config->nds_file != "") {
|
||||
if(Open( my_config->nds_file.c_str(), bad_glob_cflash_disk_image_file) >= 0) {
|
||||
if(my_config->load_slot){
|
||||
loadstate_slot(my_config->load_slot);
|
||||
}
|
||||
|
@ -1820,7 +1802,7 @@ common_gtk_main( struct configured_features *my_config)
|
|||
GTK_DIALOG_MODAL,
|
||||
GTK_MESSAGE_INFO,
|
||||
GTK_BUTTONS_OK,
|
||||
"Unable to load :\n%s", my_config->nds_file);
|
||||
"Unable to load :\n%s", my_config->nds_file.c_str());
|
||||
gtk_dialog_run(GTK_DIALOG(pDialog));
|
||||
gtk_widget_destroy(pDialog);
|
||||
}
|
||||
|
@ -1870,7 +1852,7 @@ common_gtk_main( struct configured_features *my_config)
|
|||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
struct configured_features my_config;
|
||||
configured_features my_config;
|
||||
|
||||
init_configured_features( &my_config);
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
FavorSizeOrSpeed="0"
|
||||
EnableFiberSafeOptimizations="false"
|
||||
WholeProgramOptimization="false"
|
||||
AdditionalIncludeDirectories=".;..;.\zlib123;.\zziplib;.\winpcap;userconfig;defaultconfig"
|
||||
AdditionalIncludeDirectories=".;..;"glib-2.20.1\build";"glib-2.20.1\build\glib";.\zlib123;.\zziplib;.\winpcap;userconfig;defaultconfig"
|
||||
PreprocessorDefinitions="DEBUG;_CRT_SECURE_NO_DEPRECATE;WIN32;SPU_INTERPOLATE;HAVE_LIBZ;HAVE_LIBZZIP;NOMINMAX;DEBUG;EXPERIMENTAL_WIFI"
|
||||
ExceptionHandling="1"
|
||||
BasicRuntimeChecks="0"
|
||||
|
@ -74,12 +74,13 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="vfw32.lib winmm.lib opengl32.lib glu32.lib ws2_32.lib user32.lib gdi32.lib directx\dxguid.lib shell32.lib comdlg32.lib directx\dxerr8.lib directx\dsound.lib directx\dinput8.lib directx\ddraw.lib zlib-2005-x32.lib zziplib-2005-x32.lib shlwapi.lib winpcap\wpcap.lib"
|
||||
AdditionalDependencies="glib-2.20.1-x86.lib vfw32.lib winmm.lib opengl32.lib glu32.lib ws2_32.lib user32.lib gdi32.lib directx\dxguid.lib shell32.lib comdlg32.lib directx\dxerr8.lib directx\dsound.lib directx\dinput8.lib directx\ddraw.lib zlib-2005-x32.lib zziplib-2005-x32.lib shlwapi.lib winpcap\wpcap.lib"
|
||||
OutputFile="$(OutDir)\$(ProjectName)_debug.exe"
|
||||
AdditionalLibraryDirectories=".\zlib123;.\zziplib"
|
||||
AdditionalLibraryDirectories=".\zlib123;.\zziplib;glib-2.20.1\lib"
|
||||
DelayLoadDLLs="wpcap.dll"
|
||||
GenerateDebugInformation="true"
|
||||
GenerateMapFile="true"
|
||||
OptimizeReferences="2"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
|
@ -142,7 +143,7 @@
|
|||
OmitFramePointers="true"
|
||||
EnableFiberSafeOptimizations="true"
|
||||
WholeProgramOptimization="true"
|
||||
AdditionalIncludeDirectories=".;..;.\zlib123;.\zziplib;.\winpcap;userconfig;defaultconfig"
|
||||
AdditionalIncludeDirectories=".;..;"glib-2.20.1\build";"glib-2.20.1\build\glib";.\zlib123;.\zziplib;.\winpcap;userconfig;defaultconfig"
|
||||
PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;WIN32;HAVE_LIBZ;HAVE_LIBZZIP;SPU_INTERPOLATE;NOMINMAX;NDEBUG;RELEASE;EXPERIMENTAL_WIFI"
|
||||
StringPooling="true"
|
||||
ExceptionHandling="1"
|
||||
|
@ -169,9 +170,9 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="vfw32.lib winmm.lib opengl32.lib glu32.lib ws2_32.lib user32.lib gdi32.lib directx\dxguid.lib shell32.lib comdlg32.lib directx\dxerr8.lib directx\dsound.lib directx\dinput8.lib directx\ddraw.lib zlib-2005-x32.lib zziplib-2005-x32.lib shlwapi.lib winpcap\wpcap.lib"
|
||||
AdditionalDependencies="glib-2.20.1-x86.lib vfw32.lib winmm.lib opengl32.lib glu32.lib ws2_32.lib user32.lib gdi32.lib directx\dxguid.lib shell32.lib comdlg32.lib directx\dxerr8.lib directx\dsound.lib directx\dinput8.lib directx\ddraw.lib zlib-2005-x32.lib zziplib-2005-x32.lib shlwapi.lib winpcap\wpcap.lib"
|
||||
OutputFile="$(OutDir)\$(ProjectName)_release.exe"
|
||||
AdditionalLibraryDirectories=".\zlib123;.\zziplib"
|
||||
AdditionalLibraryDirectories=".\zlib123;.\zziplib;glib-2.20.1\lib"
|
||||
DelayLoadDLLs="wpcap.dll"
|
||||
GenerateDebugInformation="true"
|
||||
GenerateMapFile="true"
|
||||
|
@ -239,7 +240,7 @@
|
|||
OmitFramePointers="true"
|
||||
EnableFiberSafeOptimizations="true"
|
||||
WholeProgramOptimization="false"
|
||||
AdditionalIncludeDirectories=".;..;.\zlib123;.\zziplib;.\winpcap;userconfig;defaultconfig"
|
||||
AdditionalIncludeDirectories=".;..;"glib-2.20.1\build";"glib-2.20.1\build\glib";.\zlib123;.\zziplib;.\winpcap;userconfig;defaultconfig"
|
||||
PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;WIN32;HAVE_LIBZ;HAVE_LIBZZIP;SPU_INTERPOLATE;NOMINMAX;NDEBUG;RELEASE;EXPERIMENTAL_WIFI"
|
||||
StringPooling="true"
|
||||
ExceptionHandling="1"
|
||||
|
@ -266,12 +267,13 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="vfw32.lib winmm.lib opengl32.lib glu32.lib ws2_32.lib user32.lib gdi32.lib directx\dxguid.lib shell32.lib comdlg32.lib directx\dxerr8.lib directx\dsound.lib directx\dinput8.lib directx\ddraw.lib zlib-2005-x32.lib zziplib-2005-x32.lib shlwapi.lib winpcap\wpcap.lib"
|
||||
AdditionalDependencies="glib-2.20.1-x86.lib vfw32.lib winmm.lib opengl32.lib glu32.lib ws2_32.lib user32.lib gdi32.lib directx\dxguid.lib shell32.lib comdlg32.lib directx\dxerr8.lib directx\dsound.lib directx\dinput8.lib directx\ddraw.lib zlib-2005-x32.lib zziplib-2005-x32.lib shlwapi.lib winpcap\wpcap.lib"
|
||||
OutputFile="$(OutDir)\$(ProjectName)_releaseFastBuild.exe"
|
||||
AdditionalLibraryDirectories=".\zlib123;.\zziplib"
|
||||
AdditionalLibraryDirectories=".\zlib123;.\zziplib;glib-2.20.1\lib"
|
||||
DelayLoadDLLs="wpcap.dll"
|
||||
GenerateDebugInformation="true"
|
||||
GenerateMapFile="true"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="0"
|
||||
OptimizeForWindows98="1"
|
||||
LinkTimeCodeGeneration="0"
|
||||
|
@ -785,6 +787,22 @@
|
|||
RelativePath="..\cheatSystem.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\commandline.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release FastBuild|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
CallingConvention="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\commandline.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\common.cpp"
|
||||
>
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
FavorSizeOrSpeed="0"
|
||||
EnableFiberSafeOptimizations="false"
|
||||
WholeProgramOptimization="false"
|
||||
AdditionalIncludeDirectories=".;..;.\zlib123;.\zziplib;.\winpcap;userconfig;defaultconfig"
|
||||
AdditionalIncludeDirectories=".;..;"glib-2.20.1\build";"glib-2.20.1\build\glib";.\zlib123;.\zziplib;.\winpcap;userconfig;defaultconfig"
|
||||
PreprocessorDefinitions="DEBUG;_CRT_SECURE_NO_DEPRECATE;WIN32;BETA_VERSION;SPU_INTERPOLATE;NOMINMAX;EXPERIMENTAL_WIFI;HAVE_LIBZZIP"
|
||||
ExceptionHandling="1"
|
||||
BasicRuntimeChecks="0"
|
||||
|
@ -73,9 +73,9 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="vfw32.lib winmm.lib comctl32.lib opengl32.lib glu32.lib ws2_32.lib user32.lib gdi32.lib directx\dxguid.lib shell32.lib comdlg32.lib directx\dxerr8.lib directx\dsound.lib directx\dinput8.lib directx\ddraw.lib shlwapi.lib winpcap\wpcap.lib zlib-2008-x32.lib zziplib-2008-x32.lib"
|
||||
AdditionalDependencies="glib-2.20.1-x86.lib vfw32.lib winmm.lib comctl32.lib opengl32.lib glu32.lib ws2_32.lib user32.lib gdi32.lib directx\dxguid.lib shell32.lib comdlg32.lib directx\dxerr8.lib directx\dsound.lib directx\dinput8.lib directx\ddraw.lib shlwapi.lib winpcap\wpcap.lib zlib-2008-x32.lib zziplib-2008-x32.lib"
|
||||
OutputFile="$(OutDir)\$(ProjectName)_debug.exe"
|
||||
AdditionalLibraryDirectories=".\zlib123;.\zziplib;.\winpcap"
|
||||
AdditionalLibraryDirectories=".\zlib123;.\zziplib;.\winpcap;glib-2.20.1\lib"
|
||||
DelayLoadDLLs="wpcap.dll"
|
||||
GenerateDebugInformation="true"
|
||||
GenerateMapFile="true"
|
||||
|
@ -140,7 +140,7 @@
|
|||
OmitFramePointers="true"
|
||||
EnableFiberSafeOptimizations="true"
|
||||
WholeProgramOptimization="true"
|
||||
AdditionalIncludeDirectories=".;..;.\zlib123;.\zziplib;.\winpcap;userconfig;defaultconfig"
|
||||
AdditionalIncludeDirectories=".;..;"glib-2.20.1\build";"glib-2.20.1\build\glib";.\zlib123;.\zziplib;.\winpcap;userconfig;defaultconfig"
|
||||
PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;WIN32;HAVE_LIBZ;HAVE_LIBZZIP;SSE2;SPU_INTERPOLATE;NOMINMAX;RELEASE;EXPERIMENTAL_WIFI;NDEBUG"
|
||||
StringPooling="true"
|
||||
ExceptionHandling="1"
|
||||
|
@ -164,11 +164,12 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="vfw32.lib winmm.lib comctl32.lib opengl32.lib glu32.lib ws2_32.lib user32.lib gdi32.lib directx\dxguid.lib shell32.lib comdlg32.lib directx\dxerr8.lib directx\dsound.lib directx\dinput8.lib directx\ddraw.lib shlwapi.lib winpcap\wpcap.lib zlib-2008-x32.lib zziplib-2008-x32.lib"
|
||||
AdditionalDependencies="glib-2.20.1-x86.lib vfw32.lib winmm.lib comctl32.lib opengl32.lib glu32.lib ws2_32.lib user32.lib gdi32.lib directx\dxguid.lib shell32.lib comdlg32.lib directx\dxerr8.lib directx\dsound.lib directx\dinput8.lib directx\ddraw.lib shlwapi.lib winpcap\wpcap.lib zlib-2008-x32.lib zziplib-2008-x32.lib"
|
||||
OutputFile="$(OutDir)\$(ProjectName)_sse2.exe"
|
||||
AdditionalLibraryDirectories=".\zlib123;.\zziplib;.\winpcap"
|
||||
DelayLoadDLLs="wpcap.dll"
|
||||
GenerateDebugInformation="true"
|
||||
OptimizeReferences="2"
|
||||
RandomizedBaseAddress="1"
|
||||
DataExecutionPrevention="0"
|
||||
Profile="false"
|
||||
|
@ -231,7 +232,7 @@
|
|||
OmitFramePointers="true"
|
||||
EnableFiberSafeOptimizations="true"
|
||||
WholeProgramOptimization="false"
|
||||
AdditionalIncludeDirectories=".;..;.\zlib123;.\zziplib;.\winpcap;userconfig;defaultconfig"
|
||||
AdditionalIncludeDirectories=".;..;"glib-2.20.1\build";"glib-2.20.1\build\glib";.\zlib123;.\zziplib;.\winpcap;userconfig;defaultconfig"
|
||||
PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;WIN32;HAVE_LIBZ;HAVE_LIBZZIP;SSE2;SPU_INTERPOLATE;NOMINMAX;RELEASE;EXPERIMENTAL_WIFI;NDEBUG"
|
||||
StringPooling="true"
|
||||
ExceptionHandling="1"
|
||||
|
@ -255,11 +256,12 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="vfw32.lib winmm.lib comctl32.lib opengl32.lib glu32.lib ws2_32.lib user32.lib gdi32.lib directx\dxguid.lib shell32.lib comdlg32.lib directx\dxerr8.lib directx\dsound.lib directx\dinput8.lib directx\ddraw.lib shlwapi.lib winpcap\wpcap.lib zlib-2008-x32.lib zziplib-2008-x32.lib"
|
||||
AdditionalDependencies="glib-2.20.1-x86.lib vfw32.lib winmm.lib comctl32.lib opengl32.lib glu32.lib ws2_32.lib user32.lib gdi32.lib directx\dxguid.lib shell32.lib comdlg32.lib directx\dxerr8.lib directx\dsound.lib directx\dinput8.lib directx\ddraw.lib shlwapi.lib winpcap\wpcap.lib zlib-2008-x32.lib zziplib-2008-x32.lib"
|
||||
OutputFile="$(OutDir)\$(ProjectName)_sse2.exe"
|
||||
AdditionalLibraryDirectories=".\zlib123;.\zziplib;.\winpcap"
|
||||
AdditionalLibraryDirectories=".\zlib123;.\zziplib;.\winpcap;glib-2.20.1\lib"
|
||||
DelayLoadDLLs="wpcap.dll"
|
||||
GenerateDebugInformation="true"
|
||||
OptimizeReferences="2"
|
||||
LinkTimeCodeGeneration="0"
|
||||
RandomizedBaseAddress="1"
|
||||
DataExecutionPrevention="0"
|
||||
|
@ -324,6 +326,18 @@
|
|||
RelativePath="..\cheatSystem.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\commandline.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Release FastBuild|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
CallingConvention="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\common.cpp"
|
||||
>
|
||||
|
@ -946,6 +960,10 @@
|
|||
RelativePath="..\cheatSystem.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\commandline.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\common.h"
|
||||
>
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Copyright (C) 2008 Tor Lillqvist
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; see the file COPYING.LIB.txt. If
|
||||
* not, write to the Free Software Foundation, Inc., 51 Franklin
|
||||
* Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef _LIBINTL_H
|
||||
#define _LIBINTL_H 1
|
||||
|
||||
#include <locale.h>
|
||||
|
||||
#ifndef LC_MESSAGES
|
||||
# define LC_MESSAGES 1729 /* Use same value as in GNU gettext */
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern char *gettext (const char *msgid);
|
||||
|
||||
extern char *dgettext (const char *domainname,
|
||||
const char *msgid);
|
||||
|
||||
extern char *dcgettext (const char *domainname,
|
||||
const char *msgid,
|
||||
int category);
|
||||
|
||||
extern char *ngettext (const char *msgid1,
|
||||
const char *msgid2,
|
||||
unsigned long int n);
|
||||
|
||||
extern char *dngettext (const char *domainname,
|
||||
const char *msgid1,
|
||||
const char *msgid2,
|
||||
unsigned long int n);
|
||||
|
||||
extern char *dcngettext (const char *domainname,
|
||||
const char *msgid1,
|
||||
const char *msgid2,
|
||||
unsigned long int n,
|
||||
int category);
|
||||
|
||||
extern char *textdomain (const char *domainname);
|
||||
|
||||
extern char *bindtextdomain (const char *domainname,
|
||||
const char *dirname);
|
||||
|
||||
extern char *bind_textdomain_codeset (const char *domainname,
|
||||
const char *codeset);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _LIBINTL_H */
|
|
@ -0,0 +1,2 @@
|
|||
This is dirent from mingw-runtime-3.3, separated for MSVC user's
|
||||
benefit.
|
|
@ -0,0 +1,341 @@
|
|||
/*
|
||||
* dirent.c
|
||||
* This file has no copyright assigned and is placed in the Public Domain.
|
||||
* This file is a part of the mingw-runtime package.
|
||||
* No warranty is given; refer to the file DISCLAIMER within the package.
|
||||
*
|
||||
* Derived from DIRLIB.C by Matt J. Weinstein
|
||||
* This note appears in the DIRLIB.H
|
||||
* DIRLIB.H by M. J. Weinstein Released to public domain 1-Jan-89
|
||||
*
|
||||
* Updated by Jeremy Bettis <jeremy@hksys.com>
|
||||
* Significantly revised and rewinddir, seekdir and telldir added by Colin
|
||||
* Peters <colin@fu.is.saga-u.ac.jp>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <io.h>
|
||||
#include <direct.h>
|
||||
|
||||
#include "dirent.h"
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h> /* for GetFileAttributes */
|
||||
|
||||
#include <tchar.h>
|
||||
|
||||
#ifdef _UNICODE
|
||||
#define _tdirent _wdirent
|
||||
#define _TDIR _WDIR
|
||||
#define _topendir _wopendir
|
||||
#define _tclosedir _wclosedir
|
||||
#define _treaddir _wreaddir
|
||||
#define _trewinddir _wrewinddir
|
||||
#define _ttelldir _wtelldir
|
||||
#define _tseekdir _wseekdir
|
||||
#else
|
||||
#define _tdirent dirent
|
||||
#define _TDIR DIR
|
||||
#define _topendir opendir
|
||||
#define _tclosedir closedir
|
||||
#define _treaddir readdir
|
||||
#define _trewinddir rewinddir
|
||||
#define _ttelldir telldir
|
||||
#define _tseekdir seekdir
|
||||
#endif
|
||||
|
||||
#define SUFFIX _T("*")
|
||||
#define SLASH _T("\\")
|
||||
|
||||
|
||||
/*
|
||||
* opendir
|
||||
*
|
||||
* Returns a pointer to a DIR structure appropriately filled in to begin
|
||||
* searching a directory.
|
||||
*/
|
||||
_TDIR *
|
||||
_topendir (const _TCHAR *szPath)
|
||||
{
|
||||
_TDIR *nd;
|
||||
unsigned int rc;
|
||||
_TCHAR szFullPath[MAX_PATH];
|
||||
|
||||
errno = 0;
|
||||
|
||||
if (!szPath)
|
||||
{
|
||||
errno = EFAULT;
|
||||
return (_TDIR *) 0;
|
||||
}
|
||||
|
||||
if (szPath[0] == _T('\0'))
|
||||
{
|
||||
errno = ENOTDIR;
|
||||
return (_TDIR *) 0;
|
||||
}
|
||||
|
||||
/* Attempt to determine if the given path really is a directory. */
|
||||
rc = GetFileAttributes (szPath);
|
||||
if (rc == (unsigned int)-1)
|
||||
{
|
||||
/* call GetLastError for more error info */
|
||||
errno = ENOENT;
|
||||
return (_TDIR *) 0;
|
||||
}
|
||||
if (!(rc & FILE_ATTRIBUTE_DIRECTORY))
|
||||
{
|
||||
/* Error, entry exists but not a directory. */
|
||||
errno = ENOTDIR;
|
||||
return (_TDIR *) 0;
|
||||
}
|
||||
|
||||
/* Make an absolute pathname. */
|
||||
_tfullpath (szFullPath, szPath, MAX_PATH);
|
||||
|
||||
/* Allocate enough space to store DIR structure and the complete
|
||||
* directory path given. */
|
||||
nd = (_TDIR *) malloc (sizeof (_TDIR) + (_tcslen(szFullPath) + _tcslen (SLASH) +
|
||||
_tcslen(SUFFIX) + 1) * sizeof(_TCHAR));
|
||||
|
||||
if (!nd)
|
||||
{
|
||||
/* Error, out of memory. */
|
||||
errno = ENOMEM;
|
||||
return (_TDIR *) 0;
|
||||
}
|
||||
|
||||
/* Create the search expression. */
|
||||
_tcscpy (nd->dd_name, szFullPath);
|
||||
|
||||
/* Add on a slash if the path does not end with one. */
|
||||
if (nd->dd_name[0] != _T('\0') &&
|
||||
nd->dd_name[_tcslen (nd->dd_name) - 1] != _T('/') &&
|
||||
nd->dd_name[_tcslen (nd->dd_name) - 1] != _T('\\'))
|
||||
{
|
||||
_tcscat (nd->dd_name, SLASH);
|
||||
}
|
||||
|
||||
/* Add on the search pattern */
|
||||
_tcscat (nd->dd_name, SUFFIX);
|
||||
|
||||
/* Initialize handle to -1 so that a premature closedir doesn't try
|
||||
* to call _findclose on it. */
|
||||
nd->dd_handle = -1;
|
||||
|
||||
/* Initialize the status. */
|
||||
nd->dd_stat = 0;
|
||||
|
||||
/* Initialize the dirent structure. ino and reclen are invalid under
|
||||
* Win32, and name simply points at the appropriate part of the
|
||||
* findfirst_t structure. */
|
||||
nd->dd_dir.d_ino = 0;
|
||||
nd->dd_dir.d_reclen = 0;
|
||||
nd->dd_dir.d_namlen = 0;
|
||||
memset (nd->dd_dir.d_name, 0, FILENAME_MAX);
|
||||
|
||||
return nd;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* readdir
|
||||
*
|
||||
* Return a pointer to a dirent structure filled with the information on the
|
||||
* next entry in the directory.
|
||||
*/
|
||||
struct _tdirent *
|
||||
_treaddir (_TDIR * dirp)
|
||||
{
|
||||
errno = 0;
|
||||
|
||||
/* Check for valid DIR struct. */
|
||||
if (!dirp)
|
||||
{
|
||||
errno = EFAULT;
|
||||
return (struct _tdirent *) 0;
|
||||
}
|
||||
|
||||
if (dirp->dd_stat < 0)
|
||||
{
|
||||
/* We have already returned all files in the directory
|
||||
* (or the structure has an invalid dd_stat). */
|
||||
return (struct _tdirent *) 0;
|
||||
}
|
||||
else if (dirp->dd_stat == 0)
|
||||
{
|
||||
/* We haven't started the search yet. */
|
||||
/* Start the search */
|
||||
dirp->dd_handle = _tfindfirst (dirp->dd_name, &(dirp->dd_dta));
|
||||
|
||||
if (dirp->dd_handle == -1)
|
||||
{
|
||||
/* Whoops! Seems there are no files in that
|
||||
* directory. */
|
||||
dirp->dd_stat = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
dirp->dd_stat = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Get the next search entry. */
|
||||
if (_tfindnext (dirp->dd_handle, &(dirp->dd_dta)))
|
||||
{
|
||||
/* We are off the end or otherwise error.
|
||||
_findnext sets errno to ENOENT if no more file
|
||||
Undo this. */
|
||||
DWORD winerr = GetLastError();
|
||||
if (winerr == ERROR_NO_MORE_FILES)
|
||||
errno = 0;
|
||||
_findclose (dirp->dd_handle);
|
||||
dirp->dd_handle = -1;
|
||||
dirp->dd_stat = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Update the status to indicate the correct
|
||||
* number. */
|
||||
dirp->dd_stat++;
|
||||
}
|
||||
}
|
||||
|
||||
if (dirp->dd_stat > 0)
|
||||
{
|
||||
/* Successfully got an entry. Everything about the file is
|
||||
* already appropriately filled in except the length of the
|
||||
* file name. */
|
||||
dirp->dd_dir.d_namlen = _tcslen (dirp->dd_dta.name);
|
||||
_tcscpy (dirp->dd_dir.d_name, dirp->dd_dta.name);
|
||||
return &dirp->dd_dir;
|
||||
}
|
||||
|
||||
return (struct _tdirent *) 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* closedir
|
||||
*
|
||||
* Frees up resources allocated by opendir.
|
||||
*/
|
||||
int
|
||||
_tclosedir (_TDIR * dirp)
|
||||
{
|
||||
int rc;
|
||||
|
||||
errno = 0;
|
||||
rc = 0;
|
||||
|
||||
if (!dirp)
|
||||
{
|
||||
errno = EFAULT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dirp->dd_handle != -1)
|
||||
{
|
||||
rc = _findclose (dirp->dd_handle);
|
||||
}
|
||||
|
||||
/* Delete the dir structure. */
|
||||
free (dirp);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
* rewinddir
|
||||
*
|
||||
* Return to the beginning of the directory "stream". We simply call findclose
|
||||
* and then reset things like an opendir.
|
||||
*/
|
||||
void
|
||||
_trewinddir (_TDIR * dirp)
|
||||
{
|
||||
errno = 0;
|
||||
|
||||
if (!dirp)
|
||||
{
|
||||
errno = EFAULT;
|
||||
return;
|
||||
}
|
||||
|
||||
if (dirp->dd_handle != -1)
|
||||
{
|
||||
_findclose (dirp->dd_handle);
|
||||
}
|
||||
|
||||
dirp->dd_handle = -1;
|
||||
dirp->dd_stat = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* telldir
|
||||
*
|
||||
* Returns the "position" in the "directory stream" which can be used with
|
||||
* seekdir to go back to an old entry. We simply return the value in stat.
|
||||
*/
|
||||
long
|
||||
_ttelldir (_TDIR * dirp)
|
||||
{
|
||||
errno = 0;
|
||||
|
||||
if (!dirp)
|
||||
{
|
||||
errno = EFAULT;
|
||||
return -1;
|
||||
}
|
||||
return dirp->dd_stat;
|
||||
}
|
||||
|
||||
/*
|
||||
* seekdir
|
||||
*
|
||||
* Seek to an entry previously returned by telldir. We rewind the directory
|
||||
* and call readdir repeatedly until either dd_stat is the position number
|
||||
* or -1 (off the end). This is not perfect, in that the directory may
|
||||
* have changed while we weren't looking. But that is probably the case with
|
||||
* any such system.
|
||||
*/
|
||||
void
|
||||
_tseekdir (_TDIR * dirp, long lPos)
|
||||
{
|
||||
errno = 0;
|
||||
|
||||
if (!dirp)
|
||||
{
|
||||
errno = EFAULT;
|
||||
return;
|
||||
}
|
||||
|
||||
if (lPos < -1)
|
||||
{
|
||||
/* Seeking to an invalid position. */
|
||||
errno = EINVAL;
|
||||
return;
|
||||
}
|
||||
else if (lPos == -1)
|
||||
{
|
||||
/* Seek past end. */
|
||||
if (dirp->dd_handle != -1)
|
||||
{
|
||||
_findclose (dirp->dd_handle);
|
||||
}
|
||||
dirp->dd_handle = -1;
|
||||
dirp->dd_stat = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Rewind and read forward to the appropriate index. */
|
||||
_trewinddir (dirp);
|
||||
|
||||
while ((dirp->dd_stat < lPos) && _treaddir (dirp))
|
||||
;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,127 @@
|
|||
/*
|
||||
* DIRENT.H (formerly DIRLIB.H)
|
||||
* This file has no copyright assigned and is placed in the Public Domain.
|
||||
* This file is a part of the mingw-runtime package.
|
||||
* No warranty is given; refer to the file DISCLAIMER within the package.
|
||||
*
|
||||
*/
|
||||
#ifndef _DIRENT_H_
|
||||
#define _DIRENT_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <io.h>
|
||||
|
||||
#ifndef RC_INVOKED
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct dirent
|
||||
{
|
||||
long d_ino; /* Always zero. */
|
||||
unsigned short d_reclen; /* Always zero. */
|
||||
unsigned short d_namlen; /* Length of name in d_name. */
|
||||
char d_name[FILENAME_MAX]; /* File name. */
|
||||
};
|
||||
|
||||
#ifdef _WIN64
|
||||
#define INTPTR __int64
|
||||
#else
|
||||
#define INTPTR long
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This is an internal data structure. Good programmers will not use it
|
||||
* except as an argument to one of the functions below.
|
||||
* dd_stat field is now int (was short in older versions).
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/* disk transfer area for this dir */
|
||||
struct _finddata_t dd_dta;
|
||||
|
||||
/* dirent struct to return from dir (NOTE: this makes this thread
|
||||
* safe as long as only one thread uses a particular DIR struct at
|
||||
* a time) */
|
||||
struct dirent dd_dir;
|
||||
|
||||
/* _findnext handle */
|
||||
INTPTR dd_handle;
|
||||
|
||||
/*
|
||||
* Status of search:
|
||||
* 0 = not started yet (next entry to read is first entry)
|
||||
* -1 = off the end
|
||||
* positive = 0 based index of next entry
|
||||
*/
|
||||
int dd_stat;
|
||||
|
||||
/* given path for dir with search pattern (struct is extended) */
|
||||
char dd_name[1];
|
||||
} DIR;
|
||||
|
||||
DIR* __cdecl opendir (const char*);
|
||||
struct dirent* __cdecl readdir (DIR*);
|
||||
int __cdecl closedir (DIR*);
|
||||
void __cdecl rewinddir (DIR*);
|
||||
long __cdecl telldir (DIR*);
|
||||
void __cdecl seekdir (DIR*, long);
|
||||
|
||||
|
||||
/* wide char versions */
|
||||
|
||||
struct _wdirent
|
||||
{
|
||||
long d_ino; /* Always zero. */
|
||||
unsigned short d_reclen; /* Always zero. */
|
||||
unsigned short d_namlen; /* Length of name in d_name. */
|
||||
wchar_t d_name[FILENAME_MAX]; /* File name. */
|
||||
};
|
||||
|
||||
/*
|
||||
* This is an internal data structure. Good programmers will not use it
|
||||
* except as an argument to one of the functions below.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/* disk transfer area for this dir */
|
||||
struct _wfinddata_t dd_dta;
|
||||
|
||||
/* dirent struct to return from dir (NOTE: this makes this thread
|
||||
* safe as long as only one thread uses a particular DIR struct at
|
||||
* a time) */
|
||||
struct _wdirent dd_dir;
|
||||
|
||||
/* _findnext handle */
|
||||
INTPTR dd_handle;
|
||||
|
||||
/*
|
||||
* Status of search:
|
||||
* 0 = not started yet (next entry to read is first entry)
|
||||
* -1 = off the end
|
||||
* positive = 0 based index of next entry
|
||||
*/
|
||||
int dd_stat;
|
||||
|
||||
/* given path for dir with search pattern (struct is extended) */
|
||||
wchar_t dd_name[1];
|
||||
} _WDIR;
|
||||
|
||||
|
||||
|
||||
_WDIR* __cdecl _wopendir (const wchar_t*);
|
||||
struct _wdirent* __cdecl _wreaddir (_WDIR*);
|
||||
int __cdecl _wclosedir (_WDIR*);
|
||||
void __cdecl _wrewinddir (_WDIR*);
|
||||
long __cdecl _wtelldir (_WDIR*);
|
||||
void __cdecl _wseekdir (_WDIR*, long);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* Not RC_INVOKED */
|
||||
|
||||
#endif /* Not _DIRENT_H_ */
|
|
@ -0,0 +1,3 @@
|
|||
#define _UNICODE 1
|
||||
#define UNICODE 1
|
||||
#include "dirent.c"
|
|
@ -0,0 +1,742 @@
|
|||
/* config.h.win32.in Merged from two versions generated by configure for gcc and MSVC. */
|
||||
/* config.h. Generated by configure. */
|
||||
/* config.h.in. Generated from configure.in by autoheader. */
|
||||
|
||||
/* define if asm blocks can use numeric local labels */
|
||||
/* #undef ASM_NUMERIC_LABELS */
|
||||
|
||||
/* poll doesn't work on devices */
|
||||
#define BROKEN_POLL 1
|
||||
|
||||
/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP
|
||||
systems. This function is required for `alloca.c' support on those systems.
|
||||
*/
|
||||
/* #undef CRAY_STACKSEG_END */
|
||||
|
||||
/* Define to 1 if using `alloca.c'. */
|
||||
/* #undef C_ALLOCA */
|
||||
|
||||
/* Whether to disable memory pools */
|
||||
/* #undef DISABLE_MEM_POOLS */
|
||||
|
||||
/* Whether to enable GC friendliness by default */
|
||||
/* #undef ENABLE_GC_FRIENDLY_DEFAULT */
|
||||
|
||||
/* always defined to indicate that i18n is enabled */
|
||||
#define ENABLE_NLS 1
|
||||
|
||||
/* Define the gettext package to be used */
|
||||
#define GETTEXT_PACKAGE "glib20"
|
||||
|
||||
/* Define to the GLIB binary age */
|
||||
#define GLIB_BINARY_AGE 2001
|
||||
|
||||
/* Byte contents of gmutex */
|
||||
/* #undef GLIB_BYTE_CONTENTS_GMUTEX */
|
||||
|
||||
/* Define to the GLIB interface age */
|
||||
#define GLIB_INTERFACE_AGE 1
|
||||
|
||||
/* Define the location where the catalogs will be installed */
|
||||
#define GLIB_LOCALE_DIR "NONE/share/locale"
|
||||
|
||||
/* Define to the GLIB major version */
|
||||
#define GLIB_MAJOR_VERSION 2
|
||||
|
||||
/* Define to the GLIB micro version */
|
||||
#define GLIB_MICRO_VERSION 1
|
||||
|
||||
/* Define to the GLIB minor version */
|
||||
#define GLIB_MINOR_VERSION 20
|
||||
|
||||
/* The size of gmutex, as computed by sizeof. */
|
||||
/* #undef GLIB_SIZEOF_GMUTEX */
|
||||
|
||||
/* The size of system_thread, as computed by sizeof. */
|
||||
#define GLIB_SIZEOF_SYSTEM_THREAD 4
|
||||
|
||||
/* alpha atomic implementation */
|
||||
/* #undef G_ATOMIC_ALPHA */
|
||||
|
||||
/* arm atomic implementation */
|
||||
/* #undef G_ATOMIC_ARM */
|
||||
|
||||
/* i486 atomic implementation */
|
||||
#ifndef _MSC_VER
|
||||
#define G_ATOMIC_I486 1
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
/* ia64 atomic implementation */
|
||||
/* #undef G_ATOMIC_IA64 */
|
||||
|
||||
/* powerpc atomic implementation */
|
||||
/* #undef G_ATOMIC_POWERPC */
|
||||
|
||||
/* s390 atomic implementation */
|
||||
/* #undef G_ATOMIC_S390 */
|
||||
|
||||
/* sparcv9 atomic implementation */
|
||||
/* #undef G_ATOMIC_SPARCV9 */
|
||||
|
||||
/* x86_64 atomic implementation */
|
||||
/* #undef G_ATOMIC_X86_64 */
|
||||
|
||||
/* Have inline keyword */
|
||||
#ifndef _MSC_VER
|
||||
#define G_HAVE_INLINE 1
|
||||
#else /* _MSC_VER */
|
||||
/* #undef G_HAVE_INLINE */
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
/* Have __inline keyword */
|
||||
#define G_HAVE___INLINE 1
|
||||
|
||||
/* Have __inline__ keyword */
|
||||
#if !defined(_MSC_VER) && !defined(__DMC__)
|
||||
#define G_HAVE___INLINE__ 1
|
||||
#else /* _MSC_VER or __DMC__ */
|
||||
/* #undef G_HAVE___INLINE__ */
|
||||
#endif /* _MSC_VER or __DMC__ */
|
||||
|
||||
/* Source file containing theread implementation */
|
||||
#define G_THREAD_SOURCE "gthread-win32.c"
|
||||
|
||||
/* A 'va_copy' style function */
|
||||
#ifndef _MSC_VER
|
||||
#define G_VA_COPY va_copy
|
||||
#else /* _MSC_VER */
|
||||
/* #undef G_VA_COPY */
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
/* 'va_lists' cannot be copies as values */
|
||||
/* #undef G_VA_COPY_AS_ARRAY */
|
||||
|
||||
/* Define to 1 if you have `alloca', as a function or macro. */
|
||||
#define HAVE_ALLOCA 1
|
||||
|
||||
/* Define to 1 if you have <alloca.h> and it should be used (not on Ultrix).
|
||||
*/
|
||||
/* #undef HAVE_ALLOCA_H */
|
||||
|
||||
/* Define to 1 if you have the `atexit' function. */
|
||||
#define HAVE_ATEXIT 1
|
||||
|
||||
/* Define to 1 if you have the <attr/xattr.h> header file. */
|
||||
/* #undef HAVE_ATTR_XATTR_H */
|
||||
|
||||
/* Define to 1 if you have the `bind_textdomain_codeset' function. */
|
||||
#define HAVE_BIND_TEXTDOMAIN_CODESET 1
|
||||
|
||||
/* Define if you have a version of the snprintf function with semantics as
|
||||
specified by the ISO C99 standard. */
|
||||
/* #undef HAVE_C99_SNPRINTF */
|
||||
|
||||
/* Define if you have a version of the vsnprintf function with semantics as
|
||||
specified by the ISO C99 standard. */
|
||||
/* #undef HAVE_C99_VSNPRINTF */
|
||||
|
||||
/* define to 1 if Carbon is available */
|
||||
/* #undef HAVE_CARBON */
|
||||
|
||||
/* Define to 1 if you have the `chown' function. */
|
||||
/* #undef HAVE_CHOWN */
|
||||
|
||||
/* Define to 1 if you have the `clock_gettime' function. */
|
||||
/* #undef HAVE_CLOCK_GETTIME */
|
||||
|
||||
/* Have nl_langinfo (CODESET) */
|
||||
/* #undef HAVE_CODESET */
|
||||
|
||||
/* Define to 1 if you have the <crt_externs.h> header file. */
|
||||
/* #undef HAVE_CRT_EXTERNS_H */
|
||||
|
||||
/* Define to 1 if you have the `dcgettext' function. */
|
||||
#define HAVE_DCGETTEXT 1
|
||||
|
||||
/* Define to 1 if you have the <dirent.h> header file. */
|
||||
#ifndef _MSC_VER
|
||||
#define HAVE_DIRENT_H 1
|
||||
#else
|
||||
/* #undef HAVE_DIRENT_H */
|
||||
#endif
|
||||
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
/* #undef HAVE_DLFCN_H */
|
||||
|
||||
/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
|
||||
/* #undef HAVE_DOPRNT */
|
||||
|
||||
/* define for working do while(0) macros */
|
||||
#define HAVE_DOWHILE_MACROS 1
|
||||
|
||||
/* Define to 1 if you have the `endmntent' function. */
|
||||
/* #undef HAVE_ENDMNTENT */
|
||||
|
||||
/* Define if we have FAM */
|
||||
/* #undef HAVE_FAM */
|
||||
|
||||
/* Define to 1 if you have the <fam.h> header file. */
|
||||
/* #undef HAVE_FAM_H */
|
||||
|
||||
/* Define if we have FAMNoExists in fam */
|
||||
/* #undef HAVE_FAM_NO_EXISTS */
|
||||
|
||||
/* Define to 1 if you have the `fchmod' function. */
|
||||
/* #undef HAVE_FCHMOD */
|
||||
|
||||
/* Define to 1 if you have the `fchown' function. */
|
||||
/* #undef HAVE_FCHOWN */
|
||||
|
||||
/* Define to 1 if you have the `fdwalk' function. */
|
||||
/* #undef HAVE_FDWALK */
|
||||
|
||||
/* Define to 1 if you have the <float.h> header file. */
|
||||
#define HAVE_FLOAT_H 1
|
||||
|
||||
/* Define to 1 if you have the <fstab.h> header file. */
|
||||
/* #undef HAVE_FSTAB_H */
|
||||
|
||||
/* Define to 1 if you have the `getcwd' function. */
|
||||
#define HAVE_GETCWD 1
|
||||
|
||||
/* Define to 1 if you have the `getc_unlocked' function. */
|
||||
/* #undef HAVE_GETC_UNLOCKED */
|
||||
|
||||
/* Define to 1 if you have the `getgrgid' function. */
|
||||
/* #undef HAVE_GETGRGID */
|
||||
|
||||
/* Define to 1 if you have the `getmntent_r' function. */
|
||||
/* #undef HAVE_GETMNTENT_R */
|
||||
|
||||
/* Define to 1 if you have the `getmntinfo' function. */
|
||||
/* #undef HAVE_GETMNTINFO */
|
||||
|
||||
/* Define to 1 if you have the `getpwuid' function. */
|
||||
/* #undef HAVE_GETPWUID */
|
||||
|
||||
/* Define if the GNU gettext() function is already present or preinstalled. */
|
||||
#define HAVE_GETTEXT 1
|
||||
|
||||
/* Define to 1 if you have the `gmtime_r' function. */
|
||||
/* #undef HAVE_GMTIME_R */
|
||||
|
||||
/* define to use system printf */
|
||||
/* #undef HAVE_GOOD_PRINTF */
|
||||
|
||||
/* Define to 1 if you have the <grp.h> header file. */
|
||||
/* #undef HAVE_GRP_H */
|
||||
|
||||
/* Define to 1 if you have the `hasmntopt' function. */
|
||||
/* #undef HAVE_HASMNTOPT */
|
||||
|
||||
/* define to support printing 64-bit integers with format I64 */
|
||||
#define HAVE_INT64_AND_I64 1
|
||||
|
||||
/* Define if you have the 'intmax_t' type in <stdint.h> or <inttypes.h>. */
|
||||
#ifndef _MSC_VER
|
||||
#define HAVE_INTMAX_T 1
|
||||
#else /* _MSC_VER */
|
||||
/* #undef HAVE_INTMAX_T */
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#ifndef _MSC_VER
|
||||
#define HAVE_INTTYPES_H 1
|
||||
#else /* _MSC_VER */
|
||||
/* #undef HAVE_INTTYPES_H */
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
/* Define if <inttypes.h> exists, doesn't clash with <sys/types.h>, and
|
||||
declares uintmax_t. */
|
||||
#ifndef _MSC_VER
|
||||
#define HAVE_INTTYPES_H_WITH_UINTMAX 1
|
||||
#else /* _MSC_VER */
|
||||
/* #undef HAVE_INTTYPES_H_WITH_UINTMAX */
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
/* Define if you have <langinfo.h> and nl_langinfo(CODESET). */
|
||||
/* #undef HAVE_LANGINFO_CODESET */
|
||||
|
||||
/* Define to 1 if you have the `lchown' function. */
|
||||
/* #undef HAVE_LCHOWN */
|
||||
|
||||
/* Define if your <locale.h> file defines LC_MESSAGES. */
|
||||
/* #undef HAVE_LC_MESSAGES */
|
||||
|
||||
/* Define to 1 if you have the <limits.h> header file. */
|
||||
#define HAVE_LIMITS_H 1
|
||||
|
||||
/* Define to 1 if you have the `link' function. */
|
||||
/* #undef HAVE_LINK */
|
||||
|
||||
/* Define to 1 if you have the <locale.h> header file. */
|
||||
#define HAVE_LOCALE_H 1
|
||||
|
||||
/* Define to 1 if you have the `localtime_r' function. */
|
||||
/* #undef HAVE_LOCALTIME_R */
|
||||
|
||||
/* Define if you have the 'long double' type. */
|
||||
#define HAVE_LONG_DOUBLE 1
|
||||
|
||||
/* Define if you have the 'long long' type. */
|
||||
#ifndef _MSC_VER
|
||||
#define HAVE_LONG_LONG 1
|
||||
#else /* _MSC_VER */
|
||||
/* #undef HAVE_LONG_LONG */
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
/* define if system printf can print long long */
|
||||
#define HAVE_LONG_LONG_FORMAT 1
|
||||
|
||||
/* Define to 1 if you have the `lstat' function. */
|
||||
/* #undef HAVE_LSTAT */
|
||||
|
||||
/* Define to 1 if you have the <malloc.h> header file. */
|
||||
#define HAVE_MALLOC_H 1
|
||||
|
||||
/* Define to 1 if you have the `memalign' function. */
|
||||
/* #undef HAVE_MEMALIGN */
|
||||
|
||||
/* Define to 1 if you have the `memmove' function. */
|
||||
#define HAVE_MEMMOVE 1
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
/* Define to 1 if you have the `mmap' system call. */
|
||||
/* #undef HAVE_MMAP */
|
||||
|
||||
/* Define to 1 if you have the <mntent.h> header file. */
|
||||
/* #undef HAVE_MNTENT_H */
|
||||
|
||||
/* Have a monotonic clock */
|
||||
/* #undef HAVE_MONOTONIC_CLOCK */
|
||||
|
||||
/* Define to 1 if you have the `nanosleep' function. */
|
||||
/* #undef HAVE_NANOSLEEP */
|
||||
|
||||
/* Have non-POSIX function getgrgid_r */
|
||||
/* #undef HAVE_NONPOSIX_GETGRGID_R */
|
||||
|
||||
/* Have non-POSIX function getpwuid_r */
|
||||
/* #undef HAVE_NONPOSIX_GETPWUID_R */
|
||||
|
||||
/* Define to 1 if you have the `nsleep' function. */
|
||||
/* #undef HAVE_NSLEEP */
|
||||
|
||||
/* Define to 1 if you have the `on_exit' function. */
|
||||
/* #undef HAVE_ON_EXIT */
|
||||
|
||||
/* Define to 1 if you have the `poll' function. */
|
||||
/* #undef HAVE_POLL */
|
||||
|
||||
/* Have POSIX function getgrgid_r */
|
||||
/* #undef HAVE_POSIX_GETGRGID_R */
|
||||
|
||||
/* Have POSIX function getpwuid_r */
|
||||
/* #undef HAVE_POSIX_GETPWUID_R */
|
||||
|
||||
/* Define to 1 if you have the `posix_memalign' function. */
|
||||
/* #undef HAVE_POSIX_MEMALIGN */
|
||||
|
||||
/* Have function pthread_attr_setstacksize */
|
||||
/* #undef HAVE_PTHREAD_ATTR_SETSTACKSIZE */
|
||||
|
||||
/* Define to 1 if the system has the type `ptrdiff_t'. */
|
||||
#define HAVE_PTRDIFF_T 1
|
||||
|
||||
/* Define to 1 if you have the <pwd.h> header file. */
|
||||
/* #undef HAVE_PWD_H */
|
||||
|
||||
/* Define to 1 if you have the `readlink' function. */
|
||||
/* #undef HAVE_READLINK */
|
||||
|
||||
/* Define to 1 if you have the <sched.h> header file. */
|
||||
/* #undef HAVE_SCHED_H */
|
||||
|
||||
/* Define to 1 if libselinux is available */
|
||||
/* #undef HAVE_SELINUX */
|
||||
|
||||
/* Define to 1 if you have the <selinux/selinux.h> header file. */
|
||||
/* #undef HAVE_SELINUX_SELINUX_H */
|
||||
|
||||
/* Define to 1 if you have the `setenv' function. */
|
||||
/* #undef HAVE_SETENV */
|
||||
|
||||
/* Define to 1 if you have the `setlocale' function. */
|
||||
#define HAVE_SETLOCALE 1
|
||||
|
||||
/* Define to 1 if you have the `setmntent' function. */
|
||||
/* #undef HAVE_SETMNTENT */
|
||||
|
||||
/* Define to 1 if you have the `snprintf' function. */
|
||||
#ifndef _MSC_VER
|
||||
#define HAVE_SNPRINTF 1
|
||||
#ifdef __DMC__
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
#else /* _MSC_VER */
|
||||
/* #undef HAVE_SNPRINTF */
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
/* Define to 1 if you have the `statfs' function. */
|
||||
/* #undef HAVE_STATFS */
|
||||
|
||||
/* Define to 1 if you have the `statvfs' function. */
|
||||
/* #undef HAVE_STATVFS */
|
||||
|
||||
/* Define to 1 if you have the <stddef.h> header file. */
|
||||
#define HAVE_STDDEF_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#ifndef _MSC_VER
|
||||
#define HAVE_STDINT_H 1
|
||||
#else /* _MSC_VER */
|
||||
/* #undef HAVE_STDINT_H */
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
/* Define if <stdint.h> exists, doesn't clash with <sys/types.h>, and
|
||||
declares uintmax_t. */
|
||||
#ifndef _MSC_VER
|
||||
#define HAVE_STDINT_H_WITH_UINTMAX 1
|
||||
#else /* _MSC_VER */
|
||||
/* #undef HAVE_STDINT_H_WITH_UINTMAX */
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* Define to 1 if you have the `stpcpy' function. */
|
||||
/* #undef HAVE_STPCPY */
|
||||
|
||||
/* Define to 1 if you have the `strcasecmp' function. */
|
||||
#if !defined(_MSC_VER) && !defined(__DMC__)
|
||||
#define HAVE_STRCASECMP 1
|
||||
#else /* _MSC_VER or __DMC__ */
|
||||
/* #undef HAVE_STRCASECMP */
|
||||
#endif /* _MSC_VER or __DMC__ */
|
||||
|
||||
/* Define to 1 if you have the `strerror' function. */
|
||||
#define HAVE_STRERROR 1
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#if !defined(_MSC_VER) && !defined(__DMC__)
|
||||
#define HAVE_STRINGS_H 1
|
||||
#else /* _MSC_VER or __DMC__ */
|
||||
/* #undef HAVE_STRINGS_H */
|
||||
#endif /* _MSC_VER or __DMC__ */
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Have functions strlcpy and strlcat */
|
||||
/* #undef HAVE_STRLCPY */
|
||||
|
||||
/* Define to 1 if you have the `strncasecmp' function. */
|
||||
#if !defined(_MSC_VER) && !defined(__DMC__)
|
||||
#define HAVE_STRNCASECMP 1
|
||||
#else /* _MSC_VER or __DMC__ */
|
||||
/* #undef HAVE_STRNCASECMP */
|
||||
#endif /* _MSC_VER or __DMC__ */
|
||||
|
||||
/* Define to 1 if you have the `strsignal' function. */
|
||||
/* #undef HAVE_STRSIGNAL */
|
||||
|
||||
/* Define to 1 if `f_bavail' is member of `struct statfs'. */
|
||||
/* #undef HAVE_STRUCT_STATFS_F_BAVAIL */
|
||||
|
||||
/* Define to 1 if `f_fstypename' is member of `struct statfs'. */
|
||||
/* #undef HAVE_STRUCT_STATFS_F_FSTYPENAME */
|
||||
|
||||
/* Define to 1 if `f_basetype' is member of `struct statvfs'. */
|
||||
/* #undef HAVE_STRUCT_STATVFS_F_BASETYPE */
|
||||
|
||||
/* Define to 1 if `st_atimensec' is member of `struct stat'. */
|
||||
/* #undef HAVE_STRUCT_STAT_ST_ATIMENSEC */
|
||||
|
||||
/* Define to 1 if `st_atim.tv_nsec' is member of `struct stat'. */
|
||||
/* #undef HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC */
|
||||
|
||||
/* Define to 1 if `st_blksize' is member of `struct stat'. */
|
||||
/* #undef HAVE_STRUCT_STAT_ST_BLKSIZE */
|
||||
|
||||
/* Define to 1 if `st_blocks' is member of `struct stat'. */
|
||||
/* #undef HAVE_STRUCT_STAT_ST_BLOCKS */
|
||||
|
||||
/* Define to 1 if `st_ctimensec' is member of `struct stat'. */
|
||||
/* #undef HAVE_STRUCT_STAT_ST_CTIMENSEC */
|
||||
|
||||
/* Define to 1 if `st_ctim.tv_nsec' is member of `struct stat'. */
|
||||
/* #undef HAVE_STRUCT_STAT_ST_CTIM_TV_NSEC */
|
||||
|
||||
/* Define to 1 if `st_mtimensec' is member of `struct stat'. */
|
||||
/* #undef HAVE_STRUCT_STAT_ST_MTIMENSEC */
|
||||
|
||||
/* Define to 1 if `st_mtim.tv_nsec' is member of `struct stat'. */
|
||||
/* #undef HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC */
|
||||
|
||||
/* Define to 1 if you have the `symlink' function. */
|
||||
/* #undef HAVE_SYMLINK */
|
||||
|
||||
/* Define to 1 if you have the <sys/inotify.h> header file. */
|
||||
/* #undef HAVE_SYS_INOTIFY_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/mntctl.h> header file. */
|
||||
/* #undef HAVE_SYS_MNTCTL_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/mnttab.h> header file. */
|
||||
/* #undef HAVE_SYS_MNTTAB_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/mount.h> header file. */
|
||||
/* #undef HAVE_SYS_MOUNT_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/param.h> header file. */
|
||||
#if !defined(_MSC_VER) && !defined(__DMC__)
|
||||
#define HAVE_SYS_PARAM_H 1
|
||||
#else /* _MSC_VER or __DMC__ */
|
||||
/* #undef HAVE_SYS_PARAM_H */
|
||||
#endif /* _MSC_VER or __DMC__ */
|
||||
|
||||
/* Define to 1 if you have the <sys/poll.h> header file. */
|
||||
/* #undef HAVE_SYS_POLL_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/resource.h> header file. */
|
||||
/* #undef HAVE_SYS_RESOURCE_H */
|
||||
|
||||
/* found fd_set in sys/select.h */
|
||||
/* #undef HAVE_SYS_SELECT_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/statfs.h> header file. */
|
||||
/* #undef HAVE_SYS_STATFS_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/statvfs.h> header file. */
|
||||
/* #undef HAVE_SYS_STATVFS_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/sysctl.h> header file. */
|
||||
/* #undef HAVE_SYS_SYSCTL_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/times.h> header file. */
|
||||
/* #undef HAVE_SYS_TIMES_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/time.h> header file. */
|
||||
#ifndef _MSC_VER
|
||||
#define HAVE_SYS_TIME_H 1
|
||||
#else /* _MSC_VER */
|
||||
/* #undef HAVE_SYS_TIME_H */
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/vfstab.h> header file. */
|
||||
/* #undef HAVE_SYS_VFSTAB_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/vfs.h> header file. */
|
||||
/* #undef HAVE_SYS_VFS_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/vmount.h> header file. */
|
||||
/* #undef HAVE_SYS_VMOUNT_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/wait.h> header file. */
|
||||
/* #undef HAVE_SYS_WAIT_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/xattr.h> header file. */
|
||||
/* #undef HAVE_SYS_XATTR_H */
|
||||
|
||||
/* Define to 1 if you have the `timegm' function. */
|
||||
/* #undef HAVE_TIMEGM */
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#ifndef _MSC_VER
|
||||
#define HAVE_UNISTD_H 1
|
||||
#else /* _MSC_VER */
|
||||
/* #undef HAVE_UNISTD_H */
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
/* Define if your printf function family supports positional parameters as
|
||||
specified by Unix98. */
|
||||
/* #undef HAVE_UNIX98_PRINTF */
|
||||
|
||||
/* Define to 1 if you have the `unsetenv' function. */
|
||||
/* #undef HAVE_UNSETENV */
|
||||
|
||||
/* Define to 1 if you have the `utimes' function. */
|
||||
/* #undef HAVE_UTIMES */
|
||||
|
||||
/* Define to 1 if you have the `valloc' function. */
|
||||
/* #undef HAVE_VALLOC */
|
||||
|
||||
/* Define to 1 if you have the <values.h> header file. */
|
||||
#if !defined(_MSC_VER) && !defined(__DMC__)
|
||||
#define HAVE_VALUES_H 1
|
||||
#else /* _MSC_VER or __DMC__ */
|
||||
/* #undef HAVE_VALUES_H */
|
||||
#endif /* _MSC_VER or __DMC__ */
|
||||
|
||||
/* Define to 1 if you have the `vasprintf' function. */
|
||||
#define HAVE_VASPRINTF 1
|
||||
|
||||
/* Define to 1 if you have the `vprintf' function. */
|
||||
#define HAVE_VPRINTF 1
|
||||
|
||||
/* Define to 1 if you have the `vsnprintf' function. */
|
||||
#ifndef _MSC_VER
|
||||
#define HAVE_VSNPRINTF 1
|
||||
#ifdef __DMC__
|
||||
#define vsnprintf _vsnprintf
|
||||
#endif
|
||||
#else /* _MSC_VER */
|
||||
/* #undef HAVE_VSNPRINTF */
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
/* Define if you have the 'wchar_t' type. */
|
||||
#define HAVE_WCHAR_T 1
|
||||
|
||||
/* Define to 1 if you have the `wcslen' function. */
|
||||
#define HAVE_WCSLEN 1
|
||||
|
||||
/* Define if you have the 'wint_t' type. */
|
||||
#define HAVE_WINT_T 1
|
||||
|
||||
/* Have a working bcopy */
|
||||
/* #undef HAVE_WORKING_BCOPY */
|
||||
|
||||
/* Define to 1 if xattr is available */
|
||||
/* #undef HAVE_XATTR */
|
||||
|
||||
/* Define to 1 if xattr API uses XATTR_NOFOLLOW */
|
||||
/* #undef HAVE_XATTR_NOFOLLOW */
|
||||
|
||||
/* Define to 1 if you have the `_NSGetEnviron' function. */
|
||||
/* #undef HAVE__NSGETENVIRON */
|
||||
|
||||
/* Do we cache iconv descriptors */
|
||||
#define NEED_ICONV_CACHE 1
|
||||
|
||||
/* didn't find fd_set */
|
||||
#define NO_FD_SET 1
|
||||
|
||||
/* Define to 1 if your C compiler doesn't accept -c and -o together. */
|
||||
/* #undef NO_MINUS_C_MINUS_O */
|
||||
|
||||
/* global 'sys_errlist' not found */
|
||||
#define NO_SYS_ERRLIST 1
|
||||
|
||||
/* global 'sys_siglist' not found */
|
||||
#define NO_SYS_SIGLIST 1
|
||||
|
||||
/* global 'sys_siglist' not declared */
|
||||
#define NO_SYS_SIGLIST_DECL 1
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT "http://bugzilla.gnome.org/enter_bug.cgi?product=glib"
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME "glib"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "glib 2.20.1"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME "glib"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "2.20.1"
|
||||
|
||||
/* Maximum POSIX RT priority */
|
||||
/* #undef POSIX_MAX_PRIORITY */
|
||||
|
||||
/* define if posix_memalign() can allocate any size */
|
||||
/* #undef POSIX_MEMALIGN_WITH_COMPLIANT_ALLOCS */
|
||||
|
||||
/* Minimum POSIX RT priority */
|
||||
/* #undef POSIX_MIN_PRIORITY */
|
||||
|
||||
/* The POSIX RT yield function */
|
||||
/* #undef POSIX_YIELD_FUNC */
|
||||
|
||||
/* whether realloc (NULL,) works */
|
||||
#define REALLOC_0_WORKS 1
|
||||
|
||||
/* Define if you have correct malloc prototypes */
|
||||
#ifndef _MSC_VER
|
||||
#define SANE_MALLOC_PROTOS 1
|
||||
#else /* _MSC_VER */
|
||||
/* #undef SANE_MALLOC_PROTOS */
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
/* The size of `char', as computed by sizeof. */
|
||||
#define SIZEOF_CHAR 1
|
||||
|
||||
/* The size of `int', as computed by sizeof. */
|
||||
#define SIZEOF_INT 4
|
||||
|
||||
/* The size of `long', as computed by sizeof. */
|
||||
#define SIZEOF_LONG 4
|
||||
|
||||
/* The size of `long long', as computed by sizeof. */
|
||||
#ifndef _MSC_VER
|
||||
#define SIZEOF_LONG_LONG 8
|
||||
#else /* _MSC_VER */
|
||||
#define SIZEOF_LONG_LONG 0
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
/* The size of `short', as computed by sizeof. */
|
||||
#define SIZEOF_SHORT 2
|
||||
|
||||
/* The size of `size_t', as computed by sizeof. */
|
||||
#define SIZEOF_SIZE_T 4
|
||||
|
||||
/* The size of `void *', as computed by sizeof. */
|
||||
#define SIZEOF_VOID_P 4
|
||||
|
||||
/* The size of `__int64', as computed by sizeof. */
|
||||
#define SIZEOF___INT64 8
|
||||
|
||||
/* If using the C implementation of alloca, define if you know the
|
||||
direction of stack growth for your system; otherwise it will be
|
||||
automatically deduced at runtime.
|
||||
STACK_DIRECTION > 0 => grows toward higher addresses
|
||||
STACK_DIRECTION < 0 => grows toward lower addresses
|
||||
STACK_DIRECTION = 0 => direction of growth unknown */
|
||||
/* #undef STACK_DIRECTION */
|
||||
|
||||
/* Number of arguments to statfs() */
|
||||
/* #undef STATFS_ARGS */
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Using GNU libiconv */
|
||||
/* #undef USE_LIBICONV_GNU */
|
||||
|
||||
/* Using a native implementation of iconv in a separate library */
|
||||
#define USE_LIBICONV_NATIVE 1
|
||||
|
||||
/* using the system-supplied PCRE library */
|
||||
/* #undef USE_SYSTEM_PCRE */
|
||||
|
||||
/* Define to 1 if your processor stores words with the most significant byte
|
||||
first (like Motorola and SPARC, unlike Intel and VAX). */
|
||||
/* #undef WORDS_BIGENDIAN */
|
||||
|
||||
/* Number of bits in a file offset, on hosts where this is settable. */
|
||||
/* #undef _FILE_OFFSET_BITS */
|
||||
|
||||
/* Define for large files, on AIX-style hosts. */
|
||||
/* #undef _LARGE_FILES */
|
||||
|
||||
/* Define to empty if `const' does not conform to ANSI C. */
|
||||
/* #undef const */
|
||||
|
||||
/* Define to long or long long if <inttypes.h> and <stdint.h> don't define. */
|
||||
/* #undef intmax_t */
|
||||
|
||||
/* Define to empty if the C compiler doesn't support this keyword. */
|
||||
/* #undef signed */
|
||||
|
||||
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||
/* #undef size_t */
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,63 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
|
||||
#error "Only <glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __G_ALLOCA_H__
|
||||
#define __G_ALLOCA_H__
|
||||
|
||||
#include <glib/gtypes.h>
|
||||
|
||||
#ifdef __GNUC__
|
||||
/* GCC does the right thing */
|
||||
# undef alloca
|
||||
# define alloca(size) __builtin_alloca (size)
|
||||
#elif defined (GLIB_HAVE_ALLOCA_H)
|
||||
/* a native and working alloca.h is there */
|
||||
# include <alloca.h>
|
||||
#else /* !__GNUC__ && !GLIB_HAVE_ALLOCA_H */
|
||||
# if defined(_MSC_VER) || defined(__DMC__)
|
||||
# include <malloc.h>
|
||||
# define alloca _alloca
|
||||
# else /* !_MSC_VER && !__DMC__ */
|
||||
# ifdef _AIX
|
||||
# pragma alloca
|
||||
# else /* !_AIX */
|
||||
# ifndef alloca /* predefined by HP cc +Olibcalls */
|
||||
G_BEGIN_DECLS
|
||||
char *alloca ();
|
||||
G_END_DECLS
|
||||
# endif /* !alloca */
|
||||
# endif /* !_AIX */
|
||||
# endif /* !_MSC_VER && !__DMC__ */
|
||||
#endif /* !__GNUC__ && !GLIB_HAVE_ALLOCA_H */
|
||||
|
||||
#define g_alloca(size) alloca (size)
|
||||
#define g_newa(struct_type, n_structs) ((struct_type*) g_alloca (sizeof (struct_type) * (gsize) (n_structs)))
|
||||
|
||||
#endif /* __G_ALLOCA_H__ */
|
|
@ -0,0 +1,719 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
/*
|
||||
* MT safe
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "garray.h"
|
||||
|
||||
#include "gmem.h"
|
||||
#include "gthread.h"
|
||||
#include "gmessages.h"
|
||||
#include "gqsort.h"
|
||||
|
||||
#include "galias.h"
|
||||
|
||||
|
||||
#define MIN_ARRAY_SIZE 16
|
||||
|
||||
typedef struct _GRealArray GRealArray;
|
||||
|
||||
struct _GRealArray
|
||||
{
|
||||
guint8 *data;
|
||||
guint len;
|
||||
guint alloc;
|
||||
guint elt_size;
|
||||
guint zero_terminated : 1;
|
||||
guint clear : 1;
|
||||
};
|
||||
|
||||
#define g_array_elt_len(array,i) ((array)->elt_size * (i))
|
||||
#define g_array_elt_pos(array,i) ((array)->data + g_array_elt_len((array),(i)))
|
||||
#define g_array_elt_zero(array, pos, len) \
|
||||
(memset (g_array_elt_pos ((array), pos), 0, g_array_elt_len ((array), len)))
|
||||
#define g_array_zero_terminate(array) G_STMT_START{ \
|
||||
if ((array)->zero_terminated) \
|
||||
g_array_elt_zero ((array), (array)->len, 1); \
|
||||
}G_STMT_END
|
||||
|
||||
static gint g_nearest_pow (gint num) G_GNUC_CONST;
|
||||
static void g_array_maybe_expand (GRealArray *array,
|
||||
gint len);
|
||||
|
||||
GArray*
|
||||
g_array_new (gboolean zero_terminated,
|
||||
gboolean clear,
|
||||
guint elt_size)
|
||||
{
|
||||
return (GArray*) g_array_sized_new (zero_terminated, clear, elt_size, 0);
|
||||
}
|
||||
|
||||
GArray* g_array_sized_new (gboolean zero_terminated,
|
||||
gboolean clear,
|
||||
guint elt_size,
|
||||
guint reserved_size)
|
||||
{
|
||||
GRealArray *array = g_slice_new (GRealArray);
|
||||
|
||||
array->data = NULL;
|
||||
array->len = 0;
|
||||
array->alloc = 0;
|
||||
array->zero_terminated = (zero_terminated ? 1 : 0);
|
||||
array->clear = (clear ? 1 : 0);
|
||||
array->elt_size = elt_size;
|
||||
|
||||
if (array->zero_terminated || reserved_size != 0)
|
||||
{
|
||||
g_array_maybe_expand (array, reserved_size);
|
||||
g_array_zero_terminate(array);
|
||||
}
|
||||
|
||||
return (GArray*) array;
|
||||
}
|
||||
|
||||
gchar*
|
||||
g_array_free (GArray *array,
|
||||
gboolean free_segment)
|
||||
{
|
||||
gchar* segment;
|
||||
|
||||
g_return_val_if_fail (array, NULL);
|
||||
|
||||
if (free_segment)
|
||||
{
|
||||
g_free (array->data);
|
||||
segment = NULL;
|
||||
}
|
||||
else
|
||||
segment = array->data;
|
||||
|
||||
g_slice_free1 (sizeof (GRealArray), array);
|
||||
|
||||
return segment;
|
||||
}
|
||||
|
||||
GArray*
|
||||
g_array_append_vals (GArray *farray,
|
||||
gconstpointer data,
|
||||
guint len)
|
||||
{
|
||||
GRealArray *array = (GRealArray*) farray;
|
||||
|
||||
g_array_maybe_expand (array, len);
|
||||
|
||||
memcpy (g_array_elt_pos (array, array->len), data,
|
||||
g_array_elt_len (array, len));
|
||||
|
||||
array->len += len;
|
||||
|
||||
g_array_zero_terminate (array);
|
||||
|
||||
return farray;
|
||||
}
|
||||
|
||||
GArray*
|
||||
g_array_prepend_vals (GArray *farray,
|
||||
gconstpointer data,
|
||||
guint len)
|
||||
{
|
||||
GRealArray *array = (GRealArray*) farray;
|
||||
|
||||
g_array_maybe_expand (array, len);
|
||||
|
||||
g_memmove (g_array_elt_pos (array, len), g_array_elt_pos (array, 0),
|
||||
g_array_elt_len (array, array->len));
|
||||
|
||||
memcpy (g_array_elt_pos (array, 0), data, g_array_elt_len (array, len));
|
||||
|
||||
array->len += len;
|
||||
|
||||
g_array_zero_terminate (array);
|
||||
|
||||
return farray;
|
||||
}
|
||||
|
||||
GArray*
|
||||
g_array_insert_vals (GArray *farray,
|
||||
guint index_,
|
||||
gconstpointer data,
|
||||
guint len)
|
||||
{
|
||||
GRealArray *array = (GRealArray*) farray;
|
||||
|
||||
g_array_maybe_expand (array, len);
|
||||
|
||||
g_memmove (g_array_elt_pos (array, len + index_),
|
||||
g_array_elt_pos (array, index_),
|
||||
g_array_elt_len (array, array->len - index_));
|
||||
|
||||
memcpy (g_array_elt_pos (array, index_), data, g_array_elt_len (array, len));
|
||||
|
||||
array->len += len;
|
||||
|
||||
g_array_zero_terminate (array);
|
||||
|
||||
return farray;
|
||||
}
|
||||
|
||||
GArray*
|
||||
g_array_set_size (GArray *farray,
|
||||
guint length)
|
||||
{
|
||||
GRealArray *array = (GRealArray*) farray;
|
||||
if (length > array->len)
|
||||
{
|
||||
g_array_maybe_expand (array, length - array->len);
|
||||
|
||||
if (array->clear)
|
||||
g_array_elt_zero (array, array->len, length - array->len);
|
||||
}
|
||||
else if (G_UNLIKELY (g_mem_gc_friendly) && length < array->len)
|
||||
g_array_elt_zero (array, length, array->len - length);
|
||||
|
||||
array->len = length;
|
||||
|
||||
g_array_zero_terminate (array);
|
||||
|
||||
return farray;
|
||||
}
|
||||
|
||||
GArray*
|
||||
g_array_remove_index (GArray *farray,
|
||||
guint index_)
|
||||
{
|
||||
GRealArray* array = (GRealArray*) farray;
|
||||
|
||||
g_return_val_if_fail (array, NULL);
|
||||
|
||||
g_return_val_if_fail (index_ < array->len, NULL);
|
||||
|
||||
if (index_ != array->len - 1)
|
||||
g_memmove (g_array_elt_pos (array, index_),
|
||||
g_array_elt_pos (array, index_ + 1),
|
||||
g_array_elt_len (array, array->len - index_ - 1));
|
||||
|
||||
array->len -= 1;
|
||||
|
||||
if (G_UNLIKELY (g_mem_gc_friendly))
|
||||
g_array_elt_zero (array, array->len, 1);
|
||||
else
|
||||
g_array_zero_terminate (array);
|
||||
|
||||
return farray;
|
||||
}
|
||||
|
||||
GArray*
|
||||
g_array_remove_index_fast (GArray *farray,
|
||||
guint index_)
|
||||
{
|
||||
GRealArray* array = (GRealArray*) farray;
|
||||
|
||||
g_return_val_if_fail (array, NULL);
|
||||
|
||||
g_return_val_if_fail (index_ < array->len, NULL);
|
||||
|
||||
if (index_ != array->len - 1)
|
||||
memcpy (g_array_elt_pos (array, index_),
|
||||
g_array_elt_pos (array, array->len - 1),
|
||||
g_array_elt_len (array, 1));
|
||||
|
||||
array->len -= 1;
|
||||
|
||||
if (G_UNLIKELY (g_mem_gc_friendly))
|
||||
g_array_elt_zero (array, array->len, 1);
|
||||
else
|
||||
g_array_zero_terminate (array);
|
||||
|
||||
return farray;
|
||||
}
|
||||
|
||||
GArray*
|
||||
g_array_remove_range (GArray *farray,
|
||||
guint index_,
|
||||
guint length)
|
||||
{
|
||||
GRealArray *array = (GRealArray*) farray;
|
||||
|
||||
g_return_val_if_fail (array, NULL);
|
||||
g_return_val_if_fail (index_ < array->len, NULL);
|
||||
g_return_val_if_fail (index_ + length <= array->len, NULL);
|
||||
|
||||
if (index_ + length != array->len)
|
||||
g_memmove (g_array_elt_pos (array, index_),
|
||||
g_array_elt_pos (array, index_ + length),
|
||||
(array->len - (index_ + length)) * array->elt_size);
|
||||
|
||||
array->len -= length;
|
||||
if (G_UNLIKELY (g_mem_gc_friendly))
|
||||
g_array_elt_zero (array, array->len, length);
|
||||
else
|
||||
g_array_zero_terminate (array);
|
||||
|
||||
return farray;
|
||||
}
|
||||
|
||||
void
|
||||
g_array_sort (GArray *farray,
|
||||
GCompareFunc compare_func)
|
||||
{
|
||||
GRealArray *array = (GRealArray*) farray;
|
||||
|
||||
g_return_if_fail (array != NULL);
|
||||
|
||||
qsort (array->data,
|
||||
array->len,
|
||||
array->elt_size,
|
||||
compare_func);
|
||||
}
|
||||
|
||||
void
|
||||
g_array_sort_with_data (GArray *farray,
|
||||
GCompareDataFunc compare_func,
|
||||
gpointer user_data)
|
||||
{
|
||||
GRealArray *array = (GRealArray*) farray;
|
||||
|
||||
g_return_if_fail (array != NULL);
|
||||
|
||||
g_qsort_with_data (array->data,
|
||||
array->len,
|
||||
array->elt_size,
|
||||
compare_func,
|
||||
user_data);
|
||||
}
|
||||
|
||||
|
||||
static gint
|
||||
g_nearest_pow (gint num)
|
||||
{
|
||||
gint n = 1;
|
||||
|
||||
while (n < num)
|
||||
n <<= 1;
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
static void
|
||||
g_array_maybe_expand (GRealArray *array,
|
||||
gint len)
|
||||
{
|
||||
guint want_alloc = g_array_elt_len (array, array->len + len +
|
||||
array->zero_terminated);
|
||||
|
||||
if (want_alloc > array->alloc)
|
||||
{
|
||||
want_alloc = g_nearest_pow (want_alloc);
|
||||
want_alloc = MAX (want_alloc, MIN_ARRAY_SIZE);
|
||||
|
||||
array->data = g_realloc (array->data, want_alloc);
|
||||
|
||||
if (G_UNLIKELY (g_mem_gc_friendly))
|
||||
memset (array->data + array->alloc, 0, want_alloc - array->alloc);
|
||||
|
||||
array->alloc = want_alloc;
|
||||
}
|
||||
}
|
||||
|
||||
/* Pointer Array
|
||||
*/
|
||||
|
||||
typedef struct _GRealPtrArray GRealPtrArray;
|
||||
|
||||
struct _GRealPtrArray
|
||||
{
|
||||
gpointer *pdata;
|
||||
guint len;
|
||||
guint alloc;
|
||||
};
|
||||
|
||||
static void g_ptr_array_maybe_expand (GRealPtrArray *array,
|
||||
gint len);
|
||||
|
||||
GPtrArray*
|
||||
g_ptr_array_new (void)
|
||||
{
|
||||
return g_ptr_array_sized_new (0);
|
||||
}
|
||||
|
||||
GPtrArray*
|
||||
g_ptr_array_sized_new (guint reserved_size)
|
||||
{
|
||||
GRealPtrArray *array = g_slice_new (GRealPtrArray);
|
||||
|
||||
array->pdata = NULL;
|
||||
array->len = 0;
|
||||
array->alloc = 0;
|
||||
|
||||
if (reserved_size != 0)
|
||||
g_ptr_array_maybe_expand (array, reserved_size);
|
||||
|
||||
return (GPtrArray*) array;
|
||||
}
|
||||
|
||||
gpointer*
|
||||
g_ptr_array_free (GPtrArray *array,
|
||||
gboolean free_segment)
|
||||
{
|
||||
gpointer* segment;
|
||||
|
||||
g_return_val_if_fail (array, NULL);
|
||||
|
||||
if (free_segment)
|
||||
{
|
||||
g_free (array->pdata);
|
||||
segment = NULL;
|
||||
}
|
||||
else
|
||||
segment = array->pdata;
|
||||
|
||||
g_slice_free1 (sizeof (GRealPtrArray), array);
|
||||
|
||||
return segment;
|
||||
}
|
||||
|
||||
static void
|
||||
g_ptr_array_maybe_expand (GRealPtrArray *array,
|
||||
gint len)
|
||||
{
|
||||
if ((array->len + len) > array->alloc)
|
||||
{
|
||||
guint old_alloc = array->alloc;
|
||||
array->alloc = g_nearest_pow (array->len + len);
|
||||
array->alloc = MAX (array->alloc, MIN_ARRAY_SIZE);
|
||||
array->pdata = g_realloc (array->pdata, sizeof (gpointer) * array->alloc);
|
||||
if (G_UNLIKELY (g_mem_gc_friendly))
|
||||
for ( ; old_alloc < array->alloc; old_alloc++)
|
||||
array->pdata [old_alloc] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
g_ptr_array_set_size (GPtrArray *farray,
|
||||
gint length)
|
||||
{
|
||||
GRealPtrArray* array = (GRealPtrArray*) farray;
|
||||
|
||||
g_return_if_fail (array);
|
||||
|
||||
if (length > array->len)
|
||||
{
|
||||
int i;
|
||||
g_ptr_array_maybe_expand (array, (length - array->len));
|
||||
/* This is not
|
||||
* memset (array->pdata + array->len, 0,
|
||||
* sizeof (gpointer) * (length - array->len));
|
||||
* to make it really portable. Remember (void*)NULL needn't be
|
||||
* bitwise zero. It of course is silly not to use memset (..,0,..).
|
||||
*/
|
||||
for (i = array->len; i < length; i++)
|
||||
array->pdata[i] = NULL;
|
||||
}
|
||||
if (G_UNLIKELY (g_mem_gc_friendly) && length < array->len)
|
||||
{
|
||||
int i;
|
||||
for (i = length; i < array->len; i++)
|
||||
array->pdata[i] = NULL;
|
||||
}
|
||||
|
||||
array->len = length;
|
||||
}
|
||||
|
||||
gpointer
|
||||
g_ptr_array_remove_index (GPtrArray *farray,
|
||||
guint index_)
|
||||
{
|
||||
GRealPtrArray* array = (GRealPtrArray*) farray;
|
||||
gpointer result;
|
||||
|
||||
g_return_val_if_fail (array, NULL);
|
||||
|
||||
g_return_val_if_fail (index_ < array->len, NULL);
|
||||
|
||||
result = array->pdata[index_];
|
||||
|
||||
if (index_ != array->len - 1)
|
||||
g_memmove (array->pdata + index_, array->pdata + index_ + 1,
|
||||
sizeof (gpointer) * (array->len - index_ - 1));
|
||||
|
||||
array->len -= 1;
|
||||
|
||||
if (G_UNLIKELY (g_mem_gc_friendly))
|
||||
array->pdata[array->len] = NULL;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
gpointer
|
||||
g_ptr_array_remove_index_fast (GPtrArray *farray,
|
||||
guint index_)
|
||||
{
|
||||
GRealPtrArray* array = (GRealPtrArray*) farray;
|
||||
gpointer result;
|
||||
|
||||
g_return_val_if_fail (array, NULL);
|
||||
|
||||
g_return_val_if_fail (index_ < array->len, NULL);
|
||||
|
||||
result = array->pdata[index_];
|
||||
|
||||
if (index_ != array->len - 1)
|
||||
array->pdata[index_] = array->pdata[array->len - 1];
|
||||
|
||||
array->len -= 1;
|
||||
|
||||
if (G_UNLIKELY (g_mem_gc_friendly))
|
||||
array->pdata[array->len] = NULL;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
g_ptr_array_remove_range (GPtrArray *farray,
|
||||
guint index_,
|
||||
guint length)
|
||||
{
|
||||
GRealPtrArray* array = (GRealPtrArray*) farray;
|
||||
|
||||
g_return_if_fail (array);
|
||||
g_return_if_fail (index_ < array->len);
|
||||
g_return_if_fail (index_ + length <= array->len);
|
||||
|
||||
if (index_ + length != array->len)
|
||||
g_memmove (&array->pdata[index_],
|
||||
&array->pdata[index_ + length],
|
||||
(array->len - (index_ + length)) * sizeof (gpointer));
|
||||
|
||||
array->len -= length;
|
||||
if (G_UNLIKELY (g_mem_gc_friendly))
|
||||
{
|
||||
guint i;
|
||||
for (i = 0; i < length; i++)
|
||||
array->pdata[array->len + i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
g_ptr_array_remove (GPtrArray *farray,
|
||||
gpointer data)
|
||||
{
|
||||
GRealPtrArray* array = (GRealPtrArray*) farray;
|
||||
guint i;
|
||||
|
||||
g_return_val_if_fail (array, FALSE);
|
||||
|
||||
for (i = 0; i < array->len; i += 1)
|
||||
{
|
||||
if (array->pdata[i] == data)
|
||||
{
|
||||
g_ptr_array_remove_index (farray, i);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
g_ptr_array_remove_fast (GPtrArray *farray,
|
||||
gpointer data)
|
||||
{
|
||||
GRealPtrArray* array = (GRealPtrArray*) farray;
|
||||
guint i;
|
||||
|
||||
g_return_val_if_fail (array, FALSE);
|
||||
|
||||
for (i = 0; i < array->len; i += 1)
|
||||
{
|
||||
if (array->pdata[i] == data)
|
||||
{
|
||||
g_ptr_array_remove_index_fast (farray, i);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
g_ptr_array_add (GPtrArray *farray,
|
||||
gpointer data)
|
||||
{
|
||||
GRealPtrArray* array = (GRealPtrArray*) farray;
|
||||
|
||||
g_return_if_fail (array);
|
||||
|
||||
g_ptr_array_maybe_expand (array, 1);
|
||||
|
||||
array->pdata[array->len++] = data;
|
||||
}
|
||||
|
||||
void
|
||||
g_ptr_array_sort (GPtrArray *array,
|
||||
GCompareFunc compare_func)
|
||||
{
|
||||
g_return_if_fail (array != NULL);
|
||||
|
||||
qsort (array->pdata,
|
||||
array->len,
|
||||
sizeof (gpointer),
|
||||
compare_func);
|
||||
}
|
||||
|
||||
void
|
||||
g_ptr_array_sort_with_data (GPtrArray *array,
|
||||
GCompareDataFunc compare_func,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_return_if_fail (array != NULL);
|
||||
|
||||
g_qsort_with_data (array->pdata,
|
||||
array->len,
|
||||
sizeof (gpointer),
|
||||
compare_func,
|
||||
user_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_ptr_array_foreach:
|
||||
* @array: a #GPtrArray
|
||||
* @func: the function to call for each array element
|
||||
* @user_data: user data to pass to the function
|
||||
*
|
||||
* Calls a function for each element of a #GPtrArray.
|
||||
*
|
||||
* Since: 2.4
|
||||
**/
|
||||
void
|
||||
g_ptr_array_foreach (GPtrArray *array,
|
||||
GFunc func,
|
||||
gpointer user_data)
|
||||
{
|
||||
guint i;
|
||||
|
||||
g_return_if_fail (array);
|
||||
|
||||
for (i = 0; i < array->len; i++)
|
||||
(*func) (array->pdata[i], user_data);
|
||||
}
|
||||
|
||||
/* Byte arrays
|
||||
*/
|
||||
|
||||
GByteArray* g_byte_array_new (void)
|
||||
{
|
||||
return (GByteArray*) g_array_sized_new (FALSE, FALSE, 1, 0);
|
||||
}
|
||||
|
||||
GByteArray* g_byte_array_sized_new (guint reserved_size)
|
||||
{
|
||||
return (GByteArray*) g_array_sized_new (FALSE, FALSE, 1, reserved_size);
|
||||
}
|
||||
|
||||
guint8* g_byte_array_free (GByteArray *array,
|
||||
gboolean free_segment)
|
||||
{
|
||||
return (guint8*) g_array_free ((GArray*) array, free_segment);
|
||||
}
|
||||
|
||||
GByteArray* g_byte_array_append (GByteArray *array,
|
||||
const guint8 *data,
|
||||
guint len)
|
||||
{
|
||||
g_array_append_vals ((GArray*) array, (guint8*)data, len);
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
GByteArray* g_byte_array_prepend (GByteArray *array,
|
||||
const guint8 *data,
|
||||
guint len)
|
||||
{
|
||||
g_array_prepend_vals ((GArray*) array, (guint8*)data, len);
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
GByteArray* g_byte_array_set_size (GByteArray *array,
|
||||
guint length)
|
||||
{
|
||||
g_array_set_size ((GArray*) array, length);
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
GByteArray* g_byte_array_remove_index (GByteArray *array,
|
||||
guint index_)
|
||||
{
|
||||
g_array_remove_index ((GArray*) array, index_);
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
GByteArray* g_byte_array_remove_index_fast (GByteArray *array,
|
||||
guint index_)
|
||||
{
|
||||
g_array_remove_index_fast ((GArray*) array, index_);
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
GByteArray*
|
||||
g_byte_array_remove_range (GByteArray *array,
|
||||
guint index_,
|
||||
guint length)
|
||||
{
|
||||
g_return_val_if_fail (array, NULL);
|
||||
g_return_val_if_fail (index_ < array->len, NULL);
|
||||
g_return_val_if_fail (index_ + length <= array->len, NULL);
|
||||
|
||||
return (GByteArray *)g_array_remove_range ((GArray*) array, index_, length);
|
||||
}
|
||||
|
||||
void
|
||||
g_byte_array_sort (GByteArray *array,
|
||||
GCompareFunc compare_func)
|
||||
{
|
||||
g_array_sort ((GArray *) array, compare_func);
|
||||
}
|
||||
|
||||
void
|
||||
g_byte_array_sort_with_data (GByteArray *array,
|
||||
GCompareDataFunc compare_func,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_array_sort_with_data ((GArray *) array, compare_func, user_data);
|
||||
}
|
||||
|
||||
#define __G_ARRAY_C__
|
||||
#include "galiasdef.c"
|
|
@ -0,0 +1,169 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
|
||||
#error "Only <glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __G_ARRAY_H__
|
||||
#define __G_ARRAY_H__
|
||||
|
||||
#include <glib/gtypes.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GArray GArray;
|
||||
typedef struct _GByteArray GByteArray;
|
||||
typedef struct _GPtrArray GPtrArray;
|
||||
|
||||
struct _GArray
|
||||
{
|
||||
gchar *data;
|
||||
guint len;
|
||||
};
|
||||
|
||||
struct _GByteArray
|
||||
{
|
||||
guint8 *data;
|
||||
guint len;
|
||||
};
|
||||
|
||||
struct _GPtrArray
|
||||
{
|
||||
gpointer *pdata;
|
||||
guint len;
|
||||
};
|
||||
|
||||
/* Resizable arrays. remove fills any cleared spot and shortens the
|
||||
* array, while preserving the order. remove_fast will distort the
|
||||
* order by moving the last element to the position of the removed.
|
||||
*/
|
||||
|
||||
#define g_array_append_val(a,v) g_array_append_vals (a, &(v), 1)
|
||||
#define g_array_prepend_val(a,v) g_array_prepend_vals (a, &(v), 1)
|
||||
#define g_array_insert_val(a,i,v) g_array_insert_vals (a, i, &(v), 1)
|
||||
#define g_array_index(a,t,i) (((t*) (void *) (a)->data) [(i)])
|
||||
|
||||
GArray* g_array_new (gboolean zero_terminated,
|
||||
gboolean clear_,
|
||||
guint element_size);
|
||||
GArray* g_array_sized_new (gboolean zero_terminated,
|
||||
gboolean clear_,
|
||||
guint element_size,
|
||||
guint reserved_size);
|
||||
gchar* g_array_free (GArray *array,
|
||||
gboolean free_segment);
|
||||
GArray* g_array_append_vals (GArray *array,
|
||||
gconstpointer data,
|
||||
guint len);
|
||||
GArray* g_array_prepend_vals (GArray *array,
|
||||
gconstpointer data,
|
||||
guint len);
|
||||
GArray* g_array_insert_vals (GArray *array,
|
||||
guint index_,
|
||||
gconstpointer data,
|
||||
guint len);
|
||||
GArray* g_array_set_size (GArray *array,
|
||||
guint length);
|
||||
GArray* g_array_remove_index (GArray *array,
|
||||
guint index_);
|
||||
GArray* g_array_remove_index_fast (GArray *array,
|
||||
guint index_);
|
||||
GArray* g_array_remove_range (GArray *array,
|
||||
guint index_,
|
||||
guint length);
|
||||
void g_array_sort (GArray *array,
|
||||
GCompareFunc compare_func);
|
||||
void g_array_sort_with_data (GArray *array,
|
||||
GCompareDataFunc compare_func,
|
||||
gpointer user_data);
|
||||
|
||||
/* Resizable pointer array. This interface is much less complicated
|
||||
* than the above. Add appends a pointer. Remove fills any cleared
|
||||
* spot and shortens the array. remove_fast will again distort order.
|
||||
*/
|
||||
#define g_ptr_array_index(array,index_) ((array)->pdata)[index_]
|
||||
GPtrArray* g_ptr_array_new (void);
|
||||
GPtrArray* g_ptr_array_sized_new (guint reserved_size);
|
||||
gpointer* g_ptr_array_free (GPtrArray *array,
|
||||
gboolean free_seg);
|
||||
void g_ptr_array_set_size (GPtrArray *array,
|
||||
gint length);
|
||||
gpointer g_ptr_array_remove_index (GPtrArray *array,
|
||||
guint index_);
|
||||
gpointer g_ptr_array_remove_index_fast (GPtrArray *array,
|
||||
guint index_);
|
||||
gboolean g_ptr_array_remove (GPtrArray *array,
|
||||
gpointer data);
|
||||
gboolean g_ptr_array_remove_fast (GPtrArray *array,
|
||||
gpointer data);
|
||||
void g_ptr_array_remove_range (GPtrArray *array,
|
||||
guint index_,
|
||||
guint length);
|
||||
void g_ptr_array_add (GPtrArray *array,
|
||||
gpointer data);
|
||||
void g_ptr_array_sort (GPtrArray *array,
|
||||
GCompareFunc compare_func);
|
||||
void g_ptr_array_sort_with_data (GPtrArray *array,
|
||||
GCompareDataFunc compare_func,
|
||||
gpointer user_data);
|
||||
void g_ptr_array_foreach (GPtrArray *array,
|
||||
GFunc func,
|
||||
gpointer user_data);
|
||||
|
||||
|
||||
/* Byte arrays, an array of guint8. Implemented as a GArray,
|
||||
* but type-safe.
|
||||
*/
|
||||
|
||||
GByteArray* g_byte_array_new (void);
|
||||
GByteArray* g_byte_array_sized_new (guint reserved_size);
|
||||
guint8* g_byte_array_free (GByteArray *array,
|
||||
gboolean free_segment);
|
||||
GByteArray* g_byte_array_append (GByteArray *array,
|
||||
const guint8 *data,
|
||||
guint len);
|
||||
GByteArray* g_byte_array_prepend (GByteArray *array,
|
||||
const guint8 *data,
|
||||
guint len);
|
||||
GByteArray* g_byte_array_set_size (GByteArray *array,
|
||||
guint length);
|
||||
GByteArray* g_byte_array_remove_index (GByteArray *array,
|
||||
guint index_);
|
||||
GByteArray* g_byte_array_remove_index_fast (GByteArray *array,
|
||||
guint index_);
|
||||
GByteArray* g_byte_array_remove_range (GByteArray *array,
|
||||
guint index_,
|
||||
guint length);
|
||||
void g_byte_array_sort (GByteArray *array,
|
||||
GCompareFunc compare_func);
|
||||
void g_byte_array_sort_with_data (GByteArray *array,
|
||||
GCompareDataFunc compare_func,
|
||||
gpointer user_data);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_ARRAY_H__ */
|
|
@ -0,0 +1,666 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* GAsyncQueue: asynchronous queue implementation, based on Gqueue.
|
||||
* Copyright (C) 2000 Sebastian Wilhelmi; University of Karlsruhe
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* MT safe
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "glib.h"
|
||||
#include "galias.h"
|
||||
|
||||
|
||||
struct _GAsyncQueue
|
||||
{
|
||||
GMutex *mutex;
|
||||
GCond *cond;
|
||||
GQueue *queue;
|
||||
GDestroyNotify item_free_func;
|
||||
guint waiting_threads;
|
||||
gint32 ref_count;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
GCompareDataFunc func;
|
||||
gpointer user_data;
|
||||
} SortData;
|
||||
|
||||
/**
|
||||
* g_async_queue_new:
|
||||
*
|
||||
* Creates a new asynchronous queue with the initial reference count of 1.
|
||||
*
|
||||
* Return value: the new #GAsyncQueue.
|
||||
**/
|
||||
GAsyncQueue*
|
||||
g_async_queue_new (void)
|
||||
{
|
||||
GAsyncQueue* retval = g_new (GAsyncQueue, 1);
|
||||
retval->mutex = g_mutex_new ();
|
||||
retval->cond = NULL;
|
||||
retval->queue = g_queue_new ();
|
||||
retval->waiting_threads = 0;
|
||||
retval->ref_count = 1;
|
||||
retval->item_free_func = NULL;
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_async_queue_new_full:
|
||||
* @item_free_func: function to free queue elements
|
||||
*
|
||||
* Creates a new asynchronous queue with an initial reference count of 1 and
|
||||
* sets up a destroy notify function that is used to free any remaining
|
||||
* queue items when the queue is destroyed after the final unref.
|
||||
*
|
||||
* Return value: the new #GAsyncQueue.
|
||||
*
|
||||
* Since: 2.16
|
||||
**/
|
||||
GAsyncQueue*
|
||||
g_async_queue_new_full (GDestroyNotify item_free_func)
|
||||
{
|
||||
GAsyncQueue *async_queue = g_async_queue_new ();
|
||||
async_queue->item_free_func = item_free_func;
|
||||
return async_queue;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_async_queue_ref:
|
||||
* @queue: a #GAsyncQueue.
|
||||
*
|
||||
* Increases the reference count of the asynchronous @queue by 1. You
|
||||
* do not need to hold the lock to call this function.
|
||||
*
|
||||
* Returns: the @queue that was passed in (since 2.6)
|
||||
**/
|
||||
GAsyncQueue *
|
||||
g_async_queue_ref (GAsyncQueue *queue)
|
||||
{
|
||||
g_return_val_if_fail (queue, NULL);
|
||||
g_return_val_if_fail (g_atomic_int_get (&queue->ref_count) > 0, NULL);
|
||||
|
||||
g_atomic_int_inc (&queue->ref_count);
|
||||
|
||||
return queue;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_async_queue_ref_unlocked:
|
||||
* @queue: a #GAsyncQueue.
|
||||
*
|
||||
* Increases the reference count of the asynchronous @queue by 1.
|
||||
*
|
||||
* @Deprecated: Since 2.8, reference counting is done atomically
|
||||
* so g_async_queue_ref() can be used regardless of the @queue's
|
||||
* lock.
|
||||
**/
|
||||
void
|
||||
g_async_queue_ref_unlocked (GAsyncQueue *queue)
|
||||
{
|
||||
g_return_if_fail (queue);
|
||||
g_return_if_fail (g_atomic_int_get (&queue->ref_count) > 0);
|
||||
|
||||
g_atomic_int_inc (&queue->ref_count);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_async_queue_unref_and_unlock:
|
||||
* @queue: a #GAsyncQueue.
|
||||
*
|
||||
* Decreases the reference count of the asynchronous @queue by 1 and
|
||||
* releases the lock. This function must be called while holding the
|
||||
* @queue's lock. If the reference count went to 0, the @queue will be
|
||||
* destroyed and the memory allocated will be freed.
|
||||
*
|
||||
* @Deprecated: Since 2.8, reference counting is done atomically
|
||||
* so g_async_queue_unref() can be used regardless of the @queue's
|
||||
* lock.
|
||||
**/
|
||||
void
|
||||
g_async_queue_unref_and_unlock (GAsyncQueue *queue)
|
||||
{
|
||||
g_return_if_fail (queue);
|
||||
g_return_if_fail (g_atomic_int_get (&queue->ref_count) > 0);
|
||||
|
||||
g_mutex_unlock (queue->mutex);
|
||||
g_async_queue_unref (queue);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_async_queue_unref:
|
||||
* @queue: a #GAsyncQueue.
|
||||
*
|
||||
* Decreases the reference count of the asynchronous @queue by 1. If
|
||||
* the reference count went to 0, the @queue will be destroyed and the
|
||||
* memory allocated will be freed. So you are not allowed to use the
|
||||
* @queue afterwards, as it might have disappeared. You do not need to
|
||||
* hold the lock to call this function.
|
||||
**/
|
||||
void
|
||||
g_async_queue_unref (GAsyncQueue *queue)
|
||||
{
|
||||
g_return_if_fail (queue);
|
||||
g_return_if_fail (g_atomic_int_get (&queue->ref_count) > 0);
|
||||
|
||||
if (g_atomic_int_dec_and_test (&queue->ref_count))
|
||||
{
|
||||
g_return_if_fail (queue->waiting_threads == 0);
|
||||
g_mutex_free (queue->mutex);
|
||||
if (queue->cond)
|
||||
g_cond_free (queue->cond);
|
||||
if (queue->item_free_func)
|
||||
g_queue_foreach (queue->queue, (GFunc) queue->item_free_func, NULL);
|
||||
g_queue_free (queue->queue);
|
||||
g_free (queue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* g_async_queue_lock:
|
||||
* @queue: a #GAsyncQueue.
|
||||
*
|
||||
* Acquires the @queue's lock. After that you can only call the
|
||||
* <function>g_async_queue_*_unlocked()</function> function variants on that
|
||||
* @queue. Otherwise it will deadlock.
|
||||
**/
|
||||
void
|
||||
g_async_queue_lock (GAsyncQueue *queue)
|
||||
{
|
||||
g_return_if_fail (queue);
|
||||
g_return_if_fail (g_atomic_int_get (&queue->ref_count) > 0);
|
||||
|
||||
g_mutex_lock (queue->mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_async_queue_unlock:
|
||||
* @queue: a #GAsyncQueue.
|
||||
*
|
||||
* Releases the queue's lock.
|
||||
**/
|
||||
void
|
||||
g_async_queue_unlock (GAsyncQueue *queue)
|
||||
{
|
||||
g_return_if_fail (queue);
|
||||
g_return_if_fail (g_atomic_int_get (&queue->ref_count) > 0);
|
||||
|
||||
g_mutex_unlock (queue->mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_async_queue_push:
|
||||
* @queue: a #GAsyncQueue.
|
||||
* @data: @data to push into the @queue.
|
||||
*
|
||||
* Pushes the @data into the @queue. @data must not be %NULL.
|
||||
**/
|
||||
void
|
||||
g_async_queue_push (GAsyncQueue* queue, gpointer data)
|
||||
{
|
||||
g_return_if_fail (queue);
|
||||
g_return_if_fail (g_atomic_int_get (&queue->ref_count) > 0);
|
||||
g_return_if_fail (data);
|
||||
|
||||
g_mutex_lock (queue->mutex);
|
||||
g_async_queue_push_unlocked (queue, data);
|
||||
g_mutex_unlock (queue->mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_async_queue_push_unlocked:
|
||||
* @queue: a #GAsyncQueue.
|
||||
* @data: @data to push into the @queue.
|
||||
*
|
||||
* Pushes the @data into the @queue. @data must not be %NULL. This
|
||||
* function must be called while holding the @queue's lock.
|
||||
**/
|
||||
void
|
||||
g_async_queue_push_unlocked (GAsyncQueue* queue, gpointer data)
|
||||
{
|
||||
g_return_if_fail (queue);
|
||||
g_return_if_fail (g_atomic_int_get (&queue->ref_count) > 0);
|
||||
g_return_if_fail (data);
|
||||
|
||||
g_queue_push_head (queue->queue, data);
|
||||
if (queue->waiting_threads > 0)
|
||||
g_cond_signal (queue->cond);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_async_queue_push_sorted:
|
||||
* @queue: a #GAsyncQueue
|
||||
* @data: the @data to push into the @queue
|
||||
* @func: the #GCompareDataFunc is used to sort @queue. This function
|
||||
* is passed two elements of the @queue. The function should return
|
||||
* 0 if they are equal, a negative value if the first element
|
||||
* should be higher in the @queue or a positive value if the first
|
||||
* element should be lower in the @queue than the second element.
|
||||
* @user_data: user data passed to @func.
|
||||
*
|
||||
* Inserts @data into @queue using @func to determine the new
|
||||
* position.
|
||||
*
|
||||
* This function requires that the @queue is sorted before pushing on
|
||||
* new elements.
|
||||
*
|
||||
* This function will lock @queue before it sorts the queue and unlock
|
||||
* it when it is finished.
|
||||
*
|
||||
* For an example of @func see g_async_queue_sort().
|
||||
*
|
||||
* Since: 2.10
|
||||
**/
|
||||
void
|
||||
g_async_queue_push_sorted (GAsyncQueue *queue,
|
||||
gpointer data,
|
||||
GCompareDataFunc func,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_return_if_fail (queue != NULL);
|
||||
|
||||
g_mutex_lock (queue->mutex);
|
||||
g_async_queue_push_sorted_unlocked (queue, data, func, user_data);
|
||||
g_mutex_unlock (queue->mutex);
|
||||
}
|
||||
|
||||
static gint
|
||||
g_async_queue_invert_compare (gpointer v1,
|
||||
gpointer v2,
|
||||
SortData *sd)
|
||||
{
|
||||
return -sd->func (v1, v2, sd->user_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_async_queue_push_sorted_unlocked:
|
||||
* @queue: a #GAsyncQueue
|
||||
* @data: the @data to push into the @queue
|
||||
* @func: the #GCompareDataFunc is used to sort @queue. This function
|
||||
* is passed two elements of the @queue. The function should return
|
||||
* 0 if they are equal, a negative value if the first element
|
||||
* should be higher in the @queue or a positive value if the first
|
||||
* element should be lower in the @queue than the second element.
|
||||
* @user_data: user data passed to @func.
|
||||
*
|
||||
* Inserts @data into @queue using @func to determine the new
|
||||
* position.
|
||||
*
|
||||
* This function requires that the @queue is sorted before pushing on
|
||||
* new elements.
|
||||
*
|
||||
* This function is called while holding the @queue's lock.
|
||||
*
|
||||
* For an example of @func see g_async_queue_sort().
|
||||
*
|
||||
* Since: 2.10
|
||||
**/
|
||||
void
|
||||
g_async_queue_push_sorted_unlocked (GAsyncQueue *queue,
|
||||
gpointer data,
|
||||
GCompareDataFunc func,
|
||||
gpointer user_data)
|
||||
{
|
||||
SortData sd;
|
||||
|
||||
g_return_if_fail (queue != NULL);
|
||||
|
||||
sd.func = func;
|
||||
sd.user_data = user_data;
|
||||
|
||||
g_queue_insert_sorted (queue->queue,
|
||||
data,
|
||||
(GCompareDataFunc)g_async_queue_invert_compare,
|
||||
&sd);
|
||||
if (queue->waiting_threads > 0)
|
||||
g_cond_signal (queue->cond);
|
||||
}
|
||||
|
||||
static gpointer
|
||||
g_async_queue_pop_intern_unlocked (GAsyncQueue *queue,
|
||||
gboolean try,
|
||||
GTimeVal *end_time)
|
||||
{
|
||||
gpointer retval;
|
||||
|
||||
if (!g_queue_peek_tail_link (queue->queue))
|
||||
{
|
||||
if (try)
|
||||
return NULL;
|
||||
|
||||
if (!queue->cond)
|
||||
queue->cond = g_cond_new ();
|
||||
|
||||
if (!end_time)
|
||||
{
|
||||
queue->waiting_threads++;
|
||||
while (!g_queue_peek_tail_link (queue->queue))
|
||||
g_cond_wait (queue->cond, queue->mutex);
|
||||
queue->waiting_threads--;
|
||||
}
|
||||
else
|
||||
{
|
||||
queue->waiting_threads++;
|
||||
while (!g_queue_peek_tail_link (queue->queue))
|
||||
if (!g_cond_timed_wait (queue->cond, queue->mutex, end_time))
|
||||
break;
|
||||
queue->waiting_threads--;
|
||||
if (!g_queue_peek_tail_link (queue->queue))
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
retval = g_queue_pop_tail (queue->queue);
|
||||
|
||||
g_assert (retval);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_async_queue_pop:
|
||||
* @queue: a #GAsyncQueue.
|
||||
*
|
||||
* Pops data from the @queue. This function blocks until data become
|
||||
* available.
|
||||
*
|
||||
* Return value: data from the queue.
|
||||
**/
|
||||
gpointer
|
||||
g_async_queue_pop (GAsyncQueue* queue)
|
||||
{
|
||||
gpointer retval;
|
||||
|
||||
g_return_val_if_fail (queue, NULL);
|
||||
g_return_val_if_fail (g_atomic_int_get (&queue->ref_count) > 0, NULL);
|
||||
|
||||
g_mutex_lock (queue->mutex);
|
||||
retval = g_async_queue_pop_intern_unlocked (queue, FALSE, NULL);
|
||||
g_mutex_unlock (queue->mutex);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_async_queue_pop_unlocked:
|
||||
* @queue: a #GAsyncQueue.
|
||||
*
|
||||
* Pops data from the @queue. This function blocks until data become
|
||||
* available. This function must be called while holding the @queue's
|
||||
* lock.
|
||||
*
|
||||
* Return value: data from the queue.
|
||||
**/
|
||||
gpointer
|
||||
g_async_queue_pop_unlocked (GAsyncQueue* queue)
|
||||
{
|
||||
g_return_val_if_fail (queue, NULL);
|
||||
g_return_val_if_fail (g_atomic_int_get (&queue->ref_count) > 0, NULL);
|
||||
|
||||
return g_async_queue_pop_intern_unlocked (queue, FALSE, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_async_queue_try_pop:
|
||||
* @queue: a #GAsyncQueue.
|
||||
*
|
||||
* Tries to pop data from the @queue. If no data is available, %NULL is
|
||||
* returned.
|
||||
*
|
||||
* Return value: data from the queue or %NULL, when no data is
|
||||
* available immediately.
|
||||
**/
|
||||
gpointer
|
||||
g_async_queue_try_pop (GAsyncQueue* queue)
|
||||
{
|
||||
gpointer retval;
|
||||
|
||||
g_return_val_if_fail (queue, NULL);
|
||||
g_return_val_if_fail (g_atomic_int_get (&queue->ref_count) > 0, NULL);
|
||||
|
||||
g_mutex_lock (queue->mutex);
|
||||
retval = g_async_queue_pop_intern_unlocked (queue, TRUE, NULL);
|
||||
g_mutex_unlock (queue->mutex);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_async_queue_try_pop_unlocked:
|
||||
* @queue: a #GAsyncQueue.
|
||||
*
|
||||
* Tries to pop data from the @queue. If no data is available, %NULL is
|
||||
* returned. This function must be called while holding the @queue's
|
||||
* lock.
|
||||
*
|
||||
* Return value: data from the queue or %NULL, when no data is
|
||||
* available immediately.
|
||||
**/
|
||||
gpointer
|
||||
g_async_queue_try_pop_unlocked (GAsyncQueue* queue)
|
||||
{
|
||||
g_return_val_if_fail (queue, NULL);
|
||||
g_return_val_if_fail (g_atomic_int_get (&queue->ref_count) > 0, NULL);
|
||||
|
||||
return g_async_queue_pop_intern_unlocked (queue, TRUE, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_async_queue_timed_pop:
|
||||
* @queue: a #GAsyncQueue.
|
||||
* @end_time: a #GTimeVal, determining the final time.
|
||||
*
|
||||
* Pops data from the @queue. If no data is received before @end_time,
|
||||
* %NULL is returned.
|
||||
*
|
||||
* To easily calculate @end_time a combination of g_get_current_time()
|
||||
* and g_time_val_add() can be used.
|
||||
*
|
||||
* Return value: data from the queue or %NULL, when no data is
|
||||
* received before @end_time.
|
||||
**/
|
||||
gpointer
|
||||
g_async_queue_timed_pop (GAsyncQueue* queue, GTimeVal *end_time)
|
||||
{
|
||||
gpointer retval;
|
||||
|
||||
g_return_val_if_fail (queue, NULL);
|
||||
g_return_val_if_fail (g_atomic_int_get (&queue->ref_count) > 0, NULL);
|
||||
|
||||
g_mutex_lock (queue->mutex);
|
||||
retval = g_async_queue_pop_intern_unlocked (queue, FALSE, end_time);
|
||||
g_mutex_unlock (queue->mutex);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_async_queue_timed_pop_unlocked:
|
||||
* @queue: a #GAsyncQueue.
|
||||
* @end_time: a #GTimeVal, determining the final time.
|
||||
*
|
||||
* Pops data from the @queue. If no data is received before @end_time,
|
||||
* %NULL is returned. This function must be called while holding the
|
||||
* @queue's lock.
|
||||
*
|
||||
* To easily calculate @end_time a combination of g_get_current_time()
|
||||
* and g_time_val_add() can be used.
|
||||
*
|
||||
* Return value: data from the queue or %NULL, when no data is
|
||||
* received before @end_time.
|
||||
**/
|
||||
gpointer
|
||||
g_async_queue_timed_pop_unlocked (GAsyncQueue* queue, GTimeVal *end_time)
|
||||
{
|
||||
g_return_val_if_fail (queue, NULL);
|
||||
g_return_val_if_fail (g_atomic_int_get (&queue->ref_count) > 0, NULL);
|
||||
|
||||
return g_async_queue_pop_intern_unlocked (queue, FALSE, end_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_async_queue_length:
|
||||
* @queue: a #GAsyncQueue.
|
||||
*
|
||||
* Returns the length of the queue, negative values mean waiting
|
||||
* threads, positive values mean available entries in the
|
||||
* @queue. Actually this function returns the number of data items in
|
||||
* the queue minus the number of waiting threads. Thus a return value
|
||||
* of 0 could mean 'n' entries in the queue and 'n' thread waiting.
|
||||
* That can happen due to locking of the queue or due to
|
||||
* scheduling.
|
||||
*
|
||||
* Return value: the length of the @queue.
|
||||
**/
|
||||
gint
|
||||
g_async_queue_length (GAsyncQueue* queue)
|
||||
{
|
||||
gint retval;
|
||||
|
||||
g_return_val_if_fail (queue, 0);
|
||||
g_return_val_if_fail (g_atomic_int_get (&queue->ref_count) > 0, 0);
|
||||
|
||||
g_mutex_lock (queue->mutex);
|
||||
retval = queue->queue->length - queue->waiting_threads;
|
||||
g_mutex_unlock (queue->mutex);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_async_queue_length_unlocked:
|
||||
* @queue: a #GAsyncQueue.
|
||||
*
|
||||
* Returns the length of the queue, negative values mean waiting
|
||||
* threads, positive values mean available entries in the
|
||||
* @queue. Actually this function returns the number of data items in
|
||||
* the queue minus the number of waiting threads. Thus a return value
|
||||
* of 0 could mean 'n' entries in the queue and 'n' thread waiting.
|
||||
* That can happen due to locking of the queue or due to
|
||||
* scheduling. This function must be called while holding the @queue's
|
||||
* lock.
|
||||
*
|
||||
* Return value: the length of the @queue.
|
||||
**/
|
||||
gint
|
||||
g_async_queue_length_unlocked (GAsyncQueue* queue)
|
||||
{
|
||||
g_return_val_if_fail (queue, 0);
|
||||
g_return_val_if_fail (g_atomic_int_get (&queue->ref_count) > 0, 0);
|
||||
|
||||
return queue->queue->length - queue->waiting_threads;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_async_queue_sort:
|
||||
* @queue: a #GAsyncQueue
|
||||
* @func: the #GCompareDataFunc is used to sort @queue. This
|
||||
* function is passed two elements of the @queue. The function
|
||||
* should return 0 if they are equal, a negative value if the
|
||||
* first element should be higher in the @queue or a positive
|
||||
* value if the first element should be lower in the @queue than
|
||||
* the second element.
|
||||
* @user_data: user data passed to @func
|
||||
*
|
||||
* Sorts @queue using @func.
|
||||
*
|
||||
* This function will lock @queue before it sorts the queue and unlock
|
||||
* it when it is finished.
|
||||
*
|
||||
* If you were sorting a list of priority numbers to make sure the
|
||||
* lowest priority would be at the top of the queue, you could use:
|
||||
* |[
|
||||
* gint32 id1;
|
||||
* gint32 id2;
|
||||
*
|
||||
* id1 = GPOINTER_TO_INT (element1);
|
||||
* id2 = GPOINTER_TO_INT (element2);
|
||||
*
|
||||
* return (id1 > id2 ? +1 : id1 == id2 ? 0 : -1);
|
||||
* ]|
|
||||
*
|
||||
* Since: 2.10
|
||||
**/
|
||||
void
|
||||
g_async_queue_sort (GAsyncQueue *queue,
|
||||
GCompareDataFunc func,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_return_if_fail (queue != NULL);
|
||||
g_return_if_fail (func != NULL);
|
||||
|
||||
g_mutex_lock (queue->mutex);
|
||||
g_async_queue_sort_unlocked (queue, func, user_data);
|
||||
g_mutex_unlock (queue->mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_async_queue_sort_unlocked:
|
||||
* @queue: a #GAsyncQueue
|
||||
* @func: the #GCompareDataFunc is used to sort @queue. This
|
||||
* function is passed two elements of the @queue. The function
|
||||
* should return 0 if they are equal, a negative value if the
|
||||
* first element should be higher in the @queue or a positive
|
||||
* value if the first element should be lower in the @queue than
|
||||
* the second element.
|
||||
* @user_data: user data passed to @func
|
||||
*
|
||||
* Sorts @queue using @func.
|
||||
*
|
||||
* This function is called while holding the @queue's lock.
|
||||
*
|
||||
* Since: 2.10
|
||||
**/
|
||||
void
|
||||
g_async_queue_sort_unlocked (GAsyncQueue *queue,
|
||||
GCompareDataFunc func,
|
||||
gpointer user_data)
|
||||
{
|
||||
SortData sd;
|
||||
|
||||
g_return_if_fail (queue != NULL);
|
||||
g_return_if_fail (func != NULL);
|
||||
|
||||
sd.func = func;
|
||||
sd.user_data = user_data;
|
||||
|
||||
g_queue_sort (queue->queue,
|
||||
(GCompareDataFunc)g_async_queue_invert_compare,
|
||||
&sd);
|
||||
}
|
||||
|
||||
/*
|
||||
* Private API
|
||||
*/
|
||||
|
||||
GMutex*
|
||||
_g_async_queue_get_mutex (GAsyncQueue* queue)
|
||||
{
|
||||
g_return_val_if_fail (queue, NULL);
|
||||
g_return_val_if_fail (g_atomic_int_get (&queue->ref_count) > 0, NULL);
|
||||
|
||||
return queue->mutex;
|
||||
}
|
||||
|
||||
#define __G_ASYNCQUEUE_C__
|
||||
#include "galiasdef.c"
|
|
@ -0,0 +1,120 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
|
||||
#error "Only <glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __G_ASYNCQUEUE_H__
|
||||
#define __G_ASYNCQUEUE_H__
|
||||
|
||||
#include <glib/gthread.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GAsyncQueue GAsyncQueue;
|
||||
|
||||
/* Asyncronous Queues, can be used to communicate between threads */
|
||||
|
||||
/* Get a new GAsyncQueue with the ref_count 1 */
|
||||
GAsyncQueue* g_async_queue_new (void);
|
||||
|
||||
GAsyncQueue* g_async_queue_new_full (GDestroyNotify item_free_func);
|
||||
|
||||
/* Lock and unlock a GAsyncQueue. All functions lock the queue for
|
||||
* themselves, but in certain cirumstances you want to hold the lock longer,
|
||||
* thus you lock the queue, call the *_unlocked functions and unlock it again.
|
||||
*/
|
||||
void g_async_queue_lock (GAsyncQueue *queue);
|
||||
void g_async_queue_unlock (GAsyncQueue *queue);
|
||||
|
||||
/* Ref and unref the GAsyncQueue. */
|
||||
GAsyncQueue* g_async_queue_ref (GAsyncQueue *queue);
|
||||
void g_async_queue_unref (GAsyncQueue *queue);
|
||||
|
||||
#ifndef G_DISABLE_DEPRECATED
|
||||
/* You don't have to hold the lock for calling *_ref and *_unref anymore. */
|
||||
void g_async_queue_ref_unlocked (GAsyncQueue *queue);
|
||||
void g_async_queue_unref_and_unlock (GAsyncQueue *queue);
|
||||
#endif /* !G_DISABLE_DEPRECATED */
|
||||
|
||||
/* Push data into the async queue. Must not be NULL. */
|
||||
void g_async_queue_push (GAsyncQueue *queue,
|
||||
gpointer data);
|
||||
void g_async_queue_push_unlocked (GAsyncQueue *queue,
|
||||
gpointer data);
|
||||
|
||||
void g_async_queue_push_sorted (GAsyncQueue *queue,
|
||||
gpointer data,
|
||||
GCompareDataFunc func,
|
||||
gpointer user_data);
|
||||
void g_async_queue_push_sorted_unlocked (GAsyncQueue *queue,
|
||||
gpointer data,
|
||||
GCompareDataFunc func,
|
||||
gpointer user_data);
|
||||
|
||||
/* Pop data from the async queue. When no data is there, the thread is blocked
|
||||
* until data arrives.
|
||||
*/
|
||||
gpointer g_async_queue_pop (GAsyncQueue *queue);
|
||||
gpointer g_async_queue_pop_unlocked (GAsyncQueue *queue);
|
||||
|
||||
/* Try to pop data. NULL is returned in case of empty queue. */
|
||||
gpointer g_async_queue_try_pop (GAsyncQueue *queue);
|
||||
gpointer g_async_queue_try_pop_unlocked (GAsyncQueue *queue);
|
||||
|
||||
|
||||
|
||||
/* Wait for data until at maximum until end_time is reached. NULL is returned
|
||||
* in case of empty queue.
|
||||
*/
|
||||
gpointer g_async_queue_timed_pop (GAsyncQueue *queue,
|
||||
GTimeVal *end_time);
|
||||
gpointer g_async_queue_timed_pop_unlocked (GAsyncQueue *queue,
|
||||
GTimeVal *end_time);
|
||||
|
||||
/* Return the length of the queue. Negative values mean that threads
|
||||
* are waiting, positve values mean that there are entries in the
|
||||
* queue. Actually this function returns the length of the queue minus
|
||||
* the number of waiting threads, g_async_queue_length == 0 could also
|
||||
* mean 'n' entries in the queue and 'n' thread waiting. Such can
|
||||
* happen due to locking of the queue or due to scheduling.
|
||||
*/
|
||||
gint g_async_queue_length (GAsyncQueue *queue);
|
||||
gint g_async_queue_length_unlocked (GAsyncQueue *queue);
|
||||
void g_async_queue_sort (GAsyncQueue *queue,
|
||||
GCompareDataFunc func,
|
||||
gpointer user_data);
|
||||
void g_async_queue_sort_unlocked (GAsyncQueue *queue,
|
||||
GCompareDataFunc func,
|
||||
gpointer user_data);
|
||||
|
||||
/* Private API */
|
||||
GMutex* _g_async_queue_get_mutex (GAsyncQueue *queue);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_ASYNCQUEUE_H__ */
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,85 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* g_atomic_*: atomic operations.
|
||||
* Copyright (C) 2003 Sebastian Wilhelmi
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
|
||||
#error "Only <glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __G_ATOMIC_H__
|
||||
#define __G_ATOMIC_H__
|
||||
|
||||
#include <glib/gtypes.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
gint g_atomic_int_exchange_and_add (volatile gint G_GNUC_MAY_ALIAS *atomic,
|
||||
gint val);
|
||||
void g_atomic_int_add (volatile gint G_GNUC_MAY_ALIAS *atomic,
|
||||
gint val);
|
||||
gboolean g_atomic_int_compare_and_exchange (volatile gint G_GNUC_MAY_ALIAS *atomic,
|
||||
gint oldval,
|
||||
gint newval);
|
||||
gboolean g_atomic_pointer_compare_and_exchange (volatile gpointer G_GNUC_MAY_ALIAS *atomic,
|
||||
gpointer oldval,
|
||||
gpointer newval);
|
||||
|
||||
gint g_atomic_int_get (volatile gint G_GNUC_MAY_ALIAS *atomic);
|
||||
void g_atomic_int_set (volatile gint G_GNUC_MAY_ALIAS *atomic,
|
||||
gint newval);
|
||||
gpointer g_atomic_pointer_get (volatile gpointer G_GNUC_MAY_ALIAS *atomic);
|
||||
void g_atomic_pointer_set (volatile gpointer G_GNUC_MAY_ALIAS *atomic,
|
||||
gpointer newval);
|
||||
|
||||
#ifndef G_ATOMIC_OP_MEMORY_BARRIER_NEEDED
|
||||
# define g_atomic_int_get(atomic) ((gint)*(atomic))
|
||||
# define g_atomic_int_set(atomic, newval) ((void) (*(atomic) = (newval)))
|
||||
# define g_atomic_pointer_get(atomic) ((gpointer)*(atomic))
|
||||
# define g_atomic_pointer_set(atomic, newval) ((void) (*(atomic) = (newval)))
|
||||
#else
|
||||
# define g_atomic_int_get(atomic) \
|
||||
((void) sizeof (gchar [sizeof (*(atomic)) == sizeof (gint) ? 1 : -1]), \
|
||||
(g_atomic_int_get) ((volatile gint G_GNUC_MAY_ALIAS *) (void *) (atomic)))
|
||||
# define g_atomic_int_set(atomic, newval) \
|
||||
((void) sizeof (gchar [sizeof (*(atomic)) == sizeof (gint) ? 1 : -1]), \
|
||||
(g_atomic_int_set) ((volatile gint G_GNUC_MAY_ALIAS *) (void *) (atomic), (newval)))
|
||||
# define g_atomic_pointer_get(atomic) \
|
||||
((void) sizeof (gchar [sizeof (*(atomic)) == sizeof (gpointer) ? 1 : -1]), \
|
||||
(g_atomic_pointer_get) ((volatile gpointer G_GNUC_MAY_ALIAS *) (void *) (atomic)))
|
||||
# define g_atomic_pointer_set(atomic, newval) \
|
||||
((void) sizeof (gchar [sizeof (*(atomic)) == sizeof (gpointer) ? 1 : -1]), \
|
||||
(g_atomic_pointer_set) ((volatile gpointer G_GNUC_MAY_ALIAS *) (void *) (atomic), (newval)))
|
||||
#endif /* G_ATOMIC_OP_MEMORY_BARRIER_NEEDED */
|
||||
|
||||
#define g_atomic_int_inc(atomic) (g_atomic_int_add ((atomic), 1))
|
||||
#define g_atomic_int_dec_and_test(atomic) \
|
||||
(g_atomic_int_exchange_and_add ((atomic), -1) == 1)
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_ATOMIC_H__ */
|
|
@ -0,0 +1,308 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
/*
|
||||
* MT safe ; except for g_on_error_stack_trace, but who wants thread safety
|
||||
* then
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "glib.h"
|
||||
#include "gprintfint.h"
|
||||
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_TIMES_H
|
||||
#include <sys/times.h>
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#ifdef HAVE_SYS_WAIT_H
|
||||
#include <sys/wait.h>
|
||||
#endif
|
||||
|
||||
#include <time.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
#include <sys/select.h>
|
||||
#endif /* HAVE_SYS_SELECT_H */
|
||||
|
||||
#include <string.h> /* for bzero on BSD systems */
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
# define STRICT /* Strict typing, please */
|
||||
# define _WIN32_WINDOWS 0x0401 /* to get IsDebuggerPresent */
|
||||
# include <windows.h>
|
||||
# undef STRICT
|
||||
#endif
|
||||
|
||||
#ifndef NO_FD_SET
|
||||
# define SELECT_MASK fd_set
|
||||
#else
|
||||
# if defined(_IBMR2)
|
||||
# define SELECT_MASK void
|
||||
# else
|
||||
# define SELECT_MASK int
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include "galias.h"
|
||||
|
||||
#ifndef G_OS_WIN32
|
||||
static void stack_trace (char **args);
|
||||
#endif
|
||||
|
||||
extern volatile gboolean glib_on_error_halt;
|
||||
volatile gboolean glib_on_error_halt = TRUE;
|
||||
|
||||
void
|
||||
g_on_error_query (const gchar *prg_name)
|
||||
{
|
||||
#ifndef G_OS_WIN32
|
||||
static const gchar * const query1 = "[E]xit, [H]alt";
|
||||
static const gchar * const query2 = ", show [S]tack trace";
|
||||
static const gchar * const query3 = " or [P]roceed";
|
||||
gchar buf[16];
|
||||
|
||||
if (!prg_name)
|
||||
prg_name = g_get_prgname ();
|
||||
|
||||
retry:
|
||||
|
||||
if (prg_name)
|
||||
_g_fprintf (stdout,
|
||||
"%s (pid:%u): %s%s%s: ",
|
||||
prg_name,
|
||||
(guint) getpid (),
|
||||
query1,
|
||||
query2,
|
||||
query3);
|
||||
else
|
||||
_g_fprintf (stdout,
|
||||
"(process:%u): %s%s: ",
|
||||
(guint) getpid (),
|
||||
query1,
|
||||
query3);
|
||||
fflush (stdout);
|
||||
|
||||
if (isatty(0) && isatty(1))
|
||||
fgets (buf, 8, stdin);
|
||||
else
|
||||
strcpy (buf, "E\n");
|
||||
|
||||
if ((buf[0] == 'E' || buf[0] == 'e')
|
||||
&& buf[1] == '\n')
|
||||
_exit (0);
|
||||
else if ((buf[0] == 'P' || buf[0] == 'p')
|
||||
&& buf[1] == '\n')
|
||||
return;
|
||||
else if (prg_name
|
||||
&& (buf[0] == 'S' || buf[0] == 's')
|
||||
&& buf[1] == '\n')
|
||||
{
|
||||
g_on_error_stack_trace (prg_name);
|
||||
goto retry;
|
||||
}
|
||||
else if ((buf[0] == 'H' || buf[0] == 'h')
|
||||
&& buf[1] == '\n')
|
||||
{
|
||||
while (glib_on_error_halt)
|
||||
;
|
||||
glib_on_error_halt = TRUE;
|
||||
return;
|
||||
}
|
||||
else
|
||||
goto retry;
|
||||
#else
|
||||
if (!prg_name)
|
||||
prg_name = g_get_prgname ();
|
||||
|
||||
MessageBox (NULL, "g_on_error_query called, program terminating",
|
||||
(prg_name && *prg_name) ? prg_name : NULL,
|
||||
MB_OK|MB_ICONERROR);
|
||||
_exit(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
g_on_error_stack_trace (const gchar *prg_name)
|
||||
{
|
||||
#if defined(G_OS_UNIX) || defined(G_OS_BEOS)
|
||||
pid_t pid;
|
||||
gchar buf[16];
|
||||
gchar *args[4] = { "gdb", NULL, NULL, NULL };
|
||||
int status;
|
||||
|
||||
if (!prg_name)
|
||||
return;
|
||||
|
||||
_g_sprintf (buf, "%u", (guint) getpid ());
|
||||
|
||||
args[1] = (gchar*) prg_name;
|
||||
args[2] = buf;
|
||||
|
||||
pid = fork ();
|
||||
if (pid == 0)
|
||||
{
|
||||
stack_trace (args);
|
||||
_exit (0);
|
||||
}
|
||||
else if (pid == (pid_t) -1)
|
||||
{
|
||||
perror ("unable to fork gdb");
|
||||
return;
|
||||
}
|
||||
|
||||
waitpid (pid, &status, 0);
|
||||
#else
|
||||
if (IsDebuggerPresent ())
|
||||
G_BREAKPOINT ();
|
||||
else
|
||||
abort ();
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef G_OS_WIN32
|
||||
|
||||
static gboolean stack_trace_done = FALSE;
|
||||
|
||||
static void
|
||||
stack_trace_sigchld (int signum)
|
||||
{
|
||||
stack_trace_done = TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
stack_trace (char **args)
|
||||
{
|
||||
pid_t pid;
|
||||
int in_fd[2];
|
||||
int out_fd[2];
|
||||
SELECT_MASK fdset;
|
||||
SELECT_MASK readset;
|
||||
struct timeval tv;
|
||||
int sel, idx, state;
|
||||
char buffer[256];
|
||||
char c;
|
||||
|
||||
stack_trace_done = FALSE;
|
||||
signal (SIGCHLD, stack_trace_sigchld);
|
||||
|
||||
if ((pipe (in_fd) == -1) || (pipe (out_fd) == -1))
|
||||
{
|
||||
perror ("unable to open pipe");
|
||||
_exit (0);
|
||||
}
|
||||
|
||||
pid = fork ();
|
||||
if (pid == 0)
|
||||
{
|
||||
close (0); dup (in_fd[0]); /* set the stdin to the in pipe */
|
||||
close (1); dup (out_fd[1]); /* set the stdout to the out pipe */
|
||||
close (2); dup (out_fd[1]); /* set the stderr to the out pipe */
|
||||
|
||||
execvp (args[0], args); /* exec gdb */
|
||||
perror ("exec failed");
|
||||
_exit (0);
|
||||
}
|
||||
else if (pid == (pid_t) -1)
|
||||
{
|
||||
perror ("unable to fork");
|
||||
_exit (0);
|
||||
}
|
||||
|
||||
FD_ZERO (&fdset);
|
||||
FD_SET (out_fd[0], &fdset);
|
||||
|
||||
write (in_fd[1], "backtrace\n", 10);
|
||||
write (in_fd[1], "p x = 0\n", 8);
|
||||
write (in_fd[1], "quit\n", 5);
|
||||
|
||||
idx = 0;
|
||||
state = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
readset = fdset;
|
||||
tv.tv_sec = 1;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
sel = select (FD_SETSIZE, &readset, NULL, NULL, &tv);
|
||||
if (sel == -1)
|
||||
break;
|
||||
|
||||
if ((sel > 0) && (FD_ISSET (out_fd[0], &readset)))
|
||||
{
|
||||
if (read (out_fd[0], &c, 1))
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case 0:
|
||||
if (c == '#')
|
||||
{
|
||||
state = 1;
|
||||
idx = 0;
|
||||
buffer[idx++] = c;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
buffer[idx++] = c;
|
||||
if ((c == '\n') || (c == '\r'))
|
||||
{
|
||||
buffer[idx] = 0;
|
||||
_g_fprintf (stdout, "%s", buffer);
|
||||
state = 0;
|
||||
idx = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (stack_trace_done)
|
||||
break;
|
||||
}
|
||||
|
||||
close (in_fd[0]);
|
||||
close (in_fd[1]);
|
||||
close (out_fd[0]);
|
||||
close (out_fd[1]);
|
||||
_exit (0);
|
||||
}
|
||||
|
||||
#endif /* !G_OS_WIN32 */
|
||||
|
||||
#define __G_BACKTRACE_C__
|
||||
#include "galiasdef.c"
|
|
@ -0,0 +1,68 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
|
||||
#error "Only <glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __G_BACKTRACE_H__
|
||||
#define __G_BACKTRACE_H__
|
||||
|
||||
#include <glib/gtypes.h>
|
||||
#include <signal.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/* Fatal error handlers.
|
||||
* g_on_error_query() will prompt the user to either
|
||||
* [E]xit, [H]alt, [P]roceed or show [S]tack trace.
|
||||
* g_on_error_stack_trace() invokes gdb, which attaches to the current
|
||||
* process and shows a stack trace.
|
||||
* These function may cause different actions on non-unix platforms.
|
||||
* The prg_name arg is required by gdb to find the executable, if it is
|
||||
* passed as NULL, g_on_error_query() will try g_get_prgname().
|
||||
*/
|
||||
void g_on_error_query (const gchar *prg_name);
|
||||
void g_on_error_stack_trace (const gchar *prg_name);
|
||||
|
||||
/* Hacker macro to place breakpoints for selected machines.
|
||||
* Actual use is strongly discouraged of course ;)
|
||||
*/
|
||||
#if (defined (__i386__) || defined (__x86_64__)) && defined (__GNUC__) && __GNUC__ >= 2
|
||||
# define G_BREAKPOINT() G_STMT_START{ __asm__ __volatile__ ("int $03"); }G_STMT_END
|
||||
#elif (defined (_MSC_VER) || defined (__DMC__)) && defined (_M_IX86)
|
||||
# define G_BREAKPOINT() G_STMT_START{ __asm int 3h }G_STMT_END
|
||||
#elif defined (_MSC_VER)
|
||||
# define G_BREAKPOINT() G_STMT_START{ __debugbreak(); }G_STMT_END
|
||||
#elif defined (__alpha__) && !defined(__osf__) && defined (__GNUC__) && __GNUC__ >= 2
|
||||
# define G_BREAKPOINT() G_STMT_START{ __asm__ __volatile__ ("bpt"); }G_STMT_END
|
||||
#else /* !__i386__ && !__alpha__ */
|
||||
# define G_BREAKPOINT() G_STMT_START{ raise (SIGTRAP); }G_STMT_END
|
||||
#endif /* __i386__ */
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_BACKTRACE_H__ */
|
|
@ -0,0 +1,423 @@
|
|||
/* gbase64.c - Base64 encoding/decoding
|
||||
*
|
||||
* Copyright (C) 2006 Alexander Larsson <alexl@redhat.com>
|
||||
* Copyright (C) 2000-2003 Ximian Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* This is based on code in camel, written by:
|
||||
* Michael Zucchi <notzed@ximian.com>
|
||||
* Jeffrey Stedfast <fejj@ximian.com>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "gbase64.h"
|
||||
#include "glib.h"
|
||||
#include "glibintl.h"
|
||||
|
||||
#include "galias.h"
|
||||
|
||||
static const char base64_alphabet[] =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
/**
|
||||
* g_base64_encode_step:
|
||||
* @in: the binary data to encode
|
||||
* @len: the length of @in
|
||||
* @break_lines: whether to break long lines
|
||||
* @out: pointer to destination buffer
|
||||
* @state: Saved state between steps, initialize to 0
|
||||
* @save: Saved state between steps, initialize to 0
|
||||
*
|
||||
* Incrementally encode a sequence of binary data into its Base-64 stringified
|
||||
* representation. By calling this function multiple times you can convert
|
||||
* data in chunks to avoid having to have the full encoded data in memory.
|
||||
*
|
||||
* When all of the data has been converted you must call
|
||||
* g_base64_encode_close() to flush the saved state.
|
||||
*
|
||||
* The output buffer must be large enough to fit all the data that will
|
||||
* be written to it. Due to the way base64 encodes you will need
|
||||
* at least: (@len / 3 + 1) * 4 + 4 bytes (+ 4 may be needed in case of
|
||||
* non-zero state). If you enable line-breaking you will need at least:
|
||||
* ((@len / 3 + 1) * 4 + 4) / 72 + 1 bytes of extra space.
|
||||
*
|
||||
* @break_lines is typically used when putting base64-encoded data in emails.
|
||||
* It breaks the lines at 72 columns instead of putting all of the text on
|
||||
* the same line. This avoids problems with long lines in the email system.
|
||||
*
|
||||
* Return value: The number of bytes of output that was written
|
||||
*
|
||||
* Since: 2.12
|
||||
*/
|
||||
gsize
|
||||
g_base64_encode_step (const guchar *in,
|
||||
gsize len,
|
||||
gboolean break_lines,
|
||||
gchar *out,
|
||||
gint *state,
|
||||
gint *save)
|
||||
{
|
||||
char *outptr;
|
||||
const guchar *inptr;
|
||||
|
||||
g_return_val_if_fail (in != NULL, 0);
|
||||
g_return_val_if_fail (out != NULL, 0);
|
||||
g_return_val_if_fail (state != NULL, 0);
|
||||
g_return_val_if_fail (save != NULL, 0);
|
||||
|
||||
if (len <= 0)
|
||||
return 0;
|
||||
|
||||
inptr = in;
|
||||
outptr = out;
|
||||
|
||||
if (len + ((char *) save) [0] > 2)
|
||||
{
|
||||
const guchar *inend = in+len-2;
|
||||
int c1, c2, c3;
|
||||
int already;
|
||||
|
||||
already = *state;
|
||||
|
||||
switch (((char *) save) [0])
|
||||
{
|
||||
case 1:
|
||||
c1 = ((unsigned char *) save) [1];
|
||||
goto skip1;
|
||||
case 2:
|
||||
c1 = ((unsigned char *) save) [1];
|
||||
c2 = ((unsigned char *) save) [2];
|
||||
goto skip2;
|
||||
}
|
||||
|
||||
/*
|
||||
* yes, we jump into the loop, no i'm not going to change it,
|
||||
* it's beautiful!
|
||||
*/
|
||||
while (inptr < inend)
|
||||
{
|
||||
c1 = *inptr++;
|
||||
skip1:
|
||||
c2 = *inptr++;
|
||||
skip2:
|
||||
c3 = *inptr++;
|
||||
*outptr++ = base64_alphabet [ c1 >> 2 ];
|
||||
*outptr++ = base64_alphabet [ c2 >> 4 |
|
||||
((c1&0x3) << 4) ];
|
||||
*outptr++ = base64_alphabet [ ((c2 &0x0f) << 2) |
|
||||
(c3 >> 6) ];
|
||||
*outptr++ = base64_alphabet [ c3 & 0x3f ];
|
||||
/* this is a bit ugly ... */
|
||||
if (break_lines && (++already) >= 19)
|
||||
{
|
||||
*outptr++ = '\n';
|
||||
already = 0;
|
||||
}
|
||||
}
|
||||
|
||||
((char *)save)[0] = 0;
|
||||
len = 2 - (inptr - inend);
|
||||
*state = already;
|
||||
}
|
||||
|
||||
if (len>0)
|
||||
{
|
||||
char *saveout;
|
||||
|
||||
/* points to the slot for the next char to save */
|
||||
saveout = & (((char *)save)[1]) + ((char *)save)[0];
|
||||
|
||||
/* len can only be 0 1 or 2 */
|
||||
switch(len)
|
||||
{
|
||||
case 2: *saveout++ = *inptr++;
|
||||
case 1: *saveout++ = *inptr++;
|
||||
}
|
||||
((char *)save)[0] += len;
|
||||
}
|
||||
|
||||
return outptr - out;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_base64_encode_close:
|
||||
* @break_lines: whether to break long lines
|
||||
* @out: pointer to destination buffer
|
||||
* @state: Saved state from g_base64_encode_step()
|
||||
* @save: Saved state from g_base64_encode_step()
|
||||
*
|
||||
* Flush the status from a sequence of calls to g_base64_encode_step().
|
||||
*
|
||||
* Return value: The number of bytes of output that was written
|
||||
*
|
||||
* Since: 2.12
|
||||
*/
|
||||
gsize
|
||||
g_base64_encode_close (gboolean break_lines,
|
||||
gchar *out,
|
||||
gint *state,
|
||||
gint *save)
|
||||
{
|
||||
int c1, c2;
|
||||
char *outptr = out;
|
||||
|
||||
g_return_val_if_fail (out != NULL, 0);
|
||||
g_return_val_if_fail (state != NULL, 0);
|
||||
g_return_val_if_fail (save != NULL, 0);
|
||||
|
||||
c1 = ((unsigned char *) save) [1];
|
||||
c2 = ((unsigned char *) save) [2];
|
||||
|
||||
switch (((char *) save) [0])
|
||||
{
|
||||
case 2:
|
||||
outptr [2] = base64_alphabet[ ( (c2 &0x0f) << 2 ) ];
|
||||
g_assert (outptr [2] != 0);
|
||||
goto skip;
|
||||
case 1:
|
||||
outptr[2] = '=';
|
||||
skip:
|
||||
outptr [0] = base64_alphabet [ c1 >> 2 ];
|
||||
outptr [1] = base64_alphabet [ c2 >> 4 | ( (c1&0x3) << 4 )];
|
||||
outptr [3] = '=';
|
||||
outptr += 4;
|
||||
break;
|
||||
}
|
||||
if (break_lines)
|
||||
*outptr++ = '\n';
|
||||
|
||||
*save = 0;
|
||||
*state = 0;
|
||||
|
||||
return outptr - out;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_base64_encode:
|
||||
* @data: the binary data to encode
|
||||
* @len: the length of @data
|
||||
*
|
||||
* Encode a sequence of binary data into its Base-64 stringified
|
||||
* representation.
|
||||
*
|
||||
* Return value: a newly allocated, zero-terminated Base-64 encoded
|
||||
* string representing @data. The returned string must
|
||||
* be freed with g_free().
|
||||
*
|
||||
* Since: 2.12
|
||||
*/
|
||||
gchar *
|
||||
g_base64_encode (const guchar *data,
|
||||
gsize len)
|
||||
{
|
||||
gchar *out;
|
||||
gint state = 0, outlen;
|
||||
gint save = 0;
|
||||
|
||||
g_return_val_if_fail (data != NULL, NULL);
|
||||
g_return_val_if_fail (len > 0, NULL);
|
||||
|
||||
/* We can use a smaller limit here, since we know the saved state is 0,
|
||||
+1 is needed for trailing \0, also check for unlikely integer overflow */
|
||||
if (len >= ((G_MAXSIZE - 1) / 4 - 1) * 3)
|
||||
g_error("%s: input too large for Base64 encoding (%"G_GSIZE_FORMAT" chars)",
|
||||
G_STRLOC, len);
|
||||
|
||||
out = g_malloc ((len / 3 + 1) * 4 + 1);
|
||||
|
||||
outlen = g_base64_encode_step (data, len, FALSE, out, &state, &save);
|
||||
outlen += g_base64_encode_close (FALSE, out + outlen, &state, &save);
|
||||
out[outlen] = '\0';
|
||||
|
||||
return (gchar *) out;
|
||||
}
|
||||
|
||||
static const unsigned char mime_base64_rank[256] = {
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255, 62,255,255,255, 63,
|
||||
52, 53, 54, 55, 56, 57, 58, 59, 60, 61,255,255,255, 0,255,255,
|
||||
255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
|
||||
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,255,255,255,255,255,
|
||||
255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
|
||||
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
};
|
||||
|
||||
/**
|
||||
* g_base64_decode_step:
|
||||
* @in: binary input data
|
||||
* @len: max length of @in data to decode
|
||||
* @out: output buffer
|
||||
* @state: Saved state between steps, initialize to 0
|
||||
* @save: Saved state between steps, initialize to 0
|
||||
*
|
||||
* Incrementally decode a sequence of binary data from its Base-64 stringified
|
||||
* representation. By calling this function multiple times you can convert
|
||||
* data in chunks to avoid having to have the full encoded data in memory.
|
||||
*
|
||||
* The output buffer must be large enough to fit all the data that will
|
||||
* be written to it. Since base64 encodes 3 bytes in 4 chars you need
|
||||
* at least: (@len / 4) * 3 + 3 bytes (+ 3 may be needed in case of non-zero
|
||||
* state).
|
||||
*
|
||||
* Return value: The number of bytes of output that was written
|
||||
*
|
||||
* Since: 2.12
|
||||
**/
|
||||
gsize
|
||||
g_base64_decode_step (const gchar *in,
|
||||
gsize len,
|
||||
guchar *out,
|
||||
gint *state,
|
||||
guint *save)
|
||||
{
|
||||
const guchar *inptr;
|
||||
guchar *outptr;
|
||||
const guchar *inend;
|
||||
guchar c, rank;
|
||||
guchar last[2];
|
||||
unsigned int v;
|
||||
int i;
|
||||
|
||||
g_return_val_if_fail (in != NULL, 0);
|
||||
g_return_val_if_fail (out != NULL, 0);
|
||||
g_return_val_if_fail (state != NULL, 0);
|
||||
g_return_val_if_fail (save != NULL, 0);
|
||||
|
||||
if (len <= 0)
|
||||
return 0;
|
||||
|
||||
inend = (const guchar *)in+len;
|
||||
outptr = out;
|
||||
|
||||
/* convert 4 base64 bytes to 3 normal bytes */
|
||||
v=*save;
|
||||
i=*state;
|
||||
inptr = (const guchar *)in;
|
||||
last[0] = last[1] = 0;
|
||||
while (inptr < inend)
|
||||
{
|
||||
c = *inptr++;
|
||||
rank = mime_base64_rank [c];
|
||||
if (rank != 0xff)
|
||||
{
|
||||
last[1] = last[0];
|
||||
last[0] = c;
|
||||
v = (v<<6) | rank;
|
||||
i++;
|
||||
if (i==4)
|
||||
{
|
||||
*outptr++ = v>>16;
|
||||
if (last[1] != '=')
|
||||
*outptr++ = v>>8;
|
||||
if (last[0] != '=')
|
||||
*outptr++ = v;
|
||||
i=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*save = v;
|
||||
*state = i;
|
||||
|
||||
return outptr - out;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_base64_decode:
|
||||
* @text: zero-terminated string with base64 text to decode
|
||||
* @out_len: The length of the decoded data is written here
|
||||
*
|
||||
* Decode a sequence of Base-64 encoded text into binary data
|
||||
*
|
||||
* Return value: a newly allocated buffer containing the binary data
|
||||
* that @text represents. The returned buffer must
|
||||
* be freed with g_free().
|
||||
*
|
||||
* Since: 2.12
|
||||
*/
|
||||
guchar *
|
||||
g_base64_decode (const gchar *text,
|
||||
gsize *out_len)
|
||||
{
|
||||
guchar *ret;
|
||||
gsize input_length;
|
||||
gint state = 0;
|
||||
guint save = 0;
|
||||
|
||||
g_return_val_if_fail (text != NULL, NULL);
|
||||
g_return_val_if_fail (out_len != NULL, NULL);
|
||||
|
||||
input_length = strlen (text);
|
||||
|
||||
g_return_val_if_fail (input_length > 1, NULL);
|
||||
|
||||
/* We can use a smaller limit here, since we know the saved state is 0,
|
||||
+1 used to avoid calling g_malloc0(0), and hence retruning NULL */
|
||||
ret = g_malloc0 ((input_length / 4) * 3 + 1);
|
||||
|
||||
*out_len = g_base64_decode_step (text, input_length, ret, &state, &save);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_base64_decode_inplace:
|
||||
* @text: zero-terminated string with base64 text to decode
|
||||
* @out_len: The length of the decoded data is written here
|
||||
*
|
||||
* Decode a sequence of Base-64 encoded text into binary data
|
||||
* by overwriting the input data.
|
||||
*
|
||||
* Return value: The binary data that @text responds. This pointer
|
||||
* is the same as the input @text.
|
||||
*
|
||||
* Since: 2.20
|
||||
*/
|
||||
guchar *
|
||||
g_base64_decode_inplace (gchar *text,
|
||||
gsize *out_len)
|
||||
{
|
||||
gint input_length, state = 0;
|
||||
guint save = 0;
|
||||
|
||||
g_return_val_if_fail (text != NULL, NULL);
|
||||
g_return_val_if_fail (out_len != NULL, NULL);
|
||||
|
||||
input_length = strlen (text);
|
||||
|
||||
g_return_val_if_fail (input_length > 1, NULL);
|
||||
|
||||
*out_len = g_base64_decode_step (text, input_length, (guchar *) text, &state, &save);
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
#define __G_BASE64_C__
|
||||
#include "galiasdef.c"
|
|
@ -0,0 +1,57 @@
|
|||
/* gbase64.h - Base64 coding functions
|
||||
*
|
||||
* Copyright (C) 2005 Alexander Larsson <alexl@redhat.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
|
||||
#error "Only <glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __G_BASE64_H__
|
||||
#define __G_BASE64_H__
|
||||
|
||||
#include <glib/gtypes.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
gsize g_base64_encode_step (const guchar *in,
|
||||
gsize len,
|
||||
gboolean break_lines,
|
||||
gchar *out,
|
||||
gint *state,
|
||||
gint *save);
|
||||
gsize g_base64_encode_close (gboolean break_lines,
|
||||
gchar *out,
|
||||
gint *state,
|
||||
gint *save);
|
||||
gchar* g_base64_encode (const guchar *data,
|
||||
gsize len) G_GNUC_MALLOC;
|
||||
gsize g_base64_decode_step (const gchar *in,
|
||||
gsize len,
|
||||
guchar *out,
|
||||
gint *state,
|
||||
guint *save);
|
||||
guchar *g_base64_decode (const gchar *text,
|
||||
gsize *out_len) G_GNUC_MALLOC;
|
||||
guchar *g_base64_decode_inplace (gchar *text,
|
||||
gsize *out_len);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_BASE64_H__ */
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,191 @@
|
|||
/* gbookmarkfile.h: parsing and building desktop bookmarks
|
||||
*
|
||||
* Copyright (C) 2005-2006 Emmanuele Bassi
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
*/
|
||||
|
||||
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
|
||||
#error "Only <glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __G_BOOKMARK_FILE_H__
|
||||
#define __G_BOOKMARK_FILE_H__
|
||||
|
||||
#include <glib/gerror.h>
|
||||
#include <time.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/* GError enumeration
|
||||
*/
|
||||
#define G_BOOKMARK_FILE_ERROR (g_bookmark_file_error_quark ())
|
||||
|
||||
typedef enum
|
||||
{
|
||||
G_BOOKMARK_FILE_ERROR_INVALID_URI,
|
||||
G_BOOKMARK_FILE_ERROR_INVALID_VALUE,
|
||||
G_BOOKMARK_FILE_ERROR_APP_NOT_REGISTERED,
|
||||
G_BOOKMARK_FILE_ERROR_URI_NOT_FOUND,
|
||||
G_BOOKMARK_FILE_ERROR_READ,
|
||||
G_BOOKMARK_FILE_ERROR_UNKNOWN_ENCODING,
|
||||
G_BOOKMARK_FILE_ERROR_WRITE,
|
||||
G_BOOKMARK_FILE_ERROR_FILE_NOT_FOUND
|
||||
} GBookmarkFileError;
|
||||
|
||||
GQuark g_bookmark_file_error_quark (void);
|
||||
|
||||
/*
|
||||
* GBookmarkFile
|
||||
*/
|
||||
typedef struct _GBookmarkFile GBookmarkFile;
|
||||
|
||||
GBookmarkFile *g_bookmark_file_new (void);
|
||||
void g_bookmark_file_free (GBookmarkFile *bookmark);
|
||||
|
||||
gboolean g_bookmark_file_load_from_file (GBookmarkFile *bookmark,
|
||||
const gchar *filename,
|
||||
GError **error);
|
||||
gboolean g_bookmark_file_load_from_data (GBookmarkFile *bookmark,
|
||||
const gchar *data,
|
||||
gsize length,
|
||||
GError **error);
|
||||
gboolean g_bookmark_file_load_from_data_dirs (GBookmarkFile *bookmark,
|
||||
const gchar *file,
|
||||
gchar **full_path,
|
||||
GError **error);
|
||||
gchar * g_bookmark_file_to_data (GBookmarkFile *bookmark,
|
||||
gsize *length,
|
||||
GError **error) G_GNUC_MALLOC;
|
||||
gboolean g_bookmark_file_to_file (GBookmarkFile *bookmark,
|
||||
const gchar *filename,
|
||||
GError **error);
|
||||
|
||||
void g_bookmark_file_set_title (GBookmarkFile *bookmark,
|
||||
const gchar *uri,
|
||||
const gchar *title);
|
||||
gchar * g_bookmark_file_get_title (GBookmarkFile *bookmark,
|
||||
const gchar *uri,
|
||||
GError **error) G_GNUC_MALLOC;
|
||||
void g_bookmark_file_set_description (GBookmarkFile *bookmark,
|
||||
const gchar *uri,
|
||||
const gchar *description);
|
||||
gchar * g_bookmark_file_get_description (GBookmarkFile *bookmark,
|
||||
const gchar *uri,
|
||||
GError **error) G_GNUC_MALLOC;
|
||||
void g_bookmark_file_set_mime_type (GBookmarkFile *bookmark,
|
||||
const gchar *uri,
|
||||
const gchar *mime_type);
|
||||
gchar * g_bookmark_file_get_mime_type (GBookmarkFile *bookmark,
|
||||
const gchar *uri,
|
||||
GError **error) G_GNUC_MALLOC;
|
||||
void g_bookmark_file_set_groups (GBookmarkFile *bookmark,
|
||||
const gchar *uri,
|
||||
const gchar **groups,
|
||||
gsize length);
|
||||
void g_bookmark_file_add_group (GBookmarkFile *bookmark,
|
||||
const gchar *uri,
|
||||
const gchar *group);
|
||||
gboolean g_bookmark_file_has_group (GBookmarkFile *bookmark,
|
||||
const gchar *uri,
|
||||
const gchar *group,
|
||||
GError **error);
|
||||
gchar ** g_bookmark_file_get_groups (GBookmarkFile *bookmark,
|
||||
const gchar *uri,
|
||||
gsize *length,
|
||||
GError **error) G_GNUC_MALLOC;
|
||||
void g_bookmark_file_add_application (GBookmarkFile *bookmark,
|
||||
const gchar *uri,
|
||||
const gchar *name,
|
||||
const gchar *exec);
|
||||
gboolean g_bookmark_file_has_application (GBookmarkFile *bookmark,
|
||||
const gchar *uri,
|
||||
const gchar *name,
|
||||
GError **error);
|
||||
gchar ** g_bookmark_file_get_applications (GBookmarkFile *bookmark,
|
||||
const gchar *uri,
|
||||
gsize *length,
|
||||
GError **error) G_GNUC_MALLOC;
|
||||
gboolean g_bookmark_file_set_app_info (GBookmarkFile *bookmark,
|
||||
const gchar *uri,
|
||||
const gchar *name,
|
||||
const gchar *exec,
|
||||
gint count,
|
||||
time_t stamp,
|
||||
GError **error);
|
||||
gboolean g_bookmark_file_get_app_info (GBookmarkFile *bookmark,
|
||||
const gchar *uri,
|
||||
const gchar *name,
|
||||
gchar **exec,
|
||||
guint *count,
|
||||
time_t *stamp,
|
||||
GError **error);
|
||||
void g_bookmark_file_set_is_private (GBookmarkFile *bookmark,
|
||||
const gchar *uri,
|
||||
gboolean is_private);
|
||||
gboolean g_bookmark_file_get_is_private (GBookmarkFile *bookmark,
|
||||
const gchar *uri,
|
||||
GError **error);
|
||||
void g_bookmark_file_set_icon (GBookmarkFile *bookmark,
|
||||
const gchar *uri,
|
||||
const gchar *href,
|
||||
const gchar *mime_type);
|
||||
gboolean g_bookmark_file_get_icon (GBookmarkFile *bookmark,
|
||||
const gchar *uri,
|
||||
gchar **href,
|
||||
gchar **mime_type,
|
||||
GError **error);
|
||||
void g_bookmark_file_set_added (GBookmarkFile *bookmark,
|
||||
const gchar *uri,
|
||||
time_t added);
|
||||
time_t g_bookmark_file_get_added (GBookmarkFile *bookmark,
|
||||
const gchar *uri,
|
||||
GError **error);
|
||||
void g_bookmark_file_set_modified (GBookmarkFile *bookmark,
|
||||
const gchar *uri,
|
||||
time_t modified);
|
||||
time_t g_bookmark_file_get_modified (GBookmarkFile *bookmark,
|
||||
const gchar *uri,
|
||||
GError **error);
|
||||
void g_bookmark_file_set_visited (GBookmarkFile *bookmark,
|
||||
const gchar *uri,
|
||||
time_t visited);
|
||||
time_t g_bookmark_file_get_visited (GBookmarkFile *bookmark,
|
||||
const gchar *uri,
|
||||
GError **error);
|
||||
gboolean g_bookmark_file_has_item (GBookmarkFile *bookmark,
|
||||
const gchar *uri);
|
||||
gint g_bookmark_file_get_size (GBookmarkFile *bookmark);
|
||||
gchar ** g_bookmark_file_get_uris (GBookmarkFile *bookmark,
|
||||
gsize *length) G_GNUC_MALLOC;
|
||||
gboolean g_bookmark_file_remove_group (GBookmarkFile *bookmark,
|
||||
const gchar *uri,
|
||||
const gchar *group,
|
||||
GError **error);
|
||||
gboolean g_bookmark_file_remove_application (GBookmarkFile *bookmark,
|
||||
const gchar *uri,
|
||||
const gchar *name,
|
||||
GError **error);
|
||||
gboolean g_bookmark_file_remove_item (GBookmarkFile *bookmark,
|
||||
const gchar *uri,
|
||||
GError **error);
|
||||
gboolean g_bookmark_file_move_item (GBookmarkFile *bookmark,
|
||||
const gchar *old_uri,
|
||||
const gchar *new_uri,
|
||||
GError **error);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_BOOKMARK_FILE_H__ */
|
|
@ -0,0 +1,303 @@
|
|||
/* GBSearchArray - Binary Searchable Array implementation
|
||||
* Copyright (C) 2000-2003 Tim Janik
|
||||
*
|
||||
* This software is provided "as is"; redistribution and modification
|
||||
* is permitted, provided that the following disclaimer is retained.
|
||||
*
|
||||
* This software 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.
|
||||
* In no event shall the authors or contributors be liable for any
|
||||
* direct, indirect, incidental, special, exemplary, or consequential
|
||||
* damages (including, but not limited to, procurement of substitute
|
||||
* goods or services; loss of use, data, or profits; or business
|
||||
* interruption) however caused and on any theory of liability, whether
|
||||
* in contract, strict liability, or tort (including negligence or
|
||||
* otherwise) arising in any way out of the use of this software, even
|
||||
* if advised of the possibility of such damage.
|
||||
*/
|
||||
#ifndef __G_BSEARCH_ARRAY_H__
|
||||
#define __G_BSEARCH_ARRAY_H__
|
||||
|
||||
#include <glib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
G_BEGIN_DECLS /* c++ guards */
|
||||
|
||||
/* this implementation is intended to be usable in third-party code
|
||||
* simply by pasting the contents of this file. as such, the
|
||||
* implementation needs to be self-contained within this file.
|
||||
*/
|
||||
|
||||
/* convenience macro to avoid signed overflow for value comparisions */
|
||||
#define G_BSEARCH_ARRAY_CMP(v1,v2) ((v1) > (v2) ? +1 : (v1) == (v2) ? 0 : -1)
|
||||
|
||||
|
||||
/* --- typedefs --- */
|
||||
typedef gint (*GBSearchCompareFunc) (gconstpointer bsearch_node1, /* key */
|
||||
gconstpointer bsearch_node2);
|
||||
typedef enum
|
||||
{
|
||||
G_BSEARCH_ARRAY_ALIGN_POWER2 = 1 << 0, /* align memory to power2 sizes */
|
||||
G_BSEARCH_ARRAY_AUTO_SHRINK = 1 << 1 /* shrink array upon removal */
|
||||
} GBSearchArrayFlags;
|
||||
|
||||
|
||||
/* --- structures --- */
|
||||
typedef struct
|
||||
{
|
||||
guint sizeof_node;
|
||||
GBSearchCompareFunc cmp_nodes;
|
||||
guint flags;
|
||||
} GBSearchConfig;
|
||||
typedef union
|
||||
{
|
||||
guint n_nodes;
|
||||
/*< private >*/
|
||||
gpointer alignment_dummy1;
|
||||
glong alignment_dummy2;
|
||||
gdouble alignment_dummy3;
|
||||
} GBSearchArray;
|
||||
|
||||
|
||||
/* --- public API --- */
|
||||
static inline GBSearchArray* g_bsearch_array_create (const GBSearchConfig *bconfig);
|
||||
static inline gpointer g_bsearch_array_get_nth (GBSearchArray *barray,
|
||||
const GBSearchConfig *bconfig,
|
||||
guint nth);
|
||||
static inline guint g_bsearch_array_get_index (GBSearchArray *barray,
|
||||
const GBSearchConfig *bconfig,
|
||||
gconstpointer node_in_array);
|
||||
static inline GBSearchArray* g_bsearch_array_remove (GBSearchArray *barray,
|
||||
const GBSearchConfig *bconfig,
|
||||
guint index_);
|
||||
/* provide uninitialized space at index for node insertion */
|
||||
static inline GBSearchArray* g_bsearch_array_grow (GBSearchArray *barray,
|
||||
const GBSearchConfig *bconfig,
|
||||
guint index);
|
||||
/* insert key_node into array if it does not exist, otherwise do nothing */
|
||||
static inline GBSearchArray* g_bsearch_array_insert (GBSearchArray *barray,
|
||||
const GBSearchConfig *bconfig,
|
||||
gconstpointer key_node);
|
||||
/* insert key_node into array if it does not exist,
|
||||
* otherwise replace the existing node's contents with key_node
|
||||
*/
|
||||
static inline GBSearchArray* g_bsearch_array_replace (GBSearchArray *barray,
|
||||
const GBSearchConfig *bconfig,
|
||||
gconstpointer key_node);
|
||||
static inline void g_bsearch_array_free (GBSearchArray *barray,
|
||||
const GBSearchConfig *bconfig);
|
||||
#define g_bsearch_array_get_n_nodes(barray) (((GBSearchArray*) (barray))->n_nodes)
|
||||
|
||||
/* g_bsearch_array_lookup():
|
||||
* return NULL or exact match node
|
||||
*/
|
||||
#define g_bsearch_array_lookup(barray, bconfig, key_node) \
|
||||
g_bsearch_array_lookup_fuzzy ((barray), (bconfig), (key_node), 0)
|
||||
|
||||
/* g_bsearch_array_lookup_sibling():
|
||||
* return NULL for barray->n_nodes==0, otherwise return the
|
||||
* exact match node, or, if there's no such node, return the
|
||||
* node last visited, which is pretty close to an exact match
|
||||
* (will be one off into either direction).
|
||||
*/
|
||||
#define g_bsearch_array_lookup_sibling(barray, bconfig, key_node) \
|
||||
g_bsearch_array_lookup_fuzzy ((barray), (bconfig), (key_node), 1)
|
||||
|
||||
/* g_bsearch_array_lookup_insertion():
|
||||
* return NULL for barray->n_nodes==0 or exact match, otherwise
|
||||
* return the node where key_node should be inserted (may be one
|
||||
* after end, i.e. g_bsearch_array_get_index(result) <= barray->n_nodes).
|
||||
*/
|
||||
#define g_bsearch_array_lookup_insertion(barray, bconfig, key_node) \
|
||||
g_bsearch_array_lookup_fuzzy ((barray), (bconfig), (key_node), 2)
|
||||
|
||||
|
||||
/* --- implementation --- */
|
||||
/* helper macro to cut down realloc()s */
|
||||
#ifdef DISABLE_MEM_POOLS
|
||||
#define G_BSEARCH_UPPER_POWER2(n) (n)
|
||||
#else /* !DISABLE_MEM_POOLS */
|
||||
#define G_BSEARCH_UPPER_POWER2(n) ((n) ? 1 << g_bit_storage ((n) - 1) : 0)
|
||||
#endif /* !DISABLE_MEM_POOLS */
|
||||
#define G_BSEARCH_ARRAY_NODES(barray) (((guint8*) (barray)) + sizeof (GBSearchArray))
|
||||
static inline GBSearchArray*
|
||||
g_bsearch_array_create (const GBSearchConfig *bconfig)
|
||||
{
|
||||
GBSearchArray *barray;
|
||||
guint size;
|
||||
|
||||
g_return_val_if_fail (bconfig != NULL, NULL);
|
||||
|
||||
size = sizeof (GBSearchArray) + bconfig->sizeof_node;
|
||||
if (bconfig->flags & G_BSEARCH_ARRAY_ALIGN_POWER2)
|
||||
size = G_BSEARCH_UPPER_POWER2 (size);
|
||||
barray = (GBSearchArray *) g_realloc (NULL, size);
|
||||
memset (barray, 0, sizeof (GBSearchArray));
|
||||
|
||||
return barray;
|
||||
}
|
||||
static inline gpointer
|
||||
g_bsearch_array_lookup_fuzzy (GBSearchArray *barray,
|
||||
const GBSearchConfig *bconfig,
|
||||
gconstpointer key_node,
|
||||
const guint sibling_or_after);
|
||||
static inline gpointer
|
||||
g_bsearch_array_lookup_fuzzy (GBSearchArray *barray,
|
||||
const GBSearchConfig *bconfig,
|
||||
gconstpointer key_node,
|
||||
const guint sibling_or_after)
|
||||
{
|
||||
GBSearchCompareFunc cmp_nodes = bconfig->cmp_nodes;
|
||||
guint8 *check = NULL, *nodes = G_BSEARCH_ARRAY_NODES (barray);
|
||||
guint n_nodes = barray->n_nodes, offs = 0;
|
||||
guint sizeof_node = bconfig->sizeof_node;
|
||||
gint cmp = 0;
|
||||
|
||||
while (offs < n_nodes)
|
||||
{
|
||||
guint i = (offs + n_nodes) >> 1;
|
||||
|
||||
check = nodes + i * sizeof_node;
|
||||
cmp = cmp_nodes (key_node, check);
|
||||
if (cmp == 0)
|
||||
return sibling_or_after > 1 ? NULL : check;
|
||||
else if (cmp < 0)
|
||||
n_nodes = i;
|
||||
else /* (cmp > 0) */
|
||||
offs = i + 1;
|
||||
}
|
||||
|
||||
/* check is last mismatch, cmp > 0 indicates greater key */
|
||||
return G_LIKELY (!sibling_or_after) ? NULL : (sibling_or_after > 1 && cmp > 0) ? check + sizeof_node : check;
|
||||
}
|
||||
static inline gpointer
|
||||
g_bsearch_array_get_nth (GBSearchArray *barray,
|
||||
const GBSearchConfig *bconfig,
|
||||
guint nth)
|
||||
{
|
||||
return (G_LIKELY (nth < barray->n_nodes) ?
|
||||
G_BSEARCH_ARRAY_NODES (barray) + nth * bconfig->sizeof_node :
|
||||
NULL);
|
||||
}
|
||||
static inline guint
|
||||
g_bsearch_array_get_index (GBSearchArray *barray,
|
||||
const GBSearchConfig *bconfig,
|
||||
gconstpointer node_in_array)
|
||||
{
|
||||
guint distance = ((guint8*) node_in_array) - G_BSEARCH_ARRAY_NODES (barray);
|
||||
|
||||
g_return_val_if_fail (node_in_array != NULL, barray->n_nodes);
|
||||
|
||||
distance /= bconfig->sizeof_node;
|
||||
|
||||
return MIN (distance, barray->n_nodes + 1); /* may return one after end */
|
||||
}
|
||||
static inline GBSearchArray*
|
||||
g_bsearch_array_grow (GBSearchArray *barray,
|
||||
const GBSearchConfig *bconfig,
|
||||
guint index_)
|
||||
{
|
||||
guint old_size = barray->n_nodes * bconfig->sizeof_node;
|
||||
guint new_size = old_size + bconfig->sizeof_node;
|
||||
guint8 *node;
|
||||
|
||||
g_return_val_if_fail (index_ <= barray->n_nodes, NULL);
|
||||
|
||||
if (G_UNLIKELY (bconfig->flags & G_BSEARCH_ARRAY_ALIGN_POWER2))
|
||||
{
|
||||
new_size = G_BSEARCH_UPPER_POWER2 (sizeof (GBSearchArray) + new_size);
|
||||
old_size = G_BSEARCH_UPPER_POWER2 (sizeof (GBSearchArray) + old_size);
|
||||
if (old_size != new_size)
|
||||
barray = (GBSearchArray *) g_realloc (barray, new_size);
|
||||
}
|
||||
else
|
||||
barray = (GBSearchArray *) g_realloc (barray, sizeof (GBSearchArray) + new_size);
|
||||
node = G_BSEARCH_ARRAY_NODES (barray) + index_ * bconfig->sizeof_node;
|
||||
g_memmove (node + bconfig->sizeof_node, node, (barray->n_nodes - index_) * bconfig->sizeof_node);
|
||||
barray->n_nodes += 1;
|
||||
return barray;
|
||||
}
|
||||
static inline GBSearchArray*
|
||||
g_bsearch_array_insert (GBSearchArray *barray,
|
||||
const GBSearchConfig *bconfig,
|
||||
gconstpointer key_node)
|
||||
{
|
||||
guint8 *node;
|
||||
|
||||
if (G_UNLIKELY (!barray->n_nodes))
|
||||
{
|
||||
barray = g_bsearch_array_grow (barray, bconfig, 0);
|
||||
node = G_BSEARCH_ARRAY_NODES (barray);
|
||||
}
|
||||
else
|
||||
{
|
||||
node = (guint8 *) g_bsearch_array_lookup_insertion (barray, bconfig, key_node);
|
||||
if (G_LIKELY (node))
|
||||
{
|
||||
guint index_ = g_bsearch_array_get_index (barray, bconfig, node);
|
||||
|
||||
/* grow and insert */
|
||||
barray = g_bsearch_array_grow (barray, bconfig, index_);
|
||||
node = G_BSEARCH_ARRAY_NODES (barray) + index_ * bconfig->sizeof_node;
|
||||
}
|
||||
else /* no insertion needed, node already there */
|
||||
return barray;
|
||||
}
|
||||
memcpy (node, key_node, bconfig->sizeof_node);
|
||||
return barray;
|
||||
}
|
||||
static inline GBSearchArray*
|
||||
g_bsearch_array_replace (GBSearchArray *barray,
|
||||
const GBSearchConfig *bconfig,
|
||||
gconstpointer key_node)
|
||||
{
|
||||
guint8 *node = (guint8 *) g_bsearch_array_lookup (barray, bconfig, key_node);
|
||||
if (G_LIKELY (node)) /* expected path */
|
||||
memcpy (node, key_node, bconfig->sizeof_node);
|
||||
else /* revert to insertion */
|
||||
barray = g_bsearch_array_insert (barray, bconfig, key_node);
|
||||
return barray;
|
||||
}
|
||||
static inline GBSearchArray*
|
||||
g_bsearch_array_remove (GBSearchArray *barray,
|
||||
const GBSearchConfig *bconfig,
|
||||
guint index_)
|
||||
{
|
||||
guint8 *node;
|
||||
|
||||
g_return_val_if_fail (index_ < barray->n_nodes, NULL);
|
||||
|
||||
barray->n_nodes -= 1;
|
||||
node = G_BSEARCH_ARRAY_NODES (barray) + index_ * bconfig->sizeof_node;
|
||||
g_memmove (node, node + bconfig->sizeof_node, (barray->n_nodes - index_) * bconfig->sizeof_node);
|
||||
if (G_UNLIKELY (bconfig->flags & G_BSEARCH_ARRAY_AUTO_SHRINK))
|
||||
{
|
||||
guint new_size = barray->n_nodes * bconfig->sizeof_node;
|
||||
guint old_size = new_size + bconfig->sizeof_node;
|
||||
|
||||
if (G_UNLIKELY (bconfig->flags & G_BSEARCH_ARRAY_ALIGN_POWER2))
|
||||
{
|
||||
new_size = G_BSEARCH_UPPER_POWER2 (sizeof (GBSearchArray) + new_size);
|
||||
old_size = G_BSEARCH_UPPER_POWER2 (sizeof (GBSearchArray) + old_size);
|
||||
if (old_size != new_size)
|
||||
barray = (GBSearchArray *) g_realloc (barray, new_size);
|
||||
}
|
||||
else
|
||||
barray = (GBSearchArray *) g_realloc (barray, sizeof (GBSearchArray) + new_size);
|
||||
}
|
||||
return barray;
|
||||
}
|
||||
static inline void
|
||||
g_bsearch_array_free (GBSearchArray *barray,
|
||||
const GBSearchConfig *bconfig)
|
||||
{
|
||||
g_return_if_fail (barray != NULL);
|
||||
|
||||
g_free (barray);
|
||||
}
|
||||
|
||||
G_END_DECLS /* c++ guards */
|
||||
|
||||
#endif /* !__G_BSEARCH_ARRAY_H__ */
|
|
@ -0,0 +1,197 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
/*
|
||||
* MT safe
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "glib.h"
|
||||
#include "galias.h"
|
||||
|
||||
|
||||
typedef struct _GCacheNode GCacheNode;
|
||||
|
||||
struct _GCacheNode
|
||||
{
|
||||
/* A reference counted node */
|
||||
gpointer value;
|
||||
gint ref_count;
|
||||
};
|
||||
|
||||
struct _GCache
|
||||
{
|
||||
/* Called to create a value from a key */
|
||||
GCacheNewFunc value_new_func;
|
||||
|
||||
/* Called to destroy a value */
|
||||
GCacheDestroyFunc value_destroy_func;
|
||||
|
||||
/* Called to duplicate a key */
|
||||
GCacheDupFunc key_dup_func;
|
||||
|
||||
/* Called to destroy a key */
|
||||
GCacheDestroyFunc key_destroy_func;
|
||||
|
||||
/* Associates keys with nodes */
|
||||
GHashTable *key_table;
|
||||
|
||||
/* Associates nodes with keys */
|
||||
GHashTable *value_table;
|
||||
};
|
||||
|
||||
static inline GCacheNode*
|
||||
g_cache_node_new (gpointer value)
|
||||
{
|
||||
GCacheNode *node = g_slice_new (GCacheNode);
|
||||
node->value = value;
|
||||
node->ref_count = 1;
|
||||
return node;
|
||||
}
|
||||
|
||||
static inline void
|
||||
g_cache_node_destroy (GCacheNode *node)
|
||||
{
|
||||
g_slice_free (GCacheNode, node);
|
||||
}
|
||||
|
||||
GCache*
|
||||
g_cache_new (GCacheNewFunc value_new_func,
|
||||
GCacheDestroyFunc value_destroy_func,
|
||||
GCacheDupFunc key_dup_func,
|
||||
GCacheDestroyFunc key_destroy_func,
|
||||
GHashFunc hash_key_func,
|
||||
GHashFunc hash_value_func,
|
||||
GEqualFunc key_equal_func)
|
||||
{
|
||||
GCache *cache;
|
||||
|
||||
g_return_val_if_fail (value_new_func != NULL, NULL);
|
||||
g_return_val_if_fail (value_destroy_func != NULL, NULL);
|
||||
g_return_val_if_fail (key_dup_func != NULL, NULL);
|
||||
g_return_val_if_fail (key_destroy_func != NULL, NULL);
|
||||
g_return_val_if_fail (hash_key_func != NULL, NULL);
|
||||
g_return_val_if_fail (hash_value_func != NULL, NULL);
|
||||
g_return_val_if_fail (key_equal_func != NULL, NULL);
|
||||
|
||||
cache = g_slice_new (GCache);
|
||||
cache->value_new_func = value_new_func;
|
||||
cache->value_destroy_func = value_destroy_func;
|
||||
cache->key_dup_func = key_dup_func;
|
||||
cache->key_destroy_func = key_destroy_func;
|
||||
cache->key_table = g_hash_table_new (hash_key_func, key_equal_func);
|
||||
cache->value_table = g_hash_table_new (hash_value_func, NULL);
|
||||
|
||||
return cache;
|
||||
}
|
||||
|
||||
void
|
||||
g_cache_destroy (GCache *cache)
|
||||
{
|
||||
g_return_if_fail (cache != NULL);
|
||||
|
||||
g_hash_table_destroy (cache->key_table);
|
||||
g_hash_table_destroy (cache->value_table);
|
||||
g_slice_free (GCache, cache);
|
||||
}
|
||||
|
||||
gpointer
|
||||
g_cache_insert (GCache *cache,
|
||||
gpointer key)
|
||||
{
|
||||
GCacheNode *node;
|
||||
gpointer value;
|
||||
|
||||
g_return_val_if_fail (cache != NULL, NULL);
|
||||
|
||||
node = g_hash_table_lookup (cache->key_table, key);
|
||||
if (node)
|
||||
{
|
||||
node->ref_count += 1;
|
||||
return node->value;
|
||||
}
|
||||
|
||||
key = (* cache->key_dup_func) (key);
|
||||
value = (* cache->value_new_func) (key);
|
||||
node = g_cache_node_new (value);
|
||||
|
||||
g_hash_table_insert (cache->key_table, key, node);
|
||||
g_hash_table_insert (cache->value_table, value, key);
|
||||
|
||||
return node->value;
|
||||
}
|
||||
|
||||
void
|
||||
g_cache_remove (GCache *cache,
|
||||
gconstpointer value)
|
||||
{
|
||||
GCacheNode *node;
|
||||
gpointer key;
|
||||
|
||||
g_return_if_fail (cache != NULL);
|
||||
|
||||
key = g_hash_table_lookup (cache->value_table, value);
|
||||
node = g_hash_table_lookup (cache->key_table, key);
|
||||
|
||||
g_return_if_fail (node != NULL);
|
||||
|
||||
node->ref_count -= 1;
|
||||
if (node->ref_count == 0)
|
||||
{
|
||||
g_hash_table_remove (cache->value_table, value);
|
||||
g_hash_table_remove (cache->key_table, key);
|
||||
|
||||
(* cache->key_destroy_func) (key);
|
||||
(* cache->value_destroy_func) (node->value);
|
||||
g_cache_node_destroy (node);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
g_cache_key_foreach (GCache *cache,
|
||||
GHFunc func,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_return_if_fail (cache != NULL);
|
||||
g_return_if_fail (func != NULL);
|
||||
|
||||
g_hash_table_foreach (cache->value_table, func, user_data);
|
||||
}
|
||||
|
||||
void
|
||||
g_cache_value_foreach (GCache *cache,
|
||||
GHFunc func,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_return_if_fail (cache != NULL);
|
||||
g_return_if_fail (func != NULL);
|
||||
|
||||
g_hash_table_foreach (cache->key_table, func, user_data);
|
||||
}
|
||||
|
||||
#define __G_CACHE_C__
|
||||
#include "galiasdef.c"
|
|
@ -0,0 +1,69 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
|
||||
#error "Only <glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __G_CACHE_H__
|
||||
#define __G_CACHE_H__
|
||||
|
||||
#include <glib/glist.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GCache GCache;
|
||||
|
||||
typedef gpointer (*GCacheNewFunc) (gpointer key);
|
||||
typedef gpointer (*GCacheDupFunc) (gpointer value);
|
||||
typedef void (*GCacheDestroyFunc) (gpointer value);
|
||||
|
||||
/* Caches
|
||||
*/
|
||||
GCache* g_cache_new (GCacheNewFunc value_new_func,
|
||||
GCacheDestroyFunc value_destroy_func,
|
||||
GCacheDupFunc key_dup_func,
|
||||
GCacheDestroyFunc key_destroy_func,
|
||||
GHashFunc hash_key_func,
|
||||
GHashFunc hash_value_func,
|
||||
GEqualFunc key_equal_func);
|
||||
void g_cache_destroy (GCache *cache);
|
||||
gpointer g_cache_insert (GCache *cache,
|
||||
gpointer key);
|
||||
void g_cache_remove (GCache *cache,
|
||||
gconstpointer value);
|
||||
void g_cache_key_foreach (GCache *cache,
|
||||
GHFunc func,
|
||||
gpointer user_data);
|
||||
#ifndef G_DISABLE_DEPRECATED
|
||||
void g_cache_value_foreach (GCache *cache,
|
||||
GHFunc func,
|
||||
gpointer user_data);
|
||||
#endif
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_CACHE_H__ */
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,86 @@
|
|||
/* gchecksum.h - data hashing functions
|
||||
*
|
||||
* Copyright (C) 2007 Emmanuele Bassi <ebassi@gnome.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
|
||||
#error "Only <glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __G_CHECKSUM_H__
|
||||
#define __G_CHECKSUM_H__
|
||||
|
||||
#include <glib/gtypes.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* GChecksumType:
|
||||
* @G_CHECKSUM_MD5: Use the MD5 hashing algorithm
|
||||
* @G_CHECKSUM_SHA1: Use the SHA-1 hashing algorithm
|
||||
* @G_CHECKSUM_SHA256: Use the SHA-256 hashing algorithm
|
||||
*
|
||||
* The hashing algorithm to be used by #GChecksum when performing the
|
||||
* digest of some data.
|
||||
*
|
||||
* Note that the #GChecksumType enumeration may be extended at a later
|
||||
* date to include new hashing algorithm types.
|
||||
*
|
||||
* Since: 2.16
|
||||
*/
|
||||
typedef enum {
|
||||
G_CHECKSUM_MD5,
|
||||
G_CHECKSUM_SHA1,
|
||||
G_CHECKSUM_SHA256
|
||||
} GChecksumType;
|
||||
|
||||
/**
|
||||
* GChecksum:
|
||||
*
|
||||
* An opaque structure representing a checksumming operation.
|
||||
* To create a new GChecksum, use g_checksum_new(). To free
|
||||
* a GChecksum, use g_checksum_free().
|
||||
*
|
||||
* Since: 2.16
|
||||
*/
|
||||
typedef struct _GChecksum GChecksum;
|
||||
|
||||
gssize g_checksum_type_get_length (GChecksumType checksum_type);
|
||||
|
||||
GChecksum * g_checksum_new (GChecksumType checksum_type);
|
||||
void g_checksum_reset (GChecksum *checksum);
|
||||
GChecksum * g_checksum_copy (const GChecksum *checksum);
|
||||
void g_checksum_free (GChecksum *checksum);
|
||||
void g_checksum_update (GChecksum *checksum,
|
||||
const guchar *data,
|
||||
gssize length);
|
||||
G_CONST_RETURN gchar *g_checksum_get_string (GChecksum *checksum);
|
||||
void g_checksum_get_digest (GChecksum *checksum,
|
||||
guint8 *buffer,
|
||||
gsize *digest_len);
|
||||
|
||||
gchar *g_compute_checksum_for_data (GChecksumType checksum_type,
|
||||
const guchar *data,
|
||||
gsize length);
|
||||
gchar *g_compute_checksum_for_string (GChecksumType checksum_type,
|
||||
const gchar *str,
|
||||
gssize length);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_CHECKSUM_H__ */
|
|
@ -0,0 +1,350 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
/*
|
||||
* MT safe
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "glib.h"
|
||||
#include "galias.h"
|
||||
|
||||
static void completion_check_cache (GCompletion* cmp,
|
||||
gchar** new_prefix);
|
||||
|
||||
GCompletion*
|
||||
g_completion_new (GCompletionFunc func)
|
||||
{
|
||||
GCompletion* gcomp;
|
||||
|
||||
gcomp = g_new (GCompletion, 1);
|
||||
gcomp->items = NULL;
|
||||
gcomp->cache = NULL;
|
||||
gcomp->prefix = NULL;
|
||||
gcomp->func = func;
|
||||
gcomp->strncmp_func = strncmp;
|
||||
|
||||
return gcomp;
|
||||
}
|
||||
|
||||
void
|
||||
g_completion_add_items (GCompletion* cmp,
|
||||
GList* items)
|
||||
{
|
||||
GList* it;
|
||||
|
||||
g_return_if_fail (cmp != NULL);
|
||||
|
||||
/* optimize adding to cache? */
|
||||
if (cmp->cache)
|
||||
{
|
||||
g_list_free (cmp->cache);
|
||||
cmp->cache = NULL;
|
||||
}
|
||||
|
||||
if (cmp->prefix)
|
||||
{
|
||||
g_free (cmp->prefix);
|
||||
cmp->prefix = NULL;
|
||||
}
|
||||
|
||||
it = items;
|
||||
while (it)
|
||||
{
|
||||
cmp->items = g_list_prepend (cmp->items, it->data);
|
||||
it = it->next;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
g_completion_remove_items (GCompletion* cmp,
|
||||
GList* items)
|
||||
{
|
||||
GList* it;
|
||||
|
||||
g_return_if_fail (cmp != NULL);
|
||||
|
||||
it = items;
|
||||
while (cmp->items && it)
|
||||
{
|
||||
cmp->items = g_list_remove (cmp->items, it->data);
|
||||
it = it->next;
|
||||
}
|
||||
|
||||
it = items;
|
||||
while (cmp->cache && it)
|
||||
{
|
||||
cmp->cache = g_list_remove(cmp->cache, it->data);
|
||||
it = it->next;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
g_completion_clear_items (GCompletion* cmp)
|
||||
{
|
||||
g_return_if_fail (cmp != NULL);
|
||||
|
||||
g_list_free (cmp->items);
|
||||
cmp->items = NULL;
|
||||
g_list_free (cmp->cache);
|
||||
cmp->cache = NULL;
|
||||
g_free (cmp->prefix);
|
||||
cmp->prefix = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
completion_check_cache (GCompletion* cmp,
|
||||
gchar** new_prefix)
|
||||
{
|
||||
register GList* list;
|
||||
register gsize len;
|
||||
register gsize i;
|
||||
register gsize plen;
|
||||
gchar* postfix;
|
||||
gchar* s;
|
||||
|
||||
if (!new_prefix)
|
||||
return;
|
||||
if (!cmp->cache)
|
||||
{
|
||||
*new_prefix = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
len = strlen(cmp->prefix);
|
||||
list = cmp->cache;
|
||||
s = cmp->func ? cmp->func (list->data) : (gchar*) list->data;
|
||||
postfix = s + len;
|
||||
plen = strlen (postfix);
|
||||
list = list->next;
|
||||
|
||||
while (list && plen)
|
||||
{
|
||||
s = cmp->func ? cmp->func (list->data) : (gchar*) list->data;
|
||||
s += len;
|
||||
for (i = 0; i < plen; ++i)
|
||||
{
|
||||
if (postfix[i] != s[i])
|
||||
break;
|
||||
}
|
||||
plen = i;
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
*new_prefix = g_new0 (gchar, len + plen + 1);
|
||||
strncpy (*new_prefix, cmp->prefix, len);
|
||||
strncpy (*new_prefix + len, postfix, plen);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_completion_complete_utf8:
|
||||
* @cmp: the #GCompletion
|
||||
* @prefix: the prefix string, typically used by the user, which is compared
|
||||
* with each of the items
|
||||
* @new_prefix: if non-%NULL, returns the longest prefix which is common to all
|
||||
* items that matched @prefix, or %NULL if no items matched @prefix.
|
||||
* This string should be freed when no longer needed.
|
||||
*
|
||||
* Attempts to complete the string @prefix using the #GCompletion target items.
|
||||
* In contrast to g_completion_complete(), this function returns the largest common
|
||||
* prefix that is a valid UTF-8 string, omitting a possible common partial
|
||||
* character.
|
||||
*
|
||||
* You should use this function instead of g_completion_complete() if your
|
||||
* items are UTF-8 strings.
|
||||
*
|
||||
* Return value: the list of items whose strings begin with @prefix. This should
|
||||
* not be changed.
|
||||
*
|
||||
* Since: 2.4
|
||||
**/
|
||||
GList*
|
||||
g_completion_complete_utf8 (GCompletion *cmp,
|
||||
const gchar *prefix,
|
||||
gchar **new_prefix)
|
||||
{
|
||||
GList *list;
|
||||
gchar *p, *q;
|
||||
|
||||
list = g_completion_complete (cmp, prefix, new_prefix);
|
||||
|
||||
if (new_prefix && *new_prefix)
|
||||
{
|
||||
p = *new_prefix + strlen (*new_prefix);
|
||||
q = g_utf8_find_prev_char (*new_prefix, p);
|
||||
|
||||
switch (g_utf8_get_char_validated (q, p - q))
|
||||
{
|
||||
case (gunichar)-2:
|
||||
case (gunichar)-1:
|
||||
*q = 0;
|
||||
break;
|
||||
default: ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
GList*
|
||||
g_completion_complete (GCompletion* cmp,
|
||||
const gchar* prefix,
|
||||
gchar** new_prefix)
|
||||
{
|
||||
gsize plen, len;
|
||||
gboolean done = FALSE;
|
||||
GList* list;
|
||||
|
||||
g_return_val_if_fail (cmp != NULL, NULL);
|
||||
g_return_val_if_fail (prefix != NULL, NULL);
|
||||
|
||||
len = strlen (prefix);
|
||||
if (cmp->prefix && cmp->cache)
|
||||
{
|
||||
plen = strlen (cmp->prefix);
|
||||
if (plen <= len && ! cmp->strncmp_func (prefix, cmp->prefix, plen))
|
||||
{
|
||||
/* use the cache */
|
||||
list = cmp->cache;
|
||||
while (list)
|
||||
{
|
||||
GList *next = list->next;
|
||||
|
||||
if (cmp->strncmp_func (prefix,
|
||||
cmp->func ? cmp->func (list->data) : (gchar*) list->data,
|
||||
len))
|
||||
cmp->cache = g_list_delete_link (cmp->cache, list);
|
||||
|
||||
list = next;
|
||||
}
|
||||
done = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (!done)
|
||||
{
|
||||
/* normal code */
|
||||
g_list_free (cmp->cache);
|
||||
cmp->cache = NULL;
|
||||
list = cmp->items;
|
||||
while (*prefix && list)
|
||||
{
|
||||
if (!cmp->strncmp_func (prefix,
|
||||
cmp->func ? cmp->func (list->data) : (gchar*) list->data,
|
||||
len))
|
||||
cmp->cache = g_list_prepend (cmp->cache, list->data);
|
||||
list = list->next;
|
||||
}
|
||||
}
|
||||
if (cmp->prefix)
|
||||
{
|
||||
g_free (cmp->prefix);
|
||||
cmp->prefix = NULL;
|
||||
}
|
||||
if (cmp->cache)
|
||||
cmp->prefix = g_strdup (prefix);
|
||||
completion_check_cache (cmp, new_prefix);
|
||||
|
||||
return *prefix ? cmp->cache : cmp->items;
|
||||
}
|
||||
|
||||
void
|
||||
g_completion_free (GCompletion* cmp)
|
||||
{
|
||||
g_return_if_fail (cmp != NULL);
|
||||
|
||||
g_completion_clear_items (cmp);
|
||||
g_free (cmp);
|
||||
}
|
||||
|
||||
void
|
||||
g_completion_set_compare(GCompletion *cmp,
|
||||
GCompletionStrncmpFunc strncmp_func)
|
||||
{
|
||||
cmp->strncmp_func = strncmp_func;
|
||||
}
|
||||
|
||||
#ifdef TEST_COMPLETION
|
||||
#include <stdio.h>
|
||||
int
|
||||
main (int argc,
|
||||
char* argv[])
|
||||
{
|
||||
FILE *file;
|
||||
gchar buf[1024];
|
||||
GList *list;
|
||||
GList *result;
|
||||
GList *tmp;
|
||||
GCompletion *cmp;
|
||||
gint i;
|
||||
gchar *longp = NULL;
|
||||
|
||||
if (argc < 3)
|
||||
{
|
||||
g_warning ("Usage: %s filename prefix1 [prefix2 ...]\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
file = fopen (argv[1], "r");
|
||||
if (!file)
|
||||
{
|
||||
g_warning ("Cannot open %s\n", argv[1]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
cmp = g_completion_new (NULL);
|
||||
list = g_list_alloc ();
|
||||
while (fgets (buf, 1024, file))
|
||||
{
|
||||
list->data = g_strdup (buf);
|
||||
g_completion_add_items (cmp, list);
|
||||
}
|
||||
fclose (file);
|
||||
|
||||
for (i = 2; i < argc; ++i)
|
||||
{
|
||||
printf ("COMPLETING: %s\n", argv[i]);
|
||||
result = g_completion_complete (cmp, argv[i], &longp);
|
||||
g_list_foreach (result, (GFunc) printf, NULL);
|
||||
printf ("LONG MATCH: %s\n", longp);
|
||||
g_free (longp);
|
||||
longp = NULL;
|
||||
}
|
||||
|
||||
g_list_foreach (cmp->items, (GFunc) g_free, NULL);
|
||||
g_completion_free (cmp);
|
||||
g_list_free (list);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#define __G_COMPLETION_C__
|
||||
#include "galiasdef.c"
|
|
@ -0,0 +1,77 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
|
||||
#error "Only <glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __G_COMPLETION_H__
|
||||
#define __G_COMPLETION_H__
|
||||
|
||||
#include <glib/glist.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GCompletion GCompletion;
|
||||
|
||||
typedef gchar* (*GCompletionFunc) (gpointer);
|
||||
|
||||
/* GCompletion
|
||||
*/
|
||||
|
||||
typedef gint (*GCompletionStrncmpFunc) (const gchar *s1,
|
||||
const gchar *s2,
|
||||
gsize n);
|
||||
|
||||
struct _GCompletion
|
||||
{
|
||||
GList* items;
|
||||
GCompletionFunc func;
|
||||
|
||||
gchar* prefix;
|
||||
GList* cache;
|
||||
GCompletionStrncmpFunc strncmp_func;
|
||||
};
|
||||
|
||||
GCompletion* g_completion_new (GCompletionFunc func);
|
||||
void g_completion_add_items (GCompletion* cmp,
|
||||
GList* items);
|
||||
void g_completion_remove_items (GCompletion* cmp,
|
||||
GList* items);
|
||||
void g_completion_clear_items (GCompletion* cmp);
|
||||
GList* g_completion_complete (GCompletion* cmp,
|
||||
const gchar* prefix,
|
||||
gchar** new_prefix);
|
||||
GList* g_completion_complete_utf8 (GCompletion *cmp,
|
||||
const gchar* prefix,
|
||||
gchar** new_prefix);
|
||||
void g_completion_set_compare (GCompletion *cmp,
|
||||
GCompletionStrncmpFunc strncmp_func);
|
||||
void g_completion_free (GCompletion* cmp);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_COMPLETION_H__ */
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,138 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
|
||||
#error "Only <glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __G_CONVERT_H__
|
||||
#define __G_CONVERT_H__
|
||||
|
||||
#include <glib/gerror.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef enum
|
||||
{
|
||||
G_CONVERT_ERROR_NO_CONVERSION,
|
||||
G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
|
||||
G_CONVERT_ERROR_FAILED,
|
||||
G_CONVERT_ERROR_PARTIAL_INPUT,
|
||||
G_CONVERT_ERROR_BAD_URI,
|
||||
G_CONVERT_ERROR_NOT_ABSOLUTE_PATH
|
||||
} GConvertError;
|
||||
|
||||
#define G_CONVERT_ERROR g_convert_error_quark()
|
||||
GQuark g_convert_error_quark (void);
|
||||
|
||||
/* Thin wrappers around iconv
|
||||
*/
|
||||
typedef struct _GIConv *GIConv;
|
||||
|
||||
GIConv g_iconv_open (const gchar *to_codeset,
|
||||
const gchar *from_codeset);
|
||||
gsize g_iconv (GIConv converter,
|
||||
gchar **inbuf,
|
||||
gsize *inbytes_left,
|
||||
gchar **outbuf,
|
||||
gsize *outbytes_left);
|
||||
gint g_iconv_close (GIConv converter);
|
||||
|
||||
|
||||
gchar* g_convert (const gchar *str,
|
||||
gssize len,
|
||||
const gchar *to_codeset,
|
||||
const gchar *from_codeset,
|
||||
gsize *bytes_read,
|
||||
gsize *bytes_written,
|
||||
GError **error) G_GNUC_MALLOC;
|
||||
gchar* g_convert_with_iconv (const gchar *str,
|
||||
gssize len,
|
||||
GIConv converter,
|
||||
gsize *bytes_read,
|
||||
gsize *bytes_written,
|
||||
GError **error) G_GNUC_MALLOC;
|
||||
gchar* g_convert_with_fallback (const gchar *str,
|
||||
gssize len,
|
||||
const gchar *to_codeset,
|
||||
const gchar *from_codeset,
|
||||
gchar *fallback,
|
||||
gsize *bytes_read,
|
||||
gsize *bytes_written,
|
||||
GError **error) G_GNUC_MALLOC;
|
||||
|
||||
|
||||
/* Convert between libc's idea of strings and UTF-8.
|
||||
*/
|
||||
gchar* g_locale_to_utf8 (const gchar *opsysstring,
|
||||
gssize len,
|
||||
gsize *bytes_read,
|
||||
gsize *bytes_written,
|
||||
GError **error) G_GNUC_MALLOC;
|
||||
gchar* g_locale_from_utf8 (const gchar *utf8string,
|
||||
gssize len,
|
||||
gsize *bytes_read,
|
||||
gsize *bytes_written,
|
||||
GError **error) G_GNUC_MALLOC;
|
||||
|
||||
/* Convert between the operating system (or C runtime)
|
||||
* representation of file names and UTF-8.
|
||||
*/
|
||||
#ifdef G_OS_WIN32
|
||||
#define g_filename_to_utf8 g_filename_to_utf8_utf8
|
||||
#define g_filename_from_utf8 g_filename_from_utf8_utf8
|
||||
#define g_filename_from_uri g_filename_from_uri_utf8
|
||||
#define g_filename_to_uri g_filename_to_uri_utf8
|
||||
#endif
|
||||
|
||||
gchar* g_filename_to_utf8 (const gchar *opsysstring,
|
||||
gssize len,
|
||||
gsize *bytes_read,
|
||||
gsize *bytes_written,
|
||||
GError **error) G_GNUC_MALLOC;
|
||||
gchar* g_filename_from_utf8 (const gchar *utf8string,
|
||||
gssize len,
|
||||
gsize *bytes_read,
|
||||
gsize *bytes_written,
|
||||
GError **error) G_GNUC_MALLOC;
|
||||
|
||||
gchar *g_filename_from_uri (const gchar *uri,
|
||||
gchar **hostname,
|
||||
GError **error) G_GNUC_MALLOC;
|
||||
|
||||
gchar *g_filename_to_uri (const gchar *filename,
|
||||
const gchar *hostname,
|
||||
GError **error) G_GNUC_MALLOC;
|
||||
gchar *g_filename_display_name (const gchar *filename) G_GNUC_MALLOC;
|
||||
gboolean g_get_filename_charsets (G_CONST_RETURN gchar ***charsets);
|
||||
|
||||
gchar *g_filename_display_basename (const gchar *filename) G_GNUC_MALLOC;
|
||||
|
||||
gchar **g_uri_list_extract_uris (const gchar *uri_list) G_GNUC_MALLOC;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_CONVERT_H__ */
|
|
@ -0,0 +1,759 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* gdataset.c: Generic dataset mechanism, similar to GtkObject data.
|
||||
* Copyright (C) 1998 Tim Janik
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
/*
|
||||
* MT safe ; except for g_data*_foreach()
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "glib.h"
|
||||
#include "gdatasetprivate.h"
|
||||
#include "galias.h"
|
||||
|
||||
|
||||
/* --- defines --- */
|
||||
#define G_QUARK_BLOCK_SIZE (512)
|
||||
|
||||
/* datalist pointer accesses have to be carried out atomically */
|
||||
#define G_DATALIST_GET_POINTER(datalist) \
|
||||
((GData*) ((gsize) g_atomic_pointer_get (datalist) & ~(gsize) G_DATALIST_FLAGS_MASK))
|
||||
|
||||
#define G_DATALIST_SET_POINTER(datalist, pointer) G_STMT_START { \
|
||||
gpointer _oldv, _newv; \
|
||||
do { \
|
||||
_oldv = g_atomic_pointer_get (datalist); \
|
||||
_newv = (gpointer) (((gsize) _oldv & G_DATALIST_FLAGS_MASK) | (gsize) pointer); \
|
||||
} while (!g_atomic_pointer_compare_and_exchange ((void**) datalist, _oldv, _newv)); \
|
||||
} G_STMT_END
|
||||
|
||||
/* --- structures --- */
|
||||
typedef struct _GDataset GDataset;
|
||||
struct _GData
|
||||
{
|
||||
GData *next;
|
||||
GQuark id;
|
||||
gpointer data;
|
||||
GDestroyNotify destroy_func;
|
||||
};
|
||||
|
||||
struct _GDataset
|
||||
{
|
||||
gconstpointer location;
|
||||
GData *datalist;
|
||||
};
|
||||
|
||||
|
||||
/* --- prototypes --- */
|
||||
static inline GDataset* g_dataset_lookup (gconstpointer dataset_location);
|
||||
static inline void g_datalist_clear_i (GData **datalist);
|
||||
static void g_dataset_destroy_internal (GDataset *dataset);
|
||||
static inline gpointer g_data_set_internal (GData **datalist,
|
||||
GQuark key_id,
|
||||
gpointer data,
|
||||
GDestroyNotify destroy_func,
|
||||
GDataset *dataset);
|
||||
static void g_data_initialize (void);
|
||||
static inline GQuark g_quark_new (gchar *string);
|
||||
|
||||
|
||||
/* --- variables --- */
|
||||
G_LOCK_DEFINE_STATIC (g_dataset_global);
|
||||
static GHashTable *g_dataset_location_ht = NULL;
|
||||
static GDataset *g_dataset_cached = NULL; /* should this be
|
||||
threadspecific? */
|
||||
G_LOCK_DEFINE_STATIC (g_quark_global);
|
||||
static GHashTable *g_quark_ht = NULL;
|
||||
static gchar **g_quarks = NULL;
|
||||
static GQuark g_quark_seq_id = 0;
|
||||
|
||||
/* --- functions --- */
|
||||
|
||||
/* HOLDS: g_dataset_global_lock */
|
||||
static inline void
|
||||
g_datalist_clear_i (GData **datalist)
|
||||
{
|
||||
register GData *list;
|
||||
|
||||
/* unlink *all* items before walking their destructors
|
||||
*/
|
||||
list = G_DATALIST_GET_POINTER (datalist);
|
||||
G_DATALIST_SET_POINTER (datalist, NULL);
|
||||
|
||||
while (list)
|
||||
{
|
||||
register GData *prev;
|
||||
|
||||
prev = list;
|
||||
list = prev->next;
|
||||
|
||||
if (prev->destroy_func)
|
||||
{
|
||||
G_UNLOCK (g_dataset_global);
|
||||
prev->destroy_func (prev->data);
|
||||
G_LOCK (g_dataset_global);
|
||||
}
|
||||
|
||||
g_slice_free (GData, prev);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
g_datalist_clear (GData **datalist)
|
||||
{
|
||||
g_return_if_fail (datalist != NULL);
|
||||
|
||||
G_LOCK (g_dataset_global);
|
||||
if (!g_dataset_location_ht)
|
||||
g_data_initialize ();
|
||||
|
||||
while (G_DATALIST_GET_POINTER (datalist))
|
||||
g_datalist_clear_i (datalist);
|
||||
G_UNLOCK (g_dataset_global);
|
||||
}
|
||||
|
||||
/* HOLDS: g_dataset_global_lock */
|
||||
static inline GDataset*
|
||||
g_dataset_lookup (gconstpointer dataset_location)
|
||||
{
|
||||
register GDataset *dataset;
|
||||
|
||||
if (g_dataset_cached && g_dataset_cached->location == dataset_location)
|
||||
return g_dataset_cached;
|
||||
|
||||
dataset = g_hash_table_lookup (g_dataset_location_ht, dataset_location);
|
||||
if (dataset)
|
||||
g_dataset_cached = dataset;
|
||||
|
||||
return dataset;
|
||||
}
|
||||
|
||||
/* HOLDS: g_dataset_global_lock */
|
||||
static void
|
||||
g_dataset_destroy_internal (GDataset *dataset)
|
||||
{
|
||||
register gconstpointer dataset_location;
|
||||
|
||||
dataset_location = dataset->location;
|
||||
while (dataset)
|
||||
{
|
||||
if (!dataset->datalist)
|
||||
{
|
||||
if (dataset == g_dataset_cached)
|
||||
g_dataset_cached = NULL;
|
||||
g_hash_table_remove (g_dataset_location_ht, dataset_location);
|
||||
g_slice_free (GDataset, dataset);
|
||||
break;
|
||||
}
|
||||
|
||||
g_datalist_clear_i (&dataset->datalist);
|
||||
dataset = g_dataset_lookup (dataset_location);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
g_dataset_destroy (gconstpointer dataset_location)
|
||||
{
|
||||
g_return_if_fail (dataset_location != NULL);
|
||||
|
||||
G_LOCK (g_dataset_global);
|
||||
if (g_dataset_location_ht)
|
||||
{
|
||||
register GDataset *dataset;
|
||||
|
||||
dataset = g_dataset_lookup (dataset_location);
|
||||
if (dataset)
|
||||
g_dataset_destroy_internal (dataset);
|
||||
}
|
||||
G_UNLOCK (g_dataset_global);
|
||||
}
|
||||
|
||||
/* HOLDS: g_dataset_global_lock */
|
||||
static inline gpointer
|
||||
g_data_set_internal (GData **datalist,
|
||||
GQuark key_id,
|
||||
gpointer data,
|
||||
GDestroyNotify destroy_func,
|
||||
GDataset *dataset)
|
||||
{
|
||||
register GData *list;
|
||||
|
||||
list = G_DATALIST_GET_POINTER (datalist);
|
||||
if (!data)
|
||||
{
|
||||
register GData *prev;
|
||||
|
||||
prev = NULL;
|
||||
while (list)
|
||||
{
|
||||
if (list->id == key_id)
|
||||
{
|
||||
gpointer ret_data = NULL;
|
||||
|
||||
if (prev)
|
||||
prev->next = list->next;
|
||||
else
|
||||
{
|
||||
G_DATALIST_SET_POINTER (datalist, list->next);
|
||||
|
||||
/* the dataset destruction *must* be done
|
||||
* prior to invocation of the data destroy function
|
||||
*/
|
||||
if (!list->next && dataset)
|
||||
g_dataset_destroy_internal (dataset);
|
||||
}
|
||||
|
||||
/* the GData struct *must* already be unlinked
|
||||
* when invoking the destroy function.
|
||||
* we use (data==NULL && destroy_func!=NULL) as
|
||||
* a special hint combination to "steal"
|
||||
* data without destroy notification
|
||||
*/
|
||||
if (list->destroy_func && !destroy_func)
|
||||
{
|
||||
G_UNLOCK (g_dataset_global);
|
||||
list->destroy_func (list->data);
|
||||
G_LOCK (g_dataset_global);
|
||||
}
|
||||
else
|
||||
ret_data = list->data;
|
||||
|
||||
g_slice_free (GData, list);
|
||||
|
||||
return ret_data;
|
||||
}
|
||||
|
||||
prev = list;
|
||||
list = list->next;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (list)
|
||||
{
|
||||
if (list->id == key_id)
|
||||
{
|
||||
if (!list->destroy_func)
|
||||
{
|
||||
list->data = data;
|
||||
list->destroy_func = destroy_func;
|
||||
}
|
||||
else
|
||||
{
|
||||
register GDestroyNotify dfunc;
|
||||
register gpointer ddata;
|
||||
|
||||
dfunc = list->destroy_func;
|
||||
ddata = list->data;
|
||||
list->data = data;
|
||||
list->destroy_func = destroy_func;
|
||||
|
||||
/* we need to have updated all structures prior to
|
||||
* invocation of the destroy function
|
||||
*/
|
||||
G_UNLOCK (g_dataset_global);
|
||||
dfunc (ddata);
|
||||
G_LOCK (g_dataset_global);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
list = g_slice_new (GData);
|
||||
list->next = G_DATALIST_GET_POINTER (datalist);
|
||||
list->id = key_id;
|
||||
list->data = data;
|
||||
list->destroy_func = destroy_func;
|
||||
G_DATALIST_SET_POINTER (datalist, list);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
g_dataset_id_set_data_full (gconstpointer dataset_location,
|
||||
GQuark key_id,
|
||||
gpointer data,
|
||||
GDestroyNotify destroy_func)
|
||||
{
|
||||
register GDataset *dataset;
|
||||
|
||||
g_return_if_fail (dataset_location != NULL);
|
||||
if (!data)
|
||||
g_return_if_fail (destroy_func == NULL);
|
||||
if (!key_id)
|
||||
{
|
||||
if (data)
|
||||
g_return_if_fail (key_id > 0);
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
G_LOCK (g_dataset_global);
|
||||
if (!g_dataset_location_ht)
|
||||
g_data_initialize ();
|
||||
|
||||
dataset = g_dataset_lookup (dataset_location);
|
||||
if (!dataset)
|
||||
{
|
||||
dataset = g_slice_new (GDataset);
|
||||
dataset->location = dataset_location;
|
||||
g_datalist_init (&dataset->datalist);
|
||||
g_hash_table_insert (g_dataset_location_ht,
|
||||
(gpointer) dataset->location,
|
||||
dataset);
|
||||
}
|
||||
|
||||
g_data_set_internal (&dataset->datalist, key_id, data, destroy_func, dataset);
|
||||
G_UNLOCK (g_dataset_global);
|
||||
}
|
||||
|
||||
void
|
||||
g_datalist_id_set_data_full (GData **datalist,
|
||||
GQuark key_id,
|
||||
gpointer data,
|
||||
GDestroyNotify destroy_func)
|
||||
{
|
||||
g_return_if_fail (datalist != NULL);
|
||||
if (!data)
|
||||
g_return_if_fail (destroy_func == NULL);
|
||||
if (!key_id)
|
||||
{
|
||||
if (data)
|
||||
g_return_if_fail (key_id > 0);
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
G_LOCK (g_dataset_global);
|
||||
if (!g_dataset_location_ht)
|
||||
g_data_initialize ();
|
||||
|
||||
g_data_set_internal (datalist, key_id, data, destroy_func, NULL);
|
||||
G_UNLOCK (g_dataset_global);
|
||||
}
|
||||
|
||||
gpointer
|
||||
g_dataset_id_remove_no_notify (gconstpointer dataset_location,
|
||||
GQuark key_id)
|
||||
{
|
||||
gpointer ret_data = NULL;
|
||||
|
||||
g_return_val_if_fail (dataset_location != NULL, NULL);
|
||||
|
||||
G_LOCK (g_dataset_global);
|
||||
if (key_id && g_dataset_location_ht)
|
||||
{
|
||||
GDataset *dataset;
|
||||
|
||||
dataset = g_dataset_lookup (dataset_location);
|
||||
if (dataset)
|
||||
ret_data = g_data_set_internal (&dataset->datalist, key_id, NULL, (GDestroyNotify) 42, dataset);
|
||||
}
|
||||
G_UNLOCK (g_dataset_global);
|
||||
|
||||
return ret_data;
|
||||
}
|
||||
|
||||
gpointer
|
||||
g_datalist_id_remove_no_notify (GData **datalist,
|
||||
GQuark key_id)
|
||||
{
|
||||
gpointer ret_data = NULL;
|
||||
|
||||
g_return_val_if_fail (datalist != NULL, NULL);
|
||||
|
||||
G_LOCK (g_dataset_global);
|
||||
if (key_id && g_dataset_location_ht)
|
||||
ret_data = g_data_set_internal (datalist, key_id, NULL, (GDestroyNotify) 42, NULL);
|
||||
G_UNLOCK (g_dataset_global);
|
||||
|
||||
return ret_data;
|
||||
}
|
||||
|
||||
gpointer
|
||||
g_dataset_id_get_data (gconstpointer dataset_location,
|
||||
GQuark key_id)
|
||||
{
|
||||
g_return_val_if_fail (dataset_location != NULL, NULL);
|
||||
|
||||
G_LOCK (g_dataset_global);
|
||||
if (key_id && g_dataset_location_ht)
|
||||
{
|
||||
register GDataset *dataset;
|
||||
|
||||
dataset = g_dataset_lookup (dataset_location);
|
||||
if (dataset)
|
||||
{
|
||||
register GData *list;
|
||||
|
||||
for (list = dataset->datalist; list; list = list->next)
|
||||
if (list->id == key_id)
|
||||
{
|
||||
G_UNLOCK (g_dataset_global);
|
||||
return list->data;
|
||||
}
|
||||
}
|
||||
}
|
||||
G_UNLOCK (g_dataset_global);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gpointer
|
||||
g_datalist_id_get_data (GData **datalist,
|
||||
GQuark key_id)
|
||||
{
|
||||
gpointer data = NULL;
|
||||
g_return_val_if_fail (datalist != NULL, NULL);
|
||||
if (key_id)
|
||||
{
|
||||
register GData *list;
|
||||
G_LOCK (g_dataset_global);
|
||||
for (list = G_DATALIST_GET_POINTER (datalist); list; list = list->next)
|
||||
if (list->id == key_id)
|
||||
{
|
||||
data = list->data;
|
||||
break;
|
||||
}
|
||||
G_UNLOCK (g_dataset_global);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
void
|
||||
g_dataset_foreach (gconstpointer dataset_location,
|
||||
GDataForeachFunc func,
|
||||
gpointer user_data)
|
||||
{
|
||||
register GDataset *dataset;
|
||||
|
||||
g_return_if_fail (dataset_location != NULL);
|
||||
g_return_if_fail (func != NULL);
|
||||
|
||||
G_LOCK (g_dataset_global);
|
||||
if (g_dataset_location_ht)
|
||||
{
|
||||
dataset = g_dataset_lookup (dataset_location);
|
||||
G_UNLOCK (g_dataset_global);
|
||||
if (dataset)
|
||||
{
|
||||
register GData *list, *next;
|
||||
|
||||
for (list = dataset->datalist; list; list = next)
|
||||
{
|
||||
next = list->next;
|
||||
func (list->id, list->data, user_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
G_UNLOCK (g_dataset_global);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
g_datalist_foreach (GData **datalist,
|
||||
GDataForeachFunc func,
|
||||
gpointer user_data)
|
||||
{
|
||||
register GData *list, *next;
|
||||
|
||||
g_return_if_fail (datalist != NULL);
|
||||
g_return_if_fail (func != NULL);
|
||||
|
||||
for (list = G_DATALIST_GET_POINTER (datalist); list; list = next)
|
||||
{
|
||||
next = list->next;
|
||||
func (list->id, list->data, user_data);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
g_datalist_init (GData **datalist)
|
||||
{
|
||||
g_return_if_fail (datalist != NULL);
|
||||
|
||||
g_atomic_pointer_set (datalist, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_datalist_set_flags:
|
||||
* @datalist: pointer to the location that holds a list
|
||||
* @flags: the flags to turn on. The values of the flags are
|
||||
* restricted by %G_DATALIST_FLAGS_MASK (currently
|
||||
* 3; giving two possible boolean flags).
|
||||
* A value for @flags that doesn't fit within the mask is
|
||||
* an error.
|
||||
*
|
||||
* Turns on flag values for a data list. This function is used
|
||||
* to keep a small number of boolean flags in an object with
|
||||
* a data list without using any additional space. It is
|
||||
* not generally useful except in circumstances where space
|
||||
* is very tight. (It is used in the base #GObject type, for
|
||||
* example.)
|
||||
*
|
||||
* Since: 2.8
|
||||
**/
|
||||
void
|
||||
g_datalist_set_flags (GData **datalist,
|
||||
guint flags)
|
||||
{
|
||||
gpointer oldvalue;
|
||||
g_return_if_fail (datalist != NULL);
|
||||
g_return_if_fail ((flags & ~G_DATALIST_FLAGS_MASK) == 0);
|
||||
|
||||
do
|
||||
{
|
||||
oldvalue = g_atomic_pointer_get (datalist);
|
||||
}
|
||||
while (!g_atomic_pointer_compare_and_exchange ((void**) datalist, oldvalue,
|
||||
(gpointer) ((gsize) oldvalue | flags)));
|
||||
}
|
||||
|
||||
/**
|
||||
* g_datalist_unset_flags:
|
||||
* @datalist: pointer to the location that holds a list
|
||||
* @flags: the flags to turn off. The values of the flags are
|
||||
* restricted by %G_DATALIST_FLAGS_MASK (currently
|
||||
* 3: giving two possible boolean flags).
|
||||
* A value for @flags that doesn't fit within the mask is
|
||||
* an error.
|
||||
*
|
||||
* Turns off flag values for a data list. See g_datalist_unset_flags()
|
||||
*
|
||||
* Since: 2.8
|
||||
**/
|
||||
void
|
||||
g_datalist_unset_flags (GData **datalist,
|
||||
guint flags)
|
||||
{
|
||||
gpointer oldvalue;
|
||||
g_return_if_fail (datalist != NULL);
|
||||
g_return_if_fail ((flags & ~G_DATALIST_FLAGS_MASK) == 0);
|
||||
|
||||
do
|
||||
{
|
||||
oldvalue = g_atomic_pointer_get (datalist);
|
||||
}
|
||||
while (!g_atomic_pointer_compare_and_exchange ((void**) datalist, oldvalue,
|
||||
(gpointer) ((gsize) oldvalue & ~(gsize) flags)));
|
||||
}
|
||||
|
||||
/**
|
||||
* g_datalist_get_flags:
|
||||
* @datalist: pointer to the location that holds a list
|
||||
*
|
||||
* Gets flags values packed in together with the datalist.
|
||||
* See g_datalist_set_flags().
|
||||
*
|
||||
* Return value: the flags of the datalist
|
||||
*
|
||||
* Since: 2.8
|
||||
**/
|
||||
guint
|
||||
g_datalist_get_flags (GData **datalist)
|
||||
{
|
||||
g_return_val_if_fail (datalist != NULL, 0);
|
||||
|
||||
return G_DATALIST_GET_FLAGS (datalist); /* atomic macro */
|
||||
}
|
||||
|
||||
/* HOLDS: g_dataset_global_lock */
|
||||
static void
|
||||
g_data_initialize (void)
|
||||
{
|
||||
g_return_if_fail (g_dataset_location_ht == NULL);
|
||||
|
||||
g_dataset_location_ht = g_hash_table_new (g_direct_hash, NULL);
|
||||
g_dataset_cached = NULL;
|
||||
}
|
||||
|
||||
GQuark
|
||||
g_quark_try_string (const gchar *string)
|
||||
{
|
||||
GQuark quark = 0;
|
||||
g_return_val_if_fail (string != NULL, 0);
|
||||
|
||||
G_LOCK (g_quark_global);
|
||||
if (g_quark_ht)
|
||||
quark = GPOINTER_TO_UINT (g_hash_table_lookup (g_quark_ht, string));
|
||||
G_UNLOCK (g_quark_global);
|
||||
|
||||
return quark;
|
||||
}
|
||||
|
||||
/* HOLDS: g_quark_global_lock */
|
||||
static inline GQuark
|
||||
g_quark_from_string_internal (const gchar *string,
|
||||
gboolean duplicate)
|
||||
{
|
||||
GQuark quark = 0;
|
||||
|
||||
if (g_quark_ht)
|
||||
quark = GPOINTER_TO_UINT (g_hash_table_lookup (g_quark_ht, string));
|
||||
|
||||
if (!quark)
|
||||
quark = g_quark_new (duplicate ? g_strdup (string) : (gchar *)string);
|
||||
|
||||
return quark;
|
||||
}
|
||||
|
||||
GQuark
|
||||
g_quark_from_string (const gchar *string)
|
||||
{
|
||||
GQuark quark;
|
||||
|
||||
if (!string)
|
||||
return 0;
|
||||
|
||||
G_LOCK (g_quark_global);
|
||||
quark = g_quark_from_string_internal (string, TRUE);
|
||||
G_UNLOCK (g_quark_global);
|
||||
|
||||
return quark;
|
||||
}
|
||||
|
||||
GQuark
|
||||
g_quark_from_static_string (const gchar *string)
|
||||
{
|
||||
GQuark quark;
|
||||
|
||||
if (!string)
|
||||
return 0;
|
||||
|
||||
G_LOCK (g_quark_global);
|
||||
quark = g_quark_from_string_internal (string, FALSE);
|
||||
G_UNLOCK (g_quark_global);
|
||||
|
||||
return quark;
|
||||
}
|
||||
|
||||
G_CONST_RETURN gchar*
|
||||
g_quark_to_string (GQuark quark)
|
||||
{
|
||||
gchar* result = NULL;
|
||||
|
||||
G_LOCK (g_quark_global);
|
||||
if (quark < g_quark_seq_id)
|
||||
result = g_quarks[quark];
|
||||
G_UNLOCK (g_quark_global);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* HOLDS: g_quark_global_lock */
|
||||
static inline GQuark
|
||||
g_quark_new (gchar *string)
|
||||
{
|
||||
GQuark quark;
|
||||
|
||||
if (g_quark_seq_id % G_QUARK_BLOCK_SIZE == 0)
|
||||
g_quarks = g_renew (gchar*, g_quarks, g_quark_seq_id + G_QUARK_BLOCK_SIZE);
|
||||
if (!g_quark_ht)
|
||||
{
|
||||
g_assert (g_quark_seq_id == 0);
|
||||
g_quark_ht = g_hash_table_new (g_str_hash, g_str_equal);
|
||||
g_quarks[g_quark_seq_id++] = NULL;
|
||||
}
|
||||
|
||||
quark = g_quark_seq_id++;
|
||||
g_quarks[quark] = string;
|
||||
g_hash_table_insert (g_quark_ht, string, GUINT_TO_POINTER (quark));
|
||||
|
||||
return quark;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_intern_string:
|
||||
* @string: a string
|
||||
*
|
||||
* Returns a canonical representation for @string. Interned strings can
|
||||
* be compared for equality by comparing the pointers, instead of using strcmp().
|
||||
*
|
||||
* Returns: a canonical representation for the string
|
||||
*
|
||||
* Since: 2.10
|
||||
*/
|
||||
G_CONST_RETURN gchar*
|
||||
g_intern_string (const gchar *string)
|
||||
{
|
||||
const gchar *result;
|
||||
GQuark quark;
|
||||
|
||||
if (!string)
|
||||
return NULL;
|
||||
|
||||
G_LOCK (g_quark_global);
|
||||
quark = g_quark_from_string_internal (string, TRUE);
|
||||
result = g_quarks[quark];
|
||||
G_UNLOCK (g_quark_global);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_intern_static_string:
|
||||
* @string: a static string
|
||||
*
|
||||
* Returns a canonical representation for @string. Interned strings can
|
||||
* be compared for equality by comparing the pointers, instead of using strcmp().
|
||||
* g_intern_static_string() does not copy the string, therefore @string must
|
||||
* not be freed or modified.
|
||||
*
|
||||
* Returns: a canonical representation for the string
|
||||
*
|
||||
* Since: 2.10
|
||||
*/
|
||||
G_CONST_RETURN gchar*
|
||||
g_intern_static_string (const gchar *string)
|
||||
{
|
||||
GQuark quark;
|
||||
const gchar *result;
|
||||
|
||||
if (!string)
|
||||
return NULL;
|
||||
|
||||
G_LOCK (g_quark_global);
|
||||
quark = g_quark_from_string_internal (string, FALSE);
|
||||
result = g_quarks[quark];
|
||||
G_UNLOCK (g_quark_global);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define __G_DATASET_C__
|
||||
#include "galiasdef.c"
|
|
@ -0,0 +1,122 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
|
||||
#error "Only <glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __G_DATASET_H__
|
||||
#define __G_DATASET_H__
|
||||
|
||||
#include <glib/gquark.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GData GData;
|
||||
|
||||
typedef void (*GDataForeachFunc) (GQuark key_id,
|
||||
gpointer data,
|
||||
gpointer user_data);
|
||||
|
||||
/* Keyed Data List
|
||||
*/
|
||||
void g_datalist_init (GData **datalist);
|
||||
void g_datalist_clear (GData **datalist);
|
||||
gpointer g_datalist_id_get_data (GData **datalist,
|
||||
GQuark key_id);
|
||||
void g_datalist_id_set_data_full (GData **datalist,
|
||||
GQuark key_id,
|
||||
gpointer data,
|
||||
GDestroyNotify destroy_func);
|
||||
gpointer g_datalist_id_remove_no_notify (GData **datalist,
|
||||
GQuark key_id);
|
||||
void g_datalist_foreach (GData **datalist,
|
||||
GDataForeachFunc func,
|
||||
gpointer user_data);
|
||||
|
||||
/**
|
||||
* G_DATALIST_FLAGS_MASK:
|
||||
*
|
||||
* A bitmask that restricts the possible flags passed to
|
||||
* g_datalist_set_flags(). Passing a flags value where
|
||||
* flags & ~G_DATALIST_FLAGS_MASK != 0 is an error.
|
||||
*/
|
||||
#define G_DATALIST_FLAGS_MASK 0x3
|
||||
|
||||
void g_datalist_set_flags (GData **datalist,
|
||||
guint flags);
|
||||
void g_datalist_unset_flags (GData **datalist,
|
||||
guint flags);
|
||||
guint g_datalist_get_flags (GData **datalist);
|
||||
|
||||
#define g_datalist_id_set_data(dl, q, d) \
|
||||
g_datalist_id_set_data_full ((dl), (q), (d), NULL)
|
||||
#define g_datalist_id_remove_data(dl, q) \
|
||||
g_datalist_id_set_data ((dl), (q), NULL)
|
||||
#define g_datalist_get_data(dl, k) \
|
||||
(g_datalist_id_get_data ((dl), g_quark_try_string (k)))
|
||||
#define g_datalist_set_data_full(dl, k, d, f) \
|
||||
g_datalist_id_set_data_full ((dl), g_quark_from_string (k), (d), (f))
|
||||
#define g_datalist_remove_no_notify(dl, k) \
|
||||
g_datalist_id_remove_no_notify ((dl), g_quark_try_string (k))
|
||||
#define g_datalist_set_data(dl, k, d) \
|
||||
g_datalist_set_data_full ((dl), (k), (d), NULL)
|
||||
#define g_datalist_remove_data(dl, k) \
|
||||
g_datalist_id_set_data ((dl), g_quark_try_string (k), NULL)
|
||||
|
||||
|
||||
/* Location Associated Keyed Data
|
||||
*/
|
||||
void g_dataset_destroy (gconstpointer dataset_location);
|
||||
gpointer g_dataset_id_get_data (gconstpointer dataset_location,
|
||||
GQuark key_id);
|
||||
void g_dataset_id_set_data_full (gconstpointer dataset_location,
|
||||
GQuark key_id,
|
||||
gpointer data,
|
||||
GDestroyNotify destroy_func);
|
||||
gpointer g_dataset_id_remove_no_notify (gconstpointer dataset_location,
|
||||
GQuark key_id);
|
||||
void g_dataset_foreach (gconstpointer dataset_location,
|
||||
GDataForeachFunc func,
|
||||
gpointer user_data);
|
||||
#define g_dataset_id_set_data(l, k, d) \
|
||||
g_dataset_id_set_data_full ((l), (k), (d), NULL)
|
||||
#define g_dataset_id_remove_data(l, k) \
|
||||
g_dataset_id_set_data ((l), (k), NULL)
|
||||
#define g_dataset_get_data(l, k) \
|
||||
(g_dataset_id_get_data ((l), g_quark_try_string (k)))
|
||||
#define g_dataset_set_data_full(l, k, d, f) \
|
||||
g_dataset_id_set_data_full ((l), g_quark_from_string (k), (d), (f))
|
||||
#define g_dataset_remove_no_notify(l, k) \
|
||||
g_dataset_id_remove_no_notify ((l), g_quark_try_string (k))
|
||||
#define g_dataset_set_data(l, k, d) \
|
||||
g_dataset_set_data_full ((l), (k), (d), NULL)
|
||||
#define g_dataset_remove_data(l, k) \
|
||||
g_dataset_id_set_data ((l), g_quark_try_string (k), NULL)
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_DATASET_H__ */
|
|
@ -0,0 +1,44 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* gdataset-private.h: Internal macros for accessing dataset values
|
||||
* Copyright (C) 2005 Red Hat
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#ifndef __G_DATASETPRIVATE_H__
|
||||
#define __G_DATASETPRIVATE_H__
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/* GET_FLAGS is implemented via atomic pointer access, to allow memory
|
||||
* barriers to take effect without acquiring the global dataset mutex.
|
||||
*/
|
||||
#define G_DATALIST_GET_FLAGS(datalist) \
|
||||
((gsize) g_atomic_pointer_get (datalist) & G_DATALIST_FLAGS_MASK)
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_DATASETPRIVATE_H__ */
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,263 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
|
||||
#error "Only <glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __G_DATE_H__
|
||||
#define __G_DATE_H__
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include <glib/gtypes.h>
|
||||
#include <glib/gquark.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/* GDate
|
||||
*
|
||||
* Date calculations (not time for now, to be resolved). These are a
|
||||
* mutant combination of Steffen Beyer's DateCalc routines
|
||||
* (http://www.perl.com/CPAN/authors/id/STBEY/) and Jon Trowbridge's
|
||||
* date routines (written for in-house software). Written by Havoc
|
||||
* Pennington <hp@pobox.com>
|
||||
*/
|
||||
|
||||
typedef gint32 GTime;
|
||||
typedef guint16 GDateYear;
|
||||
typedef guint8 GDateDay; /* day of the month */
|
||||
typedef struct _GDate GDate;
|
||||
|
||||
/* enum used to specify order of appearance in parsed date strings */
|
||||
typedef enum
|
||||
{
|
||||
G_DATE_DAY = 0,
|
||||
G_DATE_MONTH = 1,
|
||||
G_DATE_YEAR = 2
|
||||
} GDateDMY;
|
||||
|
||||
/* actual week and month values */
|
||||
typedef enum
|
||||
{
|
||||
G_DATE_BAD_WEEKDAY = 0,
|
||||
G_DATE_MONDAY = 1,
|
||||
G_DATE_TUESDAY = 2,
|
||||
G_DATE_WEDNESDAY = 3,
|
||||
G_DATE_THURSDAY = 4,
|
||||
G_DATE_FRIDAY = 5,
|
||||
G_DATE_SATURDAY = 6,
|
||||
G_DATE_SUNDAY = 7
|
||||
} GDateWeekday;
|
||||
typedef enum
|
||||
{
|
||||
G_DATE_BAD_MONTH = 0,
|
||||
G_DATE_JANUARY = 1,
|
||||
G_DATE_FEBRUARY = 2,
|
||||
G_DATE_MARCH = 3,
|
||||
G_DATE_APRIL = 4,
|
||||
G_DATE_MAY = 5,
|
||||
G_DATE_JUNE = 6,
|
||||
G_DATE_JULY = 7,
|
||||
G_DATE_AUGUST = 8,
|
||||
G_DATE_SEPTEMBER = 9,
|
||||
G_DATE_OCTOBER = 10,
|
||||
G_DATE_NOVEMBER = 11,
|
||||
G_DATE_DECEMBER = 12
|
||||
} GDateMonth;
|
||||
|
||||
#define G_DATE_BAD_JULIAN 0U
|
||||
#define G_DATE_BAD_DAY 0U
|
||||
#define G_DATE_BAD_YEAR 0U
|
||||
|
||||
/* Note: directly manipulating structs is generally a bad idea, but
|
||||
* in this case it's an *incredibly* bad idea, because all or part
|
||||
* of this struct can be invalid at any given time. Use the functions,
|
||||
* or you will get hosed, I promise.
|
||||
*/
|
||||
struct _GDate
|
||||
{
|
||||
guint julian_days : 32; /* julian days representation - we use a
|
||||
* bitfield hoping that 64 bit platforms
|
||||
* will pack this whole struct in one big
|
||||
* int
|
||||
*/
|
||||
|
||||
guint julian : 1; /* julian is valid */
|
||||
guint dmy : 1; /* dmy is valid */
|
||||
|
||||
/* DMY representation */
|
||||
guint day : 6;
|
||||
guint month : 4;
|
||||
guint year : 16;
|
||||
};
|
||||
|
||||
/* g_date_new() returns an invalid date, you then have to _set() stuff
|
||||
* to get a usable object. You can also allocate a GDate statically,
|
||||
* then call g_date_clear() to initialize.
|
||||
*/
|
||||
GDate* g_date_new (void);
|
||||
GDate* g_date_new_dmy (GDateDay day,
|
||||
GDateMonth month,
|
||||
GDateYear year);
|
||||
GDate* g_date_new_julian (guint32 julian_day);
|
||||
void g_date_free (GDate *date);
|
||||
|
||||
/* check g_date_valid() after doing an operation that might fail, like
|
||||
* _parse. Almost all g_date operations are undefined on invalid
|
||||
* dates (the exceptions are the mutators, since you need those to
|
||||
* return to validity).
|
||||
*/
|
||||
gboolean g_date_valid (const GDate *date);
|
||||
gboolean g_date_valid_day (GDateDay day) G_GNUC_CONST;
|
||||
gboolean g_date_valid_month (GDateMonth month) G_GNUC_CONST;
|
||||
gboolean g_date_valid_year (GDateYear year) G_GNUC_CONST;
|
||||
gboolean g_date_valid_weekday (GDateWeekday weekday) G_GNUC_CONST;
|
||||
gboolean g_date_valid_julian (guint32 julian_date) G_GNUC_CONST;
|
||||
gboolean g_date_valid_dmy (GDateDay day,
|
||||
GDateMonth month,
|
||||
GDateYear year) G_GNUC_CONST;
|
||||
|
||||
GDateWeekday g_date_get_weekday (const GDate *date);
|
||||
GDateMonth g_date_get_month (const GDate *date);
|
||||
GDateYear g_date_get_year (const GDate *date);
|
||||
GDateDay g_date_get_day (const GDate *date);
|
||||
guint32 g_date_get_julian (const GDate *date);
|
||||
guint g_date_get_day_of_year (const GDate *date);
|
||||
/* First monday/sunday is the start of week 1; if we haven't reached
|
||||
* that day, return 0. These are not ISO weeks of the year; that
|
||||
* routine needs to be added.
|
||||
* these functions return the number of weeks, starting on the
|
||||
* corrsponding day
|
||||
*/
|
||||
guint g_date_get_monday_week_of_year (const GDate *date);
|
||||
guint g_date_get_sunday_week_of_year (const GDate *date);
|
||||
guint g_date_get_iso8601_week_of_year (const GDate *date);
|
||||
|
||||
/* If you create a static date struct you need to clear it to get it
|
||||
* in a sane state before use. You can clear a whole array at
|
||||
* once with the ndates argument.
|
||||
*/
|
||||
void g_date_clear (GDate *date,
|
||||
guint n_dates);
|
||||
|
||||
/* The parse routine is meant for dates typed in by a user, so it
|
||||
* permits many formats but tries to catch common typos. If your data
|
||||
* needs to be strictly validated, it is not an appropriate function.
|
||||
*/
|
||||
void g_date_set_parse (GDate *date,
|
||||
const gchar *str);
|
||||
void g_date_set_time_t (GDate *date,
|
||||
time_t timet);
|
||||
void g_date_set_time_val (GDate *date,
|
||||
GTimeVal *timeval);
|
||||
#ifndef G_DISABLE_DEPRECATED
|
||||
void g_date_set_time (GDate *date,
|
||||
GTime time_);
|
||||
#endif
|
||||
void g_date_set_month (GDate *date,
|
||||
GDateMonth month);
|
||||
void g_date_set_day (GDate *date,
|
||||
GDateDay day);
|
||||
void g_date_set_year (GDate *date,
|
||||
GDateYear year);
|
||||
void g_date_set_dmy (GDate *date,
|
||||
GDateDay day,
|
||||
GDateMonth month,
|
||||
GDateYear y);
|
||||
void g_date_set_julian (GDate *date,
|
||||
guint32 julian_date);
|
||||
gboolean g_date_is_first_of_month (const GDate *date);
|
||||
gboolean g_date_is_last_of_month (const GDate *date);
|
||||
|
||||
/* To go forward by some number of weeks just go forward weeks*7 days */
|
||||
void g_date_add_days (GDate *date,
|
||||
guint n_days);
|
||||
void g_date_subtract_days (GDate *date,
|
||||
guint n_days);
|
||||
|
||||
/* If you add/sub months while day > 28, the day might change */
|
||||
void g_date_add_months (GDate *date,
|
||||
guint n_months);
|
||||
void g_date_subtract_months (GDate *date,
|
||||
guint n_months);
|
||||
|
||||
/* If it's feb 29, changing years can move you to the 28th */
|
||||
void g_date_add_years (GDate *date,
|
||||
guint n_years);
|
||||
void g_date_subtract_years (GDate *date,
|
||||
guint n_years);
|
||||
gboolean g_date_is_leap_year (GDateYear year) G_GNUC_CONST;
|
||||
guint8 g_date_get_days_in_month (GDateMonth month,
|
||||
GDateYear year) G_GNUC_CONST;
|
||||
guint8 g_date_get_monday_weeks_in_year (GDateYear year) G_GNUC_CONST;
|
||||
guint8 g_date_get_sunday_weeks_in_year (GDateYear year) G_GNUC_CONST;
|
||||
|
||||
/* Returns the number of days between the two dates. If date2 comes
|
||||
before date1, a negative value is return. */
|
||||
gint g_date_days_between (const GDate *date1,
|
||||
const GDate *date2);
|
||||
|
||||
/* qsort-friendly (with a cast...) */
|
||||
gint g_date_compare (const GDate *lhs,
|
||||
const GDate *rhs);
|
||||
void g_date_to_struct_tm (const GDate *date,
|
||||
struct tm *tm);
|
||||
|
||||
void g_date_clamp (GDate *date,
|
||||
const GDate *min_date,
|
||||
const GDate *max_date);
|
||||
|
||||
/* Swap date1 and date2's values if date1 > date2. */
|
||||
void g_date_order (GDate *date1, GDate *date2);
|
||||
|
||||
/* Just like strftime() except you can only use date-related formats.
|
||||
* Using a time format is undefined.
|
||||
*/
|
||||
gsize g_date_strftime (gchar *s,
|
||||
gsize slen,
|
||||
const gchar *format,
|
||||
const GDate *date);
|
||||
|
||||
#ifndef G_DISABLE_DEPRECATED
|
||||
|
||||
#define g_date_weekday g_date_get_weekday
|
||||
#define g_date_month g_date_get_month
|
||||
#define g_date_year g_date_get_year
|
||||
#define g_date_day g_date_get_day
|
||||
#define g_date_julian g_date_get_julian
|
||||
#define g_date_day_of_year g_date_get_day_of_year
|
||||
#define g_date_monday_week_of_year g_date_get_monday_week_of_year
|
||||
#define g_date_sunday_week_of_year g_date_get_sunday_week_of_year
|
||||
#define g_date_days_in_month g_date_get_days_in_month
|
||||
#define g_date_monday_weeks_in_year g_date_get_monday_weeks_in_year
|
||||
#define g_date_sunday_weeks_in_year g_date_get_sunday_weeks_in_year
|
||||
|
||||
#endif /* G_DISABLE_DEPRECATED */
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_DATE_H__ */
|
|
@ -0,0 +1,59 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#ifndef __G_DEBUG_H__
|
||||
#define __G_DEBUG_H__
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef enum {
|
||||
G_DEBUG_FATAL_WARNINGS = 1 << 0,
|
||||
G_DEBUG_FATAL_CRITICALS = 1 << 1
|
||||
} GDebugFlag;
|
||||
|
||||
|
||||
#ifdef G_ENABLE_DEBUG
|
||||
|
||||
#define G_NOTE(type, action) G_STMT_START { \
|
||||
if (!_g_debug_initialized) \
|
||||
{ _g_debug_init (); } \
|
||||
if (_g_debug_flags & G_DEBUG_##type) \
|
||||
{ action; }; } G_STMT_END
|
||||
|
||||
#else /* !G_ENABLE_DEBUG */
|
||||
|
||||
#define G_NOTE(type, action)
|
||||
|
||||
#endif /* G_ENABLE_DEBUG */
|
||||
|
||||
GLIB_VAR gboolean _g_debug_initialized;
|
||||
GLIB_VAR guint _g_debug_flags;
|
||||
|
||||
G_GNUC_INTERNAL void _g_debug_init (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_DEBUG_H__ */
|
|
@ -0,0 +1,302 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* gdir.c: Simplified wrapper around the DIRENT functions.
|
||||
*
|
||||
* Copyright 2001 Hans Breuer
|
||||
* Copyright 2004 Tor Lillqvist
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifdef HAVE_DIRENT_H
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
#include "glib.h"
|
||||
#include "gdir.h"
|
||||
|
||||
#include "glibintl.h"
|
||||
|
||||
#include "galias.h"
|
||||
|
||||
#if defined (_MSC_VER) && !defined (HAVE_DIRENT_H)
|
||||
#include "../dirent/dirent.h"
|
||||
#include "../dirent/wdirent.c"
|
||||
#endif
|
||||
|
||||
struct _GDir
|
||||
{
|
||||
#ifdef G_OS_WIN32
|
||||
_WDIR *wdirp;
|
||||
#else
|
||||
DIR *dirp;
|
||||
#endif
|
||||
#ifdef G_OS_WIN32
|
||||
gchar utf8_buf[FILENAME_MAX*4];
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* g_dir_open:
|
||||
* @path: the path to the directory you are interested in. On Unix
|
||||
* in the on-disk encoding. On Windows in UTF-8
|
||||
* @flags: Currently must be set to 0. Reserved for future use.
|
||||
* @error: return location for a #GError, or %NULL.
|
||||
* If non-%NULL, an error will be set if and only if
|
||||
* g_dir_open() fails.
|
||||
*
|
||||
* Opens a directory for reading. The names of the files in the
|
||||
* directory can then be retrieved using g_dir_read_name().
|
||||
*
|
||||
* Return value: a newly allocated #GDir on success, %NULL on failure.
|
||||
* If non-%NULL, you must free the result with g_dir_close()
|
||||
* when you are finished with it.
|
||||
**/
|
||||
GDir *
|
||||
g_dir_open (const gchar *path,
|
||||
guint flags,
|
||||
GError **error)
|
||||
{
|
||||
GDir *dir;
|
||||
#ifdef G_OS_WIN32
|
||||
wchar_t *wpath;
|
||||
#else
|
||||
gchar *utf8_path;
|
||||
#endif
|
||||
|
||||
g_return_val_if_fail (path != NULL, NULL);
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
wpath = g_utf8_to_utf16 (path, -1, NULL, NULL, error);
|
||||
|
||||
if (wpath == NULL)
|
||||
return NULL;
|
||||
|
||||
dir = g_new (GDir, 1);
|
||||
|
||||
dir->wdirp = _wopendir (wpath);
|
||||
g_free (wpath);
|
||||
|
||||
if (dir->wdirp)
|
||||
return dir;
|
||||
|
||||
/* error case */
|
||||
|
||||
g_set_error (error,
|
||||
G_FILE_ERROR,
|
||||
g_file_error_from_errno (errno),
|
||||
_("Error opening directory '%s': %s"),
|
||||
path, g_strerror (errno));
|
||||
|
||||
g_free (dir);
|
||||
|
||||
return NULL;
|
||||
#else
|
||||
dir = g_new (GDir, 1);
|
||||
|
||||
dir->dirp = opendir (path);
|
||||
|
||||
if (dir->dirp)
|
||||
return dir;
|
||||
|
||||
/* error case */
|
||||
utf8_path = g_filename_to_utf8 (path, -1,
|
||||
NULL, NULL, NULL);
|
||||
g_set_error (error,
|
||||
G_FILE_ERROR,
|
||||
g_file_error_from_errno (errno),
|
||||
_("Error opening directory '%s': %s"),
|
||||
utf8_path, g_strerror (errno));
|
||||
|
||||
g_free (utf8_path);
|
||||
g_free (dir);
|
||||
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined (G_OS_WIN32) && !defined (_WIN64)
|
||||
|
||||
/* The above function actually is called g_dir_open_utf8, and it's
|
||||
* that what applications compiled with this GLib version will
|
||||
* use.
|
||||
*/
|
||||
|
||||
#undef g_dir_open
|
||||
|
||||
/* Binary compatibility version. Not for newly compiled code. */
|
||||
|
||||
GDir *
|
||||
g_dir_open (const gchar *path,
|
||||
guint flags,
|
||||
GError **error)
|
||||
{
|
||||
gchar *utf8_path = g_locale_to_utf8 (path, -1, NULL, NULL, error);
|
||||
GDir *retval;
|
||||
|
||||
if (utf8_path == NULL)
|
||||
return NULL;
|
||||
|
||||
retval = g_dir_open_utf8 (utf8_path, flags, error);
|
||||
|
||||
g_free (utf8_path);
|
||||
|
||||
return retval;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* g_dir_read_name:
|
||||
* @dir: a #GDir* created by g_dir_open()
|
||||
*
|
||||
* Retrieves the name of the next entry in the directory. The '.' and
|
||||
* '..' entries are omitted. On Windows, the returned name is in
|
||||
* UTF-8. On Unix, it is in the on-disk encoding.
|
||||
*
|
||||
* Return value: The entry's name or %NULL if there are no
|
||||
* more entries. The return value is owned by GLib and
|
||||
* must not be modified or freed.
|
||||
**/
|
||||
G_CONST_RETURN gchar*
|
||||
g_dir_read_name (GDir *dir)
|
||||
{
|
||||
#ifdef G_OS_WIN32
|
||||
gchar *utf8_name;
|
||||
struct _wdirent *wentry;
|
||||
#else
|
||||
struct dirent *entry;
|
||||
#endif
|
||||
|
||||
g_return_val_if_fail (dir != NULL, NULL);
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
while (1)
|
||||
{
|
||||
wentry = _wreaddir (dir->wdirp);
|
||||
while (wentry
|
||||
&& (0 == wcscmp (wentry->d_name, L".") ||
|
||||
0 == wcscmp (wentry->d_name, L"..")))
|
||||
wentry = _wreaddir (dir->wdirp);
|
||||
|
||||
if (wentry == NULL)
|
||||
return NULL;
|
||||
|
||||
utf8_name = g_utf16_to_utf8 (wentry->d_name, -1, NULL, NULL, NULL);
|
||||
|
||||
if (utf8_name == NULL)
|
||||
continue; /* Huh, impossible? Skip it anyway */
|
||||
|
||||
strcpy (dir->utf8_buf, utf8_name);
|
||||
g_free (utf8_name);
|
||||
|
||||
return dir->utf8_buf;
|
||||
}
|
||||
#else
|
||||
entry = readdir (dir->dirp);
|
||||
while (entry
|
||||
&& (0 == strcmp (entry->d_name, ".") ||
|
||||
0 == strcmp (entry->d_name, "..")))
|
||||
entry = readdir (dir->dirp);
|
||||
|
||||
if (entry)
|
||||
return entry->d_name;
|
||||
else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined (G_OS_WIN32) && !defined (_WIN64)
|
||||
|
||||
/* Ditto for g_dir_read_name */
|
||||
|
||||
#undef g_dir_read_name
|
||||
|
||||
/* Binary compatibility version. Not for newly compiled code. */
|
||||
|
||||
G_CONST_RETURN gchar*
|
||||
g_dir_read_name (GDir *dir)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
const gchar *utf8_name = g_dir_read_name_utf8 (dir);
|
||||
gchar *retval;
|
||||
|
||||
if (utf8_name == NULL)
|
||||
return NULL;
|
||||
|
||||
retval = g_locale_from_utf8 (utf8_name, -1, NULL, NULL, NULL);
|
||||
|
||||
if (retval != NULL)
|
||||
{
|
||||
strcpy (dir->utf8_buf, retval);
|
||||
g_free (retval);
|
||||
|
||||
return dir->utf8_buf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* g_dir_rewind:
|
||||
* @dir: a #GDir* created by g_dir_open()
|
||||
*
|
||||
* Resets the given directory. The next call to g_dir_read_name()
|
||||
* will return the first entry again.
|
||||
**/
|
||||
void
|
||||
g_dir_rewind (GDir *dir)
|
||||
{
|
||||
g_return_if_fail (dir != NULL);
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
_wrewinddir (dir->wdirp);
|
||||
#else
|
||||
rewinddir (dir->dirp);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* g_dir_close:
|
||||
* @dir: a #GDir* created by g_dir_open()
|
||||
*
|
||||
* Closes the directory and deallocates all related resources.
|
||||
**/
|
||||
void
|
||||
g_dir_close (GDir *dir)
|
||||
{
|
||||
g_return_if_fail (dir != NULL);
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
_wclosedir (dir->wdirp);
|
||||
#else
|
||||
closedir (dir->dirp);
|
||||
#endif
|
||||
g_free (dir);
|
||||
}
|
||||
|
||||
#define __G_DIR_C__
|
||||
#include "galiasdef.c"
|
|
@ -0,0 +1,52 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* gdir.c: Simplified wrapper around the DIRENT functions.
|
||||
*
|
||||
* Copyright 2001 Hans Breuer
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
|
||||
#error "Only <glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __G_DIR_H__
|
||||
#define __G_DIR_H__
|
||||
|
||||
#include <glib/gerror.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GDir GDir;
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
/* For DLL ABI stability, keep old names for old (non-UTF-8) functionality. */
|
||||
#define g_dir_open g_dir_open_utf8
|
||||
#define g_dir_read_name g_dir_read_name_utf8
|
||||
#endif
|
||||
|
||||
GDir * g_dir_open (const gchar *path,
|
||||
guint flags,
|
||||
GError **error);
|
||||
G_CONST_RETURN gchar *g_dir_read_name (GDir *dir);
|
||||
void g_dir_rewind (GDir *dir);
|
||||
void g_dir_close (GDir *dir);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_DIR_H__ */
|
|
@ -0,0 +1,375 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "glib.h"
|
||||
#include "galias.h"
|
||||
|
||||
|
||||
static GError*
|
||||
g_error_new_valist (GQuark domain,
|
||||
gint code,
|
||||
const gchar *format,
|
||||
va_list args)
|
||||
{
|
||||
GError *error;
|
||||
|
||||
error = g_slice_new (GError);
|
||||
|
||||
error->domain = domain;
|
||||
error->code = code;
|
||||
error->message = g_strdup_vprintf (format, args);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_error_new:
|
||||
* @domain: error domain
|
||||
* @code: error code
|
||||
* @format: printf()-style format for error message
|
||||
* @Varargs: parameters for message format
|
||||
*
|
||||
* Creates a new #GError with the given @domain and @code,
|
||||
* and a message formatted with @format.
|
||||
*
|
||||
* Return value: a new #GError
|
||||
**/
|
||||
GError*
|
||||
g_error_new (GQuark domain,
|
||||
gint code,
|
||||
const gchar *format,
|
||||
...)
|
||||
{
|
||||
GError* error;
|
||||
va_list args;
|
||||
|
||||
g_return_val_if_fail (format != NULL, NULL);
|
||||
g_return_val_if_fail (domain != 0, NULL);
|
||||
|
||||
va_start (args, format);
|
||||
error = g_error_new_valist (domain, code, format, args);
|
||||
va_end (args);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_error_new_literal:
|
||||
* @domain: error domain
|
||||
* @code: error code
|
||||
* @message: error message
|
||||
*
|
||||
* Creates a new #GError; unlike g_error_new(), @message is not
|
||||
* a printf()-style format string. Use this
|
||||
* function if @message contains text you don't have control over,
|
||||
* that could include printf() escape sequences.
|
||||
*
|
||||
* Return value: a new #GError
|
||||
**/
|
||||
GError*
|
||||
g_error_new_literal (GQuark domain,
|
||||
gint code,
|
||||
const gchar *message)
|
||||
{
|
||||
GError* err;
|
||||
|
||||
g_return_val_if_fail (message != NULL, NULL);
|
||||
g_return_val_if_fail (domain != 0, NULL);
|
||||
|
||||
err = g_slice_new (GError);
|
||||
|
||||
err->domain = domain;
|
||||
err->code = code;
|
||||
err->message = g_strdup (message);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_error_free:
|
||||
* @error: a #GError
|
||||
*
|
||||
* Frees a #GError and associated resources.
|
||||
*
|
||||
**/
|
||||
void
|
||||
g_error_free (GError *error)
|
||||
{
|
||||
g_return_if_fail (error != NULL);
|
||||
|
||||
g_free (error->message);
|
||||
|
||||
g_slice_free (GError, error);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_error_copy:
|
||||
* @error: a #GError
|
||||
*
|
||||
* Makes a copy of @error.
|
||||
*
|
||||
* Return value: a new #GError
|
||||
**/
|
||||
GError*
|
||||
g_error_copy (const GError *error)
|
||||
{
|
||||
GError *copy;
|
||||
|
||||
g_return_val_if_fail (error != NULL, NULL);
|
||||
|
||||
copy = g_slice_new (GError);
|
||||
|
||||
*copy = *error;
|
||||
|
||||
copy->message = g_strdup (error->message);
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_error_matches:
|
||||
* @error: a #GError
|
||||
* @domain: an error domain
|
||||
* @code: an error code
|
||||
*
|
||||
* Returns %TRUE if @error matches @domain and @code, %FALSE
|
||||
* otherwise.
|
||||
*
|
||||
* Return value: whether @error has @domain and @code
|
||||
**/
|
||||
gboolean
|
||||
g_error_matches (const GError *error,
|
||||
GQuark domain,
|
||||
gint code)
|
||||
{
|
||||
return error &&
|
||||
error->domain == domain &&
|
||||
error->code == code;
|
||||
}
|
||||
|
||||
#define ERROR_OVERWRITTEN_WARNING "GError set over the top of a previous GError or uninitialized memory.\n" \
|
||||
"This indicates a bug in someone's code. You must ensure an error is NULL before it's set.\n" \
|
||||
"The overwriting error message was: %s"
|
||||
|
||||
/**
|
||||
* g_set_error:
|
||||
* @err: a return location for a #GError, or %NULL
|
||||
* @domain: error domain
|
||||
* @code: error code
|
||||
* @format: printf()-style format
|
||||
* @Varargs: args for @format
|
||||
*
|
||||
* Does nothing if @err is %NULL; if @err is non-%NULL, then *@err must
|
||||
* be %NULL. A new #GError is created and assigned to *@err.
|
||||
**/
|
||||
void
|
||||
g_set_error (GError **err,
|
||||
GQuark domain,
|
||||
gint code,
|
||||
const gchar *format,
|
||||
...)
|
||||
{
|
||||
GError *new;
|
||||
|
||||
va_list args;
|
||||
|
||||
if (err == NULL)
|
||||
return;
|
||||
|
||||
va_start (args, format);
|
||||
new = g_error_new_valist (domain, code, format, args);
|
||||
va_end (args);
|
||||
|
||||
if (*err == NULL)
|
||||
*err = new;
|
||||
else
|
||||
g_warning (ERROR_OVERWRITTEN_WARNING, new->message);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_set_error_literal:
|
||||
* @err: a return location for a #GError, or %NULL
|
||||
* @domain: error domain
|
||||
* @code: error code
|
||||
* @message: error message
|
||||
*
|
||||
* Does nothing if @err is %NULL; if @err is non-%NULL, then *@err must
|
||||
* be %NULL. A new #GError is created and assigned to *@err.
|
||||
* Unlike g_set_error(), @message is not a printf()-style format string.
|
||||
* Use this function if @message contains text you don't have control over,
|
||||
* that could include printf() escape sequences.
|
||||
*
|
||||
* Since: 2.18
|
||||
**/
|
||||
void
|
||||
g_set_error_literal (GError **err,
|
||||
GQuark domain,
|
||||
gint code,
|
||||
const gchar *message)
|
||||
{
|
||||
GError *new;
|
||||
|
||||
if (err == NULL)
|
||||
return;
|
||||
|
||||
new = g_error_new_literal (domain, code, message);
|
||||
if (*err == NULL)
|
||||
*err = new;
|
||||
else
|
||||
g_warning (ERROR_OVERWRITTEN_WARNING, new->message);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_propagate_error:
|
||||
* @dest: error return location
|
||||
* @src: error to move into the return location
|
||||
*
|
||||
* If @dest is %NULL, free @src; otherwise, moves @src into *@dest.
|
||||
* The error variable @dest points to must be %NULL.
|
||||
**/
|
||||
void
|
||||
g_propagate_error (GError **dest,
|
||||
GError *src)
|
||||
{
|
||||
g_return_if_fail (src != NULL);
|
||||
|
||||
if (dest == NULL)
|
||||
{
|
||||
if (src)
|
||||
g_error_free (src);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (*dest != NULL)
|
||||
g_warning (ERROR_OVERWRITTEN_WARNING, src->message);
|
||||
else
|
||||
*dest = src;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* g_clear_error:
|
||||
* @err: a #GError return location
|
||||
*
|
||||
* If @err is %NULL, does nothing. If @err is non-%NULL,
|
||||
* calls g_error_free() on *@err and sets *@err to %NULL.
|
||||
**/
|
||||
void
|
||||
g_clear_error (GError **err)
|
||||
{
|
||||
if (err && *err)
|
||||
{
|
||||
g_error_free (*err);
|
||||
*err = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
g_error_add_prefix (gchar **string,
|
||||
const gchar *format,
|
||||
va_list ap)
|
||||
{
|
||||
gchar *oldstring;
|
||||
gchar *prefix;
|
||||
|
||||
prefix = g_strdup_vprintf (format, ap);
|
||||
oldstring = *string;
|
||||
*string = g_strconcat (prefix, oldstring, NULL);
|
||||
g_free (oldstring);
|
||||
g_free (prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_prefix_error:
|
||||
* @err: a return location for a #GError, or %NULL
|
||||
* @format: printf()-style format string
|
||||
* @...: arguments to @format
|
||||
*
|
||||
* Formats a string according to @format and
|
||||
* prefix it to an existing error message. If
|
||||
* @err is %NULL (ie: no error variable) then do
|
||||
* nothing.
|
||||
*
|
||||
* If *@err is %NULL (ie: an error variable is
|
||||
* present but there is no error condition) then
|
||||
* also do nothing. Whether or not it makes
|
||||
* sense to take advantage of this feature is up
|
||||
* to you.
|
||||
*
|
||||
* Since: 2.16
|
||||
**/
|
||||
void
|
||||
g_prefix_error (GError **err,
|
||||
const gchar *format,
|
||||
...)
|
||||
{
|
||||
if (err && *err)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start (ap, format);
|
||||
g_error_add_prefix (&(*err)->message, format, ap);
|
||||
va_end (ap);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* g_propagate_prefixed_error:
|
||||
* @dest: error return location
|
||||
* @src: error to move into the return location
|
||||
* @format: printf()-style format string
|
||||
* @...: arguments to @format
|
||||
*
|
||||
* If @dest is %NULL, free @src; otherwise,
|
||||
* moves @src into *@dest. *@dest must be %NULL.
|
||||
* After the move, add a prefix as with
|
||||
* g_prefix_error().
|
||||
*
|
||||
* Since: 2.16
|
||||
**/
|
||||
void
|
||||
g_propagate_prefixed_error (GError **dest,
|
||||
GError *src,
|
||||
const gchar *format,
|
||||
...)
|
||||
{
|
||||
g_propagate_error (dest, src);
|
||||
|
||||
if (dest && *dest)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start (ap, format);
|
||||
g_error_add_prefix (&(*dest)->message, format, ap);
|
||||
va_end (ap);
|
||||
}
|
||||
}
|
||||
|
||||
#define __G_ERROR_C__
|
||||
#include "galiasdef.c"
|
|
@ -0,0 +1,92 @@
|
|||
/* gerror.h - Error reporting system
|
||||
*
|
||||
* Copyright 2000 Red Hat, Inc.
|
||||
*
|
||||
* The Gnome Library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* The Gnome Library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with the Gnome Library; see the file COPYING.LIB. If not,
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
|
||||
#error "Only <glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __G_ERROR_H__
|
||||
#define __G_ERROR_H__
|
||||
|
||||
#include <glib/gquark.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GError GError;
|
||||
|
||||
struct _GError
|
||||
{
|
||||
GQuark domain;
|
||||
gint code;
|
||||
gchar *message;
|
||||
};
|
||||
|
||||
GError* g_error_new (GQuark domain,
|
||||
gint code,
|
||||
const gchar *format,
|
||||
...) G_GNUC_PRINTF (3, 4);
|
||||
|
||||
GError* g_error_new_literal (GQuark domain,
|
||||
gint code,
|
||||
const gchar *message);
|
||||
|
||||
void g_error_free (GError *error);
|
||||
GError* g_error_copy (const GError *error);
|
||||
|
||||
gboolean g_error_matches (const GError *error,
|
||||
GQuark domain,
|
||||
gint code);
|
||||
|
||||
/* if (err) *err = g_error_new(domain, code, format, ...), also has
|
||||
* some sanity checks.
|
||||
*/
|
||||
void g_set_error (GError **err,
|
||||
GQuark domain,
|
||||
gint code,
|
||||
const gchar *format,
|
||||
...) G_GNUC_PRINTF (4, 5);
|
||||
|
||||
void g_set_error_literal (GError **err,
|
||||
GQuark domain,
|
||||
gint code,
|
||||
const gchar *message);
|
||||
|
||||
/* if (dest) *dest = src; also has some sanity checks.
|
||||
*/
|
||||
void g_propagate_error (GError **dest,
|
||||
GError *src);
|
||||
|
||||
/* if (err && *err) { g_error_free(*err); *err = NULL; } */
|
||||
void g_clear_error (GError **err);
|
||||
|
||||
/* if (err) prefix the formatted string to the ->message */
|
||||
void g_prefix_error (GError **err,
|
||||
const gchar *format,
|
||||
...) G_GNUC_PRINTF (2, 3);
|
||||
|
||||
/* g_propagate_error then g_error_prefix on dest */
|
||||
void g_propagate_prefixed_error (GError **dest,
|
||||
GError *src,
|
||||
const gchar *format,
|
||||
...) G_GNUC_PRINTF (3, 4);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_ERROR_H__ */
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,125 @@
|
|||
/* gfileutils.h - File utility functions
|
||||
*
|
||||
* Copyright 2000 Red Hat, Inc.
|
||||
*
|
||||
* GLib is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* GLib 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with GLib; see the file COPYING.LIB. If not,
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
|
||||
#error "Only <glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __G_FILEUTILS_H__
|
||||
#define __G_FILEUTILS_H__
|
||||
|
||||
#include <glib/gerror.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define G_FILE_ERROR g_file_error_quark ()
|
||||
|
||||
typedef enum
|
||||
{
|
||||
G_FILE_ERROR_EXIST,
|
||||
G_FILE_ERROR_ISDIR,
|
||||
G_FILE_ERROR_ACCES,
|
||||
G_FILE_ERROR_NAMETOOLONG,
|
||||
G_FILE_ERROR_NOENT,
|
||||
G_FILE_ERROR_NOTDIR,
|
||||
G_FILE_ERROR_NXIO,
|
||||
G_FILE_ERROR_NODEV,
|
||||
G_FILE_ERROR_ROFS,
|
||||
G_FILE_ERROR_TXTBSY,
|
||||
G_FILE_ERROR_FAULT,
|
||||
G_FILE_ERROR_LOOP,
|
||||
G_FILE_ERROR_NOSPC,
|
||||
G_FILE_ERROR_NOMEM,
|
||||
G_FILE_ERROR_MFILE,
|
||||
G_FILE_ERROR_NFILE,
|
||||
G_FILE_ERROR_BADF,
|
||||
G_FILE_ERROR_INVAL,
|
||||
G_FILE_ERROR_PIPE,
|
||||
G_FILE_ERROR_AGAIN,
|
||||
G_FILE_ERROR_INTR,
|
||||
G_FILE_ERROR_IO,
|
||||
G_FILE_ERROR_PERM,
|
||||
G_FILE_ERROR_NOSYS,
|
||||
G_FILE_ERROR_FAILED
|
||||
} GFileError;
|
||||
|
||||
/* For backward-compat reasons, these are synced to an old
|
||||
* anonymous enum in libgnome. But don't use that enum
|
||||
* in new code.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
G_FILE_TEST_IS_REGULAR = 1 << 0,
|
||||
G_FILE_TEST_IS_SYMLINK = 1 << 1,
|
||||
G_FILE_TEST_IS_DIR = 1 << 2,
|
||||
G_FILE_TEST_IS_EXECUTABLE = 1 << 3,
|
||||
G_FILE_TEST_EXISTS = 1 << 4
|
||||
} GFileTest;
|
||||
|
||||
GQuark g_file_error_quark (void);
|
||||
/* So other code can generate a GFileError */
|
||||
GFileError g_file_error_from_errno (gint err_no);
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
#define g_file_test g_file_test_utf8
|
||||
#define g_file_get_contents g_file_get_contents_utf8
|
||||
#define g_mkstemp g_mkstemp_utf8
|
||||
#define g_file_open_tmp g_file_open_tmp_utf8
|
||||
#endif
|
||||
|
||||
gboolean g_file_test (const gchar *filename,
|
||||
GFileTest test);
|
||||
gboolean g_file_get_contents (const gchar *filename,
|
||||
gchar **contents,
|
||||
gsize *length,
|
||||
GError **error);
|
||||
gboolean g_file_set_contents (const gchar *filename,
|
||||
const gchar *contents,
|
||||
gssize length,
|
||||
GError **error);
|
||||
gchar *g_file_read_link (const gchar *filename,
|
||||
GError **error);
|
||||
|
||||
/* Wrapper / workalike for mkstemp() */
|
||||
gint g_mkstemp (gchar *tmpl);
|
||||
|
||||
/* Wrapper for g_mkstemp */
|
||||
gint g_file_open_tmp (const gchar *tmpl,
|
||||
gchar **name_used,
|
||||
GError **error);
|
||||
|
||||
char *g_format_size_for_display (goffset size);
|
||||
|
||||
gchar *g_build_path (const gchar *separator,
|
||||
const gchar *first_element,
|
||||
...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
|
||||
gchar *g_build_pathv (const gchar *separator,
|
||||
gchar **args) G_GNUC_MALLOC;
|
||||
|
||||
gchar *g_build_filename (const gchar *first_element,
|
||||
...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
|
||||
gchar *g_build_filenamev (gchar **args) G_GNUC_MALLOC;
|
||||
|
||||
int g_mkdir_with_parents (const gchar *pathname,
|
||||
int mode);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_FILEUTILS_H__ */
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,145 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
|
||||
#error "Only <glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __G_HASH_H__
|
||||
#define __G_HASH_H__
|
||||
|
||||
#include <glib/gtypes.h>
|
||||
#include <glib/glist.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GHashTable GHashTable;
|
||||
|
||||
typedef gboolean (*GHRFunc) (gpointer key,
|
||||
gpointer value,
|
||||
gpointer user_data);
|
||||
|
||||
typedef struct _GHashTableIter GHashTableIter;
|
||||
|
||||
struct _GHashTableIter
|
||||
{
|
||||
/*< private >*/
|
||||
gpointer dummy1;
|
||||
gpointer dummy2;
|
||||
gpointer dummy3;
|
||||
int dummy4;
|
||||
gboolean dummy5;
|
||||
gpointer dummy6;
|
||||
};
|
||||
|
||||
/* Hash tables
|
||||
*/
|
||||
GHashTable* g_hash_table_new (GHashFunc hash_func,
|
||||
GEqualFunc key_equal_func);
|
||||
GHashTable* g_hash_table_new_full (GHashFunc hash_func,
|
||||
GEqualFunc key_equal_func,
|
||||
GDestroyNotify key_destroy_func,
|
||||
GDestroyNotify value_destroy_func);
|
||||
void g_hash_table_destroy (GHashTable *hash_table);
|
||||
void g_hash_table_insert (GHashTable *hash_table,
|
||||
gpointer key,
|
||||
gpointer value);
|
||||
void g_hash_table_replace (GHashTable *hash_table,
|
||||
gpointer key,
|
||||
gpointer value);
|
||||
gboolean g_hash_table_remove (GHashTable *hash_table,
|
||||
gconstpointer key);
|
||||
void g_hash_table_remove_all (GHashTable *hash_table);
|
||||
gboolean g_hash_table_steal (GHashTable *hash_table,
|
||||
gconstpointer key);
|
||||
void g_hash_table_steal_all (GHashTable *hash_table);
|
||||
gpointer g_hash_table_lookup (GHashTable *hash_table,
|
||||
gconstpointer key);
|
||||
gboolean g_hash_table_lookup_extended (GHashTable *hash_table,
|
||||
gconstpointer lookup_key,
|
||||
gpointer *orig_key,
|
||||
gpointer *value);
|
||||
void g_hash_table_foreach (GHashTable *hash_table,
|
||||
GHFunc func,
|
||||
gpointer user_data);
|
||||
gpointer g_hash_table_find (GHashTable *hash_table,
|
||||
GHRFunc predicate,
|
||||
gpointer user_data);
|
||||
guint g_hash_table_foreach_remove (GHashTable *hash_table,
|
||||
GHRFunc func,
|
||||
gpointer user_data);
|
||||
guint g_hash_table_foreach_steal (GHashTable *hash_table,
|
||||
GHRFunc func,
|
||||
gpointer user_data);
|
||||
guint g_hash_table_size (GHashTable *hash_table);
|
||||
GList * g_hash_table_get_keys (GHashTable *hash_table);
|
||||
GList * g_hash_table_get_values (GHashTable *hash_table);
|
||||
|
||||
void g_hash_table_iter_init (GHashTableIter *iter,
|
||||
GHashTable *hash_table);
|
||||
gboolean g_hash_table_iter_next (GHashTableIter *iter,
|
||||
gpointer *key,
|
||||
gpointer *value);
|
||||
GHashTable* g_hash_table_iter_get_hash_table (GHashTableIter *iter);
|
||||
void g_hash_table_iter_remove (GHashTableIter *iter);
|
||||
void g_hash_table_iter_steal (GHashTableIter *iter);
|
||||
|
||||
/* keeping hash tables alive */
|
||||
GHashTable* g_hash_table_ref (GHashTable *hash_table);
|
||||
void g_hash_table_unref (GHashTable *hash_table);
|
||||
|
||||
#ifndef G_DISABLE_DEPRECATED
|
||||
|
||||
/* The following two functions are deprecated and will be removed in
|
||||
* the next major release. They do no good. */
|
||||
#define g_hash_table_freeze(hash_table) ((void)0)
|
||||
#define g_hash_table_thaw(hash_table) ((void)0)
|
||||
|
||||
#endif /* G_DISABLE_DEPRECATED */
|
||||
|
||||
/* Hash Functions
|
||||
*/
|
||||
gboolean g_str_equal (gconstpointer v1,
|
||||
gconstpointer v2);
|
||||
guint g_str_hash (gconstpointer v);
|
||||
|
||||
gboolean g_int_equal (gconstpointer v1,
|
||||
gconstpointer v2);
|
||||
guint g_int_hash (gconstpointer v);
|
||||
|
||||
/* This "hash" function will just return the key's address as an
|
||||
* unsigned integer. Useful for hashing on plain addresses or
|
||||
* simple integer values.
|
||||
* Passing NULL into g_hash_table_new() as GHashFunc has the
|
||||
* same effect as passing g_direct_hash().
|
||||
*/
|
||||
guint g_direct_hash (gconstpointer v) G_GNUC_CONST;
|
||||
gboolean g_direct_equal (gconstpointer v1,
|
||||
gconstpointer v2) G_GNUC_CONST;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_HASH_H__ */
|
|
@ -0,0 +1,638 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* GHook: Callback maintenance functions
|
||||
* Copyright (C) 1998 Tim Janik
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
/*
|
||||
* MT safe
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "glib.h"
|
||||
#include "galias.h"
|
||||
|
||||
|
||||
/* --- functions --- */
|
||||
static void
|
||||
default_finalize_hook (GHookList *hook_list,
|
||||
GHook *hook)
|
||||
{
|
||||
GDestroyNotify destroy = hook->destroy;
|
||||
|
||||
if (destroy)
|
||||
{
|
||||
hook->destroy = NULL;
|
||||
destroy (hook->data);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
g_hook_list_init (GHookList *hook_list,
|
||||
guint hook_size)
|
||||
{
|
||||
g_return_if_fail (hook_list != NULL);
|
||||
g_return_if_fail (hook_size >= sizeof (GHook));
|
||||
|
||||
hook_list->seq_id = 1;
|
||||
hook_list->hook_size = hook_size;
|
||||
hook_list->is_setup = TRUE;
|
||||
hook_list->hooks = NULL;
|
||||
hook_list->dummy3 = NULL;
|
||||
hook_list->finalize_hook = default_finalize_hook;
|
||||
hook_list->dummy[0] = NULL;
|
||||
hook_list->dummy[1] = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
g_hook_list_clear (GHookList *hook_list)
|
||||
{
|
||||
g_return_if_fail (hook_list != NULL);
|
||||
|
||||
if (hook_list->is_setup)
|
||||
{
|
||||
GHook *hook;
|
||||
|
||||
hook_list->is_setup = FALSE;
|
||||
|
||||
hook = hook_list->hooks;
|
||||
if (!hook)
|
||||
{
|
||||
/* destroy hook_list->hook_memchunk */
|
||||
}
|
||||
else
|
||||
do
|
||||
{
|
||||
GHook *tmp;
|
||||
|
||||
g_hook_ref (hook_list, hook);
|
||||
g_hook_destroy_link (hook_list, hook);
|
||||
tmp = hook->next;
|
||||
g_hook_unref (hook_list, hook);
|
||||
hook = tmp;
|
||||
}
|
||||
while (hook);
|
||||
}
|
||||
}
|
||||
|
||||
GHook*
|
||||
g_hook_alloc (GHookList *hook_list)
|
||||
{
|
||||
GHook *hook;
|
||||
|
||||
g_return_val_if_fail (hook_list != NULL, NULL);
|
||||
g_return_val_if_fail (hook_list->is_setup, NULL);
|
||||
|
||||
hook = g_slice_alloc0 (hook_list->hook_size);
|
||||
hook->data = NULL;
|
||||
hook->next = NULL;
|
||||
hook->prev = NULL;
|
||||
hook->flags = G_HOOK_FLAG_ACTIVE;
|
||||
hook->ref_count = 0;
|
||||
hook->hook_id = 0;
|
||||
hook->func = NULL;
|
||||
hook->destroy = NULL;
|
||||
|
||||
return hook;
|
||||
}
|
||||
|
||||
void
|
||||
g_hook_free (GHookList *hook_list,
|
||||
GHook *hook)
|
||||
{
|
||||
g_return_if_fail (hook_list != NULL);
|
||||
g_return_if_fail (hook_list->is_setup);
|
||||
g_return_if_fail (hook != NULL);
|
||||
g_return_if_fail (G_HOOK_IS_UNLINKED (hook));
|
||||
g_return_if_fail (!G_HOOK_IN_CALL (hook));
|
||||
|
||||
if(hook_list->finalize_hook != NULL)
|
||||
hook_list->finalize_hook (hook_list, hook);
|
||||
g_slice_free1 (hook_list->hook_size, hook);
|
||||
}
|
||||
|
||||
void
|
||||
g_hook_destroy_link (GHookList *hook_list,
|
||||
GHook *hook)
|
||||
{
|
||||
g_return_if_fail (hook_list != NULL);
|
||||
g_return_if_fail (hook != NULL);
|
||||
|
||||
hook->flags &= ~G_HOOK_FLAG_ACTIVE;
|
||||
if (hook->hook_id)
|
||||
{
|
||||
hook->hook_id = 0;
|
||||
g_hook_unref (hook_list, hook); /* counterpart to g_hook_insert_before */
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
g_hook_destroy (GHookList *hook_list,
|
||||
gulong hook_id)
|
||||
{
|
||||
GHook *hook;
|
||||
|
||||
g_return_val_if_fail (hook_list != NULL, FALSE);
|
||||
g_return_val_if_fail (hook_id > 0, FALSE);
|
||||
|
||||
hook = g_hook_get (hook_list, hook_id);
|
||||
if (hook)
|
||||
{
|
||||
g_hook_destroy_link (hook_list, hook);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
g_hook_unref (GHookList *hook_list,
|
||||
GHook *hook)
|
||||
{
|
||||
g_return_if_fail (hook_list != NULL);
|
||||
g_return_if_fail (hook != NULL);
|
||||
g_return_if_fail (hook->ref_count > 0);
|
||||
|
||||
hook->ref_count--;
|
||||
if (!hook->ref_count)
|
||||
{
|
||||
g_return_if_fail (hook->hook_id == 0);
|
||||
g_return_if_fail (!G_HOOK_IN_CALL (hook));
|
||||
|
||||
if (hook->prev)
|
||||
hook->prev->next = hook->next;
|
||||
else
|
||||
hook_list->hooks = hook->next;
|
||||
if (hook->next)
|
||||
{
|
||||
hook->next->prev = hook->prev;
|
||||
hook->next = NULL;
|
||||
}
|
||||
hook->prev = NULL;
|
||||
|
||||
if (!hook_list->is_setup)
|
||||
{
|
||||
hook_list->is_setup = TRUE;
|
||||
g_hook_free (hook_list, hook);
|
||||
hook_list->is_setup = FALSE;
|
||||
|
||||
if (!hook_list->hooks)
|
||||
{
|
||||
/* destroy hook_list->hook_memchunk */
|
||||
}
|
||||
}
|
||||
else
|
||||
g_hook_free (hook_list, hook);
|
||||
}
|
||||
}
|
||||
|
||||
GHook *
|
||||
g_hook_ref (GHookList *hook_list,
|
||||
GHook *hook)
|
||||
{
|
||||
g_return_val_if_fail (hook_list != NULL, NULL);
|
||||
g_return_val_if_fail (hook != NULL, NULL);
|
||||
g_return_val_if_fail (hook->ref_count > 0, NULL);
|
||||
|
||||
hook->ref_count++;
|
||||
|
||||
return hook;
|
||||
}
|
||||
|
||||
void
|
||||
g_hook_prepend (GHookList *hook_list,
|
||||
GHook *hook)
|
||||
{
|
||||
g_return_if_fail (hook_list != NULL);
|
||||
|
||||
g_hook_insert_before (hook_list, hook_list->hooks, hook);
|
||||
}
|
||||
|
||||
void
|
||||
g_hook_insert_before (GHookList *hook_list,
|
||||
GHook *sibling,
|
||||
GHook *hook)
|
||||
{
|
||||
g_return_if_fail (hook_list != NULL);
|
||||
g_return_if_fail (hook_list->is_setup);
|
||||
g_return_if_fail (hook != NULL);
|
||||
g_return_if_fail (G_HOOK_IS_UNLINKED (hook));
|
||||
g_return_if_fail (hook->ref_count == 0);
|
||||
|
||||
hook->hook_id = hook_list->seq_id++;
|
||||
hook->ref_count = 1; /* counterpart to g_hook_destroy_link */
|
||||
|
||||
if (sibling)
|
||||
{
|
||||
if (sibling->prev)
|
||||
{
|
||||
hook->prev = sibling->prev;
|
||||
hook->prev->next = hook;
|
||||
hook->next = sibling;
|
||||
sibling->prev = hook;
|
||||
}
|
||||
else
|
||||
{
|
||||
hook_list->hooks = hook;
|
||||
hook->next = sibling;
|
||||
sibling->prev = hook;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (hook_list->hooks)
|
||||
{
|
||||
sibling = hook_list->hooks;
|
||||
while (sibling->next)
|
||||
sibling = sibling->next;
|
||||
hook->prev = sibling;
|
||||
sibling->next = hook;
|
||||
}
|
||||
else
|
||||
hook_list->hooks = hook;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
g_hook_list_invoke (GHookList *hook_list,
|
||||
gboolean may_recurse)
|
||||
{
|
||||
GHook *hook;
|
||||
|
||||
g_return_if_fail (hook_list != NULL);
|
||||
g_return_if_fail (hook_list->is_setup);
|
||||
|
||||
hook = g_hook_first_valid (hook_list, may_recurse);
|
||||
while (hook)
|
||||
{
|
||||
GHookFunc func;
|
||||
gboolean was_in_call;
|
||||
|
||||
func = (GHookFunc) hook->func;
|
||||
|
||||
was_in_call = G_HOOK_IN_CALL (hook);
|
||||
hook->flags |= G_HOOK_FLAG_IN_CALL;
|
||||
func (hook->data);
|
||||
if (!was_in_call)
|
||||
hook->flags &= ~G_HOOK_FLAG_IN_CALL;
|
||||
|
||||
hook = g_hook_next_valid (hook_list, hook, may_recurse);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
g_hook_list_invoke_check (GHookList *hook_list,
|
||||
gboolean may_recurse)
|
||||
{
|
||||
GHook *hook;
|
||||
|
||||
g_return_if_fail (hook_list != NULL);
|
||||
g_return_if_fail (hook_list->is_setup);
|
||||
|
||||
hook = g_hook_first_valid (hook_list, may_recurse);
|
||||
while (hook)
|
||||
{
|
||||
GHookCheckFunc func;
|
||||
gboolean was_in_call;
|
||||
gboolean need_destroy;
|
||||
|
||||
func = (GHookCheckFunc) hook->func;
|
||||
|
||||
was_in_call = G_HOOK_IN_CALL (hook);
|
||||
hook->flags |= G_HOOK_FLAG_IN_CALL;
|
||||
need_destroy = !func (hook->data);
|
||||
if (!was_in_call)
|
||||
hook->flags &= ~G_HOOK_FLAG_IN_CALL;
|
||||
if (need_destroy)
|
||||
g_hook_destroy_link (hook_list, hook);
|
||||
|
||||
hook = g_hook_next_valid (hook_list, hook, may_recurse);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
g_hook_list_marshal_check (GHookList *hook_list,
|
||||
gboolean may_recurse,
|
||||
GHookCheckMarshaller marshaller,
|
||||
gpointer data)
|
||||
{
|
||||
GHook *hook;
|
||||
|
||||
g_return_if_fail (hook_list != NULL);
|
||||
g_return_if_fail (hook_list->is_setup);
|
||||
g_return_if_fail (marshaller != NULL);
|
||||
|
||||
hook = g_hook_first_valid (hook_list, may_recurse);
|
||||
while (hook)
|
||||
{
|
||||
gboolean was_in_call;
|
||||
gboolean need_destroy;
|
||||
|
||||
was_in_call = G_HOOK_IN_CALL (hook);
|
||||
hook->flags |= G_HOOK_FLAG_IN_CALL;
|
||||
need_destroy = !marshaller (hook, data);
|
||||
if (!was_in_call)
|
||||
hook->flags &= ~G_HOOK_FLAG_IN_CALL;
|
||||
if (need_destroy)
|
||||
g_hook_destroy_link (hook_list, hook);
|
||||
|
||||
hook = g_hook_next_valid (hook_list, hook, may_recurse);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
g_hook_list_marshal (GHookList *hook_list,
|
||||
gboolean may_recurse,
|
||||
GHookMarshaller marshaller,
|
||||
gpointer data)
|
||||
{
|
||||
GHook *hook;
|
||||
|
||||
g_return_if_fail (hook_list != NULL);
|
||||
g_return_if_fail (hook_list->is_setup);
|
||||
g_return_if_fail (marshaller != NULL);
|
||||
|
||||
hook = g_hook_first_valid (hook_list, may_recurse);
|
||||
while (hook)
|
||||
{
|
||||
gboolean was_in_call;
|
||||
|
||||
was_in_call = G_HOOK_IN_CALL (hook);
|
||||
hook->flags |= G_HOOK_FLAG_IN_CALL;
|
||||
marshaller (hook, data);
|
||||
if (!was_in_call)
|
||||
hook->flags &= ~G_HOOK_FLAG_IN_CALL;
|
||||
|
||||
hook = g_hook_next_valid (hook_list, hook, may_recurse);
|
||||
}
|
||||
}
|
||||
|
||||
GHook*
|
||||
g_hook_first_valid (GHookList *hook_list,
|
||||
gboolean may_be_in_call)
|
||||
{
|
||||
g_return_val_if_fail (hook_list != NULL, NULL);
|
||||
|
||||
if (hook_list->is_setup)
|
||||
{
|
||||
GHook *hook;
|
||||
|
||||
hook = hook_list->hooks;
|
||||
if (hook)
|
||||
{
|
||||
g_hook_ref (hook_list, hook);
|
||||
if (G_HOOK_IS_VALID (hook) && (may_be_in_call || !G_HOOK_IN_CALL (hook)))
|
||||
return hook;
|
||||
else
|
||||
return g_hook_next_valid (hook_list, hook, may_be_in_call);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GHook*
|
||||
g_hook_next_valid (GHookList *hook_list,
|
||||
GHook *hook,
|
||||
gboolean may_be_in_call)
|
||||
{
|
||||
GHook *ohook = hook;
|
||||
|
||||
g_return_val_if_fail (hook_list != NULL, NULL);
|
||||
|
||||
if (!hook)
|
||||
return NULL;
|
||||
|
||||
hook = hook->next;
|
||||
while (hook)
|
||||
{
|
||||
if (G_HOOK_IS_VALID (hook) && (may_be_in_call || !G_HOOK_IN_CALL (hook)))
|
||||
{
|
||||
g_hook_ref (hook_list, hook);
|
||||
g_hook_unref (hook_list, ohook);
|
||||
|
||||
return hook;
|
||||
}
|
||||
hook = hook->next;
|
||||
}
|
||||
g_hook_unref (hook_list, ohook);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GHook*
|
||||
g_hook_get (GHookList *hook_list,
|
||||
gulong hook_id)
|
||||
{
|
||||
GHook *hook;
|
||||
|
||||
g_return_val_if_fail (hook_list != NULL, NULL);
|
||||
g_return_val_if_fail (hook_id > 0, NULL);
|
||||
|
||||
hook = hook_list->hooks;
|
||||
while (hook)
|
||||
{
|
||||
if (hook->hook_id == hook_id)
|
||||
return hook;
|
||||
hook = hook->next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GHook*
|
||||
g_hook_find (GHookList *hook_list,
|
||||
gboolean need_valids,
|
||||
GHookFindFunc func,
|
||||
gpointer data)
|
||||
{
|
||||
GHook *hook;
|
||||
|
||||
g_return_val_if_fail (hook_list != NULL, NULL);
|
||||
g_return_val_if_fail (func != NULL, NULL);
|
||||
|
||||
hook = hook_list->hooks;
|
||||
while (hook)
|
||||
{
|
||||
GHook *tmp;
|
||||
|
||||
/* test only non-destroyed hooks */
|
||||
if (!hook->hook_id)
|
||||
{
|
||||
hook = hook->next;
|
||||
continue;
|
||||
}
|
||||
|
||||
g_hook_ref (hook_list, hook);
|
||||
|
||||
if (func (hook, data) && hook->hook_id && (!need_valids || G_HOOK_ACTIVE (hook)))
|
||||
{
|
||||
g_hook_unref (hook_list, hook);
|
||||
|
||||
return hook;
|
||||
}
|
||||
|
||||
tmp = hook->next;
|
||||
g_hook_unref (hook_list, hook);
|
||||
hook = tmp;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GHook*
|
||||
g_hook_find_data (GHookList *hook_list,
|
||||
gboolean need_valids,
|
||||
gpointer data)
|
||||
{
|
||||
GHook *hook;
|
||||
|
||||
g_return_val_if_fail (hook_list != NULL, NULL);
|
||||
|
||||
hook = hook_list->hooks;
|
||||
while (hook)
|
||||
{
|
||||
/* test only non-destroyed hooks */
|
||||
if (hook->data == data &&
|
||||
hook->hook_id &&
|
||||
(!need_valids || G_HOOK_ACTIVE (hook)))
|
||||
return hook;
|
||||
|
||||
hook = hook->next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GHook*
|
||||
g_hook_find_func (GHookList *hook_list,
|
||||
gboolean need_valids,
|
||||
gpointer func)
|
||||
{
|
||||
GHook *hook;
|
||||
|
||||
g_return_val_if_fail (hook_list != NULL, NULL);
|
||||
g_return_val_if_fail (func != NULL, NULL);
|
||||
|
||||
hook = hook_list->hooks;
|
||||
while (hook)
|
||||
{
|
||||
/* test only non-destroyed hooks */
|
||||
if (hook->func == func &&
|
||||
hook->hook_id &&
|
||||
(!need_valids || G_HOOK_ACTIVE (hook)))
|
||||
return hook;
|
||||
|
||||
hook = hook->next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GHook*
|
||||
g_hook_find_func_data (GHookList *hook_list,
|
||||
gboolean need_valids,
|
||||
gpointer func,
|
||||
gpointer data)
|
||||
{
|
||||
GHook *hook;
|
||||
|
||||
g_return_val_if_fail (hook_list != NULL, NULL);
|
||||
g_return_val_if_fail (func != NULL, NULL);
|
||||
|
||||
hook = hook_list->hooks;
|
||||
while (hook)
|
||||
{
|
||||
/* test only non-destroyed hooks */
|
||||
if (hook->data == data &&
|
||||
hook->func == func &&
|
||||
hook->hook_id &&
|
||||
(!need_valids || G_HOOK_ACTIVE (hook)))
|
||||
return hook;
|
||||
|
||||
hook = hook->next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
g_hook_insert_sorted (GHookList *hook_list,
|
||||
GHook *hook,
|
||||
GHookCompareFunc func)
|
||||
{
|
||||
GHook *sibling;
|
||||
|
||||
g_return_if_fail (hook_list != NULL);
|
||||
g_return_if_fail (hook_list->is_setup);
|
||||
g_return_if_fail (hook != NULL);
|
||||
g_return_if_fail (G_HOOK_IS_UNLINKED (hook));
|
||||
g_return_if_fail (hook->func != NULL);
|
||||
g_return_if_fail (func != NULL);
|
||||
|
||||
/* first non-destroyed hook */
|
||||
sibling = hook_list->hooks;
|
||||
while (sibling && !sibling->hook_id)
|
||||
sibling = sibling->next;
|
||||
|
||||
while (sibling)
|
||||
{
|
||||
GHook *tmp;
|
||||
|
||||
g_hook_ref (hook_list, sibling);
|
||||
if (func (hook, sibling) <= 0 && sibling->hook_id)
|
||||
{
|
||||
g_hook_unref (hook_list, sibling);
|
||||
break;
|
||||
}
|
||||
|
||||
/* next non-destroyed hook */
|
||||
tmp = sibling->next;
|
||||
while (tmp && !tmp->hook_id)
|
||||
tmp = tmp->next;
|
||||
|
||||
g_hook_unref (hook_list, sibling);
|
||||
sibling = tmp;
|
||||
}
|
||||
|
||||
g_hook_insert_before (hook_list, sibling, hook);
|
||||
}
|
||||
|
||||
gint
|
||||
g_hook_compare_ids (GHook *new_hook,
|
||||
GHook *sibling)
|
||||
{
|
||||
if (new_hook->hook_id < sibling->hook_id)
|
||||
return -1;
|
||||
else if (new_hook->hook_id > sibling->hook_id)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define __G_HOOK_C__
|
||||
#include "galiasdef.c"
|
|
@ -0,0 +1,181 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
|
||||
#error "Only <glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __G_HOOK_H__
|
||||
#define __G_HOOK_H__
|
||||
|
||||
#include <glib/gmem.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
/* --- typedefs --- */
|
||||
typedef struct _GHook GHook;
|
||||
typedef struct _GHookList GHookList;
|
||||
|
||||
typedef gint (*GHookCompareFunc) (GHook *new_hook,
|
||||
GHook *sibling);
|
||||
typedef gboolean (*GHookFindFunc) (GHook *hook,
|
||||
gpointer data);
|
||||
typedef void (*GHookMarshaller) (GHook *hook,
|
||||
gpointer marshal_data);
|
||||
typedef gboolean (*GHookCheckMarshaller) (GHook *hook,
|
||||
gpointer marshal_data);
|
||||
typedef void (*GHookFunc) (gpointer data);
|
||||
typedef gboolean (*GHookCheckFunc) (gpointer data);
|
||||
typedef void (*GHookFinalizeFunc) (GHookList *hook_list,
|
||||
GHook *hook);
|
||||
typedef enum
|
||||
{
|
||||
G_HOOK_FLAG_ACTIVE = 1 << 0,
|
||||
G_HOOK_FLAG_IN_CALL = 1 << 1,
|
||||
G_HOOK_FLAG_MASK = 0x0f
|
||||
} GHookFlagMask;
|
||||
#define G_HOOK_FLAG_USER_SHIFT (4)
|
||||
|
||||
|
||||
/* --- structures --- */
|
||||
struct _GHookList
|
||||
{
|
||||
gulong seq_id;
|
||||
guint hook_size : 16;
|
||||
guint is_setup : 1;
|
||||
GHook *hooks;
|
||||
gpointer dummy3;
|
||||
GHookFinalizeFunc finalize_hook;
|
||||
gpointer dummy[2];
|
||||
};
|
||||
struct _GHook
|
||||
{
|
||||
gpointer data;
|
||||
GHook *next;
|
||||
GHook *prev;
|
||||
guint ref_count;
|
||||
gulong hook_id;
|
||||
guint flags;
|
||||
gpointer func;
|
||||
GDestroyNotify destroy;
|
||||
};
|
||||
|
||||
|
||||
/* --- macros --- */
|
||||
#define G_HOOK(hook) ((GHook*) (hook))
|
||||
#define G_HOOK_FLAGS(hook) (G_HOOK (hook)->flags)
|
||||
#define G_HOOK_ACTIVE(hook) ((G_HOOK_FLAGS (hook) & \
|
||||
G_HOOK_FLAG_ACTIVE) != 0)
|
||||
#define G_HOOK_IN_CALL(hook) ((G_HOOK_FLAGS (hook) & \
|
||||
G_HOOK_FLAG_IN_CALL) != 0)
|
||||
#define G_HOOK_IS_VALID(hook) (G_HOOK (hook)->hook_id != 0 && \
|
||||
(G_HOOK_FLAGS (hook) & \
|
||||
G_HOOK_FLAG_ACTIVE))
|
||||
#define G_HOOK_IS_UNLINKED(hook) (G_HOOK (hook)->next == NULL && \
|
||||
G_HOOK (hook)->prev == NULL && \
|
||||
G_HOOK (hook)->hook_id == 0 && \
|
||||
G_HOOK (hook)->ref_count == 0)
|
||||
|
||||
|
||||
/* --- prototypes --- */
|
||||
/* callback maintenance functions */
|
||||
void g_hook_list_init (GHookList *hook_list,
|
||||
guint hook_size);
|
||||
void g_hook_list_clear (GHookList *hook_list);
|
||||
GHook* g_hook_alloc (GHookList *hook_list);
|
||||
void g_hook_free (GHookList *hook_list,
|
||||
GHook *hook);
|
||||
GHook * g_hook_ref (GHookList *hook_list,
|
||||
GHook *hook);
|
||||
void g_hook_unref (GHookList *hook_list,
|
||||
GHook *hook);
|
||||
gboolean g_hook_destroy (GHookList *hook_list,
|
||||
gulong hook_id);
|
||||
void g_hook_destroy_link (GHookList *hook_list,
|
||||
GHook *hook);
|
||||
void g_hook_prepend (GHookList *hook_list,
|
||||
GHook *hook);
|
||||
void g_hook_insert_before (GHookList *hook_list,
|
||||
GHook *sibling,
|
||||
GHook *hook);
|
||||
void g_hook_insert_sorted (GHookList *hook_list,
|
||||
GHook *hook,
|
||||
GHookCompareFunc func);
|
||||
GHook* g_hook_get (GHookList *hook_list,
|
||||
gulong hook_id);
|
||||
GHook* g_hook_find (GHookList *hook_list,
|
||||
gboolean need_valids,
|
||||
GHookFindFunc func,
|
||||
gpointer data);
|
||||
GHook* g_hook_find_data (GHookList *hook_list,
|
||||
gboolean need_valids,
|
||||
gpointer data);
|
||||
GHook* g_hook_find_func (GHookList *hook_list,
|
||||
gboolean need_valids,
|
||||
gpointer func);
|
||||
GHook* g_hook_find_func_data (GHookList *hook_list,
|
||||
gboolean need_valids,
|
||||
gpointer func,
|
||||
gpointer data);
|
||||
/* return the first valid hook, and increment its reference count */
|
||||
GHook* g_hook_first_valid (GHookList *hook_list,
|
||||
gboolean may_be_in_call);
|
||||
/* return the next valid hook with incremented reference count, and
|
||||
* decrement the reference count of the original hook
|
||||
*/
|
||||
GHook* g_hook_next_valid (GHookList *hook_list,
|
||||
GHook *hook,
|
||||
gboolean may_be_in_call);
|
||||
/* GHookCompareFunc implementation to insert hooks sorted by their id */
|
||||
gint g_hook_compare_ids (GHook *new_hook,
|
||||
GHook *sibling);
|
||||
/* convenience macros */
|
||||
#define g_hook_append( hook_list, hook ) \
|
||||
g_hook_insert_before ((hook_list), NULL, (hook))
|
||||
/* invoke all valid hooks with the (*GHookFunc) signature.
|
||||
*/
|
||||
void g_hook_list_invoke (GHookList *hook_list,
|
||||
gboolean may_recurse);
|
||||
/* invoke all valid hooks with the (*GHookCheckFunc) signature,
|
||||
* and destroy the hook if FALSE is returned.
|
||||
*/
|
||||
void g_hook_list_invoke_check (GHookList *hook_list,
|
||||
gboolean may_recurse);
|
||||
/* invoke a marshaller on all valid hooks.
|
||||
*/
|
||||
void g_hook_list_marshal (GHookList *hook_list,
|
||||
gboolean may_recurse,
|
||||
GHookMarshaller marshaller,
|
||||
gpointer marshal_data);
|
||||
void g_hook_list_marshal_check (GHookList *hook_list,
|
||||
gboolean may_recurse,
|
||||
GHookCheckMarshaller marshaller,
|
||||
gpointer marshal_data);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_HOOK_H__ */
|
|
@ -0,0 +1,38 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997, 2002 Peter Mattis, Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __G_I18N_LIB_H__
|
||||
#define __G_I18N_LIB_H__
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include <libintl.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef GETTEXT_PACKAGE
|
||||
#error You must define GETTEXT_PACKAGE before including gi18n-lib.h. Did you forget to include config.h?
|
||||
#endif
|
||||
|
||||
#define _(String) ((char *) g_dgettext (GETTEXT_PACKAGE, String))
|
||||
#define Q_(String) g_dpgettext (GETTEXT_PACKAGE, String, 0)
|
||||
#define N_(String) (String)
|
||||
#define C_(Context,String) g_dpgettext (GETTEXT_PACKAGE, Context "\004" String, strlen (Context) + 1)
|
||||
#define NC_(Context, String) (String)
|
||||
|
||||
#endif /* __G_I18N_LIB_H__ */
|
|
@ -0,0 +1,34 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997, 2002 Peter Mattis, Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __G_I18N_H__
|
||||
#define __G_I18N_H__
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include <libintl.h>
|
||||
#include <string.h>
|
||||
|
||||
#define _(String) gettext (String)
|
||||
#define Q_(String) g_dpgettext (NULL, String, 0)
|
||||
#define N_(String) (String)
|
||||
#define C_(Context,String) g_dpgettext (NULL, Context "\004" String, strlen (Context) + 1)
|
||||
#define NC_(Context, String) (String)
|
||||
|
||||
#endif /* __G_I18N_H__ */
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,366 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
|
||||
#error "Only <glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __G_IOCHANNEL_H__
|
||||
#define __G_IOCHANNEL_H__
|
||||
|
||||
#include <glib/gconvert.h>
|
||||
#include <glib/gmain.h>
|
||||
#include <glib/gstring.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/* GIOChannel
|
||||
*/
|
||||
|
||||
typedef struct _GIOChannel GIOChannel;
|
||||
typedef struct _GIOFuncs GIOFuncs;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
G_IO_ERROR_NONE,
|
||||
G_IO_ERROR_AGAIN,
|
||||
G_IO_ERROR_INVAL,
|
||||
G_IO_ERROR_UNKNOWN
|
||||
} GIOError;
|
||||
|
||||
#define G_IO_CHANNEL_ERROR g_io_channel_error_quark()
|
||||
|
||||
typedef enum
|
||||
{
|
||||
/* Derived from errno */
|
||||
G_IO_CHANNEL_ERROR_FBIG,
|
||||
G_IO_CHANNEL_ERROR_INVAL,
|
||||
G_IO_CHANNEL_ERROR_IO,
|
||||
G_IO_CHANNEL_ERROR_ISDIR,
|
||||
G_IO_CHANNEL_ERROR_NOSPC,
|
||||
G_IO_CHANNEL_ERROR_NXIO,
|
||||
G_IO_CHANNEL_ERROR_OVERFLOW,
|
||||
G_IO_CHANNEL_ERROR_PIPE,
|
||||
/* Other */
|
||||
G_IO_CHANNEL_ERROR_FAILED
|
||||
} GIOChannelError;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
G_IO_STATUS_ERROR,
|
||||
G_IO_STATUS_NORMAL,
|
||||
G_IO_STATUS_EOF,
|
||||
G_IO_STATUS_AGAIN
|
||||
} GIOStatus;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
G_SEEK_CUR,
|
||||
G_SEEK_SET,
|
||||
G_SEEK_END
|
||||
} GSeekType;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
G_IO_IN GLIB_SYSDEF_POLLIN,
|
||||
G_IO_OUT GLIB_SYSDEF_POLLOUT,
|
||||
G_IO_PRI GLIB_SYSDEF_POLLPRI,
|
||||
G_IO_ERR GLIB_SYSDEF_POLLERR,
|
||||
G_IO_HUP GLIB_SYSDEF_POLLHUP,
|
||||
G_IO_NVAL GLIB_SYSDEF_POLLNVAL
|
||||
} GIOCondition;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
G_IO_FLAG_APPEND = 1 << 0,
|
||||
G_IO_FLAG_NONBLOCK = 1 << 1,
|
||||
G_IO_FLAG_IS_READABLE = 1 << 2, /* Read only flag */
|
||||
G_IO_FLAG_IS_WRITEABLE = 1 << 3, /* Read only flag */
|
||||
G_IO_FLAG_IS_SEEKABLE = 1 << 4, /* Read only flag */
|
||||
G_IO_FLAG_MASK = (1 << 5) - 1,
|
||||
G_IO_FLAG_GET_MASK = G_IO_FLAG_MASK,
|
||||
G_IO_FLAG_SET_MASK = G_IO_FLAG_APPEND | G_IO_FLAG_NONBLOCK
|
||||
} GIOFlags;
|
||||
|
||||
struct _GIOChannel
|
||||
{
|
||||
/*< private >*/
|
||||
gint ref_count;
|
||||
GIOFuncs *funcs;
|
||||
|
||||
gchar *encoding;
|
||||
GIConv read_cd;
|
||||
GIConv write_cd;
|
||||
gchar *line_term; /* String which indicates the end of a line of text */
|
||||
guint line_term_len; /* So we can have null in the line term */
|
||||
|
||||
gsize buf_size;
|
||||
GString *read_buf; /* Raw data from the channel */
|
||||
GString *encoded_read_buf; /* Channel data converted to UTF-8 */
|
||||
GString *write_buf; /* Data ready to be written to the file */
|
||||
gchar partial_write_buf[6]; /* UTF-8 partial characters, null terminated */
|
||||
|
||||
/* Group the flags together, immediately after partial_write_buf, to save memory */
|
||||
|
||||
guint use_buffer : 1; /* The encoding uses the buffers */
|
||||
guint do_encode : 1; /* The encoding uses the GIConv coverters */
|
||||
guint close_on_unref : 1; /* Close the channel on final unref */
|
||||
guint is_readable : 1; /* Cached GIOFlag */
|
||||
guint is_writeable : 1; /* ditto */
|
||||
guint is_seekable : 1; /* ditto */
|
||||
|
||||
gpointer reserved1;
|
||||
gpointer reserved2;
|
||||
};
|
||||
|
||||
typedef gboolean (*GIOFunc) (GIOChannel *source,
|
||||
GIOCondition condition,
|
||||
gpointer data);
|
||||
struct _GIOFuncs
|
||||
{
|
||||
GIOStatus (*io_read) (GIOChannel *channel,
|
||||
gchar *buf,
|
||||
gsize count,
|
||||
gsize *bytes_read,
|
||||
GError **err);
|
||||
GIOStatus (*io_write) (GIOChannel *channel,
|
||||
const gchar *buf,
|
||||
gsize count,
|
||||
gsize *bytes_written,
|
||||
GError **err);
|
||||
GIOStatus (*io_seek) (GIOChannel *channel,
|
||||
gint64 offset,
|
||||
GSeekType type,
|
||||
GError **err);
|
||||
GIOStatus (*io_close) (GIOChannel *channel,
|
||||
GError **err);
|
||||
GSource* (*io_create_watch) (GIOChannel *channel,
|
||||
GIOCondition condition);
|
||||
void (*io_free) (GIOChannel *channel);
|
||||
GIOStatus (*io_set_flags) (GIOChannel *channel,
|
||||
GIOFlags flags,
|
||||
GError **err);
|
||||
GIOFlags (*io_get_flags) (GIOChannel *channel);
|
||||
};
|
||||
|
||||
void g_io_channel_init (GIOChannel *channel);
|
||||
GIOChannel *g_io_channel_ref (GIOChannel *channel);
|
||||
void g_io_channel_unref (GIOChannel *channel);
|
||||
|
||||
#ifndef G_DISABLE_DEPRECATED
|
||||
GIOError g_io_channel_read (GIOChannel *channel,
|
||||
gchar *buf,
|
||||
gsize count,
|
||||
gsize *bytes_read);
|
||||
GIOError g_io_channel_write (GIOChannel *channel,
|
||||
const gchar *buf,
|
||||
gsize count,
|
||||
gsize *bytes_written);
|
||||
GIOError g_io_channel_seek (GIOChannel *channel,
|
||||
gint64 offset,
|
||||
GSeekType type);
|
||||
void g_io_channel_close (GIOChannel *channel);
|
||||
#endif /* G_DISABLE_DEPRECATED */
|
||||
|
||||
GIOStatus g_io_channel_shutdown (GIOChannel *channel,
|
||||
gboolean flush,
|
||||
GError **err);
|
||||
guint g_io_add_watch_full (GIOChannel *channel,
|
||||
gint priority,
|
||||
GIOCondition condition,
|
||||
GIOFunc func,
|
||||
gpointer user_data,
|
||||
GDestroyNotify notify);
|
||||
GSource * g_io_create_watch (GIOChannel *channel,
|
||||
GIOCondition condition);
|
||||
guint g_io_add_watch (GIOChannel *channel,
|
||||
GIOCondition condition,
|
||||
GIOFunc func,
|
||||
gpointer user_data);
|
||||
|
||||
/* character encoding conversion involved functions.
|
||||
*/
|
||||
|
||||
void g_io_channel_set_buffer_size (GIOChannel *channel,
|
||||
gsize size);
|
||||
gsize g_io_channel_get_buffer_size (GIOChannel *channel);
|
||||
GIOCondition g_io_channel_get_buffer_condition (GIOChannel *channel);
|
||||
GIOStatus g_io_channel_set_flags (GIOChannel *channel,
|
||||
GIOFlags flags,
|
||||
GError **error);
|
||||
GIOFlags g_io_channel_get_flags (GIOChannel *channel);
|
||||
void g_io_channel_set_line_term (GIOChannel *channel,
|
||||
const gchar *line_term,
|
||||
gint length);
|
||||
G_CONST_RETURN gchar* g_io_channel_get_line_term (GIOChannel *channel,
|
||||
gint *length);
|
||||
void g_io_channel_set_buffered (GIOChannel *channel,
|
||||
gboolean buffered);
|
||||
gboolean g_io_channel_get_buffered (GIOChannel *channel);
|
||||
GIOStatus g_io_channel_set_encoding (GIOChannel *channel,
|
||||
const gchar *encoding,
|
||||
GError **error);
|
||||
G_CONST_RETURN gchar* g_io_channel_get_encoding (GIOChannel *channel);
|
||||
void g_io_channel_set_close_on_unref (GIOChannel *channel,
|
||||
gboolean do_close);
|
||||
gboolean g_io_channel_get_close_on_unref (GIOChannel *channel);
|
||||
|
||||
|
||||
GIOStatus g_io_channel_flush (GIOChannel *channel,
|
||||
GError **error);
|
||||
GIOStatus g_io_channel_read_line (GIOChannel *channel,
|
||||
gchar **str_return,
|
||||
gsize *length,
|
||||
gsize *terminator_pos,
|
||||
GError **error);
|
||||
GIOStatus g_io_channel_read_line_string (GIOChannel *channel,
|
||||
GString *buffer,
|
||||
gsize *terminator_pos,
|
||||
GError **error);
|
||||
GIOStatus g_io_channel_read_to_end (GIOChannel *channel,
|
||||
gchar **str_return,
|
||||
gsize *length,
|
||||
GError **error);
|
||||
GIOStatus g_io_channel_read_chars (GIOChannel *channel,
|
||||
gchar *buf,
|
||||
gsize count,
|
||||
gsize *bytes_read,
|
||||
GError **error);
|
||||
GIOStatus g_io_channel_read_unichar (GIOChannel *channel,
|
||||
gunichar *thechar,
|
||||
GError **error);
|
||||
GIOStatus g_io_channel_write_chars (GIOChannel *channel,
|
||||
const gchar *buf,
|
||||
gssize count,
|
||||
gsize *bytes_written,
|
||||
GError **error);
|
||||
GIOStatus g_io_channel_write_unichar (GIOChannel *channel,
|
||||
gunichar thechar,
|
||||
GError **error);
|
||||
GIOStatus g_io_channel_seek_position (GIOChannel *channel,
|
||||
gint64 offset,
|
||||
GSeekType type,
|
||||
GError **error);
|
||||
#ifdef G_OS_WIN32
|
||||
#define g_io_channel_new_file g_io_channel_new_file_utf8
|
||||
#endif
|
||||
|
||||
GIOChannel* g_io_channel_new_file (const gchar *filename,
|
||||
const gchar *mode,
|
||||
GError **error);
|
||||
|
||||
/* Error handling */
|
||||
|
||||
GQuark g_io_channel_error_quark (void);
|
||||
GIOChannelError g_io_channel_error_from_errno (gint en);
|
||||
|
||||
/* On Unix, IO channels created with this function for any file
|
||||
* descriptor or socket.
|
||||
*
|
||||
* On Win32, this can be used either for files opened with the MSVCRT
|
||||
* (the Microsoft run-time C library) _open() or _pipe, including file
|
||||
* descriptors 0, 1 and 2 (corresponding to stdin, stdout and stderr),
|
||||
* or for Winsock SOCKETs. If the parameter is a legal file
|
||||
* descriptor, it is assumed to be such, otherwise it should be a
|
||||
* SOCKET. This relies on SOCKETs and file descriptors not
|
||||
* overlapping. If you want to be certain, call either
|
||||
* g_io_channel_win32_new_fd() or g_io_channel_win32_new_socket()
|
||||
* instead as appropriate.
|
||||
*
|
||||
* The term file descriptor as used in the context of Win32 refers to
|
||||
* the emulated Unix-like file descriptors MSVCRT provides. The native
|
||||
* corresponding concept is file HANDLE. There isn't as of yet a way to
|
||||
* get GIOChannels for Win32 file HANDLEs.
|
||||
*/
|
||||
GIOChannel* g_io_channel_unix_new (int fd);
|
||||
gint g_io_channel_unix_get_fd (GIOChannel *channel);
|
||||
|
||||
|
||||
/* Hook for GClosure / GSource integration. Don't touch */
|
||||
GLIB_VAR GSourceFuncs g_io_watch_funcs;
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
|
||||
/* You can use this "pseudo file descriptor" in a GPollFD to add
|
||||
* polling for Windows messages. GTK applications should not do that.
|
||||
*/
|
||||
|
||||
#define G_WIN32_MSG_HANDLE 19981206
|
||||
|
||||
/* Use this to get a GPollFD from a GIOChannel, so that you can call
|
||||
* g_io_channel_win32_poll(). After calling this you should only use
|
||||
* g_io_channel_read() to read from the GIOChannel, i.e. never read()
|
||||
* from the underlying file descriptor. For SOCKETs, it is possible to call
|
||||
* recv().
|
||||
*/
|
||||
void g_io_channel_win32_make_pollfd (GIOChannel *channel,
|
||||
GIOCondition condition,
|
||||
GPollFD *fd);
|
||||
|
||||
/* This can be used to wait a until at least one of the channels is readable.
|
||||
* On Unix you would do a select() on the file descriptors of the channels.
|
||||
*/
|
||||
gint g_io_channel_win32_poll (GPollFD *fds,
|
||||
gint n_fds,
|
||||
gint timeout_);
|
||||
|
||||
/* Create an IO channel for Windows messages for window handle hwnd. */
|
||||
#if GLIB_SIZEOF_VOID_P == 8
|
||||
/* We use gsize here so that it is still an integer type and not a
|
||||
* pointer, like the guint in the traditional prototype. We can't use
|
||||
* intptr_t as that is not portable enough.
|
||||
*/
|
||||
GIOChannel *g_io_channel_win32_new_messages (gsize hwnd);
|
||||
#else
|
||||
GIOChannel *g_io_channel_win32_new_messages (guint hwnd);
|
||||
#endif
|
||||
|
||||
/* Create an IO channel for C runtime (emulated Unix-like) file
|
||||
* descriptors. After calling g_io_add_watch() on a IO channel
|
||||
* returned by this function, you shouldn't call read() on the file
|
||||
* descriptor. This is because adding polling for a file descriptor is
|
||||
* implemented on Win32 by starting a thread that sits blocked in a
|
||||
* read() from the file descriptor most of the time. All reads from
|
||||
* the file descriptor should be done by this internal GLib
|
||||
* thread. Your code should call only g_io_channel_read_chars().
|
||||
*/
|
||||
GIOChannel* g_io_channel_win32_new_fd (gint fd);
|
||||
|
||||
/* Get the C runtime file descriptor of a channel. */
|
||||
gint g_io_channel_win32_get_fd (GIOChannel *channel);
|
||||
|
||||
/* Create an IO channel for a winsock socket. The parameter should be
|
||||
* a SOCKET. Contrary to IO channels for file descriptors (on *Win32),
|
||||
* you can use normal recv() or recvfrom() on sockets even if GLib
|
||||
* is polling them.
|
||||
*/
|
||||
GIOChannel *g_io_channel_win32_new_socket (gint socket);
|
||||
|
||||
#endif
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_IOCHANNEL_H__ */
|
|
@ -0,0 +1,609 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* giounix.c: IO Channels using unix file descriptors
|
||||
* Copyright 1998 Owen Taylor
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
/*
|
||||
* MT safe
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#define _POSIX_SOURCE /* for SSIZE_MAX */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "glib.h"
|
||||
#include "galias.h"
|
||||
|
||||
/*
|
||||
* Unix IO Channels
|
||||
*/
|
||||
|
||||
typedef struct _GIOUnixChannel GIOUnixChannel;
|
||||
typedef struct _GIOUnixWatch GIOUnixWatch;
|
||||
|
||||
struct _GIOUnixChannel
|
||||
{
|
||||
GIOChannel channel;
|
||||
gint fd;
|
||||
};
|
||||
|
||||
struct _GIOUnixWatch
|
||||
{
|
||||
GSource source;
|
||||
GPollFD pollfd;
|
||||
GIOChannel *channel;
|
||||
GIOCondition condition;
|
||||
};
|
||||
|
||||
|
||||
static GIOStatus g_io_unix_read (GIOChannel *channel,
|
||||
gchar *buf,
|
||||
gsize count,
|
||||
gsize *bytes_read,
|
||||
GError **err);
|
||||
static GIOStatus g_io_unix_write (GIOChannel *channel,
|
||||
const gchar *buf,
|
||||
gsize count,
|
||||
gsize *bytes_written,
|
||||
GError **err);
|
||||
static GIOStatus g_io_unix_seek (GIOChannel *channel,
|
||||
gint64 offset,
|
||||
GSeekType type,
|
||||
GError **err);
|
||||
static GIOStatus g_io_unix_close (GIOChannel *channel,
|
||||
GError **err);
|
||||
static void g_io_unix_free (GIOChannel *channel);
|
||||
static GSource* g_io_unix_create_watch (GIOChannel *channel,
|
||||
GIOCondition condition);
|
||||
static GIOStatus g_io_unix_set_flags (GIOChannel *channel,
|
||||
GIOFlags flags,
|
||||
GError **err);
|
||||
static GIOFlags g_io_unix_get_flags (GIOChannel *channel);
|
||||
|
||||
static gboolean g_io_unix_prepare (GSource *source,
|
||||
gint *timeout);
|
||||
static gboolean g_io_unix_check (GSource *source);
|
||||
static gboolean g_io_unix_dispatch (GSource *source,
|
||||
GSourceFunc callback,
|
||||
gpointer user_data);
|
||||
static void g_io_unix_finalize (GSource *source);
|
||||
|
||||
GSourceFuncs g_io_watch_funcs = {
|
||||
g_io_unix_prepare,
|
||||
g_io_unix_check,
|
||||
g_io_unix_dispatch,
|
||||
g_io_unix_finalize
|
||||
};
|
||||
|
||||
static GIOFuncs unix_channel_funcs = {
|
||||
g_io_unix_read,
|
||||
g_io_unix_write,
|
||||
g_io_unix_seek,
|
||||
g_io_unix_close,
|
||||
g_io_unix_create_watch,
|
||||
g_io_unix_free,
|
||||
g_io_unix_set_flags,
|
||||
g_io_unix_get_flags,
|
||||
};
|
||||
|
||||
static gboolean
|
||||
g_io_unix_prepare (GSource *source,
|
||||
gint *timeout)
|
||||
{
|
||||
GIOUnixWatch *watch = (GIOUnixWatch *)source;
|
||||
GIOCondition buffer_condition = g_io_channel_get_buffer_condition (watch->channel);
|
||||
|
||||
*timeout = -1;
|
||||
|
||||
/* Only return TRUE here if _all_ bits in watch->condition will be set
|
||||
*/
|
||||
return ((watch->condition & buffer_condition) == watch->condition);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
g_io_unix_check (GSource *source)
|
||||
{
|
||||
GIOUnixWatch *watch = (GIOUnixWatch *)source;
|
||||
GIOCondition buffer_condition = g_io_channel_get_buffer_condition (watch->channel);
|
||||
GIOCondition poll_condition = watch->pollfd.revents;
|
||||
|
||||
return ((poll_condition | buffer_condition) & watch->condition);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
g_io_unix_dispatch (GSource *source,
|
||||
GSourceFunc callback,
|
||||
gpointer user_data)
|
||||
|
||||
{
|
||||
GIOFunc func = (GIOFunc)callback;
|
||||
GIOUnixWatch *watch = (GIOUnixWatch *)source;
|
||||
GIOCondition buffer_condition = g_io_channel_get_buffer_condition (watch->channel);
|
||||
|
||||
if (!func)
|
||||
{
|
||||
g_warning ("IO watch dispatched without callback\n"
|
||||
"You must call g_source_connect().");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return (*func) (watch->channel,
|
||||
(watch->pollfd.revents | buffer_condition) & watch->condition,
|
||||
user_data);
|
||||
}
|
||||
|
||||
static void
|
||||
g_io_unix_finalize (GSource *source)
|
||||
{
|
||||
GIOUnixWatch *watch = (GIOUnixWatch *)source;
|
||||
|
||||
g_io_channel_unref (watch->channel);
|
||||
}
|
||||
|
||||
static GIOStatus
|
||||
g_io_unix_read (GIOChannel *channel,
|
||||
gchar *buf,
|
||||
gsize count,
|
||||
gsize *bytes_read,
|
||||
GError **err)
|
||||
{
|
||||
GIOUnixChannel *unix_channel = (GIOUnixChannel *)channel;
|
||||
gssize result;
|
||||
|
||||
if (count > SSIZE_MAX) /* At least according to the Debian manpage for read */
|
||||
count = SSIZE_MAX;
|
||||
|
||||
retry:
|
||||
result = read (unix_channel->fd, buf, count);
|
||||
|
||||
if (result < 0)
|
||||
{
|
||||
int errsv = errno;
|
||||
*bytes_read = 0;
|
||||
|
||||
switch (errsv)
|
||||
{
|
||||
#ifdef EINTR
|
||||
case EINTR:
|
||||
goto retry;
|
||||
#endif
|
||||
#ifdef EAGAIN
|
||||
case EAGAIN:
|
||||
return G_IO_STATUS_AGAIN;
|
||||
#endif
|
||||
default:
|
||||
g_set_error_literal (err, G_IO_CHANNEL_ERROR,
|
||||
g_io_channel_error_from_errno (errsv),
|
||||
g_strerror (errsv));
|
||||
return G_IO_STATUS_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
*bytes_read = result;
|
||||
|
||||
return (result > 0) ? G_IO_STATUS_NORMAL : G_IO_STATUS_EOF;
|
||||
}
|
||||
|
||||
static GIOStatus
|
||||
g_io_unix_write (GIOChannel *channel,
|
||||
const gchar *buf,
|
||||
gsize count,
|
||||
gsize *bytes_written,
|
||||
GError **err)
|
||||
{
|
||||
GIOUnixChannel *unix_channel = (GIOUnixChannel *)channel;
|
||||
gssize result;
|
||||
|
||||
retry:
|
||||
result = write (unix_channel->fd, buf, count);
|
||||
|
||||
if (result < 0)
|
||||
{
|
||||
int errsv = errno;
|
||||
*bytes_written = 0;
|
||||
|
||||
switch (errsv)
|
||||
{
|
||||
#ifdef EINTR
|
||||
case EINTR:
|
||||
goto retry;
|
||||
#endif
|
||||
#ifdef EAGAIN
|
||||
case EAGAIN:
|
||||
return G_IO_STATUS_AGAIN;
|
||||
#endif
|
||||
default:
|
||||
g_set_error_literal (err, G_IO_CHANNEL_ERROR,
|
||||
g_io_channel_error_from_errno (errsv),
|
||||
g_strerror (errsv));
|
||||
return G_IO_STATUS_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
*bytes_written = result;
|
||||
|
||||
return G_IO_STATUS_NORMAL;
|
||||
}
|
||||
|
||||
static GIOStatus
|
||||
g_io_unix_seek (GIOChannel *channel,
|
||||
gint64 offset,
|
||||
GSeekType type,
|
||||
GError **err)
|
||||
{
|
||||
GIOUnixChannel *unix_channel = (GIOUnixChannel *)channel;
|
||||
int whence;
|
||||
off_t tmp_offset;
|
||||
off_t result;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case G_SEEK_SET:
|
||||
whence = SEEK_SET;
|
||||
break;
|
||||
case G_SEEK_CUR:
|
||||
whence = SEEK_CUR;
|
||||
break;
|
||||
case G_SEEK_END:
|
||||
whence = SEEK_END;
|
||||
break;
|
||||
default:
|
||||
whence = -1; /* Shut the compiler up */
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
||||
tmp_offset = offset;
|
||||
if (tmp_offset != offset)
|
||||
{
|
||||
g_set_error_literal (err, G_IO_CHANNEL_ERROR,
|
||||
g_io_channel_error_from_errno (EINVAL),
|
||||
g_strerror (EINVAL));
|
||||
return G_IO_STATUS_ERROR;
|
||||
}
|
||||
|
||||
result = lseek (unix_channel->fd, tmp_offset, whence);
|
||||
|
||||
if (result < 0)
|
||||
{
|
||||
int errsv = errno;
|
||||
g_set_error_literal (err, G_IO_CHANNEL_ERROR,
|
||||
g_io_channel_error_from_errno (errsv),
|
||||
g_strerror (errsv));
|
||||
return G_IO_STATUS_ERROR;
|
||||
}
|
||||
|
||||
return G_IO_STATUS_NORMAL;
|
||||
}
|
||||
|
||||
|
||||
static GIOStatus
|
||||
g_io_unix_close (GIOChannel *channel,
|
||||
GError **err)
|
||||
{
|
||||
GIOUnixChannel *unix_channel = (GIOUnixChannel *)channel;
|
||||
|
||||
if (close (unix_channel->fd) < 0)
|
||||
{
|
||||
int errsv = errno;
|
||||
g_set_error_literal (err, G_IO_CHANNEL_ERROR,
|
||||
g_io_channel_error_from_errno (errsv),
|
||||
g_strerror (errsv));
|
||||
return G_IO_STATUS_ERROR;
|
||||
}
|
||||
|
||||
return G_IO_STATUS_NORMAL;
|
||||
}
|
||||
|
||||
static void
|
||||
g_io_unix_free (GIOChannel *channel)
|
||||
{
|
||||
GIOUnixChannel *unix_channel = (GIOUnixChannel *)channel;
|
||||
|
||||
g_free (unix_channel);
|
||||
}
|
||||
|
||||
static GSource *
|
||||
g_io_unix_create_watch (GIOChannel *channel,
|
||||
GIOCondition condition)
|
||||
{
|
||||
GIOUnixChannel *unix_channel = (GIOUnixChannel *)channel;
|
||||
GSource *source;
|
||||
GIOUnixWatch *watch;
|
||||
|
||||
|
||||
source = g_source_new (&g_io_watch_funcs, sizeof (GIOUnixWatch));
|
||||
watch = (GIOUnixWatch *)source;
|
||||
|
||||
watch->channel = channel;
|
||||
g_io_channel_ref (channel);
|
||||
|
||||
watch->condition = condition;
|
||||
|
||||
watch->pollfd.fd = unix_channel->fd;
|
||||
watch->pollfd.events = condition;
|
||||
|
||||
g_source_add_poll (source, &watch->pollfd);
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
static GIOStatus
|
||||
g_io_unix_set_flags (GIOChannel *channel,
|
||||
GIOFlags flags,
|
||||
GError **err)
|
||||
{
|
||||
glong fcntl_flags;
|
||||
GIOUnixChannel *unix_channel = (GIOUnixChannel *) channel;
|
||||
|
||||
fcntl_flags = 0;
|
||||
|
||||
if (flags & G_IO_FLAG_APPEND)
|
||||
fcntl_flags |= O_APPEND;
|
||||
if (flags & G_IO_FLAG_NONBLOCK)
|
||||
#ifdef O_NONBLOCK
|
||||
fcntl_flags |= O_NONBLOCK;
|
||||
#else
|
||||
fcntl_flags |= O_NDELAY;
|
||||
#endif
|
||||
|
||||
if (fcntl (unix_channel->fd, F_SETFL, fcntl_flags) == -1)
|
||||
{
|
||||
int errsv = errno;
|
||||
g_set_error_literal (err, G_IO_CHANNEL_ERROR,
|
||||
g_io_channel_error_from_errno (errsv),
|
||||
g_strerror (errsv));
|
||||
return G_IO_STATUS_ERROR;
|
||||
}
|
||||
|
||||
return G_IO_STATUS_NORMAL;
|
||||
}
|
||||
|
||||
static GIOFlags
|
||||
g_io_unix_get_flags (GIOChannel *channel)
|
||||
{
|
||||
GIOFlags flags = 0;
|
||||
glong fcntl_flags;
|
||||
GIOUnixChannel *unix_channel = (GIOUnixChannel *) channel;
|
||||
|
||||
fcntl_flags = fcntl (unix_channel->fd, F_GETFL);
|
||||
|
||||
if (fcntl_flags == -1)
|
||||
{
|
||||
int err = errno;
|
||||
g_warning (G_STRLOC "Error while getting flags for FD: %s (%d)\n",
|
||||
g_strerror (err), err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (fcntl_flags & O_APPEND)
|
||||
flags |= G_IO_FLAG_APPEND;
|
||||
#ifdef O_NONBLOCK
|
||||
if (fcntl_flags & O_NONBLOCK)
|
||||
#else
|
||||
if (fcntl_flags & O_NDELAY)
|
||||
#endif
|
||||
flags |= G_IO_FLAG_NONBLOCK;
|
||||
|
||||
switch (fcntl_flags & (O_RDONLY | O_WRONLY | O_RDWR))
|
||||
{
|
||||
case O_RDONLY:
|
||||
channel->is_readable = TRUE;
|
||||
channel->is_writeable = FALSE;
|
||||
break;
|
||||
case O_WRONLY:
|
||||
channel->is_readable = FALSE;
|
||||
channel->is_writeable = TRUE;
|
||||
break;
|
||||
case O_RDWR:
|
||||
channel->is_readable = TRUE;
|
||||
channel->is_writeable = TRUE;
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
GIOChannel *
|
||||
g_io_channel_new_file (const gchar *filename,
|
||||
const gchar *mode,
|
||||
GError **error)
|
||||
{
|
||||
int fid, flags;
|
||||
mode_t create_mode;
|
||||
GIOChannel *channel;
|
||||
enum { /* Cheesy hack */
|
||||
MODE_R = 1 << 0,
|
||||
MODE_W = 1 << 1,
|
||||
MODE_A = 1 << 2,
|
||||
MODE_PLUS = 1 << 3
|
||||
} mode_num;
|
||||
struct stat buffer;
|
||||
|
||||
g_return_val_if_fail (filename != NULL, NULL);
|
||||
g_return_val_if_fail (mode != NULL, NULL);
|
||||
g_return_val_if_fail ((error == NULL) || (*error == NULL), NULL);
|
||||
|
||||
switch (mode[0])
|
||||
{
|
||||
case 'r':
|
||||
mode_num = MODE_R;
|
||||
break;
|
||||
case 'w':
|
||||
mode_num = MODE_W;
|
||||
break;
|
||||
case 'a':
|
||||
mode_num = MODE_A;
|
||||
break;
|
||||
default:
|
||||
g_warning ("Invalid GIOFileMode %s.\n", mode);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch (mode[1])
|
||||
{
|
||||
case '\0':
|
||||
break;
|
||||
case '+':
|
||||
if (mode[2] == '\0')
|
||||
{
|
||||
mode_num |= MODE_PLUS;
|
||||
break;
|
||||
}
|
||||
/* Fall through */
|
||||
default:
|
||||
g_warning ("Invalid GIOFileMode %s.\n", mode);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch (mode_num)
|
||||
{
|
||||
case MODE_R:
|
||||
flags = O_RDONLY;
|
||||
break;
|
||||
case MODE_W:
|
||||
flags = O_WRONLY | O_TRUNC | O_CREAT;
|
||||
break;
|
||||
case MODE_A:
|
||||
flags = O_WRONLY | O_APPEND | O_CREAT;
|
||||
break;
|
||||
case MODE_R | MODE_PLUS:
|
||||
flags = O_RDWR;
|
||||
break;
|
||||
case MODE_W | MODE_PLUS:
|
||||
flags = O_RDWR | O_TRUNC | O_CREAT;
|
||||
break;
|
||||
case MODE_A | MODE_PLUS:
|
||||
flags = O_RDWR | O_APPEND | O_CREAT;
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
flags = 0;
|
||||
}
|
||||
|
||||
create_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
|
||||
fid = open (filename, flags, create_mode);
|
||||
if (fid == -1)
|
||||
{
|
||||
int err = errno;
|
||||
g_set_error_literal (error, G_FILE_ERROR,
|
||||
g_file_error_from_errno (err),
|
||||
g_strerror (err));
|
||||
return (GIOChannel *)NULL;
|
||||
}
|
||||
|
||||
if (fstat (fid, &buffer) == -1) /* In case someone opens a FIFO */
|
||||
{
|
||||
int err = errno;
|
||||
close (fid);
|
||||
g_set_error_literal (error, G_FILE_ERROR,
|
||||
g_file_error_from_errno (err),
|
||||
g_strerror (err));
|
||||
return (GIOChannel *)NULL;
|
||||
}
|
||||
|
||||
channel = (GIOChannel *) g_new (GIOUnixChannel, 1);
|
||||
|
||||
channel->is_seekable = S_ISREG (buffer.st_mode) || S_ISCHR (buffer.st_mode)
|
||||
|| S_ISBLK (buffer.st_mode);
|
||||
|
||||
switch (mode_num)
|
||||
{
|
||||
case MODE_R:
|
||||
channel->is_readable = TRUE;
|
||||
channel->is_writeable = FALSE;
|
||||
break;
|
||||
case MODE_W:
|
||||
case MODE_A:
|
||||
channel->is_readable = FALSE;
|
||||
channel->is_writeable = TRUE;
|
||||
break;
|
||||
case MODE_R | MODE_PLUS:
|
||||
case MODE_W | MODE_PLUS:
|
||||
case MODE_A | MODE_PLUS:
|
||||
channel->is_readable = TRUE;
|
||||
channel->is_writeable = TRUE;
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
||||
g_io_channel_init (channel);
|
||||
channel->close_on_unref = TRUE; /* must be after g_io_channel_init () */
|
||||
channel->funcs = &unix_channel_funcs;
|
||||
|
||||
((GIOUnixChannel *) channel)->fd = fid;
|
||||
return channel;
|
||||
}
|
||||
|
||||
GIOChannel *
|
||||
g_io_channel_unix_new (gint fd)
|
||||
{
|
||||
struct stat buffer;
|
||||
GIOUnixChannel *unix_channel = g_new (GIOUnixChannel, 1);
|
||||
GIOChannel *channel = (GIOChannel *)unix_channel;
|
||||
|
||||
g_io_channel_init (channel);
|
||||
channel->funcs = &unix_channel_funcs;
|
||||
|
||||
unix_channel->fd = fd;
|
||||
|
||||
/* I'm not sure if fstat on a non-file (e.g., socket) works
|
||||
* it should be safe to say if it fails, the fd isn't seekable.
|
||||
*/
|
||||
/* Newer UNIX versions support S_ISSOCK(), fstat() will probably
|
||||
* succeed in most cases.
|
||||
*/
|
||||
if (fstat (unix_channel->fd, &buffer) == 0)
|
||||
channel->is_seekable = S_ISREG (buffer.st_mode) || S_ISCHR (buffer.st_mode)
|
||||
|| S_ISBLK (buffer.st_mode);
|
||||
else /* Assume not seekable */
|
||||
channel->is_seekable = FALSE;
|
||||
|
||||
g_io_unix_get_flags (channel); /* Sets is_readable, is_writeable */
|
||||
|
||||
return channel;
|
||||
}
|
||||
|
||||
gint
|
||||
g_io_channel_unix_get_fd (GIOChannel *channel)
|
||||
{
|
||||
GIOUnixChannel *unix_channel = (GIOUnixChannel *)channel;
|
||||
return unix_channel->fd;
|
||||
}
|
||||
|
||||
#define __G_IO_UNIX_C__
|
||||
#include "galiasdef.c"
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,250 @@
|
|||
/* gkeyfile.h - desktop entry file parser
|
||||
*
|
||||
* Copyright 2004 Red Hat, Inc.
|
||||
*
|
||||
* Ray Strode <halfline@hawaii.rr.com>
|
||||
*
|
||||
* GLib is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* GLib 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with GLib; see the file COPYING.LIB. If not,
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
|
||||
#error "Only <glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __G_KEY_FILE_H__
|
||||
#define __G_KEY_FILE_H__
|
||||
|
||||
#include <glib/gerror.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef enum
|
||||
{
|
||||
G_KEY_FILE_ERROR_UNKNOWN_ENCODING,
|
||||
G_KEY_FILE_ERROR_PARSE,
|
||||
G_KEY_FILE_ERROR_NOT_FOUND,
|
||||
G_KEY_FILE_ERROR_KEY_NOT_FOUND,
|
||||
G_KEY_FILE_ERROR_GROUP_NOT_FOUND,
|
||||
G_KEY_FILE_ERROR_INVALID_VALUE
|
||||
} GKeyFileError;
|
||||
|
||||
#define G_KEY_FILE_ERROR g_key_file_error_quark()
|
||||
|
||||
GQuark g_key_file_error_quark (void);
|
||||
|
||||
typedef struct _GKeyFile GKeyFile;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
G_KEY_FILE_NONE = 0,
|
||||
G_KEY_FILE_KEEP_COMMENTS = 1 << 0,
|
||||
G_KEY_FILE_KEEP_TRANSLATIONS = 1 << 1
|
||||
} GKeyFileFlags;
|
||||
|
||||
GKeyFile *g_key_file_new (void);
|
||||
void g_key_file_free (GKeyFile *key_file);
|
||||
void g_key_file_set_list_separator (GKeyFile *key_file,
|
||||
gchar separator);
|
||||
gboolean g_key_file_load_from_file (GKeyFile *key_file,
|
||||
const gchar *file,
|
||||
GKeyFileFlags flags,
|
||||
GError **error);
|
||||
gboolean g_key_file_load_from_data (GKeyFile *key_file,
|
||||
const gchar *data,
|
||||
gsize length,
|
||||
GKeyFileFlags flags,
|
||||
GError **error);
|
||||
gboolean g_key_file_load_from_dirs (GKeyFile *key_file,
|
||||
const gchar *file,
|
||||
const gchar **search_dirs,
|
||||
gchar **full_path,
|
||||
GKeyFileFlags flags,
|
||||
GError **error);
|
||||
gboolean g_key_file_load_from_data_dirs (GKeyFile *key_file,
|
||||
const gchar *file,
|
||||
gchar **full_path,
|
||||
GKeyFileFlags flags,
|
||||
GError **error);
|
||||
gchar *g_key_file_to_data (GKeyFile *key_file,
|
||||
gsize *length,
|
||||
GError **error) G_GNUC_MALLOC;
|
||||
gchar *g_key_file_get_start_group (GKeyFile *key_file) G_GNUC_MALLOC;
|
||||
gchar **g_key_file_get_groups (GKeyFile *key_file,
|
||||
gsize *length) G_GNUC_MALLOC;
|
||||
gchar **g_key_file_get_keys (GKeyFile *key_file,
|
||||
const gchar *group_name,
|
||||
gsize *length,
|
||||
GError **error) G_GNUC_MALLOC;
|
||||
gboolean g_key_file_has_group (GKeyFile *key_file,
|
||||
const gchar *group_name);
|
||||
gboolean g_key_file_has_key (GKeyFile *key_file,
|
||||
const gchar *group_name,
|
||||
const gchar *key,
|
||||
GError **error);
|
||||
gchar *g_key_file_get_value (GKeyFile *key_file,
|
||||
const gchar *group_name,
|
||||
const gchar *key,
|
||||
GError **error) G_GNUC_MALLOC;
|
||||
void g_key_file_set_value (GKeyFile *key_file,
|
||||
const gchar *group_name,
|
||||
const gchar *key,
|
||||
const gchar *value);
|
||||
gchar *g_key_file_get_string (GKeyFile *key_file,
|
||||
const gchar *group_name,
|
||||
const gchar *key,
|
||||
GError **error) G_GNUC_MALLOC;
|
||||
void g_key_file_set_string (GKeyFile *key_file,
|
||||
const gchar *group_name,
|
||||
const gchar *key,
|
||||
const gchar *string);
|
||||
gchar *g_key_file_get_locale_string (GKeyFile *key_file,
|
||||
const gchar *group_name,
|
||||
const gchar *key,
|
||||
const gchar *locale,
|
||||
GError **error) G_GNUC_MALLOC;
|
||||
void g_key_file_set_locale_string (GKeyFile *key_file,
|
||||
const gchar *group_name,
|
||||
const gchar *key,
|
||||
const gchar *locale,
|
||||
const gchar *string);
|
||||
gboolean g_key_file_get_boolean (GKeyFile *key_file,
|
||||
const gchar *group_name,
|
||||
const gchar *key,
|
||||
GError **error);
|
||||
void g_key_file_set_boolean (GKeyFile *key_file,
|
||||
const gchar *group_name,
|
||||
const gchar *key,
|
||||
gboolean value);
|
||||
gint g_key_file_get_integer (GKeyFile *key_file,
|
||||
const gchar *group_name,
|
||||
const gchar *key,
|
||||
GError **error);
|
||||
void g_key_file_set_integer (GKeyFile *key_file,
|
||||
const gchar *group_name,
|
||||
const gchar *key,
|
||||
gint value);
|
||||
gdouble g_key_file_get_double (GKeyFile *key_file,
|
||||
const gchar *group_name,
|
||||
const gchar *key,
|
||||
GError **error);
|
||||
void g_key_file_set_double (GKeyFile *key_file,
|
||||
const gchar *group_name,
|
||||
const gchar *key,
|
||||
gdouble value);
|
||||
gchar **g_key_file_get_string_list (GKeyFile *key_file,
|
||||
const gchar *group_name,
|
||||
const gchar *key,
|
||||
gsize *length,
|
||||
GError **error) G_GNUC_MALLOC;
|
||||
void g_key_file_set_string_list (GKeyFile *key_file,
|
||||
const gchar *group_name,
|
||||
const gchar *key,
|
||||
const gchar * const list[],
|
||||
gsize length);
|
||||
gchar **g_key_file_get_locale_string_list (GKeyFile *key_file,
|
||||
const gchar *group_name,
|
||||
const gchar *key,
|
||||
const gchar *locale,
|
||||
gsize *length,
|
||||
GError **error) G_GNUC_MALLOC;
|
||||
void g_key_file_set_locale_string_list (GKeyFile *key_file,
|
||||
const gchar *group_name,
|
||||
const gchar *key,
|
||||
const gchar *locale,
|
||||
const gchar * const list[],
|
||||
gsize length);
|
||||
gboolean *g_key_file_get_boolean_list (GKeyFile *key_file,
|
||||
const gchar *group_name,
|
||||
const gchar *key,
|
||||
gsize *length,
|
||||
GError **error) G_GNUC_MALLOC;
|
||||
void g_key_file_set_boolean_list (GKeyFile *key_file,
|
||||
const gchar *group_name,
|
||||
const gchar *key,
|
||||
gboolean list[],
|
||||
gsize length);
|
||||
gint *g_key_file_get_integer_list (GKeyFile *key_file,
|
||||
const gchar *group_name,
|
||||
const gchar *key,
|
||||
gsize *length,
|
||||
GError **error) G_GNUC_MALLOC;
|
||||
void g_key_file_set_double_list (GKeyFile *key_file,
|
||||
const gchar *group_name,
|
||||
const gchar *key,
|
||||
gdouble list[],
|
||||
gsize length);
|
||||
gdouble *g_key_file_get_double_list (GKeyFile *key_file,
|
||||
const gchar *group_name,
|
||||
const gchar *key,
|
||||
gsize *length,
|
||||
GError **error) G_GNUC_MALLOC;
|
||||
void g_key_file_set_integer_list (GKeyFile *key_file,
|
||||
const gchar *group_name,
|
||||
const gchar *key,
|
||||
gint list[],
|
||||
gsize length);
|
||||
gboolean g_key_file_set_comment (GKeyFile *key_file,
|
||||
const gchar *group_name,
|
||||
const gchar *key,
|
||||
const gchar *comment,
|
||||
GError **error);
|
||||
gchar *g_key_file_get_comment (GKeyFile *key_file,
|
||||
const gchar *group_name,
|
||||
const gchar *key,
|
||||
GError **error) G_GNUC_MALLOC;
|
||||
|
||||
gboolean g_key_file_remove_comment (GKeyFile *key_file,
|
||||
const gchar *group_name,
|
||||
const gchar *key,
|
||||
GError **error);
|
||||
gboolean g_key_file_remove_key (GKeyFile *key_file,
|
||||
const gchar *group_name,
|
||||
const gchar *key,
|
||||
GError **error);
|
||||
gboolean g_key_file_remove_group (GKeyFile *key_file,
|
||||
const gchar *group_name,
|
||||
GError **error);
|
||||
|
||||
/* Defines for handling freedesktop.org Desktop files */
|
||||
#define G_KEY_FILE_DESKTOP_GROUP "Desktop Entry"
|
||||
|
||||
#define G_KEY_FILE_DESKTOP_KEY_TYPE "Type"
|
||||
#define G_KEY_FILE_DESKTOP_KEY_VERSION "Version"
|
||||
#define G_KEY_FILE_DESKTOP_KEY_NAME "Name"
|
||||
#define G_KEY_FILE_DESKTOP_KEY_GENERIC_NAME "GenericName"
|
||||
#define G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY "NoDisplay"
|
||||
#define G_KEY_FILE_DESKTOP_KEY_COMMENT "Comment"
|
||||
#define G_KEY_FILE_DESKTOP_KEY_ICON "Icon"
|
||||
#define G_KEY_FILE_DESKTOP_KEY_HIDDEN "Hidden"
|
||||
#define G_KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN "OnlyShowIn"
|
||||
#define G_KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN "NotShowIn"
|
||||
#define G_KEY_FILE_DESKTOP_KEY_TRY_EXEC "TryExec"
|
||||
#define G_KEY_FILE_DESKTOP_KEY_EXEC "Exec"
|
||||
#define G_KEY_FILE_DESKTOP_KEY_PATH "Path"
|
||||
#define G_KEY_FILE_DESKTOP_KEY_TERMINAL "Terminal"
|
||||
#define G_KEY_FILE_DESKTOP_KEY_MIME_TYPE "MimeType"
|
||||
#define G_KEY_FILE_DESKTOP_KEY_CATEGORIES "Categories"
|
||||
#define G_KEY_FILE_DESKTOP_KEY_STARTUP_NOTIFY "StartupNotify"
|
||||
#define G_KEY_FILE_DESKTOP_KEY_STARTUP_WM_CLASS "StartupWMClass"
|
||||
#define G_KEY_FILE_DESKTOP_KEY_URL "URL"
|
||||
|
||||
#define G_KEY_FILE_DESKTOP_TYPE_APPLICATION "Application"
|
||||
#define G_KEY_FILE_DESKTOP_TYPE_LINK "Link"
|
||||
#define G_KEY_FILE_DESKTOP_TYPE_DIRECTORY "Directory"
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_KEY_FILE_H__ */
|
|
@ -0,0 +1,41 @@
|
|||
/* GObject - GLib Type, Object, Parameter and Signal Library
|
||||
* Copyright (C) 1998, 1999, 2000 Tim Janik and Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General
|
||||
* Public License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#ifndef __GLIB_GOBJECT_H__
|
||||
#define __GLIB_GOBJECT_H__
|
||||
|
||||
#define __GLIB_GOBJECT_H_INSIDE__
|
||||
|
||||
/* topmost include file for GObject header files */
|
||||
#include <gobject/gboxed.h>
|
||||
#include <gobject/genums.h>
|
||||
#include <gobject/gobject.h>
|
||||
#include <gobject/gparam.h>
|
||||
#include <gobject/gparamspecs.h>
|
||||
#include <gobject/gsignal.h>
|
||||
#include <gobject/gsourceclosure.h>
|
||||
#include <gobject/gtype.h>
|
||||
#include <gobject/gtypemodule.h>
|
||||
#include <gobject/gtypeplugin.h>
|
||||
#include <gobject/gvalue.h>
|
||||
#include <gobject/gvaluearray.h>
|
||||
#include <gobject/gvaluetypes.h>
|
||||
|
||||
#undef __GLIB_GOBJECT_H_INSIDE__
|
||||
|
||||
#endif /* __GLIB_GOBJECT_H__ */
|
|
@ -0,0 +1,93 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#ifndef __G_LIB_H__
|
||||
#define __G_LIB_H__
|
||||
|
||||
#define __GLIB_H_INSIDE__
|
||||
|
||||
#include <glib/galloca.h>
|
||||
#include <glib/garray.h>
|
||||
#include <glib/gasyncqueue.h>
|
||||
#include <glib/gatomic.h>
|
||||
#include <glib/gbacktrace.h>
|
||||
#include <glib/gbase64.h>
|
||||
#include <glib/gbookmarkfile.h>
|
||||
#include <glib/gcache.h>
|
||||
#include <glib/gchecksum.h>
|
||||
#include <glib/gcompletion.h>
|
||||
#include <glib/gconvert.h>
|
||||
#include <glib/gdataset.h>
|
||||
#include <glib/gdate.h>
|
||||
#include <glib/gdir.h>
|
||||
#include <glib/gerror.h>
|
||||
#include <glib/gfileutils.h>
|
||||
#include <glib/ghash.h>
|
||||
#include <glib/ghook.h>
|
||||
#include <glib/giochannel.h>
|
||||
#include <glib/gkeyfile.h>
|
||||
#include <glib/glist.h>
|
||||
#include <glib/gmacros.h>
|
||||
#include <glib/gmain.h>
|
||||
#include <glib/gmappedfile.h>
|
||||
#include <glib/gmarkup.h>
|
||||
#include <glib/gmem.h>
|
||||
#include <glib/gmessages.h>
|
||||
#include <glib/gnode.h>
|
||||
#include <glib/goption.h>
|
||||
#include <glib/gpattern.h>
|
||||
#include <glib/gpoll.h>
|
||||
#include <glib/gprimes.h>
|
||||
#include <glib/gqsort.h>
|
||||
#include <glib/gquark.h>
|
||||
#include <glib/gqueue.h>
|
||||
#include <glib/grand.h>
|
||||
#include <glib/grel.h>
|
||||
#include <glib/gregex.h>
|
||||
#include <glib/gscanner.h>
|
||||
#include <glib/gsequence.h>
|
||||
#include <glib/gshell.h>
|
||||
#include <glib/gslice.h>
|
||||
#include <glib/gslist.h>
|
||||
#include <glib/gspawn.h>
|
||||
#include <glib/gstrfuncs.h>
|
||||
#include <glib/gstring.h>
|
||||
#include <glib/gtestutils.h>
|
||||
#include <glib/gthread.h>
|
||||
#include <glib/gthreadpool.h>
|
||||
#include <glib/gtimer.h>
|
||||
#include <glib/gtree.h>
|
||||
#include <glib/gtypes.h>
|
||||
#include <glib/gunicode.h>
|
||||
#include <glib/gurifuncs.h>
|
||||
#include <glib/gutils.h>
|
||||
#ifdef G_PLATFORM_WIN32
|
||||
#include <glib/gwin32.h>
|
||||
#endif
|
||||
|
||||
#undef __GLIB_H_INSIDE__
|
||||
|
||||
#endif /* __G_LIB_H__ */
|
|
@ -0,0 +1,38 @@
|
|||
#ifndef __GLIBINTL_H__
|
||||
#define __GLIBINTL_H__
|
||||
|
||||
#ifndef SIZEOF_CHAR
|
||||
#error "config.h must be included prior to glibintl.h"
|
||||
#endif
|
||||
|
||||
G_CONST_RETURN gchar *glib_gettext (const gchar *str) G_GNUC_FORMAT(1);
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
|
||||
#include <libintl.h>
|
||||
#define _(String) glib_gettext(String)
|
||||
/* Split out this in the code, but keep it in the same domain for now */
|
||||
#define P_(String) glib_gettext(String)
|
||||
|
||||
#ifdef gettext_noop
|
||||
#define N_(String) gettext_noop(String)
|
||||
#else
|
||||
#define N_(String) (String)
|
||||
#endif
|
||||
#else /* NLS is disabled */
|
||||
#define _(String) (String)
|
||||
#define N_(String) (String)
|
||||
#define P_(String) (String)
|
||||
#define textdomain(String) ((String) ? (String) : "messages")
|
||||
#define gettext(String) (String)
|
||||
#define dgettext(Domain,String) (String)
|
||||
#define dcgettext(Domain,String,Type) (String)
|
||||
#define dngettext(Domain,String1,String2,N) ((N) == 1 ? (String1) : (String2))
|
||||
#define bindtextdomain(Domain,Directory) (Domain)
|
||||
#define bind_textdomain_codeset(Domain,Codeset)
|
||||
#endif
|
||||
|
||||
/* not really I18N-related, but also a string marker macro */
|
||||
#define I_(string) g_intern_static_string (string)
|
||||
|
||||
#endif /* __GLIBINTL_H__ */
|
|
@ -0,0 +1,999 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
/*
|
||||
* MT safe
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "glib.h"
|
||||
#include "galias.h"
|
||||
|
||||
|
||||
void g_list_push_allocator (gpointer dummy) { /* present for binary compat only */ }
|
||||
void g_list_pop_allocator (void) { /* present for binary compat only */ }
|
||||
|
||||
#define _g_list_alloc() g_slice_new (GList)
|
||||
#define _g_list_alloc0() g_slice_new0 (GList)
|
||||
#define _g_list_free1(list) g_slice_free (GList, list)
|
||||
|
||||
GList*
|
||||
g_list_alloc (void)
|
||||
{
|
||||
return _g_list_alloc0 ();
|
||||
}
|
||||
|
||||
/**
|
||||
* g_list_free:
|
||||
* @list: a #GList
|
||||
*
|
||||
* Frees all of the memory used by a #GList.
|
||||
* The freed elements are returned to the slice allocator.
|
||||
*
|
||||
* <note><para>
|
||||
* If list elements contain dynamically-allocated memory,
|
||||
* they should be freed first.
|
||||
* </para></note>
|
||||
*/
|
||||
void
|
||||
g_list_free (GList *list)
|
||||
{
|
||||
g_slice_free_chain (GList, list, next);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_list_free_1:
|
||||
* @list: a #GList element
|
||||
*
|
||||
* Frees one #GList element.
|
||||
* It is usually used after g_list_remove_link().
|
||||
*/
|
||||
void
|
||||
g_list_free_1 (GList *list)
|
||||
{
|
||||
_g_list_free1 (list);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_list_append:
|
||||
* @list: a pointer to a #GList
|
||||
* @data: the data for the new element
|
||||
*
|
||||
* Adds a new element on to the end of the list.
|
||||
*
|
||||
* <note><para>
|
||||
* The return value is the new start of the list, which
|
||||
* may have changed, so make sure you store the new value.
|
||||
* </para></note>
|
||||
*
|
||||
* <note><para>
|
||||
* Note that g_list_append() has to traverse the entire list
|
||||
* to find the end, which is inefficient when adding multiple
|
||||
* elements. A common idiom to avoid the inefficiency is to prepend
|
||||
* the elements and reverse the list when all elements have been added.
|
||||
* </para></note>
|
||||
*
|
||||
* |[
|
||||
* /* Notice that these are initialized to the empty list. */
|
||||
* GList *list = NULL, *number_list = NULL;
|
||||
*
|
||||
* /* This is a list of strings. */
|
||||
* list = g_list_append (list, "first");
|
||||
* list = g_list_append (list, "second");
|
||||
*
|
||||
* /* This is a list of integers. */
|
||||
* number_list = g_list_append (number_list, GINT_TO_POINTER (27));
|
||||
* number_list = g_list_append (number_list, GINT_TO_POINTER (14));
|
||||
* ]|
|
||||
*
|
||||
* Returns: the new start of the #GList
|
||||
*/
|
||||
GList*
|
||||
g_list_append (GList *list,
|
||||
gpointer data)
|
||||
{
|
||||
GList *new_list;
|
||||
GList *last;
|
||||
|
||||
new_list = _g_list_alloc ();
|
||||
new_list->data = data;
|
||||
new_list->next = NULL;
|
||||
|
||||
if (list)
|
||||
{
|
||||
last = g_list_last (list);
|
||||
/* g_assert (last != NULL); */
|
||||
last->next = new_list;
|
||||
new_list->prev = last;
|
||||
|
||||
return list;
|
||||
}
|
||||
else
|
||||
{
|
||||
new_list->prev = NULL;
|
||||
return new_list;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* g_list_prepend:
|
||||
* @list: a pointer to a #GList
|
||||
* @data: the data for the new element
|
||||
*
|
||||
* Adds a new element on to the start of the list.
|
||||
*
|
||||
* <note><para>
|
||||
* The return value is the new start of the list, which
|
||||
* may have changed, so make sure you store the new value.
|
||||
* </para></note>
|
||||
*
|
||||
* |[
|
||||
* /* Notice that it is initialized to the empty list. */
|
||||
* GList *list = NULL;
|
||||
* list = g_list_prepend (list, "last");
|
||||
* list = g_list_prepend (list, "first");
|
||||
* ]|
|
||||
*
|
||||
* Returns: the new start of the #GList
|
||||
*/
|
||||
GList*
|
||||
g_list_prepend (GList *list,
|
||||
gpointer data)
|
||||
{
|
||||
GList *new_list;
|
||||
|
||||
new_list = _g_list_alloc ();
|
||||
new_list->data = data;
|
||||
new_list->next = list;
|
||||
|
||||
if (list)
|
||||
{
|
||||
new_list->prev = list->prev;
|
||||
if (list->prev)
|
||||
list->prev->next = new_list;
|
||||
list->prev = new_list;
|
||||
}
|
||||
else
|
||||
new_list->prev = NULL;
|
||||
|
||||
return new_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_list_insert:
|
||||
* @list: a pointer to a #GList
|
||||
* @data: the data for the new element
|
||||
* @position: the position to insert the element. If this is
|
||||
* negative, or is larger than the number of elements in the
|
||||
* list, the new element is added on to the end of the list.
|
||||
*
|
||||
* Inserts a new element into the list at the given position.
|
||||
*
|
||||
* Returns: the new start of the #GList
|
||||
*/
|
||||
GList*
|
||||
g_list_insert (GList *list,
|
||||
gpointer data,
|
||||
gint position)
|
||||
{
|
||||
GList *new_list;
|
||||
GList *tmp_list;
|
||||
|
||||
if (position < 0)
|
||||
return g_list_append (list, data);
|
||||
else if (position == 0)
|
||||
return g_list_prepend (list, data);
|
||||
|
||||
tmp_list = g_list_nth (list, position);
|
||||
if (!tmp_list)
|
||||
return g_list_append (list, data);
|
||||
|
||||
new_list = _g_list_alloc ();
|
||||
new_list->data = data;
|
||||
new_list->prev = tmp_list->prev;
|
||||
if (tmp_list->prev)
|
||||
tmp_list->prev->next = new_list;
|
||||
new_list->next = tmp_list;
|
||||
tmp_list->prev = new_list;
|
||||
|
||||
if (tmp_list == list)
|
||||
return new_list;
|
||||
else
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_list_insert_before:
|
||||
* @list: a pointer to a #GList
|
||||
* @sibling: the list element before which the new element
|
||||
* is inserted or %NULL to insert at the end of the list
|
||||
* @data: the data for the new element
|
||||
*
|
||||
* Inserts a new element into the list before the given position.
|
||||
*
|
||||
* Returns: the new start of the #GList
|
||||
*/
|
||||
GList*
|
||||
g_list_insert_before (GList *list,
|
||||
GList *sibling,
|
||||
gpointer data)
|
||||
{
|
||||
if (!list)
|
||||
{
|
||||
list = g_list_alloc ();
|
||||
list->data = data;
|
||||
g_return_val_if_fail (sibling == NULL, list);
|
||||
return list;
|
||||
}
|
||||
else if (sibling)
|
||||
{
|
||||
GList *node;
|
||||
|
||||
node = _g_list_alloc ();
|
||||
node->data = data;
|
||||
node->prev = sibling->prev;
|
||||
node->next = sibling;
|
||||
sibling->prev = node;
|
||||
if (node->prev)
|
||||
{
|
||||
node->prev->next = node;
|
||||
return list;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_return_val_if_fail (sibling == list, node);
|
||||
return node;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GList *last;
|
||||
|
||||
last = list;
|
||||
while (last->next)
|
||||
last = last->next;
|
||||
|
||||
last->next = _g_list_alloc ();
|
||||
last->next->data = data;
|
||||
last->next->prev = last;
|
||||
last->next->next = NULL;
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* g_list_concat:
|
||||
* @list1: a #GList
|
||||
* @list2: the #GList to add to the end of the first #GList
|
||||
*
|
||||
* Adds the second #GList onto the end of the first #GList.
|
||||
* Note that the elements of the second #GList are not copied.
|
||||
* They are used directly.
|
||||
*
|
||||
* Returns: the start of the new #GList
|
||||
*/
|
||||
GList *
|
||||
g_list_concat (GList *list1, GList *list2)
|
||||
{
|
||||
GList *tmp_list;
|
||||
|
||||
if (list2)
|
||||
{
|
||||
tmp_list = g_list_last (list1);
|
||||
if (tmp_list)
|
||||
tmp_list->next = list2;
|
||||
else
|
||||
list1 = list2;
|
||||
list2->prev = tmp_list;
|
||||
}
|
||||
|
||||
return list1;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_list_remove:
|
||||
* @list: a #GList
|
||||
* @data: the data of the element to remove
|
||||
*
|
||||
* Removes an element from a #GList.
|
||||
* If two elements contain the same data, only the first is removed.
|
||||
* If none of the elements contain the data, the #GList is unchanged.
|
||||
*
|
||||
* Returns: the new start of the #GList
|
||||
*/
|
||||
GList*
|
||||
g_list_remove (GList *list,
|
||||
gconstpointer data)
|
||||
{
|
||||
GList *tmp;
|
||||
|
||||
tmp = list;
|
||||
while (tmp)
|
||||
{
|
||||
if (tmp->data != data)
|
||||
tmp = tmp->next;
|
||||
else
|
||||
{
|
||||
if (tmp->prev)
|
||||
tmp->prev->next = tmp->next;
|
||||
if (tmp->next)
|
||||
tmp->next->prev = tmp->prev;
|
||||
|
||||
if (list == tmp)
|
||||
list = list->next;
|
||||
|
||||
_g_list_free1 (tmp);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_list_remove_all:
|
||||
* @list: a #GList
|
||||
* @data: data to remove
|
||||
*
|
||||
* Removes all list nodes with data equal to @data.
|
||||
* Returns the new head of the list. Contrast with
|
||||
* g_list_remove() which removes only the first node
|
||||
* matching the given data.
|
||||
*
|
||||
* Returns: new head of @list
|
||||
*/
|
||||
GList*
|
||||
g_list_remove_all (GList *list,
|
||||
gconstpointer data)
|
||||
{
|
||||
GList *tmp = list;
|
||||
|
||||
while (tmp)
|
||||
{
|
||||
if (tmp->data != data)
|
||||
tmp = tmp->next;
|
||||
else
|
||||
{
|
||||
GList *next = tmp->next;
|
||||
|
||||
if (tmp->prev)
|
||||
tmp->prev->next = next;
|
||||
else
|
||||
list = next;
|
||||
if (next)
|
||||
next->prev = tmp->prev;
|
||||
|
||||
_g_list_free1 (tmp);
|
||||
tmp = next;
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
static inline GList*
|
||||
_g_list_remove_link (GList *list,
|
||||
GList *link)
|
||||
{
|
||||
if (link)
|
||||
{
|
||||
if (link->prev)
|
||||
link->prev->next = link->next;
|
||||
if (link->next)
|
||||
link->next->prev = link->prev;
|
||||
|
||||
if (link == list)
|
||||
list = list->next;
|
||||
|
||||
link->next = NULL;
|
||||
link->prev = NULL;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_list_remove_link:
|
||||
* @list: a #GList
|
||||
* @llink: an element in the #GList
|
||||
*
|
||||
* Removes an element from a #GList, without freeing the element.
|
||||
* The removed element's prev and next links are set to %NULL, so
|
||||
* that it becomes a self-contained list with one element.
|
||||
*
|
||||
* Returns: the new start of the #GList, without the element
|
||||
*/
|
||||
GList*
|
||||
g_list_remove_link (GList *list,
|
||||
GList *llink)
|
||||
{
|
||||
return _g_list_remove_link (list, llink);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_list_delete_link:
|
||||
* @list: a #GList
|
||||
* @link_: node to delete from @list
|
||||
*
|
||||
* Removes the node link_ from the list and frees it.
|
||||
* Compare this to g_list_remove_link() which removes the node
|
||||
* without freeing it.
|
||||
*
|
||||
* Returns: the new head of @list
|
||||
*/
|
||||
GList*
|
||||
g_list_delete_link (GList *list,
|
||||
GList *link_)
|
||||
{
|
||||
list = _g_list_remove_link (list, link_);
|
||||
_g_list_free1 (link_);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_list_copy:
|
||||
* @list: a #GList
|
||||
*
|
||||
* Copies a #GList.
|
||||
*
|
||||
* <note><para>
|
||||
* Note that this is a "shallow" copy. If the list elements
|
||||
* consist of pointers to data, the pointers are copied but
|
||||
* the actual data is not.
|
||||
* </para></note>
|
||||
*
|
||||
* Returns: a copy of @list
|
||||
*/
|
||||
GList*
|
||||
g_list_copy (GList *list)
|
||||
{
|
||||
GList *new_list = NULL;
|
||||
|
||||
if (list)
|
||||
{
|
||||
GList *last;
|
||||
|
||||
new_list = _g_list_alloc ();
|
||||
new_list->data = list->data;
|
||||
new_list->prev = NULL;
|
||||
last = new_list;
|
||||
list = list->next;
|
||||
while (list)
|
||||
{
|
||||
last->next = _g_list_alloc ();
|
||||
last->next->prev = last;
|
||||
last = last->next;
|
||||
last->data = list->data;
|
||||
list = list->next;
|
||||
}
|
||||
last->next = NULL;
|
||||
}
|
||||
|
||||
return new_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_list_reverse:
|
||||
* @list: a #GList
|
||||
*
|
||||
* Reverses a #GList.
|
||||
* It simply switches the next and prev pointers of each element.
|
||||
*
|
||||
* Returns: the start of the reversed #GList
|
||||
*/
|
||||
GList*
|
||||
g_list_reverse (GList *list)
|
||||
{
|
||||
GList *last;
|
||||
|
||||
last = NULL;
|
||||
while (list)
|
||||
{
|
||||
last = list;
|
||||
list = last->next;
|
||||
last->next = last->prev;
|
||||
last->prev = list;
|
||||
}
|
||||
|
||||
return last;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_list_nth:
|
||||
* @list: a #GList
|
||||
* @n: the position of the element, counting from 0
|
||||
*
|
||||
* Gets the element at the given position in a #GList.
|
||||
*
|
||||
* Returns: the element, or %NULL if the position is off
|
||||
* the end of the #GList
|
||||
*/
|
||||
GList*
|
||||
g_list_nth (GList *list,
|
||||
guint n)
|
||||
{
|
||||
while ((n-- > 0) && list)
|
||||
list = list->next;
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_list_nth_prev:
|
||||
* @list: a #GList
|
||||
* @n: the position of the element, counting from 0
|
||||
*
|
||||
* Gets the element @n places before @list.
|
||||
*
|
||||
* Returns: the element, or %NULL if the position is
|
||||
* off the end of the #GList
|
||||
*/
|
||||
GList*
|
||||
g_list_nth_prev (GList *list,
|
||||
guint n)
|
||||
{
|
||||
while ((n-- > 0) && list)
|
||||
list = list->prev;
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_list_nth_data:
|
||||
* @list: a #GList
|
||||
* @n: the position of the element
|
||||
*
|
||||
* Gets the data of the element at the given position.
|
||||
*
|
||||
* Returns: the element's data, or %NULL if the position
|
||||
* is off the end of the #GList
|
||||
*/
|
||||
gpointer
|
||||
g_list_nth_data (GList *list,
|
||||
guint n)
|
||||
{
|
||||
while ((n-- > 0) && list)
|
||||
list = list->next;
|
||||
|
||||
return list ? list->data : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_list_find:
|
||||
* @list: a #GList
|
||||
* @data: the element data to find
|
||||
*
|
||||
* Finds the element in a #GList which
|
||||
* contains the given data.
|
||||
*
|
||||
* Returns: the found #GList element,
|
||||
* or %NULL if it is not found
|
||||
*/
|
||||
GList*
|
||||
g_list_find (GList *list,
|
||||
gconstpointer data)
|
||||
{
|
||||
while (list)
|
||||
{
|
||||
if (list->data == data)
|
||||
break;
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_list_find_custom:
|
||||
* @list: a #GList
|
||||
* @data: user data passed to the function
|
||||
* @func: the function to call for each element.
|
||||
* It should return 0 when the desired element is found
|
||||
*
|
||||
* Finds an element in a #GList, using a supplied function to
|
||||
* find the desired element. It iterates over the list, calling
|
||||
* the given function which should return 0 when the desired
|
||||
* element is found. The function takes two #gconstpointer arguments,
|
||||
* the #GList element's data as the first argument and the
|
||||
* given user data.
|
||||
*
|
||||
* Returns: the found #GList element, or %NULL if it is not found
|
||||
*/
|
||||
GList*
|
||||
g_list_find_custom (GList *list,
|
||||
gconstpointer data,
|
||||
GCompareFunc func)
|
||||
{
|
||||
g_return_val_if_fail (func != NULL, list);
|
||||
|
||||
while (list)
|
||||
{
|
||||
if (! func (list->data, data))
|
||||
return list;
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* g_list_position:
|
||||
* @list: a #GList
|
||||
* @llink: an element in the #GList
|
||||
*
|
||||
* Gets the position of the given element
|
||||
* in the #GList (starting from 0).
|
||||
*
|
||||
* Returns: the position of the element in the #GList,
|
||||
* or -1 if the element is not found
|
||||
*/
|
||||
gint
|
||||
g_list_position (GList *list,
|
||||
GList *llink)
|
||||
{
|
||||
gint i;
|
||||
|
||||
i = 0;
|
||||
while (list)
|
||||
{
|
||||
if (list == llink)
|
||||
return i;
|
||||
i++;
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_list_index:
|
||||
* @list: a #GList
|
||||
* @data: the data to find
|
||||
*
|
||||
* Gets the position of the element containing
|
||||
* the given data (starting from 0).
|
||||
*
|
||||
* Returns: the index of the element containing the data,
|
||||
* or -1 if the data is not found
|
||||
*/
|
||||
gint
|
||||
g_list_index (GList *list,
|
||||
gconstpointer data)
|
||||
{
|
||||
gint i;
|
||||
|
||||
i = 0;
|
||||
while (list)
|
||||
{
|
||||
if (list->data == data)
|
||||
return i;
|
||||
i++;
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_list_last:
|
||||
* @list: a #GList
|
||||
*
|
||||
* Gets the last element in a #GList.
|
||||
*
|
||||
* Returns: the last element in the #GList,
|
||||
* or %NULL if the #GList has no elements
|
||||
*/
|
||||
GList*
|
||||
g_list_last (GList *list)
|
||||
{
|
||||
if (list)
|
||||
{
|
||||
while (list->next)
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_list_first:
|
||||
* @list: a #GList
|
||||
*
|
||||
* Gets the first element in a #GList.
|
||||
*
|
||||
* Returns: the first element in the #GList,
|
||||
* or %NULL if the #GList has no elements
|
||||
*/
|
||||
GList*
|
||||
g_list_first (GList *list)
|
||||
{
|
||||
if (list)
|
||||
{
|
||||
while (list->prev)
|
||||
list = list->prev;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_list_length:
|
||||
* @list: a #GList
|
||||
*
|
||||
* Gets the number of elements in a #GList.
|
||||
*
|
||||
* <note><para>
|
||||
* This function iterates over the whole list to
|
||||
* count its elements.
|
||||
* </para></note>
|
||||
*
|
||||
* Returns: the number of elements in the #GList
|
||||
*/
|
||||
guint
|
||||
g_list_length (GList *list)
|
||||
{
|
||||
guint length;
|
||||
|
||||
length = 0;
|
||||
while (list)
|
||||
{
|
||||
length++;
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_list_foreach:
|
||||
* @list: a #GList
|
||||
* @func: the function to call with each element's data
|
||||
* @user_data: user data to pass to the function
|
||||
*
|
||||
* Calls a function for each element of a #GList.
|
||||
*/
|
||||
void
|
||||
g_list_foreach (GList *list,
|
||||
GFunc func,
|
||||
gpointer user_data)
|
||||
{
|
||||
while (list)
|
||||
{
|
||||
GList *next = list->next;
|
||||
(*func) (list->data, user_data);
|
||||
list = next;
|
||||
}
|
||||
}
|
||||
|
||||
static GList*
|
||||
g_list_insert_sorted_real (GList *list,
|
||||
gpointer data,
|
||||
GFunc func,
|
||||
gpointer user_data)
|
||||
{
|
||||
GList *tmp_list = list;
|
||||
GList *new_list;
|
||||
gint cmp;
|
||||
|
||||
g_return_val_if_fail (func != NULL, list);
|
||||
|
||||
if (!list)
|
||||
{
|
||||
new_list = _g_list_alloc0 ();
|
||||
new_list->data = data;
|
||||
return new_list;
|
||||
}
|
||||
|
||||
cmp = ((GCompareDataFunc) func) (data, tmp_list->data, user_data);
|
||||
|
||||
while ((tmp_list->next) && (cmp > 0))
|
||||
{
|
||||
tmp_list = tmp_list->next;
|
||||
|
||||
cmp = ((GCompareDataFunc) func) (data, tmp_list->data, user_data);
|
||||
}
|
||||
|
||||
new_list = _g_list_alloc0 ();
|
||||
new_list->data = data;
|
||||
|
||||
if ((!tmp_list->next) && (cmp > 0))
|
||||
{
|
||||
tmp_list->next = new_list;
|
||||
new_list->prev = tmp_list;
|
||||
return list;
|
||||
}
|
||||
|
||||
if (tmp_list->prev)
|
||||
{
|
||||
tmp_list->prev->next = new_list;
|
||||
new_list->prev = tmp_list->prev;
|
||||
}
|
||||
new_list->next = tmp_list;
|
||||
tmp_list->prev = new_list;
|
||||
|
||||
if (tmp_list == list)
|
||||
return new_list;
|
||||
else
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_list_insert_sorted:
|
||||
* @list: a pointer to a #GList
|
||||
* @data: the data for the new element
|
||||
* @func: the function to compare elements in the list. It should
|
||||
* return a number > 0 if the first parameter comes after the
|
||||
* second parameter in the sort order.
|
||||
*
|
||||
* Inserts a new element into the list, using the given comparison
|
||||
* function to determine its position.
|
||||
*
|
||||
* Returns: the new start of the #GList
|
||||
*/
|
||||
GList*
|
||||
g_list_insert_sorted (GList *list,
|
||||
gpointer data,
|
||||
GCompareFunc func)
|
||||
{
|
||||
return g_list_insert_sorted_real (list, data, (GFunc) func, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_list_insert_sorted_with_data:
|
||||
* @list: a pointer to a #GList
|
||||
* @data: the data for the new element
|
||||
* @func: the function to compare elements in the list.
|
||||
* It should return a number > 0 if the first parameter
|
||||
* comes after the second parameter in the sort order.
|
||||
* @user_data: user data to pass to comparison function.
|
||||
*
|
||||
* Inserts a new element into the list, using the given comparison
|
||||
* function to determine its position.
|
||||
*
|
||||
* Returns: the new start of the #GList
|
||||
*
|
||||
* Since: 2.10
|
||||
*/
|
||||
GList*
|
||||
g_list_insert_sorted_with_data (GList *list,
|
||||
gpointer data,
|
||||
GCompareDataFunc func,
|
||||
gpointer user_data)
|
||||
{
|
||||
return g_list_insert_sorted_real (list, data, (GFunc) func, user_data);
|
||||
}
|
||||
|
||||
static GList *
|
||||
g_list_sort_merge (GList *l1,
|
||||
GList *l2,
|
||||
GFunc compare_func,
|
||||
gpointer user_data)
|
||||
{
|
||||
GList list, *l, *lprev;
|
||||
gint cmp;
|
||||
|
||||
l = &list;
|
||||
lprev = NULL;
|
||||
|
||||
while (l1 && l2)
|
||||
{
|
||||
cmp = ((GCompareDataFunc) compare_func) (l1->data, l2->data, user_data);
|
||||
|
||||
if (cmp <= 0)
|
||||
{
|
||||
l->next = l1;
|
||||
l1 = l1->next;
|
||||
}
|
||||
else
|
||||
{
|
||||
l->next = l2;
|
||||
l2 = l2->next;
|
||||
}
|
||||
l = l->next;
|
||||
l->prev = lprev;
|
||||
lprev = l;
|
||||
}
|
||||
l->next = l1 ? l1 : l2;
|
||||
l->next->prev = l;
|
||||
|
||||
return list.next;
|
||||
}
|
||||
|
||||
static GList*
|
||||
g_list_sort_real (GList *list,
|
||||
GFunc compare_func,
|
||||
gpointer user_data)
|
||||
{
|
||||
GList *l1, *l2;
|
||||
|
||||
if (!list)
|
||||
return NULL;
|
||||
if (!list->next)
|
||||
return list;
|
||||
|
||||
l1 = list;
|
||||
l2 = list->next;
|
||||
|
||||
while ((l2 = l2->next) != NULL)
|
||||
{
|
||||
if ((l2 = l2->next) == NULL)
|
||||
break;
|
||||
l1 = l1->next;
|
||||
}
|
||||
l2 = l1->next;
|
||||
l1->next = NULL;
|
||||
|
||||
return g_list_sort_merge (g_list_sort_real (list, compare_func, user_data),
|
||||
g_list_sort_real (l2, compare_func, user_data),
|
||||
compare_func,
|
||||
user_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_list_sort:
|
||||
* @list: a #GList
|
||||
* @compare_func: the comparison function used to sort the #GList.
|
||||
* This function is passed the data from 2 elements of the #GList
|
||||
* and should return 0 if they are equal, a negative value if the
|
||||
* first element comes before the second, or a positive value if
|
||||
* the first element comes after the second.
|
||||
*
|
||||
* Sorts a #GList using the given comparison function.
|
||||
*
|
||||
* Returns: the start of the sorted #GList
|
||||
*/
|
||||
GList *
|
||||
g_list_sort (GList *list,
|
||||
GCompareFunc compare_func)
|
||||
{
|
||||
return g_list_sort_real (list, (GFunc) compare_func, NULL);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* g_list_sort_with_data:
|
||||
* @list: a #GList
|
||||
* @compare_func: comparison function
|
||||
* @user_data: user data to pass to comparison function
|
||||
*
|
||||
* Like g_list_sort(), but the comparison function accepts
|
||||
* a user data argument.
|
||||
*
|
||||
* Returns: the new head of @list
|
||||
*/
|
||||
GList *
|
||||
g_list_sort_with_data (GList *list,
|
||||
GCompareDataFunc compare_func,
|
||||
gpointer user_data)
|
||||
{
|
||||
return g_list_sort_real (list, (GFunc) compare_func, user_data);
|
||||
}
|
||||
|
||||
#define __G_LIST_C__
|
||||
#include "galiasdef.c"
|
|
@ -0,0 +1,120 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
|
||||
#error "Only <glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __G_LIST_H__
|
||||
#define __G_LIST_H__
|
||||
|
||||
#include <glib/gmem.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GList GList;
|
||||
|
||||
struct _GList
|
||||
{
|
||||
gpointer data;
|
||||
GList *next;
|
||||
GList *prev;
|
||||
};
|
||||
|
||||
/* Doubly linked lists
|
||||
*/
|
||||
GList* g_list_alloc (void) G_GNUC_WARN_UNUSED_RESULT;
|
||||
void g_list_free (GList *list);
|
||||
void g_list_free_1 (GList *list);
|
||||
#define g_list_free1 g_list_free_1
|
||||
GList* g_list_append (GList *list,
|
||||
gpointer data) G_GNUC_WARN_UNUSED_RESULT;
|
||||
GList* g_list_prepend (GList *list,
|
||||
gpointer data) G_GNUC_WARN_UNUSED_RESULT;
|
||||
GList* g_list_insert (GList *list,
|
||||
gpointer data,
|
||||
gint position) G_GNUC_WARN_UNUSED_RESULT;
|
||||
GList* g_list_insert_sorted (GList *list,
|
||||
gpointer data,
|
||||
GCompareFunc func) G_GNUC_WARN_UNUSED_RESULT;
|
||||
GList* g_list_insert_sorted_with_data (GList *list,
|
||||
gpointer data,
|
||||
GCompareDataFunc func,
|
||||
gpointer user_data) G_GNUC_WARN_UNUSED_RESULT;
|
||||
GList* g_list_insert_before (GList *list,
|
||||
GList *sibling,
|
||||
gpointer data) G_GNUC_WARN_UNUSED_RESULT;
|
||||
GList* g_list_concat (GList *list1,
|
||||
GList *list2) G_GNUC_WARN_UNUSED_RESULT;
|
||||
GList* g_list_remove (GList *list,
|
||||
gconstpointer data) G_GNUC_WARN_UNUSED_RESULT;
|
||||
GList* g_list_remove_all (GList *list,
|
||||
gconstpointer data) G_GNUC_WARN_UNUSED_RESULT;
|
||||
GList* g_list_remove_link (GList *list,
|
||||
GList *llink) G_GNUC_WARN_UNUSED_RESULT;
|
||||
GList* g_list_delete_link (GList *list,
|
||||
GList *link_) G_GNUC_WARN_UNUSED_RESULT;
|
||||
GList* g_list_reverse (GList *list) G_GNUC_WARN_UNUSED_RESULT;
|
||||
GList* g_list_copy (GList *list) G_GNUC_WARN_UNUSED_RESULT;
|
||||
GList* g_list_nth (GList *list,
|
||||
guint n);
|
||||
GList* g_list_nth_prev (GList *list,
|
||||
guint n);
|
||||
GList* g_list_find (GList *list,
|
||||
gconstpointer data);
|
||||
GList* g_list_find_custom (GList *list,
|
||||
gconstpointer data,
|
||||
GCompareFunc func);
|
||||
gint g_list_position (GList *list,
|
||||
GList *llink);
|
||||
gint g_list_index (GList *list,
|
||||
gconstpointer data);
|
||||
GList* g_list_last (GList *list);
|
||||
GList* g_list_first (GList *list);
|
||||
guint g_list_length (GList *list);
|
||||
void g_list_foreach (GList *list,
|
||||
GFunc func,
|
||||
gpointer user_data);
|
||||
GList* g_list_sort (GList *list,
|
||||
GCompareFunc compare_func) G_GNUC_WARN_UNUSED_RESULT;
|
||||
GList* g_list_sort_with_data (GList *list,
|
||||
GCompareDataFunc compare_func,
|
||||
gpointer user_data) G_GNUC_WARN_UNUSED_RESULT;
|
||||
gpointer g_list_nth_data (GList *list,
|
||||
guint n);
|
||||
|
||||
|
||||
#define g_list_previous(list) ((list) ? (((GList *)(list))->prev) : NULL)
|
||||
#define g_list_next(list) ((list) ? (((GList *)(list))->next) : NULL)
|
||||
|
||||
#ifndef G_DISABLE_DEPRECATED
|
||||
void g_list_push_allocator (gpointer allocator);
|
||||
void g_list_pop_allocator (void);
|
||||
#endif
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_LIST_H__ */
|
|
@ -0,0 +1,277 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
/* This file must not include any other glib header file and must thus
|
||||
* not refer to variables from glibconfig.h
|
||||
*/
|
||||
|
||||
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
|
||||
#error "Only <glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __G_MACROS_H__
|
||||
#define __G_MACROS_H__
|
||||
|
||||
/* We include stddef.h to get the system's definition of NULL
|
||||
*/
|
||||
#include <stddef.h>
|
||||
|
||||
/* Here we provide G_GNUC_EXTENSION as an alias for __extension__,
|
||||
* where this is valid. This allows for warningless compilation of
|
||||
* "long long" types even in the presence of '-ansi -pedantic'.
|
||||
*/
|
||||
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
|
||||
# define G_GNUC_EXTENSION __extension__
|
||||
#else
|
||||
# define G_GNUC_EXTENSION
|
||||
#endif
|
||||
|
||||
/* Provide macros to feature the GCC function attribute.
|
||||
*/
|
||||
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
|
||||
#define G_GNUC_PURE \
|
||||
__attribute__((__pure__))
|
||||
#define G_GNUC_MALLOC \
|
||||
__attribute__((__malloc__))
|
||||
#else
|
||||
#define G_GNUC_PURE
|
||||
#define G_GNUC_MALLOC
|
||||
#endif
|
||||
|
||||
#if __GNUC__ >= 4
|
||||
#define G_GNUC_NULL_TERMINATED __attribute__((__sentinel__))
|
||||
#else
|
||||
#define G_GNUC_NULL_TERMINATED
|
||||
#endif
|
||||
|
||||
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
|
||||
#define G_GNUC_ALLOC_SIZE(x) __attribute__((__alloc_size__(x)))
|
||||
#define G_GNUC_ALLOC_SIZE2(x,y) __attribute__((__alloc_size__(x,y)))
|
||||
#else
|
||||
#define G_GNUC_ALLOC_SIZE(x)
|
||||
#define G_GNUC_ALLOC_SIZE2(x,y)
|
||||
#endif
|
||||
|
||||
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
|
||||
#define G_GNUC_PRINTF( format_idx, arg_idx ) \
|
||||
__attribute__((__format__ (__printf__, format_idx, arg_idx)))
|
||||
#define G_GNUC_SCANF( format_idx, arg_idx ) \
|
||||
__attribute__((__format__ (__scanf__, format_idx, arg_idx)))
|
||||
#define G_GNUC_FORMAT( arg_idx ) \
|
||||
__attribute__((__format_arg__ (arg_idx)))
|
||||
#define G_GNUC_NORETURN \
|
||||
__attribute__((__noreturn__))
|
||||
#define G_GNUC_CONST \
|
||||
__attribute__((__const__))
|
||||
#define G_GNUC_UNUSED \
|
||||
__attribute__((__unused__))
|
||||
#define G_GNUC_NO_INSTRUMENT \
|
||||
__attribute__((__no_instrument_function__))
|
||||
#else /* !__GNUC__ */
|
||||
#define G_GNUC_PRINTF( format_idx, arg_idx )
|
||||
#define G_GNUC_SCANF( format_idx, arg_idx )
|
||||
#define G_GNUC_FORMAT( arg_idx )
|
||||
#define G_GNUC_NORETURN
|
||||
#define G_GNUC_CONST
|
||||
#define G_GNUC_UNUSED
|
||||
#define G_GNUC_NO_INSTRUMENT
|
||||
#endif /* !__GNUC__ */
|
||||
|
||||
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
|
||||
#define G_GNUC_DEPRECATED \
|
||||
__attribute__((__deprecated__))
|
||||
#else
|
||||
#define G_GNUC_DEPRECATED
|
||||
#endif /* __GNUC__ */
|
||||
|
||||
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
|
||||
# define G_GNUC_MAY_ALIAS __attribute__((may_alias))
|
||||
#else
|
||||
# define G_GNUC_MAY_ALIAS
|
||||
#endif
|
||||
|
||||
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
|
||||
#define G_GNUC_WARN_UNUSED_RESULT \
|
||||
__attribute__((warn_unused_result))
|
||||
#else
|
||||
#define G_GNUC_WARN_UNUSED_RESULT
|
||||
#endif /* __GNUC__ */
|
||||
|
||||
#ifndef G_DISABLE_DEPRECATED
|
||||
/* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with
|
||||
* macros, so we can refer to them as strings unconditionally.
|
||||
* usage not-recommended since gcc-3.0
|
||||
*/
|
||||
#if defined (__GNUC__) && (__GNUC__ < 3)
|
||||
#define G_GNUC_FUNCTION __FUNCTION__
|
||||
#define G_GNUC_PRETTY_FUNCTION __PRETTY_FUNCTION__
|
||||
#else /* !__GNUC__ */
|
||||
#define G_GNUC_FUNCTION ""
|
||||
#define G_GNUC_PRETTY_FUNCTION ""
|
||||
#endif /* !__GNUC__ */
|
||||
#endif /* !G_DISABLE_DEPRECATED */
|
||||
|
||||
#define G_STRINGIFY(macro_or_string) G_STRINGIFY_ARG (macro_or_string)
|
||||
#define G_STRINGIFY_ARG(contents) #contents
|
||||
|
||||
#define G_PASTE_ARGS(identifier1,identifier2) identifier1 ## identifier2
|
||||
#define G_PASTE(identifier1,identifier2) G_PASTE_ARGS (identifier1, identifier2)
|
||||
#define G_STATIC_ASSERT(expr) typedef struct { char Compile_Time_Assertion[(expr) ? 1 : -1]; } G_PASTE (_GStaticAssert_, __LINE__)
|
||||
|
||||
/* Provide a string identifying the current code position */
|
||||
#if defined(__GNUC__) && (__GNUC__ < 3) && !defined(__cplusplus)
|
||||
# define G_STRLOC __FILE__ ":" G_STRINGIFY (__LINE__) ":" __PRETTY_FUNCTION__ "()"
|
||||
#else
|
||||
# define G_STRLOC __FILE__ ":" G_STRINGIFY (__LINE__)
|
||||
#endif
|
||||
|
||||
/* Provide a string identifying the current function, non-concatenatable */
|
||||
#if defined (__GNUC__)
|
||||
# define G_STRFUNC ((const char*) (__PRETTY_FUNCTION__))
|
||||
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 19901L
|
||||
# define G_STRFUNC ((const char*) (__func__))
|
||||
#else
|
||||
# define G_STRFUNC ((const char*) ("???"))
|
||||
#endif
|
||||
|
||||
/* Guard C code in headers, while including them from C++ */
|
||||
#ifdef __cplusplus
|
||||
# define G_BEGIN_DECLS extern "C" {
|
||||
# define G_END_DECLS }
|
||||
#else
|
||||
# define G_BEGIN_DECLS
|
||||
# define G_END_DECLS
|
||||
#endif
|
||||
|
||||
/* Provide definitions for some commonly used macros.
|
||||
* Some of them are only provided if they haven't already
|
||||
* been defined. It is assumed that if they are already
|
||||
* defined then the current definition is correct.
|
||||
*/
|
||||
#ifndef NULL
|
||||
# ifdef __cplusplus
|
||||
# define NULL (0L)
|
||||
# else /* !__cplusplus */
|
||||
# define NULL ((void*) 0)
|
||||
# endif /* !__cplusplus */
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE (0)
|
||||
#endif
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE (!FALSE)
|
||||
#endif
|
||||
|
||||
#undef MAX
|
||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
|
||||
#undef MIN
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
|
||||
#undef ABS
|
||||
#define ABS(a) (((a) < 0) ? -(a) : (a))
|
||||
|
||||
#undef CLAMP
|
||||
#define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
|
||||
|
||||
/* Count the number of elements in an array. The array must be defined
|
||||
* as such; using this with a dynamically allocated array will give
|
||||
* incorrect results.
|
||||
*/
|
||||
#define G_N_ELEMENTS(arr) (sizeof (arr) / sizeof ((arr)[0]))
|
||||
|
||||
/* Macros by analogy to GINT_TO_POINTER, GPOINTER_TO_INT
|
||||
*/
|
||||
#define GPOINTER_TO_SIZE(p) ((gsize) (p))
|
||||
#define GSIZE_TO_POINTER(s) ((gpointer) (gsize) (s))
|
||||
|
||||
/* Provide convenience macros for handling structure
|
||||
* fields through their offsets.
|
||||
*/
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ >= 4
|
||||
# define G_STRUCT_OFFSET(struct_type, member) \
|
||||
((glong) offsetof (struct_type, member))
|
||||
#else
|
||||
# define G_STRUCT_OFFSET(struct_type, member) \
|
||||
((glong) ((guint8*) &((struct_type*) 0)->member))
|
||||
#endif
|
||||
|
||||
#define G_STRUCT_MEMBER_P(struct_p, struct_offset) \
|
||||
((gpointer) ((guint8*) (struct_p) + (glong) (struct_offset)))
|
||||
#define G_STRUCT_MEMBER(member_type, struct_p, struct_offset) \
|
||||
(*(member_type*) G_STRUCT_MEMBER_P ((struct_p), (struct_offset)))
|
||||
|
||||
/* Provide simple macro statement wrappers:
|
||||
* G_STMT_START { statements; } G_STMT_END;
|
||||
* This can be used as a single statement, like:
|
||||
* if (x) G_STMT_START { ... } G_STMT_END; else ...
|
||||
* This intentionally does not use compiler extensions like GCC's '({...})' to
|
||||
* avoid portability issue or side effects when compiled with different compilers.
|
||||
*/
|
||||
#if !(defined (G_STMT_START) && defined (G_STMT_END))
|
||||
# define G_STMT_START do
|
||||
# define G_STMT_END while (0)
|
||||
#endif
|
||||
|
||||
/* Allow the app programmer to select whether or not return values
|
||||
* (usually char*) are const or not. Don't try using this feature for
|
||||
* functions with C++ linkage.
|
||||
*/
|
||||
#ifdef G_DISABLE_CONST_RETURNS
|
||||
#define G_CONST_RETURN
|
||||
#else
|
||||
#define G_CONST_RETURN const
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The G_LIKELY and G_UNLIKELY macros let the programmer give hints to
|
||||
* the compiler about the expected result of an expression. Some compilers
|
||||
* can use this information for optimizations.
|
||||
*
|
||||
* The _G_BOOLEAN_EXPR macro is intended to trigger a gcc warning when
|
||||
* putting assignments in g_return_if_fail ().
|
||||
*/
|
||||
#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
|
||||
#define _G_BOOLEAN_EXPR(expr) \
|
||||
__extension__ ({ \
|
||||
int _g_boolean_var_; \
|
||||
if (expr) \
|
||||
_g_boolean_var_ = 1; \
|
||||
else \
|
||||
_g_boolean_var_ = 0; \
|
||||
_g_boolean_var_; \
|
||||
})
|
||||
#define G_LIKELY(expr) (__builtin_expect (_G_BOOLEAN_EXPR(expr), 1))
|
||||
#define G_UNLIKELY(expr) (__builtin_expect (_G_BOOLEAN_EXPR(expr), 0))
|
||||
#else
|
||||
#define G_LIKELY(expr) (expr)
|
||||
#define G_UNLIKELY(expr) (expr)
|
||||
#endif
|
||||
|
||||
#endif /* __G_MACROS_H__ */
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,299 @@
|
|||
/* gmain.h - the GLib Main loop
|
||||
* Copyright (C) 1998-2000 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
|
||||
#error "Only <glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __G_MAIN_H__
|
||||
#define __G_MAIN_H__
|
||||
|
||||
#include <glib/gpoll.h>
|
||||
#include <glib/gslist.h>
|
||||
#include <glib/gthread.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GMainContext GMainContext; /* Opaque */
|
||||
typedef struct _GMainLoop GMainLoop; /* Opaque */
|
||||
typedef struct _GSource GSource;
|
||||
typedef struct _GSourceCallbackFuncs GSourceCallbackFuncs;
|
||||
typedef struct _GSourceFuncs GSourceFuncs;
|
||||
|
||||
typedef gboolean (*GSourceFunc) (gpointer data);
|
||||
typedef void (*GChildWatchFunc) (GPid pid,
|
||||
gint status,
|
||||
gpointer data);
|
||||
struct _GSource
|
||||
{
|
||||
/*< private >*/
|
||||
gpointer callback_data;
|
||||
GSourceCallbackFuncs *callback_funcs;
|
||||
|
||||
GSourceFuncs *source_funcs;
|
||||
guint ref_count;
|
||||
|
||||
GMainContext *context;
|
||||
|
||||
gint priority;
|
||||
guint flags;
|
||||
guint source_id;
|
||||
|
||||
GSList *poll_fds;
|
||||
|
||||
GSource *prev;
|
||||
GSource *next;
|
||||
|
||||
gpointer reserved1;
|
||||
gpointer reserved2;
|
||||
};
|
||||
|
||||
struct _GSourceCallbackFuncs
|
||||
{
|
||||
void (*ref) (gpointer cb_data);
|
||||
void (*unref) (gpointer cb_data);
|
||||
void (*get) (gpointer cb_data,
|
||||
GSource *source,
|
||||
GSourceFunc *func,
|
||||
gpointer *data);
|
||||
};
|
||||
|
||||
typedef void (*GSourceDummyMarshal) (void);
|
||||
|
||||
struct _GSourceFuncs
|
||||
{
|
||||
gboolean (*prepare) (GSource *source,
|
||||
gint *timeout_);
|
||||
gboolean (*check) (GSource *source);
|
||||
gboolean (*dispatch) (GSource *source,
|
||||
GSourceFunc callback,
|
||||
gpointer user_data);
|
||||
void (*finalize) (GSource *source); /* Can be NULL */
|
||||
|
||||
/* For use by g_source_set_closure */
|
||||
GSourceFunc closure_callback;
|
||||
GSourceDummyMarshal closure_marshal; /* Really is of type GClosureMarshal */
|
||||
};
|
||||
|
||||
/* Standard priorities */
|
||||
|
||||
#define G_PRIORITY_HIGH -100
|
||||
#define G_PRIORITY_DEFAULT 0
|
||||
#define G_PRIORITY_HIGH_IDLE 100
|
||||
#define G_PRIORITY_DEFAULT_IDLE 200
|
||||
#define G_PRIORITY_LOW 300
|
||||
|
||||
/* GMainContext: */
|
||||
|
||||
GMainContext *g_main_context_new (void);
|
||||
GMainContext *g_main_context_ref (GMainContext *context);
|
||||
void g_main_context_unref (GMainContext *context);
|
||||
GMainContext *g_main_context_default (void);
|
||||
|
||||
gboolean g_main_context_iteration (GMainContext *context,
|
||||
gboolean may_block);
|
||||
gboolean g_main_context_pending (GMainContext *context);
|
||||
|
||||
/* For implementation of legacy interfaces
|
||||
*/
|
||||
GSource *g_main_context_find_source_by_id (GMainContext *context,
|
||||
guint source_id);
|
||||
GSource *g_main_context_find_source_by_user_data (GMainContext *context,
|
||||
gpointer user_data);
|
||||
GSource *g_main_context_find_source_by_funcs_user_data (GMainContext *context,
|
||||
GSourceFuncs *funcs,
|
||||
gpointer user_data);
|
||||
|
||||
/* Low level functions for implementing custom main loops.
|
||||
*/
|
||||
void g_main_context_wakeup (GMainContext *context);
|
||||
gboolean g_main_context_acquire (GMainContext *context);
|
||||
void g_main_context_release (GMainContext *context);
|
||||
gboolean g_main_context_is_owner (GMainContext *context);
|
||||
gboolean g_main_context_wait (GMainContext *context,
|
||||
GCond *cond,
|
||||
GMutex *mutex);
|
||||
|
||||
gboolean g_main_context_prepare (GMainContext *context,
|
||||
gint *priority);
|
||||
gint g_main_context_query (GMainContext *context,
|
||||
gint max_priority,
|
||||
gint *timeout_,
|
||||
GPollFD *fds,
|
||||
gint n_fds);
|
||||
gint g_main_context_check (GMainContext *context,
|
||||
gint max_priority,
|
||||
GPollFD *fds,
|
||||
gint n_fds);
|
||||
void g_main_context_dispatch (GMainContext *context);
|
||||
|
||||
void g_main_context_set_poll_func (GMainContext *context,
|
||||
GPollFunc func);
|
||||
GPollFunc g_main_context_get_poll_func (GMainContext *context);
|
||||
|
||||
/* Low level functions for use by source implementations
|
||||
*/
|
||||
void g_main_context_add_poll (GMainContext *context,
|
||||
GPollFD *fd,
|
||||
gint priority);
|
||||
void g_main_context_remove_poll (GMainContext *context,
|
||||
GPollFD *fd);
|
||||
|
||||
gint g_main_depth (void);
|
||||
GSource *g_main_current_source (void);
|
||||
|
||||
|
||||
/* GMainLoop: */
|
||||
|
||||
GMainLoop *g_main_loop_new (GMainContext *context,
|
||||
gboolean is_running);
|
||||
void g_main_loop_run (GMainLoop *loop);
|
||||
void g_main_loop_quit (GMainLoop *loop);
|
||||
GMainLoop *g_main_loop_ref (GMainLoop *loop);
|
||||
void g_main_loop_unref (GMainLoop *loop);
|
||||
gboolean g_main_loop_is_running (GMainLoop *loop);
|
||||
GMainContext *g_main_loop_get_context (GMainLoop *loop);
|
||||
|
||||
/* GSource: */
|
||||
|
||||
GSource *g_source_new (GSourceFuncs *source_funcs,
|
||||
guint struct_size);
|
||||
GSource *g_source_ref (GSource *source);
|
||||
void g_source_unref (GSource *source);
|
||||
|
||||
guint g_source_attach (GSource *source,
|
||||
GMainContext *context);
|
||||
void g_source_destroy (GSource *source);
|
||||
|
||||
void g_source_set_priority (GSource *source,
|
||||
gint priority);
|
||||
gint g_source_get_priority (GSource *source);
|
||||
void g_source_set_can_recurse (GSource *source,
|
||||
gboolean can_recurse);
|
||||
gboolean g_source_get_can_recurse (GSource *source);
|
||||
guint g_source_get_id (GSource *source);
|
||||
|
||||
GMainContext *g_source_get_context (GSource *source);
|
||||
|
||||
void g_source_set_callback (GSource *source,
|
||||
GSourceFunc func,
|
||||
gpointer data,
|
||||
GDestroyNotify notify);
|
||||
|
||||
void g_source_set_funcs (GSource *source,
|
||||
GSourceFuncs *funcs);
|
||||
gboolean g_source_is_destroyed (GSource *source);
|
||||
|
||||
/* Used to implement g_source_connect_closure and internally*/
|
||||
void g_source_set_callback_indirect (GSource *source,
|
||||
gpointer callback_data,
|
||||
GSourceCallbackFuncs *callback_funcs);
|
||||
|
||||
void g_source_add_poll (GSource *source,
|
||||
GPollFD *fd);
|
||||
void g_source_remove_poll (GSource *source,
|
||||
GPollFD *fd);
|
||||
|
||||
void g_source_get_current_time (GSource *source,
|
||||
GTimeVal *timeval);
|
||||
|
||||
/* void g_source_connect_closure (GSource *source,
|
||||
GClosure *closure);
|
||||
*/
|
||||
|
||||
/* Specific source types
|
||||
*/
|
||||
GSource *g_idle_source_new (void);
|
||||
GSource *g_child_watch_source_new (GPid pid);
|
||||
GSource *g_timeout_source_new (guint interval);
|
||||
GSource *g_timeout_source_new_seconds (guint interval);
|
||||
|
||||
/* Miscellaneous functions
|
||||
*/
|
||||
void g_get_current_time (GTimeVal *result);
|
||||
|
||||
/* ============== Compat main loop stuff ================== */
|
||||
|
||||
#ifndef G_DISABLE_DEPRECATED
|
||||
|
||||
/* Legacy names for GMainLoop functions
|
||||
*/
|
||||
#define g_main_new(is_running) g_main_loop_new (NULL, is_running);
|
||||
#define g_main_run(loop) g_main_loop_run(loop)
|
||||
#define g_main_quit(loop) g_main_loop_quit(loop)
|
||||
#define g_main_destroy(loop) g_main_loop_unref(loop)
|
||||
#define g_main_is_running(loop) g_main_loop_is_running(loop)
|
||||
|
||||
/* Functions to manipulate the default main loop
|
||||
*/
|
||||
|
||||
#define g_main_iteration(may_block) g_main_context_iteration (NULL, may_block)
|
||||
#define g_main_pending() g_main_context_pending (NULL)
|
||||
|
||||
#define g_main_set_poll_func(func) g_main_context_set_poll_func (NULL, func)
|
||||
|
||||
#endif /* G_DISABLE_DEPRECATED */
|
||||
|
||||
/* Source manipulation by ID */
|
||||
gboolean g_source_remove (guint tag);
|
||||
gboolean g_source_remove_by_user_data (gpointer user_data);
|
||||
gboolean g_source_remove_by_funcs_user_data (GSourceFuncs *funcs,
|
||||
gpointer user_data);
|
||||
|
||||
/* Idles, child watchers and timeouts */
|
||||
guint g_timeout_add_full (gint priority,
|
||||
guint interval,
|
||||
GSourceFunc function,
|
||||
gpointer data,
|
||||
GDestroyNotify notify);
|
||||
guint g_timeout_add (guint interval,
|
||||
GSourceFunc function,
|
||||
gpointer data);
|
||||
guint g_timeout_add_seconds_full (gint priority,
|
||||
guint interval,
|
||||
GSourceFunc function,
|
||||
gpointer data,
|
||||
GDestroyNotify notify);
|
||||
guint g_timeout_add_seconds (guint interval,
|
||||
GSourceFunc function,
|
||||
gpointer data);
|
||||
guint g_child_watch_add_full (gint priority,
|
||||
GPid pid,
|
||||
GChildWatchFunc function,
|
||||
gpointer data,
|
||||
GDestroyNotify notify);
|
||||
guint g_child_watch_add (GPid pid,
|
||||
GChildWatchFunc function,
|
||||
gpointer data);
|
||||
guint g_idle_add (GSourceFunc function,
|
||||
gpointer data);
|
||||
guint g_idle_add_full (gint priority,
|
||||
GSourceFunc function,
|
||||
gpointer data,
|
||||
GDestroyNotify notify);
|
||||
gboolean g_idle_remove_by_data (gpointer data);
|
||||
|
||||
/* Hook for GClosure / GSource integration. Don't touch */
|
||||
GLIB_VAR GSourceFuncs g_timeout_funcs;
|
||||
GLIB_VAR GSourceFuncs g_child_watch_funcs;
|
||||
GLIB_VAR GSourceFuncs g_idle_funcs;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_MAIN_H__ */
|
|
@ -0,0 +1,278 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* gmappedfile.c: Simplified wrapper around the mmap() function.
|
||||
*
|
||||
* Copyright 2005 Matthias Clasen
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#ifdef HAVE_MMAP
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
#include "glibconfig.h"
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
#include <windows.h>
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
#include "gconvert.h"
|
||||
#include "gerror.h"
|
||||
#include "gfileutils.h"
|
||||
#include "gmappedfile.h"
|
||||
#include "gmem.h"
|
||||
#include "gmessages.h"
|
||||
#include "gstdio.h"
|
||||
#include "gstrfuncs.h"
|
||||
|
||||
#include "glibintl.h"
|
||||
|
||||
#include "galias.h"
|
||||
|
||||
#ifndef _O_BINARY
|
||||
#define _O_BINARY 0
|
||||
#endif
|
||||
|
||||
#ifndef MAP_FAILED
|
||||
#define MAP_FAILED ((void *) -1)
|
||||
#endif
|
||||
|
||||
struct _GMappedFile
|
||||
{
|
||||
gsize length;
|
||||
gchar *contents;
|
||||
#ifdef G_OS_WIN32
|
||||
HANDLE mapping;
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* g_mapped_file_new:
|
||||
* @filename: The path of the file to load, in the GLib filename encoding
|
||||
* @writable: whether the mapping should be writable
|
||||
* @error: return location for a #GError, or %NULL
|
||||
*
|
||||
* Maps a file into memory. On UNIX, this is using the mmap() function.
|
||||
*
|
||||
* If @writable is %TRUE, the mapped buffer may be modified, otherwise
|
||||
* it is an error to modify the mapped buffer. Modifications to the buffer
|
||||
* are not visible to other processes mapping the same file, and are not
|
||||
* written back to the file.
|
||||
*
|
||||
* Note that modifications of the underlying file might affect the contents
|
||||
* of the #GMappedFile. Therefore, mapping should only be used if the file
|
||||
* will not be modified, or if all modifications of the file are done
|
||||
* atomically (e.g. using g_file_set_contents()).
|
||||
*
|
||||
* Return value: a newly allocated #GMappedFile which must be freed
|
||||
* with g_mapped_file_free(), or %NULL if the mapping failed.
|
||||
*
|
||||
* Since: 2.8
|
||||
*/
|
||||
GMappedFile *
|
||||
g_mapped_file_new (const gchar *filename,
|
||||
gboolean writable,
|
||||
GError **error)
|
||||
{
|
||||
GMappedFile *file;
|
||||
int fd;
|
||||
struct stat st;
|
||||
|
||||
g_return_val_if_fail (filename != NULL, NULL);
|
||||
g_return_val_if_fail (!error || *error == NULL, NULL);
|
||||
|
||||
fd = g_open (filename, (writable ? O_RDWR : O_RDONLY) | _O_BINARY, 0);
|
||||
if (fd == -1)
|
||||
{
|
||||
int save_errno = errno;
|
||||
gchar *display_filename = g_filename_display_name (filename);
|
||||
|
||||
g_set_error (error,
|
||||
G_FILE_ERROR,
|
||||
g_file_error_from_errno (save_errno),
|
||||
_("Failed to open file '%s': open() failed: %s"),
|
||||
display_filename,
|
||||
g_strerror (save_errno));
|
||||
g_free (display_filename);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
file = g_new0 (GMappedFile, 1);
|
||||
|
||||
if (fstat (fd, &st) == -1)
|
||||
{
|
||||
int save_errno = errno;
|
||||
gchar *display_filename = g_filename_display_name (filename);
|
||||
|
||||
g_set_error (error,
|
||||
G_FILE_ERROR,
|
||||
g_file_error_from_errno (save_errno),
|
||||
_("Failed to get attributes of file '%s': fstat() failed: %s"),
|
||||
display_filename,
|
||||
g_strerror (save_errno));
|
||||
g_free (display_filename);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (st.st_size == 0)
|
||||
{
|
||||
file->length = 0;
|
||||
file->contents = "";
|
||||
close (fd);
|
||||
return file;
|
||||
}
|
||||
|
||||
file->contents = MAP_FAILED;
|
||||
|
||||
#ifdef HAVE_MMAP
|
||||
if (st.st_size > G_MAXSIZE)
|
||||
{
|
||||
errno = EINVAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
file->length = (gsize) st.st_size;
|
||||
file->contents = (gchar *) mmap (NULL, file->length,
|
||||
writable ? PROT_READ|PROT_WRITE : PROT_READ,
|
||||
MAP_PRIVATE, fd, 0);
|
||||
}
|
||||
#endif
|
||||
#ifdef G_OS_WIN32
|
||||
file->length = st.st_size;
|
||||
file->mapping = CreateFileMapping ((HANDLE) _get_osfhandle (fd), NULL,
|
||||
writable ? PAGE_WRITECOPY : PAGE_READONLY,
|
||||
0, 0,
|
||||
NULL);
|
||||
if (file->mapping != NULL)
|
||||
{
|
||||
file->contents = MapViewOfFile (file->mapping,
|
||||
writable ? FILE_MAP_COPY : FILE_MAP_READ,
|
||||
0, 0,
|
||||
0);
|
||||
if (file->contents == NULL)
|
||||
{
|
||||
file->contents = MAP_FAILED;
|
||||
CloseHandle (file->mapping);
|
||||
file->mapping = NULL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
if (file->contents == MAP_FAILED)
|
||||
{
|
||||
int save_errno = errno;
|
||||
gchar *display_filename = g_filename_display_name (filename);
|
||||
|
||||
g_set_error (error,
|
||||
G_FILE_ERROR,
|
||||
g_file_error_from_errno (save_errno),
|
||||
_("Failed to map file '%s': mmap() failed: %s"),
|
||||
display_filename,
|
||||
g_strerror (save_errno));
|
||||
g_free (display_filename);
|
||||
goto out;
|
||||
}
|
||||
|
||||
close (fd);
|
||||
return file;
|
||||
|
||||
out:
|
||||
close (fd);
|
||||
g_free (file);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_mapped_file_get_length:
|
||||
* @file: a #GMappedFile
|
||||
*
|
||||
* Returns the length of the contents of a #GMappedFile.
|
||||
*
|
||||
* Returns: the length of the contents of @file.
|
||||
*
|
||||
* Since: 2.8
|
||||
*/
|
||||
gsize
|
||||
g_mapped_file_get_length (GMappedFile *file)
|
||||
{
|
||||
g_return_val_if_fail (file != NULL, 0);
|
||||
|
||||
return file->length;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_mapped_file_get_contents:
|
||||
* @file: a #GMappedFile
|
||||
*
|
||||
* Returns the contents of a #GMappedFile.
|
||||
*
|
||||
* Note that the contents may not be zero-terminated,
|
||||
* even if the #GMappedFile is backed by a text file.
|
||||
*
|
||||
* Returns: the contents of @file.
|
||||
*
|
||||
* Since: 2.8
|
||||
*/
|
||||
gchar *
|
||||
g_mapped_file_get_contents (GMappedFile *file)
|
||||
{
|
||||
g_return_val_if_fail (file != NULL, NULL);
|
||||
|
||||
return file->contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_mapped_file_free:
|
||||
* @file: a #GMappedFile
|
||||
*
|
||||
* Unmaps the buffer of @file and frees it.
|
||||
*
|
||||
* Since: 2.8
|
||||
*/
|
||||
void
|
||||
g_mapped_file_free (GMappedFile *file)
|
||||
{
|
||||
g_return_if_fail (file != NULL);
|
||||
|
||||
if (file->length)
|
||||
{
|
||||
#ifdef HAVE_MMAP
|
||||
munmap (file->contents, file->length);
|
||||
#endif
|
||||
#ifdef G_OS_WIN32
|
||||
UnmapViewOfFile (file->contents);
|
||||
CloseHandle (file->mapping);
|
||||
#endif
|
||||
}
|
||||
|
||||
g_free (file);
|
||||
}
|
||||
|
||||
|
||||
#define __G_MAPPED_FILE_C__
|
||||
#include "galiasdef.c"
|
|
@ -0,0 +1,44 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* gmappedfile.h: Simplified wrapper around the mmap function
|
||||
*
|
||||
* Copyright 2005 Matthias Clasen
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
|
||||
#error "Only <glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __G_MAPPED_FILE_H__
|
||||
#define __G_MAPPED_FILE_H__
|
||||
|
||||
#include <glib/gerror.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GMappedFile GMappedFile;
|
||||
|
||||
GMappedFile *g_mapped_file_new (const gchar *filename,
|
||||
gboolean writable,
|
||||
GError **error) G_GNUC_MALLOC;
|
||||
gsize g_mapped_file_get_length (GMappedFile *file);
|
||||
gchar *g_mapped_file_get_contents (GMappedFile *file);
|
||||
void g_mapped_file_free (GMappedFile *file);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_MAPPED_FILE_H__ */
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,163 @@
|
|||
/* gmarkup.h - Simple XML-like string parser/writer
|
||||
*
|
||||
* Copyright 2000 Red Hat, Inc.
|
||||
*
|
||||
* GLib is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* GLib 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with GLib; see the file COPYING.LIB. If not,
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
|
||||
#error "Only <glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __G_MARKUP_H__
|
||||
#define __G_MARKUP_H__
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <glib/gerror.h>
|
||||
#include <glib/gslist.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef enum
|
||||
{
|
||||
G_MARKUP_ERROR_BAD_UTF8,
|
||||
G_MARKUP_ERROR_EMPTY,
|
||||
G_MARKUP_ERROR_PARSE,
|
||||
/* The following are primarily intended for specific GMarkupParser
|
||||
* implementations to set.
|
||||
*/
|
||||
G_MARKUP_ERROR_UNKNOWN_ELEMENT,
|
||||
G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,
|
||||
G_MARKUP_ERROR_INVALID_CONTENT,
|
||||
G_MARKUP_ERROR_MISSING_ATTRIBUTE
|
||||
} GMarkupError;
|
||||
|
||||
#define G_MARKUP_ERROR g_markup_error_quark ()
|
||||
|
||||
GQuark g_markup_error_quark (void);
|
||||
|
||||
typedef enum
|
||||
{
|
||||
G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG = 1 << 0,
|
||||
G_MARKUP_TREAT_CDATA_AS_TEXT = 1 << 1,
|
||||
G_MARKUP_PREFIX_ERROR_POSITION = 1 << 2
|
||||
} GMarkupParseFlags;
|
||||
|
||||
typedef struct _GMarkupParseContext GMarkupParseContext;
|
||||
typedef struct _GMarkupParser GMarkupParser;
|
||||
|
||||
struct _GMarkupParser
|
||||
{
|
||||
/* Called for open tags <foo bar="baz"> */
|
||||
void (*start_element) (GMarkupParseContext *context,
|
||||
const gchar *element_name,
|
||||
const gchar **attribute_names,
|
||||
const gchar **attribute_values,
|
||||
gpointer user_data,
|
||||
GError **error);
|
||||
|
||||
/* Called for close tags </foo> */
|
||||
void (*end_element) (GMarkupParseContext *context,
|
||||
const gchar *element_name,
|
||||
gpointer user_data,
|
||||
GError **error);
|
||||
|
||||
/* Called for character data */
|
||||
/* text is not nul-terminated */
|
||||
void (*text) (GMarkupParseContext *context,
|
||||
const gchar *text,
|
||||
gsize text_len,
|
||||
gpointer user_data,
|
||||
GError **error);
|
||||
|
||||
/* Called for strings that should be re-saved verbatim in this same
|
||||
* position, but are not otherwise interpretable. At the moment
|
||||
* this includes comments and processing instructions.
|
||||
*/
|
||||
/* text is not nul-terminated. */
|
||||
void (*passthrough) (GMarkupParseContext *context,
|
||||
const gchar *passthrough_text,
|
||||
gsize text_len,
|
||||
gpointer user_data,
|
||||
GError **error);
|
||||
|
||||
/* Called on error, including one set by other
|
||||
* methods in the vtable. The GError should not be freed.
|
||||
*/
|
||||
void (*error) (GMarkupParseContext *context,
|
||||
GError *error,
|
||||
gpointer user_data);
|
||||
};
|
||||
|
||||
GMarkupParseContext *g_markup_parse_context_new (const GMarkupParser *parser,
|
||||
GMarkupParseFlags flags,
|
||||
gpointer user_data,
|
||||
GDestroyNotify user_data_dnotify);
|
||||
void g_markup_parse_context_free (GMarkupParseContext *context);
|
||||
gboolean g_markup_parse_context_parse (GMarkupParseContext *context,
|
||||
const gchar *text,
|
||||
gssize text_len,
|
||||
GError **error);
|
||||
void g_markup_parse_context_push (GMarkupParseContext *context,
|
||||
GMarkupParser *parser,
|
||||
gpointer user_data);
|
||||
gpointer g_markup_parse_context_pop (GMarkupParseContext *context);
|
||||
|
||||
gboolean g_markup_parse_context_end_parse (GMarkupParseContext *context,
|
||||
GError **error);
|
||||
G_CONST_RETURN gchar *g_markup_parse_context_get_element (GMarkupParseContext *context);
|
||||
G_CONST_RETURN GSList *g_markup_parse_context_get_element_stack (GMarkupParseContext *context);
|
||||
|
||||
/* For user-constructed error messages, has no precise semantics */
|
||||
void g_markup_parse_context_get_position (GMarkupParseContext *context,
|
||||
gint *line_number,
|
||||
gint *char_number);
|
||||
gpointer g_markup_parse_context_get_user_data (GMarkupParseContext *context);
|
||||
|
||||
/* useful when saving */
|
||||
gchar* g_markup_escape_text (const gchar *text,
|
||||
gssize length);
|
||||
|
||||
gchar *g_markup_printf_escaped (const char *format,
|
||||
...) G_GNUC_PRINTF (1, 2);
|
||||
gchar *g_markup_vprintf_escaped (const char *format,
|
||||
va_list args);
|
||||
|
||||
typedef enum
|
||||
{
|
||||
G_MARKUP_COLLECT_INVALID,
|
||||
G_MARKUP_COLLECT_STRING,
|
||||
G_MARKUP_COLLECT_STRDUP,
|
||||
G_MARKUP_COLLECT_BOOLEAN,
|
||||
G_MARKUP_COLLECT_TRISTATE,
|
||||
|
||||
G_MARKUP_COLLECT_OPTIONAL = (1 << 16)
|
||||
} GMarkupCollectType;
|
||||
|
||||
|
||||
/* useful from start_element */
|
||||
gboolean g_markup_collect_attributes (const gchar *element_name,
|
||||
const gchar **attribute_names,
|
||||
const gchar **attribute_values,
|
||||
GError **error,
|
||||
GMarkupCollectType first_type,
|
||||
const gchar *first_attr,
|
||||
...);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_MARKUP_H__ */
|
|
@ -0,0 +1,730 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
/*
|
||||
* MT safe
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "glib.h"
|
||||
#include "gthreadprivate.h"
|
||||
#include "galias.h"
|
||||
|
||||
#define MEM_PROFILE_TABLE_SIZE 4096
|
||||
|
||||
|
||||
/* notes on macros:
|
||||
* having G_DISABLE_CHECKS defined disables use of glib_mem_profiler_table and
|
||||
* g_mem_profile().
|
||||
* REALLOC_0_WORKS is defined if g_realloc (NULL, x) works.
|
||||
* SANE_MALLOC_PROTOS is defined if the systems malloc() and friends functions
|
||||
* match the corresponding GLib prototypes, keep configure.in and gmem.h in sync here.
|
||||
* g_mem_gc_friendly is TRUE, freed memory should be 0-wiped.
|
||||
*/
|
||||
|
||||
/* --- prototypes --- */
|
||||
static gboolean g_mem_initialized = FALSE;
|
||||
static void g_mem_init_nomessage (void);
|
||||
|
||||
|
||||
/* --- malloc wrappers --- */
|
||||
#ifndef REALLOC_0_WORKS
|
||||
static gpointer
|
||||
standard_realloc (gpointer mem,
|
||||
gsize n_bytes)
|
||||
{
|
||||
if (!mem)
|
||||
return malloc (n_bytes);
|
||||
else
|
||||
return realloc (mem, n_bytes);
|
||||
}
|
||||
#endif /* !REALLOC_0_WORKS */
|
||||
|
||||
#ifdef SANE_MALLOC_PROTOS
|
||||
# define standard_malloc malloc
|
||||
# ifdef REALLOC_0_WORKS
|
||||
# define standard_realloc realloc
|
||||
# endif /* REALLOC_0_WORKS */
|
||||
# define standard_free free
|
||||
# define standard_calloc calloc
|
||||
# define standard_try_malloc malloc
|
||||
# define standard_try_realloc realloc
|
||||
#else /* !SANE_MALLOC_PROTOS */
|
||||
static gpointer
|
||||
standard_malloc (gsize n_bytes)
|
||||
{
|
||||
return malloc (n_bytes);
|
||||
}
|
||||
# ifdef REALLOC_0_WORKS
|
||||
static gpointer
|
||||
standard_realloc (gpointer mem,
|
||||
gsize n_bytes)
|
||||
{
|
||||
return realloc (mem, n_bytes);
|
||||
}
|
||||
# endif /* REALLOC_0_WORKS */
|
||||
static void
|
||||
standard_free (gpointer mem)
|
||||
{
|
||||
free (mem);
|
||||
}
|
||||
static gpointer
|
||||
standard_calloc (gsize n_blocks,
|
||||
gsize n_bytes)
|
||||
{
|
||||
return calloc (n_blocks, n_bytes);
|
||||
}
|
||||
#define standard_try_malloc standard_malloc
|
||||
#define standard_try_realloc standard_realloc
|
||||
#endif /* !SANE_MALLOC_PROTOS */
|
||||
|
||||
|
||||
/* --- variables --- */
|
||||
static GMemVTable glib_mem_vtable = {
|
||||
standard_malloc,
|
||||
standard_realloc,
|
||||
standard_free,
|
||||
standard_calloc,
|
||||
standard_try_malloc,
|
||||
standard_try_realloc,
|
||||
};
|
||||
|
||||
|
||||
/* --- functions --- */
|
||||
gpointer
|
||||
g_malloc (gsize n_bytes)
|
||||
{
|
||||
if (G_UNLIKELY (!g_mem_initialized))
|
||||
g_mem_init_nomessage();
|
||||
if (G_LIKELY (n_bytes))
|
||||
{
|
||||
gpointer mem;
|
||||
|
||||
mem = glib_mem_vtable.malloc (n_bytes);
|
||||
if (mem)
|
||||
return mem;
|
||||
|
||||
g_error ("%s: failed to allocate %"G_GSIZE_FORMAT" bytes",
|
||||
G_STRLOC, n_bytes);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gpointer
|
||||
g_malloc0 (gsize n_bytes)
|
||||
{
|
||||
if (G_UNLIKELY (!g_mem_initialized))
|
||||
g_mem_init_nomessage();
|
||||
if (G_LIKELY (n_bytes))
|
||||
{
|
||||
gpointer mem;
|
||||
|
||||
mem = glib_mem_vtable.calloc (1, n_bytes);
|
||||
if (mem)
|
||||
return mem;
|
||||
|
||||
g_error ("%s: failed to allocate %"G_GSIZE_FORMAT" bytes",
|
||||
G_STRLOC, n_bytes);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gpointer
|
||||
g_realloc (gpointer mem,
|
||||
gsize n_bytes)
|
||||
{
|
||||
if (G_UNLIKELY (!g_mem_initialized))
|
||||
g_mem_init_nomessage();
|
||||
if (G_LIKELY (n_bytes))
|
||||
{
|
||||
mem = glib_mem_vtable.realloc (mem, n_bytes);
|
||||
if (mem)
|
||||
return mem;
|
||||
|
||||
g_error ("%s: failed to allocate %"G_GSIZE_FORMAT" bytes",
|
||||
G_STRLOC, n_bytes);
|
||||
}
|
||||
|
||||
if (mem)
|
||||
glib_mem_vtable.free (mem);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
g_free (gpointer mem)
|
||||
{
|
||||
if (G_UNLIKELY (!g_mem_initialized))
|
||||
g_mem_init_nomessage();
|
||||
if (G_LIKELY (mem))
|
||||
glib_mem_vtable.free (mem);
|
||||
}
|
||||
|
||||
gpointer
|
||||
g_try_malloc (gsize n_bytes)
|
||||
{
|
||||
if (G_UNLIKELY (!g_mem_initialized))
|
||||
g_mem_init_nomessage();
|
||||
if (G_LIKELY (n_bytes))
|
||||
return glib_mem_vtable.try_malloc (n_bytes);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gpointer
|
||||
g_try_malloc0 (gsize n_bytes)
|
||||
{
|
||||
gpointer mem;
|
||||
|
||||
mem = g_try_malloc (n_bytes);
|
||||
|
||||
if (mem)
|
||||
memset (mem, 0, n_bytes);
|
||||
|
||||
return mem;
|
||||
}
|
||||
|
||||
gpointer
|
||||
g_try_realloc (gpointer mem,
|
||||
gsize n_bytes)
|
||||
{
|
||||
if (G_UNLIKELY (!g_mem_initialized))
|
||||
g_mem_init_nomessage();
|
||||
if (G_LIKELY (n_bytes))
|
||||
return glib_mem_vtable.try_realloc (mem, n_bytes);
|
||||
|
||||
if (mem)
|
||||
glib_mem_vtable.free (mem);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static gpointer
|
||||
fallback_calloc (gsize n_blocks,
|
||||
gsize n_block_bytes)
|
||||
{
|
||||
gsize l = n_blocks * n_block_bytes;
|
||||
gpointer mem = glib_mem_vtable.malloc (l);
|
||||
|
||||
if (mem)
|
||||
memset (mem, 0, l);
|
||||
|
||||
return mem;
|
||||
}
|
||||
|
||||
static gboolean vtable_set = FALSE;
|
||||
|
||||
/**
|
||||
* g_mem_is_system_malloc
|
||||
*
|
||||
* Checks whether the allocator used by g_malloc() is the system's
|
||||
* malloc implementation. If it returns %TRUE memory allocated with
|
||||
* malloc() can be used interchangeable with memory allocated using g_malloc().
|
||||
* This function is useful for avoiding an extra copy of allocated memory returned
|
||||
* by a non-GLib-based API.
|
||||
*
|
||||
* A different allocator can be set using g_mem_set_vtable().
|
||||
*
|
||||
* Return value: if %TRUE, malloc() and g_malloc() can be mixed.
|
||||
**/
|
||||
gboolean
|
||||
g_mem_is_system_malloc (void)
|
||||
{
|
||||
return !vtable_set;
|
||||
}
|
||||
|
||||
void
|
||||
g_mem_set_vtable (GMemVTable *vtable)
|
||||
{
|
||||
if (!vtable_set)
|
||||
{
|
||||
if (vtable->malloc && vtable->realloc && vtable->free)
|
||||
{
|
||||
glib_mem_vtable.malloc = vtable->malloc;
|
||||
glib_mem_vtable.realloc = vtable->realloc;
|
||||
glib_mem_vtable.free = vtable->free;
|
||||
glib_mem_vtable.calloc = vtable->calloc ? vtable->calloc : fallback_calloc;
|
||||
glib_mem_vtable.try_malloc = vtable->try_malloc ? vtable->try_malloc : glib_mem_vtable.malloc;
|
||||
glib_mem_vtable.try_realloc = vtable->try_realloc ? vtable->try_realloc : glib_mem_vtable.realloc;
|
||||
vtable_set = TRUE;
|
||||
}
|
||||
else
|
||||
g_warning (G_STRLOC ": memory allocation vtable lacks one of malloc(), realloc() or free()");
|
||||
}
|
||||
else
|
||||
g_warning (G_STRLOC ": memory allocation vtable can only be set once at startup");
|
||||
}
|
||||
|
||||
|
||||
/* --- memory profiling and checking --- */
|
||||
#ifdef G_DISABLE_CHECKS
|
||||
GMemVTable *glib_mem_profiler_table = &glib_mem_vtable;
|
||||
void
|
||||
g_mem_profile (void)
|
||||
{
|
||||
}
|
||||
#else /* !G_DISABLE_CHECKS */
|
||||
typedef enum {
|
||||
PROFILER_FREE = 0,
|
||||
PROFILER_ALLOC = 1,
|
||||
PROFILER_RELOC = 2,
|
||||
PROFILER_ZINIT = 4
|
||||
} ProfilerJob;
|
||||
static guint *profile_data = NULL;
|
||||
static gsize profile_allocs = 0;
|
||||
static gsize profile_zinit = 0;
|
||||
static gsize profile_frees = 0;
|
||||
static GMutex *gmem_profile_mutex = NULL;
|
||||
#ifdef G_ENABLE_DEBUG
|
||||
static volatile gsize g_trap_free_size = 0;
|
||||
static volatile gsize g_trap_realloc_size = 0;
|
||||
static volatile gsize g_trap_malloc_size = 0;
|
||||
#endif /* G_ENABLE_DEBUG */
|
||||
|
||||
#define PROFILE_TABLE(f1,f2,f3) ( ( ((f3) << 2) | ((f2) << 1) | (f1) ) * (MEM_PROFILE_TABLE_SIZE + 1))
|
||||
|
||||
static void
|
||||
profiler_log (ProfilerJob job,
|
||||
gsize n_bytes,
|
||||
gboolean success)
|
||||
{
|
||||
g_mutex_lock (gmem_profile_mutex);
|
||||
if (!profile_data)
|
||||
{
|
||||
profile_data = standard_calloc ((MEM_PROFILE_TABLE_SIZE + 1) * 8,
|
||||
sizeof (profile_data[0]));
|
||||
if (!profile_data) /* memory system kiddin' me, eh? */
|
||||
{
|
||||
g_mutex_unlock (gmem_profile_mutex);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (n_bytes < MEM_PROFILE_TABLE_SIZE)
|
||||
profile_data[n_bytes + PROFILE_TABLE ((job & PROFILER_ALLOC) != 0,
|
||||
(job & PROFILER_RELOC) != 0,
|
||||
success != 0)] += 1;
|
||||
else
|
||||
profile_data[MEM_PROFILE_TABLE_SIZE + PROFILE_TABLE ((job & PROFILER_ALLOC) != 0,
|
||||
(job & PROFILER_RELOC) != 0,
|
||||
success != 0)] += 1;
|
||||
if (success)
|
||||
{
|
||||
if (job & PROFILER_ALLOC)
|
||||
{
|
||||
profile_allocs += n_bytes;
|
||||
if (job & PROFILER_ZINIT)
|
||||
profile_zinit += n_bytes;
|
||||
}
|
||||
else
|
||||
profile_frees += n_bytes;
|
||||
}
|
||||
g_mutex_unlock (gmem_profile_mutex);
|
||||
}
|
||||
|
||||
static void
|
||||
profile_print_locked (guint *local_data,
|
||||
gboolean success)
|
||||
{
|
||||
gboolean need_header = TRUE;
|
||||
guint i;
|
||||
|
||||
for (i = 0; i <= MEM_PROFILE_TABLE_SIZE; i++)
|
||||
{
|
||||
glong t_malloc = local_data[i + PROFILE_TABLE (1, 0, success)];
|
||||
glong t_realloc = local_data[i + PROFILE_TABLE (1, 1, success)];
|
||||
glong t_free = local_data[i + PROFILE_TABLE (0, 0, success)];
|
||||
glong t_refree = local_data[i + PROFILE_TABLE (0, 1, success)];
|
||||
|
||||
if (!t_malloc && !t_realloc && !t_free && !t_refree)
|
||||
continue;
|
||||
else if (need_header)
|
||||
{
|
||||
need_header = FALSE;
|
||||
g_print (" blocks of | allocated | freed | allocated | freed | n_bytes \n");
|
||||
g_print (" n_bytes | n_times by | n_times by | n_times by | n_times by | remaining \n");
|
||||
g_print (" | malloc() | free() | realloc() | realloc() | \n");
|
||||
g_print ("===========|============|============|============|============|===========\n");
|
||||
}
|
||||
if (i < MEM_PROFILE_TABLE_SIZE)
|
||||
g_print ("%10u | %10ld | %10ld | %10ld | %10ld |%+11ld\n",
|
||||
i, t_malloc, t_free, t_realloc, t_refree,
|
||||
(t_malloc - t_free + t_realloc - t_refree) * i);
|
||||
else if (i >= MEM_PROFILE_TABLE_SIZE)
|
||||
g_print (" >%6u | %10ld | %10ld | %10ld | %10ld | ***\n",
|
||||
i, t_malloc, t_free, t_realloc, t_refree);
|
||||
}
|
||||
if (need_header)
|
||||
g_print (" --- none ---\n");
|
||||
}
|
||||
|
||||
void
|
||||
g_mem_profile (void)
|
||||
{
|
||||
guint local_data[(MEM_PROFILE_TABLE_SIZE + 1) * 8 * sizeof (profile_data[0])];
|
||||
gsize local_allocs;
|
||||
gsize local_zinit;
|
||||
gsize local_frees;
|
||||
|
||||
if (G_UNLIKELY (!g_mem_initialized))
|
||||
g_mem_init_nomessage();
|
||||
|
||||
g_mutex_lock (gmem_profile_mutex);
|
||||
|
||||
local_allocs = profile_allocs;
|
||||
local_zinit = profile_zinit;
|
||||
local_frees = profile_frees;
|
||||
|
||||
if (!profile_data)
|
||||
{
|
||||
g_mutex_unlock (gmem_profile_mutex);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy (local_data, profile_data,
|
||||
(MEM_PROFILE_TABLE_SIZE + 1) * 8 * sizeof (profile_data[0]));
|
||||
|
||||
g_mutex_unlock (gmem_profile_mutex);
|
||||
|
||||
g_print ("GLib Memory statistics (successful operations):\n");
|
||||
profile_print_locked (local_data, TRUE);
|
||||
g_print ("GLib Memory statistics (failing operations):\n");
|
||||
profile_print_locked (local_data, FALSE);
|
||||
g_print ("Total bytes: allocated=%"G_GSIZE_FORMAT", "
|
||||
"zero-initialized=%"G_GSIZE_FORMAT" (%.2f%%), "
|
||||
"freed=%"G_GSIZE_FORMAT" (%.2f%%), "
|
||||
"remaining=%"G_GSIZE_FORMAT"\n",
|
||||
local_allocs,
|
||||
local_zinit,
|
||||
((gdouble) local_zinit) / local_allocs * 100.0,
|
||||
local_frees,
|
||||
((gdouble) local_frees) / local_allocs * 100.0,
|
||||
local_allocs - local_frees);
|
||||
}
|
||||
|
||||
static gpointer
|
||||
profiler_try_malloc (gsize n_bytes)
|
||||
{
|
||||
gsize *p;
|
||||
|
||||
#ifdef G_ENABLE_DEBUG
|
||||
if (g_trap_malloc_size == n_bytes)
|
||||
G_BREAKPOINT ();
|
||||
#endif /* G_ENABLE_DEBUG */
|
||||
|
||||
p = standard_malloc (sizeof (gsize) * 2 + n_bytes);
|
||||
|
||||
if (p)
|
||||
{
|
||||
p[0] = 0; /* free count */
|
||||
p[1] = n_bytes; /* length */
|
||||
profiler_log (PROFILER_ALLOC, n_bytes, TRUE);
|
||||
p += 2;
|
||||
}
|
||||
else
|
||||
profiler_log (PROFILER_ALLOC, n_bytes, FALSE);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
static gpointer
|
||||
profiler_malloc (gsize n_bytes)
|
||||
{
|
||||
gpointer mem = profiler_try_malloc (n_bytes);
|
||||
|
||||
if (!mem)
|
||||
g_mem_profile ();
|
||||
|
||||
return mem;
|
||||
}
|
||||
|
||||
static gpointer
|
||||
profiler_calloc (gsize n_blocks,
|
||||
gsize n_block_bytes)
|
||||
{
|
||||
gsize l = n_blocks * n_block_bytes;
|
||||
gsize *p;
|
||||
|
||||
#ifdef G_ENABLE_DEBUG
|
||||
if (g_trap_malloc_size == l)
|
||||
G_BREAKPOINT ();
|
||||
#endif /* G_ENABLE_DEBUG */
|
||||
|
||||
p = standard_calloc (1, sizeof (gsize) * 2 + l);
|
||||
|
||||
if (p)
|
||||
{
|
||||
p[0] = 0; /* free count */
|
||||
p[1] = l; /* length */
|
||||
profiler_log (PROFILER_ALLOC | PROFILER_ZINIT, l, TRUE);
|
||||
p += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
profiler_log (PROFILER_ALLOC | PROFILER_ZINIT, l, FALSE);
|
||||
g_mem_profile ();
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
static void
|
||||
profiler_free (gpointer mem)
|
||||
{
|
||||
gsize *p = mem;
|
||||
|
||||
p -= 2;
|
||||
if (p[0]) /* free count */
|
||||
{
|
||||
g_warning ("free(%p): memory has been freed %"G_GSIZE_FORMAT" times already",
|
||||
p + 2, p[0]);
|
||||
profiler_log (PROFILER_FREE,
|
||||
p[1], /* length */
|
||||
FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef G_ENABLE_DEBUG
|
||||
if (g_trap_free_size == p[1])
|
||||
G_BREAKPOINT ();
|
||||
#endif /* G_ENABLE_DEBUG */
|
||||
|
||||
profiler_log (PROFILER_FREE,
|
||||
p[1], /* length */
|
||||
TRUE);
|
||||
memset (p + 2, 0xaa, p[1]);
|
||||
|
||||
/* for all those that miss standard_free (p); in this place, yes,
|
||||
* we do leak all memory when profiling, and that is intentional
|
||||
* to catch double frees. patch submissions are futile.
|
||||
*/
|
||||
}
|
||||
p[0] += 1;
|
||||
}
|
||||
|
||||
static gpointer
|
||||
profiler_try_realloc (gpointer mem,
|
||||
gsize n_bytes)
|
||||
{
|
||||
gsize *p = mem;
|
||||
|
||||
p -= 2;
|
||||
|
||||
#ifdef G_ENABLE_DEBUG
|
||||
if (g_trap_realloc_size == n_bytes)
|
||||
G_BREAKPOINT ();
|
||||
#endif /* G_ENABLE_DEBUG */
|
||||
|
||||
if (mem && p[0]) /* free count */
|
||||
{
|
||||
g_warning ("realloc(%p, %"G_GSIZE_FORMAT"): "
|
||||
"memory has been freed %"G_GSIZE_FORMAT" times already",
|
||||
p + 2, (gsize) n_bytes, p[0]);
|
||||
profiler_log (PROFILER_ALLOC | PROFILER_RELOC, n_bytes, FALSE);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
p = standard_realloc (mem ? p : NULL, sizeof (gsize) * 2 + n_bytes);
|
||||
|
||||
if (p)
|
||||
{
|
||||
if (mem)
|
||||
profiler_log (PROFILER_FREE | PROFILER_RELOC, p[1], TRUE);
|
||||
p[0] = 0;
|
||||
p[1] = n_bytes;
|
||||
profiler_log (PROFILER_ALLOC | PROFILER_RELOC, p[1], TRUE);
|
||||
p += 2;
|
||||
}
|
||||
else
|
||||
profiler_log (PROFILER_ALLOC | PROFILER_RELOC, n_bytes, FALSE);
|
||||
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
static gpointer
|
||||
profiler_realloc (gpointer mem,
|
||||
gsize n_bytes)
|
||||
{
|
||||
mem = profiler_try_realloc (mem, n_bytes);
|
||||
|
||||
if (!mem)
|
||||
g_mem_profile ();
|
||||
|
||||
return mem;
|
||||
}
|
||||
|
||||
static GMemVTable profiler_table = {
|
||||
profiler_malloc,
|
||||
profiler_realloc,
|
||||
profiler_free,
|
||||
profiler_calloc,
|
||||
profiler_try_malloc,
|
||||
profiler_try_realloc,
|
||||
};
|
||||
GMemVTable *glib_mem_profiler_table = &profiler_table;
|
||||
|
||||
#endif /* !G_DISABLE_CHECKS */
|
||||
|
||||
/* --- MemChunks --- */
|
||||
#ifndef G_ALLOC_AND_FREE
|
||||
typedef struct _GAllocator GAllocator;
|
||||
typedef struct _GMemChunk GMemChunk;
|
||||
#define G_ALLOC_ONLY 1
|
||||
#define G_ALLOC_AND_FREE 2
|
||||
#endif
|
||||
|
||||
struct _GMemChunk {
|
||||
guint alloc_size; /* the size of an atom */
|
||||
};
|
||||
|
||||
GMemChunk*
|
||||
g_mem_chunk_new (const gchar *name,
|
||||
gint atom_size,
|
||||
gsize area_size,
|
||||
gint type)
|
||||
{
|
||||
GMemChunk *mem_chunk;
|
||||
g_return_val_if_fail (atom_size > 0, NULL);
|
||||
|
||||
mem_chunk = g_slice_new (GMemChunk);
|
||||
mem_chunk->alloc_size = atom_size;
|
||||
return mem_chunk;
|
||||
}
|
||||
|
||||
void
|
||||
g_mem_chunk_destroy (GMemChunk *mem_chunk)
|
||||
{
|
||||
g_return_if_fail (mem_chunk != NULL);
|
||||
|
||||
g_slice_free (GMemChunk, mem_chunk);
|
||||
}
|
||||
|
||||
gpointer
|
||||
g_mem_chunk_alloc (GMemChunk *mem_chunk)
|
||||
{
|
||||
g_return_val_if_fail (mem_chunk != NULL, NULL);
|
||||
|
||||
return g_slice_alloc (mem_chunk->alloc_size);
|
||||
}
|
||||
|
||||
gpointer
|
||||
g_mem_chunk_alloc0 (GMemChunk *mem_chunk)
|
||||
{
|
||||
g_return_val_if_fail (mem_chunk != NULL, NULL);
|
||||
|
||||
return g_slice_alloc0 (mem_chunk->alloc_size);
|
||||
}
|
||||
|
||||
void
|
||||
g_mem_chunk_free (GMemChunk *mem_chunk,
|
||||
gpointer mem)
|
||||
{
|
||||
g_return_if_fail (mem_chunk != NULL);
|
||||
|
||||
g_slice_free1 (mem_chunk->alloc_size, mem);
|
||||
}
|
||||
|
||||
void g_mem_chunk_clean (GMemChunk *mem_chunk) {}
|
||||
void g_mem_chunk_reset (GMemChunk *mem_chunk) {}
|
||||
void g_mem_chunk_print (GMemChunk *mem_chunk) {}
|
||||
void g_mem_chunk_info (void) {}
|
||||
void g_blow_chunks (void) {}
|
||||
|
||||
GAllocator*
|
||||
g_allocator_new (const gchar *name,
|
||||
guint n_preallocs)
|
||||
{
|
||||
static struct _GAllocator {
|
||||
gchar *name;
|
||||
guint16 n_preallocs;
|
||||
guint is_unused : 1;
|
||||
guint type : 4;
|
||||
GAllocator *last;
|
||||
GMemChunk *mem_chunk;
|
||||
gpointer free_list;
|
||||
} dummy = {
|
||||
"GAllocator is deprecated", 1, TRUE, 0, NULL, NULL, NULL,
|
||||
};
|
||||
/* some (broken) GAllocator uses depend on non-NULL allocators */
|
||||
return (void*) &dummy;
|
||||
}
|
||||
|
||||
void
|
||||
g_allocator_free (GAllocator *allocator)
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef ENABLE_GC_FRIENDLY_DEFAULT
|
||||
gboolean g_mem_gc_friendly = TRUE;
|
||||
#else
|
||||
gboolean g_mem_gc_friendly = FALSE;
|
||||
#endif
|
||||
|
||||
static void
|
||||
g_mem_init_nomessage (void)
|
||||
{
|
||||
gchar buffer[1024];
|
||||
const gchar *val;
|
||||
const GDebugKey keys[] = {
|
||||
{ "gc-friendly", 1 },
|
||||
};
|
||||
gint flags;
|
||||
if (g_mem_initialized)
|
||||
return;
|
||||
/* don't use g_malloc/g_message here */
|
||||
val = _g_getenv_nomalloc ("G_DEBUG", buffer);
|
||||
flags = !val ? 0 : g_parse_debug_string (val, keys, G_N_ELEMENTS (keys));
|
||||
if (flags & 1) /* gc-friendly */
|
||||
{
|
||||
g_mem_gc_friendly = TRUE;
|
||||
}
|
||||
g_mem_initialized = TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
_g_mem_thread_init_noprivate_nomessage (void)
|
||||
{
|
||||
/* we may only create mutexes here, locking/
|
||||
* unlocking a mutex does not yet work.
|
||||
*/
|
||||
g_mem_init_nomessage();
|
||||
#ifndef G_DISABLE_CHECKS
|
||||
gmem_profile_mutex = g_mutex_new ();
|
||||
#endif
|
||||
}
|
||||
|
||||
#define __G_MEM_C__
|
||||
#include "galiasdef.c"
|
|
@ -0,0 +1,152 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
|
||||
#error "Only <glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __G_MEM_H__
|
||||
#define __G_MEM_H__
|
||||
|
||||
#include <glib/gslice.h>
|
||||
#include <glib/gtypes.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GMemVTable GMemVTable;
|
||||
|
||||
|
||||
#if GLIB_SIZEOF_VOID_P > GLIB_SIZEOF_LONG
|
||||
# define G_MEM_ALIGN GLIB_SIZEOF_VOID_P
|
||||
#else /* GLIB_SIZEOF_VOID_P <= GLIB_SIZEOF_LONG */
|
||||
# define G_MEM_ALIGN GLIB_SIZEOF_LONG
|
||||
#endif /* GLIB_SIZEOF_VOID_P <= GLIB_SIZEOF_LONG */
|
||||
|
||||
|
||||
/* Memory allocation functions
|
||||
*/
|
||||
gpointer g_malloc (gsize n_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
|
||||
gpointer g_malloc0 (gsize n_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
|
||||
gpointer g_realloc (gpointer mem,
|
||||
gsize n_bytes) G_GNUC_WARN_UNUSED_RESULT;
|
||||
void g_free (gpointer mem);
|
||||
gpointer g_try_malloc (gsize n_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
|
||||
gpointer g_try_malloc0 (gsize n_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
|
||||
gpointer g_try_realloc (gpointer mem,
|
||||
gsize n_bytes) G_GNUC_WARN_UNUSED_RESULT;
|
||||
|
||||
|
||||
/* Convenience memory allocators
|
||||
*/
|
||||
#define g_new(struct_type, n_structs) \
|
||||
((struct_type *) g_malloc (((gsize) sizeof (struct_type)) * ((gsize) (n_structs))))
|
||||
#define g_new0(struct_type, n_structs) \
|
||||
((struct_type *) g_malloc0 (((gsize) sizeof (struct_type)) * ((gsize) (n_structs))))
|
||||
#define g_renew(struct_type, mem, n_structs) \
|
||||
((struct_type *) g_realloc ((mem), ((gsize) sizeof (struct_type)) * ((gsize) (n_structs))))
|
||||
|
||||
#define g_try_new(struct_type, n_structs) \
|
||||
((struct_type *) g_try_malloc (((gsize) sizeof (struct_type)) * ((gsize) (n_structs))))
|
||||
#define g_try_new0(struct_type, n_structs) \
|
||||
((struct_type *) g_try_malloc0 (((gsize) sizeof (struct_type)) * ((gsize) (n_structs))))
|
||||
#define g_try_renew(struct_type, mem, n_structs) \
|
||||
((struct_type *) g_try_realloc ((mem), ((gsize) sizeof (struct_type)) * ((gsize) (n_structs))))
|
||||
|
||||
|
||||
/* Memory allocation virtualization for debugging purposes
|
||||
* g_mem_set_vtable() has to be the very first GLib function called
|
||||
* if being used
|
||||
*/
|
||||
struct _GMemVTable
|
||||
{
|
||||
gpointer (*malloc) (gsize n_bytes);
|
||||
gpointer (*realloc) (gpointer mem,
|
||||
gsize n_bytes);
|
||||
void (*free) (gpointer mem);
|
||||
/* optional; set to NULL if not used ! */
|
||||
gpointer (*calloc) (gsize n_blocks,
|
||||
gsize n_block_bytes);
|
||||
gpointer (*try_malloc) (gsize n_bytes);
|
||||
gpointer (*try_realloc) (gpointer mem,
|
||||
gsize n_bytes);
|
||||
};
|
||||
void g_mem_set_vtable (GMemVTable *vtable);
|
||||
gboolean g_mem_is_system_malloc (void);
|
||||
|
||||
GLIB_VAR gboolean g_mem_gc_friendly;
|
||||
|
||||
/* Memory profiler and checker, has to be enabled via g_mem_set_vtable()
|
||||
*/
|
||||
GLIB_VAR GMemVTable *glib_mem_profiler_table;
|
||||
void g_mem_profile (void);
|
||||
|
||||
|
||||
/* deprecated memchunks and allocators */
|
||||
#if !defined (G_DISABLE_DEPRECATED) || defined (GTK_COMPILATION) || defined (GDK_COMPILATION)
|
||||
typedef struct _GAllocator GAllocator;
|
||||
typedef struct _GMemChunk GMemChunk;
|
||||
#define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \
|
||||
g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \
|
||||
sizeof (type), \
|
||||
sizeof (type) * (pre_alloc), \
|
||||
(alloc_type)) \
|
||||
)
|
||||
#define g_chunk_new(type, chunk) ( \
|
||||
(type *) g_mem_chunk_alloc (chunk) \
|
||||
)
|
||||
#define g_chunk_new0(type, chunk) ( \
|
||||
(type *) g_mem_chunk_alloc0 (chunk) \
|
||||
)
|
||||
#define g_chunk_free(mem, mem_chunk) G_STMT_START { \
|
||||
g_mem_chunk_free ((mem_chunk), (mem)); \
|
||||
} G_STMT_END
|
||||
#define G_ALLOC_ONLY 1
|
||||
#define G_ALLOC_AND_FREE 2
|
||||
GMemChunk* g_mem_chunk_new (const gchar *name,
|
||||
gint atom_size,
|
||||
gsize area_size,
|
||||
gint type);
|
||||
void g_mem_chunk_destroy (GMemChunk *mem_chunk);
|
||||
gpointer g_mem_chunk_alloc (GMemChunk *mem_chunk);
|
||||
gpointer g_mem_chunk_alloc0 (GMemChunk *mem_chunk);
|
||||
void g_mem_chunk_free (GMemChunk *mem_chunk,
|
||||
gpointer mem);
|
||||
void g_mem_chunk_clean (GMemChunk *mem_chunk);
|
||||
void g_mem_chunk_reset (GMemChunk *mem_chunk);
|
||||
void g_mem_chunk_print (GMemChunk *mem_chunk);
|
||||
void g_mem_chunk_info (void);
|
||||
void g_blow_chunks (void);
|
||||
GAllocator*g_allocator_new (const gchar *name,
|
||||
guint n_preallocs);
|
||||
void g_allocator_free (GAllocator *allocator);
|
||||
#define G_ALLOCATOR_LIST (1)
|
||||
#define G_ALLOCATOR_SLIST (2)
|
||||
#define G_ALLOCATOR_NODE (3)
|
||||
#endif /* G_DISABLE_DEPRECATED */
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_MEM_H__ */
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,341 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
|
||||
#error "Only <glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __G_MESSAGES_H__
|
||||
#define __G_MESSAGES_H__
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <glib/gtypes.h>
|
||||
#include <glib/gmacros.h>
|
||||
|
||||
/* Suppress warnings when GCC is in -pedantic mode and not -std=c99
|
||||
*/
|
||||
#if (__GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96))
|
||||
#pragma GCC system_header
|
||||
#endif
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/* calculate a string size, guaranteed to fit format + args.
|
||||
*/
|
||||
gsize g_printf_string_upper_bound (const gchar* format,
|
||||
va_list args);
|
||||
|
||||
/* Log level shift offset for user defined
|
||||
* log levels (0-7 are used by GLib).
|
||||
*/
|
||||
#define G_LOG_LEVEL_USER_SHIFT (8)
|
||||
|
||||
/* Glib log levels and flags.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/* log flags */
|
||||
G_LOG_FLAG_RECURSION = 1 << 0,
|
||||
G_LOG_FLAG_FATAL = 1 << 1,
|
||||
|
||||
/* GLib log levels */
|
||||
G_LOG_LEVEL_ERROR = 1 << 2, /* always fatal */
|
||||
G_LOG_LEVEL_CRITICAL = 1 << 3,
|
||||
G_LOG_LEVEL_WARNING = 1 << 4,
|
||||
G_LOG_LEVEL_MESSAGE = 1 << 5,
|
||||
G_LOG_LEVEL_INFO = 1 << 6,
|
||||
G_LOG_LEVEL_DEBUG = 1 << 7,
|
||||
|
||||
G_LOG_LEVEL_MASK = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL)
|
||||
} GLogLevelFlags;
|
||||
|
||||
/* GLib log levels that are considered fatal by default */
|
||||
#define G_LOG_FATAL_MASK (G_LOG_FLAG_RECURSION | G_LOG_LEVEL_ERROR)
|
||||
|
||||
typedef void (*GLogFunc) (const gchar *log_domain,
|
||||
GLogLevelFlags log_level,
|
||||
const gchar *message,
|
||||
gpointer user_data);
|
||||
|
||||
/* Logging mechanism
|
||||
*/
|
||||
guint g_log_set_handler (const gchar *log_domain,
|
||||
GLogLevelFlags log_levels,
|
||||
GLogFunc log_func,
|
||||
gpointer user_data);
|
||||
void g_log_remove_handler (const gchar *log_domain,
|
||||
guint handler_id);
|
||||
void g_log_default_handler (const gchar *log_domain,
|
||||
GLogLevelFlags log_level,
|
||||
const gchar *message,
|
||||
gpointer unused_data);
|
||||
GLogFunc g_log_set_default_handler (GLogFunc log_func,
|
||||
gpointer user_data);
|
||||
void g_log (const gchar *log_domain,
|
||||
GLogLevelFlags log_level,
|
||||
const gchar *format,
|
||||
...) G_GNUC_PRINTF (3, 4);
|
||||
void g_logv (const gchar *log_domain,
|
||||
GLogLevelFlags log_level,
|
||||
const gchar *format,
|
||||
va_list args);
|
||||
GLogLevelFlags g_log_set_fatal_mask (const gchar *log_domain,
|
||||
GLogLevelFlags fatal_mask);
|
||||
GLogLevelFlags g_log_set_always_fatal (GLogLevelFlags fatal_mask);
|
||||
|
||||
/* internal */
|
||||
G_GNUC_INTERNAL void _g_log_fallback_handler (const gchar *log_domain,
|
||||
GLogLevelFlags log_level,
|
||||
const gchar *message,
|
||||
gpointer unused_data);
|
||||
|
||||
/* Internal functions, used to implement the following macros */
|
||||
void g_return_if_fail_warning (const char *log_domain,
|
||||
const char *pretty_function,
|
||||
const char *expression);
|
||||
void g_warn_message (const char *domain,
|
||||
const char *file,
|
||||
int line,
|
||||
const char *func,
|
||||
const char *warnexpr);
|
||||
#ifndef G_DISABLE_DEPRECATED
|
||||
void g_assert_warning (const char *log_domain,
|
||||
const char *file,
|
||||
const int line,
|
||||
const char *pretty_function,
|
||||
const char *expression) G_GNUC_NORETURN;
|
||||
#endif /* !G_DISABLE_DEPRECATED */
|
||||
|
||||
|
||||
#ifndef G_LOG_DOMAIN
|
||||
#define G_LOG_DOMAIN ((gchar*) 0)
|
||||
#endif /* G_LOG_DOMAIN */
|
||||
#ifdef G_HAVE_ISO_VARARGS
|
||||
/* for(;;); so that GCC knows that control doesn't go past g_error() */
|
||||
#define g_error(...) G_STMT_START { \
|
||||
g_log (G_LOG_DOMAIN, \
|
||||
G_LOG_LEVEL_ERROR, \
|
||||
__VA_ARGS__); \
|
||||
for (;;); \
|
||||
} G_STMT_END
|
||||
|
||||
#define g_message(...) g_log (G_LOG_DOMAIN, \
|
||||
G_LOG_LEVEL_MESSAGE, \
|
||||
__VA_ARGS__)
|
||||
#define g_critical(...) g_log (G_LOG_DOMAIN, \
|
||||
G_LOG_LEVEL_CRITICAL, \
|
||||
__VA_ARGS__)
|
||||
#define g_warning(...) g_log (G_LOG_DOMAIN, \
|
||||
G_LOG_LEVEL_WARNING, \
|
||||
__VA_ARGS__)
|
||||
#define g_debug(...) g_log (G_LOG_DOMAIN, \
|
||||
G_LOG_LEVEL_DEBUG, \
|
||||
__VA_ARGS__)
|
||||
#elif defined(G_HAVE_GNUC_VARARGS)
|
||||
#define g_error(format...) G_STMT_START { \
|
||||
g_log (G_LOG_DOMAIN, \
|
||||
G_LOG_LEVEL_ERROR, \
|
||||
format); \
|
||||
for (;;); \
|
||||
} G_STMT_END
|
||||
|
||||
#define g_message(format...) g_log (G_LOG_DOMAIN, \
|
||||
G_LOG_LEVEL_MESSAGE, \
|
||||
format)
|
||||
#define g_critical(format...) g_log (G_LOG_DOMAIN, \
|
||||
G_LOG_LEVEL_CRITICAL, \
|
||||
format)
|
||||
#define g_warning(format...) g_log (G_LOG_DOMAIN, \
|
||||
G_LOG_LEVEL_WARNING, \
|
||||
format)
|
||||
#define g_debug(format...) g_log (G_LOG_DOMAIN, \
|
||||
G_LOG_LEVEL_DEBUG, \
|
||||
format)
|
||||
#else /* no varargs macros */
|
||||
static void
|
||||
g_error (const gchar *format,
|
||||
...)
|
||||
{
|
||||
va_list args;
|
||||
va_start (args, format);
|
||||
g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, args);
|
||||
va_end (args);
|
||||
|
||||
for(;;);
|
||||
}
|
||||
static void
|
||||
g_message (const gchar *format,
|
||||
...)
|
||||
{
|
||||
va_list args;
|
||||
va_start (args, format);
|
||||
g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format, args);
|
||||
va_end (args);
|
||||
}
|
||||
static void
|
||||
g_critical (const gchar *format,
|
||||
...)
|
||||
{
|
||||
va_list args;
|
||||
va_start (args, format);
|
||||
g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, format, args);
|
||||
va_end (args);
|
||||
}
|
||||
static void
|
||||
g_warning (const gchar *format,
|
||||
...)
|
||||
{
|
||||
va_list args;
|
||||
va_start (args, format);
|
||||
g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, args);
|
||||
va_end (args);
|
||||
}
|
||||
static void
|
||||
g_debug (const gchar *format,
|
||||
...)
|
||||
{
|
||||
va_list args;
|
||||
va_start (args, format);
|
||||
g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format, args);
|
||||
va_end (args);
|
||||
}
|
||||
#endif /* !__GNUC__ */
|
||||
|
||||
typedef void (*GPrintFunc) (const gchar *string);
|
||||
void g_print (const gchar *format,
|
||||
...) G_GNUC_PRINTF (1, 2);
|
||||
GPrintFunc g_set_print_handler (GPrintFunc func);
|
||||
void g_printerr (const gchar *format,
|
||||
...) G_GNUC_PRINTF (1, 2);
|
||||
GPrintFunc g_set_printerr_handler (GPrintFunc func);
|
||||
|
||||
|
||||
/* Provide macros for graceful error handling.
|
||||
* The "return" macros will return from the current function.
|
||||
* Two different definitions are given for the macros in
|
||||
* order to support gcc's __PRETTY_FUNCTION__ capability.
|
||||
*/
|
||||
|
||||
#define g_warn_if_reached() do { g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, NULL); } while (0)
|
||||
#define g_warn_if_fail(expr) do { if G_LIKELY (expr) ; else \
|
||||
g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, #expr); } while (0)
|
||||
|
||||
#ifdef G_DISABLE_CHECKS
|
||||
|
||||
#define g_return_if_fail(expr) G_STMT_START{ (void)0; }G_STMT_END
|
||||
#define g_return_val_if_fail(expr,val) G_STMT_START{ (void)0; }G_STMT_END
|
||||
#define g_return_if_reached() G_STMT_START{ return; }G_STMT_END
|
||||
#define g_return_val_if_reached(val) G_STMT_START{ return (val); }G_STMT_END
|
||||
|
||||
#else /* !G_DISABLE_CHECKS */
|
||||
|
||||
#ifdef __GNUC__
|
||||
|
||||
#define g_return_if_fail(expr) G_STMT_START{ \
|
||||
if G_LIKELY(expr) { } else \
|
||||
{ \
|
||||
g_return_if_fail_warning (G_LOG_DOMAIN, \
|
||||
__PRETTY_FUNCTION__, \
|
||||
#expr); \
|
||||
return; \
|
||||
}; }G_STMT_END
|
||||
|
||||
#define g_return_val_if_fail(expr,val) G_STMT_START{ \
|
||||
if G_LIKELY(expr) { } else \
|
||||
{ \
|
||||
g_return_if_fail_warning (G_LOG_DOMAIN, \
|
||||
__PRETTY_FUNCTION__, \
|
||||
#expr); \
|
||||
return (val); \
|
||||
}; }G_STMT_END
|
||||
|
||||
#define g_return_if_reached() G_STMT_START{ \
|
||||
g_log (G_LOG_DOMAIN, \
|
||||
G_LOG_LEVEL_CRITICAL, \
|
||||
"file %s: line %d (%s): should not be reached", \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
__PRETTY_FUNCTION__); \
|
||||
return; }G_STMT_END
|
||||
|
||||
#define g_return_val_if_reached(val) G_STMT_START{ \
|
||||
g_log (G_LOG_DOMAIN, \
|
||||
G_LOG_LEVEL_CRITICAL, \
|
||||
"file %s: line %d (%s): should not be reached", \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
__PRETTY_FUNCTION__); \
|
||||
return (val); }G_STMT_END
|
||||
|
||||
#else /* !__GNUC__ */
|
||||
|
||||
#define g_return_if_fail(expr) G_STMT_START{ \
|
||||
if (expr) { } else \
|
||||
{ \
|
||||
g_log (G_LOG_DOMAIN, \
|
||||
G_LOG_LEVEL_CRITICAL, \
|
||||
"file %s: line %d: assertion `%s' failed", \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
#expr); \
|
||||
return; \
|
||||
}; }G_STMT_END
|
||||
|
||||
#define g_return_val_if_fail(expr, val) G_STMT_START{ \
|
||||
if (expr) { } else \
|
||||
{ \
|
||||
g_log (G_LOG_DOMAIN, \
|
||||
G_LOG_LEVEL_CRITICAL, \
|
||||
"file %s: line %d: assertion `%s' failed", \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
#expr); \
|
||||
return (val); \
|
||||
}; }G_STMT_END
|
||||
|
||||
#define g_return_if_reached() G_STMT_START{ \
|
||||
g_log (G_LOG_DOMAIN, \
|
||||
G_LOG_LEVEL_CRITICAL, \
|
||||
"file %s: line %d: should not be reached", \
|
||||
__FILE__, \
|
||||
__LINE__); \
|
||||
return; }G_STMT_END
|
||||
|
||||
#define g_return_val_if_reached(val) G_STMT_START{ \
|
||||
g_log (G_LOG_DOMAIN, \
|
||||
G_LOG_LEVEL_CRITICAL, \
|
||||
"file %s: line %d: should not be reached", \
|
||||
__FILE__, \
|
||||
__LINE__); \
|
||||
return (val); }G_STMT_END
|
||||
|
||||
#endif /* !__GNUC__ */
|
||||
|
||||
#endif /* !G_DISABLE_CHECKS */
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_MESSAGES_H__ */
|
|
@ -0,0 +1,901 @@
|
|||
/* gmirroringtable.h
|
||||
* generated by gen-mirroring-tab
|
||||
* from the file BidiMirroring.txt of */
|
||||
|
||||
#define PACKTAB_UINT8 guint8
|
||||
#define PACKTAB_UINT16 guint16
|
||||
#define PACKTAB_UINT32 guint32
|
||||
|
||||
/*
|
||||
generated by packtab.c version 3
|
||||
|
||||
use GLIB_GET_MIRRORING_DELTA(key) to access your table
|
||||
|
||||
assumed sizeof(gint16): 2
|
||||
required memory: 1008
|
||||
lookups: 4
|
||||
partition shape: Mir[256][16][4][4]
|
||||
different table entries: 1 14 56 38
|
||||
*/
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
|
||||
static const gint16 MirLev3[4*38] = {
|
||||
#define MirLev3_0000 0x0
|
||||
0,0,0,0,
|
||||
#define MirLev3_0028 0x4
|
||||
1,-1,0,0,
|
||||
#define MirLev3_003C 0x8
|
||||
2,0,-2,0,
|
||||
#define MirLev3_0058 0xC
|
||||
0,0,0,2,
|
||||
#define MirLev3_005C 0x10
|
||||
0,-2,0,0,
|
||||
#define MirLev3_00A8 0x14
|
||||
0,0,0,16,
|
||||
#define MirLev3_00B8 0x18
|
||||
0,0,0,-16,
|
||||
#define MirLev3_0F38 0x1C
|
||||
0,0,1,-1,
|
||||
#define MirLev3_1698 0x20
|
||||
0,0,0,1,
|
||||
#define MirLev3_169C 0x24
|
||||
-1,0,0,0,
|
||||
#define MirLev3_2038 0x28
|
||||
0,1,-1,0,
|
||||
#define MirLev3_2208 0x2C
|
||||
3,3,3,-3,
|
||||
#define MirLev3_220C 0x30
|
||||
-3,-3,0,0,
|
||||
#define MirLev3_2214 0x34
|
||||
0,2016,0,0,
|
||||
#define MirLev3_2240 0x38
|
||||
0,0,0,138,
|
||||
#define MirLev3_2264 0x3C
|
||||
1,-1,1,-1,
|
||||
#define MirLev3_2290 0x40
|
||||
-1,1,-1,0,
|
||||
#define MirLev3_2298 0x44
|
||||
1824,0,0,0,
|
||||
#define MirLev3_22A4 0x48
|
||||
0,0,2104,0,
|
||||
#define MirLev3_22A8 0x4C
|
||||
2108,2106,0,2106,
|
||||
#define MirLev3_22C8 0x50
|
||||
0,1,-1,1,
|
||||
#define MirLev3_22CC 0x54
|
||||
-1,-138,0,0,
|
||||
#define MirLev3_22F0 0x58
|
||||
1,-1,8,8,
|
||||
#define MirLev3_22F4 0x5C
|
||||
8,0,7,7,
|
||||
#define MirLev3_22F8 0x60
|
||||
0,0,-8,-8,
|
||||
#define MirLev3_22FC 0x64
|
||||
-8,-7,-7,0,
|
||||
#define MirLev3_2984 0x68
|
||||
-1,1,-1,1,
|
||||
#define MirLev3_298C 0x6C
|
||||
-1,3,1,-1,
|
||||
#define MirLev3_2990 0x70
|
||||
-3,1,-1,1,
|
||||
#define MirLev3_29B8 0x74
|
||||
-1824,0,0,0,
|
||||
#define MirLev3_29F4 0x78
|
||||
0,-2016,0,0,
|
||||
#define MirLev3_2AAC 0x7C
|
||||
1,-1,0,1,
|
||||
#define MirLev3_2AB0 0x80
|
||||
-1,0,0,1,
|
||||
#define MirLev3_2ADC 0x84
|
||||
0,0,-2104,0,
|
||||
#define MirLev3_2AE0 0x88
|
||||
0,0,0,-2106,
|
||||
#define MirLev3_2AE4 0x8C
|
||||
-2108,-2106,0,0,
|
||||
#define MirLev3_FF5C 0x90
|
||||
0,-2,0,1,
|
||||
#define MirLev3_FF60 0x94
|
||||
-1,0,1,-1,
|
||||
};
|
||||
|
||||
static const PACKTAB_UINT8 MirLev2[4*56] = {
|
||||
#define MirLev2_0000 0x0
|
||||
MirLev3_0000, /* 0000..0003 */
|
||||
MirLev3_0000, /* 0004..0007 */
|
||||
MirLev3_0000, /* 0008..000B */
|
||||
MirLev3_0000, /* 000C..000F */
|
||||
#define MirLev2_0020 0x4
|
||||
MirLev3_0000, /* 0020..0023 */
|
||||
MirLev3_0000, /* 0024..0027 */
|
||||
MirLev3_0028, /* 0028..002B */
|
||||
MirLev3_0000, /* 002C..002F */
|
||||
#define MirLev2_0030 0x8
|
||||
MirLev3_0000, /* 0030..0033 */
|
||||
MirLev3_0000, /* 0034..0037 */
|
||||
MirLev3_0000, /* 0038..003B */
|
||||
MirLev3_003C, /* 003C..003F */
|
||||
#define MirLev2_0050 0xC
|
||||
MirLev3_0000, /* 0050..0053 */
|
||||
MirLev3_0000, /* 0054..0057 */
|
||||
MirLev3_0058, /* 0058..005B */
|
||||
MirLev3_005C, /* 005C..005F */
|
||||
#define MirLev2_00A0 0x10
|
||||
MirLev3_0000, /* 00A0..00A3 */
|
||||
MirLev3_0000, /* 00A4..00A7 */
|
||||
MirLev3_00A8, /* 00A8..00AB */
|
||||
MirLev3_0000, /* 00AC..00AF */
|
||||
#define MirLev2_00B0 0x14
|
||||
MirLev3_0000, /* 00B0..00B3 */
|
||||
MirLev3_0000, /* 00B4..00B7 */
|
||||
MirLev3_00B8, /* 00B8..00BB */
|
||||
MirLev3_0000, /* 00BC..00BF */
|
||||
#define MirLev2_0F30 0x18
|
||||
MirLev3_0000, /* 0F30..0F33 */
|
||||
MirLev3_0000, /* 0F34..0F37 */
|
||||
MirLev3_0F38, /* 0F38..0F3B */
|
||||
MirLev3_0028, /* 0F3C..0F3F */
|
||||
#define MirLev2_1690 0x1C
|
||||
MirLev3_0000, /* 1690..1693 */
|
||||
MirLev3_0000, /* 1694..1697 */
|
||||
MirLev3_1698, /* 1698..169B */
|
||||
MirLev3_169C, /* 169C..169F */
|
||||
#define MirLev2_2030 0x20
|
||||
MirLev3_0000, /* 2030..2033 */
|
||||
MirLev3_0000, /* 2034..2037 */
|
||||
MirLev3_2038, /* 2038..203B */
|
||||
MirLev3_0000, /* 203C..203F */
|
||||
#define MirLev2_2040 0x24
|
||||
MirLev3_0000, /* 2040..2043 */
|
||||
MirLev3_2038, /* 2044..2047 */
|
||||
MirLev3_0000, /* 2048..204B */
|
||||
MirLev3_0000, /* 204C..204F */
|
||||
#define MirLev2_2070 0x28
|
||||
MirLev3_0000, /* 2070..2073 */
|
||||
MirLev3_0000, /* 2074..2077 */
|
||||
MirLev3_0000, /* 2078..207B */
|
||||
MirLev3_2038, /* 207C..207F */
|
||||
#define MirLev2_2200 0x2C
|
||||
MirLev3_0000, /* 2200..2203 */
|
||||
MirLev3_0000, /* 2204..2207 */
|
||||
MirLev3_2208, /* 2208..220B */
|
||||
MirLev3_220C, /* 220C..220F */
|
||||
#define MirLev2_2210 0x30
|
||||
MirLev3_0000, /* 2210..2213 */
|
||||
MirLev3_2214, /* 2214..2217 */
|
||||
MirLev3_0000, /* 2218..221B */
|
||||
MirLev3_0000, /* 221C..221F */
|
||||
#define MirLev2_2230 0x34
|
||||
MirLev3_0000, /* 2230..2233 */
|
||||
MirLev3_0000, /* 2234..2237 */
|
||||
MirLev3_0000, /* 2238..223B */
|
||||
MirLev3_0028, /* 223C..223F */
|
||||
#define MirLev2_2240 0x38
|
||||
MirLev3_2240, /* 2240..2243 */
|
||||
MirLev3_0000, /* 2244..2247 */
|
||||
MirLev3_0000, /* 2248..224B */
|
||||
MirLev3_0000, /* 224C..224F */
|
||||
#define MirLev2_2250 0x3C
|
||||
MirLev3_0F38, /* 2250..2253 */
|
||||
MirLev3_0028, /* 2254..2257 */
|
||||
MirLev3_0000, /* 2258..225B */
|
||||
MirLev3_0000, /* 225C..225F */
|
||||
#define MirLev2_2260 0x40
|
||||
MirLev3_0000, /* 2260..2263 */
|
||||
MirLev3_2264, /* 2264..2267 */
|
||||
MirLev3_2264, /* 2268..226B */
|
||||
MirLev3_0F38, /* 226C..226F */
|
||||
#define MirLev2_2270 0x44
|
||||
MirLev3_2264, /* 2270..2273 */
|
||||
MirLev3_2264, /* 2274..2277 */
|
||||
MirLev3_2264, /* 2278..227B */
|
||||
MirLev3_2264, /* 227C..227F */
|
||||
#define MirLev2_2280 0x48
|
||||
MirLev3_2264, /* 2280..2283 */
|
||||
MirLev3_2264, /* 2284..2287 */
|
||||
MirLev3_2264, /* 2288..228B */
|
||||
MirLev3_1698, /* 228C..228F */
|
||||
#define MirLev2_2290 0x4C
|
||||
MirLev3_2290, /* 2290..2293 */
|
||||
MirLev3_0000, /* 2294..2297 */
|
||||
MirLev3_2298, /* 2298..229B */
|
||||
MirLev3_0000, /* 229C..229F */
|
||||
#define MirLev2_22A0 0x50
|
||||
MirLev3_0F38, /* 22A0..22A3 */
|
||||
MirLev3_22A4, /* 22A4..22A7 */
|
||||
MirLev3_22A8, /* 22A8..22AB */
|
||||
MirLev3_0000, /* 22AC..22AF */
|
||||
#define MirLev2_22B0 0x54
|
||||
MirLev3_2264, /* 22B0..22B3 */
|
||||
MirLev3_2264, /* 22B4..22B7 */
|
||||
MirLev3_0000, /* 22B8..22BB */
|
||||
MirLev3_0000, /* 22BC..22BF */
|
||||
#define MirLev2_22C0 0x58
|
||||
MirLev3_0000, /* 22C0..22C3 */
|
||||
MirLev3_0000, /* 22C4..22C7 */
|
||||
MirLev3_22C8, /* 22C8..22CB */
|
||||
MirLev3_22CC, /* 22CC..22CF */
|
||||
#define MirLev2_22D0 0x5C
|
||||
MirLev3_0028, /* 22D0..22D3 */
|
||||
MirLev3_0F38, /* 22D4..22D7 */
|
||||
MirLev3_2264, /* 22D8..22DB */
|
||||
MirLev3_2264, /* 22DC..22DF */
|
||||
#define MirLev2_22E0 0x60
|
||||
MirLev3_2264, /* 22E0..22E3 */
|
||||
MirLev3_2264, /* 22E4..22E7 */
|
||||
MirLev3_2264, /* 22E8..22EB */
|
||||
MirLev3_0028, /* 22EC..22EF */
|
||||
#define MirLev2_22F0 0x64
|
||||
MirLev3_22F0, /* 22F0..22F3 */
|
||||
MirLev3_22F4, /* 22F4..22F7 */
|
||||
MirLev3_22F8, /* 22F8..22FB */
|
||||
MirLev3_22FC, /* 22FC..22FF */
|
||||
#define MirLev2_2300 0x68
|
||||
MirLev3_0000, /* 2300..2303 */
|
||||
MirLev3_0000, /* 2304..2307 */
|
||||
MirLev3_2264, /* 2308..230B */
|
||||
MirLev3_0000, /* 230C..230F */
|
||||
#define MirLev2_2760 0x6C
|
||||
MirLev3_0000, /* 2760..2763 */
|
||||
MirLev3_0000, /* 2764..2767 */
|
||||
MirLev3_2264, /* 2768..276B */
|
||||
MirLev3_2264, /* 276C..276F */
|
||||
#define MirLev2_2770 0x70
|
||||
MirLev3_2264, /* 2770..2773 */
|
||||
MirLev3_0028, /* 2774..2777 */
|
||||
MirLev3_0000, /* 2778..277B */
|
||||
MirLev3_0000, /* 277C..277F */
|
||||
#define MirLev2_27C0 0x74
|
||||
MirLev3_1698, /* 27C0..27C3 */
|
||||
MirLev3_2290, /* 27C4..27C7 */
|
||||
MirLev3_0028, /* 27C8..27CB */
|
||||
MirLev3_0000, /* 27CC..27CF */
|
||||
#define MirLev2_27D0 0x78
|
||||
MirLev3_0000, /* 27D0..27D3 */
|
||||
MirLev3_2038, /* 27D4..27D7 */
|
||||
MirLev3_0000, /* 27D8..27DB */
|
||||
MirLev3_2038, /* 27DC..27DF */
|
||||
#define MirLev2_27E0 0x7C
|
||||
MirLev3_0F38, /* 27E0..27E3 */
|
||||
MirLev3_2264, /* 27E4..27E7 */
|
||||
MirLev3_2264, /* 27E8..27EB */
|
||||
MirLev3_2264, /* 27EC..27EF */
|
||||
#define MirLev2_2980 0x80
|
||||
MirLev3_1698, /* 2980..2983 */
|
||||
MirLev3_2984, /* 2984..2987 */
|
||||
MirLev3_2984, /* 2988..298B */
|
||||
MirLev3_298C, /* 298C..298F */
|
||||
#define MirLev2_2990 0x84
|
||||
MirLev3_2990, /* 2990..2993 */
|
||||
MirLev3_2984, /* 2994..2997 */
|
||||
MirLev3_169C, /* 2998..299B */
|
||||
MirLev3_0000, /* 299C..299F */
|
||||
#define MirLev2_29B0 0x88
|
||||
MirLev3_0000, /* 29B0..29B3 */
|
||||
MirLev3_0000, /* 29B4..29B7 */
|
||||
MirLev3_29B8, /* 29B8..29BB */
|
||||
MirLev3_0000, /* 29BC..29BF */
|
||||
#define MirLev2_29C0 0x8C
|
||||
MirLev3_0028, /* 29C0..29C3 */
|
||||
MirLev3_0028, /* 29C4..29C7 */
|
||||
MirLev3_0000, /* 29C8..29CB */
|
||||
MirLev3_1698, /* 29CC..29CF */
|
||||
#define MirLev2_29D0 0x90
|
||||
MirLev3_2290, /* 29D0..29D3 */
|
||||
MirLev3_0028, /* 29D4..29D7 */
|
||||
MirLev3_2264, /* 29D8..29DB */
|
||||
MirLev3_0000, /* 29DC..29DF */
|
||||
#define MirLev2_29F0 0x94
|
||||
MirLev3_0000, /* 29F0..29F3 */
|
||||
MirLev3_29F4, /* 29F4..29F7 */
|
||||
MirLev3_0028, /* 29F8..29FB */
|
||||
MirLev3_0028, /* 29FC..29FF */
|
||||
#define MirLev2_2A20 0x98
|
||||
MirLev3_0000, /* 2A20..2A23 */
|
||||
MirLev3_0000, /* 2A24..2A27 */
|
||||
MirLev3_1698, /* 2A28..2A2B */
|
||||
MirLev3_2290, /* 2A2C..2A2F */
|
||||
#define MirLev2_2A30 0x9C
|
||||
MirLev3_0000, /* 2A30..2A33 */
|
||||
MirLev3_0028, /* 2A34..2A37 */
|
||||
MirLev3_0000, /* 2A38..2A3B */
|
||||
MirLev3_0028, /* 2A3C..2A3F */
|
||||
#define MirLev2_2A60 0xA0
|
||||
MirLev3_0000, /* 2A60..2A63 */
|
||||
MirLev3_0028, /* 2A64..2A67 */
|
||||
MirLev3_0000, /* 2A68..2A6B */
|
||||
MirLev3_0000, /* 2A6C..2A6F */
|
||||
#define MirLev2_2A70 0xA4
|
||||
MirLev3_0000, /* 2A70..2A73 */
|
||||
MirLev3_0000, /* 2A74..2A77 */
|
||||
MirLev3_2038, /* 2A78..2A7B */
|
||||
MirLev3_22C8, /* 2A7C..2A7F */
|
||||
#define MirLev2_2A80 0xA8
|
||||
MirLev3_2984, /* 2A80..2A83 */
|
||||
MirLev3_169C, /* 2A84..2A87 */
|
||||
MirLev3_1698, /* 2A88..2A8B */
|
||||
MirLev3_169C, /* 2A8C..2A8F */
|
||||
#define MirLev2_2A90 0xAC
|
||||
MirLev3_22C8, /* 2A90..2A93 */
|
||||
MirLev3_2984, /* 2A94..2A97 */
|
||||
MirLev3_2984, /* 2A98..2A9B */
|
||||
MirLev3_169C, /* 2A9C..2A9F */
|
||||
#define MirLev2_2AA0 0xB0
|
||||
MirLev3_2038, /* 2AA0..2AA3 */
|
||||
MirLev3_0F38, /* 2AA4..2AA7 */
|
||||
MirLev3_2264, /* 2AA8..2AAB */
|
||||
MirLev3_2AAC, /* 2AAC..2AAF */
|
||||
#define MirLev2_2AB0 0xB4
|
||||
MirLev3_2AB0, /* 2AB0..2AB3 */
|
||||
MirLev3_169C, /* 2AB4..2AB7 */
|
||||
MirLev3_1698, /* 2AB8..2ABB */
|
||||
MirLev3_2984, /* 2ABC..2ABF */
|
||||
#define MirLev2_2AC0 0xB8
|
||||
MirLev3_2984, /* 2AC0..2AC3 */
|
||||
MirLev3_2290, /* 2AC4..2AC7 */
|
||||
MirLev3_0000, /* 2AC8..2ACB */
|
||||
MirLev3_22C8, /* 2ACC..2ACF */
|
||||
#define MirLev2_2AD0 0xBC
|
||||
MirLev3_2984, /* 2AD0..2AD3 */
|
||||
MirLev3_2290, /* 2AD4..2AD7 */
|
||||
MirLev3_0000, /* 2AD8..2ADB */
|
||||
MirLev3_2ADC, /* 2ADC..2ADF */
|
||||
#define MirLev2_2AE0 0xC0
|
||||
MirLev3_2AE0, /* 2AE0..2AE3 */
|
||||
MirLev3_2AE4, /* 2AE4..2AE7 */
|
||||
MirLev3_0000, /* 2AE8..2AEB */
|
||||
MirLev3_0028, /* 2AEC..2AEF */
|
||||
#define MirLev2_2AF0 0xC4
|
||||
MirLev3_0000, /* 2AF0..2AF3 */
|
||||
MirLev3_1698, /* 2AF4..2AF7 */
|
||||
MirLev3_2290, /* 2AF8..2AFB */
|
||||
MirLev3_0000, /* 2AFC..2AFF */
|
||||
#define MirLev2_2E00 0xC8
|
||||
MirLev3_0F38, /* 2E00..2E03 */
|
||||
MirLev3_0028, /* 2E04..2E07 */
|
||||
MirLev3_2038, /* 2E08..2E0B */
|
||||
MirLev3_0028, /* 2E0C..2E0F */
|
||||
#define MirLev2_2E20 0xCC
|
||||
MirLev3_2264, /* 2E20..2E23 */
|
||||
MirLev3_2264, /* 2E24..2E27 */
|
||||
MirLev3_0028, /* 2E28..2E2B */
|
||||
MirLev3_0000, /* 2E2C..2E2F */
|
||||
#define MirLev2_3010 0xD0
|
||||
MirLev3_0028, /* 3010..3013 */
|
||||
MirLev3_2264, /* 3014..3017 */
|
||||
MirLev3_2264, /* 3018..301B */
|
||||
MirLev3_0000, /* 301C..301F */
|
||||
#define MirLev2_FE50 0xD4
|
||||
MirLev3_0000, /* FE50..FE53 */
|
||||
MirLev3_0000, /* FE54..FE57 */
|
||||
MirLev3_22C8, /* FE58..FE5B */
|
||||
MirLev3_2290, /* FE5C..FE5F */
|
||||
#define MirLev2_FF50 0xD8
|
||||
MirLev3_0000, /* FF50..FF53 */
|
||||
MirLev3_0000, /* FF54..FF57 */
|
||||
MirLev3_0058, /* FF58..FF5B */
|
||||
MirLev3_FF5C, /* FF5C..FF5F */
|
||||
#define MirLev2_FF60 0xDC
|
||||
MirLev3_FF60, /* FF60..FF63 */
|
||||
MirLev3_0000, /* FF64..FF67 */
|
||||
MirLev3_0000, /* FF68..FF6B */
|
||||
MirLev3_0000, /* FF6C..FF6F */
|
||||
};
|
||||
|
||||
static const PACKTAB_UINT8 MirLev1[16*14] = {
|
||||
#define MirLev1_0000 0x0
|
||||
MirLev2_0000, /* 0000..000F */
|
||||
MirLev2_0000, /* 0010..001F */
|
||||
MirLev2_0020, /* 0020..002F */
|
||||
MirLev2_0030, /* 0030..003F */
|
||||
MirLev2_0000, /* 0040..004F */
|
||||
MirLev2_0050, /* 0050..005F */
|
||||
MirLev2_0000, /* 0060..006F */
|
||||
MirLev2_0050, /* 0070..007F */
|
||||
MirLev2_0000, /* 0080..008F */
|
||||
MirLev2_0000, /* 0090..009F */
|
||||
MirLev2_00A0, /* 00A0..00AF */
|
||||
MirLev2_00B0, /* 00B0..00BF */
|
||||
MirLev2_0000, /* 00C0..00CF */
|
||||
MirLev2_0000, /* 00D0..00DF */
|
||||
MirLev2_0000, /* 00E0..00EF */
|
||||
MirLev2_0000, /* 00F0..00FF */
|
||||
#define MirLev1_0100 0x10
|
||||
MirLev2_0000, /* 0100..010F */
|
||||
MirLev2_0000, /* 0110..011F */
|
||||
MirLev2_0000, /* 0120..012F */
|
||||
MirLev2_0000, /* 0130..013F */
|
||||
MirLev2_0000, /* 0140..014F */
|
||||
MirLev2_0000, /* 0150..015F */
|
||||
MirLev2_0000, /* 0160..016F */
|
||||
MirLev2_0000, /* 0170..017F */
|
||||
MirLev2_0000, /* 0180..018F */
|
||||
MirLev2_0000, /* 0190..019F */
|
||||
MirLev2_0000, /* 01A0..01AF */
|
||||
MirLev2_0000, /* 01B0..01BF */
|
||||
MirLev2_0000, /* 01C0..01CF */
|
||||
MirLev2_0000, /* 01D0..01DF */
|
||||
MirLev2_0000, /* 01E0..01EF */
|
||||
MirLev2_0000, /* 01F0..01FF */
|
||||
#define MirLev1_0F00 0x20
|
||||
MirLev2_0000, /* 0F00..0F0F */
|
||||
MirLev2_0000, /* 0F10..0F1F */
|
||||
MirLev2_0000, /* 0F20..0F2F */
|
||||
MirLev2_0F30, /* 0F30..0F3F */
|
||||
MirLev2_0000, /* 0F40..0F4F */
|
||||
MirLev2_0000, /* 0F50..0F5F */
|
||||
MirLev2_0000, /* 0F60..0F6F */
|
||||
MirLev2_0000, /* 0F70..0F7F */
|
||||
MirLev2_0000, /* 0F80..0F8F */
|
||||
MirLev2_0000, /* 0F90..0F9F */
|
||||
MirLev2_0000, /* 0FA0..0FAF */
|
||||
MirLev2_0000, /* 0FB0..0FBF */
|
||||
MirLev2_0000, /* 0FC0..0FCF */
|
||||
MirLev2_0000, /* 0FD0..0FDF */
|
||||
MirLev2_0000, /* 0FE0..0FEF */
|
||||
MirLev2_0000, /* 0FF0..0FFF */
|
||||
#define MirLev1_1600 0x30
|
||||
MirLev2_0000, /* 1600..160F */
|
||||
MirLev2_0000, /* 1610..161F */
|
||||
MirLev2_0000, /* 1620..162F */
|
||||
MirLev2_0000, /* 1630..163F */
|
||||
MirLev2_0000, /* 1640..164F */
|
||||
MirLev2_0000, /* 1650..165F */
|
||||
MirLev2_0000, /* 1660..166F */
|
||||
MirLev2_0000, /* 1670..167F */
|
||||
MirLev2_0000, /* 1680..168F */
|
||||
MirLev2_1690, /* 1690..169F */
|
||||
MirLev2_0000, /* 16A0..16AF */
|
||||
MirLev2_0000, /* 16B0..16BF */
|
||||
MirLev2_0000, /* 16C0..16CF */
|
||||
MirLev2_0000, /* 16D0..16DF */
|
||||
MirLev2_0000, /* 16E0..16EF */
|
||||
MirLev2_0000, /* 16F0..16FF */
|
||||
#define MirLev1_2000 0x40
|
||||
MirLev2_0000, /* 2000..200F */
|
||||
MirLev2_0000, /* 2010..201F */
|
||||
MirLev2_0000, /* 2020..202F */
|
||||
MirLev2_2030, /* 2030..203F */
|
||||
MirLev2_2040, /* 2040..204F */
|
||||
MirLev2_0000, /* 2050..205F */
|
||||
MirLev2_0000, /* 2060..206F */
|
||||
MirLev2_2070, /* 2070..207F */
|
||||
MirLev2_2070, /* 2080..208F */
|
||||
MirLev2_0000, /* 2090..209F */
|
||||
MirLev2_0000, /* 20A0..20AF */
|
||||
MirLev2_0000, /* 20B0..20BF */
|
||||
MirLev2_0000, /* 20C0..20CF */
|
||||
MirLev2_0000, /* 20D0..20DF */
|
||||
MirLev2_0000, /* 20E0..20EF */
|
||||
MirLev2_0000, /* 20F0..20FF */
|
||||
#define MirLev1_2200 0x50
|
||||
MirLev2_2200, /* 2200..220F */
|
||||
MirLev2_2210, /* 2210..221F */
|
||||
MirLev2_0000, /* 2220..222F */
|
||||
MirLev2_2230, /* 2230..223F */
|
||||
MirLev2_2240, /* 2240..224F */
|
||||
MirLev2_2250, /* 2250..225F */
|
||||
MirLev2_2260, /* 2260..226F */
|
||||
MirLev2_2270, /* 2270..227F */
|
||||
MirLev2_2280, /* 2280..228F */
|
||||
MirLev2_2290, /* 2290..229F */
|
||||
MirLev2_22A0, /* 22A0..22AF */
|
||||
MirLev2_22B0, /* 22B0..22BF */
|
||||
MirLev2_22C0, /* 22C0..22CF */
|
||||
MirLev2_22D0, /* 22D0..22DF */
|
||||
MirLev2_22E0, /* 22E0..22EF */
|
||||
MirLev2_22F0, /* 22F0..22FF */
|
||||
#define MirLev1_2300 0x60
|
||||
MirLev2_2300, /* 2300..230F */
|
||||
MirLev2_0000, /* 2310..231F */
|
||||
MirLev2_2030, /* 2320..232F */
|
||||
MirLev2_0000, /* 2330..233F */
|
||||
MirLev2_0000, /* 2340..234F */
|
||||
MirLev2_0000, /* 2350..235F */
|
||||
MirLev2_0000, /* 2360..236F */
|
||||
MirLev2_0000, /* 2370..237F */
|
||||
MirLev2_0000, /* 2380..238F */
|
||||
MirLev2_0000, /* 2390..239F */
|
||||
MirLev2_0000, /* 23A0..23AF */
|
||||
MirLev2_0000, /* 23B0..23BF */
|
||||
MirLev2_0000, /* 23C0..23CF */
|
||||
MirLev2_0000, /* 23D0..23DF */
|
||||
MirLev2_0000, /* 23E0..23EF */
|
||||
MirLev2_0000, /* 23F0..23FF */
|
||||
#define MirLev1_2700 0x70
|
||||
MirLev2_0000, /* 2700..270F */
|
||||
MirLev2_0000, /* 2710..271F */
|
||||
MirLev2_0000, /* 2720..272F */
|
||||
MirLev2_0000, /* 2730..273F */
|
||||
MirLev2_0000, /* 2740..274F */
|
||||
MirLev2_0000, /* 2750..275F */
|
||||
MirLev2_2760, /* 2760..276F */
|
||||
MirLev2_2770, /* 2770..277F */
|
||||
MirLev2_0000, /* 2780..278F */
|
||||
MirLev2_0000, /* 2790..279F */
|
||||
MirLev2_0000, /* 27A0..27AF */
|
||||
MirLev2_0000, /* 27B0..27BF */
|
||||
MirLev2_27C0, /* 27C0..27CF */
|
||||
MirLev2_27D0, /* 27D0..27DF */
|
||||
MirLev2_27E0, /* 27E0..27EF */
|
||||
MirLev2_0000, /* 27F0..27FF */
|
||||
#define MirLev1_2900 0x80
|
||||
MirLev2_0000, /* 2900..290F */
|
||||
MirLev2_0000, /* 2910..291F */
|
||||
MirLev2_0000, /* 2920..292F */
|
||||
MirLev2_0000, /* 2930..293F */
|
||||
MirLev2_0000, /* 2940..294F */
|
||||
MirLev2_0000, /* 2950..295F */
|
||||
MirLev2_0000, /* 2960..296F */
|
||||
MirLev2_0000, /* 2970..297F */
|
||||
MirLev2_2980, /* 2980..298F */
|
||||
MirLev2_2990, /* 2990..299F */
|
||||
MirLev2_0000, /* 29A0..29AF */
|
||||
MirLev2_29B0, /* 29B0..29BF */
|
||||
MirLev2_29C0, /* 29C0..29CF */
|
||||
MirLev2_29D0, /* 29D0..29DF */
|
||||
MirLev2_0000, /* 29E0..29EF */
|
||||
MirLev2_29F0, /* 29F0..29FF */
|
||||
#define MirLev1_2A00 0x90
|
||||
MirLev2_0000, /* 2A00..2A0F */
|
||||
MirLev2_0000, /* 2A10..2A1F */
|
||||
MirLev2_2A20, /* 2A20..2A2F */
|
||||
MirLev2_2A30, /* 2A30..2A3F */
|
||||
MirLev2_0000, /* 2A40..2A4F */
|
||||
MirLev2_0000, /* 2A50..2A5F */
|
||||
MirLev2_2A60, /* 2A60..2A6F */
|
||||
MirLev2_2A70, /* 2A70..2A7F */
|
||||
MirLev2_2A80, /* 2A80..2A8F */
|
||||
MirLev2_2A90, /* 2A90..2A9F */
|
||||
MirLev2_2AA0, /* 2AA0..2AAF */
|
||||
MirLev2_2AB0, /* 2AB0..2ABF */
|
||||
MirLev2_2AC0, /* 2AC0..2ACF */
|
||||
MirLev2_2AD0, /* 2AD0..2ADF */
|
||||
MirLev2_2AE0, /* 2AE0..2AEF */
|
||||
MirLev2_2AF0, /* 2AF0..2AFF */
|
||||
#define MirLev1_2E00 0xA0
|
||||
MirLev2_2E00, /* 2E00..2E0F */
|
||||
MirLev2_2230, /* 2E10..2E1F */
|
||||
MirLev2_2E20, /* 2E20..2E2F */
|
||||
MirLev2_0000, /* 2E30..2E3F */
|
||||
MirLev2_0000, /* 2E40..2E4F */
|
||||
MirLev2_0000, /* 2E50..2E5F */
|
||||
MirLev2_0000, /* 2E60..2E6F */
|
||||
MirLev2_0000, /* 2E70..2E7F */
|
||||
MirLev2_0000, /* 2E80..2E8F */
|
||||
MirLev2_0000, /* 2E90..2E9F */
|
||||
MirLev2_0000, /* 2EA0..2EAF */
|
||||
MirLev2_0000, /* 2EB0..2EBF */
|
||||
MirLev2_0000, /* 2EC0..2ECF */
|
||||
MirLev2_0000, /* 2ED0..2EDF */
|
||||
MirLev2_0000, /* 2EE0..2EEF */
|
||||
MirLev2_0000, /* 2EF0..2EFF */
|
||||
#define MirLev1_3000 0xB0
|
||||
MirLev2_2760, /* 3000..300F */
|
||||
MirLev2_3010, /* 3010..301F */
|
||||
MirLev2_0000, /* 3020..302F */
|
||||
MirLev2_0000, /* 3030..303F */
|
||||
MirLev2_0000, /* 3040..304F */
|
||||
MirLev2_0000, /* 3050..305F */
|
||||
MirLev2_0000, /* 3060..306F */
|
||||
MirLev2_0000, /* 3070..307F */
|
||||
MirLev2_0000, /* 3080..308F */
|
||||
MirLev2_0000, /* 3090..309F */
|
||||
MirLev2_0000, /* 30A0..30AF */
|
||||
MirLev2_0000, /* 30B0..30BF */
|
||||
MirLev2_0000, /* 30C0..30CF */
|
||||
MirLev2_0000, /* 30D0..30DF */
|
||||
MirLev2_0000, /* 30E0..30EF */
|
||||
MirLev2_0000, /* 30F0..30FF */
|
||||
#define MirLev1_FE00 0xC0
|
||||
MirLev2_0000, /* FE00..FE0F */
|
||||
MirLev2_0000, /* FE10..FE1F */
|
||||
MirLev2_0000, /* FE20..FE2F */
|
||||
MirLev2_0000, /* FE30..FE3F */
|
||||
MirLev2_0000, /* FE40..FE4F */
|
||||
MirLev2_FE50, /* FE50..FE5F */
|
||||
MirLev2_2A60, /* FE60..FE6F */
|
||||
MirLev2_0000, /* FE70..FE7F */
|
||||
MirLev2_0000, /* FE80..FE8F */
|
||||
MirLev2_0000, /* FE90..FE9F */
|
||||
MirLev2_0000, /* FEA0..FEAF */
|
||||
MirLev2_0000, /* FEB0..FEBF */
|
||||
MirLev2_0000, /* FEC0..FECF */
|
||||
MirLev2_0000, /* FED0..FEDF */
|
||||
MirLev2_0000, /* FEE0..FEEF */
|
||||
MirLev2_0000, /* FEF0..FEFF */
|
||||
#define MirLev1_FF00 0xD0
|
||||
MirLev2_0020, /* FF00..FF0F */
|
||||
MirLev2_0030, /* FF10..FF1F */
|
||||
MirLev2_0000, /* FF20..FF2F */
|
||||
MirLev2_0050, /* FF30..FF3F */
|
||||
MirLev2_0000, /* FF40..FF4F */
|
||||
MirLev2_FF50, /* FF50..FF5F */
|
||||
MirLev2_FF60, /* FF60..FF6F */
|
||||
MirLev2_0000, /* FF70..FF7F */
|
||||
MirLev2_0000, /* FF80..FF8F */
|
||||
MirLev2_0000, /* FF90..FF9F */
|
||||
MirLev2_0000, /* FFA0..FFAF */
|
||||
MirLev2_0000, /* FFB0..FFBF */
|
||||
MirLev2_0000, /* FFC0..FFCF */
|
||||
MirLev2_0000, /* FFD0..FFDF */
|
||||
MirLev2_0000, /* FFE0..FFEF */
|
||||
MirLev2_0000, /* FFF0..FFFF */
|
||||
};
|
||||
|
||||
static const PACKTAB_UINT8 MirLev0[256*1] = {
|
||||
#define MirLev0_0000 0x0
|
||||
MirLev1_0000, /* 0000..00FF */
|
||||
MirLev1_0100, /* 0100..01FF */
|
||||
MirLev1_0100, /* 0200..02FF */
|
||||
MirLev1_0100, /* 0300..03FF */
|
||||
MirLev1_0100, /* 0400..04FF */
|
||||
MirLev1_0100, /* 0500..05FF */
|
||||
MirLev1_0100, /* 0600..06FF */
|
||||
MirLev1_0100, /* 0700..07FF */
|
||||
MirLev1_0100, /* 0800..08FF */
|
||||
MirLev1_0100, /* 0900..09FF */
|
||||
MirLev1_0100, /* 0A00..0AFF */
|
||||
MirLev1_0100, /* 0B00..0BFF */
|
||||
MirLev1_0100, /* 0C00..0CFF */
|
||||
MirLev1_0100, /* 0D00..0DFF */
|
||||
MirLev1_0100, /* 0E00..0EFF */
|
||||
MirLev1_0F00, /* 0F00..0FFF */
|
||||
MirLev1_0100, /* 1000..10FF */
|
||||
MirLev1_0100, /* 1100..11FF */
|
||||
MirLev1_0100, /* 1200..12FF */
|
||||
MirLev1_0100, /* 1300..13FF */
|
||||
MirLev1_0100, /* 1400..14FF */
|
||||
MirLev1_0100, /* 1500..15FF */
|
||||
MirLev1_1600, /* 1600..16FF */
|
||||
MirLev1_0100, /* 1700..17FF */
|
||||
MirLev1_0100, /* 1800..18FF */
|
||||
MirLev1_0100, /* 1900..19FF */
|
||||
MirLev1_0100, /* 1A00..1AFF */
|
||||
MirLev1_0100, /* 1B00..1BFF */
|
||||
MirLev1_0100, /* 1C00..1CFF */
|
||||
MirLev1_0100, /* 1D00..1DFF */
|
||||
MirLev1_0100, /* 1E00..1EFF */
|
||||
MirLev1_0100, /* 1F00..1FFF */
|
||||
MirLev1_2000, /* 2000..20FF */
|
||||
MirLev1_0100, /* 2100..21FF */
|
||||
MirLev1_2200, /* 2200..22FF */
|
||||
MirLev1_2300, /* 2300..23FF */
|
||||
MirLev1_0100, /* 2400..24FF */
|
||||
MirLev1_0100, /* 2500..25FF */
|
||||
MirLev1_0100, /* 2600..26FF */
|
||||
MirLev1_2700, /* 2700..27FF */
|
||||
MirLev1_0100, /* 2800..28FF */
|
||||
MirLev1_2900, /* 2900..29FF */
|
||||
MirLev1_2A00, /* 2A00..2AFF */
|
||||
MirLev1_0100, /* 2B00..2BFF */
|
||||
MirLev1_0100, /* 2C00..2CFF */
|
||||
MirLev1_0100, /* 2D00..2DFF */
|
||||
MirLev1_2E00, /* 2E00..2EFF */
|
||||
MirLev1_0100, /* 2F00..2FFF */
|
||||
MirLev1_3000, /* 3000..30FF */
|
||||
MirLev1_0100, /* 3100..31FF */
|
||||
MirLev1_0100, /* 3200..32FF */
|
||||
MirLev1_0100, /* 3300..33FF */
|
||||
MirLev1_0100, /* 3400..34FF */
|
||||
MirLev1_0100, /* 3500..35FF */
|
||||
MirLev1_0100, /* 3600..36FF */
|
||||
MirLev1_0100, /* 3700..37FF */
|
||||
MirLev1_0100, /* 3800..38FF */
|
||||
MirLev1_0100, /* 3900..39FF */
|
||||
MirLev1_0100, /* 3A00..3AFF */
|
||||
MirLev1_0100, /* 3B00..3BFF */
|
||||
MirLev1_0100, /* 3C00..3CFF */
|
||||
MirLev1_0100, /* 3D00..3DFF */
|
||||
MirLev1_0100, /* 3E00..3EFF */
|
||||
MirLev1_0100, /* 3F00..3FFF */
|
||||
MirLev1_0100, /* 4000..40FF */
|
||||
MirLev1_0100, /* 4100..41FF */
|
||||
MirLev1_0100, /* 4200..42FF */
|
||||
MirLev1_0100, /* 4300..43FF */
|
||||
MirLev1_0100, /* 4400..44FF */
|
||||
MirLev1_0100, /* 4500..45FF */
|
||||
MirLev1_0100, /* 4600..46FF */
|
||||
MirLev1_0100, /* 4700..47FF */
|
||||
MirLev1_0100, /* 4800..48FF */
|
||||
MirLev1_0100, /* 4900..49FF */
|
||||
MirLev1_0100, /* 4A00..4AFF */
|
||||
MirLev1_0100, /* 4B00..4BFF */
|
||||
MirLev1_0100, /* 4C00..4CFF */
|
||||
MirLev1_0100, /* 4D00..4DFF */
|
||||
MirLev1_0100, /* 4E00..4EFF */
|
||||
MirLev1_0100, /* 4F00..4FFF */
|
||||
MirLev1_0100, /* 5000..50FF */
|
||||
MirLev1_0100, /* 5100..51FF */
|
||||
MirLev1_0100, /* 5200..52FF */
|
||||
MirLev1_0100, /* 5300..53FF */
|
||||
MirLev1_0100, /* 5400..54FF */
|
||||
MirLev1_0100, /* 5500..55FF */
|
||||
MirLev1_0100, /* 5600..56FF */
|
||||
MirLev1_0100, /* 5700..57FF */
|
||||
MirLev1_0100, /* 5800..58FF */
|
||||
MirLev1_0100, /* 5900..59FF */
|
||||
MirLev1_0100, /* 5A00..5AFF */
|
||||
MirLev1_0100, /* 5B00..5BFF */
|
||||
MirLev1_0100, /* 5C00..5CFF */
|
||||
MirLev1_0100, /* 5D00..5DFF */
|
||||
MirLev1_0100, /* 5E00..5EFF */
|
||||
MirLev1_0100, /* 5F00..5FFF */
|
||||
MirLev1_0100, /* 6000..60FF */
|
||||
MirLev1_0100, /* 6100..61FF */
|
||||
MirLev1_0100, /* 6200..62FF */
|
||||
MirLev1_0100, /* 6300..63FF */
|
||||
MirLev1_0100, /* 6400..64FF */
|
||||
MirLev1_0100, /* 6500..65FF */
|
||||
MirLev1_0100, /* 6600..66FF */
|
||||
MirLev1_0100, /* 6700..67FF */
|
||||
MirLev1_0100, /* 6800..68FF */
|
||||
MirLev1_0100, /* 6900..69FF */
|
||||
MirLev1_0100, /* 6A00..6AFF */
|
||||
MirLev1_0100, /* 6B00..6BFF */
|
||||
MirLev1_0100, /* 6C00..6CFF */
|
||||
MirLev1_0100, /* 6D00..6DFF */
|
||||
MirLev1_0100, /* 6E00..6EFF */
|
||||
MirLev1_0100, /* 6F00..6FFF */
|
||||
MirLev1_0100, /* 7000..70FF */
|
||||
MirLev1_0100, /* 7100..71FF */
|
||||
MirLev1_0100, /* 7200..72FF */
|
||||
MirLev1_0100, /* 7300..73FF */
|
||||
MirLev1_0100, /* 7400..74FF */
|
||||
MirLev1_0100, /* 7500..75FF */
|
||||
MirLev1_0100, /* 7600..76FF */
|
||||
MirLev1_0100, /* 7700..77FF */
|
||||
MirLev1_0100, /* 7800..78FF */
|
||||
MirLev1_0100, /* 7900..79FF */
|
||||
MirLev1_0100, /* 7A00..7AFF */
|
||||
MirLev1_0100, /* 7B00..7BFF */
|
||||
MirLev1_0100, /* 7C00..7CFF */
|
||||
MirLev1_0100, /* 7D00..7DFF */
|
||||
MirLev1_0100, /* 7E00..7EFF */
|
||||
MirLev1_0100, /* 7F00..7FFF */
|
||||
MirLev1_0100, /* 8000..80FF */
|
||||
MirLev1_0100, /* 8100..81FF */
|
||||
MirLev1_0100, /* 8200..82FF */
|
||||
MirLev1_0100, /* 8300..83FF */
|
||||
MirLev1_0100, /* 8400..84FF */
|
||||
MirLev1_0100, /* 8500..85FF */
|
||||
MirLev1_0100, /* 8600..86FF */
|
||||
MirLev1_0100, /* 8700..87FF */
|
||||
MirLev1_0100, /* 8800..88FF */
|
||||
MirLev1_0100, /* 8900..89FF */
|
||||
MirLev1_0100, /* 8A00..8AFF */
|
||||
MirLev1_0100, /* 8B00..8BFF */
|
||||
MirLev1_0100, /* 8C00..8CFF */
|
||||
MirLev1_0100, /* 8D00..8DFF */
|
||||
MirLev1_0100, /* 8E00..8EFF */
|
||||
MirLev1_0100, /* 8F00..8FFF */
|
||||
MirLev1_0100, /* 9000..90FF */
|
||||
MirLev1_0100, /* 9100..91FF */
|
||||
MirLev1_0100, /* 9200..92FF */
|
||||
MirLev1_0100, /* 9300..93FF */
|
||||
MirLev1_0100, /* 9400..94FF */
|
||||
MirLev1_0100, /* 9500..95FF */
|
||||
MirLev1_0100, /* 9600..96FF */
|
||||
MirLev1_0100, /* 9700..97FF */
|
||||
MirLev1_0100, /* 9800..98FF */
|
||||
MirLev1_0100, /* 9900..99FF */
|
||||
MirLev1_0100, /* 9A00..9AFF */
|
||||
MirLev1_0100, /* 9B00..9BFF */
|
||||
MirLev1_0100, /* 9C00..9CFF */
|
||||
MirLev1_0100, /* 9D00..9DFF */
|
||||
MirLev1_0100, /* 9E00..9EFF */
|
||||
MirLev1_0100, /* 9F00..9FFF */
|
||||
MirLev1_0100, /* A000..A0FF */
|
||||
MirLev1_0100, /* A100..A1FF */
|
||||
MirLev1_0100, /* A200..A2FF */
|
||||
MirLev1_0100, /* A300..A3FF */
|
||||
MirLev1_0100, /* A400..A4FF */
|
||||
MirLev1_0100, /* A500..A5FF */
|
||||
MirLev1_0100, /* A600..A6FF */
|
||||
MirLev1_0100, /* A700..A7FF */
|
||||
MirLev1_0100, /* A800..A8FF */
|
||||
MirLev1_0100, /* A900..A9FF */
|
||||
MirLev1_0100, /* AA00..AAFF */
|
||||
MirLev1_0100, /* AB00..ABFF */
|
||||
MirLev1_0100, /* AC00..ACFF */
|
||||
MirLev1_0100, /* AD00..ADFF */
|
||||
MirLev1_0100, /* AE00..AEFF */
|
||||
MirLev1_0100, /* AF00..AFFF */
|
||||
MirLev1_0100, /* B000..B0FF */
|
||||
MirLev1_0100, /* B100..B1FF */
|
||||
MirLev1_0100, /* B200..B2FF */
|
||||
MirLev1_0100, /* B300..B3FF */
|
||||
MirLev1_0100, /* B400..B4FF */
|
||||
MirLev1_0100, /* B500..B5FF */
|
||||
MirLev1_0100, /* B600..B6FF */
|
||||
MirLev1_0100, /* B700..B7FF */
|
||||
MirLev1_0100, /* B800..B8FF */
|
||||
MirLev1_0100, /* B900..B9FF */
|
||||
MirLev1_0100, /* BA00..BAFF */
|
||||
MirLev1_0100, /* BB00..BBFF */
|
||||
MirLev1_0100, /* BC00..BCFF */
|
||||
MirLev1_0100, /* BD00..BDFF */
|
||||
MirLev1_0100, /* BE00..BEFF */
|
||||
MirLev1_0100, /* BF00..BFFF */
|
||||
MirLev1_0100, /* C000..C0FF */
|
||||
MirLev1_0100, /* C100..C1FF */
|
||||
MirLev1_0100, /* C200..C2FF */
|
||||
MirLev1_0100, /* C300..C3FF */
|
||||
MirLev1_0100, /* C400..C4FF */
|
||||
MirLev1_0100, /* C500..C5FF */
|
||||
MirLev1_0100, /* C600..C6FF */
|
||||
MirLev1_0100, /* C700..C7FF */
|
||||
MirLev1_0100, /* C800..C8FF */
|
||||
MirLev1_0100, /* C900..C9FF */
|
||||
MirLev1_0100, /* CA00..CAFF */
|
||||
MirLev1_0100, /* CB00..CBFF */
|
||||
MirLev1_0100, /* CC00..CCFF */
|
||||
MirLev1_0100, /* CD00..CDFF */
|
||||
MirLev1_0100, /* CE00..CEFF */
|
||||
MirLev1_0100, /* CF00..CFFF */
|
||||
MirLev1_0100, /* D000..D0FF */
|
||||
MirLev1_0100, /* D100..D1FF */
|
||||
MirLev1_0100, /* D200..D2FF */
|
||||
MirLev1_0100, /* D300..D3FF */
|
||||
MirLev1_0100, /* D400..D4FF */
|
||||
MirLev1_0100, /* D500..D5FF */
|
||||
MirLev1_0100, /* D600..D6FF */
|
||||
MirLev1_0100, /* D700..D7FF */
|
||||
MirLev1_0100, /* D800..D8FF */
|
||||
MirLev1_0100, /* D900..D9FF */
|
||||
MirLev1_0100, /* DA00..DAFF */
|
||||
MirLev1_0100, /* DB00..DBFF */
|
||||
MirLev1_0100, /* DC00..DCFF */
|
||||
MirLev1_0100, /* DD00..DDFF */
|
||||
MirLev1_0100, /* DE00..DEFF */
|
||||
MirLev1_0100, /* DF00..DFFF */
|
||||
MirLev1_0100, /* E000..E0FF */
|
||||
MirLev1_0100, /* E100..E1FF */
|
||||
MirLev1_0100, /* E200..E2FF */
|
||||
MirLev1_0100, /* E300..E3FF */
|
||||
MirLev1_0100, /* E400..E4FF */
|
||||
MirLev1_0100, /* E500..E5FF */
|
||||
MirLev1_0100, /* E600..E6FF */
|
||||
MirLev1_0100, /* E700..E7FF */
|
||||
MirLev1_0100, /* E800..E8FF */
|
||||
MirLev1_0100, /* E900..E9FF */
|
||||
MirLev1_0100, /* EA00..EAFF */
|
||||
MirLev1_0100, /* EB00..EBFF */
|
||||
MirLev1_0100, /* EC00..ECFF */
|
||||
MirLev1_0100, /* ED00..EDFF */
|
||||
MirLev1_0100, /* EE00..EEFF */
|
||||
MirLev1_0100, /* EF00..EFFF */
|
||||
MirLev1_0100, /* F000..F0FF */
|
||||
MirLev1_0100, /* F100..F1FF */
|
||||
MirLev1_0100, /* F200..F2FF */
|
||||
MirLev1_0100, /* F300..F3FF */
|
||||
MirLev1_0100, /* F400..F4FF */
|
||||
MirLev1_0100, /* F500..F5FF */
|
||||
MirLev1_0100, /* F600..F6FF */
|
||||
MirLev1_0100, /* F700..F7FF */
|
||||
MirLev1_0100, /* F800..F8FF */
|
||||
MirLev1_0100, /* F900..F9FF */
|
||||
MirLev1_0100, /* FA00..FAFF */
|
||||
MirLev1_0100, /* FB00..FBFF */
|
||||
MirLev1_0100, /* FC00..FCFF */
|
||||
MirLev1_0100, /* FD00..FDFF */
|
||||
MirLev1_FE00, /* FE00..FEFF */
|
||||
MirLev1_FF00, /* FF00..FFFF */
|
||||
};
|
||||
|
||||
/* *INDENT-ON* */
|
||||
|
||||
#define GLIB_GET_MIRRORING_DELTA(x) \
|
||||
((x) >= 0x10000 ? 0 : \
|
||||
MirLev3[((x) & 0x03) + \
|
||||
MirLev2[((x) >> 2 & 0x03) + \
|
||||
MirLev1[((x) >> 4 & 0x0f) + \
|
||||
MirLev0[((x) >> 8)]]]])
|
||||
|
||||
#undef PACKTAB_UINT8
|
||||
#undef PACKTAB_UINT16
|
||||
#undef PACKTAB_UINT32
|
||||
|
||||
#define GLIB_GET_MIRRORING(x) ((x) + GLIB_GET_MIRRORING_DELTA(x))
|
||||
|
||||
/* End of generated gmirroringtable.h */
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,288 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
|
||||
#error "Only <glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __G_NODE_H__
|
||||
#define __G_NODE_H__
|
||||
|
||||
#include <glib/gmem.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GNode GNode;
|
||||
|
||||
/* Tree traverse flags */
|
||||
typedef enum
|
||||
{
|
||||
G_TRAVERSE_LEAVES = 1 << 0,
|
||||
G_TRAVERSE_NON_LEAVES = 1 << 1,
|
||||
G_TRAVERSE_ALL = G_TRAVERSE_LEAVES | G_TRAVERSE_NON_LEAVES,
|
||||
G_TRAVERSE_MASK = 0x03,
|
||||
G_TRAVERSE_LEAFS = G_TRAVERSE_LEAVES,
|
||||
G_TRAVERSE_NON_LEAFS = G_TRAVERSE_NON_LEAVES
|
||||
} GTraverseFlags;
|
||||
|
||||
/* Tree traverse orders */
|
||||
typedef enum
|
||||
{
|
||||
G_IN_ORDER,
|
||||
G_PRE_ORDER,
|
||||
G_POST_ORDER,
|
||||
G_LEVEL_ORDER
|
||||
} GTraverseType;
|
||||
|
||||
typedef gboolean (*GNodeTraverseFunc) (GNode *node,
|
||||
gpointer data);
|
||||
typedef void (*GNodeForeachFunc) (GNode *node,
|
||||
gpointer data);
|
||||
|
||||
/**
|
||||
* GCopyFunc:
|
||||
* @src: A pointer to the data which should be copied
|
||||
* @data: Additional data
|
||||
*
|
||||
* A function of this signature is used to copy the node data
|
||||
* when doing a deep-copy of a tree.
|
||||
*
|
||||
* Returns: A pointer to the copy
|
||||
*
|
||||
* Since: 2.4
|
||||
*/
|
||||
typedef gpointer (*GCopyFunc) (gconstpointer src,
|
||||
gpointer data);
|
||||
|
||||
/* N-way tree implementation
|
||||
*/
|
||||
struct _GNode
|
||||
{
|
||||
gpointer data;
|
||||
GNode *next;
|
||||
GNode *prev;
|
||||
GNode *parent;
|
||||
GNode *children;
|
||||
};
|
||||
|
||||
/**
|
||||
* G_NODE_IS_ROOT:
|
||||
* @node: a #GNode
|
||||
*
|
||||
* Returns %TRUE if a #GNode is the root of a tree.
|
||||
*
|
||||
* Returns: %TRUE if the #GNode is the root of a tree
|
||||
* (i.e. it has no parent or siblings)
|
||||
*/
|
||||
#define G_NODE_IS_ROOT(node) (((GNode*) (node))->parent == NULL && \
|
||||
((GNode*) (node))->prev == NULL && \
|
||||
((GNode*) (node))->next == NULL)
|
||||
|
||||
/**
|
||||
* G_NODE_IS_LEAF:
|
||||
* @node: a #GNode
|
||||
*
|
||||
* Returns %TRUE if a #GNode is a leaf node.
|
||||
*
|
||||
* Returns: %TRUE if the #GNode is a leaf node
|
||||
* (i.e. it has no children)
|
||||
*/
|
||||
#define G_NODE_IS_LEAF(node) (((GNode*) (node))->children == NULL)
|
||||
|
||||
GNode* g_node_new (gpointer data);
|
||||
void g_node_destroy (GNode *root);
|
||||
void g_node_unlink (GNode *node);
|
||||
GNode* g_node_copy_deep (GNode *node,
|
||||
GCopyFunc copy_func,
|
||||
gpointer data);
|
||||
GNode* g_node_copy (GNode *node);
|
||||
GNode* g_node_insert (GNode *parent,
|
||||
gint position,
|
||||
GNode *node);
|
||||
GNode* g_node_insert_before (GNode *parent,
|
||||
GNode *sibling,
|
||||
GNode *node);
|
||||
GNode* g_node_insert_after (GNode *parent,
|
||||
GNode *sibling,
|
||||
GNode *node);
|
||||
GNode* g_node_prepend (GNode *parent,
|
||||
GNode *node);
|
||||
guint g_node_n_nodes (GNode *root,
|
||||
GTraverseFlags flags);
|
||||
GNode* g_node_get_root (GNode *node);
|
||||
gboolean g_node_is_ancestor (GNode *node,
|
||||
GNode *descendant);
|
||||
guint g_node_depth (GNode *node);
|
||||
GNode* g_node_find (GNode *root,
|
||||
GTraverseType order,
|
||||
GTraverseFlags flags,
|
||||
gpointer data);
|
||||
|
||||
/* convenience macros */
|
||||
/**
|
||||
* g_node_append:
|
||||
* @parent: the #GNode to place the new #GNode under
|
||||
* @node: the #GNode to insert
|
||||
*
|
||||
* Inserts a #GNode as the last child of the given parent.
|
||||
*
|
||||
* Returns: the inserted #GNode
|
||||
*/
|
||||
#define g_node_append(parent, node) \
|
||||
g_node_insert_before ((parent), NULL, (node))
|
||||
|
||||
/**
|
||||
* g_node_insert_data:
|
||||
* @parent: the #GNode to place the new #GNode under
|
||||
* @position: the position to place the new #GNode at. If position is -1,
|
||||
* the new #GNode is inserted as the last child of @parent
|
||||
* @data: the data for the new #GNode
|
||||
*
|
||||
* Inserts a new #GNode at the given position.
|
||||
*
|
||||
* Returns: the new #GNode
|
||||
*/
|
||||
#define g_node_insert_data(parent, position, data) \
|
||||
g_node_insert ((parent), (position), g_node_new (data))
|
||||
|
||||
/**
|
||||
* g_node_insert_data_before:
|
||||
* @parent: the #GNode to place the new #GNode under
|
||||
* @sibling: the sibling #GNode to place the new #GNode before
|
||||
* @data: the data for the new #GNode
|
||||
*
|
||||
* Inserts a new #GNode before the given sibling.
|
||||
*
|
||||
* Returns: the new #GNode
|
||||
*/
|
||||
#define g_node_insert_data_before(parent, sibling, data) \
|
||||
g_node_insert_before ((parent), (sibling), g_node_new (data))
|
||||
|
||||
/**
|
||||
* g_node_prepend_data:
|
||||
* @parent: the #GNode to place the new #GNode under
|
||||
* @data: the data for the new #GNode
|
||||
*
|
||||
* Inserts a new #GNode as the first child of the given parent.
|
||||
*
|
||||
* Returns: the new #GNode
|
||||
*/
|
||||
#define g_node_prepend_data(parent, data) \
|
||||
g_node_prepend ((parent), g_node_new (data))
|
||||
|
||||
/**
|
||||
* g_node_append_data:
|
||||
* @parent: the #GNode to place the new #GNode under
|
||||
* @data: the data for the new #GNode
|
||||
*
|
||||
* Inserts a new #GNode as the last child of the given parent.
|
||||
*
|
||||
* Returns: the new #GNode
|
||||
*/
|
||||
#define g_node_append_data(parent, data) \
|
||||
g_node_insert_before ((parent), NULL, g_node_new (data))
|
||||
|
||||
/* traversal function, assumes that `node' is root
|
||||
* (only traverses `node' and its subtree).
|
||||
* this function is just a high level interface to
|
||||
* low level traversal functions, optimized for speed.
|
||||
*/
|
||||
void g_node_traverse (GNode *root,
|
||||
GTraverseType order,
|
||||
GTraverseFlags flags,
|
||||
gint max_depth,
|
||||
GNodeTraverseFunc func,
|
||||
gpointer data);
|
||||
|
||||
/* return the maximum tree height starting with `node', this is an expensive
|
||||
* operation, since we need to visit all nodes. this could be shortened by
|
||||
* adding `guint height' to struct _GNode, but then again, this is not very
|
||||
* often needed, and would make g_node_insert() more time consuming.
|
||||
*/
|
||||
guint g_node_max_height (GNode *root);
|
||||
|
||||
void g_node_children_foreach (GNode *node,
|
||||
GTraverseFlags flags,
|
||||
GNodeForeachFunc func,
|
||||
gpointer data);
|
||||
void g_node_reverse_children (GNode *node);
|
||||
guint g_node_n_children (GNode *node);
|
||||
GNode* g_node_nth_child (GNode *node,
|
||||
guint n);
|
||||
GNode* g_node_last_child (GNode *node);
|
||||
GNode* g_node_find_child (GNode *node,
|
||||
GTraverseFlags flags,
|
||||
gpointer data);
|
||||
gint g_node_child_position (GNode *node,
|
||||
GNode *child);
|
||||
gint g_node_child_index (GNode *node,
|
||||
gpointer data);
|
||||
|
||||
GNode* g_node_first_sibling (GNode *node);
|
||||
GNode* g_node_last_sibling (GNode *node);
|
||||
|
||||
/**
|
||||
* g_node_prev_sibling:
|
||||
* @node: a #GNode
|
||||
*
|
||||
* Gets the previous sibling of a #GNode.
|
||||
*
|
||||
* Returns: the previous sibling of @node, or %NULL if @node is %NULL
|
||||
*/
|
||||
#define g_node_prev_sibling(node) ((node) ? \
|
||||
((GNode*) (node))->prev : NULL)
|
||||
|
||||
/**
|
||||
* g_node_next_sibling:
|
||||
* @node: a #GNode
|
||||
*
|
||||
* Gets the next sibling of a #GNode.
|
||||
*
|
||||
* Returns: the next sibling of @node, or %NULL if @node is %NULL
|
||||
*/
|
||||
#define g_node_next_sibling(node) ((node) ? \
|
||||
((GNode*) (node))->next : NULL)
|
||||
|
||||
/**
|
||||
* g_node_first_child:
|
||||
* @node: a #GNode
|
||||
*
|
||||
* Gets the first child of a #GNode.
|
||||
*
|
||||
* Returns: the first child of @node, or %NULL if @node is %NULL
|
||||
* or has no children
|
||||
*/
|
||||
#define g_node_first_child(node) ((node) ? \
|
||||
((GNode*) (node))->children : NULL)
|
||||
|
||||
#ifndef G_DISABLE_DEPRECATED
|
||||
void g_node_push_allocator (gpointer dummy);
|
||||
void g_node_pop_allocator (void);
|
||||
#endif
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_NODE_H__ */
|
|
@ -0,0 +1,44 @@
|
|||
The files
|
||||
|
||||
asnprintf.c
|
||||
printf-args.c
|
||||
printf-args.h
|
||||
printf-parse.c
|
||||
printf-parse.h
|
||||
vasnprintf.c
|
||||
vasnprintf.h
|
||||
|
||||
are taken from the vasnprintf module of the GNUlib package, which can
|
||||
be found at:
|
||||
|
||||
http://www.gnu.org/software/gnulib/
|
||||
|
||||
All files have been modified to include g-gnulib.h.
|
||||
|
||||
vasnprintf.c has also been modified to include support for long long
|
||||
printing if the system printf doesn't. This code is protected by
|
||||
#ifndef HAVE_LONG_LONG_FORMAT.
|
||||
|
||||
Code has been added to printf-args.[ch], printf-parse.c and vasnprintf.c
|
||||
to support printing of __int64 values with the I64 format modifier. This
|
||||
is protected by #ifdef HAVE_INT64_AND_I64.
|
||||
|
||||
The files
|
||||
|
||||
printf.h
|
||||
printf.c
|
||||
g-gnulib.h
|
||||
|
||||
have been written by me. printf.[hc] contain implementations of the
|
||||
remaining functions in the printf family based on vasnprintf.
|
||||
g-gnulib.h is included by all source files in order to move all
|
||||
exported functions to the _g_gnulib namespace, replace malloc by
|
||||
g_malloc and make sure that snprintf is only used if it implements
|
||||
C99 return value semantics.
|
||||
|
||||
Matthias Clasen
|
||||
November 1, 2003
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
/* Formatted output to strings.
|
||||
Copyright (C) 1999, 2002 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU Library General Public License as published
|
||||
by the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
USA. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "g-gnulib.h"
|
||||
|
||||
/* Specification. */
|
||||
#include "vasnprintf.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
char *
|
||||
asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
char *result;
|
||||
|
||||
va_start (args, format);
|
||||
result = vasnprintf (resultbuf, lengthp, format, args);
|
||||
va_end (args);
|
||||
return result;
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 2003 Matthias Clasen
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#ifndef __G_GNULIB_H__
|
||||
|
||||
#include "config.h"
|
||||
#include <stdlib.h>
|
||||
#include "glib/glib.h"
|
||||
#include "glib/galias.h"
|
||||
|
||||
/* Private namespace for gnulib functions */
|
||||
#define asnprintf _g_gnulib_asnprintf
|
||||
#define vasnprintf _g_gnulib_vasnprintf
|
||||
#define printf_parse _g_gnulib_printf_parse
|
||||
#define printf_fetchargs _g_gnulib_printf_fetchargs
|
||||
|
||||
/* Use GLib memory allocation */
|
||||
#undef malloc
|
||||
#undef realloc
|
||||
#undef free
|
||||
#define malloc g_malloc
|
||||
#define realloc g_realloc
|
||||
#define free g_free
|
||||
|
||||
/* Ensure only C99 snprintf gets used */
|
||||
#undef HAVE_SNPRINTF
|
||||
#ifdef HAVE_C99_SNPRINTF
|
||||
#define HAVE_SNPRINTF 1
|
||||
#else
|
||||
#define HAVE_SNPRINTF 0
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* __G_GNULIB_H__ */
|
||||
|
|
@ -0,0 +1,133 @@
|
|||
/* Decomposed printf argument list.
|
||||
Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU Library General Public License as published
|
||||
by the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
USA. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "g-gnulib.h"
|
||||
|
||||
/* Specification. */
|
||||
#include "printf-args.h"
|
||||
|
||||
#ifdef STATIC
|
||||
STATIC
|
||||
#endif
|
||||
int
|
||||
printf_fetchargs (va_list args, arguments *a)
|
||||
{
|
||||
unsigned int i;
|
||||
argument *ap;
|
||||
|
||||
for (i = 0, ap = &a->arg[0]; i < a->count; i++, ap++)
|
||||
switch (ap->type)
|
||||
{
|
||||
case TYPE_SCHAR:
|
||||
ap->a.a_schar = va_arg (args, /*signed char*/ int);
|
||||
break;
|
||||
case TYPE_UCHAR:
|
||||
ap->a.a_uchar = va_arg (args, /*unsigned char*/ int);
|
||||
break;
|
||||
case TYPE_SHORT:
|
||||
ap->a.a_short = va_arg (args, /*short*/ int);
|
||||
break;
|
||||
case TYPE_USHORT:
|
||||
ap->a.a_ushort = va_arg (args, /*unsigned short*/ int);
|
||||
break;
|
||||
case TYPE_INT:
|
||||
ap->a.a_int = va_arg (args, int);
|
||||
break;
|
||||
case TYPE_UINT:
|
||||
ap->a.a_uint = va_arg (args, unsigned int);
|
||||
break;
|
||||
case TYPE_LONGINT:
|
||||
ap->a.a_longint = va_arg (args, long int);
|
||||
break;
|
||||
case TYPE_ULONGINT:
|
||||
ap->a.a_ulongint = va_arg (args, unsigned long int);
|
||||
break;
|
||||
#ifdef HAVE_LONG_LONG
|
||||
case TYPE_LONGLONGINT:
|
||||
ap->a.a_longlongint = va_arg (args, long long int);
|
||||
break;
|
||||
case TYPE_ULONGLONGINT:
|
||||
ap->a.a_ulonglongint = va_arg (args, unsigned long long int);
|
||||
break;
|
||||
#endif
|
||||
#ifdef HAVE_INT64_AND_I64
|
||||
case TYPE_INT64:
|
||||
ap->a.a_int64 = va_arg (args, __int64);
|
||||
break;
|
||||
case TYPE_UINT64:
|
||||
ap->a.a_uint64 = va_arg (args, unsigned __int64);
|
||||
break;
|
||||
#endif
|
||||
case TYPE_DOUBLE:
|
||||
ap->a.a_double = va_arg (args, double);
|
||||
break;
|
||||
#ifdef HAVE_LONG_DOUBLE
|
||||
case TYPE_LONGDOUBLE:
|
||||
ap->a.a_longdouble = va_arg (args, long double);
|
||||
break;
|
||||
#endif
|
||||
case TYPE_CHAR:
|
||||
ap->a.a_char = va_arg (args, int);
|
||||
break;
|
||||
#ifdef HAVE_WINT_T
|
||||
case TYPE_WIDE_CHAR:
|
||||
#ifdef _WIN32
|
||||
ap->a.a_wide_char = va_arg (args, int);
|
||||
#else
|
||||
ap->a.a_wide_char = va_arg (args, wint_t);
|
||||
#endif
|
||||
break;
|
||||
#endif
|
||||
case TYPE_STRING:
|
||||
ap->a.a_string = va_arg (args, const char *);
|
||||
break;
|
||||
#ifdef HAVE_WCHAR_T
|
||||
case TYPE_WIDE_STRING:
|
||||
ap->a.a_wide_string = va_arg (args, const wchar_t *);
|
||||
break;
|
||||
#endif
|
||||
case TYPE_POINTER:
|
||||
ap->a.a_pointer = va_arg (args, void *);
|
||||
break;
|
||||
case TYPE_COUNT_SCHAR_POINTER:
|
||||
ap->a.a_count_schar_pointer = va_arg (args, signed char *);
|
||||
break;
|
||||
case TYPE_COUNT_SHORT_POINTER:
|
||||
ap->a.a_count_short_pointer = va_arg (args, short *);
|
||||
break;
|
||||
case TYPE_COUNT_INT_POINTER:
|
||||
ap->a.a_count_int_pointer = va_arg (args, int *);
|
||||
break;
|
||||
case TYPE_COUNT_LONGINT_POINTER:
|
||||
ap->a.a_count_longint_pointer = va_arg (args, long int *);
|
||||
break;
|
||||
#ifdef HAVE_LONG_LONG
|
||||
case TYPE_COUNT_LONGLONGINT_POINTER:
|
||||
ap->a.a_count_longlongint_pointer = va_arg (args, long long int *);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
/* Unknown type. */
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,142 @@
|
|||
/* Decomposed printf argument list.
|
||||
Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU Library General Public License as published
|
||||
by the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
USA. */
|
||||
|
||||
#ifndef _PRINTF_ARGS_H
|
||||
#define _PRINTF_ARGS_H
|
||||
|
||||
/* Get wchar_t. */
|
||||
#ifdef HAVE_WCHAR_T
|
||||
# include <stddef.h>
|
||||
#endif
|
||||
|
||||
/* Get wint_t. */
|
||||
#ifdef HAVE_WINT_T
|
||||
# include <wchar.h>
|
||||
#endif
|
||||
|
||||
/* Get va_list. */
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
/* Argument types */
|
||||
typedef enum
|
||||
{
|
||||
TYPE_NONE,
|
||||
TYPE_SCHAR,
|
||||
TYPE_UCHAR,
|
||||
TYPE_SHORT,
|
||||
TYPE_USHORT,
|
||||
TYPE_INT,
|
||||
TYPE_UINT,
|
||||
TYPE_LONGINT,
|
||||
TYPE_ULONGINT,
|
||||
#ifdef HAVE_LONG_LONG
|
||||
TYPE_LONGLONGINT,
|
||||
TYPE_ULONGLONGINT,
|
||||
#endif
|
||||
#ifdef HAVE_INT64_AND_I64
|
||||
TYPE_INT64,
|
||||
TYPE_UINT64,
|
||||
#endif
|
||||
TYPE_DOUBLE,
|
||||
#ifdef HAVE_LONG_DOUBLE
|
||||
TYPE_LONGDOUBLE,
|
||||
#endif
|
||||
TYPE_CHAR,
|
||||
#ifdef HAVE_WINT_T
|
||||
TYPE_WIDE_CHAR,
|
||||
#endif
|
||||
TYPE_STRING,
|
||||
#ifdef HAVE_WCHAR_T
|
||||
TYPE_WIDE_STRING,
|
||||
#endif
|
||||
TYPE_POINTER,
|
||||
TYPE_COUNT_SCHAR_POINTER,
|
||||
TYPE_COUNT_SHORT_POINTER,
|
||||
TYPE_COUNT_INT_POINTER,
|
||||
TYPE_COUNT_LONGINT_POINTER
|
||||
#ifdef HAVE_LONG_LONG
|
||||
, TYPE_COUNT_LONGLONGINT_POINTER
|
||||
#endif
|
||||
} arg_type;
|
||||
|
||||
/* Polymorphic argument */
|
||||
typedef struct
|
||||
{
|
||||
arg_type type;
|
||||
union
|
||||
{
|
||||
signed char a_schar;
|
||||
unsigned char a_uchar;
|
||||
short a_short;
|
||||
unsigned short a_ushort;
|
||||
int a_int;
|
||||
unsigned int a_uint;
|
||||
long int a_longint;
|
||||
unsigned long int a_ulongint;
|
||||
#ifdef HAVE_LONG_LONG
|
||||
long long int a_longlongint;
|
||||
unsigned long long int a_ulonglongint;
|
||||
#endif
|
||||
#ifdef HAVE_INT64_AND_I64
|
||||
__int64 a_int64;
|
||||
unsigned __int64 a_uint64;
|
||||
#endif
|
||||
float a_float;
|
||||
double a_double;
|
||||
#ifdef HAVE_LONG_DOUBLE
|
||||
long double a_longdouble;
|
||||
#endif
|
||||
int a_char;
|
||||
#ifdef HAVE_WINT_T
|
||||
wint_t a_wide_char;
|
||||
#endif
|
||||
const char* a_string;
|
||||
#ifdef HAVE_WCHAR_T
|
||||
const wchar_t* a_wide_string;
|
||||
#endif
|
||||
void* a_pointer;
|
||||
signed char * a_count_schar_pointer;
|
||||
short * a_count_short_pointer;
|
||||
int * a_count_int_pointer;
|
||||
long int * a_count_longint_pointer;
|
||||
#ifdef HAVE_LONG_LONG
|
||||
long long int * a_count_longlongint_pointer;
|
||||
#endif
|
||||
}
|
||||
a;
|
||||
}
|
||||
argument;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned int count;
|
||||
argument *arg;
|
||||
}
|
||||
arguments;
|
||||
|
||||
|
||||
/* Fetch the arguments, putting them into a. */
|
||||
#ifdef STATIC
|
||||
STATIC
|
||||
#else
|
||||
extern
|
||||
#endif
|
||||
int printf_fetchargs (va_list args, arguments *a);
|
||||
|
||||
#endif /* _PRINTF_ARGS_H */
|
|
@ -0,0 +1,498 @@
|
|||
/* Formatted output to strings.
|
||||
Copyright (C) 1999-2000, 2002-2003 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU Library General Public License as published
|
||||
by the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
USA. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "g-gnulib.h"
|
||||
|
||||
/* Specification. */
|
||||
#include "printf-parse.h"
|
||||
|
||||
/* Get size_t, NULL. */
|
||||
#include <stddef.h>
|
||||
|
||||
/* Get intmax_t. */
|
||||
#if HAVE_STDINT_H_WITH_UINTMAX
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
#if HAVE_INTTYPES_H_WITH_UINTMAX
|
||||
# include <inttypes.h>
|
||||
#endif
|
||||
|
||||
/* malloc(), realloc(), free(). */
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef STATIC
|
||||
STATIC
|
||||
#endif
|
||||
int
|
||||
printf_parse (const char *format, char_directives *d, arguments *a)
|
||||
{
|
||||
const char *cp = format; /* pointer into format */
|
||||
int arg_posn = 0; /* number of regular arguments consumed */
|
||||
unsigned int d_allocated; /* allocated elements of d->dir */
|
||||
unsigned int a_allocated; /* allocated elements of a->arg */
|
||||
unsigned int max_width_length = 0;
|
||||
unsigned int max_precision_length = 0;
|
||||
|
||||
d->count = 0;
|
||||
d_allocated = 1;
|
||||
d->dir = malloc (d_allocated * sizeof (char_directive));
|
||||
if (d->dir == NULL)
|
||||
/* Out of memory. */
|
||||
return -1;
|
||||
|
||||
a->count = 0;
|
||||
a_allocated = 0;
|
||||
a->arg = NULL;
|
||||
|
||||
#define REGISTER_ARG(_index_,_type_) \
|
||||
{ \
|
||||
unsigned int n = (_index_); \
|
||||
if (n >= a_allocated) \
|
||||
{ \
|
||||
argument *memory; \
|
||||
a_allocated = 2 * a_allocated; \
|
||||
if (a_allocated <= n) \
|
||||
a_allocated = n + 1; \
|
||||
memory = (a->arg \
|
||||
? realloc (a->arg, a_allocated * sizeof (argument)) \
|
||||
: malloc (a_allocated * sizeof (argument))); \
|
||||
if (memory == NULL) \
|
||||
/* Out of memory. */ \
|
||||
goto error; \
|
||||
a->arg = memory; \
|
||||
} \
|
||||
while (a->count <= n) \
|
||||
a->arg[a->count++].type = TYPE_NONE; \
|
||||
if (a->arg[n].type == TYPE_NONE) \
|
||||
a->arg[n].type = (_type_); \
|
||||
else if (a->arg[n].type != (_type_)) \
|
||||
/* Ambiguous type for positional argument. */ \
|
||||
goto error; \
|
||||
}
|
||||
|
||||
while (*cp != '\0')
|
||||
{
|
||||
char c = *cp++;
|
||||
if (c == '%')
|
||||
{
|
||||
int arg_index = -1;
|
||||
char_directive *dp = &d->dir[d->count];/* pointer to next directive */
|
||||
|
||||
/* Initialize the next directive. */
|
||||
dp->dir_start = cp - 1;
|
||||
dp->flags = 0;
|
||||
dp->width_start = NULL;
|
||||
dp->width_end = NULL;
|
||||
dp->width_arg_index = -1;
|
||||
dp->precision_start = NULL;
|
||||
dp->precision_end = NULL;
|
||||
dp->precision_arg_index = -1;
|
||||
dp->arg_index = -1;
|
||||
|
||||
/* Test for positional argument. */
|
||||
if (*cp >= '0' && *cp <= '9')
|
||||
{
|
||||
const char *np;
|
||||
|
||||
for (np = cp; *np >= '0' && *np <= '9'; np++)
|
||||
;
|
||||
if (*np == '$')
|
||||
{
|
||||
unsigned int n = 0;
|
||||
|
||||
for (np = cp; *np >= '0' && *np <= '9'; np++)
|
||||
n = 10 * n + (*np - '0');
|
||||
if (n == 0)
|
||||
/* Positional argument 0. */
|
||||
goto error;
|
||||
arg_index = n - 1;
|
||||
cp = np + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Read the flags. */
|
||||
for (;;)
|
||||
{
|
||||
if (*cp == '\'')
|
||||
{
|
||||
dp->flags |= FLAG_GROUP;
|
||||
cp++;
|
||||
}
|
||||
else if (*cp == '-')
|
||||
{
|
||||
dp->flags |= FLAG_LEFT;
|
||||
cp++;
|
||||
}
|
||||
else if (*cp == '+')
|
||||
{
|
||||
dp->flags |= FLAG_SHOWSIGN;
|
||||
cp++;
|
||||
}
|
||||
else if (*cp == ' ')
|
||||
{
|
||||
dp->flags |= FLAG_SPACE;
|
||||
cp++;
|
||||
}
|
||||
else if (*cp == '#')
|
||||
{
|
||||
dp->flags |= FLAG_ALT;
|
||||
cp++;
|
||||
}
|
||||
else if (*cp == '0')
|
||||
{
|
||||
dp->flags |= FLAG_ZERO;
|
||||
cp++;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
/* Parse the field width. */
|
||||
if (*cp == '*')
|
||||
{
|
||||
dp->width_start = cp;
|
||||
cp++;
|
||||
dp->width_end = cp;
|
||||
if (max_width_length < 1)
|
||||
max_width_length = 1;
|
||||
|
||||
/* Test for positional argument. */
|
||||
if (*cp >= '0' && *cp <= '9')
|
||||
{
|
||||
const char *np;
|
||||
|
||||
for (np = cp; *np >= '0' && *np <= '9'; np++)
|
||||
;
|
||||
if (*np == '$')
|
||||
{
|
||||
unsigned int n = 0;
|
||||
|
||||
for (np = cp; *np >= '0' && *np <= '9'; np++)
|
||||
n = 10 * n + (*np - '0');
|
||||
if (n == 0)
|
||||
/* Positional argument 0. */
|
||||
goto error;
|
||||
dp->width_arg_index = n - 1;
|
||||
cp = np + 1;
|
||||
}
|
||||
}
|
||||
if (dp->width_arg_index < 0)
|
||||
dp->width_arg_index = arg_posn++;
|
||||
REGISTER_ARG (dp->width_arg_index, TYPE_INT);
|
||||
}
|
||||
else if (*cp >= '0' && *cp <= '9')
|
||||
{
|
||||
unsigned int width_length;
|
||||
|
||||
dp->width_start = cp;
|
||||
for (; *cp >= '0' && *cp <= '9'; cp++)
|
||||
;
|
||||
dp->width_end = cp;
|
||||
width_length = dp->width_end - dp->width_start;
|
||||
if (max_width_length < width_length)
|
||||
max_width_length = width_length;
|
||||
}
|
||||
|
||||
/* Parse the precision. */
|
||||
if (*cp == '.')
|
||||
{
|
||||
cp++;
|
||||
if (*cp == '*')
|
||||
{
|
||||
dp->precision_start = cp - 1;
|
||||
cp++;
|
||||
dp->precision_end = cp;
|
||||
if (max_precision_length < 2)
|
||||
max_precision_length = 2;
|
||||
|
||||
/* Test for positional argument. */
|
||||
if (*cp >= '0' && *cp <= '9')
|
||||
{
|
||||
const char *np;
|
||||
|
||||
for (np = cp; *np >= '0' && *np <= '9'; np++)
|
||||
;
|
||||
if (*np == '$')
|
||||
{
|
||||
unsigned int n = 0;
|
||||
|
||||
for (np = cp; *np >= '0' && *np <= '9'; np++)
|
||||
n = 10 * n + (*np - '0');
|
||||
if (n == 0)
|
||||
/* Positional argument 0. */
|
||||
goto error;
|
||||
dp->precision_arg_index = n - 1;
|
||||
cp = np + 1;
|
||||
}
|
||||
}
|
||||
if (dp->precision_arg_index < 0)
|
||||
dp->precision_arg_index = arg_posn++;
|
||||
REGISTER_ARG (dp->precision_arg_index, TYPE_INT);
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int precision_length;
|
||||
|
||||
dp->precision_start = cp - 1;
|
||||
for (; *cp >= '0' && *cp <= '9'; cp++)
|
||||
;
|
||||
dp->precision_end = cp;
|
||||
precision_length = dp->precision_end - dp->precision_start;
|
||||
if (max_precision_length < precision_length)
|
||||
max_precision_length = precision_length;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
arg_type type;
|
||||
|
||||
/* Parse argument type/size specifiers. */
|
||||
{
|
||||
int flags = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (*cp == 'h')
|
||||
{
|
||||
flags |= (1 << (flags & 1));
|
||||
cp++;
|
||||
}
|
||||
else if (*cp == 'L')
|
||||
{
|
||||
flags |= 4;
|
||||
cp++;
|
||||
}
|
||||
else if (*cp == 'l')
|
||||
{
|
||||
flags += 8;
|
||||
cp++;
|
||||
}
|
||||
#ifdef HAVE_INT64_AND_I64
|
||||
else if (cp[0] == 'I' &&
|
||||
cp[1] == '6' &&
|
||||
cp[2] == '4')
|
||||
{
|
||||
flags = 64;
|
||||
cp += 3;
|
||||
}
|
||||
#endif
|
||||
#ifdef HAVE_INTMAX_T
|
||||
else if (*cp == 'j')
|
||||
{
|
||||
if (sizeof (intmax_t) > sizeof (long))
|
||||
{
|
||||
/* intmax_t = long long */
|
||||
flags += 16;
|
||||
}
|
||||
else if (sizeof (intmax_t) > sizeof (int))
|
||||
{
|
||||
/* intmax_t = long */
|
||||
flags += 8;
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
#endif
|
||||
else if (*cp == 'z' || *cp == 'Z')
|
||||
{
|
||||
/* 'z' is standardized in ISO C 99, but glibc uses 'Z'
|
||||
because the warning facility in gcc-2.95.2 understands
|
||||
only 'Z' (see gcc-2.95.2/gcc/c-common.c:1784). */
|
||||
if (sizeof (size_t) > sizeof (long))
|
||||
{
|
||||
/* size_t = long long */
|
||||
flags += 16;
|
||||
}
|
||||
else if (sizeof (size_t) > sizeof (int))
|
||||
{
|
||||
/* size_t = long */
|
||||
flags += 8;
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
else if (*cp == 't')
|
||||
{
|
||||
if (sizeof (ptrdiff_t) > sizeof (long))
|
||||
{
|
||||
/* ptrdiff_t = long long */
|
||||
flags += 16;
|
||||
}
|
||||
else if (sizeof (ptrdiff_t) > sizeof (int))
|
||||
{
|
||||
/* ptrdiff_t = long */
|
||||
flags += 8;
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
/* Read the conversion character. */
|
||||
c = *cp++;
|
||||
switch (c)
|
||||
{
|
||||
case 'd': case 'i':
|
||||
#ifdef HAVE_INT64_AND_I64
|
||||
if (flags == 64)
|
||||
type = TYPE_INT64;
|
||||
else
|
||||
#endif
|
||||
#ifdef HAVE_LONG_LONG
|
||||
if (flags >= 16 || (flags & 4))
|
||||
type = TYPE_LONGLONGINT;
|
||||
else
|
||||
#endif
|
||||
if (flags >= 8)
|
||||
type = TYPE_LONGINT;
|
||||
else if (flags & 2)
|
||||
type = TYPE_SCHAR;
|
||||
else if (flags & 1)
|
||||
type = TYPE_SHORT;
|
||||
else
|
||||
type = TYPE_INT;
|
||||
break;
|
||||
case 'o': case 'u': case 'x': case 'X':
|
||||
#ifdef HAVE_INT64_AND_I64
|
||||
if (flags == 64)
|
||||
type = TYPE_UINT64;
|
||||
else
|
||||
#endif
|
||||
#ifdef HAVE_LONG_LONG
|
||||
if (flags >= 16 || (flags & 4))
|
||||
type = TYPE_ULONGLONGINT;
|
||||
else
|
||||
#endif
|
||||
if (flags >= 8)
|
||||
type = TYPE_ULONGINT;
|
||||
else if (flags & 2)
|
||||
type = TYPE_UCHAR;
|
||||
else if (flags & 1)
|
||||
type = TYPE_USHORT;
|
||||
else
|
||||
type = TYPE_UINT;
|
||||
break;
|
||||
case 'f': case 'F': case 'e': case 'E': case 'g': case 'G':
|
||||
case 'a': case 'A':
|
||||
#ifdef HAVE_LONG_DOUBLE
|
||||
if (flags >= 16 || (flags & 4))
|
||||
type = TYPE_LONGDOUBLE;
|
||||
else
|
||||
#endif
|
||||
type = TYPE_DOUBLE;
|
||||
break;
|
||||
case 'c':
|
||||
if (flags >= 8)
|
||||
#ifdef HAVE_WINT_T
|
||||
type = TYPE_WIDE_CHAR;
|
||||
#else
|
||||
goto error;
|
||||
#endif
|
||||
else
|
||||
type = TYPE_CHAR;
|
||||
break;
|
||||
#ifdef HAVE_WINT_T
|
||||
case 'C':
|
||||
type = TYPE_WIDE_CHAR;
|
||||
c = 'c';
|
||||
break;
|
||||
#endif
|
||||
case 's':
|
||||
if (flags >= 8)
|
||||
#ifdef HAVE_WCHAR_T
|
||||
type = TYPE_WIDE_STRING;
|
||||
#else
|
||||
goto error;
|
||||
#endif
|
||||
else
|
||||
type = TYPE_STRING;
|
||||
break;
|
||||
#ifdef HAVE_WCHAR_T
|
||||
case 'S':
|
||||
type = TYPE_WIDE_STRING;
|
||||
c = 's';
|
||||
break;
|
||||
#endif
|
||||
case 'p':
|
||||
type = TYPE_POINTER;
|
||||
break;
|
||||
case 'n':
|
||||
#ifdef HAVE_LONG_LONG
|
||||
if (flags >= 16 || (flags & 4))
|
||||
type = TYPE_COUNT_LONGLONGINT_POINTER;
|
||||
else
|
||||
#endif
|
||||
if (flags >= 8)
|
||||
type = TYPE_COUNT_LONGINT_POINTER;
|
||||
else if (flags & 2)
|
||||
type = TYPE_COUNT_SCHAR_POINTER;
|
||||
else if (flags & 1)
|
||||
type = TYPE_COUNT_SHORT_POINTER;
|
||||
else
|
||||
type = TYPE_COUNT_INT_POINTER;
|
||||
break;
|
||||
case '%':
|
||||
type = TYPE_NONE;
|
||||
break;
|
||||
default:
|
||||
/* Unknown conversion character. */
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
if (type != TYPE_NONE)
|
||||
{
|
||||
dp->arg_index = arg_index;
|
||||
if (dp->arg_index < 0)
|
||||
dp->arg_index = arg_posn++;
|
||||
REGISTER_ARG (dp->arg_index, type);
|
||||
}
|
||||
dp->conversion = c;
|
||||
dp->dir_end = cp;
|
||||
}
|
||||
|
||||
d->count++;
|
||||
if (d->count >= d_allocated)
|
||||
{
|
||||
char_directive *memory;
|
||||
|
||||
d_allocated = 2 * d_allocated;
|
||||
memory = realloc (d->dir, d_allocated * sizeof (char_directive));
|
||||
if (memory == NULL)
|
||||
/* Out of memory. */
|
||||
goto error;
|
||||
d->dir = memory;
|
||||
}
|
||||
}
|
||||
}
|
||||
d->dir[d->count].dir_start = cp;
|
||||
|
||||
d->max_width_length = max_width_length;
|
||||
d->max_precision_length = max_precision_length;
|
||||
return 0;
|
||||
|
||||
error:
|
||||
if (a->arg)
|
||||
free (a->arg);
|
||||
if (d->dir)
|
||||
free (d->dir);
|
||||
return -1;
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
/* Parse printf format string.
|
||||
Copyright (C) 1999, 2002 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU Library General Public License as published
|
||||
by the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
USA. */
|
||||
|
||||
#ifndef _PRINTF_PARSE_H
|
||||
#define _PRINTF_PARSE_H
|
||||
|
||||
#include "printf-args.h"
|
||||
|
||||
/* Private namespace for gnulib functions */
|
||||
#define printf_parse _g_gnulib_printf_parse
|
||||
|
||||
/* Flags */
|
||||
#define FLAG_GROUP 1 /* ' flag */
|
||||
#define FLAG_LEFT 2 /* - flag */
|
||||
#define FLAG_SHOWSIGN 4 /* + flag */
|
||||
#define FLAG_SPACE 8 /* space flag */
|
||||
#define FLAG_ALT 16 /* # flag */
|
||||
#define FLAG_ZERO 32
|
||||
|
||||
/* A parsed directive. */
|
||||
typedef struct
|
||||
{
|
||||
const char* dir_start;
|
||||
const char* dir_end;
|
||||
int flags;
|
||||
const char* width_start;
|
||||
const char* width_end;
|
||||
int width_arg_index;
|
||||
const char* precision_start;
|
||||
const char* precision_end;
|
||||
int precision_arg_index;
|
||||
char conversion; /* d i o u x X f e E g G c s p n U % but not C S */
|
||||
int arg_index;
|
||||
}
|
||||
char_directive;
|
||||
|
||||
/* A parsed format string. */
|
||||
typedef struct
|
||||
{
|
||||
unsigned int count;
|
||||
char_directive *dir;
|
||||
unsigned int max_width_length;
|
||||
unsigned int max_precision_length;
|
||||
}
|
||||
char_directives;
|
||||
|
||||
|
||||
/* Parses the format string. Fills in the number N of directives, and fills
|
||||
in directives[0], ..., directives[N-1], and sets directives[N].dir_start
|
||||
to the end of the format string. Also fills in the arg_type fields of the
|
||||
arguments and the needed count of arguments. */
|
||||
#ifdef STATIC
|
||||
STATIC
|
||||
#else
|
||||
extern
|
||||
#endif
|
||||
int printf_parse (const char *format, char_directives *d, arguments *a);
|
||||
|
||||
#endif /* _PRINTF_PARSE_H */
|
|
@ -0,0 +1,154 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 2003 Matthias Clasen
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 2003. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "g-gnulib.h"
|
||||
#include "vasnprintf.h"
|
||||
#include "printf.h"
|
||||
|
||||
int _g_gnulib_printf (char const *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
int retval;
|
||||
|
||||
va_start (args, format);
|
||||
retval = _g_gnulib_vprintf (format, args);
|
||||
va_end (args);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
int _g_gnulib_fprintf (FILE *file, char const *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
int retval;
|
||||
|
||||
va_start (args, format);
|
||||
retval = _g_gnulib_vfprintf (file, format, args);
|
||||
va_end (args);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
int _g_gnulib_sprintf (char *string, char const *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
int retval;
|
||||
|
||||
va_start (args, format);
|
||||
retval = _g_gnulib_vsprintf (string, format, args);
|
||||
va_end (args);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
int _g_gnulib_snprintf (char *string, size_t n, char const *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
int retval;
|
||||
|
||||
va_start (args, format);
|
||||
retval = _g_gnulib_vsnprintf (string, n, format, args);
|
||||
va_end (args);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
int _g_gnulib_vprintf (char const *format, va_list args)
|
||||
{
|
||||
return _g_gnulib_vfprintf (stdout, format, args);
|
||||
}
|
||||
|
||||
int _g_gnulib_vfprintf (FILE *file, char const *format, va_list args)
|
||||
{
|
||||
char *result;
|
||||
size_t length;
|
||||
|
||||
result = vasnprintf (NULL, &length, format, args);
|
||||
if (result == NULL)
|
||||
return -1;
|
||||
|
||||
fwrite (result, 1, length, file);
|
||||
free (result);
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
int _g_gnulib_vsprintf (char *string, char const *format, va_list args)
|
||||
{
|
||||
char *result;
|
||||
size_t length;
|
||||
|
||||
result = vasnprintf (NULL, &length, format, args);
|
||||
if (result == NULL)
|
||||
return -1;
|
||||
|
||||
memcpy (string, result, length + 1);
|
||||
free (result);
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
int _g_gnulib_vsnprintf (char *string, size_t n, char const *format, va_list args)
|
||||
{
|
||||
char *result;
|
||||
size_t length;
|
||||
|
||||
result = vasnprintf (NULL, &length, format, args);
|
||||
if (result == NULL)
|
||||
return -1;
|
||||
|
||||
if (n > 0)
|
||||
{
|
||||
memcpy (string, result, MIN(length + 1, n));
|
||||
string[n - 1] = 0;
|
||||
}
|
||||
|
||||
free (result);
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
int _g_gnulib_vasprintf (char **result, char const *format, va_list args)
|
||||
{
|
||||
size_t length;
|
||||
|
||||
*result = vasnprintf (NULL, &length, format, args);
|
||||
if (*result == NULL)
|
||||
return -1;
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 2003 Matthias Clasen
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#ifndef __GNULIB_PRINTF_H__
|
||||
#define __GNULIB_PRINTF_H__
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int _g_gnulib_printf (char const *format,
|
||||
...);
|
||||
int _g_gnulib_fprintf (FILE *file,
|
||||
char const *format,
|
||||
...);
|
||||
int _g_gnulib_sprintf (char *string,
|
||||
char const *format,
|
||||
...);
|
||||
int _g_gnulib_snprintf (char *string,
|
||||
size_t n,
|
||||
char const *format,
|
||||
...);
|
||||
int _g_gnulib_vprintf (char const *format,
|
||||
va_list args);
|
||||
int _g_gnulib_vfprintf (FILE *file,
|
||||
char const *format,
|
||||
va_list args);
|
||||
int _g_gnulib_vsprintf (char *string,
|
||||
char const *format,
|
||||
va_list args);
|
||||
int _g_gnulib_vsnprintf (char *string,
|
||||
size_t n,
|
||||
char const *format,
|
||||
va_list args);
|
||||
int _g_gnulib_vasprintf (char **result,
|
||||
char const *format,
|
||||
va_list args);
|
||||
|
||||
|
||||
#endif /* __GNULIB_PRINTF_H__ */
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,61 @@
|
|||
/* vsprintf with automatic memory allocation.
|
||||
Copyright (C) 2002-2003 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU Library General Public License as published
|
||||
by the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program 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
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
USA. */
|
||||
|
||||
#ifndef _VASNPRINTF_H
|
||||
#define _VASNPRINTF_H
|
||||
|
||||
/* Get va_list. */
|
||||
#include <stdarg.h>
|
||||
|
||||
/* Get size_t. */
|
||||
#include <stddef.h>
|
||||
|
||||
#ifndef __attribute__
|
||||
/* This feature is available in gcc versions 2.5 and later. */
|
||||
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
|
||||
# define __attribute__(Spec) /* empty */
|
||||
# endif
|
||||
/* The __-protected variants of `format' and `printf' attributes
|
||||
are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
|
||||
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
|
||||
# define __format__ format
|
||||
# define __printf__ printf
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Write formatted output to a string dynamically allocated with malloc().
|
||||
You can pass a preallocated buffer for the result in RESULTBUF and its
|
||||
size in *LENGTHP; otherwise you pass RESULTBUF = NULL.
|
||||
If successful, return the address of the string (this may be = RESULTBUF
|
||||
if no dynamic memory allocation was necessary) and set *LENGTHP to the
|
||||
number of resulting bytes, excluding the trailing NUL. Upon error, set
|
||||
errno and return NULL. */
|
||||
extern char * asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...)
|
||||
__attribute__ ((__format__ (__printf__, 3, 4)));
|
||||
extern char * vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args)
|
||||
__attribute__ ((__format__ (__printf__, 3, 0)));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _VASNPRINTF_H */
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,163 @@
|
|||
/* goption.h - Option parser
|
||||
*
|
||||
* Copyright (C) 2004 Anders Carlsson <andersca@gnome.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
|
||||
#error "Only <glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __G_OPTION_H__
|
||||
#define __G_OPTION_H__
|
||||
|
||||
#include <glib/gerror.h>
|
||||
#include <glib/gquark.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GOptionContext GOptionContext;
|
||||
typedef struct _GOptionGroup GOptionGroup;
|
||||
typedef struct _GOptionEntry GOptionEntry;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
G_OPTION_FLAG_HIDDEN = 1 << 0,
|
||||
G_OPTION_FLAG_IN_MAIN = 1 << 1,
|
||||
G_OPTION_FLAG_REVERSE = 1 << 2,
|
||||
G_OPTION_FLAG_NO_ARG = 1 << 3,
|
||||
G_OPTION_FLAG_FILENAME = 1 << 4,
|
||||
G_OPTION_FLAG_OPTIONAL_ARG = 1 << 5,
|
||||
G_OPTION_FLAG_NOALIAS = 1 << 6
|
||||
} GOptionFlags;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
G_OPTION_ARG_NONE,
|
||||
G_OPTION_ARG_STRING,
|
||||
G_OPTION_ARG_INT,
|
||||
G_OPTION_ARG_CALLBACK,
|
||||
G_OPTION_ARG_FILENAME,
|
||||
G_OPTION_ARG_STRING_ARRAY,
|
||||
G_OPTION_ARG_FILENAME_ARRAY,
|
||||
G_OPTION_ARG_DOUBLE,
|
||||
G_OPTION_ARG_INT64
|
||||
} GOptionArg;
|
||||
|
||||
typedef gboolean (*GOptionArgFunc) (const gchar *option_name,
|
||||
const gchar *value,
|
||||
gpointer data,
|
||||
GError **error);
|
||||
|
||||
typedef gboolean (*GOptionParseFunc) (GOptionContext *context,
|
||||
GOptionGroup *group,
|
||||
gpointer data,
|
||||
GError **error);
|
||||
|
||||
typedef void (*GOptionErrorFunc) (GOptionContext *context,
|
||||
GOptionGroup *group,
|
||||
gpointer data,
|
||||
GError **error);
|
||||
|
||||
#define G_OPTION_ERROR (g_option_error_quark ())
|
||||
|
||||
typedef enum
|
||||
{
|
||||
G_OPTION_ERROR_UNKNOWN_OPTION,
|
||||
G_OPTION_ERROR_BAD_VALUE,
|
||||
G_OPTION_ERROR_FAILED
|
||||
} GOptionError;
|
||||
|
||||
GQuark g_option_error_quark (void);
|
||||
|
||||
|
||||
struct _GOptionEntry
|
||||
{
|
||||
const gchar *long_name;
|
||||
gchar short_name;
|
||||
gint flags;
|
||||
|
||||
GOptionArg arg;
|
||||
gpointer arg_data;
|
||||
|
||||
const gchar *description;
|
||||
const gchar *arg_description;
|
||||
};
|
||||
|
||||
#define G_OPTION_REMAINING ""
|
||||
|
||||
GOptionContext *g_option_context_new (const gchar *parameter_string);
|
||||
void g_option_context_set_summary (GOptionContext *context,
|
||||
const gchar *summary);
|
||||
G_CONST_RETURN gchar *g_option_context_get_summary (GOptionContext *context);
|
||||
void g_option_context_set_description (GOptionContext *context,
|
||||
const gchar *description);
|
||||
G_CONST_RETURN gchar *g_option_context_get_description (GOptionContext *context);
|
||||
void g_option_context_free (GOptionContext *context);
|
||||
void g_option_context_set_help_enabled (GOptionContext *context,
|
||||
gboolean help_enabled);
|
||||
gboolean g_option_context_get_help_enabled (GOptionContext *context);
|
||||
void g_option_context_set_ignore_unknown_options (GOptionContext *context,
|
||||
gboolean ignore_unknown);
|
||||
gboolean g_option_context_get_ignore_unknown_options (GOptionContext *context);
|
||||
|
||||
void g_option_context_add_main_entries (GOptionContext *context,
|
||||
const GOptionEntry *entries,
|
||||
const gchar *translation_domain);
|
||||
gboolean g_option_context_parse (GOptionContext *context,
|
||||
gint *argc,
|
||||
gchar ***argv,
|
||||
GError **error);
|
||||
void g_option_context_set_translate_func (GOptionContext *context,
|
||||
GTranslateFunc func,
|
||||
gpointer data,
|
||||
GDestroyNotify destroy_notify);
|
||||
void g_option_context_set_translation_domain (GOptionContext *context,
|
||||
const gchar *domain);
|
||||
|
||||
void g_option_context_add_group (GOptionContext *context,
|
||||
GOptionGroup *group);
|
||||
void g_option_context_set_main_group (GOptionContext *context,
|
||||
GOptionGroup *group);
|
||||
GOptionGroup *g_option_context_get_main_group (GOptionContext *context);
|
||||
gchar *g_option_context_get_help (GOptionContext *context,
|
||||
gboolean main_help,
|
||||
GOptionGroup *group);
|
||||
|
||||
GOptionGroup *g_option_group_new (const gchar *name,
|
||||
const gchar *description,
|
||||
const gchar *help_description,
|
||||
gpointer user_data,
|
||||
GDestroyNotify destroy);
|
||||
void g_option_group_set_parse_hooks (GOptionGroup *group,
|
||||
GOptionParseFunc pre_parse_func,
|
||||
GOptionParseFunc post_parse_func);
|
||||
void g_option_group_set_error_hook (GOptionGroup *group,
|
||||
GOptionErrorFunc error_func);
|
||||
void g_option_group_free (GOptionGroup *group);
|
||||
void g_option_group_add_entries (GOptionGroup *group,
|
||||
const GOptionEntry *entries);
|
||||
void g_option_group_set_translate_func (GOptionGroup *group,
|
||||
GTranslateFunc func,
|
||||
gpointer data,
|
||||
GDestroyNotify destroy_notify);
|
||||
void g_option_group_set_translation_domain (GOptionGroup *group,
|
||||
const gchar *domain);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_OPTION_H__ */
|
|
@ -0,0 +1,343 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997, 1999 Peter Mattis, Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "gpattern.h"
|
||||
|
||||
#include "gmacros.h"
|
||||
#include "gmessages.h"
|
||||
#include "gmem.h"
|
||||
#include "gunicode.h"
|
||||
#include "gutils.h"
|
||||
#include "galias.h"
|
||||
|
||||
/* keep enum and structure of gpattern.c and patterntest.c in sync */
|
||||
typedef enum
|
||||
{
|
||||
G_MATCH_ALL, /* "*A?A*" */
|
||||
G_MATCH_ALL_TAIL, /* "*A?AA" */
|
||||
G_MATCH_HEAD, /* "AAAA*" */
|
||||
G_MATCH_TAIL, /* "*AAAA" */
|
||||
G_MATCH_EXACT, /* "AAAAA" */
|
||||
G_MATCH_LAST
|
||||
} GMatchType;
|
||||
|
||||
struct _GPatternSpec
|
||||
{
|
||||
GMatchType match_type;
|
||||
guint pattern_length;
|
||||
guint min_length;
|
||||
guint max_length;
|
||||
gchar *pattern;
|
||||
};
|
||||
|
||||
|
||||
/* --- functions --- */
|
||||
static inline gboolean
|
||||
g_pattern_ph_match (const gchar *match_pattern,
|
||||
const gchar *match_string,
|
||||
gboolean *wildcard_reached_p)
|
||||
{
|
||||
register const gchar *pattern, *string;
|
||||
register gchar ch;
|
||||
|
||||
pattern = match_pattern;
|
||||
string = match_string;
|
||||
|
||||
ch = *pattern;
|
||||
pattern++;
|
||||
while (ch)
|
||||
{
|
||||
switch (ch)
|
||||
{
|
||||
case '?':
|
||||
if (!*string)
|
||||
return FALSE;
|
||||
string = g_utf8_next_char (string);
|
||||
break;
|
||||
|
||||
case '*':
|
||||
*wildcard_reached_p = TRUE;
|
||||
do
|
||||
{
|
||||
ch = *pattern;
|
||||
pattern++;
|
||||
if (ch == '?')
|
||||
{
|
||||
if (!*string)
|
||||
return FALSE;
|
||||
string = g_utf8_next_char (string);
|
||||
}
|
||||
}
|
||||
while (ch == '*' || ch == '?');
|
||||
if (!ch)
|
||||
return TRUE;
|
||||
do
|
||||
{
|
||||
gboolean next_wildcard_reached = FALSE;
|
||||
while (ch != *string)
|
||||
{
|
||||
if (!*string)
|
||||
return FALSE;
|
||||
string = g_utf8_next_char (string);
|
||||
}
|
||||
string++;
|
||||
if (g_pattern_ph_match (pattern, string, &next_wildcard_reached))
|
||||
return TRUE;
|
||||
if (next_wildcard_reached)
|
||||
/* the forthcoming pattern substring up to the next wildcard has
|
||||
* been matched, but a mismatch occoured for the rest of the
|
||||
* pattern, following the next wildcard.
|
||||
* there's no need to advance the current match position any
|
||||
* further if the rest pattern will not match.
|
||||
*/
|
||||
return FALSE;
|
||||
}
|
||||
while (*string);
|
||||
break;
|
||||
|
||||
default:
|
||||
if (ch == *string)
|
||||
string++;
|
||||
else
|
||||
return FALSE;
|
||||
break;
|
||||
}
|
||||
|
||||
ch = *pattern;
|
||||
pattern++;
|
||||
}
|
||||
|
||||
return *string == 0;
|
||||
}
|
||||
|
||||
gboolean
|
||||
g_pattern_match (GPatternSpec *pspec,
|
||||
guint string_length,
|
||||
const gchar *string,
|
||||
const gchar *string_reversed)
|
||||
{
|
||||
g_return_val_if_fail (pspec != NULL, FALSE);
|
||||
g_return_val_if_fail (string != NULL, FALSE);
|
||||
|
||||
if (string_length < pspec->min_length ||
|
||||
string_length > pspec->max_length)
|
||||
return FALSE;
|
||||
|
||||
switch (pspec->match_type)
|
||||
{
|
||||
gboolean dummy;
|
||||
case G_MATCH_ALL:
|
||||
return g_pattern_ph_match (pspec->pattern, string, &dummy);
|
||||
case G_MATCH_ALL_TAIL:
|
||||
if (string_reversed)
|
||||
return g_pattern_ph_match (pspec->pattern, string_reversed, &dummy);
|
||||
else
|
||||
{
|
||||
gboolean result;
|
||||
gchar *tmp;
|
||||
tmp = g_utf8_strreverse (string, string_length);
|
||||
result = g_pattern_ph_match (pspec->pattern, tmp, &dummy);
|
||||
g_free (tmp);
|
||||
return result;
|
||||
}
|
||||
case G_MATCH_HEAD:
|
||||
if (pspec->pattern_length == string_length)
|
||||
return strcmp (pspec->pattern, string) == 0;
|
||||
else if (pspec->pattern_length)
|
||||
return strncmp (pspec->pattern, string, pspec->pattern_length) == 0;
|
||||
else
|
||||
return TRUE;
|
||||
case G_MATCH_TAIL:
|
||||
if (pspec->pattern_length)
|
||||
return strcmp (pspec->pattern, string + (string_length - pspec->pattern_length)) == 0;
|
||||
else
|
||||
return TRUE;
|
||||
case G_MATCH_EXACT:
|
||||
if (pspec->pattern_length != string_length)
|
||||
return FALSE;
|
||||
else
|
||||
return strcmp (pspec->pattern, string) == 0;
|
||||
default:
|
||||
g_return_val_if_fail (pspec->match_type < G_MATCH_LAST, FALSE);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
GPatternSpec*
|
||||
g_pattern_spec_new (const gchar *pattern)
|
||||
{
|
||||
GPatternSpec *pspec;
|
||||
gboolean seen_joker = FALSE, seen_wildcard = FALSE, more_wildcards = FALSE;
|
||||
gint hw_pos = -1, tw_pos = -1, hj_pos = -1, tj_pos = -1;
|
||||
gboolean follows_wildcard = FALSE;
|
||||
guint pending_jokers = 0;
|
||||
const gchar *s;
|
||||
gchar *d;
|
||||
guint i;
|
||||
|
||||
g_return_val_if_fail (pattern != NULL, NULL);
|
||||
|
||||
/* canonicalize pattern and collect necessary stats */
|
||||
pspec = g_new (GPatternSpec, 1);
|
||||
pspec->pattern_length = strlen (pattern);
|
||||
pspec->min_length = 0;
|
||||
pspec->max_length = 0;
|
||||
pspec->pattern = g_new (gchar, pspec->pattern_length + 1);
|
||||
d = pspec->pattern;
|
||||
for (i = 0, s = pattern; *s != 0; s++)
|
||||
{
|
||||
switch (*s)
|
||||
{
|
||||
case '*':
|
||||
if (follows_wildcard) /* compress multiple wildcards */
|
||||
{
|
||||
pspec->pattern_length--;
|
||||
continue;
|
||||
}
|
||||
follows_wildcard = TRUE;
|
||||
if (hw_pos < 0)
|
||||
hw_pos = i;
|
||||
tw_pos = i;
|
||||
break;
|
||||
case '?':
|
||||
pending_jokers++;
|
||||
pspec->min_length++;
|
||||
pspec->max_length += 4; /* maximum UTF-8 character length */
|
||||
continue;
|
||||
default:
|
||||
for (; pending_jokers; pending_jokers--, i++) {
|
||||
*d++ = '?';
|
||||
if (hj_pos < 0)
|
||||
hj_pos = i;
|
||||
tj_pos = i;
|
||||
}
|
||||
follows_wildcard = FALSE;
|
||||
pspec->min_length++;
|
||||
pspec->max_length++;
|
||||
break;
|
||||
}
|
||||
*d++ = *s;
|
||||
i++;
|
||||
}
|
||||
for (; pending_jokers; pending_jokers--) {
|
||||
*d++ = '?';
|
||||
if (hj_pos < 0)
|
||||
hj_pos = i;
|
||||
tj_pos = i;
|
||||
}
|
||||
*d++ = 0;
|
||||
seen_joker = hj_pos >= 0;
|
||||
seen_wildcard = hw_pos >= 0;
|
||||
more_wildcards = seen_wildcard && hw_pos != tw_pos;
|
||||
if (seen_wildcard)
|
||||
pspec->max_length = G_MAXUINT;
|
||||
|
||||
/* special case sole head/tail wildcard or exact matches */
|
||||
if (!seen_joker && !more_wildcards)
|
||||
{
|
||||
if (pspec->pattern[0] == '*')
|
||||
{
|
||||
pspec->match_type = G_MATCH_TAIL;
|
||||
memmove (pspec->pattern, pspec->pattern + 1, --pspec->pattern_length);
|
||||
pspec->pattern[pspec->pattern_length] = 0;
|
||||
return pspec;
|
||||
}
|
||||
if (pspec->pattern_length > 0 &&
|
||||
pspec->pattern[pspec->pattern_length - 1] == '*')
|
||||
{
|
||||
pspec->match_type = G_MATCH_HEAD;
|
||||
pspec->pattern[--pspec->pattern_length] = 0;
|
||||
return pspec;
|
||||
}
|
||||
if (!seen_wildcard)
|
||||
{
|
||||
pspec->match_type = G_MATCH_EXACT;
|
||||
return pspec;
|
||||
}
|
||||
}
|
||||
|
||||
/* now just need to distinguish between head or tail match start */
|
||||
tw_pos = pspec->pattern_length - 1 - tw_pos; /* last pos to tail distance */
|
||||
tj_pos = pspec->pattern_length - 1 - tj_pos; /* last pos to tail distance */
|
||||
if (seen_wildcard)
|
||||
pspec->match_type = tw_pos > hw_pos ? G_MATCH_ALL_TAIL : G_MATCH_ALL;
|
||||
else /* seen_joker */
|
||||
pspec->match_type = tj_pos > hj_pos ? G_MATCH_ALL_TAIL : G_MATCH_ALL;
|
||||
if (pspec->match_type == G_MATCH_ALL_TAIL) {
|
||||
gchar *tmp = pspec->pattern;
|
||||
pspec->pattern = g_utf8_strreverse (pspec->pattern, pspec->pattern_length);
|
||||
g_free (tmp);
|
||||
}
|
||||
return pspec;
|
||||
}
|
||||
|
||||
void
|
||||
g_pattern_spec_free (GPatternSpec *pspec)
|
||||
{
|
||||
g_return_if_fail (pspec != NULL);
|
||||
|
||||
g_free (pspec->pattern);
|
||||
g_free (pspec);
|
||||
}
|
||||
|
||||
gboolean
|
||||
g_pattern_spec_equal (GPatternSpec *pspec1,
|
||||
GPatternSpec *pspec2)
|
||||
{
|
||||
g_return_val_if_fail (pspec1 != NULL, FALSE);
|
||||
g_return_val_if_fail (pspec2 != NULL, FALSE);
|
||||
|
||||
return (pspec1->pattern_length == pspec2->pattern_length &&
|
||||
pspec1->match_type == pspec2->match_type &&
|
||||
strcmp (pspec1->pattern, pspec2->pattern) == 0);
|
||||
}
|
||||
|
||||
gboolean
|
||||
g_pattern_match_string (GPatternSpec *pspec,
|
||||
const gchar *string)
|
||||
{
|
||||
g_return_val_if_fail (pspec != NULL, FALSE);
|
||||
g_return_val_if_fail (string != NULL, FALSE);
|
||||
|
||||
return g_pattern_match (pspec, strlen (string), string, NULL);
|
||||
}
|
||||
|
||||
gboolean
|
||||
g_pattern_match_simple (const gchar *pattern,
|
||||
const gchar *string)
|
||||
{
|
||||
GPatternSpec *pspec;
|
||||
gboolean ergo;
|
||||
|
||||
g_return_val_if_fail (pattern != NULL, FALSE);
|
||||
g_return_val_if_fail (string != NULL, FALSE);
|
||||
|
||||
pspec = g_pattern_spec_new (pattern);
|
||||
ergo = g_pattern_match (pspec, strlen (string), string, NULL);
|
||||
g_pattern_spec_free (pspec);
|
||||
|
||||
return ergo;
|
||||
}
|
||||
|
||||
#define __G_PATTERN_C__
|
||||
#include "galiasdef.c"
|
|
@ -0,0 +1,49 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997, 1999 Peter Mattis, Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
|
||||
#error "Only <glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __G_PATTERN_H__
|
||||
#define __G_PATTERN_H__
|
||||
|
||||
#include <glib/gtypes.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
typedef struct _GPatternSpec GPatternSpec;
|
||||
|
||||
GPatternSpec* g_pattern_spec_new (const gchar *pattern);
|
||||
void g_pattern_spec_free (GPatternSpec *pspec);
|
||||
gboolean g_pattern_spec_equal (GPatternSpec *pspec1,
|
||||
GPatternSpec *pspec2);
|
||||
gboolean g_pattern_match (GPatternSpec *pspec,
|
||||
guint string_length,
|
||||
const gchar *string,
|
||||
const gchar *string_reversed);
|
||||
gboolean g_pattern_match_string (GPatternSpec *pspec,
|
||||
const gchar *string);
|
||||
gboolean g_pattern_match_simple (const gchar *pattern,
|
||||
const gchar *string);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_PATTERN_H__ */
|
|
@ -0,0 +1,430 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* gpoll.c: poll(2) abstraction
|
||||
* Copyright 1998 Owen Taylor
|
||||
* Copyright 2008 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
/*
|
||||
* MT safe
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
/* Uncomment the next line (and the corresponding line in gmain.c) to
|
||||
* enable debugging printouts if the environment variable
|
||||
* G_MAIN_POLL_DEBUG is set to some value.
|
||||
*/
|
||||
/* #define G_MAIN_POLL_DEBUG */
|
||||
|
||||
#ifdef _WIN32
|
||||
/* Always enable debugging printout on Windows, as it is more often
|
||||
* needed there...
|
||||
*/
|
||||
#define G_MAIN_POLL_DEBUG
|
||||
#endif
|
||||
|
||||
#include "glib.h"
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
#include <sys/time.h>
|
||||
#endif /* HAVE_SYS_TIME_H */
|
||||
#ifdef GLIB_HAVE_SYS_POLL_H
|
||||
# include <sys/poll.h>
|
||||
# undef events /* AIX 4.1.5 & 4.3.2 define this for SVR3,4 compatibility */
|
||||
# undef revents /* AIX 4.1.5 & 4.3.2 define this for SVR3,4 compatibility */
|
||||
|
||||
/* The poll() emulation on OS/X doesn't handle fds=NULL, nfds=0,
|
||||
* so we prefer our own poll emulation.
|
||||
*/
|
||||
#if defined(_POLL_EMUL_H_) || defined(BROKEN_POLL)
|
||||
#undef HAVE_POLL
|
||||
#endif
|
||||
|
||||
#endif /* GLIB_HAVE_SYS_POLL_H */
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif /* HAVE_UNISTD_H */
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
#define STRICT
|
||||
#include <windows.h>
|
||||
#endif /* G_OS_WIN32 */
|
||||
|
||||
#include "galias.h"
|
||||
|
||||
#ifdef G_MAIN_POLL_DEBUG
|
||||
extern gboolean _g_main_poll_debug;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_POLL
|
||||
/* SunOS has poll, but doesn't provide a prototype. */
|
||||
# if defined (sun) && !defined (__SVR4)
|
||||
extern gint poll (struct pollfd *fds, guint nfsd, gint timeout);
|
||||
# endif /* !sun */
|
||||
|
||||
/**
|
||||
* g_poll:
|
||||
* @fds: file descriptors to poll
|
||||
* @nfds: the number of file descriptors in @fds
|
||||
* @timeout: amount of time to wait, in milliseconds, or -1 to wait forever
|
||||
*
|
||||
* Polls @fds, as with the poll() system call, but portably. (On
|
||||
* systems that don't have poll(), it is emulated using select().)
|
||||
* This is used internally by #GMainContext, but it can be called
|
||||
* directly if you need to block until a file descriptor is ready, but
|
||||
* don't want to run the full main loop.
|
||||
*
|
||||
* Each element of @fds is a #GPollFD describing a single file
|
||||
* descriptor to poll. The %fd field indicates the file descriptor,
|
||||
* and the %events field indicates the events to poll for. On return,
|
||||
* the %revents fields will be filled with the events that actually
|
||||
* occurred.
|
||||
*
|
||||
* On POSIX systems, the file descriptors in @fds can be any sort of
|
||||
* file descriptor, but the situation is much more complicated on
|
||||
* Windows. If you need to use g_poll() in code that has to run on
|
||||
* Windows, the easiest solution is to construct all of your
|
||||
* #GPollFD<!-- -->s with g_io_channel_win32_make_pollfd().
|
||||
*
|
||||
* Return value: the number of entries in @fds whose %revents fields
|
||||
* were filled in, or 0 if the operation timed out, or -1 on error or
|
||||
* if the call was interrupted.
|
||||
*
|
||||
* Since: 2.20
|
||||
**/
|
||||
gint
|
||||
g_poll (GPollFD *fds,
|
||||
guint nfds,
|
||||
gint timeout)
|
||||
{
|
||||
return poll ((struct pollfd *)fds, nfds, timeout);
|
||||
}
|
||||
|
||||
#else /* !HAVE_POLL */
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
|
||||
static int
|
||||
poll_rest (gboolean poll_msgs,
|
||||
HANDLE *handles,
|
||||
gint nhandles,
|
||||
GPollFD *fds,
|
||||
guint nfds,
|
||||
gint timeout)
|
||||
{
|
||||
DWORD ready;
|
||||
GPollFD *f;
|
||||
int recursed_result;
|
||||
|
||||
if (poll_msgs)
|
||||
{
|
||||
/* Wait for either messages or handles
|
||||
* -> Use MsgWaitForMultipleObjectsEx
|
||||
*/
|
||||
if (_g_main_poll_debug)
|
||||
g_print (" MsgWaitForMultipleObjectsEx(%d, %d)\n", nhandles, timeout);
|
||||
|
||||
ready = MsgWaitForMultipleObjectsEx (nhandles, handles, timeout,
|
||||
QS_ALLINPUT, MWMO_ALERTABLE);
|
||||
|
||||
if (ready == WAIT_FAILED)
|
||||
{
|
||||
gchar *emsg = g_win32_error_message (GetLastError ());
|
||||
g_warning ("MsgWaitForMultipleObjectsEx failed: %s", emsg);
|
||||
g_free (emsg);
|
||||
}
|
||||
}
|
||||
else if (nhandles == 0)
|
||||
{
|
||||
/* No handles to wait for, just the timeout */
|
||||
if (timeout == INFINITE)
|
||||
ready = WAIT_FAILED;
|
||||
else
|
||||
{
|
||||
SleepEx (timeout, TRUE);
|
||||
ready = WAIT_TIMEOUT;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Wait for just handles
|
||||
* -> Use WaitForMultipleObjectsEx
|
||||
*/
|
||||
if (_g_main_poll_debug)
|
||||
g_print (" WaitForMultipleObjectsEx(%d, %d)\n", nhandles, timeout);
|
||||
|
||||
ready = WaitForMultipleObjectsEx (nhandles, handles, FALSE, timeout, TRUE);
|
||||
if (ready == WAIT_FAILED)
|
||||
{
|
||||
gchar *emsg = g_win32_error_message (GetLastError ());
|
||||
g_warning ("WaitForMultipleObjectsEx failed: %s", emsg);
|
||||
g_free (emsg);
|
||||
}
|
||||
}
|
||||
|
||||
if (_g_main_poll_debug)
|
||||
g_print (" wait returns %ld%s\n",
|
||||
ready,
|
||||
(ready == WAIT_FAILED ? " (WAIT_FAILED)" :
|
||||
(ready == WAIT_TIMEOUT ? " (WAIT_TIMEOUT)" :
|
||||
(poll_msgs && ready == WAIT_OBJECT_0 + nhandles ? " (msg)" : ""))));
|
||||
|
||||
if (ready == WAIT_FAILED)
|
||||
return -1;
|
||||
else if (ready == WAIT_TIMEOUT ||
|
||||
ready == WAIT_IO_COMPLETION)
|
||||
return 0;
|
||||
else if (poll_msgs && ready == WAIT_OBJECT_0 + nhandles)
|
||||
{
|
||||
for (f = fds; f < &fds[nfds]; ++f)
|
||||
if (f->fd == G_WIN32_MSG_HANDLE && f->events & G_IO_IN)
|
||||
f->revents |= G_IO_IN;
|
||||
|
||||
/* If we have a timeout, or no handles to poll, be satisfied
|
||||
* with just noticing we have messages waiting.
|
||||
*/
|
||||
if (timeout != 0 || nhandles == 0)
|
||||
return 1;
|
||||
|
||||
/* If no timeout and handles to poll, recurse to poll them,
|
||||
* too.
|
||||
*/
|
||||
recursed_result = poll_rest (FALSE, handles, nhandles, fds, nfds, 0);
|
||||
return (recursed_result == -1) ? -1 : 1 + recursed_result;
|
||||
}
|
||||
else if (ready >= WAIT_OBJECT_0 && ready < WAIT_OBJECT_0 + nhandles)
|
||||
{
|
||||
for (f = fds; f < &fds[nfds]; ++f)
|
||||
{
|
||||
if ((HANDLE) f->fd == handles[ready - WAIT_OBJECT_0])
|
||||
{
|
||||
f->revents = f->events;
|
||||
if (_g_main_poll_debug)
|
||||
g_print (" got event %p\n", (HANDLE) f->fd);
|
||||
}
|
||||
}
|
||||
|
||||
/* If no timeout and polling several handles, recurse to poll
|
||||
* the rest of them.
|
||||
*/
|
||||
if (timeout == 0 && nhandles > 1)
|
||||
{
|
||||
/* Remove the handle that fired */
|
||||
int i;
|
||||
if (ready < nhandles - 1)
|
||||
for (i = ready - WAIT_OBJECT_0 + 1; i < nhandles; i++)
|
||||
handles[i-1] = handles[i];
|
||||
nhandles--;
|
||||
recursed_result = poll_rest (FALSE, handles, nhandles, fds, nfds, 0);
|
||||
return (recursed_result == -1) ? -1 : 1 + recursed_result;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
gint
|
||||
g_poll (GPollFD *fds,
|
||||
guint nfds,
|
||||
gint timeout)
|
||||
{
|
||||
HANDLE handles[MAXIMUM_WAIT_OBJECTS];
|
||||
gboolean poll_msgs = FALSE;
|
||||
GPollFD *f;
|
||||
gint nhandles = 0;
|
||||
int retval;
|
||||
|
||||
if (_g_main_poll_debug)
|
||||
g_print ("g_poll: waiting for");
|
||||
|
||||
for (f = fds; f < &fds[nfds]; ++f)
|
||||
if (f->fd == G_WIN32_MSG_HANDLE && (f->events & G_IO_IN))
|
||||
{
|
||||
if (_g_main_poll_debug && !poll_msgs)
|
||||
g_print (" MSG");
|
||||
poll_msgs = TRUE;
|
||||
}
|
||||
else if (f->fd > 0)
|
||||
{
|
||||
/* Don't add the same handle several times into the array, as
|
||||
* docs say that is not allowed, even if it actually does seem
|
||||
* to work.
|
||||
*/
|
||||
gint i;
|
||||
|
||||
for (i = 0; i < nhandles; i++)
|
||||
if (handles[i] == (HANDLE) f->fd)
|
||||
break;
|
||||
|
||||
if (i == nhandles)
|
||||
{
|
||||
if (nhandles == MAXIMUM_WAIT_OBJECTS)
|
||||
{
|
||||
g_warning ("Too many handles to wait for!\n");
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_g_main_poll_debug)
|
||||
g_print (" %p", (HANDLE) f->fd);
|
||||
handles[nhandles++] = (HANDLE) f->fd;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_g_main_poll_debug)
|
||||
g_print ("\n");
|
||||
|
||||
for (f = fds; f < &fds[nfds]; ++f)
|
||||
f->revents = 0;
|
||||
|
||||
if (timeout == -1)
|
||||
timeout = INFINITE;
|
||||
|
||||
/* Polling for several things? */
|
||||
if (nhandles > 1 || (nhandles > 0 && poll_msgs))
|
||||
{
|
||||
/* First check if one or several of them are immediately
|
||||
* available
|
||||
*/
|
||||
retval = poll_rest (poll_msgs, handles, nhandles, fds, nfds, 0);
|
||||
|
||||
/* If not, and we have a significant timeout, poll again with
|
||||
* timeout then. Note that this will return indication for only
|
||||
* one event, or only for messages. We ignore timeouts less than
|
||||
* ten milliseconds as they are mostly pointless on Windows, the
|
||||
* MsgWaitForMultipleObjectsEx() call will timeout right away
|
||||
* anyway.
|
||||
*/
|
||||
if (retval == 0 && (timeout == INFINITE || timeout >= 10))
|
||||
retval = poll_rest (poll_msgs, handles, nhandles, fds, nfds, timeout);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Just polling for one thing, so no need to check first if
|
||||
* available immediately
|
||||
*/
|
||||
retval = poll_rest (poll_msgs, handles, nhandles, fds, nfds, timeout);
|
||||
}
|
||||
|
||||
if (retval == -1)
|
||||
for (f = fds; f < &fds[nfds]; ++f)
|
||||
f->revents = 0;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
#else /* !G_OS_WIN32 */
|
||||
|
||||
/* The following implementation of poll() comes from the GNU C Library.
|
||||
* Copyright (C) 1994, 1996, 1997 Free Software Foundation, Inc.
|
||||
*/
|
||||
|
||||
#include <string.h> /* for bzero on BSD systems */
|
||||
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
#include <sys/select.h>
|
||||
#endif /* HAVE_SYS_SELECT_H */
|
||||
|
||||
#ifdef G_OS_BEOS
|
||||
#undef NO_FD_SET
|
||||
#endif /* G_OS_BEOS */
|
||||
|
||||
#ifndef NO_FD_SET
|
||||
# define SELECT_MASK fd_set
|
||||
#else /* !NO_FD_SET */
|
||||
# ifndef _AIX
|
||||
typedef long fd_mask;
|
||||
# endif /* _AIX */
|
||||
# ifdef _IBMR2
|
||||
# define SELECT_MASK void
|
||||
# else /* !_IBMR2 */
|
||||
# define SELECT_MASK int
|
||||
# endif /* !_IBMR2 */
|
||||
#endif /* !NO_FD_SET */
|
||||
|
||||
gint
|
||||
g_poll (GPollFD *fds,
|
||||
guint nfds,
|
||||
gint timeout)
|
||||
{
|
||||
struct timeval tv;
|
||||
SELECT_MASK rset, wset, xset;
|
||||
GPollFD *f;
|
||||
int ready;
|
||||
int maxfd = 0;
|
||||
|
||||
FD_ZERO (&rset);
|
||||
FD_ZERO (&wset);
|
||||
FD_ZERO (&xset);
|
||||
|
||||
for (f = fds; f < &fds[nfds]; ++f)
|
||||
if (f->fd >= 0)
|
||||
{
|
||||
if (f->events & G_IO_IN)
|
||||
FD_SET (f->fd, &rset);
|
||||
if (f->events & G_IO_OUT)
|
||||
FD_SET (f->fd, &wset);
|
||||
if (f->events & G_IO_PRI)
|
||||
FD_SET (f->fd, &xset);
|
||||
if (f->fd > maxfd && (f->events & (G_IO_IN|G_IO_OUT|G_IO_PRI)))
|
||||
maxfd = f->fd;
|
||||
}
|
||||
|
||||
tv.tv_sec = timeout / 1000;
|
||||
tv.tv_usec = (timeout % 1000) * 1000;
|
||||
|
||||
ready = select (maxfd + 1, &rset, &wset, &xset,
|
||||
timeout == -1 ? NULL : &tv);
|
||||
if (ready > 0)
|
||||
for (f = fds; f < &fds[nfds]; ++f)
|
||||
{
|
||||
f->revents = 0;
|
||||
if (f->fd >= 0)
|
||||
{
|
||||
if (FD_ISSET (f->fd, &rset))
|
||||
f->revents |= G_IO_IN;
|
||||
if (FD_ISSET (f->fd, &wset))
|
||||
f->revents |= G_IO_OUT;
|
||||
if (FD_ISSET (f->fd, &xset))
|
||||
f->revents |= G_IO_PRI;
|
||||
}
|
||||
}
|
||||
|
||||
return ready;
|
||||
}
|
||||
|
||||
#endif /* !G_OS_WIN32 */
|
||||
|
||||
#endif /* !HAVE_POLL */
|
||||
|
||||
#define __G_POLL_C__
|
||||
#include "galiasdef.c"
|
|
@ -0,0 +1,93 @@
|
|||
/* gpoll.h - poll(2) support
|
||||
* Copyright (C) 2008 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#if !defined (__GLIB_H_INSIDE__) && !defined (__G_MAIN_H__) && !defined (GLIB_COMPILATION)
|
||||
#error "Only <glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __G_POLL_H__
|
||||
#define __G_POLL_H__
|
||||
|
||||
#include <glib/gtypes.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/* Any definitions using GPollFD or GPollFunc are primarily
|
||||
* for Unix and not guaranteed to be the compatible on all
|
||||
* operating systems on which GLib runs. Right now, the
|
||||
* GLib does use these functions on Win32 as well, but interprets
|
||||
* them in a fairly different way than on Unix. If you use
|
||||
* these definitions, you are should be prepared to recode
|
||||
* for different operating systems.
|
||||
*
|
||||
* Note that on systems with a working poll(2), that function is used
|
||||
* in place of g_poll(). Thus g_poll() must have the same signature as
|
||||
* poll(), meaning GPollFD must have the same layout as struct pollfd.
|
||||
*
|
||||
*
|
||||
* On Win32, the fd in a GPollFD should be Win32 HANDLE (*not* a file
|
||||
* descriptor as provided by the C runtime) that can be used by
|
||||
* MsgWaitForMultipleObjects. This does *not* include file handles
|
||||
* from CreateFile, SOCKETs, nor pipe handles. (But you can use
|
||||
* WSAEventSelect to signal events when a SOCKET is readable).
|
||||
*
|
||||
* On Win32, fd can also be the special value G_WIN32_MSG_HANDLE to
|
||||
* indicate polling for messages.
|
||||
*
|
||||
* But note that G_WIN32_MSG_HANDLE GPollFDs should not be used by GDK
|
||||
* (GTK) programs, as GDK itself wants to read messages and convert them
|
||||
* to GDK events.
|
||||
*
|
||||
* So, unless you really know what you are doing, it's best not to try
|
||||
* to use the main loop polling stuff for your own needs on
|
||||
* Windows.
|
||||
*/
|
||||
typedef struct _GPollFD GPollFD;
|
||||
typedef gint (*GPollFunc) (GPollFD *ufds,
|
||||
guint nfsd,
|
||||
gint timeout_);
|
||||
|
||||
struct _GPollFD
|
||||
{
|
||||
#if defined (G_OS_WIN32) && GLIB_SIZEOF_VOID_P == 8
|
||||
gint64 fd;
|
||||
#else
|
||||
gint fd;
|
||||
#endif
|
||||
gushort events;
|
||||
gushort revents;
|
||||
};
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
#if GLIB_SIZEOF_VOID_P == 8
|
||||
#define G_POLLFD_FORMAT "%#I64x"
|
||||
#else
|
||||
#define G_POLLFD_FORMAT "%#x"
|
||||
#endif
|
||||
#else
|
||||
#define G_POLLFD_FORMAT "%d"
|
||||
#endif
|
||||
|
||||
gint g_poll (GPollFD *fds,
|
||||
guint nfds,
|
||||
gint timeout);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_POLL_H__ */
|
|
@ -0,0 +1,90 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
/*
|
||||
* MT safe
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "glib.h"
|
||||
#include "galias.h"
|
||||
|
||||
|
||||
static const guint g_primes[] =
|
||||
{
|
||||
11,
|
||||
19,
|
||||
37,
|
||||
73,
|
||||
109,
|
||||
163,
|
||||
251,
|
||||
367,
|
||||
557,
|
||||
823,
|
||||
1237,
|
||||
1861,
|
||||
2777,
|
||||
4177,
|
||||
6247,
|
||||
9371,
|
||||
14057,
|
||||
21089,
|
||||
31627,
|
||||
47431,
|
||||
71143,
|
||||
106721,
|
||||
160073,
|
||||
240101,
|
||||
360163,
|
||||
540217,
|
||||
810343,
|
||||
1215497,
|
||||
1823231,
|
||||
2734867,
|
||||
4102283,
|
||||
6153409,
|
||||
9230113,
|
||||
13845163,
|
||||
};
|
||||
|
||||
static const guint g_nprimes = sizeof (g_primes) / sizeof (g_primes[0]);
|
||||
|
||||
guint
|
||||
g_spaced_primes_closest (guint num)
|
||||
{
|
||||
gint i;
|
||||
|
||||
for (i = 0; i < g_nprimes; i++)
|
||||
if (g_primes[i] > num)
|
||||
return g_primes[i];
|
||||
|
||||
return g_primes[g_nprimes - 1];
|
||||
}
|
||||
|
||||
#define __G_PRIMES_C__
|
||||
#include "galiasdef.c"
|
|
@ -0,0 +1,51 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
|
||||
#error "Only <glib.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __G_PRIMES_H__
|
||||
#define __G_PRIMES_H__
|
||||
|
||||
#include <glib/gtypes.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/* Prime numbers.
|
||||
*/
|
||||
|
||||
/* This function returns prime numbers spaced by approximately 1.5-2.0
|
||||
* and is for use in resizing data structures which prefer
|
||||
* prime-valued sizes. The closest spaced prime function returns the
|
||||
* next largest prime, or the highest it knows about which is about
|
||||
* MAXINT/4.
|
||||
*/
|
||||
guint g_spaced_primes_closest (guint num) G_GNUC_CONST;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_PRIMES_H__ */
|
|
@ -0,0 +1,344 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997, 2002 Peter Mattis, Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#define _GNU_SOURCE /* For vasprintf */
|
||||
#endif
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "glib.h"
|
||||
#include "gprintf.h"
|
||||
#include "gprintfint.h"
|
||||
|
||||
#include "galias.h"
|
||||
|
||||
/**
|
||||
* g_printf:
|
||||
* @format: a standard printf() format string, but notice
|
||||
* <link linkend="string-precision">string precision pitfalls</link>.
|
||||
* @Varargs: the arguments to insert in the output.
|
||||
*
|
||||
* An implementation of the standard printf() function which supports
|
||||
* positional parameters, as specified in the Single Unix Specification.
|
||||
*
|
||||
* Returns: the number of bytes printed.
|
||||
*
|
||||
* Since: 2.2
|
||||
**/
|
||||
gint
|
||||
g_printf (gchar const *format,
|
||||
...)
|
||||
{
|
||||
va_list args;
|
||||
gint retval;
|
||||
|
||||
va_start (args, format);
|
||||
retval = g_vprintf (format, args);
|
||||
va_end (args);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_fprintf:
|
||||
* @file: the stream to write to.
|
||||
* @format: a standard printf() format string, but notice
|
||||
* <link linkend="string-precision">string precision pitfalls</link>.
|
||||
* @Varargs: the arguments to insert in the output.
|
||||
*
|
||||
* An implementation of the standard fprintf() function which supports
|
||||
* positional parameters, as specified in the Single Unix Specification.
|
||||
*
|
||||
* Returns: the number of bytes printed.
|
||||
*
|
||||
* Since: 2.2
|
||||
**/
|
||||
gint
|
||||
g_fprintf (FILE *file,
|
||||
gchar const *format,
|
||||
...)
|
||||
{
|
||||
va_list args;
|
||||
gint retval;
|
||||
|
||||
va_start (args, format);
|
||||
retval = g_vfprintf (file, format, args);
|
||||
va_end (args);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_sprintf:
|
||||
* @string: A pointer to a memory buffer to contain the resulting string. It
|
||||
* is up to the caller to ensure that the allocated buffer is large
|
||||
* enough to hold the formatted result
|
||||
* @format: a standard printf() format string, but notice
|
||||
* <link linkend="string-precision">string precision pitfalls</link>.
|
||||
* @Varargs: the arguments to insert in the output.
|
||||
*
|
||||
* An implementation of the standard sprintf() function which supports
|
||||
* positional parameters, as specified in the Single Unix Specification.
|
||||
*
|
||||
* Returns: the number of bytes printed.
|
||||
*
|
||||
* Since: 2.2
|
||||
**/
|
||||
gint
|
||||
g_sprintf (gchar *string,
|
||||
gchar const *format,
|
||||
...)
|
||||
{
|
||||
va_list args;
|
||||
gint retval;
|
||||
|
||||
va_start (args, format);
|
||||
retval = g_vsprintf (string, format, args);
|
||||
va_end (args);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_snprintf:
|
||||
* @string: the buffer to hold the output.
|
||||
* @n: the maximum number of bytes to produce (including the
|
||||
* terminating nul character).
|
||||
* @format: a standard printf() format string, but notice
|
||||
* <link linkend="string-precision">string precision pitfalls</link>.
|
||||
* @Varargs: the arguments to insert in the output.
|
||||
*
|
||||
* A safer form of the standard sprintf() function. The output is guaranteed
|
||||
* to not exceed @n characters (including the terminating nul character), so
|
||||
* it is easy to ensure that a buffer overflow cannot occur.
|
||||
*
|
||||
* See also g_strdup_printf().
|
||||
*
|
||||
* In versions of GLib prior to 1.2.3, this function may return -1 if the
|
||||
* output was truncated, and the truncated string may not be nul-terminated.
|
||||
* In versions prior to 1.3.12, this function returns the length of the output
|
||||
* string.
|
||||
*
|
||||
* The return value of g_snprintf() conforms to the snprintf()
|
||||
* function as standardized in ISO C99. Note that this is different from
|
||||
* traditional snprintf(), which returns the length of the output string.
|
||||
*
|
||||
* The format string may contain positional parameters, as specified in
|
||||
* the Single Unix Specification.
|
||||
*
|
||||
* Returns: the number of bytes which would be produced if the buffer
|
||||
* was large enough.
|
||||
**/
|
||||
gint
|
||||
g_snprintf (gchar *string,
|
||||
gulong n,
|
||||
gchar const *format,
|
||||
...)
|
||||
{
|
||||
va_list args;
|
||||
gint retval;
|
||||
|
||||
va_start (args, format);
|
||||
retval = g_vsnprintf (string, n, format, args);
|
||||
va_end (args);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_vprintf:
|
||||
* @format: a standard printf() format string, but notice
|
||||
* <link linkend="string-precision">string precision pitfalls</link>.
|
||||
* @args: the list of arguments to insert in the output.
|
||||
*
|
||||
* An implementation of the standard vprintf() function which supports
|
||||
* positional parameters, as specified in the Single Unix Specification.
|
||||
*
|
||||
* Returns: the number of bytes printed.
|
||||
*
|
||||
* Since: 2.2
|
||||
**/
|
||||
gint
|
||||
g_vprintf (gchar const *format,
|
||||
va_list args)
|
||||
{
|
||||
g_return_val_if_fail (format != NULL, -1);
|
||||
|
||||
return _g_vprintf (format, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_vfprintf:
|
||||
* @file: the stream to write to.
|
||||
* @format: a standard printf() format string, but notice
|
||||
* <link linkend="string-precision">string precision pitfalls</link>.
|
||||
* @args: the list of arguments to insert in the output.
|
||||
*
|
||||
* An implementation of the standard fprintf() function which supports
|
||||
* positional parameters, as specified in the Single Unix Specification.
|
||||
*
|
||||
* Returns: the number of bytes printed.
|
||||
*
|
||||
* Since: 2.2
|
||||
**/
|
||||
gint
|
||||
g_vfprintf (FILE *file,
|
||||
gchar const *format,
|
||||
va_list args)
|
||||
{
|
||||
g_return_val_if_fail (format != NULL, -1);
|
||||
|
||||
return _g_vfprintf (file, format, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_vsprintf:
|
||||
* @string: the buffer to hold the output.
|
||||
* @format: a standard printf() format string, but notice
|
||||
* <link linkend="string-precision">string precision pitfalls</link>.
|
||||
* @args: the list of arguments to insert in the output.
|
||||
*
|
||||
* An implementation of the standard vsprintf() function which supports
|
||||
* positional parameters, as specified in the Single Unix Specification.
|
||||
*
|
||||
* Returns: the number of bytes printed.
|
||||
*
|
||||
* Since: 2.2
|
||||
**/
|
||||
gint
|
||||
g_vsprintf (gchar *string,
|
||||
gchar const *format,
|
||||
va_list args)
|
||||
{
|
||||
g_return_val_if_fail (string != NULL, -1);
|
||||
g_return_val_if_fail (format != NULL, -1);
|
||||
|
||||
return _g_vsprintf (string, format, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_vsnprintf:
|
||||
* @string: the buffer to hold the output.
|
||||
* @n: the maximum number of bytes to produce (including the
|
||||
* terminating nul character).
|
||||
* @format: a standard printf() format string, but notice
|
||||
* <link linkend="string-precision">string precision pitfalls</link>.
|
||||
* @args: the list of arguments to insert in the output.
|
||||
*
|
||||
* A safer form of the standard vsprintf() function. The output is guaranteed
|
||||
* to not exceed @n characters (including the terminating nul character), so
|
||||
* it is easy to ensure that a buffer overflow cannot occur.
|
||||
*
|
||||
* See also g_strdup_vprintf().
|
||||
*
|
||||
* In versions of GLib prior to 1.2.3, this function may return -1 if the
|
||||
* output was truncated, and the truncated string may not be nul-terminated.
|
||||
* In versions prior to 1.3.12, this function returns the length of the output
|
||||
* string.
|
||||
*
|
||||
* The return value of g_vsnprintf() conforms to the vsnprintf() function
|
||||
* as standardized in ISO C99. Note that this is different from traditional
|
||||
* vsnprintf(), which returns the length of the output string.
|
||||
*
|
||||
* The format string may contain positional parameters, as specified in
|
||||
* the Single Unix Specification.
|
||||
*
|
||||
* Returns: the number of bytes which would be produced if the buffer
|
||||
* was large enough.
|
||||
*/
|
||||
gint
|
||||
g_vsnprintf (gchar *string,
|
||||
gulong n,
|
||||
gchar const *format,
|
||||
va_list args)
|
||||
{
|
||||
g_return_val_if_fail (n == 0 || string != NULL, -1);
|
||||
g_return_val_if_fail (format != NULL, -1);
|
||||
|
||||
return _g_vsnprintf (string, n, format, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_vasprintf:
|
||||
* @string: the return location for the newly-allocated string.
|
||||
* @format: a standard printf() format string, but notice
|
||||
* <link linkend="string-precision">string precision pitfalls</link>.
|
||||
* @args: the list of arguments to insert in the output.
|
||||
*
|
||||
* An implementation of the GNU vasprintf() function which supports
|
||||
* positional parameters, as specified in the Single Unix Specification.
|
||||
* This function is similar to g_vsprintf(), except that it allocates a
|
||||
* string to hold the output, instead of putting the output in a buffer
|
||||
* you allocate in advance.
|
||||
*
|
||||
* Returns: the number of bytes printed.
|
||||
*
|
||||
* Since: 2.4
|
||||
**/
|
||||
gint
|
||||
g_vasprintf (gchar **string,
|
||||
gchar const *format,
|
||||
va_list args)
|
||||
{
|
||||
gint len;
|
||||
g_return_val_if_fail (string != NULL, -1);
|
||||
|
||||
#if !defined(HAVE_GOOD_PRINTF)
|
||||
|
||||
len = _g_gnulib_vasprintf (string, format, args);
|
||||
if (len < 0)
|
||||
*string = NULL;
|
||||
|
||||
#elif defined (HAVE_VASPRINTF)
|
||||
|
||||
len = vasprintf (string, format, args);
|
||||
if (len < 0)
|
||||
*string = NULL;
|
||||
else if (!g_mem_is_system_malloc ())
|
||||
{
|
||||
/* vasprintf returns malloc-allocated memory */
|
||||
gchar *string1 = g_strndup (*string, len);
|
||||
free (*string);
|
||||
*string = string1;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
{
|
||||
va_list args2;
|
||||
|
||||
G_VA_COPY (args2, args);
|
||||
|
||||
*string = g_new (gchar, g_printf_string_upper_bound (format, args));
|
||||
|
||||
len = _g_vsprintf (*string, format, args2);
|
||||
va_end (args2);
|
||||
}
|
||||
#endif
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
#define __G_PRINTF_C__
|
||||
#include "galiasdef.c"
|
|
@ -0,0 +1,52 @@
|
|||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997, 2002 Peter Mattis, Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __G_PRINTF_H__
|
||||
#define __G_PRINTF_H__
|
||||
|
||||
#include <glib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
gint g_printf (gchar const *format,
|
||||
...) G_GNUC_PRINTF (1, 2);
|
||||
gint g_fprintf (FILE *file,
|
||||
gchar const *format,
|
||||
...) G_GNUC_PRINTF (2, 3);
|
||||
gint g_sprintf (gchar *string,
|
||||
gchar const *format,
|
||||
...) G_GNUC_PRINTF (2, 3);
|
||||
|
||||
gint g_vprintf (gchar const *format,
|
||||
va_list args);
|
||||
gint g_vfprintf (FILE *file,
|
||||
gchar const *format,
|
||||
va_list args);
|
||||
gint g_vsprintf (gchar *string,
|
||||
gchar const *format,
|
||||
va_list args);
|
||||
gint g_vasprintf (gchar **string,
|
||||
gchar const *format,
|
||||
va_list args);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_PRINTF_H__ */
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue