main.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * ncurses based simulator
  3. *
  4. * Copyright (c) 2009 Openmoko Inc.
  5. *
  6. * Authors Daniel Mack <daniel@caiaq.de>
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <ncurses.h>
  24. #include <wikilib.h>
  25. #include <guilib.h>
  26. #include <msg.h>
  27. #include <input.h>
  28. static int loglevel = MSG_LEVEL_MAX;
  29. /* empty dummies - no framebuffer here */
  30. void fb_set_pixel(int x, int y, int val) {}
  31. void fb_refresh(void) {}
  32. void fb_clear(void) {}
  33. unsigned char *framebuffer = NULL;
  34. int wl_input_wait(struct wl_input_event *ev, int sleep)
  35. {
  36. ev->type = WL_INPUT_EV_TYPE_KEYBOARD;
  37. ev->key_event.keycode = getch();
  38. ev->key_event.value = 1;
  39. return 0;
  40. }
  41. void set_loglevel(int level)
  42. {
  43. loglevel = level;
  44. }
  45. void msg(int level, const char *format, ...)
  46. {
  47. va_list ap;
  48. int attrs;
  49. if (level > loglevel)
  50. return;
  51. switch (level) {
  52. case MSG_DEBUG:
  53. attrs = COLOR_PAIR(3);
  54. break;
  55. case MSG_ERROR:
  56. attrs = COLOR_PAIR(2);
  57. break;
  58. default:
  59. attrs = COLOR_PAIR(1);
  60. break;
  61. }
  62. va_start(ap, format);
  63. attron(attrs);
  64. vwprintw(stdscr, format, ap);
  65. attroff(attrs);
  66. va_end(ap);
  67. }
  68. int main(int argc, char *argv[])
  69. {
  70. framebuffer = (unsigned char *)malloc(guilib_framebuffer_size());
  71. initscr();
  72. keypad(stdscr, TRUE);
  73. noecho();
  74. cbreak();
  75. scrollok(stdscr, TRUE);
  76. idlok(stdscr, TRUE);
  77. start_color();
  78. init_pair(1, COLOR_WHITE, COLOR_BLACK);
  79. init_pair(2, COLOR_RED, COLOR_BLACK);
  80. init_pair(3, COLOR_YELLOW, COLOR_BLACK);
  81. wikilib_init();
  82. guilib_init();
  83. wikilib_run();
  84. /* never reached */
  85. return 0;
  86. }