--- np2/x11/main.c 2008/03/13 16:27:39 1.28 +++ np2/x11/main.c 2011/01/15 18:43:13 1.36 @@ -27,8 +27,13 @@ #include #include +#include #include +#if defined(USE_SDLAUDIO) || defined(USE_SDLMIXER) +#include +#endif + #include "np2.h" #include "diskdrv.h" #include "dosio.h" @@ -80,8 +85,6 @@ static void sighandler(int signo) { - UNUSED(signo); - toolkit_widget_quit(); } @@ -102,11 +105,11 @@ static void usage(void) { - printf("Usage: %s [options] [[FD1 image] [[FD2 image] [[FD3 image] [FD4 image]]]]\n\n", progname); - printf("options:\n"); - printf("\t--help [-h] : print this message\n"); - printf("\t--config [-c] : specify config file\n"); - printf("\t--timidity-config [-C] : specify timidity config file\n"); + g_printerr("Usage: %s [options] [[FD1 image] [[FD2 image] [[FD3 image] [FD4 image]]]]\n\n", progname); + g_printerr("options:\n"); + g_printerr("\t--help [-h] : print this message\n"); + g_printerr("\t--config [-c] : specify config file\n"); + g_printerr("\t--timidity-config [-C] : specify timidity config file\n"); exit(1); } @@ -125,6 +128,11 @@ main(int argc, char *argv[]) progname = argv[0]; + setlocale(LC_ALL, ""); + bindtextdomain(np2appname, NP2LOCALEDIR); + bind_textdomain_codeset(np2appname, "UTF-8"); + textdomain(np2appname); + toolkit_initialize(); toolkit_arginit(&argc, &argv); @@ -132,33 +140,21 @@ main(int argc, char *argv[]) switch (ch) { case 'c': if (stat(optarg, &sb) < 0 || !S_ISREG(sb.st_mode)) { - fprintf(stderr, "Can't access %s.\n", optarg); + g_printerr("Can't access %s.\n", optarg); exit(1); } milstr_ncpy(modulefile, optarg, sizeof(modulefile)); - - /* resume/statsave dir */ - file_cpyname(statpath, modulefile, sizeof(statpath)); - file_cutname(statpath); break; case 'C': if (stat(optarg, &sb) < 0 || !S_ISREG(sb.st_mode)) { - fprintf(stderr, "Can't access %s.\n", optarg); + g_printerr("Can't access %s.\n", optarg); exit(1); } milstr_ncpy(timidity_cfgfile_path, optarg, sizeof(timidity_cfgfile_path)); break; - case 't': - if (stat(optarg, &sb) < 0 || !S_ISREG(sb.st_mode)) { - fprintf(stderr, "Can't access %s.\n", optarg); - exit(1); - } - milstr_ncpy(fontfilename, optarg, sizeof(fontfilename)); - break; - case 'v': verbose = 1; break; @@ -177,46 +173,53 @@ main(int argc, char *argv[]) char *env = getenv("HOME"); if (env) { /* base dir */ - snprintf(modulefile, sizeof(modulefile), - "%s/.np2", env); + g_snprintf(modulefile, sizeof(modulefile), + "%s/.%s", env, np2appname); if (stat(modulefile, &sb) < 0) { if (mkdir(modulefile, 0700) < 0) { perror(modulefile); exit(1); } } else if (!S_ISDIR(sb.st_mode)) { - fprintf(stderr, "%s isn't directory.\n", + g_printerr("%s isn't directory.\n", modulefile); exit(1); } - /* font file */ - snprintf(np2cfg.fontfile, sizeof(np2cfg.fontfile), - "%s/font.bmp", modulefile); - - /* resume/statsave dir */ - file_cpyname(statpath, modulefile, sizeof(statpath)); - file_catname(statpath, "/sav/", sizeof(statpath)); - if (stat(statpath, &sb) < 0) { - if (mkdir(statpath, 0700) < 0) { - perror(statpath); - exit(1); - } - } else if (!S_ISDIR(sb.st_mode)) { - fprintf(stderr, "%s isn't directory.\n", - statpath); - exit(1); - } - /* config file */ milstr_ncat(modulefile, "/np2rc", sizeof(modulefile)); if ((stat(modulefile, &sb) >= 0) && !S_ISREG(sb.st_mode)) { - fprintf(stderr, "%s isn't regular file.\n", + g_printerr("%s isn't regular file.\n", modulefile); } } } + if (modulefile[0] != '\0') { + /* font file */ + file_cpyname(np2cfg.fontfile, modulefile, + sizeof(np2cfg.fontfile)); + file_cutname(np2cfg.fontfile); + file_setseparator(np2cfg.fontfile, sizeof(np2cfg.fontfile)); + file_catname(np2cfg.fontfile, "font.bmp", + sizeof(np2cfg.fontfile)); + + /* resume/statsave dir */ + file_cpyname(statpath, modulefile, sizeof(statpath)); + file_cutname(statpath); + file_catname(statpath, "/sav/", sizeof(statpath)); + if (stat(statpath, &sb) < 0) { + if (mkdir(statpath, 0700) < 0) { + perror(statpath); + exit(1); + } + } else if (!S_ISDIR(sb.st_mode)) { + g_printerr("%s isn't directory.\n", + statpath); + exit(1); + } + file_catname(statpath, np2appname, sizeof(statpath)); + } if (timidity_cfgfile_path[0] == '\0') { file_cpyname(timidity_cfgfile_path, modulefile, sizeof(timidity_cfgfile_path)); @@ -239,6 +242,10 @@ main(int argc, char *argv[]) TRACEINIT(); +#if defined(USE_SDLAUDIO) || defined(USE_SDLMIXER) + SDL_Init(0); +#endif + if (fontmng_init() != SUCCESS) goto fontmng_failure; @@ -352,7 +359,8 @@ scrnmng_failure: fontmng_terminate(); fontmng_failure: - if (sys_updates & (SYS_UPDATECFG|SYS_UPDATEOSCFG)) { + if (!np2oscfg.cfgreadonly + && (sys_updates & (SYS_UPDATECFG|SYS_UPDATEOSCFG))) { initsave(); toolwin_writeini(); kdispwin_writeini(); @@ -361,6 +369,10 @@ fontmng_failure: skbdwin_deinitialize(); +#if defined(USE_SDLAUDIO) || defined(USE_SDLMIXER) + SDL_Quit(); +#endif + TRACETERM(); dosio_term();