summaryrefslogtreecommitdiff
path: root/src/scanner.c
AgeCommit message (Collapse)AuthorFilesLines
2016-08-11scanner: Generate all SINCE_VERSION macros for everyoneQuentin Glidic1-0/+2
Practical example: a client supporting version 2 of wl_output will wait for the wl_output.done event before starting wl_output-related operations. However, if the server only supports version 1, no event will ever come, and it must fallback to use the wl_output.geometry event alone. Without this macro, it cannot check for that in a nice way. This patch introduces the same #defines in both server and client headers. We rely on both being generated from the same XML file and https://gcc.gnu.org/onlinedocs/cpp/Undefining-and-Redefining-Macros.html to not cause compiler errors or warning due to redefinitions. We also assume that no-one uses the same name in the same interface for both a request and an event. If this patch does cause grief due to identical redefinitions, the contingency plan is to change the generator to produce #ifndef/#define/#endif instead of just #define. Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk> [Pekka: add paragraphs to commit message.]
2016-07-25(multiple): Include stdint.hYong Bakos1-0/+1
Some headers and source files have been using types such as uint32_t without explicitly including stdint.h. Explicitly include stdint.h where appropriate. Signed-off-by: Yong Bakos <ybakos@humanoriented.com> Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2016-07-18scanner: Use uint32_t instead of uintKhem Raj1-1/+1
uint32_t is C99 defined stdint type Signed-off-by: Khem Raj <raj.khem@gmail.com> Reviewed-by: Daniel Stone <daniels@collabora.com>
2016-07-11scanner: Improve documentation for strtouint()Bryce Harrington1-2/+11
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com> Reviewed-by: Yong Bakos <ybakos@humanoriented.com>
2016-06-07scanner: Move PROGRAM_NAME defineYong Bakos1-2/+2
PROGRAM_NAME was defined within the if block of HAVE_LIBXML, causing a compilation failure when libxml is not present. Move the define of PROGRAM_NAME out of the if block. Signed-off-by: Yong Bakos <ybakos@humanoriented.com> Reviewed-by: Derek Foreman <derekf@osg.samsung.com>
2016-06-07scanner: Replace #define tab with spaceYong Bakos1-2/+2
wayland-client-protocol.h and wayland-server-protocol.h use a tab between the identifier and token of generated #defines for request/event opcodes and versions. While this sometimes enables vertical alignment, it more frequently doesn't, and leads to awkward spacing. Replace the tab with a space, for consistency and readability. Signed-off-by: Yong Bakos <ybakos@humanoriented.com> Reviewed-by: Quentin Glidic <sardemff7+git@sardemff7.net> Tested-by: Quentin Glidic <sardemff7+git@sardemff7.net>
2016-06-07scanner: Fix reported executable name to 'wayland-scanner'Bryce Harrington1-6/+8
'wayland-scanner -v' (correctly) reports the program as named "wayland-scanner", but 'wayland-scanner -h' was inconsistent, referring to it as './scanner'. Also refactor this and other references to the program name to use a common #define, PROGRAM_NAME. Signed-off-by: Bryce Harrington <bryce@osg.samsung.com> Reviewed-by: Jonas Ådahl <jadahl@gmail.com> Reviewed-by: Yong Bakos <ybakos@humanoriented.com> Tested-by: Yong Bakos <ybakos@humanoriented.com>
2016-05-20scanner: Remove unused forward decs from client protocolYong Bakos1-4/+4
wayland-client-protocol.h had forward declarations for wl_client and wl_resource, yet nothing on the client side references these types. Add a 'side' condition to only generate these forward declarations in the server protocol header. Signed-off-by: Yong Bakos <ybakos@humanoriented.com> Reviewed-by: <pekka.paalanen@collabora.co.uk> Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2016-05-06scanner: Add version argument to wayland-scannerArmin Krezović1-2/+24
This adds a command line argument to print wayland-scanner version. It also makes wayland-scanner emit a comment with wayland library version to every file it generates. v2: separate variable definitions into their own lines and remove old style "version" argument Reviewed-by: Bryce Harrington <bryce@osg.samsung.com> Reviewed-by: Yong Bakos <ybakos@humanoriented.com> Tested-by: Yong Bakos <ybakos@humanoriented.com> Signed-off-by: Armin Krezović <krezovic.armin@gmail.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2016-05-03protocol: add support for cross-interface enum attributesAuke Booij1-16/+53
The enum attribute, for which scanner support was introduced in 1771299, can be used to link message arguments to <enum>s. However, some arguments refer to <enum>s in a different <interface>. This adds scanner support for referring to an <enum> in a different <interface> using dot notation. It also sets the attributes in this style in the wayland XML protocol (wl_shm_pool::create_buffer::format to wl_shm::format, and wl_surface::set_buffer_transform::transform to wl_output::transform), and updates the documentation XSL so that this new style is supported. Changes since v2: - add object:: prefix for all enumerations in the documentation - fix whitespace in scanner.c - minor code fixup to return early and avoid casts in scanner.c Changes since v1: - several implementation bugs fixed Signed-off-by: Auke Booij <auke@tulcod.com> Reviewed-by: Nils Christopher Brause <nilschrbrause@googlemail.com> Reviewed-by: Bill Spitzak <spitzak@gmail.com> [Pekka: rebased across cde251a124d41977b447098cc530fcad2834a45f] [Pekka: wrap lines and space fixes in scanner.c] Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2016-04-19scanner: move include directives before extern "C" wrapperEmil Velikov1-3/+3
Adding extern "C" wrapper before includes (especially system ones) is illadvised as the headers themselves can behave diffently in that case. See the section "Including C Headers in C++ Code" in the following http://www.oracle.com/technetwork/articles/servers-storage-dev/mixingcandcpluspluscode-305840.html Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk> Reviewed-by: Quentin Glidic <sardemff7+git@sardemff7.net>
2016-04-01scanner: Fix spacing of @paramYong Bakos1-1/+1
Adds one space to the @param lines in generated .h files, aligning the indentation with the rest of the comment block. Signed-off-by: Yong Bakos <ybakos@humanoriented.com> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-03-07doc: generate doxygen html output from the scannerPeter Hutterer1-75/+143
This switches the scanner to generate doxygen-compatible tags for the generated protocol headers, and hooks up the doxygen build to generate server and client-side API documentation. That documentation is now in Client/ and Server/, respectively. GENERATE_HTML is on by default and must be disabled for the xml/man targets to avoid messing up the new documentation. We disable all three three targets in the doxyfile (xml and man default to NO anyway) to make it obvious that they need to be set in the per-target instructions. Each protocol is a separate doxygen @page, with each interface a @subpage. Wayland only has one protocol, wayland-protocols will have these nested. Each protocol page has a list of interfaces and the copyright and description where available. All interfaces are grouped by doxygen @defgroup and @ingroups and appear in "Modules" in the generated output. Each interface subpage has the description and a link to the actual API doc. Function, struct and #defines are documented in doxygen style and associated with the matching interface. Note that pages and groups have fixed HTML file names and are directly linkable/bookmark-able. The @mainpage is a separate file that's included at build time. It doesn't contain much other than links to where the interesting bits are. It's a static file though that supports markdown, so we can extend it easily in the future. For doxygen we need the new options EXTRACT_ALL and OPTIMIZE_OUTPUT_FOR_C so it scans C code properly. EXTRACT_STATIC is needed since most of the protocol hooks are static. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2016-02-29build: fix ./configure --disable-dtd-validationPekka Paalanen1-3/+3
When configured with --disable-dtd-validation: CPPAS src/dtddata.o src/dtddata.S: Assembler messages: src/dtddata.S:39: Error: file not found: src/wayland.dtd.embed Makefile:1520: recipe for target 'src/dtddata.o' failed This is because the variable name used does not match the implicit variable name in autoconf. Fix the variable name, making both --disable-dtd-validation and --enable-dtd-validation to what they should. Do not try to build dtddata.S if dtd-validation is disabled. It depends on wayland.dtd.embed which is created by configure only if dtd-validation is enabled. If not building dtddata.S, also make sure the extern definitions in scanner.c are compiled out. Bugzilla: https://bugs.gentoo.org/show_bug.cgi?id=575212 Reported-by: leio@gentoo.org Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk> Reviewed-by: Quentin Glidic <sardemff7+git@sardemff7.net> Tested-by: Bryce Harrington <bryce@osg.samsung.com>
2016-02-04scanner: Fix oddities in copyright printingDerek Foreman1-6/+10
Some copyright strings could result in broken generated header files with unmatched */ This change: Runs the loop long enough so the copyright[i] == 0 test can actually happen. (if there was no \n no copyright text was printed, */ still was) Prints the opening /* even if there was whitespace at the start of the very first line. Only emits a */ if a /* was printed. Signed-off-by: Derek Foreman <derekf@osg.samsung.com> Reviewed-by: Jon A. Cruz <jonc@osg.samsung.com> Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2016-02-01scanner: Print filename on DTD validation errorJonas Ådahl1-5/+10
Don't just print prefix the errors with "protocol", but the actual file name, if wayland-scanner was passed with the filename of the protocol file. If wayland-scanner is reading from stdin, errors will be prefixed with "<stdin>" instead of "protocol". Signed-off-by: Jonas Ådahl <jadahl@gmail.com> Reviewed-by: David Fort <contact@hardening-consulting.com> Reviewed-by: Derek Foreman <derekf@osg.samsung.com> Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2016-01-19Track protocol object versions inside wl_proxy.Jason Ekstrand1-8/+26
This provides a standardized mechanism for tracking protocol object versions in client code. The wl_display object is created with version 1. Every time an object is created from within wl_registry_bind, it gets the bound version. Every other time an object is created, it simply inherits it's version from the parent object that created it. (comments and minor reformatting added by Derek Foreman <derekf@osg.samsung.com>) Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk> Second trivial commit squashed into this one: Authored by Derek Foreman <derekf@osg.samsung.com> Signed-off-by: Derek Foreman <derekf@osg.samsung.com> (it's literally one of code and a lot of comments) This sets wl_display's version (for proxy version query purposes) to 0. Any proxy created with unversioned API (this happens when a client compiled with old headers links against new wayland) will inherit this 0. This gives us a way for new libraries linked by old clients to realize they can't know a proxy's version. wl_display's version being unqueryable (always returning 0) is an acceptable side effect, since it's a special object you can't bind specific versions of anyway. Second half: Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk> Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
2016-01-12scanner: Fail if 'since' is higher than the interface versionJonas Ådahl1-1/+5
If an event or request have a "since" attribute that is larger than the version of the interface it is in, fail with an explaining error message. Signed-off-by: Jonas Ådahl <jadahl@gmail.com> Reviewed-by: Daniel Stone <daniels@collabora.com> Reviewed-by: Marek Chalupa <mchqwerty@gmail.com> Reviewed-by: Derek Foreman <derekf@osg.samsung.com>
2016-01-12scanner: Add missing bracketsJonas Ådahl1-1/+2
A statement was added at the same indentation level as the true branch of the if statement, but since there were no brackets, it would be executed independently of the result of the if condition. Signed-off-by: Jonas Ådahl <jadahl@gmail.com> Reviewed-by: Daniel Stone <daniels@collabora.com> Reviewed-by: Marek Chalupa <mchqwerty@gmail.com> Reviewed-by: Derek Foreman <derekf@osg.samsung.com>
2015-11-17Validate the protocol xml during scanningPeter Hutterer1-0/+71
Embed the wayland.dtd protocol data into the scanner binary so we can validate external protocol files without requiring makefile changes. Hat-tip to Pekka Paalanen for the embedding trick. The embedding trick doesn't work well if the to-be-embedded file is in a different location than the source file, so copy/link it during configure and then build it in from the local directory. The current expat parser is not a validating parser, moving scanner.c to another parser has the risk of breaking compatibility. This patch adds libxml2 as extra (optional) dependency, but that also requires parsing the input twice. If the protocol fails validation a warning is printed but no error is returned otherwise. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2015-11-04scanner: enforce correct argument type for enumsAuke Booij1-0/+69
The scanner now checks whether arguments that have an associated <enum> have the right type. An argument with an enum attribute must be of type int or uint, and if the <enum> with that name has the bitfield attribute set to true, then the argument must be of type uint. Changes since v3: - Remove useless allow_null check - Switch to using bool - Clearer message on errorous input - Minor formatting fix Signed-off-by: Auke Booij <auke@tulcod.com> Reviewed-by: Bryce Harrington <bryce@osg.samsung.com> Reviewed-by: Nils Chr. Brause <nilschrbrause@googlemail.com>
2015-10-26scanner: stop adding trailing whitespace to copyrightJon Cruz1-1/+2
Generated code was unconditionally adding a space to lines in comments for copyright blocks even if the line was blank. Updated to not add trailing whitespace for blank lines. Signed-off-by: Jon A. Cruz <jonc@osg.samsung.com>
2015-10-09scanner: Generate 'since' macros for requests as wellJonas Ådahl1-0/+1
We already generate WL_[INTERFACE]_[REQUEST]_SINCE_VERSION macros for events in the server protocol headers. Lets do the same for requests in the client protocol headers as well. Signed-off-by: Jonas Ådahl <jadahl@gmail.com> Reviewed-by: David FORT <contact@hardening-consulting.com> Reviewed-by: Daniel Stone <daniels@collabora.com>
2015-10-05scanner: Close input resource when done to prevent leakBryce Harrington1-0/+5
Addresses this error reported by Denis Denisov: [src/scanner.c:1415]: (error) Resource leak: input Signed-off-by: Bryce Harrington <bryce@osg.samsung.com> v2: Also close input for other exit points in main. Signed-off-by: Bryce Harrington <bryce@osg.samsung.com> Reviewed-by: Jonas Ådahl <jadahl@gmail.com> Acked-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk> Reviewed-by: David FORT <contact@hardening-consulting.com>
2015-07-30scanner: check sanity of versionMarek Chalupa1-9/+30
scanner does not complain if we put into version attribute things like -1 1x 1:3 etc. Signed-off-by: Marek Chalupa <mchqwerty@gmail.com> Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2015-07-30scanner: use zxallocMarek Chalupa1-43/+40
Use xzalloc instead of xmalloc. This allows us to get rid of manual initializing the memory to 0s and the code is shorter and cleaner Suggested by Bryce Harrington Signed-off-by: Marek Chalupa <mchqwerty@gmail.com> Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2015-07-30scanner: get rid of leaksMarek Chalupa1-4/+102
Free all the memory we have allocated during running. v2.: split creating objects and getting rid of leaks into two patches move check for NULL description into free_description v3.: rebase after previous patch fixes Signed-off-by: Marek Chalupa <mchqwerty@gmail.com> Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2015-07-30scanner: refactor creating objectsMarek Chalupa1-53/+111
wrap creating and initializing objects (structures) into functions and use them in the code. v2. make create_.* functions consistent (no func will return NULL) Signed-off-by: Marek Chalupa <mchqwerty@gmail.com> Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2015-06-12src: Update boilerplate from MIT X11 license to MIT Expat licenseBryce Harrington1-16/+19
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2015-06-01scanner: don't emit the extern declarations for external typesGiulio Camuffo1-7/+3
We were emitting the extern declarations of all types used in the protocol, even if not defined in it. This caused warnings to be produced when using the -Wredundant-decls compiler flag when building an extension that uses e.g. wl_surface. However we only need the extern declarations if the protocol defines a factory for those external interfaces. That is a bad design and can be however done by including the dependent protocol header first. So only emit the extern declarations for the types that the protocol actually defines, this restoring the behavior we were using in 1.7. Fixes https://bugs.freedesktop.org/show_bug.cgi?id=90677 Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk> Tested-by: Arnaud Vrac <rawoul@gmail.com>
2015-05-15remove trailing whitespacesMichael Vetter1-1/+1
Remove trailing whitespaces because they are not needed and jumping to the end of al ine should do just that and not jump to the whitespace.
2015-05-08scanner: simplify the getopt logicPekka Paalanen1-30/+14
Use the same retvals for both short and long options. Whitespace fixes. Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2015-04-30scanner: add a new --include-core-only optionGiulio Camuffo1-59/+149
When using this new option the generated code will include the new core headers instead of the old ones. The default needs to remain unchanged for backward compatibility with old code. With this change the generated headers will now forward declare all types and interfaces it uses; that is needed when generating headers for a my-extension.xml with --include-core-only, since it may use types defined in wayland.xml. The same is done also without --include-core-only, since it is an harmless change. getopt_long() is used for the option handling. Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2015-04-08scanner: Fail on empty enumerationsJonas Ådahl1-0/+4
Without this patch, the scanner would generate invalid C which wouldn't compile anyway, so lets be nice and fail earlier and point out where the error is. Signed-off-by: Jonas Ådahl <jadahl@gmail.com> Reviewed-by: Derek Foreman <derekf@osg.samsung.com> Reviewed-by: David Fort <contact@hardening-consulting.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2015-03-27Add support for direct file reading and writing in wayland-scanner.Jussi Pakkanen1-5/+21
Add support for direct file reading and writing in wayland-scanner. Signed-off-by: Jussi Pakkanen <jpakkane@gmail.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk> Acked-by: David Fort <rdp.effort@gmail.com>
2015-01-27scanner: Fix header generation for server protocolsMariusz Ceier1-1/+1
Server protocols headers should include wayland-server.h, instead of wayland-util.h. Otherwise they're not useable with C++ compiler unless wayland-server.h was included earlier. Signed-off-by: Mariusz Ceier <mceier+wayland@gmail.com> Reviewed-by: Daniel Stone <daniels@collabora.com>
2014-11-28scanner.c: Use WL_PRINTF instead of __attribute__((format(printf)))Seedo Eldho Paul1-1/+1
Signed-off-by: Seedo Eldho Paul <seedoeldhopaul@gmail.com>
2014-11-10scanner, client: Added more error checks when strtol function is usedImran Zaman1-1/+3
Signed-off-by: Imran Zaman <imran.zaman@gmail.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-11-04cosmetic: convert some function returns from int to boolDerek Foreman1-3/+4
[Pekka Paalanen: change is_nullable_type() return value to bool.] Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-09-23scanner: Remove stray newlineJonas Ådahl1-1/+0
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2014-09-23scanner: Improve XML parse error reportingJonas Ådahl1-2/+8
Print the parse error and exit with a failure if expat can't parse the XML. Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2014-08-18scanner: Make emit_structs more explicitJasper St. Pierre1-13/+12
"is_interface" is a really terrible name for the client or server variants, and instead of checking whether we were passed the requests or the events, just pass an argument through. Reviewed-by: Marek Chalupa <mchqwerty@gmail.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-08-18scanner: Use an enum to determine the type of thing we're writing outJasper St. Pierre1-6/+11
Reviewed-by: Marek Chalupa <mchqwerty@gmail.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-05-12scanner: Downgrade non-increasing version error to warningKristian Høgsberg1-1/+1
Commit 99a72777f96f63e4e25dc528bb37115424adac59 introduced a new error for when the 'since' version decreases. It also reset the version for messages without a version to 1. Versioning semantics in the spec files was a little under-specified and we don't want to break projects caught in this grey zone. This commits replaces previous configure.ac as the 1.4.93 tag and the final 1.5 RC.
2014-05-09scanner: Generate macros for getting the 'since' version of an eventJonas Ådahl1-0/+13
This could be useful for compositors who need to be able to not send events if the client bound a version lower than the newest provided. Event version numbers are exposed as [INTERFACE_NAME]_[EVENT_NAME]_SINCE_VERSION for example wl_output.scale will have the version macro WL_OUTPUT_SCALE_SINCE_VERSION. Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2014-05-09scanner: Also fail when an implicitly versioned message is out of orderJonas Ådahl1-4/+6
Fail if a message with version implicitly set to 1 (i.e. not specified) comes after a message with since-version > 1. Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2014-05-06scanner: check wl_array_add resultU. Artie Eoff1-1/+1
Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
2014-04-03scanner: Only output each forward declaration onceKristian Høgsberg1-8/+28
Just sort the types and only print unique type names. We avoid using the GCC pragma.
2014-02-18scanner: Add GCC pragmas to disable -Wredundant-declsJasper St. Pierre1-1/+3
The code very intentionally emits a lot of redundant declarations to simplify the scanner code. Somebody building with -Wredundant-decls would have compile errors, so emit special pragmas to turn those warnings off. These pragmas should be ignored outside of gcc/clang.
2013-12-17scanner: set errno=0 before strtolAdrian Negreanu1-0/+1
POSIX says to set errno=0 before calling strtol since the return value alne cannot tell a failure. on ubuntu armel I get: ../src/wayland-scanner client-header < ../../protocol/wayland.xml > wayland-client-protocol.h <stdin>:1188: error: invalid integer (2) Signed-off-by: Adrian Negreanu <adrian.m.negreanu@intel.com>