FreeWRL / FreeX3D 4.3.0
main.c
1/*
2
3 FreeWRL main program.
4
5*/
6
7/****************************************************************************
8 This file is part of the FreeWRL/FreeX3D Distribution.
9
10 Copyright 2009 CRC Canada. (http://www.crc.gc.ca)
11
12 FreeWRL/FreeX3D is free software: you can redistribute it and/or modify
13 it under the terms of the GNU Lesser Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
16
17 FreeWRL/FreeX3D is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with FreeWRL/FreeX3D. If not, see <http://www.gnu.org/licenses/>.
24****************************************************************************/
25
26
27// OLD_IPHONE_AQUA #if !defined(TARGET_AQUA)
28
29
30#include <config.h>
31#include <system.h>
32#include <internal.h>
33
34#include <libFreeWRL.h>
35
36#include "../lib/main/MainLoop.h"
37
38#include "main.h"
39#include "options.h"
40#ifdef _MSC_VER
41#include "getopt.h"
42#endif
43
48/* file/url to start FreeWRL with */
49//char *start_url;
50
54static int CaughtSEGV = FALSE;
55void fv_catch_SIGQUIT();
56void fv_catch_SIGSEGV();
57
58#if !defined(CYGWIN)
59void fv_catch_SIGALRM(int);
60void fv_catch_SIGHUP();
61#endif
62
63#if defined(_MSC_VER)
64#include <shlwapi.h>
65char *get_current_dir();
66char *strBackslash2fore(char *str);
67
68#endif
69
70void fwExit(int iret){
71 //printf("press Enter to exit:");
72 //getchar();
73 //exit(iret);
74 fw_exit(iret); //in libfreewrl
75}
76void fwg_register_consolemessage_callback(void(*callback)(char *));
77void fw_printstring(char *str){
78 printf("%s",str);
79}
83int main (int argc, char **argv)
84{
85 const char *libver;
86 const char *progver;
87 int url_index;
88 char * start_url;
89
90//#if defined(_ANDROID)
91// int tempIsAndroid = 1 ;
92//#else
93// int tempIsAndroid = 0 ;
94//#endif
95
96 freewrl_params_t *fv_params = NULL;
97#ifdef __linux__
98 char * libpath = getenv("LD_LIBRARY_PATH");
99 if(libpath == NULL){
100 libpath = "/usr/lib64";
101 }
102 printf("\nlibrary path %s\n",libpath);
103 if(strstr(libpath,"/tmp/.mount")){
104 //freewrl is being used in an appimage
105 char targetdir[2000];
106 //assume the first entry is to /lib
107 char *ce = strstr(libpath,"/lib/:");
108 *ce = (char)0;
109 strcpy(targetdir,libpath);
110 strcat(targetdir,"/fonts");
111 printf("setting FONTS_DIR %s\n",targetdir);
112 setenv("FREEWRL_FONTS_DIR",targetdir,1);
113 }
114#endif
115 char consoleBuffer[200];
116 fwl_init_instance(); //before setting any structs we need a struct allocated
117 fwg_register_consolemessage_callback(fw_printstring);
118 fwg_setConsoleParam_maxLines(30);
119 fwg_setConsoleParam_maxLineLength(70);
120 fwg_setConsoleParam_replaceTabs(1);
121
122 /* first, get the FreeWRL shared lib, and verify the version. */
123 libver = libFreeWRL_get_version();
124 progver = freewrl_get_version();
125 if (strcmp(progver, libver)) {
126 sprintf(consoleBuffer ,"FreeWRL expected library version %s, got %s...\n",progver, libver);
127 fwl_StringConsoleMessage(consoleBuffer);
128 }else{
129 sprintf(consoleBuffer, "libfreewrl version %s\n", libver);
130 fwl_StringConsoleMessage(consoleBuffer);
131 }
132
133#ifdef _MSC_VER
134 /*
135 Set fonts directory
136 ideally we would check if we are in a) projectfiles go ../../fonts b) else c:/windows/Fonts
137 */
138 if(strstr(argv[0],"projectfiles"))
139 {
140 /* we are testing - use local fonts (may be obsolete someday) - and Vera might not be installed in C:/windows/fonts */
141 static char *fdir;
142 char *xdir, *xe;
143 fdir = malloc(MAX_PATH);
144 xdir = malloc(MAX_PATH);
145 strcpy(fdir,"FREEWRL_FONTS_DIR=");
146 //strcat(fdir,"C:/Windows/Fonts");
147 strcpy(xdir,argv[0]);
148 xe = strstr(xdir,"projectfiles");
149 if(xe) xe[0] = '\0';
150 xdir = strcat(xdir,"appleOSX/OSX_Specific/fonts");
151 strcat(fdir,xdir);
152 _putenv( fdir );
153 }
154 else
155 {
156 /* deployed system (with intalled fonts) - use system fonts
157 we plan to use a professional installer to install the fonts to %windir%\Fonts directory
158 where all the system fonts already are.
159 Then in this program we will get the %windir%\Fonts directory, and set it as temporary
160 environment variable for InputFunctions.C > makeFontsDirectory() to fetch.
161 */
162 static char *fdir;
163 char *syspath;
164 syspath = getenv("windir");
165 //printf("windir path=[%s]\n",syspath);
166 fdir = malloc(MAX_PATH);
167 strcpy(fdir,"FREEWRL_FONTS_DIR=");
168 strcat(fdir,syspath);
169 strcat(fdir,"/Fonts");
170 _putenv( fdir );
171 }
172 //get_current_dir();
173 /* VBO preference - comment out for vbos (vertex buffer objects - a rendering optimization) */
174 _putenv("FREEWRL_NO_VBOS=1");
175 //_putenv("FREEWRL_USE_VBOS=1");
176
177
178#endif
179
180 /* install the signal handlers
181 win32 > for debugging its better not to install them: the debugger will then take you to the crash line
182 if signal handlers are installed, then all you see is a SIGSEG printf
183 */
184#ifdef WANT_SIGNALHANDLERS
185 signal(SIGTERM, (void(*)(int)) fv_catch_SIGQUIT);
186 signal(SIGSEGV, (void(*)(int)) fv_catch_SIGSEGV);
187
188 #if !defined(CYGWIN)
189 signal(SIGQUIT, (void(*)(int)) fv_catch_SIGQUIT);
190 signal(SIGALRM, (void(*)(int)) fv_catch_SIGALRM);
191 signal(SIGHUP, (void(*)(int)) fv_catch_SIGHUP);
192 #endif
193#endif
194 /* Before we parse the command line, setup the FreeWRL default parameters */
195 fv_params = calloc(1, sizeof(freewrl_params_t));
196
197 /* Default values */
198 fv_params->width = 672; //640
199 fv_params->height = 480;
200
201 fv_params->fullscreen = FALSE;
202 fv_params->winToEmbedInto = INT_ID_UNDEFINED;
203 fv_params->verbose = FALSE;
204 // fv_params->collision = 1; // if you set it, you need to update ui button with a call
205 //setMenuButton_collision(fv_params->collision);
206 //fwl_init_StereoDefaults();
207
208 /* parse command line arguments */
209 if (fv_parseCommandLine(argc, argv,fv_params, &url_index)) {
210 if(argc > 1){
211 start_url = argv[url_index];
212#ifdef _MSC_VER
213 if(start_url)
214 start_url = strBackslash2fore(start_url);
215#endif
216 }else{
217 start_url = NULL;
218 }
219 }
220
221
222 /* doug- redirect stdout to a file - works, useful for sending bug reports */
223 /*freopen("freopen.txt", "w", stdout ); */
224
225 /* Put env parse here, because this gives systems that do not have env vars the chance to do it their own way. */
226 fv_parseEnvVars();
227 /* start threads, parse initial scene, etc */
228 if ( 1 ) {
229 /* give control to the library */
230 if (!fwl_initFreeWRL(fv_params)) {
231 ERROR_MSG("main: aborting during initialization.\n");
232 fwExit(1);
233 }
234 fwl_startFreeWRL(start_url);
235 } else {
236 /* keep control
237 if (!fv_initFreeWRL(fv_params)) {
238 ERROR_MSG("main: aborting during initialization.\n");
239 fwExit(1);
240 }
241 fv_startFreeWRL(start_url); */
242 }
243 return 0;
244}
245/* #include "src/bin/main-inc.c" */
246
247/* SIGQUIT handler - plugin code sends a SIGQUIT... */
248void fv_catch_SIGQUIT()
249{
250 /* fwl_StringConsoleMessage("FreeWRL got a sigquit signal"); */
251 /* shut up any SIGSEGVs we might get now. */
252 CaughtSEGV = TRUE;
253 //fwl_doQuit();
254 fwExit(-2);
255}
256
257void fv_catch_SIGSEGV()
258{
259 if (!CaughtSEGV) {
260
261 //fwl_StringConsoleMessage("FreeWRL got a SIGSEGV - please feel free to report this - http://freewrl.sf.net.\n");
262 //bombs H: its coming in on an annonymous thread and console message needs TSD (thread-specific-data via gglobal)
263 printf("FreeWRL got a SIGSEGV - please feel free to report this - http://freewrl.sf.net.\n");
264 CaughtSEGV = TRUE;
265 }
266 fwExit(1);
267}
268
269#if !defined(CYGWIN)
270
271void fv_catch_SIGHUP()
272{
273 /* fwl_StringConsoleMessage ("FreeWRL got a SIGHUP signal - reloading"); */
274 /* MBFILES Anchor_ReplaceWorld(BrowserFullPath); */
275}
276
277void fv_catch_SIGALRM(int sig)
278{
279 signal(SIGALRM, SIG_IGN);
280
281 /* stuffs to do on alarm */
282 /* fprintf(stderr,"An alarm signal just arrived ...IT WAS IGNORED!\n"); */
283 /* end of alarm actions */
284
285#if defined(_MSC_VER)
286 printf("\a");
287#else
288 alarm(0);
289#endif
290 signal(SIGALRM, fv_catch_SIGALRM);
291}
292
293#endif
294
295// OLD_IPHONE_AQUA #endif // AQUA
Initialization.
Definition libFreeWRL.h:72