|
|
1.1 root 1: /*
2: * UAE - The Un*x Amiga Emulator
3: *
4: * Config file handling
5: * This still needs some thought before it's complete...
6: *
7: * Copyright 1998 Brian King, Bernd Schmidt
8: */
9:
10: #include "sysconfig.h"
11: #include "sysdeps.h"
12:
13: #include <ctype.h>
14:
15: #include "config.h"
16: #include "options.h"
17: #include "threaddep/penguin.h"
18: #include "uae.h"
19: #include "autoconf.h"
1.1.1.3 ! root 20: #include "custom.h"
1.1 root 21:
22: /* @@@ need to get rid of this... just cut part of the manual and print that
23: * as a help text. */
24: struct cfg_lines
25: {
26: const char *config_label, *config_help;
27: };
28:
29: static struct cfg_lines opttable[] =
30: {
31: {"help", "Prints this help" },
32: {"config_description", "" },
33: {"use_gui", "Enable the GUI? If no, then goes straight to emulator" },
34: {"use_debugger", "Enable the debugger?" },
35: {"cpu_speed", "can be max, real, or a number between 1 and 20" },
36: {"cpu_type", "Can be 68000, 68010, 68020, 68020/68881" },
37: {"cpu_compatible", "yes enables compatibility-mode" },
38: {"cpu_24bit_addressing", "must be set to 'no' in order for Z3mem or P96mem to work" },
39: {"autoconfig", "yes = add filesystems and extra ram" },
40: {"accuracy", "emulation accuracy, default is 2" },
41: {"log_illegal_mem", "print illegal memory access by Amiga software?" },
42: {"fastmem_size", "Size in megabytes of fast-memory" },
43: {"chipmem_size", "Size in megabytes of chip-memory" },
44: {"bogomem_size", "Size in megabytes of bogo-memory at 0xC00000" },
45: {"a3000mem_size", "Size in megabytes of A3000 memory" },
46: {"gfxcard_size", "Size in megabytes of Picasso96 graphics-card memory" },
47: {"z3mem_size", "Size in megabytes of Zorro-III expansion memory" },
48: {"gfx_test_speed", "Test graphics speed?" },
49: {"framerate", "Print every nth frame" },
50: {"gfx_width", "Screen width" },
51: {"gfx_height", "Screen height" },
52: {"gfx_lores", "Treat display as lo-res?" },
53: {"gfx_linemode", "Can be none, double, or scanlines" },
54: {"gfx_fullscreen_amiga", "Amiga screens are fullscreen?" },
55: {"gfx_fullscreen_picasso", "Picasso screens are fullscreen?" },
56: {"gfx_correct_aspect", "Correct aspect ratio?" },
57: {"gfx_center_horizontal", "Center display horizontally?" },
58: {"gfx_center_vertical", "Center display vertically?" },
59: {"gfx_colour_mode", "" },
60: {"32bit_blits", "Enable 32 bit blitter emulation" },
61: {"immediate_blits", "Perform blits immediately" },
62: {"gfxlib_replacement", "Use graphics.library replacement?" },
63: {"sound_output", "" },
64: {"sound_frequency", "" },
65: {"sound_bits", "" },
66: {"sound_channels", "" },
67: {"sound_min_buff", "" },
68: {"sound_max_buff", "" },
69: {"parallel_on_demand", "" },
70: {"serial_on_demand", "" },
71: {"joyport0", "" },
72: {"joyport1", "" },
73: {"kickstart_rom_file", "Kickstart ROM image, (C) Copyright Amiga, Inc." },
74: {"kickstart_key_file", "Key-file for encrypted ROM images (from Cloanto's Amiga Forever)" },
75: {"floppy0", "Diskfile for drive 0" },
76: {"floppy1", "Diskfile for drive 1" },
77: {"floppy2", "Diskfile for drive 2" },
78: {"floppy3", "Diskfile for drive 3" },
79: {"hardfile", "access,sectors, surfaces, reserved, blocksize, path format" },
80: {"filesystem", "access,'Amiga volume-name':'host directory path' - where 'access' can be 'read-only' or 'read-write'" }
81: };
82:
1.1.1.3 ! root 83: static const char *csmode[] = { "ocs", "ecs_agnus", "ecs_denise", "ecs", "aga" };
1.1 root 84: static const char *linemode1[] = { "none", "double", "scanlines", 0 };
85: static const char *linemode2[] = { "n", "d", "s", 0 };
86: static const char *speedmode[] = { "max", "real", 0 };
87: static const char *cpumode[] = { "68000", "68000", "68010", "68010",
88: "68ec020", "68020", "68ec020/68881", "68020/68881", 0 };
89: static const char *portmode[] = { "joy0", "joy1", "mouse", "kbd1", "kbd2", "kbd3", 0 };
90: static const char *colormode1[] = { "8bit", "15bit", "16bit", "8bit_dither", "4bit_dither", "32bit", 0 };
91: static const char *colormode2[] = { "8", "15", "16", "8d", "4d", "32", 0 };
92: static const char *soundmode[] = { "none", "interrupts", "normal", "exact", 0 };
1.1.1.2 root 93: static const char *centermode1[] = { "none", "simple", "smart", 0 };
94: static const char *centermode2[] = { "false", "true", "smart", 0 };
1.1 root 95: static const char *stereomode1[] = { "mono", "stereo", 0 };
96: static const char *stereomode2[] = { "m", "s", 0 };
97: static const char *stereomode3[] = { "1", "2", 0 };
98:
99: #define UNEXPANDED "$(FILE_PATH)"
100:
101: static int match_string (const char *table[], const char *str)
102: {
103: int i;
104: for (i = 0; table[i] != 0; i++)
105: if (strcasecmp (table[i], str) == 0)
106: return i;
107: return -1;
108: }
109:
110: char *cfgfile_subst_path (const char *path, const char *subst, const char *file)
111: {
112: /* @@@ use strcasecmp for some targets. */
113: if (strlen (path) > 0 && strncmp (file, path, strlen (path)) == 0) {
114: int l;
115: char *p = xmalloc (strlen (file) + strlen (subst) + 2);
116: strcpy (p, subst);
117: l = strlen (p);
118: while (l > 0 && p[l - 1] == '/')
119: p[--l] = '\0';
120: l = strlen (path);
121: while (file[l] == '/')
122: l++;
123: strcat (p, "/"); strcat (p, file + l);
124: return p;
125: }
126: return my_strdup (file);
127: }
128:
129: void save_options (FILE *f, struct uae_prefs *p)
130: {
131: struct strlist *sl;
132: char *str;
133: int i;
134:
135: fprintf (f, "config_description=%s\n", p->description);
136:
137: for (sl = p->unknown_lines; sl; sl = sl->next)
138: fprintf (f, "%s\n", sl->str);
139:
140: fprintf (f, "%s.rom_path=%s\n", TARGET_NAME, p->path_rom);
141: fprintf (f, "%s.floppy_path=%s\n", TARGET_NAME, p->path_floppy);
142: fprintf (f, "%s.hardfile_path=%s\n", TARGET_NAME, p->path_hardfile);
143:
1.1.1.2 root 144: target_save_options (f, p);
145:
1.1 root 146: fprintf (f, "use_gui=%s\n", p->start_gui ? "true" : "false");
147: fprintf (f, "use_debugger=%s\n", p->start_debugger ? "true" : "false");
148: str = cfgfile_subst_path (p->path_rom, UNEXPANDED, p->romfile);
149: fprintf (f, "kickstart_rom_file=%s\n", str);
150: free (str);
151: str = cfgfile_subst_path (p->path_rom, UNEXPANDED, p->keyfile);
152: fprintf (f, "kickstart_key_file=%s\n", str);
153: free (str);
154:
155: for (i = 0; i < 4; i++) {
156: str = cfgfile_subst_path (p->path_floppy, UNEXPANDED, p->df[i]);
157: fprintf (f, "floppy%d=%s\n", i, str);
158: free (str);
159: }
160: fprintf (f, "parallel_on_demand=%s\n", p->parallel_demand ? "true" : "false");
161: fprintf (f, "serial_on_demand=%s\n", p->serial_demand ? "true" : "false");
162:
163: fprintf (f, "sound_output=%s\n", soundmode[p->produce_sound]);
164: fprintf (f, "sound_channels=%s\n", stereomode1[p->stereo]);
165: fprintf (f, "sound_bits=%d\n", p->sound_bits);
166: fprintf (f, "sound_min_buff=%d\n", p->sound_minbsiz);
167: fprintf (f, "sound_max_buff=%d\n", p->sound_maxbsiz);
168: fprintf (f, "sound_frequency=%d\n", p->sound_freq);
169:
170: fprintf (f, "sound_pri_time=%d\n", p->sound_pri_time);
171: fprintf (f, "sound_pri_cutoff=%d\n", p->sound_pri_cutoff);
172:
173: fprintf (f, "joyport0=%s\n", portmode[p->jport0]);
174: fprintf (f, "joyport1=%s\n", portmode[p->jport1]);
175:
1.1.1.3 ! root 176: fprintf (f, "bsdsocket_emu=%s\n", p->socket_emu ? "true" : "false");
1.1 root 177:
1.1.1.3 ! root 178: fprintf (f, "gfx_framerate=%d\n", p->gfx_framerate);
1.1 root 179: fprintf (f, "gfx_width=%d\n", p->gfx_width);
180: fprintf (f, "gfx_height=%d\n", p->gfx_height);
181: fprintf (f, "gfx_lores=%s\n", p->gfx_lores ? "true" : "false");
182: fprintf (f, "gfx_linemode=%s\n", linemode1[p->gfx_linedbl]);
183: fprintf (f, "gfx_correct_aspect=%s\n", p->gfx_correct_aspect ? "true" : "false");
184: fprintf (f, "gfx_fullscreen_amiga=%s\n", p->gfx_afullscreen ? "true" : "false");
185: fprintf (f, "gfx_fullscreen_picasso=%s\n", p->gfx_pfullscreen ? "true" : "false");
1.1.1.2 root 186: fprintf (f, "gfx_center_horizontal=%s\n", centermode1[p->gfx_xcenter]);
187: fprintf (f, "gfx_center_vertical=%s\n", centermode1[p->gfx_ycenter]);
1.1 root 188: fprintf (f, "gfx_colour_mode=%s\n", colormode1[p->color_mode]);
189:
190: fprintf (f, "32bit_blits=%s\n", p->blits_32bit_enabled ? "true" : "false");
191: fprintf (f, "immediate_blits=%s\n", p->immediate_blits ? "true" : "false");
1.1.1.3 ! root 192: fprintf (f, "ntsc=%s\n", p->ntscmode ? "true" : "false");
! 193: if (p->chipset_mask & CSMASK_AGA)
! 194: fprintf (f, "chipset=aga\n");
! 195: else if ((p->chipset_mask & CSMASK_ECS_AGNUS) && (p->chipset_mask & CSMASK_ECS_AGNUS))
! 196: fprintf (f, "chipset=ecs\n");
! 197: else if (p->chipset_mask & CSMASK_ECS_AGNUS)
! 198: fprintf (f, "chipset=ecs_agnus\n");
! 199: else if (p->chipset_mask & CSMASK_ECS_DENISE)
! 200: fprintf (f, "chipset=ecs_denise\n");
! 201: else
! 202: fprintf (f, "chipset=ocs\n");
1.1 root 203:
204: fprintf (f, "fastmem_size=%d\n", p->fastmem_size / 0x100000);
205: fprintf (f, "a3000mem_size=%d\n", p->a3000mem_size / 0x100000);
206: fprintf (f, "z3mem_size=%d\n", p->z3fastmem_size / 0x100000);
207: fprintf (f, "bogomem_size=%d\n", p->bogomem_size / 0x40000);
208: fprintf (f, "gfxcard_size=%d\n", p->gfxmem_size / 0x100000);
209: fprintf (f, "chipmem_size=%d\n", p->chipmem_size / 0x80000);
210:
1.1.1.3 ! root 211: if (p->m68k_speed > 0)
1.1 root 212: fprintf (f, "cpu_speed=%d\n", p->m68k_speed);
213: else
214: fprintf (f, "cpu_speed=%s\n", p->m68k_speed == -1 ? "max" : "real");
215:
216: fprintf (f, "cpu_type=%s\n", cpumode[p->cpu_level * 2 + !p->address_space_24]);
217: fprintf (f, "cpu_compatible=%s\n", p->cpu_compatible ? "true" : "false");
218: fprintf (f, "autoconfig=%s\n", p->automount_uaedev ? "true" : "false");
219:
220: fprintf (f, "accuracy=%d\n", p->emul_accuracy);
221: fprintf (f, "log_illegal_mem=%s\n", p->illegal_mem ? "true" : "false");
222:
223: fprintf (f, "kbd_lang=%s\n", (p->keyboard_lang == KBD_LANG_DE ? "de"
224: : p->keyboard_lang == KBD_LANG_ES ? "es"
225: : p->keyboard_lang == KBD_LANG_US ? "us"
226: : p->keyboard_lang == KBD_LANG_SE ? "se"
227: : p->keyboard_lang == KBD_LANG_FR ? "fr"
228: : p->keyboard_lang == KBD_LANG_IT ? "it"
229: : "FOO"));
230:
231: write_filesys_config (p->mountinfo, UNEXPANDED, p->path_hardfile, f);
232:
233: /* Don't write gfxlib/gfx_test_speed options. */
234: }
235:
236: int cfgfile_yesno (char *option, char *value, char *name, int *location)
237: {
238: if (strcmp (option, name) != 0)
239: return 0;
240: if (strcasecmp (value, "yes") == 0 || strcasecmp (value, "y") == 0
241: || strcasecmp (value, "true") == 0 || strcasecmp (value, "t") == 0)
242: *location = 1;
243: else if (strcasecmp (value, "no") == 0 || strcasecmp (value, "n") == 0
244: || strcasecmp (value, "false") == 0 || strcasecmp (value, "f") == 0)
245: *location = 0;
246: else
247: write_log ("Option `%s' requires a value of either `yes' or `no'.\n", option);
248: return 1;
249: }
250:
251: int cfgfile_intval (char *option, char *value, char *name, int *location, int scale)
252: {
253: int base = 10;
254: char *endptr;
255: if (strcmp (option, name) != 0)
256: return 0;
257: /* I guess octal isn't popular enough to worry about here... */
258: if (value[0] == '0' && value[1] == 'x')
259: value += 2, base = 16;
260: *location = strtol (value, &endptr, base) * scale;
261:
262: if (*endptr != '\0' || *value == '\0')
263: write_log ("Option `%s' requires a numeric argument.\n", option);
264: return 1;
265: }
266:
267: int cfgfile_strval (char *option, char *value, char *name, int *location, const char *table[], int more)
268: {
269: int val;
270: if (strcmp (option, name) != 0)
271: return 0;
272: val = match_string (table, value);
273: if (val == -1) {
274: if (! more)
275: write_log ("Unknown value for option `%s'.\n", option);
276: return 1;
277: }
278: *location = val;
279: return 1;
280: }
281:
282: int cfgfile_string (char *option, char *value, char *name, char *location, int maxsz)
283: {
284: if (strcmp (option, name) != 0)
285: return 0;
286: strncpy (location, value, maxsz - 1);
287: location[maxsz - 1] = '\0';
288: return 1;
289: }
290:
291: static int getintval (char **p, int *result, int delim)
292: {
293: char *value = *p;
294: int base = 10;
295: char *endptr;
296: char *p2 = strchr (*p, delim);
297:
298: if (p2 == 0)
299: return 0;
300:
301: *p2++ = '\0';
302:
303: if (value[0] == '0' && value[1] == 'x')
304: value += 2, base = 16;
305: *result = strtol (value, &endptr, base);
306: *p = p2;
307:
308: if (*endptr != '\0' || *value == '\0')
309: return 0;
310:
311: return 1;
312: }
313:
1.1.1.2 root 314: int cfgfile_parse_option (struct uae_prefs *p, char *option, char *value)
1.1 root 315: {
1.1.1.3 ! root 316: int tmpval;
1.1 root 317: char *section = 0;
318: char *tmpp;
1.1.1.3 ! root 319:
1.1 root 320: for (tmpp = option; *tmpp != '\0'; tmpp++)
321: if (isupper (*tmpp))
322: *tmpp = tolower (*tmpp);
323: tmpp = strchr (option, '.');
324: if (tmpp) {
325: section = option;
326: option = tmpp + 1;
327: *tmpp = '\0';
328: if (strcmp (section, TARGET_NAME) == 0) {
329: /* We special case the various path options here. */
330: if (cfgfile_string (option, value, "rom_path", p->path_rom, 256)
331: || cfgfile_string (option, value, "floppy_path", p->path_floppy, 256)
332: || cfgfile_string (option, value, "hardfile_path", p->path_hardfile, 256))
333: return 1;
334: return target_parse_option (p, option, value);
335: }
336: return 0;
337: }
338: if (cfgfile_yesno (option, value, "use_debugger", &p->start_debugger)
339: || cfgfile_yesno (option, value, "use_gui", &p->start_gui)
1.1.1.3 ! root 340: || cfgfile_yesno (option, value, "bsdsocket_emu", &p->socket_emu)
1.1 root 341: || cfgfile_yesno (option, value, "immediate_blits", &p->immediate_blits)
342: || cfgfile_yesno (option, value, "32bit_blits", &p->blits_32bit_enabled)
343: || cfgfile_yesno (option, value, "gfx_lores", &p->gfx_lores)
344: || cfgfile_yesno (option, value, "gfx_correct_aspect", &p->gfx_correct_aspect)
345: || cfgfile_yesno (option, value, "gfx_fullscreen_amiga", &p->gfx_afullscreen)
346: || cfgfile_yesno (option, value, "gfx_fullscreen_picasso", &p->gfx_pfullscreen)
1.1.1.3 ! root 347: || cfgfile_yesno (option, value, "ntsc", &p->ntscmode)
1.1 root 348: || cfgfile_yesno (option, value, "cpu_compatible", &p->cpu_compatible)
349: || cfgfile_yesno (option, value, "cpu_24bit_addressing", &p->address_space_24)
350: || cfgfile_yesno (option, value, "autoconfig", &p->automount_uaedev)
351: || cfgfile_yesno (option, value, "parallel_on_demand", &p->parallel_demand)
352: || cfgfile_yesno (option, value, "serial_on_demand", &p->serial_demand)
353: || cfgfile_yesno (option, value, "log_illegal_mem", &p->illegal_mem))
354: return 1;
355: if (cfgfile_intval (option, value, "accuracy", &p->emul_accuracy, 1)
356: || cfgfile_intval (option, value, "sound_min_buff", &p->sound_minbsiz, 1)
357: || cfgfile_intval (option, value, "sound_max_buff", &p->sound_maxbsiz, 1)
358: || cfgfile_intval (option, value, "sound_frequency", &p->sound_freq, 1)
359: || cfgfile_intval (option, value, "sound_bits", &p->sound_bits, 1)
360: || cfgfile_intval (option, value, "sound_pri_cutoff", &p->sound_pri_cutoff, 1)
361: || cfgfile_intval (option, value, "sound_pri_time", &p->sound_pri_time, 1)
1.1.1.3 ! root 362: || cfgfile_intval (option, value, "gfx_framerate", &p->gfx_framerate, 1)
1.1 root 363: || cfgfile_intval (option, value, "gfx_width", &p->gfx_width, 1)
364: || cfgfile_intval (option, value, "gfx_height", &p->gfx_height, 1)
365: || cfgfile_intval (option, value, "fastmem_size", &p->fastmem_size, 0x100000)
366: || cfgfile_intval (option, value, "a3000mem_size", &p->a3000mem_size, 0x100000)
367: || cfgfile_intval (option, value, "z3mem_size", &p->z3fastmem_size, 0x100000)
368: || cfgfile_intval (option, value, "bogomem_size", &p->bogomem_size, 0x40000)
369: || cfgfile_intval (option, value, "gfxcard_size", &p->gfxmem_size, 0x100000)
370: || cfgfile_intval (option, value, "chipmem_size", &p->chipmem_size, 0x80000))
371: return 1;
372: if (cfgfile_strval (option, value, "sound_output", &p->produce_sound, soundmode, 0)
373: || cfgfile_strval (option, value, "sound_channels", &p->stereo, stereomode1, 1)
374: || cfgfile_strval (option, value, "sound_channels", &p->stereo, stereomode2, 1)
375: || cfgfile_strval (option, value, "sound_channels", &p->stereo, stereomode3, 0)
376: || cfgfile_strval (option, value, "joyport0", &p->jport0, portmode, 0)
377: || cfgfile_strval (option, value, "joyport1", &p->jport1, portmode, 0)
378: || cfgfile_strval (option, value, "gfx_linemode", &p->gfx_linedbl, linemode1, 1)
379: || cfgfile_strval (option, value, "gfx_linemode", &p->gfx_linedbl, linemode2, 0)
1.1.1.2 root 380: || cfgfile_strval (option, value, "gfx_center_horizontal", &p->gfx_xcenter, centermode1, 1)
381: || cfgfile_strval (option, value, "gfx_center_vertical", &p->gfx_ycenter, centermode1, 1)
382: || cfgfile_strval (option, value, "gfx_center_horizontal", &p->gfx_xcenter, centermode2, 0)
383: || cfgfile_strval (option, value, "gfx_center_vertical", &p->gfx_ycenter, centermode2, 0)
1.1 root 384: || cfgfile_strval (option, value, "gfx_colour_mode", &p->color_mode, colormode1, 1)
385: || cfgfile_strval (option, value, "gfx_colour_mode", &p->color_mode, colormode2, 0)
386: || cfgfile_strval (option, value, "gfx_color_mode", &p->color_mode, colormode1, 1)
387: || cfgfile_strval (option, value, "gfx_color_mode", &p->color_mode, colormode2, 0))
388: return 1;
389: if (cfgfile_string (option, value, "floppy0", p->df[0], 256)
390: || cfgfile_string (option, value, "floppy1", p->df[1], 256)
391: || cfgfile_string (option, value, "floppy2", p->df[2], 256)
392: || cfgfile_string (option, value, "floppy3", p->df[3], 256)
393: || cfgfile_string (option, value, "kickstart_rom_file", p->romfile, 256)
394: || cfgfile_string (option, value, "kickstart_key_file", p->keyfile, 256)
1.1.1.2 root 395: || cfgfile_string (option, value, "config_description", p->description, 256))
1.1 root 396: return 1;
397:
398: /* Tricky ones... */
1.1.1.3 ! root 399: if (cfgfile_strval (option, value, "chipset", &tmpval, csmode, 0)) {
! 400: p->chipset_mask = (tmpval == 0 ? 0
! 401: : tmpval == 1 ? CSMASK_ECS_AGNUS
! 402: : tmpval == 2 ? CSMASK_ECS_DENISE
! 403: : tmpval == 3 ? CSMASK_ECS_DENISE | CSMASK_ECS_AGNUS
! 404: : CSMASK_AGA | CSMASK_ECS_DENISE | CSMASK_ECS_AGNUS);
! 405: return 1;
! 406: }
! 407:
1.1 root 408: if (cfgfile_strval (option, value, "cpu_type", &p->cpu_level, cpumode, 0)) {
409: p->address_space_24 = !(p->cpu_level & 1);
410: p->cpu_level >>= 1;
411: return 1;
412: }
413: if (cfgfile_strval (option, value, "cpu_speed", &p->m68k_speed, speedmode, 1)) {
414: p->m68k_speed--;
415: return 1;
416: }
417: if (cfgfile_intval (option, value, "cpu_speed", &p->m68k_speed, 1))
418: return 1;
419:
420: if (strcmp (option, "kbd_lang") == 0) {
421: KbdLang l;
422: if ((l = KBD_LANG_DE, strcasecmp (value, "de") == 0)
423: || (l = KBD_LANG_SE, strcasecmp (value, "se") == 0)
424: || (l = KBD_LANG_US, strcasecmp (value, "us") == 0)
425: || (l = KBD_LANG_FR, strcasecmp (value, "fr") == 0)
426: || (l = KBD_LANG_IT, strcasecmp (value, "it") == 0)
427: || (l = KBD_LANG_ES, strcasecmp (value, "es") == 0))
428: p->keyboard_lang = l;
429: else
430: write_log ("Unknown keyboard language\n");
431: return 1;
432: }
433:
434: if (strcmp (option, "filesystem") == 0
435: || strcmp (option, "hardfile") == 0)
436: {
1.1.1.2 root 437: int secs, heads, reserved, bs, ro;
438: char *aname, *root;
1.1 root 439: char *tmpp = strchr (value, ',');
1.1.1.2 root 440: char *str;
1.1 root 441: if (tmpp == 0)
442: goto invalid_fs;
443:
444: *tmpp++ = '\0';
445: if (strcmp (value, "0") == 0 || strcasecmp (value, "ro") == 0
446: || strcasecmp (value, "readonly") == 0
447: || strcasecmp (value, "read-only") == 0)
1.1.1.2 root 448: ro = 1;
1.1 root 449: else if (strcmp (value, "1") == 0 || strcasecmp (value, "rw") == 0
450: || strcasecmp (value, "readwrite") == 0
451: || strcasecmp (value, "read-write") == 0)
1.1.1.2 root 452: ro = 0;
1.1 root 453: else
454: goto invalid_fs;
1.1.1.2 root 455: secs = 0; heads = 0; reserved = 0; bs = 0;
1.1 root 456:
457: value = tmpp;
458: if (strcmp (option, "filesystem") == 0) {
459: tmpp = strchr (value, ':');
460: if (tmpp == 0)
461: goto invalid_fs;
462: *tmpp++ = '\0';
1.1.1.2 root 463: aname = value;
464: root = tmpp;
1.1 root 465: } else {
1.1.1.2 root 466: if (! getintval (&value, &secs, ',')
467: || ! getintval (&value, &heads, ',')
468: || ! getintval (&value, &reserved, ',')
469: || ! getintval (&value, &bs, ','))
1.1 root 470: goto invalid_fs;
1.1.1.2 root 471: root = value;
472: aname = 0;
1.1 root 473: }
1.1.1.2 root 474: str = cfgfile_subst_path (UNEXPANDED, p->path_hardfile, root);
475: tmpp = add_filesys_unit (p->mountinfo, aname, str, ro, secs,
476: heads, reserved, bs);
477: free (str);
478: if (tmpp)
479: write_log ("Error: %s\n", tmpp);
1.1 root 480: return 1;
481:
482: invalid_fs:
483: write_log ("Invalid filesystem/hardfile specification.\n");
484: return 1;
485: }
486:
487: return 0;
488: }
489:
1.1.1.2 root 490: void cfgfile_parse_line (struct uae_prefs *p, char *line)
1.1 root 491: {
492: int i;
493: char *orig_line = my_strdup (line);
494: char *line1, *line2;
495:
496: line1 = line;
497: line2 = strchr (line, '=');
498: if (! line2) {
499: write_log ("CFGFILE: line was incomplete with only %s\n", line1);
500: return;
501: }
502:
503: *line2++ = '\0';
504:
505: /* Get rid of whitespace. */
1.1.1.2 root 506: i = strlen (line2);
507: while (i > 0 && (line2[i - 1] == '\t' || line2[i - 1] == ' '
508: || line2[i - 1] == '\r' || line2[i - 1] == '\n'))
509: line2[--i] = '\0';
1.1 root 510: line2 += strspn (line2, "\t \r\n");
1.1.1.2 root 511: i = strlen (line);
512: while (i > 0 && (line[i - 1] == '\t' || line[i - 1] == ' '
513: || line[i - 1] == '\r' || line[i - 1] == '\n'))
514: line[--i] = '\0';
1.1 root 515: line += strspn (line, "\t \r\n");
516:
1.1.1.2 root 517: if (! cfgfile_parse_option (p, line, line2)) {
1.1 root 518: struct strlist *u = xmalloc (sizeof (struct strlist));
519: u->str = orig_line;
520: u->next = p->unknown_lines;
521: p->unknown_lines = u;
522: } else
523: free (orig_line);
524: }
525:
526: static void subst (char *p, char *f, int n)
527: {
528: char *str = cfgfile_subst_path (UNEXPANDED, p, f);
529: strncpy (f, str, n - 1);
530: f[n - 1] = '\0';
531: free (str);
532: }
533:
534: int cfgfile_load (struct uae_prefs *p, const char *filename)
535: {
536: char *str;
537: int i;
538:
539: FILE *fh;
540: char line[256];
541:
542: fh = fopen (filename, "rt");
543: if (! fh)
544: return 0;
545:
546: while (fgets (line, 256, fh) != 0) {
547: line[strcspn (line, "\t \r\n")] = '\0';
548: if (strlen (line) > 0)
1.1.1.2 root 549: cfgfile_parse_line (p, line);
1.1 root 550: }
551: fclose (fh);
552:
553: for (i = 0; i < 4; i++)
554: subst (p->path_floppy, p->df[i], sizeof p->df[i]);
555: subst (p->path_rom, p->romfile, sizeof p->romfile);
556: subst (p->path_rom, p->keyfile, sizeof p->keyfile);
557:
558: return 1;
559: }
560:
561: int cfgfile_save (struct uae_prefs *p, const char *filename)
562: {
563: FILE *fh = fopen (filename, "w");
564: if (! fh)
565: return 0;
566:
567: save_options (fh, p);
568: fclose (fh);
569: return 1;
570: }
571:
572: int cfgfile_get_description (const char *filename, char *description)
573: {
574: int result = 0;
575: struct uae_prefs p;
576: default_prefs (&p);
577: strcpy (p.description, "");
578: if (cfgfile_load (&p, filename) && strlen (p.description) != 0) {
579: result = 1;
580: strcpy (description, p.description);
581: }
582: discard_prefs (&p);
583: return result;
584: }
585:
586: void cfgfile_show_usage (void)
587: {
588: int i;
589: fprintf (stderr, "UAE Configuration Help:\n" \
590: "=======================\n");
591: for (i = 0; i < sizeof opttable / sizeof *opttable; i++)
592: fprintf (stderr, "%s: %s\n", opttable[i].config_label, opttable[i].config_help);
593: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.