pax_global_header00006660000000000000000000000064130057676350014526gustar00rootroot0000000000000052 comment=fee6ca6d15f5c2477c546579ec3dd9dc5a7a1b49 fcitx-punc-ng-0.1.1~git20161101/000077500000000000000000000000001300576763500157255ustar00rootroot00000000000000fcitx-punc-ng-0.1.1~git20161101/CMakeLists.txt000066400000000000000000000040171300576763500204670ustar00rootroot00000000000000project(fcitx-punc-ng) cmake_minimum_required(VERSION 2.6) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) find_package(Fcitx 4.2.8 REQUIRED) _fcitx_add_uninstall_target() set(CMAKE_C_FLAGS "-g -O0 -Wall -Wextra -Wno-sign-compare -Wno-unused-parameter -fvisibility=hidden ${CMAKE_C_FLAGS}") set(CMAKE_CXX_FLAGS "-g -O0 -Wall -Wextra -Wno-sign-compare -Wno-unused-parameter -fvisibility=hidden ${CMAKE_CXX_FLAGS}") set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--as-needed ${CMAKE_SHARED_LINKER_FLAGS}") set(CMAKE_MODULE_LINKER_FLAGS "-Wl,--as-needed ${CMAKE_MODULE_LINKER_FLAGS}") add_definitions("-D_GNU_SOURCE -DFCITX_HAVE_CONFIG_H") set(package fcitx) set(prefix ${CMAKE_INSTALL_PREFIX}) set(exec_prefix ${CMAKE_INSTALL_PREFIX}) set(bindir ${exec_prefix}/bin) if(NOT DEFINED LIB_INSTALL_DIR) set(LIB_INSTALL_DIR "${exec_prefix}/lib" CACHE PATH "Library install directory [default=PREFIX/lib/]") endif() if(NOT DEFINED LIBDATA_INSTALL_DIR) set(LIBDATA_INSTALL_DIR "${LIB_INSTALL_DIR}" CACHE PATH "Lib data install directory [default=LIB_INSTALL_DIR]") endif() if(NOT DEFINED MAN_INSTALL_DIR) set(MAN_INSTALL_DIR "${prefix}/share/man" CACHE PATH "man install directory [default=PREFIX/share/man]") endif() if (NOT DEFINED DBUS_SERVICE_DIR) set(DBUS_SERVICE_DIR "${CMAKE_INSTALL_PREFIX}/share/dbus-1/services" CACHE PATH "dbus session service directory [default=PREFIX/share/dbus-1/services]") endif() if (NOT DEFINED SYSCONFDIR) set(SYSCONFDIR "${CMAKE_INSTALL_PREFIX}/etc" CACHE PATH "sys config directory [default=PREFIX/etc/]") endif() set(includedir "${CMAKE_INSTALL_PREFIX}/include") set(libdir ${LIB_INSTALL_DIR}) set(pkgconfdir ${LIBDATA_INSTALL_DIR}/pkgconfig) set(mandir ${MAN_INSTALL_DIR}) set(addondir ${libdir}/${package} ) set(pkgdatadir ${prefix}/share/${package}) set(configdescdir ${pkgdatadir}/configdesc) set(addonconfigdir ${pkgdatadir}/addon) set(imconfigdir ${pkgdatadir}/inputmethod) set(localedir ${CMAKE_INSTALL_PREFIX}/share/locale) add_subdirectory(src) add_subdirectory(data) fcitx-punc-ng-0.1.1~git20161101/COPYING000066400000000000000000000431051300576763500167630ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, 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 software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's 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 give any other recipients of the Program a copy of this License along with the Program. 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. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, 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) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, 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 Program, 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 Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) 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; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, 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 executable. 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. If distribution of executable or 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 counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program 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. 5. 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 Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program 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. 7. 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 Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program 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 Program. 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. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program 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. 9. The Free Software Foundation may publish revised and/or new versions of the 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 Program 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 Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, 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 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "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 PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. 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 PROGRAM 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 PROGRAM (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 PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. 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. Copyright (C) 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. fcitx-punc-ng-0.1.1~git20161101/COPYING.LIBS000066400000000000000000000007221300576763500175110ustar00rootroot00000000000000== License exception for plugins == All source code in Fcitx is released under GNU General Public License version 2 or higher, but for run-time loadable add-ons that run within Fcitx's plugin framework (which means the add-on is directly loaded by libfcitx), Fcitx's copyright holders grant you additional permission to use the header of libfcitx, libfcitx-config, libfcitx-utils, and access to the data structure of libfcitx, libfcitx-config, and libfcitx-utils. fcitx-punc-ng-0.1.1~git20161101/data/000077500000000000000000000000001300576763500166365ustar00rootroot00000000000000fcitx-punc-ng-0.1.1~git20161101/data/CMakeLists.txt000066400000000000000000000002371300576763500214000ustar00rootroot00000000000000 set(FCITX_DATA_FILES punc-ng.mb.zh_CN punc-ng.mb.zh_HK punc-ng.mb.zh_TW ) install(FILES ${FCITX_DATA_FILES} DESTINATION "/usr/share/fcitx/data") fcitx-punc-ng-0.1.1~git20161101/data/punc-ng.mb.zh_CN000066400000000000000000000002051300576763500215220ustar00rootroot00000000000000. 。 , , ? ? " “ ” : : ; ; ' ‘ ’ < 《 > 》 \ 、 ! ! $ ¥ ^ …… * × _ —— ( ( ) ) [ 【 ] 】 ~ ~ fcitx-punc-ng-0.1.1~git20161101/data/punc-ng.mb.zh_HK000066400000000000000000000002051300576763500215240ustar00rootroot00000000000000. 。 , , ? ? " “ ” : : ; ; ' ‘ ’ < 《 > 》 \ 、 ! ! $ $ ^ …… * × _ —— ( ( ) ) [ 【 ] 】 ~ ~ fcitx-punc-ng-0.1.1~git20161101/data/punc-ng.mb.zh_TW000066400000000000000000000002311300576763500215530ustar00rootroot00000000000000. 。 , , ? ? " “ ” : : ; ; ' ‘ ’ < 《 》 > 〈 〉 \ 、 ! ! $ $ ^ …… * × _ —— ( ( ) ) [ 「 ] 」 { 『 } 』 ~ ~ fcitx-punc-ng-0.1.1~git20161101/debian/000077500000000000000000000000001300576763500171475ustar00rootroot00000000000000fcitx-punc-ng-0.1.1~git20161101/debian/changelog000066400000000000000000000001771300576763500210260ustar00rootroot00000000000000fcitx-punc-ng (0.1.2) stable; urgency=low * Test build -- Aron Xu Mon, 30 Jun 2014 00:23:44 +0800 fcitx-punc-ng-0.1.1~git20161101/debian/compat000066400000000000000000000000021300576763500203450ustar00rootroot000000000000009 fcitx-punc-ng-0.1.1~git20161101/debian/control000066400000000000000000000015731300576763500205600ustar00rootroot00000000000000Source: fcitx-punc-ng Section: utils Priority: optional Maintainer: Aron Xu Build-Depends: debhelper (>= 9), cmake, intltool, pkg-config, fcitx-libs-dev (>= 1:4.2.8), fcitx-bin Standards-Version: 3.9.5 Homepage: http://code.google.com/p/fcitx Package: fcitx-module-punc-ng Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends}, fcitx-bin, fcitx-data (>= 1:4.2.8), fcitx-modules Recommends: fcitx (>= 1:4.2.8) Breaks: fcitx (<< 1:4.2.8) Description: Fcitx punc module for Sogou pinyin fcitx-googlepinyin is a module for Sogou pinyin Package: fcitx-punc-ng-dbg Architecture: any Section: debug Priority: extra Depends: fcitx-module-punc-ng (= ${binary:Version}), ${misc:Depends} Recommends: fcitx (>= 1:4.2.8) Breaks: fcitx (<< 1:4.2.8) Description: Fcitx punc module for Sogou pinyin - debugging symbols fcitx-googlepinyin is a module for Sogou pinyin fcitx-punc-ng-0.1.1~git20161101/debian/copyright000066400000000000000000000017551300576763500211120ustar00rootroot00000000000000Format: http://dep.debian.net/deps/dep5/ Upstream-Name: fcitx-punc-ng Copyright: 2014, Gao Qunkai License: GPL-3+ 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 3 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. . On Debian systems, the full text of GPL-3 could be found at `/usr/share/common-licenses/GPL-3'. Files: debian/* Copyright: 2010, Aron Xu License: GPL-3+ fcitx-punc-ng-0.1.1~git20161101/debian/fcitx-module-punc-ng.install000066400000000000000000000000361300576763500245030ustar00rootroot00000000000000usr/share usr/lib usr/include fcitx-punc-ng-0.1.1~git20161101/debian/rules000077500000000000000000000005701300576763500202310ustar00rootroot00000000000000#!/usr/bin/make -f DPKG_EXPORT_BUILDFLAGS = 1 -include /usr/share/dpkg/default.mk CFLAGS += $(CPPFLAGS) CXXFLAGS += $(CPPFLAGS) %: dh $@ override_dh_makeshlibs: override_dh_auto_configure: dh_auto_configure -- \ -DLIB_INSTALL_DIR=/usr/lib/$(DEB_HOST_MULTIARCH) override_dh_strip: dh_strip --dbg-package=fcitx-punc-ng-dbg override_dh_builddeb: dh_builddeb -- -Zxz fcitx-punc-ng-0.1.1~git20161101/debian/source/000077500000000000000000000000001300576763500204475ustar00rootroot00000000000000fcitx-punc-ng-0.1.1~git20161101/debian/source/format000066400000000000000000000000151300576763500216560ustar00rootroot000000000000003.0 (native) fcitx-punc-ng-0.1.1~git20161101/src/000077500000000000000000000000001300576763500165145ustar00rootroot00000000000000fcitx-punc-ng-0.1.1~git20161101/src/CMakeLists.txt000066400000000000000000000003001300576763500212450ustar00rootroot00000000000000set(FCITX_PUNC_SOURCES iniparser/dictionary.c iniparser/iniparser.c cfgrw.c punc-ng.c) fcitx_add_addon_full(punc-ng SCAN SCAN_PRIV SOURCES ${FCITX_PUNC_SOURCES} HEADERS punc-ng.h) fcitx-punc-ng-0.1.1~git20161101/src/cfgrw.c000066400000000000000000000022321300576763500177670ustar00rootroot00000000000000 #include #include #include "cfgrw.h" #include "iniparser/iniparser.h" static char *getCfgFilePath(const char *fileName) { #define BUFF_SIZE (256) static char usrPath[BUFF_SIZE] = {0}; char *homePath = getenv("HOME"); snprintf(usrPath, BUFF_SIZE, "%s/.config/SogouPY/%s", homePath, fileName); return usrPath; } char *getCfgValueString(const char *fileName, const char *fieldName, char *defaultvalue) { char *s; dictionary *ini; #define VALUE_SIZE (128) static char val[VALUE_SIZE] = {0}; if ((ini = iniparser_load(getCfgFilePath(fileName))) == NULL) return defaultvalue; if ((s = iniparser_getstring(ini, fieldName, defaultvalue)) == NULL) { iniparser_freedict(ini); return defaultvalue; } strcpy(val, s); iniparser_freedict(ini); return val; } int getCfgValueBool(const char *fileName, const char *fieldName, int defaultvalue) { int val; dictionary *ini; if ((ini = iniparser_load(getCfgFilePath(fileName))) == NULL) return defaultvalue; val = iniparser_getboolean(ini, fieldName, defaultvalue); iniparser_freedict(ini); return val; } fcitx-punc-ng-0.1.1~git20161101/src/cfgrw.h000066400000000000000000000003371300576763500200000ustar00rootroot00000000000000 #ifndef _CFG_RW_H_ #define _CFG_RW_H_ char *getCfgValueString(const char *fileName, const char *fieldName, char *defaultvalue); int getCfgValueBool(const char *fileName, const char *fieldName, int defaultvalue); #endif fcitx-punc-ng-0.1.1~git20161101/src/fcitx-punc-ng.conf.in000066400000000000000000000010361300576763500224520ustar00rootroot00000000000000[Addon] Name=fcitx-punc-ng GeneralName=Punctuation Support GeneralName[de]=Unterstützung Interpunktion GeneralName[ja]=句読点サポート GeneralName[zh_CN]=标点支持 GeneralName[zh_TW]=標點支援 GeneralName[ko]=Punctuation 지원 Comment=Punctuation Conversion Support Comment[de]=Unterstützung der Umwandlung der Interpunktion Comment[ja]=句読点変換のサポート Comment[zh_CN]=标点转换支持 Comment[zh_TW]=標點符號轉換支援 Category=Module Enabled=True Library=fcitx-punc-ng.so Type=SharedLibrary Priority=59 fcitx-punc-ng-0.1.1~git20161101/src/fcitx-punc-ng.fxaddon000066400000000000000000000006501300576763500225440ustar00rootroot00000000000000[FcitxAddon] Name=fcitx-punc-ng Prefix=PuncNg Include0="punc.h" Function0=GetPunc Function1=GetPunc2 Function2= Function3= Function4= Function5= Function6= Function7= Function8= Self.Type=FcitxPuncState* [GetPunc] Name=get-punc Return=char* Arg0=int* Arg0.Deref=1 Arg0.DerefType=int Res.WrapFunc=GetPunc [GetPunc2] Name=get-punc2 Arg0=int* Arg0.Deref=1 Arg0.DerefType=int Arg1=char** Arg2=char** Res.WrapFunc=PuncGetPunc2 fcitx-punc-ng-0.1.1~git20161101/src/iniparser/000077500000000000000000000000001300576763500205105ustar00rootroot00000000000000fcitx-punc-ng-0.1.1~git20161101/src/iniparser/AUTHORS000066400000000000000000000003661300576763500215650ustar00rootroot00000000000000Author: Nicolas Devillard This tiny library has received countless contributions and I have not kept track of all the people who contributed. Let them be thanked for their ideas, code, suggestions, corrections, enhancements! fcitx-punc-ng-0.1.1~git20161101/src/iniparser/LICENSE000066400000000000000000000020731300576763500215170ustar00rootroot00000000000000Copyright (c) 2000-2011 by Nicolas Devillard. MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. fcitx-punc-ng-0.1.1~git20161101/src/iniparser/Makefile000066400000000000000000000006241300576763500221520ustar00rootroot00000000000000# # iniparser tests Makefile # CC = gcc CFLAGS = -g -I../src LFLAGS = -L.. -liniparser AR = ar ARFLAGS = rcv RM = rm -f default: all all: iniexample parse iniexample: iniexample.c $(CC) $(CFLAGS) -o iniexample iniexample.c -I../src -L.. -liniparser parse: parse.c $(CC) $(CFLAGS) -o parse parse.c -I../src -L.. -liniparser clean veryclean: $(RM) iniexample example.ini parse fcitx-punc-ng-0.1.1~git20161101/src/iniparser/README000066400000000000000000000004471300576763500213750ustar00rootroot00000000000000 Welcome to iniParser -- version 3.1 released 08 Apr 2012 This modules offers parsing of ini files from the C level. See a complete documentation in HTML format, from this directory open the file html/index.html with any HTML-capable browser. Enjoy! N.Devillard Sun Apr 8 16:38:09 CEST 2012 fcitx-punc-ng-0.1.1~git20161101/src/iniparser/dictionary.c000066400000000000000000000277001300576763500230270ustar00rootroot00000000000000/*-------------------------------------------------------------------------*/ /** @file dictionary.c @author N. Devillard @brief Implements a dictionary for string variables. This module implements a simple dictionary object, i.e. a list of string/string associations. This object is useful to store e.g. informations retrieved from a configuration file (ini files). */ /*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------- Includes ---------------------------------------------------------------------------*/ #include "dictionary.h" #include #include #include #include /** Maximum value size for integers and doubles. */ #define MAXVALSZ 1024 /** Minimal allocated number of entries in a dictionary */ #define DICTMINSZ 128 /** Invalid key token */ #define DICT_INVALID_KEY ((char*)-1) /*--------------------------------------------------------------------------- Private functions ---------------------------------------------------------------------------*/ /* Doubles the allocated size associated to a pointer */ /* 'size' is the current allocated size. */ static void * mem_double(void * ptr, int size) { void * newptr ; newptr = calloc(2*size, 1); if (newptr==NULL) { return NULL ; } memcpy(newptr, ptr, size); free(ptr); return newptr ; } /*-------------------------------------------------------------------------*/ /** @brief Duplicate a string @param s String to duplicate @return Pointer to a newly allocated string, to be freed with free() This is a replacement for strdup(). This implementation is provided for systems that do not have it. */ /*--------------------------------------------------------------------------*/ static char * xstrdup(const char * s) { char * t ; if (!s) return NULL ; t = (char*)malloc(strlen(s)+1) ; if (t) { strcpy(t,s); } return t ; } /*--------------------------------------------------------------------------- Function codes ---------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/ /** @brief Compute the hash key for a string. @param key Character string to use for key. @return 1 unsigned int on at least 32 bits. This hash function has been taken from an Article in Dr Dobbs Journal. This is normally a collision-free function, distributing keys evenly. The key is stored anyway in the struct so that collision can be avoided by comparing the key itself in last resort. */ /*--------------------------------------------------------------------------*/ unsigned dictionary_hash(const char * key) { int len ; unsigned hash ; int i ; len = strlen(key); for (hash=0, i=0 ; i>6) ; } hash += (hash <<3); hash ^= (hash >>11); hash += (hash <<15); return hash ; } /*-------------------------------------------------------------------------*/ /** @brief Create a new dictionary object. @param size Optional initial size of the dictionary. @return 1 newly allocated dictionary objet. This function allocates a new dictionary object of given size and returns it. If you do not know in advance (roughly) the number of entries in the dictionary, give size=0. */ /*--------------------------------------------------------------------------*/ dictionary * dictionary_new(int size) { dictionary * d ; /* If no size was specified, allocate space for DICTMINSZ */ if (sizesize = size ; d->val = (char **)calloc(size, sizeof(char*)); d->key = (char **)calloc(size, sizeof(char*)); d->hash = (unsigned int *)calloc(size, sizeof(unsigned)); return d ; } /*-------------------------------------------------------------------------*/ /** @brief Delete a dictionary object @param d dictionary object to deallocate. @return void Deallocate a dictionary object and all memory associated to it. */ /*--------------------------------------------------------------------------*/ void dictionary_del(dictionary * d) { int i ; if (d==NULL) return ; for (i=0 ; isize ; i++) { if (d->key[i]!=NULL) free(d->key[i]); if (d->val[i]!=NULL) free(d->val[i]); } free(d->val); free(d->key); free(d->hash); free(d); return ; } /*-------------------------------------------------------------------------*/ /** @brief Get a value from a dictionary. @param d dictionary object to search. @param key Key to look for in the dictionary. @param def Default value to return if key not found. @return 1 pointer to internally allocated character string. This function locates a key in a dictionary and returns a pointer to its value, or the passed 'def' pointer if no such key can be found in dictionary. The returned character pointer points to data internal to the dictionary object, you should not try to free it or modify it. */ /*--------------------------------------------------------------------------*/ char * dictionary_get(dictionary * d, const char * key, char * def) { unsigned hash ; int i ; hash = dictionary_hash(key); for (i=0 ; isize ; i++) { if (d->key[i]==NULL) continue ; /* Compare hash */ if (hash==d->hash[i]) { /* Compare string, to avoid hash collisions */ if (!strcmp(key, d->key[i])) { return d->val[i] ; } } } return def ; } /*-------------------------------------------------------------------------*/ /** @brief Set a value in a dictionary. @param d dictionary object to modify. @param key Key to modify or add. @param val Value to add. @return int 0 if Ok, anything else otherwise If the given key is found in the dictionary, the associated value is replaced by the provided one. If the key cannot be found in the dictionary, it is added to it. It is Ok to provide a NULL value for val, but NULL values for the dictionary or the key are considered as errors: the function will return immediately in such a case. Notice that if you dictionary_set a variable to NULL, a call to dictionary_get will return a NULL value: the variable will be found, and its value (NULL) is returned. In other words, setting the variable content to NULL is equivalent to deleting the variable from the dictionary. It is not possible (in this implementation) to have a key in the dictionary without value. This function returns non-zero in case of failure. */ /*--------------------------------------------------------------------------*/ int dictionary_set(dictionary * d, const char * key, const char * val) { int i ; unsigned hash ; if (d==NULL || key==NULL) return -1 ; /* Compute hash for this key */ hash = dictionary_hash(key) ; /* Find if value is already in dictionary */ if (d->n>0) { for (i=0 ; isize ; i++) { if (d->key[i]==NULL) continue ; if (hash==d->hash[i]) { /* Same hash value */ if (!strcmp(key, d->key[i])) { /* Same key */ /* Found a value: modify and return */ if (d->val[i]!=NULL) free(d->val[i]); d->val[i] = val ? xstrdup(val) : NULL ; /* Value has been modified: return */ return 0 ; } } } } /* Add a new value */ /* See if dictionary needs to grow */ if (d->n==d->size) { /* Reached maximum size: reallocate dictionary */ d->val = (char **)mem_double(d->val, d->size * sizeof(char*)) ; d->key = (char **)mem_double(d->key, d->size * sizeof(char*)) ; d->hash = (unsigned int *)mem_double(d->hash, d->size * sizeof(unsigned)) ; if ((d->val==NULL) || (d->key==NULL) || (d->hash==NULL)) { /* Cannot grow dictionary */ return -1 ; } /* Double size */ d->size *= 2 ; } /* Insert key in the first empty slot. Start at d->n and wrap at d->size. Because d->n < d->size this will necessarily terminate. */ for (i=d->n ; d->key[i] ; ) { if(++i == d->size) i = 0; } /* Copy key */ d->key[i] = xstrdup(key); d->val[i] = val ? xstrdup(val) : NULL ; d->hash[i] = hash; d->n ++ ; return 0 ; } /*-------------------------------------------------------------------------*/ /** @brief Delete a key in a dictionary @param d dictionary object to modify. @param key Key to remove. @return void This function deletes a key in a dictionary. Nothing is done if the key cannot be found. */ /*--------------------------------------------------------------------------*/ void dictionary_unset(dictionary * d, const char * key) { unsigned hash ; int i ; if (key == NULL) { return; } hash = dictionary_hash(key); for (i=0 ; isize ; i++) { if (d->key[i]==NULL) continue ; /* Compare hash */ if (hash==d->hash[i]) { /* Compare string, to avoid hash collisions */ if (!strcmp(key, d->key[i])) { /* Found key */ break ; } } } if (i>=d->size) /* Key not found */ return ; free(d->key[i]); d->key[i] = NULL ; if (d->val[i]!=NULL) { free(d->val[i]); d->val[i] = NULL ; } d->hash[i] = 0 ; d->n -- ; return ; } /*-------------------------------------------------------------------------*/ /** @brief Dump a dictionary to an opened file pointer. @param d Dictionary to dump @param f Opened file pointer. @return void Dumps a dictionary onto an opened file pointer. Key pairs are printed out as @c [Key]=[Value], one per line. It is Ok to provide stdout or stderr as output file pointers. */ /*--------------------------------------------------------------------------*/ void dictionary_dump(dictionary * d, FILE * out) { int i ; if (d==NULL || out==NULL) return ; if (d->n<1) { fprintf(out, "empty dictionary\n"); return ; } for (i=0 ; isize ; i++) { if (d->key[i]) { fprintf(out, "%20s\t[%s]\n", d->key[i], d->val[i] ? d->val[i] : "UNDEF"); } } return ; } /* Test code */ #ifdef TESTDIC #define NVALS 20000 int main(int argc, char *argv[]) { dictionary * d ; char * val ; int i ; char cval[90] ; /* Allocate dictionary */ printf("allocating...\n"); d = dictionary_new(0); /* Set values in dictionary */ printf("setting %d values...\n", NVALS); for (i=0 ; in != 0) { printf("error deleting values\n"); } printf("deallocating...\n"); dictionary_del(d); return 0 ; } #endif /* vim: set ts=4 et sw=4 tw=75 */ fcitx-punc-ng-0.1.1~git20161101/src/iniparser/dictionary.h000066400000000000000000000146271300576763500230400ustar00rootroot00000000000000 /*-------------------------------------------------------------------------*/ /** @file dictionary.h @author N. Devillard @brief Implements a dictionary for string variables. This module implements a simple dictionary object, i.e. a list of string/string associations. This object is useful to store e.g. informations retrieved from a configuration file (ini files). */ /*--------------------------------------------------------------------------*/ #ifndef _DICTIONARY_H_ #define _DICTIONARY_H_ /*--------------------------------------------------------------------------- Includes ---------------------------------------------------------------------------*/ #include #include #include #include /*--------------------------------------------------------------------------- New types ---------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/ /** @brief Dictionary object This object contains a list of string/string associations. Each association is identified by a unique string key. Looking up values in the dictionary is speeded up by the use of a (hopefully collision-free) hash function. */ /*-------------------------------------------------------------------------*/ typedef struct _dictionary_ { int n ; /** Number of entries in dictionary */ int size ; /** Storage size */ char ** val ; /** List of string values */ char ** key ; /** List of string keys */ unsigned * hash ; /** List of hash values for keys */ } dictionary ; /*--------------------------------------------------------------------------- Function prototypes ---------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/ /** @brief Compute the hash key for a string. @param key Character string to use for key. @return 1 unsigned int on at least 32 bits. This hash function has been taken from an Article in Dr Dobbs Journal. This is normally a collision-free function, distributing keys evenly. The key is stored anyway in the struct so that collision can be avoided by comparing the key itself in last resort. */ /*--------------------------------------------------------------------------*/ unsigned dictionary_hash(const char * key); /*-------------------------------------------------------------------------*/ /** @brief Create a new dictionary object. @param size Optional initial size of the dictionary. @return 1 newly allocated dictionary objet. This function allocates a new dictionary object of given size and returns it. If you do not know in advance (roughly) the number of entries in the dictionary, give size=0. */ /*--------------------------------------------------------------------------*/ dictionary * dictionary_new(int size); /*-------------------------------------------------------------------------*/ /** @brief Delete a dictionary object @param d dictionary object to deallocate. @return void Deallocate a dictionary object and all memory associated to it. */ /*--------------------------------------------------------------------------*/ void dictionary_del(dictionary * vd); /*-------------------------------------------------------------------------*/ /** @brief Get a value from a dictionary. @param d dictionary object to search. @param key Key to look for in the dictionary. @param def Default value to return if key not found. @return 1 pointer to internally allocated character string. This function locates a key in a dictionary and returns a pointer to its value, or the passed 'def' pointer if no such key can be found in dictionary. The returned character pointer points to data internal to the dictionary object, you should not try to free it or modify it. */ /*--------------------------------------------------------------------------*/ char * dictionary_get(dictionary * d, const char * key, char * def); /*-------------------------------------------------------------------------*/ /** @brief Set a value in a dictionary. @param d dictionary object to modify. @param key Key to modify or add. @param val Value to add. @return int 0 if Ok, anything else otherwise If the given key is found in the dictionary, the associated value is replaced by the provided one. If the key cannot be found in the dictionary, it is added to it. It is Ok to provide a NULL value for val, but NULL values for the dictionary or the key are considered as errors: the function will return immediately in such a case. Notice that if you dictionary_set a variable to NULL, a call to dictionary_get will return a NULL value: the variable will be found, and its value (NULL) is returned. In other words, setting the variable content to NULL is equivalent to deleting the variable from the dictionary. It is not possible (in this implementation) to have a key in the dictionary without value. This function returns non-zero in case of failure. */ /*--------------------------------------------------------------------------*/ int dictionary_set(dictionary * vd, const char * key, const char * val); /*-------------------------------------------------------------------------*/ /** @brief Delete a key in a dictionary @param d dictionary object to modify. @param key Key to remove. @return void This function deletes a key in a dictionary. Nothing is done if the key cannot be found. */ /*--------------------------------------------------------------------------*/ void dictionary_unset(dictionary * d, const char * key); /*-------------------------------------------------------------------------*/ /** @brief Dump a dictionary to an opened file pointer. @param d Dictionary to dump @param f Opened file pointer. @return void Dumps a dictionary onto an opened file pointer. Key pairs are printed out as @c [Key]=[Value], one per line. It is Ok to provide stdout or stderr as output file pointers. */ /*--------------------------------------------------------------------------*/ void dictionary_dump(dictionary * d, FILE * out); #endif fcitx-punc-ng-0.1.1~git20161101/src/iniparser/iniexample.c000066400000000000000000000043121300576763500230070ustar00rootroot00000000000000#include #include #include #include #include "iniparser.h" void create_example_ini_file(void); int parse_ini_file(char * ini_name); int main(int argc, char * argv[]) { int status ; if (argc<2) { create_example_ini_file(); status = parse_ini_file("example.ini"); } else { status = parse_ini_file(argv[1]); } return status ; } void create_example_ini_file(void) { FILE * ini ; ini = fopen("example.ini", "w"); fprintf(ini, "#\n" "# This is an example of ini file\n" "#\n" "\n" "[Pizza]\n" "\n" "Ham = yes ;\n" "Mushrooms = TRUE ;\n" "Capres = 0 ;\n" "Cheese = Non ;\n" "\n" "\n" "[Wine]\n" "\n" "Grape = Cabernet Sauvignon ;\n" "Year = 1989 ;\n" "Country = Spain ;\n" "Alcohol = 12.5 ;\n" "\n"); fclose(ini); } int parse_ini_file(char * ini_name) { dictionary * ini ; /* Some temporary variables to hold query results */ int b ; int i ; double d ; char * s ; ini = iniparser_load(ini_name); if (ini==NULL) { fprintf(stderr, "cannot parse file: %s\n", ini_name); return -1 ; } iniparser_dump(ini, stderr); /* Get pizza attributes */ printf("Pizza:\n"); b = iniparser_getboolean(ini, "pizza:ham", -1); printf("Ham: [%d]\n", b); b = iniparser_getboolean(ini, "pizza:mushrooms", -1); printf("Mushrooms: [%d]\n", b); b = iniparser_getboolean(ini, "pizza:capres", -1); printf("Capres: [%d]\n", b); b = iniparser_getboolean(ini, "pizza:cheese", -1); printf("Cheese: [%d]\n", b); /* Get wine attributes */ printf("Wine:\n"); s = iniparser_getstring(ini, "wine:grape", NULL); printf("Grape: [%s]\n", s ? s : "UNDEF"); i = iniparser_getint(ini, "wine:year", -1); printf("Year: [%d]\n", i); s = iniparser_getstring(ini, "wine:country", NULL); printf("Country: [%s]\n", s ? s : "UNDEF"); d = iniparser_getdouble(ini, "wine:alcohol", -1.0); printf("Alcohol: [%g]\n", d); iniparser_freedict(ini); return 0 ; } fcitx-punc-ng-0.1.1~git20161101/src/iniparser/iniparser.c000066400000000000000000000545101300576763500226550ustar00rootroot00000000000000 /*-------------------------------------------------------------------------*/ /** @file iniparser.c @author N. Devillard @brief Parser for ini files. */ /*--------------------------------------------------------------------------*/ /*---------------------------- Includes ------------------------------------*/ #include #include "iniparser.h" /*---------------------------- Defines -------------------------------------*/ #define ASCIILINESZ (1024) #define INI_INVALID_KEY ((char*)-1) /*--------------------------------------------------------------------------- Private to this module ---------------------------------------------------------------------------*/ /** * This enum stores the status for each parsed line (internal use only). */ typedef enum _line_status_ { LINE_UNPROCESSED, LINE_ERROR, LINE_EMPTY, LINE_COMMENT, LINE_SECTION, LINE_VALUE } line_status ; /*-------------------------------------------------------------------------*/ /** @brief Convert a string to lowercase. @param s String to convert. @return ptr to statically allocated string. This function returns a pointer to a statically allocated string containing a lowercased version of the input string. Do not free or modify the returned string! Since the returned string is statically allocated, it will be modified at each function call (not re-entrant). */ /*--------------------------------------------------------------------------*/ static char * strlwc(const char * s) { static char l[ASCIILINESZ+1]; int i ; if (s==NULL) return NULL ; memset(l, 0, ASCIILINESZ+1); i=0 ; while (s[i] && i l) { if (!isspace((int)*(last-1))) break ; last -- ; } *last = (char)0; return (char*)l ; } /*-------------------------------------------------------------------------*/ /** @brief Get number of sections in a dictionary @param d Dictionary to examine @return int Number of sections found in dictionary This function returns the number of sections found in a dictionary. The test to recognize sections is done on the string stored in the dictionary: a section name is given as "section" whereas a key is stored as "section:key", thus the test looks for entries that do not contain a colon. This clearly fails in the case a section name contains a colon, but this should simply be avoided. This function returns -1 in case of error. */ /*--------------------------------------------------------------------------*/ int iniparser_getnsec(dictionary * d) { int i ; int nsec ; if (d==NULL) return -1 ; nsec=0 ; for (i=0 ; isize ; i++) { if (d->key[i]==NULL) continue ; if (strchr(d->key[i], ':')==NULL) { nsec ++ ; } } return nsec ; } /*-------------------------------------------------------------------------*/ /** @brief Get name for section n in a dictionary. @param d Dictionary to examine @param n Section number (from 0 to nsec-1). @return Pointer to char string This function locates the n-th section in a dictionary and returns its name as a pointer to a string statically allocated inside the dictionary. Do not free or modify the returned string! This function returns NULL in case of error. */ /*--------------------------------------------------------------------------*/ char * iniparser_getsecname(dictionary * d, int n) { int i ; int foundsec ; if (d==NULL || n<0) return NULL ; foundsec=0 ; for (i=0 ; isize ; i++) { if (d->key[i]==NULL) continue ; if (strchr(d->key[i], ':')==NULL) { foundsec++ ; if (foundsec>n) break ; } } if (foundsec<=n) { return NULL ; } return d->key[i] ; } /*-------------------------------------------------------------------------*/ /** @brief Dump a dictionary to an opened file pointer. @param d Dictionary to dump. @param f Opened file pointer to dump to. @return void This function prints out the contents of a dictionary, one element by line, onto the provided file pointer. It is OK to specify @c stderr or @c stdout as output files. This function is meant for debugging purposes mostly. */ /*--------------------------------------------------------------------------*/ void iniparser_dump(dictionary * d, FILE * f) { int i ; if (d==NULL || f==NULL) return ; for (i=0 ; isize ; i++) { if (d->key[i]==NULL) continue ; if (d->val[i]!=NULL) { fprintf(f, "[%s]=[%s]\n", d->key[i], d->val[i]); } else { fprintf(f, "[%s]=UNDEF\n", d->key[i]); } } return ; } /*-------------------------------------------------------------------------*/ /** @brief Save a dictionary to a loadable ini file @param d Dictionary to dump @param f Opened file pointer to dump to @return void This function dumps a given dictionary into a loadable ini file. It is Ok to specify @c stderr or @c stdout as output files. */ /*--------------------------------------------------------------------------*/ void iniparser_dump_ini(dictionary * d, FILE * f) { int i ; int nsec ; char * secname ; if (d==NULL || f==NULL) return ; nsec = iniparser_getnsec(d); if (nsec<1) { /* No section in file: dump all keys as they are */ for (i=0 ; isize ; i++) { if (d->key[i]==NULL) continue ; fprintf(f, "%s = %s\n", d->key[i], d->val[i]); } return ; } for (i=0 ; isize ; j++) { if (d->key[j]==NULL) continue ; if (!strncmp(d->key[j], keym, seclen+1)) { fprintf(f, "%-30s = %s\n", d->key[j]+seclen+1, d->val[j] ? d->val[j] : ""); } } fprintf(f, "\n"); return ; } /*-------------------------------------------------------------------------*/ /** @brief Get the number of keys in a section of a dictionary. @param d Dictionary to examine @param s Section name of dictionary to examine @return Number of keys in section */ /*--------------------------------------------------------------------------*/ int iniparser_getsecnkeys(dictionary * d, char * s) { int seclen, nkeys ; char keym[ASCIILINESZ+1]; int j ; nkeys = 0; if (d==NULL) return nkeys; if (! iniparser_find_entry(d, s)) return nkeys; seclen = (int)strlen(s); sprintf(keym, "%s:", s); for (j=0 ; jsize ; j++) { if (d->key[j]==NULL) continue ; if (!strncmp(d->key[j], keym, seclen+1)) nkeys++; } return nkeys; } /*-------------------------------------------------------------------------*/ /** @brief Get the number of keys in a section of a dictionary. @param d Dictionary to examine @param s Section name of dictionary to examine @return pointer to statically allocated character strings This function queries a dictionary and finds all keys in a given section. Each pointer in the returned char pointer-to-pointer is pointing to a string allocated in the dictionary; do not free or modify them. This function returns NULL in case of error. */ /*--------------------------------------------------------------------------*/ char ** iniparser_getseckeys(dictionary * d, char * s) { char **keys; int i, j ; char keym[ASCIILINESZ+1]; int seclen, nkeys ; keys = NULL; if (d==NULL) return keys; if (! iniparser_find_entry(d, s)) return keys; nkeys = iniparser_getsecnkeys(d, s); keys = (char**) malloc(nkeys*sizeof(char*)); seclen = (int)strlen(s); sprintf(keym, "%s:", s); i = 0; for (j=0 ; jsize ; j++) { if (d->key[j]==NULL) continue ; if (!strncmp(d->key[j], keym, seclen+1)) { keys[i] = d->key[j]; i++; } } return keys; } /*-------------------------------------------------------------------------*/ /** @brief Get the string associated to a key @param d Dictionary to search @param key Key string to look for @param def Default value to return if key not found. @return pointer to statically allocated character string This function queries a dictionary for a key. A key as read from an ini file is given as "section:key". If the key cannot be found, the pointer passed as 'def' is returned. The returned char pointer is pointing to a string allocated in the dictionary, do not free or modify it. */ /*--------------------------------------------------------------------------*/ char * iniparser_getstring(dictionary * d, const char * key, char * def) { char * lc_key ; char * sval ; if (d==NULL || key==NULL) return def ; lc_key = strlwc(key); sval = dictionary_get(d, lc_key, def); return sval ; } /*-------------------------------------------------------------------------*/ /** @brief Get the string associated to a key, convert to an int @param d Dictionary to search @param key Key string to look for @param notfound Value to return in case of error @return integer This function queries a dictionary for a key. A key as read from an ini file is given as "section:key". If the key cannot be found, the notfound value is returned. Supported values for integers include the usual C notation so decimal, octal (starting with 0) and hexadecimal (starting with 0x) are supported. Examples: "42" -> 42 "042" -> 34 (octal -> decimal) "0x42" -> 66 (hexa -> decimal) Warning: the conversion may overflow in various ways. Conversion is totally outsourced to strtol(), see the associated man page for overflow handling. Credits: Thanks to A. Becker for suggesting strtol() */ /*--------------------------------------------------------------------------*/ int iniparser_getint(dictionary * d, const char * key, int notfound) { char * str ; str = iniparser_getstring(d, key, INI_INVALID_KEY); if (str==INI_INVALID_KEY) return notfound ; return (int)strtol(str, NULL, 0); } /*-------------------------------------------------------------------------*/ /** @brief Get the string associated to a key, convert to a double @param d Dictionary to search @param key Key string to look for @param notfound Value to return in case of error @return double This function queries a dictionary for a key. A key as read from an ini file is given as "section:key". If the key cannot be found, the notfound value is returned. */ /*--------------------------------------------------------------------------*/ double iniparser_getdouble(dictionary * d, const char * key, double notfound) { char * str ; str = iniparser_getstring(d, key, INI_INVALID_KEY); if (str==INI_INVALID_KEY) return notfound ; return atof(str); } /*-------------------------------------------------------------------------*/ /** @brief Get the string associated to a key, convert to a boolean @param d Dictionary to search @param key Key string to look for @param notfound Value to return in case of error @return integer This function queries a dictionary for a key. A key as read from an ini file is given as "section:key". If the key cannot be found, the notfound value is returned. A true boolean is found if one of the following is matched: - A string starting with 'y' - A string starting with 'Y' - A string starting with 't' - A string starting with 'T' - A string starting with '1' A false boolean is found if one of the following is matched: - A string starting with 'n' - A string starting with 'N' - A string starting with 'f' - A string starting with 'F' - A string starting with '0' The notfound value returned if no boolean is identified, does not necessarily have to be 0 or 1. */ /*--------------------------------------------------------------------------*/ int iniparser_getboolean(dictionary * d, const char * key, int notfound) { char * c ; int ret ; c = iniparser_getstring(d, key, INI_INVALID_KEY); if (c==INI_INVALID_KEY) return notfound ; if (c[0]=='y' || c[0]=='Y' || c[0]=='1' || c[0]=='t' || c[0]=='T') { ret = 1 ; } else if (c[0]=='n' || c[0]=='N' || c[0]=='0' || c[0]=='f' || c[0]=='F') { ret = 0 ; } else { ret = notfound ; } return ret; } /*-------------------------------------------------------------------------*/ /** @brief Finds out if a given entry exists in a dictionary @param ini Dictionary to search @param entry Name of the entry to look for @return integer 1 if entry exists, 0 otherwise Finds out if a given entry exists in the dictionary. Since sections are stored as keys with NULL associated values, this is the only way of querying for the presence of sections in a dictionary. */ /*--------------------------------------------------------------------------*/ int iniparser_find_entry( dictionary * ini, const char * entry ) { int found=0 ; if (iniparser_getstring(ini, entry, INI_INVALID_KEY)!=INI_INVALID_KEY) { found = 1 ; } return found ; } /*-------------------------------------------------------------------------*/ /** @brief Set an entry in a dictionary. @param ini Dictionary to modify. @param entry Entry to modify (entry name) @param val New value to associate to the entry. @return int 0 if Ok, -1 otherwise. If the given entry can be found in the dictionary, it is modified to contain the provided value. If it cannot be found, -1 is returned. It is Ok to set val to NULL. */ /*--------------------------------------------------------------------------*/ int iniparser_set(dictionary * ini, const char * entry, const char * val) { return dictionary_set(ini, strlwc(entry), val) ; } /*-------------------------------------------------------------------------*/ /** @brief Delete an entry in a dictionary @param ini Dictionary to modify @param entry Entry to delete (entry name) @return void If the given entry can be found, it is deleted from the dictionary. */ /*--------------------------------------------------------------------------*/ void iniparser_unset(dictionary * ini, const char * entry) { dictionary_unset(ini, strlwc(entry)); } /*-------------------------------------------------------------------------*/ /** @brief Load a single line from an INI file @param input_line Input line, may be concatenated multi-line input @param section Output space to store section @param key Output space to store key @param value Output space to store value @return line_status value */ /*--------------------------------------------------------------------------*/ static line_status iniparser_line( const char * input_line, char * section, char * key, char * value) { line_status sta ; char line[ASCIILINESZ+1]; int len ; strcpy(line, strstrip(input_line)); len = (int)strlen(line); sta = LINE_UNPROCESSED ; if (len<1) { /* Empty line */ sta = LINE_EMPTY ; } else if (line[0]=='#' || line[0]==';') { /* Comment line */ sta = LINE_COMMENT ; } else if (line[0]=='[' && line[len-1]==']') { /* Section name */ sscanf(line, "[%[^]]", section); strcpy(section, strstrip(section)); strcpy(section, strlwc(section)); sta = LINE_SECTION ; } else if (sscanf (line, "%[^=] = \"%[^\"]\"", key, value) == 2 || sscanf (line, "%[^=] = '%[^\']'", key, value) == 2 || sscanf (line, "%[^=] = %[^;#]", key, value) == 2) { /* Usual key=value, with or without comments */ strcpy(key, strstrip(key)); strcpy(key, strlwc(key)); strcpy(value, strstrip(value)); /* * sscanf cannot handle '' or "" as empty values * this is done here */ if (!strcmp(value, "\"\"") || (!strcmp(value, "''"))) { value[0]=0 ; } sta = LINE_VALUE ; } else if (sscanf(line, "%[^=] = %[;#]", key, value)==2 || sscanf(line, "%[^=] %[=]", key, value) == 2) { /* * Special cases: * key= * key=; * key=# */ strcpy(key, strstrip(key)); strcpy(key, strlwc(key)); value[0]=0 ; sta = LINE_VALUE ; } else { /* Generate syntax error */ sta = LINE_ERROR ; } return sta ; } /*-------------------------------------------------------------------------*/ /** @brief Parse an ini file and return an allocated dictionary object @param ininame Name of the ini file to read. @return Pointer to newly allocated dictionary This is the parser for ini files. This function is called, providing the name of the file to be read. It returns a dictionary object that should not be accessed directly, but through accessor functions instead. The returned dictionary must be freed using iniparser_freedict(). */ /*--------------------------------------------------------------------------*/ dictionary * iniparser_load(const char * ininame) { FILE * in ; char line [ASCIILINESZ+1] ; char section [ASCIILINESZ+1] ; char key [ASCIILINESZ+1] ; char tmp [ASCIILINESZ+1] ; char val [ASCIILINESZ+1] ; int last=0 ; int len ; int lineno=0 ; int errs=0; dictionary * dict ; if ((in=fopen(ininame, "r"))==NULL) { fprintf(stderr, "iniparser: cannot open %s\n", ininame); return NULL ; } dict = dictionary_new(0) ; if (!dict) { fclose(in); return NULL ; } memset(line, 0, ASCIILINESZ); memset(section, 0, ASCIILINESZ); memset(key, 0, ASCIILINESZ); memset(val, 0, ASCIILINESZ); last=0 ; while (fgets(line+last, ASCIILINESZ-last, in)!=NULL) { lineno++ ; len = (int)strlen(line)-1; if (len==0) continue; /* Safety check against buffer overflows */ if (line[len]!='\n') { fprintf(stderr, "iniparser: input line too long in %s (%d)\n", ininame, lineno); dictionary_del(dict); fclose(in); return NULL ; } /* Get rid of \n and spaces at end of line */ while ((len>=0) && ((line[len]=='\n') || (isspace(line[len])))) { line[len]=0 ; len-- ; } /* Detect multi-line */ if (line[len]=='\\') { /* Multi-line value */ last=len ; continue ; } else { last=0 ; } switch (iniparser_line(line, section, key, val)) { case LINE_EMPTY: case LINE_COMMENT: break ; case LINE_SECTION: errs = dictionary_set(dict, section, NULL); break ; case LINE_VALUE: sprintf(tmp, "%s:%s", section, key); errs = dictionary_set(dict, tmp, val) ; break ; case LINE_ERROR: fprintf(stderr, "iniparser: syntax error in %s (%d):\n", ininame, lineno); fprintf(stderr, "-> %s\n", line); errs++ ; break; default: break ; } memset(line, 0, ASCIILINESZ); last=0; if (errs<0) { fprintf(stderr, "iniparser: memory allocation failure\n"); break ; } } if (errs) { dictionary_del(dict); dict = NULL ; } fclose(in); return dict ; } /*-------------------------------------------------------------------------*/ /** @brief Free all memory associated to an ini dictionary @param d Dictionary to free @return void Free all memory associated to an ini dictionary. It is mandatory to call this function before the dictionary object gets out of the current context. */ /*--------------------------------------------------------------------------*/ void iniparser_freedict(dictionary * d) { dictionary_del(d); } /* vim: set ts=4 et sw=4 tw=75 */ fcitx-punc-ng-0.1.1~git20161101/src/iniparser/iniparser.h000066400000000000000000000264661300576763500226730ustar00rootroot00000000000000 /*-------------------------------------------------------------------------*/ /** @file iniparser.h @author N. Devillard @brief Parser for ini files. */ /*--------------------------------------------------------------------------*/ #ifndef _INIPARSER_H_ #define _INIPARSER_H_ /*--------------------------------------------------------------------------- Includes ---------------------------------------------------------------------------*/ #include #include #include /* * The following #include is necessary on many Unixes but not Linux. * It is not needed for Windows platforms. * Uncomment it if needed. */ /* #include */ #include "dictionary.h" /*-------------------------------------------------------------------------*/ /** @brief Get number of sections in a dictionary @param d Dictionary to examine @return int Number of sections found in dictionary This function returns the number of sections found in a dictionary. The test to recognize sections is done on the string stored in the dictionary: a section name is given as "section" whereas a key is stored as "section:key", thus the test looks for entries that do not contain a colon. This clearly fails in the case a section name contains a colon, but this should simply be avoided. This function returns -1 in case of error. */ /*--------------------------------------------------------------------------*/ int iniparser_getnsec(dictionary * d); /*-------------------------------------------------------------------------*/ /** @brief Get name for section n in a dictionary. @param d Dictionary to examine @param n Section number (from 0 to nsec-1). @return Pointer to char string This function locates the n-th section in a dictionary and returns its name as a pointer to a string statically allocated inside the dictionary. Do not free or modify the returned string! This function returns NULL in case of error. */ /*--------------------------------------------------------------------------*/ char * iniparser_getsecname(dictionary * d, int n); /*-------------------------------------------------------------------------*/ /** @brief Save a dictionary to a loadable ini file @param d Dictionary to dump @param f Opened file pointer to dump to @return void This function dumps a given dictionary into a loadable ini file. It is Ok to specify @c stderr or @c stdout as output files. */ /*--------------------------------------------------------------------------*/ void iniparser_dump_ini(dictionary * d, FILE * f); /*-------------------------------------------------------------------------*/ /** @brief Save a dictionary section to a loadable ini file @param d Dictionary to dump @param s Section name of dictionary to dump @param f Opened file pointer to dump to @return void This function dumps a given section of a given dictionary into a loadable ini file. It is Ok to specify @c stderr or @c stdout as output files. */ /*--------------------------------------------------------------------------*/ void iniparser_dumpsection_ini(dictionary * d, char * s, FILE * f); /*-------------------------------------------------------------------------*/ /** @brief Dump a dictionary to an opened file pointer. @param d Dictionary to dump. @param f Opened file pointer to dump to. @return void This function prints out the contents of a dictionary, one element by line, onto the provided file pointer. It is OK to specify @c stderr or @c stdout as output files. This function is meant for debugging purposes mostly. */ /*--------------------------------------------------------------------------*/ void iniparser_dump(dictionary * d, FILE * f); /*-------------------------------------------------------------------------*/ /** @brief Get the number of keys in a section of a dictionary. @param d Dictionary to examine @param s Section name of dictionary to examine @return Number of keys in section */ /*--------------------------------------------------------------------------*/ int iniparser_getsecnkeys(dictionary * d, char * s); /*-------------------------------------------------------------------------*/ /** @brief Get the number of keys in a section of a dictionary. @param d Dictionary to examine @param s Section name of dictionary to examine @return pointer to statically allocated character strings This function queries a dictionary and finds all keys in a given section. Each pointer in the returned char pointer-to-pointer is pointing to a string allocated in the dictionary; do not free or modify them. This function returns NULL in case of error. */ /*--------------------------------------------------------------------------*/ char ** iniparser_getseckeys(dictionary * d, char * s); /*-------------------------------------------------------------------------*/ /** @brief Get the string associated to a key @param d Dictionary to search @param key Key string to look for @param def Default value to return if key not found. @return pointer to statically allocated character string This function queries a dictionary for a key. A key as read from an ini file is given as "section:key". If the key cannot be found, the pointer passed as 'def' is returned. The returned char pointer is pointing to a string allocated in the dictionary, do not free or modify it. */ /*--------------------------------------------------------------------------*/ char * iniparser_getstring(dictionary * d, const char * key, char * def); /*-------------------------------------------------------------------------*/ /** @brief Get the string associated to a key, convert to an int @param d Dictionary to search @param key Key string to look for @param notfound Value to return in case of error @return integer This function queries a dictionary for a key. A key as read from an ini file is given as "section:key". If the key cannot be found, the notfound value is returned. Supported values for integers include the usual C notation so decimal, octal (starting with 0) and hexadecimal (starting with 0x) are supported. Examples: - "42" -> 42 - "042" -> 34 (octal -> decimal) - "0x42" -> 66 (hexa -> decimal) Warning: the conversion may overflow in various ways. Conversion is totally outsourced to strtol(), see the associated man page for overflow handling. Credits: Thanks to A. Becker for suggesting strtol() */ /*--------------------------------------------------------------------------*/ int iniparser_getint(dictionary * d, const char * key, int notfound); /*-------------------------------------------------------------------------*/ /** @brief Get the string associated to a key, convert to a double @param d Dictionary to search @param key Key string to look for @param notfound Value to return in case of error @return double This function queries a dictionary for a key. A key as read from an ini file is given as "section:key". If the key cannot be found, the notfound value is returned. */ /*--------------------------------------------------------------------------*/ double iniparser_getdouble(dictionary * d, const char * key, double notfound); /*-------------------------------------------------------------------------*/ /** @brief Get the string associated to a key, convert to a boolean @param d Dictionary to search @param key Key string to look for @param notfound Value to return in case of error @return integer This function queries a dictionary for a key. A key as read from an ini file is given as "section:key". If the key cannot be found, the notfound value is returned. A true boolean is found if one of the following is matched: - A string starting with 'y' - A string starting with 'Y' - A string starting with 't' - A string starting with 'T' - A string starting with '1' A false boolean is found if one of the following is matched: - A string starting with 'n' - A string starting with 'N' - A string starting with 'f' - A string starting with 'F' - A string starting with '0' The notfound value returned if no boolean is identified, does not necessarily have to be 0 or 1. */ /*--------------------------------------------------------------------------*/ int iniparser_getboolean(dictionary * d, const char * key, int notfound); /*-------------------------------------------------------------------------*/ /** @brief Set an entry in a dictionary. @param ini Dictionary to modify. @param entry Entry to modify (entry name) @param val New value to associate to the entry. @return int 0 if Ok, -1 otherwise. If the given entry can be found in the dictionary, it is modified to contain the provided value. If it cannot be found, -1 is returned. It is Ok to set val to NULL. */ /*--------------------------------------------------------------------------*/ int iniparser_set(dictionary * ini, const char * entry, const char * val); /*-------------------------------------------------------------------------*/ /** @brief Delete an entry in a dictionary @param ini Dictionary to modify @param entry Entry to delete (entry name) @return void If the given entry can be found, it is deleted from the dictionary. */ /*--------------------------------------------------------------------------*/ void iniparser_unset(dictionary * ini, const char * entry); /*-------------------------------------------------------------------------*/ /** @brief Finds out if a given entry exists in a dictionary @param ini Dictionary to search @param entry Name of the entry to look for @return integer 1 if entry exists, 0 otherwise Finds out if a given entry exists in the dictionary. Since sections are stored as keys with NULL associated values, this is the only way of querying for the presence of sections in a dictionary. */ /*--------------------------------------------------------------------------*/ int iniparser_find_entry(dictionary * ini, const char * entry) ; /*-------------------------------------------------------------------------*/ /** @brief Parse an ini file and return an allocated dictionary object @param ininame Name of the ini file to read. @return Pointer to newly allocated dictionary This is the parser for ini files. This function is called, providing the name of the file to be read. It returns a dictionary object that should not be accessed directly, but through accessor functions instead. The returned dictionary must be freed using iniparser_freedict(). */ /*--------------------------------------------------------------------------*/ dictionary * iniparser_load(const char * ininame); /*-------------------------------------------------------------------------*/ /** @brief Free all memory associated to an ini dictionary @param d Dictionary to free @return void Free all memory associated to an ini dictionary. It is mandatory to call this function before the dictionary object gets out of the current context. */ /*--------------------------------------------------------------------------*/ void iniparser_freedict(dictionary * d); #endif fcitx-punc-ng-0.1.1~git20161101/src/iniparser/parse.c000066400000000000000000000006311300576763500217660ustar00rootroot00000000000000#include #include #include #include #include "iniparser.h" int main(int argc, char * argv[]) { dictionary * ini ; char * ini_name ; if (argc<2) { ini_name = "twisted.ini"; } else { ini_name = argv[1] ; } ini = iniparser_load(ini_name); iniparser_dump(ini, stdout); iniparser_freedict(ini); return 0 ; } fcitx-punc-ng-0.1.1~git20161101/src/punc-ng.c000066400000000000000000000566471300576763500202510ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2002~2005 by Yuking * * yuking_net@sohu.com * * * * 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., * * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include #include #include #include #include #include "punc-ng.h" #include "fcitx/module.h" #include "fcitx/fcitx.h" #include "fcitx/hook.h" #include "fcitx/ime.h" #include "fcitx/keys.h" #include "fcitx/frontend.h" #include "fcitx/instance.h" #include "fcitx/candidate.h" #include "fcitx/context.h" #include "fcitx-config/xdg.h" #include "fcitx-utils/log.h" #include "fcitx-utils/utils.h" #include "fcitx-utils/bitset.h" #include #include "cfgrw.h" #ifdef FcitxLog #undef FcitxLog #define FcitxLog(e, fmt...) #endif /** * @file punc.c * Trans full width punc for Fcitx */ #define PUNC_DICT_FILENAME "punc-ng.mb" #define MAX_PUNC_NO 2 #define MAX_PUNC_LENGTH 2 struct _FcitxPuncState; typedef struct _WidePunc { char ASCII; char strWidePunc[MAX_PUNC_NO][MAX_PUNC_LENGTH * UTF8_MAX_LENGTH + 1]; unsigned iCount: 2; } WidePunc; typedef struct _PuncWhich { FcitxBitSet* bitset; WidePunc* lastPunc; } PuncWhich; typedef struct _FcitxPunc { char* langCode; WidePunc* curPunc; UT_hash_handle hh; } FcitxPunc; static boolean LoadPuncDict(struct _FcitxPuncState* puncState); static FcitxPunc* LoadPuncFile(const char* filename); static char *GetPunc(struct _FcitxPuncState* puncState, int iKey); static void FreePunc(struct _FcitxPuncState* puncState); static void* PuncCreate(FcitxInstance* instance); static boolean PuncPreFilter(void* arg, FcitxKeySym sym, unsigned int state, INPUT_RETURN_VALUE* retVal); static boolean ProcessPunc(void* arg, FcitxKeySym sym, unsigned int state, INPUT_RETURN_VALUE* retVal); static void TogglePuncState(void *arg); static boolean GetPuncState(void *arg); static void ReloadPunc(void *arg); static INPUT_RETURN_VALUE TogglePuncStateWithHotkey(void *arg); static void ResetPunc(void *arg); static void ResetPuncWhichStatus(void* arg); static boolean IsHotKeyPunc(FcitxKeySym sym, unsigned int state); static void PuncLanguageChanged(void* arg, const void* value); static void* PuncWhichAlloc(void* arg); static void* PuncWhichCopy(void* arg, void* data, void* src); static void PuncWhichFree(void* arg, void* data); DECLARE_ADDFUNCTIONS(PuncNg) typedef struct _FcitxPuncState { boolean enableSmartPunc; char cLastIsAutoConvert; boolean bLastIsNumber; int inputCount; FcitxInstance* owner; FcitxPunc* puncSet; WidePunc* curPunc; int slot; } FcitxPuncState; FCITX_DEFINE_PLUGIN(fcitx_punc_ng, module, FcitxModule) = { PuncCreate, NULL, NULL, NULL, ReloadPunc }; FCITX_EXPORT_API int ABI_VERSION = FCITX_ABI_VERSION; void* PuncCreate(FcitxInstance* instance) { FcitxPuncState* puncState = fcitx_utils_malloc0(sizeof(FcitxPuncState)); puncState->owner = instance; LoadPuncDict(puncState); puncState->enableSmartPunc = getCfgValueBool("sogouEnv.ini", "Genelal:SmartPunc", 1); FcitxKeyFilterHook hk; hk.arg = puncState; hk.func = ProcessPunc; FcitxInstanceRegisterPostInputFilter(instance, hk); hk.func = PuncPreFilter; FcitxInstanceRegisterPreInputFilter(instance, hk); puncState->cLastIsAutoConvert = '\0'; puncState->bLastIsNumber = false; puncState->inputCount = 0; FcitxHotkeyHook hotkey; hotkey.hotkey = FcitxInstanceGetGlobalConfig(instance)->hkPunc; hotkey.hotkeyhandle = TogglePuncStateWithHotkey; hotkey.arg = puncState; FcitxInstanceRegisterHotkeyFilter(instance, hotkey); FcitxIMEventHook hook; hook.arg = puncState; hook.func = ResetPunc; FcitxInstanceRegisterResetInputHook(instance, hook); hook.func = ResetPuncWhichStatus; FcitxInstanceRegisterInputUnFocusHook(instance, hook); FcitxInstanceWatchContext(instance, CONTEXT_IM_LANGUAGE, PuncLanguageChanged, puncState); // FcitxProfile* profile = FcitxInstanceGetProfile(instance); // FcitxUIRegisterStatus(instance, puncState, "punc", // profile->bUseWidePunc ? _("Full width punct") : // _("Latin punct"), // _("Toggle Full Width Punctuation"), TogglePuncState, // GetPuncState); puncState->slot = FcitxInstanceAllocDataForIC(instance, PuncWhichAlloc, PuncWhichCopy, PuncWhichFree, puncState); FcitxPuncNgAddFunctions(instance); return puncState; } void* PuncWhichAlloc(void *arg) { FcitxPunc *puncState = arg; PuncWhich *which = fcitx_utils_new(PuncWhich); which->lastPunc = puncState->curPunc; which->bitset = fcitx_bitset_new(256); return which; } void* PuncWhichCopy(void* arg, void* data, void* src) { FCITX_UNUSED(arg); PuncWhich *which = data; PuncWhich *whichsrc = src; which->lastPunc = whichsrc->lastPunc; memcpy(which->bitset, whichsrc->bitset, fcitx_bitset_size(256)); return data; } void PuncWhichFree(void* arg, void* data) { FCITX_UNUSED(arg); PuncWhich *which = data; free(which->bitset); free(data); } void PuncLanguageChanged(void* arg, const void* value) { FcitxPuncState* puncState = (FcitxPuncState*) arg; const char* lang = (const char*) value; FcitxPunc* punc = NULL; if (lang) { HASH_FIND_STR(puncState->puncSet, lang, punc); if (punc) puncState->curPunc = punc->curPunc; else puncState->curPunc = NULL; } else puncState->curPunc = NULL; FcitxUISetStatusVisable (puncState->owner, "punc", puncState->curPunc != NULL) ; } static void PuncGetPunc2(FcitxPuncState *puncState, int key, char **p1, char **p2) { int iIndex = 0; WidePunc *curPunc = puncState->curPunc; if (!curPunc) return; while (curPunc[iIndex].ASCII) { if (curPunc[iIndex].ASCII == key) { if (p1) *p1 = curPunc[iIndex].strWidePunc[0]; if (curPunc[iIndex].iCount > 1 && p2) *p2 = curPunc[iIndex].strWidePunc[1]; break; } iIndex++; } } void ResetPunc(void* arg) { // FcitxPuncState* puncState = (FcitxPuncState*) arg; // puncState->bLastIsNumber = false; // puncState->cLastIsAutoConvert = '\0'; } void ResetPuncWhichStatus(void* arg) { FcitxPuncState* puncState = (FcitxPuncState*) arg; WidePunc *curPunc = puncState->curPunc; if (!curPunc) return; FcitxInputContext* ic = FcitxInstanceGetCurrentIC(puncState->owner); if (!ic) return; PuncWhich* puncWhich = FcitxInstanceGetICData(puncState->owner, ic, puncState->slot); fcitx_bitset_clear(puncWhich->bitset); } boolean PuncPreFilter(void* arg, FcitxKeySym sym, unsigned int state, INPUT_RETURN_VALUE* retVal) { FCITX_UNUSED(retVal); FcitxPuncState *puncState = (FcitxPuncState*)arg; FcitxIM *im = FcitxInstanceGetCurrentIM(puncState->owner); if (im == NULL) return false; if(strcmp("sogoupinyin", im->uniqueName) != 0 && strcmp("sogouwubi", im->uniqueName) != 0) return false; if (FcitxHotkeyIsHotKeySimple(sym, state) && !FcitxHotkeyIsHotKeyDigit(sym, state) && !IsHotKeyPunc(sym, state)) puncState->bLastIsNumber = false; FcitxLog(WARNING, "puncState->bLastIsNumber:%d", puncState->bLastIsNumber); return false; } boolean ProcessPunc(void* arg, FcitxKeySym sym, unsigned int state, INPUT_RETURN_VALUE* retVal) { FcitxPuncState* puncState = (FcitxPuncState*) arg; FcitxInstance* instance = puncState->owner; FcitxInputState* input = FcitxInstanceGetInputState(puncState->owner); FcitxProfile* profile = FcitxInstanceGetProfile(instance); FcitxGlobalConfig* config = FcitxInstanceGetGlobalConfig(instance); boolean lastIsNumber = puncState->bLastIsNumber; FcitxIM *im = FcitxInstanceGetCurrentIM(puncState->owner); if (im == NULL) return false; if(strcmp("sogoupinyin", im->uniqueName) != 0 && strcmp("sogouwubi", im->uniqueName) != 0) return false; char *pPunc = NULL; if (*retVal != IRV_TO_PROCESS) return false; //FcitxLog(WARNING, "puncState->bLastIsNumber:%d", // puncState->bLastIsNumber); //fprintf(stderr, "profile->bUseWidePunc:%d\n", profile->bUseWidePunc); FcitxCandidateWordList *candList = FcitxInputStateGetCandidateList(input); if (FcitxCandidateWordGetListSize(candList) != 0) { if (FcitxCandidateWordGetHasGoneToNextPage(candList) && FcitxHotkeyIsHotKey(sym, state, FcitxConfigPrevPageKey(instance, config))) { return false; } /* * comparing with upper case, if paging is occupied, * punc will not let next page pass */ if (FcitxHotkeyIsHotKey(sym, state, FcitxConfigNextPageKey(instance, config))) { return false; } } FcitxKeySym origsym = sym; sym = FcitxHotkeyPadToMain(sym); //数字后句点特殊处理:直接上英文点 if (lastIsNumber && origsym == FcitxKey_period && puncState->inputCount == 0) { puncState->bLastIsNumber = false; } else if (profile->bUseWidePunc) { /* if (puncState->bLastIsNumber && config->bEngPuncAfterNumber && (FcitxHotkeyIsHotKey(origsym, state, FCITX_PERIOD) || FcitxHotkeyIsHotKey(origsym, state, FCITX_SEMICOLON) || FcitxHotkeyIsHotKey(origsym, state, FCITX_COMMA))) { puncState->cLastIsAutoConvert = origsym; puncState->bLastIsNumber = false; *retVal = IRV_DONOT_PROCESS; return true; } */ if (FcitxHotkeyIsHotKeySimple(sym, state)) pPunc = GetPunc(puncState, origsym); } if (FcitxHotkeyIsHotKeyDigit(sym, state)) { puncState->bLastIsNumber = true; puncState->inputCount = 0; } else if (!FcitxHotkeyIsHotKeyModifierCombine(sym, state) && pPunc && puncState->inputCount ++ >= 1){ puncState->bLastIsNumber = false; } /* * 在有候选词未输入的情况下,选择第一个候选词并输入标点 */ if (IsHotKeyPunc(sym, state)) { FcitxInputStateGetOutputString(input)[0] = '\0'; INPUT_RETURN_VALUE ret = IRV_TO_PROCESS; if (!FcitxInputStateGetIsInRemind(input)) ret = FcitxCandidateWordChooseByTotalIndex(FcitxInputStateGetCandidateList(input), 0); /* if there is nothing to commit */ if (ret == IRV_TO_PROCESS) { if (pPunc) { puncState->cLastIsAutoConvert = origsym; strcat(FcitxInputStateGetOutputString(input), pPunc); *retVal = IRV_PUNC; FcitxInstanceCleanInputWindow(instance); return true; } else return false; } else { if (pPunc) strcat(FcitxInputStateGetOutputString(input), pPunc); else { char buf[2] = { sym, 0 }; strcat(FcitxInputStateGetOutputString(input), buf); } FcitxInstanceCleanInputWindow(instance); *retVal = IRV_PUNC; return true; } return false; } if (profile->bUseWidePunc && puncState->enableSmartPunc) { if (FcitxHotkeyIsHotKey(sym, state, FCITX_BACKSPACE) && puncState->cLastIsAutoConvert && lastIsNumber) { if (puncState->cLastIsAutoConvert == '^' || puncState->cLastIsAutoConvert == '_') { FcitxInstanceForwardKey(puncState->owner, FcitxInstanceGetCurrentIC(instance), FCITX_PRESS_KEY, sym, state); usleep(10000); } FcitxInstanceForwardKey(puncState->owner, FcitxInstanceGetCurrentIC(instance), FCITX_PRESS_KEY, sym, state); char buf[2] = { puncState->cLastIsAutoConvert, 0 }; FcitxInstanceCommitString(puncState->owner, FcitxInstanceGetCurrentIC(instance), buf); puncState->cLastIsAutoConvert = 0; *retVal = IRV_DO_NOTHING; return true; } else if (FcitxHotkeyIsHotKeyDigit(sym, state) && puncState->cLastIsAutoConvert && lastIsNumber) { if (puncState->cLastIsAutoConvert == '^' || puncState->cLastIsAutoConvert == '_') { FcitxInstanceForwardKey(puncState->owner, FcitxInstanceGetCurrentIC(instance), FCITX_PRESS_KEY, FcitxKey_BackSpace, 0); FcitxInstanceForwardKey(puncState->owner, FcitxInstanceGetCurrentIC(instance), FCITX_RELEASE_KEY, FcitxKey_BackSpace, 0); } FcitxInstanceForwardKey(puncState->owner, FcitxInstanceGetCurrentIC(instance), FCITX_PRESS_KEY, FcitxKey_BackSpace, 0); FcitxInstanceForwardKey(puncState->owner, FcitxInstanceGetCurrentIC(instance), FCITX_RELEASE_KEY, FcitxKey_BackSpace, 0); usleep(10000); char buf[2] = { puncState->cLastIsAutoConvert, 0 }; FcitxInstanceCommitString(puncState->owner, FcitxInstanceGetCurrentIC(instance), buf); //FcitxInstanceForwardKey(puncState->owner, // FcitxInstanceGetCurrentIC(instance), FCITX_PRESS_KEY, // sym, state); puncState->cLastIsAutoConvert = 0; //*retVal = IRV_DO_NOTHING; return false; } } puncState->cLastIsAutoConvert = 0; return false; } /** * 加载标点词典 * @param void * @return void * @note 文件中数据的格式为: 对应的英文符号 中文标点 <中文标点> * 加载标点词典。标点词典定义了一组标点转换,如输入‘.’就直接转换成‘。’ */ boolean LoadPuncDict(FcitxPuncState* puncState) { FcitxStringHashSet* puncfiles = FcitxXDGGetFiles("data", PUNC_DICT_FILENAME "." , NULL); FcitxStringHashSet *curpuncfile = puncfiles; FcitxPunc* punc; while (curpuncfile) { punc = LoadPuncFile(curpuncfile->name); if (punc) HASH_ADD_KEYPTR(hh, puncState->puncSet, punc->langCode, strlen(punc->langCode), punc); curpuncfile = curpuncfile->hh.next; } fcitx_utils_free_string_hash_set(puncfiles); return true; } FcitxPunc* LoadPuncFile(const char* filename) { FILE *fpDict; // 词典文件指针 int iRecordNo; char strText[4 + MAX_PUNC_LENGTH * UTF8_MAX_LENGTH]; char *pstr; // 临时指针 int i; fpDict = FcitxXDGGetFileWithPrefix("data", filename, "r", NULL); if (strlen(filename) < strlen(PUNC_DICT_FILENAME)) return NULL; if (!fpDict) { FcitxLog(WARNING, _("Can't open punc file.")); return NULL; } /* 计算词典里面有多少的数据 * 这个函数非常简单,就是计算该文件有多少行(包含空行)。 * 因为空行,在下面会略去,所以,这儿存在内存的浪费现象。 * 没有一个空行就是浪费sizeof (WidePunc)字节内存*/ iRecordNo = fcitx_utils_calculate_record_number(fpDict); // 申请空间,用来存放这些数据。这儿没有检查是否申请到内存,严格说有小隐患 WidePunc* punc = (WidePunc *) fcitx_utils_malloc0(sizeof(WidePunc) * (iRecordNo + 1)); iRecordNo = 0; // 下面这个循环,就是一行一行的读入词典文件的数据。并将其放入到curPunc里面去。 for (;;) { if (!fgets(strText, (MAX_PUNC_LENGTH * UTF8_MAX_LENGTH + 3), fpDict)) break; i = strlen(strText) - 1; // 先找到最后一个字符 while ((strText[i] == '\n') || (strText[i] == ' ')) { if (!i) break; i--; } // 如果找到,进行出入。当是空行时,肯定找不到。所以,也就略过了空行的处理 if (i) { strText[i + 1] = '\0'; // 在字符串的最后加个封口 pstr = strText; // 将pstr指向第一个非空字符 while (*pstr == ' ') pstr++; punc[iRecordNo].ASCII = *pstr++; // 这个就是中文符号所对应的ASCII码值 while (*pstr == ' ') // 然后,将pstr指向下一个非空字符 pstr++; punc[iRecordNo].iCount = 0; // 该符号有几个转化,比如英文"就可以转换成“和” // 依次将该ASCII码所对应的符号放入到结构中 while (*pstr) { i = 0; // 因为中文符号都是多字节(这里读取并不像其他地方是固定两个,所以没有问题)的,所以,要一直往后读,知道空格或者字符串的末尾 while (*pstr != ' ' && *pstr) { punc[iRecordNo].strWidePunc[punc[iRecordNo].iCount][i] = *pstr; i++; pstr++; } // 每个中文符号用'\0'隔开 punc[iRecordNo].strWidePunc[punc[iRecordNo].iCount][i] = '\0'; while (*pstr == ' ') pstr++; punc[iRecordNo].iCount++; } iRecordNo++; } } punc[iRecordNo].ASCII = '\0'; fclose(fpDict); FcitxPunc* p = fcitx_utils_malloc0(sizeof(FcitxPunc)); p->langCode = ""; const char* langcode = filename + strlen(PUNC_DICT_FILENAME); if (*langcode == '\0') p->langCode = strdup("C"); else p->langCode = strdup(langcode + 1); p->curPunc = punc; return p; } void FreePunc(FcitxPuncState* puncState) { puncState->curPunc = NULL; FcitxPunc* cur; while (puncState->puncSet) { cur = puncState->puncSet; HASH_DEL(puncState->puncSet, cur); free(cur->langCode); free(cur->curPunc); free(cur); } } static inline int GetPuncWhich(FcitxPuncState* puncState, WidePunc* punc) { FcitxInputContext* ic = FcitxInstanceGetCurrentIC(puncState->owner); if (!ic) return 0; PuncWhich* puncWhich = FcitxInstanceGetICData(puncState->owner, ic, puncState->slot); if (puncWhich->lastPunc != puncState->curPunc) { fcitx_bitset_clear(puncWhich->bitset); puncWhich->lastPunc = puncState->curPunc; } int result = fcitx_bitset_isset(puncWhich->bitset, punc->ASCII) ? 1 : 0; if (result >= punc->iCount) result = 0; return result; } static inline void SetPuncWhich(FcitxPuncState* puncState, WidePunc* punc) { FcitxInputContext* ic = FcitxInstanceGetCurrentIC(puncState->owner); if (!ic) return; PuncWhich* puncWhich = FcitxInstanceGetICData(puncState->owner, ic, puncState->slot); FcitxBitSet* bitset = puncWhich->bitset; if (punc->iCount == 1) fcitx_bitset_unset(bitset, punc->ASCII); else { if (fcitx_bitset_isset(bitset, punc->ASCII)) fcitx_bitset_unset(bitset, punc->ASCII); else fcitx_bitset_set(bitset, punc->ASCII); } } /* * 根据字符得到相应的标点符号 * 如果该字符不在标点符号集中,则返回NULL */ static char* GetPunc(FcitxPuncState *puncState, int iKey) { int iIndex = 0; char *pPunc; WidePunc *curPunc = puncState->curPunc; if (!curPunc) return NULL; while (curPunc[iIndex].ASCII) { if (curPunc[iIndex].ASCII == iKey) { pPunc = curPunc[iIndex].strWidePunc[GetPuncWhich(puncState, &curPunc[iIndex])]; SetPuncWhich(puncState, &curPunc[iIndex]); return pPunc; } iIndex++; } return NULL; } void TogglePuncState(void* arg) { FcitxPuncState* puncState = (FcitxPuncState*)arg; FcitxInstance* instance = puncState->owner; FcitxProfile* profile = FcitxInstanceGetProfile(instance); profile->bUseWidePunc = !profile->bUseWidePunc; FcitxUISetStatusString(puncState->owner, "punc", profile->bUseWidePunc ? _("Full width punct") : _("Latin punct"), _("Toggle Full Width Punctuation")); FcitxProfileSave(profile); } INPUT_RETURN_VALUE TogglePuncStateWithHotkey(void* arg) { FcitxPuncState *puncState = (FcitxPuncState*)arg; FcitxInstance *instance = puncState->owner; FcitxProfile *profile = FcitxInstanceGetProfile(instance); FcitxUIStatus *status = FcitxUIGetStatusByName(instance, "punc"); if (status->visible){ FcitxUIUpdateStatus(instance, "punc"); FcitxFreeDesktopNotifyShowAddonTip( instance, "fcitx-punc-toggle", profile->bUseWidePunc ? "fcitx-punc-active" : "fcitx-punc-inactive", _("Punctuation Support"), profile->bUseWidePunc ? _("Full width punctuations are used.") : _("Latin punctuations are used.")); return IRV_DO_NOTHING; } else { return IRV_TO_PROCESS; } } boolean GetPuncState(void* arg) { FcitxPuncState* puncState = (FcitxPuncState*) arg; FcitxInstance* instance = puncState->owner; FcitxProfile* profile = FcitxInstanceGetProfile(instance); return profile->bUseWidePunc; } void ReloadPunc(void* arg) { FcitxPuncState* puncState = (FcitxPuncState*) arg; FreePunc(puncState); LoadPuncDict(puncState); puncState->enableSmartPunc = getCfgValueBool("sogouEnv.ini", "Genelal:SmartPunc", 1); PuncLanguageChanged(puncState, FcitxInstanceGetContextString(puncState->owner, CONTEXT_IM_LANGUAGE)); } boolean IsHotKeyPunc(FcitxKeySym sym, unsigned int state) { if (FcitxHotkeyIsHotKeySimple(sym, state) && !FcitxHotkeyIsHotKeyDigit(sym, state) && !FcitxHotkeyIsHotKeyLAZ(sym, state) && !FcitxHotkeyIsHotKeyUAZ(sym, state) && !FcitxHotkeyIsHotKey(sym, state, FCITX_SPACE)) return true; return false; } #include "fcitx-punc-ng-addfunctions.h" fcitx-punc-ng-0.1.1~git20161101/src/punc-ng.h000066400000000000000000000033311300576763500202340ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2002~2005 by Yuking * * yuking_net@sohu.com * * * * 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., * * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #ifndef _PUNC_H #define _PUNC_H #define FCITX_PUNC_NAME "fcitx-punc" #define FCITX_PUNC_GETPUNC 0 #define FCITX_PUNC_GETPUNC_RETURNTYPE char* #define FCITX_PUNC_GETPUNC2 1 #define FCITX_PUNC_GETPUNC2_RETURNTYPE void* #endif // kate: indent-mode cstyle; space-indent on; indent-width 0;