Ejemplo n.º 1
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;
}
Ejemplo n.º 2
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;
}