Skip to content
Snippets Groups Projects
Commit 9736728d authored by rsc's avatar rsc
Browse files

cleanup main

parent 7d4aef6c
No related branches found
No related tags found
No related merge requests found
...@@ -29,10 +29,11 @@ struct cmd cmdlist[MAXCMD]; ...@@ -29,10 +29,11 @@ struct cmd cmdlist[MAXCMD];
struct cmd *cmd; struct cmd *cmd;
char buf[BUFSIZ]; char buf[BUFSIZ];
int debug = 0; int debug;
int parse(char *s); int parse(char *s);
void runcmd(void); void runcmd(void);
int getcmd(char *buf, int nbuf);
int ioredirection(struct ionode *iolist, int nio); int ioredirection(struct ionode *iolist, int nio);
int gettoken(char *s, char **token); int gettoken(char *s, char **token);
int _gettoken(char *s, char **p1, char **p2); int _gettoken(char *s, char **p1, char **p2);
...@@ -40,19 +41,24 @@ int _gettoken(char *s, char **p1, char **p2); ...@@ -40,19 +41,24 @@ int _gettoken(char *s, char **p1, char **p2);
int int
main(void) main(void)
{ {
while(1){ while(getcmd(buf, sizeof buf) >= 0) {
puts("$ "); if(parse(buf) >= 0)
memset(buf, 0, sizeof buf); runcmd();
gets(buf, sizeof buf);
if(buf[0] == 0) // EOF
break;
if(parse(buf) < 0)
continue;
runcmd();
} }
exit(); exit();
} }
int
getcmd(char *buf, int nbuf)
{
puts("$ ");
memset(buf, 0, nbuf);
gets(buf, nbuf);
if(buf[0] == 0) // EOF
return -1;
return 0;
}
int int
parse(char *s) parse(char *s)
{ {
...@@ -61,13 +67,13 @@ parse(char *s) ...@@ -61,13 +67,13 @@ parse(char *s)
gettoken(s, 0); gettoken(s, 0);
cmd = &cmdlist[0];; cmd = &cmdlist[0];
for(i = 0; i < MAXCMD; i++) { for(i = 0; i < MAXCMD; i++) {
cmdlist[i].argc = 0; cmdlist[i].argc = 0;
cmdlist[i].token = 0; cmdlist[i].token = 0;
cmdlist[i].io = cmdlist[i].iolist; cmdlist[i].io = cmdlist[i].iolist;
} }
while(1) { for(;;){
switch((c = gettoken(0, &t))) { switch((c = gettoken(0, &t))) {
case 'w': // Add an argument case 'w': // Add an argument
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment