void VisualShaderEditor::_connection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index) { VisualShader::Type type = VisualShader::Type(edit_type->get_selected()); int from = p_from.to_int(); int to = p_to.to_int(); if (!visual_shader->can_connect_nodes(type, from, p_from_index, to, p_to_index)) { EditorNode::get_singleton()->show_warning(TTR("Unable to connect, port may be in use or connection may be invalid.")); return; } undo_redo->create_action(TTR("Nodes Connected")); List<VisualShader::Connection> conns; visual_shader->get_node_connections(type, &conns); for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) { if (E->get().to_node == to && E->get().to_port == p_to_index) { undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port); undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port); } } undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, from, p_from_index, to, p_to_index); undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, from, p_from_index, to, p_to_index); undo_redo->add_do_method(this, "_update_graph"); undo_redo->add_undo_method(this, "_update_graph"); undo_redo->commit_action(); }
bool ButtonArray::_get(const StringName& p_name,Variant &r_ret) const { String n=String(p_name); if (n.begins_with("button/")) { String what = n.get_slicec('/',1); if (what=="count") { r_ret=buttons.size(); } else if (what=="align") { r_ret=get_align(); } else if (what=="selected") { r_ret=get_selected(); } else if (what == "min_button_size") { r_ret = min_button_size; } else { int idx=what.to_int(); ERR_FAIL_INDEX_V(idx,buttons.size(),false); String f = n.get_slicec('/',2); if (f=="text") r_ret=buttons[idx].text; else if (f=="tooltip") r_ret=buttons[idx].tooltip; else if (f=="icon") r_ret=buttons[idx].icon; else return false; } return true; } return false; }
void VisualShaderEditor::_disconnection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index) { graph->disconnect_node(p_from, p_from_index, p_to, p_to_index); VisualShader::Type type = VisualShader::Type(edit_type->get_selected()); int from = p_from.to_int(); int to = p_to.to_int(); //updating = true; seems graph edit can handle this, no need to protect undo_redo->create_action(TTR("Nodes Disconnected")); undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, from, p_from_index, to, p_to_index); undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, from, p_from_index, to, p_to_index); undo_redo->add_do_method(this, "_update_graph"); undo_redo->add_undo_method(this, "_update_graph"); undo_redo->commit_action(); //updating = false; }
void VisualShaderEditor::_connection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index) { VisualShader::Type type = VisualShader::Type(edit_type->get_selected()); int from = p_from.to_int(); int to = p_to.to_int(); if (!visual_shader->can_connect_nodes(type, from, p_from_index, to, p_to_index)) { EditorNode::get_singleton()->show_warning(TTR("Unable to connect, port may be in use or connection may be invalid.")); return; } undo_redo->create_action("Nodes Connected"); undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, from, p_from_index, to, p_to_index); undo_redo->add_undo_method(visual_shader.ptr(), "disconnect_nodes", type, from, p_from_index, to, p_to_index); undo_redo->add_do_method(this, "_update_graph"); undo_redo->add_undo_method(this, "_update_graph"); undo_redo->commit_action(); }
bool ButtonArray::_set(const StringName& p_name, const Variant& p_value) { String n=String(p_name); if (n.begins_with("button/")) { String what = n.get_slicec('/',1); if (what=="count") { int new_size=p_value; if (new_size>0 && buttons.size()==0) { selected=0; } if (new_size < buttons.size()) { if (selected>=new_size) selected=new_size-1; } buttons.resize(new_size); _change_notify(); minimum_size_changed(); } else if (what=="align") { set_align(Align(p_value.operator int())); } else if (what=="selected") { set_selected(p_value); } else if (what == "min_button_size") { min_button_size = p_value; } else { int idx=what.to_int(); ERR_FAIL_INDEX_V(idx,buttons.size(),false); String f = n.get_slicec('/',2); if (f=="text") buttons[idx].text=p_value; else if (f=="tooltip") buttons[idx].tooltip=p_value; else if (f=="icon") buttons[idx].icon=p_value; else return false; } update(); return true; } return false; }
void TileSetEditor::_name_dialog_confirm(const String &name) { switch (option) { case MENU_OPTION_REMOVE_ITEM: { int id = tileset->find_tile_by_name(name); if (id < 0 && name.is_valid_integer()) id = name.to_int(); if (tileset->has_tile(id)) { tileset->remove_tile(id); } else { err_dialog->set_text(TTR("Could not find tile:") + " " + name); err_dialog->popup_centered(Size2(300, 60)); } } break; } }
void GDTokenizerText::_advance() { if (error_flag) { //parser broke _make_error(last_error); return; } if (code_pos>=len) { _make_token(TK_EOF); return; } #define GETCHAR(m_ofs) ((m_ofs+code_pos)>=len?0:_code[m_ofs+code_pos]) #define INCPOS(m_amount) { code_pos+=m_amount; column+=m_amount; } while (true) { bool is_node_path = false; StringMode string_mode=STRING_DOUBLE_QUOTE; switch(GETCHAR(0)) { case 0: _make_token(TK_EOF); break; case '\\': INCPOS(1); if (GETCHAR(0)=='\r') { INCPOS(1); } if (GETCHAR(0)!='\n') { _make_error("Expected newline after '\\'."); return; } INCPOS(1); while(GETCHAR(0)==' ' || GETCHAR(0)=='\t') { INCPOS(1); } continue; case '\t': case '\r': case ' ': INCPOS(1); continue; case '\n': { line++; INCPOS(1); column=0; int i=0; while(GETCHAR(i)==' ' || GETCHAR(i)=='\t') { i++; } _make_newline(i); return; } #if 1 //py style tokenizer case '#': { // line comment skip while(GETCHAR(0)!='\n') { code_pos++; if (GETCHAR(0)==0) { //end of file //_make_error("Unterminated Comment"); _make_token(TK_EOF); return; } } INCPOS(1); column=0; line++; int i=0; while(GETCHAR(i)==' ' || GETCHAR(i)=='\t') { i++; } _make_newline(i); return; } break; #endif case '/': { switch(GETCHAR(1)) { #if 0 // c style tokenizer case '*': { // block comment int pos = code_pos+2; int new_line=line; int new_col=column+2; while(true) { if (_code[pos]=='0') { _make_error("Unterminated Comment"); code_pos=pos; return; } if (_code[pos]=='*' && _code[pos+1]=='/') { new_col+=2; pos+=2; //compensate break; } else if (_code[pos]=='\n') { new_line++; new_col=0; } else { new_col++; } pos++; } column=new_col; line=new_line; code_pos=pos; continue; } break; case '/': { // line comment skip while(GETCHAR(0)!='\n') { code_pos++; if (GETCHAR(0)==0) { //end of file _make_error("Unterminated Comment"); return; } } INCPOS(1); column=0; line++; continue; } break; #endif case '=': { // diveq _make_token(TK_OP_ASSIGN_DIV); INCPOS(1); } break; default: _make_token(TK_OP_DIV); } } break; case '=': { if (GETCHAR(1)=='=') { _make_token(TK_OP_EQUAL); INCPOS(1); } else _make_token(TK_OP_ASSIGN); } break; case '<': { if (GETCHAR(1)=='=') { _make_token(TK_OP_LESS_EQUAL); INCPOS(1); } else if (GETCHAR(1)=='<') { if (GETCHAR(2)=='=') { _make_token(TK_OP_ASSIGN_SHIFT_LEFT); INCPOS(1); } else { _make_token(TK_OP_SHIFT_LEFT); } INCPOS(1); } else _make_token(TK_OP_LESS); } break; case '>': { if (GETCHAR(1)=='=') { _make_token(TK_OP_GREATER_EQUAL); INCPOS(1); } else if (GETCHAR(1)=='>') { if (GETCHAR(2)=='=') { _make_token(TK_OP_ASSIGN_SHIFT_RIGHT); INCPOS(1); } else { _make_token(TK_OP_SHIFT_RIGHT); } INCPOS(1); } else { _make_token(TK_OP_GREATER); } } break; case '!': { if (GETCHAR(1)=='=') { _make_token(TK_OP_NOT_EQUAL); INCPOS(1); } else { _make_token(TK_OP_NOT); } } break; //case '"' //string - no strings in shader //case '\'' //string - no strings in shader case '{': _make_token(TK_CURLY_BRACKET_OPEN); break; case '}': _make_token(TK_CURLY_BRACKET_CLOSE); break; case '[': _make_token(TK_BRACKET_OPEN); break; case ']': _make_token(TK_BRACKET_CLOSE); break; case '(': _make_token(TK_PARENTHESIS_OPEN); break; case ')': _make_token(TK_PARENTHESIS_CLOSE); break; case ',': _make_token(TK_COMMA); break; case ';': _make_token(TK_SEMICOLON); break; case '?': _make_token(TK_QUESTION_MARK); break; case ':': _make_token(TK_COLON); //for methods maybe but now useless. break; case '^': { if (GETCHAR(1)=='=') { _make_token(TK_OP_ASSIGN_BIT_XOR); INCPOS(1); } else { _make_token(TK_OP_BIT_XOR); } } break; case '~': _make_token(TK_OP_BIT_INVERT); break; case '&': { if (GETCHAR(1)=='&') { _make_token(TK_OP_AND); INCPOS(1); } else if (GETCHAR(1)=='=') { _make_token(TK_OP_ASSIGN_BIT_AND); INCPOS(1); } else { _make_token(TK_OP_BIT_AND); } } break; case '|': { if (GETCHAR(1)=='|') { _make_token(TK_OP_OR); INCPOS(1); } else if (GETCHAR(1)=='=') { _make_token(TK_OP_ASSIGN_BIT_OR); INCPOS(1); } else { _make_token(TK_OP_BIT_OR); } } break; case '*': { if (GETCHAR(1)=='=') { _make_token(TK_OP_ASSIGN_MUL); INCPOS(1); } else { _make_token(TK_OP_MUL); } } break; case '+': { if (GETCHAR(1)=='=') { _make_token(TK_OP_ASSIGN_ADD); INCPOS(1); //} else if (GETCHAR(1)=='+') { // _make_token(TK_OP_PLUS_PLUS); // INCPOS(1); } else { _make_token(TK_OP_ADD); } } break; case '-': { if (GETCHAR(1)=='=') { _make_token(TK_OP_ASSIGN_SUB); INCPOS(1); //} else if (GETCHAR(1)=='-') { // _make_token(TK_OP_MINUS_MINUS); // INCPOS(1); } else { _make_token(TK_OP_SUB); } } break; case '%': { if (GETCHAR(1)=='=') { _make_token(TK_OP_ASSIGN_MOD); INCPOS(1); } else { _make_token(TK_OP_MOD); } } break; case '@': if( CharType(GETCHAR(1))!='"' && CharType(GETCHAR(1))!='\'' ) { _make_error("Unexpected '@'"); return; } INCPOS(1); is_node_path=true; case '\'': case '"': { if (GETCHAR(0)=='\'') string_mode=STRING_SINGLE_QUOTE; int i=1; if (string_mode==STRING_DOUBLE_QUOTE && GETCHAR(i)=='"' && GETCHAR(i+1)=='"') { i+=2; string_mode=STRING_MULTILINE; } String str; while(true) { if (CharType(GETCHAR(i))==0) { _make_error("Unterminated String"); return; } else if( string_mode==STRING_DOUBLE_QUOTE && CharType(GETCHAR(i))=='"' ) { break; } else if( string_mode==STRING_SINGLE_QUOTE && CharType(GETCHAR(i))=='\'' ) { break; } else if( string_mode==STRING_MULTILINE && CharType(GETCHAR(i))=='\"' && CharType(GETCHAR(i+1))=='\"' && CharType(GETCHAR(i+2))=='\"') { i+=2; break; } else if( string_mode!=STRING_MULTILINE && CharType(GETCHAR(i))=='\n') { _make_error("Unexpected EOL at String."); return; } else if (CharType(GETCHAR(i))=='\\') { //escaped characters... i++; CharType next = GETCHAR(i); if (next==0) { _make_error("Unterminated String"); return; } CharType res=0; switch(next) { case 'a': res=7; break; case 'b': res=8; break; case 't': res=9; break; case 'n': res=10; break; case 'v': res=11; break; case 'f': res=12; break; case 'r': res=13; break; case '\'': res='\''; break; case '\"': res='\"'; break; case '\\': res='\\'; break; case '/': res='/'; break; //wtf case 'u': { //hexnumbarh - oct is deprecated i+=1; for(int j=0;j<4;j++) { CharType c = GETCHAR(i+j); if (c==0) { _make_error("Unterminated String"); return; } if (!((c>='0' && c<='9') || (c>='a' && c<='f') || (c>='A' && c<='F'))) { _make_error("Malformed hex constant in string"); return; } CharType v; if (c>='0' && c<='9') { v=c-'0'; } else if (c>='a' && c<='f') { v=c-'a'; v+=10; } else if (c>='A' && c<='F') { v=c-'A'; v+=10; } else { ERR_PRINT("BUG"); v=0; } res<<=4; res|=v; } i+=3; } break; default: { _make_error("Invalid escape sequence"); return; } break; } str+=res; } else { str+=CharType(GETCHAR(i)); } i++; } INCPOS(i); if (is_node_path) { _make_constant(NodePath(str)); } else { _make_constant(str); } } break; case 0xFFFF: { _make_token(TK_CURSOR); } break; default: { if (_is_number(GETCHAR(0)) || (GETCHAR(0)=='.' && _is_number(GETCHAR(1)))) { // parse number bool period_found=false; bool exponent_found=false; bool hexa_found=false; bool sign_found=false; String str; int i=0; while(true) { if (GETCHAR(i)=='.') { if (period_found || exponent_found) { _make_error("Invalid numeric constant at '.'"); return; } period_found=true; } else if (GETCHAR(i)=='x') { if (hexa_found || str.length()!=1 || !( (i==1 && str[0]=='0') || (i==2 && str[1]=='0' && str[0]=='-') ) ) { _make_error("Invalid numeric constant at 'x'"); return; } hexa_found=true; } else if (!hexa_found && GETCHAR(i)=='e') { if (hexa_found || exponent_found) { _make_error("Invalid numeric constant at 'e'"); return; } exponent_found=true; } else if (_is_number(GETCHAR(i))) { //all ok } else if (hexa_found && _is_hex(GETCHAR(i))) { } else if ((GETCHAR(i)=='-' || GETCHAR(i)=='+') && exponent_found) { if (sign_found) { _make_error("Invalid numeric constant at '-'"); return; } sign_found=true; } else break; str+=CharType(GETCHAR(i)); i++; } if (!( _is_number(str[str.length()-1]) || (hexa_found && _is_hex(str[str.length()-1])))) { _make_error("Invalid numeric constant: "+str); return; } INCPOS(str.length()); if (hexa_found) { int val = str.hex_to_int(); _make_constant(val); } else if (period_found) { real_t val = str.to_double(); //print_line("*%*%*%*% to convert: "+str+" result: "+rtos(val)); _make_constant(val); } else { int val = str.to_int(); _make_constant(val); } return; } if (GETCHAR(0)=='.') { //parse period _make_token(TK_PERIOD); break; } if (_is_text_char(GETCHAR(0))) { // parse identifier String str; str+=CharType(GETCHAR(0)); int i=1; while(_is_text_char(GETCHAR(i))) { str+=CharType(GETCHAR(i)); i++; } bool identifier=false; if (str=="null") { _make_constant(Variant()); } else if (str=="true") { _make_constant(true); } else if (str=="false") { _make_constant(false); } else { bool found=false; struct _bit { Variant::Type type; const char *text;}; //built in types static const _bit type_list[]={ //types {Variant::BOOL,"bool"}, {Variant::INT,"int"}, {Variant::REAL,"float"}, {Variant::STRING,"String"}, {Variant::VECTOR2,"vec2"}, {Variant::VECTOR2,"Vector2"}, {Variant::RECT2,"Rect2"}, {Variant::MATRIX32,"Matrix32"}, {Variant::MATRIX32,"mat32"}, {Variant::VECTOR3,"vec3"}, {Variant::VECTOR3,"Vector3"}, {Variant::_AABB,"AABB"}, {Variant::_AABB,"Rect3"}, {Variant::PLANE,"Plane"}, {Variant::QUAT,"Quat"}, {Variant::MATRIX3,"mat3"}, {Variant::MATRIX3,"Matrix3"}, {Variant::TRANSFORM,"trn"}, {Variant::TRANSFORM,"Transform"}, {Variant::COLOR,"Color"}, {Variant::IMAGE,"Image"}, {Variant::_RID,"RID"}, {Variant::OBJECT,"Object"}, {Variant::INPUT_EVENT,"InputEvent"}, {Variant::NODE_PATH,"NodePath"}, {Variant::DICTIONARY,"dict"}, {Variant::DICTIONARY,"Dictionary"}, {Variant::ARRAY,"Array"}, {Variant::RAW_ARRAY,"RawArray"}, {Variant::INT_ARRAY,"IntArray"}, {Variant::REAL_ARRAY,"FloatArray"}, {Variant::STRING_ARRAY,"StringArray"}, {Variant::VECTOR2_ARRAY,"Vector2Array"}, {Variant::VECTOR3_ARRAY,"Vector3Array"}, {Variant::COLOR_ARRAY,"ColorArray"}, {Variant::VARIANT_MAX,NULL}, }; { int idx=0; while(type_list[idx].text) { if (str==type_list[idx].text) { _make_type(type_list[idx].type); found=true; break; } idx++; } } if (!found) { //built in func? for(int i=0;i<GDFunctions::FUNC_MAX;i++) { if (str==GDFunctions::get_func_name(GDFunctions::Function(i))) { _make_built_in_func(GDFunctions::Function(i)); found=true; break; } } //keywor } if (!found) { struct _kws { Token token; const char *text;}; static const _kws keyword_list[]={ //ops {TK_OP_IN,"in"}, {TK_OP_NOT,"not"}, {TK_OP_OR,"or"}, {TK_OP_AND,"and"}, //func {TK_PR_FUNCTION,"func"}, {TK_PR_FUNCTION,"function"}, {TK_PR_CLASS,"class"}, {TK_PR_EXTENDS,"extends"}, {TK_PR_TOOL,"tool"}, {TK_PR_STATIC,"static"}, {TK_PR_EXPORT,"export"}, {TK_PR_SETGET,"setget"}, {TK_PR_VAR,"var"}, {TK_PR_PRELOAD,"preload"}, {TK_PR_ASSERT,"assert"}, {TK_PR_YIELD,"yield"}, {TK_PR_CONST,"const"}, //controlflow {TK_CF_IF,"if"}, {TK_CF_ELIF,"elif"}, {TK_CF_ELSE,"else"}, {TK_CF_FOR,"for"}, {TK_CF_WHILE,"while"}, {TK_CF_DO,"do"}, {TK_CF_SWITCH,"switch"}, {TK_CF_BREAK,"break"}, {TK_CF_CONTINUE,"continue"}, {TK_CF_RETURN,"return"}, {TK_CF_PASS,"pass"}, {TK_SELF,"self"}, {TK_ERROR,NULL} }; int idx=0; found=false; while(keyword_list[idx].text) { if (str==keyword_list[idx].text) { _make_token(keyword_list[idx].token); found=true; break; } idx++; } } if (!found) identifier=true; } if (identifier) { _make_identifier(str); } INCPOS(str.length()); return; } _make_error("Unknown character"); return; } break; } INCPOS(1); break; } }
Error HTTPClient::poll(){ switch(status) { case STATUS_RESOLVING: { ERR_FAIL_COND_V(resolving==IP::RESOLVER_INVALID_ID,ERR_BUG); IP::ResolverStatus rstatus = IP::get_singleton()->get_resolve_item_status(resolving); switch(rstatus) { case IP::RESOLVER_STATUS_WAITING: return OK; //still resolving case IP::RESOLVER_STATUS_DONE: { IP_Address host = IP::get_singleton()->get_resolve_item_address(resolving); Error err = tcp_connection->connect(host,conn_port); IP::get_singleton()->erase_resolve_item(resolving); resolving=IP::RESOLVER_INVALID_ID; if (err) { status=STATUS_CANT_CONNECT; return err; } status=STATUS_CONNECTING; } break; case IP::RESOLVER_STATUS_NONE: case IP::RESOLVER_STATUS_ERROR: { IP::get_singleton()->erase_resolve_item(resolving); resolving=IP::RESOLVER_INVALID_ID; close(); status=STATUS_CANT_RESOLVE; return ERR_CANT_RESOLVE; } break; } } break; case STATUS_CONNECTING: { StreamPeerTCP::Status s = tcp_connection->get_status(); switch(s) { case StreamPeerTCP::STATUS_CONNECTING: { return OK; //do none } break; case StreamPeerTCP::STATUS_CONNECTED: { if (ssl) { Ref<StreamPeerSSL> ssl = StreamPeerSSL::create(); Error err = ssl->connect(tcp_connection,true,ssl_verify_host?conn_host:String()); if (err!=OK) { close(); status=STATUS_SSL_HANDSHAKE_ERROR; return ERR_CANT_CONNECT; } print_line("SSL! TURNED ON!"); connection=ssl; } status=STATUS_CONNECTED; return OK; } break; case StreamPeerTCP::STATUS_ERROR: case StreamPeerTCP::STATUS_NONE: { close(); status=STATUS_CANT_CONNECT; return ERR_CANT_CONNECT; } break; } } break; case STATUS_CONNECTED: { //request something please return OK; } break; case STATUS_REQUESTING: { while(true) { uint8_t byte; int rec=0; Error err = connection->get_partial_data(&byte,1,rec); if (err!=OK) { close(); status=STATUS_CONNECTION_ERROR; return ERR_CONNECTION_ERROR; } if (rec==0) return OK; //keep trying! response_str.push_back(byte); int rs = response_str.size(); if ( (rs>=2 && response_str[rs-2]=='\n' && response_str[rs-1]=='\n') || (rs>=4 && response_str[rs-4]=='\r' && response_str[rs-3]=='\n' && rs>=4 && response_str[rs-2]=='\r' && response_str[rs-1]=='\n') ) { //end of response, parse. response_str.push_back(0); String response; response.parse_utf8((const char*)response_str.ptr()); print_line("END OF RESPONSE? :\n"+response+"\n------"); Vector<String> responses = response.split("\n"); body_size=0; chunked=false; body_left=0; chunk_left=0; response_headers.clear(); response_num = RESPONSE_OK; for(int i=0;i<responses.size();i++) { String s = responses[i].strip_edges(); if (s.length()==0) continue; if (s.begins_with("Content-Length:")) { body_size = s.substr(s.find(":")+1,s.length()).strip_edges().to_int(); body_left=body_size; } if (s.begins_with("Transfer-Encoding:")) { String encoding = s.substr(s.find(":")+1,s.length()).strip_edges(); print_line("TRANSFER ENCODING: "+encoding); if (encoding=="chunked") { chunked=true; } } if (i==0 && responses[i].begins_with("HTTP")) { String num = responses[i].get_slice(" ",1); response_num=num.to_int(); } else { response_headers.push_back(s); } } if (body_size==0 && !chunked) { status=STATUS_CONNECTED; //ask for something again? } else { status=STATUS_BODY; } return OK; } } //wait for response return OK; } break; case STATUS_DISCONNECTED: { return ERR_UNCONFIGURED; } break; case STATUS_CONNECTION_ERROR: { return ERR_CONNECTION_ERROR; } break; case STATUS_CANT_CONNECT: { return ERR_CANT_CONNECT; } break; case STATUS_CANT_RESOLVE: { return ERR_CANT_RESOLVE; } break; } return OK; }
Error HTTPClient::poll() { switch (status) { case STATUS_RESOLVING: { ERR_FAIL_COND_V(resolving == IP::RESOLVER_INVALID_ID, ERR_BUG); IP::ResolverStatus rstatus = IP::get_singleton()->get_resolve_item_status(resolving); switch (rstatus) { case IP::RESOLVER_STATUS_WAITING: return OK; // Still resolving case IP::RESOLVER_STATUS_DONE: { IP_Address host = IP::get_singleton()->get_resolve_item_address(resolving); Error err = tcp_connection->connect_to_host(host, conn_port); IP::get_singleton()->erase_resolve_item(resolving); resolving = IP::RESOLVER_INVALID_ID; if (err) { status = STATUS_CANT_CONNECT; return err; } status = STATUS_CONNECTING; } break; case IP::RESOLVER_STATUS_NONE: case IP::RESOLVER_STATUS_ERROR: { IP::get_singleton()->erase_resolve_item(resolving); resolving = IP::RESOLVER_INVALID_ID; close(); status = STATUS_CANT_RESOLVE; return ERR_CANT_RESOLVE; } break; } } break; case STATUS_CONNECTING: { StreamPeerTCP::Status s = tcp_connection->get_status(); switch (s) { case StreamPeerTCP::STATUS_CONNECTING: { return OK; } break; case StreamPeerTCP::STATUS_CONNECTED: { if (ssl) { Ref<StreamPeerSSL> ssl; if (!handshaking) { // Connect the StreamPeerSSL and start handshaking ssl = Ref<StreamPeerSSL>(StreamPeerSSL::create()); ssl->set_blocking_handshake_enabled(false); Error err = ssl->connect_to_stream(tcp_connection, ssl_verify_host, conn_host); if (err != OK) { close(); status = STATUS_SSL_HANDSHAKE_ERROR; return ERR_CANT_CONNECT; } connection = ssl; handshaking = true; } else { // We are already handshaking, which means we can use your already active SSL connection ssl = static_cast<Ref<StreamPeerSSL> >(connection); ssl->poll(); // Try to finish the handshake } if (ssl->get_status() == StreamPeerSSL::STATUS_CONNECTED) { // Handshake has been successfull handshaking = false; status = STATUS_CONNECTED; return OK; } else if (ssl->get_status() != StreamPeerSSL::STATUS_HANDSHAKING) { // Handshake has failed close(); status = STATUS_SSL_HANDSHAKE_ERROR; return ERR_CANT_CONNECT; } // ... we will need to poll more for handshake to finish } else { status = STATUS_CONNECTED; } return OK; } break; case StreamPeerTCP::STATUS_ERROR: case StreamPeerTCP::STATUS_NONE: { close(); status = STATUS_CANT_CONNECT; return ERR_CANT_CONNECT; } break; } } break; case STATUS_CONNECTED: { // Connection established, requests can now be made return OK; } break; case STATUS_REQUESTING: { while (true) { uint8_t byte; int rec = 0; Error err = _get_http_data(&byte, 1, rec); if (err != OK) { close(); status = STATUS_CONNECTION_ERROR; return ERR_CONNECTION_ERROR; } if (rec == 0) return OK; // Still requesting, keep trying! response_str.push_back(byte); int rs = response_str.size(); if ( (rs >= 2 && response_str[rs - 2] == '\n' && response_str[rs - 1] == '\n') || (rs >= 4 && response_str[rs - 4] == '\r' && response_str[rs - 3] == '\n' && response_str[rs - 2] == '\r' && response_str[rs - 1] == '\n')) { // End of response, parse. response_str.push_back(0); String response; response.parse_utf8((const char *)response_str.ptr()); Vector<String> responses = response.split("\n"); body_size = 0; chunked = false; body_left = 0; chunk_left = 0; read_until_eof = false; response_str.clear(); response_headers.clear(); response_num = RESPONSE_OK; // Per the HTTP 1.1 spec, keep-alive is the default, but in practice // it's safe to assume it only if the explicit header is found, allowing // to handle body-up-to-EOF responses on naive servers; that's what Curl // and browsers do bool keep_alive = false; for (int i = 0; i < responses.size(); i++) { String header = responses[i].strip_edges(); String s = header.to_lower(); if (s.length() == 0) continue; if (s.begins_with("content-length:")) { body_size = s.substr(s.find(":") + 1, s.length()).strip_edges().to_int(); body_left = body_size; } else if (s.begins_with("transfer-encoding:")) { String encoding = header.substr(header.find(":") + 1, header.length()).strip_edges(); if (encoding == "chunked") { chunked = true; } } else if (s.begins_with("connection: keep-alive")) { keep_alive = true; } if (i == 0 && responses[i].begins_with("HTTP")) { String num = responses[i].get_slicec(' ', 1); response_num = num.to_int(); } else { response_headers.push_back(header); } } if (body_size || chunked) { status = STATUS_BODY; } else if (!keep_alive) { read_until_eof = true; status = STATUS_BODY; } else { status = STATUS_CONNECTED; } return OK; } } // Wait for response return OK; } break; case STATUS_DISCONNECTED: { return ERR_UNCONFIGURED; } break; case STATUS_CONNECTION_ERROR: { return ERR_CONNECTION_ERROR; } break; case STATUS_CANT_CONNECT: { return ERR_CANT_CONNECT; } break; case STATUS_CANT_RESOLVE: { return ERR_CANT_RESOLVE; } break; } return OK; }
Error ResourceInteractiveLoaderBinary::poll(){ if (error!=OK) return error; int s = stage; if (s<external_resources.size()) { RES res = ResourceLoader::load(external_resources[s].path,external_resources[s].type); if (res.is_null()) { if (!ResourceLoader::get_abort_on_missing_resources()) { ResourceLoader::notify_load_error("Resource Not Found: "+external_resources[s].path); } else { error=ERR_FILE_CORRUPT; ERR_EXPLAIN("Can't load dependency: "+external_resources[s].path); ERR_FAIL_V(error); } } else { resource_cache.push_back(res); } stage++; return error; } s-=external_resources.size(); if (s>=internal_resources.size()) { error=ERR_BUG; ERR_FAIL_COND_V(s>=internal_resources.size(),error); } bool main = s==(internal_resources.size()-1); //maybe it is loaded already String path; int subindex=0; if (!main) { path=internal_resources[s].path; if (path.begins_with("local://")) { path=path.replace_first("local://",""); subindex = path.to_int(); path=res_path+"::"+path; } if (ResourceCache::has(path)) { //already loaded, don't do anything stage++; error=OK; return error; } } else { path=res_path; } uint64_t offset = internal_resources[s].offset; f->seek(offset); String t = get_unicode_string(); Object *obj = ObjectTypeDB::instance(t); if (!obj) { error=ERR_FILE_CORRUPT; ERR_EXPLAIN(local_path+":Resource of unrecognized type in file: "+t); } ERR_FAIL_COND_V(!obj,ERR_FILE_CORRUPT); Resource *r = obj->cast_to<Resource>(); if (!r) { error=ERR_FILE_CORRUPT; memdelete(obj); //bye ERR_EXPLAIN(local_path+":Resoucre type in resource field not a resource, type is: "+obj->get_type()); ERR_FAIL_COND_V(!r,ERR_FILE_CORRUPT); } RES res = RES( r ); r->set_path(path); r->set_subindex(subindex); int pc = f->get_32(); //set properties for(int i=0;i<pc;i++) { uint32_t name_idx = f->get_32(); if (name_idx>=(uint32_t)string_map.size()) { error=ERR_FILE_CORRUPT; ERR_FAIL_V(ERR_FILE_CORRUPT); } Variant value; error = parse_variant(value); if (error) return error; res->set(string_map[name_idx],value); } #ifdef TOOLS_ENABLED res->set_edited(false); #endif stage++; resource_cache.push_back(res); if (main) { if (importmd_ofs) { f->seek(importmd_ofs); Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata ); imd->set_editor(get_unicode_string()); int sc = f->get_32(); for(int i=0;i<sc;i++) { String src = get_unicode_string(); String md5 = get_unicode_string(); imd->add_source(src,md5); } int pc = f->get_32(); for(int i=0;i<pc;i++) { String name = get_unicode_string(); Variant val; parse_variant(val); imd->set_option(name,val); } res->set_import_metadata(imd); } f->close(); resource=res; error=ERR_FILE_EOF; } else { error=OK; } return OK; }
static String _fix_error_code_line(const String& p_error,int p_code_start,int p_offset) { int last_find_pos=-1; // NVIDIA String error=p_error; while((last_find_pos=p_error.find("(",last_find_pos+1))!=-1) { int end_pos=last_find_pos+1; while(true) { if (p_error[end_pos]>='0' && p_error[end_pos]<='9') { end_pos++; continue; } else if (p_error[end_pos]==')') { break; } else { end_pos=-1; break; } } if (end_pos==-1) continue; String numstr = error.substr(last_find_pos+1,(end_pos-last_find_pos)-1); String begin = error.substr(0,last_find_pos+1); String end = error.substr(end_pos,error.length()); int num = numstr.to_int()+p_code_start-p_offset; error = begin+itos(num)+end; } // ATI last_find_pos=-1; while((last_find_pos=p_error.find("ERROR: ",last_find_pos+1))!=-1) { last_find_pos+=6; int end_pos=last_find_pos+1; while(true) { if (p_error[end_pos]>='0' && p_error[end_pos]<='9') { end_pos++; continue; } else if (p_error[end_pos]==':') { break; } else { end_pos=-1; break; } } continue; if (end_pos==-1) continue; String numstr = error.substr(last_find_pos+1,(end_pos-last_find_pos)-1); print_line("numstr: "+numstr); String begin = error.substr(0,last_find_pos+1); String end = error.substr(end_pos,error.length()); int num = numstr.to_int()+p_code_start-p_offset; error = begin+itos(num)+end; } return error; }
void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { current_option=p_tool; switch(p_tool) { case TOOL_NEW: { create_dialog->popup_centered_ratio(); } break; case TOOL_INSTANCE: { Node *scene = edited_scene; if (!scene) { current_option=-1; //confirmation->get_cancel()->hide(); accept->get_ok()->set_text("I see.."); accept->set_text("This operation can't be done without a tree root."); accept->popup_centered(Size2(300,70));; break; } file->set_mode(FileDialog::MODE_OPEN_FILE); List<String> extensions; ResourceLoader::get_recognized_extensions_for_type("PackedScene",&extensions); file->clear_filters(); for(int i=0;i<extensions.size();i++) { file->add_filter("*."+extensions[i]+" ; "+extensions[i].to_upper()); } //file->set_current_path(current_path); file->popup_centered_ratio(); } break; case TOOL_REPLACE: { create_dialog->popup_centered_ratio(); } break; case TOOL_CONNECT: { Node *current = scene_tree->get_selected(); if (!current) break; connect_dialog->popup_centered_ratio(); connect_dialog->set_node(current); } break; case TOOL_GROUP: { Node *current = scene_tree->get_selected(); if (!current) break; groups_editor->set_current(current); groups_editor->popup_centered_ratio(); } break; case TOOL_SCRIPT: { Node *selected = scene_tree->get_selected(); if (!selected) break; Ref<Script> existing = selected->get_script(); if (existing.is_valid()) editor->push_item(existing.ptr()); else { String path = selected->get_filename(); script_create_dialog->config(selected->get_type(),path); script_create_dialog->popup_centered(Size2(300,290)); //script_create_dialog->popup_centered_minsize(); } } break; case TOOL_MOVE_UP: case TOOL_MOVE_DOWN: { if (!scene_tree->get_selected()) break; if (scene_tree->get_selected()==edited_scene) { current_option=-1; //accept->get_cancel()->hide(); accept->get_ok()->set_text("I see.."); accept->set_text("This operation can't be done on the tree root."); accept->popup_centered(Size2(300,70));; break; } Node * node=scene_tree->get_selected(); ERR_FAIL_COND(!node->get_parent()); int current_pos = node->get_index(); int next_pos = current_pos + ((p_tool==TOOL_MOVE_DOWN)?1:-1); if (next_pos< 0 || next_pos>=node->get_parent()->get_child_count()) break; // invalid position editor_data->get_undo_redo().create_action("Move Node In Parent"); editor_data->get_undo_redo().add_do_method(node->get_parent(),"move_child",node,next_pos); editor_data->get_undo_redo().add_undo_method(node->get_parent(),"move_child",node,current_pos); editor_data->get_undo_redo().commit_action(); } break; case TOOL_DUPLICATE: { if (!edited_scene) break; if (editor_selection->is_selected(edited_scene)) { current_option=-1; //accept->get_cancel()->hide(); accept->get_ok()->set_text("I see.."); accept->set_text("This operation can't be done on the tree root."); accept->popup_centered(Size2(300,70));; break; } List<Node*> selection = editor_selection->get_selected_node_list(); List<Node*> reselect; editor_data->get_undo_redo().create_action("Duplicate Node(s)"); editor_data->get_undo_redo().add_do_method(editor_selection,"clear"); Node *dupsingle=NULL; for (List<Node*>::Element *E=selection.front();E;E=E->next()) { Node *node = E->get(); Node *parent = node->get_parent(); List<Node*> owned; node->get_owned_by(node->get_owner(),&owned); Map<Node*,Node*> duplimap; Node * dup = _duplicate(node,duplimap); ERR_CONTINUE(!dup); if (selection.size()==1) dupsingle=dup; String name = node->get_name(); String nums; for(int i=name.length()-1;i>=0;i--) { CharType n=name[i]; if (n>='0' && n<='9') { nums=String::chr(name[i])+nums; } else { break; } } int num=nums.to_int(); if (num<2) num=2; else num++; name=name.substr(0,name.length()-nums.length()).strip_edges(); String attempt=name+" "+itos(num); while(parent->has_node(attempt)) { num++; attempt=name+" "+itos(num); } dup->set_name(attempt); editor_data->get_undo_redo().add_do_method(parent,"add_child",dup); for (List<Node*>::Element *F=owned.front();F;F=F->next()) { if (!duplimap.has(F->get())) { continue; } Node *d=duplimap[F->get()]; editor_data->get_undo_redo().add_do_method(d,"set_owner",node->get_owner()); } editor_data->get_undo_redo().add_do_method(editor_selection,"add_node",dup); editor_data->get_undo_redo().add_undo_method(parent,"remove_child",dup); editor_data->get_undo_redo().add_do_reference(dup); //parent->add_child(dup); //reselect.push_back(dup); } editor_data->get_undo_redo().commit_action(); if (dupsingle) editor->push_item(dupsingle); } break; case TOOL_REPARENT: { if (!scene_tree->get_selected()) break; if (editor_selection->is_selected(edited_scene)) { current_option=-1; //confirmation->get_cancel()->hide(); accept->get_ok()->set_text("I see.."); accept->set_text("This operation can't be done on the tree root."); accept->popup_centered(Size2(300,70));; break; } List<Node*> nodes = editor_selection->get_selected_node_list(); Set<Node*> nodeset; for(List<Node*>::Element *E=nodes.front();E;E=E->next()) { nodeset.insert(E->get()); } reparent_dialog->popup_centered_ratio(); reparent_dialog->set_current( nodeset ); } break; case TOOL_ERASE: { List<Node*> remove_list = editor_selection->get_selected_node_list(); if (remove_list.empty()) return; if (p_confirm_override) { _delete_confirm(); // hack, force 2d editor viewport to refresh after deletion if (CanvasItemEditor *editor = CanvasItemEditor::get_singleton()) editor->get_viewport_control()->update(); } else { delete_dialog->set_text("Delete Node(s)?"); delete_dialog->popup_centered(Size2(200,80)); } } break; } }
void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { current_option=p_tool; switch(p_tool) { case TOOL_NEW: { //if (!_validate_no_foreign()) // break; create_dialog->popup_centered_ratio(); } break; case TOOL_INSTANCE: { Node *scene = edited_scene; if (!scene) { current_option=-1; //confirmation->get_cancel()->hide(); accept->get_ok()->set_text("I see.."); accept->set_text("This operation can't be done without a tree root."); accept->popup_centered_minsize(); break; } //if (!_validate_no_foreign()) // break; file->set_mode(EditorFileDialog::MODE_OPEN_FILE); List<String> extensions; ResourceLoader::get_recognized_extensions_for_type("PackedScene",&extensions); file->clear_filters(); for(int i=0;i<extensions.size();i++) { file->add_filter("*."+extensions[i]+" ; "+extensions[i].to_upper()); } //file->set_current_path(current_path); file->popup_centered_ratio(); } break; case TOOL_REPLACE: { create_dialog->popup_centered_ratio(); } break; case TOOL_CONNECT: { Node *current = scene_tree->get_selected(); if (!current) break; //if (!_validate_no_foreign()) // break; connect_dialog->popup_centered_ratio(); connect_dialog->set_node(current); } break; case TOOL_GROUP: { Node *current = scene_tree->get_selected(); if (!current) break; //if (!_validate_no_foreign()) // break; groups_editor->set_current(current); groups_editor->popup_centered_ratio(); } break; case TOOL_SCRIPT: { Node *selected = scene_tree->get_selected(); if (!selected) break; //if (!_validate_no_foreign()) // break; Ref<Script> existing = selected->get_script(); if (existing.is_valid()) editor->push_item(existing.ptr()); else { String path = selected->get_filename(); script_create_dialog->config(selected->get_type(),path); script_create_dialog->popup_centered(Size2(300,290)); //script_create_dialog->popup_centered_minsize(); } } break; case TOOL_MOVE_UP: case TOOL_MOVE_DOWN: { if (!scene_tree->get_selected()) break; if (scene_tree->get_selected()==edited_scene) { current_option=-1; //accept->get_cancel()->hide(); accept->get_ok()->set_text("I see.."); accept->set_text("This operation can't be done on the tree root."); accept->popup_centered_minsize(); break; } if (!_validate_no_foreign()) break; bool MOVING_DOWN = (p_tool == TOOL_MOVE_DOWN); bool MOVING_UP = !MOVING_DOWN; Node *common_parent = scene_tree->get_selected()->get_parent(); List<Node*> selection = editor_selection->get_selected_node_list(); selection.sort_custom<Node::Comparator>(); // sort by index if (MOVING_DOWN) selection.invert(); int lowest_id = common_parent->get_child_count() - 1; int highest_id = 0; for (List<Node*>::Element *E = selection.front(); E; E = E->next()) { int index = E->get()->get_index(); if (index > highest_id) highest_id = index; if (index < lowest_id) lowest_id = index; if (E->get()->get_parent() != common_parent) common_parent = NULL; } if (!common_parent || (MOVING_DOWN && highest_id >= common_parent->get_child_count() - MOVING_DOWN) || (MOVING_UP && lowest_id == 0)) break; // one or more nodes can not be moved if (selection.size() == 1) editor_data->get_undo_redo().create_action("Move Node In Parent"); if (selection.size() > 1) editor_data->get_undo_redo().create_action("Move Nodes In Parent"); for (int i = 0; i < selection.size(); i++) { Node *top_node = selection[i]; Node *bottom_node = selection[selection.size() - 1 - i]; ERR_FAIL_COND(!top_node->get_parent()); ERR_FAIL_COND(!bottom_node->get_parent()); int top_node_pos = top_node->get_index(); int bottom_node_pos = bottom_node->get_index(); int top_node_pos_next = top_node_pos + (MOVING_DOWN ? 1 : -1); int bottom_node_pos_next = bottom_node_pos + (MOVING_DOWN ? 1 : -1); editor_data->get_undo_redo().add_do_method(top_node->get_parent(), "move_child", top_node, top_node_pos_next); editor_data->get_undo_redo().add_undo_method(bottom_node->get_parent(), "move_child", bottom_node, bottom_node_pos); } editor_data->get_undo_redo().commit_action(); } break; case TOOL_DUPLICATE: { if (!edited_scene) break; if (editor_selection->is_selected(edited_scene)) { current_option=-1; //accept->get_cancel()->hide(); accept->get_ok()->set_text("I see.."); accept->set_text("This operation can't be done on the tree root."); accept->popup_centered_minsize(); break; } if (!_validate_no_foreign()) break; List<Node*> selection = editor_selection->get_selected_node_list(); List<Node*> reselect; editor_data->get_undo_redo().create_action("Duplicate Node(s)"); editor_data->get_undo_redo().add_do_method(editor_selection,"clear"); Node *dupsingle=NULL; for (List<Node*>::Element *E=selection.front();E;E=E->next()) { Node *node = E->get(); Node *parent = node->get_parent(); List<Node*> owned; node->get_owned_by(node->get_owner(),&owned); Map<Node*,Node*> duplimap; Node * dup = _duplicate(node,duplimap); ERR_CONTINUE(!dup); if (selection.size()==1) dupsingle=dup; String name = node->get_name(); String nums; for(int i=name.length()-1;i>=0;i--) { CharType n=name[i]; if (n>='0' && n<='9') { nums=String::chr(name[i])+nums; } else { break; } } int num=nums.to_int(); if (num<1) num=1; else num++; String nnsep = _get_name_num_separator(); name = name.substr(0,name.length()-nums.length()).strip_edges(); if ( name.substr(name.length()-nnsep.length(),nnsep.length()) == nnsep) { name = name.substr(0,name.length()-nnsep.length()); } String attempt = (name + nnsep + itos(num)).strip_edges(); while(parent->has_node(attempt)) { num++; attempt = (name + nnsep + itos(num)).strip_edges(); } dup->set_name(attempt); editor_data->get_undo_redo().add_do_method(parent,"add_child",dup); for (List<Node*>::Element *F=owned.front();F;F=F->next()) { if (!duplimap.has(F->get())) { continue; } Node *d=duplimap[F->get()]; editor_data->get_undo_redo().add_do_method(d,"set_owner",node->get_owner()); } editor_data->get_undo_redo().add_do_method(editor_selection,"add_node",dup); editor_data->get_undo_redo().add_undo_method(parent,"remove_child",dup); editor_data->get_undo_redo().add_do_reference(dup); ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger(); editor_data->get_undo_redo().add_do_method(sed,"live_debug_duplicate_node",edited_scene->get_path_to(node),attempt); editor_data->get_undo_redo().add_undo_method(sed,"live_debug_remove_node",NodePath(String(edited_scene->get_path_to(parent))+"/"+attempt)); //parent->add_child(dup); //reselect.push_back(dup); } editor_data->get_undo_redo().commit_action(); if (dupsingle) editor->push_item(dupsingle); } break; case TOOL_REPARENT: { if (!scene_tree->get_selected()) break; if (editor_selection->is_selected(edited_scene)) { current_option=-1; //confirmation->get_cancel()->hide(); accept->get_ok()->set_text("I see.."); accept->set_text("This operation can't be done on the tree root."); accept->popup_centered_minsize(); break; } if (!_validate_no_foreign()) break; List<Node*> nodes = editor_selection->get_selected_node_list(); Set<Node*> nodeset; for(List<Node*>::Element *E=nodes.front();E;E=E->next()) { nodeset.insert(E->get()); } reparent_dialog->popup_centered_ratio(); reparent_dialog->set_current( nodeset ); } break; case TOOL_MULTI_EDIT: { Node*root=EditorNode::get_singleton()->get_edited_scene(); if (!root) break; Ref<MultiNodeEdit> mne = memnew( MultiNodeEdit ); for (const Map<Node*,Object*>::Element *E=EditorNode::get_singleton()->get_editor_selection()->get_selection().front();E;E=E->next()) { mne->add_node(root->get_path_to(E->key())); } EditorNode::get_singleton()->push_item(mne.ptr()); } break; case TOOL_ERASE: { List<Node*> remove_list = editor_selection->get_selected_node_list(); if (remove_list.empty()) return; if (!_validate_no_foreign()) break; if (p_confirm_override) { _delete_confirm(); // hack, force 2d editor viewport to refresh after deletion if (CanvasItemEditor *editor = CanvasItemEditor::get_singleton()) editor->get_viewport_control()->update(); } else { delete_dialog->set_text("Delete Node(s)?"); delete_dialog->popup_centered_minsize(); } } break; } }
bool PowerX11::int_string(char *str, int *val) { String sval = str; *val = sval.to_int(); return (*str != '\0'); }
void PowerX11::check_proc_acpi_battery(const char *node, bool *have_battery, bool *charging) { const char *base = proc_acpi_battery_path; char info[1024]; char state[1024]; char *ptr = NULL; char *key = NULL; char *val = NULL; bool charge = false; bool choose = false; int maximum = -1; int remaining = -1; int secs = -1; int pct = -1; if (!read_power_file(base, node, "state", state, sizeof(state))) { return; } else { if (!read_power_file(base, node, "info", info, sizeof(info))) return; } ptr = &state[0]; while (make_proc_acpi_key_val(&ptr, &key, &val)) { if (String(key) == "present") { if (String(val) == "yes") { *have_battery = true; } } else if (String(key) == "charging state") { /* !!! FIXME: what exactly _does_ charging/discharging mean? */ if (String(val) == "charging/discharging") { charge = true; } else if (String(val) == "charging") { charge = true; } } else if (String(key) == "remaining capacity") { String sval = val; const int cvt = sval.to_int(); remaining = cvt; } } ptr = &info[0]; while (make_proc_acpi_key_val(&ptr, &key, &val)) { if (String(key) == "design capacity") { String sval = val; const int cvt = sval.to_int(); maximum = cvt; } } if ((maximum >= 0) && (remaining >= 0)) { pct = (int)((((float)remaining) / ((float)maximum)) * 100.0f); if (pct < 0) { pct = 0; } else if (pct > 100) { pct = 100; } } /* !!! FIXME: calculate (secs). */ /* * We pick the battery that claims to have the most minutes left. * (failing a report of minutes, we'll take the highest percent.) */ if ((secs < 0) && (this->nsecs_left < 0)) { if ((pct < 0) && (this->percent_left < 0)) { choose = true; /* at least we know there's a battery. */ } if (pct > this->percent_left) { choose = true; } } else if (secs > this->nsecs_left) { choose = true; } if (choose) { this->nsecs_left = secs; this->percent_left = pct; *charging = charge; } }
Error VisualScriptExpression::_get_token(Token &r_token) { while (true) { #define GET_CHAR() (str_ofs >= expression.length() ? 0 : expression[str_ofs++]) CharType cchar = GET_CHAR(); if (cchar == 0) { r_token.type = TK_EOF; return OK; } switch (cchar) { case 0: { r_token.type = TK_EOF; return OK; } break; case '{': { r_token.type = TK_CURLY_BRACKET_OPEN; return OK; }; case '}': { r_token.type = TK_CURLY_BRACKET_CLOSE; return OK; }; case '[': { r_token.type = TK_BRACKET_OPEN; return OK; }; case ']': { r_token.type = TK_BRACKET_CLOSE; return OK; }; case '(': { r_token.type = TK_PARENTHESIS_OPEN; return OK; }; case ')': { r_token.type = TK_PARENTHESIS_CLOSE; return OK; }; case ',': { r_token.type = TK_COMMA; return OK; }; case ':': { r_token.type = TK_COLON; return OK; }; case '.': { r_token.type = TK_PERIOD; return OK; }; case '=': { cchar = GET_CHAR(); if (cchar == '=') { r_token.type = TK_OP_EQUAL; } else { _set_error("Expected '='"); r_token.type = TK_ERROR; return ERR_PARSE_ERROR; } return OK; }; case '!': { if (expression[str_ofs] == '=') { r_token.type = TK_OP_NOT_EQUAL; str_ofs++; } else { r_token.type = TK_OP_NOT; } return OK; }; case '>': { if (expression[str_ofs] == '=') { r_token.type = TK_OP_GREATER_EQUAL; str_ofs++; } else if (expression[str_ofs] == '>') { r_token.type = TK_OP_SHIFT_RIGHT; str_ofs++; } else { r_token.type = TK_OP_GREATER; } return OK; }; case '<': { if (expression[str_ofs] == '=') { r_token.type = TK_OP_LESS_EQUAL; str_ofs++; } else if (expression[str_ofs] == '<') { r_token.type = TK_OP_SHIFT_LEFT; str_ofs++; } else { r_token.type = TK_OP_LESS; } return OK; }; case '+': { r_token.type = TK_OP_ADD; return OK; }; case '-': { r_token.type = TK_OP_SUB; return OK; }; case '/': { r_token.type = TK_OP_DIV; return OK; }; case '*': { r_token.type = TK_OP_MUL; return OK; }; case '%': { r_token.type = TK_OP_MOD; return OK; }; case '&': { if (expression[str_ofs] == '&') { r_token.type = TK_OP_AND; str_ofs++; } else { r_token.type = TK_OP_BIT_AND; } return OK; }; case '|': { if (expression[str_ofs] == '|') { r_token.type = TK_OP_OR; str_ofs++; } else { r_token.type = TK_OP_BIT_OR; } return OK; }; case '^': { r_token.type = TK_OP_BIT_XOR; return OK; }; case '~': { r_token.type = TK_OP_BIT_INVERT; return OK; }; case '"': { String str; while (true) { CharType ch = GET_CHAR(); if (ch == 0) { _set_error("Unterminated String"); r_token.type = TK_ERROR; return ERR_PARSE_ERROR; } else if (ch == '"') { break; } else if (ch == '\\') { //escaped characters... CharType next = GET_CHAR(); if (next == 0) { _set_error("Unterminated String"); r_token.type = TK_ERROR; return ERR_PARSE_ERROR; } CharType res = 0; switch (next) { case 'b': res = 8; break; case 't': res = 9; break; case 'n': res = 10; break; case 'f': res = 12; break; case 'r': res = 13; break; case 'u': { //hexnumbarh - oct is deprecated for (int j = 0; j < 4; j++) { CharType c = GET_CHAR(); if (c == 0) { _set_error("Unterminated String"); r_token.type = TK_ERROR; return ERR_PARSE_ERROR; } if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) { _set_error("Malformed hex constant in string"); r_token.type = TK_ERROR; return ERR_PARSE_ERROR; } CharType v; if (c >= '0' && c <= '9') { v = c - '0'; } else if (c >= 'a' && c <= 'f') { v = c - 'a'; v += 10; } else if (c >= 'A' && c <= 'F') { v = c - 'A'; v += 10; } else { ERR_PRINT("BUG"); v = 0; } res <<= 4; res |= v; } } break; //case '\"': res='\"'; break; //case '\\': res='\\'; break; //case '/': res='/'; break; default: { res = next; //r_err_str="Invalid escape sequence"; //return ERR_PARSE_ERROR; } break; } str += res; } else { str += ch; } } r_token.type = TK_CONSTANT; r_token.value = str; return OK; } break; default: { if (cchar <= 32) { break; } if (cchar == '-' || (cchar >= '0' && cchar <= '9')) { //a number String num; #define READING_SIGN 0 #define READING_INT 1 #define READING_DEC 2 #define READING_EXP 3 #define READING_DONE 4 int reading = READING_INT; if (cchar == '-') { num += '-'; cchar = GET_CHAR(); } CharType c = cchar; bool exp_sign = false; bool exp_beg = false; bool is_float = false; while (true) { switch (reading) { case READING_INT: { if (c >= '0' && c <= '9') { //pass } else if (c == '.') { reading = READING_DEC; is_float = true; } else if (c == 'e') { reading = READING_EXP; } else { reading = READING_DONE; } } break; case READING_DEC: { if (c >= '0' && c <= '9') { } else if (c == 'e') { reading = READING_EXP; } else { reading = READING_DONE; } } break; case READING_EXP: { if (c >= '0' && c <= '9') { exp_beg = true; } else if ((c == '-' || c == '+') && !exp_sign && !exp_beg) { if (c == '-') is_float = true; exp_sign = true; } else { reading = READING_DONE; } } break; } if (reading == READING_DONE) break; num += String::chr(c); c = GET_CHAR(); } str_ofs--; r_token.type = TK_CONSTANT; if (is_float) r_token.value = num.to_double(); else r_token.value = num.to_int(); return OK; } else if ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_') { String id; bool first = true; while ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_' || (!first && cchar >= '0' && cchar <= '9')) { id += String::chr(cchar); cchar = GET_CHAR(); first = false; } str_ofs--; //go back one if (id == "in") { r_token.type = TK_OP_IN; } else if (id == "null") { r_token.type = TK_CONSTANT; r_token.value = Variant(); } else if (id == "true") { r_token.type = TK_CONSTANT; r_token.value = true; } else if (id == "false") { r_token.type = TK_CONSTANT; r_token.value = false; } else if (id == "PI") { r_token.type = TK_CONSTANT; r_token.value = Math_PI; } else if (id == "TAU") { r_token.type = TK_CONSTANT; r_token.value = Math_TAU; } else if (id == "INF") { r_token.type = TK_CONSTANT; r_token.value = Math_INF; } else if (id == "NAN") { r_token.type = TK_CONSTANT; r_token.value = Math_NAN; } else if (id == "not") { r_token.type = TK_OP_NOT; } else if (id == "or") { r_token.type = TK_OP_OR; } else if (id == "and") { r_token.type = TK_OP_AND; } else if (id == "self") { r_token.type = TK_SELF; } else { for (int i = 0; i < Variant::VARIANT_MAX; i++) { if (id == Variant::get_type_name(Variant::Type(i))) { r_token.type = TK_BASIC_TYPE; r_token.value = i; return OK; } } VisualScriptBuiltinFunc::BuiltinFunc bifunc = VisualScriptBuiltinFunc::find_function(id); if (bifunc != VisualScriptBuiltinFunc::FUNC_MAX) { r_token.type = TK_BUILTIN_FUNC; r_token.value = bifunc; return OK; } r_token.type = TK_IDENTIFIER; r_token.value = id; } return OK; } else { _set_error("Unexpected character."); r_token.type = TK_ERROR; return ERR_PARSE_ERROR; } } } } r_token.type = TK_ERROR; return ERR_PARSE_ERROR; }
Error VariantParser::get_token(Stream *p_stream, Token& r_token, int &line, String &r_err_str) { while (true) { CharType cchar; if (p_stream->saved) { cchar=p_stream->saved; p_stream->saved=0; } else { cchar=p_stream->get_char(); if (p_stream->is_eof()) { r_token.type=TK_EOF; return OK; } } switch(cchar) { case '\n': { line++; break; }; case 0: { r_token.type=TK_EOF; return OK; } break; case '{': { r_token.type=TK_CURLY_BRACKET_OPEN; return OK; }; case '}': { r_token.type=TK_CURLY_BRACKET_CLOSE; return OK; }; case '[': { r_token.type=TK_BRACKET_OPEN; return OK; }; case ']': { r_token.type=TK_BRACKET_CLOSE; return OK; }; case '(': { r_token.type=TK_PARENTHESIS_OPEN; return OK; }; case ')': { r_token.type=TK_PARENTHESIS_CLOSE; return OK; }; case ':': { r_token.type=TK_COLON; return OK; }; case ';': { while(true) { CharType ch=p_stream->get_char(); if (p_stream->is_eof()) { r_token.type=TK_EOF; return OK; } if (ch=='\n') break; } break; }; case ',': { r_token.type=TK_COMMA; return OK; }; case '.': { r_token.type=TK_PERIOD; return OK; }; case '=': { r_token.type=TK_EQUAL; return OK; }; case '#': { String color_str="#"; while(true) { CharType ch=p_stream->get_char(); if (p_stream->is_eof()) { r_token.type=TK_EOF; return OK; } else if ( (ch>='0' && ch<='9') || (ch>='a' && ch<='f') || (ch>='A' && ch<='F') ) { color_str+=String::chr(ch); } else { p_stream->saved=ch; break; } } r_token.value=Color::html(color_str); r_token.type=TK_COLOR; return OK; }; case '"': { String str; while(true) { CharType ch=p_stream->get_char(); if (ch==0) { r_err_str="Unterminated String"; r_token.type=TK_ERROR; return ERR_PARSE_ERROR; } else if (ch=='"') { break; } else if (ch=='\\') { //escaped characters... CharType next = p_stream->get_char(); if (next==0) { r_err_str="Unterminated String"; r_token.type=TK_ERROR; return ERR_PARSE_ERROR; } CharType res=0; switch(next) { case 'b': res=8; break; case 't': res=9; break; case 'n': res=10; break; case 'f': res=12; break; case 'r': res=13; break; case 'u': { //hexnumbarh - oct is deprecated for(int j=0;j<4;j++) { CharType c = p_stream->get_char(); if (c==0) { r_err_str="Unterminated String"; r_token.type=TK_ERROR; return ERR_PARSE_ERROR; } if (!((c>='0' && c<='9') || (c>='a' && c<='f') || (c>='A' && c<='F'))) { r_err_str="Malformed hex constant in string"; r_token.type=TK_ERROR; return ERR_PARSE_ERROR; } CharType v; if (c>='0' && c<='9') { v=c-'0'; } else if (c>='a' && c<='f') { v=c-'a'; v+=10; } else if (c>='A' && c<='F') { v=c-'A'; v+=10; } else { ERR_PRINT("BUG"); v=0; } res<<=4; res|=v; } } break; //case '\"': res='\"'; break; //case '\\': res='\\'; break; //case '/': res='/'; break; default: { res = next; //r_err_str="Invalid escape sequence"; //return ERR_PARSE_ERROR; } break; } str+=res; } else { if (ch=='\n') line++; str+=ch; } } if (p_stream->is_utf8()) { str.parse_utf8( str.ascii(true).get_data() ); } r_token.type=TK_STRING; r_token.value=str; return OK; } break; default: { if (cchar<=32) { break; } if (cchar=='-' || (cchar>='0' && cchar<='9')) { //a number String num; #define READING_SIGN 0 #define READING_INT 1 #define READING_DEC 2 #define READING_EXP 3 #define READING_DONE 4 int reading=READING_INT; if (cchar=='-') { num+='-'; cchar=p_stream->get_char(); } CharType c = cchar; bool exp_sign=false; bool exp_beg=false; bool is_float=false; while(true) { switch(reading) { case READING_INT: { if (c>='0' && c<='9') { //pass } else if (c=='.') { reading=READING_DEC; is_float=true; } else if (c=='e') { reading=READING_EXP; } else { reading=READING_DONE; } } break; case READING_DEC: { if (c>='0' && c<='9') { } else if (c=='e') { reading=READING_EXP; } else { reading=READING_DONE; } } break; case READING_EXP: { if (c>='0' && c<='9') { exp_beg=true; } else if ((c=='-' || c=='+') && !exp_sign && !exp_beg) { if (c=='-') is_float=true; exp_sign=true; } else { reading=READING_DONE; } } break; } if (reading==READING_DONE) break; num+=String::chr(c); c = p_stream->get_char(); } p_stream->saved=c; r_token.type=TK_NUMBER; if (is_float) r_token.value=num.to_double(); else r_token.value=num.to_int(); return OK; } else if ((cchar>='A' && cchar<='Z') || (cchar>='a' && cchar<='z') || cchar=='_') { String id; bool first=true; while((cchar>='A' && cchar<='Z') || (cchar>='a' && cchar<='z') || cchar=='_' || (!first && cchar>='0' && cchar<='9')) { id+=String::chr(cchar); cchar=p_stream->get_char(); first=false; } p_stream->saved=cchar; r_token.type=TK_IDENTIFIER; r_token.value=id; return OK; } else { r_err_str="Unexpected character."; r_token.type=TK_ERROR; return ERR_PARSE_ERROR; } } } } r_token.type=TK_ERROR; return ERR_PARSE_ERROR; }