summaryrefslogtreecommitdiff
path: root/userspace
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2014-10-22 11:30:31 +0200
committerMichal Idziorek <m.i@gmx.at>2014-10-22 11:30:31 +0200
commit09a2df20e03a90550a43e142a207560d34a6c4a0 (patch)
tree6216e3ac2a7cb4bcee97196d37722210db9ccb0e /userspace
parente457588f132cb130b5fb37d78cc2d19355cc41bd (diff)
simple tokenizer for the foolshell
Diffstat (limited to 'userspace')
-rw-r--r--userspace/foolshell.c54
1 files changed, 48 insertions, 6 deletions
diff --git a/userspace/foolshell.c b/userspace/foolshell.c
index 7a029ef..173b0b2 100644
--- a/userspace/foolshell.c
+++ b/userspace/foolshell.c
@@ -27,19 +27,61 @@ int main(int argc, char **argv)
{
prompt();
fgets(buf,255,input);
- buf[strlen(buf)-1]=0;
-// puts(buf);
+ buf[strlen(buf)-1]=0; // remove \n
process(buf);
+ }
+
+ return 0;
+}
+
+char **tokenize(char *buf)
+{
+
+ char **token;
+ token=malloc(10*sizeof(char*));
+
+ int l=strlen(buf);
+
+ int i;
+ int c=0;
+
+ for(i=0;i<l;i++)
+ {
+ // init space for next token
+ token[c]=malloc(256);
+
+ //skip all the whitespace
+ while(buf[i]==' '&&i<l)i++;
+ if(i==l)break;
+
+ //get token
+ int t=0;
+
+ while(buf[i]!=' '&&i<l)
+ {
+ token[c][t]=buf[i];
+ t++;
+ i++;
+ }
+ token[c][t]=0;
+
+
+// printf("token %i : <%s>\n",c, token[c]);
+ c++;
}
+ return token;
- return 0;
}
-int process(char *command)
+int process(char *buf)
{
- // copied from trottelshell
+
+ char **token=tokenize(buf);
+ char *command=token[0];
+ // puts(command);
+ // copied from trottelshell
if(!strcmp(command,"HELP"))
{
@@ -102,7 +144,7 @@ int process(char *command)
else if(!strcmp(command,"ECHO"))
{
- printf("%s\n",command);
+ printf("%s\n",token[1]);
}
else