diff --git a/TODO b/TODO index ed62857..88aa615 100644 --- a/TODO +++ b/TODO @@ -2,6 +2,7 @@ PlainOs With "micro-" prefix *Todo: +ls tail uniq head diff --git a/build b/build new file mode 100755 index 0000000..8808f26 Binary files /dev/null and b/build differ diff --git a/builder/builder.c b/builder/builder.c index 035e82d..7f18ca5 100644 --- a/builder/builder.c +++ b/builder/builder.c @@ -4,6 +4,9 @@ #include #include #include +#include +#include +#include #include "make_path.h" #include "config.h" @@ -35,8 +38,19 @@ void Compile(const char *src, const char *output_dir) { char *path = MakePath(src, output_dir); printf("[CC] Building %s -> %s\n", src, path); - if (fork()) + pid_t pid; + if ((pid = fork()) == 0) { execlp(CC, CC, CFLAGS, src, "-o", path, NULL); + kill(getpid(), 9); + + /* If compiler return 1 */ + exit(1); + } + + int status = 0; + waitpid(pid, &status, 0); + if (status) + exit(1); free(path); } diff --git a/coreutils/ls.c b/coreutils/ls.c index 4c6111c..2f47e29 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -14,6 +14,7 @@ unsigned int a_flag; unsigned int l_flag; +unsigned int p_flag; void PrintPerm(struct stat sb) { if (S_ISDIR(sb.st_mode)) @@ -131,34 +132,29 @@ int list(const char *path, int label) { -int main(const int argc, const char **argv) { - int i; - for (i = 1; i < argc; i++) { - if (argv[i][0] != '-') - break; +int main(int argc, char **argv) { + int opt; + while ((opt = getopt(argc, argv, "al")) != -1) { + switch (opt) { + case 'a': + a_flag = 1; + break; - else if (!strcmp(argv[i], "-a")) - a_flag = 1; + case 'l': + l_flag = 1; + break; - else if (!strcmp(argv[i], "-l")) - l_flag = 1; - - else if (!strcmp(argv[i], "--help")) { - printf("ls [-a show hidden files] [-l use a long listing format] [Path]\n"); - return 0; + default: + printf("ls [path]\n\t[-a Show hidden files] [-l Use a long listing format]\n"); + return 0; } } - if (i == argc) - return list(".", 0); + argv += optind; + argc -= optind; - if (i == argc - 1) - return list(argv[i], 0); - - else - for (; i < argc; i++) - if (list(argv[i], 1)) - return 1; + if (argc == 0) + list(".", 0); return 0; }