Began creating the listbox widget. It's still just a structure.
[xuni.git] / xuni.c
blobc1152380fe7061b16a7d6d4a0c57fb80f9d96ec8
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <time.h>
4 #include "SDL.h"
5 #include "graphics.h"
6 #include "loop.h"
7 #include "menu.h"
8 #include "xuni.h"
10 static const char *get_ctime(void);
11 static void print_message(const char *type, const char *message,
12 const char *file, int line);
14 #ifdef WIN32
15 #include <windows.h>
16 int STDCALL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow) {
17 #else
18 int main(int argc, char *argv[]) {
19 #endif
20 struct smode_t smode;
21 SDL_Surface *screen;
22 struct font_t font;
23 struct theme_t theme;
25 default_smode(&smode);
26 screen = init_sdl(&smode);
28 font.point = -1;
29 reload_fonts(&font, &smode);
31 load_theme(&theme, "alienglow");
32 resize_theme(&theme, &smode);
34 main_loop(screen, &smode, &font, &theme);
35 /* screen may be invalid at this point if the window was resized.
36 To reflect changes here, pass &screen as an SDL_Surface **. */
38 free_fonts(&font);
39 free_theme(&theme);
40 quit_sdl();
41 return 0;
44 char *duplicate_string(const char *str, size_t len) {
45 char *p = malloc(len + 1);
46 strcpy(p, str);
47 return p;
50 static const char *get_ctime(void) {
51 time_t tt = time(0);
53 return ctime(&tt);
56 static void print_message(const char *type, const char *message,
57 const char *file, int line) {
59 const char *sdlerror = SDL_GetError(), *t = get_ctime();
60 FILE *log = fopen(LOG_FILE, "at");
62 fprintf(stderr, "xuni (%s:%i): %s at %s %s\n SDL: %s\n",
63 file, line, type, t, message, sdlerror);
64 if(log) {
65 fprintf(log, "xuni (%s:%i): %s at %s %s\n SDL: %s\n",
66 file, line, type, t, message, sdlerror);
67 fclose(log);
71 void print_warning(const char *message, const char *file, int line) {
72 print_message("Warning", message, file, line);
75 void fatal_error(const char *message, const char *file, int line) {
76 print_message("Fatal error", message, file, line);
78 quit_sdl();
79 exit(1);