Convert tabs to spaces, alter some lines

This commit is contained in:
Artur Tamborski 2018-12-29 19:28:15 +01:00
parent 251e88f324
commit 0d4a741186
2 changed files with 61 additions and 67 deletions

View File

@ -139,12 +139,8 @@ icmd_exit(int argc, char **argv)
int
icmd_cls(int argc, char **argv)
{
int i = 24;
while (i--)
putchar('\n');
return 0;
/* use external command to do this job */
return system("clear -x");
}

View File

@ -12,8 +12,8 @@
#include "icmd.h"
#define INPUT_MAX_LEN 1024
#define PATH_MAX_LEN 4096
#define INPUT_MAX_LEN 1023
#define PATH_MAX_LEN 4095
#define TOKENS_NUM_MAX 512
#define TOKENS_ARGS_SIZE 2048
@ -40,8 +40,8 @@ void
die(int status, char *format, ...)
{
va_list args;
va_start(args, format);
if (status != 0)
puts("psh: error: ");
@ -68,7 +68,7 @@ sighup(int signal)
void
sigint(int signal)
{
die(0, "Caught ^C");
die(0, "\nCaught ^C, exiting...");
}
@ -98,6 +98,7 @@ tokenize(char *input)
return argc;
}
int
call_ecmd(int argc, char **argv)
{
@ -106,9 +107,8 @@ call_ecmd(int argc, char **argv)
pid_t pid;
pid = fork();
if (pid == -1)
die(-1, "fork failed");
die(-1, "Fork failed");
/* parent */
if (pid)
@ -117,7 +117,7 @@ call_ecmd(int argc, char **argv)
/* child */
execvp(argv[0], argv);
/* if we are here then called program failed */
/* if we end up here then exec failed */
err = strerror(errno);
print("%s: %s", argv[0], err);
@ -128,8 +128,8 @@ call_ecmd(int argc, char **argv)
int
main(int argc, char **argv)
{
char input[INPUT_MAX_LEN];
char cwd[PATH_MAX_LEN];
char input[INPUT_MAX_LEN+1];
char cwd[PATH_MAX_LEN+1];
int num_tokens, ret;
signal(SIGINT, sigint);
@ -143,8 +143,8 @@ main(int argc, char **argv)
printf("[%s] ", cwd);
if (!fgets(input, sizeof(input)-1, stdin))
die(0, "Caught ^D");
if (!fgets(input, INPUT_MAX_LEN, stdin))
die(0, "\nCaught ^D, exiting...\n");
if ((num_tokens = tokenize(input)) < 0)
die(1, "Could not parse input");
@ -153,19 +153,17 @@ main(int argc, char **argv)
if (num_tokens == 0)
continue;
/* search for internal commands first */
/* search for internal commands */
if ((ret = find_icmd(g_tokens[0])) >= 0)
{
ret = call_icmd(ret, num_tokens, g_tokens);
if (ret)
if((ret = call_icmd(ret, num_tokens, g_tokens)))
print("Internal command '%s' failed with error code: %d", g_tokens[0], ret);
continue;
}
ret = call_ecmd(num_tokens, g_tokens);
if (ret)
/* no such internal command, try to execute external */
if ((ret = call_ecmd(num_tokens, g_tokens)))
print("External command '%s' failed with error code: %d", g_tokens[0], ret);
}
}