When option-parser is confronted with a boolean option, have it write a
bool rather than treating the value as a pointer to an int32.
(lib)weston already heavily uses bool types internally, so this has the
nice side effect of eliminating quite a few local variables which only
existed as integer shadows of internal boolean variables.
Signed-off-by: Daniel Stone <daniels@collabora.com>
Fixes the following warn/error when using combination of flags like
building with debug, when disabling optimization and/or when enabling ASAN:
../shared/option-parser.c:61:1: error: control reaches end of non-void function [-Werror=return-type]
Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
It is a public installed header used by libweston.h.
See "Rename compositor.h to libweston/libweston.h" for rationale.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
These are already used as bools by all callers, let's make that official.
Signed-off-by: Eric Engestrom <eric@engestrom.ch>
Reviewed-by: Daniel Stone <daniels@collabora.com>
A little earlier today I ended up spending a lot of time trying to
figure out why weston wasn't managing to launch over SSH and telling me
that I did not have a --tty option specified, despite me passing the
option strings ["--tty", "3"]. Turns out weston just doesn't support
that.
So, add support for this kind of format in addition to "--foo=bar" to
save others from making the same mistake I did.
Changes since v1:
- Add comment about unreachable boolean check in long_option_with_arg()
- Convert boolean check in long_option_with_arg() to assert
Signed-off-by: Lyude <lyude@redhat.com>
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Reviewed-by: Quentin Glidic <sardemff7+git@sardemff7.net>
Make the error checking consistent with other strtol() calls.
Note that since strtol(nptr, &endptr) sets endptr == nptr if there were
no digits, this catches the case where the string was blank, so there's
no need to test *value != '\0'.
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
The third arg to strtol() specifies the base to assume for the number.
When 0 is passed, as is currently done in option-parser.c, hexadecimal
and octal numbers are permitted and automatically detected and
converted.
In weston and the weston clients and tests using option-parser.c, the
options are all things that can be expected to be specified in base 10:
widths, heights, counts, scales, font sizes, ports, ttys, connectors,
etc. The subsurfaces client uses two modes, limited to values 0 and 1
only. The zuc testsuite has a --random parameter for specifying a seed,
which is the only option where using hexadecimal or octal numbers might
conceivably happen.
The benefit of limiting this to base-10 is to eliminate surprises when
parsing numbers from the command line. Also, by making the code
consistent with other usages of strtol/strtoul, it may make it possible
to factor out the common code in the future.
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
weston allows both short and long style options to take arguments. In
the case of short options, allow an optional space between the option
name and value. E.g., previously you could launch weston this way:
weston -i2 -cmyconfig.ini
now you can also launch it like this:
weston -i 2 -c myconfig.ini
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Fail on trailing text after numbers, such as --width=100mm
Fail on any text after booleans, such as --flag=false
Also fixed reading of memory after the null terminator of a long
option with no = sign in it.
[Pekka Paalanen: some whitespace style fixes.]
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
AC_USE_SYSTEM_EXTENSIONS enables _XOPEN_SOURCE, _GNU_SOURCE and similar
macros to expose the largest extent of functionality supported by the
underlying system. This is required since these macros are often
limiting rather than merely additive, e.g. _XOPEN_SOURCE will actually
on some systems hide declarations which are not part of the X/Open spec.
Since this goes into config.h rather than the command line, ensure all
source is consistently including config.h before anything else,
including system libraries. This doesn't need to be guarded by a
HAVE_CONFIG_H ifdef, which was only ever a hangover from the X.Org
modular transition.
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
[pq: rebased and converted more files]
On one hand, getopt (in particular the -o suboption syntax) sucks on the
server side, and on the client side we would like to avoid the glib
dependency. We can roll out own option parser and solve both problems
and save a few lines of code total.