/[gxemul]/trunk/src/console.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/src/console.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 10 by dpavlin, Mon Oct 8 16:18:27 2007 UTC revision 42 by dpavlin, Mon Oct 8 16:22:32 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2003-2005  Anders Gavare.  All rights reserved.   *  Copyright (C) 2003-2007  Anders Gavare.  All rights reserved.
3   *   *
4   *  Redistribution and use in source and binary forms, with or without   *  Redistribution and use in source and binary forms, with or without
5   *  modification, are permitted provided that the following conditions are met:   *  modification, are permitted provided that the following conditions are met:
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *   *
27   *   *
28   *  $Id: console.c,v 1.9 2005/06/26 11:36:27 debug Exp $   *  $Id: console.c,v 1.26 2007/06/15 18:07:33 debug Exp $
29   *   *
30   *  Generic console support functions.   *  Generic console support functions.
31   *   *
32   *  This is used by individual device drivers, for example serial controllers,   *  This module is used by individual device drivers, for example serial
33   *  to attach stdin/stdout of the host system to a specific device.   *  controllers, keyboards, or other devices which need to attach to the
34     *  emulator's real stdin/stdout.
35   *   *
36   *  NOTE: This stuff is non-reentrant.   *  The idea is that several input and output streams (console handles) are
37     *  allowed. As long as the number of input streams is <= 1, then everything
38     *  can be done in the emulator's default terminal window.
39     *
40     *  If the number of inputs is more than 1, it is necessary to open up slave
41     *  xterm windows for each input. (Otherwise the behaviour is undefined; i.e.
42     *  which of two emulated serial controllers would get keyboard input?)
43     *
44     *  (If the -x command line option is NOT used, then slaves are not opened up.
45     *  Instead, a warning message is printed, and input is not allowed.)
46     *
47     *  Note that console handles that _allow_ input but are not yet used for
48     *  output are not counted. This allows a machine to have, say, 2 serial ports
49     *  which can be used for both input and output, and it will still be possible
50     *  to run in the default terminal window as long as only one of those serial
51     *  ports is actually used.
52     *
53     *  xterms are opened up "on demand", when output is sent to them.
54     *
55     *  The MAIN console handle (fixed as handle nr 0) is the one used by the
56     *  default terminal window. A machine which registers a serial controller,
57     *  which should be used as the main way of communicating with guest operating
58     *  systems running on that machine, should set machine->main_console_handle
59     *  to the handle of the correct port on that controller.
60     *
61     *
62     *  NOTE: The code in this module is mostly non-reentrant.
63   */   */
64    
65  #include <errno.h>  #include <errno.h>
# Line 43  Line 70 
70  #include <termios.h>  #include <termios.h>
71  #include <unistd.h>  #include <unistd.h>
72  #include <sys/types.h>  #include <sys/types.h>
73    #include <time.h>
74    
75  #include "console.h"  #include "console.h"
76  #include "emul.h"  #include "emul.h"
77  #include "machine.h"  #include "machine.h"
78  #include "memory.h"  #include "settings.h"
 #include "misc.h"  
79    
80    
81  extern char *progname;  extern char *progname;
82    extern int verbose;
83    extern struct settings *global_settings;
84    
85    
86  static struct termios console_oldtermios;  static struct termios console_oldtermios;
# Line 62  static struct termios console_slave_tios Line 91  static struct termios console_slave_tios
91  static int console_slave_outputd;  static int console_slave_outputd;
92    
93  static int console_initialized = 0;  static int console_initialized = 0;
94    static struct settings *console_settings = NULL;
95  static int console_stdout_pending;  static int console_stdout_pending;
96    
97  #define CONSOLE_FIFO_LEN        4096  #define CONSOLE_FIFO_LEN        4096
98    
 /*  Mouse coordinates:  */  
 static int console_framebuffer_mouse_x;         /*  absolute x, 0-based  */  
 static int console_framebuffer_mouse_y;         /*  absolute y, 0-based  */  
 static int console_framebuffer_mouse_fb_nr;     /*  fb_number of last  
                                                     framebuffer cursor update */  
   
99  static int console_mouse_x;             /*  absolute x, 0-based  */  static int console_mouse_x;             /*  absolute x, 0-based  */
100  static int console_mouse_y;             /*  absolute y, 0-based  */  static int console_mouse_y;             /*  absolute y, 0-based  */
101  static int console_mouse_fb_nr;         /*  framebuffer number of  static int console_mouse_fb_nr;         /*  framebuffer number of
# Line 82  static int allow_slaves = 0; Line 106  static int allow_slaves = 0;
106    
107  struct console_handle {  struct console_handle {
108          int             in_use;          int             in_use;
109            int             in_use_for_input;
110          int             using_xterm;          int             using_xterm;
111          int             inputonly;          int             inputonly;
112            int             outputonly;
113            int             warning_printed;
114    
115            char            *machine_name;
116          char            *name;          char            *name;
117    
118          int             w_descriptor;          int             w_descriptor;
# Line 105  static int n_console_handles = 0; Line 133  static int n_console_handles = 0;
133    
134    
135  /*  /*
136   *  console_deinit():   *  console_deinit_main():
137   *   *
138   *  Restore host's console settings.   *  Restore host's console settings.
139   */   */
140  void console_deinit(void)  void console_deinit_main(void)
141  {  {
142          if (!console_initialized)          if (!console_initialized)
143                  return;                  return;
# Line 124  void console_deinit(void) Line 152  void console_deinit(void)
152   *  console_sigcont():   *  console_sigcont():
153   *   *
154   *  If the user presses CTRL-Z (to stop the emulator process) and then   *  If the user presses CTRL-Z (to stop the emulator process) and then
155   *  continues, we have to make sure that the right termios settings are   *  continues, the termios settings might have been invalidated. This
156   *  active.  (This should be set as the SIGCONT signal handler in src/emul.c.)   *  function restores them.
157     *
158     *  (This function should be set as the SIGCONT signal handler in src/emul.c.)
159   */   */
160  void console_sigcont(int x)  void console_sigcont(int x)
161  {  {
162          if (!console_initialized)          if (!console_initialized)
163                  return;                  return;
164    
165          /*  Make sure our 'current' termios setting is active:  */          /*  Make sure that the correct (current) termios setting is active:  */
166          tcsetattr(STDIN_FILENO, TCSANOW, &console_curtermios);          tcsetattr(STDIN_FILENO, TCSANOW, &console_curtermios);
167    
168          /*  Reset the signal handler:  */          /*  Reset the signal handler:  */
# Line 143  void console_sigcont(int x) Line 173  void console_sigcont(int x)
173  /*  /*
174   *  start_xterm():   *  start_xterm():
175   *   *
176   *  When using X11, this routine tries to start up an xterm, with another   *  When using X11 (well, when allow_slaves is set), this routine tries to
177   *  copy of gxemul inside. The other gxemul copy is given arguments   *  start up an xterm, with another copy of gxemul inside. The other gxemul
178   *  that will cause it to run console_slave().   *  copy is given arguments that will cause it to run console_slave().
179     *
180     *  TODO: This is ugly and hardcoded. Clean it up.
181   */   */
182  static void start_xterm(int handle)  static void start_xterm(int handle)
183  {  {
184          int filedes[2];          int filedes[2];
185          int filedesB[2];          int filedesB[2];
186          int res;          int res;
187            size_t mlen;
188          char **a;          char **a;
189          pid_t p;          pid_t p;
190    
# Line 171  static void start_xterm(int handle) Line 204  static void start_xterm(int handle)
204          /*  printf("filedesB = %i,%i\n", filedesB[0], filedesB[1]);  */          /*  printf("filedesB = %i,%i\n", filedesB[0], filedesB[1]);  */
205    
206          /*  NOTE/warning: Hardcoded max nr of args!  */          /*  NOTE/warning: Hardcoded max nr of args!  */
207          a = malloc(sizeof(char *) * 20);          CHECK_ALLOCATION(a = malloc(sizeof(char *) * 20));
         if (a == NULL) {  
                 fprintf(stderr, "console_start_slave(): out of memory\n");  
                 exit(1);  
         }  
208    
209          a[0] = getenv("XTERM");          a[0] = getenv("XTERM");
210          if (a[0] == NULL)          if (a[0] == NULL)
# Line 183  static void start_xterm(int handle) Line 212  static void start_xterm(int handle)
212          a[1] = "-geometry";          a[1] = "-geometry";
213          a[2] = "80x25";          a[2] = "80x25";
214          a[3] = "-title";          a[3] = "-title";
215          a[4] = console_handles[handle].name;          mlen = strlen(console_handles[handle].name) +
216                strlen(console_handles[handle].machine_name) + 30;
217            CHECK_ALLOCATION(a[4] = malloc(mlen));
218            snprintf(a[4], mlen, "GXemul: %s %s",
219                console_handles[handle].machine_name,
220                console_handles[handle].name);
221          a[5] = "-e";          a[5] = "-e";
222          a[6] = progname;          a[6] = progname;
223          a[7] = malloc(80);          CHECK_ALLOCATION(a[7] = malloc(80));
224          snprintf(a[7], 80, "-WW@S%i,%i", filedes[0], filedesB[1]);          snprintf(a[7], 80, "-WW@S%i,%i", filedes[0], filedesB[1]);
225          a[8] = NULL;          a[8] = NULL;
226    
227          p = fork();          p = fork();
228          if (p == -1) {          if (p == -1) {
229                  printf("[ console_start_slave(): ERROR while trying to "                  printf("[ start_xterm(): ERROR while trying to "
230                      "fork(): %i ]\n", errno);                      "fork(): %i ]\n", errno);
231                  exit(1);                  exit(1);
232          } else if (p == 0) {          } else if (p == 0) {
# Line 201  static void start_xterm(int handle) Line 235  static void start_xterm(int handle)
235    
236                  p = setsid();                  p = setsid();
237                  if (p < 0)                  if (p < 0)
238                          printf("[ console_start_slave(): ERROR while trying "                          printf("[ start_xterm(): ERROR while trying "
239                              "to do a setsid(): %i ]\n", errno);                              "to do a setsid(): %i ]\n", errno);
240    
241                  res = execvp(a[0], a);                  res = execvp(a[0], a);
242                  printf("[ console_start_slave(): ERROR while trying to "                  printf("[ start_xterm(): ERROR while trying to "
243                      "execvp(\"");                      "execvp(\"");
244                  while (a[0] != NULL) {                  while (a[0] != NULL) {
245                          printf("%s", a[0]);                          printf("%s", a[0]);
# Line 214  static void start_xterm(int handle) Line 248  static void start_xterm(int handle)
248                          a++;                          a++;
249                  }                  }
250                  printf("\"): %i ]\n", errno);                  printf("\"): %i ]\n", errno);
251                    if (errno == ENOENT)
252                            printf("[ Most probably you don't have xterm"
253                                " in your PATH. Try again. ]\n");
254                  exit(1);                  exit(1);
255          }          }
256    
# Line 278  void console_makeavail(int handle, char Line 315  void console_makeavail(int handle, char
315   */   */
316  static int console_stdin_avail(int handle)  static int console_stdin_avail(int handle)
317  {  {
318            if (!console_handles[handle].in_use_for_input)
319                    return 0;
320    
321          if (!allow_slaves)          if (!allow_slaves)
322                  return d_avail(STDIN_FILENO);                  return d_avail(STDIN_FILENO);
323    
# Line 359  void console_putchar(int handle, int ch) Line 399  void console_putchar(int handle, int ch)
399  {  {
400          char buf[1];          char buf[1];
401    
402            if (!console_handles[handle].in_use_for_input &&
403                !console_handles[handle].outputonly)
404                    console_change_inputability(handle, 1);
405    
406          if (!allow_slaves) {          if (!allow_slaves) {
407                  /*  stdout:  */                  /*  stdout:  */
408                  putchar(ch);                  putchar(ch);
# Line 437  void console_mouse_button(int button, in Line 481  void console_mouse_button(int button, in
481    
482    
483  /*  /*
  *  console_get_framebuffer_mouse():  
  *  
  *  TODO: Comment  
  */  
 void console_get_framebuffer_mouse(int *x, int *y, int *fb_nr)  
 {  
         *x = console_framebuffer_mouse_x;  
         *y = console_framebuffer_mouse_y;  
         *fb_nr = console_framebuffer_mouse_fb_nr;  
 }  
   
   
 /*  
  *  console_set_framebuffer_mouse():  
  *  
  *  A framebuffer device calls this function when it sets the  
  *  position of a cursor (ie a mouse cursor).  
  */  
 void console_set_framebuffer_mouse(int x, int y, int fb_nr)  
 {  
         console_framebuffer_mouse_x = x;  
         console_framebuffer_mouse_y = y;  
         console_framebuffer_mouse_fb_nr = fb_nr;  
 }  
   
   
 /*  
484   *  console_getmouse():   *  console_getmouse():
485   *   *
486   *  Puts current mouse data into the variables pointed to by   *  Puts current mouse data into the variables pointed to by
# Line 520  void console_slave(char *arg) Line 537  void console_slave(char *arg)
537          int inputd;          int inputd;
538          int len;          int len;
539          char *p;          char *p;
540          char buf[400];          char buf[16384];
541    
542          /*  arg = '3,6' or similar, input and output descriptors  */          /*  arg = '3,6' or similar, input and output descriptors  */
543          /*  printf("console_slave(): arg = '%s'\n", arg);  */          /*  printf("console_slave(): arg = '%s'\n", arg);  */
# Line 566  void console_slave(char *arg) Line 583  void console_slave(char *arg)
583                          write(console_slave_outputd, buf, len);                          write(console_slave_outputd, buf, len);
584                  }                  }
585    
586                  usleep(100);                  usleep(10000);
587          }          }
588  }  }
589    
# Line 594  static struct console_handle *console_ne Line 611  static struct console_handle *console_ne
611          if (found_free == -1) {          if (found_free == -1) {
612                  /*  Let's realloc console_handles[], to make room                  /*  Let's realloc console_handles[], to make room
613                      for the new one:  */                      for the new one:  */
614                  console_handles = realloc(console_handles, sizeof(                  CHECK_ALLOCATION(console_handles =
615                      struct console_handle) * (n_console_handles + 1));                      realloc(console_handles, sizeof(
616                  if (console_handles == NULL) {                      struct console_handle) * (n_console_handles + 1)));
                         printf("console_new_handle(): out of memory\n");  
                         exit(1);  
                 }  
617                  found_free = n_console_handles;                  found_free = n_console_handles;
618                  n_console_handles ++;                  n_console_handles ++;
619          }          }
# Line 608  static struct console_handle *console_ne Line 622  static struct console_handle *console_ne
622          memset(chp, 0, sizeof(struct console_handle));          memset(chp, 0, sizeof(struct console_handle));
623    
624          chp->in_use = 1;          chp->in_use = 1;
625          chp->name = strdup(name);          chp->machine_name = "";
626          if (chp->name == NULL) {          CHECK_ALLOCATION(chp->name = strdup(name));
                 printf("console_new_handle(): out of memory\n");  
                 exit(1);  
         }  
627    
628          *handlep = found_free;          *handlep = found_free;
629          return chp;          return chp;
# Line 633  static struct console_handle *console_ne Line 644  static struct console_handle *console_ne
644   *   *
645   *  consolename should be something like "serial 0".   *  consolename should be something like "serial 0".
646   *   *
647     *  If use_for_input is 1, input is allowed right from the start. (This
648     *  can be upgraded later from 0 to 1 using the console_change_inputability()
649     *  function.)
650     *
651     *  If use_for_input is CONSOLE_OUTPUT_ONLY, then this is an output-only stream.
652     *
653   *  On success, an integer >= 0 is returned. This can then be used as a   *  On success, an integer >= 0 is returned. This can then be used as a
654   *  'handle' when writing to or reading from an emulated console.   *  'handle' when writing to or reading from an emulated console.
655   *   *
656   *  On failure, -1 is returned.   *  On failure, -1 is returned.
657   */   */
658  int console_start_slave(struct machine *machine, char *consolename)  int console_start_slave(struct machine *machine, char *consolename,
659            int use_for_input)
660  {  {
         int handle;  
         size_t mlen;  
661          struct console_handle *chp;          struct console_handle *chp;
662            int handle;
663    
664          if (machine == NULL || consolename == NULL) {          if (machine == NULL || consolename == NULL) {
665                  printf("console_start_slave(): NULL ptr\n");                  printf("console_start_slave(): NULL ptr\n");
# Line 650  int console_start_slave(struct machine * Line 667  int console_start_slave(struct machine *
667          }          }
668    
669          chp = console_new_handle(consolename, &handle);          chp = console_new_handle(consolename, &handle);
670            chp->in_use_for_input = use_for_input;
671          mlen = strlen(machine->name) + strlen(consolename) + 40;          if (use_for_input == CONSOLE_OUTPUT_ONLY) {
672          chp->name = malloc(mlen);                  chp->outputonly = 1;
673          if (chp->name == NULL) {                  chp->in_use_for_input = 0;
                 printf("out of memory\n");  
                 exit(1);  
674          }          }
         snprintf(chp->name, mlen, "GXemul: '%s' %s",  
             machine->name, consolename);  
675    
676  #if 0          if (machine->machine_name != NULL) {
677          if (!machine->use_x11) {                  CHECK_ALLOCATION(chp->machine_name =
678                  return handle;                      strdup(machine->machine_name));
679            } else {
680                    CHECK_ALLOCATION(chp->machine_name = strdup(""));
681          }          }
682  #endif  
683          chp->using_xterm = USING_XTERM_BUT_NOT_YET_OPEN;          CHECK_ALLOCATION(chp->name = strdup(consolename));
684    
685            if (allow_slaves)
686                    chp->using_xterm = USING_XTERM_BUT_NOT_YET_OPEN;
687    
688          return handle;          return handle;
689  }  }
# Line 683  int console_start_slave(struct machine * Line 701  int console_start_slave(struct machine *
701   *   *
702   *  On failure, -1 is returned.   *  On failure, -1 is returned.
703   */   */
704  int console_start_slave_inputonly(struct machine *machine, char *consolename)  int console_start_slave_inputonly(struct machine *machine, char *consolename,
705            int use_for_input)
706  {  {
707          struct console_handle *chp;          struct console_handle *chp;
708          int handle;          int handle;
         size_t mlen;  
709    
710          if (machine == NULL || consolename == NULL) {          if (machine == NULL || consolename == NULL) {
711                  printf("console_start_slave(): NULL ptr\n");                  printf("console_start_slave(): NULL ptr\n");
# Line 696  int console_start_slave_inputonly(struct Line 714  int console_start_slave_inputonly(struct
714    
715          chp = console_new_handle(consolename, &handle);          chp = console_new_handle(consolename, &handle);
716          chp->inputonly = 1;          chp->inputonly = 1;
717            chp->in_use_for_input = use_for_input;
718            CHECK_ALLOCATION(chp->machine_name = strdup(machine->name));
719            CHECK_ALLOCATION(chp->name = strdup(consolename));
720    
721            return handle;
722    }
723    
724    
725          mlen = strlen(machine->name) + strlen(consolename) + 40;  /*
726          chp->name = malloc(mlen);   *  console_change_inputability():
727          if (chp->name == NULL) {   *
728                  printf("out of memory\n");   *  Sets whether or not a console handle can be used for input. Return value
729     *  is 1 if the change took place, 0 otherwise.
730     */
731    int console_change_inputability(int handle, int inputability)
732    {
733            int old;
734    
735            if (handle < 0 || handle >= n_console_handles) {
736                    fatal("console_change_inputability(): bad handle %i\n",
737                        handle);
738                  exit(1);                  exit(1);
739          }          }
         snprintf(chp->name, mlen, "GXemul: '%s' %s",  
             machine->name, consolename);  
740    
741          return handle;          old = console_handles[handle].in_use_for_input;
742            console_handles[handle].in_use_for_input = inputability;
743    
744            if (inputability != 0) {
745                    if (console_warn_if_slaves_are_needed(0)) {
746                            console_handles[handle].in_use_for_input = old;
747                            if (!console_handles[handle].warning_printed) {
748                                    fatal("%%\n%%  WARNING! Input to console ha"
749                                        "ndle \"%s\" wasn't enabled,\n%%  because "
750                                        "it", console_handles[handle].name);
751                                    fatal(" would interfere with other inputs,\n"
752                                        "%%  and you did not use the -x command "
753                                        "line option!\n%%\n");
754                            }
755                            console_handles[handle].warning_printed = 1;
756                            return 0;
757                    }
758            }
759    
760            return 1;
761  }  }
762    
763    
764  /*  /*
765   *  console_init_main():   *  console_init_main():
766   *   *
767   *  Put host's console into single-character (non-canonical) mode.   *  Puts the host's console into single-character (non-canonical) mode.
768   */   */
769  void console_init_main(struct emul *emul)  void console_init_main(struct emul *emul)
770  {  {
# Line 763  void console_init_main(struct emul *emul Line 814  void console_init_main(struct emul *emul
814    
815    
816  /*  /*
817     *  console_debug_dump():
818     *
819     *  Dump debug info, if verbose >= 2.
820     */
821    void console_debug_dump(struct machine *machine)
822    {
823            int i, iadd = DEBUG_INDENTATION, listed_main = 0;
824    
825            if (verbose < 2)
826                    return;
827    
828            debug("console slaves (xterms): %s\n", allow_slaves?
829                "yes" : "no");
830    
831            debug("console handles:\n");
832            debug_indentation(iadd);
833    
834            for (i=0; i<n_console_handles; i++) {
835                    if (!console_handles[i].in_use)
836                            continue;
837                    debug("%i: \"%s\"", i, console_handles[i].name);
838                    if (console_handles[i].using_xterm)
839                            debug(" [xterm]");
840                    if (console_handles[i].inputonly)
841                            debug(" [inputonly]");
842                    if (console_handles[i].outputonly)
843                            debug(" [outputonly]");
844                    if (i == machine->main_console_handle) {
845                            debug(" [MAIN CONSOLE]");
846                            listed_main = 1;
847                    }
848                    debug("\n");
849            }
850    
851            debug_indentation(-iadd);
852    
853            if (!listed_main)
854                    fatal("WARNING! no main console handle?\n");
855    }
856    
857    
858    /*
859   *  console_allow_slaves():   *  console_allow_slaves():
860   *   *
861   *  This function tells the console subsystem whether or not to open up   *  This function tells the console subsystem whether or not to open up
# Line 775  void console_allow_slaves(int allow) Line 868  void console_allow_slaves(int allow)
868    
869    
870  /*  /*
871     *  console_are_slaves_allowed():
872     *
873     *  Returns the value of allow_slaves.
874     */
875    int console_are_slaves_allowed(void)
876    {
877            return allow_slaves;
878    }
879    
880    
881    /*
882     *  console_warn_if_slaves_are_needed():
883     *
884     *  Prints an error (during startup of the emulator) if slave xterms are needed
885     *  (i.e. there is more than one console handle in use which is used for
886     *  INPUT), but they are not currently allowed.
887     *
888     *  This function should be called during startup (with init = 1), and every
889     *  time a console handle changes/upgrades its in_use_for_input from 0 to 1.
890     *
891     *  If init is non-zero, this function doesn't return if there was a warning.
892     *
893     *  If init is zero, no warning is printed. 1 is returned if there were more
894     *  than one input, 0 otherwise.
895     */
896    int console_warn_if_slaves_are_needed(int init)
897    {
898            int i, n = 0;
899    
900            if (allow_slaves)
901                    return 0;
902    
903            for (i=MAIN_CONSOLE+1; i<n_console_handles; i++)
904                    if (console_handles[i].in_use &&
905                        console_handles[i].in_use_for_input &&
906                        !console_handles[i].using_xterm)
907                            n ++;
908    
909            if (n > 1) {
910                    if (init) {
911                            fatal("#\n#  ERROR! More than one console input is "
912                                "in use,\n#  but xterm slaves are not enabled.\n"
913                                "#\n");
914                            fatal("#  Use -x to enable slave xterms.)\n#\n");
915                            for (i=MAIN_CONSOLE+1; i<n_console_handles; i++)
916                                    if (console_handles[i].in_use &&
917                                        console_handles[i].in_use_for_input &&
918                                        !console_handles[i].using_xterm)
919                                            fatal("#  console handle %i: '%s'\n",
920                                                i, console_handles[i].name);
921                            fatal("#\n");
922                            exit(1);
923                    }
924                    return 1;
925            }
926    
927            return 0;
928    }
929    
930    
931    /*
932   *  console_init():   *  console_init():
933   *   *
934   *  This function should be called before any other console_*() function   *  This function should be called before any other console_*() function
# Line 785  void console_init(void) Line 939  void console_init(void)
939          int handle;          int handle;
940          struct console_handle *chp;          struct console_handle *chp;
941    
942            console_settings = settings_new();
943    
944            settings_add(global_settings, "console", 1,
945                SETTINGS_TYPE_SUBSETTINGS, 0, console_settings);
946    
947            settings_add(console_settings, "allow_slaves", 0,
948                SETTINGS_TYPE_INT, SETTINGS_FORMAT_YESNO, (void *)&allow_slaves);
949    
950          chp = console_new_handle("MAIN", &handle);          chp = console_new_handle("MAIN", &handle);
951          if (handle != MAIN_CONSOLE) {          if (handle != MAIN_CONSOLE) {
952                  printf("console_init(): fatal error: could not create"                  printf("console_init(): fatal error: could not create"
953                      " console 0: handle = %i\n", handle);                      " console 0: handle = %i\n", handle);
954                  exit(1);                  exit(1);
955          }          }
956    
957            chp->in_use_for_input = 1;
958    }
959    
960    
961    /*
962     *  console_deinit():
963     *
964     *  Unregister settings registered by console_init().
965     */
966    void console_deinit(void)
967    {
968            settings_remove(console_settings, "allow_slaves");
969            settings_remove(global_settings, "console");
970  }  }
971    

Legend:
Removed from v.10  
changed lines
  Added in v.42

  ViewVC Help
Powered by ViewVC 1.1.26