Skip to content

Commit 07831f5

Browse files
committed
ATRONIX: posix stdio related changes as were made by Andreas Bolka and Hostile Fork
1 parent bc2fead commit 07831f5

File tree

2 files changed

+25
-31
lines changed

2 files changed

+25
-31
lines changed

src/os/host-main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ extern void Init_Ext_Test(void); // see: host-ext-test.c
8585
// Host bare-bones stdio functs:
8686
extern void Open_StdIO(void);
8787
extern void Close_StdIO(void);
88-
extern void Put_Str(char *buf);
88+
extern void Put_Str(REBYTE *buf);
8989
extern REBYTE *Get_Str();
9090

9191
void Host_Crash(REBYTE *reason) {

src/os/posix/dev-stdio.c

+24-30
Original file line numberDiff line numberDiff line change
@@ -46,43 +46,39 @@
4646
#include <string.h>
4747

4848
#include "reb-host.h"
49-
#include "host-lib.h"
50-
51-
#define BUF_SIZE (16*1024)
5249

5350
#define SF_DEV_NULL 31 // local flag to mark NULL device
5451

5552
// Temporary globals: (either move or remove?!)
56-
static int Std_Inp = 0;
57-
static int Std_Out = 1;
58-
static FILE *Std_Echo = 0;
59-
60-
static REBOOL Redir_Out = 0; // redirection flags
61-
static REBOOL Redir_Inp = 0;
62-
63-
#define PUTE(s) if (Std_Echo) fputs(s, Std_Echo)
53+
static int Std_Inp = STDIN_FILENO;
54+
static int Std_Out = STDOUT_FILENO;
55+
static FILE *Std_Echo = NULL;
6456

6557
extern REBDEV *Devices[];
58+
extern void Put_Str(REBYTE *buf);
6659

6760
#ifndef HAS_SMART_CONSOLE // console line-editing and recall needed
68-
void *Init_Terminal();
69-
void Quit_Terminal(void*);
70-
int Read_Line(void*, char*, int);
61+
typedef struct term_data {
62+
char *buffer;
63+
char *residue;
64+
char *out;
65+
int pos;
66+
int end;
67+
int hist;
68+
} STD_TERM;
69+
70+
STD_TERM *Term_IO;
71+
72+
extern STD_TERM *Init_Terminal();
73+
extern void Quit_Terminal(STD_TERM*);
74+
extern int Read_Line(STD_TERM*, char*, int);
7175
#endif
7276

73-
void Put_Str(char *buf);
74-
75-
void *Term_IO;
76-
77-
/*
78-
#define PUTS(s) fputs(s, stdout)
79-
#define GETS(s,len) fgets(s, len, stdin);
80-
#define FLUSH() fflush(stdout)
81-
*/
8277

8378
static void Handle_Signal(int sig)
8479
{
85-
Put_Str("[escape]\n");
80+
REBYTE buf[] = "\x1B[1;35;49m[escape]\x1B[0m\n";
81+
Put_Str(buf);
8682
RL_Escape(0);
8783
}
8884

@@ -93,7 +89,7 @@ static void Init_Signals(void)
9389
signal(SIGTERM, Handle_Signal);
9490
}
9591

96-
static void close_stdio(void)
92+
static void Close_Stdio(void)
9793
{
9894
#ifndef HAS_SMART_CONSOLE
9995
if (Term_IO) {
@@ -115,7 +111,7 @@ static void close_stdio(void)
115111
{
116112
REBDEV *dev = (REBDEV*)dr; // just to keep compiler happy above
117113

118-
close_stdio();
114+
Close_Stdio();
119115

120116
CLR_FLAG(dev->flags, RDF_OPEN);
121117
return DR_DONE;
@@ -148,9 +144,7 @@ static void close_stdio(void)
148144
#ifndef HAS_SMART_CONSOLE
149145
if (isatty(Std_Inp))
150146
Term_IO = Init_Terminal();
151-
else
152147
#endif
153-
Term_IO = 0;
154148
//printf("%x\r\n", req->handle);
155149
}
156150
else
@@ -171,9 +165,9 @@ static void close_stdio(void)
171165
{
172166
REBDEV *dev = Devices[req->device];
173167

174-
close_stdio();
168+
Close_Stdio();
175169

176-
CLR_FLAG(req->flags, RRF_OPEN);
170+
CLR_FLAG(dev->flags, RRF_OPEN);
177171

178172
return DR_DONE;
179173
}

0 commit comments

Comments
 (0)