From 1a5f178264bc5c33e38714858f728f3623b7e544 Mon Sep 17 00:00:00 2001 From: turbocat Date: Thu, 2 Sep 2021 21:20:12 +0000 Subject: [PATCH] SHELL 0.8.3: - Added the ability to create parent directories if needed( "mkdir" command) git-svn-id: svn://kolibrios.org@9173 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/system/shell/cmd/cmd_mkdir.c | 65 +++++++++++----------- programs/system/shell/globals.h | 2 +- programs/system/shell/locale/eng/globals.h | 2 +- programs/system/shell/locale/rus/globals.h | 2 +- 4 files changed, 37 insertions(+), 34 deletions(-) diff --git a/programs/system/shell/cmd/cmd_mkdir.c b/programs/system/shell/cmd/cmd_mkdir.c index 6a8773175a..8f099e4b58 100644 --- a/programs/system/shell/cmd/cmd_mkdir.c +++ b/programs/system/shell/cmd/cmd_mkdir.c @@ -1,41 +1,44 @@ +extern int (*mkdir)(char*); int cmd_mkdir(char dir[]) { - char temp[FILENAME_MAX]; - kol_struct70 k70; - unsigned result; - - if (NULL == dir) { + unsigned dir_len = strlen(dir); + if(!dir_len){ printf(CMD_MKDIR_USAGE); return TRUE; } - if ( 0 == strcmp(dir, ".") || ( 0 == strcmp(dir, "..") ) || ( 0 == strcmp(cur_dir, "/")) ) { + char *temp = malloc(dir_len+3); + char *dir_path = strdup(dir); + ksys_bdfe_t *bdfe = malloc(sizeof(ksys_bdfe_t)); + if(!dir_path || !temp || !bdfe){ return FALSE; } - - k70.p00 = 9; - k70.p04 = 0; - //k70.p08 = 0; - k70.p12 = 0; - k70.p16 = 0; - k70.p20 = 0; - - if ( '/' == dir[0]) - k70.p21 = dir; - else { - strcpy(temp, cur_dir); - if (temp[strlen(temp)-1] != '/') - strcat(temp, "/"); // add slash - strcat(temp, dir); - k70.p21 = temp; + + if(dir[0]=='/' || dir[0]=='\\'){ + temp[0]='\0'; + }else{ + strcpy(temp,"."); } - result = kol_file_70(&k70); - - if (0 == result) - return TRUE; - else - return FALSE; - -} - + char *pch = strtok(dir_path,"\\/"); + + while (pch != NULL){ + strcat(temp, "/"); + strcat(temp, pch); + if(_ksys_file_get_info(temp, bdfe)){ + if(mkdir(temp)){ + printf("\033[0;31;40m FAIL %s\n", temp); + }else { + printf("\033[0;32;40m OK %s\n", temp); + } + }else{ + printf("\033[0;33;40m EXIST %s\n", temp); + } + pch = strtok(NULL, "\\/"); + } + printf("\033[0m"); + free(bdfe); + free(dir_path); + free(temp); + return TRUE; +} \ No newline at end of file diff --git a/programs/system/shell/globals.h b/programs/system/shell/globals.h index 84ac25d379..b1c1f9feef 100644 --- a/programs/system/shell/globals.h +++ b/programs/system/shell/globals.h @@ -1,5 +1,5 @@ -#define SHELL_VERSION "0.8.2" +#define SHELL_VERSION "0.8.3" char cmdline[256]; diff --git a/programs/system/shell/locale/eng/globals.h b/programs/system/shell/locale/eng/globals.h index 8cc04f06da..eeb4789c8b 100644 --- a/programs/system/shell/locale/eng/globals.h +++ b/programs/system/shell/locale/eng/globals.h @@ -18,7 +18,7 @@ const command_t COMMANDS[]= {"kill", " Stops a running process. Usage:\n\r kill \n\r kill all\n\r", &cmd_kill}, {"pkill", " Kills all processes by name. Usage:\n\r pkill \n\r", &cmd_pkill}, {"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}, + {"mkdir", " Create directory and parent directories as needed. Usage:\n\r mkdir \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}, {"pwd", " Displays the name of the working directory\n\r", &cmd_pwd}, diff --git a/programs/system/shell/locale/rus/globals.h b/programs/system/shell/locale/rus/globals.h index ccfb0a40b6..be8d25995d 100644 --- a/programs/system/shell/locale/rus/globals.h +++ b/programs/system/shell/locale/rus/globals.h @@ -19,7 +19,7 @@ const command_t COMMANDS[]= {"kill", " Убивает процесс. Использование:\n\r kill \n\r kill all\n\r", &cmd_kill}, {"pkill", " Убивает все процессы по имени. Использование:\n\r pkill <имя_процесса>\n\r", &cmd_pkill}, {"ls", " Выводит список файлов. Использование:\n\r ls ;список файлов в текущем каталоге\n\r ls <директория> ;список файлов из заданной директории\n\r", &cmd_ls}, - {"mkdir", " Создает каталог. Использование:\n\r mkdir <имя папки> ;создать папку в текущем каталоге\n\r mkdir <путь><имя папки> ;создать папку по указанному пути\n\r", &cmd_mkdir}, + {"mkdir", " Создает каталог и родительские каталоги при необходимости. Использование:\n\r mkdir <имя/папки>", &cmd_mkdir}, {"more", " Выводит содержимое файла на экран. Использование:\n\r more <имя файла>\n\r", &cmd_more}, {"ps", " Выводит список процессов\n\r Если указано <имяпроцесса>, показывает больше данных и сохраняет LASTPID\n\r", &cmd_ps}, {"pwd", " Показывает имя текущей директории\n\r", &cmd_pwd},