Recovered from cvs revision 2007-05-01 07:40:00

This commit is contained in:
2007-05-02 01:07:00 +00:00
parent 76daf75d92
commit e1b2079906
474 changed files with 99385 additions and 0 deletions

5938
ase/aclocal.m4 vendored Normal file

File diff suppressed because it is too large Load Diff

113
ase/ase.dsw Normal file
View File

@ -0,0 +1,113 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "asecmn"=.\cmn\asecmn.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "aseutl"=.\utl\aseutl.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "aseawk"=.\awk\aseawk.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "aseawk_jni"=.\awk\aseawk_jni.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "asecom"=.\com\asecom.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "asetestawk"=.\test\awk\asetestawk.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "aselsp"=.\lsp\aselsp.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "asetestlsp"=.\test\lsp\asetestlsp.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

175
ase/ase.sln Normal file
View File

@ -0,0 +1,175 @@

Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "asecmn", "cmn\asecmn.vcproj", "{17621C83-40C9-4305-BAF9-132E250B5FE3}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "aseutl", "utl\aseutl.vcproj", "{C3EBBFAE-9D08-4FA2-8B0E-D09BEBF84EDD}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "aseawk", "awk\aseawk.vcproj", "{5F2E77D5-1485-48D1-9371-987BC55FEE83}"
ProjectSection(ProjectDependencies) = postProject
{17621C83-40C9-4305-BAF9-132E250B5FE3} = {17621C83-40C9-4305-BAF9-132E250B5FE3}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "aesawk_jni", "awk\aseawk_jni.vcproj", "{23B58791-FD44-4F95-9F77-34E4AF45A296}"
ProjectSection(ProjectDependencies) = postProject
{5F2E77D5-1485-48D1-9371-987BC55FEE83} = {5F2E77D5-1485-48D1-9371-987BC55FEE83}
{17621C83-40C9-4305-BAF9-132E250B5FE3} = {17621C83-40C9-4305-BAF9-132E250B5FE3}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "asecom", "com\asecom.vcproj", "{963AF7B5-12E6-42B6-8CBE-89136C1A109B}"
ProjectSection(ProjectDependencies) = postProject
{5F2E77D5-1485-48D1-9371-987BC55FEE83} = {5F2E77D5-1485-48D1-9371-987BC55FEE83}
{C3EBBFAE-9D08-4FA2-8B0E-D09BEBF84EDD} = {C3EBBFAE-9D08-4FA2-8B0E-D09BEBF84EDD}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "asetestawk", "test\awk\asetestawk.vcproj", "{57F1E1D0-28B6-42BF-BAFB-045AEE2DCF4F}"
ProjectSection(ProjectDependencies) = postProject
{5F2E77D5-1485-48D1-9371-987BC55FEE83} = {5F2E77D5-1485-48D1-9371-987BC55FEE83}
{C3EBBFAE-9D08-4FA2-8B0E-D09BEBF84EDD} = {C3EBBFAE-9D08-4FA2-8B0E-D09BEBF84EDD}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "aselsp", "lsp\aselsp.vcproj", "{42FE7CED-34B7-45C8-92C9-8856E16640D2}"
ProjectSection(ProjectDependencies) = postProject
{17621C83-40C9-4305-BAF9-132E250B5FE3} = {17621C83-40C9-4305-BAF9-132E250B5FE3}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "asetestlsp", "test\lsp\asetestlsp.vcproj", "{868702B0-CB6B-4F1D-B98A-32193347EFAF}"
ProjectSection(ProjectDependencies) = postProject
{42FE7CED-34B7-45C8-92C9-8856E16640D2} = {42FE7CED-34B7-45C8-92C9-8856E16640D2}
{C3EBBFAE-9D08-4FA2-8B0E-D09BEBF84EDD} = {C3EBBFAE-9D08-4FA2-8B0E-D09BEBF84EDD}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "asetestcnt", "test\cnt\asetestcnt.csproj", "{F14B75D8-3ED7-4621-B5B9-E96A80B5D809}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "asenet", "net\asenet.vcproj", "{4CBF0E86-D018-49D7-A6B8-0CDA698203F7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "asecnt", "cnt\asecnt.csproj", "{7F679165-41FB-4E1E-B3F5-23C5EE94166A}"
ProjectSection(ProjectDependencies) = postProject
{963AF7B5-12E6-42B6-8CBE-89136C1A109B} = {963AF7B5-12E6-42B6-8CBE-89136C1A109B}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|Mixed Platforms = Debug|Mixed Platforms
Debug|Win32 = Debug|Win32
Release|Any CPU = Release|Any CPU
Release|Mixed Platforms = Release|Mixed Platforms
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{17621C83-40C9-4305-BAF9-132E250B5FE3}.Debug|Any CPU.ActiveCfg = Debug|Win32
{17621C83-40C9-4305-BAF9-132E250B5FE3}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{17621C83-40C9-4305-BAF9-132E250B5FE3}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{17621C83-40C9-4305-BAF9-132E250B5FE3}.Debug|Win32.ActiveCfg = Debug|Win32
{17621C83-40C9-4305-BAF9-132E250B5FE3}.Debug|Win32.Build.0 = Debug|Win32
{17621C83-40C9-4305-BAF9-132E250B5FE3}.Release|Any CPU.ActiveCfg = Release|Win32
{17621C83-40C9-4305-BAF9-132E250B5FE3}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{17621C83-40C9-4305-BAF9-132E250B5FE3}.Release|Mixed Platforms.Build.0 = Release|Win32
{17621C83-40C9-4305-BAF9-132E250B5FE3}.Release|Win32.ActiveCfg = Release|Win32
{17621C83-40C9-4305-BAF9-132E250B5FE3}.Release|Win32.Build.0 = Release|Win32
{C3EBBFAE-9D08-4FA2-8B0E-D09BEBF84EDD}.Debug|Any CPU.ActiveCfg = Debug|Win32
{C3EBBFAE-9D08-4FA2-8B0E-D09BEBF84EDD}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{C3EBBFAE-9D08-4FA2-8B0E-D09BEBF84EDD}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{C3EBBFAE-9D08-4FA2-8B0E-D09BEBF84EDD}.Debug|Win32.ActiveCfg = Debug|Win32
{C3EBBFAE-9D08-4FA2-8B0E-D09BEBF84EDD}.Debug|Win32.Build.0 = Debug|Win32
{C3EBBFAE-9D08-4FA2-8B0E-D09BEBF84EDD}.Release|Any CPU.ActiveCfg = Release|Win32
{C3EBBFAE-9D08-4FA2-8B0E-D09BEBF84EDD}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{C3EBBFAE-9D08-4FA2-8B0E-D09BEBF84EDD}.Release|Mixed Platforms.Build.0 = Release|Win32
{C3EBBFAE-9D08-4FA2-8B0E-D09BEBF84EDD}.Release|Win32.ActiveCfg = Release|Win32
{C3EBBFAE-9D08-4FA2-8B0E-D09BEBF84EDD}.Release|Win32.Build.0 = Release|Win32
{5F2E77D5-1485-48D1-9371-987BC55FEE83}.Debug|Any CPU.ActiveCfg = Debug|Win32
{5F2E77D5-1485-48D1-9371-987BC55FEE83}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{5F2E77D5-1485-48D1-9371-987BC55FEE83}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{5F2E77D5-1485-48D1-9371-987BC55FEE83}.Debug|Win32.ActiveCfg = Debug|Win32
{5F2E77D5-1485-48D1-9371-987BC55FEE83}.Debug|Win32.Build.0 = Debug|Win32
{5F2E77D5-1485-48D1-9371-987BC55FEE83}.Release|Any CPU.ActiveCfg = Release|Win32
{5F2E77D5-1485-48D1-9371-987BC55FEE83}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{5F2E77D5-1485-48D1-9371-987BC55FEE83}.Release|Mixed Platforms.Build.0 = Release|Win32
{5F2E77D5-1485-48D1-9371-987BC55FEE83}.Release|Win32.ActiveCfg = Release|Win32
{5F2E77D5-1485-48D1-9371-987BC55FEE83}.Release|Win32.Build.0 = Release|Win32
{23B58791-FD44-4F95-9F77-34E4AF45A296}.Debug|Any CPU.ActiveCfg = Debug|Win32
{23B58791-FD44-4F95-9F77-34E4AF45A296}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{23B58791-FD44-4F95-9F77-34E4AF45A296}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{23B58791-FD44-4F95-9F77-34E4AF45A296}.Debug|Win32.ActiveCfg = Debug|Win32
{23B58791-FD44-4F95-9F77-34E4AF45A296}.Debug|Win32.Build.0 = Debug|Win32
{23B58791-FD44-4F95-9F77-34E4AF45A296}.Release|Any CPU.ActiveCfg = Release|Win32
{23B58791-FD44-4F95-9F77-34E4AF45A296}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{23B58791-FD44-4F95-9F77-34E4AF45A296}.Release|Mixed Platforms.Build.0 = Release|Win32
{23B58791-FD44-4F95-9F77-34E4AF45A296}.Release|Win32.ActiveCfg = Release|Win32
{23B58791-FD44-4F95-9F77-34E4AF45A296}.Release|Win32.Build.0 = Release|Win32
{963AF7B5-12E6-42B6-8CBE-89136C1A109B}.Debug|Any CPU.ActiveCfg = Debug|Win32
{963AF7B5-12E6-42B6-8CBE-89136C1A109B}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{963AF7B5-12E6-42B6-8CBE-89136C1A109B}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{963AF7B5-12E6-42B6-8CBE-89136C1A109B}.Debug|Win32.ActiveCfg = Debug|Win32
{963AF7B5-12E6-42B6-8CBE-89136C1A109B}.Debug|Win32.Build.0 = Debug|Win32
{963AF7B5-12E6-42B6-8CBE-89136C1A109B}.Release|Any CPU.ActiveCfg = Release|Win32
{963AF7B5-12E6-42B6-8CBE-89136C1A109B}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{963AF7B5-12E6-42B6-8CBE-89136C1A109B}.Release|Mixed Platforms.Build.0 = Release|Win32
{963AF7B5-12E6-42B6-8CBE-89136C1A109B}.Release|Win32.ActiveCfg = Release|Win32
{963AF7B5-12E6-42B6-8CBE-89136C1A109B}.Release|Win32.Build.0 = Release|Win32
{57F1E1D0-28B6-42BF-BAFB-045AEE2DCF4F}.Debug|Any CPU.ActiveCfg = Debug|Win32
{57F1E1D0-28B6-42BF-BAFB-045AEE2DCF4F}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{57F1E1D0-28B6-42BF-BAFB-045AEE2DCF4F}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{57F1E1D0-28B6-42BF-BAFB-045AEE2DCF4F}.Debug|Win32.ActiveCfg = Debug|Win32
{57F1E1D0-28B6-42BF-BAFB-045AEE2DCF4F}.Debug|Win32.Build.0 = Debug|Win32
{57F1E1D0-28B6-42BF-BAFB-045AEE2DCF4F}.Release|Any CPU.ActiveCfg = Release|Win32
{57F1E1D0-28B6-42BF-BAFB-045AEE2DCF4F}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{57F1E1D0-28B6-42BF-BAFB-045AEE2DCF4F}.Release|Mixed Platforms.Build.0 = Release|Win32
{57F1E1D0-28B6-42BF-BAFB-045AEE2DCF4F}.Release|Win32.ActiveCfg = Release|Win32
{57F1E1D0-28B6-42BF-BAFB-045AEE2DCF4F}.Release|Win32.Build.0 = Release|Win32
{42FE7CED-34B7-45C8-92C9-8856E16640D2}.Debug|Any CPU.ActiveCfg = Debug|Win32
{42FE7CED-34B7-45C8-92C9-8856E16640D2}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{42FE7CED-34B7-45C8-92C9-8856E16640D2}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{42FE7CED-34B7-45C8-92C9-8856E16640D2}.Debug|Win32.ActiveCfg = Debug|Win32
{42FE7CED-34B7-45C8-92C9-8856E16640D2}.Debug|Win32.Build.0 = Debug|Win32
{42FE7CED-34B7-45C8-92C9-8856E16640D2}.Release|Any CPU.ActiveCfg = Release|Win32
{42FE7CED-34B7-45C8-92C9-8856E16640D2}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{42FE7CED-34B7-45C8-92C9-8856E16640D2}.Release|Mixed Platforms.Build.0 = Release|Win32
{42FE7CED-34B7-45C8-92C9-8856E16640D2}.Release|Win32.ActiveCfg = Release|Win32
{42FE7CED-34B7-45C8-92C9-8856E16640D2}.Release|Win32.Build.0 = Release|Win32
{868702B0-CB6B-4F1D-B98A-32193347EFAF}.Debug|Any CPU.ActiveCfg = Debug|Win32
{868702B0-CB6B-4F1D-B98A-32193347EFAF}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{868702B0-CB6B-4F1D-B98A-32193347EFAF}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{868702B0-CB6B-4F1D-B98A-32193347EFAF}.Debug|Win32.ActiveCfg = Debug|Win32
{868702B0-CB6B-4F1D-B98A-32193347EFAF}.Debug|Win32.Build.0 = Debug|Win32
{868702B0-CB6B-4F1D-B98A-32193347EFAF}.Release|Any CPU.ActiveCfg = Release|Win32
{868702B0-CB6B-4F1D-B98A-32193347EFAF}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{868702B0-CB6B-4F1D-B98A-32193347EFAF}.Release|Mixed Platforms.Build.0 = Release|Win32
{868702B0-CB6B-4F1D-B98A-32193347EFAF}.Release|Win32.ActiveCfg = Release|Win32
{868702B0-CB6B-4F1D-B98A-32193347EFAF}.Release|Win32.Build.0 = Release|Win32
{F14B75D8-3ED7-4621-B5B9-E96A80B5D809}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F14B75D8-3ED7-4621-B5B9-E96A80B5D809}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F14B75D8-3ED7-4621-B5B9-E96A80B5D809}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{F14B75D8-3ED7-4621-B5B9-E96A80B5D809}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{F14B75D8-3ED7-4621-B5B9-E96A80B5D809}.Debug|Win32.ActiveCfg = Debug|Any CPU
{F14B75D8-3ED7-4621-B5B9-E96A80B5D809}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F14B75D8-3ED7-4621-B5B9-E96A80B5D809}.Release|Any CPU.Build.0 = Release|Any CPU
{F14B75D8-3ED7-4621-B5B9-E96A80B5D809}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{F14B75D8-3ED7-4621-B5B9-E96A80B5D809}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{F14B75D8-3ED7-4621-B5B9-E96A80B5D809}.Release|Win32.ActiveCfg = Release|Any CPU
{4CBF0E86-D018-49D7-A6B8-0CDA698203F7}.Debug|Any CPU.ActiveCfg = Debug|Win32
{4CBF0E86-D018-49D7-A6B8-0CDA698203F7}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{4CBF0E86-D018-49D7-A6B8-0CDA698203F7}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{4CBF0E86-D018-49D7-A6B8-0CDA698203F7}.Debug|Win32.ActiveCfg = Debug|Win32
{4CBF0E86-D018-49D7-A6B8-0CDA698203F7}.Debug|Win32.Build.0 = Debug|Win32
{4CBF0E86-D018-49D7-A6B8-0CDA698203F7}.Release|Any CPU.ActiveCfg = Release|Win32
{4CBF0E86-D018-49D7-A6B8-0CDA698203F7}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{4CBF0E86-D018-49D7-A6B8-0CDA698203F7}.Release|Mixed Platforms.Build.0 = Release|Win32
{4CBF0E86-D018-49D7-A6B8-0CDA698203F7}.Release|Win32.ActiveCfg = Release|Win32
{4CBF0E86-D018-49D7-A6B8-0CDA698203F7}.Release|Win32.Build.0 = Release|Win32
{7F679165-41FB-4E1E-B3F5-23C5EE94166A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7F679165-41FB-4E1E-B3F5-23C5EE94166A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7F679165-41FB-4E1E-B3F5-23C5EE94166A}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{7F679165-41FB-4E1E-B3F5-23C5EE94166A}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{7F679165-41FB-4E1E-B3F5-23C5EE94166A}.Debug|Win32.ActiveCfg = Debug|Any CPU
{7F679165-41FB-4E1E-B3F5-23C5EE94166A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7F679165-41FB-4E1E-B3F5-23C5EE94166A}.Release|Any CPU.Build.0 = Release|Any CPU
{7F679165-41FB-4E1E-B3F5-23C5EE94166A}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{7F679165-41FB-4E1E-B3F5-23C5EE94166A}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{7F679165-41FB-4E1E-B3F5-23C5EE94166A}.Release|Win32.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

35
ase/awk/Awk.cpp Normal file
View File

@ -0,0 +1,35 @@
/*
* $Id: Awk.cpp,v 1.1 2007/04/30 05:47:33 bacon Exp $
*/
#include <ase/awk/Awk.hpp>
namespace ASE
{
Awk::Awk (): awk (ASE_NULL)
{
}
Awk::~Awk ()
{
if (awk != ASE_NULL)
{
ase_awk_close (awk);
awk = ASE_NULL;
}
}
int Awk::parse ()
{
return ase_awk_parse (awk, ASE_NULL);
}
int Awk::run (/*const ase_char_t* main*/)
{
//return ase_awk_parse (awk, main);
return 0;
}
}

28
ase/awk/Awk.hpp Normal file
View File

@ -0,0 +1,28 @@
/*
* $Id: Awk.hpp,v 1.1 2007/04/30 05:47:33 bacon Exp $
*/
#ifndef _ASE_AWK_AWK_HPP_
#define _ASE_AWK_AWK_HPP_
#include <ase/awk/awk.h>
namespace ASE
{
class Awk
{
public:
Awk ();
~Awk ();
int parse ();
int run ();
private:
ase_awk_t* awk;
};
}
#endif

346
ase/awk/Awk.java Normal file
View File

@ -0,0 +1,346 @@
/*
* $Id: Awk.java,v 1.3 2007/04/30 05:47:33 bacon Exp $
*
* {License}
*/
package ase.awk;
public abstract class Awk
{
// mode for open_source & close_source
public static final int SOURCE_READ = 1;
public static final int SOURCE_WRITE = 2;
// depth id
public static final int DEPTH_BLOCK_PARSE = (1 << 0);
public static final int DEPTH_BLOCK_RUN = (1 << 1);
public static final int DEPTH_EXPR_PARSE = (1 << 2);
public static final int DEPTH_EXPR_RUN = (1 << 3);
public static final int DEPTH_REX_BUILD = (1 << 4);
public static final int DEPTH_REX_MATCH = (1 << 5);
// options
public static final int OPTION_IMPLICIT = (1 << 0);
public static final int OPTION_EXPLICIT = (1 << 1);
public static final int OPTION_UNIQUEFN = (1 << 2);
public static final int OPTION_SHADING = (1 << 3);
public static final int OPTION_SHIFT = (1 << 4);
public static final int OPTION_IDIV = (1 << 5);
public static final int OPTION_STRCONCAT = (1 << 6);
public static final int OPTION_EXTIO = (1 << 7);
public static final int OPTION_COPROC = (1 << 8);
public static final int OPTION_BLOCKLESS = (1 << 9);
public static final int OPTION_STRBASEONE = (1 << 10);
public static final int OPTION_STRIPSPACES = (1 << 11);
public static final int OPTION_NEXTOFILE = (1 << 12);
public static final int OPTION_CRLF = (1 << 13);
public static final int OPTION_ARGSTOMAIN = (1 << 14);
private long handle;
public Awk () throws Exception
{
this.handle = 0;
open ();
}
/* == just in case == */
protected void finalize () throws Throwable
{
super.finalize ();
if (handle != 0) close ();
}
/* == native methods == */
private native void open () throws Exception;
public native void close ();
public native void parse () throws Exception;
public native void run (String main, String[] args) throws Exception;
private native int getmaxdepth (int id);
private native void setmaxdepth (int id, int depth);
private native int getoption ();
private native void setoption (int opt);
private native boolean getdebug ();
private native void setdebug (boolean debug);
private native void addbfn (
String name, int min_args, int max_args) throws Exception;
private native void delbfn (String name) throws Exception;
private native void setfilename (
long runid, String name) throws Exception;
private native void setofilename (
long runid, String name) throws Exception;
private native Object strtonum (
long runid, String str) throws Exception;
private native String valtostr (
long runid, Object obj) throws Exception;
/* == simpler run methods == */
public void run (String main) throws Exception
{
run (main, null);
}
public void run (String[] args) throws Exception
{
run (null, args);
}
public void run () throws Exception
{
run (null, null);
}
/* == builtin functions == */
public void addBuiltinFunction (
String name, int min_args, int max_args) throws Exception
{
addbfn (name, min_args, max_args);
}
public void deleteBuiltinFunction (String name) throws Exception
{
delbfn (name);
}
protected long builtinFunctionArgumentToLong (
long runid, Object obj) throws Exception
{
long n;
if (obj == null) n = 0;
else
{
if (obj instanceof String)
obj = strtonum (runid, (String)obj);
if (obj instanceof Long)
{
n = ((Long)obj).longValue ();
}
else if (obj instanceof Double)
{
n = ((Double)obj).longValue ();
}
else if (obj instanceof Integer)
{
n = ((Integer)obj).longValue ();
}
else if (obj instanceof Short)
{
n = ((Short)obj).longValue ();
}
else if (obj instanceof Float)
{
n = ((Float)obj).longValue ();
}
else n = 0;
}
return n;
}
protected double builtinFunctionArgumentToDouble (
long runid, Object obj) throws Exception
{
double n;
if (obj == null) n = 0.0;
else
{
if (obj instanceof String)
obj = strtonum (runid, (String)obj);
if (obj instanceof Long)
{
n = ((Long)obj).doubleValue ();
}
else if (obj instanceof Double)
{
n = ((Double)obj).doubleValue ();
}
else if (obj instanceof Integer)
{
n = ((Integer)obj).doubleValue ();
}
else if (obj instanceof Short)
{
n = ((Short)obj).doubleValue ();
}
else if (obj instanceof Float)
{
n = ((Float)obj).doubleValue ();
}
else n = 0.0;
}
return n;
}
protected String builtinFunctionArgumentToString (
long runid, Object obj) throws Exception
{
String str;
if (obj == null) str = "";
else if (obj instanceof String) str = (String)obj;
else str = valtostr (runid, obj);
return str;
}
/* == console name setters == */
protected void setConsoleInputName (
Extio extio, String name) throws Exception
{
/* TODO: setfilename is not safe. for example, it can
* crash the program if runid is invalid. so this wrapper
* needs to do some sanity check. */
setfilename (extio.getRunId(), name);
}
protected void setConsoleOutputName (
Extio extio, String name) throws Exception
{
setofilename (extio.getRunId(), name);
}
/* == depth limiting == */
public int getMaxDepth (int id)
{
return getmaxdepth (id);
}
public void setMaxDepth (int ids, int depth)
{
setmaxdepth (ids, depth);
}
/* == option == */
public int getOption ()
{
return getoption ();
}
public void setOption (int opt)
{
setoption (opt);
}
/* == debug == */
public boolean getDebug ()
{
return getdebug ();
}
public void setDebug (boolean debug)
{
setdebug (debug);
}
/* == source code management == */
protected abstract int openSource (int mode);
protected abstract int closeSource (int mode);
protected abstract int readSource (char[] buf, int len);
protected abstract int writeSource (char[] buf, int len);
/* == external io interface == */
protected int openExtio (Extio extio)
{
int type = extio.getType ();
if (type == Extio.TYPE_CONSOLE) return openConsole (extio);
if (type == Extio.TYPE_FILE) return openFile (extio);
if (type == Extio.TYPE_PIPE) return openPipe (extio);
//if (type == Extio.TYPE_COPROC) return openCoproc (extio);
return -1;
}
protected int closeExtio (Extio extio)
{
int type = extio.getType ();
if (type == Extio.TYPE_CONSOLE) return closeConsole (extio);
if (type == Extio.TYPE_FILE) return closeFile (extio);
if (type == Extio.TYPE_PIPE) return closePipe (extio);
//if (type == Extio.TYPE_COPROC) return closeCoproc (extio);
return -1;
}
protected int readExtio (Extio extio, char[] buf, int len)
{
// this check is needed because 0 is used to indicate
// the end of the stream. java streams can return 0
// if the data given is 0 bytes and it didn't reach
// the end of the stream.
if (len <= 0) return -1;
int type = extio.getType ();
if (type == Extio.TYPE_CONSOLE)
return readConsole (extio, buf, len);
if (type == Extio.TYPE_FILE)
return readFile (extio, buf, len);
if (type == Extio.TYPE_PIPE)
return readPipe (extio, buf, len);
//if (type == Extio.TYPE_COPROC)
// return readCoproc (extio, buf, len);
return -1;
}
protected int writeExtio (Extio extio, char[] buf, int len)
{
if (len <= 0) return -1;
int type = extio.getType ();
if (type == Extio.TYPE_CONSOLE)
return writeConsole (extio, buf, len);
if (type == Extio.TYPE_FILE)
return writeFile (extio, buf, len);
if (type == Extio.TYPE_PIPE)
return writePipe (extio, buf, len);
//if (type == Extio.TYPE_COPROC)
// return writeCoproc (extio, buf, len);
return -1;
}
protected int flushExtio (Extio extio)
{
int type = extio.getType ();
if (type == Extio.TYPE_CONSOLE) return flushConsole (extio);
if (type == Extio.TYPE_FILE) return flushFile (extio);
if (type == Extio.TYPE_PIPE) return flushPipe (extio);
//if (type == Extio.TYPE_COPROC) return flushCoproc (extio);
return -1;
}
protected int nextExtio (Extio extio)
{
int type = extio.getType ();
if (type == Extio.TYPE_CONSOLE) return nextConsole (extio);
return -1;
}
protected abstract int openConsole (Extio extio);
protected abstract int closeConsole (Extio extio);
protected abstract int readConsole (Extio extio, char[] buf, int len);
protected abstract int writeConsole (Extio extio, char[] buf, int len);
protected abstract int flushConsole (Extio extio);
protected abstract int nextConsole (Extio extio);
protected abstract int openFile (Extio extio);
protected abstract int closeFile (Extio extio);
protected abstract int readFile (Extio extio, char[] buf, int len);
protected abstract int writeFile (Extio extio, char[] buf, int len);
protected abstract int flushFile (Extio extio);
protected abstract int openPipe (Extio extio);
protected abstract int closePipe (Extio extio);
protected abstract int readPipe (Extio extio, char[] buf, int len);
protected abstract int writePipe (Extio extio, char[] buf, int len);
protected abstract int flushPipe (Extio extio);
}

51
ase/awk/Exception.java Normal file
View File

@ -0,0 +1,51 @@
/*
* $Id: Exception.java,v 1.3 2007/04/30 05:47:33 bacon Exp $
*
* {License}
*/
package ase.awk;
public class Exception extends java.lang.Exception
{
private int code;
private int line;
public Exception ()
{
super ();
this.code = 0;
this.line = 0;
}
public Exception (String msg)
{
super (msg);
this.code = 0;
this.line = 0;
}
public Exception (String msg, int code)
{
super (msg);
this.code = code;
this.line = 0;
}
public Exception (String msg, int code, int line)
{
super (msg);
this.code = code;
this.line = line;
}
public int getCode ()
{
return this.code;
}
public int getLine ()
{
return this.line;
}
}

75
ase/awk/Extio.java Normal file
View File

@ -0,0 +1,75 @@
/*
* $Id: Extio.java,v 1.3 2007/04/30 05:47:33 bacon Exp $
*
* {License}
*/
package ase.awk;
public class Extio
{
public static final int TYPE_PIPE = 0;
public static final int TYPE_COPROC = 1;
public static final int TYPE_FILE = 2;
public static final int TYPE_CONSOLE = 3;
public static final int MODE_PIPE_READ = 0;
public static final int MODE_PIPE_WRITE = 1;
public static final int MODE_FILE_READ = 0;
public static final int MODE_FILE_WRITE = 1;
public static final int MODE_FILE_APPEND = 2;
public static final int MODE_CONSOLE_READ = 0;
public static final int MODE_CONSOLE_WRITE = 1;
private String name;
private int type;
private int mode;
private long run_id;
private Object handle;
protected Extio (String name, int type, int mode, long run_id)
{
this.name = name;
this.type = type;
this.mode = mode;
this.run_id = run_id;
this.handle = null;
}
public String getName ()
{
return this.name;
}
public int getType ()
{
return this.type;
}
public int getMode ()
{
return this.mode;
}
public long getRunId ()
{
return this.run_id;
}
public void setHandle (Object handle)
{
this.handle = handle;
}
public Object getHandle ()
{
return this.handle;
}
protected void finalize () throws Throwable
{
super.finalize ();
}
};

865
ase/awk/StdAwk.java Normal file
View File

@ -0,0 +1,865 @@
/*
* $Id: StdAwk.java,v 1.3 2007/04/30 05:47:33 bacon Exp $
*
* {License}
*/
package ase.awk;
import java.io.*;
public abstract class StdAwk extends Awk
{
private Reader src_in = null;
private Writer src_out = null;
private String[] sin = null;
private int sin_no = 0;
private String[] sout = null;
private int sout_no = 0;
private String[] cin = null;
private int cin_no = 0;
private String[] cout = null;
private int cout_no = 0;
private long seed;
private java.util.Random random;
private final static Reader stdin =
new BufferedReader (new InputStreamReader (System.in));
private final static Writer stdout =
new BufferedWriter (new OutputStreamWriter (System.out));
/*
static
{
stdin = new BufferedReader (
new InputStreamReader (System.in));
stdout = new BufferedWriter (
new OutputStreamWriter (System.out));
}
*/
public StdAwk () throws Exception
{
super ();
seed = System.currentTimeMillis();
random = new java.util.Random (seed);
addBuiltinFunction ("sin", 1, 1);
addBuiltinFunction ("cos", 1, 1);
addBuiltinFunction ("tan", 1, 1);
addBuiltinFunction ("atan2", 1, 1);
addBuiltinFunction ("log", 1, 1);
addBuiltinFunction ("exp", 1, 1);
addBuiltinFunction ("sqrt", 1, 1);
addBuiltinFunction ("int", 1, 1);
addBuiltinFunction ("srand", 0, 1);
addBuiltinFunction ("rand", 0, 0);
addBuiltinFunction ("systime", 0, 0);
addBuiltinFunction ("strftime", 0, Integer.MAX_VALUE);
addBuiltinFunction ("system", 1, 1);
}
/* == major methods == */
public void parse () throws Exception
{
sin = sourceInputNames (); sin_no = 0;
sout = sourceOutputNames (); sout_no = 0;
super.parse ();
}
public void run (String main, String[] args) throws Exception
{
cin = consoleInputNames (); cin_no = 0;
cout = consoleOutputNames (); cout_no = 0;
super.run (main, args);
}
public void run (String main) throws Exception
{
run (main, null);
}
public void run (String[] args) throws Exception
{
run (null, args);
}
public void run () throws Exception
{
run (null, null);
}
/* == source code names == */
protected String[] sourceInputNames () { return null; }
protected String[] sourceOutputNames () { return null; }
/* == console names == */
protected String[] consoleInputNames () { return null; }
protected String[] consoleOutputNames () { return null; }
/* == source code == */
protected int openSource (int mode)
{
if (mode == SOURCE_READ)
{
Reader isr;
sin_no = 0;
if (sin == null || sin_no >= sin.length) return 0;
isr = get_stream_reader (sin[sin_no]);
if (isr == null) return -1;
src_in = isr;
sin_no++;
return 1;
}
else if (mode == SOURCE_WRITE)
{
Writer osw;
sout_no = 0;
// when sout is null, the source output is treated
// as if the operation has been successful with
// the writeSource and closeSource method.
if (sout == null) return 1;
if (sout_no >= sin.length) return 0;
osw = get_stream_writer (sout[sout_no]);
if (osw == null) return -1;
src_out = osw;
sout_no++;
return 1;
}
return -1;
}
protected int closeSource (int mode)
{
if (mode == SOURCE_READ)
{
if (src_in != StdAwk.stdin)
{
try { src_in.close (); }
catch (IOException e) { return -1; }
}
return 0;
}
else if (mode == SOURCE_WRITE)
{
if (src_out == null) return 0;
if (src_out != StdAwk.stdout)
{
try { src_out.close (); }
catch (IOException e) { return -1; }
}
return 0;
}
return -1;
}
protected int readSource (char[] buf, int len)
{
try {
int n = src_in.read (buf, 0, len);
while (n == -1)
{
Reader isr;
if (sin == null || sin_no >= sin.length) return 0;
isr = get_stream_reader (sin[sin_no]);
if (isr == null) return -1;
if (src_in != StdAwk.stdin)
{
try { src_in.close (); }
catch (IOException ec) { /* ignore */ }
}
src_in = isr;
sin_no++;
n = src_in.read (buf, 0, len);
}
return n;
}
catch (IOException e)
{
return -1;
}
}
protected int writeSource (char[] buf, int len)
{
if (src_out == null) return len;
// only the first file is used at the moment.
// this is because the write message doesn't indicate
// the end of the output stream.
try { src_out.write (buf, 0, len); }
catch (IOException e) { return -1; }
return len;
}
/* == console interface == */
protected int openConsole (Extio extio)
{
//System.err.println ("[openConsole called.... name: " + extio.getName() + " mode: " + extio.getMode());
int mode = extio.getMode ();
if (mode == Extio.MODE_CONSOLE_READ)
{
/*InputStream*/Reader isr;
cin_no = 0;
if (cin == null || cin_no >= cin.length) return 0;
isr = get_stream_reader (cin[cin_no]);
if (isr == null) return -1;
extio.setHandle (isr);
try { setConsoleInputName (extio, cin[cin_no]); }
catch (Exception e) { return -1; }
cin_no++;
return 1;
}
else if (mode == Extio.MODE_CONSOLE_WRITE)
{
Writer osw;
cout_no = 0;
if (cout == null || cout_no >= cout.length) return 0;
osw = get_stream_writer (cout[cout_no]);
if (osw == null) return -1;
extio.setHandle (osw);
try { setConsoleOutputName (extio, cout[cout_no]); }
catch (Exception e) { return -1; }
cout_no++;
return 1;
}
return -1;
}
protected int closeConsole (Extio extio)
{
//System.err.println ("[closeConsole called.... name: " + extio.getName() + " mode: " + extio.getMode());
int mode = extio.getMode ();
if (mode == Extio.MODE_CONSOLE_READ)
{
Reader isr = (Reader)extio.getHandle ();
if (isr != StdAwk.stdin)
{
try { isr.close (); }
catch (IOException e) { return -1; }
}
return 0;
}
else if (mode == Extio.MODE_CONSOLE_WRITE)
{
Writer osw = (Writer)extio.getHandle ();
/* TODO: selective close the stream...
* system.out should not be closed??? */
if (osw != StdAwk.stdout)
{
try { osw.close (); }
catch (IOException e) { return -1; }
}
return 0;
}
return -1;
}
protected int readConsole (Extio extio, char[] buf, int len)
{
int mode = extio.getMode ();
if (mode == Extio.MODE_CONSOLE_READ)
{
Reader isr, tmp;
int n;
isr = (Reader)extio.getHandle ();
try { n = isr.read (buf, 0, len); }
catch (IOException e) { return -1; }
while (n == -1)
{
if (cin == null || cin_no >= cin.length) return 0;
tmp = get_stream_reader (cin[cin_no]);
if (tmp == null) return -1;
if (isr != StdAwk.stdin)
{
try { isr.close (); }
catch (IOException e) { /* ignore */ }
}
extio.setHandle (tmp);
try { setConsoleInputName (extio, cin[cin_no]); }
catch (Exception e) { return -1; }
isr = (Reader)extio.getHandle ();
cin_no++;
try { n = isr.read (buf, 0, len); }
catch (IOException e) { return -1; }
}
return n;
}
return -1;
}
protected int writeConsole (Extio extio, char[] buf, int len)
{
int mode = extio.getMode ();
//System.err.println ("[writeConsole called name: " + extio.getName() + " mode: " + extio.getMode());
if (mode == Extio.MODE_CONSOLE_WRITE)
{
Writer osw;
osw = (Writer)extio.getHandle ();
// as the write operation below doesn't
// indicate if it has reached the end, console
// can't be switched here unlike in read_console
try { osw.write (buf, 0, len); osw.flush (); }
catch (IOException e) { return -1; }
return len;
}
return -1;
}
protected int flushConsole (Extio extio)
{
int mode = extio.getMode ();
if (mode == Extio.MODE_CONSOLE_WRITE)
{
Writer osw;
osw = (Writer)extio.getHandle ();
try { osw.flush (); }
catch (IOException e) { return -1; }
return 0;
}
return -1;
}
protected int nextConsole (Extio extio)
{
int mode = extio.getMode ();
if (mode == Extio.MODE_CONSOLE_READ)
{
Reader isr, tmp;
isr = (Reader)extio.getHandle ();
if (cin == null || cin_no >= cin.length) return 0;
tmp = get_stream_reader (cin[cin_no]);
if (tmp == null) return -1;
if (isr != StdAwk.stdin)
{
try { isr.close (); }
catch (IOException e) { /* ignore */ }
}
extio.setHandle (tmp);
try { setConsoleInputName (extio, cin[cin_no]); }
catch (Exception e) { return -1; }
cin_no++;
return 1;
}
else if (mode == Extio.MODE_CONSOLE_WRITE)
{
Writer osw, tmp;
osw = (Writer)extio.getHandle ();
if (cout == null || cout_no >= cout.length) return 0;
tmp = get_stream_writer (cout[cout_no]);
if (tmp == null) return -1;
if (osw != StdAwk.stdout)
{
try { osw.close (); }
catch (IOException e) { /* ignore */ }
}
extio.setHandle (tmp);
try { setConsoleOutputName (extio, cout[cout_no]); }
catch (Exception e) { return -1;}
cout_no++;
return 1;
}
return -1;
}
private Reader get_stream_reader (String name)
{
Reader isr;
if (name == null || name.length() == 0) isr = StdAwk.stdin;
else
{
FileInputStream fis;
try { fis = new FileInputStream (name); }
catch (IOException e) { return null; }
isr = new BufferedReader(new InputStreamReader (fis));
}
return isr;
}
private Writer get_stream_writer (String name)
{
Writer osw;
if (name == null || name.length() == 0) osw = StdAwk.stdout;
else
{
FileOutputStream fos;
try { fos = new FileOutputStream (name); }
catch (IOException e) { return null; }
osw = new BufferedWriter (new OutputStreamWriter (fos));
}
return osw;
}
/* == file interface == */
protected int openFile (Extio extio)
{
int mode = extio.getMode();
if (mode == Extio.MODE_FILE_READ)
{
FileInputStream fis;
Reader isr;
try { fis = new FileInputStream (extio.getName()); }
catch (IOException e) { return -1; }
isr = new BufferedReader (new InputStreamReader (fis));
extio.setHandle (isr);
return 1;
}
else if (mode == Extio.MODE_FILE_WRITE)
{
FileOutputStream fos;
Writer osw;
try { fos = new FileOutputStream (extio.getName()); }
catch (IOException e) { return -1; }
osw = new BufferedWriter (new OutputStreamWriter (fos));
extio.setHandle (osw);
return 1;
}
else if (mode == Extio.MODE_FILE_APPEND)
{
FileOutputStream fos;
Writer osw;
try { fos = new FileOutputStream (extio.getName(), true); }
catch (IOException e) { return -1; }
osw = new BufferedWriter (new OutputStreamWriter (fos));
extio.setHandle (osw);
return 1;
}
return -1;
}
protected int closeFile (Extio extio)
{
int mode = extio.getMode();
if (mode == Extio.MODE_FILE_READ)
{
Reader isr;
isr = (Reader)extio.getHandle();
if (isr != StdAwk.stdin)
{
try { isr.close (); }
catch (IOException e) { return -1; }
}
return 0;
}
else if (mode == Extio.MODE_FILE_WRITE)
{
Writer osw;
osw = (Writer)extio.getHandle();
if (osw != StdAwk.stdout)
{
try { osw.close (); }
catch (IOException e) { return -1; }
}
return 0;
}
else if (mode == Extio.MODE_FILE_APPEND)
{
Writer osw;
osw = (Writer)extio.getHandle();
if (osw != StdAwk.stdout)
{
try { osw.close (); }
catch (IOException e) { return -1; }
}
return 0;
}
return -1;
}
protected int readFile (Extio extio, char[] buf, int len)
{
int mode = extio.getMode();
if (mode == Extio.MODE_FILE_READ)
{
Reader isr;
isr = (Reader)extio.getHandle();
try
{
len = isr.read (buf, 0, len);
if (len == -1) len = 0;
}
catch (IOException e) { len = -1; }
return len;
}
return -1;
}
protected int writeFile (Extio extio, char[] buf, int len)
{
int mode = extio.getMode();
if (mode == Extio.MODE_FILE_WRITE ||
mode == Extio.MODE_FILE_APPEND)
{
Writer osw;
osw = (Writer)extio.getHandle();
try { osw.write (buf, 0, len); }
catch (IOException e) { len = -1; }
return len;
}
return -1;
}
protected int flushFile (Extio extio)
{
int mode = extio.getMode ();
if (mode == Extio.MODE_FILE_WRITE ||
mode == Extio.MODE_FILE_APPEND)
{
Writer osw;
osw = (Writer)extio.getHandle ();
try { osw.flush (); }
catch (IOException e) { return -1; }
return 0;
}
return -1;
}
/* == pipe interface == */
protected int openPipe (Extio extio)
{
int mode = extio.getMode();
if (mode == Extio.MODE_PIPE_READ)
{
Process proc;
Reader isr;
try { proc = popen (extio.getName()); }
catch (IOException e) { return -1; }
isr = new BufferedReader (new InputStreamReader (proc.getInputStream()));
extio.setHandle (isr);
return 1;
}
else if (mode == Extio.MODE_PIPE_WRITE)
{
Process proc;
Writer osw;
try { proc = popen (extio.getName()); }
catch (IOException e) { return -1; }
osw = new BufferedWriter (new OutputStreamWriter (proc.getOutputStream()));
extio.setHandle (osw);
return 1;
}
return -1;
}
protected int closePipe (Extio extio)
{
int mode = extio.getMode();
if (mode == Extio.MODE_PIPE_READ)
{
Reader isr;
isr = (Reader)extio.getHandle();
if (isr != StdAwk.stdin)
{
try { isr.close (); }
catch (IOException e) { return -1; }
}
return 0;
}
else if (mode == Extio.MODE_PIPE_WRITE)
{
Writer osw;
osw = (Writer)extio.getHandle();
if (osw != StdAwk.stdout)
{
try { osw.close (); }
catch (IOException e) { return -1; }
}
return 0;
}
return -1;
}
protected int readPipe (Extio extio, char[] buf, int len)
{
int mode = extio.getMode();
if (mode == Extio.MODE_PIPE_READ)
{
Reader isr;
isr = (Reader)extio.getHandle();
try
{
len = isr.read (buf, 0, len);
if (len == -1) len = 0;
}
catch (IOException e) { len = -1; }
return len;
}
return -1;
}
protected int writePipe (Extio extio, char[] buf, int len)
{
int mode = extio.getMode();
if (mode == Extio.MODE_PIPE_WRITE)
{
Writer osw;
osw = (Writer)extio.getHandle();
try { osw.write (buf, 0, len); }
catch (IOException e) { len = -1; }
return len;
}
return -1;
}
protected int flushPipe (Extio extio)
{
int mode = extio.getMode ();
if (mode == Extio.MODE_PIPE_WRITE)
{
Writer osw;
osw = (Writer)extio.getHandle ();
try { osw.flush (); }
catch (IOException e) { return -1; }
return 0;
}
return -1;
}
/* == arithmetic built-in functions */
public Object bfn_sin (long runid, Object[] args) throws Exception
{
double x = builtinFunctionArgumentToDouble (runid, args[0]);
return new Double (Math.sin(x));
}
public Object bfn_cos (long runid, Object[] args) throws Exception
{
double x = builtinFunctionArgumentToDouble (runid, args[0]);
return new Double (Math.cos(x));
}
public Object bfn_tan (long runid, Object[] args) throws Exception
{
double x = builtinFunctionArgumentToDouble (runid, args[0]);
return new Double (Math.tan(x));
}
public Object bfn_atan2 (long runid, Object[] args) throws Exception
{
double y = builtinFunctionArgumentToDouble (runid, args[0]);
double x = builtinFunctionArgumentToDouble (runid, args[1]);
return new Double (Math.atan2(y,x));
}
public Object bfn_log (long runid, Object[] args) throws Exception
{
double x = builtinFunctionArgumentToDouble (runid, args[0]);
return new Double (Math.log(x));
}
public Object bfn_exp (long runid, Object[] args) throws Exception
{
double x = builtinFunctionArgumentToDouble (runid, args[0]);
return new Double (Math.exp(x));
}
public Object bfn_sqrt (long runid, Object[] args) throws Exception
{
double x = builtinFunctionArgumentToDouble (runid, args[0]);
return new Double (Math.sqrt(x));
}
public Object bfn_int (long runid, Object[] args) throws Exception
{
long x = builtinFunctionArgumentToLong (runid, args[0]);
return new Long (x);
}
public Object bfn_rand (long runid, Object[] args)
{
return new Double (random.nextDouble ());
}
public Object bfn_srand (long runid, Object[] args) throws Exception
{
long prev_seed = seed;
seed = (args == null || args.length == 0)?
System.currentTimeMillis ():
builtinFunctionArgumentToLong (runid, args[0]);
random.setSeed (seed);
return new Long (prev_seed);
}
public Object bfn_systime (long runid, Object[] args)
{
long msec = System.currentTimeMillis ();
return new Long (msec / 1000);
}
public Object bfn_strftime (long runid, Object[] args)
{
// TODO: implement this...
return null;
}
/* miscellaneous built-in functions */
public Object bfn_system (long runid, Object[] args) throws Exception
{
String str = builtinFunctionArgumentToString (runid, args[0]);
Process proc = null;
int n = 0;
str = builtinFunctionArgumentToString (runid, args[0]);
try { proc = popen (str); }
catch (IOException e) { n = -1; }
if (proc != null)
{
InputStream is;
byte[] buf = new byte[1024];
is = proc.getInputStream();
// TODO; better error handling... program execution.. io redirection???
try { while (is.read (buf) != -1) ; }
catch (IOException e) { n = -1; };
try { n = proc.waitFor (); }
catch (InterruptedException e)
{
proc.destroy ();
n = -1;
}
}
return new Long (n);
}
/* == utility functions == */
private Process popen (String command) throws IOException
{
String full;
/* TODO: consider OS names and versions */
full = System.getenv ("ComSpec");
if (full != null)
{
full = full + " /c " + command;
}
else
{
full = System.getenv ("SHELL");
if (full != null)
{
full = "/bin/sh -c \"" + command + "\"";
}
else full = command;
}
return Runtime.getRuntime().exec (full);
}
}

202
ase/awk/aseawk.dsp Normal file
View File

@ -0,0 +1,202 @@
# Microsoft Developer Studio Project File - Name="aseawk" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Static Library" 0x0104
CFG=aseawk - 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 "aseawk.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 "aseawk.mak" CFG="aseawk - Win32 Release"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "aseawk - Win32 Release" (based on "Win32 (x86) Static Library")
!MESSAGE "aseawk - 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)" == "aseawk - 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
# ADD LIB32 /nologo
!ELSEIF "$(CFG)" == "aseawk - 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
# ADD LIB32 /nologo
!ENDIF
# Begin Target
# Name "aseawk - Win32 Release"
# Name "aseawk - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\awk.c
# End Source File
# Begin Source File
SOURCE=.\err.c
# End Source File
# Begin Source File
SOURCE=.\extio.c
# End Source File
# Begin Source File
SOURCE=.\func.c
# End Source File
# Begin Source File
SOURCE=.\map.c
# End Source File
# Begin Source File
SOURCE=.\misc.c
# End Source File
# Begin Source File
SOURCE=.\parse.c
# End Source File
# Begin Source File
SOURCE=.\rec.c
# End Source File
# Begin Source File
SOURCE=.\rex.c
# End Source File
# Begin Source File
SOURCE=.\run.c
# End Source File
# Begin Source File
SOURCE=.\tab.c
# End Source File
# Begin Source File
SOURCE=.\tree.c
# End Source File
# Begin Source File
SOURCE=.\val.c
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\awk.h
# End Source File
# Begin Source File
SOURCE=.\awk_i.h
# End Source File
# Begin Source File
SOURCE=.\extio.h
# End Source File
# Begin Source File
SOURCE=.\func.h
# End Source File
# Begin Source File
SOURCE=.\map.h
# End Source File
# Begin Source File
SOURCE=.\parse.h
# End Source File
# Begin Source File
SOURCE=.\rex.h
# End Source File
# Begin Source File
SOURCE=.\run.h
# End Source File
# Begin Source File
SOURCE=.\tab.h
# End Source File
# Begin Source File
SOURCE=.\tree.h
# End Source File
# Begin Source File
SOURCE=.\val.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

521
ase/awk/aseawk.vcproj Normal file
View File

@ -0,0 +1,521 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="aseawk"
ProjectGUID="{5F2E77D5-1485-48D1-9371-987BC55FEE83}"
RootNamespace="aseawk"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Release|Win32"
OutputDirectory=".\..\release\lib"
IntermediateDirectory=".\release"
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"
PrecompiledHeaderFile=".\release/aseawk.pch"
AssemblerListingLocation=".\release/"
ObjectFile=".\release/"
ProgramDataBaseFileName=".\release/"
WarningLevel="3"
SuppressStartupBanner="true"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
OutputFile="$(OutDir)\aseawk.lib"
SuppressStartupBanner="true"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\../release/lib/aseawk.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\..\debug\lib"
IntermediateDirectory=".\debug"
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"
PrecompiledHeaderFile=".\debug/aseawk.pch"
AssemblerListingLocation=".\debug/"
ObjectFile=".\debug/"
ProgramDataBaseFileName=".\debug/"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
OutputFile="$(OutDir)\aseawk.lib"
SuppressStartupBanner="true"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\../debug/lib/aseawk.bsc"
/>
<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="awk.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="err.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="extio.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="func.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="map.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="misc.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="parse.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="rec.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="rex.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="run.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="tab.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="tree.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="val.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl"
>
<File
RelativePath="awk.h"
>
</File>
<File
RelativePath="awk_i.h"
>
</File>
<File
RelativePath="extio.h"
>
</File>
<File
RelativePath="func.h"
>
</File>
<File
RelativePath="map.h"
>
</File>
<File
RelativePath="parse.h"
>
</File>
<File
RelativePath="rex.h"
>
</File>
<File
RelativePath="run.h"
>
</File>
<File
RelativePath="tab.h"
>
</File>
<File
RelativePath="tree.h"
>
</File>
<File
RelativePath="val.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>

113
ase/awk/aseawk_jni.dsp Normal file
View File

@ -0,0 +1,113 @@
# Microsoft Developer Studio Project File - Name="aesawk_jni" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
CFG=aesawk_jni - Win32 Debug
!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 "aseawk_jni.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 "aseawk_jni.mak" CFG="aesawk_jni - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "aesawk_jni - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE "aesawk_jni - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "aesawk_jni - 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 ""
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "JNI_EXPORTS" /YX /FD /c
# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\.." /I "$(JAVA_HOME)\include" /I "$(JAVA_HOME)\include\win32" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_UNICODE" /D "_USRDLL" /FD /c
# SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
# ADD LINK32 asecmn.lib aseawk.lib aseutl.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /implib:"release/aseawk_jni.lib" /libpath:"$(OutDir)"
!ELSEIF "$(CFG)" == "aesawk_jni - 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 ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "JNI_EXPORTS" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "..\.." /I "$(JAVA_HOME)\include" /I "$(JAVA_HOME)\include\win32" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_UNICODE" /D "_USRDLL" /FD /GZ /c
# SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
# ADD LINK32 asecmn.lib aseawk.lib aseutl.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /implib:"debug/aseawk_jni.lib" /pdbtype:sept /libpath:"$(OutDir)"
!ENDIF
# Begin Target
# Name "aesawk_jni - Win32 Release"
# Name "aesawk_jni - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\jni.c
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\jni.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

258
ase/awk/aseawk_jni.vcproj Normal file
View File

@ -0,0 +1,258 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="aesawk_jni"
ProjectGUID="{23B58791-FD44-4F95-9F77-34E4AF45A296}"
RootNamespace="aesawk_jni"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Release|Win32"
OutputDirectory=".\..\release\lib"
IntermediateDirectory=".\release"
ConfigurationType="2"
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"
PreprocessorDefinitions="NDEBUG"
MkTypLibCompatible="true"
SuppressStartupBanner="true"
TargetEnvironment="1"
TypeLibraryName=".\../release/lib/aseawk_jni.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
AdditionalIncludeDirectories="..\..,$(JAVA_HOME)\include,$(JAVA_HOME)\include\win32"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL"
StringPooling="true"
RuntimeLibrary="0"
EnableFunctionLevelLinking="true"
PrecompiledHeaderFile=".\release/aseawk_jni.pch"
AssemblerListingLocation=".\release/"
ObjectFile=".\release/"
ProgramDataBaseFileName=".\release/"
WarningLevel="3"
SuppressStartupBanner="true"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="asecmn.lib aseawk.lib aseutl.lib odbc32.lib odbccp32.lib"
OutputFile="$(OutDir)\aseawk_jni.dll"
LinkIncremental="1"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="$(OutDir)"
ProgramDatabaseFile=".\../release/lib/aseawk_jni.pdb"
ImportLibrary="release/aseawk_jni.lib"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\../release/lib/aseawk_jni.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\..\debug\lib"
IntermediateDirectory=".\debug"
ConfigurationType="2"
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"
PreprocessorDefinitions="_DEBUG"
MkTypLibCompatible="true"
SuppressStartupBanner="true"
TargetEnvironment="1"
TypeLibraryName=".\../debug/lib/aseawk_jni.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..,$(JAVA_HOME)\include,$(JAVA_HOME)\include\win32"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
PrecompiledHeaderFile=".\debug/aseawk_jni.pch"
AssemblerListingLocation=".\debug/"
ObjectFile=".\debug/"
ProgramDataBaseFileName=".\debug/"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="asecmn.lib aseawk.lib aseutl.lib odbc32.lib odbccp32.lib"
OutputFile="$(OutDir)\aseawk_jni.dll"
LinkIncremental="2"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="$(OutDir)"
GenerateDebugInformation="true"
ProgramDatabaseFile=".\../debug/lib/aseawk_jni.pdb"
ImportLibrary="debug/aseawk_jni.lib"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\../debug/lib/aseawk_jni.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<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="jni.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl"
>
<File
RelativePath="jni.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>

256
ase/awk/awk.c Normal file
View File

@ -0,0 +1,256 @@
/*
* $Id: awk.c,v 1.3 2007/04/30 05:47:33 bacon Exp $
*
* {License}
*/
#if defined(__BORLANDC__)
#pragma hdrstop
#define Library
#endif
#include <ase/awk/awk_i.h>
static void free_afn (void* awk, void* afn);
ase_awk_t* ase_awk_open (const ase_awk_prmfns_t* prmfns, void* custom_data)
{
ase_awk_t* awk;
ASE_ASSERT (prmfns != ASE_NULL);
ASE_ASSERT (prmfns->mmgr.malloc != ASE_NULL &&
prmfns->mmgr.free != ASE_NULL);
ASE_ASSERT (prmfns->ccls.is_upper != ASE_NULL &&
prmfns->ccls.is_lower != ASE_NULL &&
prmfns->ccls.is_alpha != ASE_NULL &&
prmfns->ccls.is_digit != ASE_NULL &&
prmfns->ccls.is_xdigit != ASE_NULL &&
prmfns->ccls.is_alnum != ASE_NULL &&
prmfns->ccls.is_space != ASE_NULL &&
prmfns->ccls.is_print != ASE_NULL &&
prmfns->ccls.is_graph != ASE_NULL &&
prmfns->ccls.is_cntrl != ASE_NULL &&
prmfns->ccls.is_punct != ASE_NULL &&
prmfns->ccls.to_upper != ASE_NULL &&
prmfns->ccls.to_lower != ASE_NULL);
ASE_ASSERT (prmfns->misc.pow != ASE_NULL &&
prmfns->misc.sprintf != ASE_NULL &&
prmfns->misc.dprintf != ASE_NULL);
#if defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG)
awk = (ase_awk_t*) malloc (ASE_SIZEOF(ase_awk_t));
#else
awk = (ase_awk_t*) prmfns->mmgr.malloc (
prmfns->mmgr.custom_data, ASE_SIZEOF(ase_awk_t));
#endif
if (awk == ASE_NULL) return ASE_NULL;
/* it uses the built-in ase_awk_memset because awk is not
* fully initialized yet */
ase_memset (awk, 0, ASE_SIZEOF(ase_awk_t));
ase_memcpy (&awk->prmfns, prmfns, ASE_SIZEOF(awk->prmfns));
if (ase_str_open (
&awk->token.name, 128, &awk->prmfns.mmgr) == ASE_NULL)
{
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
/* TODO: initial map size?? */
if (ase_awk_map_open (
&awk->tree.afns, awk, 256, free_afn, awk) == ASE_NULL)
{
ase_str_close (&awk->token.name);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
if (ase_awk_tab_open (&awk->parse.globals, awk) == ASE_NULL)
{
ase_str_close (&awk->token.name);
ase_awk_map_close (&awk->tree.afns);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
if (ase_awk_tab_open (&awk->parse.locals, awk) == ASE_NULL)
{
ase_str_close (&awk->token.name);
ase_awk_map_close (&awk->tree.afns);
ase_awk_tab_close (&awk->parse.globals);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
if (ase_awk_tab_open (&awk->parse.params, awk) == ASE_NULL)
{
ase_str_close (&awk->token.name);
ase_awk_map_close (&awk->tree.afns);
ase_awk_tab_close (&awk->parse.globals);
ase_awk_tab_close (&awk->parse.locals);
ASE_AWK_FREE (awk, awk);
return ASE_NULL;
}
awk->option = 0;
awk->errnum = ASE_AWK_ENOERR;
awk->errlin = 0;
awk->parse.nlocals_max = 0;
awk->tree.nglobals = 0;
awk->tree.nbglobals = 0;
awk->tree.begin = ASE_NULL;
awk->tree.end = ASE_NULL;
awk->tree.chain = ASE_NULL;
awk->tree.chain_tail = ASE_NULL;
awk->tree.chain_size = 0;
awk->token.prev.type = 0;
awk->token.prev.line = 0;
awk->token.prev.column = 0;
awk->token.type = 0;
awk->token.line = 0;
awk->token.column = 0;
awk->src.lex.curc = ASE_CHAR_EOF;
awk->src.lex.ungotc_count = 0;
awk->src.lex.line = 1;
awk->src.lex.column = 1;
awk->src.shared.buf_pos = 0;
awk->src.shared.buf_len = 0;
awk->bfn.sys = ASE_NULL;
awk->bfn.user = ASE_NULL;
awk->parse.depth.cur.block = 0;
awk->parse.depth.cur.loop = 0;
awk->parse.depth.cur.expr = 0;
ase_awk_setmaxdepth (awk, ASE_AWK_DEPTH_BLOCK_PARSE, 0);
ase_awk_setmaxdepth (awk, ASE_AWK_DEPTH_BLOCK_RUN, 0);
ase_awk_setmaxdepth (awk, ASE_AWK_DEPTH_EXPR_PARSE, 0);
ase_awk_setmaxdepth (awk, ASE_AWK_DEPTH_EXPR_RUN, 0);
ase_awk_setmaxdepth (awk, ASE_AWK_DEPTH_REX_BUILD, 0);
ase_awk_setmaxdepth (awk, ASE_AWK_DEPTH_REX_MATCH, 0);
awk->custom_data = custom_data;
return awk;
}
static void free_afn (void* owner, void* afn)
{
ase_awk_afn_t* f = (ase_awk_afn_t*)afn;
/* f->name doesn't have to be freed */
/*ASE_AWK_FREE ((ase_awk_t*)owner, f->name);*/
ase_awk_clrpt ((ase_awk_t*)owner, f->body);
ASE_AWK_FREE ((ase_awk_t*)owner, f);
}
int ase_awk_close (ase_awk_t* awk)
{
ase_size_t i;
if (ase_awk_clear (awk) == -1) return -1;
ase_awk_clrbfn (awk);
ase_awk_map_close (&awk->tree.afns);
ase_awk_tab_close (&awk->parse.globals);
ase_awk_tab_close (&awk->parse.locals);
ase_awk_tab_close (&awk->parse.params);
ase_str_close (&awk->token.name);
for (i = 0; i < ASE_COUNTOF(awk->errstr); i++)
{
if (awk->errstr[i] != ASE_NULL)
{
ASE_AWK_FREE (awk, awk->errstr[i]);
awk->errstr[i] = ASE_NULL;
}
}
/* ASE_AWK_ALLOC, ASE_AWK_FREE, etc can not be used
* from the next line onwards */
ASE_AWK_FREE (awk, awk);
return 0;
}
int ase_awk_clear (ase_awk_t* awk)
{
ase_memset (&awk->src.ios, 0, ASE_SIZEOF(awk->src.ios));
awk->src.lex.curc = ASE_CHAR_EOF;
awk->src.lex.ungotc_count = 0;
awk->src.lex.line = 1;
awk->src.lex.column = 1;
awk->src.shared.buf_pos = 0;
awk->src.shared.buf_len = 0;
ase_awk_tab_clear (&awk->parse.globals);
ase_awk_tab_clear (&awk->parse.locals);
ase_awk_tab_clear (&awk->parse.params);
awk->parse.nlocals_max = 0;
awk->parse.depth.cur.block = 0;
awk->parse.depth.cur.loop = 0;
awk->parse.depth.cur.expr = 0;
/* clear parse trees */
awk->tree.ok = 0;
awk->tree.nbglobals = 0;
awk->tree.nglobals = 0;
awk->tree.cur_afn.ptr = ASE_NULL;
awk->tree.cur_afn.len = 0;
ase_awk_map_clear (&awk->tree.afns);
if (awk->tree.begin != ASE_NULL)
{
ASE_ASSERT (awk->tree.begin->next == ASE_NULL);
ase_awk_clrpt (awk, awk->tree.begin);
awk->tree.begin = ASE_NULL;
}
if (awk->tree.end != ASE_NULL)
{
ASE_ASSERT (awk->tree.end->next == ASE_NULL);
ase_awk_clrpt (awk, awk->tree.end);
awk->tree.end = ASE_NULL;
}
while (awk->tree.chain != ASE_NULL)
{
ase_awk_chain_t* next = awk->tree.chain->next;
if (awk->tree.chain->pattern != ASE_NULL)
ase_awk_clrpt (awk, awk->tree.chain->pattern);
if (awk->tree.chain->action != ASE_NULL)
ase_awk_clrpt (awk, awk->tree.chain->action);
ASE_AWK_FREE (awk, awk->tree.chain);
awk->tree.chain = next;
}
awk->tree.chain_tail = ASE_NULL;
awk->tree.chain_size = 0;
return 0;
}
int ase_awk_getoption (ase_awk_t* awk)
{
return awk->option;
}
void ase_awk_setoption (ase_awk_t* awk, int opt)
{
awk->option = opt;
}
void* ase_awk_getcustomdata (ase_awk_t* awk)
{
return awk->custom_data;
}

505
ase/awk/awk.h Normal file
View File

@ -0,0 +1,505 @@
/*
* $Id: awk.h,v 1.3 2007/04/30 05:47:33 bacon Exp $
*
* {License}
*/
#ifndef _ASE_AWK_AWK_H_
#define _ASE_AWK_AWK_H_
#include <ase/cmn/types.h>
#include <ase/cmn/macros.h>
typedef struct ase_awk_t ase_awk_t;
typedef struct ase_awk_run_t ase_awk_run_t;
typedef struct ase_awk_val_t ase_awk_val_t;
typedef struct ase_awk_map_t ase_awk_map_t;
typedef struct ase_awk_extio_t ase_awk_extio_t;
typedef struct ase_awk_prmfns_t ase_awk_prmfns_t;
typedef struct ase_awk_srcios_t ase_awk_srcios_t;
typedef struct ase_awk_runios_t ase_awk_runios_t;
typedef struct ase_awk_runcbs_t ase_awk_runcbs_t;
typedef struct ase_awk_runarg_t ase_awk_runarg_t;
typedef ase_real_t (*ase_awk_pow_t) (void* custom, ase_real_t x, ase_real_t y);
typedef int (*ase_awk_sprintf_t) (
void* custom, ase_char_t* buf, ase_size_t size,
const ase_char_t* fmt, ...);
typedef void (*ase_awk_dprintf_t) (void* custom, const ase_char_t* fmt, ...);
typedef ase_ssize_t (*ase_awk_io_t) (
int cmd, void* arg, ase_char_t* data, ase_size_t count);
struct ase_awk_extio_t
{
ase_awk_run_t* run; /* [IN] */
int type; /* [IN] console, file, coproc, pipe */
int mode; /* [IN] read, write, etc */
ase_char_t* name; /* [IN] */
void* custom_data; /* [IN] */
void* handle; /* [OUT] */
/* input */
struct
{
ase_char_t buf[2048];
ase_size_t pos;
ase_size_t len;
ase_bool_t eof;
ase_bool_t eos;
} in;
/* output */
struct
{
ase_bool_t eof;
ase_bool_t eos;
} out;
ase_awk_extio_t* next;
};
struct ase_awk_prmfns_t
{
ase_mmgr_t mmgr;
ase_ccls_t ccls;
struct
{
/* utilities */
ase_awk_pow_t pow; /* required */
ase_awk_sprintf_t sprintf; /* required */
ase_awk_dprintf_t dprintf; /* required in the debug mode */
/* user-defined data passed to the functions above */
void* custom_data; /* optional */
} misc;
};
struct ase_awk_srcios_t
{
ase_awk_io_t in;
ase_awk_io_t out;
void* custom_data;
};
struct ase_awk_runios_t
{
ase_awk_io_t pipe;
ase_awk_io_t coproc;
ase_awk_io_t file;
ase_awk_io_t console;
void* custom_data;
};
struct ase_awk_runcbs_t
{
void (*on_start) (
ase_awk_run_t* run, void* custom_data);
void (*on_statement) (
ase_awk_run_t* run, ase_size_t line, void* custom_data);
void (*on_return) (
ase_awk_run_t* run, ase_awk_val_t* ret, void* custom_data);
void (*on_end) (
ase_awk_run_t* run, int errnum, void* custom_data);
void* custom_data;
};
struct ase_awk_runarg_t
{
ase_char_t* ptr;
ase_size_t len;
};
/* io function commands */
enum
{
ASE_AWK_IO_OPEN = 0,
ASE_AWK_IO_CLOSE = 1,
ASE_AWK_IO_READ = 2,
ASE_AWK_IO_WRITE = 3,
ASE_AWK_IO_FLUSH = 4,
ASE_AWK_IO_NEXT = 5
};
/* various options */
enum
{
/* allow undeclared variables and implicit concatenation */
ASE_AWK_IMPLICIT = (1 << 0),
/* allow explicit variable declaration and the concatenation
* operator, a period. */
ASE_AWK_EXPLICIT = (1 << 1),
/* a function name should not coincide to be a variable name */
ASE_AWK_UNIQUEFN = (1 << 2),
/* allow variable shading */
ASE_AWK_SHADING = (1 << 3),
/* support shift operators */
ASE_AWK_SHIFT = (1 << 4),
/* enable the idiv operator (double slashes) */
ASE_AWK_IDIV = (1 << 5),
/* support string concatenation in tokenization.
* this option can change the behavior of a certain construct.
* getline < "abc" ".def" is treated as if it is getline < "abc.def"
* when this option is on. If this option is off, the same expression
* is treated as if it is (getline < "abc") ".def". */
ASE_AWK_STRCONCAT = (1 << 6),
/* support getline and print */
ASE_AWK_EXTIO = (1 << 7),
/* support co-process */
ASE_AWK_COPROC = (1 << 8),
/* support blockless patterns */
ASE_AWK_BLOCKLESS = (1 << 9),
/* use 1 as the start index for string operations */
ASE_AWK_STRBASEONE = (1 << 10),
/* strip off leading and trailing spaces when splitting a record
* into fields with a regular expression.
*
* Consider the following program.
* BEGIN { FS="[:[:space:]]+"; }
* {
* print "NF=" NF;
* for (i = 0; i < NF; i++) print i " [" $(i+1) "]";
* }
*
* The program splits " a b c " into [a], [b], [c] when this
* option is on while into [], [a], [b], [c], [] when it is off.
*/
ASE_AWK_STRIPSPACES = (1 << 11),
/* enable the nextoutfile keyword */
ASE_AWK_NEXTOFILE = (1 << 12),
/* cr + lf by default */
ASE_AWK_CRLF = (1 << 13),
/* pass the arguments to the main function */
ASE_AWK_ARGSTOMAIN = (1 << 14)
};
/* error code */
enum
{
ASE_AWK_ENOERR, /* no error */
ASE_AWK_EINVAL, /* invalid parameter */
ASE_AWK_ENOMEM, /* out of memory */
ASE_AWK_ENOSUP, /* not supported */
ASE_AWK_ENOPER, /* operation not allowed */
ASE_AWK_ENODEV, /* function '%.*s' not found */
ASE_AWK_ENOSPC, /* no space left on device */
ASE_AWK_EMFILE, /* too many open files */
ASE_AWK_EMLINK, /* too many links */
ASE_AWK_EAGAIN, /* resource temporarily unavailable */
ASE_AWK_ENOENT, /* file or data not existing */
ASE_AWK_EEXIST, /* file or data exists */
ASE_AWK_EFTBIG, /* file or data too big */
ASE_AWK_ETBUSY, /* system too busy */
ASE_AWK_EISDIR, /* is a directory */
ASE_AWK_EIOERR, /* i/o error */
ASE_AWK_EOPEN, /* cannot open */
ASE_AWK_EREAD, /* cannot read */
ASE_AWK_EWRITE, /* cannot write */
ASE_AWK_ECLOSE, /* cannot close */
ASE_AWK_EINTERN, /* internal error */
ASE_AWK_ERUNTIME, /* run-time error */
ASE_AWK_EBLKNST, /* blocke nested too deeply */
ASE_AWK_EEXPRNST, /* expression nested too deeply */
ASE_AWK_ESINOP,
ASE_AWK_ESINCL,
ASE_AWK_ESINRD,
ASE_AWK_ESOUTOP,
ASE_AWK_ESOUTCL,
ASE_AWK_ESOUTWR,
ASE_AWK_ELXCHR, /* lexer came accross an wrong character */
ASE_AWK_ELXUNG, /* lexer failed to unget a character */
ASE_AWK_EENDSRC, /* unexpected end of source */
ASE_AWK_EENDCMT, /* a comment not closed properly */
ASE_AWK_EENDSTR, /* a string not closed with a quote */
ASE_AWK_EENDREX, /* unexpected end of a regular expression */
ASE_AWK_ELBRACE, /* left brace expected */
ASE_AWK_ELPAREN, /* left parenthesis expected */
ASE_AWK_ERPAREN, /* right parenthesis expected */
ASE_AWK_ERBRACK, /* right bracket expected */
ASE_AWK_ECOMMA, /* comma expected */
ASE_AWK_ESCOLON, /* semicolon expected */
ASE_AWK_ECOLON, /* colon expected */
ASE_AWK_ESTMEND, /* statement not ending with a semicolon */
ASE_AWK_EIN, /* keyword 'in' is expected */
ASE_AWK_ENOTVAR, /* not a variable name after 'in' */
ASE_AWK_EEXPRES, /* expression expected */
ASE_AWK_EWHILE, /* keyword 'while' is expected */
ASE_AWK_EASSIGN, /* assignment statement expected */
ASE_AWK_EIDENT, /* identifier expected */
ASE_AWK_EFNNAME, /* not a valid function name */
ASE_AWK_EBLKBEG, /* BEGIN requires an action block */
ASE_AWK_EBLKEND, /* END requires an action block */
ASE_AWK_EDUPBEG, /* duplicate BEGIN */
ASE_AWK_EDUPEND, /* duplicate END */
ASE_AWK_EBFNRED, /* builtin function redefined */
ASE_AWK_EAFNRED, /* function redefined */
ASE_AWK_EGBLRED, /* global variable redefined */
ASE_AWK_EPARRED, /* parameter redefined */
ASE_AWK_EDUPPAR, /* duplicate parameter name */
ASE_AWK_EDUPGBL, /* duplicate global variable name */
ASE_AWK_EDUPLCL, /* duplicate local variable name */
ASE_AWK_EBADPAR, /* not a valid parameter name */
ASE_AWK_EBADVAR, /* not a valid variable name */
ASE_AWK_EUNDEF, /* undefined identifier */
ASE_AWK_ELVALUE, /* l-value required */
ASE_AWK_EGBLTM, /* too many global variables */
ASE_AWK_ELCLTM, /* too many local variables */
ASE_AWK_EPARTM, /* too many parameters */
ASE_AWK_EDELETE, /* delete not followed by a variable */
ASE_AWK_EBREAK, /* break outside a loop */
ASE_AWK_ECONTINUE, /* continue outside a loop */
ASE_AWK_ENEXTBEG, /* next illegal in BEGIN block */
ASE_AWK_ENEXTEND, /* next illegal in END block */
ASE_AWK_ENEXTFBEG, /* nextfile illegal in BEGIN block */
ASE_AWK_ENEXTFEND, /* nextfile illegal in END block */
ASE_AWK_EPRINTFARG, /* printf not followed by any arguments */
ASE_AWK_EPREPST, /* both prefix and postfix increment/decrement
operator present */
ASE_AWK_EGLNCPS, /* coprocess not supported by getline */
/* run time error */
ASE_AWK_EDIVBY0, /* divide by zero */
ASE_AWK_EOPERAND, /* invalid operand */
ASE_AWK_EPOSIDX, /* wrong position index */
ASE_AWK_EARGTF, /* too few arguments */
ASE_AWK_EARGTM, /* too many arguments */
ASE_AWK_EFNNONE, /* no such function */
ASE_AWK_ENOTIDX, /* variable not indexable */
ASE_AWK_ENOTDEL, /* variable not deletable */
ASE_AWK_ENOTMAP, /* value not a map */
ASE_AWK_ENOTMAPIN, /* right-hand side of 'in' not a map */
ASE_AWK_ENOTMAPNILIN, /* right-hand side of 'in' not a map nor nil */
ASE_AWK_ENOTREF, /* value not referenceable */
ASE_AWK_ENOTASS, /* value not assignable */
ASE_AWK_EIDXVALASSMAP, /* indexed value cannot be assigned a map */
ASE_AWK_EPOSVALASSMAP, /* a positional cannot be assigned a map */
ASE_AWK_EMAPTOSCALAR, /* cannot change a map to a scalar value */
ASE_AWK_ESCALARTOMAP, /* cannot change a scalar value to a map */
ASE_AWK_EMAPNOTALLOWED, /* a map is not allowed */
ASE_AWK_EVALTYPE, /* wrong value type */
ASE_AWK_ERDELETE, /* delete called with a wrong target */
ASE_AWK_ERNEXTBEG, /* next called from BEGIN */
ASE_AWK_ERNEXTEND, /* next called from END */
ASE_AWK_ERNEXTFBEG, /* nextfile called from BEGIN */
ASE_AWK_ERNEXTFEND, /* nextfile called from END */
ASE_AWK_EBFNUSER, /* wrong builtin function implementation */
ASE_AWK_EBFNIMPL, /* builtin function handler failed */
ASE_AWK_EIOUSER, /* wrong user io handler implementation */
ASE_AWK_EIONONE, /* no such io name found */
ASE_AWK_EIOIMPL, /* i/o callback returned an error */
ASE_AWK_EIONMEM, /* i/o name empty */
ASE_AWK_EIONMNL, /* i/o name contains '\0' */
ASE_AWK_EFMTARG, /* arguments to format string not sufficient */
ASE_AWK_EFMTCNV, /* recursion detected in format conversion */
ASE_AWK_ECONVFMTCHR, /* an invalid character found in CONVFMT */
ASE_AWK_EOFMTCHR, /* an invalid character found in OFMT */
/* regular expression error */
ASE_AWK_EREXRECUR, /* recursion too deep */
ASE_AWK_EREXRPAREN, /* a right parenthesis is expected */
ASE_AWK_EREXRBRACKET, /* a right bracket is expected */
ASE_AWK_EREXRBRACE, /* a right brace is expected */
ASE_AWK_EREXUNBALPAR, /* unbalanced parenthesis */
ASE_AWK_EREXCOLON, /* a colon is expected */
ASE_AWK_EREXCRANGE, /* invalid character range */
ASE_AWK_EREXCCLASS, /* invalid character class */
ASE_AWK_EREXBRANGE, /* invalid boundary range */
ASE_AWK_EREXEND, /* unexpected end of the pattern */
ASE_AWK_EREXGARBAGE, /* garbage after the pattern */
/* the number of error numbers, internal use only */
ASE_AWK_NUMERRNUM
};
/* depth types */
enum ase_awk_depth_t
{
ASE_AWK_DEPTH_BLOCK_PARSE = (1 << 0),
ASE_AWK_DEPTH_BLOCK_RUN = (1 << 1),
ASE_AWK_DEPTH_EXPR_PARSE = (1 << 2),
ASE_AWK_DEPTH_EXPR_RUN = (1 << 3),
ASE_AWK_DEPTH_REX_BUILD = (1 << 4),
ASE_AWK_DEPTH_REX_MATCH = (1 << 5)
};
/* extio types */
enum ase_awk_extio_type_t
{
/* extio types available */
ASE_AWK_EXTIO_PIPE,
ASE_AWK_EXTIO_COPROC,
ASE_AWK_EXTIO_FILE,
ASE_AWK_EXTIO_CONSOLE,
/* reserved for internal use only */
ASE_AWK_EXTIO_NUM
};
enum
{
ASE_AWK_EXTIO_PIPE_READ = 0,
ASE_AWK_EXTIO_PIPE_WRITE = 1,
/*
ASE_AWK_EXTIO_COPROC_READ = 0,
ASE_AWK_EXTIO_COPROC_WRITE = 1,
ASE_AWK_EXTIO_COPROC_RDWR = 2,
*/
ASE_AWK_EXTIO_FILE_READ = 0,
ASE_AWK_EXTIO_FILE_WRITE = 1,
ASE_AWK_EXTIO_FILE_APPEND = 2,
ASE_AWK_EXTIO_CONSOLE_READ = 0,
ASE_AWK_EXTIO_CONSOLE_WRITE = 1
};
#ifdef __cplusplus
extern "C" {
#endif
ase_awk_t* ase_awk_open (const ase_awk_prmfns_t* prmfns, void* custom_data);
int ase_awk_close (ase_awk_t* awk);
int ase_awk_clear (ase_awk_t* awk);
void* ase_awk_getcustomdata (ase_awk_t* awk);
const ase_char_t* ase_awk_geterrstr (ase_awk_t* awk, int num);
int ase_awk_seterrstr (ase_awk_t* awk, int num, const ase_char_t* str);
int ase_awk_geterrnum (ase_awk_t* awk);
ase_size_t ase_awk_geterrlin (ase_awk_t* awk);
const ase_char_t* ase_awk_geterrmsg (ase_awk_t* awk);
void ase_awk_seterrnum (ase_awk_t* awk, int errnum);
void ase_awk_geterror (
ase_awk_t* awk, int* errnum,
ase_size_t* errlin, const ase_char_t** errmsg);
void ase_awk_seterror (
ase_awk_t* awk, int errnum, ase_size_t errlin,
const ase_cstr_t* errarg, ase_size_t argcnt);
int ase_awk_getoption (ase_awk_t* awk);
void ase_awk_setoption (ase_awk_t* awk, int opt);
ase_size_t ase_awk_getmaxdepth (ase_awk_t* awk, int type);
void ase_awk_setmaxdepth (ase_awk_t* awk, int types, ase_size_t depth);
int ase_awk_parse (ase_awk_t* awk, ase_awk_srcios_t* srcios);
/*
* ase_awk_run return 0 on success and -1 on failure, generally speaking.
* A runtime context is required for it to start running the program.
* Once the runtime context is created, the program starts to run.
* The context creation failure is reported by the return value -1 of
* this function. however, the runtime error after the context creation
* is reported differently depending on the use of the callback.
* When no callback is specified (i.e. runcbs is ASE_NULL), ase_awk_run
* returns -1 on an error and awk->errnum is set accordingly.
* However, if a callback is specified (i.e. runcbs is not ASE_NULL),
* ase_awk_run returns 0 on both success and failure. Instead, the
* on_end handler of the callback is triggered with the relevant
* error number. The third parameter to on_end denotes this error number.
*/
int ase_awk_run (
ase_awk_t* awk, const ase_char_t* main,
ase_awk_runios_t* runios, ase_awk_runcbs_t* runcbs,
ase_awk_runarg_t* runarg, void* custom_data);
int ase_awk_stop (ase_awk_run_t* run);
/* functions to access internal stack structure */
ase_size_t ase_awk_getnargs (ase_awk_run_t* run);
ase_awk_val_t* ase_awk_getarg (ase_awk_run_t* run, ase_size_t idx);
ase_awk_val_t* ase_awk_getglobal (ase_awk_run_t* run, ase_size_t idx);
int ase_awk_setglobal (ase_awk_run_t* run, ase_size_t idx, ase_awk_val_t* val);
void ase_awk_setretval (ase_awk_run_t* run, ase_awk_val_t* val);
int ase_awk_setfilename (
ase_awk_run_t* run, const ase_char_t* name, ase_size_t len);
int ase_awk_setofilename (
ase_awk_run_t* run, const ase_char_t* name, ase_size_t len);
ase_awk_t* ase_awk_getrunawk (ase_awk_run_t* awk);
void* ase_awk_getruncustomdata (ase_awk_run_t* awk);
ase_awk_map_t* ase_awk_getrunnamedvarmap (ase_awk_run_t* awk);
/* functions to manipulate the run-time error */
int ase_awk_getrunerrnum (ase_awk_run_t* run);
ase_size_t ase_awk_getrunerrlin (ase_awk_run_t* run);
const ase_char_t* ase_awk_getrunerrmsg (ase_awk_run_t* run);
void ase_awk_setrunerrnum (ase_awk_run_t* run, int errnum);
void ase_awk_getrunerror (
ase_awk_run_t* run, int* errnum,
ase_size_t* errlin, const ase_char_t** errmsg);
void ase_awk_setrunerror (
ase_awk_run_t* run, int errnum, ase_size_t errlin,
const ase_cstr_t* errarg, ase_size_t argcnt);
/* functions to manipulate built-in functions */
void* ase_awk_addbfn (
ase_awk_t* awk, const ase_char_t* name, ase_size_t name_len,
int when_valid, ase_size_t min_args, ase_size_t max_args,
const ase_char_t* arg_spec,
int (*handler)(ase_awk_run_t*,const ase_char_t*,ase_size_t));
int ase_awk_delbfn (
ase_awk_t* awk, const ase_char_t* name, ase_size_t name_len);
void ase_awk_clrbfn (ase_awk_t* awk);
/* record and field functions */
int ase_awk_clrrec (ase_awk_run_t* run, ase_bool_t skip_inrec_line);
int ase_awk_setrec (ase_awk_run_t* run, ase_size_t idx, const ase_char_t* str, ase_size_t len);
/* utility functions exported by awk.h */
void* ase_awk_malloc (ase_awk_t* awk, ase_size_t size);
void ase_awk_free (ase_awk_t* awk, void* ptr);
ase_long_t ase_awk_strxtolong (
ase_awk_t* awk, const ase_char_t* str, ase_size_t len,
int base, const ase_char_t** endptr);
ase_real_t ase_awk_strxtoreal (
ase_awk_t* awk, const ase_char_t* str, ase_size_t len,
const ase_char_t** endptr);
ase_size_t ase_awk_longtostr (
ase_long_t value, int radix, const ase_char_t* prefix,
ase_char_t* buf, ase_size_t size);
#ifdef __cplusplus
}
#endif
#endif

71
ase/awk/awk.txt Normal file
View File

@ -0,0 +1,71 @@
Programs
pattern { action }
function name (parameter-list) { statement }
Patterns
BEGIN
END
expresion
/regular expression/
pattern && pattern
pattern || pattern
!pattern
(pattern)
pattern, pattern -> range pattern
Actions
break
continue
delete array-element
do statement while (expression)
exit [expression]
expression
if (expression) statement [else statement]
input-output statement
for (expression; expression; expression) statement
for (variable in array) statement
next
return [expression]
while (expression) statement
{ statements }
Variables
global variables (enabled when awk->opt & XP_AWK_OPT_VARDCL)
global x;
global x, y;
local variables (enabled when awk->opt & XP_AWK_OPT_VARDCL)
local x;
local x, y;
function arguments (enabled always)
function funca (x, y)
local variables in function declaration (enabled when awk->opt & XP_AWK_OPT_FUNCLOCAL)
function funca (x, y, v1, v2)
variables without any declarations (enabled when awk->opt & XP_AWK_OPT_NAMEDVAR)
x = 10; // x is put into the global hash table.
Optimization
constant folding
2 * 10 => 20
loop
remove while (0) { ... }
if
remove if (0) {}
use else_part only

338
ase/awk/awk_i.h Normal file
View File

@ -0,0 +1,338 @@
/*
* $Id: awk_i.h,v 1.3 2007/04/30 05:47:33 bacon Exp $
*
* {License}
*/
#ifndef _ASE_AWK_AWKI_H_
#define _ASE_AWK_AWKI_H_
#include <ase/cmn/mem.h>
#include <ase/cmn/str.h>
typedef struct ase_awk_chain_t ase_awk_chain_t;
typedef struct ase_awk_tree_t ase_awk_tree_t;
#include <ase/awk/awk.h>
#include <ase/awk/rex.h>
#include <ase/awk/map.h>
#include <ase/awk/tree.h>
#include <ase/awk/val.h>
#include <ase/awk/func.h>
#include <ase/awk/tab.h>
#include <ase/awk/parse.h>
#include <ase/awk/run.h>
#include <ase/awk/extio.h>
#include <ase/awk/misc.h>
#ifdef _MSC_VER
#pragma warning (disable: 4996)
#pragma warning (disable: 4296)
#endif
#define ASE_AWK_MAX_GLOBALS 9999
#define ASE_AWK_MAX_LOCALS 9999
#define ASE_AWK_MAX_PARAMS 9999
#if defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG)
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#define ASE_AWK_MALLOC(awk,size) malloc (size)
#define ASE_AWK_REALLOC(awk,ptr,size) realloc (ptr, size)
#define ASE_AWK_FREE(awk,ptr) free (ptr)
#else
#define ASE_AWK_MALLOC(awk,size) ASE_MALLOC(&(awk)->prmfns.mmgr,size)
#define ASE_AWK_REALLOC(awk,ptr,size) ASE_REALLOC(&(awk)->prmfns.mmgr,ptr,size)
#define ASE_AWK_FREE(awk,ptr) ASE_FREE(&(awk)->prmfns.mmgr,ptr)
#endif
#define ASE_AWK_ISUPPER(awk,c) ASE_ISUPPER(&(awk)->prmfns.ccls,c)
#define ASE_AWK_ISLOWER(awk,c) ASE_ISLOWER(&(awk)->prmfns.ccls,c)
#define ASE_AWK_ISALPHA(awk,c) ASE_ISALPHA(&(awk)->prmfns.ccls,c)
#define ASE_AWK_ISDIGIT(awk,c) ASE_ISDIGIT(&(awk)->prmfns.ccls,c)
#define ASE_AWK_ISXDIGIT(awk,c) ASE_ISXDIGIT(&(awk)->prmfns.ccls,c)
#define ASE_AWK_ISALNUM(awk,c) ASE_ISALNUM(&(awk)->prmfns.ccls,c)
#define ASE_AWK_ISSPACE(awk,c) ASE_ISSPACE(&(awk)->prmfns.ccls,c)
#define ASE_AWK_ISPRINT(awk,c) ASE_ISPRINT(&(awk)->prmfns.ccls,c)
#define ASE_AWK_ISGRAPH(awk,c) ASE_ISGRAPH(&(awk)->prmfns.ccls,c)
#define ASE_AWK_ISCNTRL(awk,c) ASE_ISCNTRL(&(awk)->prmfns.ccls,c)
#define ASE_AWK_ISPUNCT(awk,c) ASE_ISPUNCT(&(awk)->prmfns.ccls,c)
#define ASE_AWK_TOUPPER(awk,c) ASE_TOUPPER(&(awk)->prmfns.ccls,c)
#define ASE_AWK_TOLOWER(awk,c) ASE_TOLOWER(&(awk)->prmfns.ccls,c)
struct ase_awk_tree_t
{
ase_size_t nglobals; /* total number of globals */
ase_size_t nbglobals; /* number of builtin globals */
ase_cstr_t cur_afn;
ase_awk_map_t afns; /* awk function map */
ase_awk_nde_t* begin;
ase_awk_nde_t* end;
ase_awk_chain_t* chain;
ase_awk_chain_t* chain_tail;
ase_size_t chain_size; /* number of nodes in the chain */
int ok;
};
struct ase_awk_t
{
ase_awk_prmfns_t prmfns;
void* custom_data;
/* options */
int option;
/* parse tree */
ase_awk_tree_t tree;
/* temporary information that the parser needs */
struct
{
struct
{
int block;
int loop;
int stmnt; /* statement */
} id;
struct
{
struct
{
ase_size_t block;
ase_size_t loop;
ase_size_t expr; /* expression */
} cur;
struct
{
ase_size_t block;
ase_size_t expr;
} max;
} depth;
ase_awk_tab_t globals;
ase_awk_tab_t locals;
ase_awk_tab_t params;
ase_size_t nlocals_max;
ase_awk_nde_t* (*parse_block) (
ase_awk_t*,ase_size_t,ase_bool_t);
} parse;
/* source code management */
struct
{
ase_awk_srcios_t ios;
struct
{
ase_cint_t curc;
ase_cint_t ungotc[5];
ase_size_t ungotc_line[5];
ase_size_t ungotc_column[5];
ase_size_t ungotc_count;
ase_size_t line;
ase_size_t column;
} lex;
struct
{
ase_char_t buf[512];
ase_size_t buf_pos;
ase_size_t buf_len;
} shared;
} src;
/* token */
struct
{
struct
{
int type;
ase_size_t line;
ase_size_t column;
} prev;
int type;
ase_str_t name;
ase_size_t line;
ase_size_t column;
} token;
/* builtin functions */
struct
{
ase_awk_bfn_t* sys;
ase_awk_bfn_t* user;
} bfn;
struct
{
struct
{
struct
{
ase_size_t block;
ase_size_t expr;
} max;
} depth;
} run;
struct
{
struct
{
struct
{
ase_size_t build;
ase_size_t match;
} max;
} depth;
} rex;
struct
{
ase_char_t fmt[1024];
} tmp;
/* housekeeping */
int errnum;
ase_size_t errlin;
ase_char_t errmsg[256];
ase_char_t* errstr[ASE_AWK_NUMERRNUM];
};
struct ase_awk_chain_t
{
ase_awk_nde_t* pattern;
ase_awk_nde_t* action;
ase_awk_chain_t* next;
};
struct ase_awk_run_t
{
int id;
ase_awk_map_t named;
void** stack;
ase_size_t stack_top;
ase_size_t stack_base;
ase_size_t stack_limit;
int exit_level;
ase_awk_val_int_t* icache[200]; /* TODO: choose the optimal size */
ase_awk_val_real_t* rcache[200]; /* TODO: choose the optimal size */
ase_awk_val_ref_t* fcache[200]; /* TODO: choose the optimal size */
ase_size_t icache_count;
ase_size_t rcache_count;
ase_size_t fcache_count;
ase_awk_nde_blk_t* active_block;
ase_byte_t* pattern_range_state;
struct
{
ase_char_t buf[1024];
ase_size_t buf_pos;
ase_size_t buf_len;
ase_bool_t eof;
ase_str_t line;
ase_awk_val_t* d0; /* $0 */
ase_size_t maxflds;
ase_size_t nflds; /* NF */
struct
{
ase_char_t* ptr;
ase_size_t len;
ase_awk_val_t* val; /* $1 .. $NF */
}* flds;
} inrec;
struct
{
void* rs;
void* fs;
int ignorecase;
ase_size_t fnr;
struct
{
ase_char_t* ptr;
ase_size_t len;
} convfmt;
struct
{
ase_char_t* ptr;
ase_size_t len;
} ofmt;
struct
{
ase_char_t* ptr;
ase_size_t len;
} ofs;
struct
{
ase_char_t* ptr;
ase_size_t len;
} ors;
struct
{
ase_char_t* ptr;
ase_size_t len;
} subsep;
} global;
/* extio chain */
struct
{
ase_awk_io_t handler[ASE_AWK_EXTIO_NUM];
void* custom_data;
ase_awk_extio_t* chain;
} extio;
struct
{
ase_str_t fmt;
ase_str_t out;
struct
{
ase_char_t* ptr;
ase_size_t len; /* length */
ase_size_t inc; /* increment */
} tmp;
} format;
struct
{
struct
{
ase_size_t block;
ase_size_t expr; /* expression */
} cur;
struct
{
ase_size_t block;
ase_size_t expr;
} max;
} depth;
int errnum;
ase_size_t errlin;
ase_char_t errmsg[256];
void* custom_data;
ase_awk_t* awk;
ase_awk_runcbs_t* cbs;
};
#endif

28
ase/awk/descrip.mms Normal file
View File

@ -0,0 +1,28 @@
#
# OpenVMS MMS/MMK
#
objects = awk.obj,err.obj,tree.obj,str.obj,tab.obj,map.obj,parse.obj,run.obj,rec.obj,val.obj,func.obj,misc.obj,extio.obj,rex.obj
CFLAGS = /include="../.."
#CFLAGS = /pointer_size=long /include="../.."
LIBRFLAGS =
aseawk.olb : $(objects)
$(LIBR)/create $(MMS$TARGET) $(objects)
# $(LIBR)/replace $(LIBRFLAGS) $(MMS$TARGET),$(objects)
awk.obj depends_on awk.c
err.obj depends_on err.c
tree.obj depends_on tree.c
str.obj depends_on str.c
tab.obj depends_on tab.c
map.obj depends_on map.c
parse.obj depends_on parse.c
run.obj depends_on run.c
rec.obj depends_on rec.c
val.obj depends_on val.c
func.obj depends_on func.c
misc.obj depends_on misc.c
extio.obj depends_on extio.c
rex.obj depends_on rex.c

466
ase/awk/err.c Normal file
View File

@ -0,0 +1,466 @@
/*
* $Id: err.c,v 1.3 2007/04/30 05:47:33 bacon Exp $
*
* {License}
*/
#include <ase/awk/awk_i.h>
static const ase_char_t* __geterrstr (int errnum)
{
static const ase_char_t* errstr[] =
{
ASE_T("no error"),
ASE_T("invalid parameter"),
ASE_T("out of memory"),
ASE_T("not supported"),
ASE_T("operation not allowed"),
ASE_T("no such device"),
ASE_T("no space left on device"),
ASE_T("too many open files"),
ASE_T("too many links"),
ASE_T("resource temporarily unavailable"),
ASE_T("'%.*s' not existing"),
ASE_T("'%.*s' already exists"),
ASE_T("file or data too big"),
ASE_T("system too busy"),
ASE_T("is a directory"),
ASE_T("i/o error"),
ASE_T("cannot open '%.*s'"),
ASE_T("cannot read '%.*s'"),
ASE_T("cannot write '%.*s'"),
ASE_T("cannot close '%.*s'"),
ASE_T("internal error that should never have happened"),
ASE_T("general run-time error"),
ASE_T("block nested too deeply"),
ASE_T("expressio nested too deeply"),
ASE_T("cannot open source input"),
ASE_T("cannot close source input"),
ASE_T("cannot read source input"),
ASE_T("cannot open source output"),
ASE_T("cannot close source output"),
ASE_T("cannot write source output"),
ASE_T("invalid character '%.*s'"),
ASE_T("cannot unget character"),
ASE_T("unexpected end of source"),
ASE_T("a comment not closed properly"),
ASE_T("a string not closed with a quote"),
ASE_T("unexpected end of a regular expression"),
ASE_T("a left brace expected n place of '%.*s'"),
ASE_T("a left parenthesis expected in place of '%.*s'"),
ASE_T("a right parenthesis expected in place of '%.*s'"),
ASE_T("a right bracket expected in place of '%.*s'"),
ASE_T("a comma expected in place of '%.*s'"),
ASE_T("a semicolon expected in place of '%.*s'"),
ASE_T("a colon expected in place of '%.*s'"),
ASE_T("statement not ending with a semicolon"),
ASE_T("'in' expected in place of '%.*s'"),
ASE_T("right-hand side of the 'in' operator not a variable"),
ASE_T("invalid expression"),
ASE_T("keyword 'while' expected in place of '%.*s'"),
ASE_T("invalid assignment statement"),
ASE_T("an identifier expected in place of '%.*s'"),
ASE_T("'%.*s' not a valid function name"),
ASE_T("BEGIN not followed by a left bracket on the same line"),
ASE_T("END not followed by a left bracket on the same line"),
ASE_T("duplicate BEGIN"),
ASE_T("duplicate END"),
ASE_T("built-in function '%.*s' redefined"),
ASE_T("function '%.*s' redefined"),
ASE_T("global variable '%.*s' redefined"),
ASE_T("parameter '%.*s' redefined"),
ASE_T("duplicate parameter name '%.*s'"),
ASE_T("duplicate global variable '%.*s'"),
ASE_T("duplicate local variable '%.*s'"),
ASE_T("'%.*s' not a valid parameter name"),
ASE_T("'%.*s' not a valid variable name"),
ASE_T("undefined identifier '%.*s'"),
ASE_T("l-value required"),
ASE_T("too many global variables"),
ASE_T("too many local variables"),
ASE_T("too many parameters"),
ASE_T("delete statement not followed by a normal variable"),
ASE_T("break statement outside a loop"),
ASE_T("continue statement outside a loop"),
ASE_T("next statement illegal in the BEGIN block"),
ASE_T("next statement illegal in the END block"),
ASE_T("nextfile statement illegal in the BEGIN block"),
ASE_T("nextfile statement illegal in the END block"),
ASE_T("printf not followed by any arguments"),
ASE_T("both prefix and postfix increment/decrement operator present"),
ASE_T("coprocess not supported by getline"),
ASE_T("divide by zero"),
ASE_T("invalid operand"),
ASE_T("wrong position index"),
ASE_T("too few arguments"),
ASE_T("too many arguments"),
ASE_T("function '%.*s' not found"),
ASE_T("variable not indexable"),
ASE_T("variable '%.*s' not deletable"),
ASE_T("value not a map"),
ASE_T("right-hand side of the 'in' operator not a map"),
ASE_T("right-hand side of the 'in' operator not a map nor nil"),
ASE_T("value not referenceable"),
ASE_T("value not assignable"),
ASE_T("an indexed value cannot be assigned a map"),
ASE_T("a positional value cannot be assigned a map"),
ASE_T("map '%.*s' not assignable with a scalar"),
ASE_T("cannot change a scalar value to a map"),
ASE_T("a map is not allowed"),
ASE_T("invalid value type"),
ASE_T("delete statement called with a wrong target"),
ASE_T("next statement called from the BEGIN block"),
ASE_T("next statement called from the END block"),
ASE_T("nextfile statement called from the BEGIN block"),
ASE_T("nextfile statement called from the END block"),
ASE_T("wrong implementation of built-in function handler"),
ASE_T("built-in function handler returned an error"),
ASE_T("wrong implementation of user-defined io handler"),
ASE_T("no such io name found"),
ASE_T("i/o handler returned an error"),
ASE_T("i/o name empty"),
ASE_T("i/o name containing a null character"),
ASE_T("not sufficient arguments to formatting sequence"),
ASE_T("recursion detected in format conversion"),
ASE_T("invalid character in CONVFMT"),
ASE_T("invalid character in OFMT"),
ASE_T("recursion too deep in the regular expression"),
ASE_T("a right parenthesis expected in the regular expression"),
ASE_T("a right bracket expected in the regular expression"),
ASE_T("a right brace expected in the regular expression"),
ASE_T("unbalanced parenthesis in the regular expression"),
ASE_T("a colon expected in the regular expression"),
ASE_T("invalid character range in the regular expression"),
ASE_T("invalid character class in the regular expression"),
ASE_T("invalid boundary range in the regular expression"),
ASE_T("unexpected end of the regular expression"),
ASE_T("garbage after the regular expression")
};
if (errnum >= 0 && errnum < ASE_COUNTOF(errstr))
{
return errstr[errnum];
}
return ASE_T("unknown error");
}
const ase_char_t* ase_awk_geterrstr (ase_awk_t* awk, int num)
{
if (awk != ASE_NULL &&
awk->errstr[num] != ASE_NULL) return awk->errstr[num];
return __geterrstr (num);
}
int ase_awk_seterrstr (ase_awk_t* awk, int num, const ase_char_t* str)
{
ase_char_t* dup;
if (str == ASE_NULL) dup = ASE_NULL;
else
{
dup = ase_strdup (str, &awk->prmfns.mmgr);
if (dup == ASE_NULL) return -1;
}
if (awk->errstr[num] != ASE_NULL)
ASE_AWK_FREE (awk, awk->errstr[num]);
else awk->errstr[num] = dup;
return 0;
}
int ase_awk_geterrnum (ase_awk_t* awk)
{
return awk->errnum;
}
ase_size_t ase_awk_geterrlin (ase_awk_t* awk)
{
return awk->errlin;
}
const ase_char_t* ase_awk_geterrmsg (ase_awk_t* awk)
{
if (awk->errmsg[0] == ASE_T('\0'))
return ase_awk_geterrstr (awk, awk->errnum);
return awk->errmsg;
}
void ase_awk_geterror (
ase_awk_t* awk, int* errnum,
ase_size_t* errlin, const ase_char_t** errmsg)
{
if (errnum != ASE_NULL) *errnum = awk->errnum;
if (errlin != ASE_NULL) *errlin = awk->errlin;
if (errmsg != ASE_NULL)
{
if (awk->errmsg[0] == ASE_T('\0'))
*errmsg = ase_awk_geterrstr (awk, awk->errnum);
else
*errmsg = awk->errmsg;
}
}
void ase_awk_seterrnum (ase_awk_t* awk, int errnum)
{
awk->errnum = errnum;
awk->errlin = 0;
awk->errmsg[0] = ASE_T('\0');
}
void ase_awk_seterror (
ase_awk_t* awk, int errnum, ase_size_t errlin,
const ase_cstr_t* errarg, ase_size_t argcnt)
{
const ase_char_t* errfmt;
ase_size_t fmtlen;
ASE_ASSERT (argcnt <= 5);
awk->errnum = errnum;
awk->errlin = errlin;
errfmt = ase_awk_geterrstr (awk, errnum);
fmtlen = ase_strlen(errfmt);
switch (argcnt)
{
case 0:
awk->prmfns.misc.sprintf (
awk->prmfns.misc.custom_data,
awk->errmsg,
ASE_COUNTOF(awk->errmsg),
errfmt);
return;
case 1:
{
ase_char_t tmp[ASE_COUNTOF(awk->errmsg)];
ase_size_t len, tl;
if (fmtlen < ASE_COUNTOF(awk->errmsg) &&
errarg[0].len + fmtlen >= ASE_COUNTOF(awk->errmsg))
{
len = ASE_COUNTOF(awk->errmsg) - fmtlen - 3 - 1;
tl = ase_strxncpy (tmp, ASE_COUNTOF(tmp), errarg[0].ptr, len);
tmp[tl] = ASE_T('.');
tmp[tl+1] = ASE_T('.');
tmp[tl+2] = ASE_T('.');
len += 3;
}
else
{
len = errarg[0].len;
ase_strxncpy (tmp, ASE_COUNTOF(tmp), errarg[0].ptr, len);
}
awk->prmfns.misc.sprintf (
awk->prmfns.misc.custom_data,
awk->errmsg,
ASE_COUNTOF(awk->errmsg),
errfmt, len, tmp);
return;
}
case 2:
awk->prmfns.misc.sprintf (
awk->prmfns.misc.custom_data,
awk->errmsg,
ASE_COUNTOF(awk->errmsg),
errfmt,
errarg[0].len, errarg[0].ptr,
errarg[1].len, errarg[1].ptr);
return;
case 3:
awk->prmfns.misc.sprintf (
awk->prmfns.misc.custom_data,
awk->errmsg,
ASE_COUNTOF(awk->errmsg),
errfmt,
errarg[0].len, errarg[0].ptr,
errarg[1].len, errarg[1].ptr,
errarg[2].len, errarg[2].ptr);
return;
case 4:
awk->prmfns.misc.sprintf (
awk->prmfns.misc.custom_data,
awk->errmsg,
ASE_COUNTOF(awk->errmsg),
errfmt,
errarg[0].len, errarg[0].ptr,
errarg[1].len, errarg[1].ptr,
errarg[2].len, errarg[2].ptr,
errarg[3].len, errarg[3].ptr);
return;
case 5:
awk->prmfns.misc.sprintf (
awk->prmfns.misc.custom_data,
awk->errmsg,
ASE_COUNTOF(awk->errmsg),
errfmt,
errarg[0].len, errarg[0].ptr,
errarg[1].len, errarg[1].ptr,
errarg[2].len, errarg[2].ptr,
errarg[3].len, errarg[3].ptr,
errarg[4].len, errarg[4].ptr);
return;
}
}
int ase_awk_getrunerrnum (ase_awk_run_t* run)
{
return run->errnum;
}
ase_size_t ase_awk_getrunerrlin (ase_awk_run_t* run)
{
return run->errlin;
}
const ase_char_t* ase_awk_getrunerrmsg (ase_awk_run_t* run)
{
if (run->errmsg[0] == ASE_T('\0'))
return ase_awk_geterrstr (run->awk, run->errnum);
return run->errmsg;
}
void ase_awk_setrunerrnum (ase_awk_run_t* run, int errnum)
{
run->errnum = errnum;
run->errlin = 0;
run->errmsg[0] = ASE_T('\0');
}
void ase_awk_getrunerror (
ase_awk_run_t* run, int* errnum,
ase_size_t* errlin, const ase_char_t** errmsg)
{
if (errnum != ASE_NULL) *errnum = run->errnum;
if (errlin != ASE_NULL) *errlin = run->errlin;
if (errmsg != ASE_NULL)
{
if (run->errmsg[0] == ASE_T('\0'))
*errmsg = ase_awk_geterrstr (run->awk, run->errnum);
else
*errmsg = run->errmsg;
}
}
void ase_awk_setrunerror (
ase_awk_run_t* run, int errnum, ase_size_t errlin,
const ase_cstr_t* errarg, ase_size_t argcnt)
{
const ase_char_t* errfmt;
ase_size_t fmtlen;
ASE_ASSERT (argcnt <= 5);
run->errnum = errnum;
run->errlin = errlin;
errfmt = ase_awk_geterrstr (run->awk, errnum);
fmtlen = ase_strlen (errfmt);
switch (argcnt)
{
case 0:
/* TODO: convert % to %% if the original % is not
* the first % of the %% sequence */
run->awk->prmfns.misc.sprintf (
run->awk->prmfns.misc.custom_data,
run->errmsg,
ASE_COUNTOF(run->errmsg),
errfmt);
return;
case 1:
{
ase_char_t tmp[ASE_COUNTOF(run->errmsg)];
ase_size_t len, tl;
if (fmtlen < ASE_COUNTOF(run->errmsg) &&
errarg[0].len + fmtlen >= ASE_COUNTOF(run->errmsg))
{
len = ASE_COUNTOF(run->errmsg) - fmtlen - 3 - 1;
tl = ase_strxncpy (tmp, ASE_COUNTOF(tmp), errarg[0].ptr, len);
tmp[tl] = ASE_T('.');
tmp[tl+1] = ASE_T('.');
tmp[tl+2] = ASE_T('.');
len += 3;
}
else
{
len = errarg[0].len;
ase_strxncpy (tmp, ASE_COUNTOF(tmp), errarg[0].ptr, len);
}
run->awk->prmfns.misc.sprintf (
run->awk->prmfns.misc.custom_data,
run->errmsg,
ASE_COUNTOF(run->errmsg),
errfmt, len, tmp);
return;
}
case 2:
run->awk->prmfns.misc.sprintf (
run->awk->prmfns.misc.custom_data,
run->errmsg,
ASE_COUNTOF(run->errmsg),
errfmt,
errarg[0].len, errarg[0].ptr,
errarg[1].len, errarg[1].ptr);
return;
case 3:
run->awk->prmfns.misc.sprintf (
run->awk->prmfns.misc.custom_data,
run->errmsg,
ASE_COUNTOF(run->errmsg),
errfmt,
errarg[0].len, errarg[0].ptr,
errarg[1].len, errarg[1].ptr,
errarg[2].len, errarg[2].ptr);
return;
case 4:
run->awk->prmfns.misc.sprintf (
run->awk->prmfns.misc.custom_data,
run->errmsg,
ASE_COUNTOF(run->errmsg),
errfmt,
errarg[0].len, errarg[0].ptr,
errarg[1].len, errarg[1].ptr,
errarg[2].len, errarg[2].ptr,
errarg[3].len, errarg[3].ptr);
return;
case 5:
run->awk->prmfns.misc.sprintf (
run->awk->prmfns.misc.custom_data,
run->errmsg,
ASE_COUNTOF(run->errmsg),
errfmt,
errarg[0].len, errarg[0].ptr,
errarg[1].len, errarg[1].ptr,
errarg[2].len, errarg[2].ptr,
errarg[3].len, errarg[3].ptr,
errarg[4].len, errarg[4].ptr);
return;
}
}

951
ase/awk/extio.c Normal file
View File

@ -0,0 +1,951 @@
/*
* $Id: extio.c,v 1.3 2007/04/30 05:47:33 bacon Exp $
*
* {License}
*/
#include <ase/awk/awk_i.h>
enum
{
MASK_READ = 0x0100,
MASK_WRITE = 0x0200,
MASK_RDWR = 0x0400,
MASK_CLEAR = 0x00FF
};
static int in_type_map[] =
{
/* the order should match the order of the
* ASE_AWK_IN_XXX values in tree.h */
ASE_AWK_EXTIO_PIPE,
ASE_AWK_EXTIO_COPROC,
ASE_AWK_EXTIO_FILE,
ASE_AWK_EXTIO_CONSOLE
};
static int in_mode_map[] =
{
/* the order should match the order of the
* ASE_AWK_IN_XXX values in tree.h */
ASE_AWK_EXTIO_PIPE_READ,
0,
ASE_AWK_EXTIO_FILE_READ,
ASE_AWK_EXTIO_CONSOLE_READ
};
static int in_mask_map[] =
{
MASK_READ,
MASK_RDWR,
MASK_READ,
MASK_READ
};
static int out_type_map[] =
{
/* the order should match the order of the
* ASE_AWK_OUT_XXX values in tree.h */
ASE_AWK_EXTIO_PIPE,
ASE_AWK_EXTIO_COPROC,
ASE_AWK_EXTIO_FILE,
ASE_AWK_EXTIO_FILE,
ASE_AWK_EXTIO_CONSOLE
};
static int out_mode_map[] =
{
/* the order should match the order of the
* ASE_AWK_OUT_XXX values in tree.h */
ASE_AWK_EXTIO_PIPE_WRITE,
0,
ASE_AWK_EXTIO_FILE_WRITE,
ASE_AWK_EXTIO_FILE_APPEND,
ASE_AWK_EXTIO_CONSOLE_WRITE
};
static int out_mask_map[] =
{
MASK_WRITE,
MASK_RDWR,
MASK_WRITE,
MASK_WRITE,
MASK_WRITE
};
int ase_awk_readextio (
ase_awk_run_t* run, int in_type,
const ase_char_t* name, ase_str_t* buf)
{
ase_awk_extio_t* p = run->extio.chain;
ase_awk_io_t handler;
int extio_type, extio_mode, extio_mask, n, ret;
ase_awk_val_t* rs;
ase_char_t* rs_ptr;
ase_size_t rs_len;
ase_size_t line_len = 0;
ase_char_t c = ASE_T('\0'), pc;
ASE_ASSERT (in_type >= 0 && in_type <= ASE_COUNTOF(in_type_map));
ASE_ASSERT (in_type >= 0 && in_type <= ASE_COUNTOF(in_mode_map));
ASE_ASSERT (in_type >= 0 && in_type <= ASE_COUNTOF(in_mask_map));
/* translate the in_type into the relevant extio type and mode */
extio_type = in_type_map[in_type];
extio_mode = in_mode_map[in_type];
extio_mask = in_mask_map[in_type];
handler = run->extio.handler[extio_type];
if (handler == ASE_NULL)
{
/* no io handler provided */
ase_awk_setrunerrnum (run, ASE_AWK_EIOUSER);
return -1;
}
while (p != ASE_NULL)
{
if (p->type == (extio_type | extio_mask) &&
ase_strcmp (p->name,name) == 0) break;
p = p->next;
}
if (p == ASE_NULL)
{
p = (ase_awk_extio_t*) ASE_AWK_MALLOC (
run->awk, ASE_SIZEOF(ase_awk_extio_t));
if (p == ASE_NULL)
{
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1;
}
p->name = ase_strdup (name, &run->awk->prmfns.mmgr);
if (p->name == ASE_NULL)
{
ASE_AWK_FREE (run->awk, p);
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1;
}
p->run = run;
p->type = (extio_type | extio_mask);
p->mode = extio_mode;
p->handle = ASE_NULL;
p->next = ASE_NULL;
p->custom_data = run->extio.custom_data;
p->in.buf[0] = ASE_T('\0');
p->in.pos = 0;
p->in.len = 0;
p->in.eof = ase_false;
p->in.eos = ase_false;
ase_awk_setrunerrnum (run, ASE_AWK_ENOERR);
n = handler (ASE_AWK_IO_OPEN, p, ASE_NULL, 0);
if (n <= -1)
{
ASE_AWK_FREE (run->awk, p->name);
ASE_AWK_FREE (run->awk, p);
if (run->errnum == ASE_AWK_ENOERR)
{
/* if the error number has not been
* set by the user handler */
ase_awk_setrunerrnum (run, ASE_AWK_EIOIMPL);
}
return -1;
}
/* chain it */
p->next = run->extio.chain;
run->extio.chain = p;
/* usually, n == 0 indicates that it has reached the end
* of the input. the user io handler can return 0 for the
* open request if it doesn't have any files to open. One
* advantage of doing this would be that you can skip the
* entire pattern-block matching and exeuction. */
if (n == 0)
{
p->in.eos = ase_true;
return 0;
}
}
if (p->in.eos)
{
/* no more streams. */
return 0;
}
/* ready to read a line */
ase_str_clear (buf);
/* get the record separator */
rs = ase_awk_getglobal (run, ASE_AWK_GLOBAL_RS);
ase_awk_refupval (run, rs);
if (rs->type == ASE_AWK_VAL_NIL)
{
rs_ptr = ASE_NULL;
rs_len = 0;
}
else if (rs->type == ASE_AWK_VAL_STR)
{
rs_ptr = ((ase_awk_val_str_t*)rs)->buf;
rs_len = ((ase_awk_val_str_t*)rs)->len;
}
else
{
rs_ptr = ase_awk_valtostr (
run, rs, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &rs_len);
if (rs_ptr == ASE_NULL)
{
ase_awk_refdownval (run, rs);
return -1;
}
}
ret = 1;
/* call the io handler */
while (1)
{
if (p->in.pos >= p->in.len)
{
ase_ssize_t n;
if (p->in.eof)
{
if (ASE_STR_LEN(buf) == 0) ret = 0;
break;
}
ase_awk_setrunerrnum (run, ASE_AWK_ENOERR);
n = handler (ASE_AWK_IO_READ,
p, p->in.buf, ASE_COUNTOF(p->in.buf));
if (n <= -1)
{
if (run->errnum == ASE_AWK_ENOERR)
{
/* if the error number has not been
* set by the user handler */
ase_awk_setrunerrnum (run, ASE_AWK_EIOIMPL);
}
ret = -1;
break;
}
if (n == 0)
{
p->in.eof = ase_true;
if (ASE_STR_LEN(buf) == 0) ret = 0;
break;
}
p->in.len = n;
p->in.pos = 0;
}
pc = c;
c = p->in.buf[p->in.pos++];
if (rs_ptr == ASE_NULL)
{
/* separate by a new line */
if (c == ASE_T('\n'))
{
if (pc == ASE_T('\r') &&
ASE_STR_LEN(buf) > 0)
{
ASE_STR_LEN(buf) -= 1;
}
break;
}
}
else if (rs_len == 0)
{
/* separate by a blank line */
if (c == ASE_T('\n'))
{
if (pc == ASE_T('\r') &&
ASE_STR_LEN(buf) > 0)
{
ASE_STR_LEN(buf) -= 1;
}
}
if (line_len == 0 && c == ASE_T('\n'))
{
if (ASE_STR_LEN(buf) <= 0)
{
/* if the record is empty when a blank
* line is encountered, the line
* terminator should not be added to
* the record */
continue;
}
/* when a blank line is encountered,
* it needs to snip off the line
* terminator of the previous line */
ASE_STR_LEN(buf) -= 1;
break;
}
}
else if (rs_len == 1)
{
if (c == rs_ptr[0]) break;
}
else
{
const ase_char_t* match_ptr;
ase_size_t match_len;
ASE_ASSERT (run->global.rs != ASE_NULL);
n = ase_awk_matchrex (
run->awk, run->global.rs,
((run->global.ignorecase)? ASE_AWK_REX_IGNORECASE: 0),
ASE_STR_BUF(buf), ASE_STR_LEN(buf),
&match_ptr, &match_len, &run->errnum);
if (n == -1)
{
ret = -1;
break;
}
if (n == 1)
{
/* the match should be found at the end of
* the current buffer */
ASE_ASSERT (
ASE_STR_BUF(buf) + ASE_STR_LEN(buf) ==
match_ptr + match_len);
ASE_STR_LEN(buf) -= match_len;
break;
}
}
if (ase_str_ccat (buf, c) == (ase_size_t)-1)
{
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
ret = -1;
break;
}
/* TODO: handle different line terminator like \r\n */
if (c == ASE_T('\n')) line_len = 0;
else line_len = line_len + 1;
}
if (rs_ptr != ASE_NULL &&
rs->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, rs_ptr);
ase_awk_refdownval (run, rs);
/* increment NR */
if (ret != -1 && ret != 0)
{
ase_awk_val_t* nr;
ase_long_t lv;
ase_real_t rv;
nr = ase_awk_getglobal (run, ASE_AWK_GLOBAL_NR);
ase_awk_refupval (run, nr);
n = ase_awk_valtonum (run, nr, &lv, &rv);
ase_awk_refdownval (run, nr);
if (n == -1) ret = -1;
else
{
if (n == 1) lv = (ase_long_t)rv;
nr = ase_awk_makeintval (run, lv + 1);
if (nr == ASE_NULL)
{
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
ret = -1;
}
else
{
if (ase_awk_setglobal (
run, ASE_AWK_GLOBAL_NR, nr) == -1) ret = -1;
}
}
}
return ret;
}
int ase_awk_writeextio_val (
ase_awk_run_t* run, int out_type,
const ase_char_t* name, ase_awk_val_t* v)
{
ase_char_t* str;
ase_size_t len;
int n;
if (v->type == ASE_AWK_VAL_STR)
{
str = ((ase_awk_val_str_t*)v)->buf;
len = ((ase_awk_val_str_t*)v)->len;
}
else
{
str = ase_awk_valtostr (
run, v,
ASE_AWK_VALTOSTR_CLEAR | ASE_AWK_VALTOSTR_PRINT,
ASE_NULL, &len);
if (str == ASE_NULL) return -1;
}
n = ase_awk_writeextio_str (run, out_type, name, str, len);
if (v->type != ASE_AWK_VAL_STR) ASE_AWK_FREE (run->awk, str);
return n;
}
int ase_awk_writeextio_str (
ase_awk_run_t* run, int out_type,
const ase_char_t* name, ase_char_t* str, ase_size_t len)
{
ase_awk_extio_t* p = run->extio.chain;
ase_awk_io_t handler;
int extio_type, extio_mode, extio_mask, n;
ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_type_map));
ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_mode_map));
ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_mask_map));
/* translate the out_type into the relevant extio type and mode */
extio_type = out_type_map[out_type];
extio_mode = out_mode_map[out_type];
extio_mask = out_mask_map[out_type];
handler = run->extio.handler[extio_type];
if (handler == ASE_NULL)
{
/* no io handler provided */
ase_awk_setrunerrnum (run, ASE_AWK_EIOUSER);
return -1;
}
/* look for the corresponding extio for name */
while (p != ASE_NULL)
{
/* the file "1.tmp", in the following code snippets,
* would be opened by the first print statement, but not by
* the second print statement. this is because
* both ASE_AWK_OUT_FILE and ASE_AWK_OUT_FILE_APPEND are
* translated to ASE_AWK_EXTIO_FILE and it is used to
* keep track of file handles..
*
* print "1111" >> "1.tmp"
* print "1111" > "1.tmp"
*/
if (p->type == (extio_type | extio_mask) &&
ase_strcmp (p->name, name) == 0) break;
p = p->next;
}
/* if there is not corresponding extio for name, create one */
if (p == ASE_NULL)
{
p = (ase_awk_extio_t*) ASE_AWK_MALLOC (
run->awk, ASE_SIZEOF(ase_awk_extio_t));
if (p == ASE_NULL)
{
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1;
}
p->name = ase_strdup (name, &run->awk->prmfns.mmgr);
if (p->name == ASE_NULL)
{
ASE_AWK_FREE (run->awk, p);
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1;
}
p->run = run;
p->type = (extio_type | extio_mask);
p->mode = extio_mode;
p->handle = ASE_NULL;
p->next = ASE_NULL;
p->custom_data = run->extio.custom_data;
p->out.eof = ase_false;
p->out.eos = ase_false;
ase_awk_setrunerrnum (run, ASE_AWK_ENOERR);
n = handler (ASE_AWK_IO_OPEN, p, ASE_NULL, 0);
if (n <= -1)
{
ASE_AWK_FREE (run->awk, p->name);
ASE_AWK_FREE (run->awk, p);
if (run->errnum == ASE_AWK_ENOERR)
ase_awk_setrunerrnum (run, ASE_AWK_EIOIMPL);
return -1;
}
/* chain it */
p->next = run->extio.chain;
run->extio.chain = p;
/* usually, n == 0 indicates that it has reached the end
* of the input. the user io handler can return 0 for the
* open request if it doesn't have any files to open. One
* advantage of doing this would be that you can skip the
* entire pattern-block matching and exeuction. */
if (n == 0)
{
p->out.eos = ase_true;
return 0;
}
}
if (p->out.eos)
{
/* no more streams */
return 0;
}
if (p->out.eof)
{
/* it has reached the end of the stream but this function
* has been recalled */
return 0;
}
while (len > 0)
{
ase_awk_setrunerrnum (run, ASE_AWK_ENOERR);
n = handler (ASE_AWK_IO_WRITE, p, str, len);
if (n <= -1)
{
if (run->errnum == ASE_AWK_ENOERR)
ase_awk_setrunerrnum (run, ASE_AWK_EIOIMPL);
return -1;
}
if (n == 0)
{
p->out.eof = ase_true;
return 0;
}
len -= n;
str += n;
}
return 1;
}
int ase_awk_flushextio (
ase_awk_run_t* run, int out_type, const ase_char_t* name)
{
ase_awk_extio_t* p = run->extio.chain;
ase_awk_io_t handler;
int extio_type, /*extio_mode,*/ extio_mask, n;
ase_bool_t ok = ase_false;
ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_type_map));
ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_mode_map));
ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_mask_map));
/* translate the out_type into the relevant extio type and mode */
extio_type = out_type_map[out_type];
/*extio_mode = out_mode_map[out_type];*/
extio_mask = out_mask_map[out_type];
handler = run->extio.handler[extio_type];
if (handler == ASE_NULL)
{
/* no io handler provided */
ase_awk_setrunerrnum (run, ASE_AWK_EIOUSER);
return -1;
}
/* look for the corresponding extio for name */
while (p != ASE_NULL)
{
if (p->type == (extio_type | extio_mask) &&
(name == ASE_NULL || ase_strcmp(p->name,name) == 0))
{
ase_awk_setrunerrnum (run, ASE_AWK_ENOERR);
n = handler (ASE_AWK_IO_FLUSH, p, ASE_NULL, 0);
if (n <= -1)
{
if (run->errnum == ASE_AWK_ENOERR)
ase_awk_setrunerrnum (run, ASE_AWK_EIOIMPL);
return -1;
}
ok = ase_true;
}
p = p->next;
}
if (ok) return 0;
/* there is no corresponding extio for name */
ase_awk_setrunerrnum (run, ASE_AWK_EIONONE);
return -1;
}
int ase_awk_nextextio_read (
ase_awk_run_t* run, int in_type, const ase_char_t* name)
{
ase_awk_extio_t* p = run->extio.chain;
ase_awk_io_t handler;
int extio_type, /*extio_mode,*/ extio_mask, n;
ASE_ASSERT (in_type >= 0 && in_type <= ASE_COUNTOF(in_type_map));
ASE_ASSERT (in_type >= 0 && in_type <= ASE_COUNTOF(in_mode_map));
ASE_ASSERT (in_type >= 0 && in_type <= ASE_COUNTOF(in_mask_map));
/* translate the in_type into the relevant extio type and mode */
extio_type = in_type_map[in_type];
/*extio_mode = in_mode_map[in_type];*/
extio_mask = in_mask_map[in_type];
handler = run->extio.handler[extio_type];
if (handler == ASE_NULL)
{
/* no io handler provided */
ase_awk_setrunerrnum (run, ASE_AWK_EIOUSER);
return -1;
}
while (p != ASE_NULL)
{
if (p->type == (extio_type | extio_mask) &&
ase_strcmp (p->name,name) == 0) break;
p = p->next;
}
if (p == ASE_NULL)
{
/* something is totally wrong */
ASE_ASSERT (
!"should never happen - cannot find the relevant extio entry");
ase_awk_setrunerror (run, ASE_AWK_EINTERN, 0, ASE_NULL, 0);
return -1;
}
if (p->in.eos)
{
/* no more streams. */
return 0;
}
ase_awk_setrunerrnum (run, ASE_AWK_ENOERR);
n = handler (ASE_AWK_IO_NEXT, p, ASE_NULL, 0);
if (n <= -1)
{
if (run->errnum == ASE_AWK_ENOERR)
ase_awk_setrunerrnum (run, ASE_AWK_EIOIMPL);
return -1;
}
if (n == 0)
{
/* the next stream cannot be opened.
* set the eos flags so that the next call to nextextio_read
* will return 0 without executing the handler */
p->in.eos = ase_true;
}
else
{
/* as the next stream has been opened successfully,
* the eof flag should be cleared if set */
p->in.eof = ase_false;
/* also the previous input buffer must be reset */
p->in.pos = 0;
p->in.len = 0;
}
return n;
}
int ase_awk_nextextio_write (
ase_awk_run_t* run, int out_type, const ase_char_t* name)
{
ase_awk_extio_t* p = run->extio.chain;
ase_awk_io_t handler;
int extio_type, /*extio_mode,*/ extio_mask, n;
ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_type_map));
ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_mode_map));
ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_mask_map));
/* translate the out_type into the relevant extio type and mode */
extio_type = out_type_map[out_type];
/*extio_mode = out_mode_map[out_type];*/
extio_mask = out_mask_map[out_type];
handler = run->extio.handler[extio_type];
if (handler == ASE_NULL)
{
/* no io handler provided */
ase_awk_setrunerrnum (run, ASE_AWK_EIOUSER);
return -1;
}
while (p != ASE_NULL)
{
if (p->type == (extio_type | extio_mask) &&
ase_strcmp (p->name,name) == 0) break;
p = p->next;
}
if (p == ASE_NULL)
{
/* something is totally wrong */
ASE_ASSERT (!"should never happen - cannot find the relevant extio entry");
ase_awk_setrunerror (run, ASE_AWK_EINTERN, 0, ASE_NULL, 0);
return -1;
}
if (p->out.eos)
{
/* no more streams. */
return 0;
}
ase_awk_setrunerrnum (run, ASE_AWK_ENOERR);
n = handler (ASE_AWK_IO_NEXT, p, ASE_NULL, 0);
if (n <= -1)
{
if (run->errnum == ASE_AWK_ENOERR)
ase_awk_setrunerrnum (run, ASE_AWK_EIOIMPL);
return -1;
}
if (n == 0)
{
/* the next stream cannot be opened.
* set the eos flags so that the next call to nextextio_write
* will return 0 without executing the handler */
p->out.eos = ase_true;
}
else
{
/* as the next stream has been opened successfully,
* the eof flag should be cleared if set */
p->out.eof = ase_false;
}
return n;
}
int ase_awk_closeextio_read (
ase_awk_run_t* run, int in_type, const ase_char_t* name)
{
ase_awk_extio_t* p = run->extio.chain, * px = ASE_NULL;
ase_awk_io_t handler;
int extio_type, /*extio_mode,*/ extio_mask;
ASE_ASSERT (in_type >= 0 && in_type <= ASE_COUNTOF(in_type_map));
ASE_ASSERT (in_type >= 0 && in_type <= ASE_COUNTOF(in_mode_map));
ASE_ASSERT (in_type >= 0 && in_type <= ASE_COUNTOF(in_mask_map));
/* translate the in_type into the relevant extio type and mode */
extio_type = in_type_map[in_type];
/*extio_mode = in_mode_map[in_type];*/
extio_mask = in_mask_map[in_type];
handler = run->extio.handler[extio_type];
if (handler == ASE_NULL)
{
/* no io handler provided */
ase_awk_setrunerrnum (run, ASE_AWK_EIOUSER);
return -1;
}
while (p != ASE_NULL)
{
if (p->type == (extio_type | extio_mask) &&
ase_strcmp (p->name, name) == 0)
{
ase_awk_io_t handler;
handler = run->extio.handler[p->type & MASK_CLEAR];
if (handler != ASE_NULL)
{
if (handler (ASE_AWK_IO_CLOSE, p, ASE_NULL, 0) <= -1)
{
/* this is not a run-time error.*/
ase_awk_setrunerror (run, ASE_AWK_EIOIMPL, 0, ASE_NULL, 0);
return -1;
}
}
if (px != ASE_NULL) px->next = p->next;
else run->extio.chain = p->next;
ASE_AWK_FREE (run->awk, p->name);
ASE_AWK_FREE (run->awk, p);
return 0;
}
px = p;
p = p->next;
}
/* the name given is not found */
ase_awk_setrunerrnum (run, ASE_AWK_EIONONE);
return -1;
}
int ase_awk_closeextio_write (
ase_awk_run_t* run, int out_type, const ase_char_t* name)
{
ase_awk_extio_t* p = run->extio.chain, * px = ASE_NULL;
ase_awk_io_t handler;
int extio_type, /*extio_mode,*/ extio_mask;
ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_type_map));
ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_mode_map));
ASE_ASSERT (out_type >= 0 && out_type <= ASE_COUNTOF(out_mask_map));
/* translate the out_type into the relevant extio type and mode */
extio_type = out_type_map[out_type];
/*extio_mode = out_mode_map[out_type];*/
extio_mask = out_mask_map[out_type];
handler = run->extio.handler[extio_type];
if (handler == ASE_NULL)
{
/* no io handler provided */
ase_awk_setrunerror (run, ASE_AWK_EIOUSER, 0, ASE_NULL, 0);
return -1;
}
while (p != ASE_NULL)
{
if (p->type == (extio_type | extio_mask) &&
ase_strcmp (p->name, name) == 0)
{
ase_awk_io_t handler;
handler = run->extio.handler[p->type & MASK_CLEAR];
if (handler != ASE_NULL)
{
ase_awk_setrunerrnum (run, ASE_AWK_ENOERR);
if (handler (ASE_AWK_IO_CLOSE, p, ASE_NULL, 0) <= -1)
{
if (run->errnum == ASE_AWK_ENOERR)
ase_awk_setrunerrnum (run, ASE_AWK_EIOIMPL);
return -1;
}
}
if (px != ASE_NULL) px->next = p->next;
else run->extio.chain = p->next;
ASE_AWK_FREE (run->awk, p->name);
ASE_AWK_FREE (run->awk, p);
return 0;
}
px = p;
p = p->next;
}
ase_awk_setrunerrnum (run, ASE_AWK_EIONONE);
return -1;
}
int ase_awk_closeextio (ase_awk_run_t* run, const ase_char_t* name)
{
ase_awk_extio_t* p = run->extio.chain, * px = ASE_NULL;
while (p != ASE_NULL)
{
/* it handles the first that matches the given name
* regardless of the extio type */
if (ase_strcmp (p->name, name) == 0)
{
ase_awk_io_t handler;
handler = run->extio.handler[p->type & MASK_CLEAR];
if (handler != ASE_NULL)
{
ase_awk_setrunerrnum (run, ASE_AWK_ENOERR);
if (handler (ASE_AWK_IO_CLOSE, p, ASE_NULL, 0) <= -1)
{
/* this is not a run-time error.*/
if (run->errnum == ASE_AWK_ENOERR)
ase_awk_setrunerrnum (run, ASE_AWK_EIOIMPL);
return -1;
}
}
if (px != ASE_NULL) px->next = p->next;
else run->extio.chain = p->next;
ASE_AWK_FREE (run->awk, p->name);
ASE_AWK_FREE (run->awk, p);
return 0;
}
px = p;
p = p->next;
}
ase_awk_setrunerrnum (run, ASE_AWK_EIONONE);
return -1;
}
void ase_awk_clearextio (ase_awk_run_t* run)
{
ase_awk_extio_t* next;
ase_awk_io_t handler;
int n;
while (run->extio.chain != ASE_NULL)
{
handler = run->extio.handler[
run->extio.chain->type & MASK_CLEAR];
next = run->extio.chain->next;
if (handler != ASE_NULL)
{
ase_awk_setrunerrnum (run, ASE_AWK_ENOERR);
n = handler (ASE_AWK_IO_CLOSE, run->extio.chain, ASE_NULL, 0);
if (n <= -1)
{
if (run->errnum == ASE_AWK_ENOERR)
ase_awk_setrunerrnum (run, ASE_AWK_EIOIMPL);
/* TODO: some warnings need to be shown??? */
}
}
ASE_AWK_FREE (run->awk, run->extio.chain->name);
ASE_AWK_FREE (run->awk, run->extio.chain);
run->extio.chain = next;
}
}

51
ase/awk/extio.h Normal file
View File

@ -0,0 +1,51 @@
/*
* $Id: extio.h,v 1.3 2007/04/30 05:47:33 bacon Exp $
*
* {License}
*/
#ifndef _ASE_AWK_EXTIO_H_
#define _ASE_AWK_EXTIO_H_
#ifndef _ASE_AWK_AWK_H_
#error Never include this file directly. Include <ase/awk/awk.h> instead
#endif
#ifdef __cplusplus
extern "C"
#endif
int ase_awk_readextio (
ase_awk_run_t* run, int in_type,
const ase_char_t* name, ase_str_t* buf);
int ase_awk_writeextio_val (
ase_awk_run_t* run, int out_type,
const ase_char_t* name, ase_awk_val_t* v);
int ase_awk_writeextio_str (
ase_awk_run_t* run, int out_type,
const ase_char_t* name, ase_char_t* str, ase_size_t len);
int ase_awk_flushextio (
ase_awk_run_t* run, int out_type, const ase_char_t* name);
int ase_awk_nextextio_read (
ase_awk_run_t* run, int in_type, const ase_char_t* name);
int ase_awk_nextextio_write (
ase_awk_run_t* run, int out_type, const ase_char_t* name);
int ase_awk_closeextio_read (
ase_awk_run_t* run, int in_type, const ase_char_t* name);
int ase_awk_closeextio_write (
ase_awk_run_t* run, int out_type, const ase_char_t* name);
int ase_awk_closeextio (ase_awk_run_t* run, const ase_char_t* name);
void ase_awk_clearextio (ase_awk_run_t* run);
#ifdef __cplusplus
}
#endif
#endif

1364
ase/awk/func.c Normal file

File diff suppressed because it is too large Load Diff

49
ase/awk/func.h Normal file
View File

@ -0,0 +1,49 @@
/*
* $Id: func.h,v 1.3 2007/04/30 05:47:33 bacon Exp $
*
* {License}
*/
#ifndef _ASE_AWK_FUNC_H_
#define _ASE_AWK_FUNC_H_
#ifndef _ASE_AWK_AWK_H_
#error Never include this file directly. Include <ase/awk/awk.h> instead
#endif
typedef struct ase_awk_bfn_t ase_awk_bfn_t;
struct ase_awk_bfn_t
{
struct
{
ase_char_t* ptr;
ase_size_t len;
} name;
int valid; /* the entry is valid when this option is set */
struct
{
ase_size_t min;
ase_size_t max;
ase_char_t* spec;
} arg;
int (*handler) (ase_awk_run_t*, const ase_char_t*, ase_size_t);
ase_awk_bfn_t* next;
};
#ifdef __cplusplus
extern "C" {
#endif
ase_awk_bfn_t* ase_awk_getbfn (
ase_awk_t* awk, const ase_char_t* name, ase_size_t len);
#ifdef __cplusplus
}
#endif
#endif

2350
ase/awk/jni.c Normal file

File diff suppressed because it is too large Load Diff

24
ase/awk/jni.def Normal file
View File

@ -0,0 +1,24 @@
LIBRARY "aseawk_jni.dll"
EXPORTS
Java_ase_awk_Awk_open
Java_ase_awk_Awk_close
Java_ase_awk_Awk_parse
Java_ase_awk_Awk_run
Java_ase_awk_Awk_getmaxdepth
Java_ase_awk_Awk_setmaxdepth
Java_ase_awk_Awk_getoption
Java_ase_awk_Awk_setoption
Java_ase_awk_Awk_getdebug
Java_ase_awk_Awk_setdebug
Java_ase_awk_Awk_addbfn
Java_ase_awk_Awk_delbfn
Java_ase_awk_Awk_setfilename
Java_ase_awk_Awk_setofilename
Java_ase_awk_Awk_strtonum
Java_ase_awk_Awk_valtostr

60
ase/awk/jni.h Normal file
View File

@ -0,0 +1,60 @@
/*
* $Id: jni.h,v 1.3 2007/04/30 05:47:33 bacon Exp $
*
* {License}
*/
#ifndef _ASE_AWK_JNI_H_
#define _ASE_AWK_JNI_H_
#if defined(__APPLE__) && defined(__MACH__)
#include <JavaVM/jni.h>
#else
#include <jni.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
JNIEXPORT void JNICALL Java_ase_awk_Awk_open (JNIEnv* env, jobject obj);
JNIEXPORT void JNICALL Java_ase_awk_Awk_close (JNIEnv* env, jobject obj);
JNIEXPORT void JNICALL Java_ase_awk_Awk_parse (JNIEnv* env, jobject obj);
JNIEXPORT void JNICALL Java_ase_awk_Awk_run (
JNIEnv* env, jobject obj, jstring mfn, jobjectArray args);
JNIEXPORT void JNICALL Java_ase_awk_Awk_addbfn (
JNIEnv* env, jobject obj, jstring name, jint min_args, jint max_args);
JNIEXPORT void JNICALL Java_ase_awk_Awk_delbfn (
JNIEnv* env, jobject obj, jstring name);
JNIEXPORT jint JNICALL Java_ase_awk_Awk_getmaxdepth (
JNIEnv* env, jobject obj, jint id);
JNIEXPORT void JNICALL Java_ase_awk_Awk_setmaxdepth (
JNIEnv* env, jobject obj, jint ids, jint depth);
JNIEXPORT jint JNICALL Java_ase_awk_Awk_getoption (
JNIEnv* env, jobject obj);
JNIEXPORT void JNICALL Java_ase_awk_Awk_setoption (
JNIEnv* env, jobject obj, jint options);
JNIEXPORT jboolean JNICALL Java_ase_awk_Awk_getdebug (
JNIEnv* env, jobject obj);
JNIEXPORT void JNICALL Java_ase_awk_Awk_setdebug (
JNIEnv* env, jobject obj, jboolean debug);
JNIEXPORT void JNICALL Java_ase_awk_Awk_setfilename (
JNIEnv* env, jobject obj, jlong runid, jstring name);
JNIEXPORT void JNICALL Java_ase_awk_Awk_setofilename (
JNIEnv* env, jobject obj, jlong runid, jstring name);
JNIEXPORT jobject JNICALL Java_ase_awk_Awk_strtonum (
JNIEnv* env, jobject obj, jlong runid, jstring str);
JNIEXPORT jstring JNICALL Java_ase_awk_Awk_valtostr (
JNIEnv* env, jobject obj, jlong runid, jobject val);
#ifdef __cplusplus
}
#endif
#endif

152
ase/awk/makefile.in Normal file
View File

@ -0,0 +1,152 @@
#
# $Id: makefile.in,v 1.3 2007/04/30 05:47:33 bacon Exp $
#
NAME = aseawk
TOP_BUILDDIR = @abs_top_builddir@
TOP_INSTALLDIR = @prefix@/ase
CC = @CC@
CXX = @CXX@
AR = ar
RANLIB = @RANLIB@
CFLAGS = @CFLAGS@ -I@abs_top_builddir@/..
CXXFLAGS = @CXXFLAGS@ -I@abs_top_builddir@/..
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
MODE = @BUILDMODE@
JAVAC = @JAVAC@
JAR = @JAR@
CFLAGS_JNI = @CFLAGS_JNI@
JNI = @JNI@
LIBTOOL_COMPILE = ../libtool --mode=compile
LIBTOOL_LINK = ../libtool --mode=link
OUT_DIR = ../$(MODE)/lib
OUT_FILE_LIB = $(OUT_DIR)/lib$(NAME).a
OUT_FILE_JNI = $(OUT_DIR)/lib$(NAME)_jni.la
OUT_FILE_LIB_CXX = $(OUT_DIR)/lib$(NAME)++.a
OUT_FILE_JAR = $(OUT_DIR)/$(NAME).jar
TMP_DIR = $(MODE)
TMP_DIR_CXX = $(TMP_DIR)/cxx
OBJ_FILES_LIB = \
$(TMP_DIR)/awk.o \
$(TMP_DIR)/err.o \
$(TMP_DIR)/tree.o \
$(TMP_DIR)/tab.o \
$(TMP_DIR)/map.o \
$(TMP_DIR)/parse.o \
$(TMP_DIR)/run.o \
$(TMP_DIR)/rec.o \
$(TMP_DIR)/val.o \
$(TMP_DIR)/func.o \
$(TMP_DIR)/misc.o \
$(TMP_DIR)/extio.o \
$(TMP_DIR)/rex.o
OBJ_FILES_JNI = $(TMP_DIR)/jni.o
OBJ_FILES_LIB_CXX = \
$(OBJ_FILES_LIB) \
$(TMP_DIR)/cxx/Awk.o
OBJ_FILES_SO = $(OBJ_FILES_LIB:.o=.lo) $(OBJ_FILES_JNI:.o=.lo)
OBJ_FILES_JAR = \
$(TMP_DIR)/ase/awk/Awk.class \
$(TMP_DIR)/ase/awk/StdAwk.class \
$(TMP_DIR)/ase/awk/Extio.class \
$(TMP_DIR)/ase/awk/Exception.class
lib: build$(JNI)
build: $(OUT_FILE_LIB) $(OUT_FILE_LIB_CXX)
buildjni: build $(OUT_FILE_JNI)
$(OUT_FILE_LIB): $(TMP_DIR) $(OUT_DIR) $(OBJ_FILES_LIB)
$(AR) cr $(OUT_FILE_LIB) $(OBJ_FILES_LIB)
if [ "$(RANLIB)" = "ranlib" ]; then ranlib $(OUT_FILE_LIB); fi
$(OUT_FILE_JNI): $(TMP_DIR) $(OBJ_FILES_JNI) $(OBJ_FILES_JAR) $(OUT_FILE_LIB)
$(LIBTOOL_LINK) $(CC) -rpath $(TOP_INSTALLDIR)/lib -version-info 1:0:0 -o $(OUT_FILE_JNI) $(OBJ_FILES_SO) -lm -L$(OUT_DIR) -l$(NAME) -lasecmn -laseutl
$(JAR) -Mcvf $(OUT_FILE_JAR) -C $(TMP_DIR) ase
$(OUT_FILE_LIB_CXX): $(TMP_DIR_CXX) $(OUT_DIR) $(OBJ_FILES_LIB_CXX)
$(AR) cr $(OUT_FILE_LIB_CXX) $(OBJ_FILES_LIB_CXX)
if [ "$(RANLIB)" = "ranlib" ]; then ranlib $(OUT_FILE_LIB_CXX); fi
$(TMP_DIR)/awk.o: awk.c
$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) -o $@ -c awk.c
$(TMP_DIR)/err.o: err.c
$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) -o $@ -c err.c
$(TMP_DIR)/tree.o: tree.c
$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) -o $@ -c tree.c
$(TMP_DIR)/tab.o: tab.c
$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) -o $@ -c tab.c
$(TMP_DIR)/map.o: map.c
$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) -o $@ -c map.c
$(TMP_DIR)/parse.o: parse.c
$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) -o $@ -c parse.c
$(TMP_DIR)/run.o: run.c
$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) -o $@ -c run.c
$(TMP_DIR)/rec.o: rec.c
$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) -o $@ -c rec.c
$(TMP_DIR)/val.o: val.c
$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) -o $@ -c val.c
$(TMP_DIR)/func.o: func.c
$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) -o $@ -c func.c
$(TMP_DIR)/misc.o: misc.c
$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) -o $@ -c misc.c
$(TMP_DIR)/extio.o: extio.c
$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) -o $@ -c extio.c
$(TMP_DIR)/rex.o: rex.c
$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) -o $@ -c rex.c
$(TMP_DIR)/jni.o: jni.c
$(LIBTOOL_COMPILE) $(CC) $(CFLAGS) $(CFLAGS_JNI) -o $@ -c jni.c
$(TMP_DIR)/ase/awk/Awk.class:
$(JAVAC) -classpath ../.. -d $(TMP_DIR) Awk.java
$(TMP_DIR)/ase/awk/StdAwk.class:
$(JAVAC) -classpath ../.. -d $(TMP_DIR) StdAwk.java
$(TMP_DIR)/ase/awk/Extio.class:
$(JAVAC) -classpath ../.. -d $(TMP_DIR) Extio.java
$(TMP_DIR)/ase/awk/Exception.class:
$(JAVAC) -classpath ../.. -d $(TMP_DIR) Exception.java
$(TMP_DIR)/cxx/Awk.o:
$(CXX) $(CXXFLAGS) -o $@ -c Awk.cpp
$(OUT_DIR):
mkdir -p $(OUT_DIR)
$(TMP_DIR):
mkdir -p $(TMP_DIR)
$(TMP_DIR_CXX): $(TMP_DIR)
mkdir -p $(TMP_DIR)/cxx
clean:
rm -rf $(OUT_FILE_LIB) $(OUT_FILE_JNI) $(OUT_FILE_JAR) $(OUT_FILE_LIB_CXX) $(OBJ_FILES_LIB) $(OBJ_FILES_JNI) $(OBJ_FILES_JAR) $(OBJ_FILES_LIB_CXX)

54
ase/awk/makefile.msw.bcc Normal file
View File

@ -0,0 +1,54 @@
OUT = aseawk
C_SRCS = awk.c err.c tree.c tab.c map.c parse.c \
run.c rec.c val.c func.c misc.c extio.c rex.c
JNI_SRCS = jni.c
JAVA_SRCS = Exception.java Extio.java Awk.java StdAwk.java
C_OBJS = $(C_SRCS:.c=.obj)
JNI_OBJS = $(JNI_SRCS:.c=.obj)
JAVA_OBJS = $(JAVA_SRCS:.java=.class)
JNI_INCPATH = \
-I"$(JAVA_HOME)/include" \
-I"$(JAVA_HOME)/include/win32"
CC = bcc32
LD = ilink32
AR = tlib
JAVAC = javac
CFLAGS_COMMON = -O2 -WM -WU -RT- -w -q -I../.. $(JNI_INCPATH)
CFLAGS_RELEASE = $(CFLAGS_COMMON) -DNDEBUG
CFLAGS_DEBUG = $(CFLAGS_COMMON) -D_DEBUG #-DDEBUG_REX
CFLAGS = $(CFLAGS_DEBUG)
#CFLAGS = $(CFLAGS_RELEASE)
JAVACFLAGS = -classpath ../..
LDFLAGS = -Tpd -ap -Gn -c -q
STARTUP = c0d32w.obj
LIBS = import32.lib cw32mt.lib
JNI_LDFLAGS = $(LDFLAGS) -L..\cmn -L..\utl
JNI_LIBS = $(LIBS) $(OUT).lib asecmn.lib aseutl.lib
all: lib
lib: $(C_OBJS)
$(AR) $(OUT).lib @&&!
+-$(**: = &^
+-)
!
jni: lib $(JNI_OBJS) $(JAVA_OBJS)
$(LD) $(JNI_LDFLAGS) $(STARTUP) $(JNI_OBJS),$(OUT)_jni.dll,,$(JNI_LIBS),jni.def,
clean:
-del $(OBJS) $(OUT).lib $(OUT)_jni.dll *.obj *.class
.SUFFIXES: .c .obj .java .class
.c.obj:
$(CC) $(CFLAGS) -c $<
.java.class:
$(JAVAC) $(JAVACFLAGS) $<

45
ase/awk/makefile.msw.cl Normal file
View File

@ -0,0 +1,45 @@
OUT = aseawk
C_SRCS = awk.c err.c tree.c tab.c map.c parse.c \
run.c rec.c val.c func.c misc.c extio.c rex.c
JNI_SRCS = jni.c
JAVA_SRCS = Exception.java Extio.java Awk.java StdAwk.java
C_OBJS = $(C_SRCS:.c=.obj)
JNI_OBJS = $(JNI_SRCS:.c=.obj)
JAVA_OBJS = $(JAVA_SRCS:.java=.class)
JNI_INC = \
/I"$(JAVA_HOME)/include" \
/I"$(JAVA_HOME)/include\win32"
CC = cl
LD = link
JAVAC = javac
#CFLAGS = /nologo /O2 /MT /W3 /GR- /GS- /Za -I../.. $(JNI_INC)
CFLAGS = /nologo /O2 /MT /W3 /GR- /GS- -I../.. $(JNI_INC)
JAVACFLAGS = -classpath ../.. -Xlint:unchecked
all: lib
lib: $(C_OBJS)
$(LD) /lib @<<
/nologo /out:$(OUT).lib $(C_OBJS)
<<
jni: lib $(JNI_OBJS) $(JAVA_OBJS)
$(LD) /dll /def:jni.def /subsystem:windows /version:0.1 /release @<<
/nologo /out:$(OUT)_jni.dll $(JNI_OBJS) /libpath:../cmn /libpath:../utl /implib:tmp.lib user32.lib $(OUT).lib asecmn.lib aseutl.lib
<<
del tmp.lib tmp.exp
clean:
del $(OBJS) $(OUT).lib $(OUT)_jni.dll *.obj *.class
.SUFFIXES: .c .obj .java .class
.c.obj:
$(CC) $(CFLAGS) /c $<
.java.class:
$(JAVAC) $(JAVACFLAGS) $<

289
ase/awk/map.c Normal file
View File

@ -0,0 +1,289 @@
/*
* $Id: map.c,v 1.3 2007/04/30 05:47:33 bacon Exp $
*
* {License}
*/
#include <ase/awk/awk_i.h>
/* TODO: improve the entire map routines.
support automatic bucket resizing and remaping, etc. */
static ase_size_t hashkey (const ase_char_t* keyptr, ase_size_t keylen);
#define FREE_PAIR(map,pair) \
do { \
ASE_AWK_FREE ((map)->awk, (ase_char_t*)PAIR_KEYPTR(pair)); \
if ((map)->freeval != ASE_NULL) \
(map)->freeval ((map)->owner, PAIR_VAL(pair)); \
ASE_AWK_FREE ((map)->awk, pair); \
} while (0)
ase_awk_map_t* ase_awk_map_open (
ase_awk_map_t* map, void* owner, ase_size_t capa,
void(*freeval)(void*,void*), ase_awk_t* awk)
{
ASE_ASSERTX (capa > 0, "the initial capacity should be greater than 0");
if (map == ASE_NULL)
{
map = (ase_awk_map_t*) ASE_AWK_MALLOC (
awk, ASE_SIZEOF(ase_awk_map_t));
if (map == ASE_NULL) return ASE_NULL;
map->__dynamic = ase_true;
}
else map->__dynamic = ase_false;
map->awk = awk;
map->buck = (ase_awk_pair_t**)
ASE_AWK_MALLOC (awk, ASE_SIZEOF(ase_awk_pair_t*) * capa);
if (map->buck == ASE_NULL)
{
if (map->__dynamic) ASE_AWK_FREE (awk, map);
return ASE_NULL;
}
map->owner = owner;
map->capa = capa;
map->size = 0;
map->freeval = freeval;
while (capa > 0) map->buck[--capa] = ASE_NULL;
return map;
}
void ase_awk_map_close (ase_awk_map_t* map)
{
ase_awk_map_clear (map);
ASE_AWK_FREE (map->awk, map->buck);
if (map->__dynamic) ASE_AWK_FREE (map->awk, map);
}
void ase_awk_map_clear (ase_awk_map_t* map)
{
ase_size_t i;
ase_awk_pair_t* pair, * next;
for (i = 0; i < map->capa; i++)
{
pair = map->buck[i];
while (pair != ASE_NULL)
{
next = PAIR_LNK(pair);
FREE_PAIR (map, pair);
map->size--;
pair = next;
}
map->buck[i] = ASE_NULL;
}
}
ase_size_t ase_awk_map_getsize (ase_awk_map_t* map)
{
return map->size;
}
ase_awk_pair_t* ase_awk_map_get (
ase_awk_map_t* map, const ase_char_t* keyptr, ase_size_t keylen)
{
ase_awk_pair_t* pair;
ase_size_t hc;
hc = hashkey(keyptr,keylen) % map->capa;
pair = map->buck[hc];
while (pair != ASE_NULL)
{
if (ase_strxncmp (
PAIR_KEYPTR(pair), PAIR_KEYLEN(pair),
keyptr, keylen) == 0) return pair;
pair = PAIR_LNK(pair);
}
return ASE_NULL;
}
ase_awk_pair_t* ase_awk_map_put (
ase_awk_map_t* map, ase_char_t* keyptr, ase_size_t keylen, void* val)
{
int n;
ase_awk_pair_t* px;
n = ase_awk_map_putx (map, keyptr, keylen, val, &px);
if (n < 0) return ASE_NULL;
return px;
}
int ase_awk_map_putx (
ase_awk_map_t* map, ase_char_t* keyptr, ase_size_t keylen,
void* val, ase_awk_pair_t** px)
{
ase_awk_pair_t* pair;
ase_size_t hc;
hc = hashkey(keyptr,keylen) % map->capa;
pair = map->buck[hc];
while (pair != ASE_NULL)
{
if (ase_strxncmp (
PAIR_KEYPTR(pair), PAIR_KEYLEN(pair),
keyptr, keylen) == 0)
{
if (px != ASE_NULL)
*px = ase_awk_map_setpair (map, pair, val);
else
ase_awk_map_setpair (map, pair, val);
return 0; /* value changed for the existing key */
}
pair = PAIR_LNK(pair);
}
pair = (ase_awk_pair_t*) ASE_AWK_MALLOC (
map->awk, ASE_SIZEOF(ase_awk_pair_t));
if (pair == ASE_NULL) return -1; /* error */
/* duplicate the key if it is new */
PAIR_KEYPTR(pair) = ase_strxdup (
keyptr, keylen, &map->awk->prmfns.mmgr);
if (PAIR_KEYPTR(pair) == ASE_NULL)
{
ASE_AWK_FREE (map->awk, pair);
return -1; /* error */
}
PAIR_KEYLEN(pair) = keylen;
PAIR_VAL(pair) = val;
PAIR_LNK(pair) = map->buck[hc];
map->buck[hc] = pair;
map->size++;
if (px != ASE_NULL) *px = pair;
return 1; /* new key added */
}
ase_awk_pair_t* ase_awk_map_set (
ase_awk_map_t* map, ase_char_t* keyptr, ase_size_t keylen, void* val)
{
ase_awk_pair_t* pair;
ase_size_t hc;
hc = hashkey(keyptr,keylen) % map->capa;
pair = map->buck[hc];
while (pair != ASE_NULL)
{
if (ase_strxncmp (
PAIR_KEYPTR(pair), PAIR_KEYLEN(pair),
keyptr, keylen) == 0)
{
return ase_awk_map_setpair (map, pair, val);
}
pair = PAIR_LNK(pair);
}
return ASE_NULL;
}
ase_awk_pair_t* ase_awk_map_getpair (
ase_awk_map_t* map, const ase_char_t* keyptr, ase_size_t keylen,
void** val)
{
ase_awk_pair_t* pair;
pair = ase_awk_map_get (map, keyptr, keylen);
if (pair == ASE_NULL) return ASE_NULL;
*val = PAIR_VAL(pair);
return pair;
}
ase_awk_pair_t* ase_awk_map_setpair (
ase_awk_map_t* map, ase_awk_pair_t* pair, void* val)
{
/* use this function with care */
if (PAIR_VAL(pair) != val)
{
if (map->freeval != ASE_NULL)
{
map->freeval (map->owner, PAIR_VAL(pair));
}
PAIR_VAL(pair) = val;
}
return pair;
}
int ase_awk_map_remove (
ase_awk_map_t* map, ase_char_t* keyptr, ase_size_t keylen)
{
ase_awk_pair_t* pair, * prev;
ase_size_t hc;
hc = hashkey(keyptr,keylen) % map->capa;
pair = map->buck[hc];
prev = ASE_NULL;
while (pair != ASE_NULL)
{
if (ase_strxncmp (
PAIR_KEYPTR(pair), PAIR_KEYLEN(pair),
keyptr, keylen) == 0)
{
if (prev == ASE_NULL)
map->buck[hc] = PAIR_LNK(pair);
else prev->next = PAIR_LNK(pair);
FREE_PAIR (map, pair);
map->size--;
return 0;
}
prev = pair;
pair = PAIR_LNK(pair);
}
return -1;
}
int ase_awk_map_walk (ase_awk_map_t* map,
int (*walker) (ase_awk_pair_t*,void*), void* arg)
{
ase_size_t i;
ase_awk_pair_t* pair, * next;
for (i = 0; i < map->capa; i++)
{
pair = map->buck[i];
while (pair != ASE_NULL)
{
next = PAIR_LNK(pair);
if (walker(pair,arg) == -1) return -1;
pair = next;
}
}
return 0;
}
static ase_size_t hashkey (const ase_char_t* keyptr, ase_size_t keylen)
{
ase_size_t n = 0, i;
const ase_char_t* end = keyptr + keylen;
while (keyptr < end)
{
ase_byte_t* bp = (ase_byte_t*)keyptr;
for (i = 0; i < ASE_SIZEOF(*keyptr); i++) n = n * 31 + *bp++;
keyptr++;
}
return n;
}

89
ase/awk/map.h Normal file
View File

@ -0,0 +1,89 @@
/*
* $Id: map.h,v 1.3 2007/04/30 05:47:33 bacon Exp $
*
* {License}
*/
#ifndef _ASE_AWK_MAP_H_
#define _ASE_AWK_MAP_H_
#ifndef _ASE_AWK_AWK_H_
#error Include <ase/awk/awk.h> first
#endif
/*typedef struct ase_awk_map_t ase_awk_map_t;*/
typedef struct ase_awk_pair_t ase_awk_pair_t;
struct ase_awk_pair_t
{
struct
{
ase_char_t* ptr;
ase_size_t len;
} key;
void* val;
ase_awk_pair_t* next;
};
struct ase_awk_map_t
{
void* owner;
ase_size_t size;
ase_size_t capa;
ase_awk_pair_t** buck;
void (*freeval) (void*,void*);
ase_awk_t* awk;
ase_bool_t __dynamic;
};
#define PAIR_KEYPTR(p) ((p)->key.ptr)
#define PAIR_KEYLEN(p) ((p)->key.len)
#define PAIR_VAL(p) ((p)->val)
#define PAIR_LNK(p) ((p)->next)
#ifdef __cplusplus
extern "C" {
#endif
ase_awk_map_t* ase_awk_map_open (
ase_awk_map_t* map, void* owner, ase_size_t capa,
void(*freeval)(void*,void*), ase_awk_t* awk);
void ase_awk_map_close (ase_awk_map_t* map);
void ase_awk_map_clear (ase_awk_map_t* map);
ase_size_t ase_awk_map_getsize (ase_awk_map_t* map);
ase_awk_pair_t* ase_awk_map_get (
ase_awk_map_t* map, const ase_char_t* keyptr, ase_size_t keylen);
ase_awk_pair_t* ase_awk_map_put (
ase_awk_map_t* map, ase_char_t* keyptr, ase_size_t keylen, void* val);
int ase_awk_map_putx (
ase_awk_map_t* map, ase_char_t* keyptr, ase_size_t keylen,
void* val, ase_awk_pair_t** px);
ase_awk_pair_t* ase_awk_map_set (
ase_awk_map_t* map, ase_char_t* keyptr, ase_size_t keylen, void* val);
ase_awk_pair_t* ase_awk_map_getpair (
ase_awk_map_t* map, const ase_char_t* keyptr, ase_size_t keylen,
void** val);
ase_awk_pair_t* ase_awk_map_setpair (
ase_awk_map_t* map, ase_awk_pair_t* pair, void* val);
int ase_awk_map_remove (
ase_awk_map_t* map, ase_char_t* keyptr, ase_size_t keylen);
int ase_awk_map_walk (ase_awk_map_t* map,
int (*walker)(ase_awk_pair_t*,void*), void* arg);
#ifdef __cplusplus
}
#endif
#endif

905
ase/awk/misc.c Normal file
View File

@ -0,0 +1,905 @@
/*
* $Id: misc.c,v 1.3 2007/04/30 05:47:33 bacon Exp $
*
* {License}
*/
#include <ase/awk/awk_i.h>
void* ase_awk_malloc (ase_awk_t* awk, ase_size_t size)
{
return ASE_AWK_MALLOC (awk, size);
}
void ase_awk_free (ase_awk_t* awk, void* ptr)
{
ASE_AWK_FREE (awk, ptr);
}
ase_long_t ase_awk_strxtolong (
ase_awk_t* awk, const ase_char_t* str, ase_size_t len,
int base, const ase_char_t** endptr)
{
ase_long_t n = 0;
const ase_char_t* p;
const ase_char_t* end;
ase_size_t rem;
int digit, negative = 0;
ASE_ASSERT (base < 37);
p = str;
end = str + len;
/* strip off leading spaces */
/*while (ASE_AWK_ISSPACE(awk,*p)) p++;*/
/* check for a sign */
/*while (*p != ASE_T('\0')) */
while (p < end)
{
if (*p == ASE_T('-'))
{
negative = ~negative;
p++;
}
else if (*p == ASE_T('+')) p++;
else break;
}
/* check for a binary/octal/hexadecimal notation */
rem = end - p;
if (base == 0)
{
if (rem >= 1 && *p == ASE_T('0'))
{
p++;
if (rem == 1) base = 8;
else if (*p == ASE_T('x') || *p == ASE_T('X'))
{
p++; base = 16;
}
else if (*p == ASE_T('b') || *p == ASE_T('B'))
{
p++; base = 2;
}
else base = 8;
}
else base = 10;
}
else if (rem >= 2 && base == 16)
{
if (*p == ASE_T('0') &&
(*(p+1) == ASE_T('x') || *(p+1) == ASE_T('X'))) p += 2;
}
else if (rem >= 2 && base == 2)
{
if (*p == ASE_T('0') &&
(*(p+1) == ASE_T('b') || *(p+1) == ASE_T('B'))) p += 2;
}
/* process the digits */
/*while (*p != ASE_T('\0'))*/
while (p < end)
{
if (*p >= ASE_T('0') && *p <= ASE_T('9'))
digit = *p - ASE_T('0');
else if (*p >= ASE_T('A') && *p <= ASE_T('Z'))
digit = *p - ASE_T('A') + 10;
else if (*p >= ASE_T('a') && *p <= ASE_T('z'))
digit = *p - ASE_T('a') + 10;
else break;
if (digit >= base) break;
n = n * base + digit;
p++;
}
if (endptr != ASE_NULL) *endptr = p;
return (negative)? -n: n;
}
/*
* ase_awk_strtoreal is almost a replica of strtod.
*
* strtod.c --
*
* Source code for the "strtod" library procedure.
*
* Copyright (c) 1988-1993 The Regents of the University of California.
* Copyright (c) 1994 Sun Microsystems, Inc.
*
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
* fee is hereby granted, provided that the above copyright
* notice appear in all copies. The University of California
* makes no representations about the suitability of this
* software for any purpose. It is provided "as is" without
* express or implied warranty.
*/
#define MAX_EXPONENT 511
ase_real_t ase_awk_strtoreal (ase_awk_t* awk, const ase_char_t* str)
{
/*
* Table giving binary powers of 10. Entry is 10^2^i.
* Used to convert decimal exponents into floating-point numbers.
*/
static ase_real_t powers_of_10[] =
{
10., 100., 1.0e4, 1.0e8, 1.0e16,
1.0e32, 1.0e64, 1.0e128, 1.0e256
};
ase_real_t fraction, dbl_exp, * d;
const ase_char_t* p;
ase_cint_t c;
int exp = 0; /* Esseonent read from "EX" field */
/*
* Esseonent that derives from the fractional part. Under normal
* circumstatnces, it is the negative of the number of digits in F.
* However, if I is very long, the last digits of I get dropped
* (otherwise a long I with a large negative exponent could cause an
* unnecessary overflow on I alone). In this case, frac_exp is
* incremented one for each dropped digit.
*/
int frac_exp;
int mant_size; /* Number of digits in mantissa. */
int dec_pt; /* Number of mantissa digits BEFORE decimal point */
const ase_char_t *pexp; /* Temporarily holds location of exponent in string */
int negative = 0, exp_negative = 0;
p = str;
/* strip off leading blanks */
/*while (ASE_AWK_ISSPACE(awk,*p)) p++;*/
/* check for a sign */
while (*p != ASE_T('\0'))
{
if (*p == ASE_T('-'))
{
negative = ~negative;
p++;
}
else if (*p == ASE_T('+')) p++;
else break;
}
/* Count the number of digits in the mantissa (including the decimal
* point), and also locate the decimal point. */
dec_pt = -1;
for (mant_size = 0; ; mant_size++)
{
c = *p;
if (!ASE_AWK_ISDIGIT (awk, c))
{
if ((c != ASE_T('.')) || (dec_pt >= 0)) break;
dec_pt = mant_size;
}
p++;
}
/*
* Now suck up the digits in the mantissa. Use two integers to
* collect 9 digits each (this is faster than using floating-point).
* If the mantissa has more than 18 digits, ignore the extras, since
* they can't affect the value anyway.
*/
pexp = p;
p -= mant_size;
if (dec_pt < 0)
{
dec_pt = mant_size;
}
else
{
mant_size--; /* One of the digits was the point */
}
if (mant_size > 18)
{
frac_exp = dec_pt - 18;
mant_size = 18;
}
else
{
frac_exp = dec_pt - mant_size;
}
if (mant_size == 0)
{
fraction = 0.0;
/*p = str;*/
p = pexp;
goto done;
}
else
{
int frac1, frac2;
frac1 = 0;
for ( ; mant_size > 9; mant_size--)
{
c = *p;
p++;
if (c == ASE_T('.'))
{
c = *p;
p++;
}
frac1 = 10 * frac1 + (c - ASE_T('0'));
}
frac2 = 0;
for (; mant_size > 0; mant_size--) {
c = *p;
p++;
if (c == ASE_T('.'))
{
c = *p;
p++;
}
frac2 = 10*frac2 + (c - ASE_T('0'));
}
fraction = (1.0e9 * frac1) + frac2;
}
/* Skim off the exponent */
p = pexp;
if ((*p == ASE_T('E')) || (*p == ASE_T('e')))
{
p++;
if (*p == ASE_T('-'))
{
exp_negative = 1;
p++;
}
else
{
if (*p == ASE_T('+')) p++;
exp_negative = 0;
}
if (!ASE_AWK_ISDIGIT (awk, *p))
{
/* p = pexp; */
/* goto done; */
goto no_exp;
}
while (ASE_AWK_ISDIGIT (awk, *p))
{
exp = exp * 10 + (*p - ASE_T('0'));
p++;
}
}
no_exp:
if (exp_negative) exp = frac_exp - exp;
else exp = frac_exp + exp;
/*
* Generate a floating-point number that represents the exponent.
* Do this by processing the exponent one bit at a time to combine
* many powers of 2 of 10. Then combine the exponent with the
* fraction.
*/
if (exp < 0)
{
exp_negative = 1;
exp = -exp;
}
else exp_negative = 0;
if (exp > MAX_EXPONENT) exp = MAX_EXPONENT;
dbl_exp = 1.0;
for (d = powers_of_10; exp != 0; exp >>= 1, d++)
{
if (exp & 01) dbl_exp *= *d;
}
if (exp_negative) fraction /= dbl_exp;
else fraction *= dbl_exp;
done:
return (negative)? -fraction: fraction;
}
ase_real_t ase_awk_strxtoreal (
ase_awk_t* awk, const ase_char_t* str, ase_size_t len,
const ase_char_t** endptr)
{
/*
* Table giving binary powers of 10. Entry is 10^2^i.
* Used to convert decimal exponents into floating-point numbers.
*/
static ase_real_t powers_of_10[] =
{
10., 100., 1.0e4, 1.0e8, 1.0e16,
1.0e32, 1.0e64, 1.0e128, 1.0e256
};
ase_real_t fraction, dbl_exp, * d;
const ase_char_t* p, * end;
ase_cint_t c;
int exp = 0; /* Esseonent read from "EX" field */
/*
* Esseonent that derives from the fractional part. Under normal
* circumstatnces, it is the negative of the number of digits in F.
* However, if I is very long, the last digits of I get dropped
* (otherwise a long I with a large negative exponent could cause an
* unnecessary overflow on I alone). In this case, frac_exp is
* incremented one for each dropped digit.
*/
int frac_exp;
int mant_size; /* Number of digits in mantissa. */
int dec_pt; /* Number of mantissa digits BEFORE decimal point */
const ase_char_t *pexp; /* Temporarily holds location of exponent in string */
int negative = 0, exp_negative = 0;
p = str;
end = str + len;
/* Strip off leading blanks and check for a sign */
/*while (ASE_AWK_ISSPACE(awk,*p)) p++;*/
/*while (*p != ASE_T('\0')) */
while (p < end)
{
if (*p == ASE_T('-'))
{
negative = ~negative;
p++;
}
else if (*p == ASE_T('+')) p++;
else break;
}
/* Count the number of digits in the mantissa (including the decimal
* point), and also locate the decimal point. */
dec_pt = -1;
/*for (mant_size = 0; ; mant_size++) */
for (mant_size = 0; p < end; mant_size++)
{
c = *p;
if (!ASE_AWK_ISDIGIT (awk, c))
{
if (c != ASE_T('.') || dec_pt >= 0) break;
dec_pt = mant_size;
}
p++;
}
/*
* Now suck up the digits in the mantissa. Use two integers to
* collect 9 digits each (this is faster than using floating-point).
* If the mantissa has more than 18 digits, ignore the extras, since
* they can't affect the value anyway.
*/
pexp = p;
p -= mant_size;
if (dec_pt < 0)
{
dec_pt = mant_size;
}
else
{
mant_size--; /* One of the digits was the point */
}
if (mant_size > 18) /* TODO: is 18 correct for ase_real_t??? */
{
frac_exp = dec_pt - 18;
mant_size = 18;
}
else
{
frac_exp = dec_pt - mant_size;
}
if (mant_size == 0)
{
fraction = 0.0;
/*p = str;*/
p = pexp;
goto done;
}
else
{
int frac1, frac2;
frac1 = 0;
for ( ; mant_size > 9; mant_size--)
{
c = *p;
p++;
if (c == ASE_T('.'))
{
c = *p;
p++;
}
frac1 = 10 * frac1 + (c - ASE_T('0'));
}
frac2 = 0;
for (; mant_size > 0; mant_size--) {
c = *p++;
if (c == ASE_T('.'))
{
c = *p;
p++;
}
frac2 = 10 * frac2 + (c - ASE_T('0'));
}
fraction = (1.0e9 * frac1) + frac2;
}
/* Skim off the exponent */
p = pexp;
if (p < end && (*p == ASE_T('E') || *p == ASE_T('e')))
{
p++;
if (p < end)
{
if (*p == ASE_T('-'))
{
exp_negative = 1;
p++;
}
else
{
if (*p == ASE_T('+')) p++;
exp_negative = 0;
}
}
else exp_negative = 0;
if (!(p < end && ASE_AWK_ISDIGIT (awk, *p)))
{
/*p = pexp;*/
/*goto done;*/
goto no_exp;
}
while (p < end && ASE_AWK_ISDIGIT (awk, *p))
{
exp = exp * 10 + (*p - ASE_T('0'));
p++;
}
}
no_exp:
if (exp_negative) exp = frac_exp - exp;
else exp = frac_exp + exp;
/*
* Generate a floating-point number that represents the exponent.
* Do this by processing the exponent one bit at a time to combine
* many powers of 2 of 10. Then combine the exponent with the
* fraction.
*/
if (exp < 0)
{
exp_negative = 1;
exp = -exp;
}
else exp_negative = 0;
if (exp > MAX_EXPONENT) exp = MAX_EXPONENT;
dbl_exp = 1.0;
for (d = powers_of_10; exp != 0; exp >>= 1, d++)
{
if (exp & 01) dbl_exp *= *d;
}
if (exp_negative) fraction /= dbl_exp;
else fraction *= dbl_exp;
done:
if (endptr != ASE_NULL) *endptr = p;
return (negative)? -fraction: fraction;
}
ase_size_t ase_awk_longtostr (
ase_long_t value, int radix, const ase_char_t* prefix,
ase_char_t* buf, ase_size_t size)
{
ase_long_t t, rem;
ase_size_t len, ret, i;
ase_size_t prefix_len;
prefix_len = (prefix != ASE_NULL)? ase_strlen(prefix): 0;
t = value;
if (t == 0)
{
/* zero */
if (buf == ASE_NULL)
{
/* if buf is not given,
* return the number of bytes required */
return prefix_len + 1;
}
if (size < prefix_len+1)
{
/* buffer too small */
return (ase_size_t)-1;
}
for (i = 0; i < prefix_len; i++) buf[i] = prefix[i];
buf[prefix_len] = ASE_T('0');
if (size > prefix_len+1) buf[prefix_len+1] = ASE_T('\0');
return prefix_len+1;
}
/* non-zero values */
len = prefix_len;
if (t < 0) { t = -t; len++; }
while (t > 0) { len++; t /= radix; }
if (buf == ASE_NULL)
{
/* if buf is not given, return the number of bytes required */
return len;
}
if (size < len) return (ase_size_t)-1; /* buffer too small */
if (size > len) buf[len] = ASE_T('\0');
ret = len;
t = value;
if (t < 0) t = -t;
while (t > 0)
{
rem = t % radix;
if (rem >= 10)
buf[--len] = (ase_char_t)rem + ASE_T('a') - 10;
else
buf[--len] = (ase_char_t)rem + ASE_T('0');
t /= radix;
}
if (value < 0)
{
for (i = 1; i <= prefix_len; i++)
{
buf[i] = prefix[i-1];
len--;
}
buf[--len] = ASE_T('-');
}
else
{
for (i = 0; i < prefix_len; i++) buf[i] = prefix[i];
}
return ret;
}
ase_char_t* ase_awk_strtok (
ase_awk_run_t* run, const ase_char_t* s,
const ase_char_t* delim, ase_char_t** tok, ase_size_t* tok_len)
{
return ase_awk_strxntok (
run, s, ase_strlen(s),
delim, ase_strlen(delim), tok, tok_len);
}
ase_char_t* ase_awk_strxtok (
ase_awk_run_t* run, const ase_char_t* s, ase_size_t len,
const ase_char_t* delim, ase_char_t** tok, ase_size_t* tok_len)
{
return ase_awk_strxntok (
run, s, len,
delim, ase_strlen(delim), tok, tok_len);
}
ase_char_t* ase_awk_strntok (
ase_awk_run_t* run, const ase_char_t* s,
const ase_char_t* delim, ase_size_t delim_len,
ase_char_t** tok, ase_size_t* tok_len)
{
return ase_awk_strxntok (
run, s, ase_strlen(s),
delim, delim_len, tok, tok_len);
}
ase_char_t* ase_awk_strxntok (
ase_awk_run_t* run, const ase_char_t* s, ase_size_t len,
const ase_char_t* delim, ase_size_t delim_len,
ase_char_t** tok, ase_size_t* tok_len)
{
const ase_char_t* p = s, *d;
const ase_char_t* end = s + len;
const ase_char_t* sp = ASE_NULL, * ep = ASE_NULL;
const ase_char_t* delim_end = delim + delim_len;
ase_char_t c;
int delim_mode;
#define __DELIM_NULL 0
#define __DELIM_EMPTY 1
#define __DELIM_SPACES 2
#define __DELIM_NOSPACES 3
#define __DELIM_COMPOSITE 4
if (delim == ASE_NULL) delim_mode = __DELIM_NULL;
else
{
delim_mode = __DELIM_EMPTY;
for (d = delim; d < delim_end; d++)
{
if (ASE_AWK_ISSPACE(run->awk,*d))
{
if (delim_mode == __DELIM_EMPTY)
delim_mode = __DELIM_SPACES;
else if (delim_mode == __DELIM_NOSPACES)
{
delim_mode = __DELIM_COMPOSITE;
break;
}
}
else
{
if (delim_mode == __DELIM_EMPTY)
delim_mode = __DELIM_NOSPACES;
else if (delim_mode == __DELIM_SPACES)
{
delim_mode = __DELIM_COMPOSITE;
break;
}
}
}
/* TODO: verify the following statement... */
if (delim_mode == __DELIM_SPACES &&
delim_len == 1 &&
delim[0] != ASE_T(' ')) delim_mode = __DELIM_NOSPACES;
}
if (delim_mode == __DELIM_NULL)
{
/* when ASE_NULL is given as "delim", it trims off the
* leading and trailing spaces characters off the source
* string "s" eventually. */
while (p < end && ASE_AWK_ISSPACE(run->awk,*p)) p++;
while (p < end)
{
c = *p;
if (!ASE_AWK_ISSPACE(run->awk,c))
{
if (sp == ASE_NULL) sp = p;
ep = p;
}
p++;
}
}
else if (delim_mode == __DELIM_EMPTY)
{
/* each character in the source string "s" becomes a token. */
if (p < end)
{
c = *p;
sp = p;
ep = p++;
}
}
else if (delim_mode == __DELIM_SPACES)
{
/* each token is delimited by space characters. all leading
* and trailing spaces are removed. */
while (p < end && ASE_AWK_ISSPACE(run->awk,*p)) p++;
while (p < end)
{
c = *p;
if (ASE_AWK_ISSPACE(run->awk,c)) break;
if (sp == ASE_NULL) sp = p;
ep = p++;
}
while (p < end && ASE_AWK_ISSPACE(run->awk,*p)) p++;
}
else if (delim_mode == __DELIM_NOSPACES)
{
/* each token is delimited by one of charaters
* in the delimeter set "delim". */
if (run->global.ignorecase)
{
while (p < end)
{
c = ASE_AWK_TOUPPER(run->awk, *p);
for (d = delim; d < delim_end; d++)
{
if (c == ASE_AWK_TOUPPER(run->awk,*d)) goto exit_loop;
}
if (sp == ASE_NULL) sp = p;
ep = p++;
}
}
else
{
while (p < end)
{
c = *p;
for (d = delim; d < delim_end; d++)
{
if (c == *d) goto exit_loop;
}
if (sp == ASE_NULL) sp = p;
ep = p++;
}
}
}
else /* if (delim_mode == __DELIM_COMPOSITE) */
{
/* each token is delimited by one of non-space charaters
* in the delimeter set "delim". however, all space characters
* surrounding the token are removed */
while (p < end && ASE_AWK_ISSPACE(run->awk,*p)) p++;
if (run->global.ignorecase)
{
while (p < end)
{
c = ASE_AWK_TOUPPER(run->awk, *p);
if (ASE_AWK_ISSPACE(run->awk,c))
{
p++;
continue;
}
for (d = delim; d < delim_end; d++)
{
if (c == ASE_AWK_TOUPPER(run->awk,*d)) goto exit_loop;
}
if (sp == ASE_NULL) sp = p;
ep = p++;
}
}
else
{
while (p < end)
{
c = *p;
if (ASE_AWK_ISSPACE(run->awk,c))
{
p++;
continue;
}
for (d = delim; d < delim_end; d++)
{
if (c == *d) goto exit_loop;
}
if (sp == ASE_NULL) sp = p;
ep = p++;
}
}
}
exit_loop:
if (sp == ASE_NULL)
{
*tok = ASE_NULL;
*tok_len = (ase_size_t)0;
}
else
{
*tok = (ase_char_t*)sp;
*tok_len = ep - sp + 1;
}
/* if ASE_NULL is returned, this function should not be called anymore */
if (p >= end) return ASE_NULL;
if (delim_mode == __DELIM_EMPTY ||
delim_mode == __DELIM_SPACES) return (ase_char_t*)p;
return (ase_char_t*)++p;
}
ase_char_t* ase_awk_strxntokbyrex (
ase_awk_run_t* run, const ase_char_t* s, ase_size_t len,
void* rex, ase_char_t** tok, ase_size_t* tok_len, int* errnum)
{
int n;
ase_char_t* match_ptr;
ase_size_t match_len, i;
ase_size_t left = len;
const ase_char_t* ptr = s;
const ase_char_t* str_ptr = s;
ase_size_t str_len = len;
while (len > 0)
{
n = ase_awk_matchrex (
run->awk, rex,
((run->global.ignorecase)? ASE_AWK_REX_IGNORECASE: 0),
ptr, left, (const ase_char_t**)&match_ptr, &match_len,
errnum);
if (n == -1) return ASE_NULL;
if (n == 0)
{
/* no match has been found.
* return the entire string as a token */
*tok = (ase_char_t*)str_ptr;
*tok_len = str_len;
*errnum = ASE_AWK_ENOERR;
return ASE_NULL;
}
ASE_ASSERT (n == 1);
if (match_len == 0)
{
ptr++;
left--;
}
else if (run->awk->option & ASE_AWK_STRIPSPACES)
{
/* match at the beginning of the input string */
if (match_ptr == s)
{
for (i = 0; i < match_len; i++)
{
if (!ASE_AWK_ISSPACE(run->awk, match_ptr[i]))
goto exit_loop;
}
/* the match that are all spaces at the
* beginning of the input string is skipped */
ptr += match_len;
left -= match_len;
str_ptr = s + match_len;
str_len -= match_len;
}
else break;
}
else break;
}
exit_loop:
if (len == 0)
{
*tok = (ase_char_t*)str_ptr;
*tok_len = str_len;
*errnum = ASE_AWK_ENOERR;
return ASE_NULL;
}
*tok = (ase_char_t*)str_ptr;
*tok_len = match_ptr - str_ptr;
for (i = 0; i < match_len; i++)
{
if (!ASE_AWK_ISSPACE(run->awk, match_ptr[i]))
{
*errnum = ASE_AWK_ENOERR;
return match_ptr+match_len;
}
}
*errnum = ASE_AWK_ENOERR;
if (run->awk->option & ASE_AWK_STRIPSPACES)
{
return (match_ptr+match_len >= s+len)?
ASE_NULL: (match_ptr+match_len);
}
else
{
return (match_ptr+match_len > s+len)?
ASE_NULL: (match_ptr+match_len);
}
}

45
ase/awk/misc.h Normal file
View File

@ -0,0 +1,45 @@
/*
* $Id: misc.h,v 1.3 2007/04/30 05:47:33 bacon Exp $
*
* {License}
*/
#ifndef _ASE_AWK_MISC_H_
#define _ASE_AWK_MISC_H_
#ifndef _ASE_AWK_AWK_H_
#error Never include this file directly. Include <ase/awk/awk.h> instead
#endif
#ifdef __cplusplus
extern "C" {
#endif
ase_char_t* ase_awk_strtok (
ase_awk_run_t* run, const ase_char_t* s,
const ase_char_t* delim, ase_char_t** tok, ase_size_t* tok_len);
ase_char_t* ase_awk_strxtok (
ase_awk_run_t* run, const ase_char_t* s, ase_size_t len,
const ase_char_t* delim, ase_char_t** tok, ase_size_t* tok_len);
ase_char_t* ase_awk_strntok (
ase_awk_run_t* run, const ase_char_t* s,
const ase_char_t* delim, ase_size_t delim_len,
ase_char_t** tok, ase_size_t* tok_len);
ase_char_t* ase_awk_strxntok (
ase_awk_run_t* run, const ase_char_t* s, ase_size_t len,
const ase_char_t* delim, ase_size_t delim_len,
ase_char_t** tok, ase_size_t* tok_len);
ase_char_t* ase_awk_strxntokbyrex (
ase_awk_run_t* run, const ase_char_t* s, ase_size_t len,
void* rex, ase_char_t** tok, ase_size_t* tok_len, int* errnum);
#ifdef __cplusplus
}
#endif
#endif

5113
ase/awk/parse.c Normal file

File diff suppressed because it is too large Load Diff

29
ase/awk/parse.h Normal file
View File

@ -0,0 +1,29 @@
/*
* $Id: parse.h,v 1.3 2007/04/30 05:47:33 bacon Exp $
*
* {License}
*/
#ifndef _ASE_AWK_PARSE_H_
#define _ASE_AWK_PARSE_H_
#ifndef _ASE_AWK_AWK_H_
#error Never include this file directly. Include <ase/awk/awk.h> instead
#endif
#ifdef __cplusplus
extern "C" {
#endif
int ase_awk_putsrcstr (ase_awk_t* awk, const ase_char_t* str);
int ase_awk_putsrcstrx (
ase_awk_t* awk, const ase_char_t* str, ase_size_t len);
const ase_char_t* ase_awk_getglobalname (
ase_awk_t* awk, ase_size_t idx, ase_size_t* len);
#ifdef __cplusplus
}
#endif
#endif

449
ase/awk/rec.c Normal file
View File

@ -0,0 +1,449 @@
/*
* $Id: rec.c,v 1.3 2007/04/30 05:47:33 bacon Exp $
*
* {License}
*/
#include <ase/awk/awk_i.h>
static int __split_record (ase_awk_run_t* run);
static int __recomp_record_fields (
ase_awk_run_t* run, ase_size_t lv,
const ase_char_t* str, ase_size_t len);
int ase_awk_setrec (
ase_awk_run_t* run, ase_size_t idx,
const ase_char_t* str, ase_size_t len)
{
ase_awk_val_t* v;
if (idx == 0)
{
if (str == ASE_STR_BUF(&run->inrec.line) &&
len == ASE_STR_LEN(&run->inrec.line))
{
if (ase_awk_clrrec (run, ase_true) == -1) return -1;
}
else
{
if (ase_awk_clrrec (run, ase_false) == -1) return -1;
if (ase_str_ncpy (&run->inrec.line, str, len) == (ase_size_t)-1)
{
ase_awk_clrrec (run, ase_false);
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1;
}
}
v = ase_awk_makestrval (run, str, len);
if (v == ASE_NULL)
{
ase_awk_clrrec (run, ase_false);
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1;
}
ASE_ASSERT (run->inrec.d0->type == ASE_AWK_VAL_NIL);
/* d0 should be cleared before the next line is reached
* as it doesn't call ase_awk_refdownval on run->inrec.d0 */
run->inrec.d0 = v;
ase_awk_refupval (run, v);
if (__split_record (run) == -1)
{
ase_awk_clrrec (run, ase_false);
return -1;
}
}
else
{
if (__recomp_record_fields (run, idx, str, len) == -1)
{
ase_awk_clrrec (run, ase_false);
return -1;
}
/* recompose $0 */
v = ase_awk_makestrval (run,
ASE_STR_BUF(&run->inrec.line),
ASE_STR_LEN(&run->inrec.line));
if (v == ASE_NULL)
{
ase_awk_clrrec (run, ase_false);
ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1;
}
ase_awk_refdownval (run, run->inrec.d0);
run->inrec.d0 = v;
ase_awk_refupval (run, v);
}
return 0;
}
static int __split_record (ase_awk_run_t* run)
{
ase_char_t* p, * tok;
ase_size_t len, tok_len, nflds;
ase_awk_val_t* v, * fs;
ase_char_t* fs_ptr, * fs_free;
ase_size_t fs_len;
int errnum;
/* inrec should be cleared before __split_record is called */
ASE_ASSERT (run->inrec.nflds == 0);
/* get FS */
fs = ase_awk_getglobal (run, ASE_AWK_GLOBAL_FS);
if (fs->type == ASE_AWK_VAL_NIL)
{
fs_ptr = ASE_T(" ");
fs_len = 1;
fs_free = ASE_NULL;
}
else if (fs->type == ASE_AWK_VAL_STR)
{
fs_ptr = ((ase_awk_val_str_t*)fs)->buf;
fs_len = ((ase_awk_val_str_t*)fs)->len;
fs_free = ASE_NULL;
}
else
{
fs_ptr = ase_awk_valtostr (
run, fs, ASE_AWK_VALTOSTR_CLEAR, ASE_NULL, &fs_len);
if (fs_ptr == ASE_NULL) return -1;
fs_free = fs_ptr;
}
/* scan the input record to count the fields */
p = ASE_STR_BUF(&run->inrec.line);
len = ASE_STR_LEN(&run->inrec.line);
nflds = 0;
while (p != ASE_NULL)
{
if (fs_len <= 1)
{
p = ase_awk_strxntok (run,
p, len, fs_ptr, fs_len, &tok, &tok_len);
}
else
{
p = ase_awk_strxntokbyrex (run, p, len,
run->global.fs, &tok, &tok_len, &errnum);
if (p == ASE_NULL && errnum != ASE_AWK_ENOERR)
{
if (fs_free != ASE_NULL)
ASE_AWK_FREE (run->awk, fs_free);
ase_awk_setrunerror (run, errnum, 0, ASE_NULL, 0);
return -1;
}
}
if (nflds == 0 && p == ASE_NULL && tok_len == 0)
{
/* there are no fields. it can just return here
* as ase_awk_clrrec has been called before this */
if (fs_free != ASE_NULL) ASE_AWK_FREE (run->awk, fs_free);
return 0;
}
ASE_ASSERT ((tok != ASE_NULL && tok_len > 0) || tok_len == 0);
nflds++;
len = ASE_STR_LEN(&run->inrec.line) -
(p - ASE_STR_BUF(&run->inrec.line));
}
/* allocate space */
if (nflds > run->inrec.maxflds)
{
void* tmp = ASE_AWK_MALLOC (
run->awk, ASE_SIZEOF(*run->inrec.flds) * nflds);
if (tmp == ASE_NULL)
{
if (fs_free != ASE_NULL) ASE_AWK_FREE (run->awk, fs_free);
ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1;
}
if (run->inrec.flds != ASE_NULL)
ASE_AWK_FREE (run->awk, run->inrec.flds);
run->inrec.flds = tmp;
run->inrec.maxflds = nflds;
}
/* scan again and split it */
p = ASE_STR_BUF(&run->inrec.line);
len = ASE_STR_LEN(&run->inrec.line);
while (p != ASE_NULL)
{
if (fs_len <= 1)
{
p = ase_awk_strxntok (
run, p, len, fs_ptr, fs_len, &tok, &tok_len);
}
else
{
p = ase_awk_strxntokbyrex (run, p, len,
run->global.fs, &tok, &tok_len, &errnum);
if (p == ASE_NULL && errnum != ASE_AWK_ENOERR)
{
if (fs_free != ASE_NULL)
ASE_AWK_FREE (run->awk, fs_free);
ase_awk_setrunerror (run, errnum, 0, ASE_NULL, 0);
return -1;
}
}
ASE_ASSERT ((tok != ASE_NULL && tok_len > 0) || tok_len == 0);
run->inrec.flds[run->inrec.nflds].ptr = tok;
run->inrec.flds[run->inrec.nflds].len = tok_len;
run->inrec.flds[run->inrec.nflds].val =
ase_awk_makestrval (run, tok, tok_len);
if (run->inrec.flds[run->inrec.nflds].val == ASE_NULL)
{
if (fs_free != ASE_NULL) ASE_AWK_FREE (run->awk, fs_free);
ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1;
}
ase_awk_refupval (run, run->inrec.flds[run->inrec.nflds].val);
run->inrec.nflds++;
len = ASE_STR_LEN(&run->inrec.line) -
(p - ASE_STR_BUF(&run->inrec.line));
}
if (fs_free != ASE_NULL) ASE_AWK_FREE (run->awk, fs_free);
/* set the number of fields */
v = ase_awk_makeintval (run, (ase_long_t)nflds);
if (v == ASE_NULL)
{
ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1;
}
if (ase_awk_setglobal (run, ASE_AWK_GLOBAL_NF, v) == -1) return -1;
ASE_ASSERT (nflds == run->inrec.nflds);
return 0;
}
int ase_awk_clrrec (ase_awk_run_t* run, ase_bool_t skip_inrec_line)
{
ase_size_t i;
int n = 0;
if (run->inrec.d0 != ase_awk_val_nil)
{
ase_awk_refdownval (run, run->inrec.d0);
run->inrec.d0 = ase_awk_val_nil;
}
if (run->inrec.nflds > 0)
{
ASE_ASSERT (run->inrec.flds != ASE_NULL);
for (i = 0; i < run->inrec.nflds; i++)
{
ASE_ASSERT (run->inrec.flds[i].val != ASE_NULL);
ase_awk_refdownval (run, run->inrec.flds[i].val);
}
run->inrec.nflds = 0;
if (ase_awk_setglobal (
run, ASE_AWK_GLOBAL_NF, ase_awk_val_zero) == -1)
{
/* first of all, this should never happen.
* if it happened, it would return an error
* after all the clearance tasks */
n = -1;
}
}
ASE_ASSERT (run->inrec.nflds == 0);
if (!skip_inrec_line) ase_str_clear (&run->inrec.line);
return n;
}
static int __recomp_record_fields (
ase_awk_run_t* run, ase_size_t lv,
const ase_char_t* str, ase_size_t len)
{
ase_awk_val_t* v;
ase_size_t max, i, nflds;
/* recomposes the record and the fields when $N has been assigned
* a new value and recomputes NF accordingly */
ASE_ASSERT (lv > 0);
max = (lv > run->inrec.nflds)? lv: run->inrec.nflds;
nflds = run->inrec.nflds;
if (max > run->inrec.maxflds)
{
void* tmp;
/* if the given field number is greater than the maximum
* number of fields that the current record can hold,
* the field spaces are resized */
if (run->awk->prmfns.mmgr.realloc != ASE_NULL)
{
tmp = ASE_AWK_REALLOC (
run->awk, run->inrec.flds,
ASE_SIZEOF(*run->inrec.flds) * max);
if (tmp == ASE_NULL)
{
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1;
}
}
else
{
tmp = ASE_AWK_MALLOC (
run->awk, ASE_SIZEOF(*run->inrec.flds) * max);
if (tmp == ASE_NULL)
{
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1;
}
if (run->inrec.flds != ASE_NULL)
{
ase_memcpy (tmp, run->inrec.flds,
ASE_SIZEOF(*run->inrec.flds)*run->inrec.maxflds);
ASE_AWK_FREE (run->awk, run->inrec.flds);
}
}
run->inrec.flds = tmp;
run->inrec.maxflds = max;
}
lv = lv - 1; /* adjust the value to 0-based index */
ase_str_clear (&run->inrec.line);
for (i = 0; i < max; i++)
{
if (i > 0)
{
if (ase_str_ncat (
&run->inrec.line,
run->global.ofs.ptr,
run->global.ofs.len) == (ase_size_t)-1)
{
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1;
}
}
if (i == lv)
{
ase_awk_val_t* tmp;
run->inrec.flds[i].ptr =
ASE_STR_BUF(&run->inrec.line) +
ASE_STR_LEN(&run->inrec.line);
run->inrec.flds[i].len = len;
if (ase_str_ncat (
&run->inrec.line, str, len) == (ase_size_t)-1)
{
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1;
}
tmp = ase_awk_makestrval (run, str,len);
if (tmp == ASE_NULL)
{
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1;
}
if (i < nflds)
ase_awk_refdownval (run, run->inrec.flds[i].val);
else run->inrec.nflds++;
run->inrec.flds[i].val = tmp;
ase_awk_refupval (run, tmp);
}
else if (i >= nflds)
{
run->inrec.flds[i].ptr =
ASE_STR_BUF(&run->inrec.line) +
ASE_STR_LEN(&run->inrec.line);
run->inrec.flds[i].len = 0;
if (ase_str_cat (
&run->inrec.line, ASE_T("")) == (ase_size_t)-1)
{
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1;
}
/* ase_awk_refdownval should not be called over
* run->inrec.flds[i].val as it is not initialized
* to any valid values */
/*ase_awk_refdownval (run, run->inrec.flds[i].val);*/
run->inrec.flds[i].val = ase_awk_val_zls;
ase_awk_refupval (run, ase_awk_val_zls);
run->inrec.nflds++;
}
else
{
ase_awk_val_str_t* tmp;
tmp = (ase_awk_val_str_t*)run->inrec.flds[i].val;
run->inrec.flds[i].ptr =
ASE_STR_BUF(&run->inrec.line) +
ASE_STR_LEN(&run->inrec.line);
run->inrec.flds[i].len = tmp->len;
if (ase_str_ncat (&run->inrec.line,
tmp->buf, tmp->len) == (ase_size_t)-1)
{
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1;
}
}
}
v = ase_awk_getglobal (run, ASE_AWK_GLOBAL_NF);
ASE_ASSERT (v->type == ASE_AWK_VAL_INT);
if (((ase_awk_val_int_t*)v)->val != max)
{
v = ase_awk_makeintval (run, (ase_long_t)max);
if (v == ASE_NULL)
{
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return -1;
}
if (ase_awk_setglobal (
run, ASE_AWK_GLOBAL_NF, v) == -1) return -1;
}
return 0;
}

1880
ase/awk/rex.c Normal file

File diff suppressed because it is too large Load Diff

75
ase/awk/rex.h Normal file
View File

@ -0,0 +1,75 @@
/*
* $Id: rex.h,v 1.3 2007/04/30 05:47:33 bacon Exp $
*
* {License}
*/
#ifndef _ASE_AWK_REX_H_
#define _ASE_AWK_REX_H_
#ifndef _ASE_AWK_AWK_H_
#error Never include this file directly. Include <ase/awk/awk.h> instead
#endif
/*
* Regular Esseression Syntax
* A regular expression is zero or more branches, separated by '|'.
* ......
* ......
*
* Compiled form of a regular expression:
*
* | expression |
* | header | branch | branch | branch |
* | nb | el | na | bl | cmd | arg | cmd | arg | na | bl | cmd | arg | na | bl | cmd |
*
* nb: the number of branches
* el: the length of a expression including the length of nb and el
* na: the number of atoms
* bl: the length of a branch including the length of na and bl
* cmd: The command and repetition info encoded together.
* Some commands require an argument to follow them but some other don't.
* It is encoded as follows:
*
* Subexpressions can be nested by having the command "GROUP"
* and a subexpression as its argument.
*
* Examples:
* a.c -> |1|6|5|ORD_CHAR(no bound)|a|ANY_CHAR(no bound)|ORD_CHAR(no bound)|c|
* ab|xy -> |2|10|4|ORD_CHAR(no bound)|a|ORD_CHAR(no bound)|b|4|ORD_CHAR(no bound)|x|ORD_CHAR(no bound)|y|
*/
#define ASE_AWK_REX_NA(code) (*(ase_size_t*)(code))
#define ASE_AWK_REX_LEN(code) \
(*(ase_size_t*)((ase_byte_t*)(code)+ASE_SIZEOF(ase_size_t)))
enum ase_awk_rex_opt_t
{
ASE_AWK_REX_IGNORECASE = (1 << 0)
};
#ifdef __cplusplus
extern "C" {
#endif
void* ase_awk_buildrex (
ase_awk_t* awk, const ase_char_t* ptn,
ase_size_t len, int* errnum);
int ase_awk_matchrex (
ase_awk_t* awk, void* code, int option,
const ase_char_t* str, ase_size_t len,
const ase_char_t** match_ptr, ase_size_t* match_len, int* errnum);
void ase_awk_freerex (ase_awk_t* awk, void* code);
ase_bool_t ase_awk_isemptyrex (ase_awk_t* awk, void* code);
void ase_awk_dprintrex (ase_awk_t* awk, void* rex);
#ifdef __cplusplus
}
#endif
#endif

7053
ase/awk/run.c Normal file

File diff suppressed because it is too large Load Diff

119
ase/awk/run.h Normal file
View File

@ -0,0 +1,119 @@
/*
* $Id: run.h,v 1.3 2007/04/30 05:47:33 bacon Exp $
*
* {License}
*/
#ifndef _ASE_AWK_RUN_H_
#define _ASE_AWK_RUN_H_
#ifndef _ASE_AWK_AWK_H_
#error Never include this file directly. Include <ase/awk/awk.h> instead
#endif
enum ase_awk_assop_type_t
{
/* if you change this, you have to change __assop_str in tree.c */
ASE_AWK_ASSOP_NONE,
ASE_AWK_ASSOP_PLUS, /* += */
ASE_AWK_ASSOP_MINUS, /* -= */
ASE_AWK_ASSOP_MUL, /* *= */
ASE_AWK_ASSOP_DIV, /* /= */
ASE_AWK_ASSOP_IDIV, /* //= */
ASE_AWK_ASSOP_MOD, /* %= */
ASE_AWK_ASSOP_EXP /* **= */
};
enum ase_awk_binop_type_t
{
/* if you change this, you have to change
* __binop_str in tree.c and __binop_func in run.c accordingly. */
ASE_AWK_BINOP_LOR,
ASE_AWK_BINOP_LAND,
ASE_AWK_BINOP_IN,
ASE_AWK_BINOP_BOR,
ASE_AWK_BINOP_BXOR,
ASE_AWK_BINOP_BAND,
ASE_AWK_BINOP_EQ,
ASE_AWK_BINOP_NE,
ASE_AWK_BINOP_GT,
ASE_AWK_BINOP_GE,
ASE_AWK_BINOP_LT,
ASE_AWK_BINOP_LE,
ASE_AWK_BINOP_LSHIFT,
ASE_AWK_BINOP_RSHIFT,
ASE_AWK_BINOP_PLUS,
ASE_AWK_BINOP_MINUS,
ASE_AWK_BINOP_MUL,
ASE_AWK_BINOP_DIV,
ASE_AWK_BINOP_IDIV,
ASE_AWK_BINOP_MOD,
ASE_AWK_BINOP_EXP,
ASE_AWK_BINOP_CONCAT,
ASE_AWK_BINOP_MA,
ASE_AWK_BINOP_NM
};
enum ase_awk_unrop_type_t
{
/* if you change this, you have to change
* __unrop_str in tree.c accordingly. */
ASE_AWK_UNROP_PLUS,
ASE_AWK_UNROP_MINUS,
ASE_AWK_UNROP_NOT,
ASE_AWK_UNROP_BNOT
};
enum ase_awk_incop_type_t
{
/* if you change this, you have to change
* __incop_str in tree.c accordingly. */
ASE_AWK_INCOP_PLUS,
ASE_AWK_INCOP_MINUS
};
enum ase_awk_global_id_t
{
/* this table should match __bvtab in parse.c.
* in addition, ase_awk_setglobal also counts
* on the order of these values */
ASE_AWK_GLOBAL_ARGC,
ASE_AWK_GLOBAL_ARGV,
ASE_AWK_GLOBAL_CONVFMT,
ASE_AWK_GLOBAL_ENVIRON,
ASE_AWK_GLOBAL_FILENAME,
ASE_AWK_GLOBAL_FNR,
ASE_AWK_GLOBAL_FS,
ASE_AWK_GLOBAL_IGNORECASE,
ASE_AWK_GLOBAL_NF,
ASE_AWK_GLOBAL_NR,
ASE_AWK_GLOBAL_OFILENAME,
ASE_AWK_GLOBAL_OFMT,
ASE_AWK_GLOBAL_OFS,
ASE_AWK_GLOBAL_ORS,
ASE_AWK_GLOBAL_RLENGTH,
ASE_AWK_GLOBAL_RS,
ASE_AWK_GLOBAL_RSTART,
ASE_AWK_GLOBAL_SUBSEP
};
#ifdef __cplusplus
extern "C" {
#endif
ase_char_t* ase_awk_format (
ase_awk_run_t* run, ase_str_t* out, ase_str_t* fbu,
const ase_char_t* fmt, ase_size_t fmt_len,
ase_size_t nargs_on_stack, ase_awk_nde_t* args, ase_size_t* len);
#ifdef __cplusplus
}
#endif
#endif

239
ase/awk/tab.c Normal file
View File

@ -0,0 +1,239 @@
/*
* $Id: tab.c,v 1.3 2007/04/30 05:47:33 bacon Exp $
*
* {License}
*/
#include <ase/awk/awk_i.h>
ase_awk_tab_t* ase_awk_tab_open (ase_awk_tab_t* tab, ase_awk_t* awk)
{
if (tab == ASE_NULL)
{
tab = (ase_awk_tab_t*) ASE_AWK_MALLOC (
awk, ASE_SIZEOF(ase_awk_tab_t));
if (tab == ASE_NULL) return ASE_NULL;
tab->__dynamic = ase_true;
}
else tab->__dynamic = ase_false;
tab->awk = awk;
tab->buf = ASE_NULL;
tab->size = 0;
tab->capa = 0;
return tab;
}
void ase_awk_tab_close (ase_awk_tab_t* tab)
{
ase_awk_tab_clear (tab);
if (tab->buf != ASE_NULL)
{
ASE_AWK_FREE (tab->awk, tab->buf);
tab->buf = ASE_NULL;
tab->capa = 0;
}
if (tab->__dynamic) ASE_AWK_FREE (tab->awk, tab);
}
ase_size_t ase_awk_tab_getsize (ase_awk_tab_t* tab)
{
return tab->size;
}
ase_size_t ase_awk_tab_getcapa (ase_awk_tab_t* tab)
{
return tab->capa;
}
ase_awk_tab_t* ase_awk_tab_setcapa (ase_awk_tab_t* tab, ase_size_t capa)
{
void* tmp;
if (tab->size > capa)
{
ase_awk_tab_remove (tab, capa, tab->size - capa);
ASE_ASSERT (tab->size <= capa);
}
if (capa > 0)
{
if (tab->awk->prmfns.mmgr.realloc != ASE_NULL)
{
tmp = ASE_AWK_REALLOC (tab->awk,
tab->buf, ASE_SIZEOF(*tab->buf) * capa);
if (tmp == ASE_NULL) return ASE_NULL;
}
else
{
tmp = ASE_AWK_MALLOC (
tab->awk, ASE_SIZEOF(*tab->buf) * capa);
if (tmp == ASE_NULL) return ASE_NULL;
if (tab->buf != ASE_NULL)
{
ase_size_t x;
x = (capa > tab->capa)? tab->capa: capa;
ase_memcpy (
tmp, tab->buf,
ASE_SIZEOF(*tab->buf) * x);
ASE_AWK_FREE (tab->awk, tab->buf);
}
}
}
else
{
if (tab->buf != ASE_NULL) ASE_AWK_FREE (tab->awk, tab->buf);
tmp = ASE_NULL;
}
tab->buf = tmp;
tab->capa = capa;
return tab;
}
void ase_awk_tab_clear (ase_awk_tab_t* tab)
{
ase_size_t i;
for (i = 0; i < tab->size; i++)
{
ASE_AWK_FREE (tab->awk, tab->buf[i].name);
tab->buf[i].name = ASE_NULL;
tab->buf[i].name_len = 0;
}
tab->size = 0;
}
ase_size_t ase_awk_tab_insert (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len)
{
ase_size_t i;
ase_char_t* str_dup;
str_dup = ase_strxdup (str, len, &tab->awk->prmfns.mmgr);
if (str_dup == ASE_NULL) return (ase_size_t)-1;
if (index >= tab->capa)
{
ase_size_t capa;
if (tab->capa <= 0) capa = (index + 1);
else
{
do { capa = tab->capa * 2; } while (index >= capa);
}
if (ase_awk_tab_setcapa(tab,capa) == ASE_NULL)
{
ASE_AWK_FREE (tab->awk, str_dup);
return (ase_size_t)-1;
}
}
for (i = tab->size; i > index; i--) tab->buf[i] = tab->buf[i-1];
tab->buf[index].name = str_dup;
tab->buf[index].name_len = len;
if (index > tab->size) tab->size = index + 1;
else tab->size++;
return index;
}
ase_size_t ase_awk_tab_remove (
ase_awk_tab_t* tab, ase_size_t index, ase_size_t count)
{
ase_size_t i, j, k;
if (index >= tab->size) return 0;
if (count > tab->size - index) count = tab->size - index;
i = index;
j = index + count;
k = index + count;
while (i < k)
{
ASE_AWK_FREE (tab->awk, tab->buf[i].name);
if (j >= tab->size)
{
tab->buf[i].name = ASE_NULL;
tab->buf[i].name_len = 0;
i++;
}
else
{
tab->buf[i].name = tab->buf[j].name;
tab->buf[i].name_len = tab->buf[j].name_len;
i++; j++;
}
}
tab->size -= count;
return count;
}
ase_size_t ase_awk_tab_add (
ase_awk_tab_t* tab, const ase_char_t* str, ase_size_t len)
{
return ase_awk_tab_insert (tab, tab->size, str, len);
}
ase_size_t ase_awk_tab_find (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len)
{
ase_size_t i;
for (i = index; i < tab->size; i++)
{
if (ase_strxncmp (
tab->buf[i].name, tab->buf[i].name_len,
str, len) == 0) return i;
}
return (ase_size_t)-1;
}
ase_size_t ase_awk_tab_rfind (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len)
{
ase_size_t i;
if (index >= tab->size) return (ase_size_t)-1;
for (i = index + 1; i-- > 0; )
{
if (ase_strxncmp (
tab->buf[i].name, tab->buf[i].name_len,
str, len) == 0) return i;
}
return (ase_size_t)-1;
}
ase_size_t ase_awk_tab_rrfind (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len)
{
ase_size_t i;
if (index >= tab->size) return (ase_size_t)-1;
for (i = tab->size - index; i-- > 0; )
{
if (ase_strxncmp (
tab->buf[i].name, tab->buf[i].name_len,
str, len) == 0) return i;
}
return (ase_size_t)-1;
}

69
ase/awk/tab.h Normal file
View File

@ -0,0 +1,69 @@
/*
* $Id: tab.h,v 1.3 2007/04/30 05:47:33 bacon Exp $
*
* {License}
*/
#ifndef _ASE_AWK_TAB_H_
#define _ASE_AWK_TAB_H_
#ifndef _ASE_AWK_AWK_H_
#error Never include this file directly. Include <ase/awk/awk.h> instead
#endif
/* TODO: you have to turn this into a hash table.
as of now, this is an arrayed table. */
typedef struct ase_awk_tab_t ase_awk_tab_t;
struct ase_awk_tab_t
{
struct
{
ase_char_t* name;
ase_size_t name_len;
}* buf;
ase_size_t size;
ase_size_t capa;
ase_awk_t* awk;
ase_bool_t __dynamic;
};
#ifdef __cplusplus
extern "C" {
#endif
ase_awk_tab_t* ase_awk_tab_open (ase_awk_tab_t* tab, ase_awk_t* awk);
void ase_awk_tab_close (ase_awk_tab_t* tab);
ase_size_t ase_awk_tab_getsize (ase_awk_tab_t* tab);
ase_size_t ase_awk_tab_getcapa (ase_awk_tab_t* tab);
ase_awk_tab_t* ase_awk_tab_setcapa (ase_awk_tab_t* tab, ase_size_t capa);
void ase_awk_tab_clear (ase_awk_tab_t* tab);
ase_size_t ase_awk_tab_insert (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len);
ase_size_t ase_awk_tab_remove (
ase_awk_tab_t* tab, ase_size_t index, ase_size_t count);
ase_size_t ase_awk_tab_add (
ase_awk_tab_t* tab, const ase_char_t* str, ase_size_t len);
ase_size_t ase_awk_tab_find (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len);
ase_size_t ase_awk_tab_rfind (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len);
ase_size_t ase_awk_tab_rrfind (
ase_awk_tab_t* tab, ase_size_t index,
const ase_char_t* str, ase_size_t len);
#ifdef __cplusplus
}
#endif
#endif

1176
ase/awk/tree.c Normal file

File diff suppressed because it is too large Load Diff

403
ase/awk/tree.h Normal file
View File

@ -0,0 +1,403 @@
/*
* $Id: tree.h,v 1.3 2007/04/30 05:47:33 bacon Exp $
*
* {License}
*/
#ifndef _ASE_AWK_TREE_H_
#define _ASE_AWK_TREE_H_
#ifndef _ASE_AWK_AWK_H_
#error Never include this file directly. Include <ase/awk/awk.h> instead
#endif
enum ase_awk_nde_type_t
{
ASE_AWK_NDE_NULL,
/* statement */
ASE_AWK_NDE_BLK,
ASE_AWK_NDE_IF,
ASE_AWK_NDE_WHILE,
ASE_AWK_NDE_DOWHILE,
ASE_AWK_NDE_FOR,
ASE_AWK_NDE_FOREACH,
ASE_AWK_NDE_BREAK,
ASE_AWK_NDE_CONTINUE,
ASE_AWK_NDE_RETURN,
ASE_AWK_NDE_EXIT,
ASE_AWK_NDE_NEXT,
ASE_AWK_NDE_NEXTFILE,
ASE_AWK_NDE_DELETE,
ASE_AWK_NDE_PRINT,
ASE_AWK_NDE_PRINTF,
/* expression */
/* if you change the following values including their order,
* you should change __eval_func of __eval_expression
* in run.c accordingly */
ASE_AWK_NDE_GRP,
ASE_AWK_NDE_ASS,
ASE_AWK_NDE_EXP_BIN,
ASE_AWK_NDE_EXP_UNR,
ASE_AWK_NDE_EXP_INCPRE,
ASE_AWK_NDE_EXP_INCPST,
ASE_AWK_NDE_CND,
ASE_AWK_NDE_BFN,
ASE_AWK_NDE_AFN,
ASE_AWK_NDE_INT,
ASE_AWK_NDE_REAL,
ASE_AWK_NDE_STR,
ASE_AWK_NDE_REX,
/* keep this order for the following items otherwise, you may have
* to change __eval_incpre and __eval_incpst in run.c as well as
* ASE_AWK_VAL_REF_XXX in val.h */
ASE_AWK_NDE_NAMED,
ASE_AWK_NDE_GLOBAL,
ASE_AWK_NDE_LOCAL,
ASE_AWK_NDE_ARG,
ASE_AWK_NDE_NAMEDIDX,
ASE_AWK_NDE_GLOBALIDX,
ASE_AWK_NDE_LOCALIDX,
ASE_AWK_NDE_ARGIDX,
ASE_AWK_NDE_POS,
/* ---------------------------------- */
ASE_AWK_NDE_GETLINE
};
enum ase_awk_in_type_t
{
/* the order of these values match
* __in_type_map and __in_opt_map in extio.c */
ASE_AWK_IN_PIPE,
ASE_AWK_IN_COPROC,
ASE_AWK_IN_FILE,
ASE_AWK_IN_CONSOLE
};
enum ase_awk_out_type_t
{
/* the order of these values match
* __out_type_map and __out_opt_map in extio.c */
ASE_AWK_OUT_PIPE,
ASE_AWK_OUT_COPROC,
ASE_AWK_OUT_FILE,
ASE_AWK_OUT_FILE_APPEND,
ASE_AWK_OUT_CONSOLE
};
/* afn (awk function defined with the keyword function) */
typedef struct ase_awk_afn_t ase_awk_afn_t;
typedef struct ase_awk_nde_t ase_awk_nde_t;
typedef struct ase_awk_nde_blk_t ase_awk_nde_blk_t;
typedef struct ase_awk_nde_grp_t ase_awk_nde_grp_t;
typedef struct ase_awk_nde_ass_t ase_awk_nde_ass_t;
typedef struct ase_awk_nde_exp_t ase_awk_nde_exp_t;
typedef struct ase_awk_nde_cnd_t ase_awk_nde_cnd_t;
typedef struct ase_awk_nde_pos_t ase_awk_nde_pos_t;
#ifndef ASE_AWK_NDE_INT_DEFINED
#define ASE_AWK_NDE_INT_DEFINED
typedef struct ase_awk_nde_int_t ase_awk_nde_int_t;
#endif
#ifndef ASE_AWK_NDE_REAL_DEFINED
#define ASE_AWK_NDE_REAL_DEFINED
typedef struct ase_awk_nde_real_t ase_awk_nde_real_t;
#endif
typedef struct ase_awk_nde_str_t ase_awk_nde_str_t;
typedef struct ase_awk_nde_rex_t ase_awk_nde_rex_t;
typedef struct ase_awk_nde_var_t ase_awk_nde_var_t;
typedef struct ase_awk_nde_call_t ase_awk_nde_call_t;
typedef struct ase_awk_nde_getline_t ase_awk_nde_getline_t;
typedef struct ase_awk_nde_if_t ase_awk_nde_if_t;
typedef struct ase_awk_nde_while_t ase_awk_nde_while_t;
typedef struct ase_awk_nde_for_t ase_awk_nde_for_t;
typedef struct ase_awk_nde_foreach_t ase_awk_nde_foreach_t;
typedef struct ase_awk_nde_break_t ase_awk_nde_break_t;
typedef struct ase_awk_nde_continue_t ase_awk_nde_continue_t;
typedef struct ase_awk_nde_return_t ase_awk_nde_return_t;
typedef struct ase_awk_nde_exit_t ase_awk_nde_exit_t;
typedef struct ase_awk_nde_next_t ase_awk_nde_next_t;
typedef struct ase_awk_nde_nextfile_t ase_awk_nde_nextfile_t;
typedef struct ase_awk_nde_delete_t ase_awk_nde_delete_t;
typedef struct ase_awk_nde_print_t ase_awk_nde_print_t;
struct ase_awk_afn_t
{
ase_char_t* name;
ase_size_t name_len;
ase_size_t nargs;
ase_awk_nde_t* body;
};
#define ASE_AWK_NDE_HDR \
int type; \
ase_size_t line; \
ase_awk_nde_t* next
struct ase_awk_nde_t
{
ASE_AWK_NDE_HDR;
};
/* ASE_AWK_NDE_BLK - block statement including top-level blocks */
struct ase_awk_nde_blk_t
{
ASE_AWK_NDE_HDR;
ase_size_t nlocals;
ase_awk_nde_t* body;
};
/* ASE_AWK_NDE_GRP - expression group */
struct ase_awk_nde_grp_t
{
ASE_AWK_NDE_HDR;
ase_awk_nde_t* body;
};
/* ASE_AWK_NDE_ASS - assignment */
struct ase_awk_nde_ass_t
{
ASE_AWK_NDE_HDR;
int opcode;
ase_awk_nde_t* left;
ase_awk_nde_t* right;
};
/* ASE_AWK_NDE_EXP_BIN, ASE_AWK_NDE_EXP_UNR,
* ASE_AWK_NDE_EXP_INCPRE, ASE_AW_NDE_EXP_INCPST */
struct ase_awk_nde_exp_t
{
ASE_AWK_NDE_HDR;
int opcode;
ase_awk_nde_t* left;
ase_awk_nde_t* right; /* ASE_NULL for UNR, INCPRE, INCPST */
};
/* ASE_AWK_NDE_CND */
struct ase_awk_nde_cnd_t
{
ASE_AWK_NDE_HDR;
ase_awk_nde_t* test;
ase_awk_nde_t* left;
ase_awk_nde_t* right;
};
/* ASE_AWK_NDE_POS - positional - $1, $2, $x, etc */
struct ase_awk_nde_pos_t
{
ASE_AWK_NDE_HDR;
ase_awk_nde_t* val;
};
/* ASE_AWK_NDE_INT */
struct ase_awk_nde_int_t
{
ASE_AWK_NDE_HDR;
ase_long_t val;
ase_char_t* str;
ase_size_t len;
};
/* ASE_AWK_NDE_REAL */
struct ase_awk_nde_real_t
{
ASE_AWK_NDE_HDR;
ase_real_t val;
ase_char_t* str;
ase_size_t len;
};
/* ASE_AWK_NDE_STR */
struct ase_awk_nde_str_t
{
ASE_AWK_NDE_HDR;
ase_char_t* buf;
ase_size_t len;
};
/* ASE_AWK_NDE_REX */
struct ase_awk_nde_rex_t
{
ASE_AWK_NDE_HDR;
ase_char_t* buf;
ase_size_t len;
void* code;
};
/* ASE_AWK_NDE_NAMED, ASE_AWK_NDE_GLOBAL,
* ASE_AWK_NDE_LOCAL, ASE_AWK_NDE_ARG
* ASE_AWK_NDE_NAMEDIDX, ASE_AWK_NDE_GLOBALIDX,
* ASE_AWK_NDE_LOCALIDX, ASE_AWK_NDE_ARGIDX */
struct ase_awk_nde_var_t
{
ASE_AWK_NDE_HDR;
struct
{
ase_char_t* name;
ase_size_t name_len;
ase_size_t idxa;
} id;
ase_awk_nde_t* idx; /* ASE_NULL for non-XXXXIDX */
};
/* ASE_AWK_NDE_BFN, ASE_AWK_NDE_AFN */
struct ase_awk_nde_call_t
{
ASE_AWK_NDE_HDR;
union
{
struct
{
struct
{
ase_char_t* ptr;
ase_size_t len;
} name;
} afn;
/* minimum information of a built-in function
* needed during run-time. */
struct
{
struct
{
const ase_char_t* ptr;
ase_size_t len;
} name;
struct
{
ase_size_t min;
ase_size_t max;
const ase_char_t* spec;
} arg;
int (*handler) (
ase_awk_run_t*, const ase_char_t*, ase_size_t);
} bfn;
} what;
ase_awk_nde_t* args;
ase_size_t nargs;
};
/* ASE_AWK_NDE_GETLINE */
struct ase_awk_nde_getline_t
{
ASE_AWK_NDE_HDR;
ase_awk_nde_t* var;
int in_type; /* ASE_AWK_GETLINE_XXX */
ase_awk_nde_t* in;
};
/* ASE_AWK_NDE_IF */
struct ase_awk_nde_if_t
{
ASE_AWK_NDE_HDR;
ase_awk_nde_t* test;
ase_awk_nde_t* then_part;
ase_awk_nde_t* else_part; /* optional */
};
/* ASE_AWK_NDE_WHILE, ASE_AWK_NDE_DOWHILE */
struct ase_awk_nde_while_t
{
ASE_AWK_NDE_HDR;
ase_awk_nde_t* test;
ase_awk_nde_t* body;
};
/* ASE_AWK_NDE_FOR */
struct ase_awk_nde_for_t
{
ASE_AWK_NDE_HDR;
ase_awk_nde_t* init; /* optional */
ase_awk_nde_t* test; /* optional */
ase_awk_nde_t* incr; /* optional */
ase_awk_nde_t* body;
};
/* ASE_AWK_NDE_FOREACH */
struct ase_awk_nde_foreach_t
{
ASE_AWK_NDE_HDR;
ase_awk_nde_t* test;
ase_awk_nde_t* body;
};
/* ASE_AWK_NDE_BREAK */
struct ase_awk_nde_break_t
{
ASE_AWK_NDE_HDR;
};
/* ASE_AWK_NDE_CONTINUE */
struct ase_awk_nde_continue_t
{
ASE_AWK_NDE_HDR;
};
/* ASE_AWK_NDE_RETURN */
struct ase_awk_nde_return_t
{
ASE_AWK_NDE_HDR;
ase_awk_nde_t* val; /* optional (no return code if ASE_NULL) */
};
/* ASE_AWK_NDE_EXIT */
struct ase_awk_nde_exit_t
{
ASE_AWK_NDE_HDR;
ase_awk_nde_t* val; /* optional (no exit code if ASE_NULL) */
};
/* ASE_AWK_NDE_NEXT */
struct ase_awk_nde_next_t
{
ASE_AWK_NDE_HDR;
};
/* ASE_AWK_NDE_NEXTFILE */
struct ase_awk_nde_nextfile_t
{
ASE_AWK_NDE_HDR;
int out;
};
/* ASE_AWK_NDE_DELETE */
struct ase_awk_nde_delete_t
{
ASE_AWK_NDE_HDR;
ase_awk_nde_t* var;
};
/* ASE_AWK_NDE_PRINT */
struct ase_awk_nde_print_t
{
ASE_AWK_NDE_HDR;
ase_awk_nde_t* args;
int out_type; /* ASE_AWK_OUT_XXX */
ase_awk_nde_t* out;
};
#ifdef __cplusplus
extern "C" {
#endif
int ase_awk_prnpt (ase_awk_t* awk, ase_awk_nde_t* tree);
int ase_awk_prnptnpt (ase_awk_t* awk, ase_awk_nde_t* tree);
void ase_awk_clrpt (ase_awk_t* awk, ase_awk_nde_t* tree);
#ifdef __cplusplus
}
#endif
#endif

839
ase/awk/val.c Normal file
View File

@ -0,0 +1,839 @@
/*
* $Id: val.c,v 1.3 2007/04/30 05:47:33 bacon Exp $
*
* {License}
*/
#include <ase/awk/awk_i.h>
#ifdef DEBUG_VAL
#include <ase/utl/stdio.h>
#endif
static ase_char_t* str_to_str (
ase_awk_run_t* run, const ase_char_t* str, ase_size_t str_len,
int opt, ase_str_t* buf, ase_size_t* len);
static ase_char_t* val_int_to_str (
ase_awk_run_t* run, ase_awk_val_int_t* v,
int opt, ase_str_t* buf, ase_size_t* len);
static ase_char_t* val_real_to_str (
ase_awk_run_t* run, ase_awk_val_real_t* v,
int opt, ase_str_t* buf, ase_size_t* len);
static ase_awk_val_nil_t awk_nil = { ASE_AWK_VAL_NIL, 0 };
static ase_awk_val_str_t awk_zls = { ASE_AWK_VAL_STR, 0, ASE_T(""), 0 };
ase_awk_val_t* ase_awk_val_nil = (ase_awk_val_t*)&awk_nil;
ase_awk_val_t* ase_awk_val_zls = (ase_awk_val_t*)&awk_zls;
static ase_awk_val_int_t awk_int[] =
{
{ ASE_AWK_VAL_INT, 0, -1, ASE_NULL },
{ ASE_AWK_VAL_INT, 0, 0, ASE_NULL },
{ ASE_AWK_VAL_INT, 0, 1, ASE_NULL },
{ ASE_AWK_VAL_INT, 0, 2, ASE_NULL },
{ ASE_AWK_VAL_INT, 0, 3, ASE_NULL },
{ ASE_AWK_VAL_INT, 0, 4, ASE_NULL },
{ ASE_AWK_VAL_INT, 0, 5, ASE_NULL },
{ ASE_AWK_VAL_INT, 0, 6, ASE_NULL },
{ ASE_AWK_VAL_INT, 0, 7, ASE_NULL },
{ ASE_AWK_VAL_INT, 0, 8, ASE_NULL },
{ ASE_AWK_VAL_INT, 0, 9, ASE_NULL },
{ ASE_AWK_VAL_INT, 0, 10, ASE_NULL },
{ ASE_AWK_VAL_INT, 0, 11, ASE_NULL },
{ ASE_AWK_VAL_INT, 0, 12, ASE_NULL },
{ ASE_AWK_VAL_INT, 0, 13, ASE_NULL },
{ ASE_AWK_VAL_INT, 0, 14, ASE_NULL },
{ ASE_AWK_VAL_INT, 0, 15, ASE_NULL },
{ ASE_AWK_VAL_INT, 0, 16, ASE_NULL },
{ ASE_AWK_VAL_INT, 0, 17, ASE_NULL },
{ ASE_AWK_VAL_INT, 0, 18, ASE_NULL },
{ ASE_AWK_VAL_INT, 0, 19, ASE_NULL },
{ ASE_AWK_VAL_INT, 0, 20, ASE_NULL }
};
ase_awk_val_t* ase_awk_val_negone = (ase_awk_val_t*)&awk_int[0];
ase_awk_val_t* ase_awk_val_zero = (ase_awk_val_t*)&awk_int[1];
ase_awk_val_t* ase_awk_val_one = (ase_awk_val_t*)&awk_int[2];
ase_awk_val_t* ase_awk_makeintval (ase_awk_run_t* run, ase_long_t v)
{
ase_awk_val_int_t* val;
if (v >= awk_int[0].val &&
v <= awk_int[ASE_COUNTOF(awk_int)-1].val)
{
return (ase_awk_val_t*)&awk_int[v-awk_int[0].val];
}
if (run->icache_count > 0)
{
val = run->icache[--run->icache_count];
}
else
{
val = (ase_awk_val_int_t*) ASE_AWK_MALLOC (
run->awk, ASE_SIZEOF(ase_awk_val_int_t));
if (val == ASE_NULL) return ASE_NULL;
}
val->type = ASE_AWK_VAL_INT;
val->ref = 0;
val->val = v;
val->nde = ASE_NULL;
#ifdef DEBUG_VAL
ase_dprintf (ASE_T("makeintval => %p\n"), val);
#endif
return (ase_awk_val_t*)val;
}
ase_awk_val_t* ase_awk_makerealval (ase_awk_run_t* run, ase_real_t v)
{
ase_awk_val_real_t* val;
if (run->rcache_count > 0)
{
val = run->rcache[--run->rcache_count];
}
else
{
val = (ase_awk_val_real_t*) ASE_AWK_MALLOC (
run->awk, ASE_SIZEOF(ase_awk_val_real_t));
if (val == ASE_NULL) return ASE_NULL;
}
val->type = ASE_AWK_VAL_REAL;
val->ref = 0;
val->val = v;
val->nde = ASE_NULL;
#ifdef DEBUG_VAL
ase_dprintf (ASE_T("makerealval => %p\n"), val);
#endif
return (ase_awk_val_t*)val;
}
ase_awk_val_t* ase_awk_makestrval0 (ase_awk_run_t* run, const ase_char_t* str)
{
return ase_awk_makestrval (run, str, ase_strlen(str));
}
ase_awk_val_t* ase_awk_makestrval (
ase_awk_run_t* run, const ase_char_t* str, ase_size_t len)
{
ase_awk_val_str_t* val;
val = (ase_awk_val_str_t*) ASE_AWK_MALLOC (
run->awk, ASE_SIZEOF(ase_awk_val_str_t));
if (val == ASE_NULL) return ASE_NULL;
val->type = ASE_AWK_VAL_STR;
val->ref = 0;
val->len = len;
val->buf = ase_strxdup (str, len, &run->awk->prmfns.mmgr);
if (val->buf == ASE_NULL)
{
ASE_AWK_FREE (run->awk, val);
return ASE_NULL;
}
#ifdef DEBUG_VAL
ase_dprintf (ASE_T("makestrval => %p\n"), val);
#endif
return (ase_awk_val_t*)val;
}
ase_awk_val_t* ase_awk_makestrval_nodup (
ase_awk_run_t* run, ase_char_t* str, ase_size_t len)
{
ase_awk_val_str_t* val;
val = (ase_awk_val_str_t*) ASE_AWK_MALLOC (
run->awk, ASE_SIZEOF(ase_awk_val_str_t));
if (val == ASE_NULL) return ASE_NULL;
val->type = ASE_AWK_VAL_STR;
val->ref = 0;
val->len = len;
val->buf = str;
return (ase_awk_val_t*)val;
}
ase_awk_val_t* ase_awk_makestrval2 (
ase_awk_run_t* run,
const ase_char_t* str1, ase_size_t len1,
const ase_char_t* str2, ase_size_t len2)
{
ase_awk_val_str_t* val;
val = (ase_awk_val_str_t*) ASE_AWK_MALLOC (
run->awk, ASE_SIZEOF(ase_awk_val_str_t));
if (val == ASE_NULL) return ASE_NULL;
val->type = ASE_AWK_VAL_STR;
val->ref = 0;
val->len = len1 + len2;
val->buf = ase_strxdup2 (str1, len1, str2, len2, &run->awk->prmfns.mmgr);
if (val->buf == ASE_NULL)
{
ASE_AWK_FREE (run->awk, val);
return ASE_NULL;
}
#ifdef DEBUG_VAL
ase_dprintf (ASE_T("makestrval2 => %p\n"), val);
#endif
return (ase_awk_val_t*)val;
}
ase_awk_val_t* ase_awk_makerexval (
ase_awk_run_t* run, const ase_char_t* buf, ase_size_t len, void* code)
{
ase_awk_val_rex_t* val;
val = (ase_awk_val_rex_t*) ASE_AWK_MALLOC (
run->awk, ASE_SIZEOF(ase_awk_val_rex_t));
if (val == ASE_NULL) return ASE_NULL;
val->type = ASE_AWK_VAL_REX;
val->ref = 0;
val->len = len;
val->buf = ase_strxdup (buf, len, &run->awk->prmfns.mmgr);
if (val->buf == ASE_NULL)
{
ASE_AWK_FREE (run->awk, val);
return ASE_NULL;
}
val->code = ASE_AWK_MALLOC (run->awk, ASE_AWK_REX_LEN(code));
if (val->code == ASE_NULL)
{
ASE_AWK_FREE (run->awk, val->buf);
ASE_AWK_FREE (run->awk, val);
return ASE_NULL;
}
ase_memcpy (val->code, code, ASE_AWK_REX_LEN(code));
return (ase_awk_val_t*)val;
}
static void free_map_val (void* run, void* v)
{
#ifdef DEBUG_VAL
ase_dprintf (ASE_T("refdown in map free..."));
ase_awk_dprintval (run, v);
ase_dprintf (ASE_T("\n"));
#endif
ase_awk_refdownval (run, v);
}
ase_awk_val_t* ase_awk_makemapval (ase_awk_run_t* run)
{
ase_awk_val_map_t* val;
val = (ase_awk_val_map_t*) ASE_AWK_MALLOC (
run->awk, ASE_SIZEOF(ase_awk_val_map_t));
if (val == ASE_NULL) return ASE_NULL;
val->type = ASE_AWK_VAL_MAP;
val->ref = 0;
val->map = ase_awk_map_open (
ASE_NULL, run, 256, free_map_val, run->awk);
if (val->map == ASE_NULL)
{
ASE_AWK_FREE (run->awk, val);
return ASE_NULL;
}
return (ase_awk_val_t*)val;
}
ase_awk_val_t* ase_awk_makerefval (ase_awk_run_t* run, int id, ase_awk_val_t** adr)
{
ase_awk_val_ref_t* val;
if (run->fcache_count > 0)
{
val = run->fcache[--run->fcache_count];
}
else
{
val = (ase_awk_val_ref_t*) ASE_AWK_MALLOC (
run->awk, ASE_SIZEOF(ase_awk_val_ref_t));
if (val == ASE_NULL) return ASE_NULL;
}
val->type = ASE_AWK_VAL_REF;
val->ref = 0;
val->id = id;
val->adr = adr;
return (ase_awk_val_t*)val;
}
ase_bool_t ase_awk_isbuiltinval (ase_awk_val_t* val)
{
return val == ASE_NULL ||
val == ase_awk_val_nil ||
val == ase_awk_val_zls ||
val == ase_awk_val_zero ||
val == ase_awk_val_one ||
(val >= (ase_awk_val_t*)&awk_int[0] &&
val <= (ase_awk_val_t*)&awk_int[ASE_COUNTOF(awk_int)-1]);
}
void ase_awk_freeval (ase_awk_run_t* run, ase_awk_val_t* val, ase_bool_t cache)
{
if (ase_awk_isbuiltinval(val)) return;
#ifdef DEBUG_VAL
ase_dprintf (ASE_T("freeing [cache=%d] ... "), cache);
ase_awk_dprintval (run, val);
ase_dprintf (ASE_T("\n"));
#endif
if (val->type == ASE_AWK_VAL_NIL)
{
ASE_AWK_FREE (run->awk, val);
}
else if (val->type == ASE_AWK_VAL_INT)
{
if (cache == ase_true &&
run->icache_count < ASE_COUNTOF(run->icache))
{
run->icache[run->icache_count++] =
(ase_awk_val_int_t*)val;
}
else ASE_AWK_FREE (run->awk, val);
}
else if (val->type == ASE_AWK_VAL_REAL)
{
if (cache == ase_true &&
run->rcache_count < ASE_COUNTOF(run->rcache))
{
run->rcache[run->rcache_count++] =
(ase_awk_val_real_t*)val;
}
else ASE_AWK_FREE (run->awk, val);
}
else if (val->type == ASE_AWK_VAL_STR)
{
ASE_AWK_FREE (run->awk, ((ase_awk_val_str_t*)val)->buf);
ASE_AWK_FREE (run->awk, val);
}
else if (val->type == ASE_AWK_VAL_REX)
{
ASE_AWK_FREE (run->awk, ((ase_awk_val_rex_t*)val)->buf);
ase_awk_freerex (run->awk, ((ase_awk_val_rex_t*)val)->code);
ASE_AWK_FREE (run->awk, val);
}
else if (val->type == ASE_AWK_VAL_MAP)
{
ase_awk_map_close (((ase_awk_val_map_t*)val)->map);
ASE_AWK_FREE (run->awk, val);
}
else if (val->type == ASE_AWK_VAL_REF)
{
if (cache == ase_true &&
run->fcache_count < ASE_COUNTOF(run->fcache))
{
run->fcache[run->fcache_count++] =
(ase_awk_val_ref_t*)val;
}
else ASE_AWK_FREE (run->awk, val);
}
else
{
ASE_ASSERTX (
!"should never happen - invalid value type",
"the type of a value should be one of ASE_AWK_VAL_XXX's defined in val.h");
}
}
void ase_awk_refupval (ase_awk_run_t* run, ase_awk_val_t* val)
{
if (ase_awk_isbuiltinval(val)) return;
#ifdef DEBUG_VAL
ase_dprintf (ASE_T("ref up [ptr=%p] [count=%d] "), val, (int)val->ref);
ase_awk_dprintval (run, val);
ase_dprintf (ASE_T("\n"));
#endif
val->ref++;
}
void ase_awk_refdownval (ase_awk_run_t* run, ase_awk_val_t* val)
{
if (ase_awk_isbuiltinval(val)) return;
#ifdef DEBUG_VAL
ase_dprintf (ASE_T("ref down [ptr=%p] [count=%d]\n"), val, (int)val->ref);
ase_awk_dprintval (run, val);
ase_dprintf (ASE_T("\n"));
#endif
ASE_ASSERTX (val->ref > 0,
"the reference count of a value should be greater than zero for it to be decremented. check the source code for any bugs");
val->ref--;
if (val->ref <= 0)
{
ase_awk_freeval(run, val, ase_true);
}
}
void ase_awk_refdownval_nofree (ase_awk_run_t* run, ase_awk_val_t* val)
{
if (ase_awk_isbuiltinval(val)) return;
ASE_ASSERTX (val->ref > 0,
"the reference count of a value should be greater than zero for it to be decremented. check the source code for any bugs");
val->ref--;
}
ase_bool_t ase_awk_valtobool (ase_awk_run_t* run, ase_awk_val_t* val)
{
if (val == ASE_NULL) return ase_false;
switch (val->type)
{
case ASE_AWK_VAL_NIL:
return ase_false;
case ASE_AWK_VAL_INT:
return ((ase_awk_val_int_t*)val)->val != 0;
case ASE_AWK_VAL_REAL:
return ((ase_awk_val_real_t*)val)->val != 0.0;
case ASE_AWK_VAL_STR:
return ((ase_awk_val_str_t*)val)->len > 0;
case ASE_AWK_VAL_REX: /* TODO: is this correct? */
return ((ase_awk_val_rex_t*)val)->len > 0;
case ASE_AWK_VAL_MAP:
return ase_false; /* TODO: is this correct? */
case ASE_AWK_VAL_REF:
return ase_false; /* TODO: is this correct? */
}
ASE_ASSERTX (
!"should never happen - invalid value type",
"the type of a value should be one of ASE_AWK_VAL_XXX's defined in val.h");
return ase_false;
}
ase_char_t* ase_awk_valtostr (
ase_awk_run_t* run, ase_awk_val_t* v,
int opt, ase_str_t* buf, ase_size_t* len)
{
if (v->type == ASE_AWK_VAL_NIL)
{
return str_to_str (run, ASE_T(""), 0, opt, buf, len);
}
if (v->type == ASE_AWK_VAL_INT)
{
ase_awk_val_int_t* vi = (ase_awk_val_int_t*)v;
/*
if (vi->nde != ASE_NULL && vi->nde->str != ASE_NULL)
{
return str_to_str (
run, vi->nde->str, vi->nde->len,
opt, buf, len);
}
else
{
*/
return val_int_to_str (run, vi, opt, buf, len);
/*}*/
}
if (v->type == ASE_AWK_VAL_REAL)
{
ase_awk_val_real_t* vr = (ase_awk_val_real_t*)v;
/*
if (vr->nde != ASE_NULL && vr->nde->str != ASE_NULL)
{
return str_to_str (
run, vr->nde->str, vr->nde->len,
opt, buf, len);
}
else
{*/
return val_real_to_str (run, vr, opt, buf, len);
/*}*/
}
if (v->type == ASE_AWK_VAL_STR)
{
ase_awk_val_str_t* vs = (ase_awk_val_str_t*)v;
return str_to_str (
run, vs->buf, vs->len, opt, buf, len);
}
#ifdef DEBUG_VAL
ase_dprintf (
ASE_T("ERROR: WRONG VALUE TYPE [%d] in ase_awk_valtostr\n"),
v->type);
#endif
ase_awk_setrunerror (run, ASE_AWK_EVALTYPE, 0, ASE_NULL, 0);
return ASE_NULL;
}
static ase_char_t* str_to_str (
ase_awk_run_t* run, const ase_char_t* str, ase_size_t str_len,
int opt, ase_str_t* buf, ase_size_t* len)
{
if (buf == ASE_NULL)
{
ase_char_t* tmp;
tmp = ase_strxdup (str, str_len, &run->awk->prmfns.mmgr);
if (tmp == ASE_NULL)
{
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return ASE_NULL;
}
if (len != ASE_NULL) *len = str_len;
return tmp;
}
else
{
ase_size_t n;
if (opt & ASE_AWK_VALTOSTR_CLEAR) ase_str_clear (buf);
n = ase_str_ncat (buf, str, str_len);
if (n == (ase_size_t)-1)
{
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return ASE_NULL;
}
if (len != ASE_NULL) *len = ASE_STR_LEN(buf);
return ASE_STR_BUF(buf);
}
}
static ase_char_t* val_int_to_str (
ase_awk_run_t* run, ase_awk_val_int_t* v,
int opt, ase_str_t* buf, ase_size_t* len)
{
ase_char_t* tmp;
ase_long_t t;
ase_size_t l = 0;
t = v->val;
if (t == 0)
{
/* handle zero */
if (buf == ASE_NULL)
{
tmp = ASE_AWK_MALLOC (
run->awk, 2 * ASE_SIZEOF(ase_char_t));
if (tmp == ASE_NULL)
{
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return ASE_NULL;
}
tmp[0] = ASE_T('0');
tmp[1] = ASE_T('\0');
if (len != ASE_NULL) *len = 1;
return tmp;
}
else
{
if (opt & ASE_AWK_VALTOSTR_CLEAR) ase_str_clear (buf);
if (ase_str_cat (buf, ASE_T("0")) == (ase_size_t)-1)
{
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return ASE_NULL;
}
if (len != ASE_NULL) *len = ASE_STR_LEN(buf);
return ASE_STR_BUF(buf);
}
}
/* non-zero values */
if (t < 0) { t = -t; l++; }
while (t > 0) { l++; t /= 10; }
if (buf == ASE_NULL)
{
tmp = ASE_AWK_MALLOC (
run->awk, (l + 1) * ASE_SIZEOF(ase_char_t));
if (tmp == ASE_NULL)
{
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return ASE_NULL;
}
tmp[l] = ASE_T('\0');
if (len != ASE_NULL) *len = l;
}
else
{
/* clear the buffer */
if (opt & ASE_AWK_VALTOSTR_CLEAR) ase_str_clear (buf);
tmp = ASE_STR_BUF(buf) + ASE_STR_LEN(buf);
/* extend the buffer */
if (ase_str_nccat (
buf, ASE_T(' '), l) == (ase_size_t)-1)
{
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return ASE_NULL;
}
}
t = v->val;
if (t < 0) t = -t;
while (t > 0)
{
tmp[--l] = (ase_char_t)(t % 10) + ASE_T('0');
t /= 10;
}
if (v->val < 0) tmp[--l] = ASE_T('-');
if (buf != ASE_NULL)
{
tmp = ASE_STR_BUF(buf);
if (len != ASE_NULL) *len = ASE_STR_LEN(buf);
}
return tmp;
}
static ase_char_t* val_real_to_str (
ase_awk_run_t* run, ase_awk_val_real_t* v,
int opt, ase_str_t* buf, ase_size_t* len)
{
ase_char_t* tmp;
ase_size_t tmp_len;
ase_str_t out, fbu;
if (opt & ASE_AWK_VALTOSTR_PRINT)
{
tmp = run->global.ofmt.ptr;
tmp_len = run->global.ofmt.len;
}
else
{
tmp = run->global.convfmt.ptr;
tmp_len = run->global.convfmt.len;
}
if (ase_str_open (&out, 256, &run->awk->prmfns.mmgr) == ASE_NULL)
{
ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return ASE_NULL;
}
if (ase_str_open (&fbu, 256, &run->awk->prmfns.mmgr) == ASE_NULL)
{
ase_str_close (&out);
ase_awk_setrunerror (run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return ASE_NULL;
}
tmp = ase_awk_format (run, &out, &fbu, tmp, tmp_len,
(ase_size_t)-1, (ase_awk_nde_t*)v, &tmp_len);
if (tmp == ASE_NULL)
{
ase_str_close (&fbu);
ase_str_close (&out);
return ASE_NULL;
}
if (buf == ASE_NULL)
{
ase_str_close (&fbu);
ase_str_forfeit (&out);
if (len != ASE_NULL) *len = tmp_len;
}
else
{
if (opt & ASE_AWK_VALTOSTR_CLEAR) ase_str_clear (buf);
if (ase_str_ncat (buf, tmp, tmp_len) == (ase_size_t)-1)
{
ase_str_close (&fbu);
ase_str_close (&out);
ase_awk_setrunerror (
run, ASE_AWK_ENOMEM, 0, ASE_NULL, 0);
return ASE_NULL;
}
tmp = ASE_STR_BUF(buf);
if (len != ASE_NULL) *len = ASE_STR_LEN(buf);
ase_str_close (&fbu);
ase_str_close (&out);
}
return tmp;
}
int ase_awk_valtonum (
ase_awk_run_t* run, ase_awk_val_t* v, ase_long_t* l, ase_real_t* r)
{
if (v->type == ASE_AWK_VAL_NIL)
{
*l = 0;
return 0;
}
if (v->type == ASE_AWK_VAL_INT)
{
*l = ((ase_awk_val_int_t*)v)->val;
return 0; /* long */
}
if (v->type == ASE_AWK_VAL_REAL)
{
*r = ((ase_awk_val_real_t*)v)->val;
return 1; /* real */
}
if (v->type == ASE_AWK_VAL_STR)
{
return ase_awk_strtonum (run,
((ase_awk_val_str_t*)v)->buf,
((ase_awk_val_str_t*)v)->len, l, r);
#if 0
const ase_char_t* endptr;
*l = ase_awk_strxtolong (run->awk,
((ase_awk_val_str_t*)v)->buf,
((ase_awk_val_str_t*)v)->len, 0, &endptr);
if (*endptr == ASE_T('.') ||
*endptr == ASE_T('E') ||
*endptr == ASE_T('e'))
{
*r = ase_awk_strxtoreal (run->awk,
((ase_awk_val_str_t*)v)->buf,
((ase_awk_val_str_t*)v)->len, ASE_NULL);
/* TODO: need to check if it is a valid number using endptr for strxtoreal? */
return 1; /* real */
}
/* TODO: do should i handle strings ending with invalid number characters like "123xx" or "dkdkdkd"? */
return 0; /* long */
#endif
}
#ifdef DEBUG_VAL
ase_dprintf (
ASE_T("ERROR: WRONG VALUE TYPE [%d] in ase_awk_valtonum\n"),
v->type);
#endif
ase_awk_setrunerror (run, ASE_AWK_EVALTYPE, 0, ASE_NULL, 0);
return -1; /* error */
}
int ase_awk_strtonum (
ase_awk_run_t* run, const ase_char_t* ptr, ase_size_t len,
ase_long_t* l, ase_real_t* r)
{
const ase_char_t* endptr;
*l = ase_awk_strxtolong (run->awk, ptr, len, 0, &endptr);
if (*endptr == ASE_T('.') ||
*endptr == ASE_T('E') ||
*endptr == ASE_T('e'))
{
*r = ase_awk_strxtoreal (run->awk, ptr, len, ASE_NULL);
/* TODO: need to check if it is a valid number using endptr for strxtoreal? */
return 1; /* real */
}
/* TODO: do should i handle strings ending with invalid number characters like "123xx" or "dkdkdkd"? */
return 0; /* long */
}
#define DPRINTF run->awk->prmfns.misc.dprintf
#define DCUSTOM run->awk->prmfns.misc.custom_data
static int print_pair (ase_awk_pair_t* pair, void* arg)
{
ase_awk_run_t* run = (ase_awk_run_t*)arg;
DPRINTF (DCUSTOM, ASE_T(" %s=>"), pair->key);
ase_awk_dprintval ((ase_awk_run_t*)arg, pair->val);
DPRINTF (DCUSTOM, ASE_T(" "));
return 0;
}
void ase_awk_dprintval (ase_awk_run_t* run, ase_awk_val_t* val)
{
/* TODO: better value printing ... */
switch (val->type)
{
case ASE_AWK_VAL_NIL:
DPRINTF (DCUSTOM, ASE_T("nil"));
break;
case ASE_AWK_VAL_INT:
#if ASE_SIZEOF_LONG_LONG > 0
DPRINTF (DCUSTOM, ASE_T("%lld"),
(long long)((ase_awk_val_int_t*)val)->val);
#elif ASE_SIZEOF___INT64 > 0
DPRINTF (DCUSTOM, ASE_T("%I64d"),
(__int64)((ase_awk_val_int_t*)val)->val);
#elif ASE_SIZEOF_LONG > 0
DPRINTF (DCUSTOM, ASE_T("%ld"),
(long)((ase_awk_val_int_t*)val)->val);
#elif ASE_SIZEOF_INT > 0
DPRINTF (DCUSTOM, ASE_T("%d"),
(int)((ase_awk_val_int_t*)val)->val);
#else
#error unsupported size
#endif
break;
case ASE_AWK_VAL_REAL:
DPRINTF (DCUSTOM, ASE_T("%Lf"),
(long double)((ase_awk_val_real_t*)val)->val);
break;
case ASE_AWK_VAL_STR:
DPRINTF (DCUSTOM, ASE_T("%s"), ((ase_awk_val_str_t*)val)->buf);
break;
case ASE_AWK_VAL_REX:
DPRINTF (DCUSTOM, ASE_T("REX[%s]"), ((ase_awk_val_rex_t*)val)->buf);
break;
case ASE_AWK_VAL_MAP:
DPRINTF (DCUSTOM, ASE_T("MAP["));
ase_awk_map_walk (((ase_awk_val_map_t*)val)->map, print_pair, run);
DPRINTF (DCUSTOM, ASE_T("]"));
break;
case ASE_AWK_VAL_REF:
DPRINTF (DCUSTOM, ASE_T("REF[id=%d,val="), ((ase_awk_val_ref_t*)val)->id);
ase_awk_dprintval (run, *((ase_awk_val_ref_t*)val)->adr);
DPRINTF (DCUSTOM, ASE_T("]"));
break;
default:
DPRINTF (DCUSTOM, ASE_T("**** INTERNAL ERROR - INVALID VALUE TYPE ****\n"));
}
}

206
ase/awk/val.h Normal file
View File

@ -0,0 +1,206 @@
/*
* $Id: val.h,v 1.3 2007/04/30 05:48:37 bacon Exp $
*
* {License}
*/
#ifndef _ASE_AWK_VAL_H_
#define _ASE_AWK_VAL_H_
#ifndef _ASE_AWK_AWK_H_
#error Include <ase/awk/awk.h> first
#endif
#include <ase/cmn/str.h>
#include <ase/awk/map.h>
enum ase_awk_val_type_t
{
/* the values between ASE_AWK_VAL_NIL and ASE_AWK_VAL_STR inclusive
* must be synchronized with an internal table of the __cmp_val
* function in run.c */
ASE_AWK_VAL_NIL = 0,
ASE_AWK_VAL_INT = 1,
ASE_AWK_VAL_REAL = 2,
ASE_AWK_VAL_STR = 3,
ASE_AWK_VAL_REX = 4,
ASE_AWK_VAL_MAP = 5,
ASE_AWK_VAL_REF = 6
};
enum ase_awk_val_ref_id_t
{
/* keep these items in the same order as corresponding items
* in tree.h */
ASE_AWK_VAL_REF_NAMED,
ASE_AWK_VAL_REF_GLOBAL,
ASE_AWK_VAL_REF_LOCAL,
ASE_AWK_VAL_REF_ARG,
ASE_AWK_VAL_REF_NAMEDIDX,
ASE_AWK_VAL_REF_GLOBALIDX,
ASE_AWK_VAL_REF_LOCALIDX,
ASE_AWK_VAL_REF_ARGIDX,
ASE_AWK_VAL_REF_POS
};
enum ase_awk_valtostr_opt_t
{
ASE_AWK_VALTOSTR_CLEAR = (1 << 0),
ASE_AWK_VALTOSTR_PRINT = (1 << 1)
};
typedef struct ase_awk_val_nil_t ase_awk_val_nil_t;
typedef struct ase_awk_val_int_t ase_awk_val_int_t;
typedef struct ase_awk_val_real_t ase_awk_val_real_t;
typedef struct ase_awk_val_str_t ase_awk_val_str_t;
typedef struct ase_awk_val_rex_t ase_awk_val_rex_t;
typedef struct ase_awk_val_map_t ase_awk_val_map_t;
typedef struct ase_awk_val_ref_t ase_awk_val_ref_t;
#if ASE_SIZEOF_INT == 2
#define ASE_AWK_VAL_HDR \
unsigned int type: 3; \
unsigned int ref: 13
#else
#define ASE_AWK_VAL_HDR \
unsigned int type: 3; \
unsigned int ref: 29
#endif
#ifndef ASE_AWK_NDE_INT_DEFINED
#define ASE_AWK_NDE_INT_DEFINED
typedef struct ase_awk_nde_int_t ase_awk_nde_int_t;
#endif
#ifndef ASE_AWK_NDE_REAL_DEFINED
#define ASE_AWK_NDE_REAL_DEFINED
typedef struct ase_awk_nde_real_t ase_awk_nde_real_t;
#endif
struct ase_awk_val_t
{
ASE_AWK_VAL_HDR;
};
/* ASE_AWK_VAL_NIL */
struct ase_awk_val_nil_t
{
ASE_AWK_VAL_HDR;
};
/* ASE_AWK_VAL_INT */
struct ase_awk_val_int_t
{
ASE_AWK_VAL_HDR;
ase_long_t val;
ase_awk_nde_int_t* nde;
};
/* ASE_AWK_VAL_REAL */
struct ase_awk_val_real_t
{
ASE_AWK_VAL_HDR;
ase_real_t val;
ase_awk_nde_real_t* nde;
};
/* ASE_AWK_VAL_STR */
struct ase_awk_val_str_t
{
ASE_AWK_VAL_HDR;
ase_char_t* buf;
ase_size_t len;
};
/* ASE_AWK_VAL_REX */
struct ase_awk_val_rex_t
{
ASE_AWK_VAL_HDR;
ase_char_t* buf;
ase_size_t len;
void* code;
};
/* ASE_AWK_VAL_MAP */
struct ase_awk_val_map_t
{
ASE_AWK_VAL_HDR;
/* TODO: make val_map to array if the indices used are all
* integers switch to map dynamically once the
* non-integral index is seen.
*/
ase_awk_map_t* map;
};
/* ASE_AWK_VAL_REF */
struct ase_awk_val_ref_t
{
ASE_AWK_VAL_HDR;
int id;
/* if id is ASE_AWK_VAL_REF_POS, adr holds an index of the
* positional variable. Otherwise, adr points to the value
* directly. */
ase_awk_val_t** adr;
};
#ifdef __cplusplus
extern "C" {
#endif
extern ase_awk_val_t* ase_awk_val_nil;
extern ase_awk_val_t* ase_awk_val_zls;
extern ase_awk_val_t* ase_awk_val_negone;
extern ase_awk_val_t* ase_awk_val_zero;
extern ase_awk_val_t* ase_awk_val_one;
ase_awk_val_t* ase_awk_makeintval (ase_awk_run_t* run, ase_long_t v);
ase_awk_val_t* ase_awk_makerealval (ase_awk_run_t* run, ase_real_t v);
ase_awk_val_t* ase_awk_makestrval0 (
ase_awk_run_t* run, const ase_char_t* str);
ase_awk_val_t* ase_awk_makestrval (
ase_awk_run_t* run, const ase_char_t* str, ase_size_t len);
ase_awk_val_t* ase_awk_makestrval_nodup (
ase_awk_run_t* run, ase_char_t* str, ase_size_t len);
ase_awk_val_t* ase_awk_makestrval2 (
ase_awk_run_t* run,
const ase_char_t* str1, ase_size_t len1,
const ase_char_t* str2, ase_size_t len2);
ase_awk_val_t* ase_awk_makerexval (
ase_awk_run_t* run, const ase_char_t* buf, ase_size_t len, void* code);
ase_awk_val_t* ase_awk_makemapval (ase_awk_run_t* run);
ase_awk_val_t* ase_awk_makerefval (
ase_awk_run_t* run, int id, ase_awk_val_t** adr);
ase_bool_t ase_awk_isbuiltinval (ase_awk_val_t* val);
void ase_awk_freeval (ase_awk_run_t* run, ase_awk_val_t* val, ase_bool_t cache);
void ase_awk_refupval (ase_awk_run_t* run, ase_awk_val_t* val);
void ase_awk_refdownval (ase_awk_run_t* run, ase_awk_val_t* val);
void ase_awk_refdownval_nofree (ase_awk_run_t* run, ase_awk_val_t* val);
ase_bool_t ase_awk_valtobool (
ase_awk_run_t* run, ase_awk_val_t* val);
ase_char_t* ase_awk_valtostr (
ase_awk_run_t* run, ase_awk_val_t* val,
int opt, ase_str_t* buf, ase_size_t* len);
int ase_awk_valtonum (
ase_awk_run_t* run, ase_awk_val_t* v, ase_long_t* l, ase_real_t* r);
int ase_awk_strtonum (
ase_awk_run_t* run, const ase_char_t* ptr, ase_size_t len,
ase_long_t* l, ase_real_t* r);
void ase_awk_dprintval (ase_awk_run_t* run, ase_awk_val_t* val);
#ifdef __cplusplus
}
#endif
#endif

73
ase/build.xml Normal file
View File

@ -0,0 +1,73 @@
<!-- $Id: build.xml,v 1.3 2007/04/30 05:51:26 bacon Exp $ -->
<project name="ase" default="release" basedir=".">
<description>
ANT build script for ASE
</description>
<!--
<property name="destdir" location="${basedir}/release" />
-->
<target name="release" depends="init-release,aseawk.jar,aseawk.test">
</target>
<target name="debug" depends="init-debug,aseawk.jar,aseawk.test">
</target>
<target name="init-release">
<property name="destdir" location="${basedir}/release" />
<property name="libdir" location="${destdir}/lib" />
<property name="bindir" location="${destdir}/bin" />
<mkdir dir="${libdir}" />
<mkdir dir="${bindir}" />
</target>
<target name="init-debug">
<property name="destdir" location="${basedir}/debug" />
<property name="libdir" location="${destdir}/lib" />
<property name="bindir" location="${destdir}/bin" />
<mkdir dir="${libdir}" />
<mkdir dir="${bindir}" />
</target>
<target name="aseawk.jar" description="compile the awk classes">
<javac srcdir="awk" destdir="${libdir}" />
<jar jarfile="${libdir}/aseawk.jar"
basedir="${libdir}"
includes="ase/awk/*.class" />
<delete dir="${libdir}/ase" />
</target>
<target name="aseawk.test" depends="aseawk.jar"
description="compile the awk test classes">
<javac srcdir="test/awk"
classpath="${libdir}/aseawk.jar"
destdir="${bindir}" />
<unjar src="${libdir}/aseawk.jar" dest="${bindir}" />
<jar jarfile="${bindir}/aseawk.jar"
basedir="${bindir}"
includes="**/*.class"
manifest="test/awk/manifest" />
<delete>
<fileset dir="${bindir}" includes="*.class" />
</delete>
<delete dir="${bindir}/ase" verbose="true" />
<delete dir="${bindir}/META-INF" verbose="true" />
<copy file="test/awk/AseAwkApplet.html" todir="${bindir}" />
</target>
<target name="clean" description="clean up">
<delete dir="${basedir}/release"
includes="**/*.class,**/*.jar" verbose="true"/>
<delete dir="${basedir}/debug"
includes="**/*.class,**/*.jar" verbose="true"/>
</target>
</project>

124
ase/cmn/asecmn.dsp Normal file
View File

@ -0,0 +1,124 @@
# 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.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

263
ase/cmn/asecmn.vcproj Normal file
View File

@ -0,0 +1,263 @@
<?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"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\..\debug\lib"
IntermediateDirectory=".\debug"
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"
PrecompiledHeaderFile=".\debug/asecmn.pch"
AssemblerListingLocation=".\debug/"
ObjectFile=".\debug/"
ProgramDataBaseFileName=".\debug/"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
OutputFile="$(OutDir)\asecmn.lib"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\../debug/lib/asecmn.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory=".\..\release\lib"
IntermediateDirectory=".\release"
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"
PrecompiledHeaderFile=".\release/asecmn.pch"
AssemblerListingLocation=".\release/"
ObjectFile=".\release/"
ProgramDataBaseFileName=".\release/"
WarningLevel="3"
SuppressStartupBanner="true"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
OutputFile="$(OutDir)\asecmn.lib"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\../release/lib/asecmn.bsc"
/>
<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="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="misc.c"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="str.c"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<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>

64
ase/cmn/conf_msw.h Normal file
View File

@ -0,0 +1,64 @@
/*
* $Id: conf_msw.h,v 1.3 2007/04/30 05:55:36 bacon Exp $
*
* {License}
*/
/*
Macro Meaning
_WIN64 A 64-bit platform.
_WIN32 A 32-bit platform. This value is also defined by the 64-bit
compiler for backward compatibility.
_WIN16 A 16-bit platform
The following macros are specific to the architecture.
Macro Meaning
_M_IA64 Intel Itanium Processor Family
_M_IX86 x86 platform
_M_X64 x64 platform
*/
#define ASE_ENDIAN_LITTLE
#define ASE_SIZEOF_CHAR 1
#define ASE_SIZEOF_SHORT 2
#define ASE_SIZEOF_INT 4
/*#ifdef _WIN64
#define ASE_SIZEOF_LONG 8
#else*/
#define ASE_SIZEOF_LONG 4
/*#endif*/
#ifdef __POCC__
/* pelles c with no microsoft extension */
#define ASE_SIZEOF_LONG_LONG 8
#define ASE_SIZEOF___INT8 0
#define ASE_SIZEOF___INT16 0
#define ASE_SIZEOF___INT32 0
#define ASE_SIZEOF___INT64 0
#define ASE_SIZEOF___INT96 0
#define ASE_SIZEOF___INT128 0
#else
#define ASE_SIZEOF_LONG_LONG 0
#define ASE_SIZEOF___INT8 1
#define ASE_SIZEOF___INT16 2
#define ASE_SIZEOF___INT32 4
#define ASE_SIZEOF___INT64 8
#define ASE_SIZEOF___INT96 0
#define ASE_SIZEOF___INT128 0
#endif
#ifdef _WIN64
#define ASE_SIZEOF_VOID_P 8
#else
#define ASE_SIZEOF_VOID_P 4
#endif
#define ASE_SIZEOF_FLOAT 4
#define ASE_SIZEOF_DOUBLE 8
#define ASE_SIZEOF_LONG_DOUBLE 16
#define ASE_SIZEOF_WCHAR_T 2

44
ase/cmn/conf_unx.h.in Normal file
View File

@ -0,0 +1,44 @@
/*
* $Id: conf_unx.h.in,v 1.3 2007/04/30 05:55:36 bacon Exp $
*
* {License}
*/
/* Big Endian */
#undef ASE_ENDIAN_BIG
/* Little Endian */
#undef ASE_ENDIAN_LITTLE
/* Unknown Endian */
#undef ASE_ENDIAN_UNKNOWN
/* long long */
#undef ASE_HAVE_LONG_LONG
/* long double */
#undef ASE_HAVE_LONG_DOUBLE
/* data type size */
#define ASE_SIZEOF_CHAR 0
#define ASE_SIZEOF_SHORT 0
#define ASE_SIZEOF_INT 0
#define ASE_SIZEOF_LONG 0
#define ASE_SIZEOF_LONG_LONG 0
#define ASE_SIZEOF___INT8 0
#define ASE_SIZEOF___INT16 0
#define ASE_SIZEOF___INT32 0
#define ASE_SIZEOF___INT64 0
#define ASE_SIZEOF___INT128 0
#define ASE_SIZEOF_VOID_P 0
#define ASE_SIZEOF_FLOAT 0
#define ASE_SIZEOF_DOUBLE 0
#define ASE_SIZEOF_LONG_DOUBLE 0
#define ASE_SIZEOF_WCHAR_T 0
/* char is wchar */
#undef ASE_CHAR_IS_WCHAR
/* char is mchar */
#undef ASE_CHAR_IS_MCHAR

90
ase/cmn/conf_vms.h Normal file
View File

@ -0,0 +1,90 @@
/*
* $Id: conf_vms.h,v 1.3 2007/04/30 05:55:36 bacon Exp $
*
* {License}
*/
/* all of vax, alpha, ia64 are in the little endian. */
#define ASE_ENDIAN_LITTLE
/*
* Refer to the chapter 3 of the following URL for the data sizes.
* http://h71000.www7.hp.com/commercial/c/docs/6180profile.html
*/
#define ASE_SIZEOF_CHAR 1
#define ASE_SIZEOF_SHORT 2
#define ASE_SIZEOF_INT 4
#define ASE_SIZEOF_LONG 4
#if defined(vax) || defined(__vax)
#define ASE_SIZEOF_LONG_LONG 0
#elif defined(alpha) || defined(__alpha)
#define ASE_SIZEOF_LONG_LONG 8
#elif defined(ia64) || defined(__ia64)
#define ASE_SIZEOF_LONG_LONG 8
#else
#define ASE_SIZEOF_LONG_LONG 0
#endif
#define ASE_SIZEOF___INT8 1
#define ASE_SIZEOF___INT16 2
#define ASE_SIZEOF___INT32 4
#if defined(vax) || defined(__vax)
#define ASE_SIZEOF___INT64 0
#elif defined(alpha) || defined(__alpha)
#define ASE_SIZEOF___INT64 8
#elif defined(ia64) || defined(__ia64)
#define ASE_SIZEOF___INT64 8
#else
#define ASE_SIZEOF___INT64 0
#endif
#define ASE_SIZEOF___INT96 0
#define ASE_SIZEOF___INT128 0
#if defined(vax) || defined(__vax)
#define ASE_SIZEOF_VOID_P 4
#elif defined(alpha) || defined(__alpha)
#if __INITIAL_POINTER_SIZE==64
#pragma pointer_size 64
#define ASE_SIZEOF_VOID_P 8
#elif __INITIAL_POINTER_SIZE==32
#pragma pointer_size 32
#define ASE_SIZEOF_VOID_P 4
#elif __INITIAL_POINTER_SIZE==0
#define ASE_SIZEOF_VOID_P 4
#else
#error "unsupported initial pointer size"
#endif
#elif defined(ia64) || defined(__ia64)
#if __INITIAL_POINTER_SIZE==64
#pragma pointer_size 64
#define ASE_SIZEOF_VOID_P 8
#elif __INITIAL_POINTER_SIZE==32
#pragma pointer_size 32
#define ASE_SIZEOF_VOID_P 4
#elif __INITIAL_POINTER_SIZE==0
#define ASE_SIZEOF_VOID_P 4
#else
#error "unsupported initial pointer size"
#endif
#else
#error "unsupported architecture"
#endif
#define ASE_SIZEOF_FLOAT 4
#define ASE_SIZEOF_DOUBLE 8
#if defined(vax) || defined(__vax)
#define ASE_SIZEOF_LONG_DOUBLE 8
#elif defined(alpha) || defined(__alpha)
#define ASE_SIZEOF_LONG_DOUBLE 16
#elif defined(ia64) || defined(__ia64)
#define ASE_SIZEOF_LONG_DOUBLE 16
#else
#define ASE_SIZEOF_LONG_DOUBLE 0
#endif
#define ASE_SIZEOF_WCHAR_T 4

17
ase/cmn/descrip.mms Normal file
View File

@ -0,0 +1,17 @@
#
# OpenVMS MMS/MMK
#
objects = mem.obj,str.obj,misc.obj
CFLAGS = /include="../.."
#CFLAGS = /pointer_size=long /include="../.."
LIBRFLAGS =
asecmn.olb : $(objects)
$(LIBR)/create $(MMS$TARGET) $(objects)
# $(LIBR)/replace $(LIBRFLAGS) $(MMS$TARGET),$(objects)
mem.obj depends_on mem.c
str.obj depends_on str.c
misc.obj depends_on misc.c

139
ase/cmn/macros.h Normal file
View File

@ -0,0 +1,139 @@
/*
* $Id: macros.h,v 1.3 2007/04/30 05:55:36 bacon Exp $
*
* {License}
*/
#ifndef _ASE_MACROS_H_
#define _ASE_MACROS_H_
#include <ase/cmn/types.h>
#ifdef __cplusplus
/*#define ASE_NULL ((ase_uint_t)0)*/
#define ASE_NULL (0)
#else
#define ASE_NULL ((void*)0)
#endif
#define ASE_CHAR_EOF ((ase_cint_t)-1)
#define ASE_SIZEOF(n) (sizeof(n))
#define ASE_COUNTOF(n) (sizeof(n)/sizeof(n[0]))
#define ASE_OFFSETOF(type,member) ((ase_size_t)&((type*)0)->member)
#define ASE_TYPE_IS_SIGNED(type) (((type)0) > ((type)-1))
#define ASE_TYPE_IS_UNSIGNED(type) (((type)0) < ((type)-1))
#define ASE_TYPE_SIGNED_MAX(type) \
((type)~((type)1 << (ASE_SIZEOF(type) * 8 - 1)))
#define ASE_TYPE_UNSIGNED_MAX(type) ((type)(~(type)0))
#define ASE_TYPE_SIGNED_MIN(type) \
((type)((type)1 << (ASE_SIZEOF(type) * 8 - 1)))
#define ASE_TYPE_UNSIGNED_MIN(type) ((type)0)
#define ASE_TYPE_MAX(type) \
((ASE_TYPE_IS_SIGNED(type)? ASE_TYPE_SIGNED_MAX(type): ASE_TYPE_UNSIGNED_MAX(type)))
#define ASE_TYPE_MIN(type) \
((ASE_TYPE_IS_SIGNED(type)? ASE_TYPE_SIGNED_MIN(type): ASE_TYPE_UNSIGNED_MIN(type)))
#define ASE_IS_POWOF2(x) (((x) & ((x) - 1)) == 0)
#define ASE_SWAP(x,y,original_type,casting_type) \
do { \
x = (original_type)((casting_type)(x) ^ (casting_type)(y)); \
y = (original_type)((casting_type)(y) ^ (casting_type)(x)); \
x = (original_type)((casting_type)(x) ^ (casting_type)(y)); \
} while (0)
#define ASE_ABS(x) ((x) < 0? -(x): (x))
#define ASE_LOOP_CONTINUE(id) goto __loop_ ## id ## _begin__;
#define ASE_LOOP_BREAK(id) goto __loop_ ## id ## _end__;
#define ASE_LOOP_BEGIN(id) __loop_ ## id ## _begin__: {
#define ASE_LOOP_END(id) ASE_LOOP_CONTINUE(id) } __loop_ ## id ## _end__:;
#define ASE_REPEAT(n,blk) \
do { \
ase_size_t __ase_repeat_x1__ = (ase_size_t)(n); \
ase_size_t __ase_repeat_x2__ = __ase_repeat_x1__ >> 4; \
__ase_repeat_x1__ &= 15; \
while (__ase_repeat_x1__-- > 0) { blk; } \
while (__ase_repeat_x2__-- > 0) { \
blk; blk; blk; blk; blk; blk; blk; blk; \
blk; blk; blk; blk; blk; blk; blk; blk; \
} \
} while (0);
#define ASE_MQ_I(val) #val
#define ASE_MQ(val) ASE_MQ_I(val)
#define ASE_MC(ch) ((ase_mchar_t)ch)
#define ASE_MS(str) ((const ase_mchar_t*)str)
#define ASE_MT(txt) (txt)
#define ASE_WQ_I(val) (L ## #val)
#define ASE_WQ(val) ASE_WQ_I(val)
#define ASE_WC(ch) ((ase_wchar_t)L ## ch)
#define ASE_WS(str) ((const ase_wchar_t*)L ## str)
#define ASE_WT(txt) (L ## txt)
#if defined(ASE_CHAR_IS_MCHAR)
#define ASE_C(ch) ASE_MC(ch)
#define ASE_S(str) ASE_MS(str)
#define ASE_T(txt) ASE_MT(txt)
#else
#define ASE_C(ch) ASE_WC(ch)
#define ASE_S(str) ASE_WS(str)
#define ASE_T(txt) ASE_WT(txt)
#endif
#if defined(__GNUC__)
#define ASE_BEGIN_PACKED_STRUCT(x) struct x {
#define ASE_END_PACKED_STRUCT() } __attribute__((packed));
#else
#define ASE_BEGIN_PACKED_STRUCT(x) struct x {
#define ASE_END_PACKED_STRUCT() };
#endif
#ifdef NDEBUG
#define ASE_ASSERT(expr) ((void)0)
#define ASE_ASSERTX(expr,desc) ((void)0)
#else
#ifdef __cplusplus
extern "C" {
#endif
void ase_assert_abort (void);
void ase_assert_printf (const ase_char_t* fmt, ...);
int ase_assert_failed (
const ase_char_t* expr, const ase_char_t* desc,
const ase_char_t* file, ase_size_t line);
#ifdef __cplusplus
}
#endif
#define ASE_ASSERT(expr) (void)((expr) || \
(ase_assert_failed (ASE_T(#expr), ASE_NULL, ASE_T(__FILE__), __LINE__), 0))
#define ASE_ASSERTX(expr,desc) (void)((expr) || \
(ase_assert_failed (ASE_T(#expr), ASE_T(desc), ASE_T(__FILE__), __LINE__), 0))
#endif
#define ASE_MALLOC(mmgr,size) (mmgr)->malloc((mmgr)->custom_data, size)
#define ASE_REALLOC(mmgr,ptr,size) (mmgr)->realloc((mmgr)->custom_data, ptr, size)
#define ASE_FREE(mmgr,ptr) (mmgr)->free((mmgr)->custom_data, ptr)
#define ASE_ISUPPER(ccls,c) (ccls)->is_upper((ccls)->custom_data,c)
#define ASE_ISLOWER(ccls,c) (ccls)->is_lower((ccls)->custom_data,c)
#define ASE_ISALPHA(ccls,c) (ccls)->is_alpha((ccls)->custom_data,c)
#define ASE_ISDIGIT(ccls,c) (ccls)->is_digit((ccls)->custom_data,c)
#define ASE_ISXDIGIT(ccls,c) (ccls)->is_xdigit((ccls)->custom_data,c)
#define ASE_ISALNUM(ccls,c) (ccls)->is_alnum((ccls)->custom_data,c)
#define ASE_ISSPACE(ccls,c) (ccls)->is_space((ccls)->custom_data,c)
#define ASE_ISPRINT(ccls,c) (ccls)->is_print((ccls)->custom_data,c)
#define ASE_ISGRAPH(ccls,c) (ccls)->is_graph((ccls)->custom_data,c)
#define ASE_ISCNTRL(ccls,c) (ccls)->is_cntrl((ccls)->custom_data,c)
#define ASE_ISPUNCT(ccls,c) (ccls)->is_punct((ccls)->custom_data,c)
#define ASE_TOUPPER(ccls,c) (ccls)->to_upper((ccls)->custom_data,c)
#define ASE_TOLOWER(ccls,c) (ccls)->to_lower((ccls)->custom_data,c)
#endif

49
ase/cmn/makefile.in Normal file
View File

@ -0,0 +1,49 @@
#
# $Id: makefile.in,v 1.3 2007/04/30 05:55:36 bacon Exp $
#
NAME = asecmn
CC = @CC@
AR = ar
MAKE = @MAKE@
RANLIB = @RANLIB@
CFLAGS = @CFLAGS@ -I@abs_top_builddir@/..
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
MODE = @BUILDMODE@
OUT_DIR = ../$(MODE)/lib
OUT_FILE = $(OUT_DIR)/lib$(NAME).a
TMP_DIR = $(MODE)
OBJ_FILES = \
$(TMP_DIR)/mem.o \
$(TMP_DIR)/str.o \
$(TMP_DIR)/misc.o
lib: $(OUT_FILE)
$(OUT_FILE): $(TMP_DIR) $(OBJ_FILES) $(OUT_DIR)
$(AR) cr $(OUT_FILE) $(OBJ_FILES)
if [ "$(RANLIB)" = "ranlib" ]; then ranlib $(OUT_FILE); fi
$(TMP_DIR)/mem.o: mem.c
$(CC) $(CFLAGS) -o $@ -c mem.c
$(TMP_DIR)/str.o: str.c
$(CC) $(CFLAGS) -o $@ -c str.c
$(TMP_DIR)/misc.o: misc.c
$(CC) $(CFLAGS) -o $@ -c misc.c
$(OUT_DIR):
mkdir -p $(OUT_DIR)
$(TMP_DIR):
mkdir -p $(TMP_DIR)
clean:
rm -rf $(OUT_FILE) $(OBJ_FILES)

29
ase/cmn/makefile.msw.bcc Normal file
View File

@ -0,0 +1,29 @@
OUT = asecmn
C_SRCS = mem.c str.c misc.c
C_OBJS = $(C_SRCS:.c=.obj)
CC = bcc32
LD = ilink32
AR = tlib
JAVAC = javac
CFLAGS = -O2 -WM -WU -RT- -w -q -I../.. -DNDEBUG
LDFLAGS = -Tpd -ap -Gn -c -q
STARTUP = c0d32w.obj
LIBS = import32.lib cw32mt.lib
all: lib
lib: $(C_OBJS)
$(AR) $(OUT).lib @&&!
+-$(**: = &^
+-)
!
clean:
-del $(OBJS) $(OUT).lib *.obj
.SUFFIXES: .c .obj
.c.obj:
$(CC) $(CFLAGS) -c $<

23
ase/cmn/makefile.msw.cl Normal file
View File

@ -0,0 +1,23 @@
OUT = asecmn
C_SRCS = mem.c str.c misc.c
C_OBJS = $(C_SRCS:.c=.obj)
CC = cl
LD = link
CFLAGS = /nologo /O2 /MT /W3 /GR- /GS- /Za -I../..
all: lib
lib: $(C_OBJS)
$(LD) /lib @<<
/nologo /out:$(OUT).lib $(C_OBJS)
<<
clean:
del $(OBJS) $(OUT).lib *.obj
.SUFFIXES: .c .obj
.c.obj:
$(CC) $(CFLAGS) /c $<

52
ase/cmn/mem.c Normal file
View File

@ -0,0 +1,52 @@
/*
* $Id: mem.c,v 1.3 2007/04/30 05:55:36 bacon Exp $
*
* {License}
*/
#include <ase/cmn/mem.h>
void* ase_memcpy (void* dst, const void* src, ase_size_t n)
{
void* p = dst;
void* e = (ase_byte_t*)dst + n;
while (dst < e)
{
*(ase_byte_t*)dst = *(ase_byte_t*)src;
dst = (ase_byte_t*)dst + 1;
src = (ase_byte_t*)src + 1;
}
return p;
}
void* ase_memset (void* dst, int val, ase_size_t n)
{
void* p = dst;
void* e = (ase_byte_t*)p + n;
while (p < e)
{
*(ase_byte_t*)p = (ase_byte_t)val;
p = (ase_byte_t*)p + 1;
}
return dst;
}
int ase_memcmp (const void* s1, const void* s2, ase_size_t n)
{
const void* e;
if (n == 0) return 0;
e = (const ase_byte_t*)s1 + n - 1;
while (s1 < e && *(ase_byte_t*)s1 == *(ase_byte_t*)s2)
{
s1 = (ase_byte_t*)s1 + 1;
s2 = (ase_byte_t*)s2 + 1;
}
return *((ase_byte_t*)s1) - *((ase_byte_t*)s2);
}

25
ase/cmn/mem.h Normal file
View File

@ -0,0 +1,25 @@
/*
* $Id: mem.h,v 1.3 2007/04/30 05:55:36 bacon Exp $
*
* {License}
*/
#ifndef _ASE_CMN_MEM_H_
#define _ASE_CMN_MEM_H_
#include <ase/cmn/types.h>
#include <ase/cmn/macros.h>
#ifdef __cplusplus
extern "C" {
#endif
void* ase_memcpy (void* dst, const void* src, ase_size_t n);
void* ase_memset (void* dst, int val, ase_size_t n);
int ase_memcmp (const void* s1, const void* s2, ase_size_t n);
#ifdef __cplusplus
}
#endif
#endif

34
ase/cmn/misc.c Normal file
View File

@ -0,0 +1,34 @@
/*
* $Id: misc.c,v 1.3 2007/04/30 05:55:36 bacon Exp $
*
* {License}
*/
#include <ase/cmn/types.h>
#include <ase/cmn/macros.h>
#ifndef NDEBUG
int ase_assert_failed (
const ase_char_t* expr, const ase_char_t* desc,
const ase_char_t* file, ase_size_t line)
{
if (desc == ASE_NULL)
{
ase_assert_printf (
ASE_T("ASSERTION FAILURE AT FILE %s LINE %lu\n%s\n"),
file, (unsigned long)line, expr);
}
else
{
ase_assert_printf (
ASE_T("ASSERTION FAILURE AT FILE %s LINE %lu\n%s\n\nDESCRIPTION:\n%s\n"),
file, (unsigned long)line, expr, desc);
}
ase_assert_abort ();
return 0;
}
#endif

17
ase/cmn/pack.h Normal file
View File

@ -0,0 +1,17 @@
/*
* $Id: pack.h,v 1.3 2007/04/30 05:55:36 bacon Exp $
*
* {License}
*/
#if defined(__GNUC__)
#pragma pack(1)
#elif defined(__HP_aCC) || defined(__HP_cc)
#pragma PACK 1
#elif defined(_MSC_VER) || defined(__BORLANDC__)
#pragma pack(push,1)
#elif defined(__DECC)
#pragma pack(push,1)
#else
#pragma pack(1)
#endif

385
ase/cmn/str.c Normal file
View File

@ -0,0 +1,385 @@
/*
* $Id: str.c,v 1.3 2007/04/30 05:55:36 bacon Exp $
*
* {License}
*/
#include <ase/cmn/str.h>
#include <ase/cmn/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_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;
}
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_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_C('\0')) return 0;
s1++, s2++;
}
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_TOUPPER(ccls,*s1) == ASE_TOUPPER(ccls,*s2))
{
if (*s1 == ASE_C('\0')) return 0;
s1++, s2++;
}
return (ASE_TOUPPER(ccls,*s1) > ASE_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_TOUPPER (ccls, *s1);
if (s2 < end2)
{
c2 = ASE_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_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 (ase_true)
{
if (y >= subp) return (ase_char_t*)str;
if (*x != *y) break;
x++; y++;
}
str++;
}
return ASE_NULL;
}
ase_str_t* ase_str_open (ase_str_t* str, ase_size_t capa, ase_mmgr_t* mmgr)
{
if (str == ASE_NULL)
{
str = (ase_str_t*)
ASE_MALLOC (mmgr, ASE_SIZEOF(ase_str_t));
if (str == ASE_NULL) return ASE_NULL;
str->__dynamic = ase_true;
}
else str->__dynamic = ase_false;
str->mmgr = mmgr;
str->buf = (ase_char_t*) ASE_MALLOC (
mmgr, ASE_SIZEOF(ase_char_t) * (capa + 1));
if (str->buf == ASE_NULL)
{
if (str->__dynamic) ASE_FREE (mmgr, str);
return ASE_NULL;
}
str->size = 0;
str->capa = capa;
str->buf[0] = ASE_T('\0');
return str;
}
void ase_str_close (ase_str_t* str)
{
ASE_FREE (str->mmgr, str->buf);
if (str->__dynamic) ASE_FREE (str->mmgr, str);
}
void ase_str_clear (ase_str_t* str)
{
str->size = 0;
str->buf[0] = ASE_T('\0');
}
void ase_str_forfeit (ase_str_t* str)
{
if (str->__dynamic) ASE_FREE (str->mmgr, str);
}
void ase_str_swap (ase_str_t* str, ase_str_t* str1)
{
ase_str_t tmp;
tmp.buf = str->buf;
tmp.size = str->size;
tmp.capa = str->capa;
tmp.mmgr = str->mmgr;
str->buf = str1->buf;
str->size = str1->size;
str->capa = str1->capa;
str->mmgr = str1->mmgr;
str1->buf = tmp.buf;
str1->size = tmp.size;
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)
{
buf = (ase_char_t*) ASE_MALLOC (
str->mmgr, ASE_SIZEOF(ase_char_t) * (len + 1));
if (buf == ASE_NULL) return (ase_size_t)-1;
ASE_FREE (str->mmgr, str->buf);
str->capa = len;
str->buf = buf;
}
str->size = ase_strncpy (str->buf, s, len);
str->buf[str->size] = ASE_T('\0');
return str->size;
}
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->size)
{
ase_char_t* tmp;
ase_size_t capa;
capa = str->size + len;
/* double the capa if necessary for concatenation */
if (capa < str->capa * 2) capa = str->capa * 2;
if (str->mmgr->realloc != ASE_NULL)
{
tmp = (ase_char_t*) ASE_REALLOC (
str->mmgr, str->buf,
ASE_SIZEOF(ase_char_t) * (capa + 1));
if (tmp == ASE_NULL) return (ase_size_t)-1;
}
else
{
tmp = (ase_char_t*) ASE_MALLOC (
str->mmgr, ASE_SIZEOF(ase_char_t)*(capa+1));
if (tmp == ASE_NULL) return (ase_size_t)-1;
if (str->buf != ASE_NULL)
{
ase_memcpy (tmp, str->buf,
ASE_SIZEOF(ase_char_t)*(str->capa+1));
ASE_FREE (str->mmgr, str->buf);
}
}
str->capa = capa;
str->buf = tmp;
}
str->size += ase_strncpy (&str->buf[str->size], s, len);
str->buf[str->size] = ASE_T('\0');
return str->size;
}
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->size;
}

88
ase/cmn/str.h Normal file
View File

@ -0,0 +1,88 @@
/*
* $Id: str.h,v 1.3 2007/04/30 05:55:36 bacon Exp $
*
* {License}
*/
#ifndef _ASE_CMN_STR_H_
#define _ASE_CMN_STR_H_
#include <ase/cmn/types.h>
#include <ase/cmn/macros.h>
#define ASE_STR_LEN(x) ((x)->size)
#define ASE_STR_SIZE(x) ((x)->size + 1)
#define ASE_STR_CAPA(x) ((x)->capa)
#define ASE_STR_BUF(x) ((x)->buf)
#define ASE_STR_CHAR(x,idx) ((x)->buf[idx])
typedef struct ase_str_t ase_str_t;
struct ase_str_t
{
ase_char_t* buf;
ase_size_t size;
ase_size_t capa;
ase_mmgr_t* mmgr;
ase_bool_t __dynamic;
};
#ifdef __cplusplus
extern "C" {
#endif
ase_size_t ase_strlen (const ase_char_t* str);
ase_size_t ase_strcpy (
ase_char_t* buf, const ase_char_t* str);
ase_size_t ase_strxcpy (
ase_char_t* buf, ase_size_t bsz, const ase_char_t* str);
ase_size_t ase_strncpy (
ase_char_t* buf, const ase_char_t* str, ase_size_t 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 ase_strxncat (
ase_char_t* buf, ase_size_t bsz, const ase_char_t* str, ase_size_t len);
int ase_strcmp (const ase_char_t* s1, const ase_char_t* s2);
int ase_strxncmp (
const ase_char_t* s1, ase_size_t len1,
const ase_char_t* s2, ase_size_t len2);
int ase_strcasecmp (
const ase_char_t* s1, const ase_char_t* s2, ase_ccls_t* ccls);
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* ase_strdup (const ase_char_t* str, ase_mmgr_t* mmgr);
ase_char_t* ase_strxdup (
const ase_char_t* str, ase_size_t len, ase_mmgr_t* mmgr);
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* ase_strxnstr (
const ase_char_t* str, ase_size_t strsz,
const ase_char_t* sub, ase_size_t subsz);
ase_str_t* ase_str_open (ase_str_t* str, ase_size_t capa, ase_mmgr_t* mmgr);
void ase_str_close (ase_str_t* str);
void ase_str_clear (ase_str_t* str);
void ase_str_forfeit (ase_str_t* str);
void ase_str_swap (ase_str_t* str, ase_str_t* str2);
ase_size_t ase_str_cpy (ase_str_t* str, const ase_char_t* s);
ase_size_t ase_str_ncpy (ase_str_t* str, const ase_char_t* s, ase_size_t len);
ase_size_t ase_str_cat (ase_str_t* str, const ase_char_t* s);
ase_size_t ase_str_ncat (ase_str_t* str, const ase_char_t* s, ase_size_t len);
ase_size_t ase_str_ccat (ase_str_t* str, ase_char_t c);
ase_size_t ase_str_nccat (ase_str_t* str, ase_char_t c, ase_size_t len);
#ifdef __cplusplus
}
#endif
#endif

276
ase/cmn/types.h Normal file
View File

@ -0,0 +1,276 @@
/*
* $Id: types.h,v 1.3 2007/04/30 05:55:36 bacon Exp $
*
* {License}
*/
#ifndef _ASE_TYPES_H_
#define _ASE_TYPES_H_
#if defined(_WIN32)
#include <ase/cmn/conf_msw.h>
#elif defined(vms) || defined(__vms)
#include <ase/cmn/conf_vms.h>
#elif defined(__unix__) || defined(__unix) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || (defined(__APPLE__) && defined(__MACH__))
#if !defined(__unix__)
#define __unix__
#endif
#if !defined(__unix)
#define __unix
#endif
#include <ase/cmn/conf_unx.h>
#else
#error unsupported operating system
#endif
/* boolean type */
typedef int ase_bool_t;
#define ase_true (0 == 0)
#define ase_false (0 != 0)
/* tri-state type */
typedef int ase_tri_t;
#define ase_alive 1
#define ase_zombie 0
#define ase_dead -1
/* integer that can hold a pointer */
#if ASE_SIZEOF_VOID_P == ASE_SIZEOF_INT
typedef int ase_int_t;
typedef unsigned int ase_uint_t;
#elif ASE_SIZEOF_VOID_P == ASE_SIZEOF_LONG
typedef long ase_int_t;
typedef unsigned long ase_uint_t;
#elif ASE_SIZEOF_VOID_P == ASE_SIZEOF_LONG_LONG
typedef long long ase_int_t;
typedef unsigned long long ase_uint_t;
#elif ASE_SIZEOF_VOID_P == ASE_SIZEOF___INT32
typedef __int32 ase_int_t;
typedef unsigned __int32 ase_uint_t;
#elif ASE_SIZEOF_VOID_P == ASE_SIZEOF___INT64
typedef __int64 ase_int_t;
typedef unsigned __int64 ase_uint_t;
#else
#error unsupported pointer size
#endif
/* the largest integer supported by the system */
#if ASE_SIZEOF_LONG_LONG != 0
typedef long long ase_long_t;
typedef unsigned long long ase_ulong_t;
#elif ASE_SIZEOF___INT64 != 0
typedef __int64 ase_long_t;
typedef unsigned __int64 ase_ulong_t;
#else
typedef long ase_long_t;
typedef unsigned long ase_ulong_t;
#endif
/* integers of specific size */
#if ASE_SIZEOF_CHAR == 1
typedef char ase_int8_t;
typedef unsigned char ase_uint8_t;
#elif ASE_SIZEOF___INT8 == 1
typedef __int8 ase_int8_t;
typedef unsigned __int8 ase_uint8_t;
#endif
#if ASE_SIZEOF_SHORT == 2
typedef short ase_int16_t;
typedef unsigned short ase_uint16_t;
#elif ASE_SIZEOF___INT16 == 2
typedef __int16 ase_int16_t;
typedef unsigned __int16 ase_uint16_t;
#endif
#if ASE_SIZEOF_INT == 4
typedef int ase_int32_t;
typedef unsigned int ase_uint32_t;
#elif ASE_SIZEOF_LONG == 4
typedef long ase_int32_t;
typedef unsigned long ase_uint32_t;
#elif ASE_SIZEOF___INT32 == 4
typedef __int32 ase_int32_t;
typedef unsigned __int32 ase_uint32_t;
#endif
#if ASE_SIZEOF_INT == 8
#define ASE_HAVE_INT64_T
#define ASE_HAVE_UINT64_T
typedef int ase_int64_t;
typedef unsigned int ase_uint64_t;
#elif ASE_SIZEOF_LONG == 8
#define ASE_HAVE_INT64_T
#define ASE_HAVE_UINT64_T
typedef long ase_int64_t;
typedef unsigned long ase_uint64_t;
#elif ASE_SIZEOF_LONG_LONG == 8
#define ASE_HAVE_INT64_T
#define ASE_HAVE_UINT64_T
typedef long long ase_int64_t;
typedef unsigned long long ase_uint64_t;
#elif ASE_SIZEOF___INT64 == 8
#define ASE_HAVE_INT64_T
#define ASE_HAVE_UINT64_T
typedef __int64 ase_int64_t;
typedef unsigned __int64 ase_uint64_t;
#endif
#if ASE_SIZEOF_INT == 16
#define ASE_HAVE_INT128_T
#define ASE_HAVE_UINT128_T
typedef int ase_int128_t;
typedef unsigned int ase_uint128_t;
#elif ASE_SIZEOF_LONG == 16
#define ASE_HAVE_INT128_T
#define ASE_HAVE_UINT128_T
typedef long ase_int128_t;
typedef unsigned long ase_uint128_t;
#elif ASE_SIZEOF_LONG_LONG == 16
#define ASE_HAVE_INT128_T
#define ASE_HAVE_UINT128_T
typedef long long ase_int128_t;
typedef unsigned long long ase_uint128_t;
#elif ASE_SIZEOF___INT128 == 16
#define ASE_HAVE_INT128_T
#define ASE_HAVE_UINT128_T
typedef __int128 ase_int128_t;
typedef unsigned __int128 ase_uint128_t;
#endif
/* miscellaneous integral types */
typedef ase_uint8_t ase_byte_t;
typedef ase_uint_t ase_size_t;
typedef ase_int_t ase_ssize_t;
typedef ase_uint_t ase_word_t;
/* floating-point number */
#if defined(__FreeBSD__)
/* TODO: check if the support for long double is complete.
* if so, use long double for ase_real_t */
#define ASE_SIZEOF_REAL ASE_SIZEOF_DOUBLE
typedef double ase_real_t;
#elif ASE_SIZEOF_LONG_DOUBLE > ASE_SIZEOF_DOUBLE
#define ASE_SIZEOF_REAL ASE_SIZEOF_LONG_DOUBLE
typedef long double ase_real_t;
#else
#define ASE_SIZEOF_REAL ASE_SIZEOF_DOUBLE
typedef double ase_real_t;
#endif
/* character types */
typedef char ase_mchar_t;
typedef int ase_mcint_t;
#if defined(__cplusplus)
/* C++ */
typedef wchar_t ase_wchar_t;
typedef wchar_t ase_wcint_t;
/* all the way down from here for C */
#elif (ASE_SIZEOF_WCHAR_T == 2) || (ASE_SIZEOF_WCHAR_T == 0)
typedef unsigned short ase_wchar_t;
typedef unsigned short ase_wcint_t;
#elif (ASE_SIZEOF_WCHAR_T == 4)
#if defined(vms) || defined(__vms)
typedef unsigned int ase_wchar_t;
typedef int ase_wcint_t;
#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
typedef int ase_wchar_t;
typedef int ase_wcint_t;
#elif (defined(sun) || defined(__sun)) && defined(_LP64)
typedef int ase_wchar_t;
typedef int ase_wcint_t;
#elif defined(__APPLE__) && defined(__MACH__)
typedef int ase_wchar_t;
typedef int ase_wcint_t;
#elif defined(hpux) || defined(__hpux)
typedef unsigned int ase_wchar_t;
typedef int ase_wcint_t;
#elif ASE_SIZEOF_LONG == 4
typedef long ase_wchar_t;
typedef long ase_wcint_t;
#else
typedef int ase_wchar_t;
typedef int ase_wcint_t;
#endif
#else
#error unsupported size of wchar_t
#endif
#if defined(_WIN32) && (defined(UNICODE)||defined(_UNICODE))
#define ASE_CHAR_IS_WCHAR
typedef ase_wchar_t ase_char_t;
typedef ase_wcint_t ase_cint_t;
#else
#if defined(ASE_CHAR_IS_MCHAR)
typedef ase_mchar_t ase_char_t;
typedef ase_mcint_t ase_cint_t;
#elif defined(ASE_CHAR_IS_WCHAR)
typedef ase_wchar_t ase_char_t;
typedef ase_wcint_t ase_cint_t;
#elif defined(_MBCS)
#define ASE_CHAR_IS_MCHAR
typedef ase_mchar_t ase_char_t;
typedef ase_mcint_t ase_cint_t;
#else
#define ASE_CHAR_IS_WCHAR
typedef ase_wchar_t ase_char_t;
typedef ase_wcint_t ase_cint_t;
#endif
#endif
#if defined(ASE_CHAR_IS_WCHAR) && defined(_WIN32)
#ifndef UNICODE
#define UNICODE
#endif
#ifndef _UNICODE
#define _UNICODE
#endif
#endif
typedef struct ase_cstr_t ase_cstr_t;
typedef struct ase_mmgr_t ase_mmgr_t;
typedef struct ase_ccls_t ase_ccls_t;
typedef void* (*ase_malloc_t) (void* custom, ase_size_t n);
typedef void* (*ase_realloc_t) (void* custom, void* ptr, ase_size_t n);
typedef void (*ase_free_t) (void* custom, void* ptr);
typedef ase_bool_t (*ase_isccls_t) (void* custom, ase_cint_t c);
typedef ase_cint_t (*ase_toccls_t) (void* custom, ase_cint_t c);
struct ase_cstr_t
{
const ase_char_t* ptr;
ase_size_t len;
};
struct ase_mmgr_t
{
ase_malloc_t malloc;
ase_realloc_t realloc;
ase_free_t free;
void* custom_data;
};
struct ase_ccls_t
{
ase_isccls_t is_upper;
ase_isccls_t is_lower;
ase_isccls_t is_alpha;
ase_isccls_t is_digit;
ase_isccls_t is_xdigit;
ase_isccls_t is_alnum;
ase_isccls_t is_space;
ase_isccls_t is_print;
ase_isccls_t is_graph;
ase_isccls_t is_cntrl;
ase_isccls_t is_punct;
ase_toccls_t to_upper;
ase_toccls_t to_lower;
void* custom_data;
};
#endif

17
ase/cmn/unpack.h Normal file
View File

@ -0,0 +1,17 @@
/*
* $Id: unpack.h,v 1.3 2007/04/30 05:55:36 bacon Exp $
*
* {License}
*/
#if defined(__GNUC__)
#pragma pack()
#elif defined(__HP_aCC) || defined(__HP_cc)
#pragma PACK
#elif defined(_MSC_VER) || defined(__BORLANDC__)
#pragma pack(pop)
#elif defined(__DECC)
#pragma pack(pop)
#else
#pragma pack()
#endif

1395
ase/com/Awk.cpp Normal file

File diff suppressed because it is too large Load Diff

171
ase/com/Awk.h Normal file
View File

@ -0,0 +1,171 @@
/*
* $Id: Awk.h,v 1.3 2007/04/30 06:04:43 bacon Exp $
*
* {License}
*/
#ifndef _ASE_COM_AWK_H_
#define _ASE_COM_AWK_H_
#if _MSC_VER > 1000
#pragma once
#endif
#include "resource.h"
#include "asecom.h"
#include <ase/awk/awk.h>
#include <ase/awk/val.h>
#include "awk_cp.h"
/////////////////////////////////////////////////////////////////////////////
// CAwk
class CAwk :
public IDispatchImpl<IAwk, &IID_IAwk, &LIBID_ASECOM>,
public ISupportErrorInfo,
/*public CComObjectRoot,*/
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CAwk,&CLSID_Awk>,
public IConnectionPointContainerImpl<CAwk>,
public IProvideClassInfo2Impl<&CLSID_Awk, &DIID_IAwkEvents, &LIBID_ASECOM>,
public CProxyIAwkEvents< CAwk >
{
public:
ase_awk_t* handle;
int option;
int errnum;
ase_size_t errlin;
ase_char_t errmsg[256];
struct
{
struct
{
int parse;
int run;
} block;
struct
{
int parse;
int run;
} expr;
struct
{
int build;
int match;
} rex;
} max_depth;
IBuffer* read_src_buf;
IBuffer* write_src_buf;
ase_size_t read_src_pos;
ase_size_t read_src_len;
IBuffer* write_extio_buf;
struct bfn_t
{
struct
{
TCHAR* ptr;
size_t len;
} name;
size_t min_args;
size_t max_args;
struct bfn_t* next;
} * bfn_list;
BSTR entry_point;
VARIANT_BOOL debug;
VARIANT_BOOL use_longlong;
public:
CAwk();
~CAwk ();
BEGIN_COM_MAP(CAwk)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(IAwk)
COM_INTERFACE_ENTRY(ISupportErrorInfo)
COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
COM_INTERFACE_ENTRY(IProvideClassInfo)
COM_INTERFACE_ENTRY(IProvideClassInfo2)
END_COM_MAP()
BEGIN_CONNECTION_POINT_MAP(CAwk)
CONNECTION_POINT_ENTRY(DIID_IAwkEvents)
END_CONNECTION_POINT_MAP()
//DECLARE_NOT_AGGREGATABLE(CAwk)
// Remove the comment from the line above if you don't want your object to
// support aggregation.
DECLARE_REGISTRY_RESOURCEID(IDR_AWK)
// ISupportsErrorInfo
STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
// IAwk
public:
STDMETHOD(get_UseLongLong)(/*[out, retval]*/ VARIANT_BOOL *pVal);
STDMETHOD(put_UseLongLong)(/*[in]*/ VARIANT_BOOL newVal);
STDMETHOD(get_Debug)(/*[out, retval]*/ VARIANT_BOOL *pVal);
STDMETHOD(put_Debug)(/*[in]*/ VARIANT_BOOL newVal);
STDMETHOD(get_EntryPoint)(/*[out, retval]*/ BSTR *pVal);
STDMETHOD(put_EntryPoint)(/*[in]*/ BSTR newVal);
STDMETHOD(get_MaxDepthForRexMatch)(/*[out, retval]*/ int *pVal);
STDMETHOD(put_MaxDepthForRexMatch)(/*[in]*/ int newVal);
STDMETHOD(get_MaxDepthForRexBuild)(/*[out, retval]*/ int *pVal);
STDMETHOD(put_MaxDepthForRexBuild)(/*[in]*/ int newVal);
STDMETHOD(get_MaxDepthForExprRun)(/*[out, retval]*/ int *pVal);
STDMETHOD(put_MaxDepthForExprRun)(/*[in]*/ int newVal);
STDMETHOD(get_MaxDepthForExprParse)(/*[out, retval]*/ int *pVal);
STDMETHOD(put_MaxDepthForExprParse)(/*[in]*/ int newVal);
STDMETHOD(get_MaxDepthForBlockRun)(/*[out, retval]*/ int *pVal);
STDMETHOD(put_MaxDepthForBlockRun)(/*[in]*/ int newVal);
STDMETHOD(get_MaxDepthForBlockParse)(/*[out, retval]*/ int *pVal);
STDMETHOD(put_MaxDepthForBlockParse)(/*[in]*/ int newVal);
STDMETHOD(get_ArgumentsToEntryPoint)(/*[out, retval]*/ VARIANT_BOOL *pVal);
STDMETHOD(put_ArgumentsToEntryPoint)(/*[in]*/ VARIANT_BOOL newVal);
STDMETHOD(get_UseCrlf)(/*[out, retval]*/ VARIANT_BOOL *pVal);
STDMETHOD(put_UseCrlf)(/*[in]*/ VARIANT_BOOL newVal);
STDMETHOD(get_Nextofile)(/*[out, retval]*/ VARIANT_BOOL *pVal);
STDMETHOD(put_Nextofile)(/*[in]*/ VARIANT_BOOL newVal);
STDMETHOD(get_StripSpaces)(/*[out, retval]*/ VARIANT_BOOL *pVal);
STDMETHOD(put_StripSpaces)(/*[in]*/ VARIANT_BOOL newVal);
STDMETHOD(get_StringBaseOne)(/*[out, retval]*/ VARIANT_BOOL *pVal);
STDMETHOD(put_StringBaseOne)(/*[in]*/ VARIANT_BOOL newVal);
STDMETHOD(get_SupportBlockless)(/*[out, retval]*/ VARIANT_BOOL *pVal);
STDMETHOD(put_SupportBlockless)(/*[in]*/ VARIANT_BOOL newVal);
STDMETHOD(get_SupportExtio)(/*[out, retval]*/ VARIANT_BOOL *pVal);
STDMETHOD(put_SupportExtio)(/*[in]*/ VARIANT_BOOL newVal);
STDMETHOD(get_ConcatString)(/*[out, retval]*/ VARIANT_BOOL *pVal);
STDMETHOD(put_ConcatString)(/*[in]*/ VARIANT_BOOL newVal);
STDMETHOD(get_IdivOperator)(/*[out, retval]*/ VARIANT_BOOL *pVal);
STDMETHOD(put_IdivOperator)(/*[in]*/ VARIANT_BOOL newVal);
STDMETHOD(get_ShiftOperators)(/*[out, retval]*/ VARIANT_BOOL *pVal);
STDMETHOD(put_ShiftOperators)(/*[in]*/ VARIANT_BOOL newVal);
STDMETHOD(get_VariableShading)(/*[out, retval]*/ VARIANT_BOOL *pVal);
STDMETHOD(put_VariableShading)(/*[in]*/ VARIANT_BOOL newVal);
STDMETHOD(get_UniqueFunction)(/*[out, retval]*/ VARIANT_BOOL *pVal);
STDMETHOD(put_UniqueFunction)(/*[in]*/ VARIANT_BOOL newVal);
STDMETHOD(get_ExplicitVariable)(/*[out, retval]*/ VARIANT_BOOL *pVal);
STDMETHOD(put_ExplicitVariable)(/*[in]*/ VARIANT_BOOL newVal);
STDMETHOD(get_ImplicitVariable)(/*[out, retval]*/ VARIANT_BOOL *pVal);
STDMETHOD(put_ImplicitVariable)(/*[in]*/ VARIANT_BOOL newVal);
STDMETHOD(get_ErrorMessage)(/*[out, retval]*/ BSTR *pVal);
STDMETHOD(get_ErrorLine)(/*[out, retval]*/ int *pVal);
STDMETHOD(get_ErrorCode)(/*[out, retval]*/ int *pVal);
HRESULT __stdcall DeleteFunction (
/*[in]*/ BSTR name, /*[out, retval]*/ VARIANT_BOOL* ret);
HRESULT __stdcall AddFunction (
/*[in]*/ BSTR name, /*[in]*/ int minArgs,
/*[in]*/ int maxArgs, /*[out, retval]*/ VARIANT_BOOL* ret);
HRESULT __stdcall Parse (/*[out, retval]*/ VARIANT_BOOL* ret);
HRESULT __stdcall Run (
/*[in]*/ VARIANT argarray, /*[out, retval]*/ VARIANT_BOOL* ret);
};
#endif

25
ase/com/Awk.rgs Normal file
View File

@ -0,0 +1,25 @@
HKCR
{
ASE.Awk.1 = s 'ASE Awk Class'
{
CLSID = s '{AD863B53-F5EC-45C3-8B1C-6AC678227DC8}'
}
ASE.Awk = s 'ASE Awk Class'
{
CLSID = s '{AD863B53-F5EC-45C3-8B1C-6AC678227DC8}'
}
NoRemove CLSID
{
ForceRemove {AD863B53-F5EC-45C3-8B1C-6AC678227DC8} = s 'ASE Awk Class'
{
ProgID = s 'ASE.Awk.1'
VersionIndependentProgID = s 'ASE.Awk'
ForceRemove 'Programmable'
InprocServer32 = s '%MODULE%'
{
val ThreadingModel = s 'Apartment'
}
'TypeLib' = s '{F9C69806-16A1-4162-998A-876B33C470BF}'
}
}
}

70
ase/com/AwkExtio.cpp Normal file
View File

@ -0,0 +1,70 @@
/*
* $Id: AwkExtio.cpp,v 1.3 2007/04/30 06:04:43 bacon Exp $
*
* {License}
*/
#include "stdafx.h"
#include "asecom.h"
#include "AwkExtio.h"
#include <stdio.h>
/////////////////////////////////////////////////////////////////////////////
// CAwkExtio
CAwkExtio::CAwkExtio (): name (NULL)
{
VariantInit (&handle);
}
CAwkExtio::~CAwkExtio ()
{
if (name != NULL) SysFreeString (name);
VariantClear (&handle);
}
STDMETHODIMP CAwkExtio::get_Name (BSTR *pVal)
{
if (name == NULL) *pVal = name;
else
{
BSTR tmp = SysAllocStringLen (name, SysStringLen(name));
if (tmp == NULL) return E_OUTOFMEMORY;
*pVal = tmp;
}
return S_OK;
}
BOOL CAwkExtio::PutName (const TCHAR* val)
{
if (name != NULL) SysFreeString (name);
name = SysAllocString (val);
return (name == NULL)? FALSE: TRUE;
}
STDMETHODIMP CAwkExtio::get_Type(AwkExtioType *pVal)
{
*pVal = type;
return S_OK;
}
STDMETHODIMP CAwkExtio::get_Mode(AwkExtioMode *pVal)
{
*pVal = mode;
return S_OK;
}
STDMETHODIMP CAwkExtio::get_Handle (VARIANT *pVal)
{
VariantClear (pVal);
VariantCopy (pVal, &handle);
return S_OK;
}
STDMETHODIMP CAwkExtio::put_Handle (VARIANT newVal)
{
VariantClear (&handle);
VariantCopy (&handle, &newVal);
return S_OK;
}

53
ase/com/AwkExtio.h Normal file
View File

@ -0,0 +1,53 @@
/*
* $Id: AwkExtio.h,v 1.3 2007/04/30 06:04:43 bacon Exp $
*
* {License}
*/
#ifndef _ASE_COM_AWKEXTIO_H_
#define _ASE_COM_AWKEXTIO_H_
#include "resource.h"
#include <ase/awk/awk.h>
/////////////////////////////////////////////////////////////////////////////
// CAwkExtio
class ATL_NO_VTABLE CAwkExtio :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CAwkExtio, &CLSID_AwkExtio>,
public IDispatchImpl<IAwkExtio, &IID_IAwkExtio, &LIBID_ASECOM>
{
public:
BSTR name;
AwkExtioType type;
AwkExtioMode mode;
VARIANT handle;
IBuffer* read_buf;
ase_size_t read_buf_pos;
ase_size_t read_buf_len;
BOOL PutName (const TCHAR* val);
CAwkExtio ();
~CAwkExtio ();
DECLARE_REGISTRY_RESOURCEID(IDR_AWKEXTIO)
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(CAwkExtio)
COM_INTERFACE_ENTRY(IAwkExtio)
COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()
// IAwkExtio
public:
STDMETHOD(get_Handle)(/*[out, retval]*/ VARIANT *pVal);
STDMETHOD(put_Handle)(/*[in]*/ VARIANT newVal);
STDMETHOD(get_Mode)(/*[out, retval]*/ AwkExtioMode *pVal);
STDMETHOD(get_Type)(/*[out, retval]*/ AwkExtioType *pVal);
STDMETHOD(get_Name)(/*[out, retval]*/ BSTR *pVal);
};
#endif //__AWKEXTIO_H_

26
ase/com/AwkExtio.rgs Normal file
View File

@ -0,0 +1,26 @@
HKCR
{
ASE.AwkExtio.1 = s 'ASE AwkExtio Class'
{
CLSID = s '{F52F065A-5FD4-4F4D-AFEA-F5E446B16383}'
}
ASE.AwkExtio = s 'ASE AwkExtio Class'
{
CLSID = s '{F52F065A-5FD4-4F4D-AFEA-F5E446B16383}'
CurVer = s 'ASE.AwkExtio.1'
}
NoRemove CLSID
{
ForceRemove {F52F065A-5FD4-4F4D-AFEA-F5E446B16383} = s 'ASE AwkExtio Class'
{
ProgID = s 'ASE.AwkExtio.1'
VersionIndependentProgID = s 'ASE.AwkExtio'
ForceRemove 'Programmable'
InprocServer32 = s '%MODULE%'
{
val ThreadingModel = s 'Apartment'
}
'TypeLib' = s '{F9C69806-16A1-4162-998A-876B33C470BF}'
}
}
}

51
ase/com/Buffer.cpp Normal file
View File

@ -0,0 +1,51 @@
/*
* $Id: Buffer.cpp,v 1.3 2007/04/30 06:04:43 bacon Exp $
*
* {License}
*/
#include "stdafx.h"
#include "Buffer.h"
CBuffer::CBuffer ()
{
str = NULL;
}
CBuffer::~CBuffer ()
{
if (str != NULL) SysFreeString (str);
}
STDMETHODIMP CBuffer::get_Value (BSTR *pVal)
{
if (str == NULL) *pVal = NULL;
else
{
BSTR tmp = SysAllocStringLen(str, SysStringLen(str));
if (tmp == NULL) return E_OUTOFMEMORY;
*pVal = tmp;
}
return S_OK;
}
STDMETHODIMP CBuffer::put_Value (BSTR newVal)
{
if (str != NULL) SysFreeString (str);
if (newVal == NULL) str = newVal;
else
{
str = SysAllocStringLen (newVal, SysStringLen(newVal));
if (str == NULL) return E_OUTOFMEMORY;
}
return S_OK;
}
BOOL CBuffer::PutValue (const TCHAR* val, SIZE_T len)
{
if (str != NULL) SysFreeString (str);
str = SysAllocStringLen (val, len);
return (str == NULL)? FALSE: TRUE;
}

40
ase/com/Buffer.h Normal file
View File

@ -0,0 +1,40 @@
/*
* $Id: Buffer.h,v 1.3 2007/04/30 06:04:43 bacon Exp $
*
* {License}
*/
#ifndef _ASE_COM_BUFFER_H_
#define _ASE_COM_BUFFER_H_
#include "resource.h"
#include "asecom.h"
class ATL_NO_VTABLE CBuffer :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CBuffer, &CLSID_Buffer>,
public IDispatchImpl<IBuffer, &IID_IBuffer, &LIBID_ASECOM>
{
public:
BSTR str;
BOOL PutValue (const TCHAR* val, SIZE_T len);
public:
CBuffer ();
~CBuffer ();
DECLARE_REGISTRY_RESOURCEID(IDR_BUFFER)
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(CBuffer)
COM_INTERFACE_ENTRY(IBuffer)
COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()
public:
STDMETHOD(get_Value)(/*[out, retval]*/ BSTR *pVal);
STDMETHOD(put_Value)(/*[in]*/ BSTR newVal);
};
#endif

26
ase/com/Buffer.rgs Normal file
View File

@ -0,0 +1,26 @@
HKCR
{
ASE.Buffer.1 = s 'ASE Buffer Class'
{
CLSID = s '{866B79A7-7628-4808-8AE7-784BE2491C80}'
}
ASE.Buffer = s 'ASE Buffer Class'
{
CLSID = s '{866B79A7-7628-4808-8AE7-784BE2491C80}'
CurVer = s 'ASE.Buffer.1'
}
NoRemove CLSID
{
ForceRemove {866B79A7-7628-4808-8AE7-784BE2491C80} = s 'ASE Buffer Class'
{
ProgID = s 'ASE.Buffer.1'
VersionIndependentProgID = s 'ASE.Buffer'
ForceRemove 'Programmable'
InprocServer32 = s '%MODULE%'
{
val ThreadingModel = s 'Apartment'
}
'TypeLib' = s '{F9C69806-16A1-4162-998A-876B33C470BF}'
}
}
}

78
ase/com/asecom.cpp Normal file
View File

@ -0,0 +1,78 @@
/*
* $Id: asecom.cpp,v 1.3 2007/04/30 06:04:43 bacon Exp $
*
* {License}
*/
// Note: Proxy/Stub Information
// To build a separate proxy/stub DLL,
// run nmake -f aseps.mk in the project directory.
#include "stdafx.h"
#include "resource.h"
#include <initguid.h>
#include "asecom.h"
#include "asecom_i.c"
#include "Awk.h"
#include "Buffer.h"
#include "AwkExtio.h"
CComModule _Module;
BEGIN_OBJECT_MAP(ObjectMap)
OBJECT_ENTRY(CLSID_Awk, CAwk)
OBJECT_ENTRY(CLSID_Buffer, CBuffer)
OBJECT_ENTRY(CLSID_AwkExtio, CAwkExtio)
END_OBJECT_MAP()
/////////////////////////////////////////////////////////////////////////////
// DLL Entry Point
extern "C"
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
_Module.Init(ObjectMap, hInstance, &LIBID_ASECOM);
DisableThreadLibraryCalls(hInstance);
}
else if (dwReason == DLL_PROCESS_DETACH)
_Module.Term();
return TRUE; // ok
}
/////////////////////////////////////////////////////////////////////////////
// Used to determine whether the DLL can be unloaded by OLE
STDAPI DllCanUnloadNow(void)
{
return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
}
/////////////////////////////////////////////////////////////////////////////
// Returns a class factory to create an object of the requested type
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
return _Module.GetClassObject(rclsid, riid, ppv);
}
/////////////////////////////////////////////////////////////////////////////
// DllRegisterServer - Adds entries to the system registry
STDAPI DllRegisterServer(void)
{
// registers object, typelib and all interfaces in typelib
return _Module.RegisterServer(TRUE);
}
/////////////////////////////////////////////////////////////////////////////
// DllUnregisterServer - Removes entries from the system registry
STDAPI DllUnregisterServer(void)
{
return _Module.UnregisterServer(TRUE);
}

9
ase/com/asecom.def Normal file
View File

@ -0,0 +1,9 @@
; ase.def : Declares the module parameters.
LIBRARY "asecom.dll"
EXPORTS
DllCanUnloadNow @1 PRIVATE
DllGetClassObject @2 PRIVATE
DllRegisterServer @3 PRIVATE
DllUnregisterServer @4 PRIVATE

207
ase/com/asecom.dsp Normal file
View File

@ -0,0 +1,207 @@
# Microsoft Developer Studio Project File - Name="asecom" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
CFG=asecom - Win32 Debug
!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 "asecom.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 "asecom.mak" CFG="asecom - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "asecom - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE "asecom - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "asecom - 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 ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_USRDLL" /D "_UNICODE" /Yu"stdafx.h" /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /ZI /Od /I "../.." /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_USRDLL" /D "_UNICODE" /FR /Yu"stdafx.h" /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo /o"debug/asecom.bsc"
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept
# ADD LINK32 aseawk.lib asecmn.lib aseutl.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /implib:"debug/asecom.lib" /pdbtype:sept /libpath:"$(OutDir)"
# Begin Custom Build - Performing registration
IntDir=.\debug
OutDir=.\../debug/lib
TargetPath=\projects\ase\debug\lib\asecom.dll
InputPath=\projects\ase\debug\lib\asecom.dll
SOURCE="$(InputPath)"
"$(IntDir)\regsvr32.trg" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
copy .\asecom.tlb "$(OUTDIR)\asecom.tlb"
if "%OS%"=="" goto NOTNT
if not "%OS%"=="Windows_NT" goto NOTNT
regsvr32 /s /c "$(TargetPath)"
echo regsvr32 exec. time > "$(IntDir)\regsvr32.trg"
goto end
:NOTNT
echo Warning : Cannot register DLL on Windows 95
:end
# End Custom Build
!ELSEIF "$(CFG)" == "asecom - 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 ""
# ADD BASE CPP /nologo /MT /W3 /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_USRDLL" /D "_UNICODE" /D "_ATL_STATIC_REGISTRY" /D "_ATL_MIN_CRT" /Yu"stdafx.h" /FD /c
# ADD CPP /nologo /MT /W3 /O1 /I "../.." /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_USRDLL" /D "_UNICODE" /D "_ATL_STATIC_REGISTRY" /Yu"stdafx.h" /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo /o"release/awk.bsc"
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386
# ADD LINK32 aseawk.lib asecmn.lib aseutl.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 /implib:"release/asecom.lib" /libpath:"$(OutDir)"
# Begin Custom Build - Performing registration
IntDir=.\release
OutDir=.\../release/lib
TargetPath=\projects\ase\release\lib\asecom.dll
InputPath=\projects\ase\release\lib\asecom.dll
SOURCE="$(InputPath)"
"$(IntDir)\regsvr32.trg" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
copy .\asecom.tlb "$(OUTDIR)\asecom.tlb"
if "%OS%"=="" goto NOTNT
if not "%OS%"=="Windows_NT" goto NOTNT
regsvr32 /s /c "$(TargetPath)"
echo regsvr32 exec. time > "$(IntDir)\regsvr32.trg"
goto end
:NOTNT
echo Warning : Cannot register DLL on Windows 95
:end
# End Custom Build
!ENDIF
# Begin Target
# Name "asecom - Win32 Debug"
# Name "asecom - Win32 Release"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\asecom.cpp
# End Source File
# Begin Source File
SOURCE=.\asecom.def
# End Source File
# Begin Source File
SOURCE=.\asecom.idl
# ADD MTL /tlb ".\asecom.tlb" /h "asecom.h" /iid "asecom_i.c" /Oicf
# End Source File
# Begin Source File
SOURCE=.\asecom.rc
# End Source File
# Begin Source File
SOURCE=.\Awk.cpp
# End Source File
# Begin Source File
SOURCE=.\AwkExtio.cpp
# End Source File
# Begin Source File
SOURCE=.\Buffer.cpp
# End Source File
# Begin Source File
SOURCE=.\stdafx.cpp
# ADD CPP /Yc"stdafx.h"
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\Awk.h
# End Source File
# Begin Source File
SOURCE=.\awk_cp.h
# End Source File
# Begin Source File
SOURCE=.\AwkExtio.h
# End Source File
# Begin Source File
SOURCE=.\Buffer.h
# End Source File
# Begin Source File
SOURCE=.\resource.h
# End Source File
# Begin Source File
SOURCE=.\stdafx.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"
# Begin Source File
SOURCE=.\Awk.rgs
# End Source File
# Begin Source File
SOURCE=.\AwkExtio.rgs
# End Source File
# Begin Source File
SOURCE=.\Buffer.rgs
# End Source File
# End Group
# End Target
# End Project

318
ase/com/asecom.idl Normal file
View File

@ -0,0 +1,318 @@
/*
* $Id: asecom.idl,v 1.3 2007/04/30 06:04:43 bacon Exp $
*/
import "oaidl.idl";
import "ocidl.idl";
/* IAwk */
[
object,
uuid(05BC1C9F-7C4E-4F77-B186-2E0FD26C0641),
dual,
helpstring("ASE Awk Interface"),
pointer_default(unique)
]
interface IAwk : IDispatch
{
[id(1), helpstring("method Parse")]
HRESULT Parse([out,retval] VARIANT_BOOL* ret);
[id(2), helpstring("method Run")]
HRESULT Run([in] VARIANT argarray, [out,retval] VARIANT_BOOL* ret);
[id(3), helpstring("method AddFunction")]
HRESULT AddFunction([in] BSTR name, [in] int minArgs, [in] int maxArgs, [out,retval] VARIANT_BOOL* ret);
[id(4), helpstring("method DeleteFunction")]
HRESULT DeleteFunction([in] BSTR name, [out,retval] VARIANT_BOOL* ret);
[propget, id(5), helpstring("property ErrorCode")]
HRESULT ErrorCode([out,retval] int *pVal);
[propget, id(6), helpstring("property ErrorLine")]
HRESULT ErrorLine([out,retval] int *pVal);
[propget, id(7), helpstring("property ErrorMessage")]
HRESULT ErrorMessage([out,retval] BSTR *pVal);
[propget, id(8), helpstring("property ImplicitVariable")]
HRESULT ImplicitVariable([out,retval] VARIANT_BOOL *pVal);
[propput, id(8), helpstring("property ImplicitVariable")]
HRESULT ImplicitVariable([in] VARIANT_BOOL newVal);
[propget, id(9), helpstring("property ExplicitVariable")]
HRESULT ExplicitVariable([out,retval] VARIANT_BOOL *pVal);
[propput, id(9), helpstring("property ExplicitVariable")]
HRESULT ExplicitVariable([in] VARIANT_BOOL newVal);
[propget, id(10), helpstring("property UniqueFunction")]
HRESULT UniqueFunction([out,retval] VARIANT_BOOL *pVal);
[propput, id(10), helpstring("property UniqueFunction")]
HRESULT UniqueFunction([in] VARIANT_BOOL newVal);
[propget, id(11), helpstring("property VariableShading")]
HRESULT VariableShading([out,retval] VARIANT_BOOL *pVal);
[propput, id(11), helpstring("property VariableShading")]
HRESULT VariableShading([in] VARIANT_BOOL newVal);
[propget, id(12), helpstring("property ShiftOperators")]
HRESULT ShiftOperators([out,retval] VARIANT_BOOL *pVal);
[propput, id(12), helpstring("property ShiftOperators")]
HRESULT ShiftOperators([in] VARIANT_BOOL newVal);
[propget, id(13), helpstring("property IdivOperator")]
HRESULT IdivOperator([out,retval] VARIANT_BOOL *pVal);
[propput, id(13), helpstring("property IdivOperator")]
HRESULT IdivOperator([in] VARIANT_BOOL newVal);
[propget, id(14), helpstring("property ConcatString")]
HRESULT ConcatString([out,retval] VARIANT_BOOL *pVal);
[propput, id(14), helpstring("property ConcatString")]
HRESULT ConcatString([in] VARIANT_BOOL newVal);
[propget, id(15), helpstring("property SupportExtio")]
HRESULT SupportExtio([out,retval] VARIANT_BOOL *pVal);
[propput, id(15), helpstring("property SupportExtio")]
HRESULT SupportExtio([in] VARIANT_BOOL newVal);
[propget, id(16), helpstring("property SupportBlockless")]
HRESULT SupportBlockless([out,retval] VARIANT_BOOL *pVal);
[propput, id(16), helpstring("property SupportBlockless")]
HRESULT SupportBlockless([in] VARIANT_BOOL newVal);
[propget, id(17), helpstring("property StringBaseOne")]
HRESULT StringBaseOne([out,retval] VARIANT_BOOL *pVal);
[propput, id(17), helpstring("property StringBaseOne")]
HRESULT StringBaseOne([in] VARIANT_BOOL newVal);
[propget, id(18), helpstring("property StripSpaces")]
HRESULT StripSpaces([out,retval] VARIANT_BOOL *pVal);
[propput, id(18), helpstring("property StripSpaces")]
HRESULT StripSpaces([in] VARIANT_BOOL newVal);
[propget, id(19), helpstring("property Nextofile")]
HRESULT Nextofile([out,retval] VARIANT_BOOL *pVal);
[propput, id(19), helpstring("property Nextofile")]
HRESULT Nextofile([in] VARIANT_BOOL newVal);
[propget, id(20), helpstring("property UseCrlf")]
HRESULT UseCrlf([out,retval] VARIANT_BOOL *pVal);
[propput, id(20), helpstring("property UseCrlf")]
HRESULT UseCrlf([in] VARIANT_BOOL newVal);
[propget, id(21), helpstring("property ArgumentsToEntryPoint")]
HRESULT ArgumentsToEntryPoint([out,retval] VARIANT_BOOL *pVal);
[propput, id(21), helpstring("property ArgumentsToEntryPoint")]
HRESULT ArgumentsToEntryPoint([in] VARIANT_BOOL newVal);
[propget, id(22), helpstring("property MaxDepthForBlockParse")]
HRESULT MaxDepthForBlockParse([out,retval] int *pVal);
[propput, id(22), helpstring("property MaxDepthForBlockParse")]
HRESULT MaxDepthForBlockParse([in] int newVal);
[propget, id(23), helpstring("property MaxDepthForBlockRun")]
HRESULT MaxDepthForBlockRun([out,retval] int *pVal);
[propput, id(23), helpstring("property MaxDepthForBlockRun")]
HRESULT MaxDepthForBlockRun([in] int newVal);
[propget, id(24), helpstring("property MaxDepthForExprParse")]
HRESULT MaxDepthForExprParse([out,retval] int *pVal);
[propput, id(24), helpstring("property MaxDepthForExprParse")]
HRESULT MaxDepthForExprParse([in] int newVal);
[propget, id(25), helpstring("property MaxDepthForExprRun")]
HRESULT MaxDepthForExprRun([out,retval] int *pVal);
[propput, id(25), helpstring("property MaxDepthForExprRun")]
HRESULT MaxDepthForExprRun([in] int newVal);
[propget, id(26), helpstring("property MaxDepthForRexBuild")]
HRESULT MaxDepthForRexBuild([out,retval] int *pVal);
[propput, id(26), helpstring("property MaxDepthForRexBuild")]
HRESULT MaxDepthForRexBuild([in] int newVal);
[propget, id(27), helpstring("property MaxDepthForRexMatch")]
HRESULT MaxDepthForRexMatch([out,retval] int *pVal);
[propput, id(27), helpstring("property MaxDepthForRexMatch")]
HRESULT MaxDepthForRexMatch([in] int newVal);
[propget, id(28), helpstring("property EntryPoint")]
HRESULT EntryPoint([out,retval] BSTR *pVal);
[propput, id(28), helpstring("property EntryPoint")]
HRESULT EntryPoint([in] BSTR newVal);
[propget, id(29), helpstring("property Debug")]
HRESULT Debug([out,retval] VARIANT_BOOL *pVal);
[propput, id(29), helpstring("property Debug")]
HRESULT Debug([in] VARIANT_BOOL newVal);
[propget, id(30), helpstring("property UseLongLong")]
HRESULT UseLongLong([out,retval] VARIANT_BOOL *pVal);
[propput, id(30), helpstring("property UseLongLong")]
HRESULT UseLongLong([in] VARIANT_BOOL newVal);
};
/* ASECOM */
[
uuid(F9C69806-16A1-4162-998A-876B33C470BF),
version(1.0),
helpstring("ASECOM 1.0 Type Library")
]
library ASECOM
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");
[helpstring("Awk source mode")]
typedef [v1_enum] enum AwkSourceMode
{
AWK_SOURCE_READ = 0,
AWK_SOURCE_WRITE = 1
} AwkSourceMode;
[helpstring("AwkExtio type")]
typedef [v1_enum] enum AwkExtioType
{
AWK_EXTIO_PIPE = 0,
AWK_EXTIO_COPROC = 1,
AWK_EXTIO_FILE = 2,
AWK_EXTIO_CONSOLE = 3
} AwkExtioType;
[helpstring("AwkExtio mode")]
typedef [v1_enum] enum AwkExtioMode
{
AWK_EXTIO_PIPE_READ = 0,
AWK_EXTIO_PIPE_WRITE = 1,
AWK_EXTIO_COPROC_READ = 0,
AWK_EXTIO_COPROC_WRITE = 1,
AWK_EXTIO_COPROC_RDWR = 2,
AWK_EXTIO_FILE_READ = 0,
AWK_EXTIO_FILE_WRITE = 1,
AWK_EXTIO_FILE_APPEND = 2,
AWK_EXTIO_CONSOLE_READ = 0,
AWK_EXTIO_CONSOLE_WRITE = 1
} AwkExtioMode;
/* IBuffer */
[
object,
uuid(AD5EA986-37E9-410E-A78E-21799104293A),
dual,
helpstring("IBuffer Interface"),
pointer_default(unique)
]
interface IBuffer : IDispatch
{
[propget, id(1), helpstring("property Value")]
HRESULT Value([out,retval] BSTR *pVal);
[propput, id(1), helpstring("property Value")]
HRESULT Value([in] BSTR newVal);
};
/* IAwkExtio */
[
object,
uuid(BE0B91FF-9944-4DFC-A55B-1FE14E24AFEE),
dual,
helpstring("IAwkExtio Interface"),
pointer_default(unique)
]
interface IAwkExtio : IDispatch
{
[propget, id(1), helpstring("property Name")]
HRESULT Name([out,retval] BSTR *pVal);
[propget, id(2), helpstring("property Type")]
HRESULT Type([out,retval] AwkExtioType *pVal);
[propget, id(3), helpstring("property Mode")]
HRESULT Mode([out,retval] AwkExtioMode *pVal);
[propget, id(4), helpstring("property Handle")]
HRESULT Handle([out,retval] VARIANT *pVal);
[propput, id(4), helpstring("property Handle")]
HRESULT Handle([in] VARIANT newVal);
};
/* IAwkEvents */
[
uuid(1351DC8F-10AD-4C40-A2FA-9A2E89C27AC8),
helpstring("ASE Awk Events Interface")
]
dispinterface IAwkEvents
{
properties:
methods:
[id(1), helpstring("open the source code")]
HRESULT OpenSource([in] AwkSourceMode mode, [out,retval] int* ret);
[id(2), helpstring("close the source code")]
HRESULT CloseSource([in] AwkSourceMode mode, [out,retval] int* ret);
[id(3), helpstring("read the source code")]
HRESULT ReadSource([in] IBuffer* buf, [out,retval] int* ret);
[id(4), helpstring("write the source code")]
HRESULT WriteSource([in] IBuffer* buf, [out,retval] int* ret);
[id(5), helpstring("method OpenExtio")]
HRESULT OpenExtio([in] IAwkExtio* extio, [out,retval] int* ret);
[id(6), helpstring("method CloseExtio")]
HRESULT CloseExtio([in] IAwkExtio* extio, [out,retval] int* ret);
[id(7), helpstring("method ReadExtio")]
HRESULT ReadExtio([in] IAwkExtio* extio, [in] IBuffer* buf, [out,retval] int* ret);
[id(8), helpstring("method WriteExtio")]
HRESULT WriteExtio([in] IAwkExtio* extio, [in] IBuffer* buf, [out,retval] int* ret);
[id(9), helpstring("method FlushExtio")]
HRESULT FlushExtio([in] IAwkExtio* extio, [out,retval] int* ret);
[id(10), helpstring("method NextExtio")]
HRESULT NextExtio([in] IAwkExtio* extio, [out,retval] int* ret);
[id(11), helpstring("method HandleFunction")]
HRESULT HandleFunction([in] BSTR name, [in] VARIANT argarray, [out,retval] VARIANT* ret);
/*[id(12), helpstring("method OnClose")]
HRESULT OnClose([out,retval] int* ret);*/
};
/* Awk */
[
uuid(AD863B53-F5EC-45C3-8B1C-6AC678227DC8),
helpstring("ASE Awk Class")
]
coclass Awk
{
[default] interface IAwk;
[default,source] dispinterface IAwkEvents;
};
/* AwkExtio */
[
uuid(F52F065A-5FD4-4F4D-AFEA-F5E446B16383),
helpstring("ASE AwkExtio Class")
]
coclass AwkExtio
{
[default] interface IAwkExtio;
};
/* Buffer */
[
uuid(866B79A7-7628-4808-8AE7-784BE2491C80),
helpstring("ASE Buffer Class")
]
coclass Buffer
{
[default] interface IBuffer;
};
};

121
ase/com/asecom.rc Normal file
View File

@ -0,0 +1,121 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "winres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""winres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"1 TYPELIB ""asecom.tlb""\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "FileDescription", "ASE.COM"
VALUE "FileVersion", "1, 0, 0, 0"
VALUE "InternalName", "ASECOM"
VALUE "LegalCopyright", "Hyung-Hwan Chung. All rights reserved"
VALUE "OriginalFilename", "asecom.dll"
VALUE "ProductName", "ASE.COM"
VALUE "ProductVersion", "1, 0, 0, 0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
/////////////////////////////////////////////////////////////////////////////
//
// REGISTRY
//
IDR_AWK REGISTRY "Awk.rgs"
IDR_AWKEXTIO REGISTRY "AwkExtio.rgs"
IDR_BUFFER REGISTRY "Buffer.rgs"
/////////////////////////////////////////////////////////////////////////////
//
// String Table
//
STRINGTABLE
BEGIN
IDS_PROJNAME "ASE COM Project"
END
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
1 TYPELIB "asecom.tlb"
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

441
ase/com/asecom.vcproj Normal file
View File

@ -0,0 +1,441 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="asecom"
ProjectGUID="{963AF7B5-12E6-42B6-8CBE-89136C1A109B}"
RootNamespace="asecom"
Keyword="AtlProj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\..\debug\lib"
IntermediateDirectory=".\debug"
ConfigurationType="2"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
Description="Performing registration"
CommandLine="copy .\asecom.tlb &quot;$(OUTDIR)\asecom.tlb&quot;&#x0D;&#x0A;if &quot;%OS%&quot;==&quot;&quot; goto NOTNT&#x0D;&#x0A;if not &quot;%OS%&quot;==&quot;Windows_NT&quot; goto NOTNT&#x0D;&#x0A;regsvr32 /s /c &quot;$(TargetPath)&quot;&#x0D;&#x0A;echo regsvr32 exec. time &gt; &quot;$(IntDir)\regsvr32.trg&quot;&#x0D;&#x0A;goto end&#x0D;&#x0A;:NOTNT&#x0D;&#x0A;echo Warning : Cannot register DLL on Windows 95&#x0D;&#x0A;:end&#x0D;&#x0A;"
Outputs="$(IntDir)\regsvr32.trg"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\../debug/lib/asecom.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../.."
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="2"
PrecompiledHeaderThrough="stdafx.h"
PrecompiledHeaderFile=".\debug/asecom.pch"
AssemblerListingLocation=".\debug/"
ObjectFile=".\debug/"
ProgramDataBaseFileName=".\debug/"
BrowseInformation="1"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="aseawk.lib asecmn.lib aseutl.lib odbc32.lib odbccp32.lib"
OutputFile="$(OutDir)\asecom.dll"
LinkIncremental="2"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="$(OutDir)"
ModuleDefinitionFile=".\asecom.def"
GenerateDebugInformation="true"
ProgramDatabaseFile=".\../debug/lib/asecom.pdb"
SubSystem="2"
ImportLibrary="debug/asecom.lib"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile="debug/asecom.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory=".\..\release\lib"
IntermediateDirectory=".\release"
ConfigurationType="2"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
UseOfATL="1"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
Description="Performing registration"
CommandLine="copy .\asecom.tlb &quot;$(OUTDIR)\asecom.tlb&quot;&#x0D;&#x0A;if &quot;%OS%&quot;==&quot;&quot; goto NOTNT&#x0D;&#x0A;if not &quot;%OS%&quot;==&quot;Windows_NT&quot; goto NOTNT&#x0D;&#x0A;regsvr32 /s /c &quot;$(TargetPath)&quot;&#x0D;&#x0A;echo regsvr32 exec. time &gt; &quot;$(IntDir)\regsvr32.trg&quot;&#x0D;&#x0A;goto end&#x0D;&#x0A;:NOTNT&#x0D;&#x0A;echo Warning : Cannot register DLL on Windows 95&#x0D;&#x0A;:end&#x0D;&#x0A;"
Outputs="$(IntDir)\regsvr32.trg"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\../release/lib/asecom.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="1"
InlineFunctionExpansion="1"
AdditionalIncludeDirectories="../.."
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL"
StringPooling="true"
RuntimeLibrary="0"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="2"
PrecompiledHeaderThrough="stdafx.h"
PrecompiledHeaderFile=".\release/asecom.pch"
AssemblerListingLocation=".\release/"
ObjectFile=".\release/"
ProgramDataBaseFileName=".\release/"
WarningLevel="3"
SuppressStartupBanner="true"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="aseawk.lib asecmn.lib aseutl.lib odbc32.lib odbccp32.lib"
OutputFile="$(OutDir)\asecom.dll"
LinkIncremental="1"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="$(OutDir)"
ModuleDefinitionFile=".\asecom.def"
ProgramDatabaseFile=".\../release/lib/asecom.pdb"
SubSystem="2"
ImportLibrary="release/asecom.lib"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile="release/awk.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<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="asecom.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="asecom.def"
>
</File>
<File
RelativePath="asecom.idl"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCMIDLTool"
GenerateStublessProxies="true"
TypeLibraryName=".\asecom.tlb"
HeaderFileName="asecom.h"
InterfaceIdentifierFileName="asecom_i.c"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCMIDLTool"
GenerateStublessProxies="true"
TypeLibraryName=".\asecom.tlb"
HeaderFileName="asecom.h"
InterfaceIdentifierFileName="asecom_i.c"
/>
</FileConfiguration>
</File>
<File
RelativePath="asecom.rc"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions=""
AdditionalIncludeDirectories="$(OUTDIR)"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions=""
AdditionalIncludeDirectories="$(OUTDIR)"
/>
</FileConfiguration>
</File>
<File
RelativePath="Awk.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="AwkExtio.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="Buffer.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="stdafx.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
UsePrecompiledHeader="1"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
UsePrecompiledHeader="1"
/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl"
>
<File
RelativePath="Awk.h"
>
</File>
<File
RelativePath="awk_cp.h"
>
</File>
<File
RelativePath="AwkExtio.h"
>
</File>
<File
RelativePath="Buffer.h"
>
</File>
<File
RelativePath="resource.h"
>
</File>
<File
RelativePath="stdafx.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
>
<File
RelativePath="Awk.rgs"
>
</File>
<File
RelativePath="AwkExtio.rgs"
>
</File>
<File
RelativePath="Buffer.rgs"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

11
ase/com/aseps.def Normal file
View File

@ -0,0 +1,11 @@
LIBRARY "asePS"
DESCRIPTION 'Proxy/Stub DLL'
EXPORTS
DllGetClassObject @1 PRIVATE
DllCanUnloadNow @2 PRIVATE
GetProxyDllInfo @3 PRIVATE
DllRegisterServer @4 PRIVATE
DllUnregisterServer @5 PRIVATE

16
ase/com/aseps.mk Normal file
View File

@ -0,0 +1,16 @@
aseps.dll: dlldata.obj ase_p.obj ase_i.obj
link /dll /out:aseps.dll /def:aseps.def /entry:DllMain dlldata.obj ase_p.obj ase_i.obj \
kernel32.lib rpcndr.lib rpcns4.lib rpcrt4.lib oleaut32.lib uuid.lib \
.c.obj:
cl /c /Ox /DWIN32 /D_WIN32_WINNT=0x0400 /DREGISTER_PROXY_DLL \
$<
clean:
@del aseps.dll
@del aseps.lib
@del aseps.exp
@del dlldata.obj
@del ase_p.obj
@del ase_i.obj

637
ase/com/awk_cp.h Normal file
View File

@ -0,0 +1,637 @@
/*
* $Id: awk_cp.h,v 1.3 2007/04/30 06:04:43 bacon Exp $
*
* {License}
*/
#ifndef _AWK_CP_H_
#define _AWK_CP_H_
template <class T>
class CProxyIAwkEvents:
public IConnectionPointImpl<T, &DIID_IAwkEvents, CComDynamicUnkArray>
{
public:
INT Fire_OpenSource(INT mode)
{
T* pT = static_cast<T*>(this);
int i, nconns = m_vec.GetSize();
CComVariant args[1], ret;
for (i = 0; i < nconns; i++)
{
pT->Lock();
CComPtr<IUnknown> sp = m_vec.GetAt(i);
pT->Unlock();
IDispatch* pDispatch =
reinterpret_cast<IDispatch*>(sp.p);
if (pDispatch == NULL) continue;
VariantClear (&ret);
VariantClear (&args[0]);
args[0] = mode;
DISPPARAMS disp = { args, NULL, 1, 0 };
HRESULT hr = pDispatch->Invoke (
0x1, IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_METHOD, &disp, &ret, NULL, NULL);
if (FAILED(hr)) continue;
if (ret.vt == VT_EMPTY)
{
/* probably, the handler has not been implemeted*/
continue;
}
hr = ret.ChangeType (VT_I4);
if (FAILED(hr))
{
/* TODO: set the error code properly... */
/* invalid value returned... */
return -1;
}
return ret.lVal;
}
return -1;
}
INT Fire_CloseSource(INT mode)
{
T* pT = static_cast<T*>(this);
int i, nconns = m_vec.GetSize();
CComVariant args[1], ret;
for (i = 0; i < nconns; i++)
{
pT->Lock();
CComPtr<IUnknown> sp = m_vec.GetAt(i);
pT->Unlock();
IDispatch* pDispatch =
reinterpret_cast<IDispatch*>(sp.p);
if (pDispatch == NULL) continue;
VariantClear (&ret);
VariantClear (&args[0]);
args[0] = mode;
DISPPARAMS disp = { args, NULL, 1, 0 };
HRESULT hr = pDispatch->Invoke (
0x2, IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_METHOD, &disp, &ret, NULL, NULL);
if (FAILED(hr)) continue;
if (ret.vt == VT_EMPTY)
{
/* probably, the handler has not been implemeted*/
continue;
}
hr = ret.ChangeType (VT_I4);
if (FAILED(hr))
{
/* TODO: set the error code properly... */
/* invalid value returned... */
return -1;
}
return ret.lVal;
}
return -1;
}
INT Fire_ReadSource (IBuffer* buf)
{
T* pT = static_cast<T*>(this);
int i, nconns = m_vec.GetSize();
CComVariant args[1], ret;
for (i = 0; i < nconns; i++)
{
pT->Lock();
CComPtr<IUnknown> sp = m_vec.GetAt(i);
pT->Unlock();
IDispatch* pDispatch =
reinterpret_cast<IDispatch*>(sp.p);
if (pDispatch == NULL) continue;
VariantClear (&ret);
VariantClear (&args[0]);
args[0] = (IUnknown*)buf;
DISPPARAMS disp = { args, NULL, 1, 0 };
HRESULT hr = pDispatch->Invoke (
0x3, IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_METHOD, &disp, &ret, NULL, NULL);
if (FAILED(hr))
{
continue;
}
if (ret.vt == VT_EMPTY)
{
/* probably, the handler has not been implemeted*/
continue;
}
hr = ret.ChangeType (VT_I4);
if (FAILED(hr))
{
/* TODO: set the error code properly... */
/* invalid value returned... */
return -1;
}
return ret.lVal;
}
/* no event handler attached for the source code read. */
/* TODO: set error code ... */
return -1;
}
INT Fire_WriteSource (IBuffer* buf)
{
T* pT = static_cast<T*>(this);
int i, nconns = m_vec.GetSize();
CComVariant args[1], ret;
for (i = 0; i < nconns; i++)
{
pT->Lock();
CComPtr<IUnknown> sp = m_vec.GetAt(i);
pT->Unlock();
IDispatch* pDispatch =
reinterpret_cast<IDispatch*>(sp.p);
if (pDispatch == NULL) continue;
VariantClear (&ret);
VariantClear (&args[0]);
args[0] = (IUnknown*)buf;
DISPPARAMS disp = { args, NULL, 1, 0 };
HRESULT hr = pDispatch->Invoke (
0x4, IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_METHOD, &disp, &ret, NULL, NULL);
if (FAILED(hr))
{
continue;
}
if (ret.vt == VT_EMPTY)
{
/* probably, the handler has not been implemeted*/
continue;
}
hr = ret.ChangeType (VT_I4);
if (FAILED(hr))
{
/* TODO: set the error code properly... */
/* invalid value returned... */
return -1;
}
return ret.lVal;
}
/* no event handler attached for the source code write.
* make the operation succeed by returning the reqested
* data length. */
CComBSTR bstr;
buf->get_Value (&bstr);
return bstr.Length();
}
INT Fire_OpenExtio (IAwkExtio* extio)
{
T* pT = static_cast<T*>(this);
int i, nconns = m_vec.GetSize();
CComVariant args[1], ret;
for (i = 0; i < nconns; i++)
{
pT->Lock();
CComPtr<IUnknown> sp = m_vec.GetAt(i);
pT->Unlock();
IDispatch* pDispatch =
reinterpret_cast<IDispatch*>(sp.p);
if (pDispatch == NULL) continue;
VariantClear (&ret);
VariantClear (&args[0]);
args[0] = (IUnknown*)extio;
DISPPARAMS disp = { args, NULL, 1, 0 };
HRESULT hr = pDispatch->Invoke (
0x5, IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_METHOD, &disp, &ret, NULL, NULL);
if (FAILED(hr)) continue;
if (ret.vt == VT_EMPTY)
{
/* probably, the handler has not been implemeted*/
continue;
}
hr = ret.ChangeType (VT_I4);
if (FAILED(hr))
{
/* TODO: set the error code properly... */
/* invalid value returned... */
return -1;
}
return ret.lVal;
}
return -1;
}
INT Fire_CloseExtio (IAwkExtio* extio)
{
T* pT = static_cast<T*>(this);
int i, nconns = m_vec.GetSize();
CComVariant args[1], ret;
for (i = 0; i < nconns; i++)
{
pT->Lock();
CComPtr<IUnknown> sp = m_vec.GetAt(i);
pT->Unlock();
IDispatch* pDispatch =
reinterpret_cast<IDispatch*>(sp.p);
if (pDispatch == NULL) continue;
VariantClear (&ret);
VariantClear (&args[0]);
args[0] = (IUnknown*)extio;
DISPPARAMS disp = { args, NULL, 1, 0 };
HRESULT hr = pDispatch->Invoke (
0x6, IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_METHOD, &disp, &ret, NULL, NULL);
if (FAILED(hr)) continue;
if (ret.vt == VT_EMPTY)
{
/* probably, the handler has not been implemeted*/
continue;
}
hr = ret.ChangeType (VT_I4);
if (FAILED(hr))
{
/* TODO: set the error code properly... */
/* invalid value returned... */
return -1;
}
return ret.lVal;
}
return -1;
}
INT Fire_ReadExtio (IAwkExtio* extio, IBuffer* buf)
{
T* pT = static_cast<T*>(this);
int i, nconns = m_vec.GetSize();
CComVariant args[2], ret;
for (i = 0; i < nconns; i++)
{
pT->Lock();
CComPtr<IUnknown> sp = m_vec.GetAt(i);
pT->Unlock();
IDispatch* pDispatch =
reinterpret_cast<IDispatch*>(sp.p);
if (pDispatch == NULL) continue;
VariantClear (&ret);
VariantClear (&args[0]);
VariantClear (&args[1]);
args[1] = (IUnknown*)extio;
args[0] = (IUnknown*)buf;
DISPPARAMS disp = { args, NULL, 2, 0 };
HRESULT hr = pDispatch->Invoke (
0x7, IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_METHOD, &disp, &ret, NULL, NULL);
if (FAILED(hr))
{
continue;
}
if (ret.vt == VT_EMPTY)
{
/* probably, the handler has not been implemeted*/
continue;
}
hr = ret.ChangeType (VT_I4);
if (FAILED(hr))
{
/* TODO: set the error code properly... */
/* invalid value returned... */
return -1;
}
return ret.lVal;
}
return -1;
}
INT Fire_WriteExtio (IAwkExtio* extio, IBuffer* buf)
{
T* pT = static_cast<T*>(this);
int i, nconns = m_vec.GetSize();
CComVariant args[2], ret;
for (i = 0; i < nconns; i++)
{
pT->Lock();
CComPtr<IUnknown> sp = m_vec.GetAt(i);
pT->Unlock();
IDispatch* pDispatch =
reinterpret_cast<IDispatch*>(sp.p);
if (pDispatch == NULL) continue;
VariantClear (&ret);
VariantClear (&args[0]);
VariantClear (&args[1]);
args[1] = (IUnknown*)extio;
args[0] = (IUnknown*)buf;
DISPPARAMS disp = { args, NULL, 2, 0 };
HRESULT hr = pDispatch->Invoke (
0x8, IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_METHOD, &disp, &ret, NULL, NULL);
if (FAILED(hr))
{
continue;
}
if (ret.vt == VT_EMPTY)
{
/* probably, the handler has not been implemeted*/
continue;
}
hr = ret.ChangeType (VT_I4);
if (FAILED(hr))
{
/* TODO: set the error code properly... */
/* invalid value returned... */
return -1;
}
return ret.lVal;
}
return -1;
}
INT Fire_FlushExtio (IAwkExtio* extio)
{
T* pT = static_cast<T*>(this);
int i, nconns = m_vec.GetSize();
CComVariant args[1], ret;
for (i = 0; i < nconns; i++)
{
pT->Lock();
CComPtr<IUnknown> sp = m_vec.GetAt(i);
pT->Unlock();
IDispatch* pDispatch =
reinterpret_cast<IDispatch*>(sp.p);
if (pDispatch == NULL) continue;
VariantClear (&ret);
VariantClear (&args[0]);
args[0] = (IUnknown*)extio;
DISPPARAMS disp = { args, NULL, 1, 0 };
HRESULT hr = pDispatch->Invoke (
0x9, IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_METHOD, &disp, &ret, NULL, NULL);
if (FAILED(hr)) continue;
if (ret.vt == VT_EMPTY)
{
/* probably, the handler has not been implemeted*/
continue;
}
hr = ret.ChangeType (VT_I4);
if (FAILED(hr))
{
/* TODO: set the error code properly... */
/* invalid value returned... */
return -1;
}
return ret.lVal;
}
return -1;
}
INT Fire_NextExtio (IAwkExtio* extio)
{
T* pT = static_cast<T*>(this);
int i, nconns = m_vec.GetSize();
CComVariant args[1], ret;
for (i = 0; i < nconns; i++)
{
pT->Lock();
CComPtr<IUnknown> sp = m_vec.GetAt(i);
pT->Unlock();
IDispatch* pDispatch =
reinterpret_cast<IDispatch*>(sp.p);
if (pDispatch == NULL) continue;
VariantClear (&ret);
VariantClear (&args[0]);
args[0] = (IUnknown*)extio;
DISPPARAMS disp = { args, NULL, 1, 0 };
HRESULT hr = pDispatch->Invoke (
0xA, IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_METHOD, &disp, &ret, NULL, NULL);
if (FAILED(hr)) continue;
if (ret.vt == VT_EMPTY)
{
/* probably, the handler has not been implemeted*/
continue;
}
hr = ret.ChangeType (VT_I4);
if (FAILED(hr))
{
/* TODO: set the error code properly... */
/* invalid value returned... */
return -1;
}
return ret.lVal;
}
return -1;
}
int Fire_HandleFunction (
ase_awk_run_t* run, BSTR name, SAFEARRAY* argarray, ase_awk_val_t** retv)
{
T* pT = static_cast<T*>(this);
int i, nconns = m_vec.GetSize();
CComVariant ret;
VARIANT args[2];
ase_awk_val_t* v;
VariantInit (&args[0]);
VariantInit (&args[1]);
args[1].vt = VT_BSTR;
args[1].bstrVal = name;
args[0].vt = VT_ARRAY | VT_VARIANT;
args[0].parray = argarray;
for (i = 0; i < nconns; i++)
{
pT->Lock();
CComPtr<IUnknown> sp = m_vec.GetAt(i);
pT->Unlock();
IDispatch* pDispatch =
reinterpret_cast<IDispatch*>(sp.p);
if (pDispatch == NULL) continue;
VariantClear (&ret);
DISPPARAMS disp = { args, NULL, 2, 0 };
HRESULT hr = pDispatch->Invoke (
0xB, IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_METHOD, &disp, &ret, NULL, NULL);
if (FAILED(hr)) continue;
if (ret.vt == VT_EMPTY)
{
/* probably, the handler has not been implemeted*/
continue;
}
VariantClear (&args[1]);
VariantClear (&args[0]);
if (ret.vt == VT_I1)
v = ase_awk_makeintval (run, ret.cVal);
else if (ret.vt == VT_I2)
v = ase_awk_makeintval (run, ret.iVal);
else if (ret.vt == VT_I4)
v = ase_awk_makeintval (run, ret.lVal);
else if (ret.vt == VT_I8)
v = ase_awk_makeintval (run, ret.llVal);
else if (ret.vt == VT_UI1)
v = ase_awk_makeintval (run, ret.bVal);
else if (ret.vt == VT_UI2)
v = ase_awk_makeintval (run, ret.uiVal);
else if (ret.vt == VT_UI4)
v = ase_awk_makeintval (run, ret.ulVal);
else if (ret.vt == VT_UI8)
v = ase_awk_makeintval (run, ret.ullVal);
else if (ret.vt == VT_INT)
v = ase_awk_makeintval (run, ret.intVal);
else if (ret.vt == VT_UINT)
v = ase_awk_makeintval (run, ret.uintVal);
else if (ret.vt == VT_BOOL)
v = ase_awk_makeintval (run, ((ret.boolVal == 0)? 0: 1));
else if (ret.vt == VT_R4)
v = ase_awk_makerealval (run, ret.fltVal);
else if (ret.vt == VT_R8)
v = ase_awk_makerealval (run, ret.dblVal);
else if (ret.vt == VT_BSTR)
v = ase_awk_makestrval (run, ret.bstrVal, SysStringLen(ret.bstrVal));
else if (ret.vt == VT_NULL)
v = ase_awk_val_nil;
else return 3; /* wrong return value */
if (v == ASE_NULL) return 1; /* out of memory */
*retv = v;
return 0; /* success */
}
VariantClear (&args[1]);
VariantClear (&args[0]);
return 2; /* no proper handler */
}
INT Fire_OnClose ()
{
T* pT = static_cast<T*>(this);
int i, nconns = m_vec.GetSize();
CComVariant ret;
for (i = 0; i < nconns; i++)
{
pT->Lock();
CComPtr<IUnknown> sp = m_vec.GetAt(i);
pT->Unlock();
IDispatch* pDispatch = reinterpret_cast<IDispatch*>(sp.p);
if (pDispatch == NULL) continue;
VariantClear (&ret);
HRESULT hr = pDispatch->Invoke(
0xC, IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_METHOD, NULL, &ret, NULL, NULL);
if (FAILED(hr)) continue;
if (ret.vt == VT_EMPTY) continue;
hr = ret.ChangeType (VT_I4);
if (FAILED(hr))
{
/* TODO: set the error code properly... */
/* invalid value returned... */
return -1;
}
return ret.lVal;
}
return -1;
}
};
#endif

19
ase/com/resource.h Normal file
View File

@ -0,0 +1,19 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by asecom.rc
//
#define IDS_PROJNAME 100
#define IDR_AWK 101
#define IDR_AWKEXTIO 102
#define IDR_BUFFER 103
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 201
#define _APS_NEXT_COMMAND_VALUE 32768
#define _APS_NEXT_CONTROL_VALUE 201
#define _APS_NEXT_SYMED_VALUE 105
#endif
#endif

18
ase/com/stdafx.cpp Normal file
View File

@ -0,0 +1,18 @@
/*
* $Id: stdafx.cpp,v 1.3 2007/04/30 06:04:43 bacon Exp $
*
* {License}
*/
// stdafx.cpp : source file that includes just the standard includes
// stdafx.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
#ifdef _ATL_STATIC_REGISTRY
#include <statreg.h>
#include <statreg.cpp>
#endif
#include <atlimpl.cpp>

29
ase/com/stdafx.h Normal file
View File

@ -0,0 +1,29 @@
/*
* $Id: stdafx.h,v 1.3 2007/04/30 06:04:43 bacon Exp $
*
* {License}
*/
#ifndef _ASE_COM_STDAFX_H_
#define _ASE_COM_STDAFX_H_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define STRICT
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0400
#endif
#define _ATL_APARTMENT_THREADED
#include <atlbase.h>
//You may derive a class from CComModule and use it if you want to override
//something, but do not change the name of _Module
extern CComModule _Module;
#include <atlcom.h>
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif

1411
ase/config/config.guess vendored Executable file

File diff suppressed because it is too large Load Diff

1500
ase/config/config.sub vendored Executable file

File diff suppressed because it is too large Load Diff

316
ase/config/install-sh Executable file
View File

@ -0,0 +1,316 @@
#!/bin/sh
# install - install a program, script, or datafile
scriptversion=2004-02-15.20
# This originates from X11R5 (mit/util/scripts/install.sh), which was
# later released in X11R6 (xc/config/util/install.sh) with the
# following copyright and license.
#
# Copyright (C) 1994 X Consortium
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# Except as contained in this notice, the name of the X Consortium shall not
# be used in advertising or otherwise to promote the sale, use or other deal-
# ings in this Software without prior written authorization from the X Consor-
# tium.
#
#
# FSF changes to this file are in the public domain.
#
# Calling this script install-sh is preferred over install.sh, to prevent
# `make' implicit rules from creating a file called install from it
# when there is no Makefile.
#
# This script is compatible with the BSD install script, but was written
# from scratch. It can only install one file at a time, a restriction
# shared with many OS's install programs.
# set DOITPROG to echo to test this script
# Don't use :- since 4.3BSD and earlier shells don't like it.
doit="${DOITPROG-}"
# put in absolute paths if you don't have them in your path; or use env. vars.
mvprog="${MVPROG-mv}"
cpprog="${CPPROG-cp}"
chmodprog="${CHMODPROG-chmod}"
chownprog="${CHOWNPROG-chown}"
chgrpprog="${CHGRPPROG-chgrp}"
stripprog="${STRIPPROG-strip}"
rmprog="${RMPROG-rm}"
mkdirprog="${MKDIRPROG-mkdir}"
transformbasename=
transform_arg=
instcmd="$mvprog"
chmodcmd="$chmodprog 0755"
chowncmd=
chgrpcmd=
stripcmd=
rmcmd="$rmprog -f"
mvcmd="$mvprog"
src=
dst=
dir_arg=
usage="Usage: $0 [OPTION]... SRCFILE DSTFILE
or: $0 [OPTION]... SRCFILES... DIRECTORY
or: $0 -d DIRECTORIES...
In the first form, install SRCFILE to DSTFILE, removing SRCFILE by default.
In the second, create the directory path DIR.
Options:
-b=TRANSFORMBASENAME
-c copy source (using $cpprog) instead of moving (using $mvprog).
-d create directories instead of installing files.
-g GROUP $chgrp installed files to GROUP.
-m MODE $chmod installed files to MODE.
-o USER $chown installed files to USER.
-s strip installed files (using $stripprog).
-t=TRANSFORM
--help display this help and exit.
--version display version info and exit.
Environment variables override the default commands:
CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG
"
while test -n "$1"; do
case $1 in
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
shift
continue;;
-c) instcmd=$cpprog
shift
continue;;
-d) dir_arg=true
shift
continue;;
-g) chgrpcmd="$chgrpprog $2"
shift
shift
continue;;
--help) echo "$usage"; exit 0;;
-m) chmodcmd="$chmodprog $2"
shift
shift
continue;;
-o) chowncmd="$chownprog $2"
shift
shift
continue;;
-s) stripcmd=$stripprog
shift
continue;;
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
shift
continue;;
--version) echo "$0 $scriptversion"; exit 0;;
*) # When -d is used, all remaining arguments are directories to create.
test -n "$dir_arg" && break
# Otherwise, the last argument is the destination. Remove it from $@.
for arg
do
if test -n "$dstarg"; then
# $@ is not empty: it contains at least $arg.
set fnord "$@" "$dstarg"
shift # fnord
fi
shift # arg
dstarg=$arg
done
break;;
esac
done
if test -z "$1"; then
if test -z "$dir_arg"; then
echo "$0: no input file specified." >&2
exit 1
fi
# It's OK to call `install-sh -d' without argument.
# This can happen when creating conditional directories.
exit 0
fi
for src
do
# Protect names starting with `-'.
case $src in
-*) src=./$src ;;
esac
if test -n "$dir_arg"; then
dst=$src
src=
if test -d "$dst"; then
instcmd=:
chmodcmd=
else
instcmd=$mkdirprog
fi
else
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
# might cause directories to be created, which would be especially bad
# if $src (and thus $dsttmp) contains '*'.
if test ! -f "$src" && test ! -d "$src"; then
echo "$0: $src does not exist." >&2
exit 1
fi
if test -z "$dstarg"; then
echo "$0: no destination specified." >&2
exit 1
fi
dst=$dstarg
# Protect names starting with `-'.
case $dst in
-*) dst=./$dst ;;
esac
# If destination is a directory, append the input filename; won't work
# if double slashes aren't ignored.
if test -d "$dst"; then
dst=$dst/`basename "$src"`
fi
fi
# This sed command emulates the dirname command.
dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
# Make sure that the destination directory exists.
# Skip lots of stat calls in the usual case.
if test ! -d "$dstdir"; then
defaultIFS='
'
IFS="${IFS-$defaultIFS}"
oIFS=$IFS
# Some sh's can't handle IFS=/ for some reason.
IFS='%'
set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
IFS=$oIFS
pathcomp=
while test $# -ne 0 ; do
pathcomp=$pathcomp$1
shift
if test ! -d "$pathcomp"; then
$mkdirprog "$pathcomp" || lasterr=$?
# mkdir can fail with a `File exist' error in case several
# install-sh are creating the directory concurrently. This
# is OK.
test ! -d "$pathcomp" && { (exit ${lasterr-1}); exit; }
fi
pathcomp=$pathcomp/
done
fi
if test -n "$dir_arg"; then
$doit $instcmd "$dst" \
&& { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \
&& { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \
&& { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \
&& { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; }
else
# If we're going to rename the final executable, determine the name now.
if test -z "$transformarg"; then
dstfile=`basename "$dst"`
else
dstfile=`basename "$dst" $transformbasename \
| sed $transformarg`$transformbasename
fi
# don't allow the sed command to completely eliminate the filename.
test -z "$dstfile" && dstfile=`basename "$dst"`
# Make a couple of temp file names in the proper directory.
dsttmp=$dstdir/_inst.$$_
rmtmp=$dstdir/_rm.$$_
# Trap to clean up those temp files at exit.
trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
trap '(exit $?); exit' 1 2 13 15
# Move or copy the file name to the temp name
$doit $instcmd "$src" "$dsttmp" &&
# and set any options; do chmod last to preserve setuid bits.
#
# If any of these fail, we abort the whole thing. If we want to
# ignore errors from any of these, just make sure not to ignore
# errors from the above "$doit $instcmd $src $dsttmp" command.
#
{ test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
&& { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
&& { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \
&& { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } &&
# Now remove or move aside any old file at destination location. We
# try this two ways since rm can't unlink itself on some systems and
# the destination file might be busy for other reasons. In this case,
# the final cleanup might fail but the new file should still install
# successfully.
{
if test -f "$dstdir/$dstfile"; then
$doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \
|| $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \
|| {
echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
(exit 1); exit
}
else
:
fi
} &&
# Now rename the file to the real destination.
$doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
fi || { (exit 1); exit; }
done
# The final little trick to "correctly" pass the exit status to the exit trap.
{
(exit 0); exit
}
# Local variables:
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-end: "$"
# End:

6425
ase/config/ltmain.sh Normal file

File diff suppressed because it is too large Load Diff

27053
ase/configure vendored Executable file

File diff suppressed because it is too large Load Diff

198
ase/configure.ac Normal file
View File

@ -0,0 +1,198 @@
#
# $Id: configure.ac,v 1.3 2007/04/30 05:51:26 bacon Exp $
#
AC_PREREQ(2.53)
AC_INIT([ase], [deb-0.1.0])
AC_REVISION([$Revision: 1.3 $])
AC_CONFIG_HEADER([cmn/conf_unx.h])
AC_CONFIG_AUX_DIR(config)
# Checks for programs.
AC_PROG_CC
#AC_PROG_RANLIB
AC_PROG_LIBTOOL
AC_SUBST(LIBTOOL_DEPS)
# Overrides the default CFLAGS setting
if test "$ac_test_CFLAGS" = "set"
then
CFLAGS=$ac_save_CFLAGS
else
if test "$GCC" = "yes"
then
CFLAGS="-O2"
else
CFLAGS=
fi
fi
if test "$ac_test_CXXFLAGS" = "set"
then
CXXFLAGS=$ac_save_CXXFLAGS
else
if test "$GCC" = "yes"
then
CXXFLAGS="-O2"
else
CXXFLAGS=
fi
fi
# Checks for header files.
AC_HEADER_STDC
# Checks for typedefs, structures, and compiler characteristics.
AC_C_BIGENDIAN(
[AC_DEFINE([ASE_ENDIAN_BIG],[],[Big Endian])],
[AC_DEFINE([ASE_ENDIAN_LITTLE],[],[Little Endian])],
[AC_DEFINE([ASE_ENDIAN_UNKNOWN],[],[Unknown Endian])])
# Checks for data types
AC_CHECK_TYPE(long long, [AC_DEFINE([ASE_HAVE_LONG_LONG],[],[long long])])
AC_CHECK_TYPE(long double, [AC_DEFINE([ASE_HAVE_LONG_DOUBLE],[],[long double])])
AC_CHECK_SIZEOF(char)
AC_CHECK_SIZEOF(short)
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long)
AC_CHECK_SIZEOF(long long)
AC_CHECK_SIZEOF(__int8)
AC_CHECK_SIZEOF(__int16)
AC_CHECK_SIZEOF(__int32)
AC_CHECK_SIZEOF(__int64)
AC_CHECK_SIZEOF(__int96)
AC_CHECK_SIZEOF(__int128)
AC_CHECK_SIZEOF(void *)
AC_CHECK_SIZEOF(float)
AC_CHECK_SIZEOF(double)
AC_CHECK_SIZEOF(long double)
AC_CHECK_SIZEOF(wchar_t)
AC_DEFINE_UNQUOTED(ASE_SIZEOF_CHAR,${ac_cv_sizeof_char})
AC_DEFINE_UNQUOTED(ASE_SIZEOF_SHORT,${ac_cv_sizeof_short})
AC_DEFINE_UNQUOTED(ASE_SIZEOF_INT,${ac_cv_sizeof_int})
AC_DEFINE_UNQUOTED(ASE_SIZEOF_LONG,${ac_cv_sizeof_long})
AC_DEFINE_UNQUOTED(ASE_SIZEOF_LONG_LONG,${ac_cv_sizeof_long_long})
AC_DEFINE_UNQUOTED(ASE_SIZEOF___INT8,${ac_cv_sizeof___int8})
AC_DEFINE_UNQUOTED(ASE_SIZEOF___INT16,${ac_cv_sizeof___int16})
AC_DEFINE_UNQUOTED(ASE_SIZEOF___INT32,${ac_cv_sizeof___int32})
AC_DEFINE_UNQUOTED(ASE_SIZEOF___INT64,${ac_cv_sizeof___int64})
AC_DEFINE_UNQUOTED(ASE_SIZEOF___INT96,${ac_cv_sizeof___int96})
AC_DEFINE_UNQUOTED(ASE_SIZEOF___INT128,${ac_cv_sizeof___int128})
AC_DEFINE_UNQUOTED(ASE_SIZEOF_VOID_P,${ac_cv_sizeof_void_p})
AC_DEFINE_UNQUOTED(ASE_SIZEOF_FLOAT,${ac_cv_sizeof_float})
AC_DEFINE_UNQUOTED(ASE_SIZEOF_DOUBLE,${ac_cv_sizeof_double})
AC_DEFINE_UNQUOTED(ASE_SIZEOF_LONG_DOUBLE,${ac_cv_sizeof_long_double})
AC_DEFINE_UNQUOTED(ASE_SIZEOF_WCHAR_T,${ac_cv_sizeof_wchar_t})
# Defines extra options
AC_ARG_ENABLE([wchar], [AC_HELP_STRING([--enable-wchar],
[use wchar_t a default charater type when enabled (default. yes)])],
enable_wchar_is=$enableval,enable_wchar_is=yes)
if test "$enable_wchar_is" = "yes"
then
AC_DEFINE([ASE_CHAR_IS_WCHAR],[],[char is wchar])
else
AC_DEFINE([ASE_CHAR_IS_MCHAR],[],[char is mchar])
fi
AC_ARG_ENABLE([mode], [AC_HELP_STRING([--enable-debug],
[build the library in the debug mode (default. no)])],
enable_debug_is=$enableval,enable_debug_is=no)
if test "$enable_debug_is" = "yes"
then
[CFLAGS="$CFLAGS -g -D_DEBUG -UNDEBUG"]
[CXXFLAGS="$CXXFLAGS -g -D_DEBUG -UNDEBUG"]
AC_SUBST(BUILDMODE, "debug")
else
[CFLAGS="$CFLAGS -DNDEBUG -U_DEBUG"]
[CXXFLAGS="$CXXFLAGS -DNDEBUG -U_DEBUG"]
AC_SUBST(BUILDMODE, "release")
fi
# Configure makefiles
AC_ARG_ENABLE([reentrant], [AC_HELP_STRING([--enable-reentrant],
[define _REENTRANT (default. yes)])],
enable_reentrant_is=$enableval,enable_reentrant_is=yes)
if test "$enable_reentrant_is" = "yes"
then
[CFLAGS="$CFLAGS -D_REENTRANT -D_THREAD_SAFE"]
[CXXFLAGS="$CXXFLAGS -D_REENTRANT -D_THREAD_SAFE"]
fi
# Java & JNI Configuration
AC_PATH_PROG(JAVAC_PATH, javac, :)
AC_PATH_PROG(JAR_PATH, jar, :)
if test "$JAVAC_PATH" != ":"
then
CUR_JAVAC_PATH="$JAVAC_PATH"
while ls -ld "$CUR_JAVAC_PATH" 2>/dev/null | grep " -> " >/dev/null
do
AC_MSG_CHECKING(symlink for $CUR_JAVAC_PATH)
REAL_JAVAC_PATH=`ls -ld "$CUR_JAVAC_PATH" | sed 's/.* -> //'`
case "$REAL_JAVAC_PATH" in
/*) CUR_JAVAC_PATH="$REAL_JAVAC_PATH";;
*) CUR_JAVAC_PATH=`echo "X$CUR_JAVAC_PATH" | sed -e 's/^X//' -e 's:[[^/]]*$::'`"$REAL_JAVAC_PATH";;
esac
AC_MSG_RESULT($CUR_JAVAC_PATH)
done
JAVA_DIR="$CUR_JAVAC_PATH"
while true
do
JAVA_DIR=`echo "$JAVA_DIR" | sed -e 's://*:/:g' -e 's:/[[^/]]*$::'`
if test "$JAVA_DIR" = ""
then
break
fi
AC_MSG_CHECKING($JAVA_DIR/include/jni.h)
if test -f "$JAVA_DIR/include/jni.h"
then
AC_MSG_RESULT(yes)
JNI_INCLUDE_DIRS="$JNI_INCLUDE_DIRS $JAVA_DIR/include"
break;
else
AC_MSG_RESULT(no)
fi
done
for i in $JNI_INCLUDE_DIRS
do
JNI_MD_H=`find "$i" -name jni_md.h -print`
if test "$JNI_MD_H" != ""
then
tmp=`echo "$JNI_MD_H" | sed -e 's://*:/:g' -e 's:/[[^/]]*$::'`
JNI_MD_INCLUDE_DIRS="$JNI_MD_INCLUDE_DIRS $tmp"
fi
done
JNI_INCLUDE_DIRS="$JNI_INCLUDE_DIRS $JNI_MD_INCLUDE_DIRS"
for i in $JNI_INCLUDE_DIRS
do
CFLAGS_JNI="$CFLAGS_JNI -I$i"
done
JNI="jni"
else
JAVAC_PATH=""
CFLAGS_JNI=""
JNI=""
fi
AC_SUBST(CFLAGS_JNI, $CFLAGS_JNI)
AC_SUBST(JAVAC, $JAVAC_PATH)
AC_SUBST(JAR, $JAR_PATH)
AC_SUBST(JNI, $JNI)
AC_CONFIG_FILES([makefile cmn/makefile awk/makefile lsp/makefile utl/makefile test/awk/makefile test/lsp/makefile])
AC_OUTPUT

30
ase/doc/ase-en.man Normal file
View File

@ -0,0 +1,30 @@
.title ASE
= ASE =
ASE is a programming library implementing various programming languages and text utilities for embedding purposes. The library is developed in the C programming language and provides the JNI binding to JAVA and the COM interface.
(Warning: This page is only for the test purpose prior to proper release and the contents can be changed anytime without prior notice.)
== Download ==
Download the library source code from the following links.
ase-0.1.0.tgz
[[[
* {Link 1,ase-0.1.0.tgz}
* Link 2
]]]
== Documentation ==
[[[
* {Quickstart,quickstart-en.html}
* {AWK Embedder's guide,awk-en.html}
* {LISP Embedder's guide,lsp-en.html}
* {Frequently Asked Questions,faq-en.html}
]]]
== Licensing ==
ASE is distributed under a {BSD license,license.html} and is free for all uses.

29
ase/doc/ase-ko.man Normal file
View File

@ -0,0 +1,29 @@
.title ASE
= ASE =
ASE는 임베딩을 목적으로 여러가지 프로그래밍언어를 구현하는 라이브러리이다. C언어로 개발되며 자바 JNI인터페이스와 COM인터페이스를 제공한다.
(경고: 본 페이지는 정식 배포전에 시험용으로 제작된것이므로, 언제든지 내용이 변경될 수 있다.)
== Download ==
다음 링크에서 소스코드를 받을수 있다.
ase-0.1.0.tgz
[[[
* {링크 1,ase-0.1.0.tgz}
* 링크 2
]]]
== Documentation ==
[[[
* {초간단가이드,quickstart-ko.html}
* {사용자가이드,awk-en.html}
* {자주받는질문,faq-ko.html}
]]]
== Licensing ==
ASE는 {BSD 라이센스,license.html}하에 무료로 배포된다. 단 {라이센스,license.html}는 번역상에 발생할수 있는 문제를 최소화하기 위해 영문으로만 제공된다.

202
ase/doc/awk-en.man Normal file
View File

@ -0,0 +1,202 @@
.title ASEAWK
= ASEAWK =
ASE provides an embeddable processor of a dialect of the AWK programming language. The language implemented is slightly different from {the version developed by Brian W. Kernighan, http://cm.bell-labs.com/cm/cs/awkbook/index.html} and has been adjusted to the author's preference.
== Overview ==
The following code fragment illustrates the basic steps of embedding the processor.
{{{
1) #include <ase/awk/awk.h>
2) ase_awk_t* awk;
3) awk = ase_awk_open (...);
4) if (ase_awk_parse (awk, ...) == -1)
{
/* parse error */
}
else
{
5) if (ase_awk_run (awk, ...) == -1)
{
/* run-time error */
}
}
6) ase_awk_close (awk);
}}}
(((
* Most of the functions and data types needed are defined in the header file [[ase/awk/awk.h]].
* [[ase_awk_t]] represents the processor. However, the internal representation is not exposed.
* [[ase_awk_open]] creates the processor instance.
* [[ase_awk_parse]] parses an AWK script.
* [[ase_awk_run]] executes the script parsed.
* [[ase_awk_close]] destroys the processor instance.
)))
More detailed description is available {here,awk-mini-en.html}. You may refer to other sample files such as [[ase/test/awk/awk.c]] and [[ase/awk/jni.c]].
== Primitive Functions ==
A set of primitive functions is needed to create an instance of the AWK processor. A primitive function is a user-defined function to help the library perform system-dependent operations such as memory allocation, character class handling.
{{{
typedef struct ase_awk_prmfns_t ase_awk_prmfns_t;
struct ase_awk_prmfns_t
{
ase_mmgr_t mmgr;
ase_ccls_t ccls;
struct
{
ase_awk_pow_t pow;
ase_awk_sprintf_t sprintf;
ase_awk_dprintf_t dprintf;
void* custom_data;
} misc;
};
}}}
A caller of [[ase_awk_open]] should fill in most of the fields of a [[ase_awk_prmfns_t]] structure and pass the structure to it. The function pointers in the miscellaneous group labeled [misc] is defined as follows:
{{{
/* returns the value of x raised to the power of y */
typedef ase_real_t (*ase_awk_pow_t) (void* custom, ase_real_t x, ase_real_t y);
/* similar to snprintf of the standard C library. */
typedef int (*ase_awk_sprintf_t) (void* custom, ase_char_t* buf, ase_size_t size, const ase_char_t* fmt, ...);
/* similar to printf of the standard C library. called by a few uncommonly
* used output functions usually for debugging purpose */
typedef void (*ase_awk_dprintf_t) (void* custom, const ase_char_t* fmt, ...);
}}}
The fourth field of the group is passed to its member functions as the first argument on invocation. The function pointed by the [[sprintf]] field should ensure that the resuliting string is null-terminated and [[%s]] and [[%c]] are accepted for the [[ase_char_t*]] and [[ase_char_t]] type respectively regardless the character mode.
The memory manager group labeled [mmgr] and the character class group labled [ccls] are defined as follows:
{{{
typedef void* (*ase_malloc_t) (void* custom, ase_size_t n);
typedef void* (*ase_realloc_t) (void* custom, void* ptr, ase_size_t n);
typedef void (*ase_free_t) (void* custom, void* ptr);
typedef ase_bool_t (*ase_isccls_t) (void* custom, ase_cint_t c);
typedef ase_cint_t (*ase_toccls_t) (void* custom, ase_cint_t c);
struct ase_mmgr_t
{
ase_malloc_t malloc;
ase_realloc_t realloc;
ase_free_t free;
void* custom_data;
};
struct ase_ccls_t
{
ase_isccls_t is_upper;
ase_isccls_t is_lower;
ase_isccls_t is_alpha;
ase_isccls_t is_digit;
ase_isccls_t is_xdigit;
ase_isccls_t is_alnum;
ase_isccls_t is_space;
ase_isccls_t is_print;
ase_isccls_t is_graph;
ase_isccls_t is_cntrl;
ase_isccls_t is_punct;
ase_toccls_t to_upper;
ase_toccls_t to_lower;
void* custom_data;
};
}}}
The functions in these groups perform the memory operations and character class related operations respectively. They follow the style of the memory allocation functions and character class handling functions of the standard C library except that they accept a pointer to the user-defined data as the first argument, thus providing more flexibility. The pointer to the user-defined data is specified into the [[custom_data]] field of each group. The [[realloc]] field, however, can be [[ASE_NULL]], in which case the functions pointed by the free and the malloc field replace the role of the function pointed by the [[realloc]] field.
== Source IO Handler ==
The source code is handled by a source input handler provided by the user. The optional source code output handler can be provided to have the internal parse tree converted back to the source code.
The source code handler is defined as follows:
{{{
typedef ase_ssize_t (*ase_awk_io_t) (int cmd, void* custom, ase_char_t* data, ase_size_t count);
typedef struct ase_awk_srcios_t ase_awk_srcios_t;
struct ase_awk_srcios_t
{
ase_awk_io_t in; /* source input */
ase_awk_io_t out; /* source output */
void* custom_data;
};
}}}
The [[in]] field of the ase_awk_srcios_t is mandatory and should be filled in. The [[out]] field can be set to [[ASE_NULL]] or can point to a source output handling function. The [[custom_data]] field is passed to the source handlers as the second argument. The first parameter [[cmd]] of the source input handler is one of [[ASE_AWK_IO_OPEN]], [[ASE_AWK_IO_CLOSE]], [[ASE_AWK_IO_READ]]. The first parameter [[cmd]] of the source output handler is one of [[ASE_AWK_IO_OPEN]], [[ASE_AWK_IO_CLOSE]], [[ASE_AWK_IO_WRITE]]. The third parameter [[data]] and the fourth parameter [[count]] are the pointer to the buffer to read data into and its size if the first parameter [[cmd]] is [[ASE_AWK_IO_READ]] while they are the pointer to the data and its size if [[cmd]] is [[ASE_AWK_IO_WRITE]].
The source handler should return a negative value for an error and zero or a positive value otherwise. However, there is a subtle difference in the meaning of the return value depending on the value of the first parameter [[cmd]].
When [[cmd]] is [[ASE_AWK_IO_OPEN]], the return value of -1 and 1 indicates the failure and the success respectively. In addition, the return value of 0 indicates that the operation is successful but has reached the end of the stream. The library calls the handler with [[ASE_AWK_IO_CLOSE]] for deinitialization if the return value is 0 or 1. When [[cmd]] is [[ASE_AWK_IO_CLOSE]], the return value of -1 and 0 indicate the failure and the success respectively. When [[cmd]] is [[ASE_AWK_IO_READ]] or [[ASE_AWK_IO_WRITE]], the return value of -1 indicates the failure, 0 the end of the stream, and other positive values the number of characters read or written.
The typical source handler will look as follows:
{{{
ase_ssize_t awk_srcio_in (int cmd, void* arg, ase_char_t* data, ase_size_t size)
{
if (cmd == ASE_AWK_IO_OPEN)
{
/* open the stream */
return 1;
}
else if (cmd == ASE_AWK_IO_CLOSE)
{
/* close the stream */
return 0;
}
else if (cmd == ASE_AWK_IO_READ)
{
/* read the stream */
return the number of characters read;
}
return -1;
}
ase_ssize_t awk_srcio_out (int cmd, void* arg, ase_char_t* data, ase_size_t size)
{
if (cmd == ASE_AWK_IO_OPEN)
{
/* open the stream */
return 1;
}
else if (cmd == ASE_AWK_IO_CLOSE)
{
/* close the stream after flushing it */
return 0;
}
else if (cmd == ASE_AWK_IO_WRITE)
{
/* write the stream */
return the number of characters written;
}
return -1;
}
}}}
Once you have the source handler ready, you can fill in the fields of a [[ase_awk_srcios_t]] structure and pass it to the call of [[ase_awk_parse]].
{{{
ase_awk_srcios_t srcios;
srcios.in = awk_srcio_in;
srcios.out = awk_srcio_out;
srcios.custom_data = point to the extra information necessary;
if (ase_awk_parse (awk, &srcios) == -1)
{
/* handle error */
}
}}}
== External IO Handler ==
External IO handlers should be provided to support the AWK's built-in IO facilities.

458
ase/doc/awk-mini-en.man Normal file
View File

@ -0,0 +1,458 @@
.title Annotated ASEAWK Embedding Sample
= Annotated ASEAWK Embedding Sample =
This document annotates a simple embedding sample code [[ase/test/awk/mini.c]]. Locate the [[ase_main]] function to begin exploring the sample.
== mini.c ==
{{{
#include <ase/awk/awk.h>
#include <ase/cmn/str.h>
#include <ase/cmn/mem.h>
#include <ase/utl/ctype.h>
#include <ase/utl/stdio.h>
#include <ase/utl/main.h>
#include <stdarg.h>
#include <math.h>
#include <stdlib.h>
}}}
Most of the data types and functions needed to embed a AWK processor is defined in [[ase/awk/awk.h]]. Other headers files are included as this sample code uses functions from them.
{{{
struct awk_src_io
{
const ase_char_t* file;
FILE* handle;
};
static const ase_char_t* data_file = ASE_NULL;
#if defined(vms) || defined(__vms)
/* it seems that the main function should be placed in the main object file
* in OpenVMS. otherwise, the first function in the main object file seems
* to become the main function resulting in program start-up failure. */
#include <ase/utl/main.c>
#endif
#ifndef NDEBUG
void ase_assert_abort (void)
{
abort ();
}
void ase_assert_printf (const ase_char_t* fmt, ...)
{
va_list ap;
va_start (ap, fmt);
ase_vprintf (fmt, ap);
va_end (ap);
}
#endif
}}}
The library requires [[ase_assert_abort]] and [[ase_assert_printf]] to be defined to support the assertion statements [[ASE_ASSERT]] and [[ASE_ASSERTX]] defined in [[ase/cmn/macros.h]] when [[NDEBUG]] is not defined. [[ASE_ASSERT]] behaves the same as the standard [[assert]] statement while an additional textual description can be passed to [[ASE_ASSERTX]]. They are all usuable in the caller program as well.
{{{
void* awk_malloc (void* custom, ase_size_t n) { return malloc (n); }
void* awk_realloc (void* custom, void* ptr, ase_size_t n) { return realloc (ptr, n); }
void awk_free (void* custom, void* ptr) { free (ptr); }
}}}
The memory management functions are required by the library. They need to form a part of the [[ase_awk_prmfns_t]] structure and be passed to [[ase_awk_open]]. Each function looks after the counterpart in the standard C library except that the first parameter to each function is a pointer to a custom data provided by the caller.
{{{
ase_bool_t awk_isupper (void* custom, ase_cint_t c) { return ase_isupper (c); }
ase_bool_t awk_islower (void* custom, ase_cint_t c) { return ase_islower (c); }
ase_bool_t awk_isalpha (void* custom, ase_cint_t c) { return ase_isalpha (c); }
ase_bool_t awk_isdigit (void* custom, ase_cint_t c) { return ase_isdigit (c); }
ase_bool_t awk_isxdigit (void* custom, ase_cint_t c) { return ase_isxdigit (c); }
ase_bool_t awk_isalnum (void* custom, ase_cint_t c) { return ase_isalnum (c); }
ase_bool_t awk_isspace (void* custom, ase_cint_t c) { return ase_isspace (c); }
ase_bool_t awk_isprint (void* custom, ase_cint_t c) { return ase_isprint (c); }
ase_bool_t awk_isgraph (void* custom, ase_cint_t c) { return ase_isgraph (c); }
ase_bool_t awk_iscntrl (void* custom, ase_cint_t c) { return ase_iscntrl (c); }
ase_bool_t awk_ispunct (void* custom, ase_cint_t c) { return ase_ispunct (c); }
ase_cint_t awk_toupper (void* custom, ase_cint_t c) { return ase_toupper (c); }
ase_cint_t awk_tolower (void* custom, ase_cint_t c) { return ase_tolower (c); }
}}}
The character class handling functions must be provided by the caller. Like the memory management functions, they form a part of the [[ase_awk_prmfns_t]] structure and passwd to [[ase_awk_open]].
{{{
ase_real_t awk_pow (void* custom, ase_real_t x, ase_real_t y)
{
return pow (x, y);
}
int awk_sprintf (void* custom, ase_char_t* buf, ase_size_t size, const ase_char_t* fmt, ...)
{
int n;
va_list ap;
va_start (ap, fmt);
n = ase_vsprintf (buf, size, fmt, ap);
va_end (ap);
return n;
}
void awk_dprintf (void* custom, const ase_char_t* fmt, ...)
{
va_list ap;
va_start (ap, fmt);
ase_vfprintf (stderr, fmt, ap);
va_end (ap);
}
}}}
The [[awk_pow]] function returns the value of the second parameter [[x]] raised to the third parameter [[y]]. The [[awk_sprintf]] function is similar to the standard [[snprintf]] to the standard [[snprintf]]. It should make sure that the buffer [[buf]] is null-terminated if the size [[size]] is greater than 0. Refer to [[ase_sprintf]] in [[ase/utl/stdio.h]] for details. The [[awk_dprintf]] fucntion is similar to [[fprintf(stderr,...)]] is called when the text output is performed for debugging purpose.
{{{
ase_ssize_t awk_srcio_in (int cmd, void* arg, ase_char_t* data, ase_size_t size)
{
struct awk_src_io* src_io = (struct awk_src_io*)arg;
ase_cint_t c;
if (cmd == ASE_AWK_IO_OPEN)
{
if (src_io->file == ASE_NULL) return 0;
src_io->handle = ase_fopen (src_io->file, ASE_T("r"));
if (src_io->handle == NULL) return -1;
return 1;
}
else if (cmd == ASE_AWK_IO_CLOSE)
{
if (src_io->file == ASE_NULL) return 0;
fclose ((FILE*)src_io->handle);
return 0;
}
else if (cmd == ASE_AWK_IO_READ)
{
if (size <= 0) return -1;
c = ase_fgetc ((FILE*)src_io->handle);
if (c == ASE_CHAR_EOF) return 0;
*data = (ase_char_t)c;
return 1;
}
return -1;
}
}}}
The source code is read in by the source code input handler as specified in the [[in]] field of the [[ase_awk_srcios_t]] structure passed to the [[ase_awk_parse]] function. This sample, however, doesn't use the source output handler which is used to show the internal parse tree.
{{{
/* external i/o handler for pipe */
ase_ssize_t awk_extio_pipe (int cmd, void* arg, ase_char_t* data, ase_size_t size)
{
ase_awk_extio_t* epa = (ase_awk_extio_t*)arg;
switch (cmd)
{
case ASE_AWK_IO_OPEN:
{
FILE* handle;
const ase_char_t* mode;
if (epa->mode == ASE_AWK_EXTIO_PIPE_READ)
mode = ASE_T("r");
else if (epa->mode == ASE_AWK_EXTIO_PIPE_WRITE)
mode = ASE_T("w");
else return -1;
handle = ase_popen (epa->name, mode);
if (handle == NULL) return -1;
epa->handle = (void*)handle;
return 1;
}
case ASE_AWK_IO_CLOSE:
{
fclose ((FILE*)epa->handle);
epa->handle = NULL;
return 0;
}
case ASE_AWK_IO_READ:
{
if (ase_fgets (data, size, (FILE*)epa->handle) == ASE_NULL)
{
if (ferror((FILE*)epa->handle)) return -1;
return 0;
}
return ase_strlen(data);
}
case ASE_AWK_IO_WRITE:
{
#if defined(ASE_CHAR_IS_WCHAR) && defined(__linux)
/* fwprintf seems to return an error with the file
* pointer opened by popen, as of this writing.
* anyway, hopefully the following replacement
* will work all the way. */
int n = fprintf (
(FILE*)epa->handle, "%.*ls", size, data);
#else
int n = ase_fprintf (
(FILE*)epa->handle, ASE_T("%.*s"), size, data);
#endif
if (n < 0) return -1;
return size;
}
case ASE_AWK_IO_FLUSH:
{
if (epa->mode == ASE_AWK_EXTIO_PIPE_READ) return -1;
else return 0;
}
case ASE_AWK_IO_NEXT:
{
return -1;
}
}
return -1;
}
/* external i/o handler for file */
ase_ssize_t awk_extio_file (int cmd, void* arg, ase_char_t* data, ase_size_t size)
{
ase_awk_extio_t* epa = (ase_awk_extio_t*)arg;
switch (cmd)
{
case ASE_AWK_IO_OPEN:
{
FILE* handle;
const ase_char_t* mode;
if (epa->mode == ASE_AWK_EXTIO_FILE_READ)
mode = ASE_T("r");
else if (epa->mode == ASE_AWK_EXTIO_FILE_WRITE)
mode = ASE_T("w");
else if (epa->mode == ASE_AWK_EXTIO_FILE_APPEND)
mode = ASE_T("a");
else return -1;
handle = ase_fopen (epa->name, mode);
if (handle == NULL) return -1;
epa->handle = (void*)handle;
return 1;
}
case ASE_AWK_IO_CLOSE:
{
fclose ((FILE*)epa->handle);
epa->handle = NULL;
return 0;
}
case ASE_AWK_IO_READ:
{
if (ase_fgets (data, size, (FILE*)epa->handle) == ASE_NULL)
{
if (ferror((FILE*)epa->handle)) return -1;
return 0;
}
return ase_strlen(data);
}
case ASE_AWK_IO_WRITE:
{
int n = ase_fprintf (
(FILE*)epa->handle, ASE_T("%.*s"), size, data);
if (n < 0) return -1;
return size;
}
case ASE_AWK_IO_FLUSH:
{
if (fflush ((FILE*)epa->handle) == EOF) return -1;
return 0;
}
case ASE_AWK_IO_NEXT:
{
return -1;
}
}
return -1;
}
/* external i/o handler for console */
ase_ssize_t awk_extio_console (int cmd, void* arg, ase_char_t* data, ase_size_t size)
{
ase_awk_extio_t* epa = (ase_awk_extio_t*)arg;
if (cmd == ASE_AWK_IO_OPEN)
{
if (epa->mode == ASE_AWK_EXTIO_CONSOLE_READ)
{
FILE* fp = ase_fopen (data_file, ASE_T("r"));
if (fp == ASE_NULL) return -1;
if (ase_awk_setfilename (
epa->run, data_file, ase_strlen(data_file)) == -1)
{
fclose (fp);
return -1;
}
epa->handle = fp;
return 1;
}
else if (epa->mode == ASE_AWK_EXTIO_CONSOLE_WRITE)
{
epa->handle = stdout;
return 1;
}
return -1;
}
else if (cmd == ASE_AWK_IO_CLOSE)
{
fclose ((FILE*)epa->handle);
epa->handle = NULL;
return 0;
}
else if (cmd == ASE_AWK_IO_READ)
{
while (ase_fgets (data, size, (FILE*)epa->handle) == ASE_NULL)
{
if (ferror((FILE*)epa->handle)) return -1;
return 0;
}
return ase_strlen(data);
}
else if (cmd == ASE_AWK_IO_WRITE)
{
int n = ase_fprintf ((FILE*)epa->handle, ASE_T("%.*s"), size, data);
if (n < 0) return -1;
return size;
}
else if (cmd == ASE_AWK_IO_FLUSH)
{
if (fflush ((FILE*)epa->handle) == EOF) return -1;
return 0;
}
else if (cmd == ASE_AWK_IO_NEXT)
{
return -1;
}
return -1;
}
}}}
External Input-Output Handler.
{{{
int ase_main (int argc, ase_char_t* argv[])
{
ase_awk_t* awk;
ase_awk_prmfns_t prmfns;
ase_awk_srcios_t srcios;
ase_awk_runios_t runios;
struct awk_src_io src_io = { NULL, NULL };
if (argc != 3)
{
ase_printf (ASE_T("Usage: %s source-file data-file\n"), argv[0]);
return -1;
}
src_io.file = argv[1];
data_file = argv[2];
ase_memset (&prmfns, 0, ASE_SIZEOF(prmfns));
prmfns.mmgr.malloc = awk_malloc;
prmfns.mmgr.realloc = awk_realloc;
prmfns.mmgr.free = awk_free;
prmfns.mmgr.custom_data = ASE_NULL;
prmfns.ccls.is_upper = awk_isupper;
prmfns.ccls.is_lower = awk_islower;
prmfns.ccls.is_alpha = awk_isalpha;
prmfns.ccls.is_digit = awk_isdigit;
prmfns.ccls.is_xdigit = awk_isxdigit;
prmfns.ccls.is_alnum = awk_isalnum;
prmfns.ccls.is_space = awk_isspace;
prmfns.ccls.is_print = awk_isprint;
prmfns.ccls.is_graph = awk_isgraph;
prmfns.ccls.is_cntrl = awk_iscntrl;
prmfns.ccls.is_punct = awk_ispunct;
prmfns.ccls.to_upper = awk_toupper;
prmfns.ccls.to_lower = awk_tolower;
prmfns.ccls.custom_data = ASE_NULL;
prmfns.misc.pow = awk_pow;
prmfns.misc.sprintf = awk_sprintf;
prmfns.misc.dprintf = awk_dprintf;
prmfns.misc.custom_data = ASE_NULL;
if ((awk = ase_awk_open(&prmfns, ASE_NULL)) == ASE_NULL)
{
ase_printf (ASE_T("ERROR: cannot open awk\n"));
return -1;
}
ase_awk_setoption (awk,
ASE_AWK_IMPLICIT | ASE_AWK_EXPLICIT | ASE_AWK_UNIQUEFN |
ASE_AWK_IDIV | ASE_AWK_SHADING | ASE_AWK_SHIFT |
ASE_AWK_EXTIO | ASE_AWK_BLOCKLESS | ASE_AWK_STRBASEONE |
ASE_AWK_STRIPSPACES | ASE_AWK_NEXTOFILE);
srcios.in = awk_srcio_in;
srcios.out = ASE_NULL;
srcios.custom_data = &src_io;
if (ase_awk_parse (awk, &srcios) == -1)
{
ase_printf (
ASE_T("PARSE ERROR: CODE [%d] LINE [%u] %s\n"),
ase_awk_geterrnum(awk),
(unsigned int)ase_awk_geterrlin(awk),
ase_awk_geterrmsg(awk));
ase_awk_close (awk);
return -1;
}
runios.pipe = awk_extio_pipe;
runios.file = awk_extio_file;
runios.console = awk_extio_console;
runios.custom_data = ASE_NULL;
if (ase_awk_run (awk, ASE_NULL, &runios, ASE_NULL, ASE_NULL, ASE_NULL) == -1)
{
ase_printf (
ASE_T("RUN ERROR: CODE [%d] LINE [%u] %s\n"),
ase_awk_geterrnum(awk),
(unsigned int)ase_awk_geterrlin(awk),
ase_awk_geterrmsg(awk));
ase_awk_close (awk);
return -1;
}
ase_awk_close (awk);
return 0;
}
}}}
The main function.

93
ase/doc/awk.man Normal file
View File

@ -0,0 +1,93 @@
.title Introduction To ASE AWK
== OVERVIEW ==
=== What is it? ===
'''''ASE AWK''''' is an embeddable implementation of the AWK programming language. It is composed of a set of C functions to help programmers embed the AWK interpreter to their own applications easily.
=== What does it do? ===
'''''ASE AWK''''' can do most of the things that other existing AWK interpreters can do. <TODO:>
=== Differences with other implementations ===
There exist a number of AWK interpreters available. Most of Unix/Linux operating systems come with an AWK interpreter. <TODO:>
== DESCRIPTION ==
=== Interpreter ===
Multiple instances of interpreters can be created in a single application and each instance of the interpreter created maintains its own state in the data structure pointed at by its handle of the type ''ase_awk_t''.
* ase_awk_t - an abstract type to an interpreter object.
* ase_awk_open - creates an interpreter object.
* ase_awk_close - destroys the interprer object created by ase_awk_open.
{{{
ase_awk_t* ase_awk_open (void);
void ase_awk_close (ase_awk_t* awk);
}}}
The interpreter provides two distinct functionalites in large; the parser and the executor. The parser transforms the source code into the internal parse tree and the executor evaluates the parse tree and runs the code.
{{{
int ase_awk_parse (ase_awk_t* awk);
int ase_awk_run (ase_awk_t* awk, ase_awk_io_t txtio, void* txtio_arg);
}}}
=== IO Handlers ===
'''''ASE AWK''''' does not provide any built-in IO handling routines. Instead, it requires users to provide them. 4 different IO streams should be provided to take full advantage of the interpreter.
* Source code input
* Source code output
* Data input
* Data output
{{{
enum
{
XP_AWK_INPUT_OPEN = 0,
XP_AWK_INPUT_CLOSE = 1,
XP_AWK_INPUT_NEXT = 2,
XP_AWK_INPUT_DATA = 3,
XP_AWK_OUTPUT_OPEN = 4,
XP_AWK_OUTPUT_CLOSE = 5,
XP_AWK_OUTPUT_NEXT = 6,
XP_AWK_OUTPUT_DATA = 7
};
typedef ase_ssize_t (*ase_awk_io_t) (int cmd, void* arg, ase_char_t* data, ase_size_t count);
}}}
=== Miscellaneous Functions ===
'''''ASE AWK''''' provides extra utility routines as well as the interpreter. These routines used by the interpreter can be accessed from the interested applications directly without regard to the interpreter.
==== String ====
==== Conversion ====
* ase_awk_strtolong - convert a numeric string to an integer of the ase_long_t type.
* ase_awk_strtoreal - convert a numeric string to a decimal number of the ase_real_t type.
{{{
ase_long_t ase_awk_strtolong (const ase_char_t* str, int base, const ase_char_t** endptr);
ase_real_t ase_awk_strtoreal (const ase_char_t* str);
}}}
==== Regular Expression ====
The regular expression routines built into the interpreter can replace other regular expression libraries available. By utilizing this, the application can have the identical regular expression functionalities as the embedded AWK interpreter.
{{{
ase_awk_rex_t* ase_awk_rex_open (ase_awk_rex_t* rex);
void ase_awk_rex_close (ase_awk_rex_t* rex);
}}}
=== User-defined Built-in Functions ===
Custom built-in functions can be added to the interpreter. This requires the deeper look into the internals of the interpreter.
== EXAMPLE ==
{{{
#include <xp/awk/awk.h>
int ase_main ()
{
return 0;
}
}}}

11
ase/doc/diff.man Normal file
View File

@ -0,0 +1,11 @@
== Difference From The Standard AWK ==
== line terminiator ==
it doesn't accept the new line as a line terminator.
== print/printf ==
if the statement succeeds, it sets ERRNO to 0. otherwise, it sets ERRNO to -1.

86
ase/doc/doc.css Normal file
View File

@ -0,0 +1,86 @@
body
{
font-family: verdana, "times new roman", tahoma, lucida, sans-serif;
background-color: white;
color: black;
#padding: 10px 10px 10px 10px;
font-size: 90%;
padding-left: 10px;
padding-right: 10px;
line-height: 1.3;
text-align: justify;
}
#a:link { color: #F89E59;}
#a:visited { color: #F89E59;}
#a:hover { color:#000000;}
h1,h2,h3,h4,h5
{
font-family: tahoma, "times new roman", verdana;
border-bottom: 1px solid #779098;
}
h1 { font-size: 120%; }
h2 { font-size: 115%; padding-left: 5px; }
h3 { font-size: 110%; padding-left: 10px; }
h4 { font-size: 105%; padding-left: 15px; }
h5 { font-size: 100%; padding-left: 20px; }
.header
{
font-family: verdana, tahoma;
font-size: 120%;
font-weight: bold;
#padding-right: 20px;
text-decoration: none;
border-bottom: 1px solid black;
}
.footer
{
font-family: "times new roman", tahoma;
font-size: 14px;
#padding-right: 20px;
text-decoration: none;
text-align: right;
border-top: 1px solid black;
}
.contents
{
font-family: "times new roman", tahoma;
font-size: 95%;
}
.maintext
{
font-size: 90%;
#color: #555555;
color: black;
padding-left: 20px;
padding-right: 20px;
line-height: 1.3;
text-align: justify;
}
pre.code
{
font-family: "Lucida TypeWriter", monotype, lucida, fixed;
font-size: 80%;
padding: 6px 6px 6px 6px;
xbackground-color: #000000;
xcolor: #FFD700;
#border: 1px dashed #779098;
#border: 1px solid #779098;
border: none;
background-color: yellow;
}
.linenum
{
font-weight: bold;
}

51
ase/doc/embed.man Normal file
View File

@ -0,0 +1,51 @@
.title Embedding AWK
To embed the awk interpreter to an application, the developer should provide the following routines.
* System functions including memory management
* Source code I/O functions
* I/O functions to interface with the console, files, and pipes.
ase_awk_open creates an awk object and requires a pointer to a structure holding system functions. The structure is described in ase_awk_prmfns_t.
{{{
struct ase_awk_prmfns_t
{
/* memory */
void* (*malloc) (ase_size_t n, void* custom_data);
void* (*realloc) (void* ptr, ase_size_t n, void* custom_data);
void (*free) (void* ptr, void* custom_data);
/* thread lock */
ase_awk_lk_t lock;
ase_awk_lk_t unlock;
/* character class */
ase_bool_t (*is_upper) (ase_cint_t c);
ase_bool_t (*is_lower) (ase_cint_t c);
ase_bool_t (*is_alpha) (ase_cint_t c);
ase_bool_t (*is_digit) (ase_cint_t c);
ase_bool_t (*is_xdigit) (ase_cint_t c);
ase_bool_t (*is_alnum) (ase_cint_t c);
ase_bool_t (*is_space) (ase_cint_t c);
ase_bool_t (*is_print) (ase_cint_t c);
ase_bool_t (*is_graph) (ase_cint_t c);
ase_bool_t (*is_cntrl) (ase_cint_t c);
ase_bool_t (*is_punct) (ase_cint_t c);
ase_cint_t (*to_upper) (ase_cint_t c);
ase_cint_t (*to_lower) (ase_cint_t c);
/* utilities */
void* (*memcpy) (void* dst, const void* src, ase_size_t n);
void* (*memset) (void* dst, int val, ase_size_t n);
ase_real_t (*pow) (ase_real_t x, ase_real_t y);
int (*sprintf) (ase_char_t* buf, ase_size_t size, const ase_char_t* fmt, ...);
void (*aprintf) (const ase_char_t* fmt, ...); /* assertion */
void (*dprintf) (const ase_char_t* fmt, ...); /* debug */
void (*abort) (void);
void* custom_data;
};
}}}

Some files were not shown because too many files have changed in this diff Show More