]> icculus.org git repositories - taylor/freespace2.git/blob - src/freespace2/main.cpp
merge in updated platform code
[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
17 extern int game_main(const char *szCmdLine);
18
19
20 extern "C"
21 int main(int argc, char *argv[])
22 {
23         char *argptr = NULL;
24         int i;
25         int len = 0;
26         int retr = 0;
27
28 #ifdef PLAT_UNIX
29         // make sure we create files with user access only
30         umask(S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
31 #endif
32
33         for (i = 1; i < argc; i++) {
34                 len += strlen(argv[i]) + 1;
35         }
36
37         if (len > 0) {
38                 argptr = (char *)SDL_malloc(len+5);
39
40                 if (argptr == NULL) {
41                         SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error!", "Ran out of memory in main()!", NULL);
42                         exit(1);
43                 }
44
45                 memset(argptr, 0, len+5);
46
47                 for (i = 1; i < argc; i++) {
48                         SDL_strlcat(argptr, argv[i], len+5);
49                         SDL_strlcat(argptr, " ", len+5);
50                 }
51         }
52
53         try {
54                 retr = game_main(argptr);
55         } catch(...) {
56                 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error!", "Exception caught in main()!", NULL);
57         }
58
59         if (argptr) {
60                 SDL_free(argptr);
61         }
62
63         return retr;    
64 }