Commit Graph

959 Commits

Author SHA1 Message Date
NRK
85fffbb277 improve error message on bad cli argument (#371)
currently the error messages have the shortopt hardcoded in them, even
when the user actually entered a longopt:

	$ ./nsxiv --framerate v
	nsxiv: Invalid argument for option -A: v

and as far as I see, there's no way to *reliably* tell weather we're
processing a longopt or a shortopt. perhaps we can do some shenanigangs
with `optind` but that seems finicky at best.

and it seems like other coreutils which support longopt has similar issues:

	$ xargs --max-procs=z
	xargs: invalid number "z" for -P option

utils like `grep` and `head` seems to work-around it by not mentioning the flag:

	$ head --lines=z
	head: invalid number of lines: ‘z’
	$ grep --max-count=l
	grep: invalid max count

this patch does the same thing as `grep/head` and omits the flag from
the error message.

Closes: https://codeberg.org/nsxiv/nsxiv/issues/368

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/371
Reviewed-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
2022-09-28 18:15:09 +02:00
NRK
daee34477a fix potential truncation of cli arguments (#367)
strtol() returns a `long`, but we're storing the result in an `int`
which might end up getting truncated. change `n` to `long` and guard
against >INT_MAX arguments in cases where it matters.

use a float for storing argument of `-S`

change `opt.slideshow` to `unsigned` similar to `img.ss.delay`

Co-authored-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/367
Reviewed-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
Reviewed-by: explosion-mental <explosion-mental@noreply.codeberg.org>
2022-09-14 06:58:41 +02:00
NRK
e356add07c rename: aa -> anti_alias 2022-09-10 19:43:14 +06:00
NRK
88a480c938 allow disabling anti-aliasing via cli flag
simply running nsxiv with `--anti-alias` will enable anti-aliasing, and
running it with `--anti-alias=no` will disable it.

the cli flag will overwrite the config.h default.

Closes: https://codeberg.org/nsxiv/nsxiv/issues/349
2022-09-10 19:43:07 +06:00
NRK
7e3e6008fe remove some hardcoded "nsxiv", use progname instead 2022-09-05 03:52:51 +02:00
NRK
fbe186e79d don't assume positive argc
handle a rare, but possible case of argc being 0, in which case argv[0]
would be null.

note that both POSIX and ISO C standard allow argc to be 0 and in
practice this can be triggered via calling `exec(3)` family of functions
with NULL as the first `argv`.
2022-09-05 03:52:51 +02:00
NRK
ba39006574 [ci]: disable noisy checks (#365)
* disable `cert-err33-c` and `readability-identifier-length` check
  which causes warnings on clang-tidy v14.
* disable all "readability" checks by default, instead just opt-into the
  useful ones (such as duplicate include).

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/365
Reviewed-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
2022-09-05 03:47:32 +02:00
NRK
32bfe58915 Misc docs cleanup (#362)
* link to online man-page
* rename: "N-R-K" -> "NRK"
* separate multiple links with a comma.
  otherwise the links get messed up due to `[] []` being valid syntax for
  reference style links with the 2nd `[]` serving as `id`.
* prefer codeberg links over github ones

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/362
Reviewed-by: explosion-mental <explosion-mental@noreply.codeberg.org>
2022-08-19 08:36:53 +02:00
explosion-mental
0f0c49a630 code-style: don't indent switch cases (#358)
The suckless coding style [^0] and the linux coding style [^1] both
recommends not indenting switch cases. And it helps out people with
lower resolution monitors.

[^0]: https://suckless.org/coding_style/
[^1]: https://www.kernel.org/doc/html/v5.10/process/coding-style.html#indentation

Co-authored-by: explosion-mental <explosion0mental@gmail.com>
Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/358
Reviewed-by: NRK <nrk@disroot.org>
Co-authored-by: explosion-mental <explosion-mental@noreply.codeberg.org>
Co-committed-by: explosion-mental <explosion-mental@noreply.codeberg.org>
2022-08-16 10:54:31 +02:00
NRK
6578e6eb65 code-style: various cleanups (#356)
* run_key_handler: make the logic easier to follow
* remove timeout_t
  the typedef is not needed. inline the declaration similar to the other
  static structs.
* simplify estrdup
  reuse emalloc, instead of calling malloc and null-checking.
* win_clear: initialize `e` right away
* process_bindings: explicitly check against NULL
  most pointer checks in the codebase do explicit check.
* use a named constant instead of magic number
  also changes the padding from 3 to 4 bytes according to [0]. but i
  couldn't find any situtation where this mattered, so perhaps the current
  padding is enough. but doesn't hurt adding one more byte.

[0]: https://nullprogram.com/blog/2017/10/06/

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/356
Reviewed-by: explosion-mental <explosion-mental@noreply.codeberg.org>
2022-08-16 10:53:05 +02:00
NRK
216f312578 add support for long-opts (#332)
Uses [optparse] to add support for long-opts. optparse is posix
compliant with getopt(3) and thus would be backwards compatible.
It does not have any dependency (not even the c standard library!) and
is C89 compatible and thus fits our current code-style.

[optparse]: https://github.com/skeeto/optparse

Note that we're using a couple `pragma`-s to silence some harmless
warnings. This should be portable because these pragma-s don't change the
behavior of the program. Furthermore, C standard mandates that unknown
pragma's should be ignored by the compiler and thus would not result in
build failure on compilers which do not recognize them.

Closes: https://codeberg.org/nsxiv/nsxiv/issues/328
Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/332
Reviewed-by: eylles <eylles@noreply.codeberg.org>
2022-08-16 10:43:50 +02:00
NRK
d9f20a4122 [ci]: build with macos on github
should help catch *BSD compilation issues.
2022-08-11 03:58:26 +02:00
NRK
becf1cc858 fix: build failure when _SC_PHYS_PAGES is not defined
_SC_PHYS_PAGES isn't POSIX and might not be defined. in such case, just
return back `CACHE_SIZE_FALLBACK`.

NOTE: POSIX says the `names` in `sysconf()` are "symbolic constants" not
necessarily macros. So we might end up returning the fallback in some
cases where `_SC_PHYS_PAGES` *was* available, but not defined as a
macro. which is not ideal, but nothing fatal.

in practice, this shouldn't be an issue since most systems seems to
define them to be macros, i've checked Glibc, Musl, OpenBSD, FreeBSD and
Haiku.

also add a (useful) comment on `config.h` describing the effect higher
cache size has.

Closes: https://codeberg.org/nsxiv/nsxiv/issues/354
2022-08-11 03:58:26 +02:00
NRK
fb9686c650 Move uncritical files into etc/ (#350)
This is mainly just to reduce the amount of files in the project root.
The criteria of what gets into `etc/` are the following:

* The file should not be necessary for building nsxiv. This excludes the
  `icon/*` stuff since that's needed by `window.c`.
* The file shouldn't have any valid reason to stay in the project root.
  This excludes things like `README.md`, `.gitignore` etc.

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/350
Reviewed-by: explosion-mental <explosion-mental@noreply.codeberg.org>
2022-08-09 16:21:52 +02:00
NRK
8dc126194f fix: statusbar not updating when switching bar (#353)
Closes: https://codeberg.org/nsxiv/nsxiv/issues/352
Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/353
Reviewed-by: explosion-mental <explosion-mental@noreply.codeberg.org>
2022-08-08 16:13:28 +02:00
Nan
3e17e4684c README: fix broken link (#351)
Fixes a link that previously 404'd

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/351
Reviewed-by: NRK <nrk@disroot.org>
Co-authored-by: Nan <nan42@waifu.club>
Co-committed-by: Nan <nan42@waifu.club>
2022-08-02 12:54:33 +02:00
NRK
94d531fd82 autoreload: simplify and cleanup (#342)
the current code is quite hacky and complex as it mixes multiple pointers. all
of this complexity is unnecessary. drop it by introducing an explicit scratch
buffer instead of implicitly abusing `arl->filename` as one. this also reduces
some unnecessary allocation overhead.

additionally, the argument to arl_setup must be the result of `realpath(3)` (as
commented in `nsxiv.h`). instead of commenting it, assert it.

and lastly, rename `arl_setup` to `arl_add` since it's not doing any "setup"
but rather *adding* a file to watch.

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/342
Reviewed-by: explosion-mental <explosion-mental@noreply.codeberg.org>
2022-07-30 10:05:10 +02:00
NRK
6d8ec5aee3 [ci]: fix failure (#348)
* install unversioned `llvm` so that it pulls the latest one.
* disable `uninitvar` check on cppcheck as it catches some false positives and
  gcc/clang/clang-tidy are good at catching uninitialized variables already.

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/348
Reviewed-by: explosion-mental <explosion-mental@noreply.codeberg.org>
2022-07-29 03:37:40 +02:00
NRK
1263f23970 [ci]: use git ls-files for spellchecking (#345)
excluding the `.png` icons.

this also fixes the wrong `.patch` and `.diff` extensions checks.
no clue why we were trying to find `.patch` and `.diff` to begin with.

i think i probably copy pasted the command i tested on nsxiv-extra repo
or somewhere else without changing the extensions to `.c` and `.h`.

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/345
2022-07-27 08:57:50 +02:00
NRK
dd0b3cb163 fix: stale statusbar when started in thumbnail mode (#341)
this was one of the cases which got missed in 591be8c, if someone starts
with `-t` the statusbar will remain at "Loading ...". Once we're done
loading all the thumbnail, make sure to open_info() so that `thumb-info`
gets called.

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/341
Reviewed-by: explosion-mental <explosion-mental@noreply.codeberg.org>
2022-07-26 07:20:39 +02:00
zood
78938721a4 Document Ctrl-6 keybind (#347)
Closes: #297

Co-authored-by: Sudo Nice <sudo.nice@gmail.com>
Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/347
Reviewed-by: NRK <nrk@disroot.org>
Co-authored-by: zood <zood@noreply.codeberg.org>
Co-committed-by: zood <zood@noreply.codeberg.org>
2022-07-18 11:06:02 +02:00
NRK
c131b1ed83 fix: -Wsign-compare warnings (#336)
mixing signed and unsigned types in comparison can end up having
unintended results. for example:

	if (-1 < 1U)
		printf("true\n");
	else
		printf("false\n");

previously we silenced these warnings, instead just fix them properly
via necessary casting, and in cases where the value cannot be negative
(e.g width/height members) make them unsigned.

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/336
Reviewed-by: explosion-mental <explosion-mental@noreply.codeberg.org>
2022-07-15 22:46:23 +02:00
NRK
5cab2fb525 reject empty xresources (#340)
currently, in case of an empty xresources we would fail to init:

	nsxiv: Error allocating color ''

instead, just reject empty value and use the fallback.

Closes: https://codeberg.org/nsxiv/nsxiv/issues/339

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/340
Reviewed-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
Co-authored-by: NRK <nrk@disroot.org>
Co-committed-by: NRK <nrk@disroot.org>
2022-07-05 11:24:53 +02:00
NRK
51d4c8dd4f check for utf8_decode errors (#327)
utf8_decode() may return an errors, in which case the returned codepoint
might be garbage. the issue can be tested by adding the following to
`image-info` which produces invalid utf8 sequences:

	base64 -d << EOF
	9JCAgPSQgIH0kICC9JCAg/SQgIT0kICF9JCAhvSQgIf0kICI9JCAifSQgIr0kICL9JCAjPSQgI30
	kICO9JCAj/SQgJD0kICR9JCAkvSQgJP0kICU9JCAlfSQgJb0kICX9JCAmPSQgJn0kICa9JCAm/SQ
	gJz0kICd9JCAnvSQgJ8=
	EOF

on my system, this leads to the statusbar being filled with empty boxes.

check for returned error and skip the iteration.

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/327
Reviewed-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
2022-07-03 12:45:50 +02:00
NRK
7c59cc7edc fix build failure due to missing <stdio.h> (#337)
the following combination currently fails to build:

	$ make HAVE_LIBFONTS=0 HAVE_LIBWEBP=1

this is probably because one of the font library was including <stdio.h>

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/337
Reviewed-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
Reviewed-by: TAAPArthur <taaparthur@noreply.codeberg.org>
Co-authored-by: NRK <nrk@disroot.org>
Co-committed-by: NRK <nrk@disroot.org>
2022-07-03 08:16:56 +02:00
Berke Kocaoğlu
5c2c719735 Clean up readme (#330)
Co-authored-by: NRK <nrk@disroot.org>
Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/330
Reviewed-by: NRK <nrk@disroot.org>
2022-06-29 01:02:17 +02:00
NRK
b162aee497 sort and group includes
* includes are sorted alphabetically

* their grouping and layout is the following:
  - nsxiv.h will be the first include
  - followed by any internal headers (e.g "commands.h" "config.h")
  - followed by system headers (<stdlib.h> etc)
  - followed by third party headers (X.h libwebp etc)

* also add `llvm-include-order` check to clang-tidy so that it can catch
  unsorted includes during CI.
2022-06-28 21:28:06 +02:00
NRK
6d5a04005d code-style: cleanup includes
* rm unused include <sys/types.h>
* move <sys/time.h> to main.c, it's the only file that needs it.
* move TV_* macros to main.c
* let *.c files explicitly include what they need instead of including
  them at nsxiv.h
2022-06-28 21:28:06 +02:00
NRK
86a83c1ec5 CHANGELOG: use reference style links (#325)
Originally we stopped doing links in the CHANGELOG since it harmed
readability when reading the raw markdown file. However we can use
reference styles links instead.

* Pros
  - Doesn't harm readability.
  - We can link to proper thread on the proper repo (`CodeBerg/nsxiv`
    for newer threads, `nsxiv-record` for wiped ones)
  - The links will be clickable on the [webpage]
  - Both GitHub and Codeberg support reference style links, as well as
    lowdown (which we use for building the webpage)

[webpage]: https://nsxiv.codeberg.page/changelog/

* Cons
  - Slightly higher maintainance burden.
  - Larger file size.

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/325
Reviewed-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
2022-06-27 21:20:59 +02:00
NRK
f78626c187 CHANGELOG: update title and link (#324)
now that CHANGELOG has it's own webpage [0], update the title
accordingly. also change the link to `nsxiv-record` instead.

[0]: https://nsxiv.codeberg.page/changelog/

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/324
Reviewed-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
2022-06-27 10:48:00 +02:00
NRK
50f7b767c9 [ci]: check for typos via codespell (#326)
also fix any found issues.

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/326
Reviewed-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
2022-06-27 10:47:14 +02:00
NRK
8248729320 [ci]: skip the pipeline entirely if branch isn't master
currently, it will clone the repo and then skip the step. this is
wasteful, instead skip the pipeline entirely.
2022-06-25 08:27:01 +02:00
NRK
a9d2b5b088 [ci]: suppress some cppcheck warnings
cppcheck warns about passing a plain NULL to construct_argv()

	main.c:254:36: portability: Passing NULL after the last typed argument to a variadic function leads to undefined behaviour. [varFuncNullUB]
	                fidx, fcnt, w, h, z, NULL);

in our case, POSIX mandates `NULL` to be defined as `(void *)0` rather
than a plain `0` [0]. and void pointers are required to have the same
representation and size as char pointers [1]. so this is not an issue we
need to worry about.

[0]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stddef.h.html#tag_13_47
[1]: https://port70.net/~nsz/c/c99/n1256.html#6.2.5p27
2022-06-25 08:27:01 +02:00
NRK
5c3a796e55 [ci]: slience some clang-tidy warnings
the warnings on r_readdir(), img_load_gif() and strcpy seems to be false
positives. the warning about fmt being unused is valid, but not worth
fixing with additional #ifdef guards.

use `assert` to silence the false positive cases when possible,
otherwise use a NOLINT comment with an explanation.
2022-06-25 08:27:01 +02:00
NRK
4cf17d2349 fix: memory leak in r_readdir()
reported by clang-tidy: `filename` gets leaked when this branch gets
taken.
2022-06-25 08:27:01 +02:00
NRK
b28449e10c fix: don't use reserved identifiers
identifiers beginning with an underscore is reserved by the C standard.
2022-06-25 08:27:01 +02:00
NRK
f23d57d4ad [ci]: use cppcheck and clang-tidy for static analysis 2022-06-25 08:27:01 +02:00
NRK
658a935c04 fix: potentially printing wrong error message (#321)
it's possible for the close() calls to override the errno resulting in
incorrect error message being printed.

call error() immediately to avoid such possibilities.

also refactor a couple conditions to avoid doing multiple checks.

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/321
Reviewed-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
2022-06-25 08:21:05 +02:00
NRK
9812d601c1 r_mkdir: don't truncate the path on error (#322)
currently, in case of error, r_mkdir will leave the path at a truncated
state.

a7d39b0ab8 is the commit that introduced this change, and in it the
error printing is moved from r_mkdir to the caller, which makes me think
it was probably intentional.

make it so that the function itself prints the error/warning
message and returns the path back to the caller unharmed.

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/322
Reviewed-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
Reviewed-by: TAAPArthur <taaparthur@noreply.codeberg.org>
2022-06-22 05:05:03 +02:00
NRK
a67665a1c1 add codeberg ci and cleanup github one (#311)
- apt-get is slow, takes up ~1m40s just to install deps, fix it by not
  using it. instead use alpine linux for codeberg ci, which brings build
  time down to 25s.
- And since alpine uses musl, it's probably a good idea to use it on our
  ci since it might catch us using any glibc extensions. The github ci
  can keep using ubuntu.
- remove duplication of CFLAGS by having it on a separate file instead.
- remove pull_request from github ci since we no longer accept PRs
  there.

Closes: https://codeberg.org/nsxiv/nsxiv/issues/307

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/311
Reviewed-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
Reviewed-by: TAAPArthur <taaparthur@noreply.codeberg.org>
2022-06-16 05:08:09 +02:00
NRK
33a5d54cae Release version 30
Co-authored-by: NRK <nrk@disroot.org>
Co-authored-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
2022-06-15 16:07:46 +02:00
Sanjay Pavan
91e097a4e6 Fix links in readme (#309)
The former worked on GitHub, but does not work on Codeberg.

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/309
Reviewed-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
Co-authored-by: Sanjay Pavan <withercubes@protonmail.com>
Co-committed-by: Sanjay Pavan <withercubes@protonmail.com>
2022-06-12 18:49:49 +02:00
NRK
4c6d26bef4 Move over to codeberg (#293)
Reviewed-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
2022-06-11 15:38:07 +02:00
eylles
09d2d738ad
adds emblems of mirrors 2022-06-06 18:56:21 -06:00
NRK
e9a0096d6d code-style: simplify window title related code
instead of dancing around with some `init` parameter, directly give
`win_set_title()` what it needs. `get_win_title()` now also does *just*
what the name says.

this simplifies things quite a bit and the functions now do what their
name implies more closely instead of doing some `init` dance internally.
2022-06-02 08:09:51 +00:00
NRK
810a9651a3 reduce calls to win-title
rather than calling the script unconditionally per redraw, we now have
a `title_dirty` flag and keep track of when any of the relavent
information changes.

Co-authored-by: Arthur Williams <taaparthur@gmail.com>
Partially fixes: https://github.com/nsxiv/nsxiv/issues/258
2022-06-02 08:09:51 +00:00
N-R-K
364c3d6f01
avoid doing dynamic allocation for bar buffers (#279)
just use a static buffer since the size is constant and doesn't change.

as opposed to using malloc, this also sets the buffer's initial memory
region to 0 by default.

also remove BAR_{L,R}_LEN from nsxiv.h, not needed after commit b4268fbf38
2022-06-01 07:40:49 +06:00
N-R-K
57ff8afe02
Makefile: add utf8.h as window.o dependency (#280)
unlikely for utf8.h to change, other than syncing with upstream, but
doesn't hurt tracking it either ways.
2022-05-31 06:54:32 +00:00
NRK
c713186ce9 Makefile: use lowercase for internal macros
ref: 971f5d6694
2022-05-30 12:07:01 +00:00
NRK
6c30fb22cc config.mk: use c99 as default CC
See https://github.com/nsxiv/nsxiv/issues/262#issuecomment-1111216349
for related discussion.
2022-05-30 12:07:01 +00:00