33#include <libFreeWRL.h>
37#include "../sound/internal.h"
38#include "../lib/ui/common.h"
45 #define min(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; })
49 #define max(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
52void fv_print_version()
54 const char *libver, *progver;
56 libver = libFreeWRL_get_version();
57 progver = freewrl_get_version();
59 printf(
"Program version: %s\nLibrary version: %s\n", progver, libver);
60 printf(
"\nFreeWRL VRML/X3D browser from (http://freewrl.sf.net)\n");
61 printf(
" type \"man freewrl\" to view man pages\n\n");
66 printf(
"usage: freewrl [options] <VRML or X3D file|URL>\n\n"
67 " -h|--help This help.\n"
68 " -v|--version Print version.\n"
70 " -c|--fullscreen Set window fullscreen\n"
71 " -g|--geometry <WxH> Set window geometry (W width, H height).\n"
72 " -b|--big Set window size to 800x600.\n"
73 "\nGeneral options:\n"
74 " -e|--eai Enable EAI.\n"
76 " -W|--linewidth <float> Set line width.\n"
78 "\nSnapshot options:\n"
79 " -p|--gif Set file format to GIF (default is PNG).\n"
80 " -n|--snapfile <string> Set output file name pattern with <string>,\n"
81 " (use %%n for iteration number).\n"
82 " -o|--snaptmp <string> Set output directory for snap files.\n"
84 " -V|--eaiverbose Set EAI subsystem messages.\n"
85 " -r|--screendist <float> Set screen distance.\n"
86 " -y|--eyedist <float> Set eye distance.\n"
87 " -u|--shutter Set shutter glasses.\n"
88 " -t|--stereo <float> Set stereo parameter (angle factor).\n"
89 " -A|--anaglyph <string> Set anaglyph color pair ie: RB for left red, right blue. any of RGBCAM.\n"
90 " -B|--sidebyside Set side-by-side stereo.\n"
91 " -U|--updown Set updown stereo.\n"
92 " -q|--cardboard set cardboard stereo \n"
93 " -Q|--quadrant set quadrant view \n"
94 " -O|--screenorient set screen orientation degrees {0 90 180 270} \n"
95 " -T|--touchtype set pointing device touch type {0=single 1=emulate multitouch 2=multitouch 3=gesture \n"
96 " -K|--keypress <string> Set immediate key pressed when ready.\n"
97 " -R|--record Record to /recording/<scene>.fwplay.\n"
98 " -P|--playback Playback from /recording/<scene>.fwplay to /playback\n"
99 " -I|--pin TF Pin statusbar(T/F) menubar(T/F)\n"
100 " -w|--want TF Want statusbar(T/F) menubar(T/F)\n"
101 " -E|--FPS <int> Target Maximum Frames Per Second\n"
102 " =^|--shadingStyle <int> 0=Flat 1=gouraud 2=phong 3=wire\n"
103 " -D|--DIS Allow Distributed Interactive Simulation\n"
104 " --DISaddress <string> DIS default ipv4 address or localhost \n"
105 " --DISport <int> DIS default port 1000 - 99999\n"
106 " --DISsite <int> DIS default site ID (facility / room ID) 1-255\n"
107 " --DISapp <int> DIS application instance ID 1-255\n"
108 " --DISverbose DIS console display of received pdus\n"
109 " -S|--set <int> testing set default 0, added to port number for DIS\n"
110 " -J|--javascript <string> SM spidermonkey, DUK duktape, NONE stubs\n"
111 " -x|--boxes Draw bounding boxes\n"
112 " -X|--viewpoints Show viewpointss\n"
113 " -l|--rig Draw HAnim rig\n"
114 " -M|--midi <int> choose MIDI transport 1=msg 2=ump\n"
115 "\nInternal options:\n"
116 " -i|--plugin <string> Called from plugin.\n"
117 " -j|--fd <number> Pipe to command the program.\n"
118 " -k|--instance <number> Instance of plugin.\n"
119 " -L|--logfile <filename> Log file where all messages should go.\n"
120 " --skinGPU TF for HAnim T= GPU skinning F= CPU skinning .\n"
122 " -C|--curl Use libcurl instead of wget.\n"
133const char * fv_validate_string_arg(
const char *optarg)
137 static struct option long_options[] = {
141 {
"help", no_argument, 0,
'h'},
142 {
"version", no_argument, 0,
'v'},
144 {
"fullscreen", no_argument, 0,
'c'},
145 {
"FPS", required_argument, 0,
'E'},
146 {
"pin", required_argument, 0,
'I'},
147 {
"want", required_argument, 0,
'w'},
148 {
"geometry", required_argument, 0,
'g'},
149 {
"big", no_argument, 0,
'b'},
151 {
"eai", no_argument, 0,
'e'},
153 {
"linewidth", required_argument, 0,
'W'},
155 {
"rig",no_argument,0,
'l'},
157 {
"gif", no_argument, 0,
'p'},
158 {
"snapfile", required_argument, 0,
'n'},
159 {
"snaptmp", required_argument, 0,
'o'},
161 {
"eaiverbose", no_argument, 0,
'V'},
162 {
"screendist", required_argument, 0,
'r'},
163 {
"eyedist", required_argument, 0,
'y'},
164 {
"shutter", no_argument, 0,
'u'},
165 {
"stereo", required_argument, 0,
't'},
166 {
"anaglyph", required_argument, 0,
'A'},
167 {
"sidebyside", no_argument, 0,
'B'},
168 {
"cardboard", no_argument, 0,
'q'},
169 {
"quadrant", no_argument, 0,
'Q'},
170 {
"screenorient", required_argument, 0,
'O'},
171 {
"touchtype", required_argument, 0,
'T'},
172 {
"updown", no_argument, 0,
'U'},
173 {
"keypress", required_argument, 0,
'K'},
174 {
"plugin", required_argument, 0,
'i'},
175 {
"fd", required_argument, 0,
'j'},
176 {
"instance", required_argument, 0,
'k'},
177 {
"logfile", required_argument, 0,
'L'},
179 {
"curl", no_argument, 0,
'C'},
181 {
"display", required_argument, 0,
'd'},
182 {
"record", no_argument, 0,
'R'},
183 {
"playback", no_argument, 0,
'P'},
184 {
"colorscheme", required_argument, 0,
'G'},
185 {
"colors", required_argument, 0,
'H'},
186 {
"shadingStyle",required_argument,0,
'^'},
187 {
"set",required_argument,0,
'S'},
188 {
"javascript",required_argument,0,
'J'},
189 {
"boxes",no_argument,0,
'x'},
190 {
"viewpoints",no_argument,0,
'X'},
191 {
"midi",required_argument,0,
'M'},
192 {
"DIS",no_argument,0,
'D'},
193 {
"DISaddress",required_argument,0,128},
194 {
"DISport",required_argument,0,129},
195 {
"DISsite",required_argument,0,130},
196 {
"DISapp",required_argument,0,131},
197 {
"skinGPU",required_argument,0,132},
198 {
"DISverbose",no_argument,0,133},
202int fv_find_opt_for_optopt(
char c) {
208 p = &(long_options[i]);
216 p = &(long_options[++i]);
223int fv_parseCommandLine (
int argc,
char **argv, freewrl_params_t *fv_params,
int *url_index)
228 int option_index = 0;
229 int real_option_index;
230 const char *real_option_name;
234 static const char optstring[] =
"efg:hi:j:k:vVpn:o:O:bsQqW:K:Xcr:y:utCL:d:RT:FPN:Y:DS:J:xM:l";
238#if defined(_DEBUG) || defined(DEBUG)
240 printf(
"argv[%d]=%s\n",c,argv[c]);
251#define strncasecmp _strnicmp
252 c = _getopt_internal (argc, argv, optstring, long_options, &option_index, 0);
254 c = getopt_long(argc, argv, optstring, long_options, &option_index);
257 c = getopt(argc, argv, optstring);
261#if defined(_DEBUG) || defined(DEBUG)
262 printf(
"c=%c argv[%d]=%s\n",c,optind,argv[optind]);
263#define DEBUG_ARGS printf
273 real_option_index = fv_find_opt_for_optopt(optopt);
275 real_option_index = fv_find_opt_for_optopt(c);
277 if (real_option_index < 0) {
278 real_option_name = argv[optind-1];
280 real_option_name = long_options[real_option_index].name;
282 DEBUG_ARGS(
"option_index=%d optopt=%c option=%s\n", real_option_index, c,
290 printf(
"ERROR: unknown option or missing argument to option: %c (%s)\n",
291 c, real_option_name);
316 fv_params->fullscreen = TRUE;
318#if defined(HAVE_XF86_VMODE)
319 fv_params->fullscreen = TRUE;
321 printf(
"\nFullscreen mode is only available when xf86vmode extension is\n"
322 "supported by your X11 server: i.e. XFree86 version 4 or later,\n"
323 "Xorg version 1.0 or later.\n"
324 "Configure should autodetect it for you. If not please report"
325 "this problem to\n\t " PACKAGE_BUGREPORT
"\n");
326 fv_params->fullscreen = FALSE;
337 ERROR_MSG(
"Argument missing for option -g/--geometry\n");
341 if (!fwl_parse_geometry_string(optarg,
342 &fv_params->width, &fv_params->height,
343 &fv_params->xpos, &fv_params->ypos, &fv_params->wnum)) {
344 ERROR_MSG(
"Malformed geometry string: %s\n", optarg);
351 fv_params->width = 800;
352 fv_params->height = 600;
356 printf (
"Parameter --display = %s\n", optarg);
357 sscanf(optarg,
"%zu", (
size_t*)&ldtmp);
358 fv_params->winToEmbedInto = ldtmp;
366 fv_params->enableEAI = TRUE;
374 sscanf(optarg,
"%g", &ftmp);
375 fwl_set_LineWidth(ftmp);
384#ifndef FRONTEND_DOES_SNAPSHOTS
390 fwl_set_SnapFile(optarg);
394 fwl_set_SnapTmp(optarg);
401 fwl_init_EaiVerbose();
402 fv_params->verbose = TRUE;
406 fwl_set_ScreenDist(optarg);
410 fwl_set_EyeDist(optarg);
419 fwl_setDrawBoundingBoxes(1);
422 fwl_setShowViewpoints(1);
426 fwl_set_StereoParameter(optarg);
429 fwl_set_AnaglyphParameter(optarg);
433 fwl_init_SideBySide();
439 fwl_set_DISaddress(optarg);
442 sscanf(optarg,
"%d", &itmp);
443 fwl_set_DISport(itmp);
446 sscanf(optarg,
"%d", &itmp);
447 fwl_set_DISsite(itmp);
450 sscanf(optarg,
"%d", &itmp);
451 fwl_set_DISapplication(itmp);
455 fwl_set_DISverbose(TRUE);
459 fwl_set_skinning(optarg[0]);
464 sscanf(optarg,
"%d", &itmp);
465 fwl_set_testset(itmp);
472 fwl_init_cardboard();
480 sscanf(optarg,
"%d",°rees);
481 if(degrees != 0 && degrees != 90 && degrees != 180 && degrees != 270 ) degrees = 0;
482 fwl_setOrientation2(degrees);
488 sscanf(optarg,
"%d",&ttype);
489 if(ttype < 0 || ttype > 3) ttype = 0;
490 fwl_set_touchtype(ttype);
492 fv_params->touchtype = ttype;
498 fwl_set_KeyString(optarg);
509 fwl_set_sbh_pin_option(optarg);
512 fwl_set_sbh_want_option(optarg);
516 int ival = optarg[0] -
'0';
517 fwl_setShadingStyle(max(min(ival,3),0));
521 sscanf(optarg,
"%d", &itmp);
522 fwl_set_target_fps(itmp);
528 sscanf(optarg,
"pipe:%d",&_fw_pipe);
529 isBrowserPlugin = TRUE;
533 sscanf(optarg,
"%d",&_fw_browser_plugin);
537 sscanf(optarg,
"%u",(
unsigned int *)(
void *)(&_fw_instance));
541 fwl_setDrawRig(TRUE);
547 fwl_set_logfile(optarg);
549 ERROR_MSG(
"Option -L|--logfile: log filename required\n");
554 fwl_setJsEngine(optarg);
557 fwl_set_modeRecord();
560 fwl_set_modePlayback();
566 sscanf(optarg,
"%d", &ival);
567 set_MIDITransport(ival);
580 ERROR_MSG(
"ERROR: getopt returned character code 0%o, unknown error.\n", c);
605 if (optind != (argc-1)) {
606 ERROR_MSG(
"FreeWRL accepts only one argument: we have %d\n", (argc-optind));
609 DEBUG_MSG(
"Start url: %s\n", argv[optind]);
617void fv_parseEnvVars()
620 fwl_set_strictParsing (getenv(
"FREEWRL_STRICT_PARSING") != NULL);
621 fwl_set_plugin_print (getenv(
"FREEWRL_DO_PLUGIN_PRINT") != NULL);
622 fwl_set_occlusion_disable (getenv(
"FREEWRL_NO_GL_ARB_OCCLUSION_QUERY") != NULL);
623 fwl_set_print_opengl_errors (getenv(
"FREEWRL_PRINT_OPENGL_ERRORS") != NULL);
624 fwl_set_trace_threads (getenv(
"FREEWRL_TRACE_THREADS") != NULL);
626 char *env_texture_size = getenv(
"FREEWRL_TEXTURE_SIZE");
627 if (env_texture_size) {
628 unsigned int local_texture_size ;
629 sscanf(env_texture_size,
"%u", &local_texture_size);
630 TRACE_MSG(
"Env: TEXTURE SIZE %u.\n", local_texture_size);
631 fwl_set_texture_size(local_texture_size);