char* MyStrStrI(const char* pFirst, const char* pSrch) { char* cp = (char*)pFirst; char* s1; char* s2; while (*cp) { s1 = cp; s2 = (char*)pSrch; while (*s1 && *s2 && !mame_strnicmp(s1, s2, 1)) s1++, s2++; if (!*s2) return cp; cp++; } return NULL; }
static void set_starting_view(int index, win_window_info *window, const char *view) { const char *defview = options_get_string("view"); int viewindex = -1; assert(GetCurrentThreadId() == main_threadid); // choose non-auto over auto if (strcmp(view, "auto") == 0 && strcmp(defview, "auto") != 0) view = defview; // auto view just selects the nth view if (strcmp(view, "auto") != 0) { // scan for a matching view name for (viewindex = 0; ; viewindex++) { const char *name = render_target_get_view_name(window->target, viewindex); // stop scanning if we hit NULL if (name == NULL) { viewindex = -1; break; } if (mame_strnicmp(name, view, strlen(view)) == 0) break; } } // if we don't have a match, default to the nth view if (viewindex == -1) { int scrcount; // count the number of screens for (scrcount = 0; Machine->drv->screen[scrcount].tag != NULL; scrcount++) ; // if we have enough screens to be one per monitor, assign in order if (video_config.numscreens >= scrcount) { // find the first view with this screen and this screen only for (viewindex = 0; ; viewindex++) { UINT32 viewscreens = render_target_get_view_screens(window->target, viewindex); if (viewscreens == (1 << index)) break; if (viewscreens == 0) { viewindex = -1; break; } } } // otherwise, find the first view that has all the screens if (viewindex == -1) { for (viewindex = 0; ; viewindex++) { UINT32 viewscreens = render_target_get_view_screens(window->target, viewindex); if (viewscreens == (1 << scrcount) - 1) break; if (viewscreens == 0) break; } } } // make sure it's a valid view if (render_target_get_view_name(window->target, viewindex) == NULL) viewindex = 0; // set the view render_target_set_view(window->target, viewindex); }
void ui_menu_file_selector::handle() { file_error err; const file_selector_entry *entry; const file_selector_entry *selected_entry = NULL; int bestmatch = 0; /* process the menu */ const ui_menu_event *event = process(0); if (event != NULL && event->itemref != NULL) { /* handle selections */ if (event->iptkey == IPT_UI_SELECT) { entry = (const file_selector_entry *) event->itemref; switch(entry->type) { case SELECTOR_ENTRY_TYPE_EMPTY: /* empty slot - unload */ *result = R_EMPTY; ui_menu::stack_pop(machine()); break; case SELECTOR_ENTRY_TYPE_CREATE: /* create */ *result = R_CREATE; ui_menu::stack_pop(machine()); break; case SELECTOR_ENTRY_TYPE_SOFTWARE_LIST: *result = R_SOFTLIST; ui_menu::stack_pop(machine()); break; case SELECTOR_ENTRY_TYPE_DRIVE: case SELECTOR_ENTRY_TYPE_DIRECTORY: /* drive/directory - first check the path */ err = zippath_opendir(entry->fullpath, NULL); if (err != FILERR_NONE) { /* this path is problematic; present the user with an error and bail */ ui_popup_time(1, "Error accessing %s", entry->fullpath); break; } current_directory.cpy(entry->fullpath); reset((ui_menu_reset_options)0); break; case SELECTOR_ENTRY_TYPE_FILE: /* file */ current_file.cpy(entry->fullpath); *result = R_FILE; ui_menu::stack_pop(machine()); break; } // reset the char buffer when pressing IPT_UI_SELECT if (filename_buffer[0] != '\0') memset(filename_buffer, '\0', ARRAY_LENGTH(filename_buffer)); } else if (event->iptkey == IPT_SPECIAL) { int buflen = strlen(filename_buffer); bool update_selected = FALSE; /* if it's a backspace and we can handle it, do so */ if ((event->unichar == 8 || event->unichar == 0x7f) && buflen > 0) { *(char *)utf8_previous_char(&filename_buffer[buflen]) = 0; update_selected = TRUE; if (ARRAY_LENGTH(filename_buffer) > 0) ui_popup_time(ERROR_MESSAGE_TIME, "%s", filename_buffer); } /* if it's any other key and we're not maxed out, update */ else if (event->unichar >= ' ' && event->unichar < 0x7f) { buflen += utf8_from_uchar(&filename_buffer[buflen], ARRAY_LENGTH(filename_buffer) - buflen, event->unichar); filename_buffer[buflen] = 0; update_selected = TRUE; if (ARRAY_LENGTH(filename_buffer) > 0) ui_popup_time(ERROR_MESSAGE_TIME, "%s", filename_buffer); } if (update_selected) { const file_selector_entry *cur_selected = (const file_selector_entry *)get_selection(); // check for entries which matches our filename_buffer: // from current entry to the end for (entry = cur_selected; entry != NULL; entry = entry->next) { if (entry->basename != NULL && filename_buffer != NULL) { int match = 0; for (int i = 0; i < ARRAY_LENGTH(filename_buffer); i++) { if (mame_strnicmp(entry->basename, filename_buffer, i) == 0) match = i; } if (match > bestmatch) { bestmatch = match; selected_entry = entry; } } } // and from the first entry to current one for (entry = entrylist; entry != cur_selected; entry = entry->next) { if (entry->basename != NULL && filename_buffer != NULL) { int match = 0; for (int i = 0; i < ARRAY_LENGTH(filename_buffer); i++) { if (mame_strnicmp(entry->basename, filename_buffer, i) == 0) match = i; } if (match > bestmatch) { bestmatch = match; selected_entry = entry; } } } if (selected_entry != NULL && selected_entry != cur_selected) set_selection((void *) selected_entry); } } else if (event->iptkey == IPT_UI_CANCEL) { // reset the char buffer also in this case if (filename_buffer[0] != '\0') memset(filename_buffer, '\0', ARRAY_LENGTH(filename_buffer)); } } }