void pz_set_float_setting(PzConfig *conf, unsigned int sid, double value)
{
	PzConfItem *setting, *last_setting;

	if ((setting = find_setting (conf, sid))) {
		if (setting->type == PZ_SETTING_FLOAT) {
			setting->fval = value;
			return;
		}
	}
	pz_unset_setting (conf, sid);
	
	if (!conf->settings) {
		last_setting = conf->settings = malloc (sizeof(PzConfItem));
	} else {
		last_setting = conf->settings;
		while (last_setting->next) last_setting = last_setting->next;
		last_setting->next = malloc (sizeof(PzConfItem));
		last_setting = last_setting->next;
	}
	last_setting->sid = sid;
	last_setting->type = PZ_SETTING_FLOAT;
	last_setting->fval = value;
	last_setting->next = 0;
}
static void set_int_setting(PzConfig *conf, unsigned int sid, int value, int rsvd)
{
	PzConfItem *setting, *last_setting;

	if ((rsvd && (sid < 0xf0000000)) || (!rsvd && (sid >= 0xf0000000)))
		return;

	if ((setting = find_setting (conf, sid))) {
		if (setting->type == PZ_SETTING_INT) {
			setting->ival = value;
			return;
		}
	}
	pz_unset_setting (conf, sid);
	
	if (!conf->settings) {
		last_setting = conf->settings = malloc (sizeof(PzConfItem));
	} else {
		last_setting = conf->settings;
		while (last_setting->next) last_setting = last_setting->next;
		last_setting->next = malloc (sizeof(PzConfItem));
		last_setting = last_setting->next;
	}
	last_setting->sid = sid;
	last_setting->type = PZ_SETTING_INT;
	last_setting->ival = value;
	last_setting->next = 0;
}
static void set_string_setting(PzConfig *conf, unsigned int sid, const char *value, int rsvd)
{
	PzConfItem *setting, *last_setting;

	if ((rsvd && (sid < 0xf0000000)) || (!rsvd && (sid >= 0xf0000000)))
		return;

	if ((setting = find_setting (conf, sid))) {
		if (setting->type == PZ_SETTING_STRING) {
			free (setting->strval);
			setting->strval = strdup (value);
			return;
		}
	}
	pz_unset_setting (conf, sid);
	
	if (!conf->settings) {
		last_setting = conf->settings = malloc (sizeof(PzConfItem));
	} else {
		last_setting = conf->settings;
		while (last_setting->next) last_setting = last_setting->next;
		last_setting->next = malloc (sizeof(PzConfItem));
		last_setting = last_setting->next;
	}
	last_setting->sid = sid;
	last_setting->type = PZ_SETTING_STRING;
	last_setting->strval = strdup (value);
	last_setting->next = 0;
}
Example #4
0
		virtual i_setting& find_setting(const i_string& aSettingCategory, const i_string& aSettingName)
		{
			setting_by_name_list::iterator iter = iSettingsByName.find(std::pair<string, string>(aSettingCategory, aSettingName));
			if (iter == iSettingsByName.end())
				throw setting_not_found();
			return find_setting(iter->second);
		}
void pz_set_blob_setting(PzConfig *conf, unsigned int sid, const void *value, int len)
{
	PzConfItem *setting, *last_setting;

	if ((setting = find_setting (conf, sid))) {
		if (setting->type == PZ_SETTING_BLOB) {
			free (setting->blobval);
			setting->blobval = malloc (len);
                        memcpy (setting->blobval, value, len);
                        setting->bloblen = len;
			return;
		}
	}
	pz_unset_setting (conf, sid);
	
	if (!conf->settings) {
		last_setting = conf->settings = malloc (sizeof(PzConfItem));
	} else {
		last_setting = conf->settings;
		while (last_setting->next) last_setting = last_setting->next;
		last_setting->next = malloc (sizeof(PzConfItem));
		last_setting = last_setting->next;
	}
	last_setting->sid = sid;
	last_setting->type = PZ_SETTING_BLOB;
	last_setting->blobval = malloc (len);
        memcpy (last_setting->blobval, value, len);
        last_setting->bloblen = len;
	last_setting->next = 0;
}
void pz_set_ilist_setting(PzConfig *conf, unsigned int sid, int *vals, int nvals)
{
	PzConfItem *setting, *last_setting;

	if ((setting = find_setting (conf, sid))) {
		if (setting->type == PZ_SETTING_ILIST) {
			free (setting->ivals);
			setting->ivals = calloc (nvals, sizeof(int));
			memcpy (setting->ivals, vals, nvals * sizeof(int));
			setting->nivals = nvals;
			return;
		}
	}
	pz_unset_setting (conf, sid);
	
	if (!conf->settings) {
		last_setting = conf->settings = malloc (sizeof(PzConfItem));
	} else {
		last_setting = conf->settings;
		while (last_setting->next) last_setting = last_setting->next;
		last_setting->next = malloc (sizeof(PzConfItem));
		last_setting = last_setting->next;
	}
	last_setting->sid = sid;
	last_setting->type = PZ_SETTING_ILIST;
	last_setting->ivals = calloc (nvals, sizeof(int));
	memcpy (last_setting->ivals, vals, nvals * sizeof(int));
	last_setting->nivals = nvals;
	last_setting->next = 0;
}
Example #7
0
bool quick_screen_f3(int button_enter)
{
    struct gui_quickscreen qs;
    qs.items[QUICKSCREEN_LEFT] =
                    find_setting(&global_settings.scrollbar, NULL);
    qs.items[QUICKSCREEN_RIGHT] =
                    find_setting(&global_settings.statusbar, NULL);
    qs.items[QUICKSCREEN_BOTTOM] =
                    find_setting(&global_settings.flip_display, NULL);
    qs.callback = NULL;
    if (gui_syncquickscreen_run(&qs, button_enter))
    {
        settings_save();
        settings_apply(false);
    }
    return(0);
}
Example #8
0
bool quick_screen_quick(int button_enter)
{
    struct gui_quickscreen qs;
    bool oldshuffle = global_settings.playlist_shuffle;
    int oldrepeat = global_settings.repeat_mode;
    bool usb = false;

    if (global_settings.shortcuts_replaces_qs)
        return do_shortcut_menu(NULL);

    qs.items[QUICKSCREEN_TOP] =
            get_setting(global_settings.qs_items[QUICKSCREEN_TOP], NULL);
    qs.items[QUICKSCREEN_LEFT] =
            get_setting(global_settings.qs_items[QUICKSCREEN_LEFT],
                        find_setting(&global_settings.playlist_shuffle, NULL));
    qs.items[QUICKSCREEN_RIGHT] =
            get_setting(global_settings.qs_items[QUICKSCREEN_RIGHT],
                        find_setting(&global_settings.repeat_mode, NULL));
    qs.items[QUICKSCREEN_BOTTOM] =
            get_setting(global_settings.qs_items[QUICKSCREEN_BOTTOM], NULL);

    qs.callback = NULL;
    if (gui_syncquickscreen_run(&qs, button_enter, &usb))
    {
        settings_save();
        settings_apply(false);
        /* make sure repeat/shuffle/any other nasty ones get updated */
        if ( oldrepeat != global_settings.repeat_mode &&
             (audio_status() & AUDIO_STATUS_PLAY) )
        {
            audio_flush_and_reload_tracks();
        }
        if (oldshuffle != global_settings.playlist_shuffle
            && audio_status() & AUDIO_STATUS_PLAY)
        {
            replaygain_update();
            if (global_settings.playlist_shuffle)
                playlist_randomise(NULL, current_tick, true);
            else
                playlist_sort(NULL, true);
        }
    }
    return usb;
}
Example #9
0
bool quick_screen_quick(int button_enter)
{
    struct gui_quickscreen qs;
    bool oldshuffle = global_settings.playlist_shuffle;
    int oldrepeat = global_settings.repeat_mode;

    qs.items[QUICKSCREEN_TOP] =
            get_setting(global_settings.qs_items[QUICKSCREEN_TOP],
                        find_setting(&global_settings.party_mode, NULL));
    qs.items[QUICKSCREEN_LEFT] =
            get_setting(global_settings.qs_items[QUICKSCREEN_LEFT],
                        find_setting(&global_settings.playlist_shuffle, NULL));
    qs.items[QUICKSCREEN_RIGHT] =
            get_setting(global_settings.qs_items[QUICKSCREEN_RIGHT],
                        find_setting(&global_settings.repeat_mode, NULL));
    qs.items[QUICKSCREEN_BOTTOM] =
            get_setting(global_settings.qs_items[QUICKSCREEN_BOTTOM],
                        find_setting(&global_settings.dirfilter, NULL));

    qs.callback = NULL;
    if (gui_syncquickscreen_run(&qs, button_enter))
    {
        settings_save();
        settings_apply(false);
        /* make sure repeat/shuffle/any other nasty ones get updated */
        if ( oldrepeat != global_settings.repeat_mode &&
             (audio_status() & AUDIO_STATUS_PLAY) )
        {
            audio_flush_and_reload_tracks();
        }
        if (oldshuffle != global_settings.playlist_shuffle
            && audio_status() & AUDIO_STATUS_PLAY)
        {
#if CONFIG_CODEC == SWCODEC
            dsp_set_replaygain();
#endif
            if (global_settings.playlist_shuffle)
                playlist_randomise(NULL, current_tick, true);
            else
                playlist_sort(NULL, true);
        }
    }
    return(0);
}
Example #10
0
bool quick_screen_f3(int button_enter)
{
    struct gui_quickscreen qs;
    bool usb = false;
    qs.items[QUICKSCREEN_TOP] = NULL;
    qs.items[QUICKSCREEN_LEFT] =
                    find_setting(&global_settings.scrollbar, NULL);
    qs.items[QUICKSCREEN_RIGHT] =
                    find_setting(&global_settings.statusbar, NULL);
    qs.items[QUICKSCREEN_BOTTOM] =
#ifdef HAVE_LCD_FLIP
                    find_setting(&global_settings.flip_display, NULL);
#else
                    NULL;
#endif
    qs.callback = NULL;
    if (gui_syncquickscreen_run(&qs, button_enter, &usb))
    {
        settings_save();
        settings_apply(false);
    }
    return usb;
}
Example #11
0
void set_int_setting(short id, int value)
{
	setting_st *last_setting = find_setting(id);
	setting_st *setting;

	if (last_setting == NULL ||
	    (last_setting != NULL && last_setting-> id != id)) {
		/* doesn't already exist, and last node isn't one we want to change */
		setting = new_setting(SETTING_INT, id, (void *)&value);
		if (last_setting == NULL) { /* first node */
			settings_root = setting;
		} else {
			last_setting->next = setting;
		}
	} else if (last_setting->id == id) {
		*(int *)(last_setting->value) = value;
	}
}
Example #12
0
void set_string_setting(short id, char *value)
{
	setting_st *last_setting = find_setting(id);
	setting_st *setting;

	if (last_setting == NULL ||
	    (last_setting != NULL && last_setting->id != id)) {
		/* doesn't already exist, and last node isn't one we want to change */
		setting = new_setting(SETTING_STRING, id, (void *)value);
		if (last_setting == NULL) { /* first node */
			settings_root = setting;
		} else {
			last_setting->next = setting;
		}
	} else if (last_setting->id == id) {
		free(last_setting->value);
		(last_setting->value) = strdup(value);
	}
}
Example #13
0
void pz_set_slist_setting(PzConfig *conf, unsigned int sid, char **vals, int nvals)
{
	PzConfItem *setting, *last_setting;
	int i;

	if ((setting = find_setting (conf, sid))) {
		if (setting->type == PZ_SETTING_SLIST) {
			for (i = 0; i < setting->nstrvals; i++) {
				free (setting->strvals[i]);
			}
			free (setting->strvals);
			setting->strvals = calloc (nvals + 1, sizeof(char*));
			setting->nstrvals = nvals;
			for (i = 0; i < nvals; i++) {
				setting->strvals[i] = strdup (vals[i]);
			}
			return;
		}
	}
	pz_unset_setting (conf, sid);
	
	if (!conf->settings) {
		last_setting = conf->settings = malloc (sizeof(PzConfItem));
	} else {
		last_setting = conf->settings;
		while (last_setting->next) last_setting = last_setting->next;
		last_setting->next = malloc (sizeof(PzConfItem));
		last_setting = last_setting->next;
	}
	last_setting->sid = sid;
	last_setting->type = PZ_SETTING_SLIST;
	last_setting->strvals = calloc (nvals + 1, sizeof(char*));
	last_setting->nstrvals = nvals;
	for (i = 0; i < nvals; i++) {
		last_setting->strvals[i] = strdup (vals[i]);
	}
	last_setting->next = 0;
}
Example #14
0
void ec_set(char *from, char *to)
{
	Chan	*chan;
	UniVar	*varval;
	char	num[20];
	char	*src;
	int	which,uaccess;

	src = ec_src;
	while(*src && *src != ')')
		src++;
	if (*src != ')')
		return;
	*(src++) = 0;

	if ((which = find_setting(ec_src)) >= 0)
	{
		if (which >= CHANSET_SIZE)
		{
			uaccess = get_useraccess(from,ANY_CHANNEL);
			varval = &current->setting[which];
		}
		else
		if ((chan = find_channel_ny(to)))
		{
			uaccess = get_useraccess(from,to);
			varval = &chan->setting[which];
		}
		else
		{
			nobo_strcpy("(unknown channel)");
			return;
		}
		if (uaccess < VarName[which].uaccess)
			return;

		if (IsProc(which))
			varval = varval->proc_var;

		if (IsChar(which))
		{
			num[0] = varval->char_var;
			num[1] = 0;
			nobo_strcpy(num);
		}
		else
		if (IsInt(which))
		{
			sprintf(num,"%i",varval->int_var);
			nobo_strcpy(num);
		}
		else
		if (IsTog(which))
		{
			nobo_strcpy((varval->int_var) ? "on" : "off");
		}
		else
		if (IsStr(which))
		{
			nobo_strcpy(nullstr(varval->str_var));
		}
	}
	else
	{
		nobo_strcpy("(unknown setting)");
	}
	ec_src = src;
}
Example #15
0
/* Get the touched action.
 * egde_offset is a percentage value for the position of the touch
 * inside the bar for regions which arnt WPS_TOUCHREGION_ACTION type.
 */
int skin_get_touchaction(struct wps_data *data, int* edge_offset,
                         struct touchregion **retregion)
{
    int returncode = ACTION_NONE;
    short x,y;
    short vx, vy;
    int type = action_get_touchscreen_press(&x, &y);
    struct skin_viewport *wvp;
    struct touchregion *r, *temp = NULL;
    char* skin_buffer = get_skin_buffer(data);
    bool repeated = (type == BUTTON_REPEAT);
    bool released = (type == BUTTON_REL);
    bool pressed = (type == BUTTON_TOUCHSCREEN);
    struct skin_token_list *regions = SKINOFFSETTOPTR(skin_buffer, data->touchregions);
    bool needs_repeat;

    while (regions)
    {
        struct wps_token *token = SKINOFFSETTOPTR(skin_buffer, regions->token);
        r = SKINOFFSETTOPTR(skin_buffer, token->value.data);
        wvp = SKINOFFSETTOPTR(skin_buffer, r->wvp);
        /* make sure this region's viewport is visible */
        if (wvp->hidden_flags&VP_DRAW_HIDDEN)
        {
            regions = SKINOFFSETTOPTR(skin_buffer, regions->next);
            continue;
        }
        if (data->touchscreen_locked && 
            (r->action != ACTION_TOUCH_SOFTLOCK && !r->allow_while_locked))
        {
            regions = SKINOFFSETTOPTR(skin_buffer, regions->next);
            continue;
        }
        needs_repeat = r->press_length != PRESS;
        /* check if it's inside this viewport */
        if (viewport_point_within_vp(&(wvp->vp), x, y))
        {   /* reposition the touch inside the viewport since touchregions
             * are relative to a preceding viewport */
            vx = x - wvp->vp.x;
            vy = y - wvp->vp.y;
            /* now see if the point is inside this region */
            if (vx >= r->x && vx < r->x+r->width &&
                vy >= r->y && vy < r->y+r->height)
            {
                /* reposition the touch within the area */
                vx -= r->x;
                vy -= r->y;

                switch(r->action)
                {
                    case ACTION_TOUCH_SCROLLBAR:
                    case ACTION_TOUCH_VOLUME:
                    case ACTION_TOUCH_SETTING:
                        if (edge_offset)
                        {
                            struct progressbar *bar =
                                    SKINOFFSETTOPTR(skin_buffer, r->bar);
                            if(r->width > r->height)
                                *edge_offset = vx*100/r->width;
                            else
                                *edge_offset = vy*100/r->height;
                            if (r->reverse_bar || (bar && bar->invert_fill_direction))
                                *edge_offset = 100 - *edge_offset;
                        }
                        temp = r;
                        returncode = r->action;
                        r->last_press = current_tick;
                        break;
                    default:
                        if (r->armed && ((repeated && needs_repeat) || 
                            (released && !needs_repeat)))
                        {
                            returncode = r->action;
                            temp = r;
                        }
                        if (pressed)
                        {
                            r->armed = true;
                            r->last_press = current_tick;
                        }
                        break;
                }
            }
        }
        regions = SKINOFFSETTOPTR(skin_buffer, regions->next);
    }

    /* On release, all regions are disarmed. */
    if (released)
        skin_disarm_touchregions(data);
    if (retregion && temp)
        *retregion = temp;
    if (temp && temp->press_length == LONG_PRESS)
        temp->armed = false;
    
    if (returncode != ACTION_NONE)
    {
        if (global_settings.party_mode)
        {
            switch (returncode)
            {
                case ACTION_WPS_PLAY:
                case ACTION_WPS_SKIPPREV:
                case ACTION_WPS_SKIPNEXT:
                case ACTION_WPS_STOP:
                    returncode = ACTION_NONE;
                    break;
                default:
                    break;
            }
        }
        switch (returncode)
        {
            case ACTION_TOUCH_SOFTLOCK:
                data->touchscreen_locked = !data->touchscreen_locked;
                returncode = ACTION_NONE;
                break;
            case ACTION_WPS_PLAY:
                if (!audio_status())
                {
                    if ( global_status.resume_index != -1 )
                    {
                        if (playlist_resume() != -1)
                        {
                            playlist_start(global_status.resume_index,
                                global_status.resume_offset);
                        }
                    }
                    else
                    {
                        splash(HZ*2, ID2P(LANG_NOTHING_TO_RESUME));
                    }
                }
                else
                {
                    wps_do_playpause(false);
                }
                returncode = ACTION_REDRAW;
                break;
            case ACTION_WPS_SKIPPREV:
                audio_prev();
                returncode = ACTION_REDRAW;
                break;
            case ACTION_WPS_SKIPNEXT:
                audio_next();
                returncode = ACTION_REDRAW;
                break;
            case ACTION_WPS_STOP:
                audio_stop();
                returncode = ACTION_REDRAW;
                break;
            case ACTION_SETTINGS_INC:
            case ACTION_SETTINGS_DEC:
            {
                const struct settings_list *setting = 
                                            temp->setting_data.setting;
                option_select_next_val(setting, 
                                       returncode == ACTION_SETTINGS_DEC,
                                       true);
                returncode = ACTION_REDRAW;
            }
            break;
            case ACTION_SETTINGS_SET:
            {
                struct touchsetting *data = &temp->setting_data;
                const struct settings_list *s = data->setting;
                void (*f)(int) = NULL;
                switch (s->flags&F_T_MASK)
                {
                    case F_T_CUSTOM:
                        s->custom_setting
                            ->load_from_cfg(s->setting, SKINOFFSETTOPTR(skin_buffer, data->value.text));
                        break;                          
                    case F_T_INT:
                    case F_T_UINT:
                        *(int*)s->setting = data->value.number;
                        if ((s->flags & F_T_SOUND) == F_T_SOUND)
                            sound_set(s->sound_setting->setting, data->value.number);
                        else if (s->flags&F_CHOICE_SETTING)
                            f = s->choice_setting->option_callback;
                        else if (s->flags&F_TABLE_SETTING)
                            f = s->table_setting->option_callback;
                        else
                            f = s->int_setting->option_callback;

                        if (f)
                            f(data->value.number);
                        break;
                    case F_T_BOOL:
                        *(bool*)s->setting = data->value.number ? true : false;
                        if (s->bool_setting->option_callback)
                            s->bool_setting
                                ->option_callback(data->value.number ? true : false);
                        break;
                }
                returncode = ACTION_REDRAW;
            }
            break;
            case ACTION_TOUCH_MUTE:
            {
                const int min_vol = sound_min(SOUND_VOLUME);
                if (global_settings.volume == min_vol)
                    global_settings.volume = temp->value;
                else
                {
                    temp->value = global_settings.volume;
                    global_settings.volume = min_vol;
                }
                setvol();
                returncode = ACTION_REDRAW;
            }
            break;
            case ACTION_TOUCH_SHUFFLE: /* toggle shuffle mode */
            {
                global_settings.playlist_shuffle = 
                                            !global_settings.playlist_shuffle;
                replaygain_update();
                if (global_settings.playlist_shuffle)
                    playlist_randomise(NULL, current_tick, true);
                else
                    playlist_sort(NULL, true);
                returncode = ACTION_REDRAW;
            }
            break;
            case ACTION_TOUCH_REPMODE: /* cycle the repeat mode setting */
            {
                const struct settings_list *rep_setting = 
                                find_setting(&global_settings.repeat_mode, NULL);
                option_select_next_val(rep_setting, false, true);
                audio_flush_and_reload_tracks();
                returncode = ACTION_REDRAW;
            }
            break;
            case ACTION_TOUCH_SETTING:
            {                
                struct progressbar *bar =
                        SKINOFFSETTOPTR(skin_buffer, temp->bar);
                if (bar && edge_offset)
                {                    
                    int val, count;
                    get_setting_info_for_bar(bar->setting_id, &count, &val);
                    val = *edge_offset * count / 100;
                    update_setting_value_from_touch(bar->setting_id, val);
                }
            }
            break;
        }
        return returncode;
    }

    return ACTION_TOUCHSCREEN;
}
Example #16
0
/**
 * Fetch value of typed GuestInfo setting
 *
 * @v settings		Settings block
 * @v setting		Setting to fetch
 * @v type		Setting type to attempt (or NULL for default)
 * @v data		Buffer to fill with setting data
 * @v len		Length of buffer
 * @ret found		Setting found in GuestInfo
 * @ret len		Length of setting data, or negative error
 */
static int guestinfo_fetch_type ( struct settings *settings,
				  struct setting *setting,
				  struct setting_type *type,
				  void *data, size_t len, int *found ) {
	const char *parent_name = settings->parent->name;
	char command[ 24 /* "info-get guestinfo.ipxe." */ +
		      strlen ( parent_name ) + 1 /* "." */ +
		      strlen ( setting->name ) + 1 /* "." */ +
		      ( type ? strlen ( type->name ) : 0 ) + 1 /* NUL */ ];
	struct setting *named_setting;
	char *info;
	int info_len;
	int check_len;
	int ret;

	/* Construct info-get command */
	snprintf ( command, sizeof ( command ),
		   "info-get guestinfo.ipxe.%s%s%s%s%s",
		   parent_name, ( parent_name[0] ? "." : "" ), setting->name,
		   ( type ? "." : "" ), ( type ? type->name : "" ) );

	/* Check for existence and obtain length of GuestInfo value */
	info_len = guestrpc_command ( guestinfo_channel, command, NULL, 0 );
	if ( info_len < 0 ) {
		ret = info_len;
		goto err_get_info_len;
	}

	/* Mark as found */
	*found = 1;

	/* Determine default type if necessary */
	if ( ! type ) {
		named_setting = find_setting ( setting->name );
		type = ( named_setting ?
			 named_setting->type : &setting_type_string );
	}
	assert ( type != NULL );

	/* Allocate temporary block to hold GuestInfo value */
	info = zalloc ( info_len + 1 /* NUL */ );
	if ( ! info ) {
		DBGC ( settings, "GuestInfo %p could not allocate %zd bytes\n",
		       settings, info_len );
		ret = -ENOMEM;
		goto err_alloc;
	}
	info[info_len] = '\0';

	/* Fetch GuestInfo value */
	check_len = guestrpc_command ( guestinfo_channel, command,
				       info, info_len );
	if ( check_len < 0 ) {
		ret = check_len;
		goto err_get_info;
	}
	if ( check_len != info_len ) {
		DBGC ( settings, "GuestInfo %p length mismatch (expected %d, "
		       "got %d)\n", settings, info_len, check_len );
		ret = -EIO;
		goto err_get_info;
	}
	DBGC2 ( settings, "GuestInfo %p found %s = \"%s\"\n",
		settings, &command[9] /* Skip "info-get " */, info );

	/* Parse GuestInfo value according to type */
	ret = type->parse ( info, data, len );
	if ( ret < 0 ) {
		DBGC ( settings, "GuestInfo %p could not parse \"%s\" as %s: "
		       "%s\n", settings, info, type->name, strerror ( ret ) );
		goto err_parse;
	}

 err_parse:
 err_get_info:
	free ( info );
 err_alloc:
 err_get_info_len:
	return ret;
}
Example #17
0
const char *option_get_valuestring(const struct settings_list *setting, 
                                   char *buffer, int buf_len,
                                   intptr_t temp_var)
{
    const char* str = buffer;
    if ((setting->flags & F_BOOL_SETTING) == F_BOOL_SETTING)
    {
        bool val = (bool)temp_var;
        strlcpy(buffer, str(val? setting->bool_setting->lang_yes :
                                 setting->bool_setting->lang_no), buf_len);
    }
#if 0 /* probably dont need this one */
    else if ((setting->flags & F_FILENAME) == F_FILENAME)
    {
        struct filename_setting *info = setting->filename_setting;
        snprintf(buffer, buf_len, "%s%s%s", info->prefix,
                 (char*)temp_var, info->suffix);
    }
#endif
    else if (((setting->flags & F_INT_SETTING) == F_INT_SETTING) ||
             ((setting->flags & F_TABLE_SETTING) == F_TABLE_SETTING))
    {
        const struct int_setting *int_info = setting->int_setting;
        const struct table_setting *tbl_info = setting->table_setting;
        const char *unit;
        const char* (*formatter)(char*, size_t, int, const char*);
        if ((setting->flags & F_INT_SETTING) == F_INT_SETTING)
        {
            formatter = int_info->formatter;
            unit = unit_strings[int_info->unit];
        }
        else
        {
            formatter = tbl_info->formatter;
            unit = unit_strings[tbl_info->unit];
        }
        if (formatter)
            str = formatter(buffer, buf_len, (int)temp_var, unit);
        else
            snprintf(buffer, buf_len, "%d %s", (int)temp_var, unit?unit:"");
    }
    else if ((setting->flags & F_T_SOUND) == F_T_SOUND)
    {
        char sign = ' ';
        const char *unit = sound_unit(setting->sound_setting->setting);
        int val = sound_val2phys(setting->sound_setting->setting, (int)temp_var);
        if (sound_numdecimals(setting->sound_setting->setting))
        {
            int integer, dec;
            if(val < 0)
            {
                sign = '-';
                val = abs(val);
            }
            integer = val / 10;
            dec = val % 10;
            snprintf(buffer, buf_len, "%c%d.%d %s", sign, integer, dec, unit);
        }
        else
            snprintf(buffer, buf_len, "%d %s", val, unit);
    }
    else if ((setting->flags & F_CHOICE_SETTING) == F_CHOICE_SETTING)
    {
        if (setting->flags & F_CHOICETALKS)
        {
            int setting_id;
            const struct choice_setting *info = setting->choice_setting;
            if (info->talks[(int)temp_var] < LANG_LAST_INDEX_IN_ARRAY)
            {
                strlcpy(buffer, str(info->talks[(int)temp_var]), buf_len);
            }
            else
            {
                find_setting(setting->setting, &setting_id);
                cfg_int_to_string(setting_id, (int)temp_var, buffer, buf_len);
            }
        }
        else
        {
            int value = (int)temp_var;
            char *val = P2STR(setting->choice_setting->desc[value]);
            strlcpy(buffer, val, buf_len);
        }
    }
    return str;
}
Example #18
0
void do_set(COMMAND_ARGS)
{
	/*
	 *  on_msg checks:
	 */
	Chan	*chan;
	UniVar	*univar,*varval;
	char	tmp[MSGLEN];
	char	*pp,*channel,*name;
	int	n,which,i,sz,limit,uaccess;

	/*
	 *
	 */
	channel = get_channel2(to,&rest);
	chan = find_channel_ny(channel);
	name = chop(&rest);

	/*
	 *  empty args, its "set" or "set #channel"
	 */
	if (!name)
	{
		if (!chan)
		{
			to_user(from,ERR_CHAN,channel);
			return;
		}

		if (!CurrentDCC)
			return;

		i = CHANSET_SIZE;
		limit = SIZE_VARS - 1;
		univar = current->setting;
		*tmp = 0;
		if ((uaccess = get_useraccess(from,GLOBAL_CHANNEL)))
			to_user(from,str_underline("Global settings"));
second_pass:
		for(;i<limit;i++)
		{
			if (uaccess < VarName[i].uaccess)
				continue;

			varval = (IsProc(i)) ? current->setting[i].proc_var : &univar[i];

			sz = Strlen2(tmp,VarName[i].name);

			if (IsStr(i))
			{
				sz += (varval->str_var) ? strlen(varval->str_var) : 7;
			}

			if (sz > 58)
			{
				to_user(from,FMT_PLAIN,tmp);
				*tmp = 0;
			}

			if (IsInt(i))
			{
				pp = tolowercat(tmp,VarName[i].name);
				sprintf(pp,(IsChar(i)) ? "=`%c' " : "=%i ",varval->int_var);
			}
			else
			if (IsStr(i))
			{
				pp = tolowercat(tmp,VarName[i].name);
				sprintf(pp,(varval->str_var) ? "=\"%s\" " : "=(unset) ",varval->str_var);
			}
			else
			if (IsTog(i))
			{
				pp = Strcat(tmp,(varval->int_var) ? "+" : "-");
				pp = tolowercat(pp,VarName[i].name);
				pp[0] = ' ';
				pp[1] = 0;
			}
		}
		if (*tmp && tmp[1])
			to_user(from,FMT_PLAIN,tmp);

		if (limit != CHANSET_SIZE)
		{
			to_user(from,"\037Channel settings: %s\037",(chan) ? chan->name : rest);
			i = 0;
			limit = CHANSET_SIZE;
			univar = chan->setting;
			*tmp = 0;
			uaccess = get_useraccess(from,(chan) ? chan->name : rest);
			goto second_pass;
		}
		return;
	}

	/*
	 *  alter a setting
	 */
	if ((which = find_setting(name)) == -1)
	{
set_usage:
		usage(from);	/* usage for CurrentCmd->name */
		return;
	}

	if ((which < CHANSET_SIZE) && *channel != '*')
	{
		if (!chan)
		{
			to_user(from,ERR_CHAN,channel);
			return;
		}
		/*
		 *  its a channel setting
		 */
		channel = chan->name;
		varval = &chan->setting[which];
	}
	else
	{
		/*
		 *  its a global setting
		 */
		channel = MATCH_ALL;
		varval = &current->setting[which];
	}

	if (VarName[which].uaccess > get_authaccess(from,channel))
		return;

	/*
	 *  Check each type and process `rest' if needed.
	 */
	n = 0;
	if (IsChar(which))
	{
		if (rest[1])
			goto set_usage;
	}
	else
	if (IsNum(which))
	{
		if (IsTog(which))
		{
			if (!Strcasecmp(rest,"ON"))
			{
				n = 1;
				goto num_data_ok;
			}
			else
			if (!Strcasecmp(rest,"OFF"))
			{
				/* n is 0 by default */
				goto num_data_ok;
			}
		}
		n = a2i((rest = chop(&rest)));
		if (errno || n < VarName[which].min || n > VarName[which].max)
		{
			to_user(from,"Possible values are %i through %i",VarName[which].min,VarName[which].max);
			return;
		}
	}
num_data_ok:
	/*
	 *
	 */
	if ((which < CHANSET_SIZE) && *channel == '*')
	{
		for(chan=current->chanlist;chan;chan=chan->next)
		{
			if (IsNum(which))
			{
				chan->setting[which].int_var = n;
			}
			else
			if (IsStr(which))
			{
				Free((char**)&chan->setting[which].str_var);
				if (*rest)
				{
					set_mallocdoer(do_set);
					chan->setting[which].str_var = Strdup(rest);
				}
			}
		}
		channel = "(all channels)";
	}
	else
	{
		if (IsProc(which))
			varval = varval->proc_var;

		if (IsChar(which))
			varval->char_var = *rest;
		else
		if (IsNum(which))
			varval->int_var = n;
		else
		{
			if (varval->str_var)
				Free((char**)&varval->str_var);
			if (*rest)
			{
				set_mallocdoer(do_set);
				varval->str_var = Strdup(rest);
			}
		}
	}
	to_user(from,"Var: %s   On: %s   Set to: %s",VarName[which].name,
		(which >= CHANSET_SIZE) ? "(global)" : channel,(*rest) ? rest : NULLSTR);
	if (VarName[which].func)
		VarName[which].func(&VarName[which]);
}