Revert "feat(line): add history record"

file descriptor and fork() is a mess.

This reverts commit 53bee9dfb0.
This commit is contained in:
iridiumR 2022-09-19 00:49:58 +08:00
parent 0a3efb2bd9
commit 5d3b5c5767
No known key found for this signature in database
GPG Key ID: 5574BE4450D55618
3 changed files with 6 additions and 20 deletions

View File

@ -1,9 +1,9 @@
# fish - Yet another shell with C # dish - Yet another shell with C
# TODO # TODO
- [x] History save
- [x] Environment variable settings - [x] Environment variable settings
- [ ] History save
- [ ] Color - [ ] Color
- [ ] Completion - [ ] Completion
- [ ] Config dotfile support - [ ] Config dotfile support

9
line.c
View File

@ -1,16 +1,13 @@
/* /*
* @Author: 1ridic * @Author: 1ridic
* @Date: 2022-09-18 14:14:05 * @Date: 2022-09-18 14:14:05
* @Last Modified by: 1ridic * @Last Modified by: 1ridic
* @Last Modified time: 2022-09-18 22:08:27 * @Last Modified time: 2022-09-18 14:14:05
*/ */
#include "line.h" #include "line.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h>
FILE *hf = NULL;
char *readLine(void) { char *readLine(void) {
int bufsize = LINE_BUF_SIZE; int bufsize = LINE_BUF_SIZE;
@ -29,8 +26,6 @@ char *readLine(void) {
// repleace EOF with a null character and return // repleace EOF with a null character and return
if (c == EOF || c == '\n') { if (c == EOF || c == '\n') {
buffer[position] = '\0'; buffer[position] = '\0';
time_t tick=time(NULL);
fprintf(hf,"%d:%s\n",(int)tick,buffer);
return buffer; return buffer;
} else { } else {
buffer[position] = c; buffer[position] = c;

13
main.c
View File

@ -19,9 +19,7 @@ void intHandler(int dummy) {
if (isWaiting==1) { if (isWaiting==1) {
return; return;
} }
extern FILE* hf; fprintf(stderr,"\nSIGINT exit.\n");
fprintf(stderr,"\nSIGINT exit.");
fclose(hf);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -31,18 +29,11 @@ int main(int argc, char *argv[]) {
signal(SIGINT, intHandler); signal(SIGINT, intHandler);
/* clear screen */ /* clear screen */
fprintf(stdout,"\033[H\033[J"); fprintf(stdout,"\033[H\033[J");
/* open history file */
extern FILE* hf;
const char* hf_path=strcat(getenv("HOME"), "/.dish_history");
hf = fopen(hf_path, "a+");
#ifdef DEBUG #ifdef DEBUG
fprintf(stdout,"DEBUG is defined\n"); fprintf(stdout,"DEBUG is defined\n");
#endif #endif
while (1) { while (1) {
loop(); loop();
} }
fclose(hf);
return 0; return 0;
} }