DRI.c revision 6747b715
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 "xf86Parser.h" 35#include "xf86tokens.h" 36#include "Configint.h" 37 38extern LexRec val; 39 40static xf86ConfigSymTabRec DRITab[] = 41{ 42 {ENDSECTION, "endsection"}, 43 {GROUP, "group"}, 44 {BUFFERS, "buffers"}, 45 {MODE, "mode"}, 46 {-1, ""}, 47}; 48 49#define CLEANUP xf86freeBuffersList 50 51static void 52xf86freeBuffersList (XF86ConfBuffersPtr ptr) 53{ 54 XF86ConfBuffersPtr prev; 55 56 while (ptr) { 57 TestFree (ptr->buf_flags); 58 TestFree (ptr->buf_comment); 59 prev = ptr; 60 ptr = ptr->list.next; 61 free (prev); 62 } 63} 64 65static XF86ConfBuffersPtr 66xf86parseBuffers (void) 67{ 68 int token; 69 parsePrologue (XF86ConfBuffersPtr, XF86ConfBuffersRec) 70 71 if (xf86getSubToken (&(ptr->buf_comment)) != NUMBER) 72 Error ("Buffers count expected", NULL); 73 ptr->buf_count = val.num; 74 75 if (xf86getSubToken (&(ptr->buf_comment)) != NUMBER) 76 Error ("Buffers size expected", NULL); 77 ptr->buf_size = val.num; 78 79 if ((token = xf86getSubToken (&(ptr->buf_comment))) == STRING) { 80 ptr->buf_flags = val.str; 81 if ((token = xf86getToken (NULL)) == COMMENT) 82 ptr->buf_comment = xf86addComment(ptr->buf_comment, val.str); 83 else 84 xf86unGetToken(token); 85 } 86 87#ifdef DEBUG 88 printf ("Buffers parsed\n"); 89#endif 90 91 return ptr; 92} 93 94#undef CLEANUP 95 96#define CLEANUP xf86freeDRI 97 98XF86ConfDRIPtr 99xf86parseDRISection (void) 100{ 101 int token; 102 parsePrologue (XF86ConfDRIPtr, XF86ConfDRIRec); 103 104 /* Zero is a valid value for this. */ 105 ptr->dri_group = -1; 106 while ((token = xf86getToken (DRITab)) != ENDSECTION) { 107 switch (token) 108 { 109 case GROUP: 110 if ((token = xf86getSubToken (&(ptr->dri_comment))) == STRING) 111 ptr->dri_group_name = val.str; 112 else if (token == NUMBER) 113 ptr->dri_group = val.num; 114 else 115 Error (GROUP_MSG, NULL); 116 break; 117 case MODE: 118 if (xf86getSubToken (&(ptr->dri_comment)) != NUMBER) 119 Error (NUMBER_MSG, "Mode"); 120 if (val.numType != PARSE_OCTAL) 121 Error (MUST_BE_OCTAL_MSG, val.num); 122 ptr->dri_mode = val.num; 123 break; 124 case BUFFERS: 125 HANDLE_LIST (dri_buffers_lst, xf86parseBuffers, 126 XF86ConfBuffersPtr); 127 break; 128 case EOF_TOKEN: 129 Error (UNEXPECTED_EOF_MSG, NULL); 130 break; 131 case COMMENT: 132 ptr->dri_comment = xf86addComment(ptr->dri_comment, val.str); 133 break; 134 default: 135 Error (INVALID_KEYWORD_MSG, xf86tokenString ()); 136 break; 137 } 138 } 139 140#ifdef DEBUG 141 ErrorF("DRI section parsed\n"); 142#endif 143 144 return ptr; 145} 146 147#undef CLEANUP 148 149void 150xf86printDRISection (FILE * cf, XF86ConfDRIPtr ptr) 151{ 152 XF86ConfBuffersPtr bufs; 153 154 if (ptr == NULL) 155 return; 156 157 fprintf (cf, "Section \"DRI\"\n"); 158 if (ptr->dri_comment) 159 fprintf (cf, "%s", ptr->dri_comment); 160 if (ptr->dri_group_name) 161 fprintf (cf, "\tGroup \"%s\"\n", ptr->dri_group_name); 162 else if (ptr->dri_group >= 0) 163 fprintf (cf, "\tGroup %d\n", ptr->dri_group); 164 if (ptr->dri_mode) 165 fprintf (cf, "\tMode 0%o\n", ptr->dri_mode); 166 for (bufs = ptr->dri_buffers_lst; bufs; bufs = bufs->list.next) { 167 fprintf (cf, "\tBuffers %d %d", 168 bufs->buf_count, bufs->buf_size); 169 if (bufs->buf_flags) fprintf (cf, " \"%s\"", bufs->buf_flags); 170 if (bufs->buf_comment) 171 fprintf(cf, "%s", bufs->buf_comment); 172 else 173 fprintf (cf, "\n"); 174 } 175 fprintf (cf, "EndSection\n\n"); 176} 177 178void 179xf86freeDRI (XF86ConfDRIPtr ptr) 180{ 181 if (ptr == NULL) 182 return; 183 184 xf86freeBuffersList (ptr->dri_buffers_lst); 185 TestFree (ptr->dri_comment); 186 free (ptr); 187} 188