/* key presses in the window used for a recipe name search string */ static int keypress_recipe_handler(window_info *win, int mx, int my, Uint32 key, Uint32 unikey) { char keychar = tolower(key_to_char(unikey)); last_recipe_key_time = SDL_GetTicks(); if ((keychar == SDLK_RETURN) && (key & ELW_CTRL)) { select_recipe(cur_recipe); return 1; } if ((keychar == '`') || (key & ELW_CTRL) || (key & ELW_ALT)) return 0; if (keychar == SDLK_ESCAPE) { clear_recipe_filter(); return 1; } if (string_input(recipe_name_filter, sizeof(recipe_name_filter), keychar) || (keychar == SDLK_RETURN)) { if (strlen(recipe_name_filter)) { size_t i; for (i=cur_recipe+1; i<cur_recipe+num_recipe_entries; i++) { size_t check = i % num_recipe_entries; if (recipes_store[check].name != NULL && safe_strcasestr(recipes_store[check].name, strlen(recipes_store[check].name), recipe_name_filter, strlen(recipe_name_filter)) != NULL) { /* have matching name so set as the current and make sure visible */ int first_displayed_recipe = vscrollbar_get_pos (win->window_id, recipe_win_scroll_id); int new_pos = first_displayed_recipe; cur_recipe = check; if (cur_recipe < first_displayed_recipe) new_pos = cur_recipe; else if (cur_recipe >= (first_displayed_recipe+num_displayed_recipes)) new_pos = cur_recipe - (num_displayed_recipes - 1); else break; vscrollbar_set_pos(win->window_id, recipe_win_scroll_id, new_pos); break; } } } return 1; } return 0; }
/* display or test the md5sum of the current map or the specified file */ int command_ckdata(char *text, int len) { const int DIGEST_LEN = 16; Uint8 digest[DIGEST_LEN]; char digest_str[DIGEST_LEN*2+1]; char expected_digest_str[DIGEST_LEN*2+1]; char result_str[256]; char filename[256]; /* paramters are optional, first is expected checksum value, second is filename */ /* if only a filename is specfied, we display checksum rather than do match */ filename[0] = digest_str[0] = expected_digest_str[0] = '\0'; text = getparams(text); if (*text) { /* if we have at least one space and the first string is of digest length, assume we matching */ char *tempstr = safe_strcasestr(text, strlen(text), " ", 1); if ((tempstr != NULL) && (strlen(text) - strlen(tempstr) == DIGEST_LEN*2)) { safe_strncpy2(expected_digest_str, text, DIGEST_LEN*2+1, DIGEST_LEN*2 ); /* trim leading space from filename */ while (*tempstr == ' ') tempstr++; if (*tempstr) safe_strncpy(filename, tempstr, 256); } /* else we only have a filename */ else safe_strncpy(filename, text, 256 ); } /* if no parameters default to current map elm file */ else safe_strncpy(filename, continent_maps[cur_map].name, 256 ); /* calculate, display checksum if we're not matching */ if (*filename && el_file_exists(filename) && get_file_digest(filename, digest)) { int i; for(i=0; i<DIGEST_LEN; i++) sprintf(&digest_str[2*i], "%02x", (int)digest[i]); digest_str[DIGEST_LEN*2] = 0; if (! *expected_digest_str) { safe_snprintf(result_str, sizeof(result_str), "#ckdata %s %s", digest_str, filename ); LOG_TO_CONSOLE(c_grey1,result_str); } } /* show help if something fails */ else { LOG_TO_CONSOLE(c_red2, "ckdata: invalid file or command syntax."); LOG_TO_CONSOLE(c_red1, "Show current map (elm): #ckdata"); LOG_TO_CONSOLE(c_red1, "Show specified file: #ckdata file_name"); LOG_TO_CONSOLE(c_red1, "Check specified file: #ckdata expected_checksum file_name"); return 1; } /* if we have an expected value, compare then display an appropriate message */ if (*expected_digest_str) { if (my_strcompare(digest_str, expected_digest_str)) LOG_TO_CONSOLE(c_green2,"ckdata: File matches expected checksum"); else LOG_TO_CONSOLE(c_red2,"ckdata: File does not match expected checksum"); } return 1; } /* end command_ckdata() */