⭐ Nanofur First Release
This commit is contained in:
parent
c4f6ba84d8
commit
74f9bf9fb9
141 changed files with 171628 additions and 0 deletions
80
.gitignore
vendored
Normal file
80
.gitignore
vendored
Normal file
|
@ -0,0 +1,80 @@
|
|||
*~
|
||||
*.bak
|
||||
*.o
|
||||
*.orig
|
||||
*.patch
|
||||
*.swp
|
||||
.deps
|
||||
.libs
|
||||
Makefile
|
||||
Makefile.in
|
||||
|
||||
core
|
||||
.gdb_history
|
||||
.gdbinit
|
||||
|
||||
/src/nanofur
|
||||
/src/revision.h
|
||||
|
||||
/ABOUT-NLS
|
||||
/INSTALL
|
||||
/aclocal.m4
|
||||
/ar-lib
|
||||
/autom4te.cache
|
||||
/compile
|
||||
/config.cache
|
||||
/config.guess
|
||||
/config.h
|
||||
/config.h.in
|
||||
/config.log
|
||||
/config.rpath
|
||||
/config.status
|
||||
/config.sub
|
||||
/configure
|
||||
/depcomp
|
||||
/install-sh
|
||||
/intl
|
||||
/missing
|
||||
/mkinstalldirs
|
||||
/stamp-h1
|
||||
|
||||
# Gettext m4 files:
|
||||
/m4/codeset.m4
|
||||
/m4/extern-inline.m4
|
||||
/m4/fcntl-o.m4
|
||||
/m4/gettext.m4
|
||||
/m4/glibc2.m4
|
||||
/m4/glibc21.m4
|
||||
/m4/iconv.m4
|
||||
/m4/intdiv0.m4
|
||||
/m4/intl.m4
|
||||
/m4/intldir.m4
|
||||
/m4/intlmacosx.m4
|
||||
/m4/intmax.m4
|
||||
/m4/inttypes-pri.m4
|
||||
/m4/inttypes_h.m4
|
||||
/m4/lcmessage.m4
|
||||
/m4/lib-ld.m4
|
||||
/m4/lib-link.m4
|
||||
/m4/lib-prefix.m4
|
||||
/m4/lock.m4
|
||||
/m4/longlong.m4
|
||||
/m4/nls.m4
|
||||
/m4/po.m4
|
||||
/m4/printf-posix.m4
|
||||
/m4/progtest.m4
|
||||
/m4/size_max.m4
|
||||
/m4/stdint_h.m4
|
||||
/m4/threadlib.m4
|
||||
/m4/uintmax_t.m4
|
||||
/m4/visibility.m4
|
||||
/m4/wchar_t.m4
|
||||
/m4/wint_t.m4
|
||||
/m4/xsize.m4
|
||||
|
||||
# Gnulib stuff:
|
||||
/gnulib/
|
||||
/lib/
|
||||
/m4/.gitignore
|
||||
/m4/gnulib-cache.m4
|
||||
/snippet/
|
76
AUTHORS
Normal file
76
AUTHORS
Normal file
|
@ -0,0 +1,76 @@
|
|||
This file lists people who have made significant contributions to the
|
||||
nanofur editor. Please see the ChangeLog for specific changes by author.
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Chris Allegretta <chrisa@asty.org>
|
||||
* Original program author and long-time maintainer.
|
||||
|
||||
Benno Schulenberg <bensberg@telfort.nl>
|
||||
* An array of small bug fixes, the cut-word and block-jump
|
||||
routines, text selection by holding Shift, macro recording
|
||||
and replay, extra key bindings, the --indicator, --minibar,
|
||||
and --zero options, and braced functions in string binds.
|
||||
Current maintainer.
|
||||
|
||||
David Lawrence Ramsey <pooka109@gmail.com>
|
||||
* Multiple-buffer support, operating-dir option (-o), bug fixes
|
||||
for display routines, wrapping code, spelling fixes, parts of
|
||||
UTF-8 support, softwrap overhaul, constantshow mode, undoable
|
||||
indentations, undoable justifications, justifiable regions,
|
||||
and numerous other fixes. Former stable-series maintainer.
|
||||
|
||||
Jordi Mallach <jordi@gnu.org>
|
||||
* Debian package maintainer, fellow bug squasher, translator
|
||||
for Catalan. Former head of internationalization support.
|
||||
|
||||
Adam Rogoyski <rogoyski@cs.utexas.edu>
|
||||
* New write_file() function, read_file() optimization, mouse
|
||||
support, resize support, nohelp (-x) option, justify function,
|
||||
follow symlink option and bugfixes, and much more.
|
||||
|
||||
Robert Siemborski <rjs3@andrew.cmu.edu>
|
||||
* Miscellaneous cut, display, replace, and other bug fixes,
|
||||
original and new "magic line" code, read_line() function,
|
||||
new edit display routines.
|
||||
|
||||
Rocco Corsi <rocco.corsi@sympatico.ca>
|
||||
* Internal spelling code, many optimizations and bug fixes
|
||||
for findnextstr() and search-related functions, various
|
||||
display and file-handling fixes.
|
||||
|
||||
David Benbennick <dbenbenn@math.cornell.edu>
|
||||
* Wrap and justify bugfixes/enhancements, new color syntax
|
||||
code, memleak fixes, parts of the UTF-8 support, and other
|
||||
miscellaneous fixes.
|
||||
|
||||
Mike Frysinger <vapier@gentoo.org>
|
||||
* Whitespace display mode, --enable-utf8/--disable-utf8 configure
|
||||
options for ncurses, many new color regexes and improvements to
|
||||
existing ones in syntax/*.nanofurrc, the move from svn to git, the
|
||||
conversion to gnulib, and miscellaneous bug fixes. Former
|
||||
Gentoo package maintainer.
|
||||
|
||||
Mark Majeres <mark@engine12.com>
|
||||
* A functional undo/redo system, and coloring nanofur's interface.
|
||||
|
||||
Mahyar Abbaspour <mahyar.abaspour@gmail.com>
|
||||
* Improved handling of SIGWINCH.
|
||||
|
||||
Mike Scalora <mike@scalora.org>
|
||||
* The comment/uncomment feature.
|
||||
|
||||
Faissal Bensefia <faissaloo@gmail.com>
|
||||
* Line numbers.
|
||||
|
||||
Sumedh Pendurkar <sumedh.pendurkar@gmail.com>
|
||||
* The word-completion feature.
|
||||
|
||||
Rishabh Dave <rishabhddave@gmail.com>
|
||||
* Searchable help.
|
||||
|
||||
Marco Diego Aurélio Mesquita <marcodiegomesquita@gmail.com>
|
||||
* Filtering text through an external command.
|
||||
* Placing anchors (bookmarks) and jumping to them.
|
||||
|
||||
Brand Huntsman <alpha@qzx.com>
|
||||
* The delayed parsing of syntax files.
|
676
COPYING
Normal file
676
COPYING
Normal file
|
@ -0,0 +1,676 @@
|
|||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://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 <http://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
|
||||
<http://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
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
|
397
COPYING.DOC
Normal file
397
COPYING.DOC
Normal file
|
@ -0,0 +1,397 @@
|
|||
GNU Free Documentation License
|
||||
Version 1.2, November 2002
|
||||
|
||||
|
||||
Copyright (C) 2000,2001,2002 Free Software Foundation, Inc.
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
0. PREAMBLE
|
||||
|
||||
The purpose of this License is to make a manual, textbook, or other
|
||||
functional and useful document "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.
|
||||
|
||||
|
||||
1. 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, LaTeX 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.
|
||||
|
||||
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.
|
||||
|
||||
|
||||
2. 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.
|
||||
|
||||
|
||||
3. 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.
|
||||
|
||||
|
||||
4. 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:
|
||||
|
||||
A. 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.
|
||||
B. 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.
|
||||
C. State on the Title page the name of the publisher of the
|
||||
Modified Version, as the publisher.
|
||||
D. Preserve all the copyright notices of the Document.
|
||||
E. Add an appropriate copyright notice for your modifications
|
||||
adjacent to the other copyright notices.
|
||||
F. 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.
|
||||
G. Preserve in that license notice the full lists of Invariant Sections
|
||||
and required Cover Texts given in the Document's license notice.
|
||||
H. Include an unaltered copy of this License.
|
||||
I. 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.
|
||||
J. 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.
|
||||
K. 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.
|
||||
L. 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.
|
||||
M. Delete any section Entitled "Endorsements". Such a section
|
||||
may not be included in the Modified Version.
|
||||
N. Do not retitle any existing section to be Entitled "Endorsements"
|
||||
or to conflict in title with any Invariant Section.
|
||||
O. Preserve any Warranty Disclaimers.
|
||||
|
||||
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.
|
||||
|
||||
|
||||
5. 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".
|
||||
|
||||
|
||||
6. 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.
|
||||
|
||||
|
||||
7. 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.
|
||||
|
||||
|
||||
8. 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.
|
||||
|
||||
|
||||
9. TERMINATION
|
||||
|
||||
You may not copy, modify, sublicense, or distribute the Document except
|
||||
as expressly provided for under this License. Any other attempt to
|
||||
copy, modify, sublicense or distribute the Document is void, and will
|
||||
automatically terminate your rights under this License. However,
|
||||
parties who have received copies, or rights, from you under this
|
||||
License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
|
||||
10. 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
|
||||
http://www.gnu.org/copyleft/.
|
||||
|
||||
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.
|
||||
|
||||
|
||||
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:
|
||||
|
||||
Copyright (c) YEAR YOUR NAME.
|
||||
Permission is granted to copy, distribute and/or modify this document
|
||||
under the terms of the GNU Free Documentation License, Version 1.2
|
||||
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".
|
||||
|
||||
If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts,
|
||||
replace the "with...Texts." line with this:
|
||||
|
||||
with the Invariant Sections being LIST THEIR TITLES, with the
|
||||
Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST.
|
||||
|
||||
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.
|
8371
ChangeLog.1999-2006
Normal file
8371
ChangeLog.1999-2006
Normal file
File diff suppressed because it is too large
Load diff
4010
ChangeLog.2007-2015
Normal file
4010
ChangeLog.2007-2015
Normal file
File diff suppressed because it is too large
Load diff
226
IMPROVEMENTS
Normal file
226
IMPROVEMENTS
Normal file
|
@ -0,0 +1,226 @@
|
|||
Improvements in GNU nanofur
|
||||
========================
|
||||
|
||||
Since 8.0:
|
||||
- To accommodate newcomers, ^F now starts a forward search.
|
||||
- Option --modernbindings makes ^Q quit, ^X cut, ^C copy, ^V paste,
|
||||
^Z undo, ^Y redo, ^O open a file, and ^G find again, among others.
|
||||
- M-Home/M-End put the cursor on the first/last row in the viewport.
|
||||
- With `nanofur filename:number` the given file will be opened with the
|
||||
cursor on the given line number (when 'set colonparsing' is used).
|
||||
- Option --listsyntaxes lists the names of available syntaxes.
|
||||
|
||||
Since 7.0:
|
||||
- String binds may contain bindable function names between braces.
|
||||
- Word completion looks for candidates in all open buffers.
|
||||
- Unicode codes can be entered without leading zeroes.
|
||||
|
||||
Since 6.0:
|
||||
- Option --zero hides the interface and uses the whole terminal for editing.
|
||||
- Colors can be given also in #rgb hexadecimal, to select the nearest color
|
||||
from the 6x6x6 color-cube palette available on 256-color terminals.
|
||||
- Fourteen new color names are available, from rosy to crimson.
|
||||
|
||||
Since 5.0:
|
||||
- A search briefly spotlights the found text, in black on yellow by default.
|
||||
- Option --minibar reduces the interface to a bottom bar with basic info.
|
||||
- The cursor skips over combining characters, <Del> deletes them together
|
||||
with the character they combine with, but <Bsp> deletes them separately.
|
||||
- For using libmagic the option --magic or -! or 'set magic' is required.
|
||||
- With --stateflags the state of some things is shown in the title bar.
|
||||
- M-Bsp deletes a word leftward.
|
||||
- With --indicator a "scrollbar" is shown, indicating position+portion.
|
||||
- M-Ins places an anchor, M-PgUp/M-PgDn jump to the nearest anchor.
|
||||
- Toggling help lines (M-X) and Refresh (^L) work nearly everywhere.
|
||||
- Colors can be modified with the attributes "bold," and/or "italic,".
|
||||
- Nine new color names: from pink and purple to orange and latte.
|
||||
|
||||
Since 4.0:
|
||||
- Pasting from outside into nanofur suppresses auto-indentation.
|
||||
- Such an external paste can be undone with a single M-U.
|
||||
- Shift+Meta+letter key combos can be bound with 'bind Sh-M-letter ...'.
|
||||
- A custom nanofurrc file may be specified with -f / --rcfile.
|
||||
- What the <Tab> key produces can be specified per syntax with 'tabgives'.
|
||||
- The ability to perform a search at startup with +/string or +?string.
|
||||
- Comment characters are copied when automatic hard-wrapping occurs.
|
||||
- The ability to both read from and write to a FIFO.
|
||||
- Automatic hard-wrapping is no longer the default.
|
||||
- Addition of --guidestripe to draw a helpful vertical bar.
|
||||
- Meta-Up and Meta-Down scroll the screen linewise.
|
||||
- Continuation is shown with a highlighted ">" instead of a plain "$".
|
||||
- A marked region gets justified into a single, separate paragraph.
|
||||
- Any number of justifications can be undone.
|
||||
|
||||
Since 3.0:
|
||||
- Addition of --zap to make <Del> and <Bsp> obliterate marked text.
|
||||
- <Ctrl+Delete> wipes next word and <Shift+Ctrl+Delete> preceding word.
|
||||
- An external spell check can be undone.
|
||||
|
||||
Since 2.9.0:
|
||||
- The ability to filter text through an external command.
|
||||
- Better detection of paragraphs, allowing a less indented beginning.
|
||||
- Option 'set afterends' for making Ctrl+Right stop at word ends.
|
||||
- A crash handler that saves changed buffers in case of a crash.
|
||||
- Addition of the color name "normal", meaning the default color.
|
||||
- A key can be bound to a string -- any mix of text and control codes.
|
||||
- Error messages are shown by default in bright white on red.
|
||||
- <Tab> and <Shift+Tab> can be used to indent/unindent a marked region.
|
||||
- Can snip trailing whitespace while typing, with 'set trimblanks'.
|
||||
- The ability to record and replay a series of keystrokes (a macro).
|
||||
- Assigned functions to ^S (save file) and ^Q (start backward search).
|
||||
- Indenting and unindenting have been integrated into the undo system.
|
||||
- Support for $XDG_CONFIG_HOME for the nanofurrc file, and $XDG_DATA_HOME
|
||||
for the history files (of search strings and cursor positions).
|
||||
|
||||
Since 2.8.0:
|
||||
- ^U pastes the first line of the cutbuffer at a prompt.
|
||||
- Softwrapping can be done at whitespace (with --soft --atblanks).
|
||||
- The ^G help texts have become searchable (with ^W and M-W).
|
||||
- Ctrl+Home and Ctrl+End jump to start and end of file.
|
||||
- In softwrap mode the cursor now moves per visual row instead of
|
||||
per logical line, and the screen will scroll per row.
|
||||
|
||||
Since 2.7.0:
|
||||
- The keystroke ^] to complete a fragment to an existing full word.
|
||||
- The ability to display line numbers in front of the text (M-#).
|
||||
|
||||
Since 2.6.0:
|
||||
- Shift plus the cursor keys can be used for selecting text.
|
||||
- Ctrl+Arrow should now work also on a Linux virtual console.
|
||||
- Ctrl+Up and Ctrl+Down jump to previous or next block of text.
|
||||
- Feedback during Unicode Input (M-V followed by six digits).
|
||||
- The option 'wordchars' for specifying extra word characters.
|
||||
- Hi-bit control characters are shown in a more readable manner.
|
||||
- The ability to use negative numbers at the Go To Line prompt.
|
||||
- The ability to comment/uncomment lines with a single keystroke (M-3).
|
||||
- The ability to refresh the file list in the browser (^L).
|
||||
- The ability to abort re-searches (^C after an M-W).
|
||||
- Better feedback at startup when opening large or multiple files.
|
||||
|
||||
Since 2.5.0:
|
||||
- The option 'justifytrim' for snipping whitespace from justified lines.
|
||||
- The ability to discard a buffer (^O ^Q) when --tempfile is used.
|
||||
- On most terminals Ctrl+Left / Ctrl+Right now work for PrevWord/NextWord.
|
||||
- When in the middle of a word, PrevWord now jumps to the start of this
|
||||
word (like Pico does) instead of to the start of the preceding word.
|
||||
- The ability to delete whole words with 'cutwordleft' and 'cutwordright'.
|
||||
- The ability to save a file without prompting for its name ('savefile').
|
||||
- The ability to search backward without having to toggle the direction.
|
||||
|
||||
Since 2.4.0:
|
||||
- Replacing things in a marked region now takes place in situ, in context,
|
||||
instead of changing the view to only the marked text.
|
||||
- Invalid byte sequences are properly displayed and not mistakenly found.
|
||||
- Resizing the window does not exit from help viewer nor file browser.
|
||||
|
||||
Since 2.3.0:
|
||||
- System syntaxes can be improved upon with the 'extendsyntax' command.
|
||||
- Whitespace display (M-P) does not require configuration to be useful.
|
||||
- Undo/redo is enabled by default (M-U/M-E) and works nearly everywhere
|
||||
-- just not yet for justifying and indenting/unindenting.
|
||||
- The ability to color the title bar, the status bar and the help lines.
|
||||
- The ability to run a linter or formatter (^T) on the current buffer.
|
||||
- The ability to only write to named pipes with --noread.
|
||||
- Determination of the applicable syntax through libmagic -- when the
|
||||
file extension nor the first line give an answer.
|
||||
- The option 'positionlog' for saving/restoring the cursor position.
|
||||
- The ability to read and write vim-style lock files.
|
||||
|
||||
Since 2.0.0:
|
||||
- The ability to rebind keys, via a nanofurrc file.
|
||||
- The ability to read standard input like a pager ("nanofur -").
|
||||
- Color syntax highlighting can be set by the first line of a file.
|
||||
- The ability to silence nanofurrc error messages (-q).
|
||||
- Undo/redo operations (M-U/M-E, enabled with -u).
|
||||
- Soft wrapping of text (-$).
|
||||
- Better handling of backup files: if nanofur can't write a backup file,
|
||||
it won't try to write the original file afterward.
|
||||
- Emergency savefiles retain ownerships and permissions when possible.
|
||||
- Performance improvements in color syntax highlighting.
|
||||
|
||||
Since 1.2.0:
|
||||
- Support for UTF-8.
|
||||
- Moving to a specified line and column of a file, instead of just a
|
||||
line (+LINE,COLUMN).
|
||||
- Smart home key (-A).
|
||||
- Creation of unique backup files in a specified directory (-C <dir>).
|
||||
- Insertion of spaces instead of a tab when Tab is pressed (-E).
|
||||
- The long option for -K is now --rebindkeypad.
|
||||
- Regular expression searching can now be toggled when nanofur is built
|
||||
with --enable-tiny, so -R now means something else (see next item).
|
||||
- Restricted mode that provides more security than -o (-R).
|
||||
- Blanking of the statusbar after 1 keystroke instead of 25 (-U).
|
||||
- Word searches can optionally skip over punctuation (-W).
|
||||
- Workaround for Delete's acting like Backspace (-d).
|
||||
- Many more options are supported in the nanofurrc.
|
||||
- Improvements to color syntax highlighting support: case insensitive
|
||||
matching, the ability to include color syntaxes in separate files,
|
||||
the ability to specify background colors without foreground colors...
|
||||
- Insertion of single-byte characters via Esc Esc <000-255>.
|
||||
- Insertion of any character via Meta-V, "Verbatim Input".
|
||||
- Workaround for the "NumLock glitch".
|
||||
- Meta-W now repeats the last search. Wrapping is toggled via Meta-L.
|
||||
- Replacing and spell checking only selected text.
|
||||
- Indenting lines with one keystroke.
|
||||
- Copying text into the cutbuffer without cutting it.
|
||||
- Scrolling the text up and down single lines without moving the cursor.
|
||||
- PageUp and PageDown work more smoothly when using -S.
|
||||
- Scrolling the help text up and down single lines.
|
||||
- Cutting all text from the current position to the end of the file
|
||||
with one keystroke (Meta-T).
|
||||
- Justifying the entire file with one keystroke (Meta-J).
|
||||
- Justifying without removing spaces from the ends of lines.
|
||||
- Unjustifying after justifying and immediately resizing.
|
||||
- Going to the first or last line of the current paragraph.
|
||||
- Going to the first or last line of the file without having to go to
|
||||
the "Search" prompt.
|
||||
- Searching for filenames in the file browser.
|
||||
- Spaces and tabs are shown differently to make it easier to tell them apart.
|
||||
- Many more functions are available at the prompt: moving to the next or
|
||||
previous word, searching for matching brackets, "Verbatim Input"...
|
||||
- "To Line" (^W^T) and "Read from Command" (^R^X) return to their parent
|
||||
menu when their keystroke is entered again (^W^T^T and ^R^X^X).
|
||||
- Automatic adding of newlines to the ends of files without them can
|
||||
now be disabled (-L).
|
||||
- Converting from and to DOS/Mac file format is now toggled only at the
|
||||
"Write File" prompt, via Meta-D and Meta-M, and the default file format
|
||||
to save in is now set depending on what format the file was originally
|
||||
in. -D now makes nanofur use bold text instead of reverse video text,
|
||||
and Meta-D at the edit window now does a word/line/character count.
|
||||
-O now makes the unused second line of the screen part of the edit
|
||||
window, and Meta-O now toggles this behavior while editing.
|
||||
- Converting files that contain a mix of DOS and Mac format lines.
|
||||
- Automatic switching on of -N with binary files has been removed, as
|
||||
it causes problems with UTF-8 support.
|
||||
|
||||
Since 1.0
|
||||
- Complete Pico compatibility (option --pico has been removed,
|
||||
and -p now means something else, see below).
|
||||
- Support for nanofurrc files.
|
||||
- Smooth scrolling (-S).
|
||||
- Jumping to the matching brace, bracket, etc.
|
||||
- Help for all editor features.
|
||||
- Color syntax highlighting support.
|
||||
- Quote string support, useful for mail agents, etc. (-Q).
|
||||
- Insertion of output of external commands.
|
||||
- Optional enabling of XON and XOFF control characters (-p).
|
||||
- Option -o (--operatingdir) implements a chroot of sorts.
|
||||
- Mouse support (-m) also allows clicking on shortcuts.
|
||||
- Option -r allows a negative argument.
|
||||
- Overwriting and appending or prepending to files.
|
||||
- Writing marked text to separate files.
|
||||
- Multiple file buffers (-F).
|
||||
- Converting from and to DOS/Mac file format (-D/-M, -N to disable).
|
||||
- Better control character handling.
|
||||
- Creation of backup files (-B).
|
||||
- Search/replace history (-H).
|
||||
|
||||
Available in 1.0:
|
||||
- Spell checking (^T).
|
||||
- Justification (^J) and unjustification (^U).
|
||||
- Internationalization (more translations are welcome).
|
||||
- Help texts (^G).
|
||||
- Resizing in X.
|
||||
- On PageUp/Down, the cursor is put on the first screen line (like Pico).
|
||||
- Tab completion at the prompt (for filenames and ~user).
|
||||
- Cut-to-end-of-line option (-k).
|
17
Makefile.am
Normal file
17
Makefile.am
Normal file
|
@ -0,0 +1,17 @@
|
|||
AUTOMAKE_OPTIONS = gnu no-dependencies
|
||||
|
||||
SUBDIRS = doc lib m4 po src
|
||||
|
||||
if USE_COLOR
|
||||
SUBDIRS += syntax
|
||||
endif
|
||||
|
||||
EXTRA_DIST = IMPROVEMENTS
|
||||
|
||||
ACLOCAL_AMFLAGS = -I m4
|
||||
|
||||
showinfo:
|
||||
@ echo
|
||||
@ echo " The global nanofurrc file is: @sysconfdir@/nanofurrc"
|
||||
@ echo " Syntaxes get installed in: @PKGDATADIR@/"
|
||||
@ echo
|
122
README
Normal file
122
README
Normal file
|
@ -0,0 +1,122 @@
|
|||
|
||||
GNU nanofur -- a simple editor, inspired by Pico
|
||||
|
||||
Purpose
|
||||
|
||||
Nanofur is a small and simple text editor for use on the terminal.
|
||||
It copied the interface and key bindings of the Pico editor but
|
||||
added several missing features: undo/redo, syntax highlighting,
|
||||
line numbers, softwrapping, multiple buffers, selecting text by
|
||||
holding Shift, search-and-replace with regular expressions, and
|
||||
several other conveniences.
|
||||
|
||||
Appearance
|
||||
|
||||
In rough ASCII graphics, this is what nanofur's screen looks like:
|
||||
|
||||
____________________________________________________________________
|
||||
| GNU nanofur 8.2 filename Modified |
|
||||
--------------------------------------------------------------------
|
||||
| This is the text window, displaying the contents of a 'buffer', |
|
||||
| the contents of the file you are editing. |
|
||||
| |
|
||||
| The top row of the screen is the 'title bar'; it shows nanofur's |
|
||||
| version, the name of the file, and whether you modified it. |
|
||||
| The two bottom rows display the most important shortcuts; in |
|
||||
| those lines ^ means Ctrl. The third row from the bottom shows |
|
||||
| some feedback message, or gets replaced with a prompt bar when |
|
||||
| you tell nanofur to do something that requires extra input. |
|
||||
| |
|
||||
--------------------------------------------------------------------
|
||||
| [ Some status message ] |
|
||||
|^G Help ^O Write Out ^F Where Is ^K Cut ^T Execute |
|
||||
|^X Exit ^R Read File ^\ Replace ^U Paste ^J Justify |
|
||||
--------------------------------------------------------------------
|
||||
|
||||
Origin
|
||||
|
||||
The nanofur project was started in 1999 because of a few "problems"
|
||||
with the wonderfully easy-to-use and friendly Pico text editor.
|
||||
|
||||
First and foremost was its license: the Pine suite does not use
|
||||
the GPL, and (before using the Apache License) it had unclear
|
||||
restrictions on redistribution. Because of this, Pine and Pico
|
||||
were not included in many GNU/Linux distributions. Furthermore,
|
||||
some features (like go-to-line-number or search-and-replace) were
|
||||
unavailable for a long time or require a command-line flag. Yuck.
|
||||
|
||||
Nanofur aimed to solve these problems by: 1) being truly free software
|
||||
by using the GPL, 2) emulating the functionality of Pico as closely
|
||||
as is reasonable, and 3) including extra functionality by default.
|
||||
|
||||
Nowadays, nanofur wants to be a generally useful editor with sensible
|
||||
defaults (linewise scrolling, no automatic line breaking).
|
||||
|
||||
The nanofur editor is an official GNU package. For more information on
|
||||
GNU and the Free Software Foundation, please see https://www.gnu.org/.
|
||||
|
||||
License
|
||||
|
||||
Nanofur's code and documentation are covered by the GPL version 3 or
|
||||
(at your option) any later version, except for two functions that
|
||||
were copied from busybox which are under a BSD license. Nanofur's
|
||||
documentation is additionally covered by the GNU Free Documentation
|
||||
License version 1.2 or (at your option) any later version. See the
|
||||
files COPYING and COPYING.DOC for the full text of these licenses.
|
||||
|
||||
When in any file of this package a copyright notice mentions a
|
||||
year range (such as 1999-2011), it is a shorthand for a list of
|
||||
all the years in that interval.
|
||||
|
||||
How to compile and install nanofur
|
||||
|
||||
Download the latest nanofur source tarball, and then:
|
||||
|
||||
tar -xvf nanofur-x.y.tar.gz
|
||||
cd nanofur-x.y
|
||||
./configure
|
||||
make
|
||||
make install
|
||||
|
||||
You will need the header files of ncurses installed for ./configure
|
||||
to succeed -- get them from libncurses-dev (Debian) or ncurses-devel
|
||||
(Fedora) or a similarly named package. Use --prefix with ./configure
|
||||
to override the default installation directory of /usr/local.
|
||||
|
||||
After installation you may want to copy the doc/sample.nanofurrc file
|
||||
to your home directory, rename it to ".nanofurrc", and then edit it
|
||||
according to your taste.
|
||||
|
||||
Web Page
|
||||
|
||||
https://nanofur-editor.org/
|
||||
|
||||
Mailing Lists
|
||||
|
||||
There are three nanofur-related mailing-lists.
|
||||
|
||||
* <info-nanofur@gnu.org> is a very low traffic list used to announce
|
||||
new nanofur versions or other important info about the project.
|
||||
|
||||
* <help-nanofur@gnu.org> is for those seeking to get help without
|
||||
wanting to hear about the technical details of its development.
|
||||
|
||||
* <nanofur-devel@gnu.org> is the list used by the people that make nanofur
|
||||
and a general development discussion list, with moderate traffic.
|
||||
|
||||
To subscribe, send email to <name>-request@gnu.org with a subject
|
||||
of "subscribe", where <name> is the list you want to subscribe to.
|
||||
|
||||
The archives of the development and help mailing lists are here:
|
||||
|
||||
https://lists.gnu.org/archive/html/nanofur-devel/
|
||||
https://lists.gnu.org/archive/html/help-nanofur/
|
||||
|
||||
Bug Reports
|
||||
|
||||
If you find a bug, please file a detailed description of the problem
|
||||
on nanofur's issue tracker: https://savannah.gnu.org/bugs/?group=nanofur
|
||||
(you will need an account to be able to do so), or send an email
|
||||
to the nanofur-devel list (no need to subscribe, but mention it if
|
||||
you want to be CC'ed on an answer).
|
||||
|
123
README.hacking
Normal file
123
README.hacking
Normal file
|
@ -0,0 +1,123 @@
|
|||
INSTRUCTIONS FOR COMPILING AND INSTALLING NANOFUR FROM GIT
|
||||
=======================================================
|
||||
|
||||
The latest changes and fixes for GNU nanofur are available via git, but
|
||||
building this needs a bit more care than the official tarballs.
|
||||
|
||||
|
||||
Prerequisites
|
||||
-------------
|
||||
|
||||
To successfully compile GNU nanofur from git, you'll need the following:
|
||||
|
||||
autoconf (version >= 2.69)
|
||||
automake (version >= 1.14)
|
||||
autopoint (version >= 0.20)
|
||||
gcc (version >= 5.0)
|
||||
gettext (version >= 0.20)
|
||||
git (version >= 2.7.4)
|
||||
groff (version >= 1.12)
|
||||
make (any version)
|
||||
pkg-config (version >= 0.22)
|
||||
texinfo (version >= 4.0)
|
||||
|
||||
You will also need to have the header files for ncurses installed,
|
||||
from libncurses-dev on Debian, ncurses-devel on Fedora, or similar.
|
||||
|
||||
These should all be available in your distro's package manager or
|
||||
software center, or otherwise on any GNU mirror.
|
||||
|
||||
|
||||
Clone the source
|
||||
----------------
|
||||
|
||||
To obtain the current nanofur development branch (called 'master'), use the
|
||||
following command. It will create in your current working directory a
|
||||
subdirectory called 'nanofur' containing a copy of all of the files:
|
||||
|
||||
$ git clone git://git.savannah.gnu.org/nanofur.git
|
||||
|
||||
|
||||
Generate the configure script
|
||||
-----------------------------
|
||||
|
||||
Once you have the sources in the "nanofur" directory,
|
||||
|
||||
$ cd nanofur
|
||||
$ ./autogen.sh
|
||||
|
||||
This will set up a configure script and a Makefile.in file.
|
||||
|
||||
|
||||
Configure your build
|
||||
--------------------
|
||||
|
||||
To configure your build, run the configure script from the nanofur source
|
||||
directory:
|
||||
|
||||
$ ./configure [--add-options-here]
|
||||
|
||||
|
||||
Build and install
|
||||
-----------------
|
||||
|
||||
From the nanofur source directory, build the code with:
|
||||
|
||||
$ make
|
||||
|
||||
Then, once it's done compiling, run:
|
||||
|
||||
$ make install
|
||||
|
||||
which should copy various files (i.e. the nanofur executable, the info and
|
||||
man pages, and syntax highlighting pattern files) to their appropriate
|
||||
directories.
|
||||
|
||||
If you're installing into the default install directory (/usr/local),
|
||||
you'll need to run that "make install" command with root privileges.
|
||||
|
||||
|
||||
Problems?
|
||||
---------
|
||||
|
||||
Please submit any bugs you find in the code in git via the bug tracker
|
||||
on Savannah (https://savannah.gnu.org/bugs/?group=nanofur).
|
||||
|
||||
|
||||
Contributing something
|
||||
----------------------
|
||||
|
||||
If you have a fix for a bug, or the code for a new or improved feature,
|
||||
first create a branch off of master:
|
||||
|
||||
$ git checkout -b somename
|
||||
|
||||
Then change the code so it does what you want, and commit it together
|
||||
with your Sign-off:
|
||||
|
||||
$ git commit -as
|
||||
|
||||
In the commit message (after the one-line summary) give a rationale
|
||||
for the change. With your Signed-off-by you declare that the code is
|
||||
yours, or that you are free to reuse it, and that you submit it under
|
||||
the license that covers nanofur. Then create a patch (or patches):
|
||||
|
||||
$ git format-patch master
|
||||
|
||||
Send that patch (or patches) to <nanofur-devel@gnu.org>, as an attachment
|
||||
or with git send-email.
|
||||
|
||||
To keep most lines of nanofur's source code within a width of 80 characters,
|
||||
a tab size of four should be used. So in your nanofurrc file you may want
|
||||
to include 'set tabsize 4', or you could use -T4 on the command line.
|
||||
To make git display things as intended, you can do:
|
||||
|
||||
$ git config --local core.pager "less -x1,5"
|
||||
|
||||
To see all types that are used in nanofur's source code colorized as types,
|
||||
you can add these lines to your ~/.nanofurrc:
|
||||
|
||||
extendsyntax c color green "\<struct (dirent|option|passwd)\>"
|
||||
extendsyntax c color green "\<struct (sigaction|stat|termios)\>"
|
||||
extendsyntax c color green "\<struct (timespec|vt_stat|winsize)\>"
|
||||
extendsyntax c color green "\<([[:lower:]_]+(struct|type)|va_list)\>"
|
106
THANKS
Normal file
106
THANKS
Normal file
|
@ -0,0 +1,106 @@
|
|||
The following people have helped GNU nanofur in some way or another.
|
||||
If we missed you here, let us know!
|
||||
|
||||
|
||||
Translations:
|
||||
============
|
||||
Pedro Albuquerque <palbuquerque73@gmail.com> Portuguese
|
||||
Josef Andersson <josef.andersson@fripost.org> Swedish
|
||||
Mario Blättermann <mario.blaettermann@gmail.com> German
|
||||
Besnik Bleta <besnik@programeshqip.org> Albanian
|
||||
Laurențiu Buzdugan <buzdugan@voyager.net> Romanian
|
||||
Ricardo Cárdenes Medina <ricardo@conisys.com> Spanish
|
||||
Antonio Ceballos <aceballos@gmail.com> Spanish
|
||||
Wei-Lun CHAO <chaoweilun@pcmail.com.tw> Chinese (traditional)
|
||||
Seong-ho Cho <darkcircle.0426@gmail.com> Korean
|
||||
Yuri Chornoivan <yurchor@ukr.net> Ukrainian
|
||||
Marco Colombo <magicdice@inwind.it> Italian
|
||||
Mihai Cristescu <mihai.cristescu@archlinux.info> Romanian
|
||||
Yavor Doganov <yavor@doganov.org> Bulgarian
|
||||
Karl Eichwalder <keichwa@gmx.net> German
|
||||
A. Murat EREN <meren@comu.edu.tr> Turkish
|
||||
Sveinn í Felli <sv1@fellsnet.is> Icelandic
|
||||
Marek Felšöci <marek@felsoci.sk> Slovak
|
||||
Doruk Fisek <dfisek@fisek.com.tr> Turkish
|
||||
Rafael Fontenelle <rffontenelle@gmail.com> Brazilian Portuguese
|
||||
Pavel Fric <pavelfric@seznam.cz> Czech
|
||||
Jorge González <aloriel@gmail.com> Spanish
|
||||
Jean-Philippe Guérard <jean-philippe.guerard@laposte.net> French
|
||||
Václav Haisman <V.Haisman@sh.cvut.cz> Czech
|
||||
Takeshi Hamasaki <hmatrjp@users.sourceforge.jp> Japanese
|
||||
Geir Helland <pjallabais@users.sourceforge.net> Norwegian Bokmål
|
||||
Tedi Heriyanto <tedi_h@gmx.net> Indonesian
|
||||
Kjetil Torgrim Homme <kjetilho@linpro.no> Norwegian Nynorsk
|
||||
Szabolcs Horvath <horvaths@janus.gimsz.sulinet.hu> Hungarian
|
||||
Jorma Karvonen <karvonen.jorma@gmail.com> Finnish
|
||||
Mehmet Kececi <mkececi@mehmetkececi.com> Turkish
|
||||
Gabor Kelemen <kelemeng@gnome.hu> Hungarian
|
||||
Kalle Kivimaa <kalle.kivimaa@iki.fi> Finnish
|
||||
Eivind Kjørstad <ekj@vestdata.no> Norwegian Nynorsk
|
||||
Florian König <floki@bigfoot.com> German
|
||||
Klemen Košir <klemen913@gmail.com> Slovenian
|
||||
Wojciech Kotwica <wkotwica@post.pl> Polish
|
||||
Clement Laforet <clem_laf@wanadoo.fr> French
|
||||
Ask Hjorth Larsen <asklarsen@gmail.com> Danish
|
||||
LI Daobing <lidaobing@gmail.com> Chinese (simplified)
|
||||
Jordi Mallach <jordi@gnu.org> Catalan
|
||||
João Victor Duarte Martins <jvdm@sdf.lonestar.org> Brazilian Portuguese
|
||||
Pavel Maryanov <acid@jack.kiev.ua> Russian
|
||||
Daniele Medri <madrid@linux.it> Italian
|
||||
Gergely Nagy <algernon@debian.org> Hungarian
|
||||
Claudio Neves <cneves@nextis.com> Brazilian Portuguese
|
||||
Kalle Olavi Niemitalo <kon@iki.fi> Finnish
|
||||
Мирослав Николић <miroslavnikolic@rocketmail.com> Serbian
|
||||
Lauri Nurmi <lanurmi@iki.fi> Finnish
|
||||
Daniel Nylander <po@danielnylander.se> Swedish
|
||||
Mikel Olasagasti <hey_neken@mundurat.net> Basque
|
||||
Yi-Jyun Pan <pan93412@gmail.com> Chinese (traditional)
|
||||
Michael Piefel <piefel@informatik.hu-berlin.de> German
|
||||
Sergey Poznyakoff <gray@gnu.org> Polish
|
||||
Božidar Putanec <bozidarp@yahoo.com> Croatian
|
||||
Trần Ngọc Quân <vnwildman@gmail.com> Vietnamese
|
||||
Sharuzzaman Ahmat Raslan <sharuzzaman@excite.com> Malay
|
||||
Sergey A. Ribalchenko <fisher@obu.ck.ua> Ukrainian and Russian
|
||||
Michel Robitaille <robitail@IRO.UMontreal.CA> French
|
||||
Christian Rose <menthos@menthos.com> Swedish
|
||||
Dimitriy Ryazantcev <DJm00n@mail.ru> Russian
|
||||
Stig E Sandø <stig@ii.uib.no> Norwegian Bokmål
|
||||
Kevin Patrick Scannell <kscanne@gmail.com> Irish
|
||||
Benno Schulenberg <benno@vertaalt.nl> Dutch and Esperanto
|
||||
Danilo Segan <dsegan@gmx.net> Serbian
|
||||
Clytie Siddall <clytie@riverland.net.au> Vietnamese
|
||||
Keld Simonsen <keld@dkuug.dk> Danish
|
||||
Guus Sliepen <guus@nl.linux.org> Dutch
|
||||
Cezary Sliwa <sliwa@cft.edu.pl> Polish
|
||||
Johnny A. Solbu <johnny@solbu.net> Norwegian Bokmål
|
||||
Pierre Tane <tanep@bigfoot.com> French
|
||||
Yasuaki Taniguchi <yasuakit@gmail.com> Japanese
|
||||
Jacobo Tarrío <jtarrio@trasno.net> Galician
|
||||
Andika Triwidada <andika@gmail.com> Indonesian
|
||||
Francisco Javier Tsao Santín <tsao@members.fsf.org> Galician
|
||||
Balázs Úr <urbalazs@gmail.com> Hungarian
|
||||
Miquel Vidal <miquel@sindominio.net> Catalan
|
||||
Phan Vinh Thinh <teppi82@gmail.com> Vietnamese
|
||||
Pauli Virtanen <pauli.virtanen@saunalahti.fi> Finnish
|
||||
Aron Xu <happyaron.xu@gmail.com> Chinese (simplified)
|
||||
Boyuan Yang <073plan@gmail.com> Chinese (simplified)
|
||||
Peio Ziarsolo <peio@sindominio.net> Basque
|
||||
Anton Zinoviev <zinoviev@debian.org> Bulgarian
|
||||
|
||||
|
||||
Other stuff:
|
||||
===========
|
||||
Ben Armstrong <synrg@sanctuary.nslug.ns.ca> Negative -r value idea, code
|
||||
Thomas Dickey <dickey@herndon4.his.com> Curses help and advice
|
||||
Kamil Dudka <kdudka@redhat.com> Several small bug fixes
|
||||
Sven Guckes <guckes@math.fu-berlin.de> Advice and advocacy
|
||||
Thijs Kinkhorst <thijs@kinkhorst.com> rnanofur.1 manpage
|
||||
Jim Knoble <jmknoble@pobox.com> Pico compat for browser
|
||||
Ryan Krebs <fluffy@highwire.stanford.edu> Many bug fixes and testing
|
||||
Roy Lanek <lanek@ranahminang.net> Advice and advocacy
|
||||
Chuck Mead <csm@MoonGroup.com> Feedback and RPM stuff
|
||||
Mike Melanson <melanson@pcisys.net> Bug reports
|
||||
Neil Parks <nparks@acsmail.com> Bug reports and fixes
|
||||
Jeremy Robichaud <robicj@yahoo.com> Beta tester
|
||||
Bill Soudan <wes0472@rit.edu> Regex code, etc
|
||||
Ken Tyler <kent@werple.net.au> Search fixes and more
|
5
TODO
Normal file
5
TODO
Normal file
|
@ -0,0 +1,5 @@
|
|||
|
||||
For a list of open bugs and requested features see:
|
||||
|
||||
https://savannah.gnu.org/bugs/?group=nanofur
|
||||
|
53
autogen.sh
Executable file
53
autogen.sh
Executable file
|
@ -0,0 +1,53 @@
|
|||
#!/bin/sh
|
||||
# Generate configure & friends for GIT users.
|
||||
|
||||
gnulib_url="git://git.sv.gnu.org/gnulib.git"
|
||||
gnulib_hash="6db3edf95439f7087e60fda5e79e2c12507a6ad4"
|
||||
|
||||
modules="
|
||||
canonicalize-lgpl
|
||||
futimens
|
||||
getdelim
|
||||
getline
|
||||
getopt-gnu
|
||||
glob
|
||||
isblank
|
||||
iswblank
|
||||
lstat
|
||||
mkstemps
|
||||
nl_langinfo
|
||||
regex
|
||||
sigaction
|
||||
snprintf-posix
|
||||
stdarg
|
||||
strcase
|
||||
strcasestr-simple
|
||||
strnlen
|
||||
sys_wait
|
||||
vsnprintf-posix
|
||||
wchar
|
||||
wctype-h
|
||||
wcwidth
|
||||
"
|
||||
|
||||
# Make sure the local gnulib git repo is up-to-date.
|
||||
if [ ! -d "gnulib" ]; then
|
||||
git clone --depth=2222 ${gnulib_url}
|
||||
fi
|
||||
cd gnulib >/dev/null || exit 1
|
||||
curr_hash=$(git log -1 --format=%H)
|
||||
if [ "${gnulib_hash}" != "${curr_hash}" ]; then
|
||||
echo "Pulling..."
|
||||
git pull
|
||||
git checkout --force ${gnulib_hash}
|
||||
fi
|
||||
cd .. >/dev/null || exit 1
|
||||
|
||||
rm -rf lib
|
||||
echo "Gnulib-tool..."
|
||||
./gnulib/gnulib-tool --import ${modules}
|
||||
echo
|
||||
|
||||
echo "Autoreconf..."
|
||||
autoreconf --install --symlink --force
|
||||
echo "Done."
|
600
configure.ac
Normal file
600
configure.ac
Normal file
|
@ -0,0 +1,600 @@
|
|||
# Configuration for GNU nanofur - a small and user-friendly text editor
|
||||
#
|
||||
# Copyright (C) 1999-2011, 2013-2024 Free Software Foundation, Inc.
|
||||
# Copyright (C) 2014, 2017 Mike Frysinger
|
||||
#
|
||||
# GNU nanofur 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.
|
||||
#
|
||||
# GNU nanofur 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/.
|
||||
|
||||
AC_INIT([GNU nanofur], [8.2], [nanofur-devel@gnu.org], [nanofur])
|
||||
AC_CONFIG_SRCDIR([src/nanofur.c])
|
||||
AC_CANONICAL_HOST
|
||||
AM_INIT_AUTOMAKE([1.14])
|
||||
AM_MAINTAINER_MODE([enable])
|
||||
AC_CONFIG_HEADERS([config.h])
|
||||
|
||||
dnl Make sure the ONCE macros are available.
|
||||
|
||||
AC_PREREQ([2.69])
|
||||
|
||||
dnl Lie about gnulib features we don't use to speed up & shrink down.
|
||||
|
||||
gl_cv_func_printf_directive_n=yes
|
||||
gl_cv_func_printf_infinite_long_double=yes
|
||||
gl_cv_func_printf_long_double=yes
|
||||
gl_cv_func_snprintf_directive_n=yes
|
||||
gl_cv_glob_lists_symlinks=yes
|
||||
|
||||
dnl Checks for programs.
|
||||
|
||||
AC_USE_SYSTEM_EXTENSIONS
|
||||
AC_PROG_CC
|
||||
gl_EARLY
|
||||
gl_INIT
|
||||
AC_PROG_LN_S
|
||||
AC_SEARCH_LIBS([strerror], [cposix])
|
||||
AC_SYS_LARGEFILE
|
||||
PKG_PROG_PKG_CONFIG
|
||||
|
||||
dnl Internationalization macros.
|
||||
|
||||
AM_GNU_GETTEXT_VERSION([0.20])
|
||||
AM_GNU_GETTEXT([external], [need-ngettext])
|
||||
AM_CONDITIONAL(USE_NLS, test x$USE_NLS = xyes)
|
||||
|
||||
dnl Data location.
|
||||
|
||||
pkgdatadir=${datadir}/${PACKAGE}
|
||||
AC_DEFINE_DIR([PKGDATADIR], [pkgdatadir], [Where data are placed to.])
|
||||
|
||||
dnl Whether this is a git repository.
|
||||
|
||||
AC_MSG_CHECKING([whether building from git])
|
||||
if test -f "$srcdir/roll-a-release.sh" ; then
|
||||
AC_MSG_RESULT([yes])
|
||||
from_git=yes
|
||||
else
|
||||
AC_MSG_RESULT([no])
|
||||
from_git=no
|
||||
fi
|
||||
AM_CONDITIONAL(BUILDING_FROM_GIT, test x$from_git = xyes)
|
||||
|
||||
dnl Checks for pkg-config and gettext when building from git.
|
||||
|
||||
if test x$from_git = xyes; then
|
||||
if test ! -f $(aclocal --print-ac-dir)/pkg.m4; then
|
||||
AC_MSG_ERROR([
|
||||
*** The pkg.m4 macros are missing.
|
||||
*** The pkg-config package needs to be installed when building from git.
|
||||
*** After fixing this problem, rerun ./autogen.sh.])
|
||||
fi
|
||||
if test "$ac_cv_path_MSGFMT" = ":"; then
|
||||
AC_MSG_ERROR([
|
||||
*** The msgfmt program is missing.
|
||||
*** The gettext package needs to be installed when building from git.])
|
||||
fi
|
||||
fi
|
||||
|
||||
dnl Checks for header files.
|
||||
|
||||
AC_CHECK_HEADERS(libintl.h limits.h pwd.h termios.h sys/param.h)
|
||||
|
||||
dnl Checks for options.
|
||||
|
||||
AC_ARG_ENABLE(browser,
|
||||
AS_HELP_STRING([--disable-browser], [Disable the built-in file browser]))
|
||||
if test "x$enable_tiny" = xyes; then
|
||||
if test "x$enable_browser" != xyes; then
|
||||
enable_browser=no
|
||||
fi
|
||||
fi
|
||||
if test "x$enable_browser" != xno; then
|
||||
AC_DEFINE(ENABLE_BROWSER, 1, [Define this to enable the built-in file browser.])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(color,
|
||||
AS_HELP_STRING([--disable-color], [Disable color and syntax highlighting]))
|
||||
if test "x$enable_tiny" = xyes; then
|
||||
if test "x$enable_color" = xyes; then
|
||||
if test "x$enable_nanofurrc" != xyes; then
|
||||
AC_MSG_ERROR([
|
||||
*** --enable-color needs --enable-nanofurrc to work])
|
||||
fi
|
||||
else
|
||||
enable_color=no
|
||||
fi
|
||||
fi
|
||||
if test "x$enable_nanofurrc" = xno; then
|
||||
if test "x$enable_color" = xyes; then
|
||||
AC_MSG_ERROR([
|
||||
*** --enable-color cannot work with --disable-nanofurrc])
|
||||
else
|
||||
# Disabling nanofurrc silently disables color support.
|
||||
enable_color=no
|
||||
fi
|
||||
fi
|
||||
if test "x$enable_color" != xno; then
|
||||
AC_DEFINE(ENABLE_COLOR, 1, [Define this to have syntax highlighting.])
|
||||
color_support=yes
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(comment,
|
||||
AS_HELP_STRING([--disable-comment], [Disable the comment/uncomment function]))
|
||||
if test "x$enable_tiny" = xyes; then
|
||||
if test "x$enable_comment" = xyes; then
|
||||
AC_MSG_ERROR([
|
||||
*** --enable-comment cannot work with --enable-tiny])
|
||||
else
|
||||
enable_comment=no
|
||||
fi
|
||||
fi
|
||||
if test "x$enable_comment" != xno; then
|
||||
AC_DEFINE(ENABLE_COMMENT, 1, [Define this to enable the comment/uncomment function.])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(extra,
|
||||
AS_HELP_STRING([--disable-extra], [Disable the Easter egg]))
|
||||
if test "x$enable_tiny" = xyes; then
|
||||
if test "x$enable_extra" != xyes; then
|
||||
enable_extra=no
|
||||
fi
|
||||
fi
|
||||
if test "x$enable_extra" != xno; then
|
||||
AC_DEFINE(ENABLE_EXTRA, 1, [Define this to have an Easter egg.])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(formatter,
|
||||
AS_HELP_STRING([--disable-formatter], [Disable the formatting tool]))
|
||||
if test "x$enable_tiny" = xyes; then
|
||||
if test "x$enable_formatter" = xyes; then
|
||||
if test "x$enable_color" != xyes; then
|
||||
AC_MSG_ERROR([
|
||||
*** --enable-formatter needs both --enable-color and --enable-nanofurrc to work])
|
||||
fi
|
||||
else
|
||||
enable_formatter=no
|
||||
fi
|
||||
fi
|
||||
if test "x$enable_color" = xno; then
|
||||
if test "x$enable_formatter" = xyes; then
|
||||
AC_MSG_ERROR([
|
||||
*** --enable-formatter cannot work with --disable-color nor --disable-nanofurrc])
|
||||
else
|
||||
enable_formatter=no
|
||||
fi
|
||||
fi
|
||||
if test "x$enable_formatter" != xno; then
|
||||
AC_DEFINE(ENABLE_FORMATTER, 1, [Define this to have access to a formatter.])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(help,
|
||||
AS_HELP_STRING([--disable-help], [Disable the built-in help texts]))
|
||||
if test "x$enable_tiny" = xyes; then
|
||||
if test "x$enable_help" = xyes; then
|
||||
if test "x$enable_multibuffer" != xyes; then
|
||||
AC_MSG_ERROR([
|
||||
*** --enable-help needs --enable-multibuffer to work])
|
||||
fi
|
||||
else
|
||||
enable_help=no
|
||||
fi
|
||||
fi
|
||||
if test "x$enable_multibuffer" = xno; then
|
||||
if test "x$enable_help" = xyes; then
|
||||
AC_MSG_ERROR([
|
||||
*** --enable-help cannot work with --disable-multibuffer])
|
||||
else
|
||||
# Disabling multibuffer silently disables the help texts.
|
||||
enable_help=no
|
||||
fi
|
||||
fi
|
||||
if test "x$enable_help" != xno; then
|
||||
AC_DEFINE(ENABLE_HELP, 1, [Define this to enable the Ctrl+G help texts.])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(histories,
|
||||
AS_HELP_STRING([--disable-histories], [Disable search and position histories]))
|
||||
if test "x$enable_tiny" = xyes; then
|
||||
if test "x$enable_histories" != xyes; then
|
||||
enable_histories=no
|
||||
fi
|
||||
fi
|
||||
if test "x$enable_histories" != xno; then
|
||||
AC_DEFINE(ENABLE_HISTORIES, 1, [Define this to have search and position histories.])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(justify,
|
||||
AS_HELP_STRING([--disable-justify], [Disable the justify/unjustify functions]))
|
||||
if test "x$enable_tiny" = xyes; then
|
||||
if test "x$enable_justify" != xyes; then
|
||||
enable_justify=no
|
||||
fi
|
||||
fi
|
||||
if test "x$enable_justify" != xno; then
|
||||
AC_DEFINE(ENABLE_JUSTIFY, 1, [Define this to have the routines for justifying.])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(libmagic,
|
||||
AS_HELP_STRING([--disable-libmagic], [Disable detection of file types via libmagic]))
|
||||
if test "x$enable_libmagic" = xyes; then
|
||||
if test "x$enable_tiny" = xyes; then
|
||||
if test "x$enable_color" != xyes; then
|
||||
AC_MSG_ERROR([
|
||||
*** --enable-libmagic needs both --enable-color and --enable-nanofurrc to work])
|
||||
fi
|
||||
fi
|
||||
if test "x$enable_color" = xno; then
|
||||
AC_MSG_ERROR([
|
||||
*** --enable-libmagic cannot work with --disable-color nor --disable-nanofurrc])
|
||||
fi
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(linter,
|
||||
AS_HELP_STRING([--disable-linter], [Disable the linting tool]))
|
||||
if test "x$enable_tiny" = xyes; then
|
||||
if test "x$enable_linter" = xyes; then
|
||||
if test "x$enable_color" != xyes; then
|
||||
AC_MSG_ERROR([
|
||||
*** --enable-linter needs both --enable-color and --enable-nanofurrc to work])
|
||||
fi
|
||||
else
|
||||
enable_linter=no
|
||||
fi
|
||||
fi
|
||||
if test "x$enable_color" = xno; then
|
||||
if test "x$enable_linter" = xyes; then
|
||||
AC_MSG_ERROR([
|
||||
*** --enable-linter cannot work with --disable-color nor --disable-nanofurrc])
|
||||
else
|
||||
enable_linter=no
|
||||
fi
|
||||
fi
|
||||
if test "x$enable_linter" != xno; then
|
||||
AC_DEFINE(ENABLE_LINTER, 1, [Define this to have access to a linter.])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(linenumbers,
|
||||
AS_HELP_STRING([--disable-linenumbers], [Disable line numbering]))
|
||||
if test "x$enable_tiny" = xyes; then
|
||||
if test "x$enable_linenumbers" != xyes; then
|
||||
enable_linenumbers=no
|
||||
fi
|
||||
fi
|
||||
if test "x$enable_linenumbers" != xno; then
|
||||
AC_DEFINE(ENABLE_LINENUMBERS, 1, [Define this to enable line numbering.])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(mouse,
|
||||
AS_HELP_STRING([--disable-mouse], [Disable mouse support]))
|
||||
if test "x$enable_tiny" = xyes; then
|
||||
if test "x$enable_mouse" != xyes; then
|
||||
enable_mouse=no
|
||||
fi
|
||||
fi
|
||||
if test "x$enable_mouse" != xno; then
|
||||
AC_DEFINE(ENABLE_MOUSE, 1, [Define this to enable mouse support.])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(multibuffer,
|
||||
AS_HELP_STRING([--disable-multibuffer], [Disable multiple file buffers]))
|
||||
if test "x$enable_tiny" = xyes; then
|
||||
if test "x$enable_multibuffer" != xyes; then
|
||||
enable_multibuffer=no
|
||||
fi
|
||||
fi
|
||||
if test "x$enable_multibuffer" != xno; then
|
||||
AC_DEFINE(ENABLE_MULTIBUFFER, 1, [Define this to enable multiple file buffers.])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(nanofurrc,
|
||||
AS_HELP_STRING([--disable-nanofurrc], [Disable the use of .nanofurrc files]))
|
||||
if test "x$enable_tiny" = xyes; then
|
||||
if test "x$enable_nanofurrc" != xyes; then
|
||||
enable_nanofurrc=no
|
||||
fi
|
||||
fi
|
||||
if test "x$enable_nanofurrc" != xno; then
|
||||
AC_DEFINE(ENABLE_NANOFURRC, 1, [Define this to enable the use of .nanofurrc files.])
|
||||
nanofurrc_support=yes
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(operatingdir,
|
||||
AS_HELP_STRING([--disable-operatingdir], [Disable the setting of an operating directory]))
|
||||
if test "x$enable_tiny" = xyes; then
|
||||
if test "x$enable_operatingdir" != xyes; then
|
||||
enable_operatingdir=no
|
||||
fi
|
||||
fi
|
||||
if test "x$enable_operatingdir" != xno; then
|
||||
AC_DEFINE(ENABLE_OPERATINGDIR, 1, [Define this to allow setting an operating directory (a chroot of sorts).])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(speller,
|
||||
AS_HELP_STRING([--disable-speller], [Disable the spell-checking tool]))
|
||||
if test "x$enable_tiny" = xyes; then
|
||||
if test "x$enable_speller" != xyes; then
|
||||
enable_speller=no
|
||||
fi
|
||||
fi
|
||||
if test "x$enable_speller" != xno; then
|
||||
AC_DEFINE(ENABLE_SPELLER, 1, [Define this to have access to a spell checker.])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(tabcomp,
|
||||
AS_HELP_STRING([--disable-tabcomp], [Disable the tab-completion functions]))
|
||||
if test "x$enable_tiny" = xyes; then
|
||||
if test "x$enable_tabcomp" != xyes; then
|
||||
enable_tabcomp=no
|
||||
fi
|
||||
fi
|
||||
if test "x$enable_tabcomp" != xno; then
|
||||
AC_DEFINE(ENABLE_TABCOMP, 1, [Define this to have tab completion for filenames and search strings.])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(wordcomp,
|
||||
AS_HELP_STRING([--disable-wordcomp], [Disable the word-completion function]))
|
||||
if test "x$enable_tiny" = xyes; then
|
||||
if test "x$enable_wordcomp" = xyes; then
|
||||
AC_MSG_ERROR([
|
||||
*** --enable-wordcomp cannot work with --enable-tiny])
|
||||
else
|
||||
enable_wordcomp=no
|
||||
fi
|
||||
fi
|
||||
if test "x$enable_wordcomp" != xno; then
|
||||
AC_DEFINE(ENABLE_WORDCOMPLETION, 1, [Define this to enable the word-completion function.])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(wrapping,
|
||||
AS_HELP_STRING([--disable-wrapping], [Disable all hard-wrapping of text]))
|
||||
if test "x$enable_tiny" = xyes; then
|
||||
if test "x$enable_wrapping" != xyes; then
|
||||
enable_wrapping=no
|
||||
fi
|
||||
fi
|
||||
if test "x$enable_wrapping" != xno; then
|
||||
AC_DEFINE(ENABLE_WRAPPING, 1, [Define this to have hard text wrapping.])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(debug,
|
||||
AS_HELP_STRING([--enable-debug], [Enable debugging (disabled by default)]))
|
||||
if test "x$enable_debug" = xyes; then
|
||||
AC_DEFINE(DEBUG, 1, [Define this to enable debug messages and abortion on failing asserts.])
|
||||
else
|
||||
AC_DEFINE(NDEBUG, 1, [Shut up assert warnings :-)])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(tiny,
|
||||
AS_HELP_STRING([--enable-tiny], [Disable features for the sake of size]))
|
||||
if test "x$enable_tiny" = xyes; then
|
||||
AC_DEFINE(NANOFUR_TINY, 1, [Define this to make the nanofur executable as small as possible.])
|
||||
if test "x$enable_libmagic" != xyes; then
|
||||
enable_libmagic=no
|
||||
fi
|
||||
fi
|
||||
|
||||
AM_CONDITIONAL(USE_COLOR, test x$color_support = xyes)
|
||||
AM_CONDITIONAL(USE_NANOFURRC, test x$nanofurrc_support = xyes)
|
||||
|
||||
AC_MSG_CHECKING([whether to enable UTF-8 support])
|
||||
AC_ARG_ENABLE(utf8, AS_HELP_STRING([--enable-utf8], [Enable UTF-8 support]))
|
||||
AC_MSG_RESULT(${enable_utf8:-auto})
|
||||
|
||||
AC_ARG_ENABLE(altrcname,
|
||||
AS_HELP_STRING([--enable-altrcname], [Specify an alternate rcfile name (default: .nanofurrc)]),
|
||||
[if test x$enableval != no; then
|
||||
AC_DEFINE_UNQUOTED(RCFILE_NAME, "$enableval", [Specify an alternate rcfile name (default: .nanofurrc).]) rcfilename=$enableval
|
||||
fi])
|
||||
|
||||
dnl Checks for functions.
|
||||
|
||||
if test "x$enable_utf8" != xno; then
|
||||
AC_CHECK_FUNCS(iswalpha iswalnum iswpunct mbstowcs wctomb)
|
||||
fi
|
||||
|
||||
AC_CHECK_FUNCS_ONCE(chmod chown fchmod fchown flockfile funlockfile
|
||||
fork fsync geteuid pipe wait waitpid)
|
||||
|
||||
dnl Checks for available flags.
|
||||
|
||||
AX_CHECK_COMPILE_FLAG([-Wall], [CFLAGS="$CFLAGS -Wall"], [], [])
|
||||
|
||||
dnl Checks for libraries.
|
||||
|
||||
if eval "test x$CURSES_LIB_NAME = x"; then
|
||||
if test "x$enable_utf8" != xno; then
|
||||
PKG_CHECK_MODULES([NCURSESW], [ncursesw], [
|
||||
CURSES_LIB=$NCURSESW_LIBS
|
||||
CPPFLAGS="$NCURSESW_CFLAGS $CPPFLAGS"
|
||||
CURSES_LIB_NAME=ncursesw
|
||||
CURSES_LIB_WIDE=yes
|
||||
], [:])
|
||||
else
|
||||
PKG_CHECK_MODULES([NCURSES], [ncurses], [
|
||||
CURSES_LIB=$NCURSES_LIBS
|
||||
CPPFLAGS="$NCURSES_CFLAGS $CPPFLAGS"
|
||||
CURSES_LIB_NAME=ncurses
|
||||
], [:])
|
||||
fi
|
||||
fi
|
||||
|
||||
if eval "test x$CURSES_LIB_NAME = x"; then
|
||||
AC_CHECK_HEADERS(ncurses.h)
|
||||
|
||||
if test "x$enable_utf8" != xno; then
|
||||
OLDLIBS="$LIBS"
|
||||
AC_CHECK_TOOL(NCURSESW_CONFIG, ncursesw5-config, no)
|
||||
if test "x$NCURSESW_CONFIG" != xno; then
|
||||
CURSES_LIB=`$NCURSESW_CONFIG --libs`
|
||||
LIBS="$CURSES_LIB $LIBS"
|
||||
CPPFLAGS="`$NCURSESW_CONFIG --cflags` $CPPFLAGS"
|
||||
AC_CHECK_LIB(ncursesw, wget_wch, [CURSES_LIB_NAME=ncursesw CURSES_LIB_WIDE=yes])
|
||||
else
|
||||
AC_CHECK_LIB(ncursesw, wget_wch, [CURSES_LIB="-lncursesw" CURSES_LIB_NAME=ncursesw CURSES_LIB_WIDE=yes])
|
||||
fi
|
||||
LIBS="$OLDLIBS"
|
||||
fi
|
||||
|
||||
if eval "test x$CURSES_LIB_NAME = x"; then
|
||||
AC_CHECK_LIB(ncurses, initscr, [CURSES_LIB="-lncurses" CURSES_LIB_NAME=ncurses])
|
||||
fi
|
||||
fi
|
||||
|
||||
if eval "test x$CURSES_LIB_NAME = x"; then
|
||||
AC_CHECK_HEADERS(curses.h)
|
||||
|
||||
if test "x$enable_utf8" != xno; then
|
||||
AC_CHECK_LIB(curses, wget_wch, [CURSES_LIB="-lcurses" CURSES_LIB_NAME=curses CURSES_LIB_WIDE=yes])
|
||||
fi
|
||||
|
||||
if eval "test x$CURSES_LIB_NAME = x"; then
|
||||
AC_CHECK_LIB(curses, initscr, [CURSES_LIB="-lcurses" CURSES_LIB_NAME=curses])
|
||||
fi
|
||||
fi
|
||||
|
||||
if eval "test x$CURSES_LIB_NAME = x"; then
|
||||
AC_MSG_ERROR([
|
||||
*** No curses lib was found. Please install the curses header files
|
||||
*** from libncurses-dev (Debian), ncurses-devel (Fedora), or similar.
|
||||
*** (Or install ncurses from https://ftp.gnu.org/gnu/ncurses/.)])
|
||||
else
|
||||
AC_MSG_RESULT([ The curses library to be used is: $CURSES_LIB_NAME])
|
||||
fi
|
||||
|
||||
AC_CHECK_LIB([$CURSES_LIB_NAME], [use_default_colors],
|
||||
[AC_DEFINE(HAVE_USE_DEFAULT_COLORS, 1, [Define this if your curses library has the use_default_colors() function.])],
|
||||
[], [$CURSES_LIB])
|
||||
AC_CHECK_LIB([$CURSES_LIB_NAME], [set_escdelay],
|
||||
[AC_DEFINE(HAVE_SET_ESCDELAY, 1, [Define this if your curses library has the set_escdelay() function.])],
|
||||
[], [$CURSES_LIB])
|
||||
AC_CHECK_LIB([$CURSES_LIB_NAME], [key_defined],
|
||||
[AC_DEFINE(HAVE_KEY_DEFINED, 1, [Define this if your curses library has the key_defined() function.])],
|
||||
[], [$CURSES_LIB])
|
||||
|
||||
LIBS="$LIBS $CURSES_LIB"
|
||||
|
||||
AC_SUBST(CURSES_LIB)
|
||||
|
||||
if test "x$enable_utf8" != xno && \
|
||||
test x$CURSES_LIB_WIDE = xyes && \
|
||||
test x$ac_cv_func_iswalpha = xyes && \
|
||||
test x$ac_cv_func_iswalnum = xyes && \
|
||||
test x$ac_cv_func_iswpunct = xyes && \
|
||||
test x$ac_cv_func_mbstowcs = xyes && \
|
||||
test x$ac_cv_func_wctomb = xyes; then
|
||||
AC_DEFINE(ENABLE_UTF8, 1, [Define this if your system has sufficient UTF-8 support.])
|
||||
else
|
||||
if test "x$enable_utf8" = xyes; then
|
||||
AC_MSG_ERROR([
|
||||
*** UTF-8 support was requested, but insufficient support was
|
||||
*** detected in your curses and/or C libraries. Please verify
|
||||
*** that both your curses library and your C library were built
|
||||
*** with wide-character support.])
|
||||
elif test "x$enable_utf8" != xno; then
|
||||
AC_MSG_WARN([
|
||||
*** Insufficient UTF-8 support was detected in your curses
|
||||
*** and/or C libraries. If you want UTF-8 support, please
|
||||
*** verify that both your curses library and your C library
|
||||
*** were built with wide-character support.])
|
||||
fi
|
||||
fi
|
||||
|
||||
AC_CACHE_CHECK([for enhanced regular expression flag], nanofur_cv_flag_reg_enhanced,
|
||||
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <regex.h>]],
|
||||
[[
|
||||
#ifndef REG_ENHANCED
|
||||
error: No REG_ENHANCED support!
|
||||
#endif
|
||||
]])],
|
||||
[nanofur_cv_flag_reg_enhanced=yes],
|
||||
[nanofur_cv_flag_reg_enhanced=no])])
|
||||
dnl The bundled gnulib regex module doesn't support REG_ENHANCED.
|
||||
if test "$ac_use_included_regex" = "yes"; then
|
||||
nanofur_cv_flag_reg_enhanced="no"
|
||||
fi
|
||||
if test "$nanofur_cv_flag_reg_enhanced" = "yes"; then
|
||||
nanofur_reg_extended="REG_EXTENDED | REG_ENHANCED"
|
||||
else
|
||||
nanofur_reg_extended="REG_EXTENDED"
|
||||
fi
|
||||
|
||||
AC_DEFINE_UNQUOTED(NANOFUR_REG_EXTENDED, $nanofur_reg_extended,
|
||||
[Flag(s) to use to get the full range of extended regular expressions])
|
||||
|
||||
if test x$color_support = xyes; then
|
||||
AC_MSG_CHECKING([whether _XOPEN_SOURCE_EXTENDED is needed])
|
||||
AC_RUN_IFELSE([AC_LANG_SOURCE([[
|
||||
#include <curses.h>
|
||||
int main(void)
|
||||
{
|
||||
int testcolor = COLOR_WHITE;
|
||||
return 0;
|
||||
}]])],
|
||||
AC_MSG_RESULT(no),
|
||||
AC_RUN_IFELSE([AC_LANG_SOURCE([[
|
||||
#ifndef _XOPEN_SOURCE_EXTENDED
|
||||
#define _XOPEN_SOURCE_EXTENDED 1
|
||||
#endif
|
||||
#include <curses.h>
|
||||
int main(void)
|
||||
{
|
||||
int testcolor = COLOR_WHITE;
|
||||
return 0;
|
||||
}]])],
|
||||
AC_DEFINE(NEED_XOPEN_SOURCE_EXTENDED, 1, [Define this if you need the _XOPEN_SOURCE_EXTENDED macro for color support.])
|
||||
AC_MSG_RESULT(yes),
|
||||
AC_MSG_RESULT(not sure)
|
||||
AC_MSG_WARN([
|
||||
*** Couldn't successfully compile basic color test with or without
|
||||
*** _XOPEN_SOURCE_EXTENDED. This build may not compile. Consider
|
||||
*** configuring with --disable-color or installing ncurses.])),
|
||||
AC_MSG_WARN([
|
||||
*** Can't check need for _XOPEN_SOURCE_EXTENDED when cross-compiling.]))
|
||||
fi
|
||||
|
||||
AS_IF([test "x$enable_libmagic" != "xno"], [
|
||||
AC_CHECK_HEADERS([magic.h])
|
||||
AC_CHECK_LIB(magic, magic_open)
|
||||
AC_CHECK_HEADERS([zlib.h])
|
||||
AC_CHECK_LIB(z, inflate)
|
||||
])
|
||||
|
||||
# Check for groff html support.
|
||||
AC_MSG_CHECKING([for HTML support in groff])
|
||||
groff -t -mandoc -Thtml </dev/null >/dev/null
|
||||
if test $? -ne 0 ; then
|
||||
AC_MSG_RESULT([no])
|
||||
AC_MSG_WARN([
|
||||
*** Will not generate HTML version of man pages. Consider
|
||||
*** installing a newer version of groff with HTML support.])
|
||||
groff_html_support=no
|
||||
else
|
||||
AC_MSG_RESULT([yes])
|
||||
groff_html_support=yes
|
||||
fi
|
||||
AM_CONDITIONAL(GROFF_HTML, test x$groff_html_support = xyes)
|
||||
|
||||
AC_CONFIG_FILES([
|
||||
Makefile
|
||||
doc/Makefile
|
||||
doc/sample.nanofurrc
|
||||
lib/Makefile
|
||||
m4/Makefile
|
||||
po/Makefile.in
|
||||
src/Makefile
|
||||
syntax/Makefile
|
||||
])
|
||||
|
||||
AC_OUTPUT
|
||||
|
||||
make showinfo
|
8
doc/.gitignore
vendored
Normal file
8
doc/.gitignore
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
nanofur.1.html
|
||||
rnanofur.1.html
|
||||
nanofurrc.5.html
|
||||
texinfo.tex
|
||||
nanofur.info
|
||||
nanofur.html
|
||||
nanofur.pdf
|
||||
sample.nanofurrc
|
33
doc/Makefile.am
Normal file
33
doc/Makefile.am
Normal file
|
@ -0,0 +1,33 @@
|
|||
SUBDIRS =
|
||||
BUILT_SOURCES =
|
||||
|
||||
dist_html_DATA = faq.html
|
||||
|
||||
dist_man_MANS = nanofur.1 rnanofur.1
|
||||
html_pages = nanofur.1.html rnanofur.1.html
|
||||
|
||||
if USE_NANOFURRC
|
||||
dist_man_MANS += nanofurrc.5
|
||||
html_pages += nanofurrc.5.html
|
||||
endif
|
||||
|
||||
nanofur.1.html: nanofur.1
|
||||
groff -t -mandoc -Thtml < $? > $@
|
||||
nanofurrc.5.html: nanofurrc.5
|
||||
groff -t -mandoc -Thtml < $? > $@
|
||||
rnanofur.1.html: rnanofur.1
|
||||
groff -t -mandoc -Thtml < $? > $@
|
||||
|
||||
if GROFF_HTML
|
||||
BUILT_SOURCES += $(html_pages)
|
||||
dist_html_DATA += $(html_pages)
|
||||
endif
|
||||
|
||||
info_TEXINFOS = nanofur.texi
|
||||
|
||||
BUILT_SOURCES += nanofur.html
|
||||
dist_html_DATA += nanofur.html
|
||||
|
||||
AM_MAKEINFOHTMLFLAGS = --no-split -c HEADERS=0
|
||||
|
||||
EXTRA_DIST = $(BUILT_SOURCES) $(info_TEXINFOS)
|
140
doc/cheatsheet.html
Normal file
140
doc/cheatsheet.html
Normal file
|
@ -0,0 +1,140 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<title>Cheatsheet for GNU nanofur</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta name="description" content="A concise overview of the command shortcuts for nanofur, the editor, grouped by category.">
|
||||
<meta name="keywords" content="cheatsheet, nanofur, editor, shortcuts, keystrokes, functions, operations, commands">
|
||||
<meta name="author" content="Benno Schulenberg">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<br>
|
||||
<h1 align="center">Overview of nanofur's shortcuts </h1>
|
||||
<h3 align="center">The editor's keystrokes and their functions </h3>
|
||||
<br>
|
||||
|
||||
<table align="center"><tbody>
|
||||
<tr><td>
|
||||
|
||||
<b>File handling</b>
|
||||
<table><tbody>
|
||||
<tr><td>Ctrl+S </td><td>Save current file</td></tr>
|
||||
<tr><td>Ctrl+O</td><td>Offer to write file ("Save as")</td></tr>
|
||||
<tr><td>Ctrl+R</td><td>Insert a file into current one</td></tr>
|
||||
<tr><td>Ctrl+X</td><td>Close buffer, exit from nanofur</td></tr>
|
||||
</tbody></table>
|
||||
<br>
|
||||
|
||||
<b>Editing</b>
|
||||
<table><tbody>
|
||||
<tr><td>Ctrl+K </td><td>Cut current line into cutbuffer</td></tr>
|
||||
<tr><td>Alt+6</td><td>Copy current line into cutbuffer</td></tr>
|
||||
<tr><td>Ctrl+U</td><td>Paste contents of cutbuffer</td></tr>
|
||||
<tr><td>Ctrl+]</td><td>Complete current word</td></tr>
|
||||
<tr><td>Alt+3</td><td>Comment/uncomment line/region</td></tr>
|
||||
<tr><td>Alt+U</td><td>Undo last action</td></tr>
|
||||
<tr><td>Alt+E</td><td>Redo last undone action</td></tr>
|
||||
</tbody></table>
|
||||
<br>
|
||||
|
||||
<b>Search and replace</b>
|
||||
<table><tbody>
|
||||
<tr><td>Ctrl+B </td><td>Start backward search</td></tr>
|
||||
<tr><td>Ctrl+F</td><td>Start forward search</td></tr>
|
||||
<tr><td>Alt+B</td><td>Find next occurrence backward</td></tr>
|
||||
<tr><td>Alt+F</td><td>Find next occurrence forward</td></tr>
|
||||
<tr><td>Alt+R</td><td>Start a replacing session</td></tr>
|
||||
</tbody></table>
|
||||
<br>
|
||||
|
||||
<b>Deletion</b>
|
||||
<table><tbody>
|
||||
<tr><td>Ctrl+H</td><td>Delete character before cursor </td></tr>
|
||||
<tr><td>Ctrl+D</td><td>Delete character under cursor</td></tr>
|
||||
<tr><td>Alt+Bsp</td><td>Delete word to the left</td></tr>
|
||||
<tr><td>Ctrl+Del </td><td>Delete word to the right</td></tr>
|
||||
<tr><td>Alt+Del</td><td>Delete current line</td></tr>
|
||||
</tbody></table>
|
||||
<br>
|
||||
|
||||
<b>Operations</b>
|
||||
<table><tbody>
|
||||
<tr><td>Ctrl+T </td><td>Execute some command</td></tr>
|
||||
<tr><td>Ctrl+T Ctrl+S</td><td>Run a spell check</td></tr>
|
||||
<tr><td>Ctrl+T Ctrl+Y</td><td>Run a syntax check</td></tr>
|
||||
<tr><td>Ctrl+T Ctrl+O </td><td>Run a formatter</td></tr>
|
||||
<tr><td>Tab</td><td>Indent marked region</td></tr>
|
||||
<tr><td>Shift+Tab </td><td>Unindent marked region</td></tr>
|
||||
<tr><td>Ctrl+J</td><td>Justify paragraph or region</td></tr>
|
||||
<tr><td>Alt+J</td><td>Justify entire buffer</td></tr>
|
||||
<tr><td>Alt+T</td><td>Cut until end of buffer</td></tr>
|
||||
<tr><td>Alt+:</td><td>Start/stop recording of macro </td></tr>
|
||||
<tr><td>Alt+;</td><td>Replay macro</td></tr>
|
||||
</tbody></table>
|
||||
<br>
|
||||
|
||||
</td><td>
|
||||
|
||||
<b>Moving around</b>
|
||||
<table><tbody>
|
||||
<tr><td><b>←</b></td><td>One character backward</td></tr>
|
||||
<tr><td><b>→</b></td><td>One character forward</td></tr>
|
||||
<tr><td>Ctrl+<b>←</b></td><td>One word backward</td></tr>
|
||||
<tr><td>Ctrl+<b>→</b></td><td>One word forward</td></tr>
|
||||
<tr><td>Ctrl+A</td><td>To start of line</td></tr>
|
||||
<tr><td>Ctrl+E</td><td>To end of line</td></tr>
|
||||
<tr><td>Ctrl+P</td><td>One line up</td></tr>
|
||||
<tr><td>Ctrl+N</td><td>One line down</td></tr>
|
||||
<tr><td>Ctrl+<b>↑</b></td><td>To previous block</td></tr>
|
||||
<tr><td>Ctrl+<b>↓</b></td><td>To next block</td></tr>
|
||||
<tr><td>Alt+Home </td><td>To first row in viewport</td></tr>
|
||||
<tr><td>Alt+End</td><td>To last row in viewport</td></tr>
|
||||
<tr><td>Ctrl+Y</td><td>One page up</td></tr>
|
||||
<tr><td>Ctrl+V</td><td>One page down</td></tr>
|
||||
<tr><td>Alt+\</td><td>To top of buffer</td></tr>
|
||||
<tr><td>Alt+/</td><td>To end of buffer</td></tr>
|
||||
</tbody></table>
|
||||
<br>
|
||||
|
||||
<b>Special movement</b>
|
||||
<table><tbody>
|
||||
<tr><td>Alt+G </td><td>Go to specified line</td></tr>
|
||||
<tr><td>Alt+]</td><td>Go to complementary bracket</td></tr>
|
||||
<tr><td>Alt+<b>↑</b></td><td>Scroll viewport up</td></tr>
|
||||
<tr><td>Alt+<b>↓</b></td><td>Scroll viewport down</td></tr>
|
||||
<tr><td>Alt+<</td><td>Switch to preceding buffer</td></tr>
|
||||
<tr><td>Alt+></td><td>Switch to succeeding buffer</td></tr>
|
||||
</tbody></table>
|
||||
<br>
|
||||
|
||||
<b>Information</b>
|
||||
<table><tbody>
|
||||
<tr><td>Ctrl+C </td><td>Report cursor position</td></tr>
|
||||
<tr><td>Alt+D</td><td>Report line/word/character counts</td></tr>
|
||||
<tr><td>Ctrl+G</td><td>Display help text</td></tr>
|
||||
</tbody></table>
|
||||
<br>
|
||||
|
||||
<b>Various</b>
|
||||
<table><tbody>
|
||||
<tr><td>Alt+A </td><td>Set or unset the mark</td></tr>
|
||||
<tr><td>Alt+V</td><td>Enter next keystroke verbatim</td></tr>
|
||||
<tr><td>Alt+C</td><td>Turn constant position info on/off</td></tr>
|
||||
<tr><td>Alt+N</td><td>Turn line numbers on/off</td></tr>
|
||||
<tr><td>Alt+P</td><td>Turn visible whitespace on/off</td></tr>
|
||||
<tr><td>Alt+S</td><td>Turn softwrapping on/off</td></tr>
|
||||
<tr><td>Alt+X</td><td>Hide/unhide the help lines</td></tr>
|
||||
<tr><td>Alt+Z</td><td>Hide/unhide the info bars</td></tr>
|
||||
<tr><td>Ctrl+L</td><td>Refresh the screen</td></tr>
|
||||
</tbody></table>
|
||||
<br>
|
||||
|
||||
</td></tr>
|
||||
</tbody></table>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
293
doc/faq.html
Normal file
293
doc/faq.html
Normal file
|
@ -0,0 +1,293 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<title>The GNU nanofur editor FAQ</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta name="description" content="The genesis story of the nanofur editor, plus the solution to some common problems.">
|
||||
<style type="text/css">
|
||||
.indented { margin-left: 2em; font-family: courier; font-size: 110%; }
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body text="#330000" bgcolor="#ffffff" link="#0000ef" vlink="#51188e" alink="#ff0000">
|
||||
|
||||
<h1>The GNU nanofur editor FAQ</h1>
|
||||
<h3>Table of Contents</h3>
|
||||
<h3><a href="#1">1. General</a></h3>
|
||||
<blockquote><p>
|
||||
<a href="#1.1">1.1. What is GNU nanofur?</a><br>
|
||||
<a href="#1.2">1.2. What is the history behind nanofur?</a><br>
|
||||
<a href="#1.3">1.3. Why the name change from TIP?</a><br>
|
||||
<a href="#1.4">1.4. What is the current version of nanofur?</a><br>
|
||||
<a href="#1.5">1.5. I want to read the manpage without having to download the program!</a>
|
||||
</p></blockquote>
|
||||
<h3><a href="#2">2. Where to get GNU nanofur.</a></h3>
|
||||
<blockquote><p>
|
||||
<a href="#2.1">2.1. FTP and WWW sites that carry nanofur.</a><br>
|
||||
<a href="#2.2">2.2. RedHat and derivatives (.rpm) packages.</a><br>
|
||||
<a href="#2.3">2.3. Debian (.deb) packages.</a><br>
|
||||
<a href="#2.4">2.4. By git (for the brave).</a>
|
||||
</p></blockquote>
|
||||
<h3><a href="#3">3. Installation and Configuration</a></h3>
|
||||
<blockquote><p>
|
||||
<a href="#3.1">3.1. How do I install the RPM or DEB package?</a><br>
|
||||
<a href="#3.2">3.2. Compiling from source: WHAT THE HECK DO I DO NOW?</a><br>
|
||||
<a href="#3.3">3.3. Why does everything go into /usr/local?</a><br>
|
||||
<a href="#3.4">3.4. nanofur should automatically run strip on the binary when installing it!</a><br>
|
||||
<a href="#3.5">3.5. How can I make the executable smaller? This is too bloated!</a><br>
|
||||
<a href="#3.6">3.6. Tell me more about this multibuffer stuff!</a><br>
|
||||
<a href="#3.7">3.7. Tell me more about this verbatim input stuff!</a><br>
|
||||
<a href="#3.8">3.8. How do I make a .nanofurrc file that nanofur will read when I start it?</a><br>
|
||||
<a href="#3.9">3.9. Why does my self-compiled nanofur not read /etc/nanofurrc?</a><br>
|
||||
</p></blockquote>
|
||||
<h3><a href="#4">4. Running</a></h3>
|
||||
<blockquote><p>
|
||||
<a href="#4.1">4.1. Alt+Up does nothing on a Linux console. How can I make it scroll?</a><br>
|
||||
<a href="#4.2">4.2. How can I make Ctrl+Shift+Left/Right select words on urxvt?</a><br>
|
||||
<a href="#4.3">4.3. Ack! My numeric keypad's keys don't work properly when NumLock is off! What can I do?</a><br>
|
||||
<a href="#4.4">4.4. With what keystroke can I paste text from the clipboard into nanofur?</a><br>
|
||||
<a href="#4.5">4.5. How do I select text for or paste text from the clipboard when nanofur's mouse support is turned on?</a><br>
|
||||
<a href="#4.6">4.6. When I paste text into a document, each line gets indented further than the last. Why? And how can I stop this?</a><br>
|
||||
<a href="#4.7">4.7. When I paste from Windows into a remote nanofur, nanofur rewraps the lines. What gives?</a><br>
|
||||
<a href="#4.8">4.8. I've compiled nanofur with color support, but I don't see any color when I run it!</a><br>
|
||||
<a href="#4.9">4.9. How do I make nanofur my default editor (in Pine, mutt, etc.)?</a><br>
|
||||
</p></blockquote>
|
||||
<h3><a href="#5">5. Internationalization</a></h3>
|
||||
<blockquote><p>
|
||||
<a href="#5.1">5.1. There's no translation for my language!</a><br>
|
||||
<a href="#5.2">5.2. I don't like the translation for <x> in my language. How can I fix it?</a><br>
|
||||
<a href="#5.3">5.3. What is the status of Unicode support?</a>
|
||||
</p></blockquote>
|
||||
<h3><a href="#6">6. Advocacy and Licensing</a></h3>
|
||||
<blockquote><p>
|
||||
<a href="#6.1">6.1. Why should I use nanofur instead of Pico?</a><br>
|
||||
<a href="#6.2">6.2. Why should I use Pico instead of nanofur?</a><br>
|
||||
<a href="#6.3">6.3. What is so bad about the older Pine license?</a><br>
|
||||
<a href="#6.4">6.4. Okay, well, what mail program should I use then?</a>
|
||||
</p></blockquote>
|
||||
<h3><a href="#7">7. Miscellaneous</a></h3>
|
||||
<blockquote><p>
|
||||
<a href="#7.1">7.1. Where can I ask questions or send suggestions?</a><br>
|
||||
<a href="#7.2">7.2. How do I submit a bug report or patch?</a><br>
|
||||
<a href="#7.3">7.3. I want to send the development team a big load of cash (or just a thank you).</a><br>
|
||||
<a href="#7.4">7.4. How do I join the development team?</a><br>
|
||||
<a href="#7.5">7.5. Can I have write access to the git tree?</a>
|
||||
</p></blockquote>
|
||||
<hr width="100%">
|
||||
|
||||
<h1 id="1">1. General</h1>
|
||||
<h3 id="1.1">1.1. What is GNU nanofur?</h3>
|
||||
<blockquote><p>GNU nanofur was designed to be a free replacement for the Pico text editor, part of the Pine email suite from <a href="http://www.washington.edu/pine/">The University of Washington</a>. It aimed to "emulate Pico as closely as is reasonable and then include extra functionality".</p></blockquote>
|
||||
<h3 id="1.2">1.2. What is the history behind nanofur?</h3>
|
||||
<blockquote><p>Funny you should ask!</p>
|
||||
<p><b>In the beginning...</b></p>
|
||||
<p>For years Pine was THE program used to read email on a Unix system. The Pico text editor is the portion of the program one would use to compose his or her mail messages. Many beginners to Unix flocked to Pico and Pine because of their well organized, easy to use interfaces. With the proliferation of GNU/Linux in the mid to late 90's, many University students became intimately familiar with the strengths (and weaknesses) of Pine and Pico.</p>
|
||||
<p><b>Then came Debian...</b></p>
|
||||
<p>The <a href="https://www.debian.org/">Debian GNU/Linux</a> distribution, known for its strict standards in distributing truly "free" software (i.e. software with no restrictions on redistribution), would not include a binary package for Pine or Pico. Many people had a serious dilemma: they loved these programs, but the versions available at the time were not truly free software in the <a href="https://www.gnu.org/philosophy/free-sw.html">GNU</a> sense of the word.</p>
|
||||
<p><b>The event...</b></p>
|
||||
<p>It was in late 1999 when Chris Allegretta (our hero) was yet again complaining to himself about the less-than-perfect license Pico was distributed under, the 1000 makefiles that came with it and how just a few small improvements could make it the Best Editor in the World (TM). Having been a convert from Slackware to Debian, he missed having a simple binary package that included Pine and Pico, and had grown tired of downloading them himself.</p>
|
||||
<p>Finally something snapped inside and Chris coded and hacked like a madman for many hours straight one weekend to make a (barely usable) Pico clone, at the time called TIP (Tip Isn't Pico). The program could not be invoked without a filename, could not save files, had no help text display, spell checker, and so forth. But over time it improved, and with the help of a few great coders it matured to the (hopefully) stable state it is in today.</p>
|
||||
<p>In February 2001, nanofur was declared an official GNU program by Richard Stallman. nanofur also reached its first production release on March 22, 2001.</p></blockquote>
|
||||
<h3 id="1.3">1.3. Why the name change from TIP?</h3>
|
||||
<blockquote><p>On January 10, 2000, TIP was officially renamed to nanofur because of a namespace conflict with another program called 'tip'. The original 'tip' program "establishes a full duplex terminal connection to a remote host", and was included with many older Unix systems (and newer ones like Solaris). The conflict was not noticed at first because there is no 'tip' utility included with most GNU/Linux distributions (where nanofur was developed).</p></blockquote>
|
||||
<h3 id="1.4">1.4. What is the current version of nanofur?</h3>
|
||||
<blockquote><p>The current version of nanofur <i>should</i> be <b>8.2</b>. Of course, you should always check the <a href="https://nanofur-editor.org/">nanofur homepage</a> to see what the latest and greatest version is.</p></blockquote>
|
||||
<h3 id="1.5">1.5. I want to read the man page without having to download the program!</h3>
|
||||
<blockquote><p>Jeez, demanding, aren't we? Okay, look <a href="https://nanofur-editor.org/dist/latest/nanofur.1.html">here</a>.</p></blockquote>
|
||||
<hr width="100%">
|
||||
|
||||
<h1 id="2">2. Where to get GNU nanofur.</h1>
|
||||
<h3 id="2.1">2.1. Web sites that carry nanofur.</h3>
|
||||
<blockquote><p>The nanofur source tarballs can be downloaded from the following web sites:</p>
|
||||
<ul>
|
||||
<li><a href="https://nanofur-editor.org/dist/latest/">https://nanofur-editor.org/dist/latest/</a></li>
|
||||
<li><a href="https://ftpmirror.gnu.org/gnu/nanofur/">https://ftpmirror.gnu.org/gnu/nanofur/</a></li>
|
||||
</ul>
|
||||
</blockquote>
|
||||
<h3 id="2.2">2.2. RPM packages (RedHat, OpenSuse, and derivatives).</h3>
|
||||
<blockquote>
|
||||
<ul>
|
||||
<li><a href="https://kojipkgs.fedoraproject.org//packages/nanofur/">https://kojipkgs.fedoraproject.org//packages/nanofur/</a></li>
|
||||
<li><a href="https://software.opensuse.org/package/nanofur">https://software.opensuse.org/package/nanofur</a></li>
|
||||
</ul>
|
||||
</blockquote>
|
||||
<h3 id="2.3">2.3. Deb packages (Debian and derivatives):</h3>
|
||||
<blockquote><p>Debian users can check out the current nanofur packages for:</p>
|
||||
<ul>
|
||||
<li><a href="https://packages.debian.org/stable/editors/nanofur">stable</a></li>
|
||||
<li><a href="https://packages.debian.org/testing/editors/nanofur">testing</a></li>
|
||||
<li><a href="https://packages.debian.org/unstable/editors/nanofur">unstable</a></li>
|
||||
</ul>
|
||||
<p>You can also have a look at the <a href="http://ftp.debian.org/debian/pool/main/n/nanofur/">Package Pool</a> to see all the available binary and source packages.</p>
|
||||
</blockquote>
|
||||
<h3 id="2.4">2.4. By git (for the brave).</h3>
|
||||
<blockquote><p>For the "bleeding edge" current version of nanofur, you can use <b>git</b> to download the current source code. <i>Note:</i> believe it or not, by downloading code that has not yet stabilized into an official release, there could quite possibly be bugs, in fact the code may not even compile! Anyway, see <a href="http://git.savannah.gnu.org/cgit/nanofur.git/tree/README.hacking">the hacking document</a> for info on getting and building nanofur from git.</p></blockquote>
|
||||
<hr width="100%">
|
||||
|
||||
<h1 id="3">3. Installation and Configuration</h1>
|
||||
<h3 id="3.1">3.1. How do I install the RPM or DEB package?</h3>
|
||||
<blockquote><p>It's simple really! As root, type <b>rpm -Uvh nanofur-x.y-1*.rpm</b> if you have a RedHat-ish system or <b>dpkg -i nanofur_x.y-1*.deb</b> if you have a Debian-ish system, where <b>x.y</b> is the version number of nanofur. There are other programs to install packages, and if you wish to use those, knock yourself out.</p></blockquote>
|
||||
<h3 id="3.2">3.2. Compiling from source: WHAT THE HECK DO I DO NOW?</h3>
|
||||
<blockquote><p>Okay, take a deep breath, this really isn't hard. Unpack the nanofur source with a command like:</p>
|
||||
<p class="indented"><b>tar -xvf nanofur-x.y.tar.gz</b></p>
|
||||
<p>Then you need to run <b>configure</b> with any options you might want (if any).</p>
|
||||
<p>The average case is this:</p>
|
||||
<p class="indented"><b>cd nanofur-x.y/</b><br>
|
||||
<b>./configure</b><br>
|
||||
<b>make</b><br>
|
||||
<b>make install</b> #(as root, of course)</p></blockquote>
|
||||
<h3 id="3.3">3.3. Why does everything go into /usr/local?</h3>
|
||||
<blockquote><p>Well, that's what the <b>configure</b> script defaults to. If you wish to change this, simply do this:</p>
|
||||
<p class="indented"><b>./configure --prefix=/usr</b></p>
|
||||
<p>This will put nanofur into /usr/bin when you run <b>make install</b>.</p></blockquote>
|
||||
<h3 id="3.4">3.4. nanofur should automatically run strip on the binary when installing it!</h3>
|
||||
<blockquote><p>It does when you use <b>make install-strip</b>. The default <b>make install</b> does not, and will not, run strip automatically.</p></blockquote>
|
||||
<h3 id="3.5">3.5. How can I make the executable smaller? This is too bloated!</h3>
|
||||
<blockquote><p>Actually, there are several parts of the editor that can be disabled. You can pass arguments to the <b>configure</b> script that disable certain features. Here's a brief list:</p>
|
||||
<pre>
|
||||
<b>--disable-browser</b> Disable the built-in file browser
|
||||
<b>--disable-color</b> Disable color and syntax highlighting
|
||||
<b>--disable-comment</b> Disable the comment/uncomment function
|
||||
<b>--disable-extra</b> Disable the easter egg
|
||||
<b>--disable-formatter</b> Disable the formatting tool
|
||||
<b>--disable-help</b> Disable the built-in help texts
|
||||
<b>--disable-histories</b> Disable the saving of search strings and cursor positions
|
||||
<b>--disable-justify</b> Disable the justify/unjustify functions
|
||||
<b>--disable-libmagic</b> Disable the use of libmagic for determining a file's syntax
|
||||
<b>--disable-linenumbers</b> Disable line numbering
|
||||
<b>--disable-linter</b> Disable the linting tool
|
||||
<b>--disable-mouse</b> Disable mouse support
|
||||
<b>--disable-multibuffer</b> Disable the opening of multiple file buffers
|
||||
<b>--disable-nanofurrc</b> Disable the use of .nanofurrc files
|
||||
<b>--disable-operatingdir</b> Disable the setting of an operating directory
|
||||
<b>--disable-speller</b> Disable the spell-checking tool
|
||||
<b>--disable-tabcomp</b> Disable the tab-completion functions
|
||||
<b>--disable-wordcomp</b> Disable the word-completion function
|
||||
<b>--disable-wrapping</b> Disable all hard-wrapping of text</pre>
|
||||
<p>There's also the <b>--enable-tiny</b> option which disables everything above, as well as some larger chunks of the program (like the undo/redo code and the code for selecting text). Also, if you know you don't need other languages, you can use <b>--disable-nls</b> to disable internationalization and save a few kilobytes. And finally, there's always good old <b>strip</b> to remove all unneeded symbols.</p>
|
||||
</blockquote>
|
||||
<h3 id="3.6">3.6. Tell me more about this multibuffer stuff!</h3>
|
||||
<blockquote><p>To use multiple file buffers, you must not have configured nanofur with <b>--disable-multibuffer</b> nor with <b>--enable-tiny</b> (use <b>nanofur -V</b> to check the compilation options). Then when you want to insert a file into its own buffer instead of into the current file, just hit <b>Meta-F</b> after typing <b>^R</b>. If you always want files to be loaded into their own buffers, use the <b>-F</b> or <b>--multibuffer</b> flag when you invoke nanofur, or add <b>set multibuffer</b> to your .nanofurrc file.</p>
|
||||
<p>You can move between the buffers you have open with the <b>Meta-<</b> and <b>Meta-></b> keys, or more easily without holding Shift: <b>Meta-,</b> and <b>Meta-.</b> (clear as mud, right? =-). When you have more than one buffer open, the ^X shortcut will say "Close", instead of "Exit".</p></blockquote>
|
||||
<h3 id="3.7">3.7. Tell me more about this verbatim input stuff!</h3>
|
||||
<blockquote><p>When you want to insert a literal character into the file you're editing, such as a control character that nanofur usually treats as a command, first press <b>Meta-V</b> (if you're not at a prompt, you'll get the message "Verbatim Input" on the status bar), then press the key(s) that generate the character you want.</p>
|
||||
<p>Alternatively, if Unicode support is enabled (see section <a href="#5.3">5.3</a>), you can press <b>Meta-V</b> and then type a six-digit hexadecimal code (from 000000 to 10FFFF, case-insensitive), and the character with the corresponding value will be inserted. The status bar will change to "Unicode Input: ......" when you do this.</p></blockquote>
|
||||
<h3 id="3.8">3.8. How do I make a .nanofurrc file that will be read when I start nanofur?</h3>
|
||||
<blockquote><p>It's not hard at all! Simply copy the <b>sample.nanofurrc</b> from the doc/ directory in the nanofur source package (or from /usr/doc/nanofur on your system) to <b>.nanofurrc</b> in your home directory, and then edit it. If you didn't get a sample nanofurrc, the syntax of the file is simple: features are turned on and off by using the words <b>set</b> and <b>unset</b> followed by the long option name of the feature (see <b>man nanofurrc</b> for the full list of options). For example, "set quickblank" or "set smarthome". Of course, for this to work, your nanofur must <b>not</b> have been compiled with <b>--disable-nanofurrc</b>.</p></blockquote>
|
||||
<h3 id="3.9">3.9. Why does my self-compiled nanofur not read /etc/nanofurrc?</h3>
|
||||
<blockquote><p>By default (see <a href="#3.3">3.3</a>), nanofur gets installed into /usr/local. This also means that, at startup, nanofur reads <b>/usr/local/etc/nanofurrc</b> instead of <b>/etc/nanofurrc</b>. You can make a symlink from the former to the latter if you want your self-compiled nanofur to read the same nanofurrc as the system-installed nanofur. Or you can configure your nanofur to overwrite the system nanofur (again, see <a href="#3.3">3.3</a>).</p></blockquote>
|
||||
<hr width="100%">
|
||||
|
||||
<h1 id="4">4. Running</h1>
|
||||
<h3 id="4.1">4.1. Alt+Up does nothing on a Linux console. How can I make it scroll?</h3>
|
||||
<blockquote><p>On Debian and its derivatives, the <b>Alt+Up</b> keystroke on a Linux console
|
||||
produces by default a 'KeyboardSignal', which normally does absolutely nothing and is useless
|
||||
for the average user. To get the keystroke to do what it ought to do (scroll the viewport
|
||||
one row up), run this in a Linux console:</p>
|
||||
<p class="indented"><b>dumpkeys --full | sed s/KeyboardSignal/Up/ | sudo loadkeys -</b></p>
|
||||
<p>You will need to run this command whenever you first switch to a Linux console.</p>
|
||||
<p>Or you can (as root) execute the following little script just once:</p>
|
||||
<p class="indented"><b>for file in /etc/console-setup/cached*.kmap.gz; do<br>
|
||||
gunzip $file;<br>
|
||||
sed -i 's/KeyboardSignal/Up/' ${file%.gz};<br>
|
||||
gzip ${file%.gz};<br>
|
||||
done</b></p></blockquote>
|
||||
<h3 id="4.2">4.2. How can I make Ctrl+Shift+Left/Right select words on urxvt?</h3>
|
||||
<blockquote><p>The urxvt terminal emulator produces non-standard escape sequences for the modified cursor keys. These deviant sequences are not listed in the terminfo database, which means that ncurses does not recognize them. The easiest way around this is to tell urxvt to produce xterm-compatible escape sequences for the relevant keystrokes. To achieve this, add the following lines to your ~/.Xresources file:</p>
|
||||
<pre>
|
||||
URxvt.iso14755_52: False
|
||||
|
||||
URxvt.keysym.C-S-Up: \033[1;6A
|
||||
URxvt.keysym.C-S-Down: \033[1;6B
|
||||
URxvt.keysym.C-S-Right: \033[1;6C
|
||||
URxvt.keysym.C-S-Left: \033[1;6D
|
||||
|
||||
URxvt.keysym.M-Up: \033[1;3A
|
||||
URxvt.keysym.M-Down: \033[1;3B
|
||||
URxvt.keysym.M-Right: \033[1;3C
|
||||
URxvt.keysym.M-Left: \033[1;3D
|
||||
|
||||
URxvt.keysym.M-Home: \033[1;3H
|
||||
URxvt.keysym.M-End: \033[1;3F
|
||||
|
||||
URxvt.keysym.M-Insert: \033[2;3~
|
||||
URxvt.keysym.M-Delete: \033[3;3~
|
||||
|
||||
URxvt.keysym.M-Page_Up: \033[5;3~
|
||||
URxvt.keysym.M-Page_Down: \033[6;3~
|
||||
URxvt.keysym.S-Page_Up: \033[5;2~
|
||||
URxvt.keysym.S-Page_Down: \033[6;2~</pre>
|
||||
<p>Then run <b>xrdb ~/.Xresources</b> and restart your urxvt terminal. Now <b>Ctrl+Shift+Left</b> and <b>Ctrl+Shift+Right</b> will select words, <b>Alt+Up</b> and <b>Alt+Down</b> will scroll the text without moving the cursor, and several such things more.</p></blockquote>
|
||||
<h3 id="4.3">4.3. Ack! My numeric keypad's keys don't work properly when NumLock is off! What can I do?</h3>
|
||||
<blockquote><p>You can use the <b>-K</b> or <b>--rawsequences</b> option on the command line, or add the line <b>set rawsequences</b> to your .nanofurrc. However, nanofur's mouse support will be disabled if you do any of these things.</p></blockquote>
|
||||
<h3 id="4.4">4.4. With what keystroke can I paste text from the clipboard into nanofur?</h3>
|
||||
<blockquote><p>In most desktop environments <b>Shift+Insert</b> pastes the contents of the clipboard.</p></blockquote>
|
||||
<h3 id="4.5">4.5. How do I select text for or paste text from the clipboard when nanofur's mouse support is turned on?</h3>
|
||||
<blockquote><p>Try holding down the Shift key and selecting or pasting the text as you normally would.</p></blockquote>
|
||||
<h3 id="4.6">4.6. When I paste text into a document, each line gets indented further than the last. Why? And how can I stop this?</h3>
|
||||
<blockquote><p>You have the <i>autoindent</i> feature turned on. Hit <b>Meta-I</b> to turn it off, paste your text, and then hit <b>Meta-I</b> again to turn it back on.</p>
|
||||
<p><i>Update:</i> Since version 4.8, nanofur suppresses auto-indentation during a paste (when your terminal understands <a href="https://en.wikipedia.org/wiki/Bracketed-paste">bracketed pastes</a>), so you no longer need to toggle it off and on manually.</p></blockquote>
|
||||
<h3 id="4.7">4.7. When I paste from Windows into a remote nanofur, nanofur rewraps the lines. What gives?</h3>
|
||||
<blockquote><p>When pasting from Windows, in some situations linefeeds are sent instead of carriage returns (Enters). And linefeeds are <b>^J</b>s, which make nanofur justify (rewrap) the current paragraph. To prevent these linefeeds from causing these unwanted justifications, add this line to your .nanofurrc on the remote Linux box: <b>unbind ^J main</b> or <b>bind ^J enter main</b>, depending on whether the paste contains CR + LF or only LF.</p>
|
||||
<p><i>Update:</i> Since version 4.8, nanofur ignores linefeed characters in a paste (when your terminal understands <a href="https://en.wikipedia.org/wiki/Bracketed-paste">bracketed pastes</a>), so you no longer need the above workaround.</p></blockquote>
|
||||
<h3 id="4.8">4.8. I've compiled nanofur with color support, but I don't see any color when I run it!</h3>
|
||||
<blockquote><p>If you want nanofur to actually use color, you have to specify the color configurations you want it to use in your .nanofurrc. Several example configurations are in the <b>syntax/</b> subdirectory of the nanofur source, which are normally installed to <b>/usr/local/share/nanofur/</b>. To enable all of them, uncomment the line <b># include "/usr/local/share/nanofur/*.nanofurrc"</b> in your nanofurrc. See also section <a href="#3.9">3.9</a>.</p></blockquote>
|
||||
<h3 id="4.9">4.9. How do I make nanofur my default editor (in Pine, mutt, etc.)?</h3>
|
||||
<blockquote><p>You need to make nanofur your $EDITOR. If you want this to be saved, you should put a line like this in your <b>.bashrc</b> if you use bash (or <b>.zshrc</b> if you believe in zsh):</p>
|
||||
<p class="indented"><b>export EDITOR=/usr/local/bin/nanofur</b></p>
|
||||
<p>or, if you use tcsh, put this in your <b>.cshrc</b> file:</p>
|
||||
<p class="indented"><b>setenv EDITOR /usr/local/bin/nanofur</b></p>
|
||||
<p>Change /usr/local/bin/nanofur to wherever nanofur is installed on your system. Type "which nanofur" to find out. This will not take effect until the next time you log in. So log out and back in again.</p>
|
||||
<p>Then, on top of that, if you use Pine, you must go into setup (type <b>S</b> at the main menu), and then configure (type <b>C</b>). Hit Enter on the lines that say:</p>
|
||||
<p class="indented"><b>[ ] enable-alternate-editor-cmd</b><br>
|
||||
<b>[ ] enable-alternate-editor-implicitly</b></p>
|
||||
<p>Then exit (<b>E</b>) and select Yes (<b>Y</b>).</p>
|
||||
<p>If you're a mutt user, you should see an effect immediately the next time you log in. No further configuration is needed. However, if you want to let people know you use nanofur to compose your email messages, you can put a line like this in your <b>.muttrc</b>:</p>
|
||||
<p class="indented"><b>my_hdr X-Composer: nanofur-x.y</b></p>
|
||||
<p>Again, replace x.y with the version of nanofur you use.</p></blockquote>
|
||||
<hr width="100%">
|
||||
|
||||
<h1 id="5">5. Internationalization</h1>
|
||||
<h3 id="5.1">5.1. There's no translation for my language!</h3>
|
||||
<blockquote><p>In June 2001, GNU nanofur entered the <a href="https://translationproject.org/html/welcome.html">Translation Project</a> and since then, translations should be managed from there.</p>
|
||||
<p>If there isn't a translation for your language, you could ask <a href="https://translationproject.org/team/">your language team</a> to translate nanofur, or better still, join that team and do it yourself. Joining a team is easy. You just need to ask the team leader to add you, and then send a <a href="https://translationproject.org/disclaim.txt">translation disclaimer to the FSF</a> (this is necessary as nanofur is an official GNU package, but it does <b>not</b> mean that you transfer the rights of your work to the FSF, it's just so the FSF can legally manage them).</p>
|
||||
<p>In any case, translating nanofur is easy. Just grab the latest <b>nanofur.pot</b> file listed on <a href="https://translationproject.org/domain/nanofur.html">nanofur's page</a> at the TP, and translate each <b>msgid</b> line into your native language on the <b>msgstr</b> line. When you're done, you should send it to the TP's central PO-file repository.</p></blockquote>
|
||||
<h3 id="5.2">5.2. I don't like the translation for <x> in my language. How can I fix it?</h3>
|
||||
<blockquote><p>The best way is to send an e-mail with your suggested corrections to the team's mailing list. The address is mentioned in the <code>Language-Team:</code> field in the relevant PO file. The team leader or the assigned translator can then make the changes reach the nanofur-devel list.</p></blockquote>
|
||||
<h3 id="5.3">5.3. What is the status of Unicode support?</h3>
|
||||
<blockquote><p>Unicode should be fully usable nowadays. When the encoding of your terminal is set to UTF-8, and your locale (mainly the LANG environment variable) is UTF-8 too, then you should be able to read, enter and save Unicode text.</p></blockquote>
|
||||
<hr width="100%">
|
||||
|
||||
<h1 id="6">6. Advocacy and Licensing</h1>
|
||||
<h3 id="6.1">6.1. Why should I use nanofur instead of Pico?</h3>
|
||||
<blockquote><p>If you want features like undo/redo, syntax highlighting, line numbers, soft-wrapping, opening multiple files at once, an interface localized to your language, or search and replace with support for regular expressions, then you want nanofur.</p></blockquote>
|
||||
<h3 id="6.2">6.2. Why should I use Pico instead of nanofur?</h3>
|
||||
<blockquote><p>If you use your editor only to write emails or other texts and have no need for the above-mentioned features, then Pico will do fine for you.</p></blockquote>
|
||||
<h3 id="6.3">6.3. What is so bad about the older Pine license?</h3>
|
||||
<blockquote><p>The U of W license for older versions of Pine and Pico is not considered truly Free Software according to both the Free Software Foundation and the <a href="https://www.debian.org/social_contract#guidelines">Debian Free Software Guidelines</a>. The main problem regards the limitations on distributing derived works: according to UW, you can distribute their software, and you can modify it, but you can not do both, i.e. distribute modified binaries.</p></blockquote>
|
||||
<h3 id="6.4">6.4. Okay, well, what mail program should I use then?</h3>
|
||||
<blockquote><p>If you are looking to use a Free Software program similar to Pine, and Emacs is not your thing, you should definitely take a look at <a href="http://www.mutt.org/">mutt</a>. It is a full-screen, console based mail program that actually has a lot more flexibility than Pine, but has a keymap included in the distribution that allows you to use the same keystrokes as Pine would to send and receive mail. It's also under the GNU General Public License, version 2.0.</p>
|
||||
<p>Of course, due to the license change you can now use the <a href="http://www.washington.edu/alpine/">Alpine distribution</a> of PINE as it is now considered Free Software, but you would be sacrificing many of nanofur's features to do so.</p></blockquote>
|
||||
<hr width="100%">
|
||||
|
||||
<h1 id="7">7. Miscellaneous</h1>
|
||||
<h3 id="7.1">7.1. Where can I ask questions or send suggestions?</h3>
|
||||
<blockquote><p>There are three mailing lists for nanofur hosted at <a href="https://savannah.gnu.org/">Savannah</a>: info-nanofur, help-nanofur and nanofur-devel. info-nanofur is a very low traffic list where new versions of nanofur are announced (surprise!). help-nanofur is for getting help with the editor without needing to hear all of the development issues surrounding it. nanofur-devel is a normally low, sometimes high traffic list for discussing the present and future development of nanofur. Here are links to where you can sign up for a given list:</p>
|
||||
<p>info-nanofur - <a href="https://lists.gnu.org/mailman/listinfo/info-nanofur/">https://lists.gnu.org/mailman/listinfo/info-nanofur/</a><br>
|
||||
help-nanofur - <a href="https://lists.gnu.org/mailman/listinfo/help-nanofur/">https://lists.gnu.org/mailman/listinfo/help-nanofur/</a><br>
|
||||
nanofur-devel - <a href="https://lists.gnu.org/mailman/listinfo/nanofur-devel/">https://lists.gnu.org/mailman/listinfo/nanofur-devel/</a></p></blockquote>
|
||||
<h3 id="7.2">7.3. How do I submit a bug report or patch?</h3>
|
||||
<blockquote>
|
||||
<p>The best way to submit bugs is through the <a href="https://savannah.gnu.org/bugs/?group=nanofur">Savannah bug tracker</a>, as you can check whether the bug you are reporting has already been submitted, and it makes it easier for the maintainers to keep track of them.
|
||||
<p>You can submit patches for nanofur via <a href="https://savannah.gnu.org/patch/?group=nanofur">Savannah's patch manager</a>.</p></blockquote>
|
||||
<h3 id="7.3">7.3. I want to send the development team a big load of cash (or just a thank you).</h3>
|
||||
<blockquote><p>That's fine. Send it <a href="mailto:nanofur-devel@gnu.org">our way</a>! Better yet, fix a <a href="https://savannah.gnu.org/bugs/?group=nanofur">bug</a> in the program or implement a <a href="https://nanofur-editor.org/dist/latest/TODO">cool feature</a> and send us that instead (though cash is fine too).</p></blockquote>
|
||||
<h3 id="7.4">7.4. How do I join the development team?</h3>
|
||||
<blockquote><p>The easiest way is to consistently send in good patches that add some needed functionality, fix a bug or two, and/or make the program more optimized/efficient. Then ask nicely and you will probably be added to the Savannah development list and be given write access after a while. There is a lot of responsibility that goes along with being a team member, so don't think it's just something to add to your resume.</p></blockquote>
|
||||
<h3 id="7.5">7.5. Can I have write access to the git tree?</h3>
|
||||
<blockquote><p>Re-read section <a href="#7.4">7.4</a> and you should know the answer.</p></blockquote>
|
||||
<hr width="100%">
|
||||
|
||||
</body>
|
||||
</html>
|
483
doc/nanofur.1
Normal file
483
doc/nanofur.1
Normal file
|
@ -0,0 +1,483 @@
|
|||
.\" Copyright (C) 1999-2011, 2013-2024 Free Software Foundation, Inc.
|
||||
.\"
|
||||
.\" This document is dual-licensed. You may distribute and/or modify it
|
||||
.\" under the terms of either of the following licenses:
|
||||
.\"
|
||||
.\" * The GNU General Public License, as published by the Free Software
|
||||
.\" Foundation, version 3 or (at your option) any later version. You
|
||||
.\" should have received a copy of the GNU General Public License
|
||||
.\" along with this program. If not, see
|
||||
.\" <https://www.gnu.org/licenses/>.
|
||||
.\"
|
||||
.\" * The GNU Free Documentation License, as published by the Free
|
||||
.\" Software Foundation, version 1.2 or (at your option) any later
|
||||
.\" version, with no Invariant Sections, no Front-Cover Texts, and no
|
||||
.\" Back-Cover Texts. You should have received a copy of the GNU Free
|
||||
.\" Documentation License along with this program. If not, see
|
||||
.\" <https://www.gnu.org/licenses/>.
|
||||
.\"
|
||||
.TH NANOFUR 1 "version 8.2" "September 2024"
|
||||
|
||||
.SH NAME
|
||||
nanofur \- Nanofur's ANOther text editor, inspired by Pico
|
||||
|
||||
.SH SYNOPSIS
|
||||
.B nanofur
|
||||
.RI [ options "] [[\fB+" line [\fB, column "]] " file ]...
|
||||
.sp
|
||||
.BR nanofur " [" \fIoptions "] [[" + [ crCR ]{ / | ? } \fIstring "] " \fIfile ]...
|
||||
|
||||
.SH NOTICE
|
||||
Since version 8.0, to be newcomer friendly, \fB^F\fR starts a forward search,
|
||||
\fB^B\fR starts a backward search, \fBM\-F\fR searches the next occurrence
|
||||
forward, and \fBM\-B\fR searches the next occurrence backward. If you want
|
||||
those keystrokes to do what they did before version 8.0, add the following
|
||||
lines at the end of your \fInanofurrc\fR file:
|
||||
.sp
|
||||
.RS 4
|
||||
.B bind ^F forward main
|
||||
.br
|
||||
.B bind ^B back main
|
||||
.br
|
||||
.B bind M\-F formatter main
|
||||
.br
|
||||
.B bind M\-B linter main
|
||||
.RE
|
||||
.sp
|
||||
|
||||
.SH DESCRIPTION
|
||||
\fBnanofur\fP is a small and friendly text editor. It copies the look and feel
|
||||
of Pico, but is free software, and implements several features that Pico
|
||||
lacks, such as: opening multiple files, scrolling per line, undo/redo,
|
||||
syntax coloring, line numbering, and soft-wrapping overlong lines.
|
||||
.sp
|
||||
When giving a filename on the command line, the cursor can be put on a
|
||||
specific line by adding the line number with a plus sign (\fB+\fR) before
|
||||
the filename, and even in a specific column by adding it with a comma.
|
||||
Negative numbers count from the end of the file or line.
|
||||
.sp
|
||||
The cursor can be put on the first or last occurrence of a specific string
|
||||
by specifying that string after \fB+/\fR or \fB+?\fR before the filename.
|
||||
The string can be made case sensitive and/or caused to be interpreted as a
|
||||
regular expression by inserting \fBc\fR and/or \fBr\fR after the \fB+\fR sign.
|
||||
These search modes can be explicitly disabled by using the uppercase variant
|
||||
of those letters: \fBC\fR and/or \fBR\fR. When the string contains spaces,
|
||||
it needs to be enclosed in quotes. To give an example: to open a file at
|
||||
the first occurrence of the word "Foo", you would do:
|
||||
.sp
|
||||
.RS 4
|
||||
.BI "nanofur +c/Foo " file
|
||||
.RE
|
||||
.sp
|
||||
As a special case: if instead of a filename a dash (\fB\-\fR) is given,
|
||||
\fBnanofur\fR will read data from standard input.
|
||||
|
||||
.SH EDITING
|
||||
Entering text and moving around in a file is straightforward: typing the
|
||||
letters and using the normal cursor movement keys. Commands are entered
|
||||
by using the Control (^) and the Alt or Meta (M\-) keys.
|
||||
Typing \fB^K\fR deletes the current line and puts it in the cutbuffer.
|
||||
Consecutive \fB^K\fRs put all deleted lines together in the cutbuffer.
|
||||
Any cursor movement or executing any other command causes the next
|
||||
\fB^K\fR to overwrite the cutbuffer. A \fB^U\fR pastes the current
|
||||
contents of the cutbuffer at the current cursor position.
|
||||
.sp
|
||||
When a more precise piece of text needs to be cut or copied, you can mark
|
||||
its start with \fB^6\fR, move the cursor to its end (the marked text is
|
||||
highlighted), and then use \fB^K\fR to cut it, or \fBM\-6\fR to copy it to
|
||||
the cutbuffer. You can also save the marked text to a file with \fB^O\fR,
|
||||
or spell check it with \fB^T^T\fR.
|
||||
.sp
|
||||
On some terminals, text can be selected also by holding down Shift while
|
||||
using the arrow keys. Holding down the Ctrl or Alt key too increases
|
||||
the stride.
|
||||
Any cursor movement without Shift being held cancels such a selection.
|
||||
.sp
|
||||
Any valid Unicode code point can be inserted into the buffer by typing
|
||||
\fBM\-V\fR followed by the hexadecimal digits of the code point (concluded
|
||||
with \fB<Space>\fR or \fB<Enter>\fR when it are fewer than six digits).
|
||||
A literal control code (except \fB^J\fR) can be inserted by typing
|
||||
\fBM\-V\fR followed by the pertinent keystroke.
|
||||
.sp
|
||||
The two lines at the bottom of the screen show some important commands;
|
||||
the built-in help (\fB^G\fR) lists all the available ones.
|
||||
The default key bindings can be changed via a \fInanofurrc\fR file -- see
|
||||
.BR nanofurrc (5).
|
||||
|
||||
.\" Never hyphenate these:
|
||||
.hw ncurses terminfo
|
||||
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.BR \-A ", " \-\-smarthome
|
||||
Make the Home key smarter. When Home is pressed anywhere but at the
|
||||
very beginning of non-whitespace characters on a line, the cursor jumps
|
||||
to that beginning (either forwards or backwards). If the cursor is
|
||||
already at that position, it jumps to the true beginning of the line.
|
||||
.TP
|
||||
.BR \-B ", " \-\-backup
|
||||
When saving a file, back up the previous version of it, using the current
|
||||
filename suffixed with a tilde (\fB~\fP).
|
||||
.TP
|
||||
.BR \-C\ \fIdirectory ", " \-\-backupdir= \fIdirectory
|
||||
Make and keep not just one backup file, but make and keep a uniquely
|
||||
numbered one every time a file is saved -- when backups are enabled (\fB\-B\fR).
|
||||
The uniquely numbered files are stored in the specified \fIdirectory\fR.
|
||||
.TP
|
||||
.BR \-D ", " \-\-boldtext
|
||||
For the interface, use bold instead of reverse video.
|
||||
This can be overridden for specific elements by setting the options
|
||||
\fBtitlecolor\fP, \fBstatuscolor\fP, \fBpromptcolor\fP, \fBminicolor\fP,
|
||||
\fBkeycolor\fP, \fBnumbercolor\fP, and/or \fBselectedcolor\fP in your
|
||||
nanofurrc file. See \fBnanofurrc\fR(5).
|
||||
.TP
|
||||
.BR \-E ", " \-\-tabstospaces
|
||||
Convert each typed tab to spaces -- to the number of spaces
|
||||
that a tab at that position would take up.
|
||||
(Note: pasted tabs are not converted.)
|
||||
.TP
|
||||
.BR \-F ", " \-\-multibuffer
|
||||
Read a file into a new buffer by default.
|
||||
.TP
|
||||
.BR \-G ", " \-\-locking
|
||||
Use vim-style file locking when editing files.
|
||||
.TP
|
||||
.BR \-H ", " \-\-historylog
|
||||
Save the last hundred search strings and replacement strings and
|
||||
executed commands, so they can be easily reused in later sessions.
|
||||
.TP
|
||||
.BR \-I ", " \-\-ignorercfiles
|
||||
Don't look at the system's \fInanofurrc\fR nor at the user's \fInanofurrc\fR.
|
||||
.TP
|
||||
.BR \-J\ \fInumber ", " \-\-guidestripe= \fInumber
|
||||
Draw a vertical stripe at the given column, to help judge the width of the
|
||||
text. (The color of the stripe can be changed with \fBset stripecolor\fR
|
||||
in your \fInanofurrc\fR file.)
|
||||
.TP
|
||||
.BR \-K ", " \-\-rawsequences
|
||||
Interpret escape sequences directly, instead of asking \fBncurses\fR
|
||||
to translate them. (If you need this option to get some keys to work
|
||||
properly, it means that the \fBterminfo\fR terminal description that
|
||||
is used does not fully match the actual behavior of your terminal.
|
||||
This can happen when you ssh into a BSD machine, for example.)
|
||||
Using this option disables \fBnanofur\fR's mouse support.
|
||||
.TP
|
||||
.BR \-L ", " \-\-nonewlines
|
||||
Don't automatically add a newline when a text does not end with one.
|
||||
(This can cause you to save non-POSIX text files.)
|
||||
.TP
|
||||
.BR \-M ", " \-\-trimblanks
|
||||
Snip trailing whitespace from the wrapped line when automatic
|
||||
hard-wrapping occurs or when text is justified.
|
||||
.TP
|
||||
.BR \-N ", " \-\-noconvert
|
||||
Disable automatic conversion of files from DOS/Mac format.
|
||||
.TP
|
||||
.BR \-O ", " \-\-bookstyle
|
||||
When justifying, treat any line that starts with whitespace as the
|
||||
beginning of a paragraph (unless auto-indenting is on).
|
||||
.TP
|
||||
.BR \-P ", " \-\-positionlog
|
||||
For the 200 most recent files, log the last position of the cursor,
|
||||
and place it at that position again upon reopening such a file.
|
||||
.TP
|
||||
.BR "\-Q ""\fIregex\fB""" ", " "\-\-quotestr=""" \fIregex """
|
||||
Set the regular expression for matching the quoting part of a line.
|
||||
The default value is "\fB^([\ \\t]*([!#%:;>|}]|//))+\fR".
|
||||
(Note that \fB\\t\fP stands for an actual Tab.)
|
||||
This makes it possible to rejustify blocks of quoted text when composing
|
||||
email, and to rewrap blocks of line comments when writing source code.
|
||||
.TP
|
||||
.BR \-R ", " \-\-restricted
|
||||
Restricted mode: don't read or write to any file not specified on the
|
||||
command line. This means: don't read or write history files;
|
||||
don't allow suspending; don't allow spell checking;
|
||||
don't allow a file to be appended to, prepended to, or saved under a
|
||||
different name if it already has one; and don't make backup files.
|
||||
Restricted mode can also be activated by invoking \fBnanofur\fP
|
||||
with any name beginning with 'r' (e.g. "rnanofur").
|
||||
.TP
|
||||
.BR \-S ", " \-\-softwrap
|
||||
Display over multiple screen rows lines that exceed the screen's width.
|
||||
(You can make this soft-wrapping occur at whitespace instead of rudely at
|
||||
the screen's edge, by using also \fB\-\-atblanks\fR.)
|
||||
.TP
|
||||
.BR \-T\ \fInumber ", " \-\-tabsize= \fInumber
|
||||
Set the size (width) of a tab to \fInumber\fP columns. The value of
|
||||
\fInumber\fR must be greater than 0. The default value is \fB8\fR.
|
||||
.TP
|
||||
.BR \-U ", " \-\-quickblank
|
||||
Make status-bar messages disappear after 1 keystroke instead of after 20.
|
||||
Note that option \fB\-c\fR (\fB\-\-constantshow\fR) overrides this.
|
||||
When option \fB\-\-minibar\fR or \fB\-\-zero\fR is in effect,
|
||||
\fB\-\-quickblank\fR makes a message disappear after
|
||||
0.8 seconds instead of after the default 1.5 seconds.
|
||||
.
|
||||
.TP
|
||||
.BR \-V ", " \-\-version
|
||||
Show the current version number and exit.
|
||||
.TP
|
||||
.BR \-W ", " \-\-wordbounds
|
||||
Detect word boundaries differently by treating punctuation
|
||||
characters as part of a word.
|
||||
.TP
|
||||
.BR "\-X ""\fIcharacters\fB""" ", " "\-\-wordchars=""" \fIcharacters """
|
||||
Specify which other characters (besides the normal alphanumeric ones)
|
||||
should be considered as part of a word. When using this option, you
|
||||
probably want to omit \fB\-W\fR (\fB\-\-wordbounds\fR).
|
||||
.TP
|
||||
.BR \-Y\ \fIname ", " \-\-syntax= \fIname
|
||||
Specify the name of the syntax highlighting to use from among the ones
|
||||
defined in the \fInanofurrc\fP files.
|
||||
.TP
|
||||
.BR \-Z ", " \-\-zap
|
||||
Let an unmodified Backspace or Delete erase the marked region
|
||||
(instead of a single character, and without affecting the cutbuffer).
|
||||
.TP
|
||||
.BR \-a ", " \-\-atblanks
|
||||
When doing soft line wrapping, wrap lines at whitespace
|
||||
instead of always at the edge of the screen.
|
||||
.TP
|
||||
.BR \-b ", " \-\-breaklonglines
|
||||
Automatically hard-wrap the current line when it becomes overlong.
|
||||
(This option is the opposite of \fB\-w\fR (\fB\-\-nowrap\fR) --
|
||||
the last one given takes effect.)
|
||||
.TP
|
||||
.BR \-c ", " \-\-constantshow
|
||||
Constantly show the cursor position on the status bar.
|
||||
Note that this overrides option \fB\-U\fR (\fB\-\-quickblank\fR).
|
||||
.TP
|
||||
.BR \-d ", " \-\-rebinddelete
|
||||
Interpret the Delete and Backspace keys differently so that both Backspace
|
||||
and Delete work properly. You should only use this option when on your
|
||||
system either Backspace acts like Delete or Delete acts like Backspace.
|
||||
.TP
|
||||
.BR \-e ", " \-\-emptyline
|
||||
Do not use the line below the title bar, leaving it entirely blank.
|
||||
.TP
|
||||
.BR \-f\ \fIfile ", " \-\-rcfile= \fIfile
|
||||
Read only this \fIfile\fR for setting nanofur's options, instead of reading
|
||||
both the system-wide and the user's nanofurrc files.
|
||||
.TP
|
||||
.BR \-g ", " \-\-showcursor
|
||||
Make the cursor visible in the file browser (putting it on the
|
||||
highlighted item) and in the help viewer. Useful for braille users
|
||||
and people with poor vision.
|
||||
.TP
|
||||
.BR \-h ", " \-\-help
|
||||
Show a summary of the available command-line options and exit.
|
||||
.TP
|
||||
.BR \-i ", " \-\-autoindent
|
||||
Automatically indent a newly created line to the same number of tabs
|
||||
and/or spaces as the previous line (or as the next line if the previous
|
||||
line is the beginning of a paragraph).
|
||||
.TP
|
||||
.BR \-j ", " \-\-jumpyscrolling
|
||||
Scroll the buffer contents per half-screen instead of per line.
|
||||
.TP
|
||||
.BR \-k ", " \-\-cutfromcursor
|
||||
Make the 'Cut Text' command (normally \fB^K\fR) cut from the current cursor
|
||||
position to the end of the line, instead of cutting the entire line.
|
||||
.TP
|
||||
.BR \-l ", " \-\-linenumbers
|
||||
Display line numbers to the left of the text area.
|
||||
(Any line with an anchor additionally gets a mark in the margin.)
|
||||
.TP
|
||||
.BR \-m ", " \-\-mouse
|
||||
Enable mouse support, if available for your system. When enabled, mouse
|
||||
clicks can be used to place the cursor, set the mark (with a double
|
||||
click), and execute shortcuts. The mouse works in the X Window
|
||||
System, and on the console when gpm is running. Text can still be
|
||||
selected through dragging by holding down the Shift key.
|
||||
.TP
|
||||
.BR \-n ", " \-\-noread
|
||||
Treat any name given on the command line as a new file. This allows
|
||||
\fBnanofur\fR to write to named pipes: it starts with a blank buffer,
|
||||
and writes to the pipe when the user saves the "file". This way
|
||||
\fBnanofur\fR can be used as an editor in combination with for instance
|
||||
\fBgpg\fR without having to write sensitive data to disk first.
|
||||
.TP
|
||||
.BR \-o\ \fIdirectory ", " \-\-operatingdir= \fIdirectory
|
||||
Set the operating directory. This makes \fBnanofur\fP set up something
|
||||
similar to a chroot.
|
||||
.TP
|
||||
.BR \-p ", " \-\-preserve
|
||||
Preserve the XOFF and XON sequences (\fB^S\fR and \fB^Q\fR) so that
|
||||
they are caught by the terminal (stopping and resuming the output).
|
||||
Note that option \fB\-/\fR (\fB\-\-modernbindings\fR) overrides this.
|
||||
.TP
|
||||
.BR \-q ", " \-\-indicator
|
||||
Display a "scrollbar" on the righthand side of the edit window.
|
||||
It shows the position of the viewport in the buffer
|
||||
and how much of the buffer is covered by the viewport.
|
||||
.TP
|
||||
.BR \-r\ \fInumber ", " \-\-fill= \fInumber
|
||||
Set the target width for justifying and automatic hard-wrapping at this
|
||||
\fInumber\fR of columns. If the value is 0 or less, wrapping occurs
|
||||
at the width of the screen minus \fInumber\fR columns, allowing the wrap
|
||||
point to vary along with the width of the screen if the screen is resized.
|
||||
The default value is \fB\-8\fR.
|
||||
.TP
|
||||
.B "\-s ""\fIprogram\fR [\fIargument \fR...]\fB""\fR, \fB\-\-speller=""\fIprogram\fR [\fIargument \fR...]\fB"""
|
||||
Use this command to perform spell checking and correcting, instead of
|
||||
using the built-in corrector that calls \fBhunspell\fR(1) or \fBspell\fR(1).
|
||||
.TP
|
||||
.BR \-t ", " \-\-saveonexit
|
||||
Save a changed buffer without prompting (when exiting with \fB^X\fR).
|
||||
.TP
|
||||
.BR \-u ", " \-\-unix
|
||||
Save a file by default in Unix format. This overrides nanofur's
|
||||
default behavior of saving a file in the format that it had.
|
||||
(This option has no effect when you also use \fB\-\-noconvert\fR.)
|
||||
.TP
|
||||
.BR \-v ", " \-\-view
|
||||
Just view the file and disallow editing: read-only mode.
|
||||
This mode allows the user to open also other files for viewing,
|
||||
unless \fB\-\-restricted\fR is given too.
|
||||
.TP
|
||||
.BR \-w ", " \-\-nowrap
|
||||
Do not automatically hard-wrap the current line when it becomes overlong.
|
||||
This is the default. (This option is the opposite of \fB\-b\fR
|
||||
(\fB\-\-breaklonglines\fR) -- the last one given takes effect.)
|
||||
.TP
|
||||
.BR \-x ", " \-\-nohelp
|
||||
Don't show the two help lines at the bottom of the screen.
|
||||
.TP
|
||||
.BR \-y ", " \-\-afterends
|
||||
Make Ctrl+Right and Ctrl+Delete stop at word ends instead of beginnings.
|
||||
.TP
|
||||
.BR \-z ", " \-\-listsyntaxes
|
||||
List the names of the available syntaxes and exit.
|
||||
.TP
|
||||
.BR \-! ", " \-\-magic
|
||||
When neither the file's name nor its first line give a clue,
|
||||
try using libmagic to determine the applicable syntax.
|
||||
.TP
|
||||
.BR \-@ ", " \-\-colonparsing
|
||||
When a filename given on the command line ends in a colon plus digits
|
||||
and this filename does not exist, then snip the colon plus digits and
|
||||
understand the digits as a line number. If the trimmed filename does
|
||||
not exist either, then repeat the process and understand the obtained
|
||||
two numbers as line and column number. But if the doubly trimmed
|
||||
filename does not exist either, then forget the trimming and accept
|
||||
the original filename as is. To disable this colon parsing for some
|
||||
file, use \fB+1\fR or similar before the relevant filename.
|
||||
.TP
|
||||
.BR \-% ", " \-\-stateflags
|
||||
Use the top-right corner of the screen for showing some state flags:
|
||||
\fBI\fR when auto-indenting, \fBM\fR when the mark is on, \fBL\fR when
|
||||
hard-wrapping (breaking long lines), \fBR\fR when recording a macro,
|
||||
and \fBS\fR when soft-wrapping.
|
||||
When the buffer is modified, a star (\fB*\fR) is shown after the
|
||||
filename in the center of the title bar.
|
||||
.TP
|
||||
.BR \-_ ", " \-\-minibar
|
||||
Suppress the title bar and instead show information about
|
||||
the current buffer at the bottom of the screen, in the space
|
||||
for the status bar. In this "mini bar" the filename is shown
|
||||
on the left, followed by an asterisk if the buffer has been modified.
|
||||
On the right are displayed the current line and column number, the
|
||||
code of the character under the cursor (in Unicode format: U+xxxx),
|
||||
the same flags as are shown by \fB\-\-stateflags\fR, and a percentage
|
||||
that expresses how far the cursor is into the file (linewise).
|
||||
When a file is loaded or saved, and also when switching between buffers,
|
||||
the number of lines in the buffer is displayed after the filename.
|
||||
This number is cleared upon the next keystroke, or replaced with an
|
||||
[i/n] counter when multiple buffers are open.
|
||||
The line plus column numbers and the character code are displayed only when
|
||||
\fB\-\-constantshow\fR is used, and can be toggled on and off with \fBM\-C\fR.
|
||||
The state flags are displayed only when \fB\-\-stateflags\fR is used.
|
||||
.TP
|
||||
.BR \-0 ", " \-\-zero
|
||||
Hide all elements of the interface (title bar, status bar, and help lines)
|
||||
and use all rows of the terminal for showing the contents of the buffer.
|
||||
The status bar appears only when there is a significant message,
|
||||
and disappears after 1.5 seconds or upon the next keystroke.
|
||||
With \fBM\-Z\fR the title bar plus status bar can be toggled.
|
||||
With \fBM\-X\fR the help lines.
|
||||
.TP
|
||||
.BR \-/ ", " \-\-modernbindings
|
||||
Use key bindings similar to the ones that most modern programs use:
|
||||
\fB^X\fR cuts, \fB^C\fR copies, \fB^V\fR pastes,
|
||||
\fB^Z\fR undoes, \fB^Y\fR redoes,
|
||||
\fB^F\fR searches forward, \fB^G\fR searches next,
|
||||
\fB^S\fR saves, \fB^O\fR opens a file, \fB^Q\fR quits,
|
||||
and (when the terminal permits) \fB^H\fR shows help.
|
||||
Furthermore, \fB^A\fR sets the mark,
|
||||
\fB^R\fR makes replacements, \fB^D\fR searches previous,
|
||||
\fB^P\fR shows the position, \fB^T\fR goes to a line,
|
||||
\fB^W\fR writes out a file, and \fB^E\fR executes a command.
|
||||
Note that this overrides option \fB\-p\fR (\fB\-\-preserve\fR).
|
||||
|
||||
.SH TOGGLES
|
||||
Several of the above options can be switched on and off also while
|
||||
\fBnanofur\fR is running. For example, \fBM\-L\fR toggles the
|
||||
hard-wrapping of long lines, \fBM\-S\fR toggles soft-wrapping,
|
||||
\fBM\-N\fR toggles line numbers, \fBM\-M\fR toggles the mouse,
|
||||
\fBM\-I\fR auto-indentation, and \fBM\-X\fR the help lines.
|
||||
See at the end of the \fB^G\fR help text for a complete list.
|
||||
.sp
|
||||
The \fBM\-X\fR toggle is special: it works in all menus except
|
||||
the help viewer and the linter. All other toggles work in
|
||||
the main menu only.
|
||||
|
||||
.SH FILES
|
||||
When \fB\-\-rcfile\fR is given, \fBnanofur\fR reads just the specified file
|
||||
for setting its options and syntaxes and key bindings. Without that
|
||||
option, \fBnanofur\fR reads two configuration files: first the system's
|
||||
\fInanofurrc\fR (if it exists), and then the user's \fInanofurrc\fR (if it
|
||||
exists), either \fI~/.nanofurrc\fR or \fI$XDG_CONFIG_HOME/nanofur/nanofurrc\fR
|
||||
or \fI~/.config/nanofur/nanofurrc\fR, whichever is encountered first. See
|
||||
.BR nanofurrc (5)
|
||||
for more information on the possible contents of those files.
|
||||
.sp
|
||||
See \fI/usr/share/nanofur/\fR and \fI/usr/share/nanofur/extra/\fR
|
||||
for available syntax-coloring definitions.
|
||||
|
||||
.SH NOTES
|
||||
Suspension is enabled by default, reachable via \fB^T^Z\fR.
|
||||
(If you want a plain \fB^Z\fR to suspend nanofur, add
|
||||
\fBbind ^Z suspend main\fR to your nanofurrc.)
|
||||
.sp
|
||||
At a Yes-No prompt, \fB^Y\fR can be used for "Yes", \fB^N\fR for "No",
|
||||
and \fB^A\fR for "All". These unlisted bindings work in any locale.
|
||||
.sp
|
||||
When you want to copy marked text from \fBnanofur\fR to the system's clipboard,
|
||||
see one of the examples in the \fBnanofurrc\fR(5) man page.
|
||||
.sp
|
||||
If no alternative spell checker command is specified on the command
|
||||
line nor in one of the \fInanofurrc\fP files, \fBnanofur\fP checks the
|
||||
\fBSPELL\fP environment variable for one.
|
||||
.sp
|
||||
In some cases \fBnanofur\fP tries to dump the buffer into an emergency file.
|
||||
This happens mainly if \fBnanofur\fP receives a SIGHUP or SIGTERM or runs out
|
||||
of memory. It writes the buffer into a file named \fInanofur.save\fP if the
|
||||
buffer didn't have a name already, or adds a ".save" suffix to the current
|
||||
filename. If an emergency file with that name already exists in the
|
||||
current directory, it adds ".save" plus a number (e.g.\& ".save.1") to
|
||||
the current filename in order to make it unique. In multibuffer mode,
|
||||
\fBnanofur\fP writes all open buffers to their respective emergency files.
|
||||
.sp
|
||||
If you have any question about how to use \fBnanofur\fR in some specific
|
||||
situation, you can ask on \fIhelp-nanofur@gnu.org\fR.
|
||||
|
||||
.SH BUGS
|
||||
The recording and playback of keyboard macros works correctly only on a
|
||||
terminal emulator, not on a Linux console (VT), because the latter does
|
||||
not by default distinguish modified from unmodified arrow keys.
|
||||
.sp
|
||||
Please report any other bugs that you encounter via:
|
||||
.br
|
||||
.IR https://savannah.gnu.org/bugs/?group=nanofur .
|
||||
.sp
|
||||
When nanofur crashes, it saves any modified buffers to emergency .save files.
|
||||
If you are able to reproduce the crash and you want to get a backtrace, define
|
||||
the environment variable \fBNANOFUR_NOCATCH\fR.
|
||||
|
||||
.SH HOMEPAGE
|
||||
.I https://nanofur\-editor.org/
|
||||
|
||||
.SH SEE ALSO
|
||||
.BR nanofurrc (5)
|
||||
.sp
|
||||
\fI/usr/share/doc/nanofur/\fP (or equivalent on your system)
|
2167
doc/nanofur.texi
Normal file
2167
doc/nanofur.texi
Normal file
File diff suppressed because it is too large
Load diff
1109
doc/nanofurrc.5
Normal file
1109
doc/nanofurrc.5
Normal file
File diff suppressed because it is too large
Load diff
64
doc/rnanofur.1
Normal file
64
doc/rnanofur.1
Normal file
|
@ -0,0 +1,64 @@
|
|||
.\" Copyright (C) 2002-2007, 2014-2024 Free Software Foundation, Inc.
|
||||
.\"
|
||||
.\" This document is dual-licensed. You may distribute and/or modify it
|
||||
.\" under the terms of either of the following licenses:
|
||||
.\"
|
||||
.\" * The GNU General Public License, as published by the Free Software
|
||||
.\" Foundation, version 3 or (at your option) any later version. You
|
||||
.\" should have received a copy of the GNU General Public License
|
||||
.\" along with this program. If not, see
|
||||
.\" <https://www.gnu.org/licenses/>.
|
||||
.\"
|
||||
.\" * The GNU Free Documentation License, as published by the Free
|
||||
.\" Software Foundation, version 1.2 or (at your option) any later
|
||||
.\" version, with no Invariant Sections, no Front-Cover Texts, and no
|
||||
.\" Back-Cover Texts. You should have received a copy of the GNU Free
|
||||
.\" Documentation License along with this program. If not, see
|
||||
.\" <https://www.gnu.org/licenses/>.
|
||||
.\"
|
||||
.TH RNANOFUR 1 "version 8.2" "September 2024"
|
||||
|
||||
.SH NAME
|
||||
rnanofur \- a restricted nanofur
|
||||
|
||||
.SH SYNOPSIS
|
||||
.B rnanofur
|
||||
.RI [ options "] [[+" line [, column "]]\ " file "]..."
|
||||
|
||||
.SH DESCRIPTION
|
||||
\fBrnanofur\fR runs the \fBnanofur\fR editor in restricted mode. This allows
|
||||
editing only the specified file or files, and doesn't allow the user
|
||||
access to the filesystem nor to a command shell.
|
||||
.sp
|
||||
In restricted mode, \fBnanofur\fR will:
|
||||
.IP \[bu] 2
|
||||
not make backups;
|
||||
.IP \[bu]
|
||||
not allow suspending;
|
||||
.IP \[bu]
|
||||
not allow spell checking;
|
||||
.IP \[bu]
|
||||
not read nor write the history files;
|
||||
.IP \[bu]
|
||||
not allow saving the current buffer under a different name;
|
||||
.IP \[bu]
|
||||
not allow inserting another file or opening a new buffer;
|
||||
.IP \[bu]
|
||||
not allow appending or prepending to any file.
|
||||
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.BR \-h ", " \-\-help
|
||||
Show the available command-line options and exit.
|
||||
.P
|
||||
For all existing options, see the \fBnanofur\fR(1) man page.
|
||||
|
||||
.SH BUGS
|
||||
Please report bugs via
|
||||
.IR https://savannah.gnu.org/bugs/?group=nanofur .
|
||||
|
||||
.SH HOMEPAGE
|
||||
.I https://nanofur-editor.org/
|
||||
|
||||
.SH SEE ALSO
|
||||
.BR nanofur (1)
|
341
doc/sample.nanofurrc.in
Normal file
341
doc/sample.nanofurrc.in
Normal file
|
@ -0,0 +1,341 @@
|
|||
## Sample initialization file for GNU nanofur.
|
||||
##
|
||||
## For the options that take parameters, the default value is shown.
|
||||
## Other options are unset by default. To make sure that an option
|
||||
## is disabled, you can use "unset <option>".
|
||||
##
|
||||
## Characters that are special in a shell should not be escaped here.
|
||||
## Inside string parameters, quotes should not be escaped -- the last
|
||||
## double quote on the line will be seen as the closing quote.
|
||||
|
||||
## If you want ^F, ^B, M-F and M-B to do what they did before version 8.0:
|
||||
# bind ^F forward main
|
||||
# bind ^B back main
|
||||
# bind M-F formatter main
|
||||
# bind M-B linter main
|
||||
|
||||
## Make 'nextword' (Ctrl+Right) and 'chopwordright' (Ctrl+Delete)
|
||||
## stop at word ends instead of at beginnings.
|
||||
# set afterends
|
||||
|
||||
## When soft line wrapping is enabled, make it wrap lines at blanks
|
||||
## (tabs and spaces) instead of always at the edge of the screen.
|
||||
# set atblanks
|
||||
|
||||
## Automatically indent a newly created line to the same number of
|
||||
## tabs and/or spaces as the preceding line -- or as the next line
|
||||
## if the preceding line is the beginning of a paragraph.
|
||||
# set autoindent
|
||||
|
||||
## Back up files to the current filename plus a tilde.
|
||||
# set backup
|
||||
|
||||
## The directory to put unique backup files in.
|
||||
# set backupdir ""
|
||||
|
||||
## Use bold text instead of reverse video text.
|
||||
# set boldtext
|
||||
|
||||
## Treat any line with leading whitespace as the beginning of a paragraph.
|
||||
# set bookstyle
|
||||
|
||||
## The characters treated as closing brackets when justifying paragraphs.
|
||||
## This may not include any blank characters. Only closing punctuation,
|
||||
## optionally followed by these closing brackets, can end sentences.
|
||||
# set brackets ""')>]}"
|
||||
|
||||
## Automatically hard-wrap the current line when it becomes overlong.
|
||||
# set breaklonglines
|
||||
|
||||
## Do case-sensitive searches by default.
|
||||
# set casesensitive
|
||||
|
||||
## Interpret digits given on the command line after a colon after a filename
|
||||
## as the line number to go to in that file.
|
||||
# set colonparsing
|
||||
|
||||
## Constantly display the cursor position in the status bar or minibar.
|
||||
# set constantshow
|
||||
|
||||
## Use cut-from-cursor-to-end-of-line by default.
|
||||
# set cutfromcursor
|
||||
|
||||
## Do not use the line below the title bar, leaving it entirely blank.
|
||||
# set emptyline
|
||||
|
||||
## Set the target width for automatic hard-wrapping and for justifying
|
||||
## paragraphs. If the specified value is 0 or less, the wrapping point
|
||||
## will be the terminal's width minus this number.
|
||||
# set fill -8
|
||||
|
||||
## Draw a vertical stripe at the given column, to help judge text width.
|
||||
## (This option does not have a default value.)
|
||||
# set guidestripe 75
|
||||
|
||||
## Remember the used search/replace strings for the next session.
|
||||
# set historylog
|
||||
|
||||
## Display a "scrollbar" on the righthand side of the edit window.
|
||||
# set indicator
|
||||
|
||||
## Scroll the buffer contents per half-screen instead of per line.
|
||||
# set jumpyscrolling
|
||||
|
||||
## Display line numbers to the left (and any anchors in the margin).
|
||||
# set linenumbers
|
||||
|
||||
## Enable vim-style lock-files. This is just to let a vim user know you
|
||||
## are editing a file [s]he is trying to edit and vice versa. There are
|
||||
## no plans to implement vim-style undo state in these files.
|
||||
# set locking
|
||||
|
||||
## Fall back to slow libmagic to try and determine an applicable syntax.
|
||||
# set magic
|
||||
|
||||
## The opening and closing brackets that are found by a matching-bracket
|
||||
## search. This may not contain blank characters. The opening brackets
|
||||
## must come before the closing ones, and they must be in the same order.
|
||||
# set matchbrackets "(<[{)>]}"
|
||||
|
||||
## Suppress the title bar and show the filename plus a cursor-position
|
||||
## percentage in the space of the status bar.
|
||||
# set minibar
|
||||
|
||||
## Enable mouse support, if available for your system. When enabled,
|
||||
## mouse clicks can be used to place the cursor, set the mark (with
|
||||
## two clicks), and execute shortcuts. The mouse will work in the
|
||||
## X Window System, and on the console when gpm is running.
|
||||
# set mouse
|
||||
|
||||
## Switch on multiple file buffers (inserting a file will put it into
|
||||
## a separate buffer).
|
||||
# set multibuffer
|
||||
|
||||
## Don't convert files from DOS/Mac format.
|
||||
# set noconvert
|
||||
|
||||
## Don't display the helpful shortcut lists at the bottom of the screen.
|
||||
# set nohelp
|
||||
|
||||
## Don't automatically add a newline when a file does not end with one.
|
||||
# set nonewlines
|
||||
|
||||
## Set operating directory. nanofur will not read or write files outside
|
||||
## this directory and its subdirectories. Also, the current directory
|
||||
## is changed to here, so any files are inserted from this dir. A blank
|
||||
## string means the operating-directory feature is turned off.
|
||||
# set operatingdir ""
|
||||
|
||||
## Remember the cursor position in each file for the next editing session.
|
||||
# set positionlog
|
||||
|
||||
## Preserve the XON and XOFF keys (^Q and ^S).
|
||||
# set preserve
|
||||
|
||||
## The characters treated as closing punctuation when justifying paragraphs.
|
||||
## This may not contain blank characters. Only these closing punctuations,
|
||||
## optionally followed by closing brackets, can end sentences.
|
||||
# set punct "!.?"
|
||||
|
||||
## Make status-bar messages disappear after 1 keystroke instead of after 20.
|
||||
# set quickblank
|
||||
|
||||
## The regular expression that matches quoting characters in email
|
||||
## or line-comment introducers in source code. The default is:
|
||||
# set quotestr "^([ ]*([!#%:;>|}]|//))+"
|
||||
|
||||
## Try to work around a mismatching terminfo terminal description.
|
||||
# set rawsequences
|
||||
|
||||
## Fix Backspace/Delete confusion problem.
|
||||
# set rebinddelete
|
||||
|
||||
## Do regular-expression searches by default.
|
||||
## Regular expressions are of the extended type (ERE).
|
||||
# set regexp
|
||||
|
||||
## Save a changed buffer automatically on exit; don't prompt.
|
||||
# set saveonexit
|
||||
|
||||
## Put the cursor on the highlighted item in the file browser, and
|
||||
## show the cursor in the help viewer; useful for people who use a
|
||||
## braille display and people with poor vision.
|
||||
# set showcursor
|
||||
|
||||
## Make the Home key smarter: when Home is pressed anywhere but at the
|
||||
## very beginning of non-whitespace characters on a line, the cursor
|
||||
## will jump to that beginning (either forwards or backwards). If the
|
||||
## cursor is already at that position, it will jump to the true start
|
||||
## of the line (the left edge).
|
||||
# set smarthome
|
||||
|
||||
## Spread overlong lines over multiple screen lines.
|
||||
# set softwrap
|
||||
|
||||
## Use this spelling checker instead of the internal one. This option
|
||||
## does not have a default value.
|
||||
# set speller "aspell -x -c"
|
||||
|
||||
## Use the end of the title bar for some state flags: I = auto-indenting,
|
||||
## M = mark, L = hard-wrapping long lines, R = recording, S = soft-wrapping.
|
||||
# set stateflags
|
||||
|
||||
## Use this tab size instead of the default; it must be greater than 0.
|
||||
# set tabsize 8
|
||||
|
||||
## Convert each typed tab to the fitting number of spaces.
|
||||
# set tabstospaces
|
||||
|
||||
## Snip whitespace at the end of lines when justifying or hard-wrapping.
|
||||
# set trimblanks
|
||||
|
||||
## Save files by default in Unix format (also when they were DOS or Mac).
|
||||
# set unix
|
||||
|
||||
## The two single-column characters used to display the first characters
|
||||
## of tabs and spaces. 187 in ISO 8859-1 (0000BB in Unicode) and 183 in
|
||||
## ISO-8859-1 (0000B7 in Unicode) seem to be good values for these.
|
||||
## The default when in a UTF-8 locale:
|
||||
# set whitespace "»·"
|
||||
## The default otherwise:
|
||||
# set whitespace ">."
|
||||
|
||||
## Detect word boundaries differently by treating punctuation
|
||||
## characters as parts of words.
|
||||
# set wordbounds
|
||||
|
||||
## The characters (besides alphanumeric ones) that should be considered
|
||||
## as parts of words. This option does not have a default value. When
|
||||
## set, it overrides option 'set wordbounds'.
|
||||
# set wordchars "<_>."
|
||||
|
||||
## Let an unmodified Backspace or Delete erase the marked region (instead
|
||||
## of a single character, and without affecting the cutbuffer).
|
||||
# set zap
|
||||
|
||||
## Hide the bars plus help lines and use the whole terminal as edit area.
|
||||
# set zero
|
||||
|
||||
|
||||
## Paint the interface elements of nanofur. These are examples; there are
|
||||
## no colors by default, except for errorcolor and spotlightcolor.
|
||||
# set titlecolor bold,white,blue
|
||||
# set promptcolor lightwhite,grey
|
||||
# set statuscolor bold,white,green
|
||||
# set errorcolor bold,white,red
|
||||
# set spotlightcolor black,lightyellow
|
||||
# set selectedcolor lightwhite,magenta
|
||||
# set stripecolor ,#444
|
||||
# set scrollercolor cyan
|
||||
# set numbercolor cyan
|
||||
# set keycolor cyan
|
||||
# set functioncolor green
|
||||
|
||||
## In root's .nanofurrc you might want to use:
|
||||
# set titlecolor bold,white,magenta
|
||||
# set promptcolor black,yellow
|
||||
# set statuscolor bold,white,magenta
|
||||
# set errorcolor bold,white,red
|
||||
# set spotlightcolor black,orange
|
||||
# set selectedcolor lightwhite,cyan
|
||||
# set stripecolor ,yellow
|
||||
# set scrollercolor magenta
|
||||
# set numbercolor magenta
|
||||
# set keycolor lightmagenta
|
||||
# set functioncolor magenta
|
||||
|
||||
|
||||
## === Syntax coloring ===
|
||||
## For all details, see 'man nanofurrc', section SYNTAX HIGHLIGHTING.
|
||||
|
||||
## To include most of the existing syntax definitions, you can do:
|
||||
# include @PKGDATADIR@/*.nanofurrc
|
||||
|
||||
## Or you can select just the ones you need. For example:
|
||||
# include @PKGDATADIR@/html.nanofurrc
|
||||
# include @PKGDATADIR@/python.nanofurrc
|
||||
# include @PKGDATADIR@/sh.nanofurrc
|
||||
|
||||
## In @PKGDATADIR@/extra/ you can find some syntaxes that are
|
||||
## specific for certain distros or for some less common languages.
|
||||
|
||||
|
||||
## If <Tab> should always produce four spaces when editing a Python file,
|
||||
## independent of the settings of 'tabsize' and 'tabstospaces':
|
||||
# extendsyntax python tabgives " "
|
||||
|
||||
|
||||
## === Key bindings ===
|
||||
## For all details, see 'man nanofurrc', section REBINDING KEYS.
|
||||
|
||||
## If you want to suspend nanofur with one keystroke (instead of with ^T^Z):
|
||||
# bind ^Z suspend main
|
||||
|
||||
## The <Ctrl+Delete> keystroke deletes the word to the right of the cursor.
|
||||
## On some terminals the <Ctrl+Backspace> keystroke produces ^H, which is
|
||||
## the ASCII character for backspace, so it is bound by default to the
|
||||
## backspace function. The <Backspace> key itself produces a different
|
||||
## keycode, which is hard-bound to the backspace function. So, if you
|
||||
## normally use <Backspace> for backspacing and not ^H, you can make
|
||||
## <Ctrl+Backspace> delete the word to the left of the cursor with:
|
||||
# bind ^H chopwordleft main
|
||||
|
||||
## For a more mnemonic Comment keystroke (overriding Cut-from-cursor):
|
||||
# bind M-K comment main
|
||||
|
||||
## If you want ^L to just refresh the screen and not center the cursor:
|
||||
# bind ^L refresh main
|
||||
|
||||
## When you sometimes type M-J instead of M-K, or M-T instead of M-R:
|
||||
# unbind M-J main
|
||||
# unbind M-T main
|
||||
## (Those functions are still accessible through ^T^J and ^T^V.)
|
||||
|
||||
## For quickly uppercasing or lowercasing the word that the cursor is on.
|
||||
## (These effectively select a word and pipe it through a sed command.)
|
||||
# bind Sh-M-U "{nextword}{mark}{prevword}{execute}| sed 's/.*/\U&/' {enter}" main
|
||||
# bind Sh-M-L "{nextword}{mark}{prevword}{execute}| sed 's/.*/\L&/' {enter}" main
|
||||
|
||||
## For copying a marked region to the system clipboard:
|
||||
# bind Sh-M-C "{execute}| xsel -ib {enter}{undo}" main
|
||||
|
||||
## For normalizing Unicode to precomposed characters:
|
||||
# bind Sh-M-N "{execute}| uconv -x nfc {enter}" main
|
||||
|
||||
## For snipping trailing blanks when you save a file:
|
||||
# bind ^S "{execute}| sed 's/\s\+$//' {enter}{savefile}" main
|
||||
|
||||
## If you would like nanofur to have keybindings that are more "usual",
|
||||
## such as ^O for Open, ^F for Find, ^H for Help, and ^Q for Quit,
|
||||
## then uncomment these:
|
||||
# bind ^X cut main
|
||||
# bind ^C copy main
|
||||
# bind ^V paste all
|
||||
# bind ^Q exit all
|
||||
# bind ^S savefile main
|
||||
# bind ^W writeout main
|
||||
# bind ^O insert main
|
||||
# set multibuffer
|
||||
# bind ^H help all
|
||||
# bind ^H exit help
|
||||
# bind ^F whereis all
|
||||
# bind ^G findnext all
|
||||
# bind ^B wherewas all
|
||||
# bind ^D findprevious all
|
||||
# bind ^R replace main
|
||||
# unbind ^U all
|
||||
# unbind ^N main
|
||||
# unbind ^Y all
|
||||
# unbind M-J main
|
||||
# unbind M-T main
|
||||
# bind ^A mark main
|
||||
# bind ^P location main
|
||||
# bind ^T gotoline main
|
||||
# bind ^T gotodir browser
|
||||
# bind ^T cutrestoffile execute
|
||||
# bind ^L linter execute
|
||||
# bind ^E execute main
|
||||
# bind ^K "{mark}{end}{zap}" main
|
||||
# bind ^U "{mark}{home}{zap}" main
|
||||
# bind ^Z undo main
|
||||
# bind ^Y redo main
|
35
m4/Makefile.am
Normal file
35
m4/Makefile.am
Normal file
|
@ -0,0 +1,35 @@
|
|||
EXTRA_DIST = \
|
||||
ac_define_dir.m4 \
|
||||
ax_check_compile_flag.m4 \
|
||||
codeset.m4 \
|
||||
extern-inline.m4 \
|
||||
fcntl-o.m4 \
|
||||
gettext.m4 \
|
||||
glibc21.m4 \
|
||||
glibc2.m4 \
|
||||
gnulib-cache.m4 \
|
||||
iconv.m4 \
|
||||
intdiv0.m4 \
|
||||
intldir.m4 \
|
||||
intl.m4 \
|
||||
intlmacosx.m4 \
|
||||
intmax.m4 \
|
||||
inttypes_h.m4 \
|
||||
inttypes-pri.m4 \
|
||||
lcmessage.m4 \
|
||||
lib-ld.m4 \
|
||||
lib-link.m4 \
|
||||
lib-prefix.m4 \
|
||||
lock.m4 \
|
||||
longlong.m4 \
|
||||
nls.m4 \
|
||||
po.m4 \
|
||||
printf-posix.m4 \
|
||||
progtest.m4 \
|
||||
size_max.m4 \
|
||||
stdint_h.m4 \
|
||||
threadlib.m4 \
|
||||
uintmax_t.m4 \
|
||||
visibility.m4 \
|
||||
wint_t.m4 \
|
||||
xsize.m4
|
34
m4/ac_define_dir.m4
Normal file
34
m4/ac_define_dir.m4
Normal file
|
@ -0,0 +1,34 @@
|
|||
dnl @synopsis AC_DEFINE_DIR(VARNAME, DIR [, DESCRIPTION])
|
||||
dnl
|
||||
dnl This macro sets VARNAME to the expansion of the DIR variable,
|
||||
dnl taking care of fixing up ${prefix} and such.
|
||||
dnl
|
||||
dnl VARNAME is then offered as both an output variable and a C
|
||||
dnl preprocessor symbol.
|
||||
dnl
|
||||
dnl Example:
|
||||
dnl
|
||||
dnl AC_DEFINE_DIR([DATADIR], [datadir], [Where data are placed to.])
|
||||
dnl
|
||||
dnl @category Misc
|
||||
dnl @author Stepan Kasal <kasal@ucw.cz>
|
||||
dnl @author Andreas Schwab <schwab@suse.de>
|
||||
dnl @author Guido U. Draheim <guidod@gmx.de>
|
||||
dnl @author Alexandre Oliva
|
||||
dnl @version 2006-10-13
|
||||
dnl @license AllPermissive
|
||||
|
||||
AC_DEFUN([AC_DEFINE_DIR], [
|
||||
prefix_NONE=
|
||||
exec_prefix_NONE=
|
||||
test "x$prefix" = xNONE && prefix_NONE=yes && prefix=$ac_default_prefix
|
||||
test "x$exec_prefix" = xNONE && exec_prefix_NONE=yes && exec_prefix=$prefix
|
||||
dnl In Autoconf 2.60, ${datadir} refers to ${datarootdir}, which in turn
|
||||
dnl refers to ${prefix}. Thus we have to use `eval' twice.
|
||||
eval ac_define_dir="\"[$]$2\""
|
||||
eval ac_define_dir="\"$ac_define_dir\""
|
||||
AC_SUBST($1, "$ac_define_dir")
|
||||
AC_DEFINE_UNQUOTED($1, "$ac_define_dir", [$3])
|
||||
test "$prefix_NONE" && prefix=NONE
|
||||
test "$exec_prefix_NONE" && exec_prefix=NONE
|
||||
])
|
74
m4/ax_check_compile_flag.m4
Normal file
74
m4/ax_check_compile_flag.m4
Normal file
|
@ -0,0 +1,74 @@
|
|||
# ===========================================================================
|
||||
# http://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html
|
||||
# ===========================================================================
|
||||
#
|
||||
# SYNOPSIS
|
||||
#
|
||||
# AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT])
|
||||
#
|
||||
# DESCRIPTION
|
||||
#
|
||||
# Check whether the given FLAG works with the current language's compiler
|
||||
# or gives an error. (Warnings, however, are ignored)
|
||||
#
|
||||
# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
|
||||
# success/failure.
|
||||
#
|
||||
# If EXTRA-FLAGS is defined, it is added to the current language's default
|
||||
# flags (e.g. CFLAGS) when the check is done. The check is thus made with
|
||||
# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to
|
||||
# force the compiler to issue an error when a bad flag is given.
|
||||
#
|
||||
# INPUT gives an alternative input source to AC_COMPILE_IFELSE.
|
||||
#
|
||||
# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this
|
||||
# macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG.
|
||||
#
|
||||
# LICENSE
|
||||
#
|
||||
# Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
|
||||
# Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the
|
||||
# Free Software Foundation, either version 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# As a special exception, the respective Autoconf Macro's copyright owner
|
||||
# gives unlimited permission to copy, distribute and modify the configure
|
||||
# scripts that are the output of Autoconf when processing the Macro. You
|
||||
# need not follow the terms of the GNU General Public License when using
|
||||
# or distributing such scripts, even though portions of the text of the
|
||||
# Macro appear in them. The GNU General Public License (GPL) does govern
|
||||
# all other use of the material that constitutes the Autoconf Macro.
|
||||
#
|
||||
# This special exception to the GPL applies to versions of the Autoconf
|
||||
# Macro released by the Autoconf Archive. When you make and distribute a
|
||||
# modified version of the Autoconf Macro, you may extend this special
|
||||
# exception to the GPL to apply to your modified version as well.
|
||||
|
||||
#serial 3
|
||||
|
||||
AC_DEFUN([AX_CHECK_COMPILE_FLAG],
|
||||
[AC_PREREQ(2.59)dnl for _AC_LANG_PREFIX
|
||||
AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
|
||||
AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [
|
||||
ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
|
||||
_AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
|
||||
AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
|
||||
[AS_VAR_SET(CACHEVAR,[yes])],
|
||||
[AS_VAR_SET(CACHEVAR,[no])])
|
||||
_AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
|
||||
AS_IF([test x"AS_VAR_GET(CACHEVAR)" = xyes],
|
||||
[m4_default([$2], :)],
|
||||
[m4_default([$3], :)])
|
||||
AS_VAR_POPDEF([CACHEVAR])dnl
|
||||
])dnl AX_CHECK_COMPILE_FLAGS
|
644
m4/host-cpu-c-abi.m4
Normal file
644
m4/host-cpu-c-abi.m4
Normal file
|
@ -0,0 +1,644 @@
|
|||
# host-cpu-c-abi.m4 serial 11
|
||||
dnl Copyright (C) 2002-2019 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
dnl with or without modifications, as long as this notice is preserved.
|
||||
|
||||
dnl From Bruno Haible and Sam Steingold.
|
||||
|
||||
dnl Sets the HOST_CPU variable to the canonical name of the CPU.
|
||||
dnl Sets the HOST_CPU_C_ABI variable to the canonical name of the CPU with its
|
||||
dnl C language ABI (application binary interface).
|
||||
dnl Also defines __${HOST_CPU}__ and __${HOST_CPU_C_ABI}__ as C macros in
|
||||
dnl config.h.
|
||||
dnl
|
||||
dnl This canonical name can be used to select a particular assembly language
|
||||
dnl source file that will interoperate with C code on the given host.
|
||||
dnl
|
||||
dnl For example:
|
||||
dnl * 'i386' and 'sparc' are different canonical names, because code for i386
|
||||
dnl will not run on SPARC CPUs and vice versa. They have different
|
||||
dnl instruction sets.
|
||||
dnl * 'sparc' and 'sparc64' are different canonical names, because code for
|
||||
dnl 'sparc' and code for 'sparc64' cannot be linked together: 'sparc' code
|
||||
dnl contains 32-bit instructions, whereas 'sparc64' code contains 64-bit
|
||||
dnl instructions. A process on a SPARC CPU can be in 32-bit mode or in 64-bit
|
||||
dnl mode, but not both.
|
||||
dnl * 'mips' and 'mipsn32' are different canonical names, because they use
|
||||
dnl different argument passing and return conventions for C functions, and
|
||||
dnl although the instruction set of 'mips' is a large subset of the
|
||||
dnl instruction set of 'mipsn32'.
|
||||
dnl * 'mipsn32' and 'mips64' are different canonical names, because they use
|
||||
dnl different sizes for the C types like 'int' and 'void *', and although
|
||||
dnl the instruction sets of 'mipsn32' and 'mips64' are the same.
|
||||
dnl * The same canonical name is used for different endiannesses. You can
|
||||
dnl determine the endianness through preprocessor symbols:
|
||||
dnl - 'arm': test __ARMEL__.
|
||||
dnl - 'mips', 'mipsn32', 'mips64': test _MIPSEB vs. _MIPSEL.
|
||||
dnl - 'powerpc64': test _BIG_ENDIAN vs. _LITTLE_ENDIAN.
|
||||
dnl * The same name 'i386' is used for CPUs of type i386, i486, i586
|
||||
dnl (Pentium), AMD K7, Pentium II, Pentium IV, etc., because
|
||||
dnl - Instructions that do not exist on all of these CPUs (cmpxchg,
|
||||
dnl MMX, SSE, SSE2, 3DNow! etc.) are not frequently used. If your
|
||||
dnl assembly language source files use such instructions, you will
|
||||
dnl need to make the distinction.
|
||||
dnl - Speed of execution of the common instruction set is reasonable across
|
||||
dnl the entire family of CPUs. If you have assembly language source files
|
||||
dnl that are optimized for particular CPU types (like GNU gmp has), you
|
||||
dnl will need to make the distinction.
|
||||
dnl See <https://en.wikipedia.org/wiki/X86_instruction_listings>.
|
||||
AC_DEFUN([gl_HOST_CPU_C_ABI],
|
||||
[
|
||||
AC_REQUIRE([AC_CANONICAL_HOST])
|
||||
AC_REQUIRE([gl_C_ASM])
|
||||
AC_CACHE_CHECK([host CPU and C ABI], [gl_cv_host_cpu_c_abi],
|
||||
[case "$host_cpu" in
|
||||
|
||||
changequote(,)dnl
|
||||
i[4567]86 )
|
||||
changequote([,])dnl
|
||||
gl_cv_host_cpu_c_abi=i386
|
||||
;;
|
||||
|
||||
x86_64 )
|
||||
# On x86_64 systems, the C compiler may be generating code in one of
|
||||
# these ABIs:
|
||||
# - 64-bit instruction set, 64-bit pointers, 64-bit 'long': x86_64.
|
||||
# - 64-bit instruction set, 64-bit pointers, 32-bit 'long': x86_64
|
||||
# with native Windows (mingw, MSVC).
|
||||
# - 64-bit instruction set, 32-bit pointers, 32-bit 'long': x86_64-x32.
|
||||
# - 32-bit instruction set, 32-bit pointers, 32-bit 'long': i386.
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_SOURCE(
|
||||
[[#if (defined __x86_64__ || defined __amd64__ \
|
||||
|| defined _M_X64 || defined _M_AMD64)
|
||||
int ok;
|
||||
#else
|
||||
error fail
|
||||
#endif
|
||||
]])],
|
||||
[AC_COMPILE_IFELSE(
|
||||
[AC_LANG_SOURCE(
|
||||
[[#if defined __ILP32__ || defined _ILP32
|
||||
int ok;
|
||||
#else
|
||||
error fail
|
||||
#endif
|
||||
]])],
|
||||
[gl_cv_host_cpu_c_abi=x86_64-x32],
|
||||
[gl_cv_host_cpu_c_abi=x86_64])],
|
||||
[gl_cv_host_cpu_c_abi=i386])
|
||||
;;
|
||||
|
||||
changequote(,)dnl
|
||||
alphaev[4-8] | alphaev56 | alphapca5[67] | alphaev6[78] )
|
||||
changequote([,])dnl
|
||||
gl_cv_host_cpu_c_abi=alpha
|
||||
;;
|
||||
|
||||
arm* | aarch64 )
|
||||
# Assume arm with EABI.
|
||||
# On arm64 systems, the C compiler may be generating code in one of
|
||||
# these ABIs:
|
||||
# - aarch64 instruction set, 64-bit pointers, 64-bit 'long': arm64.
|
||||
# - aarch64 instruction set, 32-bit pointers, 32-bit 'long': arm64-ilp32.
|
||||
# - 32-bit instruction set, 32-bit pointers, 32-bit 'long': arm or armhf.
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_SOURCE(
|
||||
[[#ifdef __aarch64__
|
||||
int ok;
|
||||
#else
|
||||
error fail
|
||||
#endif
|
||||
]])],
|
||||
[AC_COMPILE_IFELSE(
|
||||
[AC_LANG_SOURCE(
|
||||
[[#if defined __ILP32__ || defined _ILP32
|
||||
int ok;
|
||||
#else
|
||||
error fail
|
||||
#endif
|
||||
]])],
|
||||
[gl_cv_host_cpu_c_abi=arm64-ilp32],
|
||||
[gl_cv_host_cpu_c_abi=arm64])],
|
||||
[# Don't distinguish little-endian and big-endian arm, since they
|
||||
# don't require different machine code for simple operations and
|
||||
# since the user can distinguish them through the preprocessor
|
||||
# defines __ARMEL__ vs. __ARMEB__.
|
||||
# But distinguish arm which passes floating-point arguments and
|
||||
# return values in integer registers (r0, r1, ...) - this is
|
||||
# gcc -mfloat-abi=soft or gcc -mfloat-abi=softfp - from arm which
|
||||
# passes them in float registers (s0, s1, ...) and double registers
|
||||
# (d0, d1, ...) - this is gcc -mfloat-abi=hard. GCC 4.6 or newer
|
||||
# sets the preprocessor defines __ARM_PCS (for the first case) and
|
||||
# __ARM_PCS_VFP (for the second case), but older GCC does not.
|
||||
echo 'double ddd; void func (double dd) { ddd = dd; }' > conftest.c
|
||||
# Look for a reference to the register d0 in the .s file.
|
||||
AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS $gl_c_asm_opt conftest.c) >/dev/null 2>&1
|
||||
if LC_ALL=C grep 'd0,' conftest.$gl_asmext >/dev/null; then
|
||||
gl_cv_host_cpu_c_abi=armhf
|
||||
else
|
||||
gl_cv_host_cpu_c_abi=arm
|
||||
fi
|
||||
rm -f conftest*
|
||||
])
|
||||
;;
|
||||
|
||||
hppa1.0 | hppa1.1 | hppa2.0* | hppa64 )
|
||||
# On hppa, the C compiler may be generating 32-bit code or 64-bit
|
||||
# code. In the latter case, it defines _LP64 and __LP64__.
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_SOURCE(
|
||||
[[#ifdef __LP64__
|
||||
int ok;
|
||||
#else
|
||||
error fail
|
||||
#endif
|
||||
]])],
|
||||
[gl_cv_host_cpu_c_abi=hppa64],
|
||||
[gl_cv_host_cpu_c_abi=hppa])
|
||||
;;
|
||||
|
||||
ia64* )
|
||||
# On ia64 on HP-UX, the C compiler may be generating 64-bit code or
|
||||
# 32-bit code. In the latter case, it defines _ILP32.
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_SOURCE(
|
||||
[[#ifdef _ILP32
|
||||
int ok;
|
||||
#else
|
||||
error fail
|
||||
#endif
|
||||
]])],
|
||||
[gl_cv_host_cpu_c_abi=ia64-ilp32],
|
||||
[gl_cv_host_cpu_c_abi=ia64])
|
||||
;;
|
||||
|
||||
mips* )
|
||||
# We should also check for (_MIPS_SZPTR == 64), but gcc keeps this
|
||||
# at 32.
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_SOURCE(
|
||||
[[#if defined _MIPS_SZLONG && (_MIPS_SZLONG == 64)
|
||||
int ok;
|
||||
#else
|
||||
error fail
|
||||
#endif
|
||||
]])],
|
||||
[gl_cv_host_cpu_c_abi=mips64],
|
||||
[# In the n32 ABI, _ABIN32 is defined, _ABIO32 is not defined (but
|
||||
# may later get defined by <sgidefs.h>), and _MIPS_SIM == _ABIN32.
|
||||
# In the 32 ABI, _ABIO32 is defined, _ABIN32 is not defined (but
|
||||
# may later get defined by <sgidefs.h>), and _MIPS_SIM == _ABIO32.
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_SOURCE(
|
||||
[[#if (_MIPS_SIM == _ABIN32)
|
||||
int ok;
|
||||
#else
|
||||
error fail
|
||||
#endif
|
||||
]])],
|
||||
[gl_cv_host_cpu_c_abi=mipsn32],
|
||||
[gl_cv_host_cpu_c_abi=mips])])
|
||||
;;
|
||||
|
||||
powerpc* )
|
||||
# Different ABIs are in use on AIX vs. Mac OS X vs. Linux,*BSD.
|
||||
# No need to distinguish them here; the caller may distinguish
|
||||
# them based on the OS.
|
||||
# On powerpc64 systems, the C compiler may still be generating
|
||||
# 32-bit code. And on powerpc-ibm-aix systems, the C compiler may
|
||||
# be generating 64-bit code.
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_SOURCE(
|
||||
[[#if defined __powerpc64__ || defined _ARCH_PPC64
|
||||
int ok;
|
||||
#else
|
||||
error fail
|
||||
#endif
|
||||
]])],
|
||||
[# On powerpc64, there are two ABIs on Linux: The AIX compatible
|
||||
# one and the ELFv2 one. The latter defines _CALL_ELF=2.
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_SOURCE(
|
||||
[[#if defined _CALL_ELF && _CALL_ELF == 2
|
||||
int ok;
|
||||
#else
|
||||
error fail
|
||||
#endif
|
||||
]])],
|
||||
[gl_cv_host_cpu_c_abi=powerpc64-elfv2],
|
||||
[gl_cv_host_cpu_c_abi=powerpc64])
|
||||
],
|
||||
[gl_cv_host_cpu_c_abi=powerpc])
|
||||
;;
|
||||
|
||||
rs6000 )
|
||||
gl_cv_host_cpu_c_abi=powerpc
|
||||
;;
|
||||
|
||||
riscv32 | riscv64 )
|
||||
# There are 2 architectures (with variants): rv32* and rv64*.
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_SOURCE(
|
||||
[[#if __riscv_xlen == 64
|
||||
int ok;
|
||||
#else
|
||||
error fail
|
||||
#endif
|
||||
]])],
|
||||
[cpu=riscv64],
|
||||
[cpu=riscv32])
|
||||
# There are 6 ABIs: ilp32, ilp32f, ilp32d, lp64, lp64f, lp64d.
|
||||
# Size of 'long' and 'void *':
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_SOURCE(
|
||||
[[#if defined __LP64__
|
||||
int ok;
|
||||
#else
|
||||
error fail
|
||||
#endif
|
||||
]])],
|
||||
[main_abi=lp64],
|
||||
[main_abi=ilp32])
|
||||
# Float ABIs:
|
||||
# __riscv_float_abi_double:
|
||||
# 'float' and 'double' are passed in floating-point registers.
|
||||
# __riscv_float_abi_single:
|
||||
# 'float' are passed in floating-point registers.
|
||||
# __riscv_float_abi_soft:
|
||||
# No values are passed in floating-point registers.
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_SOURCE(
|
||||
[[#if defined __riscv_float_abi_double
|
||||
int ok;
|
||||
#else
|
||||
error fail
|
||||
#endif
|
||||
]])],
|
||||
[float_abi=d],
|
||||
[AC_COMPILE_IFELSE(
|
||||
[AC_LANG_SOURCE(
|
||||
[[#if defined __riscv_float_abi_single
|
||||
int ok;
|
||||
#else
|
||||
error fail
|
||||
#endif
|
||||
]])],
|
||||
[float_abi=f],
|
||||
[float_abi=''])
|
||||
])
|
||||
gl_cv_host_cpu_c_abi="${cpu}-${main_abi}${float_abi}"
|
||||
;;
|
||||
|
||||
s390* )
|
||||
# On s390x, the C compiler may be generating 64-bit (= s390x) code
|
||||
# or 31-bit (= s390) code.
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_SOURCE(
|
||||
[[#if defined __LP64__ || defined __s390x__
|
||||
int ok;
|
||||
#else
|
||||
error fail
|
||||
#endif
|
||||
]])],
|
||||
[gl_cv_host_cpu_c_abi=s390x],
|
||||
[gl_cv_host_cpu_c_abi=s390])
|
||||
;;
|
||||
|
||||
sparc | sparc64 )
|
||||
# UltraSPARCs running Linux have `uname -m` = "sparc64", but the
|
||||
# C compiler still generates 32-bit code.
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_SOURCE(
|
||||
[[#if defined __sparcv9 || defined __arch64__
|
||||
int ok;
|
||||
#else
|
||||
error fail
|
||||
#endif
|
||||
]])],
|
||||
[gl_cv_host_cpu_c_abi=sparc64],
|
||||
[gl_cv_host_cpu_c_abi=sparc])
|
||||
;;
|
||||
|
||||
*)
|
||||
gl_cv_host_cpu_c_abi="$host_cpu"
|
||||
;;
|
||||
esac
|
||||
])
|
||||
|
||||
dnl In most cases, $HOST_CPU and $HOST_CPU_C_ABI are the same.
|
||||
HOST_CPU=`echo "$gl_cv_host_cpu_c_abi" | sed -e 's/-.*//'`
|
||||
HOST_CPU_C_ABI="$gl_cv_host_cpu_c_abi"
|
||||
AC_SUBST([HOST_CPU])
|
||||
AC_SUBST([HOST_CPU_C_ABI])
|
||||
|
||||
# This was
|
||||
# AC_DEFINE_UNQUOTED([__${HOST_CPU}__])
|
||||
# AC_DEFINE_UNQUOTED([__${HOST_CPU_C_ABI}__])
|
||||
# earlier, but KAI C++ 3.2d doesn't like this.
|
||||
sed -e 's/-/_/g' >> confdefs.h <<EOF
|
||||
#ifndef __${HOST_CPU}__
|
||||
#define __${HOST_CPU}__ 1
|
||||
#endif
|
||||
#ifndef __${HOST_CPU_C_ABI}__
|
||||
#define __${HOST_CPU_C_ABI}__ 1
|
||||
#endif
|
||||
EOF
|
||||
AH_TOP([/* CPU and C ABI indicator */
|
||||
#ifndef __i386__
|
||||
#undef __i386__
|
||||
#endif
|
||||
#ifndef __x86_64_x32__
|
||||
#undef __x86_64_x32__
|
||||
#endif
|
||||
#ifndef __x86_64__
|
||||
#undef __x86_64__
|
||||
#endif
|
||||
#ifndef __alpha__
|
||||
#undef __alpha__
|
||||
#endif
|
||||
#ifndef __arm__
|
||||
#undef __arm__
|
||||
#endif
|
||||
#ifndef __armhf__
|
||||
#undef __armhf__
|
||||
#endif
|
||||
#ifndef __arm64_ilp32__
|
||||
#undef __arm64_ilp32__
|
||||
#endif
|
||||
#ifndef __arm64__
|
||||
#undef __arm64__
|
||||
#endif
|
||||
#ifndef __hppa__
|
||||
#undef __hppa__
|
||||
#endif
|
||||
#ifndef __hppa64__
|
||||
#undef __hppa64__
|
||||
#endif
|
||||
#ifndef __ia64_ilp32__
|
||||
#undef __ia64_ilp32__
|
||||
#endif
|
||||
#ifndef __ia64__
|
||||
#undef __ia64__
|
||||
#endif
|
||||
#ifndef __m68k__
|
||||
#undef __m68k__
|
||||
#endif
|
||||
#ifndef __mips__
|
||||
#undef __mips__
|
||||
#endif
|
||||
#ifndef __mipsn32__
|
||||
#undef __mipsn32__
|
||||
#endif
|
||||
#ifndef __mips64__
|
||||
#undef __mips64__
|
||||
#endif
|
||||
#ifndef __powerpc__
|
||||
#undef __powerpc__
|
||||
#endif
|
||||
#ifndef __powerpc64__
|
||||
#undef __powerpc64__
|
||||
#endif
|
||||
#ifndef __powerpc64_elfv2__
|
||||
#undef __powerpc64_elfv2__
|
||||
#endif
|
||||
#ifndef __riscv32__
|
||||
#undef __riscv32__
|
||||
#endif
|
||||
#ifndef __riscv64__
|
||||
#undef __riscv64__
|
||||
#endif
|
||||
#ifndef __riscv32_ilp32__
|
||||
#undef __riscv32_ilp32__
|
||||
#endif
|
||||
#ifndef __riscv32_ilp32f__
|
||||
#undef __riscv32_ilp32f__
|
||||
#endif
|
||||
#ifndef __riscv32_ilp32d__
|
||||
#undef __riscv32_ilp32d__
|
||||
#endif
|
||||
#ifndef __riscv64_ilp32__
|
||||
#undef __riscv64_ilp32__
|
||||
#endif
|
||||
#ifndef __riscv64_ilp32f__
|
||||
#undef __riscv64_ilp32f__
|
||||
#endif
|
||||
#ifndef __riscv64_ilp32d__
|
||||
#undef __riscv64_ilp32d__
|
||||
#endif
|
||||
#ifndef __riscv64_lp64__
|
||||
#undef __riscv64_lp64__
|
||||
#endif
|
||||
#ifndef __riscv64_lp64f__
|
||||
#undef __riscv64_lp64f__
|
||||
#endif
|
||||
#ifndef __riscv64_lp64d__
|
||||
#undef __riscv64_lp64d__
|
||||
#endif
|
||||
#ifndef __s390__
|
||||
#undef __s390__
|
||||
#endif
|
||||
#ifndef __s390x__
|
||||
#undef __s390x__
|
||||
#endif
|
||||
#ifndef __sh__
|
||||
#undef __sh__
|
||||
#endif
|
||||
#ifndef __sparc__
|
||||
#undef __sparc__
|
||||
#endif
|
||||
#ifndef __sparc64__
|
||||
#undef __sparc64__
|
||||
#endif
|
||||
])
|
||||
|
||||
])
|
||||
|
||||
|
||||
dnl Sets the HOST_CPU_C_ABI_32BIT variable to 'yes' if the C language ABI
|
||||
dnl (application binary interface) is a 32-bit one, or to 'no' otherwise.
|
||||
dnl This is a simplified variant of gl_HOST_CPU_C_ABI.
|
||||
AC_DEFUN([gl_HOST_CPU_C_ABI_32BIT],
|
||||
[
|
||||
AC_REQUIRE([AC_CANONICAL_HOST])
|
||||
AC_CACHE_CHECK([32-bit host C ABI], [gl_cv_host_cpu_c_abi_32bit],
|
||||
[if test -n "$gl_cv_host_cpu_c_abi"; then
|
||||
case "$gl_cv_host_cpu_c_abi" in
|
||||
i386 | x86_64-x32 | arm | armhf | arm64-ilp32 | hppa | ia64-ilp32 | mips | mipsn32 | powerpc | riscv*-ilp32* | s390 | sparc)
|
||||
gl_cv_host_cpu_c_abi_32bit=yes ;;
|
||||
*)
|
||||
gl_cv_host_cpu_c_abi_32bit=no ;;
|
||||
esac
|
||||
else
|
||||
case "$host_cpu" in
|
||||
|
||||
changequote(,)dnl
|
||||
i[4567]86 )
|
||||
changequote([,])dnl
|
||||
gl_cv_host_cpu_c_abi_32bit=yes
|
||||
;;
|
||||
|
||||
x86_64 )
|
||||
# On x86_64 systems, the C compiler may be generating code in one of
|
||||
# these ABIs:
|
||||
# - 64-bit instruction set, 64-bit pointers, 64-bit 'long': x86_64.
|
||||
# - 64-bit instruction set, 64-bit pointers, 32-bit 'long': x86_64
|
||||
# with native Windows (mingw, MSVC).
|
||||
# - 64-bit instruction set, 32-bit pointers, 32-bit 'long': x86_64-x32.
|
||||
# - 32-bit instruction set, 32-bit pointers, 32-bit 'long': i386.
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_SOURCE(
|
||||
[[#if (defined __x86_64__ || defined __amd64__ \
|
||||
|| defined _M_X64 || defined _M_AMD64) \
|
||||
&& !(defined __ILP32__ || defined _ILP32)
|
||||
int ok;
|
||||
#else
|
||||
error fail
|
||||
#endif
|
||||
]])],
|
||||
[gl_cv_host_cpu_c_abi_32bit=no],
|
||||
[gl_cv_host_cpu_c_abi_32bit=yes])
|
||||
;;
|
||||
|
||||
arm* | aarch64 )
|
||||
# Assume arm with EABI.
|
||||
# On arm64 systems, the C compiler may be generating code in one of
|
||||
# these ABIs:
|
||||
# - aarch64 instruction set, 64-bit pointers, 64-bit 'long': arm64.
|
||||
# - aarch64 instruction set, 32-bit pointers, 32-bit 'long': arm64-ilp32.
|
||||
# - 32-bit instruction set, 32-bit pointers, 32-bit 'long': arm or armhf.
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_SOURCE(
|
||||
[[#if defined __aarch64__ && !(defined __ILP32__ || defined _ILP32)
|
||||
int ok;
|
||||
#else
|
||||
error fail
|
||||
#endif
|
||||
]])],
|
||||
[gl_cv_host_cpu_c_abi_32bit=no],
|
||||
[gl_cv_host_cpu_c_abi_32bit=yes])
|
||||
;;
|
||||
|
||||
hppa1.0 | hppa1.1 | hppa2.0* | hppa64 )
|
||||
# On hppa, the C compiler may be generating 32-bit code or 64-bit
|
||||
# code. In the latter case, it defines _LP64 and __LP64__.
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_SOURCE(
|
||||
[[#ifdef __LP64__
|
||||
int ok;
|
||||
#else
|
||||
error fail
|
||||
#endif
|
||||
]])],
|
||||
[gl_cv_host_cpu_c_abi_32bit=no],
|
||||
[gl_cv_host_cpu_c_abi_32bit=yes])
|
||||
;;
|
||||
|
||||
ia64* )
|
||||
# On ia64 on HP-UX, the C compiler may be generating 64-bit code or
|
||||
# 32-bit code. In the latter case, it defines _ILP32.
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_SOURCE(
|
||||
[[#ifdef _ILP32
|
||||
int ok;
|
||||
#else
|
||||
error fail
|
||||
#endif
|
||||
]])],
|
||||
[gl_cv_host_cpu_c_abi_32bit=yes],
|
||||
[gl_cv_host_cpu_c_abi_32bit=no])
|
||||
;;
|
||||
|
||||
mips* )
|
||||
# We should also check for (_MIPS_SZPTR == 64), but gcc keeps this
|
||||
# at 32.
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_SOURCE(
|
||||
[[#if defined _MIPS_SZLONG && (_MIPS_SZLONG == 64)
|
||||
int ok;
|
||||
#else
|
||||
error fail
|
||||
#endif
|
||||
]])],
|
||||
[gl_cv_host_cpu_c_abi_32bit=no],
|
||||
[gl_cv_host_cpu_c_abi_32bit=yes])
|
||||
;;
|
||||
|
||||
powerpc* )
|
||||
# Different ABIs are in use on AIX vs. Mac OS X vs. Linux,*BSD.
|
||||
# No need to distinguish them here; the caller may distinguish
|
||||
# them based on the OS.
|
||||
# On powerpc64 systems, the C compiler may still be generating
|
||||
# 32-bit code. And on powerpc-ibm-aix systems, the C compiler may
|
||||
# be generating 64-bit code.
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_SOURCE(
|
||||
[[#if defined __powerpc64__ || defined _ARCH_PPC64
|
||||
int ok;
|
||||
#else
|
||||
error fail
|
||||
#endif
|
||||
]])],
|
||||
[gl_cv_host_cpu_c_abi_32bit=no],
|
||||
[gl_cv_host_cpu_c_abi_32bit=yes])
|
||||
;;
|
||||
|
||||
rs6000 )
|
||||
gl_cv_host_cpu_c_abi_32bit=yes
|
||||
;;
|
||||
|
||||
riscv32 | riscv64 )
|
||||
# There are 6 ABIs: ilp32, ilp32f, ilp32d, lp64, lp64f, lp64d.
|
||||
# Size of 'long' and 'void *':
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_SOURCE(
|
||||
[[#if defined __LP64__
|
||||
int ok;
|
||||
#else
|
||||
error fail
|
||||
#endif
|
||||
]])],
|
||||
[gl_cv_host_cpu_c_abi_32bit=no],
|
||||
[gl_cv_host_cpu_c_abi_32bit=yes])
|
||||
;;
|
||||
|
||||
s390* )
|
||||
# On s390x, the C compiler may be generating 64-bit (= s390x) code
|
||||
# or 31-bit (= s390) code.
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_SOURCE(
|
||||
[[#if defined __LP64__ || defined __s390x__
|
||||
int ok;
|
||||
#else
|
||||
error fail
|
||||
#endif
|
||||
]])],
|
||||
[gl_cv_host_cpu_c_abi_32bit=no],
|
||||
[gl_cv_host_cpu_c_abi_32bit=yes])
|
||||
;;
|
||||
|
||||
sparc | sparc64 )
|
||||
# UltraSPARCs running Linux have `uname -m` = "sparc64", but the
|
||||
# C compiler still generates 32-bit code.
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_SOURCE(
|
||||
[[#if defined __sparcv9 || defined __arch64__
|
||||
int ok;
|
||||
#else
|
||||
error fail
|
||||
#endif
|
||||
]])],
|
||||
[gl_cv_host_cpu_c_abi_32bit=no],
|
||||
[gl_cv_host_cpu_c_abi_32bit=yes])
|
||||
;;
|
||||
|
||||
*)
|
||||
gl_cv_host_cpu_c_abi_32bit=no
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
])
|
||||
|
||||
HOST_CPU_C_ABI_32BIT="$gl_cv_host_cpu_c_abi_32bit"
|
||||
])
|
29
nanofur-regress
Executable file
29
nanofur-regress
Executable file
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/perl
|
||||
use strict;
|
||||
|
||||
sub combinations {
|
||||
return [] unless @_;
|
||||
my $first = shift;
|
||||
my @rest = combinations(@_);
|
||||
return @rest, map { [$first, @$_] } @rest;
|
||||
}
|
||||
|
||||
my @allargs=("--enable-debug", "--disable-wrapping", "--disable-justify", "--disable-extra", "--enable-tiny", "--disable-utf8", "--disable-multibuffer", "--disable-nanofurrc", "--with-slang");
|
||||
my @combos = combinations(@allargs);
|
||||
|
||||
my $i = 0;
|
||||
foreach my $name (@combos) {
|
||||
my @args = @$name;
|
||||
my $pct = $i / $#combos * 100;
|
||||
printf "Trying with options: @args, %d%% done...\n", $pct;
|
||||
my $cmd = "./configure @args && make clean all";
|
||||
system("($cmd) >/dev/null 2>&1");
|
||||
if ($? != 0) {
|
||||
print "Build failed for args: @args\n";
|
||||
print "To reproduce, run:\n $cmd\n";
|
||||
exit(1);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
print "All options completed successfully!\n";
|
14
po/.gitignore
vendored
Normal file
14
po/.gitignore
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
/*.gmo
|
||||
|
||||
/Makefile.in.in
|
||||
/Makevars.template
|
||||
/Rules-quot
|
||||
/boldquot.sed
|
||||
/en@boldquot.header
|
||||
/en@quot.header
|
||||
/insert-header.sin
|
||||
/POTFILES
|
||||
/quot.sed
|
||||
/remove-potcdate.sed
|
||||
/remove-potcdate.sin
|
||||
/stamp-po
|
2
po/LINGUAS
Normal file
2
po/LINGUAS
Normal file
|
@ -0,0 +1,2 @@
|
|||
# List of available languages.
|
||||
bg ca cs da de eo es eu fi fr ga gl hr hu id is it ja ka ko ms nb nl pl pt pt_BR ro ru sk sl sq sr sv tr uk vi zh_CN zh_TW
|
22
po/Makevars
Normal file
22
po/Makevars
Normal file
|
@ -0,0 +1,22 @@
|
|||
# Makefile variables for PO directory in any package using GNU gettext.
|
||||
|
||||
# Usually the message domain is the same as the package name.
|
||||
DOMAIN = $(PACKAGE)
|
||||
|
||||
# These two variables depend on the location of this directory.
|
||||
subdir = po
|
||||
top_builddir = ..
|
||||
|
||||
# These options get passed to xgettext.
|
||||
XGETTEXT_OPTIONS = --keyword=_ --keyword=N_ --keyword=P_:1,2
|
||||
|
||||
# This is the copyright holder that gets inserted into the header of the
|
||||
# $(DOMAIN).pot file. Translators are expected to disclaim their copyright.
|
||||
COPYRIGHT_HOLDER = Free Software Foundation, Inc.
|
||||
|
||||
# This is the list of locale categories, beyond LC_MESSAGES, for which the
|
||||
# message catalogs shall be used. It is usually empty.
|
||||
EXTRA_LOCALE_CATEGORIES =
|
||||
|
||||
# Don't do fuzzy matching when merging the PO files against the POT file.
|
||||
MSGMERGE_OPTIONS = --no-fuzzy-matching
|
19
po/POTFILES.in
Normal file
19
po/POTFILES.in
Normal file
|
@ -0,0 +1,19 @@
|
|||
# List of source files containing translatable strings.
|
||||
|
||||
src/browser.c
|
||||
src/color.c
|
||||
src/cut.c
|
||||
src/files.c
|
||||
src/global.c
|
||||
src/help.c
|
||||
src/history.c
|
||||
src/nanofur.c
|
||||
src/prompt.c
|
||||
src/rcfile.c
|
||||
src/search.c
|
||||
src/text.c
|
||||
src/utils.c
|
||||
src/winio.c
|
||||
|
||||
lib/getopt.c
|
||||
lib/regcomp.c
|
2978
po/nanofur.pot
Normal file
2978
po/nanofur.pot
Normal file
File diff suppressed because it is too large
Load diff
3151
po/pt_BR.po
Normal file
3151
po/pt_BR.po
Normal file
File diff suppressed because it is too large
Load diff
40
po/update_linguas.sh
Executable file
40
po/update_linguas.sh
Executable file
|
@ -0,0 +1,40 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Let this be executed in the po/ subdir.
|
||||
cd "$(dirname "$0")" || exit 1
|
||||
|
||||
echo "Updating translations via TP"
|
||||
# First remove existing PO files, as wget will not overwrite them.
|
||||
rm *.po
|
||||
wget --recursive --level=1 --accept=po --no-directories --no-verbose \
|
||||
https://translationproject.org/latest/nanofur/ || exit 2
|
||||
|
||||
# This PO file is less than twenty percent translated:
|
||||
rm -v nn.po
|
||||
|
||||
# Are there now PO files that are not in git yet?
|
||||
NEWSTUFF=$(git status --porcelain *.po | grep "^??")
|
||||
|
||||
if [ -n "${NEWSTUFF}" ]; then
|
||||
echo "New languages found; updating LINGUAS"
|
||||
echo "# List of available languages." >LINGUAS
|
||||
echo $(printf '%s\n' *.po | LC_ALL=C sort | sed 's/\.po//g') >>LINGUAS
|
||||
fi
|
||||
|
||||
echo "Regenerating POT file and remerging and recompiling PO files..."
|
||||
make update-po
|
||||
|
||||
echo "Removing the dead weight of obsolete and fuzzy translations..."
|
||||
for pofile in *.po; do
|
||||
msgattrib --no-obsolete --no-fuzzy $pofile >trimmed.po || exit 4
|
||||
mv trimmed.po $pofile || exit 4
|
||||
done
|
||||
echo
|
||||
|
||||
if grep "[[:cntrl:]]" ./*.po; then
|
||||
echo "*** PO file contains control character"; exit 5;
|
||||
fi
|
||||
|
||||
# If needed, fix a problem in the Makefile template.
|
||||
grep -q '^datarootdir' Makefile.in.in || \
|
||||
sed -i 's/^\(datadir.*\)/datarootdir = @datarootdir@\n\1/' Makefile.in.in
|
3092
po/zh_CN.po
Normal file
3092
po/zh_CN.po
Normal file
File diff suppressed because it is too large
Load diff
3095
po/zh_TW.po
Normal file
3095
po/zh_TW.po
Normal file
File diff suppressed because it is too large
Load diff
33
roll-a-release.sh
Executable file
33
roll-a-release.sh
Executable file
|
@ -0,0 +1,33 @@
|
|||
#!/bin/bash
|
||||
|
||||
VERSION="8.2"
|
||||
|
||||
./configure -C --enable-tiny && make && ./configure -C &&
|
||||
|
||||
echo "Running autogen..." && ./autogen.sh &&
|
||||
rm -v -f m4/*.m4~ *.asc *.sig *.gz *.xz &&
|
||||
|
||||
echo "Rebuilding..." && make &&
|
||||
po/update_linguas.sh &&
|
||||
|
||||
make distcheck && make dist-xz &&
|
||||
|
||||
git add po/*.po po/nanofur.pot po/LINGUAS &&
|
||||
git commit -m "$(git log -1 --grep 'po: up' | grep o: | sed 's/^ //')" &&
|
||||
|
||||
gpg -a -b nanofur-$VERSION.tar.gz &&
|
||||
gpg -a -b nanofur-$VERSION.tar.xz &&
|
||||
gpg --verify nanofur-$VERSION.tar.gz.asc &&
|
||||
gpg --verify nanofur-$VERSION.tar.xz.asc &&
|
||||
|
||||
git tag -u B8E1961F -a v$VERSION -m "the nanofur $VERSION release" &&
|
||||
|
||||
make pdf && rm -rf doc/nanofur.t2p &&
|
||||
scp doc/nanofur.pdf bens@wh0rd.org:nanofur.pdf &&
|
||||
scp doc/cheatsheet.html bens@wh0rd.org:cheatsheet.html &&
|
||||
|
||||
for file in nanofur-$VERSION.tar.*z*; do scp $file bens@wh0rd.org:$file; done &&
|
||||
|
||||
gnupload --to ftp.gnu.org:nanofur nanofur-$VERSION.tar.*z &&
|
||||
|
||||
echo "Tarballs have been rolled and uploaded."
|
12
script
Normal file
12
script
Normal file
|
@ -0,0 +1,12 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Find all files containing "nanofur" (case-insensitive) in the current directory and subdirectories
|
||||
find . -type f -iname '*nanofur*' | while read -r file; do
|
||||
# Construct the new file name by replacing "nanofur" with "nanofurfur" (case-insensitive)
|
||||
new_file=$(echo "$file" | sed -E 's/[Nn][Aa][Nn][Oo]/nanofurfur/g')
|
||||
# Rename the file
|
||||
mv "$file" "$new_file"
|
||||
done
|
||||
|
||||
echo "Renaming complete for all directories!"
|
||||
|
51
src/Makefile.am
Normal file
51
src/Makefile.am
Normal file
|
@ -0,0 +1,51 @@
|
|||
AM_CPPFLAGS = -DLOCALEDIR=\"$(localedir)\" -DSYSCONFDIR=\"$(sysconfdir)\" \
|
||||
-I$(top_builddir)/lib -I$(top_srcdir)/lib
|
||||
|
||||
CLEANFILES = revision.h
|
||||
|
||||
if BUILDING_FROM_GIT
|
||||
SOMETHING = "REVISION \"`git describe --tags 2>/dev/null`\""
|
||||
else
|
||||
SOMETHING = "PLAINBUILD \"from tarball\""
|
||||
endif
|
||||
|
||||
nanofur.o: revision.h
|
||||
winio.o: revision.h
|
||||
|
||||
# Always run the commands in this rule. But update the target
|
||||
# only when the revision actually changed.
|
||||
revision.h: FORCE
|
||||
@[ -f $@ ] || touch $@
|
||||
@! git describe >/dev/null 2>&1 || \
|
||||
echo "#define $(SOMETHING)" | cmp -s $@ - || \
|
||||
echo "#define $(SOMETHING)" > $@
|
||||
FORCE:
|
||||
|
||||
bin_PROGRAMS = nanofur
|
||||
nanofur_SOURCES = \
|
||||
definitions.h \
|
||||
prototypes.h \
|
||||
browser.c \
|
||||
chars.c \
|
||||
color.c \
|
||||
cut.c \
|
||||
files.c \
|
||||
global.c \
|
||||
help.c \
|
||||
history.c \
|
||||
move.c \
|
||||
nanofur.c \
|
||||
prompt.c \
|
||||
rcfile.c \
|
||||
search.c \
|
||||
text.c \
|
||||
utils.c \
|
||||
winio.c
|
||||
|
||||
nanofur_LDADD = @LIBINTL@ $(top_builddir)/lib/libgnu.a \
|
||||
$(GETRANDOM_LIB) $(CLOCK_TIME_LIB) $(LIBTHREAD)
|
||||
|
||||
install-exec-hook:
|
||||
cd $(DESTDIR)$(bindir) && rm -f rnanofur && $(LN_S) nanofur rnanofur
|
||||
uninstall-hook:
|
||||
cd $(DESTDIR)$(bindir) && rm -f rnanofur
|
707
src/browser.c
Normal file
707
src/browser.c
Normal file
|
@ -0,0 +1,707 @@
|
|||
/**************************************************************************
|
||||
* browser.c -- This file is part of GNU nanofur. *
|
||||
* *
|
||||
* Copyright (C) 2001-2011, 2013-2024 Free Software Foundation, Inc. *
|
||||
* Copyright (C) 2015-2016, 2020, 2022 Benno Schulenberg *
|
||||
* *
|
||||
* GNU nanofur 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. *
|
||||
* *
|
||||
* GNU nanofur 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 http://www.gnu.org/licenses/. *
|
||||
* *
|
||||
**************************************************************************/
|
||||
|
||||
#include "prototypes.h"
|
||||
|
||||
#ifdef ENABLE_BROWSER
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static char **filelist = NULL;
|
||||
/* The list of files to display in the file browser. */
|
||||
static size_t list_length = 0;
|
||||
/* The number of files in the list. */
|
||||
static size_t usable_rows = 0;
|
||||
/* The number of screen rows we can use to display the list. */
|
||||
static int piles = 0;
|
||||
/* The number of files that we can display per screen row. */
|
||||
static int gauge = 0;
|
||||
/* The width of a 'pile' -- the widest filename plus ten. */
|
||||
static size_t selected = 0;
|
||||
/* The currently selected filename in the list; zero-based. */
|
||||
|
||||
/* Fill 'filelist' with the names of the files in the given directory, set
|
||||
* 'list_length' to the number of names in that list, set 'gauge' to the
|
||||
* width of the widest filename plus ten, and set 'piles' to the number of
|
||||
* files that can be displayed per screen row. And sort the list too. */
|
||||
void read_the_list(const char *path, DIR *dir)
|
||||
{
|
||||
size_t path_len = strlen(path);
|
||||
const struct dirent *entry;
|
||||
size_t widest = 0;
|
||||
size_t index = 0;
|
||||
|
||||
/* Find the width of the widest filename in the current folder. */
|
||||
while ((entry = readdir(dir)) != NULL) {
|
||||
size_t span = breadth(entry->d_name);
|
||||
|
||||
if (span > widest)
|
||||
widest = span;
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
/* Reserve ten columns for blanks plus file size. */
|
||||
gauge = widest + 10;
|
||||
|
||||
/* If needed, make room for ".. (parent dir)". */
|
||||
if (gauge < 15)
|
||||
gauge = 15;
|
||||
/* Make sure we're not wider than the window. */
|
||||
if (gauge > COLS)
|
||||
gauge = COLS;
|
||||
|
||||
rewinddir(dir);
|
||||
|
||||
free_chararray(filelist, list_length);
|
||||
|
||||
list_length = index;
|
||||
index = 0;
|
||||
|
||||
filelist = nmalloc(list_length * sizeof(char *));
|
||||
|
||||
while ((entry = readdir(dir)) != NULL && index < list_length) {
|
||||
/* Don't show the useless dot item. */
|
||||
if (strcmp(entry->d_name, ".") == 0)
|
||||
continue;
|
||||
|
||||
filelist[index] = nmalloc(path_len + strlen(entry->d_name) + 1);
|
||||
sprintf(filelist[index], "%s%s", path, entry->d_name);
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
/* Maybe the number of files in the directory decreased between
|
||||
* the first time we scanned and the second time. */
|
||||
list_length = index;
|
||||
|
||||
/* Sort the list of names. */
|
||||
qsort(filelist, list_length, sizeof(char *), diralphasort);
|
||||
|
||||
/* Calculate how many files fit on a line -- feigning room for two
|
||||
* spaces beyond the right edge, and adding two spaces of padding
|
||||
* between columns. */
|
||||
piles = (COLS + 2) / (gauge + 2);
|
||||
|
||||
usable_rows = editwinrows - (ISSET(ZERO) && LINES > 1 ? 1 : 0);
|
||||
}
|
||||
|
||||
/* Reselect the given file or directory name, if it still exists. */
|
||||
void reselect(const char *name)
|
||||
{
|
||||
size_t looking_at = 0;
|
||||
|
||||
while (looking_at < list_length && strcmp(filelist[looking_at], name) != 0)
|
||||
looking_at++;
|
||||
|
||||
/* If the sought name was found, select it; otherwise, just move
|
||||
* the highlight so that the changed selection will be noticed,
|
||||
* but make sure to stay within the current available range. */
|
||||
if (looking_at < list_length)
|
||||
selected = looking_at;
|
||||
else if (selected > list_length)
|
||||
selected = list_length - 1;
|
||||
else
|
||||
--selected;
|
||||
}
|
||||
|
||||
/* Display at most a screenful of filenames from the gleaned filelist. */
|
||||
void browser_refresh(void)
|
||||
{
|
||||
int row = 0, col = 0;
|
||||
/* The current row and column while the list is getting displayed. */
|
||||
int the_row = 0, the_column = 0;
|
||||
/* The row and column of the selected item. */
|
||||
char *info;
|
||||
/* The additional information that we'll display about a file. */
|
||||
|
||||
titlebar(present_path);
|
||||
blank_edit();
|
||||
|
||||
for (size_t index = selected - selected % (usable_rows * piles);
|
||||
index < list_length && row < usable_rows; index++) {
|
||||
const char *thename = tail(filelist[index]);
|
||||
/* The filename we display, minus the path. */
|
||||
size_t namelen = breadth(thename);
|
||||
/* The length of the filename in columns. */
|
||||
size_t infolen;
|
||||
/* The length of the file information in columns. */
|
||||
size_t infomaxlen = 7;
|
||||
/* The maximum length of the file information in columns:
|
||||
* normally seven, but will be twelve for "(parent dir)". */
|
||||
bool dots = (COLS >= 15 && namelen >= gauge - infomaxlen);
|
||||
/* Whether to put an ellipsis before the filename? We don't
|
||||
* waste space on dots when there are fewer than 15 columns. */
|
||||
char *disp = display_string(thename, dots ?
|
||||
namelen + infomaxlen + 4 - gauge : 0, gauge, FALSE, FALSE);
|
||||
/* The filename (or a fragment of it) in displayable format.
|
||||
* When a fragment, account for dots plus one space padding. */
|
||||
struct stat state;
|
||||
|
||||
/* If this is the selected item, draw its highlighted bar upfront, and
|
||||
* remember its location to be able to place the cursor on it. */
|
||||
if (index == selected) {
|
||||
wattron(midwin, interface_color_pair[SELECTED_TEXT]);
|
||||
mvwprintw(midwin, row, col, "%*s", gauge, " ");
|
||||
the_row = row;
|
||||
the_column = col;
|
||||
}
|
||||
|
||||
/* If the name is too long, we display something like "...ename". */
|
||||
if (dots)
|
||||
mvwaddstr(midwin, row, col, "...");
|
||||
mvwaddstr(midwin, row, dots ? col + 3 : col, disp);
|
||||
|
||||
col += gauge;
|
||||
|
||||
/* Show information about the file: "--" for symlinks (except when
|
||||
* they point to a directory) and for files that have disappeared,
|
||||
* "(dir)" for directories, and the file size for normal files. */
|
||||
if (lstat(filelist[index], &state) == -1 || S_ISLNK(state.st_mode)) {
|
||||
if (stat(filelist[index], &state) == -1 || !S_ISDIR(state.st_mode))
|
||||
info = copy_of("--");
|
||||
else
|
||||
/* TRANSLATORS: Anything more than 7 cells gets clipped. */
|
||||
info = copy_of(_("(dir)"));
|
||||
} else if (S_ISDIR(state.st_mode)) {
|
||||
if (strcmp(thename, "..") == 0) {
|
||||
/* TRANSLATORS: Anything more than 12 cells gets clipped. */
|
||||
info = copy_of(_("(parent dir)"));
|
||||
infomaxlen = 12;
|
||||
} else
|
||||
info = copy_of(_("(dir)"));
|
||||
} else {
|
||||
off_t result = state.st_size;
|
||||
char modifier;
|
||||
|
||||
info = nmalloc(infomaxlen + 1);
|
||||
|
||||
/* Massage the file size into a human-readable form. */
|
||||
if (state.st_size < (1 << 10))
|
||||
modifier = ' '; /* bytes */
|
||||
else if (state.st_size < (1 << 20)) {
|
||||
result >>= 10;
|
||||
modifier = 'K'; /* kilobytes */
|
||||
} else if (state.st_size < (1 << 30)) {
|
||||
result >>= 20;
|
||||
modifier = 'M'; /* megabytes */
|
||||
} else {
|
||||
result >>= 30;
|
||||
modifier = 'G'; /* gigabytes */
|
||||
}
|
||||
|
||||
/* Show the size if less than a terabyte, else show "(huge)". */
|
||||
if (result < (1 << 10))
|
||||
sprintf(info, "%4ju %cB", (intmax_t)result, modifier);
|
||||
else
|
||||
/* TRANSLATORS: Anything more than 7 cells gets clipped.
|
||||
* If necessary, you can leave out the parentheses. */
|
||||
info = mallocstrcpy(info, _("(huge)"));
|
||||
}
|
||||
|
||||
/* Make sure info takes up no more than infomaxlen columns. */
|
||||
infolen = breadth(info);
|
||||
if (infolen > infomaxlen) {
|
||||
info[actual_x(info, infomaxlen)] = '\0';
|
||||
infolen = infomaxlen;
|
||||
}
|
||||
|
||||
mvwaddstr(midwin, row, col - infolen, info);
|
||||
|
||||
/* If this is the selected item, finish its highlighting. */
|
||||
if (index == selected)
|
||||
wattroff(midwin, interface_color_pair[SELECTED_TEXT]);
|
||||
|
||||
free(disp);
|
||||
free(info);
|
||||
|
||||
/* Add some space between the columns. */
|
||||
col += 2;
|
||||
|
||||
/* If the next item will not fit on this row, move to next row. */
|
||||
if (col > COLS - gauge) {
|
||||
row++;
|
||||
col = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* If requested, put the cursor on the selected item and switch it on. */
|
||||
if (ISSET(SHOW_CURSOR)) {
|
||||
wmove(midwin, the_row, the_column);
|
||||
curs_set(1);
|
||||
}
|
||||
|
||||
wnoutrefresh(midwin);
|
||||
}
|
||||
|
||||
/* Look for the given needle in the list of files, forwards or backwards. */
|
||||
void findfile(const char *needle, bool forwards)
|
||||
{
|
||||
size_t began_at = selected;
|
||||
|
||||
/* Iterate through the list of filenames, until a match is found or
|
||||
* we've come back to the point where we started. */
|
||||
while (TRUE) {
|
||||
if (forwards) {
|
||||
if (selected++ == list_length - 1) {
|
||||
selected = 0;
|
||||
statusbar(_("Search Wrapped"));
|
||||
}
|
||||
} else {
|
||||
if (selected-- == 0) {
|
||||
selected = list_length - 1;
|
||||
statusbar(_("Search Wrapped"));
|
||||
}
|
||||
}
|
||||
|
||||
/* When the needle occurs in the basename of the file, we have a match. */
|
||||
if (mbstrcasestr(tail(filelist[selected]), needle)) {
|
||||
if (selected == began_at)
|
||||
statusbar(_("This is the only occurrence"));
|
||||
return;
|
||||
}
|
||||
|
||||
/* When we're back at the starting point without any match... */
|
||||
if (selected == began_at) {
|
||||
not_found_msg(needle);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Prepare the prompt and ask the user what to search for; then search for it.
|
||||
* If forwards is TRUE, search forward in the list; otherwise, search backward. */
|
||||
void search_filename(bool forwards)
|
||||
{
|
||||
char *thedefault;
|
||||
int response;
|
||||
|
||||
/* If something was searched for before, show it between square brackets. */
|
||||
if (*last_search != '\0') {
|
||||
char *disp = display_string(last_search, 0, COLS / 3, FALSE, FALSE);
|
||||
|
||||
thedefault = nmalloc(strlen(disp) + 7);
|
||||
/* We use (COLS / 3) here because we need to see more on the line. */
|
||||
sprintf(thedefault, " [%s%s]", disp,
|
||||
(breadth(last_search) > COLS / 3) ? "..." : "");
|
||||
free(disp);
|
||||
} else
|
||||
thedefault = copy_of("");
|
||||
|
||||
/* Now ask what to search for. */
|
||||
response = do_prompt(MWHEREISFILE, "", &search_history,
|
||||
browser_refresh, "%s%s%s", _("Search"),
|
||||
/* TRANSLATORS: A modifier of the Search prompt. */
|
||||
!forwards ? _(" [Backwards]") : "", thedefault);
|
||||
free(thedefault);
|
||||
|
||||
/* If the user cancelled, or typed <Enter> on a blank answer and
|
||||
* nothing was searched for yet during this session, get out. */
|
||||
if (response == -1 || (response == -2 && *last_search == '\0')) {
|
||||
statusbar(_("Cancelled"));
|
||||
return;
|
||||
}
|
||||
|
||||
/* If the user typed an answer, remember it. */
|
||||
if (*answer != '\0') {
|
||||
last_search = mallocstrcpy(last_search, answer);
|
||||
#ifdef ENABLE_HISTORIES
|
||||
update_history(&search_history, answer, PRUNE_DUPLICATE);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (response == 0 || response == -2)
|
||||
findfile(last_search, forwards);
|
||||
}
|
||||
|
||||
/* Search again without prompting for the last given search string,
|
||||
* either forwards or backwards. */
|
||||
void research_filename(bool forwards)
|
||||
{
|
||||
#ifdef ENABLE_HISTORIES
|
||||
/* If nothing was searched for yet, take the last item from history. */
|
||||
if (*last_search == '\0' && searchbot->prev != NULL)
|
||||
last_search = mallocstrcpy(last_search, searchbot->prev->data);
|
||||
#endif
|
||||
|
||||
if (*last_search == '\0')
|
||||
statusbar(_("No current search pattern"));
|
||||
else {
|
||||
wipe_statusbar();
|
||||
findfile(last_search, forwards);
|
||||
}
|
||||
}
|
||||
|
||||
/* Select the first file in the list -- called by ^W^Y. */
|
||||
void to_first_file(void)
|
||||
{
|
||||
selected = 0;
|
||||
}
|
||||
|
||||
/* Select the last file in the list -- called by ^W^V. */
|
||||
void to_last_file(void)
|
||||
{
|
||||
selected = list_length - 1;
|
||||
}
|
||||
|
||||
/* Strip one element from the end of path, and return the stripped path.
|
||||
* The returned string is dynamically allocated, and should be freed. */
|
||||
char *strip_last_component(const char *path)
|
||||
{
|
||||
char *copy = copy_of(path);
|
||||
char *last_slash = strrchr(copy, '/');
|
||||
|
||||
if (last_slash != NULL)
|
||||
*last_slash = '\0';
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
/* Allow the user to browse through the directories in the filesystem,
|
||||
* starting at the given path. */
|
||||
char *browse(char *path)
|
||||
{
|
||||
char *present_name = NULL;
|
||||
/* The name of the currently selected file, or of the directory we
|
||||
* were in before backing up to "..". */
|
||||
size_t old_selected;
|
||||
/* The number of the selected file before the current selected file. */
|
||||
DIR *dir;
|
||||
/* The directory whose contents we are showing. */
|
||||
char *chosen = NULL;
|
||||
/* The name of the file that the user picked, or NULL if none. */
|
||||
|
||||
read_directory_contents:
|
||||
/* We come here when the user refreshes or selects a new directory. */
|
||||
|
||||
path = free_and_assign(path, get_full_path(path));
|
||||
|
||||
if (path != NULL)
|
||||
dir = opendir(path);
|
||||
|
||||
if (path == NULL || dir == NULL) {
|
||||
statusline(ALERT, _("Cannot open directory: %s"), strerror(errno));
|
||||
/* If we don't have a file list, there is nothing to show. */
|
||||
if (filelist == NULL) {
|
||||
lastmessage = VACUUM;
|
||||
free(present_name);
|
||||
free(path);
|
||||
napms(1200);
|
||||
return NULL;
|
||||
}
|
||||
path = mallocstrcpy(path, present_path);
|
||||
present_name = mallocstrcpy(present_name, filelist[selected]);
|
||||
}
|
||||
|
||||
if (dir != NULL) {
|
||||
/* Get the file list, and set gauge and piles in the process. */
|
||||
read_the_list(path, dir);
|
||||
closedir(dir);
|
||||
dir = NULL;
|
||||
}
|
||||
|
||||
/* If something was selected before, reselect it;
|
||||
* otherwise, just select the first item (..). */
|
||||
if (present_name != NULL) {
|
||||
reselect(present_name);
|
||||
free(present_name);
|
||||
present_name = NULL;
|
||||
} else
|
||||
selected = 0;
|
||||
|
||||
old_selected = (size_t)-1;
|
||||
|
||||
present_path = mallocstrcpy(present_path, path);
|
||||
|
||||
titlebar(path);
|
||||
|
||||
if (list_length == 0) {
|
||||
statusline(ALERT, _("No entries"));
|
||||
napms(1200);
|
||||
} else while (TRUE) {
|
||||
functionptrtype function;
|
||||
int kbinput;
|
||||
|
||||
lastmessage = VACUUM;
|
||||
|
||||
bottombars(MBROWSER);
|
||||
|
||||
/* Display (or redisplay) the file list if the list itself or
|
||||
* the selected file has changed. */
|
||||
if (old_selected != selected || ISSET(SHOW_CURSOR))
|
||||
browser_refresh();
|
||||
|
||||
old_selected = selected;
|
||||
|
||||
kbinput = get_kbinput(midwin, ISSET(SHOW_CURSOR));
|
||||
|
||||
#ifdef ENABLE_MOUSE
|
||||
if (kbinput == KEY_MOUSE) {
|
||||
int mouse_x, mouse_y;
|
||||
|
||||
/* When the user clicked in the file list, select a filename. */
|
||||
if (get_mouseinput(&mouse_y, &mouse_x, TRUE) == 0 &&
|
||||
wmouse_trafo(midwin, &mouse_y, &mouse_x, FALSE)) {
|
||||
selected = selected - selected % (usable_rows * piles) +
|
||||
(mouse_y * piles) + (mouse_x / (gauge + 2));
|
||||
|
||||
/* When beyond end-of-row, select the preceding filename. */
|
||||
if (mouse_x > piles * (gauge + 2))
|
||||
selected--;
|
||||
|
||||
/* When beyond end-of-list, select the last filename. */
|
||||
if (selected > list_length - 1)
|
||||
selected = list_length - 1;
|
||||
|
||||
/* When a filename is clicked a second time, choose it. */
|
||||
if (old_selected == selected)
|
||||
kbinput = KEY_ENTER;
|
||||
}
|
||||
|
||||
if (kbinput == KEY_MOUSE)
|
||||
continue;
|
||||
}
|
||||
#endif /* ENABLE_MOUSE */
|
||||
#ifndef NANOFUR_TINY
|
||||
while (bracketed_paste)
|
||||
kbinput = get_kbinput(midwin, BLIND);
|
||||
if (kbinput == BRACKETED_PASTE_MARKER) {
|
||||
beep();
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
function = interpret(kbinput);
|
||||
|
||||
if (function == do_help || function == full_refresh) {
|
||||
function();
|
||||
#ifndef NANOFUR_TINY
|
||||
/* Simulate a terminal resize to force a directory reread,
|
||||
* or because the terminal dimensions might have changed. */
|
||||
kbinput = THE_WINDOW_RESIZED;
|
||||
} else if (function == do_toggle && get_shortcut(kbinput)->toggle == NO_HELP) {
|
||||
TOGGLE(NO_HELP);
|
||||
window_init();
|
||||
kbinput = THE_WINDOW_RESIZED;
|
||||
#endif
|
||||
} else if (function == do_search_backward) {
|
||||
search_filename(BACKWARD);
|
||||
} else if (function == do_search_forward) {
|
||||
search_filename(FORWARD);
|
||||
} else if (function == do_findprevious) {
|
||||
research_filename(BACKWARD);
|
||||
} else if (function == do_findnext) {
|
||||
research_filename(FORWARD);
|
||||
} else if (function == do_left) {
|
||||
if (selected > 0)
|
||||
selected--;
|
||||
} else if (function == do_right) {
|
||||
if (selected < list_length - 1)
|
||||
selected++;
|
||||
} else if (function == to_prev_word) {
|
||||
selected -= (selected % piles);
|
||||
} else if (function == to_next_word) {
|
||||
selected += piles - 1 - (selected % piles);
|
||||
if (selected >= list_length)
|
||||
selected = list_length - 1;
|
||||
} else if (function == do_up) {
|
||||
if (selected >= piles)
|
||||
selected -= piles;
|
||||
} else if (function == do_down) {
|
||||
if (selected + piles <= list_length - 1)
|
||||
selected += piles;
|
||||
} else if (function == to_prev_block) {
|
||||
selected = ((selected / (usable_rows * piles)) * usable_rows * piles) +
|
||||
selected % piles;
|
||||
} else if (function == to_next_block) {
|
||||
selected = ((selected / (usable_rows * piles)) * usable_rows * piles) +
|
||||
selected % piles + usable_rows * piles - piles;
|
||||
if (selected >= list_length)
|
||||
selected = (list_length / piles) * piles + selected % piles;
|
||||
if (selected >= list_length)
|
||||
selected -= piles;
|
||||
} else if (function == do_page_up) {
|
||||
if (selected < piles)
|
||||
selected = 0;
|
||||
else if (selected < usable_rows * piles)
|
||||
selected = selected % piles;
|
||||
else
|
||||
selected -= usable_rows * piles;
|
||||
} else if (function == do_page_down) {
|
||||
if (selected + piles >= list_length - 1)
|
||||
selected = list_length - 1;
|
||||
else if (selected + usable_rows * piles >= list_length)
|
||||
selected = (selected + usable_rows * piles - list_length) % piles +
|
||||
list_length - piles;
|
||||
else
|
||||
selected += usable_rows * piles;
|
||||
} else if (function == to_first_file) {
|
||||
selected = 0;
|
||||
} else if (function == to_last_file) {
|
||||
selected = list_length - 1;
|
||||
} else if (function == goto_dir) {
|
||||
/* Ask for the directory to go to. */
|
||||
if (do_prompt(MGOTODIR, "", NULL,
|
||||
/* TRANSLATORS: This is a prompt. */
|
||||
browser_refresh, _("Go To Directory")) < 0) {
|
||||
statusbar(_("Cancelled"));
|
||||
continue;
|
||||
}
|
||||
|
||||
path = free_and_assign(path, real_dir_from_tilde(answer));
|
||||
|
||||
/* If the given path is relative, join it with the current path. */
|
||||
if (*path != '/') {
|
||||
path = nrealloc(path, strlen(present_path) + strlen(answer) + 1);
|
||||
sprintf(path, "%s%s", present_path, answer);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_OPERATINGDIR
|
||||
if (outside_of_confinement(path, FALSE)) {
|
||||
/* TRANSLATORS: This refers to the confining effect of
|
||||
* the option --operatingdir, not of --restricted. */
|
||||
statusline(ALERT, _("Can't go outside of %s"), operating_dir);
|
||||
path = mallocstrcpy(path, present_path);
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
/* Snip any trailing slashes, so the name can be compared. */
|
||||
while (strlen(path) > 1 && path[strlen(path) - 1] == '/')
|
||||
path[strlen(path) - 1] = '\0';
|
||||
|
||||
/* In case the specified directory cannot be entered, select it
|
||||
* (if it is in the current list) so it will be highlighted. */
|
||||
for (size_t j = 0; j < list_length; j++)
|
||||
if (strcmp(filelist[j], path) == 0)
|
||||
selected = j;
|
||||
|
||||
/* Try opening and reading the specified directory. */
|
||||
goto read_directory_contents;
|
||||
} else if (function == do_enter) {
|
||||
struct stat st;
|
||||
|
||||
/* It isn't possible to move up from the root directory. */
|
||||
if (strcmp(filelist[selected], "/..") == 0) {
|
||||
statusline(ALERT, _("Can't move up a directory"));
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_OPERATINGDIR
|
||||
/* Note: The selected file can be outside the operating
|
||||
* directory if it's ".." or if it's a symlink to a
|
||||
* directory outside the operating directory. */
|
||||
if (outside_of_confinement(filelist[selected], FALSE)) {
|
||||
statusline(ALERT, _("Can't go outside of %s"), operating_dir);
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
/* If for some reason the file is inaccessible, complain. */
|
||||
if (stat(filelist[selected], &st) == -1) {
|
||||
statusline(ALERT, _("Error reading %s: %s"),
|
||||
filelist[selected], strerror(errno));
|
||||
continue;
|
||||
}
|
||||
|
||||
/* If it isn't a directory, a file was selected -- we're done. */
|
||||
if (!S_ISDIR(st.st_mode)) {
|
||||
chosen = copy_of(filelist[selected]);
|
||||
break;
|
||||
}
|
||||
|
||||
/* If we are moving up one level, remember where we came from, so
|
||||
* this directory can be highlighted and easily reentered. */
|
||||
if (strcmp(tail(filelist[selected]), "..") == 0)
|
||||
present_name = strip_last_component(filelist[selected]);
|
||||
|
||||
/* Try opening and reading the selected directory. */
|
||||
path = mallocstrcpy(path, filelist[selected]);
|
||||
goto read_directory_contents;
|
||||
#ifdef ENABLE_NANOFURRC
|
||||
} else if (function == (functionptrtype)implant) {
|
||||
implant(first_sc_for(MBROWSER, function)->expansion);
|
||||
#endif
|
||||
#ifndef NANOFUR_TINY
|
||||
} else if (kbinput == THE_WINDOW_RESIZED) {
|
||||
; /* Gets handled below. */
|
||||
#endif
|
||||
} else if (function == do_exit) {
|
||||
break;
|
||||
} else
|
||||
unbound_key(kbinput);
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
/* If the terminal resized (or might have), refresh the file list. */
|
||||
if (kbinput == THE_WINDOW_RESIZED) {
|
||||
/* Remember the selected file, to be able to reselect it. */
|
||||
present_name = copy_of(filelist[selected]);
|
||||
goto read_directory_contents;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
titlebar(NULL);
|
||||
edit_refresh();
|
||||
|
||||
free(path);
|
||||
|
||||
free_chararray(filelist, list_length);
|
||||
filelist = NULL;
|
||||
list_length = 0;
|
||||
|
||||
return chosen;
|
||||
}
|
||||
|
||||
/* Prepare to start browsing. If the given path has a directory part,
|
||||
* start browsing in that directory, otherwise in the current directory. */
|
||||
char *browse_in(const char *inpath)
|
||||
{
|
||||
char *path = real_dir_from_tilde(inpath);
|
||||
struct stat fileinfo;
|
||||
|
||||
/* If path is not a directory, try to strip a filename from it; if then
|
||||
* still not a directory, use the current working directory instead. */
|
||||
if (stat(path, &fileinfo) == -1 || !S_ISDIR(fileinfo.st_mode)) {
|
||||
path = free_and_assign(path, strip_last_component(path));
|
||||
|
||||
if (stat(path, &fileinfo) == -1 || !S_ISDIR(fileinfo.st_mode)) {
|
||||
path = free_and_assign(path, realpath(".", NULL));
|
||||
|
||||
if (path == NULL) {
|
||||
statusline(ALERT, _("The working directory has disappeared"));
|
||||
napms(1200);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ENABLE_OPERATINGDIR
|
||||
/* If the resulting path isn't in the operating directory,
|
||||
* use the operating directory instead. */
|
||||
if (outside_of_confinement(path, FALSE))
|
||||
path = mallocstrcpy(path, operating_dir);
|
||||
#endif
|
||||
|
||||
return browse(path);
|
||||
}
|
||||
|
||||
#endif /* ENABLE_BROWSER */
|
665
src/chars.c
Normal file
665
src/chars.c
Normal file
|
@ -0,0 +1,665 @@
|
|||
/**************************************************************************
|
||||
* chars.c -- This file is part of GNU nanofur. *
|
||||
* *
|
||||
* Copyright (C) 2001-2011, 2013-2024 Free Software Foundation, Inc. *
|
||||
* Copyright (C) 2016-2021 Benno Schulenberg *
|
||||
* *
|
||||
* GNU nanofur 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. *
|
||||
* *
|
||||
* GNU nanofur 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 http://www.gnu.org/licenses/. *
|
||||
* *
|
||||
**************************************************************************/
|
||||
|
||||
#include "prototypes.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef ENABLE_UTF8
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
|
||||
static bool use_utf8 = FALSE;
|
||||
/* Whether we've enabled UTF-8 support. */
|
||||
|
||||
/* Enable UTF-8 support. */
|
||||
void utf8_init(void)
|
||||
{
|
||||
use_utf8 = TRUE;
|
||||
}
|
||||
|
||||
/* Is UTF-8 support enabled? */
|
||||
bool using_utf8(void)
|
||||
{
|
||||
return use_utf8;
|
||||
}
|
||||
#endif /* ENABLE_UTF8 */
|
||||
|
||||
#ifdef ENABLE_SPELLER
|
||||
/* Return TRUE when the given character is some kind of letter. */
|
||||
bool is_alpha_char(const char *c)
|
||||
{
|
||||
#ifdef ENABLE_UTF8
|
||||
wchar_t wc;
|
||||
|
||||
if (mbtowide(&wc, c) < 0)
|
||||
return FALSE;
|
||||
|
||||
return iswalpha(wc);
|
||||
#else
|
||||
return isalpha((unsigned char)*c);
|
||||
#endif
|
||||
}
|
||||
#endif /* ENABLE_SPELLER */
|
||||
|
||||
/* Return TRUE when the given character is some kind of letter or a digit. */
|
||||
bool is_alnum_char(const char *c)
|
||||
{
|
||||
#ifdef ENABLE_UTF8
|
||||
wchar_t wc;
|
||||
|
||||
if (mbtowide(&wc, c) < 0)
|
||||
return FALSE;
|
||||
|
||||
return iswalnum(wc);
|
||||
#else
|
||||
return isalnum((unsigned char)*c);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Return TRUE when the given character is space or tab or other whitespace. */
|
||||
bool is_blank_char(const char *c)
|
||||
{
|
||||
#ifdef ENABLE_UTF8
|
||||
wchar_t wc;
|
||||
|
||||
if ((signed char)*c >= 0)
|
||||
return (*c == ' ' || *c == '\t');
|
||||
|
||||
if (mbtowide(&wc, c) < 0)
|
||||
return FALSE;
|
||||
|
||||
return iswblank(wc);
|
||||
#else
|
||||
return isblank((unsigned char)*c);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Return TRUE when the given character is a control character. */
|
||||
bool is_cntrl_char(const char *c)
|
||||
{
|
||||
#ifdef ENABLE_UTF8
|
||||
if (use_utf8)
|
||||
return ((c[0] & 0xE0) == 0 || c[0] == DEL_CODE ||
|
||||
((signed char)c[0] == -62 && (signed char)c[1] < -96));
|
||||
else
|
||||
#endif
|
||||
return ((*c & 0x60) == 0 || *c == DEL_CODE);
|
||||
}
|
||||
|
||||
/* Return TRUE when the given character is a punctuation character. */
|
||||
bool is_punct_char(const char *c)
|
||||
{
|
||||
#ifdef ENABLE_UTF8
|
||||
wchar_t wc;
|
||||
|
||||
if (mbtowide(&wc, c) < 0)
|
||||
return FALSE;
|
||||
|
||||
return iswpunct(wc);
|
||||
#else
|
||||
return ispunct((unsigned char)*c);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Return TRUE when the given character is word-forming (it is alphanumeric or
|
||||
* specified in 'wordchars', or it is punctuation when allow_punct is TRUE). */
|
||||
bool is_word_char(const char *c, bool allow_punct)
|
||||
{
|
||||
if (*c == '\0')
|
||||
return FALSE;
|
||||
|
||||
if (is_alnum_char(c))
|
||||
return TRUE;
|
||||
|
||||
if (allow_punct && is_punct_char(c))
|
||||
return TRUE;
|
||||
|
||||
if (word_chars != NULL && *word_chars != '\0') {
|
||||
char symbol[MAXCHARLEN + 1];
|
||||
int symlen = collect_char(c, symbol);
|
||||
|
||||
symbol[symlen] = '\0';
|
||||
return (strstr(word_chars, symbol) != NULL);
|
||||
} else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Return the visible representation of control character c. */
|
||||
char control_rep(const signed char c)
|
||||
{
|
||||
if (c == DEL_CODE)
|
||||
return '?';
|
||||
else if (c == -97)
|
||||
return '=';
|
||||
else if (c < 0)
|
||||
return c + 224;
|
||||
else
|
||||
return c + 64;
|
||||
}
|
||||
|
||||
/* Return the visible representation of multibyte control character c. */
|
||||
char control_mbrep(const char *c, bool isdata)
|
||||
{
|
||||
/* An embedded newline is an encoded NUL if it is data. */
|
||||
if (*c == '\n' && (isdata || as_an_at))
|
||||
return '@';
|
||||
|
||||
#ifdef ENABLE_UTF8
|
||||
if (use_utf8) {
|
||||
if ((unsigned char)c[0] < 128)
|
||||
return control_rep(c[0]);
|
||||
else
|
||||
return control_rep(c[1]);
|
||||
} else
|
||||
#endif
|
||||
return control_rep(*c);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_UTF8
|
||||
/* Convert the given multibyte sequence c to wide character wc, and return
|
||||
* the number of bytes in the sequence, or -1 for an invalid sequence. */
|
||||
int mbtowide(wchar_t *wc, const char *c)
|
||||
{
|
||||
if ((signed char)*c < 0 && use_utf8) {
|
||||
unsigned char v1 = c[0];
|
||||
unsigned char v2 = c[1] ^ 0x80;
|
||||
|
||||
if (v2 > 0x3F || v1 < 0xC2)
|
||||
return -1;
|
||||
|
||||
if (v1 < 0xE0) {
|
||||
*wc = (((unsigned int)(v1 & 0x1F) << 6) | (unsigned int)v2);
|
||||
return 2;
|
||||
}
|
||||
|
||||
unsigned char v3 = c[2] ^ 0x80;
|
||||
|
||||
if (v3 > 0x3F)
|
||||
return -1;
|
||||
|
||||
if (v1 < 0xF0) {
|
||||
if ((v1 > 0xE0 || v2 >= 0x20) && (v1 != 0xED || v2 < 0x20)) {
|
||||
*wc = (((unsigned int)(v1 & 0x0F) << 12) |
|
||||
((unsigned int)v2 << 6) | (unsigned int)v3);
|
||||
return 3;
|
||||
} else
|
||||
return -1;
|
||||
}
|
||||
|
||||
unsigned char v4 = c[3] ^ 0x80;
|
||||
|
||||
if (v4 > 0x3F || v1 > 0xF4)
|
||||
return -1;
|
||||
|
||||
if ((v1 > 0xF0 || v2 >= 0x10) && (v1 != 0xF4 || v2 < 0x10)) {
|
||||
*wc = (((unsigned int)(v1 & 0x07) << 18) | ((unsigned int)v2 << 12) |
|
||||
((unsigned int)v3 << 6) | (unsigned int)v4);
|
||||
return 4;
|
||||
} else
|
||||
return -1;
|
||||
}
|
||||
|
||||
*wc = (unsigned int)*c;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Return TRUE when the given character occupies two cells. */
|
||||
bool is_doublewidth(const char *ch)
|
||||
{
|
||||
wchar_t wc;
|
||||
|
||||
/* Only from U+1100 can code points have double width. */
|
||||
if ((unsigned char)*ch < 0xE1 || !use_utf8)
|
||||
return FALSE;
|
||||
|
||||
if (mbtowide(&wc, ch) < 0)
|
||||
return FALSE;
|
||||
|
||||
return (wcwidth(wc) == 2);
|
||||
}
|
||||
|
||||
/* Return TRUE when the given character occupies zero cells. */
|
||||
bool is_zerowidth(const char *ch)
|
||||
{
|
||||
wchar_t wc;
|
||||
|
||||
/* Only from U+0300 can code points have zero width. */
|
||||
if ((unsigned char)*ch < 0xCC || !use_utf8)
|
||||
return FALSE;
|
||||
|
||||
if (mbtowide(&wc, ch) < 0)
|
||||
return FALSE;
|
||||
|
||||
#if defined(__OpenBSD__)
|
||||
/* Work around an OpenBSD bug -- see https://sv.gnu.org/bugs/?60393. */
|
||||
if (wc >= 0xF0000)
|
||||
return FALSE;
|
||||
#endif
|
||||
|
||||
return (wcwidth(wc) == 0);
|
||||
}
|
||||
#endif /* ENABLE_UTF8 */
|
||||
|
||||
/* Return the number of bytes in the character that starts at *pointer. */
|
||||
int char_length(const char *pointer)
|
||||
{
|
||||
#ifdef ENABLE_UTF8
|
||||
if ((unsigned char)*pointer > 0xC1 && use_utf8) {
|
||||
unsigned char c1 = pointer[0];
|
||||
unsigned char c2 = pointer[1];
|
||||
|
||||
if ((c2 ^ 0x80) > 0x3F)
|
||||
return 1;
|
||||
|
||||
if (c1 < 0xE0)
|
||||
return 2;
|
||||
|
||||
if (((unsigned char)pointer[2] ^ 0x80) > 0x3F)
|
||||
return 1;
|
||||
|
||||
if (c1 < 0xF0) {
|
||||
if ((c1 > 0xE0 || c2 >= 0xA0) && (c1 != 0xED || c2 < 0xA0))
|
||||
return 3;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (((unsigned char)pointer[3] ^ 0x80) > 0x3F)
|
||||
return 1;
|
||||
|
||||
if (c1 > 0xF4)
|
||||
return 1;
|
||||
|
||||
if ((c1 > 0xF0 || c2 >= 0x90) && (c1 != 0xF4 || c2 < 0x90))
|
||||
return 4;
|
||||
}
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Return the number of (multibyte) characters in the given string. */
|
||||
size_t mbstrlen(const char *pointer)
|
||||
{
|
||||
size_t count = 0;
|
||||
|
||||
while (*pointer != '\0') {
|
||||
pointer += char_length(pointer);
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/* Return the length (in bytes) of the character at the start of the
|
||||
* given string, and return a copy of this character in *thechar. */
|
||||
int collect_char(const char *string, char *thechar)
|
||||
{
|
||||
int charlen = char_length(string);
|
||||
|
||||
for (int i = 0; i < charlen; i++)
|
||||
thechar[i] = string[i];
|
||||
|
||||
return charlen;
|
||||
}
|
||||
|
||||
/* Return the length (in bytes) of the character at the start of
|
||||
* the given string, and add this character's width to *column. */
|
||||
int advance_over(const char *string, size_t *column)
|
||||
{
|
||||
#ifdef ENABLE_UTF8
|
||||
if ((signed char)*string < 0 && use_utf8) {
|
||||
/* A UTF-8 upper control code has two bytes and takes two columns. */
|
||||
if (((unsigned char)string[0] == 0xC2 && (signed char)string[1] < -96)) {
|
||||
*column += 2;
|
||||
return 2;
|
||||
} else {
|
||||
wchar_t wc;
|
||||
int charlen = mbtowide(&wc, string);
|
||||
|
||||
if (charlen < 0) {
|
||||
*column += 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int width = wcwidth(wc);
|
||||
|
||||
#if defined(__OpenBSD__)
|
||||
*column += (width < 0 || wc >= 0xF0000) ? 1 : width;
|
||||
#else
|
||||
*column += (width < 0) ? 1 : width;
|
||||
#endif
|
||||
return charlen;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((unsigned char)*string < 0x20) {
|
||||
if (*string == '\t')
|
||||
*column += tabsize - *column % tabsize;
|
||||
else
|
||||
*column += 2;
|
||||
} else if (0x7E < (unsigned char)*string && (unsigned char)*string < 0xA0)
|
||||
*column += 2;
|
||||
else
|
||||
*column += 1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Return the index in buf of the beginning of the multibyte character
|
||||
* before the one at pos. */
|
||||
size_t step_left(const char *buf, size_t pos)
|
||||
{
|
||||
#ifdef ENABLE_UTF8
|
||||
if (use_utf8) {
|
||||
size_t before, charlen = 0;
|
||||
|
||||
if (pos < 4)
|
||||
before = 0;
|
||||
else {
|
||||
const char *ptr = buf + pos;
|
||||
|
||||
/* Probe for a valid starter byte in the preceding four bytes. */
|
||||
if ((signed char)*(--ptr) > -65)
|
||||
before = pos - 1;
|
||||
else if ((signed char)*(--ptr) > -65)
|
||||
before = pos - 2;
|
||||
else if ((signed char)*(--ptr) > -65)
|
||||
before = pos - 3;
|
||||
else if ((signed char)*(--ptr) > -65)
|
||||
before = pos - 4;
|
||||
else
|
||||
before = pos - 1;
|
||||
}
|
||||
|
||||
/* Move forward again until we reach the original character,
|
||||
* so we know the length of its preceding character. */
|
||||
while (before < pos) {
|
||||
charlen = char_length(buf + before);
|
||||
before += charlen;
|
||||
}
|
||||
|
||||
return before - charlen;
|
||||
} else
|
||||
#endif
|
||||
return (pos == 0 ? 0 : pos - 1);
|
||||
}
|
||||
|
||||
/* Return the index in buf of the beginning of the multibyte character
|
||||
* after the one at pos. */
|
||||
size_t step_right(const char *buf, size_t pos)
|
||||
{
|
||||
return pos + char_length(buf + pos);
|
||||
}
|
||||
|
||||
/* This function is equivalent to strcasecmp() for multibyte strings. */
|
||||
int mbstrcasecmp(const char *s1, const char *s2)
|
||||
{
|
||||
return mbstrncasecmp(s1, s2, HIGHEST_POSITIVE);
|
||||
}
|
||||
|
||||
/* This function is equivalent to strncasecmp() for multibyte strings. */
|
||||
int mbstrncasecmp(const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
#ifdef ENABLE_UTF8
|
||||
if (use_utf8) {
|
||||
wchar_t wc1, wc2;
|
||||
|
||||
while (*s1 != '\0' && *s2 != '\0' && n > 0) {
|
||||
if ((signed char)*s1 >= 0 && (signed char)*s2 >= 0) {
|
||||
if ('A' <= (*s1 & 0x5F) && (*s1 & 0x5F) <= 'Z') {
|
||||
if ('A' <= (*s2 & 0x5F) && (*s2 & 0x5F) <= 'Z') {
|
||||
if ((*s1 & 0x5F) != (*s2 & 0x5F))
|
||||
return ((*s1 & 0x5F) - (*s2 & 0x5F));
|
||||
} else
|
||||
return ((*s1 | 0x20) - *s2);
|
||||
} else if ('A' <= (*s2 & 0x5F) && (*s2 & 0x5F) <= 'Z')
|
||||
return (*s1 - (*s2 | 0x20));
|
||||
else if (*s1 != *s2)
|
||||
return (*s1 - *s2);
|
||||
|
||||
s1++; s2++; n--;
|
||||
continue;
|
||||
}
|
||||
|
||||
bool bad1 = (mbtowide(&wc1, s1) < 0);
|
||||
bool bad2 = (mbtowide(&wc2, s2) < 0);
|
||||
|
||||
if (bad1 || bad2) {
|
||||
if (*s1 != *s2)
|
||||
return (unsigned char)*s1 - (unsigned char)*s2;
|
||||
|
||||
if (bad1 != bad2)
|
||||
return (bad1 ? 1 : -1);
|
||||
} else {
|
||||
int difference = towlower(wc1) - towlower(wc2);
|
||||
|
||||
if (difference != 0)
|
||||
return difference;
|
||||
}
|
||||
|
||||
s1 += char_length(s1);
|
||||
s2 += char_length(s2);
|
||||
n--;
|
||||
}
|
||||
|
||||
return (n > 0) ? ((unsigned char)*s1 - (unsigned char)*s2) : 0;
|
||||
} else
|
||||
#endif
|
||||
return strncasecmp(s1, s2, n);
|
||||
}
|
||||
|
||||
/* This function is equivalent to strcasestr() for multibyte strings. */
|
||||
char *mbstrcasestr(const char *haystack, const char *needle)
|
||||
{
|
||||
#ifdef ENABLE_UTF8
|
||||
if (use_utf8) {
|
||||
size_t needle_len = mbstrlen(needle);
|
||||
|
||||
while (*haystack != '\0') {
|
||||
if (mbstrncasecmp(haystack, needle, needle_len) == 0)
|
||||
return (char *)haystack;
|
||||
|
||||
haystack += char_length(haystack);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
} else
|
||||
#endif
|
||||
return (char *)strcasestr(haystack, needle);
|
||||
}
|
||||
|
||||
/* This function is equivalent to strstr(), except in that it scans the
|
||||
* string in reverse, starting at pointer. */
|
||||
char *revstrstr(const char *haystack, const char *needle,
|
||||
const char *pointer)
|
||||
{
|
||||
size_t needle_len = strlen(needle);
|
||||
size_t tail_len = strlen(pointer);
|
||||
|
||||
if (tail_len < needle_len)
|
||||
pointer -= (needle_len - tail_len);
|
||||
|
||||
while (pointer >= haystack) {
|
||||
if (strncmp(pointer, needle, needle_len) == 0)
|
||||
return (char *)pointer;
|
||||
pointer--;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* This function is equivalent to strcasestr(), except in that it scans
|
||||
* the string in reverse, starting at pointer. */
|
||||
char *revstrcasestr(const char *haystack, const char *needle,
|
||||
const char *pointer)
|
||||
{
|
||||
size_t needle_len = strlen(needle);
|
||||
size_t tail_len = strlen(pointer);
|
||||
|
||||
if (tail_len < needle_len)
|
||||
pointer -= (needle_len - tail_len);
|
||||
|
||||
while (pointer >= haystack) {
|
||||
if (strncasecmp(pointer, needle, needle_len) == 0)
|
||||
return (char *)pointer;
|
||||
pointer--;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* This function is equivalent to strcasestr() for multibyte strings,
|
||||
* except in that it scans the string in reverse, starting at pointer. */
|
||||
char *mbrevstrcasestr(const char *haystack, const char *needle,
|
||||
const char *pointer)
|
||||
{
|
||||
#ifdef ENABLE_UTF8
|
||||
if (use_utf8) {
|
||||
size_t needle_len = mbstrlen(needle);
|
||||
size_t tail_len = mbstrlen(pointer);
|
||||
|
||||
if (tail_len < needle_len)
|
||||
pointer -= (needle_len - tail_len);
|
||||
|
||||
if (pointer < haystack)
|
||||
return NULL;
|
||||
|
||||
while (TRUE) {
|
||||
if (mbstrncasecmp(pointer, needle, needle_len) == 0)
|
||||
return (char *)pointer;
|
||||
|
||||
if (pointer == haystack)
|
||||
return NULL;
|
||||
|
||||
pointer = haystack + step_left(haystack, pointer - haystack);
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
return revstrcasestr(haystack, needle, pointer);
|
||||
}
|
||||
|
||||
#if !defined(NANOFUR_TINY) || defined(ENABLE_JUSTIFY)
|
||||
/* This function is equivalent to strchr() for multibyte strings. */
|
||||
char *mbstrchr(const char *string, const char *chr)
|
||||
{
|
||||
#ifdef ENABLE_UTF8
|
||||
if (use_utf8) {
|
||||
bool bad_s = FALSE, bad_c = FALSE;
|
||||
wchar_t ws, wc;
|
||||
|
||||
if (mbtowide(&wc, chr) < 0) {
|
||||
wc = (unsigned char)*chr;
|
||||
bad_c = TRUE;
|
||||
}
|
||||
|
||||
while (*string != '\0') {
|
||||
int symlen = mbtowide(&ws, string);
|
||||
|
||||
if (symlen < 0) {
|
||||
ws = (unsigned char)*string;
|
||||
bad_s = TRUE;
|
||||
}
|
||||
|
||||
if (ws == wc && bad_s == bad_c)
|
||||
break;
|
||||
|
||||
string += symlen;
|
||||
}
|
||||
|
||||
if (*string == '\0')
|
||||
return NULL;
|
||||
|
||||
return (char *)string;
|
||||
} else
|
||||
#endif
|
||||
return strchr(string, *chr);
|
||||
}
|
||||
#endif /* !NANOFUR_TINY || ENABLE_JUSTIFY */
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
/* Locate, in the given string, the first occurrence of any of
|
||||
* the characters in accept, searching forward. */
|
||||
char *mbstrpbrk(const char *string, const char *accept)
|
||||
{
|
||||
while (*string != '\0') {
|
||||
if (mbstrchr(accept, string) != NULL)
|
||||
return (char *)string;
|
||||
|
||||
string += char_length(string);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Locate, in the string that starts at head, the first occurrence of any of
|
||||
* the characters in accept, starting from pointer and searching backwards. */
|
||||
char *mbrevstrpbrk(const char *head, const char *accept, const char *pointer)
|
||||
{
|
||||
if (*pointer == '\0') {
|
||||
if (pointer == head)
|
||||
return NULL;
|
||||
pointer = head + step_left(head, pointer - head);
|
||||
}
|
||||
|
||||
while (TRUE) {
|
||||
if (mbstrchr(accept, pointer) != NULL)
|
||||
return (char *)pointer;
|
||||
|
||||
/* If we've reached the head of the string, we found nothing. */
|
||||
if (pointer == head)
|
||||
return NULL;
|
||||
|
||||
pointer = head + step_left(head, pointer - head);
|
||||
}
|
||||
}
|
||||
#endif /* !NANOFUR_TINY */
|
||||
|
||||
#if defined(ENABLE_NANOFURRC) && (!defined(NANOFUR_TINY) || defined(ENABLE_JUSTIFY))
|
||||
/* Return TRUE if the given string contains at least one blank character. */
|
||||
bool has_blank_char(const char *string)
|
||||
{
|
||||
while (*string != '\0' && !is_blank_char(string))
|
||||
string += char_length(string);
|
||||
|
||||
return *string;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Return TRUE when the given string is empty or consists of only blanks. */
|
||||
bool white_string(const char *string)
|
||||
{
|
||||
while (*string != '\0' && (is_blank_char(string) || *string == '\r'))
|
||||
string += char_length(string);
|
||||
|
||||
return !*string;
|
||||
}
|
||||
|
||||
#if defined(ENABLE_SPELLER) || defined(ENABLE_COLOR)
|
||||
/* Remove leading whitespace from the given string. */
|
||||
void strip_leading_blanks_from(char *string)
|
||||
{
|
||||
while (string && (*string == ' ' || *string == '\t'))
|
||||
memmove(string, string + 1, strlen(string));
|
||||
}
|
||||
#endif
|
379
src/color.c
Normal file
379
src/color.c
Normal file
|
@ -0,0 +1,379 @@
|
|||
/**************************************************************************
|
||||
* color.c -- This file is part of GNU nanofur. *
|
||||
* *
|
||||
* Copyright (C) 2001-2011, 2013-2024 Free Software Foundation, Inc. *
|
||||
* Copyright (C) 2014-2017, 2020, 2021 Benno Schulenberg *
|
||||
* *
|
||||
* GNU nanofur 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. *
|
||||
* *
|
||||
* GNU nanofur 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 http://www.gnu.org/licenses/. *
|
||||
* *
|
||||
**************************************************************************/
|
||||
|
||||
#include "prototypes.h"
|
||||
|
||||
#ifdef ENABLE_COLOR
|
||||
|
||||
#include <errno.h>
|
||||
#ifdef HAVE_MAGIC_H
|
||||
#include <magic.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
|
||||
static bool defaults_allowed = FALSE;
|
||||
/* Whether ncurses accepts -1 to mean "default color". */
|
||||
|
||||
/* Initialize the color pairs for nanofur's interface. */
|
||||
void set_interface_colorpairs(void)
|
||||
{
|
||||
#ifdef HAVE_USE_DEFAULT_COLORS
|
||||
/* Ask ncurses to allow -1 to mean "default color". */
|
||||
defaults_allowed = (use_default_colors() == OK);
|
||||
#endif
|
||||
|
||||
/* Initialize the color pairs for nanofur's interface elements. */
|
||||
for (size_t index = 0; index < NUMBER_OF_ELEMENTS; index++) {
|
||||
colortype *combo = color_combo[index];
|
||||
|
||||
if (combo != NULL) {
|
||||
if (!defaults_allowed) {
|
||||
if (combo->fg == THE_DEFAULT)
|
||||
combo->fg = COLOR_WHITE;
|
||||
if (combo->bg == THE_DEFAULT)
|
||||
combo->bg = COLOR_BLACK;
|
||||
}
|
||||
init_pair(index + 1, combo->fg, combo->bg);
|
||||
interface_color_pair[index] = COLOR_PAIR(index + 1) | combo->attributes;
|
||||
rescind_colors = FALSE;
|
||||
} else {
|
||||
if (index == FUNCTION_TAG || index == SCROLL_BAR)
|
||||
interface_color_pair[index] = A_NORMAL;
|
||||
else if (index == GUIDE_STRIPE)
|
||||
interface_color_pair[index] = A_REVERSE;
|
||||
else if (index == SPOTLIGHTED) {
|
||||
init_pair(index + 1, COLOR_BLACK, COLOR_YELLOW + (COLORS > 15 ? 8 : 0));
|
||||
interface_color_pair[index] = COLOR_PAIR(index + 1);
|
||||
} else if (index == MINI_INFOBAR || index == PROMPT_BAR)
|
||||
interface_color_pair[index] = interface_color_pair[TITLE_BAR];
|
||||
else if (index == ERROR_MESSAGE) {
|
||||
init_pair(index + 1, COLOR_WHITE, COLOR_RED);
|
||||
interface_color_pair[index] = COLOR_PAIR(index + 1) | A_BOLD;
|
||||
} else
|
||||
interface_color_pair[index] = hilite_attribute;
|
||||
}
|
||||
|
||||
free(color_combo[index]);
|
||||
}
|
||||
|
||||
if (rescind_colors) {
|
||||
interface_color_pair[SPOTLIGHTED] = A_REVERSE;
|
||||
interface_color_pair[ERROR_MESSAGE] = A_REVERSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Assign a pair number to each of the foreground/background color combinations
|
||||
* in the given syntax, giving identical combinations the same number. */
|
||||
void set_syntax_colorpairs(syntaxtype *sntx)
|
||||
{
|
||||
short number = NUMBER_OF_ELEMENTS;
|
||||
colortype *older;
|
||||
|
||||
for (colortype *ink = sntx->color; ink != NULL; ink = ink->next) {
|
||||
if (!defaults_allowed) {
|
||||
if (ink->fg == THE_DEFAULT)
|
||||
ink->fg = COLOR_WHITE;
|
||||
if (ink->bg == THE_DEFAULT)
|
||||
ink->bg = COLOR_BLACK;
|
||||
}
|
||||
|
||||
older = sntx->color;
|
||||
|
||||
while (older != ink && (older->fg != ink->fg || older->bg != ink->bg))
|
||||
older = older->next;
|
||||
|
||||
ink->pairnum = (older != ink) ? older->pairnum : ++number;
|
||||
|
||||
ink->attributes |= COLOR_PAIR(ink->pairnum);
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialize the color pairs for the current syntax. */
|
||||
void prepare_palette(void)
|
||||
{
|
||||
short number = NUMBER_OF_ELEMENTS;
|
||||
|
||||
/* For each unique pair number, tell ncurses the combination of colors. */
|
||||
for (colortype *ink = openfile->syntax->color; ink != NULL; ink = ink->next)
|
||||
if (ink->pairnum > number) {
|
||||
init_pair(ink->pairnum, ink->fg, ink->bg);
|
||||
number = ink->pairnum;
|
||||
}
|
||||
|
||||
have_palette = TRUE;
|
||||
}
|
||||
|
||||
/* Try to match the given shibboleth string with one of the regexes in
|
||||
* the list starting at head. Return TRUE upon success. */
|
||||
bool found_in_list(regexlisttype *head, const char *shibboleth)
|
||||
{
|
||||
for (regexlisttype *item = head; item != NULL; item = item->next)
|
||||
if (regexec(item->one_rgx, shibboleth, 0, NULL, 0) == 0)
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Find a syntax that applies to the current buffer, based upon filename
|
||||
* or buffer content, and load and prime this syntax when needed. */
|
||||
void find_and_prime_applicable_syntax(void)
|
||||
{
|
||||
syntaxtype *sntx = NULL;
|
||||
|
||||
/* If the rcfiles were not read, or contained no syntaxes, get out. */
|
||||
if (syntaxes == NULL)
|
||||
return;
|
||||
|
||||
/* If we specified a syntax-override string, use it. */
|
||||
if (syntaxstr != NULL) {
|
||||
/* An override of "none" is like having no syntax at all. */
|
||||
if (strcmp(syntaxstr, "none") == 0)
|
||||
return;
|
||||
|
||||
for (sntx = syntaxes; sntx != NULL; sntx = sntx->next)
|
||||
if (strcmp(sntx->name, syntaxstr) == 0)
|
||||
break;
|
||||
|
||||
if (sntx == NULL && !inhelp)
|
||||
statusline(ALERT, _("Unknown syntax name: %s"), syntaxstr);
|
||||
}
|
||||
|
||||
/* If no syntax-override string was specified, or it didn't match,
|
||||
* try finding a syntax based on the filename (extension). */
|
||||
if (sntx == NULL && !inhelp) {
|
||||
char *fullname = get_full_path(openfile->filename);
|
||||
|
||||
if (fullname == NULL)
|
||||
fullname = mallocstrcpy(fullname, openfile->filename);
|
||||
|
||||
for (sntx = syntaxes; sntx != NULL; sntx = sntx->next)
|
||||
if (found_in_list(sntx->extensions, fullname))
|
||||
break;
|
||||
|
||||
free(fullname);
|
||||
}
|
||||
|
||||
/* If the filename didn't match anything, try the first line. */
|
||||
if (sntx == NULL && !inhelp) {
|
||||
for (sntx = syntaxes; sntx != NULL; sntx = sntx->next)
|
||||
if (found_in_list(sntx->headers, openfile->filetop->data))
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBMAGIC
|
||||
/* If we still don't have an answer, try using magic (when requested). */
|
||||
if (sntx == NULL && !inhelp && ISSET(USE_MAGIC)) {
|
||||
struct stat fileinfo;
|
||||
magic_t cookie = NULL;
|
||||
const char *magicstring = NULL;
|
||||
|
||||
if (stat(openfile->filename, &fileinfo) == 0) {
|
||||
/* Open the magic database and get a diagnosis of the file. */
|
||||
cookie = magic_open(MAGIC_SYMLINK |
|
||||
#ifdef DEBUG
|
||||
MAGIC_DEBUG | MAGIC_CHECK |
|
||||
#endif
|
||||
MAGIC_ERROR);
|
||||
if (cookie == NULL || magic_load(cookie, NULL) < 0)
|
||||
statusline(ALERT, _("magic_load() failed: %s"), strerror(errno));
|
||||
else {
|
||||
magicstring = magic_file(cookie, openfile->filename);
|
||||
if (magicstring == NULL)
|
||||
statusline(ALERT, _("magic_file(%s) failed: %s"),
|
||||
openfile->filename, magic_error(cookie));
|
||||
}
|
||||
}
|
||||
|
||||
/* Now try and find a syntax that matches the magic string. */
|
||||
if (magicstring != NULL) {
|
||||
for (sntx = syntaxes; sntx != NULL; sntx = sntx->next)
|
||||
if (found_in_list(sntx->magics, magicstring))
|
||||
break;
|
||||
}
|
||||
|
||||
if (stat(openfile->filename, &fileinfo) == 0)
|
||||
magic_close(cookie);
|
||||
}
|
||||
#endif /* HAVE_LIBMAGIC */
|
||||
|
||||
/* If nothing at all matched, see if there is a default syntax. */
|
||||
if (sntx == NULL && !inhelp) {
|
||||
for (sntx = syntaxes; sntx != NULL; sntx = sntx->next)
|
||||
if (strcmp(sntx->name, "default") == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
/* When the syntax isn't loaded yet, parse it and initialize its colors. */
|
||||
if (sntx != NULL && sntx->filename != NULL) {
|
||||
parse_one_include(sntx->filename, sntx);
|
||||
set_syntax_colorpairs(sntx);
|
||||
}
|
||||
|
||||
openfile->syntax = sntx;
|
||||
}
|
||||
|
||||
/* Determine whether the matches of multiline regexes are still the same,
|
||||
* and if not, schedule a screen refresh, so things will be repainted. */
|
||||
void check_the_multis(linestruct *line)
|
||||
{
|
||||
const colortype *ink;
|
||||
bool astart, anend;
|
||||
regmatch_t startmatch, endmatch;
|
||||
char *afterstart;
|
||||
|
||||
/* If there is no syntax or no multiline regex, there is nothing to do. */
|
||||
if (!openfile->syntax || openfile->syntax->multiscore == 0)
|
||||
return;
|
||||
|
||||
if (line->multidata == NULL) {
|
||||
refresh_needed = TRUE;
|
||||
return;
|
||||
}
|
||||
|
||||
for (ink = openfile->syntax->color; ink != NULL; ink = ink->next) {
|
||||
/* If it's not a multiline regex, skip. */
|
||||
if (ink->end == NULL)
|
||||
continue;
|
||||
|
||||
astart = (regexec(ink->start, line->data, 1, &startmatch, 0) == 0);
|
||||
afterstart = line->data + (astart ? startmatch.rm_eo : 0);
|
||||
anend = (regexec(ink->end, afterstart, 1, &endmatch, 0) == 0);
|
||||
|
||||
/* Check whether the multidata still matches the current situation. */
|
||||
if (line->multidata[ink->id] == NOTHING) {
|
||||
if (!astart)
|
||||
continue;
|
||||
} else if (line->multidata[ink->id] == WHOLELINE) {
|
||||
/* Ensure that a detected start match is not actually an end match. */
|
||||
if (!anend && (!astart || regexec(ink->end, line->data, 1,
|
||||
&endmatch, 0) != 0))
|
||||
continue;
|
||||
} else if (line->multidata[ink->id] == JUSTONTHIS) {
|
||||
if (astart && anend && regexec(ink->start, line->data + startmatch.rm_eo +
|
||||
endmatch.rm_eo, 1, &startmatch, 0) != 0)
|
||||
continue;
|
||||
} else if (line->multidata[ink->id] == STARTSHERE) {
|
||||
if (astart && !anend)
|
||||
continue;
|
||||
} else if (line->multidata[ink->id] == ENDSHERE) {
|
||||
if (!astart && anend)
|
||||
continue;
|
||||
}
|
||||
|
||||
/* There is a mismatch, so something changed: repaint. */
|
||||
refresh_needed = TRUE;
|
||||
perturbed = TRUE;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Precalculate the multi-line start and end regex info so we can
|
||||
* speed up rendering (with any hope at all...). */
|
||||
void precalc_multicolorinfo(void)
|
||||
{
|
||||
const colortype *ink;
|
||||
regmatch_t startmatch, endmatch;
|
||||
linestruct *line, *tailline;
|
||||
|
||||
if (!openfile->syntax || openfile->syntax->multiscore == 0 || ISSET(NO_SYNTAX))
|
||||
return;
|
||||
|
||||
//#define TIMEPRECALC 123
|
||||
#ifdef TIMEPRECALC
|
||||
#include <time.h>
|
||||
clock_t start = clock();
|
||||
#endif
|
||||
|
||||
/* For each line, allocate cache space for the multiline-regex info. */
|
||||
for (line = openfile->filetop; line != NULL; line = line->next)
|
||||
if (!line->multidata)
|
||||
line->multidata = nmalloc(openfile->syntax->multiscore * sizeof(short));
|
||||
|
||||
for (ink = openfile->syntax->color; ink != NULL; ink = ink->next) {
|
||||
/* If this is not a multi-line regex, skip it. */
|
||||
if (ink->end == NULL)
|
||||
continue;
|
||||
|
||||
for (line = openfile->filetop; line != NULL; line = line->next) {
|
||||
int index = 0;
|
||||
|
||||
/* Assume nothing applies until proven otherwise below. */
|
||||
line->multidata[ink->id] = NOTHING;
|
||||
|
||||
/* When the line contains a start match, look for an end,
|
||||
* and if found, mark all the lines that are affected. */
|
||||
while (regexec(ink->start, line->data + index, 1, &startmatch,
|
||||
(index == 0) ? 0 : REG_NOTBOL) == 0) {
|
||||
/* Begin looking for an end match after the start match. */
|
||||
index += startmatch.rm_eo;
|
||||
|
||||
/* If there is an end match on this same line, mark the line,
|
||||
* but continue looking for other starts after it. */
|
||||
if (regexec(ink->end, line->data + index, 1, &endmatch,
|
||||
(index == 0) ? 0 : REG_NOTBOL) == 0) {
|
||||
line->multidata[ink->id] = JUSTONTHIS;
|
||||
|
||||
index += endmatch.rm_eo;
|
||||
|
||||
/* If the total match has zero length, force an advance. */
|
||||
if (startmatch.rm_eo - startmatch.rm_so + endmatch.rm_eo == 0) {
|
||||
/* When at end-of-line, there is no other start. */
|
||||
if (line->data[index] == '\0')
|
||||
break;
|
||||
index = step_right(line->data, index);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Look for an end match on later lines. */
|
||||
tailline = line->next;
|
||||
|
||||
while (tailline && regexec(ink->end, tailline->data,
|
||||
1, &endmatch, 0) != 0)
|
||||
tailline = tailline->next;
|
||||
|
||||
line->multidata[ink->id] = STARTSHERE;
|
||||
|
||||
// Note that this also advances the line in the main loop.
|
||||
for (line = line->next; line != tailline; line = line->next)
|
||||
line->multidata[ink->id] = WHOLELINE;
|
||||
|
||||
if (tailline == NULL) {
|
||||
line = openfile->filebot;
|
||||
break;
|
||||
}
|
||||
|
||||
tailline->multidata[ink->id] = ENDSHERE;
|
||||
|
||||
/* Look for a possible new start after the end match. */
|
||||
index = endmatch.rm_eo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TIMEPRECALC
|
||||
statusline(INFO, "Precalculation: %.1f ms", 1000 * (double)(clock() - start) / CLOCKS_PER_SEC);
|
||||
napms(1200);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* ENABLE_COLOR */
|
785
src/cut.c
Normal file
785
src/cut.c
Normal file
|
@ -0,0 +1,785 @@
|
|||
/**************************************************************************
|
||||
* cut.c -- This file is part of GNU nanofur. *
|
||||
* *
|
||||
* Copyright (C) 1999-2011, 2013-2024 Free Software Foundation, Inc. *
|
||||
* Copyright (C) 2014 Mark Majeres *
|
||||
* Copyright (C) 2016, 2018-2020 Benno Schulenberg *
|
||||
* *
|
||||
* GNU nanofur 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. *
|
||||
* *
|
||||
* GNU nanofur 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 http://www.gnu.org/licenses/. *
|
||||
* *
|
||||
**************************************************************************/
|
||||
|
||||
#include "prototypes.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/* Delete the character at the current position, and
|
||||
* add or update an undo item for the given action. */
|
||||
void expunge(undo_type action)
|
||||
{
|
||||
openfile->placewewant = xplustabs();
|
||||
|
||||
/* When in the middle of a line, delete the current character. */
|
||||
if (openfile->current->data[openfile->current_x] != '\0') {
|
||||
int charlen = char_length(openfile->current->data + openfile->current_x);
|
||||
size_t line_len = strlen(openfile->current->data + openfile->current_x);
|
||||
#ifndef NANOFUR_TINY
|
||||
size_t old_amount = ISSET(SOFTWRAP) ? extra_chunks_in(openfile->current) : 0;
|
||||
|
||||
/* If the type of action changed or the cursor moved to a different
|
||||
* line, create a new undo item, otherwise update the existing item. */
|
||||
if (action != openfile->last_action ||
|
||||
openfile->current->lineno != openfile->current_undo->head_lineno)
|
||||
add_undo(action, NULL);
|
||||
else
|
||||
update_undo(action);
|
||||
#endif
|
||||
/* Move the remainder of the line "in", over the current character. */
|
||||
memmove(&openfile->current->data[openfile->current_x],
|
||||
&openfile->current->data[openfile->current_x + charlen],
|
||||
line_len - charlen + 1);
|
||||
#ifndef NANOFUR_TINY
|
||||
/* When softwrapping, a changed number of chunks requires a refresh. */
|
||||
if (ISSET(SOFTWRAP) && extra_chunks_in(openfile->current) != old_amount)
|
||||
refresh_needed = TRUE;
|
||||
|
||||
/* Adjust the mark if it is after the cursor on the current line. */
|
||||
if (openfile->mark == openfile->current &&
|
||||
openfile->mark_x > openfile->current_x)
|
||||
openfile->mark_x -= charlen;
|
||||
#endif
|
||||
/* Otherwise, when not at end of buffer, join this line with the next. */
|
||||
} else if (openfile->current != openfile->filebot) {
|
||||
linestruct *joining = openfile->current->next;
|
||||
|
||||
/* If there is a magic line, and we're before it: don't eat it. */
|
||||
if (joining == openfile->filebot && openfile->current_x != 0 &&
|
||||
!ISSET(NO_NEWLINES)) {
|
||||
#ifndef NANOFUR_TINY
|
||||
if (action == BACK)
|
||||
add_undo(BACK, NULL);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
add_undo(action, NULL);
|
||||
|
||||
/* Adjust the mark if it is on the line that will be "eaten". */
|
||||
if (openfile->mark == joining) {
|
||||
openfile->mark = openfile->current;
|
||||
openfile->mark_x += openfile->current_x;
|
||||
}
|
||||
|
||||
openfile->current->has_anchor |= joining->has_anchor;
|
||||
#endif
|
||||
/* Add the content of the next line to that of the current one. */
|
||||
openfile->current->data = nrealloc(openfile->current->data,
|
||||
strlen(openfile->current->data) + strlen(joining->data) + 1);
|
||||
strcat(openfile->current->data, joining->data);
|
||||
|
||||
unlink_node(joining);
|
||||
|
||||
/* Two lines were joined, so do a renumbering and refresh the screen. */
|
||||
renumber_from(openfile->current);
|
||||
refresh_needed = TRUE;
|
||||
} else
|
||||
/* We're at the end-of-file: nothing to do. */
|
||||
return;
|
||||
|
||||
#ifdef ENABLE_COLOR
|
||||
if (!refresh_needed)
|
||||
check_the_multis(openfile->current);
|
||||
#endif
|
||||
if (!refresh_needed)
|
||||
update_line(openfile->current, openfile->current_x);
|
||||
|
||||
/* Adjust the file size, and remember it for a possible redo. */
|
||||
openfile->totsize--;
|
||||
#ifndef NANOFUR_TINY
|
||||
openfile->current_undo->newsize = openfile->totsize;
|
||||
#endif
|
||||
set_modified();
|
||||
}
|
||||
|
||||
/* Delete the character under the cursor plus any succeeding zero-widths,
|
||||
* or, when the mark is on and --zap is active, delete the marked region. */
|
||||
void do_delete(void)
|
||||
{
|
||||
#ifndef NANOFUR_TINY
|
||||
if (openfile->mark && ISSET(LET_THEM_ZAP))
|
||||
zap_text();
|
||||
else
|
||||
#endif
|
||||
{
|
||||
expunge(DEL);
|
||||
#ifdef ENABLE_UTF8
|
||||
while (openfile->current->data[openfile->current_x] != '\0' &&
|
||||
is_zerowidth(openfile->current->data + openfile->current_x))
|
||||
expunge(DEL);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/* Backspace over one character. That is, move the cursor left one
|
||||
* character, and then delete the character under the cursor. Or,
|
||||
* when mark is on and --zap is active, delete the marked region. */
|
||||
void do_backspace(void)
|
||||
{
|
||||
#ifndef NANOFUR_TINY
|
||||
if (openfile->mark && ISSET(LET_THEM_ZAP))
|
||||
zap_text();
|
||||
else
|
||||
#endif
|
||||
if (openfile->current_x > 0) {
|
||||
openfile->current_x = step_left(openfile->current->data, openfile->current_x);
|
||||
expunge(BACK);
|
||||
} else if (openfile->current != openfile->filetop) {
|
||||
do_left();
|
||||
expunge(BACK);
|
||||
}
|
||||
}
|
||||
|
||||
/* Return FALSE when a cut command would not actually cut anything: when
|
||||
* on an empty line at EOF, or when the mark covers zero characters, or
|
||||
* (when test_cliff is TRUE) when the magic line would be cut. */
|
||||
bool is_cuttable(bool test_cliff)
|
||||
{
|
||||
size_t from = (test_cliff) ? openfile->current_x : 0;
|
||||
|
||||
if ((openfile->current->next == NULL && openfile->current->data[from] == '\0'
|
||||
#ifndef NANOFUR_TINY
|
||||
&& openfile->mark == NULL) ||
|
||||
(openfile->mark == openfile->current &&
|
||||
openfile->mark_x == openfile->current_x) ||
|
||||
(from > 0 && !ISSET(NO_NEWLINES) &&
|
||||
openfile->current->data[from] == '\0' &&
|
||||
openfile->current->next == openfile->filebot
|
||||
#endif
|
||||
)) {
|
||||
#ifndef NANOFUR_TINY
|
||||
statusbar(_("Nothing was cut"));
|
||||
openfile->mark = NULL;
|
||||
#endif
|
||||
return FALSE;
|
||||
} else
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
/* Delete text from the cursor until the first start of a word to
|
||||
* the left, or to the right when forward is TRUE. */
|
||||
void chop_word(bool forward)
|
||||
{
|
||||
/* Remember the current cursor position. */
|
||||
linestruct *is_current = openfile->current;
|
||||
size_t is_current_x = openfile->current_x;
|
||||
/* Remember where the cutbuffer is, then make it seem blank. */
|
||||
linestruct *is_cutbuffer = cutbuffer;
|
||||
|
||||
cutbuffer = NULL;
|
||||
|
||||
/* Move the cursor to a word start, to the left or to the right.
|
||||
* If that word is on another line and the cursor was not already
|
||||
* on the edge of the original line, then put the cursor on that
|
||||
* edge instead, so that lines will not be joined unexpectedly. */
|
||||
if (!forward) {
|
||||
do_prev_word();
|
||||
if (openfile->current != is_current) {
|
||||
if (is_current_x > 0) {
|
||||
openfile->current = is_current;
|
||||
openfile->current_x = 0;
|
||||
} else
|
||||
openfile->current_x = strlen(openfile->current->data);
|
||||
}
|
||||
} else {
|
||||
do_next_word(ISSET(AFTER_ENDS));
|
||||
if (openfile->current != is_current &&
|
||||
is_current->data[is_current_x] != '\0') {
|
||||
openfile->current = is_current;
|
||||
openfile->current_x = strlen(is_current->data);
|
||||
}
|
||||
}
|
||||
|
||||
/* Set the mark at the start of that word. */
|
||||
openfile->mark = openfile->current;
|
||||
openfile->mark_x = openfile->current_x;
|
||||
|
||||
/* Put the cursor back where it was, so an undo will put it there too. */
|
||||
openfile->current = is_current;
|
||||
openfile->current_x = is_current_x;
|
||||
|
||||
/* Now kill the marked region and a word is gone. */
|
||||
add_undo(CUT, NULL);
|
||||
do_snip(TRUE, FALSE, FALSE);
|
||||
update_undo(CUT);
|
||||
|
||||
/* Discard the cut word and restore the cutbuffer. */
|
||||
free_lines(cutbuffer);
|
||||
cutbuffer = is_cutbuffer;
|
||||
}
|
||||
|
||||
/* Delete a word leftward. */
|
||||
void chop_previous_word(void)
|
||||
{
|
||||
if (openfile->current->prev == NULL && openfile->current_x == 0)
|
||||
statusbar(_("Nothing was cut"));
|
||||
else
|
||||
chop_word(BACKWARD);
|
||||
}
|
||||
|
||||
/* Delete a word rightward. */
|
||||
void chop_next_word(void)
|
||||
{
|
||||
openfile->mark = NULL;
|
||||
|
||||
if (is_cuttable(TRUE))
|
||||
chop_word(FORWARD);
|
||||
}
|
||||
#endif /* !NANOFUR_TINY */
|
||||
|
||||
/* Excise the text between the given two points and add it to the cutbuffer. */
|
||||
void extract_segment(linestruct *top, size_t top_x, linestruct *bot, size_t bot_x)
|
||||
{
|
||||
linestruct *taken, *last;
|
||||
bool edittop_inside = (openfile->edittop->lineno >= top->lineno &&
|
||||
openfile->edittop->lineno <= bot->lineno);
|
||||
#ifndef NANOFUR_TINY
|
||||
bool same_line = (openfile->mark == top);
|
||||
bool post_marked = (openfile->mark && (openfile->mark->lineno > top->lineno ||
|
||||
(same_line && openfile->mark_x > top_x)));
|
||||
static bool inherited_anchor = FALSE;
|
||||
bool had_anchor = top->has_anchor;
|
||||
|
||||
if (top == bot && top_x == bot_x)
|
||||
return;
|
||||
|
||||
if (top != bot)
|
||||
for (linestruct *line = top->next; line != bot->next; line = line->next)
|
||||
had_anchor |= line->has_anchor;
|
||||
#endif
|
||||
|
||||
if (top == bot) {
|
||||
taken = make_new_node(NULL);
|
||||
taken->data = measured_copy(top->data + top_x, bot_x - top_x);
|
||||
memmove(top->data + top_x, top->data + bot_x, strlen(top->data + bot_x) + 1);
|
||||
last = taken;
|
||||
} else if (top_x == 0 && bot_x == 0) {
|
||||
taken = top;
|
||||
last = make_new_node(NULL);
|
||||
last->data = copy_of("");
|
||||
#ifndef NANOFUR_TINY
|
||||
last->has_anchor = bot->has_anchor;
|
||||
#endif
|
||||
last->prev = bot->prev;
|
||||
bot->prev->next = last;
|
||||
last->next = NULL;
|
||||
|
||||
bot->prev = top->prev;
|
||||
if (top->prev)
|
||||
top->prev->next = bot;
|
||||
else
|
||||
openfile->filetop = bot;
|
||||
|
||||
openfile->current = bot;
|
||||
} else {
|
||||
taken = make_new_node(NULL);
|
||||
taken->data = copy_of(top->data + top_x);
|
||||
taken->next = top->next;
|
||||
top->next->prev = taken;
|
||||
|
||||
top->next = bot->next;
|
||||
if (bot->next)
|
||||
bot->next->prev = top;
|
||||
|
||||
top->data = nrealloc(top->data, top_x + strlen(bot->data + bot_x) + 1);
|
||||
strcpy(top->data + top_x, bot->data + bot_x);
|
||||
|
||||
last = bot;
|
||||
last->data[bot_x] = '\0';
|
||||
last->next = NULL;
|
||||
|
||||
openfile->current = top;
|
||||
}
|
||||
|
||||
/* Subtract the size of the excised text from the buffer size. */
|
||||
openfile->totsize -= number_of_characters_in(taken, last);
|
||||
|
||||
/* If the cutbuffer is currently empty, just move all the text directly
|
||||
* into it; otherwise, append the text to what is already there. */
|
||||
if (cutbuffer == NULL) {
|
||||
cutbuffer = taken;
|
||||
cutbottom = last;
|
||||
#ifndef NANOFUR_TINY
|
||||
inherited_anchor = taken->has_anchor;
|
||||
#endif
|
||||
} else {
|
||||
cutbottom->data = nrealloc(cutbottom->data,
|
||||
strlen(cutbottom->data) + strlen(taken->data) + 1);
|
||||
strcat(cutbottom->data, taken->data);
|
||||
#ifndef NANOFUR_TINY
|
||||
cutbottom->has_anchor = taken->has_anchor && !inherited_anchor;
|
||||
inherited_anchor |= taken->has_anchor;
|
||||
#endif
|
||||
cutbottom->next = taken->next;
|
||||
delete_node(taken);
|
||||
|
||||
if (cutbottom->next != NULL) {
|
||||
cutbottom->next->prev = cutbottom;
|
||||
cutbottom = last;
|
||||
}
|
||||
}
|
||||
|
||||
openfile->current_x = top_x;
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
openfile->current->has_anchor = had_anchor;
|
||||
|
||||
if (post_marked || same_line)
|
||||
openfile->mark = openfile->current;
|
||||
if (post_marked)
|
||||
openfile->mark_x = openfile->current_x;
|
||||
#endif
|
||||
if (openfile->filebot == bot)
|
||||
openfile->filebot = openfile->current;
|
||||
|
||||
renumber_from(openfile->current);
|
||||
|
||||
/* When the beginning of the viewport was inside the excision, adjust. */
|
||||
if (edittop_inside) {
|
||||
adjust_viewport(STATIONARY);
|
||||
refresh_needed = TRUE;
|
||||
}
|
||||
|
||||
/* If the text doesn't end with a newline, and it should, add one. */
|
||||
if (!ISSET(NO_NEWLINES) && openfile->filebot->data[0] != '\0')
|
||||
new_magicline();
|
||||
}
|
||||
|
||||
/* Meld the buffer that starts at topline into the current file buffer
|
||||
* at the current cursor position. */
|
||||
void ingraft_buffer(linestruct *topline)
|
||||
{
|
||||
linestruct *line = openfile->current;
|
||||
size_t length = strlen(line->data);
|
||||
size_t extralen = strlen(topline->data);
|
||||
size_t xpos = openfile->current_x;
|
||||
char *tailtext = copy_of(line->data + xpos);
|
||||
#ifndef NANOFUR_TINY
|
||||
bool mark_follows = (openfile->mark == line && !mark_is_before_cursor());
|
||||
#endif
|
||||
linestruct *botline = topline;
|
||||
|
||||
while (botline->next != NULL)
|
||||
botline = botline->next;
|
||||
|
||||
/* Add the size of the text to be grafted to the buffer size. */
|
||||
openfile->totsize += number_of_characters_in(topline, botline);
|
||||
|
||||
if (topline != botline)
|
||||
length = xpos;
|
||||
|
||||
if (extralen > 0) {
|
||||
/* Insert the text of topline at the current cursor position. */
|
||||
line->data = nrealloc(line->data, length + extralen + 1);
|
||||
memmove(line->data + xpos + extralen, line->data + xpos, length - xpos + 1);
|
||||
strncpy(line->data + xpos, topline->data, extralen);
|
||||
}
|
||||
|
||||
if (topline != botline) {
|
||||
/* When inserting at end-of-buffer, update the relevant pointer. */
|
||||
if (line->next == NULL)
|
||||
openfile->filebot = botline;
|
||||
|
||||
line->data[xpos + extralen] = '\0';
|
||||
|
||||
/* Hook the grafted lines in after the current one. */
|
||||
botline->next = openfile->current->next;
|
||||
if (botline->next)
|
||||
botline->next->prev = botline;
|
||||
openfile->current->next = topline->next;
|
||||
topline->next->prev = openfile->current;
|
||||
|
||||
/* Add the text after the cursor position at the end of botline. */
|
||||
length = strlen(botline->data);
|
||||
extralen = strlen(tailtext);
|
||||
botline->data = nrealloc(botline->data, length + extralen + 1);
|
||||
strcpy(botline->data + length, tailtext);
|
||||
|
||||
/* Put the cursor at the end of the grafted text. */
|
||||
openfile->current = botline;
|
||||
openfile->current_x = length;
|
||||
} else
|
||||
openfile->current_x += extralen;
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
/* When needed, update the mark's pointer and position. */
|
||||
if (mark_follows && topline != botline) {
|
||||
openfile->mark = botline;
|
||||
openfile->mark_x += length - xpos;
|
||||
} else if (mark_follows)
|
||||
openfile->mark_x += extralen;
|
||||
#endif
|
||||
|
||||
delete_node(topline);
|
||||
free(tailtext);
|
||||
|
||||
renumber_from(line);
|
||||
|
||||
/* If the text doesn't end with a newline, and it should, add one. */
|
||||
if (!ISSET(NO_NEWLINES) && openfile->filebot->data[0] != '\0')
|
||||
new_magicline();
|
||||
}
|
||||
|
||||
/* Meld a copy of the given buffer into the current file buffer. */
|
||||
void copy_from_buffer(linestruct *somebuffer)
|
||||
{
|
||||
#ifdef ENABLE_COLOR
|
||||
size_t threshold = openfile->edittop->lineno + editwinrows - 1;
|
||||
#endif
|
||||
linestruct *the_copy = copy_buffer(somebuffer);
|
||||
|
||||
ingraft_buffer(the_copy);
|
||||
|
||||
#ifdef ENABLE_COLOR
|
||||
if (openfile->current->lineno > threshold || ISSET(SOFTWRAP))
|
||||
recook = TRUE;
|
||||
else
|
||||
perturbed = TRUE;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
/* Move all marked text from the current buffer into the cutbuffer. */
|
||||
void cut_marked_region(void)
|
||||
{
|
||||
linestruct *top, *bot;
|
||||
size_t top_x, bot_x;
|
||||
|
||||
get_region(&top, &top_x, &bot, &bot_x);
|
||||
|
||||
extract_segment(top, top_x, bot, bot_x);
|
||||
|
||||
openfile->placewewant = xplustabs();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Move text from the current buffer into the cutbuffer.
|
||||
* If until_eof is TRUE, move all text from the current cursor
|
||||
* position to the end of the file into the cutbuffer. If append
|
||||
* is TRUE (when zapping), always append the cut to the cutbuffer. */
|
||||
void do_snip(bool marked, bool until_eof, bool append)
|
||||
{
|
||||
linestruct *line = openfile->current;
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
keep_cutbuffer &= (openfile->last_action != COPY);
|
||||
#endif
|
||||
|
||||
/* If cuts were not continuous, or when cutting a region, clear the slate. */
|
||||
if ((marked || until_eof || !keep_cutbuffer) && !append) {
|
||||
free_lines(cutbuffer);
|
||||
cutbuffer = NULL;
|
||||
}
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
/* Now move the relevant piece of text into the cutbuffer. */
|
||||
if (until_eof)
|
||||
extract_segment(openfile->current, openfile->current_x,
|
||||
openfile->filebot, strlen(openfile->filebot->data));
|
||||
else if (openfile->mark) {
|
||||
cut_marked_region();
|
||||
openfile->mark = NULL;
|
||||
} else if (ISSET(CUT_FROM_CURSOR)) {
|
||||
/* When not at the end of a line, move the rest of this line into
|
||||
* the cutbuffer. Otherwise, when not at the end of the buffer,
|
||||
* move just the "line separator" into the cutbuffer. */
|
||||
if (line->data[openfile->current_x] != '\0')
|
||||
extract_segment(line, openfile->current_x, line, strlen(line->data));
|
||||
else if (openfile->current != openfile->filebot) {
|
||||
extract_segment(line, openfile->current_x, line->next, 0);
|
||||
openfile->placewewant = xplustabs();
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
/* When not at end-of-buffer, move one full line into the cutbuffer;
|
||||
* otherwise, move all text until end-of-line into the cutbuffer. */
|
||||
if (openfile->current != openfile->filebot)
|
||||
extract_segment(line, 0, line->next, 0);
|
||||
else
|
||||
extract_segment(line, 0, line, strlen(line->data));
|
||||
|
||||
openfile->placewewant = 0;
|
||||
}
|
||||
|
||||
/* After a line operation, future ones should add to the cutbuffer. */
|
||||
keep_cutbuffer = !marked && !until_eof;
|
||||
|
||||
set_modified();
|
||||
refresh_needed = TRUE;
|
||||
#ifdef ENABLE_COLOR
|
||||
perturbed = TRUE;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Move text from the current buffer into the cutbuffer. */
|
||||
void cut_text(void)
|
||||
{
|
||||
#ifndef NANOFUR_TINY
|
||||
if (!is_cuttable(ISSET(CUT_FROM_CURSOR) && openfile->mark == NULL))
|
||||
return;
|
||||
|
||||
/* Only add a new undo item when the current item is not a CUT or when
|
||||
* the current cut is not contiguous with the previous cutting. */
|
||||
if (openfile->last_action != CUT || !keep_cutbuffer) {
|
||||
keep_cutbuffer = FALSE;
|
||||
add_undo(CUT, NULL);
|
||||
}
|
||||
|
||||
do_snip(openfile->mark != NULL, FALSE, FALSE);
|
||||
|
||||
update_undo(CUT);
|
||||
#else
|
||||
if (is_cuttable(FALSE))
|
||||
do_snip(FALSE, FALSE, FALSE);
|
||||
#endif
|
||||
wipe_statusbar();
|
||||
}
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
/* Cut from the current cursor position to the end of the file. */
|
||||
void cut_till_eof(void)
|
||||
{
|
||||
ran_a_tool = TRUE;
|
||||
|
||||
if (openfile->current->data[openfile->current_x] == '\0' &&
|
||||
(openfile->current->next == NULL ||
|
||||
(!ISSET(NO_NEWLINES) && openfile->current_x > 0 &&
|
||||
openfile->current->next == openfile->filebot))) {
|
||||
statusbar(_("Nothing was cut"));
|
||||
return;
|
||||
}
|
||||
|
||||
add_undo(CUT_TO_EOF, NULL);
|
||||
do_snip(FALSE, TRUE, FALSE);
|
||||
update_undo(CUT_TO_EOF);
|
||||
wipe_statusbar();
|
||||
}
|
||||
|
||||
/* Erase text (current line or marked region), sending it into oblivion. */
|
||||
void zap_text(void)
|
||||
{
|
||||
/* Remember the current cutbuffer so it can be restored after the zap. */
|
||||
linestruct *was_cutbuffer = cutbuffer;
|
||||
|
||||
if (!is_cuttable(ISSET(CUT_FROM_CURSOR) && openfile->mark == NULL))
|
||||
return;
|
||||
|
||||
/* Add a new undo item only when the current item is not a ZAP or when
|
||||
* the current zap is not contiguous with the previous zapping. */
|
||||
if (openfile->last_action != ZAP || !keep_cutbuffer)
|
||||
add_undo(ZAP, NULL);
|
||||
|
||||
/* Use the cutbuffer from the ZAP undo item, so the cut can be undone. */
|
||||
cutbuffer = openfile->current_undo->cutbuffer;
|
||||
|
||||
do_snip(openfile->mark != NULL, FALSE, TRUE);
|
||||
|
||||
update_undo(ZAP);
|
||||
wipe_statusbar();
|
||||
|
||||
cutbuffer = was_cutbuffer;
|
||||
}
|
||||
|
||||
/* Make a copy of the marked region, putting it in the cutbuffer. */
|
||||
void copy_marked_region(void)
|
||||
{
|
||||
linestruct *topline, *botline, *afterline;
|
||||
char *was_datastart, saved_byte;
|
||||
size_t top_x, bot_x;
|
||||
|
||||
get_region(&topline, &top_x, &botline, &bot_x);
|
||||
|
||||
openfile->last_action = OTHER;
|
||||
keep_cutbuffer = FALSE;
|
||||
openfile->mark = NULL;
|
||||
refresh_needed = TRUE;
|
||||
|
||||
if (topline == botline && top_x == bot_x) {
|
||||
statusbar(_("Copied nothing"));
|
||||
return;
|
||||
}
|
||||
|
||||
/* Make the area that was marked look like a separate buffer. */
|
||||
afterline = botline->next;
|
||||
botline->next = NULL;
|
||||
saved_byte = botline->data[bot_x];
|
||||
botline->data[bot_x] = '\0';
|
||||
was_datastart = topline->data;
|
||||
topline->data += top_x;
|
||||
|
||||
cutbuffer = copy_buffer(topline);
|
||||
|
||||
/* Restore the proper state of the buffer. */
|
||||
topline->data = was_datastart;
|
||||
botline->data[bot_x] = saved_byte;
|
||||
botline->next = afterline;
|
||||
}
|
||||
#endif /* !NANOFUR_TINY */
|
||||
|
||||
/* Copy text from the current buffer into the cutbuffer. The text is either
|
||||
* the marked region, the whole line, the text from cursor to end-of-line,
|
||||
* just the line break, or nothing, depending on mode and cursor position. */
|
||||
void copy_text(void)
|
||||
{
|
||||
bool at_eol = (openfile->current->data[openfile->current_x] == '\0');
|
||||
bool sans_newline = (ISSET(NO_NEWLINES) && openfile->current->next == NULL);
|
||||
size_t from_x = (ISSET(CUT_FROM_CURSOR)) ? openfile->current_x : 0;
|
||||
linestruct *was_current = openfile->current;
|
||||
linestruct *addition;
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
if (openfile->mark || openfile->last_action != COPY)
|
||||
keep_cutbuffer = FALSE;
|
||||
#endif
|
||||
|
||||
if (!keep_cutbuffer) {
|
||||
free_lines(cutbuffer);
|
||||
cutbuffer = NULL;
|
||||
}
|
||||
|
||||
wipe_statusbar();
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
if (openfile->mark) {
|
||||
copy_marked_region();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* When at the very end of the buffer, there is nothing to do. */
|
||||
if (openfile->current->next == NULL && at_eol && (ISSET(CUT_FROM_CURSOR) ||
|
||||
openfile->current_x == 0 || cutbuffer)) {
|
||||
statusbar(_("Copied nothing"));
|
||||
return;
|
||||
}
|
||||
|
||||
addition = make_new_node(NULL);
|
||||
addition->data = copy_of(openfile->current->data + from_x);
|
||||
|
||||
if (ISSET(CUT_FROM_CURSOR))
|
||||
sans_newline = !at_eol;
|
||||
|
||||
/* Create the cutbuffer OR add to it, depending on the mode, the position
|
||||
* of the cursor, and whether or not the cutbuffer is currently empty. */
|
||||
if (cutbuffer == NULL && sans_newline) {
|
||||
cutbuffer = addition;
|
||||
cutbottom = addition;
|
||||
} else if (cutbuffer == NULL) {
|
||||
cutbuffer = addition;
|
||||
cutbottom = make_new_node(cutbuffer);
|
||||
cutbottom->data = copy_of("");
|
||||
cutbuffer->next = cutbottom;
|
||||
} else if (sans_newline) {
|
||||
addition->prev = cutbottom->prev;
|
||||
addition->prev->next = addition;
|
||||
delete_node(cutbottom);
|
||||
cutbottom = addition;
|
||||
} else if (ISSET(CUT_FROM_CURSOR)) {
|
||||
addition->prev = cutbottom;
|
||||
cutbottom->next = addition;
|
||||
cutbottom = addition;
|
||||
} else {
|
||||
addition->prev = cutbottom->prev;
|
||||
addition->prev->next = addition;
|
||||
addition->next = cutbottom;
|
||||
cutbottom->prev = addition;
|
||||
}
|
||||
|
||||
/* When needed and possible, move the cursor to the next line. */
|
||||
if ((!ISSET(CUT_FROM_CURSOR) || at_eol) && openfile->current->next) {
|
||||
openfile->current = openfile->current->next;
|
||||
openfile->current_x = 0;
|
||||
} else
|
||||
openfile->current_x = strlen(openfile->current->data);
|
||||
|
||||
edit_redraw(was_current, FLOWING);
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
openfile->last_action = COPY;
|
||||
#endif
|
||||
keep_cutbuffer = TRUE;
|
||||
}
|
||||
|
||||
/* Copy text from the cutbuffer into the current buffer. */
|
||||
void paste_text(void)
|
||||
{
|
||||
#if defined(ENABLE_WRAPPING) || !defined(NANOFUR_TINY)
|
||||
/* Remember where the paste started. */
|
||||
linestruct *was_current = openfile->current;
|
||||
#endif
|
||||
#ifndef NANOFUR_TINY
|
||||
bool had_anchor = was_current->has_anchor;
|
||||
#endif
|
||||
ssize_t was_lineno = openfile->current->lineno;
|
||||
size_t was_leftedge = 0;
|
||||
|
||||
if (cutbuffer == NULL) {
|
||||
statusline(AHEM, _("Cutbuffer is empty"));
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
add_undo(PASTE, NULL);
|
||||
|
||||
if (ISSET(SOFTWRAP))
|
||||
was_leftedge = leftedge_for(xplustabs(), openfile->current);
|
||||
#endif
|
||||
|
||||
/* Add a copy of the text in the cutbuffer to the current buffer
|
||||
* at the current cursor position. */
|
||||
copy_from_buffer(cutbuffer);
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
/* Wipe any anchors in the pasted text, so that they don't proliferate. */
|
||||
for (linestruct *line = was_current; line != openfile->current->next; line = line->next)
|
||||
line->has_anchor = FALSE;
|
||||
|
||||
was_current->has_anchor = had_anchor;
|
||||
|
||||
update_undo(PASTE);
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_WRAPPING
|
||||
/* When still on the same line and doing hard-wrapping, limit the width. */
|
||||
if (openfile->current == was_current && ISSET(BREAK_LONG_LINES))
|
||||
do_wrap();
|
||||
#endif
|
||||
|
||||
/* If we pasted less than a screenful, don't center the cursor. */
|
||||
if (less_than_a_screenful(was_lineno, was_leftedge))
|
||||
focusing = FALSE;
|
||||
#ifdef ENABLE_COLOR
|
||||
else
|
||||
precalc_multicolorinfo();
|
||||
#endif
|
||||
|
||||
/* Set the desired x position to where the pasted text ends. */
|
||||
openfile->placewewant = xplustabs();
|
||||
|
||||
set_modified();
|
||||
wipe_statusbar();
|
||||
refresh_needed = TRUE;
|
||||
}
|
666
src/definitions.h
Normal file
666
src/definitions.h
Normal file
|
@ -0,0 +1,666 @@
|
|||
/**************************************************************************
|
||||
* definitions.h -- This file is part of GNU nanofur. *
|
||||
* *
|
||||
* Copyright (C) 1999-2011, 2013-2024 Free Software Foundation, Inc. *
|
||||
* Copyright (C) 2014-2017 Benno Schulenberg *
|
||||
* *
|
||||
* GNU nanofur 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. *
|
||||
* *
|
||||
* GNU nanofur 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 http://www.gnu.org/licenses/. *
|
||||
* *
|
||||
**************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef NEED_XOPEN_SOURCE_EXTENDED
|
||||
#ifndef _XOPEN_SOURCE_EXTENDED
|
||||
#define _XOPEN_SOURCE_EXTENDED 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__HAIKU__) && !defined(_DEFAULT_SOURCE)
|
||||
#define _DEFAULT_SOURCE 1
|
||||
#endif
|
||||
|
||||
#ifdef __TANDEM
|
||||
/* Tandem NonStop Kernel support. */
|
||||
#include <floss.h>
|
||||
#define ROOT_UID 65535
|
||||
#else
|
||||
#define ROOT_UID 0
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIMITS_H
|
||||
#include <limits.h>
|
||||
#endif
|
||||
|
||||
/* Set a default value for PATH_MAX if there isn't one. */
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 4096
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_PARAM_H
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#include <dirent.h>
|
||||
#include <regex.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
/* Prefer wide ncurses over normal ncurses over curses. */
|
||||
#if defined(HAVE_NCURSESW_NCURSES_H)
|
||||
#include <ncursesw/ncurses.h>
|
||||
#elif defined(HAVE_NCURSES_H)
|
||||
#include <ncurses.h>
|
||||
#else
|
||||
#include <curses.h>
|
||||
#endif
|
||||
|
||||
/* Native language support. */
|
||||
#ifdef ENABLE_NLS
|
||||
#ifdef HAVE_LIBINTL_H
|
||||
#include <libintl.h>
|
||||
#endif
|
||||
#define _(string) gettext(string)
|
||||
#define P_(singular, plural, number) ngettext(singular, plural, number)
|
||||
#else
|
||||
#define _(string) (string)
|
||||
#define P_(singular, plural, number) (number == 1 ? singular : plural)
|
||||
#endif
|
||||
/* For marking a string on which gettext() will be called later. */
|
||||
#define gettext_noop(string) (string)
|
||||
#define N_(string) gettext_noop(string)
|
||||
|
||||
/* If we aren't using an ncurses with mouse support, then
|
||||
* exclude the mouse routines, as they are useless then. */
|
||||
#ifndef NCURSES_MOUSE_VERSION
|
||||
#undef ENABLE_MOUSE
|
||||
#endif
|
||||
|
||||
#if defined(ENABLE_WRAPPING) || defined(ENABLE_JUSTIFY)
|
||||
#define ENABLED_WRAPORJUSTIFY 1
|
||||
#endif
|
||||
|
||||
/* Suppress warnings for __attribute__((warn_unused_result)). */
|
||||
#define IGNORE_CALL_RESULT(call) do { if (call) {} } while(0)
|
||||
|
||||
/* Macros for flags, indexing each bit in a small array. */
|
||||
#define FLAGS(flag) flags[((flag) / (sizeof(unsigned) * 8))]
|
||||
#define FLAGMASK(flag) ((unsigned)1 << ((flag) % (sizeof(unsigned) * 8)))
|
||||
#define SET(flag) FLAGS(flag) |= FLAGMASK(flag)
|
||||
#define UNSET(flag) FLAGS(flag) &= ~FLAGMASK(flag)
|
||||
#define ISSET(flag) ((FLAGS(flag) & FLAGMASK(flag)) != 0)
|
||||
#define TOGGLE(flag) FLAGS(flag) ^= FLAGMASK(flag)
|
||||
|
||||
#define BACKWARD FALSE
|
||||
#define FORWARD TRUE
|
||||
|
||||
#define YESORNO FALSE
|
||||
#define YESORALLORNO TRUE
|
||||
|
||||
#define YES 1
|
||||
#define ALL 2
|
||||
#define NO 0
|
||||
#define CANCEL -1
|
||||
|
||||
#define BLIND FALSE
|
||||
#define VISIBLE TRUE
|
||||
|
||||
#define JUSTFIND 0
|
||||
#define REPLACING 1
|
||||
#define INREGION 2
|
||||
|
||||
#define NORMAL TRUE
|
||||
#define SPECIAL FALSE
|
||||
#define TEMPORARY FALSE
|
||||
|
||||
#define ANNOTATE TRUE
|
||||
#define NONOTES FALSE
|
||||
|
||||
#define PRUNE_DUPLICATE TRUE
|
||||
#define IGNORE_DUPLICATES FALSE
|
||||
|
||||
#ifdef ENABLE_UTF8
|
||||
/* In UTF-8 a valid character is at most four bytes long. */
|
||||
#define MAXCHARLEN 4
|
||||
#else
|
||||
#define MAXCHARLEN 1
|
||||
#endif
|
||||
|
||||
/* The default width of a tab in spaces. */
|
||||
#define WIDTH_OF_TAB 8
|
||||
|
||||
/* The default number of columns from end of line where wrapping occurs. */
|
||||
#define COLUMNS_FROM_EOL 8
|
||||
|
||||
/* The default comment character when a syntax does not specify any. */
|
||||
#define GENERAL_COMMENT_CHARACTER "#"
|
||||
|
||||
/* The maximum number of search/replace history strings saved. */
|
||||
#define MAX_SEARCH_HISTORY 100
|
||||
|
||||
/* The largest size_t number that doesn't have the high bit set. */
|
||||
#define HIGHEST_POSITIVE ((~(size_t)0) >> 1)
|
||||
|
||||
#ifdef ENABLE_COLOR
|
||||
#define THE_DEFAULT -1
|
||||
#define BAD_COLOR -2
|
||||
|
||||
/* Flags for indicating how a multiline regex pair apply to a line. */
|
||||
#define NOTHING (1<<1)
|
||||
/* The start/end regexes don't cover this line at all. */
|
||||
#define STARTSHERE (1<<2)
|
||||
/* The start regex matches on this line, the end regex on a later one. */
|
||||
#define WHOLELINE (1<<3)
|
||||
/* The start regex matches on an earlier line, the end regex on a later one. */
|
||||
#define ENDSHERE (1<<4)
|
||||
/* The start regex matches on an earlier line, the end regex on this one. */
|
||||
#define JUSTONTHIS (1<<5)
|
||||
/* Both the start and end regexes match within this line. */
|
||||
#endif
|
||||
|
||||
/* Basic control codes. */
|
||||
#define ESC_CODE 0x1B
|
||||
#define DEL_CODE 0x7F
|
||||
|
||||
/* Codes for "modified" Arrow keys, beyond KEY_MAX of ncurses. */
|
||||
#define CONTROL_LEFT 0x401
|
||||
#define CONTROL_RIGHT 0x402
|
||||
#define CONTROL_UP 0x403
|
||||
#define CONTROL_DOWN 0x404
|
||||
#define CONTROL_HOME 0x405
|
||||
#define CONTROL_END 0x406
|
||||
#define CONTROL_DELETE 0x40D
|
||||
#define SHIFT_CONTROL_LEFT 0x411
|
||||
#define SHIFT_CONTROL_RIGHT 0x412
|
||||
#define SHIFT_CONTROL_UP 0x413
|
||||
#define SHIFT_CONTROL_DOWN 0x414
|
||||
#define SHIFT_CONTROL_HOME 0x415
|
||||
#define SHIFT_CONTROL_END 0x416
|
||||
#define CONTROL_SHIFT_DELETE 0x41D
|
||||
#define ALT_LEFT 0x421
|
||||
#define ALT_RIGHT 0x422
|
||||
#define ALT_UP 0x423
|
||||
#define ALT_DOWN 0x424
|
||||
#define ALT_HOME 0x425
|
||||
#define ALT_END 0x426
|
||||
#define ALT_PAGEUP 0x427
|
||||
#define ALT_PAGEDOWN 0x428
|
||||
#define ALT_INSERT 0x42C
|
||||
#define ALT_DELETE 0x42D
|
||||
#define SHIFT_ALT_LEFT 0x431
|
||||
#define SHIFT_ALT_RIGHT 0x432
|
||||
#define SHIFT_ALT_UP 0x433
|
||||
#define SHIFT_ALT_DOWN 0x434
|
||||
//#define SHIFT_LEFT 0x451
|
||||
//#define SHIFT_RIGHT 0x452
|
||||
#define SHIFT_UP 0x453
|
||||
#define SHIFT_DOWN 0x454
|
||||
#define SHIFT_HOME 0x455
|
||||
#define SHIFT_END 0x456
|
||||
#define SHIFT_PAGEUP 0x457
|
||||
#define SHIFT_PAGEDOWN 0x458
|
||||
#define SHIFT_DELETE 0x45D
|
||||
#define SHIFT_TAB 0x45F
|
||||
|
||||
#define FOCUS_IN 0x491
|
||||
#define FOCUS_OUT 0x499
|
||||
|
||||
/* Special keycodes for when a string bind has been partially implanted
|
||||
* or has an unpaired opening brace, or when a function in a string bind
|
||||
* needs execution or a specified function name is invalid. */
|
||||
#define MORE_PLANTS 0x4EA
|
||||
#define MISSING_BRACE 0x4EB
|
||||
#define PLANTED_A_COMMAND 0x4EC
|
||||
#define NO_SUCH_FUNCTION 0x4EF
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
/* A special keycode for Ctrl + the central key on the numeric keypad. */
|
||||
#define KEY_CENTER 0x4F0
|
||||
|
||||
/* A special keycode for when we get a SIGWINCH (a window resize). */
|
||||
#define THE_WINDOW_RESIZED 0x4F7
|
||||
#endif
|
||||
|
||||
/* A special keycode to signal the beginning and end of a bracketed paste. */
|
||||
#define BRACKETED_PASTE_MARKER 0x4FB
|
||||
|
||||
/* A special keycode for when a key produces an unknown escape sequence. */
|
||||
#define FOREIGN_SEQUENCE 0x4FC
|
||||
|
||||
/* A special keycode for plugging into the input stream after a suspension. */
|
||||
#define KEY_FRESH 0x4FE
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
/* Some extra flags for the undo function. */
|
||||
#define WAS_BACKSPACE_AT_EOF (1<<1)
|
||||
#define WAS_WHOLE_LINE (1<<2)
|
||||
#define INCLUDED_LAST_LINE (1<<3)
|
||||
#define MARK_WAS_SET (1<<4)
|
||||
#define CURSOR_WAS_AT_HEAD (1<<5)
|
||||
#define HAD_ANCHOR_AT_START (1<<6)
|
||||
#endif /* !NANOFUR_TINY */
|
||||
|
||||
/* Identifiers for the different menus. */
|
||||
#define MMAIN (1<<0)
|
||||
#define MWHEREIS (1<<1)
|
||||
#define MREPLACE (1<<2)
|
||||
#define MREPLACEWITH (1<<3)
|
||||
#define MGOTOLINE (1<<4)
|
||||
#define MWRITEFILE (1<<5)
|
||||
#define MINSERTFILE (1<<6)
|
||||
#define MEXECUTE (1<<7)
|
||||
#define MHELP (1<<8)
|
||||
#define MSPELL (1<<9)
|
||||
#define MBROWSER (1<<10)
|
||||
#define MWHEREISFILE (1<<11)
|
||||
#define MGOTODIR (1<<12)
|
||||
#define MYESNO (1<<13)
|
||||
#define MLINTER (1<<14)
|
||||
#define MFINDINHELP (1<<15)
|
||||
/* This is an abbreviation for all menus except Help and Browser and YesNo. */
|
||||
#define MMOST (MMAIN|MWHEREIS|MREPLACE|MREPLACEWITH|MGOTOLINE|MWRITEFILE|MINSERTFILE|\
|
||||
MEXECUTE|MWHEREISFILE|MGOTODIR|MFINDINHELP|MSPELL|MLINTER)
|
||||
#ifndef NANOFUR_TINY
|
||||
#define MSOME MMOST|MBROWSER
|
||||
#else
|
||||
#define MSOME MMAIN|MBROWSER
|
||||
#endif
|
||||
|
||||
/* Enumeration types. */
|
||||
typedef enum {
|
||||
UNSPECIFIED, NIX_FILE, DOS_FILE, MAC_FILE
|
||||
} format_type;
|
||||
|
||||
typedef enum {
|
||||
VACUUM, HUSH, REMARK, INFO, NOTICE, AHEM, MILD, ALERT
|
||||
} message_type;
|
||||
|
||||
typedef enum {
|
||||
OVERWRITE, APPEND, PREPEND, EMERGENCY
|
||||
} kind_of_writing_type;
|
||||
|
||||
typedef enum {
|
||||
CENTERING, FLOWING, STATIONARY
|
||||
} update_type;
|
||||
|
||||
/* The kinds of undo actions. ADD...REPLACE must come first. */
|
||||
typedef enum {
|
||||
ADD, ENTER, BACK, DEL, JOIN, REPLACE,
|
||||
#ifdef ENABLE_WRAPPING
|
||||
SPLIT_BEGIN, SPLIT_END,
|
||||
#endif
|
||||
INDENT, UNINDENT,
|
||||
#ifdef ENABLE_COMMENT
|
||||
COMMENT, UNCOMMENT, PREFLIGHT,
|
||||
#endif
|
||||
ZAP, CUT, CUT_TO_EOF, COPY, PASTE, INSERT,
|
||||
COUPLE_BEGIN, COUPLE_END, OTHER
|
||||
} undo_type;
|
||||
|
||||
/* The elements of the interface that can be colored differently. */
|
||||
enum {
|
||||
TITLE_BAR = 0,
|
||||
LINE_NUMBER,
|
||||
GUIDE_STRIPE,
|
||||
SCROLL_BAR,
|
||||
SELECTED_TEXT,
|
||||
SPOTLIGHTED,
|
||||
MINI_INFOBAR,
|
||||
PROMPT_BAR,
|
||||
STATUS_BAR,
|
||||
ERROR_MESSAGE,
|
||||
KEY_COMBO,
|
||||
FUNCTION_TAG,
|
||||
NUMBER_OF_ELEMENTS
|
||||
};
|
||||
|
||||
/* Enumeration used in the flags array. See the definition of FLAGMASK. */
|
||||
enum {
|
||||
DONTUSE = 0,
|
||||
CASE_SENSITIVE,
|
||||
CONSTANT_SHOW,
|
||||
NO_HELP,
|
||||
NO_WRAP,
|
||||
AUTOINDENT,
|
||||
VIEW_MODE,
|
||||
USE_MOUSE,
|
||||
USE_REGEXP,
|
||||
SAVE_ON_EXIT,
|
||||
CUT_FROM_CURSOR,
|
||||
BACKWARDS_SEARCH,
|
||||
MULTIBUFFER,
|
||||
REBIND_DELETE,
|
||||
RAW_SEQUENCES,
|
||||
NO_CONVERT,
|
||||
MAKE_BACKUP,
|
||||
INSECURE_BACKUP,
|
||||
NO_SYNTAX,
|
||||
PRESERVE,
|
||||
HISTORYLOG,
|
||||
RESTRICTED,
|
||||
SMART_HOME,
|
||||
WHITESPACE_DISPLAY,
|
||||
TABS_TO_SPACES,
|
||||
QUICK_BLANK,
|
||||
WORD_BOUNDS,
|
||||
NO_NEWLINES,
|
||||
BOLD_TEXT,
|
||||
SOFTWRAP,
|
||||
POSITIONLOG,
|
||||
LOCKING,
|
||||
NOREAD_MODE,
|
||||
MAKE_IT_UNIX,
|
||||
TRIM_BLANKS,
|
||||
SHOW_CURSOR,
|
||||
LINE_NUMBERS,
|
||||
AT_BLANKS,
|
||||
AFTER_ENDS,
|
||||
LET_THEM_ZAP,
|
||||
BREAK_LONG_LINES,
|
||||
JUMPY_SCROLLING,
|
||||
EMPTY_LINE,
|
||||
INDICATOR,
|
||||
BOOKSTYLE,
|
||||
COLON_PARSING,
|
||||
STATEFLAGS,
|
||||
USE_MAGIC,
|
||||
MINIBAR,
|
||||
ZERO,
|
||||
MODERN_BINDINGS
|
||||
};
|
||||
|
||||
/* Structure types. */
|
||||
#ifdef ENABLE_COLOR
|
||||
typedef struct colortype {
|
||||
short id;
|
||||
/* An ordinal number (if this color combo is for a multiline regex). */
|
||||
short fg;
|
||||
/* This combo's foreground color. */
|
||||
short bg;
|
||||
/* This combo's background color. */
|
||||
short pairnum;
|
||||
/* The pair number for this foreground/background color combination. */
|
||||
int attributes;
|
||||
/* Pair number and brightness composed into ready-to-use attributes. */
|
||||
regex_t *start;
|
||||
/* The compiled regular expression for 'start=', or the only one. */
|
||||
regex_t *end;
|
||||
/* The compiled regular expression for 'end=', if any. */
|
||||
struct colortype *next;
|
||||
/* Next color combination. */
|
||||
} colortype;
|
||||
|
||||
typedef struct regexlisttype {
|
||||
regex_t *one_rgx;
|
||||
/* A regex to match things that imply a certain syntax. */
|
||||
struct regexlisttype *next;
|
||||
/* The next regex. */
|
||||
} regexlisttype;
|
||||
|
||||
typedef struct augmentstruct {
|
||||
char *filename;
|
||||
/* The file where the syntax is extended. */
|
||||
ssize_t lineno;
|
||||
/* The number of the line of the extendsyntax command. */
|
||||
char *data;
|
||||
/* The text of the line. */
|
||||
struct augmentstruct *next;
|
||||
/* Next node. */
|
||||
} augmentstruct;
|
||||
|
||||
typedef struct syntaxtype {
|
||||
char *name;
|
||||
/* The name of this syntax. */
|
||||
char *filename;
|
||||
/* File where the syntax is defined, or NULL if not an included file. */
|
||||
size_t lineno;
|
||||
/* The line number where the 'syntax' command was found. */
|
||||
augmentstruct *augmentations;
|
||||
/* List of extendsyntax commands to apply when loaded. */
|
||||
regexlisttype *extensions;
|
||||
/* The list of extensions that this syntax applies to. */
|
||||
regexlisttype *headers;
|
||||
/* The list of headerlines that this syntax applies to. */
|
||||
regexlisttype *magics;
|
||||
/* The list of libmagic results that this syntax applies to. */
|
||||
char *linter;
|
||||
/* The command with which to lint this type of file. */
|
||||
char *formatter;
|
||||
/* The command with which to format/modify/arrange this type of file. */
|
||||
char *tabstring;
|
||||
/* What the Tab key should produce; NULL for default behavior. */
|
||||
#ifdef ENABLE_COMMENT
|
||||
char *comment;
|
||||
/* The line comment prefix (and postfix) for this type of file. */
|
||||
#endif
|
||||
colortype *color;
|
||||
/* The colors and their regexes used in this syntax. */
|
||||
short multiscore;
|
||||
/* How many multiline regex strings this syntax has. */
|
||||
struct syntaxtype *next;
|
||||
/* Next syntax. */
|
||||
} syntaxtype;
|
||||
|
||||
typedef struct lintstruct {
|
||||
ssize_t lineno;
|
||||
/* Line number of the error. */
|
||||
ssize_t colno;
|
||||
/* Column # of the error. */
|
||||
char *msg;
|
||||
/* Error message text. */
|
||||
char *filename;
|
||||
/* Filename. */
|
||||
struct lintstruct *next;
|
||||
/* Next error. */
|
||||
struct lintstruct *prev;
|
||||
/* Previous error. */
|
||||
} lintstruct;
|
||||
#endif /* ENABLE_COLOR */
|
||||
|
||||
/* More structure types. */
|
||||
typedef struct linestruct {
|
||||
char *data;
|
||||
/* The text of this line. */
|
||||
ssize_t lineno;
|
||||
/* The number of this line. */
|
||||
struct linestruct *next;
|
||||
/* Next node. */
|
||||
struct linestruct *prev;
|
||||
/* Previous node. */
|
||||
#ifdef ENABLE_COLOR
|
||||
short *multidata;
|
||||
/* Array of which multi-line regexes apply to this line. */
|
||||
#endif
|
||||
#ifndef NANOFUR_TINY
|
||||
bool has_anchor;
|
||||
/* Whether the user has placed an anchor at this line. */
|
||||
#endif
|
||||
} linestruct;
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
typedef struct groupstruct {
|
||||
ssize_t top_line;
|
||||
/* First line of group. */
|
||||
ssize_t bottom_line;
|
||||
/* Last line of group. */
|
||||
char **indentations;
|
||||
/* String data used to restore the affected lines; one per line. */
|
||||
struct groupstruct *next;
|
||||
/* The next group, if any. */
|
||||
} groupstruct;
|
||||
|
||||
typedef struct undostruct {
|
||||
undo_type type;
|
||||
/* The operation type that this undo item is for. */
|
||||
int xflags;
|
||||
/* Some flag data to mark certain corner cases. */
|
||||
ssize_t head_lineno;
|
||||
/* The line number where the operation began or ended. */
|
||||
size_t head_x;
|
||||
/* The x position where the operation began or ended. */
|
||||
char *strdata;
|
||||
/* String data to help restore the affected line. */
|
||||
size_t wassize;
|
||||
/* The file size before the action. */
|
||||
size_t newsize;
|
||||
/* The file size after the action. */
|
||||
groupstruct *grouping;
|
||||
/* Undo info specific to groups of lines. */
|
||||
linestruct *cutbuffer;
|
||||
/* A copy of the cutbuffer. */
|
||||
ssize_t tail_lineno;
|
||||
/* Mostly the line number of the current line; sometimes something else. */
|
||||
size_t tail_x;
|
||||
/* The x position corresponding to the above line number. */
|
||||
struct undostruct *next;
|
||||
/* A pointer to the undo item of the preceding action. */
|
||||
} undostruct;
|
||||
#endif /* !NANOFUR_TINY */
|
||||
|
||||
#ifdef ENABLE_HISTORIES
|
||||
typedef struct poshiststruct {
|
||||
char *filename;
|
||||
/* The full path plus name of the file. */
|
||||
ssize_t linenumber;
|
||||
/* The line where the cursor was when we closed the file. */
|
||||
ssize_t columnnumber;
|
||||
/* The column where the cursor was. */
|
||||
struct poshiststruct *next;
|
||||
/* The next item of position history. */
|
||||
} poshiststruct;
|
||||
#endif
|
||||
|
||||
typedef struct openfilestruct {
|
||||
char *filename;
|
||||
/* The file's name. */
|
||||
linestruct *filetop;
|
||||
/* The file's first line. */
|
||||
linestruct *filebot;
|
||||
/* The file's last line. */
|
||||
linestruct *edittop;
|
||||
/* The current top of the edit window for this file. */
|
||||
linestruct *current;
|
||||
/* The current line for this file. */
|
||||
size_t totsize;
|
||||
/* The file's total number of characters. */
|
||||
size_t firstcolumn;
|
||||
/* The starting column of the top line of the edit window.
|
||||
* When not in softwrap mode, it's always zero. */
|
||||
size_t current_x;
|
||||
/* The file's x-coordinate position. */
|
||||
size_t placewewant;
|
||||
/* The file's x position we would like. */
|
||||
ssize_t cursor_row;
|
||||
/* The row in the edit window that the cursor is on. */
|
||||
struct stat *statinfo;
|
||||
/* The file's stat information from when it was opened or last saved. */
|
||||
#ifdef ENABLE_WRAPPING
|
||||
linestruct *spillage_line;
|
||||
/* The line for prepending stuff to during automatic hard-wrapping. */
|
||||
#endif
|
||||
#ifndef NANOFUR_TINY
|
||||
linestruct *mark;
|
||||
/* The line in the file where the mark is set; NULL if not set. */
|
||||
size_t mark_x;
|
||||
/* The mark's x position in the above line. */
|
||||
bool softmark;
|
||||
/* Whether a marked region was made by holding Shift. */
|
||||
format_type fmt;
|
||||
/* The file's format -- Unix or DOS or Mac. */
|
||||
char *lock_filename;
|
||||
/* The path of the lockfile, if we created one. */
|
||||
undostruct *undotop;
|
||||
/* The top of the undo list. */
|
||||
undostruct *current_undo;
|
||||
/* The current (i.e. next) level of undo. */
|
||||
undostruct *last_saved;
|
||||
/* The undo item at which the file was last saved. */
|
||||
undo_type last_action;
|
||||
/* The type of the last action the user performed. */
|
||||
#endif
|
||||
bool modified;
|
||||
/* Whether the file has been modified. */
|
||||
#ifdef ENABLE_COLOR
|
||||
syntaxtype *syntax;
|
||||
/* The syntax that applies to this file, if any. */
|
||||
#endif
|
||||
#ifdef ENABLE_MULTIBUFFER
|
||||
char *errormessage;
|
||||
/* The ALERT message (if any) that occurred when opening the file. */
|
||||
struct openfilestruct *next;
|
||||
/* The next open file, if any. */
|
||||
struct openfilestruct *prev;
|
||||
/* The preceding open file, if any. */
|
||||
#endif
|
||||
} openfilestruct;
|
||||
|
||||
#ifdef ENABLE_NANOFURRC
|
||||
typedef struct rcoption {
|
||||
const char *name;
|
||||
/* The name of the rcfile option. */
|
||||
long flag;
|
||||
/* The flag associated with it, if any. */
|
||||
} rcoption;
|
||||
#endif
|
||||
|
||||
typedef struct keystruct {
|
||||
const char *keystr;
|
||||
/* The string that describes the keystroke, like "^C" or "M-R". */
|
||||
int keycode;
|
||||
/* The integer that, together with meta, identifies the keystroke. */
|
||||
int menus;
|
||||
/* The menus in which this keystroke is bound. */
|
||||
void (*func)(void);
|
||||
/* The function to which this keystroke is bound. */
|
||||
#ifndef NANOFUR_TINY
|
||||
int toggle;
|
||||
/* If a toggle, what we're toggling. */
|
||||
int ordinal;
|
||||
/* The how-manieth toggle this is, in order to be able to
|
||||
* keep them in sequence. */
|
||||
#endif
|
||||
#ifdef ENABLE_NANOFURRC
|
||||
char *expansion;
|
||||
/* The string of keycodes to which this shortcut is expanded. */
|
||||
#endif
|
||||
struct keystruct *next;
|
||||
/* Next in the list. */
|
||||
} keystruct;
|
||||
|
||||
typedef struct funcstruct {
|
||||
void (*func)(void);
|
||||
/* The actual function to call. */
|
||||
const char *tag;
|
||||
/* The function's help-line label, for example "Where Is". */
|
||||
#ifdef ENABLE_HELP
|
||||
const char *phrase;
|
||||
/* The function's description for in the help viewer. */
|
||||
bool blank_after;
|
||||
/* Whether to distance this function from the next in the help viewer. */
|
||||
#endif
|
||||
int menus;
|
||||
/* In what menus this function applies. */
|
||||
struct funcstruct *next;
|
||||
/* Next item in the list. */
|
||||
} funcstruct;
|
||||
|
||||
#ifdef ENABLE_WORDCOMPLETION
|
||||
typedef struct completionstruct {
|
||||
char *word;
|
||||
struct completionstruct *next;
|
||||
} completionstruct;
|
||||
#endif
|
2719
src/files.c
Normal file
2719
src/files.c
Normal file
File diff suppressed because it is too large
Load diff
1623
src/global.c
Normal file
1623
src/global.c
Normal file
File diff suppressed because it is too large
Load diff
592
src/help.c
Normal file
592
src/help.c
Normal file
|
@ -0,0 +1,592 @@
|
|||
/**************************************************************************
|
||||
* help.c -- This file is part of GNU nanofur. *
|
||||
* *
|
||||
* Copyright (C) 2000-2011, 2013-2024 Free Software Foundation, Inc. *
|
||||
* Copyright (C) 2017 Rishabh Dave *
|
||||
* Copyright (C) 2014-2019 Benno Schulenberg *
|
||||
* *
|
||||
* GNU nanofur 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. *
|
||||
* *
|
||||
* GNU nanofur 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 http://www.gnu.org/licenses/. *
|
||||
* *
|
||||
**************************************************************************/
|
||||
|
||||
#include "prototypes.h"
|
||||
|
||||
#ifdef ENABLE_HELP
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
static char *help_text = NULL;
|
||||
/* The text displayed in the help window. */
|
||||
static const char *start_of_body = NULL;
|
||||
/* The point in the help text just after the title. */
|
||||
static char *end_of_intro = NULL;
|
||||
/* The point in the help text where the shortcut descriptions begin. */
|
||||
static size_t location;
|
||||
/* The offset (in bytes) of the topleft of the shown help text. */
|
||||
|
||||
/* Allocate space for the help text for the current menu,
|
||||
* and concatenate the different pieces of text into it. */
|
||||
void help_init(void)
|
||||
{
|
||||
size_t allocsize = 0;
|
||||
/* Space needed for help_text. */
|
||||
const char *htx[3];
|
||||
/* Untranslated help introduction. We break it up into three chunks
|
||||
* in case the full string is too long for the compiler to handle. */
|
||||
const funcstruct *f;
|
||||
const keystruct *s;
|
||||
char *ptr;
|
||||
|
||||
/* First, set up the initial help text for the current function. */
|
||||
if (currmenu & (MWHEREIS|MREPLACE)) {
|
||||
htx[0] = N_("Search Command Help Text\n\n "
|
||||
"Enter the words or characters you would like to "
|
||||
"search for, and then press Enter. If there is a "
|
||||
"match for the text you entered, the screen will be "
|
||||
"updated to the location of the nearest match for the "
|
||||
"search string.\n\n The previous search string will be "
|
||||
"shown in brackets after the search prompt. Hitting "
|
||||
"Enter without entering any text will perform the "
|
||||
"previous search. ");
|
||||
htx[1] = N_("If you have selected text with the mark and then "
|
||||
"search to replace, only matches in the selected text "
|
||||
"will be replaced.\n\n The following function keys are "
|
||||
"available in Search mode:\n\n");
|
||||
htx[2] = NULL;
|
||||
} else if (currmenu == MREPLACEWITH) {
|
||||
htx[0] = N_("=== Replacement ===\n\n "
|
||||
"Type the characters that should replace what you "
|
||||
"typed at the previous prompt, and press Enter.\n\n");
|
||||
htx[1] = N_(" The following function keys "
|
||||
"are available at this prompt:\n\n");
|
||||
htx[2] = NULL;
|
||||
} else if (currmenu == MGOTOLINE) {
|
||||
htx[0] = N_("Go To Line Help Text\n\n "
|
||||
"Enter the line number that you wish to go to and hit "
|
||||
"Enter. If there are fewer lines of text than the "
|
||||
"number you entered, you will be brought to the last "
|
||||
"line of the file.\n\n The following function keys are "
|
||||
"available in Go To Line mode:\n\n");
|
||||
htx[1] = NULL;
|
||||
htx[2] = NULL;
|
||||
} else if (currmenu == MINSERTFILE) {
|
||||
htx[0] = N_("Insert File Help Text\n\n "
|
||||
"Type in the name of a file to be inserted into the "
|
||||
"current file buffer at the current cursor "
|
||||
"location.\n\n If you have compiled nanofur with multiple "
|
||||
"file buffer support, and enable multiple file buffers "
|
||||
"with the -F or --multibuffer command line flags, the "
|
||||
"Meta-F toggle, or a nanofurrc file, inserting a file "
|
||||
"will cause it to be loaded into a separate buffer "
|
||||
"(use Meta-< and > to switch between file buffers). ");
|
||||
htx[1] = N_("If you need another blank buffer, do not enter "
|
||||
"any filename, or type in a nonexistent filename at "
|
||||
"the prompt and press Enter.\n\n The following "
|
||||
"function keys are available in Insert File mode:\n\n");
|
||||
htx[2] = NULL;
|
||||
} else if (currmenu == MWRITEFILE) {
|
||||
htx[0] = N_("Write File Help Text\n\n "
|
||||
"Type the name that you wish to save the current file "
|
||||
"as and press Enter to save the file.\n\n If you have "
|
||||
"selected text with the mark, you will be prompted to "
|
||||
"save only the selected portion to a separate file. To "
|
||||
"reduce the chance of overwriting the current file with "
|
||||
"just a portion of it, the current filename is not the "
|
||||
"default in this mode.\n\n The following function keys "
|
||||
"are available in Write File mode:\n\n");
|
||||
htx[1] = NULL;
|
||||
htx[2] = NULL;
|
||||
}
|
||||
#ifdef ENABLE_BROWSER
|
||||
else if (currmenu == MBROWSER) {
|
||||
htx[0] = N_("File Browser Help Text\n\n "
|
||||
"The file browser is used to visually browse the "
|
||||
"directory structure to select a file for reading "
|
||||
"or writing. You may use the arrow keys or Page Up/"
|
||||
"Down to browse through the files, and S or Enter to "
|
||||
"choose the selected file or enter the selected "
|
||||
"directory. To move up one level, select the "
|
||||
"directory called \"..\" at the top of the file "
|
||||
"list.\n\n The following function keys are available "
|
||||
"in the file browser:\n\n");
|
||||
htx[1] = NULL;
|
||||
htx[2] = NULL;
|
||||
} else if (currmenu == MWHEREISFILE) {
|
||||
htx[0] = N_("Browser Search Command Help Text\n\n "
|
||||
"Enter the words or characters you would like to "
|
||||
"search for, and then press Enter. If there is a "
|
||||
"match for the text you entered, the screen will be "
|
||||
"updated to the location of the nearest match for the "
|
||||
"search string.\n\n The previous search string will be "
|
||||
"shown in brackets after the search prompt. Hitting "
|
||||
"Enter without entering any text will perform the "
|
||||
"previous search.\n\n");
|
||||
htx[1] = N_(" The following function keys "
|
||||
"are available at this prompt:\n\n");
|
||||
htx[2] = NULL;
|
||||
} else if (currmenu == MGOTODIR) {
|
||||
htx[0] = N_("Browser Go To Directory Help Text\n\n "
|
||||
"Enter the name of the directory you would like to "
|
||||
"browse to.\n\n If tab completion has not been "
|
||||
"disabled, you can use the Tab key to (attempt to) "
|
||||
"automatically complete the directory name.\n\n The "
|
||||
"following function keys are available in Browser Go "
|
||||
"To Directory mode:\n\n");
|
||||
htx[1] = NULL;
|
||||
htx[2] = NULL;
|
||||
}
|
||||
#endif /* ENABLE_BROWSER */
|
||||
#ifdef ENABLE_SPELLER
|
||||
else if (currmenu == MSPELL) {
|
||||
htx[0] = N_("Spell Check Help Text\n\n "
|
||||
"The spell checker checks the spelling of all text in "
|
||||
"the current file. When an unknown word is "
|
||||
"encountered, it is highlighted and a replacement can "
|
||||
"be edited. It will then prompt to replace every "
|
||||
"instance of the given misspelled word in the current "
|
||||
"file, or, if you have selected text with the mark, in "
|
||||
"the selected text.\n\n The following function keys "
|
||||
"are available in Spell Check mode:\n\n");
|
||||
htx[1] = NULL;
|
||||
htx[2] = NULL;
|
||||
}
|
||||
#endif /* ENABLE_SPELLER */
|
||||
#ifndef NANOFUR_TINY
|
||||
else if (currmenu == MEXECUTE) {
|
||||
htx[0] = N_("Execute Command Help Text\n\n "
|
||||
"This mode allows you to insert the output of a "
|
||||
"command run by the shell into the current buffer (or "
|
||||
"into a new buffer). If the command is preceded by '|' "
|
||||
"(the pipe symbol), the current contents of the buffer "
|
||||
"(or marked region) will be piped to the command. ");
|
||||
htx[1] = N_("If you just need another blank buffer, do not enter any "
|
||||
"command.\n\n You can also pick one of four tools, or cut a "
|
||||
"large piece of the buffer, or put the editor to sleep.\n\n");
|
||||
htx[2] = N_(" The following function keys "
|
||||
"are available at this prompt:\n\n");
|
||||
} else if (currmenu == MLINTER) {
|
||||
htx[0] = N_("=== Linter ===\n\n "
|
||||
"In this mode, the status bar shows an error message or "
|
||||
"warning, and the cursor is put at the corresponding "
|
||||
"position in the file. With PageUp and PageDown you "
|
||||
"can switch to earlier and later messages.\n\n");
|
||||
htx[1] = N_(" The following function keys are "
|
||||
"available in Linter mode:\n\n");
|
||||
htx[2] = NULL;
|
||||
}
|
||||
#endif /* !NANOFUR_TINY */
|
||||
else {
|
||||
/* Default to the main help list. */
|
||||
htx[0] = N_("Main nanofur help text\n\n "
|
||||
"The nanofur editor is designed to emulate the "
|
||||
"functionality and ease-of-use of the UW Pico text "
|
||||
"editor. There are four main sections of the editor. "
|
||||
"The top line shows the program version, the current "
|
||||
"filename being edited, and whether or not the file "
|
||||
"has been modified. Next is the main editor window "
|
||||
"showing the file being edited. The status line is "
|
||||
"the third line from the bottom and shows important "
|
||||
"messages. ");
|
||||
htx[1] = N_("The bottom two lines show the most commonly used "
|
||||
"shortcuts in the editor.\n\n Shortcuts are written as "
|
||||
"follows: Control-key sequences are notated with a '^' "
|
||||
"and can be entered either by using the Ctrl key or "
|
||||
"pressing the Esc key twice. Meta-key sequences are "
|
||||
"notated with 'M-' and can be entered using either the "
|
||||
"Alt, Cmd, or Esc key, depending on your keyboard setup. ");
|
||||
htx[2] = N_("Also, pressing Esc twice and then typing a "
|
||||
"three-digit decimal number from 000 to 255 will enter "
|
||||
"the character with the corresponding value. The "
|
||||
"following keystrokes are available in the main editor "
|
||||
"window. Alternative keys are shown in "
|
||||
"parentheses:\n\n");
|
||||
}
|
||||
|
||||
htx[0] = _(htx[0]);
|
||||
if (htx[1] != NULL)
|
||||
htx[1] = _(htx[1]);
|
||||
if (htx[2] != NULL)
|
||||
htx[2] = _(htx[2]);
|
||||
|
||||
allocsize += strlen(htx[0]);
|
||||
if (htx[1] != NULL)
|
||||
allocsize += strlen(htx[1]);
|
||||
if (htx[2] != NULL)
|
||||
allocsize += strlen(htx[2]);
|
||||
|
||||
/* Calculate the length of the descriptions of the shortcuts.
|
||||
* Each entry has one or two keystrokes, which fill 17 cells,
|
||||
* plus translated text, plus one or two \n's. */
|
||||
for (f = allfuncs; f != NULL; f = f->next)
|
||||
if (f->menus & currmenu)
|
||||
allocsize += strlen(_(f->phrase)) + 21;
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
/* If we're on the main list, we also count the toggle help text.
|
||||
* Each entry has "M-%c\t\t ", six chars which fill 17 cells, plus
|
||||
* two translated texts, plus a space, plus one or two '\n's. */
|
||||
if (currmenu == MMAIN) {
|
||||
size_t onoff_len = strlen(_("enable/disable"));
|
||||
|
||||
for (s = sclist; s != NULL; s = s->next)
|
||||
if (s->func == do_toggle)
|
||||
allocsize += strlen(_(epithet_of_flag(s->toggle))) + onoff_len + 9;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Allocate memory for the help text. */
|
||||
help_text = nmalloc(allocsize + 1);
|
||||
|
||||
/* Now add the text we want. */
|
||||
strcpy(help_text, htx[0]);
|
||||
if (htx[1] != NULL)
|
||||
strcat(help_text, htx[1]);
|
||||
if (htx[2] != NULL)
|
||||
strcat(help_text, htx[2]);
|
||||
|
||||
/* Remember this end-of-introduction, start-of-shortcuts. */
|
||||
end_of_intro = help_text + strlen(help_text);
|
||||
ptr = end_of_intro;
|
||||
|
||||
/* Now add the shortcuts and their descriptions. */
|
||||
for (f = allfuncs; f != NULL; f = f->next) {
|
||||
int tally = 0;
|
||||
|
||||
if ((f->menus & currmenu) == 0)
|
||||
continue;
|
||||
|
||||
/* Show the first two shortcuts (if any) for each function. */
|
||||
for (s = sclist; s != NULL; s = s->next) {
|
||||
if ((s->menus & currmenu) && s->func == f->func && s->keystr[0]) {
|
||||
/* Make the first column 7 cells wide and the second 10. */
|
||||
if (++tally == 1) {
|
||||
sprintf(ptr, "%s ", s->keystr);
|
||||
/* Unicode arrows take three bytes instead of one. */
|
||||
ptr += (strstr(s->keystr, "\xE2") != NULL ? 9 : 7);
|
||||
} else {
|
||||
sprintf(ptr, "(%s) ", s->keystr);
|
||||
ptr += (strstr(s->keystr, "\xE2") != NULL ? 12 : 10);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tally == 0)
|
||||
ptr += sprintf(ptr, "\t\t ");
|
||||
else if (tally == 1)
|
||||
ptr += 10;
|
||||
|
||||
/* The shortcut's description. */
|
||||
ptr += sprintf(ptr, "%s\n", _(f->phrase));
|
||||
|
||||
if (f->blank_after)
|
||||
ptr += sprintf(ptr, "\n");
|
||||
}
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
/* And the toggles... */
|
||||
if (currmenu == MMAIN) {
|
||||
int maximum = 0, counter = 0;
|
||||
|
||||
/* First see how many toggles there are. */
|
||||
for (s = sclist; s != NULL; s = s->next)
|
||||
maximum = (s->toggle && s->ordinal > maximum) ? s->ordinal : maximum;
|
||||
|
||||
/* Now show them in the original order. */
|
||||
while (counter < maximum) {
|
||||
counter++;
|
||||
for (s = sclist; s != NULL; s = s->next)
|
||||
if (s->toggle && s->ordinal == counter) {
|
||||
ptr += sprintf(ptr, "%s\t\t %s %s\n", (s->menus & MMAIN ? s->keystr : ""),
|
||||
_(epithet_of_flag(s->toggle)), _("enable/disable"));
|
||||
/* Add a blank like between two groups. */
|
||||
if (s->toggle == NO_SYNTAX)
|
||||
ptr += sprintf(ptr, "\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Hard-wrap the concatenated help text, and write it into a new buffer. */
|
||||
void wrap_help_text_into_buffer(void)
|
||||
{
|
||||
/* Avoid overtight and overwide paragraphs in the introductory text. */
|
||||
size_t wrapping_point = ((COLS < 40) ? 40 : (COLS > 74) ? 74 : COLS) - sidebar;
|
||||
const char *ptr = start_of_body;
|
||||
size_t sum = 0;
|
||||
|
||||
make_new_buffer();
|
||||
|
||||
/* Ensure there is a blank line at the top of the text, for esthetics. */
|
||||
if ((ISSET(MINIBAR) || !ISSET(EMPTY_LINE)) && LINES > 6) {
|
||||
openfile->current->data = mallocstrcpy(openfile->current->data, " ");
|
||||
openfile->current->next = make_new_node(openfile->current);
|
||||
openfile->current = openfile->current->next;
|
||||
}
|
||||
|
||||
/* Copy the help text into the just-created new buffer. */
|
||||
while (*ptr != '\0') {
|
||||
int length, shim;
|
||||
char *oneline;
|
||||
|
||||
if (ptr == end_of_intro)
|
||||
wrapping_point = ((COLS < 40) ? 40 : COLS) - sidebar;
|
||||
|
||||
if (ptr < end_of_intro || *(ptr - 1) == '\n') {
|
||||
length = break_line(ptr, wrapping_point, TRUE);
|
||||
oneline = nmalloc(length + 1);
|
||||
shim = (*(ptr + length - 1) == ' ') ? 0 : 1;
|
||||
snprintf(oneline, length + shim, "%s", ptr);
|
||||
} else {
|
||||
length = break_line(ptr, ((COLS < 40) ? 22 : COLS - 18) - sidebar, TRUE);
|
||||
oneline = nmalloc(length + 5);
|
||||
snprintf(oneline, length + 5, "\t\t %s", ptr);
|
||||
}
|
||||
|
||||
free(openfile->current->data);
|
||||
openfile->current->data = oneline;
|
||||
|
||||
ptr += length;
|
||||
if (*ptr != '\n')
|
||||
ptr--;
|
||||
|
||||
/* Create a new line, and then one more for each extra \n. */
|
||||
do {
|
||||
openfile->current->next = make_new_node(openfile->current);
|
||||
openfile->current = openfile->current->next;
|
||||
openfile->current->data = copy_of("");
|
||||
} while (*(++ptr) == '\n');
|
||||
}
|
||||
|
||||
openfile->filebot = openfile->current;
|
||||
openfile->current = openfile->filetop;
|
||||
|
||||
remove_magicline();
|
||||
#ifdef ENABLE_COLOR
|
||||
find_and_prime_applicable_syntax();
|
||||
#endif
|
||||
prepare_for_display();
|
||||
|
||||
/* Move to the position in the file where we were before. */
|
||||
while (TRUE) {
|
||||
sum += strlen(openfile->current->data);
|
||||
if (sum > location)
|
||||
break;
|
||||
openfile->current = openfile->current->next;
|
||||
}
|
||||
|
||||
openfile->edittop = openfile->current;
|
||||
}
|
||||
|
||||
/* Assemble a help text, display it, and allow scrolling through it. */
|
||||
void show_help(void)
|
||||
{
|
||||
int kbinput = ERR;
|
||||
functionptrtype function;
|
||||
/* The function of the key the user typed in. */
|
||||
int oldmenu = currmenu;
|
||||
/* The menu we were called from. */
|
||||
#ifdef ENABLE_LINENUMBERS
|
||||
int was_margin = margin;
|
||||
#endif
|
||||
ssize_t was_tabsize = tabsize;
|
||||
#ifdef ENABLE_COLOR
|
||||
char *was_syntax = syntaxstr;
|
||||
#endif
|
||||
char *saved_answer = (answer != NULL) ? copy_of(answer) : NULL;
|
||||
/* The current answer when the user invokes help at the prompt. */
|
||||
unsigned stash[sizeof(flags) / sizeof(flags[0])];
|
||||
/* A storage place for the current flag settings. */
|
||||
linestruct *line;
|
||||
int length;
|
||||
|
||||
/* Save the settings of all flags. */
|
||||
memcpy(stash, flags, sizeof(flags));
|
||||
|
||||
/* Ensure that the help screen's shortcut list can be displayed. */
|
||||
if (ISSET(NO_HELP) || ISSET(ZERO)) {
|
||||
UNSET(NO_HELP);
|
||||
UNSET(ZERO);
|
||||
window_init();
|
||||
} else
|
||||
blank_statusbar();
|
||||
|
||||
/* When searching, do it forward, case insensitive, and without regexes. */
|
||||
UNSET(BACKWARDS_SEARCH);
|
||||
UNSET(CASE_SENSITIVE);
|
||||
UNSET(USE_REGEXP);
|
||||
|
||||
UNSET(WHITESPACE_DISPLAY);
|
||||
|
||||
#ifdef ENABLE_LINENUMBERS
|
||||
editwincols = COLS - sidebar;
|
||||
margin = 0;
|
||||
#endif
|
||||
tabsize = 8;
|
||||
#ifdef ENABLE_COLOR
|
||||
syntaxstr = "nanofurhelp";
|
||||
#endif
|
||||
curs_set(0);
|
||||
|
||||
/* Compose the help text from all the relevant pieces. */
|
||||
help_init();
|
||||
|
||||
inhelp = TRUE;
|
||||
location = 0;
|
||||
didfind = 0;
|
||||
|
||||
bottombars(MHELP);
|
||||
|
||||
/* Extract the title from the head of the help text. */
|
||||
length = break_line(help_text, HIGHEST_POSITIVE, TRUE);
|
||||
title = measured_copy(help_text, length);
|
||||
|
||||
titlebar(title);
|
||||
|
||||
/* Skip over the title to point at the start of the body text. */
|
||||
start_of_body = help_text + length;
|
||||
while (*start_of_body == '\n')
|
||||
start_of_body++;
|
||||
|
||||
wrap_help_text_into_buffer();
|
||||
edit_refresh();
|
||||
|
||||
while (TRUE) {
|
||||
lastmessage = VACUUM;
|
||||
focusing = TRUE;
|
||||
|
||||
/* Show the cursor when we searched and found something. */
|
||||
kbinput = get_kbinput(midwin, didfind == 1 || ISSET(SHOW_CURSOR));
|
||||
|
||||
didfind = 0;
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
spotlighted = FALSE;
|
||||
|
||||
while (bracketed_paste)
|
||||
kbinput = get_kbinput(midwin, BLIND);
|
||||
if (kbinput == BRACKETED_PASTE_MARKER) {
|
||||
beep();
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
function = interpret(kbinput);
|
||||
|
||||
if (ISSET(SHOW_CURSOR) && (function == do_left || function == do_right ||
|
||||
function == do_up || function == do_down)) {
|
||||
function();
|
||||
} else if (function == do_up || function == do_scroll_up) {
|
||||
do_scroll_up();
|
||||
} else if (function == do_down || function == do_scroll_down) {
|
||||
if (openfile->edittop->lineno + editwinrows - 1 < openfile->filebot->lineno)
|
||||
do_scroll_down();
|
||||
} else if (function == do_page_up || function == do_page_down ||
|
||||
function == to_first_line || function == to_last_line) {
|
||||
function();
|
||||
} else if (function == do_search_backward || function == do_search_forward ||
|
||||
function == do_findprevious || function == do_findnext) {
|
||||
function();
|
||||
bottombars(MHELP);
|
||||
#ifdef ENABLE_NANOFURRC
|
||||
} else if (function == (functionptrtype)implant) {
|
||||
implant(first_sc_for(MHELP, function)->expansion);
|
||||
#endif
|
||||
#ifdef ENABLE_MOUSE
|
||||
} else if (kbinput == KEY_MOUSE) {
|
||||
int dummy_row, dummy_col;
|
||||
get_mouseinput(&dummy_row, &dummy_col, TRUE);
|
||||
#endif
|
||||
#ifndef NANOFUR_TINY
|
||||
} else if (kbinput == THE_WINDOW_RESIZED) {
|
||||
; /* Nothing to do. */
|
||||
#endif
|
||||
} else if (function == full_refresh) {
|
||||
full_refresh();
|
||||
} else if (function == do_exit) {
|
||||
break;
|
||||
} else
|
||||
unbound_key(kbinput);
|
||||
|
||||
edit_refresh();
|
||||
|
||||
location = 0;
|
||||
line = openfile->filetop;
|
||||
|
||||
/* Count how far (in bytes) edittop is into the file. */
|
||||
while (line != openfile->edittop) {
|
||||
location += strlen(line->data);
|
||||
line = line->next;
|
||||
}
|
||||
}
|
||||
|
||||
/* Discard the help-text buffer. */
|
||||
close_buffer();
|
||||
|
||||
/* Restore the settings of all flags. */
|
||||
memcpy(flags, stash, sizeof(flags));
|
||||
|
||||
#ifdef ENABLE_LINENUMBERS
|
||||
margin = was_margin;
|
||||
editwincols = COLS - margin - sidebar;
|
||||
#endif
|
||||
tabsize = was_tabsize;
|
||||
#ifdef ENABLE_COLOR
|
||||
syntaxstr = was_syntax;
|
||||
have_palette = FALSE;
|
||||
#endif
|
||||
|
||||
free(title);
|
||||
title = NULL;
|
||||
free(answer);
|
||||
answer = saved_answer;
|
||||
free(help_text);
|
||||
inhelp = FALSE;
|
||||
|
||||
curs_set(0);
|
||||
|
||||
if (ISSET(NO_HELP) || ISSET(ZERO))
|
||||
window_init();
|
||||
else
|
||||
blank_statusbar();
|
||||
|
||||
bottombars(oldmenu);
|
||||
|
||||
#ifdef ENABLE_BROWSER
|
||||
if (oldmenu & (MBROWSER|MWHEREISFILE|MGOTODIR))
|
||||
browser_refresh();
|
||||
else
|
||||
#endif
|
||||
{
|
||||
titlebar(NULL);
|
||||
edit_refresh();
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* ENABLE_HELP */
|
||||
|
||||
/* Start the help viewer, or indicate that there is no help. */
|
||||
void do_help(void)
|
||||
{
|
||||
#ifdef ENABLE_HELP
|
||||
show_help();
|
||||
#else
|
||||
if (currmenu & (MMAIN|MBROWSER))
|
||||
statusbar(_("^W = Ctrl+W M-W = Alt+W"));
|
||||
else
|
||||
beep();
|
||||
#endif
|
||||
}
|
585
src/history.c
Normal file
585
src/history.c
Normal file
|
@ -0,0 +1,585 @@
|
|||
/**************************************************************************
|
||||
* history.c -- This file is part of GNU nanofur. *
|
||||
* *
|
||||
* Copyright (C) 2003-2011, 2013-2024 Free Software Foundation, Inc. *
|
||||
* Copyright (C) 2016, 2017, 2019 Benno Schulenberg *
|
||||
* *
|
||||
* GNU nanofur 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. *
|
||||
* *
|
||||
* GNU nanofur 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 http://www.gnu.org/licenses/. *
|
||||
* *
|
||||
**************************************************************************/
|
||||
|
||||
#include "prototypes.h"
|
||||
|
||||
#ifdef ENABLE_HISTORIES
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef SEARCH_HISTORY
|
||||
#define SEARCH_HISTORY "search_history"
|
||||
#endif
|
||||
|
||||
#ifndef POSITION_HISTORY
|
||||
#define POSITION_HISTORY "filepos_history"
|
||||
#endif
|
||||
|
||||
static bool history_changed = FALSE;
|
||||
/* Whether any of the history lists has changed. */
|
||||
static char *poshistname = NULL;
|
||||
/* The name of the positions-history file. */
|
||||
static time_t latest_timestamp = 942927132;
|
||||
/* The last time the positions-history file was written. */
|
||||
static poshiststruct *position_history = NULL;
|
||||
/* The list of filenames with their last cursor positions. */
|
||||
|
||||
/* Initialize the lists of historical search and replace strings
|
||||
* and the list of historical executed commands. */
|
||||
void history_init(void)
|
||||
{
|
||||
search_history = make_new_node(NULL);
|
||||
search_history->data = copy_of("");
|
||||
searchtop = search_history;
|
||||
searchbot = search_history;
|
||||
|
||||
replace_history = make_new_node(NULL);
|
||||
replace_history->data = copy_of("");
|
||||
replacetop = replace_history;
|
||||
replacebot = replace_history;
|
||||
|
||||
execute_history = make_new_node(NULL);
|
||||
execute_history->data = copy_of("");
|
||||
executetop = execute_history;
|
||||
executebot = execute_history;
|
||||
}
|
||||
|
||||
/* Reset the pointer into the history list that contains item to the bottom. */
|
||||
void reset_history_pointer_for(const linestruct *item)
|
||||
{
|
||||
if (item == search_history)
|
||||
search_history = searchbot;
|
||||
else if (item == replace_history)
|
||||
replace_history = replacebot;
|
||||
else if (item == execute_history)
|
||||
execute_history = executebot;
|
||||
}
|
||||
|
||||
/* Return from the history list that starts at start and ends at end
|
||||
* the first node that contains the first len characters of the given
|
||||
* text, or NULL if there is no such node. */
|
||||
linestruct *find_in_history(const linestruct *start, const linestruct *end,
|
||||
const char *text, size_t len)
|
||||
{
|
||||
const linestruct *item;
|
||||
|
||||
for (item = start; item != end->prev && item != NULL; item = item->prev) {
|
||||
if (strncmp(item->data, text, len) == 0)
|
||||
return (linestruct *)item;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Update a history list (the one in which item is the current position)
|
||||
* with a fresh string text. That is: add text, or move it to the end. */
|
||||
void update_history(linestruct **item, const char *text, bool avoid_duplicates)
|
||||
{
|
||||
linestruct **htop = NULL, **hbot = NULL;
|
||||
linestruct *thesame = NULL;
|
||||
|
||||
if (*item == search_history) {
|
||||
htop = &searchtop;
|
||||
hbot = &searchbot;
|
||||
} else if (*item == replace_history) {
|
||||
htop = &replacetop;
|
||||
hbot = &replacebot;
|
||||
} else if (*item == execute_history) {
|
||||
htop = &executetop;
|
||||
hbot = &executebot;
|
||||
}
|
||||
|
||||
/* When requested, check if the string is already in the history. */
|
||||
if (avoid_duplicates)
|
||||
thesame = find_in_history(*hbot, *htop, text, HIGHEST_POSITIVE);
|
||||
|
||||
/* If an identical string was found, delete that item. */
|
||||
if (thesame) {
|
||||
linestruct *after = thesame->next;
|
||||
|
||||
/* If the string is at the head of the list, move the head. */
|
||||
if (thesame == *htop)
|
||||
*htop = after;
|
||||
|
||||
unlink_node(thesame);
|
||||
renumber_from(after);
|
||||
}
|
||||
|
||||
/* If the history is full, delete the oldest item (the one at the
|
||||
* head of the list), to make room for a new item at the end. */
|
||||
if ((*hbot)->lineno == MAX_SEARCH_HISTORY + 1) {
|
||||
linestruct *oldest = *htop;
|
||||
|
||||
*htop = (*htop)->next;
|
||||
unlink_node(oldest);
|
||||
renumber_from(*htop);
|
||||
}
|
||||
|
||||
/* Store the fresh string in the last item, then create a new item. */
|
||||
(*hbot)->data = mallocstrcpy((*hbot)->data, text);
|
||||
splice_node(*hbot, make_new_node(*hbot));
|
||||
*hbot = (*hbot)->next;
|
||||
(*hbot)->data = copy_of("");
|
||||
|
||||
/* Indicate that the history needs to be saved on exit. */
|
||||
history_changed = TRUE;
|
||||
|
||||
/* Set the current position in the list to the bottom. */
|
||||
*item = *hbot;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_TABCOMP
|
||||
/* Go backward through one of three history lists, starting at item *here,
|
||||
* searching for a string that is a tab completion of the given string,
|
||||
* looking at only its first len characters. When found, make *here point
|
||||
* at the item and return its string; otherwise, just return the string. */
|
||||
char *get_history_completion(linestruct **here, char *string, size_t len)
|
||||
{
|
||||
linestruct *htop = NULL, *hbot = NULL;
|
||||
linestruct *item;
|
||||
|
||||
if (*here == search_history) {
|
||||
htop = searchtop;
|
||||
hbot = searchbot;
|
||||
} else if (*here == replace_history) {
|
||||
htop = replacetop;
|
||||
hbot = replacebot;
|
||||
} else if (*here == execute_history) {
|
||||
htop = executetop;
|
||||
hbot = executebot;
|
||||
}
|
||||
|
||||
/* First search from the current position to the top of the list
|
||||
* for a match of len characters. Skip over an exact match. */
|
||||
item = find_in_history((*here)->prev, htop, string, len);
|
||||
|
||||
while (item != NULL && strcmp(item->data, string) == 0)
|
||||
item = find_in_history(item->prev, htop, string, len);
|
||||
|
||||
if (item) {
|
||||
*here = item;
|
||||
return mallocstrcpy(string, item->data);
|
||||
}
|
||||
|
||||
/* Now search from the bottom of the list to the original position. */
|
||||
item = find_in_history(hbot, *here, string, len);
|
||||
|
||||
while (item != NULL && strcmp(item->data, string) == 0)
|
||||
item = find_in_history(item->prev, *here, string, len);
|
||||
|
||||
if (item) {
|
||||
*here = item;
|
||||
return mallocstrcpy(string, item->data);
|
||||
}
|
||||
|
||||
/* When no useful match was found, simply return the given string. */
|
||||
return (char *)string;
|
||||
}
|
||||
#endif /* ENABLE_TABCOMP */
|
||||
|
||||
/* Check whether we have or could make a directory for history files. */
|
||||
bool have_statedir(void)
|
||||
{
|
||||
const char *xdgdatadir;
|
||||
struct stat dirinfo;
|
||||
|
||||
get_homedir();
|
||||
|
||||
if (homedir != NULL) {
|
||||
statedir = concatenate(homedir, "/.nanofur/");
|
||||
|
||||
if (stat(statedir, &dirinfo) == 0 && S_ISDIR(dirinfo.st_mode)) {
|
||||
poshistname = concatenate(statedir, POSITION_HISTORY);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
free(statedir);
|
||||
xdgdatadir = getenv("XDG_DATA_HOME");
|
||||
|
||||
if (homedir == NULL && xdgdatadir == NULL)
|
||||
return FALSE;
|
||||
|
||||
if (xdgdatadir != NULL)
|
||||
statedir = concatenate(xdgdatadir, "/nanofur/");
|
||||
else
|
||||
statedir = concatenate(homedir, "/.local/share/nanofur/");
|
||||
|
||||
if (stat(statedir, &dirinfo) == -1) {
|
||||
if (xdgdatadir == NULL) {
|
||||
char *statepath = concatenate(homedir, "/.local");
|
||||
mkdir(statepath, S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
free(statepath);
|
||||
statepath = concatenate(homedir, "/.local/share");
|
||||
mkdir(statepath, S_IRWXU);
|
||||
free(statepath);
|
||||
}
|
||||
if (mkdir(statedir, S_IRWXU) == -1) {
|
||||
jot_error(N_("Unable to create directory %s: %s\n"
|
||||
"It is required for saving/loading "
|
||||
"search history or cursor positions.\n"),
|
||||
statedir, strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
} else if (!S_ISDIR(dirinfo.st_mode)) {
|
||||
jot_error(N_("Path %s is not a directory and needs to be.\n"
|
||||
"Nanofur will be unable to load or save "
|
||||
"search history or cursor positions.\n"),
|
||||
statedir);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
poshistname = concatenate(statedir, POSITION_HISTORY);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Load the histories for Search, Replace With, and Execute Command. */
|
||||
void load_history(void)
|
||||
{
|
||||
char *histname = concatenate(statedir, SEARCH_HISTORY);
|
||||
FILE *histfile = fopen(histname, "rb");
|
||||
|
||||
/* If reading an existing file failed, don't save history when we quit. */
|
||||
if (histfile == NULL && errno != ENOENT) {
|
||||
jot_error(N_("Error reading %s: %s"), histname, strerror(errno));
|
||||
UNSET(HISTORYLOG);
|
||||
}
|
||||
|
||||
if (histfile == NULL) {
|
||||
free(histname);
|
||||
return;
|
||||
}
|
||||
|
||||
linestruct **history = &search_history;
|
||||
char *stanza = NULL;
|
||||
size_t dummy = 0;
|
||||
ssize_t read;
|
||||
|
||||
/* Load the three history lists (first search, then replace, then execute)
|
||||
* from oldest entry to newest. Between two lists there is an empty line. */
|
||||
while ((read = getline(&stanza, &dummy, histfile)) > 0) {
|
||||
stanza[--read] = '\0';
|
||||
if (read > 0) {
|
||||
recode_NUL_to_LF(stanza, read);
|
||||
update_history(history, stanza, IGNORE_DUPLICATES);
|
||||
} else if (history == &search_history)
|
||||
history = &replace_history;
|
||||
else
|
||||
history = &execute_history;
|
||||
}
|
||||
|
||||
if (fclose(histfile) == EOF)
|
||||
jot_error(N_("Error reading %s: %s"), histname, strerror(errno));
|
||||
|
||||
free(histname);
|
||||
free(stanza);
|
||||
|
||||
/* Reading in the lists has marked them as changed; undo this side effect. */
|
||||
history_changed = FALSE;
|
||||
}
|
||||
|
||||
/* Write the lines of a history list, starting at head, from oldest to newest,
|
||||
* to the given file. Return TRUE if writing succeeded, and FALSE otherwise. */
|
||||
bool write_list(const linestruct *head, FILE *histfile)
|
||||
{
|
||||
const linestruct *item;
|
||||
|
||||
for (item = head; item != NULL; item = item->next) {
|
||||
/* Decode 0x0A bytes as embedded NULs. */
|
||||
size_t length = recode_LF_to_NUL(item->data);
|
||||
|
||||
if (fwrite(item->data, 1, length, histfile) < length)
|
||||
return FALSE;
|
||||
if (putc('\n', histfile) == EOF)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Save the histories for Search, Replace With, and Execute Command. */
|
||||
void save_history(void)
|
||||
{
|
||||
char *histname;
|
||||
FILE *histfile;
|
||||
|
||||
/* If the histories are unchanged, don't bother saving them. */
|
||||
if (!history_changed)
|
||||
return;
|
||||
|
||||
histname = concatenate(statedir, SEARCH_HISTORY);
|
||||
histfile = fopen(histname, "wb");
|
||||
|
||||
if (histfile == NULL) {
|
||||
jot_error(N_("Error writing %s: %s"), histname, strerror(errno));
|
||||
free(histname);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Don't allow others to read or write the history file. */
|
||||
if (chmod(histname, S_IRUSR | S_IWUSR) < 0)
|
||||
jot_error(N_("Cannot limit permissions on %s: %s"), histname, strerror(errno));
|
||||
|
||||
if (!write_list(searchtop, histfile) || !write_list(replacetop, histfile) ||
|
||||
!write_list(executetop, histfile))
|
||||
jot_error(N_("Error writing %s: %s"), histname, strerror(errno));
|
||||
|
||||
if (fclose(histfile) == EOF)
|
||||
jot_error(N_("Error writing %s: %s"), histname, strerror(errno));
|
||||
|
||||
free(histname);
|
||||
}
|
||||
|
||||
/* Load the recorded cursor positions for files that were edited. */
|
||||
void load_poshistory(void)
|
||||
{
|
||||
FILE *histfile = fopen(poshistname, "rb");
|
||||
|
||||
/* If reading an existing file failed, don't save history when we quit. */
|
||||
if (histfile == NULL && errno != ENOENT) {
|
||||
jot_error(N_("Error reading %s: %s"), poshistname, strerror(errno));
|
||||
UNSET(POSITIONLOG);
|
||||
}
|
||||
|
||||
if (histfile == NULL)
|
||||
return;
|
||||
|
||||
poshiststruct *lastitem = NULL;
|
||||
poshiststruct *newitem;
|
||||
char *lineptr, *columnptr;
|
||||
char *stanza = NULL;
|
||||
struct stat fileinfo;
|
||||
size_t dummy = 0;
|
||||
ssize_t count = 0;
|
||||
ssize_t read;
|
||||
|
||||
/* Read and parse each line, and store the extracted data. */
|
||||
while ((read = getline(&stanza, &dummy, histfile)) > 5) {
|
||||
/* Decode NULs as embedded newlines. */
|
||||
recode_NUL_to_LF(stanza, read);
|
||||
|
||||
/* Find the spaces before column number and line number. */
|
||||
columnptr = revstrstr(stanza, " ", stanza + read - 3);
|
||||
if (columnptr == NULL)
|
||||
continue;
|
||||
lineptr = revstrstr(stanza, " ", columnptr - 2);
|
||||
if (lineptr == NULL)
|
||||
continue;
|
||||
|
||||
/* Now separate the three elements of the line. */
|
||||
*(columnptr++) = '\0';
|
||||
*(lineptr++) = '\0';
|
||||
|
||||
/* Create a new position record. */
|
||||
newitem = nmalloc(sizeof(poshiststruct));
|
||||
newitem->filename = copy_of(stanza);
|
||||
newitem->linenumber = atoi(lineptr);
|
||||
newitem->columnnumber = atoi(columnptr);
|
||||
newitem->next = NULL;
|
||||
|
||||
/* Add the record to the list. */
|
||||
if (position_history == NULL)
|
||||
position_history = newitem;
|
||||
else
|
||||
lastitem->next = newitem;
|
||||
|
||||
lastitem = newitem;
|
||||
|
||||
/* Impose a limit, so the file will not grow indefinitely. */
|
||||
if (++count > 200) {
|
||||
poshiststruct *drop_record = position_history;
|
||||
|
||||
position_history = position_history->next;
|
||||
|
||||
free(drop_record->filename);
|
||||
free(drop_record);
|
||||
}
|
||||
}
|
||||
|
||||
if (fclose(histfile) == EOF)
|
||||
jot_error(N_("Error reading %s: %s"), poshistname, strerror(errno));
|
||||
|
||||
free(stanza);
|
||||
|
||||
if (stat(poshistname, &fileinfo) == 0)
|
||||
latest_timestamp = fileinfo.st_mtime;
|
||||
}
|
||||
|
||||
/* Save the recorded cursor positions for files that were edited. */
|
||||
void save_poshistory(void)
|
||||
{
|
||||
FILE *histfile = fopen(poshistname, "wb");
|
||||
struct stat fileinfo;
|
||||
poshiststruct *item;
|
||||
|
||||
if (histfile == NULL) {
|
||||
jot_error(N_("Error writing %s: %s"), poshistname, strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
/* Don't allow others to read or write the history file. */
|
||||
if (chmod(poshistname, S_IRUSR | S_IWUSR) < 0)
|
||||
jot_error(N_("Cannot limit permissions on %s: %s"), poshistname, strerror(errno));
|
||||
|
||||
for (item = position_history; item != NULL; item = item->next) {
|
||||
char *path_and_place;
|
||||
size_t length;
|
||||
|
||||
/* Assume 20 decimal positions each for line and column number,
|
||||
* plus two spaces, plus the line feed, plus the null byte. */
|
||||
path_and_place = nmalloc(strlen(item->filename) + 44);
|
||||
sprintf(path_and_place, "%s %zd %zd\n",
|
||||
item->filename, item->linenumber, item->columnnumber);
|
||||
|
||||
/* Encode newlines in filenames as NULs. */
|
||||
length = recode_LF_to_NUL(path_and_place);
|
||||
/* Restore the terminating newline. */
|
||||
path_and_place[length - 1] = '\n';
|
||||
|
||||
if (fwrite(path_and_place, 1, length, histfile) < length)
|
||||
jot_error(N_("Error writing %s: %s"), poshistname, strerror(errno));
|
||||
|
||||
free(path_and_place);
|
||||
}
|
||||
|
||||
if (fclose(histfile) == EOF)
|
||||
jot_error(N_("Error writing %s: %s"), poshistname, strerror(errno));
|
||||
|
||||
if (stat(poshistname, &fileinfo) == 0)
|
||||
latest_timestamp = fileinfo.st_mtime;
|
||||
}
|
||||
|
||||
/* Reload the position history file if it has been modified since last load. */
|
||||
void reload_positions_if_needed(void)
|
||||
{
|
||||
poshiststruct *item, *nextone;
|
||||
struct stat fileinfo;
|
||||
|
||||
if (stat(poshistname, &fileinfo) != 0 || fileinfo.st_mtime == latest_timestamp)
|
||||
return;
|
||||
|
||||
for (item = position_history; item != NULL; item = nextone) {
|
||||
nextone = item->next;
|
||||
free(item->filename);
|
||||
free(item);
|
||||
}
|
||||
|
||||
position_history = NULL;
|
||||
|
||||
load_poshistory();
|
||||
}
|
||||
|
||||
/* Update the recorded last file positions with the current position in the
|
||||
* current buffer. If no existing entry is found, add a new one at the end. */
|
||||
void update_poshistory(void)
|
||||
{
|
||||
char *fullpath = get_full_path(openfile->filename);
|
||||
poshiststruct *previous = NULL;
|
||||
poshiststruct *item, *theone;
|
||||
|
||||
if (fullpath == NULL || openfile->filename[0] == '\0') {
|
||||
free(fullpath);
|
||||
return;
|
||||
}
|
||||
|
||||
reload_positions_if_needed();
|
||||
|
||||
/* Look for a matching filename in the list. */
|
||||
for (item = position_history; item != NULL; item = item->next) {
|
||||
if (!strcmp(item->filename, fullpath))
|
||||
break;
|
||||
previous = item;
|
||||
}
|
||||
|
||||
/* Don't record files that have the default cursor position. */
|
||||
if (openfile->current->lineno == 1 && openfile->current_x == 0) {
|
||||
if (item != NULL) {
|
||||
if (previous == NULL)
|
||||
position_history = item->next;
|
||||
else
|
||||
previous->next = item->next;
|
||||
free(item->filename);
|
||||
free(item);
|
||||
save_poshistory();
|
||||
}
|
||||
free(fullpath);
|
||||
return;
|
||||
}
|
||||
|
||||
theone = item;
|
||||
|
||||
/* If we didn't find it, make a new node; otherwise, if we're
|
||||
* not at the end, move the matching one to the end. */
|
||||
if (theone == NULL) {
|
||||
theone = nmalloc(sizeof(poshiststruct));
|
||||
theone->filename = copy_of(fullpath);
|
||||
if (position_history == NULL)
|
||||
position_history = theone;
|
||||
else
|
||||
previous->next = theone;
|
||||
} else if (item->next != NULL) {
|
||||
if (previous == NULL)
|
||||
position_history = item->next;
|
||||
else
|
||||
previous->next = item->next;
|
||||
while (item->next != NULL)
|
||||
item = item->next;
|
||||
item->next = theone;
|
||||
}
|
||||
|
||||
/* Store the last cursor position. */
|
||||
theone->linenumber = openfile->current->lineno;
|
||||
theone->columnnumber = xplustabs() + 1;
|
||||
theone->next = NULL;
|
||||
|
||||
free(fullpath);
|
||||
|
||||
save_poshistory();
|
||||
}
|
||||
|
||||
/* Check whether the given file matches an existing entry in the recorded
|
||||
* last file positions. If not, return FALSE. If yes, return TRUE and
|
||||
* set line and column to the retrieved values. */
|
||||
bool has_old_position(const char *file, ssize_t *line, ssize_t *column)
|
||||
{
|
||||
char *fullpath = get_full_path(file);
|
||||
poshiststruct *item;
|
||||
|
||||
if (fullpath == NULL)
|
||||
return FALSE;
|
||||
|
||||
reload_positions_if_needed();
|
||||
|
||||
item = position_history;
|
||||
while (item != NULL && strcmp(item->filename, fullpath) != 0)
|
||||
item = item->next;
|
||||
|
||||
free(fullpath);
|
||||
|
||||
if (item == NULL)
|
||||
return FALSE;
|
||||
|
||||
*line = item->linenumber;
|
||||
*column = item->columnnumber;
|
||||
return TRUE;
|
||||
}
|
||||
#endif /* ENABLE_HISTORIES */
|
691
src/move.c
Normal file
691
src/move.c
Normal file
|
@ -0,0 +1,691 @@
|
|||
/**************************************************************************
|
||||
* move.c -- This file is part of GNU nanofur. *
|
||||
* *
|
||||
* Copyright (C) 1999-2011, 2013-2024 Free Software Foundation, Inc. *
|
||||
* Copyright (C) 2014-2018 Benno Schulenberg *
|
||||
* *
|
||||
* GNU nanofur 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. *
|
||||
* *
|
||||
* GNU nanofur 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 http://www.gnu.org/licenses/. *
|
||||
* *
|
||||
**************************************************************************/
|
||||
|
||||
#include "prototypes.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/* Move to the first line of the file. */
|
||||
void to_first_line(void)
|
||||
{
|
||||
openfile->current = openfile->filetop;
|
||||
openfile->current_x = 0;
|
||||
openfile->placewewant = 0;
|
||||
|
||||
refresh_needed = TRUE;
|
||||
}
|
||||
|
||||
/* Move to the last line of the file. */
|
||||
void to_last_line(void)
|
||||
{
|
||||
openfile->current = openfile->filebot;
|
||||
openfile->current_x = (inhelp) ? 0 : strlen(openfile->filebot->data);
|
||||
openfile->placewewant = xplustabs();
|
||||
|
||||
/* Set the last line of the screen as the target for the cursor. */
|
||||
openfile->cursor_row = editwinrows - 1;
|
||||
|
||||
refresh_needed = TRUE;
|
||||
#ifdef ENABLE_COLOR
|
||||
recook |= perturbed;
|
||||
#endif
|
||||
focusing = FALSE;
|
||||
}
|
||||
|
||||
/* Determine the actual current chunk and the target column. */
|
||||
void get_edge_and_target(size_t *leftedge, size_t *target_column)
|
||||
{
|
||||
#ifndef NANOFUR_TINY
|
||||
if (ISSET(SOFTWRAP)) {
|
||||
size_t shim = editwincols * (1 + (tabsize / editwincols));
|
||||
|
||||
*leftedge = leftedge_for(xplustabs(), openfile->current);
|
||||
*target_column = (openfile->placewewant + shim - *leftedge) % editwincols;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
*leftedge = 0;
|
||||
*target_column = openfile->placewewant;
|
||||
}
|
||||
}
|
||||
|
||||
/* Return the index in line->data that corresponds to the given column on the
|
||||
* chunk that starts at the given leftedge. If the target column has landed
|
||||
* on a tab, prevent the cursor from falling back a row when moving forward,
|
||||
* or from skipping a row when moving backward, by incrementing the index. */
|
||||
size_t proper_x(linestruct *line, size_t *leftedge, bool forward,
|
||||
size_t column, bool *shifted)
|
||||
{
|
||||
size_t index = actual_x(line->data, column);
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
if (ISSET(SOFTWRAP) && line->data[index] == '\t' &&
|
||||
((forward && wideness(line->data, index) < *leftedge) ||
|
||||
(!forward && column / tabsize == (*leftedge - 1) / tabsize &&
|
||||
column / tabsize < (*leftedge + editwincols - 1) / tabsize))) {
|
||||
index++;
|
||||
|
||||
if (shifted != NULL)
|
||||
*shifted = TRUE;
|
||||
}
|
||||
|
||||
if (ISSET(SOFTWRAP))
|
||||
*leftedge = leftedge_for(wideness(line->data, index), line);
|
||||
#endif
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
/* Adjust the values for current_x and placewewant in case we have landed in
|
||||
* the middle of a tab that crosses a row boundary. */
|
||||
void set_proper_index_and_pww(size_t *leftedge, size_t target, bool forward)
|
||||
{
|
||||
size_t was_edge = *leftedge;
|
||||
bool shifted = FALSE;
|
||||
|
||||
openfile->current_x = proper_x(openfile->current, leftedge, forward,
|
||||
actual_last_column(*leftedge, target), &shifted);
|
||||
|
||||
/* If the index was incremented, try going to the target column. */
|
||||
if (shifted || *leftedge < was_edge)
|
||||
openfile->current_x = proper_x(openfile->current, leftedge, forward,
|
||||
actual_last_column(*leftedge, target), &shifted);
|
||||
|
||||
openfile->placewewant = *leftedge + target;
|
||||
}
|
||||
|
||||
/* Move up almost one screenful. */
|
||||
void do_page_up(void)
|
||||
{
|
||||
int mustmove = (editwinrows < 3) ? 1 : editwinrows - 2;
|
||||
size_t leftedge, target_column;
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
/* If we're not in smooth scrolling mode, put the cursor at the
|
||||
* beginning of the top line of the edit window, as Pico does. */
|
||||
if (ISSET(JUMPY_SCROLLING)) {
|
||||
openfile->current = openfile->edittop;
|
||||
leftedge = openfile->firstcolumn;
|
||||
openfile->cursor_row = 0;
|
||||
target_column = 0;
|
||||
} else
|
||||
#endif
|
||||
get_edge_and_target(&leftedge, &target_column);
|
||||
|
||||
/* Move up the required number of lines or chunks. If we can't, we're
|
||||
* at the top of the file, so put the cursor there and get out. */
|
||||
if (go_back_chunks(mustmove, &openfile->current, &leftedge) > 0) {
|
||||
to_first_line();
|
||||
return;
|
||||
}
|
||||
|
||||
set_proper_index_and_pww(&leftedge, target_column, FALSE);
|
||||
|
||||
/* Move the viewport so that the cursor stays immobile, if possible. */
|
||||
adjust_viewport(STATIONARY);
|
||||
refresh_needed = TRUE;
|
||||
}
|
||||
|
||||
/* Move down almost one screenful. */
|
||||
void do_page_down(void)
|
||||
{
|
||||
int mustmove = (editwinrows < 3) ? 1 : editwinrows - 2;
|
||||
size_t leftedge, target_column;
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
/* If we're not in smooth scrolling mode, put the cursor at the
|
||||
* beginning of the top line of the edit window, as Pico does. */
|
||||
if (ISSET(JUMPY_SCROLLING)) {
|
||||
openfile->current = openfile->edittop;
|
||||
leftedge = openfile->firstcolumn;
|
||||
openfile->cursor_row = 0;
|
||||
target_column = 0;
|
||||
} else
|
||||
#endif
|
||||
get_edge_and_target(&leftedge, &target_column);
|
||||
|
||||
/* Move down the required number of lines or chunks. If we can't, we're
|
||||
* at the bottom of the file, so put the cursor there and get out. */
|
||||
if (go_forward_chunks(mustmove, &openfile->current, &leftedge) > 0) {
|
||||
to_last_line();
|
||||
return;
|
||||
}
|
||||
|
||||
set_proper_index_and_pww(&leftedge, target_column, TRUE);
|
||||
|
||||
/* Move the viewport so that the cursor stays immobile, if possible. */
|
||||
adjust_viewport(STATIONARY);
|
||||
refresh_needed = TRUE;
|
||||
}
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
/* Place the cursor on the first row in the viewport. */
|
||||
void to_top_row(void)
|
||||
{
|
||||
size_t leftedge, offset;
|
||||
|
||||
get_edge_and_target(&leftedge, &offset);
|
||||
|
||||
openfile->current = openfile->edittop;
|
||||
leftedge = openfile->firstcolumn;
|
||||
|
||||
set_proper_index_and_pww(&leftedge, offset, FALSE);
|
||||
|
||||
refresh_needed = (openfile->mark != NULL);
|
||||
}
|
||||
|
||||
/* Place the cursor on the last row in the viewport, when possible. */
|
||||
void to_bottom_row(void)
|
||||
{
|
||||
size_t leftedge, offset;
|
||||
|
||||
get_edge_and_target(&leftedge, &offset);
|
||||
|
||||
openfile->current = openfile->edittop;
|
||||
leftedge = openfile->firstcolumn;
|
||||
|
||||
go_forward_chunks(editwinrows - 1, &openfile->current, &leftedge);
|
||||
set_proper_index_and_pww(&leftedge, offset, TRUE);
|
||||
|
||||
refresh_needed = (openfile->mark != NULL);
|
||||
}
|
||||
|
||||
/* Put the cursor line at the center, then the top, then the bottom. */
|
||||
void do_cycle(void)
|
||||
{
|
||||
if (cycling_aim == 0)
|
||||
adjust_viewport(CENTERING);
|
||||
else {
|
||||
openfile->cursor_row = (cycling_aim == 1) ? 0 : editwinrows - 1;
|
||||
adjust_viewport(STATIONARY);
|
||||
}
|
||||
|
||||
cycling_aim = (cycling_aim + 1) % 3;
|
||||
|
||||
draw_all_subwindows();
|
||||
full_refresh();
|
||||
}
|
||||
|
||||
/* Scroll the line with the cursor to the center of the screen. */
|
||||
void do_center(void)
|
||||
{
|
||||
do_cycle(); /* The main loop has set 'cycling_aim' to zero. */
|
||||
}
|
||||
#endif /* !NANOFUR_TINY */
|
||||
|
||||
#ifdef ENABLE_JUSTIFY
|
||||
/* Move to the first beginning of a paragraph before the current line. */
|
||||
void do_para_begin(linestruct **line)
|
||||
{
|
||||
if ((*line)->prev != NULL)
|
||||
*line = (*line)->prev;
|
||||
|
||||
while (!begpar(*line, 0))
|
||||
*line = (*line)->prev;
|
||||
}
|
||||
|
||||
/* Move down to the last line of the first found paragraph. */
|
||||
void do_para_end(linestruct **line)
|
||||
{
|
||||
while ((*line)->next != NULL && !inpar(*line))
|
||||
*line = (*line)->next;
|
||||
|
||||
while ((*line)->next != NULL && inpar((*line)->next) &&
|
||||
!begpar((*line)->next, 0))
|
||||
*line = (*line)->next;
|
||||
}
|
||||
|
||||
/* Move up to first start of a paragraph before the current line. */
|
||||
void to_para_begin(void)
|
||||
{
|
||||
linestruct *was_current = openfile->current;
|
||||
|
||||
do_para_begin(&openfile->current);
|
||||
openfile->current_x = 0;
|
||||
|
||||
edit_redraw(was_current, CENTERING);
|
||||
}
|
||||
|
||||
/* Move down to just after the first found end of a paragraph. */
|
||||
void to_para_end(void)
|
||||
{
|
||||
linestruct *was_current = openfile->current;
|
||||
|
||||
do_para_end(&openfile->current);
|
||||
|
||||
/* Step beyond the last line of the paragraph, if possible;
|
||||
* otherwise, move to the end of the line. */
|
||||
if (openfile->current->next != NULL) {
|
||||
openfile->current = openfile->current->next;
|
||||
openfile->current_x = 0;
|
||||
} else
|
||||
openfile->current_x = strlen(openfile->current->data);
|
||||
|
||||
edit_redraw(was_current, CENTERING);
|
||||
#ifdef ENABLE_COLOR
|
||||
recook |= perturbed;
|
||||
#endif
|
||||
}
|
||||
#endif /* ENABLE_JUSTIFY */
|
||||
|
||||
/* Move to the preceding block of text. */
|
||||
void to_prev_block(void)
|
||||
{
|
||||
linestruct *was_current = openfile->current;
|
||||
bool is_text = FALSE, seen_text = FALSE;
|
||||
|
||||
/* Skip backward until first blank line after some nonblank line(s). */
|
||||
while (openfile->current->prev != NULL && (!seen_text || is_text)) {
|
||||
openfile->current = openfile->current->prev;
|
||||
is_text = !white_string(openfile->current->data);
|
||||
seen_text = seen_text || is_text;
|
||||
}
|
||||
|
||||
/* Step forward one line again if we passed text but this line is blank. */
|
||||
if (seen_text && openfile->current->next != NULL &&
|
||||
white_string(openfile->current->data))
|
||||
openfile->current = openfile->current->next;
|
||||
|
||||
openfile->current_x = 0;
|
||||
edit_redraw(was_current, CENTERING);
|
||||
}
|
||||
|
||||
/* Move to the next block of text. */
|
||||
void to_next_block(void)
|
||||
{
|
||||
linestruct *was_current = openfile->current;
|
||||
bool is_white = white_string(openfile->current->data);
|
||||
bool seen_white = is_white;
|
||||
|
||||
/* Skip forward until first nonblank line after some blank line(s). */
|
||||
while (openfile->current->next != NULL && (!seen_white || is_white)) {
|
||||
openfile->current = openfile->current->next;
|
||||
is_white = white_string(openfile->current->data);
|
||||
seen_white = seen_white || is_white;
|
||||
}
|
||||
|
||||
openfile->current_x = 0;
|
||||
edit_redraw(was_current, CENTERING);
|
||||
#ifdef ENABLE_COLOR
|
||||
recook |= perturbed;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Move to the previous word. */
|
||||
void do_prev_word(void)
|
||||
{
|
||||
bool punctuation_as_letters = ISSET(WORD_BOUNDS);
|
||||
bool seen_a_word = FALSE, step_forward = FALSE;
|
||||
|
||||
/* Move backward until we pass over the start of a word. */
|
||||
while (TRUE) {
|
||||
/* If at the head of a line, move to the end of the preceding one. */
|
||||
if (openfile->current_x == 0) {
|
||||
if (openfile->current->prev == NULL)
|
||||
break;
|
||||
openfile->current = openfile->current->prev;
|
||||
openfile->current_x = strlen(openfile->current->data);
|
||||
}
|
||||
|
||||
/* Step back one character. */
|
||||
openfile->current_x = step_left(openfile->current->data,
|
||||
openfile->current_x);
|
||||
|
||||
if (is_word_char(openfile->current->data + openfile->current_x,
|
||||
punctuation_as_letters)) {
|
||||
seen_a_word = TRUE;
|
||||
/* If at the head of a line now, this surely is a word start. */
|
||||
if (openfile->current_x == 0)
|
||||
break;
|
||||
#ifdef ENABLE_UTF8
|
||||
} else if (is_zerowidth(openfile->current->data + openfile->current_x)) {
|
||||
; /* skip */
|
||||
#endif
|
||||
} else if (seen_a_word) {
|
||||
/* This is space now: we've overshot the start of the word. */
|
||||
step_forward = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (step_forward)
|
||||
/* Move one character forward again to sit on the start of the word. */
|
||||
openfile->current_x = step_right(openfile->current->data,
|
||||
openfile->current_x);
|
||||
}
|
||||
|
||||
/* Move to the next word. If after_ends is TRUE, stop at the ends of words
|
||||
* instead of at their beginnings. Return TRUE if we started on a word. */
|
||||
bool do_next_word(bool after_ends)
|
||||
{
|
||||
bool punctuation_as_letters = ISSET(WORD_BOUNDS);
|
||||
bool started_on_word = is_word_char(openfile->current->data +
|
||||
openfile->current_x, punctuation_as_letters);
|
||||
bool seen_space = !started_on_word;
|
||||
#ifndef NANOFUR_TINY
|
||||
bool seen_word = started_on_word;
|
||||
#endif
|
||||
|
||||
/* Move forward until we reach the start of a word. */
|
||||
while (TRUE) {
|
||||
/* If at the end of a line, move to the beginning of the next one. */
|
||||
if (openfile->current->data[openfile->current_x] == '\0') {
|
||||
/* When at end of file, stop. */
|
||||
if (openfile->current->next == NULL)
|
||||
break;
|
||||
openfile->current = openfile->current->next;
|
||||
openfile->current_x = 0;
|
||||
seen_space = TRUE;
|
||||
} else {
|
||||
/* Step forward one character. */
|
||||
openfile->current_x = step_right(openfile->current->data,
|
||||
openfile->current_x);
|
||||
}
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
if (after_ends) {
|
||||
/* If this is a word character, continue; else it's a separator,
|
||||
* and if we've already seen a word, then it's a word end. */
|
||||
if (is_word_char(openfile->current->data + openfile->current_x,
|
||||
punctuation_as_letters))
|
||||
seen_word = TRUE;
|
||||
#ifdef ENABLE_UTF8
|
||||
else if (is_zerowidth(openfile->current->data + openfile->current_x))
|
||||
; /* skip */
|
||||
#endif
|
||||
else if (seen_word)
|
||||
break;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
#ifdef ENABLE_UTF8
|
||||
if (is_zerowidth(openfile->current->data + openfile->current_x))
|
||||
; /* skip */
|
||||
else
|
||||
#endif
|
||||
/* If this is not a word character, then it's a separator; else
|
||||
* if we've already seen a separator, then it's a word start. */
|
||||
if (!is_word_char(openfile->current->data + openfile->current_x,
|
||||
punctuation_as_letters))
|
||||
seen_space = TRUE;
|
||||
else if (seen_space)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return started_on_word;
|
||||
}
|
||||
|
||||
/* Move to the previous word in the file, and update the screen afterwards. */
|
||||
void to_prev_word(void)
|
||||
{
|
||||
linestruct *was_current = openfile->current;
|
||||
|
||||
do_prev_word();
|
||||
|
||||
edit_redraw(was_current, FLOWING);
|
||||
}
|
||||
|
||||
/* Move to the next word in the file. If the AFTER_ENDS flag is set, stop
|
||||
* at word ends instead of beginnings. Update the screen afterwards. */
|
||||
void to_next_word(void)
|
||||
{
|
||||
linestruct *was_current = openfile->current;
|
||||
|
||||
do_next_word(ISSET(AFTER_ENDS));
|
||||
|
||||
edit_redraw(was_current, FLOWING);
|
||||
}
|
||||
|
||||
/* Move to the beginning of the current line (or softwrapped chunk).
|
||||
* When enabled, do a smart home. When softwrapping, go the beginning
|
||||
* of the full line when already at the start of a chunk. */
|
||||
void do_home(void)
|
||||
{
|
||||
linestruct *was_current = openfile->current;
|
||||
size_t was_column = xplustabs();
|
||||
bool moved_off_chunk = TRUE;
|
||||
#ifndef NANOFUR_TINY
|
||||
bool moved = FALSE;
|
||||
size_t leftedge = 0;
|
||||
size_t left_x = 0;
|
||||
|
||||
if (ISSET(SOFTWRAP)) {
|
||||
leftedge = leftedge_for(was_column, openfile->current);
|
||||
left_x = proper_x(openfile->current, &leftedge, FALSE, leftedge, NULL);
|
||||
}
|
||||
|
||||
if (ISSET(SMART_HOME)) {
|
||||
size_t indent_x = indent_length(openfile->current->data);
|
||||
|
||||
if (openfile->current->data[indent_x] != '\0') {
|
||||
/* If we're exactly on the indent, move fully home. Otherwise,
|
||||
* when not softwrapping or not after the first nonblank chunk,
|
||||
* move to the first nonblank character. */
|
||||
if (openfile->current_x == indent_x) {
|
||||
openfile->current_x = 0;
|
||||
moved = TRUE;
|
||||
} else if (left_x <= indent_x) {
|
||||
openfile->current_x = indent_x;
|
||||
moved = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!moved && ISSET(SOFTWRAP)) {
|
||||
/* If already at the left edge of the screen, move fully home.
|
||||
* Otherwise, move to the left edge. */
|
||||
if (openfile->current_x == left_x)
|
||||
openfile->current_x = 0;
|
||||
else {
|
||||
openfile->current_x = left_x;
|
||||
openfile->placewewant = leftedge;
|
||||
moved_off_chunk = FALSE;
|
||||
}
|
||||
} else if (!moved)
|
||||
#endif
|
||||
openfile->current_x = 0;
|
||||
|
||||
if (moved_off_chunk)
|
||||
openfile->placewewant = xplustabs();
|
||||
|
||||
/* If we changed chunk, we might be offscreen. Otherwise,
|
||||
* update current if the mark is on or we changed "page". */
|
||||
if (ISSET(SOFTWRAP) && moved_off_chunk)
|
||||
edit_redraw(was_current, FLOWING);
|
||||
else if (line_needs_update(was_column, openfile->placewewant))
|
||||
update_line(openfile->current, openfile->current_x);
|
||||
}
|
||||
|
||||
/* Move to the end of the current line (or softwrapped chunk).
|
||||
* When softwrapping and already at the end of a chunk, go to the
|
||||
* end of the full line. */
|
||||
void do_end(void)
|
||||
{
|
||||
linestruct *was_current = openfile->current;
|
||||
size_t was_column = xplustabs();
|
||||
size_t line_len = strlen(openfile->current->data);
|
||||
bool moved_off_chunk = TRUE;
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
if (ISSET(SOFTWRAP)) {
|
||||
bool kickoff = TRUE;
|
||||
bool last_chunk = FALSE;
|
||||
size_t leftedge = leftedge_for(was_column, openfile->current);
|
||||
size_t rightedge = get_softwrap_breakpoint(openfile->current->data,
|
||||
leftedge, &kickoff, &last_chunk);
|
||||
size_t right_x;
|
||||
|
||||
/* If we're on the last chunk, we're already at the end of the line.
|
||||
* Otherwise, we're one column past the end of the line. Shifting
|
||||
* backwards one column might put us in the middle of a multi-column
|
||||
* character, but actual_x() will fix that. */
|
||||
if (!last_chunk)
|
||||
rightedge--;
|
||||
|
||||
right_x = actual_x(openfile->current->data, rightedge);
|
||||
|
||||
/* If already at the right edge of the screen, move fully to
|
||||
* the end of the line. Otherwise, move to the right edge. */
|
||||
if (openfile->current_x == right_x)
|
||||
openfile->current_x = line_len;
|
||||
else {
|
||||
openfile->current_x = right_x;
|
||||
openfile->placewewant = rightedge;
|
||||
moved_off_chunk = FALSE;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
openfile->current_x = line_len;
|
||||
|
||||
if (moved_off_chunk)
|
||||
openfile->placewewant = xplustabs();
|
||||
|
||||
/* If we changed chunk, we might be offscreen. Otherwise,
|
||||
* update current if the mark is on or we changed "page". */
|
||||
if (ISSET(SOFTWRAP) && moved_off_chunk)
|
||||
edit_redraw(was_current, FLOWING);
|
||||
else if (line_needs_update(was_column, openfile->placewewant))
|
||||
update_line(openfile->current, openfile->current_x);
|
||||
}
|
||||
|
||||
/* Move the cursor to the preceding line or chunk. */
|
||||
void do_up(void)
|
||||
{
|
||||
linestruct *was_current = openfile->current;
|
||||
size_t leftedge, target_column;
|
||||
|
||||
get_edge_and_target(&leftedge, &target_column);
|
||||
|
||||
/* If we can't move up one line or chunk, we're at top of file. */
|
||||
if (go_back_chunks(1, &openfile->current, &leftedge) > 0)
|
||||
return;
|
||||
|
||||
set_proper_index_and_pww(&leftedge, target_column, FALSE);
|
||||
|
||||
if (openfile->cursor_row == 0 && !ISSET(JUMPY_SCROLLING) &&
|
||||
(tabsize < editwincols || !ISSET(SOFTWRAP)))
|
||||
edit_scroll(BACKWARD);
|
||||
else
|
||||
edit_redraw(was_current, FLOWING);
|
||||
|
||||
/* <Up> should not change placewewant, so restore it. */
|
||||
openfile->placewewant = leftedge + target_column;
|
||||
}
|
||||
|
||||
/* Move the cursor to next line or chunk. */
|
||||
void do_down(void)
|
||||
{
|
||||
linestruct *was_current = openfile->current;
|
||||
size_t leftedge, target_column;
|
||||
|
||||
get_edge_and_target(&leftedge, &target_column);
|
||||
|
||||
/* If we can't move down one line or chunk, we're at bottom of file. */
|
||||
if (go_forward_chunks(1, &openfile->current, &leftedge) > 0)
|
||||
return;
|
||||
|
||||
set_proper_index_and_pww(&leftedge, target_column, TRUE);
|
||||
|
||||
if (openfile->cursor_row == editwinrows - 1 && !ISSET(JUMPY_SCROLLING) &&
|
||||
(tabsize < editwincols || !ISSET(SOFTWRAP)))
|
||||
edit_scroll(FORWARD);
|
||||
else
|
||||
edit_redraw(was_current, FLOWING);
|
||||
|
||||
/* <Down> should not change placewewant, so restore it. */
|
||||
openfile->placewewant = leftedge + target_column;
|
||||
}
|
||||
|
||||
#if !defined(NANOFUR_TINY) || defined(ENABLE_HELP)
|
||||
/* Scroll up one line or chunk without moving the cursor textwise. */
|
||||
void do_scroll_up(void)
|
||||
{
|
||||
/* When the top of the file is onscreen, we can't scroll. */
|
||||
if (openfile->edittop->prev == NULL && openfile->firstcolumn == 0)
|
||||
return;
|
||||
|
||||
if (openfile->cursor_row == editwinrows - 1)
|
||||
do_up();
|
||||
|
||||
if (editwinrows > 1)
|
||||
edit_scroll(BACKWARD);
|
||||
}
|
||||
|
||||
/* Scroll down one line or chunk without moving the cursor textwise. */
|
||||
void do_scroll_down(void)
|
||||
{
|
||||
if (openfile->cursor_row == 0)
|
||||
do_down();
|
||||
|
||||
if (editwinrows > 1 && (openfile->edittop->next != NULL
|
||||
#ifndef NANOFUR_TINY
|
||||
|| (ISSET(SOFTWRAP) && (extra_chunks_in(openfile->edittop) >
|
||||
chunk_for(openfile->firstcolumn, openfile->edittop)))
|
||||
#endif
|
||||
))
|
||||
edit_scroll(FORWARD);
|
||||
}
|
||||
#endif /* !NANOFUR_TINY || ENABLE_HELP */
|
||||
|
||||
/* Move left one character. */
|
||||
void do_left(void)
|
||||
{
|
||||
linestruct *was_current = openfile->current;
|
||||
|
||||
if (openfile->current_x > 0) {
|
||||
openfile->current_x = step_left(openfile->current->data,
|
||||
openfile->current_x);
|
||||
#ifdef ENABLE_UTF8
|
||||
while (openfile->current_x > 0 &&
|
||||
is_zerowidth(openfile->current->data + openfile->current_x))
|
||||
openfile->current_x = step_left(openfile->current->data,
|
||||
openfile->current_x);
|
||||
#endif
|
||||
} else if (openfile->current != openfile->filetop) {
|
||||
openfile->current = openfile->current->prev;
|
||||
openfile->current_x = strlen(openfile->current->data);
|
||||
}
|
||||
|
||||
edit_redraw(was_current, FLOWING);
|
||||
}
|
||||
|
||||
/* Move right one character. */
|
||||
void do_right(void)
|
||||
{
|
||||
linestruct *was_current = openfile->current;
|
||||
|
||||
if (openfile->current->data[openfile->current_x] != '\0') {
|
||||
openfile->current_x = step_right(openfile->current->data,
|
||||
openfile->current_x);
|
||||
#ifdef ENABLE_UTF8
|
||||
while (openfile->current->data[openfile->current_x] != '\0' &&
|
||||
is_zerowidth(openfile->current->data + openfile->current_x))
|
||||
openfile->current_x = step_right(openfile->current->data,
|
||||
openfile->current_x);
|
||||
#endif
|
||||
} else if (openfile->current != openfile->filebot) {
|
||||
openfile->current = openfile->current->next;
|
||||
openfile->current_x = 0;
|
||||
}
|
||||
|
||||
edit_redraw(was_current, FLOWING);
|
||||
}
|
2708
src/nanofur.c
Normal file
2708
src/nanofur.c
Normal file
File diff suppressed because it is too large
Load diff
792
src/prompt.c
Normal file
792
src/prompt.c
Normal file
|
@ -0,0 +1,792 @@
|
|||
/**************************************************************************
|
||||
* prompt.c -- This file is part of GNU nanofur. *
|
||||
* *
|
||||
* Copyright (C) 1999-2011, 2013-2024 Free Software Foundation, Inc. *
|
||||
* Copyright (C) 2016, 2018, 2020, 2022 Benno Schulenberg *
|
||||
* *
|
||||
* GNU nanofur 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. *
|
||||
* *
|
||||
* GNU nanofur 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 http://www.gnu.org/licenses/. *
|
||||
* *
|
||||
**************************************************************************/
|
||||
|
||||
#include "prototypes.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
static char *prompt = NULL;
|
||||
/* The prompt string used for status-bar questions. */
|
||||
static size_t typing_x = HIGHEST_POSITIVE;
|
||||
/* The cursor position in answer. */
|
||||
|
||||
/* Move to the beginning of the answer. */
|
||||
void do_statusbar_home(void)
|
||||
{
|
||||
typing_x = 0;
|
||||
}
|
||||
|
||||
/* Move to the end of the answer. */
|
||||
void do_statusbar_end(void)
|
||||
{
|
||||
typing_x = strlen(answer);
|
||||
}
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
/* Move to the previous word in the answer. */
|
||||
void do_statusbar_prev_word(void)
|
||||
{
|
||||
bool seen_a_word = FALSE, step_forward = FALSE;
|
||||
|
||||
/* Move backward until we pass over the start of a word. */
|
||||
while (typing_x != 0) {
|
||||
typing_x = step_left(answer, typing_x);
|
||||
|
||||
if (is_word_char(answer + typing_x, FALSE))
|
||||
seen_a_word = TRUE;
|
||||
#ifdef ENABLE_UTF8
|
||||
else if (is_zerowidth(answer + typing_x))
|
||||
; /* skip */
|
||||
#endif
|
||||
else if (seen_a_word) {
|
||||
/* This is space now: we've overshot the start of the word. */
|
||||
step_forward = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (step_forward)
|
||||
/* Move one character forward again to sit on the start of the word. */
|
||||
typing_x = step_right(answer, typing_x);
|
||||
}
|
||||
|
||||
/* Move to the next word in the answer. */
|
||||
void do_statusbar_next_word(void)
|
||||
{
|
||||
bool seen_space = !is_word_char(answer + typing_x, FALSE);
|
||||
bool seen_word = !seen_space;
|
||||
|
||||
/* Move forward until we reach either the end or the start of a word,
|
||||
* depending on whether the AFTER_ENDS flag is set or not. */
|
||||
while (answer[typing_x] != '\0') {
|
||||
typing_x = step_right(answer, typing_x);
|
||||
|
||||
if (ISSET(AFTER_ENDS)) {
|
||||
/* If this is a word character, continue; else it's a separator,
|
||||
* and if we've already seen a word, then it's a word end. */
|
||||
if (is_word_char(answer + typing_x, FALSE))
|
||||
seen_word = TRUE;
|
||||
#ifdef ENABLE_UTF8
|
||||
else if (is_zerowidth(answer + typing_x))
|
||||
; /* skip */
|
||||
#endif
|
||||
else if (seen_word)
|
||||
break;
|
||||
} else {
|
||||
#ifdef ENABLE_UTF8
|
||||
if (is_zerowidth(answer + typing_x))
|
||||
; /* skip */
|
||||
else
|
||||
#endif
|
||||
/* If this is not a word character, then it's a separator; else
|
||||
* if we've already seen a separator, then it's a word start. */
|
||||
if (!is_word_char(answer + typing_x, FALSE))
|
||||
seen_space = TRUE;
|
||||
else if (seen_space)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* !NANOFUR_TINY */
|
||||
|
||||
/* Move left one character in the answer. */
|
||||
void do_statusbar_left(void)
|
||||
{
|
||||
if (typing_x > 0) {
|
||||
typing_x = step_left(answer, typing_x);
|
||||
#ifdef ENABLE_UTF8
|
||||
while (typing_x > 0 && is_zerowidth(answer + typing_x))
|
||||
typing_x = step_left(answer, typing_x);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/* Move right one character in the answer. */
|
||||
void do_statusbar_right(void)
|
||||
{
|
||||
if (answer[typing_x] != '\0') {
|
||||
typing_x = step_right(answer, typing_x);
|
||||
#ifdef ENABLE_UTF8
|
||||
while (answer[typing_x] != '\0' && is_zerowidth(answer + typing_x))
|
||||
typing_x = step_right(answer, typing_x);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/* Backspace over one character in the answer. */
|
||||
void do_statusbar_backspace(void)
|
||||
{
|
||||
if (typing_x > 0) {
|
||||
size_t was_x = typing_x;
|
||||
|
||||
typing_x = step_left(answer, typing_x);
|
||||
memmove(answer + typing_x, answer + was_x, strlen(answer) - was_x + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Delete one character in the answer. */
|
||||
void do_statusbar_delete(void)
|
||||
{
|
||||
if (answer[typing_x] != '\0') {
|
||||
int charlen = char_length(answer + typing_x);
|
||||
|
||||
memmove(answer + typing_x, answer + typing_x + charlen,
|
||||
strlen(answer) - typing_x - charlen + 1);
|
||||
#ifdef ENABLE_UTF8
|
||||
if (is_zerowidth(answer + typing_x))
|
||||
do_statusbar_delete();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/* Zap the part of the answer after the cursor, or the whole answer. */
|
||||
void lop_the_answer(void)
|
||||
{
|
||||
if (answer[typing_x] == '\0')
|
||||
typing_x = 0;
|
||||
|
||||
answer[typing_x] = '\0';
|
||||
}
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
/* Copy the current answer (if any) into the cutbuffer. */
|
||||
void copy_the_answer(void)
|
||||
{
|
||||
if (*answer) {
|
||||
free_lines(cutbuffer);
|
||||
cutbuffer = make_new_node(NULL);
|
||||
cutbuffer->data = copy_of(answer);
|
||||
typing_x = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Paste the first line of the cutbuffer into the current answer. */
|
||||
void paste_into_answer(void)
|
||||
{
|
||||
size_t pastelen = strlen(cutbuffer->data);
|
||||
|
||||
answer = nrealloc(answer, strlen(answer) + pastelen + 1);
|
||||
memmove(answer + typing_x + pastelen, answer + typing_x,
|
||||
strlen(answer) - typing_x + 1);
|
||||
strncpy(answer + typing_x, cutbuffer->data, pastelen);
|
||||
|
||||
typing_x += pastelen;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_MOUSE
|
||||
/* Handle a mouse click on the status-bar prompt or the shortcut list. */
|
||||
int do_statusbar_mouse(void)
|
||||
{
|
||||
int click_row, click_col;
|
||||
int retval = get_mouseinput(&click_row, &click_col, TRUE);
|
||||
|
||||
/* We can click on the status-bar window text to move the cursor. */
|
||||
if (retval == 0 && wmouse_trafo(footwin, &click_row, &click_col, FALSE)) {
|
||||
size_t start_col = breadth(prompt) + 2;
|
||||
|
||||
/* Move to where the click occurred. */
|
||||
if (click_row == 0 && click_col >= start_col)
|
||||
typing_x = actual_x(answer,
|
||||
get_statusbar_page_start(start_col, start_col +
|
||||
wideness(answer, typing_x)) + click_col - start_col);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Insert the given short burst of bytes into the answer. */
|
||||
void inject_into_answer(char *burst, size_t count)
|
||||
{
|
||||
/* First encode any embedded NUL byte as 0x0A. */
|
||||
for (size_t index = 0; index < count; index++)
|
||||
if (burst[index] == '\0')
|
||||
burst[index] = '\n';
|
||||
|
||||
answer = nrealloc(answer, strlen(answer) + count + 1);
|
||||
memmove(answer + typing_x + count, answer + typing_x,
|
||||
strlen(answer) - typing_x + 1);
|
||||
strncpy(answer + typing_x, burst, count);
|
||||
|
||||
typing_x += count;
|
||||
}
|
||||
|
||||
/* Get a verbatim keystroke and insert it into the answer. */
|
||||
void do_statusbar_verbatim_input(void)
|
||||
{
|
||||
size_t count = 1;
|
||||
char *bytes;
|
||||
|
||||
bytes = get_verbatim_kbinput(footwin, &count);
|
||||
|
||||
if (0 < count && count < 999)
|
||||
inject_into_answer(bytes, count);
|
||||
else if (count == 0)
|
||||
beep();
|
||||
|
||||
free(bytes);
|
||||
}
|
||||
|
||||
/* Add the given input to the input buffer when it's a normal byte,
|
||||
* and inject the gathered bytes into the answer when ready. */
|
||||
void absorb_character(int input, functionptrtype function)
|
||||
{
|
||||
static char *puddle = NULL;
|
||||
/* The input buffer. */
|
||||
static size_t capacity = 8;
|
||||
/* The size of the input buffer; gets doubled whenever needed. */
|
||||
static size_t depth = 0;
|
||||
/* The length of the input buffer. */
|
||||
|
||||
/* If not a command, discard anything that is not a normal character byte.
|
||||
* Apart from that, only accept input when not in restricted mode, or when
|
||||
* not at the "Write File" prompt, or when there is no filename yet. */
|
||||
if (!function) {
|
||||
if (input < 0x20 || input > 0xFF || meta_key)
|
||||
beep();
|
||||
else if (!ISSET(RESTRICTED) || currmenu != MWRITEFILE ||
|
||||
openfile->filename[0] == '\0') {
|
||||
/* When the input buffer (plus room for terminating NUL) is full,
|
||||
* extend it; otherwise, if it does not exist yet, create it. */
|
||||
if (depth + 1 == capacity) {
|
||||
capacity = 2 * capacity;
|
||||
puddle = nrealloc(puddle, capacity);
|
||||
} else if (!puddle)
|
||||
puddle = nmalloc(capacity);
|
||||
|
||||
puddle[depth++] = (char)input;
|
||||
}
|
||||
}
|
||||
|
||||
/* If there are gathered bytes and we have a command or no other key codes
|
||||
* are waiting, it's time to insert these bytes into the answer. */
|
||||
if (depth > 0 && (function || waiting_keycodes() == 0)) {
|
||||
puddle[depth] = '\0';
|
||||
inject_into_answer(puddle, depth);
|
||||
depth = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle any editing shortcut, and return TRUE when handled. */
|
||||
bool handle_editing(functionptrtype function)
|
||||
{
|
||||
if (function == do_left)
|
||||
do_statusbar_left();
|
||||
else if (function == do_right)
|
||||
do_statusbar_right();
|
||||
#ifndef NANOFUR_TINY
|
||||
else if (function == to_prev_word)
|
||||
do_statusbar_prev_word();
|
||||
else if (function == to_next_word)
|
||||
do_statusbar_next_word();
|
||||
#endif
|
||||
else if (function == do_home)
|
||||
do_statusbar_home();
|
||||
else if (function == do_end)
|
||||
do_statusbar_end();
|
||||
/* When in restricted mode at the "Write File" prompt and the
|
||||
* filename isn't blank, disallow any input and deletion. */
|
||||
else if (ISSET(RESTRICTED) && currmenu == MWRITEFILE &&
|
||||
openfile->filename[0] != '\0' &&
|
||||
(function == do_verbatim_input ||
|
||||
function == do_delete || function == do_backspace ||
|
||||
function == cut_text || function == paste_text))
|
||||
;
|
||||
else if (function == do_verbatim_input)
|
||||
do_statusbar_verbatim_input();
|
||||
else if (function == do_delete)
|
||||
do_statusbar_delete();
|
||||
else if (function == do_backspace)
|
||||
do_statusbar_backspace();
|
||||
else if (function == cut_text)
|
||||
lop_the_answer();
|
||||
#ifndef NANOFUR_TINY
|
||||
else if (function == copy_text)
|
||||
copy_the_answer();
|
||||
else if (function == paste_text) {
|
||||
if (cutbuffer != NULL)
|
||||
paste_into_answer();
|
||||
}
|
||||
#endif
|
||||
else
|
||||
return FALSE;
|
||||
|
||||
/* Don't handle any handled function again. */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Return the column number of the first character of the answer that is
|
||||
* displayed in the status bar when the cursor is at the given column,
|
||||
* with the available room for the answer starting at base. Note that
|
||||
* (0 <= column - get_statusbar_page_start(column) < COLS). */
|
||||
size_t get_statusbar_page_start(size_t base, size_t column)
|
||||
{
|
||||
if (column == base || column < COLS - 1)
|
||||
return 0;
|
||||
else if (COLS > base + 2)
|
||||
return column - base - 1 - (column - base - 1) % (COLS - base - 2);
|
||||
else
|
||||
return column - 2;
|
||||
}
|
||||
|
||||
/* Reinitialize the cursor position in the answer. */
|
||||
void put_cursor_at_end_of_answer(void)
|
||||
{
|
||||
typing_x = HIGHEST_POSITIVE;
|
||||
}
|
||||
|
||||
/* Redraw the prompt bar and place the cursor at the right spot. */
|
||||
void draw_the_promptbar(void)
|
||||
{
|
||||
size_t base = breadth(prompt) + 2;
|
||||
size_t column = base + wideness(answer, typing_x);
|
||||
size_t the_page, end_page;
|
||||
char *expanded;
|
||||
|
||||
the_page = get_statusbar_page_start(base, column);
|
||||
end_page = get_statusbar_page_start(base, base + breadth(answer) - 1);
|
||||
|
||||
/* Color the prompt bar over its full width. */
|
||||
wattron(footwin, interface_color_pair[PROMPT_BAR]);
|
||||
mvwprintw(footwin, 0, 0, "%*s", COLS, " ");
|
||||
|
||||
mvwaddstr(footwin, 0, 0, prompt);
|
||||
waddch(footwin, ':');
|
||||
waddch(footwin, (the_page == 0) ? ' ' : '<');
|
||||
|
||||
expanded = display_string(answer, the_page, COLS - base, FALSE, TRUE);
|
||||
waddstr(footwin, expanded);
|
||||
free(expanded);
|
||||
|
||||
if (the_page < end_page && base + breadth(answer) - the_page > COLS)
|
||||
mvwaddch(footwin, 0, COLS - 1, '>');
|
||||
|
||||
wattroff(footwin, interface_color_pair[PROMPT_BAR]);
|
||||
|
||||
#if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH < 20210220)
|
||||
/* Work around a cursor-misplacement bug -- https://sv.gnu.org/bugs/?59808. */
|
||||
if (ISSET(NO_HELP)) {
|
||||
wmove(footwin, 0, 0);
|
||||
wrefresh(footwin);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Place the cursor at the right spot. */
|
||||
wmove(footwin, 0, column - the_page);
|
||||
|
||||
wnoutrefresh(footwin);
|
||||
}
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
/* Remove or add the pipe character at the answer's head. */
|
||||
void add_or_remove_pipe_symbol_from_answer(void)
|
||||
{
|
||||
if (answer[0] == '|') {
|
||||
memmove(answer, answer + 1, strlen(answer));
|
||||
if (typing_x > 0)
|
||||
typing_x--;
|
||||
} else {
|
||||
answer = nrealloc(answer, strlen(answer) + 2);
|
||||
memmove(answer + 1, answer, strlen(answer) + 1);
|
||||
answer[0] = '|';
|
||||
typing_x++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Get a string of input at the status-bar prompt. */
|
||||
functionptrtype acquire_an_answer(int *actual, bool *listed,
|
||||
linestruct **history_list, void (*refresh_func)(void))
|
||||
{
|
||||
#ifdef ENABLE_HISTORIES
|
||||
char *stored_string = NULL;
|
||||
/* Whatever the answer was before the user foraged into history. */
|
||||
#ifdef ENABLE_TABCOMP
|
||||
bool previous_was_tab = FALSE;
|
||||
/* Whether the previous keystroke was an attempt at tab completion. */
|
||||
size_t fragment_length = 0;
|
||||
/* The length of the fragment that the user tries to tab complete. */
|
||||
#endif
|
||||
#endif
|
||||
const keystruct *shortcut;
|
||||
functionptrtype function;
|
||||
int input;
|
||||
|
||||
if (typing_x > strlen(answer))
|
||||
typing_x = strlen(answer);
|
||||
|
||||
while (TRUE) {
|
||||
draw_the_promptbar();
|
||||
|
||||
/* Read in one keystroke. */
|
||||
input = get_kbinput(footwin, VISIBLE);
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
/* If the window size changed, go reformat the prompt string. */
|
||||
if (input == THE_WINDOW_RESIZED) {
|
||||
refresh_func(); /* Only needed when in file browser. */
|
||||
*actual = THE_WINDOW_RESIZED;
|
||||
#ifdef ENABLE_HISTORIES
|
||||
free(stored_string);
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
#ifdef ENABLE_MOUSE
|
||||
/* For a click on a shortcut, read in the resulting keycode. */
|
||||
if (input == KEY_MOUSE && do_statusbar_mouse() == 1)
|
||||
input = get_kbinput(footwin, BLIND);
|
||||
if (input == KEY_MOUSE)
|
||||
continue;
|
||||
#endif
|
||||
|
||||
/* Check for a shortcut in the current list. */
|
||||
shortcut = get_shortcut(input);
|
||||
function = (shortcut ? shortcut->func : NULL);
|
||||
|
||||
/* When it's a normal character, add it to the answer. */
|
||||
absorb_character(input, function);
|
||||
|
||||
if (function == do_cancel || function == do_enter)
|
||||
break;
|
||||
|
||||
#ifdef ENABLE_TABCOMP
|
||||
if (function == do_tab) {
|
||||
#ifdef ENABLE_HISTORIES
|
||||
if (history_list != NULL) {
|
||||
if (!previous_was_tab)
|
||||
fragment_length = strlen(answer);
|
||||
|
||||
if (fragment_length > 0) {
|
||||
answer = get_history_completion(history_list,
|
||||
answer, fragment_length);
|
||||
typing_x = strlen(answer);
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
/* Allow tab completion of filenames, but not in restricted mode. */
|
||||
if ((currmenu & (MINSERTFILE|MWRITEFILE|MGOTODIR)) && !ISSET(RESTRICTED))
|
||||
answer = input_tab(answer, &typing_x, refresh_func, listed);
|
||||
} else
|
||||
#endif
|
||||
#ifdef ENABLE_HISTORIES
|
||||
if (function == get_older_item && history_list != NULL) {
|
||||
/* If this is the first step into history, start at the bottom. */
|
||||
if (stored_string == NULL)
|
||||
reset_history_pointer_for(*history_list);
|
||||
|
||||
/* When moving up from the bottom, remember the current answer. */
|
||||
if ((*history_list)->next == NULL)
|
||||
stored_string = mallocstrcpy(stored_string, answer);
|
||||
|
||||
/* If there is an older item, move to it and copy its string. */
|
||||
if ((*history_list)->prev != NULL) {
|
||||
*history_list = (*history_list)->prev;
|
||||
answer = mallocstrcpy(answer, (*history_list)->data);
|
||||
typing_x = strlen(answer);
|
||||
}
|
||||
} else if (function == get_newer_item && history_list != NULL) {
|
||||
/* If there is a newer item, move to it and copy its string. */
|
||||
if ((*history_list)->next != NULL) {
|
||||
*history_list = (*history_list)->next;
|
||||
answer = mallocstrcpy(answer, (*history_list)->data);
|
||||
typing_x = strlen(answer);
|
||||
}
|
||||
|
||||
/* When at the bottom of the history list, restore the old answer. */
|
||||
if ((*history_list)->next == NULL && stored_string && *answer == '\0') {
|
||||
answer = mallocstrcpy(answer, stored_string);
|
||||
typing_x = strlen(answer);
|
||||
}
|
||||
} else
|
||||
#endif /* ENABLE_HISTORIES */
|
||||
if (function == do_help || function == full_refresh)
|
||||
function();
|
||||
#ifndef NANOFUR_TINY
|
||||
else if (function == do_toggle && shortcut->toggle == NO_HELP) {
|
||||
TOGGLE(NO_HELP);
|
||||
window_init();
|
||||
focusing = FALSE;
|
||||
refresh_func();
|
||||
bottombars(currmenu);
|
||||
} else if (function == do_nothing)
|
||||
;
|
||||
#endif
|
||||
#ifdef ENABLE_NANOFURRC
|
||||
else if (function == (functionptrtype)implant)
|
||||
implant(shortcut->expansion);
|
||||
#endif
|
||||
else if (function && !handle_editing(function)) {
|
||||
/* When it's a permissible shortcut, run it and done. */
|
||||
if (!ISSET(VIEW_MODE) || !changes_something(function)) {
|
||||
function();
|
||||
break;
|
||||
} else
|
||||
beep();
|
||||
}
|
||||
|
||||
#if defined(ENABLE_HISTORIES) && defined(ENABLE_TABCOMP)
|
||||
previous_was_tab = (function == do_tab);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef ENABLE_HISTORIES
|
||||
/* If the history pointer was moved, point it at the bottom again. */
|
||||
if (stored_string != NULL) {
|
||||
reset_history_pointer_for(*history_list);
|
||||
free(stored_string);
|
||||
}
|
||||
#endif
|
||||
|
||||
*actual = input;
|
||||
|
||||
return function;
|
||||
}
|
||||
|
||||
/* Ask a question on the status bar. Return 0 when text was entered,
|
||||
* -1 for a cancelled entry, -2 for a blank string, and the relevant
|
||||
* keycode when a valid shortcut key was pressed. The 'provided'
|
||||
* parameter is the default answer for when simply Enter is typed. */
|
||||
int do_prompt(int menu, const char *provided, linestruct **history_list,
|
||||
void (*refresh_func)(void), const char *msg, ...)
|
||||
{
|
||||
functionptrtype function = NULL;
|
||||
bool listed = FALSE;
|
||||
va_list ap;
|
||||
int retval;
|
||||
/* Save a possible current status-bar x position and prompt. */
|
||||
size_t was_typing_x = typing_x;
|
||||
char *saved_prompt = prompt;
|
||||
|
||||
bottombars(menu);
|
||||
|
||||
if (answer != provided)
|
||||
answer = mallocstrcpy(answer, provided);
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
redo_theprompt:
|
||||
#endif
|
||||
prompt = nmalloc((COLS * MAXCHARLEN) + 1);
|
||||
va_start(ap, msg);
|
||||
vsnprintf(prompt, COLS * MAXCHARLEN, msg, ap);
|
||||
va_end(ap);
|
||||
/* Reserve five columns for colon plus angles plus answer, ":<aa>". */
|
||||
prompt[actual_x(prompt, (COLS < 5) ? 0 : COLS - 5)] = '\0';
|
||||
|
||||
lastmessage = VACUUM;
|
||||
|
||||
function = acquire_an_answer(&retval, &listed, history_list, refresh_func);
|
||||
free(prompt);
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
if (retval == THE_WINDOW_RESIZED)
|
||||
goto redo_theprompt;
|
||||
#endif
|
||||
|
||||
/* Restore a possible previous prompt and maybe the typing position. */
|
||||
prompt = saved_prompt;
|
||||
if (function == do_cancel || function == do_enter ||
|
||||
#ifdef ENABLE_BROWSER
|
||||
function == to_first_file || function == to_last_file ||
|
||||
#endif
|
||||
function == to_first_line || function == to_last_line)
|
||||
typing_x = was_typing_x;
|
||||
|
||||
/* Set the proper return value for Cancel and Enter. */
|
||||
if (function == do_cancel)
|
||||
retval = -1;
|
||||
else if (function == do_enter)
|
||||
retval = (*answer == '\0') ? -2 : 0;
|
||||
|
||||
if (lastmessage == VACUUM)
|
||||
wipe_statusbar();
|
||||
|
||||
#ifdef ENABLE_TABCOMP
|
||||
/* If possible filename completions are still listed, clear them off. */
|
||||
if (listed)
|
||||
refresh_func();
|
||||
#endif
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
#define UNDECIDED -2
|
||||
|
||||
/* Ask a simple Yes/No (and optionally All) question on the status bar
|
||||
* and return the choice -- either YES or NO or ALL or CANCEL. */
|
||||
int ask_user(bool withall, const char *question)
|
||||
{
|
||||
int choice = UNDECIDED;
|
||||
int width = 16;
|
||||
/* TRANSLATORS: For the next three strings, specify the starting letters
|
||||
* of the translations for "Yes"/"No"/"All". The first letter of each of
|
||||
* these strings MUST be a single-byte letter; others may be multi-byte. */
|
||||
const char *yesstr = _("Yy");
|
||||
const char *nostr = _("Nn");
|
||||
const char *allstr = _("Aa");
|
||||
const keystruct *shortcut;
|
||||
functionptrtype function;
|
||||
|
||||
while (choice == UNDECIDED) {
|
||||
#ifdef ENABLE_NLS
|
||||
char letter[MAXCHARLEN + 1];
|
||||
int index = 0;
|
||||
#endif
|
||||
int kbinput;
|
||||
|
||||
if (!ISSET(NO_HELP)) {
|
||||
char shortstr[MAXCHARLEN + 2];
|
||||
/* Temporary string for (translated) " Y", " N" and " A". */
|
||||
const keystruct *cancelshortcut = first_sc_for(MYESNO, do_cancel);
|
||||
/* The keystroke that is bound to the Cancel function. */
|
||||
|
||||
if (COLS < 32)
|
||||
width = COLS / 2;
|
||||
|
||||
/* Clear the shortcut list from the bottom of the screen. */
|
||||
blank_bottombars();
|
||||
|
||||
/* Now show the ones for "Yes", "No", "Cancel" and maybe "All". */
|
||||
sprintf(shortstr, " %c", yesstr[0]);
|
||||
wmove(footwin, 1, 0);
|
||||
post_one_key(shortstr, _("Yes"), width);
|
||||
|
||||
shortstr[1] = nostr[0];
|
||||
wmove(footwin, 2, 0);
|
||||
post_one_key(shortstr, _("No"), width);
|
||||
|
||||
if (withall) {
|
||||
shortstr[1] = allstr[0];
|
||||
wmove(footwin, 1, width);
|
||||
post_one_key(shortstr, _("All"), width);
|
||||
}
|
||||
|
||||
wmove(footwin, 2, width);
|
||||
post_one_key(cancelshortcut->keystr, _("Cancel"), width);
|
||||
}
|
||||
|
||||
/* Color the prompt bar over its full width and display the question. */
|
||||
wattron(footwin, interface_color_pair[PROMPT_BAR]);
|
||||
mvwprintw(footwin, 0, 0, "%*s", COLS, " ");
|
||||
mvwaddnstr(footwin, 0, 0, question, actual_x(question, COLS - 1));
|
||||
wattroff(footwin, interface_color_pair[PROMPT_BAR]);
|
||||
wnoutrefresh(footwin);
|
||||
|
||||
currmenu = MYESNO;
|
||||
|
||||
/* When not replacing, show the cursor while waiting for a key. */
|
||||
kbinput = get_kbinput(footwin, !withall);
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
if (kbinput == THE_WINDOW_RESIZED)
|
||||
continue;
|
||||
|
||||
/* Accept first character of an external paste and ignore the rest. */
|
||||
if (bracketed_paste)
|
||||
kbinput = get_kbinput(footwin, BLIND);
|
||||
while (bracketed_paste)
|
||||
get_kbinput(footwin, BLIND);
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
letter[index++] = (unsigned char)kbinput;
|
||||
#ifdef ENABLE_UTF8
|
||||
/* If the received code is a UTF-8 starter byte, get also the
|
||||
* continuation bytes and assemble them into one letter. */
|
||||
if (using_utf8() && 0xC0 <= kbinput && kbinput <= 0xF7) {
|
||||
int extras = (kbinput / 16) % 4 + (kbinput <= 0xCF ? 1 : 0);
|
||||
|
||||
while (extras <= waiting_keycodes() && extras-- > 0)
|
||||
letter[index++] = (unsigned char)get_kbinput(footwin, !withall);
|
||||
}
|
||||
#endif
|
||||
letter[index] = '\0';
|
||||
|
||||
/* See if the typed letter is in the Yes, No, or All strings. */
|
||||
if (strstr(yesstr, letter) != NULL)
|
||||
choice = YES;
|
||||
else if (strstr(nostr, letter) != NULL)
|
||||
choice = NO;
|
||||
else if (withall && strstr(allstr, letter) != NULL)
|
||||
choice = ALL;
|
||||
else
|
||||
#endif /* ENABLE_NLS */
|
||||
if (strchr("Yy", kbinput) != NULL)
|
||||
choice = YES;
|
||||
else if (strchr("Nn", kbinput) != NULL)
|
||||
choice = NO;
|
||||
else if (withall && strchr("Aa", kbinput) != NULL)
|
||||
choice = ALL;
|
||||
|
||||
if (choice != UNDECIDED)
|
||||
break;
|
||||
|
||||
shortcut = get_shortcut(kbinput);
|
||||
function = (shortcut ? shortcut->func : NULL);
|
||||
|
||||
if (function == do_cancel)
|
||||
choice = CANCEL;
|
||||
else if (function == full_refresh)
|
||||
full_refresh();
|
||||
#ifndef NANOFUR_TINY
|
||||
else if (function == do_toggle && shortcut->toggle == NO_HELP) {
|
||||
TOGGLE(NO_HELP);
|
||||
window_init();
|
||||
titlebar(NULL);
|
||||
focusing = FALSE;
|
||||
edit_refresh();
|
||||
focusing = TRUE;
|
||||
}
|
||||
#endif
|
||||
/* Interpret ^N as "No", to allow exiting in anger, and ^Q or ^X too. */
|
||||
else if (kbinput == '\x0E' || (kbinput == '\x11' && !ISSET(MODERN_BINDINGS)) ||
|
||||
(kbinput == '\x18' && ISSET(MODERN_BINDINGS)))
|
||||
choice = NO;
|
||||
/* Also, interpret ^Y as "Yes, and ^A as "All". */
|
||||
else if (kbinput == '\x19')
|
||||
choice = YES;
|
||||
else if (kbinput == '\x01' && withall)
|
||||
choice = ALL;
|
||||
#ifdef ENABLE_MOUSE
|
||||
else if (kbinput == KEY_MOUSE) {
|
||||
int mouse_x, mouse_y;
|
||||
/* We can click on the Yes/No/All shortcuts to select an answer. */
|
||||
if (get_mouseinput(&mouse_y, &mouse_x, FALSE) == 0 &&
|
||||
wmouse_trafo(footwin, &mouse_y, &mouse_x, FALSE) &&
|
||||
mouse_x < (width * 2) && mouse_y > 0) {
|
||||
int x = mouse_x / width;
|
||||
int y = mouse_y - 1;
|
||||
|
||||
/* x == 0 means Yes or No, y == 0 means Yes or All. */
|
||||
choice = -2 * x * y + x - y + 1;
|
||||
|
||||
if (choice == ALL && !withall)
|
||||
choice = UNDECIDED;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
else
|
||||
beep();
|
||||
}
|
||||
|
||||
return choice;
|
||||
}
|
688
src/prototypes.h
Normal file
688
src/prototypes.h
Normal file
|
@ -0,0 +1,688 @@
|
|||
/**************************************************************************
|
||||
* prototypes.h -- This file is part of GNU nanofur. *
|
||||
* *
|
||||
* Copyright (C) 1999-2011, 2013-2024 Free Software Foundation, Inc. *
|
||||
* *
|
||||
* GNU nanofur 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. *
|
||||
* *
|
||||
* GNU nanofur 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 http://www.gnu.org/licenses/. *
|
||||
* *
|
||||
**************************************************************************/
|
||||
|
||||
#include "definitions.h"
|
||||
|
||||
/* All external variables. See global.c for their descriptions. */
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
extern volatile sig_atomic_t the_window_resized;
|
||||
#endif
|
||||
|
||||
extern bool on_a_vt;
|
||||
extern bool shifted_metas;
|
||||
|
||||
extern bool meta_key;
|
||||
extern bool shift_held;
|
||||
extern bool mute_modifiers;
|
||||
extern bool bracketed_paste;
|
||||
|
||||
extern bool we_are_running;
|
||||
extern bool more_than_one;
|
||||
extern bool report_size;
|
||||
extern bool ran_a_tool;
|
||||
|
||||
extern bool inhelp;
|
||||
extern char *title;
|
||||
|
||||
extern bool focusing;
|
||||
|
||||
extern bool as_an_at;
|
||||
|
||||
extern bool control_C_was_pressed;
|
||||
|
||||
extern message_type lastmessage;
|
||||
|
||||
extern linestruct *pletion_line;
|
||||
|
||||
extern bool also_the_last;
|
||||
|
||||
extern char *answer;
|
||||
|
||||
extern char *last_search;
|
||||
extern int didfind;
|
||||
|
||||
extern char *present_path;
|
||||
|
||||
extern unsigned flags[4];
|
||||
|
||||
extern int controlleft, controlright;
|
||||
extern int controlup, controldown;
|
||||
extern int controlhome, controlend;
|
||||
#ifndef NANOFUR_TINY
|
||||
extern int controldelete, controlshiftdelete;
|
||||
extern int shiftleft, shiftright;
|
||||
extern int shiftup, shiftdown;
|
||||
extern int shiftcontrolleft, shiftcontrolright;
|
||||
extern int shiftcontrolup, shiftcontroldown;
|
||||
extern int shiftcontrolhome, shiftcontrolend;
|
||||
extern int altleft, altright;
|
||||
extern int altup, altdown;
|
||||
extern int althome, altend;
|
||||
extern int altpageup, altpagedown;
|
||||
extern int altinsert, altdelete;
|
||||
extern int shiftaltleft, shiftaltright;
|
||||
extern int shiftaltup, shiftaltdown;
|
||||
#endif
|
||||
extern int mousefocusin, mousefocusout;
|
||||
|
||||
#ifdef ENABLED_WRAPORJUSTIFY
|
||||
extern ssize_t fill;
|
||||
extern size_t wrap_at;
|
||||
#endif
|
||||
|
||||
extern WINDOW *topwin;
|
||||
extern WINDOW *midwin;
|
||||
extern WINDOW *footwin;
|
||||
extern int editwinrows;
|
||||
extern int editwincols;
|
||||
extern int margin;
|
||||
extern int sidebar;
|
||||
#ifndef NANOFUR_TINY
|
||||
extern int *bardata;
|
||||
extern ssize_t stripe_column;
|
||||
extern int cycling_aim;
|
||||
#endif
|
||||
|
||||
extern linestruct *cutbuffer;
|
||||
extern linestruct *cutbottom;
|
||||
extern bool keep_cutbuffer;
|
||||
|
||||
extern openfilestruct *openfile;
|
||||
#ifdef ENABLE_MULTIBUFFER
|
||||
extern openfilestruct *startfile;
|
||||
#endif
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
extern char *matchbrackets;
|
||||
extern char *whitespace;
|
||||
extern int whitelen[2];
|
||||
#endif
|
||||
|
||||
extern const char *exit_tag;
|
||||
extern const char *close_tag;
|
||||
#ifdef ENABLE_JUSTIFY
|
||||
extern char *punct;
|
||||
extern char *brackets;
|
||||
extern char *quotestr;
|
||||
extern regex_t quotereg;
|
||||
#endif
|
||||
|
||||
extern char *word_chars;
|
||||
|
||||
extern ssize_t tabsize;
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
extern char *backup_dir;
|
||||
#endif
|
||||
#ifdef ENABLE_OPERATINGDIR
|
||||
extern char *operating_dir;
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_SPELLER
|
||||
extern char *alt_speller;
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_COLOR
|
||||
extern syntaxtype *syntaxes;
|
||||
extern char *syntaxstr;
|
||||
extern bool have_palette;
|
||||
extern bool rescind_colors;
|
||||
extern bool perturbed;
|
||||
extern bool recook;
|
||||
#endif
|
||||
|
||||
extern bool refresh_needed;
|
||||
|
||||
extern int currmenu;
|
||||
extern keystruct *sclist;
|
||||
extern funcstruct *allfuncs;
|
||||
extern funcstruct *exitfunc;
|
||||
|
||||
extern linestruct *search_history;
|
||||
extern linestruct *replace_history;
|
||||
extern linestruct *execute_history;
|
||||
#ifdef ENABLE_HISTORIES
|
||||
extern linestruct *searchtop;
|
||||
extern linestruct *searchbot;
|
||||
extern linestruct *replacetop;
|
||||
extern linestruct *replacebot;
|
||||
extern linestruct *executetop;
|
||||
extern linestruct *executebot;
|
||||
#endif
|
||||
|
||||
extern regex_t search_regexp;
|
||||
extern regmatch_t regmatches[10];
|
||||
|
||||
extern int hilite_attribute;
|
||||
#ifdef ENABLE_COLOR
|
||||
extern colortype *color_combo[NUMBER_OF_ELEMENTS];
|
||||
#endif
|
||||
extern int interface_color_pair[NUMBER_OF_ELEMENTS];
|
||||
|
||||
extern char *homedir;
|
||||
extern char *statedir;
|
||||
#if defined(ENABLE_NANOFURRC) || defined(ENABLE_HISTORIES)
|
||||
extern char *startup_problem;
|
||||
#endif
|
||||
#ifdef ENABLE_NANOFURRC
|
||||
extern char *custom_nanofurrc;
|
||||
|
||||
extern char *commandname;
|
||||
extern keystruct *planted_shortcut;
|
||||
#endif
|
||||
|
||||
extern bool spotlighted;
|
||||
extern size_t light_from_col;
|
||||
extern size_t light_to_col;
|
||||
|
||||
typedef void (*functionptrtype)(void);
|
||||
|
||||
/* The two needed functions from browser.c. */
|
||||
#ifdef ENABLE_BROWSER
|
||||
void browser_refresh(void);
|
||||
char *browse_in(const char *inpath);
|
||||
void to_first_file(void);
|
||||
void to_last_file(void);
|
||||
#endif
|
||||
|
||||
/* Most functions in chars.c. */
|
||||
#ifdef ENABLE_UTF8
|
||||
void utf8_init(void);
|
||||
bool using_utf8(void);
|
||||
#endif
|
||||
bool is_alpha_char(const char *c);
|
||||
bool is_blank_char(const char *c);
|
||||
bool is_cntrl_char(const char *c);
|
||||
bool is_word_char(const char *c, bool allow_punct);
|
||||
char control_mbrep(const char *c, bool isdata);
|
||||
#ifdef ENABLE_UTF8
|
||||
int mbtowide(wchar_t *wc, const char *c);
|
||||
bool is_doublewidth(const char *ch);
|
||||
bool is_zerowidth(const char *ch);
|
||||
#endif
|
||||
int char_length(const char *pointer);
|
||||
size_t mbstrlen(const char *pointer);
|
||||
int collect_char(const char *string, char *thechar);
|
||||
int advance_over(const char *string, size_t *column);
|
||||
size_t step_left(const char *buf, size_t pos);
|
||||
size_t step_right(const char *buf, size_t pos);
|
||||
int mbstrcasecmp(const char *s1, const char *s2);
|
||||
int mbstrncasecmp(const char *s1, const char *s2, size_t n);
|
||||
char *mbstrcasestr(const char *haystack, const char *needle);
|
||||
char *revstrstr(const char *haystack, const char *needle, const char *pointer);
|
||||
char *mbrevstrcasestr(const char *haystack, const char *needle, const char *pointer);
|
||||
#if !defined(NANOFUR_TINY) || defined(ENABLE_JUSTIFY)
|
||||
char *mbstrchr(const char *string, const char *chr);
|
||||
#endif
|
||||
#ifndef NANOFUR_TINY
|
||||
char *mbstrpbrk(const char *string, const char *accept);
|
||||
char *mbrevstrpbrk(const char *head, const char *accept, const char *pointer);
|
||||
#endif
|
||||
#if defined(ENABLE_NANOFURRC) && (!defined(NANOFUR_TINY) || defined(ENABLE_JUSTIFY))
|
||||
bool has_blank_char(const char *string);
|
||||
#endif
|
||||
bool white_string(const char *string);
|
||||
#if defined(ENABLE_SPELLER) || defined(ENABLE_COLOR)
|
||||
void strip_leading_blanks_from(char *string);
|
||||
#endif
|
||||
|
||||
/* Most functions in color.c. */
|
||||
#ifdef ENABLE_COLOR
|
||||
void set_interface_colorpairs(void);
|
||||
void prepare_palette(void);
|
||||
void find_and_prime_applicable_syntax(void);
|
||||
void check_the_multis(linestruct *line);
|
||||
void precalc_multicolorinfo(void);
|
||||
#endif
|
||||
|
||||
/* Most functions in cut.c. */
|
||||
void expunge(undo_type action);
|
||||
void do_delete(void);
|
||||
void do_backspace(void);
|
||||
#ifndef NANOFUR_TINY
|
||||
void chop_previous_word(void);
|
||||
void chop_next_word(void);
|
||||
#endif
|
||||
void extract_segment(linestruct *top, size_t top_x, linestruct *bot, size_t bot_x);
|
||||
void ingraft_buffer(linestruct *topline);
|
||||
void copy_from_buffer(linestruct *somebuffer);
|
||||
#ifndef NANOFUR_TINY
|
||||
void cut_marked_region(void);
|
||||
#endif
|
||||
void do_snip(bool marked, bool until_eof, bool append);
|
||||
void cut_text(void);
|
||||
#ifndef NANOFUR_TINY
|
||||
void cut_till_eof(void);
|
||||
void zap_text(void);
|
||||
void copy_marked_region(void);
|
||||
#endif
|
||||
void copy_text(void);
|
||||
void paste_text(void);
|
||||
|
||||
/* Most functions in files.c. */
|
||||
void make_new_buffer(void);
|
||||
#ifndef NANOFUR_TINY
|
||||
bool delete_lockfile(const char *lockfilename);
|
||||
#endif
|
||||
bool open_buffer(const char *filename, bool new_one);
|
||||
void set_modified(void);
|
||||
void prepare_for_display(void);
|
||||
#ifdef ENABLE_MULTIBUFFER
|
||||
void mention_name_and_linecount(void);
|
||||
void switch_to_prev_buffer(void);
|
||||
void switch_to_next_buffer(void);
|
||||
void close_buffer(void);
|
||||
#endif
|
||||
void read_file(FILE *f, int fd, const char *filename, bool undoable);
|
||||
int open_file(const char *filename, bool new_one, FILE **f);
|
||||
char *get_next_filename(const char *name, const char *suffix);
|
||||
void do_insertfile(void);
|
||||
#ifndef NANOFUR_TINY
|
||||
void do_execute(void);
|
||||
#endif
|
||||
char *get_full_path(const char *origpath);
|
||||
char *safe_tempfile(FILE **stream);
|
||||
#ifdef ENABLE_OPERATINGDIR
|
||||
void init_operating_dir(void);
|
||||
bool outside_of_confinement(const char *currpath, bool allow_tabcomp);
|
||||
#endif
|
||||
#ifndef NANOFUR_TINY
|
||||
void init_backup_dir(void);
|
||||
#endif
|
||||
int copy_file(FILE *inn, FILE *out, bool close_out);
|
||||
bool write_file(const char *name, FILE *thefile, bool normal,
|
||||
kind_of_writing_type method, bool annotate);
|
||||
#ifndef NANOFUR_TINY
|
||||
bool write_region_to_file(const char *name, FILE *stream, bool normal,
|
||||
kind_of_writing_type method);
|
||||
#endif
|
||||
int write_it_out(bool exiting, bool withprompt);
|
||||
void do_writeout(void);
|
||||
void do_savefile(void);
|
||||
char *real_dir_from_tilde(const char *path);
|
||||
#if defined(ENABLE_TABCOMP) || defined(ENABLE_BROWSER)
|
||||
int diralphasort(const void *va, const void *vb);
|
||||
#endif
|
||||
#ifdef ENABLE_TABCOMP
|
||||
char *input_tab(char *buf, size_t *place, void (*refresh_func)(void), bool *listed);
|
||||
#endif
|
||||
|
||||
/* Some functions in global.c. */
|
||||
const keystruct *first_sc_for(int menu, void (*function)(void));
|
||||
size_t shown_entries_for(int menu);
|
||||
const keystruct *get_shortcut(const int keycode);
|
||||
functionptrtype func_from_key(const int keycode);
|
||||
#if defined(ENABLE_BROWSER) || defined(ENABLE_HELP)
|
||||
functionptrtype interpret(const int keycode);
|
||||
#endif
|
||||
int keycode_from_string(const char *keystring);
|
||||
void shortcut_init(void);
|
||||
const char *epithet_of_flag(int flag);
|
||||
|
||||
/* Some functions in help.c. */
|
||||
#ifdef ENABLE_HELP
|
||||
void wrap_help_text_into_buffer(void);
|
||||
#endif
|
||||
void do_help(void);
|
||||
|
||||
/* Most functions in history.c. */
|
||||
#ifdef ENABLE_HISTORIES
|
||||
void history_init(void);
|
||||
void reset_history_pointer_for(const linestruct *list);
|
||||
void update_history(linestruct **item, const char *text, bool avoid_duplicates);
|
||||
#ifdef ENABLE_TABCOMP
|
||||
char *get_history_completion(linestruct **h, char *s, size_t len);
|
||||
#endif
|
||||
bool have_statedir(void);
|
||||
void load_history(void);
|
||||
void save_history(void);
|
||||
void load_poshistory(void);
|
||||
void update_poshistory(void);
|
||||
bool has_old_position(const char *file, ssize_t *line, ssize_t *column);
|
||||
#endif
|
||||
|
||||
/* Most functions in move.c. */
|
||||
void to_first_line(void);
|
||||
void to_last_line(void);
|
||||
void do_page_up(void);
|
||||
void do_page_down(void);
|
||||
#ifndef NANOFUR_TINY
|
||||
void to_top_row(void);
|
||||
void to_bottom_row(void);
|
||||
void do_cycle(void);
|
||||
void do_center(void);
|
||||
#endif
|
||||
#ifdef ENABLE_JUSTIFY
|
||||
void do_para_begin(linestruct **line);
|
||||
void do_para_end(linestruct **line);
|
||||
void to_para_begin(void);
|
||||
void to_para_end(void);
|
||||
#endif
|
||||
void to_prev_block(void);
|
||||
void to_next_block(void);
|
||||
void do_prev_word(void);
|
||||
bool do_next_word(bool after_ends);
|
||||
void to_prev_word(void);
|
||||
void to_next_word(void);
|
||||
void do_home(void);
|
||||
void do_end(void);
|
||||
void do_up(void);
|
||||
void do_down(void);
|
||||
#if !defined(NANOFUR_TINY) || defined(ENABLE_HELP)
|
||||
void do_scroll_up(void);
|
||||
void do_scroll_down(void);
|
||||
#endif
|
||||
void do_left(void);
|
||||
void do_right(void);
|
||||
|
||||
/* Most functions in nanofur.c. */
|
||||
linestruct *make_new_node(linestruct *prevnode);
|
||||
void splice_node(linestruct *afterthis, linestruct *newnode);
|
||||
void unlink_node(linestruct *line);
|
||||
void delete_node(linestruct *line);
|
||||
linestruct *copy_buffer(const linestruct *src);
|
||||
void free_lines(linestruct *src);
|
||||
void renumber_from(linestruct *line);
|
||||
void print_view_warning(void);
|
||||
bool in_restricted_mode(void);
|
||||
#ifndef NANOFUR_TINY
|
||||
void suggest_ctrlT_ctrlZ(void);
|
||||
#endif
|
||||
void finish(void);
|
||||
void close_and_go(void);
|
||||
void do_exit(void);
|
||||
void die(const char *msg, ...);
|
||||
void window_init(void);
|
||||
void install_handler_for_Ctrl_C(void);
|
||||
void restore_handler_for_Ctrl_C(void);
|
||||
#ifndef NANOFUR_TINY
|
||||
void reconnect_and_store_state(void);
|
||||
#endif
|
||||
void handle_hupterm(int signal);
|
||||
#ifndef DEBUG
|
||||
void handle_crash(int signal);
|
||||
#endif
|
||||
void suspend_nanofur(int signal);
|
||||
void do_suspend(void);
|
||||
void continue_nanofur(int signal);
|
||||
#if !defined(NANOFUR_TINY) || defined(ENABLE_SPELLER) || defined(ENABLE_COLOR)
|
||||
void block_sigwinch(bool blockit);
|
||||
#endif
|
||||
#ifndef NANOFUR_TINY
|
||||
void handle_sigwinch(int signal);
|
||||
void regenerate_screen(void);
|
||||
#endif
|
||||
void disable_kb_interrupt(void);
|
||||
void enable_kb_interrupt(void);
|
||||
void disable_flow_control(void);
|
||||
void enable_flow_control(void);
|
||||
void terminal_init(void);
|
||||
#ifdef ENABLE_LINENUMBERS
|
||||
void confirm_margin(void);
|
||||
#endif
|
||||
void unbound_key(int code);
|
||||
bool changes_something(functionptrtype f);
|
||||
void inject(char *burst, size_t count);
|
||||
|
||||
/* Most functions in prompt.c. */
|
||||
size_t get_statusbar_page_start(size_t base, size_t column);
|
||||
void put_cursor_at_end_of_answer(void);
|
||||
void add_or_remove_pipe_symbol_from_answer(void);
|
||||
int do_prompt(int menu, const char *provided, linestruct **history_list,
|
||||
void (*refresh_func)(void), const char *msg, ...);
|
||||
int ask_user(bool withall, const char *question);
|
||||
|
||||
/* Most functions in rcfile.c. */
|
||||
#if defined(ENABLE_NANOFURRC) || defined(ENABLE_HISTORIES)
|
||||
void display_rcfile_errors(void);
|
||||
void jot_error(const char *msg, ...);
|
||||
#endif
|
||||
#ifdef ENABLE_NANOFURRC
|
||||
keystruct *strtosc(const char *input);
|
||||
#ifdef ENABLE_COLOR
|
||||
void parse_one_include(char *file, syntaxtype *syntax);
|
||||
void grab_and_store(const char *kind, char *ptr, regexlisttype **storage);
|
||||
bool parse_syntax_commands(char *keyword, char *ptr);
|
||||
#endif
|
||||
void parse_rcfile(FILE *rcstream, bool just_syntax, bool intros_only);
|
||||
void do_rcfiles(void);
|
||||
#endif /* ENABLE_NANOFURRC */
|
||||
|
||||
/* Most functions in search.c. */
|
||||
bool regexp_init(const char *regexp);
|
||||
void tidy_up_after_search(void);
|
||||
int findnextstr(const char *needle, bool whole_word_only, int modus,
|
||||
size_t *match_len, bool skipone, const linestruct *begin, size_t begin_x);
|
||||
void do_search_forward(void);
|
||||
void do_search_backward(void);
|
||||
void do_findprevious(void);
|
||||
void do_findnext(void);
|
||||
void not_found_msg(const char *str);
|
||||
void go_looking(void);
|
||||
ssize_t do_replace_loop(const char *needle, bool whole_word_only,
|
||||
const linestruct *real_current, size_t *real_current_x);
|
||||
void do_replace(void);
|
||||
void ask_for_and_do_replacements(void);
|
||||
#if !defined(NANOFUR_TINY) || defined(ENABLE_SPELLER) || defined (ENABLE_LINTER) || defined (ENABLE_FORMATTER)
|
||||
void goto_line_posx(ssize_t line, size_t pos_x);
|
||||
#endif
|
||||
void goto_line_and_column(ssize_t line, ssize_t column, bool retain_answer,
|
||||
bool interactive);
|
||||
void do_gotolinecolumn(void);
|
||||
#ifndef NANOFUR_TINY
|
||||
void do_find_bracket(void);
|
||||
void put_or_lift_anchor(void);
|
||||
void to_prev_anchor(void);
|
||||
void to_next_anchor(void);
|
||||
#endif
|
||||
|
||||
/* Most functions in text.c. */
|
||||
#ifndef NANOFUR_TINY
|
||||
void do_mark(void);
|
||||
#endif
|
||||
void do_tab(void);
|
||||
#ifndef NANOFUR_TINY
|
||||
void do_indent(void);
|
||||
void do_unindent(void);
|
||||
#endif
|
||||
#ifdef ENABLE_COMMENT
|
||||
void do_comment(void);
|
||||
#endif
|
||||
void do_undo(void);
|
||||
void do_redo(void);
|
||||
void do_enter(void);
|
||||
#ifndef NANOFUR_TINY
|
||||
void discard_until(const undostruct *thisitem);
|
||||
void add_undo(undo_type action, const char *message);
|
||||
void update_multiline_undo(ssize_t lineno, char *indentation);
|
||||
void update_undo(undo_type action);
|
||||
#endif /* !NANOFUR_TINY */
|
||||
#ifdef ENABLE_WRAPPING
|
||||
void do_wrap(void);
|
||||
#endif
|
||||
#if defined(ENABLE_HELP) || defined(ENABLED_WRAPORJUSTIFY)
|
||||
ssize_t break_line(const char *textstart, ssize_t goal, bool snap_at_nl);
|
||||
#endif
|
||||
#if !defined(NANOFUR_TINY) || defined(ENABLED_WRAPORJUSTIFY)
|
||||
size_t indent_length(const char *line);
|
||||
#endif
|
||||
#ifdef ENABLE_JUSTIFY
|
||||
size_t quote_length(const char *line);
|
||||
bool begpar(const linestruct *const line, int depth);
|
||||
bool inpar(const linestruct *const line);
|
||||
void do_justify(void);
|
||||
void do_full_justify(void);
|
||||
#endif
|
||||
#ifdef ENABLE_SPELLER
|
||||
void do_spell(void);
|
||||
#endif
|
||||
#ifdef ENABLE_LINTER
|
||||
void do_linter(void);
|
||||
#endif
|
||||
#ifdef ENABLE_FORMATTER
|
||||
void do_formatter(void);
|
||||
#endif
|
||||
#ifndef NANOFUR_TINY
|
||||
void count_lines_words_and_characters(void);
|
||||
#endif
|
||||
void do_verbatim_input(void);
|
||||
#ifdef ENABLE_WORDCOMPLETION
|
||||
void complete_a_word(void);
|
||||
#endif
|
||||
|
||||
/* All functions in utils.c. */
|
||||
void get_homedir(void);
|
||||
const char *tail(const char *path);
|
||||
char *concatenate(const char *path, const char *name);
|
||||
int digits(ssize_t n);
|
||||
bool parse_num(const char *str, ssize_t *result);
|
||||
bool parse_line_column(const char *str, ssize_t *line, ssize_t *column);
|
||||
void recode_NUL_to_LF(char *string, size_t length);
|
||||
size_t recode_LF_to_NUL(char *string);
|
||||
#if !defined(ENABLE_TINY) || defined(ENABLE_TABCOMP) || defined(ENABLE_BROWSER)
|
||||
void free_chararray(char **array, size_t len);
|
||||
#endif
|
||||
#ifdef ENABLE_SPELLER
|
||||
bool is_separate_word(size_t position, size_t length, const char *buf);
|
||||
#endif
|
||||
const char *strstrwrapper(const char *haystack, const char *needle,
|
||||
const char *start);
|
||||
void *nmalloc(size_t howmuch);
|
||||
void *nrealloc(void *ptr, size_t howmuch);
|
||||
char *measured_copy(const char *string, size_t count);
|
||||
char *mallocstrcpy(char *dest, const char *src);
|
||||
char *copy_of(const char *string);
|
||||
char *free_and_assign(char *dest, char *src);
|
||||
size_t get_page_start(size_t column);
|
||||
size_t xplustabs(void);
|
||||
size_t actual_x(const char *text, size_t column);
|
||||
size_t wideness(const char *text, size_t maxlen);
|
||||
size_t breadth(const char *text);
|
||||
void new_magicline(void);
|
||||
#if !defined(NANOFUR_TINY) || defined(ENABLE_HELP)
|
||||
void remove_magicline(void);
|
||||
#endif
|
||||
#ifndef NANOFUR_TINY
|
||||
bool mark_is_before_cursor(void);
|
||||
void get_region(linestruct **top, size_t *top_x, linestruct **bot, size_t *bot_x);
|
||||
void get_range(linestruct **top, linestruct **bot);
|
||||
#endif
|
||||
size_t number_of_characters_in(const linestruct *begin, const linestruct *end);
|
||||
#if !defined(NANOFUR_TINY) || defined(ENABLE_SPELLER) || defined (ENABLE_LINTER) || defined (ENABLE_FORMATTER)
|
||||
linestruct *line_from_number(ssize_t number);
|
||||
#endif
|
||||
|
||||
/* Most functions in winio.c. */
|
||||
#ifndef NANOFUR_TINY
|
||||
void record_macro(void);
|
||||
void run_macro(void);
|
||||
#endif
|
||||
size_t waiting_keycodes(void);
|
||||
void put_back(int keycode);
|
||||
#ifdef ENABLE_NANOFURRC
|
||||
void implant(const char *string);
|
||||
#endif
|
||||
int get_input(WINDOW *win);
|
||||
int get_kbinput(WINDOW *win, bool showcursor);
|
||||
char *get_verbatim_kbinput(WINDOW *win, size_t *count);
|
||||
#ifdef ENABLE_MOUSE
|
||||
int get_mouseinput(int *mouse_y, int *mouse_x, bool allow_shortcuts);
|
||||
#endif
|
||||
void blank_edit(void);
|
||||
void blank_statusbar(void);
|
||||
void wipe_statusbar(void);
|
||||
void blank_bottombars(void);
|
||||
void blank_it_when_expired(void);
|
||||
void set_blankdelay_to_one(void);
|
||||
char *display_string(const char *buf, size_t column, size_t span,
|
||||
bool isdata, bool isprompt);
|
||||
void titlebar(const char *path);
|
||||
void minibar(void);
|
||||
void statusline(message_type importance, const char *msg, ...);
|
||||
void statusbar(const char *msg);
|
||||
void warn_and_briefly_pause(const char *msg);
|
||||
void bottombars(int menu);
|
||||
void post_one_key(const char *keystroke, const char *tag, int width);
|
||||
void place_the_cursor(void);
|
||||
int update_line(linestruct *line, size_t index);
|
||||
#ifndef NANOFUR_TINY
|
||||
int update_softwrapped_line(linestruct *line);
|
||||
#endif
|
||||
bool line_needs_update(const size_t old_column, const size_t new_column);
|
||||
int go_back_chunks(int nrows, linestruct **line, size_t *leftedge);
|
||||
int go_forward_chunks(int nrows, linestruct **line, size_t *leftedge);
|
||||
bool less_than_a_screenful(size_t was_lineno, size_t was_leftedge);
|
||||
void edit_scroll(bool direction);
|
||||
#ifndef NANOFUR_TINY
|
||||
size_t get_softwrap_breakpoint(const char *linedata, size_t leftedge,
|
||||
bool *kickoff, bool *end_of_line);
|
||||
size_t get_chunk_and_edge(size_t column, linestruct *line, size_t *leftedge);
|
||||
size_t chunk_for(size_t column, linestruct *line);
|
||||
size_t leftedge_for(size_t column, linestruct *line);
|
||||
size_t extra_chunks_in(linestruct *line);
|
||||
void ensure_firstcolumn_is_aligned(void);
|
||||
#endif
|
||||
size_t actual_last_column(size_t leftedge, size_t column);
|
||||
void edit_redraw(linestruct *old_current, update_type manner);
|
||||
void edit_refresh(void);
|
||||
void adjust_viewport(update_type manner);
|
||||
void full_refresh(void);
|
||||
void draw_all_subwindows(void);
|
||||
void report_cursor_position(void);
|
||||
void spotlight(size_t from_col, size_t to_col);
|
||||
#ifndef NANOFUR_TINY
|
||||
void spotlight_softwrapped(size_t from_col, size_t to_col);
|
||||
#endif
|
||||
#ifdef ENABLE_EXTRA
|
||||
void do_credits(void);
|
||||
#endif
|
||||
|
||||
/* These are just name definitions. */
|
||||
void case_sens_void(void);
|
||||
void regexp_void(void);
|
||||
void backwards_void(void);
|
||||
#ifdef ENABLE_HISTORIES
|
||||
void get_older_item(void);
|
||||
void get_newer_item(void);
|
||||
#endif
|
||||
void flip_replace(void);
|
||||
void flip_goto(void);
|
||||
#ifdef ENABLE_BROWSER
|
||||
void to_files(void);
|
||||
void goto_dir(void);
|
||||
#endif
|
||||
#ifndef NANOFUR_TINY
|
||||
void do_nothing(void);
|
||||
void do_toggle(void);
|
||||
void dos_format(void);
|
||||
void mac_format(void);
|
||||
void append_it(void);
|
||||
void prepend_it(void);
|
||||
void back_it_up(void);
|
||||
void flip_execute(void);
|
||||
void flip_pipe(void);
|
||||
void flip_convert(void);
|
||||
#endif
|
||||
#ifdef ENABLE_MULTIBUFFER
|
||||
void flip_newbuffer(void);
|
||||
#endif
|
||||
void discard_buffer(void);
|
||||
void do_cancel(void);
|
1760
src/rcfile.c
Normal file
1760
src/rcfile.c
Normal file
File diff suppressed because it is too large
Load diff
1056
src/search.c
Normal file
1056
src/search.c
Normal file
File diff suppressed because it is too large
Load diff
3264
src/text.c
Normal file
3264
src/text.c
Normal file
File diff suppressed because it is too large
Load diff
526
src/utils.c
Normal file
526
src/utils.c
Normal file
|
@ -0,0 +1,526 @@
|
|||
/**************************************************************************
|
||||
* utils.c -- This file is part of GNU nanofur. *
|
||||
* *
|
||||
* Copyright (C) 1999-2011, 2013-2024 Free Software Foundation, Inc. *
|
||||
* Copyright (C) 2016, 2017, 2019 Benno Schulenberg *
|
||||
* *
|
||||
* GNU nanofur 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. *
|
||||
* *
|
||||
* GNU nanofur 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 http://www.gnu.org/licenses/. *
|
||||
* *
|
||||
**************************************************************************/
|
||||
|
||||
#include "prototypes.h"
|
||||
|
||||
#include <errno.h>
|
||||
#ifdef HAVE_PWD_H
|
||||
#include <pwd.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* Return the user's home directory. We use $HOME, and if that fails,
|
||||
* we fall back on the home directory of the effective user ID. */
|
||||
void get_homedir(void)
|
||||
{
|
||||
if (homedir == NULL) {
|
||||
const char *homenv = getenv("HOME");
|
||||
|
||||
#ifdef HAVE_PWD_H
|
||||
/* When HOME isn't set, or when we're root, get the home directory
|
||||
* from the password file instead. */
|
||||
if (homenv == NULL || geteuid() == ROOT_UID) {
|
||||
const struct passwd *userage = getpwuid(geteuid());
|
||||
|
||||
if (userage != NULL)
|
||||
homenv = userage->pw_dir;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Only set homedir if some home directory could be determined,
|
||||
* otherwise keep homedir NULL. */
|
||||
if (homenv != NULL && *homenv != '\0')
|
||||
homedir = copy_of(homenv);
|
||||
}
|
||||
}
|
||||
|
||||
/* Return the filename part of the given path. */
|
||||
const char *tail(const char *path)
|
||||
{
|
||||
const char *slash = strrchr(path, '/');
|
||||
|
||||
if (slash == NULL)
|
||||
return path;
|
||||
else
|
||||
return slash + 1;
|
||||
}
|
||||
|
||||
/* Return a copy of the two given strings, welded together. */
|
||||
char *concatenate(const char *path, const char *name)
|
||||
{
|
||||
size_t pathlen = strlen(path);
|
||||
char *joined = nmalloc(pathlen + strlen(name) + 1);
|
||||
|
||||
strcpy(joined, path);
|
||||
strcpy(joined + pathlen, name);
|
||||
|
||||
return joined;
|
||||
}
|
||||
|
||||
/* Return the number of digits that the given integer n takes up. */
|
||||
int digits(ssize_t n)
|
||||
{
|
||||
if (n < 100000) {
|
||||
if (n < 1000) {
|
||||
if (n < 100)
|
||||
return 2;
|
||||
else
|
||||
return 3;
|
||||
} else {
|
||||
if (n < 10000)
|
||||
return 4;
|
||||
else
|
||||
return 5;
|
||||
}
|
||||
} else {
|
||||
if (n < 10000000) {
|
||||
if (n < 1000000)
|
||||
return 6;
|
||||
else
|
||||
return 7;
|
||||
} else {
|
||||
if (n < 100000000)
|
||||
return 8;
|
||||
else
|
||||
return 9;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Read an integer from the given string. If it parses okay,
|
||||
* store it in *result and return TRUE; otherwise, return FALSE. */
|
||||
bool parse_num(const char *string, ssize_t *result)
|
||||
{
|
||||
ssize_t value;
|
||||
char *excess;
|
||||
|
||||
/* Clear the error number so that we can check it afterward. */
|
||||
errno = 0;
|
||||
|
||||
value = (ssize_t)strtol(string, &excess, 10);
|
||||
|
||||
if (errno == ERANGE || *string == '\0' || *excess != '\0')
|
||||
return FALSE;
|
||||
|
||||
*result = value;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Read one number (or two numbers separated by comma, period, or colon)
|
||||
* from the given string and store the number(s) in *line (and *column).
|
||||
* Return FALSE on a failed parsing, and TRUE otherwise. */
|
||||
bool parse_line_column(const char *string, ssize_t *line, ssize_t *column)
|
||||
{
|
||||
const char *comma;
|
||||
char *firstpart;
|
||||
bool retval;
|
||||
|
||||
while (*string == ' ')
|
||||
string++;
|
||||
|
||||
comma = strpbrk(string, ",.:");
|
||||
|
||||
if (comma == NULL)
|
||||
return parse_num(string, line);
|
||||
|
||||
retval = parse_num(comma + 1, column);
|
||||
|
||||
if (comma == string)
|
||||
return retval;
|
||||
|
||||
firstpart = copy_of(string);
|
||||
firstpart[comma - string] = '\0';
|
||||
|
||||
retval = parse_num(firstpart, line) && retval;
|
||||
|
||||
free(firstpart);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* In the given string, recode each embedded NUL as a newline. */
|
||||
void recode_NUL_to_LF(char *string, size_t length)
|
||||
{
|
||||
while (length > 0) {
|
||||
if (*string == '\0')
|
||||
*string = '\n';
|
||||
length--;
|
||||
string++;
|
||||
}
|
||||
}
|
||||
|
||||
/* In the given string, recode each embedded newline as a NUL,
|
||||
* and return the number of bytes in the string. */
|
||||
size_t recode_LF_to_NUL(char *string)
|
||||
{
|
||||
char *beginning = string;
|
||||
|
||||
while (*string != '\0') {
|
||||
if (*string == '\n')
|
||||
*string = '\0';
|
||||
string++;
|
||||
}
|
||||
|
||||
return (string - beginning);
|
||||
}
|
||||
|
||||
#if !defined(ENABLE_TINY) || defined(ENABLE_TABCOMP) || defined(ENABLE_BROWSER)
|
||||
/* Free the memory of the given array, which should contain len elements. */
|
||||
void free_chararray(char **array, size_t len)
|
||||
{
|
||||
if (array == NULL)
|
||||
return;
|
||||
|
||||
while (len > 0)
|
||||
free(array[--len]);
|
||||
|
||||
free(array);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_SPELLER
|
||||
/* Is the word starting at the given position in 'text' and of the given
|
||||
* length a separate word? That is: is it not part of a longer word? */
|
||||
bool is_separate_word(size_t position, size_t length, const char *text)
|
||||
{
|
||||
const char *before = text + step_left(text, position);
|
||||
const char *after = text + position + length;
|
||||
|
||||
/* If the word starts at the beginning of the line OR the character before
|
||||
* the word isn't a letter, and if the word ends at the end of the line OR
|
||||
* the character after the word isn't a letter, we have a whole word. */
|
||||
return ((position == 0 || !is_alpha_char(before)) &&
|
||||
(*after == '\0' || !is_alpha_char(after)));
|
||||
}
|
||||
#endif /* ENABLE_SPELLER */
|
||||
|
||||
/* Return the position of the needle in the haystack, or NULL if not found.
|
||||
* When searching backwards, we will find the last match that starts no later
|
||||
* than the given start; otherwise, we find the first match starting no earlier
|
||||
* than start. If we are doing a regexp search, and we find a match, we fill
|
||||
* in the global variable regmatches with at most 9 subexpression matches. */
|
||||
const char *strstrwrapper(const char *haystack, const char *needle,
|
||||
const char *start)
|
||||
{
|
||||
if (ISSET(USE_REGEXP)) {
|
||||
if (ISSET(BACKWARDS_SEARCH)) {
|
||||
size_t last_find, ceiling, far_end;
|
||||
size_t floor = 0, next_rung = 0;
|
||||
/* The start of the search range, and the next start. */
|
||||
|
||||
if (regexec(&search_regexp, haystack, 1, regmatches, 0) != 0)
|
||||
return NULL;
|
||||
|
||||
far_end = strlen(haystack);
|
||||
ceiling = start - haystack;
|
||||
last_find = regmatches[0].rm_so;
|
||||
|
||||
/* A result beyond the search range also means: no match. */
|
||||
if (last_find > ceiling)
|
||||
return NULL;
|
||||
|
||||
/* Move the start-of-range forward until there is no more match;
|
||||
* then the last match found is the first match backwards. */
|
||||
while (regmatches[0].rm_so <= ceiling) {
|
||||
floor = next_rung;
|
||||
last_find = regmatches[0].rm_so;
|
||||
/* If this is the last possible match, don't try to advance. */
|
||||
if (last_find == ceiling)
|
||||
break;
|
||||
next_rung = step_right(haystack, last_find);
|
||||
regmatches[0].rm_so = next_rung;
|
||||
regmatches[0].rm_eo = far_end;
|
||||
if (regexec(&search_regexp, haystack, 1, regmatches,
|
||||
REG_STARTEND) != 0)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Find the last match again, to get possible submatches. */
|
||||
regmatches[0].rm_so = floor;
|
||||
regmatches[0].rm_eo = far_end;
|
||||
if (regexec(&search_regexp, haystack, 10, regmatches,
|
||||
REG_STARTEND) != 0)
|
||||
return NULL;
|
||||
|
||||
return haystack + regmatches[0].rm_so;
|
||||
}
|
||||
|
||||
/* Do a forward regex search from the starting point. */
|
||||
regmatches[0].rm_so = start - haystack;
|
||||
regmatches[0].rm_eo = strlen(haystack);
|
||||
if (regexec(&search_regexp, haystack, 10, regmatches,
|
||||
REG_STARTEND) != 0)
|
||||
return NULL;
|
||||
else
|
||||
return haystack + regmatches[0].rm_so;
|
||||
}
|
||||
|
||||
if (ISSET(CASE_SENSITIVE)) {
|
||||
if (ISSET(BACKWARDS_SEARCH))
|
||||
return revstrstr(haystack, needle, start);
|
||||
else
|
||||
return strstr(start, needle);
|
||||
}
|
||||
|
||||
if (ISSET(BACKWARDS_SEARCH))
|
||||
return mbrevstrcasestr(haystack, needle, start);
|
||||
else
|
||||
return mbstrcasestr(start, needle);
|
||||
}
|
||||
|
||||
/* Allocate the given amount of memory and return a pointer to it. */
|
||||
void *nmalloc(size_t howmuch)
|
||||
{
|
||||
void *section = malloc(howmuch);
|
||||
|
||||
if (section == NULL)
|
||||
die(_("Nanofur is out of memory!\n"));
|
||||
|
||||
return section;
|
||||
}
|
||||
|
||||
/* Reallocate the given section of memory to have the given size. */
|
||||
void *nrealloc(void *section, size_t howmuch)
|
||||
{
|
||||
section = realloc(section, howmuch);
|
||||
|
||||
if (section == NULL)
|
||||
die(_("Nanofur is out of memory!\n"));
|
||||
|
||||
return section;
|
||||
}
|
||||
|
||||
/* Return an appropriately reallocated dest string holding a copy of src.
|
||||
* Usage: "dest = mallocstrcpy(dest, src);". */
|
||||
char *mallocstrcpy(char *dest, const char *src)
|
||||
{
|
||||
size_t count = strlen(src) + 1;
|
||||
|
||||
dest = nrealloc(dest, count);
|
||||
strncpy(dest, src, count);
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/* Return an allocated copy of the first count characters
|
||||
* of the given string, and NUL-terminate the copy. */
|
||||
char *measured_copy(const char *string, size_t count)
|
||||
{
|
||||
char *thecopy = nmalloc(count + 1);
|
||||
|
||||
memcpy(thecopy, string, count);
|
||||
thecopy[count] = '\0';
|
||||
|
||||
return thecopy;
|
||||
}
|
||||
|
||||
/* Return an allocated copy of the given string. */
|
||||
char *copy_of(const char *string)
|
||||
{
|
||||
return measured_copy(string, strlen(string));
|
||||
}
|
||||
|
||||
/* Free the string at dest and return the string at src. */
|
||||
char *free_and_assign(char *dest, char *src)
|
||||
{
|
||||
free(dest);
|
||||
return src;
|
||||
}
|
||||
|
||||
/* When not softwrapping, nanofur scrolls the current line horizontally by
|
||||
* chunks ("pages"). Return the column number of the first character
|
||||
* displayed in the edit window when the cursor is at the given column. */
|
||||
size_t get_page_start(size_t column)
|
||||
{
|
||||
if (column == 0 || column + 2 < editwincols || ISSET(SOFTWRAP))
|
||||
return 0;
|
||||
else if (editwincols > 8)
|
||||
return column - 6 - (column - 6) % (editwincols - 8);
|
||||
else
|
||||
return column - (editwincols - 2);
|
||||
}
|
||||
|
||||
/* Return the placewewant associated with current_x, i.e. the zero-based
|
||||
* column position of the cursor. */
|
||||
size_t xplustabs(void)
|
||||
{
|
||||
return wideness(openfile->current->data, openfile->current_x);
|
||||
}
|
||||
|
||||
/* Return the index in text of the character that (when displayed) will
|
||||
* not overshoot the given column. */
|
||||
size_t actual_x(const char *text, size_t column)
|
||||
{
|
||||
const char *start = text;
|
||||
/* From where we start walking through the text. */
|
||||
size_t width = 0;
|
||||
/* The current accumulated span, in columns. */
|
||||
|
||||
while (*text != '\0') {
|
||||
int charlen = advance_over(text, &width);
|
||||
|
||||
if (width > column)
|
||||
break;
|
||||
|
||||
text += charlen;
|
||||
}
|
||||
|
||||
return (text - start);
|
||||
}
|
||||
|
||||
/* A strnlen() with tabs and multicolumn characters factored in:
|
||||
* how many columns wide are the first maxlen bytes of text? */
|
||||
size_t wideness(const char *text, size_t maxlen)
|
||||
{
|
||||
size_t width = 0;
|
||||
|
||||
if (maxlen == 0)
|
||||
return 0;
|
||||
|
||||
while (*text != '\0') {
|
||||
size_t charlen = advance_over(text, &width);
|
||||
|
||||
if (maxlen <= charlen)
|
||||
break;
|
||||
|
||||
maxlen -= charlen;
|
||||
text += charlen;
|
||||
}
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
/* Return the number of columns that the given text occupies. */
|
||||
size_t breadth(const char *text)
|
||||
{
|
||||
size_t span = 0;
|
||||
|
||||
while (*text != '\0')
|
||||
text += advance_over(text, &span);
|
||||
|
||||
return span;
|
||||
}
|
||||
|
||||
/* Append a new magic line to the end of the buffer. */
|
||||
void new_magicline(void)
|
||||
{
|
||||
openfile->filebot->next = make_new_node(openfile->filebot);
|
||||
openfile->filebot->next->data = copy_of("");
|
||||
openfile->filebot = openfile->filebot->next;
|
||||
openfile->totsize++;
|
||||
}
|
||||
|
||||
#if !defined(NANOFUR_TINY) || defined(ENABLE_HELP)
|
||||
/* Remove the magic line from the end of the buffer, if there is one and
|
||||
* it isn't the only line in the file. */
|
||||
void remove_magicline(void)
|
||||
{
|
||||
if (openfile->filebot->data[0] == '\0' &&
|
||||
openfile->filebot != openfile->filetop) {
|
||||
if (openfile->current == openfile->filebot)
|
||||
openfile->current = openfile->current->prev;
|
||||
openfile->filebot = openfile->filebot->prev;
|
||||
delete_node(openfile->filebot->next);
|
||||
openfile->filebot->next = NULL;
|
||||
openfile->totsize--;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef NANOFUR_TINY
|
||||
/* Return TRUE when the mark is before or at the cursor, and FALSE otherwise. */
|
||||
bool mark_is_before_cursor(void)
|
||||
{
|
||||
return (openfile->mark->lineno < openfile->current->lineno ||
|
||||
(openfile->mark == openfile->current &&
|
||||
openfile->mark_x <= openfile->current_x));
|
||||
}
|
||||
|
||||
/* Return in (top, top_x) and (bot, bot_x) the start and end "coordinates"
|
||||
* of the marked region. */
|
||||
void get_region(linestruct **top, size_t *top_x, linestruct **bot, size_t *bot_x)
|
||||
{
|
||||
if (mark_is_before_cursor()) {
|
||||
*top = openfile->mark;
|
||||
*top_x = openfile->mark_x;
|
||||
*bot = openfile->current;
|
||||
*bot_x = openfile->current_x;
|
||||
} else {
|
||||
*bot = openfile->mark;
|
||||
*bot_x = openfile->mark_x;
|
||||
*top = openfile->current;
|
||||
*top_x = openfile->current_x;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get the set of lines to work on -- either just the current line, or the
|
||||
* first to last lines of the marked region. When the cursor (or mark) is
|
||||
* at the start of the last line of the region, exclude that line. */
|
||||
void get_range(linestruct **top, linestruct **bot)
|
||||
{
|
||||
if (!openfile->mark) {
|
||||
*top = openfile->current;
|
||||
*bot = openfile->current;
|
||||
} else {
|
||||
size_t top_x, bot_x;
|
||||
|
||||
get_region(top, &top_x, bot, &bot_x);
|
||||
|
||||
if (bot_x == 0 && *bot != *top && !also_the_last)
|
||||
*bot = (*bot)->prev;
|
||||
else
|
||||
also_the_last = TRUE;
|
||||
}
|
||||
}
|
||||
#endif /* !NANOFUR_TINY */
|
||||
|
||||
#if !defined(NANOFUR_TINY) || defined(ENABLE_SPELLER) || defined (ENABLE_LINTER) || defined (ENABLE_FORMATTER)
|
||||
/* Return a pointer to the line that has the given line number. */
|
||||
linestruct *line_from_number(ssize_t number)
|
||||
{
|
||||
linestruct *line = openfile->current;
|
||||
|
||||
if (line->lineno > number)
|
||||
while (line->lineno != number)
|
||||
line = line->prev;
|
||||
else
|
||||
while (line->lineno != number)
|
||||
line = line->next;
|
||||
|
||||
return line;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Count the number of characters from begin to end, and return it. */
|
||||
size_t number_of_characters_in(const linestruct *begin, const linestruct *end)
|
||||
{
|
||||
const linestruct *line;
|
||||
size_t count = 0;
|
||||
|
||||
/* Sum the number of characters (plus a newline) in each line. */
|
||||
for (line = begin; line != end->next; line = line->next)
|
||||
count += mbstrlen(line->data) + 1;
|
||||
|
||||
/* Do not count the final newline. */
|
||||
return (count - 1);
|
||||
}
|
3734
src/winio.c
Normal file
3734
src/winio.c
Normal file
File diff suppressed because it is too large
Load diff
49
syntax/Makefile.am
Normal file
49
syntax/Makefile.am
Normal file
|
@ -0,0 +1,49 @@
|
|||
pkgdata_DATA = asm.nanofurrc \
|
||||
autoconf.nanofurrc \
|
||||
awk.nanofurrc \
|
||||
changelog.nanofurrc \
|
||||
cmake.nanofurrc \
|
||||
c.nanofurrc \
|
||||
css.nanofurrc \
|
||||
default.nanofurrc \
|
||||
elisp.nanofurrc \
|
||||
email.nanofurrc \
|
||||
go.nanofurrc \
|
||||
groff.nanofurrc \
|
||||
guile.nanofurrc \
|
||||
html.nanofurrc \
|
||||
java.nanofurrc \
|
||||
javascript.nanofurrc \
|
||||
json.nanofurrc \
|
||||
lua.nanofurrc \
|
||||
makefile.nanofurrc \
|
||||
man.nanofurrc \
|
||||
markdown.nanofurrc \
|
||||
nanofurhelp.nanofurrc \
|
||||
nanofurrc.nanofurrc \
|
||||
nftables.nanofurrc \
|
||||
objc.nanofurrc \
|
||||
ocaml.nanofurrc \
|
||||
patch.nanofurrc \
|
||||
perl.nanofurrc \
|
||||
php.nanofurrc \
|
||||
po.nanofurrc \
|
||||
python.nanofurrc \
|
||||
ruby.nanofurrc \
|
||||
rust.nanofurrc \
|
||||
sh.nanofurrc \
|
||||
sql.nanofurrc \
|
||||
tcl.nanofurrc \
|
||||
tex.nanofurrc \
|
||||
texinfo.nanofurrc \
|
||||
xml.nanofurrc \
|
||||
yaml.nanofurrc
|
||||
|
||||
nobase_pkgdata_DATA = \
|
||||
extra/ada.nanofurrc \
|
||||
extra/fortran.nanofurrc \
|
||||
extra/haskell.nanofurrc \
|
||||
extra/povray.nanofurrc \
|
||||
extra/spec.nanofurrc
|
||||
|
||||
EXTRA_DIST = $(pkgdata_DATA) $(nobase_pkgdata_DATA)
|
24
syntax/asm.nanofurrc
Normal file
24
syntax/asm.nanofurrc
Normal file
|
@ -0,0 +1,24 @@
|
|||
## Syntax highlighting for assembler.
|
||||
|
||||
## Original author: Mike Frysinger
|
||||
|
||||
syntax asm "\.(S|s|asm)$"
|
||||
magic "assembler source"
|
||||
comment "//"
|
||||
|
||||
color red "\<[A-Z_]{2,}\>"
|
||||
color brightgreen "\.(data|subsection|text)\>"
|
||||
color green "\.(align|file|globl|global|hidden|section|size|type|weak)\>"
|
||||
color brightyellow "\.(ascii|asciz|byte|double|float|hword|int|long|short|single|struct|word)\>"
|
||||
color brightred "^[[:blank:]]*[.0-9A-Za-z_]*:"
|
||||
color brightcyan "^[[:blank:]]*#[[:blank:]]*(define|undef|include|ifn?def|endif|elif|else|if|warning|error)\>"
|
||||
|
||||
# Strings and names of included files.
|
||||
color brightyellow ""([^"\]|\\.)*"|<[^= ]*>"
|
||||
|
||||
# Comments.
|
||||
color brightblue "//.*"
|
||||
color brightblue start="/\*" end="\*/"
|
||||
|
||||
# Trailing whitespace.
|
||||
color ,green "[[:space:]]+$"
|
35
syntax/autoconf.nanofurrc
Normal file
35
syntax/autoconf.nanofurrc
Normal file
|
@ -0,0 +1,35 @@
|
|||
## Syntax highlighting for Autoconf.
|
||||
|
||||
## Original author: Benno Schulenberg
|
||||
## License: GPL version 3 or newer
|
||||
|
||||
syntax autoconf "\.(ac|m4)$"
|
||||
comment "#"
|
||||
|
||||
# Keywords:
|
||||
color yellow "\<(if|test|then|elif|else|fi|case|esac|ifelse|for|in|do|done)\>"
|
||||
color yellow "=|!=|&&|\|\|"
|
||||
|
||||
# Macros:
|
||||
color cyan "\<[[:upper:]_[:digit:]]+\>"
|
||||
|
||||
# Version numbers:
|
||||
color red "\<[-_.0-9]+\>"
|
||||
|
||||
# Strings:
|
||||
color red ""[^"]*"|'[^']*'"
|
||||
|
||||
# Backticks:
|
||||
color green "`[^`]*`"
|
||||
|
||||
# Error lines:
|
||||
color brightred "^[[:blank:]]*\*\*\*.*"
|
||||
|
||||
# Brackets:
|
||||
color magenta "\[|\]|\(|\)"
|
||||
|
||||
# Comments:
|
||||
color blue "^[[:blank:]]*#.*" "\<dnl.*"
|
||||
|
||||
# Trailing whitespace:
|
||||
color ,green "[[:space:]]+$"
|
41
syntax/awk.nanofurrc
Normal file
41
syntax/awk.nanofurrc
Normal file
|
@ -0,0 +1,41 @@
|
|||
## Syntax highlighting for AWK scripts.
|
||||
|
||||
## Original author: Donnie Berkholz
|
||||
|
||||
syntax awk "\.awk$"
|
||||
header "^#!.*awk"
|
||||
magic "awk script"
|
||||
comment "#"
|
||||
|
||||
# Records.
|
||||
color brightred "\$[0-9A-Za-z_!@#$*?-]+"
|
||||
# Awk-set variables.
|
||||
color red "\<(ARGC|ARGIND|ARGV|BINMODE|CONVFMT|ENVIRON|ERRNO|FIELDWIDTHS)\>"
|
||||
color red "\<(FILENAME|FNR|FS|IGNORECASE|LINT|NF|NR|OFMT|OFS|ORS)\>"
|
||||
color red "\<(PROCINFO|RS|RT|RSTART|RLENGTH|SUBSEP|TEXTDOMAIN)\>"
|
||||
# Function declarations and special patterns.
|
||||
color brightgreen "\<(function|extension|BEGIN|END)\>"
|
||||
# Operators and brackets/braces/slashes/parentheses.
|
||||
color green "[][!%&()*+/:;<=>?\^{|}~-]"
|
||||
# Flow control.
|
||||
color brightyellow "\<(for|if|while|do|else|in|delete|exit)\>"
|
||||
color brightyellow "\<(break|continue|return)\>"
|
||||
# I/O statements.
|
||||
color brightgreen "\<(close|fflush|getline|next|nextfile|print|printf|system)\>"
|
||||
# Standard functions.
|
||||
color magenta "\<(atan2|cos|exp|int|log|rand|sin|sqrt|srand)\>"
|
||||
color magenta "\<(asort|asorti|gensub|gsub|index|length|match)\>"
|
||||
color magenta "\<(split|sprintf|strtonum|sub|substr|tolower|toupper)\>"
|
||||
color magenta "\<(mktime|strftime|systime)\>"
|
||||
color magenta "\<(and|compl|lshift|or|rshift|xor)\>"
|
||||
color magenta "\<(bindtextdomain|dcgettext|dcngettext)\>"
|
||||
|
||||
# Strings.
|
||||
color brightyellow ""([^"\]|\\.)*""
|
||||
# Escape sequences.
|
||||
color brick "\\([abfnrtv\/"]|[0-7]{1,3}|x[[:xdigit:]]{1,2}|u[[:xdigit:]]{1,8})"
|
||||
# Comments.
|
||||
color brightblue "(^|[[:blank:]])#.*"
|
||||
|
||||
# Trailing whitespace.
|
||||
color ,green "[[:space:]]+$"
|
46
syntax/c.nanofurrc
Normal file
46
syntax/c.nanofurrc
Normal file
|
@ -0,0 +1,46 @@
|
|||
## Syntax highlighting for C and C++ files.
|
||||
|
||||
syntax c "\.([ch](pp|xx)?|C|cc|c\+\+|cu|H|hh|ii?)$"
|
||||
header "-\*-.*\<C(\+\+)?((;|[[:blank:]]).*)?-\*-"
|
||||
magic "^(C|C\+\+) (source|program)"
|
||||
comment "//"
|
||||
|
||||
# Constants.
|
||||
color brightred "\<[A-Z_][0-9A-Z_]*\>"
|
||||
# Labels.
|
||||
color brightmagenta "^[[:blank:]]*[A-Z_a-z][0-9A-Z_a-z]*:[[:blank:]]*$"
|
||||
color normal ":[[:blank:]]*$"
|
||||
|
||||
# Types and related keywords.
|
||||
color green "\<(auto|bool|char|const|double|enum|extern|float|inline|int|long|restrict|short|signed|sizeof|static|struct|typedef|union|unsigned|void)\>"
|
||||
color green "\<([[:lower:]][[:lower:]_]*|(u_?)?int(8|16|32|64))_t\>"
|
||||
color green "\<(_(Alignas|Alignof|Atomic|Bool|Complex|Generic|Imaginary|Noreturn|Static_assert|Thread_local))\>"
|
||||
color green "\<(class|explicit|friend|mutable|namespace|override|private|protected|public|register|template|this|typename|using|virtual|volatile)\>"
|
||||
|
||||
# Flow control.
|
||||
color brightyellow "\<(if|else|for|while|do|switch|case|default)\>"
|
||||
color brightyellow "\<(try|throw|catch|operator|new|delete)\>"
|
||||
color magenta "\<(break|continue|goto|return)\>"
|
||||
|
||||
# Single-quoted stuff (characters, backslash escapes, hex and octal byte codes).
|
||||
color brightmagenta "'([^'\]|\\(["'\abfnrtv]|x[[:xdigit:]]{1,2}|[0-3]?[0-7]{1,2}))'"
|
||||
|
||||
# GCC builtins.
|
||||
color cyan "__attribute__[[:blank:]]*\(\([^)]*\)\)|__(aligned|asm|builtin|hidden|inline|packed|restrict|section|typeof|weak)__"
|
||||
|
||||
# Strings and names of included files.
|
||||
color brightyellow ""([^"]|\\")*"|#[[:blank:]]*include[[:blank:]]*<[^>]+>"
|
||||
|
||||
# Preprocessor directives.
|
||||
color brightcyan start="^[[:blank:]]*#[[:blank:]]*(if(n?def)?|elif|warning|error|pragma)\>" end="(\`|[^\])$"
|
||||
color brightcyan "^[[:blank:]]*#[[:blank:]]*((define|else|endif|include(_next)?|line|undef)\>|$)"
|
||||
|
||||
# Comments.
|
||||
color brightblue "//[^"]*$|(^|[[:blank:]])//.*"
|
||||
color brightblue start="/\*" end="\*/"
|
||||
|
||||
# Reminders.
|
||||
color brightwhite,yellow "\<(FIXME|TODO|XXX)\>"
|
||||
|
||||
# Trailing whitespace.
|
||||
color ,green "[[:space:]]+$"
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue