chore: change struct

This commit is contained in:
iridiumR 2022-09-18 13:14:30 +08:00
parent c1a1726430
commit 7d7030a2d9
No known key found for this signature in database
GPG key ID: 5574BE4450D55618
7 changed files with 37 additions and 15 deletions

View file

@ -1,6 +1,9 @@
{ {
"files.associations": { "files.associations": {
"stdio.h": "c" "stdio.h": "c",
"stdlib.h": "c",
"loop.h": "c",
"exec.h": "c"
}, },
"editor.tabSize": 2 "editor.tabSize": 2
} }

View file

@ -1,4 +1,4 @@
OBJ=main.o line.o OBJ=main.o line.o loop.o exec.o
CC=gcc CC=gcc
CFLAGS= -O3 -Wall CFLAGS= -O3 -Wall

12
line.c
View file

@ -57,6 +57,9 @@ char **splitLine(char *line) {
while (token != NULL) { while (token != NULL) {
tokens[position] = token; tokens[position] = token;
#ifdef DEBUG
fprintf(stdout, "debug: tokens[%d] = %s\n", position, tokens[position]);
#endif
position++; position++;
/* if the buffer is full, reallocate */ /* if the buffer is full, reallocate */
@ -76,12 +79,3 @@ char **splitLine(char *line) {
tokens[position] = NULL; tokens[position] = NULL;
return tokens; return tokens;
} }
void line() {
char *line;
int status = 1;
char str;
printf("> ");
line = readLine();
free(line);
}

4
line.h
View file

@ -1,5 +1,7 @@
#ifndef _LINE_H_ #ifndef _LINE_H_
#define _LINE_H_ #define _LINE_H_
#define LINE_BUF_SIZE 1024 #define LINE_BUF_SIZE 1024
void line();
char *readLine(void);
char **splitLine(char *line);
#endif #endif

20
loop.c Normal file
View 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
View file

@ -0,0 +1,4 @@
#ifndef _LOOP_H_
#define _LOOP_H_
int loop();
#endif

5
main.c
View file

@ -2,8 +2,7 @@
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include "line.h" #include "loop.h"
void intHandler(int dummy) { void intHandler(int dummy) {
printf("\nend!\n"); printf("\nend!\n");
@ -19,7 +18,7 @@ int main(int argc, char *argv[]) {
printf("DEBUG is defined\n"); printf("DEBUG is defined\n");
#endif #endif
while (1) { while (1) {
line(); loop();
} }
return 0; return 0;
} }