1117N/A/* DRI.c -- DRI Section in XF86Config file
1117N/A * Created: Fri Mar 19 08:40:22 1999 by faith@precisioninsight.com
1117N/A * Revised: Thu Jun 17 16:08:05 1999 by faith@precisioninsight.com
1117N/A *
1117N/A * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
1117N/A * All Rights Reserved.
1117N/A *
1117N/A * Permission is hereby granted, free of charge, to any person obtaining a
1117N/A * copy of this software and associated documentation files (the "Software"),
1117N/A * to deal in the Software without restriction, including without limitation
1117N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1117N/A * and/or sell copies of the Software, and to permit persons to whom the
1117N/A * Software is furnished to do so, subject to the following conditions:
1117N/A *
1117N/A * The above copyright notice and this permission notice (including the next
1117N/A * paragraph) shall be included in all copies or substantial portions of the
1117N/A * Software.
1117N/A *
1117N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1117N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1117N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1117N/A * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
1117N/A * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1117N/A * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1117N/A * DEALINGS IN THE SOFTWARE.
1117N/A *
1117N/A *
1117N/A */
1117N/A
1117N/A#ifdef HAVE_XORG_CONFIG_H
1117N/A#include <xorg-config.h>
1117N/A#endif
1117N/A
1117N/A#include "xf86Parser.h"
1117N/A#include "xf86tokens.h"
1117N/A#include "Configint.h"
1117N/A
1117N/Aextern LexRec val;
1117N/A
1117N/Astatic xf86ConfigSymTabRec DRITab[] =
1117N/A{
1117N/A {ENDSECTION, "endsection"},
1117N/A {GROUP, "group"},
1117N/A {BUFFERS, "buffers"},
1117N/A {MODE, "mode"},
1117N/A {-1, ""},
1117N/A};
1117N/A
1117N/A#define CLEANUP xf86freeBuffersList
1117N/A
1117N/AXF86ConfBuffersPtr
1117N/Axf86parseBuffers (void)
1117N/A{
1117N/A int token;
1117N/A parsePrologue (XF86ConfBuffersPtr, XF86ConfBuffersRec)
1117N/A
1117N/A if (xf86getSubToken (&(ptr->buf_comment)) != NUMBER)
1117N/A Error ("Buffers count expected", NULL);
1117N/A ptr->buf_count = val.num;
1117N/A
1117N/A if (xf86getSubToken (&(ptr->buf_comment)) != NUMBER)
1117N/A Error ("Buffers size expected", NULL);
1117N/A ptr->buf_size = val.num;
1117N/A
1117N/A if ((token = xf86getSubToken (&(ptr->buf_comment))) == STRING) {
1117N/A ptr->buf_flags = val.str;
1117N/A if ((token = xf86getToken (NULL)) == COMMENT)
1117N/A ptr->buf_comment = xf86addComment(ptr->buf_comment, val.str);
1117N/A else
1117N/A xf86unGetToken(token);
1117N/A }
1117N/A
1117N/A#ifdef DEBUG
1117N/A printf ("Buffers parsed\n");
1117N/A#endif
1117N/A
1117N/A return ptr;
1117N/A}
1117N/A
1117N/A#undef CLEANUP
1117N/A
1117N/A#define CLEANUP xf86freeDRI
1117N/A
1117N/AXF86ConfDRIPtr
1117N/Axf86parseDRISection (void)
1117N/A{
1117N/A int token;
1117N/A parsePrologue (XF86ConfDRIPtr, XF86ConfDRIRec);
1117N/A
1117N/A /* Zero is a valid value for this. */
1117N/A ptr->dri_group = -1;
1117N/A while ((token = xf86getToken (DRITab)) != ENDSECTION) {
1117N/A switch (token)
1117N/A {
1117N/A case GROUP:
1117N/A if ((token = xf86getSubToken (&(ptr->dri_comment))) == STRING)
1117N/A ptr->dri_group_name = val.str;
1117N/A else if (token == NUMBER)
1117N/A ptr->dri_group = val.num;
1117N/A else
1117N/A Error (GROUP_MSG, NULL);
1117N/A break;
1117N/A case MODE:
1117N/A if (xf86getSubToken (&(ptr->dri_comment)) != NUMBER)
1117N/A Error (NUMBER_MSG, "Mode");
1117N/A ptr->dri_mode = val.num;
1117N/A break;
1117N/A case BUFFERS:
1117N/A HANDLE_LIST (dri_buffers_lst, xf86parseBuffers,
1117N/A XF86ConfBuffersPtr);
1117N/A break;
1117N/A case EOF_TOKEN:
1117N/A Error (UNEXPECTED_EOF_MSG, NULL);
1117N/A break;
1117N/A case COMMENT:
1117N/A ptr->dri_comment = xf86addComment(ptr->dri_comment, val.str);
1117N/A break;
1117N/A default:
1117N/A Error (INVALID_KEYWORD_MSG, xf86tokenString ());
1117N/A break;
1117N/A }
1117N/A }
1117N/A
1117N/A#ifdef DEBUG
1117N/A ErrorF("DRI section parsed\n");
1117N/A#endif
1117N/A
1117N/A return ptr;
1117N/A}
1117N/A
1117N/A#undef CLEANUP
1117N/A
1117N/Avoid
1117N/Axf86printDRISection (FILE * cf, XF86ConfDRIPtr ptr)
1117N/A{
1117N/A XF86ConfBuffersPtr bufs;
1117N/A
1117N/A if (ptr == NULL)
1117N/A return;
1117N/A
1117N/A fprintf (cf, "Section \"DRI\"\n");
1117N/A if (ptr->dri_comment)
1117N/A fprintf (cf, "%s", ptr->dri_comment);
1117N/A if (ptr->dri_group_name)
1117N/A fprintf (cf, "\tGroup \"%s\"\n", ptr->dri_group_name);
1117N/A else if (ptr->dri_group >= 0)
1117N/A fprintf (cf, "\tGroup %d\n", ptr->dri_group);
1117N/A if (ptr->dri_mode)
1117N/A fprintf (cf, "\tMode 0%o\n", ptr->dri_mode);
1117N/A for (bufs = ptr->dri_buffers_lst; bufs; bufs = bufs->list.next) {
1117N/A fprintf (cf, "\tBuffers %d %d",
1117N/A bufs->buf_count, bufs->buf_size);
1117N/A if (bufs->buf_flags) fprintf (cf, " \"%s\"", bufs->buf_flags);
1117N/A if (bufs->buf_comment)
1117N/A fprintf(cf, "%s", bufs->buf_comment);
1117N/A else
1117N/A fprintf (cf, "\n");
1117N/A }
1117N/A fprintf (cf, "EndSection\n\n");
1117N/A}
1117N/A
1117N/Avoid
1117N/Axf86freeDRI (XF86ConfDRIPtr ptr)
1117N/A{
1117N/A if (ptr == NULL)
1117N/A return;
1117N/A
1117N/A xf86freeBuffersList (ptr->dri_buffers_lst);
1117N/A TestFree (ptr->dri_comment);
1117N/A xf86conffree (ptr);
1117N/A}
1117N/A
1117N/Avoid
1117N/Axf86freeBuffersList (XF86ConfBuffersPtr ptr)
1117N/A{
1117N/A XF86ConfBuffersPtr prev;
1117N/A
1117N/A while (ptr) {
1117N/A TestFree (ptr->buf_flags);
1117N/A TestFree (ptr->buf_comment);
1117N/A prev = ptr;
1117N/A ptr = ptr->list.next;
1117N/A xf86conffree (prev);
1117N/A }
1117N/A}
1117N/A