chore: change struct
This commit is contained in:
parent
c1a1726430
commit
7d7030a2d9
7 changed files with 37 additions and 15 deletions
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
|
@ -1,6 +1,9 @@
|
|||
{
|
||||
"files.associations": {
|
||||
"stdio.h": "c"
|
||||
"stdio.h": "c",
|
||||
"stdlib.h": "c",
|
||||
"loop.h": "c",
|
||||
"exec.h": "c"
|
||||
},
|
||||
"editor.tabSize": 2
|
||||
}
|
2
Makefile
2
Makefile
|
@ -1,4 +1,4 @@
|
|||
OBJ=main.o line.o
|
||||
OBJ=main.o line.o loop.o exec.o
|
||||
CC=gcc
|
||||
CFLAGS= -O3 -Wall
|
||||
|
||||
|
|
12
line.c
12
line.c
|
@ -57,6 +57,9 @@ char **splitLine(char *line) {
|
|||
|
||||
while (token != NULL) {
|
||||
tokens[position] = token;
|
||||
#ifdef DEBUG
|
||||
fprintf(stdout, "debug: tokens[%d] = %s\n", position, tokens[position]);
|
||||
#endif
|
||||
position++;
|
||||
|
||||
/* if the buffer is full, reallocate */
|
||||
|
@ -76,12 +79,3 @@ char **splitLine(char *line) {
|
|||
tokens[position] = NULL;
|
||||
return tokens;
|
||||
}
|
||||
|
||||
void line() {
|
||||
char *line;
|
||||
int status = 1;
|
||||
char str;
|
||||
printf("> ");
|
||||
line = readLine();
|
||||
free(line);
|
||||
}
|
4
line.h
4
line.h
|
@ -1,5 +1,7 @@
|
|||
#ifndef _LINE_H_
|
||||
#define _LINE_H_
|
||||
#define LINE_BUF_SIZE 1024
|
||||
void line();
|
||||
|
||||
char *readLine(void);
|
||||
char **splitLine(char *line);
|
||||
#endif
|
20
loop.c
Normal file
20
loop.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "line.h"
|
||||
#include "loop.h"
|
||||
#include "exec.h"
|
||||
|
||||
int loop() {
|
||||
|
||||
char *line;
|
||||
char **args;
|
||||
int status = 1;
|
||||
printf("> ");
|
||||
line = readLine();
|
||||
args = splitLine(line);
|
||||
status = forkExec(args);
|
||||
free(line);
|
||||
free(args);
|
||||
return 0;
|
||||
}
|
4
loop.h
Normal file
4
loop.h
Normal file
|
@ -0,0 +1,4 @@
|
|||
#ifndef _LOOP_H_
|
||||
#define _LOOP_H_
|
||||
int loop();
|
||||
#endif
|
5
main.c
5
main.c
|
@ -2,8 +2,7 @@
|
|||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include "line.h"
|
||||
|
||||
#include "loop.h"
|
||||
|
||||
void intHandler(int dummy) {
|
||||
printf("\nend!\n");
|
||||
|
@ -19,7 +18,7 @@ int main(int argc, char *argv[]) {
|
|||
printf("DEBUG is defined\n");
|
||||
#endif
|
||||
while (1) {
|
||||
line();
|
||||
loop();
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue