init for 0.3
authorMr.LeQuocTuan <Mr.LeQuocTuan@79bd180b-0a32-48ee-ac55-ada8cae9df61>
Thu, 18 Jun 2009 05:40:20 +0000 (05:40 +0000)
committerMr.LeQuocTuan <Mr.LeQuocTuan@79bd180b-0a32-48ee-ac55-ada8cae9df61>
Thu, 18 Jun 2009 05:40:20 +0000 (05:40 +0000)
git-svn-id: svn://localhost/trunk@2 79bd180b-0a32-48ee-ac55-ada8cae9df61

67 files changed:
AUTHORS [new file with mode: 0644]
COPYING [new file with mode: 0644]
ChangeLog [new file with mode: 0644]
INSTALL [new file with mode: 0644]
Makefile.am [new file with mode: 0644]
NEWS [new file with mode: 0644]
README [new file with mode: 0644]
autogen.sh [new file with mode: 0755]
configure.ac [new file with mode: 0644]
icon/Makefile.am [new file with mode: 0644]
icon/scim-unikey-check.png [new file with mode: 0644]
icon/scim-unikey-configure.png [new file with mode: 0644]
icon/scim-unikey.png [new file with mode: 0644]
po/LINGUAS [new file with mode: 0644]
po/Makevars [new file with mode: 0644]
po/POTFILES.in [new file with mode: 0644]
po/scim-unikey.pot [new file with mode: 0644]
po/vi.po [new file with mode: 0644]
src/Makefile.am [new file with mode: 0644]
src/scim_unikey_const.h [new file with mode: 0644]
src/scim_unikey_imengine.cpp [new file with mode: 0644]
src/scim_unikey_imengine.h [new file with mode: 0644]
src/scim_unikey_setup.cpp [new file with mode: 0644]
src/scim_unikey_utils.cpp [new file with mode: 0644]
src/scim_unikey_utils.h [new file with mode: 0644]
src/scimkeyselection.h [new file with mode: 0644]
ukengine/COPYING [new file with mode: 0644]
ukengine/Makefile.am [new file with mode: 0644]
ukengine/README [new file with mode: 0644]
ukengine/byteio.cpp [new file with mode: 0644]
ukengine/byteio.h [new file with mode: 0644]
ukengine/charset.cpp [new file with mode: 0644]
ukengine/charset.h [new file with mode: 0644]
ukengine/convert.cpp [new file with mode: 0644]
ukengine/data.cpp [new file with mode: 0644]
ukengine/data.h [new file with mode: 0644]
ukengine/diff/byteio.cpp.diff [new file with mode: 0644]
ukengine/diff/charset.cpp.diff [new file with mode: 0644]
ukengine/diff/convert.cpp.diff [new file with mode: 0644]
ukengine/diff/data.cpp.diff [new file with mode: 0644]
ukengine/diff/inputproc.cpp.diff [new file with mode: 0644]
ukengine/diff/mactab.cpp.diff [new file with mode: 0644]
ukengine/diff/pattern.cpp.diff [new file with mode: 0644]
ukengine/diff/prehdr.h.diff [new file with mode: 0644]
ukengine/diff/stdafx.h.diff [new file with mode: 0644]
ukengine/diff/ukengine.cpp.diff [new file with mode: 0644]
ukengine/diff/ukengine.h.diff [new file with mode: 0644]
ukengine/diff/unikey.cpp.diff [new file with mode: 0644]
ukengine/diff/unikey.h.diff [new file with mode: 0644]
ukengine/diff/usrkeymap.cpp.diff [new file with mode: 0644]
ukengine/diff/vnconv.h.diff [new file with mode: 0644]
ukengine/error.cpp [new file with mode: 0644]
ukengine/inputproc.cpp [new file with mode: 0644]
ukengine/inputproc.h [new file with mode: 0644]
ukengine/keycons.h [new file with mode: 0644]
ukengine/mactab.cpp [new file with mode: 0644]
ukengine/mactab.h [new file with mode: 0644]
ukengine/pattern.cpp [new file with mode: 0644]
ukengine/pattern.h [new file with mode: 0644]
ukengine/ukengine.cpp [new file with mode: 0644]
ukengine/ukengine.h [new file with mode: 0644]
ukengine/unikey.cpp [new file with mode: 0644]
ukengine/unikey.h [new file with mode: 0644]
ukengine/usrkeymap.cpp [new file with mode: 0644]
ukengine/usrkeymap.h [new file with mode: 0644]
ukengine/vnconv.h [new file with mode: 0644]
ukengine/vnlexi.h [new file with mode: 0644]

diff --git a/AUTHORS b/AUTHORS
new file mode 100644 (file)
index 0000000..343f33f
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,8 @@
+Author: Le Quoc Tuan <mr.lequoctuan@gmail.com>
+
+Thanks to:
+    Pham Kim Long <unikey@gmail.com> for making ukengine
+    Le Kien Truc <afterlastangel@gmail.com> for test, some technique about gtk, ...
+    bautroibaola <bautroibaola@yahoo.com> for logo
+    Ubuntu-VN Community <http://www.ubuntu-vn.org> for support forum
+
diff --git a/COPYING b/COPYING
new file mode 100644 (file)
index 0000000..b1e3f5a
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,504 @@
+                 GNU LESSER GENERAL PUBLIC LICENSE
+                      Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL.  It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+                           Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+  This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it.  You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+  When we speak of free software, we are referring to freedom of use,
+not price.  Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+  To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights.  These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+  For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you.  You must make sure that they, too, receive or can get the source
+code.  If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it.  And you must show them these terms so they know their rights.
+
+  We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+  To protect each distributor, we want to make it very clear that
+there is no warranty for the free library.  Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+\f
+  Finally, software patents pose a constant threat to the existence of
+any free program.  We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder.  Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+  Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License.  This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License.  We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+  When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library.  The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom.  The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+  We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License.  It also provides other free software developers Less
+of an advantage over competing non-free programs.  These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries.  However, the Lesser license provides advantages in certain
+special circumstances.
+
+  For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard.  To achieve this, non-free programs must be
+allowed to use the library.  A more frequent case is that a free
+library does the same job as widely used non-free libraries.  In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+  In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software.  For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+  Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.  Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library".  The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+\f
+                 GNU LESSER GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+  A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+  The "Library", below, refers to any such software library or work
+which has been distributed under these terms.  A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language.  (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+  "Source code" for a work means the preferred form of the work for
+making modifications to it.  For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+  Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it).  Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+  
+  1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+  You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+\f
+  2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) The modified work must itself be a software library.
+
+    b) You must cause the files modified to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    c) You must cause the whole of the work to be licensed at no
+    charge to all third parties under the terms of this License.
+
+    d) If a facility in the modified Library refers to a function or a
+    table of data to be supplied by an application program that uses
+    the facility, other than as an argument passed when the facility
+    is invoked, then you must make a good faith effort to ensure that,
+    in the event an application does not supply such function or
+    table, the facility still operates, and performs whatever part of
+    its purpose remains meaningful.
+
+    (For example, a function in a library to compute square roots has
+    a purpose that is entirely well-defined independent of the
+    application.  Therefore, Subsection 2d requires that any
+    application-supplied function or table used by this function must
+    be optional: if the application does not supply it, the square
+    root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library.  To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License.  (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.)  Do not make any other change in
+these notices.
+\f
+  Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+  This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+  4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+  If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library".  Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+  However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library".  The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+  When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library.  The
+threshold for this to be true is not precisely defined by law.
+
+  If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work.  (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+  Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+\f
+  6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+  You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License.  You must supply a copy of this License.  If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License.  Also, you must do one
+of these things:
+
+    a) Accompany the work with the complete corresponding
+    machine-readable source code for the Library including whatever
+    changes were used in the work (which must be distributed under
+    Sections 1 and 2 above); and, if the work is an executable linked
+    with the Library, with the complete machine-readable "work that
+    uses the Library", as object code and/or source code, so that the
+    user can modify the Library and then relink to produce a modified
+    executable containing the modified Library.  (It is understood
+    that the user who changes the contents of definitions files in the
+    Library will not necessarily be able to recompile the application
+    to use the modified definitions.)
+
+    b) Use a suitable shared library mechanism for linking with the
+    Library.  A suitable mechanism is one that (1) uses at run time a
+    copy of the library already present on the user's computer system,
+    rather than copying library functions into the executable, and (2)
+    will operate properly with a modified version of the library, if
+    the user installs one, as long as the modified version is
+    interface-compatible with the version that the work was made with.
+
+    c) Accompany the work with a written offer, valid for at
+    least three years, to give the same user the materials
+    specified in Subsection 6a, above, for a charge no more
+    than the cost of performing this distribution.
+
+    d) If distribution of the work is made by offering access to copy
+    from a designated place, offer equivalent access to copy the above
+    specified materials from the same place.
+
+    e) Verify that the user has already received a copy of these
+    materials or that you have already sent this user a copy.
+
+  For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it.  However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+  It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system.  Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+\f
+  7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+    a) Accompany the combined library with a copy of the same work
+    based on the Library, uncombined with any other library
+    facilities.  This must be distributed under the terms of the
+    Sections above.
+
+    b) Give prominent notice with the combined library of the fact
+    that part of it is a work based on the Library, and explaining
+    where to find the accompanying uncombined form of the same work.
+
+  8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License.  Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License.  However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+  9. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Library or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+  10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+\f
+  11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded.  In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+  13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation.  If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+\f
+  14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission.  For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this.  Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+                           NO WARRANTY
+
+  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+                    END OF TERMS AND CONDITIONS
+\f
+           How to Apply These Terms to Your New Libraries
+
+  If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change.  You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+  To apply these terms, attach the following notices to the library.  It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the library's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the
+  library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+  <signature of Ty Coon>, 1 April 1990
+  Ty Coon, President of Vice
+
+That's all there is to it!
+
+
diff --git a/ChangeLog b/ChangeLog
new file mode 100644 (file)
index 0000000..634f1fd
--- /dev/null
+++ b/ChangeLog
@@ -0,0 +1,34 @@
+2009-06-xx  Le Quoc Tuan <mr.lequoctuan@gmail.com>
+
+       * Release 0.3
+       * Change how to choose input method and output charset
+       * fix preedit mode with macro
+       * fix shift+space with capslock
+
+2009-05-14  Le Quoc Tuan <mr.lequoctuan@gmail.com>
+
+       * Release 0.2.0
+
+2009-05-12  Le Quoc Tuan <mr.lequoctuan@gmail.com>
+
+       * Add switch typing mode keys (and setup that key)
+
+2009-05-07  Le Quoc Tuan <mr.lequoctuan@gmail.com>
+
+       * Many bugs fixed
+
+2009-04-28  gettextize  <bug-gnu-gettext@gnu.org>
+
+       * Makefile.am (SUBDIRS): Add po.
+       (ACLOCAL_AMFLAGS): New variable.
+       (EXTRA_DIST): Add config.rpath, m4/ChangeLog.
+       * configure.ac (AC_CONFIG_FILES): Add po/Makefile.in.
+
+2009-03-13  Le Quoc Tuan <mr.lequoctuan@gmail.com>
+
+       * Release 0.2.0~20090313
+       * Improve non-preedit type
+       * Add preedit type
+       * A SetupUI for configure Unikey and others
+       * Many bugs fixed
+
diff --git a/INSTALL b/INSTALL
new file mode 100644 (file)
index 0000000..7ddbb87
--- /dev/null
+++ b/INSTALL
@@ -0,0 +1,30 @@
+Scim-Unikey IME
+---------------
+Copyright (C) 2008-2009 Ubuntu-VN <http://www.ubuntu-vn.org>
+Author: Le Quoc Tuan <mr.lequoctuan@gmail.com>
+Home: http://scim-unikey.googlecode.com
+License: GNU LESSER GENERAL PUBLIC LICENSE v2.1
+---------------------------------------------
+Install from source:
+--------------------
+Basic step:
+       ./configure --prefix=/usr
+       make
+       make install
+----------
+On Ubuntu:
+    1. Install some package for build:
+       sudo apt-get install build-essential libscim-dev
+
+    2. Open a Terminal, change directory to parent of scim-unikey-version.tar.bz2 and type
+       tar xvjf scim-unikey-version.tar.bz2
+       ./configure --prefix=/usr
+       make
+       sudo make install
+
+       (for smaller size use: sudo make install-strip)
+
+    3*. For uninstall, type:
+       sudo make uninstall
+
+If you have difficult with compile or using, goto http://forum.ubuntu-vn.org/viewforum.php?f=85
diff --git a/Makefile.am b/Makefile.am
new file mode 100644 (file)
index 0000000..2da1d39
--- /dev/null
@@ -0,0 +1,5 @@
+SUBDIRS = po ukengine src icon
+EXTRA_DIST = config.rpath m4/ChangeLog  README
+
+
+ACLOCAL_AMFLAGS = -I m4
diff --git a/NEWS b/NEWS
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
+++ b/NEWS
@@ -0,0 +1 @@
+
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..e9221d4
--- /dev/null
+++ b/README
@@ -0,0 +1,15 @@
+Scim-Unikey IME
+---------------
+Copyright (C) 2008-2009 Ubuntu-VN <http://www.ubuntu-vn.org>
+Author: Le Quoc Tuan <mr.lequoctuan@gmail.com>
+Home: http://scim-unikey.googlecode.com
+License: GNU LESSER GENERAL PUBLIC LICENSE v2.1
+---------------------------------------------
+scim-unikey is a scim input method engine.
+It use ukengine for progress key event.
+(a mod version of ukengine)
+
+For support: goto http://forum.ubuntu-vn.org/viewforum.php?f=85
+
+Please read INSTALL for how to install
+
diff --git a/autogen.sh b/autogen.sh
new file mode 100755 (executable)
index 0000000..f50b596
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/sh
+set -e
+set -x
+
+autopoint
+libtoolize --automake --copy
+aclocal -I m4
+autoheader
+automake --add-missing --copy
+autoconf
+export CFLAGS="-g -O0"
+export CXXFLAGS="$CFLAGS"
+./configure $*
diff --git a/configure.ac b/configure.ac
new file mode 100644 (file)
index 0000000..9ff93f6
--- /dev/null
@@ -0,0 +1,112 @@
+# Process this file with autoconf to produce a configure script.
+AC_PREREQ(2.59)
+
+AC_INIT(scim-unikey, 0.3, mr.lequoctuan@gmail.com)
+
+cflags_set=${CFLAGS+set}
+cppflags_set=${CPPFLAGS+set}
+
+# Init automake stuff
+AM_INIT_AUTOMAKE([dist-bzip2])
+AM_CONFIG_HEADER([config.h])
+AC_CONFIG_SRCDIR([src/scim_unikey_imengine.h])
+AM_PROG_INSTALL_STRIP
+
+AM_GNU_GETTEXT([external])
+AM_GNU_GETTEXT_VERSION(0.17)
+
+# Init libtool
+LT_INIT([disable-static])
+AC_PROG_LIBTOOL
+
+# Checks for programs.
+AC_PROG_CXX
+AC_PROG_CC
+AC_LANG(C++)
+
+AC_C_CONST
+AC_TYPE_SIZE_T
+
+SCIM_VERSION=1.4.0
+
+UNIKEY_CURRENT=1
+UNIKEY_REVISION=0
+UNIKEY_AGE=0
+
+AC_SUBST(UNIKEY_CURRENT)
+AC_SUBST(UNIKEY_REVISION)
+AC_SUBST(UNIKEY_AGE)
+
+PKG_CHECK_MODULES(SCIM,[scim >= $SCIM_VERSION])
+AC_SUBST(SCIM_VERSION)
+
+PKG_CHECK_MODULES(SCIM_GTKUTILS,[scim-gtkutils >= $SCIM_VERSION],
+                               [SCIM_HAS_GTKUTILS=yes],
+                               [SCIM_HAS_GTKUTILS=no])
+
+if test "$SCIM_HAS_GTKUTILS" = "yes"; then
+  SCIM_BUILD_SETUP=1
+else
+  SCIM_BUILD_SETUP=0
+fi
+
+AM_CONDITIONAL(SCIM_BUILD_SETUP, [test "$SCIM_HAS_GTKUTILS" = "yes"])
+AC_SUBST(SCIM_BUILD_SETUP)
+
+
+# Checks for header files.
+AC_HEADER_STDC
+
+# Checks for library functions.
+AC_SUBST(ac_aux_dir)
+
+# libtool option to control which symbols are exported
+# right now, symbols starting with _ are not exported
+LIBTOOL_EXPORT_OPTIONS='-export-symbols-regex "^[[^_]].*"'
+AC_SUBST(LIBTOOL_EXPORT_OPTIONS)
+
+# Extra args.
+AC_ARG_ENABLE(debug,
+             [  --enable-debug     Turn on debugging],
+             [case "${enableval}" in
+              yes) debug=yes ;;
+              no)  debug=no ;;
+              *) AC_MSG_ERROR(bad value ${enableval} for --enable-debug) ;;
+                     esac],[debug=no])
+
+if test "x$debug" = "xyes"; then
+  test "$cflags_set" = set || CFLAGS="$CFLAGS -g"
+  test "$cppflags_set" = set || CPPFLAGS="$CXXFLAGS -g"
+  SCIM_DEBUG_FLAGS="-DENABLE_DEBUG=1"
+else
+  SCIM_DEBUG_FLAGS=""
+fi
+AC_SUBST(SCIM_DEBUG_FLAGS)
+
+newprefix=`$PKG_CONFIG --variable=prefix scim`
+if test "x$newprefix" != "x"; then
+  prefix=$newprefix
+fi
+
+SCIM_ICONDIR=`$PKG_CONFIG --variable=icondir scim`
+SCIM_MODULEDIR=`$PKG_CONFIG --variable=moduledir scim`
+
+if test "x$SCIM_ICONDIR" = "x"; then
+  SCIM_ICONDIR=${datadir}/scim/icons
+fi
+
+if test "x$SCIM_MODULEDIR" = "x"; then
+  SCIM_MODULEDIR=${libdir}/scim-1.0
+fi
+
+AC_SUBST(SCIM_ICONDIR)
+AC_SUBST(SCIM_MODULEDIR)
+
+AC_CONFIG_FILES([Makefile
+  src/Makefile
+  ukengine/Makefile
+  icon/Makefile
+  po/Makefile.in
+])
+AC_OUTPUT
+
diff --git a/icon/Makefile.am b/icon/Makefile.am
new file mode 100644 (file)
index 0000000..7396ab8
--- /dev/null
@@ -0,0 +1,4 @@
+icondir                        = $(SCIM_ICONDIR)
+icon_DATA              = scim-unikey.png scim-unikey-configure.png scim-unikey-check.png
+
+EXTRA_DIST             = $(icon_DATA)
diff --git a/icon/scim-unikey-check.png b/icon/scim-unikey-check.png
new file mode 100644 (file)
index 0000000..584de4a
Binary files /dev/null and b/icon/scim-unikey-check.png differ
diff --git a/icon/scim-unikey-configure.png b/icon/scim-unikey-configure.png
new file mode 100644 (file)
index 0000000..cfc03fc
Binary files /dev/null and b/icon/scim-unikey-configure.png differ
diff --git a/icon/scim-unikey.png b/icon/scim-unikey.png
new file mode 100644 (file)
index 0000000..43fa791
Binary files /dev/null and b/icon/scim-unikey.png differ
diff --git a/po/LINGUAS b/po/LINGUAS
new file mode 100644 (file)
index 0000000..7c74f87
--- /dev/null
@@ -0,0 +1 @@
+vi
diff --git a/po/Makevars b/po/Makevars
new file mode 100644 (file)
index 0000000..6442d70
--- /dev/null
@@ -0,0 +1,41 @@
+# Makefile variables for PO directory in any package using GNU gettext.
+
+# Usually the message domain is the same as the package name.
+DOMAIN = $(PACKAGE)
+
+# These two variables depend on the location of this directory.
+subdir = po
+top_builddir = ..
+
+# These options get passed to xgettext.
+XGETTEXT_OPTIONS = --keyword=_ --keyword=N_ --from-code=UTF-8
+
+# This is the copyright holder that gets inserted into the header of the
+# $(DOMAIN).pot file.  Set this to the copyright holder of the surrounding
+# package.  (Note that the msgstr strings, extracted from the package's
+# sources, belong to the copyright holder of the package.)  Translators are
+# expected to transfer the copyright for their translations to this person
+# or entity, or to disclaim their copyright.  The empty string stands for
+# the public domain; in this case the translators are expected to disclaim
+# their copyright.
+COPYRIGHT_HOLDER = Free Software Foundation, Inc.
+
+# This is the email address or URL to which the translators shall report
+# bugs in the untranslated strings:
+# - Strings which are not entire sentences, see the maintainer guidelines
+#   in the GNU gettext documentation, section 'Preparing Strings'.
+# - Strings which use unclear terms or require additional context to be
+#   understood.
+# - Strings which make invalid assumptions about notation of date, time or
+#   money.
+# - Pluralisation problems.
+# - Incorrect English spelling.
+# - Incorrect formatting.
+# It can be your email address, or a mailing list address where translators
+# can write to without being subscribed, or the URL of a web page through
+# which the translators can contact you.
+MSGID_BUGS_ADDRESS =
+
+# This is the list of locale categories, beyond LC_MESSAGES, for which the
+# message catalogs shall be used.  It is usually empty.
+EXTRA_LOCALE_CATEGORIES =
diff --git a/po/POTFILES.in b/po/POTFILES.in
new file mode 100644 (file)
index 0000000..37a7a3b
--- /dev/null
@@ -0,0 +1,4 @@
+# List of source files which contain translatable strings.
+src/scim_unikey_setup.cpp
+src/scim_unikey_imengine.cpp
+
diff --git a/po/scim-unikey.pot b/po/scim-unikey.pot
new file mode 100644 (file)
index 0000000..2bfd196
--- /dev/null
@@ -0,0 +1,173 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR Free Software Foundation, Inc.
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: scim-unikey 0.3\n"
+"Report-Msgid-Bugs-To: mr.lequoctuan@gmail.com\n"
+"POT-Creation-Date: 2009-06-18 01:45+0700\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: src/scim_unikey_setup.cpp:103
+msgid "Unikey Setup"
+msgstr ""
+
+#: src/scim_unikey_setup.cpp:143
+msgid "Unikey option"
+msgstr ""
+
+#: src/scim_unikey_setup.cpp:151 src/scim_unikey_imengine.cpp:683
+msgid "Enable spell check"
+msgstr ""
+
+#: src/scim_unikey_setup.cpp:157 src/scim_unikey_imengine.cpp:685
+msgid "If enable, you can decrease mistake when typing"
+msgstr ""
+
+#: src/scim_unikey_setup.cpp:160 src/scim_unikey_imengine.cpp:691
+msgid "Auto restore keys with invalid words"
+msgstr ""
+
+#: src/scim_unikey_setup.cpp:166 src/scim_unikey_imengine.cpp:693
+msgid ""
+"When typing a word not in Vietnamese,\n"
+"it will auto restore keystroke into orginal"
+msgstr ""
+
+#: src/scim_unikey_setup.cpp:170 src/scim_unikey_imengine.cpp:700
+msgid "Use oà, uý (instead of òa, úy)"
+msgstr ""
+
+#: src/scim_unikey_setup.cpp:176 src/scim_unikey_imengine.cpp:708
+msgid "Allow type with more freedom"
+msgstr ""
+
+#: src/scim_unikey_setup.cpp:184
+msgid "Typing mode"
+msgstr ""
+
+#: src/scim_unikey_setup.cpp:195
+msgid "Mode switch key:"
+msgstr ""
+
+#: src/scim_unikey_setup.cpp:209
+msgid "Preedit is default"
+msgstr ""
+
+#: src/scim_unikey_setup.cpp:215 src/scim_unikey_imengine.cpp:725
+msgid ""
+"This option is best for most application\n"
+"But you may don't like it because it have an underline when typing"
+msgstr ""
+
+#: src/scim_unikey_setup.cpp:225
+msgid "Macro option"
+msgstr ""
+
+#: src/scim_unikey_setup.cpp:230
+msgid "Telex option"
+msgstr ""
+
+#: src/scim_unikey_setup.cpp:238 src/scim_unikey_imengine.cpp:716
+msgid "Enable Macro"
+msgstr ""
+
+#: src/scim_unikey_setup.cpp:244
+msgid "Macro Table"
+msgstr ""
+
+#: src/scim_unikey_setup.cpp:250
+msgid "Edit the macro table for Macro function"
+msgstr ""
+
+#: src/scim_unikey_setup.cpp:258 src/scim_unikey_imengine.cpp:732
+msgid "Process W at word begin"
+msgstr ""
+
+#: src/scim_unikey_setup.cpp:264 src/scim_unikey_imengine.cpp:734
+msgid ""
+"If enable, type W at begin\n"
+"of word will change to Ư."
+msgstr ""
+
+#: src/scim_unikey_setup.cpp:268 src/scim_unikey_imengine.cpp:741
+msgid "Not use [,],{,} on Telex"
+msgstr ""
+
+#: src/scim_unikey_setup.cpp:274 src/scim_unikey_imengine.cpp:743
+msgid "Not use [,],{,} for map on Telex"
+msgstr ""
+
+#: src/scim_unikey_setup.cpp:414
+msgid "Macro table definition"
+msgstr ""
+
+#: src/scim_unikey_setup.cpp:442
+msgid "Word"
+msgstr ""
+
+#: src/scim_unikey_setup.cpp:450
+msgid "Replace with"
+msgstr ""
+
+#: src/scim_unikey_setup.cpp:457
+msgid "Delete"
+msgstr ""
+
+#: src/scim_unikey_setup.cpp:462
+msgid "Delete All"
+msgstr ""
+
+#: src/scim_unikey_setup.cpp:605
+msgid "(replace text)"
+msgstr ""
+
+#: src/scim_unikey_imengine.cpp:119
+msgid ""
+"This IME work best when environment variable are\n"
+"- GTK_IM_MODULE=scim-bridge\n"
+"- QT_IM_MODULE=xim\n"
+" If you use preedit, you don't not need that\n"
+"\n"
+"Some time, in some application, you \"must\"\n"
+"enable Preedit to type best\n"
+"\n"
+"In some application, scim can't enable,\n"
+"this is not a bug of scim-unikey.\n"
+"You can try this in terminal: app_name | scim\n"
+"\n"
+"This IME come into being not intend to\n"
+"replace scim-m17n, just a choose, I recommend\n"
+"use this combine with scim-m17n\n"
+"\n"
+"For other support goto:\n"
+"  http://forum.ubuntu-vn.org/viewforum.php?f=85"
+msgstr ""
+
+#: src/scim_unikey_imengine.cpp:643
+msgid "Choose input method"
+msgstr ""
+
+#: src/scim_unikey_imengine.cpp:660
+msgid "Choose output charset"
+msgstr ""
+
+#: src/scim_unikey_imengine.cpp:675
+msgid "Options"
+msgstr ""
+
+#: src/scim_unikey_imengine.cpp:677
+msgid "Configure Unikey here"
+msgstr ""
+
+#: src/scim_unikey_imengine.cpp:723
+msgid "Enable PreEdit"
+msgstr ""
diff --git a/po/vi.po b/po/vi.po
new file mode 100644 (file)
index 0000000..6c4de4a
--- /dev/null
+++ b/po/vi.po
@@ -0,0 +1,199 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: scim-unikey\n"
+"Report-Msgid-Bugs-To: mr.lequoctuan@gmail.com\n"
+"POT-Creation-Date: 2009-06-18 01:45+0700\n"
+"PO-Revision-Date: \n"
+"Last-Translator: Le Quoc Tuan <mr.lequoctuan@gmail.com>\n"
+"Language-Team: Le Quoc Tuan <mr.lequoctuan@gmail.com>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"X-Poedit-Language: Vietnamese\n"
+"X-Poedit-Country: VIET NAM\n"
+"X-Poedit-SourceCharset: utf-8\n"
+
+#: src/scim_unikey_setup.cpp:103
+msgid "Unikey Setup"
+msgstr "Cài đặt Unikey"
+
+#: src/scim_unikey_setup.cpp:143
+msgid "Unikey option"
+msgstr "Tùy chọn Unikey"
+
+#: src/scim_unikey_setup.cpp:151 src/scim_unikey_imengine.cpp:683
+msgid "Enable spell check"
+msgstr "Bật kiểm tra chính tả"
+
+#: src/scim_unikey_setup.cpp:157 src/scim_unikey_imengine.cpp:685
+msgid "If enable, you can decrease mistake when typing"
+msgstr "Nếu bật, bạn có thể giảm lỗi chính tả khi gõ"
+
+#: src/scim_unikey_setup.cpp:160 src/scim_unikey_imengine.cpp:691
+msgid "Auto restore keys with invalid words"
+msgstr "Tự động khôi phục phím với từ sai"
+
+#: src/scim_unikey_setup.cpp:166 src/scim_unikey_imengine.cpp:693
+msgid ""
+"When typing a word not in Vietnamese,\n"
+"it will auto restore keystroke into orginal"
+msgstr ""
+"Khi gõ một từ không phải tiếng Việt,\n"
+"nó sẽ tự động khôi phục phím gốc"
+
+#: src/scim_unikey_setup.cpp:170 src/scim_unikey_imengine.cpp:700
+msgid "Use oà, uý (instead of òa, úy)"
+msgstr "Đặt dấu oà, uý (thay vì òa, úy)"
+
+#: src/scim_unikey_setup.cpp:176 src/scim_unikey_imengine.cpp:708
+msgid "Allow type with more freedom"
+msgstr "Cho phép gõ tự do"
+
+#: src/scim_unikey_setup.cpp:184
+msgid "Typing mode"
+msgstr "Chế độ gõ"
+
+#: src/scim_unikey_setup.cpp:195
+msgid "Mode switch key:"
+msgstr "Phím chuyển chế độ"
+
+#: src/scim_unikey_setup.cpp:209
+msgid "Preedit is default"
+msgstr "Preedit là mặc định"
+
+#: src/scim_unikey_setup.cpp:215 src/scim_unikey_imengine.cpp:725
+msgid ""
+"This option is best for most application\n"
+"But you may don't like it because it have an underline when typing"
+msgstr ""
+"Tùy chọn này thì tốt cho hầu hết mọi ứng dụng\n"
+"Nhưng bạn có thể không thích nó, bởi vì nó có một đường gạch chân khi gõ"
+
+#: src/scim_unikey_setup.cpp:225
+msgid "Macro option"
+msgstr "Tùy chọn gõ tắt"
+
+#: src/scim_unikey_setup.cpp:230
+msgid "Telex option"
+msgstr "Tùy chọn cho Telex"
+
+#: src/scim_unikey_setup.cpp:238 src/scim_unikey_imengine.cpp:716
+msgid "Enable Macro"
+msgstr "Cho phép gõ tắt"
+
+#: src/scim_unikey_setup.cpp:244
+msgid "Macro Table"
+msgstr "Bảng gõ tắt"
+
+#: src/scim_unikey_setup.cpp:250
+msgid "Edit the macro table for Macro function"
+msgstr "Soạn thảo bảng gõ tắt cho chức năng gõ tắt"
+
+#: src/scim_unikey_setup.cpp:258 src/scim_unikey_imengine.cpp:732
+msgid "Process W at word begin"
+msgstr "Xử lý phím W ở đầu từ"
+
+#: src/scim_unikey_setup.cpp:264 src/scim_unikey_imengine.cpp:734
+msgid ""
+"If enable, type W at begin\n"
+"of word will change to Ư."
+msgstr ""
+"Nếu bật, gõ W ở đầu\n"
+"của từ sẽ chuyển thành Ư."
+
+#: src/scim_unikey_setup.cpp:268 src/scim_unikey_imengine.cpp:741
+msgid "Not use [,],{,} on Telex"
+msgstr "Không dùng [,],{,} khi gõ Telex"
+
+#: src/scim_unikey_setup.cpp:274 src/scim_unikey_imengine.cpp:743
+msgid "Not use [,],{,} for map on Telex"
+msgstr "Không dùng [,],{,} khi gõ Telex"
+
+#: src/scim_unikey_setup.cpp:414
+msgid "Macro table definition"
+msgstr "Định nghĩa bảng gõ tắt"
+
+#: src/scim_unikey_setup.cpp:442
+msgid "Word"
+msgstr "Từ"
+
+#: src/scim_unikey_setup.cpp:450
+msgid "Replace with"
+msgstr "Thay thế bởi"
+
+#: src/scim_unikey_setup.cpp:457
+msgid "Delete"
+msgstr "Xóa"
+
+#: src/scim_unikey_setup.cpp:462
+msgid "Delete All"
+msgstr "Xóa tất cả"
+
+#: src/scim_unikey_setup.cpp:605
+msgid "(replace text)"
+msgstr "(chuỗi thay thế)"
+
+#: src/scim_unikey_imengine.cpp:119
+msgid ""
+"This IME work best when environment variable are\n"
+"- GTK_IM_MODULE=scim-bridge\n"
+"- QT_IM_MODULE=xim\n"
+" If you use preedit, you don't not need that\n"
+"\n"
+"Some time, in some application, you \"must\"\n"
+"enable Preedit to type best\n"
+"\n"
+"In some application, scim can't enable,\n"
+"this is not a bug of scim-unikey.\n"
+"You can try this in terminal: app_name | scim\n"
+"\n"
+"This IME come into being not intend to\n"
+"replace scim-m17n, just a choose, I recommend\n"
+"use this combine with scim-m17n\n"
+"\n"
+"For other support goto:\n"
+"  http://forum.ubuntu-vn.org/viewforum.php?f=85"
+msgstr ""
+"IME này hoạt động tốt nhất khi giá trị biến mỗi trường là\n"
+"- GTK_IM_MODULE=scim-bridge\n"
+"- QT_IM_MODULE=ximNếu bạn dùng preedit, bạn không cần điều đó\n"
+"\n"
+"Thỉnh thoảng, trong một vài ứng dụng, bạn \"phải\"\n"
+"bật chức năng Preedit để gõ được tốt\n"
+"\n"
+"Trong vài ứng dụng, scim không thể bật,\n"
+"đây không phải là bug của scim-unikey.\n"
+"Bạn có thể thử chạy lệnh này trong terminal: app_name | scim\n"
+"\n"
+"IME này tồn tại không có ý định \n"
+"thay thế scim-m17n, chỉ là một lựa chọn, tôi khuyến cáo\n"
+"dùng kết hợp với scim-m17n\n"
+"\n"
+"Để nhận được sự hỗ trợ hãy ghé thăm:\n"
+"  http://forum.ubuntu-vn.org/viewforum.php?f=85"
+
+#: src/scim_unikey_imengine.cpp:643
+msgid "Choose input method"
+msgstr "Chọn kiểu gõ"
+
+#: src/scim_unikey_imengine.cpp:660
+msgid "Choose output charset"
+msgstr "Chọn bảng mã"
+
+#: src/scim_unikey_imengine.cpp:675
+msgid "Options"
+msgstr "Tùy chọn"
+
+#: src/scim_unikey_imengine.cpp:677
+msgid "Configure Unikey here"
+msgstr "Cấu hình Unikey ở đây"
+
+#: src/scim_unikey_imengine.cpp:723
+msgid "Enable PreEdit"
+msgstr "Bật PreEdit"
+
+#~ msgid "Input method"
+#~ msgstr "Kiểu gõ"
+
+#~ msgid "Charset"
+#~ msgstr "Bảng mã"
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644 (file)
index 0000000..234324d
--- /dev/null
@@ -0,0 +1,44 @@
+INCLUDES                   = -I$(top_builddir) \
+                             -I$(top_srcdir) \
+                             -I$(top_srcdir)/src \
+                             -I$(top_srcdir)/ukengine \
+                              -I$(top_srcdir)/intl \
+                              -DPACKAGE_NAME=\"@PACKAGE_NAME@\" \
+                             -DSCIM_ICONDIR=\"@SCIM_ICONDIR@\" \
+                              -DSCIM_UNIKEY_VERSION=\"@PACKAGE_VERSION@\" \
+                              -DSCIM_LOCALEDIR=\"@SCIM_LOCALEDIR@\"
+
+#IME module
+imenginedir                = @SCIM_MODULEDIR@/IMEngine
+imengine_LTLIBRARIES       = unikey.la
+unikey_la_SOURCES          = scim_unikey_imengine.cpp \
+                              scim_unikey_imengine.h \
+                              scim_unikey_const.h \
+                              scim_unikey_utils.cpp \
+                              scim_unikey_utils.h \
+                              scimkeyselection.h
+
+unikey_la_LIBADD           = $(top_builddir)/ukengine/libunikey-zmod.la
+unikey_la_CFLAGS           = @SCIM_CFLAGS@ @SCIM_DEBUG_FLAGS@
+unikey_la_CXXFLAGS         = @SCIM_CFLAGS@ @SCIM_DEBUG_FLAGS@
+unikey_la_LDFLAGS          = -avoid-version -rpath $(imenginedir) -module @LIBTOOL_EXPORT_OPTIONS@ @SCIM_LIBS@
+
+#Setup module
+if SCIM_BUILD_SETUP
+
+setupdir                    = @SCIM_MODULEDIR@/SetupUI
+setup_LTLIBRARIES           = unikey-setup.la
+unikey_setup_la_SOURCES     = scim_unikey_setup.cpp \
+                              scim_unikey_const.h
+
+unikey_setup_la_LIBADD      = $(top_builddir)/ukengine/libunikey-zmod.la
+unikey_setup_la_CFLAGS      = @SCIM_GTKUTILS_CFLAGS@ @SCIM_CFLAGS@
+unikey_setup_la_CXXFLAGS    = @SCIM_GTKUTILS_CFLAGS@ @SCIM_CFLAGS@
+unikey_setup_la_LDFLAGS     = -avoid-version -rpath $(setupdir) \
+                              -module @LIBTOOL_EXPORT_OPTIONS@ \
+                              @SCIM_GTKUTILS_LIBS@ @SCIM_LIBS@ \
+                              unikey_la-scim_unikey_utils.lo
+
+endif
+
+
diff --git a/src/scim_unikey_const.h b/src/scim_unikey_const.h
new file mode 100644 (file)
index 0000000..832cc6f
--- /dev/null
@@ -0,0 +1,47 @@
+/**
+   Scim-Unikey Input Method
+   Version: 0.2.0a
+
+   Copyright (C) 2008-2009 Ubuntu-VN <http://www.ubuntu-vn.org>
+   Author: Le Quoc Tuan <mr.lequoctuan@gmail.com>
+   Home: http://scim-unikey.googlecode.com
+   License: GNU LESSER GENERAL PUBLIC LICENSE v2.1
+*/
+
+#if !defined (__SCIM_UNIKEY_IMENGINE_CONST_H)
+#define __SCIM_UNIKEY_IMENGINE_CONST_H
+
+#define SCIM_UNIKEY_ICON_FILENAME                      "/scim-unikey.png"
+#define SCIM_UNIKEY_ICON_CONFIGURE                     "/scim-unikey-configure.png"
+#define SCIM_UNIKEY_ICON_CHECK                         "/scim-unikey-check.png"
+
+#define SCIM_IMENGINE_UNIKEY_MACROPATH                 "/.scim/scim-unikey/macro"
+
+/** define the config string off the unikey engine */
+#define SCIM_IMENGINE_UNIKEY_PREEDIT                   "/IMEngine/Unikey/preEdit"
+#define SCIM_IMENGINE_UNIKEY_PREEDIT_SWITCH_KEY                "/IMEngine/Unikey/preEditSwitchKey"
+#define SCIM_IMENGINE_UNIKEY_PROCESSWATWORDBEGIN       "/IMEngine/Unikey/processWAtBeginWord"
+#define SCIM_IMENGINE_UNIKEY_CODERTELEX                        "/IMEngine/Unikey/useCoderTelex"
+
+#define SCIM_IMENGINE_UNIKEY_FREEMARKING               "/IMEngine/Unikey/freeMarking"
+#define SCIM_IMENGINE_UNIKEY_MODERNSTYLE               "/IMEngine/Unikey/modernStyle"
+#define SCIM_IMENGINE_UNIKEY_MACROENABLED              "/IMEngine/Unikey/macroEnabled"
+#define SCIM_IMENGINE_UNIKEY_SPELLCHECKENABLED         "/IMEngine/Unikey/spellCheckEnabled"
+#define SCIM_IMENGINE_UNIKEY_AUTONONVNRESTORE          "/IMEngine/Unikey/autoNonVnRestore"
+
+#define SCIM_IMENGINE_UNIKEY_INPUTMETHOD               "/IMEngine/Unikey/InputMethod"
+#define SCIM_IMENGINE_UNIKEY_OUTPUTCHARSET             "/IMEngine/Unikey/OutputCharset"
+
+/** define the default value off the unikey engine */
+#define SCIM_IMENGINE_UNIKEY_PROCESSWATWORDBEGIN_DEF   true
+#define SCIM_IMENGINE_UNIKEY_CODERTELEX_DEF            false
+
+#define SCIM_IMENGINE_UNIKEY_PREEDIT_DEF               true
+#define SCIM_IMENGINE_UNIKEY_PREEDIT_SWITCH_KEY_DEF    "Control+Alt+backslash"
+#define SCIM_IMENGINE_UNIKEY_FREEMARKING_DEF           true
+#define SCIM_IMENGINE_UNIKEY_MODERNSTYLE_DEF           false
+#define SCIM_IMENGINE_UNIKEY_MACROENABLED_DEF          false
+#define SCIM_IMENGINE_UNIKEY_SPELLCHECKENABLED_DEF     true
+#define SCIM_IMENGINE_UNIKEY_AUTONONVNRESTORE_DEF      true
+
+#endif
diff --git a/src/scim_unikey_imengine.cpp b/src/scim_unikey_imengine.cpp
new file mode 100644 (file)
index 0000000..e8336a3
--- /dev/null
@@ -0,0 +1,914 @@
+/**
+   Scim-Unikey Input Method
+   Version: 0.2.0
+
+   Copyright (C) 2008-2009 Ubuntu-VN <http://www.ubuntu-vn.org>
+   Author: Le Quoc Tuan <mr.lequoctuan@gmail.com>
+   Home: http://scim-unikey.googlecode.com
+   License: GNU LESSER GENERAL PUBLIC LICENSE v2.1
+*/
+
+#define Uses_SCIM_IMENGINE
+#define Uses_SCIM_ICONV
+#define Uses_SCIM_CONFIG_BASE
+#define Uses_SCIM_CONFIG_PATH
+
+#include <libintl.h>
+#define _(String) dgettext(PACKAGE_NAME,String)
+
+#include <scim.h>
+#include "scim_unikey_const.h"
+#include "scim_unikey_utils.h"
+#include "scim_unikey_imengine.h"
+
+#include <string.h>
+#include "unikey.h"
+#include "vnconv.h"
+
+#define scim_module_init                            unikey_LTX_scim_module_init
+#define scim_module_exit                            unikey_LTX_scim_module_exit
+#define scim_imengine_module_init                   unikey_LTX_scim_imengine_module_init
+#define scim_imengine_module_create_factory         unikey_LTX_scim_imengine_module_create_factory
+
+static unsigned char WordBreakSyms[] =
+{
+       ',', ';', ':', '.', '\"', '\'', '!', '?', ' ',
+       '<', '>', '=', '+', '-', '*', '/', '\\',
+       '_', '~', '`', '@', '#', '$', '%', '^', '&', '(', ')', '{', '}', '[', ']',
+       '|'
+};
+
+static unsigned char WordAutoCommit[] =
+{
+       '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+       'b', 'c', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n',
+       'p', 'q', 'r', 's', 't', 'v', 'x', 'z',
+       'B', 'C', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N',
+       'P', 'Q', 'R', 'S', 'T', 'V', 'X', 'Z'
+};
+
+const String          Unikey_IMNames[]    = {"Telex", "Vni", "Viqr"};
+const UkInputMethod   Unikey_IM[]         = {UkTelex, UkVni, UkViqr};
+const unsigned int    NUM_INPUTMETHOD     = sizeof(Unikey_IMNames)/sizeof(Unikey_IMNames[0]);
+
+const String          Unikey_OCNames[]    = {"Unicode",           "TCVN3",            "VNI Win",              "VIQR"};
+const unsigned int    Unikey_OC[]         = {CONV_CHARSET_XUTF8,  CONV_CHARSET_TCVN3, CONV_CHARSET_VNIWIN,    CONV_CHARSET_VIQR};
+const unsigned int    NUM_OUTPUTCHARSET   = sizeof(Unikey_OCNames)/sizeof(Unikey_OCNames[0]);
+
+ConfigPointer   __config;
+
+using namespace scim;
+
+extern "C"
+{
+       void scim_module_init(void)
+       {
+               UnikeySetup();
+       }
+
+       void scim_module_exit(void)
+       {
+               UnikeyCleanup();
+       }
+
+       unsigned int scim_imengine_module_init(ConfigPointer &config)
+       {
+               if (config.null())
+                       return 0;
+               __config = config;
+
+               return 1;
+       }
+
+       IMEngineFactoryPointer scim_imengine_module_create_factory(unsigned int index)
+       {
+               return new UnikeyFactory();
+       }
+}
+
+UnikeyFactory::UnikeyFactory()
+{
+       set_languages("vi_VN");
+}
+UnikeyFactory::~UnikeyFactory()
+{
+}
+WideString UnikeyFactory::get_name() const
+{
+       return utf8_mbstowcs("Unikey");
+}
+String UnikeyFactory::get_uuid() const
+{
+       return String(String("16ef5139-de02-494f-8d98-ddfcd60bbae1"));
+}
+WideString UnikeyFactory::get_authors() const
+{
+       return utf8_mbstowcs("Le Quoc Tuan <mr.lequoctuan@gmail.com>");
+}
+WideString UnikeyFactory::get_credits() const
+{
+       return utf8_mbstowcs(String("Scim-Unikey Input Method\n"
+                                                               "Version: " SCIM_UNIKEY_VERSION "\n"
+                                                               "Copyright © 2008-2009 Ubuntu-VN\n"
+                                                               "http://www.ubuntu-vn.org\n\n"
+                                                               "Thanks to Pham Kim Long for ukengine")
+               );
+}
+WideString UnikeyFactory::get_help() const
+{
+       return utf8_mbstowcs(_("This IME work best when environment variable are\n"
+                                                  "- GTK_IM_MODULE=scim-bridge\n"
+                                                  "- QT_IM_MODULE=xim\n"
+                                                  " If you use preedit, you don't not need that\n\n"
+                                                  
+                                                  "Some time, in some application, you \"must\"\n"
+                                                  "enable Preedit to type best\n\n"
+
+                                                  "In some application, scim can't enable,\n"
+                                                  "this is not a bug of scim-unikey.\n"
+                                                  "You can try this in terminal: app_name | scim\n\n"
+
+                                                  "This IME come into being not intend to\n"
+                                                  "replace scim-m17n, just a choose, I recommend\n"
+                                                  "use this combine with scim-m17n\n\n"
+
+                                                  "For other support goto:\n"
+                                                  "  http://forum.ubuntu-vn.org/viewforum.php?f=85"));
+}
+String UnikeyFactory::get_icon_file() const
+{
+       return String(SCIM_ICONDIR SCIM_UNIKEY_ICON_FILENAME);
+}
+
+IMEngineInstancePointer UnikeyFactory::create_instance(const String & encoding, int id)
+{
+       return new UnikeyInstance(this, encoding, id);
+}
+
+UnikeyInstance::UnikeyInstance(UnikeyFactory *factory, const String &encoding, int id)
+       :IMEngineInstanceBase(factory, encoding, id),
+        m_auto_commit(false)
+{
+       static bool t, o;  //temp variable
+
+       m_preeditstring.clear();
+
+       CreateDefaultUnikeyOptions(&m_ukopt);
+
+       /* Read config
+          if can't read config, set it to default value*/
+
+    t = __config->read(SCIM_IMENGINE_UNIKEY_INPUTMETHOD, &m_im);
+       if (!t) m_im = 0;
+
+    t = __config->read(SCIM_IMENGINE_UNIKEY_OUTPUTCHARSET, &m_oc);
+       if (!t) m_oc = 0;
+
+       t = __config->read(SCIM_IMENGINE_UNIKEY_PREEDIT, &m_preedit);
+       if (!t) m_preedit = SCIM_IMENGINE_UNIKEY_PREEDIT_DEF;
+
+    // read preedit switch key
+       m_preeditskey.clear();
+       String s;
+       int i = 0, j;
+       t = __config->read(SCIM_IMENGINE_UNIKEY_PREEDIT_SWITCH_KEY, &s);
+       if (!t) s=SCIM_IMENGINE_UNIKEY_PREEDIT_SWITCH_KEY_DEF;
+       if (s.length())
+       {
+               while (true)
+               {
+                       j=s.find(',', i);
+                       if (j!=String::npos)
+                               m_preeditskey.push_back(KeyEvent(s.substr(i, j-i)));
+                       else
+                               break;
+                       i = j+1;
+               }
+               m_preeditskey.push_back(KeyEvent(s.substr(i)));
+       } // end read preedit switch key
+
+       t = __config->read(SCIM_IMENGINE_UNIKEY_PROCESSWATWORDBEGIN, &o);
+       m_process_w_AtBeginWord = t?o:SCIM_IMENGINE_UNIKEY_PROCESSWATWORDBEGIN_DEF;
+
+       t = __config->read(SCIM_IMENGINE_UNIKEY_CODERTELEX, &o);
+       m_codertelex = t?o:SCIM_IMENGINE_UNIKEY_CODERTELEX_DEF;
+
+// Unikey Options
+       t = __config->read(SCIM_IMENGINE_UNIKEY_FREEMARKING, &o);
+       m_ukopt.freeMarking = t?o:SCIM_IMENGINE_UNIKEY_FREEMARKING_DEF;
+
+       t = __config->read(SCIM_IMENGINE_UNIKEY_MODERNSTYLE, &o);
+       m_ukopt.modernStyle = t?o:SCIM_IMENGINE_UNIKEY_MODERNSTYLE_DEF;
+
+       t = __config->read(SCIM_IMENGINE_UNIKEY_MACROENABLED, &o);
+       m_ukopt.macroEnabled = t?o:SCIM_IMENGINE_UNIKEY_MACROENABLED_DEF;
+
+       t = __config->read(SCIM_IMENGINE_UNIKEY_SPELLCHECKENABLED, &o);
+       m_ukopt.spellCheckEnabled = t?o:SCIM_IMENGINE_UNIKEY_SPELLCHECKENABLED_DEF;
+
+       t = __config->read(SCIM_IMENGINE_UNIKEY_AUTONONVNRESTORE, &o);
+       m_ukopt.autoNonVnRestore = t?o:SCIM_IMENGINE_UNIKEY_AUTONONVNRESTORE_DEF;
+
+       UnikeySetOptions(&m_ukopt);
+
+       if (m_ukopt.macroEnabled)
+    {
+               UnikeyLoadMacroTable(getMacroFile());
+    }
+}
+
+UnikeyInstance::~UnikeyInstance()
+{
+}
+
+void UnikeyInstance::focus_in()
+{
+       reset();
+
+       register_properties(CreatePropertyList());
+
+       UnikeySetInputMethod(Unikey_IM[m_im]);
+       UnikeySetOutputCharset(Unikey_OC[m_oc]);
+       UnikeySetOptions(&m_ukopt);
+}
+
+void UnikeyInstance::focus_out()
+{
+       reset();
+}
+
+void UnikeyInstance::reset()
+{
+       UnikeyResetBuf();
+
+    m_lastkey_with_shift = false;
+
+       if (m_preedit)
+       {
+               if (m_preeditstring.length())
+               {
+                       commit_string(m_preeditstring);
+                       hide_preedit_string();
+                       m_preeditstring.clear();
+               }
+               m_auto_commit = false;
+       }
+}
+
+void UnikeyInstance::Unikey_send_backspace(int nBackspace)
+{
+       static WideString ws;
+       static int n;
+
+       //  if surrounding text was provided, use it instead of send backspace
+       if (get_surrounding_text(ws, n, nBackspace, 0))
+       {
+               // for type in Auto Complete in OpenOffice
+               // Hope this not rise bugs in others application
+               // not use SCIM_KEY_NullKey, because GTK application crash when GTK_IM_MODULE=scim
+
+               forward_key_event(SCIM_KEY_VoidSymbol);
+
+               delete_surrounding_text(-ws.length(), ws.length());
+       }
+       else
+       {
+               for (int i=0; i < nBackspace; i++)
+                       forward_key_event(SCIM_KEY_BackSpace);
+       }
+}
+
+void UnikeyInstance::Unikey_update_preedit_string(const WideString s, const bool visible)
+{
+    update_preedit_string(s);
+    update_preedit_caret(s.length());
+
+    if (visible == true)
+    {
+        show_preedit_string();
+    }
+    else
+    {
+        hide_preedit_string();
+    }
+}
+
+bool UnikeyInstance::process_key_event(const KeyEvent& key)
+{
+    bool tmp;
+
+       for (int i; i<m_preeditskey.size(); i++)
+               if (key==m_preeditskey.at(i))
+               {
+                       reset();
+                       m_preedit=!m_preedit;
+                       register_properties(CreatePropertyList());
+                       return true;
+               }
+
+    tmp = m_preedit?Unikey_process_key_event_preedit(key)
+               :Unikey_process_key_event_direct(key);
+
+
+    if ((key.code >= SCIM_KEY_space && key.code <= SCIM_KEY_asciitilde)
+        || (key.code >= SCIM_KEY_KP_Multiply && key.code <= SCIM_KEY_KP_9))
+    {
+        m_lastkey_with_shift = key.is_shift_down();
+    }
+    else
+    {
+        m_lastkey_with_shift = false;
+    }
+
+       return tmp;
+}
+
+/** This method not use preedit string */
+bool UnikeyInstance::Unikey_process_key_event_direct(const KeyEvent& key)
+{
+       if (key.is_key_release())
+               return false;
+
+       if (key.is_control_down() || key.mask & SCIM_KEY_AltMask)
+       {
+               reset();
+               return false;
+       }
+
+       if (key.code >= SCIM_KEY_Shift_L && key.code <= SCIM_KEY_Hyper_R)
+               return false;
+
+       if (key.code == SCIM_KEY_BackSpace)
+       {
+               UnikeyBackspacePress();     // xu ly phim backspace
+               if (UnikeyBackspaces==0)    // neu ukengine bao khong can xoa ky tu nao,
+                       return false;  // thi tra lai backspace cho chuong trinh khach
+               else
+               {
+                       Unikey_send_backspace(UnikeyBackspaces);
+
+                       // append key that need change tone pos after press backspace
+                       if (UnikeyBufChars)
+                       {
+                               if (Unikey_OC[m_oc] == CONV_CHARSET_XUTF8)
+                                       commit_string(utf8_mbstowcs((const char*)UnikeyBuf, UnikeyBufChars));  // send the solved string to client
+                               else
+                               {
+                                       static unsigned char buf[1024];
+                                       int bufSize=sizeof(buf)/sizeof(buf[0]);
+
+                                       latinToUtf(buf, UnikeyBuf, UnikeyBufChars, &bufSize);
+                                       commit_string(utf8_mbstowcs((const char*)buf, sizeof(buf)/sizeof(buf[0]) - bufSize));
+                               }
+                       }
+
+                       return true;
+               }
+       }
+
+       if (   (key.code >= SCIM_KEY_space && key.code <= SCIM_KEY_asciitilde)
+                  || (key.code >= SCIM_KEY_KP_Multiply && key.code <= SCIM_KEY_KP_9)
+               )
+       {
+               UnikeySetCapsState(key.mask & SCIM_KEY_ShiftMask,
+                                                  key.mask & SCIM_KEY_CapsLockMask);
+
+        // shift + space to restore keystroke
+               if (m_lastkey_with_shift == false
+            && key.mask & SCIM_KEY_ShiftMask
+            && key.code == SCIM_KEY_space
+                       && !UnikeyAtWordBeginning())
+        {
+                       UnikeyRestoreKeyStrokes();
+        }
+
+               else if ((key.code >= SCIM_KEY_KP_0 &&
+                                 key.code <= SCIM_KEY_KP_9))
+        {
+                       UnikeyPutChar(key.code);
+        }
+
+               else if (!m_process_w_AtBeginWord &&
+                                (key.code == SCIM_KEY_w || key.code == SCIM_KEY_W) &&
+                                UnikeyAtWordBeginning())
+        {
+                       UnikeyPutChar(key.code);
+        }
+
+               else if (m_codertelex && Unikey_IM[m_im] == UkTelex
+                                && (key.code == SCIM_KEY_bracketleft || key.code == SCIM_KEY_bracketright
+                                        || key.code == SCIM_KEY_braceleft || key.code == SCIM_KEY_braceright)
+                       )
+        {
+                       UnikeyPutChar(key.code);
+        }
+               else
+        {
+                       UnikeyFilter(key.code);
+        }
+
+               if (UnikeyBackspaces)
+        {
+                       Unikey_send_backspace(UnikeyBackspaces);
+        }
+
+               if (UnikeyBufChars)
+               {
+                       if (Unikey_OC[m_oc] == CONV_CHARSET_XUTF8)
+            {
+                               commit_string(utf8_mbstowcs((const char*)UnikeyBuf, UnikeyBufChars));  // send the solved string to client
+            }
+                       else
+                       {
+                               static unsigned char buf[1024];
+                               int bufSize=sizeof(buf)/sizeof(buf[0]);
+
+                               latinToUtf(buf, UnikeyBuf, UnikeyBufChars, &bufSize);
+                               commit_string(utf8_mbstowcs((const char*)buf, sizeof(buf)/sizeof(buf[0]) - bufSize));
+                       }
+               }
+               else
+        {
+            forward_key_event(key);
+                       return true;
+        }
+
+               return true;
+       }
+
+       // else
+       reset();
+       return false;
+}
+
+/** This method use preedit string */
+bool UnikeyInstance::Unikey_process_key_event_preedit(const KeyEvent& key)
+{
+       static int i;
+
+       if (key.code == SCIM_KEY_Tab
+               || key.mask & SCIM_KEY_ControlMask
+               || key.mask & SCIM_KEY_AltMask)
+       {
+               if (m_preeditstring.length())
+               {
+                       commit_string(m_preeditstring);
+                       hide_preedit_string();
+                       m_preeditstring.clear();
+               }
+               reset();
+               return false;
+       }
+
+       if (key.is_key_release())
+               return false;
+
+       if (key.code >= SCIM_KEY_Shift_L && key.code <= SCIM_KEY_Hyper_R)
+               return false;
+
+       else if (key.code == SCIM_KEY_Tab || key.code == SCIM_KEY_Return
+                        || key.code == SCIM_KEY_Delete || key.code == SCIM_KEY_KP_Enter
+                        || (key.code >= SCIM_KEY_Home && key.code <= SCIM_KEY_Insert)
+                        || (key.code >= SCIM_KEY_KP_Home && key.code <= SCIM_KEY_KP_Delete)
+               )
+       {
+               if (m_preeditstring.length())
+               {
+                       commit_string(m_preeditstring);
+                       hide_preedit_string();
+                       m_preeditstring.clear();
+               }
+
+               reset();
+               return false;
+       }
+
+       else if (key.code == SCIM_KEY_BackSpace)
+       {
+               UnikeyBackspacePress();     // process Backspace
+
+               if (UnikeyBackspaces==0 || m_preeditstring.empty())    // if Unikey tell no Backspace
+               {
+                       reset();
+                       return false;  // Return Backspace to client
+               }
+               else
+               {
+                       static int len;
+
+                       len = m_preeditstring.length();
+                       if (len <= UnikeyBackspaces)
+                       {
+                               m_preeditstring.clear();
+                               hide_preedit_string();
+                               m_auto_commit = true;
+                       }
+                       else
+                       {
+                               m_preeditstring.erase(len - UnikeyBackspaces, UnikeyBackspaces);
+                               Unikey_update_preedit_string(m_preeditstring, true);
+                       }
+
+                       // append key that need change tone pos after press backspace
+                       if (UnikeyBufChars)
+                       {
+                               if (Unikey_OC[m_oc] == CONV_CHARSET_XUTF8)
+                                       m_preeditstring.append(utf8_mbstowcs((const char*)UnikeyBuf, UnikeyBufChars));
+                               else
+                               {
+                                       static unsigned char buf[1024];
+                                       int bufSize=sizeof(buf)/sizeof(buf[0]);
+
+                                       latinToUtf(buf, UnikeyBuf, UnikeyBufChars, &bufSize);
+                                       m_preeditstring.append(utf8_mbstowcs((const char*)buf, sizeof(buf)/sizeof(buf[0])-bufSize));
+                               }
+
+                               m_auto_commit = false;
+                               Unikey_update_preedit_string(m_preeditstring, true);
+                       }
+               }
+
+               return true;
+       }
+
+       else if (   (key.code >= SCIM_KEY_space && key.code <= SCIM_KEY_asciitilde)
+                               || (key.code >= SCIM_KEY_KP_Multiply && key.code <= SCIM_KEY_KP_9)
+               )
+       {
+               UnikeySetCapsState(key.mask & SCIM_KEY_ShiftMask, key.mask & SCIM_KEY_CapsLockMask);
+
+        // auto commit char: commit char that never change later in preedit string
+        // if macro enabled, then not auto commit. Because macro may change any word
+               if (m_ukopt.macroEnabled==0 && (UnikeyAtWordBeginning() || m_auto_commit))
+               {
+                       for (i = 0; i < sizeof(WordAutoCommit); i++)
+                               if (key.code == WordAutoCommit[i])
+                               {
+                                       UnikeyPutChar(key.code);
+                                       m_auto_commit = true;
+                    forward_key_event(key); // forward keyevent instead of return false
+                                       return true;
+                               }
+               } // end auto commit char
+
+               if (!m_process_w_AtBeginWord && (key.code == SCIM_KEY_w || key.code == SCIM_KEY_W) && UnikeyAtWordBeginning())
+               {
+                       UnikeyPutChar(key.code);
+                       m_auto_commit = true;
+                       return false;
+               }
+
+               m_auto_commit = false;
+
+               if (m_lastkey_with_shift == false
+            && key.mask & SCIM_KEY_ShiftMask
+            && key.code == SCIM_KEY_space
+                       && !UnikeyAtWordBeginning())
+        {
+                       UnikeyRestoreKeyStrokes();
+        }
+               else if (key.code >= SCIM_KEY_KP_Multiply && key.code <= SCIM_KEY_KP_9)
+                       UnikeyPutChar(key.code);
+               else if (m_codertelex && Unikey_IM[m_im] == UkTelex
+                                && (key.code == SCIM_KEY_bracketleft || key.code == SCIM_KEY_bracketright
+                                        || key.code == SCIM_KEY_braceleft || key.code == SCIM_KEY_braceright)
+                       )
+                       UnikeyPutChar(key.code);
+               else
+                       UnikeyFilter(key.code);
+
+               if (UnikeyBackspaces > 0)
+               {
+                       static int len;
+
+                       len = m_preeditstring.length();
+
+                       if (len <= UnikeyBackspaces)
+                               m_preeditstring.clear();
+                       else
+                               m_preeditstring.erase(len - UnikeyBackspaces, UnikeyBackspaces);
+               }
+
+               if (UnikeyBufChars > 0)
+               {
+                       if (Unikey_OC[m_oc] == CONV_CHARSET_XUTF8)
+                               m_preeditstring.append(utf8_mbstowcs((const char*)UnikeyBuf, UnikeyBufChars));
+                       else
+                       {
+                               static unsigned char buf[1024];
+                               int bufSize=sizeof(buf)/sizeof(buf[0]);
+
+                               latinToUtf(buf, UnikeyBuf, UnikeyBufChars, &bufSize);
+                               m_preeditstring.append(utf8_mbstowcs((const char*)buf, sizeof(buf)/sizeof(buf[0])-bufSize));
+                       }
+               }
+               else
+               {       
+                       m_preeditstring.push_back(key.get_unicode_code());
+               }
+
+               if (m_preeditstring.length())
+               {
+                       if (key.code >= SCIM_KEY_KP_Multiply && key.code <= SCIM_KEY_KP_9)
+                       {
+                               commit_string(m_preeditstring);
+                               hide_preedit_string();
+                               m_preeditstring.clear();
+                               reset();
+                               return true;
+                       }
+                       else
+                       {
+                               for (i=0; i < sizeof(WordBreakSyms); i++)
+                                       if (WordBreakSyms[i] == m_preeditstring[m_preeditstring.length()-1] && key.code == WordBreakSyms[i])
+                                       {
+                                               commit_string(m_preeditstring);
+                                               hide_preedit_string();
+                                               m_preeditstring.clear();
+                                               reset();
+                                               return true;
+                                       }
+                       }
+               }
+
+        Unikey_update_preedit_string(m_preeditstring, true);
+               return true;
+       }
+
+       // else (key non process)
+       reset();
+       return false;
+}
+
+PropertyList UnikeyInstance::CreatePropertyList()
+{
+       PropertyList props;
+       int i;
+
+       Property prop("", "", "", "");
+
+// input method
+       prop.set_key("/Unikey/InputMethod");
+       prop.set_label(Unikey_IMNames[m_im]);
+       prop.set_icon("");
+       prop.set_tip(_("Choose input method"));
+       props.push_back(prop);
+
+       for (i=0; i<NUM_INPUTMETHOD; i++)
+       {
+               prop.set_key(String("/Unikey/InputMethod/") + Unikey_IMNames[i] + String(m_im==i?"-Checked":""));
+               prop.set_label(Unikey_IMNames[i]);
+               prop.set_icon(m_im==i?SCIM_ICONDIR SCIM_UNIKEY_ICON_CHECK:"");
+               prop.set_tip("");
+               props.push_back(prop);
+       }
+
+// output charset
+
+       prop.set_key("/Unikey/OutputCharset");
+       prop.set_label(Unikey_OCNames[m_oc]);
+       prop.set_icon("");
+       prop.set_tip(_("Choose output charset"));
+       props.push_back(prop);
+
+       for (i=0; i<NUM_OUTPUTCHARSET; i++)
+       {
+               prop.set_key(String("/Unikey/OutputCharset/") + Unikey_OCNames[i] + String(m_oc==i?"-Checked":""));
+               prop.set_label(Unikey_OCNames[i]);
+               prop.set_icon(m_oc==i?SCIM_ICONDIR SCIM_UNIKEY_ICON_CHECK:"");
+               prop.set_tip("");
+               props.push_back(prop);
+       }
+
+// unikey options
+    // menu
+       prop.set_key("/Unikey/Options");
+       prop.set_label(_("Options"));
+       prop.set_icon(SCIM_ICONDIR SCIM_UNIKEY_ICON_CONFIGURE);
+       prop.set_tip(_("Configure Unikey here"));
+       props.push_back(prop);
+
+       // spellcheck
+       prop.set_key(m_ukopt.spellCheckEnabled?
+                                "/Unikey/Options/SpellCheck/Disable":"/Unikey/Options/SpellCheck/Enable");
+       prop.set_label(_("Enable spell check"));
+       prop.set_icon(m_ukopt.spellCheckEnabled?SCIM_ICONDIR SCIM_UNIKEY_ICON_CHECK:"");
+       prop.set_tip(_("If enable, you can decrease mistake when typing"));
+       props.push_back(prop);
+       
+       // auto restore keystroke
+       prop.set_key(m_ukopt.autoNonVnRestore?
+                                "/Unikey/Options/AutoRestoreKeys/Disable":"/Unikey/Options/AutoRestoreKeys/Enable");
+       prop.set_label(_("Auto restore keys with invalid words"));
+       prop.set_icon(m_ukopt.autoNonVnRestore?SCIM_ICONDIR SCIM_UNIKEY_ICON_CHECK:"");
+       prop.set_tip(_("When typing a word not in Vietnamese,\n"
+                                                 "it will auto restore keystroke into orginal"));
+       props.push_back(prop);
+
+       // modern style
+       prop.set_key(m_ukopt.modernStyle?
+                                "/Unikey/Options/ModernStyle/Disable":"/Unikey/Options/ModernStyle/Enable");
+       prop.set_label(_("Use oà, uý (instead of òa, úy)"));
+       prop.set_icon(m_ukopt.modernStyle?SCIM_ICONDIR SCIM_UNIKEY_ICON_CHECK:"");
+       prop.set_tip("");
+       props.push_back(prop);
+
+       // freeMarking
+       prop.set_key(m_ukopt.freeMarking?
+                                "/Unikey/Options/FreeMarking/Disable":"/Unikey/Options/FreeMarking/Enable");
+       prop.set_label(_("Allow type with more freedom"));
+       prop.set_icon(m_ukopt.freeMarking?SCIM_ICONDIR SCIM_UNIKEY_ICON_CHECK:"");
+       prop.set_tip("");
+       props.push_back(prop);
+
+       // macro
+       prop.set_key(m_ukopt.macroEnabled?
+                                "/Unikey/Options/EnabledMacro/Disable":"/Unikey/Options/EnabledMacro/Enable");
+       prop.set_label(_("Enable Macro"));
+       prop.set_icon(m_ukopt.macroEnabled?SCIM_ICONDIR SCIM_UNIKEY_ICON_CHECK:"");
+       prop.set_tip("");
+       props.push_back(prop);
+
+       // preedit
+       prop.set_key(m_preedit?"/Unikey/Options/Preedit/Disable":"/Unikey/Options/Preedit/Enable");
+       prop.set_label(_("Enable PreEdit"));
+       prop.set_icon(m_preedit?SCIM_ICONDIR SCIM_UNIKEY_ICON_CHECK:"");
+       prop.set_tip(_("This option is best for most application\n"
+                                  "But you may don't like it because it have an underline when typing"));
+       props.push_back(prop);
+
+       // process w at begin
+       prop.set_key(m_process_w_AtBeginWord?
+                                "/Unikey/Options/ProcessWAtBegin/Disable":"/Unikey/Options/ProcessWAtBegin/Enable");
+       prop.set_label(_("Process W at word begin"));
+       prop.set_icon(m_process_w_AtBeginWord?SCIM_ICONDIR SCIM_UNIKEY_ICON_CHECK:"");
+       prop.set_tip(_("If enable, type W at begin\n"
+                                  "of word will change to Ư."));
+       props.push_back(prop);
+
+       // coder telex [,],{,}
+       prop.set_key(m_codertelex?
+                                "/Unikey/Options/CoderTelex/Disable":"/Unikey/Options/CoderTelex/Enable");
+       prop.set_label(_("Not use [,],{,} on Telex"));
+       prop.set_icon(m_codertelex?SCIM_ICONDIR SCIM_UNIKEY_ICON_CHECK:"");
+       prop.set_tip(_("Not use [,],{,} for map on Telex"));
+       props.push_back(prop);
+
+
+       return props;
+}
+
+void UnikeyInstance::trigger_property(const String &property)
+{
+       bool change = false;
+       int i;
+
+// input method
+       if (!property.compare(0, strlen("/Unikey/InputMethod/"), "/Unikey/InputMethod/"))
+       {
+               for (i=0; i<NUM_INPUTMETHOD; i++)
+                       if (!property.compare(property.length()-Unikey_IMNames[i].length(),
+                                                                Unikey_IMNames[i].length(),
+                                                                Unikey_IMNames[i]))
+                       {
+                               m_im = i;
+                               __config->write(SCIM_IMENGINE_UNIKEY_INPUTMETHOD, m_im);
+                               change = true;
+                               break;
+                       }
+       }
+
+// output charset
+       else if (!property.compare(0, strlen("/Unikey/OutputCharset/"), "/Unikey/OutputCharset/"))
+       {
+               for (i=0; i<NUM_OUTPUTCHARSET; i++)
+                       if (!property.compare(property.length()-Unikey_OCNames[i].length(),
+                                                                 Unikey_OCNames[i].length(),
+                                                                 Unikey_OCNames[i]))
+                       {
+                               m_oc = i;
+                               __config->write(SCIM_IMENGINE_UNIKEY_OUTPUTCHARSET, m_oc);
+                               change = true;
+                               break;
+                       }
+       }
+
+// spellcheck
+       else if (property == "/Unikey/Options/SpellCheck/Enable")
+       {
+               m_ukopt.spellCheckEnabled = true;
+               __config->write(SCIM_IMENGINE_UNIKEY_SPELLCHECKENABLED, true);
+               change = true;
+       }
+       else if (property == "/Unikey/Options/SpellCheck/Disable")
+       {
+               m_ukopt.spellCheckEnabled = false;
+               __config->write(SCIM_IMENGINE_UNIKEY_SPELLCHECKENABLED, false);
+               change = true;
+       }
+
+// auto restore keystroke
+       else if (property == "/Unikey/Options/AutoRestoreKeys/Enable")
+       {
+               m_ukopt.autoNonVnRestore = true;
+               __config->write(SCIM_IMENGINE_UNIKEY_AUTONONVNRESTORE, true);
+               change = true;
+       }
+       else if (property == "/Unikey/Options/AutoRestoreKeys/Disable")
+       {
+               m_ukopt.autoNonVnRestore = false;
+               __config->write(SCIM_IMENGINE_UNIKEY_AUTONONVNRESTORE, false);
+               change = true;
+       }
+
+// modern style
+       else if (property == "/Unikey/Options/ModernStyle/Enable")
+       {
+               m_ukopt.modernStyle = true;
+               __config->write(SCIM_IMENGINE_UNIKEY_MODERNSTYLE, true);
+               change = true;
+       }
+       else if (property == "/Unikey/Options/ModernStyle/Disable")
+       {
+               m_ukopt.modernStyle = false;
+               __config->write(SCIM_IMENGINE_UNIKEY_MODERNSTYLE, false);
+               change = true;
+       }
+
+// free Marking
+       else if (property == "/Unikey/Options/FreeMarking/Enable")
+       {
+               m_ukopt.freeMarking = true;
+               __config->write(SCIM_IMENGINE_UNIKEY_FREEMARKING, true);
+               change = true;
+       }
+       else if (property == "/Unikey/Options/FreeMarking/Disable")
+       {
+               m_ukopt.freeMarking = false;
+               __config->write(SCIM_IMENGINE_UNIKEY_FREEMARKING, false);
+               change = true;
+       }
+// macro 
+       else if (property == "/Unikey/Options/EnabledMacro/Enable")
+       {
+               m_ukopt.macroEnabled = true;
+        UnikeyLoadMacroTable(getMacroFile());
+               __config->write(SCIM_IMENGINE_UNIKEY_MACROENABLED, true);
+               change = true;
+       }
+       else if (property == "/Unikey/Options/EnabledMacro/Disable")
+       {
+               m_ukopt.macroEnabled = false;
+               __config->write(SCIM_IMENGINE_UNIKEY_MACROENABLED, false);
+               change = true;
+       }
+
+// preedit
+       else if (property == "/Unikey/Options/Preedit/Enable")
+       {
+               m_preedit = true;
+               __config->write(SCIM_IMENGINE_UNIKEY_PREEDIT, true);
+               change = true;
+       }
+       else if (property == "/Unikey/Options/Preedit/Disable")
+       {
+               m_preedit = false;
+               __config->write(SCIM_IMENGINE_UNIKEY_PREEDIT, false);
+               change = true;
+       }
+
+// process w at begin
+       else if (property == "/Unikey/Options/ProcessWAtBegin/Enable")
+       {
+               m_process_w_AtBeginWord = true;
+               __config->write(SCIM_IMENGINE_UNIKEY_PROCESSWATWORDBEGIN, true);
+               change = true;
+       }
+       else if (property == "/Unikey/Options/ProcessWAtBegin/Disable")
+       {
+               m_process_w_AtBeginWord = false;
+               __config->write(SCIM_IMENGINE_UNIKEY_PROCESSWATWORDBEGIN, false);
+               change = true;
+       }
+
+// coder telex
+       else if (property == "/Unikey/Options/CoderTelex/Enable")
+       {
+               m_codertelex = true;
+               __config->write(SCIM_IMENGINE_UNIKEY_CODERTELEX, true);
+               change = true;
+       }
+       else if (property == "/Unikey/Options/CoderTelex/Disable")
+       {
+               m_codertelex = false;
+               __config->write(SCIM_IMENGINE_UNIKEY_CODERTELEX, false);
+               change = true;
+       }
+
+       if (change)
+       {
+               __config->flush();
+        focus_out();
+               focus_in();
+       }
+}
diff --git a/src/scim_unikey_imengine.h b/src/scim_unikey_imengine.h
new file mode 100644 (file)
index 0000000..d8eef9f
--- /dev/null
@@ -0,0 +1,68 @@
+/**
+   Scim-Unikey Input Method
+   Version: 0.2.0a
+
+   Copyright (C) 2008-2009 Ubuntu-VN <http://www.ubuntu-vn.org>
+   Author: Le Quoc Tuan <mr.lequoctuan@gmail.com>
+   Home: http://scim-unikey.googlecode.com
+   License: GNU LESSER GENERAL PUBLIC LICENSE v2.1
+*/
+
+#if !defined (__SCIM_UNIKEY_IMENGINE_H)
+#define __SCIM_UNIKEY_IMENGINE_H
+
+#include "unikey.h"
+
+using namespace scim;
+
+class UnikeyFactory : public IMEngineFactoryBase
+{
+       friend class UnikeyInstance;
+
+public:
+       UnikeyFactory();
+       virtual ~UnikeyFactory ();
+
+       virtual WideString  get_name () const;
+       virtual WideString  get_authors () const;
+       virtual WideString  get_credits () const;
+       virtual WideString  get_help () const;
+       virtual String      get_uuid () const;
+       virtual String      get_icon_file () const;
+
+       virtual IMEngineInstancePointer create_instance (const String& encoding, int id = -1);
+};
+
+class UnikeyInstance : public IMEngineInstanceBase
+{
+public:
+       UnikeyInstance(UnikeyFactory *factory, const String& encoding, int id = -1);
+       virtual ~UnikeyInstance ();
+
+       virtual bool process_key_event(const KeyEvent& key);
+       virtual void reset();
+       virtual void focus_in();
+       virtual void focus_out();
+       virtual void trigger_property(const String &property);
+
+private:
+       bool Unikey_process_key_event_direct(const KeyEvent& key);
+       bool Unikey_process_key_event_preedit(const KeyEvent& key);
+       void Unikey_send_backspace(int nBackspace);
+       void Unikey_update_preedit_string(const WideString s, const bool visible);
+       PropertyList CreatePropertyList();
+
+       int m_im;                               // input method
+       int m_oc;                               // output charset
+       UnikeyOptions m_ukopt;                  // Unikey Options
+       WideString m_preeditstring;             // store PreEdit String
+       bool m_preedit;                         // is PreEdit On?
+       bool m_codertelex;                      // is CoderTelex on?
+       bool m_process_w_AtBeginWord;           // process W at Begin Word?
+       bool m_auto_commit;                     // auto commit?
+       std::vector<KeyEvent> m_preeditskey;    // keys to switch preedit and non preedit mode
+       bool m_lastkey_with_shift;              // last press key with modifier is shift
+};
+
+#endif
+
diff --git a/src/scim_unikey_setup.cpp b/src/scim_unikey_setup.cpp
new file mode 100644 (file)
index 0000000..7776d56
--- /dev/null
@@ -0,0 +1,664 @@
+/**
+   Scim-Unikey Input Method
+   Version: 0.2.0
+
+   Copyright (C) 2008-2009 Ubuntu-VN <http://www.ubuntu-vn.org>
+   Author: Le Quoc Tuan <mr.lequoctuan@gmail.com>
+   Home: http://scim-unikey.googlecode.com
+   License: GNU LESSER GENERAL PUBLIC LICENSE v2.1
+*/
+
+#define Uses_SCIM_CONFIG_BASE
+
+#include <libintl.h>
+#define _(String) dgettext(PACKAGE_NAME,String)
+
+#include <iostream>
+#include <gtk/gtk.h>
+#include <string.h>
+
+#include <scim.h>
+#include "scim_unikey_const.h"
+#include "scim_unikey_utils.h"
+#include "keycons.h"
+#include "mactab.h"
+#include "scimkeyselection.h"
+
+using namespace scim;
+
+#define scim_module_init unikey_setup_LTX_scim_module_init
+#define scim_module_exit unikey_setup_LTX_scim_module_exit
+
+#define scim_setup_module_create_ui       unikey_setup_LTX_scim_setup_module_create_ui
+#define scim_setup_module_get_category    unikey_setup_LTX_scim_setup_module_get_category
+#define scim_setup_module_get_name        unikey_setup_LTX_scim_setup_module_get_name
+#define scim_setup_module_get_description unikey_setup_LTX_scim_setup_module_get_description
+#define scim_setup_module_load_config     unikey_setup_LTX_scim_setup_module_load_config
+#define scim_setup_module_save_config     unikey_setup_LTX_scim_setup_module_save_config
+#define scim_setup_module_query_changed   unikey_setup_LTX_scim_setup_module_query_changed
+
+static bool    __have_changed                       = false;
+
+static bool    __unikey_preedit                     = SCIM_IMENGINE_UNIKEY_PREEDIT_DEF;
+static bool    __unikey_freemarking                 = SCIM_IMENGINE_UNIKEY_FREEMARKING_DEF;
+static bool    __unikey_modernstyle                 = SCIM_IMENGINE_UNIKEY_MODERNSTYLE_DEF;
+static bool    __unikey_macroenabled                = SCIM_IMENGINE_UNIKEY_MACROENABLED_DEF;
+static bool    __unikey_spellcheckenabled           = SCIM_IMENGINE_UNIKEY_SPELLCHECKENABLED_DEF;
+static bool    __unikey_autononvnrestore            = SCIM_IMENGINE_UNIKEY_AUTONONVNRESTORE_DEF;
+static bool    __unikey_codertelex                  = SCIM_IMENGINE_UNIKEY_CODERTELEX_DEF;
+static bool    __unikey_processwatwordbegin       = SCIM_IMENGINE_UNIKEY_PROCESSWATWORDBEGIN_DEF;
+
+static GtkTooltips  *__widget_tooltips              = 0;
+static GtkWidget    *__widget_preedit               = 0;
+static GtkWidget    *__widget_preedit_skey          = 0;
+static GtkWidget    *__widget_freemarking           = 0;
+static GtkWidget    *__widget_modernstyle           = 0;
+static GtkWidget    *__widget_macroenabled          = 0;
+static GtkWidget    *__widget_spellcheckenabled     = 0;
+static GtkWidget    *__widget_autononvnrestore      = 0;
+static GtkWidget    *__widget_codertelex            = 0;
+static GtkWidget    *__widget_processwatwordbegin   = 0;
+static CMacroTable  __macStore;
+
+static GtkWidget* create_setup_window();
+static void load_config(const ConfigPointer &config);
+static void save_config(const ConfigPointer &config);
+static bool query_changed();
+
+static void setup_widget_value();
+static GtkListStore* create_and_fill_list_store();
+
+static void on_default_toggle_button_toggled(GtkToggleButton *togglebutton, gpointer user_data);
+static void on_macrotable_button_clicked(GtkButton *button, gpointer user_data);
+static void on_key_edited (GtkCellRendererText *celltext, const gchar *string_path, const gchar *new_text, gpointer data);
+static void on_replace_edited (GtkCellRendererText *celltext, const gchar *string_path, const gchar *new_text, gpointer data);
+static void on_end_macro_table(GtkListStore *liststore);
+static void on_del_macro_clicked(GtkButton *button, gpointer user_data);
+static void on_delall_macro_clicked(GtkButton *button, gpointer user_data);
+static gboolean iter_2_macro(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data);
+static void on_hotkey_button_clicked(GtkButton *button, gpointer user_data);
+
+extern "C"
+{
+       void scim_module_init(void)
+       {
+       }
+
+       void scim_module_exit(void)
+       {
+       }
+
+       GtkWidget * scim_setup_module_create_ui (void)
+       {
+               return create_setup_window();
+       }
+
+       String scim_setup_module_get_category (void)
+       {
+               return String("IMEngine");
+       }
+
+       String scim_setup_module_get_name(void)
+       {
+               return String(_("Unikey Setup"));
+       }
+
+       String scim_setup_module_get_description(void)
+       {
+               return String("Setup scim-unikey v" SCIM_UNIKEY_VERSION " IMEngine.");
+       }
+
+       void scim_setup_module_load_config(const ConfigPointer &config)
+       {
+               load_config(config);
+       }
+
+       void scim_setup_module_save_config(const ConfigPointer &config)
+       {
+               save_config(config);
+       }
+
+       bool scim_setup_module_query_changed()
+       {
+               return query_changed();
+       }
+} // extern "C"
+
+static GtkWidget* create_setup_window()
+{
+       static GtkWidget *window = 0;
+       if (!window)
+       {
+               gtk_window_set_default_icon_from_file(SCIM_ICONDIR SCIM_UNIKEY_ICON_FILENAME, NULL);
+               __widget_tooltips = gtk_tooltips_new();
+
+// Create the toplevel box.
+               window = gtk_hbox_new(false, 0);
+
+// create vbox
+               GtkWidget *vbox0 = gtk_vbox_new(false, 0);
+               gtk_box_pack_start(GTK_BOX(window), vbox0, false, false, 0);
+
+// create Common Frame
+               GtkWidget *fr = gtk_frame_new(_("Unikey option"));
+               gtk_box_pack_start(GTK_BOX(vbox0), fr, false, false, 0);
+
+               GtkWidget *vbox = gtk_vbox_new(false, 5);
+               gtk_container_add(GTK_CONTAINER(fr), vbox);
+               gtk_container_set_border_width(GTK_CONTAINER(fr), 5);
+
+// create spellcheck checkbox
+               __widget_spellcheckenabled = gtk_check_button_new_with_label(_("Enable spell check"));
+               gtk_box_pack_start(GTK_BOX(vbox), __widget_spellcheckenabled, false, false, 0);
+               gtk_container_set_border_width(GTK_CONTAINER(__widget_spellcheckenabled), 5);
+               g_signal_connect(__widget_spellcheckenabled, "toggled", G_CALLBACK(on_default_toggle_button_toggled), &__unikey_spellcheckenabled);
+
+               gtk_tooltips_set_tip (__widget_tooltips, __widget_spellcheckenabled,
+                                                         _("If enable, you can decrease mistake when typing"), NULL);
+
+// create autononvnrestore checkbox
+               __widget_autononvnrestore = gtk_check_button_new_with_label(_("Auto restore keys with invalid words"));
+               gtk_box_pack_start(GTK_BOX(vbox), __widget_autononvnrestore, false, false, 0);
+               gtk_container_set_border_width(GTK_CONTAINER(__widget_autononvnrestore), 5);
+               g_signal_connect(__widget_autononvnrestore, "toggled", G_CALLBACK(on_default_toggle_button_toggled), &__unikey_autononvnrestore);
+
+               gtk_tooltips_set_tip (__widget_tooltips, __widget_autononvnrestore,
+                                                         _("When typing a word not in Vietnamese,\n"
+                                                         "it will auto restore keystroke into orginal"), NULL);
+
+// create modernstyle checkbox
+               __widget_modernstyle = gtk_check_button_new_with_label(_("Use oà, uý (instead of òa, úy)"));
+               gtk_box_pack_start(GTK_BOX(vbox), __widget_modernstyle, false, false, 0);
+               gtk_container_set_border_width(GTK_CONTAINER(__widget_modernstyle), 5);
+               g_signal_connect(__widget_modernstyle, "toggled", G_CALLBACK(on_default_toggle_button_toggled), &__unikey_modernstyle);
+
+// create freemarking checkbox
+               __widget_freemarking = gtk_check_button_new_with_label(_("Allow type with more freedom"));
+               gtk_box_pack_start(GTK_BOX(vbox), __widget_freemarking, false, false, 0);
+               gtk_container_set_border_width(GTK_CONTAINER(__widget_freemarking), 5);
+               g_signal_connect(__widget_freemarking, "toggled", G_CALLBACK(on_default_toggle_button_toggled), &__unikey_freemarking);
+
+/*
+// create preedit frame
+*/
+               GtkWidget *prefr = gtk_frame_new(_("Typing mode"));
+               gtk_container_set_border_width(GTK_CONTAINER(prefr), 5);
+               gtk_box_pack_start(GTK_BOX(vbox0), prefr, false, false, 0);
+
+               vbox = gtk_vbox_new(false, 5);
+               gtk_container_add(GTK_CONTAINER(prefr), vbox);
+
+// create preedit switch key
+               GtkWidget *psbox = gtk_hbox_new(false, 0);
+               gtk_box_pack_start(GTK_BOX(vbox), psbox, false, false, 0);
+
+               GtkWidget *lpskey = gtk_label_new(_("Mode switch key:"));
+               gtk_box_pack_start(GTK_BOX(psbox), lpskey, false, false, 5);
+
+               __widget_preedit_skey = gtk_entry_new();
+               gtk_entry_set_editable(GTK_ENTRY(__widget_preedit_skey), false);
+               gtk_box_pack_start(GTK_BOX(psbox), __widget_preedit_skey, true, false, 0);
+
+               GtkWidget *bpskey = gtk_button_new_with_label("...");
+               gtk_box_pack_start(GTK_BOX(psbox), bpskey, true, true, 0);
+               gtk_container_set_border_width(GTK_CONTAINER(bpskey), 5);
+               g_signal_connect(bpskey, "clicked", G_CALLBACK(on_hotkey_button_clicked), __widget_preedit_skey);
+
+
+// create preedit checkbox
+               __widget_preedit = gtk_check_button_new_with_label(_("Preedit is default"));
+               gtk_box_pack_start(GTK_BOX(vbox), __widget_preedit, false, false, 0);
+               gtk_container_set_border_width(GTK_CONTAINER(__widget_preedit), 5);
+               g_signal_connect(__widget_preedit, "toggled", G_CALLBACK(on_default_toggle_button_toggled), &__unikey_preedit);
+
+               gtk_tooltips_set_tip (__widget_tooltips, __widget_preedit,
+                                                         _("This option is best for most application\n"
+                                                         "But you may don't like it because it have an underline when typing"), NULL);
+
+
+
+//
+               vbox = gtk_vbox_new(false, 0);
+               gtk_box_pack_start(GTK_BOX(window), vbox, true, true, 0);
+
+// right frame 1
+               fr = gtk_frame_new(_("Macro option"));
+               gtk_box_pack_start(GTK_BOX(vbox), fr, false, true, 0);
+               gtk_container_set_border_width(GTK_CONTAINER(fr), 5);
+
+               // (frame 2)
+               GtkWidget *fr2 = gtk_frame_new(_("Telex option"));
+               gtk_box_pack_start(GTK_BOX(vbox), fr2, false, false, 0);
+               gtk_container_set_border_width(GTK_CONTAINER(fr2), 5);
+
+               vbox = gtk_vbox_new(false, 5);
+               gtk_container_add(GTK_CONTAINER(fr), vbox);
+
+// create macroenabled checkbox
+               __widget_macroenabled = gtk_check_button_new_with_label(_("Enable Macro"));
+               gtk_box_pack_start(GTK_BOX(vbox), __widget_macroenabled, false, false, 0);
+               gtk_container_set_border_width(GTK_CONTAINER(__widget_macroenabled), 5);
+               g_signal_connect(__widget_macroenabled, "toggled", G_CALLBACK(on_default_toggle_button_toggled), &__unikey_macroenabled);
+
+// create macroedit button
+               GtkWidget* __widget_macrotable = gtk_button_new_with_label(_("Macro Table"));
+               gtk_box_pack_start(GTK_BOX(vbox), __widget_macrotable, false, false, 0);
+               gtk_container_set_border_width(GTK_CONTAINER(__widget_macrotable), 5);
+               g_signal_connect(__widget_macrotable, "clicked", G_CALLBACK(on_macrotable_button_clicked), NULL);
+
+               gtk_tooltips_set_tip (__widget_tooltips, __widget_macrotable,
+                                                         _("Edit the macro table for Macro function"), NULL);
+
+
+// right frame 2
+               vbox = gtk_vbox_new(false, 5);
+               gtk_container_add(GTK_CONTAINER(fr2), vbox);
+
+// create process w at word begin checkbox
+               __widget_processwatwordbegin = gtk_check_button_new_with_label(_("Process W at word begin"));
+               gtk_box_pack_start(GTK_BOX(vbox), __widget_processwatwordbegin, false, false, 0);
+               gtk_container_set_border_width(GTK_CONTAINER(__widget_processwatwordbegin), 5);
+               g_signal_connect(__widget_processwatwordbegin, "toggled", G_CALLBACK(on_default_toggle_button_toggled), &__unikey_processwatwordbegin);
+
+               gtk_tooltips_set_tip (__widget_tooltips, __widget_processwatwordbegin,
+                                                         _("If enable, type W at begin\n"
+                                                         "of word will change to Ư."), NULL);
+
+// create coder telex checkbox
+               __widget_codertelex = gtk_check_button_new_with_label(_("Not use [,],{,} on Telex"));
+               gtk_box_pack_start(GTK_BOX(vbox), __widget_codertelex, false, false, 0);
+               gtk_container_set_border_width(GTK_CONTAINER(__widget_codertelex), 5);
+               g_signal_connect(__widget_codertelex, "toggled", G_CALLBACK(on_default_toggle_button_toggled), &__unikey_codertelex);
+
+               gtk_tooltips_set_tip (__widget_tooltips, __widget_codertelex,
+                                                         _("Not use [,],{,} for map on Telex"), NULL);
+
+
+               setup_widget_value();
+               gtk_widget_show_all(window);
+       }
+       return window;
+}
+
+static void setup_widget_value()
+{
+       if (__widget_preedit)
+               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(__widget_preedit), __unikey_preedit);
+
+       if (__widget_spellcheckenabled)
+               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(__widget_spellcheckenabled), __unikey_spellcheckenabled);
+
+       if (__widget_autononvnrestore)
+               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(__widget_autononvnrestore), __unikey_autononvnrestore);
+
+       if (__widget_modernstyle)
+               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(__widget_modernstyle), __unikey_modernstyle);
+
+       if (__widget_freemarking)
+               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(__widget_freemarking), __unikey_freemarking);
+
+       if (__widget_macroenabled)
+               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(__widget_macroenabled), __unikey_macroenabled);
+
+       if (__widget_codertelex)
+               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(__widget_codertelex), __unikey_codertelex);
+
+       if (__widget_processwatwordbegin)
+               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(__widget_processwatwordbegin), __unikey_processwatwordbegin);
+}
+
+static void load_config(const ConfigPointer &config)
+{
+       if (!config.null())
+       {
+               bool t;
+               t = config->read(SCIM_IMENGINE_UNIKEY_PREEDIT, &__unikey_preedit);
+               if (!t) __unikey_preedit = SCIM_IMENGINE_UNIKEY_PREEDIT_DEF;
+
+               String s;               
+               t = config->read(SCIM_IMENGINE_UNIKEY_PREEDIT_SWITCH_KEY, &s);
+               gtk_entry_set_text(GTK_ENTRY(__widget_preedit_skey), t?s.c_str():SCIM_IMENGINE_UNIKEY_PREEDIT_SWITCH_KEY_DEF);
+
+               t = config->read(SCIM_IMENGINE_UNIKEY_FREEMARKING, &__unikey_freemarking);
+               if (!t) __unikey_freemarking = SCIM_IMENGINE_UNIKEY_FREEMARKING_DEF;
+
+               t = config->read(SCIM_IMENGINE_UNIKEY_MODERNSTYLE, &__unikey_modernstyle);
+               if (!t) __unikey_modernstyle = SCIM_IMENGINE_UNIKEY_MODERNSTYLE_DEF;
+
+               t = config->read(SCIM_IMENGINE_UNIKEY_MACROENABLED, &__unikey_macroenabled);
+               if (!t) __unikey_macroenabled = SCIM_IMENGINE_UNIKEY_MACROENABLED_DEF;
+
+               t = config->read(SCIM_IMENGINE_UNIKEY_SPELLCHECKENABLED, &__unikey_spellcheckenabled);
+               if (!t) __unikey_spellcheckenabled = SCIM_IMENGINE_UNIKEY_SPELLCHECKENABLED_DEF;
+
+               t = config->read(SCIM_IMENGINE_UNIKEY_AUTONONVNRESTORE, &__unikey_autononvnrestore);
+               if (!t) __unikey_autononvnrestore = SCIM_IMENGINE_UNIKEY_AUTONONVNRESTORE_DEF;
+
+               t = config->read(SCIM_IMENGINE_UNIKEY_CODERTELEX, &__unikey_codertelex);
+               if (!t) __unikey_codertelex = SCIM_IMENGINE_UNIKEY_CODERTELEX_DEF;
+
+               t = config->read(SCIM_IMENGINE_UNIKEY_PROCESSWATWORDBEGIN, &__unikey_processwatwordbegin);
+               if (!t) __unikey_processwatwordbegin = SCIM_IMENGINE_UNIKEY_PROCESSWATWORDBEGIN_DEF;
+
+               __macStore.init();
+               __macStore.loadFromFile(getMacroFile());
+
+               setup_widget_value();
+               __have_changed = false;
+       }
+}
+
+static void save_config(const ConfigPointer &config)
+{
+       if (!config.null())
+       {
+               config->write(SCIM_IMENGINE_UNIKEY_PREEDIT, __unikey_preedit);
+               String s = String(gtk_entry_get_text(GTK_ENTRY(__widget_preedit_skey)));
+               config->write(SCIM_IMENGINE_UNIKEY_PREEDIT_SWITCH_KEY, s);
+               config->write(SCIM_IMENGINE_UNIKEY_FREEMARKING, __unikey_freemarking);
+               config->write(SCIM_IMENGINE_UNIKEY_MODERNSTYLE, __unikey_modernstyle);
+               config->write(SCIM_IMENGINE_UNIKEY_MACROENABLED, __unikey_macroenabled);
+               config->write(SCIM_IMENGINE_UNIKEY_SPELLCHECKENABLED, __unikey_spellcheckenabled);
+               config->write(SCIM_IMENGINE_UNIKEY_AUTONONVNRESTORE, __unikey_autononvnrestore);
+               config->write(SCIM_IMENGINE_UNIKEY_AUTONONVNRESTORE, __unikey_autononvnrestore);
+               config->write(SCIM_IMENGINE_UNIKEY_CODERTELEX, __unikey_codertelex);
+               config->write(SCIM_IMENGINE_UNIKEY_PROCESSWATWORDBEGIN, __unikey_processwatwordbegin);
+
+               s = String(getMacroFile());
+               FILE *f = fopen(s.c_str(), "wt");
+               if (f == NULL)
+               {
+                       s = s.substr(0, s.rfind('/'));
+                       int tmp=system((String("mkdir ") + s).c_str());
+               }
+               else
+                       fclose(f);
+
+               __macStore.writeToFile(getMacroFile());
+
+               __have_changed = false;
+       }
+}
+
+static bool query_changed()
+{
+       return __have_changed;
+}
+
+static void on_default_toggle_button_toggled(GtkToggleButton *togglebutton, gpointer user_data)
+{
+       bool *toggle = static_cast<bool*> (user_data);
+
+       if (toggle)
+       {
+               *toggle = gtk_toggle_button_get_active (togglebutton);
+               __have_changed = true;
+       }
+}
+
+enum {COL_KEY = 0, COL_REPLACE, NUM_COLS};
+
+static void on_macrotable_button_clicked(GtkButton *button, gpointer user_data)
+{
+       GtkWidget           *dialog;
+       GtkWidget           *treeview;
+       GtkTreeModel        *model;
+       GtkTreeViewColumn   *col;
+       GtkWidget           *contentarea;
+       GtkWidget           *hbox, *vbox;
+       GtkCellRenderer     *renderer;
+
+// create main dialog
+       dialog = gtk_dialog_new();
+       gtk_window_set_default_size(GTK_WINDOW(dialog), 600, 300);
+       gtk_window_set_title(GTK_WINDOW(dialog), _("Macro table definition"));
+       gtk_dialog_add_buttons(GTK_DIALOG(dialog),
+                                                  GTK_STOCK_OK, GTK_RESPONSE_OK,
+                                                  GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                                                  NULL);
+
+       //contentarea = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); // only for GTK >= 2.14
+       contentarea = GTK_DIALOG(dialog)->vbox;
+
+       hbox = gtk_hbox_new (false, 5);
+       gtk_container_add(GTK_CONTAINER(contentarea), hbox);
+
+// create scroll window and tree view
+       model = GTK_TREE_MODEL(create_and_fill_list_store());
+
+       treeview = gtk_tree_view_new_with_model (model);
+
+       GtkWidget *scroll = gtk_scrolled_window_new(NULL, NULL);
+       gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+
+       gtk_box_pack_start(GTK_BOX(hbox), scroll, true, true, 0);
+       gtk_container_add(GTK_CONTAINER(scroll), treeview);
+
+// create key column
+       renderer = gtk_cell_renderer_text_new();
+       g_object_set(renderer, "editable", true, NULL);
+       g_object_set(renderer, "width-chars", MAX_MACRO_KEY_LEN+4, NULL);
+       g_signal_connect(renderer, "edited", G_CALLBACK(on_key_edited), model);
+       col = gtk_tree_view_column_new_with_attributes(_("Word"), renderer, "text", COL_KEY, NULL);
+       gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), col);
+
+// create replace column
+       renderer = gtk_cell_renderer_text_new();
+       g_object_set(renderer, "editable", true, NULL);
+       //g_object_set(renderer, "width-chars", MAX_MACRO_KEY_LEN*3, NULL);
+       g_signal_connect(renderer, "edited", G_CALLBACK(on_replace_edited), model);
+       col = gtk_tree_view_column_new_with_attributes(_("Replace with"), renderer, "text", COL_REPLACE, NULL);
+       gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), col);
+
+       vbox = gtk_vbox_new (false, 0);
+       gtk_box_pack_end(GTK_BOX(hbox), vbox, false, false, 6);
+
+// create Del button
+       GtkWidget* btDel = gtk_button_new_with_label (_("Delete"));
+       gtk_box_pack_start(GTK_BOX(vbox), btDel, false, true, 3);
+       g_signal_connect(btDel, "clicked", G_CALLBACK(on_del_macro_clicked), treeview);
+
+// create DelAll button
+       GtkWidget *btDelAll = gtk_button_new_with_label (_("Delete All"));
+       gtk_box_pack_start(GTK_BOX(vbox), btDelAll, false, true, 3);
+       g_signal_connect(btDelAll, "clicked", G_CALLBACK(on_delall_macro_clicked), model);
+
+       gtk_widget_show_all(dialog);
+       gint result = gtk_dialog_run(GTK_DIALOG(dialog));
+
+// save Macro Table
+       if (result == GTK_RESPONSE_OK)
+       {
+               __macStore.init();
+               gtk_tree_model_foreach(model, iter_2_macro, NULL);
+
+               __have_changed = true;
+       }
+
+       g_object_unref(model);
+       gtk_widget_destroy(dialog);
+}
+
+static void on_end_macro_table(GtkListStore *liststore)
+{
+       GtkTreeIter     iter;
+       gchar           *lastkey;
+       gint n;
+
+       n = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(liststore), NULL);
+       if (n)
+       {
+               gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(liststore), &iter, NULL, n-1);
+       }
+       else
+       {
+               gtk_list_store_append(liststore, &iter);
+               gtk_list_store_set(liststore, &iter, COL_KEY, "...", COL_REPLACE, "...", -1);
+               return;
+       }
+
+       gtk_tree_model_get(GTK_TREE_MODEL(liststore), &iter, COL_KEY, &lastkey, -1);
+       if (strcmp(lastkey, "...") || n==0)
+       {
+               gtk_list_store_append(liststore, &iter);
+               gtk_list_store_set(liststore, &iter, COL_KEY, "...", COL_REPLACE, "...", -1);
+       }
+}
+
+static void on_del_macro_clicked(GtkButton *button, gpointer user_data)
+{
+       GtkTreeView     *treeview;
+       GtkListStore    *liststore;
+       GtkTreeSelection*tselect;
+       GtkTreeIter     iter;
+       gchar           *lastkey;
+
+       treeview = GTK_TREE_VIEW(user_data);
+       tselect = gtk_tree_view_get_selection(treeview);
+
+       if (gtk_tree_selection_get_selected(tselect, NULL, &iter))
+       {
+               liststore = GTK_LIST_STORE(gtk_tree_view_get_model(treeview));
+               gtk_tree_model_get(GTK_TREE_MODEL(liststore), &iter, COL_KEY, &lastkey, -1);
+               if (strcmp(lastkey, "..."))
+                       gtk_list_store_remove(liststore, &iter);
+       }
+}
+
+static void on_delall_macro_clicked(GtkButton *button, gpointer user_data)
+{
+       GtkListStore    *liststore;
+       GtkTreeIter     iter;
+
+       liststore = GTK_LIST_STORE(user_data);
+
+       gtk_list_store_clear(liststore);
+       on_end_macro_table(liststore);
+}
+
+static GtkListStore* create_and_fill_list_store()
+{
+       GtkListStore*   liststore;
+       GtkTreeIter     iter;
+       FILE            *f;
+       char            key[MAX_MACRO_KEY_LEN*3], replace[MAX_MACRO_TEXT_LEN*3];
+       UKBYTE          *p;
+       int             i, inLen, maxOutLen, ret;
+
+       liststore = gtk_list_store_new (NUM_COLS, G_TYPE_STRING, G_TYPE_STRING);
+
+// add key and replace to liststore
+       for (int i=0 ; i < __macStore.getCount() ; i++)
+       {
+               p = (UKBYTE *)__macStore.getKey(i);
+               inLen = -1;
+               maxOutLen = sizeof(key);
+               ret = VnConvert(CONV_CHARSET_VNSTANDARD, CONV_CHARSET_UNIUTF8,
+                                               (UKBYTE *) p, (UKBYTE *)key,
+                                               &inLen, &maxOutLen);
+               if (ret != 0)
+                       continue;
+
+               p = (UKBYTE *)__macStore.getText(i);
+               inLen = -1;
+               maxOutLen = sizeof(replace);
+               ret = VnConvert(CONV_CHARSET_VNSTANDARD, CONV_CHARSET_UNIUTF8,
+                                               p, (UKBYTE *)replace,
+                                               &inLen, &maxOutLen);
+               if (ret != 0)
+                       continue;
+
+               gtk_list_store_append(liststore, &iter);
+               gtk_list_store_set(liststore, &iter, COL_KEY, key, COL_REPLACE, replace, -1);
+       }
+
+       on_end_macro_table(liststore);
+       return liststore;
+}
+
+static void on_key_edited (GtkCellRendererText *celltext, const gchar *string_path, const gchar *new_text, gpointer data)
+{
+       GtkTreeModel    *model;
+       GtkTreeIter     iter;
+       gchar           *curkey, *oldkey, *oldreplace;
+       bool            b;
+
+       model = GTK_TREE_MODEL (data);
+
+       if (!strcmp(new_text, "..."))
+               return;
+
+       b = gtk_tree_model_get_iter_first(model, &iter);
+       while (b)
+       {
+               gtk_tree_model_get(model, &iter, COL_KEY, &curkey, -1);
+               if (!strcmp(curkey, new_text))
+                       return;
+
+               b = gtk_tree_model_iter_next(model, &iter);
+       }
+       gtk_tree_model_get_iter_from_string(model, &iter, string_path);
+       gtk_tree_model_get(model, &iter, COL_KEY, &oldkey, COL_REPLACE, &oldreplace, -1);
+
+       gtk_list_store_set(GTK_LIST_STORE(model), &iter, COL_KEY, new_text, -1);
+       if (!strcmp(oldkey, "..."))
+               gtk_list_store_set(GTK_LIST_STORE(model), &iter, COL_REPLACE, _("(replace text)"));
+
+       on_end_macro_table(GTK_LIST_STORE(model));
+}
+
+static void on_replace_edited (GtkCellRendererText *celltext, const gchar *string_path, const gchar *new_text, gpointer data)
+{
+       GtkTreeModel    *model;
+       GtkTreeIter     iter;
+       gchar           *oldkey;
+
+       model = GTK_TREE_MODEL (data);
+       gtk_tree_model_get_iter_from_string(model, &iter, string_path);
+
+       gtk_tree_model_get(model, &iter, COL_KEY, &oldkey, -1);
+       if (strcmp(oldkey, "..."))
+               gtk_list_store_set(GTK_LIST_STORE(model), &iter, COL_REPLACE, new_text, -1);
+}
+
+static gboolean iter_2_macro(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
+{
+       gchar   *key, *replace;
+       GtkTreeIter c;
+
+       c = *iter;
+
+       if (!gtk_tree_model_iter_next(model, &c))
+               return true;
+       gtk_tree_model_get(model, iter, COL_KEY, &key, COL_REPLACE, &replace, -1);
+
+       __macStore.addItem(key, replace, CONV_CHARSET_XUTF8);
+
+       return false;
+}
+
+static void on_hotkey_button_clicked (GtkButton *button, gpointer data)
+{
+       GtkWidget *wid = (GtkWidget*)data;
+
+       GtkWidget *dialog = scim_key_selection_dialog_new("Edit hotkey");
+       gint r;
+       const gchar *hotkeys = gtk_entry_get_text(GTK_ENTRY(wid));
+       
+       if (hotkeys)
+       {
+               scim_key_selection_dialog_set_keys(
+                       SCIM_KEY_SELECTION_DIALOG(dialog), hotkeys);
+       }
+
+       r = gtk_dialog_run(GTK_DIALOG(dialog));
+
+       if (r == GTK_RESPONSE_OK)
+       {
+               const gchar *newkeys = scim_key_selection_dialog_get_keys(SCIM_KEY_SELECTION_DIALOG(dialog));
+               gtk_entry_set_text(GTK_ENTRY(wid), newkeys?newkeys:"");
+               __have_changed = true;
+       }
+
+       gtk_widget_destroy(dialog);
+}
diff --git a/src/scim_unikey_utils.cpp b/src/scim_unikey_utils.cpp
new file mode 100644 (file)
index 0000000..f1cde6b
--- /dev/null
@@ -0,0 +1,63 @@
+/**
+   Scim-Unikey Input Method
+   Version: 0.2.0a
+
+   Copyright (C) 2008-2009 Ubuntu-VN <http://www.ubuntu-vn.org>
+   Author: Le Quoc Tuan <mr.lequoctuan@gmail.com>
+   Home: http://scim-unikey.googlecode.com
+   License: GNU LESSER GENERAL PUBLIC LICENSE v2.1
+*/
+
+#include <scim.h>
+#include "scim_unikey_const.h"
+
+const char *getMacroFile()
+{
+       scim::String s;
+       bool t;
+
+       s = getenv("HOME");
+       s.append(SCIM_IMENGINE_UNIKEY_MACROPATH);
+
+       int k=s.length()-1;
+       if ((s.at(0)=='\"' && s.at(k)=='\"'))
+       {
+               s.erase(k, 1);
+               s.erase(0, 1);
+       }
+
+       return s.c_str();
+}
+
+// code from x-unikey, for convert charset that not is XUtf-8
+int latinToUtf(unsigned char *dst, unsigned char *src, int inSize, int * pOutSize)
+{
+       int i;
+       int outLeft;
+       unsigned char ch;
+
+       outLeft = *pOutSize;
+
+       for (i=0; i<inSize; i++)
+       {
+               ch = *src++;
+               if (ch < 0x80)
+               {
+                       outLeft -= 1;
+                       if (outLeft >= 0)
+                               *dst++ = ch;
+               }
+               else
+               {
+                       outLeft -= 2;
+                       if (outLeft >= 0)
+                       {
+                               *dst++ = (0xC0 | ch >> 6);
+                               *dst++ = (0x80 | (ch & 0x3F));
+                       }
+               }
+       }
+
+       *pOutSize = outLeft;
+       return (outLeft >= 0);
+}
diff --git a/src/scim_unikey_utils.h b/src/scim_unikey_utils.h
new file mode 100644 (file)
index 0000000..cd1a05b
--- /dev/null
@@ -0,0 +1,17 @@
+/**
+   Scim-Unikey Input Method
+   Version: 0.2.0a
+
+   Copyright (C) 2008-2009 Ubuntu-VN <http://www.ubuntu-vn.org>
+   Author: Le Quoc Tuan <mr.lequoctuan@gmail.com>
+   Home: http://scim-unikey.googlecode.com
+   License: GNU LESSER GENERAL PUBLIC LICENSE v2.1
+*/
+
+#if !defined (__SCIM_UNIKEY_IMENGINE_UTILS_H)
+#define __SCIM_UNIKEY_IMENGINE_UTILS_H
+
+const char *getMacroFile();
+int latinToUtf(unsigned char *dst, unsigned char *src, int inSize, int * pOutSize);
+
+#endif
diff --git a/src/scimkeyselection.h b/src/scimkeyselection.h
new file mode 100644 (file)
index 0000000..686725b
--- /dev/null
@@ -0,0 +1,106 @@
+#ifndef __SCIM_KEY_SELECTION_H__
+#define __SCIM_KEY_SELECTION_H__
+
+#include <gtk/gtk.h>
+#include <scim.h>
+
+G_BEGIN_DECLS
+
+#define SCIM_TYPE_KEY_SELECTION            (scim_key_selection_get_type ())
+#define SCIM_KEY_SELECTION(obj)            (GTK_CHECK_CAST ((obj), SCIM_TYPE_KEY_SELECTION, ScimKeySelection))
+#define SCIM_KEY_SELECTION_CLASS(klass)    (GTK_CHECK_CLASS_CAST ((klass), SCIM_TYPE_KEY_SELECTION, ScimKeySelectionClass))
+#define SCIM_IS_KEY_SELECTION(obj)         (GTK_CHECK_TYPE ((obj), SCIM_TYPE_KEY_SELECTION))
+#define SCIM_IS_KEY_SELECTION_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), SCIM_TYPE_KEY_SELECTION))
+#define SCIM_KEY_SELECTION_GET_CLASS(obj)  (GTK_CHECK_GET_CLASS ((obj), SCIM_TYPE_KEY_SELECTION, ScimKeySelectionClass))
+
+#define SCIM_TYPE_KEY_SELECTION_DIALOG            (scim_key_selection_dialog_get_type ())
+#define SCIM_KEY_SELECTION_DIALOG(obj)            (GTK_CHECK_CAST ((obj), SCIM_TYPE_KEY_SELECTION_DIALOG, ScimKeySelectionDialog))
+#define SCIM_KEY_SELECTION_DIALOG_CLASS(klass)    (GTK_CHECK_CLASS_CAST ((klass), SCIM_TYPE_KEY_SELECTION_DIALOG, ScimKeySelectionDialogClass))
+#define SCIM_IS_KEY_SELECTION_DIALOG(obj)         (GTK_CHECK_TYPE ((obj), SCIM_TYPE_KEY_SELECTION_DIALOG))
+#define SCIM_IS_KEY_SELECTION_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), SCIM_TYPE_KEY_SELECTION_DIALOG))
+#define SCIM_KEY_SELECTION_DIALOG_GET_CLASS(obj)  (GTK_CHECK_GET_CLASS ((obj), SCIM_TYPE_KEY_SELECTION_DIALOG, ScimKeySelectionDialogClass))
+
+typedef struct _ScimKeySelection       ScimKeySelection;
+typedef struct _ScimKeySelectionClass  ScimKeySelectionClass;
+
+typedef struct _ScimKeySelectionDialog       ScimKeySelectionDialog;
+typedef struct _ScimKeySelectionDialogClass  ScimKeySelectionDialogClass;
+
+struct _ScimKeySelection
+{
+    GtkVBox  vbox;
+
+    GtkWidget *toggle_ctrl;
+    GtkWidget *toggle_alt;
+    GtkWidget *toggle_shift;
+    GtkWidget *toggle_meta;
+    GtkWidget *toggle_super;
+    GtkWidget *toggle_hyper;
+    GtkWidget *toggle_release;
+    GtkWidget *key_code;
+
+    GtkWidget        *list_view;
+    GtkTreeSelection *list_selection;
+    GtkListStore     *list_model;
+
+    gchar            *keys;
+};
+
+struct _ScimKeySelectionClass
+{
+    GtkVBoxClass parent_class;
+
+    void (*changed) (ScimKeySelection *keyselection);
+};
+
+struct _ScimKeySelectionDialog
+{
+    GtkDialog parent_instance;
+
+    GtkWidget *keysel;
+
+    GtkWidget *main_vbox;
+    GtkWidget *action_area;
+
+    GtkWidget *ok_button;
+    GtkWidget *cancel_button;
+};
+
+struct _ScimKeySelectionDialogClass
+{
+    GtkDialogClass parent_class;
+
+    /* Padding for future expansion */
+    void (*_gtk_reserved1) (void);
+    void (*_gtk_reserved2) (void);
+    void (*_gtk_reserved3) (void);
+    void (*_gtk_reserved4) (void);
+};
+
+GType                 scim_key_selection_get_type        (void) G_GNUC_CONST;
+
+GtkWidget*            scim_key_selection_new             (void);
+
+void                  scim_key_selection_set_keys        (ScimKeySelection       *keyselection,
+                                                          const gchar            *keys);
+
+void                  scim_key_selection_append_keys     (ScimKeySelection       *keyselection,
+                                                          const gchar            *keys);
+
+
+G_CONST_RETURN gchar* scim_key_selection_get_keys        (ScimKeySelection       *keyselection);
+
+
+GType                 scim_key_selection_dialog_get_type (void) G_GNUC_CONST;
+GtkWidget*            scim_key_selection_dialog_new      (const gchar            *title);
+void                  scim_key_selection_dialog_set_keys (ScimKeySelectionDialog *ksd,
+                                                          const gchar            *keys);
+G_CONST_RETURN gchar* scim_key_selection_dialog_get_keys (ScimKeySelectionDialog *ksd);
+
+G_END_DECLS
+
+#endif /* __GTK_KEY_SELECTION_H__ */
+
+/*
+vi:ts=4:nowrap:ai:expandtab
+*/
diff --git a/ukengine/COPYING b/ukengine/COPYING
new file mode 100644 (file)
index 0000000..bf50f20
--- /dev/null
@@ -0,0 +1,482 @@
+                 GNU LIBRARY GENERAL PUBLIC LICENSE
+                      Version 2, June 1991
+
+ Copyright (C) 1991 Free Software Foundation, Inc.
+                   59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the library GPL.  It is
+ numbered 2 because it goes with version 2 of the ordinary GPL.]
+
+                           Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+  This license, the Library General Public License, applies to some
+specially designated Free Software Foundation software, and to any
+other libraries whose authors decide to use it.  You can use it for
+your libraries, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if
+you distribute copies of the library, or if you modify it.
+
+  For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you.  You must make sure that they, too, receive or can get the source
+code.  If you link a program with the library, you must provide
+complete object files to the recipients so that they can relink them
+with the library, after making changes to the library and recompiling
+it.  And you must show them these terms so they know their rights.
+
+  Our method of protecting your rights has two steps: (1) copyright
+the library, and (2) offer you this license which gives you legal
+permission to copy, distribute and/or modify the library.
+
+  Also, for each distributor's protection, we want to make certain
+that everyone understands that there is no warranty for this free
+library.  If the library is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original
+version, so that any problems introduced by others will not reflect on
+the original authors' reputations.
+\f
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that companies distributing free
+software will individually obtain patent licenses, thus in effect
+transforming the program into proprietary software.  To prevent this,
+we have made it clear that any patent must be licensed for everyone's
+free use or not licensed at all.
+
+  Most GNU software, including some libraries, is covered by the ordinary
+GNU General Public License, which was designed for utility programs.  This
+license, the GNU Library General Public License, applies to certain
+designated libraries.  This license is quite different from the ordinary
+one; be sure to read it in full, and don't assume that anything in it is
+the same as in the ordinary license.
+
+  The reason we have a separate public license for some libraries is that
+they blur the distinction we usually make between modifying or adding to a
+program and simply using it.  Linking a program with a library, without
+changing the library, is in some sense simply using the library, and is
+analogous to running a utility program or application program.  However, in
+a textual and legal sense, the linked executable is a combined work, a
+derivative of the original library, and the ordinary General Public License
+treats it as such.
+
+  Because of this blurred distinction, using the ordinary General
+Public License for libraries did not effectively promote software
+sharing, because most developers did not use the libraries.  We
+concluded that weaker conditions might promote sharing better.
+
+  However, unrestricted linking of non-free programs would deprive the
+users of those programs of all benefit from the free status of the
+libraries themselves.  This Library General Public License is intended to
+permit developers of non-free programs to use free libraries, while
+preserving your freedom as a user of such programs to change the free
+libraries that are incorporated in them.  (We have not seen how to achieve
+this as regards changes in header files, but we have achieved it as regards
+changes in the actual functions of the Library.)  The hope is that this
+will lead to faster development of free libraries.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.  Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library".  The
+former contains code derived from the library, while the latter only
+works together with the library.
+
+  Note that it is possible for a library to be covered by the ordinary
+General Public License rather than by this special one.
+\f
+                 GNU LIBRARY GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License Agreement applies to any software library which
+contains a notice placed by the copyright holder or other authorized
+party saying it may be distributed under the terms of this Library
+General Public License (also called "this License").  Each licensee is
+addressed as "you".
+
+  A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+  The "Library", below, refers to any such software library or work
+which has been distributed under these terms.  A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language.  (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+  "Source code" for a work means the preferred form of the work for
+making modifications to it.  For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+  Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it).  Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+  
+  1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+  You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+\f
+  2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) The modified work must itself be a software library.
+
+    b) You must cause the files modified to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    c) You must cause the whole of the work to be licensed at no
+    charge to all third parties under the terms of this License.
+
+    d) If a facility in the modified Library refers to a function or a
+    table of data to be supplied by an application program that uses
+    the facility, other than as an argument passed when the facility
+    is invoked, then you must make a good faith effort to ensure that,
+    in the event an application does not supply such function or
+    table, the facility still operates, and performs whatever part of
+    its purpose remains meaningful.
+
+    (For example, a function in a library to compute square roots has
+    a purpose that is entirely well-defined independent of the
+    application.  Therefore, Subsection 2d requires that any
+    application-supplied function or table used by this function must
+    be optional: if the application does not supply it, the square
+    root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library.  To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License.  (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.)  Do not make any other change in
+these notices.
+\f
+  Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+  This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+  4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+  If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library".  Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+  However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library".  The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+  When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library.  The
+threshold for this to be true is not precisely defined by law.
+
+  If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work.  (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+  Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+\f
+  6. As an exception to the Sections above, you may also compile or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+  You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License.  You must supply a copy of this License.  If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License.  Also, you must do one
+of these things:
+
+    a) Accompany the work with the complete corresponding
+    machine-readable source code for the Library including whatever
+    changes were used in the work (which must be distributed under
+    Sections 1 and 2 above); and, if the work is an executable linked
+    with the Library, with the complete machine-readable "work that
+    uses the Library", as object code and/or source code, so that the
+    user can modify the Library and then relink to produce a modified
+    executable containing the modified Library.  (It is understood
+    that the user who changes the contents of definitions files in the
+    Library will not necessarily be able to recompile the application
+    to use the modified definitions.)
+
+    b) Accompany the work with a written offer, valid for at
+    least three years, to give the same user the materials
+    specified in Subsection 6a, above, for a charge no more
+    than the cost of performing this distribution.
+
+    c) If distribution of the work is made by offering access to copy
+    from a designated place, offer equivalent access to copy the above
+    specified materials from the same place.
+
+    d) Verify that the user has already received a copy of these
+    materials or that you have already sent this user a copy.
+
+  For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it.  However, as a special exception,
+the source code distributed need not include anything that is normally
+distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+  It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system.  Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+\f
+  7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+    a) Accompany the combined library with a copy of the same work
+    based on the Library, uncombined with any other library
+    facilities.  This must be distributed under the terms of the
+    Sections above.
+
+    b) Give prominent notice with the combined library of the fact
+    that part of it is a work based on the Library, and explaining
+    where to find the accompanying uncombined form of the same work.
+
+  8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License.  Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License.  However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+  9. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Library or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+  10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+\f
+  11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded.  In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+  13. The Free Software Foundation may publish revised and/or new
+versions of the Library General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation.  If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+\f
+  14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission.  For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this.  Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+                           NO WARRANTY
+
+  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+                    END OF TERMS AND CONDITIONS
+\f
+           How to Apply These Terms to Your New Libraries
+
+  If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change.  You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+  To apply these terms, attach the following notices to the library.  It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the library's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public
+    License along with this library; if not, write to the 
+    Free Software Foundation, Inc., 59 Temple Place - Suite 330, 
+    Boston, MA  02111-1307  USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the
+  library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+  <signature of Ty Coon>, 1 April 1990
+  Ty Coon, President of Vice
+
+That's all there is to it!
diff --git a/ukengine/Makefile.am b/ukengine/Makefile.am
new file mode 100644 (file)
index 0000000..d1cacda
--- /dev/null
@@ -0,0 +1,32 @@
+EXTRA_DIST                  = diff README COPYING
+
+unikey_zmoddir              = ${libdir}
+unikey_zmod_LTLIBRARIES     = libunikey-zmod.la
+
+libunikey_zmod_la_LDFLAGS= -version-info $(UNIKEY_CURRENT):$(UNIKEY_REVISION):$(UNIKEY_AGE)
+
+libunikey_zmod_la_SOURCES = \
+       byteio.cpp \
+       byteio.h \
+       charset.cpp \
+       charset.h \
+       convert.cpp \
+       data.cpp \
+       data.h \
+       error.cpp \
+       inputproc.cpp \
+       inputproc.h \
+       keycons.h \
+       mactab.cpp \
+       mactab.h \
+       pattern.cpp \
+       pattern.h \
+       ukengine.cpp \
+       ukengine.h \
+       unikey.cpp \
+       unikey.h \
+       usrkeymap.cpp \
+       usrkeymap.h \
+       vnconv.h \
+       vnlexi.h
+
diff --git a/ukengine/README b/ukengine/README
new file mode 100644 (file)
index 0000000..a769bac
--- /dev/null
@@ -0,0 +1,9 @@
+   This folder contains ukengine (with changes
+for better use in my project) taking from project
+x-unikey (http://www.unikey.org).
+
+   The diff folder contains the difference of
+this ukengine and the original version.
+
+   Read COPYING for License of ukengine.
+
diff --git a/ukengine/byteio.cpp b/ukengine/byteio.cpp
new file mode 100644 (file)
index 0000000..a69c222
--- /dev/null
@@ -0,0 +1,528 @@
+// -*- coding:unix; mode:c++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
+#include <string.h>
+#include "byteio.h"
+
+//------------------------------------------------
+StringBIStream::StringBIStream(UKBYTE *data, int len, int elementSize)
+{
+       m_data = m_current = data;
+       m_len = m_left = len;
+    if (len == -1) {
+        if (elementSize == 2)
+            m_eos = (*(UKWORD *)data == 0);
+        else if (elementSize == 4)
+            m_eos = (*(UKDWORD *)data == 4);
+        else
+            m_eos = (*data == 0);
+    }
+       else
+               m_eos = (len <= 0);
+       m_didBookmark = 0;
+}
+
+//------------------------------------------------
+int StringBIStream::eos()
+{
+       return m_eos;
+}
+
+//------------------------------------------------
+int StringBIStream::getNext(UKBYTE & b)
+{
+       if (m_eos)
+               return 0;
+       b = *m_current++;
+       if (m_len == -1) {
+               m_eos = (b == 0);
+       }
+       else {
+               m_left--;
+               m_eos = (m_left <= 0);
+       }
+       return 1;
+}
+
+//------------------------------------------------
+int StringBIStream::unget(UKBYTE b)
+{
+       if (m_current != m_data) {
+               *--m_current = b;
+               m_eos = 0;
+               if (m_len != -1)
+                       m_left++;
+       }
+       return 1;
+}
+
+//------------------------------------------------
+int StringBIStream::getNextW(UKWORD & w)
+{
+       if (m_eos) return 0;
+       w = *((UKWORD *)m_current);
+       m_current += 2;
+       if (m_len == -1)
+               m_eos = (w == 0);
+       else {
+               m_left -= 2;
+               m_eos = (m_left <= 0);
+       }
+       return 1;
+}
+
+//------------------------------------------------
+int StringBIStream::getNextDW(UKDWORD & dw)
+{
+       if (m_eos) return 0;
+
+       dw = *((UKDWORD *)m_current);
+       m_current += 4;
+       if (m_len == -1)
+               m_eos = (dw == 0);
+       else {
+               m_left -= 4;
+               m_eos = (m_left <= 0);
+       }
+       return 1;
+}
+
+//------------------------------------------------
+int StringBIStream::peekNext(UKBYTE & b)
+{
+       if (m_eos)
+               return 0;
+       b = *m_current;
+       return 1;
+}
+
+//------------------------------------------------
+int StringBIStream::peekNextW(UKWORD & w)
+{
+       if (m_eos)
+               return 0;
+       w = *((UKWORD *)m_current);
+       return 1;
+}
+
+/*
+//------------------------------------------------
+int StringBIStream::peekNextDW(UKDWORD & dw)
+{
+       if (m_eos)
+               return 0;
+       dw = *((UKDWORD *)m_current);
+       return 1;
+}
+*/
+
+//------------------------------------------------
+void StringBIStream::reopen()
+{
+       m_current = m_data;
+       m_left = m_len;
+       if (m_len == -1)
+               m_eos = (m_data == 0);
+       else
+               m_eos = (m_len <= 0);
+       m_didBookmark = 0;
+}
+
+//------------------------------------------------
+int StringBIStream::bookmark()
+{
+       m_didBookmark = 1;
+       m_bookmark.current = m_current;
+       m_bookmark.data = m_data;
+       m_bookmark.eos = m_eos;
+       m_bookmark.left = m_left;
+       m_bookmark.len = m_len;
+       return 1;
+}
+
+//------------------------------------------------
+int StringBIStream::gotoBookmark()
+{
+       if (!m_didBookmark)
+               return 0;
+       m_current = m_bookmark.current;
+       m_data = m_bookmark.data;
+       m_eos = m_bookmark.eos;
+       m_left = m_bookmark.left;
+       m_len = m_bookmark.len;
+       return 1;
+}
+
+//------------------------------------------------
+int StringBIStream::close()
+{
+       return 1;
+};
+
+//////////////////////////////////////////////////
+// Class StringBOStream
+//////////////////////////////////////////////////
+
+//------------------------------------------------
+StringBOStream::StringBOStream(UKBYTE *buf, int len)
+{
+       m_current = m_buf = buf;
+       m_len = len;
+       m_out = 0;
+       m_bad = 0;
+}
+
+//------------------------------------------------
+int StringBOStream::putB(UKBYTE b)
+{
+       m_out++;
+/*
+       if (m_out >= 2147483647) {
+               int err;
+               err = 1;
+       }
+*/
+       if (m_bad)
+               return 0;
+/*
+       if (m_out < 0) {
+               int i;
+               i = 1;
+       }
+*/
+       if (m_out <= m_len) {
+               *m_current++ = b;
+               return 1;
+       }
+       m_bad = 1;
+       return 0;
+}
+
+//------------------------------------------------
+int StringBOStream::putW(UKWORD w)
+{
+       m_out += 2;
+       if (m_bad)
+               return 0;
+       if (m_out <= m_len) {
+               *((UKWORD *)m_current) = w;
+               m_current += 2;
+               return 1;
+       }
+       m_bad = 1;
+       return 0;
+}
+
+//------------------------------------------------
+int StringBOStream::puts(const char *s, int size)
+{
+       if (size == -1) {
+               while (*s) {
+                       m_out++;
+                       if (m_out <= m_len) 
+                               *m_current++ = *s;
+                       s++;
+               }
+               if (!m_bad && m_out > m_len)
+                       m_bad = 1;
+               return (!m_bad);
+       }
+
+       int n;
+       if (!m_bad && m_out <= m_len) {
+               n = m_len - m_out;
+               if (n>size)
+                       n = size;
+               memcpy(m_current, s, n);
+               m_current += n;
+       }
+
+       m_out += size;
+       if (!m_bad && m_out > m_len)
+               m_bad = 1;
+       return (!m_bad);
+}
+
+//------------------------------------------------
+void StringBOStream::reopen()
+{
+       m_current = m_buf;
+       m_out = 0;
+       m_bad = 0;
+}
+
+
+//------------------------------------------------
+int StringBOStream::isOK()
+{
+       return !m_bad;
+}
+
+
+////////////////////////////////////////////////////
+// Class FileBIStream                             //
+////////////////////////////////////////////////////
+
+//----------------------------------------------------
+FileBIStream::FileBIStream(int bufSize, char *buf) 
+{
+       m_file = NULL;
+       m_buf = buf;
+       m_bufSize = bufSize;
+       m_own = 1;
+       m_didBookmark = 0;
+       
+       m_readAhead = 0;
+       m_lastIsAhead = 0;
+}
+
+//----------------------------------------------------
+FileBIStream::~FileBIStream()
+{
+       if (m_own)
+               close();
+}
+
+//----------------------------------------------------
+int FileBIStream::open(const char *fileName)
+{
+       m_file = fopen(fileName, "rb");
+       if (m_file == NULL)
+               return 0;
+       setvbuf(m_file, m_buf, _IOFBF, m_bufSize);
+       m_own = 0;
+       m_readAhead = 0;
+       m_lastIsAhead = 0;
+       return 1;
+}
+
+//----------------------------------------------------
+int FileBIStream::close()
+{
+       if (m_file != NULL) {
+               fclose(m_file);
+               m_file = NULL;
+       }
+       return 1;
+}
+
+//----------------------------------------------------
+void FileBIStream::attach(FILE * f)
+{
+       m_file = f;
+       m_own = 0;
+       m_readAhead = 0;
+       m_lastIsAhead = 0;
+}
+
+//----------------------------------------------------
+int FileBIStream::eos()
+{
+  if (m_readAhead)
+    return 0;
+  return feof(m_file);
+}
+
+//----------------------------------------------------
+int FileBIStream::getNext(UKBYTE &b)
+{
+  if (m_readAhead) {
+    m_readAhead = 0;
+    b = m_readByte;
+    m_lastIsAhead = 1;
+    return 1;
+  }
+
+  m_lastIsAhead = 0;
+  b = fgetc(m_file);
+  return (!feof(m_file));
+}
+
+//----------------------------------------------------
+int FileBIStream::peekNext(UKBYTE &b)
+{
+  if (m_readAhead) {
+    b = m_readByte;
+    return 1;
+  }
+
+  b = fgetc(m_file);
+  if (feof(m_file))
+    return 0;
+  ungetc(b, m_file);
+  return 1;
+}
+
+//----------------------------------------------------
+int FileBIStream::unget(UKBYTE b)
+{
+  if (m_lastIsAhead) {
+    m_lastIsAhead = 0;
+    m_readAhead = 1;
+    m_readByte = b;
+    return 1;
+  }
+
+  ungetc(b, m_file);
+  return 1;
+}
+
+//----------------------------------------------------
+int FileBIStream::getNextW(UKWORD &w)
+{
+  UKBYTE b1, b2;
+
+  if (getNext(b1)) {
+    if (getNext(b2)) {
+      *((UKBYTE *)&w) = b1;
+      *(((UKBYTE *)&w)+1) = b2;
+      return 1;
+    }
+  }
+  return 0;
+}
+
+//----------------------------------------------------
+int FileBIStream::getNextDW(UKDWORD &dw)
+{
+  UKWORD w1, w2;
+  if (getNextW(w1)) {
+    if (getNextW(w2)) {
+      *((UKWORD *)&dw) = w1;
+      *(((UKWORD *)&dw)+1) = w2;
+      return 1;
+    }
+  }
+  return 0;
+      
+}
+//----------------------------------------------------
+int FileBIStream::peekNextW(UKWORD &w)
+{
+  UKBYTE hi, low;
+  if (getNext(low)) {
+    if (getNext(hi)) {
+      unget(hi);
+      w = hi;
+      w = (w << 8) + low;
+      m_readAhead = 1;
+      m_readByte = low;
+      m_lastIsAhead = 0;
+      return 1;
+    }
+
+    m_readAhead = 1;
+    m_readByte = low;
+    m_lastIsAhead = 0;
+    return 0;
+  }
+  return 0;
+}
+
+//----------------------------------------------------
+int FileBIStream::bookmark()
+{
+       m_didBookmark = 1;
+       m_bookmark.pos = ftell(m_file);
+       return 1;
+}
+
+
+//----------------------------------------------------
+int FileBIStream::gotoBookmark()
+{
+       if (!m_didBookmark)
+               return 0;
+       fseek(m_file, m_bookmark.pos, SEEK_SET);
+       return 1;
+}
+
+////////////////////////////////////////////////////
+// Class FileBOStream                             //
+////////////////////////////////////////////////////
+//----------------------------------------------------
+FileBOStream::FileBOStream(int bufSize, char *buf) 
+{
+       m_file = NULL;
+       m_buf = buf;
+       m_bufSize = bufSize;
+       m_own = 1;
+       m_bad = 1;
+}
+
+//----------------------------------------------------
+FileBOStream::~FileBOStream()
+{
+       if (m_own)
+               close();
+}
+
+//----------------------------------------------------
+int FileBOStream::open(const char *fileName)
+{
+       m_file = fopen(fileName, "wb");
+       if (m_file == NULL)
+               return 0;
+       m_bad = 0;
+       setvbuf(m_file, m_buf, _IOFBF, m_bufSize);
+       m_own = 1;
+       return 1;
+}
+
+//----------------------------------------------------
+void FileBOStream::attach(FILE * f)
+{
+       m_file = f;
+       m_own = 0;
+       m_bad = 0;
+}
+
+//----------------------------------------------------
+int FileBOStream::close()
+{
+       if (m_file != NULL) {
+               fclose(m_file);
+               m_file = NULL;
+       }
+       return 1;
+}
+
+//----------------------------------------------------
+int FileBOStream::putB(UKBYTE b)
+{
+       if (m_bad)
+               return 0;
+       m_bad = (fputc(b, m_file) == EOF);
+       return (!m_bad);
+}
+
+//----------------------------------------------------
+int FileBOStream::putW(UKWORD w)
+{
+       if (m_bad)
+               return 0;
+       //      m_bad = (fputwc(w, m_file) == WEOF); 
+       m_bad = (fputc((UKBYTE)w, m_file) == EOF);
+       if (m_bad)
+         return 0;
+       m_bad = (fputc((UKBYTE)(w >> 8), m_file) == EOF);
+       return (!m_bad);
+}
+
+//----------------------------------------------------
+int FileBOStream::puts(const char *s, int size)
+{
+       if (m_bad)
+               return 0;
+       if (size == -1) {
+               m_bad = (fputs(s, m_file) == EOF);
+               return (!m_bad);
+       }
+       int out = fwrite(s, 1, size, m_file);
+       m_bad = (out != size);
+       return (!m_bad);
+}
+
+//----------------------------------------------------
+int FileBOStream::isOK()
+{
+       return !m_bad;
+}
diff --git a/ukengine/byteio.h b/ukengine/byteio.h
new file mode 100644 (file)
index 0000000..bc42678
--- /dev/null
@@ -0,0 +1,194 @@
+// -*- coding:unix; mode:c++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
+#ifndef BYTE_IO_STREAM_H
+#define BYTE_IO_STREAM_H
+
+
+//#include "vnconv.h"
+#include <stdio.h>
+
+typedef unsigned char UKBYTE;
+typedef unsigned short UKWORD;
+typedef unsigned int UKDWORD;
+
+//----------------------------------------------------
+class ByteStream {
+ public:
+  virtual ~ByteStream(){};
+};
+
+//----------------------------------------------------
+class ByteInStream: public ByteStream
+{
+public:
+       virtual int getNext(UKBYTE &b) = 0;
+       virtual int peekNext(UKBYTE &b) = 0;
+       virtual int unget(UKBYTE b) = 0;
+
+       virtual int getNextW(UKWORD &w) = 0;
+       virtual int peekNextW(UKWORD &w) = 0;
+
+       virtual int getNextDW(UKDWORD &dw) = 0;
+
+       virtual int bookmark() //no support for bookmark by default
+       {
+               return 0;
+       }
+
+       virtual int gotoBookmark()
+       {
+               return 0;
+       }
+
+       virtual int eos() = 0; //end of stream
+       virtual int close() = 0;
+};
+
+//----------------------------------------------------
+class ByteOutStream: public ByteStream
+{
+public:
+       virtual int putB(UKBYTE b) = 0;
+       virtual int putW(UKWORD w) = 0;
+       virtual int puts(const char *s, int size = -1) = 0; // write an 8-bit string
+       virtual int isOK() = 0;// get current stream state
+};
+
+//----------------------------------------------------
+class StringBIStream : public ByteInStream
+{
+protected:
+       int m_eos;
+       UKBYTE *m_data, *m_current;
+       int m_len, m_left;
+
+       struct {
+               int eos;
+               UKBYTE *data, *current;
+               int len, left;
+       } m_bookmark;
+
+       int m_didBookmark;
+               
+public:
+       StringBIStream(UKBYTE *data, int len, int elementSize = 1);
+       virtual int getNext(UKBYTE &b);
+       virtual int peekNext(UKBYTE &b);
+       virtual int unget(UKBYTE b);
+
+       virtual int getNextW(UKWORD &w);
+       virtual int peekNextW(UKWORD &w);
+
+       virtual int getNextDW(UKDWORD &dw);
+
+    virtual int eos(); //end of stream
+       virtual int close();
+
+       virtual int bookmark();
+       virtual int gotoBookmark();
+
+       void reopen();
+       int left() {
+               return m_left;
+       }
+};
+
+//----------------------------------------------------
+class FileBIStream : public ByteInStream
+{
+protected:
+       FILE *m_file;
+       int m_bufSize;
+       char *m_buf;
+       int m_own;
+       int m_didBookmark;
+
+       struct {
+               long pos;
+       } m_bookmark;
+
+       //some systems don't have wide char IO functions
+       //we have to use this variables to implement that
+       UKBYTE m_readByte; 
+       int m_readAhead;
+       int m_lastIsAhead;
+
+public:
+
+       FileBIStream(int bufsize = 8192, char *buf = NULL);
+//     FileBIStream(char *fileName, int bufsize = 8192, void *buf = NULL);
+
+       int open(const char *fileName);
+       void attach(FILE *f);
+       virtual int close();
+
+       virtual int getNext(UKBYTE &b);
+       virtual int peekNext(UKBYTE &b);
+       virtual int unget(UKBYTE b);
+
+       virtual int getNextW(UKWORD &w);
+       virtual int peekNextW(UKWORD &w);
+
+    virtual int getNextDW(UKDWORD &dw);
+
+    virtual int eos(); //end of stream
+
+       virtual int bookmark();
+       virtual int gotoBookmark();
+
+       virtual ~FileBIStream();
+};
+
+
+//----------------------------------------------------
+class StringBOStream : public ByteOutStream
+{
+protected:
+       UKBYTE *m_buf, *m_current;
+       int m_out;
+       int m_len;
+       int m_bad;
+public:
+       StringBOStream(UKBYTE *buf, int len);
+       virtual int putB(UKBYTE b);
+       virtual int putW(UKWORD w);
+       virtual int puts(const char *s, int size = -1);
+       virtual int isOK(); // get current stream state
+
+       virtual int close()     
+       {
+               return 1;
+       };
+
+       void reopen();
+       int getOutBytes() {
+               return m_out;
+       }
+};
+
+//----------------------------------------------------
+class FileBOStream : public ByteOutStream
+{
+protected:
+       FILE *m_file;
+       int m_bufSize;
+       char *m_buf;
+       int m_own;
+       int m_bad;
+
+public:
+       FileBOStream(int bufsize = 8192, char *buf = NULL);
+//     FileBOStream(char *fileName, int bufsize = 8192, void *buf = NULL);
+
+       int open(const char *fileName);
+       void attach(FILE *);
+       virtual int close();
+
+       virtual int putB(UKBYTE b);
+       virtual int putW(UKWORD w);
+       virtual int puts(const char *s, int size = -1);
+       virtual int isOK(); // get current stream state
+       virtual ~FileBOStream();
+};
+
+
+#endif
diff --git a/ukengine/charset.cpp b/ukengine/charset.cpp
new file mode 100644 (file)
index 0000000..9c88c20
--- /dev/null
@@ -0,0 +1,1304 @@
+// -*- coding:unix; mode:c++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
+/*------------------------------------------------------------------------------
+VnConv: Vietnamese Encoding Converter Library
+UniKey Project: http://unikey.sourceforge.net
+Copyleft (C) 1998-2002 Pham Kim Long
+Contact: longp@cslab.felk.cvut.cz
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+--------------------------------------------------------------------------------*/
+
+#include <stddef.h>
+#include <search.h>
+#include <memory.h>
+#include <ctype.h>
+#include <stdlib.h>
+
+#include "charset.h"
+#include "data.h"
+
+int LoVowel['z'-'a'+1];
+int HiVowel['Z'-'A'+1];
+
+#define IS_VOWEL(x) ((x >= 'a' && x <= 'z' && LoVowel[x-'a']) || (x >= 'A' && x <= 'Z' && HiVowel[x-'A']))
+
+SingleByteCharset *SgCharsets[CONV_TOTAL_SINGLE_CHARSETS];
+DoubleByteCharset *DbCharsets[CONV_TOTAL_DOUBLE_CHARSETS];
+
+DllExport CVnCharsetLib VnCharsetLibObj;
+
+//////////////////////////////////////////////////////
+// Generic VnCharset class
+//////////////////////////////////////////////////////
+int VnCharset::elementSize()
+{
+    return 1;
+}
+
+//-------------------------------------------
+int VnInternalCharset::nextInput(ByteInStream & is, StdVnChar & stdChar, int & bytesRead)
+{
+    if (!is.getNextDW(stdChar)) {
+        bytesRead = 0;
+        return 0;
+    }
+    bytesRead = sizeof(UKDWORD);
+    return 1;
+}
+
+//-------------------------------------------
+int VnInternalCharset::putChar(ByteOutStream & os, StdVnChar stdChar, int & outLen)
+{
+  outLen = sizeof(StdVnChar);
+  UKWORD *pWord = (UKWORD *)&stdChar;
+  os.putW(*pWord);
+  pWord++;
+  return os.putW(*pWord);
+}
+
+//-------------------------------------------
+int VnInternalCharset::elementSize()
+{
+    return 4;
+}
+
+//-------------------------------------------
+SingleByteCharset::SingleByteCharset(unsigned char * vnChars)
+{
+       int i;
+       m_vnChars = vnChars;
+       memset(m_stdMap, 0, 256*sizeof(UKWORD));
+       for (i=0; i<TOTAL_VNCHARS; i++) {
+               if (vnChars[i] != 0 && (i==TOTAL_VNCHARS-1 || vnChars[i] != vnChars[i+1]))
+                       m_stdMap[vnChars[i]] = i + 1;
+       }
+}
+
+//-------------------------------------------
+int SingleByteCharset::nextInput(ByteInStream & is, StdVnChar & stdChar, int & bytesRead)
+{
+       unsigned char ch;
+       if (!is.getNext(ch)) {
+               bytesRead = 0;
+               return 0;
+       }
+
+       stdChar = (m_stdMap[ch])? (VnStdCharOffset + m_stdMap[ch] - 1) : ch;
+       bytesRead = 1;
+       return 1;
+}
+
+
+//-------------------------------------------
+int SingleByteCharset::putChar(ByteOutStream & os, StdVnChar stdChar, int & outLen)
+{
+       int ret;
+       unsigned char ch;
+       if (stdChar >= VnStdCharOffset) {
+               outLen = 1;
+               ch = m_vnChars[stdChar - VnStdCharOffset];
+               if (ch == 0)
+                       ch = (stdChar == StdStartQuote)? PadStartQuote :
+                         ((stdChar == StdEndQuote)? PadEndQuote :
+                                  ((stdChar == StdEllipsis)? PadEllipsis: PadChar) );
+               ret = os.putB(ch);
+       }
+       else {
+               if (stdChar > 255 || m_stdMap[stdChar]) { 
+                       //this character is missing in the charset
+                       // output padding character
+                       outLen = 1;
+                       ret = os.putB(PadChar);
+               }
+               else {
+                       outLen = 1;
+                       ret = os.putB((UKBYTE)stdChar);
+               }
+       }
+       return ret;
+}
+
+//-------------------------------------------
+int wideCharCompare(const void *ele1, const void *ele2)
+{
+       UKWORD ch1 = LOWORD(*((UKDWORD *)ele1));
+       UKWORD ch2 = LOWORD(*((UKDWORD *)ele2));
+       return (ch1 == ch2)? 0 : ((ch1 > ch2)? 1 : -1);
+}
+
+//-------------------------------------------
+UnicodeCharset::UnicodeCharset(UnicodeChar *vnChars)
+{
+       UKDWORD i;
+       m_toUnicode = vnChars;
+       for (i=0; i<TOTAL_VNCHARS; i++)
+               m_vnChars[i] = (i << 16) + vnChars[i]; // high word is used for index
+       qsort(m_vnChars, TOTAL_VNCHARS, sizeof(UKDWORD), wideCharCompare);
+}
+
+//-------------------------------------------
+int UnicodeCharset::nextInput(ByteInStream & is, StdVnChar & stdChar, int & bytesRead)
+{
+       UnicodeChar uniCh;
+       if (!is.getNextW(uniCh)) {
+               bytesRead = 0;
+               return 0;
+       }
+       bytesRead = sizeof(UnicodeChar);
+       UKDWORD key = uniCh;
+       UKDWORD *pChar = (UKDWORD *)bsearch(&key, m_vnChars, TOTAL_VNCHARS, sizeof(UKDWORD), wideCharCompare);
+       if (pChar)
+               stdChar = VnStdCharOffset + HIWORD(*pChar);
+       else
+               stdChar = uniCh;
+       return 1;
+}
+
+//-------------------------------------------
+int UnicodeCharset::putChar(ByteOutStream & os, StdVnChar stdChar, int & outLen)
+{
+       outLen = sizeof(UnicodeChar);
+       return os.putW((stdChar >= VnStdCharOffset)? 
+                              m_toUnicode[stdChar-VnStdCharOffset] : (UnicodeChar)stdChar);
+}
+
+//-------------------------------------------
+int UnicodeCharset::elementSize()
+{
+    return 2;
+}
+
+////////////////////////////////////////
+// Unicode decomposed
+////////////////////////////////////////
+//-------------------------------------------
+int uniCompInfoCompare(const void *ele1, const void *ele2)
+{
+       UKDWORD ch1 = ((UniCompCharInfo *)ele1)->compChar;
+       UKDWORD ch2 = ((UniCompCharInfo *)ele2)->compChar;
+       return (ch1 == ch2)? 0 : ((ch1 > ch2)? 1 : -1);
+}
+
+UnicodeCompCharset::UnicodeCompCharset(UnicodeChar *uniChars, UKDWORD *uniCompChars)
+{
+  int i,k;
+       m_uniCompChars = uniCompChars;
+       m_totalChars = 0;
+       for (i=0; i<TOTAL_VNCHARS; i++) {
+               m_info[i].compChar = uniCompChars[i];
+               m_info[i].stdIndex = i;
+               m_totalChars++;
+       }
+
+       for (k=0, i=TOTAL_VNCHARS; k<TOTAL_VNCHARS; k++)
+               if (uniChars[k] != uniCompChars[k]) {
+                       m_info[i].compChar = uniChars[k];
+                       m_info[i].stdIndex = k;
+                       m_totalChars++;
+                       i++;
+               }
+
+       qsort(m_info, m_totalChars, sizeof(UniCompCharInfo), uniCompInfoCompare);
+}
+
+//---------------------------------------------
+int UnicodeCompCharset::nextInput(ByteInStream & is, StdVnChar & stdChar, int & bytesRead)
+{
+       // read first char
+
+       UniCompCharInfo key;
+       UKWORD w;
+       if (!is.getNextW(w)) {
+               bytesRead = 0;
+               return 0;
+       }
+       key.compChar = w;
+       bytesRead = 2;
+
+       UniCompCharInfo *pInfo = (UniCompCharInfo *)bsearch(&key, m_info, m_totalChars, 
+                                                               sizeof(UniCompCharInfo), uniCompInfoCompare);
+       if (!pInfo)
+               stdChar = key.compChar;
+       else {
+               stdChar = pInfo->stdIndex + VnStdCharOffset;
+               if (is.peekNextW(w)) {
+                       UKDWORD hi = w;
+                       if (hi > 0) {
+                               key.compChar += hi << 16;
+                               pInfo = (UniCompCharInfo *)bsearch(&key, m_info, m_totalChars,
+                                                      sizeof(UniCompCharInfo), uniCompInfoCompare);
+                               if (pInfo) {
+                                       stdChar = pInfo->stdIndex + VnStdCharOffset;
+                                       bytesRead += 2;
+                                       is.getNextW(w);
+                               }
+                       }
+               }
+       }
+       return 1;
+}
+
+//---------------------------------------------
+int UnicodeCompCharset::putChar(ByteOutStream & os, StdVnChar stdChar, int & outLen)
+{
+       int ret;
+       if (stdChar     >= VnStdCharOffset) {
+               UKDWORD uniCompCh = m_uniCompChars[stdChar-VnStdCharOffset];
+               UKWORD lo = LOWORD(uniCompCh);
+               UKWORD hi = HIWORD(uniCompCh);
+               outLen = 2;
+               ret = os.putW(lo);
+               if (hi > 0) {
+                       outLen += 2;
+                       ret = os.putW(hi);
+               }
+       }
+       else {
+               outLen = 2;
+               ret = os.putW((UKWORD)stdChar);
+       }
+       return ret;
+}
+
+//-------------------------------------------
+int UnicodeCompCharset::elementSize()
+{
+    return 2;
+}
+
+////////////////////////////////
+// Unicode UTF-8              //
+////////////////////////////////
+int UnicodeUTF8Charset::nextInput(ByteInStream & is, StdVnChar & stdChar, int & bytesRead)
+{
+       UKWORD w1, w2, w3;
+       UKBYTE first, second, third;
+       UnicodeChar uniCh;
+
+       bytesRead = 0;
+       if (!is.getNext(first))
+               return 0;
+       bytesRead = 1;
+
+       if (first < 0x80) 
+               uniCh = first; // 1-byte sequence
+       else if ((first & 0xE0) == 0xC0) {
+               //2-byte sequence
+               if (!is.peekNext(second))
+                       return 0;
+               if ((second & 0xC0) != 0x80) {
+                       stdChar = INVALID_STD_CHAR;
+                       return 1;
+               }
+               is.getNext(second);
+               bytesRead = 2;
+               w1 = first;
+               w2 = second;
+               uniCh = ((w1 & 0x001F) << 6) | (w2 & 0x3F);
+       }
+       else if ((first & 0xF0) == 0xE0) {
+               //3-byte sequence
+               if (!is.peekNext(second))
+                       return 0;
+               if ((second & 0xC0) != 0x80) {
+                       stdChar = INVALID_STD_CHAR;
+                       return 1;
+               }
+               is.getNext(second);
+               bytesRead = 2;
+               if (!is.peekNext(third))
+                       return 0;
+               if ((third & 0xC0) != 0x80) {
+                       stdChar = INVALID_STD_CHAR;
+                       return 1;
+               }
+               is.getNext(third);
+               bytesRead = 3;
+               w1 = first;
+               w2 = second;
+               w3 = third;
+               uniCh = ((w1 & 0x000F) << 12) | ((w2 & 0x003F) << 6) | (w3 & 0x003F);
+       }
+       else {
+               stdChar = INVALID_STD_CHAR;
+               return 1;
+       }
+
+       // translate to StdVnChar
+       UKDWORD key = uniCh;
+       UKDWORD *pChar = (UKDWORD *)bsearch(&key, m_vnChars, TOTAL_VNCHARS, sizeof(UKDWORD), wideCharCompare);
+       if (pChar)
+               stdChar = VnStdCharOffset + HIWORD(*pChar);
+       else stdChar = uniCh;
+       return 1;
+}
+
+//-------------------------------------------
+int UnicodeUTF8Charset::putChar(ByteOutStream & os, StdVnChar stdChar, int & outLen)
+{
+       UnicodeChar uChar = (stdChar < VnStdCharOffset)? 
+                               (UnicodeChar)stdChar : m_toUnicode[stdChar-VnStdCharOffset];
+       int ret;
+       if (uChar < 0x0080) {
+               outLen = 1;
+               ret = os.putB((UKBYTE)uChar);
+       } else if (uChar < 0x0800) {
+               outLen = 2;
+               os.putB(0xC0 | (UKBYTE)(uChar >> 6));
+               ret = os.putB(0x80 | (UKBYTE)(uChar & 0x003F));
+       } else {
+               outLen = 3;
+               os.putB(0xE0 | (UKBYTE)(uChar >> 12));
+               os.putB(0x80 | (UKBYTE)((uChar >> 6) & 0x003F));
+               ret = os.putB(0x80 | (UKBYTE)(uChar & 0x003F));
+       }
+       return ret;
+}
+
+////////////////////////////////////////
+// Unicode character reference &#D;   //
+////////////////////////////////////////
+int hexDigitValue(unsigned char digit)
+{
+       if (digit >= 'a' && digit <= 'f')
+               return digit-'a'+10;
+       if (digit >= 'A' && digit <= 'F')
+               return digit-'A'+10;
+       if (digit >= '0' && digit <= '9')
+               return digit-'0';
+       return 0;
+}
+
+
+//--------------------------------------
+int UnicodeRefCharset::nextInput(ByteInStream & is, StdVnChar & stdChar, int & bytesRead)
+{
+       unsigned char ch;
+       UnicodeChar uniCh;
+       bytesRead = 0;
+       if (!is.getNext(ch))
+               return 0;
+       bytesRead = 1;
+       uniCh = ch;
+       if (ch == '&') {
+               if (is.peekNext(ch) && ch == '#') {
+                       is.getNext(ch);
+                       bytesRead++;
+                       if (!is.eos()) {
+                               is.peekNext(ch);
+                               if (ch != 'x' && ch != 'X') {
+                                       UKWORD code = 0;
+                                       int digits = 0;
+                                       while (is.peekNext(ch) && isdigit(ch) && digits < 5) {
+                                               is.getNext(ch);
+                                               bytesRead++;
+                                               code = code*10 + (ch - '0');
+                                               digits++;
+                                       }
+                                       if (is.peekNext(ch) && ch == ';') {
+                                               is.getNext(ch);
+                                               bytesRead++;
+                                               uniCh = code;
+                                       }
+                               }
+                               else {
+                                       is.getNext(ch);
+                                       bytesRead++;
+                                       UKWORD code = 0;
+                                       int digits = 0;
+                                       while (is.peekNext(ch) && isxdigit(ch) && digits < 4) {
+                                               is.getNext(ch);
+                                               bytesRead++;
+                                               code = (code << 4) + hexDigitValue(ch);
+                                               digits++;
+                                       }
+                                       if (is.peekNext(ch) && ch == ';') {
+                                               is.getNext(ch);
+                                               bytesRead++;
+                                               uniCh = code;
+                                       }
+                               } // hex digits
+                       }
+               }
+       }
+
+       // translate to StdVnChar
+       UKDWORD key = uniCh;
+       UKDWORD *pChar = (UKDWORD *)bsearch(&key, m_vnChars, TOTAL_VNCHARS, sizeof(UKDWORD), wideCharCompare);
+       if (pChar)
+               stdChar = VnStdCharOffset + HIWORD(*pChar);
+       else stdChar = uniCh;
+       return 1;
+}
+
+
+//--------------------------------
+int UnicodeRefCharset::putChar(ByteOutStream & os, StdVnChar stdChar, int & outLen)
+{
+       UnicodeChar uChar = (stdChar < VnStdCharOffset)? 
+                               (UnicodeChar)stdChar : m_toUnicode[stdChar-VnStdCharOffset];
+       int ret;
+       if (uChar < 128) {
+               outLen = 1;
+               ret = os.putB((UKBYTE)uChar);
+       }
+       else {
+               outLen = 2;
+               os.putB((UKBYTE)'&');
+               os.putB((UKBYTE)'#');
+
+               int i, digit, prev, base;
+               prev = 0;
+               base = 10000;
+               for (i=0; i < 5; i++) {
+                       digit = uChar / base;
+                       if (digit || prev) {
+                               prev = 1;
+                               outLen++;
+                               os.putB('0' + (unsigned char)digit);
+                       }
+                       uChar %= base;
+                       base /= 10;
+               }
+               ret = os.putB((UKBYTE)';');
+               outLen++;
+       }
+       return ret;
+}
+
+#define HEX_DIGIT(x) ((x < 10)? ('0'+x) : ('A'+x-10))
+
+//--------------------------------
+int UnicodeHexCharset::putChar(ByteOutStream & os, StdVnChar stdChar, int & outLen)
+{
+       UnicodeChar uChar = (stdChar < VnStdCharOffset)? 
+                               (UnicodeChar)stdChar : m_toUnicode[stdChar-VnStdCharOffset];
+       int ret;
+       if (uChar < 256) {
+               outLen = 1;
+               ret = os.putB((UKBYTE)uChar);
+       }
+       else {
+               outLen = 3;
+               os.putB('&');
+               os.putB('#');
+               os.putB('x');
+
+               int i, digit;
+               int prev = 0;
+               int shifts = 12;
+
+               for (i=0; i < 4; i++) {
+                       digit = ((uChar >> shifts) & 0x000F);
+                       if (digit > 0 || prev) {
+                               prev = 1;
+                               outLen++;
+                               os.putB((UKBYTE)HEX_DIGIT(digit));
+                       }
+                       shifts -= 4;
+               }
+               ret = os.putB(';');
+               outLen++;
+       }
+       return ret;
+}
+
+
+/////////////////////////////////
+// Class UnicodeCStringCharset  /
+/////////////////////////////////
+void UnicodeCStringCharset::startInput()
+{
+       m_prevIsHex = 0;
+}
+
+//----------------------------------------
+int UnicodeCStringCharset::nextInput(ByteInStream & is, StdVnChar & stdChar, int & bytesRead)
+{
+       unsigned char ch;
+       UnicodeChar uniCh;
+       bytesRead = 0;
+       if (!is.getNext(ch))
+               return 0;
+       bytesRead = 1;
+       uniCh = ch;
+       if (ch == '\\') {
+               if (is.peekNext(ch) && (ch=='x' || ch=='X')) {
+                       is.getNext(ch);
+                       bytesRead++;
+                       UKWORD code = 0;
+                       int digits = 0;
+                       while (is.peekNext(ch) && isxdigit(ch) && digits < 4) {
+                               is.getNext(ch);
+                               bytesRead++;
+                               code = (code << 4) + hexDigitValue(ch);
+                               digits++;
+                       }
+                       uniCh = code;
+               }
+       }
+
+       // translate to StdVnChar
+       UKDWORD key = uniCh;
+       UKDWORD *pChar = (UKDWORD *)bsearch(&key, m_vnChars, TOTAL_VNCHARS, sizeof(UKDWORD), wideCharCompare);
+       if (pChar)
+               stdChar = VnStdCharOffset + HIWORD(*pChar);
+       else stdChar = uniCh;
+       return 1;
+}
+
+//------------------------------------
+int UnicodeCStringCharset::putChar(ByteOutStream & os, StdVnChar stdChar, int & outLen)
+{
+       UnicodeChar uChar = (stdChar < VnStdCharOffset)? 
+                               (UnicodeChar)stdChar : m_toUnicode[stdChar-VnStdCharOffset];
+       int ret;
+       if (uChar < 128 && !isxdigit(uChar) && uChar != 'x' && uChar != 'X') {
+               outLen = 1;
+               ret = os.putB((UKBYTE)uChar);
+       }
+       else {
+               outLen = 2;
+               os.putB('\\');
+               os.putB('x');
+
+               int i, digit;
+               int prev = 0;
+               int shifts = 12;
+
+               for (i=0; i < 4; i++) {
+                       digit = ((uChar >> shifts) & 0x000F);
+                       if (digit > 0 || prev) {
+                               prev = 1;
+                               outLen++;
+                               os.putB((UKBYTE)HEX_DIGIT(digit));
+                       }
+                       shifts -= 4;
+               }
+               ret = os.isOK();
+               m_prevIsHex = 1;
+       }
+       return ret;
+}
+
+/////////////////////////////////
+// Double-byte charsets        //
+/////////////////////////////////
+DoubleByteCharset::DoubleByteCharset(UKWORD *vnChars)
+{
+       m_toDoubleChar = vnChars;
+       memset(m_stdMap, 0, 256*sizeof(UKWORD));
+       for (int i=0; i<TOTAL_VNCHARS; i++) {
+               if (vnChars[i] >> 8) // a 2-byte character
+                       m_stdMap[vnChars[i] >> 8] = 0xFFFF; //INVALID_STD_CHAR;
+               else if (m_stdMap[vnChars[i]] == 0)
+                       m_stdMap[vnChars[i]] = i+1;
+               m_vnChars[i] = (i << 16) + vnChars[i]; // high word is used for StdChar index
+       }
+       qsort(m_vnChars, TOTAL_VNCHARS, sizeof(UKDWORD), wideCharCompare);
+}
+
+//---------------------------------------------
+int DoubleByteCharset::nextInput(ByteInStream & is, StdVnChar & stdChar, int & bytesRead)
+{
+       unsigned char ch;
+
+       // read first byte
+       bytesRead = 0;
+       if (!is.getNext(ch))
+               return 0;
+       bytesRead = 1;
+       stdChar = m_stdMap[ch];
+       if (stdChar == 0)
+               stdChar = ch;
+       else if (stdChar == 0xFFFF)
+               stdChar = INVALID_STD_CHAR;
+       else {
+               stdChar += VnStdCharOffset - 1;
+               UKBYTE hi;
+               if (is.peekNext(hi) && hi > 0) {
+                       //test if a double-byte character is encountered
+                       UKDWORD key = MAKEWORD(ch,hi);
+                       UKDWORD *pChar = (UKDWORD *)bsearch(&key, m_vnChars, TOTAL_VNCHARS, sizeof(UKDWORD), wideCharCompare);
+                       if (pChar) {
+                               stdChar = VnStdCharOffset + HIWORD(*pChar);
+                               bytesRead = 2;
+                               is.getNext(hi);
+                       }
+               }
+       }
+       return 1;
+}
+
+//---------------------------------------------
+int DoubleByteCharset::putChar(ByteOutStream & os, StdVnChar stdChar, int & outLen)
+{
+       int ret;
+       if (stdChar     >= VnStdCharOffset) {
+               UKWORD wCh = m_toDoubleChar[stdChar-VnStdCharOffset];
+
+               if (wCh & 0xFF00) {
+                       outLen = 2;
+                       os.putB((UKBYTE)(wCh & 0x00FF));
+                       ret = os.putB((UKBYTE)(wCh >> 8));
+               }
+               else {
+                       unsigned char b = (unsigned char)wCh;
+                       if (m_stdMap[b] == 0xFFFF)
+                               b = PadChar;
+                       outLen = 1;
+                       ret = os.putB(b);
+               }
+/*
+               outLen = 1;
+               ret = os.putB((UKBYTE)(wCh & 0x00FF));
+               if (wCh & 0xFF00) {
+                       outLen = 2;
+                       ret = os.putB((UKBYTE)(wCh >> 8));
+               }
+*/
+       }
+       else {
+               if (stdChar > 255 || m_stdMap[stdChar]) {
+                       outLen = 1;
+                       ret = os.putB((UKBYTE)PadChar);
+               }
+               else {
+                       outLen = 1;
+                       ret = os.putB((UKBYTE)stdChar);
+               }
+       }
+       return ret;
+}
+
+/////////////////////////////////////////////
+// Class: VIQRCharset                      //
+/////////////////////////////////////////////
+
+unsigned char VIQRTones[] = {'\'','`','?','~','.'};
+
+const char *VIQREscapes[] = {
+       "://",
+       "/",
+       "@",
+       "mailto:",
+       "email:",
+       "news:",
+       "www",
+       "ftp"
+};
+
+const int VIQREscCount = sizeof(VIQREscapes) / sizeof(char*);
+
+VIQRCharset::VIQRCharset(UKDWORD *vnChars)
+{
+       memset(m_stdMap, 0, 256*sizeof(UKWORD));
+       int i;
+       UKDWORD dw;
+       m_vnChars = vnChars;
+       for (i=0; i<TOTAL_VNCHARS; i++) {
+               dw = m_vnChars[i];
+               if (!(dw & 0xffffff00)) { //single byte
+                       //ch = (unsigned char)(dw & 0xff);
+                       m_stdMap[dw] = i+256;
+               }
+       }
+
+       // set offset from base characters according to tone marks
+       m_stdMap[(unsigned char)'\''] = 2;
+       m_stdMap[(unsigned char)'`'] = 4;
+       m_stdMap[(unsigned char)'?'] = 6;
+       m_stdMap[(unsigned char)'~'] = 8;
+       m_stdMap[(unsigned char)'.'] = 10;
+       m_stdMap[(unsigned char)'^'] = 12;
+
+       m_stdMap[(unsigned char)'('] = 24;
+       m_stdMap[(unsigned char)'+'] = 26;
+       m_stdMap[(unsigned char)'*'] = 26;
+}
+
+//---------------------------------------------------
+void VIQRCharset::startInput()
+{
+       m_suspicious = 0;
+       m_atWordBeginning = 1;
+       m_gotTone = 0;
+       m_escAll = 0;
+       if (VnCharsetLibObj.m_options.viqrEsc)
+               VnCharsetLibObj.m_VIQREscPatterns.reset();
+}
+
+//---------------------------------------------------
+int VIQRCharset::nextInput(ByteInStream & is, StdVnChar & stdChar, int & bytesRead)
+{
+       unsigned char ch1;
+       bytesRead = 0;
+
+       if (!is.getNext(ch1))
+               return 0;
+       bytesRead = 1;
+       stdChar = m_stdMap[ch1];
+
+       if (VnCharsetLibObj.m_options.viqrEsc) {
+               if (VnCharsetLibObj.m_VIQREscPatterns.foundAtNextChar(ch1)!=-1) {
+                       m_escAll = 1;
+               }
+       }
+
+       if (m_escAll && (ch1==' ' || ch1=='\t' || ch1=='\r' || ch1=='\n'))
+               m_escAll = 0;
+       
+       if (ch1 == '\\') {
+               // ecape character , try to read next
+               if (!is.getNext(ch1)) {
+                       bytesRead++;
+                       stdChar = m_stdMap[ch1];
+               }
+       }
+
+       if (stdChar < 256) {
+               stdChar = ch1;
+       }
+       else if (!m_escAll && !is.eos()) {
+               // try to read the next byte
+               unsigned char ch2;
+               is.peekNext(ch2);
+               unsigned char upper = toupper(ch1);
+        if ((!VnCharsetLibObj.m_options.smartViqr || m_atWordBeginning) &&
+             upper == 'D' && (ch2 == 'd' || ch2 == 'D')) 
+        {
+                       is.getNext(ch2);
+                       bytesRead++;
+                       stdChar += 2; // dd is 2 positions after d.
+               }
+               else {
+                       StdVnChar index = m_stdMap[ch2];
+
+                       int cond;
+                       if (m_suspicious) {
+                               cond = IS_VOWEL(ch1) &&
+                            ( index == 2 || index == 4 || index == 8 || //not accepting ? . in suspicious mode
+                                  (index == 12 &&  (upper == 'A' || upper == 'E' || upper == 'O')) ||
+                                  (m_stdMap[ch2] == 24 && upper== 'A') ||
+                                  (m_stdMap[ch2] == 26 && (upper == 'O' || upper == 'U')) );
+                               if (cond)
+                                       m_suspicious = 0;
+                       }
+                       else
+                               cond = IS_VOWEL(ch1) &&
+                                 ((index <= 10  && index > 0 && (!m_gotTone || (index!=6 && index!=10)) ) ||
+                                  (index == 12 &&  (upper == 'A' || upper == 'E' || upper == 'O')) ||
+                                  (m_stdMap[ch2] == 24 && upper== 'A') ||
+                                  (m_stdMap[ch2] == 26 && (upper == 'O' || upper == 'U')) );
+
+                       if (cond) {
+                               if (index > 0)
+                                       m_gotTone = 1; //we have a tone/breve/hook in the current word
+
+                               // ok, take this byte
+                               is.getNext(ch2);
+                               bytesRead++;
+                               int offset = m_stdMap[ch2];
+                               if (offset == 26) offset = 24;
+                               if (offset == 24 && (ch1 == 'u' || ch1 == 'U'))
+                                       offset = 12;
+                               stdChar += offset;
+                               // check next byte
+                               if (is.peekNext(ch2)) {
+                                       if (index > 10 && m_stdMap[ch2] > 0 && m_stdMap[ch2] <= 10) {
+                                               // ok, take one more byte
+                                               is.getNext(ch2);
+                                               bytesRead++;
+                                               stdChar += m_stdMap[ch2];
+                                       }
+                               }
+                       }
+               }
+       }
+       m_atWordBeginning = (stdChar < 256);
+       if (stdChar < 256) {
+               m_gotTone = 0; //reset this flag because we are at the beginning of a new word
+       }
+
+       // adjust stdChar
+       if (stdChar >= 256)
+               stdChar += VnStdCharOffset - 256;
+       return 1;
+}
+
+//---------------------------------------------------
+void VIQRCharset::startOutput()
+{
+       m_escapeBowl = 0;
+       m_escapeRoof = 0;
+       m_escapeHook = 0;
+       m_escapeTone = 0;
+       m_noOutEsc = 0;
+       VnCharsetLibObj.m_VIQROutEscPatterns.reset();
+}
+
+//---------------------------------------------------
+int VIQRCharset::putChar(ByteOutStream & os, StdVnChar stdChar, int & outLen)
+{
+       int ret;
+       UKBYTE b;
+       if (stdChar >= VnStdCharOffset) {
+               outLen = 1;
+               UKDWORD dw = m_vnChars[stdChar-VnStdCharOffset];
+
+               unsigned char first = (unsigned char)dw;
+               unsigned char firstUpper = toupper(first);
+
+               b = (UKBYTE)dw;
+               ret = os.putB(b);
+               if (VnCharsetLibObj.m_VIQROutEscPatterns.foundAtNextChar(b) != -1)
+                 m_noOutEsc = 1;
+
+               if (m_noOutEsc && (b==' ' || b=='\t' || b=='\r' || b=='\n'))
+                 m_noOutEsc = 0;
+
+               if (dw & 0x0000FF00) {
+                       // second byte is present
+                       unsigned char second = (UKBYTE)(dw >> 8);
+                       outLen++;
+                       ret = os.putB(second);
+
+                       if (dw & 0x00FF0000) {
+                               //third byte is present
+                               outLen++;
+                               ret = os.putB((UKBYTE)(dw >> 16));
+                               m_escapeTone = 0;
+                       }
+                       else {
+                               UKWORD index = m_stdMap[second];
+                               m_escapeTone = (index == 12 || index == 24 || index == 26);
+                       }
+
+                        VnCharsetLibObj.m_VIQROutEscPatterns.reset();
+
+                       m_escapeBowl = 0;
+                       m_escapeHook = 0;
+                       m_escapeRoof = 0;
+               }
+               else {
+                       m_escapeTone = IS_VOWEL(first);
+                       m_escapeBowl = (firstUpper == 'A');
+                       m_escapeHook = (firstUpper == 'U' || firstUpper == 'O');
+                       m_escapeRoof = (firstUpper == 'A' || firstUpper == 'E' || firstUpper == 'O');
+               }
+       }
+       else {
+               if (stdChar > 255) {
+                       outLen = 1;
+                       ret = os.putB((UKBYTE)PadChar);
+                        if (VnCharsetLibObj.m_VIQROutEscPatterns.foundAtNextChar((UKBYTE)PadChar) != -1)
+                         m_noOutEsc = 1;
+               }
+               else {
+                       outLen = 1;
+                       UKWORD index = m_stdMap[stdChar];
+                       if (!VnCharsetLibObj.m_options.viqrMixed && !m_noOutEsc &&
+                                  (stdChar=='\\' || 
+                                       (index > 0 && index <= 10 && m_escapeTone) ||
+                                       (index == 12 && m_escapeRoof) ||
+                                       (index == 24 && m_escapeBowl) ||
+                                       (index == 26 && m_escapeHook))) {
+                               //(m_stdMap[stdChar] > 0 && m_stdMap[stdChar] <= 26)) {
+                               // tone mark, needs an escape character
+                               outLen++;
+                               ret = os.putB('\\');
+                               if (VnCharsetLibObj.m_VIQROutEscPatterns.foundAtNextChar('\\') != -1)
+                                 m_noOutEsc = 1;
+                       }
+                       b = (UKBYTE)stdChar;
+                       ret = os.putB(b);
+                       if (VnCharsetLibObj.m_VIQROutEscPatterns.foundAtNextChar(b) != -1)
+                         m_noOutEsc = 1;
+                       if (m_noOutEsc && (b==' ' || b=='\t' || b=='\r' || b=='\n'))
+                         m_noOutEsc = 0;
+               }
+               // reset escape marks
+               m_escapeBowl = 0;
+               m_escapeRoof = 0;
+               m_escapeHook = 0;
+               m_escapeTone = 0;
+       }
+       return ret;
+}
+
+/////////////////////////////////////////////
+// Class: UTF8VIQRCharset                  //
+/////////////////////////////////////////////
+
+//-----------------------------------------
+UTF8VIQRCharset::UTF8VIQRCharset(UnicodeUTF8Charset *pUtf, VIQRCharset *pViqr)
+{
+  m_pUtf = pUtf;
+  m_pViqr = pViqr;
+}
+
+//-----------------------------------------
+void UTF8VIQRCharset::startInput()
+{
+  m_pUtf->startInput();
+  m_pViqr->startInput();
+}
+
+//-----------------------------------------
+void UTF8VIQRCharset::startOutput()
+{
+  m_pUtf->startOutput();
+  m_pViqr->startOutput();
+}
+
+//-----------------------------------------
+int UTF8VIQRCharset::nextInput(ByteInStream & is, StdVnChar & stdChar, int & bytesRead)
+{
+       UKBYTE ch;
+
+       if (!is.peekNext(ch))
+               return 0;
+
+       if (ch > 0xBF && ch < 0xFE) {
+               m_pViqr->startInput(); // just to reset the VIQR object state
+               m_pViqr->m_suspicious = 1;
+               return m_pUtf->nextInput(is, stdChar, bytesRead);
+       }
+
+       return m_pViqr->nextInput(is, stdChar, bytesRead);
+}
+
+//-----------------------------------------
+int UTF8VIQRCharset::putChar(ByteOutStream & os, StdVnChar stdChar, int & outLen)
+{
+  return m_pViqr->putChar(os, stdChar, outLen);
+}
+
+
+//-----------------------------------------
+CVnCharsetLib::CVnCharsetLib()
+{
+       unsigned char ch;
+       for (ch = 'a'; ch < 'z'; ch++)
+               LoVowel[ch-'a'] = 0;
+       LoVowel['a'-'a'] = 1;
+       LoVowel['e'-'a'] = 1;
+       LoVowel['i'-'a'] = 1;
+       LoVowel['o'-'a'] = 1;
+       LoVowel['u'-'a'] = 1;
+       LoVowel['y'-'a'] = 1;
+
+       for (ch = 'A'; ch < 'Z'; ch++)
+               HiVowel[ch-'A'] = 0;
+       HiVowel['A'-'A'] = 1;
+       HiVowel['E'-'A'] = 1;
+       HiVowel['I'-'A'] = 1;
+       HiVowel['O'-'A'] = 1;
+       HiVowel['U'-'A'] = 1;
+       HiVowel['Y'-'A'] = 1;
+
+       m_pUniCharset = NULL;
+       m_pUniCompCharset = NULL;
+       m_pUniUTF8 = NULL;
+       m_pUniRef = NULL;
+       m_pUniHex = NULL;
+       m_pVIQRCharObj = NULL;
+       m_pUVIQRCharObj = NULL;
+       m_pWinCP1258 = NULL;
+       m_pVnIntCharset = NULL;
+
+       int i;
+       for (i = 0; i < CONV_TOTAL_SINGLE_CHARSETS; i++)
+               m_sgCharsets[i] = NULL;
+
+       for (i = 0; i < CONV_TOTAL_DOUBLE_CHARSETS; i++)
+               m_dbCharsets[i] = NULL;
+
+       VnConvResetOptions(&m_options);
+       m_VIQREscPatterns.init((char**)VIQREscapes, VIQREscCount);
+       m_VIQROutEscPatterns.init((char**)VIQREscapes, VIQREscCount);
+}
+
+
+//-----------------------------------------
+CVnCharsetLib::~CVnCharsetLib()
+{
+       if (m_pUniCharset)
+               delete m_pUniCharset;
+       if (m_pUniUTF8)
+               delete m_pUniUTF8;
+       if (m_pUniRef)
+               delete m_pUniRef;
+       if (m_pUniHex)
+               delete m_pUniHex;
+       if (m_pVIQRCharObj)
+               delete m_pVIQRCharObj;
+       if (m_pUVIQRCharObj)
+               delete m_pUVIQRCharObj;
+       if (m_pWinCP1258)
+               delete m_pWinCP1258;
+       if (m_pUniCString)
+               delete m_pUniCString;
+       if (m_pVnIntCharset)
+               delete m_pVnIntCharset;
+
+       int i;
+       for (i = 0; i < CONV_TOTAL_SINGLE_CHARSETS; i++)
+               if (m_sgCharsets[i]) delete m_sgCharsets[i];
+
+       for (i = 0; i < CONV_TOTAL_DOUBLE_CHARSETS; i++)
+               if (m_dbCharsets[i]) delete m_dbCharsets[i];
+
+}
+
+//-----------------------------------------
+VnCharset * CVnCharsetLib::getVnCharset(int charsetIdx)
+{
+       switch (charsetIdx) {
+
+       case CONV_CHARSET_UNICODE:
+               if (m_pUniCharset == NULL)
+                       m_pUniCharset = new UnicodeCharset(UnicodeTable);
+               return m_pUniCharset;
+       case CONV_CHARSET_UNIDECOMPOSED:
+               if (m_pUniCompCharset == NULL)
+                       m_pUniCompCharset = new UnicodeCompCharset(UnicodeTable, UnicodeComposite);
+               return m_pUniCompCharset;
+       case CONV_CHARSET_UNIUTF8:
+  case CONV_CHARSET_XUTF8:
+               if (m_pUniUTF8 == NULL)
+                       m_pUniUTF8 = new UnicodeUTF8Charset(UnicodeTable);
+               return m_pUniUTF8;
+       
+       case CONV_CHARSET_UNIREF:
+               if (m_pUniRef == NULL)
+                       m_pUniRef = new UnicodeRefCharset(UnicodeTable);
+               return m_pUniRef;
+
+       case CONV_CHARSET_UNIREF_HEX:
+               if (m_pUniHex == NULL)
+                       m_pUniHex = new UnicodeHexCharset(UnicodeTable);
+               return m_pUniHex;
+
+       case CONV_CHARSET_UNI_CSTRING:
+               if (m_pUniCString == NULL)
+                       m_pUniCString = new UnicodeCStringCharset(UnicodeTable);
+               return m_pUniCString;
+
+       case CONV_CHARSET_WINCP1258:
+               if (m_pWinCP1258 == NULL)
+                       m_pWinCP1258 = new WinCP1258Charset(WinCP1258, WinCP1258Pre);
+               return m_pWinCP1258;
+
+       case CONV_CHARSET_VIQR:
+               if (m_pVIQRCharObj == NULL)
+                       m_pVIQRCharObj = new VIQRCharset(VIQRTable);
+               return m_pVIQRCharObj;
+
+       case CONV_CHARSET_VNSTANDARD:
+               if (m_pVnIntCharset == NULL)
+                       m_pVnIntCharset = new VnInternalCharset();
+               return m_pVnIntCharset;
+
+       case CONV_CHARSET_UTF8VIQR:
+         if (m_pUVIQRCharObj == NULL) {
+           if (m_pVIQRCharObj == NULL)
+             m_pVIQRCharObj = new VIQRCharset(VIQRTable);
+
+           if (m_pUniUTF8 == NULL)
+             m_pUniUTF8 = new UnicodeUTF8Charset(UnicodeTable);
+           m_pUVIQRCharObj = new UTF8VIQRCharset(m_pUniUTF8, m_pVIQRCharObj);
+         }
+         return m_pUVIQRCharObj;
+
+       default:
+               if (IS_SINGLE_BYTE_CHARSET(charsetIdx)) {
+                       int i = charsetIdx - CONV_CHARSET_TCVN3;
+                       if (m_sgCharsets[i] == NULL)
+                               m_sgCharsets[i] = new SingleByteCharset(SingleByteTables[i]);
+                       return m_sgCharsets[i];
+               }
+               else if (IS_DOUBLE_BYTE_CHARSET(charsetIdx)) {
+                       int i = charsetIdx - CONV_CHARSET_VNIWIN;
+                       if (m_dbCharsets[i] == NULL)
+                               m_dbCharsets[i] = new DoubleByteCharset(DoubleByteTables[i]);
+                       return m_dbCharsets[i];
+               }
+       }
+       return NULL;
+}
+
+
+//-------------------------------------------------
+DllExport void VnConvSetOptions(VnConvOptions *pOptions)
+{
+       VnCharsetLibObj.m_options = *pOptions;
+}
+
+//-------------------------------------------------
+DllExport void VnConvGetOptions(VnConvOptions *pOptions)
+{
+       *pOptions = VnCharsetLibObj.m_options;
+}
+
+//-------------------------------------------------
+DllExport void VnConvResetOptions(VnConvOptions *pOptions)
+{
+       pOptions->viqrEsc = 1;
+       pOptions->viqrMixed = 0;
+       pOptions->toUpper = 0;
+       pOptions->toLower = 0;
+       pOptions->removeTone = 0;
+    pOptions->smartViqr = 1;
+}
+
+
+/////////////////////////////////////////////
+// Class WinCP1258Charset
+/////////////////////////////////////////////
+WinCP1258Charset::WinCP1258Charset(UKWORD *compositeChars, UKWORD *precomposedChars)
+{
+  int i,k;
+       m_toDoubleChar = compositeChars;
+       memset(m_stdMap, 0, 256*sizeof(UKWORD));
+
+       // encode composite chars
+       for (i=0; i<TOTAL_VNCHARS; i++) {
+               if (compositeChars[i] >> 8) // a 2-byte character
+                       m_stdMap[compositeChars[i] >> 8] = 0xFFFF; //INVALID_STD_CHAR;
+               else if (m_stdMap[compositeChars[i]] == 0)
+                       m_stdMap[compositeChars[i]] = i+1;
+
+               m_vnChars[i] = (i << 16) + compositeChars[i]; // high word is used for StdChar index
+       }
+
+       m_totalChars = TOTAL_VNCHARS;
+
+       //add precomposed chars to the table
+       for (k=0, i=TOTAL_VNCHARS; k<TOTAL_VNCHARS; k++)
+               if (precomposedChars[k] != compositeChars[k]) {
+                       if (precomposedChars[k] >> 8) // a 2-byte character
+                               m_stdMap[precomposedChars[k] >> 8] = 0xFFFF; //INVALID_STD_CHAR;
+                       else if (m_stdMap[precomposedChars[k]] == 0)
+                               m_stdMap[precomposedChars[k]] = k+1;
+
+                       m_vnChars[i] = (k << 16) + precomposedChars[k];
+                       m_totalChars++;
+                       i++;
+               }
+
+       qsort(m_vnChars, m_totalChars, sizeof(UKDWORD), wideCharCompare);
+}
+
+
+//---------------------------------------------------------------------
+// This fuction is basically the same as that of DoubleByteCharset
+// with m_totalChars is used instead of constant TOTAL_VNCHARS
+//---------------------------------------------------------------------
+int WinCP1258Charset::nextInput(ByteInStream & is, StdVnChar & stdChar, int & bytesRead)
+{
+       unsigned char ch;
+
+       // read first byte
+       bytesRead = 0;
+       if (!is.getNext(ch))
+               return 0;
+       bytesRead = 1;
+       stdChar = m_stdMap[ch];
+       if (stdChar == 0)
+               stdChar = ch;
+       else if (stdChar == 0xFFFF)
+               stdChar = INVALID_STD_CHAR;
+       else {
+               stdChar += VnStdCharOffset - 1;
+               UKBYTE hi;
+               if (is.peekNext(hi) && hi > 0) {
+                       //test if a double-byte character is encountered
+                       UKDWORD key = MAKEWORD(ch,hi);
+                       UKDWORD *pChar = (UKDWORD *)bsearch(&key, m_vnChars, m_totalChars, sizeof(UKDWORD), wideCharCompare);
+                       if (pChar) {
+                               stdChar = VnStdCharOffset + HIWORD(*pChar);
+                               bytesRead = 2;
+                               is.getNext(hi);
+                       }
+               }
+       }
+       return 1;
+}
+
+//---------------------------------------------------------------------
+// This fuction is exactly the same as that of DoubleByteCharset
+//---------------------------------------------------------------------
+int WinCP1258Charset::putChar(ByteOutStream & os, StdVnChar stdChar, int & outLen)
+{
+       int ret;
+       if (stdChar     >= VnStdCharOffset) {
+               UKWORD wCh = m_toDoubleChar[stdChar-VnStdCharOffset];
+
+               if (wCh & 0xFF00) {
+                       outLen = 2;
+                       os.putB((UKBYTE)(wCh & 0x00FF));
+                       ret = os.putB((UKBYTE)(wCh >> 8));
+               }
+               else {
+                       unsigned char b = (unsigned char)wCh;
+                       if (m_stdMap[b] == 0xFFFF)
+                               b = PadChar;
+                       outLen = 1;
+                       ret = os.putB(b);
+               }
+       }
+       else {
+               if (stdChar > 255 || m_stdMap[stdChar]) {
+                       outLen = 1;
+                       ret = os.putB((UKBYTE)PadChar);
+               }
+               else {
+                       outLen = 1;
+                       ret = os.putB((UKBYTE)stdChar);
+               }
+       }
+       return ret;
+}
+
+#define IS_ODD(x) (x & 1)
+#define IS_EVEN(x) (!(x & 1))
+
+StdVnChar StdVnToUpper(StdVnChar ch)
+{
+       if (ch >= VnStdCharOffset && 
+               ch<(VnStdCharOffset + TOTAL_ALPHA_VNCHARS) && 
+               IS_ODD(ch))
+               ch -= 1;
+       return ch;
+}
+
+//----------------------------------------
+StdVnChar StdVnToLower(StdVnChar ch)
+{
+       if (ch >= VnStdCharOffset && 
+               ch<(VnStdCharOffset + TOTAL_ALPHA_VNCHARS) && 
+               IS_EVEN(ch))
+               ch += 1;
+       return ch;
+}
+
+//----------------------------------------
+StdVnChar StdVnGetRoot(StdVnChar ch)
+{
+       if (ch >= VnStdCharOffset && ch<VnStdCharOffset+TOTAL_VNCHARS)
+               ch = VnStdCharOffset + StdVnRootChar[ch-VnStdCharOffset];
+       return ch;
+}
diff --git a/ukengine/charset.h b/ukengine/charset.h
new file mode 100644 (file)
index 0000000..e02f76c
--- /dev/null
@@ -0,0 +1,305 @@
+// -*- coding:unix; mode:c++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
+/*------------------------------------------------------------------------------
+VnConv: Vietnamese Encoding Converter Library
+UniKey Project: http://unikey.sourceforge.net
+Copyleft (C) 1998-2002 Pham Kim Long
+Contact: longp@cslab.felk.cvut.cz
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+--------------------------------------------------------------------------------*/
+
+#ifndef __CHARSET_CONVERT_H
+#define __CHARSET_CONVERT_H
+
+#if !defined(_WIN32)
+  #include <stdint.h>
+#endif
+
+#if defined(_WIN32)
+    #if defined(UNIKEYHOOK)
+        #define DllInterface   __declspec( dllexport )
+    #else
+        #define DllInterface   __declspec( dllimport )
+    #endif
+#else
+    #define DllInterface //not used
+    #define DllExport
+    #define DllImport
+#endif
+
+#include "vnconv.h"
+#include "byteio.h"
+#include "pattern.h"
+
+#define TOTAL_VNCHARS 213
+#define TOTAL_ALPHA_VNCHARS 186
+
+#if defined(_WIN32)
+    typedef unsigned __int32 StdVnChar;
+    typedef unsigned __int16 UnicodeChar;
+    typedef unsigned __int16 UKWORD;
+    typedef unsigned __int32 UKDWORD;
+#else
+//typedef unsigned int StdVnChar; //the size should be more specific
+       typedef uint32_t StdVnChar;
+    typedef uint16_t UnicodeChar;
+    typedef uint16_t UKWORD;
+    typedef uint32_t UKDWORD;
+#endif
+
+//typedef unsigned short UnicodeChar;
+//typedef unsigned short UKWORD;
+
+//typedef unsigned int UKDWORD; //the size should be more specific
+
+#ifndef LOWORD
+#define LOWORD(l)           ((UKWORD)(l))
+#endif
+
+#ifndef HIWORD
+#define HIWORD(l)           ((UKWORD)(((UKDWORD)(l) >> 16) & 0xFFFF))
+#endif
+
+#ifndef MAKEWORD
+#define MAKEWORD(a, b)      ((UKWORD)(((UKBYTE)(a)) | ((UKWORD)((UKBYTE)(b))) << 8))
+#endif
+
+const StdVnChar VnStdCharOffset = 0x10000;
+const StdVnChar INVALID_STD_CHAR = 0xFFFFFFFF;
+//const unsigned char PadChar = '?'; //? is used for VIQR charset
+const unsigned char PadChar = '#';
+const unsigned char PadStartQuote = '\"';
+const unsigned char PadEndQuote = '\"';
+const unsigned char PadEllipsis = '.';
+
+class DllInterface VnCharset {
+public:
+       virtual void startInput() {};
+       virtual void startOutput() {};
+//     virtual UKBYTE *nextInput(UKBYTE *input, int inLen, StdVnChar & stdChar, int & bytesRead) = 0;
+       virtual int nextInput(ByteInStream & is, StdVnChar & stdChar, int & bytesRead) = 0;
+
+       //------------------------------------------------------------------------
+       // put a character to the output after converting it
+       // Arguments:
+       //     output[in]: output buffer
+       //     stdChar[in]: character in standard charset
+       //     outLen[out]: length of converted sequence
+       //     maxAvail[in]: max length available.
+       // Returns: next position in output
+       //------------------------------------------------------------------------
+       virtual int putChar(ByteOutStream & os, StdVnChar stdChar, int & outLen) = 0;
+    virtual int elementSize();
+       virtual ~VnCharset() {}
+};
+
+//--------------------------------------------------
+class SingleByteCharset: public VnCharset {
+protected:
+       UKWORD m_stdMap[256];
+       unsigned char * m_vnChars;
+public:
+       SingleByteCharset(unsigned char * vnChars);
+       virtual int nextInput(ByteInStream & is, StdVnChar & stdChar, int & bytesRead);
+       virtual int putChar(ByteOutStream & os, StdVnChar stdChar, int & outLen);
+};
+
+//--------------------------------------------------
+class VnInternalCharset: public VnCharset {
+public:
+  VnInternalCharset() {};
+  virtual int nextInput(ByteInStream & is, StdVnChar & stdChar, int & bytesRead);
+  virtual int putChar(ByteOutStream & os, StdVnChar stdChar, int & outLen);
+  virtual int elementSize();
+};
+
+//--------------------------------------------------
+class UnicodeCharset: public VnCharset {
+protected:
+       UKDWORD m_vnChars[TOTAL_VNCHARS];
+       UnicodeChar * m_toUnicode;
+public:
+       UnicodeCharset(UnicodeChar *vnChars);
+       virtual int nextInput(ByteInStream & is, StdVnChar & stdChar, int & bytesRead);
+       virtual int putChar(ByteOutStream & os, StdVnChar stdChar, int & outLen);
+    virtual int elementSize();
+};
+
+//--------------------------------------------------
+class DoubleByteCharset: public VnCharset {
+protected:
+       UKWORD m_stdMap[256];
+       UKDWORD m_vnChars[TOTAL_VNCHARS];
+       UKWORD * m_toDoubleChar;
+public:
+       DoubleByteCharset(UKWORD *vnChars);
+       virtual int nextInput(ByteInStream & is, StdVnChar & stdChar, int & bytesRead);
+       virtual int putChar(ByteOutStream & os, StdVnChar stdChar, int & outLen);
+};
+
+//--------------------------------------------------
+class UnicodeUTF8Charset: public UnicodeCharset
+{
+public:
+       UnicodeUTF8Charset(UnicodeChar *vnChars) : UnicodeCharset(vnChars)      {}
+
+       virtual int nextInput(ByteInStream & is, StdVnChar & stdChar, int & bytesRead);
+       virtual int putChar(ByteOutStream & os, StdVnChar stdChar, int & outLen);
+};
+
+//--------------------------------------------------
+class UnicodeRefCharset: public UnicodeCharset
+{
+public:
+       UnicodeRefCharset(UnicodeChar *vnChars) : UnicodeCharset(vnChars)       {}
+
+       virtual int nextInput(ByteInStream & is, StdVnChar & stdChar, int & bytesRead);
+       virtual int putChar(ByteOutStream & os, StdVnChar stdChar, int & outLen);
+};
+
+//--------------------------------------------------
+class UnicodeHexCharset: public UnicodeRefCharset
+{
+public:
+       UnicodeHexCharset(UnicodeChar *vnChars) : UnicodeRefCharset(vnChars) {}
+       virtual int putChar(ByteOutStream & os, StdVnChar stdChar, int & outLen);
+};
+
+//--------------------------------------------------
+class UnicodeCStringCharset: public UnicodeCharset
+{
+protected:
+       int m_prevIsHex;
+public:
+       UnicodeCStringCharset(UnicodeChar *vnChars) : UnicodeCharset(vnChars) {}
+       virtual int nextInput(ByteInStream & is, StdVnChar & stdChar, int & bytesRead);
+       virtual int putChar(ByteOutStream & os, StdVnChar stdChar, int & outLen);
+       virtual void startInput();
+};
+
+//--------------------------------------------------
+class WinCP1258Charset: public VnCharset {
+protected:
+       UKWORD m_stdMap[256];
+       UKDWORD m_vnChars[TOTAL_VNCHARS*2];
+       UKWORD *m_toDoubleChar;
+       int m_totalChars;
+
+public:
+       WinCP1258Charset(UKWORD *compositeChars, UKWORD *precomposedChars);
+       virtual int nextInput(ByteInStream & is, StdVnChar & stdChar, int & bytesRead);
+       virtual int putChar(ByteOutStream & os, StdVnChar stdChar, int & outLen);
+};
+
+//--------------------------------------------------
+struct UniCompCharInfo {
+       UKDWORD compChar;
+       int stdIndex;
+};
+
+class UnicodeCompCharset: public VnCharset {
+protected:
+       UniCompCharInfo m_info[TOTAL_VNCHARS*2];
+       UKDWORD *m_uniCompChars;
+       int m_totalChars;
+public:
+       UnicodeCompCharset(UnicodeChar *uniChars, UKDWORD *uniCompChars);
+       virtual int nextInput(ByteInStream & is, StdVnChar & stdChar, int & bytesRead);
+       virtual int putChar(ByteOutStream & os, StdVnChar stdChar, int & outLen);
+    virtual int elementSize();
+};
+
+//--------------------------------------------------
+class VIQRCharset: public VnCharset {
+protected:
+       UKDWORD *m_vnChars;
+       UKWORD m_stdMap[256];
+       int m_atWordBeginning;
+       int m_escapeBowl;
+       int m_escapeRoof;
+       int m_escapeHook;
+       int m_escapeTone;
+       int m_gotTone;
+       int m_escAll;
+       int m_noOutEsc;
+public:
+       int m_suspicious;
+       VIQRCharset(UKDWORD *vnChars);
+       virtual void startInput();
+       virtual void startOutput();
+       virtual int nextInput(ByteInStream & is, StdVnChar & stdChar, int & bytesRead);
+       virtual int putChar(ByteOutStream & os, StdVnChar stdChar, int & outLen);
+};
+
+//--------------------------------------------------
+class UTF8VIQRCharset: public VnCharset {
+
+protected:
+       VIQRCharset *m_pViqr;
+       UnicodeUTF8Charset *m_pUtf;
+
+public:
+       UTF8VIQRCharset(UnicodeUTF8Charset *pUtf, VIQRCharset *pViqr);
+       virtual void startInput();
+       virtual void startOutput();
+       virtual int nextInput(ByteInStream & is, StdVnChar & stdChar, int & bytesRead);
+       virtual int putChar(ByteOutStream & os, StdVnChar stdChar, int & outLen);
+};
+
+
+//--------------------------------------------------
+class DllInterface CVnCharsetLib {
+protected:
+       SingleByteCharset * m_sgCharsets[CONV_TOTAL_SINGLE_CHARSETS];
+       DoubleByteCharset * m_dbCharsets[CONV_TOTAL_DOUBLE_CHARSETS];
+       UnicodeCharset * m_pUniCharset; 
+       UnicodeCompCharset * m_pUniCompCharset;
+       UnicodeUTF8Charset * m_pUniUTF8;
+       UnicodeRefCharset * m_pUniRef;
+       UnicodeHexCharset * m_pUniHex;
+       VIQRCharset * m_pVIQRCharObj;
+       UTF8VIQRCharset * m_pUVIQRCharObj;
+       WinCP1258Charset * m_pWinCP1258;
+       UnicodeCStringCharset *m_pUniCString;
+       VnInternalCharset *m_pVnIntCharset;
+
+public:
+       PatternList m_VIQREscPatterns, m_VIQROutEscPatterns;
+       VnConvOptions m_options;
+       CVnCharsetLib();
+       ~CVnCharsetLib();
+       VnCharset * getVnCharset(int charsetIdx);
+};
+
+extern unsigned char SingleByteTables[][TOTAL_VNCHARS];
+extern UKWORD DoubleByteTables[][TOTAL_VNCHARS];
+extern UnicodeChar UnicodeTable[TOTAL_VNCHARS];
+extern UKDWORD VIQRTable[TOTAL_VNCHARS];
+extern UKDWORD UnicodeComposite[TOTAL_VNCHARS];
+extern UKWORD WinCP1258[TOTAL_VNCHARS];
+extern UKWORD WinCP1258Pre[TOTAL_VNCHARS];
+
+extern DllInterface CVnCharsetLib VnCharsetLibObj;
+extern VnConvOptions VnConvGlobalOptions;
+extern int StdVnNoTone[TOTAL_VNCHARS];
+extern int StdVnRootChar[TOTAL_VNCHARS];
+
+DllInterface int genConvert(VnCharset & incs, VnCharset & outcs, ByteInStream & input, ByteOutStream & output);
+
+StdVnChar StdVnToUpper(StdVnChar ch);
+StdVnChar StdVnToLower(StdVnChar ch);
+StdVnChar StdVnGetRoot(StdVnChar ch);
+
+#endif
diff --git a/ukengine/convert.cpp b/ukengine/convert.cpp
new file mode 100644 (file)
index 0000000..0ccfdb1
--- /dev/null
@@ -0,0 +1,251 @@
+// -*- coding:unix; mode:c++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
+/*------------------------------------------------------------------------------
+VnConv: Vietnamese Encoding Converter Library
+UniKey Project: http://unikey.sourceforge.net
+Copyleft (C) 1998-2002 Pham Kim Long
+Contact: longp@cslab.felk.cvut.cz
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+--------------------------------------------------------------------------------*/
+
+#include "charset.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if defined(_WIN32)
+       #include <io.h>
+       #include <fcntl.h>
+#endif
+
+#include "vnconv.h"
+
+int vnFileStreamConvert(int inCharset, int outCharset, FILE * inf, FILE *outf);
+
+DllExport int genConvert(VnCharset & incs, VnCharset & outcs, ByteInStream & input, ByteOutStream & output)
+{
+       StdVnChar stdChar;
+       int bytesRead, bytesWritten;
+
+       incs.startInput();
+       outcs.startOutput();
+
+       int ret = 1;
+       while (!input.eos()) {
+        stdChar = 0;
+               if (incs.nextInput(input, stdChar, bytesRead)) {
+                       if (stdChar != INVALID_STD_CHAR) {
+                         if (VnCharsetLibObj.m_options.toLower)
+                           stdChar = StdVnToLower(stdChar);
+                         else if (VnCharsetLibObj.m_options.toUpper)
+                           stdChar = StdVnToUpper(stdChar);
+                         if (VnCharsetLibObj.m_options.removeTone)
+                           stdChar = StdVnGetRoot(stdChar);
+                         ret = outcs.putChar(output, stdChar, bytesWritten);
+                       }
+               }
+               else break;
+       }
+       return (ret? 0 : VNCONV_OUT_OF_MEMORY);
+}
+
+//----------------------------------------------
+// Arguments:
+//       inCharset: charset of input
+//       outCharset: charset of output
+//       input: input data
+//       output: output data
+//       inLen: [in]  size of input. if inLen = -1, input data is null-terminated.
+//              [out] if input inLen != -1, output iLen is the numbers of byte left in input.
+//       maxOutLen: [in] size of output.
+//                  [out] number of bytes output, if enough memory
+//                        number of bytes needed for output, if not enough memory
+// Returns:  0 if successful
+//           error code: if failed
+//----------------------------------------------
+//int VnConvert(int inCharset, int outCharset, UKBYTE *input, UKBYTE *output, int & inLen, int & maxOutLen)
+
+DllExport int VnConvert(int inCharset, int outCharset, UKBYTE *input, UKBYTE *output, 
+             int * pInLen, int * pMaxOutLen)
+{
+       int inLen, maxOutLen;
+       int ret = -1;
+
+       inLen = *pInLen;
+       maxOutLen = *pMaxOutLen;
+
+       if (inLen != -1 && inLen < 0) // invalid inLen
+               return ret;
+
+       VnCharset *pInCharset = VnCharsetLibObj.getVnCharset(inCharset);
+       VnCharset *pOutCharset = VnCharsetLibObj.getVnCharset(outCharset);
+
+       if (!pInCharset || !pOutCharset)
+               return VNCONV_INVALID_CHARSET;
+
+       StringBIStream is(input, inLen, pInCharset->elementSize());
+       StringBOStream os(output, maxOutLen);
+
+       ret = genConvert(*pInCharset, *pOutCharset, is, os);
+       *pMaxOutLen = os.getOutBytes();
+       *pInLen = is.left();
+       return ret;
+}
+
+//---------------------------------------
+// Arguments:
+//   inFile: input file name. NULL if STDIN is used
+//   outFile: output file name, NULL if STDOUT is used
+// Returns:
+//     0: successful
+//     errCode: if failed
+//---------------------------------------
+DllExport int VnFileConvert(int inCharset, int outCharset, const char *inFile, const char *outFile)
+{
+       FILE *inf = NULL;
+       FILE *outf = NULL;
+       int ret = 0;
+       char tmpName[32];
+
+       if (inFile == NULL) {
+               inf = stdin;
+#if defined(_WIN32)
+               _setmode( _fileno(stdin), _O_BINARY);
+#endif
+       }
+       else {
+               inf = fopen(inFile, "rb");
+               if (inf == NULL) {
+                       ret = VNCONV_ERR_INPUT_FILE;
+                       goto end;
+               }
+       }
+
+       if (outFile == NULL)
+               outf = stdout;
+       else {
+               // setup temporary output file (because real output file may be the same as input file
+               char outDir[256];
+               strcpy(outDir, outFile);
+
+#if defined(_WIN32)
+               char *p = strrchr(outDir, '\\');
+#else
+               char *p = strrchr(outDir, '/');
+#endif
+
+               if (p == NULL)
+                       outDir[0] = 0;
+               else
+                       *p = 0;
+
+               strcpy(tmpName, outDir);
+        strcat(tmpName, "XXXXXX");
+
+               if (mkstemp(tmpName) == -1) {
+                       fclose(inf);
+                       ret = VNCONV_ERR_OUTPUT_FILE;
+                       goto end;
+               }
+               outf = fopen(tmpName, "wb");
+
+               if (outf == NULL) {
+                       fclose(inf);
+                       ret = VNCONV_ERR_OUTPUT_FILE; 
+                       goto end;
+               }
+       }
+
+
+       ret = vnFileStreamConvert(inCharset, outCharset, inf, outf);
+       if (inf != stdin)
+               fclose(inf);
+       if (outf != stdout) {
+               fclose(outf);
+
+               // delete output file if exisits
+               if (ret == 0) {
+                       remove(outFile);
+#if !defined(_WIN32)
+                       char cmd[256];
+                       sprintf(cmd, "mv %s %s", tmpName, outFile);
+                       int tmp = system(cmd);
+#else
+                       if (rename(tmpName, outFile) != 0) {
+                               remove(tmpName);
+                               ret = VNCONV_ERR_OUTPUT_FILE;
+                               goto end;
+                       }
+#endif
+               }
+               else 
+                       remove(tmpName);
+       }
+
+end:
+#if defined(_WIN32)
+       if (inf == stdin) {
+               _setmode( _fileno(stdin), _O_BINARY);
+       }
+#endif
+       return ret;
+}
+
+//------------------------------------------------
+// Returns:
+//     0: successful
+//     errCode: if failed
+//---------------------------------------
+int vnFileStreamConvert(int inCharset, int outCharset, FILE * inf, FILE *outf)
+{
+       int ret = 0;
+
+       VnCharset *pInCharset = VnCharsetLibObj.getVnCharset(inCharset);
+       VnCharset *pOutCharset = VnCharsetLibObj.getVnCharset(outCharset);
+
+       if (!pInCharset || !pOutCharset)
+               return VNCONV_INVALID_CHARSET;
+
+       if (outCharset == CONV_CHARSET_UNICODE) {
+               UKWORD sign = 0xFEFF;
+               fwrite(&sign, sizeof(UKWORD), 1, outf);
+       }
+
+       FileBIStream is;
+       FileBOStream os;
+
+       is.attach(inf);
+       os.attach(outf);
+
+       return genConvert(*pInCharset, *pOutCharset, is, os);
+}
+
+const char *ErrTable[VNCONV_LAST_ERROR] = 
+{"No error",
+ "Unknown error",
+ "Invalid charset",
+ "Error opening input file",
+ "Error opening output file",
+ "Error writing to output stream",
+ "Not enough memory",
+};
+
+DllExport const char * VnConvErrMsg(int errCode)
+{
+       if (errCode < 0 || errCode >= VNCONV_LAST_ERROR)
+               errCode = VNCONV_UNKNOWN_ERROR;
+       return ErrTable[errCode];
+}
+
diff --git a/ukengine/data.cpp b/ukengine/data.cpp
new file mode 100644 (file)
index 0000000..733ed35
--- /dev/null
@@ -0,0 +1,571 @@
+// -*- coding:unix; mode:c++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
+/*------------------------------------------------------------------------------
+VnConv: Vietnamese Encoding Converter Library
+UniKey Project: http://unikey.sourceforge.net
+Copyleft (C) 1998-2002 Pham Kim Long
+Contact: longp@cslab.felk.cvut.cz
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+--------------------------------------------------------------------------------*/
+
+#include "charset.h"
+
+/*
+Instructions on how to add more charset supports
+
+Each charset enumerates all its characters according to a fixed order.
+To understand this order, copy the TCVN3 charset bellow to some application
+and view it with some TCVN3 font.
+
+Steps to add an 1-byte charset:
+
+- Determine the Id for your charset. See "vnconv.h". The Id
+  for your charset is equal to the id of the last 1-byte charset PLUS 1.
+  Then define a constant for that Id (e.g. #define MY_NEW_CHARSET 25)
+- In "vnconv.h": Increase the variable CONV_TOTAL_SINGLE_CHARSETS by 1.
+- Add an entry for your charset to the end of CharsetIdMap (in this file)
+- Add your charset to the end of SingleBytesTable
+- Note that and the end of each charset (after character z) there's a section
+  for the symbols in western charsets (see TCVN3). Just copy
+  this section for your charset, and set zero for each code point
+  that is occupied by your charset (for representing Vietnamese characters).
+
+Steps to add a 2-byte charset:
+- Determine the Id for your charset. See "vnconv.h". The Id
+  for your charset is equal to the id of the last 2-byte charset PLUS 1.
+  Then define a constant for that Id (e.g. #define MY_NEW_CHARSET 44)
+- In "vnconv.h": Increase the variable CONV_TOTAL_DOUBLE_CHARSETS by 1.
+- Add an entry for your charset to the end of CharsetIdMap (in this file)
+- Add your charset to the end of DoubleByteTables
+- Note that and the end of each charset (after character z) there's a section
+  for the symbols in western charsets. Just copy this section from
+  VNI-WIN charset to your charset
+- Double-byte characters are represented as a word in which the
+  low byte is base character, high byte is tone mark (if present).
+*/
+extern CharsetNameId CharsetIdMap[];
+extern const int CharsetCount;
+
+CharsetNameId CharsetIdMap[] = {
+       {"BKHCM1",              CONV_CHARSET_BKHCM1},
+       {"BKHCM2",              CONV_CHARSET_BKHCM2},
+       {"ISC",                 CONV_CHARSET_ISC},
+       {"NCR-DEC",             CONV_CHARSET_UNIREF},
+       {"NCR-HEX",             CONV_CHARSET_UNIREF_HEX},
+       {"TCVN3",               CONV_CHARSET_TCVN3},
+       {"UNI-COMP",    CONV_CHARSET_UNIDECOMPOSED},
+       {"UNICODE",             CONV_CHARSET_UNICODE},
+       {"UTF-8",               CONV_CHARSET_UNIUTF8},
+       {"UTF8",                CONV_CHARSET_UNIUTF8},
+       {"UVIQR",       CONV_CHARSET_UTF8VIQR},
+       {"VIETWARE-F",  CONV_CHARSET_VIETWAREF},
+       {"VIETWARE-X",  CONV_CHARSET_VIETWAREX},
+       {"VIQR",                CONV_CHARSET_VIQR},
+       {"VISCII",              CONV_CHARSET_VISCII},
+       {"VNI-MAC",             CONV_CHARSET_VNIMAC},
+       {"VNI-WIN",             CONV_CHARSET_VNIWIN},
+       {"VPS",                 CONV_CHARSET_VPS},
+       {"WINCP-1258",  CONV_CHARSET_WINCP1258}
+};
+
+const int CharsetCount = sizeof(CharsetIdMap)/sizeof(CharsetNameId);
+
+/* Western symbols that need to be mapped
+  0x80, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88,
+  0x89, 0x8A, 0x8B, 0x8C, 0x8E, 0x91, 0x92, 0x93,
+  0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B,
+  0x9C, 0x9E, 0x9F,
+
+If a single byte charset occupies a certain symbol,
+its code point in the charset must be set to zero.
+See TCVN3 & VPS below for examples
+*/
+
+unsigned char SingleByteTables[][TOTAL_VNCHARS] = 
+
+// TCVN3
+{{'A','a','¸','¸','µ','µ','¶','¶','·','·','¹','¹',      // 0: a
+  '¢','©','Ê','Ê','Ç','Ç','È','È','É','É','Ë','Ë',             // 1: a^
+  '¡','¨','¾','¾','»','»','¼','¼','½','½','Æ','Æ',             // 2: a(
+  'B','b','C','c','D','d',
+  '§','®',
+  'E','e','Ð','Ð','Ì','Ì','Î','Î','Ï','Ï','Ñ','Ñ',             // 3: e
+  '£','ª','Õ','Õ','Ò','Ò','Ó','Ó','Ô','Ô','Ö','Ö',      // 4: e^
+  'F','f','G','g','H','h',
+  'I','i','Ý','Ý','×','×','Ø','Ø','Ü','Ü','Þ','Þ',             // 5: i
+  'J','j','K','k','L','l','M','m','N','n',
+  'O','o','ã','ã','ß','ß','á','á','â','â','ä','ä',             // 6: o
+  '¤','«','è','è','å','å','æ','æ','ç','ç','é','é',             // 7: o^
+  '¥','¬','í','í','ê','ê','ë','ë','ì','ì','î','î',             // 8: o+
+  'P','p','Q','q','R','r','S','s','T','t',
+  'U','u','ó','ó','ï','ï','ñ','ñ','ò','ò','ô','ô',             // 9: u
+  '¦','­','ø','ø','õ','õ','ö','ö','÷','÷','ù','ù',             //10: u+ 
+  'V','v','W','w','X','x',
+  'Y','y','ý','ý','ú','ú','û','û','ü','ü','þ','þ',             //11: y
+  'Z','z',
+  0x80, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88,
+  0x89, 0x8A, 0x8B, 0x8C, 0x8E, 0x91, 0x92, 0x93,
+  0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B,
+  0x9C, 0x9E, 0x9F},
+//VPS
+{ 'A','a','Á','á','\80','à','\81','ä','\82','ã','å','å',
+  'Â','â','\83','Ã','\84','À','\85','Ä','Å','Å','Æ','Æ',
+  '\88','æ','\8d','¡','\8e','¢','\8f','£','ð','¤','¥','¥',
+  'B','b','C','c','D','d',
+  'ñ','Ç',
+  'E','e','É','é','×','è','Þ','È','þ','ë','Ë','Ë',
+  'Ê','ê','\90','\89','\93','\8a','\94','\8b','\95','Í','\8c','\8c',
+  'F','f','G','g','H','h',
+  'I','i','´','í','µ','ì','·','Ì','¸','ï','Î','Î',
+  'J','j','K','k','L','l','M','m','N','n',
+  'O','o','¹','ó','¼','ò','½','Õ','¾','õ','\86','\86',
+  'Ô','ô','\96','Ó','\97','Ò','\98','°','\99','\87','¶','¶',
+  '÷','Ö','\9d','§','\9e','©','\9f','ª','¦','«','®','®',
+  'P','p','Q','q','R','r','S','s','T','t',
+  'U','u','Ú','ú','¨','ù','Ñ','û','¬','Û','ø','ø',
+  'Ð','Ü','­','Ù','¯','Ø','±','º','»','»','¿','¿',
+  'V','v','W','w','X','x',
+  'Y','y','Ý','\9a','²','ÿ','ý','\9b','³','Ï','\9c','\9c',
+  'Z','z',
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00, 0x8E, 0x91, 0x92, 0x00,
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x9E, 0x00},
+//VISCII
+{ 'A','a','Á','á','À','à','Ä','ä','Ã','ã','\80','Õ',
+  'Â','â','\84','¤','\85','¥','\86','¦','ç','ç','\87','§',
+  'Å','å','\81','¡','\82','¢','Æ','Æ','Ç','Ç','\83','£',
+  'B','b','C','c','D','d',
+  'Ð','ð',
+  'E','e','É','é','È','è','Ë','ë','\88','¨','\89','©',
+  'Ê','ê','\8a','ª','\8b','«','\8c','¬','\8d','­','\8e','®',
+  'F','f','G','g','H','h',
+  'I','i','Í','í','Ì','ì','\9b','ï','Î','î','\98','¸',
+  'J','j','K','k','L','l','M','m','N','n',
+  'O','o','Ó','ó','Ò','ò','\99','ö','õ','õ','\9a','÷',
+  'Ô','ô','\8f','¯','\90','°','\91','±','\92','²','\93','µ',
+  '´','½','\95','¾','\96','¶','\97','·','³','Þ','\94','þ',
+  'P','p','Q','q','R','r','S','s','T','t',
+  'U','u','Ú','ú','Ù','ù','\9c','ü','\9d','û','\9e','ø',
+  '¿','ß','º','Ñ','»','×','¼','Ø','ÿ','æ','¹','ñ',
+  'V','v','W','w','X','x',
+  'Y','y','Ý','ý','\9f','Ï','Ö','Ö','Û','Û','Ü','Ü',
+  'Z','z',
+  0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00, 0x8E, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x9E, 0x00},
+// BKHCM1
+{'A','a','\80','¾','\81','¿','\82','À','\83','Á','\84','Â',
+  '\9f','Ý','~','Þ','¡','ß','¢','à','£','á','¤','â',
+  '\99','×','\9a','Ø','\9b','Ù','\9c','Ú','\9d','Û','\98','Ü',
+  'B','b','C','c','D','d',
+  '}','½',
+  'E','e','\85','Ã','\86','Ä','\87','Å','\88','Æ','\89','Ç',
+  '¥','ã','¦','ä','§','å','¨','æ','©','ç','ª','è',
+  'F','f','G','g','H','h',
+  'I','i','\8a','È','\8b','É','\8c','Ê','\8d','Ë','\8e','Ì',
+  'J','j','K','k','L','l','M','m','N','n',
+  'O','o','\8f','Í','\90','Î','\91','Ï','\92','Ð','\93','Ñ',
+  '«','é','¬','ê','­','ë','®','ì','¯','í','°','î',
+  '±','ï','²','ð','³','ñ','´','ò','µ','ó','¶','ô',
+  'P','p','Q','q','R','r','S','s','T','t',
+  'U','u','\94','Ò','\95','Ó','\96','Ô','\97','Õ','\98','Ö',
+  '·','õ','¸','ö','¹','÷','º','ø','»','ù','¼','ú',
+  'V','v','W','w','X','x',
+  'Y','y','{','û','^','ü','`','ý','|','þ','\8e','ÿ',
+  'Z','z',
+  0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00, 0x8E, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x9E, 0x00},
+//Vietware-F
+{ 'A','a','À','À','ª','ª','¶','¶','º','º','Á','Á',
+  '\97','¡','Ê','Ê','Ç','Ç','È','È','É','É','Ë','Ë',
+  '\96','\9f','Å','Å','Â','Â','Ã','Ã','Ä','Ä','Æ','Æ',
+  'B','b','C','c','D','d',
+  '\98','¢',
+  'E','e','Ï','Ï','Ì','Ì','Í','Í','Î','Î','Ñ','Ñ',
+  '\99','£','Õ','Õ','Ò','Ò','Ó','Ó','Ô','Ô','Ö','Ö',
+  'F','f','G','g','H','h',
+  'I','i','Û','Û','Ø','Ø','Ù','Ù','Ú','Ú','Ü','Ü',
+  'J','j','K','k','L','l','M','m','N','n',
+  'O','o','â','â','ß','ß','à','à','á','á','ã','ã',
+  '\9a','¤','ç','ç','ä','ä','å','å','æ','æ','è','è',
+  '\9b','¥','ì','ì','é','é','ê','ê','ë','ë','í','í',
+  'P','p','Q','q','R','r','S','s','T','t',
+  'U','u','ò','ò','î','î','ï','ï','ñ','ñ','ó','ó',
+  '\9c','§','÷','÷','ô','ô','õ','õ','ö','ö','ø','ø',
+  'V','v','W','w','X','x',
+  'Y','y','ü','ü','ù','ù','ú','ú','û','û','ÿ','ÿ',
+  'Z','z',
+  0x80, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88,
+  0x89, 0x8A, 0x8B, 0x8C, 0x8E, 0x91, 0x92, 0x93,
+  0x94, 0x95, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x9E, 0x00},
+// ISC
+ {'A','a','\83','¸','\80','µ','\81','¶','\82','·','\84','¹', 
+  '¢','©','Ä',' ','Á','Ç','Â','È','Ã','É','\86','Ë',
+  '¡','¨','À','¾','¯','»','º','¼','¿','½','\85','Æ',
+  'B','b','C','c','D','d',
+  '§','®',
+  'E','e','Ð','\8a','\87','Ì','\88','Î','\89','Ï','Ñ','\8b',
+  '£','ª','Ú','Õ','Å','Ò','Í','Ó','Ù','Ô','\8c','Ö',
+  'F','f','G','g','H','h',
+  'I','i','\90','Ý','\8d','×','\8e','Ø','\8f','Ü','\91','Þ',
+  'J','j','K','k','L','l','M','m','N','n',
+  'O','o','\95','ã','\92','ß','\93','á','\94','â','\96','ä',
+  '¤','«','ÿ','è','Û','å','à','æ','ð','ç','\97','é',
+  '¥','¬','\9b','í','\98','ê','\99','ë','\9a','ì','\9c','î',
+  'P','p','Q','q','R','r','S','s','T','t',
+  'U','u','@','ó','\9d','ï','\9e','ñ','\9f','ò','|','ô',
+  '¦','­','`','ø',0x5C,'õ','^','ö','~','÷','#','ù',
+  'V','v','W','w','X','x',
+  'Y','y','³','ý','°','ú','±','û','²','ü','´','þ',
+  'Z','z',
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x12, 0x13,
+  0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00}
+};
+
+UKWORD DoubleByteTables[][TOTAL_VNCHARS] = {
+//VNI-WIN
+{ 0x0041, 0x0061, 0xd941, 0xf961, 0xd841, 0xf861, 0xdb41, 0xfb61, 0xd541, 0xf561, 0xcf41, 0xef61, //a
+  0xc241, 0xe261, 0xc141, 0xe161, 0xc041, 0xe061, 0xc541, 0xe561, 0xc341, 0xe361, 0xc441, 0xe461, //a^
+  0xca41, 0xea61, 0xc941, 0xe961, 0xc841, 0xe861, 0xda41, 0xfa61, 0xdc41, 0xfc61, 0xcb41, 0xeb61, //a(
+  0x0042, 0x0062, 0x0043, 0x0063, 0x0044, 0x0064, //B b C c D d
+  0x00d1, 0x00f1, //DD, dd
+  0x0045, 0x0065, 0xd945, 0xf965, 0xd845, 0xf865, 0xdb45, 0xfb65, 0xd545, 0xf565, 0xcf45, 0xef65, //e
+  0xc245, 0xe265, 0xc145, 0xe165, 0xc045, 0xe065, 0xc545, 0xe565, 0xc345, 0xe365, 0xc445, 0xe465, //e^
+  0x0046, 0x0066, 0x0047, 0x0067, 0x0048, 0x0068, // F f G g H h
+  0x0049, 0x0069, 0x00cd, 0x00ed, 0x00cc, 0x00ec, 0x00c6, 0x00e6, 0x00d3, 0x00f3, 0x00d2, 0x00f2, //i
+  0x004a, 0x006a, 0x004b, 0x006b, 0x004c, 0x006c, 0x004d, 0x006d, 0x004e, 0x006e,  // J j K k L l M m N n
+  0x004f, 0x006f, 0xd94f, 0xf96f, 0xd84f, 0xf86f, 0xdb4f, 0xfb6f, 0xd54f, 0xf56f, 0xcf4f, 0xef6f, //o
+  0xc24f, 0xe26f, 0xc14f, 0xe16f, 0xc04f, 0xe06f, 0xc54f, 0xe56f, 0xc34f, 0xe36f, 0xc44f, 0xe46f, //o^
+  0x00d4, 0x00f4, 0xd9d4, 0xf9f4, 0xd8d4, 0xf8f4, 0xdbd4, 0xfbf4, 0xd5d4, 0xf5f4, 0xcfd4, 0xeff4, //o+
+  0x0050, 0x0070, 0x0051, 0x0071, 0x0052, 0x0072, 0x0053, 0x0073, 0x0054, 0x0074,                 //P p Q q R r S s T t
+  0x0055, 0x0075, 0xd955, 0xf975, 0xd855, 0xf875, 0xdb55, 0xfb75, 0xd555, 0xf575, 0xcf55, 0xef75, //u
+  0x00d6, 0x00f6, 0xd9d6, 0xf9f6, 0xd8d6, 0xf8f6, 0xdbd6, 0xfbf6, 0xd5d6, 0xf5f6, 0xcfd6, 0xeff6, //u+
+  0x0056, 0x0076, 0x0057, 0x0077, 0x0058, 0x0078, // V v W w X x
+  0x0059, 0x0079, 0xd959, 0xf979, 0xd859, 0xf879, 0xdb59, 0xfb79, 0xd559, 0xf579, 0x00ce, 0x00ee, //y
+  0x005a, 0x007a, // Z z
+  0x0080, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088,
+  0x0089, 0x008A, 0x008B, 0x008C, 0x008E, 0x0091, 0x0092, 0x0093,
+  0x0094, 0x0095, 0x0096, 0x0097, 0x0098, 0x0099, 0x009A, 0x009B,
+  0x009C, 0x009E, 0x009F},
+//BKHCM2
+{ 0x0041, 0x0061, 0xC141, 0xe161, 0xC241, 0xe261, 0xC341, 0xe361, 0xC441, 0xe461, 0xC541, 0xe561, //a
+  0x00CA, 0x00EA, 0xCBCA, 0xEBEA, 0xCCCA, 0xECEA, 0xCDCA, 0xEDEA, 0xCECA, 0xEEEA, 0xC5CA, 0xE5EA, //a^
+  0x00D9, 0x00F9, 0xC6D9, 0xE6F9, 0xC7D9, 0xE7F9, 0xC8D9, 0xE8F9, 0xC9D9, 0xE9F9, 0xC5D9, 0xE5F9,
+  0x0042, 0x0062, 0x0043, 0x0063, 0x0044, 0x0064, //B b C c D d
+  0x00C0, 0x00E0,
+  0x0045, 0x0065, 0xC145, 0xE165, 0xC245, 0xE265, 0xC345, 0xE365, 0xC445, 0xE465, 0xC545, 0xE565, //e
+  0x00CF, 0x00EF, 0xCBCF, 0xEBEF, 0xCCCF, 0xECEF, 0xCDCF, 0xEDEF, 0xCECF, 0xEEEF, 0xE5CF, 0xE5EF, //e^
+  0x0046, 0x0066, 0x0047, 0x0067, 0x0048, 0x0068, // F f G g H h
+  0x0049, 0x0069, 0x00D1, 0x00F1, 0x00D2, 0x00F2, 0x00D3, 0x00F3, 0x00D4, 0x00F4, 0x00D5, 0x00F5, //i
+  0x004a, 0x006a, 0x004b, 0x006b, 0x004c, 0x006c, 0x004d, 0x006d, 0x004e, 0x006e,  // J j K k L l M m N n
+  0x004F, 0x006F, 0xC14F, 0xE16F, 0xC24F, 0xE26F, 0xC34F, 0xE36F, 0xC44F, 0xE46F, 0xC54F, 0xE56F, //o
+  0x00D6, 0x00F6, 0xCBD6, 0xEBF6, 0xCCD6, 0xECF6, 0xCDD6, 0xEDF6, 0xCED6, 0xEEF6, 0xC5D6, 0xE5F6, //o^
+  0x00DA, 0x00FA, 0xC1DA, 0xE1FA, 0xC2DA, 0xE2FA, 0xC3DA, 0xE3FA, 0xC4DA, 0xE4FA, 0xC5DA, 0xE5FA, //o+
+  0x0050, 0x0070, 0x0051, 0x0071, 0x0052, 0x0072, 0x0053, 0x0073, 0x0054, 0x0074,    //P p Q q R r S s T t      
+  0x0055, 0x0075, 0xC155, 0xE175, 0xC255, 0xE275, 0xC355, 0xE375, 0xC455, 0xE475, 0xC555, 0xE575, //u
+  0x00DB, 0x00FB, 0xC1DB, 0xE1FB, 0xC2DB, 0xE2FB, 0xC3DB, 0xE3FB, 0xC4DB, 0xE4FB, 0xC5DB, 0xE5FB, //u+
+  0x0056, 0x0076, 0x0057, 0x0077, 0x0058, 0x0078, // V v W w X x
+  0x0059, 0x0079, 0xC159, 0xE179, 0xC259, 0xE279, 0xC359, 0xE379, 0xC459, 0xE479, 0xC559, 0xE579,
+  0x005a, 0x007a,// Z z
+  0x0080, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088,
+  0x0089, 0x008A, 0x008B, 0x008C, 0x008E, 0x0091, 0x0092, 0x0093,
+  0x0094, 0x0095, 0x0096, 0x0097, 0x0098, 0x0099, 0x009A, 0x009B,
+  0x009C, 0x009E, 0x009F},
+//VIETWARE-X
+{ 0x0041, 0x0061, 0xCF41, 0xEF61, 0xCC41, 0xEC61, 0xCD41, 0xED61, 0xCE41, 0xEE61, 0xDB41, 0xFB61, //a
+  0x00C1, 0x00E1, 0xDAC1, 0xFAE1, 0xD6C1, 0xF6E1, 0xD8C1, 0xF8E1, 0xD9C1, 0xF9E1, 0xDBC1, 0xFBE1, //a^
+  0x00C0, 0x00E0, 0xD5C0, 0xF5E0, 0xD2C0, 0xF2E0, 0xD3C0, 0xF3E0, 0xD4C0, 0xF4E0, 0xDBC0, 0xFBE0, //a(
+  0x0042, 0x0062, 0x0043, 0x0063, 0x0044, 0x0064, //B b C c D d
+  0x00C2, 0x00E2,
+  0x0045, 0x0065, 0xCF45, 0xEF65, 0xCC45, 0xEC65, 0xCD45, 0xED65, 0xCE45, 0xEE65, 0xDB45, 0xFB65, //e
+  0x00C3, 0x00E3, 0xDAC3, 0xFAE3, 0xD6C3, 0xF6E3, 0xD8C3, 0xF8E3, 0xD9C3, 0xF9E3, 0xDBC3, 0xFBE3, //e^
+  0x0046, 0x0066, 0x0047, 0x0067, 0x0048, 0x0068, // F f G g H h
+  0x0049, 0x0069, 0x00CA, 0x00EA, 0x00C7, 0x00E7, 0x00C8, 0x00E8, 0x00C9, 0x00E9, 0x00CB, 0x00EB, //i
+  0x004a, 0x006a, 0x004b, 0x006b, 0x004c, 0x006c, 0x004d, 0x006d, 0x004e, 0x006e,  // J j K k L l M m N n
+  0x004F, 0x006F, 0xCF4F, 0xEF6F, 0xCC4F, 0xEC6F, 0xCD4F, 0xED6F, 0xCE4F, 0xEE6F, 0xDC4F, 0xFC6F, //o
+  0x00C4, 0x00E4, 0xDAC4, 0xFAE4, 0xD6C4, 0xF6E4, 0xD8C4, 0xF8E4, 0xD9C4, 0xF9E4, 0xDCC4, 0xFCE4, //o^
+  0x00C5, 0x00E5, 0xCFC5, 0xEFE5, 0xCCC5, 0xECE5, 0xCDC5, 0xEDE5, 0xCEC5, 0xEEE5, 0xDCC5, 0xFCE5, //o+
+  0x0050, 0x0070, 0x0051, 0x0071, 0x0052, 0x0072, 0x0053, 0x0073, 0x0054, 0x0074,                 //P p Q q R r S s T t
+  0x0055, 0x0075, 0xCF55, 0xEF75, 0xCC55, 0xEC75, 0xCD55, 0xED75, 0xCE55, 0xEE75, 0xDB55, 0xFB75, //u
+  0x00C6, 0x00E6, 0xCFC6, 0xEFE6, 0xCCC6, 0xECE6, 0xCDC6, 0xEDE6, 0xCEC6, 0xEEE6, 0xDBC6, 0xFBE6, //u+
+  0x0056, 0x0076, 0x0057, 0x0077, 0x0058, 0x0078, // V v W w X x
+  0x0059, 0x0079, 0xCF59, 0xEF79, 0xCC59, 0xEC79, 0xCD59, 0xED79, 0xCE59, 0xEE79, 0xD159, 0xF179, //Y
+  0x005a, 0x007a,// Z z
+  0x0080, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088,
+  0x0089, 0x008A, 0x008B, 0x008C, 0x008E, 0x0091, 0x0092, 0x0093,
+  0x0094, 0x0095, 0x0096, 0x0097, 0x0098, 0x0099, 0x009A, 0x009B,
+  0x009C, 0x009E, 0x009F},
+// VNI-MAC
+{ 0x0041, 0x0061, 0xf441, 0x9d61, 0xaf41, 0xbf61, 0xf341, 0x9e61, 0xcd41, 0x9b61, 0xec41, 0x9561, //a
+  0xe541, 0x8961, 0xe741, 0x8761, 0xcb41, 0x8861, 0x8141, 0x8c61, 0xcc41, 0x8b61, 0x8041, 0x8a61, //a^
+  0xe641, 0x9061, 0x8341, 0x8e61, 0xe941, 0x8f61, 0xf241, 0x9c61, 0x8641, 0x9f61, 0xe841, 0x9161, //a(
+  0x0042, 0x0062, 0x0043, 0x0063, 0x0044, 0x0064, //B b C c D d
+  0x0084, 0x0096, //DD, dd
+  0x0045, 0x0065, 0xf445, 0x9d65, 0xaf45, 0xbf65, 0xf345, 0x9e65, 0xcd45, 0x9b65, 0xec45, 0x9565, //e
+  0xe545, 0x8965, 0xe745, 0x8765, 0xcb45, 0x8865, 0x8145, 0x8c65, 0xcc45, 0x8b65, 0x8045, 0x8a65, //e^
+  0x0046, 0x0066, 0x0047, 0x0067, 0x0048, 0x0068, // F f G g H h
+  0x0049, 0x0069, 0x00ea, 0x0092, 0x00ed, 0x0093, 0x00ae, 0x00be, 0x00ee, 0x0097, 0x00f1, 0x0098, //i
+  0x004a, 0x006a, 0x004b, 0x006b, 0x004c, 0x006c, 0x004d, 0x006d, 0x004e, 0x006e,  // J j K k L l M m N n
+  0x004f, 0x006f, 0xf44f, 0x9d6f, 0xaf4f, 0xbf6f, 0xf34f, 0x9e6f, 0xcd4f, 0x9b6f, 0xec4f, 0x956f, //o
+  0xe54f, 0x896f, 0xe74f, 0x876f, 0xcb4f, 0x886f, 0x814f, 0x8c6f, 0xcc4f, 0x8b6f, 0x804f, 0x8a6f, //o^
+  0x00ef, 0x0099, 0xf4ef, 0x9d99, 0xafef, 0xbf99, 0xf3ef, 0x9e99, 0xcdef, 0x9b99, 0xecef, 0x9599, //o+
+  0x0050, 0x0070, 0x0051, 0x0071, 0x0052, 0x0072, 0x0053, 0x0073, 0x0054, 0x0074,                 //P p Q q R r S s T t
+  0x0055, 0x0075, 0xf455, 0x9d75, 0xaf55, 0xbf75, 0xf355, 0x9e75, 0xcd55, 0x9b75, 0xec55, 0x9575, //u
+  0x0085, 0x009a, 0xf485, 0x9d9a, 0xaf85, 0xbf9a, 0xf385, 0x9e9a, 0xcd85, 0x9b9a, 0xec85, 0x959a, //u+
+  0x0056, 0x0076, 0x0057, 0x0077, 0x0058, 0x0078, // V v W w X x
+  0x0059, 0x0079, 0xf459, 0x9d79, 0xaf59, 0xbf79, 0xf359, 0x9e79, 0xcd59, 0x9b79, 0x00eb, 0x0094, //y
+  0x005a, 0x007a, // Z z
+  0x00db, 0x00e2, 0x00c4, 0x00e3, 0x00c9, 0x00a0, 0x00e0, 0x00f6,
+  0x00e4, 0x003f, 0x00dc, 0x00ce, 0x003f, 0x00d4, 0x00d5, 0x00d2,
+  0x00d3, 0x00a5, 0x00d0, 0x00d1, 0x00f7, 0x00aa, 0x003f, 0x00dd,
+  0x00cf, 0x003f, 0x00d9}
+};
+
+UKWORD WinCP1258[TOTAL_VNCHARS]=
+//Windows CP 1258
+{ 0x0041, 0x0061, 0xec41, 0xec61, 0xcc41, 0xcc61, 0xd241, 0xd261, 0xde41, 0xde61, 0xf241, 0xf261, //a
+  0x00c2, 0x00e2, 0xecc2, 0xece2, 0xccc2, 0xcce2, 0xd2c2, 0xd2e2, 0xdec2, 0xdee2, 0xf2c2, 0xf2e2, //a^
+  0x00c3, 0x00e3, 0xecc3, 0xece3, 0xccc3, 0xcce3, 0xd2c3, 0xd2e3, 0xdec3, 0xdee3, 0xf2c3, 0xf2e3, //a(
+  0x0042, 0x0062, 0x0043, 0x0063, 0x0044, 0x0064, //B b C c D d
+  0x00d0, 0x00f0, //DD, dd
+  0x0045, 0x0065, 0xec45, 0xec65, 0xcc45, 0xcc65, 0xd245, 0xd265, 0xde45, 0xde65, 0xf245, 0xf265, //e
+  0x00ca, 0x00ea, 0xecca, 0xecea, 0xccca, 0xccea, 0xd2ca, 0xd2ea, 0xdeca, 0xdeea, 0xf2ca, 0xf2ea, //e^
+  0x0046, 0x0066, 0x0047, 0x0067, 0x0048, 0x0068, // F f G g H h
+  0x0049, 0x0069, 0xec49, 0xec69, 0xcc49, 0xcc69, 0xd249, 0xd269, 0xde49, 0xde69, 0xf249, 0xf269, //i
+  0x004a, 0x006a, 0x004b, 0x006b, 0x004c, 0x006c, 0x004d, 0x006d, 0x004e, 0x006e,  // J j K k L l M m N n
+  0x004f, 0x006f, 0xec4f, 0xec6f, 0xcc4f, 0xcc6f, 0xd24f, 0xd26f, 0xde4f, 0xde6f, 0xf24f, 0xf26f, //o
+  0x00d4, 0x00f4, 0xecd4, 0xecf4, 0xccd4, 0xccf4, 0xd2d4, 0xd2f4, 0xded4, 0xdef4, 0xf2d4, 0xf2f4, //o^
+  0x00d5, 0x00f5, 0xecd5, 0xecf5, 0xccd5, 0xccf5, 0xd2d5, 0xd2f5, 0xded5, 0xdef5, 0xf2d5, 0xf2f5, //o+
+  0x0050, 0x0070, 0x0051, 0x0071, 0x0052, 0x0072, 0x0053, 0x0073, 0x0054, 0x0074,                 //P p Q q R r S s T t
+  0x0055, 0x0075, 0xec55, 0xec75, 0xcc55, 0xcc75, 0xd255, 0xd275, 0xde55, 0xde75, 0xf255, 0xf275, //u
+  0x00dd, 0x00fd, 0xecdd, 0xecfd, 0xccdd, 0xccfd, 0xd2dd, 0xd2fd, 0xdedd, 0xdefd, 0xf2dd, 0xf2fd, //u+
+  0x0056, 0x0076, 0x0057, 0x0077, 0x0058, 0x0078, // V v W w X x
+  0x0059, 0x0079, 0xec59, 0xec79, 0xcc59, 0xcc79, 0xd259, 0xd279, 0xde59, 0xde79, 0xf259, 0xf279, //y
+  0x005a, 0x007a, // Z z
+  0x0080, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088,
+  0x0089, 0x008A, 0x008B, 0x008C, 0x008E, 0x0091, 0x0092, 0x0093,
+  0x0094, 0x0095, 0x0096, 0x0097, 0x0098, 0x0099, 0x009A, 0x009B,
+  0x009C, 0x009E, 0x009F};
+
+UKWORD WinCP1258Pre[TOTAL_VNCHARS]=
+//Windows CP1258 - with some more precomposed characters
+{ 0x0041, 0x0061, 0x00c1, 0x00e1, 0x00c0, 0x00e0, 0xd241, 0xd261, 0xde41, 0xde61, 0xf241, 0xf261, //a
+  0x00c2, 0x00e2, 0xecc2, 0xece2, 0xccc2, 0xcce2, 0xd2c2, 0xd2e2, 0xdec2, 0xdee2, 0xf2c2, 0xf2e2, //a^
+  0x00c3, 0x00e3, 0xecc3, 0xece3, 0xccc3, 0xcce3, 0xd2c3, 0xd2e3, 0xdec3, 0xdee3, 0xf2c3, 0xf2e3, //a(
+  0x0042, 0x0062, 0x0043, 0x0063, 0x0044, 0x0064, //B b C c D d
+  0x00d0, 0x00f0, //DD, dd
+  0x0045, 0x0065, 0x00c9, 0x00e9, 0x00c8, 0x00e8, 0xd245, 0xd265, 0xde45, 0xde65, 0xf245, 0xf265, //e
+  0x00ca, 0x00ea, 0xecca, 0xecea, 0xccca, 0xccea, 0xd2ca, 0xd2ea, 0xdeca, 0xdeea, 0xf2ca, 0xf2ea, //e^
+  0x0046, 0x0066, 0x0047, 0x0067, 0x0048, 0x0068, // F f G g H h
+  0x0049, 0x0069, 0x00cd, 0x00ed, 0xcc49, 0xcc69, 0xd249, 0xd269, 0xde49, 0xde69, 0xf249, 0xf269, //i
+  0x004a, 0x006a, 0x004b, 0x006b, 0x004c, 0x006c, 0x004d, 0x006d, 0x004e, 0x006e,  // J j K k L l M m N n
+  0x004f, 0x006f, 0x00d3, 0x00f3, 0xcc4f, 0xcc6f, 0xd24f, 0xd26f, 0xde4f, 0xde6f, 0xf24f, 0xf26f, //o
+  0x00d4, 0x00f4, 0xecd4, 0xecf4, 0xccd4, 0xccf4, 0xd2d4, 0xd2f4, 0xded4, 0xdef4, 0xf2d4, 0xf2f4, //o^
+  0x00d5, 0x00f5, 0xecd5, 0xecf5, 0xccd5, 0xccf5, 0xd2d5, 0xd2f5, 0xded5, 0xdef5, 0xf2d5, 0xf2f5, //o+
+  0x0050, 0x0070, 0x0051, 0x0071, 0x0052, 0x0072, 0x0053, 0x0073, 0x0054, 0x0074,                 //P p Q q R r S s T t
+  0x0055, 0x0075, 0x00da, 0x00fa, 0x00d9, 0x00f9, 0xd255, 0xd275, 0xde55, 0xde75, 0xf255, 0xf275, //u
+  0x00dd, 0x00fd, 0xecdd, 0xecfd, 0xccdd, 0xccfd, 0xd2dd, 0xd2fd, 0xdedd, 0xdefd, 0xf2dd, 0xf2fd, //u+
+  0x0056, 0x0076, 0x0057, 0x0077, 0x0058, 0x0078, // V v W w X x
+  0x0059, 0x0079, 0xec59, 0xec79, 0xcc59, 0xcc79, 0xd259, 0xd279, 0xde59, 0xde79, 0xf259, 0xf279, //y
+  0x005a, 0x007a, // Z z
+  0x0080, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088,
+  0x0089, 0x008A, 0x008B, 0x008C, 0x008E, 0x0091, 0x0092, 0x0093,
+  0x0094, 0x0095, 0x0096, 0x0097, 0x0098, 0x0099, 0x009A, 0x009B,
+  0x009C, 0x009E, 0x009F};
+
+UnicodeChar UnicodeTable[TOTAL_VNCHARS] =
+       {0x0041, 0x0061, 0x00c1, 0x00e1, 0x00c0, 0x00e0, 0x1ea2, 0x1ea3, 0x00c3, 0x00e3, 0x1ea0, 0x1ea1, //a
+     0x00c2, 0x00e2, 0x1ea4, 0x1ea5, 0x1ea6, 0x1ea7, 0x1ea8, 0x1ea9, 0x1eaa, 0x1eab, 0x1eac, 0x1ead, //a^
+        0x0102, 0x0103, 0x1eae, 0x1eaf, 0x1eb0, 0x1eb1, 0x1eb2, 0x1eb3, 0x1eb4, 0x1eb5, 0x1eb6, 0x1eb7, //a(
+     0x0042, 0x0062, 0x0043, 0x0063, 0x0044, 0x0064,                                                 //B b C c D d
+     0x0110, 0x0111,                                                                                 // DD, dd
+        0x0045, 0x0065, 0x00c9, 0x00e9, 0x00c8, 0x00e8, 0x1eba, 0x1ebb, 0x1ebc, 0x1ebd, 0x1eb8, 0x1eb9, //e
+        0x00ca, 0x00ea, 0x1ebe, 0x1ebf, 0x1ec0, 0x1ec1, 0x1ec2, 0x1ec3, 0x1ec4, 0x1ec5, 0x1ec6, 0x1ec7, //e^
+     0x0046, 0x0066, 0x0047, 0x0067, 0x0048, 0x0068,                                                 // F f G g H h
+        0x0049, 0x0069, 0x00cd, 0x00ed, 0x00cc, 0x00ec, 0x1ec8, 0x1ec9, 0x0128, 0x0129, 0x1eca, 0x1ecb, //i
+     0x004a, 0x006a, 0x004b, 0x006b, 0x004c, 0x006c, 0x004d, 0x006d, 0x004e, 0x006e,                 // J j K k L l M m N n
+        0x004f, 0x006f, 0x00d3, 0x00f3, 0x00d2, 0x00f2, 0x1ece, 0x1ecf, 0x00d5, 0x00f5, 0x1ecc, 0x1ecd, //o
+     0x00d4, 0x00f4, 0x1ed0, 0x1ed1, 0x1ed2, 0x1ed3, 0x1ed4, 0x1ed5, 0x1ed6, 0x1ed7, 0x1ed8, 0x1ed9, //o^
+        0x01a0, 0x01a1, 0x1eda, 0x1edb, 0x1edc, 0x1edd, 0x1ede, 0x1edf, 0x1ee0, 0x1ee1, 0x1ee2, 0x1ee3, //o+
+        0x0050, 0x0070, 0x0051, 0x0071, 0x0052, 0x0072, 0x0053, 0x0073, 0x0054, 0x0074,                 //P p Q q R r S s T t
+        0x0055, 0x0075, 0x00da, 0x00fa, 0x00d9, 0x00f9, 0x1ee6, 0x1ee7, 0x0168, 0x0169, 0x1ee4, 0x1ee5, //u
+        0x01af, 0x01b0, 0x1ee8, 0x1ee9, 0x1eea, 0x1eeb, 0x1eec, 0x1eed, 0x1eee, 0x1eef, 0x1ef0, 0x1ef1, //u+
+     0x0056, 0x0076, 0x0057, 0x0077, 0x0058, 0x0078,                                                 // V v W w X x
+     0x0059, 0x0079, 0x00dd, 0x00fd, 0x1ef2, 0x1ef3, 0x1ef6, 0x1ef7, 0x1ef8, 0x1ef9, 0x1ef4, 0x1ef5, //y
+     0x005a, 0x007a,                                                                                // Z z
+// Symbols that have different code points in Unicode and Western charsets
+        0x20AC, 0x20A1, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021, 0x02C6,
+        0x2030, 0x0160, 0x2039, 0x0152, 0x017D, 0x2018, 0x2019, 0x201C,
+        0x201D, 0x2022, 0x2013, 0x2014, 0x02DC, 0x2122, 0x0161, 0x203A, 
+        0x0153, 0x017E, 0x0178};
+
+/*
+unsigned char WesternSymbols[] = 
+       {0x80, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88,
+        0x89, 0x8A, 0x8B, 0x8C, 0x8E, 0x91, 0x92, 0x93,
+        0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B,
+        0x9C, 0x9E, 0x9F};
+*/
+
+/*
+' 0x27
+` 0x60
+? 0x3f
+~ 0x7e
+. 0x2e
+
+^ 0x5e
+( 0x28
++ 0x2b
+
+*/
+UKDWORD VIQRTable[TOTAL_VNCHARS] = 
+       {  0x41,   0x61,   0x2741,   0x2761,   0x6041,   0x6061,   0x3f41,   0x3f61,   0x7e41,   0x7e61,   0x2e41,   0x2e61, //a
+        0x5e41, 0x5e61, 0x275e41, 0x275e61, 0x605e41, 0x605e61, 0x3f5e41, 0x3f5e61, 0x7e5e41, 0x7e5e61, 0x2e5e41, 0x2e5e61, //a^
+        0x2841, 0x2861, 0x272841, 0x272861, 0x602841, 0x602861, 0x3f2841, 0x3f2861, 0x7e2841, 0x7e2861, 0x2e2841, 0x2e2861, //a(
+       0x42,   0x62,     0x43,     0x63,     0x44,     0x64,                                                 //B b C c D d
+        0x4444, 0x6464,                                                                                 // DD, dd
+          0x45,   0x65,   0x2745,   0x2765,   0x6045,   0x6065,   0x3f45,   0x3f65,   0x7e45,   0x7e65,   0x2e45,   0x2e65, //e
+        0x5e45, 0x5e65, 0x275e45, 0x275e65, 0x605e45, 0x605e65, 0x3f5e45, 0x3f5e65, 0x7e5e45, 0x7e5e65, 0x2e5e45, 0x2e5e65, //e^
+       0x46,   0x66,     0x47,     0x67,     0x48,     0x68,                                                 // F f G g H h
+          0x49,   0x69,   0x2749,   0x2769,   0x6049,   0x6069,   0x3f49,   0x3f69,   0x7e49,   0x7e69,   0x2e49,   0x2e69, //i
+       0x4a,   0x6a,     0x4b,     0x6b,     0x4c,     0x6c,     0x4d,     0x6d,     0x4e,     0x6e,                     // J j K k L l M m N n
+          0x4f,   0x6f,   0x274f,   0x276f,   0x604f,   0x606f,   0x3f4f,   0x3f6f,   0x7e4f,   0x7e6f,   0x2e4f,   0x2e6f, //o
+        0x5e4f, 0x5e6f, 0x275e4f, 0x275e6f, 0x605e4f, 0x605e6f, 0x3f5e4f, 0x3f5e6f, 0x7e5e4f, 0x7e5e6f, 0x2e5e4f, 0x2e5e6f, //o^
+        0x2b4f, 0x2b6f, 0x272b4f, 0x272b6f, 0x602b4f, 0x602b6f, 0x3f2b4f, 0x3f2b6f, 0x7e2b4f, 0x7e2b6f, 0x2e2b4f, 0x2e2b6f, //o+
+          0x50,   0x70,     0x51,     0x71,     0x52,     0x72,     0x53,     0x73,     0x54,     0x74,                     //P p Q q R r S s T t
+       0x55,   0x75,   0x2755,   0x2775,   0x6055,   0x6075,   0x3f55,   0x3f75,   0x7e55,   0x7e75,   0x2e55,   0x2e75, //u
+        0x2b55, 0x2b75, 0x272b55, 0x272b75, 0x602b55, 0x602b75, 0x3f2b55, 0x3f2b75, 0x7e2b55, 0x7e2b75, 0x2e2b55, 0x2e2b75, //u+
+       0x56,   0x76,     0x57,     0x77,     0x58,     0x78,                                                 // V v W w X x
+          0x59,   0x79,   0x2759,   0x2779,   0x6059,   0x6079,   0x3f59,   0x3f79,   0x7e59,   0x7e79,   0x2e59,   0x2e79, 
+       0x5a,   0x7a,                                                                                // Z z
+          0x80, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88,
+          0x89, 0x8A, 0x8B, 0x8C, 0x8E, 0x91, 0x92, 0x93,
+          0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B,
+          0x9C, 0x9E, 0x9F};
+
+
+UKDWORD UnicodeComposite[TOTAL_VNCHARS] = 
+{ 0x00000041, 0x00000061, 0x03010041, 0x03010061, 0x03000041, 0x03000061, //a
+  0x03090041, 0x03090061, 0x03030041, 0x03030061, 0x03230041, 0x03230061, //a
+
+  0x000000c2, 0x000000e2, 0x030100c2, 0x030100e2, 0x030000c2, 0x030000e2, 
+  0x030900c2, 0x030900e2, 0x030300c2, 0x030300e2, 0x032300c2, 0x032300e2, //a^
+
+  0x00000102, 0x00000103, 0x03010102, 0x03010103, 0x03000102, 0x03000103,
+  0x03090102, 0x03090103, 0x03030102, 0x03030103, 0x03230102, 0x03230103, //a(
+  
+  0x0042, 0x0062, 0x0043, 0x0063, 0x0044, 0x0064, //B b C c D d
+  0x0110, 0x0111, //0x00d1, 0x00f1, //DD, dd
+
+  0x00000045, 0x00000065, 0x03010045, 0x03010065, 0x03000045, 0x03000065, 
+  0x03090045, 0x03090065, 0x03030045, 0x03030065, 0x03230045, 0x03230065, //e
+
+  0x000000ca, 0x000000ea, 0x030100ca, 0x030100ea, 0x030000ca, 0x030000ea,
+  0x030900ca, 0x030900ea, 0x030300ca, 0x030300ea, 0x032300ca, 0x032300ea, //e^
+
+  0x0046, 0x0066, 0x0047, 0x0067, 0x0048, 0x0068, // F f G g H h
+  
+  0x00000049, 0x00000069, 0x03010049, 0x03010069, 0x03000049, 0x03000069,
+  0x03090049, 0x03090069, 0x03030049, 0x03030069, 0x03230049, 0x03230069, //i
+
+  0x004a, 0x006a, 0x004b, 0x006b, 0x004c, 0x006c, 0x004d, 0x006d, 0x004e, 0x006e,  // J j K k L l M m N n
+
+  0x0000004f, 0x0000006f, 0x0301004f, 0x0301006f, 0x0300004f, 0x0300006f, 
+  0x0309004f, 0x0309006f, 0x0303004f, 0x0303006f, 0x0323004f, 0x0323006f, //o
+  
+  0x000000d4, 0x000000f4, 0x030100d4, 0x030100f4, 0x030000d4, 0x030000f4, 
+  0x030900d4, 0x030900f4, 0x030300d4, 0x030300f4, 0x032300d4, 0x032300f4, //o^
+
+  0x000001a0, 0x000001a1, 0x030101a0, 0x030101a1, 0x030001a0, 0x030001a1,
+  0x030901a0, 0x030901a1, 0x030301a0, 0x030301a1, 0x032301a0, 0x032301a1, //o+
+  
+  0x0050, 0x0070, 0x0051, 0x0071, 0x0052, 0x0072, 0x0053, 0x0073, 0x0054, 0x0074,                 //P p Q q R r S s T t
+
+  0x00000055, 0x00000075, 0x03010055, 0x03010075, 0x03000055, 0x03000075,
+  0x03090055, 0x03090075, 0x03030055, 0x03030075, 0x03230055, 0x03230075, //u
+
+  0x000001af, 0x000001b0, 0x030101af, 0x030101b0, 0x030001af, 0x030001b0,
+  0x030901af, 0x030901b0, 0x030301af, 0x030301b0, 0x032301af, 0x032301b0, //u+
+
+  0x0056, 0x0076, 0x0057, 0x0077, 0x0058, 0x0078, // V v W w X x
+
+  0x00000059, 0x00000079, 0x03010059, 0x03010079, 0x03000059, 0x03000079,
+  0x03090059, 0x03090079, 0x03030059, 0x03030079, 0x03230059, 0x03230079, //y
+  0x005a, 0x007a, // Z z
+// Symbols that have different code points in Unicode and Western charsets
+  0x20AC, 0x20A1, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021, 0x02C6,
+  0x2030, 0x0160, 0x2039, 0x0152, 0x017D, 0x2018, 0x2019, 0x201C,
+  0x201D, 0x2022, 0x2013, 0x2014, 0x02DC, 0x2122, 0x0161, 0x203A, 
+  0x0153, 0x017E, 0x0178};
+
+int StdVnRootChar[TOTAL_VNCHARS] = {
+  0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, //a [A=0]
+  0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, //a^ -> a
+  0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, //a( -> a
+  36, 37, 38, 39, 40, 41, // bcd [D=40, d=41]
+  40, 41,                 // DD dd [mapped to D, d]
+  44, 45, 44, 45, 44, 45, 44, 45, 44, 45, 44, 45, // 3: e [E = 44]
+  44, 45, 44, 45, 44, 45, 44, 45, 44, 45, 44, 45, // 4: e^ -> e
+  68, 69, 70, 71, 72, 73, // fgh
+  74, 75, 74, 75, 74, 75, 74, 75, 74, 75, 74, 75, // 5: i
+  86, 87, 88, 89, 90, 91, 92, 93, 94, 95,  //jklmn
+  96, 97, 96, 97, 96, 97, 96, 97, 96, 97, 96, 97, // 6: o [o=96]
+  96, 97, 96, 97, 96, 97, 96, 97, 96, 97, 96, 97, // 7: o^ -> o
+  96, 97, 96, 97, 96, 97, 96, 97, 96, 97, 96, 97, // 8: o+ -> o
+  132, 133, 134, 135, 136, 137, 138, 139, 140, 141, // pqrst
+  142, 143, 142, 143, 142, 143, 142, 143, 142, 143, 142, 143, // 9: u [U=142]
+  142, 143, 142, 143, 142, 143, 142, 143, 142, 143, 142, 143, //10: u+ -> u
+  166, 167, 168, 169, 170, 171, //vwx
+  172, 173, 172, 173, 172, 173, 172, 173, 172, 173, 172, 173, //11: y [Y=172]
+  184, 185, // z
+  186, 187, 188, 189, 190, 191, 192, 193,
+  194, 195, 196, 197, 198, 199, 200, 201,
+  202, 203, 204, 205, 206, 207, 208, 209,
+  210, 211, 212
+};
+
+int StdVnNoTone[TOTAL_VNCHARS] = {
+  0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, //a [A=0]
+  12, 13, 12, 13, 12, 13, 12, 13, 12, 13, 12, 13, //a^
+  24, 25, 24, 25, 24, 25, 24, 25, 24, 25, 24, 25, //a(
+  36, 37, 38, 39, 40, 41, // bcd [D=40, d=41]
+  42, 43,                 // DD dd
+  44, 45, 44, 45, 44, 45, 44, 45, 44, 45, 44, 45, // 3: e [E = 44]
+  56, 57, 56, 57, 56, 57, 56, 57, 56, 57, 56, 57, // 4: e^
+  68, 69, 70, 71, 72, 73, // fgh
+  74, 75, 74, 75, 74, 75, 74, 75, 74, 75, 74, 75, // 5: i
+  86, 87, 88, 89, 90, 91, 92, 93, 94, 95,  //jklmn
+  96, 97, 96, 97, 96, 97, 96, 97, 96, 97, 96, 97, // 6: o [o=96]
+  108, 109, 108, 109, 108, 109, 108, 109, 108, 109, 108, 109, // 7: o^
+  120, 121, 120, 121, 120, 121, 120, 121, 120, 121, 120, 121, // 8: o+
+  132, 133, 134, 135, 136, 137, 138, 139, 140, 141, // pqrst
+  142, 143, 142, 143, 142, 143, 142, 143, 142, 143, 142, 143, // 9: u [U=142]
+  154, 155, 154, 155, 154, 155, 154, 155, 154, 155, 154, 155, //10: u+ 
+  166, 167, 168, 169, 170, 171, //vwx
+  172, 173, 172, 173, 172, 173, 172, 173, 172, 173, 172, 173, //11: y [Y=172]
+  184, 185, // z
+  186, 187, 188, 189, 190, 191, 192, 193,
+  194, 195, 196, 197, 198, 199, 200, 201,
+  202, 203, 204, 205, 206, 207, 208, 209,
+  210, 211, 212
+};
diff --git a/ukengine/data.h b/ukengine/data.h
new file mode 100644 (file)
index 0000000..d4b2be8
--- /dev/null
@@ -0,0 +1,11 @@
+// -*- coding:unix; mode:c++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
+#ifndef VIETNAMESE_CHARSET_DATA_H
+#define VIETNAMESE_CHARSET_DATA_H
+
+// This header defines some special characters
+const StdVnChar StdStartQuote = (VnStdCharOffset + 201);  // 0x93 in the Western charset
+// 201 is the offset of character 0x93 (start quote) in Vn charsets
+const StdVnChar StdEndQuote = (VnStdCharOffset + 202); // 0x94 in the Western charset
+const StdVnChar StdEllipsis = (VnStdCharOffset + 190); // 0x85 in Western charet.
+
+#endif
diff --git a/ukengine/diff/byteio.cpp.diff b/ukengine/diff/byteio.cpp.diff
new file mode 100644 (file)
index 0000000..2731f0a
--- /dev/null
@@ -0,0 +1,9 @@
+--- orginal/byteio.cpp 2009-04-14 00:16:33.000000000 +0700
++++ byteio.cpp 2009-06-12 10:41:04.000000000 +0700
+@@ -1,5 +1,5 @@
+ // -*- coding:unix; mode:c++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
+-#include "prehdr.h"
++#include <string.h>
+ #include "byteio.h"
+ //------------------------------------------------
diff --git a/ukengine/diff/charset.cpp.diff b/ukengine/diff/charset.cpp.diff
new file mode 100644 (file)
index 0000000..a88534b
--- /dev/null
@@ -0,0 +1,30 @@
+--- orginal/charset.cpp        2009-04-14 00:16:33.000000000 +0700
++++ charset.cpp        2009-06-12 10:44:20.000000000 +0700
+@@ -20,7 +20,6 @@
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ --------------------------------------------------------------------------------*/
+-#include "stdafx.h"
+ #include <stddef.h>
+ #include <search.h>
+ #include <memory.h>
+@@ -690,7 +689,7 @@
+ unsigned char VIQRTones[] = {'\'','`','?','~','.'};
+-char *VIQREscapes[] = {
++const char *VIQREscapes[] = {
+       "://",
+       "/",
+       "@",
+@@ -1028,8 +1027,8 @@
+               m_dbCharsets[i] = NULL;
+       VnConvResetOptions(&m_options);
+-      m_VIQREscPatterns.init(VIQREscapes, VIQREscCount);
+-      m_VIQROutEscPatterns.init(VIQREscapes, VIQREscCount);
++      m_VIQREscPatterns.init((char**)VIQREscapes, VIQREscCount);
++      m_VIQROutEscPatterns.init((char**)VIQREscapes, VIQREscCount);
+ }
diff --git a/ukengine/diff/convert.cpp.diff b/ukengine/diff/convert.cpp.diff
new file mode 100644 (file)
index 0000000..157f1bf
--- /dev/null
@@ -0,0 +1,70 @@
+--- orginal/convert.cpp        2009-04-14 00:16:33.000000000 +0700
++++ convert.cpp        2009-06-12 14:00:32.000000000 +0700
+@@ -20,7 +20,6 @@
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ --------------------------------------------------------------------------------*/
+-#include "stdafx.h"
+ #include "charset.h"
+ #include <stdio.h>
+ #include <stdlib.h>
+@@ -118,7 +117,7 @@
+       FILE *inf = NULL;
+       FILE *outf = NULL;
+       int ret = 0;
+-      char *tmpName = NULL;
++      char tmpName[32];
+       if (inFile == NULL) {
+               inf = stdin;
+@@ -152,9 +151,10 @@
+               else
+                       *p = 0;
+-              tmpName = tempnam(outDir, NULL);
++              strcpy(tmpName, outDir);
++        strcat(tmpName, "XXXXXX");
+-              if (tmpName == NULL) {
++              if (mkstemp(tmpName) == -1) {
+                       fclose(inf);
+                       ret = VNCONV_ERR_OUTPUT_FILE;
+                       goto end;
+@@ -163,7 +163,6 @@
+               if (outf == NULL) {
+                       fclose(inf);
+-                      free(tmpName);
+                       ret = VNCONV_ERR_OUTPUT_FILE; 
+                       goto end;
+               }
+@@ -182,11 +181,10 @@
+ #if !defined(_WIN32)
+                       char cmd[256];
+                       sprintf(cmd, "mv %s %s", tmpName, outFile);
+-                      system(cmd);
++                      int tmp = system(cmd);
+ #else
+                       if (rename(tmpName, outFile) != 0) {
+                               remove(tmpName);
+-                              free(tmpName);
+                               ret = VNCONV_ERR_OUTPUT_FILE;
+                               goto end;
+                       }
+@@ -194,7 +192,6 @@
+               }
+               else 
+                       remove(tmpName);
+-              free(tmpName);
+       }
+ end:
+@@ -235,7 +232,7 @@
+       return genConvert(*pInCharset, *pOutCharset, is, os);
+ }
+-char *ErrTable[VNCONV_LAST_ERROR] = 
++const char *ErrTable[VNCONV_LAST_ERROR] = 
+ {"No error",
+  "Unknown error",
+  "Invalid charset",
diff --git a/ukengine/diff/data.cpp.diff b/ukengine/diff/data.cpp.diff
new file mode 100644 (file)
index 0000000..e90e908
--- /dev/null
@@ -0,0 +1,10 @@
+--- orginal/data.cpp   2009-04-14 00:16:33.000000000 +0700
++++ data.cpp   2009-06-12 10:41:59.000000000 +0700
+@@ -20,7 +20,6 @@
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ --------------------------------------------------------------------------------*/
+-#include "stdafx.h"
+ #include "charset.h"
+ /*
diff --git a/ukengine/diff/inputproc.cpp.diff b/ukengine/diff/inputproc.cpp.diff
new file mode 100644 (file)
index 0000000..8c44a24
--- /dev/null
@@ -0,0 +1,11 @@
+--- orginal/inputproc.cpp      2009-04-14 00:16:33.000000000 +0700
++++ inputproc.cpp      2009-06-12 10:42:12.000000000 +0700
+@@ -20,7 +20,7 @@
+  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+  * Boston, MA 02111-1307, USA.
+  */
+-#include "stdafx.h"
++
+ #include <iostream>
+ #include "inputproc.h"
diff --git a/ukengine/diff/mactab.cpp.diff b/ukengine/diff/mactab.cpp.diff
new file mode 100644 (file)
index 0000000..9df69b1
--- /dev/null
@@ -0,0 +1,20 @@
+--- orginal/mactab.cpp 2009-04-14 00:16:33.000000000 +0700
++++ mactab.cpp 2009-06-12 10:45:07.000000000 +0700
+@@ -20,7 +20,7 @@
+  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+  * Boston, MA 02111-1307, USA.
+  */
+-#include "stdafx.h"
++
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+@@ -311,7 +311,7 @@
+   char key[MAX_MACRO_KEY_LEN];
+   
+   // Parse the input item
+-  char * pos = strchr(item, ':');
++  char * pos = (char*)strchr(item, ':');
+   if (pos == NULL)
+     return -1;
+   int keyLen = (int)(pos - item);
diff --git a/ukengine/diff/pattern.cpp.diff b/ukengine/diff/pattern.cpp.diff
new file mode 100644 (file)
index 0000000..832e973
--- /dev/null
@@ -0,0 +1,11 @@
+--- orginal/pattern.cpp        2009-04-14 00:16:33.000000000 +0700
++++ pattern.cpp        2009-06-12 10:42:40.000000000 +0700
+@@ -19,7 +19,7 @@
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ --------------------------------------------------------------------------------*/
+-#include "stdafx.h"
++
+ #include "pattern.h"
+ //////////////////////////////////////////////////
diff --git a/ukengine/diff/prehdr.h.diff b/ukengine/diff/prehdr.h.diff
new file mode 100644 (file)
index 0000000..9073fde
--- /dev/null
@@ -0,0 +1,26 @@
+--- orginal/prehdr.h   2009-04-14 00:16:33.000000000 +0700
++++ prehdr.h   1970-01-01 07:00:00.000000000 +0700
+@@ -1,23 +0,0 @@
+-// stdafx.h : include file for standard system include files,
+-//  or project specific include files that are used frequently, but
+-//      are changed infrequently
+-//
+-
+-#if !defined(AFX_STDAFX_H__E9288DDD_DB2B_413C_A8E3_E079B0E3C763__INCLUDED_)
+-#define AFX_STDAFX_H__E9288DDD_DB2B_413C_A8E3_E079B0E3C763__INCLUDED_
+-
+-#if _MSC_VER > 1000
+-#pragma once
+-#endif // _MSC_VER > 1000
+-
+-#define WIN32_LEAN_AND_MEAN           // Exclude rarely-used stuff from Windows headers
+-
+-
+-// TODO: reference additional headers your program requires here
+-#include <stdio.h>
+-#include <memory.h>
+-
+-//{{AFX_INSERT_LOCATION}}
+-// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
+-
+-#endif // !defined(AFX_STDAFX_H__E9288DDD_DB2B_413C_A8E3_E079B0E3C763__INCLUDED_)
diff --git a/ukengine/diff/stdafx.h.diff b/ukengine/diff/stdafx.h.diff
new file mode 100644 (file)
index 0000000..6134327
--- /dev/null
@@ -0,0 +1,20 @@
+--- orginal/stdafx.h   2009-04-14 00:16:33.000000000 +0700
++++ stdafx.h   1970-01-01 07:00:00.000000000 +0700
+@@ -1,17 +0,0 @@
+-// stdafx.h : include file for standard system include files,
+-// or project specific include files that are used frequently, but
+-// are changed infrequently
+-//
+-
+-#pragma once
+-
+-#if defined(_WIN32)
+-
+-#define WIN32_LEAN_AND_MEAN           // Exclude rarely-used stuff from Windows headers
+-
+-// TODO: reference additional headers your program requires here
+-#include <windows.h>
+-#include <tchar.h>
+-#include <stdio.h>
+-
+-#endif
diff --git a/ukengine/diff/ukengine.cpp.diff b/ukengine/diff/ukengine.cpp.diff
new file mode 100644 (file)
index 0000000..e4e6ede
--- /dev/null
@@ -0,0 +1,11 @@
+--- orginal/ukengine.cpp       2009-04-14 00:16:33.000000000 +0700
++++ ukengine.cpp       2009-06-12 10:42:52.000000000 +0700
+@@ -20,7 +20,7 @@
+  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+  * Boston, MA 02111-1307, USA.
+  */
+-#include "stdafx.h"
++
+ #include <stdlib.h>
+ #include <string.h>
+ #include <iostream>
diff --git a/ukengine/diff/ukengine.h.diff b/ukengine/diff/ukengine.h.diff
new file mode 100644 (file)
index 0000000..d0bb060
--- /dev/null
@@ -0,0 +1,26 @@
+--- orginal/ukengine.h 2009-04-14 00:16:33.000000000 +0700
++++ ukengine.h 2009-06-12 10:45:23.000000000 +0700
+@@ -20,6 +20,7 @@
+  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+  * Boston, MA 02111-1307, USA.
+  */
++
+ #ifndef __UKENGINE_H
+ #define __UKENGINE_H
+@@ -97,6 +98,7 @@
+     int processMapChar(UkKeyEvent & ev);
+     int processTelexW(UkKeyEvent & ev);
+     int processEscChar(UkKeyEvent & ev);
++    bool lastWordIsNonVn();
+ protected:
+     static bool m_classInit;
+@@ -157,7 +159,6 @@
+     int processNoSpellCheck(UkKeyEvent & ev);
+     int processWordEnd(UkKeyEvent & ev);
+     void synchKeyStrokeBuffer();
+-    bool lastWordIsNonVn();
+     bool lastWordHasVnMark();
+ };
diff --git a/ukengine/diff/unikey.cpp.diff b/ukengine/diff/unikey.cpp.diff
new file mode 100644 (file)
index 0000000..5e660a4
--- /dev/null
@@ -0,0 +1,16 @@
+--- orginal/unikey.cpp 2009-04-14 01:13:02.000000000 +0700
++++ unikey.cpp 2009-06-12 10:45:31.000000000 +0700
+@@ -196,3 +196,13 @@
+     UnikeyBufChars = sizeof(UnikeyBuf);
+     MyKbEngine.restoreKeyStrokes(UnikeyBackspaces, UnikeyBuf, UnikeyBufChars, UnikeyOutput);
+ }
++
++bool UnikeyAtWordBeginning()
++{
++    return MyKbEngine.atWordBeginning();
++}
++
++bool UnikeyLastWordIsNonVn()
++{
++    return MyKbEngine.lastWordIsNonVn();
++}
diff --git a/ukengine/diff/unikey.h.diff b/ukengine/diff/unikey.h.diff
new file mode 100644 (file)
index 0000000..7a5d2a7
--- /dev/null
@@ -0,0 +1,12 @@
+--- orginal/unikey.h   2009-04-14 01:14:29.000000000 +0700
++++ unikey.h   2009-06-12 10:45:38.000000000 +0700
+@@ -109,6 +109,9 @@
+   //e.g: GD&DDT,QDDND...
+   //The engine will return to normal mode when a word-break occurs.
+   void UnikeySetSingleMode();
++
++  bool UnikeyAtWordBeginning();
++  bool UnikeyLastWordIsNonVn();
+ #if defined(__cplusplus)
+ }
+ #endif
diff --git a/ukengine/diff/usrkeymap.cpp.diff b/ukengine/diff/usrkeymap.cpp.diff
new file mode 100644 (file)
index 0000000..9334ff8
--- /dev/null
@@ -0,0 +1,28 @@
+--- orginal/usrkeymap.cpp      2009-04-14 01:12:54.000000000 +0700
++++ usrkeymap.cpp      2009-06-12 10:45:46.000000000 +0700
+@@ -21,13 +21,15 @@
+  * Boston, MA 02111-1307, USA.
+  */
+-#include "stdafx.h"
+ #include <iostream>
++#include <string.h>
++#include <stdio.h>
+ using namespace std;
+ #include <ctype.h>
+ #include "usrkeymap.h"
++
+ int getLabelIndex(int action);
+ void initKeyMap(int keyMap[256]);
+@@ -226,7 +228,7 @@
+         keyMap[c] = vneNormal;
+ }
+-char *UkKeyMapHeader = 
++const char *UkKeyMapHeader = 
+     "; This is UniKey user-defined key mapping file, generated from UniKey (Windows)\n\n";
+ DllExport int UkStoreKeyOrderMap(const char *fileName, UkKeyMapPair *pMap, int mapCount)
diff --git a/ukengine/diff/vnconv.h.diff b/ukengine/diff/vnconv.h.diff
new file mode 100644 (file)
index 0000000..9d6bb3d
--- /dev/null
@@ -0,0 +1,19 @@
+--- orginal/vnconv.h   2009-04-14 00:16:33.000000000 +0700
++++ vnconv.h   2009-06-12 10:45:58.000000000 +0700
+@@ -19,6 +19,7 @@
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ --------------------------------------------------------------------------------*/
++
+ //
+ #ifndef __VN_CONVERT_H
+ #define __VN_CONVERT_H
+@@ -99,7 +100,7 @@
+ typedef struct _CharsetNameId CharsetNameId;
+ struct _CharsetNameId {
+-      char *name;
++      const char *name;
+       int id;
+ };
diff --git a/ukengine/error.cpp b/ukengine/error.cpp
new file mode 100644 (file)
index 0000000..4b73526
--- /dev/null
@@ -0,0 +1,46 @@
+// -*- coding:unix; mode:c++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
+/*------------------------------------------------------------------------------
+VnConv: Vietnamese Encoding Converter Library
+UniKey Project: http://unikey.sourceforge.net
+Copyleft (C) 1998-2002 Pham Kim Long
+Contact: longp@cslab.felk.cvut.cz
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+--------------------------------------------------------------------------------*/
+// For some unknown reasons, the functions in this file cannot be exported
+// We had to move them to convert.cpp.
+// TODO: inspect this problem later!
+/*
+#include "stdafx.h"
+#include "vnconv.h"
+
+char *ErrTable[VNCONV_LAST_ERROR] = 
+{"No error",
+ "Unknown error",
+ "Invalid charset",
+ "Error opening input file",
+ "Error opening output file",
+ "Error writing to output stream",
+ "Not enough memory",
+};
+
+DllExport const char * VnConvErrMsg(int errCode)
+{
+       if (errCode < 0 || errCode >= VNCONV_LAST_ERROR)
+               errCode = VNCONV_UNKNOWN_ERROR;
+       return ErrTable[errCode];
+}
+
+*/
\ No newline at end of file
diff --git a/ukengine/inputproc.cpp b/ukengine/inputproc.cpp
new file mode 100644 (file)
index 0000000..1dd7c4b
--- /dev/null
@@ -0,0 +1,380 @@
+// -*- mode:c++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
+/* Unikey Vietnamese Input Method
+ * Copyright (C) 2000-2005 Pham Kim Long
+ * Contact:
+ *   unikey@gmail.com
+ *   UniKey project: http://unikey.org
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <iostream>
+#include "inputproc.h"
+
+using namespace std;
+
+/*
+unsigned char WordBreakSyms[] = {
+       ',', ';', ':', '.', '\"', '\'', '!', '?', ' ',
+       '<', '>', '=', '+', '-', '*', '/', '\\',
+       '_', '~', '`', '@', '#', '$', '%', '^', '&', '(', ')', '{', '}', '[', ']'};
+*/
+
+unsigned char WordBreakSyms[] = {
+       ',', ';', ':', '.', '\"', '\'', '!', '?', ' ',
+       '<', '>', '=', '+', '-', '*', '/', '\\',
+       '_', '@', '#', '$', '%', '&', '(', ')', '{', '}', '[', ']', '|'}; //we excluded ~, `, ^
+
+VnLexiName AZLexiUpper[] = 
+  {vnl_A, vnl_B, vnl_C, vnl_D, vnl_E, vnl_F, vnl_G, vnl_H, vnl_I, vnl_J,
+   vnl_K, vnl_L, vnl_M, vnl_N, vnl_O, vnl_P, vnl_Q, vnl_R, vnl_S, vnl_T,
+   vnl_U, vnl_V, vnl_W, vnl_X, vnl_Y, vnl_Z};
+
+VnLexiName AZLexiLower[] =
+  {vnl_a, vnl_b, vnl_c, vnl_d, vnl_e, vnl_f, vnl_g, vnl_h, vnl_i, vnl_j,
+   vnl_k, vnl_l, vnl_m, vnl_n, vnl_o, vnl_p, vnl_q, vnl_r, vnl_s, vnl_t,
+   vnl_u, vnl_v, vnl_w, vnl_x, vnl_y, vnl_z};
+
+UkCharType UkcMap[256];
+
+struct _ascVnLexi {
+    int asc;
+    VnLexiName lexi;
+};
+
+//List of western characters outside range A-Z that are
+//also Vietnamese characters
+_ascVnLexi AscVnLexiList[] = {
+    {0xC0, vnl_A2},
+    {0xC1, vnl_A1},
+    {0xC2, vnl_Ar},
+    {0xC2, vnl_A4},
+    {0xC8, vnl_E2},
+    {0xC9, vnl_E1},
+    {0xCA, vnl_Er},
+    {0xCC, vnl_I2},
+    {0xCD, vnl_I1},
+    {0xD2, vnl_O2},
+    {0xD3, vnl_O1},
+    {0xD4, vnl_Or},
+    {0xD5, vnl_O4},
+    {0xD9, vnl_U2},
+    {0xDA, vnl_U1},
+    {0xDD, vnl_Y1},
+    {0xE0, vnl_a2},
+    {0xE1, vnl_a1},
+    {0xE2, vnl_ar},
+    {0xE3, vnl_a4},
+    {0xE8, vnl_e2},
+    {0xE9, vnl_e1},
+    {0xEA, vnl_er},
+    {0xEC, vnl_i2},
+    {0xED, vnl_i1},
+    {0xF2, vnl_o2},
+    {0xF3, vnl_o1},
+    {0xF4, vnl_or},
+    {0xF5, vnl_o4},
+    {0xF9, vnl_u2},
+    {0xFA, vnl_u1},
+    {0xFD, vnl_y1},
+    {0x00, vnl_nonVnChar}
+};
+
+VnLexiName IsoVnLexiMap[256];
+
+bool ClassifierTableInitialized = false;
+
+DllExport UkKeyMapping TelexMethodMapping[] = {
+    {'Z', vneTone0},
+    {'S', vneTone1},
+    {'F', vneTone2},
+    {'R', vneTone3},
+    {'X', vneTone4},
+    {'J', vneTone5},
+    {'W', vne_telex_w},
+    {'A', vneRoof_a},
+    {'E', vneRoof_e},
+    {'O', vneRoof_o},
+    {'D', vneDd},
+    {'[', vneCount + vnl_oh},
+    {']', vneCount + vnl_uh},
+    {'{', vneCount + vnl_Oh},
+    {'}', vneCount + vnl_Uh},
+    {0, vneNormal}
+};
+
+DllExport UkKeyMapping SimpleTelexMethodMapping[] = {
+    {'Z', vneTone0},
+    {'S', vneTone1},
+    {'F', vneTone2},
+    {'R', vneTone3},
+    {'X', vneTone4},
+    {'J', vneTone5},
+    {'W', vneHookAll},
+    {'A', vneRoof_a},
+    {'E', vneRoof_e},
+    {'O', vneRoof_o},
+    {'D', vneDd},
+    {0, vneNormal}
+};
+
+DllExport UkKeyMapping VniMethodMapping[] = {
+    {'0', vneTone0},
+    {'1', vneTone1},
+    {'2', vneTone2},
+    {'3', vneTone3},
+    {'4', vneTone4},
+    {'5', vneTone5},
+    {'6', vneRoofAll},
+    {'7', vneHook_uo},
+    {'8', vneBowl},
+    {'9', vneDd},
+    {0, vneNormal}
+};
+
+DllExport UkKeyMapping VIQRMethodMapping[] = {
+    {'0', vneTone0},
+    {'\'', vneTone1},
+    {'`', vneTone2},
+    {'?', vneTone3},
+    {'~', vneTone4},
+    {'.', vneTone5},
+    {'^', vneRoofAll},
+    {'+', vneHook_uo},
+    {'*', vneHook_uo},
+    {'(', vneBowl},
+    {'D', vneDd},
+    {'\\', vneEscChar},
+    {0, vneNormal}
+};
+
+DllExport UkKeyMapping MsViMethodMapping[] = {
+    {'5', vneTone2},
+    {'%', vneTone2},
+    {'6', vneTone3},
+    {'^', vneTone3},
+    {'7', vneTone4},
+    {'&', vneTone4},
+    {'8', vneTone1},
+    {'*', vneTone1},
+    {'9', vneTone5},
+    {'(', vneTone5},
+    {'1', vneCount + vnl_ab},
+    {'!', vneCount + vnl_Ab},
+    {'2', vneCount + vnl_ar},
+    {'@', vneCount + vnl_Ar},
+    {'3', vneCount + vnl_er},
+    {'#', vneCount + vnl_Er},
+    {'4', vneCount + vnl_or},
+    {'$', vneCount + vnl_Or},
+    {'0', vneCount + vnl_dd},
+    {')', vneCount + vnl_DD},
+    {'[', vneCount + vnl_uh},
+    {']', vneCount + vnl_oh},
+    {'{', vneCount + vnl_Uh},
+    {'}', vneCount + vnl_Oh},
+    {0, vneNormal}
+};
+
+//-------------------------------------------
+void SetupInputClassifierTable()
+{
+  unsigned int c;
+  int i;
+
+  for (c=0; c<=32; c++) {
+    UkcMap[c] = ukcReset;
+  }
+
+  for (c=33; c<256; c++) {
+    UkcMap[c] = ukcNonVn;
+  }
+
+  /*
+  for (c = '0'; c <= '9'; c++)
+    UkcMap[c] = ukcNonVn;
+  */
+
+  for (c = 'a'; c <= 'z'; c++)
+    UkcMap[c] = ukcVn;
+  for (c = 'A'; c <= 'Z'; c++)
+    UkcMap[c] = ukcVn;
+
+  for (i=0; AscVnLexiList[i].asc; i++) {
+      UkcMap[AscVnLexiList[i].asc] = ukcVn;
+  }
+
+  UkcMap[(unsigned char)'j'] = ukcNonVn;
+  UkcMap[(unsigned char)'J'] = ukcNonVn;
+  UkcMap[(unsigned char)'f'] = ukcNonVn;
+  UkcMap[(unsigned char)'F'] = ukcNonVn;
+  UkcMap[(unsigned char)'w'] = ukcNonVn;
+  UkcMap[(unsigned char)'W'] = ukcNonVn;
+
+  int count = sizeof(WordBreakSyms)/sizeof(unsigned char);
+  for (i = 0; i < count; i++)
+    UkcMap[WordBreakSyms[i]] = ukcWordBreak;
+
+  //Calculate IsoVnLexiMap
+  for (i = 0; i < 256; i++) {
+      IsoVnLexiMap[i] = vnl_nonVnChar;
+  }
+
+  for (i = 0; AscVnLexiList[i].asc; i++) {
+      IsoVnLexiMap[AscVnLexiList[i].asc] = AscVnLexiList[i].lexi;
+  }
+
+  for (c = 'a'; c <= 'z'; c++) {
+      IsoVnLexiMap[c] = AZLexiLower[c - 'a'];
+  }
+
+  for (c = 'A'; c <= 'Z'; c++) {
+      IsoVnLexiMap[c] = AZLexiUpper[c - 'A'];
+  }
+}
+
+//-------------------------------------------
+void UkInputProcessor::init()
+{
+  if (!ClassifierTableInitialized) {
+    SetupInputClassifierTable();
+    ClassifierTableInitialized = true;
+  }
+  setIM(UkTelex);
+}
+
+//-------------------------------------------
+int UkInputProcessor::setIM(UkInputMethod im)
+{
+    m_im = im;
+    switch (im) {
+        case UkTelex:
+            useBuiltIn(TelexMethodMapping);
+            break;
+        case UkVni:
+            useBuiltIn(VniMethodMapping);
+            break;
+        case UkViqr:
+            useBuiltIn(VIQRMethodMapping);
+            break;
+        case UkMsVi:
+            useBuiltIn(MsViMethodMapping);
+            break;
+        default:
+            m_im = UkTelex;
+            useBuiltIn(TelexMethodMapping);
+    }
+    return 1;
+}
+
+//-------------------------------------------
+int UkInputProcessor::setIM(int map[256])
+{
+  int i;
+  m_im = UkUsrIM;
+  for (i=0; i<256; i++)
+    m_keyMap[i] = map[i];
+  return 1;
+}
+  
+
+//-------------------------------------------
+void UkResetKeyMap(int keyMap[256])
+{
+  unsigned int c;
+  for (c=0; c<256; c++)
+    keyMap[c] = vneNormal;
+}
+
+//-------------------------------------------
+void UkInputProcessor::useBuiltIn(UkKeyMapping *map)
+{
+    UkResetKeyMap(m_keyMap);
+    for (int i=0; map[i].key; i++) {
+        m_keyMap[map[i].key] = map[i].action;
+        if (map[i].action < vneCount) {
+            if (islower(map[i].key)) {
+                m_keyMap[toupper(map[i].key)] = map[i].action;
+            }
+            else if (isupper(map[i].key)) {
+                m_keyMap[tolower(map[i].key)] = map[i].action;
+            }
+        }
+    }
+}
+
+//-------------------------------------------
+void UkInputProcessor::keyCodeToEvent(unsigned int keyCode, UkKeyEvent & ev)
+{
+    ev.keyCode = keyCode;
+    if (keyCode > 255) {
+        ev.evType = vneNormal;
+        ev.vnSym = IsoToVnLexi(keyCode);
+        ev.chType = (ev.vnSym == vnl_nonVnChar)? ukcNonVn : ukcVn;
+    }
+    else {
+        ev.chType = UkcMap[keyCode];
+        ev.evType = m_keyMap[keyCode];
+
+        if (ev.evType >= vneTone0 && ev.evType <= vneTone5) {
+            ev.tone = ev.evType - vneTone0;
+        }
+
+        if (ev.evType >= vneCount) {
+            ev.chType = ukcVn;
+            ev.vnSym = (VnLexiName)(ev.evType - vneCount);
+            ev.evType = vneMapChar;
+        }
+        else {
+            ev.vnSym = IsoToVnLexi(keyCode);
+        }
+    }
+}
+
+//----------------------------------------------------------------
+// This method translates a key stroke to a symbol.
+// Key strokes are simply considered character input, not action keys as in
+// keyCodeToEvent method
+//----------------------------------------------------------------
+void UkInputProcessor::keyCodeToSymbol(unsigned int keyCode, UkKeyEvent & ev)
+{
+    ev.keyCode = keyCode;
+    ev.evType = vneNormal;
+    ev.vnSym = IsoToVnLexi(keyCode);
+    if (keyCode > 255) {
+        ev.chType = (ev.vnSym == vnl_nonVnChar)? ukcNonVn : ukcVn;
+    }
+    else {
+        ev.chType = UkcMap[keyCode];
+    }
+}
+
+//-------------------------------------------
+UkCharType UkInputProcessor::getCharType(unsigned int keyCode)
+{
+  if (keyCode > 255)
+    return (IsoToVnLexi(keyCode) == vnl_nonVnChar) ? ukcNonVn : ukcVn;
+  return UkcMap[keyCode];
+}
+
+//-------------------------------------------
+void UkInputProcessor::getKeyMap(int map[256])
+{
+  int i;
+  for (i=0; i<256; i++)
+    map[i] = m_keyMap[i];
+}
+
diff --git a/ukengine/inputproc.h b/ukengine/inputproc.h
new file mode 100644 (file)
index 0000000..c344757
--- /dev/null
@@ -0,0 +1,124 @@
+// -*- coding:unix; mode:c++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
+/* Unikey Vietnamese Input Method
+ * Copyright (C) 2000-2005 Pham Kim Long
+ * Contact:
+ *   unikey@gmail.com
+ *   UniKey project: http://unikey.org
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#ifndef __UK_INPUT_PROCESSOR_H
+#define __UK_INPUT_PROCESSOR_H
+
+#include "keycons.h"
+#include "vnlexi.h"
+
+#if defined(_WIN32)
+    #define DllExport   __declspec( dllexport )
+    #define DllImport   __declspec( dllimport )
+    #if defined(UNIKEYHOOK)
+        #define DllInterface   __declspec( dllexport )
+    #else
+        #define DllInterface   __declspec( dllimport )
+    #endif
+#else
+    #define DllInterface //not used
+    #define DllExport
+    #define DllImport
+#endif
+
+enum UkKeyEvName {
+  vneRoofAll, vneRoof_a, vneRoof_e, vneRoof_o, 
+  vneHookAll, vneHook_uo, vneHook_u, vneHook_o, vneBowl, 
+  vneDd, 
+  vneTone0, vneTone1, vneTone2, vneTone3, vneTone4, vneTone5,
+  vne_telex_w, //special for telex
+  vneMapChar, //e.g. [ -> u+ , ] -> o+
+  vneEscChar,
+  vneNormal, //does not belong to any of the above categories
+  vneCount //just to count how many event types there are
+};
+
+enum UkCharType {
+  ukcVn,
+  ukcWordBreak, 
+  ukcNonVn, 
+  ukcReset
+};
+
+struct UkKeyEvent {
+  int evType;
+  UkCharType chType;
+  VnLexiName vnSym; //meaningful only when chType==ukcVn
+  unsigned int keyCode;
+  int tone; //meaningful only when this is a vowel
+};
+
+struct UkKeyMapping {
+    unsigned char key;
+    int action;
+};
+
+///////////////////////////////////////////
+class UkInputProcessor {
+
+public:
+  //don't do anything with constructor, because
+  //this object can be allocated in shared memory
+  //Use init method instead
+  //UkInputProcessor();
+  
+  void init();
+
+  UkInputMethod getIM()
+  {
+    return m_im;
+  }
+
+  void keyCodeToEvent(unsigned int keyCode, UkKeyEvent & ev);
+  void keyCodeToSymbol(unsigned int keyCode, UkKeyEvent & ev);
+  int setIM(UkInputMethod im);
+  int setIM(int map[256]);
+  void getKeyMap(int map[256]);
+
+  UkCharType getCharType(unsigned int keyCode);
+
+protected:
+  static bool m_classInit;
+
+  UkInputMethod m_im;
+  int m_keyMap[256];
+
+  void useBuiltIn(UkKeyMapping *map);
+
+};
+
+void UkResetKeyMap(int keyMap[256]);
+void SetupInputClassifierTable();
+
+DllInterface extern UkKeyMapping TelexMethodMapping[];
+DllInterface extern UkKeyMapping SimpleTelexMethodMapping[];
+DllInterface extern UkKeyMapping VniMethodMapping[];
+DllInterface extern UkKeyMapping VIQRMethodMapping[];
+DllInterface extern UkKeyMapping MsViMethodMapping[];
+
+extern VnLexiName IsoVnLexiMap[];
+inline VnLexiName IsoToVnLexi(int keyCode)
+{
+    return (keyCode >= 256)? vnl_nonVnChar : IsoVnLexiMap[keyCode];
+}
+
+#endif
diff --git a/ukengine/keycons.h b/ukengine/keycons.h
new file mode 100644 (file)
index 0000000..52cb2e4
--- /dev/null
@@ -0,0 +1,81 @@
+// -*- coding:unix; mode:c++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
+/*------------------------------------------------------------------------------
+UniKey - Open-source Vietnamese Keyboard
+Copyright (C) 1998-2004 Pham Kim Long
+Contact:
+  unikey@gmail.com
+  http://unikey.org
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+--------------------------------------------------------------------------------*/
+#ifndef __KEY_CONS_H
+#define __KEY_CONS_H
+
+// macro table constants
+#define MAX_MACRO_KEY_LEN 16
+//#define MAX_MACRO_TEXT_LEN 256
+#define MAX_MACRO_TEXT_LEN 1024
+#define MAX_MACRO_ITEMS 1024
+#define MAX_MACRO_LINE (MAX_MACRO_TEXT_LEN + MAX_MACRO_KEY_LEN)
+
+#define MACRO_MEM_SIZE (1024*128) //128 KB
+
+#define CP_US_ANSI 1252
+
+typedef enum {UkTelex, UkVni, UkViqr, UkMsVi, UkUsrIM, UkSimpleTelex} UkInputMethod;
+typedef struct _UnikeyOptions UnikeyOptions;
+
+struct _UnikeyOptions
+{
+  int freeMarking;
+  int modernStyle;
+  int macroEnabled;
+  int useUnicodeClipboard;
+  int alwaysMacro;
+  int strictSpellCheck;
+  int useIME; //for Win32 only
+  int spellCheckEnabled;
+  int autoNonVnRestore;
+};
+
+#define UKOPT_FLAG_ALL                   0xFFFFFFFF
+#define UKOPT_FLAG_FREE_STYLE            0x00000001
+//#define UKOPT_FLAG_MANUAL_TONE           0x00000002
+#define UKOPT_FLAG_MODERN                0x00000004
+#define UKOPT_FLAG_MACRO_ENABLED         0x00000008
+#define UKOPT_FLAG_USE_CLIPBOARD         0x00000010
+#define UKOPT_FLAG_ALWAYS_MACRO          0x00000020
+#define UKOPT_FLAG_STRICT_SPELL          0x00000040
+#define UKOPT_FLAG_USE_IME               0x00000080
+#define UKOPT_FLAG_SPELLCHECK_ENABLED   0x00000100
+
+#if defined(WIN32)
+typedef struct _UnikeySysInfo UnikeySysInfo;
+struct _UnikeySysInfo
+{
+  int switchKey;
+  HHOOK keyHook;
+  HHOOK mouseHook;
+  HWND hMainDlg;
+  UINT iconMsgId;
+  HICON hVietIcon,hEnIcon;
+  int unicodePlatform;
+  DWORD winMajorVersion, winMinorVersion;
+};
+#endif
+
+typedef enum {UkCharOutput, UkKeyOutput} UkOutputType;
+
+#endif
diff --git a/ukengine/mactab.cpp b/ukengine/mactab.cpp
new file mode 100644 (file)
index 0000000..9abfa57
--- /dev/null
@@ -0,0 +1,346 @@
+// -*- coding:unix; mode:c++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
+/* Unikey Vietnamese Input Method
+ * Copyright (C) 2000-2005 Pham Kim Long
+ * Contact:
+ *   unikey@gmail.com
+ *   UniKey project: http://unikey.org
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <iostream>
+#include "mactab.h"
+#include "vnconv.h"
+
+using namespace std;
+#define UKMACRO_VERSION_UTF8 1
+
+//---------------------------------------------------------------
+void CMacroTable::init()
+{
+  m_memSize = MACRO_MEM_SIZE;
+  m_count = 0;
+  m_occupied = 0;
+}
+
+//---------------------------------------------------------------
+char *MacCompareStartMem;
+
+#define STD_TO_LOWER(x) (((x) >= VnStdCharOffset && \
+                          (x) < (VnStdCharOffset + TOTAL_ALPHA_VNCHARS) && \
+                          !((x) & 1)) ? \
+                          (x+1) : (x))
+
+int macCompare(const void *p1, const void *p2)
+{
+    StdVnChar *s1 = (StdVnChar *) ((char *)MacCompareStartMem + ((MacroDef *)p1)->keyOffset);
+    StdVnChar *s2 = (StdVnChar *) ((char *)MacCompareStartMem + ((MacroDef *)p2)->keyOffset);
+
+    int i;
+    StdVnChar ls1, ls2;
+
+    for (i=0; s1[i] != 0 && s2[i] != 0; i++) {
+        ls1 = STD_TO_LOWER(s1[i]);
+        ls2 = STD_TO_LOWER(s2[i]);
+        if (ls1 > ls2)
+            return 1;
+        if (ls1 < ls2)
+            return -1;
+        /*
+        if (s1[i] > s2[i])
+            return 1;
+        if (s1[i] < s2[i])
+            return -1;
+        */
+    }
+    if (s1[i] == 0)
+        return (s2[i] == 0)? 0 : -1;
+    return 1;
+}
+
+//---------------------------------------------------------------
+int macKeyCompare(const void *key, const void *ele)
+{
+    StdVnChar *s1 = (StdVnChar *)key;
+    StdVnChar *s2 = (StdVnChar *) ((char *)MacCompareStartMem + ((MacroDef *)ele)->keyOffset);
+
+    StdVnChar ls1, ls2;
+    int i;
+    for (i=0; s1[i] != 0 && s2[i] != 0; i++) {
+        ls1 = STD_TO_LOWER(s1[i]);
+        ls2 = STD_TO_LOWER(s2[i]);
+        if (ls1 > ls2)
+            return 1;
+        if (ls1 < ls2)
+            return -1;
+        /*
+        if (s1[i] > s2[i])
+            return 1;
+        if (s1[i] < s2[i])
+            return -1;
+        */
+    }
+    if (s1[i] == 0)
+        return (s2[i] == 0)? 0 : -1;
+    return 1;
+}
+
+//---------------------------------------------------------------
+const StdVnChar *CMacroTable::lookup(StdVnChar *key)
+{
+  MacCompareStartMem = m_macroMem;
+  MacroDef *p = (MacroDef *)bsearch(key, m_table, m_count, sizeof(MacroDef), macKeyCompare);
+  if (p)
+    return (StdVnChar *)(m_macroMem + p->textOffset);
+  return 0;
+}
+
+//----------------------------------------------------------------------------
+// Read header, if it's present in the file. Get the version of the file
+// If header is absent, go back to the beginning of file and set version to 0
+// Return false if reading failed.
+//
+// Header format: ;[DO NOT DELETE THIS LINE]***version=n
+//----------------------------------------------------------------------------
+bool CMacroTable::readHeader(FILE *f, int & version)
+{
+    char line[MAX_MACRO_LINE];
+    if (!fgets(line, sizeof(line), f)) {
+        if (feof(f)) {
+            fseek(f, 0, SEEK_SET);
+            version = 0;
+            return true;
+        }
+        return false;
+    }
+
+    //if BOM is available, skip it
+    char *p = line;
+    size_t len = strlen(line);
+    if (len >= 3 && (unsigned char)line[0] == 0xEF && (unsigned char)line[1] == 0xBB && 
+                    (unsigned char)line[2] == 0xBF) 
+    {
+        p += 3;
+    }
+
+    //read version number
+    p = strstr(p, "***");
+    if (p) {
+        p += 3;
+        //skip possible spaces
+        while (*p == ' ') p++;
+        if (sscanf(p, "version=%d", &version) == 1)
+            return true;
+    }
+
+    fseek(f, 0, SEEK_SET);
+    version = 0;
+    return true;
+}
+
+//----------------------------------------------------------------
+void CMacroTable::writeHeader(FILE *f)
+{
+#if defined(WIN32)
+    fprintf(f, "\xEF\xBB\xBF;DO NOT DELETE THIS LINE*** version=%d ***\n", UKMACRO_VERSION_UTF8);
+#else
+    fprintf(f, "DO NOT DELETE THIS LINE*** version=%d ***\n", UKMACRO_VERSION_UTF8);
+#endif
+}
+//---------------------------------------------------------------
+int CMacroTable::loadFromFile(const char *fname)
+{
+    FILE *f;
+#if defined(WIN32)
+    f = _tfopen(fname, _TEXT("rt"));
+#else
+    f = fopen(fname, "r");
+#endif
+
+    if (f == NULL) 
+        return 0;
+    char line[MAX_MACRO_LINE];
+    size_t len;
+
+    resetContent();
+
+    //read possible header
+    int version;
+    if (!readHeader(f, version)) {
+        version = 0;
+    }
+
+    while (fgets(line, sizeof(line), f)) {
+        len = strlen(line);
+        if (len > 0 && line[len-1] == '\n')
+            line[len-1] = 0;
+        if (len > 1 && line[len-2] == '\r')
+            line[len-2] = 0;
+        if (version == UKMACRO_VERSION_UTF8)
+            addItem(line, CONV_CHARSET_UNIUTF8);
+        else
+            addItem(line, CONV_CHARSET_VIQR);
+    }
+    fclose(f);
+    MacCompareStartMem = m_macroMem;
+    qsort(m_table, m_count, sizeof(MacroDef), macCompare);
+    // Convert old version
+    if (version != UKMACRO_VERSION_UTF8) {
+        writeToFile(fname);
+    }
+    return 1;
+}
+
+//---------------------------------------------------------------
+int CMacroTable::writeToFile(const char *fname)
+{
+  int ret;
+  int inLen, maxOutLen;
+  FILE *f;
+#if defined(WIN32)
+  f = _tfopen(fname, _TEXT("wt"));
+#else
+  f = fopen(fname, "w");
+#endif
+
+  if (f == NULL)
+    return 0;
+
+  char line[MAX_MACRO_LINE*3]; //1 VnChar may need 3 chars in UTF8
+  char key[MAX_MACRO_KEY_LEN*3];
+  char text[MAX_MACRO_TEXT_LEN*3];
+
+  writeHeader(f);
+
+  UKBYTE *p;
+  for (int i=0; i < m_count; i++) {
+    p = (UKBYTE *)m_macroMem + m_table[i].keyOffset;
+    inLen = -1;
+    maxOutLen = sizeof(key);
+    ret = VnConvert(CONV_CHARSET_VNSTANDARD, CONV_CHARSET_UNIUTF8,
+                   (UKBYTE *) p, (UKBYTE *)key,
+                   &inLen, &maxOutLen);
+    if (ret != 0)
+      continue;
+
+    p = (UKBYTE *)m_macroMem + m_table[i].textOffset;
+    inLen = -1;
+    maxOutLen = sizeof(text);
+    ret = VnConvert(CONV_CHARSET_VNSTANDARD, CONV_CHARSET_UNIUTF8,
+                   p, (UKBYTE *)text,
+                   &inLen, &maxOutLen);
+    if (ret != 0)
+      continue;
+    if (i < m_count-1)
+      sprintf(line, "%s:%s\n", key, text);
+    else
+      sprintf(line, "%s:%s", key, text);
+    fputs(line, f);
+  }
+
+  fclose(f);
+  return 1;
+}
+
+//---------------------------------------------------------------
+int CMacroTable::addItem(const void *key, const void *text, int charset)
+{
+  int ret;
+  int inLen, maxOutLen;
+  int offset = m_occupied;
+  char *p = m_macroMem + offset;
+
+  if (m_count >= MAX_MACRO_ITEMS)
+    return -1;
+  
+  m_table[m_count].keyOffset = offset;
+
+  // Convert macro key to VN standard
+  inLen = -1; //input is null-terminated
+  maxOutLen = MAX_MACRO_KEY_LEN * sizeof(StdVnChar);
+  if (maxOutLen + offset > m_memSize)
+    maxOutLen = m_memSize - offset;
+  ret = VnConvert(charset, CONV_CHARSET_VNSTANDARD, 
+                         (UKBYTE *)key, (UKBYTE *)p,
+                         &inLen, &maxOutLen);
+  if (ret != 0)
+    return -1;
+
+  offset += maxOutLen;
+  p += maxOutLen;
+
+  //convert macro text to VN standard
+  m_table[m_count].textOffset = offset;
+  inLen = -1; //input is null-terminated
+  maxOutLen = MAX_MACRO_TEXT_LEN * sizeof(StdVnChar);
+  if (maxOutLen + offset > m_memSize)
+    maxOutLen = m_memSize - offset;
+  ret = VnConvert(charset, CONV_CHARSET_VNSTANDARD, 
+                 (UKBYTE *)text, (UKBYTE *)p,
+                 &inLen, &maxOutLen);
+  if (ret != 0)
+    return -1;
+
+  m_occupied = offset + maxOutLen;
+  m_count++;
+  return (m_count-1);
+}
+
+//---------------------------------------------------------------
+// add a new macro into the sorted macro table
+// item format: key:text (key and text are separated by a colon)
+//---------------------------------------------------------------
+int CMacroTable::addItem(const char *item, int charset)
+{
+  char key[MAX_MACRO_KEY_LEN];
+  
+  // Parse the input item
+  char * pos = (char*)strchr(item, ':');
+  if (pos == NULL)
+    return -1;
+  int keyLen = (int)(pos - item);
+  if (keyLen > MAX_MACRO_KEY_LEN-1)
+    keyLen = MAX_MACRO_KEY_LEN-1;
+  strncpy(key, item, keyLen);
+  key[keyLen] = '\0';
+  return addItem(key, ++pos, charset);
+}
+
+//---------------------------------------------------------------
+void CMacroTable::resetContent()
+{
+  m_occupied = 0;
+  m_count = 0;
+}
+
+//---------------------------------------------------------------
+const StdVnChar *CMacroTable::getKey(int idx)
+{
+    if (idx < 0 || idx >= m_count)
+        return 0;
+    return (StdVnChar *)(m_macroMem + m_table[idx].keyOffset);
+}
+
+//---------------------------------------------------------------
+const StdVnChar *CMacroTable::getText(int idx)
+{
+    if (idx < 0 || idx >= m_count)
+        return 0;
+    return (StdVnChar *)(m_macroMem + m_table[idx].textOffset);
+}
diff --git a/ukengine/mactab.h b/ukengine/mactab.h
new file mode 100644 (file)
index 0000000..c38965f
--- /dev/null
@@ -0,0 +1,78 @@
+// -*- coding:unix; mode:c++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
+/* Unikey Vietnamese Input Method
+ * Copyright (C) 2000-2005 Pham Kim Long
+ * Contact:
+ *   unikey@gmail.com
+ *   UniKey project: http://unikey.org
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __MACRO_TABLE_H
+#define __MACRO_TABLE_H
+
+#include "keycons.h"
+#include "charset.h"
+
+#if defined(_WIN32)
+    #if defined(UNIKEYHOOK)
+        #define DllInterface   __declspec( dllexport )
+    #else
+        #define DllInterface   __declspec( dllimport )
+    #endif
+#else
+    #define DllInterface //not used
+    #define DllExport
+    #define DllImport
+#endif
+
+struct MacroDef
+{
+  int keyOffset;
+  int textOffset;
+};
+
+#if !defined(WIN32)
+typedef char TCHAR;
+#endif
+
+class DllInterface CMacroTable
+{
+public:
+    void init();
+    int loadFromFile(const char *fname);
+    int writeToFile(const char *fname);
+
+    const StdVnChar *lookup(StdVnChar *key);
+    const StdVnChar *getKey(int idx);
+    const StdVnChar *getText(int idx);
+    int getCount() { return m_count; }
+    void resetContent();
+    int addItem(const char *item, int charset);
+    int addItem(const void *key, const void *text, int charset);
+
+protected:
+    bool readHeader(FILE *f, int & version);
+    void writeHeader(FILE *f);
+
+    MacroDef m_table[MAX_MACRO_ITEMS];
+    char m_macroMem[MACRO_MEM_SIZE];
+
+    int m_count;
+    int m_memSize, m_occupied;
+};
+
+#endif
diff --git a/ukengine/pattern.cpp b/ukengine/pattern.cpp
new file mode 100644 (file)
index 0000000..7e1f43b
--- /dev/null
@@ -0,0 +1,100 @@
+// -*- coding:unix; mode:c++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
+/*------------------------------------------------------------------------------
+VnConv: Vietnamese Encoding Converter Library
+UniKey Project: http://unikey.sourceforge.net
+Copyleft (C) 1998-2002 Pham Kim Long
+Contact: longp@cslab.felk.cvut.cz
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+--------------------------------------------------------------------------------*/
+
+#include "pattern.h"
+
+//////////////////////////////////////////////////
+// Pattern matching (based on KPM algorithm)
+//////////////////////////////////////////////////
+
+//----------------------------
+void PatternState::reset()
+{
+       m_pos = 0;
+       m_found = 0;
+}
+
+//----------------------------
+void PatternState::init(char *pattern)
+{
+       m_pos = 0;
+       m_found = 0;
+       m_pattern = pattern;
+
+       int i=0, j=-1;
+    m_border[i]=j;
+    while (m_pattern[i])
+    {
+        while (j>=0 && m_pattern[i]!=m_pattern[j]) j=m_border[j];
+        i++; j++;
+        m_border[i]=j;
+    }
+}
+
+//-----------------------------------------------------
+//get next input char, returns 1 if pattern is found.
+//-----------------------------------------------------
+int PatternState::foundAtNextChar(char ch)
+{
+       int ret = 0;
+       //int j = m_pos;
+       while (m_pos>=0 && ch!=m_pattern[m_pos]) m_pos=m_border[m_pos];
+       m_pos++;
+       if (m_pattern[m_pos]==0) {
+               m_found++;
+               m_pos = m_border[m_pos];
+               ret = 1;
+       }
+       return ret;
+}
+
+//-----------------------------------------------------
+void PatternList::init(char **patterns, int count)
+{
+       m_count = count;
+       delete [] m_patterns;
+       m_patterns = new PatternState[count];
+       for (int i=0; i<count; i++)
+               m_patterns[i].init(patterns[i]);
+}
+
+//-----------------------------------------------------
+// return the order number of the pattern that is found.
+// If more than 1 pattern is found, returns any pattern
+// Returns -1 if no pattern is found
+//-----------------------------------------------------
+int PatternList::foundAtNextChar(char ch)
+{
+       int patternFound = -1;
+       for (int i=0; i<m_count; i++) {
+               if (m_patterns[i].foundAtNextChar(ch))
+                       patternFound = i;
+       }
+       return patternFound;
+}
+
+//-----------------------------------------------------
+void PatternList::reset()
+{
+       for (int i=0; i<m_count; i++)
+               m_patterns[i].reset();
+}
diff --git a/ukengine/pattern.h b/ukengine/pattern.h
new file mode 100644 (file)
index 0000000..d26fe55
--- /dev/null
@@ -0,0 +1,72 @@
+// -*- coding:unix; mode:c++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
+/*------------------------------------------------------------------------------
+VnConv: Vietnamese Encoding Converter Library
+UniKey Project: http://unikey.sourceforge.net
+Copyleft (C) 1998-2002 Pham Kim Long
+Contact: longp@cslab.felk.cvut.cz
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+--------------------------------------------------------------------------------*/
+
+#ifndef __PATTERN_H
+#define __PATTERN_H
+
+#if defined(_WIN32)
+    #if defined(UNIKEYHOOK)
+        #define DllInterface   __declspec( dllexport )
+    #else
+        #define DllInterface   __declspec( dllimport )
+    #endif
+#else
+    #define DllInterface //not used
+#endif
+
+#define MAX_PATTERN_LEN 40
+
+class DllInterface PatternState
+{
+public:
+       char *m_pattern;
+       int m_border[MAX_PATTERN_LEN+1];
+       int m_pos;
+       int m_found;
+       void init(char *pattern);
+       void reset();
+       int foundAtNextChar(char ch); //get next input char, returns 1 if pattern is found.
+};
+
+class DllInterface PatternList
+{
+public:
+       PatternState *m_patterns;
+       int m_count;
+       void init(char **patterns, int count);
+       int foundAtNextChar(char ch); 
+       void reset();
+
+       PatternList() {
+               m_count = 0;
+               m_patterns = 0;
+       }
+
+       ~PatternList()
+       {
+               if (m_patterns)
+                       delete [] m_patterns;
+       }
+};
+
+
+#endif
diff --git a/ukengine/ukengine.cpp b/ukengine/ukengine.cpp
new file mode 100644 (file)
index 0000000..6a1b2bc
--- /dev/null
@@ -0,0 +1,2386 @@
+// -*- mode:c++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
+/* Unikey Vietnamese Input Method
+ * Copyright (C) 2000-2005 Pham Kim Long
+ * Contact:
+ *   unikey@gmail.com
+ *   UniKey project: http://unikey.org
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <iostream>
+#include "keycons.h"
+
+/*
+#if defined(_WIN32)
+#include "keyhook.h"
+#endif
+*/
+
+#include "vnlexi.h"
+#include "ukengine.h"
+
+#include "charset.h"
+
+using namespace std;
+
+#define ENTER_CHAR 13
+#define IS_ODD(x) (x & 1)
+#define IS_EVEN(x) (!(x & 1))
+
+#define IS_STD_VN_LOWER(x) ((x) >= VnStdCharOffset && (x) < (VnStdCharOffset + TOTAL_ALPHA_VNCHARS) && IS_ODD(x))
+#define IS_STD_VN_UPPER(x) ((x) >= VnStdCharOffset && (x) < (VnStdCharOffset + TOTAL_ALPHA_VNCHARS) && IS_EVEN(x))
+
+bool IsVnVowel[vnl_lastChar];
+
+extern VnLexiName AZLexiUpper[]; //defined in inputproc.cpp
+extern VnLexiName AZLexiLower[];
+
+//see vnconv/data.cpp for explanation of these characters
+unsigned char SpecialWesternChars[] = {
+  0x80, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88,
+  0x89, 0x8A, 0x8B, 0x8C, 0x8E, 0x91, 0x92, 0x93,
+  0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B,
+  0x9C, 0x9E, 0x9F, 0x00};
+
+StdVnChar IsoStdVnCharMap[256];
+
+inline StdVnChar IsoToStdVnChar(int keyCode)
+{
+    return (keyCode < 256)? IsoStdVnCharMap[keyCode] : keyCode;
+}
+
+struct VowelSeqInfo {
+    int len;
+    int complete;
+    int conSuffix; //allow consonnant suffix
+    VnLexiName v[3];
+    VowelSeq sub[3];
+
+    int roofPos;
+    VowelSeq withRoof;
+
+    int hookPos;
+    VowelSeq withHook; //hook & bowl
+};
+
+VowelSeqInfo VSeqList[] = {
+    {1, 1, 1, {vnl_a, vnl_nonVnChar, vnl_nonVnChar}, {vs_a, vs_nil, vs_nil}, -1, vs_ar, -1, vs_ab},
+    {1, 1, 1, {vnl_ar, vnl_nonVnChar, vnl_nonVnChar}, {vs_ar, vs_nil, vs_nil}, 0, vs_nil, -1, vs_ab},
+    {1, 1, 1, {vnl_ab, vnl_nonVnChar, vnl_nonVnChar}, {vs_ab, vs_nil, vs_nil}, -1, vs_ar, 0, vs_nil},
+    {1, 1, 1, {vnl_e, vnl_nonVnChar, vnl_nonVnChar}, {vs_e, vs_nil, vs_nil}, -1, vs_er, -1, vs_nil},
+    {1, 1, 1, {vnl_er, vnl_nonVnChar, vnl_nonVnChar}, {vs_er, vs_nil, vs_nil}, 0, vs_nil, -1, vs_nil},
+    {1, 1, 1, {vnl_i, vnl_nonVnChar, vnl_nonVnChar}, {vs_i, vs_nil, vs_nil}, -1, vs_nil, -1, vs_nil},
+    {1, 1, 1, {vnl_o, vnl_nonVnChar, vnl_nonVnChar}, {vs_o, vs_nil, vs_nil}, -1, vs_or, -1, vs_oh},
+    {1, 1, 1, {vnl_or, vnl_nonVnChar, vnl_nonVnChar}, {vs_or, vs_nil, vs_nil}, 0, vs_nil, -1, vs_oh},
+    {1, 1, 1, {vnl_oh, vnl_nonVnChar, vnl_nonVnChar}, {vs_oh, vs_nil, vs_nil}, -1, vs_or, 0, vs_nil},
+    {1, 1, 1, {vnl_u, vnl_nonVnChar, vnl_nonVnChar}, {vs_u, vs_nil, vs_nil}, -1, vs_nil, -1, vs_uh},
+    {1, 1, 1, {vnl_uh, vnl_nonVnChar, vnl_nonVnChar}, {vs_uh, vs_nil, vs_nil}, -1, vs_nil, 0, vs_nil},
+    {1, 1, 1, {vnl_y, vnl_nonVnChar, vnl_nonVnChar}, {vs_y, vs_nil, vs_nil}, -1, vs_nil, -1, vs_nil},
+    {2, 1, 0, {vnl_a, vnl_i, vnl_nonVnChar}, {vs_a, vs_ai, vs_nil}, -1, vs_nil, -1, vs_nil},
+    {2, 1, 0, {vnl_a, vnl_o, vnl_nonVnChar}, {vs_a, vs_ao, vs_nil}, -1, vs_nil, -1, vs_nil},
+    {2, 1, 0, {vnl_a, vnl_u, vnl_nonVnChar}, {vs_a, vs_au, vs_nil}, -1, vs_aru, -1, vs_nil},
+    {2, 1, 0, {vnl_a, vnl_y, vnl_nonVnChar}, {vs_a, vs_ay, vs_nil}, -1, vs_ary, -1, vs_nil},
+    {2, 1, 0, {vnl_ar, vnl_u, vnl_nonVnChar}, {vs_ar, vs_aru, vs_nil}, 0, vs_nil, -1, vs_nil},
+    {2, 1, 0, {vnl_ar, vnl_y, vnl_nonVnChar}, {vs_ar, vs_ary, vs_nil}, 0, vs_nil, -1, vs_nil},
+    {2, 1, 0, {vnl_e, vnl_o, vnl_nonVnChar}, {vs_e, vs_eo, vs_nil}, -1, vs_nil, -1, vs_nil},
+    {2, 0, 0, {vnl_e, vnl_u, vnl_nonVnChar}, {vs_e, vs_eu, vs_nil}, -1, vs_eru, -1, vs_nil},
+    {2, 1, 0, {vnl_er, vnl_u, vnl_nonVnChar}, {vs_er, vs_eru, vs_nil}, 0, vs_nil, -1, vs_nil},
+    {2, 1, 0, {vnl_i, vnl_a, vnl_nonVnChar}, {vs_i, vs_ia, vs_nil}, -1, vs_nil, -1, vs_nil},
+    {2, 0, 1, {vnl_i, vnl_e, vnl_nonVnChar}, {vs_i, vs_ie, vs_nil}, -1, vs_ier, -1, vs_nil},
+    {2, 1, 1, {vnl_i, vnl_er, vnl_nonVnChar}, {vs_i, vs_ier, vs_nil}, 1, vs_nil, -1, vs_nil},
+    {2, 1, 0, {vnl_i, vnl_u, vnl_nonVnChar}, {vs_i, vs_iu, vs_nil}, -1, vs_nil, -1, vs_nil},
+    {2, 1, 1, {vnl_o, vnl_a, vnl_nonVnChar}, {vs_o, vs_oa, vs_nil}, -1, vs_nil, -1, vs_oab},
+    {2, 1, 1, {vnl_o, vnl_ab, vnl_nonVnChar}, {vs_o, vs_oab, vs_nil}, -1, vs_nil, 1, vs_nil},
+    {2, 1, 1, {vnl_o, vnl_e, vnl_nonVnChar}, {vs_o, vs_oe, vs_nil}, -1, vs_nil, -1, vs_nil},
+    {2, 1, 0, {vnl_o, vnl_i, vnl_nonVnChar}, {vs_o, vs_oi, vs_nil}, -1, vs_ori, -1, vs_ohi},
+    {2, 1, 0, {vnl_or, vnl_i, vnl_nonVnChar}, {vs_or, vs_ori, vs_nil}, 0, vs_nil, -1, vs_ohi},
+    {2, 1, 0, {vnl_oh, vnl_i, vnl_nonVnChar}, {vs_oh, vs_ohi, vs_nil}, -1, vs_ori, 0, vs_nil},
+    {2, 1, 1, {vnl_u, vnl_a, vnl_nonVnChar}, {vs_u, vs_ua, vs_nil}, -1, vs_uar, -1, vs_uha},
+    {2, 1, 1, {vnl_u, vnl_ar, vnl_nonVnChar}, {vs_u, vs_uar, vs_nil}, 1, vs_nil, -1, vs_nil},
+    {2, 0, 1, {vnl_u, vnl_e, vnl_nonVnChar}, {vs_u, vs_ue, vs_nil}, -1, vs_uer, -1, vs_nil},
+    {2, 1, 1, {vnl_u, vnl_er, vnl_nonVnChar}, {vs_u, vs_uer, vs_nil}, 1, vs_nil, -1, vs_nil},
+    {2, 1, 0, {vnl_u, vnl_i, vnl_nonVnChar}, {vs_u, vs_ui, vs_nil}, -1, vs_nil, -1, vs_uhi},
+    {2, 0, 1, {vnl_u, vnl_o, vnl_nonVnChar}, {vs_u, vs_uo, vs_nil}, -1, vs_uor, -1, vs_uho},
+    {2, 1, 1, {vnl_u, vnl_or, vnl_nonVnChar}, {vs_u, vs_uor, vs_nil}, 1, vs_nil, -1, vs_uoh},
+    {2, 1, 1, {vnl_u, vnl_oh, vnl_nonVnChar}, {vs_u, vs_uoh, vs_nil}, -1, vs_uor, 1, vs_uhoh},
+    {2, 0, 0, {vnl_u, vnl_u, vnl_nonVnChar}, {vs_u, vs_uu, vs_nil}, -1, vs_nil, -1, vs_uhu},
+    {2, 1, 1, {vnl_u, vnl_y, vnl_nonVnChar}, {vs_u, vs_uy, vs_nil}, -1, vs_nil, -1, vs_nil},
+    {2, 1, 0, {vnl_uh, vnl_a, vnl_nonVnChar}, {vs_uh, vs_uha, vs_nil}, -1, vs_nil, 0, vs_nil},
+    {2, 1, 0, {vnl_uh, vnl_i, vnl_nonVnChar}, {vs_uh, vs_uhi, vs_nil}, -1, vs_nil, 0, vs_nil},
+    {2, 0, 1, {vnl_uh, vnl_o, vnl_nonVnChar}, {vs_uh, vs_uho, vs_nil}, -1, vs_nil, 0, vs_uhoh},
+    {2, 1, 1, {vnl_uh, vnl_oh, vnl_nonVnChar}, {vs_uh, vs_uhoh, vs_nil}, -1, vs_nil, 0, vs_nil},
+    {2, 1, 0, {vnl_uh, vnl_u, vnl_nonVnChar}, {vs_uh, vs_uhu, vs_nil}, -1, vs_nil, 0, vs_nil},
+    {2, 0, 1, {vnl_y, vnl_e, vnl_nonVnChar}, {vs_y, vs_ye, vs_nil}, -1, vs_yer, -1, vs_nil},
+    {2, 1, 1, {vnl_y, vnl_er, vnl_nonVnChar}, {vs_y, vs_yer, vs_nil}, 1, vs_nil, -1, vs_nil},
+    {3, 0, 0, {vnl_i, vnl_e, vnl_u}, {vs_i, vs_ie, vs_ieu}, -1, vs_ieru, -1, vs_nil},
+    {3, 1, 0, {vnl_i, vnl_er, vnl_u}, {vs_i, vs_ier, vs_ieru}, 1, vs_nil, -1, vs_nil},
+    {3, 1, 0, {vnl_o, vnl_a, vnl_i}, {vs_o, vs_oa, vs_oai}, -1, vs_nil, -1, vs_nil},
+    {3, 1, 0, {vnl_o, vnl_a, vnl_y}, {vs_o, vs_oa, vs_oay}, -1, vs_nil, -1, vs_nil},  
+    {3, 1, 0, {vnl_o, vnl_e, vnl_o}, {vs_o, vs_oe, vs_oeo}, -1, vs_nil, -1, vs_nil},
+    {3, 0, 0, {vnl_u, vnl_a, vnl_y}, {vs_u, vs_ua, vs_uay}, -1, vs_uary, -1, vs_nil},
+    {3, 1, 0, {vnl_u, vnl_ar, vnl_y}, {vs_u, vs_uar, vs_uary}, 1, vs_nil, -1, vs_nil},
+    {3, 0, 0, {vnl_u, vnl_o, vnl_i}, {vs_u, vs_uo, vs_uoi}, -1, vs_uori, -1, vs_uhoi},
+    {3, 0, 0, {vnl_u, vnl_o, vnl_u}, {vs_u, vs_uo, vs_uou}, -1, vs_nil, -1, vs_uhou},
+    {3, 1, 0, {vnl_u, vnl_or, vnl_i}, {vs_u, vs_uor, vs_uori}, 1, vs_nil, -1, vs_uohi},
+    {3, 0, 0, {vnl_u, vnl_oh, vnl_i}, {vs_u, vs_uoh, vs_uohi}, -1, vs_uori, 1, vs_uhohi},
+    {3, 0, 0, {vnl_u, vnl_oh, vnl_u}, {vs_u, vs_uoh, vs_uohu}, -1, vs_nil, 1, vs_uhohu},
+    {3, 1, 0, {vnl_u, vnl_y, vnl_a}, {vs_u, vs_uy, vs_uya}, -1, vs_nil, -1, vs_nil},
+    {3, 0, 1, {vnl_u, vnl_y, vnl_e}, {vs_u, vs_uy, vs_uye}, -1, vs_uyer, -1, vs_nil},
+    {3, 1, 1, {vnl_u, vnl_y, vnl_er}, {vs_u, vs_uy, vs_uyer}, 2, vs_nil, -1, vs_nil},
+    {3, 1, 0, {vnl_u, vnl_y, vnl_u}, {vs_u, vs_uy, vs_uyu}, -1, vs_nil, -1, vs_nil},
+    {3, 0, 0, {vnl_uh, vnl_o, vnl_i}, {vs_uh, vs_uho, vs_uhoi}, -1, vs_nil, 0, vs_uhohi},
+    {3, 0, 0, {vnl_uh, vnl_o, vnl_u}, {vs_uh, vs_uho, vs_uhou}, -1, vs_nil, 0, vs_uhohu},
+    {3, 1, 0, {vnl_uh, vnl_oh, vnl_i}, {vs_uh, vs_uhoh, vs_uhohi}, -1, vs_nil, 0, vs_nil},
+    {3, 1, 0, {vnl_uh, vnl_oh, vnl_u}, {vs_uh, vs_uhoh, vs_uhohu}, -1, vs_nil, 0, vs_nil},
+    {3, 0, 0, {vnl_y, vnl_e, vnl_u}, {vs_y, vs_ye, vs_yeu}, -1, vs_yeru, -1, vs_nil},
+    {3, 1, 0, {vnl_y, vnl_er, vnl_u}, {vs_y, vs_yer, vs_yeru}, 1, vs_nil, -1, vs_nil}
+};
+
+struct ConSeqInfo {
+    int len;
+    VnLexiName c[3];
+    bool suffix;
+};
+
+ConSeqInfo CSeqList[] = {
+    {1, {vnl_b, vnl_nonVnChar, vnl_nonVnChar}, false},
+    {1, {vnl_c, vnl_nonVnChar, vnl_nonVnChar}, true},
+    {2, {vnl_c, vnl_h, vnl_nonVnChar}, true},
+    {1, {vnl_d, vnl_nonVnChar, vnl_nonVnChar}, false},
+    {1, {vnl_dd, vnl_nonVnChar, vnl_nonVnChar}, false},
+    {2, {vnl_d, vnl_z, vnl_nonVnChar}, false},
+    {1, {vnl_g, vnl_nonVnChar, vnl_nonVnChar}, false},
+    {2, {vnl_g, vnl_h, vnl_nonVnChar}, false},
+    {2, {vnl_g, vnl_i, vnl_nonVnChar}, false},
+    {3, {vnl_g, vnl_i, vnl_n}, false},
+    {1, {vnl_h, vnl_nonVnChar, vnl_nonVnChar}, false},
+    {1, {vnl_k, vnl_nonVnChar, vnl_nonVnChar}, false},
+    {2, {vnl_k, vnl_h, vnl_nonVnChar}, false},
+    {1, {vnl_l, vnl_nonVnChar, vnl_nonVnChar}, false},
+    {1, {vnl_m, vnl_nonVnChar, vnl_nonVnChar}, true},
+    {1, {vnl_n, vnl_nonVnChar, vnl_nonVnChar}, true},
+    {2, {vnl_n, vnl_g, vnl_nonVnChar}, true},
+    {3, {vnl_n, vnl_g, vnl_h}, false},
+    {2, {vnl_n, vnl_h, vnl_nonVnChar}, true},
+    {1, {vnl_p, vnl_nonVnChar, vnl_nonVnChar}, true},
+    {2, {vnl_p, vnl_h, vnl_nonVnChar}, false},
+    {1, {vnl_q, vnl_nonVnChar, vnl_nonVnChar}, false},
+    {2, {vnl_q, vnl_u, vnl_nonVnChar}, false},
+    {1, {vnl_r, vnl_nonVnChar, vnl_nonVnChar}, false},
+    {1, {vnl_s, vnl_nonVnChar, vnl_nonVnChar}, false},
+    {1, {vnl_t, vnl_nonVnChar, vnl_nonVnChar}, true},
+    {2, {vnl_t, vnl_h, vnl_nonVnChar}, false},
+    {2, {vnl_t, vnl_r, vnl_nonVnChar}, false},
+    {1, {vnl_v, vnl_nonVnChar, vnl_nonVnChar}, false},
+    {1, {vnl_x, vnl_nonVnChar, vnl_nonVnChar}, false}
+};
+
+const int VSeqCount = sizeof(VSeqList)/sizeof(VowelSeqInfo);
+struct VSeqPair {
+    VnLexiName v[3];
+    VowelSeq vs;
+};
+VSeqPair SortedVSeqList[VSeqCount];
+
+const int CSeqCount = sizeof(CSeqList)/sizeof(ConSeqInfo);
+struct CSeqPair {
+    VnLexiName c[3];
+    ConSeq cs;
+};
+CSeqPair SortedCSeqList[CSeqCount];
+
+struct VCPair {
+    VowelSeq v;
+    ConSeq c;
+};
+
+VCPair VCPairList [] = {
+  {vs_a, cs_c}, {vs_a, cs_ch}, {vs_a, cs_m}, {vs_a, cs_n}, {vs_a, cs_ng},
+                {vs_a, cs_nh}, {vs_a, cs_p}, {vs_a, cs_t},
+  {vs_ar, cs_c}, {vs_ar, cs_m}, {vs_ar, cs_n}, {vs_ar, cs_ng}, {vs_ar, cs_p}, {vs_ar, cs_t},
+  {vs_ab, cs_c}, {vs_ab, cs_m}, {vs_ab, cs_n}, {vs_ab, cs_ng}, {vs_ab, cs_p}, {vs_ab, cs_t},
+
+  {vs_e, cs_c}, {vs_e, cs_ch}, {vs_e, cs_m}, {vs_e, cs_n}, {vs_e, cs_ng},
+                {vs_e, cs_nh}, {vs_e, cs_p}, {vs_e, cs_t},
+  {vs_er, cs_c}, {vs_er, cs_ch}, {vs_er, cs_m}, {vs_er, cs_n}, {vs_er, cs_nh},
+                {vs_er, cs_p}, {vs_er, cs_t},
+
+  {vs_i, cs_c}, {vs_i, cs_ch}, {vs_i, cs_m}, {vs_i, cs_n}, {vs_i, cs_nh}, {vs_i, cs_p}, {vs_i, cs_t},
+
+  {vs_o, cs_c}, {vs_o, cs_m}, {vs_o, cs_n}, {vs_o, cs_ng}, {vs_o, cs_p}, {vs_o, cs_t},
+  {vs_or, cs_c}, {vs_or, cs_m}, {vs_or, cs_n}, {vs_or, cs_ng}, {vs_or, cs_p}, {vs_or, cs_t},
+  {vs_oh, cs_m}, {vs_oh, cs_n}, {vs_oh, cs_p}, {vs_oh, cs_t},
+
+  {vs_u, cs_c}, {vs_u, cs_m}, {vs_u, cs_n}, {vs_u, cs_ng}, {vs_u, cs_p}, {vs_u, cs_t},
+  {vs_uh, cs_c}, {vs_uh, cs_m}, {vs_uh, cs_n}, {vs_uh, cs_ng}, {vs_uh, cs_t},
+
+  {vs_y, cs_t},
+  {vs_ie, cs_c}, {vs_ie, cs_m}, {vs_ie, cs_n}, {vs_ie, cs_ng}, {vs_ie, cs_p}, {vs_ie, cs_t},
+  {vs_ier, cs_c}, {vs_ier, cs_m}, {vs_ier, cs_n}, {vs_ier, cs_ng}, {vs_ier, cs_p}, {vs_ier, cs_t},
+
+  {vs_oa, cs_c}, {vs_oa, cs_ch}, {vs_oa, cs_m}, {vs_oa, cs_n}, {vs_oa, cs_ng},
+                 {vs_oa, cs_nh}, {vs_oa, cs_p}, {vs_oa, cs_t},
+  {vs_oab, cs_c}, {vs_oab, cs_m}, {vs_oab, cs_n}, {vs_oab, cs_ng}, {vs_oab, cs_t},
+
+  {vs_oe, cs_n}, {vs_oe, cs_t},
+
+  {vs_ua, cs_n}, {vs_ua, cs_ng}, {vs_ua, cs_t},
+  {vs_uar, cs_n}, {vs_uar, cs_ng}, {vs_uar, cs_t},
+
+  {vs_ue, cs_c}, {vs_ue, cs_ch}, {vs_ue, cs_n}, {vs_ue, cs_nh},
+  {vs_uer, cs_c}, {vs_uer, cs_ch}, {vs_uer, cs_n}, {vs_uer, cs_nh},
+
+  {vs_uo, cs_c}, {vs_uo, cs_m}, {vs_uo, cs_n}, {vs_uo, cs_ng}, {vs_uo, cs_p}, {vs_uo, cs_t},
+  {vs_uor, cs_c}, {vs_uor, cs_m}, {vs_uor, cs_n}, {vs_uor, cs_ng}, {vs_uor, cs_t},
+  {vs_uho, cs_c}, {vs_uho, cs_m}, {vs_uho, cs_n}, {vs_uho, cs_ng}, {vs_uho, cs_p}, {vs_uho, cs_t},
+  {vs_uhoh, cs_c}, {vs_uhoh, cs_m}, {vs_uhoh, cs_n}, {vs_uhoh, cs_ng}, {vs_uhoh, cs_p}, {vs_uhoh, cs_t},
+
+  {vs_uy, cs_c}, {vs_uy, cs_ch}, {vs_uy, cs_n}, {vs_uy, cs_nh}, {vs_uy, cs_p}, {vs_uy, cs_t},
+
+  {vs_ye, cs_m}, {vs_ye, cs_n}, {vs_ye, cs_ng}, {vs_ye, cs_p}, {vs_ye, cs_t},
+  {vs_yer, cs_m}, {vs_yer, cs_n}, {vs_yer, cs_ng}, {vs_yer, cs_t},
+
+  {vs_uye, cs_n}, {vs_uye, cs_t},
+  {vs_uyer, cs_n}, {vs_uyer, cs_t}
+
+};
+
+const int VCPairCount = sizeof(VCPairList)/sizeof(VCPair);
+
+//TODO: auto-complete: e.g. luan -> lua^n
+
+typedef int (UkEngine::* UkKeyProc)(UkKeyEvent & ev);
+
+UkKeyProc UkKeyProcList[vneCount] = {
+    &UkEngine::processRoof,    //vneRoofAll
+    &UkEngine::processRoof,    //vneRoof_a
+    &UkEngine::processRoof,    //vneRoof_e
+    &UkEngine::processRoof,    //vneRoof_o
+    &UkEngine::processHook,    //vneHookAll
+    &UkEngine::processHook,    //vneHook_uo
+    &UkEngine::processHook,    //vneHook_u
+    &UkEngine::processHook,    //vneHook_o
+    &UkEngine::processHook,    //vneBowl
+    &UkEngine::processDd,      //vneDd
+    &UkEngine::processTone,    //vneTone0
+    &UkEngine::processTone,    //vneTone1
+    &UkEngine::processTone,    //vneTone2
+    &UkEngine::processTone,    //vneTone3
+    &UkEngine::processTone,    //vneTone4
+    &UkEngine::processTone,    //vneTone5
+    &UkEngine::processTelexW,  //vne_telex_w
+    &UkEngine::processMapChar, //vneMapChar
+    &UkEngine::processEscChar, //vneEscChar
+    &UkEngine::processAppend   //vneNormal
+};
+
+
+VowelSeq lookupVSeq(VnLexiName v1, VnLexiName v2 = vnl_nonVnChar, VnLexiName v3 = vnl_nonVnChar);
+ConSeq lookupCSeq(VnLexiName c1, VnLexiName c2 = vnl_nonVnChar, VnLexiName c3 = vnl_nonVnChar);
+
+bool UkEngine::m_classInit = false;
+
+//------------------------------------------------
+int tripleVowelCompare(const void *p1, const void *p2)
+{
+    VSeqPair *t1 = (VSeqPair *)p1;
+    VSeqPair *t2 = (VSeqPair *)p2;
+
+    for (int i=0; i<3; i++) {
+        if (t1->v[i] < t2->v[i])
+            return -1;
+        if (t1->v[i] > t2->v[i])
+            return 1;
+    }
+    return 0;
+}
+
+//------------------------------------------------
+int tripleConCompare(const void *p1, const void *p2)
+{
+    CSeqPair *t1 = (CSeqPair *)p1;
+    CSeqPair *t2 = (CSeqPair *)p2;
+
+    for (int i=0; i<3; i++) {
+        if (t1->c[i] < t2->c[i])
+            return -1;
+        if (t1->c[i] > t2->c[i])
+            return 1;
+    }
+    return 0;
+}
+
+//------------------------------------------------
+int VCPairCompare(const void *p1, const void *p2)
+{
+    VCPair *t1 = (VCPair *)p1;
+    VCPair *t2 = (VCPair *)p2;
+
+    if (t1->v < t2->v)
+        return -1;
+    if (t1->v > t2->v)
+      return 1;
+  
+    if (t1->c < t2->c)
+        return -1;
+    if (t1->c > t2->c)
+        return 1;
+    return 0;
+}
+
+//----------------------------------------------------------
+bool isValidCV(ConSeq c, VowelSeq v)
+{
+    if (c == cs_nil || v == vs_nil)
+        return true;
+
+    VowelSeqInfo & vInfo = VSeqList[v];
+
+    if ((c == cs_gi && vInfo.v[0] == vnl_i) ||
+        (c == cs_qu && vInfo.v[0] == vnl_u))
+        return false; // gi doesn't go with i, qu doesn't go with u
+  
+    if (c == cs_k) {
+        // k can only go with the following vowel sequences
+        static VowelSeq kVseq[] = {vs_e, vs_i, vs_y, vs_er, vs_eo, vs_eu, 
+                                   vs_eru, vs_ia, vs_ie, vs_ier, vs_ieu, vs_ieru, vs_nil};
+        int i;
+        for (i=0; kVseq[i] != vs_nil && kVseq[i] != v; i++);
+        return (kVseq[i] != vs_nil);
+    }
+
+    //More checks
+    return true;
+}
+
+//----------------------------------------------------------
+bool isValidVC(VowelSeq v, ConSeq c)
+{
+    if (v == vs_nil || c == cs_nil)
+        return true;
+
+    VowelSeqInfo & vInfo = VSeqList[v];
+    if (!vInfo.conSuffix)
+        return false;
+
+    ConSeqInfo & cInfo = CSeqList[c];
+    if (!cInfo.suffix)
+        return false;
+
+    VCPair p;
+    p.v = v;
+    p.c = c;
+    if (bsearch(&p, VCPairList, VCPairCount, sizeof(VCPair), VCPairCompare))
+        return true;
+
+    return false;
+}
+
+//----------------------------------------------------------
+bool isValidCVC(ConSeq c1, VowelSeq v, ConSeq c2)
+{
+    if (v == vs_nil)
+        return (c1 == cs_nil || c2 != cs_nil);
+
+    if (c1 == cs_nil)
+        return isValidVC(v, c2);
+
+    if (c2 == cs_nil)
+        return isValidCV(c1, v);
+
+    bool okCV = isValidCV(c1, v);
+    bool okVC = isValidVC(v, c2);
+
+    if (okCV && okVC)
+        return true;
+
+    if (!okVC) {
+        //check some exceptions: vc fails but cvc passes
+
+        // quyn, quynh
+        if (c1 == cs_qu && v == vs_y && (c2 == cs_n || c2 == cs_nh))
+            return true;
+
+        // gieng, gie^ng
+        if (c1 == cs_gi && (v == vs_e || v == vs_er) && (c2 == cs_n || c2 == cs_ng))
+            return true;
+    }
+    return false;
+}
+
+//------------------------------------------------
+void engineClassInit()
+{
+    int i, j;
+
+    for (i=0; i < VSeqCount; i++) {
+        for (j=0; j<3; j++)
+            SortedVSeqList[i].v[j] = VSeqList[i].v[j];
+        SortedVSeqList[i].vs = (VowelSeq)i;
+    }
+
+    for (i=0; i < CSeqCount; i++) {
+        for (j=0; j<3; j++)
+            SortedCSeqList[i].c[j] = CSeqList[i].c[j];
+        SortedCSeqList[i].cs = (ConSeq)i;
+    }
+
+    qsort(SortedVSeqList, VSeqCount, sizeof(VSeqPair), tripleVowelCompare);
+    qsort(SortedCSeqList, CSeqCount, sizeof(CSeqPair), tripleConCompare);
+    qsort(VCPairList, VCPairCount, sizeof(VCPair), VCPairCompare);
+
+    for (i=0; i<vnl_lastChar; i++)
+        IsVnVowel[i] = true;
+
+    unsigned char ch;
+    for (ch='a'; ch <= 'z'; ch++) {
+        if (ch != 'a' && ch != 'e' && ch != 'i' &&
+            ch != 'o' && ch != 'u' && ch != 'y') {
+            IsVnVowel[AZLexiLower[ch-'a']] = false;
+            IsVnVowel[AZLexiUpper[ch-'a']] = false;
+        }
+    }
+    IsVnVowel[vnl_dd] = false;
+    IsVnVowel[vnl_DD] = false;
+}
+
+//------------------------------------------------
+VowelSeq lookupVSeq(VnLexiName v1, VnLexiName v2, VnLexiName v3)
+{
+    VSeqPair key;
+    key.v[0] = v1;
+    key.v[1] = v2;
+    key.v[2] = v3;
+
+    VSeqPair *pInfo = (VSeqPair *)bsearch(&key, SortedVSeqList, VSeqCount, sizeof(VSeqPair), tripleVowelCompare);
+    if (pInfo == 0)
+        return vs_nil;
+    return pInfo->vs;
+}
+
+//------------------------------------------------
+ConSeq lookupCSeq(VnLexiName c1, VnLexiName c2, VnLexiName c3)
+{
+    CSeqPair key;
+    key.c[0] = c1;
+    key.c[1] = c2;
+    key.c[2] = c3;
+
+    CSeqPair *pInfo = (CSeqPair *)bsearch(&key, SortedCSeqList, CSeqCount, sizeof(CSeqPair), tripleConCompare);
+    if (pInfo == 0)
+        return cs_nil;
+    return pInfo->cs;
+}
+
+//------------------------------------------------------------------
+int UkEngine::processRoof(UkKeyEvent & ev)
+{
+    if (!m_pCtrl->vietKey || m_current < 0 || m_buffer[m_current].vOffset < 0)
+        return processAppend(ev);
+
+    VnLexiName target;
+    switch (ev.evType) {
+    case vneRoof_a:
+        target = vnl_ar;
+        break;
+    case vneRoof_e:
+        target = vnl_er;
+        break;
+    case vneRoof_o:
+        target = vnl_or;
+        break;
+    default:
+        target = vnl_nonVnChar;
+    }
+
+
+    VowelSeq vs, newVs;
+    int i, vStart, vEnd;
+    int curTonePos, newTonePos, tone;
+    int changePos;
+    bool roofRemoved = false;
+
+    vEnd = m_current - m_buffer[m_current].vOffset;
+    vs = m_buffer[vEnd].vseq;
+    vStart = vEnd - (VSeqList[vs].len - 1);
+    curTonePos = vStart + getTonePosition(vs, vEnd == m_current);
+    tone = m_buffer[curTonePos].tone;
+
+    bool doubleChangeUO = false;
+    if (vs == vs_uho || vs == vs_uhoh || vs == vs_uhoi || vs == vs_uhohi) {
+        //special cases: u+o+ -> uo^, u+o -> uo^, u+o+i -> uo^i, u+oi -> uo^i
+        newVs = lookupVSeq(vnl_u, vnl_or, VSeqList[vs].v[2]);
+        doubleChangeUO = true;
+    }
+    else {
+        newVs = VSeqList[vs].withRoof;
+    }
+
+    VowelSeqInfo *pInfo;
+
+    if (newVs == vs_nil) {
+        if (VSeqList[vs].roofPos == -1)
+            return processAppend(ev); //roof is not applicable
+    
+        //a roof already exists -> undo roof
+        VnLexiName curCh = m_buffer[vStart + VSeqList[vs].roofPos].vnSym;
+        if (target != vnl_nonVnChar && curCh != target)
+            return processAppend(ev); //specific roof and the roof character don't match
+
+        VnLexiName newCh = (curCh == vnl_ar)? vnl_a : ((curCh == vnl_er)? vnl_e : vnl_o);
+        changePos = vStart + VSeqList[vs].roofPos;
+
+        if (!m_pCtrl->options.freeMarking && changePos != m_current)
+            return processAppend(ev);
+
+        markChange(changePos);
+        m_buffer[changePos].vnSym = newCh;
+
+        if (VSeqList[vs].len == 3)
+            newVs = lookupVSeq(m_buffer[vStart].vnSym, m_buffer[vStart+1].vnSym, m_buffer[vStart+2].vnSym);
+        else if (VSeqList[vs].len == 2)
+            newVs = lookupVSeq(m_buffer[vStart].vnSym, m_buffer[vStart+1].vnSym);
+        else
+            newVs = lookupVSeq(m_buffer[vStart].vnSym);
+
+        pInfo = &VSeqList[newVs];
+        roofRemoved = true;
+    }
+    else {
+        pInfo = &VSeqList[newVs];
+        if (target != vnl_nonVnChar &&  pInfo->v[pInfo->roofPos] != target)
+            return processAppend(ev);
+
+        //check validity of new VC and CV
+        bool valid = true;
+        ConSeq c1 = cs_nil;
+        ConSeq c2 = cs_nil;
+        if (m_buffer[m_current].c1Offset != -1)
+            c1 = m_buffer[m_current-m_buffer[m_current].c1Offset].cseq;
+        
+        if (m_buffer[m_current].c2Offset != -1)
+            c2 = m_buffer[m_current-m_buffer[m_current].c2Offset].cseq;
+
+        valid = isValidCVC(c1, newVs, c2);
+        if (!valid)
+            return processAppend(ev);
+
+        if (doubleChangeUO) {
+            changePos = vStart;
+        }
+        else {
+            changePos = vStart + pInfo->roofPos;
+        }
+        if (!m_pCtrl->options.freeMarking && changePos != m_current)
+            return processAppend(ev);
+        markChange(changePos);
+        if (doubleChangeUO) {
+            m_buffer[vStart].vnSym = vnl_u;
+            m_buffer[vStart+1].vnSym = vnl_or;
+        }
+        else {
+            m_buffer[changePos].vnSym = pInfo->v[pInfo->roofPos];
+        }
+    }
+
+    for (i=0; i < pInfo->len; i++) { //update sub-sequences
+        m_buffer[vStart+i].vseq = pInfo->sub[i];
+    }
+
+    //check if tone re-position is needed
+    newTonePos = vStart + getTonePosition(newVs, vEnd == m_current);
+    /* //For now, users don't seem to like the following processing, thus commented out
+    if (roofRemoved && tone != 0 &&
+        (!pInfo->complete || changePos == curTonePos)) {
+        //remove tone if the vowel sequence becomes incomplete as a result of roof removal OR
+        //if removed roof is at the same position as the current tone
+        markChange(curTonePos);
+        m_buffer[curTonePos].tone = 0;
+    } else
+    */
+    if (curTonePos != newTonePos && tone != 0) {
+        markChange(newTonePos);
+        m_buffer[newTonePos].tone = tone;
+        markChange(curTonePos);
+        m_buffer[curTonePos].tone = 0;
+    }
+
+    if (roofRemoved) {
+        m_singleMode = false;
+        processAppend(ev);
+        m_reverted = true;
+    }
+
+    return 1;
+}
+
+//------------------------------------------------------------------
+// can only be called from processHook
+//------------------------------------------------------------------
+int UkEngine::processHookWithUO(UkKeyEvent & ev)
+{
+    VowelSeq vs, newVs;
+    int i, vStart, vEnd;
+    int curTonePos, newTonePos, tone;
+    bool hookRemoved = false;
+    bool removeWithUndo = true;
+    bool toneRemoved = false;
+
+    VnLexiName *v;
+
+    if (!m_pCtrl->options.freeMarking && m_buffer[m_current].vOffset != 0)
+        return processAppend(ev);    
+
+    vEnd = m_current - m_buffer[m_current].vOffset;
+    vs = m_buffer[vEnd].vseq;
+    vStart = vEnd - (VSeqList[vs].len - 1);
+    v = VSeqList[vs].v;
+    curTonePos = vStart + getTonePosition(vs, vEnd == m_current);
+    tone = m_buffer[curTonePos].tone;
+
+    switch (ev.evType) {
+    case vneHook_u:
+        if (v[0] == vnl_u) {
+            newVs = VSeqList[vs].withHook;
+            markChange(vStart);
+            m_buffer[vStart].vnSym = vnl_uh;
+        }
+        else {// v[0] = vnl_uh, -> uo
+            newVs = lookupVSeq(vnl_u, vnl_o, v[2]);
+            markChange(vStart);
+            m_buffer[vStart].vnSym = vnl_u;
+            m_buffer[vStart+1].vnSym = vnl_o;
+            hookRemoved = true;
+            toneRemoved =  (m_buffer[vStart].tone != 0);
+        }
+        break;
+    case vneHook_o:
+        if (v[1] == vnl_o || v[1] == vnl_or) {
+            if (vEnd == m_current && VSeqList[vs].len == 2 && 
+                m_buffer[m_current].form == vnw_cv && m_buffer[m_current-2].cseq == cs_th)
+            {
+                // o|o^ -> o+
+                newVs = VSeqList[vs].withHook;
+                markChange(vStart+1);
+                m_buffer[vStart+1].vnSym = vnl_oh;
+            }
+            else {
+                newVs = lookupVSeq(vnl_uh, vnl_oh, v[2]);
+                if (v[0] == vnl_u) {
+                    markChange(vStart);
+                    m_buffer[vStart].vnSym = vnl_uh;
+                    m_buffer[vStart+1].vnSym = vnl_oh;
+                }
+                else {
+                    markChange(vStart+1);
+                    m_buffer[vStart+1].vnSym = vnl_oh;
+                }
+            }
+        }
+        else {// v[1] = vnl_oh, -> uo
+            newVs = lookupVSeq(vnl_u, vnl_o, v[2]);
+            if (v[0] == vnl_uh) {
+                markChange(vStart);
+                m_buffer[vStart].vnSym = vnl_u;
+                m_buffer[vStart+1].vnSym = vnl_o;
+            }
+            else {
+                markChange(vStart+1);
+                m_buffer[vStart+1].vnSym = vnl_o;
+            }
+            hookRemoved = true;
+            toneRemoved = (m_buffer[vStart+1].tone != 0);
+        }
+        break;
+    default:  //vneHookAll, vneHookUO:
+        if (v[0] == vnl_u) {
+            if (v[1] == vnl_o || v[1] == vnl_or) { 
+                //uo -> uo+ if prefixed by "th"
+                if ((vs == vs_uo || vs == vs_uor) && vEnd == m_current && 
+                    m_buffer[m_current].form == vnw_cv && m_buffer[m_current-2].cseq == cs_th) 
+                {
+                    newVs = vs_uoh;
+                    markChange(vStart+1);
+                    m_buffer[vStart+1].vnSym = vnl_oh;
+                }
+                else {
+                    //uo -> u+o+
+                    newVs = VSeqList[vs].withHook;
+                    markChange(vStart);
+                    m_buffer[vStart].vnSym = vnl_uh;
+                    newVs = VSeqList[newVs].withHook;
+                    m_buffer[vStart+1].vnSym = vnl_oh;
+                }
+            }
+            else {//uo+ -> u+o+
+                newVs = VSeqList[vs].withHook;
+                markChange(vStart);
+                m_buffer[vStart].vnSym = vnl_uh;
+            }
+        }
+        else {//v[0] == vnl_uh
+            if (v[1] == vnl_o) { // u+o -> u+o+
+                newVs = VSeqList[vs].withHook;
+                markChange(vStart+1);
+                m_buffer[vStart+1].vnSym = vnl_oh;
+            }
+            else { //v[1] == vnl_oh, u+o+ -> uo
+                newVs = lookupVSeq(vnl_u, vnl_o, v[2]); //vs_uo;
+                markChange(vStart);
+                m_buffer[vStart].vnSym = vnl_u;
+                m_buffer[vStart+1].vnSym = vnl_o;
+                hookRemoved = true;
+                toneRemoved = (m_buffer[vStart].tone != 0 || m_buffer[vStart+1].tone != 0);
+            }
+        }
+        break;
+    }
+
+    VowelSeqInfo *p = &VSeqList[newVs];
+    for (i=0; i < p->len; i++) { //update sub-sequences
+        m_buffer[vStart+i].vseq = p->sub[i];
+    }
+
+    //check if tone re-position is needed
+    newTonePos = vStart + getTonePosition(newVs, vEnd == m_current);
+    /* //For now, users don't seem to like the following processing, thus commented out
+    if (hookRemoved && tone != 0 && (!p->complete || toneRemoved)) {
+        //remove tone if the vowel sequence becomes incomplete as a result of hook removal
+        //OR if a removed hook is at the same position as the current tone
+        markChange(curTonePos);
+        m_buffer[curTonePos].tone = 0;
+    }
+    else 
+    */
+    if (curTonePos != newTonePos && tone != 0) {
+        markChange(newTonePos);
+        m_buffer[newTonePos].tone = tone;
+        markChange(curTonePos);
+        m_buffer[curTonePos].tone = 0;
+    }
+
+    if (hookRemoved && removeWithUndo) {
+        m_singleMode = false;
+        processAppend(ev);
+        m_reverted = true;
+    }
+
+    return 1;
+}
+
+//------------------------------------------------------------------
+int UkEngine::processHook(UkKeyEvent & ev)
+{
+    if (!m_pCtrl->vietKey || m_current < 0 || m_buffer[m_current].vOffset < 0)
+        return processAppend(ev);
+
+    VowelSeq vs, newVs;
+    int i, vStart, vEnd;
+    int curTonePos, newTonePos, tone;
+    int changePos;
+    bool hookRemoved = false;
+    VowelSeqInfo *pInfo;
+    VnLexiName *v;
+
+    vEnd = m_current - m_buffer[m_current].vOffset;
+    vs = m_buffer[vEnd].vseq;
+
+    v = VSeqList[vs].v;
+  
+    if (VSeqList[vs].len > 1 && 
+        ev.evType != vneBowl &&
+        (v[0] == vnl_u || v[0] == vnl_uh) &&
+        (v[1] == vnl_o || v[1] == vnl_oh || v[1] == vnl_or))
+        return processHookWithUO(ev);
+
+    vStart = vEnd - (VSeqList[vs].len - 1);
+    curTonePos = vStart + getTonePosition(vs, vEnd == m_current);
+    tone = m_buffer[curTonePos].tone;
+
+    newVs = VSeqList[vs].withHook;
+    if (newVs == vs_nil) {
+        if (VSeqList[vs].hookPos == -1)
+            return processAppend(ev); //hook is not applicable
+
+        //a hook already exists -> undo hook
+        VnLexiName curCh = m_buffer[vStart + VSeqList[vs].hookPos].vnSym;
+        VnLexiName newCh = (curCh == vnl_ab)? vnl_a : ((curCh == vnl_uh)? vnl_u : vnl_o);
+        changePos = vStart + VSeqList[vs].hookPos;
+        if (!m_pCtrl->options.freeMarking && changePos != m_current)
+            return processAppend(ev);
+
+        switch (ev.evType) {
+        case vneHook_u:
+            if (curCh != vnl_uh)
+                return processAppend(ev);
+            break;
+        case vneHook_o:
+            if (curCh != vnl_oh)
+                return processAppend(ev);
+            break;
+        case vneBowl:
+            if (curCh != vnl_ab)
+                return processAppend(ev);
+            break;
+        default:
+            if (ev.evType == vneHook_uo && curCh == vnl_ab)
+                return processAppend(ev);
+        }
+
+        markChange(changePos);
+        m_buffer[changePos].vnSym = newCh;
+
+        if (VSeqList[vs].len == 3)
+            newVs = lookupVSeq(m_buffer[vStart].vnSym, m_buffer[vStart+1].vnSym, m_buffer[vStart+2].vnSym);
+        else if (VSeqList[vs].len == 2)
+            newVs = lookupVSeq(m_buffer[vStart].vnSym, m_buffer[vStart+1].vnSym);
+        else
+            newVs = lookupVSeq(m_buffer[vStart].vnSym);
+
+        pInfo = &VSeqList[newVs];
+        hookRemoved = true;
+    }
+    else {
+        pInfo = &VSeqList[newVs];
+
+        switch (ev.evType) {
+        case vneHook_u:
+            if (pInfo->v[pInfo->hookPos] != vnl_uh)
+                return processAppend(ev);
+            break;
+        case vneHook_o:
+            if (pInfo->v[pInfo->hookPos] != vnl_oh)
+                return processAppend(ev);
+            break;
+        case vneBowl:
+            if (pInfo->v[pInfo->hookPos] != vnl_ab)
+                return processAppend(ev);
+            break;
+        default: //vneHook_uo, vneHookAll
+            if (ev.evType == vneHook_uo && pInfo->v[pInfo->hookPos] == vnl_ab)
+                return processAppend(ev);
+        }
+
+        //check validity of new VC and CV
+        bool valid = true;
+        ConSeq c1 = cs_nil;
+        ConSeq c2 = cs_nil;
+        if (m_buffer[m_current].c1Offset != -1)
+            c1 = m_buffer[m_current-m_buffer[m_current].c1Offset].cseq;
+        
+        if (m_buffer[m_current].c2Offset != -1)
+            c2 = m_buffer[m_current-m_buffer[m_current].c2Offset].cseq;
+
+        valid = isValidCVC(c1, newVs, c2);
+
+        if (!valid)
+            return processAppend(ev);
+
+        changePos = vStart + pInfo->hookPos;
+        if (!m_pCtrl->options.freeMarking && changePos != m_current)
+            return processAppend(ev);
+
+        markChange(changePos);
+        m_buffer[changePos].vnSym = pInfo->v[pInfo->hookPos];
+    }
+   
+    for (i=0; i < pInfo->len; i++) { //update sub-sequences
+        m_buffer[vStart+i].vseq = pInfo->sub[i];
+    }
+
+    //check if tone re-position is needed
+    newTonePos = vStart + getTonePosition(newVs, vEnd == m_current);
+    /* //For now, users don't seem to like the following processing, thus commented out
+    if (hookRemoved && tone != 0 && 
+        (!pInfo->complete || (hookRemoved && curTonePos == changePos))) {
+        //remove tone if the vowel sequence becomes incomplete as a result of hook removal
+        //OR if a removed hook was at the same position as the current tone
+        markChange(curTonePos);
+        m_buffer[curTonePos].tone = 0;
+    }
+    else */
+    if (curTonePos != newTonePos && tone != 0) {
+        markChange(newTonePos);
+        m_buffer[newTonePos].tone = tone;
+        markChange(curTonePos);
+        m_buffer[curTonePos].tone = 0;
+    }
+
+    if (hookRemoved) {
+        m_singleMode = false;
+        processAppend(ev);
+        m_reverted = true;
+    }
+
+    return 1;
+}
+
+//----------------------------------------------------------
+int UkEngine::getTonePosition(VowelSeq vs, bool terminated)
+{
+    VowelSeqInfo & info = VSeqList[vs];
+    if (info.len == 1)
+        return 0;
+
+    if (info.roofPos != -1)
+        return info.roofPos;
+    if (info.hookPos != -1) {
+        if (vs == vs_uhoh || vs == vs_uhohi || vs == vs_uhohu) //u+o+, u+o+u, u+o+i
+            return 1;
+        return info.hookPos;
+    }
+  
+    if (info.len == 3)
+        return 1;
+
+    if (m_pCtrl->options.modernStyle &&
+        (vs == vs_oa || vs == vs_oe ||vs == vs_uy))
+        return 1;
+
+    return terminated ? 0 : 1;
+}
+
+//----------------------------------------------------------
+int UkEngine::processTone(UkKeyEvent & ev)
+{
+    if (m_current < 0 || !m_pCtrl->vietKey)
+        return processAppend(ev);
+
+    if (m_buffer[m_current].form == vnw_c && 
+        (m_buffer[m_current].cseq == cs_gi || m_buffer[m_current].cseq == cs_gin)) {
+        int p = (m_buffer[m_current].cseq == cs_gi)? m_current : m_current - 1;
+        if (m_buffer[p].tone == 0 && ev.tone == 0)
+            return processAppend(ev);
+        markChange(p);
+        if (m_buffer[p].tone == ev.tone) {
+            m_buffer[p].tone = 0;
+            m_singleMode = false;
+            processAppend(ev);
+            m_reverted = true;
+            return 1;
+        }
+        m_buffer[p].tone = ev.tone;
+        return 1;
+    }
+
+    if (m_buffer[m_current].vOffset < 0)
+        return processAppend(ev);
+
+    int vEnd;
+    VowelSeq vs;
+
+    vEnd = m_current - m_buffer[m_current].vOffset;
+    vs = m_buffer[vEnd].vseq;
+    VowelSeqInfo & info = VSeqList[vs];
+    if (m_pCtrl->options.spellCheckEnabled && !m_pCtrl->options.freeMarking && !info.complete)
+        return processAppend(ev);
+
+    if (m_buffer[m_current].form == vnw_vc || m_buffer[m_current].form == vnw_cvc) {
+        ConSeq cs = m_buffer[m_current].cseq;
+        if ((cs == cs_c || cs == cs_ch || cs == cs_p || cs == cs_t) &&
+            (ev.tone == 2 || ev.tone == 3 || ev.tone == 4))
+            return processAppend(ev); // c, ch, p, t suffixes don't allow ` ? ~
+    }
+      
+    int toneOffset = getTonePosition(vs, vEnd == m_current);
+    int tonePos = vEnd - (info.len -1 ) + toneOffset;
+    if (m_buffer[tonePos].tone == 0 && ev.tone == 0)
+        return processAppend(ev);
+
+    if (m_buffer[tonePos].tone == ev.tone) {
+        markChange(tonePos);
+        m_buffer[tonePos].tone = 0;
+        m_singleMode = false;
+        processAppend(ev);
+        m_reverted = true;
+        return 1;
+    }
+
+    markChange(tonePos);
+    m_buffer[tonePos].tone = ev.tone;
+    return 1;
+}
+
+//----------------------------------------------------------
+int UkEngine::processDd(UkKeyEvent & ev)
+{
+    if (!m_pCtrl->vietKey || m_current < 0)
+        return processAppend(ev);
+    
+    int pos;
+
+    // we want to allow dd even in non-vn sequence, because dd is used a lot in abbreviation
+    // we allow dd only if preceding character is not a vowel
+    if (m_buffer[m_current].form == vnw_nonVn && 
+        m_buffer[m_current].vnSym == vnl_d &&
+        (m_buffer[m_current-1].vnSym == vnl_nonVnChar ||!IsVnVowel[m_buffer[m_current-1].vnSym]))
+    {
+        m_singleMode = true;
+        pos = m_current;
+        markChange(pos);
+        m_buffer[pos].cseq = cs_dd;
+        m_buffer[pos].vnSym = vnl_dd;
+        m_buffer[pos].form = vnw_c;
+        m_buffer[pos].c1Offset = 0;
+        m_buffer[pos].c2Offset = -1;
+        m_buffer[pos].vOffset = -1;
+        return 1;
+    }
+
+    if (m_buffer[m_current].c1Offset < 0) {
+        return processAppend(ev);
+    }
+
+    pos = m_current - m_buffer[m_current].c1Offset;
+    if (!m_pCtrl->options.freeMarking && pos != m_current)
+        return processAppend(ev);
+
+    if (m_buffer[pos].cseq == cs_d) {
+        markChange(pos);
+        m_buffer[pos].cseq = cs_dd;
+        m_buffer[pos].vnSym = vnl_dd;
+        //never spellcheck a word which starts with dd, because it's used alot in abbreviation
+        m_singleMode = true;
+        return 1;
+    }
+
+    if (m_buffer[pos].cseq == cs_dd) {
+        //undo dd
+        markChange(pos);
+        m_buffer[pos].cseq = cs_d;
+        m_buffer[pos].vnSym = vnl_d;
+        m_singleMode = false;
+        processAppend(ev);
+        m_reverted = true;
+        return 1;
+    }
+  
+    return processAppend(ev);
+}
+
+//----------------------------------------------------------
+VnLexiName changeCase(VnLexiName x)
+{
+    if (x == vnl_nonVnChar)
+        return x;
+    if (!(x & 0x01))
+        return (VnLexiName)(x+1);
+    return (VnLexiName)(x-1);
+}
+
+//----------------------------------------------------------
+inline VnLexiName vnToLower(VnLexiName x)
+{
+    if (x == vnl_nonVnChar)
+        return x;
+    if (!(x & 0x01)) //even
+        return (VnLexiName)(x+1);
+    return x;
+}
+
+//----------------------------------------------------------
+int UkEngine::processMapChar(UkKeyEvent & ev)
+{
+    int capsLockOn = 0;
+    int shiftPressed = 0;
+    if (m_keyCheckFunc)
+        m_keyCheckFunc(&shiftPressed, &capsLockOn);
+
+    if (capsLockOn)
+        ev.vnSym = changeCase(ev.vnSym);
+
+    int ret = processAppend(ev);
+    if (!m_pCtrl->vietKey)
+        return ret;
+
+    if (m_current >= 0 && m_buffer[m_current].form != vnw_empty &&
+        m_buffer[m_current].form != vnw_nonVn) {
+        return 1;
+    }
+
+    if (m_current < 0)
+        return 0;
+
+    // mapChar doesn't apply
+    m_current--;
+    WordInfo & entry = m_buffer[m_current];
+
+    bool undo = false;
+    // test if undo is needed
+    if (entry.form != vnw_empty && entry.form != vnw_nonVn) {
+        VnLexiName prevSym = entry.vnSym;
+        if (entry.caps) {
+            prevSym = (VnLexiName)(prevSym - 1);
+        }
+        if (prevSym == ev.vnSym) {
+            if (entry.form != vnw_c) {
+                int vStart, vEnd, curTonePos, newTonePos, tone;
+                VowelSeq vs, newVs;
+
+                vEnd = m_current - entry.vOffset;
+                vs = m_buffer[vEnd].vseq;
+                vStart = vEnd - VSeqList[vs].len +1;
+                curTonePos = vStart + getTonePosition(vs, vEnd == m_current);
+                tone = m_buffer[curTonePos].tone;
+                markChange(m_current);
+                m_current--;
+
+                //check if tone position is needed
+                if (tone != 0 && m_current >= 0 &&
+                    (m_buffer[m_current].form == vnw_v || m_buffer[m_current].form == vnw_cv)) {
+                    newVs = m_buffer[m_current].vseq;
+                    newTonePos = vStart + getTonePosition(newVs, true);
+                    if (newTonePos != curTonePos) {
+                        markChange(newTonePos);
+                        m_buffer[newTonePos].tone = tone;
+                        markChange(curTonePos);
+                        m_buffer[curTonePos].tone = 0;
+                    }
+                }
+            }
+            else {
+                markChange(m_current);
+                m_current--;
+            }
+            undo = true;
+        }
+    }
+
+    ev.evType = vneNormal;
+    ev.chType = m_pCtrl->input.getCharType(ev.keyCode);
+    ev.vnSym = IsoToVnLexi(ev.keyCode);
+    ret = processAppend(ev);
+    if (undo) {
+        m_singleMode = false;
+        m_reverted = true;
+        return 1;
+    }
+    return ret;
+}
+
+//----------------------------------------------------------
+int UkEngine::processTelexW(UkKeyEvent & ev)
+{
+    if (!m_pCtrl->vietKey)
+        return processAppend(ev);
+
+    int ret;
+    static bool usedAsMapChar = false;
+    int capsLockOn = 0;
+    int shiftPressed = 0;
+    if (m_keyCheckFunc)
+        m_keyCheckFunc(&shiftPressed, &capsLockOn);
+
+    if (usedAsMapChar) {
+        ev.evType = vneMapChar;
+        ev.vnSym = isupper(ev.keyCode)? vnl_Uh : vnl_uh;
+        if (capsLockOn)
+            ev.vnSym = changeCase(ev.vnSym);
+        ev.chType = ukcVn;
+        ret = processMapChar(ev);
+        if (ret == 0) {
+            if (m_current >= 0)
+                m_current--;
+            usedAsMapChar = false;
+            ev.evType = vneHookAll;
+            return processHook(ev);
+        }
+        return ret;
+    }
+
+    ev.evType = vneHookAll;
+    usedAsMapChar = false;
+    ret = processHook(ev);
+    if (ret == 0) {
+        if (m_current >= 0)
+            m_current--;
+        ev.evType = vneMapChar;
+        ev.vnSym = isupper(ev.keyCode)? vnl_Uh : vnl_uh;
+        if (capsLockOn)
+            ev.vnSym = changeCase(ev.vnSym);
+        ev.chType = ukcVn;
+        usedAsMapChar = true;
+        return processMapChar(ev);
+    }
+    return ret;
+}
+
+//----------------------------------------------------------
+int UkEngine::checkEscapeVIQR(UkKeyEvent & ev)
+{
+    if (m_current < 0)
+        return 0;
+    WordInfo & entry = m_buffer[m_current];
+    int escape = 0;
+    if (entry.form == vnw_v || entry.form == vnw_cv) {
+        switch (ev.keyCode) {
+        case '^':
+            escape = (entry.vnSym == vnl_a || entry.vnSym == vnl_o || entry.vnSym == vnl_e);
+            break;
+        case '(':
+            escape = (entry.vnSym == vnl_a);
+            break;
+        case '+':
+            escape = (entry.vnSym == vnl_o || entry.vnSym == vnl_u);
+            break;
+        case '\'':
+        case '`':
+        case '?':
+        case '~':
+        case '.':
+            escape = (entry.tone == 0);
+            break;
+        }
+    }
+    else if (entry.form == vnw_nonVn) {
+        unsigned char ch = toupper(entry.keyCode);
+        switch (ev.keyCode) {
+        case '^':
+            escape = (ch == 'A' || ch == 'O' || ch == 'E');
+            break;
+        case '(':
+            escape = (ch == 'A');
+            break;
+        case '+':
+            escape = (ch == 'O' || ch == 'U');
+            break;
+        case '\'':
+        case '`':
+        case '?':
+        case '~':
+        case '.':
+            escape = (ch == 'A' || ch == 'E' || ch == 'I' ||
+                      ch == 'O' || ch == 'U' || ch == 'Y');
+            break;
+        }
+    }
+  
+    if (escape) {
+        m_current++;
+        WordInfo *p = &m_buffer[m_current];
+        p->form = (ev.chType == ukcWordBreak) ? vnw_empty : vnw_nonVn;
+        p->c1Offset = p->c2Offset = p->vOffset = -1;
+        p->keyCode = '?';
+        p->vnSym = vnl_nonVnChar;
+
+        m_current++;
+        p++;
+        p->form = (ev.chType == ukcWordBreak) ? vnw_empty : vnw_nonVn;
+        p->c1Offset = p->c2Offset = p->vOffset = -1;
+        p->keyCode = ev.keyCode;
+        p->vnSym = vnl_nonVnChar;
+
+        //write output
+        m_pOutBuf[0] = '\\';
+        m_pOutBuf[1] = ev.keyCode;
+        *m_pOutSize = 2;
+        m_outputWritten = true;
+    }
+    return escape;
+}
+
+//----------------------------------------------------------
+int UkEngine::processAppend(UkKeyEvent & ev)
+{
+    int ret = 0;
+    switch (ev.chType) {
+    case ukcReset:
+#if defined(_WIN32)
+        if (ev.keyCode == ENTER_CHAR) {
+            if (m_pCtrl->options.macroEnabled && macroMatch(ev))
+                return 1;
+        }
+#endif
+        reset();
+        return 0;
+    case ukcWordBreak:
+        m_singleMode = false;
+        return processWordEnd(ev);
+    case ukcNonVn:
+        {
+            if (m_pCtrl->vietKey && m_pCtrl->charsetId == CONV_CHARSET_VIQR && checkEscapeVIQR(ev))
+                return 1;
+
+            m_current++;
+            WordInfo & entry = m_buffer[m_current];
+            entry.form = (ev.chType == ukcWordBreak) ? vnw_empty : vnw_nonVn;
+            entry.c1Offset = entry.c2Offset = entry.vOffset = -1;
+            entry.keyCode = ev.keyCode;
+            entry.vnSym = vnToLower(ev.vnSym);
+            entry.tone = 0;
+            entry.caps = (entry.vnSym != ev.vnSym);
+            if (!m_pCtrl->vietKey || m_pCtrl->charsetId != CONV_CHARSET_UNI_CSTRING)
+                return 0;
+            markChange(m_current);
+            return 1;
+        }
+    case ukcVn:
+        {
+            if (IsVnVowel[ev.vnSym]) {
+                VnLexiName v = (VnLexiName)StdVnNoTone[vnToLower(ev.vnSym)];
+                if (m_current >= 0 && m_buffer[m_current].form == vnw_c &&
+                      ((m_buffer[m_current].cseq == cs_q && v == vnl_u) ||
+                      (m_buffer[m_current].cseq == cs_g && v == vnl_i))) {
+                    return appendConsonnant(ev); //process u after q, i after g as consonnants
+                }
+                return appendVowel(ev);
+            }
+            return appendConsonnant(ev);
+        }
+        break;
+    }
+
+    return ret;
+}
+
+//----------------------------------------------------------
+int UkEngine::appendVowel(UkKeyEvent & ev)
+{
+    bool autoCompleted = false;
+
+    m_current++;
+    WordInfo & entry = m_buffer[m_current];
+
+    VnLexiName lowerSym = vnToLower(ev.vnSym);
+    VnLexiName canSym = (VnLexiName)StdVnNoTone[lowerSym];
+
+    entry.vnSym = canSym;
+    entry.caps = (lowerSym != ev.vnSym);
+    entry.tone = (lowerSym - canSym)/2;
+    entry.keyCode = ev.keyCode;
+
+    if (m_current == 0 || !m_pCtrl->vietKey) {
+        entry.form = vnw_v;
+        entry.c1Offset = entry.c2Offset = -1;
+        entry.vOffset = 0;
+        entry.vseq = lookupVSeq(canSym);
+
+        if (!m_pCtrl->vietKey || 
+            ((m_pCtrl->charsetId != CONV_CHARSET_UNI_CSTRING) && isalpha(entry.keyCode)) ) {
+            return 0;
+        }
+        markChange(m_current);
+        return 1;
+    }
+  
+    WordInfo & prev = m_buffer[m_current-1];
+    VowelSeq vs, newVs;
+    ConSeq cs;
+    int prevTonePos;
+    int tone, newTone, tonePos, newTonePos;
+
+    switch (prev.form) {
+
+    case vnw_empty:
+        entry.form = vnw_v;
+        entry.c1Offset = entry.c2Offset = -1;
+        entry.vOffset = 0;
+        entry.vseq = newVs = lookupVSeq(canSym);
+        break;
+
+    case vnw_nonVn:
+    case vnw_cvc:
+    case vnw_vc:
+        entry.form = vnw_nonVn;
+        entry.c1Offset = entry.c2Offset = entry.vOffset = -1;
+        break;
+
+    case vnw_v:
+    case vnw_cv:
+        vs = prev.vseq;
+        prevTonePos = (m_current - 1) - (VSeqList[vs].len - 1) + getTonePosition(vs, true);
+        tone = m_buffer[prevTonePos].tone;
+    
+        if (lowerSym != canSym && tone != 0) //new sym has a tone, but there's is already a preceeding tone
+            newVs = vs_nil;
+        else {
+            if (VSeqList[vs].len == 3)
+                newVs = vs_nil;
+            else if (VSeqList[vs].len == 2)
+                newVs = lookupVSeq(VSeqList[vs].v[0], VSeqList[vs].v[1], canSym);
+            else
+                newVs = lookupVSeq(VSeqList[vs].v[0], canSym);
+        }
+
+        if (newVs != vs_nil && prev.form == vnw_cv) {
+            cs = m_buffer[m_current - 1 - prev.c1Offset].cseq;
+            if (!isValidCV(cs, newVs))
+                newVs = vs_nil;
+        }
+
+        if (newVs == vs_nil) {
+            entry.form = vnw_nonVn;
+            entry.c1Offset = entry.c2Offset = entry.vOffset = -1;
+            break;
+        }
+    
+        entry.form = prev.form;
+        if (prev.form == vnw_cv)
+            entry.c1Offset = prev.c1Offset + 1;
+        else
+            entry.c1Offset = -1;
+        entry.c2Offset = -1;
+        entry.vOffset = 0;
+        entry.vseq = newVs;
+        entry.tone = 0;
+        
+        newTone = (lowerSym - canSym)/2;
+        if (tone == 0) {
+            if (newTone != 0) {
+                tone = newTone;
+                tonePos = getTonePosition(newVs, true) + ((m_current - 1) - VSeqList[vs].len + 1);
+                markChange(tonePos);
+                m_buffer[tonePos].tone = tone;
+                return 1;
+            }
+        }
+        else {
+            newTonePos = getTonePosition(newVs, true) + ((m_current - 1) - VSeqList[vs].len + 1);
+            if (newTonePos != prevTonePos) {
+                markChange(prevTonePos);
+                m_buffer[prevTonePos].tone = 0;
+                markChange(newTonePos);
+                if (newTone != 0)
+                    tone = newTone;
+                m_buffer[newTonePos].tone = tone;
+                return 1;
+            }
+            if (newTone != 0 && newTone != tone) {
+                tone = newTone;
+                markChange(prevTonePos);
+                m_buffer[prevTonePos].tone = tone;
+                return 1;
+            }
+
+        }
+
+        break;
+    case vnw_c:
+        newVs = lookupVSeq(canSym);
+        cs = prev.cseq;
+        if (!isValidCV(cs, newVs)) {
+            entry.form = vnw_nonVn;
+            entry.c1Offset = entry.c2Offset = entry.vOffset = -1;
+            break;
+        }
+
+        entry.form = vnw_cv;
+        entry.c1Offset = 1;
+        entry.c2Offset = -1;
+        entry.vOffset = 0;
+        entry.vseq = newVs;
+
+        if (cs == cs_gi && prev.tone != 0) {
+            if (entry.tone == 0)
+                entry.tone = prev.tone;
+            markChange(m_current - 1);
+            prev.tone = 0;
+            return 1;
+        }
+    
+        break;
+  }
+
+    if (!autoCompleted &&
+        (m_pCtrl->charsetId != CONV_CHARSET_UNI_CSTRING) && 
+        isalpha(entry.keyCode)) {
+        return 0;
+    }
+
+    markChange(m_current);
+    return 1;
+}
+
+//----------------------------------------------------------
+int UkEngine::appendConsonnant(UkKeyEvent & ev)
+{
+    bool complexEvent = false;
+    m_current++;
+    WordInfo & entry = m_buffer[m_current];
+
+    VnLexiName lowerSym = vnToLower(ev.vnSym);
+
+    entry.vnSym = lowerSym;
+    entry.caps = (lowerSym != ev.vnSym);
+    entry.keyCode = ev.keyCode;
+    entry.tone = 0;
+
+    if (m_current == 0 || !m_pCtrl->vietKey) {
+        entry.form = vnw_c;
+        entry.c1Offset = 0;
+        entry.c2Offset = -1;
+        entry.vOffset = -1;
+        entry.cseq = lookupCSeq(lowerSym);
+        if (!m_pCtrl->vietKey || m_pCtrl->charsetId != CONV_CHARSET_UNI_CSTRING)
+            return 0;
+        markChange(m_current);
+        return 1;
+    }
+
+    ConSeq cs, newCs, c1;
+    VowelSeq vs, newVs;
+    bool isValid;
+
+    WordInfo & prev = m_buffer[m_current-1];
+
+    switch (prev.form) {
+    case vnw_nonVn:
+        entry.form = vnw_nonVn;
+        entry.c1Offset = entry.c2Offset = entry.vOffset = -1;
+        if (m_pCtrl->charsetId != CONV_CHARSET_UNI_CSTRING)
+            return 0;
+        markChange(m_current);
+        return 1;
+    case vnw_empty:
+        entry.form = vnw_c;
+        entry.c1Offset = 0;
+        entry.c2Offset = -1;
+        entry.vOffset = -1;
+        entry.cseq = lookupCSeq(lowerSym);
+        if (m_pCtrl->charsetId != CONV_CHARSET_UNI_CSTRING)
+            return 0;
+        markChange(m_current);
+        return 1;
+    case vnw_v:
+    case vnw_cv:
+        vs = prev.vseq;
+        newVs = vs;
+        if (vs == vs_uoh || vs == vs_uho) {
+            newVs = vs_uhoh;
+        }
+
+        c1 = cs_nil;
+        if (prev.c1Offset != -1)
+            c1 = m_buffer[m_current-1-prev.c1Offset].cseq;
+
+        newCs = lookupCSeq(lowerSym);
+        isValid = isValidCVC(c1, newVs, newCs);
+
+        if (isValid) {
+            //check u+o -> u+o+
+            if (vs == vs_uho) {
+                markChange(m_current-1);
+                prev.vnSym = vnl_oh;
+                prev.vseq = vs_uhoh;
+                complexEvent = true;
+            }
+            else if (vs == vs_uoh) {
+                markChange(m_current-2);
+                m_buffer[m_current-2].vnSym = vnl_uh;
+                m_buffer[m_current-2].vseq = vs_uh;
+                prev.vseq = vs_uhoh;
+                complexEvent = true;
+            }
+
+            if (prev.form == vnw_v) {
+                entry.form = vnw_vc;
+                entry.c1Offset = -1;
+                entry.c2Offset = 0;
+                entry.vOffset = 1;
+            }
+            else { //prev == vnw_cv
+                entry.form = vnw_cvc;
+                entry.c1Offset = prev.c1Offset + 1;
+                entry.c2Offset = 0;
+                entry.vOffset = 1;
+            }
+            entry.cseq = newCs;
+
+            //reposition tone if needed
+            int oldIdx = (m_current-1) - (VSeqList[vs].len - 1) + getTonePosition(vs, true);
+            if (m_buffer[oldIdx].tone != 0) {
+                int newIdx = (m_current-1) - (VSeqList[newVs].len - 1) + getTonePosition(newVs, false);
+                if (newIdx != oldIdx) {
+                    markChange(newIdx);
+                    m_buffer[newIdx].tone = m_buffer[oldIdx].tone;
+                    markChange(oldIdx);
+                    m_buffer[oldIdx].tone = 0;
+                    return 1;
+                }
+            }
+        }
+        else {
+            entry.form = vnw_nonVn;
+            entry.c1Offset = entry.c2Offset = entry.vOffset = -1;
+        }
+
+        if (complexEvent) {
+            return 1;
+        }
+
+        if (m_pCtrl->charsetId != CONV_CHARSET_UNI_CSTRING)
+            return 0;
+        markChange(m_current);
+        return 1;
+    case vnw_c:
+    case vnw_vc:
+    case vnw_cvc:
+        cs = prev.cseq;
+        if (CSeqList[cs].len == 3)
+            newCs = cs_nil;
+        else if (CSeqList[cs].len == 2)
+            newCs = lookupCSeq(CSeqList[cs].c[0], CSeqList[cs].c[1], lowerSym);
+        else
+            newCs = lookupCSeq(CSeqList[cs].c[0], lowerSym);
+        
+        if (newCs != cs_nil && (prev.form == vnw_vc || prev.form == vnw_cvc)) {
+            // Check CVC combination
+            c1 = cs_nil;
+            if (prev.c1Offset != -1)
+                c1 = m_buffer[m_current-1-prev.c1Offset].cseq;
+
+            int vIdx = (m_current - 1) - prev.vOffset;
+            vs = m_buffer[vIdx].vseq;
+            isValid = isValidCVC(c1, vs, newCs);
+
+            if (!isValid)
+                newCs = cs_nil;
+        }
+
+        if (newCs == cs_nil) {
+            entry.form = vnw_nonVn;
+            entry.c1Offset = entry.c2Offset = entry.vOffset = -1;
+        }
+        else {
+            if (prev.form == vnw_c) {
+                entry.form = vnw_c;
+                entry.c1Offset = 0;
+                entry.c2Offset = -1;
+                entry.vOffset = -1;
+            }
+            else if (prev.form == vnw_vc) {
+                entry.form = vnw_vc;
+                entry.c1Offset = -1;
+                entry.c2Offset = 0;
+                entry.vOffset = prev.vOffset + 1;
+            }
+            else { //vnw_cvc
+                entry.form = vnw_cvc;
+                entry.c1Offset = prev.c1Offset + 1;
+                entry.c2Offset = 0;
+                entry.vOffset = prev.vOffset + 1;
+            }
+            entry.cseq = newCs;
+        }
+        if (m_pCtrl->charsetId != CONV_CHARSET_UNI_CSTRING)
+            return 0;
+        markChange(m_current);
+        return 1;
+    }
+
+    if (m_pCtrl->charsetId != CONV_CHARSET_UNI_CSTRING)
+        return 0;
+    markChange(m_current);
+    return 1;
+}
+
+//----------------------------------------------------------
+int UkEngine::processEscChar(UkKeyEvent & ev)
+{
+    if (m_pCtrl->vietKey && 
+        m_current >=0 && m_buffer[m_current].form != vnw_empty && m_buffer[m_current].form != vnw_nonVn) {
+        m_toEscape = true;
+    }
+    return processAppend(ev);
+}
+
+//----------------------------------------------------------
+void UkEngine::pass(int keyCode)
+{
+    UkKeyEvent ev;
+    m_pCtrl->input.keyCodeToEvent(keyCode, ev);
+    processAppend(ev);
+}
+
+//---------------------------------------------
+// This can be called only after other processing have been done.
+// The new event is supposed to be put into m_buffer already
+//---------------------------------------------
+int UkEngine::processNoSpellCheck(UkKeyEvent & ev)
+{
+    WordInfo & entry = m_buffer[m_current];
+    if (IsVnVowel[entry.vnSym]) {
+        entry.form = vnw_v;
+        entry.vOffset = 0;
+        entry.vseq = lookupVSeq(entry.vnSym);
+        entry.c1Offset = entry.c2Offset = -1;
+    }
+    else {
+        entry.form = vnw_c;
+        entry.c1Offset = 0;
+        entry.c2Offset = -1;
+        entry.vOffset = -1;
+        entry.cseq = lookupCSeq(entry.vnSym);
+    }
+
+    if (ev.evType == vneNormal &&
+        ((entry.keyCode >= 'a' && entry.keyCode <= 'z') || 
+         (entry.keyCode >= 'A' && entry.keyCode <= 'Z') ) )
+        return 0;
+    markChange(m_current);
+    return 1;
+}
+//----------------------------------------------------------
+int UkEngine::process(unsigned int keyCode, int & backs, unsigned char *outBuf, int & outSize, UkOutputType & outType)
+{
+    UkKeyEvent ev;
+    prepareBuffer();
+    m_backs = 0;
+    m_changePos = m_current+1;
+    m_pOutBuf = outBuf;
+    m_pOutSize = &outSize;
+    m_outputWritten = false;
+    m_reverted = false;
+    m_keyRestored = false;
+    m_keyRestoring = false;
+    m_outType = UkCharOutput;
+
+    m_pCtrl->input.keyCodeToEvent(keyCode, ev);
+
+    int ret;
+    if (!m_toEscape) {
+        ret = (this->*UkKeyProcList[ev.evType])(ev);
+    }
+    else {
+        m_toEscape = false;
+        if (m_current < 0 || ev.evType == vneNormal || ev.evType == vneEscChar) {
+            ret = processAppend(ev);
+        }
+        else {
+            m_current--;
+            processAppend(ev);
+            markChange(m_current); //this will assign m_backs to 1 and mark the character for output
+            ret = 1;
+        }
+    }
+
+    if ( m_pCtrl->vietKey &&
+         m_current >= 0 && m_buffer[m_current].form == vnw_nonVn &&
+         ev.chType == ukcVn &&
+         (!m_pCtrl->options.spellCheckEnabled || m_singleMode) )
+    {
+
+        //The spell check has failed, but because we are in non-spellcheck mode,
+        //we consider the new character as the beginning of a new word
+        ret = processNoSpellCheck(ev);
+        /*
+        if ((!m_pCtrl->options.spellCheckEnabled || m_singleMode) || 
+            ( !m_reverted && 
+              (m_current < 1 || m_buffer[m_current-1].form != vnw_nonVn)) ) {
+
+            ret = processNoSpellCheck(ev);
+        }
+        */
+    }
+
+    //we add key to key buffer only if that key has not caused a reset
+    if (m_current >= 0) {
+        ev.chType = m_pCtrl->input.getCharType(ev.keyCode);
+        m_keyCurrent++;
+        m_keyStrokes[m_keyCurrent].ev = ev;
+        m_keyStrokes[m_keyCurrent].converted = (ret && !m_keyRestored);
+    }
+
+    if (ret == 0) {
+        backs = 0;
+        outSize = 0;
+        outType = m_outType;
+        return 0;
+    }
+
+    backs = m_backs;
+    if (!m_outputWritten) {
+        writeOutput(outBuf, outSize);
+    }
+    outType = m_outType;
+
+    return ret;
+}
+
+
+//----------------------------------------------------------
+// Returns 0 on success
+//         error code otherwise
+//  outBuf: buffer to write
+//  outSize: [in] size of buffer in bytes
+//           [out] bytes written to buffer
+//----------------------------------------------------------
+int UkEngine::writeOutput(unsigned char *outBuf, int & outSize)
+{
+    StdVnChar stdChar;
+    int i, bytesWritten;
+    int ret = 1;
+    StringBOStream os(outBuf, outSize);
+    VnCharset *pCharset = VnCharsetLibObj.getVnCharset(m_pCtrl->charsetId);
+    pCharset->startOutput();
+
+    for (i = m_changePos; i <= m_current; i++) {
+        if (m_buffer[i].vnSym != vnl_nonVnChar) {
+            //process vn symbol
+            stdChar = m_buffer[i].vnSym + VnStdCharOffset;
+            if (m_buffer[i].caps)
+                stdChar--;
+            if (m_buffer[i].tone != 0)
+                stdChar += m_buffer[i].tone * 2;
+        }
+        else {
+            stdChar = IsoToStdVnChar(m_buffer[i].keyCode);
+        }
+    
+        if (stdChar != INVALID_STD_CHAR)
+            ret = pCharset->putChar(os, stdChar, bytesWritten);
+    }
+
+    outSize = os.getOutBytes();
+    return (ret? 0 : VNCONV_OUT_OF_MEMORY);
+}
+
+//---------------------------------------------
+// Returns the number of backspaces needed to
+// go back from last to first
+//---------------------------------------------
+int UkEngine::getSeqSteps(int first, int last)
+{
+    StdVnChar stdChar;
+
+    if (last < first)
+        return 0;
+
+    if (m_pCtrl->charsetId == CONV_CHARSET_XUTF8 || 
+        m_pCtrl->charsetId == CONV_CHARSET_UNICODE)
+        return (last - first +  1);
+
+    StringBOStream os(0, 0);
+    int i, bytesWritten;
+
+    VnCharset *pCharset = VnCharsetLibObj.getVnCharset(m_pCtrl->charsetId);
+    pCharset->startOutput();
+
+    for (i = first; i <= last; i++) {
+        if (m_buffer[i].vnSym != vnl_nonVnChar) {
+            //process vn symbol
+            stdChar = m_buffer[i].vnSym + VnStdCharOffset;
+            if (m_buffer[i].caps)
+                stdChar--;
+            if (m_buffer[i].tone != 0)
+                stdChar += m_buffer[i].tone*2;
+        }
+        else {
+            stdChar = m_buffer[i].keyCode;
+        }
+    
+        if (stdChar != INVALID_STD_CHAR)
+            pCharset->putChar(os, stdChar, bytesWritten);
+    }
+  
+    int len = os.getOutBytes();
+    if (m_pCtrl->charsetId == CONV_CHARSET_UNIDECOMPOSED)
+        len = len / 2;
+    return len;
+}
+
+//---------------------------------------------
+void UkEngine::markChange(int pos)
+{
+    if (pos < m_changePos) {
+        m_backs += getSeqSteps(pos, m_changePos-1);
+        m_changePos = pos;
+    }
+}
+
+//----------------------------------------------------------------
+// Called from processBackspace to keep
+// character buffer (m_buffer) and key stroke buffer in synch
+//----------------------------------------------------------------
+void UkEngine::synchKeyStrokeBuffer()
+{
+    //synchronize with key-stroke buffer
+    if (m_keyCurrent >= 0)
+        m_keyCurrent--;
+    if (m_current >= 0 && m_buffer[m_current].form == vnw_empty) {
+        //in character buffer, we have reached a word break,
+        //so we also need to move key stroke pointer backward to corresponding word break
+        while (m_keyCurrent >= 0 && m_keyStrokes[m_keyCurrent].ev.chType != ukcWordBreak)
+        {
+            m_keyCurrent--;
+        }
+    }
+}
+
+//---------------------------------------------
+int UkEngine::processBackspace(int & backs, unsigned char *outBuf, int & outSize, UkOutputType & outType)
+{
+    outType = UkCharOutput;
+    if (!m_pCtrl->vietKey || m_current < 0) {
+        backs = 0;
+        outSize = 0;
+        return 0;
+    }
+
+    m_backs = 0;
+    m_changePos = m_current + 1;
+    markChange(m_current);
+
+    if (m_current == 0 || 
+        m_buffer[m_current].form == vnw_empty ||
+        m_buffer[m_current].form == vnw_nonVn ||
+        m_buffer[m_current].form == vnw_c ||
+        m_buffer[m_current-1].form == vnw_c ||
+        m_buffer[m_current-1].form == vnw_cvc ||
+        m_buffer[m_current-1].form == vnw_vc) {
+
+        m_current--;
+        backs = m_backs;
+        outSize = 0;
+        synchKeyStrokeBuffer();
+        return (backs > 1);
+    }
+  
+    VowelSeq vs, newVs;
+    int curTonePos, newTonePos, tone, vStart, vEnd;
+
+    vEnd = m_current - m_buffer[m_current].vOffset;
+    vs = m_buffer[vEnd].vseq;
+    vStart = vEnd - VSeqList[vs].len + 1;
+    newVs = m_buffer[m_current-1].vseq;
+    curTonePos = vStart +  getTonePosition(vs, vEnd == m_current);
+    newTonePos = vStart + getTonePosition(newVs, true);
+    tone = m_buffer[curTonePos].tone;
+
+    if (tone == 0 || curTonePos == newTonePos || 
+        (curTonePos == m_current && m_buffer[m_current].tone != 0)) {
+        m_current--;
+        backs = m_backs;
+        outSize = 0;
+        synchKeyStrokeBuffer();
+        return (backs > 1);
+    }
+
+    markChange(newTonePos);
+    m_buffer[newTonePos].tone = tone;
+    markChange(curTonePos);
+    m_buffer[curTonePos].tone = 0;
+    m_current--;
+    synchKeyStrokeBuffer();
+    backs = m_backs;
+    writeOutput(outBuf, outSize);
+    return 1;
+}
+
+//------------------------------------------------
+void UkEngine::reset()
+{
+    m_current = -1;
+    m_keyCurrent = -1;
+    m_singleMode = false;
+    m_toEscape = false;
+}
+
+//------------------------------------------------
+void UkEngine::resetKeyBuf()
+{
+    m_keyCurrent = -1;
+}
+
+//------------------------------------------------
+UkEngine::UkEngine()
+{
+    if (!m_classInit) {
+        engineClassInit();
+        m_classInit = true;
+    }
+    m_pCtrl = 0;
+    m_bufSize = MAX_UK_ENGINE;
+    m_keyBufSize = MAX_UK_ENGINE;
+    m_current = -1;
+    m_keyCurrent = -1;
+    m_singleMode = false;
+    m_keyCheckFunc = 0;
+    m_reverted = false;
+    m_toEscape = false;
+    m_keyRestored = false;
+}
+
+//----------------------------------------------------
+// make sure there are at least 10 entries available
+//----------------------------------------------------
+void UkEngine::prepareBuffer()
+{
+    int rid;
+    //prepare symbol buffer
+    if (m_current >= 0 && m_current + 10 >= m_bufSize) {
+        // Get rid of at least half of the current entries
+        // don't get rid from the middle of a word.
+        for (rid = m_current/2; m_buffer[rid].form != vnw_empty && rid < m_current; rid++);
+        if (rid == m_current) {
+            m_current = -1;
+        }
+        else {
+            rid++;
+            memmove(m_buffer, m_buffer+rid, (m_current-rid+1)*sizeof(WordInfo));
+            m_current -= rid;
+        }
+    }
+
+    //prepare key stroke buffer
+    if (m_keyCurrent > 0 && m_keyCurrent + 1 >= m_keyBufSize) {
+        // Get rid of at least half of the current entries
+        rid = m_keyCurrent/2;
+        memmove(m_keyStrokes, m_keyStrokes + rid, (m_keyCurrent-rid+1)*sizeof(m_keyStrokes[0]));
+        m_keyCurrent -= rid;
+    }
+
+}
+
+#define ENTER_CHAR 13
+enum VnCaseType {VnCaseNoChange, VnCaseAllCapital, VnCaseAllSmall};
+
+//----------------------------------------------------
+int UkEngine::macroMatch(UkKeyEvent & ev)
+{
+    int capsLockOn = 0;
+    int shiftPressed = 0;
+    if (m_keyCheckFunc)
+        m_keyCheckFunc(&shiftPressed, &capsLockOn);
+
+    if (shiftPressed && (ev.keyCode ==' ' || ev.keyCode == ENTER_CHAR))
+        return 0;
+
+    const StdVnChar *pMacText = NULL;
+    StdVnChar key[MAX_MACRO_KEY_LEN+1];
+    StdVnChar *pKeyStart;
+
+    // Use static macro text so we can gain a bit of performance
+    // by avoiding memory allocation each time this function is called
+    static StdVnChar macroText[MAX_MACRO_TEXT_LEN+1];
+
+    int i, j;
+
+    i = m_current;
+    while (i >= 0 && (m_current-i + 1) < MAX_MACRO_KEY_LEN) {
+        while (i>=0 && m_buffer[i].form != vnw_empty && (m_current-i + 1) < MAX_MACRO_KEY_LEN)
+            i--;
+        if (i>=0 && m_buffer[i].form != vnw_empty)
+            return 0;
+
+        if (i>=0) {
+            if (m_buffer[i].vnSym != vnl_nonVnChar) {
+                key[0] = m_buffer[i].vnSym + VnStdCharOffset;
+                if (m_buffer[i].caps)
+                    key[0]--;
+                key[0] += m_buffer[i].tone*2;
+            }
+            else
+                key[0] = m_buffer[i].keyCode;
+        }
+
+        for (j=i+1; j<=m_current; j++) {
+            if (m_buffer[j].vnSym != vnl_nonVnChar) {
+                key[j-i] = m_buffer[j].vnSym + VnStdCharOffset;
+                if (m_buffer[j].caps)
+                    key[j-i]--;
+                key[j-i] += m_buffer[j].tone*2;
+            }
+            else
+                key[j-i] = m_buffer[j].keyCode;
+        }
+        key[m_current-i+1] = 0;
+        //search macro table
+        pMacText = m_pCtrl->macStore.lookup(key+1);
+        if (pMacText) {
+            i++; //mark the position where change is needed
+            pKeyStart = key + 1;
+            break;
+        }
+        if (i>=0) {
+            pMacText = m_pCtrl->macStore.lookup(key);
+            if (pMacText) {
+                pKeyStart = key;
+                break;
+            }
+        }
+        i--;
+    }
+
+    if (!pMacText) {
+        return 0;
+    }
+
+    markChange(i);
+
+    // determine the form of macro replacements: ALL CAPITALS, First Character Capital, or no change
+    VnCaseType macroCase;
+    if (IS_STD_VN_LOWER(*pKeyStart)) {
+        macroCase = VnCaseAllSmall;
+    }
+    else if (IS_STD_VN_UPPER(*pKeyStart)) {
+        macroCase = VnCaseAllCapital;
+        for (i=1; pKeyStart[i]; i++) {
+            if (IS_STD_VN_LOWER(pKeyStart[i])) {
+                macroCase = VnCaseNoChange;
+            }
+        }
+    }
+    else macroCase = VnCaseNoChange;
+
+    // Convert case of macro text according to macroCase
+    int charCount = 0;
+    while (pMacText[charCount] != 0)
+        charCount++;
+
+    for (i = 0; i < charCount; i++)
+    {
+        if (macroCase == VnCaseAllCapital)
+            macroText[i] = StdVnToUpper(pMacText[i]);
+        else if (macroCase == VnCaseAllSmall)
+            macroText[i] = StdVnToLower(pMacText[i]);
+        else
+            macroText[i] = pMacText[i];
+    }
+
+    // Convert to target output charset
+    int outSize;
+    int maxOutSize = *m_pOutSize;
+    int inLen = charCount * sizeof(StdVnChar);
+    VnConvert(CONV_CHARSET_VNSTANDARD, m_pCtrl->charsetId,
+               (UKBYTE *) macroText, (UKBYTE *)m_pOutBuf,
+               &inLen, &maxOutSize);
+    outSize = maxOutSize;
+
+    //write the last input character
+    StdVnChar vnChar;
+    if (outSize < *m_pOutSize) {
+        maxOutSize = *m_pOutSize - outSize;
+        if (ev.vnSym != vnl_nonVnChar)
+            vnChar = ev.vnSym + VnStdCharOffset;
+        else
+            vnChar = ev.keyCode;
+        inLen = sizeof(StdVnChar);
+        VnConvert(CONV_CHARSET_VNSTANDARD, m_pCtrl->charsetId,
+                   (UKBYTE *) &vnChar, ((UKBYTE *)m_pOutBuf) + outSize,
+                   &inLen, &maxOutSize);
+        outSize += maxOutSize;
+    }
+    int backs = m_backs; //store m_backs before calling reset
+    reset();
+    m_outputWritten = true;
+    m_backs = backs;
+    *m_pOutSize = outSize;
+    return 1;
+}
+
+//----------------------------------------------------
+int UkEngine::restoreKeyStrokes(int & backs, unsigned char *outBuf, int & outSize, UkOutputType & outType)
+{
+    outType = UkKeyOutput;
+    if (!lastWordHasVnMark()) {
+        backs = 0;
+        outSize = 0;
+        return 0;
+    }
+
+    m_backs = 0;
+    m_changePos = m_current+1;
+
+    int keyStart;
+    bool converted = false;
+    for (keyStart = m_keyCurrent; keyStart >= 0 && m_keyStrokes[keyStart].ev.chType != ukcWordBreak; keyStart--) {
+        if (m_keyStrokes[keyStart].converted) {
+            converted = true;
+        }
+    }
+    keyStart++;
+
+    if (!converted) {
+        //no key stroke has been converted, so it doesn't make sense to restore key strokes
+        backs = 0;
+        outSize = 0;
+        return 0;
+    }
+
+    //int i = m_current;
+    while (m_current >=0 && m_buffer[m_current].form != vnw_empty)
+        m_current--;
+    markChange(m_current+1);
+    backs = m_backs;
+
+    int count;
+    int i;
+    UkKeyEvent ev;
+    m_keyRestoring = true;
+    for (i=keyStart, count = 0; i <= m_keyCurrent; i++) {
+        if (count<outSize) {
+            outBuf[count++] = (unsigned char)m_keyStrokes[i].ev.keyCode;
+        }
+        m_pCtrl->input.keyCodeToSymbol(m_keyStrokes[i].ev.keyCode, ev);
+        m_keyStrokes[i].converted = false;
+        processAppend(ev);
+    }
+    outSize = count;
+    m_keyRestoring = false;
+
+    return 1;
+}
+
+//--------------------------------------------------
+void UkEngine::setSingleMode()
+{
+    m_singleMode = true;
+}
+
+//--------------------------------------------------
+void SetupUnikeyEngine()
+{
+    SetupInputClassifierTable();
+    int i;
+    VnLexiName lexi;
+
+    //Calculate IsoStdVnCharMap
+    for (i=0; i < 256; i++) {
+        IsoStdVnCharMap[i] = i;
+    }
+
+    for (i=0; SpecialWesternChars[i]; i++) {
+        IsoStdVnCharMap[SpecialWesternChars[i]] = (vnl_lastChar + i) + VnStdCharOffset;
+    }
+
+    for (i=0; i < 256; i++) {
+        if ((lexi = IsoToVnLexi(i)) != vnl_nonVnChar) {
+            IsoStdVnCharMap[i] = lexi + VnStdCharOffset;
+        }
+    }
+}
+
+//--------------------------------------------------
+bool UkEngine::atWordBeginning()
+{
+    return (m_current < 0 || m_buffer[m_current].form == vnw_empty);
+}
+
+//--------------------------------------------------
+// Check for macro first, if there's a match, expand macro. If not:
+// Spell-check, if is valid Vietnamese, return normally, if not:
+// restore key strokes if auto-restore is enabled
+//--------------------------------------------------
+int UkEngine::processWordEnd(UkKeyEvent & ev)
+{
+    if (m_pCtrl->options.macroEnabled && macroMatch(ev))
+        return 1;
+
+    if (!m_pCtrl->options.spellCheckEnabled || m_singleMode || m_current < 0 || m_keyRestoring) {
+        m_current++;
+        WordInfo & entry = m_buffer[m_current];
+        entry.form = vnw_empty;
+        entry.c1Offset = entry.c2Offset = entry.vOffset = -1;
+        entry.keyCode = ev.keyCode;
+        entry.vnSym = vnToLower(ev.vnSym);
+        entry.caps = (entry.vnSym != ev.vnSym);
+        return 0;
+    }
+
+    int outSize = 0;
+    if (m_pCtrl->options.autoNonVnRestore && lastWordIsNonVn()) {
+        outSize = *m_pOutSize;
+        if (restoreKeyStrokes(m_backs, m_pOutBuf, outSize, m_outType)) {
+            m_keyRestored = true;
+            m_outputWritten = true;
+        }
+    }
+
+    m_current++;
+    WordInfo & entry = m_buffer[m_current];
+    entry.form = vnw_empty;
+    entry.c1Offset = entry.c2Offset = entry.vOffset = -1;
+    entry.keyCode = ev.keyCode;
+    entry.vnSym = vnToLower(ev.vnSym);
+    entry.caps = (entry.vnSym != ev.vnSym);
+    
+    if (m_keyRestored && outSize < *m_pOutSize) {
+        m_pOutBuf[outSize] = ev.keyCode;
+        outSize++;
+        *m_pOutSize = outSize;
+        return 1;
+    }
+    return 0;
+}
+
+//---------------------------------------------------------------------------
+// Test if last word is a non-Vietnamese word, so that
+// the engine can restore key strokes if it is indeed not a Vietnamese word
+//---------------------------------------------------------------------------
+bool UkEngine::lastWordIsNonVn()
+{
+    if (m_current < 0)
+        return false;
+
+    switch (m_buffer[m_current].form) {
+        case vnw_nonVn:
+            return true;
+        case vnw_empty:
+        case vnw_c:
+            return false;
+        case vnw_v:
+        case vnw_cv:
+            return !VSeqList[m_buffer[m_current].vseq].complete;
+        case vnw_vc:
+        case vnw_cvc: {
+            int vIndex = m_current - m_buffer[m_current].vOffset;
+            VowelSeq vs = m_buffer[vIndex].vseq;
+            if (!VSeqList[vs].complete)
+                return true;
+            ConSeq cs = m_buffer[m_current].cseq;
+            ConSeq c1 = cs_nil;
+            if (m_buffer[m_current].c1Offset != -1)
+                c1 = m_buffer[m_current-m_buffer[m_current].c1Offset].cseq;
+
+            if (!isValidCVC(c1, vs, cs)) {
+                return true;
+            }
+
+            int tonePos = (vIndex - VSeqList[vs].len + 1) + getTonePosition(vs, false);
+            int tone = m_buffer[tonePos].tone;
+            if ((cs == cs_c || cs == cs_ch || cs == cs_p || cs == cs_t) &&
+                (tone == 2 || tone == 3 || tone == 4))
+            {
+                return true;
+            }
+        }
+    }
+    return false;
+}
+
+//---------------------------------------------------------------------------
+// Test if last word has a Vietnamese mark, that is tones, decorators
+//---------------------------------------------------------------------------
+bool UkEngine::lastWordHasVnMark()
+{
+    for (int i=m_current; i>=0 && m_buffer[i].form != vnw_empty; i--) {
+        VnLexiName sym = m_buffer[i].vnSym;
+        if (sym != vnl_nonVnChar) {
+            if (IsVnVowel[sym]) {
+                if (m_buffer[i].tone)
+                    return true;
+            }
+            if (sym != StdVnRootChar[sym] )
+                return true;
+        }
+    }
+    return false;
+}
diff --git a/ukengine/ukengine.h b/ukengine/ukengine.h
new file mode 100644 (file)
index 0000000..d8aaf15
--- /dev/null
@@ -0,0 +1,167 @@
+// -*- mode:c++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
+/* Unikey Vietnamese Input Method
+ * Copyright (C) 2000-2005 Pham Kim Long
+ * Contact:
+ *   unikey@gmail.com
+ *   UniKey project: http://unikey.org
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __UKENGINE_H
+#define __UKENGINE_H
+
+#include "charset.h"
+#include "vnlexi.h"
+#include "inputproc.h"
+#include "mactab.h"
+
+//This is a shared object among processes, do not put any pointer in it
+struct UkSharedMem {
+    //states
+    int initialized;
+    int vietKey;
+    int iconShown;
+
+    UnikeyOptions options;
+    UkInputProcessor input;
+    int usrKeyMapLoaded;
+    int usrKeyMap[256];
+    int charsetId;
+
+#if defined(WIN32)
+    UnikeySysInfo sysInfo;
+#endif
+    CMacroTable macStore;
+};
+
+#define CTRL_SHIFT_SW 0
+#define ALT_Z_SW 1
+
+#define MAX_UK_ENGINE 128
+
+enum VnWordForm {vnw_nonVn, vnw_empty, vnw_c, vnw_v, vnw_cv, vnw_vc, vnw_cvc};
+
+typedef void (* CheckKeyboardCaseCb)(int *pShiftPressed, int *pCapslockOn);
+
+struct KeyBufEntry {
+    UkKeyEvent ev;
+    bool converted;
+};
+
+class UkEngine
+{
+public:
+    UkEngine();
+    void setCtrlInfo(UkSharedMem *p)
+    {
+        m_pCtrl = p;
+    }
+
+    void setCheckKbCaseFunc(CheckKeyboardCaseCb pFunc) 
+    {
+        m_keyCheckFunc = pFunc;
+    }
+
+    bool atWordBeginning();
+
+    int process(unsigned int keyCode, int & backs, unsigned char *outBuf, int & outSize, UkOutputType & outType);
+    void pass(int keyCode); //just pass through without filtering
+    void setSingleMode();
+
+    int processBackspace(int & backs, unsigned char *outBuf, int & outSize, UkOutputType & outType);
+    void reset();
+    int restoreKeyStrokes(int & backs, unsigned char *outBuf, int & outSize, UkOutputType & outType);
+
+    //following methods must be public just to enable the use of pointers to them
+    //they should not be called from outside.
+    int processTone(UkKeyEvent & ev);
+    int processRoof(UkKeyEvent & ev);
+    int processHook(UkKeyEvent & ev);
+    int processAppend(UkKeyEvent & ev);
+    int appendVowel(UkKeyEvent & ev);
+    int appendConsonnant(UkKeyEvent & ev);
+    int processDd(UkKeyEvent & ev);
+    int processMapChar(UkKeyEvent & ev);
+    int processTelexW(UkKeyEvent & ev);
+    int processEscChar(UkKeyEvent & ev);
+    bool lastWordIsNonVn();
+
+protected:
+    static bool m_classInit;
+    CheckKeyboardCaseCb m_keyCheckFunc;
+    UkSharedMem *m_pCtrl;
+
+    int m_changePos;
+    int m_backs;
+    int m_bufSize;
+    int m_current;
+    int m_singleMode;
+
+    int m_keyBufSize;
+    //unsigned int m_keyStrokes[MAX_UK_ENGINE];
+    KeyBufEntry m_keyStrokes[MAX_UK_ENGINE];
+    int m_keyCurrent;
+    bool m_toEscape;
+
+    //varables valid in one session
+    unsigned char *m_pOutBuf;
+    int *m_pOutSize;
+    bool m_outputWritten;
+    bool m_reverted;
+    bool m_keyRestored;
+    bool m_keyRestoring;
+    UkOutputType m_outType;
+  
+    struct WordInfo {
+        //info for word ending at this position
+        VnWordForm form;
+        int c1Offset, vOffset, c2Offset;
+
+        union {
+            VowelSeq vseq;
+            ConSeq cseq;
+        };
+
+        //info for current symbol
+        int caps, tone;
+        //canonical symbol, after caps, tone are removed
+        //for non-Vn, vnSym == -1
+        VnLexiName vnSym;
+        int keyCode;
+    };
+
+    WordInfo m_buffer[MAX_UK_ENGINE];
+
+    int processHookWithUO(UkKeyEvent & ev);
+    int macroMatch(UkKeyEvent & ev);
+    void markChange(int pos);
+    void prepareBuffer(); //make sure we have a least 10 entries available
+    int writeOutput(unsigned char *outBuf, int & outSize);
+    //int getSeqLength(int first, int last);
+    int getSeqSteps(int first, int last);
+    int getTonePosition(VowelSeq vs, bool terminated);
+    void resetKeyBuf();
+    int checkEscapeVIQR(UkKeyEvent & ev);
+    int processNoSpellCheck(UkKeyEvent & ev);
+    int processWordEnd(UkKeyEvent & ev);
+    void synchKeyStrokeBuffer();
+    bool lastWordHasVnMark();
+};
+
+void SetupUnikeyEngine();
+
+#endif
diff --git a/ukengine/unikey.cpp b/ukengine/unikey.cpp
new file mode 100644 (file)
index 0000000..9251044
--- /dev/null
@@ -0,0 +1,208 @@
+// -*- coding:unix; mode:c++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
+/*------------------------------------------------------------------------------
+UniKey - Open-source Vietnamese Keyboard
+Copyright (C) 1998-2004 Pham Kim Long
+Contact:
+  longcz@yahoo.com
+  http://unikey.sf.net
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+--------------------------------------------------------------------------------*/
+
+#include <ctype.h>
+#include <memory.h>
+#include <stdio.h>
+#include <iostream>
+#include "unikey.h"
+#include "ukengine.h"
+#include "usrkeymap.h"
+
+using namespace std;
+
+//---- exported variables for use in UkEnginge class ----
+UkSharedMem *pShMem = 0;
+
+UkEngine MyKbEngine;
+
+int UnikeyCapsLockOn = 0;
+int UnikeyShiftPressed = 0;
+//----------------------------------------------------
+
+unsigned char UnikeyBuf[1024];
+int UnikeyBackspaces;
+int UnikeyBufChars;
+UkOutputType UnikeyOutput;
+
+//--------------------------------------------
+void UnikeySetInputMethod(UkInputMethod im)
+{
+  if (im == UkTelex || im == UkVni || im == UkViqr) {
+    pShMem->input.setIM(im);
+    MyKbEngine.reset();
+  }
+  else if (im == UkUsrIM && pShMem->usrKeyMapLoaded) {
+    //cout << "Switched to user mode\n"; //DEBUG
+    pShMem->input.setIM(pShMem->usrKeyMap);
+    MyKbEngine.reset();
+  }
+
+  //cout << "IM changed to: " << im << endl; //DEBUG
+}
+
+
+//--------------------------------------------
+void UnikeySetCapsState(int shiftPressed, int CapsLockOn)
+{
+  //UnikeyCapsAll = (shiftPressed && !CapsLockOn) || (!shiftPressed && CapsLockOn);
+  UnikeyCapsLockOn = CapsLockOn;
+  UnikeyShiftPressed = shiftPressed;
+}
+
+//--------------------------------------------
+int UnikeySetOutputCharset(int charset)
+{
+    pShMem->charsetId = charset;
+    MyKbEngine.reset();
+    return 1;
+}
+
+//--------------------------------------------
+void UnikeySetOptions(UnikeyOptions *pOpt)
+{
+  pShMem->options.freeMarking = pOpt->freeMarking;
+  pShMem->options.modernStyle = pOpt->modernStyle;
+  pShMem->options.macroEnabled = pOpt->macroEnabled;
+  pShMem->options.useUnicodeClipboard = pOpt->useUnicodeClipboard;
+  pShMem->options.alwaysMacro = pOpt->alwaysMacro;
+  pShMem->options.spellCheckEnabled = pOpt->spellCheckEnabled;
+  pShMem->options.autoNonVnRestore = pOpt->autoNonVnRestore;
+}
+
+//--------------------------------------------
+void UnikeyGetOptions(UnikeyOptions *pOpt)
+{
+  *pOpt = pShMem->options;
+}
+
+//--------------------------------------------
+void CreateDefaultUnikeyOptions(UnikeyOptions *pOpt)
+{
+  pOpt->freeMarking = 1;
+  pOpt->modernStyle = 0;
+  pOpt->macroEnabled = 0;
+  pOpt->useUnicodeClipboard = 0;
+  pOpt->alwaysMacro = 0;
+  pOpt->spellCheckEnabled = 1;
+  pOpt->autoNonVnRestore = 0;
+}
+
+//--------------------------------------------
+void UnikeyCheckKbCase(int *pShiftPressed, int *pCapsLockOn)
+{
+  *pShiftPressed = UnikeyShiftPressed;
+  *pCapsLockOn = UnikeyCapsLockOn;
+}
+
+//--------------------------------------------
+void UnikeySetup()
+{
+    SetupUnikeyEngine();
+    pShMem = new UkSharedMem;
+    pShMem->input.init();
+    pShMem->macStore.init();
+    pShMem->vietKey = 1;
+    pShMem->usrKeyMapLoaded = 0;
+    MyKbEngine.setCtrlInfo(pShMem);
+    MyKbEngine.setCheckKbCaseFunc(&UnikeyCheckKbCase);
+    UnikeySetInputMethod(UkTelex);
+    UnikeySetOutputCharset(CONV_CHARSET_XUTF8);
+    pShMem->initialized = 1;
+    CreateDefaultUnikeyOptions(&pShMem->options);
+}
+
+//--------------------------------------------
+void UnikeyCleanup()
+{
+  delete pShMem;
+}
+
+//--------------------------------------------
+void UnikeyFilter(unsigned int ch)
+{
+  UnikeyBufChars = sizeof(UnikeyBuf);
+  MyKbEngine.process(ch, UnikeyBackspaces, UnikeyBuf, UnikeyBufChars, UnikeyOutput);
+}
+
+//--------------------------------------------
+void UnikeyPutChar(unsigned int ch)
+{
+  MyKbEngine.pass(ch);
+  UnikeyBufChars = 0;
+  UnikeyBackspaces = 0;
+}
+
+//--------------------------------------------
+void UnikeyResetBuf()
+{
+  MyKbEngine.reset();
+}
+
+//--------------------------------------------
+void UnikeySetSingleMode()
+{
+  MyKbEngine.setSingleMode();
+}
+
+//--------------------------------------------
+void UnikeyBackspacePress()
+{
+  UnikeyBufChars = sizeof(UnikeyBuf);
+  MyKbEngine.processBackspace(UnikeyBackspaces, UnikeyBuf, UnikeyBufChars, UnikeyOutput);
+  //  printf("Backspaces: %d\n",UnikeyBackspaces);
+}
+
+//--------------------------------------------
+int UnikeyLoadMacroTable(const char *fileName)
+{
+  return pShMem->macStore.loadFromFile(fileName);
+}
+
+//--------------------------------------------
+int UnikeyLoadUserKeyMap(const char *fileName)
+{
+  if (UkLoadKeyMap(fileName, pShMem->usrKeyMap)) {
+    //cout << "User key map loaded!\n"; //DEBUG
+    pShMem->usrKeyMapLoaded = 1;
+    return 1;
+  }
+  return 0;
+}
+
+//--------------------------------------------
+void UnikeyRestoreKeyStrokes()
+{
+    UnikeyBufChars = sizeof(UnikeyBuf);
+    MyKbEngine.restoreKeyStrokes(UnikeyBackspaces, UnikeyBuf, UnikeyBufChars, UnikeyOutput);
+}
+
+bool UnikeyAtWordBeginning()
+{
+    return MyKbEngine.atWordBeginning();
+}
+
+bool UnikeyLastWordIsNonVn()
+{
+    return MyKbEngine.lastWordIsNonVn();
+}
diff --git a/ukengine/unikey.h b/ukengine/unikey.h
new file mode 100644 (file)
index 0000000..ab683fc
--- /dev/null
@@ -0,0 +1,119 @@
+// -*- coding:unix; mode:c++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
+/*------------------------------------------------------------------------------
+UniKey - Open-source Vietnamese Keyboard
+Copyright (C) 2000-2005 Pham Kim Long
+Contact:
+  unikey@gmail.com
+  http://unikey.org
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+--------------------------------------------------------------------------------*/
+
+#ifndef __UNIKEY_H
+#define __UNIKEY_H
+
+#include "keycons.h"
+
+/*----------------------------------------------------
+Initialization steps:
+   1. UnikeySetup: This will initialized Unikey module,
+      with default options, input method = TELEX, output format = UTF-8
+   2. If you want a different settings:
+     + Call UnikeySetInputMethod to change input method
+     + Call UnikeySetOutputVIQR/UTF8 to chang output format
+     + Call UnikeySetOptions to change extra options
+
+Key event handling:
+
+- Call UnikeyFilter when a key event occurs, examine results in
+    + UnikeyBackspaces: number of backspaces that need to be sent
+    + UnikeyBufChars: number of chars in buffer that need to be sent
+    + UnikeyAnsiBuf: buffer containing output characters.
+    + UnikeyUniBuf: not used
+
+  You should also call UnikeySetCapsState() before calling UnikeyFilter.
+
+  To make this module portable across platforms, UnikeyFilter should not
+  be called on special keys: Enter, Tab, movement keys, delete, backspace...
+
+- Special events:
+    + Call UnikeyResetBuf to reset the engine's state in situations such as:
+      focus lost, movement keys: arrow keys, pgup, pgdown....
+    + If a backspace is received, call UnikeyBackspacePress,
+      then examine the result:
+      UnikeyBackspaces is the number of backspaces actually required to
+      remove one character.
+
+Clean up:
+- When the Engine is no longer needed, call UnikeyCleanup
+------------------------------------------------------*/
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+    extern unsigned char UnikeyBuf[];
+    extern int UnikeyBackspaces;
+    extern int UnikeyBufChars;
+    extern UkOutputType UnikeyOutput;
+
+  void UnikeySetup(); // always call this first
+  void UnikeyCleanup(); // call this when unloading unikey module
+  
+  // call this to reset Unikey's state when focus, context is changed or
+  // some control key is pressed
+  void UnikeyResetBuf(); 
+
+ // main handler, call every time a character input is received
+  void UnikeyFilter(unsigned int ch);
+  void UnikeyPutChar(unsigned int ch); // put new char without filtering
+
+  // call this before UnikeyFilter for correctly processing some TELEX shortcuts
+  void UnikeySetCapsState(int shiftPressed, int CapsLockOn);
+
+ // call this when backspace is pressed
+  void UnikeyBackspacePress();
+
+  // call this to restore to original key strokes
+  void UnikeyRestoreKeyStrokes();
+
+ //set extra options
+  void UnikeySetOptions(UnikeyOptions *pOpt); 
+  void CreateDefaultUnikeyOptions(UnikeyOptions *pOpt);
+
+  void UnikeyGetOptions(UnikeyOptions *pOpt);
+
+  // set input method
+  //   im: TELEX_INPUT, VNI_INPUT, VIQR_INPUT, VIQR_STAR_INPUT
+  void UnikeySetInputMethod(UkInputMethod im);
+  // set output format
+  //  void UnikeySetOutputVIQR();
+  // void UnikeySetOutputUTF8();
+  int UnikeySetOutputCharset(int charset);
+
+  int UnikeyLoadMacroTable(const char *fileName);
+  int UnikeyLoadUserKeyMap(const char *fileName);
+
+  //call this to enable typing vietnamese even in a non-vn sequence
+  //e.g: GD&DDT,QDDND...
+  //The engine will return to normal mode when a word-break occurs.
+  void UnikeySetSingleMode();
+
+  bool UnikeyAtWordBeginning();
+  bool UnikeyLastWordIsNonVn();
+#if defined(__cplusplus)
+}
+#endif
+
+#endif
diff --git a/ukengine/usrkeymap.cpp b/ukengine/usrkeymap.cpp
new file mode 100644 (file)
index 0000000..46a2fee
--- /dev/null
@@ -0,0 +1,267 @@
+// -*- mode:c++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
+/* Unikey Vietnamese Input Method
+ * Copyright (C) 2000-2005 Pham Kim Long
+ * Contact:
+ *   unikey@gmail.com
+ *   UniKey project: http://unikey.org
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <iostream>
+#include <string.h>
+#include <stdio.h>
+using namespace std;
+
+#include <ctype.h>
+#include "usrkeymap.h"
+
+
+int getLabelIndex(int action);
+void initKeyMap(int keyMap[256]);
+
+#define OPT_COMMENT_CHAR ';'
+
+struct UkEventLabelPair
+{
+    char label[32];
+    int ev;
+};
+
+UkEventLabelPair UkEvLabelList[] = {
+    {"Tone0", vneTone0},
+    {"Tone1", vneTone1},
+    {"Tone2", vneTone2},
+    {"Tone3", vneTone3},
+    {"Tone4", vneTone4},
+    {"Tone5", vneTone5},
+    {"Roof-All", vneRoofAll},
+    {"Roof-A", vneRoof_a},
+    {"Roof-E", vneRoof_e}, 
+    {"Roof-O", vneRoof_o},
+    {"Hook-Bowl", vneHookAll},
+    {"Hook-UO", vneHook_uo},
+    {"Hook-U", vneHook_u},
+    {"Hook-O", vneHook_o},
+    {"Bowl", vneBowl},
+    {"D-Mark", vneDd},
+    {"Telex-W", vne_telex_w},
+    {"Escape", vneEscChar},
+    {"DD", vneCount + vnl_DD},
+    {"dd", vneCount + vnl_dd},
+    {"A^", vneCount + vnl_Ar},
+    {"a^", vneCount + vnl_ar},
+    {"A(", vneCount + vnl_Ab},
+    {"a(", vneCount + vnl_ab},
+    {"E^", vneCount + vnl_Er},
+    {"e^", vneCount + vnl_er},
+    {"O^", vneCount + vnl_Or},
+    {"o^", vneCount + vnl_or},
+    {"O+", vneCount + vnl_Oh},
+    {"o+", vneCount + vnl_oh},
+    {"U+", vneCount + vnl_Uh},
+    {"u+", vneCount + vnl_uh}
+};
+
+const int UkEvLabelCount = sizeof(UkEvLabelList)/sizeof(UkEventLabelPair);
+
+//--------------------------------------------------
+static int parseNameValue(char *line, char **name, char **value)
+{
+    char *p, *mark;
+    char ch;
+
+    if (line == 0)
+        return 0;
+
+    // get rid of comment
+    p = strchr(line, OPT_COMMENT_CHAR);
+    if (p)
+        *p = 0;
+
+    //get option name
+    for (p=line; *p == ' '; p++);
+    if (*p == 0)
+        return 0;
+
+    *name = p;
+    mark = p; //mark the last non-space character
+    p++;
+    while ((ch=*p) != '=' && ch!=0) {
+        if (ch != ' ')
+            mark = p;
+        p++;
+    }
+
+    if (ch == 0)
+        return 0;
+    *(mark+1) = 0; //terminate name with a null character
+
+    //get option value
+    p++;
+    while (*p == ' ') p++;
+    if (*p == 0)
+        return 0;
+
+    *value = p;
+    mark = p;
+    while (*p) { //strip trailing spaces
+        if (*p != ' ')
+            mark = p;
+        p++;
+    }
+    *++mark = 0;
+    return 1;
+}
+
+//-----------------------------------------------------
+DllExport int UkLoadKeyMap(const char *fileName, int keyMap[256])
+{
+    int i, mapCount;
+    UkKeyMapPair orderMap[256];
+    if (!UkLoadKeyOrderMap(fileName, orderMap, &mapCount))
+        return 0;
+
+    initKeyMap(keyMap);
+    for (i=0; i < mapCount; i++) {
+        keyMap[orderMap[i].key] = orderMap[i].action;
+        if (orderMap[i].action < vneCount) {
+            keyMap[tolower(orderMap[i].key)] = orderMap[i].action;
+        }
+    }
+    return 1;
+}
+
+//------------------------------------------------------------------
+DllExport int UkLoadKeyOrderMap(const char *fileName, UkKeyMapPair *pMap, int *pMapCount)
+{
+    FILE *f;
+    char *buf;
+    char *name, *value;
+    size_t len;
+    int i, bufSize, lineCount;
+    unsigned char c;
+    int mapCount;
+    int keyMap[256];
+
+    f = fopen(fileName, "r");
+    if (f == 0) {
+        cerr << "Failed to open file: " << fileName << endl;
+        return 0;
+    }
+
+    initKeyMap(keyMap);
+    bufSize = 256;
+    buf = new char[bufSize];
+
+    lineCount = 0;
+    mapCount = 0;
+    while (!feof(f)) {
+        if (fgets((char *)buf, bufSize, f) == 0)
+            break;
+        lineCount++;
+        len = strlen(buf);
+        if (len == 0)
+            break;
+
+        if (buf[len-1] == '\n')
+            buf[len-1] = 0;
+        if (parseNameValue(buf, (char **)&name, (char **)&value)) {
+            if (strlen(name) == 1) {
+                for (i=0; i < UkEvLabelCount; i++) {
+                    if (strcmp(UkEvLabelList[i].label, value) == 0) {
+                        c = (unsigned char)name[0];
+                        if (keyMap[c] != vneNormal) {
+                            //already assigned, don't accept this map
+                            break;
+                        }
+                        //cout << "key: " << c << " value: " << UkEvLabelList[i].ev << endl; //DEBUG
+                        keyMap[c] = UkEvLabelList[i].ev;
+                        pMap[mapCount].action = UkEvLabelList[i].ev;
+                        if (keyMap[c] < vneCount) {
+                            pMap[mapCount].key = toupper(c);
+                            keyMap[toupper(c)] = UkEvLabelList[i].ev;
+                        }
+                        else {
+                            pMap[mapCount].key = c;
+                        }
+                        mapCount++;
+                        break;
+                    }
+                }
+                if (i == UkEvLabelCount) {
+                    cerr << "Error in user key layout, line " << lineCount << ": command not found" << endl;
+                }
+            }
+            else {
+                cerr << "Error in user key layout, line " << lineCount 
+                     << ": key name is not a single character" << endl;        
+            }
+        }
+    }
+    delete [] buf;
+    fclose(f);
+
+    *pMapCount = mapCount;
+
+    return 1;
+}
+
+//-------------------------------------------
+void initKeyMap(int keyMap[256])
+{
+    unsigned int c;
+    for (c=0; c<256; c++)
+        keyMap[c] = vneNormal;
+}
+
+const char *UkKeyMapHeader = 
+    "; This is UniKey user-defined key mapping file, generated from UniKey (Windows)\n\n";
+
+DllExport int UkStoreKeyOrderMap(const char *fileName, UkKeyMapPair *pMap, int mapCount)
+{
+    FILE *f;
+    int i;
+    int labelIndex;
+    char line[128];
+
+    f = fopen(fileName, "wt");
+    if (f == 0) {
+        cerr << "Failed to open file: " << fileName << endl;
+        return 0;
+    }
+
+    fputs(UkKeyMapHeader, f);
+    for (i=0; i < mapCount; i++) {
+        labelIndex = getLabelIndex(pMap[i].action);
+        if (labelIndex != -1) {
+            sprintf(line, "%c = %s\n", pMap[i].key, UkEvLabelList[labelIndex].label);
+            fputs(line, f);
+        }
+    }
+    fclose(f);
+    return 1;
+}
+
+int getLabelIndex(int event)
+{
+    int i;
+    for (i = 0; i < UkEvLabelCount; i++) {
+        if (UkEvLabelList[i].ev == event)
+            return i;
+    }
+    return -1;
+}
diff --git a/ukengine/usrkeymap.h b/ukengine/usrkeymap.h
new file mode 100644 (file)
index 0000000..4dc8ec6
--- /dev/null
@@ -0,0 +1,37 @@
+// -*- coding:unix; mode:c++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
+/* Unikey Vietnamese Input Method
+ * Copyright (C) 2000-2005 Pham Kim Long
+ * Contact:
+ *   unikey@gmail.com
+ *   UniKey project: http://unikey.org
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __UNIKEY_USER_KEY_MAP_H
+#define __UNIKEY_USER_KEY_MAP_H
+
+#include "inputproc.h"
+struct UkKeyMapPair {
+    unsigned char   key;
+    int             action;
+};
+
+DllInterface int UkLoadKeyMap(const char *fileName, int keyMap[256]);
+DllInterface int UkLoadKeyOrderMap(const char *fileName, UkKeyMapPair *pMap, int *pMapCount);
+DllInterface int UkStoreKeyOrderMap(const char *fileName, UkKeyMapPair *pMap, int mapCount);
+
+#endif
diff --git a/ukengine/vnconv.h b/ukengine/vnconv.h
new file mode 100644 (file)
index 0000000..c94a72f
--- /dev/null
@@ -0,0 +1,122 @@
+// -*- coding:unix; mode:c++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
+/*------------------------------------------------------------------------------
+VnConv: Vietnamese Encoding Converter Library
+UniKey Project: http://unikey.sourceforge.net
+Copyleft (C) 1998-2002 Pham Kim Long
+Contact: longp@cslab.felk.cvut.cz
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+--------------------------------------------------------------------------------*/
+
+//
+#ifndef __VN_CONVERT_H
+#define __VN_CONVERT_H
+
+#if defined(_WIN32)
+    #if defined(UNIKEYHOOK)
+        #define DllInterface   __declspec( dllexport )
+    #else
+        #define DllInterface   __declspec( dllimport )
+    #endif
+    #define DllExport   __declspec( dllexport )
+    #define DllImport   __declspec( dllimport )
+#else
+    #define DllInterface //not used
+    #define DllExport
+    #define DllImport
+#endif
+
+#define CONV_CHARSET_UNICODE   0
+#define CONV_CHARSET_UNIUTF8    1
+#define CONV_CHARSET_UNIREF     2  //&#D;
+#define CONV_CHARSET_UNIREF_HEX 3
+#define CONV_CHARSET_UNIDECOMPOSED 4
+#define CONV_CHARSET_WINCP1258 5
+#define CONV_CHARSET_UNI_CSTRING 6
+#define CONV_CHARSET_VNSTANDARD 7
+
+#define CONV_CHARSET_VIQR              10
+#define CONV_CHARSET_UTF8VIQR 11
+#define CONV_CHARSET_XUTF8  12
+
+#define CONV_CHARSET_TCVN3             20
+#define CONV_CHARSET_VPS               21
+#define CONV_CHARSET_VISCII            22
+#define CONV_CHARSET_BKHCM1            23
+#define CONV_CHARSET_VIETWAREF 24
+#define CONV_CHARSET_ISC        25
+
+#define CONV_CHARSET_VNIWIN            40
+#define CONV_CHARSET_BKHCM2            41
+#define CONV_CHARSET_VIETWAREX 42
+#define CONV_CHARSET_VNIMAC            43
+
+#define CONV_TOTAL_SINGLE_CHARSETS 6
+#define CONV_TOTAL_DOUBLE_CHARSETS 4
+
+
+#define IS_SINGLE_BYTE_CHARSET(x) (x >= CONV_CHARSET_TCVN3 && x < CONV_CHARSET_TCVN3+CONV_TOTAL_SINGLE_CHARSETS)
+#define IS_DOUBLE_BYTE_CHARSET(x) (x >= CONV_CHARSET_VNIWIN && x < CONV_CHARSET_VNIWIN+CONV_TOTAL_DOUBLE_CHARSETS)
+
+typedef unsigned char UKBYTE;
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+DllInterface  int VnConvert(int inCharset, int outCharset, UKBYTE *input, UKBYTE *output, 
+               int * pInLen, int * pMaxOutLen);
+
+DllInterface  int VnFileConvert(int inCharset, int outCharset, const char *inFile, const char *outFile);
+
+#if defined(__cplusplus)
+}
+#endif
+
+DllInterface const char * VnConvErrMsg(int errCode);
+
+enum VnConvError {
+       VNCONV_NO_ERROR,
+       VNCONV_UNKNOWN_ERROR,
+       VNCONV_INVALID_CHARSET,
+       VNCONV_ERR_INPUT_FILE,
+       VNCONV_ERR_OUTPUT_FILE,
+       VNCONV_OUT_OF_MEMORY,
+       VNCONV_ERR_WRITING,
+       VNCONV_LAST_ERROR
+};
+
+typedef struct _CharsetNameId CharsetNameId;
+
+struct _CharsetNameId {
+       const char *name;
+       int id;
+};
+
+typedef struct _VnConvOptions VnConvOptions;
+
+struct _VnConvOptions {
+       int viqrMixed;
+       int viqrEsc;
+       int toUpper;
+       int toLower;
+       int removeTone;
+    int smartViqr;
+};
+
+DllInterface void VnConvSetOptions(VnConvOptions *pOptions);
+DllInterface void VnConvGetOptions(VnConvOptions *pOptions);
+DllInterface void VnConvResetOptions(VnConvOptions *pOptions);
+
+#endif
diff --git a/ukengine/vnlexi.h b/ukengine/vnlexi.h
new file mode 100644 (file)
index 0000000..8724013
--- /dev/null
@@ -0,0 +1,162 @@
+// -*- coding:unix; mode:c++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
+/* Unikey Vietnamese Input Method
+ * Copyright (C) 2000-2005 Pham Kim Long
+ * Contact:
+ *   unikey@gmail.com
+ *   UniKey project: http://unikey.org
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __VN_LEXI_H
+#define __VN_LEXI_H
+
+enum VnLexiName {
+  vnl_nonVnChar = -1,
+  vnl_A, vnl_a, vnl_A1, vnl_a1, vnl_A2, vnl_a2, vnl_A3, vnl_a3, vnl_A4, vnl_a4, vnl_A5, vnl_a5,
+  vnl_Ar, vnl_ar, vnl_Ar1, vnl_ar1, vnl_Ar2, vnl_ar2, vnl_Ar3, vnl_ar3, vnl_Ar4, vnl_ar4, vnl_Ar5, vnl_ar5,
+  vnl_Ab, vnl_ab, vnl_Ab1, vnl_ab1, vnl_Ab2, vnl_ab2, vnl_Ab3, vnl_ab3, vnl_Ab4, vnl_ab4, vnl_Ab5, vnl_ab5,
+  vnl_B, vnl_b, vnl_C, vnl_c, 
+  vnl_D, vnl_d, vnl_DD, vnl_dd,
+  vnl_E, vnl_e, vnl_E1, vnl_e1, vnl_E2, vnl_e2, vnl_E3, vnl_e3, vnl_E4, vnl_e4, vnl_E5, vnl_e5,
+  vnl_Er, vnl_er, vnl_Er1, vnl_er1, vnl_Er2, vnl_er2, vnl_Er3, vnl_er3, vnl_Er4, vnl_er4, vnl_Er5, vnl_er5,
+  vnl_F, vnl_f, vnl_G, vnl_g, vnl_H, vnl_h,
+  vnl_I, vnl_i, vnl_I1, vnl_i1, vnl_I2, vnl_i2, vnl_I3, vnl_i3, vnl_I4, vnl_i4, vnl_I5, vnl_i5,
+  vnl_J, vnl_j, vnl_K, vnl_k, vnl_L, vnl_l, vnl_M, vnl_m, vnl_N, vnl_n,
+  vnl_O, vnl_o, vnl_O1, vnl_o1, vnl_O2, vnl_o2, vnl_O3, vnl_o3, vnl_O4, vnl_o4, vnl_O5, vnl_o5,
+  vnl_Or, vnl_or, vnl_Or1, vnl_or1, vnl_Or2, vnl_or2, vnl_Or3, vnl_or3, vnl_Or4, vnl_or4, vnl_Or5, vnl_or5,
+  vnl_Oh, vnl_oh, vnl_Oh1, vnl_oh1, vnl_Oh2, vnl_oh2, vnl_Oh3, vnl_oh3, vnl_Oh4, vnl_oh4, vnl_Oh5, vnl_oh5,
+  vnl_P, vnl_p, vnl_Q, vnl_q, vnl_R, vnl_r, vnl_S, vnl_s, vnl_T, vnl_t,
+  vnl_U, vnl_u, vnl_U1, vnl_u1, vnl_U2, vnl_u2, vnl_U3, vnl_u3, vnl_U4, vnl_u4, vnl_U5, vnl_u5,
+  vnl_Uh, vnl_uh, vnl_Uh1, vnl_uh1, vnl_Uh2, vnl_uh2, vnl_Uh3, vnl_uh3, vnl_Uh4, vnl_uh4, vnl_Uh5, vnl_uh5,
+  vnl_V, vnl_v, vnl_W, vnl_w, vnl_X, vnl_x,
+  vnl_Y, vnl_y, vnl_Y1, vnl_y1, vnl_Y2, vnl_y2, vnl_Y3, vnl_y3, vnl_Y4, vnl_y4, vnl_Y5, vnl_y5,
+  vnl_Z, vnl_z,
+
+  vnl_lastChar,
+};
+
+enum VowelSeq {
+  vs_nil = -1,
+  vs_a,
+  vs_ar,
+  vs_ab,
+  vs_e,
+  vs_er,
+  vs_i,
+  vs_o,
+  vs_or,
+  vs_oh,
+  vs_u,
+  vs_uh,
+  vs_y,
+  vs_ai,
+  vs_ao,
+  vs_au,
+  vs_ay,
+  vs_aru,
+  vs_ary,
+  vs_eo,
+  vs_eu,
+  vs_eru,
+  vs_ia,
+  vs_ie,
+  vs_ier,
+  vs_iu,
+  vs_oa,
+  vs_oab,
+  vs_oe,
+  vs_oi,
+  vs_ori,
+  vs_ohi,
+  vs_ua,
+  vs_uar,
+  vs_ue,
+  vs_uer,
+  vs_ui,
+  vs_uo,
+  vs_uor,
+  vs_uoh,
+  vs_uu,
+  vs_uy,
+  vs_uha,
+  vs_uhi,
+  vs_uho,
+  vs_uhoh,
+  vs_uhu,
+  vs_ye,
+  vs_yer,
+  vs_ieu,
+  vs_ieru,
+  vs_oai,
+  vs_oay,
+  vs_oeo,
+  vs_uay,
+  vs_uary,
+  vs_uoi,
+  vs_uou,
+  vs_uori,
+  vs_uohi,
+  vs_uohu,
+  vs_uya,
+  vs_uye,
+  vs_uyer,
+  vs_uyu,
+  vs_uhoi,
+  vs_uhou,
+  vs_uhohi,
+  vs_uhohu,
+  vs_yeu,
+  vs_yeru
+};
+
+enum ConSeq {
+  cs_nil = -1,
+  cs_b,
+  cs_c,
+  cs_ch,
+  cs_d,
+  cs_dd,
+  cs_dz,
+  cs_g,
+  cs_gh,
+  cs_gi,
+  cs_gin,
+  cs_h,
+  cs_k,
+  cs_kh,
+  cs_l,
+  cs_m,
+  cs_n,
+  cs_ng,
+  cs_ngh,
+  cs_nh,
+  cs_p,
+  cs_ph,
+  cs_q,
+  cs_qu,
+  cs_r,
+  cs_s,
+  cs_t,
+  cs_th,
+  cs_tr,
+  cs_v,
+  cs_x
+};
+
+
+
+#endif