135c4bbdfSmrg/*
235c4bbdfSmrg *
305b261ecSmrg * Copyright (c) 1997  Metro Link Incorporated
435c4bbdfSmrg *
505b261ecSmrg * Permission is hereby granted, free of charge, to any person obtaining a
635c4bbdfSmrg * copy of this software and associated documentation files (the "Software"),
705b261ecSmrg * to deal in the Software without restriction, including without limitation
805b261ecSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
905b261ecSmrg * and/or sell copies of the Software, and to permit persons to whom the
1005b261ecSmrg * Software is furnished to do so, subject to the following conditions:
1135c4bbdfSmrg *
1205b261ecSmrg * The above copyright notice and this permission notice shall be included in
1305b261ecSmrg * all copies or substantial portions of the Software.
1435c4bbdfSmrg *
1505b261ecSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1605b261ecSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1705b261ecSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1805b261ecSmrg * THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
1905b261ecSmrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
2005b261ecSmrg * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2105b261ecSmrg * SOFTWARE.
2235c4bbdfSmrg *
2305b261ecSmrg * Except as contained in this notice, the name of the Metro Link shall not be
2405b261ecSmrg * used in advertising or otherwise to promote the sale, use or other dealings
2505b261ecSmrg * in this Software without prior written authorization from Metro Link.
2635c4bbdfSmrg *
2705b261ecSmrg */
2805b261ecSmrg/*
2905b261ecSmrg * Copyright (c) 1997-2003 by The XFree86 Project, Inc.
3005b261ecSmrg *
3105b261ecSmrg * Permission is hereby granted, free of charge, to any person obtaining a
3205b261ecSmrg * copy of this software and associated documentation files (the "Software"),
3305b261ecSmrg * to deal in the Software without restriction, including without limitation
3405b261ecSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
3505b261ecSmrg * and/or sell copies of the Software, and to permit persons to whom the
3605b261ecSmrg * Software is furnished to do so, subject to the following conditions:
3705b261ecSmrg *
3805b261ecSmrg * The above copyright notice and this permission notice shall be included in
3905b261ecSmrg * all copies or substantial portions of the Software.
4005b261ecSmrg *
4105b261ecSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
4205b261ecSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
4305b261ecSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
4405b261ecSmrg * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
4505b261ecSmrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
4605b261ecSmrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
4705b261ecSmrg * OTHER DEALINGS IN THE SOFTWARE.
4805b261ecSmrg *
4905b261ecSmrg * Except as contained in this notice, the name of the copyright holder(s)
5005b261ecSmrg * and author(s) shall not be used in advertising or otherwise to promote
5105b261ecSmrg * the sale, use or other dealings in this Software without prior written
5205b261ecSmrg * authorization from the copyright holder(s) and author(s).
5305b261ecSmrg */
5405b261ecSmrg
5505b261ecSmrg#ifdef HAVE_XORG_CONFIG_H
5605b261ecSmrg#include <xorg-config.h>
5705b261ecSmrg#endif
5805b261ecSmrg
5905b261ecSmrg#include "xf86Parser.h"
6005b261ecSmrg#include "xf86tokens.h"
6105b261ecSmrg#include "Configint.h"
6205b261ecSmrg
6305b261ecSmrg
641b5d61b8Smrgstatic const xf86ConfigSymTabRec VideoPortTab[] = {
6535c4bbdfSmrg    {ENDSUBSECTION, "endsubsection"},
6635c4bbdfSmrg    {IDENTIFIER, "identifier"},
6735c4bbdfSmrg    {OPTION, "option"},
6835c4bbdfSmrg    {-1, ""},
6905b261ecSmrg};
7005b261ecSmrg
7105b261ecSmrg#define CLEANUP xf86freeVideoPortList
7205b261ecSmrg
7305b261ecSmrgstatic void
7435c4bbdfSmrgxf86freeVideoPortList(XF86ConfVideoPortPtr ptr)
7505b261ecSmrg{
7635c4bbdfSmrg    XF86ConfVideoPortPtr prev;
7705b261ecSmrg
7835c4bbdfSmrg    while (ptr) {
7935c4bbdfSmrg        TestFree(ptr->vp_identifier);
8035c4bbdfSmrg        TestFree(ptr->vp_comment);
8135c4bbdfSmrg        xf86optionListFree(ptr->vp_option_lst);
8235c4bbdfSmrg        prev = ptr;
8335c4bbdfSmrg        ptr = ptr->list.next;
8435c4bbdfSmrg        free(prev);
8535c4bbdfSmrg    }
8605b261ecSmrg}
8705b261ecSmrg
8805b261ecSmrgstatic XF86ConfVideoPortPtr
8935c4bbdfSmrgxf86parseVideoPortSubSection(void)
9005b261ecSmrg{
9135c4bbdfSmrg    int has_ident = FALSE;
9235c4bbdfSmrg    int token;
9335c4bbdfSmrg
9435c4bbdfSmrg    parsePrologue(XF86ConfVideoPortPtr, XF86ConfVideoPortRec)
9505b261ecSmrg
9635c4bbdfSmrg        while ((token = xf86getToken(VideoPortTab)) != ENDSUBSECTION) {
9735c4bbdfSmrg        switch (token) {
9835c4bbdfSmrg        case COMMENT:
9935c4bbdfSmrg            ptr->vp_comment = xf86addComment(ptr->vp_comment, xf86_lex_val.str);
10058cf2af7Smrg            free(xf86_lex_val.str);
10158cf2af7Smrg            xf86_lex_val.str = NULL;
10235c4bbdfSmrg            break;
10335c4bbdfSmrg        case IDENTIFIER:
10435c4bbdfSmrg            if (xf86getSubToken(&(ptr->vp_comment)) != STRING)
10535c4bbdfSmrg                Error(QUOTE_MSG, "Identifier");
10635c4bbdfSmrg            if (has_ident == TRUE)
10735c4bbdfSmrg                Error(MULTIPLE_MSG, "Identifier");
10835c4bbdfSmrg            ptr->vp_identifier = xf86_lex_val.str;
10935c4bbdfSmrg            has_ident = TRUE;
11035c4bbdfSmrg            break;
11135c4bbdfSmrg        case OPTION:
11235c4bbdfSmrg            ptr->vp_option_lst = xf86parseOption(ptr->vp_option_lst);
11335c4bbdfSmrg            break;
11405b261ecSmrg
11535c4bbdfSmrg        case EOF_TOKEN:
11635c4bbdfSmrg            Error(UNEXPECTED_EOF_MSG);
11735c4bbdfSmrg            break;
11835c4bbdfSmrg        default:
11935c4bbdfSmrg            Error(INVALID_KEYWORD_MSG, xf86tokenString());
12035c4bbdfSmrg            break;
12135c4bbdfSmrg        }
12235c4bbdfSmrg    }
12305b261ecSmrg
12405b261ecSmrg#ifdef DEBUG
12535c4bbdfSmrg    printf("VideoPort subsection parsed\n");
12605b261ecSmrg#endif
12705b261ecSmrg
12835c4bbdfSmrg    return ptr;
12905b261ecSmrg}
13005b261ecSmrg
13105b261ecSmrg#undef CLEANUP
13205b261ecSmrg
1331b5d61b8Smrgstatic const xf86ConfigSymTabRec VideoAdaptorTab[] = {
13435c4bbdfSmrg    {ENDSECTION, "endsection"},
13535c4bbdfSmrg    {IDENTIFIER, "identifier"},
13635c4bbdfSmrg    {VENDOR, "vendorname"},
13735c4bbdfSmrg    {BOARD, "boardname"},
13835c4bbdfSmrg    {BUSID, "busid"},
13935c4bbdfSmrg    {DRIVER, "driver"},
14035c4bbdfSmrg    {OPTION, "option"},
14135c4bbdfSmrg    {SUBSECTION, "subsection"},
14235c4bbdfSmrg    {-1, ""},
14305b261ecSmrg};
14405b261ecSmrg
14505b261ecSmrg#define CLEANUP xf86freeVideoAdaptorList
14605b261ecSmrg
14705b261ecSmrgXF86ConfVideoAdaptorPtr
14835c4bbdfSmrgxf86parseVideoAdaptorSection(void)
14905b261ecSmrg{
15035c4bbdfSmrg    int has_ident = FALSE;
15135c4bbdfSmrg    int token;
15205b261ecSmrg
15335c4bbdfSmrg    parsePrologue(XF86ConfVideoAdaptorPtr, XF86ConfVideoAdaptorRec)
15405b261ecSmrg
15535c4bbdfSmrg        while ((token = xf86getToken(VideoAdaptorTab)) != ENDSECTION) {
15635c4bbdfSmrg        switch (token) {
15735c4bbdfSmrg        case COMMENT:
15835c4bbdfSmrg            ptr->va_comment = xf86addComment(ptr->va_comment, xf86_lex_val.str);
15958cf2af7Smrg            free(xf86_lex_val.str);
16058cf2af7Smrg            xf86_lex_val.str = NULL;
16135c4bbdfSmrg            break;
16235c4bbdfSmrg        case IDENTIFIER:
16335c4bbdfSmrg            if (xf86getSubToken(&(ptr->va_comment)) != STRING)
16435c4bbdfSmrg                Error(QUOTE_MSG, "Identifier");
16535c4bbdfSmrg            ptr->va_identifier = xf86_lex_val.str;
16635c4bbdfSmrg            if (has_ident == TRUE)
16735c4bbdfSmrg                Error(MULTIPLE_MSG, "Identifier");
16835c4bbdfSmrg            has_ident = TRUE;
16935c4bbdfSmrg            break;
17035c4bbdfSmrg        case VENDOR:
17135c4bbdfSmrg            if (xf86getSubToken(&(ptr->va_comment)) != STRING)
17235c4bbdfSmrg                Error(QUOTE_MSG, "Vendor");
17335c4bbdfSmrg            ptr->va_vendor = xf86_lex_val.str;
17435c4bbdfSmrg            break;
17535c4bbdfSmrg        case BOARD:
17635c4bbdfSmrg            if (xf86getSubToken(&(ptr->va_comment)) != STRING)
17735c4bbdfSmrg                Error(QUOTE_MSG, "Board");
17835c4bbdfSmrg            ptr->va_board = xf86_lex_val.str;
17935c4bbdfSmrg            break;
18035c4bbdfSmrg        case BUSID:
18135c4bbdfSmrg            if (xf86getSubToken(&(ptr->va_comment)) != STRING)
18235c4bbdfSmrg                Error(QUOTE_MSG, "BusID");
18335c4bbdfSmrg            ptr->va_busid = xf86_lex_val.str;
18435c4bbdfSmrg            break;
18535c4bbdfSmrg        case DRIVER:
18635c4bbdfSmrg            if (xf86getSubToken(&(ptr->va_comment)) != STRING)
18735c4bbdfSmrg                Error(QUOTE_MSG, "Driver");
18835c4bbdfSmrg            ptr->va_driver = xf86_lex_val.str;
18935c4bbdfSmrg            break;
19035c4bbdfSmrg        case OPTION:
19135c4bbdfSmrg            ptr->va_option_lst = xf86parseOption(ptr->va_option_lst);
19235c4bbdfSmrg            break;
19335c4bbdfSmrg        case SUBSECTION:
19435c4bbdfSmrg            if (xf86getSubToken(&(ptr->va_comment)) != STRING)
19535c4bbdfSmrg                Error(QUOTE_MSG, "SubSection");
19635c4bbdfSmrg            {
19735c4bbdfSmrg                HANDLE_LIST(va_port_lst, xf86parseVideoPortSubSection,
19835c4bbdfSmrg                            XF86ConfVideoPortPtr);
19935c4bbdfSmrg            }
20035c4bbdfSmrg            break;
20105b261ecSmrg
20235c4bbdfSmrg        case EOF_TOKEN:
20335c4bbdfSmrg            Error(UNEXPECTED_EOF_MSG);
20435c4bbdfSmrg            break;
20535c4bbdfSmrg        default:
20635c4bbdfSmrg            Error(INVALID_KEYWORD_MSG, xf86tokenString());
20735c4bbdfSmrg            break;
20835c4bbdfSmrg        }
20935c4bbdfSmrg    }
21005b261ecSmrg
21135c4bbdfSmrg    if (!has_ident)
21235c4bbdfSmrg        Error(NO_IDENT_MSG);
21305b261ecSmrg
21405b261ecSmrg#ifdef DEBUG
21535c4bbdfSmrg    printf("VideoAdaptor section parsed\n");
21605b261ecSmrg#endif
21705b261ecSmrg
21835c4bbdfSmrg    return ptr;
21905b261ecSmrg}
22005b261ecSmrg
22105b261ecSmrgvoid
22235c4bbdfSmrgxf86printVideoAdaptorSection(FILE * cf, XF86ConfVideoAdaptorPtr ptr)
22305b261ecSmrg{
22435c4bbdfSmrg    XF86ConfVideoPortPtr pptr;
22505b261ecSmrg
22635c4bbdfSmrg    while (ptr) {
22735c4bbdfSmrg        fprintf(cf, "Section \"VideoAdaptor\"\n");
22835c4bbdfSmrg        if (ptr->va_comment)
22935c4bbdfSmrg            fprintf(cf, "%s", ptr->va_comment);
23035c4bbdfSmrg        if (ptr->va_identifier)
23135c4bbdfSmrg            fprintf(cf, "\tIdentifier  \"%s\"\n", ptr->va_identifier);
23235c4bbdfSmrg        if (ptr->va_vendor)
23335c4bbdfSmrg            fprintf(cf, "\tVendorName  \"%s\"\n", ptr->va_vendor);
23435c4bbdfSmrg        if (ptr->va_board)
23535c4bbdfSmrg            fprintf(cf, "\tBoardName   \"%s\"\n", ptr->va_board);
23635c4bbdfSmrg        if (ptr->va_busid)
23735c4bbdfSmrg            fprintf(cf, "\tBusID       \"%s\"\n", ptr->va_busid);
23835c4bbdfSmrg        if (ptr->va_driver)
23935c4bbdfSmrg            fprintf(cf, "\tDriver      \"%s\"\n", ptr->va_driver);
24035c4bbdfSmrg        xf86printOptionList(cf, ptr->va_option_lst, 1);
24135c4bbdfSmrg        for (pptr = ptr->va_port_lst; pptr; pptr = pptr->list.next) {
24235c4bbdfSmrg            fprintf(cf, "\tSubSection \"VideoPort\"\n");
24335c4bbdfSmrg            if (pptr->vp_comment)
24435c4bbdfSmrg                fprintf(cf, "%s", pptr->vp_comment);
24535c4bbdfSmrg            if (pptr->vp_identifier)
24635c4bbdfSmrg                fprintf(cf, "\t\tIdentifier \"%s\"\n", pptr->vp_identifier);
24735c4bbdfSmrg            xf86printOptionList(cf, pptr->vp_option_lst, 2);
24835c4bbdfSmrg            fprintf(cf, "\tEndSubSection\n");
24935c4bbdfSmrg        }
25035c4bbdfSmrg        fprintf(cf, "EndSection\n\n");
25135c4bbdfSmrg        ptr = ptr->list.next;
25235c4bbdfSmrg    }
25305b261ecSmrg
25405b261ecSmrg}
25505b261ecSmrg
25605b261ecSmrgvoid
25735c4bbdfSmrgxf86freeVideoAdaptorList(XF86ConfVideoAdaptorPtr ptr)
25805b261ecSmrg{
25935c4bbdfSmrg    XF86ConfVideoAdaptorPtr prev;
26005b261ecSmrg
26135c4bbdfSmrg    while (ptr) {
26235c4bbdfSmrg        TestFree(ptr->va_identifier);
26335c4bbdfSmrg        TestFree(ptr->va_vendor);
26435c4bbdfSmrg        TestFree(ptr->va_board);
26535c4bbdfSmrg        TestFree(ptr->va_busid);
26635c4bbdfSmrg        TestFree(ptr->va_driver);
26735c4bbdfSmrg        TestFree(ptr->va_fwdref);
26835c4bbdfSmrg        TestFree(ptr->va_comment);
26935c4bbdfSmrg        xf86freeVideoPortList(ptr->va_port_lst);
27035c4bbdfSmrg        xf86optionListFree(ptr->va_option_lst);
27135c4bbdfSmrg        prev = ptr;
27235c4bbdfSmrg        ptr = ptr->list.next;
27335c4bbdfSmrg        free(prev);
27435c4bbdfSmrg    }
27505b261ecSmrg}
27605b261ecSmrg
27705b261ecSmrgXF86ConfVideoAdaptorPtr
27835c4bbdfSmrgxf86findVideoAdaptor(const char *ident, XF86ConfVideoAdaptorPtr p)
27905b261ecSmrg{
28035c4bbdfSmrg    while (p) {
28135c4bbdfSmrg        if (xf86nameCompare(ident, p->va_identifier) == 0)
28235c4bbdfSmrg            return p;
28305b261ecSmrg
28435c4bbdfSmrg        p = p->list.next;
28535c4bbdfSmrg    }
28635c4bbdfSmrg    return NULL;
28705b261ecSmrg}
288