void WindowManager::removeWindow(Window *window) { static WMGlobals globals; fatal_assert((window == NULL), "How did you do that? removeWindow has been passed a NULL pointer", __FILE__, __LINE__); globals->registeredwindows.remove(window); if(globals->handleractive == true) { fatal_assert((globals->mousefilters.count(window) != 1), "Tried to remove a window that is not in the mousefilter map", __FILE__, __LINE__); window->setMouseFilter(globals->mousefilters[window]); globals->mousefilters.erase(window); fatal_assert((globals->keyfilters.count(window) != 1), "Tried to remove a window that is not in the keyfilter map", __FILE__, __LINE__); window->setKeyboardFilter(globals->keyfilters[window]); globals->keyfilters.erase(window); fatal_assert((globals->timerfilters.count(window) != 1), "Tried to remove a window that is not in the timerfilter map", __FILE__, __LINE__); window->setTimerFilter(globals->timerfilters[window]); globals->timerfilters.erase(window); } }
Daemon::Daemon(Window *window) : window(window) { fatal_assert((window == NULL), "I seem to have recieved a NULL Window pointer", __FILE__, __LINE__); if(!renderer_active) { renderer = new RENDERER; renderer_active = true; } }
/** * @brief Converts a filename according to the Unix path separator rules * @param[in,out] file_path null-terminated string, with a file path to convert * @return returns a pointer to the \file_path C string * @see http://pubs.opengroup.org/onlinepubs/007904975/basedefs/xbd_chap03.html * @author Cristian Martinez */ char* to_unix_path_separators(char* file_path) { // check that that finename is not a NULL pointer fatal_assert(!file_path, "NULL error in to_unix_path_separators file_path\n"); // pointer to the first occurrence of '\' char* it_current = strchr(file_path, '\\'); // return when there are nothing to do if (it_current == NULL) return file_path; // pointer to the next character after the first '\' char* it_next = it_current + 1; // convert '\' to '/' while (*it_current != '\0') { // do not convert file paths with escaped spaces if (*it_current == '\\' && *it_next != ' ' ) { *it_current = '/'; } ++it_current; } // conserve UNC paths if(file_path[0] && file_path[0] == '/' && file_path[1] && file_path[1] == '/') { file_path[0] = '\\'; file_path[1] = '\\'; } // remove trailing slashes if (file_path[1] && *(it_current-1) == '/') { while (*(it_current-1) == '/') { *(it_current-1) = '\0'; --it_current; } // put back a single slash if file_path is now empty if(file_path[0] == '\0') { file_path[0] = '/'; } } // put a trailing slash to DRIVE:/, e.g. 'c:/' if (file_path[1] == ':' && file_path[2] == '\0') { file_path[2] = '/'; file_path[3] = '\0'; } return file_path; }
/** * Returns 1 if the state is not final and has no outgoing transition; 0 otherwise. */ static inline int is_useless_state(OptimizedFst2State s) { fatal_assert(s==NULL,"NULL error in is_useless_state\n"); return !(s->control&1) && s->graph_calls==NULL && s->metas==NULL && s->patterns==NULL && s->compound_patterns==NULL && s->number_of_tokens==0 && s->input_variable_starts==NULL && s->input_variable_ends==NULL && s->output_variable_starts==NULL && s->output_variable_ends==NULL && (s->contexts==NULL || (s->contexts->non_NULL_positive_transitions==0 && s->contexts->size_negative==0 && s->contexts->end_mark==NULL)); }
void WindowManager::registerWindow(Window *window) { static WMGlobals globals; fatal_assert((window == NULL), "How did you do that? registerWindow has been passed a NULL pointer", __FILE__, __LINE__); if(globals->handleractive == true) { globals->mousefilters[window] = window->getMouseFilter(); // window->setMouseFilter(NULL); globals->keyfilters[window] = window->getKeyboardFilter(); // window->setKeyboardFilter(NULL); globals->timerfilters[window] = window->getTimerFilter(); // window->setTimerFilter(NULL); } globals->registeredwindows.push_front(window); }
/** * @brief Converts a filename according to the Windows path separator rules * @param[in,out] filename null-terminated string, with a file path to convert * @return returns a pointer to the \file_path C string * @author Cristian Martinez */ char* to_windows_path_separators(char* file_path) { // check that that the file path is not a NULL pointer fatal_assert(!file_path, "NULL error in to_native_path file_path\n"); // pointer to the first occurrence of '\' char* it_current = strchr(file_path, '/'); // return when there are nothing to do if (it_current == NULL) return file_path; // convert '/' to '\' while (*it_current != '\0') { if (*it_current == '/') { *it_current = '\\'; } ++it_current; } return file_path; }
void WindowManager::handleEvents() { static WMGlobals globals; list<Window *>::iterator iterate; iterate = globals->registeredwindows.begin(); while(iterate != globals->registeredwindows.end()) { fatal_assert((*iterate == NULL), "There seems to be a NULL pointer in the window list", __FILE__, __LINE__); globals->mousefilters[*iterate] = (*iterate)->getMouseFilter(); // (*iterate)->setMouseFilter(NULL); globals->keyfilters[*iterate] = (*iterate)->getKeyboardFilter(); // (*iterate)->setKeyboardFilter(NULL); globals->timerfilters[*iterate] = (*iterate)->getTimerFilter(); // (*iterate)->setTimerFilter(NULL); iterate++; } globals->handleractive = true; while(globals->handleractive) { // Necessary for doing cooperative threading yield(); iterate = globals->registeredwindows.begin(); while(iterate != globals->registeredwindows.end()) { fatal_assert((*iterate == NULL), "There seems to be a a NULL pointer in the window list", __FILE__, __LINE__); while(!(*iterate)->isTimerQueueEmpty()) (*iterate)->handleTimerEvent((*iterate)->getTimerEvent()); while(!(*iterate)->isKeyboardQueueEmpty()) (*iterate)->handleKeyboardEvent((*iterate)->getKeyboardEvent()); while(!(*iterate)->isMouseQueueEmpty()) (*iterate)->handleMouseEvent((*iterate)->getMouseEvent()); (*iterate)->handleIdleEvent(); // Necessary for doing cooperative threading yield(); iterate++; } } iterate = globals->registeredwindows.begin(); while(iterate != globals->registeredwindows.end()) { fatal_assert((*iterate == NULL), "There seems to be a NULL pointer in the window list", __FILE__, __LINE__); fatal_assert((globals->mousefilters.count(*iterate) != 1), "There is a window in the window list that is not in the mousefilter map", __FILE__, __LINE__); (*iterate)->setMouseFilter(globals->mousefilters[*iterate]); /// mousefilters[*iterate] = NULL; globals->mousefilters.erase(*iterate); fatal_assert((globals->keyfilters.count(*iterate) != 1), "There is a window in the window list that is not in the keyfilter map.", __FILE__, __LINE__); (*iterate)->setKeyboardFilter(globals->keyfilters[*iterate]); // keyfilters[*iterate] = NULL; globals->keyfilters.erase(*iterate); fatal_assert((globals->timerfilters.count(*iterate) != 1), "There is a window in the window list that is not in the timerfilter map.", __FILE__, __LINE__); (*iterate)->setTimerFilter(globals->timerfilters[*iterate]); // timerfilters[*iterate] = NULL; globals->timerfilters.erase(*iterate); iterate++; } }
/** * @brief Unitex implementation of realpath() * * Derives from the pathname pointed to by filename, an absolute pathname that * names the same file, whose resolution does not involve ".", "..", or symbolic * links * * @param[in] filename null-terminated string, with a filename to resolve * @param[out] resolved_name null-terminated string, up to a maximum of {FILENAME_MAX} bytes * @return different from SUCCESS_RETURN_CODE if fails * @remarks if resolved_name is a null pointer, function will fail * @author Cristian Martinez */ int get_real_path(const char* filename, char* resolved_name) { // check that the arguments are not NULL pointers fatal_assert(!filename, "NULL error in get_realpath filename\n"); fatal_assert(!resolved_name, "NULL error in get_realpath resolved_name\n"); // check that the file name is not empty if (filename[0]=='\0') { return DEFAULT_ERROR_CODE; } // get the file type UnitexFileType file_type = get_file_type(filename); // if get_file_type() fails or the file doesn't exist if(file_type <= FILE_NOT_FOUND) { return DEFAULT_ERROR_CODE; } // if the file is under the abstract file layer, the name // is already resolved if(file_type == FILE_ABST) { strncpy(resolved_name, filename, FILENAME_MAX); return SUCCESS_RETURN_CODE; } // default value to be returned by this function int return_code = DEFAULT_ERROR_CODE; // temporal buffer to store the resolved_name char buffer[FILENAME_MAX + 1] = {0}; #ifdef _NOT_UNDER_WINDOWS // try to get the resolved filename if (realpath(filename, buffer) != NULL) { return_code = SUCCESS_RETURN_CODE; } #else // under Windows wchar_t w_filename[FILENAME_MAX + 1] = {0}; // wide string filename wchar_t w_buffer[FILENAME_MAX + 1] = {0}; // wide string resolved filename // get the required size, in characters, for the wide string buffer output int length = MultiByteToWideChar(CP_ACP, // Windows ANSI code page 0, // no flags for conversion type filename, // string to convert -1, // filename is null-terminated NULL, // wide string buffer output 0); // size of the buffer output // maps filename C string to w_filename wide character string MultiByteToWideChar(CP_ACP, // Windows ANSI code page 0, // no flags for conversion type filename, // string to convert -1, // filename is null-terminated w_filename, // wide string buffer output length); // size of the buffer output // try to get the resolved filename if (_wfullpath(w_buffer, w_filename, FILENAME_MAX)) { WideCharToMultiByte(CP_ACP, // Windows ANSI code page 0, // no flags for conversion type w_buffer, // string to convert -1, // w_buffer is null-terminated buffer, // C string buffer output FILENAME_MAX, // size of the buffer output NULL, // use the system default character NULL); // parameter can be set to NULL return_code = SUCCESS_RETURN_CODE; } #endif // #ifdef _NOT_UNDER_WINDOWS // if we have a resolved name copy it into the // resolved_name output buffer if(return_code == SUCCESS_RETURN_CODE) { strncpy(resolved_name, buffer, FILENAME_MAX); } return return_code; }
/** * @brief Returns the type of the given file * @param filename null-terminated string, with a filename to check * @return \a UnitexFileType, a Unix file type * @author Cristian Martinez */ UnitexFileType get_file_type(const char* filename) { // check that that the file name is not a NULL pointer fatal_assert(!filename, "NULL error in is_regular_file filename\n"); // test if the file is under the abstract file layer if (is_filename_in_abstract_file_space(filename)) { return FILE_ABST; } // by default the file type is unknown UnitexFileType file_type = FILE_UNK; #ifndef _MSC_VER struct stat info; // return information about filename int status = stat(filename,&info); // on error, stat returns a non zero value if (status < 0) { // no such file or directory if (errno == ENOENT || errno == ENOTDIR) return FILE_NOT_FOUND; // permission denied else if (errno == EACCES) return FUNC_EACCES; // other stat() error else return FUNC_ERROR; } // if (status < 0) if (S_ISDIR (info.st_mode)) file_type = FILE_DIR; else if (S_ISREG (info.st_mode)) file_type = FILE_REG; # ifdef _NOT_UNDER_WINDOWS else if (S_ISCHR (info.st_mode)) file_type = FILE_CHR; else if (S_ISBLK (info.st_mode)) file_type = FILE_BLK; else if (S_ISLNK (info.st_mode)) file_type = FILE_LNK; else if (S_ISSOCK(info.st_mode)) file_type = FILE_SOCK; else if (S_ISFIFO(info.st_mode)) file_type = FILE_FIFO; # endif // _NOT_UNDER_WINDOWS #else // under a non-POSIX system wchar_t w_filename[FILENAME_MAX + 1] = {0}; // get the required size, in characters, for the wide string buffer output int length = MultiByteToWideChar(CP_ACP, // Windows ANSI code page 0, // no flags for conversion type filename, // string to convert -1, // filename is null-terminated NULL, // wide string buffer output 0); // size of the buffer output // maps filename string to w_filename wide character string MultiByteToWideChar(CP_ACP, // Windows ANSI code page 0, // no flags for conversion type filename, // string to convert -1, // filename is null-terminated w_filename, // wide string buffer output length); // size of the buffer output // retrieves file system attributes for a specified file or directory DWORD dwAttribute = GetFileAttributesW(w_filename); // on error, dwAttribute is 0xFFFFFFFF if (dwAttribute == INVALID_FILE_ATTRIBUTES) { DWORD lastError = GetLastError(); // no such file or directory if (lastError == ERROR_FILE_NOT_FOUND || lastError == ERROR_PATH_NOT_FOUND) return FILE_NOT_FOUND; // permission denied else if (lastError == ERROR_ACCESS_DENIED) return FUNC_EACCES; // other stat() error else return FUNC_ERROR; } // if (status < 0) if ((dwAttribute & FILE_ATTRIBUTE_DIRECTORY) != 0) file_type = FILE_DIR; else if ((dwAttribute & FILE_ATTRIBUTE_ARCHIVE) != 0) file_type = FILE_REG; #endif // _MSC_VER // return main file type return file_type; }