33#include <libFreeWRL.h>
37#include "../sound/internal.h"
44 #define min(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; })
48 #define max(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
51void fv_print_version()
53 const char *libver, *progver;
55 libver = libFreeWRL_get_version();
56 progver = freewrl_get_version();
58 printf(
"Program version: %s\nLibrary version: %s\n", progver, libver);
59 printf(
"\nFreeWRL VRML/X3D browser from (http://freewrl.sf.net)\n");
60 printf(
" type \"man freewrl\" to view man pages\n\n");
65 printf(
"usage: freewrl [options] <VRML or X3D file|URL>\n\n"
66 " -h|--help This help.\n"
67 " -v|--version Print version.\n"
69 " -c|--fullscreen Set window fullscreen\n"
70 " -g|--geometry <WxH> Set window geometry (W width, H height).\n"
71 " -b|--big Set window size to 800x600.\n"
72 "\nGeneral options:\n"
73 " -e|--eai Enable EAI.\n"
75 " -W|--linewidth <float> Set line width.\n"
77 "\nSnapshot options:\n"
78 " -p|--gif Set file format to GIF (default is PNG).\n"
79 " -n|--snapfile <string> Set output file name pattern with <string>,\n"
80 " (use %%n for iteration number).\n"
81 " -o|--snaptmp <string> Set output directory for snap files.\n"
83 " -V|--eaiverbose Set EAI subsystem messages.\n"
84 " -r|--screendist <float> Set screen distance.\n"
85 " -y|--eyedist <float> Set eye distance.\n"
86 " -u|--shutter Set shutter glasses.\n"
87 " -t|--stereo <float> Set stereo parameter (angle factor).\n"
88 " -A|--anaglyph <string> Set anaglyph color pair ie: RB for left red, right blue. any of RGBCAM.\n"
89 " -B|--sidebyside Set side-by-side stereo.\n"
90 " -U|--updown Set updown stereo.\n"
91 " -K|--keypress <string> Set immediate key pressed when ready.\n"
92#ifdef USE_SNAPSHOT_TESTING
93 " -R|--record Record to /recording/<scene>.fwplay.\n"
94 " -F|--fixture Playback from /recording/<scene>.fwplay to /fixture.\n"
95 " -P|--playback Playback from /recording/<scene>.fwplay to /playback\n"
96 " -N|--nametest <string> Set name of .fwplay test file\n"
97 " -Y|--testpath <string> Set path to recording directory\n"
99 " -G|--colorscheme <string> UI colorscheme by builtin name: {original,angry,\n"
100 " aqua,favicon,midnight,neon:lime,neon:yellow,neon:cyan,neon:pink}\n"
101 " -H|--colors <string> UI colorscheme by 4 html colors in order: \n"
102 " panel,menuIcon,statusText,messageText ie \"#3D4557,#00FFFF,#00FFFF.#00FFFF\" \n"
103 " -I|--pin TF Pin statusbar(T/F) menubar(T/F)\n"
104 " -w|--want TF Want statusbar(T/F) menubar(T/F)\n"
105 " -E|--FPS <int> Target Maximum Frames Per Second\n"
106 " =^|--shadingStyle <int> 0=Flat 1=gouraud 2=phong 3=wire\n"
108 " -D|--DIS Allow Distributed Interactive Simulation\n"
109 " -J|--javascript <string> SM spidermonkey, DUK duktape, NONE stubs\n"
110 " -x|--boxes Draw bounding boxes\n"
111 "\nInternal options:\n"
112 " -i|--plugin <string> Called from plugin.\n"
113 " -j|--fd <number> Pipe to command the program.\n"
114 " -k|--instance <number> Instance of plugin.\n"
115 " -L|--logfile <filename> Log file where all messages should go.\n"
117 " -C|--curl Use libcurl instead of wget.\n"
123const char * fv_validate_string_arg(
const char *optarg)
127 static struct option long_options[] = {
131 {
"help", no_argument, 0,
'h'},
132 {
"version", no_argument, 0,
'v'},
134 {
"fullscreen", no_argument, 0,
'c'},
135 {
"FPS", required_argument, 0,
'E'},
136 {
"pin", required_argument, 0,
'I'},
137 {
"want", required_argument, 0,
'w'},
138 {
"geometry", required_argument, 0,
'g'},
139 {
"big", no_argument, 0,
'b'},
141 {
"eai", no_argument, 0,
'e'},
143 {
"linewidth", required_argument, 0,
'W'},
146 {
"gif", no_argument, 0,
'p'},
147 {
"snapfile", required_argument, 0,
'n'},
148 {
"snaptmp", required_argument, 0,
'o'},
150 {
"eaiverbose", no_argument, 0,
'V'},
151 {
"screendist", required_argument, 0,
'r'},
152 {
"eyedist", required_argument, 0,
'y'},
153 {
"shutter", no_argument, 0,
'u'},
154 {
"stereo", required_argument, 0,
't'},
155 {
"anaglyph", required_argument, 0,
'A'},
156 {
"sidebyside", no_argument, 0,
'B'},
157 {
"updown", no_argument, 0,
'U'},
158 {
"keypress", required_argument, 0,
'K'},
159 {
"plugin", required_argument, 0,
'i'},
160 {
"fd", required_argument, 0,
'j'},
161 {
"instance", required_argument, 0,
'k'},
162 {
"logfile", required_argument, 0,
'L'},
164 {
"curl", no_argument, 0,
'C'},
166 {
"display", required_argument, 0,
'd'},
167#ifdef USE_SNAPSHOT_TESTING
168 {
"record", no_argument, 0,
'R'},
169 {
"fixture", no_argument, 0,
'F'},
170 {
"playback", no_argument, 0,
'P'},
171 {
"nametest", required_argument, 0,
'N'},
172 {
"testpath", required_argument, 0,
'Y'},
174 {
"colorscheme", required_argument, 0,
'G'},
175 {
"colors", required_argument, 0,
'H'},
176 {
"shadingStyle",required_argument,0,
'^'},
177 {
"DIS",no_argument,0,
'D'},
178 {
"javascript",required_argument,0,
'J'},
179 {
"boxes",no_argument,0,
'x'},
183int fv_find_opt_for_optopt(
char c) {
189 p = &(long_options[i]);
197 p = &(long_options[++i]);
204int fv_parseCommandLine (
int argc,
char **argv,
freewrl_params_t *fv_params,
int *url_index)
209 int option_index = 0;
210 int real_option_index;
211 const char *real_option_name;
215 static const char optstring[] =
"efg:hi:j:k:vVpn:o:bsQW:K:Xcr:y:utCL:d:RFPN:Y:DJ:x";
219#if defined(_DEBUG) || defined(DEBUG)
221 printf(
"argv[%d]=%s\n",c,argv[c]);
232#define strncasecmp _strnicmp
233 c = _getopt_internal (argc, argv, optstring, long_options, &option_index, 0);
235 c = getopt_long(argc, argv, optstring, long_options, &option_index);
238 c = getopt(argc, argv, optstring);
241#if defined(_DEBUG) || defined(DEBUG)
242 printf(
"c=%c argv[%d]=%s\n",c,optind,argv[optind]);
243#define DEBUG_ARGS printf
253 real_option_index = fv_find_opt_for_optopt(optopt);
255 real_option_index = fv_find_opt_for_optopt(c);
257 if (real_option_index < 0) {
258 real_option_name = argv[optind-1];
260 real_option_name = long_options[real_option_index].name;
262 DEBUG_ARGS(
"option_index=%d optopt=%c option=%s\n", real_option_index, c,
270 ERROR_MSG(
"ERROR: unknown option or missing argument to option: %c (%s)\n",
271 c, real_option_name);
296 fv_params->fullscreen = TRUE;
298#if defined(HAVE_XF86_VMODE)
299 fv_params->fullscreen = TRUE;
301 printf(
"\nFullscreen mode is only available when xf86vmode extension is\n"
302 "supported by your X11 server: i.e. XFree86 version 4 or later,\n"
303 "Xorg version 1.0 or later.\n"
304 "Configure should autodetect it for you. If not please report"
305 "this problem to\n\t " PACKAGE_BUGREPORT
"\n");
306 fv_params->fullscreen = FALSE;
317 ERROR_MSG(
"Argument missing for option -g/--geometry\n");
321 if (!fwl_parse_geometry_string(optarg,
322 &fv_params->width, &fv_params->height,
323 &fv_params->xpos, &fv_params->ypos)) {
324 ERROR_MSG(
"Malformed geometry string: %s\n", optarg);
331 fv_params->width = 800;
332 fv_params->height = 600;
336 printf (
"Parameter --display = %s\n", optarg);
337 sscanf(optarg,
"%ld", (
long int *)&ldtmp);
338 fv_params->winToEmbedInto = ldtmp;
346 fv_params->enableEAI = TRUE;
354 sscanf(optarg,
"%g", &ftmp);
355 fwl_set_LineWidth(ftmp);
364#ifndef FRONTEND_DOES_SNAPSHOTS
370 fwl_set_SnapFile(optarg);
374 fwl_set_SnapTmp(optarg);
381 fwl_init_EaiVerbose();
382 fv_params->verbose = TRUE;
386 fwl_set_ScreenDist(optarg);
390 fwl_set_EyeDist(optarg);
399 fwl_setDrawBoundingBoxes(1);
403 fwl_set_StereoParameter(optarg);
406 fwl_set_AnaglyphParameter(optarg);
410 fwl_init_SideBySide();
422 fwl_set_KeyString(optarg);
426 fwl_set_ui_colorscheme(optarg);
429 fwl_set_ui_colors(optarg);
433 fwl_set_sbh_pin_option(optarg);
436 fwl_set_sbh_want_option(optarg);
440 int ival = optarg[0] -
'0';
441 fwl_setShadingStyle(max(min(ival,3),0));
445 sscanf(optarg,
"%d", &itmp);
446 fwl_set_target_fps(itmp);
452 sscanf(optarg,
"pipe:%d",&_fw_pipe);
453 isBrowserPlugin = TRUE;
457 sscanf(optarg,
"%d",&_fw_browser_plugin);
461 sscanf(optarg,
"%u",(
unsigned int *)(
void *)(&_fw_instance));
467 fwl_set_logfile(optarg);
469 ERROR_MSG(
"Option -L|--logfile: log filename required\n");
474 fwl_setJsEngine(optarg);
477#ifdef USE_SNAPSHOT_TESTING
480 fwl_set_modeRecord();
483 fwl_set_modeFixture();
486 fwl_set_modePlayback();
489 fwl_set_nameTest(optarg);
492 fwl_set_testPath(optarg);
503 ERROR_MSG(
"ERROR: getopt returned character code 0%o, unknown error.\n", c);
528 if (optind != (argc-1)) {
529 ERROR_MSG(
"FreeWRL accepts only one argument: we have %d\n", (argc-optind));
532 DEBUG_MSG(
"Start url: %s\n", argv[optind]);
540void fv_parseEnvVars()
543 fwl_set_strictParsing (getenv(
"FREEWRL_STRICT_PARSING") != NULL);
544 fwl_set_plugin_print (getenv(
"FREEWRL_DO_PLUGIN_PRINT") != NULL);
545 fwl_set_occlusion_disable (getenv(
"FREEWRL_NO_GL_ARB_OCCLUSION_QUERY") != NULL);
546 fwl_set_print_opengl_errors (getenv(
"FREEWRL_PRINT_OPENGL_ERRORS") != NULL);
547 fwl_set_trace_threads (getenv(
"FREEWRL_TRACE_THREADS") != NULL);
549 char *env_texture_size = getenv(
"FREEWRL_TEXTURE_SIZE");
550 if (env_texture_size) {
551 unsigned int local_texture_size ;
552 sscanf(env_texture_size,
"%u", &local_texture_size);
553 TRACE_MSG(
"Env: TEXTURE SIZE %u.\n", local_texture_size);
554 fwl_set_texture_size(local_texture_size);