-
Notifications
You must be signed in to change notification settings - Fork 2
/
console.c
226 lines (195 loc) · 3.61 KB
/
console.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#include <mintbind.h>
#include "console.h"
#include "textwin.h"
#include "proc.h"
#include "toswin2.h"
long con_fd = 0;
long con_log_fd = 0;
TEXTWIN *con_win = NULL;
char const console_progname[] = "Console";
static bool is_dirty = FALSE;
static void uniconify_con(WINDOW *v, short x, short y, short w, short h)
{
wind_calc(WC_BORDER, v->kind, v->prev.g_x, v->prev.g_y, v->prev.g_w, v->prev.g_h, &x, &y, &w, &h);
wind_set(v->handle, WF_UNICONIFY, x, y, w, h);
wind_get_grect(v->handle, WF_WORKXYWH, &v->work);
v->mouseinp = v->oldmouse;
v->flags &= ~WICONIFIED;
(*v->topped)(v);
is_dirty = FALSE;
}
static bool open_con_fd(void)
{
if (con_fd == 0)
{
con_fd = Fopen(XCONNAME, 2);
if (con_fd > 0)
{
Fsymlink(XCONNAME, TWCONNAME);
add_fd(con_fd);
}
else
{
debug("open_con_fd() failed\n");
return FALSE;
}
}
return TRUE;
}
static void close_con_fd(void)
{
if (con_fd != 0 && con_win == NULL)
{
Fdelete(TWCONNAME);
Fclose(con_fd);
con_fd = 0;
}
}
void create_console(bool open)
{
WINCFG *cfg;
char str[30];
if (con_win == NULL)
{
cfg = get_wincfg(console_progname);
if (cfg->title[0] == '\0')
strcpy(str, rsc_string(STRCONSTITLE));
else
strcpy(str, cfg->title);
con_win = create_textwin(str, cfg);
if (con_win)
{
if (!open_con_fd())
{
destroy_textwin(con_win);
alert(1, 0, XCONERR);
return;
}
con_win->win->uniconify = uniconify_con;
con_win->prog = strdup(console_progname);
con_win->fd = con_fd;
/* Cursor mu an, sonst kommt die Ausgabe durcheinander!! */
(*con_win->output)(con_win, '\033');
(*con_win->output)(con_win, 'e');
if (open)
open_window(con_win->win, cfg->iconified);
}
else
{
alert(1, 0, XCONERR);
return;
}
}
else
{
if (!(con_win->win->flags & WICONIFIED))
{
if (con_win->win->flags & WSHADED)
(*con_win->win->shaded)(con_win->win, -1);
else
(*con_win->win->topped)(con_win->win);
}
}
}
void handle_console(char *txt, long len)
{
/*
* Wenn das erste Zeichen ein Ping ist, wird auf weitere Pings
* geprft. Werden nur Pings gefunden, wird die Funktion verlassen,
* damit das Fenster nicht unn”tig aufgeht.
*/
if (txt[0] == 7)
{
int i, j = 0;
for (i = 0; i<len; i++)
{
if (txt[i] == 7)
j++;
else
{
j = 0;
break;
}
}
if (j > 0)
return;
}
if (con_win != NULL)
{
WINCFG *cfg = get_wincfg(console_progname);
open_window(con_win->win, cfg->iconified);
if (con_win->win->flags == WICONIFIED)
{
is_dirty = TRUE;
draw_winicon(con_win->win);
}
else
{
is_dirty = FALSE;
if (gl_con_output)
{
if (con_win->win->flags & WSHADED)
(*con_win->win->shaded)(con_win->win, -1);
}
}
}
if (con_log_fd > 0)
Fwrite(con_log_fd, len, txt);
}
bool log_console(bool on)
{
if (gl_con_log && !on && con_log_fd > 0)
{
Fclose(con_log_fd);
con_log_fd = 0;
close_con_fd();
}
if (!gl_con_log && on && con_log_fd == 0)
{
int log;
log = (int)Fopen(gl_con_logname, 0x200|34);
if (log > 0)
{
Fseek(0, log, 2);
con_log_fd = log;
if (!open_con_fd())
{
Fclose(con_log_fd);
con_log_fd = 0;
on = FALSE;
}
}
else
{
on = FALSE;
debug("Fopen(%s) failed: %d\n", gl_con_logname, log);
}
}
return on;
}
bool out_console(bool on)
{
if (gl_con_output && !on && con_fd > 0)
{
close_con_fd();
}
if (!gl_con_output && on && con_fd == 0)
{
if (!open_con_fd())
{
on = FALSE;
}
}
return on;
}
bool is_console(WINDOW *win)
{
return ((con_win != NULL) && (win == (WINDOW *)con_win->win));
}
OBJECT *get_con_icon(void)
{
if (is_dirty)
return conicon;
else
return winicon;
}