aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mesalib/src/mesa/state_tracker/st_manager.c1850
-rw-r--r--xkbcomp/compat.c9
-rw-r--r--xkbcomp/configure.ac124
-rw-r--r--xkbcomp/man/xkbcomp.man3
-rw-r--r--xkbcomp/parseutils.c1691
-rw-r--r--xkbcomp/parseutils.h416
-rw-r--r--xkbcomp/xkbcomp.c2453
-rw-r--r--xkbcomp/xkbcomp.h793
-rw-r--r--xkbcomp/xkbparse.y1564
9 files changed, 4463 insertions, 4440 deletions
diff --git a/mesalib/src/mesa/state_tracker/st_manager.c b/mesalib/src/mesa/state_tracker/st_manager.c
index e126c0a1e..46be55318 100644
--- a/mesalib/src/mesa/state_tracker/st_manager.c
+++ b/mesalib/src/mesa/state_tracker/st_manager.c
@@ -1,923 +1,927 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.9
- *
- * Copyright (C) 2010 LunarG Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- * Chia-I Wu <olv@lunarg.com>
- */
-
-#include "state_tracker/st_gl_api.h"
-
-#include "pipe/p_context.h"
-#include "pipe/p_screen.h"
-#include "util/u_format.h"
-#include "util/u_pointer.h"
-#include "util/u_inlines.h"
-#include "util/u_atomic.h"
-#include "util/u_surface.h"
-
-#include "main/mtypes.h"
-#include "main/context.h"
-#include "main/mfeatures.h"
-#include "main/texobj.h"
-#include "main/teximage.h"
-#include "main/texstate.h"
-#include "main/framebuffer.h"
-#include "main/fbobject.h"
-#include "main/renderbuffer.h"
-#include "main/version.h"
-#include "st_texture.h"
-
-#include "st_context.h"
-#include "st_format.h"
-#include "st_cb_fbo.h"
-#include "st_cb_flush.h"
-#include "st_manager.h"
-
-/**
- * Cast wrapper to convert a struct gl_framebuffer to an st_framebuffer.
- * Return NULL if the struct gl_framebuffer is a user-created framebuffer.
- * We'll only return non-null for window system framebuffers.
- * Note that this function may fail.
- */
-static INLINE struct st_framebuffer *
-st_ws_framebuffer(struct gl_framebuffer *fb)
-{
- /* FBO cannot be casted. See st_new_framebuffer */
- return (struct st_framebuffer *) ((fb && !fb->Name) ? fb : NULL);
-}
-
-/**
- * Map an attachment to a buffer index.
- */
-static INLINE gl_buffer_index
-attachment_to_buffer_index(enum st_attachment_type statt)
-{
- gl_buffer_index index;
-
- switch (statt) {
- case ST_ATTACHMENT_FRONT_LEFT:
- index = BUFFER_FRONT_LEFT;
- break;
- case ST_ATTACHMENT_BACK_LEFT:
- index = BUFFER_BACK_LEFT;
- break;
- case ST_ATTACHMENT_FRONT_RIGHT:
- index = BUFFER_FRONT_RIGHT;
- break;
- case ST_ATTACHMENT_BACK_RIGHT:
- index = BUFFER_BACK_RIGHT;
- break;
- case ST_ATTACHMENT_DEPTH_STENCIL:
- index = BUFFER_DEPTH;
- break;
- case ST_ATTACHMENT_ACCUM:
- index = BUFFER_ACCUM;
- break;
- case ST_ATTACHMENT_SAMPLE:
- default:
- index = BUFFER_COUNT;
- break;
- }
-
- return index;
-}
-
-/**
- * Map a buffer index to an attachment.
- */
-static INLINE enum st_attachment_type
-buffer_index_to_attachment(gl_buffer_index index)
-{
- enum st_attachment_type statt;
-
- switch (index) {
- case BUFFER_FRONT_LEFT:
- statt = ST_ATTACHMENT_FRONT_LEFT;
- break;
- case BUFFER_BACK_LEFT:
- statt = ST_ATTACHMENT_BACK_LEFT;
- break;
- case BUFFER_FRONT_RIGHT:
- statt = ST_ATTACHMENT_FRONT_RIGHT;
- break;
- case BUFFER_BACK_RIGHT:
- statt = ST_ATTACHMENT_BACK_RIGHT;
- break;
- case BUFFER_DEPTH:
- statt = ST_ATTACHMENT_DEPTH_STENCIL;
- break;
- case BUFFER_ACCUM:
- statt = ST_ATTACHMENT_ACCUM;
- break;
- default:
- statt = ST_ATTACHMENT_INVALID;
- break;
- }
-
- return statt;
-}
-
-/**
- * Validate a framebuffer to make sure up-to-date pipe_textures are used.
- */
-static void
-st_framebuffer_validate(struct st_framebuffer *stfb, struct st_context *st)
-{
- struct pipe_context *pipe = st->pipe;
- struct pipe_resource *textures[ST_ATTACHMENT_COUNT];
- uint width, height;
- unsigned i;
- boolean changed = FALSE;
-
- if (!p_atomic_read(&stfb->revalidate))
- return;
-
- /* validate the fb */
- if (!stfb->iface->validate(stfb->iface, stfb->statts, stfb->num_statts, textures))
- return;
-
- width = stfb->Base.Width;
- height = stfb->Base.Height;
-
- for (i = 0; i < stfb->num_statts; i++) {
- struct st_renderbuffer *strb;
- struct pipe_surface *ps, surf_tmpl;
- gl_buffer_index idx;
-
- if (!textures[i])
- continue;
-
- idx = attachment_to_buffer_index(stfb->statts[i]);
- if (idx >= BUFFER_COUNT) {
- pipe_resource_reference(&textures[i], NULL);
- continue;
- }
-
- strb = st_renderbuffer(stfb->Base.Attachment[idx].Renderbuffer);
- assert(strb);
- if (strb->texture == textures[i]) {
- pipe_resource_reference(&textures[i], NULL);
- continue;
- }
-
- memset(&surf_tmpl, 0, sizeof(surf_tmpl));
- u_surface_default_template(&surf_tmpl, textures[i],
- PIPE_BIND_RENDER_TARGET);
- ps = pipe->create_surface(pipe, textures[i], &surf_tmpl);
- if (ps) {
- pipe_surface_reference(&strb->surface, ps);
- pipe_resource_reference(&strb->texture, ps->texture);
- /* ownership transfered */
- pipe_surface_reference(&ps, NULL);
-
- changed = TRUE;
-
- strb->Base.Width = strb->surface->width;
- strb->Base.Height = strb->surface->height;
-
- width = strb->Base.Width;
- height = strb->Base.Height;
- }
-
- pipe_resource_reference(&textures[i], NULL);
- }
-
- if (changed) {
- st->dirty.st |= ST_NEW_FRAMEBUFFER;
- _mesa_resize_framebuffer(st->ctx, &stfb->Base, width, height);
-
- assert(stfb->Base.Width == width);
- assert(stfb->Base.Height == height);
- }
-
- p_atomic_set(&stfb->revalidate, FALSE);
-}
-
-/**
- * Update the attachments to validate by looping the existing renderbuffers.
- */
-static void
-st_framebuffer_update_attachments(struct st_framebuffer *stfb)
-{
- gl_buffer_index idx;
-
- stfb->num_statts = 0;
- for (idx = 0; idx < BUFFER_COUNT; idx++) {
- struct st_renderbuffer *strb;
- enum st_attachment_type statt;
-
- strb = st_renderbuffer(stfb->Base.Attachment[idx].Renderbuffer);
- if (!strb || strb->software)
- continue;
-
- statt = buffer_index_to_attachment(idx);
- if (statt != ST_ATTACHMENT_INVALID &&
- st_visual_have_buffers(stfb->iface->visual, 1 << statt))
- stfb->statts[stfb->num_statts++] = statt;
- }
-
- p_atomic_set(&stfb->revalidate, TRUE);
-}
-
-/**
- * Add a renderbuffer to the framebuffer.
- */
-static boolean
-st_framebuffer_add_renderbuffer(struct st_framebuffer *stfb,
- gl_buffer_index idx)
-{
- struct gl_renderbuffer *rb;
- enum pipe_format format;
- int samples;
- boolean sw;
-
- if (!stfb->iface)
- return FALSE;
-
- /* do not distinguish depth/stencil buffers */
- if (idx == BUFFER_STENCIL)
- idx = BUFFER_DEPTH;
-
- switch (idx) {
- case BUFFER_DEPTH:
- format = stfb->iface->visual->depth_stencil_format;
- sw = FALSE;
- break;
- case BUFFER_ACCUM:
- format = stfb->iface->visual->accum_format;
- sw = TRUE;
- break;
- default:
- format = stfb->iface->visual->color_format;
- sw = FALSE;
- break;
- }
-
- if (format == PIPE_FORMAT_NONE)
- return FALSE;
-
- samples = stfb->iface->visual->samples;
- if (!samples)
- samples = st_get_msaa();
-
- rb = st_new_renderbuffer_fb(format, samples, sw);
- if (!rb)
- return FALSE;
-
- if (idx != BUFFER_DEPTH) {
- _mesa_add_renderbuffer(&stfb->Base, idx, rb);
- }
- else {
- if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_ZS, 0))
- _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, rb);
- if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_ZS, 1))
- _mesa_add_renderbuffer(&stfb->Base, BUFFER_STENCIL, rb);
- }
-
- return TRUE;
-}
-
-/**
- * Intialize a struct gl_config from a visual.
- */
-static void
-st_visual_to_context_mode(const struct st_visual *visual,
- struct gl_config *mode)
-{
- memset(mode, 0, sizeof(*mode));
-
- if (st_visual_have_buffers(visual, ST_ATTACHMENT_BACK_LEFT_MASK))
- mode->doubleBufferMode = GL_TRUE;
- if (st_visual_have_buffers(visual,
- ST_ATTACHMENT_FRONT_RIGHT_MASK | ST_ATTACHMENT_BACK_RIGHT_MASK))
- mode->stereoMode = GL_TRUE;
-
- if (visual->color_format != PIPE_FORMAT_NONE) {
- mode->rgbMode = GL_TRUE;
-
- mode->redBits =
- util_format_get_component_bits(visual->color_format,
- UTIL_FORMAT_COLORSPACE_RGB, 0);
- mode->greenBits =
- util_format_get_component_bits(visual->color_format,
- UTIL_FORMAT_COLORSPACE_RGB, 1);
- mode->blueBits =
- util_format_get_component_bits(visual->color_format,
- UTIL_FORMAT_COLORSPACE_RGB, 2);
- mode->alphaBits =
- util_format_get_component_bits(visual->color_format,
- UTIL_FORMAT_COLORSPACE_RGB, 3);
-
- mode->rgbBits = mode->redBits +
- mode->greenBits + mode->blueBits + mode->alphaBits;
- }
-
- if (visual->depth_stencil_format != PIPE_FORMAT_NONE) {
- mode->depthBits =
- util_format_get_component_bits(visual->depth_stencil_format,
- UTIL_FORMAT_COLORSPACE_ZS, 0);
- mode->stencilBits =
- util_format_get_component_bits(visual->depth_stencil_format,
- UTIL_FORMAT_COLORSPACE_ZS, 1);
-
- mode->haveDepthBuffer = mode->depthBits > 0;
- mode->haveStencilBuffer = mode->stencilBits > 0;
- }
-
- if (visual->accum_format != PIPE_FORMAT_NONE) {
- mode->haveAccumBuffer = GL_TRUE;
-
- mode->accumRedBits =
- util_format_get_component_bits(visual->accum_format,
- UTIL_FORMAT_COLORSPACE_RGB, 0);
- mode->accumGreenBits =
- util_format_get_component_bits(visual->accum_format,
- UTIL_FORMAT_COLORSPACE_RGB, 1);
- mode->accumBlueBits =
- util_format_get_component_bits(visual->accum_format,
- UTIL_FORMAT_COLORSPACE_RGB, 2);
- mode->accumAlphaBits =
- util_format_get_component_bits(visual->accum_format,
- UTIL_FORMAT_COLORSPACE_RGB, 3);
- }
-
- if (visual->samples) {
- mode->sampleBuffers = 1;
- mode->samples = visual->samples;
- }
-}
-
-/**
- * Determine the default draw or read buffer from a visual.
- */
-static void
-st_visual_to_default_buffer(const struct st_visual *visual,
- GLenum *buffer, GLint *index)
-{
- enum st_attachment_type statt;
- GLenum buf;
- gl_buffer_index idx;
-
- statt = visual->render_buffer;
- /* do nothing if an invalid render buffer is specified */
- if (statt == ST_ATTACHMENT_INVALID ||
- !st_visual_have_buffers(visual, 1 << statt))
- return;
-
- switch (statt) {
- case ST_ATTACHMENT_FRONT_LEFT:
- buf = GL_FRONT_LEFT;
- idx = BUFFER_FRONT_LEFT;
- break;
- case ST_ATTACHMENT_BACK_LEFT:
- buf = GL_BACK_LEFT;
- idx = BUFFER_BACK_LEFT;
- break;
- case ST_ATTACHMENT_FRONT_RIGHT:
- buf = GL_FRONT_RIGHT;
- idx = BUFFER_FRONT_RIGHT;
- break;
- case ST_ATTACHMENT_BACK_RIGHT:
- buf = GL_BACK_RIGHT;
- idx = BUFFER_BACK_RIGHT;
- break;
- default:
- buf = GL_NONE;
- idx = BUFFER_COUNT;
- break;
- }
-
- if (buf != GL_NONE) {
- if (buffer)
- *buffer = buf;
- if (index)
- *index = idx;
- }
-}
-
-/**
- * Create a framebuffer from a manager interface.
- */
-static struct st_framebuffer *
-st_framebuffer_create(struct st_framebuffer_iface *stfbi)
-{
- struct st_framebuffer *stfb;
- struct gl_config mode;
- gl_buffer_index idx;
-
- if (!stfbi)
- return NULL;
-
- stfb = CALLOC_STRUCT(st_framebuffer);
- if (!stfb)
- return NULL;
-
- st_visual_to_context_mode(stfbi->visual, &mode);
- _mesa_initialize_window_framebuffer(&stfb->Base, &mode);
-
- /* modify the draw/read buffers of the fb */
- st_visual_to_default_buffer(stfbi->visual, &stfb->Base.ColorDrawBuffer[0],
- &stfb->Base._ColorDrawBufferIndexes[0]);
- st_visual_to_default_buffer(stfbi->visual, &stfb->Base.ColorReadBuffer,
- &stfb->Base._ColorReadBufferIndex);
-
- stfb->iface = stfbi;
-
- /* add the color buffer */
- idx = stfb->Base._ColorDrawBufferIndexes[0];
- if (!st_framebuffer_add_renderbuffer(stfb, idx)) {
- FREE(stfb);
- return NULL;
- }
-
- st_framebuffer_add_renderbuffer(stfb, BUFFER_DEPTH);
- st_framebuffer_add_renderbuffer(stfb, BUFFER_ACCUM);
-
- st_framebuffer_update_attachments(stfb);
-
- stfb->Base.Initialized = GL_TRUE;
-
- return stfb;
-}
-
-/**
- * Reference a framebuffer.
- */
-static void
-st_framebuffer_reference(struct st_framebuffer **ptr,
- struct st_framebuffer *stfb)
-{
- struct gl_framebuffer *fb = &stfb->Base;
- _mesa_reference_framebuffer((struct gl_framebuffer **) ptr, fb);
-}
-
-static void
-st_context_notify_invalid_framebuffer(struct st_context_iface *stctxi,
- struct st_framebuffer_iface *stfbi)
-{
- struct st_context *st = (struct st_context *) stctxi;
- struct st_framebuffer *stfb;
-
- /* either draw or read winsys fb */
- stfb = st_ws_framebuffer(st->ctx->WinSysDrawBuffer);
- if (!stfb || stfb->iface != stfbi)
- stfb = st_ws_framebuffer(st->ctx->WinSysReadBuffer);
-
- if (stfb && stfb->iface == stfbi) {
- p_atomic_set(&stfb->revalidate, TRUE);
- }
- else {
- /* This function is probably getting called when we've detected a
- * change in a window's size but the currently bound context is
- * not bound to that window.
- * If the st_framebuffer_iface structure had a pointer to the
- * corresponding st_framebuffer we'd be able to handle this.
- */
- }
-}
-
-static void
-st_context_flush(struct st_context_iface *stctxi, unsigned flags,
- struct pipe_fence_handle **fence)
-{
- struct st_context *st = (struct st_context *) stctxi;
- st_flush(st, fence);
- if (flags & ST_FLUSH_FRONT)
- st_manager_flush_frontbuffer(st);
-}
-
-static boolean
-st_context_teximage(struct st_context_iface *stctxi,
- enum st_texture_type target,
- int level, enum pipe_format internal_format,
- struct pipe_resource *tex, boolean mipmap)
-{
- struct st_context *st = (struct st_context *) stctxi;
- struct gl_context *ctx = st->ctx;
- struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
- struct gl_texture_object *texObj;
- struct gl_texture_image *texImage;
- struct st_texture_object *stObj;
- struct st_texture_image *stImage;
- GLenum internalFormat;
- GLuint width, height, depth;
-
- switch (target) {
- case ST_TEXTURE_1D:
- target = GL_TEXTURE_1D;
- break;
- case ST_TEXTURE_2D:
- target = GL_TEXTURE_2D;
- break;
- case ST_TEXTURE_3D:
- target = GL_TEXTURE_3D;
- break;
- case ST_TEXTURE_RECT:
- target = GL_TEXTURE_RECTANGLE_ARB;
- break;
- default:
- return FALSE;
- break;
- }
-
- texObj = _mesa_select_tex_object(ctx, texUnit, target);
- _mesa_lock_texture(ctx, texObj);
-
- stObj = st_texture_object(texObj);
- /* switch to surface based */
- if (!stObj->surface_based) {
- _mesa_clear_texture_object(ctx, texObj);
- stObj->surface_based = GL_TRUE;
- }
-
- texImage = _mesa_get_tex_image(ctx, texObj, target, level);
- stImage = st_texture_image(texImage);
- if (tex) {
- gl_format texFormat;
-
- /*
- * XXX When internal_format and tex->format differ, st_finalize_texture
- * needs to allocate a new texture with internal_format and copy the
- * texture here into the new one. It will result in surface_copy being
- * called on surfaces whose formats differ.
- *
- * To avoid that, internal_format is (wrongly) ignored here. A sane fix
- * is to use a sampler view.
- */
- if (!st_sampler_compat_formats(tex->format, internal_format))
- internal_format = tex->format;
-
- if (util_format_get_component_bits(internal_format,
- UTIL_FORMAT_COLORSPACE_RGB, 3) > 0)
- internalFormat = GL_RGBA;
- else
- internalFormat = GL_RGB;
-
- texFormat = st_ChooseTextureFormat(ctx, internalFormat,
- GL_RGBA, GL_UNSIGNED_BYTE);
-
- _mesa_init_teximage_fields(ctx, target, texImage,
- tex->width0, tex->height0, 1, 0,
- internalFormat, texFormat);
-
- width = tex->width0;
- height = tex->height0;
- depth = tex->depth0;
-
- /* grow the image size until we hit level = 0 */
- while (level > 0) {
- if (width != 1)
- width <<= 1;
- if (height != 1)
- height <<= 1;
- if (depth != 1)
- depth <<= 1;
- level--;
- }
- }
- else {
- _mesa_clear_texture_image(ctx, texImage);
- width = height = depth = 0;
- }
-
- pipe_resource_reference(&stImage->pt, tex);
- stObj->width0 = width;
- stObj->height0 = height;
- stObj->depth0 = depth;
-
- _mesa_dirty_texobj(ctx, texObj, GL_TRUE);
- _mesa_unlock_texture(ctx, texObj);
-
- return TRUE;
-}
-
-static void
-st_context_copy(struct st_context_iface *stctxi,
- struct st_context_iface *stsrci, unsigned mask)
-{
- struct st_context *st = (struct st_context *) stctxi;
- struct st_context *src = (struct st_context *) stsrci;
-
- _mesa_copy_context(src->ctx, st->ctx, mask);
-}
-
-static boolean
-st_context_share(struct st_context_iface *stctxi,
- struct st_context_iface *stsrci)
-{
- struct st_context *st = (struct st_context *) stctxi;
- struct st_context *src = (struct st_context *) stsrci;
-
- return _mesa_share_state(st->ctx, src->ctx);
-}
-
-static void
-st_context_destroy(struct st_context_iface *stctxi)
-{
- struct st_context *st = (struct st_context *) stctxi;
- st_destroy_context(st);
-}
-
-static struct st_context_iface *
-st_api_create_context(struct st_api *stapi, struct st_manager *smapi,
- const struct st_context_attribs *attribs,
- struct st_context_iface *shared_stctxi)
-{
- struct st_context *shared_ctx = (struct st_context *) shared_stctxi;
- struct st_context *st;
- struct pipe_context *pipe;
- struct gl_config mode;
- gl_api api;
-
- if (!(stapi->profile_mask & (1 << attribs->profile)))
- return NULL;
-
- switch (attribs->profile) {
- case ST_PROFILE_DEFAULT:
- api = API_OPENGL;
- break;
- case ST_PROFILE_OPENGL_ES1:
- api = API_OPENGLES;
- break;
- case ST_PROFILE_OPENGL_ES2:
- api = API_OPENGLES2;
- break;
- case ST_PROFILE_OPENGL_CORE:
- default:
- return NULL;
- break;
- }
-
- pipe = smapi->screen->context_create(smapi->screen, NULL);
- if (!pipe)
- return NULL;
-
- st_visual_to_context_mode(&attribs->visual, &mode);
- st = st_create_context(api, pipe, &mode, shared_ctx);
- if (!st) {
- pipe->destroy(pipe);
- return NULL;
- }
-
- /* need to perform version check */
- if (attribs->major > 1 || attribs->minor > 0) {
- _mesa_compute_version(st->ctx);
-
- /* is the actual version less than the requested version? */
- if (st->ctx->VersionMajor * 10 + st->ctx->VersionMinor <
- attribs->major * 10 + attribs->minor) {
- st_destroy_context(st);
- return NULL;
- }
- }
-
- st->invalidate_on_gl_viewport =
- smapi->get_param(smapi, ST_MANAGER_BROKEN_INVALIDATE);
-
- st->iface.destroy = st_context_destroy;
- st->iface.notify_invalid_framebuffer =
- st_context_notify_invalid_framebuffer;
- st->iface.flush = st_context_flush;
- st->iface.teximage = st_context_teximage;
- st->iface.copy = st_context_copy;
- st->iface.share = st_context_share;
- st->iface.st_context_private = (void *) smapi;
-
- return &st->iface;
-}
-
-static boolean
-st_api_make_current(struct st_api *stapi, struct st_context_iface *stctxi,
- struct st_framebuffer_iface *stdrawi,
- struct st_framebuffer_iface *streadi)
-{
- struct st_context *st = (struct st_context *) stctxi;
- struct st_framebuffer *stdraw, *stread, *stfb;
- boolean ret;
-
- _glapi_check_multithread();
-
- if (st) {
- /* reuse/create the draw fb */
- stfb = st_ws_framebuffer(st->ctx->WinSysDrawBuffer);
- if (stfb && stfb->iface == stdrawi) {
- stdraw = NULL;
- st_framebuffer_reference(&stdraw, stfb);
- }
- else {
- stdraw = st_framebuffer_create(stdrawi);
- }
-
- /* reuse/create the read fb */
- stfb = st_ws_framebuffer(st->ctx->WinSysReadBuffer);
- if (!stfb || stfb->iface != streadi)
- stfb = stdraw;
- if (stfb && stfb->iface == streadi) {
- stread = NULL;
- st_framebuffer_reference(&stread, stfb);
- }
- else {
- stread = st_framebuffer_create(streadi);
- }
-
- if (stdraw && stread) {
- st_framebuffer_validate(stdraw, st);
- if (stread != stdraw)
- st_framebuffer_validate(stread, st);
-
- /* modify the draw/read buffers of the context */
- if (stdraw->iface) {
- st_visual_to_default_buffer(stdraw->iface->visual,
- &st->ctx->Color.DrawBuffer[0], NULL);
- }
- if (stread->iface) {
- st_visual_to_default_buffer(stread->iface->visual,
- &st->ctx->Pixel.ReadBuffer, NULL);
- }
-
- ret = _mesa_make_current(st->ctx, &stdraw->Base, &stread->Base);
- }
- else {
- struct gl_framebuffer *incomplete = _mesa_get_incomplete_framebuffer();
- ret = _mesa_make_current(st->ctx, incomplete, incomplete);
- }
-
- st_framebuffer_reference(&stdraw, NULL);
- st_framebuffer_reference(&stread, NULL);
- }
- else {
- ret = _mesa_make_current(NULL, NULL, NULL);
- }
-
- return ret;
-}
-
-static struct st_context_iface *
-st_api_get_current(struct st_api *stapi)
-{
- GET_CURRENT_CONTEXT(ctx);
- struct st_context *st = (ctx) ? ctx->st : NULL;
-
- return (st) ? &st->iface : NULL;
-}
-
-static st_proc_t
-st_api_get_proc_address(struct st_api *stapi, const char *procname)
-{
- return (st_proc_t) _glapi_get_proc_address(procname);
-}
-
-static void
-st_api_destroy(struct st_api *stapi)
-{
-}
-
-/**
- * Flush the front buffer if the current context renders to the front buffer.
- */
-void
-st_manager_flush_frontbuffer(struct st_context *st)
-{
- struct st_framebuffer *stfb = st_ws_framebuffer(st->ctx->DrawBuffer);
- struct st_renderbuffer *strb = NULL;
-
- if (stfb)
- strb = st_renderbuffer(stfb->Base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer);
- if (!strb)
- return;
-
- /* never a dummy fb */
- assert(stfb->iface);
- stfb->iface->flush_front(stfb->iface, ST_ATTACHMENT_FRONT_LEFT);
-}
-
-/**
- * Return the surface of an EGLImage.
- * FIXME: I think this should operate on resources, not surfaces
- */
-struct pipe_surface *
-st_manager_get_egl_image_surface(struct st_context *st,
- void *eglimg, unsigned usage)
-{
- struct st_manager *smapi =
- (struct st_manager *) st->iface.st_context_private;
- struct st_egl_image stimg;
- struct pipe_surface *ps, surf_tmpl;
-
- if (!smapi || !smapi->get_egl_image)
- return NULL;
-
- memset(&stimg, 0, sizeof(stimg));
- if (!smapi->get_egl_image(smapi, eglimg, &stimg))
- return NULL;
-
- memset(&surf_tmpl, 0, sizeof(surf_tmpl));
- surf_tmpl.format = stimg.texture->format;
- surf_tmpl.usage = usage;
- surf_tmpl.u.tex.level = stimg.level;
- surf_tmpl.u.tex.first_layer = stimg.layer;
- surf_tmpl.u.tex.last_layer = stimg.layer;
- ps = st->pipe->create_surface(st->pipe, stimg.texture, &surf_tmpl);
- pipe_resource_reference(&stimg.texture, NULL);
-
- return ps;
-}
-
-/**
- * Re-validate the framebuffers.
- */
-void
-st_manager_validate_framebuffers(struct st_context *st)
-{
- struct st_framebuffer *stdraw = st_ws_framebuffer(st->ctx->DrawBuffer);
- struct st_framebuffer *stread = st_ws_framebuffer(st->ctx->ReadBuffer);
-
- if (stdraw)
- st_framebuffer_validate(stdraw, st);
- if (stread && stread != stdraw)
- st_framebuffer_validate(stread, st);
-}
-
-/**
- * Add a color renderbuffer on demand.
- */
-boolean
-st_manager_add_color_renderbuffer(struct st_context *st,
- struct gl_framebuffer *fb,
- gl_buffer_index idx)
-{
- struct st_framebuffer *stfb = st_ws_framebuffer(fb);
-
- /* FBO */
- if (!stfb)
- return FALSE;
-
- if (stfb->Base.Attachment[idx].Renderbuffer)
- return TRUE;
-
- switch (idx) {
- case BUFFER_FRONT_LEFT:
- case BUFFER_BACK_LEFT:
- case BUFFER_FRONT_RIGHT:
- case BUFFER_BACK_RIGHT:
- break;
- default:
- return FALSE;
- break;
- }
-
- if (!st_framebuffer_add_renderbuffer(stfb, idx))
- return FALSE;
-
- st_framebuffer_update_attachments(stfb);
- st_invalidate_state(st->ctx, _NEW_BUFFERS);
-
- return TRUE;
-}
-
-static const struct st_api st_gl_api = {
- "Mesa " MESA_VERSION_STRING,
- ST_API_OPENGL,
-#if FEATURE_GL
- ST_PROFILE_DEFAULT_MASK |
-#endif
-#if FEATURE_ES1
- ST_PROFILE_OPENGL_ES1_MASK |
-#endif
-#if FEATURE_ES2
- ST_PROFILE_OPENGL_ES2_MASK |
-#endif
- 0,
- st_api_destroy,
- st_api_get_proc_address,
- st_api_create_context,
- st_api_make_current,
- st_api_get_current,
-};
-
-struct st_api *
-st_gl_api_create(void)
-{
- return (struct st_api *) &st_gl_api;
-}
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.9
+ *
+ * Copyright (C) 2010 LunarG Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Chia-I Wu <olv@lunarg.com>
+ */
+
+#include "state_tracker/st_gl_api.h"
+
+#include "pipe/p_context.h"
+#include "pipe/p_screen.h"
+#include "util/u_format.h"
+#include "util/u_pointer.h"
+#include "util/u_inlines.h"
+#include "util/u_atomic.h"
+#include "util/u_surface.h"
+
+#include "main/mtypes.h"
+#include "main/context.h"
+#include "main/mfeatures.h"
+#include "main/texobj.h"
+#include "main/teximage.h"
+#include "main/texstate.h"
+#include "main/framebuffer.h"
+#include "main/fbobject.h"
+#include "main/renderbuffer.h"
+#include "main/version.h"
+#include "st_texture.h"
+
+#include "st_context.h"
+#include "st_format.h"
+#include "st_cb_fbo.h"
+#include "st_cb_flush.h"
+#include "st_manager.h"
+
+/**
+ * Cast wrapper to convert a struct gl_framebuffer to an st_framebuffer.
+ * Return NULL if the struct gl_framebuffer is a user-created framebuffer.
+ * We'll only return non-null for window system framebuffers.
+ * Note that this function may fail.
+ */
+static INLINE struct st_framebuffer *
+st_ws_framebuffer(struct gl_framebuffer *fb)
+{
+ /* FBO cannot be casted. See st_new_framebuffer */
+ return (struct st_framebuffer *) ((fb && !fb->Name) ? fb : NULL);
+}
+
+/**
+ * Map an attachment to a buffer index.
+ */
+static INLINE gl_buffer_index
+attachment_to_buffer_index(enum st_attachment_type statt)
+{
+ gl_buffer_index index;
+
+ switch (statt) {
+ case ST_ATTACHMENT_FRONT_LEFT:
+ index = BUFFER_FRONT_LEFT;
+ break;
+ case ST_ATTACHMENT_BACK_LEFT:
+ index = BUFFER_BACK_LEFT;
+ break;
+ case ST_ATTACHMENT_FRONT_RIGHT:
+ index = BUFFER_FRONT_RIGHT;
+ break;
+ case ST_ATTACHMENT_BACK_RIGHT:
+ index = BUFFER_BACK_RIGHT;
+ break;
+ case ST_ATTACHMENT_DEPTH_STENCIL:
+ index = BUFFER_DEPTH;
+ break;
+ case ST_ATTACHMENT_ACCUM:
+ index = BUFFER_ACCUM;
+ break;
+ case ST_ATTACHMENT_SAMPLE:
+ default:
+ index = BUFFER_COUNT;
+ break;
+ }
+
+ return index;
+}
+
+/**
+ * Map a buffer index to an attachment.
+ */
+static INLINE enum st_attachment_type
+buffer_index_to_attachment(gl_buffer_index index)
+{
+ enum st_attachment_type statt;
+
+ switch (index) {
+ case BUFFER_FRONT_LEFT:
+ statt = ST_ATTACHMENT_FRONT_LEFT;
+ break;
+ case BUFFER_BACK_LEFT:
+ statt = ST_ATTACHMENT_BACK_LEFT;
+ break;
+ case BUFFER_FRONT_RIGHT:
+ statt = ST_ATTACHMENT_FRONT_RIGHT;
+ break;
+ case BUFFER_BACK_RIGHT:
+ statt = ST_ATTACHMENT_BACK_RIGHT;
+ break;
+ case BUFFER_DEPTH:
+ statt = ST_ATTACHMENT_DEPTH_STENCIL;
+ break;
+ case BUFFER_ACCUM:
+ statt = ST_ATTACHMENT_ACCUM;
+ break;
+ default:
+ statt = ST_ATTACHMENT_INVALID;
+ break;
+ }
+
+ return statt;
+}
+
+/**
+ * Validate a framebuffer to make sure up-to-date pipe_textures are used.
+ */
+static void
+st_framebuffer_validate(struct st_framebuffer *stfb, struct st_context *st)
+{
+ struct pipe_context *pipe = st->pipe;
+ struct pipe_resource *textures[ST_ATTACHMENT_COUNT];
+ uint width, height;
+ unsigned i;
+ boolean changed = FALSE;
+
+ if (!p_atomic_read(&stfb->revalidate))
+ return;
+
+ /* validate the fb */
+ if (!stfb->iface->validate(stfb->iface, stfb->statts, stfb->num_statts, textures))
+ return;
+
+ width = stfb->Base.Width;
+ height = stfb->Base.Height;
+
+ for (i = 0; i < stfb->num_statts; i++) {
+ struct st_renderbuffer *strb;
+ struct pipe_surface *ps, surf_tmpl;
+ gl_buffer_index idx;
+
+ if (!textures[i])
+ continue;
+
+ idx = attachment_to_buffer_index(stfb->statts[i]);
+ if (idx >= BUFFER_COUNT) {
+ pipe_resource_reference(&textures[i], NULL);
+ continue;
+ }
+
+ strb = st_renderbuffer(stfb->Base.Attachment[idx].Renderbuffer);
+ assert(strb);
+ if (strb->texture == textures[i]) {
+ pipe_resource_reference(&textures[i], NULL);
+ continue;
+ }
+
+ memset(&surf_tmpl, 0, sizeof(surf_tmpl));
+ u_surface_default_template(&surf_tmpl, textures[i],
+ PIPE_BIND_RENDER_TARGET);
+ ps = pipe->create_surface(pipe, textures[i], &surf_tmpl);
+ if (ps) {
+ pipe_surface_reference(&strb->surface, ps);
+ pipe_resource_reference(&strb->texture, ps->texture);
+ /* ownership transfered */
+ pipe_surface_reference(&ps, NULL);
+
+ changed = TRUE;
+
+ strb->Base.Width = strb->surface->width;
+ strb->Base.Height = strb->surface->height;
+
+ width = strb->Base.Width;
+ height = strb->Base.Height;
+ }
+
+ pipe_resource_reference(&textures[i], NULL);
+ }
+
+ if (changed) {
+ st->dirty.st |= ST_NEW_FRAMEBUFFER;
+ _mesa_resize_framebuffer(st->ctx, &stfb->Base, width, height);
+
+ assert(stfb->Base.Width == width);
+ assert(stfb->Base.Height == height);
+ }
+
+ p_atomic_set(&stfb->revalidate, FALSE);
+}
+
+/**
+ * Update the attachments to validate by looping the existing renderbuffers.
+ */
+static void
+st_framebuffer_update_attachments(struct st_framebuffer *stfb)
+{
+ gl_buffer_index idx;
+
+ stfb->num_statts = 0;
+ for (idx = 0; idx < BUFFER_COUNT; idx++) {
+ struct st_renderbuffer *strb;
+ enum st_attachment_type statt;
+
+ strb = st_renderbuffer(stfb->Base.Attachment[idx].Renderbuffer);
+ if (!strb || strb->software)
+ continue;
+
+ statt = buffer_index_to_attachment(idx);
+ if (statt != ST_ATTACHMENT_INVALID &&
+ st_visual_have_buffers(stfb->iface->visual, 1 << statt))
+ stfb->statts[stfb->num_statts++] = statt;
+ }
+
+ p_atomic_set(&stfb->revalidate, TRUE);
+}
+
+/**
+ * Add a renderbuffer to the framebuffer.
+ */
+static boolean
+st_framebuffer_add_renderbuffer(struct st_framebuffer *stfb,
+ gl_buffer_index idx)
+{
+ struct gl_renderbuffer *rb;
+ enum pipe_format format;
+ int samples;
+ boolean sw;
+
+ if (!stfb->iface)
+ return FALSE;
+
+ /* do not distinguish depth/stencil buffers */
+ if (idx == BUFFER_STENCIL)
+ idx = BUFFER_DEPTH;
+
+ switch (idx) {
+ case BUFFER_DEPTH:
+ format = stfb->iface->visual->depth_stencil_format;
+ sw = FALSE;
+ break;
+ case BUFFER_ACCUM:
+ format = stfb->iface->visual->accum_format;
+ sw = TRUE;
+ break;
+ default:
+ format = stfb->iface->visual->color_format;
+ sw = FALSE;
+ break;
+ }
+
+ if (format == PIPE_FORMAT_NONE)
+ return FALSE;
+
+ samples = stfb->iface->visual->samples;
+ if (!samples)
+ samples = st_get_msaa();
+
+ rb = st_new_renderbuffer_fb(format, samples, sw);
+ if (!rb)
+ return FALSE;
+
+ if (idx != BUFFER_DEPTH) {
+ _mesa_add_renderbuffer(&stfb->Base, idx, rb);
+ }
+ else {
+ if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_ZS, 0))
+ _mesa_add_renderbuffer(&stfb->Base, BUFFER_DEPTH, rb);
+ if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_ZS, 1))
+ _mesa_add_renderbuffer(&stfb->Base, BUFFER_STENCIL, rb);
+ }
+
+ return TRUE;
+}
+
+/**
+ * Intialize a struct gl_config from a visual.
+ */
+static void
+st_visual_to_context_mode(const struct st_visual *visual,
+ struct gl_config *mode)
+{
+ memset(mode, 0, sizeof(*mode));
+
+ if (st_visual_have_buffers(visual, ST_ATTACHMENT_BACK_LEFT_MASK))
+ mode->doubleBufferMode = GL_TRUE;
+ if (st_visual_have_buffers(visual,
+ ST_ATTACHMENT_FRONT_RIGHT_MASK | ST_ATTACHMENT_BACK_RIGHT_MASK))
+ mode->stereoMode = GL_TRUE;
+
+ if (visual->color_format != PIPE_FORMAT_NONE) {
+ mode->rgbMode = GL_TRUE;
+
+ mode->redBits =
+ util_format_get_component_bits(visual->color_format,
+ UTIL_FORMAT_COLORSPACE_RGB, 0);
+ mode->greenBits =
+ util_format_get_component_bits(visual->color_format,
+ UTIL_FORMAT_COLORSPACE_RGB, 1);
+ mode->blueBits =
+ util_format_get_component_bits(visual->color_format,
+ UTIL_FORMAT_COLORSPACE_RGB, 2);
+ mode->alphaBits =
+ util_format_get_component_bits(visual->color_format,
+ UTIL_FORMAT_COLORSPACE_RGB, 3);
+
+ mode->rgbBits = mode->redBits +
+ mode->greenBits + mode->blueBits + mode->alphaBits;
+ }
+
+ if (visual->depth_stencil_format != PIPE_FORMAT_NONE) {
+ mode->depthBits =
+ util_format_get_component_bits(visual->depth_stencil_format,
+ UTIL_FORMAT_COLORSPACE_ZS, 0);
+ mode->stencilBits =
+ util_format_get_component_bits(visual->depth_stencil_format,
+ UTIL_FORMAT_COLORSPACE_ZS, 1);
+
+ mode->haveDepthBuffer = mode->depthBits > 0;
+ mode->haveStencilBuffer = mode->stencilBits > 0;
+ }
+
+ if (visual->accum_format != PIPE_FORMAT_NONE) {
+ mode->haveAccumBuffer = GL_TRUE;
+
+ mode->accumRedBits =
+ util_format_get_component_bits(visual->accum_format,
+ UTIL_FORMAT_COLORSPACE_RGB, 0);
+ mode->accumGreenBits =
+ util_format_get_component_bits(visual->accum_format,
+ UTIL_FORMAT_COLORSPACE_RGB, 1);
+ mode->accumBlueBits =
+ util_format_get_component_bits(visual->accum_format,
+ UTIL_FORMAT_COLORSPACE_RGB, 2);
+ mode->accumAlphaBits =
+ util_format_get_component_bits(visual->accum_format,
+ UTIL_FORMAT_COLORSPACE_RGB, 3);
+ }
+
+ if (visual->samples) {
+ mode->sampleBuffers = 1;
+ mode->samples = visual->samples;
+ }
+}
+
+/**
+ * Determine the default draw or read buffer from a visual.
+ */
+static void
+st_visual_to_default_buffer(const struct st_visual *visual,
+ GLenum *buffer, GLint *index)
+{
+ enum st_attachment_type statt;
+ GLenum buf;
+ gl_buffer_index idx;
+
+ statt = visual->render_buffer;
+ /* do nothing if an invalid render buffer is specified */
+ if (statt == ST_ATTACHMENT_INVALID ||
+ !st_visual_have_buffers(visual, 1 << statt))
+ return;
+
+ switch (statt) {
+ case ST_ATTACHMENT_FRONT_LEFT:
+ buf = GL_FRONT_LEFT;
+ idx = BUFFER_FRONT_LEFT;
+ break;
+ case ST_ATTACHMENT_BACK_LEFT:
+ buf = GL_BACK_LEFT;
+ idx = BUFFER_BACK_LEFT;
+ break;
+ case ST_ATTACHMENT_FRONT_RIGHT:
+ buf = GL_FRONT_RIGHT;
+ idx = BUFFER_FRONT_RIGHT;
+ break;
+ case ST_ATTACHMENT_BACK_RIGHT:
+ buf = GL_BACK_RIGHT;
+ idx = BUFFER_BACK_RIGHT;
+ break;
+ default:
+ buf = GL_NONE;
+ idx = BUFFER_COUNT;
+ break;
+ }
+
+ if (buf != GL_NONE) {
+ if (buffer)
+ *buffer = buf;
+ if (index)
+ *index = idx;
+ }
+}
+
+/**
+ * Create a framebuffer from a manager interface.
+ */
+static struct st_framebuffer *
+st_framebuffer_create(struct st_framebuffer_iface *stfbi)
+{
+ struct st_framebuffer *stfb;
+ struct gl_config mode;
+ gl_buffer_index idx;
+
+ if (!stfbi)
+ return NULL;
+
+ stfb = CALLOC_STRUCT(st_framebuffer);
+ if (!stfb)
+ return NULL;
+
+ st_visual_to_context_mode(stfbi->visual, &mode);
+ _mesa_initialize_window_framebuffer(&stfb->Base, &mode);
+
+ /* modify the draw/read buffers of the fb */
+ st_visual_to_default_buffer(stfbi->visual, &stfb->Base.ColorDrawBuffer[0],
+ &stfb->Base._ColorDrawBufferIndexes[0]);
+ st_visual_to_default_buffer(stfbi->visual, &stfb->Base.ColorReadBuffer,
+ &stfb->Base._ColorReadBufferIndex);
+
+ stfb->iface = stfbi;
+
+ /* add the color buffer */
+ idx = stfb->Base._ColorDrawBufferIndexes[0];
+ if (!st_framebuffer_add_renderbuffer(stfb, idx)) {
+ FREE(stfb);
+ return NULL;
+ }
+
+ st_framebuffer_add_renderbuffer(stfb, BUFFER_DEPTH);
+ st_framebuffer_add_renderbuffer(stfb, BUFFER_ACCUM);
+
+ st_framebuffer_update_attachments(stfb);
+
+ stfb->Base.Initialized = GL_TRUE;
+
+ return stfb;
+}
+
+/**
+ * Reference a framebuffer.
+ */
+static void
+st_framebuffer_reference(struct st_framebuffer **ptr,
+ struct st_framebuffer *stfb)
+{
+ struct gl_framebuffer *fb = &stfb->Base;
+ _mesa_reference_framebuffer((struct gl_framebuffer **) ptr, fb);
+}
+
+static void
+st_context_notify_invalid_framebuffer(struct st_context_iface *stctxi,
+ struct st_framebuffer_iface *stfbi)
+{
+ struct st_context *st = (struct st_context *) stctxi;
+ struct st_framebuffer *stfb;
+
+ /* either draw or read winsys fb */
+ stfb = st_ws_framebuffer(st->ctx->WinSysDrawBuffer);
+ if (!stfb || stfb->iface != stfbi)
+ stfb = st_ws_framebuffer(st->ctx->WinSysReadBuffer);
+
+ if (stfb && stfb->iface == stfbi) {
+ p_atomic_set(&stfb->revalidate, TRUE);
+ }
+ else {
+ /* This function is probably getting called when we've detected a
+ * change in a window's size but the currently bound context is
+ * not bound to that window.
+ * If the st_framebuffer_iface structure had a pointer to the
+ * corresponding st_framebuffer we'd be able to handle this.
+ */
+ }
+}
+
+static void
+st_context_flush(struct st_context_iface *stctxi, unsigned flags,
+ struct pipe_fence_handle **fence)
+{
+ struct st_context *st = (struct st_context *) stctxi;
+ st_flush(st, fence);
+ if (flags & ST_FLUSH_FRONT)
+ st_manager_flush_frontbuffer(st);
+}
+
+static boolean
+st_context_teximage(struct st_context_iface *stctxi,
+ enum st_texture_type target,
+ int level, enum pipe_format internal_format,
+ struct pipe_resource *tex, boolean mipmap)
+{
+ struct st_context *st = (struct st_context *) stctxi;
+ struct gl_context *ctx = st->ctx;
+ struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
+ struct gl_texture_object *texObj;
+ struct gl_texture_image *texImage;
+ struct st_texture_object *stObj;
+ struct st_texture_image *stImage;
+ GLenum internalFormat;
+ GLuint width, height, depth;
+
+ switch (target) {
+ case ST_TEXTURE_1D:
+ target = GL_TEXTURE_1D;
+ break;
+ case ST_TEXTURE_2D:
+ target = GL_TEXTURE_2D;
+ break;
+ case ST_TEXTURE_3D:
+ target = GL_TEXTURE_3D;
+ break;
+ case ST_TEXTURE_RECT:
+ target = GL_TEXTURE_RECTANGLE_ARB;
+ break;
+ default:
+ return FALSE;
+ break;
+ }
+
+ texObj = _mesa_select_tex_object(ctx, texUnit, target);
+ _mesa_lock_texture(ctx, texObj);
+
+ stObj = st_texture_object(texObj);
+ /* switch to surface based */
+ if (!stObj->surface_based) {
+ _mesa_clear_texture_object(ctx, texObj);
+ stObj->surface_based = GL_TRUE;
+ }
+
+ texImage = _mesa_get_tex_image(ctx, texObj, target, level);
+ stImage = st_texture_image(texImage);
+ if (tex) {
+ gl_format texFormat;
+
+ /*
+ * XXX When internal_format and tex->format differ, st_finalize_texture
+ * needs to allocate a new texture with internal_format and copy the
+ * texture here into the new one. It will result in surface_copy being
+ * called on surfaces whose formats differ.
+ *
+ * To avoid that, internal_format is (wrongly) ignored here. A sane fix
+ * is to use a sampler view.
+ */
+ if (!st_sampler_compat_formats(tex->format, internal_format))
+ internal_format = tex->format;
+
+ if (util_format_get_component_bits(internal_format,
+ UTIL_FORMAT_COLORSPACE_RGB, 3) > 0)
+ internalFormat = GL_RGBA;
+ else
+ internalFormat = GL_RGB;
+
+ texFormat = st_ChooseTextureFormat(ctx, internalFormat,
+ GL_RGBA, GL_UNSIGNED_BYTE);
+
+ _mesa_init_teximage_fields(ctx, target, texImage,
+ tex->width0, tex->height0, 1, 0,
+ internalFormat, texFormat);
+
+ width = tex->width0;
+ height = tex->height0;
+ depth = tex->depth0;
+
+ /* grow the image size until we hit level = 0 */
+ while (level > 0) {
+ if (width != 1)
+ width <<= 1;
+ if (height != 1)
+ height <<= 1;
+ if (depth != 1)
+ depth <<= 1;
+ level--;
+ }
+ }
+ else {
+ _mesa_clear_texture_image(ctx, texImage);
+ width = height = depth = 0;
+ }
+
+ pipe_resource_reference(&stImage->pt, tex);
+ stObj->width0 = width;
+ stObj->height0 = height;
+ stObj->depth0 = depth;
+
+ _mesa_dirty_texobj(ctx, texObj, GL_TRUE);
+ _mesa_unlock_texture(ctx, texObj);
+
+ return TRUE;
+}
+
+static void
+st_context_copy(struct st_context_iface *stctxi,
+ struct st_context_iface *stsrci, unsigned mask)
+{
+ struct st_context *st = (struct st_context *) stctxi;
+ struct st_context *src = (struct st_context *) stsrci;
+
+ _mesa_copy_context(src->ctx, st->ctx, mask);
+}
+
+static boolean
+st_context_share(struct st_context_iface *stctxi,
+ struct st_context_iface *stsrci)
+{
+ struct st_context *st = (struct st_context *) stctxi;
+ struct st_context *src = (struct st_context *) stsrci;
+
+ return _mesa_share_state(st->ctx, src->ctx);
+}
+
+static void
+st_context_destroy(struct st_context_iface *stctxi)
+{
+ struct st_context *st = (struct st_context *) stctxi;
+ st_destroy_context(st);
+}
+
+static struct st_context_iface *
+st_api_create_context(struct st_api *stapi, struct st_manager *smapi,
+ const struct st_context_attribs *attribs,
+ struct st_context_iface *shared_stctxi)
+{
+ struct st_context *shared_ctx = (struct st_context *) shared_stctxi;
+ struct st_context *st;
+ struct pipe_context *pipe;
+ struct gl_config mode;
+ gl_api api;
+
+ if (!(stapi->profile_mask & (1 << attribs->profile)))
+ return NULL;
+
+ switch (attribs->profile) {
+ case ST_PROFILE_DEFAULT:
+ api = API_OPENGL;
+ break;
+ case ST_PROFILE_OPENGL_ES1:
+ api = API_OPENGLES;
+ break;
+ case ST_PROFILE_OPENGL_ES2:
+ api = API_OPENGLES2;
+ break;
+ case ST_PROFILE_OPENGL_CORE:
+ default:
+ return NULL;
+ break;
+ }
+
+ pipe = smapi->screen->context_create(smapi->screen, NULL);
+ if (!pipe)
+ return NULL;
+
+ st_visual_to_context_mode(&attribs->visual, &mode);
+ st = st_create_context(api, pipe, &mode, shared_ctx);
+ if (!st) {
+ pipe->destroy(pipe);
+ return NULL;
+ }
+
+ /* need to perform version check */
+ if (attribs->major > 1 || attribs->minor > 0) {
+ _mesa_compute_version(st->ctx);
+
+ /* is the actual version less than the requested version? */
+ if (st->ctx->VersionMajor * 10 + st->ctx->VersionMinor <
+ attribs->major * 10 + attribs->minor) {
+ st_destroy_context(st);
+ return NULL;
+ }
+ }
+
+ st->invalidate_on_gl_viewport =
+ smapi->get_param(smapi, ST_MANAGER_BROKEN_INVALIDATE);
+
+ st->iface.destroy = st_context_destroy;
+ st->iface.notify_invalid_framebuffer =
+ st_context_notify_invalid_framebuffer;
+ st->iface.flush = st_context_flush;
+ st->iface.teximage = st_context_teximage;
+ st->iface.copy = st_context_copy;
+ st->iface.share = st_context_share;
+ st->iface.st_context_private = (void *) smapi;
+
+ return &st->iface;
+}
+
+static struct st_context_iface *
+st_api_get_current(struct st_api *stapi)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ struct st_context *st = (ctx) ? ctx->st : NULL;
+
+ return (st) ? &st->iface : NULL;
+}
+
+static boolean
+st_api_make_current(struct st_api *stapi, struct st_context_iface *stctxi,
+ struct st_framebuffer_iface *stdrawi,
+ struct st_framebuffer_iface *streadi)
+{
+ struct st_context *st = (struct st_context *) stctxi;
+ struct st_framebuffer *stdraw, *stread, *stfb;
+ boolean ret;
+
+ _glapi_check_multithread();
+
+ if (st) {
+ /* reuse/create the draw fb */
+ stfb = st_ws_framebuffer(st->ctx->WinSysDrawBuffer);
+ if (stfb && stfb->iface == stdrawi) {
+ stdraw = NULL;
+ st_framebuffer_reference(&stdraw, stfb);
+ }
+ else {
+ stdraw = st_framebuffer_create(stdrawi);
+ }
+
+ /* reuse/create the read fb */
+ stfb = st_ws_framebuffer(st->ctx->WinSysReadBuffer);
+ if (!stfb || stfb->iface != streadi)
+ stfb = stdraw;
+ if (stfb && stfb->iface == streadi) {
+ stread = NULL;
+ st_framebuffer_reference(&stread, stfb);
+ }
+ else {
+ stread = st_framebuffer_create(streadi);
+ }
+
+ if (stdraw && stread) {
+ if (stctxi != st_api_get_current(stapi)) {
+ p_atomic_set(&stdraw->revalidate, TRUE);
+ p_atomic_set(&stread->revalidate, TRUE);
+ }
+ st_framebuffer_validate(stdraw, st);
+ if (stread != stdraw)
+ st_framebuffer_validate(stread, st);
+
+ /* modify the draw/read buffers of the context */
+ if (stdraw->iface) {
+ st_visual_to_default_buffer(stdraw->iface->visual,
+ &st->ctx->Color.DrawBuffer[0], NULL);
+ }
+ if (stread->iface) {
+ st_visual_to_default_buffer(stread->iface->visual,
+ &st->ctx->Pixel.ReadBuffer, NULL);
+ }
+
+ ret = _mesa_make_current(st->ctx, &stdraw->Base, &stread->Base);
+ }
+ else {
+ struct gl_framebuffer *incomplete = _mesa_get_incomplete_framebuffer();
+ ret = _mesa_make_current(st->ctx, incomplete, incomplete);
+ }
+
+ st_framebuffer_reference(&stdraw, NULL);
+ st_framebuffer_reference(&stread, NULL);
+ }
+ else {
+ ret = _mesa_make_current(NULL, NULL, NULL);
+ }
+
+ return ret;
+}
+
+static st_proc_t
+st_api_get_proc_address(struct st_api *stapi, const char *procname)
+{
+ return (st_proc_t) _glapi_get_proc_address(procname);
+}
+
+static void
+st_api_destroy(struct st_api *stapi)
+{
+}
+
+/**
+ * Flush the front buffer if the current context renders to the front buffer.
+ */
+void
+st_manager_flush_frontbuffer(struct st_context *st)
+{
+ struct st_framebuffer *stfb = st_ws_framebuffer(st->ctx->DrawBuffer);
+ struct st_renderbuffer *strb = NULL;
+
+ if (stfb)
+ strb = st_renderbuffer(stfb->Base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer);
+ if (!strb)
+ return;
+
+ /* never a dummy fb */
+ assert(stfb->iface);
+ stfb->iface->flush_front(stfb->iface, ST_ATTACHMENT_FRONT_LEFT);
+}
+
+/**
+ * Return the surface of an EGLImage.
+ * FIXME: I think this should operate on resources, not surfaces
+ */
+struct pipe_surface *
+st_manager_get_egl_image_surface(struct st_context *st,
+ void *eglimg, unsigned usage)
+{
+ struct st_manager *smapi =
+ (struct st_manager *) st->iface.st_context_private;
+ struct st_egl_image stimg;
+ struct pipe_surface *ps, surf_tmpl;
+
+ if (!smapi || !smapi->get_egl_image)
+ return NULL;
+
+ memset(&stimg, 0, sizeof(stimg));
+ if (!smapi->get_egl_image(smapi, eglimg, &stimg))
+ return NULL;
+
+ memset(&surf_tmpl, 0, sizeof(surf_tmpl));
+ surf_tmpl.format = stimg.texture->format;
+ surf_tmpl.usage = usage;
+ surf_tmpl.u.tex.level = stimg.level;
+ surf_tmpl.u.tex.first_layer = stimg.layer;
+ surf_tmpl.u.tex.last_layer = stimg.layer;
+ ps = st->pipe->create_surface(st->pipe, stimg.texture, &surf_tmpl);
+ pipe_resource_reference(&stimg.texture, NULL);
+
+ return ps;
+}
+
+/**
+ * Re-validate the framebuffers.
+ */
+void
+st_manager_validate_framebuffers(struct st_context *st)
+{
+ struct st_framebuffer *stdraw = st_ws_framebuffer(st->ctx->DrawBuffer);
+ struct st_framebuffer *stread = st_ws_framebuffer(st->ctx->ReadBuffer);
+
+ if (stdraw)
+ st_framebuffer_validate(stdraw, st);
+ if (stread && stread != stdraw)
+ st_framebuffer_validate(stread, st);
+}
+
+/**
+ * Add a color renderbuffer on demand.
+ */
+boolean
+st_manager_add_color_renderbuffer(struct st_context *st,
+ struct gl_framebuffer *fb,
+ gl_buffer_index idx)
+{
+ struct st_framebuffer *stfb = st_ws_framebuffer(fb);
+
+ /* FBO */
+ if (!stfb)
+ return FALSE;
+
+ if (stfb->Base.Attachment[idx].Renderbuffer)
+ return TRUE;
+
+ switch (idx) {
+ case BUFFER_FRONT_LEFT:
+ case BUFFER_BACK_LEFT:
+ case BUFFER_FRONT_RIGHT:
+ case BUFFER_BACK_RIGHT:
+ break;
+ default:
+ return FALSE;
+ break;
+ }
+
+ if (!st_framebuffer_add_renderbuffer(stfb, idx))
+ return FALSE;
+
+ st_framebuffer_update_attachments(stfb);
+ st_invalidate_state(st->ctx, _NEW_BUFFERS);
+
+ return TRUE;
+}
+
+static const struct st_api st_gl_api = {
+ "Mesa " MESA_VERSION_STRING,
+ ST_API_OPENGL,
+#if FEATURE_GL
+ ST_PROFILE_DEFAULT_MASK |
+#endif
+#if FEATURE_ES1
+ ST_PROFILE_OPENGL_ES1_MASK |
+#endif
+#if FEATURE_ES2
+ ST_PROFILE_OPENGL_ES2_MASK |
+#endif
+ 0,
+ st_api_destroy,
+ st_api_get_proc_address,
+ st_api_create_context,
+ st_api_make_current,
+ st_api_get_current,
+};
+
+struct st_api *
+st_gl_api_create(void)
+{
+ return (struct st_api *) &st_gl_api;
+}
diff --git a/xkbcomp/compat.c b/xkbcomp/compat.c
index 03c29efdc..759535a38 100644
--- a/xkbcomp/compat.c
+++ b/xkbcomp/compat.c
@@ -656,8 +656,15 @@ HandleInterpDef(InterpDef * def, XkbDescPtr xkb, unsigned merge,
{
ERROR("Couldn't determine matching modifiers\n");
ACTION("Symbol interpretation ignored\n");
- return False;
+ return True;
}
+ if (def->ignore)
+ {
+ ERROR("Couldn't lookup keysym\n");
+ ACTION("Symbol interpretation ignored\n");
+ return True;
+ }
+
if (def->merge != MergeDefault)
merge = def->merge;
diff --git a/xkbcomp/configure.ac b/xkbcomp/configure.ac
index 6ef26b47d..252eb1a0b 100644
--- a/xkbcomp/configure.ac
+++ b/xkbcomp/configure.ac
@@ -1,62 +1,62 @@
-dnl Copyright 2005 Red Hat, Inc.
-dnl
-dnl Permission to use, copy, modify, distribute, and sell this software and its
-dnl documentation for any purpose is hereby granted without fee, provided that
-dnl the above copyright notice appear in all copies and that both that
-dnl copyright notice and this permission notice appear in supporting
-dnl documentation, and that the name of Red Hat not be used in
-dnl advertising or publicity pertaining to distribution of the software without
-dnl specific, written prior permission. Red Hat makes no
-dnl representations about the suitability of this software for any purpose. It
-dnl is provided "as is" without express or implied warranty.
-dnl
-dnl RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-dnl INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
-dnl EVENT SHALL RED HAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
-dnl CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
-dnl DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
-dnl TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-dnl PERFORMANCE OF THIS SOFTWARE.
-dnl
-dnl Process this file with autoconf to create configure.
-
-AC_PREREQ([2.60])
-AC_INIT([xkbcomp], [1.2.1],
- [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], [xkbcomp])
-AM_INIT_AUTOMAKE([foreign dist-bzip2])
-AM_MAINTAINER_MODE
-
-# Require X.Org macros 1.8 or later for MAN_SUBSTS set by XORG_MANPAGE_SECTIONS
-m4_ifndef([XORG_MACROS_VERSION],
- [m4_fatal([must install xorg-macros 1.8 or later before running autoconf/autogen])])
-XORG_MACROS_VERSION(1.8)
-XORG_DEFAULT_OPTIONS
-
-AC_CONFIG_HEADERS([config.h])
-
-# If both the C file and YACC are missing, the package cannot be build.
-AC_PROG_YACC
-AC_PATH_PROG([YACC_INST], $YACC)
-if test ! -f "$srcdir/xkbparse.c"; then
- if test -z "$YACC_INST"; then
- AC_MSG_ERROR([yacc not found - unable to compile xkbparse.y])
- fi
-fi
-
-AC_CHECK_FUNCS([strdup strcasecmp])
-
-# Checks for pkg-config packages
-PKG_CHECK_MODULES(XKBCOMP, x11 xkbfile)
-
-AC_ARG_WITH([xkb_config_root],
- [AS_HELP_STRING([--with-xkb-config-root=<paths>],
- [Set default XKB config root (default: ${datadir}/X11/xkb)])],
- [XKBCONFIGROOT="$withval"],
- [XKBCONFIGROOT='${datadir}/X11/xkb'])
-AC_SUBST([XKBCONFIGROOT])
-
-
-AC_CONFIG_FILES([
- Makefile
- man/Makefile])
-AC_OUTPUT
+dnl Copyright 2005 Red Hat, Inc.
+dnl
+dnl Permission to use, copy, modify, distribute, and sell this software and its
+dnl documentation for any purpose is hereby granted without fee, provided that
+dnl the above copyright notice appear in all copies and that both that
+dnl copyright notice and this permission notice appear in supporting
+dnl documentation, and that the name of Red Hat not be used in
+dnl advertising or publicity pertaining to distribution of the software without
+dnl specific, written prior permission. Red Hat makes no
+dnl representations about the suitability of this software for any purpose. It
+dnl is provided "as is" without express or implied warranty.
+dnl
+dnl RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+dnl INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+dnl EVENT SHALL RED HAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+dnl CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+dnl DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+dnl TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+dnl PERFORMANCE OF THIS SOFTWARE.
+dnl
+dnl Process this file with autoconf to create configure.
+
+AC_PREREQ([2.60])
+AC_INIT([xkbcomp], [1.2.3],
+ [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], [xkbcomp])
+AM_INIT_AUTOMAKE([foreign dist-bzip2])
+AM_MAINTAINER_MODE
+
+# Require X.Org macros 1.8 or later for MAN_SUBSTS set by XORG_MANPAGE_SECTIONS
+m4_ifndef([XORG_MACROS_VERSION],
+ [m4_fatal([must install xorg-macros 1.8 or later before running autoconf/autogen])])
+XORG_MACROS_VERSION(1.8)
+XORG_DEFAULT_OPTIONS
+
+AC_CONFIG_HEADERS([config.h])
+
+# If both the C file and YACC are missing, the package cannot be build.
+AC_PROG_YACC
+AC_PATH_PROG([YACC_INST], $YACC)
+if test ! -f "$srcdir/xkbparse.c"; then
+ if test -z "$YACC_INST"; then
+ AC_MSG_ERROR([yacc not found - unable to compile xkbparse.y])
+ fi
+fi
+
+AC_CHECK_FUNCS([strdup strcasecmp])
+
+# Checks for pkg-config packages
+PKG_CHECK_MODULES(XKBCOMP, x11 xkbfile)
+
+AC_ARG_WITH([xkb_config_root],
+ [AS_HELP_STRING([--with-xkb-config-root=<paths>],
+ [Set default XKB config root (default: ${datadir}/X11/xkb)])],
+ [XKBCONFIGROOT="$withval"],
+ [XKBCONFIGROOT='${datadir}/X11/xkb'])
+AC_SUBST([XKBCONFIGROOT])
+
+
+AC_CONFIG_FILES([
+ Makefile
+ man/Makefile])
+AC_OUTPUT
diff --git a/xkbcomp/man/xkbcomp.man b/xkbcomp/man/xkbcomp.man
index 9b380a0fd..0486b7dd7 100644
--- a/xkbcomp/man/xkbcomp.man
+++ b/xkbcomp/man/xkbcomp.man
@@ -88,6 +88,9 @@ Specifies the root directory for relative path names.
.B -synch
Force synchronization for X requests.
.TP 8
+.B -version
+Print version number.
+.TP 8
.B \-w\ \fIlvl\fP
Controls the reporting of warnings during compilation. A warning level
of 0 disables all warnings; a warning level of 10 enables them all.
diff --git a/xkbcomp/parseutils.c b/xkbcomp/parseutils.c
index be8a1788f..ca665e25a 100644
--- a/xkbcomp/parseutils.c
+++ b/xkbcomp/parseutils.c
@@ -1,844 +1,847 @@
-/************************************************************
- Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
-
- Permission to use, copy, modify, and distribute this
- software and its documentation for any purpose and without
- fee is hereby granted, provided that the above copyright
- notice appear in all copies and that both that copyright
- notice and this permission notice appear in supporting
- documentation, and that the name of Silicon Graphics not be
- used in advertising or publicity pertaining to distribution
- of the software without specific prior written permission.
- Silicon Graphics makes no representation about the suitability
- of this software for any purpose. It is provided "as is"
- without any express or implied warranty.
-
- SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
- SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
- GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
- DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
- THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
- ********************************************************/
-
-#define DEBUG_VAR parseDebug
-#include "parseutils.h"
-#include "xkbpath.h"
-#include <X11/keysym.h>
-#include <X11/extensions/XKBgeom.h>
-#include <X11/Xalloca.h>
-#include <limits.h>
-#include <stdlib.h>
-
-XkbFile *rtrnValue;
-
-ParseCommon *
-AppendStmt(ParseCommon * to, ParseCommon * append)
-{
- ParseCommon *start = to;
-
- if (append == NULL)
- return to;
- while ((to != NULL) && (to->next != NULL))
- {
- to = to->next;
- }
- if (to)
- {
- to->next = append;
- return start;
- }
- return append;
-}
-
-ExprDef *
-ExprCreate(unsigned op, unsigned type)
-{
- ExprDef *expr;
- expr = uTypedAlloc(ExprDef);
- if (expr)
- {
- expr->common.stmtType = StmtExpr;
- expr->common.next = NULL;
- expr->op = op;
- expr->type = type;
- }
- else
- {
- FATAL("Couldn't allocate expression in parser\n");
- /* NOTREACHED */
- }
- return expr;
-}
-
-ExprDef *
-ExprCreateUnary(unsigned op, unsigned type, ExprDef * child)
-{
- ExprDef *expr;
- expr = uTypedAlloc(ExprDef);
- if (expr)
- {
- expr->common.stmtType = StmtExpr;
- expr->common.next = NULL;
- expr->op = op;
- expr->type = type;
- expr->value.child = child;
- }
- else
- {
- FATAL("Couldn't allocate expression in parser\n");
- /* NOTREACHED */
- }
- return expr;
-}
-
-ExprDef *
-ExprCreateBinary(unsigned op, ExprDef * left, ExprDef * right)
-{
- ExprDef *expr;
- expr = uTypedAlloc(ExprDef);
- if (expr)
- {
- expr->common.stmtType = StmtExpr;
- expr->common.next = NULL;
- expr->op = op;
- if ((op == OpAssign) || (left->type == TypeUnknown))
- expr->type = right->type;
- else if ((left->type == right->type) || (right->type == TypeUnknown))
- expr->type = left->type;
- else
- expr->type = TypeUnknown;
- expr->value.binary.left = left;
- expr->value.binary.right = right;
- }
- else
- {
- FATAL("Couldn't allocate expression in parser\n");
- /* NOTREACHED */
- }
- return expr;
-}
-
-KeycodeDef *
-KeycodeCreate(char *name, ExprDef * value)
-{
- KeycodeDef *def;
-
- def = uTypedAlloc(KeycodeDef);
- if (def)
- {
- def->common.stmtType = StmtKeycodeDef;
- def->common.next = NULL;
- strncpy(def->name, name, XkbKeyNameLength);
- def->name[XkbKeyNameLength] = '\0';
- def->value = value;
- }
- else
- {
- FATAL("Couldn't allocate key name definition in parser\n");
- /* NOTREACHED */
- }
- return def;
-}
-
-KeyAliasDef *
-KeyAliasCreate(char *alias, char *real)
-{
- KeyAliasDef *def;
-
- def = uTypedAlloc(KeyAliasDef);
- if (def)
- {
- def->common.stmtType = StmtKeyAliasDef;
- def->common.next = NULL;
- strncpy(def->alias, alias, XkbKeyNameLength);
- def->alias[XkbKeyNameLength] = '\0';
- strncpy(def->real, real, XkbKeyNameLength);
- def->real[XkbKeyNameLength] = '\0';
- }
- else
- {
- FATAL("Couldn't allocate key alias definition in parser\n");
- /* NOTREACHED */
- }
- return def;
-}
-
-VModDef *
-VModCreate(Atom name, ExprDef * value)
-{
- VModDef *def;
- def = uTypedAlloc(VModDef);
- if (def)
- {
- def->common.stmtType = StmtVModDef;
- def->common.next = NULL;
- def->name = name;
- def->value = value;
- }
- else
- {
- FATAL("Couldn't allocate variable definition in parser\n");
- /* NOTREACHED */
- }
- return def;
-}
-
-VarDef *
-VarCreate(ExprDef * name, ExprDef * value)
-{
- VarDef *def;
- def = uTypedAlloc(VarDef);
- if (def)
- {
- def->common.stmtType = StmtVarDef;
- def->common.next = NULL;
- def->name = name;
- def->value = value;
- }
- else
- {
- FATAL("Couldn't allocate variable definition in parser\n");
- /* NOTREACHED */
- }
- return def;
-}
-
-VarDef *
-BoolVarCreate(Atom nameToken, unsigned set)
-{
- ExprDef *name, *value;
-
- name = ExprCreate(ExprIdent, TypeUnknown);
- name->value.str = nameToken;
- value = ExprCreate(ExprValue, TypeBoolean);
- value->value.uval = set;
- return VarCreate(name, value);
-}
-
-InterpDef *
-InterpCreate(KeySym sym, ExprDef * match)
-{
- InterpDef *def;
-
- def = uTypedAlloc(InterpDef);
- if (def)
- {
- def->common.stmtType = StmtInterpDef;
- def->common.next = NULL;
- def->sym = sym;
- def->match = match;
- }
- else
- {
- FATAL("Couldn't allocate interp definition in parser\n");
- /* NOTREACHED */
- }
- return def;
-}
-
-KeyTypeDef *
-KeyTypeCreate(Atom name, VarDef * body)
-{
- KeyTypeDef *def;
-
- def = uTypedAlloc(KeyTypeDef);
- if (def)
- {
- def->common.stmtType = StmtKeyTypeDef;
- def->common.next = NULL;
- def->merge = MergeDefault;
- def->name = name;
- def->body = body;
- }
- else
- {
- FATAL("Couldn't allocate key type definition in parser\n");
- /* NOTREACHED */
- }
- return def;
-}
-
-SymbolsDef *
-SymbolsCreate(char *keyName, ExprDef * symbols)
-{
- SymbolsDef *def;
-
- def = uTypedAlloc(SymbolsDef);
- if (def)
- {
- def->common.stmtType = StmtSymbolsDef;
- def->common.next = NULL;
- def->merge = MergeDefault;
- bzero(def->keyName, 5);
- strncpy(def->keyName, keyName, 4);
- def->symbols = symbols;
- }
- else
- {
- FATAL("Couldn't allocate symbols definition in parser\n");
- /* NOTREACHED */
- }
- return def;
-}
-
-GroupCompatDef *
-GroupCompatCreate(int group, ExprDef * val)
-{
- GroupCompatDef *def;
-
- def = uTypedAlloc(GroupCompatDef);
- if (def)
- {
- def->common.stmtType = StmtGroupCompatDef;
- def->common.next = NULL;
- def->merge = MergeDefault;
- def->group = group;
- def->def = val;
- }
- else
- {
- FATAL("Couldn't allocate group compat definition in parser\n");
- /* NOTREACHED */
- }
- return def;
-}
-
-ModMapDef *
-ModMapCreate(Atom modifier, ExprDef * keys)
-{
- ModMapDef *def;
-
- def = uTypedAlloc(ModMapDef);
- if (def)
- {
- def->common.stmtType = StmtModMapDef;
- def->common.next = NULL;
- def->merge = MergeDefault;
- def->modifier = modifier;
- def->keys = keys;
- }
- else
- {
- FATAL("Couldn't allocate mod mask definition in parser\n");
- /* NOTREACHED */
- }
- return def;
-}
-
-IndicatorMapDef *
-IndicatorMapCreate(Atom name, VarDef * body)
-{
- IndicatorMapDef *def;
-
- def = uTypedAlloc(IndicatorMapDef);
- if (def)
- {
- def->common.stmtType = StmtIndicatorMapDef;
- def->common.next = NULL;
- def->merge = MergeDefault;
- def->name = name;
- def->body = body;
- }
- else
- {
- FATAL("Couldn't allocate indicator map definition in parser\n");
- /* NOTREACHED */
- }
- return def;
-}
-
-IndicatorNameDef *
-IndicatorNameCreate(int ndx, ExprDef * name, Bool virtual)
-{
- IndicatorNameDef *def;
-
- def = uTypedAlloc(IndicatorNameDef);
- if (def)
- {
- def->common.stmtType = StmtIndicatorNameDef;
- def->common.next = NULL;
- def->merge = MergeDefault;
- def->ndx = ndx;
- def->name = name;
- def->virtual = virtual;
- }
- else
- {
- FATAL("Couldn't allocate indicator index definition in parser\n");
- /* NOTREACHED */
- }
- return def;
-}
-
-ExprDef *
-ActionCreate(Atom name, ExprDef * args)
-{
- ExprDef *act;
-
- act = uTypedAlloc(ExprDef);
- if (act)
- {
- act->common.stmtType = StmtExpr;
- act->common.next = NULL;
- act->op = ExprActionDecl;
- act->value.action.name = name;
- act->value.action.args = args;
- return act;
- }
- FATAL("Couldn't allocate ActionDef in parser\n");
- return NULL;
-}
-
-ExprDef *
-CreateKeysymList(char *sym)
-{
- ExprDef *def;
-
- def = ExprCreate(ExprKeysymList, TypeSymbols);
- if (def)
- {
- def->value.list.nSyms = 1;
- def->value.list.szSyms = 4;
- def->value.list.syms = uTypedCalloc(4, char *);
- if (def->value.list.syms != NULL)
- {
- def->value.list.syms[0] = sym;
- return def;
- }
- }
- FATAL("Couldn't allocate expression for keysym list in parser\n");
- return NULL;
-}
-
-ShapeDef *
-ShapeDeclCreate(Atom name, OutlineDef * outlines)
-{
- ShapeDef *shape;
- OutlineDef *ol;
-
- shape = uTypedAlloc(ShapeDef);
- if (shape != NULL)
- {
- bzero(shape, sizeof(ShapeDef));
- shape->common.stmtType = StmtShapeDef;
- shape->common.next = NULL;
- shape->merge = MergeDefault;
- shape->name = name;
- shape->nOutlines = 0;
- shape->outlines = outlines;
- for (ol = outlines; ol != NULL; ol = (OutlineDef *) ol->common.next)
- {
- if (ol->nPoints > 0)
- shape->nOutlines++;
- }
- }
- return shape;
-}
-
-OutlineDef *
-OutlineCreate(Atom field, ExprDef * points)
-{
- OutlineDef *outline;
- ExprDef *pt;
-
- outline = uTypedAlloc(OutlineDef);
- if (outline != NULL)
- {
- bzero(outline, sizeof(OutlineDef));
- outline->common.stmtType = StmtOutlineDef;
- outline->common.next = NULL;
- outline->field = field;
- outline->nPoints = 0;
- if (points->op == ExprCoord)
- {
- for (pt = points; pt != NULL; pt = (ExprDef *) pt->common.next)
- {
- outline->nPoints++;
- }
- }
- outline->points = points;
- }
- return outline;
-}
-
-KeyDef *
-KeyDeclCreate(char *name, ExprDef * expr)
-{
- KeyDef *key;
-
- key = uTypedAlloc(KeyDef);
- if (key != NULL)
- {
- bzero(key, sizeof(KeyDef));
- key->common.stmtType = StmtKeyDef;
- key->common.next = NULL;
- if (name)
- key->name = name;
- else
- key->expr = expr;
- }
- return key;
-}
-
-KeyDef *
-KeyDeclMerge(KeyDef * into, KeyDef * from)
-{
- into->expr =
- (ExprDef *) AppendStmt(&into->expr->common, &from->expr->common);
- from->expr = NULL;
- uFree(from);
- return into;
-}
-
-RowDef *
-RowDeclCreate(KeyDef * keys)
-{
- RowDef *row;
- KeyDef *key;
-
- row = uTypedAlloc(RowDef);
- if (row != NULL)
- {
- bzero(row, sizeof(RowDef));
- row->common.stmtType = StmtRowDef;
- row->common.next = NULL;
- row->nKeys = 0;
- row->keys = keys;
- for (key = keys; key != NULL; key = (KeyDef *) key->common.next)
- {
- if (key->common.stmtType == StmtKeyDef)
- row->nKeys++;
- }
- }
- return row;
-}
-
-SectionDef *
-SectionDeclCreate(Atom name, RowDef * rows)
-{
- SectionDef *section;
- RowDef *row;
-
- section = uTypedAlloc(SectionDef);
- if (section != NULL)
- {
- bzero(section, sizeof(SectionDef));
- section->common.stmtType = StmtSectionDef;
- section->common.next = NULL;
- section->name = name;
- section->nRows = 0;
- section->rows = rows;
- for (row = rows; row != NULL; row = (RowDef *) row->common.next)
- {
- if (row->common.stmtType == StmtRowDef)
- section->nRows++;
- }
- }
- return section;
-}
-
-OverlayKeyDef *
-OverlayKeyCreate(char *under, char *over)
-{
- OverlayKeyDef *key;
-
- key = uTypedAlloc(OverlayKeyDef);
- if (key != NULL)
- {
- bzero(key, sizeof(OverlayKeyDef));
- key->common.stmtType = StmtOverlayKeyDef;
- strncpy(key->over, over, XkbKeyNameLength);
- strncpy(key->under, under, XkbKeyNameLength);
- if (over)
- uFree(over);
- if (under)
- uFree(under);
- }
- return key;
-}
-
-OverlayDef *
-OverlayDeclCreate(Atom name, OverlayKeyDef * keys)
-{
- OverlayDef *ol;
- OverlayKeyDef *key;
-
- ol = uTypedAlloc(OverlayDef);
- if (ol != NULL)
- {
- bzero(ol, sizeof(OverlayDef));
- ol->common.stmtType = StmtOverlayDef;
- ol->name = name;
- ol->keys = keys;
- for (key = keys; key != NULL;
- key = (OverlayKeyDef *) key->common.next)
- {
- ol->nKeys++;
- }
- }
- return ol;
-}
-
-DoodadDef *
-DoodadCreate(unsigned type, Atom name, VarDef * body)
-{
- DoodadDef *doodad;
-
- doodad = uTypedAlloc(DoodadDef);
- if (doodad != NULL)
- {
- bzero(doodad, sizeof(DoodadDef));
- doodad->common.stmtType = StmtDoodadDef;
- doodad->common.next = NULL;
- doodad->type = type;
- doodad->name = name;
- doodad->body = body;
- }
- return doodad;
-}
-
-ExprDef *
-AppendKeysymList(ExprDef * list, char *sym)
-{
- if (list->value.list.nSyms >= list->value.list.szSyms)
- {
- list->value.list.szSyms *= 2;
- list->value.list.syms = uTypedRecalloc(list->value.list.syms,
- list->value.list.nSyms,
- list->value.list.szSyms,
- char *);
- if (list->value.list.syms == NULL)
- {
- FATAL("Couldn't resize list of symbols for append\n");
- return NULL;
- }
- }
- list->value.list.syms[list->value.list.nSyms++] = sym;
- return list;
-}
-
-int
-LookupKeysym(char *str, KeySym * sym_rtrn)
-{
- KeySym sym;
- char *tmp;
-
- if ((!str) || (uStrCaseCmp(str, "any") == 0)
- || (uStrCaseCmp(str, "nosymbol") == 0))
- {
- *sym_rtrn = NoSymbol;
- return 1;
- }
- else if ((uStrCaseCmp(str, "none") == 0)
- || (uStrCaseCmp(str, "voidsymbol") == 0))
- {
- *sym_rtrn = XK_VoidSymbol;
- return 1;
- }
- sym = XStringToKeysym(str);
- if (sym != NoSymbol)
- {
- *sym_rtrn = sym;
- return 1;
- }
- if (strlen(str) > 2 && str[0] == '0' && str[1] == 'x') {
- sym = strtoul(str, &tmp, 16);
- if (sym != ULONG_MAX && (!tmp || *tmp == '\0')) {
- *sym_rtrn = sym;
- return 1;
- }
- }
- return 0;
-}
-
-IncludeStmt *
-IncludeCreate(char *str, unsigned merge)
-{
- IncludeStmt *incl, *first;
- char *file, *map, *stmt, *tmp, *extra_data;
- char nextop;
- Bool haveSelf;
-
- haveSelf = False;
- incl = first = NULL;
- file = map = NULL;
- tmp = str;
- stmt = uStringDup(str);
- while ((tmp) && (*tmp))
- {
- if (XkbParseIncludeMap(&tmp, &file, &map, &nextop, &extra_data))
- {
- if ((file == NULL) && (map == NULL))
- {
- if (haveSelf)
- goto BAIL;
- haveSelf = True;
- }
- if (first == NULL)
- first = incl = uTypedAlloc(IncludeStmt);
- else
- {
- incl->next = uTypedAlloc(IncludeStmt);
- incl = incl->next;
- }
- if (incl)
- {
- incl->common.stmtType = StmtInclude;
- incl->common.next = NULL;
- incl->merge = merge;
- incl->stmt = NULL;
- incl->file = file;
- incl->map = map;
- incl->modifier = extra_data;
- incl->path = NULL;
- incl->next = NULL;
- }
- else
- {
- WSGO("Allocation failure in IncludeCreate\n");
- ACTION("Using only part of the include\n");
- break;
- }
- if (nextop == '|')
- merge = MergeAugment;
- else
- merge = MergeOverride;
- }
- else
- {
- goto BAIL;
- }
- }
- if (first)
- first->stmt = stmt;
- else if (stmt)
- uFree(stmt);
- return first;
- BAIL:
- ERROR1("Illegal include statement \"%s\"\n", stmt);
- ACTION("Ignored\n");
- while (first)
- {
- incl = first->next;
- if (first->file)
- uFree(first->file);
- if (first->map)
- uFree(first->map);
- if (first->modifier)
- uFree(first->modifier);
- if (first->path)
- uFree(first->path);
- first->file = first->map = first->path = NULL;
- uFree(first);
- first = incl;
- }
- if (stmt)
- uFree(stmt);
- return NULL;
-}
-
-#ifdef DEBUG
-void
-PrintStmtAddrs(ParseCommon * stmt)
-{
- fprintf(stderr, "0x%x", stmt);
- if (stmt)
- {
- do
- {
- fprintf(stderr, "->0x%x", stmt->next);
- stmt = stmt->next;
- }
- while (stmt);
- }
- fprintf(stderr, "\n");
-}
-#endif
-
-static void
-CheckDefaultMap(XkbFile * maps)
-{
- XkbFile *dflt, *tmp;
-
- dflt = NULL;
- for (tmp = maps, dflt = NULL; tmp != NULL;
- tmp = (XkbFile *) tmp->common.next)
- {
- if (tmp->flags & XkbLC_Default)
- {
- if (dflt == NULL)
- dflt = tmp;
- else
- {
- if (warningLevel > 2)
- {
- WARN1("Multiple default components in %s\n",
- (scanFile ? scanFile : "(unknown)"));
- ACTION2("Using %s, ignoring %s\n",
- (dflt->name ? dflt->name : "(first)"),
- (tmp->name ? tmp->name : "(subsequent)"));
- }
- tmp->flags &= (~XkbLC_Default);
- }
- }
- }
- return;
-}
-
-int
-XKBParseFile(FILE * file, XkbFile ** pRtrn)
-{
- if (file)
- {
- yyin = file;
- rtrnValue = NULL;
- if (yyparse() == 0)
- {
- *pRtrn = rtrnValue;
- CheckDefaultMap(rtrnValue);
- rtrnValue = NULL;
- return 1;
- }
- *pRtrn = NULL;
- return 0;
- }
- *pRtrn = NULL;
- return 1;
-}
-
-XkbFile *
-CreateXKBFile(int type, char *name, ParseCommon * defs, unsigned flags)
-{
- XkbFile *file;
- static int fileID;
-
- file = uTypedAlloc(XkbFile);
- if (file)
- {
- XkbEnsureSafeMapName(name);
- bzero(file, sizeof(XkbFile));
- file->type = type;
- file->topName = uStringDup(name);
- file->name = name;
- file->defs = defs;
- file->id = fileID++;
- file->compiled = False;
- file->flags = flags;
- }
- return file;
-}
-
-unsigned
-StmtSetMerge(ParseCommon * stmt, unsigned merge)
-{
- if ((merge == MergeAltForm) && (stmt->stmtType != StmtKeycodeDef))
- {
- yyerror("illegal use of 'alternate' merge mode");
- merge = MergeDefault;
- }
- return merge;
-}
+/************************************************************
+ Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
+
+ Permission to use, copy, modify, and distribute this
+ software and its documentation for any purpose and without
+ fee is hereby granted, provided that the above copyright
+ notice appear in all copies and that both that copyright
+ notice and this permission notice appear in supporting
+ documentation, and that the name of Silicon Graphics not be
+ used in advertising or publicity pertaining to distribution
+ of the software without specific prior written permission.
+ Silicon Graphics makes no representation about the suitability
+ of this software for any purpose. It is provided "as is"
+ without any express or implied warranty.
+
+ SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+ GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
+ THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+ ********************************************************/
+
+#define DEBUG_VAR parseDebug
+#include "parseutils.h"
+#include "xkbpath.h"
+#include <X11/keysym.h>
+#include <X11/extensions/XKBgeom.h>
+#include <X11/Xalloca.h>
+#include <limits.h>
+#include <stdlib.h>
+
+XkbFile *rtrnValue;
+
+ParseCommon *
+AppendStmt(ParseCommon * to, ParseCommon * append)
+{
+ ParseCommon *start = to;
+
+ if (append == NULL)
+ return to;
+ while ((to != NULL) && (to->next != NULL))
+ {
+ to = to->next;
+ }
+ if (to)
+ {
+ to->next = append;
+ return start;
+ }
+ return append;
+}
+
+ExprDef *
+ExprCreate(unsigned op, unsigned type)
+{
+ ExprDef *expr;
+ expr = uTypedAlloc(ExprDef);
+ if (expr)
+ {
+ expr->common.stmtType = StmtExpr;
+ expr->common.next = NULL;
+ expr->op = op;
+ expr->type = type;
+ }
+ else
+ {
+ FATAL("Couldn't allocate expression in parser\n");
+ /* NOTREACHED */
+ }
+ return expr;
+}
+
+ExprDef *
+ExprCreateUnary(unsigned op, unsigned type, ExprDef * child)
+{
+ ExprDef *expr;
+ expr = uTypedAlloc(ExprDef);
+ if (expr)
+ {
+ expr->common.stmtType = StmtExpr;
+ expr->common.next = NULL;
+ expr->op = op;
+ expr->type = type;
+ expr->value.child = child;
+ }
+ else
+ {
+ FATAL("Couldn't allocate expression in parser\n");
+ /* NOTREACHED */
+ }
+ return expr;
+}
+
+ExprDef *
+ExprCreateBinary(unsigned op, ExprDef * left, ExprDef * right)
+{
+ ExprDef *expr;
+ expr = uTypedAlloc(ExprDef);
+ if (expr)
+ {
+ expr->common.stmtType = StmtExpr;
+ expr->common.next = NULL;
+ expr->op = op;
+ if ((op == OpAssign) || (left->type == TypeUnknown))
+ expr->type = right->type;
+ else if ((left->type == right->type) || (right->type == TypeUnknown))
+ expr->type = left->type;
+ else
+ expr->type = TypeUnknown;
+ expr->value.binary.left = left;
+ expr->value.binary.right = right;
+ }
+ else
+ {
+ FATAL("Couldn't allocate expression in parser\n");
+ /* NOTREACHED */
+ }
+ return expr;
+}
+
+KeycodeDef *
+KeycodeCreate(char *name, ExprDef * value)
+{
+ KeycodeDef *def;
+
+ def = uTypedAlloc(KeycodeDef);
+ if (def)
+ {
+ def->common.stmtType = StmtKeycodeDef;
+ def->common.next = NULL;
+ strncpy(def->name, name, XkbKeyNameLength);
+ def->name[XkbKeyNameLength] = '\0';
+ def->value = value;
+ }
+ else
+ {
+ FATAL("Couldn't allocate key name definition in parser\n");
+ /* NOTREACHED */
+ }
+ return def;
+}
+
+KeyAliasDef *
+KeyAliasCreate(char *alias, char *real)
+{
+ KeyAliasDef *def;
+
+ def = uTypedAlloc(KeyAliasDef);
+ if (def)
+ {
+ def->common.stmtType = StmtKeyAliasDef;
+ def->common.next = NULL;
+ strncpy(def->alias, alias, XkbKeyNameLength);
+ def->alias[XkbKeyNameLength] = '\0';
+ strncpy(def->real, real, XkbKeyNameLength);
+ def->real[XkbKeyNameLength] = '\0';
+ }
+ else
+ {
+ FATAL("Couldn't allocate key alias definition in parser\n");
+ /* NOTREACHED */
+ }
+ return def;
+}
+
+VModDef *
+VModCreate(Atom name, ExprDef * value)
+{
+ VModDef *def;
+ def = uTypedAlloc(VModDef);
+ if (def)
+ {
+ def->common.stmtType = StmtVModDef;
+ def->common.next = NULL;
+ def->name = name;
+ def->value = value;
+ }
+ else
+ {
+ FATAL("Couldn't allocate variable definition in parser\n");
+ /* NOTREACHED */
+ }
+ return def;
+}
+
+VarDef *
+VarCreate(ExprDef * name, ExprDef * value)
+{
+ VarDef *def;
+ def = uTypedAlloc(VarDef);
+ if (def)
+ {
+ def->common.stmtType = StmtVarDef;
+ def->common.next = NULL;
+ def->name = name;
+ def->value = value;
+ }
+ else
+ {
+ FATAL("Couldn't allocate variable definition in parser\n");
+ /* NOTREACHED */
+ }
+ return def;
+}
+
+VarDef *
+BoolVarCreate(Atom nameToken, unsigned set)
+{
+ ExprDef *name, *value;
+
+ name = ExprCreate(ExprIdent, TypeUnknown);
+ name->value.str = nameToken;
+ value = ExprCreate(ExprValue, TypeBoolean);
+ value->value.uval = set;
+ return VarCreate(name, value);
+}
+
+InterpDef *
+InterpCreate(const char *sym_str, ExprDef * match)
+{
+ InterpDef *def;
+
+ def = uTypedAlloc(InterpDef);
+ if (def)
+ {
+ def->common.stmtType = StmtInterpDef;
+ def->common.next = NULL;
+ if (LookupKeysym(sym_str, &def->sym) == 0)
+ def->ignore = True;
+ else
+ def->ignore = False;
+ def->match = match;
+ }
+ else
+ {
+ FATAL("Couldn't allocate interp definition in parser\n");
+ /* NOTREACHED */
+ }
+ return def;
+}
+
+KeyTypeDef *
+KeyTypeCreate(Atom name, VarDef * body)
+{
+ KeyTypeDef *def;
+
+ def = uTypedAlloc(KeyTypeDef);
+ if (def)
+ {
+ def->common.stmtType = StmtKeyTypeDef;
+ def->common.next = NULL;
+ def->merge = MergeDefault;
+ def->name = name;
+ def->body = body;
+ }
+ else
+ {
+ FATAL("Couldn't allocate key type definition in parser\n");
+ /* NOTREACHED */
+ }
+ return def;
+}
+
+SymbolsDef *
+SymbolsCreate(char *keyName, ExprDef * symbols)
+{
+ SymbolsDef *def;
+
+ def = uTypedAlloc(SymbolsDef);
+ if (def)
+ {
+ def->common.stmtType = StmtSymbolsDef;
+ def->common.next = NULL;
+ def->merge = MergeDefault;
+ bzero(def->keyName, 5);
+ strncpy(def->keyName, keyName, 4);
+ def->symbols = symbols;
+ }
+ else
+ {
+ FATAL("Couldn't allocate symbols definition in parser\n");
+ /* NOTREACHED */
+ }
+ return def;
+}
+
+GroupCompatDef *
+GroupCompatCreate(int group, ExprDef * val)
+{
+ GroupCompatDef *def;
+
+ def = uTypedAlloc(GroupCompatDef);
+ if (def)
+ {
+ def->common.stmtType = StmtGroupCompatDef;
+ def->common.next = NULL;
+ def->merge = MergeDefault;
+ def->group = group;
+ def->def = val;
+ }
+ else
+ {
+ FATAL("Couldn't allocate group compat definition in parser\n");
+ /* NOTREACHED */
+ }
+ return def;
+}
+
+ModMapDef *
+ModMapCreate(Atom modifier, ExprDef * keys)
+{
+ ModMapDef *def;
+
+ def = uTypedAlloc(ModMapDef);
+ if (def)
+ {
+ def->common.stmtType = StmtModMapDef;
+ def->common.next = NULL;
+ def->merge = MergeDefault;
+ def->modifier = modifier;
+ def->keys = keys;
+ }
+ else
+ {
+ FATAL("Couldn't allocate mod mask definition in parser\n");
+ /* NOTREACHED */
+ }
+ return def;
+}
+
+IndicatorMapDef *
+IndicatorMapCreate(Atom name, VarDef * body)
+{
+ IndicatorMapDef *def;
+
+ def = uTypedAlloc(IndicatorMapDef);
+ if (def)
+ {
+ def->common.stmtType = StmtIndicatorMapDef;
+ def->common.next = NULL;
+ def->merge = MergeDefault;
+ def->name = name;
+ def->body = body;
+ }
+ else
+ {
+ FATAL("Couldn't allocate indicator map definition in parser\n");
+ /* NOTREACHED */
+ }
+ return def;
+}
+
+IndicatorNameDef *
+IndicatorNameCreate(int ndx, ExprDef * name, Bool virtual)
+{
+ IndicatorNameDef *def;
+
+ def = uTypedAlloc(IndicatorNameDef);
+ if (def)
+ {
+ def->common.stmtType = StmtIndicatorNameDef;
+ def->common.next = NULL;
+ def->merge = MergeDefault;
+ def->ndx = ndx;
+ def->name = name;
+ def->virtual = virtual;
+ }
+ else
+ {
+ FATAL("Couldn't allocate indicator index definition in parser\n");
+ /* NOTREACHED */
+ }
+ return def;
+}
+
+ExprDef *
+ActionCreate(Atom name, ExprDef * args)
+{
+ ExprDef *act;
+
+ act = uTypedAlloc(ExprDef);
+ if (act)
+ {
+ act->common.stmtType = StmtExpr;
+ act->common.next = NULL;
+ act->op = ExprActionDecl;
+ act->value.action.name = name;
+ act->value.action.args = args;
+ return act;
+ }
+ FATAL("Couldn't allocate ActionDef in parser\n");
+ return NULL;
+}
+
+ExprDef *
+CreateKeysymList(char *sym)
+{
+ ExprDef *def;
+
+ def = ExprCreate(ExprKeysymList, TypeSymbols);
+ if (def)
+ {
+ def->value.list.nSyms = 1;
+ def->value.list.szSyms = 4;
+ def->value.list.syms = uTypedCalloc(4, char *);
+ if (def->value.list.syms != NULL)
+ {
+ def->value.list.syms[0] = sym;
+ return def;
+ }
+ }
+ FATAL("Couldn't allocate expression for keysym list in parser\n");
+ return NULL;
+}
+
+ShapeDef *
+ShapeDeclCreate(Atom name, OutlineDef * outlines)
+{
+ ShapeDef *shape;
+ OutlineDef *ol;
+
+ shape = uTypedAlloc(ShapeDef);
+ if (shape != NULL)
+ {
+ bzero(shape, sizeof(ShapeDef));
+ shape->common.stmtType = StmtShapeDef;
+ shape->common.next = NULL;
+ shape->merge = MergeDefault;
+ shape->name = name;
+ shape->nOutlines = 0;
+ shape->outlines = outlines;
+ for (ol = outlines; ol != NULL; ol = (OutlineDef *) ol->common.next)
+ {
+ if (ol->nPoints > 0)
+ shape->nOutlines++;
+ }
+ }
+ return shape;
+}
+
+OutlineDef *
+OutlineCreate(Atom field, ExprDef * points)
+{
+ OutlineDef *outline;
+ ExprDef *pt;
+
+ outline = uTypedAlloc(OutlineDef);
+ if (outline != NULL)
+ {
+ bzero(outline, sizeof(OutlineDef));
+ outline->common.stmtType = StmtOutlineDef;
+ outline->common.next = NULL;
+ outline->field = field;
+ outline->nPoints = 0;
+ if (points->op == ExprCoord)
+ {
+ for (pt = points; pt != NULL; pt = (ExprDef *) pt->common.next)
+ {
+ outline->nPoints++;
+ }
+ }
+ outline->points = points;
+ }
+ return outline;
+}
+
+KeyDef *
+KeyDeclCreate(char *name, ExprDef * expr)
+{
+ KeyDef *key;
+
+ key = uTypedAlloc(KeyDef);
+ if (key != NULL)
+ {
+ bzero(key, sizeof(KeyDef));
+ key->common.stmtType = StmtKeyDef;
+ key->common.next = NULL;
+ if (name)
+ key->name = name;
+ else
+ key->expr = expr;
+ }
+ return key;
+}
+
+KeyDef *
+KeyDeclMerge(KeyDef * into, KeyDef * from)
+{
+ into->expr =
+ (ExprDef *) AppendStmt(&into->expr->common, &from->expr->common);
+ from->expr = NULL;
+ uFree(from);
+ return into;
+}
+
+RowDef *
+RowDeclCreate(KeyDef * keys)
+{
+ RowDef *row;
+ KeyDef *key;
+
+ row = uTypedAlloc(RowDef);
+ if (row != NULL)
+ {
+ bzero(row, sizeof(RowDef));
+ row->common.stmtType = StmtRowDef;
+ row->common.next = NULL;
+ row->nKeys = 0;
+ row->keys = keys;
+ for (key = keys; key != NULL; key = (KeyDef *) key->common.next)
+ {
+ if (key->common.stmtType == StmtKeyDef)
+ row->nKeys++;
+ }
+ }
+ return row;
+}
+
+SectionDef *
+SectionDeclCreate(Atom name, RowDef * rows)
+{
+ SectionDef *section;
+ RowDef *row;
+
+ section = uTypedAlloc(SectionDef);
+ if (section != NULL)
+ {
+ bzero(section, sizeof(SectionDef));
+ section->common.stmtType = StmtSectionDef;
+ section->common.next = NULL;
+ section->name = name;
+ section->nRows = 0;
+ section->rows = rows;
+ for (row = rows; row != NULL; row = (RowDef *) row->common.next)
+ {
+ if (row->common.stmtType == StmtRowDef)
+ section->nRows++;
+ }
+ }
+ return section;
+}
+
+OverlayKeyDef *
+OverlayKeyCreate(char *under, char *over)
+{
+ OverlayKeyDef *key;
+
+ key = uTypedAlloc(OverlayKeyDef);
+ if (key != NULL)
+ {
+ bzero(key, sizeof(OverlayKeyDef));
+ key->common.stmtType = StmtOverlayKeyDef;
+ strncpy(key->over, over, XkbKeyNameLength);
+ strncpy(key->under, under, XkbKeyNameLength);
+ if (over)
+ uFree(over);
+ if (under)
+ uFree(under);
+ }
+ return key;
+}
+
+OverlayDef *
+OverlayDeclCreate(Atom name, OverlayKeyDef * keys)
+{
+ OverlayDef *ol;
+ OverlayKeyDef *key;
+
+ ol = uTypedAlloc(OverlayDef);
+ if (ol != NULL)
+ {
+ bzero(ol, sizeof(OverlayDef));
+ ol->common.stmtType = StmtOverlayDef;
+ ol->name = name;
+ ol->keys = keys;
+ for (key = keys; key != NULL;
+ key = (OverlayKeyDef *) key->common.next)
+ {
+ ol->nKeys++;
+ }
+ }
+ return ol;
+}
+
+DoodadDef *
+DoodadCreate(unsigned type, Atom name, VarDef * body)
+{
+ DoodadDef *doodad;
+
+ doodad = uTypedAlloc(DoodadDef);
+ if (doodad != NULL)
+ {
+ bzero(doodad, sizeof(DoodadDef));
+ doodad->common.stmtType = StmtDoodadDef;
+ doodad->common.next = NULL;
+ doodad->type = type;
+ doodad->name = name;
+ doodad->body = body;
+ }
+ return doodad;
+}
+
+ExprDef *
+AppendKeysymList(ExprDef * list, char *sym)
+{
+ if (list->value.list.nSyms >= list->value.list.szSyms)
+ {
+ list->value.list.szSyms *= 2;
+ list->value.list.syms = uTypedRecalloc(list->value.list.syms,
+ list->value.list.nSyms,
+ list->value.list.szSyms,
+ char *);
+ if (list->value.list.syms == NULL)
+ {
+ FATAL("Couldn't resize list of symbols for append\n");
+ return NULL;
+ }
+ }
+ list->value.list.syms[list->value.list.nSyms++] = sym;
+ return list;
+}
+
+int
+LookupKeysym(const char *str, KeySym * sym_rtrn)
+{
+ KeySym sym;
+ char *tmp;
+
+ if ((!str) || (uStrCaseCmp(str, "any") == 0)
+ || (uStrCaseCmp(str, "nosymbol") == 0))
+ {
+ *sym_rtrn = NoSymbol;
+ return 1;
+ }
+ else if ((uStrCaseCmp(str, "none") == 0)
+ || (uStrCaseCmp(str, "voidsymbol") == 0))
+ {
+ *sym_rtrn = XK_VoidSymbol;
+ return 1;
+ }
+ sym = XStringToKeysym(str);
+ if (sym != NoSymbol)
+ {
+ *sym_rtrn = sym;
+ return 1;
+ }
+ if (strlen(str) > 2 && str[0] == '0' && str[1] == 'x') {
+ sym = strtoul(str, &tmp, 16);
+ if (sym != ULONG_MAX && (!tmp || *tmp == '\0')) {
+ *sym_rtrn = sym;
+ return 1;
+ }
+ }
+ return 0;
+}
+
+IncludeStmt *
+IncludeCreate(char *str, unsigned merge)
+{
+ IncludeStmt *incl, *first;
+ char *file, *map, *stmt, *tmp, *extra_data;
+ char nextop;
+ Bool haveSelf;
+
+ haveSelf = False;
+ incl = first = NULL;
+ file = map = NULL;
+ tmp = str;
+ stmt = uStringDup(str);
+ while ((tmp) && (*tmp))
+ {
+ if (XkbParseIncludeMap(&tmp, &file, &map, &nextop, &extra_data))
+ {
+ if ((file == NULL) && (map == NULL))
+ {
+ if (haveSelf)
+ goto BAIL;
+ haveSelf = True;
+ }
+ if (first == NULL)
+ first = incl = uTypedAlloc(IncludeStmt);
+ else
+ {
+ incl->next = uTypedAlloc(IncludeStmt);
+ incl = incl->next;
+ }
+ if (incl)
+ {
+ incl->common.stmtType = StmtInclude;
+ incl->common.next = NULL;
+ incl->merge = merge;
+ incl->stmt = NULL;
+ incl->file = file;
+ incl->map = map;
+ incl->modifier = extra_data;
+ incl->path = NULL;
+ incl->next = NULL;
+ }
+ else
+ {
+ WSGO("Allocation failure in IncludeCreate\n");
+ ACTION("Using only part of the include\n");
+ break;
+ }
+ if (nextop == '|')
+ merge = MergeAugment;
+ else
+ merge = MergeOverride;
+ }
+ else
+ {
+ goto BAIL;
+ }
+ }
+ if (first)
+ first->stmt = stmt;
+ else if (stmt)
+ uFree(stmt);
+ return first;
+ BAIL:
+ ERROR1("Illegal include statement \"%s\"\n", stmt);
+ ACTION("Ignored\n");
+ while (first)
+ {
+ incl = first->next;
+ if (first->file)
+ uFree(first->file);
+ if (first->map)
+ uFree(first->map);
+ if (first->modifier)
+ uFree(first->modifier);
+ if (first->path)
+ uFree(first->path);
+ first->file = first->map = first->path = NULL;
+ uFree(first);
+ first = incl;
+ }
+ if (stmt)
+ uFree(stmt);
+ return NULL;
+}
+
+#ifdef DEBUG
+void
+PrintStmtAddrs(ParseCommon * stmt)
+{
+ fprintf(stderr, "0x%x", stmt);
+ if (stmt)
+ {
+ do
+ {
+ fprintf(stderr, "->0x%x", stmt->next);
+ stmt = stmt->next;
+ }
+ while (stmt);
+ }
+ fprintf(stderr, "\n");
+}
+#endif
+
+static void
+CheckDefaultMap(XkbFile * maps)
+{
+ XkbFile *dflt, *tmp;
+
+ dflt = NULL;
+ for (tmp = maps, dflt = NULL; tmp != NULL;
+ tmp = (XkbFile *) tmp->common.next)
+ {
+ if (tmp->flags & XkbLC_Default)
+ {
+ if (dflt == NULL)
+ dflt = tmp;
+ else
+ {
+ if (warningLevel > 2)
+ {
+ WARN1("Multiple default components in %s\n",
+ (scanFile ? scanFile : "(unknown)"));
+ ACTION2("Using %s, ignoring %s\n",
+ (dflt->name ? dflt->name : "(first)"),
+ (tmp->name ? tmp->name : "(subsequent)"));
+ }
+ tmp->flags &= (~XkbLC_Default);
+ }
+ }
+ }
+ return;
+}
+
+int
+XKBParseFile(FILE * file, XkbFile ** pRtrn)
+{
+ if (file)
+ {
+ yyin = file;
+ rtrnValue = NULL;
+ if (yyparse() == 0)
+ {
+ *pRtrn = rtrnValue;
+ CheckDefaultMap(rtrnValue);
+ rtrnValue = NULL;
+ return 1;
+ }
+ *pRtrn = NULL;
+ return 0;
+ }
+ *pRtrn = NULL;
+ return 1;
+}
+
+XkbFile *
+CreateXKBFile(int type, char *name, ParseCommon * defs, unsigned flags)
+{
+ XkbFile *file;
+ static int fileID;
+
+ file = uTypedAlloc(XkbFile);
+ if (file)
+ {
+ XkbEnsureSafeMapName(name);
+ bzero(file, sizeof(XkbFile));
+ file->type = type;
+ file->topName = uStringDup(name);
+ file->name = name;
+ file->defs = defs;
+ file->id = fileID++;
+ file->compiled = False;
+ file->flags = flags;
+ }
+ return file;
+}
+
+unsigned
+StmtSetMerge(ParseCommon * stmt, unsigned merge)
+{
+ if ((merge == MergeAltForm) && (stmt->stmtType != StmtKeycodeDef))
+ {
+ yyerror("illegal use of 'alternate' merge mode");
+ merge = MergeDefault;
+ }
+ return merge;
+}
diff --git a/xkbcomp/parseutils.h b/xkbcomp/parseutils.h
index 9d78ad6bf..8b8a6c11d 100644
--- a/xkbcomp/parseutils.h
+++ b/xkbcomp/parseutils.h
@@ -1,208 +1,208 @@
-/************************************************************
- Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
-
- Permission to use, copy, modify, and distribute this
- software and its documentation for any purpose and without
- fee is hereby granted, provided that the above copyright
- notice appear in all copies and that both that copyright
- notice and this permission notice appear in supporting
- documentation, and that the name of Silicon Graphics not be
- used in advertising or publicity pertaining to distribution
- of the software without specific prior written permission.
- Silicon Graphics makes no representation about the suitability
- of this software for any purpose. It is provided "as is"
- without any express or implied warranty.
-
- SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
- SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
- GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
- DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
- THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
- ********************************************************/
-
-#ifndef XKBPARSE_H
-#define XKBPARSE_H 1
-
-#ifndef DEBUG_VAR
-#define DEBUG_VAR parseDebug
-#endif
-
-#include "xkbcomp.h"
-
-extern char scanBuf[1024];
-extern int scanInt;
-extern int lineNum;
-
-extern XkbFile *rtrnValue;
-
-#ifdef DEBUG
-#define d(str) fprintf(stderr,"%s\n",str);
-#define d1(str,a) fprintf(stderr,str,a);
-#define d2(str,a,b) fprintf(stderr,str,a,b);
-#else
-#define d(str)
-#define d1(str,a)
-#define d2(str,a,b)
-#endif
-
-
-extern ParseCommon *AppendStmt(ParseCommon * /* to */ ,
- ParseCommon * /* append */
- );
-
-extern ExprDef *ExprCreate(unsigned /* op */ ,
- unsigned /* type */
- );
-
-extern ExprDef *ExprCreateUnary(unsigned /* op */ ,
- unsigned /* type */ ,
- ExprDef * /* child */
- );
-
-extern ExprDef *ExprCreateBinary(unsigned /* op */ ,
- ExprDef * /* left */ ,
- ExprDef * /* right */
- );
-
-extern KeycodeDef *KeycodeCreate(char * /* name */ ,
- ExprDef * /* value */
- );
-
-extern KeyAliasDef *KeyAliasCreate(char * /* alias */ ,
- char * /* real */
- );
-
-extern VModDef *VModCreate(Atom /* name */ ,
- ExprDef * /* value */
- );
-
-extern VarDef *VarCreate(ExprDef * /* name */ ,
- ExprDef * /* value */
- );
-
-extern VarDef *BoolVarCreate(Atom /* nameToken */ ,
- unsigned /* set */
- );
-
-extern InterpDef *InterpCreate(KeySym /* sym */ ,
- ExprDef * /* match */
- );
-
-extern KeyTypeDef *KeyTypeCreate(Atom /* name */ ,
- VarDef * /* body */
- );
-
-extern SymbolsDef *SymbolsCreate(char * /* keyName */ ,
- ExprDef * /* symbols */
- );
-
-extern GroupCompatDef *GroupCompatCreate(int /* group */ ,
- ExprDef * /* def */
- );
-
-extern ModMapDef *ModMapCreate(Atom /* modifier */ ,
- ExprDef * /* keys */
- );
-
-extern IndicatorMapDef *IndicatorMapCreate(Atom /* name */ ,
- VarDef * /* body */
- );
-
-extern IndicatorNameDef *IndicatorNameCreate(int /* ndx */ ,
- ExprDef * /* name */ ,
- Bool /* virtual */
- );
-
-extern ExprDef *ActionCreate(Atom /* name */ ,
- ExprDef * /* args */
- );
-
-extern ExprDef *CreateKeysymList(char * /* sym */
- );
-
-extern ShapeDef *ShapeDeclCreate(Atom /* name */ ,
- OutlineDef * /* outlines */
- );
-
-extern OutlineDef *OutlineCreate(Atom /* field */ ,
- ExprDef * /* points */
- );
-
-extern KeyDef *KeyDeclCreate(char * /* name */ ,
- ExprDef * /* expr */
- );
-
-extern KeyDef *KeyDeclMerge(KeyDef * /* into */ ,
- KeyDef * /* from */
- );
-
-extern RowDef *RowDeclCreate(KeyDef * /* keys */
- );
-
-extern SectionDef *SectionDeclCreate(Atom /* name */ ,
- RowDef * /* rows */
- );
-
-extern OverlayKeyDef *OverlayKeyCreate(char * /* under */ ,
- char * /* over */
- );
-
-extern OverlayDef *OverlayDeclCreate(Atom /* name */ ,
- OverlayKeyDef * /* rows */
- );
-
-extern DoodadDef *DoodadCreate(unsigned /* type */ ,
- Atom /* name */ ,
- VarDef * /* body */
- );
-
-extern ExprDef *AppendKeysymList(ExprDef * /* list */ ,
- char * /* sym */
- );
-
-extern int LookupKeysym(char * /* str */ ,
- KeySym * /* sym_rtrn */
- );
-
-extern IncludeStmt *IncludeCreate(char * /* str */ ,
- unsigned /* merge */
- );
-
-extern unsigned StmtSetMerge(ParseCommon * /* stmt */ ,
- unsigned /* merge */
- );
-
-#ifdef DEBUG
-extern void PrintStmtAddrs(ParseCommon * /* stmt */
- );
-#endif
-
-extern int XKBParseFile(FILE * /* file */ ,
- XkbFile ** /* pRtrn */
- );
-
-extern XkbFile *CreateXKBFile(int /* type */ ,
- char * /* name */ ,
- ParseCommon * /* defs */ ,
- unsigned /* flags */
- );
-
-extern void yyerror(const char * /* s */
- );
-
-extern int yywrap(void);
-
-extern int yylex(void);
-extern int yyparse(void);
-
-extern int setScanState(char * /* file */ ,
- int /* line */
- );
-
-extern FILE *yyin;
-
-#endif /* XKBPARSE_H */
+/************************************************************
+ Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
+
+ Permission to use, copy, modify, and distribute this
+ software and its documentation for any purpose and without
+ fee is hereby granted, provided that the above copyright
+ notice appear in all copies and that both that copyright
+ notice and this permission notice appear in supporting
+ documentation, and that the name of Silicon Graphics not be
+ used in advertising or publicity pertaining to distribution
+ of the software without specific prior written permission.
+ Silicon Graphics makes no representation about the suitability
+ of this software for any purpose. It is provided "as is"
+ without any express or implied warranty.
+
+ SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+ GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
+ THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+ ********************************************************/
+
+#ifndef XKBPARSE_H
+#define XKBPARSE_H 1
+
+#ifndef DEBUG_VAR
+#define DEBUG_VAR parseDebug
+#endif
+
+#include "xkbcomp.h"
+
+extern char scanBuf[1024];
+extern int scanInt;
+extern int lineNum;
+
+extern XkbFile *rtrnValue;
+
+#ifdef DEBUG
+#define d(str) fprintf(stderr,"%s\n",str);
+#define d1(str,a) fprintf(stderr,str,a);
+#define d2(str,a,b) fprintf(stderr,str,a,b);
+#else
+#define d(str)
+#define d1(str,a)
+#define d2(str,a,b)
+#endif
+
+
+extern ParseCommon *AppendStmt(ParseCommon * /* to */ ,
+ ParseCommon * /* append */
+ );
+
+extern ExprDef *ExprCreate(unsigned /* op */ ,
+ unsigned /* type */
+ );
+
+extern ExprDef *ExprCreateUnary(unsigned /* op */ ,
+ unsigned /* type */ ,
+ ExprDef * /* child */
+ );
+
+extern ExprDef *ExprCreateBinary(unsigned /* op */ ,
+ ExprDef * /* left */ ,
+ ExprDef * /* right */
+ );
+
+extern KeycodeDef *KeycodeCreate(char * /* name */ ,
+ ExprDef * /* value */
+ );
+
+extern KeyAliasDef *KeyAliasCreate(char * /* alias */ ,
+ char * /* real */
+ );
+
+extern VModDef *VModCreate(Atom /* name */ ,
+ ExprDef * /* value */
+ );
+
+extern VarDef *VarCreate(ExprDef * /* name */ ,
+ ExprDef * /* value */
+ );
+
+extern VarDef *BoolVarCreate(Atom /* nameToken */ ,
+ unsigned /* set */
+ );
+
+extern InterpDef *InterpCreate(const char * /* sym_str */ ,
+ ExprDef * /* match */
+ );
+
+extern KeyTypeDef *KeyTypeCreate(Atom /* name */ ,
+ VarDef * /* body */
+ );
+
+extern SymbolsDef *SymbolsCreate(char * /* keyName */ ,
+ ExprDef * /* symbols */
+ );
+
+extern GroupCompatDef *GroupCompatCreate(int /* group */ ,
+ ExprDef * /* def */
+ );
+
+extern ModMapDef *ModMapCreate(Atom /* modifier */ ,
+ ExprDef * /* keys */
+ );
+
+extern IndicatorMapDef *IndicatorMapCreate(Atom /* name */ ,
+ VarDef * /* body */
+ );
+
+extern IndicatorNameDef *IndicatorNameCreate(int /* ndx */ ,
+ ExprDef * /* name */ ,
+ Bool /* virtual */
+ );
+
+extern ExprDef *ActionCreate(Atom /* name */ ,
+ ExprDef * /* args */
+ );
+
+extern ExprDef *CreateKeysymList(char * /* sym */
+ );
+
+extern ShapeDef *ShapeDeclCreate(Atom /* name */ ,
+ OutlineDef * /* outlines */
+ );
+
+extern OutlineDef *OutlineCreate(Atom /* field */ ,
+ ExprDef * /* points */
+ );
+
+extern KeyDef *KeyDeclCreate(char * /* name */ ,
+ ExprDef * /* expr */
+ );
+
+extern KeyDef *KeyDeclMerge(KeyDef * /* into */ ,
+ KeyDef * /* from */
+ );
+
+extern RowDef *RowDeclCreate(KeyDef * /* keys */
+ );
+
+extern SectionDef *SectionDeclCreate(Atom /* name */ ,
+ RowDef * /* rows */
+ );
+
+extern OverlayKeyDef *OverlayKeyCreate(char * /* under */ ,
+ char * /* over */
+ );
+
+extern OverlayDef *OverlayDeclCreate(Atom /* name */ ,
+ OverlayKeyDef * /* rows */
+ );
+
+extern DoodadDef *DoodadCreate(unsigned /* type */ ,
+ Atom /* name */ ,
+ VarDef * /* body */
+ );
+
+extern ExprDef *AppendKeysymList(ExprDef * /* list */ ,
+ char * /* sym */
+ );
+
+extern int LookupKeysym(const char * /* str */ ,
+ KeySym * /* sym_rtrn */
+ );
+
+extern IncludeStmt *IncludeCreate(char * /* str */ ,
+ unsigned /* merge */
+ );
+
+extern unsigned StmtSetMerge(ParseCommon * /* stmt */ ,
+ unsigned /* merge */
+ );
+
+#ifdef DEBUG
+extern void PrintStmtAddrs(ParseCommon * /* stmt */
+ );
+#endif
+
+extern int XKBParseFile(FILE * /* file */ ,
+ XkbFile ** /* pRtrn */
+ );
+
+extern XkbFile *CreateXKBFile(int /* type */ ,
+ char * /* name */ ,
+ ParseCommon * /* defs */ ,
+ unsigned /* flags */
+ );
+
+extern void yyerror(const char * /* s */
+ );
+
+extern int yywrap(void);
+
+extern int yylex(void);
+extern int yyparse(void);
+
+extern int setScanState(char * /* file */ ,
+ int /* line */
+ );
+
+extern FILE *yyin;
+
+#endif /* XKBPARSE_H */
diff --git a/xkbcomp/xkbcomp.c b/xkbcomp/xkbcomp.c
index c8caf59c5..2a3e8f48a 100644
--- a/xkbcomp/xkbcomp.c
+++ b/xkbcomp/xkbcomp.c
@@ -1,1224 +1,1229 @@
-/************************************************************
- Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
-
- Permission to use, copy, modify, and distribute this
- software and its documentation for any purpose and without
- fee is hereby granted, provided that the above copyright
- notice appear in all copies and that both that copyright
- notice and this permission notice appear in supporting
- documentation, and that the name of Silicon Graphics not be
- used in advertising or publicity pertaining to distribution
- of the software without specific prior written permission.
- Silicon Graphics makes no representation about the suitability
- of this software for any purpose. It is provided "as is"
- without any express or implied warranty.
-
- SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
- SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
- GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
- DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
- THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
- ********************************************************/
-
-#include <stdio.h>
-#include <ctype.h>
-#include <X11/keysym.h>
-
-/* for symlink attack security fix -- Branden Robinson */
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-/* end BR */
-
-#if defined(sgi)
-#include <malloc.h>
-#endif
-
-#define DEBUG_VAR debugFlags
-#include "xkbcomp.h"
-#include <stdlib.h>
-#include "xkbpath.h"
-#include "parseutils.h"
-#include "misc.h"
-#include "tokens.h"
-#include <X11/extensions/XKBgeom.h>
-
-#ifdef __UNIXOS2__
-#define chdir _chdir2
-#endif
-
-#ifdef WIN32
-#define S_IRGRP 0
-#define S_IWGRP 0
-#define S_IROTH 0
-#define S_IWOTH 0
-#endif
-
-#define lowbit(x) ((x) & (-(x)))
-
-/***====================================================================***/
-
-#define WANT_DEFAULT 0
-#define WANT_XKM_FILE 1
-#define WANT_C_HDR 2
-#define WANT_XKB_FILE 3
-#define WANT_X_SERVER 4
-#define WANT_LISTING 5
-
-#define INPUT_UNKNOWN 0
-#define INPUT_XKB 1
-#define INPUT_XKM 2
-
-unsigned int debugFlags;
-
-static const char *fileTypeExt[] = {
- "XXX",
- "xkm",
- "h",
- "xkb",
- "dir"
-};
-
-static unsigned inputFormat, outputFormat;
-char *rootDir;
-static char *inputFile;
-static char *inputMap;
-static char *outputFile;
-static char *inDpyName;
-static char *outDpyName;
-static Display *inDpy;
-static Display *outDpy;
-static Bool showImplicit = False;
-static Bool synch = False;
-static Bool computeDflts = False;
-static Bool xkblist = False;
-unsigned warningLevel = 5;
-unsigned verboseLevel = 0;
-unsigned dirsToStrip = 0;
-unsigned optionalParts = 0;
-static char *preErrorMsg = NULL;
-static char *postErrorMsg = NULL;
-static char *errorPrefix = NULL;
-static unsigned int device_id = XkbUseCoreKbd;
-
-/***====================================================================***/
-
-#define M(m) fprintf(stderr,(m))
-#define M1(m,a) fprintf(stderr,(m),(a))
-
-static void
-Usage(int argc, char *argv[])
-{
- if (!xkblist)
- M1("Usage: %s [options] input-file [ output-file ]\n", argv[0]);
- else
- M1("Usage: %s [options] file[(map)] ...\n", argv[0]);
- M("Legal options:\n");
- M("-?,-help Print this message\n");
- if (!xkblist)
- {
- M("-a Show all actions\n");
- M("-C Create a C header file\n");
- }
-#ifdef DEBUG
- M("-d [flags] Report debugging information\n");
-#endif
- M("-em1 <msg> Print <msg> before printing first error message\n");
- M("-emp <msg> Print <msg> at the start of each message line\n");
- M("-eml <msg> If there were any errors, print <msg> before exiting\n");
- if (!xkblist)
- {
- M("-dflts Compute defaults for missing parts\n");
- M("-I[<dir>] Specifies a top level directory for include\n");
- M(" directives. Multiple directories are legal.\n");
- M("-l [flags] List matching maps in the specified files\n");
- M(" f: list fully specified names\n");
- M(" h: also list hidden maps\n");
- M(" l: long listing (show flags)\n");
- M(" p: also list partial maps\n");
- M(" R: recursively list subdirectories\n");
- M(" default is all options off\n");
- }
- M("-i <deviceid> Specifies device ID (not name) to compile for\n");
- M("-m[ap] <map> Specifies map to compile\n");
- M("-o <file> Specifies output file name\n");
- if (!xkblist)
- {
- M("-opt[ional] <parts> Specifies optional components of keymap\n");
- M(" Errors in optional parts are not fatal\n");
- M(" <parts> can be any combination of:\n");
- M(" c: compat map g: geometry\n");
- M(" k: keycodes s: symbols\n");
- M(" t: types\n");
- }
- if (xkblist)
- {
- M("-p <count> Specifies the number of slashes to be stripped\n");
- M(" from the front of the map name on output\n");
- }
- M("-R[<DIR>] Specifies the root directory for\n");
- M(" relative path names\n");
- M("-synch Force synchronization\n");
- if (xkblist)
- {
- M("-v [<flags>] Set level of detail for listing.\n");
- M(" flags are as for the -l option\n");
- }
- M("-w [<lvl>] Set warning level (0=none, 10=all)\n");
- if (!xkblist)
- {
- M("-xkb Create an XKB source (.xkb) file\n");
- M("-xkm Create a compiled key map (.xkm) file\n");
- }
- return;
-}
-
-/***====================================================================***/
-
-static void
-setVerboseFlags(char *str)
-{
- for (; *str; str++)
- {
- switch (*str)
- {
- case 'f':
- verboseLevel |= WantFullNames;
- break;
- case 'h':
- verboseLevel |= WantHiddenMaps;
- break;
- case 'l':
- verboseLevel |= WantLongListing;
- break;
- case 'p':
- verboseLevel |= WantPartialMaps;
- break;
- case 'R':
- verboseLevel |= ListRecursive;
- break;
- default:
- if (warningLevel > 4)
- {
- WARN1("Unknown verbose option \"%c\"\n", (unsigned int) *str);
- ACTION("Ignored\n");
- }
- break;
- }
- }
- return;
-}
-
-static Bool
-parseArgs(int argc, char *argv[])
-{
- register int i, tmp;
-
- i = strlen(argv[0]);
- tmp = strlen("xkblist");
- if ((i >= tmp) && (strcmp(&argv[0][i - tmp], "xkblist") == 0))
- {
- xkblist = True;
- }
- for (i = 1; i < argc; i++)
- {
- int itmp;
- if ((argv[i][0] != '-') || (uStringEqual(argv[i], "-")))
- {
- if (!xkblist)
- {
- if (inputFile == NULL)
- inputFile = argv[i];
- else if (outputFile == NULL)
- outputFile = argv[i];
- else if (warningLevel > 0)
- {
- WARN("Too many file names on command line\n");
- ACTION3
- ("Compiling %s, writing to %s, ignoring %s\n",
- inputFile, outputFile, argv[i]);
- }
- }
- else if (!AddMatchingFiles(argv[i]))
- return False;
- }
- else if ((strcmp(argv[i], "-?") == 0)
- || (strcmp(argv[i], "-help") == 0))
- {
- Usage(argc, argv);
- exit(0);
- }
- else if ((strcmp(argv[i], "-a") == 0) && (!xkblist))
- {
- showImplicit = True;
- }
- else if ((strcmp(argv[i], "-C") == 0) && (!xkblist))
- {
- if ((outputFormat != WANT_DEFAULT)
- && (outputFormat != WANT_C_HDR))
- {
- if (warningLevel > 0)
- {
- WARN("Multiple output file formats specified\n");
- ACTION1("\"%s\" flag ignored\n", argv[i]);
- }
- }
- else
- outputFormat = WANT_C_HDR;
- }
-#ifdef DEBUG
- else if (strcmp(argv[i], "-d") == 0)
- {
- if ((i >= (argc - 1)) || (!isdigit(argv[i + 1][0])))
- {
- debugFlags = 1;
- }
- else
- {
- if (sscanf(argv[++i], "%i", &itmp) == 1)
- debugFlags = itmp;
- }
- INFO1("Setting debug flags to %d\n", debugFlags);
- }
-#endif
- else if ((strcmp(argv[i], "-dflts") == 0) && (!xkblist))
- {
- computeDflts = True;
- }
- else if (strcmp(argv[i], "-em1") == 0)
- {
- if (++i >= argc)
- {
- if (warningLevel > 0)
- {
- WARN("No pre-error message specified\n");
- ACTION("Trailing \"-em1\" option ignored\n");
- }
- }
- else if (preErrorMsg != NULL)
- {
- if (warningLevel > 0)
- {
- WARN("Multiple pre-error messsages specified\n");
- ACTION2("Compiling %s, ignoring %s\n",
- preErrorMsg, argv[i]);
- }
- }
- else
- preErrorMsg = argv[i];
- }
- else if (strcmp(argv[i], "-emp") == 0)
- {
- if (++i >= argc)
- {
- if (warningLevel > 0)
- {
- WARN("No error prefix specified\n");
- ACTION("Trailing \"-emp\" option ignored\n");
- }
- }
- else if (errorPrefix != NULL)
- {
- if (warningLevel > 0)
- {
- WARN("Multiple error prefixes specified\n");
- ACTION2("Compiling %s, ignoring %s\n",
- errorPrefix, argv[i]);
- }
- }
- else
- errorPrefix = argv[i];
- }
- else if (strcmp(argv[i], "-eml") == 0)
- {
- if (++i >= argc)
- {
- if (warningLevel > 0)
- {
- WARN("No post-error message specified\n");
- ACTION("Trailing \"-eml\" option ignored\n");
- }
- }
- else if (postErrorMsg != NULL)
- {
- if (warningLevel > 0)
- {
- WARN("Multiple post-error messages specified\n");
- ACTION2("Compiling %s, ignoring %s\n",
- postErrorMsg, argv[i]);
- }
- }
- else
- postErrorMsg = argv[i];
- }
- else if ((strncmp(argv[i], "-I", 2) == 0) && (!xkblist))
- {
- if (!XkbAddDirectoryToPath(&argv[i][2]))
- {
- ACTION("Exiting\n");
- exit(1);
- }
- }
- else if ((strncmp(argv[i], "-i", 2) == 0) && (!xkblist))
- {
- if (++i >= argc)
- {
- if (warningLevel > 0)
- WARN("No device ID specified\n");
- }
- device_id = atoi(argv[i]);
- }
- else if ((strncmp(argv[i], "-l", 2) == 0) && (!xkblist))
- {
- if (outputFormat != WANT_DEFAULT)
- {
- if (warningLevel > 0)
- {
- WARN("Multiple output file formats specified\n");
- ACTION1("\"%s\" flag ignored\n", argv[i]);
- }
- }
- else
- {
- if (argv[i][2] != '\0')
- setVerboseFlags(&argv[i][2]);
- xkblist = True;
- if ((inputFile) && (!AddMatchingFiles(inputFile)))
- return False;
- else
- inputFile = NULL;
- if ((outputFile) && (!AddMatchingFiles(outputFile)))
- return False;
- else
- outputFile = NULL;
- }
- }
- else if ((strcmp(argv[i], "-m") == 0)
- || (strcmp(argv[i], "-map") == 0))
- {
- if (++i >= argc)
- {
- if (warningLevel > 0)
- {
- WARN("No map name specified\n");
- ACTION1("Trailing \"%s\" option ignored\n", argv[i - 1]);
- }
- }
- else if (xkblist)
- {
- if (!AddMapOnly(argv[i]))
- return False;
- }
- else if (inputMap != NULL)
- {
- if (warningLevel > 0)
- {
- WARN("Multiple map names specified\n");
- ACTION2("Compiling %s, ignoring %s\n", inputMap, argv[i]);
- }
- }
- else
- inputMap = argv[i];
- }
- else if ((strcmp(argv[i], "-merge") == 0) && (!xkblist))
- {
- /* Ignored */
- }
- else if (strcmp(argv[i], "-o") == 0)
- {
- if (++i >= argc)
- {
- if (warningLevel > 0)
- {
- WARN("No output file specified\n");
- ACTION("Trailing \"-o\" option ignored\n");
- }
- }
- else if (outputFile != NULL)
- {
- if (warningLevel > 0)
- {
- WARN("Multiple output files specified\n");
- ACTION2("Compiling %s, ignoring %s\n", outputFile,
- argv[i]);
- }
- }
- else
- outputFile = argv[i];
- }
- else if (((strcmp(argv[i], "-opt") == 0)
- || (strcmp(argv[i], "optional") == 0)) && (!xkblist))
- {
- if (++i >= argc)
- {
- if (warningLevel > 0)
- {
- WARN("No optional components specified\n");
- ACTION1("Trailing \"%s\" option ignored\n", argv[i - 1]);
- }
- }
- else
- {
- char *tmp2;
- for (tmp2 = argv[i]; (*tmp2 != '\0'); tmp2++)
- {
- switch (*tmp2)
- {
- case 'c':
- case 'C':
- optionalParts |= XkmCompatMapMask;
- break;
- case 'g':
- case 'G':
- optionalParts |= XkmGeometryMask;
- break;
- case 'k':
- case 'K':
- optionalParts |= XkmKeyNamesMask;
- break;
- case 's':
- case 'S':
- optionalParts |= XkmSymbolsMask;
- break;
- case 't':
- case 'T':
- optionalParts |= XkmTypesMask;
- break;
- default:
- if (warningLevel > 0)
- {
- WARN1
- ("Illegal component for %s option\n",
- argv[i - 1]);
- ACTION1
- ("Ignoring unknown specifier \"%c\"\n",
- (unsigned int) *tmp2);
- }
- break;
- }
- }
- }
- }
- else if (strncmp(argv[i], "-p", 2) == 0)
- {
- if (isdigit(argv[i][2]))
- {
- if (sscanf(&argv[i][2], "%i", &itmp) == 1)
- dirsToStrip = itmp;
- }
- else if ((i < (argc - 1)) && (isdigit(argv[i + 1][0])))
- {
- if (sscanf(argv[++i], "%i", &itmp) == 1)
- dirsToStrip = itmp;
- }
- else
- {
- dirsToStrip = 0;
- }
- if (warningLevel > 5)
- INFO1("Setting path count to %d\n", dirsToStrip);
- }
- else if (strncmp(argv[i], "-R", 2) == 0)
- {
- if (argv[i][2] == '\0')
- {
- if (warningLevel > 0)
- {
- WARN("No root directory specified\n");
- ACTION("Ignoring -R option\n");
- }
- }
- else if (rootDir != NULL)
- {
- if (warningLevel > 0)
- {
- WARN("Multiple root directories specified\n");
- ACTION2("Using %s, ignoring %s\n", rootDir, argv[i]);
- }
- }
- else
- {
- rootDir = &argv[i][2];
- if (warningLevel > 8)
- {
- WARN1("Changing root directory to \"%s\"\n", rootDir);
- }
- if ((chdir(rootDir) < 0) && (warningLevel > 0))
- {
- WARN1("Couldn't change directory to \"%s\"\n", rootDir);
- ACTION("Root directory (-R) option ignored\n");
- rootDir = NULL;
- }
- }
- }
- else if ((strcmp(argv[i], "-synch") == 0)
- || (strcmp(argv[i], "-s") == 0))
- {
- synch = True;
- }
- else if (strncmp(argv[i], "-v", 2) == 0)
- {
- char *str;
- if (argv[i][2] != '\0')
- str = &argv[i][2];
- else if ((i < (argc - 1)) && (argv[i + 1][0] != '-'))
- str = argv[++i];
- else
- str = NULL;
- if (str)
- setVerboseFlags(str);
- }
- else if (strncmp(argv[i], "-w", 2) == 0)
- {
- if ((i >= (argc - 1)) || (!isdigit(argv[i + 1][0])))
- {
- warningLevel = 0;
- if (isdigit(argv[i][1]))
- if (sscanf(&argv[i][1], "%i", &itmp) == 1)
- warningLevel = itmp;
- }
- else
- {
- if (sscanf(argv[++i], "%i", &itmp) == 1)
- warningLevel = itmp;
- }
- }
- else if ((strcmp(argv[i], "-xkb") == 0) && (!xkblist))
- {
- if ((outputFormat != WANT_DEFAULT)
- && (outputFormat != WANT_XKB_FILE))
- {
- if (warningLevel > 0)
- {
- WARN("Multiple output file formats specified\n");
- ACTION1("\"%s\" flag ignored\n", argv[i]);
- }
- }
- else
- outputFormat = WANT_XKB_FILE;
- }
- else if ((strcmp(argv[i], "-xkm") == 0) && (!xkblist))
- {
- if ((outputFormat != WANT_DEFAULT)
- && (outputFormat != WANT_XKM_FILE))
- {
- if (warningLevel > 0)
- {
- WARN("Multiple output file formats specified\n");
- ACTION1("\"%s\" flag ignored\n", argv[i]);
- }
- }
- else
- outputFormat = WANT_XKM_FILE;
- }
- else
- {
- ERROR1("Unknown flag \"%s\" on command line\n", argv[i]);
- Usage(argc, argv);
- return False;
- }
- }
- if (xkblist)
- inputFormat = INPUT_XKB;
- else if (inputFile == NULL)
- {
- ERROR("No input file specified\n");
- return False;
- }
- else if (uStringEqual(inputFile, "-"))
- {
- inputFormat = INPUT_XKB;
- }
-#ifndef WIN32
- else if (strchr(inputFile, ':') == NULL)
- {
-#else
- else if ((strchr(inputFile, ':') == NULL) || (strlen(inputFile) > 2 &&
- isalpha(inputFile[0]) &&
- inputFile[1] == ':'
- && strchr(inputFile + 2,
- ':') == NULL))
- {
-#endif
- int len;
- len = strlen(inputFile);
- if (inputFile[len - 1] == ')')
- {
- char *tmp;
- if ((tmp = strchr(inputFile, '(')) != NULL)
- {
- *tmp = '\0';
- inputFile[len - 1] = '\0';
- tmp++;
- if (*tmp == '\0')
- {
- WARN("Empty map in filename\n");
- ACTION("Ignored\n");
- }
- else if (inputMap == NULL)
- {
- inputMap = uStringDup(tmp);
- }
- else
- {
- WARN("Map specified in filename and with -m flag\n");
- ACTION1("map from name (\"%s\") ignored\n", tmp);
- }
- }
- else
- {
- ERROR1("Illegal name \"%s\" for input file\n", inputFile);
- return False;
- }
- }
- if ((len > 4) && (strcmp(&inputFile[len - 4], ".xkm") == 0))
- {
- inputFormat = INPUT_XKM;
- }
- else
- {
- FILE *file;
- file = fopen(inputFile, "r");
- if (file)
- {
- if (XkmProbe(file))
- inputFormat = INPUT_XKM;
- else
- inputFormat = INPUT_XKB;
- fclose(file);
- }
- else
- {
- fprintf(stderr, "Cannot open \"%s\" for reading\n",
- inputFile);
- return False;
- }
- }
- }
- else
- {
- inDpyName = inputFile;
- inputFile = NULL;
- inputFormat = INPUT_XKM;
- }
-
- if (outputFormat == WANT_DEFAULT)
- {
- if (xkblist)
- outputFormat = WANT_LISTING;
- else if (inputFormat == INPUT_XKB)
- outputFormat = WANT_XKM_FILE;
- else
- outputFormat = WANT_XKB_FILE;
- }
- if ((outputFormat == WANT_LISTING) && (inputFormat != INPUT_XKB))
- {
- if (inputFile)
- ERROR("Cannot generate a listing from a .xkm file (yet)\n");
- else
- ERROR("Cannot generate a listing from an X connection (yet)\n");
- return False;
- }
- if (xkblist)
- {
- if (outputFile == NULL)
- outputFile = uStringDup("-");
- else if (strchr(outputFile, ':') != NULL)
- {
- ERROR("Cannot write a listing to an X connection\n");
- return False;
- }
- }
- else if ((!outputFile) && (inputFile) && uStringEqual(inputFile, "-"))
- {
- int len = strlen("stdin") + strlen(fileTypeExt[outputFormat]) + 2;
- outputFile = uTypedCalloc(len, char);
- if (outputFile == NULL)
- {
- WSGO("Cannot allocate space for output file name\n");
- ACTION("Exiting\n");
- exit(1);
- }
- sprintf(outputFile, "stdin.%s", fileTypeExt[outputFormat]);
- }
- else if ((outputFile == NULL) && (inputFile != NULL))
- {
- int len;
- char *base, *ext;
-
- if (inputMap == NULL)
- {
- base = strrchr(inputFile, '/');
- if (base == NULL)
- base = inputFile;
- else
- base++;
- }
- else
- base = inputMap;
-
- len = strlen(base) + strlen(fileTypeExt[outputFormat]) + 2;
- outputFile = uTypedCalloc(len, char);
- if (outputFile == NULL)
- {
- WSGO("Cannot allocate space for output file name\n");
- ACTION("Exiting\n");
- exit(1);
- }
- ext = strrchr(base, '.');
- if (ext == NULL)
- sprintf(outputFile, "%s.%s", base, fileTypeExt[outputFormat]);
- else
- {
- strcpy(outputFile, base);
- strcpy(&outputFile[ext - base + 1], fileTypeExt[outputFormat]);
- }
- }
- else if (outputFile == NULL)
- {
- int len;
- char *ch, *name, buf[128];
- if (inDpyName[0] == ':')
- snprintf(name = buf, sizeof(buf), "server%s", inDpyName);
- else
- name = inDpyName;
-
- len = strlen(name) + strlen(fileTypeExt[outputFormat]) + 2;
- outputFile = uTypedCalloc(len, char);
- if (outputFile == NULL)
- {
- WSGO("Cannot allocate space for output file name\n");
- ACTION("Exiting\n");
- exit(1);
- }
- strcpy(outputFile, name);
- for (ch = outputFile; (*ch) != '\0'; ch++)
- {
- if (*ch == ':')
- *ch = '-';
- else if (*ch == '.')
- *ch = '_';
- }
- *ch++ = '.';
- strcpy(ch, fileTypeExt[outputFormat]);
- }
-#ifdef WIN32
- else if (strlen(outputFile) > 2 &&
- isalpha(outputFile[0]) &&
- outputFile[1] == ':' && strchr(outputFile + 2, ':') == NULL)
- {
- }
-#endif
- else if (strchr(outputFile, ':') != NULL)
- {
- outDpyName = outputFile;
- outputFile = NULL;
- outputFormat = WANT_X_SERVER;
- }
- return True;
-}
-
-static Display *
-GetDisplay(char *program, char *dpyName)
-{
- int mjr, mnr, error;
- Display *dpy;
-
- mjr = XkbMajorVersion;
- mnr = XkbMinorVersion;
- dpy = XkbOpenDisplay(dpyName, NULL, NULL, &mjr, &mnr, &error);
- if (dpy == NULL)
- {
- switch (error)
- {
- case XkbOD_BadLibraryVersion:
- INFO3("%s was compiled with XKB version %d.%02d\n",
- program, XkbMajorVersion, XkbMinorVersion);
- ERROR2("X library supports incompatible version %d.%02d\n",
- mjr, mnr);
- break;
- case XkbOD_ConnectionRefused:
- ERROR1("Cannot open display \"%s\"\n", dpyName);
- break;
- case XkbOD_NonXkbServer:
- ERROR1("XKB extension not present on %s\n", dpyName);
- break;
- case XkbOD_BadServerVersion:
- INFO3("%s was compiled with XKB version %d.%02d\n",
- program, XkbMajorVersion, XkbMinorVersion);
- ERROR3("Server %s uses incompatible version %d.%02d\n",
- dpyName, mjr, mnr);
- break;
- default:
- WSGO1("Unknown error %d from XkbOpenDisplay\n", error);
- }
- }
- else if (synch)
- XSynchronize(dpy, True);
- return dpy;
-}
-
-/***====================================================================***/
-
-#ifdef DEBUG
-extern int yydebug;
-#endif
-
-int
-main(int argc, char *argv[])
-{
- FILE *file; /* input file (or stdin) */
- XkbFile *rtrn;
- XkbFile *mapToUse;
- int ok;
- XkbFileInfo result;
- Status status;
-
- yyin = stdin;
- uSetEntryFile(NullString);
- uSetDebugFile(NullString);
- uSetErrorFile(NullString);
-
- XkbInitIncludePath();
- if (!parseArgs(argc, argv))
- exit(1);
-#ifdef DEBUG
- if (debugFlags & 0x2)
- yydebug = 1;
-#endif
- if (preErrorMsg)
- uSetPreErrorMessage(preErrorMsg);
- if (errorPrefix)
- uSetErrorPrefix(errorPrefix);
- if (postErrorMsg)
- uSetPostErrorMessage(postErrorMsg);
- file = NULL;
- XkbInitAtoms(NULL);
- XkbAddDefaultDirectoriesToPath();
- if (xkblist)
- {
- Bool gotSome;
- gotSome = GenerateListing(outputFile);
- if ((warningLevel > 7) && (!gotSome))
- return -1;
- return 0;
- }
- if (inputFile != NULL)
- {
- if (uStringEqual(inputFile, "-"))
- {
- file = stdin;
- inputFile = "stdin";
- }
- else
- {
- file = fopen(inputFile, "r");
- }
- }
- else if (inDpyName != NULL)
- {
- inDpy = GetDisplay(argv[0], inDpyName);
- if (!inDpy)
- {
- ACTION("Exiting\n");
- exit(1);
- }
- }
- if (outDpyName != NULL)
- {
- outDpy = GetDisplay(argv[0], outDpyName);
- if (!outDpy)
- {
- ACTION("Exiting\n");
- exit(1);
- }
- }
- if ((inDpy == NULL) && (outDpy == NULL))
- {
- int mjr, mnr;
- mjr = XkbMajorVersion;
- mnr = XkbMinorVersion;
- if (!XkbLibraryVersion(&mjr, &mnr))
- {
- INFO3("%s was compiled with XKB version %d.%02d\n",
- argv[0], XkbMajorVersion, XkbMinorVersion);
- ERROR2("X library supports incompatible version %d.%02d\n",
- mjr, mnr);
- ACTION("Exiting\n");
- exit(1);
- }
- }
- if (file)
- {
- ok = True;
- setScanState(inputFile, 1);
- if ((inputFormat == INPUT_XKB) /* parse .xkb file */
- && (XKBParseFile(file, &rtrn) && (rtrn != NULL)))
- {
- fclose(file);
- mapToUse = rtrn;
- if (inputMap != NULL) /* map specified on cmdline? */
- {
- while ((mapToUse)
- && (!uStringEqual(mapToUse->name, inputMap)))
- {
- mapToUse = (XkbFile *) mapToUse->common.next;
- }
- if (!mapToUse)
- {
- FATAL2("No map named \"%s\" in \"%s\"\n",
- inputMap, inputFile);
- /* NOTREACHED */
- }
- }
- else if (rtrn->common.next != NULL)
- {
- /* look for map with XkbLC_Default flag. */
- mapToUse = rtrn;
- for (; mapToUse; mapToUse = (XkbFile *) mapToUse->common.next)
- {
- if (mapToUse->flags & XkbLC_Default)
- break;
- }
- if (!mapToUse)
- {
- mapToUse = rtrn;
- if (warningLevel > 4)
- {
- WARN1
- ("No map specified, but \"%s\" has several\n",
- inputFile);
- ACTION1
- ("Using the first defined map, \"%s\"\n",
- mapToUse->name);
- }
- }
- }
- bzero((char *) &result, sizeof(result));
- result.type = mapToUse->type;
- if ((result.xkb = XkbAllocKeyboard()) == NULL)
- {
- WSGO("Cannot allocate keyboard description\n");
- /* NOTREACHED */
- }
- switch (mapToUse->type)
- {
- case XkmSemanticsFile:
- case XkmLayoutFile:
- case XkmKeymapFile:
- ok = CompileKeymap(mapToUse, &result, MergeReplace);
- break;
- case XkmKeyNamesIndex:
- ok = CompileKeycodes(mapToUse, &result, MergeReplace);
- break;
- case XkmTypesIndex:
- ok = CompileKeyTypes(mapToUse, &result, MergeReplace);
- break;
- case XkmSymbolsIndex:
- /* if it's just symbols, invent key names */
- result.xkb->flags |= AutoKeyNames;
- ok = False;
- break;
- case XkmCompatMapIndex:
- ok = CompileCompatMap(mapToUse, &result, MergeReplace, NULL);
- break;
- case XkmGeometryFile:
- case XkmGeometryIndex:
- /* if it's just a geometry, invent key names */
- result.xkb->flags |= AutoKeyNames;
- ok = CompileGeometry(mapToUse, &result, MergeReplace);
- break;
- default:
- WSGO1("Unknown file type %d\n", mapToUse->type);
- ok = False;
- break;
- }
- result.xkb->device_spec = device_id;
- }
- else if (inputFormat == INPUT_XKM) /* parse xkm file */
- {
- unsigned tmp;
- bzero((char *) &result, sizeof(result));
- if ((result.xkb = XkbAllocKeyboard()) == NULL)
- {
- WSGO("Cannot allocate keyboard description\n");
- /* NOTREACHED */
- }
- tmp = XkmReadFile(file, 0, XkmKeymapLegal, &result);
- if (tmp == XkmKeymapLegal)
- {
- ERROR1("Cannot read XKM file \"%s\"\n", inputFile);
- ok = False;
- }
- result.xkb->device_spec = device_id;
- }
- else
- {
- INFO1("Errors encountered in %s; not compiled.\n", inputFile);
- ok = False;
- }
- }
- else if (inDpy != NULL)
- {
- bzero((char *) &result, sizeof(result));
- result.type = XkmKeymapFile;
- result.xkb = XkbGetMap(inDpy, XkbAllMapComponentsMask, device_id);
- if (result.xkb == NULL)
- WSGO("Cannot load keyboard description\n");
- if (XkbGetIndicatorMap(inDpy, ~0, result.xkb) != Success)
- WSGO("Could not load indicator map\n");
- if (XkbGetControls(inDpy, XkbAllControlsMask, result.xkb) != Success)
- WSGO("Could not load keyboard controls\n");
- if (XkbGetCompatMap(inDpy, XkbAllCompatMask, result.xkb) != Success)
- WSGO("Could not load compatibility map\n");
- if (XkbGetNames(inDpy, XkbAllNamesMask, result.xkb) != Success)
- WSGO("Could not load names\n");
- if ((status = XkbGetGeometry(inDpy, result.xkb)) != Success)
- {
- if (warningLevel > 3)
- {
- char buf[100];
- buf[0] = '\0';
- XGetErrorText(inDpy, status, buf, 100);
- WARN1("Could not load keyboard geometry for %s\n", inDpyName);
- ACTION1("%s\n", buf);
- ACTION("Resulting keymap file will not describe geometry\n");
- }
- }
- if (computeDflts)
- ok = (ComputeKbdDefaults(result.xkb) == Success);
- else
- ok = True;
- }
- else
- {
- fprintf(stderr, "Cannot open \"%s\" to compile\n", inputFile);
- ok = 0;
- }
- if (ok)
- {
- FILE *out = stdout;
- if ((inDpy != outDpy) &&
- (XkbChangeKbdDisplay(outDpy, &result) != Success))
- {
- WSGO2("Error converting keyboard display from %s to %s\n",
- inDpyName, outDpyName);
- exit(1);
- }
- if (outputFile != NULL)
- {
- if (uStringEqual(outputFile, "-"))
- outputFile = "stdout";
- else
- {
- /*
- * fix to prevent symlink attack (e.g.,
- * ln -s /etc/passwd /var/tmp/server-0.xkm)
- */
- /*
- * this patch may have POSIX, Linux, or GNU libc bias
- * -- Branden Robinson
- */
- int outputFileFd;
- int binMode = 0;
- const char *openMode = "w";
- unlink(outputFile);
-#ifdef O_BINARY
- switch (outputFormat)
- {
- case WANT_XKM_FILE:
- binMode = O_BINARY;
- openMode = "wb";
- break;
- default:
- binMode = 0;
- break;
- }
-#endif
- outputFileFd =
- open(outputFile, O_WRONLY | O_CREAT | O_EXCL,
- S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH
- | S_IWOTH | binMode);
- if (outputFileFd < 0)
- {
- ERROR1
- ("Cannot open \"%s\" to write keyboard description\n",
- outputFile);
- ACTION("Exiting\n");
- exit(1);
- }
-#ifndef WIN32
- out = fdopen(outputFileFd, openMode);
-#else
- close(outputFileFd);
- out = fopen(outputFile, "wb");
-#endif
- /* end BR */
- if (out == NULL)
- {
- ERROR1
- ("Cannot open \"%s\" to write keyboard description\n",
- outputFile);
- ACTION("Exiting\n");
- exit(1);
- }
- }
- }
- switch (outputFormat)
- {
- case WANT_XKM_FILE:
- ok = XkbWriteXKMFile(out, &result);
- break;
- case WANT_XKB_FILE:
- ok = XkbWriteXKBFile(out, &result, showImplicit, NULL, NULL);
- break;
- case WANT_C_HDR:
- ok = XkbWriteCFile(out, outputFile, &result);
- break;
- case WANT_X_SERVER:
- if (!(ok = XkbWriteToServer(&result)))
- {
- ERROR2("%s in %s\n", _XkbErrMessages[_XkbErrCode],
- _XkbErrLocation ? _XkbErrLocation : "unknown");
- ACTION1("Couldn't write keyboard description to %s\n",
- outDpyName);
- }
- break;
- default:
- WSGO1("Unknown output format %d\n", outputFormat);
- ACTION("No output file created\n");
- ok = False;
- break;
- }
- if (outputFormat != WANT_X_SERVER)
- {
- if (fclose(out))
- {
- ERROR1("Cannot close \"%s\" properly (not enough space?)\n",
- outputFile);
- ok= False;
- }
- else if (!ok)
- {
- ERROR2("%s in %s\n", _XkbErrMessages[_XkbErrCode],
- _XkbErrLocation ? _XkbErrLocation : "unknown");
- }
- if (!ok)
- {
- ACTION1("Output file \"%s\" removed\n", outputFile);
- unlink(outputFile);
- }
- }
- }
- if (inDpy)
- XCloseDisplay(inDpy);
- inDpy = NULL;
- if (outDpy)
- XCloseDisplay(outDpy);
- uFinishUp();
- return (ok == 0);
-}
+/************************************************************
+ Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
+
+ Permission to use, copy, modify, and distribute this
+ software and its documentation for any purpose and without
+ fee is hereby granted, provided that the above copyright
+ notice appear in all copies and that both that copyright
+ notice and this permission notice appear in supporting
+ documentation, and that the name of Silicon Graphics not be
+ used in advertising or publicity pertaining to distribution
+ of the software without specific prior written permission.
+ Silicon Graphics makes no representation about the suitability
+ of this software for any purpose. It is provided "as is"
+ without any express or implied warranty.
+
+ SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+ GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
+ THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+ ********************************************************/
+
+#include <stdio.h>
+#include <ctype.h>
+#include <X11/keysym.h>
+
+/* for symlink attack security fix -- Branden Robinson */
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+/* end BR */
+
+#if defined(sgi)
+#include <malloc.h>
+#endif
+
+#define DEBUG_VAR debugFlags
+#include "xkbcomp.h"
+#include <stdlib.h>
+#include "xkbpath.h"
+#include "parseutils.h"
+#include "misc.h"
+#include "tokens.h"
+#include <X11/extensions/XKBgeom.h>
+
+#ifdef __UNIXOS2__
+#define chdir _chdir2
+#endif
+
+#ifdef WIN32
+#define S_IRGRP 0
+#define S_IWGRP 0
+#define S_IROTH 0
+#define S_IWOTH 0
+#endif
+
+#define lowbit(x) ((x) & (-(x)))
+
+/***====================================================================***/
+
+#define WANT_DEFAULT 0
+#define WANT_XKM_FILE 1
+#define WANT_C_HDR 2
+#define WANT_XKB_FILE 3
+#define WANT_X_SERVER 4
+#define WANT_LISTING 5
+
+#define INPUT_UNKNOWN 0
+#define INPUT_XKB 1
+#define INPUT_XKM 2
+
+unsigned int debugFlags;
+
+static const char *fileTypeExt[] = {
+ "XXX",
+ "xkm",
+ "h",
+ "xkb",
+ "dir"
+};
+
+static unsigned inputFormat, outputFormat;
+char *rootDir;
+static char *inputFile;
+static char *inputMap;
+static char *outputFile;
+static char *inDpyName;
+static char *outDpyName;
+static Display *inDpy;
+static Display *outDpy;
+static Bool showImplicit = False;
+static Bool synch = False;
+static Bool computeDflts = False;
+static Bool xkblist = False;
+unsigned warningLevel = 5;
+unsigned verboseLevel = 0;
+unsigned dirsToStrip = 0;
+unsigned optionalParts = 0;
+static char *preErrorMsg = NULL;
+static char *postErrorMsg = NULL;
+static char *errorPrefix = NULL;
+static unsigned int device_id = XkbUseCoreKbd;
+
+/***====================================================================***/
+
+#define M(m) fprintf(stderr,(m))
+#define M1(m,a) fprintf(stderr,(m),(a))
+
+static void
+Usage(int argc, char *argv[])
+{
+ if (!xkblist)
+ M1("Usage: %s [options] input-file [ output-file ]\n", argv[0]);
+ else
+ M1("Usage: %s [options] file[(map)] ...\n", argv[0]);
+ M("Legal options:\n");
+ M("-?,-help Print this message\n");
+ M("-version Print the version number\n");
+ if (!xkblist)
+ {
+ M("-a Show all actions\n");
+ M("-C Create a C header file\n");
+ }
+#ifdef DEBUG
+ M("-d [flags] Report debugging information\n");
+#endif
+ M("-em1 <msg> Print <msg> before printing first error message\n");
+ M("-emp <msg> Print <msg> at the start of each message line\n");
+ M("-eml <msg> If there were any errors, print <msg> before exiting\n");
+ if (!xkblist)
+ {
+ M("-dflts Compute defaults for missing parts\n");
+ M("-I[<dir>] Specifies a top level directory for include\n");
+ M(" directives. Multiple directories are legal.\n");
+ M("-l [flags] List matching maps in the specified files\n");
+ M(" f: list fully specified names\n");
+ M(" h: also list hidden maps\n");
+ M(" l: long listing (show flags)\n");
+ M(" p: also list partial maps\n");
+ M(" R: recursively list subdirectories\n");
+ M(" default is all options off\n");
+ }
+ M("-i <deviceid> Specifies device ID (not name) to compile for\n");
+ M("-m[ap] <map> Specifies map to compile\n");
+ M("-o <file> Specifies output file name\n");
+ if (!xkblist)
+ {
+ M("-opt[ional] <parts> Specifies optional components of keymap\n");
+ M(" Errors in optional parts are not fatal\n");
+ M(" <parts> can be any combination of:\n");
+ M(" c: compat map g: geometry\n");
+ M(" k: keycodes s: symbols\n");
+ M(" t: types\n");
+ }
+ if (xkblist)
+ {
+ M("-p <count> Specifies the number of slashes to be stripped\n");
+ M(" from the front of the map name on output\n");
+ }
+ M("-R[<DIR>] Specifies the root directory for\n");
+ M(" relative path names\n");
+ M("-synch Force synchronization\n");
+ if (xkblist)
+ {
+ M("-v [<flags>] Set level of detail for listing.\n");
+ M(" flags are as for the -l option\n");
+ }
+ M("-w [<lvl>] Set warning level (0=none, 10=all)\n");
+ if (!xkblist)
+ {
+ M("-xkb Create an XKB source (.xkb) file\n");
+ M("-xkm Create a compiled key map (.xkm) file\n");
+ }
+ return;
+}
+
+/***====================================================================***/
+
+static void
+setVerboseFlags(char *str)
+{
+ for (; *str; str++)
+ {
+ switch (*str)
+ {
+ case 'f':
+ verboseLevel |= WantFullNames;
+ break;
+ case 'h':
+ verboseLevel |= WantHiddenMaps;
+ break;
+ case 'l':
+ verboseLevel |= WantLongListing;
+ break;
+ case 'p':
+ verboseLevel |= WantPartialMaps;
+ break;
+ case 'R':
+ verboseLevel |= ListRecursive;
+ break;
+ default:
+ if (warningLevel > 4)
+ {
+ WARN1("Unknown verbose option \"%c\"\n", (unsigned int) *str);
+ ACTION("Ignored\n");
+ }
+ break;
+ }
+ }
+ return;
+}
+
+static Bool
+parseArgs(int argc, char *argv[])
+{
+ register int i, tmp;
+
+ i = strlen(argv[0]);
+ tmp = strlen("xkblist");
+ if ((i >= tmp) && (strcmp(&argv[0][i - tmp], "xkblist") == 0))
+ {
+ xkblist = True;
+ }
+ for (i = 1; i < argc; i++)
+ {
+ int itmp;
+ if ((argv[i][0] != '-') || (uStringEqual(argv[i], "-")))
+ {
+ if (!xkblist)
+ {
+ if (inputFile == NULL)
+ inputFile = argv[i];
+ else if (outputFile == NULL)
+ outputFile = argv[i];
+ else if (warningLevel > 0)
+ {
+ WARN("Too many file names on command line\n");
+ ACTION3
+ ("Compiling %s, writing to %s, ignoring %s\n",
+ inputFile, outputFile, argv[i]);
+ }
+ }
+ else if (!AddMatchingFiles(argv[i]))
+ return False;
+ }
+ else if ((strcmp(argv[i], "-?") == 0)
+ || (strcmp(argv[i], "-help") == 0))
+ {
+ Usage(argc, argv);
+ exit(0);
+ }
+ else if (strcmp(argv[i], "-version") == 0)
+ {
+ printf("xkbcomp %s\n", PACKAGE_VERSION);
+ exit(0);
+ } else if ((strcmp(argv[i], "-a") == 0) && (!xkblist))
+ {
+ showImplicit = True;
+ }
+ else if ((strcmp(argv[i], "-C") == 0) && (!xkblist))
+ {
+ if ((outputFormat != WANT_DEFAULT)
+ && (outputFormat != WANT_C_HDR))
+ {
+ if (warningLevel > 0)
+ {
+ WARN("Multiple output file formats specified\n");
+ ACTION1("\"%s\" flag ignored\n", argv[i]);
+ }
+ }
+ else
+ outputFormat = WANT_C_HDR;
+ }
+#ifdef DEBUG
+ else if (strcmp(argv[i], "-d") == 0)
+ {
+ if ((i >= (argc - 1)) || (!isdigit(argv[i + 1][0])))
+ {
+ debugFlags = 1;
+ }
+ else
+ {
+ if (sscanf(argv[++i], "%i", &itmp) == 1)
+ debugFlags = itmp;
+ }
+ INFO1("Setting debug flags to %d\n", debugFlags);
+ }
+#endif
+ else if ((strcmp(argv[i], "-dflts") == 0) && (!xkblist))
+ {
+ computeDflts = True;
+ }
+ else if (strcmp(argv[i], "-em1") == 0)
+ {
+ if (++i >= argc)
+ {
+ if (warningLevel > 0)
+ {
+ WARN("No pre-error message specified\n");
+ ACTION("Trailing \"-em1\" option ignored\n");
+ }
+ }
+ else if (preErrorMsg != NULL)
+ {
+ if (warningLevel > 0)
+ {
+ WARN("Multiple pre-error messsages specified\n");
+ ACTION2("Compiling %s, ignoring %s\n",
+ preErrorMsg, argv[i]);
+ }
+ }
+ else
+ preErrorMsg = argv[i];
+ }
+ else if (strcmp(argv[i], "-emp") == 0)
+ {
+ if (++i >= argc)
+ {
+ if (warningLevel > 0)
+ {
+ WARN("No error prefix specified\n");
+ ACTION("Trailing \"-emp\" option ignored\n");
+ }
+ }
+ else if (errorPrefix != NULL)
+ {
+ if (warningLevel > 0)
+ {
+ WARN("Multiple error prefixes specified\n");
+ ACTION2("Compiling %s, ignoring %s\n",
+ errorPrefix, argv[i]);
+ }
+ }
+ else
+ errorPrefix = argv[i];
+ }
+ else if (strcmp(argv[i], "-eml") == 0)
+ {
+ if (++i >= argc)
+ {
+ if (warningLevel > 0)
+ {
+ WARN("No post-error message specified\n");
+ ACTION("Trailing \"-eml\" option ignored\n");
+ }
+ }
+ else if (postErrorMsg != NULL)
+ {
+ if (warningLevel > 0)
+ {
+ WARN("Multiple post-error messages specified\n");
+ ACTION2("Compiling %s, ignoring %s\n",
+ postErrorMsg, argv[i]);
+ }
+ }
+ else
+ postErrorMsg = argv[i];
+ }
+ else if ((strncmp(argv[i], "-I", 2) == 0) && (!xkblist))
+ {
+ if (!XkbAddDirectoryToPath(&argv[i][2]))
+ {
+ ACTION("Exiting\n");
+ exit(1);
+ }
+ }
+ else if ((strncmp(argv[i], "-i", 2) == 0) && (!xkblist))
+ {
+ if (++i >= argc)
+ {
+ if (warningLevel > 0)
+ WARN("No device ID specified\n");
+ }
+ device_id = atoi(argv[i]);
+ }
+ else if ((strncmp(argv[i], "-l", 2) == 0) && (!xkblist))
+ {
+ if (outputFormat != WANT_DEFAULT)
+ {
+ if (warningLevel > 0)
+ {
+ WARN("Multiple output file formats specified\n");
+ ACTION1("\"%s\" flag ignored\n", argv[i]);
+ }
+ }
+ else
+ {
+ if (argv[i][2] != '\0')
+ setVerboseFlags(&argv[i][2]);
+ xkblist = True;
+ if ((inputFile) && (!AddMatchingFiles(inputFile)))
+ return False;
+ else
+ inputFile = NULL;
+ if ((outputFile) && (!AddMatchingFiles(outputFile)))
+ return False;
+ else
+ outputFile = NULL;
+ }
+ }
+ else if ((strcmp(argv[i], "-m") == 0)
+ || (strcmp(argv[i], "-map") == 0))
+ {
+ if (++i >= argc)
+ {
+ if (warningLevel > 0)
+ {
+ WARN("No map name specified\n");
+ ACTION1("Trailing \"%s\" option ignored\n", argv[i - 1]);
+ }
+ }
+ else if (xkblist)
+ {
+ if (!AddMapOnly(argv[i]))
+ return False;
+ }
+ else if (inputMap != NULL)
+ {
+ if (warningLevel > 0)
+ {
+ WARN("Multiple map names specified\n");
+ ACTION2("Compiling %s, ignoring %s\n", inputMap, argv[i]);
+ }
+ }
+ else
+ inputMap = argv[i];
+ }
+ else if ((strcmp(argv[i], "-merge") == 0) && (!xkblist))
+ {
+ /* Ignored */
+ }
+ else if (strcmp(argv[i], "-o") == 0)
+ {
+ if (++i >= argc)
+ {
+ if (warningLevel > 0)
+ {
+ WARN("No output file specified\n");
+ ACTION("Trailing \"-o\" option ignored\n");
+ }
+ }
+ else if (outputFile != NULL)
+ {
+ if (warningLevel > 0)
+ {
+ WARN("Multiple output files specified\n");
+ ACTION2("Compiling %s, ignoring %s\n", outputFile,
+ argv[i]);
+ }
+ }
+ else
+ outputFile = argv[i];
+ }
+ else if (((strcmp(argv[i], "-opt") == 0)
+ || (strcmp(argv[i], "optional") == 0)) && (!xkblist))
+ {
+ if (++i >= argc)
+ {
+ if (warningLevel > 0)
+ {
+ WARN("No optional components specified\n");
+ ACTION1("Trailing \"%s\" option ignored\n", argv[i - 1]);
+ }
+ }
+ else
+ {
+ char *tmp2;
+ for (tmp2 = argv[i]; (*tmp2 != '\0'); tmp2++)
+ {
+ switch (*tmp2)
+ {
+ case 'c':
+ case 'C':
+ optionalParts |= XkmCompatMapMask;
+ break;
+ case 'g':
+ case 'G':
+ optionalParts |= XkmGeometryMask;
+ break;
+ case 'k':
+ case 'K':
+ optionalParts |= XkmKeyNamesMask;
+ break;
+ case 's':
+ case 'S':
+ optionalParts |= XkmSymbolsMask;
+ break;
+ case 't':
+ case 'T':
+ optionalParts |= XkmTypesMask;
+ break;
+ default:
+ if (warningLevel > 0)
+ {
+ WARN1
+ ("Illegal component for %s option\n",
+ argv[i - 1]);
+ ACTION1
+ ("Ignoring unknown specifier \"%c\"\n",
+ (unsigned int) *tmp2);
+ }
+ break;
+ }
+ }
+ }
+ }
+ else if (strncmp(argv[i], "-p", 2) == 0)
+ {
+ if (isdigit(argv[i][2]))
+ {
+ if (sscanf(&argv[i][2], "%i", &itmp) == 1)
+ dirsToStrip = itmp;
+ }
+ else if ((i < (argc - 1)) && (isdigit(argv[i + 1][0])))
+ {
+ if (sscanf(argv[++i], "%i", &itmp) == 1)
+ dirsToStrip = itmp;
+ }
+ else
+ {
+ dirsToStrip = 0;
+ }
+ if (warningLevel > 5)
+ INFO1("Setting path count to %d\n", dirsToStrip);
+ }
+ else if (strncmp(argv[i], "-R", 2) == 0)
+ {
+ if (argv[i][2] == '\0')
+ {
+ if (warningLevel > 0)
+ {
+ WARN("No root directory specified\n");
+ ACTION("Ignoring -R option\n");
+ }
+ }
+ else if (rootDir != NULL)
+ {
+ if (warningLevel > 0)
+ {
+ WARN("Multiple root directories specified\n");
+ ACTION2("Using %s, ignoring %s\n", rootDir, argv[i]);
+ }
+ }
+ else
+ {
+ rootDir = &argv[i][2];
+ if (warningLevel > 8)
+ {
+ WARN1("Changing root directory to \"%s\"\n", rootDir);
+ }
+ if ((chdir(rootDir) < 0) && (warningLevel > 0))
+ {
+ WARN1("Couldn't change directory to \"%s\"\n", rootDir);
+ ACTION("Root directory (-R) option ignored\n");
+ rootDir = NULL;
+ }
+ }
+ }
+ else if ((strcmp(argv[i], "-synch") == 0)
+ || (strcmp(argv[i], "-s") == 0))
+ {
+ synch = True;
+ }
+ else if (strncmp(argv[i], "-v", 2) == 0)
+ {
+ char *str;
+ if (argv[i][2] != '\0')
+ str = &argv[i][2];
+ else if ((i < (argc - 1)) && (argv[i + 1][0] != '-'))
+ str = argv[++i];
+ else
+ str = NULL;
+ if (str)
+ setVerboseFlags(str);
+ }
+ else if (strncmp(argv[i], "-w", 2) == 0)
+ {
+ if ((i >= (argc - 1)) || (!isdigit(argv[i + 1][0])))
+ {
+ warningLevel = 0;
+ if (isdigit(argv[i][1]))
+ if (sscanf(&argv[i][1], "%i", &itmp) == 1)
+ warningLevel = itmp;
+ }
+ else
+ {
+ if (sscanf(argv[++i], "%i", &itmp) == 1)
+ warningLevel = itmp;
+ }
+ }
+ else if ((strcmp(argv[i], "-xkb") == 0) && (!xkblist))
+ {
+ if ((outputFormat != WANT_DEFAULT)
+ && (outputFormat != WANT_XKB_FILE))
+ {
+ if (warningLevel > 0)
+ {
+ WARN("Multiple output file formats specified\n");
+ ACTION1("\"%s\" flag ignored\n", argv[i]);
+ }
+ }
+ else
+ outputFormat = WANT_XKB_FILE;
+ }
+ else if ((strcmp(argv[i], "-xkm") == 0) && (!xkblist))
+ {
+ if ((outputFormat != WANT_DEFAULT)
+ && (outputFormat != WANT_XKM_FILE))
+ {
+ if (warningLevel > 0)
+ {
+ WARN("Multiple output file formats specified\n");
+ ACTION1("\"%s\" flag ignored\n", argv[i]);
+ }
+ }
+ else
+ outputFormat = WANT_XKM_FILE;
+ }
+ else
+ {
+ ERROR1("Unknown flag \"%s\" on command line\n", argv[i]);
+ Usage(argc, argv);
+ return False;
+ }
+ }
+ if (xkblist)
+ inputFormat = INPUT_XKB;
+ else if (inputFile == NULL)
+ {
+ ERROR("No input file specified\n");
+ return False;
+ }
+ else if (uStringEqual(inputFile, "-"))
+ {
+ inputFormat = INPUT_XKB;
+ }
+#ifndef WIN32
+ else if (strchr(inputFile, ':') == NULL)
+ {
+#else
+ else if ((strchr(inputFile, ':') == NULL) || (strlen(inputFile) > 2 &&
+ isalpha(inputFile[0]) &&
+ inputFile[1] == ':'
+ && strchr(inputFile + 2,
+ ':') == NULL))
+ {
+#endif
+ int len;
+ len = strlen(inputFile);
+ if (inputFile[len - 1] == ')')
+ {
+ char *tmp;
+ if ((tmp = strchr(inputFile, '(')) != NULL)
+ {
+ *tmp = '\0';
+ inputFile[len - 1] = '\0';
+ tmp++;
+ if (*tmp == '\0')
+ {
+ WARN("Empty map in filename\n");
+ ACTION("Ignored\n");
+ }
+ else if (inputMap == NULL)
+ {
+ inputMap = uStringDup(tmp);
+ }
+ else
+ {
+ WARN("Map specified in filename and with -m flag\n");
+ ACTION1("map from name (\"%s\") ignored\n", tmp);
+ }
+ }
+ else
+ {
+ ERROR1("Illegal name \"%s\" for input file\n", inputFile);
+ return False;
+ }
+ }
+ if ((len > 4) && (strcmp(&inputFile[len - 4], ".xkm") == 0))
+ {
+ inputFormat = INPUT_XKM;
+ }
+ else
+ {
+ FILE *file;
+ file = fopen(inputFile, "r");
+ if (file)
+ {
+ if (XkmProbe(file))
+ inputFormat = INPUT_XKM;
+ else
+ inputFormat = INPUT_XKB;
+ fclose(file);
+ }
+ else
+ {
+ fprintf(stderr, "Cannot open \"%s\" for reading\n",
+ inputFile);
+ return False;
+ }
+ }
+ }
+ else
+ {
+ inDpyName = inputFile;
+ inputFile = NULL;
+ inputFormat = INPUT_XKM;
+ }
+
+ if (outputFormat == WANT_DEFAULT)
+ {
+ if (xkblist)
+ outputFormat = WANT_LISTING;
+ else if (inputFormat == INPUT_XKB)
+ outputFormat = WANT_XKM_FILE;
+ else
+ outputFormat = WANT_XKB_FILE;
+ }
+ if ((outputFormat == WANT_LISTING) && (inputFormat != INPUT_XKB))
+ {
+ if (inputFile)
+ ERROR("Cannot generate a listing from a .xkm file (yet)\n");
+ else
+ ERROR("Cannot generate a listing from an X connection (yet)\n");
+ return False;
+ }
+ if (xkblist)
+ {
+ if (outputFile == NULL)
+ outputFile = uStringDup("-");
+ else if (strchr(outputFile, ':') != NULL)
+ {
+ ERROR("Cannot write a listing to an X connection\n");
+ return False;
+ }
+ }
+ else if ((!outputFile) && (inputFile) && uStringEqual(inputFile, "-"))
+ {
+ int len = strlen("stdin") + strlen(fileTypeExt[outputFormat]) + 2;
+ outputFile = uTypedCalloc(len, char);
+ if (outputFile == NULL)
+ {
+ WSGO("Cannot allocate space for output file name\n");
+ ACTION("Exiting\n");
+ exit(1);
+ }
+ sprintf(outputFile, "stdin.%s", fileTypeExt[outputFormat]);
+ }
+ else if ((outputFile == NULL) && (inputFile != NULL))
+ {
+ int len;
+ char *base, *ext;
+
+ if (inputMap == NULL)
+ {
+ base = strrchr(inputFile, '/');
+ if (base == NULL)
+ base = inputFile;
+ else
+ base++;
+ }
+ else
+ base = inputMap;
+
+ len = strlen(base) + strlen(fileTypeExt[outputFormat]) + 2;
+ outputFile = uTypedCalloc(len, char);
+ if (outputFile == NULL)
+ {
+ WSGO("Cannot allocate space for output file name\n");
+ ACTION("Exiting\n");
+ exit(1);
+ }
+ ext = strrchr(base, '.');
+ if (ext == NULL)
+ sprintf(outputFile, "%s.%s", base, fileTypeExt[outputFormat]);
+ else
+ {
+ strcpy(outputFile, base);
+ strcpy(&outputFile[ext - base + 1], fileTypeExt[outputFormat]);
+ }
+ }
+ else if (outputFile == NULL)
+ {
+ int len;
+ char *ch, *name, buf[128];
+ if (inDpyName[0] == ':')
+ snprintf(name = buf, sizeof(buf), "server%s", inDpyName);
+ else
+ name = inDpyName;
+
+ len = strlen(name) + strlen(fileTypeExt[outputFormat]) + 2;
+ outputFile = uTypedCalloc(len, char);
+ if (outputFile == NULL)
+ {
+ WSGO("Cannot allocate space for output file name\n");
+ ACTION("Exiting\n");
+ exit(1);
+ }
+ strcpy(outputFile, name);
+ for (ch = outputFile; (*ch) != '\0'; ch++)
+ {
+ if (*ch == ':')
+ *ch = '-';
+ else if (*ch == '.')
+ *ch = '_';
+ }
+ *ch++ = '.';
+ strcpy(ch, fileTypeExt[outputFormat]);
+ }
+#ifdef WIN32
+ else if (strlen(outputFile) > 2 &&
+ isalpha(outputFile[0]) &&
+ outputFile[1] == ':' && strchr(outputFile + 2, ':') == NULL)
+ {
+ }
+#endif
+ else if (strchr(outputFile, ':') != NULL)
+ {
+ outDpyName = outputFile;
+ outputFile = NULL;
+ outputFormat = WANT_X_SERVER;
+ }
+ return True;
+}
+
+static Display *
+GetDisplay(char *program, char *dpyName)
+{
+ int mjr, mnr, error;
+ Display *dpy;
+
+ mjr = XkbMajorVersion;
+ mnr = XkbMinorVersion;
+ dpy = XkbOpenDisplay(dpyName, NULL, NULL, &mjr, &mnr, &error);
+ if (dpy == NULL)
+ {
+ switch (error)
+ {
+ case XkbOD_BadLibraryVersion:
+ INFO3("%s was compiled with XKB version %d.%02d\n",
+ program, XkbMajorVersion, XkbMinorVersion);
+ ERROR2("X library supports incompatible version %d.%02d\n",
+ mjr, mnr);
+ break;
+ case XkbOD_ConnectionRefused:
+ ERROR1("Cannot open display \"%s\"\n", dpyName);
+ break;
+ case XkbOD_NonXkbServer:
+ ERROR1("XKB extension not present on %s\n", dpyName);
+ break;
+ case XkbOD_BadServerVersion:
+ INFO3("%s was compiled with XKB version %d.%02d\n",
+ program, XkbMajorVersion, XkbMinorVersion);
+ ERROR3("Server %s uses incompatible version %d.%02d\n",
+ dpyName, mjr, mnr);
+ break;
+ default:
+ WSGO1("Unknown error %d from XkbOpenDisplay\n", error);
+ }
+ }
+ else if (synch)
+ XSynchronize(dpy, True);
+ return dpy;
+}
+
+/***====================================================================***/
+
+#ifdef DEBUG
+extern int yydebug;
+#endif
+
+int
+main(int argc, char *argv[])
+{
+ FILE *file; /* input file (or stdin) */
+ XkbFile *rtrn;
+ XkbFile *mapToUse;
+ int ok;
+ XkbFileInfo result;
+ Status status;
+
+ yyin = stdin;
+ uSetEntryFile(NullString);
+ uSetDebugFile(NullString);
+ uSetErrorFile(NullString);
+
+ XkbInitIncludePath();
+ if (!parseArgs(argc, argv))
+ exit(1);
+#ifdef DEBUG
+ if (debugFlags & 0x2)
+ yydebug = 1;
+#endif
+ if (preErrorMsg)
+ uSetPreErrorMessage(preErrorMsg);
+ if (errorPrefix)
+ uSetErrorPrefix(errorPrefix);
+ if (postErrorMsg)
+ uSetPostErrorMessage(postErrorMsg);
+ file = NULL;
+ XkbInitAtoms(NULL);
+ XkbAddDefaultDirectoriesToPath();
+ if (xkblist)
+ {
+ Bool gotSome;
+ gotSome = GenerateListing(outputFile);
+ if ((warningLevel > 7) && (!gotSome))
+ return -1;
+ return 0;
+ }
+ if (inputFile != NULL)
+ {
+ if (uStringEqual(inputFile, "-"))
+ {
+ file = stdin;
+ inputFile = "stdin";
+ }
+ else
+ {
+ file = fopen(inputFile, "r");
+ }
+ }
+ else if (inDpyName != NULL)
+ {
+ inDpy = GetDisplay(argv[0], inDpyName);
+ if (!inDpy)
+ {
+ ACTION("Exiting\n");
+ exit(1);
+ }
+ }
+ if (outDpyName != NULL)
+ {
+ outDpy = GetDisplay(argv[0], outDpyName);
+ if (!outDpy)
+ {
+ ACTION("Exiting\n");
+ exit(1);
+ }
+ }
+ if ((inDpy == NULL) && (outDpy == NULL))
+ {
+ int mjr, mnr;
+ mjr = XkbMajorVersion;
+ mnr = XkbMinorVersion;
+ if (!XkbLibraryVersion(&mjr, &mnr))
+ {
+ INFO3("%s was compiled with XKB version %d.%02d\n",
+ argv[0], XkbMajorVersion, XkbMinorVersion);
+ ERROR2("X library supports incompatible version %d.%02d\n",
+ mjr, mnr);
+ ACTION("Exiting\n");
+ exit(1);
+ }
+ }
+ if (file)
+ {
+ ok = True;
+ setScanState(inputFile, 1);
+ if ((inputFormat == INPUT_XKB) /* parse .xkb file */
+ && (XKBParseFile(file, &rtrn) && (rtrn != NULL)))
+ {
+ fclose(file);
+ mapToUse = rtrn;
+ if (inputMap != NULL) /* map specified on cmdline? */
+ {
+ while ((mapToUse)
+ && (!uStringEqual(mapToUse->name, inputMap)))
+ {
+ mapToUse = (XkbFile *) mapToUse->common.next;
+ }
+ if (!mapToUse)
+ {
+ FATAL2("No map named \"%s\" in \"%s\"\n",
+ inputMap, inputFile);
+ /* NOTREACHED */
+ }
+ }
+ else if (rtrn->common.next != NULL)
+ {
+ /* look for map with XkbLC_Default flag. */
+ mapToUse = rtrn;
+ for (; mapToUse; mapToUse = (XkbFile *) mapToUse->common.next)
+ {
+ if (mapToUse->flags & XkbLC_Default)
+ break;
+ }
+ if (!mapToUse)
+ {
+ mapToUse = rtrn;
+ if (warningLevel > 4)
+ {
+ WARN1
+ ("No map specified, but \"%s\" has several\n",
+ inputFile);
+ ACTION1
+ ("Using the first defined map, \"%s\"\n",
+ mapToUse->name);
+ }
+ }
+ }
+ bzero((char *) &result, sizeof(result));
+ result.type = mapToUse->type;
+ if ((result.xkb = XkbAllocKeyboard()) == NULL)
+ {
+ WSGO("Cannot allocate keyboard description\n");
+ /* NOTREACHED */
+ }
+ switch (mapToUse->type)
+ {
+ case XkmSemanticsFile:
+ case XkmLayoutFile:
+ case XkmKeymapFile:
+ ok = CompileKeymap(mapToUse, &result, MergeReplace);
+ break;
+ case XkmKeyNamesIndex:
+ ok = CompileKeycodes(mapToUse, &result, MergeReplace);
+ break;
+ case XkmTypesIndex:
+ ok = CompileKeyTypes(mapToUse, &result, MergeReplace);
+ break;
+ case XkmSymbolsIndex:
+ /* if it's just symbols, invent key names */
+ result.xkb->flags |= AutoKeyNames;
+ ok = False;
+ break;
+ case XkmCompatMapIndex:
+ ok = CompileCompatMap(mapToUse, &result, MergeReplace, NULL);
+ break;
+ case XkmGeometryFile:
+ case XkmGeometryIndex:
+ /* if it's just a geometry, invent key names */
+ result.xkb->flags |= AutoKeyNames;
+ ok = CompileGeometry(mapToUse, &result, MergeReplace);
+ break;
+ default:
+ WSGO1("Unknown file type %d\n", mapToUse->type);
+ ok = False;
+ break;
+ }
+ result.xkb->device_spec = device_id;
+ }
+ else if (inputFormat == INPUT_XKM) /* parse xkm file */
+ {
+ unsigned tmp;
+ bzero((char *) &result, sizeof(result));
+ if ((result.xkb = XkbAllocKeyboard()) == NULL)
+ {
+ WSGO("Cannot allocate keyboard description\n");
+ /* NOTREACHED */
+ }
+ tmp = XkmReadFile(file, 0, XkmKeymapLegal, &result);
+ if (tmp == XkmKeymapLegal)
+ {
+ ERROR1("Cannot read XKM file \"%s\"\n", inputFile);
+ ok = False;
+ }
+ result.xkb->device_spec = device_id;
+ }
+ else
+ {
+ INFO1("Errors encountered in %s; not compiled.\n", inputFile);
+ ok = False;
+ }
+ }
+ else if (inDpy != NULL)
+ {
+ bzero((char *) &result, sizeof(result));
+ result.type = XkmKeymapFile;
+ result.xkb = XkbGetMap(inDpy, XkbAllMapComponentsMask, device_id);
+ if (result.xkb == NULL)
+ WSGO("Cannot load keyboard description\n");
+ if (XkbGetIndicatorMap(inDpy, ~0, result.xkb) != Success)
+ WSGO("Could not load indicator map\n");
+ if (XkbGetControls(inDpy, XkbAllControlsMask, result.xkb) != Success)
+ WSGO("Could not load keyboard controls\n");
+ if (XkbGetCompatMap(inDpy, XkbAllCompatMask, result.xkb) != Success)
+ WSGO("Could not load compatibility map\n");
+ if (XkbGetNames(inDpy, XkbAllNamesMask, result.xkb) != Success)
+ WSGO("Could not load names\n");
+ if ((status = XkbGetGeometry(inDpy, result.xkb)) != Success)
+ {
+ if (warningLevel > 3)
+ {
+ char buf[100];
+ buf[0] = '\0';
+ XGetErrorText(inDpy, status, buf, 100);
+ WARN1("Could not load keyboard geometry for %s\n", inDpyName);
+ ACTION1("%s\n", buf);
+ ACTION("Resulting keymap file will not describe geometry\n");
+ }
+ }
+ if (computeDflts)
+ ok = (ComputeKbdDefaults(result.xkb) == Success);
+ else
+ ok = True;
+ }
+ else
+ {
+ fprintf(stderr, "Cannot open \"%s\" to compile\n", inputFile);
+ ok = 0;
+ }
+ if (ok)
+ {
+ FILE *out = stdout;
+ if ((inDpy != outDpy) &&
+ (XkbChangeKbdDisplay(outDpy, &result) != Success))
+ {
+ WSGO2("Error converting keyboard display from %s to %s\n",
+ inDpyName, outDpyName);
+ exit(1);
+ }
+ if (outputFile != NULL)
+ {
+ if (uStringEqual(outputFile, "-"))
+ outputFile = "stdout";
+ else
+ {
+ /*
+ * fix to prevent symlink attack (e.g.,
+ * ln -s /etc/passwd /var/tmp/server-0.xkm)
+ */
+ /*
+ * this patch may have POSIX, Linux, or GNU libc bias
+ * -- Branden Robinson
+ */
+ int outputFileFd;
+ int binMode = 0;
+ const char *openMode = "w";
+ unlink(outputFile);
+#ifdef O_BINARY
+ switch (outputFormat)
+ {
+ case WANT_XKM_FILE:
+ binMode = O_BINARY;
+ openMode = "wb";
+ break;
+ default:
+ binMode = 0;
+ break;
+ }
+#endif
+ outputFileFd =
+ open(outputFile, O_WRONLY | O_CREAT | O_EXCL,
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH
+ | S_IWOTH | binMode);
+ if (outputFileFd < 0)
+ {
+ ERROR1
+ ("Cannot open \"%s\" to write keyboard description\n",
+ outputFile);
+ ACTION("Exiting\n");
+ exit(1);
+ }
+#ifndef WIN32
+ out = fdopen(outputFileFd, openMode);
+#else
+ close(outputFileFd);
+ out = fopen(outputFile, "wb");
+#endif
+ /* end BR */
+ if (out == NULL)
+ {
+ ERROR1
+ ("Cannot open \"%s\" to write keyboard description\n",
+ outputFile);
+ ACTION("Exiting\n");
+ exit(1);
+ }
+ }
+ }
+ switch (outputFormat)
+ {
+ case WANT_XKM_FILE:
+ ok = XkbWriteXKMFile(out, &result);
+ break;
+ case WANT_XKB_FILE:
+ ok = XkbWriteXKBFile(out, &result, showImplicit, NULL, NULL);
+ break;
+ case WANT_C_HDR:
+ ok = XkbWriteCFile(out, outputFile, &result);
+ break;
+ case WANT_X_SERVER:
+ if (!(ok = XkbWriteToServer(&result)))
+ {
+ ERROR2("%s in %s\n", _XkbErrMessages[_XkbErrCode],
+ _XkbErrLocation ? _XkbErrLocation : "unknown");
+ ACTION1("Couldn't write keyboard description to %s\n",
+ outDpyName);
+ }
+ break;
+ default:
+ WSGO1("Unknown output format %d\n", outputFormat);
+ ACTION("No output file created\n");
+ ok = False;
+ break;
+ }
+ if (outputFormat != WANT_X_SERVER)
+ {
+ if (fclose(out))
+ {
+ ERROR1("Cannot close \"%s\" properly (not enough space?)\n",
+ outputFile);
+ ok= False;
+ }
+ else if (!ok)
+ {
+ ERROR2("%s in %s\n", _XkbErrMessages[_XkbErrCode],
+ _XkbErrLocation ? _XkbErrLocation : "unknown");
+ }
+ if (!ok)
+ {
+ ACTION1("Output file \"%s\" removed\n", outputFile);
+ unlink(outputFile);
+ }
+ }
+ }
+ if (inDpy)
+ XCloseDisplay(inDpy);
+ inDpy = NULL;
+ if (outDpy)
+ XCloseDisplay(outDpy);
+ uFinishUp();
+ return (ok == 0);
+}
diff --git a/xkbcomp/xkbcomp.h b/xkbcomp/xkbcomp.h
index 800780fc0..fb4006165 100644
--- a/xkbcomp/xkbcomp.h
+++ b/xkbcomp/xkbcomp.h
@@ -1,396 +1,397 @@
-/************************************************************
- Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
-
- Permission to use, copy, modify, and distribute this
- software and its documentation for any purpose and without
- fee is hereby granted, provided that the above copyright
- notice appear in all copies and that both that copyright
- notice and this permission notice appear in supporting
- documentation, and that the name of Silicon Graphics not be
- used in advertising or publicity pertaining to distribution
- of the software without specific prior written permission.
- Silicon Graphics makes no representation about the suitability
- of this software for any purpose. It is provided "as is"
- without any express or implied warranty.
-
- SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
- SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
- GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
- DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
- THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
- ********************************************************/
-
-#ifndef XKBCOMP_H
-#define XKBCOMP_H 1
-
-#ifndef DEBUG_VAR
-#define DEBUG_VAR debugFlags
-#endif
-
-#include <X11/Xlib.h>
-#include <X11/XKBlib.h>
-
-#include "utils.h"
-
-#include <X11/extensions/XKM.h>
-#include <X11/extensions/XKBfile.h>
-
-extern char *scanFile;
-
-#define TypeUnknown 0
-#define TypeBoolean 1
-#define TypeInt 2
-#define TypeFloat 3
-#define TypeString 4
-#define TypeAction 5
-#define TypeKeyName 6
-#define TypeSymbols 7
-
-#define StmtUnknown 0
-#define StmtInclude 1
-#define StmtKeycodeDef 2
-#define StmtKeyAliasDef 3
-#define StmtExpr 4
-#define StmtVarDef 5
-#define StmtKeyTypeDef 6
-#define StmtInterpDef 7
-#define StmtVModDef 8
-#define StmtSymbolsDef 9
-#define StmtModMapDef 10
-#define StmtGroupCompatDef 11
-#define StmtIndicatorMapDef 12
-#define StmtIndicatorNameDef 13
-#define StmtOutlineDef 14
-#define StmtShapeDef 15
-#define StmtKeyDef 16
-#define StmtRowDef 17
-#define StmtSectionDef 18
-#define StmtOverlayKeyDef 19
-#define StmtOverlayDef 20
-#define StmtDoodadDef 21
-
-#define FileSymInterp 100
-
-typedef struct _ParseCommon
-{
- unsigned stmtType;
- struct _ParseCommon *next;
-} ParseCommon;
-
-#define ExprValue 0
-#define ExprIdent 1
-#define ExprActionDecl 2
-#define ExprFieldRef 3
-#define ExprArrayRef 4
-#define ExprKeysymList 5
-#define ExprActionList 6
-#define ExprCoord 7
-
-#define OpAdd 20
-#define OpSubtract 21
-#define OpMultiply 22
-#define OpDivide 23
-#define OpAssign 24
-#define OpNot 25
-#define OpNegate 26
-#define OpInvert 27
-#define OpUnaryPlus 28
-
-#define MergeDefault 0
-#define MergeAugment 1
-#define MergeOverride 2
-#define MergeReplace 3
-#define MergeAltForm 4
-
-#define AutoKeyNames (1L << 0)
-#define CreateKeyNames(x) ((x)->flags&AutoKeyNames)
-
-extern unsigned warningLevel;
-extern unsigned optionalParts;
-
-typedef struct _IncludeStmt
-{
- ParseCommon common;
- unsigned merge;
- char *stmt;
- char *file;
- char *map;
- char *modifier;
- char *path;
- struct _IncludeStmt *next;
-} IncludeStmt;
-
-typedef struct _Expr
-{
- ParseCommon common;
- unsigned op;
- unsigned type;
- union
- {
- struct
- {
- struct _Expr *left;
- struct _Expr *right;
- } binary;
- struct
- {
- Atom element;
- Atom field;
- } field;
- struct
- {
- Atom element;
- Atom field;
- struct _Expr *entry;
- } array;
- struct
- {
- Atom name;
- struct _Expr *args;
- } action;
- struct
- {
- int nSyms;
- int szSyms;
- char **syms;
- } list;
- struct
- {
- int x;
- int y;
- } coord;
- struct _Expr *child;
- Atom str;
- unsigned uval;
- int ival;
- char keyName[5];
- Opaque ptr;
- } value;
-} ExprDef;
-
-typedef struct _VarDef
-{
- ParseCommon common;
- unsigned merge;
- ExprDef *name;
- ExprDef *value;
-} VarDef;
-
-typedef struct _VModDef
-{
- ParseCommon common;
- unsigned merge;
- Atom name;
- ExprDef *value;
-} VModDef;
-
-typedef struct _KeycodeDef
-{
- ParseCommon common;
- unsigned merge;
- char name[5];
- ExprDef *value;
-} KeycodeDef;
-
-typedef struct _KeyAliasDef
-{
- ParseCommon common;
- unsigned merge;
- char alias[5];
- char real[5];
-} KeyAliasDef;
-
-typedef struct _KeyTypeDef
-{
- ParseCommon common;
- unsigned merge;
- Atom name;
- VarDef *body;
-} KeyTypeDef;
-
-typedef struct _SymbolsDef
-{
- ParseCommon common;
- unsigned merge;
- char keyName[5];
- ExprDef *symbols;
-} SymbolsDef;
-
-typedef struct _ModMapDef
-{
- ParseCommon common;
- unsigned merge;
- Atom modifier;
- ExprDef *keys;
-} ModMapDef;
-
-typedef struct _GroupCompatDef
-{
- ParseCommon common;
- unsigned merge;
- int group;
- ExprDef *def;
-} GroupCompatDef;
-
-typedef struct _InterpDef
-{
- ParseCommon common;
- unsigned merge;
- KeySym sym;
- ExprDef *match;
- VarDef *def;
-} InterpDef;
-
-typedef struct _IndicatorNameDef
-{
- ParseCommon common;
- unsigned merge;
- int ndx;
- ExprDef *name;
- Bool virtual;
-} IndicatorNameDef;
-
-typedef struct _OutlineDef
-{
- ParseCommon common;
- Atom field;
- int nPoints;
- ExprDef *points;
-} OutlineDef;
-
-typedef struct _ShapeDef
-{
- ParseCommon common;
- unsigned merge;
- Atom name;
- int nOutlines;
- OutlineDef *outlines;
-} ShapeDef;
-
-typedef struct _KeyDef
-{
- ParseCommon common;
- unsigned defined;
- char *name;
- ExprDef *expr;
-} KeyDef;
-
-typedef struct _RowDef
-{
- ParseCommon common;
- int nKeys;
- KeyDef *keys;
-} RowDef;
-
-typedef struct _SectionDef
-{
- ParseCommon common;
- unsigned merge;
- Atom name;
- int nRows;
- RowDef *rows;
-} SectionDef;
-
-typedef struct _OverlayKeyDef
-{
- ParseCommon common;
- char over[5];
- char under[5];
-} OverlayKeyDef;
-
-typedef struct _OverlayDef
-{
- ParseCommon common;
- unsigned merge;
- Atom name;
- int nKeys;
- OverlayKeyDef *keys;
-} OverlayDef;
-
-typedef struct _DoodadDef
-{
- ParseCommon common;
- unsigned merge;
- unsigned type;
- Atom name;
- VarDef *body;
-} DoodadDef;
-
-/* IndicatorMapDef doesn't use the type field, but the rest of the fields
- need to be at the same offsets as in DoodadDef. Use #define to avoid
- any strict aliasing problems. */
-#define IndicatorMapDef DoodadDef
-
-typedef struct _XkbFile
-{
- ParseCommon common;
- int type;
- char *topName;
- char *name;
- ParseCommon *defs;
- int id;
- unsigned flags;
- Bool compiled;
-} XkbFile;
-
-extern Bool CompileKeymap(XkbFile * /* file */ ,
- XkbFileInfo * /* result */ ,
- unsigned /* merge */
- );
-
-extern Bool CompileKeycodes(XkbFile * /* file */ ,
- XkbFileInfo * /* result */ ,
- unsigned /* merge */
- );
-
-extern Bool CompileGeometry(XkbFile * /* file */ ,
- XkbFileInfo * /* result */ ,
- unsigned /* merge */
- );
-
-extern Bool CompileKeyTypes(XkbFile * /* file */ ,
- XkbFileInfo * /* result */ ,
- unsigned /* merge */
- );
-
-typedef struct _LEDInfo *LEDInfoPtr;
-
-extern Bool CompileCompatMap(XkbFile * /* file */ ,
- XkbFileInfo * /* result */ ,
- unsigned /* merge */ ,
- LEDInfoPtr * /* unboundLEDs */
- );
-
-extern Bool CompileSymbols(XkbFile * /* file */ ,
- XkbFileInfo * /* result */ ,
- unsigned /* merge */
- );
-
-#define WantLongListing (1<<0)
-#define WantPartialMaps (1<<1)
-#define WantHiddenMaps (1<<2)
-#define WantFullNames (1<<3)
-#define ListRecursive (1<<4)
-
-extern char *rootDir;
-extern unsigned verboseLevel;
-extern unsigned dirsToStrip;
-
-extern Bool AddListing(char * /* file */ ,
- char * /* map */
- );
-
-extern Bool AddMatchingFiles(char * /* head_in */
- );
-
-extern int AddMapOnly(char * /* map */
- );
-
-extern int GenerateListing(char * /* filename */
- );
-
-#endif /* XKBCOMP_H */
+/************************************************************
+ Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
+
+ Permission to use, copy, modify, and distribute this
+ software and its documentation for any purpose and without
+ fee is hereby granted, provided that the above copyright
+ notice appear in all copies and that both that copyright
+ notice and this permission notice appear in supporting
+ documentation, and that the name of Silicon Graphics not be
+ used in advertising or publicity pertaining to distribution
+ of the software without specific prior written permission.
+ Silicon Graphics makes no representation about the suitability
+ of this software for any purpose. It is provided "as is"
+ without any express or implied warranty.
+
+ SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+ GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
+ THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+ ********************************************************/
+
+#ifndef XKBCOMP_H
+#define XKBCOMP_H 1
+
+#ifndef DEBUG_VAR
+#define DEBUG_VAR debugFlags
+#endif
+
+#include <X11/Xlib.h>
+#include <X11/XKBlib.h>
+
+#include "utils.h"
+
+#include <X11/extensions/XKM.h>
+#include <X11/extensions/XKBfile.h>
+
+extern char *scanFile;
+
+#define TypeUnknown 0
+#define TypeBoolean 1
+#define TypeInt 2
+#define TypeFloat 3
+#define TypeString 4
+#define TypeAction 5
+#define TypeKeyName 6
+#define TypeSymbols 7
+
+#define StmtUnknown 0
+#define StmtInclude 1
+#define StmtKeycodeDef 2
+#define StmtKeyAliasDef 3
+#define StmtExpr 4
+#define StmtVarDef 5
+#define StmtKeyTypeDef 6
+#define StmtInterpDef 7
+#define StmtVModDef 8
+#define StmtSymbolsDef 9
+#define StmtModMapDef 10
+#define StmtGroupCompatDef 11
+#define StmtIndicatorMapDef 12
+#define StmtIndicatorNameDef 13
+#define StmtOutlineDef 14
+#define StmtShapeDef 15
+#define StmtKeyDef 16
+#define StmtRowDef 17
+#define StmtSectionDef 18
+#define StmtOverlayKeyDef 19
+#define StmtOverlayDef 20
+#define StmtDoodadDef 21
+
+#define FileSymInterp 100
+
+typedef struct _ParseCommon
+{
+ unsigned stmtType;
+ struct _ParseCommon *next;
+} ParseCommon;
+
+#define ExprValue 0
+#define ExprIdent 1
+#define ExprActionDecl 2
+#define ExprFieldRef 3
+#define ExprArrayRef 4
+#define ExprKeysymList 5
+#define ExprActionList 6
+#define ExprCoord 7
+
+#define OpAdd 20
+#define OpSubtract 21
+#define OpMultiply 22
+#define OpDivide 23
+#define OpAssign 24
+#define OpNot 25
+#define OpNegate 26
+#define OpInvert 27
+#define OpUnaryPlus 28
+
+#define MergeDefault 0
+#define MergeAugment 1
+#define MergeOverride 2
+#define MergeReplace 3
+#define MergeAltForm 4
+
+#define AutoKeyNames (1L << 0)
+#define CreateKeyNames(x) ((x)->flags&AutoKeyNames)
+
+extern unsigned warningLevel;
+extern unsigned optionalParts;
+
+typedef struct _IncludeStmt
+{
+ ParseCommon common;
+ unsigned merge;
+ char *stmt;
+ char *file;
+ char *map;
+ char *modifier;
+ char *path;
+ struct _IncludeStmt *next;
+} IncludeStmt;
+
+typedef struct _Expr
+{
+ ParseCommon common;
+ unsigned op;
+ unsigned type;
+ union
+ {
+ struct
+ {
+ struct _Expr *left;
+ struct _Expr *right;
+ } binary;
+ struct
+ {
+ Atom element;
+ Atom field;
+ } field;
+ struct
+ {
+ Atom element;
+ Atom field;
+ struct _Expr *entry;
+ } array;
+ struct
+ {
+ Atom name;
+ struct _Expr *args;
+ } action;
+ struct
+ {
+ int nSyms;
+ int szSyms;
+ char **syms;
+ } list;
+ struct
+ {
+ int x;
+ int y;
+ } coord;
+ struct _Expr *child;
+ Atom str;
+ unsigned uval;
+ int ival;
+ char keyName[5];
+ Opaque ptr;
+ } value;
+} ExprDef;
+
+typedef struct _VarDef
+{
+ ParseCommon common;
+ unsigned merge;
+ ExprDef *name;
+ ExprDef *value;
+} VarDef;
+
+typedef struct _VModDef
+{
+ ParseCommon common;
+ unsigned merge;
+ Atom name;
+ ExprDef *value;
+} VModDef;
+
+typedef struct _KeycodeDef
+{
+ ParseCommon common;
+ unsigned merge;
+ char name[5];
+ ExprDef *value;
+} KeycodeDef;
+
+typedef struct _KeyAliasDef
+{
+ ParseCommon common;
+ unsigned merge;
+ char alias[5];
+ char real[5];
+} KeyAliasDef;
+
+typedef struct _KeyTypeDef
+{
+ ParseCommon common;
+ unsigned merge;
+ Atom name;
+ VarDef *body;
+} KeyTypeDef;
+
+typedef struct _SymbolsDef
+{
+ ParseCommon common;
+ unsigned merge;
+ char keyName[5];
+ ExprDef *symbols;
+} SymbolsDef;
+
+typedef struct _ModMapDef
+{
+ ParseCommon common;
+ unsigned merge;
+ Atom modifier;
+ ExprDef *keys;
+} ModMapDef;
+
+typedef struct _GroupCompatDef
+{
+ ParseCommon common;
+ unsigned merge;
+ int group;
+ ExprDef *def;
+} GroupCompatDef;
+
+typedef struct _InterpDef
+{
+ ParseCommon common;
+ unsigned merge;
+ KeySym sym;
+ ExprDef *match;
+ VarDef *def;
+ Bool ignore;
+} InterpDef;
+
+typedef struct _IndicatorNameDef
+{
+ ParseCommon common;
+ unsigned merge;
+ int ndx;
+ ExprDef *name;
+ Bool virtual;
+} IndicatorNameDef;
+
+typedef struct _OutlineDef
+{
+ ParseCommon common;
+ Atom field;
+ int nPoints;
+ ExprDef *points;
+} OutlineDef;
+
+typedef struct _ShapeDef
+{
+ ParseCommon common;
+ unsigned merge;
+ Atom name;
+ int nOutlines;
+ OutlineDef *outlines;
+} ShapeDef;
+
+typedef struct _KeyDef
+{
+ ParseCommon common;
+ unsigned defined;
+ char *name;
+ ExprDef *expr;
+} KeyDef;
+
+typedef struct _RowDef
+{
+ ParseCommon common;
+ int nKeys;
+ KeyDef *keys;
+} RowDef;
+
+typedef struct _SectionDef
+{
+ ParseCommon common;
+ unsigned merge;
+ Atom name;
+ int nRows;
+ RowDef *rows;
+} SectionDef;
+
+typedef struct _OverlayKeyDef
+{
+ ParseCommon common;
+ char over[5];
+ char under[5];
+} OverlayKeyDef;
+
+typedef struct _OverlayDef
+{
+ ParseCommon common;
+ unsigned merge;
+ Atom name;
+ int nKeys;
+ OverlayKeyDef *keys;
+} OverlayDef;
+
+typedef struct _DoodadDef
+{
+ ParseCommon common;
+ unsigned merge;
+ unsigned type;
+ Atom name;
+ VarDef *body;
+} DoodadDef;
+
+/* IndicatorMapDef doesn't use the type field, but the rest of the fields
+ need to be at the same offsets as in DoodadDef. Use #define to avoid
+ any strict aliasing problems. */
+#define IndicatorMapDef DoodadDef
+
+typedef struct _XkbFile
+{
+ ParseCommon common;
+ int type;
+ char *topName;
+ char *name;
+ ParseCommon *defs;
+ int id;
+ unsigned flags;
+ Bool compiled;
+} XkbFile;
+
+extern Bool CompileKeymap(XkbFile * /* file */ ,
+ XkbFileInfo * /* result */ ,
+ unsigned /* merge */
+ );
+
+extern Bool CompileKeycodes(XkbFile * /* file */ ,
+ XkbFileInfo * /* result */ ,
+ unsigned /* merge */
+ );
+
+extern Bool CompileGeometry(XkbFile * /* file */ ,
+ XkbFileInfo * /* result */ ,
+ unsigned /* merge */
+ );
+
+extern Bool CompileKeyTypes(XkbFile * /* file */ ,
+ XkbFileInfo * /* result */ ,
+ unsigned /* merge */
+ );
+
+typedef struct _LEDInfo *LEDInfoPtr;
+
+extern Bool CompileCompatMap(XkbFile * /* file */ ,
+ XkbFileInfo * /* result */ ,
+ unsigned /* merge */ ,
+ LEDInfoPtr * /* unboundLEDs */
+ );
+
+extern Bool CompileSymbols(XkbFile * /* file */ ,
+ XkbFileInfo * /* result */ ,
+ unsigned /* merge */
+ );
+
+#define WantLongListing (1<<0)
+#define WantPartialMaps (1<<1)
+#define WantHiddenMaps (1<<2)
+#define WantFullNames (1<<3)
+#define ListRecursive (1<<4)
+
+extern char *rootDir;
+extern unsigned verboseLevel;
+extern unsigned dirsToStrip;
+
+extern Bool AddListing(char * /* file */ ,
+ char * /* map */
+ );
+
+extern Bool AddMatchingFiles(char * /* head_in */
+ );
+
+extern int AddMapOnly(char * /* map */
+ );
+
+extern int GenerateListing(char * /* filename */
+ );
+
+#endif /* XKBCOMP_H */
diff --git a/xkbcomp/xkbparse.y b/xkbcomp/xkbparse.y
index 1918f6b72..51b3bf7e9 100644
--- a/xkbcomp/xkbparse.y
+++ b/xkbcomp/xkbparse.y
@@ -1,782 +1,782 @@
-/************************************************************
- Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
-
- Permission to use, copy, modify, and distribute this
- software and its documentation for any purpose and without
- fee is hereby granted, provided that the above copyright
- notice appear in all copies and that both that copyright
- notice and this permission notice appear in supporting
- documentation, and that the name of Silicon Graphics not be
- used in advertising or publicity pertaining to distribution
- of the software without specific prior written permission.
- Silicon Graphics makes no representation about the suitability
- of this software for any purpose. It is provided "as is"
- without any express or implied warranty.
-
- SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
- SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
- GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
- DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
- THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
- ********************************************************/
-
-%token
- END_OF_FILE 0
- ERROR_TOK 255
- XKB_KEYMAP 1
- XKB_KEYCODES 2
- XKB_TYPES 3
- XKB_SYMBOLS 4
- XKB_COMPATMAP 5
- XKB_GEOMETRY 6
- XKB_SEMANTICS 7
- XKB_LAYOUT 8
- INCLUDE 10
- OVERRIDE 11
- AUGMENT 12
- REPLACE 13
- ALTERNATE 14
- VIRTUAL_MODS 20
- TYPE 21
- INTERPRET 22
- ACTION_TOK 23
- KEY 24
- ALIAS 25
- GROUP 26
- MODIFIER_MAP 27
- INDICATOR 28
- SHAPE 29
- KEYS 30
- ROW 31
- SECTION 32
- OVERLAY 33
- TEXT 34
- OUTLINE 35
- SOLID 36
- LOGO 37
- VIRTUAL 38
- EQUALS 40
- PLUS 41
- MINUS 42
- DIVIDE 43
- TIMES 44
- OBRACE 45
- CBRACE 46
- OPAREN 47
- CPAREN 48
- OBRACKET 49
- CBRACKET 50
- DOT 51
- COMMA 52
- SEMI 53
- EXCLAM 54
- INVERT 55
- STRING 60
- INTEGER 61
- FLOAT 62
- IDENT 63
- KEYNAME 64
- PARTIAL 70
- DEFAULT 71
- HIDDEN 72
- ALPHANUMERIC_KEYS 73
- MODIFIER_KEYS 74
- KEYPAD_KEYS 75
- FUNCTION_KEYS 76
- ALTERNATE_GROUP 77
-%{
-#ifdef DEBUG
-#define YYDEBUG 1
-#endif
-#define DEBUG_VAR parseDebug
-#include "parseutils.h"
-#include <X11/keysym.h>
-#include <X11/extensions/XKBgeom.h>
-#include <stdlib.h>
-
-unsigned int parseDebug;
-
-%}
-%right EQUALS
-%left PLUS MINUS
-%left TIMES DIVIDE
-%left EXCLAM INVERT
-%left OPAREN
-%start XkbFile
-%union {
- int ival;
- unsigned uval;
- char *str;
- Atom sval;
- ParseCommon *any;
- ExprDef *expr;
- VarDef *var;
- VModDef *vmod;
- InterpDef *interp;
- KeyTypeDef *keyType;
- SymbolsDef *syms;
- ModMapDef *modMask;
- GroupCompatDef *groupCompat;
- IndicatorMapDef *ledMap;
- IndicatorNameDef *ledName;
- KeycodeDef *keyName;
- KeyAliasDef *keyAlias;
- ShapeDef *shape;
- SectionDef *section;
- RowDef *row;
- KeyDef *key;
- OverlayDef *overlay;
- OverlayKeyDef *olKey;
- OutlineDef *outline;
- DoodadDef *doodad;
- XkbFile *file;
-}
-%type <ival> Number Integer Float SignedNumber
-%type <uval> XkbCompositeType FileType MergeMode OptMergeMode
-%type <uval> DoodadType Flag Flags OptFlags
-%type <str> KeyName MapName OptMapName KeySym
-%type <sval> FieldSpec Ident Element String
-%type <any> DeclList Decl
-%type <expr> OptExprList ExprList Expr Term Lhs Terminal ArrayInit
-%type <expr> OptKeySymList KeySymList Action ActionList Coord CoordList
-%type <var> VarDecl VarDeclList SymbolsBody SymbolsVarDecl
-%type <vmod> VModDecl VModDefList VModDef
-%type <interp> InterpretDecl InterpretMatch
-%type <keyType> KeyTypeDecl
-%type <syms> SymbolsDecl
-%type <modMask> ModMapDecl
-%type <groupCompat> GroupCompatDecl
-%type <ledMap> IndicatorMapDecl
-%type <ledName> IndicatorNameDecl
-%type <keyName> KeyNameDecl
-%type <keyAlias> KeyAliasDecl
-%type <shape> ShapeDecl
-%type <section> SectionDecl
-%type <row> SectionBody SectionBodyItem
-%type <key> RowBody RowBodyItem Keys Key
-%type <overlay> OverlayDecl
-%type <olKey> OverlayKeyList OverlayKey
-%type <outline> OutlineList OutlineInList
-%type <doodad> DoodadDecl
-%type <file> XkbFile XkbMapConfigList XkbMapConfig XkbConfig
-%type <file> XkbCompositeMap XkbCompMapList
-%%
-XkbFile : XkbCompMapList
- { $$= rtrnValue= $1; }
- | XkbMapConfigList
- { $$= rtrnValue= $1; }
- | XkbConfig
- { $$= rtrnValue= $1; }
- ;
-
-XkbCompMapList : XkbCompMapList XkbCompositeMap
- { $$= (XkbFile *)AppendStmt(&$1->common,&$2->common); }
- | XkbCompositeMap
- { $$= $1; }
- ;
-
-XkbCompositeMap : OptFlags XkbCompositeType OptMapName OBRACE
- XkbMapConfigList
- CBRACE SEMI
- { $$= CreateXKBFile($2,$3,&$5->common,$1); }
- ;
-
-XkbCompositeType: XKB_KEYMAP { $$= XkmKeymapFile; }
- | XKB_SEMANTICS { $$= XkmSemanticsFile; }
- | XKB_LAYOUT { $$= XkmLayoutFile; }
- ;
-
-XkbMapConfigList : XkbMapConfigList XkbMapConfig
- { $$= (XkbFile *)AppendStmt(&$1->common,&$2->common); }
- | XkbMapConfig
- { $$= $1; }
- ;
-
-XkbMapConfig : OptFlags FileType OptMapName OBRACE
- DeclList
- CBRACE SEMI
- { $$= CreateXKBFile($2,$3,$5,$1); }
- ;
-
-XkbConfig : OptFlags FileType OptMapName DeclList
- { $$= CreateXKBFile($2,$3,$4,$1); }
- ;
-
-
-FileType : XKB_KEYCODES { $$= XkmKeyNamesIndex; }
- | XKB_TYPES { $$= XkmTypesIndex; }
- | XKB_COMPATMAP { $$= XkmCompatMapIndex; }
- | XKB_SYMBOLS { $$= XkmSymbolsIndex; }
- | XKB_GEOMETRY { $$= XkmGeometryIndex; }
- ;
-
-OptFlags : Flags { $$= $1; }
- | { $$= 0; }
- ;
-
-Flags : Flags Flag { $$= (($1)|($2)); }
- | Flag { $$= $1; }
- ;
-
-Flag : PARTIAL { $$= XkbLC_Partial; }
- | DEFAULT { $$= XkbLC_Default; }
- | HIDDEN { $$= XkbLC_Hidden; }
- | ALPHANUMERIC_KEYS { $$= XkbLC_AlphanumericKeys; }
- | MODIFIER_KEYS { $$= XkbLC_ModifierKeys; }
- | KEYPAD_KEYS { $$= XkbLC_KeypadKeys; }
- | FUNCTION_KEYS { $$= XkbLC_FunctionKeys; }
- | ALTERNATE_GROUP { $$= XkbLC_AlternateGroup; }
- ;
-
-DeclList : DeclList Decl
- { $$= AppendStmt($1,$2); }
- | { $$= NULL; }
- ;
-
-Decl : OptMergeMode VarDecl
- {
- $2->merge= StmtSetMerge(&$2->common,$1);
- $$= &$2->common;
- }
- | OptMergeMode VModDecl
- {
- $2->merge= StmtSetMerge(&$2->common,$1);
- $$= &$2->common;
- }
- | OptMergeMode InterpretDecl
- {
- $2->merge= StmtSetMerge(&$2->common,$1);
- $$= &$2->common;
- }
- | OptMergeMode KeyNameDecl
- {
- $2->merge= StmtSetMerge(&$2->common,$1);
- $$= &$2->common;
- }
- | OptMergeMode KeyAliasDecl
- {
- $2->merge= StmtSetMerge(&$2->common,$1);
- $$= &$2->common;
- }
- | OptMergeMode KeyTypeDecl
- {
- $2->merge= StmtSetMerge(&$2->common,$1);
- $$= &$2->common;
- }
- | OptMergeMode SymbolsDecl
- {
- $2->merge= StmtSetMerge(&$2->common,$1);
- $$= &$2->common;
- }
- | OptMergeMode ModMapDecl
- {
- $2->merge= StmtSetMerge(&$2->common,$1);
- $$= &$2->common;
- }
- | OptMergeMode GroupCompatDecl
- {
- $2->merge= StmtSetMerge(&$2->common,$1);
- $$= &$2->common;
- }
- | OptMergeMode IndicatorMapDecl
- {
- $2->merge= StmtSetMerge(&$2->common,$1);
- $$= &$2->common;
- }
- | OptMergeMode IndicatorNameDecl
- {
- $2->merge= StmtSetMerge(&$2->common,$1);
- $$= &$2->common;
- }
- | OptMergeMode ShapeDecl
- {
- $2->merge= StmtSetMerge(&$2->common,$1);
- $$= &$2->common;
- }
- | OptMergeMode SectionDecl
- {
- $2->merge= StmtSetMerge(&$2->common,$1);
- $$= &$2->common;
- }
- | OptMergeMode DoodadDecl
- {
- $2->merge= StmtSetMerge(&$2->common,$1);
- $$= &$2->common;
- }
- | MergeMode STRING
- {
- if ($1==MergeAltForm) {
- yyerror("cannot use 'alternate' to include other maps");
- $$= &IncludeCreate(scanBuf,MergeDefault)->common;
- }
- else {
- $$= &IncludeCreate(scanBuf,$1)->common;
- }
- }
- ;
-
-VarDecl : Lhs EQUALS Expr SEMI
- { $$= VarCreate($1,$3); }
- | Ident SEMI
- { $$= BoolVarCreate($1,1); }
- | EXCLAM Ident SEMI
- { $$= BoolVarCreate($2,0); }
- ;
-
-KeyNameDecl : KeyName EQUALS Expr SEMI
- {
- KeycodeDef *def;
-
- def= KeycodeCreate($1,$3);
- if ($1)
- free($1);
- $$= def;
- }
- ;
-
-KeyAliasDecl : ALIAS KeyName EQUALS KeyName SEMI
- {
- KeyAliasDef *def;
- def= KeyAliasCreate($2,$4);
- if ($2) free($2);
- if ($4) free($4);
- $$= def;
- }
- ;
-
-VModDecl : VIRTUAL_MODS VModDefList SEMI
- { $$= $2; }
- ;
-
-VModDefList : VModDefList COMMA VModDef
- { $$= (VModDef *)AppendStmt(&$1->common,&$3->common); }
- | VModDef
- { $$= $1; }
- ;
-
-VModDef : Ident
- { $$= VModCreate($1,NULL); }
- | Ident EQUALS Expr
- { $$= VModCreate($1,$3); }
- ;
-
-InterpretDecl : INTERPRET InterpretMatch OBRACE
- VarDeclList
- CBRACE SEMI
- {
- $2->def= $4;
- $$= $2;
- }
- ;
-
-InterpretMatch : KeySym PLUS Expr
- { $$= InterpCreate(XStringToKeysym($1), $3); }
- | KeySym
- { $$= InterpCreate(XStringToKeysym($1), NULL); }
- ;
-
-VarDeclList : VarDeclList VarDecl
- { $$= (VarDef *)AppendStmt(&$1->common,&$2->common); }
- | VarDecl
- { $$= $1; }
- ;
-
-KeyTypeDecl : TYPE String OBRACE
- VarDeclList
- CBRACE SEMI
- { $$= KeyTypeCreate($2,$4); }
- ;
-
-SymbolsDecl : KEY KeyName OBRACE
- SymbolsBody
- CBRACE SEMI
- { $$= SymbolsCreate($2,(ExprDef *)$4); }
- ;
-
-SymbolsBody : SymbolsBody COMMA SymbolsVarDecl
- { $$= (VarDef *)AppendStmt(&$1->common,&$3->common); }
- | SymbolsVarDecl
- { $$= $1; }
- | { $$= NULL; }
- ;
-
-SymbolsVarDecl : Lhs EQUALS Expr
- { $$= VarCreate($1,$3); }
- | Lhs EQUALS ArrayInit
- { $$= VarCreate($1,$3); }
- | Ident
- { $$= BoolVarCreate($1,1); }
- | EXCLAM Ident
- { $$= BoolVarCreate($2,0); }
- | ArrayInit
- { $$= VarCreate(NULL,$1); }
- ;
-
-ArrayInit : OBRACKET OptKeySymList CBRACKET
- { $$= $2; }
- | OBRACKET ActionList CBRACKET
- { $$= ExprCreateUnary(ExprActionList,TypeAction,$2); }
- ;
-
-GroupCompatDecl : GROUP Integer EQUALS Expr SEMI
- { $$= GroupCompatCreate($2,$4); }
- ;
-
-ModMapDecl : MODIFIER_MAP Ident OBRACE ExprList CBRACE SEMI
- { $$= ModMapCreate($2,$4); }
- ;
-
-IndicatorMapDecl: INDICATOR String OBRACE VarDeclList CBRACE SEMI
- { $$= IndicatorMapCreate($2,$4); }
- ;
-
-IndicatorNameDecl: INDICATOR Integer EQUALS Expr SEMI
- { $$= IndicatorNameCreate($2,$4,False); }
- | VIRTUAL INDICATOR Integer EQUALS Expr SEMI
- { $$= IndicatorNameCreate($3,$5,True); }
- ;
-
-ShapeDecl : SHAPE String OBRACE OutlineList CBRACE SEMI
- { $$= ShapeDeclCreate($2,(OutlineDef *)&$4->common); }
- | SHAPE String OBRACE CoordList CBRACE SEMI
- {
- OutlineDef *outlines;
- outlines= OutlineCreate(None,$4);
- $$= ShapeDeclCreate($2,outlines);
- }
- ;
-
-SectionDecl : SECTION String OBRACE SectionBody CBRACE SEMI
- { $$= SectionDeclCreate($2,$4); }
- ;
-
-SectionBody : SectionBody SectionBodyItem
- { $$=(RowDef *)AppendStmt(&$1->common,&$2->common);}
- | SectionBodyItem
- { $$= $1; }
- ;
-
-SectionBodyItem : ROW OBRACE RowBody CBRACE SEMI
- { $$= RowDeclCreate($3); }
- | VarDecl
- { $$= (RowDef *)$1; }
- | DoodadDecl
- { $$= (RowDef *)$1; }
- | IndicatorMapDecl
- { $$= (RowDef *)$1; }
- | OverlayDecl
- { $$= (RowDef *)$1; }
- ;
-
-RowBody : RowBody RowBodyItem
- { $$=(KeyDef *)AppendStmt(&$1->common,&$2->common);}
- | RowBodyItem
- { $$= $1; }
- ;
-
-RowBodyItem : KEYS OBRACE Keys CBRACE SEMI
- { $$= $3; }
- | VarDecl
- { $$= (KeyDef *)$1; }
- ;
-
-Keys : Keys COMMA Key
- { $$=(KeyDef *)AppendStmt(&$1->common,&$3->common);}
- | Key
- { $$= $1; }
- ;
-
-Key : KeyName
- { $$= KeyDeclCreate($1,NULL); }
- | OBRACE ExprList CBRACE
- { $$= KeyDeclCreate(NULL,$2); }
- ;
-
-OverlayDecl : OVERLAY String OBRACE OverlayKeyList CBRACE SEMI
- { $$= OverlayDeclCreate($2,$4); }
- ;
-
-OverlayKeyList : OverlayKeyList COMMA OverlayKey
- {
- $$= (OverlayKeyDef *)
- AppendStmt(&$1->common,&$3->common);
- }
- | OverlayKey
- { $$= $1; }
- ;
-
-OverlayKey : KeyName EQUALS KeyName
- { $$= OverlayKeyCreate($1,$3); }
- ;
-
-OutlineList : OutlineList COMMA OutlineInList
- { $$=(OutlineDef *)AppendStmt(&$1->common,&$3->common);}
- | OutlineInList
- { $$= $1; }
- ;
-
-OutlineInList : OBRACE CoordList CBRACE
- { $$= OutlineCreate(None,$2); }
- | Ident EQUALS OBRACE CoordList CBRACE
- { $$= OutlineCreate($1,$4); }
- | Ident EQUALS Expr
- { $$= OutlineCreate($1,$3); }
- ;
-
-CoordList : CoordList COMMA Coord
- { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
- | Coord
- { $$= $1; }
- ;
-
-Coord : OBRACKET SignedNumber COMMA SignedNumber CBRACKET
- {
- ExprDef *expr;
- expr= ExprCreate(ExprCoord,TypeUnknown);
- expr->value.coord.x= $2;
- expr->value.coord.y= $4;
- $$= expr;
- }
- ;
-
-DoodadDecl : DoodadType String OBRACE VarDeclList CBRACE SEMI
- { $$= DoodadCreate($1,$2,$4); }
- ;
-
-DoodadType : TEXT { $$= XkbTextDoodad; }
- | OUTLINE { $$= XkbOutlineDoodad; }
- | SOLID { $$= XkbSolidDoodad; }
- | LOGO { $$= XkbLogoDoodad; }
- ;
-
-FieldSpec : Ident { $$= $1; }
- | Element { $$= $1; }
- ;
-
-Element : ACTION_TOK
- { $$= XkbInternAtom(NULL,"action",False); }
- | INTERPRET
- { $$= XkbInternAtom(NULL,"interpret",False); }
- | TYPE
- { $$= XkbInternAtom(NULL,"type",False); }
- | KEY
- { $$= XkbInternAtom(NULL,"key",False); }
- | GROUP
- { $$= XkbInternAtom(NULL,"group",False); }
- | MODIFIER_MAP
- {$$=XkbInternAtom(NULL,"modifier_map",False);}
- | INDICATOR
- { $$= XkbInternAtom(NULL,"indicator",False); }
- | SHAPE
- { $$= XkbInternAtom(NULL,"shape",False); }
- | ROW
- { $$= XkbInternAtom(NULL,"row",False); }
- | SECTION
- { $$= XkbInternAtom(NULL,"section",False); }
- | TEXT
- { $$= XkbInternAtom(NULL,"text",False); }
- ;
-
-OptMergeMode : MergeMode { $$= $1; }
- | { $$= MergeDefault; }
- ;
-
-MergeMode : INCLUDE { $$= MergeDefault; }
- | AUGMENT { $$= MergeAugment; }
- | OVERRIDE { $$= MergeOverride; }
- | REPLACE { $$= MergeReplace; }
- | ALTERNATE { $$= MergeAltForm; }
- ;
-
-OptExprList : ExprList { $$= $1; }
- | { $$= NULL; }
- ;
-
-ExprList : ExprList COMMA Expr
- { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
- | Expr
- { $$= $1; }
- ;
-
-Expr : Expr DIVIDE Expr
- { $$= ExprCreateBinary(OpDivide,$1,$3); }
- | Expr PLUS Expr
- { $$= ExprCreateBinary(OpAdd,$1,$3); }
- | Expr MINUS Expr
- { $$= ExprCreateBinary(OpSubtract,$1,$3); }
- | Expr TIMES Expr
- { $$= ExprCreateBinary(OpMultiply,$1,$3); }
- | Lhs EQUALS Expr
- { $$= ExprCreateBinary(OpAssign,$1,$3); }
- | Term
- { $$= $1; }
- ;
-
-Term : MINUS Term
- { $$= ExprCreateUnary(OpNegate,$2->type,$2); }
- | PLUS Term
- { $$= ExprCreateUnary(OpUnaryPlus,$2->type,$2); }
- | EXCLAM Term
- { $$= ExprCreateUnary(OpNot,TypeBoolean,$2); }
- | INVERT Term
- { $$= ExprCreateUnary(OpInvert,$2->type,$2); }
- | Lhs
- { $$= $1; }
- | FieldSpec OPAREN OptExprList CPAREN %prec OPAREN
- { $$= ActionCreate($1,$3); }
- | Terminal
- { $$= $1; }
- | OPAREN Expr CPAREN
- { $$= $2; }
- ;
-
-ActionList : ActionList COMMA Action
- { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
- | Action
- { $$= $1; }
- ;
-
-Action : FieldSpec OPAREN OptExprList CPAREN
- { $$= ActionCreate($1,$3); }
- ;
-
-Lhs : FieldSpec
- {
- ExprDef *expr;
- expr= ExprCreate(ExprIdent,TypeUnknown);
- expr->value.str= $1;
- $$= expr;
- }
- | FieldSpec DOT FieldSpec
- {
- ExprDef *expr;
- expr= ExprCreate(ExprFieldRef,TypeUnknown);
- expr->value.field.element= $1;
- expr->value.field.field= $3;
- $$= expr;
- }
- | FieldSpec OBRACKET Expr CBRACKET
- {
- ExprDef *expr;
- expr= ExprCreate(ExprArrayRef,TypeUnknown);
- expr->value.array.element= None;
- expr->value.array.field= $1;
- expr->value.array.entry= $3;
- $$= expr;
- }
- | FieldSpec DOT FieldSpec OBRACKET Expr CBRACKET
- {
- ExprDef *expr;
- expr= ExprCreate(ExprArrayRef,TypeUnknown);
- expr->value.array.element= $1;
- expr->value.array.field= $3;
- expr->value.array.entry= $5;
- $$= expr;
- }
- ;
-
-Terminal : String
- {
- ExprDef *expr;
- expr= ExprCreate(ExprValue,TypeString);
- expr->value.str= $1;
- $$= expr;
- }
- | Integer
- {
- ExprDef *expr;
- expr= ExprCreate(ExprValue,TypeInt);
- expr->value.ival= $1;
- $$= expr;
- }
- | Float
- {
- ExprDef *expr;
- expr= ExprCreate(ExprValue,TypeFloat);
- expr->value.ival= $1;
- $$= expr;
- }
- | KeyName
- {
- ExprDef *expr;
- expr= ExprCreate(ExprValue,TypeKeyName);
- memset(expr->value.keyName,0,5);
- strncpy(expr->value.keyName,$1,4);
- free($1);
- $$= expr;
- }
- ;
-
-OptKeySymList : KeySymList { $$= $1; }
- | { $$= NULL; }
- ;
-
-KeySymList : KeySymList COMMA KeySym
- { $$= AppendKeysymList($1,$3); }
- | KeySym
- { $$= CreateKeysymList($1); }
- ;
-
-KeySym : IDENT { $$= strdup(scanBuf); }
- | SECTION { $$= strdup("section"); }
- | Integer
- {
- if ($1<10) { $$= malloc(2); $$[0]= '0' + $1; $$[1]= '\0'; }
- else { $$= malloc(19); snprintf($$, 19, "0x%x", $1); }
- }
- ;
-
-SignedNumber : MINUS Number { $$= -$2; }
- | Number { $$= $1; }
- ;
-
-Number : FLOAT { $$= scanInt; }
- | INTEGER { $$= scanInt*XkbGeomPtsPerMM; }
- ;
-
-Float : FLOAT { $$= scanInt; }
- ;
-
-Integer : INTEGER { $$= scanInt; }
- ;
-
-KeyName : KEYNAME { $$= strdup(scanBuf); }
- ;
-
-Ident : IDENT { $$= XkbInternAtom(NULL,scanBuf,False); }
- | DEFAULT { $$= XkbInternAtom(NULL,"default",False); }
- ;
-
-String : STRING { $$= XkbInternAtom(NULL,scanBuf,False); }
- ;
-
-OptMapName : MapName { $$= $1; }
- | { $$= NULL; }
- ;
-
-MapName : STRING { $$= strdup(scanBuf); }
- ;
-%%
-void
-yyerror(const char *s)
-{
- if (warningLevel>0) {
- (void)fprintf(stderr,"%s: line %d of %s\n",s,lineNum,
- (scanFile?scanFile:"(unknown)"));
- if ((warningLevel>3))
- (void)fprintf(stderr,"last scanned symbol is: %s\n",scanBuf);
- }
- return;
-}
-
-
-int
-yywrap(void)
-{
- return 1;
-}
-
+/************************************************************
+ Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
+
+ Permission to use, copy, modify, and distribute this
+ software and its documentation for any purpose and without
+ fee is hereby granted, provided that the above copyright
+ notice appear in all copies and that both that copyright
+ notice and this permission notice appear in supporting
+ documentation, and that the name of Silicon Graphics not be
+ used in advertising or publicity pertaining to distribution
+ of the software without specific prior written permission.
+ Silicon Graphics makes no representation about the suitability
+ of this software for any purpose. It is provided "as is"
+ without any express or implied warranty.
+
+ SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+ GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
+ THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+ ********************************************************/
+
+%token
+ END_OF_FILE 0
+ ERROR_TOK 255
+ XKB_KEYMAP 1
+ XKB_KEYCODES 2
+ XKB_TYPES 3
+ XKB_SYMBOLS 4
+ XKB_COMPATMAP 5
+ XKB_GEOMETRY 6
+ XKB_SEMANTICS 7
+ XKB_LAYOUT 8
+ INCLUDE 10
+ OVERRIDE 11
+ AUGMENT 12
+ REPLACE 13
+ ALTERNATE 14
+ VIRTUAL_MODS 20
+ TYPE 21
+ INTERPRET 22
+ ACTION_TOK 23
+ KEY 24
+ ALIAS 25
+ GROUP 26
+ MODIFIER_MAP 27
+ INDICATOR 28
+ SHAPE 29
+ KEYS 30
+ ROW 31
+ SECTION 32
+ OVERLAY 33
+ TEXT 34
+ OUTLINE 35
+ SOLID 36
+ LOGO 37
+ VIRTUAL 38
+ EQUALS 40
+ PLUS 41
+ MINUS 42
+ DIVIDE 43
+ TIMES 44
+ OBRACE 45
+ CBRACE 46
+ OPAREN 47
+ CPAREN 48
+ OBRACKET 49
+ CBRACKET 50
+ DOT 51
+ COMMA 52
+ SEMI 53
+ EXCLAM 54
+ INVERT 55
+ STRING 60
+ INTEGER 61
+ FLOAT 62
+ IDENT 63
+ KEYNAME 64
+ PARTIAL 70
+ DEFAULT 71
+ HIDDEN 72
+ ALPHANUMERIC_KEYS 73
+ MODIFIER_KEYS 74
+ KEYPAD_KEYS 75
+ FUNCTION_KEYS 76
+ ALTERNATE_GROUP 77
+%{
+#ifdef DEBUG
+#define YYDEBUG 1
+#endif
+#define DEBUG_VAR parseDebug
+#include "parseutils.h"
+#include <X11/keysym.h>
+#include <X11/extensions/XKBgeom.h>
+#include <stdlib.h>
+
+unsigned int parseDebug;
+
+%}
+%right EQUALS
+%left PLUS MINUS
+%left TIMES DIVIDE
+%left EXCLAM INVERT
+%left OPAREN
+%start XkbFile
+%union {
+ int ival;
+ unsigned uval;
+ char *str;
+ Atom sval;
+ ParseCommon *any;
+ ExprDef *expr;
+ VarDef *var;
+ VModDef *vmod;
+ InterpDef *interp;
+ KeyTypeDef *keyType;
+ SymbolsDef *syms;
+ ModMapDef *modMask;
+ GroupCompatDef *groupCompat;
+ IndicatorMapDef *ledMap;
+ IndicatorNameDef *ledName;
+ KeycodeDef *keyName;
+ KeyAliasDef *keyAlias;
+ ShapeDef *shape;
+ SectionDef *section;
+ RowDef *row;
+ KeyDef *key;
+ OverlayDef *overlay;
+ OverlayKeyDef *olKey;
+ OutlineDef *outline;
+ DoodadDef *doodad;
+ XkbFile *file;
+}
+%type <ival> Number Integer Float SignedNumber
+%type <uval> XkbCompositeType FileType MergeMode OptMergeMode
+%type <uval> DoodadType Flag Flags OptFlags
+%type <str> KeyName MapName OptMapName KeySym
+%type <sval> FieldSpec Ident Element String
+%type <any> DeclList Decl
+%type <expr> OptExprList ExprList Expr Term Lhs Terminal ArrayInit
+%type <expr> OptKeySymList KeySymList Action ActionList Coord CoordList
+%type <var> VarDecl VarDeclList SymbolsBody SymbolsVarDecl
+%type <vmod> VModDecl VModDefList VModDef
+%type <interp> InterpretDecl InterpretMatch
+%type <keyType> KeyTypeDecl
+%type <syms> SymbolsDecl
+%type <modMask> ModMapDecl
+%type <groupCompat> GroupCompatDecl
+%type <ledMap> IndicatorMapDecl
+%type <ledName> IndicatorNameDecl
+%type <keyName> KeyNameDecl
+%type <keyAlias> KeyAliasDecl
+%type <shape> ShapeDecl
+%type <section> SectionDecl
+%type <row> SectionBody SectionBodyItem
+%type <key> RowBody RowBodyItem Keys Key
+%type <overlay> OverlayDecl
+%type <olKey> OverlayKeyList OverlayKey
+%type <outline> OutlineList OutlineInList
+%type <doodad> DoodadDecl
+%type <file> XkbFile XkbMapConfigList XkbMapConfig XkbConfig
+%type <file> XkbCompositeMap XkbCompMapList
+%%
+XkbFile : XkbCompMapList
+ { $$= rtrnValue= $1; }
+ | XkbMapConfigList
+ { $$= rtrnValue= $1; }
+ | XkbConfig
+ { $$= rtrnValue= $1; }
+ ;
+
+XkbCompMapList : XkbCompMapList XkbCompositeMap
+ { $$= (XkbFile *)AppendStmt(&$1->common,&$2->common); }
+ | XkbCompositeMap
+ { $$= $1; }
+ ;
+
+XkbCompositeMap : OptFlags XkbCompositeType OptMapName OBRACE
+ XkbMapConfigList
+ CBRACE SEMI
+ { $$= CreateXKBFile($2,$3,&$5->common,$1); }
+ ;
+
+XkbCompositeType: XKB_KEYMAP { $$= XkmKeymapFile; }
+ | XKB_SEMANTICS { $$= XkmSemanticsFile; }
+ | XKB_LAYOUT { $$= XkmLayoutFile; }
+ ;
+
+XkbMapConfigList : XkbMapConfigList XkbMapConfig
+ { $$= (XkbFile *)AppendStmt(&$1->common,&$2->common); }
+ | XkbMapConfig
+ { $$= $1; }
+ ;
+
+XkbMapConfig : OptFlags FileType OptMapName OBRACE
+ DeclList
+ CBRACE SEMI
+ { $$= CreateXKBFile($2,$3,$5,$1); }
+ ;
+
+XkbConfig : OptFlags FileType OptMapName DeclList
+ { $$= CreateXKBFile($2,$3,$4,$1); }
+ ;
+
+
+FileType : XKB_KEYCODES { $$= XkmKeyNamesIndex; }
+ | XKB_TYPES { $$= XkmTypesIndex; }
+ | XKB_COMPATMAP { $$= XkmCompatMapIndex; }
+ | XKB_SYMBOLS { $$= XkmSymbolsIndex; }
+ | XKB_GEOMETRY { $$= XkmGeometryIndex; }
+ ;
+
+OptFlags : Flags { $$= $1; }
+ | { $$= 0; }
+ ;
+
+Flags : Flags Flag { $$= (($1)|($2)); }
+ | Flag { $$= $1; }
+ ;
+
+Flag : PARTIAL { $$= XkbLC_Partial; }
+ | DEFAULT { $$= XkbLC_Default; }
+ | HIDDEN { $$= XkbLC_Hidden; }
+ | ALPHANUMERIC_KEYS { $$= XkbLC_AlphanumericKeys; }
+ | MODIFIER_KEYS { $$= XkbLC_ModifierKeys; }
+ | KEYPAD_KEYS { $$= XkbLC_KeypadKeys; }
+ | FUNCTION_KEYS { $$= XkbLC_FunctionKeys; }
+ | ALTERNATE_GROUP { $$= XkbLC_AlternateGroup; }
+ ;
+
+DeclList : DeclList Decl
+ { $$= AppendStmt($1,$2); }
+ | { $$= NULL; }
+ ;
+
+Decl : OptMergeMode VarDecl
+ {
+ $2->merge= StmtSetMerge(&$2->common,$1);
+ $$= &$2->common;
+ }
+ | OptMergeMode VModDecl
+ {
+ $2->merge= StmtSetMerge(&$2->common,$1);
+ $$= &$2->common;
+ }
+ | OptMergeMode InterpretDecl
+ {
+ $2->merge= StmtSetMerge(&$2->common,$1);
+ $$= &$2->common;
+ }
+ | OptMergeMode KeyNameDecl
+ {
+ $2->merge= StmtSetMerge(&$2->common,$1);
+ $$= &$2->common;
+ }
+ | OptMergeMode KeyAliasDecl
+ {
+ $2->merge= StmtSetMerge(&$2->common,$1);
+ $$= &$2->common;
+ }
+ | OptMergeMode KeyTypeDecl
+ {
+ $2->merge= StmtSetMerge(&$2->common,$1);
+ $$= &$2->common;
+ }
+ | OptMergeMode SymbolsDecl
+ {
+ $2->merge= StmtSetMerge(&$2->common,$1);
+ $$= &$2->common;
+ }
+ | OptMergeMode ModMapDecl
+ {
+ $2->merge= StmtSetMerge(&$2->common,$1);
+ $$= &$2->common;
+ }
+ | OptMergeMode GroupCompatDecl
+ {
+ $2->merge= StmtSetMerge(&$2->common,$1);
+ $$= &$2->common;
+ }
+ | OptMergeMode IndicatorMapDecl
+ {
+ $2->merge= StmtSetMerge(&$2->common,$1);
+ $$= &$2->common;
+ }
+ | OptMergeMode IndicatorNameDecl
+ {
+ $2->merge= StmtSetMerge(&$2->common,$1);
+ $$= &$2->common;
+ }
+ | OptMergeMode ShapeDecl
+ {
+ $2->merge= StmtSetMerge(&$2->common,$1);
+ $$= &$2->common;
+ }
+ | OptMergeMode SectionDecl
+ {
+ $2->merge= StmtSetMerge(&$2->common,$1);
+ $$= &$2->common;
+ }
+ | OptMergeMode DoodadDecl
+ {
+ $2->merge= StmtSetMerge(&$2->common,$1);
+ $$= &$2->common;
+ }
+ | MergeMode STRING
+ {
+ if ($1==MergeAltForm) {
+ yyerror("cannot use 'alternate' to include other maps");
+ $$= &IncludeCreate(scanBuf,MergeDefault)->common;
+ }
+ else {
+ $$= &IncludeCreate(scanBuf,$1)->common;
+ }
+ }
+ ;
+
+VarDecl : Lhs EQUALS Expr SEMI
+ { $$= VarCreate($1,$3); }
+ | Ident SEMI
+ { $$= BoolVarCreate($1,1); }
+ | EXCLAM Ident SEMI
+ { $$= BoolVarCreate($2,0); }
+ ;
+
+KeyNameDecl : KeyName EQUALS Expr SEMI
+ {
+ KeycodeDef *def;
+
+ def= KeycodeCreate($1,$3);
+ if ($1)
+ free($1);
+ $$= def;
+ }
+ ;
+
+KeyAliasDecl : ALIAS KeyName EQUALS KeyName SEMI
+ {
+ KeyAliasDef *def;
+ def= KeyAliasCreate($2,$4);
+ if ($2) free($2);
+ if ($4) free($4);
+ $$= def;
+ }
+ ;
+
+VModDecl : VIRTUAL_MODS VModDefList SEMI
+ { $$= $2; }
+ ;
+
+VModDefList : VModDefList COMMA VModDef
+ { $$= (VModDef *)AppendStmt(&$1->common,&$3->common); }
+ | VModDef
+ { $$= $1; }
+ ;
+
+VModDef : Ident
+ { $$= VModCreate($1,NULL); }
+ | Ident EQUALS Expr
+ { $$= VModCreate($1,$3); }
+ ;
+
+InterpretDecl : INTERPRET InterpretMatch OBRACE
+ VarDeclList
+ CBRACE SEMI
+ {
+ $2->def= $4;
+ $$= $2;
+ }
+ ;
+
+InterpretMatch : KeySym PLUS Expr
+ { $$= InterpCreate($1, $3); }
+ | KeySym
+ { $$= InterpCreate($1, NULL); }
+ ;
+
+VarDeclList : VarDeclList VarDecl
+ { $$= (VarDef *)AppendStmt(&$1->common,&$2->common); }
+ | VarDecl
+ { $$= $1; }
+ ;
+
+KeyTypeDecl : TYPE String OBRACE
+ VarDeclList
+ CBRACE SEMI
+ { $$= KeyTypeCreate($2,$4); }
+ ;
+
+SymbolsDecl : KEY KeyName OBRACE
+ SymbolsBody
+ CBRACE SEMI
+ { $$= SymbolsCreate($2,(ExprDef *)$4); }
+ ;
+
+SymbolsBody : SymbolsBody COMMA SymbolsVarDecl
+ { $$= (VarDef *)AppendStmt(&$1->common,&$3->common); }
+ | SymbolsVarDecl
+ { $$= $1; }
+ | { $$= NULL; }
+ ;
+
+SymbolsVarDecl : Lhs EQUALS Expr
+ { $$= VarCreate($1,$3); }
+ | Lhs EQUALS ArrayInit
+ { $$= VarCreate($1,$3); }
+ | Ident
+ { $$= BoolVarCreate($1,1); }
+ | EXCLAM Ident
+ { $$= BoolVarCreate($2,0); }
+ | ArrayInit
+ { $$= VarCreate(NULL,$1); }
+ ;
+
+ArrayInit : OBRACKET OptKeySymList CBRACKET
+ { $$= $2; }
+ | OBRACKET ActionList CBRACKET
+ { $$= ExprCreateUnary(ExprActionList,TypeAction,$2); }
+ ;
+
+GroupCompatDecl : GROUP Integer EQUALS Expr SEMI
+ { $$= GroupCompatCreate($2,$4); }
+ ;
+
+ModMapDecl : MODIFIER_MAP Ident OBRACE ExprList CBRACE SEMI
+ { $$= ModMapCreate($2,$4); }
+ ;
+
+IndicatorMapDecl: INDICATOR String OBRACE VarDeclList CBRACE SEMI
+ { $$= IndicatorMapCreate($2,$4); }
+ ;
+
+IndicatorNameDecl: INDICATOR Integer EQUALS Expr SEMI
+ { $$= IndicatorNameCreate($2,$4,False); }
+ | VIRTUAL INDICATOR Integer EQUALS Expr SEMI
+ { $$= IndicatorNameCreate($3,$5,True); }
+ ;
+
+ShapeDecl : SHAPE String OBRACE OutlineList CBRACE SEMI
+ { $$= ShapeDeclCreate($2,(OutlineDef *)&$4->common); }
+ | SHAPE String OBRACE CoordList CBRACE SEMI
+ {
+ OutlineDef *outlines;
+ outlines= OutlineCreate(None,$4);
+ $$= ShapeDeclCreate($2,outlines);
+ }
+ ;
+
+SectionDecl : SECTION String OBRACE SectionBody CBRACE SEMI
+ { $$= SectionDeclCreate($2,$4); }
+ ;
+
+SectionBody : SectionBody SectionBodyItem
+ { $$=(RowDef *)AppendStmt(&$1->common,&$2->common);}
+ | SectionBodyItem
+ { $$= $1; }
+ ;
+
+SectionBodyItem : ROW OBRACE RowBody CBRACE SEMI
+ { $$= RowDeclCreate($3); }
+ | VarDecl
+ { $$= (RowDef *)$1; }
+ | DoodadDecl
+ { $$= (RowDef *)$1; }
+ | IndicatorMapDecl
+ { $$= (RowDef *)$1; }
+ | OverlayDecl
+ { $$= (RowDef *)$1; }
+ ;
+
+RowBody : RowBody RowBodyItem
+ { $$=(KeyDef *)AppendStmt(&$1->common,&$2->common);}
+ | RowBodyItem
+ { $$= $1; }
+ ;
+
+RowBodyItem : KEYS OBRACE Keys CBRACE SEMI
+ { $$= $3; }
+ | VarDecl
+ { $$= (KeyDef *)$1; }
+ ;
+
+Keys : Keys COMMA Key
+ { $$=(KeyDef *)AppendStmt(&$1->common,&$3->common);}
+ | Key
+ { $$= $1; }
+ ;
+
+Key : KeyName
+ { $$= KeyDeclCreate($1,NULL); }
+ | OBRACE ExprList CBRACE
+ { $$= KeyDeclCreate(NULL,$2); }
+ ;
+
+OverlayDecl : OVERLAY String OBRACE OverlayKeyList CBRACE SEMI
+ { $$= OverlayDeclCreate($2,$4); }
+ ;
+
+OverlayKeyList : OverlayKeyList COMMA OverlayKey
+ {
+ $$= (OverlayKeyDef *)
+ AppendStmt(&$1->common,&$3->common);
+ }
+ | OverlayKey
+ { $$= $1; }
+ ;
+
+OverlayKey : KeyName EQUALS KeyName
+ { $$= OverlayKeyCreate($1,$3); }
+ ;
+
+OutlineList : OutlineList COMMA OutlineInList
+ { $$=(OutlineDef *)AppendStmt(&$1->common,&$3->common);}
+ | OutlineInList
+ { $$= $1; }
+ ;
+
+OutlineInList : OBRACE CoordList CBRACE
+ { $$= OutlineCreate(None,$2); }
+ | Ident EQUALS OBRACE CoordList CBRACE
+ { $$= OutlineCreate($1,$4); }
+ | Ident EQUALS Expr
+ { $$= OutlineCreate($1,$3); }
+ ;
+
+CoordList : CoordList COMMA Coord
+ { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
+ | Coord
+ { $$= $1; }
+ ;
+
+Coord : OBRACKET SignedNumber COMMA SignedNumber CBRACKET
+ {
+ ExprDef *expr;
+ expr= ExprCreate(ExprCoord,TypeUnknown);
+ expr->value.coord.x= $2;
+ expr->value.coord.y= $4;
+ $$= expr;
+ }
+ ;
+
+DoodadDecl : DoodadType String OBRACE VarDeclList CBRACE SEMI
+ { $$= DoodadCreate($1,$2,$4); }
+ ;
+
+DoodadType : TEXT { $$= XkbTextDoodad; }
+ | OUTLINE { $$= XkbOutlineDoodad; }
+ | SOLID { $$= XkbSolidDoodad; }
+ | LOGO { $$= XkbLogoDoodad; }
+ ;
+
+FieldSpec : Ident { $$= $1; }
+ | Element { $$= $1; }
+ ;
+
+Element : ACTION_TOK
+ { $$= XkbInternAtom(NULL,"action",False); }
+ | INTERPRET
+ { $$= XkbInternAtom(NULL,"interpret",False); }
+ | TYPE
+ { $$= XkbInternAtom(NULL,"type",False); }
+ | KEY
+ { $$= XkbInternAtom(NULL,"key",False); }
+ | GROUP
+ { $$= XkbInternAtom(NULL,"group",False); }
+ | MODIFIER_MAP
+ {$$=XkbInternAtom(NULL,"modifier_map",False);}
+ | INDICATOR
+ { $$= XkbInternAtom(NULL,"indicator",False); }
+ | SHAPE
+ { $$= XkbInternAtom(NULL,"shape",False); }
+ | ROW
+ { $$= XkbInternAtom(NULL,"row",False); }
+ | SECTION
+ { $$= XkbInternAtom(NULL,"section",False); }
+ | TEXT
+ { $$= XkbInternAtom(NULL,"text",False); }
+ ;
+
+OptMergeMode : MergeMode { $$= $1; }
+ | { $$= MergeDefault; }
+ ;
+
+MergeMode : INCLUDE { $$= MergeDefault; }
+ | AUGMENT { $$= MergeAugment; }
+ | OVERRIDE { $$= MergeOverride; }
+ | REPLACE { $$= MergeReplace; }
+ | ALTERNATE { $$= MergeAltForm; }
+ ;
+
+OptExprList : ExprList { $$= $1; }
+ | { $$= NULL; }
+ ;
+
+ExprList : ExprList COMMA Expr
+ { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
+ | Expr
+ { $$= $1; }
+ ;
+
+Expr : Expr DIVIDE Expr
+ { $$= ExprCreateBinary(OpDivide,$1,$3); }
+ | Expr PLUS Expr
+ { $$= ExprCreateBinary(OpAdd,$1,$3); }
+ | Expr MINUS Expr
+ { $$= ExprCreateBinary(OpSubtract,$1,$3); }
+ | Expr TIMES Expr
+ { $$= ExprCreateBinary(OpMultiply,$1,$3); }
+ | Lhs EQUALS Expr
+ { $$= ExprCreateBinary(OpAssign,$1,$3); }
+ | Term
+ { $$= $1; }
+ ;
+
+Term : MINUS Term
+ { $$= ExprCreateUnary(OpNegate,$2->type,$2); }
+ | PLUS Term
+ { $$= ExprCreateUnary(OpUnaryPlus,$2->type,$2); }
+ | EXCLAM Term
+ { $$= ExprCreateUnary(OpNot,TypeBoolean,$2); }
+ | INVERT Term
+ { $$= ExprCreateUnary(OpInvert,$2->type,$2); }
+ | Lhs
+ { $$= $1; }
+ | FieldSpec OPAREN OptExprList CPAREN %prec OPAREN
+ { $$= ActionCreate($1,$3); }
+ | Terminal
+ { $$= $1; }
+ | OPAREN Expr CPAREN
+ { $$= $2; }
+ ;
+
+ActionList : ActionList COMMA Action
+ { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
+ | Action
+ { $$= $1; }
+ ;
+
+Action : FieldSpec OPAREN OptExprList CPAREN
+ { $$= ActionCreate($1,$3); }
+ ;
+
+Lhs : FieldSpec
+ {
+ ExprDef *expr;
+ expr= ExprCreate(ExprIdent,TypeUnknown);
+ expr->value.str= $1;
+ $$= expr;
+ }
+ | FieldSpec DOT FieldSpec
+ {
+ ExprDef *expr;
+ expr= ExprCreate(ExprFieldRef,TypeUnknown);
+ expr->value.field.element= $1;
+ expr->value.field.field= $3;
+ $$= expr;
+ }
+ | FieldSpec OBRACKET Expr CBRACKET
+ {
+ ExprDef *expr;
+ expr= ExprCreate(ExprArrayRef,TypeUnknown);
+ expr->value.array.element= None;
+ expr->value.array.field= $1;
+ expr->value.array.entry= $3;
+ $$= expr;
+ }
+ | FieldSpec DOT FieldSpec OBRACKET Expr CBRACKET
+ {
+ ExprDef *expr;
+ expr= ExprCreate(ExprArrayRef,TypeUnknown);
+ expr->value.array.element= $1;
+ expr->value.array.field= $3;
+ expr->value.array.entry= $5;
+ $$= expr;
+ }
+ ;
+
+Terminal : String
+ {
+ ExprDef *expr;
+ expr= ExprCreate(ExprValue,TypeString);
+ expr->value.str= $1;
+ $$= expr;
+ }
+ | Integer
+ {
+ ExprDef *expr;
+ expr= ExprCreate(ExprValue,TypeInt);
+ expr->value.ival= $1;
+ $$= expr;
+ }
+ | Float
+ {
+ ExprDef *expr;
+ expr= ExprCreate(ExprValue,TypeFloat);
+ expr->value.ival= $1;
+ $$= expr;
+ }
+ | KeyName
+ {
+ ExprDef *expr;
+ expr= ExprCreate(ExprValue,TypeKeyName);
+ memset(expr->value.keyName,0,5);
+ strncpy(expr->value.keyName,$1,4);
+ free($1);
+ $$= expr;
+ }
+ ;
+
+OptKeySymList : KeySymList { $$= $1; }
+ | { $$= NULL; }
+ ;
+
+KeySymList : KeySymList COMMA KeySym
+ { $$= AppendKeysymList($1,$3); }
+ | KeySym
+ { $$= CreateKeysymList($1); }
+ ;
+
+KeySym : IDENT { $$= strdup(scanBuf); }
+ | SECTION { $$= strdup("section"); }
+ | Integer
+ {
+ if ($1<10) { $$= malloc(2); $$[0]= '0' + $1; $$[1]= '\0'; }
+ else { $$= malloc(19); snprintf($$, 19, "0x%x", $1); }
+ }
+ ;
+
+SignedNumber : MINUS Number { $$= -$2; }
+ | Number { $$= $1; }
+ ;
+
+Number : FLOAT { $$= scanInt; }
+ | INTEGER { $$= scanInt*XkbGeomPtsPerMM; }
+ ;
+
+Float : FLOAT { $$= scanInt; }
+ ;
+
+Integer : INTEGER { $$= scanInt; }
+ ;
+
+KeyName : KEYNAME { $$= strdup(scanBuf); }
+ ;
+
+Ident : IDENT { $$= XkbInternAtom(NULL,scanBuf,False); }
+ | DEFAULT { $$= XkbInternAtom(NULL,"default",False); }
+ ;
+
+String : STRING { $$= XkbInternAtom(NULL,scanBuf,False); }
+ ;
+
+OptMapName : MapName { $$= $1; }
+ | { $$= NULL; }
+ ;
+
+MapName : STRING { $$= strdup(scanBuf); }
+ ;
+%%
+void
+yyerror(const char *s)
+{
+ if (warningLevel>0) {
+ (void)fprintf(stderr,"%s: line %d of %s\n",s,lineNum,
+ (scanFile?scanFile:"(unknown)"));
+ if ((warningLevel>3))
+ (void)fprintf(stderr,"last scanned symbol is: %s\n",scanBuf);
+ }
+ return;
+}
+
+
+int
+yywrap(void)
+{
+ return 1;
+}
+