1 /* trivoptions.c - loads some trivial options from the ini file
2    Copyright (C) 1996-2017 Paul Sheer
3 
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 2 of the License, or
7    (at your option) any later version.
8 
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13 
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software
16    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17    02111-1307, USA.
18  */
19 
20 #include <config.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <my_string.h>
24 #include <stringtools.h>
25 #include <mad.h>
26 
27 #define OPTIONS_FILE "/.cedit/.cooledit.ini"
28 
29 extern int option_tab_spacing ;
30 extern int option_fill_tabs_with_spaces;
31 
32 extern int option_editor_fg_normal;
33 extern int option_editor_fg_bold;
34 extern int option_editor_fg_italic;
35 extern int option_editor_bg_normal;
36 extern int option_editor_bg_marked;
37 extern int option_editor_bg_highlighted;
38 
39 extern int option_text_fg_normal;
40 extern int option_text_fg_bold;
41 extern int option_text_fg_italic;
42 extern int option_text_bg_normal;
43 extern int option_text_bg_marked;
44 extern int option_text_bg_highlighted;
45 extern int option_toolhint_milliseconds;
46 
47 extern char *init_look;
48 
49 struct options_struct {
50     char *text;
51     int *value;
52 } options[] =
53 {
54 	{"\noption_tab_spacing = ", &option_tab_spacing},
55 	{"\noption_fill_tabs_with_spaces = ", &option_fill_tabs_with_spaces},
56 	{"\noption_text_fg_normal = ", &option_text_fg_normal},
57 	{"\noption_text_fg_bold = ", &option_text_fg_bold},
58 	{"\noption_text_fg_italic = ", &option_text_fg_italic},
59 	{"\noption_text_bg_normal = ", &option_text_bg_normal},
60 	{"\noption_text_bg_marked = ", &option_text_bg_marked},
61 	{"\noption_text_bg_highlighted = ", &option_text_bg_highlighted},
62 	{"\noption_toolhint_milliseconds = ", &option_toolhint_milliseconds}
63 };
64 
65 char *loadfile (const char *filename, long *filelen);
66 
load_trivial_options(void)67 void load_trivial_options (void)
68 {
69     char *f, *s, *e, *p;
70     int i;
71     f = loadfile (catstrs (getenv ("HOME"), OPTIONS_FILE, NULL), 0);
72     if (!f)
73 	return;
74     s = strstr (f, "[Options]\n");
75     if (!s)
76 	return;
77     e = strstr (f, "\n\n[");
78     if (e)
79 	*e = '\0';
80     for (i = 0; i < sizeof (options) / sizeof (struct options_struct); i++) {
81 	p = strstr (s, options[i].text);
82 	if (!p)
83 	    continue;
84 	p += strlen (options[i].text);
85 	*(options[i].value) = atoi (p);
86     }
87     p = strstr (s, "\noption_look = ");
88     if (p) {
89 	int l;
90 	p += strlen ("\noption_look = ");
91 	l = strcspn (p, "\n");
92 	strncpy (init_look = (char *) malloc (l + 1), p, l);
93 	init_look[l] = '\0';
94     }
95     free (f);
96 
97 #ifndef NEXT_LOOK
98     option_editor_fg_normal = option_text_fg_normal;
99     option_editor_fg_bold = option_text_fg_bold;
100     option_editor_fg_italic = option_text_fg_italic;
101     option_editor_bg_normal = option_text_bg_normal;
102     option_editor_bg_marked = option_text_bg_marked;
103     option_editor_bg_highlighted = option_text_bg_highlighted;
104 #endif
105 }
106 
107