chore: prepare for Savannah
continuous-integration/drone Build is passing
Details
continuous-integration/drone Build is passing
Details
This commit is contained in:
commit
d748d8972e
|
@ -0,0 +1,26 @@
|
|||
#
|
||||
# Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
#
|
||||
# Copying and distribution of this file, with or without modification, are
|
||||
# permitted in any medium without royalty, provided the copyright notice and
|
||||
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||
#
|
||||
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: pureos/byzantium
|
||||
commands:
|
||||
- apt -y update
|
||||
- apt -y install
|
||||
build-essential pkg-config autoconf automake libtool
|
||||
autoconf-archive dejagnu texinfo libreadline-dev
|
||||
- autoreconf -i && mkdir build && cd build
|
||||
- ../configure --with-readline --without-rime --enable-debug
|
||||
CFLAGS='-O0 -g -std=c99 -Wall -Wextra -Wpedantic -Wshadow'
|
||||
CPPFLAGS='-D_POSIX_C_SOURCE=200112L'
|
||||
- make
|
||||
- make check
|
|
@ -0,0 +1,34 @@
|
|||
#
|
||||
# Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
#
|
||||
# Copying and distribution of this file, with or without modification, are
|
||||
# permitted in any medium without royalty, provided the copyright notice and
|
||||
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||
#
|
||||
|
||||
# Generated by devel tools
|
||||
\#*#
|
||||
*~
|
||||
*.swp
|
||||
.ccls
|
||||
.ccls-cache/
|
||||
.idea/
|
||||
.vscode/
|
||||
|
||||
# Generated by the build system
|
||||
aclocal.m4
|
||||
autom4te.cache/
|
||||
autoscan.log
|
||||
compile
|
||||
config.guess
|
||||
config.h.in
|
||||
config.sub
|
||||
configure
|
||||
depcomp
|
||||
install-sh
|
||||
ltmain.sh
|
||||
Makefile.in
|
||||
missing
|
||||
|
||||
# Where we invoke `configure' during development
|
||||
build/
|
|
@ -0,0 +1,674 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. 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
|
||||
them 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 prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. 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.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey 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;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If 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 convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU 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 that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
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.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
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.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
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
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
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, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program 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, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU 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 Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
|
@ -0,0 +1,48 @@
|
|||
<!--
|
||||
Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
|
||||
Copying and distribution of this file, with or without modification, are
|
||||
permitted in any medium without royalty, provided the copyright notice and
|
||||
this notice are preserved. This file is offered as-is, without any warranty.
|
||||
-->
|
||||
|
||||
|
||||
Prerequisites
|
||||
-------------
|
||||
|
||||
Runtime requirements:
|
||||
- POSIX.1-2001 compliant operating system
|
||||
- GNU Readline (optional)
|
||||
|
||||
Build tools:
|
||||
- GNU Autotools (Autoconf, Automake, Libtool, Autoconf Archive)
|
||||
- pkg-config
|
||||
- POSIX-compliant make
|
||||
- C compiler with ISO C99 support
|
||||
- GNU Texinfo (optional, for building the user manual)
|
||||
|
||||
Other softwares (optional):
|
||||
- DejaGnu (for running tests)
|
||||
- Rime IME core library: <https://github.com/rime/librime>
|
||||
|
||||
|
||||
Build and Install
|
||||
-----------------
|
||||
|
||||
ARIF can be built and installed from source using the GNU build system.
|
||||
|
||||
Notable build options:
|
||||
- `--with-readline[=PREFIX]` (default), `--without-readline`
|
||||
* Whether to build the ARIF library with GNU Readline features.
|
||||
- `--enable-arify` (default), `--disable-arify`
|
||||
* Whether to build the `arify` command-line tool.
|
||||
- `--with-rime[=PREFIX]`, `--without-rime` (default)
|
||||
* Whether to build the example Rime IME integration.
|
||||
|
||||
Example shell script:
|
||||
|
||||
autoreconf -i
|
||||
mkdir build && cd build
|
||||
../configure --prefix=${HOME}/.local
|
||||
make
|
||||
make install
|
|
@ -0,0 +1,15 @@
|
|||
#
|
||||
# Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
#
|
||||
# Copying and distribution of this file, with or without modification, are
|
||||
# permitted in any medium without royalty, provided the copyright notice and
|
||||
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||
#
|
||||
|
||||
ACLOCAL_AMFLAGS = -I m4
|
||||
|
||||
SUBDIRS = doc examples include src tests
|
||||
|
||||
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
pkgconfig_DATA = arif.pc
|
|
@ -0,0 +1,27 @@
|
|||
<!--
|
||||
Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
|
||||
Copying and distribution of this file, with or without modification, are
|
||||
permitted in any medium without royalty, provided the copyright notice and
|
||||
this notice are preserved. This file is offered as-is, without any warranty.
|
||||
-->
|
||||
|
||||
|
||||
Introduction
|
||||
------------
|
||||
|
||||
ARIF is an input method framework for GNU Readline.
|
||||
|
||||
ARIF is free software, distributed under the terms of the GNU General Public
|
||||
License, either version 3, or any later version of the license. For more
|
||||
information, see the file 'COPYING'.
|
||||
|
||||
|
||||
Getting Started
|
||||
---------------
|
||||
|
||||
See 'INSTALL.md' for instructions on how to build and install ARIF.
|
||||
|
||||
See the files under 'doc/' for documentation.
|
||||
|
||||
For more information, visit the project homepage: <https://nongnu.org/arif>.
|
|
@ -0,0 +1,23 @@
|
|||
#
|
||||
# Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
#
|
||||
# Copying and distribution of this file, with or without modification, are
|
||||
# permitted in any medium without royalty, provided the copyright notice and
|
||||
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||
#
|
||||
|
||||
package=@PACKAGE@
|
||||
version=@VERSION@
|
||||
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
libdir=@libdir@
|
||||
includedir=@includedir@
|
||||
pkgincludedir=${includedir}/${package}
|
||||
|
||||
Name: ${package}
|
||||
Description: Another Readline Input Framework
|
||||
Version: ${version}
|
||||
URL: https://nongnu.org/arif
|
||||
Libs: -L${libdir} -larif
|
||||
Cflags: -I${includedir} -I${pkgincludedir}
|
|
@ -0,0 +1,103 @@
|
|||
dnl
|
||||
dnl Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
dnl
|
||||
dnl Copying and distribution of this file, with or without modification,
|
||||
dnl are permitted in any medium without royalty,
|
||||
dnl provided the copyright notice and this notice are preserved.
|
||||
dnl This file is offered as-is, without any warranty.
|
||||
dnl
|
||||
|
||||
AC_PREREQ([2.69])
|
||||
AC_INIT([arif], [0.1.0], [arif-devel@nongnu.org])
|
||||
AC_CONFIG_SRCDIR([src/arif.c])
|
||||
AC_CONFIG_HEADERS([config.h])
|
||||
AC_CONFIG_MACRO_DIR([m4])
|
||||
AM_INIT_AUTOMAKE([foreign])
|
||||
PKG_PROG_PKG_CONFIG([0.27])
|
||||
LT_PREREQ([2.4.2])
|
||||
LT_INIT
|
||||
|
||||
# -- Checks for programs --
|
||||
|
||||
AC_PROG_AWK
|
||||
AC_PROG_CC
|
||||
AC_PROG_CPP
|
||||
AC_PROG_INSTALL
|
||||
AC_PROG_LN_S
|
||||
AC_PROG_MAKE_SET
|
||||
AC_PROG_MKDIR_P
|
||||
AC_PROG_SED
|
||||
|
||||
# -- Checks for libraries --
|
||||
|
||||
AC_CHECK_LIB([dl], [dlopen], [
|
||||
AS_VAR_SET([DL_LIBS], [-ldl])
|
||||
])
|
||||
|
||||
ARIF_CHECK_PKG([readline], [>= 6.0], [GNU Readline], [], [
|
||||
AC_DEFINE([HAVE_READLINE], [1], [Define to 1 if you have GNU Readline.])
|
||||
])
|
||||
AM_CONDITIONAL([BUILD_ARIF_READLINE], [test x${with_readline} != xno])
|
||||
|
||||
ARIF_CHECK_PKG([rime], [>= 1.7], [Rime Input Method Engine], [
|
||||
AS_VAR_SET([with_rime], [no])
|
||||
], [
|
||||
AC_DEFINE([HAVE_RIME], [1],
|
||||
[Define to 1 if you have the Rime Input Method Engine.])
|
||||
])
|
||||
AM_CONDITIONAL([BUILD_ARIF_RIME], [test x${with_rime} != xno])
|
||||
|
||||
# -- Checks for features --
|
||||
|
||||
ARIF_ARG_ENABLE([arif-debug], [no], [debugging features for ARIF], [], [
|
||||
AC_DEFINE([ARIF_DEBUG], [1],
|
||||
[Define to 1 if ARIF debugging is enabled])
|
||||
AS_VAR_SET([enable_debug], [yes])
|
||||
])
|
||||
AM_CONDITIONAL([ENABLE_DEBUG], [test x${enable_debug} = xyes])
|
||||
|
||||
ARIF_ARG_ENABLE([arify], [yes], [the arify command line tool], [], [
|
||||
AS_VAR_IF([with_readline], [no], [
|
||||
AC_MSG_WARN(m4_normalize([
|
||||
The arify command line tool will not be built,
|
||||
as the ARIF library is configured without GNU Readline.
|
||||
]))
|
||||
AS_VAR_SET([enable_arify], [no])
|
||||
])
|
||||
])
|
||||
AM_CONDITIONAL([BUILD_ARIFY], [test x${enable_arify} != xno])
|
||||
|
||||
# -- Checks for compiler builtins and attributes --
|
||||
|
||||
ARIF_TRY_APPLY([AX_GCC_FUNC_ATTRIBUTE],
|
||||
[constructor], [destructor], [noreturn])
|
||||
ARIF_TRY_APPLY([AX_GCC_VAR_ATTRIBUTE],
|
||||
[unused])
|
||||
|
||||
# -- Checks for header files --
|
||||
|
||||
AC_CHECK_HEADERS([fcntl.h strings.h unistd.h])
|
||||
|
||||
# -- Checks for typedefs, structures, and compiler characteristics --
|
||||
|
||||
AC_CHECK_HEADER_STDBOOL
|
||||
AC_C_INLINE
|
||||
AC_TYPE_SIZE_T
|
||||
|
||||
# -- Checks for library functions.
|
||||
AC_FUNC_MALLOC
|
||||
AC_FUNC_REALLOC
|
||||
AC_CHECK_FUNCS([atexit memchr strcasecmp])
|
||||
|
||||
# -- Output --
|
||||
|
||||
AC_CONFIG_FILES([
|
||||
Makefile
|
||||
doc/Makefile
|
||||
examples/Makefile
|
||||
include/Makefile
|
||||
src/Makefile
|
||||
tests/Makefile
|
||||
arif.pc
|
||||
])
|
||||
AC_OUTPUT
|
|
@ -0,0 +1,13 @@
|
|||
#
|
||||
# Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
#
|
||||
# Copying and distribution of this file, with or without modification, are
|
||||
# permitted in any medium without royalty, provided the copyright notice and
|
||||
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||
#
|
||||
|
||||
*.info
|
||||
mdate-sh
|
||||
stamp-vti
|
||||
texinfo.tex
|
||||
version.texi
|
|
@ -0,0 +1,27 @@
|
|||
#
|
||||
# Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
#
|
||||
# Copying and distribution of this file, with or without modification, are
|
||||
# permitted in any medium without royalty, provided the copyright notice and
|
||||
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||
#
|
||||
|
||||
info_TEXINFOS = arif.texi
|
||||
dist_man1_MANS =
|
||||
dist_man3_MANS = arif_ctx_create.3 \
|
||||
arif_ctx_destroy.3 \
|
||||
arif_fetch.3 \
|
||||
arif_query.3 \
|
||||
arif_select_page.3 \
|
||||
arif_set_engine.3
|
||||
|
||||
arif_TEXINFOS = fdl.texi
|
||||
|
||||
|
||||
if BUILD_ARIF_READLINE
|
||||
|
||||
dist_man1_MANS += arify.1
|
||||
dist_man3_MANS += arif_rl_complete.3 \
|
||||
arif_rl_display.3
|
||||
|
||||
endif # BUILD_ARIF_READLINE
|
|
@ -0,0 +1,315 @@
|
|||
\input texinfo @c -*-texinfo-*-
|
||||
|
||||
@c %**start of header
|
||||
@setfilename arif.info
|
||||
@include version.texi
|
||||
@settitle ARIF User Manual
|
||||
@c %**end of header
|
||||
|
||||
@macro manpage {name, section, url}
|
||||
@uref{\url\,, @code{\name\(\section\)}}
|
||||
@end macro
|
||||
|
||||
@macro arifmanpage {name, section}
|
||||
@manpage{\name\, \section\, /arif/man-pages/man\section\/\name\.\section\.html}
|
||||
@end macro
|
||||
|
||||
@macro posixmanpage {name, section}
|
||||
@manpage{\name\, \section\,
|
||||
https://pubs.opengroup.org/onlinepubs/9699919799/functions/\name\.html}
|
||||
@end macro
|
||||
|
||||
@tex
|
||||
\global\def\linkcolor{0 0 1}
|
||||
\global\def\urlcolor{0 0 1}
|
||||
\global\urefurlonlylinktrue
|
||||
@end tex
|
||||
|
||||
@copying
|
||||
This manual is for ARIF (Another Readline Input Framework),
|
||||
version @value{VERSION}.
|
||||
|
||||
Copyright @copyright{} 2023 CismonX <admin@@cismon.net>
|
||||
|
||||
@quotation
|
||||
Permission is granted to copy, distribute and/or modify this document
|
||||
under the terms of the GNU Free Documentation License, Version 1.3
|
||||
or any later version published by the Free Software Foundation;
|
||||
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
|
||||
Texts. A copy of the license is included in the section entitled
|
||||
``GNU Free Documentation License''.
|
||||
@end quotation
|
||||
@end copying
|
||||
|
||||
@titlepage
|
||||
@title ARIF
|
||||
@subtitle Another Readline Input Framework, version @value{VERSION}
|
||||
@author CismonX
|
||||
|
||||
@page
|
||||
@vskip 0pt plus 1filll
|
||||
@insertcopying
|
||||
|
||||
@end titlepage
|
||||
|
||||
|
||||
@summarycontents
|
||||
@contents
|
||||
|
||||
@ifnottex
|
||||
@node Top
|
||||
@top ARIF
|
||||
|
||||
@insertcopying
|
||||
|
||||
@end ifnottex
|
||||
|
||||
|
||||
@menu
|
||||
@ifhtml
|
||||
Chapters
|
||||
@end ifhtml
|
||||
* Overview:: About the ARIF project.
|
||||
* ARIF Library:: Using the ARIF library.
|
||||
* @code{arify}:: Using the @code{arify} command line tool.
|
||||
|
||||
Appendices
|
||||
* General Index:: Index of general concepts of ARIF.
|
||||
* GNU Free Documentation License:: Copying conditions of this manual.
|
||||
@end menu
|
||||
|
||||
|
||||
@node Overview
|
||||
@chapter Overview
|
||||
|
||||
ARIF (Another Readline Input Framework) is an input method framework for
|
||||
GNU Readline.
|
||||
|
||||
The ARIF project codebase is mainly comprised of two parts: The ARIF library
|
||||
(@code{libarif}), which provides C API to communicate with
|
||||
input method engines; and the @code{arify} command-line tool, which can make
|
||||
ARIF library features available to existing Readline programs.
|
||||
|
||||
@menu
|
||||
@ifhtml
|
||||
Sections
|
||||
@end ifhtml
|
||||
* Why ARIF:: Why would I use ARIF.
|
||||
* Contributing:: Contribute to ARIF.
|
||||
@end menu
|
||||
|
||||
|
||||
@node Why ARIF
|
||||
@section Why ARIF
|
||||
|
||||
ARIF cannot, and does not try to compete with modern input method frameworks
|
||||
like IBus and Fcitx, which are way more mature, and supports more features.
|
||||
|
||||
Instead, ARIF aims to provide a lightweight, portable and minimalist solution
|
||||
that can serve as a last resort. Particularly, ARIF does not depend on
|
||||
GUI toolkits like GTK or Qt (whereas most input method frameworks choose so),
|
||||
but instead focuses on line editors like GNU Readline (which has stable API
|
||||
and good portability).
|
||||
|
||||
Let us suppose that you're SSH'ing to your PC from a friend's to get some
|
||||
urgent work done, but unfortunately there isn't any input method that you're
|
||||
familiar with installed on his/her PC. In situations like that, ARIF may be
|
||||
a good option.
|
||||
|
||||
Also, if you prefer a ``uniform user experience'' when using Readline programs,
|
||||
you may choose ARIF over GUI-based input method frameworks (just like why
|
||||
Emacs users may choose @uref{https://github.com/tumashu/pyim,, pyim}).
|
||||
|
||||
|
||||
@node Contributing
|
||||
@section Contributing
|
||||
|
||||
The ARIF project is hosted on Savannah. Contribute to ARIF by writing to
|
||||
one of the mailing lists
|
||||
@uref{https://savannah.nongnu.org/mail/?group=arif, here}.
|
||||
|
||||
Currently ARIF is considered experimental, and is not ready for open
|
||||
collaboration. However, feel free to report bugs and request for new features.
|
||||
Other discussions are also welcomed.
|
||||
|
||||
|
||||
@node ARIF Library
|
||||
@chapter The ARIF Library
|
||||
|
||||
The ARIF library API is separated into three parts: the base, frontend and
|
||||
engine API.
|
||||
|
||||
@cindex ARIF Library Base API
|
||||
The base API manages input contexts and candidate pages, and acts as a bridge
|
||||
between the frontend and the engine.
|
||||
See the following manual pages for details.
|
||||
|
||||
@itemize @bullet
|
||||
@item @arifmanpage{arif_ctx_create, 3}
|
||||
@item @arifmanpage{arif_ctx_destroy, 3}
|
||||
@item @arifmanpage{arif_set_engine, 3}
|
||||
@item @arifmanpage{arif_query, 3}
|
||||
@item @arifmanpage{arif_fetch, 3}
|
||||
@item @arifmanpage{arif_select_page, 3}
|
||||
@end itemize
|
||||
|
||||
@menu
|
||||
@ifhtml
|
||||
Sections
|
||||
@end ifhtml
|
||||
* Frontends:: Frontend implementations of ARIF.
|
||||
* Engines:: Implementing an engine for ARIF.
|
||||
@end menu
|
||||
|
||||
|
||||
@node Frontends
|
||||
@section Frontends
|
||||
|
||||
An ARIF frontend determines how to fetch and interpret user input, and
|
||||
how to present candidates to users.
|
||||
|
||||
@cindex ARIF Library Readline Frontend API
|
||||
The ARIF library already comes with a frontend based on GNU Readline's
|
||||
completion API. See the manual pages for the following functions:
|
||||
|
||||
@itemize @bullet
|
||||
@item @arifmanpage{arif_rl_complete, 3}
|
||||
@item @arifmanpage{arif_rl_display, 3}
|
||||
@end itemize
|
||||
|
||||
ARIF is designed to (hopefully) cope with any line editor, not Readline
|
||||
in particular. You can implement your own frontend if Readline is not your
|
||||
cup of tea.
|
||||
|
||||
More frontends (e.g. @uref{https://sites.astro.caltech.edu/~mcs/tecla,, tecla},
|
||||
@uref{https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html,, ZLE}) may
|
||||
be supported in the future.
|
||||
|
||||
|
||||
@node Engines
|
||||
@section Engines
|
||||
|
||||
An ARIF engine's responsibility is to generate candidates from a given
|
||||
input text, presumably by communicating with an actual input method engine.
|
||||
The manual page for @arifmanpage{arif_set_engine, 3} contains a detailed
|
||||
description for how to implement an ARIF engine.
|
||||
|
||||
The ARIF project codebase contains an example engine implementation,
|
||||
powered by the @uref{https://github.com/rime/librime, Rime IME core library}.
|
||||
See the @arifmanpage{arif_rime, 3} manual page for details.
|
||||
|
||||
|
||||
@node @code{arify}
|
||||
@chapter The @code{arify} Command Line Tool
|
||||
|
||||
The @code{arify} command-line tool, implemented on top of the ARIF library,
|
||||
can be used to make ARIF features available to existing programs, without the
|
||||
need to modify, rebuild or write plugins for those programs.
|
||||
|
||||
See the @arifmanpage{arify, 1} manual page for detailed usage of @code{arify}.
|
||||
|
||||
|
||||
@menu
|
||||
@ifhtml
|
||||
Sections
|
||||
@end ifhtml
|
||||
* Engine Names:: Naming convention for engines.
|
||||
* Readline Frontend:: Using @code{arify}'s Readline frontend.
|
||||
* Limitations:: When @code{arify} does not work.
|
||||
@end menu
|
||||
|
||||
|
||||
@node Engine Names
|
||||
@section Engine Names
|
||||
|
||||
The @code{arify} command-line tool loads engine implementations from shared
|
||||
libraries. Each engine name passed to @code{arify} should comply with the
|
||||
following format:
|
||||
|
||||
@example
|
||||
$@{lib_name@}:$@{symbol_name@}
|
||||
@end example
|
||||
|
||||
The @code{$@{lib_name@}} is the path to the shared library file containing
|
||||
the engine implementation. This name is used as the first argument to pass to
|
||||
@posixmanpage{dlopen, 3}.
|
||||
|
||||
The @code{$@{symbol_name@}} is the name of the @code{struct arif_engine const}
|
||||
where the engine is implemented. This name is used as the second argument to
|
||||
pass to @posixmanpage{dlsym, 3}.
|
||||
|
||||
If the two names match the following pattern, a @code{$@{short_name@}} can be
|
||||
used instead of the full name:
|
||||
|
||||
@example
|
||||
lib$@{short_name@}$@{shlib_suffix@}:arif_$@{short_name@}_engine
|
||||
@end example
|
||||
|
||||
Where @code{$@{shlib_suffix@}} is the common name suffix for shared library
|
||||
files on the current platform (e.g. @code{.so} on GNU/Linux).
|
||||
|
||||
|
||||
@node Readline Frontend
|
||||
@section Readline Frontend
|
||||
|
||||
@cindex New Readline Functions
|
||||
In addition to @code{libarif}'s Readline features, @code{arify} also provides
|
||||
the following Readline functions:
|
||||
|
||||
@itemize @bullet
|
||||
@item @code{arify-toggle}: Turn on/off input method engine. When turned on,
|
||||
Readline's completion functions will be replaced by those provided by ARIF.
|
||||
When turned off, the previously saved completion functions will be restored.
|
||||
@item @code{arify-engine-info}: Prints information regarding the currently
|
||||
active engine.
|
||||
@item @code{arify-next-engine}: Switch to the next loaded engine. If there are
|
||||
no more available engines, switch to the first engine instead.
|
||||
@item @code{arify-page-up}, @code{arify-page-down}: Switch to previous/next
|
||||
page of candidates, and display them.
|
||||
@end itemize
|
||||
|
||||
@cindex Example @code{~/.inputrc} Snippet
|
||||
By default, these Readline functions are not bound to any keys. To use them,
|
||||
configure the key bindings from a Readline init file.
|
||||
Here is an example @code{~/.inputrc} snippet:
|
||||
|
||||
@example
|
||||
set show-all-if-ambiguous on
|
||||
|
||||
"\e ": arify-toggle
|
||||
"\e\b": arify-next-engine
|
||||
"\e[5;3~": arify-page-up # M-PgUp
|
||||
"\e[6;3~": arify-page-down # M-PgDn
|
||||
@end example
|
||||
|
||||
|
||||
@node Limitations
|
||||
@section Limitations
|
||||
|
||||
Theoretically @code{arify} should work with most programs with a supported
|
||||
frontend. However, there are situations where it may not work as expected:
|
||||
|
||||
@itemize @bullet
|
||||
@item @code{arify} does not work when @code{LD_PRELOAD} is not functioning.
|
||||
@item @code{arify} may also fail to work, when the program it's working with
|
||||
does fancy things with Readline API (e.g. changing handler functions during
|
||||
user input), which may break the internal states @code{arify} maintains.
|
||||
@end itemize
|
||||
|
||||
Meanwhile, adding support for more frontends may not be as simple (or even
|
||||
possible) as with Readline, due to the way how @code{arify} works.
|
||||
|
||||
|
||||
@node General Index
|
||||
@appendix General Index
|
||||
|
||||
@printindex cp
|
||||
|
||||
|
||||
@node GNU Free Documentation License
|
||||
@appendix GNU Free Documentation License
|
||||
|
||||
@include fdl.texi
|
||||
|
||||
|
||||
@bye
|
|
@ -0,0 +1,96 @@
|
|||
.TH ARIF_CTX_CREATE 3 "Jan 02, 2023" 0.1.0 "ARIF User Manual"
|
||||
.
|
||||
.SH NAME
|
||||
arif_ctx_create - create input context
|
||||
.
|
||||
.SH SYNOPSYS
|
||||
.EX
|
||||
.B #include <arif/arif.h>
|
||||
.PP
|
||||
.B struct arif_ctx *
|
||||
.B arif_ctx_create (
|
||||
.BI " struct arif_opts const *" options
|
||||
.B );
|
||||
.EE
|
||||
.
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.BR arif_ctx_create ()
|
||||
function creates an input context with
|
||||
.IR options .
|
||||
Operations on separate input contexts do not affect each other.
|
||||
.PP
|
||||
If the input context is no longer in use, it should be destroyed with
|
||||
.BR \%arif_ctx_destroy ().
|
||||
.SS Options
|
||||
The
|
||||
.B struct arif_opts
|
||||
type is defined as:
|
||||
.PP
|
||||
.in +4n
|
||||
.EX
|
||||
struct arif_opts {
|
||||
arif_cand_disp_func *disp_cand;
|
||||
int page_size;
|
||||
};
|
||||
.EE
|
||||
.in
|
||||
.PP
|
||||
Member
|
||||
.I disp_cand
|
||||
is the function to generate the text to display for a given candidate.
|
||||
If NULL, a default function (which prepends a bracket-enclosed index number
|
||||
to the text) will be used.
|
||||
.PP
|
||||
Member
|
||||
.I page_size
|
||||
is the number of candidates per page.
|
||||
.SS Candidate display function
|
||||
The
|
||||
.B arif_cand_disp_func
|
||||
type is defined as:
|
||||
.PP
|
||||
.in +4n
|
||||
.EX
|
||||
typedef char *(arif_cand_disp_func) (
|
||||
char *text,
|
||||
int len,
|
||||
int idx,
|
||||
int *display_len_ptr
|
||||
);
|
||||
.EE
|
||||
.in
|
||||
.PP
|
||||
Argument
|
||||
.I text
|
||||
is the candidate's text to replace the original text, and
|
||||
.I len
|
||||
is its length in bytes.
|
||||
.PP
|
||||
Argument
|
||||
.I idx
|
||||
is the candidate's index for the current page, starting at 1.
|
||||
.PP
|
||||
The function should return a
|
||||
.BR malloc ()'ed
|
||||
pointer to the text to display for the candidate, and store
|
||||
its length (in bytes) to
|
||||
.IR display_len_ptr .
|
||||
.
|
||||
.SH RETURN VALUES
|
||||
Returns an opaque pointer to the new input context.
|
||||
On failure, returns NULL.
|
||||
.
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
.PP
|
||||
Permission is granted to copy, distribute and/or modify this document
|
||||
under the terms of the GNU Free Documentation License, Version 1.3
|
||||
or any later version published by the Free Software Foundation;
|
||||
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
|
||||
.PP
|
||||
You should have received a copy of the license along with this document.
|
||||
If not, see <https://www.gnu.org/licenses/fdl-1.3.html>.
|
||||
.
|
||||
.SH SEE ALSO
|
||||
.BR arif_ctx_destroy (3)
|
|
@ -0,0 +1,39 @@
|
|||
.TH ARIF_CTX_DESTROY 3 "Jan 02, 2023" 0.1.0 "ARIF User Manual"
|
||||
.
|
||||
.SH NAME
|
||||
arif_ctx_destroy - destroy input context
|
||||
.
|
||||
.SH SYNOPSYS
|
||||
.EX
|
||||
.B #include <arif/arif.h>
|
||||
.PP
|
||||
.B void
|
||||
.B arif_ctx_destroy (
|
||||
.BI " struct arif_ctx *" ctx
|
||||
.B );
|
||||
.EE
|
||||
.
|
||||
.SH DESCRIPTION
|
||||
Function
|
||||
.BR arif_ctx_destroy ()
|
||||
destroys the input context referred to by
|
||||
.IR ctx .
|
||||
It must not be used afterwards.
|
||||
.PP
|
||||
If
|
||||
.I ctx
|
||||
is NULL, this function has no effect.
|
||||
.
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
.PP
|
||||
Permission is granted to copy, distribute and/or modify this document
|
||||
under the terms of the GNU Free Documentation License, Version 1.3
|
||||
or any later version published by the Free Software Foundation;
|
||||
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
|
||||
.PP
|
||||
You should have received a copy of the license along with this document.
|
||||
If not, see <https://www.gnu.org/licenses/fdl-1.3.html>.
|
||||
.
|
||||
.SH SEE ALSO
|
||||
.BR arif_ctx_create (3)
|
|
@ -0,0 +1,98 @@
|
|||
.TH ARIF_FETCH 3 "Jan 02, 2023" 0.1.0 "ARIF User Manual"
|
||||
.
|
||||
.SH NAME
|
||||
arif_fetch - fetch candidates
|
||||
.
|
||||
.SH SYNOPSYS
|
||||
.EX
|
||||
.B #include <arif/arif.h>
|
||||
.PP
|
||||
.B int
|
||||
.B arif_fetch (
|
||||
.BI " struct arif_ctx *" ctx ,
|
||||
.BI " struct arif_cand const **" candidates_ptr
|
||||
.B );
|
||||
.EE
|
||||
.
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.BR arif_fetch ()
|
||||
function fetches all candidates from the current page of input context
|
||||
.I ctx
|
||||
into an array of
|
||||
.BR "struct arif_cand" ,
|
||||
and stores a pointer to that array into
|
||||
.IR candidates_ptr .
|
||||
The array is valid until the next time
|
||||
.BR arif_query ()
|
||||
is called with new input text.
|
||||
.SS Candidates
|
||||
A candidate is a piece of text generated by an IME that is meant to replace
|
||||
part of the original input text.
|
||||
.PP
|
||||
The
|
||||
.B struct arif_cand
|
||||
type is defined as:
|
||||
.PP
|
||||
.in +4n
|
||||
.EX
|
||||
struct arif_cand {
|
||||
char const *text;
|
||||
int len;
|
||||
int replace_len;
|
||||
char const *transform;
|
||||
int transform_len;
|
||||
char const *display;
|
||||
int display_len;
|
||||
};
|
||||
.EE
|
||||
.in
|
||||
.PP
|
||||
The
|
||||
.I text
|
||||
member is the actual text of the candidate, and
|
||||
.I len
|
||||
is its length in bytes.
|
||||
.PP
|
||||
Member
|
||||
.I replace_len
|
||||
is the number of leading bytes of the original text that are meant to
|
||||
be replaced by the candidate.
|
||||
.PP
|
||||
Should the original text passed to
|
||||
.BR arif_query ()
|
||||
be transformed into another text when selecting this candidate, the resulting
|
||||
text is put into
|
||||
.IR transform ,
|
||||
and
|
||||
.I transform_len
|
||||
is its length in bytes.
|
||||
Otherwise,
|
||||
.I transform
|
||||
value is NULL.
|
||||
.PP
|
||||
The
|
||||
.I display
|
||||
member is the text to display when listing candidates for the user to choose.
|
||||
Member
|
||||
.I display_len
|
||||
is its length in bytes.
|
||||
.
|
||||
.SH RETURN VALUES
|
||||
Returns the number of items in the array stored to
|
||||
.IR candidates_ptr .
|
||||
.
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
.PP
|
||||
Permission is granted to copy, distribute and/or modify this document
|
||||
under the terms of the GNU Free Documentation License, Version 1.3
|
||||
or any later version published by the Free Software Foundation;
|
||||
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
|
||||
.PP
|
||||
You should have received a copy of the license along with this document.
|
||||
If not, see <https://www.gnu.org/licenses/fdl-1.3.html>.
|
||||
.
|
||||
.SH SEE ALSO
|
||||
.BR arif_query (3),
|
||||
.BR arif_select_page (3)
|
|
@ -0,0 +1,97 @@
|
|||
.TH ARIF_QUERY 3 "Jan 02, 2023" 0.1.0 "ARIF User Manual"
|
||||
.
|
||||
.SH NAME
|
||||
arif_query - query for candidates
|
||||
.
|
||||
.SH SYNOPSYS
|
||||
.EX
|
||||
.B #include <arif/arif.h>
|
||||
.PP
|
||||
.B int
|
||||
.B arif_query (
|
||||
.BI " struct arif_ctx *" ctx ,
|
||||
.BI " char const *" line ,
|
||||
.BI " int " offset ,
|
||||
.BI " int " len
|
||||
.B );
|
||||
.EE
|
||||
.
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.BR arif_query ()
|
||||
function queries the input method engine associated with input context
|
||||
.IR ctx
|
||||
for candidates to replace the given input text
|
||||
.IR line .
|
||||
Candidates can be later obtained using the
|
||||
.BR \%arif_fetch ()
|
||||
function.
|
||||
.PP
|
||||
The actual text to query for candidates starts at
|
||||
.I offset
|
||||
byte offset, and has a length of
|
||||
.I len
|
||||
bytes.
|
||||
The IME may look at the text before
|
||||
.IR offset ,
|
||||
so it should be valid (instead of garbage data).
|
||||
.PP
|
||||
The caller is free to modify or deallocate
|
||||
.I line
|
||||
after the
|
||||
.BR arif_query ()
|
||||
call, as the function keeps its copy inside
|
||||
.IR ctx .
|
||||
.PP
|
||||
If the text referred to by
|
||||
.I line
|
||||
and
|
||||
.I len
|
||||
is empty, or identical to the previous text, this function has no effect.
|
||||
.SS Trailing digits
|
||||
If the input text contains trailing ASCII digits, the function removes them
|
||||
(by modifying
|
||||
.IR len )
|
||||
before sending the text to IME.
|
||||
Meanwhile, if the remaining text is identical to the text from the last
|
||||
query, the aforementioned digits are converted into an integer and then
|
||||
used as an index to select a candidate from the current page.
|
||||
.PP
|
||||
When a candidate is selected, candidates from the previous query are replaced
|
||||
by a single candidate page containing only the selected candidate.
|
||||
If the integer cannot be used to select a valid candidate, it is ignored.
|
||||
.PP
|
||||
See the "Inlined candidate selection" subsection in NOTES for the rationale
|
||||
behind this.
|
||||
.
|
||||
.SH RETURN VALUES
|
||||
Returns the byte length of the input text after removing the trailing digits.
|
||||
.
|
||||
.SH NOTES
|
||||
.SS Inlined candidate selection
|
||||
In a typical input method framework, numeric keys are used for candidate
|
||||
selection.
|
||||
The ARIF library, however, is designed to work with line editors like
|
||||
GNU Readline, where numeric keys serve the same purpose as alphabet keys.
|
||||
.PP
|
||||
In an
|
||||
.BR arif_query ()
|
||||
function call, a candidate selection request can be inlined into the
|
||||
input text.
|
||||
This approach works well with Readline's completion API, and eliminates the
|
||||
need to hack the keymap.
|
||||
.
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
.PP
|
||||
Permission is granted to copy, distribute and/or modify this document
|
||||
under the terms of the GNU Free Documentation License, Version 1.3
|
||||
or any later version published by the Free Software Foundation;
|
||||
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
|
||||
.PP
|
||||
You should have received a copy of the license along with this document.
|
||||
If not, see <https://www.gnu.org/licenses/fdl-1.3.html>.
|
||||
.
|
||||
.SH SEE ALSO
|
||||
.BR arif_fetch (3),
|
||||
.BR arif_select_page (3)
|
|
@ -0,0 +1,65 @@
|
|||
.TH ARIF_RL_COMPLETE 3 "Jan 02, 2023" 0.1.0 "ARIF User Manual"
|
||||
.
|
||||
.SH NAME
|
||||
arif_rl_complete - generate Readline completion candidates
|
||||
.
|
||||
.SH SYNOPSYS
|
||||
.EX
|
||||
.B #include <arif/arif_rl.h>
|
||||
.PP
|
||||
.B char **
|
||||
.B arif_rl_complete (
|
||||
.BI " struct arif_ctx *" ctx ,
|
||||
.BI " char *" text ,
|
||||
.BI " int " start ,
|
||||
.BI " int " end
|
||||
.B );
|
||||
.EE
|
||||
.
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.BR arif_rl_complete ()
|
||||
function generates Readline completion candidates for the given
|
||||
.I text
|
||||
from offset
|
||||
.I start
|
||||
to
|
||||
.IR end ,
|
||||
by querying the input method engine associated with input context
|
||||
.IR ctx .
|
||||
.PP
|
||||
This function is intended be called from within a custom Readline
|
||||
.IR rl_attempted_completion_function ,
|
||||
with arguments
|
||||
.IR text ,
|
||||
.I start
|
||||
and
|
||||
.I end
|
||||
passed as-is.
|
||||
.
|
||||
.SH RETURN VALUES
|
||||
Returns NULL when there are no completion candidates.
|
||||
Otherwise, returns an array of NUL-terminated strings of candidate text.
|
||||
NULL denotes the end of the array.
|
||||
.PP
|
||||
The return value is intended to be used as the return value of an
|
||||
.IR rl_attempted_completion_function .
|
||||
If used otherwise, the array and each of the strings should be deallocated with
|
||||
.BR free ()
|
||||
after use.
|
||||
.
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
.PP
|
||||
Permission is granted to copy, distribute and/or modify this document
|
||||
under the terms of the GNU Free Documentation License, Version 1.3
|
||||
or any later version published by the Free Software Foundation;
|
||||
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
|
||||
.PP
|
||||
You should have received a copy of the license along with this document.
|
||||
If not, see <https://www.gnu.org/licenses/fdl-1.3.html>.
|
||||
.
|
||||
.SH SEE ALSO
|
||||
.BR arif_query (3),
|
||||
.BR arif_fetch (3),
|
||||
.BR readline (3)
|
|
@ -0,0 +1,50 @@
|
|||
.TH ARIF_RL_DISPLAY 3 "Jan 02, 2023" 0.1.0 "ARIF User Manual"
|
||||
.
|
||||
.SH NAME
|
||||
arif_rl_display - display Readline completion candidates
|
||||
.
|
||||
.SH SYNOPSYS
|
||||
.EX
|
||||
.B #include <arif/arif_rl.h>
|
||||
.PP
|
||||
.B void
|
||||
.B arif_rl_display (
|
||||
.BI " struct arif_ctx *" ctx ,
|
||||
.BI " char **" matches ,
|
||||
.BI " int " num ,
|
||||
.BI " int " max_len
|
||||
.B );
|
||||
.EE
|
||||
.
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.BR arif_rl_display ()
|
||||
function fetches the current page of candidates from input context
|
||||
.IR ctx ,
|
||||
and prints their display text with Readline's
|
||||
.BR rl_display_match_list ()
|
||||
function.
|
||||
.PP
|
||||
This function is intended be called from within a custom Readline
|
||||
.I rl_completion_display_matches_hook
|
||||
function, with arguments
|
||||
.IR matches ,
|
||||
.I num
|
||||
and
|
||||
.I max_len
|
||||
passed as-is.
|
||||
.
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
.PP
|
||||
Permission is granted to copy, distribute and/or modify this document
|
||||
under the terms of the GNU Free Documentation License, Version 1.3
|
||||
or any later version published by the Free Software Foundation;
|
||||
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
|
||||
.PP
|
||||
You should have received a copy of the license along with this document.
|
||||
If not, see <https://www.gnu.org/licenses/fdl-1.3.html>.
|
||||
.
|
||||
.SH SEE ALSO
|
||||
.BR arif_fetch (3),
|
||||
.BR readline (3)
|
|
@ -0,0 +1,53 @@
|
|||
.TH ARIF_SELECT_PAGE 3 "Jan 02, 2023" 0.1.0 "ARIF User Manual"
|
||||
.
|
||||
.SH NAME
|
||||
arif_select_page - select the page of candidates
|
||||
.
|
||||
.SH SYNOPSYS
|
||||
.EX
|
||||
.B #include <arif/arif.h>
|
||||
.PP
|
||||
.B int
|
||||
.B arif_select_page (
|
||||
.BI " struct arif_ctx *" ctx ,
|
||||
.BI " int " idx
|
||||
.B );
|
||||
.EE
|
||||
.
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.BR arif_select_page ()
|
||||
function changes the input context
|
||||
.IR ctx 's
|
||||
current page of candidates to the page referred to by
|
||||
.IR idx .
|
||||
.PP
|
||||
The argument
|
||||
.I idx
|
||||
can either be a specific page number (starting at 1), or a relative page
|
||||
(-1 for the previous page, and 0 for the next page).
|
||||
.PP
|
||||
If the page does not exist, this function has no effect.
|
||||
.
|
||||
.SH RETURN VALUES
|
||||
Returns the page number if the given page exists, or -1 if otherwise.
|
||||
.
|
||||
.SH NOTES
|
||||
.SS Default page
|
||||
If the
|
||||
.BR arif_select_page ()
|
||||
function is not yet called after a query, the first page is the current page.
|
||||
.
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
.PP
|
||||
Permission is granted to copy, distribute and/or modify this document
|
||||
under the terms of the GNU Free Documentation License, Version 1.3
|
||||
or any later version published by the Free Software Foundation;
|
||||
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
|
||||
.PP
|
||||
You should have received a copy of the license along with this document.
|
||||
If not, see <https://www.gnu.org/licenses/fdl-1.3.html>.
|
||||
.
|
||||
.SH SEE ALSO
|
||||
.BR arif_query (3)
|
|
@ -0,0 +1,234 @@
|
|||
.TH ARIF_SET_ENGINE 3 "Jan 02, 2023" 0.1.0 "ARIF User Manual"
|
||||
.
|
||||
.SH NAME
|
||||
arif_set_engine - set input method engine
|
||||
.
|
||||
.SH SYNOPSYS
|
||||
.EX
|
||||
.B #include <arif/arif.h>
|
||||
.PP
|
||||
.B void
|
||||
.B arif_set_engine (
|
||||
.BI " struct arif_ctx *" ctx ,
|
||||
.BI " struct arif_engine const *" engine ,
|
||||
.BI " void *" engine_data
|
||||
.B );
|
||||
.EE
|
||||
.
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.BR arif_set_engine ()
|
||||
function changes the input context
|
||||
.IR ctx 's
|
||||
current input method engine and its associated data pointer to
|
||||
.I \%engine
|
||||
and
|
||||
.IR \%engine_data .
|
||||
It also resets the internal state of
|
||||
.IR ctx .
|
||||
.PP
|
||||
Passing NULL
|
||||
to
|
||||
.I engine
|
||||
is allowed.
|
||||
See the "Input context without engine" subsection in NOTES for details.
|
||||
.PP
|
||||
After setting the engine, it must be initialized before calling
|
||||
.BR arif_query ()
|
||||
with
|
||||
.IR ctx .
|
||||
.SS Input method engines
|
||||
The
|
||||
.B struct arif_engine
|
||||
type defines a few functions for ARIF to communite with an input method engine.
|
||||
.PP
|
||||
.in +4n
|
||||
.EX
|
||||
struct arif_engine {
|
||||
arif_engine_init_func *init;
|
||||
arif_engine_finalize_func *finalize;
|
||||
arif_engine_info_func *info;
|
||||
arif_engine_query_func *query;
|
||||
};
|
||||
.EE
|
||||
.in
|
||||
.PP
|
||||
Only the
|
||||
.I query
|
||||
function is used by the ARIF library.
|
||||
It's up to the library user to call the other functions when needed.
|
||||
.SS Engine initialization
|
||||
If an input method engine needs to be initialized before use, the
|
||||
.I init
|
||||
function must be implemented.
|
||||
Otherwise, it should be NULL.
|
||||
.PP
|
||||
.in +4n
|
||||
.EX
|
||||
typedef int (arif_engine_init_func) (
|
||||
void const *args,
|
||||
void **engine_data_ptr
|
||||
);
|
||||
.EE
|
||||
.in
|
||||
.PP
|
||||
Extra info can be passed into the initializer function through
|
||||
.IR args .
|
||||
.PP
|
||||
If initialization is successful, the function must return 0.
|
||||
Optionally, it can store a pointer to
|
||||
.IR engine_data_ptr ,
|
||||
which will be passed as an argument on subsequent engine function calls.
|
||||
.PP
|
||||
If initialization fails, the function must return a non-zero value.
|
||||
.SS Engine finalization
|
||||
If not NULL, the
|
||||
.I finalize
|
||||
function is used for cleaning up resources for an engine, when the engine is
|
||||
no longer in use.
|
||||
.PP
|
||||
.in +4n
|
||||
.EX
|
||||
typedef void (arif_engine_finalize_func) (
|
||||
void *engine_data
|
||||
);
|
||||
.EE
|
||||
.in
|
||||
.PP
|
||||
The
|
||||
.I engine_data
|
||||
argument is the pointer stored to
|
||||
.I engine_data_ptr
|
||||
during initialization.
|
||||
.SS Engine info
|
||||
If not NULL, the
|
||||
.I info
|
||||
function is used for retrieving information of an engine.
|
||||
.PP
|
||||
.in +4n
|
||||
.EX
|
||||
typedef void (arif_engine_info_func) (
|
||||
void *engine_data,
|
||||
char const **name_ptr,
|
||||
char const **description_ptr
|
||||
);
|
||||
.EE
|
||||
.in
|
||||
.PP
|
||||
The
|
||||
.I engine_data
|
||||
argument is the pointer stored to
|
||||
.I engine_data_ptr
|
||||
during initialization.
|
||||
.PP
|
||||
The function can store a NUL-terminated string that identifies an engine
|
||||
to
|
||||
.IR name_ptr .
|
||||
It's preferably a short and memorable word (like "pinyin" and "rime").
|
||||
.PP
|
||||
The function can store another NUL-terminated string to
|
||||
.IR description_ptr ,
|
||||
to provide additional information of the engine, such as version,
|
||||
copyright notice, homepage URL, etc.
|
||||
.SS Query engine for candidates
|
||||
The
|
||||
.I query
|
||||
function is used for asking the engine for candidates of an input text.
|
||||
It must not be NULL.
|
||||
.PP
|
||||
.in +4n
|
||||
.EX
|
||||
typedef int (arif_engine_query_func) (
|
||||
void *engine_data,
|
||||
char const *line,
|
||||
int offset,
|
||||
int len,
|
||||
int num_candidates,
|
||||
struct arif_cand const **candidates_ptr
|
||||
);
|
||||
.EE
|
||||
.in
|
||||
.PP
|
||||
The
|
||||
.I engine_data
|
||||
argument is the pointer stored to
|
||||
.I engine_data_ptr
|
||||
during initialization.
|
||||
.PP
|
||||
The
|
||||
.IR line ,
|
||||
.I offset
|
||||
and
|
||||
.I len
|
||||
arguments correspond to the arguments of function
|
||||
.BR arif_query ()
|
||||
with the same name.
|
||||
If
|
||||
.I line
|
||||
is NULL, it means that the caller is asking for more candidates for the
|
||||
previous input text.
|
||||
.PP
|
||||
The
|
||||
.I num_candidates
|
||||
argument is the minimum number of candidates required from the engine.
|
||||
The engine should store the pointer of an array containing at least that many
|
||||
candidates to
|
||||
.IR candidates_ptr ,
|
||||
and return the number of candidates.
|
||||
If returning less than
|
||||
.IR num_candidates ,
|
||||
it indicates that the entire list of candidates is exhausted.
|
||||
The engine should ensure that the memory location referenced by those
|
||||
candidates are valid until the next
|
||||
.I query
|
||||
call with non-NULL
|
||||
.IR line .
|
||||
.PP
|
||||
Note that the engine is not responsible for specifying the display text for a
|
||||
candidate.
|
||||
The
|
||||
.I display
|
||||
and
|
||||
.I display_len
|
||||
members of a candidate should be ignored by the caller.
|
||||
.PP
|
||||
Both
|
||||
.I line
|
||||
and
|
||||
.I candidates_ptr
|
||||
can be NULL, in which case the caller is indicating that a candidate at
|
||||
.I offset
|
||||
is selected with inlined candidate selection (see
|
||||
.BR \%arif_query ()),
|
||||
and the return value is ignored.
|
||||
The engine may make use of this information for purposes like analytics.
|
||||
.
|
||||
.SH NOTES
|
||||
.SS Input context without engine
|
||||
For an input context, when
|
||||
.BR arif_set_engine ()
|
||||
is not yet called, or last called with a NULL
|
||||
.I engine
|
||||
argument, the input context does not have an associated input method engine.
|
||||
.PP
|
||||
In such input contexts, functions other than
|
||||
.BR arif_set_engine ()
|
||||
or
|
||||
.BR arif_ctx_destroy ()
|
||||
must not be called.
|
||||
.
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
.PP
|
||||
Permission is granted to copy, distribute and/or modify this document
|
||||
under the terms of the GNU Free Documentation License, Version 1.3
|
||||
or any later version published by the Free Software Foundation;
|
||||
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
|
||||
.PP
|
||||
You should have received a copy of the license along with this document.
|
||||
If not, see <https://www.gnu.org/licenses/fdl-1.3.html>.
|
||||
.
|
||||
.SH SEE ALSO
|
||||
.BR arif_ctx_destroy (3),
|
||||
.BR arif_fetch (3),
|
||||
.BR arif_query (3)
|
|
@ -0,0 +1,104 @@
|
|||
.TH ARIFY 1 "Jan 02, 2023" 0.1.0 "ARIF User Manual"
|
||||
.
|
||||
.SH NAME
|
||||
arify - execute program with input methods
|
||||
.
|
||||
.SH SYNOPSYS
|
||||
.B arify
|
||||
.RI [ options ]
|
||||
.I pathname
|
||||
.RI [ args ]
|
||||
.
|
||||
.SH DESCRIPTION
|
||||
Executes the program referred to by
|
||||
.IR pathname ,
|
||||
passing
|
||||
.I args
|
||||
as its command-line arguments.
|
||||
.PP
|
||||
If the program uses a line editor supported by ARIF,
|
||||
it will be provided with the ability to interact with input method engines.
|
||||
The exact behaviour depends on the frontend specified.
|
||||
.
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
\fB\-e\fR \fIengines\fR
|
||||
Overrides the ARIFY_ENGINES environment variable with
|
||||
.IR engines .
|
||||
.IP
|
||||
If multiple
|
||||
.BR \-e
|
||||
options are provided, the resulting value is a concatentation of each
|
||||
.IR engines ,
|
||||
with an ASCII Space character as separator.
|
||||
.TP
|
||||
\fB\-f\fR \fIfrontend\fR
|
||||
Overrides the ARIFY_FRONTEND environment variable with
|
||||
.IR frontend .
|
||||
.TP
|
||||
\fB\-l\fR \fIlog-file\fR
|
||||
Overrides the ARIFY_LOG_FILE environment variable with
|
||||
.IR log-file .
|
||||
.TP
|
||||
\fB\-n\fR \fIpage-size\fR
|
||||
Overrides the ARIFY_PAGE_SIZE environment variable with
|
||||
.IR page-size .
|
||||
.TP
|
||||
\fB\-p\fR \fIpreload-library\fR
|
||||
Path to the preload library (e.g. "/usr/local/lib/libarify.so").
|
||||
.IP
|
||||
Default value depends on the specified install directory when building ARIF.
|
||||
.TP
|
||||
\fB\-V\fR
|
||||
Prints the version number of ARIF, and then exits.
|
||||
.
|
||||
.SH EXIT STATUS
|
||||
If an error occurs before
|
||||
.I pathname
|
||||
is executed, the program exits with status 1.
|
||||
Otherwise, the exit status equals to that program's exit status.
|
||||
.
|
||||
.SH ENVIRONMENT
|
||||
.TP
|
||||
.B ARIFY_FRONTEND
|
||||
The frontend program to use.
|
||||
.IP
|
||||
If the variable is unset or empty, value \%"readline" will be used.
|
||||
.TP
|
||||
.B ARIFY_ENGINES
|
||||
Whitespace-separated list of input method engines to use.
|
||||
At least one engine should be specified.
|
||||
.TP
|
||||
.B ARIFY_LOG_FILE
|
||||
Path to the file where error logs (and debug logs, if enabled)
|
||||
will be written to.
|
||||
.IP
|
||||
If the variable is unset or empty, value \%"/dev/null" will be used.
|
||||
.TP
|
||||
.B ARIFY_PAGE_SIZE
|
||||
Maximum number of candidates per page (at most 99).
|
||||
.IP
|
||||
If the variable is unset or empty, value 5 will be used.
|
||||
.
|
||||
.SH NOTES
|
||||
This manual page only contains part of
|
||||
.BR arify 's
|
||||
usage.
|
||||
For anything not covered here, please refer to ARIF's Info entry.
|
||||
.
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
.PP
|
||||
Permission is granted to copy, distribute and/or modify this document
|
||||
under the terms of the GNU Free Documentation License, Version 1.3
|
||||
or any later version published by the Free Software Foundation;
|
||||
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
|
||||
.PP
|
||||
You should have received a copy of the license along with this document.
|
||||
If not, see <https://www.gnu.org/licenses/fdl-1.3.html>.
|
||||
.
|
||||
.SH SEE ALSO
|
||||
.BR arif_set_engine (3),
|
||||
.BR readline (3)
|
||||
.PP
|
||||
The Info entry for ARIF
|
|
@ -0,0 +1,505 @@
|
|||
@c The GNU Free Documentation License.
|
||||
@center Version 1.3, 3 November 2008
|
||||
|
||||
@c This file is intended to be included within another document,
|
||||
@c hence no sectioning command or @node.
|
||||
|
||||
@display
|
||||
Copyright @copyright{} 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
|
||||
@uref{https://fsf.org/}
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
@end display
|
||||
|
||||
@enumerate 0
|
||||
@item
|
||||
PREAMBLE
|
||||
|
||||
The purpose of this License is to make a manual, textbook, or other
|
||||
functional and useful document @dfn{free} in the sense of freedom: to
|
||||
assure everyone the effective freedom to copy and redistribute it,
|
||||
with or without modifying it, either commercially or noncommercially.
|
||||
Secondarily, this License preserves for the author and publisher a way
|
||||
to get credit for their work, while not being considered responsible
|
||||
for modifications made by others.
|
||||
|
||||
This License is a kind of ``copyleft'', which means that derivative
|
||||
works of the document must themselves be free in the same sense. It
|
||||
complements the GNU General Public License, which is a copyleft
|
||||
license designed for free software.
|
||||
|
||||
We have designed this License in order to use it for manuals for free
|
||||
software, because free software needs free documentation: a free
|
||||
program should come with manuals providing the same freedoms that the
|
||||
software does. But this License is not limited to software manuals;
|
||||
it can be used for any textual work, regardless of subject matter or
|
||||
whether it is published as a printed book. We recommend this License
|
||||
principally for works whose purpose is instruction or reference.
|
||||
|
||||
@item
|
||||
APPLICABILITY AND DEFINITIONS
|
||||
|
||||
This License applies to any manual or other work, in any medium, that
|
||||
contains a notice placed by the copyright holder saying it can be
|
||||
distributed under the terms of this License. Such a notice grants a
|
||||
world-wide, royalty-free license, unlimited in duration, to use that
|
||||
work under the conditions stated herein. The ``Document'', below,
|
||||
refers to any such manual or work. Any member of the public is a
|
||||
licensee, and is addressed as ``you''. You accept the license if you
|
||||
copy, modify or distribute the work in a way requiring permission
|
||||
under copyright law.
|
||||
|
||||
A ``Modified Version'' of the Document means any work containing the
|
||||
Document or a portion of it, either copied verbatim, or with
|
||||
modifications and/or translated into another language.
|
||||
|
||||
A ``Secondary Section'' is a named appendix or a front-matter section
|
||||
of the Document that deals exclusively with the relationship of the
|
||||
publishers or authors of the Document to the Document's overall
|
||||
subject (or to related matters) and contains nothing that could fall
|
||||
directly within that overall subject. (Thus, if the Document is in
|
||||
part a textbook of mathematics, a Secondary Section may not explain
|
||||
any mathematics.) The relationship could be a matter of historical
|
||||
connection with the subject or with related matters, or of legal,
|
||||
commercial, philosophical, ethical or political position regarding
|
||||
them.
|
||||
|
||||
The ``Invariant Sections'' are certain Secondary Sections whose titles
|
||||
are designated, as being those of Invariant Sections, in the notice
|
||||
that says that the Document is released under this License. If a
|
||||
section does not fit the above definition of Secondary then it is not
|
||||
allowed to be designated as Invariant. The Document may contain zero
|
||||
Invariant Sections. If the Document does not identify any Invariant
|
||||
Sections then there are none.
|
||||
|
||||
The ``Cover Texts'' are certain short passages of text that are listed,
|
||||
as Front-Cover Texts or Back-Cover Texts, in the notice that says that
|
||||
the Document is released under this License. A Front-Cover Text may
|
||||
be at most 5 words, and a Back-Cover Text may be at most 25 words.
|
||||
|
||||
A ``Transparent'' copy of the Document means a machine-readable copy,
|
||||
represented in a format whose specification is available to the
|
||||
general public, that is suitable for revising the document
|
||||
straightforwardly with generic text editors or (for images composed of
|
||||
pixels) generic paint programs or (for drawings) some widely available
|
||||
drawing editor, and that is suitable for input to text formatters or
|
||||
for automatic translation to a variety of formats suitable for input
|
||||
to text formatters. A copy made in an otherwise Transparent file
|
||||
format whose markup, or absence of markup, has been arranged to thwart
|
||||
or discourage subsequent modification by readers is not Transparent.
|
||||
An image format is not Transparent if used for any substantial amount
|
||||
of text. A copy that is not ``Transparent'' is called ``Opaque''.
|
||||
|
||||
Examples of suitable formats for Transparent copies include plain
|
||||
ASCII without markup, Texinfo input format, La@TeX{} input
|
||||
format, SGML or XML using a publicly available
|
||||
DTD, and standard-conforming simple HTML,
|
||||
PostScript or PDF designed for human modification. Examples
|
||||
of transparent image formats include PNG, XCF and
|
||||
JPG@. Opaque formats include proprietary formats that can be
|
||||
read and edited only by proprietary word processors, SGML or
|
||||
XML for which the DTD and/or processing tools are
|
||||
not generally available, and the machine-generated HTML,
|
||||
PostScript or PDF produced by some word processors for
|
||||
output purposes only.
|
||||
|
||||
The ``Title Page'' means, for a printed book, the title page itself,
|
||||
plus such following pages as are needed to hold, legibly, the material
|
||||
this License requires to appear in the title page. For works in
|
||||
formats which do not have any title page as such, ``Title Page'' means
|
||||
the text near the most prominent appearance of the work's title,
|
||||
preceding the beginning of the body of the text.
|
||||
|
||||
The ``publisher'' means any person or entity that distributes copies
|
||||
of the Document to the public.
|
||||
|
||||
A section ``Entitled XYZ'' means a named subunit of the Document whose
|
||||
title either is precisely XYZ or contains XYZ in parentheses following
|
||||
text that translates XYZ in another language. (Here XYZ stands for a
|
||||
specific section name mentioned below, such as ``Acknowledgements'',
|
||||
``Dedications'', ``Endorsements'', or ``History''.) To ``Preserve the Title''
|
||||
of such a section when you modify the Document means that it remains a
|
||||
section ``Entitled XYZ'' according to this definition.
|
||||
|
||||
The Document may include Warranty Disclaimers next to the notice which
|
||||
states that this License applies to the Document. These Warranty
|
||||
Disclaimers are considered to be included by reference in this
|
||||
License, but only as regards disclaiming warranties: any other
|
||||
implication that these Warranty Disclaimers may have is void and has
|
||||
no effect on the meaning of this License.
|
||||
|
||||
@item
|
||||
VERBATIM COPYING
|
||||
|
||||
You may copy and distribute the Document in any medium, either
|
||||
commercially or noncommercially, provided that this License, the
|
||||
copyright notices, and the license notice saying this License applies
|
||||
to the Document are reproduced in all copies, and that you add no other
|
||||
conditions whatsoever to those of this License. You may not use
|
||||
technical measures to obstruct or control the reading or further
|
||||
copying of the copies you make or distribute. However, you may accept
|
||||
compensation in exchange for copies. If you distribute a large enough
|
||||
number of copies you must also follow the conditions in section 3.
|
||||
|
||||
You may also lend copies, under the same conditions stated above, and
|
||||
you may publicly display copies.
|
||||
|
||||
@item
|
||||
COPYING IN QUANTITY
|
||||
|
||||
If you publish printed copies (or copies in media that commonly have
|
||||
printed covers) of the Document, numbering more than 100, and the
|
||||
Document's license notice requires Cover Texts, you must enclose the
|
||||
copies in covers that carry, clearly and legibly, all these Cover
|
||||
Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on
|
||||
the back cover. Both covers must also clearly and legibly identify
|
||||
you as the publisher of these copies. The front cover must present
|
||||
the full title with all words of the title equally prominent and
|
||||
visible. You may add other material on the covers in addition.
|
||||
Copying with changes limited to the covers, as long as they preserve
|
||||
the title of the Document and satisfy these conditions, can be treated
|
||||
as verbatim copying in other respects.
|
||||
|
||||
If the required texts for either cover are too voluminous to fit
|
||||
legibly, you should put the first ones listed (as many as fit
|
||||
reasonably) on the actual cover, and continue the rest onto adjacent
|
||||
pages.
|
||||
|
||||
If you publish or distribute Opaque copies of the Document numbering
|
||||
more than 100, you must either include a machine-readable Transparent
|
||||
copy along with each Opaque copy, or state in or with each Opaque copy
|
||||
a computer-network location from which the general network-using
|
||||
public has access to download using public-standard network protocols
|
||||
a complete Transparent copy of the Document, free of added material.
|
||||
If you use the latter option, you must take reasonably prudent steps,
|
||||
when you begin distribution of Opaque copies in quantity, to ensure
|
||||
that this Transparent copy will remain thus accessible at the stated
|
||||
location until at least one year after the last time you distribute an
|
||||
Opaque copy (directly or through your agents or retailers) of that
|
||||
edition to the public.
|
||||
|
||||
It is requested, but not required, that you contact the authors of the
|
||||
Document well before redistributing any large number of copies, to give
|
||||
them a chance to provide you with an updated version of the Document.
|
||||
|
||||
@item
|
||||
MODIFICATIONS
|
||||
|
||||
You may copy and distribute a Modified Version of the Document under
|
||||
the conditions of sections 2 and 3 above, provided that you release
|
||||
the Modified Version under precisely this License, with the Modified
|
||||
Version filling the role of the Document, thus licensing distribution
|
||||
and modification of the Modified Version to whoever possesses a copy
|
||||
of it. In addition, you must do these things in the Modified Version:
|
||||
|
||||
@enumerate A
|
||||
@item
|
||||
Use in the Title Page (and on the covers, if any) a title distinct
|
||||
from that of the Document, and from those of previous versions
|
||||
(which should, if there were any, be listed in the History section
|
||||
of the Document). You may use the same title as a previous version
|
||||
if the original publisher of that version gives permission.
|
||||
|
||||
@item
|
||||
List on the Title Page, as authors, one or more persons or entities
|
||||
responsible for authorship of the modifications in the Modified
|
||||
Version, together with at least five of the principal authors of the
|
||||
Document (all of its principal authors, if it has fewer than five),
|
||||
unless they release you from this requirement.
|
||||
|
||||
@item
|
||||
State on the Title page the name of the publisher of the
|
||||
Modified Version, as the publisher.
|
||||
|
||||
@item
|
||||
Preserve all the copyright notices of the Document.
|
||||
|
||||
@item
|
||||
Add an appropriate copyright notice for your modifications
|
||||
adjacent to the other copyright notices.
|
||||
|
||||
@item
|
||||
Include, immediately after the copyright notices, a license notice
|
||||
giving the public permission to use the Modified Version under the
|
||||
terms of this License, in the form shown in the Addendum below.
|
||||
|
||||
@item
|
||||
Preserve in that license notice the full lists of Invariant Sections
|
||||
and required Cover Texts given in the Document's license notice.
|
||||
|
||||
@item
|
||||
Include an unaltered copy of this License.
|
||||
|
||||
@item
|
||||
Preserve the section Entitled ``History'', Preserve its Title, and add
|
||||
to it an item stating at least the title, year, new authors, and
|
||||
publisher of the Modified Version as given on the Title Page. If
|
||||
there is no section Entitled ``History'' in the Document, create one
|
||||
stating the title, year, authors, and publisher of the Document as
|
||||
given on its Title Page, then add an item describing the Modified
|
||||
Version as stated in the previous sentence.
|
||||
|
||||
@item
|
||||
Preserve the network location, if any, given in the Document for
|
||||
public access to a Transparent copy of the Document, and likewise
|
||||
the network locations given in the Document for previous versions
|
||||
it was based on. These may be placed in the ``History'' section.
|
||||
You may omit a network location for a work that was published at
|
||||
least four years before the Document itself, or if the original
|
||||
publisher of the version it refers to gives permission.
|
||||
|
||||
@item
|
||||
For any section Entitled ``Acknowledgements'' or ``Dedications'', Preserve
|
||||
the Title of the section, and preserve in the section all the
|
||||
substance and tone of each of the contributor acknowledgements and/or
|
||||
dedications given therein.
|
||||
|
||||
@item
|
||||
Preserve all the Invariant Sections of the Document,
|
||||
unaltered in their text and in their titles. Section numbers
|
||||
or the equivalent are not considered part of the section titles.
|
||||
|
||||
@item
|
||||
Delete any section Entitled ``Endorsements''. Such a section
|
||||
may not be included in the Modified Version.
|
||||
|
||||
@item
|
||||
Do not retitle any existing section to be Entitled ``Endorsements'' or
|
||||
to conflict in title with any Invariant Section.
|
||||
|
||||
@item
|
||||
Preserve any Warranty Disclaimers.
|
||||
@end enumerate
|
||||
|
||||
If the Modified Version includes new front-matter sections or
|
||||
appendices that qualify as Secondary Sections and contain no material
|
||||
copied from the Document, you may at your option designate some or all
|
||||
of these sections as invariant. To do this, add their titles to the
|
||||
list of Invariant Sections in the Modified Version's license notice.
|
||||
These titles must be distinct from any other section titles.
|
||||
|
||||
You may add a section Entitled ``Endorsements'', provided it contains
|
||||
nothing but endorsements of your Modified Version by various
|
||||
parties---for example, statements of peer review or that the text has
|
||||
been approved by an organization as the authoritative definition of a
|
||||
standard.
|
||||
|
||||
You may add a passage of up to five words as a Front-Cover Text, and a
|
||||
passage of up to 25 words as a Back-Cover Text, to the end of the list
|
||||
of Cover Texts in the Modified Version. Only one passage of
|
||||
Front-Cover Text and one of Back-Cover Text may be added by (or
|
||||
through arrangements made by) any one entity. If the Document already
|
||||
includes a cover text for the same cover, previously added by you or
|
||||
by arrangement made by the same entity you are acting on behalf of,
|
||||
you may not add another; but you may replace the old one, on explicit
|
||||
permission from the previous publisher that added the old one.
|
||||
|
||||
The author(s) and publisher(s) of the Document do not by this License
|
||||
give permission to use their names for publicity for or to assert or
|
||||
imply endorsement of any Modified Version.
|
||||
|
||||
@item
|
||||
COMBINING DOCUMENTS
|
||||
|
||||
You may combine the Document with other documents released under this
|
||||
License, under the terms defined in section 4 above for modified
|
||||
versions, provided that you include in the combination all of the
|
||||
Invariant Sections of all of the original documents, unmodified, and
|
||||
list them all as Invariant Sections of your combined work in its
|
||||
license notice, and that you preserve all their Warranty Disclaimers.
|
||||
|
||||
The combined work need only contain one copy of this License, and
|
||||
multiple identical Invariant Sections may be replaced with a single
|
||||
copy. If there are multiple Invariant Sections with the same name but
|
||||
different contents, make the title of each such section unique by
|
||||
adding at the end of it, in parentheses, the name of the original
|
||||
author or publisher of that section if known, or else a unique number.
|
||||
Make the same adjustment to the section titles in the list of
|
||||
Invariant Sections in the license notice of the combined work.
|
||||
|
||||
In the combination, you must combine any sections Entitled ``History''
|
||||
in the various original documents, forming one section Entitled
|
||||
``History''; likewise combine any sections Entitled ``Acknowledgements'',
|
||||
and any sections Entitled ``Dedications''. You must delete all
|
||||
sections Entitled ``Endorsements.''
|
||||
|
||||
@item
|
||||
COLLECTIONS OF DOCUMENTS
|
||||
|
||||
You may make a collection consisting of the Document and other documents
|
||||
released under this License, and replace the individual copies of this
|
||||
License in the various documents with a single copy that is included in
|
||||
the collection, provided that you follow the rules of this License for
|
||||
verbatim copying of each of the documents in all other respects.
|
||||
|
||||
You may extract a single document from such a collection, and distribute
|
||||
it individually under this License, provided you insert a copy of this
|
||||
License into the extracted document, and follow this License in all
|
||||
other respects regarding verbatim copying of that document.
|
||||
|
||||
@item
|
||||
AGGREGATION WITH INDEPENDENT WORKS
|
||||
|
||||
A compilation of the Document or its derivatives with other separate
|
||||
and independent documents or works, in or on a volume of a storage or
|
||||
distribution medium, is called an ``aggregate'' if the copyright
|
||||
resulting from the compilation is not used to limit the legal rights
|
||||
of the compilation's users beyond what the individual works permit.
|
||||
When the Document is included in an aggregate, this License does not
|
||||
apply to the other works in the aggregate which are not themselves
|
||||
derivative works of the Document.
|
||||
|
||||
If the Cover Text requirement of section 3 is applicable to these
|
||||
copies of the Document, then if the Document is less than one half of
|
||||
the entire aggregate, the Document's Cover Texts may be placed on
|
||||
covers that bracket the Document within the aggregate, or the
|
||||
electronic equivalent of covers if the Document is in electronic form.
|
||||
Otherwise they must appear on printed covers that bracket the whole
|
||||
aggregate.
|
||||
|
||||
@item
|
||||
TRANSLATION
|
||||
|
||||
Translation is considered a kind of modification, so you may
|
||||
distribute translations of the Document under the terms of section 4.
|
||||
Replacing Invariant Sections with translations requires special
|
||||
permission from their copyright holders, but you may include
|
||||
translations of some or all Invariant Sections in addition to the
|
||||
original versions of these Invariant Sections. You may include a
|
||||
translation of this License, and all the license notices in the
|
||||
Document, and any Warranty Disclaimers, provided that you also include
|
||||
the original English version of this License and the original versions
|
||||
of those notices and disclaimers. In case of a disagreement between
|
||||
the translation and the original version of this License or a notice
|
||||
or disclaimer, the original version will prevail.
|
||||
|
||||
If a section in the Document is Entitled ``Acknowledgements'',
|
||||
``Dedications'', or ``History'', the requirement (section 4) to Preserve
|
||||
its Title (section 1) will typically require changing the actual
|
||||
title.
|
||||
|
||||
@item
|
||||
TERMINATION
|
||||
|
||||
You may not copy, modify, sublicense, or distribute the Document
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense, or distribute it is void, and
|
||||
will automatically terminate your rights under this License.
|
||||
|
||||
However, if you cease all violation of this License, then your license
|
||||
from a particular copyright holder is reinstated (a) provisionally,
|
||||
unless and until the copyright holder explicitly and finally
|
||||
terminates your license, and (b) permanently, if the copyright holder
|
||||
fails to notify you of the violation by some reasonable means prior to
|
||||
60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, receipt of a copy of some or all of the same material does
|
||||
not give you any rights to use it.
|
||||
|
||||
@item
|
||||
FUTURE REVISIONS OF THIS LICENSE
|
||||
|
||||
The Free Software Foundation may publish new, revised versions
|
||||
of the GNU Free Documentation 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. See
|
||||
@uref{https://www.gnu.org/licenses/}.
|
||||
|
||||
Each version of the License is given a distinguishing version number.
|
||||
If the Document specifies that a particular numbered version of this
|
||||
License ``or any later version'' applies to it, you have the option of
|
||||
following the terms and conditions either of that specified version or
|
||||
of any later version that has been published (not as a draft) by the
|
||||
Free Software Foundation. If the Document does not specify a version
|
||||
number of this License, you may choose any version ever published (not
|
||||
as a draft) by the Free Software Foundation. If the Document
|
||||
specifies that a proxy can decide which future versions of this
|
||||
License can be used, that proxy's public statement of acceptance of a
|
||||
version permanently authorizes you to choose that version for the
|
||||
Document.
|
||||
|
||||
@item
|
||||
RELICENSING
|
||||
|
||||
``Massive Multiauthor Collaboration Site'' (or ``MMC Site'') means any
|
||||
World Wide Web server that publishes copyrightable works and also
|
||||
provides prominent facilities for anybody to edit those works. A
|
||||
public wiki that anybody can edit is an example of such a server. A
|
||||
``Massive Multiauthor Collaboration'' (or ``MMC'') contained in the
|
||||
site means any set of copyrightable works thus published on the MMC
|
||||
site.
|
||||
|
||||
``CC-BY-SA'' means the Creative Commons Attribution-Share Alike 3.0
|
||||
license published by Creative Commons Corporation, a not-for-profit
|
||||
corporation with a principal place of business in San Francisco,
|
||||
California, as well as future copyleft versions of that license
|
||||
published by that same organization.
|
||||
|
||||
``Incorporate'' means to publish or republish a Document, in whole or
|
||||
in part, as part of another Document.
|
||||
|
||||
An MMC is ``eligible for relicensing'' if it is licensed under this
|
||||
License, and if all works that were first published under this License
|
||||
somewhere other than this MMC, and subsequently incorporated in whole
|
||||
or in part into the MMC, (1) had no cover texts or invariant sections,
|
||||
and (2) were thus incorporated prior to November 1, 2008.
|
||||
|
||||
The operator of an MMC Site may republish an MMC contained in the site
|
||||
under CC-BY-SA on the same site at any time before August 1, 2009,
|
||||
provided the MMC is eligible for relicensing.
|
||||
|
||||
@end enumerate
|
||||
|
||||
@page
|
||||
@heading ADDENDUM: How to use this License for your documents
|
||||
|
||||
To use this License in a document you have written, include a copy of
|
||||
the License in the document and put the following copyright and
|
||||
license notices just after the title page:
|
||||
|
||||
@smallexample
|
||||
@group
|
||||
Copyright (C) @var{year} @var{your name}.
|
||||
Permission is granted to copy, distribute and/or modify this document
|
||||
under the terms of the GNU Free Documentation License, Version 1.3
|
||||
or any later version published by the Free Software Foundation;
|
||||
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
|
||||
Texts. A copy of the license is included in the section entitled ``GNU
|
||||
Free Documentation License''.
|
||||
@end group
|
||||
@end smallexample
|
||||
|
||||
If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts,
|
||||
replace the ``with@dots{}Texts.''@: line with this:
|
||||
|
||||
@smallexample
|
||||
@group
|
||||
with the Invariant Sections being @var{list their titles}, with
|
||||
the Front-Cover Texts being @var{list}, and with the Back-Cover Texts
|
||||
being @var{list}.
|
||||
@end group
|
||||
@end smallexample
|
||||
|
||||
If you have Invariant Sections without Cover Texts, or some other
|
||||
combination of the three, merge those two alternatives to suit the
|
||||
situation.
|
||||
|
||||
If your document contains nontrivial examples of program code, we
|
||||
recommend releasing these examples in parallel under your choice of
|
||||
free software license, such as the GNU General Public License,
|
||||
to permit their use in free software.
|
||||
|
||||
@c Local Variables:
|
||||
@c ispell-local-pdict: "ispell-dict"
|
||||
@c End:
|
|
@ -0,0 +1,24 @@
|
|||
#
|
||||
# Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
#
|
||||
# Copying and distribution of this file, with or without modification, are
|
||||
# permitted in any medium without royalty, provided the copyright notice and
|
||||
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||
#
|
||||
|
||||
include_HEADERS =
|
||||
lib_LTLIBRARIES =
|
||||
dist_man3_MANS =
|
||||
|
||||
|
||||
if BUILD_ARIF_RIME
|
||||
|
||||
include_HEADERS += arif_rime.h
|
||||
lib_LTLIBRARIES += libarifrime.la
|
||||
dist_man3_MANS += arif_rime.3
|
||||
|
||||
libarifrime_la_CPPFLAGS = $(RIME_CFLAGS) -I$(top_srcdir)/include
|
||||
libarifrime_la_LIBADD = $(RIME_LIBS)
|
||||
libarifrime_la_SOURCES = arif_rime.c
|
||||
|
||||
endif # BUILD_ARIF_RIME
|
|
@ -0,0 +1,77 @@
|
|||
.TH ARIF_RIME 3 "Jan 02, 2023" 0.1.0 "ARIF User Manual"
|
||||
.
|
||||
.SH NAME
|
||||
arif_rime - example Rime IME integration for ARIF
|
||||
.
|
||||
.SH SYNOPSYS
|
||||
.EX
|
||||
.B #include <arif_rime.h>
|
||||
.PP
|
||||
.BI "extern struct arif_engine const " arif_rime_engine ;
|
||||
.EE
|
||||
.
|
||||
.SH DESCRIPTION
|
||||
An example implementation of ARIF engine, powered by the Rime IME core library.
|
||||
.PP
|
||||
See the manual page of
|
||||
.BR arif_set_engine ()
|
||||
for how to use this engine.
|
||||
.SS Initialization
|
||||
The
|
||||
.IR init ()
|
||||
function of
|
||||
.I arif_rime_engine
|
||||
ignores the first argument.
|
||||
Engine configuration is instead read from environment variables.
|
||||
.PP
|
||||
Note that the variables are only read during the first
|
||||
.IR init ()
|
||||
call, initialization of subsequent engine instances share the same
|
||||
configuration.
|
||||
.
|
||||
.SH ENVIRONMENT
|
||||
.TP
|
||||
.B ARIF_RIME_SHARED_DATA_DIR
|
||||
Path to the directory where Rime schema data files are stored.
|
||||
.IP
|
||||
Defaults to "/usr/share/rime-data".
|
||||
.TP
|
||||
.B ARIF_RIME_USER_DATA_DIR
|
||||
Path to the directory where user configuration files are stored.
|
||||
.TP
|
||||
.B ARIF_RIME_LOG_DIR
|
||||
Path to the directory where Rime log files will be written to.
|
||||
.IP
|
||||
Defaults to "/tmp".
|
||||
.TP
|
||||
.B ARIF_RIME_LOG_LEVEL
|
||||
Rime minimum log level.
|
||||
Should be one of INFO, WARNING, ERROR or FATAL (case insensitive).
|
||||
.IP
|
||||
Default log level is INFO.
|
||||
.TP
|
||||
.B ARIF_RIME_MODULES
|
||||
A whitespace-separated list of Rime modules to load before Rime initialization.
|
||||
.
|
||||
.SH BUGS
|
||||
This is only an example to shed light on how an ARIF engine can be implemented.
|
||||
It is not intended for everyday use.
|
||||
.PP
|
||||
Only part of Rime's features are supported, and may not work as expected
|
||||
with certain configurations.
|
||||
.
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
.PP
|
||||
Permission is granted to copy, distribute and/or modify this document
|
||||
under the terms of the GNU Free Documentation License, Version 1.3
|
||||
or any later version published by the Free Software Foundation;
|
||||
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
|
||||
.PP
|
||||
You should have received a copy of the license along with this document.
|
||||
If not, see <https://www.gnu.org/licenses/fdl-1.3.html>.
|
||||
.
|
||||
.SH SEE ALSO
|
||||
.BR arif_set_engine (3)
|
||||
.PP
|
||||
Rime IME core library: <https://github.com/rime/librime>
|
|
@ -0,0 +1,394 @@
|
|||
/**
|
||||
* arif/examples/arif_rime.c - example Rime IME integration for ARIF
|
||||
* ----
|
||||
*
|
||||
* Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
*
|
||||
* This file is part of ARIF, Another Readline Input Framework.
|
||||
*
|
||||
* ARIF 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.
|
||||
*
|
||||
* ARIF 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 ARIF. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include "arif_rime.h"
|
||||
|
||||
#ifdef HAVE_RIME
|
||||
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <strings.h>
|
||||
|
||||
#include <rime_api.h>
|
||||
|
||||
#include "arif_defs.h"
|
||||
|
||||
#ifndef ARIF_RIME_APP_NAME
|
||||
# define ARIF_RIME_APP_NAME "rime.arif"
|
||||
#endif
|
||||
#ifndef ARIF_RIME_DIST_NAME
|
||||
# define ARIF_RIME_DIST_NAME "Rime"
|
||||
#endif
|
||||
#ifndef ARIF_RIME_DIST_CODE_NAME
|
||||
# define ARIF_RIME_DIST_CODE_NAME "arif-rime"
|
||||
#endif
|
||||
|
||||
#define VERSION_STR_(major, minor, patch) #major "." #minor "." #patch
|
||||
#define VERSION_STR(major, minor, patch) VERSION_STR_(major, minor, patch)
|
||||
|
||||
#define XK_Down 0xff54 // #include <X11/keysym.h>
|
||||
|
||||
struct engine_ctx {
|
||||
RimeSessionId session;
|
||||
struct cand_entry *candidates;
|
||||
bool no_more_candidates;
|
||||
};
|
||||
|
||||
// Forward declaration start
|
||||
static void arif_rime_finalize (void *);
|
||||
static void arif_rime_info (void *, char const **, char const **);
|
||||
static int arif_rime_init (void *, void **);
|
||||
static int arif_rime_query (void *, char const *, int, int, int,
|
||||
struct arif_cand const **);
|
||||
static bool copy_candidate (struct arif_cand *, RimeContext *);
|
||||
static int init_rime (void);
|
||||
static void finalize_rime (void);
|
||||
static void free_candidates (struct engine_ctx *);
|
||||
static char const * gen_description (void);
|
||||
static char const * get_env (char const *, char const *);
|
||||
static int get_log_level (char const *);
|
||||
static char const ** get_modules (char const *);
|
||||
// Forward declaration end
|
||||
|
||||
struct cand_entry {
|
||||
struct cand_entry *next;
|
||||
int num_candidates;
|
||||
struct arif_cand candidates[];
|
||||
};
|
||||
|
||||
struct arif_engine const arif_rime_engine = {
|
||||
.init = arif_rime_init,
|
||||
.finalize = arif_rime_finalize,
|
||||
.info = arif_rime_info,
|
||||
.query = arif_rime_query,
|
||||
};
|
||||
|
||||
static RimeApi *rime_api;
|
||||
static char *rime_description;
|
||||
static char const **rime_modules;
|
||||
|
||||
static void
|
||||
arif_rime_finalize (
|
||||
void *engine_data
|
||||
) {
|
||||
struct engine_ctx *ctx = engine_data;
|
||||
|
||||
free_candidates(ctx);
|
||||
|
||||
if (rime_api != NULL) {
|
||||
if (ctx->session != 0) {
|
||||
rime_api->destroy_session(ctx->session);
|
||||
}
|
||||
}
|
||||
|
||||
free(ctx);
|
||||
}
|
||||
|
||||
static void
|
||||
arif_rime_info (
|
||||
void *ARIF_UNUSED_ARG(engine_data),
|
||||
char const **name_ptr,
|
||||
char const **description_ptr
|
||||
) {
|
||||
if (name_ptr != NULL) {
|
||||
*name_ptr = "rime";
|
||||
}
|
||||
if (description_ptr != NULL) {
|
||||
*description_ptr = gen_description();
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
arif_rime_init (
|
||||
void *ARIF_UNUSED_ARG(args),
|
||||
void **engine_data_ptr
|
||||
) {
|
||||
int status = init_rime();
|
||||
if (status != 0) {
|
||||
return status;
|
||||
}
|
||||
|
||||
struct engine_ctx *ctx = malloc(sizeof(struct engine_ctx));
|
||||
assert(ctx != NULL);
|
||||
|
||||
*ctx = (struct engine_ctx) {
|
||||
.session = rime_api->create_session(),
|
||||
};
|
||||
*engine_data_ptr = ctx;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
arif_rime_query (
|
||||
void *engine_data,
|
||||
char const *line,
|
||||
int offset,
|
||||
int len,
|
||||
int num_candidates,
|
||||
struct arif_cand const **candidates_ptr
|
||||
) {
|
||||
struct engine_ctx *ctx = engine_data;
|
||||
|
||||
if (line != NULL) {
|
||||
free_candidates(ctx);
|
||||
rime_api->destroy_session(ctx->session);
|
||||
ctx->session = rime_api->create_session();
|
||||
|
||||
char const *text = line + offset;
|
||||
for (int idx = 0; idx < len; ++idx) {
|
||||
if (!rime_api->process_key(ctx->session, text[idx], 0)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} else if (candidates_ptr == NULL) {
|
||||
// TODO: handle candidate selection so that we can preserve a
|
||||
// Rime session when possible.
|
||||
return 0;
|
||||
} else {
|
||||
if (!rime_api->find_session(ctx->session)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
size_t candidates_size = sizeof(struct arif_cand) * num_candidates;
|
||||
struct cand_entry *entries
|
||||
= malloc(sizeof(struct cand_entry) + candidates_size);
|
||||
assert(entries != NULL);
|
||||
entries->next = ctx->candidates;
|
||||
ctx->candidates = entries;
|
||||
|
||||
int idx = 0;
|
||||
for (; !ctx->no_more_candidates && idx < num_candidates; ++idx) {
|
||||
RIME_STRUCT(RimeContext, rimectx);
|
||||
if (!rime_api->get_context(ctx->session, &rimectx)) {
|
||||
break;
|
||||
}
|
||||
|
||||
struct arif_cand *candidate = entries->candidates + idx;
|
||||
if (copy_candidate(candidate, &rimectx)) {
|
||||
ctx->no_more_candidates = true;
|
||||
}
|
||||
|
||||
rime_api->free_context(&rimectx);
|
||||
|
||||
if (!rime_api->process_key(ctx->session, XK_Down, 0)) {
|
||||
ctx->no_more_candidates = true;
|
||||
}
|
||||
}
|
||||
entries->num_candidates = idx;
|
||||
*candidates_ptr = entries->candidates;
|
||||
return idx;
|
||||
}
|
||||
|
||||
static bool
|
||||
copy_candidate (
|
||||
struct arif_cand *dest,
|
||||
RimeContext *src
|
||||
) {
|
||||
RimeMenu *menu = &src->menu;
|
||||
RimeComposition *composition = &src->composition;
|
||||
int candidate_idx = menu->highlighted_candidate_index;
|
||||
|
||||
char const *text = menu->candidates[candidate_idx].text;
|
||||
int text_len = strlen(text);
|
||||
char const *line = composition->preedit;
|
||||
int line_len = strlen(line);
|
||||
|
||||
char *buf = malloc(text_len + line_len);
|
||||
assert(buf != NULL);
|
||||
|
||||
dest->text = memcpy(buf, text, text_len);
|
||||
dest->len = text_len;
|
||||
dest->replace_len = composition->sel_end - composition->sel_start;
|
||||
dest->transform = memcpy(buf + text_len, line, line_len);
|
||||
dest->transform_len = line_len;
|
||||
|
||||
return menu->is_last_page && candidate_idx + 1 == menu->page_size;
|
||||
}
|
||||
|
||||
static void
|
||||
free_candidates (
|
||||
struct engine_ctx *ctx
|
||||
) {
|
||||
struct cand_entry *entry, *next;
|
||||
for (entry = ctx->candidates; entry != NULL; entry = next) {
|
||||
for (int idx = 0; idx < entry->num_candidates; ++idx) {
|
||||
struct arif_cand *candidate = entry->candidates + idx;
|
||||
free((char *) candidate->text);
|
||||
}
|
||||
|
||||
next = entry->next;
|
||||
free(entry);
|
||||
}
|
||||
ctx->candidates = NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
init_rime (void)
|
||||
{
|
||||
if (rime_api != NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
rime_api = rime_get_api();
|
||||
if (rime_api == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
RIME_STRUCT(RimeTraits, traits);
|
||||
traits.app_name = ARIF_RIME_APP_NAME;
|
||||
traits.distribution_name = ARIF_RIME_DIST_NAME;
|
||||
traits.distribution_code_name = ARIF_RIME_DIST_CODE_NAME;
|
||||
traits.distribution_version
|
||||
= VERSION_STR(ARIF_VER_MAJOR, ARIF_VER_MINOR, ARIF_VER_PATCH);
|
||||
traits.shared_data_dir
|
||||
= get_env("ARIF_RIME_SHARED_DATA_DIR", "/usr/share/rime-data");
|
||||
traits.user_data_dir = get_env("ARIF_RIME_USER_DATA_DIR", NULL);
|
||||
traits.log_dir = get_env("ARIF_RIME_LOG_DIR", "/tmp");
|
||||
traits.min_log_level = get_log_level("ARIF_RIME_LOG_LEVEL");
|
||||
traits.modules = get_modules("ARIF_RIME_MODULES");
|
||||
|
||||
rime_api->setup(&traits);
|
||||
rime_api->initialize(&traits);
|
||||
|
||||
// Rime uses static C++ variables to store its states, which get destroyed
|
||||
// on exit. Make sure we finalize Rime API before that.
|
||||
atexit(finalize_rime);
|
||||
|
||||
rime_modules = traits.modules;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
finalize_rime (void)
|
||||
{
|
||||
if (rime_api != NULL) {
|
||||
rime_api->finalize();
|
||||
rime_api = NULL;
|
||||
}
|
||||
if (rime_modules != NULL) {
|
||||
free((char *) rime_modules[0]);
|
||||
free(rime_modules);
|
||||
rime_modules = NULL;
|
||||
}
|
||||
free(rime_description);
|
||||
}
|
||||
|
||||
static char const *
|
||||
gen_description (void)
|
||||
{
|
||||
if (rime_description != NULL) {
|
||||
return rime_description;
|
||||
}
|
||||
|
||||
char const *fmt = "Example Rime integration for ARIF\n"
|
||||
" Rime IME <https://rime.im/> version: %s\n";
|
||||
char const *rime_version = rime_api->get_version();
|
||||
if (rime_version == NULL) {
|
||||
rime_version = "N/A";
|
||||
}
|
||||
|
||||
int desc_len = snprintf(NULL, 0, fmt, rime_version);
|
||||
assert(desc_len > 0);
|
||||
|
||||
rime_description = malloc(sizeof(char) * (desc_len + 1));
|
||||
assert(rime_description != NULL);
|
||||
sprintf(rime_description, fmt, rime_version);
|
||||
|
||||
return rime_description;
|
||||
}
|
||||
|
||||
static char const *
|
||||
get_env (
|
||||
char const *name,
|
||||
char const *default_val
|
||||
) {
|
||||
char const *val = getenv(name);
|
||||
if (val == NULL || val[0] == '\0') {
|
||||
val = default_val;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
static int
|
||||
get_log_level (
|
||||
char const *env_name
|
||||
) {
|
||||
char const *log_level = get_env(env_name, "");
|
||||
|
||||
if (0 == strcasecmp("INFO", log_level)) {
|
||||
return 0;
|
||||
}
|
||||
if (0 == strcasecmp("WARNING", log_level)) {
|
||||
return 1;
|
||||
}
|
||||
if (0 == strcasecmp("ERROR", log_level)) {
|
||||
return 2;
|
||||
}
|
||||
if (0 == strcasecmp("FATAL", log_level)) {
|
||||
return 3;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char const **
|
||||
get_modules (
|
||||
char const *env_name
|
||||
) {
|
||||
char const *modules_env = get_env(env_name, NULL);
|
||||
if (modules_env == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
size_t modules_len = strlen(modules_env) + 1;
|
||||
|
||||
char *modules_str = malloc(sizeof(char) * modules_len);
|
||||
assert(modules_str != NULL);
|
||||
memcpy(modules_str, modules_env, modules_len);
|
||||
|
||||
size_t modules_size = 4, idx = 0;
|
||||
char const **modules = NULL;
|
||||
|
||||
char const *delim = " \n\t\r\v\f";
|
||||
for (char *module = strtok(modules_str, delim); module != NULL;
|
||||
module = strtok(NULL, delim)
|
||||
) {
|
||||
if (modules == NULL || idx == modules_size - 1) {
|
||||
modules_size += modules_size / 2;
|
||||
modules = realloc(modules, sizeof(char const *) * modules_size);
|
||||
assert(modules != NULL);
|
||||
}
|
||||
modules[idx++] = module;
|
||||
}
|
||||
modules[idx] = NULL;
|
||||
return modules;
|
||||
}
|
||||
|
||||
#endif // defined(HAVE_RIME)
|
|
@ -0,0 +1,30 @@
|
|||
/**
|
||||
* arif/examples/arif_rime.h - example Rime IME integration for ARIF
|
||||
* ----
|
||||
*
|
||||
* Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
*
|
||||
* This file is part of ARIF, Another Readline Input Framework.
|
||||
*
|
||||
* ARIF 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.
|
||||
*
|
||||
* ARIF 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 ARIF. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef ARIF_RIME_H_
|
||||
#define ARIF_RIME_H_
|
||||
|
||||
#include "arif.h"
|
||||
|
||||
extern struct arif_engine const arif_rime_engine;
|
||||
|
||||
#endif // !defined(ARIF_RIME_H_)
|
|
@ -0,0 +1,18 @@
|
|||
#
|
||||
# Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
#
|
||||
# Copying and distribution of this file, with or without modification, are
|
||||
# permitted in any medium without royalty, provided the copyright notice and
|
||||
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||
#
|
||||
|
||||
noinst_HEADERS = arif_defs.h arify.h
|
||||
pkginclude_HEADERS = arif.h
|
||||
|
||||
|
||||
if BUILD_ARIF_READLINE
|
||||
|
||||
noinst_HEADERS += arify_rl.h
|
||||
pkginclude_HEADERS += arif_rl.h
|
||||
|
||||
endif # BUILD_ARIF_READLINE
|
|
@ -0,0 +1,123 @@
|
|||
/**
|
||||
* arif/include/arif.h - ARIF base library
|
||||
* ----
|
||||
*
|
||||
* Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
*
|
||||
* This file is part of ARIF, Another Readline Input Framework.
|
||||
*
|
||||
* ARIF 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.
|
||||
*
|
||||
* ARIF 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 ARIF. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef ARIF_H_
|
||||
#define ARIF_H_
|
||||
|
||||
#define ARIF_VER_MAJOR 0
|
||||
#define ARIF_VER_MINOR 1
|
||||
#define ARIF_VER_PATCH 0
|
||||
|
||||
struct arif_cand;
|
||||
struct arif_ctx;
|
||||
|
||||
typedef char *(arif_cand_disp_func) (
|
||||
char const *text,
|
||||
int len,
|
||||
int idx,
|
||||
int *display_len_ptr
|
||||
);
|
||||
|
||||
typedef void (arif_engine_finalize_func) (
|
||||
void *engine_data
|
||||
);
|
||||
|
||||
typedef void (arif_engine_info_func) (
|
||||
void *engine_data,
|
||||
char const **name_ptr,
|
||||
char const **description_ptr
|
||||
);
|
||||
|
||||
typedef int (arif_engine_init_func) (
|
||||
void *args,
|
||||
void **engine_data_ptr
|
||||
);
|
||||
|
||||
typedef int (arif_engine_query_func) (
|
||||
void *engine_data,
|
||||
char const *line,
|
||||
int offset,
|
||||
int len,
|
||||
int num_candidates,
|
||||
struct arif_cand const **candidates_ptr
|
||||
);
|
||||
|
||||
struct arif_cand {
|
||||
char const *text;
|
||||
int len;
|
||||
int replace_len;
|
||||
char const *transform;
|
||||
int transform_len;
|
||||
char const *display;
|
||||
int display_len;
|
||||
};
|
||||
|
||||
struct arif_engine {
|
||||
arif_engine_init_func *init;
|
||||
arif_engine_finalize_func *finalize;
|
||||
arif_engine_info_func *info;
|
||||
arif_engine_query_func *query;
|
||||
};
|
||||
|
||||
struct arif_opts {
|
||||
arif_cand_disp_func *disp_cand;
|
||||
int page_size;
|
||||
};
|
||||
|
||||
struct arif_ctx *
|
||||
arif_ctx_create (
|
||||
struct arif_opts const *options
|
||||
);
|
||||
|
||||
void
|
||||
arif_ctx_destroy (
|
||||
struct arif_ctx *ctx
|
||||
);
|
||||
|
||||
int
|
||||
arif_fetch (
|
||||
struct arif_ctx *ctx,
|
||||
struct arif_cand const **candidates_ptr
|
||||
);
|
||||
|
||||
int
|
||||
arif_query (
|
||||
struct arif_ctx *ctx,
|
||||
char const *line,
|
||||
int offset,
|
||||
int len
|
||||
);
|
||||
|
||||
int
|
||||
arif_select_page (
|
||||
struct arif_ctx *ctx,
|
||||
int idx
|
||||
);
|
||||
|
||||
void
|
||||
arif_set_engine (
|
||||
struct arif_ctx *ctx,
|
||||
struct arif_engine const *engine,
|
||||
void *engine_data
|
||||
);
|
||||
|
||||
#endif // !defined(ARIF_H_)
|
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* arif/include/arif_defs.h - ARIF common macros
|
||||
* ----
|
||||
*
|
||||
* Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
*
|
||||
* This file is part of ARIF, Another Readline Input Framework.
|
||||
*
|
||||
* ARIF 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.
|
||||
*
|
||||
* ARIF 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 ARIF. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_FUNC_ATTRIBUTE_NORETURN
|
||||
# define ARIF_NORETURN __attribute__((noreturn))
|
||||
#else
|
||||
# define ARIF_NORETURN
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_VAR_ATTRIBUTE_UNUSED
|
||||
# define ARIF_UNUSED __attribute__((unused))
|
||||
#else
|
||||
# define ARIF_UNUSED
|
||||
#endif
|
||||
#define ARIF_UNUSED_ARG(name) name##_unused_ ARIF_UNUSED
|
||||
|
||||
#if defined(__APPLE__)
|
||||
# define ARIF_SHLIB_SUFFIX ".dylib"
|
||||
#elif defined(__CYGWIN__) || defined(__MINGW32__)
|
||||
# define ARIF_SHLIB_SUFFIX ".dll"
|
||||
#else
|
||||
# define ARIF_SHLIB_SUFFIX ".so"
|
||||
#endif
|
||||
|
||||
#ifdef ARIF_DEBUG
|
||||
# define ARIF_DEBUG_ASSERT(expr) assert(expr)
|
||||
#else
|
||||
# define ARIF_DEBUG_ASSERT(expr)
|
||||
#endif
|
|
@ -0,0 +1,44 @@
|
|||
/**
|
||||
* arif/include/arif_rl.h - ARIF Readline frontend
|
||||
* ----
|
||||
*
|
||||
* Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
*
|
||||
* This file is part of ARIF, Another Readline Input Framework.
|
||||
*
|
||||
* ARIF 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.
|
||||
*
|
||||
* ARIF 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 ARIF. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef ARIF_RL_H_
|
||||
#define ARIF_RL_H_
|
||||
|
||||
#include "arif.h"
|
||||
|
||||
char **
|
||||
arif_rl_complete (
|
||||
struct arif_ctx *ctx,
|
||||
char const *text,
|
||||
int start,
|
||||
int end
|
||||
);
|
||||
|
||||
void
|
||||
arif_rl_display (
|
||||
struct arif_ctx *ctx,
|
||||
char **matches,
|
||||
int num,
|
||||
int max_len
|
||||
);
|
||||
|
||||
#endif // !defined(ARIF_RL_H_)
|
|
@ -0,0 +1,62 @@
|
|||
/**
|
||||
* arif/include/arify.h - ARIF preload library
|
||||
* ----
|
||||
*
|
||||
* Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
*
|
||||
* This file is part of ARIF, Another Readline Input Framework.
|
||||
*
|
||||
* ARIF 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.
|
||||
*
|
||||
* ARIF 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 ARIF. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef ARIFY_H_
|
||||
#define ARIFY_H_
|
||||
|
||||
#include "arif.h"
|
||||
|
||||
#ifdef ARIF_DEBUG
|
||||
# define arify_debug_printf(fmt, ...) arify_log_printf(fmt, "D", __VA_ARGS__)
|
||||
#else
|
||||
# define arify_debug_printf(fmt, ...)
|
||||
#endif
|
||||
|
||||
#define arify_err_printf(fmt, ...) arify_log_printf(fmt, "E", __VA_ARGS__)
|
||||
|
||||
typedef void (arify_frontend_finalize_func) (
|
||||
void *frontend_data
|
||||
);
|
||||
|
||||
typedef int (arify_frontend_init_func) (
|
||||
struct arif_ctx *ctx,
|
||||
void **frontend_data_ptr
|
||||
);
|
||||
|
||||
struct arify_frontend {
|
||||
arify_frontend_init_func *init;
|
||||
arify_frontend_finalize_func *finalize;
|
||||
};
|
||||
|
||||
void
|
||||
arify_log_printf (
|
||||
char const *fmt,
|
||||
char const *level,
|
||||
...
|
||||
);
|
||||
|
||||
struct arif_engine const *
|
||||
arify_next_engine (
|
||||
void **engine_data_ptr
|
||||
);
|
||||
|
||||
#endif // !defined(ARIFY_H_)
|
|
@ -0,0 +1,30 @@
|
|||
/**
|
||||
* arif/include/arify_rl.h - Readline frontend for the ARIF preload library
|
||||
* ----
|
||||
*
|
||||
* Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
*
|
||||
* This file is part of ARIF, Another Readline Input Framework.
|
||||
*
|
||||
* ARIF 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.
|
||||
*
|
||||
* ARIF 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 ARIF. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef ARIFY_RL_H_
|
||||
#define ARIFY_RL_H_
|
||||
|
||||
#include "arify.h"
|
||||
|
||||
extern struct arify_frontend const arify_frontend_readline;
|
||||
|
||||
#endif // !defined(ARIFY_RL_H_)
|
|
@ -0,0 +1,10 @@
|
|||
#
|
||||
# Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
#
|
||||
# Copying and distribution of this file, with or without modification, are
|
||||
# permitted in any medium without royalty, provided the copyright notice and
|
||||
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||
#
|
||||
|
||||
libtool.m4
|
||||
lt*.m4
|
|
@ -0,0 +1,71 @@
|
|||
dnl
|
||||
dnl Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
dnl
|
||||
dnl Copying and distribution of this file, with or without modification,
|
||||
dnl are permitted in any medium without royalty,
|
||||
dnl provided the copyright notice and this notice are preserved.
|
||||
dnl This file is offered as-is, without any warranty.
|
||||
dnl
|
||||
|
||||
dnl
|
||||
dnl ARIF_ARG_ENABLE(feature, default-value, description, [extra-msg],
|
||||
dnl [action-if-enabled], [action-if-disabled])
|
||||
dnl
|
||||
dnl Wrapper for AC_ARG_ENABLE.
|
||||
dnl
|
||||
AC_DEFUN([ARIF_ARG_ENABLE], [
|
||||
m4_pushdef([arg_action_], m4_if([$2], [no], [enable], [disable]))
|
||||
m4_pushdef([enable_var_], [enable_]m4_translit([$1], [-+.], [___]))
|
||||
AC_MSG_CHECKING(m4_normalize([if $3 is enabled]))
|
||||
AC_ARG_ENABLE([$1], m4_normalize([
|
||||
AS_HELP_STRING([--]arg_action_[-$1], arg_action_ [$3 $4])
|
||||
]), [], [
|
||||
AS_VAR_SET(enable_var_, [$2])
|
||||
])
|
||||
AS_VAR_IF(enable_var_, [no], [
|
||||
$6
|
||||
AC_MSG_RESULT([no])
|
||||
], [
|
||||
$5
|
||||
AC_MSG_RESULT([yes])
|
||||
])
|
||||
m4_popdef([arg_action_])
|
||||
m4_popdef([enable_var_])
|
||||
])
|
||||
|
||||
dnl
|
||||
dnl ARIF_CHECK_PKG(package, version, package-name, [action-if-not-given],
|
||||
dnl [action-if-found], [action-if-without])
|
||||
dnl
|
||||
dnl Checks if a package exists with `pkg-config', and provides option for
|
||||
dnl the configure script to specify the package's custom install location.
|
||||
dnl
|
||||
AC_DEFUN([ARIF_CHECK_PKG], [
|
||||
m4_pushdef([with_var_], [with_]m4_translit([$1], [-+.], [___]))
|
||||
AC_ARG_WITH([$1], m4_normalize([
|
||||
AS_HELP_STRING([--with-$1[[=PREFIX]]], [installation path of $3])
|
||||
]), [], [$4])
|
||||
AS_VAR_IF(with_var_, [no], [$6], [
|
||||
AS_VAR_SET([SAVED_PKG_CONFIG_PATH_], ["${PKG_CONFIG_PATH}"])
|
||||
AS_VAR_IF(with_var_, [yes], [], [
|
||||
AS_VAR_SET([PKG_CONFIG_PATH],
|
||||
["${with_$1}/lib/pkgconfig:${PKG_CONFIG_PATH}"])
|
||||
])
|
||||
export PKG_CONFIG_PATH
|
||||
PKG_CHECK_MODULES(m4_toupper([$1]), [$1 $2], [$5])
|
||||
AS_VAR_SET([PKG_CONFIG_PATH], ["${SAVED_PKG_CONFIG_PATH_}"])
|
||||
])
|
||||
m4_popdef([with_var_])
|
||||
])
|
||||
|
||||
dnl
|
||||
dnl ARIF_TRY_APPLY(macro-name, ...)
|
||||
dnl
|
||||
dnl If `macro-name' is defined, for each remaining argument,
|
||||
dnl applies the macro to that argument.
|
||||
dnl
|
||||
AC_DEFUN([ARIF_TRY_APPLY], [
|
||||
m4_ifdef([$1], [
|
||||
m4_foreach([val_], [m4_shift($@)], [$1(val_)])
|
||||
])
|
||||
])
|
|
@ -0,0 +1,44 @@
|
|||
#
|
||||
# Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
#
|
||||
# Copying and distribution of this file, with or without modification, are
|
||||
# permitted in any medium without royalty, provided the copyright notice and
|
||||
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||
#
|
||||
|
||||
bin_PROGRAMS =
|
||||
lib_LTLIBRARIES = libarif.la
|
||||
|
||||
ARIF_CPPFLAGS_ = -I$(top_srcdir)/include
|
||||
|
||||
libarif_la_CPPFLAGS = $(READLINE_CFLAGS) $(ARIF_CPPFLAGS_)
|
||||
libarif_la_LIBADD = $(READLINE_LIBS)
|
||||
libarif_la_SOURCES = arif.c
|
||||
|
||||
|
||||
if BUILD_ARIF_READLINE
|
||||
|
||||
libarif_la_SOURCES += arif_rl.c
|
||||
|
||||
endif # BUILD_ARIF_READLINE
|
||||
|
||||
if BUILD_ARIFY
|
||||
|
||||
bin_PROGRAMS += arify
|
||||
lib_LTLIBRARIES += libarify.la
|
||||
|
||||
arify_CPPFLAGS = $(ARIF_CPPFLAGS_) -DARIFY_LIBDIR=$(libdir)
|
||||
arify_LDADD = libarify.la
|
||||
arify_SOURCES = arify_cli.c
|
||||
|
||||
libarify_la_CPPFLAGS = $(ARIF_CPPFLAGS_)
|
||||
libarify_la_LIBADD = $(DL_LIBS) libarif.la
|
||||
libarify_la_SOURCES = arify.c
|
||||
|
||||
if BUILD_ARIF_READLINE
|
||||
|
||||
libarify_la_SOURCES += arify_rl.c
|
||||
|
||||
endif # BUILD_ARIF_READLINE
|
||||
|
||||
endif # BUILD_ARIFY
|
|
@ -0,0 +1,489 @@
|
|||
/**
|
||||
* arif/src/arif.c - ARIF base library
|
||||
* ----
|
||||
*
|
||||
* Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
*
|
||||
* This file is part of ARIF, Another Readline Input Framework.
|
||||
*
|
||||
* ARIF 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.
|
||||
*
|
||||
* ARIF 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 ARIF. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include "arif.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct cand_page {
|
||||
struct cand_page *prev;
|
||||
struct cand_page *next;
|
||||
int size;
|
||||
struct arif_cand values[];
|
||||
};
|
||||
|
||||
struct arif_ctx {
|
||||
struct arif_opts opts;
|
||||
struct arif_engine const *engine;
|
||||
void *engine_data;
|
||||
|
||||
// candidate pages
|
||||
struct cand_page *current_page;
|
||||
struct cand_page *last_page;
|
||||
int page_num;
|
||||
bool no_more_pages;
|
||||
|
||||
// input text from previous query
|
||||
char const *old_line;
|
||||
int old_offset;
|
||||
int old_len;
|
||||
};
|
||||
|
||||
// Forward declaration start
|
||||
static struct cand_page *
|
||||
choose_candidate (struct cand_page *, int);
|
||||
static void clear_old_line (struct arif_ctx *);
|
||||
static int compare_text (char const *, int, char const *, int);
|
||||
static void copy_candidate (struct arif_cand *, struct arif_cand const *,
|
||||
int, arif_cand_disp_func *);
|
||||
static char * disp_cand_default (char const *, int, int, int *);
|
||||
static void first_candidates (struct arif_ctx *, char const *, int, int);
|
||||
static void free_page (struct cand_page *);
|
||||
static void free_page_list (struct cand_page *);
|
||||
static int last_num_offset (char const *, int);
|
||||
static struct cand_page *
|
||||
more_candidates (struct arif_ctx *, int);
|
||||
static struct cand_page *
|
||||
new_page (struct arif_cand const *, int,
|
||||
arif_cand_disp_func *);
|
||||
static void new_pages (struct arif_cand const *, int, int,
|
||||
arif_cand_disp_func *, struct cand_page **,
|
||||
struct cand_page **);
|
||||
// Forward declaration end
|
||||
|
||||
static struct cand_page *
|
||||
choose_candidate (
|
||||
struct cand_page *page,
|
||||
int idx
|
||||
) {
|
||||
if (page == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (idx < 1 || idx > page->size) {
|
||||
return NULL;
|
||||
}
|
||||
struct arif_cand *cand = &page->values[idx - 1];
|
||||
|
||||
int size = sizeof(struct cand_page) + sizeof(struct arif_cand);
|
||||
struct cand_page *new_page = malloc(size);
|
||||
assert(new_page != NULL);
|
||||
*new_page = (struct cand_page) {
|
||||
.size = 1,
|
||||
};
|
||||
*new_page->values = *cand;
|
||||
|
||||
cand->display = NULL;
|
||||
free_page_list(page);
|
||||
return new_page;
|
||||
}
|
||||
|
||||
static inline void
|
||||
clear_old_line (
|
||||
struct arif_ctx *ctx
|
||||
) {
|
||||
free((char *) ctx->old_line);
|
||||
ctx->old_line = NULL;
|
||||
ctx->old_offset = 0;
|
||||
ctx->old_len = 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
compare_text (
|
||||
char const *text1,
|
||||
int len1,
|
||||
char const *text2,
|
||||
int len2
|
||||
) {
|
||||
if (len1 != len2) {
|
||||
return -1;
|
||||
}
|
||||
return memcmp(text1, text2, len1);
|
||||
}
|
||||
|
||||
static inline void
|
||||
copy_candidate (
|
||||
struct arif_cand *dest,
|
||||
struct arif_cand const *src,
|
||||
int idx,
|
||||
arif_cand_disp_func *disp_cand
|
||||
) {
|
||||
int display_len;
|
||||
char *display = disp_cand(src->text, src->len, idx + 1, &display_len);
|
||||
|
||||
*dest = (struct arif_cand) {
|
||||
.text = src->text,
|
||||
.len = src->len,
|
||||
.replace_len = src->replace_len,
|
||||
.transform = src->transform,
|
||||
.transform_len = src->transform_len,
|
||||
.display = display,
|
||||
.display_len = display_len,
|
||||
};
|
||||
}
|
||||
|
||||
static char *
|
||||
disp_cand_default (
|
||||
char const *text,
|
||||
int len,
|
||||
int idx,
|
||||
int *display_len_ptr
|
||||
) {
|
||||
char const *fmt = "[%d] %.*s";
|
||||
int display_len = snprintf(NULL, 0, fmt, idx, len, text);
|
||||
assert(display_len >= 0);
|
||||
|
||||
char *disp = malloc(sizeof(char) * (display_len + 1));
|
||||
assert(disp != NULL);
|
||||
|
||||
sprintf(disp, fmt, idx, len, text);
|
||||
|
||||
*display_len_ptr = display_len;
|
||||
return disp;
|
||||
}
|
||||
|
||||
static void
|
||||
first_candidates (
|
||||
struct arif_ctx *ctx,
|
||||
char const *line,
|
||||
int offset,
|
||||
int len
|
||||
) {
|
||||
struct cand_page *current_page = NULL;
|
||||
struct cand_page *last_page = NULL;
|
||||
|
||||
int num_required = ctx->opts.page_size;
|
||||
struct arif_cand const *candidates;
|
||||
int num_fetched = ctx->engine->query(ctx->engine_data, line, offset, len,
|
||||
num_required, &candidates);
|
||||
|
||||
ctx->no_more_pages = num_fetched < num_required;
|
||||
if (num_fetched > 0) {
|
||||
new_pages(candidates, num_fetched, num_required, ctx->opts.disp_cand,
|
||||
¤t_page, &last_page);
|
||||
}
|
||||
|
||||
ctx->current_page = current_page;
|
||||
ctx->last_page = last_page;
|
||||
ctx->page_num = 1;
|
||||
}
|
||||
|
||||
static void
|
||||
free_page(
|
||||
struct cand_page *page
|
||||
) {
|
||||
for (int i = 0; i < page->size; ++i) {
|
||||
struct arif_cand *cand = page->values + i;
|
||||
free((char *) cand->display);
|
||||
}
|
||||
free(page);
|
||||
}
|
||||
|
||||
static void
|
||||
free_page_list (
|
||||
struct cand_page *head
|
||||
) {
|
||||
if (head == NULL) {
|
||||
return;
|
||||
}
|
||||
struct cand_page *prev = head->prev;
|
||||
// free forward
|
||||
for (struct cand_page *next, *page = head; page != NULL; page = next) {
|
||||
next = page->next;
|
||||
free_page(page);
|
||||
}
|
||||
// free backward
|
||||
for (struct cand_page *next, *page = prev; page != NULL; page = next) {
|
||||
next = page->prev;
|
||||
free_page(page);
|
||||
}
|
||||
}
|
||||
|
||||
static inline int
|
||||
last_num_offset (
|
||||
char const *text,
|
||||
int len
|
||||
) {
|
||||
while (--len >= 0) {
|
||||
if (!isdigit((unsigned char) text[len])) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return len + 1;
|
||||
}
|
||||
|
||||
static struct cand_page *
|
||||
more_candidates (
|
||||
struct arif_ctx *ctx,
|
||||
int num_pages
|
||||
) {
|
||||
if (ctx->no_more_pages) {
|
||||
return NULL;
|
||||
}
|
||||
struct cand_page *last_page = ctx->last_page;
|
||||
if (last_page == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int page_size = ctx->opts.page_size;
|
||||
int last_page_size = last_page->size;
|
||||
int num_required = num_pages * page_size;
|
||||
if (last_page_size < page_size) {
|
||||
num_required -= last_page_size;
|
||||
}
|
||||
|
||||
struct arif_cand const *candidates;
|
||||
int num_fetched = ctx->engine->query(ctx->engine_data, NULL, 0, 0,
|
||||
num_required, &candidates);
|
||||
if (num_fetched < num_required) {
|
||||
ctx->no_more_pages = true;
|
||||
if (num_fetched == 0) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
arif_cand_disp_func *disp_cand = ctx->opts.disp_cand;
|
||||
|
||||
while (num_fetched > 0 && last_page_size < page_size) {
|
||||
copy_candidate(last_page->values + last_page_size, candidates++,
|
||||
last_page_size, disp_cand);
|
||||
--num_fetched;
|
||||
++last_page_size;
|
||||
}
|
||||
last_page->size = last_page_size;
|
||||
|
||||
struct cand_page *first = last_page;
|
||||
new_pages(candidates, num_fetched, page_size, disp_cand, &first,
|
||||
&ctx->last_page);
|
||||
return first;
|
||||
}
|
||||
|
||||
static struct cand_page *
|
||||
new_page (
|
||||
struct arif_cand const *candidates,
|
||||
int num,
|
||||
arif_cand_disp_func *disp_cand
|
||||
) {
|
||||
int size = sizeof(struct cand_page) + sizeof(struct arif_cand) * num;
|
||||
struct cand_page *page = malloc(size);
|
||||
assert(page != NULL);
|
||||
|
||||
*page = (struct cand_page) {
|
||||
.size = num,
|
||||
};
|
||||
for (int i = 0; i < num; ++i) {
|
||||
struct arif_cand const *src_cand = candidates + i;
|
||||
struct arif_cand *dest_cand = page->values + i;
|
||||
copy_candidate(dest_cand, src_cand, i, disp_cand);
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
static void
|
||||
new_pages (
|
||||
struct arif_cand const *candidates,
|
||||
int num_cands,
|
||||
int page_size,
|
||||
arif_cand_disp_func *disp_cand,
|
||||
struct cand_page **first_ptr,
|
||||
struct cand_page **last_ptr
|
||||
) {
|
||||
struct cand_page *first = NULL, *curr = NULL;
|
||||
struct cand_page *prev = *first_ptr;
|
||||
for (; num_cands > 0; candidates += page_size, num_cands -= page_size) {
|
||||
curr = new_page(candidates,
|
||||
num_cands > page_size ? page_size : num_cands, disp_cand);
|
||||
if (first == NULL) {
|
||||
first = curr;
|
||||
}
|
||||
if (prev != NULL) {
|
||||
prev->next = curr;
|
||||
curr->prev = prev;
|
||||
}
|
||||
prev = curr;
|
||||
}
|
||||
*first_ptr = first;
|
||||
*last_ptr = curr;
|
||||
}
|
||||
|
||||
struct arif_ctx *
|
||||
arif_ctx_create (
|
||||
struct arif_opts const *options
|
||||
) {
|
||||
struct arif_ctx *ctx = malloc(sizeof(struct arif_ctx));
|
||||
assert(ctx != NULL);
|
||||
|
||||
arif_cand_disp_func *disp_cand = options->disp_cand;
|
||||
if (disp_cand == NULL) {
|
||||
disp_cand = disp_cand_default;
|
||||
}
|
||||
|
||||
*ctx = (struct arif_ctx) {
|
||||
.opts = {
|
||||
.disp_cand = disp_cand,
|
||||
.page_size = options->page_size,
|
||||
},
|
||||
};
|
||||
return ctx;
|
||||
}
|
||||
|
||||
void
|
||||
arif_ctx_destroy (
|
||||
struct arif_ctx *ctx
|
||||
) {
|
||||
if (ctx == NULL) {
|
||||
return;
|
||||
}
|
||||
arif_set_engine(ctx, NULL, NULL);
|
||||
free(ctx);
|
||||
}
|
||||
|
||||
int
|
||||
arif_fetch (
|
||||
struct arif_ctx *ctx,
|
||||
struct arif_cand const **candidates_ptr
|
||||
) {
|
||||
struct cand_page *page = ctx->current_page;
|
||||
if (page == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
*candidates_ptr = page->values;
|
||||
return page->size;
|
||||
}
|
||||
|
||||
int
|
||||
arif_query (
|
||||
struct arif_ctx *ctx,
|
||||
char const *line,
|
||||
int offset,
|
||||
int len
|
||||
) {
|
||||
if (line == NULL || len < 1) {
|
||||
return 0;
|
||||
}
|
||||
char const *input = line + offset;
|
||||
int input_len = last_num_offset(input, len);
|
||||
char const *old_input = ctx->old_line + ctx->old_offset;
|
||||
|
||||
if (0 != compare_text(old_input, ctx->old_len, input, input_len)) {
|
||||
// new text
|
||||
char *saved_line = malloc(sizeof(char) * (offset + len));
|
||||
assert(saved_line != NULL);
|
||||
|
||||
free((char *) ctx->old_line);
|
||||
ctx->old_line = memcpy(saved_line, line, offset + len);
|
||||
ctx->old_offset = offset;
|
||||
ctx->old_len = len;
|
||||
|
||||
first_candidates(ctx, saved_line, offset, len);
|
||||
} else {
|
||||
// same text as old query
|
||||
if (input_len == len) {
|
||||
// not selecting candidate
|
||||
goto finish;
|
||||
}
|
||||
// select candidate
|
||||
int idx = atoi(input + input_len);
|
||||
struct cand_page *page = choose_candidate(ctx->current_page, idx);
|
||||
if (page == NULL) {
|
||||
// bad candidate index
|
||||
goto finish;
|
||||
}
|
||||
// tell engine that we selected a candidate
|
||||
int selected_idx = (ctx->page_num - 1) * ctx->opts.page_size + idx - 1;
|
||||
ctx->engine->query(ctx->engine_data, NULL, selected_idx, 0, 0, NULL);
|
||||
|
||||
ctx->current_page = page;
|
||||
ctx->last_page = page;
|
||||
ctx->page_num = 1;
|
||||
ctx->no_more_pages = false;
|
||||
|
||||
clear_old_line(ctx);
|
||||
}
|
||||
|
||||
finish:
|
||||
return input_len;
|
||||
}
|
||||
|
||||
int
|
||||
arif_select_page (
|
||||
struct arif_ctx *ctx,
|
||||
int idx
|
||||
) {
|
||||
struct cand_page *page = ctx->current_page;
|
||||
if (idx > 0) {
|
||||
idx -= ctx->page_num;
|
||||
} else {
|
||||
idx = idx == 0 ? 1 : -1;
|
||||
}
|
||||
int page_num = ctx->page_num + idx;
|
||||
|
||||
if (idx < 0) {
|
||||
do {
|
||||
page = page->prev;
|
||||
if (page == NULL) {
|
||||
return -1;
|
||||
}
|
||||
} while (++idx < 0);
|
||||
} else {
|
||||
while (idx-- > 0) {
|
||||
page = page->next;
|
||||
if (page == NULL) {
|
||||
page = more_candidates(ctx, idx + 1);
|
||||
if (page == NULL) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ctx->current_page = page;
|
||||
ctx->page_num = page_num;
|
||||
return page_num;
|
||||
}
|
||||
|
||||
void
|
||||
arif_set_engine (
|
||||
struct arif_ctx *ctx,
|
||||
struct arif_engine const *engine,
|
||||
void *engine_data
|
||||
) {
|
||||
free_page_list(ctx->current_page);
|
||||
ctx->current_page = NULL;
|
||||
ctx->last_page = NULL;
|
||||
ctx->page_num = 0;
|
||||
ctx->no_more_pages = false;
|
||||
|
||||
clear_old_line(ctx);
|
||||
|
||||
ctx->engine = engine;
|
||||
ctx->engine_data = engine_data;
|
||||
}
|
|
@ -0,0 +1,153 @@
|
|||
/**
|
||||
* arif/src/arif_rl.c - ARIF Readline frontend
|
||||
* ----
|
||||
*
|
||||
* Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
*
|
||||
* This file is part of ARIF, Another Readline Input Framework.
|
||||
*
|
||||
* ARIF 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.
|
||||
*
|
||||
* ARIF 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 ARIF. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include "arif_rl.h"
|
||||
|
||||
#ifdef HAVE_READLINE
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <readline/readline.h>
|
||||
|
||||
#include "arif_defs.h"
|
||||
|
||||
char **
|
||||
arif_rl_complete(
|
||||
struct arif_ctx *ctx,
|
||||
char const *text,
|
||||
int start,
|
||||
int end
|
||||
) {
|
||||
// skip right next to the last non-ASCII character
|
||||
int skip;
|
||||
for (skip = end - start; skip >= 0; --skip) {
|
||||
unsigned char ch = text[skip];
|
||||
if (0 != ch >> 7) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
start += ++skip;
|
||||
|
||||
rl_attempted_completion_over = 1;
|
||||
rl_completion_suppress_append = 1;
|
||||
rl_completion_suppress_quote = 1;
|
||||
|
||||
end = arif_query(ctx, rl_line_buffer, start, end - start);
|
||||
if (end <= 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct arif_cand const *cand;
|
||||
int num = arif_fetch(ctx, &cand);
|
||||
if (num == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char **comp_list = malloc(sizeof(char *) * (num + 2));
|
||||
assert(comp_list != NULL);
|
||||
|
||||
for (int idx = 1; idx <= num; ++idx, ++cand) {
|
||||
char const *line;
|
||||
int line_len;
|
||||
if (cand->transform != NULL) {
|
||||
line = cand->transform;
|
||||
line_len = cand->transform_len;
|
||||
} else {
|
||||
line = text + skip;
|
||||
line_len = end;
|
||||
}
|
||||
|
||||
int len = line_len - cand->replace_len + cand->len + skip;
|
||||
char *match = malloc(sizeof(char) * (len + 1));
|
||||
assert(match != NULL);
|
||||
|
||||
memcpy(match, text, skip);
|
||||
memcpy(match + skip, cand->text, cand->len);
|
||||
memcpy(match + skip + cand->len, line + cand->replace_len,
|
||||
len - cand->len - skip);
|
||||
match[len] = '\0';
|
||||
comp_list[idx] = match;
|
||||
}
|
||||
comp_list[num + 1] = NULL;
|
||||
|
||||
// Readline inserts completion matches by common prefix.
|
||||
// What we want:
|
||||
// - if there is only one candidate, insert it
|
||||
// - if there are multiple candidates, insert nothing
|
||||
if (num == 1) {
|
||||
comp_list[0] = comp_list[1];
|
||||
comp_list[1] = NULL;
|
||||
} else {
|
||||
char *match = malloc(sizeof(char));
|
||||
assert(match != NULL);
|
||||
match[0] = '\0';
|
||||
comp_list[0] = match;
|
||||
}
|
||||
|
||||
return comp_list;
|
||||
}
|
||||
|
||||
void
|
||||
arif_rl_display(
|
||||
struct arif_ctx *ctx,
|
||||
char **ARIF_UNUSED_ARG(matches),
|
||||
int num,
|
||||
int max_len
|
||||
) {
|
||||
char **disp_list = malloc(sizeof(char *) * (num + 2));
|
||||
assert(NULL != disp_list);
|
||||
|
||||
struct arif_cand const *cand;
|
||||
assert(num == arif_fetch(ctx, &cand));
|
||||
|
||||
disp_list[0] = "";
|
||||
for (int idx = 1; idx <= num; ++idx, ++cand) {
|
||||
int disp_len = cand->display_len;
|
||||
if (disp_len > max_len) {
|
||||
max_len = disp_len;
|
||||
}
|
||||
|
||||
char *disp = malloc(sizeof(char) * (disp_len + 1));
|
||||
assert(disp != NULL);
|
||||
disp_list[idx] = memcpy(disp, cand->display, disp_len);
|
||||
disp[disp_len] = '\0';
|
||||
}
|
||||
disp_list[num + 1] = NULL;
|
||||
|
||||
rl_display_match_list(disp_list, num, max_len);
|
||||
|
||||
for (int i = 1; i <= num; ++i) {
|
||||
free(disp_list[i]);
|
||||
}
|
||||
free(disp_list);
|
||||
|
||||
rl_forced_update_display();
|
||||
}
|
||||
|
||||
#endif // defined(HAVE_READLINE)
|
|
@ -0,0 +1,406 @@
|
|||
/**
|
||||
* arif/src/arify.c - ARIF preload library
|
||||
* ----
|
||||
*
|
||||
* Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
*
|
||||
* This file is part of ARIF, Another Readline Input Framework.
|
||||
*
|
||||
* ARIF 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.
|
||||
*
|
||||
* ARIF 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 ARIF. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include "arify.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "arif.h"
|
||||
#include "arif_defs.h"
|
||||
|
||||
#ifdef HAVE_READLINE
|
||||
# include "arify_rl.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR
|
||||
# define ARIF_CTOR __attribute__((constructor))
|
||||
#else
|
||||
# error "__attribute__((constructor)) not supported"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_FUNC_ATTRIBUTE_DESTRUCTOR
|
||||
# define ARIF_DTOR __attribute__((destructor))
|
||||
#else
|
||||
# error "__attribute__((destructor)) not supported"
|
||||
#endif
|
||||
|
||||
#ifndef ARIFY_MAX_PAGE_SIZE
|
||||
# define ARIFY_MAX_PAGE_SIZE 99
|
||||
#endif
|
||||
|
||||
#ifndef ARIFY_LOG_TIME_MAXLEN
|
||||
# define ARIFY_LOG_TIME_MAXLEN 16
|
||||
#endif
|
||||
|
||||
struct arify_engine {
|
||||
char const *lib_name;
|
||||
char const *var_name;
|
||||
void *handle;
|
||||
struct arif_engine *impl;
|
||||
void *data;
|
||||
struct arify_engine *next;
|
||||
};
|
||||
|
||||
// Forward declaration start
|
||||
static int config_engines (void);
|
||||
static int config_frontend (void);
|
||||
static int config_log_file (void);
|
||||
static int config_page_size (void);
|
||||
static char const * current_time (void);
|
||||
static void finalize (void) ARIF_DTOR;
|
||||
static void finalize_engines (struct arify_engine *);
|
||||
static char const * get_env (char const *, char const *);
|
||||
static int init_config (void);
|
||||
static void initialize (void) ARIF_CTOR;
|
||||
static int load_engine (struct arify_engine *);
|
||||
// Forward declaration end
|
||||
|
||||
struct arify_ctx {
|
||||
struct arify_engine *engines;
|
||||
struct arify_engine *current_engine;
|
||||
char *engines_str;
|
||||
struct arify_frontend const *frontend;
|
||||
void *frontend_data;
|
||||
struct arif_ctx *ctx;
|
||||
FILE *log_file;
|
||||
int log_fd;
|
||||
int page_size;
|
||||
long pid;
|
||||
};
|
||||
|
||||
static struct arify_ctx ctx;
|
||||
|
||||
static int
|
||||
config_engines (void)
|
||||
{
|
||||
char const *engines_str = get_env("ARIFY_ENGINES", "");
|
||||
size_t engines_len = strlen(engines_str) + 1;
|
||||
char *names = malloc(sizeof(char) * engines_len);
|
||||
assert(names != NULL);
|
||||
ctx.engines_str = memcpy(names, engines_str, engines_len);
|
||||
|
||||
char const *delim = " \n\t\r\v\f";
|
||||
|
||||
struct arify_engine dummy_engine = { .next = NULL };
|
||||
struct arify_engine *engine = &dummy_engine;
|
||||
for (char *name = strtok(names, delim); name != NULL;
|
||||
name = strtok(NULL, delim)
|
||||
) {
|
||||
engine = engine->next = malloc(sizeof(struct arify_engine));
|
||||
assert(engine != NULL);
|
||||
|
||||
char *var_name = strchr(name, ':');
|
||||
if (var_name != NULL) {
|
||||
*(var_name++) = '\0';
|
||||
}
|
||||
*engine = (struct arify_engine) {
|
||||
.lib_name = name,
|
||||
.var_name = var_name,
|
||||
};
|
||||
}
|
||||
|
||||
ctx.current_engine = ctx.engines = dummy_engine.next;
|
||||
if (ctx.engines == NULL) {
|
||||
arify_err_printf("%s", "at least one engine should be specified");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
config_frontend (void)
|
||||
{
|
||||
char const *frontend_str = get_env("ARIFY_FRONTEND", "readline");
|
||||
#ifdef HAVE_READLINE
|
||||
if (0 == strcmp("readline", frontend_str)) {
|
||||
ctx.frontend = &arify_frontend_readline;
|
||||
return 0;
|
||||
}
|
||||
#endif // defined(HAVE_READLINE)
|
||||
arify_err_printf("unsupported frontend '%s'", frontend_str);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
config_log_file (void)
|
||||
{
|
||||
char const *log_file_path = get_env("ARIFY_LOG_FILE", "/dev/null");
|
||||
ctx.log_file = fopen(log_file_path, "a");
|
||||
if (ctx.log_file == NULL) {
|
||||
return -1;
|
||||
}
|
||||
setvbuf(ctx.log_file, NULL, _IOLBF, 0);
|
||||
|
||||
int fd = fileno(ctx.log_file);
|
||||
if (fd < 0) {
|
||||
return -1;
|
||||
}
|
||||
ctx.log_fd = fd;
|
||||
|
||||
ctx.pid = (long) getpid();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
config_page_size (void)
|
||||
{
|
||||
char const *page_size_str = get_env("ARIFY_PAGE_SIZE", "5");
|
||||
errno = 0;
|
||||
long page_size = strtol(page_size_str, NULL, 10);
|
||||
if (errno != 0) {
|
||||
arify_err_printf("invalid page size '%s'", page_size_str);
|
||||
return -1;
|
||||
}
|
||||
if (page_size < 1 || page_size > ARIFY_MAX_PAGE_SIZE) {
|
||||
arify_err_printf("bad page size %d, should be in range 1~%d",
|
||||
page_size, ARIFY_MAX_PAGE_SIZE);
|
||||
return -1;
|
||||
}
|
||||
ctx.page_size = page_size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char const *
|
||||
current_time (void)
|
||||
{
|
||||
static char buf[ARIFY_LOG_TIME_MAXLEN];
|
||||
|
||||
time_t ts = time(NULL);
|
||||
assert(ts != ((time_t) -1));
|
||||
|
||||
struct tm const *tm = localtime(&ts);
|
||||
assert(tm != NULL);
|
||||
|
||||
strftime(buf, ARIFY_LOG_TIME_MAXLEN, "%T", tm);
|
||||
return buf;
|
||||
}
|
||||
|
||||
static void
|
||||
finalize (void)
|
||||
{
|
||||
if (ctx.frontend != NULL) {
|
||||
ctx.frontend->finalize(ctx.frontend_data);
|
||||
}
|
||||
finalize_engines(ctx.engines);
|
||||
arif_ctx_destroy(ctx.ctx);
|
||||
free(ctx.engines_str);
|
||||
|
||||
arify_debug_printf("%s", "finalized");
|
||||
if (ctx.log_file != NULL) {
|
||||
fclose(ctx.log_file);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
finalize_engines (
|
||||
struct arify_engine *engine
|
||||
) {
|
||||
for (struct arify_engine *next; engine != NULL; engine = next) {
|
||||
if (engine->impl != NULL) {
|
||||
engine->impl->finalize(engine->data);
|
||||
}
|
||||
if (engine->handle != NULL) {
|
||||
dlclose(engine->handle);
|
||||
}
|
||||
|
||||
next = engine->next;
|
||||
free(engine);
|
||||
}
|
||||
}
|
||||
|
||||
static char const *
|
||||
get_env (
|
||||
char const *name,
|
||||
char const *default_val
|
||||
) {
|
||||
char const *val = getenv(name);
|
||||
if (val == NULL || val[0] == '\0') {
|
||||
val = default_val;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
static int
|
||||
init_config (void)
|
||||
{
|
||||
if (0 != config_log_file()) {
|
||||
return -1;
|
||||
}
|
||||
if (0 != config_frontend()) {
|
||||
return -1;
|
||||
}
|
||||
if (0 != config_engines()) {
|
||||
return -1;
|
||||
}
|
||||
if (0 != config_page_size()) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
initialize (void)
|
||||
{
|
||||
if (0 != init_config()) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct arif_opts opts = {
|
||||
.page_size = ctx.page_size,
|
||||
};
|
||||
ctx.ctx = arif_ctx_create(&opts);
|
||||
if (ctx.ctx == NULL) {
|
||||
arify_err_printf("%s", "failed to create input context");
|
||||
return;
|
||||
}
|
||||
|
||||
int result = ctx.frontend->init(ctx.ctx, &ctx.frontend_data);
|
||||
if (result != 0) {
|
||||
arify_err_printf("frontend init failed with return value %d", result);
|
||||
return;
|
||||
}
|
||||
|
||||
arify_debug_printf("%s", "initialized");
|
||||
}
|
||||
|
||||
static int
|
||||
load_engine (
|
||||
struct arify_engine *engine
|
||||
) {
|
||||
char const *lib_name = engine->lib_name;
|
||||
char const *var_name = engine->var_name;
|
||||
char *lib_tmp = NULL;
|
||||
char *var_tmp = NULL;
|
||||
|
||||
if (var_name == NULL) {
|
||||
size_t lib_name_len = 7 + strlen(lib_name) + sizeof ARIF_SHLIB_SUFFIX;
|
||||
lib_tmp = malloc(sizeof(char) * lib_name_len);
|
||||
assert(lib_tmp != NULL);
|
||||
sprintf(lib_tmp, "libarif%s" ARIF_SHLIB_SUFFIX, lib_name);
|
||||
|
||||
size_t var_name_len = 12 + strlen(lib_name) + 1;
|
||||
var_tmp = malloc(sizeof(char) * var_name_len);
|
||||
assert(var_tmp != NULL);
|
||||
sprintf(var_tmp, "arif_%s_engine", lib_name);
|
||||
|
||||
lib_name = lib_tmp;
|
||||
var_name = var_tmp;
|
||||
}
|
||||
|
||||
int result = -1;
|
||||
|
||||
void *handle = dlopen(lib_name, RTLD_NOW);
|
||||
if (handle == NULL) {
|
||||
arify_err_printf("failed to load engine %s: %s", lib_name, dlerror());
|
||||
goto finish;
|
||||
}
|
||||
engine->handle = handle;
|
||||
|
||||
struct arif_engine *engine_impl = dlsym(handle, var_name);
|
||||
if (engine_impl == NULL) {
|
||||
arify_err_printf("failed to find symbol %s for engine %s: %s",
|
||||
var_name, lib_name, dlerror());
|
||||
goto finish;
|
||||
}
|
||||
|
||||
int init_status = engine_impl->init(NULL, &engine->data);
|
||||
if (init_status != 0) {
|
||||
arify_err_printf("failed to initialize engine %s: %d",
|
||||
lib_name, init_status);
|
||||
goto finish;
|
||||
}
|
||||
engine->impl = engine_impl;
|
||||
|
||||
result = 0;
|
||||
|
||||
finish:
|
||||
free(lib_tmp);
|
||||
free(var_tmp);
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
arify_log_printf (
|
||||
char const *fmt,
|
||||
char const *level,
|
||||
...
|
||||
) {
|
||||
struct flock lock = {
|
||||
.l_start = SEEK_SET,
|
||||
.l_len = 0,
|
||||
};
|
||||
lock.l_type = F_WRLCK;
|
||||
fcntl(ctx.log_fd, F_SETLKW, &lock);
|
||||
|
||||
fprintf(ctx.log_file, "[%s %ld %s] ", current_time(), ctx.pid, level);
|
||||
|
||||
va_list args;
|
||||
va_start(args, level);
|
||||
vfprintf(ctx.log_file, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
fputc('\n', ctx.log_file);
|
||||
|
||||
lock.l_type = F_UNLCK;
|
||||
fcntl(ctx.log_fd, F_SETLK, &lock);
|
||||
}
|
||||
|
||||
struct arif_engine const *
|
||||
arify_next_engine (
|
||||
void **engine_data_ptr
|
||||
) {
|
||||
struct arify_engine *engine = ctx.current_engine;
|
||||
struct arif_engine *engine_impl = NULL;
|
||||
void *engine_data = NULL;
|
||||
while (engine != NULL) {
|
||||
ARIF_DEBUG_ASSERT(engine->impl == NULL);
|
||||
int result = load_engine(engine);
|
||||
|
||||
engine_impl = engine->impl;
|
||||
engine_data = engine->data;
|
||||
engine = engine->next;
|
||||
|
||||
if (result == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
ctx.current_engine = engine;
|
||||
|
||||
*engine_data_ptr = engine_data;
|
||||
return engine_impl;
|
||||
}
|
|
@ -0,0 +1,194 @@
|
|||
/**
|
||||
* arif/src/arify_cli.c - CLI wrapper for the ARIF preload library
|
||||
* ----
|
||||
*
|
||||
* Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
*
|
||||
* This file is part of ARIF, Another Readline Input Framework.
|
||||
*
|
||||
* ARIF 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.
|
||||
*
|
||||
* ARIF 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 ARIF. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <getopt.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "arif.h"
|
||||
#include "arif_defs.h"
|
||||
|
||||
#ifndef ARIFY_LIBDIR
|
||||
#define ARIFY_LIBDIR /usr/local/lib
|
||||
#endif
|
||||
#define ARIFY_PRELOAD_LIB_(libdir) #libdir "/libarify" ARIF_SHLIB_SUFFIX
|
||||
#define ARIFY_PRELOAD_LIB(libdir) ARIFY_PRELOAD_LIB_(libdir)
|
||||
|
||||
struct options {
|
||||
char *frontend;
|
||||
char *engines;
|
||||
char *log_file;
|
||||
char *page_size;
|
||||
char *preload;
|
||||
};
|
||||
|
||||
// Forward declaration start
|
||||
static void append_str (char const *, char **, char);
|
||||
static char * concat_str (char const *, char const *, char);
|
||||
static int parse_options (int, char *const [], struct options *);
|
||||
static void print_usage (char const *) ARIF_NORETURN;
|
||||
static void set_envs (struct options *);
|
||||
// Forward declaration end
|
||||
|
||||
static void
|
||||
append_str (
|
||||
char const *src,
|
||||
char **dest_ptr,
|
||||
char sep
|
||||
) {
|
||||
char *dest = *dest_ptr;
|
||||
|
||||
size_t src_len = strlen(src) + 1;
|
||||
size_t dest_len = dest == NULL ? 0 : strlen(dest);
|
||||
|
||||
*dest_ptr = dest = realloc(dest, src_len + dest_len + 1);
|
||||
assert(dest != NULL);
|
||||
|
||||
dest[dest_len++] = sep;
|
||||
memcpy(dest + dest_len, src, src_len);
|
||||
}
|
||||
|
||||
static char *
|
||||
concat_str (
|
||||
char const *left,
|
||||
char const *right,
|
||||
char sep
|
||||
) {
|
||||
size_t left_len = strlen(left);
|
||||
size_t right_len = strlen(right) + 1;
|
||||
|
||||
char *dest = malloc(sizeof(char) * (left_len + right_len + 1));
|
||||
assert(dest != NULL);
|
||||
|
||||
memcpy(dest, left, left_len);
|
||||
dest[left_len++] = sep;
|
||||
memcpy(dest + left_len, right, right_len);
|
||||
return dest;
|
||||
}
|
||||
|
||||
static int
|
||||
parse_options (
|
||||
int argc,
|
||||
char *const argv[],
|
||||
struct options *opts
|
||||
) {
|
||||
while (1) {
|
||||
switch (getopt(argc, argv, "e:f:p:l:n:HV")) {
|
||||
case 'e':
|
||||
append_str(optarg, &opts->engines, ' ');
|
||||
break;
|
||||
case 'f':
|
||||
opts->frontend = optarg;
|
||||
break;
|
||||
case 'p':
|
||||
opts->preload = optarg;
|
||||
break;
|
||||
case 'l':
|
||||
opts->log_file = optarg;
|
||||
break;
|
||||
case 'n':
|
||||
opts->page_size = optarg;
|
||||
break;
|
||||
case 'V':
|
||||
fprintf(stderr, "arify (ARIF %d.%d.%d)\n",
|
||||
ARIF_VER_MAJOR, ARIF_VER_MINOR, ARIF_VER_PATCH);
|
||||
exit(EXIT_SUCCESS);
|
||||
case -1:
|
||||
return optind;
|
||||
case '?':
|
||||
default:
|
||||
print_usage(argv[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
print_usage (
|
||||
char const *program
|
||||
) {
|
||||
fputs("Usage: ", stderr);
|
||||
fputs(program, stderr);
|
||||
fputs(" [options] filepath [args]\n\n", stderr);
|
||||
fputs("See the arify(1) man page for details.\n", stderr);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static void
|
||||
set_envs (
|
||||
struct options *opts
|
||||
) {
|
||||
if (opts->frontend != NULL) {
|
||||
setenv("ARIFY_FRONTEND", opts->frontend, 1);
|
||||
}
|
||||
if (opts->engines != NULL) {
|
||||
setenv("ARIFY_ENGINES", opts->engines, 1);
|
||||
}
|
||||
if (opts->log_file != NULL) {
|
||||
setenv("ARIFY_LOG_FILE", opts->log_file, 1);
|
||||
}
|
||||
if (opts->page_size != NULL) {
|
||||
setenv("ARIFY_PAGE_SIZE", opts->page_size, 1);
|
||||
}
|
||||
|
||||
char *old_preload = getenv("LD_PRELOAD");
|
||||
if (old_preload == NULL) {
|
||||
old_preload = "";
|
||||
}
|
||||
opts->preload = concat_str(old_preload, opts->preload, ':');
|
||||
setenv("LD_PRELOAD", opts->preload, 1);
|
||||
}
|
||||
|
||||
int
|
||||
main (
|
||||
int argc,
|
||||
char *argv[]
|
||||
) {
|
||||
char const *program = argv[0];
|
||||
assert(program != NULL);
|
||||
|
||||
struct options opts = {
|
||||
.preload = ARIFY_PRELOAD_LIB(ARIFY_LIBDIR),
|
||||
};
|
||||
argv += parse_options(argc, argv, &opts);
|
||||
set_envs(&opts);
|
||||
free(opts.engines);
|
||||
free(opts.preload);
|
||||
|
||||
if (argv[0] == NULL) {
|
||||
fprintf(stderr, "%s: no executable file specified\n", program);
|
||||
print_usage(program);
|
||||
}
|
||||
if (-1 == execvp(argv[0], argv)) {
|
||||
fprintf(stderr, "%s: %s: %s\n", program, argv[0], strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,369 @@
|
|||
/**
|
||||
* arif/src/arify_rl.c - Readline frontend for the ARIF preload library
|
||||
* ----
|
||||
*
|
||||
* Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
*
|
||||
* This file is part of ARIF, Another Readline Input Framework.
|
||||
*
|
||||
* ARIF 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.
|
||||
*
|
||||
* ARIF 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 ARIF. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include "arify_rl.h"
|
||||
|
||||
#ifdef HAVE_READLINE
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <readline/readline.h>
|
||||
|
||||
#include "arif_defs.h"
|
||||
#include "arif_rl.h"
|
||||
|
||||
struct arify_rl_engine {
|
||||
struct arif_engine const *engine;
|
||||
void *engine_data;
|
||||
struct arify_rl_engine *next;
|
||||
};
|
||||
|
||||
// Forward declaration start
|
||||
static char ** complete (char const *, int, int);
|
||||
static void disable_arify (bool);
|
||||
static void display_hook (char **, int, int);
|
||||
static void enable_arify (void);
|
||||
|
||||
static void get_engine_info (struct arify_rl_engine const *,
|
||||
char const **, char const **);
|
||||
static void finalize (void *);
|
||||
static struct arify_rl_engine *
|
||||
get_next_engine (void);
|
||||
static int initialize (struct arif_ctx *, void **);
|
||||
static int rlfunc_engine_info (int, int);
|
||||
static int rlfunc_next_engine (int, int);
|
||||
static int rlfunc_page_down (int, int);
|
||||
static int rlfunc_page_up (int, int);
|
||||
static int rlfunc_toggle (int, int);
|
||||
static void rlprintf (char const *, ...);
|
||||
// Forward declaration end
|
||||
|
||||
struct arify_funmap_entry {
|
||||
char const *name;
|
||||
rl_command_func_t *func;
|
||||
};
|
||||
|
||||
struct arify_rl_ctx {
|
||||
struct arif_ctx *ctx;
|
||||
struct arify_rl_engine *engines;
|
||||
struct arify_rl_engine *current_engine;
|
||||
bool enabled;
|
||||
char const *old_basic_quote_chars;
|
||||
rl_completion_func_t *old_comp_func;
|
||||
rl_compdisp_func_t *old_disp_func;
|
||||
int old_ignore_duplicates;
|
||||
int old_query_items;
|
||||
int old_sort_matches;
|
||||
};
|
||||
|
||||
struct arify_frontend const arify_frontend_readline = {
|
||||
.init = initialize,
|
||||
.finalize = finalize,
|
||||
};
|
||||
|
||||
static struct arify_funmap_entry const funmap_entries[] = {
|
||||
{ "arify-toggle", rlfunc_toggle },
|
||||
{ "arify-next-engine", rlfunc_next_engine },
|
||||
{ "arify-page-up", rlfunc_page_up },
|
||||
{ "arify-page-down", rlfunc_page_down },
|
||||
{ "arify-engine-info", rlfunc_engine_info },
|
||||
};
|
||||
|
||||
static struct arify_rl_ctx rlctx;
|
||||
|
||||
static char **
|
||||
complete (
|
||||
char const *text,
|
||||
int start,
|
||||
int end
|
||||
) {
|
||||
arify_debug_printf("%s", "complete");
|
||||
|
||||
return arif_rl_complete(rlctx.ctx, text, start, end);
|
||||
}
|
||||
|
||||
static void
|
||||
disable_arify (
|
||||
bool supress_message
|
||||
) {
|
||||
rl_basic_quote_characters = rlctx.old_basic_quote_chars;
|
||||
rl_attempted_completion_function = rlctx.old_comp_func;
|
||||
rl_completion_display_matches_hook = rlctx.old_disp_func;
|
||||
rl_completion_query_items = rlctx.old_query_items;
|
||||
rl_ignore_completion_duplicates = rlctx.old_ignore_duplicates;
|
||||
rl_sort_completion_matches = rlctx.old_sort_matches;
|
||||
|
||||
rlctx.enabled = false;
|
||||
if (!supress_message) {
|
||||
rlprintf("%s", "[arify] disabled");
|
||||
}
|
||||
arify_debug_printf("%s", "disabled");
|
||||
}
|
||||
|
||||
static void
|
||||
display_hook (
|
||||
char **matches,
|
||||
int num,
|
||||
int max_len
|
||||
) {
|
||||
arify_debug_printf("%s", "display hook");
|
||||
|
||||
arif_rl_display(rlctx.ctx, matches, num, max_len);
|
||||
}
|
||||
|
||||
static void
|
||||
enable_arify (void)
|
||||
{
|
||||
if (rlctx.current_engine == NULL) {
|
||||
struct arify_rl_engine *entry = get_next_engine();
|
||||
if (entry == NULL) {
|
||||
arify_err_printf("%s", "no available engines");
|
||||
return;
|
||||
}
|
||||
rlctx.current_engine = rlctx.engines = entry;
|
||||
arif_set_engine(rlctx.ctx, entry->engine, entry->engine_data);
|
||||
}
|
||||
|
||||
rlctx.old_basic_quote_chars = rl_basic_quote_characters;
|
||||
rlctx.old_comp_func = rl_attempted_completion_function;
|
||||
rlctx.old_disp_func = rl_completion_display_matches_hook;
|
||||
rlctx.old_query_items = rl_completion_query_items;
|
||||
rlctx.old_ignore_duplicates = rl_ignore_completion_duplicates;
|
||||
rlctx.old_sort_matches = rl_sort_completion_matches;
|
||||
|
||||
// This is necessary, as rl_complete_internal() appends these characters
|
||||
// even with rl_completion_suppress_quote set to non-zero
|
||||
rl_basic_quote_characters = "";
|
||||
rl_attempted_completion_function = complete;
|
||||
rl_completion_display_matches_hook = display_hook;
|
||||
rl_completion_query_items = 0;
|
||||
rl_ignore_completion_duplicates = 0;
|
||||
rl_sort_completion_matches = 0;
|
||||
|
||||
char const *engine_name;
|
||||
get_engine_info(rlctx.current_engine, &engine_name, NULL);
|
||||
rlprintf("[arify] enabled (engine: %s)", engine_name);
|
||||
|
||||
rlctx.enabled = true;
|
||||
arify_debug_printf("%s", "enabled");
|
||||
}
|
||||
|
||||
static void
|
||||
get_engine_info (
|
||||
struct arify_rl_engine const *entry,
|
||||
char const **name_ptr,
|
||||
char const **description_ptr
|
||||
) {
|
||||
char const *name, *description;
|
||||
if (name_ptr == NULL) {
|
||||
name_ptr = &name;
|
||||
}
|
||||
if (description_ptr == NULL) {
|
||||
description_ptr = &description;
|
||||
}
|
||||
|
||||
struct arif_engine const *engine = entry->engine;
|
||||
if (engine->info != NULL) {
|
||||
engine->info(entry->engine_data, name_ptr, description_ptr);
|
||||
} else {
|
||||
*name_ptr = "";
|
||||
*description_ptr = "";
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
finalize (
|
||||
void *ARIF_UNUSED_ARG(frontend_data)
|
||||
) {
|
||||
if (rlctx.enabled) {
|
||||
disable_arify(true);
|
||||
}
|
||||
|
||||
struct arify_rl_engine *next, *entry;
|
||||
for (entry = rlctx.engines; entry != NULL; entry = next) {
|
||||
next = entry->next;
|
||||
free(entry);
|
||||
if (next == rlctx.engines) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
arify_debug_printf("%s", "readline frontend finalized");
|
||||
}
|
||||
|
||||
static struct arify_rl_engine *
|
||||
get_next_engine (void)
|
||||
{
|
||||
void *engine_data;
|
||||
struct arif_engine const *engine = arify_next_engine(&engine_data);
|
||||
if (engine == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct arify_rl_engine *entry = malloc(sizeof(struct arify_rl_engine));
|
||||
assert(entry != NULL);
|
||||
*entry = (struct arify_rl_engine) {
|
||||
.engine = engine,
|
||||
.engine_data = engine_data,
|
||||
};
|
||||
return entry;
|
||||
}
|
||||
|
||||
static int
|
||||
initialize (
|
||||
struct arif_ctx *ctx,
|
||||
void **frontend_data_ptr
|
||||
) {
|
||||
// We must not call rl_initialize() here
|
||||
int entries = sizeof(funmap_entries) / sizeof(funmap_entries[0]);
|
||||
for (int idx = 0; idx < entries; ++idx) {
|
||||
struct arify_funmap_entry const *entry = funmap_entries + idx;
|
||||
rl_add_funmap_entry(entry->name, entry->func);
|
||||
}
|
||||
|
||||
rlctx.ctx = ctx;
|
||||
*frontend_data_ptr = &rlctx;
|
||||
|
||||
arify_debug_printf("%s", "readline frontend initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
rlfunc_engine_info (
|
||||
int ARIF_UNUSED_ARG(arg),
|
||||
int ARIF_UNUSED_ARG(key)
|
||||
) {
|
||||
if (!rlctx.enabled) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
char const *name, *description;
|
||||
get_engine_info(rlctx.current_engine, &name, &description);
|
||||
rlprintf("[arify] engine: %s\n\n%s", name, description);
|
||||
|
||||
arify_debug_printf("%s", "print engine info");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
rlfunc_next_engine (
|
||||
int ARIF_UNUSED_ARG(arg),
|
||||
int ARIF_UNUSED_ARG(key)
|
||||
) {
|
||||
if (!rlctx.enabled) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct arify_rl_engine *entry = rlctx.current_engine;
|
||||
if (entry->next == NULL) {
|
||||
entry->next = get_next_engine();
|
||||
if (entry->next == NULL) {
|
||||
entry->next = rlctx.engines;
|
||||
}
|
||||
}
|
||||
rlctx.current_engine = entry = entry->next;
|
||||
arif_set_engine(rlctx.ctx, entry->engine, entry->engine_data);
|
||||
|
||||
char const *engine_name;
|
||||
get_engine_info(entry, &engine_name, NULL);
|
||||
rlprintf("[arify] engine: %s", engine_name);
|
||||
|
||||
arify_debug_printf("next engine: %s", engine_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
rlfunc_page_down (
|
||||
int ARIF_UNUSED_ARG(arg),
|
||||
int ARIF_UNUSED_ARG(key)
|
||||
) {
|
||||
if (!rlctx.enabled) {
|
||||
return 0;
|
||||
}
|
||||
if (rl_inhibit_completion) {
|
||||
return 0;
|
||||
}
|
||||
int page = arif_select_page(rlctx.ctx, 0);
|
||||
if (page > 0) {
|
||||
rl_complete_internal('?');
|
||||
}
|
||||
arify_debug_printf("page down: %d", page);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
rlfunc_page_up (
|
||||
int ARIF_UNUSED_ARG(arg),
|
||||
int ARIF_UNUSED_ARG(key)
|
||||
) {
|
||||
if (!rlctx.enabled) {
|
||||
return 0;
|
||||
}
|
||||
if (rl_inhibit_completion) {
|
||||
return 0;
|
||||
}
|
||||
int page = arif_select_page(rlctx.ctx, -1);
|
||||
if (page > 0) {
|
||||
rl_complete_internal('?');
|
||||
}
|
||||
arify_debug_printf("page up: %d", page);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
rlfunc_toggle (
|
||||
int ARIF_UNUSED_ARG(arg),
|
||||
int ARIF_UNUSED_ARG(key)
|
||||
) {
|
||||
if (rlctx.enabled) {
|
||||
disable_arify(false);
|
||||
} else {
|
||||
enable_arify();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
rlprintf (
|
||||
char const *fmt,
|
||||
...
|
||||
) {
|
||||
rl_crlf();
|
||||
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vfprintf(rl_outstream, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
rl_crlf();
|
||||
rl_forced_update_display();
|
||||
}
|
||||
|
||||
#endif // defined(HAVE_READLINE)
|
|
@ -0,0 +1,33 @@
|
|||
#
|
||||
# Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
#
|
||||
# Copying and distribution of this file, with or without modification, are
|
||||
# permitted in any medium without royalty, provided the copyright notice and
|
||||
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||
#
|
||||
|
||||
AUTOMAKE_OPTIONS = dejagnu
|
||||
|
||||
|
||||
check_HEADERS = arif_dummy_engine.h
|
||||
check_PROGRAMS = arif-test
|
||||
check_LTLIBRARIES = libarifdummy.la
|
||||
|
||||
arif_test_CPPFLAGS = -I$(top_srcdir)/include
|
||||
arif_test_LDADD = $(top_builddir)/src/libarif.la
|
||||
arif_test_SOURCES = arif_test.c arif_dummy_engine.c
|
||||
|
||||
libarifdummy_la_CPPFLAGS = -I$(top_srcdir)/include
|
||||
libarifdummy_la_SOURCES = arif_dummy_engine.c
|
||||
|
||||
EXTRA_DIST = lib/arif.exp \
|
||||
arif/000-query.exp \
|
||||
arif/001-select-page.exp \
|
||||
arif/002-fetch.exp
|
||||
RUNTESTFLAGS = ARIF_TEST_BIN=$(builddir)/arif-test
|
||||
|
||||
if ENABLE_DEBUG
|
||||
|
||||
RUNTESTFLAGS += ARIF_ENABLE_DEBUG=1
|
||||
|
||||
endif # ENABLE_DEBUG
|
|
@ -0,0 +1,37 @@
|
|||
#
|
||||
# Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
#
|
||||
# Copying and distribution of this file, with or without modification, are
|
||||
# permitted in any medium without royalty, provided the copyright notice and
|
||||
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||
#
|
||||
|
||||
set tool arif
|
||||
set timeout 1
|
||||
|
||||
set text_len [ random_int 1 16 ]
|
||||
set text [ random_string $text_len ]
|
||||
|
||||
arif_test_start
|
||||
|
||||
arif_query $text
|
||||
expect {
|
||||
-ex $text_len\n {}
|
||||
default {
|
||||
fail "query fail"
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
arif_query ${text}1
|
||||
expect {
|
||||
-ex $text_len\n {}
|
||||
default {
|
||||
fail "query fail"
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
pass "ok"
|
||||
|
||||
arif_test_stop
|
|
@ -0,0 +1,59 @@
|
|||
#
|
||||
# Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
#
|
||||
# Copying and distribution of this file, with or without modification, are
|
||||
# permitted in any medium without royalty, provided the copyright notice and
|
||||
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||
#
|
||||
|
||||
set tool arif
|
||||
set timeout 1
|
||||
|
||||
set page_size [ random_int 5 10 ]
|
||||
set text_len [ random_int 10 100 ]
|
||||
set text [ random_string $text_len ]
|
||||
|
||||
arif_test_start $page_size [ expr { $text_len + 2 } ]
|
||||
|
||||
arif_query $text
|
||||
expect \n
|
||||
|
||||
set pages [ expr { $text_len / $page_size + ( $text_len % $page_size > 0 ) } ]
|
||||
set page 1
|
||||
for { set i 0 } { $i < 100 } { incr i } {
|
||||
set new_page [ random_int -1 $pages ]
|
||||
arif_select_page $new_page
|
||||
if { $new_page == 0 } {
|
||||
if { $page < $pages } {
|
||||
set new_page [ incr page ]
|
||||
} else {
|
||||
set new_page -1
|
||||
}
|
||||
} elseif { $new_page == -1 } {
|
||||
if { $page > 1 } {
|
||||
set new_page [ incr page -1 ]
|
||||
} else {
|
||||
set new_page -1
|
||||
}
|
||||
} else {
|
||||
if { $new_page > $pages } {
|
||||
set new_page -1
|
||||
} else {
|
||||
set page $new_page
|
||||
}
|
||||
}
|
||||
expect {
|
||||
-ex $new_page\n {}
|
||||
default {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if { $i == 100 } {
|
||||
pass "ok"
|
||||
} else {
|
||||
fail "select page fail"
|
||||
}
|
||||
|
||||
arif_test_stop
|
|
@ -0,0 +1,55 @@
|
|||
#
|
||||
# Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
#
|
||||
# Copying and distribution of this file, with or without modification, are
|
||||
# permitted in any medium without royalty, provided the copyright notice and
|
||||
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||
#
|
||||
|
||||
set tool arif
|
||||
set timeout 1
|
||||
|
||||
set page_size [ random_int 5 10 ]
|
||||
set text_len [ random_int 10 100 ]
|
||||
set text [ random_string $text_len ]
|
||||
|
||||
arif_test_start $page_size [ expr { $text_len + 2 } ]
|
||||
|
||||
arif_query $text
|
||||
expect \n
|
||||
|
||||
proc arif_gen_cands { str start len } {
|
||||
for { set i 1 } { $i <= $len } { incr i } {
|
||||
set ch [ string index $str [ expr { $start + $i - 1 } ] ]
|
||||
if { $ch == "" } {
|
||||
break
|
||||
}
|
||||
set disp [ string repeat $ch [ expr { $start + $i } ] ]
|
||||
append result \[ $i \] " " $disp \n
|
||||
}
|
||||
return $result
|
||||
}
|
||||
|
||||
set pages [ expr { $text_len / $page_size + ( $text_len % $page_size > 0 ) } ]
|
||||
for { set i 1 } { $i <= $pages } { incr i } {
|
||||
arif_select_page $i
|
||||
expect $i\n
|
||||
|
||||
set start [ expr { ($i - 1) * $page_size } ]
|
||||
set expected [ arif_gen_cands $text $start $page_size ]
|
||||
|
||||
arif_fetch
|
||||
expect {
|
||||
-ex $expected {}
|
||||
default {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if { $i > $pages } {
|
||||
pass "ok"
|
||||
} else {
|
||||
fail "fetch fail"
|
||||
}
|
||||
|
||||
arif_test_stop
|
|
@ -0,0 +1,187 @@
|
|||
/**
|
||||
* arif/tests/arif_dummy_engine.c
|
||||
* ----
|
||||
*
|
||||
* Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
*
|
||||
* This file is part of ARIF, Another Readline Input Framework.
|
||||
*
|
||||
* ARIF 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.
|
||||
*
|
||||
* ARIF 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 ARIF. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include "arif_dummy_engine.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "arif.h"
|
||||
#include "arif_defs.h"
|
||||
|
||||
struct dummy_engine_ctx {
|
||||
char const *input;
|
||||
int input_len;
|
||||
|
||||
struct arif_cand *candidates;
|
||||
int num_candidates;
|
||||
bool gen_all_candidates;
|
||||
};
|
||||
|
||||
// Forward declaration start
|
||||
static void dummy_engine_finalize (void *);
|
||||
static void dummy_engine_info (void *, char const **, char const **);
|
||||
static int dummy_engine_init (void *, void **);
|
||||
static int dummy_engine_query (void *, char const *, int, int, int,
|
||||
struct arif_cand const **);
|
||||
static void free_candidates (struct arif_cand *, int);
|
||||
static void generate_candidate (struct arif_cand *, char, int);
|
||||
// Forward declaration end
|
||||
|
||||
struct arif_engine const arif_dummy_engine = {
|
||||
.init = dummy_engine_init,
|
||||
.finalize = dummy_engine_finalize,
|
||||
.info = dummy_engine_info,
|
||||
.query = dummy_engine_query,
|
||||
};
|
||||
|
||||
static void
|
||||
dummy_engine_finalize (
|
||||
void *engine_data
|
||||
) {
|
||||
struct dummy_engine_ctx *ctx = engine_data;
|
||||
if (ctx == NULL) {
|
||||
return;
|
||||
}
|
||||
free_candidates(ctx->candidates, ctx->num_candidates);
|
||||
free(ctx);
|
||||
}
|
||||
|
||||
static void
|
||||
dummy_engine_info (
|
||||
void *ARIF_UNUSED_ARG(engine_data),
|
||||
char const **name_ptr,
|
||||
char const **description_ptr
|
||||
) {
|
||||
if (name_ptr != NULL) {
|
||||
*name_ptr = "dummy";
|
||||
}
|
||||
if (description_ptr != NULL) {
|
||||
*description_ptr = "A dummy engine for testing.";
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
dummy_engine_init (
|
||||
void *args,
|
||||
void **engine_data_ptr
|
||||
) {
|
||||
struct arif_dummy_engine_opts const *opts = args;
|
||||
|
||||
struct dummy_engine_ctx *ctx = malloc(sizeof(struct dummy_engine_ctx));
|
||||
assert(ctx != NULL);
|
||||
*ctx = (struct dummy_engine_ctx) {
|
||||
.gen_all_candidates = opts != NULL ? opts->gen_all_candidates : false,
|
||||
};
|
||||
*engine_data_ptr = ctx;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
dummy_engine_query (
|
||||
void *engine_data,
|
||||
char const *line,
|
||||
int offset,
|
||||
int len,
|
||||
int num_candidates,
|
||||
struct arif_cand const **candidates_ptr
|
||||
) {
|
||||
struct dummy_engine_ctx *ctx = engine_data;
|
||||
|
||||
char const *input;
|
||||
int old_candidates = 0;
|
||||
if (line == NULL) {
|
||||
input = ctx->input;
|
||||
len = ctx->input_len;
|
||||
old_candidates = ctx->num_candidates;
|
||||
} else if (candidates_ptr == NULL) {
|
||||
return 0;
|
||||
} else {
|
||||
ctx->input = input = line + offset;
|
||||
ctx->input_len = len;
|
||||
|
||||
free_candidates(ctx->candidates, ctx->num_candidates);
|
||||
ctx->candidates = NULL;
|
||||
ctx->num_candidates = 0;
|
||||
}
|
||||
|
||||
int candidates_left = len - ctx->num_candidates;
|
||||
if (ctx->gen_all_candidates || candidates_left < num_candidates) {
|
||||
num_candidates = candidates_left;
|
||||
}
|
||||
if (num_candidates == 0) {
|
||||
return 0;
|
||||
}
|
||||
int new_candidates = old_candidates + num_candidates;
|
||||
|
||||
struct arif_cand *candidates = realloc(ctx->candidates,
|
||||
sizeof(struct arif_cand) * new_candidates);
|
||||
assert(candidates != NULL);
|
||||
ctx->candidates = candidates;
|
||||
ctx->num_candidates = new_candidates;
|
||||
|
||||
for (int i = old_candidates; i < new_candidates; ++i) {
|
||||
generate_candidate(candidates + i, input[i], i);
|
||||
}
|
||||
|
||||
*candidates_ptr = candidates + old_candidates;
|
||||
return num_candidates;
|
||||
}
|
||||
|
||||
static void free_candidates (
|
||||
struct arif_cand *cand,
|
||||
int num
|
||||
) {
|
||||
if (cand == NULL) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < num; ++i) {
|
||||
free((char *) cand[i].text);
|
||||
}
|
||||
free(cand);
|
||||
}
|
||||
|
||||
static void
|
||||
generate_candidate (
|
||||
struct arif_cand *cand,
|
||||
char ch,
|
||||
int offset
|
||||
) {
|
||||
int len = offset + 1;
|
||||
char *text = malloc(sizeof(char) * len);
|
||||
assert(text != NULL);
|
||||
|
||||
for (int i = 0; i < len; ++i) {
|
||||
text[i] = ch;
|
||||
}
|
||||
|
||||
*cand = (struct arif_cand) {
|
||||
.text = text,
|
||||
.len = len,
|
||||
.replace_len = len,
|
||||
};
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/**
|
||||
* arif/tests/arif_dummy_engine.h
|
||||
* ----
|
||||
*
|
||||
* Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
*
|
||||
* This file is part of ARIF, Another Readline Input Framework.
|
||||
*
|
||||
* ARIF 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.
|
||||
*
|
||||
* ARIF 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 ARIF. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef ARIF_DUMMY_ENGINE_H_
|
||||
#define ARIF_DUMMY_ENGINE_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "arif.h"
|
||||
|
||||
struct arif_dummy_engine_opts {
|
||||
bool gen_all_candidates;
|
||||
};
|
||||
|
||||
extern struct arif_engine const arif_dummy_engine;
|
||||
|
||||
#endif // !defined(ARIF_DUMMY_ENGINE_H_)
|
|
@ -0,0 +1,134 @@
|
|||
/**
|
||||
* arif/tests/arif_test.c
|
||||
* ----
|
||||
*
|
||||
* Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
*
|
||||
* This file is part of ARIF, Another Readline Input Framework.
|
||||
*
|
||||
* ARIF 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.
|
||||
*
|
||||
* ARIF 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 ARIF. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "arif.h"
|
||||
#include "arif_dummy_engine.h"
|
||||
|
||||
int
|
||||
main (
|
||||
int argc,
|
||||
char *argv[]
|
||||
) {
|
||||
int buffer_size = 64;
|
||||
int page_size = 5;
|
||||
bool gen_all_candidates = false;
|
||||
for (int opt; -1 != (opt = getopt(argc, argv, "ab:p:")); ) {
|
||||
switch (opt) {
|
||||
case 'a':
|
||||
gen_all_candidates = true;
|
||||
break;
|
||||
case 'b':
|
||||
buffer_size = atoi(optarg);
|
||||
break;
|
||||
case 'p':
|
||||
page_size = atoi(optarg);
|
||||
break;
|
||||
default:
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
char *buffer = malloc(sizeof(char) * buffer_size);
|
||||
assert(buffer != NULL);
|
||||
|
||||
struct arif_opts opts = {
|
||||
.page_size = page_size,
|
||||
};
|
||||
struct arif_ctx *ctx = arif_ctx_create(&opts);
|
||||
assert(ctx != NULL);
|
||||
|
||||
struct arif_engine const *engine = &arif_dummy_engine;
|
||||
struct arif_dummy_engine_opts engine_opts = {
|
||||
.gen_all_candidates = gen_all_candidates,
|
||||
};
|
||||
void *engine_data;
|
||||
if (0 != engine->init(&engine_opts, &engine_data)) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
arif_set_engine(ctx, engine, engine_data);
|
||||
|
||||
int exit_status = EXIT_SUCCESS;
|
||||
|
||||
if (0 != setvbuf(stdin, NULL, _IONBF, 0)) {
|
||||
exit_status = EXIT_FAILURE;
|
||||
goto finish;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
if (NULL == fgets(buffer, buffer_size, stdin)) {
|
||||
break;
|
||||
}
|
||||
char const *end = memchr(buffer, '\n', buffer_size);
|
||||
if (end == NULL) {
|
||||
end = memchr(buffer, '\0', buffer_size);
|
||||
}
|
||||
|
||||
switch (buffer[0]) {
|
||||
case '\0':
|
||||
case '\n':
|
||||
continue;
|
||||
case ':': ;
|
||||
int page_num = arif_select_page(ctx, atoi(buffer + 1));
|
||||
printf("%d\n", page_num);
|
||||
break;
|
||||
case '<': ;
|
||||
struct arif_cand const *candidates;
|
||||
int num = arif_fetch(ctx, &candidates);
|
||||
if (num == 0) {
|
||||
puts("-");
|
||||
break;
|
||||
}
|
||||
for (int i = 0; i < num; ++i) {
|
||||
struct arif_cand const *cand = candidates + i;
|
||||
fwrite(cand->display, 1, cand->display_len, stdout);
|
||||
puts("");
|
||||
}
|
||||
break;
|
||||
case '>': ;
|
||||
int len = arif_query(ctx, buffer, 1, end - buffer - 1);
|
||||
printf("%d\n", len);
|
||||
break;
|
||||
default:
|
||||
puts("?");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
finish:
|
||||
arif_ctx_destroy(ctx);
|
||||
engine->finalize(engine_data);
|
||||
free(buffer);
|
||||
exit(exit_status);
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
#
|
||||
# Copyright (C) 2023 CismonX <admin@cismon.net>
|
||||
#
|
||||
# Copying and distribution of this file, with or without modification, are
|
||||
# permitted in any medium without royalty, provided the copyright notice and
|
||||
# this notice are preserved. This file is offered as-is, without any warranty.
|
||||
#
|
||||
|
||||
if { [ info exists ARIF_ENABLE_DEBUG ] && $ARIF_ENABLE_DEBUG == 1 } {
|
||||
exp_internal 1
|
||||
}
|
||||
|
||||
proc arif_test_start {
|
||||
{ page_size 5 }
|
||||
{ buf_size 64 }
|
||||
{ gen_all yes }
|
||||
} {
|
||||
global ARIF_TEST_BIN
|
||||
set run_cmd [ list $ARIF_TEST_BIN -p $page_size -b $buf_size ]
|
||||
if { $gen_all } {
|
||||
lappend $run_cmd -a
|
||||
}
|
||||
|
||||
set stty_init { raw -echo }
|
||||
global spawn_id
|
||||
spawn {*}$run_cmd
|
||||
}
|
||||
|
||||
proc arif_test_stop {} {
|
||||
global spawn_id
|
||||
send \x04
|
||||
}
|
||||
|
||||
proc random_uint32_list { len } {
|
||||
set nbytes [ expr { $len * 4 } ]
|
||||
return [ exec od -An -tu4 -N$nbytes /dev/urandom ]
|
||||
}
|
||||
|
||||
proc random_int { min max } {
|
||||
set num [ random_uint32_list 1 ]
|
||||
return [ expr { $num % ( $max - $min + 1 ) + $min } ]
|
||||
}
|
||||
|
||||
proc random_string { len } {
|
||||
set nums [ random_uint32_list $len ]
|
||||
set chars [ split abcdefghijklmnopqrstuvwxyz "" ]
|
||||
|
||||
for { set i 0 } { $i < $len } { incr i } {
|
||||
set offset [ expr { [ lindex $nums $i ] % 26 } ]
|
||||
append str [ lindex $chars $offset ]
|
||||
}
|
||||
return $str
|
||||
}
|
||||
|
||||
proc arif_fetch {} {
|
||||
global spawn_id
|
||||
send <\n
|
||||
}
|
||||
|
||||
proc arif_query { text } {
|
||||
global spawn_id
|
||||
send >$text\n
|
||||
}
|
||||
|
||||
proc arif_select_page { page } {
|
||||
global spawn_id
|
||||
send :$page\n
|
||||
}
|
Loading…
Reference in New Issue