Rockbox Technical Forums

Rockbox Development => Starting Development and Compiling => Topic started by: tdtooke on June 24, 2008, 03:54:05 AM

Title: parse_progressbar or parse_list
Post by: tdtooke on June 24, 2008, 03:54:05 AM
Basically I'm updating the progressbar-slider patch and was hoping one of you intrepid devs wouldn't mind answering a few questions.  Ok, in parse_progressbar in wps_parser.c I added another field for pb->pb_type which is what this patch uses instead of pb->have_bitmap_pb because with this patch you have 3 choices REGULAR, BITMAP and SLIDER instead of just REGULAR and BITMAP.  In wps_parser I added an extra 'd' to the list I was parsing so I could have the kind variable which I was using in the %pb tag to indicate what type of progressbar that progressbar was.  The problem is the way I have it set up with that extra if (LIST_VALUE_PARSED(set, PB_KIND)) I have in it I have to add "-|" to the end of the %pb declaration in the default theme for it to work since my code insists on having that extra field even if it has no value like that.  What I'm wanting to know how to do is how can I have an extra field there and not have it required to be there in some form.  Right now I have to at least have a |-| there but I want the default theme to work as is because nobody will remember to do that most likely.  so...How do I do this?  Oh and by the way, whoever wrote parse_list in misc.c is a genius!  I love that function!  Sorry for the sloppiness, but for clarity here is my parse_progressbar method so you'll know exactly what I'm doing:
Code: [Select]
static int parse_progressbar(const char *wps_bufptr,
                             struct wps_token *token,
                             struct wps_data *wps_data)
    (void)token; /* Kill warnings */
    /* %pb or %pb|filename|x|y|width|height|
    using - for any of the params uses "sane" values */

    enum {
        PB_FILENAME = 0,
    const char *filename;
    int x, y, height, width, kind;
    uint32_t set = 0;
    const char *ptr = wps_bufptr;
    struct progressbar *pb;
    struct viewport *vp = &wps_data->viewports[wps_data->num_viewports].vp;
    int font_height = font_get(vp->font)->height;
    int line_y_pos = font_height*(wps_data->num_lines -
    if (wps_data->progressbar_count +1 >= MAX_PROGRESSBARS)
    pb = &wps_data->progressbar[wps_data->progressbar_count];
    pb->have_bitmap_pb = false;
    if (*wps_bufptr != '|') /* regular old style */
        pb->x = 0;
        pb->width = vp->width;
        pb->height = SYSFONT_HEIGHT-2;
        pb->y = line_y_pos + (font_height-pb->height)/2;

        wps_data->viewports[wps_data->num_viewports].pb =
        return 0;
    ptr = wps_bufptr + 1;
    if (!(ptr = parse_list("sddddd", &set, '|', ptr, &filename,
                                                 &x, &y, &width, &height, &kind)))
    if (LIST_VALUE_PARSED(set, PB_FILENAME)) /* filename */
        bmp_names[PROGRESSBAR_BMP+wps_data->progressbar_count] = filename;
    if (LIST_VALUE_PARSED(set, PB_X)) /* x */
        pb->x = x;
        pb->x = vp->x;
    if (LIST_VALUE_PARSED(set, PB_WIDTH)) /* width */
        pb->width = width;
        pb->width = vp->width - pb->x;
    if (LIST_VALUE_PARSED(set, PB_HEIGHT)) /* height, default to font height */
        pb->height = height;
        pb->height = font_height;
    if (LIST_VALUE_PARSED(set, PB_Y)) /* y */
        pb->y = y;
        pb->y = line_y_pos + (font_height-pb->height)/2;
        pb->pb_type = kind;
        pb->pb_type = BITMAP;
    wps_data->progressbar[wps_data->progressbar_count].have_bitmap_pb = false;
    wps_data->viewports[wps_data->num_viewports].pb =
    /* Skip the rest of the line */
    return skip_end_of_line(wps_bufptr)-1;
    if (*(wps_bufptr-1) == 'f')
        wps_data->full_line_progressbar = true;
        wps_data->full_line_progressbar = false;

    return 0;

Title: Re: parse_progressbar or parse_list
Post by: JdGordon on June 25, 2008, 01:53:45 AM
I think parse_list returns a pointer to the end of the string parsed.... so
1) remove your extra d from the list
2) check to see if \n follows the |  at the end of the list.. if it doesnt then do an atoi() to get the value...
Title: Re: parse_progressbar or parse_list
Post by: tdtooke on June 25, 2008, 06:28:57 AM
Thanks, I don't know why I felt somehow bound to add my field to parse_list.  I guess I was just so impressed with it when I looked it up.  :)
Title: Re: parse_progressbar or parse_list
Post by: kugel. on July 28, 2008, 02:44:59 PM
Haha, I know what you mean :)