=== modified file 'uspace/app/bdsh/cmds/modules/ls/ls.c'
--- uspace/app/bdsh/cmds/modules/ls/ls.c	2012-03-25 19:42:07 +0000
+++ uspace/app/bdsh/cmds/modules/ls/ls.c	2012-04-14 18:00:06 +0000
@@ -40,6 +40,9 @@
 #include <sys/stat.h>
 #include <str.h>
 #include <sort.h>
+#include <io/console.h>
+#include <errno.h>
+#include <macros.h>
 
 #include "ls.h"
 #include "errors.h"
@@ -56,12 +59,13 @@
 	{ "help", no_argument, 0, 'h' },
 	{ "unsort", no_argument, 0, 'u' },
 	{ "recursive", no_argument, 0, 'r' },
+	{ "longformat", no_argument, 0, 'l'},
 	{ 0, 0, 0, 0 }
 };
 
 /* Prototypes for the ls command, excluding entry points. */
 static unsigned int ls_start(ls_job_t *);
-static void ls_print(struct dir_elem_t *);
+static void ls_print_long_format(struct dir_elem_t *, unsigned int);
 static int ls_cmp(void *, void *, void *);
 static signed int ls_scan_dir(const char *, DIR *, struct dir_elem_t **);
 static unsigned int ls_recursive(const char *, DIR *);
@@ -69,31 +73,102 @@
 
 static unsigned int ls_start(ls_job_t *ls)
 {
+	sysarg_t _dummy_;
+
+	ls->long_format = 0;
 	ls->recursive = 0;
 	ls->sort = 1;
 
+	ls->cols = 0;
+
+	console_ctrl_t* console = console_init(stdin, stdout);
+
+	if (console) {
+		if (console_get_size(console, &ls->cols, &_dummy_) != EOK) {
+			printf("%s - cannot get console size\n", cmdname);
+			return 0;
+		}
+
+		console_done(console);
+	}
+
 	return 1;
 }
 
+/*
+ * Print a list of elements on several column.
+ * @param elements      the list of directory entries to print.
+ * @param nb_elements   the number of element in the list.
+ */
+static void ls_print_columns_listing(struct dir_elem_t *elements, unsigned int nb_elements)
+{
+	assert(elements);
+
+	unsigned int i;
+	unsigned int size;
+	unsigned int current_col;
+	unsigned int max_element_size;
+
+	// nothing to print
+	if (!nb_elements) {
+		return ;
+	}
+
+	/* First we need to get the max size of the elements to print */
+	max_element_size = str_size(elements->name);
+	for (i = 1; i < nb_elements; i++) {
+		size = str_size(elements[i].name);
+		max_element_size = max(max_element_size, size);
+	}
+
+	++max_element_size; // +1 space
+
+	i = 0;
+	current_col = 0;
+	while (i < nb_elements) {
+
+		size = max_element_size - printf("%s", elements[i].name);
+
+		for (; size; size--) {
+			printf(" ");
+		}
+
+		current_col += max_element_size;
+
+		if ((current_col + max_element_size) >= ls.cols) {
+			current_col = 0;
+			printf("\n");
+		}
+
+		++i;
+	}
+
+	printf("\n");
+}
+
+
 /** Print an entry.
  *
- * ls_print currently does nothing more than print the entry.
+ * ls_print_long_format currently does nothing more than print the entry.
  * In the future, we will likely pass the absolute path, and
  * some sort of ls_options structure that controls how each
  * entry is printed and what is printed about it.
  *
  * Now we just print basic DOS style lists.
  *
- * @param de		Directory element.
+ * @param de		Directory elements.
+ * @param size		Number of element in de.
  */
-static void ls_print(struct dir_elem_t *de)
+static void ls_print_long_format(struct dir_elem_t *de, unsigned int nb_element)
 {
-	if (de->s.is_file)
-		printf("%-40s\t%llu\n", de->name, (long long) de->s.size);
-	else if (de->s.is_directory)
-		printf("%-40s\t<dir>\n", de->name);
-	else
-		printf("%-40s\n", de->name);
+	unsigned int i;
+
+	for(i = 0; i < nb_element; ++i) {
+		if (de[i].s.is_file)
+			printf("%-40s\t%llu\n", de[i].name, (long long) de[i].s.size);
+		else if (de[i].s.is_directory)
+			printf("%-40s\t<dir>\n", de[i].name);
+	}
 }
 
 /** Compare 2 directory elements.
@@ -197,9 +272,13 @@
 			printf("Sorting error.\n");
 		}
 	}
-	
-	for (i = 0; i < nbdirs; i++)
-		ls_print(&tosort[i]);
+
+	if (ls.long_format) {
+		ls_print_long_format(tosort, nbdirs);
+	}
+	else {
+		ls_print_columns_listing(tosort, nbdirs);
+	}
 
 	/* Populate the directory list. */
 	if (ls.recursive) {
@@ -336,9 +415,10 @@
 		"Usage:  %s [options] [path]\n"
 		"If not path is given, the current working directory is used.\n"
 		"Options:\n"
-		"  -h, --help       A short option summary\n"
-		"  -u, --unsort     Do not sort directory entries\n"
-		"  -r, --recursive  List subdirectories recursively\n",
+		"  -h, --help           A short option summary\n"
+		"  -u, --unsort         Do not sort directory entries\n"
+		"  -r, --recursive      List subdirectories recursively\n"
+		"  -l, --long-format    List the files as a list with extra information\n",
 		cmdname);
 	}
 
@@ -362,7 +442,7 @@
 	argc = cli_count_args(argv);
 	
 	for (c = 0, optind = 0, opt_ind = 0; c != -1;) {
-		c = getopt_long(argc, argv, "hur", long_options, &opt_ind);
+		c = getopt_long(argc, argv, "hurl", long_options, &opt_ind);
 		switch (c) {
 		case 'h':
 			help_cmd_ls(HELP_LONG);
@@ -373,6 +453,9 @@
 		case 'r':
 			ls.recursive = 1;
 			break;
+		case 'l':
+		    ls.long_format = 1;
+		    break;
 		}
 	}
 	
@@ -393,7 +476,12 @@
 	scope = ls_scope(de.name, &de);
 	switch (scope) {
 	case LS_FILE:
-		ls_print(&de);
+		if (ls.long_format) {
+			ls_print_long_format(&de, 1);
+		}
+		else {
+			ls_print_columns_listing(&de, 1);
+		}
 		break;
 	case LS_DIR:
 		dirp = opendir(de.name);

=== modified file 'uspace/app/bdsh/cmds/modules/ls/ls.h'
--- uspace/app/bdsh/cmds/modules/ls/ls.h	2012-03-25 18:46:13 +0000
+++ uspace/app/bdsh/cmds/modules/ls/ls.h	2012-04-14 17:55:59 +0000
@@ -8,9 +8,13 @@
 
 typedef struct {
 	/* Options set at runtime. */
+	unsigned int long_format;
 	unsigned int recursive;
 	unsigned int sort;
 
+	/* Terminal's number of columns. */
+	sysarg_t cols;
+
 } ls_job_t;
 
 /** Structure to represent a directory entry.

