Clean a little bit the code.

This commit is contained in:
Tiago Vignatti 2007-08-07 04:22:26 -03:00
parent 7a5eb3e96b
commit d9ee5f3e3a

View File

@ -1105,6 +1105,40 @@ KdRemovePointer (KdPointerInfo *pi)
KdFreePointer(pi); KdFreePointer(pi);
} }
static Bool
KdGetOptions (InputOption **options, char *string)
{
InputOption *newopt = NULL, **tmpo = NULL;
int tam_key = 0;
newopt = (InputOption *) xalloc(sizeof (InputOption));
if (!newopt)
return FALSE;
bzero(newopt, sizeof (InputOption));
for (tmpo = options; *tmpo; tmpo = &(*tmpo)->next)
; /* Hello, I'm here */
*tmpo = newopt;
if (strchr(string, '='))
{
tam_key = (strchr(string, '=') - string);
newopt->key = (char *)xalloc(tam_key);
strncpy(newopt->key, string, tam_key);
newopt->key[tam_key] = '\0';
newopt->value = xstrdup(strchr(string, '=') + 1);
}
else
{
newopt->key = xstrdup(string);
newopt->value = NULL;
}
newopt->next = NULL;
return TRUE;
}
static void static void
KdParseKbdOptions (KdKeyboardInfo *ki) KdParseKbdOptions (KdKeyboardInfo *ki)
{ {
@ -1133,8 +1167,7 @@ KdParseKeyboard (char *arg)
{ {
char save[1024]; char save[1024];
char delim; char delim;
InputOption *options = NULL, *newopt = NULL, **tmpo = NULL; InputOption *options = NULL;
int i = 0;
KdKeyboardInfo *ki = NULL; KdKeyboardInfo *ki = NULL;
ki = KdNewKeyboard(); ki = KdNewKeyboard();
@ -1188,32 +1221,11 @@ KdParseKeyboard (char *arg)
{ {
arg = KdParseFindNext (arg, ",", save, &delim); arg = KdParseFindNext (arg, ",", save, &delim);
newopt = (InputOption *) xalloc(sizeof (InputOption)); if (!KdGetOptions(&options, save))
if (!newopt) {
{ KdFreeKeyboard(ki);
KdFreeKeyboard(ki); return NULL;
return NULL; }
}
bzero(newopt, sizeof (InputOption));
for (tmpo = &options; *tmpo; tmpo = &(*tmpo)->next)
; /* Hello, I'm here */
*tmpo = newopt;
if (strchr(save, '='))
{
i = (strchr(save, '=') - save);
newopt->key = (char *)xalloc(i);
strncpy(newopt->key, save, i);
newopt->key[i] = '\0';
newopt->value = xstrdup(strchr(save, '=') + 1);
}
else
{
newopt->key = xstrdup(save);
newopt->value = NULL;
}
newopt->next = NULL;
} }
if (options) if (options)
@ -1252,7 +1264,7 @@ KdParsePointer (char *arg)
char save[1024]; char save[1024];
char delim; char delim;
KdPointerInfo *pi = NULL; KdPointerInfo *pi = NULL;
InputOption *options = NULL, *newopt = NULL, **tmpo = NULL; InputOption *options = NULL;
int i = 0; int i = 0;
pi = KdNewPointer(); pi = KdNewPointer();
@ -1314,33 +1326,11 @@ KdParsePointer (char *arg)
} }
else else
{ {
newopt = (InputOption *) xalloc(sizeof (InputOption)); if (!KdGetOptions(&options, save))
if (!newopt)
{ {
KdFreePointer(pi); KdFreePointer(pi);
return NULL; return NULL;
} }
bzero(newopt, sizeof (InputOption));
for (tmpo = &options; *tmpo; tmpo = &(*tmpo)->next)
; /* Hello, I'm here */
*tmpo = newopt;
if (strchr(save, '='))
{
i = (strchr(save, '=') - save);
newopt->key = (char *)xalloc(i);
strncpy(newopt->key, save, i);
newopt->key[i] = '\0';
newopt->value = xstrdup(strchr(save, '=') + 1);
}
else
{
newopt->key = xstrdup(save);
newopt->value = NULL;
}
newopt->next = NULL;
} }
} }