static void panel_properties_dialog_update_background_image (PanelPropertiesDialog *dialog, GConfValue *value) { const char *text; char *old_text; if (!value || value->type != GCONF_VALUE_STRING) return; text = gconf_value_get_string (value); old_text = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog->image_chooser)); if (string_empty (text) && old_text) gtk_file_chooser_unselect_all (GTK_FILE_CHOOSER (dialog->image_chooser)); else if (!string_empty (text) && (!old_text || strcmp (text, old_text))) gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog->image_chooser), text); if (old_text) g_free (old_text); }
uint32_t server_pool_idx(struct server_pool *pool, uint8_t *key, uint32_t keylen) { uint32_t hash, idx; ASSERT(array_n(&pool->server) != 0); ASSERT(key != NULL); /* * If hash_tag: is configured for this server pool, we use the part of * the key within the hash tag as an input to the distributor. Otherwise * we use the full key */ if (!string_empty(&pool->hash_tag)) { struct string *tag = &pool->hash_tag; uint8_t *tag_start, *tag_end; tag_start = nc_strchr(key, key + keylen, tag->data[0]); if (tag_start != NULL) { tag_end = nc_strchr(tag_start + 1, key + keylen, tag->data[1]); if ((tag_end != NULL) && (tag_end - tag_start > 1)) { key = tag_start + 1; keylen = (uint32_t)(tag_end - key); } } } switch (pool->dist_type) { case DIST_KETAMA: hash = server_pool_hash(pool, key, keylen); idx = ketama_dispatch(pool->continuum, pool->ncontinuum, hash); break; case DIST_MODULA: hash = server_pool_hash(pool, key, keylen); idx = modula_dispatch(pool->continuum, pool->ncontinuum, hash); break; case DIST_RANDOM: idx = random_dispatch(pool->continuum, pool->ncontinuum, 0); break; default: NOT_REACHED(); return 0; } ASSERT(idx < array_n(&pool->server)); return idx; }
int request_read_query(int sock, query* q) { string ands, nots; string_init(&ands), string_init(¬s); while(1) { /* get query */ if(socket_readline(sock, &ands) == -1 || socket_readline(sock, ¬s) == -1) { string_delete(&ands), string_delete(¬s); return 0; } if(!ands.used && !nots.used) break; query_add(q, &ands, ¬s); string_empty(&ands), string_empty(¬s); } string_delete(&ands), string_delete(¬s); return 1; }
static void panel_properties_dialog_setup_image_chooser (PanelPropertiesDialog *dialog, GladeXML *gui) { GtkFileFilter *filter; GtkWidget *chooser_preview; char *image; dialog->image_chooser = glade_xml_get_widget (gui, "image_chooser"); filter = gtk_file_filter_new (); gtk_file_filter_set_name (filter, _("Images")); gtk_file_filter_add_pixbuf_formats (filter); gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog->image_chooser), filter); gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog->image_chooser), filter); chooser_preview = gtk_image_new (); gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER (dialog->image_chooser), chooser_preview); g_signal_connect (dialog->image_chooser, "update-preview", G_CALLBACK (panel_properties_dialog_chooser_preview_update), chooser_preview); image = panel_profile_get_background_image (dialog->toplevel); if (string_empty (image)) gtk_file_chooser_unselect_all (GTK_FILE_CHOOSER (dialog->image_chooser)); else gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog->image_chooser), image); if (image) g_free (image); dialog->selection_emitted = 0; g_signal_connect_swapped (dialog->image_chooser, "selection-changed", G_CALLBACK (panel_properties_dialog_image_changed), dialog); if ( ! panel_profile_is_writable_background_image (dialog->toplevel)) { gtk_widget_set_sensitive (dialog->image_chooser, FALSE); gtk_widget_show (dialog->writability_warn_background); } }
void Model_resolveInheritance( const char* name, Model& model ){ if ( model.m_resolved == false ) { model.m_resolved = true; if ( !string_empty( model.m_parent.c_str() ) ) { Models::iterator i = g_models.find( model.m_parent ); if ( i == g_models.end() ) { globalErrorStream() << "model " << name << " inherits unknown model " << model.m_parent.c_str() << "\n"; } else { Model_resolveInheritance( ( *i ).first.c_str(), ( *i ).second ); model.m_mesh = ( *i ).second.m_mesh; model.m_skin = ( *i ).second.m_skin; } } } }
EntityClass *Eclass_ForName(const char *name, bool has_brushes) { ASSERT_NOTNULL(name); if(string_empty(name)) { return eclass_bad; } EntityClasses::iterator i = g_entityClasses.find(name); if(i != g_entityClasses.end() && string_equal((*i).first, name)) { return (*i).second; } EntityClass* e = EntityClass_Create_Default(name, has_brushes); return Eclass_InsertAlphabetized(e); }
bool pre( const scene::Path& path, scene::Instance& instance ) const { const char *str; Entity* entity = Node_getEntity( path.top() ); if ( entity != 0 && string_equal( m_classname, entity->getKeyValue( "classname" ) ) ) { if ( m_count ) { ( *m_count )++; } // now get the highest teamnum if ( m_team ) { str = entity->getKeyValue( "team" ); if ( !string_empty( str ) ) { if ( atoi( str ) > *m_team ) { ( *m_team ) = atoi( str ); } } } } return true; }
static void background_task_bridge_uart(void) { if(uart_empty(0) || lwip_if_send_buffer_locked(&uart_socket)) return; string_clear(&uart_socket_send_buffer); while(!uart_empty(0) && string_space(&uart_socket_send_buffer)) string_append_byte(&uart_socket_send_buffer, uart_receive(0)); if(string_empty(&uart_socket_send_buffer)) return; if(!lwip_if_send(&uart_socket)) { stat_uart_send_buffer_overflow++; log("lwip uart send failed\n"); } }
void LoadBuildMenu() { if(string_empty(g_buildMenu.c_str()) || !build_commands_parse(g_buildMenu.c_str())) { { StringOutputStream buffer(256); buffer << GameToolsPath_get() << "default_build_menu.xml"; bool success = build_commands_parse(buffer.c_str()); ASSERT_MESSAGE(success, "failed to parse default build commands: " << buffer.c_str()); } { StringOutputStream buffer(256); buffer << SettingsPath_get() << g_pGameDescription->mGameFile.c_str() << "/build_menu.xml"; g_buildMenu = buffer.c_str(); } } }
EntityClass* EntityClassDoom3_findOrInsert( const char *name, bool has_brushes ){ ASSERT_NOTNULL( name ); if ( string_empty( name ) ) { return g_EntityClassDoom3_bad; } EntityClasses::iterator i = g_EntityClassDoom3_classes.find( name ); if ( i != g_EntityClassDoom3_classes.end() //&& string_equal((*i).first, name) ) { return ( *i ).second; } EntityClass* e = EntityClass_Create_Default( name, has_brushes ); EntityClass* inserted = EntityClassDoom3_insertUnique( e ); ASSERT_MESSAGE( inserted == e, "" ); return inserted; }
void visit( const char* name, Accelerator& accelerator ){ char value[1024]; if ( read_var( m_filename, "Commands", name, value ) ) { if ( string_empty( value ) ) { accelerator.key = 0; accelerator.modifiers = (GdkModifierType)0; return; } gtk_accelerator_parse( value, &accelerator.key, &accelerator.modifiers ); accelerator = accelerator; // fix modifiers if ( accelerator.key != 0 ) { ++m_count; } else { globalOutputStream() << "WARNING: failed to parse user command " << makeQuoted( name ) << ": unknown key " << makeQuoted( value ) << "\n"; } } }
gboolean commands_cell_edited(GtkCellRendererText* cell, gchar* path_string, gchar* new_text, GtkListStore* store) { if(g_current_build == 0) { return FALSE; } Build& build = *g_current_build; GtkTreePath* path = gtk_tree_path_new_from_string(path_string); ASSERT_MESSAGE(gtk_tree_path_get_depth(path) == 1, "invalid path length"); GtkTreeIter iter; gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path); Build::iterator i = Build_find(build, gtk_tree_path_get_indices(path)[0]); if(i != build.end()) { g_build_changed = true; (*i).setString(new_text); gtk_list_store_set(store, &iter, 0, new_text, -1); } else if(!string_empty(new_text)) { g_build_changed = true; build.push_back(Build::value_type(VariableString(new_text))); gtk_list_store_set(store, &iter, 0, new_text, -1); GtkTreeIter lastIter; gtk_list_store_append(store, &lastIter); } gtk_tree_path_free(path); return FALSE; }
void accelerator_write( const Accelerator& accelerator, TextOutputStream& ostream ){ #if 0 if ( accelerator.modifiers & GDK_SHIFT_MASK ) { ostream << "Shift + "; } if ( accelerator.modifiers & GDK_MOD1_MASK ) { ostream << "Alt + "; } if ( accelerator.modifiers & GDK_CONTROL_MASK ) { ostream << "Control + "; } const char* keyName = global_keys_find( accelerator.key ); if ( !string_empty( keyName ) ) { ostream << keyName; } else { ostream << static_cast<char>( accelerator.key ); } #endif ostream << gtk_accelerator_get_label( accelerator.key, accelerator.modifiers ); }
void Entity_normalizeColor(){ if ( GlobalSelectionSystem().countSelected() != 0 ) { const scene::Path& path = GlobalSelectionSystem().ultimateSelected().path(); Entity* entity = Node_getEntity( path.top() ); if ( entity != 0 ) { const char* strColor = entity->getKeyValue( "_color" ); if ( !string_empty( strColor ) ) { Vector3 rgb; if ( string_parse_vector3( strColor, rgb ) ) { g_entity_globals.color_entity = rgb; NormalizeColor( g_entity_globals.color_entity ); char buffer[128]; sprintf( buffer, "%g %g %g", g_entity_globals.color_entity[0], g_entity_globals.color_entity[1], g_entity_globals.color_entity[2] ); Scene_EntitySetKeyValue_Selected( "_color", buffer ); } } } } }
static rstatus_t conf_validate_pool(struct conf *cf, struct conf_pool *cp) { rstatus_t status; ASSERT(!cp->valid); ASSERT(!string_empty(&cp->name)); if (!cp->listen.valid) { log_error("conf: directive \"listen:\" is missing"); return NC_ERROR; } /* set default values for unset directives */ if (cp->hash == CONF_UNSET_HASH) { cp->hash = CONF_DEFAULT_HASH; } if (cp->distribution == CONF_UNSET_DIST) { cp->distribution = CONF_DEFAULT_DIST; } if (cp->timeout == CONF_UNSET_NUM) { cp->timeout = CONF_DEFAULT_TIMEOUT; } if (cp->backlog == CONF_UNSET_NUM) { cp->backlog = CONF_DEFAULT_LISTEN_BACKLOG; } cp->client_connections = CONF_DEFAULT_CLIENT_CONNECTIONS; if (cp->tcpkeepalive == CONF_UNSET_NUM) { cp->tcpkeepalive = CONF_DEFAULT_TCPKEEPALIVE; } if (cp->redis_db == CONF_UNSET_NUM) { cp->redis_db = CONF_DEFAULT_REDIS_DB; } if (cp->server_connections == CONF_UNSET_NUM) { cp->server_connections = CONF_DEFAULT_SERVER_CONNECTIONS; } else if (cp->server_connections == 0) { log_error("conf: directive \"server_connections:\" cannot be 0"); return NC_ERROR; } status = conf_validate_group(cf, cp); if (status != NC_OK) { return status; } if (cp->sentinel_heartbeat == CONF_UNSET_NUM) { cp->sentinel_heartbeat = CONF_DEFAULT_SENTINEL_HEARTBEAT; } status = conf_validate_sentinel(cf, cp); if (status != NC_OK) { return status; } cp->valid = 1; return NC_OK; }
static bool EntityClass_parse( EntityClass& entityClass, Tokeniser& tokeniser ){ PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, entityClass.m_name ) ); PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseToken( tokeniser, "{" ) ); tokeniser.nextLine(); StringOutputStream usage( 256 ); StringOutputStream description( 256 ); CopiedString* currentDescription = 0; StringOutputStream* currentString = 0; for (;; ) { const char* key; PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, key ) ); const char* last = string_findFirstSpaceOrTab( key ); CopiedString first( StringRange( key, last ) ); if ( !string_empty( last ) ) { last = string_findFirstNonSpaceOrTab( last ); } if ( currentString != 0 && string_equal( key, "\\" ) ) { tokeniser.nextLine(); *currentString << " "; PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, *currentString ) ); continue; } if ( currentDescription != 0 ) { *currentDescription = description.c_str(); description.clear(); currentDescription = 0; } currentString = 0; if ( string_equal( key, "}" ) ) { tokeniser.nextLine(); break; } else if ( string_equal( key, "model" ) ) { const char* token; PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, token ) ); entityClass.fixedsize = true; StringOutputStream buffer( 256 ); buffer << PathCleaned( token ); entityClass.m_modelpath = buffer.c_str(); } else if ( string_equal( key, "editor_color" ) ) { const char* value; PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, value ) ); if ( !string_empty( value ) ) { entityClass.colorSpecified = true; bool success = string_parse_vector3( value, entityClass.color ); ASSERT_MESSAGE( success, "editor_color: parse error" ); } } else if ( string_equal( key, "editor_ragdoll" ) ) { //bool ragdoll = atoi(tokeniser.getToken()) != 0; PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseToken( tokeniser ) ); } else if ( string_equal( key, "editor_mins" ) ) { entityClass.sizeSpecified = true; const char* value; PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, value ) ); if ( !string_empty( value ) && !string_equal( value, "?" ) ) { entityClass.fixedsize = true; bool success = string_parse_vector3( value, entityClass.mins ); ASSERT_MESSAGE( success, "editor_mins: parse error" ); } } else if ( string_equal( key, "editor_maxs" ) ) { entityClass.sizeSpecified = true; const char* value; PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, value ) ); if ( !string_empty( value ) && !string_equal( value, "?" ) ) { entityClass.fixedsize = true; bool success = string_parse_vector3( value, entityClass.maxs ); ASSERT_MESSAGE( success, "editor_maxs: parse error" ); } } else if ( string_equal( key, "editor_usage" ) ) { PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, usage ) ); currentString = &usage; } else if ( string_equal_n( key, "editor_usage", 12 ) ) { PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, usage ) ); currentString = &usage; } else if ( string_equal( key, "editor_rotatable" ) || string_equal( key, "editor_showangle" ) || string_equal( key, "editor_showangles" ) // typo? in prey movables.def || string_equal( key, "editor_mover" ) || string_equal( key, "editor_model" ) || string_equal( key, "editor_material" ) || string_equal( key, "editor_combatnode" ) || ( !string_empty( last ) && string_equal( first.c_str(), "editor_gui" ) ) || string_equal_n( key, "editor_copy", 11 ) ) { PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseToken( tokeniser ) ); } else if ( !string_empty( last ) && ( string_equal( first.c_str(), "editor_var" ) || string_equal( first.c_str(), "editor_string" ) ) ) { EntityClassAttribute& attribute = EntityClass_insertAttribute( entityClass, last ).second; attribute.m_type = "string"; currentDescription = &attribute.m_description; currentString = &description; PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, description ) ); } else if ( !string_empty( last ) && string_equal( first.c_str(), "editor_float" ) ) { EntityClassAttribute& attribute = EntityClass_insertAttribute( entityClass, last ).second; attribute.m_type = "string"; currentDescription = &attribute.m_description; currentString = &description; PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, description ) ); } else if ( !string_empty( last ) && string_equal( first.c_str(), "editor_snd" ) ) { EntityClassAttribute& attribute = EntityClass_insertAttribute( entityClass, last ).second; attribute.m_type = "sound"; currentDescription = &attribute.m_description; currentString = &description; PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, description ) ); } else if ( !string_empty( last ) && string_equal( first.c_str(), "editor_bool" ) ) { EntityClassAttribute& attribute = EntityClass_insertAttribute( entityClass, last ).second; attribute.m_type = "boolean"; currentDescription = &attribute.m_description; currentString = &description; PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, description ) ); } else if ( !string_empty( last ) && string_equal( first.c_str(), "editor_int" ) ) { EntityClassAttribute& attribute = EntityClass_insertAttribute( entityClass, last ).second; attribute.m_type = "integer"; currentDescription = &attribute.m_description; currentString = &description; PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, description ) ); } else if ( !string_empty( last ) && string_equal( first.c_str(), "editor_model" ) ) { EntityClassAttribute& attribute = EntityClass_insertAttribute( entityClass, last ).second; attribute.m_type = "model"; currentDescription = &attribute.m_description; currentString = &description; PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, description ) ); } else if ( !string_empty( last ) && string_equal( first.c_str(), "editor_color" ) ) { EntityClassAttribute& attribute = EntityClass_insertAttribute( entityClass, last ).second; attribute.m_type = "color"; currentDescription = &attribute.m_description; currentString = &description; PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, description ) ); } else if ( !string_empty( last ) && ( string_equal( first.c_str(), "editor_material" ) || string_equal( first.c_str(), "editor_mat" ) ) ) { EntityClassAttribute& attribute = EntityClass_insertAttribute( entityClass, last ).second; attribute.m_type = "shader"; currentDescription = &attribute.m_description; currentString = &description; PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, description ) ); } else if ( string_equal( key, "inherit" ) ) { entityClass.inheritanceResolved = false; ASSERT_MESSAGE( entityClass.m_parent.empty(), "only one 'inherit' supported per entityDef" ); const char* token; PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, token ) ); entityClass.m_parent.push_back( token ); } // begin quake4-specific keys else if ( string_equal( key, "editor_targetonsel" ) ) { //const char* value = PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseToken( tokeniser ) ); } else if ( string_equal( key, "editor_menu" ) ) { //const char* value = PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseToken( tokeniser ) ); } else if ( string_equal( key, "editor_ignore" ) ) { //const char* value = PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseToken( tokeniser ) ); } // end quake4-specific keys // begin ignore prey (unknown/unused?) entity keys else if ( string_equal( key, "editor_light" ) || string_equal( key, "editor_def def_debrisspawner" ) || string_equal( key, "editor_def def_drop" ) || string_equal( key, "editor_def def_guihand" ) || string_equal( key, "editor_def def_mine" ) ) { //const char* value = PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseToken( tokeniser ) ); } // end ignore prey entity keys else { CopiedString tmp( key ); if ( string_equal_n( key, "editor_", 7 ) ) { globalErrorStream() << "unsupported editor key " << makeQuoted( key ) ; } EntityClassAttribute& attribute = EntityClass_insertAttribute( entityClass, key ).second; attribute.m_type = "string"; const char* value; PARSE_RETURN_FALSE_IF_FAIL( EntityClassDoom3_parseString( tokeniser, value ) ); if ( string_equal( value, "}" ) ) { // hack for quake4 powerups.def bug globalErrorStream() << "entityDef " << makeQuoted( entityClass.m_name.c_str() ) << " key " << makeQuoted( tmp.c_str() ) << " has no value\n"; break; } else { attribute.m_value = value; } } tokeniser.nextLine(); } entityClass.m_comments = usage.c_str(); if ( string_equal( entityClass.m_name.c_str(), "light" ) ) { { EntityClassAttribute& attribute = EntityClass_insertAttribute( entityClass, "light_radius" ).second; attribute.m_type = "vector3"; attribute.m_value = "300 300 300"; } { EntityClassAttribute& attribute = EntityClass_insertAttribute( entityClass, "light_center" ).second; attribute.m_type = "vector3"; } { EntityClassAttribute& attribute = EntityClass_insertAttribute( entityClass, "noshadows" ).second; attribute.m_type = "boolean"; attribute.m_value = "0"; } { EntityClassAttribute& attribute = EntityClass_insertAttribute( entityClass, "nospecular" ).second; attribute.m_type = "boolean"; attribute.m_value = "0"; } { EntityClassAttribute& attribute = EntityClass_insertAttribute( entityClass, "nodiffuse" ).second; attribute.m_type = "boolean"; attribute.m_value = "0"; } { EntityClassAttribute& attribute = EntityClass_insertAttribute( entityClass, "falloff" ).second; attribute.m_type = "real"; } } return true; }
static rstatus_t conf_validate_pool(struct conf *cf, struct conf_pool *cp) { rstatus_t status; ASSERT(!cp->valid); ASSERT(!string_empty(&cp->name)); if (!cp->listen.valid) { log_error("conf: directive \"listen:\" is missing"); return NC_ERROR; } /* set default values for unset directives */ if (cp->distribution == CONF_UNSET_DIST) { cp->distribution = CONF_DEFAULT_DIST; } if (cp->hash == CONF_UNSET_HASH) { cp->hash = CONF_DEFAULT_HASH; } if (cp->timeout == CONF_UNSET_NUM) { cp->timeout = CONF_DEFAULT_TIMEOUT; } if (cp->backlog == CONF_UNSET_NUM) { cp->backlog = CONF_DEFAULT_LISTEN_BACKLOG; } cp->client_connections = CONF_DEFAULT_CLIENT_CONNECTIONS; if (cp->redis != CONF_UNSET_NUM) { log_warn("conf: directive \"redis:\" is deprecated, " "use \"protocol:\" instead"); if (cp->proto != CONF_UNSET_PROTO && (cp->redis || cp->proto != PROTO_MEMCACHED) && (!cp->redis || cp->proto != PROTO_REDIS)) { log_error("conf: directive \"redis: %s\" is incompatible with " "directive \"protocol: %s\"", cp->redis ? "true" : "false", proto_type_string(cp->proto)); return NC_ERROR; } cp->proto = cp->redis ? PROTO_REDIS : PROTO_MEMCACHED; } if (cp->proto == CONF_UNSET_PROTO) { cp->proto = CONF_DEFAULT_PROTO; } if (cp->tcpkeepalive == CONF_UNSET_NUM) { cp->tcpkeepalive = CONF_DEFAULT_TCPKEEPALIVE; } if (cp->redis_db == CONF_UNSET_NUM) { cp->redis_db = CONF_DEFAULT_REDIS_DB; } if (cp->preconnect == CONF_UNSET_NUM) { cp->preconnect = CONF_DEFAULT_PRECONNECT; } if (cp->auto_eject_hosts == CONF_UNSET_NUM) { cp->auto_eject_hosts = CONF_DEFAULT_AUTO_EJECT_HOSTS; } if (cp->server_connections == CONF_UNSET_NUM) { cp->server_connections = CONF_DEFAULT_SERVER_CONNECTIONS; } else if (cp->server_connections == 0) { log_error("conf: directive \"server_connections:\" cannot be 0"); return NC_ERROR; } if (cp->server_retry_timeout == CONF_UNSET_NUM) { cp->server_retry_timeout = CONF_DEFAULT_SERVER_RETRY_TIMEOUT; } if (cp->server_failure_limit == CONF_UNSET_NUM) { cp->server_failure_limit = CONF_DEFAULT_SERVER_FAILURE_LIMIT; } if (!cp->redis && cp->redis_auth.len > 0) { log_error("conf: directive \"redis_auth:\" is only valid for a redis pool"); return NC_ERROR; } status = conf_validate_server(cf, cp); if (status != NC_OK) { return status; } cp->valid = 1; return NC_OK; }
void visit(const char* name, Accelerator& accelerator) { char value[1024]; if (read_var(m_filename, "Commands", name, value )) { if(string_empty(value)) { accelerator.key = 0; accelerator.modifiers = (GdkModifierType)0; return; } int modifiers = 0; const char* last = value + string_length(value); const char* keyEnd = stringrange_find(value, last, '+'); for(const char* modifier = keyEnd; modifier != last;) { const char* next = stringrange_find(modifier + 1, last, '+'); if(next - modifier == 4 && string_equal_nocase_n(modifier, "+alt", 4)) { modifiers |= GDK_MOD1_MASK; } else if(next - modifier == 5 && string_equal_nocase_n(modifier, "+ctrl", 5) != 0) { modifiers |= GDK_CONTROL_MASK; } else if(next - modifier == 6 && string_equal_nocase_n(modifier, "+shift", 6) != 0) { modifiers |= GDK_SHIFT_MASK; } else { globalOutputStream() << "WARNING: failed to parse user command " << makeQuoted(value) << ": unknown modifier " << makeQuoted(StringRange(modifier, next)) << "\n"; } modifier = next; } accelerator.modifiers = (GdkModifierType)modifiers; // strBuff has been cleaned of it's modifiers .. switch between a regular key and a virtual one // based on length if(keyEnd - value == 1) // most often case.. deal with first { accelerator.key = std::toupper(value[0]); ++m_count; } else // special key { CopiedString keyName(StringRange(value, keyEnd)); accelerator.key = global_keys_find(keyName.c_str()); if(accelerator.key != 0) { ++m_count; } else { globalOutputStream() << "WARNING: failed to parse user command " << makeQuoted(value) << ": unknown key " << makeQuoted(keyName.c_str()) << "\n"; } } } }
static void dnode_req_forward(struct context *ctx, struct conn *conn, struct msg *msg) { struct server_pool *pool; uint8_t *key; uint32_t keylen; if (log_loggable(LOG_DEBUG)) { log_debug(LOG_DEBUG, "dnode_req_forward entering "); } log_debug(LOG_DEBUG, "DNODE REQ RECEIVED %s %d dmsg->id %u", conn_get_type_string(conn), conn->sd, msg->dmsg->id); ASSERT(conn->type == CONN_DNODE_PEER_CLIENT); pool = conn->owner; key = NULL; keylen = 0; log_debug(LOG_DEBUG, "conn %p adding message %d:%d", conn, msg->id, msg->parent_id); dictAdd(conn->outstanding_msgs_dict, &msg->id, msg); if (!string_empty(&pool->hash_tag)) { struct string *tag = &pool->hash_tag; uint8_t *tag_start, *tag_end; tag_start = dn_strchr(msg->key_start, msg->key_end, tag->data[0]); if (tag_start != NULL) { tag_end = dn_strchr(tag_start + 1, msg->key_end, tag->data[1]); if (tag_end != NULL) { key = tag_start + 1; keylen = (uint32_t)(tag_end - key); } } } if (keylen == 0) { key = msg->key_start; keylen = (uint32_t)(msg->key_end - msg->key_start); } ASSERT(msg->dmsg != NULL); if (msg->dmsg->type == DMSG_REQ) { local_req_forward(ctx, conn, msg, key, keylen); } else if (msg->dmsg->type == DMSG_REQ_FORWARD) { struct mbuf *orig_mbuf = STAILQ_FIRST(&msg->mhdr); struct datacenter *dc = server_get_dc(pool, &pool->dc); uint32_t rack_cnt = array_n(&dc->racks); uint32_t rack_index; for(rack_index = 0; rack_index < rack_cnt; rack_index++) { struct rack *rack = array_get(&dc->racks, rack_index); //log_debug(LOG_DEBUG, "forwarding to rack '%.*s'", // rack->name->len, rack->name->data); struct msg *rack_msg; if (string_compare(rack->name, &pool->rack) == 0 ) { rack_msg = msg; } else { rack_msg = msg_get(conn, msg->request, __FUNCTION__); if (rack_msg == NULL) { log_debug(LOG_VERB, "whelp, looks like yer screwed now, buddy. no inter-rack messages for you!"); continue; } if (msg_clone(msg, orig_mbuf, rack_msg) != DN_OK) { msg_put(rack_msg); continue; } rack_msg->swallow = true; } if (log_loggable(LOG_DEBUG)) { log_debug(LOG_DEBUG, "forwarding request from conn '%s' to rack '%.*s' dc '%.*s' ", dn_unresolve_peer_desc(conn->sd), rack->name->len, rack->name->data, rack->dc->len, rack->dc->data); } remote_req_forward(ctx, conn, rack_msg, rack, key, keylen); } } }
bool isModified() const { return ((!string_empty(m_path.c_str()) // had or has an absolute path && m_modified != modified()) // AND disk timestamp changed || !path_equal(rootPath(m_originalName.c_str()), m_path.c_str())); // OR absolute vfs-root changed }
static rstatus_t conf_validate_pool(struct conf *cf, struct conf_pool *cp) { rstatus_t status; ASSERT(!cp->valid); ASSERT(!string_empty(&cp->name)); if (!cp->listen.valid) { log_error("conf: directive \"listen:\" is missing"); return NC_ERROR; } /* set default values for unset directives */ if (cp->distribution == CONF_UNSET_DIST) { cp->distribution = CONF_DEFAULT_DIST; } if (cp->hash == CONF_UNSET_HASH) { cp->hash = CONF_DEFAULT_HASH; } if (cp->timeout == CONF_UNSET_NUM) { cp->timeout = CONF_DEFAULT_TIMEOUT; } if (cp->backlog == CONF_UNSET_NUM) { cp->backlog = CONF_DEFAULT_LISTEN_BACKLOG; } if (cp->item_size_max == CONF_UNSET_NUM) { cp->item_size_max = CONF_DEFAULT_ITEM_SIZE_MAX; } cp->client_connections = CONF_DEFAULT_CLIENT_CONNECTIONS; if (cp->preconnect == CONF_UNSET_NUM) { cp->preconnect = CONF_DEFAULT_PRECONNECT; } if (cp->auto_eject_hosts == CONF_UNSET_NUM) { cp->auto_eject_hosts = CONF_DEFAULT_AUTO_EJECT_HOSTS; } if (cp->server_connections == CONF_UNSET_NUM) { cp->server_connections = CONF_DEFAULT_SERVER_CONNECTIONS; } else if (cp->server_connections == 0) { log_error("conf: directive \"server_connections:\" cannot be 0"); return NC_ERROR; } if (cp->server_retry_timeout == CONF_UNSET_NUM) { cp->server_retry_timeout = CONF_DEFAULT_SERVER_RETRY_TIMEOUT; } if (cp->server_failure_limit == CONF_UNSET_NUM) { cp->server_failure_limit = CONF_DEFAULT_SERVER_FAILURE_LIMIT; } status = conf_validate_server(cf, cp); if (status != NC_OK) { return status; } cp->valid = 1; return NC_OK; }
DECLARE_TEST(exception, error) { error_handler_fn handler; int ret; error(); EXPECT_EQ(error(), ERROR_NONE); error_report(ERRORLEVEL_ERROR, ERROR_NONE); EXPECT_EQ(error(), ERROR_NONE); error_report(ERRORLEVEL_ERROR, ERROR_EXCEPTION); EXPECT_EQ(error(), ERROR_EXCEPTION); handler = error_handler(); error_set_handler(_error_handler_test); ret = error_report(ERRORLEVEL_WARNING, ERROR_INVALID_VALUE); EXPECT_EQ(error(), ERROR_INVALID_VALUE); EXPECT_EQ(ret, 2); EXPECT_EQ(_error_level_test, ERRORLEVEL_WARNING); EXPECT_EQ(_error_test, ERROR_INVALID_VALUE); EXPECT_EQ(error_handler(), _error_handler_test); error_set_handler(handler); { #if BUILD_ENABLE_ERROR_CONTEXT const char context_data[] = "another message"; #endif char context_buffer[512]; string_t contextstr; error_context_clear(); error_context_push(STRING_CONST("test context"), STRING_CONST("some message")); error_context_push(STRING_CONST("foo bar"), 0, 0); error_context_pop(); error_context_pop(); error_context_pop(); error_context_push(STRING_CONST("test context"), STRING_CONST(context_data)); #if BUILD_ENABLE_ERROR_CONTEXT EXPECT_NE(error_context(), 0); EXPECT_EQ(error_context()->depth, 1); EXPECT_CONSTSTRINGEQ(error_context()->frame[0].name, string_const(STRING_CONST("test context"))); EXPECT_EQ(error_context()->frame[0].data.str, context_data); EXPECT_EQ(error_context()->frame[0].data.length, sizeof(context_data) - 1); #endif contextstr = error_context_buffer(context_buffer, 512); #if BUILD_ENABLE_ERROR_CONTEXT EXPECT_NE_MSGFORMAT(string_find_string(STRING_ARGS(contextstr), STRING_CONST("test context"), 0), STRING_NPOS, "context name 'test context' not found in buffer: %s", context_buffer); EXPECT_NE_MSGFORMAT(string_find_string(STRING_ARGS(contextstr), STRING_CONST(context_data), 0), STRING_NPOS, "context data '%s' not found in buffer: %s", context_data, context_buffer); #else EXPECT_EQ(contextstr.length, 0); #endif error_context_clear(); contextstr = error_context_buffer(context_buffer, 512); #if BUILD_ENABLE_ERROR_CONTEXT EXPECT_STRINGEQ(contextstr, string_empty()); #endif } return 0; }
static void panel_menu_items_append_from_desktop (GtkWidget *menu, char *path, char *force_name) { GKeyFile *key_file; gboolean loaded; GtkWidget *item; char *path_freeme; char *full_path; char *uri; char *icon; char *name; char *comment; path_freeme = NULL; key_file = g_key_file_new (); if (g_path_is_absolute (path)) { loaded = g_key_file_load_from_file (key_file, path, G_KEY_FILE_NONE, NULL); full_path = path; } else { char *lookup_file; char *desktop_path; if (!g_str_has_suffix (path, ".desktop")) { desktop_path = g_strconcat (path, ".desktop", NULL); } else { desktop_path = path; } lookup_file = g_strconcat ("applications", G_DIR_SEPARATOR_S, desktop_path, NULL); loaded = g_key_file_load_from_data_dirs (key_file, lookup_file, &path_freeme, G_KEY_FILE_NONE, NULL); full_path = path_freeme; g_free (lookup_file); if (desktop_path != path) g_free (desktop_path); } if (!loaded) { g_key_file_free (key_file); if (path_freeme) g_free (path_freeme); return; } icon = panel_util_key_file_get_locale_string (key_file, "Icon"); comment = panel_util_key_file_get_locale_string (key_file, "Comment"); if (string_empty (force_name)) name = panel_util_key_file_get_locale_string (key_file, "Name"); else name = g_strdup (force_name); item = gtk_image_menu_item_new (); setup_menu_item_with_icon (item, panel_menu_icon_get_size (), icon, NULL, NULL, name); panel_util_set_tooltip_text (item, comment); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); g_signal_connect_data (item, "activate", G_CALLBACK (panel_menu_item_activate_desktop_file), g_strdup (full_path), (GClosureNotify) g_free, 0); g_signal_connect (G_OBJECT (item), "button_press_event", G_CALLBACK (menu_dummy_button_press_event), NULL); uri = g_filename_to_uri (full_path, NULL, NULL); setup_uri_drag (item, uri, icon); g_free (uri); g_key_file_free (key_file); if (icon) g_free (icon); if (name) g_free (name); if (comment) g_free (comment); if (path_freeme) g_free (path_freeme); }
bool join_sub_string ( const basic_cstring_view<CharT, Traits>& in, typename basic_cstring_view<CharT, Traits>::size_type& pos, std::basic_string<CharT, Traits, Allocator>& out, InputIterator valuesBegin, InputIterator valuesEnd, bool optional ) { using string_type = std::basic_string<CharT, Traits, Allocator>; using size_type = typename string_type::size_type; bool escapeChar = false; bool replacedAllValues = true; const auto numValues = static_cast<size_type>(std::distance(valuesBegin, valuesEnd)); if (numValues < 0) throw std::invalid_argument("reversed range iterators in join_string"); for (auto num = in.size(); pos < num;) { /* Get next character */ auto c = in[pos++]; if (escapeChar) { /* Add character without transformation to output string */ out.push_back(c); escapeChar = false; } else { if (c == CharT('\\')) { /* Next character will be added without transformation */ escapeChar = true; } else if (c == CharT('{')) { /* Parse index N in '{N}' */ string_type idxStr; while (pos < num) { /* Get next character */ c = in[pos++]; if (c == CharT('}')) break; else idxStr.push_back(c); } /* Get value by index from array */ const auto idx = static_cast<size_type>(std::stoul(idxStr)); if (idx < numValues) { /* Append value to output string */ const auto& val = *(valuesBegin + idx); if (string_empty(val)) replacedAllValues = false; else string_append(out, val); } else if (optional) { /* This sub string will not be added to the final output string */ replacedAllValues = false; } else { /* If this value replacement was not optional -> error */ throw std::out_of_range( "index (" + std::to_string(idx) + ") out of range [0, " + std::to_string(numValues) + ") in join_string" ); } } else if (c == CharT('[')) { /* Parse optional part with recursive call */ string_type outOpt; if (join_sub_string(in, pos, outOpt, valuesBegin, valuesEnd, true)) out.append(outOpt); } else if (c == CharT(']')) { /* Close optional part and return from recursive call */ break; } else { /* Add current character to output string */ out.push_back(c); } } } if (escapeChar) throw std::invalid_argument("incomplete escape character in report string"); return replacedAllValues; }
const char* file_dialog_show(GtkWidget* parent, bool open, const char* title, const char* path, const char* pattern) { filetype_t type; if(pattern == 0) { pattern = "*"; } FileTypeList typelist; GlobalFiletypes().getTypeList(pattern, &typelist); GTKMasks masks(typelist); if (title == 0) title = open ? "Open File" : "Save File"; GtkWidget* dialog; if (open) { dialog = gtk_file_chooser_dialog_new(title, GTK_WINDOW(parent), GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); } else { dialog = gtk_file_chooser_dialog_new(title, GTK_WINDOW(parent), GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL); gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), "unnamed"); } gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER_ON_PARENT); // we expect an actual path below, if the path is 0 we might crash if (path != 0 && !string_empty(path)) { ASSERT_MESSAGE(path_is_absolute(path), "file_dialog_show: path not absolute: " << makeQuoted(path)); Array<char> new_path(strlen(path)+1); // copy path, replacing dir separators as appropriate Array<char>::iterator w = new_path.begin(); for(const char* r = path; *r != '\0'; ++r) { *w++ = (*r == '/') ? G_DIR_SEPARATOR : *r; } // remove separator from end of path if required if(*(w-1) == G_DIR_SEPARATOR) { --w; } // terminate string *w = '\0'; gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), new_path.data()); } // we should add all important paths as shortcut folder... // gtk_file_chooser_add_shortcut_folder(GTK_FILE_CHOOSER(dialog), "/tmp/", NULL); for(std::size_t i = 0; i < masks.m_filters.size(); ++i) { GtkFileFilter* filter = gtk_file_filter_new(); gtk_file_filter_add_pattern(filter, masks.m_filters[i].c_str()); gtk_file_filter_set_name(filter, masks.m_masks[i].c_str()); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter); } if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { strcpy(g_file_dialog_file, gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog))); if(!string_equal(pattern, "*")) { GtkFileFilter* filter = gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog)); if(filter != 0) // no filter set? some file-chooser implementations may allow the user to set no filter, which we treat as 'all files' { type = masks.GetTypeForGTKMask(gtk_file_filter_get_name(filter)).m_type; // last ext separator const char* extension = path_get_extension(g_file_dialog_file); // no extension if(string_empty(extension)) { strcat(g_file_dialog_file, type.pattern+1); } else { strcpy(g_file_dialog_file + (extension - g_file_dialog_file), type.pattern+2); } } } // convert back to unix format for(char* w = g_file_dialog_file; *w!='\0'; w++) { if(*w=='\\') { *w = '/'; } } } else { g_file_dialog_file[0] = '\0'; } gtk_widget_destroy(dialog); // don't return an empty filename if(g_file_dialog_file[0] == '\0') return NULL; return g_file_dialog_file; }
void connectEntities(const scene::Path& path, const scene::Path& targetPath, int index) { Entity* e1 = ScenePath_getEntity(path); Entity* e2 = ScenePath_getEntity(targetPath); if(e1 == 0 || e2 == 0) { globalErrorStream() << "entityConnectSelected: both of the selected instances must be an entity\n"; return; } if(e1 == e2) { globalErrorStream() << "entityConnectSelected: the selected instances must not both be from the same entity\n"; return; } UndoableCommand undo("entityConnectSelected"); if(g_gameType == eGameTypeDoom3) { StringOutputStream key(16); if(index >= 0) { key << "target"; if(index != 0) { key << index; } e1->setKeyValue(key.c_str(), e2->getKeyValue("name")); key.clear(); } else { for(unsigned int i = 0; ; ++i) { key << "target"; if(i != 0) { key << i; } const char* value = e1->getKeyValue(key.c_str()); if(string_empty(value)) { e1->setKeyValue(key.c_str(), e2->getKeyValue("name")); break; } key.clear(); } } } else { ConnectEntities connector(e1, e2, index); const char* value = e2->getKeyValue("targetname"); if(!string_empty(value)) { connector.connect(value); } else { const char* type = e2->getKeyValue("classname"); if(string_empty(type)) { type = "t"; } StringOutputStream key(64); key << type << "1"; GlobalNamespace().makeUnique(key.c_str(), ConnectEntities::ConnectCaller(connector)); } } SceneChangeNotify(); }
int main_run(void* main_arg) { #if !BUILD_MONOLITHIC string_const_t pattern; string_t* exe_paths = 0; size_t iexe, exesize; process_t* process = 0; string_t process_path = { 0, 0 }; unsigned int* exe_flags = 0; #else void* test_result; #endif #if FOUNDATION_PLATFORM_IOS || FOUNDATION_PLATFORM_ANDROID || FOUNDATION_PLATFORM_PNACL int remain_counter = 0; #endif #if BUILD_DEBUG const string_const_t build_name = string_const(STRING_CONST("debug")); #elif BUILD_RELEASE const string_const_t build_name = string_const(STRING_CONST("release")); #elif BUILD_PROFILE const string_const_t build_name = string_const(STRING_CONST("profile")); #elif BUILD_DEPLOY const string_const_t build_name = string_const(STRING_CONST("deploy")); #endif #if BUILD_MONOLITHIC const string_const_t build_type = string_const(STRING_CONST(" monolithic")); #else const string_const_t build_type = string_empty(); #endif char* pathbuf; int process_result = 0; thread_t event_thread; FOUNDATION_UNUSED(main_arg); FOUNDATION_UNUSED(build_name); log_set_suppress(HASH_TEST, ERRORLEVEL_DEBUG); log_infof(HASH_TEST, STRING_CONST("Task library v%s built for %s using %s (%.*s%.*s)"), string_from_version_static(task_module_version()).str, FOUNDATION_PLATFORM_DESCRIPTION, FOUNDATION_COMPILER_DESCRIPTION, STRING_FORMAT(build_name), STRING_FORMAT(build_type)); thread_initialize(&event_thread, event_loop, 0, STRING_CONST("event_thread"), THREAD_PRIORITY_NORMAL, 0); thread_start(&event_thread); pathbuf = memory_allocate(HASH_STRING, BUILD_MAX_PATHLEN, 0, MEMORY_PERSISTENT); while (!thread_is_running(&event_thread)) thread_sleep(10); #if FOUNDATION_PLATFORM_IOS || FOUNDATION_PLATFORM_ANDROID || FOUNDATION_PLATFORM_PNACL while (!_test_should_start) { #if FOUNDATION_PLATFORM_ANDROID system_process_events(); #endif thread_sleep(100); } #endif fs_remove_directory(STRING_ARGS(environment_temporary_directory())); #if BUILD_MONOLITHIC test_run_fn tests[] = { test_task_run, 0 }; #if FOUNDATION_PLATFORM_ANDROID thread_t test_thread; thread_initialize(&test_thread, test_runner, tests, STRING_CONST("test_runner"), THREAD_PRIORITY_NORMAL, 0); thread_start(&test_thread); log_debug(HASH_TEST, STRING_CONST("Starting test runner thread")); while (!thread_is_running(&test_thread)) { system_process_events(); thread_sleep(10); } while (thread_is_running(&test_thread)) { system_process_events(); thread_sleep(10); } test_result = thread_join(&test_thread); process_result = (int)(intptr_t)test_result; thread_finalize(&test_thread); #else test_result = test_runner(tests); process_result = (int)(intptr_t)test_result; #endif if (process_result != 0) log_warnf(HASH_TEST, WARNING_SUSPICIOUS, STRING_CONST("Tests failed with exit code %d"), process_result); #if FOUNDATION_PLATFORM_IOS || FOUNDATION_PLATFORM_ANDROID || FOUNDATION_PLATFORM_PNACL while (!_test_should_terminate && _test_have_focus && (remain_counter < 50)) { system_process_events(); thread_sleep(100); ++remain_counter; } #endif log_debug(HASH_TEST, STRING_CONST("Exiting main loop")); #else // !BUILD_MONOLITHIC //Find all test executables in the current executable directory #if FOUNDATION_PLATFORM_WINDOWS pattern = string_const(STRING_CONST("^test-.*\\.exe$")); #elif FOUNDATION_PLATFORM_MACOSX pattern = string_const(STRING_CONST("^test-.*$")); #elif FOUNDATION_PLATFORM_POSIX pattern = string_const(STRING_CONST("^test-.*$")); #else # error Not implemented #endif exe_paths = fs_matching_files(STRING_ARGS(environment_executable_directory()), STRING_ARGS(pattern), false); array_resize(exe_flags, array_size(exe_paths)); memset(exe_flags, 0, sizeof(unsigned int) * array_size(exe_flags)); #if FOUNDATION_PLATFORM_MACOSX //Also search for test applications string_const_t app_pattern = string_const(STRING_CONST("^test-.*\\.app$")); regex_t* app_regex = regex_compile(app_pattern.str, app_pattern.length); string_t* subdirs = fs_subdirs(STRING_ARGS(environment_executable_directory())); for (size_t idir = 0, dirsize = array_size(subdirs); idir < dirsize; ++idir) { if (regex_match(app_regex, subdirs[idir].str, subdirs[idir].length, 0, 0)) { string_t exe_path = { subdirs[idir].str, subdirs[idir].length - 4 }; array_push(exe_paths, exe_path); array_push(exe_flags, PROCESS_MACOSX_USE_OPENAPPLICATION); } } string_array_deallocate(subdirs); regex_deallocate(app_regex); #endif for (iexe = 0, exesize = array_size(exe_paths); iexe < exesize; ++iexe) { string_const_t* process_args = 0; string_const_t exe_file_name = path_base_file_name(STRING_ARGS(exe_paths[iexe])); if (string_equal(STRING_ARGS(exe_file_name), STRING_ARGS(environment_executable_name()))) continue; //Don't run self process_path = path_concat(pathbuf, BUILD_MAX_PATHLEN, STRING_ARGS(environment_executable_directory()), STRING_ARGS(exe_paths[iexe])); process = process_allocate(); process_set_executable_path(process, STRING_ARGS(process_path)); process_set_working_directory(process, STRING_ARGS(environment_executable_directory())); process_set_flags(process, PROCESS_ATTACHED | exe_flags[iexe]); if (!_test_memory_tracker) array_push(process_args, string_const(STRING_CONST("--no-memory-tracker"))); process_set_arguments(process, process_args, array_size(process_args)); log_infof(HASH_TEST, STRING_CONST("Running test executable: %.*s"), STRING_FORMAT(exe_paths[iexe])); process_result = process_spawn(process); while (process_result == PROCESS_WAIT_INTERRUPTED) { thread_sleep(10); process_result = process_wait(process); } process_deallocate(process); array_deallocate(process_args); if (process_result != 0) { if (process_result >= PROCESS_INVALID_ARGS) log_warnf(HASH_TEST, WARNING_SUSPICIOUS, STRING_CONST("Tests failed, process terminated with error %x"), process_result); else log_warnf(HASH_TEST, WARNING_SUSPICIOUS, STRING_CONST("Tests failed with exit code %d"), process_result); process_set_exit_code(-1); goto exit; } log_infof(HASH_TEST, STRING_CONST("All tests from %.*s passed (%d)"), STRING_FORMAT(exe_paths[iexe]), process_result); } log_info(HASH_TEST, STRING_CONST("All tests passed")); exit: if (exe_paths) string_array_deallocate(exe_paths); array_deallocate(exe_flags); #endif _test_should_terminate = true; thread_signal(&event_thread); thread_finalize(&event_thread); memory_deallocate(pathbuf); log_infof(HASH_TEST, STRING_CONST("Tests exiting: %s (%d)"), process_result ? "FAILED" : "PASSED", process_result); if (process_result) memory_set_tracker(memory_tracker_none()); return process_result; }
void update_unique_name(Term* term) { Term::UniqueName& name = term->uniqueName; if (term->owningBlock == NULL) { copy(&term->nameValue, &name.name); return; } copy(&term->nameValue, &name.base); if (string_empty(&name.base)) { if (term->function == NULL) set_string(&name.base, "_anon"); else { set_string(&name.base, "_"); string_append(&name.base, &term->function->nameValue); } } copy(&name.base, &name.name); name.ordinal = 0; // Look for a name collision. We might need to keep looping, if our generated name // collides with an existing name. Block* block = term->owningBlock; bool updatedName = true; while (updatedName) { updatedName = false; for (int i = term->index-1; i >= 0; i--) { Term* other = block->get(i); if (other == NULL) continue; // If another term shares the same base, then make sure our ordinal is // higher. This turns some O(n) cases into O(1) if (string_equals(&other->uniqueName.base, &name.base) && (other->uniqueName.ordinal >= name.ordinal)) { name.ordinal = other->uniqueName.ordinal + 1; updatedName = true; // If this name is already used, then just try the next ordinal. This // case results in more blind searching, but it's necessary to handle // the situation where a generated name is already taken. } else if (string_equals(&other->uniqueName.name, &name.name)) { name.ordinal++; updatedName = true; } if (updatedName) { char ordinalBuf[30]; sprintf(ordinalBuf, "%d", name.ordinal); copy(&name.base, &name.name); string_append(&name.name, "_"); string_append(&name.name, ordinalBuf); break; } } } }
static void req_forward(struct context *ctx, struct conn *c_conn, struct msg *msg) { rstatus_t status; struct conn *s_conn; struct server_pool *pool; uint8_t *key; uint32_t keylen; ASSERT(c_conn->client && !c_conn->proxy); /* enqueue message (request) into client outq, if response is expected */ if (!msg->noreply) { c_conn->enqueue_outq(ctx, c_conn, msg); } pool = c_conn->owner; key = NULL; keylen = 0; /* * If hash_tag: is configured for this server pool, we use the part of * the key within the hash tag as an input to the distributor. Otherwise * we use the full key */ if (!string_empty(&pool->hash_tag)) { struct string *tag = &pool->hash_tag; uint8_t *tag_start, *tag_end; tag_start = nc_strchr(msg->key_start, msg->key_end, tag->data[0]); if (tag_start != NULL) { tag_end = nc_strchr(tag_start + 1, msg->key_end, tag->data[1]); if (tag_end != NULL) { key = tag_start + 1; keylen = (uint32_t)(tag_end - key); } } } if (keylen == 0) { key = msg->key_start; keylen = (uint32_t)(msg->key_end - msg->key_start); } s_conn = server_pool_conn(ctx, c_conn->owner, key, keylen); if (s_conn == NULL) { req_forward_error(ctx, c_conn, msg); return; } ASSERT(!s_conn->client && !s_conn->proxy); /* enqueue the message (request) into server inq */ status = event_add_out_with_conn(ctx, s_conn, msg); if (status != NC_OK) { req_forward_error(ctx, c_conn, msg); s_conn->err = errno; return; } req_forward_stats(ctx, s_conn->owner, msg); log_debug(LOG_VERB, "forward from c %d to s %d req %"PRIu64" len %"PRIu32 " type %d with key '%.*s'", c_conn->sd, s_conn->sd, msg->id, msg->mlen, msg->type, keylen, key); }
void updateIsModel() { setIsModel(!string_empty(m_modelKey.c_str()) && !string_equal(m_modelKey.c_str(), m_name.c_str())); }