Esempio n. 1
0
void DestinNetworkAlt::init(SupportedImageWidths width, unsigned int layers,
                            unsigned int centroid_counts [], bool isUniform,
                            int extRatio, unsigned int layer_widths[]){
    callback = NULL;
    initTemperatures(layers, centroid_counts);

    DestinConfig *dc = CreateDefaultConfig(layers);
    dc->addCoeff = 0; // disabled addition of centroids
    dc->beta = 0.01;
    std::copy(centroid_counts, centroid_counts + layers, dc->centroids); // initial number of centroids
    dc->extRatio = extRatio;
    dc->freqCoeff = 0.05;
    dc->freqTreshold = 0; // disabled deletion of centroids
    dc->gamma = gamma;
    dc->isUniform = isUniform;
    dc->lambdaCoeff = lambdaCoeff;
   
    std::copy(centroid_counts, centroid_counts + layers, dc->layerMaxNb); // max number of centroids

    if(layer_widths != NULL){ // provide support for non standard heirarchy
        std::copy(layer_widths, layer_widths + layers, dc->layerWidths);
    }

    if(width % dc->layerWidths[0] == 0){
        int ratio = width / dc->layerWidths[0];
        dc->inputDim = ratio * ratio;
    } else {
        DestroyConfig(dc);
        throw std::runtime_error("Input image width must be evenly divisible by the bottom layer width.");
    }

    dc->nClasses = 0;
    dc->nMovements = 0; //this class does not use movements
    dc->starvCoeff = 0.05;
    std::copy(temperatures, temperatures + layers, dc->temperatures);

    destin = InitDestinWithConfig(dc);
    destin->rindex=0;
    if(destin == NULL){
        throw std::runtime_error("Could not create the destin structure. Perhaps the given layer widths is not supported.");
    }

    DestroyConfig(dc);

    setBeliefTransform(DST_BT_NONE);
    ClearBeliefs(destin);
    SetLearningStrat(destin, CLS_FIXED);
    destin->fixedLearnRate = 0.1;
    isTraining(true);
}
Esempio n. 2
0
/* returns:
 *		0 on success
 *		1 if data is empty
 *		2 if ConfigWriter cannot be initialized
 *
 */
int
WriteIdentOptions (const char *filename, char *myname, IdentConfig * config, unsigned long flags)
{
	ConfigDef    *IdentConfigWriter = NULL;
	FreeStorageElem *Storage = NULL, **tail = &Storage;
	ConfigData cd ;

	if (config == NULL)
		return 1;
	cd.filename = filename ;
	if ((IdentConfigWriter = InitConfigWriter (myname, &IdentSyntax, CDT_Filename, cd)) == NULL)
		return 2;

	CopyFreeStorage (&Storage, config->more_stuff);
    if (config->style_defs)
        *tail = MyStyleDefinitionsList2free_storage (config->style_defs, &IdentSyntax);
	ADVANCE_LINKED_LIST_TAIL(tail);

	/* building free storage here */
	/* writing config into the file */
	cd.filename = filename ;
	WriteConfig (IdentConfigWriter, Storage, CDT_Filename, &cd, flags);
	DestroyFreeStorage (&Storage);
	DestroyConfig (IdentConfigWriter);

	if (Storage)
	{
		fprintf (stderr, "\n%s:Config Writing warning: Not all Free Storage discarded! Trying again...", myname);
		DestroyFreeStorage (&Storage);
		fprintf (stderr, (Storage != NULL) ? " failed." : " success.");
	}
	return 0;
}
Esempio n. 3
0
IdentConfig  *
ParseIdentOptions (const char *filename, char *myname)
{
	ConfigData    cd ;
	ConfigDef    *IdentConfigReader ; 
	IdentConfig  *config = CreateIdentConfig ();
	FreeStorageElem *Storage = NULL;

	cd.filename = filename ;
	IdentConfigReader = InitConfigReader (myname, &IdentSyntax, CDT_Filename, cd, NULL);
	if (!IdentConfigReader)
		return config;

	PrintConfigReader (IdentConfigReader);
	ParseConfig (IdentConfigReader, &Storage);

	/* getting rid of all the crap first */
	StorageCleanUp (&Storage, &(config->more_stuff), CF_DISABLED_OPTION);

	config->style_defs = free_storage2MyStyleDefinitionsList (Storage);

	DestroyConfig (IdentConfigReader);
	DestroyFreeStorage (&Storage);
	return config;

}
Esempio n. 4
0
ThemeConfig *
ParseThemeFile (const char *filename, char *myname)
{
	ThemeConfig *config ;
	ConfigData cd ;
    ConfigDef *ConfigReader;
    FreeStorageElem *Storage = NULL, *pCurr;
    ConfigItem item;

	cd.filename = filename ;
	ConfigReader = InitConfigReader (myname, &ThemeSyntax, CDT_Filename, cd, NULL);
	LOCAL_DEBUG_OUT( "ConfigReader is %p", ConfigReader );
    if (!ConfigReader)
        return NULL;

	config = safecalloc( 1, sizeof(ThemeConfig ) );

	PrintConfigReader (ConfigReader);
	ParseConfig (ConfigReader, &Storage);

	/* getting rid of all the crap first */
    StorageCleanUp (&Storage, &(config->more_stuff), CF_DISABLED_OPTION);

	for (pCurr = Storage; pCurr; pCurr = pCurr->next)
  	{
  	    if (pCurr->term == NULL)
			continue;
        if (!ReadConfigItem (&item, pCurr))
			continue;

        switch (pCurr->term->id)
		{
            case FEEL_Function_ID           :
                if( mystrncasecmp( item.data.string, THEME_INSTALL_FUNC_NAME, sizeof(THEME_INSTALL_FUNC_NAME))== 0 )
                {
                    if( config->install )
                        really_destroy_complex_func( config->install );
                     config->install = FreeStorage2ComplexFunction( pCurr, &item, NULL );
                }else if( mystrncasecmp( item.data.string, THEME_APPLY_FUNC_NAME, sizeof(THEME_APPLY_FUNC_NAME) )== 0 )
                {
                    if( config->apply )
                        really_destroy_complex_func( config->apply );
                    config->apply = FreeStorage2ComplexFunction( pCurr, &item, NULL );
                }
                break ;
          default:
				item.ok_to_free = 1;
		}
    }
	ReadConfigItem (&item, NULL);

	DestroyConfig (ConfigReader);
	DestroyFreeStorage (&Storage);

	return config;
}
Esempio n. 5
0
ASetRootConfig *ParseASetRootOptions (const char *filename, char *myname)
{
	ConfigData cd;
	ConfigDef *ConfigReader;
	ASetRootConfig *config = CreateASetRootConfig ();
	MyBackgroundConfig **backs_tail = &(config->my_backs);
	DeskBackConfig **desks_tail = &(config->my_desks);
	FreeStorageElem *Storage = NULL, *pCurr;
	ConfigItem item;

	cd.filename = filename;
	ConfigReader =
			InitConfigReader (myname, &ASetRootSyntax, CDT_Filename, cd, NULL);

	if (!ConfigReader)
		return config;

	item.memory = NULL;
	PrintConfigReader (ConfigReader);
	ParseConfig (ConfigReader, &Storage);

	/* getting rid of all the crap first */
	StorageCleanUp (&Storage, &(config->more_stuff), CF_DISABLED_OPTION);

	config->style_defs = free_storage2MyStyleDefinitionsList (Storage);

	for (pCurr = Storage; pCurr; pCurr = pCurr->next) {
		if (pCurr->term == NULL)
			continue;

		if (pCurr->term->id == BGR_MYBACKGROUND) {
			if ((*backs_tail =
					 ParseMyBackgroundOptions (pCurr->sub, myname)) != NULL)
				backs_tail = &((*backs_tail)->next);
			continue;
		}

		if (!ReadConfigItem (&item, pCurr))
			continue;
		switch (pCurr->term->id) {
		case BGR_DESK_BACK:
			if ((*desks_tail = ParseDeskBackOptions (&item, myname)) != NULL)
				desks_tail = &((*desks_tail)->next);
			break;
		default:
			item.ok_to_free = 1;
		}
	}
	ReadConfigItem (&item, NULL);
	FixDeskBacks (config);

	DestroyConfig (ConfigReader);
	DestroyFreeStorage (&Storage);
	return config;
}
Esempio n. 6
0
AutoExecConfig *
ParseAutoExecOptions (const char *filename, char *myname)
{
    ConfigData cd ;
	ConfigDef *ConfigReader;
    AutoExecConfig *config = CreateAutoExecConfig ();
	FreeStorageElem *Storage = NULL, *pCurr;
    ConfigItem item;

	cd.filename = filename ;
	ConfigReader = InitConfigReader (myname, &AutoExecSyntax, CDT_Filename, cd, NULL);
	if (!ConfigReader)
  		return config;

    item.memory = NULL;
	PrintConfigReader (ConfigReader);
	ParseConfig (ConfigReader, &Storage);

	/* getting rid of all the crap first */
    StorageCleanUp (&Storage, &(config->more_stuff), CF_DISABLED_OPTION);

    for (pCurr = Storage; pCurr; pCurr = pCurr->next)
  	{
  	    if (pCurr->term == NULL)
			continue;
        if (!ReadConfigItem (&item, pCurr))
			continue;

        switch (pCurr->term->id)
		{
            case FEEL_Function_ID           :
                if( mystrncasecmp( item.data.string, "InitFunction", 12 ) == 0 )
                {
                    if( config->init )
                        really_destroy_complex_func( config->init );
                     config->init = FreeStorage2ComplexFunction( pCurr, &item, NULL );
                }else if( mystrncasecmp( item.data.string, "RestartFunction", 15 ) == 0 )
                {
                    if( config->restart )
                        really_destroy_complex_func( config->restart );
                    config->restart = FreeStorage2ComplexFunction( pCurr, &item, NULL );
                }
                break ;
          default:
				item.ok_to_free = 1;
		}
    }
	ReadConfigItem (&item, NULL);

	DestroyConfig (ConfigReader);
	DestroyFreeStorage (&Storage);
	return config;

}
Esempio n. 7
0
void
windowbox_parse (char *tline, FILE * fd, char **unused1, int *unused2)
{
    FilePtrAndData fpd ;
    ConfigDef    *ConfigReader ;
    FreeStorageElem *Storage = NULL, *more_stuff = NULL;
    ASWindowBox **aswbox_list = &(ASDefaultScr->Feel.window_boxes);
	unsigned int *count = &(ASDefaultScr->Feel.window_boxes_num);
    ASWindowBox *new_box ;
	ConfigData cd ;

    fpd.fp = fd ;
    fpd.data = safemalloc( 12+1+strlen(tline)+1+1 ) ;
    sprintf( fpd.data, "WindowBox %s\n", tline );
    LOCAL_DEBUG_OUT( "fd(%p)->tline(\"%s\")->fpd.data(\"%s\")", fd, tline, fpd.data );
	cd.fileptranddata = &fpd ;
    ConfigReader = InitConfigReader ((char*)get_application_name(), &WindowBoxSyntax, CDT_FilePtrAndData, cd, NULL);
    free( fpd.data );

    if (!ConfigReader)
        return ;

	PrintConfigReader (ConfigReader);
	ParseConfig (ConfigReader, &Storage);

	/* getting rid of all the crap first */
    StorageCleanUp (&Storage, &more_stuff, CF_DISABLED_OPTION);
    DestroyFreeStorage (&more_stuff);

    if( (new_box = ProcessWindowBoxOptions (Storage)) != NULL )
    {
        int i = *count ;
        ++(*count) ;
        *aswbox_list = realloc( *aswbox_list, sizeof(ASWindowBox)*(i+1));
        (*aswbox_list)[i] = *new_box ;
        free( new_box );
    }

	DestroyConfig (ConfigReader);
	DestroyFreeStorage (&Storage);
}
Esempio n. 8
0
int
WriteAutoExecOptions (const char *filename, char *myname,  AutoExecConfig * config, unsigned long flags)
{
    ConfigDef *ConfigWriter = NULL;
    FreeStorageElem *Storage = NULL, **tail = &Storage;
	ConfigData cd ;

	if (config == NULL)
  		return 1;
	cd.filename = filename ; 
    if ((ConfigWriter = InitConfigWriter (myname, &AutoExecSyntax, CDT_Filename, cd)) == NULL)
	    return 2;

    CopyFreeStorage (&Storage, config->more_stuff);

    if( config->init )
        tail = ComplexFunction2FreeStorage( &AutoExecSyntax, tail, config->init );
    if(config->restart)
        tail = ComplexFunction2FreeStorage( &AutoExecSyntax, tail, config->restart );

    /* writing config into the file */
	cd.filename = filename ; 
	WriteConfig (ConfigWriter, Storage, CDT_Filename, &cd, flags);
	DestroyFreeStorage (&Storage);
    DestroyConfig (ConfigWriter);

	if (Storage)
  	{
    	fprintf (stderr,
	  		     "\n%s:Config Writing warning: Not all Free Storage discarded! Trying again...",
	      		 myname);
    	DestroyFreeStorage (&Storage);
  		fprintf (stderr, (Storage != NULL) ? " failed." : " success.");
    }
	return 0;
}
Esempio n. 9
0
int main( int argc, char** argv )
{
    InitTests(argc, argv);

    Describe("Config module")
        .use(dummyExceptionSandbox)

        .it("can be initialized empty.", [](){

            Require(InitConfig(0, NULL) == true);
            DestroyConfig();
        })

        .it("has a proper destructor.", [](){

            const char* argv[] = {"", "--aaa=bbb"};

            {
                Require(InitConfig(2, argv) == true);
                ConfigScope scope;
                Require(strcmp(GetConfigString("aaa",""), "bbb") == 0);
            }

            {
                Require(InitConfig(0, NULL) == true);
                ConfigScope scope;
                Require(GetConfigString("aaa",NULL) == NULL);
            }
        })

        .it("can parse arguments.", [](){

            const char* argv[] = {"", "--aaa=bbb", "--foo=bar", "--ccc=ddd"};

            Require(InitConfig(4, argv) == true);
            ConfigScope scope;

            Require(strcmp(GetConfigString("foo",""), "bar") == 0);
            Require(strcmp(GetConfigString("foo","yyy"), "bar") == 0);
            Require(strcmp(GetConfigString("foo",NULL), "bar") == 0);
            Require(strcmp(GetConfigString("xxx",""), "") == 0);
            Require(strcmp(GetConfigString("xxx","yyy"), "yyy") == 0);
            Require(GetConfigString("xxx",NULL) == NULL);
        })

        .it("can convert integer values.", [](){

            const char* argv[] = {"", "--aaa=42", "--bbb=1.1", "--ccc=1.9"};

            Require(InitConfig(4, argv) == true);
            ConfigScope scope;

            Require(GetConfigInt("aaa", 0) == 42);
            Require(GetConfigInt("bbb", 0) == 1);
            Require(GetConfigInt("ccc", 0) == 1);
            Require(GetConfigInt("xxx", 0) == 0);
        })

        .it("can convert floating point values.", [](){

            const char* argv[] = {"", "--aaa=42", "--bbb=1.1", "--ccc=1.9"};

            Require(InitConfig(4, argv) == true);
            ConfigScope scope;

            Require(GetConfigFloat("aaa", 0) == 42);
            Require(GetConfigFloat("bbb", 0) == 1.1f);
            Require(GetConfigFloat("ccc", 0) == 1.9f);
            Require(GetConfigFloat("xxx", 0.1f) == 0.1f);
        })

        .it("can convert boolean values.", [](){

            const char* argv[] = {
                "",
                "--aaa=42",
                "--bbb=1.1",
                "--ccc=1.9",
                "--ddd=0",
                "--eee=0.0",
                "--fff=true",
                "--ggg=false",
                "--hhh=yes",
                "--jjj=no"};

            Require(InitConfig(10, argv) == true);
            ConfigScope scope;

            Require(GetConfigBool("aaa", false) == true);
            Require(GetConfigBool("bbb", false) == true);
            Require(GetConfigBool("ccc", false) == true);
            Require(GetConfigBool("ddd", true) == false);
            Require(GetConfigBool("eee", true) == false);
            Require(GetConfigBool("fff", false) == true);
            Require(GetConfigBool("ggg", true) == false);
            Require(GetConfigBool("hhh", false) == true);
            Require(GetConfigBool("jjj", true) == false);

            Require(GetConfigBool("xxx", true) == true);
            Require(GetConfigBool("xxx", false) == false);
        })

        .it("can parse ini files.", [](){

            const char* argv[] = {"", "--config=config/Test.ini"};

            Require(InitConfig(2, argv) == true);
            ConfigScope scope;

            Require(GetConfigString("config", NULL) == NULL);
            Require(strcmp(GetConfigString("aaa", ""), "bbb") == 0);
            Require(strcmp(GetConfigString("foo.bar", ""), "baz") == 0);
            Require(strcmp(GetConfigString("foo.hello", ""), "Hello World") == 0);
        });

    return RunTests();
}
Esempio n. 10
0
 void destroy() { DestroyConfig(); destroyed = true; };
Esempio n. 11
0
 ~ConfigScope() { if(!destroyed) DestroyConfig(); }
Esempio n. 12
0
SoundConfig  *
ParseSoundOptions (const char *filename, char *myname)
{
	ConfigData cd ;
	ConfigDef    *SoundConfigReader;
	SoundConfig  *config = CreateSoundConfig ();

	FreeStorageElem *Storage = NULL, *pCurr;
	ConfigItem    item;

	cd.filename = filename ;
	SoundConfigReader = InitConfigReader (myname, &SoundSyntax, CDT_Filename, cd, NULL);
	if (!SoundConfigReader)
		return config;

	item.memory = NULL;
	PrintConfigReader (SoundConfigReader);
	ParseConfig (SoundConfigReader, &Storage);

	/* getting rid of all the crap first */
	StorageCleanUp (&Storage, &(config->more_stuff), CF_DISABLED_OPTION);

	for (pCurr = Storage; pCurr; pCurr = pCurr->next)
	{
		if (pCurr->term == NULL)
			continue;

		{
			if (!ReadConfigItem (&item, pCurr))
				continue;

			switch (pCurr->term->id)
			{
			 case SOUND_SOUND_ID:
                 if( pCurr->sub )
                 {
                    if( pCurr->sub->term && pCurr->sub->argv )
                        if( pCurr->sub->term->id >= EVENT_ID_START && pCurr->sub->term->id < EVENT_ID_END )
                            set_string( &(config->sounds[pCurr->sub->term->id-EVENT_ID_START]), mystrdup( pCurr->sub->argv[0] ));
                 }
				 break;
			 case SOUND_PCMDEVICE_ID:
				 //set_string( &(config->pcmdevice), item.data.string );
				 config->pcmdevice = item.data.string;
				 break;
			 case SOUND_PATH_ID:
			 	 config->path = item.data.string;
			 	 break;
			
			 case SOUND_DEBUG_ID:
			 	config->debug = (int)item.data.integer;
			 	break;
/*				 
			 case SOUND_DELAY_ID:
			 	 set_flags( config->set_flags, SOUND_SET_DELAY );
				 config->delay = (int)item.data.integer;
				 break;
	*/
	/*
			 case SOUND_RPLAY_HOST_ID:
			 	 set_string_value( &(config->rplay_host), item.data.string, &(config->set_flags), SOUND_SET_RPLAY_HOST );
				 break;
			 case SOUND_RPLAY_PRI_ID:
				 set_flags( config->set_flags, SOUND_SET_RPLAY_PRIORITY );
				 config->rplay_priority = (int)item.data.integer;
				 break;
			 case SOUND_RPLAY_VOL_ID:
				 set_flags( config->set_flags, SOUND_SET_RPLAY_VOLUME );
				 config->rplay_volume = (int)item.data.integer;
				 break;
	*/
			 default:
				 item.ok_to_free = 1;
			}
		}
	}

	ReadConfigItem (&item, NULL);

	DestroyConfig (SoundConfigReader);
	DestroyFreeStorage (&Storage);
	return config;

}
Esempio n. 13
0
int
WriteSoundOptions (const char *filename, char *myname, SoundConfig * config, unsigned long flags)
{
	ConfigDef    *SoundConfigWriter = NULL;
	FreeStorageElem *Storage = NULL, **tail = &Storage;
    register int i ;
	ConfigData cd ;

	if (config == NULL)
		return 1;
	cd.filename = filename ;

	if ((SoundConfigWriter = InitConfigWriter (myname, &SoundSyntax, CDT_Filename, cd)) == NULL)
		return 2;
	CopyFreeStorage (&Storage, config->more_stuff);
	/* building free storage here */
	/* PCM Device */
	if( config->pcmdevice )
		tail = String2FreeStorage (&SoundSyntax, tail, config->pcmdevice, SOUND_PCMDEVICE_ID);
		
	if (config->debug)
		tail = Integer2FreeStorage (&SoundSyntax, tail, NULL, config->debug, SOUND_DEBUG_ID);
	/* delay */
/*
	if( get_flags(config->set_flags, SOUND_SET_DELAY) )
    	tail = Integer2FreeStorage (&SoundSyntax, tail, NULL, config->delay, SOUND_DELAY_ID);
*/
	/* rplay_host */
//	if (get_flags(config->set_flags, SOUND_SET_RPLAY_HOST) && config->rplay_host)
//        tail = String2FreeStorage (&SoundSyntax, tail, config->rplay_host, SOUND_RPLAY_HOST_ID);

	/* rplay_priority */
//	if (get_flags(config->set_flags, SOUND_SET_RPLAY_PRIORITY))
//        tail = Integer2FreeStorage (&SoundSyntax, tail, NULL, config->rplay_priority, SOUND_RPLAY_PRI_ID);

	/* rplay_volume */
//	if( get_flags(config->set_flags, SOUND_SET_RPLAY_VOLUME) )
//        tail = Integer2FreeStorage (&SoundSyntax, tail, NULL, config->rplay_volume, SOUND_RPLAY_VOL_ID);

	/* line structure */
    for( i = EVENT_ID_END-EVENT_ID_START-1 ; i >=0 ; i-- )
        if( config->sounds[i] )
        {
            FreeStorageElem **dtail = tail ;

            tail = Flag2FreeStorage (&SoundSyntax, tail, SOUND_SOUND_ID);
            if( *dtail )
                Path2FreeStorage (&SoundEventsSyntax, &((*dtail)->sub), NULL, config->sounds[i], EVENT_ID_START + i);
        }

    /* writing config into the file */
	WriteConfig (SoundConfigWriter, Storage, CDT_Filename, &cd, flags);
	DestroyFreeStorage (&Storage);
	DestroyConfig (SoundConfigWriter);

	if (Storage)
	{
		fprintf (stderr, "\n%s:Config Writing warning: Not all Free Storage discarded! Trying again...", myname);
		DestroyFreeStorage (&Storage);
		fprintf (stderr, (Storage != NULL) ? " failed." : " success.");
	}
	return 0;
}
Esempio n. 14
0
/* returns:
 *            0 on success
 *              1 if data is empty
 *              2 if ConfigWriter cannot be initialized
 *
 */
int
WriteFeelOptions (const char *filename, char *myname,
		  FeelConfig * config, unsigned long flags)
{
	ConfigDef *ConfigWriter = NULL;
    FreeStorageElem *Storage = NULL, **tail = &Storage;
    int i ;

	if (config == NULL)
  		return 1;
	if ((ConfigWriter = InitConfigWriter (myname, &FeelSyntax, CDT_Filename,
			  (void *) filename)) == NULL)
	    return 2;

    CopyFreeStorage (&Storage, config->more_stuff);

	/* building free storage here */
    /* flags : */
    tail = Flags2FreeStorage (&FeelSyntax, tail, FeelFlagsXref, config->feel->flags, config->feel->flags);

    /* integer parameters : */
    if (get_flags (config->feel->set_flags, FEEL_ClickTime))
        tail = Integer2FreeStorage (&FeelSyntax, tail, NULL, config->feel->ClickTime, FEEL_ClickTime_ID);
    if (get_flags (config->feel->set_flags, FEEL_OpaqueMove))
        tail = Integer2FreeStorage (&FeelSyntax, tail, NULL, config->feel->OpaqueMove, FEEL_OpaqueMove_ID);
    if (get_flags (config->feel->set_flags, FEEL_OpaqueResize))
        tail = Integer2FreeStorage (&FeelSyntax, tail, NULL, config->feel->OpaqueResize, FEEL_OpaqueResize_ID);
    if (get_flags (config->feel->set_flags, FEEL_AutoRaise))
        tail = Integer2FreeStorage (&FeelSyntax, tail, NULL, config->feel->AutoRaiseDelay, FEEL_AutoRaise_ID);
    if (get_flags (config->feel->set_flags, FEEL_AutoReverse))
        tail = Integer2FreeStorage (&FeelSyntax, tail, NULL, config->feel->AutoReverse, FEEL_AutoReverse_ID);
    if (get_flags (config->feel->set_flags, FEEL_DeskAnimationType))
        tail = Integer2FreeStorage (&FeelSyntax, tail, NULL, config->feel->DeskAnimationType, FEEL_DeskAnimationType_ID);
    if (get_flags (config->feel->set_flags, FEEL_DeskAnimationSteps))
        tail = Integer2FreeStorage (&FeelSyntax, tail, NULL, config->feel->DeskAnimationSteps, FEEL_DeskAnimationSteps_ID);
    if (get_flags (config->feel->set_flags, FEEL_ShadeAnimationSteps))
        tail = Integer2FreeStorage (&FeelSyntax, tail, NULL, config->feel->ShadeAnimationSteps, FEEL_ShadeAnimationSteps_ID);

    if (get_flags (config->feel->set_flags, FEEL_XorValue))
        tail = Integer2FreeStorage (&FeelSyntax, tail, NULL, config->feel->XorValue, FEEL_XorValue_ID);
    if (get_flags (config->feel->set_flags, FEEL_Xzap))
        tail = Integer2FreeStorage (&FeelSyntax, tail, NULL, config->feel->Xzap, FEEL_Xzap_ID);
    if (get_flags (config->feel->set_flags, FEEL_Yzap))
        tail = Integer2FreeStorage (&FeelSyntax, tail, NULL, config->feel->Yzap, FEEL_Yzap_ID);

    for( i = 0 ; i < MAX_CURSORS ; i++ )
    {
        if (config->feel->standard_cursors[i] != 0)
            tail = Integer2FreeStorage (&FeelSyntax, tail, &i, config->feel->standard_cursors[i], FEEL_Cursor_ID);
        if (config->feel->custom_cursors[i] != NULL)
            tail = ASCursor2FreeStorage (&FeelSyntax, tail, i, config->feel->custom_cursors[i], FEEL_CustomCursor_ID);
    }

    if (get_flags (config->feel->set_flags, FEEL_ClickToRaise))
        Bitlist2FreeStorage( &FeelSyntax, tail, config->feel->RaiseButtons, FEEL_ClickToRaise_ID);

    if (get_flags (config->feel->set_flags, FEEL_EdgeScroll))
        Integer2FreeStorage( &FeelSyntax, tail, &(config->feel->EdgeScrollX), config->feel->EdgeScrollY, FEEL_EdgeScroll_ID);
    if (get_flags (config->feel->set_flags, FEEL_EdgeResistance))
        Integer2FreeStorage( &FeelSyntax, tail, &(config->feel->EdgeResistanceScroll), config->feel->EdgeResistanceMove, FEEL_EdgeResistance_ID);

    /* complex functions : */
    if( config->feel->funcs_list )
        if( config->feel->funcs_list->items_num )
        {
            ComplexFunction **list ;

            list = safecalloc( config->feel->funcs_list->items_num, sizeof(ComplexFunction*));
            if( (i = sort_hash_items( config->feel->funcs_list, NULL, (void**)list, 0 )) > 0 )
                while ( --i >= 0 )
                    tail = ComplexFunction2FreeStorage( &FeelSyntax, tail, list[i]);
            free( list );
        }
    /* menus */
    /* menus writing require additional work due to the nature of the problem -
     * menus can come from file or directory or from feel file itself.
     * plus there has to be some mechanismus in place in order to preserve
     * .include configuration when menu is saved as directory.
     *          Sasha.
     */
    /* this is preliminary code that only saves menus into feel file itself  - make sure
     * you remove all the other menus from the feel->menus_list prior to calling this */
    if( config->feel->menus_list )
        if( config->feel->menus_list->items_num )
        {
            MenuData **list ;
            register int i ;
            list = safecalloc( config->feel->menus_list->items_num, sizeof(MenuData*));
            if( (i = sort_hash_items( config->feel->menus_list, NULL, (void**)list, 0 )) > 0 )
                while ( --i >= 0 )
                    tail = MenuData2FreeStorage( &FeelSyntax, tail, list[i]);
            free( list );
        }
    /* mouse bindings : */
    for( i = 0 ; i < MAX_MOUSE_BUTTONS+1 ; i++ )
    {
        char btn_id[2] ;
        btn_id[0] = '0'+i ;
        btn_id[1] = '\0' ;
        tail = Contexts2FreeStorage( &FeelSyntax, tail, btn_id, &(config->feel->mouse[i]), FEEL_Mouse_ID );
    }

    /* keyboard bindings : */
    if( config->feel->keyboard )
        if( config->feel->keyboard->items_num > 0 )
        {
            ASHashableValue  *keys;
            ASInputContexts **contexts;
            unsigned int items_num = config->feel->keyboard->items_num ;

            keys = safecalloc( items_num, sizeof(ASHashableValue) );
            contexts = safecalloc( items_num, sizeof(ASInputContexts*) );
            items_num = sort_hash_items( config->feel->keyboard, keys, (void**)contexts, 0 );
            for( i = 0 ; i < items_num ; i++ )
            {
                KeySym keysym = (KeySym)keys[i];
                tail = Contexts2FreeStorage( &FeelSyntax, tail, XKeysymToString(keysym), contexts[i], FEEL_Key_ID );
            }
        }

    /* writing config into the file */
	WriteConfig (ConfigWriter, Storage, CDT_Filename, (void **) &filename, flags);
	DestroyFreeStorage (&Storage);
    DestroyConfig (ConfigWriter);

	if (Storage)
  	{
    	fprintf (stderr,
	  		     "\n%s:Config Writing warning: Not all Free Storage discarded! Trying again...",
	      		 myname);
    	DestroyFreeStorage (&Storage);
  		fprintf (stderr, (Storage != NULL) ? " failed." : " success.");
    }
	return 0;
}
Esempio n. 15
0
void myback_parse (char *tline, FILE * fd, char **myname, int *mylook)
{
	FilePtrAndData fpd;
	ConfigDef *ConfigReader;
	MyBackgroundConfig *back_config = NULL;
	FreeStorageElem *Storage = NULL, *more_stuff = NULL;
	MyLook *look = (MyLook *) mylook;
	MyBackground *myback = NULL;
	ConfigData cd;

	if (look == NULL)
		look = get_screen_look (NULL);

	fpd.fp = fd;
	fpd.data = safemalloc (12 + 1 + strlen (tline) + 1 + 1);
	sprintf (fpd.data, "MyBackground %s\n", tline);
	LOCAL_DEBUG_OUT ("fd(%p)->tline(\"%s\")->fpd.data(\"%s\")", fd, tline,
									 fpd.data);
	cd.fileptranddata = &fpd;
	ConfigReader =
			InitConfigReader ((char *)myname, &MyBackgroundSyntax,
												CDT_FilePtrAndData, cd, NULL);
	free (fpd.data);

	if (!ConfigReader)
		return;

	PrintConfigReader (ConfigReader);
	ParseConfig (ConfigReader, &Storage);

	/* getting rid of all the crap first */
	StorageCleanUp (&Storage, &more_stuff, CF_DISABLED_OPTION);
	DestroyFreeStorage (&more_stuff);

	back_config = ParseMyBackgroundOptions (Storage, (char *)myname);

	DestroyConfig (ConfigReader);
	DestroyFreeStorage (&Storage);

	if (back_config == NULL)
		return;

	/* now we have to turn MyBackgroundConfig into MyBackground structure : */
	myback = create_myback (back_config->name);

	if (get_flags (back_config->flags, BGFLAG_FILE))
		myback->type = MB_BackImage;
	else if (get_flags (back_config->flags, BGFLAG_MYSTYLE))
		myback->type = MB_BackMyStyle;
	else
		myback->type = MB_BackCmd;

	myback->data = back_config->data;
	back_config->data = NULL;
	if (get_flags (back_config->flags, BGFLAG_CUT))
		myback->cut = back_config->cut;
	if (get_flags (back_config->flags, BGFLAG_SCALE)) {
		myback->scale = back_config->scale;
		if (!get_flags (back_config->scale.flags, WidthValue))
			myback->scale.width = get_screen_width (NULL);
		if (!get_flags (back_config->scale.flags, HeightValue))
			myback->scale.height = get_screen_height (NULL);
		set_flags (myback->scale.flags, WidthValue | HeightValue);
	}

	myback->tint = TINT_LEAVE_SAME;
	if (get_flags (back_config->flags, BGFLAG_TINT) && back_config->tint)
		parse_argb_color (back_config->tint, &(myback->tint));
	myback->pad_color = ARGB32_Black;
	if (get_flags (back_config->flags, BGFLAG_PAD) && back_config->pad)
		parse_argb_color (back_config->pad, &(myback->pad_color));

	myback->align_flags = NO_ALIGN;
	if (get_flags (back_config->flags, BGFLAG_PAD_HOR)) {
		if (get_flags (back_config->flags, BGFLAG_ALIGN_RIGHT))
			myback->align_flags = ALIGN_RIGHT;
		else if (get_flags (back_config->flags, BGFLAG_ALIGN_CENTER))
			myback->align_flags = ALIGN_HCENTER;
		else
			myback->align_flags = ALIGN_LEFT;
	}
	if (get_flags (back_config->flags, BGFLAG_PAD_VERT)) {
		if (get_flags (back_config->flags, BGFLAG_ALIGN_BOTTOM))
			myback->align_flags |= ALIGN_BOTTOM;
		else if (get_flags (back_config->flags, BGFLAG_ALIGN_CENTER))
			myback->align_flags |= ALIGN_VCENTER;
		else
			myback->align_flags = ALIGN_TOP;
	}
	LOCAL_DEBUG_OUT ("myback added: name(\"%s\")->type(%d)->data(\"%s\")",
									 myback->name, myback->type, myback->data);
	add_myback (look, myback);

	/* final cleanup : */
	DestroyMyBackgroundConfig (&back_config);
}
Esempio n. 16
0
WharfConfig *ParseWharfOptions (const char *filename, char *myname)
{
	ConfigData cd;
	ConfigDef *ConfigReader;
	WharfConfig *config = CreateWharfConfig ();
	FreeStorageElem *Storage = NULL, *pCurr;
	ConfigItem item;
	TermDef *folder_term = func2fterm (F_Folder, False);

	cd.filename = filename;
	ConfigReader =
			InitConfigReader (myname, &WharfSyntax, CDT_Filename, cd,
												NULL /*WharfSpecialFunc */ );
	if (!ConfigReader)
		return config;

	folder_term->sub_syntax = &WharfSyntax;

	item.memory = NULL;
	PrintConfigReader (ConfigReader);
	ParseConfig (ConfigReader, &Storage);

	/* getting rid of all the crap first */
	StorageCleanUp (&Storage, &(config->more_stuff), CF_DISABLED_OPTION);
	config->balloon_conf =
			Process_balloonOptions (Storage, NULL, BALLOON_ID_START);
	config->style_defs = free_storage2MyStyleDefinitionsList (Storage);

	for (pCurr = Storage; pCurr; pCurr = pCurr->next) {
		if (pCurr->term == NULL)
			continue;
		if (ReadFlagItem
				(&(config->set_flags), &(config->flags), pCurr, WharfFlags)) {
			continue;
		}
		if (!ReadConfigItem (&item, pCurr))
			continue;
		switch (pCurr->term->id) {
		case WHARF_Wharf_ID:
			item.ok_to_free = 1;
			ParseWharfFolder (&pCurr, &(config->root_folder));
			break;
		case WHARF_Geometry_ID:
			set_flags (config->set_flags, WHARF_GEOMETRY);
			config->geometry = item.data.geometry;
			break;
		case WHARF_Rows_ID:
			set_flags (config->set_flags, WHARF_ROWS);
			config->rows = item.data.integer;
			break;
		case WHARF_Columns_ID:
			set_flags (config->set_flags, WHARF_COLUMNS);
			clear_flags (config->set_flags, WHARF_ROWS);
			config->columns = item.data.integer;
			break;
		case WHARF_WithdrawStyle_ID:
			set_flags (config->set_flags, WHARF_WITHDRAW_STYLE);
			config->withdraw_style = item.data.integer;
			break;
		case WHARF_ForceSize_ID:
			set_flags (config->set_flags, WHARF_FORCE_SIZE);
			config->force_size = item.data.geometry;
			/* errorneous value check */
			if (!(config->force_size.flags & WidthValue))
				config->force_size.width = 64;
			if (!(config->force_size.flags & HeightValue))
				config->force_size.height = 64;
			config->force_size.flags = WidthValue | HeightValue;
			break;
		case WHARF_TextureType_ID:
			set_flags (config->set_flags, WHARF_TEXTURE_TYPE);
			config->texture_type = item.data.integer;
			break;
		case WHARF_BgColor_ID:
			set_string_value (&(config->bg_color), item.data.string,
												&(config->set_flags), WHARF_BG_COLOR);
			break;
		case WHARF_TextureColor_ID:
			set_string_value (&(config->texture_color), item.data.string,
												&(config->set_flags), WHARF_TEXTURE_COLOR);
			break;
		case WHARF_Pixmap_ID:
			set_string_value (&(config->pixmap), item.data.string,
												&(config->set_flags), WHARF_PIXMAP);
			break;
		case WHARF_AnimateStepsMain_ID:
			set_flags (config->set_flags, WHARF_ANIMATE_STEPS_MAIN);
			config->animate_steps_main = item.data.integer;
			break;
		case WHARF_AnimateSteps_ID:
			set_flags (config->set_flags, WHARF_ANIMATE_STEPS);
			config->animate_steps = item.data.integer;
			break;
		case WHARF_AnimateDelay_ID:
			set_flags (config->set_flags, WHARF_ANIMATE_DELAY);
			config->animate_delay = item.data.integer;
			break;
		case WHARF_Sound_ID:
			if (pCurr->sub == NULL) {
				if (pCurr->argc > 0) {
					register char *sound = mystrdup (pCurr->argv[pCurr->argc - 1]);

					set_string_value (&(config->sounds[WHEV_PUSH]), sound,
														&(config->set_flags), WHARF_SOUND);
				}
			} else if (pCurr->sub->argc > 0) {
				register char *sound = mystrdup (pCurr->sub->argv[0]);

				set_string_value (&
													(config->
													 sounds[WHEV_Id2Code (pCurr->sub->term->id)]),
													sound, &(config->set_flags), WHARF_SOUND);
			}
			item.ok_to_free = 1;
			break;
			ASCF_HANDLE_INTEGER_KEYWORD_CASE (WHARF, config, item,
																				LabelLocation);
			ASCF_HANDLE_ALIGN_KEYWORD_CASE (WHARF, config, pCurr, AlignContents);
			ASCF_HANDLE_BEVEL_KEYWORD_CASE (WHARF, config, pCurr, Bevel);
			ASCF_HANDLE_SUBSYNTAX_KEYWORD_CASE (WHARF, config, pCurr, ShowHints,
																					BalloonContents);
			ASCF_HANDLE_INTEGER_KEYWORD_CASE (WHARF, config, item,
																				CompositionMethod);
			ASCF_HANDLE_INTEGER_KEYWORD_CASE (WHARF, config, item, FolderOffset);
			ASCF_HANDLE_INTEGER_KEYWORD_CASE (WHARF, config, item,
																				OrthogonalFolderOffset);
		default:
			if (pCurr->term->type != TT_FLAG)
				item.ok_to_free = 1;
		}
	}
	if (get_flags (config->set_flags, WHARF_Bevel))
		clear_flags (config->flags, WHARF_NO_BORDER);


	ReadConfigItem (&item, NULL);
	SHOW_CHECKPOINT;
	DestroyConfig (ConfigReader);
	SHOW_CHECKPOINT;
	DestroyFreeStorage (&Storage);
	SHOW_CHECKPOINT;
	return config;
}
Esempio n. 17
0
int main(int argc, char** argv)
{
    signal(SIGINT, IntHandler);

    Server serv;

    // Initialize the server
    InitConfig(&serv.conf, argv[1], argc, argv);
    
    if(!serv.conf.name) {
        fprintf(stderr, "Script doesn't specify a server name.\n");
        return 1;
    }

    if(!serv.conf.port) {
        fprintf(stderr, "Script doesn't specify a port.\n");
        return 1;
    }

	printf("Successfully configured server.\n"
		"Name: %s\n"
		"Port: %s\n"
		"Num Threads: %d\n"
		"Cycles Per Loop: %d\n"
		"Num Routes: %d\n", serv.conf.name, serv.conf.port, serv.conf.numThreads, serv.conf.cyclesPerLoop, sb_count(serv.conf.routes));

    InitList(&serv.clientQueue, sizeof(Sock));
    InitList(&serv.requestQueue, sizeof(ClientRequest));

    cnd_init(&serv.updateLoop);
    cnd_init(&serv.newConn);

    // The loop thread is responsible for initializing LoopData

    thrd_t loopThread, connThread;

    thrd_create(&loopThread, MainLoop, &serv);
    thrd_create(&connThread, ConnLoop, &serv);

    // Initialize winsock and listen for clients
    WSADATA wsaData;
    SOCKET listenSocket;

    int iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
    if(iResult != 0) {
        fprintf(stderr, "WSAStartup failed: %d\n", iResult);
        return 1;
    }

    struct addrinfo hints;
    
    ZeroMemory(&hints, sizeof(hints));

    hints.ai_family = AF_INET;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_protocol = IPPROTO_TCP;
    hints.ai_flags = AI_PASSIVE;

    struct addrinfo* result;

    iResult = getaddrinfo(NULL, serv.conf.port, &hints, &result);
    if(iResult != 0) {
        fprintf(stderr, "getaddrinfo failed: %d\n", iResult);
        WSACleanup();
        return 1;
    }
    
    listenSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol);

    if(listenSocket == INVALID_SOCKET) {
        fprintf(stderr, "Error at socket(): %d\n", WSAGetLastError());
        freeaddrinfo(result); 
        WSACleanup();
        return 1;
    }

    freeaddrinfo(result);

    iResult = bind(listenSocket, result->ai_addr, (int)result->ai_addrlen);

    if(iResult == SOCKET_ERROR) {
        fprintf(stderr, "bind failed with error: %d\n", WSAGetLastError());
        closesocket(listenSocket);
        WSACleanup();
        return 1;
    }

    if(listen(listenSocket, SOMAXCONN) == SOCKET_ERROR) {
        fprintf(stderr, "listen failed with error: %d\n", WSAGetLastError());
        closesocket(listenSocket);
        WSACleanup();
        return 1;
    }
	
	while (KeepRunning) {
		SOCKET clientSocket = accept(listenSocket, NULL, NULL);

		if (clientSocket == INVALID_SOCKET) {
			fprintf(stderr, "accept failed: %d\n", WSAGetLastError());
            continue;
		}

		int iMode = 1;
        if (ioctlsocket(clientSocket, FIONBIO, &iMode) == SOCKET_ERROR) {
            fprintf(stderr, "ioctlsocket failed: %d\n", WSAGetLastError());
            continue;
        }

        Sock sock;

        InitSock(&sock, (void*)clientSocket);
        
        ListPushBack(&serv.clientQueue, &sock);

        cnd_signal(&serv.newConn);
	}

    WSACleanup();

    thrd_join(&connThread, NULL);
	thrd_join(&loopThread, NULL);

    cnd_destroy(&serv.newConn);
    cnd_destroy(&serv.updateLoop);

	DestroyList(&serv.requestQueue);
	DestroyList(&serv.clientQueue);

    DestroyConfig(&serv.conf);

	return 0;
}
Esempio n. 18
0
/* returns:
 *		0 on success
 *		1 if data is empty
 *		2 if ConfigWriter cannot be initialized
 *
 */
int
WriteBaseOptions (const char *filename, char *myname, BaseConfig * config,
									unsigned long flags)
{
	ConfigDef *BaseConfigWriter = NULL;
	FreeStorageElem *Storage = NULL, **tail = &Storage;
	ConfigData cd;

	if (config == NULL)
		return 1;
	cd.filename = filename;
	if ((BaseConfigWriter =
			 InitConfigWriter (myname, &BaseSyntax, CDT_Filename, cd)) == NULL)
		return 2;

	CopyFreeStorage (&Storage, config->more_stuff);

	/* building free storage here */

	/* module_path */
	tail =
			String2FreeStorage (&BaseSyntax, tail, config->module_path,
													BASE_MODULE_PATH_ID);

	/* icon_path */
	tail =
			String2FreeStorage (&BaseSyntax, tail, config->icon_path,
													BASE_ICON_PATH_ID);

	/* pixmap_path */
	tail =
			String2FreeStorage (&BaseSyntax, tail, config->pixmap_path,
													BASE_PIXMAP_PATH_ID);

	/* cursor_path */
	tail =
			String2FreeStorage (&BaseSyntax, tail, config->cursor_path,
													BASE_CURSOR_PATH_ID);

	/* sound_path */
	tail =
			String2FreeStorage (&BaseSyntax, tail, config->sound_path,
													BASE_SOUND_PATH_ID);

	/* myname_path */
	tail =
			String2FreeStorage (&BaseSyntax, tail, config->myname_path,
													BASE_MYNAME_PATH_ID);

	/* IconTheme */
	tail =
			String2FreeStorage (&BaseSyntax, tail, config->IconTheme,
													BASE_IconTheme_ID);
	/* IconThemePath */
	tail =
			String2FreeStorage (&BaseSyntax, tail, config->IconThemePath,
													BASE_IconThemePath_ID);
	/* IconThemeFallback */
	tail =
			String2FreeStorage (&BaseSyntax, tail, config->IconThemeFallback,
													BASE_IconThemeFallback_ID);

	/* desktop_size */
	tail =
			Geometry2FreeStorage (&BaseSyntax, tail, &(config->desktop_size),
														BASE_DESKTOP_SIZE_ID);

	/* desktop_scale */
	tail =
			Integer2FreeStorage (&BaseSyntax, tail, NULL, config->desktop_scale,
													 BASE_DESKTOP_SCALE_ID);

	cd.filename = filename;
	/* writing config into the file */
	WriteConfig (BaseConfigWriter, Storage, CDT_Filename, &cd, flags);
	DestroyFreeStorage (&Storage);
	DestroyConfig (BaseConfigWriter);

	return 0;
}
Esempio n. 19
0
/* returns:
 *            0 on success
 *              1 if data is empty
 *              2 if ConfigWriter cannot be initialized
 *
 */
int
WriteWharfOptions (const char *filename, char *myname,
									 WharfConfig * config, unsigned long flags)
{
	ConfigDef *WharfConfigWriter = NULL;
	FreeStorageElem *Storage = NULL, **tail = &Storage;
	TermDef *folder_term = func2fterm (F_Folder, True);
	int i;

	if (config == NULL)
		return 1;

	folder_term->sub_syntax = &WharfSyntax;

	if ((WharfConfigWriter =
			 InitConfigWriter (myname, &WharfSyntax, CDT_Filename,
												 (void *)filename)) == NULL)
		return 2;

	CopyFreeStorage (&Storage, config->more_stuff);

	if (config->style_defs)
		*tail =
				MyStyleDefinitionsList2free_storage (config->style_defs,
																						 &WharfSyntax);

	if (config->balloon_conf)
		tail = balloon2FreeStorage (&WharfSyntax, tail, config->balloon_conf);

	/* building free storage here */
	/* geometry */
	if (get_flags (config->set_flags, WHARF_GEOMETRY))
		tail =
				Geometry2FreeStorage (&WharfSyntax, tail, &(config->geometry),
															WHARF_Geometry_ID);
	if (get_flags (config->set_flags, WHARF_FORCE_SIZE))
		tail =
				Geometry2FreeStorage (&WharfSyntax, tail, &(config->force_size),
															WHARF_ForceSize_ID);
	/* Integer values : */
	/* rows */
	if (get_flags (config->set_flags, WHARF_ROWS))
		tail =
				Integer2FreeStorage (&WharfSyntax, tail, NULL, config->rows,
														 WHARF_Rows_ID);
	/* columns */
	if (get_flags (config->set_flags, WHARF_COLUMNS))
		tail =
				Integer2FreeStorage (&WharfSyntax, tail, NULL, config->columns,
														 WHARF_Columns_ID);
	/* withdraw_style */
	if (get_flags (config->set_flags, WHARF_WITHDRAW_STYLE))
		tail =
				Integer2FreeStorage (&WharfSyntax, tail, NULL,
														 config->withdraw_style,
														 WHARF_WithdrawStyle_ID);
	/* texture_type  */
	if (get_flags (config->set_flags, WHARF_TEXTURE_TYPE))
		tail =
				Integer2FreeStorage (&WharfSyntax, tail, NULL,
														 config->texture_type, WHARF_TextureType_ID);
	/* animate_steps */
	if (get_flags (config->set_flags, WHARF_ANIMATE_STEPS))
		tail =
				Integer2FreeStorage (&WharfSyntax, tail, NULL,
														 config->animate_steps, WHARF_AnimateSteps_ID);
	/* animate_steps_main */
	if (get_flags (config->set_flags, WHARF_ANIMATE_STEPS_MAIN))
		tail =
				Integer2FreeStorage (&WharfSyntax, tail, NULL,
														 config->animate_steps_main,
														 WHARF_AnimateStepsMain_ID);
	/* animate_delay */
	if (get_flags (config->set_flags, WHARF_ANIMATE_DELAY))
		tail =
				Integer2FreeStorage (&WharfSyntax, tail, NULL,
														 config->animate_delay, WHARF_AnimateDelay_ID);


	/* Flags : */
	tail =
			Flags2FreeStorage (&WharfSyntax, tail, WharfFlags, 0xFFFFFFFF,
												 config->set_flags);

	/* StringValues */
	/* bg_color */
	if (get_flags (config->set_flags, WHARF_BG_COLOR))
		tail =
				String2FreeStorage (&WharfSyntax, tail, config->bg_color,
														WHARF_BgColor_ID);

	/* texture_color */
	if (get_flags (config->set_flags, WHARF_TEXTURE_COLOR))
		tail =
				String2FreeStorage (&WharfSyntax, tail, config->texture_color,
														WHARF_TextureColor_ID);

	/* pixmap name */
	if (get_flags (config->set_flags, WHARF_PIXMAP))
		tail =
				String2FreeStorage (&WharfSyntax, tail, config->pixmap,
														WHARF_Pixmap_ID);

	/* sound */
	if (get_flags (config->set_flags, WHARF_SOUND))
		for (i = 0; i < WHEV_MAX_EVENTS; i++)
			tail =
					String2FreeStorage (&WharfSyntax, tail, config->sounds[i],
															WHARF_Sound_ID);

	/* Writing Wharf Entries : */
	if (config->root_folder)
		tail =
				WharfFolder2FreeStorage (&WharfSyntax, tail, config->root_folder,
																 True);

	/* writing config into the file */
	WriteConfig (WharfConfigWriter, Storage, CDT_Filename,
							 (void **)&filename, flags);
	DestroyFreeStorage (&Storage);
	DestroyConfig (WharfConfigWriter);

	if (Storage) {
		fprintf (stderr,
						 "\n%s:Config Writing warning: Not all Free Storage discarded! Trying again...",
						 myname);
		DestroyFreeStorage (&Storage);
		fprintf (stderr, (Storage != NULL) ? " failed." : " success.");
	}
	return 0;
}
Esempio n. 20
0
FeelConfig *
ParseFeelOptions (const char *filename, char *myname)
{
    ConfigData cd ; 
	ConfigDef *ConfigReader;
    FeelConfig *config = CreateFeelConfig ();
	FreeStorageElem *Storage = NULL, *pCurr;
    ConfigItem item;

	cd.filename = filename ; 
	ConfigReader = InitConfigReader (myname, &FeelSyntax, CDT_Filename, cd, BindingSpecialFunc);
	if (!ConfigReader)
  		return config;

    item.memory = NULL;
	PrintConfigReader (ConfigReader);
	ParseConfig (ConfigReader, &Storage);

	/* getting rid of all the crap first */
    StorageCleanUp (&Storage, &(config->more_stuff), CF_DISABLED_OPTION);

	for (pCurr = Storage; pCurr; pCurr = pCurr->next)
  	{
  	    if (pCurr->term == NULL)
			continue;
        if (ReadFlagItem (NULL, &(config->feel->flags), pCurr, FeelFlagsXref))
            continue;
        if (!ReadConfigItem (&item, pCurr))
			continue;
        switch (pCurr->term->id)
		{
            case FEEL_ClickTime_ID          :
                config->feel->ClickTime = item.data.integer;
                set_flags (config->feel->set_val_flags, FEEL_ClickTime);
                break ;
            case FEEL_OpaqueMove_ID         :
                config->feel->OpaqueMove = item.data.integer;
                set_flags (config->feel->set_val_flags, FEEL_OpaqueMove);
                break ;
            case FEEL_OpaqueResize_ID       :
                config->feel->OpaqueResize = item.data.integer;
                set_flags (config->feel->set_val_flags, FEEL_OpaqueResize);
                break ;
            case FEEL_AutoRaise_ID          :
                config->feel->AutoRaiseDelay = item.data.integer;
                set_flags (config->feel->set_val_flags, FEEL_AutoRaise);
                break ;
            case FEEL_AutoReverse_ID        :
                config->feel->AutoReverse = item.data.integer;
                set_flags (config->feel->set_val_flags, FEEL_AutoReverse);
                break ;
            case FEEL_ShadeAnimationSteps_ID :
                config->feel->ShadeAnimationSteps = item.data.integer;
                set_flags (config->feel->set_val_flags, FEEL_ShadeAnimationSteps);
                break ;

            case FEEL_XorValue_ID           :
                config->feel->XorValue = item.data.integer;
                set_flags (config->feel->set_val_flags, FEEL_XorValue);
                break ;
            case FEEL_Xzap_ID               :
                config->feel->Xzap = item.data.integer;
                set_flags (config->feel->set_val_flags, FEEL_Xzap);
                break ;
            case FEEL_Yzap_ID               :
                config->feel->Yzap = item.data.integer;
                set_flags (config->feel->set_val_flags, FEEL_Yzap);
                break ;

            case FEEL_Cursor_ID             :                   /* TT_INTEGER */
				/* TODO: backport from as-devel : */
                /*if ( item.index  > 0 && item.index < MAX_CURSORS)
                    config->feel->standard_cursors[item.index] = item.data.integer ;
				 */
                break ;
            case FEEL_CustomCursor_ID       :                   /* TT_BUTTON  */
				/* TODO: backport from as-devel : */
				/*
					if ( item.index  > 0 && item.index < MAX_CURSORS)
                	{
                    	if( config->feel->custom_cursors[item.index] )
                        	destroy_ascursor( &(config->feel->custom_cursors[item.index]));
                    	config->feel->custom_cursors[item.index] = item.data.cursor ;
                	}
				 */
                break ;

            case FEEL_ClickToRaise_ID       :                   /* TT_BITLIST */
                config->feel->RaiseButtons = item.data.integer ;
                set_flags (config->feel->set_val_flags, FEEL_ClickToRaise);
                set_flags (config->feel->set_flags, ClickToRaise);
				set_flags (config->feel->flags, ClickToRaise);
                break ;

            case FEEL_EdgeScroll_ID         :                   /* TT_INTARRAY*/
				item.ok_to_free = 1;
                if( item.data.int_array.size > 0 )
                {
                    config->feel->EdgeScrollX = item.data.int_array.array[0];
                    if( item.data.int_array.size > 1 )
                        config->feel->EdgeScrollY = item.data.int_array.array[1];
                    set_flags (config->feel->set_val_flags, FEEL_EdgeScroll );
                }
                break ;
            case FEEL_EdgeResistance_ID     :                   /* TT_INTARRAY*/
				item.ok_to_free = 1;
                if( item.data.int_array.size > 0 )
                {
                    config->feel->EdgeResistanceScroll = item.data.int_array.array[0];
                    if( item.data.int_array.size > 1 )
                        config->feel->EdgeResistanceMove = item.data.int_array.array[1];
                    set_flags (config->feel->set_val_flags, FEEL_EdgeResistance );
                }
                break ;

            case FEEL_Popup_ID              :
				/* TODO: backport from as-devel : */
                /* FreeStorage2MenuData( pCurr, &item, config->feel->Popups ); */
                break ;
            case FEEL_Function_ID           :
                FreeStorage2ComplexFunction( pCurr, &item, config->feel->ComplexFunctions );
                break ;
            case FEEL_Mouse_ID              :
                if( item.data.binding.sym )
                    if( isdigit( (int)item.data.binding.sym[0] ) && pCurr->sub )
                    {
                        int button_num = item.data.binding.sym[0] - '0' ;
                        if( button_num >= 0 && button_num <= MAX_MOUSE_BUTTONS &&
                            pCurr->sub->term->type == TT_FUNCTION )
                        {
                            ConfigItem func_item ;
                            func_item.memory = NULL ;
                            if( ReadConfigItem( &func_item, pCurr->sub ) )
							{
								MouseButton *tmp = safecalloc( 1, sizeof(MouseButton) );
								tmp->Button = button_num ;
								tmp->Modifier = item.data.binding.mods ;
								tmp->Context = item.data.binding.context ;
								tmp->fdata = func_item.data.function ;
								func_item.data.function = NULL ;
								tmp->NextButton = config->feel->MouseButtonRoot ;
								config->feel->MouseButtonRoot = tmp ;
							}
                            if( func_item.data.function )
                            {
                                func_item.ok_to_free = 1;
                                ReadConfigItem( &func_item, NULL );
                            }
                        }
                    }
                item.ok_to_free = 1;
                break ;
            case FEEL_Key_ID                :
                ParseKeyBinding( &item, pCurr->sub, &(config->feel->FuncKeyRoot) );
                break ;
          default:
				item.ok_to_free = 1;
		}
    }
	ReadConfigItem (&item, NULL);

	DestroyConfig (ConfigReader);
	DestroyFreeStorage (&Storage);
	return config;
}