修复tty设备清屏BUG

This commit is contained in:
XIAOYI12 2024-09-08 23:39:07 +08:00
parent 229523beb2
commit 84278651b6
5 changed files with 46 additions and 11 deletions

View File

@ -535,6 +535,12 @@ int filesize(const char* filename){
int fputc(int ch, FILE *stream) { int fputc(int ch, FILE *stream) {
if (CANWRITE(stream->mode)) { if (CANWRITE(stream->mode)) {
if(strcmp("<stdout>",stream->name)||strcmp("<stderr>",stream->name)){
syscall_putchar(ch);
return 0;
}
// printk("Current Buffer=%s\n",stream->buffer); // printk("Current Buffer=%s\n",stream->buffer);
if (stream->p >= stream->bufferSize) { if (stream->p >= stream->bufferSize) {
// printk("Realloc....(%d,%d)\n",stream->p,stream->bufferSize); // printk("Realloc....(%d,%d)\n",stream->p,stream->bufferSize);
@ -632,6 +638,10 @@ FILE *fopen(char *filename, char *mode) {
int fgetc(FILE *stream) { int fgetc(FILE *stream) {
if (CANREAD(stream->mode)) { if (CANREAD(stream->mode)) {
if(strcmp("<stdin>",stream->name)) {
return getc();
}
if (stream->p >= stream->fileSize) { if (stream->p >= stream->fileSize) {
return EOF; return EOF;
} else { } else {
@ -698,6 +708,12 @@ char *fgets(char *str, int n, FILE *stream) {
int fputs(const char *str, FILE *stream) { int fputs(const char *str, FILE *stream) {
if (CANWRITE(stream->mode)) { if (CANWRITE(stream->mode)) {
if(strcmp("<stdout>",stream->name)||strcmp("<stderr>",stream->name)){
syscall_print(str);
return 0;
}
for (int i = 0; i < strlen(str); i++) { for (int i = 0; i < strlen(str); i++) {
fputc(str[i], stream); fputc(str[i], stream);
} }
@ -713,7 +729,9 @@ int fprintf(FILE *stream, const char *format, ...) {
va_start(ap, format); va_start(ap, format);
char *buf = malloc(1024); char *buf = malloc(1024);
len = vsprintf(buf, format, ap); len = vsprintf(buf, format, ap);
fputs(buf, stream); if(strcmp("<stdout>",stream->name)||strcmp("<stderr>",stream->name)){
syscall_print(buf);
} else fputs(buf, stream);
free(buf); free(buf);
va_end(ap); va_end(ap);
return len; return len;

View File

@ -23,7 +23,7 @@
#define LUA_VERSION_NUM 504 #define LUA_VERSION_NUM 504
#define LUA_VERSION_RELEASE_NUM (LUA_VERSION_NUM * 100 + 4) #define LUA_VERSION_RELEASE_NUM (LUA_VERSION_NUM * 100 + 4)
#define LUA_VERSION "CoolPotOS Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR #define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
#define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE #define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE
#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2022 Lua.org, PUC-Rio" #define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2022 Lua.org, PUC-Rio"
#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes" #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"

View File

@ -121,7 +121,7 @@
#if !defined(LUA_PROGNAME) #if !defined(LUA_PROGNAME)
#define LUA_PROGNAME "lua" #define LUA_PROGNAME "lua.elf"
#endif #endif
#if !defined(LUA_INIT_VAR) #if !defined(LUA_INIT_VAR)
@ -149,11 +149,14 @@ static void laction(int i) {
static void print_usage(const char *badoption) { static void print_usage(const char *badoption) {
if(badoption[0] != '+'){
lua_writestringerror("%s: ", progname); lua_writestringerror("%s: ", progname);
if (badoption[1] == 'e' || badoption[1] == 'l') if (badoption[1] == 'e' || badoption[1] == 'l')
lua_writestringerror("'%s' needs argument\n", badoption); lua_writestringerror("'%s' needs argument\n", badoption);
else else
lua_writestringerror("unrecognized option '%s'\n", badoption); lua_writestringerror("unrecognized option '%s'\n", badoption);
}
lua_writestringerror( lua_writestringerror(
"usage: %s [options] [script [args]]\n" "usage: %s [options] [script [args]]\n"
"Available options are:\n" "Available options are:\n"
@ -333,6 +336,7 @@ static int handle_script(lua_State *L, char **argv) {
#define has_v 4 /* -v */ #define has_v 4 /* -v */
#define has_e 8 /* -e */ #define has_e 8 /* -e */
#define has_E 16 /* -E */ #define has_E 16 /* -E */
#define has_h 32 /* -h */
/* /*
@ -380,6 +384,11 @@ static int collectargs(char **argv, int *first) {
return has_error; /* invalid option */ return has_error; /* invalid option */
args |= has_v; args |= has_v;
break; break;
case 'h':
if (argv[i][2] != '\0') /* extra characters? */
return has_error; /* invalid option */
args |= has_h;
break;
case 'e': case 'e':
args |= has_e; /* FALLTHROUGH */ args |= has_e; /* FALLTHROUGH */
case 'l': /* both options need an argument */ case 'l': /* both options need an argument */
@ -858,6 +867,10 @@ static int pmain(lua_State *L) {
char **argv = (char **) lua_touserdata(L, 2); char **argv = (char **) lua_touserdata(L, 2);
int script; int script;
if(argc == 1){
print_usage("+");
return 0;
}
int args = collectargs(argv, &script); int args = collectargs(argv, &script);
int optlim = (script > 0) ? script : argc; /* first argv not an option */ int optlim = (script > 0) ? script : argc; /* first argv not an option */
@ -866,6 +879,9 @@ static int pmain(lua_State *L) {
print_usage(argv[script]); /* 'script' has index of bad arg. */ print_usage(argv[script]); /* 'script' has index of bad arg. */
return 0; return 0;
} }
if(args & has_h){
print_usage("<null>");
}
if (args & has_v) /* option '-v'? */ if (args & has_v) /* option '-v'? */
print_version(); print_version();
if (args & has_E) { /* option '-E'? */ if (args & has_E) { /* option '-E'? */
@ -875,8 +891,8 @@ static int pmain(lua_State *L) {
// printf("In this2\n"); // printf("In this2\n");
luaopen_base(L); luaopen_base(L);
luaL_setfuncs(L, my_lib_bsp, 0); luaL_setfuncs(L, my_lib_bsp, 0);
luaL_requiref(L, "pio", open_io, 1); luaL_requiref(L, "cpio", open_io, 1);
luaL_requiref(L, "pl_api", open_os, 1); luaL_requiref(L, "cp_api", open_os, 1);
luaL_openlibs(L); /* open standard libraries */ luaL_openlibs(L); /* open standard libraries */
createargtable(L, argv, argc, script); /* create table 'arg' */ createargtable(L, argv, argc, script); /* create table 'arg' */
lua_gc(L, LUA_GCGEN, 0, 0); /* GC in generational mode */ lua_gc(L, LUA_GCGEN, 0, 0); /* GC in generational mode */

View File

@ -393,7 +393,7 @@ void init_default_tty(struct task_struct *task){
task->tty->is_using = true; task->tty->is_using = true;
task->tty->print = tty_print; task->tty->print = tty_print;
task->tty->clear = clear_TextMode; task->tty->clear = vbe_clear;
task->tty->putchar = vbe_putchar; task->tty->putchar = vbe_putchar;
task->tty->gotoxy = tty_gotoxy; task->tty->gotoxy = tty_gotoxy;
task->tty->screen_ne = screen_ne_TextMode; task->tty->screen_ne = screen_ne_TextMode;

View File

@ -312,6 +312,7 @@ void screen_clear(){
return; return;
} }
if(vbe_status){ if(vbe_status){
vbe_clear(); vbe_clear();
} else vga_clear(); } else vga_clear();