/* Formats contents of the job bar. Returns pointer to statically allocated * storage. */ static const char * format_job_bar(void) { enum { MAX_UTF_CHAR_LEN = 4 }; static char bar_text[512*MAX_UTF_CHAR_LEN + 1]; size_t i; size_t text_width; size_t width_used; size_t max_width; char **descrs; descrs = take_job_descr_snapshot(); bar_text[0] = '\0'; text_width = 0U; /* The check of stage is for tests. */ max_width = (curr_stats.load_stage < 2) ? 80 : getmaxx(job_bar); width_used = 0U; for(i = 0U; i < nbar_jobs; ++i) { const int progress = bar_jobs[i]->progress; const unsigned int reserved = (progress == -1) ? 0U : 5U; char item_text[max_width*MAX_UTF_CHAR_LEN + 1U]; const size_t width = (i == nbar_jobs - 1U) ? (max_width - width_used) : (max_width/nbar_jobs); char *const ellipsed = left_ellipsis(descrs[i], width - 2U - reserved, curr_stats.ellipsis); if(progress == -1) { snprintf(item_text, sizeof(item_text), "[%s]", ellipsed); } else { snprintf(item_text, sizeof(item_text), "[%s %3d%%]", ellipsed, progress); } free(ellipsed); (void)sstrappend(bar_text, &text_width, sizeof(bar_text), item_text); width_used += width; } free_string_array(descrs, nbar_jobs); return bar_text; }
/* Formats dialog control message for custom set of responses. Returns pointer * to statically allocated buffer. */ static const char * get_custom_control_msg(const response_variant responses[]) { static char msg_buf[256]; const response_variant *response = responses; size_t len = 0U; msg_buf[0] = '\0'; while(response != NULL && response->key != '\0') { if(response->descr[0] != '\0') { (void)sstrappend(msg_buf, &len, sizeof(msg_buf), response->descr); if(response[1].key != '\0') { (void)sstrappendch(msg_buf, &len, sizeof(msg_buf), '/'); } } ++response; } return msg_buf; }