// given a valid XSTR() tag piece of text, extract the string portion, return it in out, nonzero on success int lcl_ext_get_text(const SCP_string &xstr, SCP_string &out) { size_t open_quote_pos, close_quote_pos; // this is some crazy wack-ass code. // look for the open quote open_quote_pos = xstr.find('\"'); if (open_quote_pos == SCP_string::npos) { error_display(0, "Error parsing XSTR() tag %s\n", xstr.c_str()); return 0; } // look for the close quote close_quote_pos = xstr.find('\"', open_quote_pos+1); if (close_quote_pos == SCP_string::npos) { error_display(0, "Error parsing XSTR() tag %s\n", xstr.c_str()); return 0; } // now that we know the boundaries of the actual string in the XSTR() tag, copy it out.assign(xstr, open_quote_pos + 1, close_quote_pos - open_quote_pos - 1); // success return 1; }
ParticleEffectIndex parseEffectElement(EffectType forcedType, const SCP_string& name) { if (!optional_string("$New Effect")) { SCP_string newName; stuff_string(newName, F_NAME); auto index = ParticleManager::get()->getEffectByName(newName); if (index < 0) { error_display(0, "Unknown particle effect name '%s' encountered!", newName.c_str()); } if (forcedType != EffectType::Invalid) { // Validate the effect type auto effect = ParticleManager::get()->getEffect(index); if (effect->getType() != forcedType) { error_display(0, "Particle effect '%s' has the wrong effect type! Expected %s but was %s!", getEffectTypeName(forcedType), getEffectTypeName(effect->getType())); } } return index; } if (forcedType == EffectType::Invalid) { forcedType = parseEffectType(); } auto effect = constructEffect(name, forcedType); return ParticleManager::get()->addEffect(effect); }
void files_open(FS_ArchiveID archiveId, FS_Path archivePath) { files_data* data = (files_data*) calloc(1, sizeof(files_data)); if(data == NULL) { error_display(NULL, NULL, NULL, "Failed to allocate files data."); return; } data->populateData.recursive = false; data->populateData.includeBase = false; data->populateData.dirsFirst = true; data->populateData.filter = files_filter; data->populateData.filterData = data; data->populateData.finished = true; data->populated = false; data->showDirectories = true; data->showCias = true; data->showTickets = true; data->showMisc = true; data->archiveId = archiveId; data->archivePath.type = archivePath.type; data->archivePath.size = archivePath.size; if(archivePath.data != NULL) { data->archivePath.data = calloc(1, data->archivePath.size); if(data->archivePath.data == NULL) { error_display(NULL, NULL, NULL, "Failed to allocate files data."); files_free_data(data); return; } memcpy((void*) data->archivePath.data, archivePath.data, data->archivePath.size); } else { data->archivePath.data = NULL; } snprintf(data->currDir, FILE_PATH_MAX, "/"); data->dirItem = NULL; Result res = 0; if(R_FAILED(res = FSUSER_OpenArchive(&data->archive, archiveId, archivePath))) { error_display_res(NULL, NULL, NULL, res, "Failed to open file listing archive."); files_free_data(data); return; } list_display("Files", "A: Select, B: Back, X: Refresh, Y: Dir, Select: Filter", data, files_update, files_draw_top); }
EnhancedSoundPriority convert_to_enhanced_priority(const char * priority_str) { Assertion(priority_str != NULL, "convert_to_enhanced_priority given null priority_str!"); if (!stricmp(priority_str, "Must Play")) { return SND_ENHANCED_PRIORITY_MUST_PLAY; } else if (!stricmp(priority_str, "High")) { return SND_ENHANCED_PRIORITY_HIGH; } else if (!stricmp(priority_str, "Medium-High")) { return SND_ENHANCED_PRIORITY_MEDIUM_HIGH; } else if (!stricmp(priority_str, "Medium")) { return SND_ENHANCED_PRIORITY_MEDIUM; } else if (!stricmp(priority_str, "Medium-Low")) { return SND_ENHANCED_PRIORITY_MEDIUM_LOW; } else if (!stricmp(priority_str, "Low")) { return SND_ENHANCED_PRIORITY_LOW; } else { error_display(1, "Unknown enhanced sound priority: %s\n", priority_str); return SND_ENHANCED_PRIORITY_INVALID; } }
Handle task_populate_pending_titles(list_item* items, u32* count, u32 max) { if(items == NULL || count == NULL || max == 0) { return 0; } task_clear_pending_titles(items, count); populate_pending_titles_data* data = (populate_pending_titles_data*) calloc(1, sizeof(populate_pending_titles_data)); data->items = items; data->count = count; data->max = max; Result eventRes = svcCreateEvent(&data->cancelEvent, 1); if(R_FAILED(eventRes)) { error_display_res(NULL, NULL, eventRes, "Failed to create pending title list cancel event."); free(data); return 0; } if(threadCreate(task_populate_pending_titles_thread, data, 0x4000, 0x18, 1, true) == NULL) { error_display(NULL, NULL, "Failed to create pending title list thread."); svcCloseHandle(data->cancelEvent); free(data); return 0; } return data->cancelEvent; }
EffectTiming EffectTiming::parseTiming() { EffectTiming timing; if (optional_string("+Duration:")) { if (optional_string("Onetime")) { timing.m_duration = Duration::Onetime; } else if (optional_string("Always")) { timing.m_duration = Duration::Always; } else { timing.m_duration = Duration::Range; timing.m_durationRange = util::parseUniformRange<float>(false); } } if (optional_string("+Delay:")) { if (timing.m_duration == Duration::Onetime) { error_display(0, "+Delay is not valid for one-time effects!"); } else { timing.m_delayRange = util::parseUniformRange<float>(false); } } return timing; }
void dumpnand_open() { data_op_data* data = (data_op_data*) calloc(1, sizeof(data_op_data)); if(data == NULL) { error_display(NULL, NULL, NULL, "Failed to allocate dump NAND data."); return; } data->data = data; data->op = DATAOP_COPY; data->copyEmpty = true; data->total = 1; data->isSrcDirectory = dumpnand_is_src_directory; data->makeDstDirectory = dumpnand_make_dst_directory; data->openSrc = dumpnand_open_src; data->closeSrc = dumpnand_close_src; data->getSrcSize = dumpnand_get_src_size; data->readSrc = dumpnand_read_src; data->openDst = dumpnand_open_dst; data->closeDst = dumpnand_close_dst; data->writeDst = dumpnand_write_dst; data->error = dumpnand_error; data->finished = true; prompt_display("Confirmation", "Dump raw NAND image to the SD card?", COLOR_TEXT, true, data, NULL, NULL, dumpnand_onresponse); }
static void files_action_open(linked_list* items, list_item* selected, files_data* parent) { files_action_data* data = (files_action_data*) calloc(1, sizeof(files_action_data)); if(data == NULL) { error_display(NULL, NULL, "Failed to allocate files action data."); return; } data->items = items; data->selected = selected; data->parent = parent; data->containsCias = false; data->containsTickets = false; linked_list_iter iter; linked_list_iterate(data->items, &iter); while(linked_list_iter_has_next(&iter)) { file_info* info = (file_info*) ((list_item*) linked_list_iter_next(&iter))->data; if(info->isCia) { data->containsCias = true; } else if(info->isTicket) { data->containsTickets = true; } } list_display((((file_info*) selected->data)->attributes & FS_ATTRIBUTE_DIRECTORY) ? "Directory Action" : "File Action", "A: Select, B: Return", data, files_action_update, files_action_draw_top); }
void init() { bSmartDiagnostics = true; //true to enable smart diagnostic screen bCompetitionMode = true; //true to enable competition mode displaySplash("Mecanum Bot", "", true); bool ok = false; while(!ok) { const int testcount = 2; bool test[testcount] = { errorcheck(1,0,1,MOTORCON), errorcheck(1,0,2,MOTORCON)}; string desc[testcount] = {"MC1-1","MC1-2"}; ok = error_display(test,desc,testcount); if (!ok) { PlayTone(440, 50); if (test[0] == false && test[1] == false){ nxtDisplayCenteredTextLine(7, "Reboot MC!"); } } else { ClearSounds(); } } eraseDisplay(); gyro_init(HTGYRO); wait1Msec(50); nxtbarOn(); return; }
// given a valid XSTR() tag piece of text, extract the string portion, return it in out, nonzero on success int lcl_ext_get_text(const char *xstr, char *out) { size_t str_start, str_end; size_t str_len; const char *p, *p2; Assert(xstr != NULL); Assert(out != NULL); str_len = strlen(xstr); // this is some crazy wack-ass code. // look for the open quote str_start = str_end = 0; p = strstr(xstr, "\""); if(p == NULL){ error_display(0, "Error parsing XSTR() tag %s\n", xstr); return 0; } else { str_start = p - xstr + 1; } // make sure we're not about to walk past the end of the string if(static_cast<size_t>(p - xstr) >= str_len){ error_display(0, "Error parsing XSTR() tag %s\n", xstr); return 0; } // look for the close quote p2 = strstr(p+1, "\""); if(p2 == NULL){ error_display(0, "Error parsing XSTR() tag %s\n", xstr); return 0; } else { str_end = p2 - xstr; } // check bounds if (str_end - str_start > PARSE_BUF_SIZE - 1) { error_display(0, "String cannot fit within XSTR buffer!\n\n%s\n", xstr); return 0; } // now that we know the boundaries of the actual string in the XSTR() tag, copy it memcpy(out, xstr + str_start, str_end - str_start); // success return 1; }
ParticleEffectIndex parseEffect(const SCP_string& objectName) { SCP_string name; stuff_string(name, F_NAME); auto idx = ParticleManager::get()->getEffectByName(name); if (idx < 0) { if (objectName.empty()) { error_display(0, "Unknown particle effect name '%s' encountered!", name.c_str()); } else { error_display(0, "Unknown particle effect name '%s' encountered while parsing '%s'!", name.c_str(), objectName.c_str()); } } return idx; }
static void action_rename_kbd_finished(void* data, char* input) { rename_data* renameData = (rename_data*) data; if(strlen(input) == 0) { error_display(NULL, NULL, NULL, "No name specified."); } file_info* targetInfo = (file_info*) renameData->target->data; Result res = 0; char parentPath[FILE_PATH_MAX] = {'\0'}; util_get_parent_path(parentPath, targetInfo->path, FILE_PATH_MAX); char dstPath[FILE_PATH_MAX] = {'\0'}; snprintf(dstPath, FILE_PATH_MAX, "%s%s", parentPath, input); FS_Path* srcFsPath = util_make_path_utf8(targetInfo->path); if(srcFsPath != NULL) { FS_Path* dstFsPath = util_make_path_utf8(dstPath); if(dstFsPath != NULL) { if(targetInfo->isDirectory) { res = FSUSER_RenameDirectory(targetInfo->archive, *srcFsPath, targetInfo->archive, *dstFsPath); } else { res = FSUSER_RenameFile(targetInfo->archive, *srcFsPath, targetInfo->archive, *dstFsPath); } util_free_path_utf8(dstFsPath); } else { res = R_FBI_OUT_OF_MEMORY; } util_free_path_utf8(srcFsPath); } else { res = R_FBI_OUT_OF_MEMORY; } if(R_SUCCEEDED(res)) { if(strncmp(renameData->target->name, "<current directory>", LIST_ITEM_NAME_MAX) != 0 && strncmp(renameData->target->name, "<current file>", LIST_ITEM_NAME_MAX) != 0) { strncpy(renameData->target->name, input, LIST_ITEM_NAME_MAX); } strncpy(targetInfo->name, input, FILE_NAME_MAX); strncpy(targetInfo->path, dstPath, FILE_PATH_MAX); linked_list_sort(renameData->items, util_compare_file_infos); prompt_display("Success", "Renamed.", COLOR_TEXT, false, NULL, NULL, NULL); } else { error_display_res(NULL, NULL, NULL, res, "Failed to perform rename."); } free(data); }
// given a valid XSTR() tag piece of text, extract the string portion, return it in out, nonzero on success int lcl_ext_get_text(char *xstr, char *out) { int str_start, str_end; int str_len; char *p, *p2; Assert(xstr != NULL); Assert(out != NULL); str_len = strlen(xstr); // this is some crazy wack-ass code. // look for the open quote str_start = str_end = 0; p = strstr(xstr, "\""); if(p == NULL){ error_display(0, "Error parsing XSTR() tag %s\n", xstr); return 0; } else { str_start = p - xstr + 1; } // make sure we're not about to walk past the end of the string if((p - xstr) >= str_len){ error_display(0, "Error parsing XSTR() tag %s\n", xstr); return 0; } // look for the close quote p2 = strstr(p+1, "\""); if(p2 == NULL){ error_display(0, "Error parsing XSTR() tag %s\n", xstr); return 0; } else { str_end = p2 - xstr; } // now that we know the boundaries of the actual string in the XSTR() tag. copy it memcpy(out, xstr + str_start, str_end - str_start); // success return 1; }
void titles_open() { titles_data* data = (titles_data*) calloc(1, sizeof(titles_data)); if(data == NULL) { error_display(NULL, NULL, NULL, "Failed to allocate titles data."); return; } data->populateData.finished = true; list_display("Titles", "A: Select, B: Return, X: Refresh", data, titles_update, titles_draw_top); }
int parse_font() { int font_idx; SCP_string input; stuff_string(input, F_NAME); SCP_stringstream ss(input); int fontNum; ss >> fontNum; if (ss.fail()) { fontNum = FontManager::getFontIndex(input); if (fontNum < 0) { error_display(0, "Invalid font name \"%s\"!", input.c_str()); font_idx = -1; } else { font_idx = fontNum; } } else { if (fontNum < 0 || fontNum >= FontManager::numberOfFonts()) { error_display(0, "Invalid font number %d! must be greater or equal to zero and smaller than %d.", fontNum, FontManager::numberOfFonts()); font_idx = -1; } else { font_idx = fontNum; } } return font_idx; }
bool action_install_cdn_error(void* data, u32 index, Result res) { install_cdn_data* installData = (install_cdn_data*) data; if(res == R_FBI_CANCELLED) { prompt_display("Failure", "Install cancelled.", COLOR_TEXT, false, installData->ticket, NULL, ui_draw_ticket_info, NULL); } else if(res == R_FBI_HTTP_RESPONSE_CODE) { error_display(NULL, installData->ticket, ui_draw_ticket_info, "Failed to install CDN title.\nHTTP server returned response code %d", installData->responseCode); } else { error_display_res(NULL, installData->ticket, ui_draw_ticket_info, res, "Failed to install CDN title."); } return false; }
void action_rename(linked_list* items, list_item* selected) { rename_data* data = (rename_data*) calloc(1, sizeof(rename_data)); if(data == NULL) { error_display(NULL, NULL, NULL, "Failed to allocate rename data."); return; } data->items = items; data->target = selected; kbd_display("Enter New Name", ((file_info*) selected->data)->name, data, NULL, action_rename_kbd_finished, action_rename_kbd_canceled); }
static void titles_action_open(linked_list* items, list_item* selected) { titles_action_data* data = (titles_action_data*) calloc(1, sizeof(titles_action_data)); if(data == NULL) { error_display(NULL, NULL, "Failed to allocate titles action data."); return; } data->items = items; data->selected = selected; list_display("Title Action", "A: Select, B: Return", data, titles_action_update, titles_action_draw_top); }
int parseAnimation(bool critical) { SCP_string name; stuff_string(name, F_FILESPEC); auto handle = bm_load_animation(name.c_str()); if (handle < 0) { int level = critical ? 1 : 0; error_display(level, "Failed to load effect %s!", name.c_str()); } return handle; }
void action_delete_ticket(linked_list* items, list_item* selected) { delete_ticket_data* data = (delete_ticket_data*) calloc(1, sizeof(delete_ticket_data)); if(data == NULL) { error_display(NULL, NULL, NULL, "Failed to allocate delete ticket data."); return; } data->items = items; data->selected = selected; prompt_display("Confirmation", "Delete the selected ticket?", COLOR_TEXT, true, data, NULL, action_delete_ticket_draw_top, action_delete_ticket_onresponse); }
static void action_delete_title_internal(linked_list* items, list_item* selected, const char* message, bool ticket) { delete_title_data* data = (delete_title_data*) calloc(1, sizeof(delete_title_data)); if(data == NULL) { error_display(NULL, NULL, "Failed to allocate delete title data."); return; } data->items = items; data->selected = selected; data->ticket = ticket; prompt_display("Confirmation", message, COLOR_TEXT, true, data, action_delete_title_draw_top, action_delete_title_onresponse); }
static void files_action_open(linked_list* items, list_item* selected, files_data* parent) { files_action_data* data = (files_action_data*) calloc(1, sizeof(files_action_data)); if(data == NULL) { error_display(NULL, NULL, NULL, "Failed to allocate files action data."); return; } data->items = items; data->selected = selected; data->parent = parent; list_display(((file_info*) selected->data)->isDirectory ? "Directory Action" : "File Action", "A: Select, B: Return", data, files_action_update, files_action_draw_top); }
static void action_install_tickets_onresponse(ui_view* view, void* data, bool response) { install_tickets_data* installData = (install_tickets_data*) data; if(response) { installData->cancelEvent = task_data_op(&installData->installInfo); if(installData->cancelEvent != 0) { info_display("Installing ticket(s)", "Press B to cancel.", true, data, action_install_tickets_update, action_install_tickets_draw_top); } else { error_display(NULL, installData->base, ui_draw_file_info, "Failed to initiate ticket installation."); action_install_tickets_free_data(installData); } } else { action_install_tickets_free_data(installData); } }
static int create_client(char *addr, int port) { int sock; struct protoent *proto; struct sockaddr_in sin; proto = getprotobyname("tcp"); if (proto == 0) return (-1); sock = socket(AF_INET, SOCK_STREAM, proto->p_proto); sin.sin_family = AF_INET; sin.sin_port = htons(port); sin.sin_addr.s_addr = inet_addr(addr); if (connect(sock, (const struct sockaddr *)&sin, sizeof(sin)) == -1) error_display("ERROR: connect()"); return (sock); }
static void action_write_locale_dir_config(ui_view* view, void* data, bool response) { config_info *info = (config_info*) data; if(response) { FILE* config_file = fopen("/locales.conf", "w"); // TODO hardcoding if (config_file != NULL) { fprintf(config_file, "%s\n", info->path); fclose(config_file); char* msg = (char*) calloc(PATH_MAX+18, sizeof(char)); sprintf(msg, "Wrote %s to /locales.conf", info->path); prompt_display("Success", msg, COLOR_TEXT, false, NULL, NULL, NULL, NULL); } else { error_display(NULL, NULL, NULL, "Failed to write config."); } } }
static void action_delete_system_save_data_update(ui_view* view, void* data, float* progress, char* text) { delete_system_save_data_data* deleteData = (delete_system_save_data_data*) data; system_save_data_info* info = (system_save_data_info*) deleteData->selected->data; FS_SystemSaveDataInfo sysInfo = {.mediaType = MEDIATYPE_NAND, .saveId = info->systemSaveDataId}; Result res = FSUSER_DeleteSystemSaveData(sysInfo); ui_pop(); info_destroy(view); if(R_FAILED(res)) { error_display_res(info, ui_draw_system_save_data_info, res, "Failed to delete system save data."); } else { linked_list_remove(deleteData->items, deleteData->selected); task_free_system_save_data(deleteData->selected); prompt_display("Success", "System save data deleted.", COLOR_TEXT, false, NULL, NULL, NULL); } free(data); } static void action_delete_system_save_data_onresponse(ui_view* view, void* data, bool response) { if(response) { info_display("Deleting System Save Data", "", false, data, action_delete_system_save_data_update, action_delete_system_save_data_draw_top); } else { free(data); } } void action_delete_system_save_data(linked_list* items, list_item* selected) { delete_system_save_data_data* data = (delete_system_save_data_data*) calloc(1, sizeof(delete_system_save_data_data)); if(data == NULL) { error_display(NULL, NULL, "Failed to allocate delete system save data data."); return; } data->items = items; data->selected = selected; prompt_display("Confirmation", "Delete the selected system save data?", COLOR_TEXT, true, data, action_delete_system_save_data_draw_top, action_delete_system_save_data_onresponse); }
void action_import_twl_save(linked_list* items, list_item* selected) { import_twl_save_data* data = (import_twl_save_data*) calloc(1, sizeof(import_twl_save_data)); if(data == NULL) { error_display(NULL, NULL, "Failed to allocate import TWL save data."); return; } data->title = (title_info*) selected->data; data->importInfo.data = data; data->importInfo.op = DATAOP_COPY; data->importInfo.copyBufferSize = 16 * 1024; data->importInfo.copyEmpty = true; data->importInfo.total = 1; data->importInfo.isSrcDirectory = action_import_twl_save_is_src_directory; data->importInfo.makeDstDirectory = action_import_twl_save_make_dst_directory; data->importInfo.openSrc = action_import_twl_save_open_src; data->importInfo.closeSrc = action_import_twl_save_close_src; data->importInfo.getSrcSize = action_import_twl_save_get_src_size; data->importInfo.readSrc = action_import_twl_save_read_src; data->importInfo.openDst = action_import_twl_save_open_dst; data->importInfo.closeDst = action_import_twl_save_close_dst; data->importInfo.writeDst = action_import_twl_save_write_dst; data->importInfo.suspendCopy = action_import_twl_save_suspend_copy; data->importInfo.restoreCopy = action_import_twl_save_restore_copy; data->importInfo.suspend = action_import_twl_save_suspend; data->importInfo.restore = action_import_twl_save_restore; data->importInfo.error = action_import_twl_save_error; data->importInfo.finished = true; prompt_display("Confirmation", "Import the save of the selected title?", COLOR_TEXT, true, data, action_import_twl_save_draw_top, action_import_twl_save_onresponse); }
int main(int ac, char **av) { int port; int sock; char buf[1024]; if (ac != 3) usage(av[0]); port = ft_atoi(av[2]); if (ft_strcmp(av[1], "localhost") == 0) av[1] = "127.0.0.1"; if ((sock = create_client(av[1], port)) == -1) error_display("ERROR: sock()"); ft_bzero(buf, 1024); while (1) ft_display(buf, sock); close(sock); return (0); }
void titles_open() { titles_data* data = (titles_data*) calloc(1, sizeof(titles_data)); if(data == NULL) { error_display(NULL, NULL, NULL, "Failed to allocate titles data."); return; } data->populateData.filter = titles_filter; data->populateData.filterData = data; data->populateData.finished = true; data->showGameCard = true; data->showSD = true; data->showNAND = true; list_display("Titles", "A: Select, B: Return, X: Refresh, Select: Filter", data, titles_update, titles_draw_top); }
void ft_display(char *buf, int sock) { int ret; int n; ft_bzero(buf, 1024); ft_putstr("\x1B[31mft_p> \x1B[0m"); ret = read(0, buf, 1024); buf[ret] = '\0'; if ((n = send(sock, buf, ft_strlen(buf), 0)) < 0) error_display("ERROR: send()"); else if (n > 1) { if (ft_strncmp(buf, "put", 3) == 0 || ft_strncmp(buf, "get", 3) == 0 || ft_strncmp(buf, "help", 4) == 0) execcmd(buf, sock); else ft_display_norme(n, sock, buf); } }