From 9e91bb1d1c2f17c27a13217000f7a6c4a5e7535b Mon Sep 17 00:00:00 2001 From: "Kirill Lipatov (Leency)" Date: Wed, 27 Sep 2017 18:44:15 +0000 Subject: [PATCH] * help now displays the list of commands in three columns * ps now displays the RAM size used by the process * ls now displays all files not in one but in several columns, the old single column output is still accessible via the key '-1' git-svn-id: svn://kolibrios.org@7024 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/system/shell/Docs_rus.txt | 3 +- programs/system/shell/History.txt | 7 +++ programs/system/shell/cmd/cmd_help.c | 7 ++- programs/system/shell/cmd/cmd_ls.c | 59 +++++++++++++++++++--- programs/system/shell/cmd/cmd_ps.c | 4 +- programs/system/shell/globals.h | 2 +- programs/system/shell/locale/eng/globals.h | 2 +- programs/system/shell/system/boolean.h | 2 + 8 files changed, 74 insertions(+), 12 deletions(-) diff --git a/programs/system/shell/Docs_rus.txt b/programs/system/shell/Docs_rus.txt index 5531e47944..554aae2987 100644 --- a/programs/system/shell/Docs_rus.txt +++ b/programs/system/shell/Docs_rus.txt @@ -43,12 +43,13 @@ help history cписок последних использованных команд kill убивает процесс по . kill all убивает все процессы, слоты >=2 ls выводит список файлов в текущем каталоге или указанном <каталоге> + ключ '-1' выводит список в одну колонку, иначе многоколоночный вывод mkdir cоздает <каталог>. Поддерживаются абсолюные и относительные пути more выводит содержимое <файла> на экран ps показывает список процессов и их PID, если задать <имя>, покажет %CPU, используемую память и запомнит внутреннюю переменную LASTPID (полезно для команды waitfor) - <имя> - это первые 10 букв имени исполняемого файла без расширения + <имя> - это первые 11 букв имени исполняемого файла без расширения pwd показывает имя текущего каталога reboot перезагружает компьютер или ядро KolibriOS. reboot kernel перезапустить ядро Kolibri rm удаляет <файл> diff --git a/programs/system/shell/History.txt b/programs/system/shell/History.txt index 3454eac2d6..5a2376a6f4 100644 --- a/programs/system/shell/History.txt +++ b/programs/system/shell/History.txt @@ -1,3 +1,10 @@ +Shell 0.7.7 // 06.02.2017 // Leency +* help ⥯Ґам ўлў®¤Ёв бЇЁб®Є Є®¬¬ ­¤ ў ваЁ Є®«®­ЄЁ +* ps ⥯Ґам ўлў®¤Ёв а §¬Ґа Ћ‡“, ЁбЇ®«м§гҐ¬л© Їа®жҐбᮬ +* ls ⥯Ґам ўлў®¤Ёв ўбҐ д ©«л ­Ґ ў ®¤­г,   ў ­ҐбЄ®«мЄ® Є®«®­®Є + а §¬Ґа Є®«®­®Є а бзЁвлў Ґвбп Ёбе®¤п Ё§ б ¬®Ј® ¤«Ё­­®Ј® Ё¬Ґ­Ё д ©«  ў Ї ЇЄҐ + бв ал© ўлў®¤ бЇЁбЄ®¬ Ї® ЇаҐ¦­Ґ¬г ¤®бвгЇҐ­ зҐаҐ§ Є«оз '-1' + Shell 0.7.6 // 06.02.2017 // Siemargl * ” ©«®ўлҐ ®ЇҐа жЁЁ ЁбЇ®«м§гов 64-bit а §¬Ґал д ©«®ў. cp ⥯Ґам Ї®­Ё¬ Ґв, Ґб«Ё - Є в «®Ј diff --git a/programs/system/shell/cmd/cmd_help.c b/programs/system/shell/cmd/cmd_help.c index 73b2af5c77..77af706f67 100644 --- a/programs/system/shell/cmd/cmd_help.c +++ b/programs/system/shell/cmd/cmd_help.c @@ -12,9 +12,14 @@ int i; if ( !strlen(cmd) ) { + int columns_max=3; printf (available, NUM_OF_CMD); for (i = 0; i < NUM_OF_CMD; i++) - printf(" %s\n\r", COMMANDS[i].name); + { + printf(" %-12s", COMMANDS[i].name); + if ((i) && ((i+1)%columns_max == 0)) printf("\n\r"); + } + if ((i)%columns_max != 0) printf("\n\r"); return TRUE; } else diff --git a/programs/system/shell/cmd/cmd_ls.c b/programs/system/shell/cmd/cmd_ls.c index 18de3b3dac..741251474d 100644 --- a/programs/system/shell/cmd/cmd_ls.c +++ b/programs/system/shell/cmd/cmd_ls.c @@ -4,11 +4,13 @@ int cmd_ls(char dir[]) kol_struct70 k70; unsigned *n; -unsigned num_of_file; +unsigned num_of_file; // number of files in directory unsigned *t; -unsigned type_of_file; +unsigned type_of_file; // check is this a file or a folder int i, result; +bool single_column_mode = FALSE; + k70.p00 = 1; k70.p04 = 0; @@ -17,22 +19,27 @@ k70.p12 = 2; // just for test exist & read number of entries k70.p16 = (unsigned) malloc(32+k70.p12*560); k70.p20 = 0; -/// !!! -// …б«Ё ls § ЇгбЄ Ґвбп ЎҐ§ Ї а ¬Ґва®ў, Їа®б¬ ваЁў Ґ¬ ⥪гйЁ© Є в «®Ј + +if (!strnicmp(dir,"-1",1)) + { + single_column_mode = TRUE; + dir += 3; + } + if ( !strlen(dir) ) k70.p21 = cur_dir; else k70.p21 = dir; result = kol_file_70(&k70); -if ( !((result==0) || (result==6)) ) // Їа®ўҐа塞 бгйҐбвў®ў ­ЁҐ Є в «®Ј  +if ( !((result==0) || (result==6)) ) // check does the directory exists { free( (void*) k70.p16); return FALSE; } n = (unsigned*) (k70.p16+8); -num_of_file = *n; // зЁб«® д ©«®ў ў Є в «®ЈҐ +num_of_file = *n; // now read full directory k70.p12 = num_of_file; @@ -48,7 +55,12 @@ if ( !((result==0) || (result==6)) ) return FALSE; } -for (i = 0; i < num_of_file; i++) +// if there was '-1' param, then show single column mode +// otherwise show files in several columns +if (single_column_mode == TRUE) +{ +_SINGLE_COLUMN_MODE: + for (i = 0; i < num_of_file; i++) { printf (" %s", k70.p16+32+40+(264+40)*i); t = (unsigned*) (k70.p16+32+(264+40)*i); @@ -57,6 +69,39 @@ for (i = 0; i < num_of_file; i++) printf ("/"); printf ("\n\r"); } +} +else +{ + int longest_name_len = 0; + int console_window_width = 78; //need to get this value from console.obj if it's possible + for (i = 0; i < num_of_file; i++) + { + int current_name_len; + current_name_len = strlen( (char*)k70.p16+32+40+(264+40)*i); + if (current_name_len > longest_name_len) longest_name_len = current_name_len; + } + + longest_name_len+=2; //consider space separator and '/' symbol for folders + int columns_max = console_window_width / longest_name_len; + + if (longest_name_len >= console_window_width) goto _SINGLE_COLUMN_MODE; //there was too long filename + + for (i = 0; i < num_of_file; i++) + { + char cur_file[2048]; + strncpy(cur_file, (char*)k70.p16+32+40+(304)*i, sizeof(cur_file)-2); + + t = (unsigned*) (k70.p16+32+(304)*i); + type_of_file = *t; + + if ( (0x10 == (type_of_file&0x10)) || (8 == (type_of_file&8)) ) strcat(cur_file, "/"); + + printf ("%*s", -longest_name_len, cur_file); + + if ((i>0) && ((i+1)%columns_max == 0)) printf ("\n\r"); + } + if ((i)%columns_max != 0) printf("\n\r"); +} free((void*)k70.p16); return TRUE; diff --git a/programs/system/shell/cmd/cmd_ps.c b/programs/system/shell/cmd/cmd_ps.c index 65e8b334bd..b07290ddb4 100644 --- a/programs/system/shell/cmd/cmd_ps.c +++ b/programs/system/shell/cmd/cmd_ps.c @@ -13,6 +13,8 @@ if (NULL == buf1k) sel = param && strlen(param) > 0; +printf (" PID NAME RAM KB\n\r", PID, buf1k+10); + for (i = 1;;i++) { n = kol_process_info(i, buf1k); @@ -22,7 +24,7 @@ for (i = 1;;i++) { if (!sel || 0 == strnicmp(param, buf1k+10, 10)) { - printf (" %7d %s\n\r", PID, buf1k+10); + printf (" %7d %11s %d\n\r", PID, buf1k+10, (*(int*)(buf1k+26)+1)/1024); if (sel) { LAST_PID = PID; diff --git a/programs/system/shell/globals.h b/programs/system/shell/globals.h index 5cefd96104..9dd6caf9bb 100644 --- a/programs/system/shell/globals.h +++ b/programs/system/shell/globals.h @@ -1,5 +1,5 @@ -#define SHELL_VERSION "0.7.6" +#define SHELL_VERSION "0.7.7" extern char PATH[256]; extern char PARAM[256]; diff --git a/programs/system/shell/locale/eng/globals.h b/programs/system/shell/locale/eng/globals.h index faf04e0368..ae1b9d14df 100644 --- a/programs/system/shell/locale/eng/globals.h +++ b/programs/system/shell/locale/eng/globals.h @@ -13,7 +13,7 @@ const command_t COMMANDS[]= {"help", " Gives help on commands. Usage:\n\r help ;it lists all builtins\n\r help ;help on command\n\r", &cmd_help}, {"history", " Lists used commands\n\r", &cmd_history}, {"kill", " Stops a running process. Usage:\n\r kill \n\r kill all\n\r", &cmd_kill}, - {"ls", " Lists the files in a directory. Usage:\n\r ls ;lists the files in current directory\n\r ls ;lists the files at specified folder\n\r", &cmd_ls}, + {"ls", " Lists the files in a directory. Usage:\n\r ls ;lists the files in current directory\n\r ls ;lists the files at specified folder\n\r ls -1 ;lists the files in a single column\n\r", &cmd_ls}, {"mkdir", " Makes directory. Usage:\n\r mkdir ;creates the folder in working directory\n\r mkdir ;create folder by specified path\n\r", &cmd_mkdir}, {"more", " Displays a file data to the screen. Usage:\n\r more \n\r", &cmd_more}, {"ps", " Lists the current processes running\n\r or shows more info on and save LASTPID\n\r", &cmd_ps}, diff --git a/programs/system/shell/system/boolean.h b/programs/system/shell/system/boolean.h index 072ddad2f3..bd9efdf511 100644 --- a/programs/system/shell/system/boolean.h +++ b/programs/system/shell/system/boolean.h @@ -1,3 +1,5 @@ +#define bool int + #define FALSE 0 #define TRUE 1