diff options
-rw-r--r-- | src/apoint.c | 5 | ||||
-rw-r--r-- | src/ical.c | 31 | ||||
-rw-r--r-- | src/todo.c | 5 | ||||
-rw-r--r-- | src/wins.c | 5 |
4 files changed, 21 insertions, 25 deletions
diff --git a/src/apoint.c b/src/apoint.c index b00bc8a..9860038 100644 --- a/src/apoint.c +++ b/src/apoint.c @@ -359,9 +359,8 @@ void apoint_update_panel(int which_pan) /* Draw the scrollbar if necessary. */ if ((apad.length >= app_length) || (apad.first_onscreen > 0)) { - float ratio = ((float)app_length) / ((float)apad.length); - int sbar_length = (int)(ratio * app_length); - int highend = (int)(ratio * apad.first_onscreen); + int sbar_length = app_length * app_length / apad.length; + int highend = app_length * apad.first_onscreen / apad.length; unsigned hilt_bar = (which_pan == APP) ? 1 : 0; int sbar_top = highend + title_lines + 1; @@ -237,13 +237,13 @@ static void ical_export_todo(FILE * stream) } /* Print a header to describe import log report format. */ -static void ical_log_init(FILE * log, float version) +static void ical_log_init(FILE * log, int major, int minor) { const char *header = "+-------------------------------------------------------------------+\n" "| Calcurse icalendar import log. |\n" "| |\n" - "| Items imported from icalendar file, version %1.1f |\n" + "| Items imported from icalendar file, version %d.%d |\n" "| Some items could not be imported, they are described hereafter. |\n" "| The log line format is as follows: |\n" "| |\n" @@ -256,7 +256,7 @@ static void ical_log_init(FILE * log, float version) "+-------------------------------------------------------------------+\n\n"; if (log) - fprintf(log, header, version); + fprintf(log, header, major, minor); } /* @@ -419,25 +419,25 @@ static int ical_readline(FILE * fdi, char *buf, char *lstore, unsigned *ln) return 1; } -static float -ical_chk_header(FILE * fd, char *buf, char *lstore, unsigned *lineno) +static int +ical_chk_header(FILE * fd, char *buf, char *lstore, unsigned *lineno, + int *major, int *minor) { - const int HEADER_MALFORMED = -1; const char icalheader[] = "BEGIN:VCALENDAR"; - float version; if (!ical_readline(fd, buf, lstore, lineno)) - return HEADER_MALFORMED; + return 0; str_toupper(buf); if (strncmp(buf, icalheader, sizeof(icalheader) - 1) != 0) - return HEADER_MALFORMED; + return 0; - while (!sscanf(buf, "VERSION:%f", &version)) { + while (!sscanf(buf, "VERSION:%d.%d", major, minor)) { if (!ical_readline(fd, buf, lstore, lineno)) - return HEADER_MALFORMED; + return 0; } - return version; + + return 1; } /* @@ -1055,15 +1055,14 @@ ical_import_data(FILE * stream, FILE * log, unsigned *events, unsigned *apoints, const char vevent[] = "BEGIN:VEVENT"; const char vtodo[] = "BEGIN:VTODO"; char buf[BUFSIZ], lstore[BUFSIZ]; - float ical_version; + int major, minor; ical_readline_init(stream, buf, lstore, lines); - ical_version = ical_chk_header(stream, buf, lstore, lines); - RETURN_IF(ical_version < 0, + RETURN_IF(!ical_chk_header(stream, buf, lstore, lines, &major, &minor), _("Warning: ical header malformed or wrong version number. " "Aborting...")); - ical_log_init(log, ical_version); + ical_log_init(log, major, minor); while (ical_readline(stream, buf, lstore, lines)) { (*lines)++; @@ -311,9 +311,8 @@ void todo_update_panel(int which_pan) /* Draw the scrollbar if necessary. */ if (todos > max_items) { - float ratio = ((float)max_items) / ((float)todos); - int sbar_length = (int)(ratio * (max_items + 1)); - int highend = (int)(ratio * first); + int sbar_length = max_items * (max_items + 1) / todos; + int highend = max_items * first / todos; unsigned hilt_bar = (which_pan == TOD) ? 1 : 0; int sbar_top = highend + title_lines; @@ -253,9 +253,8 @@ void wins_scrollwin_display(struct scrollwin *sw) const int visible_lines = sw->win.h - sw->pad.y - 1; if (sw->total_lines > visible_lines) { - float ratio = ((float)visible_lines) / ((float)sw->total_lines); - int sbar_length = (int)(ratio * visible_lines); - int highend = (int)(ratio * sw->first_visible_line); + int sbar_length = visible_lines * visible_lines / sw->total_lines; + int highend = visible_lines * sw->first_visible_line / sw->total_lines; int sbar_top = highend + sw->pad.y + 1; if ((sbar_top + sbar_length) > sw->win.h - 1) |