1706f2543Smrg/* DRI.c -- DRI Section in XF86Config file 2706f2543Smrg * Created: Fri Mar 19 08:40:22 1999 by faith@precisioninsight.com 3706f2543Smrg * Revised: Thu Jun 17 16:08:05 1999 by faith@precisioninsight.com 4706f2543Smrg * 5706f2543Smrg * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. 6706f2543Smrg * All Rights Reserved. 7706f2543Smrg * 8706f2543Smrg * Permission is hereby granted, free of charge, to any person obtaining a 9706f2543Smrg * copy of this software and associated documentation files (the "Software"), 10706f2543Smrg * to deal in the Software without restriction, including without limitation 11706f2543Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 12706f2543Smrg * and/or sell copies of the Software, and to permit persons to whom the 13706f2543Smrg * Software is furnished to do so, subject to the following conditions: 14706f2543Smrg * 15706f2543Smrg * The above copyright notice and this permission notice (including the next 16706f2543Smrg * paragraph) shall be included in all copies or substantial portions of the 17706f2543Smrg * Software. 18706f2543Smrg * 19706f2543Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20706f2543Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21706f2543Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 22706f2543Smrg * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 23706f2543Smrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 24706f2543Smrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25706f2543Smrg * DEALINGS IN THE SOFTWARE. 26706f2543Smrg * 27706f2543Smrg * 28706f2543Smrg */ 29706f2543Smrg 30706f2543Smrg#ifdef HAVE_XORG_CONFIG_H 31706f2543Smrg#include <xorg-config.h> 32706f2543Smrg#endif 33706f2543Smrg 34706f2543Smrg#include "xf86Parser.h" 35706f2543Smrg#include "xf86tokens.h" 36706f2543Smrg#include "Configint.h" 37706f2543Smrg 38706f2543Smrgextern LexRec val; 39706f2543Smrg 40706f2543Smrgstatic xf86ConfigSymTabRec DRITab[] = 41706f2543Smrg{ 42706f2543Smrg {ENDSECTION, "endsection"}, 43706f2543Smrg {GROUP, "group"}, 44706f2543Smrg {MODE, "mode"}, 45706f2543Smrg {-1, ""}, 46706f2543Smrg}; 47706f2543Smrg 48706f2543Smrg#define CLEANUP xf86freeDRI 49706f2543Smrg 50706f2543SmrgXF86ConfDRIPtr 51706f2543Smrgxf86parseDRISection (void) 52706f2543Smrg{ 53706f2543Smrg int token; 54706f2543Smrg parsePrologue (XF86ConfDRIPtr, XF86ConfDRIRec); 55706f2543Smrg 56706f2543Smrg /* Zero is a valid value for this. */ 57706f2543Smrg ptr->dri_group = -1; 58706f2543Smrg while ((token = xf86getToken (DRITab)) != ENDSECTION) { 59706f2543Smrg switch (token) 60706f2543Smrg { 61706f2543Smrg case GROUP: 62706f2543Smrg if ((token = xf86getSubToken (&(ptr->dri_comment))) == STRING) 63706f2543Smrg ptr->dri_group_name = val.str; 64706f2543Smrg else if (token == NUMBER) 65706f2543Smrg ptr->dri_group = val.num; 66706f2543Smrg else 67706f2543Smrg Error (GROUP_MSG, NULL); 68706f2543Smrg break; 69706f2543Smrg case MODE: 70706f2543Smrg if (xf86getSubToken (&(ptr->dri_comment)) != NUMBER) 71706f2543Smrg Error (NUMBER_MSG, "Mode"); 72706f2543Smrg if (val.numType != PARSE_OCTAL) 73706f2543Smrg Error (MUST_BE_OCTAL_MSG, val.num); 74706f2543Smrg ptr->dri_mode = val.num; 75706f2543Smrg break; 76706f2543Smrg case EOF_TOKEN: 77706f2543Smrg Error (UNEXPECTED_EOF_MSG, NULL); 78706f2543Smrg break; 79706f2543Smrg case COMMENT: 80706f2543Smrg ptr->dri_comment = xf86addComment(ptr->dri_comment, val.str); 81706f2543Smrg break; 82706f2543Smrg default: 83706f2543Smrg Error (INVALID_KEYWORD_MSG, xf86tokenString ()); 84706f2543Smrg break; 85706f2543Smrg } 86706f2543Smrg } 87706f2543Smrg 88706f2543Smrg#ifdef DEBUG 89706f2543Smrg ErrorF("DRI section parsed\n"); 90706f2543Smrg#endif 91706f2543Smrg 92706f2543Smrg return ptr; 93706f2543Smrg} 94706f2543Smrg 95706f2543Smrg#undef CLEANUP 96706f2543Smrg 97706f2543Smrgvoid 98706f2543Smrgxf86printDRISection (FILE * cf, XF86ConfDRIPtr ptr) 99706f2543Smrg{ 100706f2543Smrg if (ptr == NULL) 101706f2543Smrg return; 102706f2543Smrg 103706f2543Smrg fprintf (cf, "Section \"DRI\"\n"); 104706f2543Smrg if (ptr->dri_comment) 105706f2543Smrg fprintf (cf, "%s", ptr->dri_comment); 106706f2543Smrg if (ptr->dri_group_name) 107706f2543Smrg fprintf (cf, "\tGroup \"%s\"\n", ptr->dri_group_name); 108706f2543Smrg else if (ptr->dri_group >= 0) 109706f2543Smrg fprintf (cf, "\tGroup %d\n", ptr->dri_group); 110706f2543Smrg if (ptr->dri_mode) 111706f2543Smrg fprintf (cf, "\tMode 0%o\n", ptr->dri_mode); 112706f2543Smrg fprintf (cf, "EndSection\n\n"); 113706f2543Smrg} 114706f2543Smrg 115706f2543Smrgvoid 116706f2543Smrgxf86freeDRI (XF86ConfDRIPtr ptr) 117706f2543Smrg{ 118706f2543Smrg if (ptr == NULL) 119706f2543Smrg return; 120706f2543Smrg 121706f2543Smrg TestFree (ptr->dri_comment); 122706f2543Smrg free (ptr); 123706f2543Smrg} 124