Commit Graph

73 Commits (master)

Author SHA1 Message Date
NRK f2f4903de4 apply clang-format
minus the bogus changes

Co-authored-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
1 year ago
NRK a051ad210d update copyright year 1 year ago
NRK 01f3cf2e47 use assertions instead of ignoring bogus arguments (#406)
instead of silently ignoring bogus arguments (i.e programming errors),
which can make debugging harder, it's better to assert them so that they
get caught faster in debug builds.

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/406
Reviewed-by: explosion-mental <explosion-mental@noreply.codeberg.org>
1 year ago
NRK 16b966be3b spawn(): search $PATH as well
makes this function more useful for other people writing patches such as
this: https://codeberg.org/nsxiv/nsxiv-extra/src/branch/master/patches/dmenu-search
1 year ago
NRK 49d11f0d1f spawn(): improve performance and simplify API
posix_spawn() is designed especially for this purpose, and thus it's
much more lightweight and efficient than manually fork/dup/exec-ing.

on my system, it improves the performance of spawn() by about 10x. given
that we make frequent calls to potentially multiple scripts, the
increased efficiency will add up overtime.

using posix_spawn() also simplifies the logic quite a bit, despite the
very verbose function names. however it does make cleanup a bit more
complicated.

this patch uses the linux kernel style cleanup strategy [0] (which I'm
personally not a huge fan of, but it fits this situation quite nicely)
with a "stack-like" unwinding via `goto`-s.

additionally simplify the spawn() API by taking in {read,write}fd
pointers and returning the pid instead of using some custom struct.

this coincidently also fixes #299

[0]: https://www.kernel.org/doc/html/v4.10/process/coding-style.html?highlight=goto#centralized-exiting-of-functions
1 year ago
NRK b11384a694 code-style: misc changes (#374)
* ensure static variables comes after non-static ones
* remove depreciated DATA32 type
* prefer `sizeof(expression)` over `sizeof(Type)`.
* silence a -Wsign warning
* {gif,webp} loader: use a pointer to reduce code-noise
* gif loader: allocate in one place

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/374
Reviewed-by: TAAPArthur <taaparthur@noreply.codeberg.org>
2 years ago
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`.
2 years ago
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>
2 years ago
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.
2 years ago
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
2 years ago
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.
2 years ago
NRK 4cf17d2349 fix: memory leak in r_readdir()
reported by clang-tidy: `filename` gets leaked when this branch gets
taken.
2 years ago
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>
2 years ago
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>
2 years ago
N-R-K ad95012be9
Add reuseable abstraction over fork/exec/dup2 (#211) 2 years ago
NRK 48343e99b8 code-style: prefer calloc over malloc+memset 2 years ago
NRK 9cdeeab9b8 update copyright year 2 years ago
N-R-K f7145db7f8
remove unused function and typedef (#199)
byteorder_t and size_readable is not used anywhere within the code.

byteorder_t seems to be a remain from some time sxiv handled exif data itself instead of relying on a library, introduced in 691c6d7, and probably became irrelevant when libexif was added as dependency again. And size_readable from some time it displayed the file size in the window title, introduced in bad9a70.
2 years ago
N-R-K 850bc788c3
code-style: general cleanups (#137)
* tns_clean_cache: remove unused function arg

* remove malloc casting

* improve consistency

use sizeof(T) at the end

* avoid comparing integers of different signedness

* use Window type for embed and parent

* remove unnecessary comparisons

* remove cpp style comments

* improve consistency: remove comma from the end of enumerator list

* Removed useless _IMAGE_CONFIG defines

* consistency: use the same order as snprintf

* Resolve c89 warnings


Co-authored-by: uidops <uidops@protonmail.com>
Co-authored-by: Arthur Williams <taaparthur@gmail.com>
3 years ago
eylles 5b3221cfa6
update copyright notice (#139) 3 years ago
javad bbebd45ce6 code-style: remove extra casts (#130)
Co-authored-by: N-R-K <79544946+N-R-K@users.noreply.github.com>
3 years ago
Berke Kocaoğlu 1449bfc5e9
code-style: fix consistency issues all over the codebase (#94)
* remove duplicate comment
* remove empty tabs and blank lines
* move macros and globals ontop
* comment to seprate function implementation
* fix alignment
* switch to *argv[] similar to other suckless code
* kill all empty last lines
* append comment to endif
* reuse existing ARRLEN macro
* comment fall through
* use while (true) everywhere

Co-authored-by: NRK <nrk@disroot.org>
3 years ago
Berke Kocaoğlu 7cce7ea857 Rename, Update Docs and Prepare for Release (#9)
Co-authored-by: Guilherme Rugai Freire <41879254+GRFreire@users.noreply.github.com>
Co-authored-by: N-R-K <79544946+N-R-K@users.noreply.github.com>
Co-authored-by: NRK <nrk@disroot.org>
Co-authored-by: Arthur Williams <taaparthur@gmail.com>
Co-authored-by: eylles <ed.ylles1997@gmail.com>
3 years ago
Kacper Gutowski e6c9218319 Don't skip dot files when cleaning cache 6 years ago
Bert Münnich 3c7d6f3528 Replace utf8codepoint with Chris Wellons' utf8_decode
Code under a different license should be kept in a separate file. This
implemention is a single header file with ~65 lines, so it better fits this
requirement.
7 years ago
Squibby eb96c71725 Try to match a fallback font if needed
Fixes #276

Instead of rendering the entire filename at once, Xft will let us do it
character by character. This will allow sxiv to query fontconfig for
a font that can provide any missing codepoints, if needed.

A known issue of this patch is that the "..." dots rendering will not
work properly for very long multibyte filenames. That is because we
cannot easily predict the final width of the rendered filename before
drawing it. I couldn't figure out a clean way to deal with this, so I
ended up just truncating the offending filenames.
7 years ago
Bert Münnich 148026007c One header file for type definitions and function declarations 7 years ago
Paride Legovini 86dc6860f9 Allow opening directories non-recursively 8 years ago
Bert Münnich 53a72c7b65 Fix option -q; commit d3a70a2 completely broke it; fixes issue #223 9 years ago
Bert Münnich a7d39b0ab8 Simplified r_mkdir() 9 years ago
Bert Münnich d3a70a285d Revised error handling
- Functions warn() and die() replaced by GNU-like error(3) function
- Register cleanup() with atexit(3)
- Functions called by cleanup() are marked with CLEANUP and are not allowed to
  call exit(3)
9 years ago
Bert Münnich 851e4288c1 Prefix safe allocation functions with 'e' instead of 's_' 9 years ago
Bert Münnich b096cbd536 Removed unnecessary buffer size constants 9 years ago
Bert Münnich 9a7e97cd89 Use XSI realpath(3) 9 years ago
Bert Münnich 66c3c55759 Use POSIX.1-2008 getline(3) 9 years ago
Bert Münnich e574a6d0dd Removed feature test macro definitions from source files 9 years ago
Bert Münnich e0e96977b3 Removed overcautious parameter checks 9 years ago
Markus Elfring 0f6cb93a09 Bug #165: Deletion of unnecessary null pointer checks
The function "free" performs input parameter validation.
http://pubs.opengroup.org/onlinepubs/9699919799/functions/free.html

It is therefore not needed to check a passed pointer before this function call.
A corresponding update suggestion was generated by the software "Coccinelle"
from the following semantic patch approach.
http://coccinelle.lip6.fr/

@Remove_unnecessary_pointer_checks1@
expression x;
@@
-if (x != \(0 \| NULL\))
    free(x);

@Remove_unnecessary_pointer_checks2@
expression x;
@@
-if (x != \(0 \| NULL\)) {
    free(x);
    x = \(0 \| NULL\);
-}

@Remove_unnecessary_pointer_checks3@
expression a, b;
@@
-if (a != \(0 \| NULL\) && b != \(0 \| NULL\))
+if (a)
    free(b);

@Remove_unnecessary_pointer_checks4@
expression a, b;
@@
-if (a != \(0 \| NULL\) && b != \(0 \| NULL\)) {
+if (a) {
    free(b);
    b = \(0 \| NULL\);
 }

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
10 years ago
lucas8 3b8a79fb8b Made argument of s_strdup const 10 years ago
Bert Münnich 5cfae63620 Create thumbnail cache dir automatically 10 years ago
Bert Münnich 408b75a0b4 Ignore dotfiles for -r 11 years ago
Bert Münnich 08ae25da22 Refactored function definitions to use dangling brace 11 years ago
Bert Münnich 6d3bbc6d5e Updated/corrected license header 11 years ago
Bert Münnich d407dd65d5 Already in the year 2012 12 years ago
Bert Münnich c3c95ab218 Removed slideshow support 12 years ago
Bert Münnich 36177fb180 Updated contact information 13 years ago
Bert Münnich 4383a651c7 Strictly adhere to ANSI-C standard 13 years ago
Bert Münnich a09b20c5e6 Use void for empty argument lists 13 years ago
Bert Münnich 8dcf682de9 Made all conditionals more precise 13 years ago
Bert Münnich 22d4e991d5 Transformed function macros in util.h to inline functions 13 years ago