diff options
author | Aaron Plattner <aplattner@nvidia.com> | 2008-11-14 16:45:37 -0800 |
---|---|---|
committer | Aaron Plattner <aplattner@nvidia.com> | 2008-11-14 16:45:37 -0800 |
commit | e2d617a3db5214a2e3211127496dd8d23fd1c840 (patch) | |
tree | be6d678c62a71ffc70c12397f03446cd46a56d12 | |
parent | eb216a0ff85db22c1ac7d8f92b33aecab03a583a (diff) |
-rw-r--r-- | XF86Config-parser/Configint.h | 21 | ||||
-rw-r--r-- | XF86Config-parser/DRI.c | 50 | ||||
-rw-r--r-- | XF86Config-parser/Device.c | 33 | ||||
-rw-r--r-- | XF86Config-parser/Extensions.c | 11 | ||||
-rw-r--r-- | XF86Config-parser/Files.c | 19 | ||||
-rw-r--r-- | XF86Config-parser/Flags.c | 98 | ||||
-rw-r--r-- | XF86Config-parser/Generate.c | 95 | ||||
-rw-r--r-- | XF86Config-parser/Input.c | 32 | ||||
-rw-r--r-- | XF86Config-parser/Keyboard.c | 67 | ||||
-rw-r--r-- | XF86Config-parser/Layout.c | 82 | ||||
-rw-r--r-- | XF86Config-parser/Merge.c | 52 | ||||
-rw-r--r-- | XF86Config-parser/Module.c | 65 | ||||
-rw-r--r-- | XF86Config-parser/Monitor.c | 80 | ||||
-rw-r--r-- | XF86Config-parser/Pointer.c | 37 | ||||
-rw-r--r-- | XF86Config-parser/Read.c | 109 | ||||
-rw-r--r-- | XF86Config-parser/Screen.c | 119 | ||||
-rw-r--r-- | XF86Config-parser/Vendor.c | 35 | ||||
-rw-r--r-- | XF86Config-parser/Video.c | 46 | ||||
-rw-r--r-- | XF86Config-parser/xf86Parser.h | 84 | ||||
-rw-r--r-- | make_usable.c | 50 | ||||
-rw-r--r-- | multiple_screens.c | 42 | ||||
-rw-r--r-- | nvidia-cfg.h | 12 | ||||
-rw-r--r-- | nvidia-xconfig.c | 4 | ||||
-rw-r--r-- | nvidia-xconfig.h | 7 | ||||
-rw-r--r-- | option_table.h | 16 | ||||
-rw-r--r-- | options.c | 38 |
26 files changed, 630 insertions, 674 deletions
diff --git a/XF86Config-parser/Configint.h b/XF86Config-parser/Configint.h index f91c6ee..b626bb2 100644 --- a/XF86Config-parser/Configint.h +++ b/XF86Config-parser/Configint.h @@ -97,24 +97,23 @@ LexRec, *LexPtr; #define HANDLE_LIST(field,func,type) \ { \ type p = func(); \ - if (p == NULL) \ - { \ - CLEANUP (ptr); \ + if (p == NULL) { \ + CLEANUP (&ptr); \ return (NULL); \ } else { \ - ptr->field = (type) \ - xconfigAddListItem((GenericListPtr) ptr->field, \ - (GenericListPtr) p); \ + xconfigAddListItem((GenericListPtr*)(&ptr->field), \ + (GenericListPtr) p); \ } \ } -#define Error(a,b) \ - do { \ +#define Error(a,b) \ + do { \ xconfigErrorMsg(ParseErrorMsg, a, b); \ - CLEANUP (ptr); \ - return NULL; \ - } while (0) \ + CLEANUP (&ptr); \ + return NULL; \ + } while (0) + /* * These are defines for error messages to promote consistency. diff --git a/XF86Config-parser/DRI.c b/XF86Config-parser/DRI.c index 9936830..b032ced 100644 --- a/XF86Config-parser/DRI.c +++ b/XF86Config-parser/DRI.c @@ -47,22 +47,24 @@ XConfigBuffersPtr xconfigParseBuffers (void) { int token; - PARSE_PROLOGUE (XConfigBuffersPtr, XConfigBuffersRec) + PARSE_PROLOGUE (XConfigBuffersPtr, XConfigBuffersRec); - if (xconfigGetSubToken (&(ptr->comment)) != NUMBER) - Error("Buffers count expected", NULL); + if (xconfigGetSubToken (&(ptr->comment)) != NUMBER) { + Error("Buffers count expected", NULL); + } ptr->count = val.num; - if (xconfigGetSubToken (&(ptr->comment)) != NUMBER) - Error("Buffers size expected", NULL); + if (xconfigGetSubToken (&(ptr->comment)) != NUMBER) { + Error("Buffers size expected", NULL); + } ptr->size = val.num; if ((token = xconfigGetSubToken (&(ptr->comment))) == STRING) { - ptr->flags = val.str; - if ((token = xconfigGetToken (NULL)) == COMMENT) - ptr->comment = xconfigAddComment(ptr->comment, val.str); - else - xconfigUnGetToken(token); + ptr->flags = val.str; + if ((token = xconfigGetToken (NULL)) == COMMENT) + ptr->comment = xconfigAddComment(ptr->comment, val.str); + else + xconfigUnGetToken(token); } return ptr; @@ -126,26 +128,30 @@ xconfigPrintDRISection (FILE * cf, XConfigDRIPtr ptr) } void -xconfigFreeDRI (XConfigDRIPtr ptr) +xconfigFreeDRI (XConfigDRIPtr *ptr) { - if (ptr == NULL) - return; + if (ptr == NULL || *ptr == NULL) + return; - xconfigFreeBuffersList (ptr->buffers); - TEST_FREE (ptr->comment); - free (ptr); + xconfigFreeBuffersList (&((*ptr)->buffers)); + TEST_FREE ((*ptr)->comment); + free (*ptr); + *ptr = NULL; } void -xconfigFreeBuffersList (XConfigBuffersPtr ptr) +xconfigFreeBuffersList (XConfigBuffersPtr *ptr) { XConfigBuffersPtr prev; - while (ptr) { - TEST_FREE (ptr->flags); - TEST_FREE (ptr->comment); - prev = ptr; - ptr = ptr->next; + if (ptr == NULL || *ptr == NULL) + return; + + while (*ptr) { + TEST_FREE ((*ptr)->flags); + TEST_FREE ((*ptr)->comment); + prev = *ptr; + *ptr = (*ptr)->next; free (prev); } } diff --git a/XF86Config-parser/Device.c b/XF86Config-parser/Device.c index a4c3f62..a374fa4 100644 --- a/XF86Config-parser/Device.c +++ b/XF86Config-parser/Device.c @@ -329,25 +329,28 @@ xconfigPrintDeviceSection (FILE * cf, XConfigDevicePtr ptr) } void -xconfigFreeDeviceList (XConfigDevicePtr ptr) +xconfigFreeDeviceList (XConfigDevicePtr *ptr) { XConfigDevicePtr prev; - while (ptr) + if (ptr == NULL || *ptr == NULL) + return; + + while (*ptr) { - TEST_FREE (ptr->identifier); - TEST_FREE (ptr->vendor); - TEST_FREE (ptr->board); - TEST_FREE (ptr->chipset); - TEST_FREE (ptr->card); - TEST_FREE (ptr->driver); - TEST_FREE (ptr->ramdac); - TEST_FREE (ptr->clockchip); - TEST_FREE (ptr->comment); - xconfigOptionListFree (ptr->options); - - prev = ptr; - ptr = ptr->next; + TEST_FREE ((*ptr)->identifier); + TEST_FREE ((*ptr)->vendor); + TEST_FREE ((*ptr)->board); + TEST_FREE ((*ptr)->chipset); + TEST_FREE ((*ptr)->card); + TEST_FREE ((*ptr)->driver); + TEST_FREE ((*ptr)->ramdac); + TEST_FREE ((*ptr)->clockchip); + TEST_FREE ((*ptr)->comment); + xconfigFreeOptionList (&((*ptr)->options)); + + prev = *ptr; + *ptr = (*ptr)->next; free (prev); } } diff --git a/XF86Config-parser/Extensions.c b/XF86Config-parser/Extensions.c index 7482a6d..415ae17 100644 --- a/XF86Config-parser/Extensions.c +++ b/XF86Config-parser/Extensions.c @@ -91,12 +91,13 @@ xconfigPrintExtensionsSection (FILE * cf, XConfigExtensionsPtr ptr) } void -xconfigFreeExtensions (XConfigExtensionsPtr ptr) +xconfigFreeExtensions (XConfigExtensionsPtr *ptr) { - if (ptr == NULL) + if (ptr == NULL || *ptr == NULL) return; - xconfigOptionListFree (ptr->options); - TEST_FREE (ptr->comment); - free (ptr); + xconfigFreeOptionList (&((*ptr)->options)); + TEST_FREE ((*ptr)->comment); + free (*ptr); + *ptr = NULL; } diff --git a/XF86Config-parser/Files.c b/XF86Config-parser/Files.c index 6493cd1..dac9335 100644 --- a/XF86Config-parser/Files.c +++ b/XF86Config-parser/Files.c @@ -265,17 +265,18 @@ xconfigPrintFileSection (FILE * cf, XConfigFilesPtr ptr) } void -xconfigFreeFiles (XConfigFilesPtr p) +xconfigFreeFiles (XConfigFilesPtr *p) { - if (p == NULL) + if (p == NULL || *p == NULL) return; - TEST_FREE (p->logfile); - TEST_FREE (p->rgbpath); - TEST_FREE (p->modulepath); - TEST_FREE (p->inputdevs); - TEST_FREE (p->fontpath); - TEST_FREE (p->comment); + TEST_FREE ((*p)->logfile); + TEST_FREE ((*p)->rgbpath); + TEST_FREE ((*p)->modulepath); + TEST_FREE ((*p)->inputdevs); + TEST_FREE ((*p)->fontpath); + TEST_FREE ((*p)->comment); - free (p); + free (*p); + *p = NULL; } diff --git a/XF86Config-parser/Flags.c b/XF86Config-parser/Flags.c index b86b7a4..6eadae2 100644 --- a/XF86Config-parser/Flags.c +++ b/XF86Config-parser/Flags.c @@ -141,8 +141,8 @@ xconfigParseFlagsSection (void) valstr = buff; } } - ptr->options = xconfigAddNewOption - (ptr->options, ServerFlagsTab[i].name, valstr); + xconfigAddNewOption(&ptr->options, + ServerFlagsTab[i].name, valstr); } i++; } @@ -181,13 +181,16 @@ xconfigPrintServerFlagsSection (FILE * f, XConfigFlagsPtr flags) fprintf (f, "EndSection\n\n"); } -XConfigOptionPtr -xconfigAddNewOption (XConfigOptionPtr head, const char *name, const char *val) +void +xconfigAddNewOption (XConfigOptionPtr *pHead, const char *name, + const char *val) { - XConfigOptionPtr new, old = NULL; + XConfigOptionPtr new; + XConfigOptionPtr old = NULL; /* Don't allow duplicates */ - if (head != NULL && (old = xconfigFindOption(head, name)) != NULL) { + if (*pHead != NULL && + ((old = xconfigFindOption(*pHead, name)) != NULL)) { TEST_FREE(old->name); TEST_FREE(old->val); new = old; @@ -198,21 +201,21 @@ xconfigAddNewOption (XConfigOptionPtr head, const char *name, const char *val) new->name = xconfigStrdup(name); new->val = xconfigStrdup(val); - if (old == NULL) - return ((XConfigOptionPtr) xconfigAddListItem ((GenericListPtr) head, - (GenericListPtr) new)); - else - return head; + if (old == NULL) { + xconfigAddListItem((GenericListPtr *)(pHead), (GenericListPtr)new); + } } void -xconfigFreeFlags (XConfigFlagsPtr flags) +xconfigFreeFlags (XConfigFlagsPtr *flags) { - if (flags == NULL) + if (flags == NULL || *flags == NULL) return; - xconfigOptionListFree (flags->options); - TEST_FREE(flags->comment); - free (flags); + + xconfigFreeOptionList (&((*flags)->options)); + TEST_FREE((*flags)->comment); + free (*flags); + *flags = NULL; } XConfigOptionPtr @@ -220,27 +223,31 @@ xconfigOptionListDup (XConfigOptionPtr opt) { XConfigOptionPtr newopt = NULL; - while (opt) - { - newopt = xconfigAddNewOption(newopt, opt->name, opt->val); - newopt->comment = xconfigStrdup(opt->comment); + while (opt) { + xconfigAddNewOption(&newopt, opt->name, opt->val); + if (newopt) { + newopt->comment = xconfigStrdup(opt->comment); + } opt = opt->next; } return newopt; } void -xconfigOptionListFree (XConfigOptionPtr opt) +xconfigFreeOptionList (XConfigOptionPtr *opt) { XConfigOptionPtr prev; - while (opt) + if (opt == NULL || *opt == NULL) + return; + + while (*opt) { - TEST_FREE (opt->name); - TEST_FREE (opt->val); - TEST_FREE (opt->comment); - prev = opt; - opt = opt->next; + TEST_FREE ((*opt)->name); + TEST_FREE ((*opt)->val); + TEST_FREE ((*opt)->comment); + prev = *opt; + *opt = (*opt)->next; free (prev); } } @@ -277,28 +284,15 @@ xconfigNewOption(const char *name, const char *value) return opt; } -XConfigOptionPtr -xconfigRemoveOption(XConfigOptionPtr list, XConfigOptionPtr opt) +void +xconfigRemoveOption(XConfigOptionPtr *pHead, XConfigOptionPtr opt) { - XConfigOptionPtr prev = NULL; - XConfigOptionPtr p = list; - - while (p) { - if (p == opt) { - if (prev) prev->next = opt->next; - if (list == opt) list = opt->next; - - TEST_FREE(opt->name); - TEST_FREE(opt->val); - TEST_FREE(opt->comment); - free(opt); - break; - } - prev = p; - p = p->next; - } + xconfigRemoveListItem((GenericListPtr *)pHead, (GenericListPtr)opt); - return list; + TEST_FREE(opt->name); + TEST_FREE(opt->val); + TEST_FREE(opt->comment); + free(opt); } XConfigOptionPtr @@ -397,7 +391,7 @@ xconfigOptionListMerge (XConfigOptionPtr head, XConfigOptionPtr tail) ap->next = a->next; a->next = b->next; b->next = NULL; - xconfigOptionListFree (b); + xconfigFreeOptionList (&b); b = a->next; bp = a; a = tail; @@ -482,11 +476,11 @@ xconfigParseOption(XConfigOptionPtr head) else cnew = option; - if (old == NULL) - return ((XConfigOptionPtr)xconfigAddListItem((GenericListPtr)head, - (GenericListPtr)cnew)); + if (old == NULL) { + xconfigAddListItem((GenericListPtr *)(&head), (GenericListPtr)cnew); + } - return (head); + return head; } void diff --git a/XF86Config-parser/Generate.c b/XF86Config-parser/Generate.c index 22ce212..a45602e 100644 --- a/XF86Config-parser/Generate.c +++ b/XF86Config-parser/Generate.c @@ -122,8 +122,7 @@ XConfigScreenPtr xconfigGenerateAddScreen(XConfigPtr config, screen->defaultdepth = 24; - screen->displays = xconfigAddDisplay(screen->displays, - screen->defaultdepth); + xconfigAddDisplay(&screen->displays, screen->defaultdepth); /* append to the end of the screen list */ @@ -377,25 +376,25 @@ static void add_modules(GenerateOptions *gop, XConfigPtr config) config->modules = xconfigAlloc(sizeof(XConfigModuleRec)); - l = xconfigAddNewLoadDirective(l, xconfigStrdup("dbe"), - XCONFIG_LOAD_MODULE, NULL, FALSE); - l = xconfigAddNewLoadDirective(l, xconfigStrdup("extmod"), - XCONFIG_LOAD_MODULE, NULL, FALSE); - l = xconfigAddNewLoadDirective(l, xconfigStrdup("type1"), - XCONFIG_LOAD_MODULE, NULL, FALSE); + xconfigAddNewLoadDirective(&l, xconfigStrdup("dbe"), + XCONFIG_LOAD_MODULE, NULL, FALSE); + xconfigAddNewLoadDirective(&l, xconfigStrdup("extmod"), + XCONFIG_LOAD_MODULE, NULL, FALSE); + xconfigAddNewLoadDirective(&l, xconfigStrdup("type1"), + XCONFIG_LOAD_MODULE, NULL, FALSE); #if defined(NV_SUNOS) - l = xconfigAddNewLoadDirective(l, xconfigStrdup("IA"), - XCONFIG_LOAD_MODULE, NULL, FALSE); - l = xconfigAddNewLoadDirective(l, xconfigStrdup("bitstream"), - XCONFIG_LOAD_MODULE, NULL, FALSE); - l = xconfigAddNewLoadDirective(l, xconfigStrdup("xtsol"), - XCONFIG_LOAD_MODULE, NULL, FALSE); + xconfigAddNewLoadDirective(&l, xconfigStrdup("IA"), + XCONFIG_LOAD_MODULE, NULL, FALSE); + xconfigAddNewLoadDirective(&l, xconfigStrdup("bitstream"), + XCONFIG_LOAD_MODULE, NULL, FALSE); + xconfigAddNewLoadDirective(&l, xconfigStrdup("xtsol"), + XCONFIG_LOAD_MODULE, NULL, FALSE); #else - l = xconfigAddNewLoadDirective(l, xconfigStrdup("freetype"), - XCONFIG_LOAD_MODULE, NULL, FALSE); + xconfigAddNewLoadDirective(&l, xconfigStrdup("freetype"), + XCONFIG_LOAD_MODULE, NULL, FALSE); #endif - l = xconfigAddNewLoadDirective(l, xconfigStrdup("glx"), - XCONFIG_LOAD_MODULE, NULL, FALSE); + xconfigAddNewLoadDirective(&l, xconfigStrdup("glx"), + XCONFIG_LOAD_MODULE, NULL, FALSE); config->modules->loads = l; @@ -412,7 +411,6 @@ static void add_modules(GenerateOptions *gop, XConfigPtr config) XConfigMonitorPtr xconfigAddMonitor(XConfigPtr config, int count) { XConfigMonitorPtr monitor, m; - XConfigOptionPtr opt = NULL; /* XXX need to query resman for the EDID */ @@ -426,16 +424,15 @@ XConfigMonitorPtr xconfigAddMonitor(XConfigPtr config, int count) /* XXX check EDID for freq ranges */ monitor->n_hsync = 1; - monitor->hsync[0].lo = 30.0; - monitor->hsync[0].hi = 110.0; + monitor->hsync[0].lo = 28.0; + monitor->hsync[0].hi = 33.0; monitor->n_vrefresh = 1; - monitor->vrefresh[0].lo = 50.0; - monitor->vrefresh[0].hi = 150.0; + monitor->vrefresh[0].lo = 43.0; + monitor->vrefresh[0].hi = 72.0; - opt = xconfigAddNewOption(opt, "DPMS", NULL); - - monitor->options = opt; + monitor->options = NULL; + xconfigAddNewOption(&monitor->options, "DPMS", NULL); /* append to the end of the monitor list */ @@ -495,7 +492,7 @@ add_device(XConfigPtr config, int bus, int slot, char *boardname, int count) -XConfigDisplayPtr xconfigAddDisplay(XConfigDisplayPtr head, const int depth) +void xconfigAddDisplay(XConfigDisplayPtr *pHead, const int depth) { XConfigDisplayPtr display; @@ -507,9 +504,8 @@ XConfigDisplayPtr xconfigAddDisplay(XConfigDisplayPtr head, const int depth) display->black.red = -1; display->white.red = -1; - display->next = head; - - return display; + display->next = *pHead; + *pHead = display; } @@ -566,8 +562,8 @@ static void add_inputref(XConfigPtr config, XConfigLayoutPtr layout, inputRef = xconfigAlloc(sizeof(XConfigInputrefRec)); inputRef->input_name = xconfigStrdup(name); inputRef->input = xconfigFindInput(inputRef->input_name, config->inputs); - inputRef->options = - xconfigAddNewOption(NULL, coreKeyword, NULL); + inputRef->options = NULL; + xconfigAddNewOption(&inputRef->options, coreKeyword, NULL); inputRef->next = layout->inputs; layout->inputs = inputRef; @@ -918,7 +914,6 @@ int xconfigAddMouse(GenerateOptions *gop, XConfigPtr config) { const MouseEntry *entry = NULL; XConfigInputPtr input; - XConfigOptionPtr opt = NULL; char *device_path, *comment = "default"; /* if the user specified on the commandline, use that */ @@ -1015,9 +1010,10 @@ int xconfigAddMouse(GenerateOptions *gop, XConfigPtr config) device_path = xconfigStrcat("/dev/", entry->device, NULL); - opt = xconfigAddNewOption(opt, "Protocol", entry->Xproto); - opt = xconfigAddNewOption(opt, "Device", device_path); - opt = xconfigAddNewOption(opt, "Emulate3Buttons", + input->options = NULL; + xconfigAddNewOption(&input->options, "Protocol", entry->Xproto); + xconfigAddNewOption(&input->options, "Device", device_path); + xconfigAddNewOption(&input->options, "Emulate3Buttons", (entry->emulate3 ? "yes" : "no")); TEST_FREE(device_path); @@ -1027,9 +1023,7 @@ int xconfigAddMouse(GenerateOptions *gop, XConfigPtr config) * ignore ZAxisMapping */ - opt = xconfigAddNewOption(opt, "ZAxisMapping", "4 5"); - - input->options = opt; + xconfigAddNewOption(&input->options, "ZAxisMapping", "4 5"); input->next = config->inputs; config->inputs = input; @@ -1213,7 +1207,6 @@ int xconfigAddKeyboard(GenerateOptions *gop, XConfigPtr config) const KeyboardEntry *entry = NULL; XConfigInputPtr input; - XConfigOptionPtr opt = NULL; /* * if the user specified on the command line, use that @@ -1280,16 +1273,18 @@ int xconfigAddKeyboard(GenerateOptions *gop, XConfigPtr config) * entry we found above */ - if (entry && entry->layout) - opt = xconfigAddNewOption(opt, "XkbLayout", entry->layout); - if (entry && entry->model) - opt = xconfigAddNewOption(opt, "XkbModel", entry->model); - if (entry && entry->variant) - opt = xconfigAddNewOption(opt, "XkbVariant", entry->variant); - if (entry && entry->options) - opt = xconfigAddNewOption(opt, "XkbOptions", entry->options); - - input->options = opt; + input->options = NULL; + + if (entry) { + if (entry->layout) + xconfigAddNewOption(&input->options, "XkbLayout", entry->layout); + if (entry->model) + xconfigAddNewOption(&input->options, "XkbModel", entry->model); + if (entry->variant) + xconfigAddNewOption(&input->options, "XkbVariant", entry->variant); + if (entry->options) + xconfigAddNewOption(&input->options, "XkbOptions", entry->options); + } input->next = config->inputs; config->inputs = input; diff --git a/XF86Config-parser/Input.c b/XF86Config-parser/Input.c index 4b660f6..e016b4f 100644 --- a/XF86Config-parser/Input.c +++ b/XF86Config-parser/Input.c @@ -139,19 +139,22 @@ xconfigPrintInputSection (FILE * cf, XConfigInputPtr ptr) } void -xconfigFreeInputList (XConfigInputPtr ptr) +xconfigFreeInputList (XConfigInputPtr *ptr) { XConfigInputPtr prev; - while (ptr) + if (ptr == NULL || *ptr == NULL) + return; + + while (*ptr) { - TEST_FREE (ptr->identifier); - TEST_FREE (ptr->driver); - TEST_FREE (ptr->comment); - xconfigOptionListFree (ptr->options); + TEST_FREE ((*ptr)->identifier); + TEST_FREE ((*ptr)->driver); + TEST_FREE ((*ptr)->comment); + xconfigFreeOptionList (&((*ptr)->options)); - prev = ptr; - ptr = ptr->next; + prev = *ptr; + *ptr = (*ptr)->next; free (prev); } } @@ -242,10 +245,12 @@ static int getCoreInputDevice(GenerateOptions *gop, if (!core) { core = input; } else { - if (opt1) input->options = - xconfigRemoveOption(input->options, opt1); - if (opt2) inputRef->options = - xconfigRemoveOption(inputRef->options, opt2); + if (opt1) { + xconfigRemoveOption(&input->options, opt1); + } + if (opt2) { + xconfigRemoveOption(&inputRef->options, opt2); + } xconfigErrorMsg(WarnMsg, "Duplicate %s devices; removing %s " "attribute from \"%s\"\n", coreKeyword, coreKeyword, input->identifier); @@ -367,8 +372,7 @@ static int getCoreInputDevice(GenerateOptions *gop, opt2 = xconfigFindOption(inputRef->options, coreKeyword); if (!opt1 && !opt2) { - inputRef->options = xconfigAddNewOption(inputRef->options, - coreKeyword, NULL); + xconfigAddNewOption(&inputRef->options, coreKeyword, NULL); } break; } diff --git a/XF86Config-parser/Keyboard.c b/XF86Config-parser/Keyboard.c index 26bbb73..f282eb6 100644 --- a/XF86Config-parser/Keyboard.c +++ b/XF86Config-parser/Keyboard.c @@ -126,9 +126,7 @@ xconfigParseKeyboardSection (void) case KPROTOCOL: if (xconfigGetSubToken (&(ptr->comment)) != STRING) Error (QUOTE_MSG, "Protocol"); - ptr->options = xconfigAddNewOption(ptr->options, - xconfigStrdup("Protocol"), - val.str); + xconfigAddNewOption(&ptr->options, "Protocol", val.str); break; case AUTOREPEAT: if (xconfigGetSubToken (&(ptr->comment)) != NUMBER) @@ -142,9 +140,7 @@ xconfigParseKeyboardSection (void) sprintf(s, "%s %s", s1, s2); free(s1); free(s2); - ptr->options = - xconfigAddNewOption(ptr->options, - xconfigStrdup("AutoRepeat"), s); + xconfigAddNewOption(&ptr->options, "AutoRepeat", s); break; case XLEDS: if (xconfigGetSubToken (&(ptr->comment)) != NUMBER) @@ -178,7 +174,7 @@ xconfigParseKeyboardSection (void) { case EOF_TOKEN: xconfigErrorMsg(ParseErrorMsg, UNEXPECTED_EOF_MSG); - CLEANUP (ptr); + CLEANUP (&ptr); return (NULL); break; @@ -197,93 +193,65 @@ xconfigParseKeyboardSection (void) MOVED_TO_FLAGS_MSG, "VTSysReq"); break; case XKBDISABLE: - ptr->options = xconfigAddNewOption(ptr->options, - xconfigStrdup("XkbDisable"), - NULL); + xconfigAddNewOption(&ptr->options, "XkbDisable", NULL); break; case XKBKEYMAP: if (xconfigGetSubToken (&(ptr->comment)) != STRING) Error (QUOTE_MSG, "XKBKeymap"); - ptr->options = xconfigAddNewOption(ptr->options, - xconfigStrdup("XkbKeymap"), - val.str); + xconfigAddNewOption(&ptr->options, "XkbKeymap", val.str); break; case XKBCOMPAT: if (xconfigGetSubToken (&(ptr->comment)) != STRING) Error (QUOTE_MSG, "XKBCompat"); - ptr->options = xconfigAddNewOption(ptr->options, - xconfigStrdup("XkbCompat"), - val.str); + xconfigAddNewOption(&ptr->options, "XkbCompat", val.str); break; case XKBTYPES: if (xconfigGetSubToken (&(ptr->comment)) != STRING) Error (QUOTE_MSG, "XKBTypes"); - ptr->options = xconfigAddNewOption(ptr->options, - xconfigStrdup("XkbTypes"), - val.str); + xconfigAddNewOption(&ptr->options, "XkbTypes", val.str); break; case XKBKEYCODES: if (xconfigGetSubToken (&(ptr->comment)) != STRING) Error (QUOTE_MSG, "XKBKeycodes"); - ptr->options = - xconfigAddNewOption(ptr->options, - xconfigStrdup("XkbKeycodes"), - val.str); + xconfigAddNewOption(&ptr->options, "XkbKeycodes", val.str); break; case XKBGEOMETRY: if (xconfigGetSubToken (&(ptr->comment)) != STRING) Error (QUOTE_MSG, "XKBGeometry"); - ptr->options = - xconfigAddNewOption(ptr->options, - xconfigStrdup("XkbGeometry"), - val.str); + xconfigAddNewOption(&ptr->options, "XkbGeometry", val.str); break; case XKBSYMBOLS: if (xconfigGetSubToken (&(ptr->comment)) != STRING) Error (QUOTE_MSG, "XKBSymbols"); - ptr->options = xconfigAddNewOption(ptr->options, - xconfigStrdup("XkbSymbols"), - val.str); + xconfigAddNewOption(&ptr->options, "XkbSymbols", val.str); break; case XKBRULES: if (xconfigGetSubToken (&(ptr->comment)) != STRING) Error (QUOTE_MSG, "XKBRules"); - ptr->options = xconfigAddNewOption(ptr->options, - xconfigStrdup("XkbRules"), - val.str); + xconfigAddNewOption(&ptr->options, "XkbRules", val.str); break; case XKBMODEL: if (xconfigGetSubToken (&(ptr->comment)) != STRING) Error (QUOTE_MSG, "XKBModel"); - ptr->options = xconfigAddNewOption(ptr->options, - xconfigStrdup("XkbModel"), - val.str); + xconfigAddNewOption(&ptr->options, "XkbModel", val.str); break; case XKBLAYOUT: if (xconfigGetSubToken (&(ptr->comment)) != STRING) Error (QUOTE_MSG, "XKBLayout"); - ptr->options = xconfigAddNewOption(ptr->options, - xconfigStrdup("XkbLayout"), - val.str); + xconfigAddNewOption(&ptr->options, "XkbLayout", val.str); break; case XKBVARIANT: if (xconfigGetSubToken (&(ptr->comment)) != STRING) Error (QUOTE_MSG, "XKBVariant"); - ptr->options = xconfigAddNewOption(ptr->options, - xconfigStrdup("XkbVariant"), - val.str); + xconfigAddNewOption(&ptr->options, "XkbVariant", val.str); break; case XKBOPTIONS: if (xconfigGetSubToken (&(ptr->comment)) != STRING) Error (QUOTE_MSG, "XKBOptions"); - ptr->options = xconfigAddNewOption(ptr->options, - xconfigStrdup("XkbOptions"), - val.str); + xconfigAddNewOption(&ptr->options, "XkbOptions", val.str); break; case PANIX106: - ptr->options = xconfigAddNewOption(ptr->options, - xconfigStrdup("Panix106"), - NULL); + xconfigAddNewOption(&ptr->options, "Panix106", NULL); break; case EOF_TOKEN: Error (UNEXPECTED_EOF_MSG, NULL); @@ -296,8 +264,7 @@ xconfigParseKeyboardSection (void) ptr->identifier = xconfigStrdup(CONF_IMPLICIT_KEYBOARD); ptr->driver = xconfigStrdup("keyboard"); - ptr->options = xconfigAddNewOption(ptr->options, - xconfigStrdup("CoreKeyboard"), NULL); + xconfigAddNewOption(&ptr->options, "CoreKeyboard", NULL); return ptr; } diff --git a/XF86Config-parser/Layout.c b/XF86Config-parser/Layout.c index 1e62d26..9f7c7ca 100644 --- a/XF86Config-parser/Layout.c +++ b/XF86Config-parser/Layout.c @@ -121,9 +121,8 @@ xconfigParseLayoutSection (void) if (xconfigGetSubToken (&(ptr->comment)) != STRING) Error (INACTIVE_MSG, NULL); iptr->device_name = val.str; - ptr->inactives = (XConfigInactivePtr) - xconfigAddListItem((GenericListPtr) ptr->inactives, - (GenericListPtr) iptr); + xconfigAddListItem((GenericListPtr *)(&ptr->inactives), + (GenericListPtr) iptr); } break; case SCREEN: @@ -240,9 +239,8 @@ xconfigParseLayoutSection (void) aptr->right_name = val.str; } - ptr->adjacencies = (XConfigAdjacencyPtr) - xconfigAddListItem((GenericListPtr) ptr->adjacencies, - (GenericListPtr) aptr); + xconfigAddListItem((GenericListPtr *)(&ptr->adjacencies), + (GenericListPtr) aptr); } break; case INPUTDEVICE: @@ -252,18 +250,15 @@ xconfigParseLayoutSection (void) iptr = calloc (1, sizeof (XConfigInputrefRec)); iptr->next = NULL; iptr->options = NULL; - if (xconfigGetSubToken (&(ptr->comment)) != STRING) + if (xconfigGetSubToken(&(ptr->comment)) != STRING) Error (INPUTDEV_MSG, NULL); iptr->input_name = val.str; - while ((token = xconfigGetSubToken (&(ptr->comment))) == STRING) - { - iptr->options = - xconfigAddNewOption (iptr->options, val.str, NULL); + while ((token = xconfigGetSubToken(&(ptr->comment))) == STRING) { + xconfigAddNewOption(&iptr->options, val.str, NULL); } - xconfigUnGetToken (token); - ptr->inputs = (XConfigInputrefPtr) - xconfigAddListItem((GenericListPtr) ptr->inputs, - (GenericListPtr) iptr); + xconfigUnGetToken(token); + xconfigAddListItem((GenericListPtr *)(&ptr->inputs), + (GenericListPtr) iptr); } break; case OPTION: @@ -360,53 +355,62 @@ xconfigPrintLayoutSection (FILE * cf, XConfigLayoutPtr ptr) } void -xconfigFreeLayoutList (XConfigLayoutPtr ptr) +xconfigFreeLayoutList (XConfigLayoutPtr *ptr) { XConfigLayoutPtr prev; - while (ptr) + if (ptr == NULL || *ptr == NULL) + return; + + while (*ptr) { - TEST_FREE (ptr->identifier); - TEST_FREE (ptr->comment); - xconfigFreeAdjacencyList (ptr->adjacencies); - xconfigFreeInputrefList (ptr->inputs); - prev = ptr; - ptr = ptr->next; + TEST_FREE ((*ptr)->identifier); + TEST_FREE ((*ptr)->comment); + xconfigFreeAdjacencyList (&((*ptr)->adjacencies)); + xconfigFreeInputrefList (&((*ptr)->inputs)); + prev = *ptr; + *ptr = (*ptr)->next; free (prev); } } void -xconfigFreeAdjacencyList (XConfigAdjacencyPtr ptr) +xconfigFreeAdjacencyList (XConfigAdjacencyPtr *ptr) { XConfigAdjacencyPtr prev; - while (ptr) - { - TEST_FREE (ptr->screen_name); - TEST_FREE (ptr->top_name); - TEST_FREE (ptr->bottom_name); - TEST_FREE (ptr->left_name); - TEST_FREE (ptr->right_name); + if (ptr == NULL || *ptr == NULL) + return; - prev = ptr; - ptr = ptr->next; + while (*ptr) + { + TEST_FREE ((*ptr)->screen_name); + TEST_FREE ((*ptr)->top_name); + TEST_FREE ((*ptr)->bottom_name); + TEST_FREE ((*ptr)->left_name); + TEST_FREE ((*ptr)->right_name); + + prev = *ptr; + *ptr = (*ptr)->next; free (prev); } } void -xconfigFreeInputrefList (XConfigInputrefPtr ptr) +xconfigFreeInputrefList (XConfigInputrefPtr *ptr) { XConfigInputrefPtr prev; - while (ptr) + if (ptr == NULL || *ptr == NULL) + return; + + while (*ptr) { - TEST_FREE (ptr->input_name); - xconfigOptionListFree (ptr->options); - prev = ptr; - ptr = ptr->next; + TEST_FREE ((*ptr)->input_name); + xconfigFreeOptionList (&((*ptr)->options)); + prev = *ptr; + *ptr = (*ptr)->next; free (prev); } diff --git a/XF86Config-parser/Merge.c b/XF86Config-parser/Merge.c index 7d8ab98..20da333 100644 --- a/XF86Config-parser/Merge.c +++ b/XF86Config-parser/Merge.c @@ -76,17 +76,17 @@ static void xconfigAddRemovedOptionComment(char **existing_comments, * list and (if specified) adds a comment to an existing comments string * */ -static void xconfigRemoveNamedOption(XConfigOptionPtr *head, char *name, - char **comments) +void xconfigRemoveNamedOption(XConfigOptionPtr *pHead, const char *name, + char **comments) { XConfigOptionPtr option; - option = xconfigFindOption(*head, name); + option = xconfigFindOption(*pHead, name); if (option) { if (comments) { xconfigAddRemovedOptionComment(comments, option); } - *head = xconfigRemoveOption(*head, option); + xconfigRemoveOption(pHead, option); } } /* xconfigRemoveNamedOption() */ @@ -153,12 +153,12 @@ static void xconfigMergeOption(XConfigOptionPtr *dstHead, if (!srcOption && dstOption) { /* option does not exist in src, but exists in dst: remove from dst */ - *dstHead = xconfigRemoveOption(*dstHead, dstOption); + xconfigRemoveOption(dstHead, dstOption); } else if (srcOption && !dstOption) { /* option exists in src but not in dst: add to dst */ - *dstHead = xconfigAddNewOption(*dstHead, name, srcValue); + xconfigAddNewOption(dstHead, name, srcValue); } else if (srcOption && dstOption) { @@ -173,7 +173,7 @@ static void xconfigMergeOption(XConfigOptionPtr *dstHead, if (comments) { xconfigAddRemovedOptionComment(comments, dstOption); } - *dstHead = xconfigAddNewOption(*dstHead, name, srcValue); + xconfigAddNewOption(dstHead, name, srcValue); } } @@ -259,8 +259,7 @@ static void xconfigMergeMonitors(XConfigMonitorPtr dstMonitor, /* XXX Remove the destination monitor's "UseModes" references to * avoid having the wrong modelines tied to the new monitor. */ - xconfigFreeModesLinkList(dstMonitor->modes_sections); - dstMonitor->modes_sections = NULL; + xconfigFreeModesLinkList(&dstMonitor->modes_sections); } /* xconfigMergeMonitors() */ @@ -295,9 +294,8 @@ static int xconfigMergeAllMonitors(XConfigPtr dstConfig, XConfigPtr srcConfig) dstMonitor->identifier = xconfigStrdup(srcMonitor->identifier); - dstConfig->monitors = (XConfigMonitorPtr) - xconfigAddListItem((GenericListPtr)dstConfig->monitors, - (GenericListPtr)dstMonitor); + xconfigAddListItem((GenericListPtr *)(&dstConfig->monitors), + (GenericListPtr)dstMonitor); } /* Do the merge */ @@ -386,9 +384,8 @@ static int xconfigMergeAllDevices(XConfigPtr dstConfig, XConfigPtr srcConfig) dstDevice->identifier = xconfigStrdup(srcDevice->identifier); - dstConfig->devices = (XConfigDevicePtr) - xconfigAddListItem((GenericListPtr)dstConfig->devices, - (GenericListPtr)dstDevice); + xconfigAddListItem((GenericListPtr *)(&dstConfig->devices), + (GenericListPtr)dstDevice); } /* Do the merge */ @@ -451,9 +448,8 @@ static int xconfigMergeDriverOptions(XConfigScreenPtr dstScreen, /* Add the option to the screen->options list */ - dstScreen->options = - xconfigAddNewOption(dstScreen->options, - name, xconfigOptionValue(option)); + xconfigAddNewOption(&dstScreen->options, + name, xconfigOptionValue(option)); option = option->next; } @@ -478,8 +474,7 @@ static int xconfigMergeDisplays(XConfigScreenPtr dstScreen, /* Free all the displays in the destination screen */ - xconfigFreeDisplayList(dstScreen->displays); - dstScreen->displays = NULL; + xconfigFreeDisplayList(&dstScreen->displays); /* Copy all te displays */ @@ -514,11 +509,12 @@ static int xconfigMergeDisplays(XConfigScreenPtr dstScreen, lastDstMode = NULL; srcMode = srcDisplay->modes; + dstMode = NULL; while (srcMode) { /* Copy the mode */ - - dstMode = xconfigAddMode(NULL, srcMode->mode_name); + + xconfigAddMode(&dstMode, srcMode->mode_name); /* Add mode at the end of the list */ @@ -532,9 +528,8 @@ static int xconfigMergeDisplays(XConfigScreenPtr dstScreen, srcMode = srcMode->next; } - dstScreen->displays = - (XConfigDisplayPtr)xconfigAddListItem((GenericListPtr)(dstScreen->displays), - (GenericListPtr)dstDisplay); + xconfigAddListItem((GenericListPtr *)(&dstScreen->displays), + (GenericListPtr)dstDisplay); } return 1; @@ -619,9 +614,8 @@ static int xconfigMergeAllScreens(XConfigPtr dstConfig, XConfigPtr srcConfig) dstScreen->identifier = xconfigStrdup(srcScreen->identifier); - dstConfig->screens = (XConfigScreenPtr) - xconfigAddListItem((GenericListPtr)dstConfig->screens, - (GenericListPtr)dstScreen); + xconfigAddListItem((GenericListPtr *)(&dstConfig->screens), + (GenericListPtr)dstScreen); } /* Do the merge */ @@ -650,7 +644,7 @@ static int xconfigMergeLayout(XConfigPtr dstConfig, XConfigPtr srcConfig) /* Clear the destination's adjacency list */ - xconfigFreeAdjacencyList(dstLayout->adjacencies); + xconfigFreeAdjacencyList(&dstLayout->adjacencies); /* Copy adjacencies over */ diff --git a/XF86Config-parser/Module.c b/XF86Config-parser/Module.c index 0605367..69dde1a 100644 --- a/XF86Config-parser/Module.c +++ b/XF86Config-parser/Module.c @@ -114,8 +114,8 @@ xconfigParseModuleSubSection (XConfigLoadPtr head, char *name) } - return ((XConfigLoadPtr) xconfigAddListItem ((GenericListPtr) head, - (GenericListPtr) ptr)); + xconfigAddListItem((GenericListPtr *)(&head), (GenericListPtr)ptr); + return head; } XConfigModulePtr @@ -134,16 +134,14 @@ xconfigParseModuleSection (void) case LOAD: if (xconfigGetSubToken (&(ptr->comment)) != STRING) Error (QUOTE_MSG, "Load"); - ptr->loads = - xconfigAddNewLoadDirective (ptr->loads, val.str, - XCONFIG_LOAD_MODULE, NULL, TRUE); + xconfigAddNewLoadDirective (&ptr->loads, val.str, + XCONFIG_LOAD_MODULE, NULL, TRUE); break; case LOAD_DRIVER: if (xconfigGetSubToken (&(ptr->comment)) != STRING) Error (QUOTE_MSG, "LoadDriver"); - ptr->loads = - xconfigAddNewLoadDirective (ptr->loads, val.str, - XCONFIG_LOAD_DRIVER, NULL, TRUE); + xconfigAddNewLoadDirective (&ptr->loads, val.str, + XCONFIG_LOAD_DRIVER, NULL, TRUE); break; case SUBSECTION: if (xconfigGetSubToken (&(ptr->comment)) != STRING) @@ -212,8 +210,8 @@ xconfigPrintModuleSection (FILE * cf, XConfigModulePtr ptr) } } -XConfigLoadPtr -xconfigAddNewLoadDirective (XConfigLoadPtr head, char *name, int type, +void +xconfigAddNewLoadDirective (XConfigLoadPtr *pHead, char *name, int type, XConfigOptionPtr opts, int do_token) { XConfigLoadPtr new; @@ -226,49 +224,37 @@ xconfigAddNewLoadDirective (XConfigLoadPtr head, char *name, int type, new->next = NULL; if (do_token) { - if ((token = xconfigGetToken(NULL)) == COMMENT) + if ((token = xconfigGetToken(NULL)) == COMMENT) { new->comment = xconfigAddComment(new->comment, val.str); - else + } else { xconfigUnGetToken(token); + } } - return ((XConfigLoadPtr) xconfigAddListItem ((GenericListPtr) head, - (GenericListPtr) new)); + xconfigAddListItem((GenericListPtr *)pHead, (GenericListPtr)new); } -XConfigLoadPtr -xconfigRemoveLoadDirective(XConfigLoadPtr head, XConfigLoadPtr load) +void +xconfigRemoveLoadDirective(XConfigLoadPtr *pHead, XConfigLoadPtr load) { - XConfigLoadPtr prev = NULL; - XConfigLoadPtr l = head; + xconfigRemoveListItem((GenericListPtr *)pHead, (GenericListPtr)load); - while (l) { - if (l == load) { - if (prev) prev->next = load->next; - if (head == load) head = load->next; - TEST_FREE(load->name); - TEST_FREE(load->comment); - xconfigOptionListFree(load->opt); - free(load); - break; - } - - prev = l; - l = l->next; - } - - return head; + TEST_FREE(load->name); + TEST_FREE(load->comment); + xconfigFreeOptionList(&(load->opt)); + free(load); } void -xconfigFreeModules (XConfigModulePtr ptr) +xconfigFreeModules (XConfigModulePtr *ptr) { XConfigLoadPtr lptr; XConfigLoadPtr prev; - if (ptr == NULL) + if (ptr == NULL || *ptr == NULL) return; - lptr = ptr->loads; + + lptr = (*ptr)->loads; while (lptr) { TEST_FREE (lptr->name); @@ -277,6 +263,7 @@ xconfigFreeModules (XConfigModulePtr ptr) lptr = lptr->next; free (prev); } - TEST_FREE (ptr->comment); - free (ptr); + TEST_FREE ((*ptr)->comment); + free (*ptr); + *ptr = NULL; } diff --git a/XF86Config-parser/Monitor.c b/XF86Config-parser/Monitor.c index 32080a9..6a8fd00 100644 --- a/XF86Config-parser/Monitor.c +++ b/XF86Config-parser/Monitor.c @@ -560,9 +560,8 @@ VertDone: mptr->next = NULL; mptr->modes_name = val.str; mptr->modes = NULL; - ptr->modes_sections = (XConfigModesLinkPtr) - xconfigAddListItem((GenericListPtr)ptr->modes_sections, - (GenericListPtr)mptr); + xconfigAddListItem((GenericListPtr *)(&ptr->modes_sections), + (GenericListPtr)mptr); } break; case EOF_TOKEN: @@ -571,7 +570,7 @@ VertDone: default: xconfigErrorMsg(ParseErrorMsg, INVALID_KEYWORD_MSG, xconfigTokenString()); - CLEANUP (ptr); + CLEANUP (&ptr); return NULL; break; } @@ -619,7 +618,7 @@ xconfigParseModesSection (void) default: xconfigErrorMsg(ParseErrorMsg, INVALID_KEYWORD_MSG, xconfigTokenString()); - CLEANUP (ptr); + CLEANUP (&ptr); return NULL; break; } @@ -785,65 +784,78 @@ xconfigPrintModesSection (FILE * cf, XConfigModesPtr ptr) } void -xconfigFreeMonitorList (XConfigMonitorPtr ptr) +xconfigFreeMonitorList (XConfigMonitorPtr *ptr) { XConfigMonitorPtr prev; - while (ptr) + if (ptr == NULL || *ptr == NULL) + return; + + while (*ptr) { - TEST_FREE (ptr->identifier); - TEST_FREE (ptr->vendor); - TEST_FREE (ptr->modelname); - TEST_FREE (ptr->comment); - xconfigOptionListFree (ptr->options); - xconfigFreeModeLineList (ptr->modelines); - prev = ptr; - ptr = ptr->next; + TEST_FREE ((*ptr)->identifier); + TEST_FREE ((*ptr)->vendor); + TEST_FREE ((*ptr)->modelname); + TEST_FREE ((*ptr)->comment); + xconfigFreeOptionList (&((*ptr)->options)); + xconfigFreeModeLineList (&((*ptr)->modelines)); + prev = *ptr; + *ptr = (*ptr)->next; free (prev); } } void -xconfigFreeModesList (XConfigModesPtr ptr) +xconfigFreeModesList (XConfigModesPtr *ptr) { XConfigModesPtr prev; - while (ptr) + if (ptr == NULL || *ptr == NULL) + return; + + while (*ptr) { - TEST_FREE (ptr->identifier); - TEST_FREE (ptr->comment); - xconfigFreeModeLineList (ptr->modelines); - prev = ptr; - ptr = ptr->next; + TEST_FREE ((*ptr)->identifier); + TEST_FREE ((*ptr)->comment); + xconfigFreeModeLineList (&((*ptr)->modelines)); + prev = *ptr; + *ptr = (*ptr)->next; free (prev); } } void -xconfigFreeModeLineList (XConfigModeLinePtr ptr) +xconfigFreeModeLineList (XConfigModeLinePtr *ptr) { XConfigModeLinePtr prev; - while (ptr) + + if (ptr == NULL || *ptr == NULL) + return; + + while (*ptr) { - TEST_FREE (ptr->identifier); - TEST_FREE (ptr->comment); - TEST_FREE (ptr->clock); - prev = ptr; - ptr = ptr->next; + TEST_FREE ((*ptr)->identifier); + TEST_FREE ((*ptr)->comment); + TEST_FREE ((*ptr)->clock); + prev = *ptr; + *ptr = (*ptr)->next; free (prev); } } void -xconfigFreeModesLinkList (XConfigModesLinkPtr ptr) +xconfigFreeModesLinkList (XConfigModesLinkPtr *ptr) { XConfigModesLinkPtr prev; - while (ptr) + if (ptr == NULL || *ptr == NULL) + return; + + while (*ptr) { - TEST_FREE (ptr->modes_name); - prev = ptr; - ptr = ptr->next; + TEST_FREE ((*ptr)->modes_name); + prev = *ptr; + *ptr = (*ptr)->next; free (prev); } } diff --git a/XF86Config-parser/Pointer.c b/XF86Config-parser/Pointer.c index ed49669..29e1c85 100644 --- a/XF86Config-parser/Pointer.c +++ b/XF86Config-parser/Pointer.c @@ -110,69 +110,59 @@ xconfigParsePointerSection (void) case PROTOCOL: if (xconfigGetSubToken (&(ptr->comment)) != STRING) Error (QUOTE_MSG, "Protocol"); - ptr->options = xconfigAddNewOption(ptr->options, - "Protocol", val.str); + xconfigAddNewOption(&ptr->options, "Protocol", val.str); break; case PDEVICE: if (xconfigGetSubToken (&(ptr->comment)) != STRING) Error (QUOTE_MSG, "Device"); - ptr->options = xconfigAddNewOption(ptr->options, - "Device", val.str); + xconfigAddNewOption(&ptr->options, "Device", val.str); break; case EMULATE3: - ptr->options = - xconfigAddNewOption(ptr->options, "Emulate3Buttons", NULL); + xconfigAddNewOption(&ptr->options, "Emulate3Buttons", NULL); break; case EM3TIMEOUT: if (xconfigGetSubToken (&(ptr->comment)) != NUMBER || val.num < 0) Error (POSITIVE_INT_MSG, "Emulate3Timeout"); s = xconfigULongToString(val.num); - ptr->options = - xconfigAddNewOption(ptr->options, "Emulate3Timeout", s); + xconfigAddNewOption(&ptr->options, "Emulate3Timeout", s); TEST_FREE(s); break; case CHORDMIDDLE: - ptr->options = xconfigAddNewOption(ptr->options, "ChordMiddle", - NULL); + xconfigAddNewOption(&ptr->options, "ChordMiddle", NULL); break; case PBUTTONS: if (xconfigGetSubToken (&(ptr->comment)) != NUMBER || val.num < 0) Error (POSITIVE_INT_MSG, "Buttons"); s = xconfigULongToString(val.num); - ptr->options = xconfigAddNewOption(ptr->options, "Buttons", s); + xconfigAddNewOption(&ptr->options, "Buttons", s); TEST_FREE(s); break; case BAUDRATE: if (xconfigGetSubToken (&(ptr->comment)) != NUMBER || val.num < 0) Error (POSITIVE_INT_MSG, "BaudRate"); s = xconfigULongToString(val.num); - ptr->options = - xconfigAddNewOption(ptr->options, "BaudRate", s); + xconfigAddNewOption(&ptr->options, "BaudRate", s); TEST_FREE(s); break; case SAMPLERATE: if (xconfigGetSubToken (&(ptr->comment)) != NUMBER || val.num < 0) Error (POSITIVE_INT_MSG, "SampleRate"); s = xconfigULongToString(val.num); - ptr->options = - xconfigAddNewOption(ptr->options, "SampleRate", s); + xconfigAddNewOption(&ptr->options, "SampleRate", s); TEST_FREE(s); break; case PRESOLUTION: if (xconfigGetSubToken (&(ptr->comment)) != NUMBER || val.num < 0) Error (POSITIVE_INT_MSG, "Resolution"); s = xconfigULongToString(val.num); - ptr->options = - xconfigAddNewOption(ptr->options, "Resolution", s); + xconfigAddNewOption(&ptr->options, "Resolution", s); TEST_FREE(s); break; case CLEARDTR: - ptr->options = - xconfigAddNewOption(ptr->options, "ClearDTR", NULL); + xconfigAddNewOption(&ptr->options, "ClearDTR", NULL); break; case CLEARRTS: - ptr->options = - xconfigAddNewOption(ptr->options, "ClearRTS", NULL); + xconfigAddNewOption(&ptr->options, "ClearRTS", NULL); break; case ZAXISMAPPING: switch (xconfigGetToken(ZMapTab)) { @@ -200,8 +190,7 @@ xconfigParsePointerSection (void) Error (ZAXISMAPPING_MSG, NULL); break; } - ptr->options = - xconfigAddNewOption(ptr->options, "ZAxisMapping", s); + xconfigAddNewOption(&ptr->options, "ZAxisMapping", s); TEST_FREE(s); break; case ALWAYSCORE: @@ -217,7 +206,7 @@ xconfigParsePointerSection (void) ptr->identifier = xconfigStrdup(CONF_IMPLICIT_POINTER); ptr->driver = xconfigStrdup("mouse"); - ptr->options = xconfigAddNewOption(ptr->options, "CorePointer", NULL); + xconfigAddNewOption(&ptr->options, "CorePointer", NULL); return ptr; } diff --git a/XF86Config-parser/Read.c b/XF86Config-parser/Read.c index 7d21e44..28b0432 100644 --- a/XF86Config-parser/Read.c +++ b/XF86Config-parser/Read.c @@ -68,9 +68,9 @@ static XConfigSymTabRec TopLevelTab[] = #define CLEANUP xconfigFreeConfig -#define READ_HANDLE_RETURN(f,func) \ - if ((ptr->f=func) == NULL) { \ - xconfigFreeConfig(ptr); \ +#define READ_HANDLE_RETURN(f,func) \ + if ((ptr->f=func) == NULL) { \ + xconfigFreeConfig(&ptr); \ return XCONFIG_RETURN_PARSE_ERROR; \ } @@ -78,21 +78,20 @@ static XConfigSymTabRec TopLevelTab[] = { \ type p = func(); \ if (p == NULL) { \ - xconfigFreeConfig(ptr); \ - return XCONFIG_RETURN_PARSE_ERROR; \ + xconfigFreeConfig(&ptr); \ + return XCONFIG_RETURN_PARSE_ERROR; \ } else { \ - ptr->field = (type) \ - xconfigAddListItem((GenericListPtr) ptr->field, \ - (GenericListPtr) p); \ + xconfigAddListItem((GenericListPtr *)(&ptr->field), \ + (GenericListPtr) p); \ } \ } -#define READ_ERROR(a,b) \ - do { \ +#define READ_ERROR(a,b) \ + do { \ xconfigErrorMsg(ParseErrorMsg, a, b); \ - xconfigFreeConfig(ptr); \ + xconfigFreeConfig(&ptr); \ return XCONFIG_RETURN_PARSE_ERROR; \ - } while (0) \ + } while (0) @@ -121,7 +120,7 @@ XConfigError xconfigReadConfigFile(XConfigPtr *configPtr) case SECTION: if (xconfigGetSubToken(&(ptr->comment)) != STRING) { xconfigErrorMsg(ParseErrorMsg, QUOTE_MSG, "Section"); - xconfigFreeConfig(ptr); + xconfigFreeConfig(&ptr); return XCONFIG_RETURN_PARSE_ERROR; } @@ -248,7 +247,7 @@ XConfigError xconfigReadConfigFile(XConfigPtr *configPtr) *configPtr = ptr; return XCONFIG_RETURN_SUCCESS; } else { - xconfigFreeConfig(ptr); + xconfigFreeConfig(&ptr); return XCONFIG_RETURN_VALIDATION_ERROR; } } @@ -300,56 +299,47 @@ int xconfigSanitizeConfig(XConfigPtr p, /* * adds an item to the end of the linked list. Any record whose first field * is a GenericListRec can be cast to this type and used with this function. - * A pointer to the head of the list is returned to handle the addition of - * the first item. */ -GenericListPtr -xconfigAddListItem (GenericListPtr head, GenericListPtr new) +void xconfigAddListItem (GenericListPtr *pHead, GenericListPtr new) { - GenericListPtr p = head; + GenericListPtr p = *pHead; GenericListPtr last = NULL; - while (p) - { + while (p) { last = p; p = p->next; } - if (last) - { + if (last) { last->next = new; - return (head); + } else { + *pHead = new; } - else - return (new); } /* - * removes an item from the linked list. Any record whose first field - * is a GenericListRec can be cast to this type and used with this function. - * A pointer to the head of the list is returned to handle the removal of - * the first item. + * removes an item from the linked list (but does not delete it). Any record + * whose first field is a GenericListRec can be cast to this type and used + * with this function. */ -GenericListPtr -xconfigRemoveListItem (GenericListPtr head, GenericListPtr item) +void xconfigRemoveListItem (GenericListPtr *pHead, GenericListPtr item) { - GenericListPtr cur = head; + GenericListPtr cur = *pHead; GenericListPtr prev = NULL; - while (cur) - { - if (cur == item) - { - if (prev) prev->next = item->next; - if (head == item) head = item->next; - break; + while (cur) { + if (cur == item) { + if (prev) { + prev->next = item->next; + } else { + *pHead = item->next; + } + return; } prev = cur; cur = cur->next; } - - return head; } @@ -378,24 +368,25 @@ xconfigItemNotSublist(GenericListPtr list_1, GenericListPtr list_2) } void -xconfigFreeConfig (XConfigPtr p) +xconfigFreeConfig (XConfigPtr *p) { - if (p == NULL) + if (p == NULL || *p == NULL) return; - xconfigFreeFiles (p->files); - xconfigFreeModules (p->modules); - xconfigFreeFlags (p->flags); - xconfigFreeMonitorList (p->monitors); - xconfigFreeModesList (p->modes); - xconfigFreeVideoAdaptorList (p->videoadaptors); - xconfigFreeDeviceList (p->devices); - xconfigFreeScreenList (p->screens); - xconfigFreeLayoutList (p->layouts); - xconfigFreeInputList (p->inputs); - xconfigFreeVendorList (p->vendors); - xconfigFreeDRI (p->dri); - TEST_FREE(p->comment); - - free (p); + xconfigFreeFiles (&((*p)->files)); + xconfigFreeModules (&((*p)->modules)); + xconfigFreeFlags (&((*p)->flags)); + xconfigFreeMonitorList (&((*p)->monitors)); + xconfigFreeModesList (&((*p)->modes)); + xconfigFreeVideoAdaptorList (&((*p)->videoadaptors)); + xconfigFreeDeviceList (&((*p)->devices)); + xconfigFreeScreenList (&((*p)->screens)); + xconfigFreeLayoutList (&((*p)->layouts)); + xconfigFreeInputList (&((*p)->inputs)); + xconfigFreeVendorList (&((*p)->vendors)); + xconfigFreeDRI (&((*p)->dri)); + TEST_FREE((*p)->comment); + + free (*p); + *p = NULL; } diff --git a/XF86Config-parser/Screen.c b/XF86Config-parser/Screen.c index f58d76b..fbb155c 100644 --- a/XF86Config-parser/Screen.c +++ b/XF86Config-parser/Screen.c @@ -170,9 +170,8 @@ xconfigParseDisplaySubSection (void) mptr = calloc (1, sizeof (XConfigModeRec)); mptr->mode_name = val.str; mptr->next = NULL; - ptr->modes = (XConfigModePtr) - xconfigAddListItem ((GenericListPtr) ptr->modes, - (GenericListPtr) mptr); + xconfigAddListItem((GenericListPtr *)(&ptr->modes), + (GenericListPtr) mptr); } xconfigUnGetToken (token); } @@ -289,9 +288,8 @@ xconfigParseScreenSection (void) aptr = calloc (1, sizeof (XConfigAdaptorLinkRec)); aptr->next = NULL; aptr->adaptor_name = val.str; - ptr->adaptors = (XConfigAdaptorLinkPtr) - xconfigAddListItem ((GenericListPtr) ptr->adaptors, - (GenericListPtr) aptr); + xconfigAddListItem ((GenericListPtr *)(&ptr->adaptors), + (GenericListPtr) aptr); } } break; @@ -420,64 +418,76 @@ xconfigPrintScreenSection (FILE * cf, XConfigScreenPtr ptr) } void -xconfigFreeScreenList (XConfigScreenPtr ptr) +xconfigFreeScreenList (XConfigScreenPtr *ptr) { XConfigScreenPtr prev; - while (ptr) + if (ptr == NULL || *ptr == NULL) + return; + + while (*ptr) { - TEST_FREE (ptr->identifier); - TEST_FREE (ptr->monitor_name); - TEST_FREE (ptr->device_name); - TEST_FREE (ptr->comment); - xconfigOptionListFree (ptr->options); - xconfigFreeAdaptorLinkList (ptr->adaptors); - xconfigFreeDisplayList (ptr->displays); - prev = ptr; - ptr = ptr->next; + TEST_FREE ((*ptr)->identifier); + TEST_FREE ((*ptr)->monitor_name); + TEST_FREE ((*ptr)->device_name); + TEST_FREE ((*ptr)->comment); + xconfigFreeOptionList (&((*ptr)->options)); + xconfigFreeAdaptorLinkList (&((*ptr)->adaptors)); + xconfigFreeDisplayList (&((*ptr)->displays)); + prev = *ptr; + *ptr = (*ptr)->next; free (prev); } } void -xconfigFreeAdaptorLinkList (XConfigAdaptorLinkPtr ptr) +xconfigFreeAdaptorLinkList (XConfigAdaptorLinkPtr *ptr) { XConfigAdaptorLinkPtr prev; - while (ptr) + if (ptr == NULL || *ptr == NULL) + return; + + while (*ptr) { - TEST_FREE (ptr->adaptor_name); - prev = ptr; - ptr = ptr->next; + TEST_FREE ((*ptr)->adaptor_name); + prev = *ptr; + *ptr = (*ptr)->next; free (prev); } } void -xconfigFreeDisplayList (XConfigDisplayPtr ptr) +xconfigFreeDisplayList (XConfigDisplayPtr *ptr) { XConfigDisplayPtr prev; - while (ptr) + if (ptr == NULL || *ptr == NULL) + return; + + while (*ptr) { - xconfigFreeModeList (ptr->modes); - xconfigOptionListFree (ptr->options); - prev = ptr; - ptr = ptr->next; + xconfigFreeModeList (&((*ptr)->modes)); + xconfigFreeOptionList (&((*ptr)->options)); + prev = *ptr; + *ptr = (*ptr)->next; free (prev); } } void -xconfigFreeModeList (XConfigModePtr ptr) +xconfigFreeModeList (XConfigModePtr *ptr) { XConfigModePtr prev; - while (ptr) + if (ptr == NULL || *ptr == NULL) + return; + + while (*ptr) { - TEST_FREE (ptr->mode_name); - prev = ptr; - ptr = ptr->next; + TEST_FREE ((*ptr)->mode_name); + prev = *ptr; + *ptr = (*ptr)->next; free (prev); } } @@ -639,40 +649,39 @@ xconfigFindMode (const char *name, XConfigModePtr p) return (NULL); } -XConfigModePtr -xconfigAddMode(XConfigModePtr head, const char *name) +void +xconfigAddMode(XConfigModePtr *pHead, const char *name) { XConfigModePtr mode; mode = xconfigAlloc(sizeof(XConfigModeRec)); mode->mode_name = xconfigStrdup(name); - mode->next = head; - - return mode; - + mode->next = *pHead; + *pHead = mode; } -XConfigModePtr -xconfigRemoveMode(XConfigModePtr head, const char *name) +void +xconfigRemoveMode(XConfigModePtr *pHead, const char *name) { - XConfigModePtr prev = NULL; - XConfigModePtr m = head; - - while (m) { - if (xconfigNameCompare(m->mode_name, name) == 0) { - if (prev) prev->next = m->next; - if (head == m) head = m->next; - free(m->mode_name); - free(m); - break; + XConfigModePtr p = *pHead; + XConfigModePtr last = NULL; + + while (p) { + if (xconfigNameCompare(p->mode_name, name) == 0) { + if (last) { + last->next = p->next; + } else { + *pHead = p->next; + } + free(p->mode_name); + free(p); + return; } - prev = m; - m = m->next; + last = p; + p = p->next; } - - return head; } diff --git a/XF86Config-parser/Vendor.c b/XF86Config-parser/Vendor.c index 7f6beba..ba0ca09 100644 --- a/XF86Config-parser/Vendor.c +++ b/XF86Config-parser/Vendor.c @@ -203,30 +203,35 @@ xconfigPrintVendorSection (FILE * cf, XConfigVendorPtr ptr) } void -xconfigFreeVendorList (XConfigVendorPtr p) +xconfigFreeVendorList (XConfigVendorPtr *p) { - if (p == NULL) + if (p == NULL || *p == NULL) return; - xconfigFreeVendorSubList (p->subs); - TEST_FREE (p->identifier); - TEST_FREE (p->comment); - xconfigOptionListFree (p->options); - free (p); + + xconfigFreeVendorSubList (&((*p)->subs)); + TEST_FREE ((*p)->identifier); + TEST_FREE ((*p)->comment); + xconfigFreeOptionList (&((*p)->options)); + free (*p); + *p = NULL; } void -xconfigFreeVendorSubList (XConfigVendSubPtr ptr) +xconfigFreeVendorSubList (XConfigVendSubPtr *ptr) { XConfigVendSubPtr prev; - while (ptr) + if (ptr == NULL || *ptr == NULL) + return; + + while (*ptr) { - TEST_FREE (ptr->identifier); - TEST_FREE (ptr->name); - TEST_FREE (ptr->comment); - xconfigOptionListFree (ptr->options); - prev = ptr; - ptr = ptr->next; + TEST_FREE ((*ptr)->identifier); + TEST_FREE ((*ptr)->name); + TEST_FREE ((*ptr)->comment); + xconfigFreeOptionList (&((*ptr)->options)); + prev = *ptr; + *ptr = (*ptr)->next; free (prev); } } diff --git a/XF86Config-parser/Video.c b/XF86Config-parser/Video.c index a09d7f7..2a66dce 100644 --- a/XF86Config-parser/Video.c +++ b/XF86Config-parser/Video.c @@ -233,39 +233,45 @@ xconfigPrintVideoAdaptorSection (FILE * cf, XConfigVideoAdaptorPtr ptr) } void -xconfigFreeVideoAdaptorList (XConfigVideoAdaptorPtr ptr) +xconfigFreeVideoAdaptorList (XConfigVideoAdaptorPtr *ptr) { XConfigVideoAdaptorPtr prev; - while (ptr) + if (ptr == NULL || *ptr == NULL) + return; + + while (*ptr) { - TEST_FREE (ptr->identifier); - TEST_FREE (ptr->vendor); - TEST_FREE (ptr->board); - TEST_FREE (ptr->busid); - TEST_FREE (ptr->driver); - TEST_FREE (ptr->fwdref); - TEST_FREE (ptr->comment); - xconfigFreeVideoPortList (ptr->ports); - xconfigOptionListFree (ptr->options); - prev = ptr; - ptr = ptr->next; + TEST_FREE ((*ptr)->identifier); + TEST_FREE ((*ptr)->vendor); + TEST_FREE ((*ptr)->board); + TEST_FREE ((*ptr)->busid); + TEST_FREE ((*ptr)->driver); + TEST_FREE ((*ptr)->fwdref); + TEST_FREE ((*ptr)->comment); + xconfigFreeVideoPortList (&((*ptr)->ports)); + xconfigFreeOptionList (&((*ptr)->options)); + prev = *ptr; + *ptr = (*ptr)->next; free (prev); } } void -xconfigFreeVideoPortList (XConfigVideoPortPtr ptr) +xconfigFreeVideoPortList (XConfigVideoPortPtr *ptr) { XConfigVideoPortPtr prev; - while (ptr) + if (ptr == NULL || *ptr == NULL) + return; + + while (*ptr) { - TEST_FREE (ptr->identifier); - TEST_FREE (ptr->comment); - xconfigOptionListFree (ptr->options); - prev = ptr; - ptr = ptr->next; + TEST_FREE ((*ptr)->identifier); + TEST_FREE ((*ptr)->comment); + xconfigFreeOptionList (&((*ptr)->options)); + prev = *ptr; + *ptr = (*ptr)->next; free (prev); } } diff --git a/XF86Config-parser/xf86Parser.h b/XF86Config-parser/xf86Parser.h index 6598d5e..7d34407 100644 --- a/XF86Config-parser/xf86Parser.h +++ b/XF86Config-parser/xf86Parser.h @@ -604,7 +604,7 @@ int xconfigSanitizeConfig(XConfigPtr p, const char *screenName, void xconfigCloseConfigFile(void); int xconfigWriteConfigFile(const char *, XConfigPtr); -void xconfigFreeConfig(XConfigPtr p); +void xconfigFreeConfig(XConfigPtr *p); /* * Functions for searching for entries in lists @@ -629,29 +629,30 @@ XConfigVideoAdaptorPtr xconfigFindVideoAdaptor(const char *ident, * Functions for freeing lists */ -void xconfigFreeDeviceList(XConfigDevicePtr ptr); -void xconfigFreeFiles(XConfigFilesPtr p); -void xconfigFreeFlags(XConfigFlagsPtr flags); -void xconfigFreeInputList(XConfigInputPtr ptr); -void xconfigFreeLayoutList(XConfigLayoutPtr ptr); -void xconfigFreeAdjacencyList(XConfigAdjacencyPtr ptr); -void xconfigFreeInputrefList(XConfigInputrefPtr ptr); -void xconfigFreeModules(XConfigModulePtr ptr); -void xconfigFreeMonitorList(XConfigMonitorPtr ptr); -void xconfigFreeModesList(XConfigModesPtr ptr); -void xconfigFreeModeLineList(XConfigModeLinePtr ptr); -void xconfigFreeScreenList(XConfigScreenPtr ptr); -void xconfigFreeAdaptorLinkList(XConfigAdaptorLinkPtr ptr); -void xconfigFreeDisplayList(XConfigDisplayPtr ptr); -void xconfigFreeModeList(XConfigModePtr ptr); -void xconfigFreeVendorList(XConfigVendorPtr p); -void xconfigFreeVendorSubList(XConfigVendSubPtr ptr); -void xconfigFreeVideoAdaptorList(XConfigVideoAdaptorPtr ptr); -void xconfigFreeVideoPortList(XConfigVideoPortPtr ptr); -void xconfigFreeBuffersList (XConfigBuffersPtr ptr); -void xconfigFreeDRI(XConfigDRIPtr ptr); -void xconfigFreeExtensions(XConfigExtensionsPtr ptr); -void xconfigFreeModesLinkList(XConfigModesLinkPtr ptr); +void xconfigFreeDeviceList(XConfigDevicePtr *ptr); +void xconfigFreeFiles(XConfigFilesPtr *p); +void xconfigFreeFlags(XConfigFlagsPtr *flags); +void xconfigFreeInputList(XConfigInputPtr *ptr); +void xconfigFreeLayoutList(XConfigLayoutPtr *ptr); +void xconfigFreeAdjacencyList(XConfigAdjacencyPtr *ptr); +void xconfigFreeInputrefList(XConfigInputrefPtr *ptr); +void xconfigFreeModules(XConfigModulePtr *ptr); +void xconfigFreeMonitorList(XConfigMonitorPtr *ptr); +void xconfigFreeModesList(XConfigModesPtr *ptr); +void xconfigFreeModeLineList(XConfigModeLinePtr *ptr); +void xconfigFreeOptionList(XConfigOptionPtr *opt); +void xconfigFreeScreenList(XConfigScreenPtr *ptr); +void xconfigFreeAdaptorLinkList(XConfigAdaptorLinkPtr *ptr); +void xconfigFreeDisplayList(XConfigDisplayPtr *ptr); +void xconfigFreeModeList(XConfigModePtr *ptr); +void xconfigFreeVendorList(XConfigVendorPtr *p); +void xconfigFreeVendorSubList(XConfigVendSubPtr *ptr); +void xconfigFreeVideoAdaptorList(XConfigVideoAdaptorPtr *ptr); +void xconfigFreeVideoPortList(XConfigVideoPortPtr *ptr); +void xconfigFreeBuffersList (XConfigBuffersPtr *ptr); +void xconfigFreeDRI(XConfigDRIPtr *ptr); +void xconfigFreeExtensions(XConfigExtensionsPtr *ptr); +void xconfigFreeModesLinkList(XConfigModesLinkPtr *ptr); @@ -659,26 +660,26 @@ void xconfigFreeModesLinkList(XConfigModesLinkPtr ptr); * item/list manipulation */ -GenericListPtr xconfigAddListItem(GenericListPtr head, GenericListPtr c_new); -GenericListPtr xconfigRemoveListItem(GenericListPtr list, GenericListPtr item); +void xconfigAddListItem(GenericListPtr *pHead, GenericListPtr c_new); +void xconfigRemoveListItem(GenericListPtr *pHead, GenericListPtr item); int xconfigItemNotSublist(GenericListPtr list_1, GenericListPtr list_2); char *xconfigAddComment(char *cur, char *add); -XConfigLoadPtr xconfigAddNewLoadDirective(XConfigLoadPtr head, - char *name, int type, - XConfigOptionPtr opts, int do_token); -XConfigLoadPtr xconfigRemoveLoadDirective(XConfigLoadPtr head, - XConfigLoadPtr load); +void xconfigAddNewLoadDirective(XConfigLoadPtr *pHead, + char *name, int type, + XConfigOptionPtr opts, int do_token); +void xconfigRemoveLoadDirective(XConfigLoadPtr *pHead, XConfigLoadPtr load); /* * Functions for manipulating Options */ -XConfigOptionPtr xconfigAddNewOption(XConfigOptionPtr head, - const char *name, const char *val); -XConfigOptionPtr xconfigRemoveOption(XConfigOptionPtr list, - XConfigOptionPtr opt); +void xconfigAddNewOption(XConfigOptionPtr *pHead, + const char *name, const char *val); +void xconfigRemoveOption(XConfigOptionPtr *pHead, XConfigOptionPtr opt); +void xconfigRemoveNamedOption(XConfigOptionPtr *head, const char *name, + char **comments); + XConfigOptionPtr xconfigOptionListDup(XConfigOptionPtr opt); -void xconfigOptionListFree(XConfigOptionPtr opt); char *xconfigOptionName(XConfigOptionPtr opt); char *xconfigOptionValue(XConfigOptionPtr opt); XConfigOptionPtr xconfigNewOption(const char *name, const char *value); @@ -705,15 +706,10 @@ void xconfigPrintOptionList(FILE *fp, XConfigOptionPtr list, int tabs); int xconfigParsePciBusString(const char *busID, int *bus, int *device, int *func); -XConfigDisplayPtr -xconfigAddDisplay(XConfigDisplayPtr head, const int depth); - -XConfigModePtr -xconfigAddMode(XConfigModePtr head, const char *name); - -XConfigModePtr -xconfigRemoveMode(XConfigModePtr head, const char *name); +void xconfigAddDisplay(XConfigDisplayPtr *pHead, const int depth); +void xconfigAddMode(XConfigModePtr *pHead, const char *name); +void xconfigRemoveMode(XConfigModePtr *pHead, const char *name); XConfigPtr xconfigGenerate(GenerateOptions *gop); diff --git a/make_usable.c b/make_usable.c index 8c047d7..417524d 100644 --- a/make_usable.c +++ b/make_usable.c @@ -36,7 +36,7 @@ static void ensure_module_loaded(XConfigPtr config, char *name); -static int update_device(XConfigPtr config, XConfigDevicePtr device); +static int update_device(Options *op, XConfigPtr config, XConfigDevicePtr device); static void update_depth(Options *op, XConfigScreenPtr screen); static void update_display(Options *op, XConfigScreenPtr screen); @@ -53,10 +53,9 @@ static void ensure_module_loaded(XConfigPtr config, char *name) { } if (!found) { - config->modules->loads = - xconfigAddNewLoadDirective(config->modules->loads, - name, XCONFIG_LOAD_MODULE, - NULL, FALSE); + xconfigAddNewLoadDirective(&config->modules->loads, + name, XCONFIG_LOAD_MODULE, + NULL, FALSE); } } /* ensure_module_loaded */ @@ -93,11 +92,9 @@ int update_modules(XConfigPtr config) while (load) { next = load->next; if (xconfigNameCompare("GLcore", load->name) == 0) { - config->modules->loads = - xconfigRemoveLoadDirective(config->modules->loads, load); + xconfigRemoveLoadDirective(&config->modules->loads, load); } else if (xconfigNameCompare("dri", load->name) == 0) { - config->modules->loads = - xconfigRemoveLoadDirective(config->modules->loads, load); + xconfigRemoveLoadDirective(&config->modules->loads, load); } load = next; } @@ -121,7 +118,7 @@ int update_screen(Options *op, XConfigPtr config, XConfigScreenPtr screen) update_display(op, screen); update_depth(op, screen); - update_device(config, screen->device); + update_device(op, config, screen->device); update_options(op, screen); return TRUE; @@ -191,7 +188,8 @@ int update_extensions(Options *op, XConfigPtr config) /* remove any existing composite extension option */ - remove_option_from_list(&(config->extensions->options), "Composite"); + xconfigRemoveNamedOption(&(config->extensions->options), "Composite", + NULL); /* determine the value to set for the Composite option */ @@ -201,9 +199,7 @@ int update_extensions(Options *op, XConfigPtr config) /* add the option */ - config->extensions->options = - xconfigAddNewOption(config->extensions->options, - "Composite", value); + xconfigAddNewOption(&config->extensions->options, "Composite", value); } return TRUE; @@ -228,15 +224,13 @@ int update_server_flags(Options *op, XConfigPtr config) } if (config->flags->options) { - remove_option_from_list(&(config->flags->options), - "HandleSpecialKeys"); + xconfigRemoveNamedOption(&(config->flags->options), + "HandleSpecialKeys", NULL); } if (op->handle_special_keys != NV_DISABLE_STRING_OPTION) { - config->flags->options = - xconfigAddNewOption(config->flags->options, - "HandleSpecialKeys", - op->handle_special_keys); + xconfigAddNewOption(&config->flags->options, "HandleSpecialKeys", + op->handle_special_keys); } return TRUE; @@ -255,9 +249,9 @@ int update_server_flags(Options *op, XConfigPtr config) * the NVIDIA X driver. */ -static int update_device(XConfigPtr config, XConfigDevicePtr device) +static int update_device(Options *op, XConfigPtr config, XConfigDevicePtr device) { - char *identifier, *vendor, *comment, *board, *busid; + char *identifier, *vendor, *comment, *board, *busid, *driver; int screen; XConfigDevicePtr next; XConfigOptionPtr options; @@ -270,6 +264,7 @@ static int update_device(XConfigPtr config, XConfigDevicePtr device) screen = device->screen; board = device->board; busid = device->busid; + driver = device->driver; memset(device, 0, sizeof(XConfigDeviceRec)); @@ -285,8 +280,12 @@ static int update_device(XConfigPtr config, XConfigDevicePtr device) device->chipid = -1; device->chiprev = -1; device->irq = -1; - - device->driver = "nvidia"; + + if (op->preserve_driver) { + device->driver = driver; + } else { + device->driver = "nvidia"; + } /* * XXX do we really want to preserve the BusID line? Let's only @@ -364,7 +363,7 @@ static void update_display(Options *op, XConfigScreenPtr screen) XConfigDisplayPtr display; XConfigModePtr mode = NULL; - mode = xconfigAddMode(mode, "nvidia-auto-select"); + xconfigAddMode(&mode, "nvidia-auto-select"); display = nvalloc(sizeof(XConfigDisplayRec)); display->depth = screen->defaultdepth; @@ -376,6 +375,7 @@ static void update_display(Options *op, XConfigScreenPtr screen) screen->displays = display; } + } /* update_display() */ diff --git a/multiple_screens.c b/multiple_screens.c index 09fd5dc..b4a20cc 100644 --- a/multiple_screens.c +++ b/multiple_screens.c @@ -315,13 +315,12 @@ static int set_xinerama(int xinerama_enabled, XConfigPtr config) } if (config->flags->options) { - remove_option_from_list(&(config->flags->options), "Xinerama"); + xconfigRemoveNamedOption(&(config->flags->options), "Xinerama", NULL); } - config->flags->options = - xconfigAddNewOption(config->flags->options, - "Xinerama", - (xinerama_enabled ? "1" : "0")); + xconfigAddNewOption(&config->flags->options, + "Xinerama", + (xinerama_enabled ? "1" : "0")); return TRUE; @@ -493,8 +492,7 @@ static int enable_separate_x_screens(Options *op, XConfigPtr config, * new adjacencies */ - xconfigFreeAdjacencyList(layout->adjacencies); - layout->adjacencies = NULL; + xconfigFreeAdjacencyList(&layout->adjacencies); create_adjacencies(op, config, layout); @@ -620,7 +618,7 @@ static int disable_separate_x_screens(Options *op, XConfigPtr config, } next = screen->next; screen->next = NULL; - xconfigFreeScreenList(screen); + xconfigFreeScreenList(&screen); screen = next; } else { @@ -636,8 +634,7 @@ static int disable_separate_x_screens(Options *op, XConfigPtr config, /* wipe the existing adjacencies and recreate them */ - xconfigFreeAdjacencyList(layout->adjacencies); - layout->adjacencies = NULL; + xconfigFreeAdjacencyList(&layout->adjacencies); create_adjacencies(op, config, layout); @@ -829,17 +826,10 @@ static int enable_all_gpus(Options *op, XConfigPtr config, /* free all existing X screens, monitors, devices, and adjacencies */ - xconfigFreeScreenList(config->screens); - config->screens = NULL; - - xconfigFreeDeviceList(config->devices); - config->devices = NULL; - - xconfigFreeMonitorList(config->monitors); - config->monitors = NULL; - - xconfigFreeAdjacencyList(layout->adjacencies); - layout->adjacencies = NULL; + xconfigFreeScreenList(&config->screens); + xconfigFreeDeviceList(&config->devices); + xconfigFreeMonitorList(&config->monitors); + xconfigFreeAdjacencyList(&layout->adjacencies); /* add N new screens; this will also add device and monitor sections */ @@ -895,7 +885,7 @@ static void free_unused_devices(Options *op, XConfigPtr config) } next = device->next; device->next = NULL; - xconfigFreeDeviceList(device); + xconfigFreeDeviceList(&device); device = next; } else { prev = device; @@ -939,7 +929,7 @@ static void free_unused_monitors(Options *op, XConfigPtr config) } next = monitor->next; monitor->next = NULL; - xconfigFreeMonitorList(monitor); + xconfigFreeMonitorList(&monitor); monitor = next; } else { prev = monitor; @@ -961,13 +951,11 @@ static int only_one_screen(Options *op, XConfigPtr config, /* free all existing X screens after the first */ - xconfigFreeScreenList(config->screens->next); - config->screens->next = NULL; + xconfigFreeScreenList(&config->screens->next); /* free all adjacencies */ - xconfigFreeAdjacencyList(layout->adjacencies); - layout->adjacencies = NULL; + xconfigFreeAdjacencyList(&layout->adjacencies); /* add new adjacency */ diff --git a/nvidia-cfg.h b/nvidia-cfg.h index 6069d2a..71a2c9c 100644 --- a/nvidia-cfg.h +++ b/nvidia-cfg.h @@ -202,6 +202,18 @@ NvCfgBool nvCfgGetDisplayDevices(NvCfgDeviceHandle handle, unsigned int *display_device_mask); + +/* nvCfgGetSupportedDisplayDevices() - get all supported display devices, + * not only connected ones. Interpretation of display_device_mask + * parameter is the same as for nvCfgGetDisplayDevices() call. + * On success, NVCFG_TRUE will be returned and display_device_mask will be + * assigned. On failure, NVCFG_FALSE will be returned. + */ + +NvCfgBool nvCfgGetSupportedDisplayDevices(NvCfgDeviceHandle handle, + unsigned int *display_device_mask); + + /* * nvCfgGetEDIDData() - return an allocated byte array containing the * EDID for the specified display device, if any. On success, diff --git a/nvidia-xconfig.c b/nvidia-xconfig.c index c2d9530..aaada9d 100644 --- a/nvidia-xconfig.c +++ b/nvidia-xconfig.c @@ -654,6 +654,8 @@ Options *parse_commandline(int argc, char *argv[]) } break; + case PRESERVE_DRIVER_NAME_OPTION: op->preserve_driver = TRUE; break; + case DISABLE_SCF_OPTION: op->disable_scf = TRUE; break; case QUERY_GPU_INFO_OPTION: op->query_gpu_info = TRUE; break; @@ -1034,7 +1036,7 @@ static XConfigPtr find_system_xconfig(Options *op) /* Sanitize the X config file */ if (!xconfigSanitizeConfig(config, op->screen, &(op->gop))) { - xconfigFreeConfig(config); + xconfigFreeConfig(&config); return NULL; } diff --git a/nvidia-xconfig.h b/nvidia-xconfig.h index d15c399..a444556 100644 --- a/nvidia-xconfig.h +++ b/nvidia-xconfig.h @@ -77,7 +77,6 @@ typedef struct { #define MULTISAMPLE_COMPATIBILITY_BOOL_OPTION 22 #define XVMC_USES_TEXTURES_BOOL_OPTION 23 #define EXACT_MODE_TIMINGS_DVI_BOOL_OPTION 24 -#define ALLOW_DDCCI_BOOL_OPTION 25 #define LOAD_KERNEL_MODULE_BOOL_OPTION 26 #define ADD_ARGB_GLX_VISUALS_BOOL_OPTION 27 #define COMPOSITE_BOOL_OPTION 28 @@ -91,9 +90,9 @@ typedef struct { #define USE_EVENTS_BOOL_OPTION 36 #define CONNECT_TO_ACPID_BOOL_OPTION 37 #define ENABLE_ACPI_HOTKEYS_BOOL_OPTION 38 +#define MODE_DEBUG_BOOL_OPTION 39 - -#define XCONFIG_BOOL_OPTION_COUNT (ENABLE_ACPI_HOTKEYS_BOOL_OPTION + 1) +#define XCONFIG_BOOL_OPTION_COUNT (MODE_DEBUG_BOOL_OPTION + 1) /* # of 32-bit variables needed to hold all the boolean options (bits) */ #define XCONFIG_BOOL_OPTION_SLOTS \ @@ -129,6 +128,7 @@ typedef struct __options { int only_one_screen; int disable_scf; int query_gpu_info; + int preserve_driver; /* * the option parser will set bits in boolean_options to indicate @@ -259,7 +259,6 @@ int print_tree(Options *op, XConfigPtr config); /* options.c */ -void remove_option_from_list(XConfigOptionPtr *list, const char *name); void set_boolean_option(Options *op, const int c, const int boolval); void validate_composite(Options *op, XConfigPtr config); void update_options(Options *op, XConfigScreenPtr screen); diff --git a/option_table.h b/option_table.h index cca8fc7..6a60ad6 100644 --- a/option_table.h +++ b/option_table.h @@ -44,6 +44,7 @@ #define COOL_BITS_OPTION 33 #define ACPID_SOCKET_PATH_OPTION 34 #define HANDLE_SPECIAL_KEYS_OPTION 35 +#define PRESERVE_DRIVER_NAME_OPTION 36 /* * To add a boolean option to nvidia-xconfig: @@ -134,10 +135,6 @@ static const NVGetoptOption __options[] = { "Enables or disables support for OpenGL rendering into 32-bit ARGB " "windows and pixmaps." }, - { "allow-ddcci", XCONFIG_BOOL_VAL(ALLOW_DDCCI_BOOL_OPTION), - NVGETOPT_IS_BOOLEAN, NULL, "Enables or disables DDC/CI support in the " - "NV-CONTROL X extension." }, - { "allow-dfp-stereo", XCONFIG_BOOL_VAL(ALLOW_DFP_STEREO_BOOL_OPTION), NVGETOPT_IS_BOOLEAN, NULL, "Enable or disable the \"AllowDFPStereo\" X configuration option." }, @@ -224,6 +221,11 @@ static const NVGetoptOption __options[] = { NVGETOPT_IS_BOOLEAN, NULL, "Enable or disable support for dynamically configuring TwinView." }, + { "preserve-driver-name", PRESERVE_DRIVER_NAME_OPTION, 0, NULL, + "By default nvidia-xconfig changes the display driver to \"nvidia\" " + "for all configured X screens; this option preserves the existing driver " + "name of each X screen." }, + { "enable-acpi-hotkeys", XCONFIG_BOOL_VAL(ENABLE_ACPI_HOTKEYS_BOOL_OPTION), NVGETOPT_IS_BOOLEAN, NULL, @@ -335,6 +337,12 @@ static const NVGetoptOption __options[] = { MODE_OPTION, NVGETOPT_IS_BOOLEAN | NVGETOPT_STRING_ARGUMENT, NULL, "Add the specified mode to the mode list." }, + { "mode-debug", XCONFIG_BOOL_VAL(MODE_DEBUG_BOOL_OPTION), + NVGETOPT_IS_BOOLEAN, NULL, + "Enable or disable the \"ModeDebug\" X configuration option; when " + "enabled, this option causes the X driver to print verbose details " + "about mode validation to the X log file." }, + { "mode-list", MODE_LIST_OPTION, NVGETOPT_STRING_ARGUMENT, "MODELIST", "Remove all existing modes from the X configuration's modelist and " "add the one(s) specified in the [MODELIST] string." }, @@ -65,7 +65,6 @@ static const NvidiaXConfigOption __options[] = { { MULTISAMPLE_COMPATIBILITY_BOOL_OPTION, FALSE, "MultisampleCompatibility" }, { XVMC_USES_TEXTURES_BOOL_OPTION, FALSE, "XvmcUsesTextures" }, { EXACT_MODE_TIMINGS_DVI_BOOL_OPTION, FALSE, "ExactModeTimingsDVI" }, - { ALLOW_DDCCI_BOOL_OPTION, FALSE, "AllowDDCCI" }, { LOAD_KERNEL_MODULE_BOOL_OPTION, FALSE, "LoadKernelModule" }, { ADD_ARGB_GLX_VISUALS_BOOL_OPTION, FALSE, "AddARGBGLXVisuals" }, { DISABLE_GLX_ROOT_CLIPPING_BOOL_OPTION, FALSE, "DisableGLXRootClipping" }, @@ -78,6 +77,7 @@ static const NvidiaXConfigOption __options[] = { { USE_EVENTS_BOOL_OPTION, FALSE, "UseEvents" }, { CONNECT_TO_ACPID_BOOL_OPTION, FALSE, "ConnectToAcpid" }, { ENABLE_ACPI_HOTKEYS_BOOL_OPTION, FALSE, "EnableACPIHotkeys" }, + { MODE_DEBUG_BOOL_OPTION, FALSE, "ModeDebug" }, { 0, FALSE, NULL }, }; @@ -102,21 +102,6 @@ static const NvidiaXConfigOption *get_option(const int n) /* - * remove_option_from_list() - remove the option with the given name - * from the list - */ - -void remove_option_from_list(XConfigOptionPtr *list, const char *name) -{ - XConfigOptionPtr opt = xconfigFindOption(*list, name); - if (opt) { - *list = xconfigRemoveOption(*list, opt); - } -} /* remove_option_from_list() */ - - - -/* * set_boolean_option() - set boolean option 'c' to the given 'boolval' */ @@ -252,15 +237,15 @@ static void remove_option(XConfigScreenPtr screen, const char *name) if (!screen) return; if (screen->device) { - remove_option_from_list(&screen->device->options, name); + xconfigRemoveNamedOption(&screen->device->options, name, NULL); } if (screen->monitor) { - remove_option_from_list(&screen->monitor->options, name); + xconfigRemoveNamedOption(&screen->monitor->options, name, NULL); } - remove_option_from_list(&screen->options, name); + xconfigRemoveNamedOption(&screen->options, name, NULL); for (display = screen->displays; display; display = display->next) { - remove_option_from_list(&display->options, name); + xconfigRemoveNamedOption(&display->options, name, NULL); } } /* remove_option() */ @@ -315,7 +300,8 @@ static void set_option_value(XConfigScreenPtr screen, /* then, add the option to the screen's option list */ - screen->options = xconfigAddNewOption(screen->options, name, val); + xconfigAddNewOption(&screen->options, name, val); + } /* set_option_value() */ @@ -505,12 +491,10 @@ static void update_display_options(Options *op, XConfigScreenPtr screen) } for (i = 0; i < op->remove_modes.n; i++) { - display->modes = xconfigRemoveMode(display->modes, - op->remove_modes.t[i]); + xconfigRemoveMode(&display->modes, op->remove_modes.t[i]); } for (i = 0; i < op->add_modes.n; i++) { - display->modes = xconfigAddMode(display->modes, - op->add_modes.t[i]); + xconfigAddMode(&display->modes, op->add_modes.t[i]); } if (op->add_modes_list.n) { int mode_list_size = op->add_modes_list.n; @@ -524,8 +508,8 @@ static void update_display_options(Options *op, XConfigScreenPtr screen) */ for (i = 0; i < op->add_modes_list.n; i++) { - display->modes = xconfigAddMode(display->modes, - op->add_modes_list.t[mode_list_size-i-1]); + xconfigAddMode(&display->modes, + op->add_modes_list.t[mode_list_size-i-1]); } } |