Compare commits
No commits in common. "4f09deb394881c322c27f716c7d5cc18fe6d262f" and "f136728d78e10411618a0c26104413a035d35fe2" have entirely different histories.
4f09deb394
...
f136728d78
5 changed files with 12 additions and 24 deletions
|
@ -3,9 +3,11 @@
|
|||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "parse.h"
|
||||
|
||||
unsigned char invoke(struct Args args) {
|
||||
pid_t child = fork();
|
||||
if (child == 0) {
|
||||
if (child == 0 && args.argc > 0) {
|
||||
execvp(args.argv[0], args.argv);
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,7 @@
|
|||
#ifndef COMMAND_H
|
||||
#define COMMAND_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
struct Args {
|
||||
unsigned int argc;
|
||||
size_t argv_size;
|
||||
char **argv;
|
||||
};
|
||||
#include "parse.h"
|
||||
|
||||
unsigned char invoke(struct Args args);
|
||||
|
||||
|
|
13
src/main.c
13
src/main.c
|
@ -18,19 +18,6 @@ int main() {
|
|||
struct Args args = parse(input_line);
|
||||
free(input_line);
|
||||
|
||||
if (args.argc > 0) {
|
||||
invoke(args);
|
||||
}
|
||||
|
||||
{
|
||||
unsigned int i = 0;
|
||||
while (i < args.argc) {
|
||||
free(args.argv[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
if (args.argv != NULL) {
|
||||
free(args.argv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,6 @@ struct Args parse(char *line) {
|
|||
struct Args args;
|
||||
args.argc = 0;
|
||||
args.argv_size = 0;
|
||||
args.argv = NULL;
|
||||
|
||||
parse_worker(&args, line, 0, line);
|
||||
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
#ifndef PARSE_H
|
||||
#define PARSE_H
|
||||
|
||||
#include "command.h"
|
||||
#include <sys/types.h>
|
||||
|
||||
struct Args {
|
||||
unsigned int argc;
|
||||
size_t argv_size;
|
||||
char **argv;
|
||||
};
|
||||
|
||||
void add_arg(struct Args *args, char *arg_ptr, unsigned int arg_length);
|
||||
void parse_worker(struct Args *args, char *arg_position, unsigned int arg_length, char *line);
|
||||
|
|
Loading…
Reference in a new issue