1/* DRI.c -- DRI Section in XF86Config file
2 * Created: Fri Mar 19 08:40:22 1999 by faith@precisioninsight.com
3 * Revised: Thu Jun 17 16:08:05 1999 by faith@precisioninsight.com
4 *
5 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
6 * All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
17 * Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
22 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
26 *
27 *
28 */
29
30#ifdef HAVE_XORG_CONFIG_H
31#include <xorg-config.h>
32#endif
33
34#include "xf86Parser.h"
35#include "xf86tokens.h"
36#include "Configint.h"
37
38extern LexRec val;
39
40static xf86ConfigSymTabRec DRITab[] =
41{
42    {ENDSECTION, "endsection"},
43    {GROUP,      "group"},
44    {MODE,       "mode"},
45    {-1,         ""},
46};
47
48#define CLEANUP xf86freeDRI
49
50XF86ConfDRIPtr
51xf86parseDRISection (void)
52{
53    int token;
54    parsePrologue (XF86ConfDRIPtr, XF86ConfDRIRec);
55
56    /* Zero is a valid value for this. */
57    ptr->dri_group = -1;
58    while ((token = xf86getToken (DRITab)) != ENDSECTION) {
59	switch (token)
60	    {
61	    case GROUP:
62		if ((token = xf86getSubToken (&(ptr->dri_comment))) == STRING)
63		    ptr->dri_group_name = val.str;
64		else if (token == NUMBER)
65		    ptr->dri_group = val.num;
66		else
67		    Error (GROUP_MSG, NULL);
68		break;
69	    case MODE:
70		if (xf86getSubToken (&(ptr->dri_comment)) != NUMBER)
71		    Error (NUMBER_MSG, "Mode");
72                if (val.numType != PARSE_OCTAL)
73                    Error (MUST_BE_OCTAL_MSG, val.num);
74		ptr->dri_mode = val.num;
75		break;
76	    case EOF_TOKEN:
77		Error (UNEXPECTED_EOF_MSG, NULL);
78		break;
79	    case COMMENT:
80		ptr->dri_comment = xf86addComment(ptr->dri_comment, val.str);
81		break;
82	    default:
83		Error (INVALID_KEYWORD_MSG, xf86tokenString ());
84		break;
85	    }
86    }
87
88#ifdef DEBUG
89    ErrorF("DRI section parsed\n");
90#endif
91
92    return ptr;
93}
94
95#undef CLEANUP
96
97void
98xf86printDRISection (FILE * cf, XF86ConfDRIPtr ptr)
99{
100    if (ptr == NULL)
101	return;
102
103    fprintf (cf, "Section \"DRI\"\n");
104    if (ptr->dri_comment)
105	fprintf (cf, "%s", ptr->dri_comment);
106    if (ptr->dri_group_name)
107	fprintf (cf, "\tGroup        \"%s\"\n", ptr->dri_group_name);
108    else if (ptr->dri_group >= 0)
109	fprintf (cf, "\tGroup        %d\n", ptr->dri_group);
110    if (ptr->dri_mode)
111	fprintf (cf, "\tMode         0%o\n", ptr->dri_mode);
112    fprintf (cf, "EndSection\n\n");
113}
114
115void
116xf86freeDRI (XF86ConfDRIPtr ptr)
117{
118    if (ptr == NULL)
119	return;
120
121    TestFree (ptr->dri_comment);
122    free (ptr);
123}
124