File: params.c

package info (click to toggle)
fookb 2.21-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 360 kB
  • ctags: 49
  • sloc: ansic: 567; makefile: 85; sh: 44
file content (92 lines) | stat: -rw-r--r-- 1,958 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <stdio.h>
#include <string.h>		/* strlen & strcat */
#include <ctype.h>		/* toupper */
#include <stdlib.h>
#ifdef HAVE_LIBPROPLIST
#ifdef HAVE_PROPLIST_H
#define PROPLIST
#endif
#endif
#include "params.h"
#include "opts.h"

char *read_param(string)
char *string;
{

	XrmValue xvalue;

#ifdef HAVE_LIBPROPLIST
#ifdef HAVE_PROPLIST_H
#define PROPLIST
#endif
#endif

#ifdef PROPLIST
	proplist_t pl, value;
#endif

	char *newstring;
	char *newString;
	char *result;
	char *str_type[20];

	newstring = (char *) malloc(7 + strlen(string));	/* 7 is
								   strlen("fookb.") + 1 */
	newString = (char *) malloc(7 + strlen(string));	/* The same */

	strcpy(newstring, "fookb.");
	strcpy(newString, "Fookb.");

	strcat(newstring, string);
	strcat(newString, string);
	newstring[6] = tolower(newstring[6]);
	newString[6] = toupper(newString[6]);

/* Command line parameters take precedence over all */

	if (XrmGetResource(cmdlineDB, newstring, newString, str_type,
			   &xvalue) == True) {
		result = (char *) malloc((int) xvalue.size + 1);
		strncpy(result, xvalue.addr, (int) xvalue.size);
		result[(int) xvalue.size + 1] = '\0';
		return result;
	}
#ifdef PROPLIST

	pl = PLGetProplistWithPath(DEFAULTS_FILE);

	if (!pl) {
		puts("Cannot open config file: ");
		puts(DEFAULTS_FILE);
		exit(20);
	}

	value = PLGetDictionaryEntry(pl, PLMakeString(string));

	if (!value) {
		puts("Cannot find in config file value for: ");
		puts(string);
		exit(21);
	}

	result = (char *) malloc(strlen(PLGetString(value)) + 1);
	strcpy(result, PLGetString(value));
	return result;

#else				/* PROPLIST */

	if (XrmGetResource(finalDB, newstring, newString, str_type,
			   &xvalue) == True) {
		result = (char *) malloc((int) xvalue.size + 1);
		strncpy(result, xvalue.addr, (int) xvalue.size);
		result[(int) xvalue.size + 1] = '\0';
		return result;
	} else {
		printf("Fatal error: cannot find configuration parameter %s\n", newstring);
		exit(25);
	}

#endif

}