summaryrefslogtreecommitdiff
path: root/XF86Config-parser
diff options
context:
space:
mode:
authorAaron Plattner <aplattner@nvidia.com>2008-02-13 10:26:53 -0800
committerAaron Plattner <aplattner@nvidia.com>2008-02-13 10:26:53 -0800
commitb03157d67b34e51465b788d38c1a9a0ce97a8637 (patch)
tree9d6f34390e0faa0f58c8081b9a189bf1d24641f6 /XF86Config-parser
parent9544a6e9c1e4faf27a28ca7d8fb1425a570befe1 (diff)
169.04169.04
Diffstat (limited to 'XF86Config-parser')
-rw-r--r--XF86Config-parser/Flags.c82
-rw-r--r--XF86Config-parser/Generate.c35
-rw-r--r--XF86Config-parser/Input.c33
-rw-r--r--XF86Config-parser/Merge.c16
-rw-r--r--XF86Config-parser/Pointer.c50
-rw-r--r--XF86Config-parser/xf86Parser.h7
6 files changed, 71 insertions, 152 deletions
diff --git a/XF86Config-parser/Flags.c b/XF86Config-parser/Flags.c
index 21413c9..b86b7a4 100644
--- a/XF86Config-parser/Flags.c
+++ b/XF86Config-parser/Flags.c
@@ -123,30 +123,26 @@ xconfigParseFlagsSection (void)
int i = 0;
while (ServerFlagsTab[i].token != -1)
{
- char *tmp;
-
if (ServerFlagsTab[i].token == token)
{
+ char buff[16];
char *valstr = NULL;
- /* can't use strdup because it calls malloc */
- tmp = xconfigStrdup (ServerFlagsTab[i].name);
if (hasvalue)
{
tokentype = xconfigGetSubToken(&(ptr->comment));
if (strvalue) {
if (tokentype != STRING)
- Error (QUOTE_MSG, tmp);
+ Error (QUOTE_MSG, ServerFlagsTab[i].name);
valstr = val.str;
} else {
if (tokentype != NUMBER)
- Error (NUMBER_MSG, tmp);
- valstr = malloc(16);
- if (valstr)
- sprintf(valstr, "%d", val.num);
+ Error (NUMBER_MSG, ServerFlagsTab[i].name);
+ snprintf(buff, 16, "%d", val.num);
+ valstr = buff;
}
}
ptr->options = xconfigAddNewOption
- (ptr->options, tmp, valstr);
+ (ptr->options, ServerFlagsTab[i].name, valstr);
}
i++;
}
@@ -185,8 +181,8 @@ xconfigPrintServerFlagsSection (FILE * f, XConfigFlagsPtr flags)
fprintf (f, "EndSection\n\n");
}
-static XConfigOptionPtr
-addNewOption2 (XConfigOptionPtr head, char *name, char *val, int used)
+XConfigOptionPtr
+xconfigAddNewOption (XConfigOptionPtr head, const char *name, const char *val)
{
XConfigOptionPtr new, old = NULL;
@@ -196,12 +192,11 @@ addNewOption2 (XConfigOptionPtr head, char *name, char *val, int used)
TEST_FREE(old->val);
new = old;
} else {
- new = calloc (1, sizeof (XConfigOptionRec));
+ new = calloc(1, sizeof (XConfigOptionRec));
new->next = NULL;
}
- new->name = name;
- new->val = val;
- new->used = used;
+ new->name = xconfigStrdup(name);
+ new->val = xconfigStrdup(val);
if (old == NULL)
return ((XConfigOptionPtr) xconfigAddListItem ((GenericListPtr) head,
@@ -210,12 +205,6 @@ addNewOption2 (XConfigOptionPtr head, char *name, char *val, int used)
return head;
}
-XConfigOptionPtr
-xconfigAddNewOption (XConfigOptionPtr head, char *name, char *val)
-{
- return addNewOption2(head, name, val, 0);
-}
-
void
xconfigFreeFlags (XConfigFlagsPtr flags)
{
@@ -233,11 +222,8 @@ xconfigOptionListDup (XConfigOptionPtr opt)
while (opt)
{
- newopt = xconfigAddNewOption(newopt, xconfigStrdup(opt->name),
- xconfigStrdup(opt->val));
- newopt->used = opt->used;
- if (opt->comment)
- newopt->comment = xconfigStrdup(opt->comment);
+ newopt = xconfigAddNewOption(newopt, opt->name, opt->val);
+ newopt->comment = xconfigStrdup(opt->comment);
opt = opt->next;
}
return newopt;
@@ -276,7 +262,7 @@ xconfigOptionValue(XConfigOptionPtr opt)
}
XConfigOptionPtr
-xconfigNewOption(char *name, char *value)
+xconfigNewOption(const char *name, const char *value)
{
XConfigOptionPtr opt;
@@ -284,10 +270,9 @@ xconfigNewOption(char *name, char *value)
if (!opt)
return NULL;
- opt->used = 0;
- opt->next = 0;
- opt->name = name;
- opt->val = value;
+ opt->name = xconfigStrdup(name);
+ opt->val = xconfigStrdup(value);
+ opt->next = NULL;
return opt;
}
@@ -388,39 +373,6 @@ xconfigFindOptionBoolean (XConfigOptionPtr list, const char *name)
return 0;
}
-XConfigOptionPtr
-xconfigOptionListCreate( const char **options, int count, int used )
-{
- XConfigOptionPtr p = NULL;
- char *t1, *t2;
- int i;
-
- if (count == -1)
- {
- for (count = 0; options[count]; count++)
- ;
- }
- if( (count % 2) != 0 )
- {
- xconfigErrorMsg(InternalErrorMsg, "xconfigOptionListCreate: count must "
- "be an even number.\n");
- return (NULL);
- }
- for (i = 0; i < count; i += 2)
- {
- /* can't use strdup because it calls malloc */
- t1 = malloc (sizeof (char) *
- (strlen (options[i]) + 1));
- strcpy (t1, options[i]);
- t2 = malloc (sizeof (char) *
- (strlen (options[i + 1]) + 1));
- strcpy (t2, options[i + 1]);
- p = addNewOption2 (p, t1, t2, used);
- }
-
- return (p);
-}
-
/* the 2 given lists are merged. If an option with the same name is present in
* both, the option from the user list - specified in the second argument -
* is used. The end result is a single valid list of options. Duplicates
diff --git a/XF86Config-parser/Generate.c b/XF86Config-parser/Generate.c
index 008730a..0b6c9bd 100644
--- a/XF86Config-parser/Generate.c
+++ b/XF86Config-parser/Generate.c
@@ -450,7 +450,7 @@ XConfigMonitorPtr xconfigAddMonitor(XConfigPtr config, int count)
monitor->vrefresh[0].lo = 50.0;
monitor->vrefresh[0].hi = 150.0;
- opt = xconfigAddNewOption(opt, xconfigStrdup("DPMS"), NULL);
+ opt = xconfigAddNewOption(opt, "DPMS", NULL);
monitor->options = opt;
@@ -584,7 +584,7 @@ static void add_inputref(XConfigPtr config, XConfigLayoutPtr layout,
inputRef->input_name = xconfigStrdup(name);
inputRef->input = xconfigFindInput(inputRef->input_name, config->inputs);
inputRef->options =
- xconfigAddNewOption(NULL, xconfigStrdup(coreKeyword), NULL);
+ xconfigAddNewOption(NULL, coreKeyword, NULL);
inputRef->next = layout->inputs;
layout->inputs = inputRef;
@@ -1032,20 +1032,19 @@ int xconfigAddMouse(GenerateOptions *gop, XConfigPtr config)
device_path = xconfigStrcat("/dev/", entry->device, NULL);
- opt = xconfigAddNewOption(opt, xconfigStrdup("Protocol"),
- xconfigStrdup(entry->Xproto));
- opt = xconfigAddNewOption(opt, xconfigStrdup("Device"), device_path);
- opt = xconfigAddNewOption(opt, xconfigStrdup("Emulate3Buttons"),
- entry->emulate3 ?
- xconfigStrdup("yes") : xconfigStrdup("no"));
+ opt = xconfigAddNewOption(opt, "Protocol", entry->Xproto);
+ opt = xconfigAddNewOption(opt, "Device", device_path);
+ opt = xconfigAddNewOption(opt, "Emulate3Buttons",
+ (entry->emulate3 ? "yes" : "no"));
+ TEST_FREE(device_path);
+
/*
* This will make wheel mice work, and non-wheel mice should
* ignore ZAxisMapping
*/
- opt = xconfigAddNewOption(opt, xconfigStrdup("ZAxisMapping"),
- xconfigStrdup("4 5"));
+ opt = xconfigAddNewOption(opt, "ZAxisMapping", "4 5");
input->options = opt;
@@ -1299,21 +1298,13 @@ int xconfigAddKeyboard(GenerateOptions *gop, XConfigPtr config)
*/
if (entry && entry->layout)
- opt = xconfigAddNewOption(opt,
- xconfigStrdup("XkbLayout"),
- xconfigStrdup(entry->layout));
+ opt = xconfigAddNewOption(opt, "XkbLayout", entry->layout);
if (entry && entry->model)
- opt = xconfigAddNewOption(opt,
- xconfigStrdup("XkbModel"),
- xconfigStrdup(entry->model));
+ opt = xconfigAddNewOption(opt, "XkbModel", entry->model);
if (entry && entry->variant)
- opt = xconfigAddNewOption(opt,
- xconfigStrdup("XkbVariant"),
- xconfigStrdup(entry->variant));
+ opt = xconfigAddNewOption(opt, "XkbVariant", entry->variant);
if (entry && entry->options)
- opt = xconfigAddNewOption(opt,
- xconfigStrdup("XkbOptions"),
- xconfigStrdup(entry->options));
+ opt = xconfigAddNewOption(opt, "XkbOptions", entry->options);
input->options = opt;
diff --git a/XF86Config-parser/Input.c b/XF86Config-parser/Input.c
index 1665600..4b660f6 100644
--- a/XF86Config-parser/Input.c
+++ b/XF86Config-parser/Input.c
@@ -239,9 +239,9 @@ static int getCoreInputDevice(GenerateOptions *gop,
opt2 = xconfigFindOption(inputRef->options, coreKeyword);
if (opt1 || opt2) {
- if (!core) {
- core = input;
- } else {
+ if (!core) {
+ core = input;
+ } else {
if (opt1) input->options =
xconfigRemoveOption(input->options, opt1);
if (opt2) inputRef->options =
@@ -265,13 +265,13 @@ static int getCoreInputDevice(GenerateOptions *gop,
*/
if (!core) {
- for (input = config->inputs; input; input = input->next) {
- if (xconfigFindOption(input->options, coreKeyword)) {
+ for (input = config->inputs; input; input = input->next) {
+ if (xconfigFindOption(input->options, coreKeyword)) {
core = input;
found_msg = foundMsg0;
break;
- }
- }
+ }
+ }
}
/*
@@ -285,16 +285,16 @@ static int getCoreInputDevice(GenerateOptions *gop,
if (!core) {
input = xconfigFindInput(implicitDriverName, config->inputs);
- if (!input && defaultDriver0) {
- input = xconfigFindInputByDriver(defaultDriver0, config->inputs);
- }
+ if (!input && defaultDriver0) {
+ input = xconfigFindInputByDriver(defaultDriver0, config->inputs);
+ }
if (!input && defaultDriver1) {
- input = xconfigFindInputByDriver(defaultDriver1, config->inputs);
+ input = xconfigFindInputByDriver(defaultDriver1, config->inputs);
+ }
+ if (input) {
+ core = input;
+ found_msg = foundMsg1;
}
- if (input) {
- core = input;
- found_msg = foundMsg1;
- }
}
/*
@@ -368,8 +368,7 @@ static int getCoreInputDevice(GenerateOptions *gop,
if (!opt1 && !opt2) {
inputRef->options = xconfigAddNewOption(inputRef->options,
- strdup(coreKeyword),
- NULL);
+ coreKeyword, NULL);
}
break;
}
diff --git a/XF86Config-parser/Merge.c b/XF86Config-parser/Merge.c
index 2931934..a9f2c97 100644
--- a/XF86Config-parser/Merge.c
+++ b/XF86Config-parser/Merge.c
@@ -120,8 +120,7 @@ static void xconfigMergeOption(XConfigOptionPtr *dstHead,
xconfigAddRemovedOptionComment(comments, dstOption);
}
*dstHead = xconfigAddNewOption
- (*dstHead, xconfigStrdup(name),
- xconfigStrdup(xconfigOptionValue(srcOption)));
+ (*dstHead, name, xconfigOptionValue(srcOption));
}
}
@@ -402,8 +401,7 @@ static int xconfigMergeDriverOptions(XConfigScreenPtr dstScreen,
dstScreen->options =
xconfigAddNewOption(dstScreen->options,
- xconfigStrdup(name),
- xconfigStrdup(xconfigOptionValue(option)));
+ name, xconfigOptionValue(option));
option = option->next;
}
@@ -424,7 +422,6 @@ static int xconfigMergeDisplays(XConfigScreenPtr dstScreen,
{
XConfigDisplayPtr dstDisplay;
XConfigDisplayPtr srcDisplay;
- XConfigOptionPtr srcOption;
XConfigModePtr srcMode, dstMode, lastDstMode;
/* Free all the displays in the destination screen */
@@ -458,14 +455,7 @@ static int xconfigMergeDisplays(XConfigScreenPtr dstScreen,
/* Copy options over */
- srcOption = srcDisplay->options;
- while (srcOption) {
- xconfigMergeOption(&(dstDisplay->options),
- &(srcDisplay->options),
- xconfigOptionName(srcOption),
- NULL);
- srcOption = srcOption->next;
- }
+ dstDisplay->options = xconfigOptionListDup(srcDisplay->options);
/* Copy modes over */
diff --git a/XF86Config-parser/Pointer.c b/XF86Config-parser/Pointer.c
index d1e282a..ed49669 100644
--- a/XF86Config-parser/Pointer.c
+++ b/XF86Config-parser/Pointer.c
@@ -111,76 +111,68 @@ xconfigParsePointerSection (void)
if (xconfigGetSubToken (&(ptr->comment)) != STRING)
Error (QUOTE_MSG, "Protocol");
ptr->options = xconfigAddNewOption(ptr->options,
- xconfigStrdup("Protocol"),
- val.str);
+ "Protocol", val.str);
break;
case PDEVICE:
if (xconfigGetSubToken (&(ptr->comment)) != STRING)
Error (QUOTE_MSG, "Device");
ptr->options = xconfigAddNewOption(ptr->options,
- xconfigStrdup("Device"),
- val.str);
+ "Device", val.str);
break;
case EMULATE3:
ptr->options =
- xconfigAddNewOption(ptr->options,
- xconfigStrdup("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,
- xconfigStrdup("Emulate3Timeout"),
- s);
+ xconfigAddNewOption(ptr->options, "Emulate3Timeout", s);
+ TEST_FREE(s);
break;
case CHORDMIDDLE:
- ptr->options = xconfigAddNewOption(ptr->options,
- xconfigStrdup("ChordMiddle"),
- NULL);
+ ptr->options = 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,
- xconfigStrdup("Buttons"), s);
+ ptr->options = 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,
- xconfigStrdup("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,
- xconfigStrdup("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,
- xconfigStrdup("Resolution"), s);
+ xconfigAddNewOption(ptr->options, "Resolution", s);
+ TEST_FREE(s);
break;
case CLEARDTR:
ptr->options =
- xconfigAddNewOption(ptr->options,
- xconfigStrdup("ClearDTR"), NULL);
+ xconfigAddNewOption(ptr->options, "ClearDTR", NULL);
break;
case CLEARRTS:
ptr->options =
- xconfigAddNewOption(ptr->options,
- xconfigStrdup("ClearRTS"), NULL);
+ xconfigAddNewOption(ptr->options, "ClearRTS", NULL);
break;
case ZAXISMAPPING:
switch (xconfigGetToken(ZMapTab)) {
@@ -209,9 +201,8 @@ xconfigParsePointerSection (void)
break;
}
ptr->options =
- xconfigAddNewOption(ptr->options,
- xconfigStrdup("ZAxisMapping"),
- s);
+ xconfigAddNewOption(ptr->options, "ZAxisMapping", s);
+ TEST_FREE(s);
break;
case ALWAYSCORE:
break;
@@ -226,8 +217,7 @@ xconfigParsePointerSection (void)
ptr->identifier = xconfigStrdup(CONF_IMPLICIT_POINTER);
ptr->driver = xconfigStrdup("mouse");
- ptr->options = xconfigAddNewOption(ptr->options,
- xconfigStrdup("CorePointer"), NULL);
+ ptr->options = xconfigAddNewOption(ptr->options, "CorePointer", NULL);
return ptr;
}
diff --git a/XF86Config-parser/xf86Parser.h b/XF86Config-parser/xf86Parser.h
index 7013b9b..c81574c 100644
--- a/XF86Config-parser/xf86Parser.h
+++ b/XF86Config-parser/xf86Parser.h
@@ -148,7 +148,6 @@ typedef struct __xconfigoptionrec {
struct __xconfigoptionrec *next;
char *name;
char *val;
- int used;
char *comment;
} XConfigOptionRec, *XConfigOptionPtr;
@@ -675,22 +674,20 @@ XConfigLoadPtr xconfigRemoveLoadDirective(XConfigLoadPtr head,
*/
XConfigOptionPtr xconfigAddNewOption(XConfigOptionPtr head,
- char *name, char *val);
+ const char *name, const char *val);
XConfigOptionPtr xconfigRemoveOption(XConfigOptionPtr list,
XConfigOptionPtr opt);
XConfigOptionPtr xconfigOptionListDup(XConfigOptionPtr opt);
void xconfigOptionListFree(XConfigOptionPtr opt);
char *xconfigOptionName(XConfigOptionPtr opt);
char *xconfigOptionValue(XConfigOptionPtr opt);
-XConfigOptionPtr xconfigNewOption(char *name, char *value);
+XConfigOptionPtr xconfigNewOption(const char *name, const char *value);
XConfigOptionPtr xconfigNextOption(XConfigOptionPtr list);
XConfigOptionPtr xconfigFindOption(XConfigOptionPtr list, const char *name);
char *xconfigFindOptionValue(XConfigOptionPtr list,
const char *name);
int xconfigFindOptionBoolean (XConfigOptionPtr,
const char *name);
-XConfigOptionPtr xconfigOptionListCreate(const char **options,
- int count, int used);
XConfigOptionPtr xconfigOptionListMerge(XConfigOptionPtr head,
XConfigOptionPtr tail);