Correct backtrace() array size argument
[forms.git] / src / F_Linux_Console_UI.C
blobcb3ec3f34ee19f39c29e03e7e6c5c09c0ba9d52f
2  /*
3   *   Copyright (C) 2007, Harbour, All rights reserved.
4   */
6 #include <F_Linux_Console_UI.H>
7 #include <errno.h>
9 using namespace F;
10 using namespace ost;
12 // ÏÓÔÁÌÓÑ ÐÏÓÌÅ probe()
13 FILE *vcsa;
15 // TODO: test if console in graphics mode (svgalib/etc.)
18 // ËÏÎÓÏÌØ ÄÏÌÖÎÁ ÉÍÅÔØ ÍÙÛØ É ËÌÁ×Õ - linux-2.6 input subsystem / gpm + kbd
19 // /dev/vcsa :
20 //  - 2 ÂÁÊÔÁ w/h
21 //  - 2 ÂÁÊÔÁ cursor position
22 //  - char / attr array
24 void F_Linux_Console_UI::initial()
26   mouse = new F_Gpm();
27   if (!mouse->good())
28     log("linux_console_ui", CHAT_LEVEL, "Gpm is missing.");
29   input = new F_Linux_Input;
30   if (!input->good()) {
31     log("linux_console_ui", CHAT_LEVEL, "Linux input subsystem is missing.");
32     // try to get working keyboard
33     delete input;
34     input = new F_Linux_Keyboard;
35     if (!input->good()) {
36       log("linux_console_ui", CHAT_LEVEL, "Linux keyboard is missing, giving up.");
37       ::exit(-1);
38     }
39   } else
40       mouse->disable(); // we do not need double mouse events
41   // try to know screen width & height
42   unsigned char b[2];
43   int err;
44   if ((err = read(fileno(vcsa), &b, 2)) != 2) {
45    if (err < 0)
46     log("linux_console_ui", ALERT_LEVEL, "vcsa read error: %s",
47       strerror(errno));
48    else
49     log("linux_console_ui", ALERT_LEVEL, "short read from vcsa (%d) !", err);
50   ::exit(-1);
51  }
52   log("linux_console_ui", CHAT_LEVEL, "w - %d, h - %d", b[1], b[0]);
53   display = new F_Linux_Console_Display(vcsa, b[1], b[0]);
54   // save display area to back_store
55   display->store();
56   display->cursor(0); // cursor off
57   display->sync();
58   init(); // user init
59   ui_started_.post();
62 // ÓÏÂÉÒÁÅÍ ÓÏÂÙÔÉÑ ÏÔ ÕÓÔÒÏÊÓÔ× ÕÐÒÁ×ÌÅÎÉÑ É ÐÅÒÅÄÁÅÍ ÐÏ ÃÅÐÏÞËÅ
64 void F_Linux_Console_UI::run()
66  F_Event_t iev;
67  bool need_flush = false;
69  while (1) {
70    mouse->check_for_events();
71    input->check_for_events();
72    if (mouse->get_event(&iev))
73      event_queue.push_back(iev);
74    if (input->get_event(&iev))
75      event_queue.push_back(iev);
76    while (display->get_event(&iev)) {
77      event_queue.push_back(iev);
78      need_flush = true;
79   }
80    if (need_flush) {
81      iev.dev = F_DISPLAY;
82      iev.type = F_DISPLAY_FLUSH;
83      iev.display.window = 0;
84      event_queue.push_back(iev);
85      need_flush = false;
86   }
87    if (event_queue.size()) {
88      while (event_queue.size()) { // process events
89        iev = event_queue[0];
90        display->handle(iev);
91        event_queue.erase(event_queue.begin());
92    }
93   } else
94          idle();
95  } // while(1)
98 bool F_Linux_Console_UI::exit_confirm(bool from_sighandler)
100  return true;
103 void F_Linux_Console_UI::refresh()
105  // refresh damaged windows
108 void F_Linux_Console_UI::sigcont()
110  debug("console continued");
111  input->sigcont();
112  display->sync();
115 void F_Linux_Console_UI::sigstop()
117  input->sigstop();
118  display->restore();
119  debug("console stopping");
122 void F_Linux_Console_UI::sigwinch()
124  exit_on_unimplemented("SIGWINCH");
127 #include <linux/vt.h>
128 #include <sys/ioctl.h>
130 bool F_Linux_Console_UI::probe()
132  if (strcmp(getenv("TERM"), "linux") && strcmp(getenv("TERM"), "linux"))
133    return false;
134  const char *tty = ttyname(fileno(stdout));
135  int tty_fd = open(tty, O_RDWR);
136  if (tty_fd < 0) { // can't open tty
137   debug("Can't open tty.");
138   return false;
140  vt_mode vtmode;
141  if (ioctl(tty_fd, VT_GETMODE, &vtmode) < 0) {
142    ::close(tty_fd);
143    debug("VT_GETMODE ioctl failed.");
144    return false;
146  if (!strstr(tty, "/dev/vc/")) {
147    debug("Looks like not a tty.");
148    return false;
150  char vcsa_n[32] = "/dev/vcsa";
151  strcat(vcsa_n, rindex(tty, '/') + 1);
152    vcsa = ::fopen(vcsa_n, "r+");
153  if (!vcsa) {
154    debug("Can't open /dev/vcsa.");
155    return false;
157  return true;
160 F_Linux_Console_UI::~F_Linux_Console_UI()
162  shutdown();