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"
629ace9065Smrg#include "Xprintf.h"
6305b261ecSmrg
6405b261ecSmrg
651b5d61b8Smrgstatic const xf86ConfigSymTabRec PointerTab[] = {
6635c4bbdfSmrg    {PROTOCOL, "protocol"},
6735c4bbdfSmrg    {EMULATE3, "emulate3buttons"},
6835c4bbdfSmrg    {EM3TIMEOUT, "emulate3timeout"},
6935c4bbdfSmrg    {ENDSUBSECTION, "endsubsection"},
7035c4bbdfSmrg    {ENDSECTION, "endsection"},
7135c4bbdfSmrg    {PDEVICE, "device"},
7235c4bbdfSmrg    {PDEVICE, "port"},
7335c4bbdfSmrg    {BAUDRATE, "baudrate"},
7435c4bbdfSmrg    {SAMPLERATE, "samplerate"},
7535c4bbdfSmrg    {CLEARDTR, "cleardtr"},
7635c4bbdfSmrg    {CLEARRTS, "clearrts"},
7735c4bbdfSmrg    {CHORDMIDDLE, "chordmiddle"},
7835c4bbdfSmrg    {PRESOLUTION, "resolution"},
7935c4bbdfSmrg    {DEVICE_NAME, "devicename"},
8035c4bbdfSmrg    {ALWAYSCORE, "alwayscore"},
8135c4bbdfSmrg    {PBUTTONS, "buttons"},
8235c4bbdfSmrg    {ZAXISMAPPING, "zaxismapping"},
8335c4bbdfSmrg    {-1, ""},
8405b261ecSmrg};
8505b261ecSmrg
861b5d61b8Smrgstatic const xf86ConfigSymTabRec ZMapTab[] = {
8735c4bbdfSmrg    {XAXIS, "x"},
8835c4bbdfSmrg    {YAXIS, "y"},
8935c4bbdfSmrg    {-1, ""},
9005b261ecSmrg};
9105b261ecSmrg
9205b261ecSmrg#define CLEANUP xf86freeInputList
9305b261ecSmrg
9405b261ecSmrgXF86ConfInputPtr
9535c4bbdfSmrgxf86parsePointerSection(void)
9605b261ecSmrg{
9735c4bbdfSmrg    char *s;
9835c4bbdfSmrg    unsigned long val1;
9935c4bbdfSmrg    int token;
10035c4bbdfSmrg
10135c4bbdfSmrg    parsePrologue(XF86ConfInputPtr, XF86ConfInputRec)
10205b261ecSmrg
10335c4bbdfSmrg        while ((token = xf86getToken(PointerTab)) != ENDSECTION) {
10435c4bbdfSmrg        switch (token) {
10535c4bbdfSmrg        case COMMENT:
10635c4bbdfSmrg            ptr->inp_comment = xf86addComment(ptr->inp_comment, xf86_lex_val.str);
10758cf2af7Smrg            free(xf86_lex_val.str);
10858cf2af7Smrg            xf86_lex_val.str = NULL;
10935c4bbdfSmrg            break;
11035c4bbdfSmrg        case PROTOCOL:
11135c4bbdfSmrg            if (xf86getSubToken(&(ptr->inp_comment)) != STRING)
11235c4bbdfSmrg                Error(QUOTE_MSG, "Protocol");
11335c4bbdfSmrg            ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
11435c4bbdfSmrg                                                   strdup("Protocol"), xf86_lex_val.str);
11535c4bbdfSmrg            break;
11635c4bbdfSmrg        case PDEVICE:
11735c4bbdfSmrg            if (xf86getSubToken(&(ptr->inp_comment)) != STRING)
11835c4bbdfSmrg                Error(QUOTE_MSG, "Device");
11935c4bbdfSmrg            ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
12035c4bbdfSmrg                                                   strdup("Device"), xf86_lex_val.str);
12135c4bbdfSmrg            break;
12235c4bbdfSmrg        case EMULATE3:
12335c4bbdfSmrg            ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
12435c4bbdfSmrg                                                   strdup("Emulate3Buttons"),
12535c4bbdfSmrg                                                   NULL);
12635c4bbdfSmrg            break;
12735c4bbdfSmrg        case EM3TIMEOUT:
12835c4bbdfSmrg            if (xf86getSubToken(&(ptr->inp_comment)) != NUMBER || xf86_lex_val.num < 0)
12935c4bbdfSmrg                Error(POSITIVE_INT_MSG, "Emulate3Timeout");
13035c4bbdfSmrg            s = xf86uLongToString(xf86_lex_val.num);
13135c4bbdfSmrg            ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
13235c4bbdfSmrg                                                   strdup("Emulate3Timeout"),
13335c4bbdfSmrg                                                   s);
13435c4bbdfSmrg            break;
13535c4bbdfSmrg        case CHORDMIDDLE:
13635c4bbdfSmrg            ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
13735c4bbdfSmrg                                                   strdup("ChordMiddle"), NULL);
13835c4bbdfSmrg            break;
13935c4bbdfSmrg        case PBUTTONS:
14035c4bbdfSmrg            if (xf86getSubToken(&(ptr->inp_comment)) != NUMBER || xf86_lex_val.num < 0)
14135c4bbdfSmrg                Error(POSITIVE_INT_MSG, "Buttons");
14235c4bbdfSmrg            s = xf86uLongToString(xf86_lex_val.num);
14335c4bbdfSmrg            ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
14435c4bbdfSmrg                                                   strdup("Buttons"), s);
14535c4bbdfSmrg            break;
14635c4bbdfSmrg        case BAUDRATE:
14735c4bbdfSmrg            if (xf86getSubToken(&(ptr->inp_comment)) != NUMBER || xf86_lex_val.num < 0)
14835c4bbdfSmrg                Error(POSITIVE_INT_MSG, "BaudRate");
14935c4bbdfSmrg            s = xf86uLongToString(xf86_lex_val.num);
15035c4bbdfSmrg            ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
15135c4bbdfSmrg                                                   strdup("BaudRate"), s);
15235c4bbdfSmrg            break;
15335c4bbdfSmrg        case SAMPLERATE:
15435c4bbdfSmrg            if (xf86getSubToken(&(ptr->inp_comment)) != NUMBER || xf86_lex_val.num < 0)
15535c4bbdfSmrg                Error(POSITIVE_INT_MSG, "SampleRate");
15635c4bbdfSmrg            s = xf86uLongToString(xf86_lex_val.num);
15735c4bbdfSmrg            ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
15835c4bbdfSmrg                                                   strdup("SampleRate"), s);
15935c4bbdfSmrg            break;
16035c4bbdfSmrg        case PRESOLUTION:
16135c4bbdfSmrg            if (xf86getSubToken(&(ptr->inp_comment)) != NUMBER || xf86_lex_val.num < 0)
16235c4bbdfSmrg                Error(POSITIVE_INT_MSG, "Resolution");
16335c4bbdfSmrg            s = xf86uLongToString(xf86_lex_val.num);
16435c4bbdfSmrg            ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
16535c4bbdfSmrg                                                   strdup("Resolution"), s);
16635c4bbdfSmrg            break;
16735c4bbdfSmrg        case CLEARDTR:
16835c4bbdfSmrg            ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
16935c4bbdfSmrg                                                   strdup("ClearDTR"), NULL);
17035c4bbdfSmrg            break;
17135c4bbdfSmrg        case CLEARRTS:
17235c4bbdfSmrg            ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
17335c4bbdfSmrg                                                   strdup("ClearRTS"), NULL);
17435c4bbdfSmrg            break;
17535c4bbdfSmrg        case ZAXISMAPPING:
17635c4bbdfSmrg            switch (xf86getToken(ZMapTab)) {
17735c4bbdfSmrg            case NUMBER:
17835c4bbdfSmrg                if (xf86_lex_val.num < 0)
17935c4bbdfSmrg                    Error(ZAXISMAPPING_MSG);
18035c4bbdfSmrg                val1 = xf86_lex_val.num;
18135c4bbdfSmrg                if (xf86getSubToken(&(ptr->inp_comment)) != NUMBER ||
18235c4bbdfSmrg                    xf86_lex_val.num < 0) {
18335c4bbdfSmrg                    Error(ZAXISMAPPING_MSG);
18435c4bbdfSmrg                }
18535c4bbdfSmrg                if (asprintf(&s, "%lu %u", val1, xf86_lex_val.num) == -1)
18635c4bbdfSmrg                    s = NULL;
18735c4bbdfSmrg                break;
18835c4bbdfSmrg            case XAXIS:
18935c4bbdfSmrg                s = strdup("x");
19035c4bbdfSmrg                break;
19135c4bbdfSmrg            case YAXIS:
19235c4bbdfSmrg                s = strdup("y");
19335c4bbdfSmrg                break;
19435c4bbdfSmrg            default:
19535c4bbdfSmrg                Error(ZAXISMAPPING_MSG);
19635c4bbdfSmrg                break;
19735c4bbdfSmrg            }
19835c4bbdfSmrg            ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
19935c4bbdfSmrg                                                   strdup("ZAxisMapping"), s);
20035c4bbdfSmrg            break;
20135c4bbdfSmrg        case ALWAYSCORE:
20235c4bbdfSmrg            break;
20335c4bbdfSmrg        case EOF_TOKEN:
20435c4bbdfSmrg            Error(UNEXPECTED_EOF_MSG);
20535c4bbdfSmrg            break;
20635c4bbdfSmrg        default:
20735c4bbdfSmrg            Error(INVALID_KEYWORD_MSG, xf86tokenString());
20835c4bbdfSmrg            break;
20935c4bbdfSmrg        }
21035c4bbdfSmrg    }
21105b261ecSmrg
21235c4bbdfSmrg    ptr->inp_identifier = strdup(CONF_IMPLICIT_POINTER);
21335c4bbdfSmrg    ptr->inp_driver = strdup("mouse");
21435c4bbdfSmrg    ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
21535c4bbdfSmrg                                           strdup("CorePointer"), NULL);
21605b261ecSmrg
21705b261ecSmrg#ifdef DEBUG
21835c4bbdfSmrg    printf("Pointer section parsed\n");
21905b261ecSmrg#endif
22005b261ecSmrg
22135c4bbdfSmrg    return ptr;
22205b261ecSmrg}
22305b261ecSmrg
22405b261ecSmrg#undef CLEANUP
225