Fix compiler warnings (missing #includes etc) thrown up by RedHat.
[sgt/tweak] / slang.c
CommitLineData
6e182d98 1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <ctype.h>
5#include <assert.h>
6
7#if defined(unix) && !defined(GO32)
8#include <signal.h>
9#include <sys/ioctl.h>
10#endif
11
12#include <slang.h>
13
14#include "tweak.h"
15
16#if defined(unix) && !defined(GO32)
17static int sigwinch (int sigtype)
18{
19 extern void schedule_update(void);
20 schedule_update();
21 signal (SIGWINCH, (void *) sigwinch);
22 return 0;
23}
24#endif
25
26int display_rows, display_cols;
27
28void display_beep(void)
29{
30 SLtt_beep();
31}
32
33static void get_screen_size (void) {
34 int r = 0, c = 0;
35
36#ifdef TIOCGWINSZ
37 struct winsize wind_struct;
38
39 if ((ioctl(1,TIOCGWINSZ,&wind_struct) == 0)
40 || (ioctl(0, TIOCGWINSZ, &wind_struct) == 0)
41 || (ioctl(2, TIOCGWINSZ, &wind_struct) == 0)) {
42 c = (int) wind_struct.ws_col;
43 r = (int) wind_struct.ws_row;
44 }
45#elif defined(MSDOS)
46 union REGS regs;
47
48 regs.h.ah = 0x0F;
49 int86 (0x10, &regs, &regs);
50 c = regs.h.ah;
51
52 regs.x.ax = 0x1130, regs.h.bh = 0;
53 int86 (0x10, &regs, &regs);
54 r = regs.h.dl + 1;
55#endif
56
57 if ((r <= 0) || (r > 200)) r = 24;
58 if ((c <= 0) || (c > 250)) c = 80;
59 display_rows = SLtt_Screen_Rows = r;
60 display_cols = SLtt_Screen_Cols = c;
61}
62
63void display_setup(void)
64{
65 SLtt_get_terminfo();
66
67 if (SLang_init_tty (ABORT, 1, 0) == -1) {
68 fprintf(stderr, "tweak: SLang_init_tty: returned error code\n");
69 exit (1);
70 }
71 SLang_set_abort_signal (NULL);
72 SLtt_Use_Ansi_Colors = TRUE;
73
74 get_screen_size ();
75 if (SLsmg_init_smg () < 0) {
76 fprintf(stderr, "tweak: SLsmg_init_smg: returned error code\n");
77 SLang_reset_tty ();
78 exit (1);
79 }
80
81#if defined(unix) && !defined(GO32)
82 signal (SIGWINCH, (void *) sigwinch);
83#endif
84}
85
86void display_cleanup(void)
87{
88 SLsmg_reset_smg ();
89 SLang_reset_tty ();
90}
91
92void display_moveto(int y, int x)
93{
94 SLsmg_gotorc(y, x);
95}
96
97void display_refresh(void)
98{
99 SLsmg_refresh();
100}
101
102void display_write_str(char *str)
103{
104 SLsmg_write_nchars(str, strlen(str));
105}
106
107void display_write_chars(char *str, int len)
108{
109 SLsmg_write_nchars(str, len);
110}
111
112void display_define_colour(int colour, int fg, int bg)
113{
114 static char *colours[16] = {
115 "black", "red", "green", "brown",
116 "blue", "magenta", "cyan", "lightgray",
117 "gray", "brightred", "brightgreen", "yellow",
118 "brightblue", "brightmagenta", "brightcyan", "white",
119 };
120 char cname[40];
121
122 sprintf(cname, "colour%d", colour);
123
124 SLtt_set_color(colour, cname, colours[fg], colours[bg]);
125}
126
127void display_set_colour(int colour)
128{
129 SLsmg_set_color(colour);
130}
131
132void display_clear_to_eol(void)
133{
134 SLsmg_erase_eol();
135}
136
137int display_getkey(void)
138{
139 return SLang_getkey();
140}
141
142int display_input_to_flush(void)
143{
144 return SLang_input_pending(0);
145}
146
147void display_post_error(void)
148{
149 SLKeyBoard_Quit = 0;
150 SLang_Error = 0;
151}
152
153void display_recheck_size(void)
154{
155 SLsmg_reset_smg ();
156 get_screen_size ();
157 SLsmg_init_smg ();
158}