Figured out termios
This commit is contained in:
@@ -13,12 +13,19 @@
|
||||
|
||||
#ifdef __TINYC__
|
||||
#include <tcclib.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#define stderr 2
|
||||
#define SEEK_SET 0
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -723,9 +730,11 @@ int main(int argc, char* argv[]) {
|
||||
int host_islittle = 1;
|
||||
host_islittle = (*((char *)&host_islittle) == 1) ? 1 : 0;
|
||||
/* _attempt_ to disable buffering for char input/output */
|
||||
#if !defined __CC65__ && !defined __TINYC__
|
||||
setvbuf(stdin, NULL, _IONBF, 0);
|
||||
setvbuf(stdout, NULL, _IONBF, 0);
|
||||
#if !defined __CC65__
|
||||
struct termios tty_opts_raw, tty_opts_backup;
|
||||
tcgetattr(STDIN_FILENO, &tty_opts_backup);
|
||||
cfmakeraw(&tty_opts_raw);
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &tty_opts_raw);
|
||||
#endif
|
||||
/* initialize the PRNG */
|
||||
srand((unsigned)time(NULL));
|
||||
@@ -736,8 +745,10 @@ int main(int argc, char* argv[]) {
|
||||
ram.cmd_size = CMD_BUF_SIZE;
|
||||
ram.II = ram.MM = 0; /* reset all flags */
|
||||
/* process command line params */
|
||||
if(argc > 1 && argv[1][0] == 'm') /* enter minification mode, don't run the programs */
|
||||
if(argc > 1 && argv[1][0] == 'm') { /* enter minification mode, don't run the programs */
|
||||
ram.MM = 1;
|
||||
smode = 1; /* also behave as if in the silent mode */
|
||||
}
|
||||
else if(argc > 1 && argv[1][0] == 's') /* enter silent mode, don't print the banners and prompts */
|
||||
smode = 1;
|
||||
/* Start input buffering from the start of command buffer (-1 because we use prefix increment) */
|
||||
@@ -750,26 +761,25 @@ int main(int argc, char* argv[]) {
|
||||
#else /* VT100-compatible terminal init */
|
||||
printf("\033c");
|
||||
#endif
|
||||
printf("Welcome to Equi v" EQUI_VER " by Luxferre, 2022\nSystem RAM: %d bytes\nEqui ready\n\n> ", (int) sizeof(ram));
|
||||
printf("Welcome to Equi v" EQUI_VER " by Luxferre, 2022\r\nSystem RAM: %d bytes\r\nEqui ready\r\n\r\n> ", (int) sizeof(ram));
|
||||
}
|
||||
|
||||
while(1) { /* Now, we're in the command mode loop */
|
||||
instr = cgetc(); /* Fetch the next instruction from the keyboard/stdin */
|
||||
if(instr == 0xFFU || instr == 0U) /* exit on zero byte */
|
||||
if(instr == 0xFFU || instr == 0U || instr == 3U || instr == 4U) /* exit on zero byte or ctrl+C or ctrl+D */
|
||||
break;
|
||||
else if(instr == BS || instr == CR || instr == LF || instr == ' ' || instr == '\t') { /* ignore the backspace or whitespaces */
|
||||
#ifdef __CC65__
|
||||
cputc(instr); /* echo it */
|
||||
#endif
|
||||
if(!smode)
|
||||
cputc(instr); /* echo it if not in silent mode */
|
||||
if(instr == CR)
|
||||
cputc(LF);
|
||||
} else if(instr == INS_IISTART) { /* process II start */
|
||||
#ifdef __CC65__
|
||||
cputc(instr); /* echo it */
|
||||
#endif
|
||||
if(!smode)
|
||||
cputc(instr); /* echo it if not in silent mode */
|
||||
ram.II = 1;
|
||||
} else if(instr == INS_IIEND) { /* process II end */
|
||||
#ifdef __CC65__
|
||||
cputc(instr); /* echo it */
|
||||
#endif
|
||||
if(!smode)
|
||||
cputc(instr); /* echo it if not in silent mode */
|
||||
ram.II = 0;
|
||||
} else if(!ram.II && instr == INS_QUIT) {
|
||||
if(ram.MM) { /* output command buffer contents to stdout and exit */
|
||||
@@ -798,10 +808,13 @@ int main(int argc, char* argv[]) {
|
||||
} else { /* append the instruction/character to the command buffer if and only if it doesn't match the above criteria and we're not in II mode */
|
||||
if(!ram.II)
|
||||
ram.cmdbuf[++ram.ibp] = instr;
|
||||
#ifdef __CC65__
|
||||
cputc(instr); /* echo it */
|
||||
#endif
|
||||
if(!smode)
|
||||
cputc(instr); /* echo it if not in silent mode */
|
||||
}
|
||||
} /* command mode loop end */
|
||||
#if !defined __CC65__ && !defined __TINYC__
|
||||
/* restore the terminal settings */
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &tty_opts_backup);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user