Fix two bugs related to command execution:
[dockapps.git] / wmweather+ / wmgeneral / rcfile.c
blobeb1b058bfa5acc0ee4ec6f5264f65905d9445aec
1 #include "../config.h"
3 /*
4 Best viewed with vim5, using ts=4
6 wmgeneral was taken from wmppp.
8 It has a lot of routines which most of the wm* programs use.
10 ------------------------------------------------------------
12 Author: Martijn Pieterse (pieterse@xs4all.nl)
14 ---
15 CHANGES:
16 ---
17 11/08/2002 (Brad Jorsch, anomie@users.sourceforge.net)
18 * Moved all the rc-file related stuff to rcfile.[ch]
20 28/08/2001 (Brad Jorsch, anomie@users.sourceforge.net)
21 * Added EnableMouseRegion and DisableMouseRegion
22 * Got annoyed with the 81-character lines. Fixed it. If you don't like
23 it, find a different copy of wmgeneral.c ;)
24 * GraphicsExpose events are enabled here.
25 * GetXPM is exported. It optionally takes an XpmColorSymbol array.
26 * GetColor is exported.
28 30/09/2000 (Brad Jorsch, anomie@users.sourceforge.net)
29 * You know, wmgen.mask sounds like a much nicer place to store the
30 mask... why don't we do that?
32 21/09/1999 (Brad Jorsch, anomie@users.sourceforge.net)
33 * Changed openXwindow to use only the filename, sans path,
34 as the name and class properties of the app.
36 14/09/1998 (Dave Clark, clarkd@skyia.com)
37 * Updated createXBMfromXPM routine
38 * Now supports >256 colors
39 11/09/1998 (Martijn Pieterse, pieterse@xs4all.nl)
40 * Removed a bug from parse_rcfile. You could
41 not use "start" in a command if a label was
42 also start.
43 * Changed the needed geometry string.
44 We don't use window size, and don't support
45 negative positions.
46 03/09/1998 (Martijn Pieterse, pieterse@xs4all.nl)
47 * Added parse_rcfile2
48 02/09/1998 (Martijn Pieterse, pieterse@xs4all.nl)
49 * Added -geometry support (untested)
50 28/08/1998 (Martijn Pieterse, pieterse@xs4all.nl)
51 * Added createXBMfromXPM routine
52 * Saves a lot of work with changing xpm's.
53 02/05/1998 (Martijn Pieterse, pieterse@xs4all.nl)
54 * changed the read_rc_file to parse_rcfile, as suggested by Marcelo E. Magallon
55 * debugged the parse_rc file.
56 30/04/1998 (Martijn Pieterse, pieterse@xs4all.nl)
57 * Ripped similar code from all the wm* programs,
58 and put them in a single file.
62 #include <stdio.h>
63 #include <string.h>
64 #include <stdlib.h>
66 #include "rcfile.h"
68 /******************************************************************************\
69 |* parse_rcfile *|
70 \******************************************************************************/
72 void parse_rcfile(const char *filename, rckeys *keys) {
74 char *p,*q;
75 char temp[128];
76 char *tokens = " :\t\n";
77 FILE *fp;
78 int i,key;
80 fp = fopen(filename, "r");
81 if (fp) {
82 while (fgets(temp, 128, fp)) {
83 key = 0;
84 q = strdup(temp);
85 q = strtok(q, tokens);
86 while (key >= 0 && keys[key].label) {
87 if ((!strcmp(q, keys[key].label))) {
88 p = strstr(temp, keys[key].label);
89 p += strlen(keys[key].label);
90 p += strspn(p, tokens);
91 if ((i = strcspn(p, "#\n"))) p[i] = 0;
92 free(*keys[key].var);
93 *keys[key].var = strdup(p);
94 key = -1;
95 } else key++;
97 free(q);
99 fclose(fp);
103 /******************************************************************************\
104 |* parse_rcfile2 *|
105 \******************************************************************************/
107 void parse_rcfile2(const char *filename, rckeys2 *keys) {
109 char *p;
110 char temp[128];
111 char *tokens = " :\t\n";
112 FILE *fp;
113 int i,key;
114 char *family = NULL;
116 fp = fopen(filename, "r");
117 if (fp) {
118 while (fgets(temp, 128, fp)) {
119 key = 0;
120 while (key >= 0 && keys[key].label) {
121 if ((p = strstr(temp, keys[key].label))) {
122 p += strlen(keys[key].label);
123 p += strspn(p, tokens);
124 if ((i = strcspn(p, "#\n"))) p[i] = 0;
125 free(*keys[key].var);
126 *keys[key].var = strdup(p);
127 key = -1;
128 } else key++;
131 fclose(fp);
133 free(family);