fixed builder. Rewritting ls

This commit is contained in:
Your Name 2023-11-08 11:05:04 +03:00
parent 5d1a153fca
commit e2934e4d5b
4 changed files with 34 additions and 23 deletions

1
TODO
View File

@ -2,6 +2,7 @@ PlainOs
With "micro-" prefix
*Todo:
ls
tail
uniq
head

BIN
build Executable file

Binary file not shown.

View File

@ -4,6 +4,9 @@
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#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);
}

View File

@ -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;
}