Annotation of uae/src/cfgfile.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.