renamed ase to qse
This commit is contained in:
250
qse/lib/cmn/asecmn.bdsproj
Normal file
250
qse/lib/cmn/asecmn.bdsproj
Normal file
@ -0,0 +1,250 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<BorlandProject>
|
||||
<PersonalityInfo>
|
||||
<Option>
|
||||
<Option Name="Personality">CPlusPlusBuilder.Personality</Option>
|
||||
<Option Name="ProjectType">CppStaticLibrary</Option>
|
||||
<Option Name="Version">1.0</Option>
|
||||
<Option Name="GUID">{C16C0B49-6DA4-43F4-9DA8-021728817084}</Option>
|
||||
</Option>
|
||||
</PersonalityInfo>
|
||||
<CPlusPlusBuilder.Personality>
|
||||
<Source>
|
||||
<Source Name="MainSource">misc.c</Source>
|
||||
</Source>
|
||||
<BCBPROJECT>
|
||||
<project version="10.0">
|
||||
<property category="build.config" name="active" value="0"/>
|
||||
<property category="build.config" name="count" value="1"/>
|
||||
<property category="build.config" name="excludedefaultforzero" value="0"/>
|
||||
<property category="build.config.0" name="builddir" value="Debug"/>
|
||||
<property category="build.config.0" name="key" value="Debug_Build"/>
|
||||
<property category="build.config.0" name="name" value="Debug Build"/>
|
||||
<property category="build.config.0" name="settings.win32b" value="default"/>
|
||||
<property category="build.config.0" name="type" value="Toolset"/>
|
||||
<property category="build.config.0" name="win32.win32b.builddir" value="debug"/>
|
||||
<property category="build.config.1" name="key" value="Release_Build"/>
|
||||
<property category="build.config.1" name="name" value="Release Build"/>
|
||||
<property category="build.config.1" name="settings.win32b" value="default"/>
|
||||
<property category="build.config.1" name="type" value="Toolset"/>
|
||||
<property category="build.config.1" name="win32.win32b.builddir" value="release"/>
|
||||
<property category="build.node" name="lastconfig" value="Debug_Build"/>
|
||||
<property category="build.node" name="libraries" value="vcl.lib rtl.lib"/>
|
||||
<property category="build.node" name="name" value="asecmn.lib"/>
|
||||
<property category="build.node" name="packages" value="vclx;vcl;rtl;dbrtl;vcldb;adortl;dbxcds;dbexpress;xmlrtl;vclie;inet;inetdbbde;inetdbxpress;soaprtl;dsnap;bdertl;vcldbx"/>
|
||||
<property category="build.node" name="sparelibs" value="rtl.lib vcl.lib"/>
|
||||
<property category="build.node" name="use_packages" value="0"/>
|
||||
<property category="build.platform" name="active" value="win32"/>
|
||||
<property category="build.platform" name="win32.Debug_Build.toolset" value="win32b"/>
|
||||
<property category="build.platform" name="win32.Release_Build.toolset" value="win32b"/>
|
||||
<property category="build.platform" name="win32.default" value="win32b"/>
|
||||
<property category="build.platform" name="win32.enabled" value="1"/>
|
||||
<property category="build.platform" name="win32.win32b.enabled" value="1"/>
|
||||
<property category="win32.*.win32b.dcc32" name="param.filenames.merge" value="1"/>
|
||||
<property category="win32.*.win32b.tasm32" name="param.listfile.merge" value="1"/>
|
||||
<property category="win32.*.win32b.tasm32" name="param.objfile.merge" value="1"/>
|
||||
<property category="win32.*.win32b.tasm32" name="param.xreffile.merge" value="1"/>
|
||||
<property category="win32.Debug_Build.win32b.bcc32" name="option.A.enabled" value="0"/>
|
||||
<property category="win32.Debug_Build.win32b.bcc32" name="option.AK.enabled" value="0"/>
|
||||
<property category="win32.Debug_Build.win32b.bcc32" name="option.AU.enabled" value="0"/>
|
||||
<property category="win32.Debug_Build.win32b.bcc32" name="option.D.arg.1" value="_DEBUG"/>
|
||||
<property category="win32.Debug_Build.win32b.bcc32" name="option.D.arg.merge" value="1"/>
|
||||
<property category="win32.Debug_Build.win32b.bcc32" name="option.D.enabled" value="1"/>
|
||||
<property category="win32.Debug_Build.win32b.bcc32" name="option.H=.arg.merge" value="1"/>
|
||||
<property category="win32.Debug_Build.win32b.bcc32" name="option.H=.enabled" value="0"/>
|
||||
<property category="win32.Debug_Build.win32b.bcc32" name="option.Hc.enabled" value="0"/>
|
||||
<property category="win32.Debug_Build.win32b.bcc32" name="option.He.enabled" value="0"/>
|
||||
<property category="win32.Debug_Build.win32b.bcc32" name="option.Hs.enabled" value="0"/>
|
||||
<property category="win32.Debug_Build.win32b.bcc32" name="option.Jgi.enabled" value="0"/>
|
||||
<property category="win32.Debug_Build.win32b.bcc32" name="option.Jgx.enabled" value="0"/>
|
||||
<property category="win32.Debug_Build.win32b.bcc32" name="option.Od.enabled" value="1"/>
|
||||
<property category="win32.Debug_Build.win32b.bcc32" name="option.k.enabled" value="1"/>
|
||||
<property category="win32.Debug_Build.win32b.bcc32" name="option.n.arg.1" value="debug"/>
|
||||
<property category="win32.Debug_Build.win32b.bcc32" name="option.n.arg.merge" value="0"/>
|
||||
<property category="win32.Debug_Build.win32b.bcc32" name="option.n.enabled" value="1"/>
|
||||
<property category="win32.Debug_Build.win32b.bcc32" name="option.r.enabled" value="0"/>
|
||||
<property category="win32.Debug_Build.win32b.bcc32" name="option.v.enabled" value="1"/>
|
||||
<property category="win32.Debug_Build.win32b.bcc32" name="option.vG.enabled" value="0"/>
|
||||
<property category="win32.Debug_Build.win32b.bcc32" name="option.vG0.enabled" value="0"/>
|
||||
<property category="win32.Debug_Build.win32b.bcc32" name="option.vi.enabled" value="0"/>
|
||||
<property category="win32.Debug_Build.win32b.bcc32" name="option.y.enabled" value="1"/>
|
||||
<property category="win32.Debug_Build.win32b.dcc32" name="option.$D.enabled" value="1"/>
|
||||
<property category="win32.Debug_Build.win32b.dcc32" name="option.$O.enabled" value="0"/>
|
||||
<property category="win32.Debug_Build.win32b.dcc32" name="option.D.arg.1" value="DEBUG"/>
|
||||
<property category="win32.Debug_Build.win32b.dcc32" name="option.D.arg.merge" value="1"/>
|
||||
<property category="win32.Debug_Build.win32b.dcc32" name="option.D.enabled" value="1"/>
|
||||
<property category="win32.Debug_Build.win32b.dcc32" name="option.V.enabled" value="1"/>
|
||||
<property category="win32.Debug_Build.win32b.ilink32" name="option.D.enabled" value="1"/>
|
||||
<property category="win32.Debug_Build.win32b.ilink32" name="option.Gn.enabled" value="1"/>
|
||||
<property category="win32.Debug_Build.win32b.ilink32" name="option.L.arg.1" value="$(BDS)\lib\debug"/>
|
||||
<property category="win32.Debug_Build.win32b.ilink32" name="option.L.arg.merge" value="1"/>
|
||||
<property category="win32.Debug_Build.win32b.ilink32" name="option.L.enabled" value="1"/>
|
||||
<property category="win32.Debug_Build.win32b.ilink32" name="option.v.enabled" value="1"/>
|
||||
<property category="win32.Debug_Build.win32b.tasm32" name="option.z.enabled" value="1"/>
|
||||
<property category="win32.Debug_Build.win32b.tasm32" name="option.zd.enabled" value="0"/>
|
||||
<property category="win32.Debug_Build.win32b.tasm32" name="option.zi.enabled" value="1"/>
|
||||
<property category="win32.Debug_Build.win32b.tlib" name="option.outputdir.arg.1" value="..\debug\lib"/>
|
||||
<property category="win32.Debug_Build.win32b.tlib" name="option.outputdir.arg.merge" value="0"/>
|
||||
<property category="win32.Debug_Build.win32b.tlib" name="option.outputdir.enabled" value="1"/>
|
||||
<property category="win32.Release_Build.win32b.bcc32" name="container.SelectedWarnings.containerenabled" value="1"/>
|
||||
<property category="win32.Release_Build.win32b.bcc32" name="option.D.arg.1" value="NDEBUG"/>
|
||||
<property category="win32.Release_Build.win32b.bcc32" name="option.D.arg.merge" value="1"/>
|
||||
<property category="win32.Release_Build.win32b.bcc32" name="option.D.enabled" value="1"/>
|
||||
<property category="win32.Release_Build.win32b.bcc32" name="option.H=.arg.merge" value="1"/>
|
||||
<property category="win32.Release_Build.win32b.bcc32" name="option.H=.enabled" value="0"/>
|
||||
<property category="win32.Release_Build.win32b.bcc32" name="option.Hc.enabled" value="0"/>
|
||||
<property category="win32.Release_Build.win32b.bcc32" name="option.He.enabled" value="0"/>
|
||||
<property category="win32.Release_Build.win32b.bcc32" name="option.Hs.enabled" value="0"/>
|
||||
<property category="win32.Release_Build.win32b.bcc32" name="option.O2.enabled" value="1"/>
|
||||
<property category="win32.Release_Build.win32b.bcc32" name="option.disablewarns.enabled" value="0"/>
|
||||
<property category="win32.Release_Build.win32b.bcc32" name="option.k.enabled" value="0"/>
|
||||
<property category="win32.Release_Build.win32b.bcc32" name="option.n.arg.1" value="release"/>
|
||||
<property category="win32.Release_Build.win32b.bcc32" name="option.n.arg.merge" value="0"/>
|
||||
<property category="win32.Release_Build.win32b.bcc32" name="option.n.enabled" value="1"/>
|
||||
<property category="win32.Release_Build.win32b.bcc32" name="option.noregistervars.enabled" value="0"/>
|
||||
<property category="win32.Release_Build.win32b.bcc32" name="option.r.enabled" value="1"/>
|
||||
<property category="win32.Release_Build.win32b.bcc32" name="option.rd.enabled" value="0"/>
|
||||
<property category="win32.Release_Build.win32b.bcc32" name="option.vi.enabled" value="1"/>
|
||||
<property category="win32.Release_Build.win32b.bcc32" name="option.w.enabled" value="0"/>
|
||||
<property category="win32.Release_Build.win32b.dcc32" name="option.$D.enabled" value="0"/>
|
||||
<property category="win32.Release_Build.win32b.dcc32" name="option.$O.enabled" value="1"/>
|
||||
<property category="win32.Release_Build.win32b.dcc32" name="option.V.enabled" value="0"/>
|
||||
<property category="win32.Release_Build.win32b.ilink32" name="option.L.arg.1" value="$(BDS)\lib\release"/>
|
||||
<property category="win32.Release_Build.win32b.ilink32" name="option.L.arg.merge" value="1"/>
|
||||
<property category="win32.Release_Build.win32b.ilink32" name="option.L.enabled" value="1"/>
|
||||
<property category="win32.Release_Build.win32b.tasm32" name="option.z.enabled" value="0"/>
|
||||
<property category="win32.Release_Build.win32b.tasm32" name="option.zd.enabled" value="0"/>
|
||||
<property category="win32.Release_Build.win32b.tasm32" name="option.zi.enabled" value="0"/>
|
||||
<property category="win32.Release_Build.win32b.tasm32" name="option.zn.enabled" value="1"/>
|
||||
<property category="win32.Release_Build.win32b.tlib" name="option.outputdir.arg.1" value="..\release\lib"/>
|
||||
<property category="win32.Release_Build.win32b.tlib" name="option.outputdir.arg.merge" value="0"/>
|
||||
<property category="win32.Release_Build.win32b.tlib" name="option.outputdir.enabled" value="1"/>
|
||||
<optionset name="all_configurations">
|
||||
<property category="node" name="displayname" value="All Configurations"/>
|
||||
<property category="win32.*.win32b.bcc32" name="option.H=.arg.1" value="$(BDS)\lib\vcl100.csm"/>
|
||||
<property category="win32.*.win32b.bcc32" name="option.H=.arg.merge" value="1"/>
|
||||
<property category="win32.*.win32b.bcc32" name="option.H=.enabled" value="1"/>
|
||||
<property category="win32.*.win32b.bcc32" name="option.Hc.enabled" value="1"/>
|
||||
<property category="win32.*.win32b.bcc32" name="option.I.arg.1" value="..\.."/>
|
||||
<property category="win32.*.win32b.bcc32" name="option.I.arg.2" value="C:\projects\ase\cmn"/>
|
||||
<property category="win32.*.win32b.bcc32" name="option.I.arg.3" value="$(BDS)\include"/>
|
||||
<property category="win32.*.win32b.bcc32" name="option.I.arg.4" value="$(BDS)\include\dinkumware"/>
|
||||
<property category="win32.*.win32b.bcc32" name="option.I.arg.5" value="$(BDS)\include\vcl"/>
|
||||
<property category="win32.*.win32b.bcc32" name="option.I.arg.merge" value="1"/>
|
||||
<property category="win32.*.win32b.bcc32" name="option.I.enabled" value="1"/>
|
||||
<property category="win32.*.win32b.bcc32" name="option.b.enabled" value="0"/>
|
||||
<property category="win32.*.win32b.bcc32" name="option.n.arg.merge" value="1"/>
|
||||
<property category="win32.*.win32b.bcc32" name="option.n.enabled" value="0"/>
|
||||
<property category="win32.*.win32b.bcc32" name="option.sysdefines.arg.1" value="_RTLDLL"/>
|
||||
<property category="win32.*.win32b.bcc32" name="option.sysdefines.arg.2" value="NO_STRICT"/>
|
||||
<property category="win32.*.win32b.bcc32" name="option.sysdefines.arg.merge" value="1"/>
|
||||
<property category="win32.*.win32b.bcc32" name="option.sysdefines.enabled" value="1"/>
|
||||
<property category="win32.*.win32b.bcc32" name="option.tW.enabled" value="1"/>
|
||||
<property category="win32.*.win32b.bcc32" name="option.tWC.enabled" value="0"/>
|
||||
<property category="win32.*.win32b.bcc32" name="option.tWD.enabled" value="0"/>
|
||||
<property category="win32.*.win32b.bcc32" name="option.tWM.enabled" value="1"/>
|
||||
<property category="win32.*.win32b.dcc32" name="option.I.arg.1" value="C:\projects\ase\cmn"/>
|
||||
<property category="win32.*.win32b.dcc32" name="option.I.arg.merge" value="1"/>
|
||||
<property category="win32.*.win32b.dcc32" name="option.I.enabled" value="0"/>
|
||||
<property category="win32.*.win32b.dcc32" name="option.O.arg.1" value="C:\projects\ase\cmn"/>
|
||||
<property category="win32.*.win32b.dcc32" name="option.O.arg.merge" value="1"/>
|
||||
<property category="win32.*.win32b.dcc32" name="option.O.enabled" value="0"/>
|
||||
<property category="win32.*.win32b.dcc32" name="option.R.arg.1" value="C:\projects\ase\cmn"/>
|
||||
<property category="win32.*.win32b.dcc32" name="option.R.arg.merge" value="1"/>
|
||||
<property category="win32.*.win32b.dcc32" name="option.R.enabled" value="0"/>
|
||||
<property category="win32.*.win32b.dcc32" name="option.U.arg.1" value="C:\projects\ase\cmn"/>
|
||||
<property category="win32.*.win32b.dcc32" name="option.U.arg.2" value="C:\Documents and Settings\Administrator\My Documents\Borland Studio Projects"/>
|
||||
<property category="win32.*.win32b.dcc32" name="option.U.arg.3" value="$(BDS)\lib"/>
|
||||
<property category="win32.*.win32b.dcc32" name="option.U.arg.4" value="$(BDS)\lib\obj"/>
|
||||
<property category="win32.*.win32b.dcc32" name="option.U.arg.merge" value="1"/>
|
||||
<property category="win32.*.win32b.dcc32" name="option.U.enabled" value="1"/>
|
||||
<property category="win32.*.win32b.dcc32" name="param.filenames.merge" value="1"/>
|
||||
<property category="win32.*.win32b.idl2cpp" name="option.I.arg.1" value="C:\projects\ase\cmn"/>
|
||||
<property category="win32.*.win32b.idl2cpp" name="option.I.arg.merge" value="1"/>
|
||||
<property category="win32.*.win32b.idl2cpp" name="option.I.enabled" value="1"/>
|
||||
<property category="win32.*.win32b.ilink32" name="option.Gi.enabled" value="0"/>
|
||||
<property category="win32.*.win32b.ilink32" name="option.L.arg.1" value="$(BDS)\lib"/>
|
||||
<property category="win32.*.win32b.ilink32" name="option.L.arg.2" value="$(BDS)\lib\obj"/>
|
||||
<property category="win32.*.win32b.ilink32" name="option.L.arg.3" value="$(BDS)\lib\psdk"/>
|
||||
<property category="win32.*.win32b.ilink32" name="option.L.arg.merge" value="1"/>
|
||||
<property category="win32.*.win32b.ilink32" name="option.L.enabled" value="1"/>
|
||||
<property category="win32.*.win32b.ilink32" name="option.Tpd.enabled" value="0"/>
|
||||
<property category="win32.*.win32b.ilink32" name="option.Tpe.enabled" value="0"/>
|
||||
<property category="win32.*.win32b.ilink32" name="option.Tpp.enabled" value="0"/>
|
||||
<property category="win32.*.win32b.ilink32" name="option.aa.enabled" value="0"/>
|
||||
<property category="win32.*.win32b.ilink32" name="option.ap.enabled" value="0"/>
|
||||
<property category="win32.*.win32b.ilink32" name="option.dynamicrtl.enabled" value="1"/>
|
||||
<property category="win32.*.win32b.tlib" name="option.dynamicrtl.enabled" value="0"/>
|
||||
</optionset>
|
||||
</project>
|
||||
<FILELIST>
|
||||
<FILE FILENAME="str_bas.c" CONTAINERID="CCompiler" LOCALCOMMAND="" UNITNAME="str" FORMNAME="" DESIGNCLASS=""/>
|
||||
<FILE FILENAME="str_cnv.c" CONTAINERID="CCompiler" LOCALCOMMAND="" UNITNAME="str" FORMNAME="" DESIGNCLASS=""/>
|
||||
<FILE FILENAME="str_dyn.c" CONTAINERID="CCompiler" LOCALCOMMAND="" UNITNAME="str" FORMNAME="" DESIGNCLASS=""/>
|
||||
<FILE FILENAME="mem.c" CONTAINERID="CCompiler" LOCALCOMMAND="" UNITNAME="mem" FORMNAME="" DESIGNCLASS=""/>
|
||||
<FILE FILENAME="misc.c" CONTAINERID="CCompiler" LOCALCOMMAND="" UNITNAME="misc" FORMNAME="" DESIGNCLASS=""/>
|
||||
</FILELIST>
|
||||
<IDEOPTIONS>
|
||||
<VersionInfo>
|
||||
<VersionInfo Name="IncludeVerInfo">False</VersionInfo>
|
||||
<VersionInfo Name="AutoIncBuild">False</VersionInfo>
|
||||
<VersionInfo Name="MajorVer">1</VersionInfo>
|
||||
<VersionInfo Name="MinorVer">0</VersionInfo>
|
||||
<VersionInfo Name="Release">0</VersionInfo>
|
||||
<VersionInfo Name="Build">0</VersionInfo>
|
||||
<VersionInfo Name="Debug">False</VersionInfo>
|
||||
<VersionInfo Name="PreRelease">False</VersionInfo>
|
||||
<VersionInfo Name="Special">False</VersionInfo>
|
||||
<VersionInfo Name="Private">False</VersionInfo>
|
||||
<VersionInfo Name="DLL">False</VersionInfo>
|
||||
<VersionInfo Name="Locale">1033</VersionInfo>
|
||||
<VersionInfo Name="CodePage">1252</VersionInfo>
|
||||
</VersionInfo>
|
||||
<VersionInfoKeys>
|
||||
<VersionInfoKeys Name="CompanyName"></VersionInfoKeys>
|
||||
<VersionInfoKeys Name="FileDescription"></VersionInfoKeys>
|
||||
<VersionInfoKeys Name="FileVersion">1.0.0.0</VersionInfoKeys>
|
||||
<VersionInfoKeys Name="InternalName"></VersionInfoKeys>
|
||||
<VersionInfoKeys Name="LegalCopyright"></VersionInfoKeys>
|
||||
<VersionInfoKeys Name="LegalTrademarks"></VersionInfoKeys>
|
||||
<VersionInfoKeys Name="OriginalFilename"></VersionInfoKeys>
|
||||
<VersionInfoKeys Name="ProductName"></VersionInfoKeys>
|
||||
<VersionInfoKeys Name="ProductVersion">1.0.0.0</VersionInfoKeys>
|
||||
<VersionInfoKeys Name="Comments"></VersionInfoKeys>
|
||||
</VersionInfoKeys>
|
||||
<Debugging>
|
||||
<Debugging Name="DebugSourceDirs"></Debugging>
|
||||
</Debugging>
|
||||
<Parameters>
|
||||
<Parameters Name="RunParams"></Parameters>
|
||||
<Parameters Name="Launcher"></Parameters>
|
||||
<Parameters Name="UseLauncher">False</Parameters>
|
||||
<Parameters Name="DebugCWD"></Parameters>
|
||||
<Parameters Name="HostApplication"></Parameters>
|
||||
<Parameters Name="RemoteHost"></Parameters>
|
||||
<Parameters Name="RemotePath"></Parameters>
|
||||
<Parameters Name="RemoteParams"></Parameters>
|
||||
<Parameters Name="RemoteLauncher"></Parameters>
|
||||
<Parameters Name="UseRemoteLauncher">False</Parameters>
|
||||
<Parameters Name="RemoteCWD"></Parameters>
|
||||
<Parameters Name="RemoteDebug">False</Parameters>
|
||||
<Parameters Name="Debug Symbols Search Path"></Parameters>
|
||||
<Parameters Name="LoadAllSymbols">True</Parameters>
|
||||
<Parameters Name="LoadUnspecifiedSymbols">False</Parameters>
|
||||
</Parameters>
|
||||
<Linker>
|
||||
<Linker Name="LibPrefix"></Linker>
|
||||
<Linker Name="LibSuffix"></Linker>
|
||||
<Linker Name="LibVersion"></Linker>
|
||||
</Linker>
|
||||
</IDEOPTIONS>
|
||||
</BCBPROJECT>
|
||||
<buildevents>
|
||||
<buildevent file="asecmn.bdsproj">
|
||||
<precompile mode="0" cancancel="0" capture="-1" showconsole="0">mkdir $(PROJECTDIR)..\release\lib
|
||||
mkdir $(PROJECTDIR)..\debug\lib
|
||||
</precompile>
|
||||
</buildevent>
|
||||
</buildevents>
|
||||
</CPlusPlusBuilder.Personality>
|
||||
</BorlandProject>
|
132
qse/lib/cmn/asecmn.dsp
Normal file
132
qse/lib/cmn/asecmn.dsp
Normal file
@ -0,0 +1,132 @@
|
||||
# Microsoft Developer Studio Project File - Name="asecmn" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Static Library" 0x0104
|
||||
|
||||
CFG=asecmn - Win32 Release
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "asecmn.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "asecmn.mak" CFG="asecmn - Win32 Release"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "asecmn - Win32 Release" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "asecmn - Win32 Debug" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "asecmn - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "../release/lib"
|
||||
# PROP Intermediate_Dir "release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
MTL=midl.exe
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_UNICODE" /D "_USRDLL" /Yu"stdafx.h" /FD /c
|
||||
# ADD CPP /nologo /MT /Za /W3 /GX /O2 /I "../.." /D "NDEBUG" /D "WIN32" /D "_UNICODE" /FD /c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
|
||||
!ELSEIF "$(CFG)" == "asecmn - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "../debug/lib"
|
||||
# PROP Intermediate_Dir "debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
MTL=midl.exe
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_UNICODE" /D "_USRDLL" /Yu"stdafx.h" /FD /GZ /c
|
||||
# ADD CPP /nologo /MTd /Za /W3 /Gm /GX /ZI /Od /I "../.." /D "_DEBUG" /D "WIN32" /D "_UNICODE" /FD /GZ /c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "asecmn - Win32 Release"
|
||||
# Name "asecmn - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\mem.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\misc.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\str_bas.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\str_cnv.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\str_dyn.c
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\mem.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\str.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
528
qse/lib/cmn/asecmn.vcproj
Normal file
528
qse/lib/cmn/asecmn.vcproj
Normal file
@ -0,0 +1,528 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8.00"
|
||||
Name="asecmn"
|
||||
ProjectGUID="{17621C83-40C9-4305-BAF9-132E250B5FE3}"
|
||||
RootNamespace="asecmn"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
<Platform
|
||||
Name="x64"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)\lib"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="false"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="../.."
|
||||
PreprocessorDefinitions="_DEBUG;WIN32"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
DisableLanguageExtensions="true"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
Culture="1033"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
SuppressStartupBanner="true"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Debug|x64"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)\lib"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="false"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
TargetEnvironment="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="../.."
|
||||
PreprocessorDefinitions="_DEBUG;WIN32"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
DisableLanguageExtensions="true"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="true"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
Culture="1033"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
SuppressStartupBanner="true"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)\lib"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="false"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories="../.."
|
||||
PreprocessorDefinitions="NDEBUG;WIN32"
|
||||
StringPooling="true"
|
||||
RuntimeLibrary="0"
|
||||
EnableFunctionLevelLinking="true"
|
||||
DisableLanguageExtensions="true"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="true"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
Culture="1033"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
SuppressStartupBanner="true"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|x64"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)\lib"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="false"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
TargetEnvironment="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories="../.."
|
||||
PreprocessorDefinitions="NDEBUG;WIN32"
|
||||
StringPooling="true"
|
||||
RuntimeLibrary="0"
|
||||
EnableFunctionLevelLinking="true"
|
||||
DisableLanguageExtensions="true"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="true"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
Culture="1033"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
SuppressStartupBanner="true"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
>
|
||||
<File
|
||||
RelativePath="mem.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|x64"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|x64"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="misc.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|x64"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|x64"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="str_bas.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|x64"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|x64"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="str_cnv.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|x64"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|x64"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="str_dyn.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|x64"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|x64"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl"
|
||||
>
|
||||
<File
|
||||
RelativePath="mem.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="str.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
145
qse/lib/cmn/chr.c
Normal file
145
qse/lib/cmn/chr.c
Normal file
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* $Id: ctype.c 132 2008-03-17 10:27:02Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
|
||||
#include <ase/cmn/chr.h>
|
||||
|
||||
#if defined(ASE_CHAR_IS_MCHAR)
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
static ase_bool_t is_upper (ase_cint_t c) { return isupper(c); }
|
||||
static ase_bool_t is_lower (ase_cint_t c) { return islower(c); }
|
||||
static ase_bool_t is_alpha (ase_cint_t c) { return isalpha(c); }
|
||||
static ase_bool_t is_digit (ase_cint_t c) { return isdigit(c); }
|
||||
static ase_bool_t is_xdigit (ase_cint_t c) { return isxdigit(c); }
|
||||
static ase_bool_t is_alnum (ase_cint_t c) { return isalnum(c); }
|
||||
static ase_bool_t is_space (ase_cint_t c) { return isspace(c); }
|
||||
static ase_bool_t is_print (ase_cint_t c) { return isprint(c); }
|
||||
static ase_bool_t is_graph (ase_cint_t c) { return isgraph(c); }
|
||||
static ase_bool_t is_cntrl (ase_cint_t c) { return iscntrl(c); }
|
||||
static ase_bool_t is_punct (ase_cint_t c) { return ispunct(c); }
|
||||
|
||||
ase_bool_t ase_ccls_is (ase_cint_t c, ase_ccls_type_t type)
|
||||
{
|
||||
/* TODO: use GetStringTypeW/A for WIN32 to implement these */
|
||||
|
||||
static ase_bool_t (*f[]) (ase_cint_t) =
|
||||
{
|
||||
is_upper,
|
||||
is_lower,
|
||||
is_alpha,
|
||||
is_digit,
|
||||
is_xdigit,
|
||||
is_alnum,
|
||||
is_space,
|
||||
is_print,
|
||||
is_graph,
|
||||
is_cntrl,
|
||||
is_punct
|
||||
};
|
||||
|
||||
ASE_ASSERTX (type >= ASE_CCLS_UPPER && type <= ASE_CCLS_PUNCT,
|
||||
"The character type should be one of ase_ccls_type_t values");
|
||||
return f[type] (c);
|
||||
}
|
||||
|
||||
ase_cint_t ase_ccls_to (ase_cint_t c, ase_ccls_type_t type)
|
||||
{
|
||||
ASE_ASSERTX (type >= ASE_CCLS_UPPER && type <= ASE_CCLS_LOWER,
|
||||
"The character type should be one of ASE_CCLS_UPPER and ASE_CCLS_LOWER");
|
||||
|
||||
if (type == ASE_CCLS_UPPER) return toupper(c);
|
||||
if (type == ASE_CCLS_LOWER) return tolower(c);
|
||||
return c;
|
||||
}
|
||||
|
||||
#elif defined(ASE_CHAR_IS_WCHAR)
|
||||
|
||||
#include <wctype.h>
|
||||
|
||||
ase_bool_t ase_ccls_is (ase_cint_t c, ase_ccls_type_t type)
|
||||
{
|
||||
static const char* name[] =
|
||||
{
|
||||
"upper",
|
||||
"lower",
|
||||
"alpha",
|
||||
"digit",
|
||||
"xdigit",
|
||||
"alnum",
|
||||
"space",
|
||||
"print",
|
||||
"graph",
|
||||
"cntrl",
|
||||
"punct"
|
||||
};
|
||||
|
||||
static wctype_t desc[] =
|
||||
{
|
||||
(wctype_t)0,
|
||||
(wctype_t)0,
|
||||
(wctype_t)0,
|
||||
(wctype_t)0,
|
||||
(wctype_t)0,
|
||||
(wctype_t)0,
|
||||
(wctype_t)0,
|
||||
(wctype_t)0,
|
||||
(wctype_t)0,
|
||||
(wctype_t)0,
|
||||
(wctype_t)0
|
||||
};
|
||||
|
||||
ASE_ASSERTX (type >= ASE_CCLS_UPPER && type <= ASE_CCLS_PUNCT,
|
||||
"The character type should be one of ase_ccls_type_t values");
|
||||
|
||||
if (desc[type] == (wctype_t)0) desc[type] = wctype(name[type]);
|
||||
return iswctype (c, desc[type]);
|
||||
}
|
||||
|
||||
ase_cint_t ase_ccls_to (ase_cint_t c, ase_ccls_type_t type)
|
||||
{
|
||||
static const char* name[] =
|
||||
{
|
||||
"toupper",
|
||||
"tolower"
|
||||
};
|
||||
|
||||
static wctrans_t desc[] =
|
||||
{
|
||||
(wctrans_t)0,
|
||||
(wctrans_t)0
|
||||
};
|
||||
|
||||
ASE_ASSERTX (type >= ASE_CCLS_UPPER && type <= ASE_CCLS_LOWER,
|
||||
"The character type should be one of ASE_CCLS_UPPER and ASE_CCLS_LOWER");
|
||||
|
||||
if (desc[type] == (wctrans_t)0) desc[type] = wctrans(name[type]);
|
||||
return towctrans (c, desc[type]);
|
||||
}
|
||||
|
||||
#else
|
||||
#error unsupported character type
|
||||
#endif
|
||||
|
||||
static ase_bool_t ccls_is (void* data, ase_cint_t c, ase_ccls_type_t type)
|
||||
{
|
||||
return ase_ccls_is (c, type);
|
||||
}
|
||||
|
||||
static ase_cint_t ccls_to (void* data, ase_cint_t c, ase_ccls_type_t type)
|
||||
{
|
||||
return ase_ccls_to (c, type);
|
||||
}
|
||||
|
||||
static ase_ccls_t ccls =
|
||||
{
|
||||
ccls_is,
|
||||
ccls_to,
|
||||
ASE_NULL
|
||||
};
|
||||
|
||||
ase_ccls_t* ase_ccls = &ccls;
|
||||
|
70
qse/lib/cmn/chr.h
Normal file
70
qse/lib/cmn/chr.h
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
|
||||
#ifndef _ASE_LIB_CMN_CHR_H_
|
||||
#define _ASE_LIB_CMN_CHR_H_
|
||||
|
||||
#include <ase/cmn/chr.h>
|
||||
|
||||
#ifdef USE_STDC
|
||||
|
||||
#if defined(ASE_CHAR_IS_MCHAR)
|
||||
|
||||
#include <ctype.h>
|
||||
#define ASE_ISUPPER(c) isupper(c)
|
||||
#define ASE_ISLOWER(c) islower(c)
|
||||
#define ASE_ISALPHA(c) isalpha(c)
|
||||
#define ASE_ISDIGIT(c) isdigit(c)
|
||||
#define ASE_ISXDIGIT(c) isxdigit(c)
|
||||
#define ASE_ISALNUM(c) isalnum(c)
|
||||
#define ASE_ISSPACE(c) isspace(c)
|
||||
#define ASE_ISPRINT(c) isprint(c)
|
||||
#define ASE_ISGRAPH(c) isgraph(c)
|
||||
#define ASE_ISCNTRL(c) iscntrl(c)
|
||||
#define ASE_ISPUNCT(c) ispunct(c)
|
||||
#define ASE_TOUPPER(c) toupper(c)
|
||||
#define ASE_TOLOWER(c) tolower(c)
|
||||
|
||||
#elif defined(ASE_CHAR_IS_WCHAR)
|
||||
|
||||
#include <wctype.h>
|
||||
#define ASE_ISUPPER(c) iswupper(c)
|
||||
#define ASE_ISLOWER(c) iswlower(c)
|
||||
#define ASE_ISALPHA(c) iswalpha(c)
|
||||
#define ASE_ISDIGIT(c) iswdigit(c)
|
||||
#define ASE_ISXDIGIT(c) iswxdigit(c)
|
||||
#define ASE_ISALNUM(c) iswalnum(c)
|
||||
#define ASE_ISSPACE(c) iswspace(c)
|
||||
#define ASE_ISPRINT(c) iswprint(c)
|
||||
#define ASE_ISGRAPH(c) iswgraph(c)
|
||||
#define ASE_ISCNTRL(c) iswcntrl(c)
|
||||
#define ASE_ISPUNCT(c) iswpunct(c)
|
||||
#define ASE_TOUPPER(c) towupper(c)
|
||||
#define ASE_TOLOWER(c) towlower(c)
|
||||
|
||||
#else
|
||||
#error Unsupported character type
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#define ASE_ISUPPER(c) (ase_ccls_is(c,ASE_CCLS_UPPER))
|
||||
#define ASE_ISLOWER(c) (ase_ccls_is(c,ASE_CCLS_LOWER))
|
||||
#define ASE_ISALPHA(c) (ase_ccls_is(c,ASE_CCLS_ALPHA))
|
||||
#define ASE_ISDIGIT(c) (ase_ccls_is(c,ASE_CCLS_DIGIT))
|
||||
#define ASE_ISXDIGIT(c) (ase_ccls_is(c,ASE_CCLS_XDIGIT))
|
||||
#define ASE_ISALNUM(c) (ase_ccls_is(c,ASE_CCLS_ALNUM))
|
||||
#define ASE_ISSPACE(c) (ase_ccls_is(c,ASE_CCLS_SPACE))
|
||||
#define ASE_ISPRINT(c) (ase_ccls_is(c,ASE_CCLS_PRINT))
|
||||
#define ASE_ISGRAPH(c) (ase_ccls_is(c,ASE_CCLS_GRAPH))
|
||||
#define ASE_ISCNTRL(c) (ase_ccls_is(c,ASE_CCLS_CNTRL))
|
||||
#define ASE_ISPUNCT(c) (ase_ccls_is(c,ASE_CCLS_PUNCT))
|
||||
#define ASE_TOUPPER(c) (ase_ccls_to(c,ASE_CCLS_UPPER))
|
||||
#define ASE_TOLOWER(c) (ase_ccls_to(c,ASE_CCLS_LOWER))
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
91
qse/lib/cmn/chr_cnv.c
Normal file
91
qse/lib/cmn/chr_cnv.c
Normal file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <ase/cmn/chr.h>
|
||||
#include "mem.h"
|
||||
|
||||
#ifdef HAVE_WCHAR_H
|
||||
#include <wchar.h>
|
||||
#endif
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
ase_size_t ase_mblen (const ase_mchar_t* mb, ase_size_t mblen)
|
||||
{
|
||||
#ifdef HAVE_MBRLEN
|
||||
size_t n;
|
||||
mbstate_t mbs = { 0 };
|
||||
|
||||
n = mbrlen (mb, mblen, &mbs);
|
||||
if (n == 0) return 1; /* a null character */
|
||||
|
||||
if (n == (size_t)-1) return 0; /* invalid sequence */
|
||||
if (n == (size_t)-2) return mblen + 1; /* incomplete sequence */
|
||||
|
||||
return (ase_size_t)n;
|
||||
#else
|
||||
#error #### NOT SUPPORTED ####
|
||||
#endif
|
||||
}
|
||||
|
||||
ase_size_t ase_mbtowc (const ase_mchar_t* mb, ase_size_t mblen, ase_wchar_t* wc)
|
||||
{
|
||||
#ifdef HAVE_MBRTOWC
|
||||
size_t n;
|
||||
mbstate_t mbs = { 0 };
|
||||
|
||||
n = mbrtowc (wc, mb, mblen, &mbs);
|
||||
if (n == 0)
|
||||
{
|
||||
*wc = ASE_WT('\0');
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (n == (size_t)-1) return 0; /* invalid sequence */
|
||||
if (n == (size_t)-2) return mblen + 1; /* incomplete sequence */
|
||||
return (ase_size_t)n;
|
||||
#else
|
||||
#error #### NOT SUPPORTED ####
|
||||
#endif
|
||||
}
|
||||
|
||||
ase_size_t ase_wctomb (ase_wchar_t wc, ase_mchar_t* mb, ase_size_t mblen)
|
||||
{
|
||||
#ifdef HAVE_WCRTOMB
|
||||
size_t n;
|
||||
mbstate_t mbs = { 0 };
|
||||
|
||||
/* man mbsinit
|
||||
* For 8-bit encodings, all states are equivalent to the initial state.
|
||||
* For multibyte encodings like UTF-8, EUC-*, BIG5 or SJIS, the wide char‐
|
||||
* acter to multibyte conversion functions never produce non-initial
|
||||
* states, but the multibyte to wide-character conversion functions like
|
||||
* mbrtowc(3) do produce non-initial states when interrupted in the middle
|
||||
* of a character.
|
||||
*/
|
||||
|
||||
if (mblen < MB_CUR_MAX)
|
||||
{
|
||||
ase_mchar_t buf[MB_CUR_MAX];
|
||||
|
||||
n = wcrtomb (buf, wc, &mbs);
|
||||
if (n > mblen) return mblen + 1; /* buffer to small */
|
||||
if (n == (size_t)-1) return 0; /* illegal character */
|
||||
|
||||
ASE_MEMCPY (mb, buf, mblen);
|
||||
}
|
||||
else
|
||||
{
|
||||
n = wcrtomb (mb, wc, &mbs);
|
||||
if (n > mblen) return mblen + 1; /* buffer to small */
|
||||
if (n == (size_t)-1) return 0; /* illegal character */
|
||||
}
|
||||
|
||||
return n;
|
||||
#else
|
||||
#error #### NOT SUPPORTED ####
|
||||
#endif
|
||||
}
|
||||
|
21
qse/lib/cmn/descrip.mms
Normal file
21
qse/lib/cmn/descrip.mms
Normal file
@ -0,0 +1,21 @@
|
||||
#
|
||||
# OpenVMS MMS/MMK
|
||||
#
|
||||
|
||||
objects = mem.obj,str_bas.obj,str_cnv.obj,str_dyn.obj,map.obj,rex.obj,misc.obj
|
||||
|
||||
CFLAGS = /include="../../inc"
|
||||
#CFLAGS = /pointer_size=long /include="../../inc"
|
||||
LIBRFLAGS =
|
||||
|
||||
asecmn.olb : $(objects)
|
||||
$(LIBR)/create $(MMS$TARGET) $(objects)
|
||||
# $(LIBR)/replace $(LIBRFLAGS) $(MMS$TARGET),$(objects)
|
||||
|
||||
mem.obj depends_on mem.c
|
||||
str_bas.obj depends_on str_bas.c
|
||||
str_cnv.obj depends_on str_cnv.c
|
||||
str_dyn.obj depends_on str_dyn.c
|
||||
map.obj depends_on map.c
|
||||
rex.obj depends_on rex.c
|
||||
misc.obj depends_on misc.c
|
242
qse/lib/cmn/dll.c
Normal file
242
qse/lib/cmn/dll.c
Normal file
@ -0,0 +1,242 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
|
||||
#include <ase/cmn/dll.h>
|
||||
#include "mem.h"
|
||||
|
||||
ase_dll_t* ase_dll_open (ase_mmgr_t* mmgr, ase_size_t ext)
|
||||
{
|
||||
ase_dll_t* dll;
|
||||
|
||||
if (mmgr == ASE_NULL)
|
||||
{
|
||||
mmgr = ASE_MMGR_GETDFL();
|
||||
|
||||
ASE_ASSERTX (mmgr != ASE_NULL,
|
||||
"Set the memory manager with ASE_MMGR_SETDFL()");
|
||||
|
||||
if (mmgr == ASE_NULL) return ASE_NULL;
|
||||
}
|
||||
|
||||
dll = ASE_MMGR_ALLOC (mmgr, ASE_SIZEOF(ase_dll_t) + ext);
|
||||
if (dll == ASE_NULL) return ASE_NULL;
|
||||
|
||||
/* do not zero the extension */
|
||||
ASE_MEMSET (dll, 0, ASE_SIZEOF(ase_dll_t));
|
||||
dll->mmgr = mmgr;
|
||||
|
||||
return dll;
|
||||
}
|
||||
|
||||
void ase_dll_close (ase_dll_t* dll)
|
||||
{
|
||||
ase_dll_clear (dll);
|
||||
ASE_MMGR_FREE (dll->mmgr, dll);
|
||||
}
|
||||
|
||||
void ase_dll_clear (ase_dll_t* dll)
|
||||
{
|
||||
while (dll->head != ASE_NULL) ase_dll_delete (dll, dll->head);
|
||||
ASE_ASSERT (dll->tail == ASE_NULL);
|
||||
}
|
||||
|
||||
void* ase_dll_getxtn (ase_dll_t* dll)
|
||||
{
|
||||
return dll + 1;
|
||||
}
|
||||
|
||||
ase_mmgr_t* ase_dll_getmmgr (ase_dll_t* dll)
|
||||
{
|
||||
return dll->mmgr;
|
||||
}
|
||||
|
||||
void ase_dll_setmmgr (ase_dll_t* dll, ase_mmgr_t* mmgr)
|
||||
{
|
||||
dll->mmgr = mmgr;
|
||||
}
|
||||
|
||||
ase_size_t ase_dll_getsize (ase_dll_t* dll)
|
||||
{
|
||||
return dll->size;
|
||||
}
|
||||
|
||||
ase_dll_node_t* ase_dll_gethead (ase_dll_t* dll)
|
||||
{
|
||||
return dll->head;
|
||||
}
|
||||
|
||||
ase_dll_node_t* ase_dll_gettail (ase_dll_t* dll)
|
||||
{
|
||||
return dll->tail;
|
||||
}
|
||||
|
||||
ase_dll_copier_t ase_dll_getcopier (ase_dll_t* dll)
|
||||
{
|
||||
return dll->copier;
|
||||
}
|
||||
|
||||
void ase_dll_setcopier (ase_dll_t* dll, ase_dll_copier_t copier)
|
||||
{
|
||||
dll->copier = copier;
|
||||
}
|
||||
|
||||
ase_dll_freeer_t ase_dll_getfreeer (ase_dll_t* dll)
|
||||
{
|
||||
return dll->freeer;
|
||||
}
|
||||
|
||||
void ase_dll_setfreeer (ase_dll_t* dll, ase_dll_freeer_t freeer)
|
||||
{
|
||||
dll->freeer = freeer;
|
||||
}
|
||||
|
||||
static ase_dll_node_t* alloc_node (ase_dll_t* dll, void* dptr, ase_size_t dlen)
|
||||
{
|
||||
ase_dll_node_t* n;
|
||||
|
||||
if (dll->copier == ASE_NULL)
|
||||
{
|
||||
n = ASE_MMGR_ALLOC (dll->mmgr, ASE_SIZEOF(ase_dll_node_t));
|
||||
if (n == ASE_NULL) return ASE_NULL;
|
||||
n->dptr = dptr;
|
||||
}
|
||||
else if (dll->copier == ASE_DLL_COPIER_INLINE)
|
||||
{
|
||||
n = ASE_MMGR_ALLOC (dll->mmgr, ASE_SIZEOF(ase_dll_node_t) + dlen);
|
||||
if (n == ASE_NULL) return ASE_NULL;
|
||||
|
||||
ASE_MEMCPY (n + 1, dptr, dlen);
|
||||
n->dptr = n + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
n = ASE_MMGR_ALLOC (dll->mmgr, ASE_SIZEOF(ase_dll_node_t));
|
||||
if (n == ASE_NULL) return ASE_NULL;
|
||||
n->dptr = dll->copier (dll, dptr, dlen);
|
||||
if (n->dptr == ASE_NULL)
|
||||
{
|
||||
ASE_MMGR_FREE (dll->mmgr, n);
|
||||
return ASE_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
n->dlen = dlen;
|
||||
n->next = ASE_NULL;
|
||||
n->prev = ASE_NULL;
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
ase_dll_node_t* ase_dll_insert (
|
||||
ase_dll_t* dll, ase_dll_node_t* pos, void* dptr, ase_size_t dlen)
|
||||
{
|
||||
ase_dll_node_t* n = alloc_node (dll, dptr, dlen);
|
||||
if (n == ASE_NULL) return ASE_NULL;
|
||||
|
||||
if (pos == ASE_NULL)
|
||||
{
|
||||
/* insert at the end */
|
||||
if (dll->head == ASE_NULL)
|
||||
{
|
||||
ASE_ASSERT (dll->tail == ASE_NULL);
|
||||
dll->head = n;
|
||||
}
|
||||
else dll->tail->next = n;
|
||||
|
||||
dll->tail = n;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* insert in front of the positional node */
|
||||
n->next = pos;
|
||||
if (pos == dll->head) dll->head = n;
|
||||
else
|
||||
{
|
||||
/* take note of performance penalty */
|
||||
ase_dll_node_t* n2 = dll->head;
|
||||
while (n2->next != pos) n2 = n2->next;
|
||||
n2->next = n;
|
||||
}
|
||||
}
|
||||
|
||||
dll->size++;
|
||||
return n;
|
||||
}
|
||||
|
||||
ase_dll_node_t* ase_dll_pushhead (ase_dll_t* dll, void* data, ase_size_t size)
|
||||
{
|
||||
return ase_dll_insert (dll, dll->head, data, size);
|
||||
}
|
||||
|
||||
ase_dll_node_t* ase_dll_pushtail (ase_dll_t* dll, void* data, ase_size_t size)
|
||||
{
|
||||
return ase_dll_insert (dll, ASE_NULL, data, size);
|
||||
}
|
||||
|
||||
void ase_dll_delete (ase_dll_t* dll, ase_dll_node_t* pos)
|
||||
{
|
||||
if (pos == ASE_NULL) return; /* not a valid node */
|
||||
|
||||
if (pos == dll->head)
|
||||
{
|
||||
/* it is simple to delete the head node */
|
||||
dll->head = pos->next;
|
||||
if (dll->head == ASE_NULL) dll->tail = ASE_NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* but deletion of other nodes has significant performance
|
||||
* penalty as it has look for the predecessor of the
|
||||
* target node */
|
||||
ase_dll_node_t* n2 = dll->head;
|
||||
while (n2->next != pos) n2 = n2->next;
|
||||
|
||||
n2->next = pos->next;
|
||||
|
||||
/* update the tail node if necessary */
|
||||
if (pos == dll->tail) dll->tail = n2;
|
||||
}
|
||||
|
||||
if (dll->freeer != ASE_NULL)
|
||||
{
|
||||
/* free the actual data */
|
||||
dll->freeer (dll, pos->dptr, pos->dlen);
|
||||
}
|
||||
|
||||
/* free the node */
|
||||
ASE_MMGR_FREE (dll->mmgr, pos);
|
||||
|
||||
/* decrement the number of elements */
|
||||
dll->size--;
|
||||
}
|
||||
|
||||
void ase_dll_pophead (ase_dll_t* dll)
|
||||
{
|
||||
ase_dll_delete (dll, dll->head);
|
||||
}
|
||||
|
||||
void ase_dll_poptail (ase_dll_t* dll)
|
||||
{
|
||||
ase_dll_delete (dll, dll->tail);
|
||||
}
|
||||
|
||||
void ase_dll_walk (ase_dll_t* dll, ase_dll_walker_t walker, void* arg)
|
||||
{
|
||||
ase_dll_node_t* n = dll->head;
|
||||
|
||||
while (n != ASE_NULL)
|
||||
{
|
||||
if (walker(dll,n,arg) == ASE_DLL_WALK_STOP) return;
|
||||
n = n->next;
|
||||
}
|
||||
}
|
||||
|
||||
void* ase_dll_copyinline (ase_dll_t* dll, void* dptr, ase_size_t dlen)
|
||||
{
|
||||
/* this is a dummy copier */
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
329
qse/lib/cmn/fio.c
Normal file
329
qse/lib/cmn/fio.c
Normal file
@ -0,0 +1,329 @@
|
||||
/*
|
||||
* $Id: fio.c,v 1.23 2006/06/30 04:18:47 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <ase/cmn/fio.h>
|
||||
#include "mem.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#endif
|
||||
|
||||
#if defined(ASE_USE_SYSCALL) && defined(HAVE_SYS_SYSCALL_H)
|
||||
#include <sys/syscall.h>
|
||||
#endif
|
||||
|
||||
ase_fio_t* ase_fio_open (
|
||||
ase_mmgr_t* mmgr, ase_size_t ext,
|
||||
const ase_char_t* path, int flags, int mode)
|
||||
{
|
||||
ase_fio_t* fio;
|
||||
|
||||
if (mmgr == ASE_NULL)
|
||||
{
|
||||
mmgr = ASE_MMGR_GETDFL();
|
||||
|
||||
ASE_ASSERTX (mmgr != ASE_NULL,
|
||||
"Set the memory manager with ASE_MMGR_SETDFL()");
|
||||
|
||||
if (mmgr == ASE_NULL) return ASE_NULL;
|
||||
}
|
||||
|
||||
fio = ASE_MMGR_ALLOC (mmgr, ASE_SIZEOF(ase_fio_t) + ext);
|
||||
if (fio == ASE_NULL) return ASE_NULL;
|
||||
|
||||
if (ase_fio_init (fio, mmgr, path, flags, mode) == ASE_NULL)
|
||||
{
|
||||
ASE_MMGR_FREE (mmgr, fio);
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
return fio;
|
||||
}
|
||||
|
||||
void ase_fio_close (ase_fio_t* fio)
|
||||
{
|
||||
ase_fio_fini (fio);
|
||||
ASE_MMGR_FREE (fio->mmgr, fio);
|
||||
}
|
||||
|
||||
ase_fio_t* ase_fio_init (
|
||||
ase_fio_t* fio, ase_mmgr_t* mmgr,
|
||||
const ase_char_t* path, int flags, int mode)
|
||||
{
|
||||
ase_fio_hnd_t handle;
|
||||
|
||||
ASE_MEMSET (fio, 0, ASE_SIZEOF(*fio));
|
||||
fio->mmgr = mmgr;
|
||||
|
||||
#ifdef _WIN32
|
||||
if (flags & ASE_FIO_HANDLE)
|
||||
{
|
||||
handle = *(ase_fio_hnd_t*)path;
|
||||
}
|
||||
else
|
||||
{
|
||||
DWORD desired_access = 0;
|
||||
DWORD share_mode = FILE_SHARE_READ | FILE_SHARE_WRITE;
|
||||
DWORD creation_disposition = 0;
|
||||
DWORD attributes = FILE_ATTRIBUTE_NORMAL;
|
||||
|
||||
if (flags & ASE_FIO_APPEND)
|
||||
{
|
||||
/* this is not officialy documented for CreateFile.
|
||||
* ZwCreateFile (kernel) seems to document it */
|
||||
desired_access |= FILE_APPEND_DATA;
|
||||
}
|
||||
else if (flags & ASE_FIO_WRITE)
|
||||
{
|
||||
/* In WIN32, FILE_APPEND_DATA and GENERIC_WRITE can't
|
||||
* be used together */
|
||||
desired_access |= GENERIC_WRITE;
|
||||
}
|
||||
if (flags & ASE_FIO_READ) desired_access |= GENERIC_READ;
|
||||
|
||||
if (flags & ASE_FIO_CREATE)
|
||||
{
|
||||
creation_disposition =
|
||||
(flags & ASE_FIO_EXCLUSIVE)? CREATE_NEW:
|
||||
(flags & ASE_FIO_TRUNCATE)? CREATE_ALWAYS: OPEN_ALWAYS;
|
||||
}
|
||||
else if (flags & ASE_FIO_TRUNCATE)
|
||||
{
|
||||
creation_disposition = TRUNCATE_EXISTING;
|
||||
}
|
||||
else creation_disposition = OPEN_EXISTING;
|
||||
|
||||
if (flags & ASE_FIO_NOSHRD) share_mode &= ~FILE_SHARE_READ;
|
||||
if (flags & ASE_FIO_NOSHWR) share_mode &= ~FILE_SHARE_WRITE;
|
||||
|
||||
if (flags & ASE_FIO_SYNC) attributes |= FILE_FLAG_WRITE_THROUGH;
|
||||
/* TODO: handle mode... set attribuets */
|
||||
handle = CreateFile (path,
|
||||
desired_access, share_mode, ASE_NULL,
|
||||
creation_disposition, attributes, 0);
|
||||
}
|
||||
|
||||
if (handle == INVALID_HANDLE_VALUE) return ASE_NULL;
|
||||
|
||||
{
|
||||
DWORD file_type = GetFileType(handle);
|
||||
if (file_type == FILE_TYPE_UNKNOWN)
|
||||
{
|
||||
CloseHandle (handle);
|
||||
return ASE_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: a lot more */
|
||||
#else
|
||||
|
||||
if (flags & ASE_FIO_HANDLE)
|
||||
{
|
||||
handle = *(ase_fio_hnd_t*)path;
|
||||
}
|
||||
else
|
||||
{
|
||||
int desired_access = 0;
|
||||
#ifdef ASE_CHAR_IS_MCHAR
|
||||
const ase_mchar_t* path_mb = path;
|
||||
#else
|
||||
ase_mchar_t path_mb[PATH_MAX + 1];
|
||||
if (ase_wcstombs_strict (path,
|
||||
path_mb, ASE_COUNTOF(path_mb)) == -1) return ASE_NULL;
|
||||
#endif
|
||||
/*
|
||||
* rwa -> RDWR | APPEND
|
||||
* ra -> RDWR | APPEND
|
||||
* wa -> WRONLY | APPEND
|
||||
* a -> WRONLY | APPEND
|
||||
*/
|
||||
if (flags & ASE_FIO_APPEND)
|
||||
{
|
||||
if ((flags & ASE_FIO_READ)) desired_access |= O_RDWR;
|
||||
else desired_access |= O_WRONLY;
|
||||
desired_access |= O_APPEND;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((flags & ASE_FIO_READ) &&
|
||||
(flags & ASE_FIO_WRITE)) desired_access |= O_RDWR;
|
||||
else if (flags & ASE_FIO_READ) desired_access |= O_RDONLY;
|
||||
else if (flags & ASE_FIO_WRITE) desired_access |= O_WRONLY;
|
||||
}
|
||||
|
||||
if (flags & ASE_FIO_CREATE) desired_access |= O_CREAT;
|
||||
if (flags & ASE_FIO_TRUNCATE) desired_access |= O_TRUNC;
|
||||
if (flags & ASE_FIO_EXCLUSIVE) desired_access |= O_EXCL;
|
||||
if (flags & ASE_FIO_SYNC) desired_access |= O_SYNC;
|
||||
|
||||
#if defined(O_LARGEFILE)
|
||||
desired_access |= O_LARGEFILE;
|
||||
#endif
|
||||
|
||||
#ifdef SYS_open
|
||||
handle = syscall (SYS_open, path_mb, desired_access, mode);
|
||||
#else
|
||||
handle = open (path_mb, desired_access, mode);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (handle == -1) return ASE_NULL;
|
||||
|
||||
#endif
|
||||
|
||||
fio->handle = handle;
|
||||
return fio;
|
||||
}
|
||||
|
||||
void ase_fio_fini (ase_fio_t* fio)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
CloseHandle (fio->handle);
|
||||
#else
|
||||
#if defined(SYS_close)
|
||||
syscall (SYS_close, fio->handle);
|
||||
#else
|
||||
close (fio->handle);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
ase_fio_hnd_t ase_fio_gethandle (ase_fio_t* fio)
|
||||
{
|
||||
return fio->handle;
|
||||
}
|
||||
|
||||
void ase_fio_sethandle (ase_fio_t* fio, ase_fio_hnd_t handle)
|
||||
{
|
||||
fio->handle = handle;
|
||||
}
|
||||
|
||||
ase_fio_off_t ase_fio_seek (
|
||||
ase_fio_t* fio, ase_fio_off_t offset, ase_fio_ori_t origin)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
static int seek_map[] =
|
||||
{
|
||||
FILE_BEGIN,
|
||||
FILE_CURRENT,
|
||||
FILE_END
|
||||
};
|
||||
LARGE_INTEGER x, y;
|
||||
|
||||
ASE_ASSERT (AES_SIZEOF(offset) <= AES_SIZEOF(x.QuadPart));
|
||||
|
||||
x.QuadPart = offset;
|
||||
if (SetFilePointerEx (fio->handle, x, &y, seek_map[origin]) == FALSE)
|
||||
{
|
||||
return (ase_fio_off_t)-1;
|
||||
}
|
||||
|
||||
return (ase_fio_off_t)y.QuadPart;
|
||||
|
||||
/*
|
||||
x.QuadPart = offset;
|
||||
x.LowPart = SetFilePointer (fio->handle, x.LowPart, &x.HighPart, seek_map[origin]);
|
||||
if (x.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR)
|
||||
{
|
||||
return (ase_fio_off_t)-1;
|
||||
}
|
||||
|
||||
return (ase_fio_off_t)x.QuadPart;
|
||||
*/
|
||||
|
||||
#else
|
||||
static int seek_map[] =
|
||||
{
|
||||
SEEK_SET,
|
||||
SEEK_CUR,
|
||||
SEEK_END
|
||||
};
|
||||
|
||||
#if !defined(_LP64) && defined(SYS__llseek)
|
||||
loff_t tmp;
|
||||
|
||||
if (syscall (SYS__llseek, fio->handle,
|
||||
(unsigned long)(offset>>32),
|
||||
(unsigned long)(offset&0xFFFFFFFFlu),
|
||||
&tmp,
|
||||
seek_map[origin]) == -1)
|
||||
{
|
||||
return (ase_fio_off_t)-1;
|
||||
}
|
||||
|
||||
return (ase_fio_off_t)tmp;
|
||||
|
||||
#elif defined(SYS_lseek)
|
||||
return syscall (SYS_lseek, fio->handle, offset, seek_map[origin]);
|
||||
#elif !defined(_LP64) && defined(HAVE_LSEEK64)
|
||||
return lseek64 (fio->handle, offset, seek_map[origin]);
|
||||
#else
|
||||
return lseek (fio->handle, offset, seek_map[origin]);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
int ase_fio_truncate (ase_fio_t* fio, ase_fio_off_t size)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
LARGE_INTEGER x;
|
||||
x.QuadPart = size;
|
||||
|
||||
if (SetFilePointerEx(fio->handle,x,NULL,FILE_BEGIN) == FALSE ||
|
||||
SetEndOfFile(fio->handle) == FALSE) return -1;
|
||||
|
||||
return 0;
|
||||
#else
|
||||
|
||||
#if !defined(_LP64) && defined(SYS_ftruncate64)
|
||||
return syscall (SYS_ftruncate64, fio->handle, size);
|
||||
#elif defined(SYS_ftruncate)
|
||||
return syscall (SYS_ftruncate, fio->handle, size);
|
||||
#elif !defined(_LP64) && defined(HAVE_FTRUNCATE64)
|
||||
return ftruncate64 (fio->handle, size);
|
||||
#else
|
||||
return ftruncate (fio->handle, size);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
ase_ssize_t ase_fio_read (ase_fio_t* fio, void* buf, ase_size_t size)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
DWORD count;
|
||||
if (size > ASE_TYPE_MAX(DWORD)) size = ASE_TYPE_MAX(DWORD);
|
||||
if (ReadFile(fio->handle, buf, size, &count, ASE_NULL) == FALSE) return -1;
|
||||
return (ase_ssize_t)count;
|
||||
#else
|
||||
if (size > ASE_TYPE_MAX(size_t)) size = ASE_TYPE_MAX(size_t);
|
||||
#ifdef SYS_read
|
||||
return syscall (SYS_read, fio->handle, buf, size);
|
||||
#else
|
||||
return read (fio->handle, buf, size);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
ase_ssize_t ase_fio_write (ase_fio_t* fio, const void* data, ase_size_t size)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
DWORD count;
|
||||
if (size > ASE_TYPE_MAX(DWORD)) size = ASE_TYPE_MAX(DWORD);
|
||||
if (WriteFile(fio->handle, data, size, &count, ASE_NULL) == FALSE) return -1;
|
||||
return (ase_ssize_t)count;
|
||||
#else
|
||||
if (size > ASE_TYPE_MAX(size_t)) size = ASE_TYPE_MAX(size_t);
|
||||
#ifdef SYS_write
|
||||
return syscall (SYS_write, fio->handle, data, size);
|
||||
#else
|
||||
return write (fio->handle, data, size);
|
||||
#endif
|
||||
#endif
|
||||
}
|
564
qse/lib/cmn/lda.c
Normal file
564
qse/lib/cmn/lda.c
Normal file
@ -0,0 +1,564 @@
|
||||
/*
|
||||
* $Id: lda.c 337 2008-08-20 09:17:25Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
|
||||
#include <ase/cmn/lda.h>
|
||||
#include "mem.h"
|
||||
|
||||
#define lda_t ase_lda_t
|
||||
#define node_t ase_lda_node_t
|
||||
#define copier_t ase_lda_copier_t
|
||||
#define freeer_t ase_lda_freeer_t
|
||||
#define comper_t ase_lda_comper_t
|
||||
#define sizer_t ase_lda_sizer_t
|
||||
#define keeper_t ase_lda_keeper_t
|
||||
#define walker_t ase_lda_walker_t
|
||||
|
||||
#define mmgr_t ase_mmgr_t
|
||||
#define size_t ase_size_t
|
||||
|
||||
#define TOB(lda,len) ((len)*(lda)->scale)
|
||||
#define DPTR(node) ((node)->dptr)
|
||||
#define DLEN(node) ((node)->dlen)
|
||||
#define INVALID ASE_LDA_INVALID
|
||||
|
||||
static int comp_data (lda_t* lda,
|
||||
const void* dptr1, size_t dlen1,
|
||||
const void* dptr2, size_t dlen2)
|
||||
{
|
||||
/*
|
||||
if (dlen1 == dlen2) return ASE_MEMCMP (dptr1, dptr2, TOB(lda,dlen1));
|
||||
return 1;
|
||||
*/
|
||||
|
||||
size_t min = (dlen1 < dlen2)? dlen1: dlen2;
|
||||
int n = ASE_MEMCMP (dptr1, dptr2, TOB(lda,min));
|
||||
if (n == 0 && dlen1 != dlen2)
|
||||
{
|
||||
n = (dlen1 > dlen2)? 1: -1;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
static node_t* alloc_node (lda_t* lda, void* dptr, size_t dlen)
|
||||
{
|
||||
node_t* n;
|
||||
|
||||
if (lda->copier == ASE_LDA_COPIER_SIMPLE)
|
||||
{
|
||||
n = ASE_MMGR_ALLOC (lda->mmgr, ASE_SIZEOF(node_t));
|
||||
if (n == ASE_NULL) return ASE_NULL;
|
||||
DPTR(n) = dptr;
|
||||
}
|
||||
else if (lda->copier == ASE_LDA_COPIER_INLINE)
|
||||
{
|
||||
n = ASE_MMGR_ALLOC (lda->mmgr,
|
||||
ASE_SIZEOF(node_t) + TOB(lda,dlen));
|
||||
if (n == ASE_NULL) return ASE_NULL;
|
||||
|
||||
ASE_MEMCPY (n + 1, dptr, TOB(lda,dlen));
|
||||
DPTR(n) = n + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
n = ASE_MMGR_ALLOC (lda->mmgr, ASE_SIZEOF(node_t));
|
||||
if (n == ASE_NULL) return ASE_NULL;
|
||||
DPTR(n) = lda->copier (lda, dptr, dlen);
|
||||
if (DPTR(n) == ASE_NULL)
|
||||
{
|
||||
ASE_MMGR_FREE (lda->mmgr, n);
|
||||
return ASE_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
DLEN(n) = dlen;
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
lda_t* ase_lda_open (mmgr_t* mmgr, size_t ext, size_t capa)
|
||||
{
|
||||
lda_t* lda;
|
||||
|
||||
if (mmgr == ASE_NULL)
|
||||
{
|
||||
mmgr = ASE_MMGR_GETDFL();
|
||||
|
||||
ASE_ASSERTX (mmgr != ASE_NULL,
|
||||
"Set the memory manager with ASE_MMGR_SETDFL()");
|
||||
|
||||
if (mmgr == ASE_NULL) return ASE_NULL;
|
||||
}
|
||||
|
||||
lda = ASE_MMGR_ALLOC (mmgr, ASE_SIZEOF(lda_t) + ext);
|
||||
if (lda == ASE_NULL) return ASE_NULL;
|
||||
|
||||
if (ase_lda_init (lda, mmgr, capa) == ASE_NULL)
|
||||
{
|
||||
ASE_MMGR_FREE (mmgr, lda);
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
return lda;
|
||||
}
|
||||
|
||||
void ase_lda_close (lda_t* lda)
|
||||
{
|
||||
ase_lda_fini (lda);
|
||||
ASE_MMGR_FREE (lda->mmgr, lda);
|
||||
}
|
||||
|
||||
lda_t* ase_lda_init (lda_t* lda, mmgr_t* mmgr, size_t capa)
|
||||
{
|
||||
ASE_MEMSET (lda, 0, ASE_SIZEOF(*lda));
|
||||
|
||||
lda->mmgr = mmgr;
|
||||
lda->size = 0;
|
||||
lda->capa = 0;
|
||||
lda->node = ASE_NULL;
|
||||
|
||||
lda->copier = ASE_LDA_COPIER_SIMPLE;
|
||||
lda->comper = comp_data;
|
||||
|
||||
if (ase_lda_setcapa (lda, capa) == ASE_NULL) return ASE_NULL;
|
||||
return lda;
|
||||
}
|
||||
|
||||
void ase_lda_fini (lda_t* lda)
|
||||
{
|
||||
ase_lda_clear (lda);
|
||||
|
||||
if (lda->node != ASE_NULL)
|
||||
{
|
||||
ASE_MMGR_FREE (lda->mmgr, lda->node);
|
||||
lda->node = ASE_NULL;
|
||||
lda->capa = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void* ase_lda_getxtn (lda_t* lda)
|
||||
{
|
||||
return lda + 1;
|
||||
}
|
||||
|
||||
mmgr_t* ase_lda_getmmgr (lda_t* lda)
|
||||
{
|
||||
return lda->mmgr;
|
||||
}
|
||||
|
||||
void ase_lda_setmmgr (lda_t* lda, mmgr_t* mmgr)
|
||||
{
|
||||
lda->mmgr = mmgr;
|
||||
}
|
||||
|
||||
int ase_lda_getscale (lda_t* lda)
|
||||
{
|
||||
return lda->scale;
|
||||
}
|
||||
|
||||
void ase_lda_setscale (lda_t* lda, int scale)
|
||||
{
|
||||
ASE_ASSERTX (scale > 0 && scale <= ASE_TYPE_MAX(ase_byte_t),
|
||||
"The scale should be larger than 0 and less than or equal to the maximum value that the ase_byte_t type can hold");
|
||||
|
||||
if (scale <= 0) scale = 1;
|
||||
if (scale > ASE_TYPE_MAX(ase_byte_t)) scale = ASE_TYPE_MAX(ase_byte_t);
|
||||
|
||||
lda->scale = scale;
|
||||
}
|
||||
|
||||
copier_t ase_lda_getcopier (lda_t* lda)
|
||||
{
|
||||
return lda->copier;
|
||||
}
|
||||
|
||||
void ase_lda_setcopier (lda_t* lda, copier_t copier)
|
||||
{
|
||||
if (copier == ASE_NULL) copier = ASE_LDA_COPIER_SIMPLE;
|
||||
lda->copier = copier;
|
||||
}
|
||||
|
||||
freeer_t ase_lda_getfreeer (lda_t* lda)
|
||||
{
|
||||
return lda->freeer;
|
||||
}
|
||||
|
||||
void ase_lda_setfreeer (lda_t* lda, freeer_t freeer)
|
||||
{
|
||||
lda->freeer = freeer;
|
||||
}
|
||||
|
||||
comper_t ase_lda_getcomper (lda_t* lda)
|
||||
{
|
||||
return lda->comper;
|
||||
}
|
||||
|
||||
void ase_lda_setcomper (lda_t* lda, comper_t comper)
|
||||
{
|
||||
if (comper == ASE_NULL) comper = comp_data;
|
||||
lda->comper = comper;
|
||||
}
|
||||
|
||||
keeper_t ase_lda_getkeeper (lda_t* lda)
|
||||
{
|
||||
return lda->keeper;
|
||||
}
|
||||
|
||||
void ase_lda_setkeeper (lda_t* lda, keeper_t keeper)
|
||||
{
|
||||
lda->keeper = keeper;
|
||||
}
|
||||
|
||||
sizer_t ase_lda_getsizer (lda_t* lda)
|
||||
{
|
||||
return lda->sizer;
|
||||
}
|
||||
|
||||
void ase_lda_setsizer (lda_t* lda, sizer_t sizer)
|
||||
{
|
||||
lda->sizer = sizer;
|
||||
}
|
||||
|
||||
size_t ase_lda_getsize (lda_t* lda)
|
||||
{
|
||||
return lda->size;
|
||||
}
|
||||
|
||||
size_t ase_lda_getcapa (lda_t* lda)
|
||||
{
|
||||
return lda->capa;
|
||||
}
|
||||
|
||||
lda_t* ase_lda_setcapa (lda_t* lda, size_t capa)
|
||||
{
|
||||
void* tmp;
|
||||
|
||||
if (lda->size > capa)
|
||||
{
|
||||
ase_lda_delete (lda, capa, lda->size - capa);
|
||||
ASE_ASSERT (lda->size <= capa);
|
||||
}
|
||||
|
||||
if (capa > 0)
|
||||
{
|
||||
if (lda->mmgr->realloc != ASE_NULL && lda->node != ASE_NULL)
|
||||
{
|
||||
tmp = (ase_lda_node_t**)ASE_MMGR_REALLOC (
|
||||
lda->mmgr, lda->node, ASE_SIZEOF(*lda->node)*capa);
|
||||
if (tmp == ASE_NULL) return ASE_NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = (ase_lda_node_t**) ASE_MMGR_ALLOC (
|
||||
lda->mmgr, ASE_SIZEOF(*lda->node)*capa);
|
||||
if (tmp == ASE_NULL) return ASE_NULL;
|
||||
|
||||
if (lda->node != ASE_NULL)
|
||||
{
|
||||
size_t x;
|
||||
x = (capa > lda->capa)? lda->capa: capa;
|
||||
ASE_MEMCPY (tmp, lda->node,
|
||||
ASE_SIZEOF(*lda->node) * x);
|
||||
ASE_MMGR_FREE (lda->mmgr, lda->node);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (lda->node != ASE_NULL)
|
||||
{
|
||||
ase_lda_clear (lda);
|
||||
ASE_MMGR_FREE (lda->mmgr, lda->node);
|
||||
}
|
||||
|
||||
tmp = ASE_NULL;
|
||||
}
|
||||
|
||||
lda->node = tmp;
|
||||
lda->capa = capa;
|
||||
|
||||
return lda;
|
||||
}
|
||||
|
||||
size_t ase_lda_search (lda_t* lda, size_t pos, const void* dptr, size_t dlen)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = pos; i < lda->size; i++)
|
||||
{
|
||||
if (lda->node[i] == ASE_NULL) continue;
|
||||
|
||||
if (lda->comper (lda,
|
||||
DPTR(lda->node[i]), DLEN(lda->node[i]),
|
||||
dptr, dlen) == 0) return i;
|
||||
}
|
||||
|
||||
return INVALID;
|
||||
}
|
||||
|
||||
size_t ase_lda_rsearch (lda_t* lda, size_t pos, const void* dptr, size_t dlen)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (lda->size > 0)
|
||||
{
|
||||
if (pos >= lda->size) pos = lda->size - 1;
|
||||
|
||||
for (i = pos + 1; i-- > 0; )
|
||||
{
|
||||
if (lda->node[i] == ASE_NULL) continue;
|
||||
|
||||
if (lda->comper (lda,
|
||||
DPTR(lda->node[i]), DLEN(lda->node[i]),
|
||||
dptr, dlen) == 0) return i;
|
||||
}
|
||||
}
|
||||
|
||||
return INVALID;
|
||||
}
|
||||
|
||||
size_t ase_lda_upsert (lda_t* lda, size_t pos, void* dptr, size_t dlen)
|
||||
{
|
||||
if (pos < lda->size) return ase_lda_update (lda, pos, dptr, dlen);
|
||||
return ase_lda_insert (lda, pos, dptr, dlen);
|
||||
}
|
||||
|
||||
size_t ase_lda_insert (lda_t* lda, size_t pos, void* dptr, size_t dlen)
|
||||
{
|
||||
size_t i;
|
||||
node_t* node;
|
||||
|
||||
/* allocate the node first */
|
||||
node = alloc_node (lda, dptr, dlen);
|
||||
if (node == ASE_NULL) return INVALID;
|
||||
|
||||
/* do resizeing if necessary.
|
||||
* resizing is performed after node allocation because that way, it
|
||||
* doesn't modify lda on any errors */
|
||||
if (pos >= lda->capa || lda->size >= lda->capa)
|
||||
{
|
||||
size_t capa;
|
||||
|
||||
if (lda->sizer)
|
||||
{
|
||||
capa = (pos >= lda->size)? (pos + 1): (lda->size + 1);
|
||||
capa = lda->sizer (lda, capa);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (lda->capa <= 0)
|
||||
{
|
||||
ASE_ASSERT (lda->size <= 0);
|
||||
capa = (pos < 16)? 16: (pos + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t bound = (pos >= lda->size)? pos: lda->size;
|
||||
do { capa = lda->capa * 2; } while (capa <= bound);
|
||||
}
|
||||
}
|
||||
|
||||
if (ase_lda_setcapa(lda,capa) == ASE_NULL)
|
||||
{
|
||||
if (lda->freeer)
|
||||
lda->freeer (lda, DPTR(node), DLEN(node));
|
||||
ASE_MMGR_FREE (lda->mmgr, node);
|
||||
return INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
if (pos >= lda->capa || lda->size >= lda->capa)
|
||||
{
|
||||
/* the buffer is not still enough after resizing */
|
||||
if (lda->freeer)
|
||||
lda->freeer (lda, DPTR(node), DLEN(node));
|
||||
ASE_MMGR_FREE (lda->mmgr, node);
|
||||
return INVALID;
|
||||
}
|
||||
|
||||
/* fill in the gap with ASE_NULL */
|
||||
for (i = lda->size; i < pos; i++) lda->node[i] = ASE_NULL;
|
||||
|
||||
/* shift values to the next cell */
|
||||
for (i = lda->size; i > pos; i--) lda->node[i] = lda->node[i-1];
|
||||
|
||||
/* set the value */
|
||||
lda->node[pos] = node;
|
||||
|
||||
if (pos > lda->size) lda->size = pos + 1;
|
||||
else lda->size++;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
size_t ase_lda_update (lda_t* lda, size_t pos, void* dptr, size_t dlen)
|
||||
{
|
||||
node_t* c;
|
||||
|
||||
if (pos >= lda->size) return INVALID;
|
||||
|
||||
c = lda->node[pos];
|
||||
if (c == ASE_NULL)
|
||||
{
|
||||
/* no previous data */
|
||||
lda->node[pos] = alloc_node (lda, dptr, dlen);
|
||||
if (lda->node[pos] == ASE_NULL) return INVALID;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dptr == DPTR(c) && dlen == DLEN(c))
|
||||
{
|
||||
/* updated to the same data */
|
||||
if (lda->keeper) lda->keeper (lda, dptr, dlen);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* updated to different data */
|
||||
node_t* node = alloc_node (lda, dptr, dlen);
|
||||
if (node == ASE_NULL) return INVALID;
|
||||
|
||||
if (lda->freeer != ASE_NULL)
|
||||
lda->freeer (lda, DPTR(c), DLEN(c));
|
||||
ASE_MMGR_FREE (lda->mmgr, c);
|
||||
|
||||
lda->node[pos] = node;
|
||||
}
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
size_t ase_lda_delete (lda_t* lda, size_t index, size_t count)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (index >= lda->size) return 0;
|
||||
if (count > lda->size - index) count = lda->size - index;
|
||||
|
||||
i = index;
|
||||
|
||||
for (i = index; i < index + count; i++)
|
||||
{
|
||||
node_t* c = lda->node[i];
|
||||
|
||||
if (c != ASE_NULL)
|
||||
{
|
||||
if (lda->freeer != ASE_NULL)
|
||||
lda->freeer (lda, DPTR(c), DLEN(c));
|
||||
ASE_MMGR_FREE (lda->mmgr, c);
|
||||
|
||||
lda->node[i] = ASE_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = index + count; i < lda->size; i++)
|
||||
{
|
||||
lda->node[i-count] = lda->node[i];
|
||||
}
|
||||
lda->node[lda->size-1] = ASE_NULL;
|
||||
|
||||
lda->size -= count;
|
||||
return count;
|
||||
}
|
||||
|
||||
size_t ase_lda_uplete (lda_t* lda, size_t index, size_t count)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (index >= lda->size) return 0;
|
||||
if (count > lda->size - index) count = lda->size - index;
|
||||
|
||||
i = index;
|
||||
|
||||
for (i = index; i < index + count; i++)
|
||||
{
|
||||
node_t* c = lda->node[i];
|
||||
|
||||
if (c != ASE_NULL)
|
||||
{
|
||||
if (lda->freeer != ASE_NULL)
|
||||
lda->freeer (lda, DPTR(c), DLEN(c));
|
||||
ASE_MMGR_FREE (lda->mmgr, c);
|
||||
|
||||
lda->node[i] = ASE_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
void ase_lda_clear (lda_t* lda)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < lda->size; i++)
|
||||
{
|
||||
node_t* c = lda->node[i];
|
||||
if (c != ASE_NULL)
|
||||
{
|
||||
if (lda->freeer)
|
||||
lda->freeer (lda, DPTR(c), DLEN(c));
|
||||
ASE_MMGR_FREE (lda->mmgr, c);
|
||||
lda->node[i] = ASE_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
lda->size = 0;
|
||||
}
|
||||
|
||||
void ase_lda_walk (lda_t* lda, walker_t walker, void* arg)
|
||||
{
|
||||
ase_lda_walk_t w = ASE_LDA_WALK_FORWARD;
|
||||
size_t i = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (lda->node[i] != ASE_NULL)
|
||||
w = walker (lda, i, arg);
|
||||
|
||||
if (w == ASE_LDA_WALK_STOP) return;
|
||||
|
||||
if (w == ASE_LDA_WALK_FORWARD)
|
||||
{
|
||||
i++;
|
||||
if (i >= lda->size) return;
|
||||
}
|
||||
if (w == ASE_LDA_WALK_BACKWARD)
|
||||
{
|
||||
if (i <= 0) return;
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ase_lda_rwalk (lda_t* lda, walker_t walker, void* arg)
|
||||
{
|
||||
ase_lda_walk_t w = ASE_LDA_WALK_BACKWARD;
|
||||
size_t i;
|
||||
|
||||
if (lda->size <= 0) return;
|
||||
i = lda->size - 1;
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (lda->node[i] != ASE_NULL)
|
||||
w = walker (lda, i, arg);
|
||||
|
||||
if (w == ASE_LDA_WALK_STOP) return;
|
||||
|
||||
if (w == ASE_LDA_WALK_FORWARD)
|
||||
{
|
||||
i++;
|
||||
if (i >= lda->size) return;
|
||||
}
|
||||
if (w == ASE_LDA_WALK_BACKWARD)
|
||||
{
|
||||
if (i <= 0) return;
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
13
qse/lib/cmn/makefile.am
Normal file
13
qse/lib/cmn/makefile.am
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
AUTOMAKE_OPTIONS = nostdinc
|
||||
AM_CFLAGS = -I$(top_builddir)/include
|
||||
|
||||
lib_LTLIBRARIES = libasecmn.la
|
||||
libasecmn_la_SOURCES = mem.h chr.h \
|
||||
mem.c chr.c chr_cnv.c rex.c str_bas.c str_cnv.c str_dyn.c \
|
||||
lda.c map.c sll.c dll.c opt.c \
|
||||
fio.c sio.c tio.c tio_get.c tio_put.c \
|
||||
time.c \
|
||||
misc.c
|
||||
libasecmn_la_LDFLAGS = -version-info 1:0:0 -no-undefined
|
||||
|
508
qse/lib/cmn/makefile.in
Normal file
508
qse/lib/cmn/makefile.in
Normal file
@ -0,0 +1,508 @@
|
||||
# makefile.in generated by automake 1.10.1 from makefile.am.
|
||||
# @configure_input@
|
||||
|
||||
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
|
||||
# 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
|
||||
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE.
|
||||
|
||||
@SET_MAKE@
|
||||
|
||||
VPATH = @srcdir@
|
||||
pkgdatadir = $(datadir)/@PACKAGE@
|
||||
pkglibdir = $(libdir)/@PACKAGE@
|
||||
pkgincludedir = $(includedir)/@PACKAGE@
|
||||
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
|
||||
install_sh_DATA = $(install_sh) -c -m 644
|
||||
install_sh_PROGRAM = $(install_sh) -c
|
||||
install_sh_SCRIPT = $(install_sh) -c
|
||||
INSTALL_HEADER = $(INSTALL_DATA)
|
||||
transform = $(program_transform_name)
|
||||
NORMAL_INSTALL = :
|
||||
PRE_INSTALL = :
|
||||
POST_INSTALL = :
|
||||
NORMAL_UNINSTALL = :
|
||||
PRE_UNINSTALL = :
|
||||
POST_UNINSTALL = :
|
||||
build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
subdir = lib/cmn
|
||||
DIST_COMMON = $(srcdir)/makefile.am $(srcdir)/makefile.in
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = $(top_srcdir)/configure.ac
|
||||
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
|
||||
$(ACLOCAL_M4)
|
||||
mkinstalldirs = $(install_sh) -d
|
||||
CONFIG_HEADER = $(top_builddir)/include/ase/config.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
|
||||
am__vpath_adj = case $$p in \
|
||||
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
|
||||
*) f=$$p;; \
|
||||
esac;
|
||||
am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
|
||||
am__installdirs = "$(DESTDIR)$(libdir)"
|
||||
libLTLIBRARIES_INSTALL = $(INSTALL)
|
||||
LTLIBRARIES = $(lib_LTLIBRARIES)
|
||||
libasecmn_la_LIBADD =
|
||||
am_libasecmn_la_OBJECTS = mem.lo chr.lo chr_cnv.lo rex.lo str_bas.lo \
|
||||
str_cnv.lo str_dyn.lo lda.lo map.lo sll.lo dll.lo opt.lo \
|
||||
fio.lo sio.lo tio.lo tio_get.lo tio_put.lo time.lo misc.lo
|
||||
libasecmn_la_OBJECTS = $(am_libasecmn_la_OBJECTS)
|
||||
libasecmn_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||
$(libasecmn_la_LDFLAGS) $(LDFLAGS) -o $@
|
||||
DEFAULT_INCLUDES =
|
||||
depcomp = $(SHELL) $(top_srcdir)/autoconf/depcomp
|
||||
am__depfiles_maybe = depfiles
|
||||
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
|
||||
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
|
||||
--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
|
||||
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
CCLD = $(CC)
|
||||
LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
|
||||
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
|
||||
$(LDFLAGS) -o $@
|
||||
SOURCES = $(libasecmn_la_SOURCES)
|
||||
DIST_SOURCES = $(libasecmn_la_SOURCES)
|
||||
ETAGS = etags
|
||||
CTAGS = ctags
|
||||
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
||||
ACLOCAL = @ACLOCAL@
|
||||
AMTAR = @AMTAR@
|
||||
AR = @AR@
|
||||
AUTOCONF = @AUTOCONF@
|
||||
AUTOHEADER = @AUTOHEADER@
|
||||
AUTOMAKE = @AUTOMAKE@
|
||||
AWK = @AWK@
|
||||
BUILD_CJ = @BUILD_CJ@
|
||||
BUILD_JNI = @BUILD_JNI@
|
||||
BUILD_MODE = @BUILD_MODE@
|
||||
CC = @CC@
|
||||
CCDEPMODE = @CCDEPMODE@
|
||||
CFLAGS = @CFLAGS@
|
||||
CFLAGS_JNI = @CFLAGS_JNI@
|
||||
CJ = @CJ@
|
||||
CJFLAGS = @CJFLAGS@
|
||||
CPP = @CPP@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
CXX = @CXX@
|
||||
CXXCPP = @CXXCPP@
|
||||
CXXDEPMODE = @CXXDEPMODE@
|
||||
CXXFLAGS = @CXXFLAGS@
|
||||
CYGPATH_W = @CYGPATH_W@
|
||||
DEFS = @DEFS@
|
||||
DEPDIR = @DEPDIR@
|
||||
DSYMUTIL = @DSYMUTIL@
|
||||
ECHO = @ECHO@
|
||||
ECHO_C = @ECHO_C@
|
||||
ECHO_N = @ECHO_N@
|
||||
ECHO_T = @ECHO_T@
|
||||
EGREP = @EGREP@
|
||||
EXEEXT = @EXEEXT@
|
||||
F77 = @F77@
|
||||
FFLAGS = @FFLAGS@
|
||||
GREP = @GREP@
|
||||
HAVE_CXX = @HAVE_CXX@
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
|
||||
JAR = @JAR@
|
||||
JAR_PATH = @JAR_PATH@
|
||||
JAVAC = @JAVAC@
|
||||
JAVAC_PATH = @JAVAC_PATH@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBM = @LIBM@
|
||||
LIBOBJS = @LIBOBJS@
|
||||
LIBS = @LIBS@
|
||||
LIBTOOL = @LIBTOOL@
|
||||
LIBTOOL_DEPS = @LIBTOOL_DEPS@
|
||||
LN_S = @LN_S@
|
||||
LTLIBOBJS = @LTLIBOBJS@
|
||||
MAKEINFO = @MAKEINFO@
|
||||
MKDIR_P = @MKDIR_P@
|
||||
NMEDIT = @NMEDIT@
|
||||
OBJEXT = @OBJEXT@
|
||||
PACKAGE = @PACKAGE@
|
||||
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
|
||||
PACKAGE_NAME = @PACKAGE_NAME@
|
||||
PACKAGE_STRING = @PACKAGE_STRING@
|
||||
PACKAGE_TARNAME = @PACKAGE_TARNAME@
|
||||
PACKAGE_VERSION = @PACKAGE_VERSION@
|
||||
PATH_SEPARATOR = @PATH_SEPARATOR@
|
||||
RANLIB = @RANLIB@
|
||||
RM = @RM@
|
||||
SED = @SED@
|
||||
SET_MAKE = @SET_MAKE@
|
||||
SHELL = @SHELL@
|
||||
STRIP = @STRIP@
|
||||
VERSION = @VERSION@
|
||||
abs_builddir = @abs_builddir@
|
||||
abs_srcdir = @abs_srcdir@
|
||||
abs_top_builddir = @abs_top_builddir@
|
||||
abs_top_srcdir = @abs_top_srcdir@
|
||||
ac_ct_CC = @ac_ct_CC@
|
||||
ac_ct_CXX = @ac_ct_CXX@
|
||||
ac_ct_F77 = @ac_ct_F77@
|
||||
am__include = @am__include@
|
||||
am__leading_dot = @am__leading_dot@
|
||||
am__quote = @am__quote@
|
||||
am__tar = @am__tar@
|
||||
am__untar = @am__untar@
|
||||
bindir = @bindir@
|
||||
build = @build@
|
||||
build_alias = @build_alias@
|
||||
build_cpu = @build_cpu@
|
||||
build_os = @build_os@
|
||||
build_vendor = @build_vendor@
|
||||
builddir = @builddir@
|
||||
datadir = @datadir@
|
||||
datarootdir = @datarootdir@
|
||||
docdir = @docdir@
|
||||
dvidir = @dvidir@
|
||||
exec_prefix = @exec_prefix@
|
||||
host = @host@
|
||||
host_alias = @host_alias@
|
||||
host_cpu = @host_cpu@
|
||||
host_os = @host_os@
|
||||
host_vendor = @host_vendor@
|
||||
htmldir = @htmldir@
|
||||
includedir = @includedir@
|
||||
infodir = @infodir@
|
||||
install_sh = @install_sh@
|
||||
libdir = @libdir@
|
||||
libexecdir = @libexecdir@
|
||||
localedir = @localedir@
|
||||
localstatedir = @localstatedir@
|
||||
mandir = @mandir@
|
||||
mkdir_p = @mkdir_p@
|
||||
oldincludedir = @oldincludedir@
|
||||
pdfdir = @pdfdir@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
psdir = @psdir@
|
||||
sbindir = @sbindir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
srcdir = @srcdir@
|
||||
sysconfdir = @sysconfdir@
|
||||
target_alias = @target_alias@
|
||||
top_builddir = @top_builddir@
|
||||
top_srcdir = @top_srcdir@
|
||||
AUTOMAKE_OPTIONS = nostdinc
|
||||
AM_CFLAGS = -I$(top_builddir)/include
|
||||
lib_LTLIBRARIES = libasecmn.la
|
||||
libasecmn_la_SOURCES = mem.h chr.h \
|
||||
mem.c chr.c chr_cnv.c rex.c str_bas.c str_cnv.c str_dyn.c \
|
||||
lda.c map.c sll.c dll.c opt.c \
|
||||
fio.c sio.c tio.c tio_get.c tio_put.c \
|
||||
time.c \
|
||||
misc.c
|
||||
|
||||
libasecmn_la_LDFLAGS = -version-info 1:0:0 -no-undefined
|
||||
all: all-am
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .c .lo .o .obj
|
||||
$(srcdir)/makefile.in: $(srcdir)/makefile.am $(am__configure_deps)
|
||||
@for dep in $?; do \
|
||||
case '$(am__configure_deps)' in \
|
||||
*$$dep*) \
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
|
||||
&& exit 0; \
|
||||
exit 1;; \
|
||||
esac; \
|
||||
done; \
|
||||
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign lib/cmn/makefile'; \
|
||||
cd $(top_srcdir) && \
|
||||
$(AUTOMAKE) --foreign lib/cmn/makefile
|
||||
.PRECIOUS: makefile
|
||||
makefile: $(srcdir)/makefile.in $(top_builddir)/config.status
|
||||
@case '$?' in \
|
||||
*config.status*) \
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
|
||||
*) \
|
||||
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
|
||||
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
|
||||
esac;
|
||||
|
||||
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
|
||||
$(top_srcdir)/configure: $(am__configure_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
install-libLTLIBRARIES: $(lib_LTLIBRARIES)
|
||||
@$(NORMAL_INSTALL)
|
||||
test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)"
|
||||
@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
|
||||
if test -f $$p; then \
|
||||
f=$(am__strip_dir) \
|
||||
echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) '$$p' '$(DESTDIR)$(libdir)/$$f'"; \
|
||||
$(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) "$$p" "$(DESTDIR)$(libdir)/$$f"; \
|
||||
else :; fi; \
|
||||
done
|
||||
|
||||
uninstall-libLTLIBRARIES:
|
||||
@$(NORMAL_UNINSTALL)
|
||||
@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
|
||||
p=$(am__strip_dir) \
|
||||
echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$p'"; \
|
||||
$(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$p"; \
|
||||
done
|
||||
|
||||
clean-libLTLIBRARIES:
|
||||
-test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
|
||||
@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
|
||||
dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
|
||||
test "$$dir" != "$$p" || dir=.; \
|
||||
echo "rm -f \"$${dir}/so_locations\""; \
|
||||
rm -f "$${dir}/so_locations"; \
|
||||
done
|
||||
libasecmn.la: $(libasecmn_la_OBJECTS) $(libasecmn_la_DEPENDENCIES)
|
||||
$(libasecmn_la_LINK) -rpath $(libdir) $(libasecmn_la_OBJECTS) $(libasecmn_la_LIBADD) $(LIBS)
|
||||
|
||||
mostlyclean-compile:
|
||||
-rm -f *.$(OBJEXT)
|
||||
|
||||
distclean-compile:
|
||||
-rm -f *.tab.c
|
||||
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/chr.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/chr_cnv.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dll.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fio.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lda.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/map.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mem.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/misc.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/opt.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rex.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sio.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sll.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_bas.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_cnv.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str_dyn.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/time.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tio.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tio_get.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tio_put.Plo@am__quote@
|
||||
|
||||
.c.o:
|
||||
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
|
||||
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(COMPILE) -c $<
|
||||
|
||||
.c.obj:
|
||||
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
|
||||
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
|
||||
|
||||
.c.lo:
|
||||
@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
|
||||
@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
|
||||
|
||||
mostlyclean-libtool:
|
||||
-rm -f *.lo
|
||||
|
||||
clean-libtool:
|
||||
-rm -rf .libs _libs
|
||||
|
||||
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
|
||||
END { if (nonempty) { for (i in files) print i; }; }'`; \
|
||||
mkid -fID $$unique
|
||||
tags: TAGS
|
||||
|
||||
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
|
||||
$(TAGS_FILES) $(LISP)
|
||||
tags=; \
|
||||
here=`pwd`; \
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
|
||||
END { if (nonempty) { for (i in files) print i; }; }'`; \
|
||||
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
|
||||
test -n "$$unique" || unique=$$empty_fix; \
|
||||
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
|
||||
$$tags $$unique; \
|
||||
fi
|
||||
ctags: CTAGS
|
||||
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
|
||||
$(TAGS_FILES) $(LISP)
|
||||
tags=; \
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
|
||||
END { if (nonempty) { for (i in files) print i; }; }'`; \
|
||||
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|
||||
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
|
||||
$$tags $$unique
|
||||
|
||||
GTAGS:
|
||||
here=`$(am__cd) $(top_builddir) && pwd` \
|
||||
&& cd $(top_srcdir) \
|
||||
&& gtags -i $(GTAGS_ARGS) $$here
|
||||
|
||||
distclean-tags:
|
||||
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
|
||||
|
||||
distdir: $(DISTFILES)
|
||||
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
|
||||
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
|
||||
list='$(DISTFILES)'; \
|
||||
dist_files=`for file in $$list; do echo $$file; done | \
|
||||
sed -e "s|^$$srcdirstrip/||;t" \
|
||||
-e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
|
||||
case $$dist_files in \
|
||||
*/*) $(MKDIR_P) `echo "$$dist_files" | \
|
||||
sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
|
||||
sort -u` ;; \
|
||||
esac; \
|
||||
for file in $$dist_files; do \
|
||||
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
|
||||
if test -d $$d/$$file; then \
|
||||
dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
|
||||
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
|
||||
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
|
||||
fi; \
|
||||
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
|
||||
else \
|
||||
test -f $(distdir)/$$file \
|
||||
|| cp -p $$d/$$file $(distdir)/$$file \
|
||||
|| exit 1; \
|
||||
fi; \
|
||||
done
|
||||
check-am: all-am
|
||||
check: check-am
|
||||
all-am: makefile $(LTLIBRARIES)
|
||||
installdirs:
|
||||
for dir in "$(DESTDIR)$(libdir)"; do \
|
||||
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
|
||||
done
|
||||
install: install-am
|
||||
install-exec: install-exec-am
|
||||
install-data: install-data-am
|
||||
uninstall: uninstall-am
|
||||
|
||||
install-am: all-am
|
||||
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
|
||||
|
||||
installcheck: installcheck-am
|
||||
install-strip:
|
||||
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
|
||||
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
|
||||
`test -z '$(STRIP)' || \
|
||||
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
|
||||
mostlyclean-generic:
|
||||
|
||||
clean-generic:
|
||||
|
||||
distclean-generic:
|
||||
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
|
||||
|
||||
maintainer-clean-generic:
|
||||
@echo "This command is intended for maintainers to use"
|
||||
@echo "it deletes files that may require special tools to rebuild."
|
||||
clean: clean-am
|
||||
|
||||
clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \
|
||||
mostlyclean-am
|
||||
|
||||
distclean: distclean-am
|
||||
-rm -rf ./$(DEPDIR)
|
||||
-rm -f makefile
|
||||
distclean-am: clean-am distclean-compile distclean-generic \
|
||||
distclean-tags
|
||||
|
||||
dvi: dvi-am
|
||||
|
||||
dvi-am:
|
||||
|
||||
html: html-am
|
||||
|
||||
info: info-am
|
||||
|
||||
info-am:
|
||||
|
||||
install-data-am:
|
||||
|
||||
install-dvi: install-dvi-am
|
||||
|
||||
install-exec-am: install-libLTLIBRARIES
|
||||
|
||||
install-html: install-html-am
|
||||
|
||||
install-info: install-info-am
|
||||
|
||||
install-man:
|
||||
|
||||
install-pdf: install-pdf-am
|
||||
|
||||
install-ps: install-ps-am
|
||||
|
||||
installcheck-am:
|
||||
|
||||
maintainer-clean: maintainer-clean-am
|
||||
-rm -rf ./$(DEPDIR)
|
||||
-rm -f makefile
|
||||
maintainer-clean-am: distclean-am maintainer-clean-generic
|
||||
|
||||
mostlyclean: mostlyclean-am
|
||||
|
||||
mostlyclean-am: mostlyclean-compile mostlyclean-generic \
|
||||
mostlyclean-libtool
|
||||
|
||||
pdf: pdf-am
|
||||
|
||||
pdf-am:
|
||||
|
||||
ps: ps-am
|
||||
|
||||
ps-am:
|
||||
|
||||
uninstall-am: uninstall-libLTLIBRARIES
|
||||
|
||||
.MAKE: install-am install-strip
|
||||
|
||||
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
|
||||
clean-libLTLIBRARIES clean-libtool ctags distclean \
|
||||
distclean-compile distclean-generic distclean-libtool \
|
||||
distclean-tags distdir dvi dvi-am html html-am info info-am \
|
||||
install install-am install-data install-data-am install-dvi \
|
||||
install-dvi-am install-exec install-exec-am install-html \
|
||||
install-html-am install-info install-info-am \
|
||||
install-libLTLIBRARIES install-man install-pdf install-pdf-am \
|
||||
install-ps install-ps-am install-strip installcheck \
|
||||
installcheck-am installdirs maintainer-clean \
|
||||
maintainer-clean-generic mostlyclean mostlyclean-compile \
|
||||
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
|
||||
tags uninstall uninstall-am uninstall-libLTLIBRARIES
|
||||
|
||||
# Tell versions [3.59,3.63) of GNU make to not export all variables.
|
||||
# Otherwise a system limit (for SysV at least) may be exceeded.
|
||||
.NOEXPORT:
|
730
qse/lib/cmn/map.c
Normal file
730
qse/lib/cmn/map.c
Normal file
@ -0,0 +1,730 @@
|
||||
/*
|
||||
* $Id: map.c 496 2008-12-15 09:56:48Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
|
||||
#include <ase/cmn/map.h>
|
||||
#include "mem.h"
|
||||
|
||||
#define map_t ase_map_t
|
||||
#define pair_t ase_map_pair_t
|
||||
#define copier_t ase_map_copier_t
|
||||
#define freeer_t ase_map_freeer_t
|
||||
#define hasher_t ase_map_hasher_t
|
||||
#define comper_t ase_map_comper_t
|
||||
#define keeper_t ase_map_keeper_t
|
||||
#define sizer_t ase_map_sizer_t
|
||||
#define walker_t ase_map_walker_t
|
||||
|
||||
#define KPTR(p) ASE_MAP_KPTR(p)
|
||||
#define KLEN(p) ASE_MAP_KLEN(p)
|
||||
#define VPTR(p) ASE_MAP_VPTR(p)
|
||||
#define VLEN(p) ASE_MAP_VLEN(p)
|
||||
#define NEXT(p) ASE_MAP_NEXT(p)
|
||||
|
||||
#define SIZEOF(x) ASE_SIZEOF(x)
|
||||
#define size_t ase_size_t
|
||||
#define byte_t ase_byte_t
|
||||
#define uint_t ase_uint_t
|
||||
#define mmgr_t ase_mmgr_t
|
||||
|
||||
#define KTOB(map,len) ((len)*(map)->scale[ASE_MAP_KEY])
|
||||
#define VTOB(map,len) ((len)*(map)->scale[ASE_MAP_VAL])
|
||||
|
||||
static int reorganize (map_t* map);
|
||||
|
||||
static size_t hash_key (map_t* map, const void* kptr, size_t klen)
|
||||
{
|
||||
size_t n = 0;
|
||||
const byte_t* p = (const byte_t*)kptr;
|
||||
const byte_t* bound = p + klen;
|
||||
|
||||
while (p < bound)
|
||||
{
|
||||
n = n * 31 + *p++;
|
||||
p++;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
static int comp_key (map_t* map,
|
||||
const void* kptr1, size_t klen1,
|
||||
const void* kptr2, size_t klen2)
|
||||
{
|
||||
if (klen1 == klen2) return ASE_MEMCMP (kptr1, kptr2, KTOB(map,klen1));
|
||||
/* it just returns 1 to indicate that they are different. */
|
||||
return 1;
|
||||
}
|
||||
|
||||
static pair_t* alloc_pair (map_t* map,
|
||||
void* kptr, size_t klen, void* vptr, size_t vlen)
|
||||
{
|
||||
pair_t* n;
|
||||
copier_t kcop = map->copier[ASE_MAP_KEY];
|
||||
copier_t vcop = map->copier[ASE_MAP_VAL];
|
||||
|
||||
size_t as = SIZEOF(pair_t);
|
||||
if (kcop == ASE_MAP_COPIER_INLINE) as += KTOB(map,klen);
|
||||
if (vcop == ASE_MAP_COPIER_INLINE) as += VTOB(map,vlen);
|
||||
|
||||
n = (pair_t*) ASE_MMGR_ALLOC (map->mmgr, as);
|
||||
if (n == ASE_NULL) return ASE_NULL;
|
||||
|
||||
NEXT(n) = ASE_NULL;
|
||||
|
||||
KLEN(n) = klen;
|
||||
if (kcop == ASE_MAP_COPIER_SIMPLE)
|
||||
{
|
||||
KPTR(n) = kptr;
|
||||
}
|
||||
else if (kcop == ASE_MAP_COPIER_INLINE)
|
||||
{
|
||||
KPTR(n) = n + 1;
|
||||
ASE_MEMCPY (KPTR(n), kptr, KTOB(map,klen));
|
||||
}
|
||||
else
|
||||
{
|
||||
KPTR(n) = kcop (map, kptr, klen);
|
||||
if (KPTR(n) == ASE_NULL)
|
||||
{
|
||||
ASE_MMGR_FREE (map->mmgr, n);
|
||||
return ASE_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
VLEN(n) = vlen;
|
||||
if (vcop == ASE_MAP_COPIER_SIMPLE)
|
||||
{
|
||||
VPTR(n) = vptr;
|
||||
}
|
||||
else if (vcop == ASE_MAP_COPIER_INLINE)
|
||||
{
|
||||
VPTR(n) = n + 1;
|
||||
if (kcop == ASE_MAP_COPIER_INLINE)
|
||||
VPTR(n) = (byte_t*)VPTR(n) + KTOB(map,klen);
|
||||
ASE_MEMCPY (VPTR(n), vptr, VTOB(map,vlen));
|
||||
}
|
||||
else
|
||||
{
|
||||
VPTR(n) = vcop (map, vptr, vlen);
|
||||
if (VPTR(n) != ASE_NULL)
|
||||
{
|
||||
if (map->freeer[ASE_MAP_KEY] != ASE_NULL)
|
||||
map->freeer[ASE_MAP_KEY] (map, KPTR(n), KLEN(n));
|
||||
ASE_MMGR_FREE (map->mmgr, n);
|
||||
return ASE_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
static void free_pair (map_t* map, pair_t* pair)
|
||||
{
|
||||
if (map->freeer[ASE_MAP_KEY] != ASE_NULL)
|
||||
map->freeer[ASE_MAP_KEY] (map, KPTR(pair), KLEN(pair));
|
||||
if (map->freeer[ASE_MAP_VAL] != ASE_NULL)
|
||||
map->freeer[ASE_MAP_VAL] (map, VPTR(pair), VLEN(pair));
|
||||
ASE_MMGR_FREE (map->mmgr, pair);
|
||||
}
|
||||
|
||||
static pair_t* change_pair_val (
|
||||
map_t* map, pair_t* pair, void* vptr, size_t vlen)
|
||||
{
|
||||
if (VPTR(pair) == vptr && VLEN(pair) == vlen)
|
||||
{
|
||||
/* if the old value and the new value are the same,
|
||||
* it just calls the handler for this condition.
|
||||
* No value replacement occurs. */
|
||||
if (map->keeper != ASE_NULL)
|
||||
{
|
||||
map->keeper (map, vptr, vlen);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
copier_t vcop = map->copier[ASE_MAP_VAL];
|
||||
void* ovptr = VPTR(pair);
|
||||
size_t ovlen = VLEN(pair);
|
||||
|
||||
/* place the new value according to the copier */
|
||||
if (vcop == ASE_MAP_COPIER_SIMPLE)
|
||||
{
|
||||
VPTR(pair) = vptr;
|
||||
VLEN(pair) = vlen;
|
||||
}
|
||||
else if (vcop == ASE_MAP_COPIER_INLINE)
|
||||
{
|
||||
if (ovlen == vlen)
|
||||
{
|
||||
ASE_MEMCPY (VPTR(pair), vptr, VTOB(map,vlen));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* need to reconstruct the pair */
|
||||
pair_t* p = alloc_pair (map,
|
||||
KPTR(pair), KLEN(pair),
|
||||
vptr, vlen);
|
||||
if (p == ASE_NULL) return ASE_NULL;
|
||||
free_pair (map, pair);
|
||||
return p;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
void* nvptr = vcop (map, vptr, vlen);
|
||||
if (nvptr == ASE_NULL) return ASE_NULL;
|
||||
VPTR(pair) = nvptr;
|
||||
VLEN(pair) = vlen;
|
||||
}
|
||||
|
||||
/* free up the old value */
|
||||
if (map->freeer[ASE_MAP_VAL] != ASE_NULL)
|
||||
{
|
||||
map->freeer[ASE_MAP_VAL] (map, ovptr, ovlen);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return pair;
|
||||
}
|
||||
|
||||
map_t* ase_map_open (mmgr_t* mmgr, size_t ext, size_t capa, int factor)
|
||||
{
|
||||
map_t* map;
|
||||
|
||||
if (mmgr == ASE_NULL)
|
||||
{
|
||||
mmgr = ASE_MMGR_GETDFL();
|
||||
|
||||
ASE_ASSERTX (mmgr != ASE_NULL,
|
||||
"Set the memory manager with ASE_MMGR_SETDFL()");
|
||||
|
||||
if (mmgr == ASE_NULL) return ASE_NULL;
|
||||
}
|
||||
|
||||
map = (ase_map_t*) ASE_MMGR_ALLOC (mmgr, ASE_SIZEOF(ase_map_t) + ext);
|
||||
if (map == ASE_NULL) return ASE_NULL;
|
||||
|
||||
if (ase_map_init (map, mmgr, capa, factor) == ASE_NULL)
|
||||
{
|
||||
ASE_MMGR_FREE (mmgr, map);
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
void ase_map_close (map_t* map)
|
||||
{
|
||||
ase_map_fini (map);
|
||||
ASE_MMGR_FREE (map->mmgr, map);
|
||||
}
|
||||
|
||||
map_t* ase_map_init (map_t* map, mmgr_t* mmgr, size_t capa, int factor)
|
||||
{
|
||||
ASE_ASSERTX (capa > 0,
|
||||
"The initial capacity should be greater than 0. Otherwise, it is adjusted to 1 in the release mode");
|
||||
ASE_ASSERTX (factor >= 0 && factor <= 100,
|
||||
"The load factor should be between 0 and 100 inclusive. In the release mode, a value out of the range is adjusted to 100");
|
||||
|
||||
/* some initial adjustment */
|
||||
if (capa <= 0) capa = 1;
|
||||
if (factor > 100) factor = 100;
|
||||
|
||||
/* do not zero out the extension */
|
||||
ASE_MEMSET (map, 0, SIZEOF(*map));
|
||||
map->mmgr = mmgr;
|
||||
|
||||
map->bucket = ASE_MMGR_ALLOC (mmgr, capa*SIZEOF(pair_t*));
|
||||
if (map->bucket == ASE_NULL) return ASE_NULL;
|
||||
|
||||
/*for (i = 0; i < capa; i++) map->bucket[i] = ASE_NULL;*/
|
||||
ASE_MEMSET (map->bucket, 0, capa*SIZEOF(pair_t*));
|
||||
|
||||
map->scale[ASE_MAP_KEY] = 1;
|
||||
map->scale[ASE_MAP_VAL] = 1;
|
||||
map->factor = factor;
|
||||
|
||||
map->size = 0;
|
||||
map->capa = capa;
|
||||
map->threshold = map->capa * map->factor / 100;
|
||||
if (map->capa > 0 && map->threshold <= 0) map->threshold = 1;
|
||||
|
||||
map->hasher = hash_key;
|
||||
map->comper = comp_key;
|
||||
map->copier[ASE_MAP_KEY] = ASE_MAP_COPIER_SIMPLE;
|
||||
map->copier[ASE_MAP_VAL] = ASE_MAP_COPIER_SIMPLE;
|
||||
|
||||
/*
|
||||
map->freeer[ASE_MAP_KEY] = ASE_NULL;
|
||||
map->freeer[ASE_MAP_VAL] = ASE_NULL;
|
||||
map->keeper = ASE_NULL;
|
||||
map->sizer = ASE_NULL;
|
||||
*/
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
void ase_map_fini (map_t* map)
|
||||
{
|
||||
ase_map_clear (map);
|
||||
ASE_MMGR_FREE (map->mmgr, map->bucket);
|
||||
}
|
||||
|
||||
void* ase_map_getxtn (map_t* map)
|
||||
{
|
||||
return map + 1;
|
||||
}
|
||||
|
||||
mmgr_t* ase_map_getmmgr (map_t* map)
|
||||
{
|
||||
return map->mmgr;
|
||||
}
|
||||
|
||||
void ase_map_setmmgr (map_t* map, mmgr_t* mmgr)
|
||||
{
|
||||
map->mmgr = mmgr;
|
||||
}
|
||||
|
||||
int ase_map_getscale (map_t* map, ase_map_id_t id)
|
||||
{
|
||||
ASE_ASSERTX (id == ASE_MAP_KEY || id == ASE_MAP_VAL,
|
||||
"The ID should be either ASE_MAP_KEY or ASE_MAP_VAL");
|
||||
return map->scale[id];
|
||||
}
|
||||
|
||||
void ase_map_setscale (map_t* map, ase_map_id_t id, int scale)
|
||||
{
|
||||
ASE_ASSERTX (id == ASE_MAP_KEY || id == ASE_MAP_VAL,
|
||||
"The ID should be either ASE_MAP_KEY or ASE_MAP_VAL");
|
||||
|
||||
ASE_ASSERTX (scale > 0 && scale <= ASE_TYPE_MAX(ase_byte_t),
|
||||
"The scale should be larger than 0 and less than or equal to the maximum value that the ase_byte_t type can hold");
|
||||
|
||||
if (scale <= 0) scale = 1;
|
||||
if (scale > ASE_TYPE_MAX(ase_byte_t)) scale = ASE_TYPE_MAX(ase_byte_t);
|
||||
|
||||
map->scale[id] = scale;
|
||||
}
|
||||
|
||||
copier_t ase_map_getcopier (map_t* map, ase_map_id_t id)
|
||||
{
|
||||
ASE_ASSERTX (id == ASE_MAP_KEY || id == ASE_MAP_VAL,
|
||||
"The ID should be either ASE_MAP_KEY or ASE_MAP_VAL");
|
||||
return map->copier[id];
|
||||
}
|
||||
|
||||
void ase_map_setcopier (map_t* map, ase_map_id_t id, copier_t copier)
|
||||
{
|
||||
ASE_ASSERTX (id == ASE_MAP_KEY || id == ASE_MAP_VAL,
|
||||
"The ID should be either ASE_MAP_KEY or ASE_MAP_VAL");
|
||||
if (copier == ASE_NULL) copier = ASE_MAP_COPIER_SIMPLE;
|
||||
map->copier[id] = copier;
|
||||
}
|
||||
|
||||
freeer_t ase_map_getfreeer (map_t* map, ase_map_id_t id)
|
||||
{
|
||||
ASE_ASSERTX (id == ASE_MAP_KEY || id == ASE_MAP_VAL,
|
||||
"The ID should be either ASE_MAP_KEY or ASE_MAP_VAL");
|
||||
return map->freeer[id];
|
||||
}
|
||||
|
||||
void ase_map_setfreeer (map_t* map, ase_map_id_t id, freeer_t freeer)
|
||||
{
|
||||
ASE_ASSERTX (id == ASE_MAP_KEY || id == ASE_MAP_VAL,
|
||||
"The ID should be either ASE_MAP_KEY or ASE_MAP_VAL");
|
||||
map->freeer[id] = freeer;
|
||||
}
|
||||
|
||||
hasher_t ase_map_gethasher (map_t* map)
|
||||
{
|
||||
return map->hasher;
|
||||
}
|
||||
|
||||
void ase_map_sethasher (map_t* map, hasher_t hasher)
|
||||
{
|
||||
if (hasher == ASE_NULL) hasher = hash_key;
|
||||
map->hasher = hasher;
|
||||
}
|
||||
|
||||
comper_t ase_map_getcomper (map_t* map)
|
||||
{
|
||||
return map->comper;
|
||||
}
|
||||
|
||||
void ase_map_setcomper (map_t* map, comper_t comper)
|
||||
{
|
||||
if (comper == ASE_NULL) comper = comp_key;
|
||||
map->comper = comper;
|
||||
}
|
||||
|
||||
keeper_t ase_map_getkeeper (map_t* map)
|
||||
{
|
||||
return map->keeper;
|
||||
}
|
||||
|
||||
void ase_map_setkeeper (map_t* map, keeper_t keeper)
|
||||
{
|
||||
map->keeper = keeper;
|
||||
}
|
||||
|
||||
sizer_t ase_map_getsizer (map_t* map)
|
||||
{
|
||||
return map->sizer;
|
||||
}
|
||||
|
||||
void ase_map_setsizer (map_t* map, sizer_t sizer)
|
||||
{
|
||||
map->sizer = sizer;
|
||||
}
|
||||
|
||||
size_t ase_map_getsize (map_t* map)
|
||||
{
|
||||
return map->size;
|
||||
}
|
||||
|
||||
size_t ase_map_getcapa (map_t* map)
|
||||
{
|
||||
return map->capa;
|
||||
}
|
||||
|
||||
pair_t* ase_map_search (map_t* map, const void* kptr, size_t klen)
|
||||
{
|
||||
pair_t* pair;
|
||||
size_t hc;
|
||||
|
||||
hc = map->hasher(map,kptr,klen) % map->capa;
|
||||
pair = map->bucket[hc];
|
||||
|
||||
while (pair != ASE_NULL)
|
||||
{
|
||||
if (map->comper (map, KPTR(pair), KLEN(pair), kptr, klen) == 0)
|
||||
{
|
||||
return pair;
|
||||
}
|
||||
|
||||
pair = NEXT(pair);
|
||||
}
|
||||
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
int ase_map_put (
|
||||
map_t* map, void* kptr, size_t klen,
|
||||
void* vptr, size_t vlen, pair_t** px)
|
||||
{
|
||||
pair_t* pair, * p, * prev, * next;
|
||||
size_t hc;
|
||||
|
||||
hc = map->hasher(map,kptr,klen) % map->capa;
|
||||
pair = map->bucket[hc];
|
||||
prev = ASE_NULL;
|
||||
|
||||
while (pair != ASE_NULL)
|
||||
{
|
||||
next = NEXT(pair);
|
||||
|
||||
if (map->comper (map, KPTR(pair), KLEN(pair), kptr, klen) == 0)
|
||||
{
|
||||
p = change_pair_val (map, pair, vptr, vlen);
|
||||
if (p == ASE_NULL) return -1; /* change error */
|
||||
if (p != pair)
|
||||
{
|
||||
/* the pair has been reallocated. relink it */
|
||||
if (prev == ASE_NULL) map->bucket[hc] = p;
|
||||
else NEXT(prev) = p;
|
||||
NEXT(p) = next;
|
||||
}
|
||||
|
||||
if (px != ASE_NULL) *px = p;
|
||||
return 0; /* value changed for the existing key */
|
||||
}
|
||||
|
||||
prev = pair;
|
||||
pair = next;
|
||||
}
|
||||
|
||||
if (map->threshold > 0 && map->size >= map->threshold)
|
||||
{
|
||||
if (reorganize(map) == 0) /* ignore the error */
|
||||
{
|
||||
hc = map->hasher(map,kptr,klen) % map->capa;
|
||||
}
|
||||
}
|
||||
|
||||
ASE_ASSERT (pair == ASE_NULL);
|
||||
|
||||
pair = alloc_pair (map, kptr, klen, vptr, vlen);
|
||||
if (pair == ASE_NULL) return -1; /* error */
|
||||
|
||||
NEXT(pair) = map->bucket[hc];
|
||||
map->bucket[hc] = pair;
|
||||
map->size++;
|
||||
|
||||
if (px != ASE_NULL) *px = pair;
|
||||
return 1; /* new key added */
|
||||
}
|
||||
|
||||
pair_t* ase_map_upsert (
|
||||
map_t* map, void* kptr, size_t klen, void* vptr, size_t vlen)
|
||||
{
|
||||
/* update if the key exists, otherwise insert a new pair */
|
||||
int n;
|
||||
pair_t* px;
|
||||
|
||||
n = ase_map_put (map, kptr, klen, vptr, vlen, &px);
|
||||
if (n < 0) return ASE_NULL;
|
||||
return px;
|
||||
}
|
||||
|
||||
pair_t* ase_map_insert (map_t* map, void* kptr, size_t klen, void* vptr, size_t vlen)
|
||||
{
|
||||
pair_t* pair;
|
||||
size_t hc;
|
||||
|
||||
hc = map->hasher(map,kptr,klen) % map->capa;
|
||||
pair = map->bucket[hc];
|
||||
|
||||
while (pair != ASE_NULL)
|
||||
{
|
||||
if (map->comper (map, KPTR(pair), KLEN(pair), kptr, klen) == 0)
|
||||
{
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
pair = NEXT(pair);
|
||||
}
|
||||
|
||||
if (map->threshold > 0 && map->size >= map->threshold)
|
||||
{
|
||||
if (reorganize(map) == 0) /* ignore the error */
|
||||
{
|
||||
hc = map->hasher(map,kptr,klen) % map->capa;
|
||||
}
|
||||
}
|
||||
|
||||
ASE_ASSERT (pair == ASE_NULL);
|
||||
|
||||
pair = alloc_pair (map, kptr, klen, vptr, vlen);
|
||||
if (pair == ASE_NULL) return ASE_NULL;
|
||||
|
||||
NEXT(pair) = map->bucket[hc];
|
||||
map->bucket[hc] = pair;
|
||||
map->size++;
|
||||
|
||||
return pair;
|
||||
}
|
||||
|
||||
pair_t* ase_map_update (map_t* map, void* kptr, size_t klen, void* vptr, size_t vlen)
|
||||
{
|
||||
pair_t* pair, * p, * prev, * next;
|
||||
size_t hc;
|
||||
|
||||
hc = map->hasher(map,kptr,klen) % map->capa;
|
||||
pair = map->bucket[hc];
|
||||
prev = ASE_NULL;
|
||||
|
||||
while (pair != ASE_NULL)
|
||||
{
|
||||
next = NEXT(pair);
|
||||
|
||||
if (map->comper (map, KPTR(pair), KLEN(pair), kptr, klen) == 0)
|
||||
{
|
||||
p = change_pair_val (map, pair, vptr, vlen);
|
||||
|
||||
if (p == ASE_NULL) return ASE_NULL; /* change error */
|
||||
if (p != pair)
|
||||
{
|
||||
/* the pair has been reallocated. relink it */
|
||||
if (prev == ASE_NULL) map->bucket[hc] = p;
|
||||
else NEXT(prev) = p;
|
||||
NEXT(p) = next;
|
||||
}
|
||||
|
||||
return p; /* value changed for the existing key */
|
||||
}
|
||||
|
||||
prev = pair;
|
||||
pair = next;
|
||||
}
|
||||
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
int ase_map_delete (map_t* map, const void* kptr, size_t klen)
|
||||
{
|
||||
pair_t* pair, * prev;
|
||||
size_t hc;
|
||||
|
||||
hc = map->hasher(map,kptr,klen) % map->capa;
|
||||
pair = map->bucket[hc];
|
||||
prev = ASE_NULL;
|
||||
|
||||
while (pair != ASE_NULL)
|
||||
{
|
||||
if (map->comper (map, KPTR(pair), KLEN(pair), kptr, klen) == 0)
|
||||
{
|
||||
if (prev == ASE_NULL)
|
||||
map->bucket[hc] = NEXT(pair);
|
||||
else NEXT(prev) = NEXT(pair);
|
||||
|
||||
free_pair (map, pair);
|
||||
map->size--;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
prev = pair;
|
||||
pair = NEXT(pair);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void ase_map_clear (map_t* map)
|
||||
{
|
||||
size_t i;
|
||||
pair_t* pair, * next;
|
||||
|
||||
for (i = 0; i < map->capa; i++)
|
||||
{
|
||||
pair = map->bucket[i];
|
||||
|
||||
while (pair != ASE_NULL)
|
||||
{
|
||||
next = NEXT(pair);
|
||||
free_pair (map, pair);
|
||||
map->size--;
|
||||
pair = next;
|
||||
}
|
||||
|
||||
map->bucket[i] = ASE_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ase_map_walk (map_t* map, walker_t walker, void* arg)
|
||||
{
|
||||
size_t i;
|
||||
pair_t* pair, * next;
|
||||
|
||||
for (i = 0; i < map->capa; i++)
|
||||
{
|
||||
pair = map->bucket[i];
|
||||
|
||||
while (pair != ASE_NULL)
|
||||
{
|
||||
next = NEXT(pair);
|
||||
if (walker(map, pair, arg) == ASE_MAP_WALK_STOP) return;
|
||||
pair = next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pair_t* ase_map_getfirstpair (map_t* map, size_t* buckno)
|
||||
{
|
||||
size_t i;
|
||||
pair_t* pair;
|
||||
|
||||
for (i = 0; i < map->capa; i++)
|
||||
{
|
||||
pair = map->bucket[i];
|
||||
if (pair != ASE_NULL)
|
||||
{
|
||||
*buckno = i;
|
||||
return pair;
|
||||
}
|
||||
}
|
||||
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
pair_t* ase_map_getnextpair (map_t* map, pair_t* pair, size_t* buckno)
|
||||
{
|
||||
size_t i;
|
||||
pair_t* next;
|
||||
|
||||
next = NEXT(pair);
|
||||
if (next != ASE_NULL)
|
||||
{
|
||||
/* no change in bucket number */
|
||||
return next;
|
||||
}
|
||||
|
||||
for (i = (*buckno)+1; i < map->capa; i++)
|
||||
{
|
||||
pair = map->bucket[i];
|
||||
if (pair != ASE_NULL)
|
||||
{
|
||||
*buckno = i;
|
||||
return pair;
|
||||
}
|
||||
}
|
||||
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
static int reorganize (map_t* map)
|
||||
{
|
||||
size_t i, hc, new_capa;
|
||||
pair_t** new_buck;
|
||||
|
||||
if (map->sizer)
|
||||
{
|
||||
new_capa = map->sizer (map, map->capa + 1);
|
||||
|
||||
/* if no change in capacity, return success
|
||||
* without reorganization */
|
||||
if (new_capa == map->capa) return 0;
|
||||
|
||||
/* adjust to 1 if the new capacity is not reasonable */
|
||||
if (new_capa <= 0) new_capa = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* the bucket is doubled until it grows up to 65536 slots.
|
||||
* once it has reached it, it grows by 65536 slots */
|
||||
new_capa = (map->capa >= 65536)? (map->capa + 65536): (map->capa << 1);
|
||||
}
|
||||
|
||||
new_buck = (pair_t**) ASE_MMGR_ALLOC (
|
||||
map->mmgr, new_capa*SIZEOF(pair_t*));
|
||||
if (new_buck == ASE_NULL)
|
||||
{
|
||||
/* reorganization is disabled once it fails */
|
||||
map->threshold = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*for (i = 0; i < new_capa; i++) new_buck[i] = ASE_NULL;*/
|
||||
ASE_MEMSET (new_buck, 0, new_capa*SIZEOF(pair_t*));
|
||||
|
||||
for (i = 0; i < map->capa; i++)
|
||||
{
|
||||
pair_t* pair = map->bucket[i];
|
||||
|
||||
while (pair != ASE_NULL)
|
||||
{
|
||||
pair_t* next = NEXT(pair);
|
||||
|
||||
hc = map->hasher (map,
|
||||
KPTR(pair),
|
||||
KLEN(pair)) % new_capa;
|
||||
|
||||
NEXT(pair) = new_buck[hc];
|
||||
new_buck[hc] = pair;
|
||||
|
||||
pair = next;
|
||||
}
|
||||
}
|
||||
|
||||
ASE_MMGR_FREE (map->mmgr, map->bucket);
|
||||
map->bucket = new_buck;
|
||||
map->capa = new_capa;
|
||||
map->threshold = map->capa * map->factor / 100;
|
||||
|
||||
return 0;
|
||||
}
|
427
qse/lib/cmn/mem.c
Normal file
427
qse/lib/cmn/mem.c
Normal file
@ -0,0 +1,427 @@
|
||||
/*
|
||||
* $Id: mem.c 335 2008-08-20 08:22:07Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
|
||||
#include <ase/cmn/mem.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(__SPU__)
|
||||
#include <spu_intrinsics.h>
|
||||
#define SPU_VUC_SIZE ASE_SIZEOF(vector unsigned char)
|
||||
#endif
|
||||
|
||||
/*#define IS_UNALIGNED(ptr) (((ase_size_t)ptr)%ASE_SIZEOF(ase_size_t))*/
|
||||
#define IS_UNALIGNED(ptr) (((ase_size_t)ptr)&(ASE_SIZEOF(ase_size_t)-1))
|
||||
#define IS_ALIGNED(ptr) (!IS_UNALIGNED(ptr))
|
||||
|
||||
#define IS_EITHER_UNALIGNED(ptr1,ptr2) \
|
||||
(((ase_size_t)ptr1|(ase_size_t)ptr2)&(ASE_SIZEOF(ase_size_t)-1))
|
||||
#define IS_BOTH_ALIGNED(ptr1,ptr2) (!IS_EITHER_UNALIGNED(ptr1,ptr2))
|
||||
|
||||
void* ase_memcpy (void* dst, const void* src, ase_size_t n)
|
||||
{
|
||||
#if defined(ASE_BUILD_FOR_SIZE)
|
||||
|
||||
ase_byte_t* d = (ase_byte_t*)dst;
|
||||
ase_byte_t* s = (ase_byte_t*)src;
|
||||
while (n-- > 0) *d++ = *s++;
|
||||
return dst;
|
||||
|
||||
#elif defined(__SPU__)
|
||||
|
||||
ase_byte_t* d;
|
||||
ase_byte_t* s;
|
||||
|
||||
if (n >= SPU_VUC_SIZE &&
|
||||
(((ase_size_t)dst) & (SPU_VUC_SIZE-1)) == 0 &&
|
||||
(((ase_size_t)src) & (SPU_VUC_SIZE-1)) == 0)
|
||||
{
|
||||
vector unsigned char* du = (vector unsigned char*)dst;
|
||||
vector unsigned char* su = (vector unsigned char*)src;
|
||||
|
||||
do
|
||||
{
|
||||
*du++ = *su++;
|
||||
n -= SPU_VUC_SIZE;
|
||||
}
|
||||
while (n >= SPU_VUC_SIZE);
|
||||
|
||||
d = (ase_byte_t*)du;
|
||||
s = (ase_byte_t*)su;
|
||||
}
|
||||
else
|
||||
{
|
||||
d = (ase_byte_t*)dst;
|
||||
s = (ase_byte_t*)src;
|
||||
}
|
||||
|
||||
while (n-- > 0) *d++ = *s++;
|
||||
return dst;
|
||||
|
||||
#else
|
||||
|
||||
ase_byte_t* d;
|
||||
ase_byte_t* s;
|
||||
|
||||
if (n >= ASE_SIZEOF(ase_size_t) && IS_BOTH_ALIGNED(dst,src))
|
||||
{
|
||||
ase_size_t* du = (ase_size_t*)dst;
|
||||
ase_size_t* su = (ase_size_t*)src;
|
||||
|
||||
do
|
||||
{
|
||||
*du++ = *su++;
|
||||
n -= ASE_SIZEOF(ase_size_t);
|
||||
}
|
||||
while (n >= ASE_SIZEOF(ase_size_t));
|
||||
|
||||
d = (ase_byte_t*)du;
|
||||
s = (ase_byte_t*)su;
|
||||
}
|
||||
else
|
||||
{
|
||||
d = (ase_byte_t*)dst;
|
||||
s = (ase_byte_t*)src;
|
||||
}
|
||||
|
||||
while (n-- > 0) *d++ = *s++;
|
||||
return dst;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void* ase_memmove (void* dst, const void* src, ase_size_t n)
|
||||
{
|
||||
const ase_byte_t* sre = (const ase_byte_t*)src + n;
|
||||
|
||||
if (dst <= src || dst >= (const void*)sre)
|
||||
{
|
||||
ase_byte_t* d = (ase_byte_t*)dst;
|
||||
const ase_byte_t* s = (const ase_byte_t*)src;
|
||||
while (n-- > 0) *d++ = *s++;
|
||||
}
|
||||
else
|
||||
{
|
||||
ase_byte_t* dse = (ase_byte_t*)dst + n;
|
||||
while (n-- > 0) *--dse = *--sre;
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
void* ase_memset (void* dst, int val, ase_size_t n)
|
||||
{
|
||||
#if defined(ASE_BUILD_FOR_SIZE)
|
||||
|
||||
ase_byte_t* d = (ase_byte_t*)dst;
|
||||
while (n-- > 0) *d++ = (ase_byte_t)val;
|
||||
return dst;
|
||||
|
||||
#elif defined(__SPU__)
|
||||
|
||||
ase_byte_t* d;
|
||||
ase_size_t rem;
|
||||
|
||||
if (n <= 0) return dst;
|
||||
|
||||
d = (ase_byte_t*)dst;
|
||||
|
||||
/* spu SIMD instructions require 16-byte alignment */
|
||||
rem = ((ase_size_t)dst) & (SPU_VUC_SIZE-1);
|
||||
if (rem > 0)
|
||||
{
|
||||
/* handle leading unaligned part */
|
||||
do { *d++ = (ase_byte_t)val; }
|
||||
while (n-- > 0 && ++rem < SPU_VUC_SIZE);
|
||||
}
|
||||
|
||||
/* do the vector copy */
|
||||
if (n >= SPU_VUC_SIZE)
|
||||
{
|
||||
/* a vector of 16 unsigned char cells */
|
||||
vector unsigned char v16;
|
||||
/* a pointer to such a vector */
|
||||
vector unsigned char* vd = (vector unsigned char*)d;
|
||||
|
||||
/* fills all 16 unsigned char cells with the same value
|
||||
* no need to use shift and bitwise-or owing to splats */
|
||||
v16 = spu_splats((ase_byte_t)val);
|
||||
|
||||
do
|
||||
{
|
||||
*vd++ = v16;
|
||||
n -= SPU_VUC_SIZE;
|
||||
}
|
||||
while (n >= SPU_VUC_SIZE);
|
||||
|
||||
d = (ase_byte_t*)vd;
|
||||
}
|
||||
|
||||
/* handle the trailing part */
|
||||
while (n-- > 0) *d++ = (ase_byte_t)val;
|
||||
return dst;
|
||||
|
||||
#else
|
||||
|
||||
ase_byte_t* d;
|
||||
ase_size_t rem;
|
||||
|
||||
if (n <= 0) return dst;
|
||||
|
||||
d = (ase_byte_t*)dst;
|
||||
|
||||
rem = IS_UNALIGNED(dst);
|
||||
if (rem > 0)
|
||||
{
|
||||
do { *d++ = (ase_byte_t)val; }
|
||||
while (n-- > 0 && ++rem < ASE_SIZEOF(ase_size_t));
|
||||
}
|
||||
|
||||
if (n >= ASE_SIZEOF(ase_size_t))
|
||||
{
|
||||
ase_size_t* u = (ase_size_t*)d;
|
||||
ase_size_t uv = 0;
|
||||
int i;
|
||||
|
||||
if (val != 0)
|
||||
{
|
||||
for (i = 0; i < ASE_SIZEOF(ase_size_t); i++)
|
||||
uv = (uv << 8) | (ase_byte_t)val;
|
||||
}
|
||||
|
||||
ASE_ASSERT (IS_ALIGNED(u));
|
||||
do
|
||||
{
|
||||
*u++ = uv;
|
||||
n -= ASE_SIZEOF(ase_size_t);
|
||||
}
|
||||
while (n >= ASE_SIZEOF(ase_size_t));
|
||||
|
||||
d = (ase_byte_t*)u;
|
||||
}
|
||||
|
||||
while (n-- > 0) *d++ = (ase_byte_t)val;
|
||||
return dst;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
int ase_memcmp (const void* s1, const void* s2, ase_size_t n)
|
||||
{
|
||||
#if defined(ASE_BUILD_FOR_SIZE)
|
||||
|
||||
const ase_byte_t* b1 = (const ase_byte_t*)s1;
|
||||
const ase_byte_t* b2 = (const ase_byte_t*)s2;
|
||||
|
||||
while (n-- > 0)
|
||||
{
|
||||
if (*b1 != *b2) return *b1 - *b2;
|
||||
b1++; b2++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
#elif defined(__SPU__)
|
||||
|
||||
const ase_byte_t* b1;
|
||||
const ase_byte_t* b2;
|
||||
|
||||
if (n >= SPU_VUC_SIZE &&
|
||||
(((ase_size_t)s1) & (SPU_VUC_SIZE-1)) == 0 &&
|
||||
(((ase_size_t)s2) & (SPU_VUC_SIZE-1)) == 0)
|
||||
{
|
||||
vector unsigned char* v1 = (vector unsigned char*)s1;
|
||||
vector unsigned char* v2 = (vector unsigned char*)s2;
|
||||
|
||||
vector unsigned int tmp;
|
||||
|
||||
do
|
||||
{
|
||||
unsigned int cnt;
|
||||
unsigned int pat;
|
||||
|
||||
/* compare 16 chars at one time */
|
||||
tmp = spu_gather(spu_cmpeq(*v1,*v2));
|
||||
/* extract the bit pattern */
|
||||
pat = spu_extract(tmp, 0);
|
||||
/* invert the bit patterns */
|
||||
pat = 0xFFFF & ~pat;
|
||||
|
||||
/* put it back to the vector */
|
||||
tmp = spu_insert (pat, tmp, 0);
|
||||
/* count the leading zeros */
|
||||
cnt = spu_extract(spu_cntlz(tmp),0);
|
||||
/* 32 leading zeros mean that
|
||||
* all characters are the same */
|
||||
if (cnt != 32)
|
||||
{
|
||||
/* otherwise, calculate the
|
||||
* unmatching pointer address */
|
||||
b1 = (const ase_byte_t*)v1 + (cnt - 16);
|
||||
b2 = (const ase_byte_t*)v2 + (cnt - 16);
|
||||
break;
|
||||
}
|
||||
|
||||
v1++; v2++;
|
||||
n -= SPU_VUC_SIZE;
|
||||
|
||||
if (n < SPU_VUC_SIZE)
|
||||
{
|
||||
b1 = (const ase_byte_t*)v1;
|
||||
b2 = (const ase_byte_t*)v2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (1);
|
||||
}
|
||||
else
|
||||
{
|
||||
b1 = (const ase_byte_t*)s1;
|
||||
b2 = (const ase_byte_t*)s2;
|
||||
}
|
||||
|
||||
while (n-- > 0)
|
||||
{
|
||||
if (*b1 != *b2) return *b1 - *b2;
|
||||
b1++; b2++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
#else
|
||||
const ase_byte_t* b1;
|
||||
const ase_byte_t* b2;
|
||||
|
||||
if (n >= ASE_SIZEOF(ase_size_t) && IS_BOTH_ALIGNED(s1,s2))
|
||||
{
|
||||
const ase_size_t* u1 = (const ase_size_t*)s1;
|
||||
const ase_size_t* u2 = (const ase_size_t*)s2;
|
||||
|
||||
do
|
||||
{
|
||||
if (*u1 != *u2) break;
|
||||
u1++; u2++;
|
||||
n -= ASE_SIZEOF(ase_size_t);
|
||||
}
|
||||
while (n >= ASE_SIZEOF(ase_size_t));
|
||||
|
||||
b1 = (const ase_byte_t*)u1;
|
||||
b2 = (const ase_byte_t*)u2;
|
||||
}
|
||||
else
|
||||
{
|
||||
b1 = (const ase_byte_t*)s1;
|
||||
b2 = (const ase_byte_t*)s2;
|
||||
}
|
||||
|
||||
while (n-- > 0)
|
||||
{
|
||||
if (*b1 != *b2) return *b1 - *b2;
|
||||
b1++; b2++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void* ase_memchr (const void* s, int val, ase_size_t n)
|
||||
{
|
||||
const ase_byte_t* x = (const ase_byte_t*)s;
|
||||
|
||||
while (n-- > 0)
|
||||
{
|
||||
if (*x == (ase_byte_t)val) return (void*)x;
|
||||
x++;
|
||||
}
|
||||
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
void* ase_memrchr (const void* s, int val, ase_size_t n)
|
||||
{
|
||||
const ase_byte_t* x = (ase_byte_t*)s + n - 1;
|
||||
|
||||
while (n-- > 0)
|
||||
{
|
||||
if (*x == (ase_byte_t)val) return (void*)x;
|
||||
x--;
|
||||
}
|
||||
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
void* ase_memmem (const void* hs, ase_size_t hl, const void* nd, ase_size_t nl)
|
||||
{
|
||||
if (nl <= hl)
|
||||
{
|
||||
ase_size_t i;
|
||||
const ase_byte_t* h = (const ase_byte_t*)hs;
|
||||
|
||||
for (i = hl - nl + 1; i > 0; i--)
|
||||
{
|
||||
if (ase_memcmp(h, nd, nl) == 0) return (void*)h;
|
||||
h++;
|
||||
}
|
||||
}
|
||||
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
void* ase_memrmem (const void* hs, ase_size_t hl, const void* nd, ase_size_t nl)
|
||||
{
|
||||
if (nl <= hl)
|
||||
{
|
||||
ase_size_t i;
|
||||
const ase_byte_t* h;
|
||||
|
||||
/* things are slightly more complacated
|
||||
* when searching backward */
|
||||
if (nl == 0)
|
||||
{
|
||||
/* when the needle is empty, it returns
|
||||
* the pointer to the last byte of the haystack.
|
||||
* this is because ase_memmem returns the pointer
|
||||
* to the first byte of the haystack when the
|
||||
* needle is empty. but I'm not so sure if this
|
||||
* is really desirable behavior */
|
||||
h = (const ase_byte_t*)hs + hl - 1;
|
||||
return (void*)h;
|
||||
}
|
||||
|
||||
h = (const ase_byte_t*)hs + hl - nl;
|
||||
for (i = hl - nl + 1; i > 0; i--)
|
||||
{
|
||||
if (ase_memcmp(h, nd, nl) == 0) return (void*)h;
|
||||
h--;
|
||||
}
|
||||
}
|
||||
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
static void* mmgr_alloc (void* data, ase_size_t n)
|
||||
{
|
||||
return malloc (n);
|
||||
}
|
||||
|
||||
static void* mmgr_realloc (void* data, void* ptr, ase_size_t n)
|
||||
{
|
||||
return realloc (ptr, n);
|
||||
}
|
||||
|
||||
static void mmgr_free (void* data, void* ptr)
|
||||
{
|
||||
free (ptr);
|
||||
}
|
||||
|
||||
static ase_mmgr_t mmgr =
|
||||
{
|
||||
mmgr_alloc,
|
||||
mmgr_realloc,
|
||||
mmgr_free,
|
||||
ASE_NULL
|
||||
};
|
||||
|
||||
ase_mmgr_t* ase_mmgr = &mmgr;
|
39
qse/lib/cmn/mem.h
Normal file
39
qse/lib/cmn/mem.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
|
||||
#ifndef _ASE_LIB_CMN_MEM_H_
|
||||
#define _ASE_LIB_CMN_MEM_H_
|
||||
|
||||
#include <ase/cmn/mem.h>
|
||||
|
||||
#ifdef USE_STDC
|
||||
|
||||
#include <string.h>
|
||||
#define ASE_MEMCPY(dst,src,len) memcpy(dst,src,len)
|
||||
#define ASE_MEMCMP(p1,p2,len) memcmp(p1,p2,len)
|
||||
#define ASE_MEMSET(dst,val,len) memset(dst,val,len)
|
||||
#define ASE_MEMBYTE(s,val,len) memchr(s,val,len)
|
||||
#define ASE_MEMRBYTE(s,val,len) memrchr(s,val,len)
|
||||
#define ASE_MEMMEM(hs,hl,nd,nl) memmem(hs,hl,nd,nl)
|
||||
#define ASE_MEMRMEM(hs,hl,nd,nl) memrmem(hs,hl,nd,nl)
|
||||
|
||||
#else
|
||||
|
||||
#define ASE_MEMCPY(dst,src,len) ase_memcpy(dst,src,len)
|
||||
#define ASE_MEMCMP(p1,p2,len) ase_memcmp(p1,p2,len)
|
||||
#define ASE_MEMSET(dst,val,len) ase_memset(dst,val,len)
|
||||
#define ASE_MEMBYTE(s,val,len) ase_membyte(s,val,len)
|
||||
#define ASE_MEMRBYTE(s,val,len) ase_memrbyte(s,val,len)
|
||||
#define ASE_MEMMEM(hs,hl,nd,nl) ase_memmem(hs,hl,nd,nl)
|
||||
#define ASE_MEMRMEM(hs,hl,nd,nl) ase_memrmem(hs,hl,nd,nl)
|
||||
|
||||
#endif
|
||||
|
||||
#define ASE_MALLOC(mmgr,size) ASE_MMGR_ALLOC(mmgr,size)
|
||||
#define ASE_REALLOC(mmgr,ptr,size) ASE_MMGR_REALLOC(mmgr,ptr,size)
|
||||
#define ASE_FREE(mmgr,ptr) ASE_MMGR_FREE(mmgr,ptr)
|
||||
|
||||
#endif
|
11
qse/lib/cmn/misc.c
Normal file
11
qse/lib/cmn/misc.c
Normal file
@ -0,0 +1,11 @@
|
||||
/*
|
||||
* $Id: misc.c 191 2008-06-06 10:19:57Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
|
||||
#if defined(__BORLANDC__)
|
||||
#pragma hdrstop
|
||||
#define Library
|
||||
#endif
|
||||
|
75
qse/lib/cmn/msw-bcc.mak
Normal file
75
qse/lib/cmn/msw-bcc.mak
Normal file
@ -0,0 +1,75 @@
|
||||
NAME = asecmn
|
||||
|
||||
!ifndef MODE
|
||||
MODE = release
|
||||
!endif
|
||||
|
||||
CC = bcc32
|
||||
LD = ilink32
|
||||
AR = tlib
|
||||
|
||||
CFLAGS = -WM -WU -RT- -w -q -I..\..
|
||||
|
||||
!IF "$(MODE)" == "debug"
|
||||
CFLAGS = $(CFLAGS) -D_DEBUG -DDEBUG
|
||||
!ELSEIF "$(MODE)" == "release"
|
||||
CFLAGS = $(CFLAGS) -DNDEBUG -O2
|
||||
!ELSE
|
||||
CFLAGS = $(CFLAGS)
|
||||
!ENDIF
|
||||
|
||||
OUT_DIR = ..\$(MODE)\lib
|
||||
OUT_FILE_LIB = $(OUT_DIR)\$(NAME).lib
|
||||
|
||||
TMP_DIR = $(MODE)
|
||||
|
||||
OBJ_FILES_LIB = \
|
||||
$(TMP_DIR)\mem.obj \
|
||||
$(TMP_DIR)\str_bas.obj \
|
||||
$(TMP_DIR)\str_cnv.obj \
|
||||
$(TMP_DIR)\str_dyn.obj \
|
||||
$(TMP_DIR)\map.obj \
|
||||
$(TMP_DIR)\rex.obj \
|
||||
$(TMP_DIR)\misc.obj
|
||||
|
||||
all: lib
|
||||
|
||||
lib: $(TMP_DIR) $(OUT_DIR) $(OUT_FILE_LIB)
|
||||
|
||||
$(OUT_FILE_LIB): $(OBJ_FILES_LIB)
|
||||
$(AR) $(OUT_FILE_LIB) @&&!
|
||||
+-$(**: = &^
|
||||
+-)
|
||||
!
|
||||
|
||||
$(TMP_DIR)\mem.obj: mem.c
|
||||
$(CC) $(CFLAGS) -o$@ -c mem.c
|
||||
|
||||
$(TMP_DIR)\str_bas.obj: str_bas.c
|
||||
$(CC) $(CFLAGS) -o$@ -c str_bas.c
|
||||
|
||||
$(TMP_DIR)\str_cnv.obj: str_cnv.c
|
||||
$(CC) $(CFLAGS) -o$@ -c str_cnv.c
|
||||
|
||||
$(TMP_DIR)\str_dyn.obj: str_dyn.c
|
||||
$(CC) $(CFLAGS) -o$@ -c str_dyn.c
|
||||
|
||||
$(TMP_DIR)\map.obj: map.c
|
||||
$(CC) $(CFLAGS) -o$@ -c map.c
|
||||
|
||||
$(TMP_DIR)\rex.obj: rex.c
|
||||
$(CC) $(CFLAGS) -o$@ -c rex.c
|
||||
|
||||
$(TMP_DIR)\misc.obj: misc.c
|
||||
$(CC) $(CFLAGS) -o$@ -c misc.c
|
||||
|
||||
$(OUT_DIR):
|
||||
-md $(OUT_DIR)
|
||||
|
||||
$(TMP_DIR):
|
||||
-md $(TMP_DIR)
|
||||
|
||||
clean:
|
||||
-del $(OUT_FILE_LIB)
|
||||
-del $(OBJ_FILES_LIB)
|
||||
|
71
qse/lib/cmn/msw-cl.mak
Normal file
71
qse/lib/cmn/msw-cl.mak
Normal file
@ -0,0 +1,71 @@
|
||||
NAME = asecmn
|
||||
MODE = release
|
||||
|
||||
CC = cl
|
||||
LD = link
|
||||
AR = link
|
||||
|
||||
CFLAGS = /nologo /W3 -I..\..
|
||||
|
||||
!IF "$(MODE)" == "debug"
|
||||
CFLAGS = $(CFLAGS) -D_DEBUG -DDEBUG /MTd /Zi
|
||||
!ELSEIF "$(MODE)" == "release"
|
||||
CFLAGS = $(CFLAGS) -DNDEBUG /MT /O2
|
||||
!ELSE
|
||||
CFLAGS = $(CFLAGS) /MT
|
||||
!ENDIF
|
||||
|
||||
OUT_DIR = ..\$(MODE)\lib
|
||||
OUT_FILE_LIB = $(OUT_DIR)\$(NAME).lib
|
||||
|
||||
TMP_DIR = $(MODE)
|
||||
|
||||
OBJ_FILES_LIB = \
|
||||
$(TMP_DIR)\mem.obj \
|
||||
$(TMP_DIR)\str_bas.obj \
|
||||
$(TMP_DIR)\str_cnv.obj \
|
||||
$(TMP_DIR)\str_dyn.obj \
|
||||
$(TMP_DIR)\map.obj \
|
||||
$(TMP_DIR)\rex.obj \
|
||||
$(TMP_DIR)\misc.obj
|
||||
|
||||
all: lib
|
||||
|
||||
lib: $(OUT_FILE_LIB)
|
||||
|
||||
$(OUT_FILE_LIB): $(TMP_DIR) $(OUT_DIR) $(OBJ_FILES_LIB)
|
||||
$(AR) /lib @<<
|
||||
/nologo /out:$(OUT_FILE_LIB) $(OBJ_FILES_LIB)
|
||||
<<
|
||||
|
||||
$(TMP_DIR)\mem.obj: mem.c
|
||||
$(CC) $(CFLAGS) /Fo$@ /c mem.c
|
||||
|
||||
$(TMP_DIR)\str_bas.obj: str_bas.c
|
||||
$(CC) $(CFLAGS) /Fo$@ /c str_bas.c
|
||||
|
||||
$(TMP_DIR)\str_cnv.obj: str_cnv.c
|
||||
$(CC) $(CFLAGS) /Fo$@ /c str_cnv.c
|
||||
|
||||
$(TMP_DIR)\str_dyn.obj: str_dyn.c
|
||||
$(CC) $(CFLAGS) /Fo$@ /c str_dyn.c
|
||||
|
||||
$(TMP_DIR)\map.obj: map.c
|
||||
$(CC) $(CFLAGS) /Fo$@ /c map.c
|
||||
|
||||
$(TMP_DIR)\rex.obj: rex.c
|
||||
$(CC) $(CFLAGS) /Fo$@ /c rex.c
|
||||
|
||||
$(TMP_DIR)\misc.obj: misc.c
|
||||
$(CC) $(CFLAGS) /Fo$@ /c misc.c
|
||||
|
||||
$(OUT_DIR):
|
||||
-md $(OUT_DIR)
|
||||
|
||||
$(TMP_DIR):
|
||||
-md $(TMP_DIR)
|
||||
|
||||
clean:
|
||||
-del $(OUT_FILE_LIB)
|
||||
-del $(OBJ_FILES_LIB)
|
||||
|
62
qse/lib/cmn/msw-dmc.mak
Normal file
62
qse/lib/cmn/msw-dmc.mak
Normal file
@ -0,0 +1,62 @@
|
||||
#
|
||||
# You may override the value of MODE by specifying from the command-line
|
||||
# make -f msw-dmc.mak MODE=debug
|
||||
#
|
||||
|
||||
NAME = asecmn
|
||||
MODE = release
|
||||
|
||||
CC = dmc
|
||||
AR = lib
|
||||
|
||||
CFLAGS = -mn -I..\.. -DUNICODE -D_UNICODE
|
||||
|
||||
OUT_DIR = ..\$(MODE)\lib
|
||||
OUT_FILE_LIB = $(OUT_DIR)\$(NAME).lib
|
||||
|
||||
TMP_DIR = $(MODE)
|
||||
|
||||
OBJ_FILES_LIB = \
|
||||
$(TMP_DIR)\mem.obj \
|
||||
$(TMP_DIR)\str_bas.obj \
|
||||
$(TMP_DIR)\str_cnv.obj \
|
||||
$(TMP_DIR)\str_dyn.obj \
|
||||
$(TMP_DIR)\map.obj \
|
||||
$(TMP_DIR)\rex.obj \
|
||||
$(TMP_DIR)\misc.obj
|
||||
|
||||
all: $(OUT_FILE_LIB)
|
||||
|
||||
$(OUT_FILE_LIB): $(TMP_DIR) $(OUT_DIR) $(OBJ_FILES_LIB)
|
||||
$(AR) -c $(OUT_FILE_LIB) $(OBJ_FILES_LIB)
|
||||
|
||||
$(TMP_DIR)\mem.obj: mem.c
|
||||
$(CC) $(CFLAGS) -o$@ -c mem.c
|
||||
|
||||
$(TMP_DIR)\str_bas.obj: str_bas.c
|
||||
$(CC) $(CFLAGS) -o$@ -c str_bas.c
|
||||
|
||||
$(TMP_DIR)\str_cnv.obj: str_cnv.c
|
||||
$(CC) $(CFLAGS) -o$@ -c str_cnv.c
|
||||
|
||||
$(TMP_DIR)\str_dyn.obj: str_dyn.c
|
||||
$(CC) $(CFLAGS) -o$@ -c str_dyn.c
|
||||
|
||||
$(TMP_DIR)\map.obj: map.c
|
||||
$(CC) $(CFLAGS) -o$@ -c map.c
|
||||
|
||||
$(TMP_DIR)\rex.obj: rex.c
|
||||
$(CC) $(CFLAGS) -o$@ -c rex.c
|
||||
|
||||
$(TMP_DIR)\misc.obj: misc.c
|
||||
$(CC) $(CFLAGS) -o$@ -c misc.c
|
||||
|
||||
$(OUT_DIR):
|
||||
md $(OUT_DIR)
|
||||
|
||||
$(TMP_DIR):
|
||||
md $(TMP_DIR)
|
||||
|
||||
clean:
|
||||
del $(OUT_FILE_LIB) $(OBJ_FILES_LIB)
|
||||
|
193
qse/lib/cmn/opt.c
Normal file
193
qse/lib/cmn/opt.c
Normal file
@ -0,0 +1,193 @@
|
||||
/*
|
||||
* $Id: getopt.c 313 2008-08-03 14:06:43Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
|
||||
#include <ase/cmn/opt.h>
|
||||
#include <ase/cmn/str.h>
|
||||
|
||||
/*
|
||||
* ase_getopt is based on BSD getopt.
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 1987-2002 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* A. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* B. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* C. Neither the names of the copyright holders nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
|
||||
* IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS 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.
|
||||
*
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define BADCH ASE_T('?')
|
||||
#define BADARG ASE_T(':')
|
||||
#define EMSG ASE_T("")
|
||||
|
||||
ase_cint_t ase_getopt (int argc, ase_char_t* const* argv, ase_opt_t* opt)
|
||||
{
|
||||
ase_char_t* oli; /* option letter list index */
|
||||
int dbldash = 0;
|
||||
|
||||
opt->arg = ASE_NULL;
|
||||
opt->lngopt = ASE_NULL;
|
||||
|
||||
if (opt->cur == ASE_NULL)
|
||||
{
|
||||
opt->cur = EMSG;
|
||||
opt->ind = 1;
|
||||
}
|
||||
|
||||
if (*opt->cur == ASE_T('\0'))
|
||||
{
|
||||
/* update scanning pointer */
|
||||
if (opt->ind >= argc || *(opt->cur = argv[opt->ind]) != ASE_T('-'))
|
||||
{
|
||||
/* All arguments have been processed or the current
|
||||
* argument doesn't start with a dash */
|
||||
opt->cur = EMSG;
|
||||
return ASE_CHAR_EOF;
|
||||
}
|
||||
|
||||
opt->cur++;
|
||||
|
||||
#if 0
|
||||
if (*opt->cur == ASE_T('\0'))
|
||||
{
|
||||
/* - */
|
||||
opt->ind++;
|
||||
opt->cur = EMSG;
|
||||
return ASE_CHAR_EOF;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (*opt->cur == ASE_T('-'))
|
||||
{
|
||||
if (*++opt->cur == ASE_T('\0'))
|
||||
{
|
||||
/* -- */
|
||||
opt->ind++;
|
||||
opt->cur = EMSG;
|
||||
return ASE_CHAR_EOF;
|
||||
}
|
||||
else
|
||||
{
|
||||
dbldash = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (dbldash && opt->lng != ASE_NULL)
|
||||
{
|
||||
const ase_opt_lng_t* o;
|
||||
ase_char_t* end = opt->cur;
|
||||
|
||||
while (*end != ASE_T('\0') && *end != ASE_T('=')) end++;
|
||||
|
||||
for (o = opt->lng; o->str != ASE_NULL; o++)
|
||||
{
|
||||
const ase_char_t* str = o->str;
|
||||
if (*str == ASE_T(':')) str++;
|
||||
|
||||
if (ase_strxcmp (opt->cur, end-opt->cur, str) != 0) continue;
|
||||
|
||||
/* match */
|
||||
opt->cur = EMSG;
|
||||
opt->lngopt = o->str;
|
||||
if (*end == ASE_T('=')) opt->arg = end + 1;
|
||||
|
||||
if (*o->str != ASE_T(':'))
|
||||
{
|
||||
/* should not have an option argument */
|
||||
if (opt->arg != ASE_NULL) return BADARG;
|
||||
}
|
||||
else if (opt->arg == ASE_NULL)
|
||||
{
|
||||
/* Check if it has a remaining argument
|
||||
* available */
|
||||
if (argc <= ++opt->ind) return BADARG;
|
||||
/* If so, the next available argument is
|
||||
* taken to be an option argument */
|
||||
opt->arg = argv[opt->ind];
|
||||
}
|
||||
|
||||
opt->ind++;
|
||||
return o->val;
|
||||
}
|
||||
|
||||
/*if (*end == ASE_T('=')) *end = ASE_T('\0');*/
|
||||
opt->lngopt = opt->cur;
|
||||
return BADCH;
|
||||
}
|
||||
|
||||
if ((opt->opt = *opt->cur++) == ASE_T(':') ||
|
||||
(oli = ase_strchr(opt->str, opt->opt)) == ASE_NULL)
|
||||
{
|
||||
/*
|
||||
* if the user didn't specify '-' as an option,
|
||||
* assume it means EOF.
|
||||
*/
|
||||
if (opt->opt == (int)'-') return ASE_CHAR_EOF;
|
||||
if (*opt->cur == ASE_T('\0')) ++opt->ind;
|
||||
return BADCH;
|
||||
}
|
||||
|
||||
if (*++oli != ASE_T(':'))
|
||||
{
|
||||
/* don't need argument */
|
||||
if (*opt->cur == ASE_T('\0')) opt->ind++;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* need an argument */
|
||||
|
||||
if (*opt->cur != ASE_T('\0'))
|
||||
{
|
||||
/* no white space */
|
||||
opt->arg = opt->cur;
|
||||
}
|
||||
else if (argc <= ++opt->ind)
|
||||
{
|
||||
/* no arg */
|
||||
opt->cur = EMSG;
|
||||
/*if (*opt->str == ASE_T(':'))*/ return BADARG;
|
||||
/*return BADCH;*/
|
||||
}
|
||||
else
|
||||
{
|
||||
/* white space */
|
||||
opt->arg = argv[opt->ind];
|
||||
}
|
||||
|
||||
opt->cur = EMSG;
|
||||
opt->ind++;
|
||||
}
|
||||
|
||||
return opt->opt; /* dump back option letter */
|
||||
}
|
||||
|
2008
qse/lib/cmn/rex.c
Normal file
2008
qse/lib/cmn/rex.c
Normal file
File diff suppressed because it is too large
Load Diff
370
qse/lib/cmn/sio.c
Normal file
370
qse/lib/cmn/sio.c
Normal file
@ -0,0 +1,370 @@
|
||||
/*
|
||||
* $Id: sio.c,v 1.30 2006/01/15 06:51:35 bacon Ease $
|
||||
*/
|
||||
|
||||
#include <ase/cmn/sio.h>
|
||||
#include "mem.h"
|
||||
|
||||
static ase_ssize_t __sio_input (int cmd, void* arg, void* buf, ase_size_t size);
|
||||
static ase_ssize_t __sio_output (int cmd, void* arg, void* buf, ase_size_t size);
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
static ase_sio_t __sio_in =
|
||||
{
|
||||
ASE_NULL, /* mmgr */
|
||||
|
||||
/* fio */
|
||||
{
|
||||
ASE_NULL,
|
||||
#ifdef _WIN32
|
||||
(HANDLE)STD_INPUT_HANDLE,
|
||||
#else
|
||||
0,
|
||||
#endif
|
||||
},
|
||||
|
||||
/* tio */
|
||||
{
|
||||
ASE_NULL,
|
||||
0,
|
||||
|
||||
__sio_input,
|
||||
__sio_output,
|
||||
&__sio_in,
|
||||
&__sio_in,
|
||||
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
||||
{ 0 },
|
||||
{ 0 }
|
||||
}
|
||||
};
|
||||
|
||||
static ase_sio_t __sio_out =
|
||||
{
|
||||
ASE_NULL, /* mmgr */
|
||||
|
||||
/* fio */
|
||||
{
|
||||
ASE_NULL,
|
||||
#ifdef _WIN32
|
||||
(HANDLE)STD_OUTPUT_HANDLE,
|
||||
#else
|
||||
1
|
||||
#endif
|
||||
},
|
||||
|
||||
/* tio */
|
||||
{
|
||||
ASE_NULL,
|
||||
0,
|
||||
|
||||
__sio_input,
|
||||
__sio_output,
|
||||
&__sio_out,
|
||||
&__sio_out,
|
||||
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
||||
{ 0 },
|
||||
{ 0 }
|
||||
}
|
||||
};
|
||||
|
||||
static ase_sio_t __sio_err =
|
||||
{
|
||||
ASE_NULL, /* mmgr */
|
||||
|
||||
/* fio */
|
||||
{
|
||||
ASE_NULL,
|
||||
#ifdef _WIN32
|
||||
(HANDLE)STD_ERROR_HANDLE,
|
||||
#else
|
||||
2
|
||||
#endif
|
||||
},
|
||||
|
||||
/* tio */
|
||||
{
|
||||
ASE_NULL,
|
||||
0,
|
||||
|
||||
__sio_input,
|
||||
__sio_output,
|
||||
&__sio_err,
|
||||
&__sio_err,
|
||||
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
||||
{ 0 },
|
||||
{ 0 }
|
||||
}
|
||||
};
|
||||
|
||||
ase_sio_t* ase_sio_in = &__sio_in;
|
||||
ase_sio_t* ase_sio_out = &__sio_out;
|
||||
ase_sio_t* ase_sio_err = &__sio_err;
|
||||
|
||||
ase_sio_t* ase_sio_open (
|
||||
ase_mmgr_t* mmgr, ase_size_t ext, const ase_char_t* file, int flags)
|
||||
{
|
||||
ase_sio_t* sio;
|
||||
|
||||
if (mmgr == ASE_NULL)
|
||||
{
|
||||
mmgr = ASE_MMGR_GETDFL();
|
||||
|
||||
ASE_ASSERTX (mmgr != ASE_NULL,
|
||||
"Set the memory manager with ASE_MMGR_SETDFL()");
|
||||
|
||||
if (mmgr == ASE_NULL) return ASE_NULL;
|
||||
}
|
||||
|
||||
sio = ASE_MMGR_ALLOC (mmgr, ASE_SIZEOF(ase_sio_t) + ext);
|
||||
if (sio == ASE_NULL) return ASE_NULL;
|
||||
|
||||
if (ase_sio_init (sio, mmgr, file, flags) == ASE_NULL)
|
||||
{
|
||||
ASE_MMGR_FREE (mmgr, sio);
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
return sio;
|
||||
}
|
||||
|
||||
void ase_sio_close (ase_sio_t* sio)
|
||||
{
|
||||
ase_sio_fini (sio);
|
||||
ASE_MMGR_FREE (sio->mmgr, sio);
|
||||
}
|
||||
|
||||
ase_sio_t* ase_sio_init (
|
||||
ase_sio_t* sio, ase_mmgr_t* mmgr, const ase_char_t* file, int flags)
|
||||
{
|
||||
ASE_MEMSET (sio, 0, ASE_SIZEOF(*sio));
|
||||
sio->mmgr = mmgr;
|
||||
|
||||
if (ase_fio_init (&sio->fio, mmgr, file, flags, 0644) == ASE_NULL)
|
||||
{
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
if (ase_tio_init(&sio->tio, mmgr) == ASE_NULL)
|
||||
{
|
||||
ase_fio_fini (&sio->fio);
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
if (ase_tio_attachin(&sio->tio, __sio_input, sio) == -1 ||
|
||||
ase_tio_attachout(&sio->tio, __sio_output, sio) == -1)
|
||||
{
|
||||
ase_tio_fini (&sio->tio);
|
||||
ase_fio_fini (&sio->fio);
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
return sio;
|
||||
}
|
||||
|
||||
void ase_sio_fini (ase_sio_t* sio)
|
||||
{
|
||||
/*if (ase_sio_flush (sio) == -1) return -1;*/
|
||||
ase_sio_flush (sio);
|
||||
ase_tio_fini (&sio->tio);
|
||||
ase_fio_fini (&sio->fio);
|
||||
|
||||
if (sio == ase_sio_in) ase_sio_in = ASE_NULL;
|
||||
else if (sio == ase_sio_out) ase_sio_out = ASE_NULL;
|
||||
else if (sio == ase_sio_err) ase_sio_err = ASE_NULL;
|
||||
}
|
||||
|
||||
ase_sio_hnd_t ase_sio_gethandle (ase_sio_t* sio)
|
||||
{
|
||||
/*return ase_fio_gethandle (&sio->fio);*/
|
||||
return ASE_FIO_HANDLE(&sio->fio);
|
||||
}
|
||||
|
||||
ase_ssize_t ase_sio_flush (ase_sio_t* sio)
|
||||
{
|
||||
return ase_tio_flush (&sio->tio);
|
||||
}
|
||||
|
||||
void ase_sio_purge (ase_sio_t* sio)
|
||||
{
|
||||
ase_tio_purge (&sio->tio);
|
||||
}
|
||||
|
||||
ase_ssize_t ase_sio_getc (ase_sio_t* sio, ase_char_t* c)
|
||||
{
|
||||
return ase_tio_getc (&sio->tio, c);
|
||||
}
|
||||
|
||||
ase_ssize_t ase_sio_gets (ase_sio_t* sio, ase_char_t* buf, ase_size_t size)
|
||||
{
|
||||
return ase_tio_gets (&sio->tio, buf, size);
|
||||
}
|
||||
|
||||
ase_ssize_t ase_sio_getsx (ase_sio_t* sio, ase_char_t* buf, ase_size_t size)
|
||||
{
|
||||
return ase_tio_getsx (&sio->tio, buf, size);
|
||||
}
|
||||
|
||||
ase_ssize_t ase_sio_getstr (ase_sio_t* sio, ase_str_t* buf)
|
||||
{
|
||||
return ase_tio_getstr (&sio->tio, buf);
|
||||
}
|
||||
|
||||
ase_ssize_t ase_sio_putc (ase_sio_t* sio, ase_char_t c)
|
||||
{
|
||||
return ase_tio_putc (&sio->tio, c);
|
||||
}
|
||||
|
||||
ase_ssize_t ase_sio_puts (ase_sio_t* sio, const ase_char_t* str)
|
||||
{
|
||||
return ase_tio_puts (&sio->tio, str);
|
||||
}
|
||||
|
||||
ase_ssize_t ase_sio_putsx (ase_sio_t* sio, const ase_char_t* str, ase_size_t size)
|
||||
{
|
||||
return ase_tio_putsx (&sio->tio, str, size);
|
||||
}
|
||||
|
||||
#if 0
|
||||
ase_ssize_t ase_sio_putsn (ase_sio_t* sio, ...)
|
||||
{
|
||||
ase_ssize_t n;
|
||||
ase_va_list ap;
|
||||
|
||||
ase_va_start (ap, sio);
|
||||
n = ase_tio_putsv (&sio->tio, ap);
|
||||
ase_va_end (ap);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
ase_ssize_t ase_sio_putsxn (ase_sio_t* sio, ...)
|
||||
{
|
||||
ase_ssize_t n;
|
||||
ase_va_list ap;
|
||||
|
||||
ase_va_start (ap, sio);
|
||||
n = ase_tio_putsxv (&sio->tio, ap);
|
||||
ase_va_end (ap);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
ase_ssize_t ase_sio_putsv (ase_sio_t* sio, ase_va_list ap)
|
||||
{
|
||||
return ase_tio_putsv (&sio->tio, ap);
|
||||
}
|
||||
|
||||
ase_ssize_t ase_sio_putsxv (ase_sio_t* sio, ase_va_list ap)
|
||||
{
|
||||
return ase_tio_putsxv (&sio->tio, ap);
|
||||
}
|
||||
|
||||
int ase_sio_getpos (ase_sio_t* sio, ase_siopos_t* pos)
|
||||
{
|
||||
ase_off_t off;
|
||||
|
||||
off = ase_fio_seek (&sio->fio, 0, ASE_FIO_SEEK_CURRENT);
|
||||
if (off == (ase_off_t)-1) return -1;
|
||||
|
||||
*pos = off;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ase_sio_setpos (ase_sio_t* sio, ase_siopos_t pos)
|
||||
{
|
||||
if (ase_sio_flush(sio) == -1) return -1;
|
||||
return (ase_fio_seek (&sio->fio,
|
||||
pos, ASE_FIO_SEEK_BEGIN) == (ase_off_t)-1)? -1: 0;
|
||||
}
|
||||
|
||||
int ase_sio_rewind (ase_sio_t* sio)
|
||||
{
|
||||
if (ase_sio_flush(sio) == -1) return -1;
|
||||
return (ase_fio_seek (&sio->fio,
|
||||
0, ASE_FIO_SEEK_BEGIN) == (ase_off_t)-1)? -1: 0;
|
||||
}
|
||||
|
||||
int ase_sio_movetoend (ase_sio_t* sio)
|
||||
{
|
||||
if (ase_sio_flush(sio) == -1) return -1;
|
||||
return (ase_fio_seek (&sio->fio,
|
||||
0, ASE_FIO_SEEK_END) == (ase_off_t)-1)? -1: 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static ase_ssize_t __sio_input (int cmd, void* arg, void* buf, ase_size_t size)
|
||||
{
|
||||
ase_sio_t* sio = (ase_sio_t*)arg;
|
||||
|
||||
ASE_ASSERT (sio != ASE_NULL);
|
||||
|
||||
if (cmd == ASE_TIO_IO_DATA)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
/* TODO: I hate this way of adjusting the handle value
|
||||
* Is there any good ways to do it statically? */
|
||||
HANDLE h = sio->fio.handle;
|
||||
if (h == (HANDLE)STD_INPUT_HANDLE ||
|
||||
h == (HANDLE)STD_OUTPUT_HANDLE ||
|
||||
h == (HANDLE)STD_ERROR_HANDLE)
|
||||
{
|
||||
h = GetStdHandle((DWORD)h);
|
||||
if (h != INVALID_HANDLE_VALUE && h != NULL)
|
||||
{
|
||||
sio->fio.handle = h;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return ase_fio_read (&sio->fio, buf, size);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ase_ssize_t __sio_output (int cmd, void* arg, void* buf, ase_size_t size)
|
||||
{
|
||||
ase_sio_t* sio = (ase_sio_t*)arg;
|
||||
|
||||
ASE_ASSERT (sio != ASE_NULL);
|
||||
|
||||
if (cmd == ASE_TIO_IO_DATA)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
/* TODO: I hate this way of adjusting the handle value
|
||||
* Is there any good ways to do it statically? */
|
||||
HANDLE h = sio->fio.handle;
|
||||
if (h == (HANDLE)STD_INPUT_HANDLE ||
|
||||
h == (HANDLE)STD_OUTPUT_HANDLE ||
|
||||
h == (HANDLE)STD_ERROR_HANDLE)
|
||||
{
|
||||
h = GetStdHandle((DWORD)h);
|
||||
if (h != INVALID_HANDLE_VALUE && h != NULL)
|
||||
{
|
||||
sio->fio.handle = h;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return ase_fio_write (&sio->fio, buf, size);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
331
qse/lib/cmn/sll.c
Normal file
331
qse/lib/cmn/sll.c
Normal file
@ -0,0 +1,331 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
|
||||
#include <ase/cmn/sll.h>
|
||||
#include "mem.h"
|
||||
|
||||
#define sll_t ase_sll_t
|
||||
#define node_t ase_sll_node_t
|
||||
#define copier_t ase_sll_copier_t
|
||||
#define freeer_t ase_sll_freeer_t
|
||||
#define comper_t ase_sll_comper_t
|
||||
#define walker_t ase_sll_walker_t
|
||||
|
||||
#define HEAD(s) ASE_SLL_HEAD(s)
|
||||
#define TAIL(s) ASE_SLL_TAIL(s)
|
||||
#define SIZE(s) ASE_SLL_SIZE(s)
|
||||
|
||||
#define DPTR(n) ASE_SLL_DPTR(n)
|
||||
#define DLEN(n) ASE_SLL_DLEN(n)
|
||||
#define NEXT(n) ASE_SLL_NEXT(n)
|
||||
|
||||
#define TOB(sll,len) ((len)*(sll)->scale)
|
||||
|
||||
#define SIZEOF(x) ASE_SIZEOF(x)
|
||||
#define size_t ase_size_t
|
||||
#define mmgr_t ase_mmgr_t
|
||||
|
||||
static int comp_data (sll_t* sll,
|
||||
const void* dptr1, size_t dlen1,
|
||||
const void* dptr2, size_t dlen2)
|
||||
{
|
||||
if (dlen1 == dlen2) return ASE_MEMCMP (dptr1, dptr2, TOB(sll,dlen1));
|
||||
/* it just returns 1 to indicate that they are different. */
|
||||
return 1;
|
||||
}
|
||||
|
||||
static node_t* alloc_node (sll_t* sll, void* dptr, size_t dlen)
|
||||
{
|
||||
node_t* n;
|
||||
|
||||
if (sll->copier == ASE_SLL_COPIER_SIMPLE)
|
||||
{
|
||||
n = ASE_MMGR_ALLOC (sll->mmgr, SIZEOF(node_t));
|
||||
if (n == ASE_NULL) return ASE_NULL;
|
||||
DPTR(n) = dptr;
|
||||
}
|
||||
else if (sll->copier == ASE_SLL_COPIER_INLINE)
|
||||
{
|
||||
n = ASE_MMGR_ALLOC (sll->mmgr,
|
||||
SIZEOF(node_t) + TOB(sll,dlen));
|
||||
if (n == ASE_NULL) return ASE_NULL;
|
||||
|
||||
ASE_MEMCPY (n + 1, dptr, TOB(sll,dlen));
|
||||
DPTR(n) = n + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
n = ASE_MMGR_ALLOC (sll->mmgr, SIZEOF(node_t));
|
||||
if (n == ASE_NULL) return ASE_NULL;
|
||||
DPTR(n) = sll->copier (sll, dptr, dlen);
|
||||
if (DPTR(n) == ASE_NULL)
|
||||
{
|
||||
ASE_MMGR_FREE (sll->mmgr, n);
|
||||
return ASE_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
DLEN(n) = dlen;
|
||||
NEXT(n) = ASE_NULL;
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
sll_t* ase_sll_open (mmgr_t* mmgr, size_t ext)
|
||||
{
|
||||
sll_t* sll;
|
||||
|
||||
if (mmgr == ASE_NULL)
|
||||
{
|
||||
mmgr = ASE_MMGR_GETDFL();
|
||||
|
||||
ASE_ASSERTX (mmgr != ASE_NULL,
|
||||
"Set the memory manager with ASE_MMGR_SETDFL()");
|
||||
|
||||
if (mmgr == ASE_NULL) return ASE_NULL;
|
||||
}
|
||||
|
||||
sll = ASE_MMGR_ALLOC (mmgr, SIZEOF(sll_t) + ext);
|
||||
if (sll == ASE_NULL) return ASE_NULL;
|
||||
|
||||
if (ase_sll_init (sll, mmgr) == ASE_NULL)
|
||||
{
|
||||
ASE_MMGR_FREE (mmgr, sll);
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
return sll;
|
||||
}
|
||||
|
||||
void ase_sll_close (sll_t* sll)
|
||||
{
|
||||
ase_sll_fini (sll);
|
||||
ASE_MMGR_FREE (sll->mmgr, sll);
|
||||
}
|
||||
|
||||
sll_t* ase_sll_init (sll_t* sll, mmgr_t* mmgr)
|
||||
{
|
||||
/* do not zero out the extension */
|
||||
ASE_MEMSET (sll, 0, SIZEOF(*sll));
|
||||
|
||||
sll->mmgr = mmgr;
|
||||
sll->size = 0;
|
||||
sll->scale = 1;
|
||||
|
||||
sll->comper = comp_data;
|
||||
sll->copier = ASE_SLL_COPIER_SIMPLE;
|
||||
return sll;
|
||||
}
|
||||
|
||||
void ase_sll_fini (sll_t* sll)
|
||||
{
|
||||
ase_sll_clear (sll);
|
||||
}
|
||||
|
||||
void* ase_sll_getxtn (sll_t* sll)
|
||||
{
|
||||
return sll + 1;
|
||||
}
|
||||
|
||||
mmgr_t* ase_sll_getmmgr (sll_t* sll)
|
||||
{
|
||||
return sll->mmgr;
|
||||
}
|
||||
|
||||
void ase_sll_setmmgr (sll_t* sll, mmgr_t* mmgr)
|
||||
{
|
||||
sll->mmgr = mmgr;
|
||||
}
|
||||
|
||||
int ase_sll_getscale (sll_t* sll)
|
||||
{
|
||||
return sll->scale;
|
||||
}
|
||||
|
||||
void ase_sll_setscale (sll_t* sll, int scale)
|
||||
{
|
||||
ASE_ASSERTX (scale > 0 && scale <= ASE_TYPE_MAX(ase_byte_t),
|
||||
"The scale should be larger than 0 and less than or equal to the maximum value that the ase_byte_t type can hold");
|
||||
|
||||
if (scale <= 0) scale = 1;
|
||||
if (scale > ASE_TYPE_MAX(ase_byte_t)) scale = ASE_TYPE_MAX(ase_byte_t);
|
||||
|
||||
sll->scale = scale;
|
||||
}
|
||||
|
||||
copier_t ase_sll_getcopier (sll_t* sll)
|
||||
{
|
||||
return sll->copier;
|
||||
}
|
||||
|
||||
void ase_sll_setcopier (sll_t* sll, copier_t copier)
|
||||
{
|
||||
if (copier == ASE_NULL) copier = ASE_SLL_COPIER_SIMPLE;
|
||||
sll->copier = copier;
|
||||
}
|
||||
|
||||
freeer_t ase_sll_getfreeer (sll_t* sll)
|
||||
{
|
||||
return sll->freeer;
|
||||
}
|
||||
|
||||
void ase_sll_setfreeer (sll_t* sll, freeer_t freeer)
|
||||
{
|
||||
sll->freeer = freeer;
|
||||
}
|
||||
|
||||
comper_t ase_sll_getcomper (sll_t* sll)
|
||||
{
|
||||
return sll->comper;
|
||||
}
|
||||
|
||||
void ase_sll_setcomper (sll_t* sll, comper_t comper)
|
||||
{
|
||||
if (comper == ASE_NULL) comper = comp_data;
|
||||
sll->comper = comper;
|
||||
}
|
||||
|
||||
size_t ase_sll_getsize (sll_t* sll)
|
||||
{
|
||||
return SIZE(sll);
|
||||
}
|
||||
|
||||
node_t* ase_sll_gethead (sll_t* sll)
|
||||
{
|
||||
return HEAD(sll);
|
||||
}
|
||||
|
||||
node_t* ase_sll_gettail (sll_t* sll)
|
||||
{
|
||||
return TAIL(sll);
|
||||
}
|
||||
|
||||
node_t* ase_sll_search (sll_t* sll, node_t* pos, const void* dptr, size_t dlen)
|
||||
{
|
||||
pos = (pos == ASE_NULL)? pos = sll->head: NEXT(pos);
|
||||
|
||||
while (pos != ASE_NULL)
|
||||
{
|
||||
if (sll->comper (sll, DPTR(pos), DLEN(pos), dptr, dlen) == 0)
|
||||
{
|
||||
return pos;
|
||||
}
|
||||
pos = NEXT(pos);
|
||||
}
|
||||
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
node_t* ase_sll_insert (
|
||||
sll_t* sll, node_t* pos, void* dptr, size_t dlen)
|
||||
{
|
||||
node_t* n = alloc_node (sll, dptr, dlen);
|
||||
if (n == ASE_NULL) return ASE_NULL;
|
||||
|
||||
if (pos == ASE_NULL)
|
||||
{
|
||||
/* insert at the end */
|
||||
if (HEAD(sll) == ASE_NULL)
|
||||
{
|
||||
ASE_ASSERT (TAIL(sll) == ASE_NULL);
|
||||
HEAD(sll) = n;
|
||||
}
|
||||
else NEXT(TAIL(sll)) = n;
|
||||
|
||||
TAIL(sll) = n;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* insert in front of the positional node */
|
||||
NEXT(n) = pos;
|
||||
if (pos == HEAD(sll)) HEAD(sll) = n;
|
||||
else
|
||||
{
|
||||
/* take note of performance penalty */
|
||||
node_t* n2 = HEAD(sll);
|
||||
while (NEXT(n2) != pos) n2 = NEXT(n2);
|
||||
NEXT(n2) = n;
|
||||
}
|
||||
}
|
||||
|
||||
SIZE(sll)++;
|
||||
return n;
|
||||
}
|
||||
|
||||
void ase_sll_delete (sll_t* sll, node_t* pos)
|
||||
{
|
||||
if (pos == ASE_NULL) return; /* not a valid node */
|
||||
|
||||
if (pos == HEAD(sll))
|
||||
{
|
||||
/* it is simple to delete the head node */
|
||||
HEAD(sll) = NEXT(pos);
|
||||
if (HEAD(sll) == ASE_NULL) TAIL(sll) = ASE_NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* but deletion of other nodes has significant performance
|
||||
* penalty as it has look for the predecessor of the
|
||||
* target node */
|
||||
node_t* n2 = HEAD(sll);
|
||||
while (NEXT(n2) != pos) n2 = NEXT(n2);
|
||||
|
||||
NEXT(n2) = NEXT(pos);
|
||||
|
||||
/* update the tail node if necessary */
|
||||
if (pos == TAIL(sll)) TAIL(sll) = n2;
|
||||
}
|
||||
|
||||
if (sll->freeer != ASE_NULL)
|
||||
{
|
||||
/* free the actual data */
|
||||
sll->freeer (sll, DPTR(pos), DLEN(pos));
|
||||
}
|
||||
|
||||
/* free the node */
|
||||
ASE_MMGR_FREE (sll->mmgr, pos);
|
||||
|
||||
/* decrement the number of elements */
|
||||
SIZE(sll)--;
|
||||
}
|
||||
|
||||
void ase_sll_clear (sll_t* sll)
|
||||
{
|
||||
while (HEAD(sll) != ASE_NULL) ase_sll_delete (sll, HEAD(sll));
|
||||
ASE_ASSERT (TAIL(sll) == ASE_NULL);
|
||||
}
|
||||
|
||||
node_t* ase_sll_pushhead (sll_t* sll, void* data, size_t size)
|
||||
{
|
||||
return ase_sll_insert (sll, HEAD(sll), data, size);
|
||||
}
|
||||
|
||||
node_t* ase_sll_pushtail (sll_t* sll, void* data, size_t size)
|
||||
{
|
||||
return ase_sll_insert (sll, ASE_NULL, data, size);
|
||||
}
|
||||
|
||||
void ase_sll_pophead (sll_t* sll)
|
||||
{
|
||||
ase_sll_delete (sll, HEAD(sll));
|
||||
}
|
||||
|
||||
void ase_sll_poptail (sll_t* sll)
|
||||
{
|
||||
ase_sll_delete (sll, TAIL(sll));
|
||||
}
|
||||
|
||||
void ase_sll_walk (sll_t* sll, walker_t walker, void* arg)
|
||||
{
|
||||
node_t* n = HEAD(sll);
|
||||
|
||||
while (n != ASE_NULL)
|
||||
{
|
||||
if (walker(sll,n,arg) == ASE_SLL_WALK_STOP) return;
|
||||
n = NEXT(n);
|
||||
}
|
||||
}
|
||||
|
477
qse/lib/cmn/str_bas.c
Normal file
477
qse/lib/cmn/str_bas.c
Normal file
@ -0,0 +1,477 @@
|
||||
/*
|
||||
* $Id: str_bas.c 376 2008-09-24 07:18:50Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
|
||||
#include <ase/cmn/str.h>
|
||||
#include "chr.h"
|
||||
#include "mem.h"
|
||||
|
||||
ase_size_t ase_strlen (const ase_char_t* str)
|
||||
{
|
||||
const ase_char_t* p = str;
|
||||
while (*p != ASE_T('\0')) p++;
|
||||
return p - str;
|
||||
}
|
||||
|
||||
ase_size_t ase_strbytes (const ase_char_t* str)
|
||||
{
|
||||
const ase_char_t* p = str;
|
||||
while (*p != ASE_T('\0')) p++;
|
||||
return (p - str) * ASE_SIZEOF(ase_char_t);
|
||||
}
|
||||
|
||||
ase_size_t ase_strcpy (ase_char_t* buf, const ase_char_t* str)
|
||||
{
|
||||
ase_char_t* org = buf;
|
||||
while ((*buf++ = *str++) != ASE_T('\0'));
|
||||
return buf - org - 1;
|
||||
}
|
||||
|
||||
ase_size_t ase_strxcpy (
|
||||
ase_char_t* buf, ase_size_t bsz, const ase_char_t* str)
|
||||
{
|
||||
ase_char_t* p, * p2;
|
||||
|
||||
p = buf; p2 = buf + bsz - 1;
|
||||
|
||||
while (p < p2)
|
||||
{
|
||||
if (*str == ASE_T('\0')) break;
|
||||
*p++ = *str++;
|
||||
}
|
||||
|
||||
if (bsz > 0) *p = ASE_T('\0');
|
||||
return p - buf;
|
||||
}
|
||||
|
||||
ase_size_t ase_strncpy (
|
||||
ase_char_t* buf, const ase_char_t* str, ase_size_t len)
|
||||
{
|
||||
/*
|
||||
const ase_char_t* end = str + len;
|
||||
while (str < end) *buf++ = *str++;
|
||||
*buf = ASE_T('\0');
|
||||
return len;
|
||||
*/
|
||||
|
||||
if (len > 0)
|
||||
{
|
||||
ase_size_t n = (len-1) >> 3; /* (len-1) / 8 */
|
||||
|
||||
switch (len & 7) /* len % 8 */
|
||||
{
|
||||
repeat:
|
||||
case 0: *buf++ = *str++;
|
||||
case 7: *buf++ = *str++;
|
||||
case 6: *buf++ = *str++;
|
||||
case 5: *buf++ = *str++;
|
||||
case 4: *buf++ = *str++;
|
||||
case 3: *buf++ = *str++;
|
||||
case 2: *buf++ = *str++;
|
||||
case 1: *buf++ = *str++;
|
||||
if (n <= 0) break;
|
||||
n--;
|
||||
goto repeat;
|
||||
}
|
||||
}
|
||||
|
||||
*buf = ASE_T('\0');
|
||||
return len;
|
||||
}
|
||||
|
||||
ase_size_t ase_strxncpy (
|
||||
ase_char_t* buf, ase_size_t bsz, const ase_char_t* str, ase_size_t len)
|
||||
{
|
||||
ase_size_t n;
|
||||
|
||||
if (bsz <= 0) return 0;
|
||||
if ((n = bsz - 1) > len) n = len;
|
||||
ASE_MEMCPY (buf, str, n * ASE_SIZEOF(ase_char_t));
|
||||
buf[n] = ASE_T('\0');
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
ase_size_t ase_strxcat (ase_char_t* buf, ase_size_t bsz, const ase_char_t* str)
|
||||
{
|
||||
ase_char_t* p, * p2;
|
||||
ase_size_t blen;
|
||||
|
||||
blen = ase_strlen(buf);
|
||||
if (blen >= bsz) return blen; /* something wrong */
|
||||
|
||||
p = buf + blen;
|
||||
p2 = buf + bsz - 1;
|
||||
|
||||
while (p < p2)
|
||||
{
|
||||
if (*str == ASE_T('\0')) break;
|
||||
*p++ = *str++;
|
||||
}
|
||||
|
||||
if (bsz > 0) *p = ASE_T('\0');
|
||||
return p - buf;
|
||||
}
|
||||
|
||||
|
||||
ase_size_t ase_strxncat (
|
||||
ase_char_t* buf, ase_size_t bsz, const ase_char_t* str, ase_size_t len)
|
||||
{
|
||||
ase_char_t* p, * p2;
|
||||
const ase_char_t* end;
|
||||
ase_size_t blen;
|
||||
|
||||
blen = ase_strlen(buf);
|
||||
if (blen >= bsz) return blen; /* something wrong */
|
||||
|
||||
p = buf + blen;
|
||||
p2 = buf + bsz - 1;
|
||||
|
||||
end = str + len;
|
||||
|
||||
while (p < p2)
|
||||
{
|
||||
if (str >= end) break;
|
||||
*p++ = *str++;
|
||||
}
|
||||
|
||||
if (bsz > 0) *p = ASE_T('\0');
|
||||
return p - buf;
|
||||
}
|
||||
|
||||
int ase_strcmp (const ase_char_t* s1, const ase_char_t* s2)
|
||||
{
|
||||
while (*s1 == *s2)
|
||||
{
|
||||
if (*s1 == ASE_T('\0')) return 0;
|
||||
s1++, s2++;
|
||||
}
|
||||
|
||||
return (*s1 > *s2)? 1: -1;
|
||||
}
|
||||
|
||||
int ase_strxcmp (const ase_char_t* s1, ase_size_t len, const ase_char_t* s2)
|
||||
{
|
||||
const ase_char_t* end = s1 + len;
|
||||
while (s1 < end && *s2 != ASE_T('\0') && *s1 == *s2) s1++, s2++;
|
||||
if (s1 == end && *s2 == ASE_T('\0')) return 0;
|
||||
if (*s1 == *s2) return (s1 < end)? 1: -1;
|
||||
return (*s1 > *s2)? 1: -1;
|
||||
}
|
||||
|
||||
int ase_strxncmp (
|
||||
const ase_char_t* s1, ase_size_t len1,
|
||||
const ase_char_t* s2, ase_size_t len2)
|
||||
{
|
||||
ase_char_t c1, c2;
|
||||
const ase_char_t* end1 = s1 + len1;
|
||||
const ase_char_t* end2 = s2 + len2;
|
||||
|
||||
while (s1 < end1)
|
||||
{
|
||||
c1 = *s1;
|
||||
if (s2 < end2)
|
||||
{
|
||||
c2 = *s2;
|
||||
if (c1 > c2) return 1;
|
||||
if (c1 < c2) return -1;
|
||||
}
|
||||
else return 1;
|
||||
s1++; s2++;
|
||||
}
|
||||
|
||||
return (s2 < end2)? -1: 0;
|
||||
}
|
||||
|
||||
int ase_strcasecmp (
|
||||
const ase_char_t* s1, const ase_char_t* s2, ase_ccls_t* ccls)
|
||||
{
|
||||
while (ASE_CCLS_TOUPPER(ccls,*s1) == ASE_CCLS_TOUPPER(ccls,*s2))
|
||||
{
|
||||
if (*s1 == ASE_C('\0')) return 0;
|
||||
s1++, s2++;
|
||||
}
|
||||
|
||||
return (ASE_CCLS_TOUPPER(ccls,*s1) > ASE_CCLS_TOUPPER(ccls,*s2))? 1: -1;
|
||||
}
|
||||
|
||||
int ase_strxncasecmp (
|
||||
const ase_char_t* s1, ase_size_t len1,
|
||||
const ase_char_t* s2, ase_size_t len2, ase_ccls_t* ccls)
|
||||
{
|
||||
ase_char_t c1, c2;
|
||||
const ase_char_t* end1 = s1 + len1;
|
||||
const ase_char_t* end2 = s2 + len2;
|
||||
|
||||
while (s1 < end1)
|
||||
{
|
||||
c1 = ASE_CCLS_TOUPPER (ccls, *s1);
|
||||
if (s2 < end2)
|
||||
{
|
||||
c2 = ASE_CCLS_TOUPPER (ccls, *s2);
|
||||
if (c1 > c2) return 1;
|
||||
if (c1 < c2) return -1;
|
||||
}
|
||||
else return 1;
|
||||
s1++; s2++;
|
||||
}
|
||||
|
||||
return (s2 < end2)? -1: 0;
|
||||
}
|
||||
|
||||
ase_char_t* ase_strdup (const ase_char_t* str, ase_mmgr_t* mmgr)
|
||||
{
|
||||
ase_char_t* tmp;
|
||||
|
||||
tmp = (ase_char_t*) ASE_MALLOC (
|
||||
mmgr, (ase_strlen(str)+1)*ASE_SIZEOF(ase_char_t));
|
||||
if (tmp == ASE_NULL) return ASE_NULL;
|
||||
|
||||
ase_strcpy (tmp, str);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
ase_char_t* ase_strxdup (
|
||||
const ase_char_t* str, ase_size_t len, ase_mmgr_t* mmgr)
|
||||
{
|
||||
ase_char_t* tmp;
|
||||
|
||||
tmp = (ase_char_t*) ASE_MALLOC (
|
||||
mmgr, (len+1)*ASE_SIZEOF(ase_char_t));
|
||||
if (tmp == ASE_NULL) return ASE_NULL;
|
||||
|
||||
ase_strncpy (tmp, str, len);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
ase_char_t* ase_strxdup2 (
|
||||
const ase_char_t* str1, ase_size_t len1,
|
||||
const ase_char_t* str2, ase_size_t len2, ase_mmgr_t* mmgr)
|
||||
{
|
||||
ase_char_t* tmp;
|
||||
|
||||
tmp = (ase_char_t*) ASE_MALLOC (
|
||||
mmgr, (len1+len2+1) * ASE_SIZEOF(ase_char_t));
|
||||
if (tmp == ASE_NULL) return ASE_NULL;
|
||||
|
||||
ase_strncpy (tmp, str1, len1);
|
||||
ase_strncpy (tmp + len1, str2, len2);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
ase_char_t* ase_strstr (const ase_char_t* str, const ase_char_t* sub)
|
||||
{
|
||||
const ase_char_t* x, * y;
|
||||
|
||||
y = sub;
|
||||
if (*y == ASE_T('\0')) return (ase_char_t*)str;
|
||||
|
||||
while (*str != ASE_T('\0'))
|
||||
{
|
||||
if (*str != *y)
|
||||
{
|
||||
str++;
|
||||
continue;
|
||||
}
|
||||
|
||||
x = str;
|
||||
while (1)
|
||||
{
|
||||
if (*y == ASE_T('\0')) return (ase_char_t*)str;
|
||||
if (*x++ != *y++) break;
|
||||
}
|
||||
|
||||
y = sub;
|
||||
str++;
|
||||
}
|
||||
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
ase_char_t* ase_strxstr (
|
||||
const ase_char_t* str, ase_size_t size, const ase_char_t* sub)
|
||||
{
|
||||
return ase_strxnstr (str, size, sub, ase_strlen(sub));
|
||||
}
|
||||
|
||||
ase_char_t* ase_strxnstr (
|
||||
const ase_char_t* str, ase_size_t strsz,
|
||||
const ase_char_t* sub, ase_size_t subsz)
|
||||
{
|
||||
const ase_char_t* end, * subp;
|
||||
|
||||
if (subsz == 0) return (ase_char_t*)str;
|
||||
if (strsz < subsz) return ASE_NULL;
|
||||
|
||||
end = str + strsz - subsz;
|
||||
subp = sub + subsz;
|
||||
|
||||
while (str <= end)
|
||||
{
|
||||
const ase_char_t* x = str;
|
||||
const ase_char_t* y = sub;
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (y >= subp) return (ase_char_t*)str;
|
||||
if (*x != *y) break;
|
||||
x++; y++;
|
||||
}
|
||||
|
||||
str++;
|
||||
}
|
||||
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
ase_char_t* ase_strchr (const ase_char_t* str, ase_cint_t c)
|
||||
{
|
||||
while (*str != ASE_T('\0'))
|
||||
{
|
||||
if (*str == c) return (ase_char_t*)str;
|
||||
str++;
|
||||
}
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
ase_char_t* ase_strxchr (const ase_char_t* str, ase_size_t len, ase_cint_t c)
|
||||
{
|
||||
const ase_char_t* end = str + len;
|
||||
|
||||
while (str < end)
|
||||
{
|
||||
if (*str == c) return (ase_char_t*)str;
|
||||
str++;
|
||||
}
|
||||
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
ase_char_t* ase_strrchr (const ase_char_t* str, ase_cint_t c)
|
||||
{
|
||||
const ase_char_t* end = str;
|
||||
|
||||
while (*end != ASE_T('\0')) end++;
|
||||
|
||||
while (end > str)
|
||||
{
|
||||
if (*--end == c) return (ase_char_t*)end;
|
||||
}
|
||||
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
ase_char_t* ase_strxrchr (const ase_char_t* str, ase_size_t len, ase_cint_t c)
|
||||
{
|
||||
const ase_char_t* end = str + len;
|
||||
|
||||
while (end > str)
|
||||
{
|
||||
if (*--end == c) return (ase_char_t*)end;
|
||||
}
|
||||
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
ase_char_t* ase_strbeg (const ase_char_t* str, const ase_char_t* sub)
|
||||
{
|
||||
while (*sub != ASE_T('\0'))
|
||||
{
|
||||
if (*str != *sub) return ASE_NULL;
|
||||
str++; sub++;
|
||||
}
|
||||
|
||||
/* returns the pointer to the next character of the match */
|
||||
return (ase_char_t*)str;
|
||||
}
|
||||
|
||||
ase_char_t* ase_strxbeg (
|
||||
const ase_char_t* str, ase_size_t len, const ase_char_t* sub)
|
||||
{
|
||||
const ase_char_t* end = str + len;
|
||||
|
||||
while (*sub != ASE_T('\0'))
|
||||
{
|
||||
if (str >= end || *str != *sub) return ASE_NULL;
|
||||
str++; sub++;
|
||||
}
|
||||
|
||||
/* returns the pointer to the next character of the match */
|
||||
return (ase_char_t*)str;
|
||||
}
|
||||
|
||||
ase_char_t* ase_strnbeg (
|
||||
const ase_char_t* str, const ase_char_t* sub, ase_size_t len)
|
||||
{
|
||||
const ase_char_t* end = sub + len;
|
||||
|
||||
while (sub < end)
|
||||
{
|
||||
if (*str == ASE_T('\0') || *str != *sub) return ASE_NULL;
|
||||
str++; sub++;
|
||||
}
|
||||
|
||||
/* returns the pointer to the next character of the match */
|
||||
return (ase_char_t*)str;
|
||||
}
|
||||
|
||||
ase_char_t* ase_strxnbeg (
|
||||
const ase_char_t* str, ase_size_t len1,
|
||||
const ase_char_t* sub, ase_size_t len2)
|
||||
{
|
||||
const ase_char_t* end1, * end2;
|
||||
|
||||
if (len2 > len1) return ASE_NULL;
|
||||
|
||||
end1 = str + len1;
|
||||
end2 = sub + len2;
|
||||
|
||||
while (sub < end2)
|
||||
{
|
||||
if (str >= end1 || *str != *sub) return ASE_NULL;
|
||||
str++; sub++;
|
||||
}
|
||||
|
||||
/* returns the pointer to the next character of the match */
|
||||
return (ase_char_t*)str;
|
||||
}
|
||||
|
||||
ase_char_t* ase_strend (const ase_char_t* str, const ase_char_t* sub)
|
||||
{
|
||||
return ase_strxnend (str, ase_strlen(str), sub, ase_strlen(sub));
|
||||
}
|
||||
|
||||
ase_char_t* ase_strxend (
|
||||
const ase_char_t* str, ase_size_t len, const ase_char_t* sub)
|
||||
{
|
||||
return ase_strxnend (str, len, sub, ase_strlen(sub));
|
||||
}
|
||||
|
||||
ase_char_t* ase_strnend (
|
||||
const ase_char_t* str, const ase_char_t* sub, ase_size_t len)
|
||||
{
|
||||
return ase_strxnend (str, ase_strlen(str), sub, len);
|
||||
}
|
||||
|
||||
ase_char_t* ase_strxnend (
|
||||
const ase_char_t* str, ase_size_t len1,
|
||||
const ase_char_t* sub, ase_size_t len2)
|
||||
{
|
||||
const ase_char_t* end1, * end2;
|
||||
|
||||
if (len2 > len1) return ASE_NULL;
|
||||
|
||||
end1 = str + len1;
|
||||
end2 = sub + len2;
|
||||
|
||||
while (end2 > sub)
|
||||
{
|
||||
if (end1 <= str) return ASE_NULL;
|
||||
if (*(--end1) != *(--end2)) return ASE_NULL;
|
||||
}
|
||||
|
||||
/* returns the pointer to the match start */
|
||||
return (ase_char_t*)end1;
|
||||
}
|
256
qse/lib/cmn/str_cnv.c
Normal file
256
qse/lib/cmn/str_cnv.c
Normal file
@ -0,0 +1,256 @@
|
||||
/*
|
||||
* $Id: str_cnv.c 455 2008-11-26 09:05:00Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
|
||||
#include <ase/cmn/str.h>
|
||||
|
||||
int ase_strtoi (const ase_char_t* str)
|
||||
{
|
||||
int v;
|
||||
ASE_STRTONUM (v, str, ASE_NULL, 10);
|
||||
return v;
|
||||
}
|
||||
|
||||
long ase_strtol (const ase_char_t* str)
|
||||
{
|
||||
long v;
|
||||
ASE_STRTONUM (v, str, ASE_NULL, 10);
|
||||
return v;
|
||||
}
|
||||
|
||||
unsigned int ase_strtoui (const ase_char_t* str)
|
||||
{
|
||||
unsigned int v;
|
||||
ASE_STRTONUM (v, str, ASE_NULL, 10);
|
||||
return v;
|
||||
}
|
||||
|
||||
unsigned long ase_strtoul (const ase_char_t* str)
|
||||
{
|
||||
unsigned long v;
|
||||
ASE_STRTONUM (v, str, ASE_NULL, 10);
|
||||
return v;
|
||||
}
|
||||
|
||||
int ase_strxtoi (const ase_char_t* str, ase_size_t len)
|
||||
{
|
||||
int v;
|
||||
ASE_STRXTONUM (v, str, len, ASE_NULL, 10);
|
||||
return v;
|
||||
}
|
||||
|
||||
long ase_strxtol (const ase_char_t* str, ase_size_t len)
|
||||
{
|
||||
long v;
|
||||
ASE_STRXTONUM (v, str, len, ASE_NULL, 10);
|
||||
return v;
|
||||
}
|
||||
|
||||
unsigned int ase_strxtoui (const ase_char_t* str, ase_size_t len)
|
||||
{
|
||||
unsigned int v;
|
||||
ASE_STRXTONUM (v, str, len, ASE_NULL, 10);
|
||||
return v;
|
||||
}
|
||||
|
||||
unsigned long ase_strxtoul (const ase_char_t* str, ase_size_t len)
|
||||
{
|
||||
unsigned long v;
|
||||
ASE_STRXTONUM (v, str, len, ASE_NULL, 10);
|
||||
return v;
|
||||
}
|
||||
|
||||
ase_int_t ase_strtoint (const ase_char_t* str)
|
||||
{
|
||||
ase_int_t v;
|
||||
ASE_STRTONUM (v, str, ASE_NULL, 10);
|
||||
return v;
|
||||
}
|
||||
|
||||
ase_long_t ase_strtolong (const ase_char_t* str)
|
||||
{
|
||||
ase_long_t v;
|
||||
ASE_STRTONUM (v, str, ASE_NULL, 10);
|
||||
return v;
|
||||
}
|
||||
|
||||
ase_uint_t ase_strtouint (const ase_char_t* str)
|
||||
{
|
||||
ase_uint_t v;
|
||||
ASE_STRTONUM (v, str, ASE_NULL, 10);
|
||||
return v;
|
||||
}
|
||||
|
||||
ase_ulong_t ase_strtoulong (const ase_char_t* str)
|
||||
{
|
||||
ase_ulong_t v;
|
||||
ASE_STRTONUM (v, str, ASE_NULL, 10);
|
||||
return v;
|
||||
}
|
||||
|
||||
ase_int_t ase_strxtoint (const ase_char_t* str, ase_size_t len)
|
||||
{
|
||||
ase_int_t v;
|
||||
ASE_STRXTONUM (v, str, len, ASE_NULL, 10);
|
||||
return v;
|
||||
}
|
||||
|
||||
ase_long_t ase_strxtolong (const ase_char_t* str, ase_size_t len)
|
||||
{
|
||||
ase_long_t v;
|
||||
ASE_STRXTONUM (v, str, len, ASE_NULL, 10);
|
||||
return v;
|
||||
}
|
||||
|
||||
ase_uint_t ase_strxtouint (const ase_char_t* str, ase_size_t len)
|
||||
{
|
||||
ase_uint_t v;
|
||||
ASE_STRXTONUM (v, str, len, ASE_NULL, 10);
|
||||
return v;
|
||||
}
|
||||
|
||||
ase_ulong_t ase_strxtoulong (const ase_char_t* str, ase_size_t len)
|
||||
{
|
||||
ase_ulong_t v;
|
||||
ASE_STRXTONUM (v, str, len, ASE_NULL, 10);
|
||||
return v;
|
||||
}
|
||||
|
||||
ase_size_t ase_mbstowcs (
|
||||
const ase_mchar_t* mbs, ase_wchar_t* wcs, ase_size_t* wcslen)
|
||||
{
|
||||
ase_size_t wlen, mlen;
|
||||
const ase_mchar_t* mp;
|
||||
|
||||
/* get the length of mbs and pass it to ase_mbsntowcsn as
|
||||
* ase_mbtowc called by ase_mbsntowcsn needs it. */
|
||||
for (mp = mbs; *mp != '\0'; mp++);
|
||||
|
||||
if (*wcslen <= 0)
|
||||
{
|
||||
/* buffer too small. cannot null-terminate it */
|
||||
return 0;
|
||||
}
|
||||
if (*wcslen == 1)
|
||||
{
|
||||
wcs[0] = L'\0';
|
||||
return 0;
|
||||
}
|
||||
|
||||
wlen = *wcslen - 1;
|
||||
mlen = ase_mbsntowcsn (mbs, mp - mbs, wcs, &wlen);
|
||||
|
||||
wcs[wlen] = L'\0';
|
||||
*wcslen = wlen;
|
||||
|
||||
return mlen;
|
||||
}
|
||||
|
||||
ase_size_t ase_mbsntowcsn (
|
||||
const ase_mchar_t* mbs, ase_size_t mbslen,
|
||||
ase_wchar_t* wcs, ase_size_t* wcslen)
|
||||
{
|
||||
ase_size_t mlen = mbslen, n;
|
||||
const ase_mchar_t* p;
|
||||
ase_wchar_t* q, * qend ;
|
||||
|
||||
qend = wcs + *wcslen;
|
||||
|
||||
for (p = mbs, q = wcs; mlen > 0 && q < qend; p += n, mlen -= n)
|
||||
{
|
||||
n = ase_mbtowc (p, mlen, q);
|
||||
if (n == 0 || n > mlen)
|
||||
{
|
||||
/* wrong sequence or insufficient input */
|
||||
break;
|
||||
}
|
||||
|
||||
q++;
|
||||
}
|
||||
|
||||
*wcslen = q - wcs;
|
||||
return p - mbs; /* returns the number of bytes processed */
|
||||
}
|
||||
|
||||
ase_size_t ase_wcstombs (
|
||||
const ase_wchar_t* wcs, ase_mchar_t* mbs, ase_size_t* mbslen)
|
||||
{
|
||||
const ase_wchar_t* p = wcs;
|
||||
ase_size_t rem = *mbslen;
|
||||
|
||||
while (*p != ASE_WT('\0') && rem > 1)
|
||||
{
|
||||
ase_size_t n = ase_wctomb (*p, mbs, rem);
|
||||
if (n == 0 || n > rem)
|
||||
{
|
||||
/* illegal character or buffer not enough */
|
||||
break;
|
||||
}
|
||||
|
||||
if (rem == n)
|
||||
{
|
||||
/* the buffer is full without the space for a
|
||||
* terminating null. should stop processing further
|
||||
* excluding this last character emitted. */
|
||||
break;
|
||||
}
|
||||
|
||||
mbs += n; rem -= n; p++;
|
||||
}
|
||||
|
||||
*mbslen -= rem;
|
||||
|
||||
/* null-terminate the multibyte sequence if it has sufficient space */
|
||||
if (rem > 0) *mbs = '\0';
|
||||
|
||||
/* returns the number of characters handled. */
|
||||
return p - wcs;
|
||||
}
|
||||
|
||||
ase_size_t ase_wcsntombsn (
|
||||
const ase_wchar_t* wcs, ase_size_t wcslen,
|
||||
ase_mchar_t* mbs, ase_size_t* mbslen)
|
||||
{
|
||||
const ase_wchar_t* p = wcs;
|
||||
const ase_wchar_t* end = wcs + wcslen;
|
||||
ase_size_t len = *mbslen;
|
||||
|
||||
while (p < end && len > 0)
|
||||
{
|
||||
ase_size_t n = ase_wctomb (*p, mbs, len);
|
||||
if (n == 0 || n > len)
|
||||
{
|
||||
/* illegal character or buffer not enough */
|
||||
break;
|
||||
}
|
||||
mbs += n; len -= n; p++;
|
||||
}
|
||||
|
||||
*mbslen -= len;
|
||||
|
||||
/* returns the number of characters handled.
|
||||
* the caller can check if the return value is as large is wcslen
|
||||
* for an error. */
|
||||
return p - wcs;
|
||||
}
|
||||
|
||||
int ase_wcstombs_strict (
|
||||
const ase_wchar_t* wcs, ase_mchar_t* mbs, ase_size_t mbslen)
|
||||
{
|
||||
ase_size_t n;
|
||||
ase_size_t mn = mbslen;
|
||||
|
||||
n = ase_wcstombs (wcs, mbs, &mn);
|
||||
if (wcs[n] != ASE_WT('\0')) return -1; /* didn't process all */
|
||||
if (mn >= mbslen)
|
||||
{
|
||||
/* mbs not big enough to be null-terminated.
|
||||
* if it has been null-terminated properly,
|
||||
* mn should be less than mbslen. */
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
286
qse/lib/cmn/str_dyn.c
Normal file
286
qse/lib/cmn/str_dyn.c
Normal file
@ -0,0 +1,286 @@
|
||||
/*
|
||||
* $Id: str_dyn.c 496 2008-12-15 09:56:48Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
|
||||
#include <ase/cmn/str.h>
|
||||
#include "mem.h"
|
||||
|
||||
ase_str_t* ase_str_open (ase_mmgr_t* mmgr, ase_size_t ext, ase_size_t capa)
|
||||
{
|
||||
ase_str_t* str;
|
||||
|
||||
if (mmgr == ASE_NULL)
|
||||
{
|
||||
mmgr = ASE_MMGR_GETDFL();
|
||||
|
||||
ASE_ASSERTX (mmgr != ASE_NULL,
|
||||
"Set the memory manager with ASE_MMGR_SETDFL()");
|
||||
|
||||
if (mmgr == ASE_NULL) return ASE_NULL;
|
||||
}
|
||||
|
||||
str = (ase_str_t*) ASE_MMGR_ALLOC (mmgr, ASE_SIZEOF(ase_str_t) + ext);
|
||||
if (str == ASE_NULL) return ASE_NULL;
|
||||
|
||||
if (ase_str_init (str, mmgr, capa) == ASE_NULL)
|
||||
{
|
||||
ASE_MMGR_FREE (mmgr, str);
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
void ase_str_close (ase_str_t* str)
|
||||
{
|
||||
ase_str_fini (str);
|
||||
ASE_MMGR_FREE (str->mmgr, str);
|
||||
}
|
||||
|
||||
ase_str_t* ase_str_init (ase_str_t* str, ase_mmgr_t* mmgr, ase_size_t capa)
|
||||
{
|
||||
ASE_MEMSET (str, 0, ASE_SIZEOF(ase_str_t));
|
||||
|
||||
str->mmgr = mmgr;
|
||||
str->sizer = ASE_NULL;
|
||||
|
||||
if (capa == 0) str->ptr = ASE_NULL;
|
||||
else
|
||||
{
|
||||
str->ptr = (ase_char_t*) ASE_MMGR_ALLOC (
|
||||
mmgr, ASE_SIZEOF(ase_char_t) * (capa + 1));
|
||||
if (str->ptr == ASE_NULL) return ASE_NULL;
|
||||
str->ptr[0] = ASE_T('\0');
|
||||
}
|
||||
|
||||
str->len = 0;
|
||||
str->capa = capa;
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
void ase_str_fini (ase_str_t* str)
|
||||
{
|
||||
if (str->ptr != ASE_NULL) ASE_MMGR_FREE (str->mmgr, str->ptr);
|
||||
}
|
||||
|
||||
int ase_str_yield (ase_str_t* str, ase_xstr_t* buf, int new_capa)
|
||||
{
|
||||
ase_char_t* tmp;
|
||||
|
||||
if (new_capa == 0) tmp = ASE_NULL;
|
||||
else
|
||||
{
|
||||
tmp = (ase_char_t*) ASE_MMGR_ALLOC (
|
||||
str->mmgr, ASE_SIZEOF(ase_char_t) * (new_capa + 1));
|
||||
if (tmp == ASE_NULL) return -1;
|
||||
tmp[0] = ASE_T('\0');
|
||||
}
|
||||
|
||||
if (buf != ASE_NULL)
|
||||
{
|
||||
buf->ptr = str->ptr;
|
||||
buf->len = str->len;
|
||||
}
|
||||
|
||||
str->ptr = tmp;
|
||||
str->len = 0;
|
||||
str->capa = new_capa;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* ase_str_getxtn (ase_str_t* str)
|
||||
{
|
||||
return str + 1;
|
||||
}
|
||||
|
||||
ase_mmgr_t* ase_str_getmmgr (ase_str_t* str)
|
||||
{
|
||||
return str->mmgr;
|
||||
}
|
||||
|
||||
void ase_str_setmmgr (ase_str_t* str, ase_mmgr_t* mmgr)
|
||||
{
|
||||
str->mmgr = mmgr;
|
||||
}
|
||||
|
||||
ase_str_sizer_t ase_str_getsizer (ase_str_t* str)
|
||||
{
|
||||
return str->sizer;
|
||||
}
|
||||
|
||||
void ase_str_setsizer (ase_str_t* str, ase_str_sizer_t sizer)
|
||||
{
|
||||
str->sizer = sizer;
|
||||
}
|
||||
|
||||
ase_size_t ase_str_getcapa (ase_str_t* str)
|
||||
{
|
||||
return str->capa;
|
||||
}
|
||||
|
||||
ase_size_t ase_str_setcapa (ase_str_t* str, ase_size_t capa)
|
||||
{
|
||||
ase_char_t* tmp;
|
||||
|
||||
if (str->mmgr->realloc != ASE_NULL && str->ptr != ASE_NULL)
|
||||
{
|
||||
tmp = (ase_char_t*) ASE_MMGR_REALLOC (
|
||||
str->mmgr, str->ptr,
|
||||
ASE_SIZEOF(ase_char_t)*(capa+1));
|
||||
if (tmp == ASE_NULL) return (ase_size_t)-1;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = (ase_char_t*) ASE_MMGR_ALLOC (
|
||||
str->mmgr, ASE_SIZEOF(ase_char_t)*(capa+1));
|
||||
if (tmp == ASE_NULL) return (ase_size_t)-1;
|
||||
|
||||
if (str->ptr != ASE_NULL)
|
||||
{
|
||||
ase_size_t ncopy = (str->len <= capa)? str->len: capa;
|
||||
ASE_MEMCPY (tmp, str->ptr,
|
||||
ASE_SIZEOF(ase_char_t)*(ncopy+1));
|
||||
ASE_MMGR_FREE (str->mmgr, str->ptr);
|
||||
}
|
||||
}
|
||||
|
||||
if (capa < str->len)
|
||||
{
|
||||
str->len = capa;
|
||||
tmp[capa] = ASE_T('\0');
|
||||
}
|
||||
|
||||
str->capa = capa;
|
||||
str->ptr = tmp;
|
||||
|
||||
return str->capa;
|
||||
}
|
||||
|
||||
void ase_str_clear (ase_str_t* str)
|
||||
{
|
||||
str->len = 0;
|
||||
str->ptr[0] = ASE_T('\0');
|
||||
}
|
||||
|
||||
void ase_str_swap (ase_str_t* str, ase_str_t* str1)
|
||||
{
|
||||
ase_str_t tmp;
|
||||
|
||||
tmp.ptr = str->ptr;
|
||||
tmp.len = str->len;
|
||||
tmp.capa = str->capa;
|
||||
tmp.mmgr = str->mmgr;
|
||||
|
||||
str->ptr = str1->ptr;
|
||||
str->len = str1->len;
|
||||
str->capa = str1->capa;
|
||||
str->mmgr = str1->mmgr;
|
||||
|
||||
str1->ptr = tmp.ptr;
|
||||
str1->len = tmp.len;
|
||||
str1->capa = tmp.capa;
|
||||
str1->mmgr = tmp.mmgr;
|
||||
}
|
||||
|
||||
ase_size_t ase_str_cpy (ase_str_t* str, const ase_char_t* s)
|
||||
{
|
||||
/* TODO: improve it */
|
||||
return ase_str_ncpy (str, s, ase_strlen(s));
|
||||
}
|
||||
|
||||
ase_size_t ase_str_ncpy (ase_str_t* str, const ase_char_t* s, ase_size_t len)
|
||||
{
|
||||
ase_char_t* buf;
|
||||
|
||||
if (len > str->capa || str->ptr == ASE_NULL)
|
||||
{
|
||||
buf = (ase_char_t*) ASE_MMGR_ALLOC (
|
||||
str->mmgr, ASE_SIZEOF(ase_char_t) * (len + 1));
|
||||
if (buf == ASE_NULL) return (ase_size_t)-1;
|
||||
|
||||
if (str->ptr != ASE_NULL) ASE_MMGR_FREE (str->mmgr, str->ptr);
|
||||
str->capa = len;
|
||||
str->ptr = buf;
|
||||
}
|
||||
|
||||
str->len = ase_strncpy (str->ptr, s, len);
|
||||
str->ptr[str->len] = ASE_T('\0');
|
||||
return str->len;
|
||||
}
|
||||
|
||||
ase_size_t ase_str_cat (ase_str_t* str, const ase_char_t* s)
|
||||
{
|
||||
/* TODO: improve it */
|
||||
return ase_str_ncat (str, s, ase_strlen(s));
|
||||
}
|
||||
|
||||
|
||||
ase_size_t ase_str_ncat (ase_str_t* str, const ase_char_t* s, ase_size_t len)
|
||||
{
|
||||
if (len > str->capa - str->len)
|
||||
{
|
||||
ase_size_t ncapa;
|
||||
|
||||
if (str->sizer == ASE_NULL)
|
||||
{
|
||||
/* increase the capacity by the length to add */
|
||||
ncapa = str->len + len;
|
||||
/* if the new capacity is less than the double,
|
||||
* just double it */
|
||||
if (ncapa < str->capa * 2) ncapa = str->capa * 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* let the user determine the new capacity.
|
||||
* pass the minimum capacity required as a hint */
|
||||
ncapa = str->sizer (str, str->len + len);
|
||||
/* if no change in capacity, return current length */
|
||||
if (ncapa == str->capa) return str->len;
|
||||
}
|
||||
|
||||
if (ase_str_setcapa (str, ncapa) == (ase_size_t)-1)
|
||||
{
|
||||
return (ase_size_t)-1;
|
||||
}
|
||||
}
|
||||
|
||||
if (len > str->capa - str->len)
|
||||
{
|
||||
/* copy as many characters as the number of cells available.
|
||||
* if the capacity has been decreased, len is adjusted here */
|
||||
len = str->capa - str->len;
|
||||
}
|
||||
|
||||
if (len > 0)
|
||||
{
|
||||
ASE_MEMCPY (&str->ptr[str->len], s, len*ASE_SIZEOF(*s));
|
||||
str->len += len;
|
||||
str->ptr[str->len] = ASE_T('\0');
|
||||
}
|
||||
|
||||
return str->len;
|
||||
}
|
||||
|
||||
ase_size_t ase_str_ccat (ase_str_t* str, ase_char_t c)
|
||||
{
|
||||
return ase_str_ncat (str, &c, 1);
|
||||
}
|
||||
|
||||
ase_size_t ase_str_nccat (ase_str_t* str, ase_char_t c, ase_size_t len)
|
||||
{
|
||||
while (len > 0)
|
||||
{
|
||||
if (ase_str_ncat (str, &c, 1) == (ase_size_t)-1)
|
||||
{
|
||||
return (ase_size_t)-1;
|
||||
}
|
||||
|
||||
len--;
|
||||
}
|
||||
return str->len;
|
||||
}
|
||||
|
147
qse/lib/cmn/time.c
Normal file
147
qse/lib/cmn/time.c
Normal file
@ -0,0 +1,147 @@
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <ase/cmn/time.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
#if defined(ASE_USE_SYSCALL) && defined(HAVE_SYS_SYSCALL_H)
|
||||
#include <sys/syscall.h>
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#define WIN_EPOCH_YEAR ((ase_ntime_t)1601)
|
||||
#define WIN_EPOCH_MON ((ase_ntime_t)1)
|
||||
#define WIN_EPOCH_DAY ((ase_ntime_t)1)
|
||||
|
||||
#define EPOCH_DIFF_YEARS (ASE_EPOCH_YEAR-WIN_EPOCH_YEAR)
|
||||
#define EPOCH_DIFF_DAYS (EPOCH_DIFF_YEARS*365+EPOCH_DIFF_YEARS/4-3)
|
||||
#define EPOCH_DIFF_SECS (EPOCH_DIFF_DAYS*24*60*60)
|
||||
#define EPOCH_DIFF_MSECS (EPOCH_DIFF_SECS*ASE_MSEC_IN_SEC)
|
||||
#endif
|
||||
|
||||
static int mdays[2][ASE_MON_IN_YEAR] =
|
||||
{
|
||||
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
|
||||
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
|
||||
};
|
||||
|
||||
int ase_gettime (ase_ntime_t* t)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
SYSTEMTIME st;
|
||||
FILETIME ft;
|
||||
|
||||
/*
|
||||
* MSDN: The FILETIME structure is a 64-bit value representing the
|
||||
* number of 100-nanosecond intervals since January 1, 1601 (UTC).
|
||||
*/
|
||||
|
||||
GetSystemTime (&st);
|
||||
if (SystemTimeToFileTime (&st, &ft) == FALSE) return -1;
|
||||
*t = ((ase_ntime_t)(*((ase_int64_t*)&ft)) / (10 * 1000));
|
||||
*t -= EPOCH_DIFF_MSECS;
|
||||
return 0;
|
||||
#else
|
||||
struct timeval tv;
|
||||
int n;
|
||||
|
||||
#ifdef SYS_gettimeofday
|
||||
n = syscall (SYS_gettimeofday, &tv, ASE_NULL);
|
||||
#else
|
||||
n = gettimeofday (&tv, ASE_NULL);
|
||||
#endif
|
||||
if (n == -1) return -1;
|
||||
|
||||
*t = tv.tv_sec * ASE_MSEC_IN_SEC + tv.tv_usec / ASE_USEC_IN_MSEC;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int ase_settime (ase_ntime_t t)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
FILETIME ft;
|
||||
SYSTEMTIME st;
|
||||
|
||||
*((ase_int64_t*)&ft) = ((t + EPOCH_DIFF_MSECS) * (10 * 1000));
|
||||
if (FileTimeToSystemTime (&ft, &st) == FALSE) return -1;
|
||||
if (SetSystemTime(&st) == FALSE) return -1;
|
||||
return 0;
|
||||
#else
|
||||
struct timeval tv;
|
||||
int n;
|
||||
|
||||
tv.tv_sec = t / ASE_MSEC_IN_SEC;
|
||||
tv.tv_usec = (t % ASE_MSEC_IN_SEC) * ASE_USEC_IN_MSEC;
|
||||
|
||||
/*
|
||||
#if defined CLOCK_REALTIME && HAVE_CLOCK_SETTIME
|
||||
{
|
||||
int r = clock_settime (CLOCK_REALTIME, ts);
|
||||
if (r == 0 || errno == EPERM)
|
||||
return r;
|
||||
}
|
||||
#elif HAVE_STIME
|
||||
/* This fails to compile on OSF1 V5.1, due to stime requiring
|
||||
a `long int*' and tv_sec is `int'. But that system does provide
|
||||
settimeofday. */
|
||||
return stime (&ts->tv_sec);
|
||||
#else
|
||||
*/
|
||||
|
||||
#ifdef SYS_settimeofday
|
||||
n = syscall (SYS_settimeofday, &tv, ASE_NULL);
|
||||
#else
|
||||
n = settimeofday (&tv, ASE_NULL);
|
||||
#endif
|
||||
if (n == -1) return -1;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void ase_gmtime (ase_ntime_t nt, ase_btime_t* bt)
|
||||
{
|
||||
/* code based on minix 2.0 src/lib/ansi/gmtime.c */
|
||||
|
||||
ase_ntime_t days; /* total days */
|
||||
ase_ntime_t secs; /* number of seconds in the fractional days */
|
||||
ase_ntime_t time; /* total seconds */
|
||||
|
||||
int year = ASE_EPOCH_YEAR;
|
||||
|
||||
time = nt / ASE_MSEC_IN_SEC;
|
||||
days = (unsigned long)time / ASE_SEC_IN_DAY;
|
||||
secs = (unsigned long)time % ASE_SEC_IN_DAY;
|
||||
|
||||
bt->sec = secs % ASE_SEC_IN_MIN;
|
||||
bt->min = (secs % ASE_SEC_IN_HOUR) / ASE_SEC_IN_MIN;
|
||||
bt->hour = secs / ASE_SEC_IN_HOUR;
|
||||
|
||||
bt->wday = (days + 4) % ASE_DAY_IN_WEEK;
|
||||
|
||||
while (days >= ASE_DAY_IN_YEAR(year))
|
||||
{
|
||||
days -= ASE_DAY_IN_YEAR(year);
|
||||
year++;
|
||||
}
|
||||
|
||||
bt->year = year - 1900;
|
||||
bt->yday = days;
|
||||
bt->mon = 0;
|
||||
|
||||
while (days >= mdays[ASE_IS_LEAPYEAR(year)][bt->mon])
|
||||
{
|
||||
days -= mdays[ASE_IS_LEAPYEAR(year)][bt->mon];
|
||||
bt->mon++;
|
||||
}
|
||||
|
||||
bt->mday = days + 1;
|
||||
bt->isdst = 0;
|
||||
}
|
239
qse/lib/cmn/tio.c
Normal file
239
qse/lib/cmn/tio.c
Normal file
@ -0,0 +1,239 @@
|
||||
/*
|
||||
* $Id: tio.c,v 1.13 2006/01/01 13:50:24 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <ase/cmn/tio.h>
|
||||
#include "mem.h"
|
||||
|
||||
ase_tio_t* ase_tio_open (ase_mmgr_t* mmgr, ase_size_t ext)
|
||||
{
|
||||
ase_tio_t* tio;
|
||||
|
||||
if (mmgr == ASE_NULL)
|
||||
{
|
||||
mmgr = ASE_MMGR_GETDFL();
|
||||
|
||||
ASE_ASSERTX (mmgr != ASE_NULL,
|
||||
"Set the memory manager with ASE_MMGR_SETDFL()");
|
||||
|
||||
if (mmgr == ASE_NULL) return ASE_NULL;
|
||||
}
|
||||
|
||||
tio = ASE_MMGR_ALLOC (mmgr, ASE_SIZEOF(ase_tio_t) + ext);
|
||||
if (tio == ASE_NULL) return ASE_NULL;
|
||||
|
||||
if (ase_tio_init (tio, mmgr) == ASE_NULL)
|
||||
{
|
||||
ASE_MMGR_FREE (mmgr, tio);
|
||||
return ASE_NULL;
|
||||
}
|
||||
|
||||
return tio;
|
||||
}
|
||||
|
||||
int ase_tio_close (ase_tio_t* tio)
|
||||
{
|
||||
int n = ase_tio_fini (tio);
|
||||
ASE_MMGR_FREE (tio->mmgr, tio);
|
||||
return n;
|
||||
}
|
||||
|
||||
ase_tio_t* ase_tio_init (ase_tio_t* tio, ase_mmgr_t* mmgr)
|
||||
{
|
||||
ASE_MEMSET (tio, 0, ASE_SIZEOF(*tio));
|
||||
|
||||
tio->mmgr = mmgr;
|
||||
|
||||
/*
|
||||
tio->input_func = ASE_NULL;
|
||||
tio->input_arg = ASE_NULL;
|
||||
tio->output_func = ASE_NULL;
|
||||
tio->output_arg = ASE_NULL;
|
||||
|
||||
tio->input_status = 0;
|
||||
tio->inbuf_curp = 0;
|
||||
tio->inbuf_len = 0;
|
||||
tio->outbuf_len = 0;
|
||||
*/
|
||||
|
||||
tio->errnum = ASE_TIO_ENOERR;
|
||||
|
||||
return tio;
|
||||
}
|
||||
|
||||
int ase_tio_fini (ase_tio_t* tio)
|
||||
{
|
||||
ase_tio_flush (tio); /* don't care about the result */
|
||||
if (ase_tio_detachin(tio) == -1) return -1;
|
||||
if (ase_tio_detachout(tio) == -1) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* ase_tio_getxtn (ase_tio_t* tio)
|
||||
{
|
||||
return tio + 1;
|
||||
}
|
||||
|
||||
ase_mmgr_t* ase_tio_getmmgr (ase_tio_t* tio)
|
||||
{
|
||||
return tio->mmgr;
|
||||
}
|
||||
|
||||
void ase_tio_setmmgr (ase_tio_t* tio, ase_mmgr_t* mmgr)
|
||||
{
|
||||
tio->mmgr = mmgr;
|
||||
}
|
||||
|
||||
int ase_tio_geterrnum (ase_tio_t* tio)
|
||||
{
|
||||
return tio->errnum;
|
||||
}
|
||||
|
||||
const ase_char_t* ase_tio_geterrstr (ase_tio_t* tio)
|
||||
{
|
||||
static const ase_char_t* __errstr[] =
|
||||
{
|
||||
ASE_T("no error"),
|
||||
ASE_T("out of memory"),
|
||||
ASE_T("no more space"),
|
||||
ASE_T("illegal multibyte sequence"),
|
||||
ASE_T("incomplete multibyte sequence"),
|
||||
ASE_T("illegal wide character"),
|
||||
ASE_T("no input function attached"),
|
||||
ASE_T("input function returned an error"),
|
||||
ASE_T("input function failed to open"),
|
||||
ASE_T("input function failed to closed"),
|
||||
ASE_T("no output function attached"),
|
||||
ASE_T("output function returned an error"),
|
||||
ASE_T("output function failed to open"),
|
||||
ASE_T("output function failed to closed"),
|
||||
ASE_T("unknown error")
|
||||
};
|
||||
|
||||
return __errstr[
|
||||
(tio->errnum < 0 || tio->errnum >= ASE_COUNTOF(__errstr))?
|
||||
ASE_COUNTOF(__errstr) - 1: tio->errnum];
|
||||
}
|
||||
|
||||
int ase_tio_attachin (ase_tio_t* tio, ase_tio_io_t input, void* arg)
|
||||
{
|
||||
if (ase_tio_detachin(tio) == -1) return -1;
|
||||
|
||||
ASE_ASSERT (tio->input_func == ASE_NULL);
|
||||
|
||||
if (input(ASE_TIO_IO_OPEN, arg, ASE_NULL, 0) == -1)
|
||||
{
|
||||
tio->errnum = ASE_TIO_EINPOP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
tio->input_func = input;
|
||||
tio->input_arg = arg;
|
||||
|
||||
tio->input_status = 0;
|
||||
tio->inbuf_curp = 0;
|
||||
tio->inbuf_len = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ase_tio_detachin (ase_tio_t* tio)
|
||||
{
|
||||
if (tio->input_func != ASE_NULL)
|
||||
{
|
||||
if (tio->input_func (
|
||||
ASE_TIO_IO_CLOSE, tio->input_arg, ASE_NULL, 0) == -1)
|
||||
{
|
||||
tio->errnum = ASE_TIO_EINPCL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
tio->input_func = ASE_NULL;
|
||||
tio->input_arg = ASE_NULL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ase_tio_attachout (ase_tio_t* tio, ase_tio_io_t output, void* arg)
|
||||
{
|
||||
if (ase_tio_detachout(tio) == -1) return -1;
|
||||
|
||||
ASE_ASSERT (tio->output_func == ASE_NULL);
|
||||
|
||||
if (output(ASE_TIO_IO_OPEN, arg, ASE_NULL, 0) == -1)
|
||||
{
|
||||
tio->errnum = ASE_TIO_EOUTOP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
tio->output_func = output;
|
||||
tio->output_arg = arg;
|
||||
tio->outbuf_len = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ase_tio_detachout (ase_tio_t* tio)
|
||||
{
|
||||
if (tio->output_func != ASE_NULL)
|
||||
{
|
||||
ase_tio_flush (tio); /* don't care about the result */
|
||||
|
||||
if (tio->output_func (
|
||||
ASE_TIO_IO_CLOSE, tio->output_arg, ASE_NULL, 0) == -1)
|
||||
{
|
||||
tio->errnum = ASE_TIO_EOUTCL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
tio->output_func = ASE_NULL;
|
||||
tio->output_arg = ASE_NULL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
ase_ssize_t ase_tio_flush (ase_tio_t* tio)
|
||||
{
|
||||
ase_size_t left, count;
|
||||
|
||||
if (tio->output_func == ASE_NULL)
|
||||
{
|
||||
tio->errnum = ASE_TIO_ENOUTF;
|
||||
return (ase_ssize_t)-1;
|
||||
}
|
||||
|
||||
left = tio->outbuf_len;
|
||||
while (left > 0)
|
||||
{
|
||||
ase_ssize_t n;
|
||||
|
||||
n = tio->output_func (
|
||||
ASE_TIO_IO_DATA, tio->output_arg, tio->outbuf, left);
|
||||
if (n <= -1)
|
||||
{
|
||||
tio->outbuf_len = left;
|
||||
tio->errnum = ASE_TIO_EOUTPT;
|
||||
return -1;
|
||||
}
|
||||
if (n == 0) break;
|
||||
|
||||
left -= n;
|
||||
ASE_MEMCPY (tio->outbuf, &tio->inbuf[n], left);
|
||||
}
|
||||
|
||||
count = tio->outbuf_len - left;
|
||||
tio->outbuf_len = left;
|
||||
|
||||
return (ase_ssize_t)count;
|
||||
}
|
||||
|
||||
void ase_tio_purge (ase_tio_t* tio)
|
||||
{
|
||||
tio->input_status = 0;
|
||||
tio->inbuf_curp = 0;
|
||||
tio->inbuf_len = 0;
|
||||
tio->outbuf_len = 0;
|
||||
tio->errnum = ASE_TIO_ENOERR;
|
||||
}
|
214
qse/lib/cmn/tio_get.c
Normal file
214
qse/lib/cmn/tio_get.c
Normal file
@ -0,0 +1,214 @@
|
||||
/*
|
||||
* $Id: tio_get.c,v 1.8 2005/12/26 07:41:48 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <ase/cmn/tio.h>
|
||||
#include "mem.h"
|
||||
|
||||
#define STATUS_GETC_EILSEQ (1 << 0)
|
||||
|
||||
ase_ssize_t ase_tio_getc (ase_tio_t* tio, ase_char_t* c)
|
||||
{
|
||||
ase_size_t left = 0;
|
||||
ase_ssize_t n;
|
||||
ase_char_t curc;
|
||||
#ifndef ASE_CHAR_IS_MCHAR
|
||||
ase_size_t seqlen;
|
||||
#endif
|
||||
|
||||
/* TODO: more efficient way to check this?
|
||||
* maybe better to use ASE_ASSERT
|
||||
* ASE_ASSERT (tio->input_func != ASE_NULL);
|
||||
*/
|
||||
if (tio->input_func == ASE_NULL)
|
||||
{
|
||||
tio->errnum = ASE_TIO_ENOINF;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tio->input_status & STATUS_GETC_EILSEQ)
|
||||
{
|
||||
tio->input_status &= ~STATUS_GETC_EILSEQ;
|
||||
tio->errnum = ASE_TIO_EILSEQ;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tio->inbuf_curp >= tio->inbuf_len)
|
||||
{
|
||||
getc_conv:
|
||||
n = tio->input_func (
|
||||
ASE_TIO_IO_DATA, tio->input_arg,
|
||||
&tio->inbuf[left], ASE_COUNTOF(tio->inbuf) - left);
|
||||
if (n == 0)
|
||||
{
|
||||
if (tio->inbuf_curp < tio->inbuf_len)
|
||||
{
|
||||
/* gargage left in the buffer */
|
||||
tio->errnum = ASE_TIO_EICSEQ;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
if (n <= -1)
|
||||
{
|
||||
tio->errnum = ASE_TIO_EINPUT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
tio->inbuf_curp = 0;
|
||||
tio->inbuf_len = (ase_size_t)n + left;
|
||||
}
|
||||
|
||||
#ifdef ASE_CHAR_IS_MCHAR
|
||||
curc = tio->inbuf[tio->inbuf_curp++];
|
||||
#else
|
||||
left = tio->inbuf_len - tio->inbuf_curp;
|
||||
|
||||
#if 0
|
||||
seqlen = ase_mblen (tio->inbuf[tio->inbuf_curp], left);
|
||||
if (seqlen == 0)
|
||||
{
|
||||
/* illegal sequence */
|
||||
tio->inbuf_curp++; /* skip one byte */
|
||||
tio->errnum = ASE_TIO_EILSEQ;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (seqlen > left)
|
||||
{
|
||||
/* incomplete sequence */
|
||||
if (tio->inbuf_curp > 0)
|
||||
{
|
||||
ASE_MEMCPY (tio->inbuf, &tio->inbuf[tio->inbuf_curp], left);
|
||||
tio->inbuf_curp = 0;
|
||||
tio->inbuf_len = left;
|
||||
}
|
||||
goto getc_conv;
|
||||
}
|
||||
|
||||
n = ase_mbtowc (&tio->inbuf[tio->inbuf_curp], seqlen, &curc);
|
||||
if (n == 0)
|
||||
{
|
||||
/* illegal sequence */
|
||||
tio->inbuf_curp++; /* skip one byte */
|
||||
tio->errnum = ASE_TIO_EILSEQ;
|
||||
return -1;
|
||||
}
|
||||
if (n > seqlen)
|
||||
{
|
||||
/* incomplete sequence -
|
||||
* this check might not be needed because ase_mblen has
|
||||
* checked it. would ASE_ASSERT (n <= seqlen) be enough? */
|
||||
|
||||
if (tio->inbuf_curp > 0)
|
||||
{
|
||||
ASE_MEMCPY (tio->inbuf, &tio->inbuf[tio->inbuf_curp], left);
|
||||
tio->inbuf_curp = 0;
|
||||
tio->inbuf_len = left;
|
||||
}
|
||||
goto getc_conv;
|
||||
}
|
||||
#endif
|
||||
|
||||
n = ase_mbtowc (&tio->inbuf[tio->inbuf_curp], left, &curc);
|
||||
if (n == 0)
|
||||
{
|
||||
/* illegal sequence */
|
||||
tio->inbuf_curp++; /* skip one byte */
|
||||
tio->errnum = ASE_TIO_EILSEQ;
|
||||
return -1;
|
||||
}
|
||||
if (n > left)
|
||||
{
|
||||
/* incomplete sequence */
|
||||
if (tio->inbuf_curp > 0)
|
||||
{
|
||||
ASE_MEMCPY (tio->inbuf, &tio->inbuf[tio->inbuf_curp], left);
|
||||
tio->inbuf_curp = 0;
|
||||
tio->inbuf_len = left;
|
||||
}
|
||||
goto getc_conv;
|
||||
}
|
||||
|
||||
tio->inbuf_curp += n;
|
||||
#endif
|
||||
|
||||
*c = curc;
|
||||
return 1;
|
||||
}
|
||||
|
||||
ase_ssize_t ase_tio_gets (ase_tio_t* tio, ase_char_t* buf, ase_size_t size)
|
||||
{
|
||||
ase_ssize_t n;
|
||||
|
||||
if (size <= 0) return 0;
|
||||
n = ase_tio_getsx (tio, buf, size - 1);
|
||||
if (n == -1) return -1;
|
||||
buf[n] = ASE_T('\0');
|
||||
return n;
|
||||
}
|
||||
|
||||
ase_ssize_t ase_tio_getsx (ase_tio_t* tio, ase_char_t* buf, ase_size_t size)
|
||||
{
|
||||
ase_ssize_t n;
|
||||
ase_char_t* p, * end, c;
|
||||
|
||||
if (size <= 0) return 0;
|
||||
|
||||
p = buf; end = buf + size;
|
||||
while (p < end)
|
||||
{
|
||||
n = ase_tio_getc (tio, &c);
|
||||
if (n == -1)
|
||||
{
|
||||
if (p > buf && tio->errnum == ASE_TIO_EILSEQ)
|
||||
{
|
||||
tio->input_status |= STATUS_GETC_EILSEQ;
|
||||
break;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
if (n == 0) break;
|
||||
*p++ = c;
|
||||
|
||||
/* TODO: support a different line breaker */
|
||||
if (c == ASE_T('\n')) break;
|
||||
}
|
||||
|
||||
return p - buf;
|
||||
}
|
||||
|
||||
ase_ssize_t ase_tio_getstr (ase_tio_t* tio, ase_str_t* buf)
|
||||
{
|
||||
ase_ssize_t n;
|
||||
ase_char_t c;
|
||||
|
||||
ase_str_clear (buf);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
n = ase_tio_getc (tio, &c);
|
||||
if (n == -1)
|
||||
{
|
||||
if (ASE_STR_LEN(buf) > 0 && tio->errnum == ASE_TIO_EILSEQ)
|
||||
{
|
||||
tio->input_status |= STATUS_GETC_EILSEQ;
|
||||
break;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
if (n == 0) break;
|
||||
|
||||
if (ase_str_ccat(buf, c) == (ase_size_t)-1)
|
||||
{
|
||||
tio->errnum = ASE_TIO_ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* TODO: support a different line breaker */
|
||||
if (c == ASE_T('\n')) break;
|
||||
}
|
||||
|
||||
return ASE_STR_LEN(buf);
|
||||
}
|
157
qse/lib/cmn/tio_put.c
Normal file
157
qse/lib/cmn/tio_put.c
Normal file
@ -0,0 +1,157 @@
|
||||
/*
|
||||
* $Id: tio_put.c,v 1.2 2005/12/26 07:41:48 bacon Exp $
|
||||
*/
|
||||
|
||||
#include <ase/cmn/tio.h>
|
||||
|
||||
ase_ssize_t ase_tio_putc (ase_tio_t* tio, ase_char_t c)
|
||||
{
|
||||
#ifndef ASE_CHAR_IS_MCHAR
|
||||
ase_size_t n, i;
|
||||
ase_mchar_t mc[50];
|
||||
#endif
|
||||
|
||||
if (tio->outbuf_len >= ASE_COUNTOF(tio->outbuf))
|
||||
{
|
||||
/* maybe, previous flush operation has failed a few
|
||||
* times previously. so the buffer is full.
|
||||
*/
|
||||
tio->errnum = ASE_TIO_ENOSPC;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef ASE_CHAR_IS_MCHAR
|
||||
tio->outbuf[tio->outbuf_len++] = c;
|
||||
if (tio->outbuf_len >= ASE_COUNTOF(tio->outbuf))
|
||||
return ase_tio_flush (tio);
|
||||
#else
|
||||
|
||||
n = ase_wctomb (c, mc, ASE_COUNTOF(mc));
|
||||
if (n == 0)
|
||||
{
|
||||
tio->errnum = ASE_TIO_EILCHR;
|
||||
return -1;
|
||||
}
|
||||
else if (n > ASE_COUNTOF(mc))
|
||||
{
|
||||
tio->errnum = ASE_TIO_ENOSPC;
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
tio->outbuf[tio->outbuf_len++] = mc[i];
|
||||
if (tio->outbuf_len >= ASE_COUNTOF(tio->outbuf))
|
||||
{
|
||||
if (ase_tio_flush(tio) == -1) return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (c == ASE_T('\n') && tio->outbuf_len > 0)
|
||||
{
|
||||
if (ase_tio_flush(tio) == -1) return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
ase_ssize_t ase_tio_puts (ase_tio_t* tio, const ase_char_t* str)
|
||||
{
|
||||
ase_ssize_t n;
|
||||
const ase_char_t* p;
|
||||
|
||||
for (p = str; *p != ASE_T('\0'); p++)
|
||||
{
|
||||
n = ase_tio_putc (tio, *p);
|
||||
if (n == -1) return -1;
|
||||
if (n == 0) break;
|
||||
}
|
||||
|
||||
return p - str;
|
||||
}
|
||||
|
||||
ase_ssize_t ase_tio_putsx (ase_tio_t* tio, const ase_char_t* str, ase_size_t size)
|
||||
{
|
||||
ase_ssize_t n;
|
||||
const ase_char_t* p, * end;
|
||||
|
||||
if (size == 0) return 0;
|
||||
|
||||
p = str; end = str + size;
|
||||
while (p < end)
|
||||
{
|
||||
n = ase_tio_putc (tio, *p);
|
||||
if (n == -1) return -1;
|
||||
if (n == 0) break;
|
||||
|
||||
p++;
|
||||
}
|
||||
|
||||
return p - str;
|
||||
}
|
||||
|
||||
#if 0
|
||||
ase_ssize_t ase_tio_putsn (ase_tio_t* tio, ...)
|
||||
{
|
||||
ase_ssize_t n;
|
||||
ase_va_list ap;
|
||||
|
||||
ase_va_start (ap, tio);
|
||||
n = ase_tio_putsv (tio, ap);
|
||||
ase_va_end (ap);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
ase_ssize_t ase_tio_putsxn (ase_tio_t* tio, ...)
|
||||
{
|
||||
ase_ssize_t n;
|
||||
ase_va_list ap;
|
||||
|
||||
ase_va_start (ap, tio);
|
||||
n = ase_tio_putsxv (tio, ap);
|
||||
ase_va_end (ap);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
ase_ssize_t ase_tio_putsv (ase_tio_t* tio, ase_va_list ap)
|
||||
{
|
||||
const ase_char_t* p;
|
||||
ase_size_t n, total = 0;
|
||||
|
||||
while ((p = ase_va_arg (ap, const ase_char_t*)) != ASE_NULL)
|
||||
{
|
||||
if (p[0] == ASE_T('\0')) continue;
|
||||
|
||||
n = ase_tio_puts (tio, p);
|
||||
if (n == -1) return -1;
|
||||
if (n == 0) break;
|
||||
|
||||
total += n;
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
ase_ssize_t ase_tio_putsxv (ase_tio_t* tio, ase_va_list ap)
|
||||
{
|
||||
const ase_char_t* p;
|
||||
ase_size_t len, n, total = 0;
|
||||
|
||||
while ((p = ase_va_arg (ap, const ase_char_t*)) != ASE_NULL)
|
||||
{
|
||||
len = ase_va_arg (ap, ase_size_t);
|
||||
if (len == 0) continue;
|
||||
|
||||
n = ase_tio_putsx (tio, p, len);
|
||||
if (n == -1) return -1;
|
||||
if (n == 0) break;
|
||||
|
||||
total += n;
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
#endif
|
Reference in New Issue
Block a user