summaryrefslogtreecommitdiff
path: root/Build/source/libs/icu-xetex/samples/strsrch
diff options
context:
space:
mode:
authorJonathan Kew <jfkthame@googlemail.com>2008-03-04 13:26:36 +0000
committerJonathan Kew <jfkthame@googlemail.com>2008-03-04 13:26:36 +0000
commit53790d2a0c50915d8cec71df3e89cd24d887b2fe (patch)
tree16f6b4df067eb3c2024e0a7735cb7ccea86b3aba /Build/source/libs/icu-xetex/samples/strsrch
parentf483a5de9331a257f597282e611ecfb63f5ab118 (diff)
update icu-xetex to 3.8.1-based code from xetex repository
git-svn-id: svn://tug.org/texlive/trunk@6842 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/libs/icu-xetex/samples/strsrch')
-rw-r--r--Build/source/libs/icu-xetex/samples/strsrch/Makefile22
-rw-r--r--Build/source/libs/icu-xetex/samples/strsrch/readme.txt55
-rw-r--r--Build/source/libs/icu-xetex/samples/strsrch/strsrch.cpp301
-rw-r--r--Build/source/libs/icu-xetex/samples/strsrch/strsrch.sln19
-rw-r--r--Build/source/libs/icu-xetex/samples/strsrch/strsrch.vcproj224
5 files changed, 621 insertions, 0 deletions
diff --git a/Build/source/libs/icu-xetex/samples/strsrch/Makefile b/Build/source/libs/icu-xetex/samples/strsrch/Makefile
new file mode 100644
index 00000000000..ffd211c061c
--- /dev/null
+++ b/Build/source/libs/icu-xetex/samples/strsrch/Makefile
@@ -0,0 +1,22 @@
+# Copyright (c) 2000-2002 IBM, Inc. and others
+# sample code makefile
+
+# Usage:
+# - configure, build, install ICU (make install)
+# - make sure "icu-config" (in the ICU installed bin directory) is on
+# the path
+# - do 'make' in this directory
+
+#### definitions
+# Name of your target
+TARGET=strsrch
+
+# All object files (C or C++)
+OBJECTS=strsrch.o
+
+#### rules
+# Load in standard makefile definitions
+include ../defs.mk
+
+# the actual rules (this is a simple sample)
+include ../rules.mk
diff --git a/Build/source/libs/icu-xetex/samples/strsrch/readme.txt b/Build/source/libs/icu-xetex/samples/strsrch/readme.txt
new file mode 100644
index 00000000000..589c7adf83b
--- /dev/null
+++ b/Build/source/libs/icu-xetex/samples/strsrch/readme.txt
@@ -0,0 +1,55 @@
+Copyright (c) 2002-2005, International Business Machines Corporation and others. All Rights Reserved.
+strsrch: a sample program which finds the occurrences of a pattern string in a source string, using user-defined collation rules.
+
+This sample demonstrates
+ Creating a user-defined string search mechanism.
+ Finding all occurrences of a pattern string in a given source string.
+
+Files:
+ strsrch.c Main source file
+ strsrch.sln Windows MSVC workspace. Double-click this to get started.
+ strsrch.vcproj Windows MSVC project file
+
+To Build strsrch on Windows
+ 1. Install and build ICU
+ 2. In MSVC, open the workspace file icu\samples\strsrch\strsrch.sln
+ 3. Choose a Debug or Release build.
+ 4. Build.
+
+To Run on Windows
+ 1. Start a command shell window
+ 2. Add ICU's bin directory to the path, e.g.
+ set PATH=c:\icu\bin;%PATH%
+ (Use the path to where ever ICU is on your system.)
+ 3. cd into the strsrch directory, e.g.
+ cd c:\icu\source\samples\strsrch\debug
+ 4. Run it
+ strsrch [options*] -source source_string -pattern pattern_string
+
+To Build on Unixes
+ 1. Build ICU. strsrch is built automatically by default unless samples are turned off.
+ Specify an ICU install directory when running configure,
+ using the --prefix option. The steps to build ICU will look something
+ like this:
+ cd <icu directory>/source
+ runConfigureICU <platform-name> --prefix <icu install directory> [other options]
+ gmake all
+
+ 2. Install ICU,
+ gmake install
+
+ To Run on Unixes
+ cd <icu directory>/source/samples/strsrch
+
+ gmake check
+ -or-
+
+ export LD_LIBRARY_PATH=<icu install directory>/lib:.:$LD_LIBRARY_PATH
+ cal
+
+
+ Note: The name of the LD_LIBRARY_PATH variable is different on some systems.
+ If in doubt, run the sample using "gmake check", and note the name of
+ the variable that is used there. LD_LIBRARY_PATH is the correct name
+ for Linux and Solaris.
+
diff --git a/Build/source/libs/icu-xetex/samples/strsrch/strsrch.cpp b/Build/source/libs/icu-xetex/samples/strsrch/strsrch.cpp
new file mode 100644
index 00000000000..5054ceebdaf
--- /dev/null
+++ b/Build/source/libs/icu-xetex/samples/strsrch/strsrch.cpp
@@ -0,0 +1,301 @@
+/********************************************************************
+ * COPYRIGHT:
+ * Copyright (C) 2002-2006 IBM, Inc. All Rights Reserved.
+ *
+ ********************************************************************/
+
+/**
+ * This program demos string collation
+ */
+
+const char gHelpString[] =
+ "usage: strsrch [options*] -source source_string -pattern pattern_string\n"
+ "-help Display this message.\n"
+ "-locale name ICU locale to use. Default is en_US\n"
+ "-rules rule Collation rules file (overrides locale)\n"
+ "-french French accent ordering\n"
+ "-norm Normalizing mode on\n"
+ "-shifted Shifted mode\n"
+ "-lower Lower case first\n"
+ "-upper Upper case first\n"
+ "-case Enable separate case level\n"
+ "-level n Sort level, 1 to 5, for Primary, Secndary, Tertiary, Quaternary, Identical\n"
+ "-source string Source string\n"
+ "-pattern string Pattern string to look for in source\n"
+ "-overlap Enable searching to be done on overlapping patterns\n"
+ "-canonical Enable searching to be done matching canonical equivalent patterns"
+ "Example strsrch -rules \\u0026b\\u003ca -source a\\u0020b\\u0020bc -pattern b\n"
+ "The format \\uXXXX is supported for the rules and comparison strings\n"
+ ;
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <unicode/utypes.h>
+#include <unicode/ucol.h>
+#include <unicode/usearch.h>
+#include <unicode/ustring.h>
+
+/**
+ * Command line option variables
+ * These global variables are set according to the options specified
+ * on the command line by the user.
+ */
+char * opt_locale = "en_US";
+char * opt_rules = 0;
+UBool opt_help = FALSE;
+UBool opt_norm = FALSE;
+UBool opt_french = FALSE;
+UBool opt_shifted = FALSE;
+UBool opt_lower = FALSE;
+UBool opt_upper = FALSE;
+UBool opt_case = FALSE;
+UBool opt_overlap = FALSE;
+UBool opt_canonical = FALSE;
+int opt_level = 0;
+char * opt_source = "International Components for Unicode";
+char * opt_pattern = "Unicode";
+UCollator * collator = 0;
+UStringSearch * search = 0;
+UChar rules[100];
+UChar source[100];
+UChar pattern[100];
+
+/**
+ * Definitions for the command line options
+ */
+struct OptSpec {
+ const char *name;
+ enum {FLAG, NUM, STRING} type;
+ void *pVar;
+};
+
+OptSpec opts[] = {
+ {"-locale", OptSpec::STRING, &opt_locale},
+ {"-rules", OptSpec::STRING, &opt_rules},
+ {"-source", OptSpec::STRING, &opt_source},
+ {"-pattern", OptSpec::STRING, &opt_pattern},
+ {"-norm", OptSpec::FLAG, &opt_norm},
+ {"-french", OptSpec::FLAG, &opt_french},
+ {"-shifted", OptSpec::FLAG, &opt_shifted},
+ {"-lower", OptSpec::FLAG, &opt_lower},
+ {"-upper", OptSpec::FLAG, &opt_upper},
+ {"-case", OptSpec::FLAG, &opt_case},
+ {"-level", OptSpec::NUM, &opt_level},
+ {"-overlap", OptSpec::FLAG, &opt_overlap},
+ {"-canonical", OptSpec::FLAG, &opt_canonical},
+ {"-help", OptSpec::FLAG, &opt_help},
+ {"-?", OptSpec::FLAG, &opt_help},
+ {0, OptSpec::FLAG, 0}
+};
+
+/**
+ * processOptions() Function to read the command line options.
+ */
+UBool processOptions(int argc, const char **argv, OptSpec opts[])
+{
+ for (int argNum = 1; argNum < argc; argNum ++) {
+ const char *pArgName = argv[argNum];
+ OptSpec *pOpt;
+ for (pOpt = opts; pOpt->name != 0; pOpt ++) {
+ if (strcmp(pOpt->name, pArgName) == 0) {
+ switch (pOpt->type) {
+ case OptSpec::FLAG:
+ *(UBool *)(pOpt->pVar) = TRUE;
+ break;
+ case OptSpec::STRING:
+ argNum ++;
+ if (argNum >= argc) {
+ fprintf(stderr, "value expected for \"%s\" option.\n",
+ pOpt->name);
+ return FALSE;
+ }
+ *(const char **)(pOpt->pVar) = argv[argNum];
+ break;
+ case OptSpec::NUM:
+ argNum ++;
+ if (argNum >= argc) {
+ fprintf(stderr, "value expected for \"%s\" option.\n",
+ pOpt->name);
+ return FALSE;
+ }
+ char *endp;
+ int i = strtol(argv[argNum], &endp, 0);
+ if (endp == argv[argNum]) {
+ fprintf(stderr,
+ "integer value expected for \"%s\" option.\n",
+ pOpt->name);
+ return FALSE;
+ }
+ *(int *)(pOpt->pVar) = i;
+ }
+ break;
+ }
+ }
+ if (pOpt->name == 0)
+ {
+ fprintf(stderr, "Unrecognized option \"%s\"\n", pArgName);
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+
+/**
+ * Creates a collator
+ */
+UBool processCollator()
+{
+ // Set up an ICU collator
+ UErrorCode status = U_ZERO_ERROR;
+
+ if (opt_rules != 0) {
+ u_unescape(opt_rules, rules, 100);
+ collator = ucol_openRules(rules, -1, UCOL_OFF, UCOL_TERTIARY,
+ NULL, &status);
+ }
+ else {
+ collator = ucol_open(opt_locale, &status);
+ }
+ if (U_FAILURE(status)) {
+ fprintf(stderr, "Collator creation failed.: %d\n", status);
+ return FALSE;
+ }
+ if (status == U_USING_DEFAULT_WARNING) {
+ fprintf(stderr, "Warning, U_USING_DEFAULT_WARNING for %s\n",
+ opt_locale);
+ }
+ if (status == U_USING_FALLBACK_WARNING) {
+ fprintf(stderr, "Warning, U_USING_FALLBACK_ERROR for %s\n",
+ opt_locale);
+ }
+ if (opt_norm) {
+ ucol_setAttribute(collator, UCOL_NORMALIZATION_MODE, UCOL_ON, &status);
+ }
+ if (opt_french) {
+ ucol_setAttribute(collator, UCOL_FRENCH_COLLATION, UCOL_ON, &status);
+ }
+ if (opt_lower) {
+ ucol_setAttribute(collator, UCOL_CASE_FIRST, UCOL_LOWER_FIRST,
+ &status);
+ }
+ if (opt_upper) {
+ ucol_setAttribute(collator, UCOL_CASE_FIRST, UCOL_UPPER_FIRST,
+ &status);
+ }
+ if (opt_case) {
+ ucol_setAttribute(collator, UCOL_CASE_LEVEL, UCOL_ON, &status);
+ }
+ if (opt_shifted) {
+ ucol_setAttribute(collator, UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED,
+ &status);
+ }
+ if (opt_level != 0) {
+ switch (opt_level) {
+ case 1:
+ ucol_setAttribute(collator, UCOL_STRENGTH, UCOL_PRIMARY, &status);
+ break;
+ case 2:
+ ucol_setAttribute(collator, UCOL_STRENGTH, UCOL_SECONDARY,
+ &status);
+ break;
+ case 3:
+ ucol_setAttribute(collator, UCOL_STRENGTH, UCOL_TERTIARY, &status);
+ break;
+ case 4:
+ ucol_setAttribute(collator, UCOL_STRENGTH, UCOL_QUATERNARY,
+ &status);
+ break;
+ case 5:
+ ucol_setAttribute(collator, UCOL_STRENGTH, UCOL_IDENTICAL,
+ &status);
+ break;
+ default:
+ fprintf(stderr, "-level param must be between 1 and 5\n");
+ return FALSE;
+ }
+ }
+ if (U_FAILURE(status)) {
+ fprintf(stderr, "Collator attribute setting failed.: %d\n", status);
+ return FALSE;
+ }
+ return TRUE;
+}
+
+/**
+ * Creates a string search
+ */
+UBool processStringSearch()
+{
+ u_unescape(opt_source, source, 100);
+ u_unescape(opt_pattern, pattern, 100);
+ UErrorCode status = U_ZERO_ERROR;
+ search = usearch_openFromCollator(pattern, -1, source, -1, collator, NULL,
+ &status);
+ if (U_FAILURE(status)) {
+ return FALSE;
+ }
+ if (opt_overlap == TRUE) {
+ usearch_setAttribute(search, USEARCH_OVERLAP, USEARCH_ON, &status);
+ }
+ if (opt_canonical == TRUE) {
+ usearch_setAttribute(search, USEARCH_CANONICAL_MATCH, USEARCH_ON,
+ &status);
+ }
+ if (U_FAILURE(status)) {
+ fprintf(stderr, "Error setting search attributes\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+UBool findPattern()
+{
+ UErrorCode status = U_ZERO_ERROR;
+ int32_t offset = usearch_next(search, &status);
+ if (offset == USEARCH_DONE) {
+ fprintf(stdout, "Pattern not found in source\n");
+ }
+ while (offset != USEARCH_DONE) {
+ fprintf(stdout, "Pattern found at offset %d size %d\n", offset,
+ usearch_getMatchedLength(search));
+ offset = usearch_next(search, &status);
+ }
+ if (U_FAILURE(status)) {
+ fprintf(stderr, "Error in searching for pattern %d\n", status);
+ return FALSE;
+ }
+ fprintf(stdout, "End of search\n");
+ return TRUE;
+}
+
+/**
+ * Main -- process command line, read in and pre-process the test file,
+ * call other functions to do the actual tests.
+ */
+int main(int argc, const char** argv)
+{
+ if (processOptions(argc, argv, opts) != TRUE || opt_help) {
+ printf(gHelpString);
+ return -1;
+ }
+
+ if (processCollator() != TRUE) {
+ fprintf(stderr, "Error creating collator\n");
+ return -1;
+ }
+
+ if (processStringSearch() != TRUE) {
+ fprintf(stderr, "Error creating string search\n");
+ return -1;
+ }
+
+ fprintf(stdout, "Finding pattern %s in source %s\n", opt_pattern,
+ opt_source);
+
+ findPattern();
+ ucol_close(collator);
+ usearch_close(search);
+ return 0;
+}
diff --git a/Build/source/libs/icu-xetex/samples/strsrch/strsrch.sln b/Build/source/libs/icu-xetex/samples/strsrch/strsrch.sln
new file mode 100644
index 00000000000..89a7bfba5eb
--- /dev/null
+++ b/Build/source/libs/icu-xetex/samples/strsrch/strsrch.sln
@@ -0,0 +1,19 @@
+Microsoft Visual Studio Solution File, Format Version 9.00
+# Visual Studio 2005
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "strsrch", "strsrch.vcproj", "{E97790D1-7ABE-4C8E-9627-251ABEAA3EEC}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Win32 = Debug|Win32
+ Release|Win32 = Release|Win32
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {E97790D1-7ABE-4C8E-9627-251ABEAA3EEC}.Debug|Win32.ActiveCfg = Debug|Win32
+ {E97790D1-7ABE-4C8E-9627-251ABEAA3EEC}.Debug|Win32.Build.0 = Debug|Win32
+ {E97790D1-7ABE-4C8E-9627-251ABEAA3EEC}.Release|Win32.ActiveCfg = Release|Win32
+ {E97790D1-7ABE-4C8E-9627-251ABEAA3EEC}.Release|Win32.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/Build/source/libs/icu-xetex/samples/strsrch/strsrch.vcproj b/Build/source/libs/icu-xetex/samples/strsrch/strsrch.vcproj
new file mode 100644
index 00000000000..4bfec78d752
--- /dev/null
+++ b/Build/source/libs/icu-xetex/samples/strsrch/strsrch.vcproj
@@ -0,0 +1,224 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="strsrch"
+ ProjectGUID="{E97790D1-7ABE-4C8E-9627-251ABEAA3EEC}"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory=".\Debug"
+ IntermediateDirectory=".\Debug"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="false"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ TypeLibraryName=".\Debug/strsrch.tlb"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\..\..\include"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CRT_SECURE_NO_DEPRECATE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ TreatWChar_tAsBuiltInType="true"
+ UsePrecompiledHeader="0"
+ PrecompiledHeaderFile=".\Debug/strsrch.pch"
+ AssemblerListingLocation=".\Debug/"
+ ObjectFile=".\Debug/"
+ ProgramDataBaseFileName=".\Debug/"
+ BrowseInformation="1"
+ WarningLevel="3"
+ SuppressStartupBanner="true"
+ DebugInformationFormat="4"
+ CompileAs="0"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="_DEBUG"
+ Culture="1033"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="icuind.lib icuucd.lib"
+ OutputFile=".\Debug/strsrch.exe"
+ LinkIncremental="2"
+ SuppressStartupBanner="true"
+ AdditionalLibraryDirectories="..\..\..\lib"
+ GenerateDebugInformation="true"
+ ProgramDatabaseFile=".\Debug/strsrch.pdb"
+ SubSystem="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory=".\Release"
+ IntermediateDirectory=".\Release"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="false"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ TypeLibraryName=".\Release/strsrch.tlb"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ InlineFunctionExpansion="1"
+ AdditionalIncludeDirectories="..\..\..\include"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CRT_SECURE_NO_DEPRECATE"
+ StringPooling="true"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ TreatWChar_tAsBuiltInType="true"
+ UsePrecompiledHeader="0"
+ PrecompiledHeaderFile=".\Release/strsrch.pch"
+ AssemblerListingLocation=".\Release/"
+ ObjectFile=".\Release/"
+ ProgramDataBaseFileName=".\Release/"
+ WarningLevel="3"
+ SuppressStartupBanner="true"
+ CompileAs="0"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="NDEBUG"
+ Culture="1033"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="icuin.lib icuuc.lib"
+ OutputFile=".\Release/strsrch.exe"
+ LinkIncremental="1"
+ SuppressStartupBanner="true"
+ AdditionalLibraryDirectories="..\..\..\lib"
+ ProgramDatabaseFile=".\Release/strsrch.pdb"
+ SubSystem="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <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=".\strsrch.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl"
+ >
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+ >
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>