From bc39f1d6d7fe09a0449b785394e33d31a888dd00 Mon Sep 17 00:00:00 2001 From: Creamy Goodness Date: Tue, 14 Sep 2010 14:26:16 -0600 Subject: [PATCH] fixed bugs and added comments to scroll.c; scrolling now works better although i didn't test color changes. --- src/scroll.c | 64 +++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 18 deletions(-) diff --git a/src/scroll.c b/src/scroll.c index f78f807..263394f 100644 --- a/src/scroll.c +++ b/src/scroll.c @@ -34,9 +34,10 @@ struct scroll_data { char *text; - unsigned int show; + unsigned int show;//length of scrolling field in # of characters requested by conf file unsigned int step; - unsigned int start; + unsigned int start;//current position of first letter of text? + unsigned int junk;//to keep track of any padding we add long resetcolor; }; @@ -50,27 +51,31 @@ void parse_scroll_arg(struct text_object *obj, const char *arg, void *free_at_cr sd->resetcolor = get_current_text_color(); sd->step = 1; - if (!arg || sscanf(arg, "%u %n", &sd->show, &n1) <= 0) + if (!arg || sscanf(arg, "%u %n", &sd->show, &n1) <= 0)//get 1st arg: show = field length; n1 = number of bytes read from the input so far by this call CRIT_ERR(obj, free_at_crash, "scroll needs arguments: [] "); - sscanf(arg + n1, "%u %n", &sd->step, &n2); - if (*(arg + n1 + n2)) { - n1 += n2; + sscanf(arg + n1, "%u %n", &sd->step, &n2);//gets step size; n2 is bytes of data required to store that + if (*(arg + n1 + n2)) {//trying to read the first byte of text to scroll, i wonder what happens if it's a zero? + n1 += n2;//n1 is now total bytes of all args read, or the number of bytes to skip if you want the text from arg } else { - sd->step = 1; + sd->step = 1;//default step size is 1 if it wasn't specified, although that was set above anyways. } - sd->text = malloc(strlen(arg + n1) + sd->show + 1); - - if (strlen(arg) > sd->show) { - for(n2 = 0; (unsigned int) n2 < sd->show; n2++) { - sd->text[n2] = ' '; + sd->text = malloc(strlen(arg + n1) + sd->show + 1);//changes the text pointer to point to an array of 2x text + 1; + +//i think it's trying to check if there is more text to display than space to fit it. +// if (strlen(arg) > sd->show) {//if the total text and parameters is more than the size to display just the text? why aren't we subtracting n1 from the left side? + sd->junk = 0; + if (strlen(arg + n1) > sd->show) {//better, we need to skip past the parameters + for(n2 = 0; (unsigned int) n2 < sd->show; n2++) {//i guess this would clear half of the array starting at the beginning, if it was set to 2 x text as above lame code does + sd->text[n2] = ' ';//here we are padding spaces that end up BEFORE the text. + sd->junk++; } - sd->text[n2] = 0; + sd->text[n2] = 0;//terminates the string } else - sd->text[0] = 0; - - strcat(sd->text, arg + n1); + sd->text[0] = 0;//empty string, strcat probably explodes if you don't do this + + strcat(sd->text, arg + n1);//copies only the text into sd.text, appending to any existing blank space. sd->start = 0; obj->sub = malloc(sizeof(struct text_object)); extract_variable_text_internal(obj->sub, sd->text); @@ -100,8 +105,31 @@ void print_scroll(struct text_object *obj, char *p, int p_max_size, struct infor break; } } - //no scrolling necessary if the length of the text to scroll is too short - if (strlen(buf) - colorchanges <= sd->show) { + //(r)trim any incoming strings. some functions might return data with extra spaces on the end... + int k; + int len; + int junk=0; + len=strlen(buf); + for + (k=len-1;k>=0&&buf[k]==' ';k--) + { + buf[k]='\0'; + } +//count left padding but don't trim it because it's potentially needed for scrolling... (i commented this out because probably the only spaces on the front of the string +//will be ours that we added above, should be more efficient to just keep track of those. but maybe this will be useful some day so i've left it here. +// k=0; +// while (buf[k]==' ') { +// k++; +// junk++; +// } + + //no scrolling necessary if the length of the text to scroll is shorter than the requested space from the conf + //if (strlen(buf) - colorchanges <= sd->show) { + if (strlen(buf) - junk - sd->junk - colorchanges <= sd->show) { + //ok we can really trim the left spaces now since we aren't scrolling it... + while ( buf[0] != '\0' && strchr ( &buf[0], ' ' ) != NULL ) { + memmove( &buf[0], &buf[1], strlen(buf) ); + } snprintf(p, p_max_size, "%s", buf); return; } -- 1.7.9.5