fixed. Support building in one binary
This commit is contained in:
parent
7d0207ace2
commit
33b89e64da
38 changed files with 285 additions and 163 deletions
|
@ -4,6 +4,7 @@
|
|||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include "make_path.h"
|
||||
#include "get_stat.h"
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include "mode_to_str.h"
|
||||
#include "make_path.h"
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(const int argc, char **argv, const char **envp) {
|
||||
int main(const int argc, char **argv) {
|
||||
int i;
|
||||
for (i = 1; i < argc; i++) {
|
||||
char *val = strchr(argv[i], '=');
|
||||
|
@ -21,10 +21,8 @@ int main(const int argc, char **argv, const char **envp) {
|
|||
|
||||
/* Print env */
|
||||
if (i == argc) {
|
||||
while (*envp)
|
||||
puts(*envp++);
|
||||
|
||||
return 0;
|
||||
fputs("env: not enought opearands\n", stderr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
execvp(argv[i], argv + i);
|
||||
|
|
25
src/grep.c
25
src/grep.c
|
@ -11,6 +11,11 @@ typedef struct {
|
|||
static PATTERN *regexs;
|
||||
static size_t r_size;
|
||||
|
||||
static char i_flag;
|
||||
static char F_flag;
|
||||
static char E_flag;
|
||||
static char H_flag;
|
||||
|
||||
static int addpattern(char *str) {
|
||||
if (regexs == NULL) {
|
||||
regexs = malloc(sizeof(PATTERN));
|
||||
|
@ -29,16 +34,16 @@ static int addpattern(char *str) {
|
|||
}
|
||||
regexs = regexs_tmp;
|
||||
|
||||
/* Add new pattern */
|
||||
regexs[r_size].pattern = str;
|
||||
|
||||
|
||||
r_size++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
int opt;
|
||||
while ((opt = getopt(argc, argv, "e:")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "e:iFH")) != -1) {
|
||||
switch (opt) {
|
||||
case 'e':
|
||||
if (addpattern(optarg))
|
||||
|
@ -46,8 +51,20 @@ int main(int argc, char **argv) {
|
|||
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
i_flag = 1;
|
||||
break;
|
||||
|
||||
case 'F':
|
||||
F_flag = 1;
|
||||
break;
|
||||
|
||||
case 'H':
|
||||
H_flag = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("grep [e] [FILE]\n\t-e PTRN Pattern to match\n");
|
||||
printf("grep [eiFH] [FILE]\n\t-e PTRN Pattern to match\n\t-i Ignore case\n\t-H Add 'filename:' prefix\n\t-F PATTERN is a literal (not regexp)\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ int main(int argc, char **argv) {
|
|||
argc -= optind;
|
||||
|
||||
if ((n_flag || !a_flag) && argc == 0) {
|
||||
fprintf(stderr, "kill: missing operands\n");
|
||||
fputs("kill: missing operands\n", stderr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
1
src/ln.c
1
src/ln.c
|
@ -1,5 +1,6 @@
|
|||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "make_path.h"
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static int printvars(int len, char **names) {
|
||||
extern char **environ;
|
||||
|
||||
static int printvars(int len, char **names, char n_flag) {
|
||||
int ret = 0;
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
|
@ -13,28 +15,38 @@ static int printvars(int len, char **names) {
|
|||
continue;
|
||||
}
|
||||
|
||||
printf("%s\n", val);
|
||||
printf("%s%c", val, n_flag);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv, const char **envp) {
|
||||
int main(int argc, char **argv) {
|
||||
char n_flag = '\n';
|
||||
|
||||
int opt;
|
||||
while ((opt = getopt(argc, argv, "0")) != -1) {
|
||||
puts("printenv [var1 var2...]");
|
||||
return 0;
|
||||
switch (opt) {
|
||||
case 'n':
|
||||
n_flag = '\0';
|
||||
break;
|
||||
|
||||
default:
|
||||
puts("printenv [var1 var2...]\n\t-0 NUL terminated output\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
argv += optind;
|
||||
argc -= optind;
|
||||
|
||||
if (argc == 0)
|
||||
while (*envp)
|
||||
printf("%s\n", *envp++);
|
||||
if (argc == 0) {
|
||||
while (*environ)
|
||||
printf("%s%c", *environ++, n_flag);
|
||||
}
|
||||
|
||||
else
|
||||
return printvars(argc, argv);
|
||||
return printvars(argc, argv, n_flag);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
2
src/rm.c
2
src/rm.c
|
@ -77,7 +77,7 @@ int main(int argc, char **argv) {
|
|||
break;
|
||||
|
||||
default:
|
||||
puts("rm [rif] [file1 file2...]\n\t-f Force\n\t-r Recursive\n\t-i Print prompt before remove");
|
||||
puts("rm [rif] [file1 file2...]\n\t-f Never prompt\n\t-r Recursive\n\t-i Print prompt before remove");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue