bool java_bytecode_languaget::parse( std::istream &instream, const std::string &path) { java_class_loader.set_message_handler(get_message_handler()); // look at extension if(has_suffix(path, ".class")) { java_class_loader.add_class_file(path); main_class=java_class_loadert::file_to_class_name(path); } else if(has_suffix(path, ".jar")) { java_class_loader.add_jar_file(path); // need to get entry point class from the manifest in the jar file std::map<std::string, std::string> manifest; get_jar_manifest(path, manifest); main_class=manifest["Main-Class"]; if(main_class=="") { error() << "JAR has no Main-Class" << eom; return true; } status() << "Java main class: " << main_class << eom; } else assert(false); java_class_loader(main_class); return false; }
static void gpage_filenames_init (const char *base) { if (base == NULL) { strcpy(gpage_base, gretl_dotdir()); strcat(gpage_base, "gretl_graphpage"); strcpy(gpage_tex_base, "gretl_graphpage"); } else { const char *p; strcpy(gpage_base, base); if (has_suffix(gpage_base, ".tex") || has_suffix(gpage_base, ".pdf") || has_suffix(gpage_base, ".eps")) { gpage_base[strlen(gpage_base) - 4] = '\0'; } else if (has_suffix(gpage_base, ".ps")) { gpage_base[strlen(gpage_base) - 3] = '\0'; } p = strrchr(gpage_base, SLASH); if (p != NULL) { strcpy(gpage_tex_base, p + 1); } else { strcpy(gpage_tex_base, gpage_base); } } }
static struct config_paths_t determine_config_directory_paths(const char *argv0) { struct config_paths_t paths; bool done = false; std::string exec_path = get_executable_path(argv0); if (get_realpath(exec_path)) { debug(2, L"exec_path: '%s'", exec_path.c_str()); if (!done) { // The next check is that we are in a reloctable directory tree const char *installed_suffix = "/bin/fish"; const char *just_a_fish = "/fish"; const char *suffix = NULL; if (has_suffix(exec_path, installed_suffix, false)) { suffix = installed_suffix; } else if (has_suffix(exec_path, just_a_fish, false)) { debug(2, L"'fish' not in a 'bin/', trying paths relative to source tree"); suffix = just_a_fish; } if (suffix) { bool seems_installed = (suffix == installed_suffix); wcstring base_path = str2wcstring(exec_path); base_path.resize(base_path.size() - strlen(suffix)); paths.data = base_path + (seems_installed ? L"/share/fish" : L"/share"); paths.sysconf = base_path + (seems_installed ? L"/etc/fish" : L"/etc"); paths.doc = base_path + (seems_installed ? L"/share/doc/fish" : L"/user_doc/html"); paths.bin = base_path + (seems_installed ? L"/bin" : L""); // Check only that the data and sysconf directories exist. Handle the doc // directories separately. struct stat buf; if (0 == wstat(paths.data, &buf) && 0 == wstat(paths.sysconf, &buf)) { // The docs dir may not exist; in that case fall back to the compiled in path. if (0 != wstat(paths.doc, &buf)) { paths.doc = L"" DOCDIR; } done = true; } } } } if (!done) { // Fall back to what got compiled in. debug(2, L"Using compiled in paths:"); paths.data = L"" DATADIR "/fish"; paths.sysconf = L"" SYSCONFDIR "/fish"; paths.doc = L"" DOCDIR; paths.bin = L"" BINDIR; } debug(2, L"determine_config_directory_paths() results:\npaths.data: %ls\npaths.sysconf: " L"%ls\npaths.doc: %ls\npaths.bin: %ls", paths.data.c_str(), paths.sysconf.c_str(), paths.doc.c_str(), paths.bin.c_str()); return paths; }
/* * 解析参数 */ static void parse_arguments(int argc, char* argv[]) { int opt; extern char *optarg; while ((opt = getopt(argc, argv, "c:t:m:d:S:s")) != -1) { switch (opt) { case 'c': PROBLEM::code_path = optarg; break; case 't': PROBLEM::time_limit = atoi(optarg); break; case 'm': PROBLEM::memory_limit = atoi(optarg); break; case 's': PROBLEM::spj = true; break; case 'S': PROBLEM::spj_lang = atoi(optarg); break; case 'd': PROBLEM::run_dir = optarg; break; default: FM_LOG_WARNING("Unknown option provided: -%c %s", opt, optarg); exit(JUDGE_CONF::EXIT_BAD_PARAM); } } if (has_suffix(PROBLEM::code_path, ".cpp")) { PROBLEM::lang = JUDGE_CONF::LANG_CPP; } else if (has_suffix(PROBLEM::code_path, ".c")) { PROBLEM::lang = JUDGE_CONF::LANG_C; } else if (has_suffix(PROBLEM::code_path, ".java")) { PROBLEM::lang = JUDGE_CONF::LANG_JAVA; } else { FM_LOG_WARNING("It seems that you give me a language which I do not known now: %d", PROBLEM::lang); exit(JUDGE_CONF::EXIT_BAD_PARAM); } PROBLEM::exec_file = PROBLEM::run_dir + "/a.out"; PROBLEM::input_file = PROBLEM::run_dir + "/in.in"; PROBLEM::output_file = PROBLEM::run_dir + "/out.out"; PROBLEM::exec_output = PROBLEM::run_dir + "/out.txt"; PROBLEM::result_file = PROBLEM::run_dir + "/result.txt"; PROBLEM::stdout_file_compiler = PROBLEM::run_dir + "/stdout_file_compiler.txt"; PROBLEM::stderr_file_compiler = PROBLEM::run_dir + "/stderr_file_compiler.txt"; if (PROBLEM::lang == JUDGE_CONF::LANG_JAVA) { PROBLEM::exec_file = PROBLEM::run_dir + "/Main"; PROBLEM::time_limit *= JUDGE_CONF::JAVA_TIME_FACTOR; PROBLEM::memory_limit *= JUDGE_CONF::JAVA_MEM_FACTOR; //Java放宽内存和时间限制 } if (PROBLEM::spj) { switch (PROBLEM::spj_lang) { case 1: case 2: PROBLEM::spj_exec_file = PROBLEM::run_dir + "/SpecialJudge";break; case 3: PROBLEM::spj_exec_file = PROBLEM::run_dir + "/SpecialJudge";break; default: FM_LOG_WARNING("OMG, I really do not kwon the special judge problem language."); exit(JUDGE_CONF::EXIT_BAD_PARAM); } PROBLEM::spj_output_file = PROBLEM::run_dir + "/spj_output.txt"; } }
enum program_type identify_program(char *filename) { if (has_suffix(filename, ".ban")) return BANAL; if (has_suffix(filename, ".c")) return C; if (has_suffix(filename, ".cpp")) return C; if (has_suffix(filename, ".pas")) return PASCAL; /* Not a supported programming language */ return NONE; }
FileType TLJPak::get_type(int i) { // FIXME: add some assert/exceptions here std::ifstream in(filename.c_str(), std::ios::binary); if (!in) { throw std::runtime_error("Error: Couldn't open " + filename); } else { char magic[8]; in.seekg(files[i].offset, std::ios::beg); in.read(magic, sizeof(magic)); in.close(); if (strncmp(magic, "DDS", 3) == 0) return FILETYPE_DDS; else if (strncmp(magic, "tljbone", 7) == 0) return FILETYPE_TLJBONE; else if (strncmp(magic, "STFU4", 4) == 0) return FILETYPE_STFU4; else if (strncmp(magic, "RIFF", 4) == 0) return FILETYPE_WAV; else if (strncmp(magic, "shark3d", 7) == 0) return FILETYPE_SHARK3D; else if (has_suffix(files[i].pathname, ".bun")) return FILETYPE_BUNDLE; else if (has_suffix(files[i].pathname, ".mp3")) return FILETYPE_MP3; else if (has_suffix(files[i].pathname, ".wav")) return FILETYPE_WAV; else if (has_suffix(files[i].pathname, ".lip")) return FILETYPE_LIP; else if (files[i].pathname, "art/generated/config/universe/localization.dat") return FILETYPE_LOCALISATION; // FIXME: This is mostly guessing else if (strncmp(magic, "ID3", 3) == 0) return FILETYPE_MP3; else if (strncmp(magic, "vs", 2) == 0 || strncmp(magic, "xvs", 3) == 0) return FILETYPE_TEXT; else if (strncmp(magic, "ps", 2) == 0 || strncmp(magic, "xps", 3) == 0) return FILETYPE_TEXT; else if (strncmp(magic, "; ", 2) == 0 || strncmp(magic, "//", 2) == 0) return FILETYPE_TEXT; else return FILETYPE_UNKNOWN; } }
std::string AddonManager::scan_for_info(const std::string& archive_os_path) const { std::unique_ptr<char*, decltype(&PHYSFS_freeList)> rc2(PHYSFS_enumerateFiles("/"), PHYSFS_freeList); for(char** j = rc2.get(); *j != 0; ++j) { if (has_suffix(*j, ".nfo")) { std::string nfo_filename = FileSystem::join("/", *j); // make sure it's in the current archive_os_path const char* realdir = PHYSFS_getRealDir(nfo_filename.c_str()); if (!realdir) { log_warning << "PHYSFS_getRealDir() failed for " << nfo_filename << ": " << PHYSFS_getLastError() << std::endl; } else { if (realdir == archive_os_path) { return nfo_filename; } } } } return std::string(); }
// Return all suffix-matched files in the directory 'dirpath' bool suffix_matched_files_in_dir(const char *dirpath, StringList &file_list, const char *suffix, bool use_fullname) { Directory dir(dirpath); bool found_it = false; file_list.clearAll(); const char *f = NULL; dir.Rewind(); while( (f=dir.Next()) ) { if( dir.IsDirectory() ) { continue; } if( has_suffix(f, suffix) ) { if( use_fullname ) { file_list.append(dir.GetFullPath()); }else { file_list.append(f); } found_it = true; } } return found_it; }
static int should_extract (struct archive_entry *entry) { const char *path = archive_entry_pathname (entry); if (has_prefix (path, "./")) path += 2; /* Skip these as we're using GLVND on majod > 367*/ if (nvidia_major_version > 367 && (has_prefix (path, "libGL.so") || has_prefix (path, "libEGL.so"))) return 0; if ((has_prefix (path, "lib") || has_prefix (path, "tls/lib"))&& has_suffix (path, ".so." NVIDIA_VERSION)) return 1; if (strcmp (path, "nvidia_icd.json") == 0) { archive_entry_set_pathname (entry, "./vulkan/icd.d/nvidia_icd.json"); return 1; } if (strcmp (path, "10_nvidia.json") == 0) { archive_entry_set_pathname (entry, "./glvnd/egl_vendor.d/10_nvidia.json"); return 1; } return 0; }
bool is_fasta_gzip_file_name(char const *path) { for(string ext: fasta_gzip_ext) if(has_suffix(path, ext)) return true; return false; }
void java_class_loadert::read_jar_file( java_class_loader_limitt &class_loader_limit, const irep_idt &file) { // done already? if(jar_map.find(file)!=jar_map.end()) return; jar_filet &jar_file=jar_pool(class_loader_limit, id2string(file)); if(!jar_file) { error() << "failed to open JAR file `" << file << "'" << eom; return; } debug() << "adding JAR file `" << file << "'" << eom; auto &jm=jar_map[file]; for(auto &jar_entry : jar_file.filtered_jar) { std::string file_name=id2string(jar_entry.first); // does it end on .class? if(has_suffix(file_name, ".class")) { irep_idt class_name=file_to_class_name(file_name); // record jm.entries[class_name].class_file_name=file_name; } } }
void ImageManager::ReadSamples(const string &directory, vector_sample* result) { DIR* dir; struct dirent* ent; string path = Parameter::pathToTrainingSet + directory; dir = opendir(path.c_str()); if (dir == NULL) { cerr << "TrainingSet not found!" << endl; assert(0); } Sample* sample = nullptr; image_rgb* image = nullptr; while ((ent = readdir(dir)) != NULL) { string name = string(ent->d_name); if (has_suffix(name, ".png")) { string file = path + name; image = new image_rgb(file); sample = new Sample(image, name); result->push_back(sample); } } closedir(dir); }
std::string java_class_loadert::file_to_class_name(const std::string &file) { std::string result=file; // Strip .class. Note that the Java class loader would // not do that. if(has_suffix(result, ".class")) result.resize(result.size()-6); // Strip a "./" prefix. Note that the Java class loader // would not do that. #ifdef _WIN32 while(has_prefix(result, ".\\")) result=std::string(result, 2, std::string::npos); #else while(has_prefix(result, "./")) result=std::string(result, 2, std::string::npos); #endif // slash to dot for(std::string::iterator it=result.begin(); it!=result.end(); it++) if(*it=='/') *it='.'; return result; }
static void tabwin_handle_drag (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *data, guint info, guint time, gpointer p) { const guchar *seldata = NULL; gchar *dfname; char tmp[MAXLEN]; int pos, skip = 5; if (data != NULL) { seldata = gtk_selection_data_get_data(data); } if (info != GRETL_FILENAME) { return; } /* ignore the wrong sort of data */ if (data == NULL || (dfname = (gchar *) seldata) == NULL || strlen(dfname) <= 5 || strncmp(dfname, "file:", 5)) { return; } if (strncmp(dfname, "file://", 7) == 0) skip = 7; #ifdef G_OS_WIN32 if (strncmp(dfname, "file:///", 8) == 0) skip = 8; #endif /* there may be multiple files: we ignore all but the first */ *tmp = 0; if ((pos = gretl_charpos('\r', dfname)) > 0 || (pos = gretl_charpos('\n', dfname) > 0)) { strncat(tmp, dfname + skip, pos - skip); } else { strcat(tmp, dfname + skip); } /* handle spaces and such */ unescape_url(tmp); #ifdef G_OS_WIN32 filename_to_win32(tryfile, tmp); #else strcpy(tryfile, tmp); #endif if (has_suffix(tryfile, ".inp")) { do_open_script(EDIT_SCRIPT); } }
/** * Gets the full file name including the correct suffix * @param filename: the name of the file except for the suffix * @param isHistoWorkspace: flag if the workspace is an MDHistoWorkspace or not * @return a full file path including a suffix */ std::string SaveMDWorkspaceToVTKImpl::getFullFilename(std::string filename, bool isHistoWorkspace) const { const auto extension = isHistoWorkspace ? structuredGridExtension : unstructuredGridExtension; if (!has_suffix(filename, extension)) { filename += extension; } return filename; }
static bool list_in_directory (string dir, string name, array<string> suffix, bool dir_flag) { if (name == "") return false; if (name == "..") return dir_flag; if (name[0]=='.') return false; if (dir_flag) return is_directory (url_system (dir, name)); else return is_regular (url_system (dir, name)) && has_suffix (name, suffix); }
RETCODE Connection::Handle(uint32_t event) { if (event == EPOLLIN) { char buf[1024]; int ret = read(mFd, buf, 1024); if (ret == 0) { return DELETE; } else if (ret == -1) { if (errno == EAGAIN || errno == EINTR) { return CONTINUE; } else { printf("unknown read errno: %d\n", errno); return DELETE; } } else { mReq += std::string(buf, ret); if (has_suffix(mReq, "\r\n\r\n")) { // printf("req: %s\n", mReq.c_str()); return ADDOUT; } // printf("req: %s\n", mReq.c_str()); return CONTINUE; } } else if (event == EPOLLOUT) { if (mRespPos == resp.size()) { return DELETE; } while(1) { size_t size = std::min(1000ul, resp.size() - mRespPos); int ret = write(mFd, resp.c_str() + mRespPos, size); if (ret < 0) { if (errno == EAGAIN || errno == EINTR) { return CONTINUE; } else { printf("unknown write errno: %d %s\n", errno, strerror(errno)); return DELETE; } } else { mRespPos += ret; if (ret < size) { printf("send incomplete\n"); // return CONTINUE; } if (mRespPos == resp.size()) { return DELETE; } } usleep(100); } } else { printf("unknown event: %u\n", event); return DELETE; } }
CL_PixelBuffer Tile::get_pixelbuffer() { if (impl->pixelbuffer) { return impl->pixelbuffer; } else { if (impl->provider) { impl->pixelbuffer = impl->provider.get_pixelbuffer(); return impl->pixelbuffer; } else { // FIXME: Move all this into a special provider try { if (has_suffix(impl->filename, ".png") || has_suffix(impl->filename, ".jpg")) { impl->pixelbuffer = CL_PixelBuffer(CL_ProviderFactory::load(impl->filename)); } else { //CL_SpriteDescription descr(impl->filename, resources); //impl->pixelbuffer = CL_PixelBuffer(*(descr.get_frames().begin()->first)); std::cout << "Error: not a png or jpg file: " << impl->filename << std::endl; assert(0); } return impl->pixelbuffer; } catch(CL_Error& err) { std::cout << "CL_Error: " << err.message << std::endl; std::cout << " filename = " << impl->filename << std::endl; return CL_PixelBuffer(); } } } }
int win32_open_file (const char *fname) { char sfx[5]; int err = 0; if (has_suffix(fname, ".pdf")) { strcpy(sfx, ".pdf"); } else if (has_suffix(fname, ".ps") || has_suffix(fname, ".eps")) { strcpy(sfx, ".ps"); } else { *sfx = '\0'; } err = win32_open_arg(fname, sfx); if (err) { win_show_last_error(); } return err; }
static char *remove_suffix(char *filename, char *suffix) { static char *outfile = NULL; int flen = strlen(filename); int slen = strlen(suffix); if (suffix[0]==0 || !has_suffix(filename, suffix)) { return filename; } outfile = xrealloc(outfile, flen-slen+1, cmd.name); strncpy (outfile, filename, flen-slen); outfile[flen-slen] = 0; return outfile; }
static int check_downloaded_file (const char *fname, const char *dl) { int err = 0; if (has_suffix(fname, ".zip") && !gretl_is_pkzip_file(fname)) { err = E_DATA; } else if (has_suffix(fname, ".gfn") && !gretl_is_xml_file(fname)) { err = E_DATA; } if (err) { /* let's see what we got */ FILE *fp = gretl_fopen(fname, "rb"); int msg_done = 0; if (fp != NULL) { char buf[128] = {0}; size_t n; n = fread(buf, 1, 127, fp); if (n > 8 && g_utf8_validate(buf, -1, NULL)) { gretl_errmsg_set(g_strchomp(buf)); msg_done = 1; } fclose(fp); gretl_remove(fname); } if (!msg_done) { gretl_errmsg_sprintf("%s\ndownload failed", dl); } } return err; }
bool gcc_modet::needs_preprocessing(const std::string &file) { if(has_suffix(file, ".c") || has_suffix(file, ".cc") || has_suffix(file, ".cp") || has_suffix(file, ".cpp") || has_suffix(file, ".CPP") || has_suffix(file, ".c++") || has_suffix(file, ".C")) return true; else return false; }
int check_for_program (const char *prog) { int ret = 0; if (has_suffix(prog, ".exe")) { ret = win32_check_for_program(prog); } else { gchar *test = g_strdup_printf("%s.exe", prog); ret = win32_check_for_program(test); g_free(test); } return ret; }
void ImageManager::CreateTrainingSamplesFromOriginals() { DIR* dir; struct dirent* ent; dir = opendir(Parameter::pathToOriginals.c_str()); if (dir == NULL) { cerr << "PathToOriginals not found!" << endl; assert(0); } while ((ent = readdir(dir)) != NULL) { string name = string(ent->d_name); if (has_suffix(name, ".png")) { ProcessOriginal(name); } } closedir(dir); };
std::set<Language> DictionaryManager::get_languages() { std::set<Language> languages; for (SearchPath::iterator p = search_path.begin(); p != search_path.end(); ++p) { std::vector<std::string> files = filesystem->open_directory(*p); for(std::vector<std::string>::iterator file = files.begin(); file != files.end(); ++file) { if (has_suffix(*file, ".po")) { languages.insert(Language::from_env(file->substr(0, file->size()-3))); } } } return languages; }
static void write_to_file (PicoSAT * picosat, const char *name, const char *type, void (*writer) (PicoSAT *, FILE *)) { int pclose_file, zipped = has_suffix (name, ".gz"); FILE *file; char *cmd; if (zipped) { cmd = malloc (strlen (GZIP) + strlen (name)); sprintf (cmd, GZIP, name); file = popen (cmd, "w"); free (cmd); pclose_file = 1; } else { file = fopen (name, "w"); pclose_file = 0; } if (file) { if (verbose) fprintf (output, "c\nc writing %s%s to '%s'\n", zipped ? "gzipped " : "", type, name); writer (picosat, file); if (pclose_file) pclose (file); else fclose (file); } else fprintf (output, "*** picosat: can not write to '%s'\n", name); }
/** * Parse key to remove "type" if this is for schema and initiate compaction */ static int parse_keys (char *buffer, size_t buffer_size, const char *key_str) { char tmp[2 * buffer_size]; if (buffer == NULL || buffer_size == 0 || key_str == NULL || strlen (key_str) == 0) return EINVAL; if ((count_parts (key_str) > 2) && has_suffix (key_str, ".type")) { /* strip ".type" suffix iff the key has more than two parts. */ size_t sz = strlen (key_str) - strlen (".type") + 1; if (sz > sizeof (tmp)) sz = sizeof (tmp); sstrncpy (tmp, key_str, sz); } else { sstrncpy (tmp, key_str, sizeof (tmp)); } return compact_ds_name (buffer, buffer_size, tmp); }
void TLJPak::read_filetable(std::istream& in) { Shark3D* shark = Shark3D::parse_text(in); if (!has_suffix(filename, shark->get_string("filename", ""))) { std::cout << "TLJPak::read_filetable: filename missmatch in " << filename << std::endl; } SectionNodes* nodes = shark->get_sections("files"); for(std::vector<SectionNode*>::iterator i = nodes->sections.begin(); i != nodes->sections.end(); ++i) { int index = (*i)->get_ints("index").front(); assert(index >= 0 && index < int(files.size()) && files[index].is_file()); files[index].guesses = (*i)->get_strings("pathnames"); files[index].pathname = files[index].guesses.front(); files[index].filetype = string2filetype((*i)->get_strings("filetype").front().c_str()); //files[i].guesses = (*i)->get_strings("pathnames"); } }
std::vector<std::string> AddonManager::scan_for_archives() const { std::vector<std::string> archives; // Search for archives and add them to the search path std::unique_ptr<char*, decltype(&PHYSFS_freeList)> rc(PHYSFS_enumerateFiles(m_addon_directory.c_str()), PHYSFS_freeList); for(char** i = rc.get(); *i != 0; ++i) { if (has_suffix(*i, ".zip")) { std::string archive = FileSystem::join(m_addon_directory, *i); if (PHYSFS_exists(archive.c_str())) { archives.push_back(archive); } } } return archives; }
java_bytecode_parse_treet &java_class_loadert::get_parse_tree( java_class_loader_limitt &class_loader_limit, const irep_idt &class_name) { java_bytecode_parse_treet &parse_tree=class_map[class_name]; // First check given JAR files for(const auto &jf : jar_files) { read_jar_file(class_loader_limit, jf); const auto &jm=jar_map[jf]; auto jm_it=jm.entries.find(class_name); if(jm_it!=jm.entries.end()) { debug() << "Getting class `" << class_name << "' from JAR " << jf << eom; std::string data=jar_pool(class_loader_limit, jf) .get_entry(jm_it->second.class_file_name); std::istringstream istream(data); java_bytecode_parse( istream, parse_tree, get_message_handler()); return parse_tree; } } // See if we can find it in the class path for(const auto &cp : config.java.classpath) { // in a JAR? if(has_suffix(cp, ".jar")) { read_jar_file(class_loader_limit, cp); const auto &jm=jar_map[cp]; auto jm_it=jm.entries.find(class_name); if(jm_it!=jm.entries.end()) { debug() << "Getting class `" << class_name << "' from JAR " << cp << eom; std::string data=jar_pool(class_loader_limit, cp) .get_entry(jm_it->second.class_file_name); std::istringstream istream(data); java_bytecode_parse( istream, parse_tree, get_message_handler()); return parse_tree; } } else { // in a given directory? std::string full_path= #ifdef _WIN32 cp+'\\'+class_name_to_file(class_name); #else cp+'/'+class_name_to_file(class_name); #endif // full class path starts with './' if(class_loader_limit.load_class_file(full_path.substr(2)) && std::ifstream(full_path)) { if(!java_bytecode_parse( full_path, parse_tree, get_message_handler())) return parse_tree; } } } // not found warning() << "failed to load class `" << class_name << '\'' << eom; parse_tree.parsed_class.name=class_name; return parse_tree; }