Convert tabs to spaces, alter some lines
This commit is contained in:
parent
251e88f324
commit
0d4a741186
@ -139,12 +139,8 @@ icmd_exit(int argc, char **argv)
|
|||||||
int
|
int
|
||||||
icmd_cls(int argc, char **argv)
|
icmd_cls(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int i = 24;
|
/* use external command to do this job */
|
||||||
|
return system("clear -x");
|
||||||
while (i--)
|
|
||||||
putchar('\n');
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
32
src/main.c
32
src/main.c
@ -12,8 +12,8 @@
|
|||||||
#include "icmd.h"
|
#include "icmd.h"
|
||||||
|
|
||||||
|
|
||||||
#define INPUT_MAX_LEN 1024
|
#define INPUT_MAX_LEN 1023
|
||||||
#define PATH_MAX_LEN 4096
|
#define PATH_MAX_LEN 4095
|
||||||
|
|
||||||
#define TOKENS_NUM_MAX 512
|
#define TOKENS_NUM_MAX 512
|
||||||
#define TOKENS_ARGS_SIZE 2048
|
#define TOKENS_ARGS_SIZE 2048
|
||||||
@ -40,8 +40,8 @@ void
|
|||||||
die(int status, char *format, ...)
|
die(int status, char *format, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
|
|
||||||
if (status != 0)
|
if (status != 0)
|
||||||
puts("psh: error: ");
|
puts("psh: error: ");
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ sighup(int signal)
|
|||||||
void
|
void
|
||||||
sigint(int signal)
|
sigint(int signal)
|
||||||
{
|
{
|
||||||
die(0, "Caught ^C");
|
die(0, "\nCaught ^C, exiting...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -98,6 +98,7 @@ tokenize(char *input)
|
|||||||
return argc;
|
return argc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
call_ecmd(int argc, char **argv)
|
call_ecmd(int argc, char **argv)
|
||||||
{
|
{
|
||||||
@ -106,9 +107,8 @@ call_ecmd(int argc, char **argv)
|
|||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
pid = fork();
|
pid = fork();
|
||||||
|
|
||||||
if (pid == -1)
|
if (pid == -1)
|
||||||
die(-1, "fork failed");
|
die(-1, "Fork failed");
|
||||||
|
|
||||||
/* parent */
|
/* parent */
|
||||||
if (pid)
|
if (pid)
|
||||||
@ -117,7 +117,7 @@ call_ecmd(int argc, char **argv)
|
|||||||
/* child */
|
/* child */
|
||||||
execvp(argv[0], argv);
|
execvp(argv[0], argv);
|
||||||
|
|
||||||
/* if we are here then called program failed */
|
/* if we end up here then exec failed */
|
||||||
err = strerror(errno);
|
err = strerror(errno);
|
||||||
print("%s: %s", argv[0], err);
|
print("%s: %s", argv[0], err);
|
||||||
|
|
||||||
@ -128,8 +128,8 @@ call_ecmd(int argc, char **argv)
|
|||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char input[INPUT_MAX_LEN];
|
char input[INPUT_MAX_LEN+1];
|
||||||
char cwd[PATH_MAX_LEN];
|
char cwd[PATH_MAX_LEN+1];
|
||||||
int num_tokens, ret;
|
int num_tokens, ret;
|
||||||
|
|
||||||
signal(SIGINT, sigint);
|
signal(SIGINT, sigint);
|
||||||
@ -143,8 +143,8 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
printf("[%s] ", cwd);
|
printf("[%s] ", cwd);
|
||||||
|
|
||||||
if (!fgets(input, sizeof(input)-1, stdin))
|
if (!fgets(input, INPUT_MAX_LEN, stdin))
|
||||||
die(0, "Caught ^D");
|
die(0, "\nCaught ^D, exiting...\n");
|
||||||
|
|
||||||
if ((num_tokens = tokenize(input)) < 0)
|
if ((num_tokens = tokenize(input)) < 0)
|
||||||
die(1, "Could not parse input");
|
die(1, "Could not parse input");
|
||||||
@ -153,19 +153,17 @@ main(int argc, char **argv)
|
|||||||
if (num_tokens == 0)
|
if (num_tokens == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* search for internal commands first */
|
/* search for internal commands */
|
||||||
if ((ret = find_icmd(g_tokens[0])) >= 0)
|
if ((ret = find_icmd(g_tokens[0])) >= 0)
|
||||||
{
|
{
|
||||||
ret = call_icmd(ret, num_tokens, g_tokens);
|
if((ret = call_icmd(ret, num_tokens, g_tokens)))
|
||||||
|
|
||||||
if (ret)
|
|
||||||
print("Internal command '%s' failed with error code: %d", g_tokens[0], ret);
|
print("Internal command '%s' failed with error code: %d", g_tokens[0], ret);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = call_ecmd(num_tokens, g_tokens);
|
/* no such internal command, try to execute external */
|
||||||
if (ret)
|
if ((ret = call_ecmd(num_tokens, g_tokens)))
|
||||||
print("External command '%s' failed with error code: %d", g_tokens[0], ret);
|
print("External command '%s' failed with error code: %d", g_tokens[0], ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user