forked from KolibriOS/kolibrios
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
This commit is contained in:
parent
20cc0935c0
commit
1a5f178264
@ -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;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
|
||||
#define SHELL_VERSION "0.8.2"
|
||||
#define SHELL_VERSION "0.8.3"
|
||||
|
||||
char cmdline[256];
|
||||
|
||||
|
@ -18,7 +18,7 @@ const command_t COMMANDS[]=
|
||||
{"kill", " Stops a running process. Usage:\n\r kill <PID of process>\n\r kill all\n\r", &cmd_kill},
|
||||
{"pkill", " Kills all processes by name. Usage:\n\r pkill <process_name>\n\r", &cmd_pkill},
|
||||
{"ls", " Lists the files in a directory. Usage:\n\r ls ;lists the files in current directory\n\r ls <directory> ;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 <folder name> ;creates the folder in working directory\n\r mkdir <path><folder name> ;create folder by specified path\n\r", &cmd_mkdir},
|
||||
{"mkdir", " Create directory and parent directories as needed. Usage:\n\r mkdir <folder/name>\n\r", &cmd_mkdir},
|
||||
{"more", " Displays a file data to the screen. Usage:\n\r more <file name>\n\r", &cmd_more},
|
||||
{"ps", " Lists the current processes running\n\r or shows more info on <procname> and save LASTPID\n\r", &cmd_ps},
|
||||
{"pwd", " Displays the name of the working directory\n\r", &cmd_pwd},
|
||||
|
@ -19,7 +19,7 @@ const command_t COMMANDS[]=
|
||||
{"kill", " “¡¨¢ ¥â ¯à®æ¥áá. ˆá¯®«ì§®¢ ¨¥:\n\r kill <PID ¯à®æ¥áá >\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", " <20>®ª §ë¢ ¥â ¨¬ï ⥪ã饩 ¤¨à¥ªâ®à¨¨\n\r", &cmd_pwd},
|
||||
|
Loading…
Reference in New Issue
Block a user