Commit Graph
30 Commits
Author SHA1 Message Date
Laslo HunholdandAaron Marcher b640cc489b Check return value of pclose() 2018-05-20 01:01:26 +02:00
Laslo HunholdandAaron Marcher 951ea4e304 Refactor entropy.c 2018-05-20 00:19:52 +02:00
Laslo HunholdandAaron Marcher 46c4540dd2 Implement fmt_human_2() and fmt_human_10()
These functions take the raw number and a unit and automatically
print it out "scaled down" to a proper SI-prefix, for powers of 2
and 10 respectively.

Apply them to the 2-power cases and keep the 10-power for a later
commit.
2018-05-19 22:58:21 +02:00
Laslo HunholdandAaron Marcher 68a3902dc5 Increase precision in netspeeds.c
First dividing by interval before multiplying with 1000 decreases the
precision by +-(interval - 1) * 1000, as interval arithmetic always
applies the Gauß-function to the result.

This is not necessary and simply reordering the operations mitigates
this.
2018-05-19 20:14:09 +02:00
Laslo HunholdandAaron Marcher 422cadfd5f Implement esnprintf() and make formatted calls more efficient
Within the components, snprintf() was unchecked and had inefficient
calls in some places.
We implement esnprintf() that does all the dirty laundry for us
and use it exclusively now.
2018-05-19 19:44:02 +02:00
Laslo HunholdandAaron Marcher 80fc20d1d6 Add warn() and die()
Given slstatus is a tool that runs in the background, most likely run
from .xinitrc, it's important to prepend the name of the tool to error
messages so it becomes clear where the error is coming from.

To make this much more consistent, this commit adds warn() and die()
utility functions consistent with other suckless projects and adapts all
calls to fprintf(stderr, *) to the warn() and die() functions, greatly
increasing the readability of the code.
2018-05-18 11:13:05 +02:00
Laslo HunholdandAaron Marcher a4fe8c9741 Audit slstatus.c
1) Remove setlocale() (locales are harmful and any 'issues' shall
    be fixed in different ways that are expected).
 2) Disable buffering on stdout with setbuf() rather than flushing
    it each time.
 3) Make error messages more consistent.
 4) Add error checks where applicable.
 5) Make code a bit more readable where res is assigned.
 6) Use XFlush() rather than XSync() (we don't need to wait for the
    XServer to react, which could lead to long hangs on our side).
2018-05-18 10:08:03 +02:00
Laslo HunholdandAaron Marcher c83b388a3f Properly handle *snprintf() errors
Posix guarantees that the resulting string is null-terminated, even if
we have an overflow. Instead of doing what has already been done,
properly warn when there has been an error or overflow, so the user can
do something about it.
2018-05-17 23:26:56 +02:00
Laslo HunholdandAaron Marcher 24b663d657 Tweak build system a little bit
Be consistent with brackets and add a comment for OpenBSD to make it
clearer what the actual intent of the uncommented line is.

In the Makefile, add a dependency of slstatus.o from config.mk.
2018-05-01 20:53:27 +02:00
Laslo HunholdandAaron Marcher 19343ff343 components/swap.c | move duplicated code to separate function 2018-05-01 20:24:13 +02:00
Laslo HunholdandAaron Marcher 9750a3d731 Use indentation to increase readability
Granted, this style is definitely not common, but for the short
utility-functions of this program it's just the right choice. This
provides great flexibility, such that in the long run, it will be
possible to also share code between the OS-implementations.

This also keeps the state-keeping at a minimum and makes it clearer
which functions are implemented on which OS without having to jiggle
around with too many files in the process.
2018-05-01 19:43:49 +02:00
Laslo HunholdandAaron Marcher 42edfea89a Revert component-split
this reverts the commits from 92ab9ef52e up to
d42870d6ca.

After heavy consideration, the component split has more disadvantages
than advantages, especially given there will be utility-functions
sharing quite a lot of code that would then need to be duplicated, as it
does not fit into the util.c due to its speciality.

One big advantage of the component-wise build is readability, and
without doubt, this was achieved here. This point will be addressed
with a different approach that will be visible in the upcoming commits.

One big disadvantage of the component build is the fact that it
introduces state to the build process which is not necessary. Before its
introduction, the only influencing factors where the system-defines
__linux__ and __OpenBSD__. With the components, we are also relying on
the output of uname(1).
Additionally, if the os.mk is not present, make gives the output

     $ make
     Makefile:5: os.mk: No such file or directory
     make: *** No rule to make target 'os.mk'.  Stop.

This could easily be fixed by providing some sort of meta-rule for this
file, however, it indicates the problem we have here, and this entire
statefulness will heavily complicate packaging of this tool and makes
the build process much more complex than it actually has to be.
2018-05-01 19:43:34 +02:00
Laslo HunholdandAaron Marcher 7246dc4381 Move components into dedicated subdirectory
This brings us a lot more tidiness.
2017-09-24 17:20:27 +02:00
Laslo HunholdandAaron Marcher 61e44e8948 Get rid of HDR variable
The HDR variable is used for general purpose headers, which are not
given in this project. arg.h and config.h are only needed for
slstatus.c, not every component $(COM:=.c).

This also fixes a problem introduced in
e04a385364, where config.h is pulled into
the tarball.
2017-09-18 10:08:51 +02:00
Laslo HunholdandAaron Marcher f56e50a269 Simplify Makefile 2017-09-18 08:47:54 +02:00
Laslo HunholdandAaron Marcher 914440b4fc Properly declare buf as extern and fix all unused-warnings 2017-09-17 17:38:07 +02:00
Laslo HunholdandAaron Marcher eea99fc0ac Rewrite Makefile to accomodate file split 2017-09-17 17:37:49 +02:00
Laslo HunholdandAaron Marcher 0f7e022381 Fix a little logic error 2017-08-14 11:35:52 +02:00
Laslo HunholdandAaron Marcher e1e1b1d79a Add pscanf()
This reduces a lot of equivalent code to one function call.
2017-08-14 08:24:54 +02:00
Laslo HunholdandAaron Marcher 796b661284 Refactor main()
We remove the hack with the sleep and global "delay"-variable and use a
monotonic clock to derive the desired monotonic properties of the tool.
Inside each function that demands a personal delay we can then just do a
nanosleep() and be done with it.
It's a shame that timespec is so ugly to work with, but there's really
no way to make it more beautiful. However, at this cost though we
finally can set the interval times in milliseconds and not only just
seconds.

We remove setlocale(), because nothing good ever came out of this
function.

Besides that we have some more code refactoring, especially in the
argument loop which saves us a bit of complexity.
2017-08-13 23:45:16 +02:00
Laslo HunholdandAaron Marcher 3468a6e368 Simplify signal handling a bit 2017-08-13 23:32:14 +02:00
Laslo HunholdandAaron Marcher 450e8e6e6b Remove unnecessary prototypes 2017-08-13 23:32:06 +02:00
Laslo HunholdandAaron Marcher ecf2779904 Remove unnecessary blank lines after license-notice 2017-08-13 23:31:56 +02:00
Laslo HunholdandAaron Marcher 1814061396 Add and use LEN() macro 2017-08-11 13:43:11 +02:00
Laslo HunholdandAaron Marcher 178c23e3d2 Refactor battery_state() 2017-08-11 00:20:47 +02:00
Laslo HunholdandAaron Marcher 00ce7a746a Print usage() when we are left with arguments 2017-08-10 22:33:05 +02:00
Laslo HunholdandAaron Marcher c9d47405f4 Reduce -o | -n to -s
What we really want is to either output to WM_NAME or stdout. If we want
just one single line, we do slstatus | head -n 1.
2017-08-10 22:32:57 +02:00
Laslo HunholdandAaron Marcher 4d33c36014 Remove d- and v-flags
d-flag: There's no need for that, use the &-operator or fork+exec in a
        non-shell-context. In the latter case you get the PID for free.
v-flag: If you want to find out which version of a package is installed,
        consult your package manager. That's his job.
2017-08-10 22:32:48 +02:00
Laslo HunholdandAaron Marcher 958c34052a Convert slstatus.1 to mandoc, simplify it and remove -h
We also change the semantics of -v to only return the version
information.
There is now no need for usage() to exit with anything other than 1.
2017-08-10 22:32:28 +02:00
Laslo HunholdandAaron Marcher 8dad4910bf Refactor build system 2017-08-10 22:32:14 +02:00