MainLoop *test() { List<String> cmdlargs = OS::get_singleton()->get_cmdline_args(); if (cmdlargs.empty()) { //try editor! print_line("usage: godot -test shader_lang <shader>"); return NULL; } String test = cmdlargs.back()->get(); FileAccess *fa = FileAccess::open(test, FileAccess::READ); if (!fa) { ERR_FAIL_V(NULL); } String code; while (true) { CharType c = fa->get_8(); if (fa->eof_reached()) break; code += c; } SL sl; print_line("tokens:\n\n" + sl.token_debug(code)); Map<StringName, SL::FunctionInfo> dt; dt["fragment"].built_ins["ALBEDO"] = SL::TYPE_VEC3; dt["fragment"].can_discard = true; Vector<StringName> rm; rm.push_back("popo"); Set<String> types; types.insert("spatial"); Error err = sl.compile(code, dt, rm, types); if (err) { print_line("Error at line: " + rtos(sl.get_error_line()) + ": " + sl.get_error_text()); return NULL; } else { String code; recreate_code(&code, sl.get_shader()); print_line("code:\n\n" + code); } return NULL; }
Error DirAccess::copy(String p_from, String p_to, int p_chmod_flags) { //printf("copy %s -> %s\n",p_from.ascii().get_data(),p_to.ascii().get_data()); Error err; FileAccess *fsrc = FileAccess::open(p_from, FileAccess::READ, &err); if (err) { ERR_PRINTS("Failed to open " + p_from); return err; } FileAccess *fdst = FileAccess::open(p_to, FileAccess::WRITE, &err); if (err) { fsrc->close(); memdelete(fsrc); ERR_PRINTS("Failed to open " + p_to); return err; } fsrc->seek_end(0); int size = fsrc->get_position(); fsrc->seek(0); err = OK; while (size--) { if (fsrc->get_error() != OK) { err = fsrc->get_error(); break; } if (fdst->get_error() != OK) { err = fdst->get_error(); break; } fdst->store_8(fsrc->get_8()); } if (err == OK && p_chmod_flags != -1) { fdst->close(); err = FileAccess::set_unix_permissions(p_to, p_chmod_flags); // If running on a platform with no chmod support (i.e., Windows), don't fail if (err == ERR_UNAVAILABLE) err = OK; } memdelete(fsrc); memdelete(fdst); return err; }
void RichTextEditor::_file_selected(const String& p_path) { CharString cs; FileAccess *fa = FileAccess::open(p_path,FileAccess::READ); if (!fa) { ERR_FAIL(); } while(!fa->eof_reached()) cs.push_back(fa->get_8()); cs.push_back(0); memdelete(fa); String bbcode; bbcode.parse_utf8(&cs[0]); node->parse_bbcode(bbcode); }
Error DirAccess::copy(String p_from,String p_to) { //printf("copy %s -> %s\n",p_from.ascii().get_data(),p_to.ascii().get_data()); Error err; FileAccess *fsrc = FileAccess::open(p_from, FileAccess::READ,&err); if (err) { ERR_FAIL_COND_V( err, err ); } FileAccess *fdst = FileAccess::open(p_to, FileAccess::WRITE,&err ); if (err) { fsrc->close(); memdelete( fsrc ); ERR_FAIL_COND_V( err, err ); } fsrc->seek_end(0); int size = fsrc->get_pos(); fsrc->seek(0); err = OK; while(size--) { if (fsrc->get_error()!=OK) { err= fsrc->get_error(); break; } if (fdst->get_error()!=OK) { err= fdst->get_error(); break; } fdst->store_8( fsrc->get_8() ); } memdelete(fsrc); memdelete(fdst); return err; }