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

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

unix.superglobalmegacorp.com

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