Commit Graph

14 Commits

Author SHA1 Message Date
Daniel Stone
dd8219b3fb option-parser: Make bools boolean
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>
2019-11-28 19:24:13 +00:00
Marius Vlad
6630f2acd3 shared/: Please compiler when passed certain compile flags
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>
2019-08-06 20:36:06 +03:00
Pekka Paalanen
91b1010de9 Rename config-parser.h to libweston/config-parser.h
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>
2019-04-18 12:31:46 +03:00
Eric Engestrom
0c30fa5503 option-parser: replace int/0/1 with bool/false/true
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>
2017-12-04 19:37:33 +00:00
Lyude Paul
47bbdc7296
weston: Add support for "--foo bar" style options
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>
2017-05-23 11:19:27 +02:00
Bryce Harrington
25a2bdd814 Switch to use safe_strtoint instead of strtol
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>
2016-08-06 18:19:22 -07:00
Bryce Harrington
d9779e3ff1 option-parser: Improve error checking for strtol call
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>
2016-08-06 18:19:16 -07:00
Bryce Harrington
f6051cbab8 option-parser: Require integer option string values to be base-10
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>
2016-07-08 17:44:10 -07:00
Bryce Harrington
38298ec0b4 option-parser: Handle short double-arg options
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>
2016-03-08 16:32:16 -08:00
Bryce Harrington
6c6164c5ba shared: Update boilerplate from MIT X11 license to MIT Expat license 2015-06-15 13:04:18 -07:00
Bill Spitzak
3011493e9b parse_options: fail on more malformed options
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>
2014-09-11 12:36:55 +03:00
Daniel Stone
c228e23b05 configure.ac: Enable AC_USE_SYSTEM_EXTENSIONS
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]
2013-06-05 01:16:34 -04:00
Kristian Høgsberg
4172f668e7 Pass argc pointer to parse_options()
This lets us keep argc up to date as the backend picks out arguments
from the argv array.
2013-02-20 15:27:49 -05:00
Kristian Høgsberg
bcacef19b0 Add an option parser
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.
2012-03-12 01:28:50 -04:00