Commit Graph
41 Commits
Author SHA1 Message Date
Laslo HunholdandAaron Marcher 81d5b427cb Don't explicitly list each component-target
I made a mistake while reading the Posix spec. In fact, the implicit
prerequisite imposed by the .c.o-rule is evaluated as expected, even if
the .c is not given in the target rule.

This partially reverts 0efd64ffaa.
2018-05-29 21:25:39 +02:00
Laslo HunholdandAaron Marcher a18439af11 Refactor swap.c to use getline() instead of buf-filling
This drops a lot of code and even though we are using a common function,
the specification of only the needed things keeps it very efficient and
even more efficient in memory and time than the previous solution.
2018-05-28 22:21:34 +02:00
Laslo HunholdandAaron Marcher cd884c2f0a Fix object order and stop using a GNU make idiom 2018-05-28 16:16:20 +02:00
Laslo HunholdandAaron Marcher 0efd64ffaa Explicitly list component-objects in the Makefile
There was a long tinkering process at farbfeld about this, but the sad
truth is that it's the only way to make the Makefile truly portable.
Listing it just as

   $(COM:=.o): config.mk $(REQ:=.h)

omits the dependency on the c-file itself, which incurs that strictly
speaking the object file is not depending on the source file, which is
nonsense.

You don't see strictly Posix compliant Makefiles around very often and
most use nasty GNU-extensions everywhere. It is a good idea to go ahead
as a fitting example and show how to write them portably.
2018-05-27 22:55:15 +02:00
Laslo HunholdandAaron Marcher 682c0fedde Use E-notation for large powers of 10 2018-05-27 19:53:36 +02:00
Laslo HunholdandAaron Marcher f17f39d0a2 Refactor keymap.c
- Get rid of camel-casing
 - Don't use all-caps for variable names
 - use LEN()-macro
 - use strncmp() rather than strstr() for prefix-checking
 - clean up the tokenizer-loop and don't use copies
 - make the loop more readable by separating different breaking
   conditions
 - stricter error-checking and cleanup
 - store the layout directly with bprintf rather than having
   a separate buffer
2018-05-23 19:56:16 +02:00
Laslo HunholdandAaron Marcher 13d77cd268 Refactor snprintf-usage in util.c 2018-05-23 19:56:04 +02:00
Laslo HunholdandAaron Marcher 57f69e900b Remove o-flag as it is redundant
Even if we extend the flag to be an n-flag with a numerical input, we
already have other Unix-tools to take care of us much more flexibly,
e.g. with head(1) you can easily get the first 10 outputs with

	slstatus -s | head -n 10,

but also e.g. discard the first one and then get the consecutive 10
outputs.

For the X11-root-window-name, you can limit the runtime with timeout(1)
or a comparable solution.

This reverts commit fa8b939990.
2018-05-22 13:27:11 +02:00
Laslo HunholdandAaron Marcher 9c9ce8a125 Check printf() for output errors
This way cases like

	$ slstatus -s > /dev/full

are properly caught and the program terminated with the proper return
code.
2018-05-22 13:25:47 +02:00
Laslo HunholdandAaron Marcher 7f91ce265e swap.c: Refactor getstats() and its usage
Add a return value so we are able to check any errors and actually fail
when there has been a critical error instead of carrying on uselessly.
2018-05-21 23:05:39 +02:00
Laslo HunholdandAaron Marcher ceb13206a4 Refactor fmt_human() and fix a bug
It is not necessary to copy memory or anything. Just keep a pointer to
the active prefix-array and assign the length of the arrays to a
variable.

Make the code more readable by using a switch, be more strict when an
invalid base is passed to it and fix a small oversight in the bottom of
the code where the base 1024 was forgotten to generalized.
2018-05-21 20:28:57 +02:00
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