glazier

the original window manipulator
Log | Files | Refs | Submodules | README | LICENSE

commit e8169b62ac85a3f5ab0145f28393e924fc43725b
parent 6e0e08447424e5bdaa0d1daac749cad011c8e659
Author: Willy Goiffon <dev@z3bra.org>
Date:   Tue, 22 Oct 2019 14:06:25 +0200

Add command line argument parsing

Diffstat:
arg.h | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
glazier.c | 27+++++++++++++++++++++++++--
2 files changed, 90 insertions(+), 2 deletions(-)

diff --git a/arg.h b/arg.h @@ -0,0 +1,65 @@ +/* + * Copy me if you can. + * by 20h + */ + +#ifndef ARG_H__ +#define ARG_H__ + +extern char *argv0; + +/* use main(int argc, char *argv[]) */ +#define ARGBEGIN for (argv0 = *argv, argv++, argc--;\ + argv[0] && argv[0][1]\ + && argv[0][0] == '-';\ + argc--, argv++) {\ + char argc_;\ + char **argv_;\ + int brk_;\ + if (argv[0][1] == '-' && argv[0][2] == '\0') {\ + argv++;\ + argc--;\ + break;\ + }\ + for (brk_ = 0, argv[0]++, argv_ = argv;\ + argv[0][0] && !brk_;\ + argv[0]++) {\ + if (argv_ != argv)\ + break;\ + argc_ = argv[0][0];\ + switch (argc_) + +/* Handles obsolete -NUM syntax */ +#define ARGNUM case '0':\ + case '1':\ + case '2':\ + case '3':\ + case '4':\ + case '5':\ + case '6':\ + case '7':\ + case '8':\ + case '9' + +#define ARGEND }\ + } + +#define ARGC() argc_ + +#define ARGNUMF() (brk_ = 1, estrtonum(argv[0], 0, INT_MAX)) + +#define EARGF(x) ((argv[0][1] == '\0' && argv[1] == NULL)?\ + ((x), abort(), (char *)0) :\ + (brk_ = 1, (argv[0][1] != '\0')?\ + (&argv[0][1]) :\ + (argc--, argv++, argv[0]))) + +#define ARGF() ((argv[0][1] == '\0' && argv[1] == NULL)?\ + (char *)0 :\ + (brk_ = 1, (argv[0][1] != '\0')?\ + (&argv[0][1]) :\ + (argc--, argv++, argv[0]))) + +#define LNGARG() &argv[0][0] + +#endif diff --git a/glazier.c b/glazier.c @@ -3,6 +3,7 @@ #include <xcb/xcb.h> #include <xcb/xcb_cursor.h> +#include "arg.h" #include "wm.h" #include "config.h" @@ -32,7 +33,7 @@ static int cb_enter(xcb_generic_event_t *); static int cb_configure(xcb_generic_event_t *); static int cb_configreq(xcb_generic_event_t *); -int verbose = 1; +int verbose = 0; xcb_connection_t *conn; xcb_screen_t *scrn; xcb_window_t curwid; @@ -82,6 +83,12 @@ static const struct ev_callback_t cb[] = { { XCB_CONFIGURE_REQUEST, cb_configreq }, }; +void +usage(char *name) +{ + fprintf(stderr, "usage: %s [-vh]\n", name); +} + xcb_window_t frame_window(xcb_window_t child) { @@ -441,15 +448,31 @@ ev_callback(xcb_generic_event_t *ev) int main (int argc, char *argv[]) { + char *argv0; xcb_generic_event_t *ev = NULL; + ARGBEGIN { + case 'v': + verbose++; + break; + case 'h': + usage(argv0); + return 0; + break; /* NOTREACHED */ + default: + usage(argv0); + return -1; + break; /* NOTREACHED */ + } ARGEND; + wm_init_xcb(); wm_get_screen(); curwid = scrn->root; /* needed to get notified of windows creation */ - wm_reg_event(scrn->root, XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT); + wm_reg_event(scrn->root, XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY + | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT); xcb_flush(conn); for (;;) {