1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stddef.h>
4 #include <unistd.h>
5 #include <string.h>
6 #include <sys/stat.h>
7 
8 #include "fbiconfig.h"
9 
10 /* ------------------------------------------------------------------------ */
11 
12 struct cfg_cmdline fbi_cmd[] = {
13     {
14 	.letter   = 'h',
15 	.cmdline  = "help",
16 	.option   = { O_HELP },
17 	.value    = "1",
18 	.desc     = "print this help text",
19     },{
20 	.letter   = 'V',
21 	.cmdline  = "version",
22 	.option   = { O_VERSION },
23 	.value    = "1",
24 	.desc     = "print fbi version number",
25     },{
26 	.letter   = 'i',
27 	.cmdline  = "info",
28 	.option   = { O_DEVICE_INFO },
29 	.value    = "1",
30 	.desc     = "print device info",
31     },{
32 	.cmdline  = "store",
33 	.option   = { O_WRITECONF },
34 	.value    = "1",
35 	.desc     = "write cmd line args to config file",
36     },{
37 	.letter   = 'l',
38 	.cmdline  = "list",
39 	.option   = { O_FILE_LIST },
40 	.needsarg = 1,
41 	.desc     = "read image filelist from file <arg>",
42     },{
43 	.letter   = 'P',
44 	.cmdline  = "text",
45 	.option   = { O_TEXT_MODE },
46 	.value    = "1",
47 	.desc     = "switch into text reading mode",
48     },{
49 	.letter   = 'a',
50 	.cmdline  = "autozoom",
51 	.option   = { O_AUTO_ZOOM },
52 	.value    = "1",
53 	.desc     = "automagically pick useful zoom factor",
54     },{
55 	/* end of list */
56     }
57 };
58 
59 struct cfg_cmdline fbi_cfg[] = {
60     {
61 	.cmdline  = "autoup",
62 	.option   = { O_AUTO_UP },
63 	.yesno    = 1,
64 	.desc     = "  like the above, but upscale only",
65     },{
66 	.cmdline  = "autodown",
67 	.option   = { O_AUTO_DOWN },
68 	.yesno    = 1,
69 	.desc     = "  like the above, but downscale only",
70     },{
71 	.letter   = 'w',
72 	.cmdline  = "fitwidth",
73 	.option   = { O_FIT_WIDTH },
74 	.yesno    = 1,
75 	.desc     = "  use width only for autoscaling",
76 
77     },{
78 	.letter   = 'v',
79 	.cmdline  = "verbose",
80 	.option   = { O_VERBOSE },
81 	.yesno    = 1,
82 	.desc     = "show filenames all the time",
83     },{
84 	.letter   = 'u',
85 	.cmdline  = "random",
86 	.option   = { O_RANDOM },
87 	.yesno    = 1,
88 	.desc     = "show files in a random order",
89     },{
90 	.letter   = '1',
91 	.cmdline  = "once",
92 	.option   = { O_ONCE },
93 	.yesno    = 1,
94 	.desc     = "don't loop (for use with -t)",
95     },{
96 	.cmdline  = "comments",
97 	.option   = { O_COMMENTS },
98 	.yesno    = 1,
99 	.desc     = "display image comments",
100     },{
101 	.letter   = 'e',
102 	.cmdline  = "edit",
103 	.option   = { O_EDIT },
104 	.yesno    = 1,
105 	.desc     = "enable editing commands (see man page)",
106     },{
107 	.cmdline  = "backup",
108 	.option   = { O_BACKUP },
109 	.yesno    = 1,
110 	.desc     = "  create backup files when editing",
111     },{
112 	.cmdline  = "preserve",
113 	.option   = { O_PRESERVE },
114 	.yesno    = 1,
115 	.desc     = "  preserve timestamps when editing",
116     },{
117 	.cmdline  = "readahead",
118 	.option   = { O_READ_AHEAD },
119 	.yesno    = 1,
120 	.desc     = "read ahead images into cache",
121 
122     },{
123 	.cmdline  = "cachemem",
124 	.option   = { O_CACHE_MEM },
125 	.needsarg = 1,
126 	.desc     = "image cache size in megabytes",
127     },{
128 	.cmdline  = "blend",
129 	.option   = { O_BLEND_MSECS },
130 	.needsarg = 1,
131 	.desc     = "image blend time in miliseconds",
132     },{
133 	.letter   = 'T',
134 	.cmdline  = "vt",
135 	.option   = { O_VT },
136 	.needsarg = 1,
137 	.desc     = "start on virtual console <arg>",
138     },{
139 	.letter   = 's',
140 	.cmdline  = "scroll",
141 	.option   = { O_SCROLL },
142 	.needsarg = 1,
143 	.desc     = "scroll image by <arg> pixels",
144     },{
145 	.letter   = 't',
146 	.cmdline  = "timeout",
147 	.option   = { O_TIMEOUT },
148 	.needsarg = 1,
149 	.desc     = "load next image after <arg> sec without user input",
150     },{
151 	.letter   = 'r',
152 	.cmdline  = "resolution",
153 	.option   = { O_PCD_RES },
154 	.needsarg = 1,
155 	.desc     = "pick PhotoCD resolution (1..5)",
156     },{
157 	.letter   = 'f',
158 	.cmdline  = "font",
159 	.option   = { O_FONT },
160 	.needsarg = 1,
161 	.desc     = "use font <arg> (anything fontconfig accepts)",
162     },{
163 	.letter   = 'd',
164 	.cmdline  = "device",
165 	.option   = { O_DEVICE },
166 	.needsarg = 1,
167 	.desc     = "use framebuffer/drm device <arg>",
168     },{
169 	.letter   = 'o',
170 	.cmdline  = "output",
171 	.option   = { O_OUTPUT },
172 	.needsarg = 1,
173 	.desc     = "use drm output <arg> (try -info for a list)",
174     },{
175 	.cmdline  = "interactive",
176 	.option   = { O_INTERACTIVE },
177 	.yesno    = 1,
178 	.desc     = "allow keyboard interaction",
179     },{
180 	.letter   = 'm',
181 	.cmdline  = "mode",
182 	.option   = { O_VIDEO_MODE },
183 	.needsarg = 1,
184 	.desc     = "use video mode <arg> (from /etc/fb.modes)",
185 
186     },{
187 	/* end of list */
188     }
189 };
190 
191 /* ------------------------------------------------------------------------ */
192 
193 struct cfg_cmdline fbpdf_cmd[] = {
194     {
195 	.letter   = 'h',
196 	.cmdline  = "help",
197 	.option   = { O_HELP },
198 	.value    = "1",
199 	.desc     = "print this help text",
200     },{
201 	.letter   = 'V',
202 	.cmdline  = "version",
203 	.option   = { O_VERSION },
204 	.value    = "1",
205 	.desc     = "print fbi version number",
206     },{
207 	.letter   = 'i',
208 	.cmdline  = "info",
209 	.option   = { O_DEVICE_INFO },
210 	.value    = "1",
211 	.desc     = "print device info",
212     },{
213 	.cmdline  = "store",
214 	.option   = { O_WRITECONF },
215 	.value    = "1",
216 	.desc     = "write cmd line args to config file",
217     },{
218 	/* end of list */
219     }
220 };
221 
222 struct cfg_cmdline fbpdf_cfg[] = {
223     {
224 	.letter   = 'w',
225 	.cmdline  = "fitwidth",
226 	.option   = { O_FIT_WIDTH },
227 	.yesno    = 1,
228 	.desc     = "fit page width on screen",
229     },{
230 	.letter   = 'd',
231 	.cmdline  = "device",
232 	.option   = { O_DEVICE },
233 	.needsarg = 1,
234 	.desc     = "use framebuffer/drm device <arg>",
235     },{
236 	.letter   = 'o',
237 	.cmdline  = "output",
238 	.option   = { O_OUTPUT },
239 	.needsarg = 1,
240 	.desc     = "use drm output <arg> (try -info for a list)",
241     },{
242 	.cmdline  = "pageflip",
243 	.option   = { O_PAGEFLIP },
244 	.yesno    = 1,
245 	.desc     = "use pageflip (drm only)",
246 #ifdef HAVE_CAIRO_GL
247     },{
248 	.letter   = 'g',
249 	.cmdline  = "opengl",
250 	.option   = { O_OPENGL },
251 	.yesno    = 1,
252 	.desc     = "use opengl (drm only)",
253 #endif
254     },{
255 	.letter   = 'm',
256 	.cmdline  = "mode",
257 	.option   = { O_VIDEO_MODE },
258 	.needsarg = 1,
259 	.desc     = "use video mode <arg> (from /etc/fb.modes)",
260     },{
261 	/* end of list */
262     }
263 };
264 
265 /* ------------------------------------------------------------------------ */
266 
267 static char *fbi_config = NULL;
268 
init_config(const char * name)269 static void init_config(const char *name)
270 {
271     char *home;
272 
273     home = getenv("HOME");
274     if (NULL == home)
275 	return;
276 
277     fbi_config = malloc(strlen(home) + strlen(name) + 2);
278     sprintf(fbi_config,"%s/%s", home, name);
279 }
280 
fbi_read_config(const char * name)281 void fbi_read_config(const char *name)
282 {
283     init_config(name);
284     if (fbi_config)
285 	cfg_parse_file("config", fbi_config);
286 }
287 
fbi_write_config(void)288 void fbi_write_config(void)
289 {
290     if (fbi_config)
291 	cfg_write_file("config", fbi_config);
292 }
293