fixed builder. Rewritting ls
This commit is contained in:
parent
5d1a153fca
commit
e2934e4d5b
1
TODO
1
TODO
@ -2,6 +2,7 @@ PlainOs
|
|||||||
With "micro-" prefix
|
With "micro-" prefix
|
||||||
|
|
||||||
*Todo:
|
*Todo:
|
||||||
|
ls
|
||||||
tail
|
tail
|
||||||
uniq
|
uniq
|
||||||
head
|
head
|
||||||
|
@ -4,6 +4,9 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <signal.h>
|
||||||
#include "make_path.h"
|
#include "make_path.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
@ -35,8 +38,19 @@ void Compile(const char *src, const char *output_dir) {
|
|||||||
char *path = MakePath(src, output_dir);
|
char *path = MakePath(src, output_dir);
|
||||||
printf("[CC] Building %s -> %s\n", src, path);
|
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);
|
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);
|
free(path);
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
unsigned int a_flag;
|
unsigned int a_flag;
|
||||||
unsigned int l_flag;
|
unsigned int l_flag;
|
||||||
|
unsigned int p_flag;
|
||||||
|
|
||||||
void PrintPerm(struct stat sb) {
|
void PrintPerm(struct stat sb) {
|
||||||
if (S_ISDIR(sb.st_mode))
|
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 main(int argc, char **argv) {
|
||||||
int i;
|
int opt;
|
||||||
for (i = 1; i < argc; i++) {
|
while ((opt = getopt(argc, argv, "al")) != -1) {
|
||||||
if (argv[i][0] != '-')
|
switch (opt) {
|
||||||
break;
|
case 'a':
|
||||||
|
a_flag = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
else if (!strcmp(argv[i], "-a"))
|
case 'l':
|
||||||
a_flag = 1;
|
l_flag = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
else if (!strcmp(argv[i], "-l"))
|
default:
|
||||||
l_flag = 1;
|
printf("ls [path]\n\t[-a Show hidden files] [-l Use a long listing format]\n");
|
||||||
|
return 0;
|
||||||
else if (!strcmp(argv[i], "--help")) {
|
|
||||||
printf("ls [-a show hidden files] [-l use a long listing format] [Path]\n");
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i == argc)
|
argv += optind;
|
||||||
return list(".", 0);
|
argc -= optind;
|
||||||
|
|
||||||
if (i == argc - 1)
|
if (argc == 0)
|
||||||
return list(argv[i], 0);
|
list(".", 0);
|
||||||
|
|
||||||
else
|
|
||||||
for (; i < argc; i++)
|
|
||||||
if (list(argv[i], 1))
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user