char *archdep_default_sysfile_pathlist(const char *emu_id) { static char *default_path; if (default_path == NULL) { const char *boot_path = archdep_boot_path(); default_path = util_concat(boot_path, "\\", emu_id, ARCHDEP_FINDPATH_SEPARATOR_STRING, boot_path, "\\DRIVES", ARCHDEP_FINDPATH_SEPARATOR_STRING, boot_path, "\\PRINTER", NULL); } return default_path; }
/* return malloc'd version of full pathname of orig_name */ int archdep_expand_path(char **return_path, const char *orig_name) { /* Unix version. */ if (*orig_name == '/') { *return_path = lib_stralloc(orig_name); } else { static char *cwd; cwd = ioutil_current_dir(); *return_path = util_concat(cwd, "/", orig_name, NULL); lib_free(cwd); } return 0; }
FILE *archdep_mkstemp_fd(char **filename, const char *mode) { char *tmp; FILE *fd; if (getenv("temp")) { tmp = util_concat(getenv("temp"), tmpnam(NULL), NULL); } else if (getenv("tmp")) { tmp = util_concat(getenv("tmp"), tmpnam(NULL), NULL); } else { tmp = lib_stralloc(tmpnam(NULL)); } fd = fopen(tmp, mode); if (fd == NULL) { return NULL; } *filename = tmp; return fd; }
char *archdep_program_name(void) { static char *name = NULL; if (!name) { char drive[_MAX_DRIVE]; char dir[_MAX_DIR]; char fname[_MAX_FNAME+_MAX_EXT]; char ext[_MAX_EXT]; _splitpath(argv0, drive, dir, fname, ext); name = util_concat(fname, ext, NULL); } return name; }
int digimax_cmdline_options_init(void) { char *temp1, *temp2; if (cmdline_register_options(cmdline_options) < 0) { return -1; } if (machine_class == VICE_MACHINE_VIC20) { temp1 = util_gen_hex_address_list(0x9800, 0x9900, 0x20); temp2 = util_gen_hex_address_list(0x9c00, 0x9d00, 0x20); digimax_address_list = util_concat(". (", temp1, "/", temp2, ")", NULL); lib_free(temp2); } else { temp1 = util_gen_hex_address_list(0xde00, 0xe000, 0x20); digimax_address_list = util_concat(". (0xDD00: Userport/", temp1, ")", NULL); } lib_free(temp1); base_cmdline_options[0].description = digimax_address_list; return cmdline_register_options(base_cmdline_options); }
char *cmdline_options_get_description(int counter) { if (options[counter].use_description_id == USE_DESCRIPTION_ID) { return translate_text(options[counter].description_trans); } else if (options[counter].use_description_id == USE_DESCRIPTION_COMBO) { if (options[counter].combined_string) { lib_free(options[counter].combined_string); } options[counter].combined_string = util_concat(translate_text(options[counter].description_trans), options[counter].description, NULL); return options[counter].combined_string; } else { return (char *)_(options[counter].description); } }
/* NOTE: even when _DIRENT_HAVE_D_TYPE is defined, d_type may still be returned as DT_UNKNOWN - in that case we must fall back to using stat instead. */ static int ioutil_count_dir_items(const char *path) { DIR *dirp; struct dirent *dp; /* #ifndef _DIRENT_HAVE_D_TYPE */ unsigned int len, isdir; char *filename; int retval; /* #endif */ dirs_amount = 0; files_amount = 0; dirp = opendir(path); if (dirp == NULL) { return -1; } dp = readdir(dirp); while (dp != NULL) { #ifdef _DIRENT_HAVE_D_TYPE if (dp->d_type != DT_UNKNOWN) { if (dp->d_type == DT_DIR) { dirs_amount++; } else { files_amount++; } dp = readdir(dirp); } else { #endif filename = util_concat(path, FSDEV_DIR_SEP_STR, dp->d_name, NULL); retval = ioutil_stat(filename, &len, &isdir); if (retval == 0) { if (isdir) { dirs_amount++; } else { files_amount++; } } dp = readdir(dirp); lib_free(filename); #ifdef _DIRENT_HAVE_D_TYPE } #endif } closedir(dirp); return 0; }
void ui_exit(void) { ui_button_t b; int value1, value2; char *s = util_concat(_("Exit "), (machine_class != VICE_MACHINE_VSID) ? machine_name : "SID", _(" emulator"), NULL); #ifdef HAVE_FULLSCREEN fullscreen_suspend(1); #endif resources_get_int("ConfirmOnExit", &value1); resources_get_int("SaveResourcesOnExit", &value2); b = UI_BUTTON_YES; if ((value1) && (!value2)) { b = ui_ask_yesno(s, _("Do you really want to exit?")); } if (b == UI_BUTTON_YES) { if (value2) { b = UI_BUTTON_YES; if (value1) { b = ui_ask_confirmation(s, _("Save the current settings?")); } if (b == UI_BUTTON_YES) { if (resources_save(NULL) < 0) { ui_error(_("Cannot save settings.")); b = UI_BUTTON_CANCEL; } } } if (b != UI_BUTTON_CANCEL) { /* ui_autorepeat_on(); */ ui_restore_mouse(); #ifdef HAVE_FULLSCREEN fullscreen_suspend(0); #endif ui_dispatch_events(); lib_free(s); #ifdef USE_UI_THREADS dthread_shutdown(); #endif exit(0); }; } lib_free(s); vsync_suspend_speed_eval(); }
/* return malloced version of full pathname of filename */ int archdep_expand_path(char **return_path, const char *filename) { if (filename[0] == '\\' || filename[1] == ':') { *return_path = lib_stralloc(filename); } else { char *p = (char *)malloc(512); while (getcwd(p, 512) == NULL) { return 0; } *return_path = util_concat(p, "\\", filename, NULL); lib_free(p); } return 0; }
static UI_CALLBACK(openGL_set_desktoprefresh) { char *enter_refresh_rate = util_concat(_("Enter refresh rate"), " (Hz): ", NULL); char *refresh_rate = util_concat(_("Refresh rate"), ": ", NULL); if (!CHECK_MENUS) { float f; char *buf = lib_calloc(sizeof(char), 10); sprintf(buf, "%.0f", openGL_get_canvas_refreshrate()); ui_input_string(refresh_rate, enter_refresh_rate, buf, 10); f = (float) strtol(buf, NULL, 10); openGL_set_canvas_refreshrate(f); lib_free(buf); lib_free(enter_refresh_rate); lib_free(refresh_rate); } else { if (openGL_available(0) && openGL_sync_enabled()) { ui_menu_set_sensitive(w, 1); } else { ui_menu_set_sensitive(w, 0); } } }
/** \brief Construct filename for quickload/quicksave snapshots * * \return filename for the quickload/save file, heap-allocated by VICE, so * free after use with lib_free() */ static char *quicksnap_filename(void) { char *fname; const char *mname; char *cfg; mname = machine_class == VICE_MACHINE_C64SC ? "c64sc" : machine_name; cfg = archdep_user_config_path(); fname = util_concat(cfg, "/", mname, ".vsf", NULL); #if 0 lib_free(cfg); #endif debug_gtk3("quicksnap_filename = %s.", fname); return fname; }
static void ioutil_filldir(const char *path, ioutil_name_table_t *dirs, ioutil_name_table_t *files) { DIR *dirp = NULL; struct dirent *dp = NULL; int dir_count = 0; int file_count = 0; /* #ifndef _DIRENT_HAVE_D_TYPE */ unsigned int len, isdir; char *filename; int retval; /* #endif */ dirp = opendir(path); dp = readdir(dirp); while (dp != NULL) { #ifdef _DIRENT_HAVE_D_TYPE if (dp->d_type != DT_UNKNOWN) { if (dp->d_type == DT_DIR) { dirs[dir_count].name = lib_stralloc(dp->d_name); dir_count++; } else { files[file_count].name = lib_stralloc(dp->d_name); file_count++; } dp = readdir(dirp); } else { #endif filename = util_concat(path, FSDEV_DIR_SEP_STR, dp->d_name, NULL); retval = ioutil_stat(filename, &len, &isdir); if (retval == 0) { if (isdir) { dirs[dir_count].name = lib_stralloc(dp->d_name); dir_count++; } else { files[file_count].name = lib_stralloc(dp->d_name); file_count++; } } dp = readdir(dirp); lib_free(filename); #ifdef _DIRENT_HAVE_D_TYPE } #endif } closedir(dirp); }
static void cart_game_dynmenu(HMENU menu) { cartridge_info_t *cart_info = cartridge_get_info_list(); int i; char *name; DeleteMenu(menu, 0, MF_BYPOSITION); for (i = 0; cart_info[i].name; ++i) { if (cart_info[i].flags == CARTRIDGE_GROUP_GAME) { name = util_concat(cart_info[i].name, " ", translate_text(IDS_IMAGE), "...", NULL); AppendMenu(menu, MF_STRING, current_dyn_id++, name); lib_free(name); } } }
char *platform_get_sco_runtime_os(void) { int retval = 0; struct utsname name; FILE *infile; int amount = 0; int i = 0; char *tempfile = NULL; char *tempsystem = NULL; if (!got_os) { buffer[0] = 0; retval = uname(&name); if (!retval) { sprintf(buffer, "%s", name.version); } else { tempfile = archdep_tmpnam(); tempsystem = util_concat("uname -v >", tempfile, NULL); system(tempsystem); infile = fopen(tempfile, "rb"); if (infile) { amount = fread(buffer, 1, 80, infile); if (amount) { while (buffer[i] != '\n') { i++; } buffer[i] = 0; } fclose(infile); } unlink(tempfile); lib_free(tempfile); lib_free(tempsystem); } if (buffer[0] == '2') { sprintf(platform_os, "SCO Unix v4.x"); } else if (buffer[0] == '5' || buffer[0] == '6') { sprintf(platform_os, "SCO Openserver %s", buffer); } else if (buffer[0] == '7') { sprintf(platform_os, "SCO Unixware %s", buffer); } else { sprintf(platform_os, "SCO Unix"); } got_os = 1; } return platform_os; }
static int set_chip_rendermode(int val, void *param) { char *chip, *dsize; int old, err; video_canvas_t *canvas = (video_canvas_t *)param; old = canvas->videoconfig->filter; chip = canvas->videoconfig->chip_name; DBG(("set_chip_rendermode %s (%d->%d)", chip, old, val)); dsize = util_concat(chip, "DoubleSize", NULL); canvas->videoconfig->filter = val; canvas->videoconfig->scale2x = 0; /* FIXME: remove this */ err = 0; switch (val) { case VIDEO_FILTER_NONE: break; case VIDEO_FILTER_CRT: if (video_color_update_palette(canvas) < 0) { err = 1; } break; case VIDEO_FILTER_SCALE2X: /* set double size */ if (resources_set_int(dsize, 1) < 0) { err = 1; } canvas->videoconfig->scale2x = 1; /* FIXME: remove this */ break; } if (err) { canvas->videoconfig->filter = old; } lib_free(dsize); if (canvas->initialized) { video_canvas_refresh_all(canvas); } video_resources_update_ui(canvas); return 0; }
rawfile_info_t *rawfile_open(const char *file_name, const char *path, unsigned int command) { rawfile_info_t *info; char *complete; FILE *fd; const char *mode = NULL; if (path == NULL) complete = lib_stralloc(file_name); else complete = util_concat(path, FSDEV_DIR_SEP_STR, file_name, NULL); switch (command) { case FILEIO_COMMAND_READ: mode = MODE_READ; break; case FILEIO_COMMAND_WRITE: mode = MODE_WRITE; break; case FILEIO_COMMAND_APPEND: mode = MODE_APPEND; break; case FILEIO_COMMAND_APPEND_READ: mode = MODE_APPEND_READ_WRITE; break; default: return NULL; } fd = fopen(complete, mode); if (fd == NULL) { lib_free(complete); return NULL; } info = lib_malloc(sizeof(rawfile_info_t)); info->fd = fd; util_fname_split(complete, &(info->path), &(info->name)); info->read_only = 0; lib_free(complete); return info; }
static UI_MENU_CALLBACK(about_callback) { int active = 1; int i; int j; char *tmp; if (activated) { sdl_ui_clear(); i = 0; sdl_ui_print_center("VICE", i++); sdl_ui_print_center("Versatile Commodore Emulator", i++); #ifdef USE_SVN_REVISION sdl_ui_print_center("Version " VERSION " rev " VICE_SVN_REV_STRING, i); #else sdl_ui_print_center("Version " VERSION, i); #endif i++; #ifdef USE_SDLUI2 sdl_ui_print_center("SDL2", i++); #else sdl_ui_print_center("SDL", i++); #endif i++; sdl_ui_print_center("The VICE Team", i++); for (j = 0; core_team[j].name; j++) { tmp = util_concat("(C) ", core_team[j].years, " ", core_team[j].name, NULL); sdl_ui_print_center(tmp, i++); lib_free(tmp); } sdl_ui_refresh(); while (active) { switch (sdl_ui_menu_poll_input()) { case MENU_ACTION_CANCEL: case MENU_ACTION_EXIT: case MENU_ACTION_SELECT: active = 0; break; default: SDL_Delay(10); break; } } } return NULL; }
void ui_about(void) { APTR gui = GroupObject, End; int i = 0; static const char *authors_start[] = { "VICE", "", "Versatile Commodore Emulator", "", #ifdef USE_SVN_REVISION "Version " VERSION "rev " VICE_SVN_REV_STRING " (" PLATFORM_CPU " " PLATFORM_OS " " PLATFORM_COMPILER ")", #else "Version " VERSION " (" PLATFORM_CPU " " PLATFORM_OS " " PLATFORM_COMPILER ")", #endif "", "The VICE Team", NULL}; static const char *authors_end[] = { "", "Official VICE homepage:", "http://vice-emu.sourceforge.net/", NULL}; char *tmp = NULL; for (i = 0; authors_start[i] != NULL; i++) { if (i <= 5) { /* centered */ DoMethod(gui, OM_ADDMEMBER, CLabel(authors_start[i])); } else { DoMethod(gui, OM_ADDMEMBER, LLabel(authors_start[i])); } } for (i = 0; core_team[i].name; i++) { tmp = util_concat("Copyright \xa9 ", core_team[i].years, " ", core_team[i].name, NULL); DoMethod(gui, OM_ADDMEMBER, LLabel(tmp)); lib_free(tmp); } for (i = 0; authors_end[i] != NULL; i++) { DoMethod(gui, OM_ADDMEMBER, LLabel(authors_end[i])); } mui_show_dialog(gui, translate_text(IDS_ABOUT), NULL); }
/** \brief Get a pixbuf from the GResource blob * * \param name virtual path to the file * * \return pixbuf or `NULL` on error */ GdkPixbuf * uidata_get_pixbuf(const char *name) { GdkPixbuf *buf; GError *err = NULL; char *path; path = util_concat(UIDATA_ROOT_PATH, "/", name, NULL); debug_gtk3("attempting to load resource '%s'.", path); buf = gdk_pixbuf_new_from_resource(path, &err); lib_free(path); if (buf == NULL) { debug_gtk3("failed: %s.", err->message); /* TODO: log error */ g_clear_error(&err); } return buf; }
static void debug_create_new_file(void) { char *filename, *st; const char *directory; debug_close_file(); resources_get_string("EventSnapshotDir", &directory); st = lib_msprintf("debug%06d", debug_file_current); filename = util_concat(directory, st, FSDEV_EXT_SEP_STR, "log", NULL); lib_free(st); debug_file = fopen(filename, MODE_WRITE_TEXT); lib_free(filename); }
/* create the default directory where prefs, fliplist, autostart images etc are stored a pointer to the resulting path is returned, and it should be freed by the caller. */ static char *archdep_make_default_pref_path(int create) { char *path; if (archdep_pref_path == NULL) { const char *home; home = archdep_home_path(); path = util_concat(home, "/.vice", NULL); } else { path = lib_stralloc(archdep_pref_path); } if(create) { if (access(path, F_OK)) { mkdir(path, S_IRWXU); } } return path; }
static int archdep_search_path(const char *name, char *pBuf, int lBuf) { const int flags = SEARCH_CUR_DIRECTORY|SEARCH_IGNORENETERRS; char *path = ""; /* PATH environment variable */ char *pgmName = util_concat(name, ".exe", NULL); // Search the program in the path DosScanEnv("PATH", &path); if (DosSearchPath(flags, path, pgmName, pBuf, lBuf)) { return -1; } lib_free(pgmName); return 0; }
const char *archdep_boot_path(void) { static char *boot_path = NULL; if (!boot_path) { char drive[_MAX_DRIVE+_MAX_DIR]; char dir[_MAX_DIR]; char fname[_MAX_FNAME+_MAX_EXT]; char ext[_MAX_EXT]; _splitpath(argv0, drive, dir, fname, ext); if (strlen(dir)) { *(dir + strlen(dir) - 1) = '\0'; // cut last backslash } boot_path = util_concat(drive, dir, NULL); } return boot_path; }
int archdep_default_logger(const char *lvl, const char *txt) { // // This is used if archdep_open_default_log_file returns NULL // #ifndef __X1541__ char *text = util_concat(lvl, txt, NULL); WinSendMsg(hwndLog, WM_INSERT, text, FALSE); lib_free(text); #endif if (fLog) { fprintf(fLog, "%s%s\n", lvl, txt); } return 0; }
DIR *opendir(const char *path) { DIR *dir; TCHAR *st_filter; dir = lib_malloc(sizeof(DIR)); dir->filter = util_concat(path, "\\*", NULL); st_filter = system_mbstowcs_alloc(dir->filter); dir->handle = FindFirstFile(st_filter, &dir->find_data); system_mbstowcs_free(st_filter); if (dir->handle == INVALID_HANDLE_VALUE) { return NULL; } dir->first_passed = 0; return dir; }
unsigned int rawfile_remove(const char *src_name, const char *path) { char *complete_src; int rc; if (path == NULL) complete_src = lib_stralloc(src_name); else complete_src = util_concat(path, FSDEV_DIR_SEP_STR, src_name, NULL); rc = ioutil_remove(complete_src); lib_free(complete_src); if (rc < 0) return FILEIO_FILE_NOT_FOUND; return FILEIO_FILE_SCRATCHED; }
int archdep_search_path(const char *name, char *pBuf, int lBuf) { const int flags = SEARCH_CUR_DIRECTORY|SEARCH_IGNORENETERRS; char *path = ""; /* PATH environment variable */ char *pgmName = util_concat(name, ".exe", NULL); // Search the program in the path if (DosScanEnv("PATH", &path)) { log_warning(archlog, "Environment variable PATH not found."); } if (DosSearchPath(flags, path, pgmName, pBuf, lBuf)) { log_error(archlog, "File \"%s\" not found.", pgmName); return -1; } lib_free(pgmName); return 0; }
FILE *archdep_open_default_log_file(void) { if (run_from_wb) { char *fname; FILE *f; fname = util_concat(archdep_boot_path(), "vice.log", NULL); f = fopen(fname, MODE_WRITE_TEXT); lib_free(fname); if (f == NULL) { return stdout; } return f; } else { return stdout; } }
int server_help(int sock, int argc, char **argv) { server_function_t *func; char buffer[RECV_BUFFER]; if (strncmp(argv[0], "help", 4)) { server_reply(sock, "Unknown command"); } server_reply(sock, "HELP:"); for (func = server_functions; func->sf_name; ++func) { util_concat(buffer, sizeof buffer, func->sf_name, "\t", func->sf_help, NULL); server_reply(sock, buffer); } return 1; }
var_t * exp_math_string(int op, var_t *left, var_t *right) { char *l, *r, x[EXP_STRLEN]; var_t *v; l = left->v_data; r = right->v_data; if (l == NULL) { l = "(null)"; } if (r == NULL) { r = "(null)"; } switch (op) { case '+': break; default: log_error("exp_math_string: bad operation"); return NULL; } if (util_concat(x, sizeof x, l, r, NULL) == -1) { log_error("exp_math_string: util_concat: buffer exhausted"); return NULL; } v = var_create(VT_STRING, NULL, x, VF_COPYDATA | VF_EXP_FREE); if (v == NULL) { log_error("exp_math_string: var_create failed"); } return v; }