ICU-4639 Initial checkin of a little sample application.

X-SVN-Rev: 19306
This commit is contained in:
Eric Mader 2006-03-01 21:56:10 +00:00
parent c22ff9d2ee
commit 76da88a1ed
6 changed files with 331 additions and 3 deletions

View File

@ -1035,7 +1035,7 @@ AC_OUTPUT([icudefs.mk \
test/letest/Makefile \
test/threadtest/Makefile \
samples/Makefile samples/date/Makefile \
samples/cal/Makefile samples/layout/Makefile \
samples/cal/Makefile samples/csdet/Makefile samples/layout/Makefile \
common/unicode/platform.h])
if test $ICU_USE_THREADS = 0; then

View File

@ -1,5 +1,5 @@
## Makefile.in for ICU samples
## Copyright (c) 1999-2005, International Business Machines Corporation and
## Copyright (c) 1999-2006, International Business Machines Corporation and
## others. All Rights Reserved.
## Install directory information
@ -20,7 +20,7 @@ include @platform_make_fragment@
CLEANFILES = *~
SUBDIRS = date cal
ALLSUBDIRS = break case datefmt msgfmt numfmt props translit ucnv udata ufortune uresb ustring citer uciter8
ALLSUBDIRS = break case csdet datefmt msgfmt numfmt props translit ucnv udata ufortune uresb ustring citer uciter8
## List of phony targets
.PHONY : all all-local all-recursive install install-local \

View File

@ -0,0 +1,93 @@
## Makefile.in for ICU - samples/csdet
## Copyright (c) 2006, International Business Machines Corporation and
## others. All Rights Reserved.
## Source directory information
srcdir = @srcdir@
top_srcdir = @top_srcdir@
top_builddir = ../..
include $(top_builddir)/icudefs.mk
## Platform-specific setup
include @platform_make_fragment@
## Build directory information
subdir = samples/csdet
## Extra files to remove for 'make clean'
CLEANFILES = *~ $(DEPS)
## Target information
TARGET = csdet
CPPFLAGS += -I$(top_builddir)/common -I$(top_srcdir)/common -I$(top_srcdir)/i18n -I$(top_srcdir)
LIBS = $(LIBICUUC) $(LIBICUI18N) @LIBS@ @LIB_M@
OBJECTS=csdet.o
DEPS = $(OBJECTS:.o=.d)
## List of phony targets
.PHONY : all all-local install install-local clean clean-local \
distclean distclean-local dist dist-local check check-local
## Clear suffix list
.SUFFIXES :
## List of standard targets
all: all-local
install: install-local
clean: clean-local
distclean : distclean-local
dist: dist-local
check: all check-local
all-local: $(TARGET)
install-local:
dist-local:
clean-local:
test -z "$(CLEANFILES)" || $(RMV) $(CLEANFILES)
$(RMV) $(OBJECTS) $(TARGET)
distclean-local: clean-local
$(RMV) Makefile
check-local: all-local
$(INVOKE) ./$(TARGET)
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
cd $(top_builddir) \
&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
# The following two rules make it possible to
# compile scrptrun.cpp from the extra/scrptrun directory.
# they were copied from the default rules in mh-linux which
# is probably OK because this sample will only run on Linux...
scrptrun.d: $(top_srcdir)/extra/scrptrun/scrptrun.cpp
$(SHELL) -ec '$(GEN_DEPS.cc) $< \
| sed '\''s%\($*\)\.o[ :]*%\1.o $@ : %g'\'' > $@; \
[ -s $@ ] || rm -f $@'
scrptrun.o: $(top_srcdir)/extra/scrptrun/scrptrun.cpp
$(COMPILE.cc) $(DYNAMICCPPFLAGS) $(DYNAMICCXXFLAGS) -o $@ $<
$(TARGET) : $(OBJECTS)
$(LINK.cc) -o $@ $^ $(LIBS)
invoke:
ICU_DATA=$${ICU_DATA:-$(top_builddir)/data/} TZ=PST8PDT $(INVOKE) $(INVOCATION)
ifeq (,$(MAKECMDGOALS))
-include $(DEPS)
else
ifneq ($(patsubst %clean,,$(MAKECMDGOALS)),)
-include $(DEPS)
endif
endif

View File

@ -0,0 +1,71 @@
/*
********************************************************************************
* Copyright (C) 2005-2006, International Business Machines
* Corporation and others. All Rights Reserved.
********************************************************************************
*/
#include "unicode/utypes.h"
#include "unicode/ucsdet.h"
#include <string.h>
#include <stdio.h>
#define BUFFER_SIZE 8192
int main(int argc, char *argv[])
{
static char buffer[BUFFER_SIZE];
int32_t arg;
if( argc <= 1 ) {
printf("Usage: %s [filename]...\n", argv[0]);
return -1;
}
for(arg = 1; arg < argc; arg += 1) {
FILE *file;
char *filename = argv[arg];
int32_t inputLength, match, matchCount = 0;
UCharsetDetector* csd;
const UCharsetMatch **csm;
UErrorCode status = U_ZERO_ERROR;
if (arg > 1) {
printf("\n");
}
file = fopen(filename, "rb");
if (file == NULL) {
printf("Cannot open file \"%s\"\n\n", filename);
continue;
}
printf("%s:\n", filename);
inputLength = (int32_t) fread(buffer, 1, BUFFER_SIZE, file);
fclose(file);
csd = ucsdet_open(&status);
ucsdet_setText(csd, buffer, inputLength, &status);
csm = ucsdet_detectAll(csd, &matchCount, &status);
for(match = 0; match < matchCount; match += 1) {
const char *name = ucsdet_getName(csm[match], &status);
const char *lang = ucsdet_getLanguage(csm[match], &status);
int32_t confidence = ucsdet_getConfidence(csm[match], &status);
if (lang == NULL || strlen(lang) == 0) {
lang = "**";
}
printf("%s (%s) %d\n", name, lang, confidence);
}
ucsdet_close(csd);
}
}

View File

@ -0,0 +1,21 @@
Microsoft Visual Studio Solution File, Format Version 8.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "csdet", "csdet.vcproj", "{683745AD-3BC2-4B89-898B-93490D7F2757}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
Debug = Debug
Release = Release
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution
{683745AD-3BC2-4B89-898B-93490D7F2757}.Debug.ActiveCfg = Debug|Win32
{683745AD-3BC2-4B89-898B-93490D7F2757}.Debug.Build.0 = Debug|Win32
{683745AD-3BC2-4B89-898B-93490D7F2757}.Release.ActiveCfg = Release|Win32
{683745AD-3BC2-4B89-898B-93490D7F2757}.Release.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,143 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="csdet"
ProjectGUID="{683745AD-3BC2-4B89-898B-93490D7F2757}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../include"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="5"
TreatWChar_tAsBuiltInType="TRUE"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="icuucd.lib icuind.lib"
OutputFile="$(OutDir)/csdet.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="../../../lib"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/csdet.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="../../../include"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="4"
TreatWChar_tAsBuiltInType="TRUE"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="icuuc.lib icuin.lib"
OutputFile="$(OutDir)/csdet.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="../../../lib"
GenerateDebugInformation="TRUE"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
<File
RelativePath=".\csdet.c">
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
</Filter>
<File
RelativePath=".\ReadMe.txt">
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>