int column_array(char **strings, int num_to_print, int screen_width, int column_width, int number_of_columns, int margin, int spread_flag, int number_flag, int var_col_flag, FILE *outfile) { char buf[BUFSIZ]; int updown, leftright, height; int string_width; int numwidth; numwidth = num_width(num_to_print); if (! var_col_flag) { string_width = calc_string_width(column_width, margin, number_flag, num_to_print); if (string_width <= 0) { set_error(COL_COLUMNS_TOO_THIN); error("calc_string_width"); return error_code; } trim_strings(strings, num_to_print, string_width); } else if (calc_widths(strings, &screen_width, &column_width, &number_of_columns, num_to_print, &margin, spread_flag, number_flag)) { error("calc_widths"); return error_code; } height = num_to_print / number_of_columns; if (num_to_print % number_of_columns) height++; if (number_flag) for (updown = 0; updown < height; updown++) { for (leftright = updown; leftright < num_to_print; ) { (void) sprintf(buf, "%*d. %s", numwidth, leftright+1, strings[leftright]); if ((leftright += height) >= num_to_print) fprintf(outfile, "%s", buf ); else fprintf(outfile, "%*s", -column_width, buf); } fprintf(outfile, "\n"); } else for (updown = 0; updown < height; updown++) { for (leftright = updown; leftright < num_to_print; ) { (void) sprintf(buf, "%s", strings[leftright]); if ((leftright += height) >= num_to_print) fprintf(outfile, "%s", buf ); else fprintf(outfile, "%*s", -column_width, buf); } fprintf(outfile, "\n"); } return 0; }
static void t_draw(ui_tab_t *tab) { tab_t *t = (tab_t *)tab; calc_widths(t); // header attron(UIC(list_header)); mvhline(1, 0, ' ', wincols); mvaddstr(1, 2, "opt"); int i = 6; DRAW_COL(1, i, t->cw_country, "CC"); DRAW_COL(1, i, t->cw_user, "Username"); DRAW_COL(1, i, t->cw_share, "Share"); DRAW_COL(1, i, t->cw_desc, "Description"); DRAW_COL(1, i, t->cw_tag, "Tag"); DRAW_COL(1, i, t->cw_mail, "E-Mail"); DRAW_COL(1, i, t->cw_conn, "Connection"); DRAW_COL(1, i, t->cw_ip, "IP"); attroff(UIC(list_header)); // rows int bottom = t->details ? winrows-7 : winrows-3; ui_cursor_t cursor; int pos = ui_listing_draw(t->list, 2, bottom-1, &cursor, draw_row); // footer attron(UIC(separator)); mvhline(bottom, 0, ' ', wincols); int count = g_hash_table_size(t->tab.hub->users); mvaddstr(bottom, 0, "Totals:"); mvprintw(bottom, t->cw_user+6, "%s%c %d users", str_formatsize(t->tab.hub->sharesize), t->tab.hub->sharecount == count ? ' ' : '+', count); mvprintw(bottom, wincols-6, "%3d%%", pos); attroff(UIC(separator)); // detailed info box if(t->details && g_sequence_iter_is_end(t->list->sel)) mvaddstr(bottom+1, 2, "No user selected."); else if(t->details) { hub_user_t *u = g_sequence_get(t->list->sel); attron(A_BOLD); mvaddstr(bottom+1, 4, "Username:"******"Share:"); mvaddstr(bottom+2, 2, "Connection:"); mvaddstr(bottom+2, 25+19, "IP:"); mvaddstr(bottom+3, 6, "E-Mail:"); mvaddstr(bottom+3, 25+18, "Tag:"); mvaddstr(bottom+4, 1, "Description:"); attroff(A_BOLD); mvaddstr(bottom+1, 14, u->name); if(u->hasinfo) mvprintw(bottom+1, 25+23, "%s (%s bytes)", str_formatsize(u->sharesize), str_fullsize(u->sharesize)); else mvaddstr(bottom+1, 25+23, "-"); char *conn = hub_user_conn(u); mvaddstr(bottom+2, 14, conn?conn:"-"); g_free(conn); mvaddstr(bottom+2, 25+23, hub_user_ip(u, "-")); mvaddstr(bottom+3, 14, u->mail?u->mail:"-"); char *tag = hub_user_tag(u); mvaddstr(bottom+3, 25+23, tag?tag:"-"); g_free(tag); mvaddstr(bottom+4, 14, u->desc?u->desc:"-"); // TODO: CID? } move(cursor.y, cursor.x); }