From eb8588266e08d773f277a71e07e160a26c61555d Mon Sep 17 00:00:00 2001 From: Yumingz Date: Wed, 26 Nov 2014 00:06:47 -0400 Subject: [PATCH 1/6] Add main function. fixed #1. Add main function. fixed #1. --- shellZilla.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/shellZilla.c b/shellZilla.c index 554535a..da886af 100644 --- a/shellZilla.c +++ b/shellZilla.c @@ -13,3 +13,73 @@ #define SHELL_HIS_CMD_CNT_MAX 10 #define PATH_LEN_MAX 1024 #define PROMPT_LEN_MAX 1024 + + +int main() +{ + char shellPrompt[PROMPT_LEN_MAX]; + char cwd[PATH_LEN_MAX]; + char *userInput = NULL; + char curFolder[64]; + char *inputWithNoSpace = NULL; + char cmd[PROMPT_LEN_MAX]; + char param[PROMPT_LEN_MAX]; + + /*init the completion function*/ + funShellZillaReadLineIni(); + + /*set the command history count to 10*/ + stifle_history(SHELL_HIS_CMD_CNT_MAX); + while(1) + { + memset(cwd, 0, sizeof(cwd)); + getcwd(cwd, sizeof(cwd)); + + memset(curFolder, 0, sizeof(curFolder)); + /*just get the folder name in current directory*/ + funShellZillaGetCurFolder(cwd, curFolder); + memset(shellPrompt, 0, sizeof(shellPrompt)); + + sprintf(shellPrompt, "%s@%s:%s $", getenv("USER"), "ShellZilla", curFolder); + + /*read from stdinput*/ + userInput = readline(shellPrompt); + if(NULL == userInput) + { + break; + } + + /*get rid of the white space at the beginning and the end*/ + inputWithNoSpace = funShellZillaGetRidOfSpace(userInput); + /*printf("%s\n", inputWithNoSpace);*/ + + /*add the command to history*/ + add_history(inputWithNoSpace); + if(!funShellZillaIsValidCmd(inputWithNoSpace)) + { + /*if command not supported,print warning info*/ + printf("%s :command not found!\n", inputWithNoSpace); + free(userInput); + userInput = NULL; + continue; + } + + memset(cmd, 0, PROMPT_LEN_MAX); + memset(param, 0, PROMPT_LEN_MAX); + /*parse the input,get the command name and the parameter*/ + funShellZillaParse(inputWithNoSpace, cmd, param); + if(!strcmp(cmd, "quit")) + { + free(userInput); + userInput = NULL; + break; + } + /*excute the command*/ + funShellZillaExc(cmd, param); + + free(userInput); + userInput = NULL; + } + return OK; +} +#endif From 5bb640a6a2cd24409c0ae0cc3d120ef9543f4735 Mon Sep 17 00:00:00 2001 From: Yumingz Date: Wed, 26 Nov 2014 00:52:09 -0400 Subject: [PATCH 2/6] fixed #2. add current folder function.fixed #2. --- shellZilla.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/shellZilla.c b/shellZilla.c index da886af..05a4fd1 100644 --- a/shellZilla.c +++ b/shellZilla.c @@ -15,6 +15,24 @@ #define PROMPT_LEN_MAX 1024 +/*get current folder name*/ +void funShellZillaGetCurFolder(char *pCwd, char *curFolder) +{ + char *p = NULL; + int len = 0; + + p = pCwd + strlen(pCwd); + /*find the last / from the directory*/ + while(*p != '/') + { + len++; + p--; + } + memcpy(curFolder, p+1, len); + return; +} + + int main() { char shellPrompt[PROMPT_LEN_MAX]; From 8aa75938d8493862ae7e3a0707d98590ab273294 Mon Sep 17 00:00:00 2001 From: Yumingz Date: Wed, 26 Nov 2014 01:13:36 -0400 Subject: [PATCH 3/6] fixed bugs. fixed bugs for #2. --- shellZilla.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/shellZilla.c b/shellZilla.c index 05a4fd1..ebf43dc 100644 --- a/shellZilla.c +++ b/shellZilla.c @@ -32,6 +32,28 @@ void funShellZillaGetCurFolder(char *pCwd, char *curFolder) return; } +char *funShellZillaGetRidOfSpace(char *input) +{ + char *p = NULL; + char *q = NULL; + + p = input; + /*find the first char that is not whitespace*/ + while(*p == ' ') + { + p++; + } + + /*get rid of the white space at the end*/ + q = input+strlen(input)-1; + while(*q == ' ') + { + q--; + } + q++; + *q = '\0'; + return p; +} int main() { From 904c520bba2a6d25e361ce378cca82809e24f94a Mon Sep 17 00:00:00 2001 From: Yumingz Date: Wed, 26 Nov 2014 01:20:44 -0400 Subject: [PATCH 4/6] Update shellZilla.c add we now support function. --- shellZilla.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/shellZilla.c b/shellZilla.c index ebf43dc..66ffdca 100644 --- a/shellZilla.c +++ b/shellZilla.c @@ -14,6 +14,12 @@ #define PATH_LEN_MAX 1024 #define PROMPT_LEN_MAX 1024 +/*command we now support*/ +char *supCmd[] = +{ + "currentdir", + NULL +}; /*get current folder name*/ void funShellZillaGetCurFolder(char *pCwd, char *curFolder) From 98ee4a025f8b191dbda9b916b378467d2d075d09 Mon Sep 17 00:00:00 2001 From: Yumingz Date: Wed, 26 Nov 2014 01:34:23 -0400 Subject: [PATCH 5/6] fixed #6 add shell author and shell version. --- shellZilla.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/shellZilla.c b/shellZilla.c index 66ffdca..e33cafa 100644 --- a/shellZilla.c +++ b/shellZilla.c @@ -18,6 +18,7 @@ char *supCmd[] = { "currentdir", + "ver", NULL }; @@ -61,6 +62,23 @@ char *funShellZillaGetRidOfSpace(char *input) return p; } +/*function for command ver*/ +void funShellZillaExcVer(char *pCmd, char *pParam) +{ + printf("\r\n**********************************************************************\n"); + printf("**************************SHELL ZILLA*********************************\n"); + printf("**********************************************************************\n"); + printf("*current version : 1.1 *\n"); + printf("*feature description: 1.get current folder name *\n"); + printf("* 2.shell version *\n"); + printf("* 3. *\n"); + printf("*author : Wentao Xu, Yuming Zhang, Zhenqing Luo *\n"); + printf("**********************************************************************\r\n"); + return; +} + + + int main() { char shellPrompt[PROMPT_LEN_MAX]; From 1b85f99ae7d92afec8cab58d744a3137e49affb5 Mon Sep 17 00:00:00 2001 From: Yumingz Date: Wed, 26 Nov 2014 02:14:25 -0400 Subject: [PATCH 6/6] Update shellZilla.c --- shellZilla.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shellZilla.c b/shellZilla.c index e33cafa..81335a8 100644 --- a/shellZilla.c +++ b/shellZilla.c @@ -72,7 +72,7 @@ void funShellZillaExcVer(char *pCmd, char *pParam) printf("*feature description: 1.get current folder name *\n"); printf("* 2.shell version *\n"); printf("* 3. *\n"); - printf("*author : Wentao Xu, Yuming Zhang, Zhenqing Luo *\n"); + printf("*author : Tianqi Zhou, Wentao Xu, Yuming Zhang, Zhenqing Luo *\n"); printf("**********************************************************************\r\n"); return; }