Reduce indentation in all code + shell examples

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2017-09-20 08:41:47 +02:00
1 parent d92b4ce2ae
commit 649f40e5d3
1 file changed
+72 -72
+72 -72
View File
@@ -75,9 +75,9 @@ is achieved by calling `uev_init()` with a pointer to a (thread) local
`uev_ctx_t` variable. `uev_ctx_t` variable.
```C ```C
uev_ctx_t ctx; uev_ctx_t ctx;
uev_init(&ctx); uev_init(&ctx);
``` ```
@@ -91,22 +91,22 @@ with the `uev_ctx_t` context, the callback, and an optional argument.
Here is a signal example: Here is a signal example:
```C ```C
void cleanup_exit(uev_t *w, void *arg, int events) void cleanup_exit(uev_t *w, void *arg, int events)
{ {
/* Graceful exit, with optional cleanup ... */ /* Graceful exit, with optional cleanup ... */
uev_exit(w->ctx); uev_exit(w->ctx);
} }
int main(void)
{
uev_t sigterm_watcher;
. int main(void)
. {
uev_signal_init(&ctx, &sigterm_watcher, cleanup_exit, NULL, SIGTERM); uev_t sigterm_watcher;
.
. .
} .
uev_signal_init(&ctx, &sigterm_watcher, cleanup_exit, NULL, SIGTERM);
.
.
}
``` ```
@@ -119,7 +119,7 @@ used to integrate [libuEv][] into another event loop.
In this example we set `flags` to none: In this example we set `flags` to none:
```C ```C
uev_run(&ctx, UEV_NONE); uev_run(&ctx, UEV_NONE);
``` ```
With `flags` set to `UEV_ONCE` the event loop returns as soon as it has With `flags` set to `UEV_ONCE` the event loop returns as soon as it has
@@ -163,14 +163,14 @@ LibuEv is by default installed as a library with a few header files, you
should only ever need to include one: should only ever need to include one:
```C ```C
#include <uev/uev.h> #include <uev/uev.h>
``` ```
The output from the `pkg-config` tool holds no surprises: The output from the `pkg-config` tool holds no surprises:
```sh ```sh
$ pkg-config --libs --static --cflags libuev $ pkg-config --libs --static --cflags libuev
-I/usr/local/include -L/usr/local/lib -luev -I/usr/local/include -L/usr/local/lib -luev
``` ```
The prefix path `/usr/local/` shown here is only the default. Use the The prefix path `/usr/local/` shown here is only the default. Use the
@@ -179,15 +179,15 @@ The prefix path `/usr/local/` shown here is only the default. Use the
For GNU autotools based projects, use the following in `configure.ac`: For GNU autotools based projects, use the following in `configure.ac`:
```sh ```sh
# Check for required libraries # Check for required libraries
PKG_CHECK_MODULES([uev], [libuev >= 1.4.0]) PKG_CHECK_MODULES([uev], [libuev >= 1.4.0])
``` ```
and in your `Makefile.am`: and in your `Makefile.am`:
```sh ```sh
proggy_CFLAGS = $(uev_CFLAGS) proggy_CFLAGS = $(uev_CFLAGS)
proggy_LDADD = $(uev_LIBS) proggy_LDADD = $(uev_LIBS)
``` ```
@@ -198,60 +198,60 @@ Here follows a very brief example to illustrate how one can use libuEv
to act upon joystick input. to act upon joystick input.
```C ```C
#include <err.h> #include <err.h>
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <uev/uev.h> #include <uev/uev.h>
struct js_event { struct js_event {
uint32_t time; /* event timestamp in milliseconds */ uint32_t time; /* event timestamp in milliseconds */
int16_t value; /* value */ int16_t value; /* value */
uint8_t type; /* event type */ uint8_t type; /* event type */
uint8_t number; /* axis/button number */ uint8_t number; /* axis/button number */
} e; } e;
static void joystick_cb(uev_t *w, void *arg, int events) static void joystick_cb(uev_t *w, void *arg, int events)
{ {
read(w->fd, &e, sizeof(e)); read(w->fd, &e, sizeof(e));
switch (e.type) { switch (e.type) {
case 1: case 1:
printf("Button %d %s\n", e.number, e.value ? "pressed" : "released"); printf("Button %d %s\n", e.number, e.value ? "pressed" : "released");
break; break;
case 2: case 2:
printf("Joystick axis %d moved, value %d!\n", e.number, e.value); printf("Joystick axis %d moved, value %d!\n", e.number, e.value);
break; break;
}
}
int main(void)
{
int fd;
uev_t watcher;
uev_ctx_t ctx;
fd = open("/dev/input/js1", O_RDONLY, O_NONBLOCK);
if (fd < 0)
errx(errno, "Cannot find a joystick attached.");
uev_init(&ctx);
uev_io_init(&ctx, &watcher, joystick_cb, NULL, fd, UEV_READ);
puts("Starting, press Ctrl-C to exit.");
return uev_run(&ctx, 0);
} }
}
int main(void)
{
int fd;
uev_t watcher;
uev_ctx_t ctx;
fd = open("/dev/input/js1", O_RDONLY, O_NONBLOCK);
if (fd < 0)
errx(errno, "Cannot find a joystick attached.");
uev_init(&ctx);
uev_io_init(&ctx, &watcher, joystick_cb, NULL, fd, UEV_READ);
puts("Starting, press Ctrl-C to exit.");
return uev_run(&ctx, 0);
}
``` ```
To build the example, follow installation instructions below, then save To build the example, follow installation instructions below, then save
the code as `joystick.c` and call GCC the code as `joystick.c` and call GCC
```sh ```sh
$ gcc `pkg-config --libs --static --cflags libuev` -o joystick joystick.c $ gcc `pkg-config --libs --static --cflags libuev` -o joystick joystick.c
``` ```
Alternatively, call the `Makefile` with <kbd>make joystick</kbd> from Alternatively, call the `Makefile` with <kbd>make joystick</kbd> from