psh/src/main.c

50 lines
871 B
C
Raw Normal View History

2018-12-01 18:10:17 +01:00
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <limits.h>
#include "icmd.h"
/* should be enough */
#define CMD_LINE_MAX 1024
#define CMD_PATH_MAX 4096
int
die(char *s)
{
perror(s);
exit(-1);
}
int
main(int argc, char **argv)
{
char line[CMD_LINE_MAX];
char cwd[CMD_PATH_MAX];
char *pline = line;
int ret;
for (;;)
{
/* todo: does it really fail? */
if (getcwd(cwd, sizeof(cwd)) == NULL)
die("getcwd()");
printf("[%s] ", cwd);
fgets(line, sizeof(line), stdin);
ret = call_icmds(line);
if (ret == INT_MAX)
puts("no such internal command, going on...");
else if (ret == 0)
puts("internal command succeded!");
else
puts("internal command succeded!");
}
return 0;
}