bool path_iterator::next(astring &buffer, const char *name) { // if none left, return FALSE to indicate we are done if (m_index != 0 && *m_current == 0) return false; // copy up to the next semicolon const char *semi = strchr(m_current, ';'); if (semi == NULL) semi = m_current + strlen(m_current); buffer.cpy(m_current, semi - m_current); m_current = (*semi == 0) ? semi : semi + 1; // append the name if we have one if (name != NULL) { // compute the full pathname if (buffer.len() > 0) buffer.cat(PATH_SEPARATOR); buffer.cat(name); } // bump the index and return TRUE m_index++; return true; }
void consolewin_info::build_generic_filter(device_image_interface *img, bool is_save, astring &filter) { // common image types add_filter_entry(filter, "Common image types", img->file_extensions()); // compressed if (!is_save) filter.cat("Compressed Images (*.zip)|*.zip|"); // all files filter.cat("All files (*.*)|*.*|"); }
static bool find_include_file(astring &srcincpath, int srcrootlen, const astring &srcfile, const astring &filename) { // iterate over include paths and find the file for (include_path *curpath = incpaths; curpath != NULL; curpath = curpath->next) { // a '.' include path is specially treated if (curpath->path == ".") srcincpath.cpysubstr(srcfile, 0, srcfile.rchr(0, PATH_SEPARATOR[0])); else srcincpath.cpy(curpath->path); // append the filename piecemeal to account for directories int lastsepindex = 0; int sepindex; while ((sepindex = filename.chr(lastsepindex, '/')) != -1) { astring pathpart(filename, lastsepindex, sepindex - lastsepindex); // handle .. by removing a chunk from the incpath if (pathpart == "..") { int sepindex_part = srcincpath.rchr(0, PATH_SEPARATOR[0]); if (sepindex_part != -1) srcincpath.substr(0, sepindex_part); } // otherwise, append a path separator and the pathpart else srcincpath.cat(PATH_SEPARATOR).cat(pathpart); // advance past the previous index lastsepindex = sepindex + 1; } // now append the filename srcincpath.cat(PATH_SEPARATOR).catsubstr(filename, lastsepindex, -1); // see if we can open it core_file *testfile; if (core_fopen(srcincpath, OPEN_FLAG_READ, &testfile) == FILERR_NONE) { // close the file core_fclose(testfile); return true; } } return false; }
void consolewin_info::add_filter_entry(astring &dest, const char *description, const char *extensions) { // add the description dest.cat(description); dest.catformat(" ("); // add the extensions to the description copy_extension_list(dest, extensions); // add the trailing rparen and '|' character dest.cat(")|"); // now add the extension list itself copy_extension_list(dest, extensions); // append a '|' dest.cat('|'); }
void consolewin_info::copy_extension_list(astring &dest, const char *extensions) { // our extension lists are comma delimited; Win32 expects to see lists // delimited by semicolons char const *s = extensions; while (*s) { // append a semicolon if not at the beginning if (s != extensions) dest.cat(';'); // append ".*" dest.cat("*."); // append the file extension while (*s && (*s != ',')) dest.cat(*s++); // if we found a comma, advance while(*s == ',') s++; } }
static bool find_include_file(astring &srcincpath, int srcrootlen, int dstrootlen, astring &srcfile, astring &dstfile, astring &filename) { // iterate over include paths and find the file for (include_path *curpath = incpaths; curpath != NULL; curpath = curpath->next) { // a '.' include path is specially treated if (curpath->path == ".") srcincpath.cpysubstr(srcfile, 0, srcfile.rchr(0, PATH_SEPARATOR[0])); else srcincpath.cpysubstr(srcfile, 0, srcrootlen + 1).cat(curpath->path); // append the filename piecemeal to account for directories int lastsepindex = 0; int sepindex; while ((sepindex = filename.chr(lastsepindex, '/')) != -1) { // handle .. by removing a chunk from the incpath astring pathpart(filename, lastsepindex, sepindex - lastsepindex); if (pathpart == "..") { sepindex = srcincpath.rchr(0, PATH_SEPARATOR[0]); if (sepindex != -1) srcincpath.substr(0, sepindex); } // otherwise, append a path separator and the pathpart else srcincpath.cat(PATH_SEPARATOR).cat(pathpart); // advance past the previous index lastsepindex = sepindex + 1; } // now append the filename srcincpath.cat(PATH_SEPARATOR).catsubstr(filename, lastsepindex, -1); // see if we can open it core_file *testfile; if (core_fopen(srcincpath, OPEN_FLAG_READ, &testfile) == FILERR_NONE) { // close the file core_fclose(testfile); // find the longest matching directory substring between the include and source file lastsepindex = 0; while ((sepindex = srcincpath.chr(lastsepindex, PATH_SEPARATOR[0])) != -1) { // get substrings up to the current directory astring tempfile(srcfile, 0, sepindex); astring tempinc(srcincpath, 0, sepindex); // if we don't match, stop if (tempfile != tempinc) break; lastsepindex = sepindex + 1; } // chop off the common parts of the paths astring tempfile(srcfile, lastsepindex, -1); srcincpath.substr(lastsepindex, -1).replacechr(PATH_SEPARATOR[0], '/'); // for each directory left in the filename, we need to prepend a "../" while ((sepindex = tempfile.chr(0, PATH_SEPARATOR[0])) != -1) { tempfile.substr(sepindex + 1, -1); srcincpath.ins(0, "../"); } srcincpath.cat(".html"); // free the strings and return the include path return true; } } return false; }