DFBResult dfb_state_set_index_translation( CardState *state, const int *indices, int num_indices ) { D_MAGIC_ASSERT( state, CardState ); D_ASSERT( indices != NULL || num_indices == 0 ); dfb_state_lock( state ); if (state->num_translation != num_indices) { int *new_trans = D_REALLOC( state->index_translation, num_indices * sizeof(int) ); D_ASSERT( num_indices || new_trans == NULL ); if (num_indices && !new_trans) { dfb_state_unlock( state ); return D_OOM(); } state->index_translation = new_trans; state->num_translation = num_indices; } if (num_indices) direct_memcpy( state->index_translation, indices, num_indices * sizeof(int) ); state->modified |= SMF_INDEX_TRANSLATION; dfb_state_unlock( state ); return DFB_OK; }
DirectResult fusion_shm_pool_reallocate( FusionSHMPoolShared *pool, void *data, int size, bool lock, void **ret_data ) { void *new_data; D_MAGIC_ASSERT( pool, FusionSHMPoolShared ); new_data = D_REALLOC( data, size ); if (!new_data) return DR_NOSHAREDMEMORY; *ret_data = new_data; return DR_OK; }
DirectResult direct_config_set( const char *name, const char *value ) { if (direct_strcmp (name, "disable-module" ) == 0) { if (value) { int n = 0; while (direct_config->disable_module && direct_config->disable_module[n]) n++; direct_config->disable_module = (char**) D_REALLOC( direct_config->disable_module, sizeof(char*) * (n + 2) ); direct_config->disable_module[n] = D_STRDUP( value ); direct_config->disable_module[n+1] = NULL; } else { D_ERROR("Direct/Config '%s': No module name specified!\n", name); return DR_INVARG; } } else if (direct_strcmp (name, "module-dir" ) == 0) { if (value) { if (direct_config->module_dir) D_FREE( direct_config->module_dir ); direct_config->module_dir = D_STRDUP( value ); } else { D_ERROR("Direct/Config 'module-dir': No directory name specified!\n"); return DR_INVARG; } } else if (direct_strcmp (name, "memcpy" ) == 0) { if (value) { if (direct_config->memcpy) D_FREE( direct_config->memcpy ); direct_config->memcpy = D_STRDUP( value ); } else { D_ERROR("Direct/Config '%s': No method specified!\n", name); return DR_INVARG; } } else if (direct_strcmp (name, "quiet" ) == 0 || strcmp (name, "no-quiet" ) == 0) { /* Enable/disable all at once by default. */ DirectMessageType type = DMT_ALL; /* Find out the specific message type being configured. */ if (value) { if (!strcmp( value, "info" )) type = DMT_INFO; else if (!strcmp( value, "warning" )) type = DMT_WARNING; else if (!strcmp( value, "error" )) type = DMT_ERROR; else if (!strcmp( value, "once" )) type = DMT_ONCE; else if (!strcmp( value, "untested" )) type = DMT_UNTESTED; else if (!strcmp( value, "unimplemented" )) type = DMT_UNIMPLEMENTED; else { D_ERROR( "DirectFB/Config '%s': Unknown message type '%s'!\n", name, value ); return DR_INVARG; } } /* Set/clear the corresponding flag in the configuration. */ if (name[0] == 'q') D_FLAGS_SET( direct_config->quiet, type ); else D_FLAGS_CLEAR( direct_config->quiet, type ); } else if (direct_strcmp (name, "no-quiet" ) == 0) { direct_config->quiet = DMT_NONE; } else if (direct_strcmp (name, "debug" ) == 0) { if (value) { DirectLogDomainConfig config = {0}; if (value[0] && value[1] == ':') { config.level = value[0] - '0' + DIRECT_LOG_DEBUG_0; value += 2; } else config.level = DIRECT_LOG_DEBUG; direct_log_domain_configure( value, &config ); } else if (direct_config->log_level < DIRECT_LOG_DEBUG) direct_config->log_level = DIRECT_LOG_DEBUG; } else if (direct_strcmp (name, "no-debug" ) == 0) { if (value) { DirectLogDomainConfig config = {0}; config.level = DIRECT_LOG_DEBUG_0; direct_log_domain_configure( value, &config ); } else if (direct_config->log_level > DIRECT_LOG_DEBUG_0) direct_config->log_level = DIRECT_LOG_DEBUG_0; } else if (direct_strcmp (name, "log-all" ) == 0) { direct_config->log_all = true; } else if (direct_strcmp (name, "log-none" ) == 0) { direct_config->log_none = true; } else if (direct_strcmp (name, "debugmem" ) == 0) { direct_config->debugmem = true; } else if (direct_strcmp (name, "no-debugmem" ) == 0) { direct_config->debugmem = false; } else if (direct_strcmp (name, "trace" ) == 0) { direct_config->trace = true; } else if (direct_strcmp (name, "no-trace" ) == 0) { direct_config->trace = false; } else if (direct_strcmp (name, "log-file" ) == 0 || strcmp (name, "log-udp" ) == 0) { if (value) { DirectResult ret; DirectLog *log; ret = direct_log_create( strcmp(name,"log-udp") ? DLT_FILE : DLT_UDP, value, &log ); if (ret) return ret; if (direct_config->log) direct_log_destroy( direct_config->log ); direct_config->log = log; direct_log_set_default( log ); } else { if (direct_strcmp(name,"log-udp")) D_ERROR("Direct/Config '%s': No file name specified!\n", name); else D_ERROR("Direct/Config '%s': No host and port specified!\n", name); return DR_INVARG; } } else if (direct_strcmp (name, "fatal-level" ) == 0) { if (direct_strcasecmp (value, "none" ) == 0) { direct_config->fatal = DCFL_NONE; } else if (direct_strcasecmp (value, "assert" ) == 0) { direct_config->fatal = DCFL_ASSERT; } else if (direct_strcasecmp (value, "assume" ) == 0) { direct_config->fatal = DCFL_ASSUME; } else { D_ERROR("Direct/Config '%s': Unknown level specified (use 'none', 'assert', 'assume')!\n", name); return DR_INVARG; } } else if (direct_strcmp (name, "fatal-break" ) == 0) { direct_config->fatal_break = true; } else if (direct_strcmp (name, "no-fatal-break" ) == 0) { direct_config->fatal_break = false; } else if (direct_strcmp (name, "sighandler" ) == 0) { direct_config->sighandler = true; } else if (direct_strcmp (name, "no-sighandler" ) == 0) { direct_config->sighandler = false; } else if (direct_strcmp (name, "dont-catch" ) == 0) { if (value) { char *signals = D_STRDUP( value ); char *p = NULL, *r, *s = signals; while ((r = direct_strtok_r( s, ",", &p ))) { char *error; unsigned long signum; direct_trim( &r ); signum = direct_strtoul( r, &error, 10 ); if (*error) { D_ERROR( "Direct/Config '%s': Error in number at '%s'!\n", name, error ); D_FREE( signals ); return DR_INVARG; } sigaddset( &direct_config->dont_catch, signum ); s = NULL; } D_FREE( signals ); } else { D_ERROR("Direct/Config '%s': No signals specified!\n", name); return DR_INVARG; } } else if (direct_strcmp (name, "thread_block_signals") == 0) { direct_config->thread_block_signals = true; } else if (direct_strcmp (name, "no-thread_block_signals") == 0) { direct_config->thread_block_signals = false; } else if (direct_strcmp (name, "thread-priority-scale" ) == 0) { if (value) { int scale; if (direct_sscanf( value, "%d", &scale ) < 1) { D_ERROR("Direct/Config '%s': Could not parse value!\n", name); return DR_INVARG; } direct_config->thread_priority_scale = scale; } else { D_ERROR("Direct/Config '%s': No value specified!\n", name); return DR_INVARG; } } else if (direct_strcmp (name, "thread-priority" ) == 0) { /* Must be moved to lib/direct/conf.c in trunk! */ if (value) { int priority; if (direct_sscanf( value, "%d", &priority ) < 1) { D_ERROR("Direct/Config '%s': Could not parse value!\n", name); return DR_INVARG; } direct_config->thread_priority = priority; } else { D_ERROR("Direct/Config '%s': No value specified!\n", name); return DR_INVARG; } } else if (direct_strcmp (name, "thread-scheduler" ) == 0) { /* Must be moved to lib/direct/conf.c in trunk! */ if (value) { if (direct_strcmp( value, "other" ) == 0) { direct_config->thread_scheduler = DCTS_OTHER; } else if (direct_strcmp( value, "fifo" ) == 0) { direct_config->thread_scheduler = DCTS_FIFO; } else if (direct_strcmp( value, "rr" ) == 0) { direct_config->thread_scheduler = DCTS_RR; } else { D_ERROR( "Direct/Config '%s': Unknown scheduler '%s'!\n", name, value ); return DR_INVARG; } } else { D_ERROR( "Direct/Config '%s': No value specified!\n", name ); return DR_INVARG; } } else if (direct_strcmp (name, "thread-stacksize" ) == 0) { /* Must be moved to lib/direct/conf.c in trunk! */ if (value) { int size; if (direct_sscanf( value, "%d", &size ) < 1) { D_ERROR( "Direct/Config '%s': Could not parse value!\n", name ); return DR_INVARG; } direct_config->thread_stack_size = size; } else { D_ERROR( "Direct/Config '%s': No value specified!\n", name ); return DR_INVARG; } } else return DR_UNSUPPORTED; return DR_OK; }
/**************************************************************************** * * Procedure read_graph_data * * Arguments: infile: pointer to type FILE * graph: a pointer to graph_type * sideways: a char * * Returns: none * * Action: Reads the data out of 'infile. * This reads until it hits a line beginning with a # mark. * * If 'sideways is non-zero then it is assumed that the data columns * occur first in the file, followed by the independant variable. * ****************************************************************************/ void read_graph_data(FILE *infile,graph_type *graph,char sideways,char parse_header) { char instring[MAX_STR_LEN],foostring[MAX_STR_LEN]; int num_curves,num_names; int i,j; int done; int max_p,num_p; float xval,yval; float min_x,min_y,max_x,max_y; if( !graph )FATAL_BUG("No graph passed to read_graph_data."); if( skipcomments(infile,instring) < 0){ error("That file is empty!"); display("Too Bad...."); return; } /******* make sure that we've read past any header information write some code to process this stuff! ********/ while(instring[0] == '#'){ if(skipcomments(infile,instring)<0){ error("That file is empty!"); display("Too Bad...."); return; } } /* figure out how many curves there are in the file */ count_curves(instring,&num_curves); if(num_curves < 1){ error("That data file has less than one data set in it... check it please."); display("Yikes!"); return; } /* parse the header information */ if( parse_header ){ rewind(infile); graph->curve_names = (char *)D_CALLOC(NORMAL_STR_LEN*num_curves,sizeof(char)); num_names = 1; skipcomments(infile,instring); while(instring[0] == '#'){ skipcomments(infile,instring); if( strstr(instring,"Curve") ){ sscanf(instring,"%s %s",foostring, &(graph->curve_names[num_names*NORMAL_STR_LEN])); num_names++; } else if (strstr(instring,"Title")){ sscanf(instring,"%s %s",foostring,graph->curve_names); } } } /* get space to keep track of which curves should be displayed */ graph->curves_to_display = (char *)D_CALLOC(num_curves,sizeof(char)); if( !graph->curves_to_display ) fatal("Can't get space for curves_to_display."); /* get space to store linestyles */ graph->styles = (char *)D_CALLOC(num_curves,sizeof(char)); if( !graph->styles )fatal("Can't get space for curve styles."); /* get space to store fill toggles */ graph->fills = (char *)D_CALLOC(num_curves,sizeof(char)); if( !graph->fills )fatal("Can't get space for curve fills."); /* initialize the styles */ for( i=0;i<num_curves; i++){ graph->styles[i] = i; } /* default to showing just the first curve */ graph->curves_to_display[0] = 1; graph->do_x_tics = 1; graph->do_y_tics = 1; /******* get initial space for the data (we don't really know how much there will be yet, but we'll deal with that. *******/ max_p = 100; num_p = 0; graph->raw_data = (point_type2D *)D_CALLOC(max_p*num_curves,sizeof(point_type2D)); if( !graph->raw_data ){ error("Can't get space for graph data...."); display("Oh well..."); return; } /* read in data until either EOF or a # mark is hit */ done = 1; while(done >= 0 ){ /* now use strtok to read out space delimited numbers */ if( !sideways ){ sscanf((const char *)strtok(instring," "),"%lf",&xval); for(i=0;i<num_curves;i++){ graph->raw_data[num_p*num_curves+i].x = xval; sscanf((const char *)strtok(0," "),"%lf",&(graph->raw_data[num_p*num_curves+i].y)); } } else{ /******* assume that the x coordinate is at the end of the line for properties data.... *******/ sscanf((const char *)strtok(instring," "),"%lf",&(graph->raw_data[num_p*num_curves].x)); for(i=1;i<num_curves;i++){ sscanf((const char *)strtok(0," "),"%lf",&(graph->raw_data[num_p*num_curves+i].x)); } sscanf((const char *)strtok(0," "),"%lf",&yval); for(i=0;i<num_curves;i++){ graph->raw_data[num_p*num_curves+i].y = yval; } } num_p++; /* if we need more space, get it now */ if( num_p == max_p ){ max_p += 100; graph->raw_data = (point_type2D *)D_REALLOC((void *)graph->raw_data, (unsigned)max_p*num_curves* sizeof(point_type2D)); if( !graph->raw_data ){ error("Can't D_REALLOCate space for graph data...."); display("Oh well..."); return; } } done = skipcomments(infile,instring); /* check to see if this line begins with a # */ if( done >= 0 && instring[0] == '#' ) done = -1; } graph->num_p = num_p; graph->num_curves = num_curves; graph->data = (point_type2D *)D_CALLOC((unsigned)num_p*num_curves,sizeof(point_type2D)); if( !graph->data ) fatal("Can't get space for graph data."); /* find the minimum and maximum values (to use in scaling) */ min_y = min_x = 1e10; max_y = max_x = -1e10; for( i=0; i<num_p; i++ ){ if(graph->raw_data[i*num_curves].x > max_x) max_x = graph->raw_data[i*num_curves].x; if(graph->raw_data[i*num_curves].x < min_x) min_x = graph->raw_data[i*num_curves].x; for(j=0;j<num_curves;j++){ if(graph->raw_data[i*num_curves+j].y > max_y) max_y = graph->raw_data[i*num_curves+j].y; if(graph->raw_data[i*num_curves+j].y < min_y) min_y = graph->raw_data[i*num_curves+j].y; } } graph->max_x = max_x; graph->max_y = max_y; graph->min_x = min_x; graph->min_y = min_y; /* that's it */ }
DFBResult dfb_font_get_glyph_data( CoreFont *font, unichar glyph, CoreGlyphData **ret_data ) { DFBResult ret; CoreGlyphData *data; D_MAGIC_ASSERT( font, CoreFont ); D_ASSERT( ret_data != NULL ); if ((data = direct_tree_lookup (font->glyph_infos, (void *)glyph)) != NULL) { *ret_data = data; return DFB_OK; } data = (CoreGlyphData *) D_CALLOC(1, sizeof (CoreGlyphData)); if (!data) return DFB_NOSYSTEMMEMORY; if (font->GetGlyphInfo && font->GetGlyphInfo (font, glyph, data) == DFB_OK && data->width > 0 && data->height > 0) { if (font->next_x + data->width > font->row_width) { CoreSurface *surface; if (font->row_width == 0) { int width = 8192 / font->height; if (width > 2048) width = 2048; if (width < font->maxadvance) width = font->maxadvance; font->row_width = (width + 7) & ~7; } ret = dfb_surface_create( font->core, font->row_width, MAX( font->height + 1, 8 ), font->pixel_format, CSP_VIDEOLOW, DSCAPS_NONE, NULL, &surface ); if (ret) { D_ERROR( "DirectFB/core/fonts: " "Could not create glyph surface! (%s)\n", DirectFBErrorString( ret ) ); D_FREE( data ); return ret; } font->next_x = 0; font->rows++; font->surfaces = D_REALLOC( font->surfaces, sizeof(void *) * font->rows ); font->surfaces[font->rows - 1] = surface; } if (font->RenderGlyph(font, glyph, data, font->surfaces[font->rows - 1]) == DFB_OK) { int align = DFB_PIXELFORMAT_ALIGNMENT(font->pixel_format); data->surface = font->surfaces[font->rows - 1]; data->start = font->next_x; font->next_x += (data->width + align) & ~align; dfb_gfxcard_flush_texture_cache(); } else { data->start = data->width = data->height = 0; } } else { data->start = data->width = data->height = 0; } direct_tree_insert (font->glyph_infos, (void *) glyph, data); *ret_data = data; return DFB_OK; }