]> icculus.org git repositories - taylor/freespace2.git/blob - src/freespace2/main.cpp
better memory debugging
[taylor/freespace2.git] / src / freespace2 / main.cpp
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell
5  * or otherwise commercially exploit the source or things you created based on
6  * the source.
7  */
8
9 #include "pstypes.h"
10
11 #ifdef PLAT_UNIX
12 #include <sys/types.h>
13 #include <sys/stat.h>
14 #endif
15
16 #undef malloc
17 #undef free
18
19 extern int game_main(const char *szCmdLine);
20
21
22 int main(int argc, char **argv)
23 {
24         char *argptr = NULL;
25         int i;
26         int len = 0;
27         int retr = 0;
28
29 #ifdef PLAT_UNIX
30         // make sure we create files with user access only
31         umask(S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
32 #endif
33
34         for (i = 1; i < argc; i++) {
35                 len += strlen(argv[i]) + 1;
36         }
37
38         if (len > 0) {
39                 argptr = (char *)malloc(len+5);
40
41                 if (argptr == NULL) {
42                         SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error!", "Ran out of memory in main()!", NULL);
43                         exit(1);
44                 }
45
46                 memset(argptr, 0, len+5);
47
48                 for (i = 1; i < argc; i++) {
49                         strcat(argptr, argv[i]);
50                         strcat(argptr, " ");
51                 }
52         }
53
54         try {
55                 retr = game_main(argptr);
56         } catch(...) {
57                 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error!", "Exception caught in main()!", NULL);
58         }
59
60         if (argptr) {
61                 free(argptr);
62         }
63
64         return retr;    
65 }