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 "os.h" 35#include "xf86Parser.h" 36#include "xf86tokens.h" 37#include "Configint.h" 38 39 40static const xf86ConfigSymTabRec DRITab[] = { 41 {ENDSECTION, "endsection"}, 42 {GROUP, "group"}, 43 {MODE, "mode"}, 44 {-1, ""}, 45}; 46 47#define CLEANUP xf86freeDRI 48 49XF86ConfDRIPtr 50xf86parseDRISection(void) 51{ 52 int token; 53 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 case GROUP: 61 if ((token = xf86getSubToken(&(ptr->dri_comment))) == STRING) 62 ptr->dri_group_name = xf86_lex_val.str; 63 else if (token == NUMBER) 64 ptr->dri_group = xf86_lex_val.num; 65 else 66 Error(GROUP_MSG); 67 break; 68 case MODE: 69 if (xf86getSubToken(&(ptr->dri_comment)) != NUMBER) 70 Error(NUMBER_MSG, "Mode"); 71 if (xf86_lex_val.numType != PARSE_OCTAL) 72 Error(MUST_BE_OCTAL_MSG, xf86_lex_val.num); 73 ptr->dri_mode = xf86_lex_val.num; 74 break; 75 case EOF_TOKEN: 76 Error(UNEXPECTED_EOF_MSG); 77 break; 78 case COMMENT: 79 ptr->dri_comment = xf86addComment(ptr->dri_comment, xf86_lex_val.str); 80 free(xf86_lex_val.str); 81 xf86_lex_val.str = NULL; 82 break; 83 default: 84 Error(INVALID_KEYWORD_MSG, xf86tokenString()); 85 break; 86 } 87 } 88 89#ifdef DEBUG 90 ErrorF("DRI section parsed\n"); 91#endif 92 93 return ptr; 94} 95 96#undef CLEANUP 97 98void 99xf86printDRISection(FILE * cf, XF86ConfDRIPtr ptr) 100{ 101 if (ptr == NULL) 102 return; 103 104 fprintf(cf, "Section \"DRI\"\n"); 105 if (ptr->dri_comment) 106 fprintf(cf, "%s", ptr->dri_comment); 107 if (ptr->dri_group_name) 108 fprintf(cf, "\tGroup \"%s\"\n", ptr->dri_group_name); 109 else if (ptr->dri_group >= 0) 110 fprintf(cf, "\tGroup %d\n", ptr->dri_group); 111 if (ptr->dri_mode) 112 fprintf(cf, "\tMode 0%o\n", ptr->dri_mode); 113 fprintf(cf, "EndSection\n\n"); 114} 115 116void 117xf86freeDRI(XF86ConfDRIPtr ptr) 118{ 119 if (ptr == NULL) 120 return; 121 122 TestFree(ptr->dri_comment); 123 free(ptr); 124} 125