/** @relates string */ struct string * add_duration_to_string(struct string *string, long seconds) { unsigned char q[64]; int qlen = 0; if (seconds < 0) seconds = 0; /* Days */ if (seconds >= (24 * 3600)) { ulongcat(q, &qlen, (seconds / (24 * 3600)), 5, 0); q[qlen++] = 'd'; q[qlen++] = ' '; } /* Hours and minutes */ if (seconds >= 3600) { seconds %= (24 * 3600); ulongcat(q, &qlen, (seconds / 3600), 4, 0); q[qlen++] = ':'; ulongcat(q, &qlen, ((seconds / 60) % 60), 2, '0'); } else { /* Only minutes */ ulongcat(q, &qlen, (seconds / 60), 2, 0); } /* Seconds */ q[qlen++] = ':'; ulongcat(q, &qlen, (seconds % 60), 2, '0'); add_to_string(string, q); return string; }
static void build_edit_dialog(struct terminal *term, struct cookie *cookie) { #define EDIT_WIDGETS_COUNT 8 /* [gettext_accelerator_context(.build_edit_dialog)] */ struct dialog *dlg; unsigned char *name, *value, *domain, *expires, *secure; unsigned char *dlg_server; int length = 0; dlg = calloc_dialog(EDIT_WIDGETS_COUNT, MAX_STR_LEN * 5); if (!dlg) return; dlg->title = _("Edit", term); dlg->layouter = generic_dialog_layouter; dlg->udata = cookie; dlg->udata2 = NULL; name = get_dialog_offset(dlg, EDIT_WIDGETS_COUNT); value = name + MAX_STR_LEN; domain = value + MAX_STR_LEN; expires = domain + MAX_STR_LEN; secure = expires + MAX_STR_LEN; safe_strncpy(name, cookie->name, MAX_STR_LEN); safe_strncpy(value, cookie->value, MAX_STR_LEN); safe_strncpy(domain, cookie->domain, MAX_STR_LEN); /* Bug 923: Assumes time_t values fit in unsigned long. */ ulongcat(expires, &length, cookie->expires, MAX_STR_LEN, 0); length = 0; ulongcat(secure, &length, cookie->secure, MAX_STR_LEN, 0); dlg_server = cookie->server->host; dlg_server = straconcat(_("Server", term), ": ", dlg_server, "\n", (unsigned char *) NULL); if (!dlg_server) { mem_free(dlg); return; } add_dlg_text(dlg, dlg_server, ALIGN_LEFT, 0); add_dlg_field_float(dlg, _("Name", term), 0, 0, set_cookie_name, MAX_STR_LEN, name, NULL); add_dlg_field_float(dlg, _("Value", term), 0, 0, set_cookie_value, MAX_STR_LEN, value, NULL); add_dlg_field_float(dlg, _("Domain", term), 0, 0, set_cookie_domain, MAX_STR_LEN, domain, NULL); add_dlg_field_float(dlg, _("Expires", term), 0, 0, set_cookie_expires, MAX_STR_LEN, expires, NULL); add_dlg_field_float(dlg, _("Secure", term), 0, 0, set_cookie_secure, MAX_STR_LEN, secure, NULL); add_dlg_button(dlg, _("~OK", term), B_ENTER, ok_dialog, NULL); add_dlg_button(dlg, _("~Cancel", term), B_ESC, cancel_dialog, NULL); add_dlg_end(dlg, EDIT_WIDGETS_COUNT); do_dialog(term, dlg, getml(dlg, (void *) dlg_server, (void *) NULL)); #undef EDIT_WIDGETS_COUNT }
void draw_progress_bar(struct progress *progress, struct terminal *term, int x, int y, int width, unsigned char *text, struct color_pair *meter_color) { /* Note : values > 100% are theorically possible and were seen. */ int percent = 0; struct box barprogress; if (progress->size > 0) percent = (int) ((longlong) 100 * progress->pos / progress->size); /* Draw the progress meter part "[### ]" */ if (!text && width > 2) { width -= 2; draw_text(term, x++, y, "[", 1, 0, NULL); draw_text(term, x + width, y, "]", 1, 0, NULL); } if (!meter_color) meter_color = get_bfu_color(term, "dialog.meter"); set_box(&barprogress, x, y, int_min(width * percent / 100, width), 1); draw_box(term, &barprogress, ' ', 0, meter_color); /* On error, will print '?' only, should not occur. */ if (text) { width = int_min(width, strlen(text)); } else if (width > 1) { static unsigned char s[] = "????"; /* Reduce or enlarge at will. */ unsigned int slen = 0; int max = int_min(sizeof(s), width) - 1; if (ulongcat(s, &slen, percent, max, 0)) { s[0] = '?'; slen = 1; } s[slen++] = '%'; /* Draw the percentage centered in the progress meter */ x += (1 + width - slen) / 2; assert(slen <= width); width = slen; text = s; } draw_text(term, x, y, text, width, 0, NULL); }
/** Adds the term code for positioning the cursor at @a x and @a y to * @a string. The template term code is: "\033[<y>;<x>H" */ static inline struct string * add_cursor_move_to_string(struct string *screen, int y, int x) { #define CURSOR_NUM_LEN 10 /* 10 chars for @y and @x numbers should be more than enough. */ unsigned char code[4 + 2 * CURSOR_NUM_LEN + 1]; unsigned int length = 2; code[0] = '\033'; code[1] = '['; if (ulongcat(code, &length, y, CURSOR_NUM_LEN, 0) < 0) return screen; code[length++] = ';'; if (ulongcat(code, &length, x, CURSOR_NUM_LEN, 0) < 0) return screen; code[length++] = 'H'; return add_bytes_to_string(screen, code, length); #undef CURSOR_NUM_LEN }
void html_li(struct html_context *html_context, unsigned char *a, unsigned char *xxx3, unsigned char *xxx4, unsigned char **xxx5) { int t = par_format.flags & P_LISTMASK; /* When handling the code <li><li> @was_li will be 1 and it means we * have to insert a line break since no list item content has done it * for us. */ if (html_context->was_li) { html_context->line_breax = 0; ln_break(html_context, 1); } /*kill_html_stack_until(html_context, 0 "", "UL", "OL", NULL);*/ if (t == P_NO_BULLET) { /* Print nothing. */ } else if (!par_format.list_number) { if (t == P_O) /* Print U+25E6 WHITE BULLET. */ put_chrs(html_context, (unsigned char *)"◦", 7); else if (t == P_SQUARE) /* Print U+25AA BLACK SMALL SQUARE. */ put_chrs(html_context, (unsigned char *)"▪", 7); else /* Print U+2022 BULLET. */ put_chrs(html_context, (unsigned char *)"•", 7); put_chrs(html_context, (unsigned char *)" ", 6); par_format.leftmargin += 2; par_format.align = ALIGN_LEFT; } else { unsigned char c = 0; int nlen; int t = par_format.flags & P_LISTMASK; int s = get_num(a, (unsigned char *)"value", html_context->doc_cp); struct string n; if (!init_string(&n)) return; if (s != -1) par_format.list_number = s; if (t == P_ALPHA || t == P_alpha) { unsigned char n0; put_chrs(html_context, (unsigned char *)" ", 6); c = 1; n0 = par_format.list_number ? (par_format.list_number - 1) % 26 + (t == P_ALPHA ? 'A' : 'a') : 0; if (n0) add_char_to_string(&n, n0); } else if (t == P_ROMAN || t == P_roman) { roman(&n, par_format.list_number); if (t == P_ROMAN) { unsigned char *x; for (x = n.source; *x; x++) *x = c_toupper(*x); } } else { unsigned char n0[64]; if (par_format.list_number < 10) { put_chrs(html_context, (unsigned char *)" ", 6); c = 1; } ulongcat(n0, NULL, par_format.list_number, (sizeof(n) - 1), 0); add_to_string(&n, n0); } nlen = n.length; put_chrs(html_context, n.source, nlen); put_chrs(html_context, (unsigned char *)". ", 7); par_format.leftmargin += nlen + c + 2; par_format.align = ALIGN_LEFT; done_string(&n); { struct html_element *element; element = search_html_stack(html_context, (unsigned char *)"ol"); if (element) element->parattr.list_number = par_format.list_number + 1; } par_format.list_number = 0; } html_context->putsp = HTML_SPACE_SUPPRESS; html_context->line_breax = 2; html_context->was_li = 1; }