bool dir_create(const char *p_dir) { assert(p_dir); char tmp_dir[MAX_FILENAME]; return_path(p_dir, "", tmp_dir, MAX_FILENAME); struct stat st; // Check the dir pprintfnl("Checking %s...",tmp_dir); if(stat(tmp_dir,&st) == -1 && errno == ENOENT) { pprintfnl("missing, try to create it..."); #ifdef WINDOWS if(mkdir(tmp_dir) != -1) { #else if(mkdir(tmp_dir,DEFAULT_DIR_MASK) != -1) { #endif pprintf("ok"); return(TRUE); } else { print_errno(TRUE); pprintf("failed"); return(FALSE); } } else { pprintf("ok"); return(TRUE); } }
/* * Utility */ void dir_list::update_path(char *p_dir) { char buffer[MAX_FILENAME]; return_path(p_dir, "", buffer, MAX_FILENAME); chdir(cwd); chdir(buffer); getcwd(p_dir,MAX_FILENAME); }
char * path_correction(char *p_file, int max_lenght) { char tmp[MAX_FILENAME]; return_path(NULL, p_file, tmp, MAX_FILENAME); assert(strlen(tmp) < (unsigned)max_lenght); strcpy(p_file, tmp); return(p_file); }
/*---------------------------------------------------------------------------- gzhandle file interface - compressed files ---------------------------------------------------------------------------- */ bool gzhandle::open(const char * p_dir, const char * p_file, const char *p_mode, bool safe) { char filename[MAX_FILENAME]; bool ret; assert(f == NULL); return_path(p_dir, p_file, filename, MAX_FILENAME); f = gzopen(filename, p_mode); ret = (f != NULL); if(!ret && safe) { char cwd[MAX_FILENAME]; PERROR(FALSE, "Unable to open %s!\nError: %s\nCurrent dir: %s", filename,strerror(errno),getcwd(cwd,MAX_FILENAME)); } return(ret); }
bool data_file::load(void) { DATA_FILE_SECTION *p_current = NULL; bool in_comment = FALSE; char line[MAX_TOKEN_LEN]; while(load_line(line)) { LINE_TYPE type = line_type_get(line); /* * Skip comments in input file */ if(type == LINE_COMMENT_START) { in_comment = TRUE; continue; } else if(type == LINE_COMMENT_STOP) { in_comment = FALSE; continue; } else if(in_comment) { continue; } switch(type) { case LINE_NONE: case LINE_COMMENT: case LINE_COMMENT_START: case LINE_COMMENT_STOP: break; // Create and load whole section case LINE_SECTION_START: p_current = section_new(); p_current->load(); break; case LINE_SECTION_ITEM: // Should not be here break; case LINE_SECTION_STOP: // Should not be here break; case LINE_SECTION_INCLUDE: { // Load sub-file char value[MAX_TOKEN_LEN]; if(tokenize_line_command(line, NULL, value)) { DATA_FILE file; if(!file.load(value, FALSE)) { char local_file[MAX_FILENAME]; return_path(current_dir, value, local_file, MAX_FILENAME); if(!file.load(local_file, FALSE)) { return(FALSE); } } import(&file); } } break; } } return(TRUE); }
bool GetPath(void *data, xyLoc s, xyLoc g, std::vector<xyLoc> &path){ /* clear open list */ #ifdef _BUCKET_LIST_H open_list.Reset(); #elif HEAP2_H open_list.reset(); open_list.reserve(3000); #else open_list.clear(); #endif /* initialize closed list */ closed_list.resize(map.size()); for( int i=0; i<map.size(); i++){ closed_list[i] = false; } /* start location */ start = s; /* goal location */ goal = g; m_currentIteration++; /* start state */ State* start = (State*)malloc(sizeof(State));//new State; #ifdef _SPEEDY_H start->set_values(distance(s,g),s); #endif #ifdef _WASTAR_H start->set_values(0,distance(s,g),s); #endif start->set_parent(NULL); start->m_iteration = m_currentIteration; /* push start state */ #ifdef _BUCKET_LIST_H open_list.Push(start); #elif HEAP2_H open_list.add(start); #else open_list.push_back(start); std::push_heap(open_list.begin(),open_list.end(),StateComparator()); #endif /* Speedy */ #ifdef _BUCKET_LIST_H while( !open_list.Empty() ){ #else while( !open_list.empty() ){ #endif #ifdef _BUCKET_LIST_H State* curr = open_list.Pop(); #elif HEAP2_H State* curr = open_list.remove(); #else std::pop_heap (open_list.begin(),open_list.end(),StateComparator()); State* curr = open_list.back(); open_list.pop_back(); #endif if( FindGoal(curr) ){ return_path(curr, path); #ifdef DEBUG display_search(); #endif break; } GetSuccessors(curr->pos(), succ); for( int i=0; i<succ.size(); i++){ State* nb = (State*)malloc(sizeof(State));//new State; xyLoc pos = succ[i]; #ifdef _SPEEDY_H /* estimate total number of moves to go */ nb->set_values(distance(pos,g),pos); #endif #ifdef _WASTAR_H /* octile distance heuristic */ if( succ[i].x == curr->pos().x || succ[i].y == curr->pos().y ){ nb->set_values(curr->g()+1.0f,distance(pos,g),pos); } else{ nb->set_values(curr->g()+sqrt(2),distance(pos,g),pos); } #endif nb->set_parent(curr); nb->m_iteration = m_currentIteration; int index = GetIndex(succ[i]); if( !closed_list[index] && map[index] ){ closed_list[GetIndex(pos)] = true; //add state to closed list #ifdef _BUCKET_LIST_H open_list.Push(nb); #elif HEAP2_H open_list.add(nb); #else open_list.push_back(nb); std::push_heap(open_list.begin(),open_list.end(),StateComparator()); #endif } } } return true; }