pax_global_header00006660000000000000000000000064145354761710014527gustar00rootroot0000000000000052 comment=31355e644f30a912f4f8bed8d33686f8276ae673 urlview-ng-1c/000077500000000000000000000000001453547617100134735ustar00rootroot00000000000000urlview-ng-1c/.builds/000077500000000000000000000000001453547617100150335ustar00rootroot00000000000000urlview-ng-1c/.builds/freebsd-latest.yml000066400000000000000000000004531453547617100204640ustar00rootroot00000000000000# SPDX-License-Identifier: 0BSD image: freebsd/latest packages: - gmake - gettext-runtime - gettext-tools tasks: - build: | LDFLAGS=-L/usr/local/lib LDLIBS=-lintl CPPFLAGS=-I/usr/local/include gmake -C urlview-ng CXX=c++ all check - install: | sudo gmake -C urlview-ng install urlview-ng-1c/.builds/openbsd-latest.yml000066400000000000000000000003001453547617100204730ustar00rootroot00000000000000# SPDX-License-Identifier: 0BSD image: openbsd/latest packages: - gmake tasks: - build: | gmake -C urlview-ng CXX=c++ all check - install: | doas gmake -C urlview-ng install urlview-ng-1c/.builds/sid+void.yml000066400000000000000000000017371453547617100173020ustar00rootroot00000000000000# SPDX-License-Identifier: 0BSD image: debian/sid packages: - clang - lld - libncurses-dev - shellcheck - gettext tasks: - build-gcc: | make -C urlview-ng all check make -C urlview-ng clean - build-clang: | export CC=clang CXX=clang++ LDFLAGS=-fuse-ld=lld make -C urlview-ng all check - install: | sudo gmake -C urlview-ng install - void: | curl https://repo-default.voidlinux.org/live/current/sha256sum.txt | grep -w tar | grep -w x86_64 | grep -m1 musl > sha256sum.txt curl -SL https://repo-default.voidlinux.org/live/current/"$(awk -F'[( )]' '{print $3}' < sha256sum.txt)" | tar -xJ cp /etc/resolv.conf etc printf '%s\n' 'xbps-install -yS' \ 'xbps-install -yu xbps' \ 'xbps-install -y make gcc ncurses ncurses-devel' \ 'make -C urlview-ng clean' \ 'make -C urlview-ng VERSION=sid.yml SOURCE_DATE_EPOCH=0' | unshare -rR . sh -ex urlview-ng-1c/.clang-format000066400000000000000000000020771453547617100160540ustar00rootroot00000000000000--- Language : Cpp BasedOnStyle : LLVM AlignAfterOpenBracket : true AlignEscapedNewlinesLeft : true AlignConsecutiveAssignments : true AllowShortFunctionsOnASingleLine : Inline AlwaysBreakTemplateDeclarations : true ColumnLimit : 160 ConstructorInitializerIndentWidth : 6 IndentCaseLabels : true MaxEmptyLinesToKeep : 2 KeepEmptyLinesAtTheStartOfBlocks : false NamespaceIndentation : All PointerAlignment : Middle SpacesBeforeTrailingComments : 2 IndentWidth : 2 TabWidth : 2 UseTab : ForIndentation SpaceBeforeParens : Never FixNamespaceComments : false ... urlview-ng-1c/.gitignore000066400000000000000000000000511453547617100154570ustar00rootroot00000000000000urlview *.o urlview.1 sample.urlview loc urlview-ng-1c/LICENSES/000077500000000000000000000000001453547617100147005ustar00rootroot00000000000000urlview-ng-1c/LICENSES/0BSD.txt000066400000000000000000000011371453547617100161330ustar00rootroot00000000000000Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. urlview-ng-1c/LICENSES/GPL-2.0-or-later.txt000066400000000000000000000431051453547617100201060ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. urlview-ng-1c/Makefile000066400000000000000000000074311453547617100151400ustar00rootroot00000000000000# SPDX-License-Identifier: 0BSD # gcc -DPACKAGE=\"urlview\" -DVERSION=\"0.9\" -DHAVE_CURS_SET=1 -DHAVE_NCURSES_H=1 -DHAVE_SNPRINTF=1 -DHAVE_REGEX_H=1 -DHAVE_STDARG_H=1 -I. -I. -g -O2 -DURLVIEW -Dunix -c urlview.c # gcc -g -O2 -DURLVIEW -Dunix -o urlview urlview.o enter.o dokey.o quote.o -lncurses CC ?= cc CXX ?= c++ LOCALLOC ?= SHELLCHECK ?= $(shell command -v shellcheck 2>/dev/null || echo @#) NOLOCREGEN ?= CURSESCONF ?= ncursesw6-config # can be "pkgconf ncursesw" too VERSION ?= $(shell git describe) DATE_EPOCH = date $(shell date --date @0 > /dev/null 2>&1 && echo "--date @" || echo "-r ") SOURCE_DATE_EPOCH ?= $(shell git log -1 --no-show-signature --format=%at "urlview.1.in") MANUAL_DATE ?= $(shell $(DATE_EPOCH)$(SOURCE_DATE_EPOCH) +"%B %e, %Y") PREFIX ?= /usr/local DEFAULT_COMMAND ?= url_handler.sh# Debian uses: /etc/urlview/url_handler.sh SYSTEM_INITFILE ?= /etc/urlview.conf# Debian uses: /etc/urlview/system.urlview DEFAULT_REGEXP ?= ((http|https|ftp|gopher|gemini|mailto):(//)?[^ <>"\t]*|(www|ftp)[0-9]?\.[-a-z0-9.]+)[^ .,;\t\n\r<">\):]?[^, <>"\t]*[^ .,;\t\n\r<">\):] export DEFAULT_COMMAND export SYSTEM_INITFILE export DEFAULT_REGEXP ADD_L := $(shell $(CURSESCONF) --cflags 2>/dev/null) -O3 -g -Wall -Wextra CPPFLAGS += -DNCURSES_WIDECHAR -D_GNU_SOURCE CFLAGS += $(ADD_L) CXXFLAGS += $(ADD_L) -fno-exceptions -fno-rtti -std=c++2b # c++23 isn't understood by everyone LDLIBS += $(shell $(CURSESCONF) --libs 2>/dev/null || echo -lncursesw) CPPFLAGS += -DVERSION='"$(VERSION)"' -DDEFAULT_COMMAND='"$(DEFAULT_COMMAND)"' -DSYSTEM_INITFILE='"$(SYSTEM_INITFILE)"' -DDEFAULT_REGEXP='"$(shell printf '%s\n' '$(subst ','\'',$(DEFAULT_REGEXP))' | sed -e 's/\\\([^nrtf]\)/\\\\\1/g' -e 's/"/\\"/g' -e "s/'/'\\\\''/g")"' -DTEXTDOMAIN_DIRNAME='"$(if $(LOCALLOC),loc,$(PREFIX)/share/locale)"' # syntax highlighter fix: )' ifneq (,$(shell command -v msgfmt)) LOCALES := $(wildcard *.po) endif .PHONY: all check clean install all: urlview urlview.1 sample.urlview $(patsubst %.po,loc/%/LC_MESSAGES/urlview-ng.mo,$(LOCALES)) check: $(SHELLCHECK) url_handler.sh clean: rm -rf *.o urlview urlview.1 sample.urlview loc loc/urlview-ng.pot: urlview.c url_handler.sh @mkdir -p $(@D) $(NOLOCREGEN)xgettext --from-code=UTF-8 -c -io- $^ | sed -n '/^#[:.]/,$$p' > $@ $(NOLOCREGEN)$(foreach l,$(LOCALES),msgmerge --backup=off --no-wrap -Uiq $(l) $@ &&) : @>> loc/urlview-ng.pot loc/%/LC_MESSAGES/urlview-ng.mo : %.po loc/urlview-ng.pot @mkdir -p $(@D) msgfmt --statistics --check-format --check-domain -o $@ $< ifneq (,$(findstring /,$(DEFAULT_COMMAND))) DEFAULT_COMMAND_DEST := $(DESTDIR)$(DEFAULT_COMMAND) else DEFAULT_COMMAND_DEST := $(DESTDIR)$(PREFIX)/bin/$(DEFAULT_COMMAND) endif install: all mkdir -p $(DESTDIR)$(PREFIX)/bin $(dir $(DEFAULT_COMMAND_DEST) $(DESTDIR)$(SYSTEM_INITFILE)) $(DESTDIR)$(PREFIX)/share/man/man1 $(DESTDIR)$(PREFIX)/share/locale cp urlview $(DESTDIR)$(PREFIX)/bin cp url_handler.sh $(DEFAULT_COMMAND_DEST) [ -e "$(DESTDIR)$(SYSTEM_INITFILE)" ] || cp sample.urlview $(DESTDIR)$(SYSTEM_INITFILE) cp urlview.1 $(DESTDIR)$(PREFIX)/share/man/man1 ifneq (,$(LOCALES)) cp -r $(patsubst %.po,loc/%,$(LOCALES)) $(DESTDIR)$(PREFIX)/share/locale endif %: %.in awk '{gsub(/@DEFAULT_COMMAND@/, ENVIRON["DEFAULT_COMMAND"]); gsub(/@SYSTEM_INITFILE@/, ENVIRON["SYSTEM_INITFILE"]); if(/@DEFAULT_REGEXP@/) { gsub(/@DEFAULT_REGEXP@/, ENVIRON["DEFAULT_REGEXP"]); $(DEFAULT_REGEXP_SPECIAL); } $(AWKADD) print}' < $< > $@ urlview.1: DEFAULT_REGEXP_SPECIAL=gsub(/\\/, "\\\\") urlview.1: AWKADD=gsub(/ \^/, " \\(ha"); gsub(/ ~/, " \\(ti"); if($$1 == ".Dd") $$2 = "$(MANUAL_DATE)"; if($$1 == ".Dt") print ".ds doc-volume-operating-system"; if($$1 == ".Os") $$2 = "urlview-ng $(VERSION)"; urlview: urlview.o enter.o enter.o dokey.o quote.o urlview.o dokey.o enter.o: enter.h urlview.o quote.o: quote.h urlview-ng-1c/README000066400000000000000000000063651453547617100143650ustar00rootroot00000000000000urlview-ng https://builds.sr.ht/~nabijaczleweli/urlview-ng https://todo.sr.ht/~nabijaczleweli/urlview-ng (report at ) https://lists.sr.ht/~nabijaczleweli/urlview-ng A new urlview upstream, originally derived from snapshot.d.o (0.7, 0.9), with imported patches from 0.9-24. [2023-09-26T23:39:46+02:00] Originally this had been part of the mutt contrib subdistribution, but hasn't been since at least 0.9-22 (16 Sep 2021). The date in the 0.9 .orig is 2000-07-04, so all it got is a (precisely! -24 is "Orphaning urlview") release a year in Debian. This, then, is roughly "modernised". Explicit pain points include(d): ☑ Whatever bullshit autohell from 23 years ago that meant it refused to build if CC=clang, for example, was replaced with a 20-line Makefile. ☑ 30 years of whitespace damage of all sorts is also removed. ☑ All bug-based Debian bugs up to 2023-09-26 are fixed. https://bugs.debian.org/988055 — 5cedddc172d83c26f2bc536b1da7ce1425ddb0a9 https://bugs.debian.org/690405 – https://todo.sr.ht/~nabijaczleweli/urlview-ng/2 https://bugs.debian.org/127090 – f2c66d1512815a5402938705e3e36cfb8e952333 https://bugs.debian.org/631481 – the 0.9 manual is underspecified and doesn't actually say what "URL wrapping" is, WRAP actually controls scrolling wraparound; to that end: 39cc25ebf28f9db96f9a2dda706b81ff5f80701a to the end of "long URLs are truncated except the last": 77f7d9e63e76fb456eec7cdd4133cb421092d093 https://bugs.debian.org/983417 – norepro, but it's likely actually the same bug as above https://bugs.debian.org/161620 – 1dd57b5e10b469c600badc2a2a63ed52f443a04b https://bugs.debian.org/985259 – e8f8027bf036cb8bc89af784c896c5298d9ced00 0f8006ecb9d189a8561395302d6c1b09453deb2c ☑ The manual corresponds to the behaviour. ☑ What's up with the god damn {url_handler.sh,urlview.conf}.suse files? Not much. They were just included verbatim from the SUSE submitters instead of synthesised into the distribution. Partially synthesised in https://git.sr.ht/~nabijaczleweli/urlview-ng/commit/2f9e2c978213c39d23310e70cea01f3269f267b7 and axed in https://git.sr.ht/~nabijaczleweli/urlview-ng/commit/a56e10e8c3d53a678c5f85e3751b8c6ff76105c3 ☑ The config paths are configurable instead of "patch this"able: set DEFAULT_COMMAND and SYSTEM_INITFILE for the makefile [2023-09-27T07:02:00+02:00] ☑ The regex should be as well: set DEFAULT_REGEXP [2023-09-28T00:42:01+02:00] Or, rather than "modernised", maybe it's largely rewritten in-situ. [2023-09-29T01:47:37+02:00] Release tarballs are signed with nabijaczleweli@nabijaczleweli.xyz (pull with WKD, but 7D69 474E 8402 8C5C C0C4 4163 BCFD 0B01 8D26 58F1). аnd stored in git notes, a formerly-undocumented shart feature: https://101010.pl/@nabijaczleweli/111145439026891724 as-if via the example program provided at https://man.sr.ht/git.sr.ht/#signing-tagsx27-tarballs and are thus available on the refs listing/tag page as .tar.gz.asc. urlview-ng-1c/dokey.c000066400000000000000000000040221453547617100147500ustar00rootroot00000000000000// SPDX-License-Identifier: GPL-2.0-or-later // Copyright (C) 1997 Michael R. Elkins #include #include #include #include "enter.h" static cc_t Kill = CKILL; static cc_t Werase = CWERASE; static cc_t Erase = CERASE; static cc_t Eol = CEOL; static cc_t Eol2 = #ifdef CEOL2 CEOL2; #else _POSIX_VDISABLE; #endif void km_dokey_load_termios(void) { struct termios termios; if(!tcgetattr(0, &termios)) { Kill = termios.c_cc[VKILL]; Werase = termios.c_cc[VWERASE]; Erase = termios.c_cc[VERASE]; } } int km_dokey(wint_t * LastKey) { switch(get_wch(LastKey)) { case ERR: default: return -1; case OK: switch(*LastKey) { case L'\r': case L'\n': return OP_EDITOR_DONE; case CTRL(L'B'): return OP_EDITOR_BACKWARD_CHAR; case CTRL(L'F'): return OP_EDITOR_FORWARD_CHAR; case CTRL(L'H'): return OP_EDITOR_BACKSPACE; case CTRL(L'D'): return OP_EDITOR_DELETE_CHAR; case CTRL(L'A'): return OP_EDITOR_BOL; case CTRL(L'E'): return OP_EDITOR_EOL; case KEY_DL: return OP_EDITOR_KILL_LINE; case CTRL(L'I'): return OP_EDITOR_KILL_EOL; case CTRL(L'G'): return -1; } #define MAP(stty, op) \ if(*LastKey == stty && *LastKey != _POSIX_VDISABLE) \ return op MAP(Kill, OP_EDITOR_KILL_LINE); MAP(Werase, OP_EDITOR_KILL_WORD); MAP(Erase, OP_EDITOR_DELETE_CHAR); MAP(Eol, OP_EDITOR_DONE); MAP(Eol2, OP_EDITOR_DONE); return OP_EDITOR_CHAR; case KEY_CODE_YES: switch(*LastKey) { case KEY_LEFT: return OP_EDITOR_BACKWARD_CHAR; case KEY_RIGHT: return OP_EDITOR_FORWARD_CHAR; case KEY_BACKSPACE: return OP_EDITOR_BACKSPACE; case KEY_DC: return OP_EDITOR_DELETE_CHAR; case KEY_HOME: return OP_EDITOR_BOL; case KEY_END: return OP_EDITOR_EOL; case KEY_DL: return OP_EDITOR_KILL_LINE; case KEY_RESIZE: return OP_EDITOR_RESIZE; default: return OP_EDITOR_IDK; } } } urlview-ng-1c/enter.cpp000066400000000000000000000176111453547617100153220ustar00rootroot00000000000000// SPDX-License-Identifier: 0BSD extern "C" { #include "enter.h" } #include #include #include #include #include #include #include #include #include struct character { wchar_t c; char seg[MB_LEN_MAX]; unsigned seglen : std::bit_width(static_cast(MB_LEN_MAX)); unsigned width : 2; bool space : 1; bool word : 1; }; static_assert(MB_LEN_MAX <= ((1 << std::bit_width(static_cast(MB_LEN_MAX))) - 1)); extern "C" struct enter_string enter_string(const char * init, size_t initlen) { int y, x; getyx(stdscr, y, x); km_dokey_load_termios(); #define MEASURE(character) \ mvaddnwstr(y, x, &character.c, 1); \ character.width = getcurx(stdscr) - x; \ character.space = iswspace(character.c); \ character.word = iswalnum(character.c) struct character * characters{}; size_t characters_len{}, characters_cap{}; #define BUMPCHAR() \ do { \ if(characters_len == characters_cap) { \ characters_cap = characters_cap ? characters_cap * 2 : 16; \ if(!(characters = reinterpret_cast(reallocarray(characters, characters_cap, sizeof(*characters))))) \ return {}; \ } \ } while(false) while(initlen) { if(!characters) { characters_cap = initlen; if(!(characters = reinterpret_cast(reallocarray(characters, characters_cap, sizeof(*characters))))) return {}; } struct character character = {}; mbstate_t state = {}; switch(auto r = mbrtowc(&character.c, init, initlen, &state)) { case(size_t)-2: // too short state = {}; character.c = -1; r = std::min(initlen, (size_t)((1 << 5) - 1)); goto dfl; case(size_t)-1: // EILSEQ state = {}; character.c = -1; [[fallthrough]]; case 0: r = 1; [[fallthrough]]; default: dfl: character.seglen = r; memcpy(character.seg, init, r); initlen -= r; init += r; } MEASURE(character); BUMPCHAR(); characters[characters_len++] = character; } size_t characters_cursor = characters_len; #define LEFTBY(howmuch) \ do { \ int moveleft = howmuch; \ while(first_on_screen && moveleft > 0) \ moveleft -= characters[--first_on_screen].width; \ } while(false) #define RIGHTBY(howmuch) \ do { \ int moveright = howmuch; \ while(first_on_screen != characters_len && moveright > 0) \ moveright -= characters[++first_on_screen].width; \ } while(false) // Write out from first_on_screen, so long as the cursor fits on the screen, else move by a half-screen to find it. // Start off with as much text as possible and cursor on the right margin; you can't return to this state; this mimicks how ≤1b did it size_t first_on_screen = characters_cursor; LEFTBY((getmaxx(stdscr) - x) - 1); for(wint_t input;;) { { auto screen_width = getmaxx(stdscr) - x; auto all_characters_width = std::accumulate(characters, characters + characters_len, 0z, [](auto acc, auto && c) { return acc + c.width; }); if(all_characters_width < screen_width) first_on_screen = 0; else { if(first_on_screen >= characters_len) { first_on_screen = characters_cursor - 1; LEFTBY(screen_width / 2); } else if(characters_cursor < first_on_screen) while(characters_cursor < first_on_screen) LEFTBY(screen_width / 2); else for(;;) { auto last = std::find_if(characters + first_on_screen, characters + characters_len, [&, acc = 0z](auto && c) mutable { acc += c.width; return acc > screen_width; }); auto characters_on_screen = last - (characters + first_on_screen); if(first_on_screen + characters_on_screen < characters_cursor) RIGHTBY(screen_width / 2); else break; } } move(y, x); auto cursor_x = x; for(auto itr = characters + first_on_screen; itr != characters + characters_len; ++itr) { if(itr->width <= screen_width) screen_width -= itr->width; else break; addnwstr(&itr->c, 1); if(itr < characters + characters_cursor) cursor_x += itr->width; } clrtoeol(); move(y, cursor_x); } switch(km_dokey(&input)) { case -1: return free(characters), (struct enter_string){}; case OP_EDITOR_CHAR: if(iswprint(input)) { struct character character = {}; character.c = input; int newlen = wctomb(character.seg, input); if(newlen == -1) goto err; character.seglen = newlen; MEASURE(character); BUMPCHAR(); memmove(characters + characters_cursor + 1, characters + characters_cursor, (characters_len - characters_cursor) * sizeof(*characters)); ++characters_len; characters[characters_cursor++] = character; } else { err: flushinp(); beep(); } break; case OP_EDITOR_DONE: { struct enter_string ret = {0, std::accumulate(characters, characters + characters_len, 0zu, [](auto acc, auto && c) { return acc + c.seglen; })}; if(!ret.len) return free(characters), (struct enter_string){}; ret.data = reinterpret_cast(malloc(ret.len + 1)); if(!ret.data) return free(characters), (struct enter_string){}; auto acc = ret.data; for(auto itr = characters; itr != characters + characters_len; ++itr) acc = reinterpret_cast(memcpy(acc, itr->seg, itr->seglen)) + itr->seglen; *acc = '\0'; return free(characters), ret; } break; case OP_EDITOR_RESIZE: break; case OP_EDITOR_IDK: beep(); break; case OP_EDITOR_BACKSPACE: if(!characters_cursor) beep(); else { memmove(characters + characters_cursor - 1, characters + characters_cursor, (characters_len - characters_cursor) * sizeof(*characters)); --characters_len; --characters_cursor; } break; case OP_EDITOR_DELETE_CHAR: if(characters_cursor == characters_len) beep(); else { memmove(characters + characters_cursor, characters + characters_cursor + 1, (characters_len - (characters_cursor + 1)) * sizeof(*characters)); --characters_len; } break; case OP_EDITOR_KILL_LINE: characters_len = characters_cursor = 0; break; case OP_EDITOR_KILL_EOL: characters_len = characters_cursor; break; case OP_EDITOR_KILL_WORD: { if(!characters_cursor) break; auto end = characters_cursor; --characters_cursor; while(characters_cursor && characters[characters_cursor - 1].space) --characters_cursor; while(characters_cursor && characters[characters_cursor - 1].word) --characters_cursor; memmove(characters + characters_cursor, characters + end, (characters_len - end) * sizeof(*characters)); characters_len -= end - characters_cursor; } break; case OP_EDITOR_BOL: characters_cursor = 0; break; case OP_EDITOR_EOL: characters_cursor = characters_len; break; case OP_EDITOR_BACKWARD_CHAR: if(!characters_cursor) beep(); else --characters_cursor; break; case OP_EDITOR_FORWARD_CHAR: if(characters_cursor == characters_len) beep(); else ++characters_cursor; break; } } } urlview-ng-1c/enter.h000066400000000000000000000011441453547617100147610ustar00rootroot00000000000000// SPDX-License-Identifier: GPL-2.0-or-later // Copyright (C) 1997 Michael R. Elkins #include enum { OP_EDITOR_CHAR, OP_EDITOR_DONE, OP_EDITOR_RESIZE, OP_EDITOR_IDK, OP_EDITOR_BACKSPACE, OP_EDITOR_DELETE_CHAR, OP_EDITOR_KILL_LINE, OP_EDITOR_KILL_EOL, OP_EDITOR_KILL_WORD, OP_EDITOR_BOL, OP_EDITOR_EOL, OP_EDITOR_BACKWARD_CHAR, OP_EDITOR_FORWARD_CHAR, }; struct enter_string { char * data; size_t len; }; extern struct enter_string enter_string(const char * init, size_t initlen); extern void km_dokey_load_termios(void); extern int km_dokey(wint_t * LastKey); urlview-ng-1c/fr.po000066400000000000000000000073601453547617100144500ustar00rootroot00000000000000# SPDX-License-Identifier: 0BSD msgid "" msgstr "Language: fr\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" #. as in "no search results", p.a. to "No such URL!"; potentially displayed after "Search [forwards/backwards] for:" #: urlview.c:86 msgid "No matches!" msgstr "Aucune correspondance !" #. "BROWSER", user's input, "yes, no" #. "VIA", user's input, "argument, environment, pipe" #: urlview.c:225 urlview.c:278 #, c-format msgid "Unknown value for %s: %s. Valid values are: %s." msgstr "Valeur inconnue pour %s : %s. Valeurs acceptables : %s." #. leave yes/no intact, but add explanations #: urlview.c:225 msgid "yes, no" msgstr "\"yes\" (oui), \"no\" (non)" #. leave argument/environment/pipe intact, but add explanations #: urlview.c:279 msgid "argument, environment, pipe" msgstr "\"argument\", \"environment\" (environnement), \"pipe\" (tube)" #. #: urlview.c:286 #, c-format msgid "Unknown setting: %s" msgstr "Paramètre inconnu : %s" #: urlview.c:303 #, c-format msgid "Empty $BROWSER, falling back to COMMAND (%s)." msgstr "$BROWSER vide, utilisation de COMMAND (%s) en rechange." #: urlview.c:310 msgid "\n" "Your COMMAND/$BROWSER contains a single quote (') character.\n" "This is most likely in error; please read the manual page for details.\n" "If you really want to use this command, please put the word EXPERT\n" "into a line of its own in your ~/.urlview file." msgstr "\n" "Votre COMMAND/$BROWSER contient une apostrophe (').\n" "C'est sans doute une erreur, consultez le manuel pour plus de détails.\n" "Si vous voulez vraiment utiliser cette commande, mettez le mot\n" "\"EXPERT\" seul sur une ligne dans votre fichier ~/.urlview." #: urlview.c:378 #, c-format msgid "couldn't allocate memory for additional URLs, only first %zu displayed" msgstr "pas assez de mémoire pour d'autres URLs, affichage des %zu premières" #: urlview.c:416 msgid "No URLs found." msgstr "Aucune URL trouvée." #: urlview.c:471 urlview.c:501 #, c-format msgid "%zu URL" msgid_plural "%zu URLs" msgstr[0] "%zu URL" msgstr[1] "%zu URLs" #: urlview.c:490 urlview.c:497 #, c-format msgid "Press q or %.*s to quit!" msgstr "Appuyez sur q ou %.*s pour quitter !" #: urlview.c:492 urlview.c:499 msgid "Press q to quit!" msgstr "Appuyez sur q pour quitter !" #: urlview.c:665 msgid "URL: " msgstr "URL : " #: urlview.c:720 urlview.c:721 #, c-format msgid "Executing: %s... " msgstr "Exécution : %s… " #. child exit code or human-readable signal name, written after "Executing: %s... " #: urlview.c:740 #, c-format msgid "%s! " msgstr "%s ! " #: urlview.c:741 #, c-format msgid "%s!\n" msgstr "%s !\n" #. edit prompt #: urlview.c:771 msgid "Jump to URL: " msgstr "Aller à l'URL : " #. error from the above #: urlview.c:779 msgid "No such URL!" msgstr "Cette URL n'existe pas !" #. edit prompt #: urlview.c:806 msgid "Search forwards for: " msgstr "Chercher (en avant) : " #. edit prompt #: urlview.c:806 msgid "Search backwards for: " msgstr "Chercher (en arrière) : " #: url_handler.sh:87 msgid "Is \"%s\" a file? " msgstr "Est-ce que \"%s\" est un fichier ?" #. "viewer" as-in something that can open and potentially show the URL #: url_handler.sh:118 msgid "Unknown URL protocol \"%s\".\n" "Please report URL and viewer to <~nabijaczleweli/urlview-ng@lists.sr.ht>.\n" "Press enter to continue... " msgstr "Protocole d'URL \"%s\" inconnu.\n" "Veuillez signaler l'URL et son programme associé à <~nabijaczleweli/urlview-ng@lists.sr.ht>.\n" "Appuyez sur entrée pour continuer.… " urlview-ng-1c/pl.po000066400000000000000000000072741453547617100144600ustar00rootroot00000000000000# SPDX-License-Identifier: 0BSD msgid "" msgstr "Language: pl\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" #. as in "no search results", p.a. to "No such URL!"; potentially displayed after "Search [forwards/backwards] for:" #: urlview.c:86 msgid "No matches!" msgstr "Brak wyników!" #. "BROWSER", user's input, "yes, no" #. "VIA", user's input, "argument, environment, pipe" #: urlview.c:225 urlview.c:278 #, c-format msgid "Unknown value for %s: %s. Valid values are: %s." msgstr "Nieznana wartość %s: %s. Poprawne wartości to %s." #. leave yes/no intact, but add explanations #: urlview.c:225 msgid "yes, no" msgstr "\"yes\" (tak) i \"no\" (nie)" #. leave argument/environment/pipe intact, but add explanations #: urlview.c:279 msgid "argument, environment, pipe" msgstr "\"argument\", \"environment\" (środowisko), lub \"pipe\" (potok)" #. #: urlview.c:286 #, c-format msgid "Unknown setting: %s" msgstr "Nieznane ustawienie: %s" #: urlview.c:303 #, c-format msgid "Empty $BROWSER, falling back to COMMAND (%s)." msgstr "$BROWSER puste, używam COMMAND (%s)." #: urlview.c:310 msgid "\n" "Your COMMAND/$BROWSER contains a single quote (') character.\n" "This is most likely in error; please read the manual page for details.\n" "If you really want to use this command, please put the word EXPERT\n" "into a line of its own in your ~/.urlview file." msgstr "\n" "Twoje COMMAND lub $BROWSER zawiera znak '.\n" "Jest to najprawdopodibniej błąd (por. urlview(1)).\n" "Jeżeli na pewno chcesz użyć tego polecenia,\n" "dodaj \"EXPERT\" do swojego ~/.urlview." #: urlview.c:378 #, c-format msgid "couldn't allocate memory for additional URLs, only first %zu displayed" msgstr "nie udało się zaalokowac pamięci dla dodatkowych URLi, pokazuję pierwsze %zu" #: urlview.c:416 msgid "No URLs found." msgstr "Nie znaleziono żadnych URLi." #: urlview.c:471 urlview.c:501 #, c-format msgid "%zu URL" msgid_plural "%zu URLs" msgstr[0] "%zu URL" msgstr[1] "%zu URLe" msgstr[2] "%zu URLi" #: urlview.c:490 urlview.c:497 #, c-format msgid "Press q or %.*s to quit!" msgstr "Wyjście: q lub %.*s" #: urlview.c:492 urlview.c:499 msgid "Press q to quit!" msgstr "Wyjście: q" #: urlview.c:665 msgid "URL: " msgstr "URL: " #: urlview.c:720 urlview.c:721 #, c-format msgid "Executing: %s... " msgstr "Wykonuję %s… " #. child exit code or human-readable signal name, written after "Executing: %s... " #: urlview.c:740 #, c-format msgid "%s! " msgstr "%s! " #: urlview.c:741 #, c-format msgid "%s!\n" msgstr "%s !\n" #. edit prompt #: urlview.c:771 msgid "Jump to URL: " msgstr "Przejdź do URLa: " #. error from the above #: urlview.c:779 msgid "No such URL!" msgstr "Nie ma takiego!" #. edit prompt #: urlview.c:806 msgid "Search forwards for: " msgstr "Szukanie do przodu: " #. edit prompt #: urlview.c:806 msgid "Search backwards for: " msgstr "Szukanie do tyłu: " #: url_handler.sh:87 msgid "Is \"%s\" a file? " msgstr "Czy \"%s\" jest plikiem? " #. "viewer" as-in something that can open and potentially show the URL #: url_handler.sh:118 msgid "Unknown URL protocol \"%s\".\n" "Please report URL and viewer to <~nabijaczleweli/urlview-ng@lists.sr.ht>.\n" "Press enter to continue... " msgstr "Nieznany protokół \"%s\".\n" "Proszę zgłosić URL i odpowiednią mu przeglądarkę na adres <~nabijaczleweli/urlview-ng@lists.sr.ht>.\n" "⏎ żeby przejść dalej… " urlview-ng-1c/quote.cpp000066400000000000000000000030331453547617100153330ustar00rootroot00000000000000// SPDX-License-Identifier: 0BSD #include #include #include extern "C" { #include "quote.h" } static char * quote(const char * beg, const char * end, char * cur) { *cur++ = '\''; for(; beg != end; ++beg) if(*beg == '\'') { *cur++ = '\''; *cur++ = '\\'; *cur++ = '\''; *cur++ = '\''; } else *cur++ = *beg; *cur++ = '\''; return cur; } /* Turn "abc %s def %s", "qwe'rt" into "abc 'qwe'\''rt' def %s" * or "ghi", "qwe'rt" into "ghi 'qwe'\''rt'" */ extern "C" char * quotesub(const char * execline, size_t execlinelen, const char * url, size_t urllen) { assert(execline); assert(url); auto pct_s = static_cast(memmem(execline, execlinelen, "%s", 2)); // %s SPC ' ' NUL auto space = execlinelen + (pct_s ? -2 : 1) + 1 + urllen + (std::count(url, url + urllen, '\'') * 3) + 1 + 1; auto ret = reinterpret_cast(std::malloc(space)), cur = ret; if(pct_s) { cur = std::copy(execline, pct_s, cur); cur = quote(url, url + urllen, cur); cur = std::copy(pct_s + 2, execline + execlinelen, cur); } else { cur = std::copy(execline, execline + execlinelen, cur); *cur++ = ' '; cur = quote(url, url + urllen, cur); } *cur++ = '\0'; return ret; } // #include // int main() { // std::puts(quotesub("abc %s def %s", strlen("abc %s def %s"), "qwe'rt", strlen("qwe'rt"))); // std::puts(quotesub("ghi", strlen("ghi"), "qwe'rt", strlen("qwe'rt"))); // } urlview-ng-1c/quote.h000066400000000000000000000002001453547617100147710ustar00rootroot00000000000000// SPDX-License-Identifier: 0BSD char * quotesub(const char * execline, size_t execlinelen, const char * url, size_t urllen); urlview-ng-1c/sample.urlview.in000066400000000000000000000015101453547617100167750ustar00rootroot00000000000000# # Default urlview(1) configuration file # # You can call urlview from (neo)mutt by pressing ^B: # macro index,pager,attach,compose \cb |urlview # this is part of the default configuration. # # You can call urlview from tin by pressing |, a[rticle], then "urlview". # regular expression to use to match URLs #REGEXP @DEFAULT_REGEXP@ # program to invoke for selected URL # if this is unset, it'll be overridden by $BROWSER COMMAND @DEFAULT_COMMAND@ # argument: run sh -c 'COMMAND URL' # environment: run URL=URL sh -c 'COMMAND' # pipe: run sh -c 'COMMAND' <<Harvey Mudd College Home Page Harvey Mudd College Home Page mailto:me@cs.hmc.edu some other random text Please see the Mutt Home Page at http://www.cs.hmc.edu/~me/mutt, or its mirror site http://www.mutt.org. Sometimes we also see things like www.gnustep.org, or www.windowmaker.org/features.html all by itself with no http or ftp. www.m-w.com is a good internet dictionary. Also "strange" urls like www3.google.com are now supported. ftp://ftp.fooboo.com Ftp urls without protocol, like ftp.debian.org, are recognized. ftp.us.debian.org/debian/pool/main/u/urlview/urlview_0.9-6_i386.deb Since urlview-0.9-11 we are also able to manage correctly RFC 2368 urls (mailto URL scheme). For instance: Quotes, like in , are guarded against Following Debian#985259, gemini://geminiprotocol.net/ also works And following Debian#1017569, http://henryk.tłuściutki/достопримечательности does http://chinese.test/开花馒头好吃方法很简单,学会这个做法,蓬松柔软个个开花【海娟美食】 Debian#1035358: https://en.wikipedia.org/wiki/Close_Combat_(series) vs (https://en.wikipedia.org/wiki/Debian) vs https://en.wikipedia.org/wiki/(You_Gotta)_Fight_for_Your_Right_(To_Party!) urlview-ng-1c/text.uv000066400000000000000000000073651453547617100150460ustar00rootroot00000000000000Qq qqqqq, Qq qqqq qqqqqqqq q qqqqqqqq qqqqqqq qqq qq qqqqqqq qqqqqq qqqq qqqq qqqqq. Qq qqqqqq qqqq qqqqqqq, qqqqqq qqqqq qqq qqqqqq qqqqq: Qqqqqq Qqqqqqq ( https://qqqq.qqqq.qqqqqqq.qqq/qq/qqqqq?qqq=q0qqqq0Qq0QqQqq0QQQ-0QqqQqqqQqQQQqQQqQqQQ0Q0Qq00QQQq0Q0qQ0qqQq0qqqQqQqQqQqq0QqqQqQqQqqqQ00QQ-0Qq0-0QQQQqQQqq0qQQqqq0QqQQ00QqQqQqQ0q0QQqq0qQqq0QqqQQqqQQqq0q00qqqQ00Qqq0QQqQqq0QQ-0QqqqQQqQQqqQQqqq0qqq0qQQQqQQqQQQQQqQQQQQqqqQqQQ0qQ-0Qqq0QqQqQQQ0-0QqQ-0QQqqQ_QQQqqqq0qQQq-0Q0Q-0QQ00Qqqq0Q0q0qQqQQqQq0QQq0q0q0QqQQqQQq0QqqqQ0qqQ0qqQ0QQ0qQqQqQQQQqQ-0QQq0q0QQq-0QQQqQ0QQQqQq0Qqq0qQQ0qQQ0Qqqqq0QQqQqQQqQqqqqQqQqQQQ-0QQqqQQQQQqqQqqQq0qQ0-0QqQQqq0qQQ0q0qQQQQqQq0QQ0QQQ0Qq0qq0-0QQqQQQqQQqqqqQqqQQQQQqQQq00-0QqqQqqQQ-0QQqqqQQ0QQ0q0qQQ0Qq00Qq0qqqQQQQQQQQQQqqqqqqqQQ-0QqqqQqQ0q0q0qqQQqqQq-0QQq0QqQ0qqqQQqqQqQQ0Q-0Q0q-0QQ0qq00qqqqQ-0QQQQq0QqQqQQqqqQQ0qqqQ0qQ0q-0QqQqqqqQQqQqqqQq0Q-0QQq000qqqqQ000QqqqQq0QqQqQQqqqqqQq0-0QqQQqQqq-0QqqqqqQ-0QQQqq0QQ00QqQqQqQq0QQQQQqQq0qqQQQqQQqQqQQQqQQqqQQqqQ0qQQqQ-0QqQqqQqqqQqQQQ00qqQQQQqqqqqQQQq-0QQqQQQQqqQ0qqqQqqq0QQqqQqqqqq0Q0QqQqQQq0qQqqQqQqQ0QQQqq0qQ0QqQqQQqQqqQqQQQqqQ-0QQq-0QQqQQQq0Q0q0qQqqQQ0QqQq0QQ0qqqq0QqqQ0q0Qq0QqqQ0Q0qqQq0qQQQQQQqQq-0Q-0Q ) Qq qqq qqqq’q qqqq qqqq qqqqqqq, qqqqqq qqqqqq qqqq qqqqq. Qq qqq'qq qqqqqq qq qqqqq qqq qqqqq qqqqqq, qqqqqq qqqqq qqqq qqqq qqqq qqqq qqqqqqq: https://qqqq.qqqq.qqqqqqq.qqq/qq/qqqqq?qqq=q0qqqq0Qq0QqQqq0QQQ-0QqqQqqqQqQQQqQQqQqQQ0Q0Qq00QQQq0Q0qQ0qqQq0qqqQqQqQqQqq0QqqQqQqQqqqQ00QQ-0Qq0-0QQQQqQQqq0qQQqqq0QqQQ00QqQqQqQ0q0QQqq0qQqq0QqqQQqqQQqq0q00qqqQ00Qqq0QQqQqq0QQ-0QqqqQQqQQqqQQqqq0qqq0qQQQqQQqQQQQQqQQQQQqqqQQQqqQqqQqQQqqqQqQQQqQ-0QQqqQ_QQQqqqq0qQQq-0Q0Q-0QQ00Qqqq0Q0q0qQqQQqQq0QQq0q0q0QqQQqQQq0QqqqQ0qqQ0qqQ0QQ0qQqQqQQQQqQ-0QQq0q0QQq-0QQQqQ0QQQqQq0Qqq0qQQ0qQQ0Qqqqq0QQqQqQQqQqqqqQqQqQQQ-0QQqqQQQQQqqQqqQq0qQ0-0QqQQqq0qQQ0q0qQQQQqQq0QQ0QQQ0Qq0qq0-0QQqQQQqQQqqqqQqqQQQQQqQQq00-0QqqQqqQQ-0QQqqqQQ0QQ0q0qQQ0Qq00Qq0qqqQQQQQQQQQQqqqqqqqQQ-0QqqqQqQ0q0q0qqQQqqQq-0QQq0QqQ0qqqQQqqQqQQ0Q-0Q0q-0QQ0qq00qqqqQ-0QQQQq0QqQqQQqqqQQ0qqqQ0qQ0q-0QqQqqqqQQqQqqqQq0Q-0QQq000qqqqQ000QqqqQq0QqQqQQqqqqqQq0-0QqQQqQqq-0QqqqqqQ-0QQQqq0QQ00QqQqQqQq0QQQQQqQq0qqQQQqQQqQqQQQqQQqqQQqqQ0qQQqQ-0QqQqqQqqqQqQQQ00qqQQQQqqqqqQqQQ0qqqQ0qq0Q0QqQQ-0QqqQQQ00Qq0qQQQqqqQ-0QQqQQqqq00Q0QQq0QQQqQ0QqqQqqQQqq0qQQQ0qQqqqQQQQqQ0qqQQq-0QqQQqQQ0QQ0-0QQq0q0qqqqQqqqqQq0QQq-0Qqqqq0Q0qQqqQq0Qqq00qQq-0Q-0Q Qqqqqqq 0000 Qqqq Qq. Qqqqqqqq Q, Qqqqq Qqqqqq, QQ 00000 Qqqqqqqqqqq ( https://qqqq.qqqq.qqqqqqq.qqq/qq/qqqqq?qqq=q0qqqq0Qq0QqQqq0QQQ-0Qqq-0Q0q0Qq0q00Q0QqqQ00qQqqQqqQQQq0Q0QQ0QQqQQqQQqQQ0QqQqqqQQQ0qQQQQqqqqQqqQqQ-0QqQqQQQq0QqqqQQQqQQQQQqqqqq0QQqQQ0qqqQQqqQqQQQQ0Qq-0QQq00QQQq0qqQQq-0QQQq0q0qQQqQQ-0Qq0QqqQq-0Q0qQQQ0QQqQQqqqqQ00qQ-0QQQqqqQqqQQ-0Q0QQqQ0QQqqqQQQ0QQqqq00Qq00Q-0QQqQQq0QQ0QQq0qqQqQQqqQQ0q-0QQQqQQQQqQ-0QQqQqQqQqqQQqQq-0Q0Qq0Qqq-0QqqqQQQQ0Qq0q-0QQ0qqQqQ0QQqQqQ0Q0QQQQQ0q0qqqQqQQq0Qqq0Qqqqq0q0q0QqQqQqQQ0qQqQqqqq0qQQ00qqQQ-0QQQQqq0qQ00qQqQq0QQQQQQqQqQQQQq0QqqQQQ0qQqqQQqQQqqQQ0Qq0qQQqQQ0QqqQqQqQq0QQqQQ0-0QQQQqqqQqq-0QQq0Qq00QqqqQqq0QqQQq0qQ0qQQQQqq-0Q-0QQq-0QQqQqqqQq0q0QqQqqq0qqqq0QqQqqqQ0Qq0QqqQqQ0-0QQqQQ0QqqqqqqQQQQqqQQq0qQQQQq0QqQQQqqQQqqqQ-0Q-0Q0qqq_QQQqqqq0qQQq-0Q0Q-0QQ00Qqqq0Q0q0qQqQQqQq0QQq0q0q0QqQQqQQq0QqqqQ0qqQ0qqQ0QQ0qQqQqQQQQqQ-0QQq0q0QQq-0QQQqQ0QQQqQq0Qqq0qQQ0qQQ0Qqqqq0QQqQqQQqQqqqqQqQqQQQ-0QQqqQQQQQqqQqqQq0qQ0-0QqQQqq0qQQ0q0qQQQQqQq0QQ0QQQ0Qq0qq0-0QQqQQQqQQqqqqQqqQQQQQqQQq00-0QqqQqqQQ-0QQqqqQQ0QQ0q0qQQ0Qq00Qq0qqqQQQQQQQQQQqqqqqqqQQ-0QqqqQqQ0q0q0qqQQqqQq-0QQq0QqQ0qqqQQqqQqQQ0Q-0Q0q-0QQ0qq00qqqqQ-0QQQQq0QqQqQQqqqQQ0qqqQ0qQ0q-0QqQqqqqQQqQqqqQq0Q-0QQq000qqqqQ000QqqqQq0QqQqQQqqqqqQq0-0QqQQqQqq-0QqqqqqQ-0QQQqq0QQ00QqQqQqQq0QQQQQqQq0qqQQQqQQqQqQQQqQQqqQQqqQ0qQQqQ-0QqQqqQqqqQqQQQ00qqQQQQqqqqQQq0QQ0qQqQQqq0qqqqqqQq-0Q0q0qqqqQqqqqq0qq00qQQ0QqQq0qQqqQqqqqQQQqqQQQqqq-0Q-0Q0QqqQqqq0QqQQQQ-0QQ0QqqQQqQqQQ0Q-0QqQq0QQ-0QqQQQQQQqQqqqQQqq0QQq00Q0qQ0-0QQqQQq000qq-0Q-0Q )urlview-ng-1c/url_handler.sh000077500000000000000000000064371453547617100163430ustar00rootroot00000000000000#!/bin/sh # SPDX-License-Identifier: GPL-2.0-or-later # Copyright (c) 1998 Martin Schulze # Slightly modified by: # Luis Francisco Gonzalez # Emanuele Rocca # shellcheck disable=SC2086,SC2059 ########################################################################### # Configurable section ########################################################################### # # Any entry in the lists of programs that urlview handler will try out will # be made of program + ':' + TAG where TAG is one of # PW: X11 program intended to live on after urlview's caller exits. # XW: X11 program # XT: Launch with an xterm if possible or as VT if not # VT: Launch in the same terminal # # Entries are separated by tabs! Arguments may be given with spaces # The lists of programs to be executed are http_prgs="sensible-browser:PW sensible-browser:XT www-browser:PW www-browser:XT galeon:PW konqueror:PW firefox:PW lynx:XT w3m:XT links:XT" mailto_prgs="neomutt:VT mutt:VT elm:VT alpine:VT pine:VT thunderbird:PW mail:VT" gopher_prgs="gopher:XT lynx:XT" gemini_prgs="lagrange:XW amfora:XT" ftp_prgs="ncftp:XT lftp:XT $http_prgs" download_prgs="wget:XT curl -SOL:XT snarf:XT" file_prgs="$http_prgs $download_prgs" XTERM=/usr/bin/x-terminal-emulator ########################################################################### # Change below this at your own risk ########################################################################### command -v gettext > /dev/null || alias gettext='printf %s' getprg() { IFS=' ' for ele in $1; do tag=${ele##*:} prog=${ele%:*} if command -v "${prog%%' '*}" > /dev/null; then case "$tag" in PW) [ -n "$DISPLAY" ] && echo "PW:$prog" && return 0 ;; XW) [ -n "$DISPLAY" ] && echo "XW:$prog" && return 0 ;; XT) [ -n "$DISPLAY" ] && [ -x "$XTERM" ] && echo "XT:$XTERM -e $prog" && return 0 echo "$prog" && return 0 ;; VT) echo "$prog" && return 0 ;; esac fi done } if [ $# -ne 0 ]; then url=$1 elif ( : "${URL?}" ) 2>/dev/null; then url=$URL else IFS= read -r url fi type=${url%%:*} if [ "$url" = "$type" ]; then type=${url%%.*} case "$type" in www|web|www[1-9]) type=http ;; esac url=$type://$url fi if [ "$type" = "ftp" ]; then filename=${url##*/} if [ -n "$filename" ]; then printf "$(TEXTDOMAIN=urlview-ng gettext 'Is "%s" a file? ')" "$filename" read -r x printf '%s\n' "$x" | grep -q "$(locale yesexpr 2>/dev/null || echo '^[yY1]')" && type="!download" fi fi case "$type" in http|https) prg=$(getprg "$http_prgs") ;; ftp) prg=$(getprg "$ftp_prgs") ;; mailto) prg=$(getprg "$mailto_prgs") ;; gopher) prg=$(getprg "$gopher_prgs") ;; gemini) prg=$(getprg "$gemini_prgs") ;; file) prg=$(getprg "$file_prgs") ;; '!download') prg=$(getprg "$download_prgs") ;; *) prg= # "viewer" as-in something that can open and potentially show the URL printf "$(TEXTDOMAIN=urlview-ng gettext 'Unknown URL protocol "%s". Please report URL and viewer to <~nabijaczleweli/urlview-ng@lists.sr.ht>. Press enter to continue... ')" "$type" >&2 read -r _ ;; esac [ -z "$prg" ] && exit 127 case "${prg%%:*}" in PW) nohup ${prg#*:} "$url" 2>/dev/null 1>&2 & ;; XT) ${prg#*:} "$url" 2>/dev/null & ;; *) exec $prg "$url" ;; esac urlview-ng-1c/urlview.1.in000066400000000000000000000116001453547617100156550ustar00rootroot00000000000000.\" SPDX-License-Identifier: 0BSD .\" .Dd .Dt URLVIEW 1 .Os . .Sh NAME .Nm urlview .Nd extract URLs, launch associated program .Sh SYNOPSIS .Nm .Op Fl Ns Ar line .Oo Ar file Oc Ns … . .Sh DESCRIPTION Scans each .Ar file .Pq standard input stream if Qo Sy - Qc , the default for URLs, then shows them in a .Xr curses 3 menu. (If the standard output stream is not a teletype: writes them, one per line, thereto.) .Pp The menu allows viewing, searching, editing, and opening the URLs in the appropriate program. .br URLs are shown in order, but multiple instances of the same URL are deduplicated case-insensitively! .Pp If .Fl Ns Ar line is given, where .Ar line is a decimal integer, then the first URL at or following that line is selected automatically, instead of the first. . .Ss Bindings .Bl -tag -compact -width ".No \(da , Sy j , No Scroll down" .It \(da , Sy j , No Scroll down Select next URL. . .It \(ua , Sy k , No Scroll up Select previous URL. . .It Sy e Edit selected URL, confirm with \(CR. . .It Sy \(CR , ␣ If .Va EDIT is .Sy yes : run .Sy e . Then open selected URL with .Va COMMAND or .Pf $ Ev BROWSER . . .It Mouse button 1 Select the URL under the cursor, then .Sy \(CR . . .It Bo Sy 0 Ns - Ns Sy 9 Bc Ns Ns … Jump to numbered URL, confirm with \(CR. URLs are numbered from .Em 1 . . .It Home , Sy = Select first URL. . .It End , Sy * , G Select last URL. . .It Page Down , Sy ^F Next page. . .It Page Up , Sy ^B Previous page. . .It Sy / Enter regex to search URLs forward by; confirm with \(CR. . .It Sy ?\& Enter regex to search URLs backward by; confirm with \(CR. . .It Sy n Search URLs forward with saved search (prompt if none). . .It Sy N Search URLs backward with saved search (prompt if none). . .It Sy ^L , ^G Redraw screen. . .It Sy q , x , h Exit. .El .Pp Full .Xr mutt 1 Ns -style line editing is supported (incl.\& .Sy ^I Pq Tab to erase to end of line). During entry, .Sy ^G cancels. . .Sh ENVIRONMENT .Bl -tag -compact -width ".Ev URLVIEW_DEBUG" .It Ev BROWSER Overrides the built-in default for .Va COMMAND if not specified in .Sx Configuration , . .It Ev URLVIEW_DEBUG Behave as-if the standard output stream weren't a teletype. .El . .Sh FILES The first extant of .Pa ~/.urlview , .Pa @SYSTEM_INITFILE@ is read. In this case, the defaults may be overridden through a simple line-based .Qq Fa setting No whitespace Ar value format. Empty lines and lines starting with .So Sy # Sc Ns es are ignored. . .Ss Configuration .Bl -tag -compact -width ".Li VIA Sy environment" .It Li REGEXP Ar ere Use the specified case-insensitive extended regular expression to match URLs. .Qq Sy \en , .Qq Sy \er , .Qq Sy \et , and .Qq Sy \ef are replaced with the new-line, the carriage return, the horizontal tab, and the form feed, respectively. The default is: .Bd -filled -compact -offset 4n .ft CR .if n .nf @DEFAULT_REGEXP@ .ft .Ed .Pp . .It Li COMMAND Ar prog Run shell .Ar prog Ns ram , subject to .Li VIA , when an URL is opened. .br .Ar prog may contain multiple programs, delimited by .So Sy :\& Sc Ns s ; they are tried in order until one exits .Sy 0 . .br Shadows .Pf $ Ev BROWSER . Defaults to .Qq Li @DEFAULT_COMMAND@ . . .It Li VIA Sy argument Run .Ar prog , followed by a space and the quoted URL. If .Ar prog contains .Qq Sy %s , that is instead replaced with the quoted URL. .br This may leave the URL visible in to other users in .Pa /proc . This is the default. . .It Li VIA Sy environment Set the .Ev URL environment variable to the URL, then run .Ar prog verbatim. . .It Li VIA Sy pipe Run .Ar prog verbatim with a line containing the URL piped via the standard input stream. .Pp . .It These two are only useful with Va VIA Ns = Sy argument : .It Li BROWSER Unshadows .Pf $ Ev BROWSER even if .Va COMMAND is set. . .It Li EXPERT Allows .Li "'" Ns s in .Va COMMAND : the URL to be opened is substituted as a quoted word using .Li "'" . If .Ar prog is, for example .Qq Nm w3m Li '%s' Fl N , this would defeat this quoting, and .Em run the URL as code . If you're sure your .Ar prog Ns s don't quote the URL \(em for example .Qq Nm lynx Li %s Fl cookie_file Ns Li ='/tmp/lynx cookies' \(em it's safe to enable .Va EXPERT . .Pp . .It Li EDIT Sy no Ns \&| Ns Sy yes Edit the selected URL before opening it. The default is .Sy no . . .It Li WRAP Sy no Ns \&| Ns Sy yes When at the last URL, allow \(da to go to the first, and vice versa. The default is .Sy no . . .It Li MOUSE Sy yes Ns \&| Ns Sy no Enable mouse support. The default is .Sy yes . .El .Pp .Sy yes , .Sy no , .Sy argument , .Sy environment , and .Sy pipe are case-insensitive. . .Sh EXIT STATUS .Sy 1 if no URLs were found, the effective .Va COMMAND contained a .Li "'" and .Va EXPERT wasn't enabled with .Va VIA Ns = Ns Sy argument . .Va WRAP Ns / Ns Va EDIT Ns / Ns Va MOUSE Ns / Ns Va VIA received an invalid value, .Ar ere isn't a valid ERE, an unknown .Va setting was specified, or a .Ar file couldn't be opened. . .Sh SEE ALSO .Xr mutt 1 , .Xr curses 3 , .Xr regex 7 , .Xr url 7 urlview-ng-1c/urlview.c000066400000000000000000000601531453547617100153410ustar00rootroot00000000000000// SPDX-License-Identifier: GPL-2.0-or-later // Copyright (C) 1997 Michael R. Elkins // Created: Thu Dec 4 02:13:11 PST 1997 // Last Modified: Tue Jul 4 11:23:49 CEST 2000 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #if __has_include() #include #else #define gettext(s) (s) #define ngettext(s, p, n) (n == 1 ? s : p) #endif #include "enter.h" #include "quote.h" #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define auto __auto_type #ifndef REG_STARTEND #define REG_STARTEND_OPT 0 #else #define REG_STARTEND_OPT REG_STARTEND #endif enum redraw { FULL, INDEX, MOTION, CURSORPOS, NO }; struct url { char * url; size_t urllen; int cursor_y, cursor_x; int last_y; }; static char * regex_error(const regex_t * rx, int err) { size_t es = regerror(err, rx, NULL, 0); char * eb = malloc(es); if(eb) regerror(err, rx, eb, es); return eb; } static void search_common(const char * search, regex_t * rx, size_t urlcount, struct url * url, enum redraw * redraw, size_t * current, bool (*matcher)(const regex_t * rx, size_t urlcount, struct url * url, size_t * current)) { if(search) { regex_t newrx; int regerr = regcomp(&newrx, search, REG_EXTENDED | REG_ICASE | REG_NOSUB); if(regerr) { char * err = regex_error(&newrx, regerr); mvaddstr(LINES - 1, 0, search); addstr(": "); addstr(err ?: "?"); clrtoeol(); free(err); *redraw = CURSORPOS; return; } if(rx->re_nsub != (size_t)-1) regfree(rx); *rx = newrx; } if(matcher(rx, urlcount, url, current)) { move(LINES - 1, 0); *redraw = MOTION; } else { // as in "no search results", p.a. to "No such URL!"; potentially displayed after "Search [forwards/backwards] for:" mvaddstr(LINES - 1, 0, gettext("No matches!")); *redraw = CURSORPOS; } clrtoeol(); } static bool search_impl(const regex_t * rx, struct url * url) { return !regexec(rx, url->url, 0, &(regmatch_t){.rm_so = 0, .rm_eo = url->urllen}, REG_STARTEND_OPT); } static bool search_forward(const regex_t * rx, size_t urlcount, struct url * url, size_t * current) { for(size_t i = *current + 1; i < urlcount; ++i) if(search_impl(rx, &url[i])) { *current = i; return true; } return false; } static bool search_backward(const regex_t * rx, size_t urlcount, struct url * url, size_t * current) { (void)urlcount; for(size_t i = *current - 1; i != (size_t)-1; --i) if(search_impl(rx, &url[i])) { *current = i; return true; } return false; } enum via { ARGUMENT, ENVIRONMENT, PIPE }; // if ARGUMENT, program must have already been pre-processed static int system_via(const char * program, const char * url, enum via via) { struct sigaction intr, quit; sigaction(SIGINT, &(struct sigaction){.sa_handler = SIG_IGN}, &intr); sigaction(SIGQUIT, &(struct sigaction){.sa_handler = SIG_IGN}, &quit); int pfd[2]; if(via == PIPE) if(pipe2(pfd, O_CLOEXEC) == -1) return -1; pid_t pid = fork(); switch(pid) { case -1: return -1; case 0: // child sigaction(SIGINT, &intr, NULL); sigaction(SIGQUIT, &quit, NULL); switch(via) { case ARGUMENT: break; case ENVIRONMENT: setenv("URL", url, true); break; case PIPE: dup2(pfd[0], 0); break; } execl("/bin/sh", "sh", "-c", "--", program, (char *)NULL); _exit(errno == ENOENT ? 127 : 126); } if(via == PIPE) { close(pfd[0]); struct iovec iovs[2] = {{.iov_base = (void *)url, .iov_len = strlen(url)}, {.iov_base = "\n", .iov_len = 1}}; for(off_t wr;;) { while((wr = writev(pfd[1], iovs, 2)) == -1 && errno == EINTR) ; if(wr == -1) break; if((size_t)wr > iovs[0].iov_len) break; iovs[0].iov_base += wr; iovs[0].iov_len -= wr; } close(pfd[1]); } int status; while(waitpid(pid, &status, 0) == -1) // EINTR ; sigaction(SIGINT, &intr, NULL); sigaction(SIGINT, &quit, NULL); return status; } int main(int argc, char ** argv) { setlocale(LC_ALL, ""); #if __has_include() bindtextdomain("urlview-ng", TEXTDOMAIN_DIRNAME); textdomain("urlview-ng"); #endif /*** read the initialization file ***/ char * command = NULL; char * regexp = NULL; bool expert = false; bool skip_browser = false; bool menu_wrapping = false; bool edit_url = false; bool mouse = true; enum via via = ARGUMENT; FILE * fp = NULL; char * home = getenv("HOME"); if(home) { char * fpp; if(asprintf(&fpp, "%s/.urlview", home) != -1) { fp = fopen(fpp, "re"); free(fpp); } } if(!fp) fp = fopen(SYSTEM_INITFILE, "re"); char * line = NULL; size_t linecap = 0; if(fp) { for(ssize_t len; (len = getline(&line, &linecap, fp)) != -1;) { if(line[0] == '#' || line[0] == '\n') continue; if(line[len - 1] == '\n') line[--len] = '\0'; size_t keylen = strcspn(line, " \f\n\r\t\v"); size_t seplen = strspn(line + keylen, " \f\n\r\t\v"); char * key = line; char * value = line + keylen + seplen; size_t valuelen = len - (keylen + seplen); #define BOOLKEY(name, var) \ if(KEYMATCH(name)) { \ if(!strcasecmp("YES", value)) \ var = true; \ else if(!strcasecmp("NO", value)) \ var = false; \ else /* "BROWSER", user's input, "yes, no" */ \ errx(1, gettext("Unknown value for %s: %s. Valid values are: %s."), name, value, /* leave yes/no intact, but add explanations */ gettext("yes, no")); \ } #define KEYMATCH(k) keylen == sizeof(k) - 1 && !memcmp(key, k, sizeof(k) - 1) if(KEYMATCH("REGEXP") && valuelen) { if(!(regexp = realloc(regexp, valuelen))) err(1, NULL); char * wc = regexp; while(*value) { if(*value == '\\') { value++; switch(*value) { case 'n': *wc++ = '\n'; break; case 'r': *wc++ = '\r'; break; case 't': *wc++ = '\t'; break; case 'f': *wc++ = '\f'; break; default: *wc++ = '\\'; *wc++ = *value; break; } } else *wc++ = *value; ++value; } *wc = '\0'; } else if(KEYMATCH("COMMAND") && valuelen) { free(command); if(!(command = strdup(value))) err(1, NULL); skip_browser = true; } else BOOLKEY("WRAP", menu_wrapping) else // BOOLKEY("EDIT", edit_url) // else // BOOLKEY("MOUSE", mouse) // else if(KEYMATCH("VIA")) { if(!strcasecmp("ARGUMENT", value)) via = ARGUMENT; else if(!strcasecmp("ENVIRONMENT", value)) via = ENVIRONMENT; else if(!strcasecmp("PIPE", value)) via = PIPE; else /* "VIA", user's input, "argument, environment, pipe" */ errx(1, gettext("Unknown value for %s: %s. Valid values are: %s."), "VIA", value, /*leave argument/environment/pipe intact, but add explanations*/ gettext("argument, environment, pipe")); } else if(KEYMATCH("BROWSER")) // skip_browser = false; else if(KEYMATCH("EXPERT")) // expert = true; else // errx(1, gettext("Unknown setting: %s"), line); } fclose(fp); } /* Only use the $BROWSER environment variable if * (a) no COMMAND in rc file or * (b) BROWSER in rc file. * If both COMMAND and BROWSER are in the rc file, then the option used * last counts. */ if(!skip_browser) { char * browser = getenv("BROWSER"); if(browser) { if(*browser) command = browser; else warnx(gettext("Empty $BROWSER, falling back to COMMAND (%s)."), command ?: DEFAULT_COMMAND); } } if(!command) command = (char *)DEFAULT_COMMAND; if(via == ARGUMENT && !expert && strchr(command, '\'')) errx(1, gettext("\n" "Your COMMAND/$BROWSER contains a single quote (') character.\n" "This is most likely in error; please read the manual page for details.\n" "If you really want to use this command, please put the word EXPERT\n" "into a line of its own in your ~/.urlview file.")); /*** compile the regexp ***/ regex_t rx; int regerr = regcomp(&rx, regexp ?: DEFAULT_REGEXP, REG_EXTENDED | REG_ICASE | REG_NEWLINE); if(regerr) errx(1, "%s: %s", regexp ?: DEFAULT_REGEXP, regex_error(&rx, regerr)); free(regexp); /*** prepare arguments ***/ off_t startline = 0; bool reopen_tty = false; size_t current = 0, oldcurrent = 0; opterr = false; for(int opt; (opt = getopt(argc, argv, "+0::1::2::3::4::5::6::7::8::9::")) != -1;) { if(opt == '?') { --optind; break; } if(optarg) { char * end; errno = 0; startline = strtoll(optarg - 1, &end, 10); if(errno || *end) { errno = errno ? errno : EINVAL; err(1, "-%s", optarg - 1); } } else startline = opt - '0'; current = (size_t)-1; } if(optind == argc) argv[--optind] = "-"; /*** find matching patterns ***/ struct url * url = NULL; size_t urlsize = 0; size_t urlcount = 0; bool error = false; for(int i = optind; i < argc; ++i) { if(!strcmp("-", argv[i])) { fp = stdin; reopen_tty = true; } else if(!(fp = fopen(argv[i], "re"))) { warn("%s", argv[i]); error = true; continue; } for(ssize_t linelen; (linelen = getline(&line, &linecap, fp)) != -1;) { --startline; size_t offset = 0; for(regmatch_t match; (match = (regmatch_t){.rm_so = 0, .rm_eo = linelen - offset}), !regexec(&rx, line + offset, 1, &match, (offset ? REG_NOTBOL : 0) | REG_STARTEND_OPT);) { size_t len = match.rm_eo - match.rm_so; if(urlcount >= urlsize) { size_t urlsizetmp = urlsize ? urlsize * 2 : 16; void * urltmp = reallocarray(url, urlsizetmp, sizeof(*url)); if(urltmp == NULL) { cantalloc: warn(gettext("couldn't allocate memory for additional URLs, only first %zu displayed"), urlsize); goto got_urls; } else { urlsize = urlsizetmp; url = urltmp; } } if(!(url[urlcount].url = malloc(len + 1))) goto cantalloc; memcpy(url[urlcount].url, line + match.rm_so + offset, len); url[urlcount].url[len] = 0; url[urlcount].urllen = len; for(size_t i = 0; i < urlcount; ++i) if(url[i].urllen == len && !strncasecmp(url[i].url, url[urlcount].url, len)) { --urlcount; break; } if(current == (size_t)-1 && startline <= 0) current = urlcount; ++urlcount; offset += match.rm_eo; } } got_urls: if(fp != stdin) fclose(fp); } regfree(&rx); free(line); if(getenv("URLVIEW_DEBUG") || !isatty(1)) { for(size_t i = 0; i < urlcount; ++i) fwrite(url[i].url, 1, url[i].urllen, stdout), putchar('\n'); return 0; } if(!urlcount) { puts(gettext("No URLs found.")); return 1; } if(current == (size_t)-1) current = urlcount - 1; if(reopen_tty) if(!freopen("/dev/tty", "r", stdin)) err(1, "/dev/tty"); initscr(); cbreak(); noecho(); curs_set(1); keypad(stdscr, TRUE); if(mouse) { // OpenBSD shim: it ships with NCURSES_MOUSE_VERSION being 1, which excludes BUTTON[45]_PRESSED: https://builds.sr.ht/~nabijaczleweli/job/1064539 #ifndef BUTTON5_PRESSED #define BUTTON5_PRESSED 0 #endif #ifndef BUTTON4_PRESSED #define BUTTON4_PRESSED 0 #endif mousemask(BUTTON1_CLICKED | BUTTON5_PRESSED | BUTTON4_PRESSED, NULL); mouseinterval(0); } // title line #define urlswin_logical_height (LINES - 1 - 1) // status line WINDOW * urlswin = newpad(LINES, COLS); if(!urlswin) return endwin(), 1; enum redraw redraw = FULL; struct enter_string search = {}; regex_t search_rx = {.re_nsub = (size_t)-1}; int page_of_current = 0; size_t first_on_page = 0; int fudge = 0; for(bool done = false; !done;) { switch(redraw) { case FULL: { wresize(urlswin, LINES, COLS); /* "N URLs" is on top of "Press q to quit" is on top of the branding * "N URLs" is left margin, "Press q to quit" is right margin, branding goes to center of remaining * This unfortunately means we have to draw "N URLs" and "Press q to quit" first to a scratch window to establish the width, * (urlswin is good since it's cleared below anyway; this approach is recommended by Dickey: https://stackoverflow.com/a/70590135/2851815), * then draw them in the right order to stdscr. */ clear(); standout(); mvwprintw(urlswin, 0, 0, ngettext("%zu URL", "%zu URLs", urlcount), urlcount); int urlswidth = getcurx(urlswin); cc_t intr = CINTR; struct termios termios; if(!tcgetattr(0, &termios)) intr = termios.c_cc[VINTR]; char intr_s[4] = {}; // M-^? if(intr != _POSIX_VDISABLE) { char * intr_cur = intr_s; if(intr & 0x80) *intr_cur++ = 'M', *intr_cur++ = '-'; intr &= 0x7F; if(isprint(intr)) *intr_cur++ = intr; else if(intr == 0x7F) *intr_cur++ = '^', *intr_cur++ = '?'; else *intr_cur++ = '^', *intr_cur++ = intr + '@'; mvwprintw(urlswin, 0, 0, gettext("Press q or %.*s to quit!"), (int)sizeof(intr_s), intr_s); } else mvwaddstr(urlswin, 0, 0, gettext("Press q to quit!")); #define BRAND "urlview-ng " VERSION "" mvwaddstr(stdscr, 0, urlswidth + (COLS - getcurx(urlswin) - urlswidth) / 2 - (sizeof(BRAND) - 1) / 2, BRAND); if(intr != _POSIX_VDISABLE) mvwprintw(stdscr, 0, COLS - getcurx(urlswin), gettext("Press q or %.*s to quit!"), (int)sizeof(intr_s), intr_s); else mvwaddstr(stdscr, 0, COLS - getcurx(urlswin), gettext("Press q to quit!")); mvwprintw(stdscr, 0, 0, ngettext("%zu URL", "%zu URLs", urlcount), urlcount); standend(); wnoutrefresh(stdscr); } __attribute__((fallthrough)); case INDEX: wclear(urlswin); wmove(urlswin, 0, 0); for(size_t i = 0; i < urlcount; ++i) { #define EXPAND() \ { \ int sizey, sizex; \ getmaxyx(urlswin, sizey, sizex); \ if(wresize(urlswin, sizey * 2, sizex) == ERR) \ break; \ } #define EXPANDONSCROLL(...) \ if(__VA_ARGS__ != OK) { \ wmove(urlswin, starty, startx); \ EXPAND(); \ goto again; \ } int starty, startx; getyx(urlswin, starty, startx); again: EXPANDONSCROLL(waddstr(urlswin, " ")); getyx(urlswin, url[i].cursor_y, url[i].cursor_x); --url[i].cursor_x; EXPANDONSCROLL(wprintw(urlswin, "%4zu", i + 1)); EXPANDONSCROLL(waddch(urlswin, ' ')); EXPANDONSCROLL(waddnstr(urlswin, url[i].url, url[i].urllen)); url[i].last_y = getcury(urlswin); if(i != urlcount - 1) if(waddch(urlswin, '\n') != OK) { EXPAND(); waddch(urlswin, '\n'); } } __attribute__((fallthrough)); case MOTION: mvwaddstr(urlswin, url[oldcurrent].cursor_y, url[oldcurrent].cursor_x - 2, " "); wstandout(urlswin); mvwaddstr(urlswin, url[current].cursor_y, url[current].cursor_x - 2, "->"); wstandend(urlswin); page_of_current = url[current].cursor_y / urlswin_logical_height; first_on_page = 0; while(url[first_on_page].cursor_y / urlswin_logical_height != page_of_current) ++first_on_page; fudge = 0; // try to get the last-URL-on-the-page to be included when it's selected if(url[current].last_y - url[first_on_page].cursor_y > urlswin_logical_height) // unclear why +1 needed here; this means we overscroll (sometimes) // compare the first screen on a rows 54; cols 172; teletype of // ./urlview text.uv <(for i in A B C D E F H I J K L M; do tr Q $i < text.uv; done) // and // ./urlview text.uv <(for i in A B C D E F H I J K L M; do tr Q $i < text.uv; done | fold -w 300) // the last link on the first screen appear to have a completely identical last_y, but the former is taller by a line? fudge = (url[current].last_y - url[first_on_page].cursor_y) - urlswin_logical_height + 1; pnoutrefresh(urlswin, /**/ url[first_on_page].cursor_y + fudge, 0, /**/ 1 /*title line*/, 0, urlswin_logical_height, COLS); doupdate(); oldcurrent = current; __attribute__((fallthrough)); case CURSORPOS: // same projection as pnoutrefresh() above move(url[current].cursor_y - (url[first_on_page].cursor_y + fudge) + 1 /*title line*/, url[current].cursor_x - 0 + 0); __attribute__((fallthrough)); case NO: break; } redraw = NO; int c = getch(); rekey: switch(c) { case KEY_RESIZE: redraw = FULL; break; case KEY_MOUSE: { MEVENT ev; getmouse(&ev); if(ev.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED | BUTTON1_TRIPLE_CLICKED)) { wmouse_trafo(urlswin, &ev.y, &ev.x, false); ev.y += url[first_on_page].cursor_y + fudge; for(size_t hit = first_on_page; hit != urlcount; ++hit) if(ev.y >= url[hit].cursor_y && ev.y <= url[hit].last_y) { current = hit; redraw = MOTION; ungetch('\n'); break; } } else if(ev.bstate & BUTTON5_PRESSED) { c = KEY_DOWN; goto rekey; } else if(ev.bstate & BUTTON4_PRESSED) { c = KEY_UP; goto rekey; } } break; case 'q': case 'x': case 'h': done = true; break; case KEY_DOWN: case 'j': if(current < urlcount - 1) ++current; else { if(menu_wrapping) current = 0; } redraw = MOTION; break; case KEY_UP: case 'k': if(current) --current; else { if(menu_wrapping) current = urlcount - 1; } redraw = MOTION; break; case KEY_HOME: case '=': current = 0; redraw = MOTION; break; case KEY_END: case '*': case 'G': current = urlcount - 1; redraw = MOTION; break; case KEY_NPAGE: case '\006': { size_t first_on_next_page = first_on_page; while(first_on_next_page != urlcount - 1 && url[first_on_next_page].cursor_y / urlswin_logical_height != page_of_current + 1) ++first_on_next_page; current = first_on_next_page; redraw = MOTION; } break; case KEY_PPAGE: case '\002': if(first_on_page != 0) current = first_on_page - 1; else current = 0; redraw = MOTION; break; case '\n': case '\r': case KEY_ENTER: case ' ': case 'e': // edit prompt if(edit_url || c == 'e') { mvaddstr(LINES - 1, 0, gettext("URL: ")); mmask_t oldmouse = 0; mousemask(0, &oldmouse); auto newurl = enter_string(url[current].url, url[current].urllen); if(newurl.len) { if(newurl.len != url[current].urllen || memcmp(url[current].url, newurl.data, newurl.len)) redraw = INDEX; free(url[current].url); url[current].url = newurl.data; url[current].urllen = newurl.len; } mousemask(oldmouse, NULL); move(LINES - 1, 0); clrtoeol(); if(c == 'e' || !newurl.len) goto promptcancel; } endwin(); char * execstatus = NULL; size_t execstatuslen = 0; #define EXECAPPENDONE(str, len_arg) \ { \ size_t len = (len_arg); \ char * new = realloc(execstatus, execstatuslen + len); \ if(new) { \ execstatus = new; \ memcpy(execstatus + execstatuslen, str, len); \ execstatuslen += len; \ } \ } #define EXECAPPEND_PCNT_S(fmt, s, slen) \ { \ const char * pcnt = strstr(fmt, "%s"); \ EXECAPPENDONE(fmt, pcnt - fmt); \ EXECAPPENDONE(s, slen == (size_t)-1 ? strlen(s) : slen); \ EXECAPPENDONE(pcnt + 2, strlen(pcnt + 2)); \ } bool okexit = false; char * curcom = command; size_t curcomlen = strcspn(curcom, ":"); while(*curcom) { char *toexec, *tofree = NULL; size_t toexeclen = -1; if(via == ARGUMENT) toexec = tofree = quotesub(curcom, curcomlen, url[current].url, url[current].urllen); else { if(curcom[curcomlen]) toexec = tofree = strndup(curcom, curcomlen); else toexec = curcom; toexeclen = curcomlen; } EXECAPPEND_PCNT_S(gettext("Executing: %s... "), toexec, toexeclen); printf(gettext("Executing: %s... "), toexec); fflush(stdout); int childret = system_via(toexec, url[current].url, via); free(tofree); if(WIFEXITED(childret) && !WEXITSTATUS(childret)) { EXECAPPENDONE("i", 1); putchar('\n'); okexit = true; break; } char childrets_buf[11 + 1], *childrets = childrets_buf; // -2147483648 size_t childrets_len = -1; if(WIFSIGNALED(childret)) childrets = strsignal(WTERMSIG(childret)); else childrets_len = sprintf(childrets_buf, "%d", WEXITSTATUS(childret)); // child exit code or human-readable signal name, written after "Executing: %s... " EXECAPPEND_PCNT_S(gettext("%s! "), childrets, childrets_len); printf(gettext("%s!\n"), childrets); curcom += curcomlen; if(*curcom) ++curcom; curcomlen = strcspn(curcom, ":"); } if(execstatus) { size_t off = 0; for(; off != execstatuslen && mvaddnstr(LINES - 1, 0, execstatus + off, execstatuslen - off) == ERR; ++off) ; if(okexit) { mvaddch(LINES - 1, getcurx(stdscr) - 1, ACS_DIAMOND); clrtoeol(); } free(execstatus); } redraw = MIN(redraw, CURSORPOS); break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { // edit prompt mvaddstr(LINES - 1, 0, gettext("Jump to URL: ")); auto num = enter_string(&(char){c}, 1); if(num.len) { static_assert(sizeof(size_t) == sizeof(unsigned long), "size mismatch"); char * end; size_t i = strtoul(num.data, &end, 0); if(i < 1 || i > urlcount || *end) { // error from the above mvaddstr(LINES - 1, 0, gettext("No such URL!")); redraw = CURSORPOS; } else { current = i - 1; move(LINES - 1, 0); redraw = MOTION; } free(num.data); clrtoeol(); } else goto promptcancel; } break; case '\f': case '\007': clearok(stdscr, TRUE); redraw = FULL; break; case 'n': case 'N': c = c == 'n' ? '/' : '?'; if(search_rx.re_nsub != (size_t)-1) { search_common(NULL, &search_rx, urlcount, url, &redraw, ¤t, c == '/' ? search_forward : search_backward); break; } __attribute__((fallthrough)); case '/': case '?': mvaddstr(LINES - 1, 0, c == '/' ? /* edit prompt */ gettext("Search forwards for: ") : /* edit prompt */ gettext("Search backwards for: ")); auto newsearch = enter_string(search.data, search.len); if(newsearch.len) { free(search.data); search = newsearch; search_common(search.data, &search_rx, urlcount, url, &redraw, ¤t, c == '/' ? search_forward : search_backward); } else { promptcancel: move(LINES - 1, 0); clrtoeol(); redraw = MIN(redraw, CURSORPOS); } break; } } endwin(); return error; }