Extensions.c revision 58cf2af7
1/*
2 * Copyright 2004 Red Hat Inc., Raleigh, North Carolina.
3 *
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation on the rights to use, copy, modify, merge,
10 * publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial
16 * portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NON-INFRINGEMENT.  IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
22 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 */
27
28/*
29 * Authors:
30 *   Kevin E. Martin <kem@redhat.com>
31 *
32 */
33
34#ifdef HAVE_XORG_CONFIG_H
35#include <xorg-config.h>
36#endif
37
38#include "os.h"
39#include "xf86Parser.h"
40#include "xf86tokens.h"
41#include "Configint.h"
42
43
44static const xf86ConfigSymTabRec ExtensionsTab[] = {
45    {ENDSECTION, "endsection"},
46    {OPTION, "option"},
47    {-1, ""},
48};
49
50#define CLEANUP xf86freeExtensions
51
52XF86ConfExtensionsPtr
53xf86parseExtensionsSection(void)
54{
55    int token;
56
57    parsePrologue(XF86ConfExtensionsPtr, XF86ConfExtensionsRec);
58
59    while ((token = xf86getToken(ExtensionsTab)) != ENDSECTION) {
60        switch (token) {
61        case OPTION:
62            ptr->ext_option_lst = xf86parseOption(ptr->ext_option_lst);
63            break;
64        case EOF_TOKEN:
65            Error(UNEXPECTED_EOF_MSG);
66            break;
67        case COMMENT:
68            ptr->extensions_comment =
69                xf86addComment(ptr->extensions_comment, xf86_lex_val.str);
70            free(xf86_lex_val.str);
71            xf86_lex_val.str = NULL;
72            break;
73        default:
74            Error(INVALID_KEYWORD_MSG, xf86tokenString());
75            break;
76        }
77    }
78
79#ifdef DEBUG
80    ErrorF("Extensions section parsed\n");
81#endif
82
83    return ptr;
84}
85
86#undef CLEANUP
87
88void
89xf86printExtensionsSection(FILE * cf, XF86ConfExtensionsPtr ptr)
90{
91    XF86OptionPtr p;
92
93    if (ptr == NULL || ptr->ext_option_lst == NULL)
94        return;
95
96    p = ptr->ext_option_lst;
97    fprintf(cf, "Section \"Extensions\"\n");
98    if (ptr->extensions_comment)
99        fprintf(cf, "%s", ptr->extensions_comment);
100    xf86printOptionList(cf, p, 1);
101    fprintf(cf, "EndSection\n\n");
102}
103
104void
105xf86freeExtensions(XF86ConfExtensionsPtr ptr)
106{
107    if (ptr == NULL)
108        return;
109
110    xf86optionListFree(ptr->ext_option_lst);
111    TestFree(ptr->extensions_comment);
112    free(ptr);
113}
114