[All of these changes were wrought on the Dell.]
[xuni.git] / xuni.c
blobf47022cd7cac8dab5002b6368d37c1f8dce2daec
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stdarg.h>
4 #include <time.h>
5 #include "SDL.h"
6 #include "graphics.h"
7 #include "loop.h"
8 #include "menu.h"
9 #include "settings.h"
10 #include "xuni.h"
12 static const char *get_ctime(void);
13 static void log_printf(const char *format, ...);
14 static void print_message(const char *type, const char *message,
15 const char *file, int line);
17 #ifdef WIN32
18 #include <windows.h>
19 int STDCALL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow) {
20 #else
21 int main(int argc, char *argv[]) {
22 #endif
23 struct smode_t smode;
24 struct font_t font;
25 struct theme_t theme;
27 load_settings(&smode, &font, &theme);
29 init_sdl(&smode);
31 reload_fonts(&font, &smode);
33 load_theme(&theme);
34 resize_theme(&theme, &smode);
36 main_loop(&smode, &font, &theme);
38 write_settings(&smode, &font, &theme);
40 free_fonts(&font);
41 free_theme(&theme);
42 quit_sdl();
43 return 0;
46 char *duplicate_string(const char *str, size_t len) {
47 char *p = malloc(len + 1);
48 strcpy(p, str);
49 return p;
52 static const char *get_ctime(void) {
53 time_t tt = time(0);
55 return ctime(&tt);
58 static void log_printf(const char *format, ...) {
59 FILE *log = fopen(LOG_FILE, "at");
60 va_list arg;
62 va_start(arg, format);
64 vfprintf(stderr, format, arg);
65 vfprintf(log, format, arg);
67 va_end(arg);
69 fclose(log);
72 static void print_message(const char *type, const char *message,
73 const char *file, int line) {
75 const char *sdlerror = SDL_GetError(), *t = get_ctime();
77 log_printf("xuni: %s from %s:%i at %s %s\n SDL: %s\n",
78 type, file, line, t, message, sdlerror);
81 void print_warning(const char *message, const char *file, int line) {
82 print_message("Warning", message, file, line);
85 void settings_error(const char *message, const char *sfile, int sline) {
86 const char *t = get_ctime();
88 log_printf("xuni: Error in settings file %s:%i at %s %s\n",
89 sfile, sline, t, message);
92 void fatal_error(const char *message, const char *file, int line) {
93 print_message("Fatal error", message, file, line);
95 quit_sdl();
96 exit(1);