EMBX_THREAD EMBX_OS_ThreadCreate(void (*thread)(void *), void *param, EMBX_INT priority, const EMBX_CHAR *name) { task_t *t; EMBX_Info(EMBX_INFO_OS, (">>>>ThreadCreate\n")); if(name == EMBX_DEFAULT_THREAD_NAME) { name = get_default_name(); } t = task_create(thread, param, EMBX_DEFAULT_THREAD_STACK_SIZE, priority, name, 0); if(t == EMBX_INVALID_THREAD) { EMBX_DebugMessage(("ThreadCreate: task_create failed.\n")); } EMBX_Info(EMBX_INFO_OS, ("<<<<ThreadCreate\n")); return t; }
int z_restore( int argc, zword_t table, zword_t bytes, zword_t name ) { char new_name[Z_FILENAME_MAX + Z_PATHNAME_MAX + 1]; char default_name[Z_FILENAME_MAX + Z_PATHNAME_MAX + 1]; FILE *afp; #if defined BUFFER_FILES char afpbuffer[BUFSIZ]; #endif int status; status = 0; if ( argc == 3 ) { get_default_name( default_name, name ); if ( get_file_name( new_name, default_name, GAME_LOAD_AUX ) == 0 ) { goto finished; } if ( ( afp = fopen( new_name, "rb" ) ) == NULL ) { goto finished; } #if defined BUFFER_FILES setbuf( afp, afpbuffer ); #endif status = fread( datap + table, bytes, 1, afp ); fclose( afp ); if ( status != 0 ) { strcpy( auxilary_name, default_name ); } status = !status; } else { /* Get the file name */ status = 1; if ( get_file_name( new_name, save_name, GAME_RESTORE ) == 0 ) { /* Do the restore operation */ if ( save_restore( new_name, GAME_RESTORE ) == 0 ) { /* Reset the status region (this is just for Seastalker) */ if ( h_type < V4 ) { z_split_window( 0 ); blank_status_line( ); } /* Cleanup file */ file_cleanup( new_name, GAME_SAVE ); /* Save the new name as the default file name */ strcpy( save_name, new_name ); /* Indicate success */ status = 0; } } } finished: /* Return result of save to Z-code */ if ( h_type < V4 ) { conditional_jump( status == 0 ); } else { store_operand( (zword_t)(( status == 0 ) ? 2 : 0) ); } return ( status ); } /* z_restore */
void Archive::make_index() { num_indices = 0; CHECK_COM(in_arc->GetNumberOfItems(&num_indices)); file_list.clear(); file_list.reserve(num_indices); struct DirInfo { UInt32 index; UInt32 parent; wstring name; bool operator<(const DirInfo& dir_info) const { if (parent == dir_info.parent) return lstrcmpiW(name.c_str(), dir_info.name.c_str()) < 0; else return parent < dir_info.parent; } }; typedef set<DirInfo> DirList; map<UInt32, unsigned> dir_index_map; DirList dir_list; DirInfo dir_info; UInt32 dir_index = 0; ArcFileInfo file_info; wstring path; PropVariant prop; for (UInt32 i = 0; i < num_indices; i++) { // is directory? file_info.is_dir = in_arc->GetProperty(i, kpidIsDir, prop.ref()) == S_OK && prop.is_bool() && prop.get_bool(); // file name if (in_arc->GetProperty(i, kpidPath, prop.ref()) == S_OK && prop.is_str()) path.assign(prop.get_str()); else path.assign(get_default_name()); size_t name_end_pos = path.size(); while (name_end_pos && is_slash(path[name_end_pos - 1])) name_end_pos--; size_t name_pos = name_end_pos; while (name_pos && !is_slash(path[name_pos - 1])) name_pos--; file_info.name.assign(path.data() + name_pos, name_end_pos - name_pos); // split path into individual directories and put them into DirList dir_info.parent = c_root_index; size_t begin_pos = 0; while (begin_pos < name_pos) { dir_info.index = dir_index; size_t end_pos = begin_pos; while (end_pos < name_pos && !is_slash(path[end_pos])) end_pos++; if (end_pos != begin_pos) { dir_info.name.assign(path.data() + begin_pos, end_pos - begin_pos); pair<DirList::iterator, bool> ins_pos = dir_list.insert(dir_info); if (ins_pos.second) dir_index++; dir_info.parent = ins_pos.first->index; } begin_pos = end_pos + 1; } file_info.parent = dir_info.parent; if (file_info.is_dir) { dir_info.index = dir_index; dir_info.parent = file_info.parent; dir_info.name = file_info.name; pair<DirList::iterator, bool> ins_pos = dir_list.insert(dir_info); if (ins_pos.second) { dir_index++; dir_index_map[dir_info.index] = i; } else { if (dir_index_map.count(ins_pos.first->index)) file_info.parent = c_dup_index; else dir_index_map[ins_pos.first->index] = i; } } file_list.push_back(file_info); } // add directories that not present in archive index file_list.reserve(file_list.size() + dir_list.size() - dir_index_map.size()); dir_index = num_indices; for_each(dir_list.begin(), dir_list.end(), [&] (const DirInfo& dir_info) { if (dir_index_map.count(dir_info.index) == 0) { dir_index_map[dir_info.index] = dir_index; file_info.parent = dir_info.parent; file_info.name = dir_info.name; file_info.is_dir = true; dir_index++; file_list.push_back(file_info); } }); // fix parent references for_each(file_list.begin(), file_list.end(), [&] (ArcFileInfo& file_info) { if (file_info.parent != c_root_index) file_info.parent = dir_index_map[file_info.parent]; }); // create search index file_list_index.clear(); file_list_index.reserve(file_list.size()); for (UInt32 i = 0; i < file_list.size(); i++) { file_list_index.push_back(i); } sort(file_list_index.begin(), file_list_index.end(), [&] (UInt32 left, UInt32 right) -> bool { return file_list[left] < file_list[right]; }); load_arc_attr(); }
static krb5_error_code KRB5_CALLCONV xcc_api_get_default_name(krb5_context context, char **str) { return get_default_name(context, &krb5_xcc_api_ops, "API:11111111-71F2-48EB-94C4-7D7392E900E5", str); }
void z_restore (void) { char new_name[MAX_FILE_NAME + 1]; char default_name[MAX_FILE_NAME + 1]; FILE *gfp; zword success = 0; if (zargc != 0) { /* Get the file name */ get_default_name (default_name, (zargc >= 3) ? zargs[2] : 0); if (os_read_file_name (new_name, default_name, FILE_LOAD_AUX) == 0) goto finished; strcpy (auxilary_name, default_name); /* Open auxilary file */ if ((gfp = fopen (new_name, "rb")) == NULL) goto finished; /* Load auxilary file */ success = fread (zmp + zargs[0], 1, zargs[1], gfp); /* Close auxilary file */ fclose (gfp); } else { long pc; zword release; zword addr; int i; /* Get the file name */ if (os_read_file_name (new_name, save_name, FILE_RESTORE) == 0) goto finished; strcpy (save_name, new_name); /* Open game file */ if ((gfp = fopen (new_name, "rb")) == NULL) goto finished; if (f_setup.save_quetzal) { success = restore_quetzal (gfp, story_fp); } else { /* Load game file */ release = (unsigned) fgetc (gfp) << 8; release |= fgetc (gfp); (void) fgetc (gfp); (void) fgetc (gfp); /* Check the release number */ if (release == h_release) { pc = (long) fgetc (gfp) << 16; pc |= (unsigned) fgetc (gfp) << 8; pc |= fgetc (gfp); SET_PC (pc); sp = stack + (fgetc (gfp) << 8); sp += fgetc (gfp); fp = stack + (fgetc (gfp) << 8); fp += fgetc (gfp); for (i = (int) (sp - stack); i < STACK_SIZE; i++) { stack[i] = (unsigned) fgetc (gfp) << 8; stack[i] |= fgetc (gfp); } fseek (story_fp, 0, SEEK_SET); for (addr = 0; addr < h_dynamic_size; addr++) { int skip = fgetc (gfp); for (i = 0; i < skip; i++) zmp[addr++] = fgetc (story_fp); zmp[addr] = fgetc (gfp); (void) fgetc (story_fp); } /* Check for errors */ if (ferror (gfp) || ferror (story_fp) || addr != h_dynamic_size) success = -1; else /* Success */ success = 2; } else print_string ("Invalid save file\n"); } if ((short) success >= 0) { /* Close game file */ fclose (gfp); if ((short) success > 0) { zbyte old_screen_rows; zbyte old_screen_cols; /* In V3, reset the upper window. */ if (h_version == V3) split_window (0); LOW_BYTE (H_SCREEN_ROWS, old_screen_rows); LOW_BYTE (H_SCREEN_COLS, old_screen_cols); /* Reload cached header fields. */ restart_header (); /* * Since QUETZAL files may be saved on many different machines, * the screen sizes may vary a lot. Erasing the status window * seems to cover up most of the resulting badness. */ if (h_version > V3 && h_version != V6 && (h_screen_rows != old_screen_rows || h_screen_cols != old_screen_cols)) erase_window (1); } } else os_fatal ("Error reading save file"); } finished: if (h_version <= V3) branch (success); else store (success); }/* z_restore */