Revert "feat(line): add history record"
file descriptor and fork() is a mess.
This reverts commit 53bee9dfb0
.
This commit is contained in:
parent
0a3efb2bd9
commit
5d3b5c5767
3 changed files with 6 additions and 20 deletions
|
@ -1,9 +1,9 @@
|
|||
# fish - Yet another shell with C
|
||||
# dish - Yet another shell with C
|
||||
|
||||
# TODO
|
||||
|
||||
- [x] History save
|
||||
- [x] Environment variable settings
|
||||
- [ ] History save
|
||||
- [ ] Color
|
||||
- [ ] Completion
|
||||
- [ ] Config dotfile support
|
||||
|
|
9
line.c
9
line.c
|
@ -1,16 +1,13 @@
|
|||
/*
|
||||
* @Author: 1ridic
|
||||
* @Date: 2022-09-18 14:14:05
|
||||
* @Last Modified by: 1ridic
|
||||
* @Last Modified time: 2022-09-18 22:08:27
|
||||
* @Last Modified by: 1ridic
|
||||
* @Last Modified time: 2022-09-18 14:14:05
|
||||
*/
|
||||
#include "line.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
FILE *hf = NULL;
|
||||
|
||||
char *readLine(void) {
|
||||
int bufsize = LINE_BUF_SIZE;
|
||||
|
@ -29,8 +26,6 @@ char *readLine(void) {
|
|||
// repleace EOF with a null character and return
|
||||
if (c == EOF || c == '\n') {
|
||||
buffer[position] = '\0';
|
||||
time_t tick=time(NULL);
|
||||
fprintf(hf,"%d:%s\n",(int)tick,buffer);
|
||||
return buffer;
|
||||
} else {
|
||||
buffer[position] = c;
|
||||
|
|
11
main.c
11
main.c
|
@ -19,9 +19,7 @@ void intHandler(int dummy) {
|
|||
if (isWaiting==1) {
|
||||
return;
|
||||
}
|
||||
extern FILE* hf;
|
||||
fprintf(stderr,"\nSIGINT exit.");
|
||||
fclose(hf);
|
||||
fprintf(stderr,"\nSIGINT exit.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
}
|
||||
|
@ -31,18 +29,11 @@ int main(int argc, char *argv[]) {
|
|||
signal(SIGINT, intHandler);
|
||||
/* clear screen */
|
||||
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
|
||||
fprintf(stdout,"DEBUG is defined\n");
|
||||
#endif
|
||||
while (1) {
|
||||
loop();
|
||||
}
|
||||
|
||||
fclose(hf);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue