Files.c revision 05b261ec
1/* 2 * Copyright (c) 1997 Metro Link Incorporated 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 * SOFTWARE. 21 * 22 * Except as contained in this notice, the name of the Metro Link shall not be 23 * used in advertising or otherwise to promote the sale, use or other dealings 24 * in this Software without prior written authorization from Metro Link. 25 * 26 */ 27/* 28 * Copyright (c) 1997-2003 by The XFree86 Project, Inc. 29 * 30 * Permission is hereby granted, free of charge, to any person obtaining a 31 * copy of this software and associated documentation files (the "Software"), 32 * to deal in the Software without restriction, including without limitation 33 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 34 * and/or sell copies of the Software, and to permit persons to whom the 35 * Software is furnished to do so, subject to the following conditions: 36 * 37 * The above copyright notice and this permission notice shall be included in 38 * all copies or substantial portions of the Software. 39 * 40 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 41 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 42 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 43 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 44 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 45 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 46 * OTHER DEALINGS IN THE SOFTWARE. 47 * 48 * Except as contained in this notice, the name of the copyright holder(s) 49 * and author(s) shall not be used in advertising or otherwise to promote 50 * the sale, use or other dealings in this Software without prior written 51 * authorization from the copyright holder(s) and author(s). 52 */ 53 54 55/* View/edit this file with tab stops set to 4 */ 56 57#ifdef HAVE_XORG_CONFIG_H 58#include <xorg-config.h> 59#endif 60 61#include <X11/Xos.h> 62#include "xf86Parser.h" 63#include "xf86tokens.h" 64#include "Configint.h" 65 66extern LexRec val; 67 68static xf86ConfigSymTabRec FilesTab[] = 69{ 70 {ENDSECTION, "endsection"}, 71 {FONTPATH, "fontpath"}, 72 {RGBPATH, "rgbpath"}, 73 {MODULEPATH, "modulepath"}, 74 {INPUTDEVICES, "inputdevices"}, 75 {LOGFILEPATH, "logfile"}, 76 {-1, ""}, 77}; 78 79#define CLEANUP xf86freeFiles 80 81XF86ConfFilesPtr 82xf86parseFilesSection (void) 83{ 84 int i, j; 85 int k, l; 86 char *str; 87 int token; 88 parsePrologue (XF86ConfFilesPtr, XF86ConfFilesRec) 89 90 while ((token = xf86getToken (FilesTab)) != ENDSECTION) 91 { 92 switch (token) 93 { 94 case COMMENT: 95 ptr->file_comment = xf86addComment(ptr->file_comment, val.str); 96 break; 97 case FONTPATH: 98 if (xf86getSubToken (&(ptr->file_comment)) != STRING) 99 Error (QUOTE_MSG, "FontPath"); 100 j = FALSE; 101 str = val.str; 102 if (ptr->file_fontpath == NULL) 103 { 104 ptr->file_fontpath = xf86confmalloc (1); 105 ptr->file_fontpath[0] = '\0'; 106 i = strlen (str) + 1; 107 } 108 else 109 { 110 i = strlen (ptr->file_fontpath) + strlen (str) + 1; 111 if (ptr->file_fontpath[strlen (ptr->file_fontpath) - 1] != ',') 112 { 113 i++; 114 j = TRUE; 115 } 116 } 117 ptr->file_fontpath = 118 xf86confrealloc (ptr->file_fontpath, i); 119 if (j) 120 strcat (ptr->file_fontpath, ","); 121 122 strcat (ptr->file_fontpath, str); 123 xf86conffree (val.str); 124 break; 125 case RGBPATH: 126 if (xf86getSubToken (&(ptr->file_comment)) != STRING) 127 Error (QUOTE_MSG, "RGBPath"); 128 ptr->file_rgbpath = val.str; 129 break; 130 case MODULEPATH: 131 if (xf86getSubToken (&(ptr->file_comment)) != STRING) 132 Error (QUOTE_MSG, "ModulePath"); 133 l = FALSE; 134 str = val.str; 135 if (ptr->file_modulepath == NULL) 136 { 137 ptr->file_modulepath = xf86confmalloc (1); 138 ptr->file_modulepath[0] = '\0'; 139 k = strlen (str) + 1; 140 } 141 else 142 { 143 k = strlen (ptr->file_modulepath) + strlen (str) + 1; 144 if (ptr->file_modulepath[strlen (ptr->file_modulepath) - 1] != ',') 145 { 146 k++; 147 l = TRUE; 148 } 149 } 150 ptr->file_modulepath = xf86confrealloc (ptr->file_modulepath, k); 151 if (l) 152 strcat (ptr->file_modulepath, ","); 153 154 strcat (ptr->file_modulepath, str); 155 xf86conffree (val.str); 156 break; 157 case INPUTDEVICES: 158 if (xf86getSubToken (&(ptr->file_comment)) != STRING) 159 Error (QUOTE_MSG, "InputDevices"); 160 l = FALSE; 161 str = val.str; 162 if (ptr->file_inputdevs == NULL) 163 { 164 ptr->file_inputdevs = xf86confmalloc (1); 165 ptr->file_inputdevs[0] = '\0'; 166 k = strlen (str) + 1; 167 } 168 else 169 { 170 k = strlen (ptr->file_inputdevs) + strlen (str) + 1; 171 if (ptr->file_inputdevs[strlen (ptr->file_inputdevs) - 1] != ',') 172 { 173 k++; 174 l = TRUE; 175 } 176 } 177 ptr->file_inputdevs = xf86confrealloc (ptr->file_inputdevs, k); 178 if (l) 179 strcat (ptr->file_inputdevs, ","); 180 181 strcat (ptr->file_inputdevs, str); 182 xf86conffree (val.str); 183 break; 184 case LOGFILEPATH: 185 if (xf86getSubToken (&(ptr->file_comment)) != STRING) 186 Error (QUOTE_MSG, "LogFile"); 187 ptr->file_logfile = val.str; 188 break; 189 case EOF_TOKEN: 190 Error (UNEXPECTED_EOF_MSG, NULL); 191 break; 192 default: 193 Error (INVALID_KEYWORD_MSG, xf86tokenString ()); 194 break; 195 } 196 } 197 198#ifdef DEBUG 199 printf ("File section parsed\n"); 200#endif 201 202 return ptr; 203} 204 205#undef CLEANUP 206 207void 208xf86printFileSection (FILE * cf, XF86ConfFilesPtr ptr) 209{ 210 char *p, *s; 211 212 if (ptr == NULL) 213 return; 214 215 if (ptr->file_comment) 216 fprintf (cf, "%s", ptr->file_comment); 217 if (ptr->file_logfile) 218 fprintf (cf, "\tLogFile \"%s\"\n", ptr->file_logfile); 219 if (ptr->file_rgbpath) 220 fprintf (cf, "\tRgbPath \"%s\"\n", ptr->file_rgbpath); 221 if (ptr->file_modulepath) 222 { 223 s = ptr->file_modulepath; 224 p = index (s, ','); 225 while (p) 226 { 227 *p = '\000'; 228 fprintf (cf, "\tModulePath \"%s\"\n", s); 229 *p = ','; 230 s = p; 231 s++; 232 p = index (s, ','); 233 } 234 fprintf (cf, "\tModulePath \"%s\"\n", s); 235 } 236 if (ptr->file_inputdevs) 237 { 238 s = ptr->file_inputdevs; 239 p = index (s, ','); 240 while (p) 241 { 242 *p = '\000'; 243 fprintf (cf, "\tInputDevices \"%s\"\n", s); 244 *p = ','; 245 s = p; 246 s++; 247 p = index (s, ','); 248 } 249 fprintf (cf, "\tInputDevices \"%s\"\n", s); 250 } 251 if (ptr->file_fontpath) 252 { 253 s = ptr->file_fontpath; 254 p = index (s, ','); 255 while (p) 256 { 257 *p = '\000'; 258 fprintf (cf, "\tFontPath \"%s\"\n", s); 259 *p = ','; 260 s = p; 261 s++; 262 p = index (s, ','); 263 } 264 fprintf (cf, "\tFontPath \"%s\"\n", s); 265 } 266} 267 268void 269xf86freeFiles (XF86ConfFilesPtr p) 270{ 271 if (p == NULL) 272 return; 273 274 TestFree (p->file_logfile); 275 TestFree (p->file_rgbpath); 276 TestFree (p->file_modulepath); 277 TestFree (p->file_inputdevs); 278 TestFree (p->file_fontpath); 279 TestFree (p->file_comment); 280 281 xf86conffree (p); 282} 283