diff options
author | Aaron Plattner <aplattner@nvidia.com> | 2008-05-28 10:46:42 -0700 |
---|---|---|
committer | Aaron Plattner <aplattner@nvidia.com> | 2008-05-28 10:46:42 -0700 |
commit | d7ac9f8fb223ae2ec3de4e60705f46258501c35c (patch) | |
tree | 40d5d7a8663ef079911bd4ed60064d6c8a29c0ae | |
parent | aded256a432c5979c9b27c73689bda7e522b3090 (diff) |
-rw-r--r-- | XF86Config-parser/Merge.c | 98 | ||||
-rw-r--r-- | XF86Config-parser/Monitor.c | 17 | ||||
-rw-r--r-- | XF86Config-parser/Scan.c | 1 | ||||
-rw-r--r-- | XF86Config-parser/xf86Parser.h | 2 |
4 files changed, 86 insertions, 32 deletions
diff --git a/XF86Config-parser/Merge.c b/XF86Config-parser/Merge.c index a9f2c97..aaf66bc 100644 --- a/XF86Config-parser/Merge.c +++ b/XF86Config-parser/Merge.c @@ -43,22 +43,30 @@ static void xconfigAddRemovedOptionComment(char **existing_comments, { int len; char *str; + char *name, *value; if (!option || !existing_comments) return; - len = 32 + strlen(xconfigOptionName(option)) + - strlen(xconfigOptionValue(option)); + name = xconfigOptionName(option); + value = xconfigOptionValue(option); - str = (char *)malloc(len); + if (!name) return; - if (str) { - snprintf(str, len, "# Removed Option \"%s\" \"%s\"", - xconfigOptionName(option), - xconfigOptionValue(option)); - *existing_comments = xconfigAddComment(*existing_comments, str); + if (value) { + len = 32 + strlen(name) + strlen(value); + str = malloc(len); + if (!str) return; + snprintf(str, len, "# Removed Option \"%s\" \"%s\"", name, value); + } else { + len = 32 + strlen(name); + str = malloc(len); + if (!str) return; + snprintf(str, len, "# Removed Option \"%s\"", name); } + *existing_comments = xconfigAddComment(*existing_comments, str); + } /* xconfigAddRemovedOptionComment() */ @@ -86,6 +94,36 @@ static void xconfigRemoveNamedOption(XConfigOptionPtr *head, char *name, /* + * xconfigOptionValuesDiffer() - return '1' if the option values for + * option0 and option1 are different; return '0' if the option values + * are the same. + */ + +static int xconfigOptionValuesDiffer(XConfigOptionPtr option0, + XConfigOptionPtr option1) +{ + char *value0, *value1; + + value0 = value1 = NULL; + + if (!option0 && !option1) return 0; + if (!option0 && option1) return 1; + if ( option0 && !option1) return 1; + + value0 = xconfigOptionValue(option0); + value1 = xconfigOptionValue(option1); + + if (!value0 && !value1) return 0; + if (!value0 && value1) return 1; + if ( value0 && !value1) return 1; + + return (strcmp(value0, value1) != 0); + +} /* xconfigOptionValuesDiffer() */ + + + +/* * xconfigMergeOption() - Merge option "name" from option source * list "srcHead" to option destination list "dstHead". * @@ -107,20 +145,35 @@ static void xconfigMergeOption(XConfigOptionPtr *dstHead, { XConfigOptionPtr srcOption = xconfigFindOption(*srcHead, name); XConfigOptionPtr dstOption = xconfigFindOption(*dstHead, name); - - if (!srcOption) { - if (dstOption) { - *dstHead = xconfigRemoveOption(*dstHead, dstOption); - } - } else { - if (!dstOption || strcmp(xconfigOptionValue(srcOption), - xconfigOptionValue(dstOption))) { - if (dstOption && comments) { + char *srcValue = NULL; + + if (srcOption) srcValue = xconfigOptionValue(srcOption); + + if (!srcOption && dstOption) { + + /* option does not exist in src, but exists in dst: remove from dst */ + *dstHead = xconfigRemoveOption(*dstHead, dstOption); + + } else if (srcOption && !dstOption) { + + /* option exists in src but not in dst: add to dst */ + *dstHead = xconfigAddNewOption(*dstHead, name, srcValue); + + } else if (srcOption && dstOption) { + + /* + * option exists in src and in dst; if the option values are + * different, replace the dst's option value with src's option + * value; note that xconfigAddNewOption() will remove the old + * option first, if necessary + */ + + if (xconfigOptionValuesDiffer(srcOption, dstOption)) { + if (comments) { xconfigAddRemovedOptionComment(comments, dstOption); } - *dstHead = xconfigAddNewOption - (*dstHead, name, xconfigOptionValue(srcOption)); + *dstHead = xconfigAddNewOption(*dstHead, name, srcValue); } } @@ -387,13 +440,12 @@ static int xconfigMergeDriverOptions(XConfigScreenPtr dstScreen, XConfigOptionPtr old = xconfigFindOption(dstScreen->options, name); - if (!old || !strcmp(xconfigOptionValue(option), - xconfigOptionValue(old))) { + if (old && xconfigOptionValuesDiffer(option, old)) { xconfigRemoveNamedOption(&(dstScreen->options), name, - NULL); + &(dstScreen->comment)); } else { xconfigRemoveNamedOption(&(dstScreen->options), name, - &(dstScreen->comment)); + NULL); } } diff --git a/XF86Config-parser/Monitor.c b/XF86Config-parser/Monitor.c index e8d8e3c..32080a9 100644 --- a/XF86Config-parser/Monitor.c +++ b/XF86Config-parser/Monitor.c @@ -132,9 +132,9 @@ xconfigParseModeLine (void) ptr->identifier = val.str; /* DotClock */ - if (xconfigGetSubToken (&(ptr->comment)) != NUMBER) + if ((xconfigGetSubToken (&(ptr->comment)) != NUMBER) || !val.str) Error ("ModeLine dotclock expected", NULL); - ptr->clock = (int) (val.realnum * 1000.0 + 0.5); + ptr->clock = xconfigStrdup(val.str); /* HDisplay */ if (xconfigGetSubToken (&(ptr->comment)) != NUMBER) @@ -264,9 +264,9 @@ xconfigParseVerboseMode (void) ptr->comment = xconfigAddComment(ptr->comment, val.str); break; case DOTCLOCK: - if ((token = xconfigGetSubToken (&(ptr->comment))) != NUMBER) + if ((xconfigGetSubToken (&(ptr->comment)) != NUMBER) || !val.str) Error (NUMBER_MSG, "DotClock"); - ptr->clock = (int) (val.realnum * 1000.0 + 0.5); + ptr->clock = xconfigStrdup(val.str); had_dotclock = 1; break; case HTIMINGS: @@ -692,8 +692,8 @@ xconfigPrintMonitorSection (FILE * cf, XConfigMonitorPtr ptr) } for (mlptr = ptr->modelines; mlptr; mlptr = mlptr->next) { - fprintf (cf, " ModeLine \"%s\" %2.1f ", - mlptr->identifier, mlptr->clock / 1000.0); + fprintf (cf, " ModeLine \"%s\" %s ", + mlptr->identifier, mlptr->clock); fprintf (cf, "%d %d %d %d %d %d %d %d", mlptr->hdisplay, mlptr->hsyncstart, mlptr->hsyncend, mlptr->htotal, @@ -743,8 +743,8 @@ xconfigPrintModesSection (FILE * cf, XConfigModesPtr ptr) fprintf (cf, " Identifier \"%s\"\n", ptr->identifier); for (mlptr = ptr->modelines; mlptr; mlptr = mlptr->next) { - fprintf (cf, " ModeLine \"%s\" %2.1f ", - mlptr->identifier, mlptr->clock / 1000.0); + fprintf (cf, " ModeLine \"%s\" %s ", + mlptr->identifier, mlptr->clock); fprintf (cf, "%d %d %d %d %d %d %d %d", mlptr->hdisplay, mlptr->hsyncstart, mlptr->hsyncend, mlptr->htotal, @@ -827,6 +827,7 @@ xconfigFreeModeLineList (XConfigModeLinePtr ptr) { TEST_FREE (ptr->identifier); TEST_FREE (ptr->comment); + TEST_FREE (ptr->clock); prev = ptr; ptr = ptr->next; free (prev); diff --git a/XF86Config-parser/Scan.c b/XF86Config-parser/Scan.c index 22b6557..d0a4258 100644 --- a/XF86Config-parser/Scan.c +++ b/XF86Config-parser/Scan.c @@ -422,6 +422,7 @@ again: configRBuf[i] = '\0'; val.num = xconfigStrToUL (configRBuf); val.realnum = atof (configRBuf); + val.str = configRBuf; return (NUMBER); } diff --git a/XF86Config-parser/xf86Parser.h b/XF86Config-parser/xf86Parser.h index c81574c..6598d5e 100644 --- a/XF86Config-parser/xf86Parser.h +++ b/XF86Config-parser/xf86Parser.h @@ -216,7 +216,7 @@ typedef struct { typedef struct __xconfigconfmodelinerec { struct __xconfigconfmodelinerec *next; char *identifier; - int clock; + char *clock; /* stored in MHz */ int hdisplay; int hsyncstart; int hsyncend; |