65 lines
1.4 KiB
C
65 lines
1.4 KiB
C
#include <stdio.h>
|
|
#include <string.h> /* strlen & strcat */
|
|
#include <ctype.h> /* toupper */
|
|
#include <stdlib.h>
|
|
#include "params.h"
|
|
#include "opts.h"
|
|
|
|
/* Let's make lint happy */
|
|
#define lputs(x) (void)puts(x)
|
|
|
|
char *read_param(char *string)
|
|
{
|
|
XrmValue xvalue;
|
|
|
|
char *newstring;
|
|
char *newString;
|
|
char *result;
|
|
char *str_type[20];
|
|
|
|
/* Let's make lint happy */
|
|
xvalue.size = 0;
|
|
|
|
newstring = (char *) malloc(7 + strlen(string));
|
|
newString = (char *) malloc(7 + strlen(string));
|
|
/* 7 is strlen("fookb.") + 1 */
|
|
|
|
if ((NULL == newstring) || (NULL == newString)) {
|
|
lputs("Not enough memory");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
strcpy(newstring, "fookb.");
|
|
strcpy(newString, "Fookb.");
|
|
|
|
strcat(newstring, string);
|
|
strcat(newString, string);
|
|
newstring[6] = tolower((unsigned char)newstring[6]);
|
|
newString[6] = toupper((unsigned char)newString[6]);
|
|
|
|
/* Command line parameters take precedence over all */
|
|
|
|
if (XrmGetResource(cmdlineDB,
|
|
newstring,
|
|
newString,
|
|
str_type,
|
|
&xvalue) == True) {
|
|
result = (char *) malloc(xvalue.size + 1);
|
|
if (NULL == result) {
|
|
lputs("Not enough memory");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
strncpy(result, xvalue.addr, (size_t)xvalue.size);
|
|
result[(int) xvalue.size + 1] = '\0';
|
|
|
|
free(newstring);
|
|
free(newString);
|
|
return result;
|
|
} else {
|
|
(void)printf("Fatal error: cannot find configuration parameter %s\n",
|
|
newstring);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
}
|