busybox-1.32.0/libbb/lineedit.c
static void showfiles(void)
{
	int ncols, row;
	int column_width = 0;
	int nfiles = num_matches;
	int nrows = nfiles;
	int l;

	/* find the longest file name - use that as the column width */
	for (row = 0; row < nrows; row++) {
		l = unicode_strwidth(matches[row]);
		if (column_width < l)
			column_width = l;
	}
	column_width += 2;              /* min space for columns */
	ncols = cmdedit_termw / column_width;

	if (ncols > 1) {
		nrows /= ncols;
		if (nfiles % ncols)
			nrows++;        /* round up fractionals */
	} else {
		ncols = 1;
	}
	for (row = 0; row < nrows; row++) {
		int n = row;
		int nc;

		for (nc = 1; nc < ncols && n+nrows < nfiles; n += nrows, nc++) {
			printf("%s%-*s", matches[n],
				(int)(column_width - unicode_strwidth(matches[n])), ""
			);
		}
		if (ENABLE_UNICODE_SUPPORT)
			puts(printable_string(matches[n]));
		else
			puts(matches[n]);
	}
}
/*
 * Display by column (original idea from ls applet,
 * very optimized by me [Vladimir] :)
 */
Display by column (original idea from ls applet,
very optimized by me [Vladimir] :)
Display by column ( original idea from ls applet very optimized by me [ Vladimir ] : )
static void showfiles(void)
{
	int ncols, row;
	int column_width = 0;
	int nfiles = num_matches;
	int nrows = nfiles;
	int l;
	for (row = 0; row < nrows; row++) {
		l = unicode_strwidth(matches[row]);
		if (column_width < l)
			column_width = l;
	}
	column_width += 2;              
	ncols = cmdedit_termw / column_width;
	if (ncols > 1) {
		nrows /= ncols;
		if (nfiles % ncols)
			nrows++;        
	} else {
		ncols = 1;
	}
	for (row = 0; row < nrows; row++) {
		int n = row;
		int nc;
		for (nc = 1; nc < ncols && n+nrows < nfiles; n += nrows, nc++) {
			printf("%s%-*s", matches[n],
				(int)(column_width - unicode_strwidth(matches[n])), ""
			);
		}
		if (ENABLE_UNICODE_SUPPORT)
			puts(printable_string(matches[n]));
		else
			puts(matches[n]);
	}
}
static void showfiles ( void ) { int ncols , row ; int column_width = 0 ; int nfiles = num_matches ; int nrows = nfiles ; int l ; for ( row = 0 ; row < nrows ; row ++ ) { l = unicode_strwidth ( matches [ row ] ) ; if ( column_width < l ) column_width = l ; } column_width += 2 ; ncols = cmdedit_termw / column_width ; if ( ncols > 1 ) { nrows /= ncols ; if ( nfiles % ncols ) nrows ++ ; } else { ncols = 1 ; } for ( row = 0 ; row < nrows ; row ++ ) { int n = row ; int nc ; for ( nc = 1 ; nc < ncols && n + nrows < nfiles ; n += nrows , nc ++ ) { printf ( " " , matches [ n ] , ( int ) ( column_width - unicode_strwidth ( matches [ n ] ) ) , " " ) ; } if ( ENABLE_UNICODE_SUPPORT ) puts ( printable_string ( matches [ n ] ) ) ; else puts ( matches [ n ] ) ; } }
Display by column (original idea from ls applet,
 very optimized by me [Vladimir] :)
Display by column ( original idea from ls applet very optimized by me [ Vladimir ] : )
/* find the longest file name - use that as the column width */ /* min space for columns */ /* round up fractionals */