33#include <libFreeWRL.h>
43 #define min(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; })
47 #define max(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
50void fv_print_version()
52 const char *libver, *progver;
54 libver = libFreeWRL_get_version();
55 progver = freewrl_get_version();
57 printf(
"Program version: %s\nLibrary version: %s\n", progver, libver);
58 printf(
"\nFreeWRL VRML/X3D browser from (http://freewrl.sf.net)\n");
59 printf(
" type \"man freewrl\" to view man pages\n\n");
64 printf(
"usage: freewrl [options] <VRML or X3D file|URL>\n\n"
65 " -h|--help This help.\n"
66 " -v|--version Print version.\n"
68 " -c|--fullscreen Set window fullscreen\n"
69 " -g|--geometry <WxH> Set window geometry (W width, H height).\n"
70 " -b|--big Set window size to 800x600.\n"
71 "\nGeneral options:\n"
72 " -e|--eai Enable EAI.\n"
74 " -W|--linewidth <float> Set line width.\n"
76 "\nSnapshot options:\n"
77 " -p|--gif Set file format to GIF (default is PNG).\n"
78 " -n|--snapfile <string> Set output file name pattern with <string>,\n"
79 " (use %%n for iteration number).\n"
80 " -o|--snaptmp <string> Set output directory for snap files.\n"
82 " -V|--eaiverbose Set EAI subsystem messages.\n"
83 " -r|--screendist <float> Set screen distance.\n"
84 " -y|--eyedist <float> Set eye distance.\n"
85 " -u|--shutter Set shutter glasses.\n"
86 " -t|--stereo <float> Set stereo parameter (angle factor).\n"
87 " -A|--anaglyph <string> Set anaglyph color pair ie: RB for left red, right blue. any of RGBCAM.\n"
88 " -B|--sidebyside Set side-by-side stereo.\n"
89 " -U|--updown Set updown stereo.\n"
90 " -K|--keypress <string> Set immediate key pressed when ready.\n"
91#ifdef USE_SNAPSHOT_TESTING
92 " -R|--record Record to /recording/<scene>.fwplay.\n"
93 " -F|--fixture Playback from /recording/<scene>.fwplay to /fixture.\n"
94 " -P|--playback Playback from /recording/<scene>.fwplay to /playback\n"
95 " -N|--nametest <string> Set name of .fwplay test file\n"
96 " -Y|--testpath <string> Set path to recording directory\n"
98 " -G|--colorscheme <string> UI colorscheme by builtin name: {original,angry,\n"
99 " aqua,favicon,midnight,neon:lime,neon:yellow,neon:cyan,neon:pink}\n"
100 " -H|--colors <string> UI colorscheme by 4 html colors in order: \n"
101 " panel,menuIcon,statusText,messageText ie \"#3D4557,#00FFFF,#00FFFF.#00FFFF\" \n"
102 " -I|--pin TF Pin statusbar(T/F) menubar(T/F)\n"
103 " -w|--want TF Want statusbar(T/F) menubar(T/F)\n"
104 " -E|--FPS <int> Target Maximum Frames Per Second\n"
105 " =^|--shadingStyle <int> 0=Flat 1=gouraud 2=phong 3=wire\n"
107 " -D|--DIS Allow Distributed Interactive Simulation\n"
108 " -J|--javascript <string> SM spidermonkey, DUK duktape, NONE stubs\n"
109 " -x|--boxes Draw bounding boxes\n"
110 "\nInternal options:\n"
111 " -i|--plugin <string> Called from plugin.\n"
112 " -j|--fd <number> Pipe to command the program.\n"
113 " -k|--instance <number> Instance of plugin.\n"
114 " -L|--logfile <filename> Log file where all messages should go.\n"
116 " -C|--curl Use libcurl instead of wget.\n"
122const char * fv_validate_string_arg(
const char *optarg)
126 static struct option long_options[] = {
130 {
"help", no_argument, 0,
'h'},
131 {
"version", no_argument, 0,
'v'},
133 {
"fullscreen", no_argument, 0,
'c'},
134 {
"FPS", required_argument, 0,
'E'},
135 {
"pin", required_argument, 0,
'I'},
136 {
"want", required_argument, 0,
'w'},
137 {
"geometry", required_argument, 0,
'g'},
138 {
"big", no_argument, 0,
'b'},
140 {
"eai", no_argument, 0,
'e'},
142 {
"linewidth", required_argument, 0,
'W'},
145 {
"gif", no_argument, 0,
'p'},
146 {
"snapfile", required_argument, 0,
'n'},
147 {
"snaptmp", required_argument, 0,
'o'},
149 {
"eaiverbose", no_argument, 0,
'V'},
150 {
"screendist", required_argument, 0,
'r'},
151 {
"eyedist", required_argument, 0,
'y'},
152 {
"shutter", no_argument, 0,
'u'},
153 {
"stereo", required_argument, 0,
't'},
154 {
"anaglyph", required_argument, 0,
'A'},
155 {
"sidebyside", no_argument, 0,
'B'},
156 {
"updown", no_argument, 0,
'U'},
157 {
"keypress", required_argument, 0,
'K'},
158 {
"plugin", required_argument, 0,
'i'},
159 {
"fd", required_argument, 0,
'j'},
160 {
"instance", required_argument, 0,
'k'},
161 {
"logfile", required_argument, 0,
'L'},
163 {
"curl", no_argument, 0,
'C'},
165 {
"display", required_argument, 0,
'd'},
166#ifdef USE_SNAPSHOT_TESTING
167 {
"record", no_argument, 0,
'R'},
168 {
"fixture", no_argument, 0,
'F'},
169 {
"playback", no_argument, 0,
'P'},
170 {
"nametest", required_argument, 0,
'N'},
171 {
"testpath", required_argument, 0,
'Y'},
173 {
"colorscheme", required_argument, 0,
'G'},
174 {
"colors", required_argument, 0,
'H'},
175 {
"shadingStyle",required_argument,0,
'^'},
176 {
"DIS",no_argument,0,
'D'},
177 {
"javascript",required_argument,0,
'J'},
178 {
"boxes",no_argument,0,
'x'},
182int fv_find_opt_for_optopt(
char c) {
188 p = &(long_options[i]);
196 p = &(long_options[++i]);
203int fv_parseCommandLine (
int argc,
char **argv,
freewrl_params_t *fv_params,
int *url_index)
208 int option_index = 0;
209 int real_option_index;
210 const char *real_option_name;
214 static const char optstring[] =
"efg:hi:j:k:vVpn:o:bsQW:K:Xcr:y:utCL:d:RFPN:Y:DJ:x";
218#if defined(_DEBUG) || defined(DEBUG)
220 printf(
"argv[%d]=%s\n",c,argv[c]);
231#define strncasecmp _strnicmp
232 c = _getopt_internal (argc, argv, optstring, long_options, &option_index, 0);
234 c = getopt_long(argc, argv, optstring, long_options, &option_index);
237 c = getopt(argc, argv, optstring);
240#if defined(_DEBUG) || defined(DEBUG)
241 printf(
"c=%c argv[%d]=%s\n",c,optind,argv[optind]);
242#define DEBUG_ARGS printf
252 real_option_index = fv_find_opt_for_optopt(optopt);
254 real_option_index = fv_find_opt_for_optopt(c);
256 if (real_option_index < 0) {
257 real_option_name = argv[optind-1];
259 real_option_name = long_options[real_option_index].name;
261 DEBUG_ARGS(
"option_index=%d optopt=%c option=%s\n", real_option_index, c,
269 ERROR_MSG(
"ERROR: unknown option or missing argument to option: %c (%s)\n",
270 c, real_option_name);
295 fv_params->fullscreen = TRUE;
297#if defined(HAVE_XF86_VMODE)
298 fv_params->fullscreen = TRUE;
300 printf(
"\nFullscreen mode is only available when xf86vmode extension is\n"
301 "supported by your X11 server: i.e. XFree86 version 4 or later,\n"
302 "Xorg version 1.0 or later.\n"
303 "Configure should autodetect it for you. If not please report"
304 "this problem to\n\t " PACKAGE_BUGREPORT
"\n");
305 fv_params->fullscreen = FALSE;
316 ERROR_MSG(
"Argument missing for option -g/--geometry\n");
320 if (!fwl_parse_geometry_string(optarg,
321 &fv_params->width, &fv_params->height,
322 &fv_params->xpos, &fv_params->ypos)) {
323 ERROR_MSG(
"Malformed geometry string: %s\n", optarg);
330 fv_params->width = 800;
331 fv_params->height = 600;
335 printf (
"Parameter --display = %s\n", optarg);
336 sscanf(optarg,
"%ld", (
long int *)&ldtmp);
337 fv_params->winToEmbedInto = ldtmp;
345 fv_params->enableEAI = TRUE;
353 sscanf(optarg,
"%g", &ftmp);
354 fwl_set_LineWidth(ftmp);
363#ifndef FRONTEND_DOES_SNAPSHOTS
369 fwl_set_SnapFile(optarg);
373 fwl_set_SnapTmp(optarg);
380 fwl_init_EaiVerbose();
381 fv_params->verbose = TRUE;
385 fwl_set_ScreenDist(optarg);
389 fwl_set_EyeDist(optarg);
398 fwl_setDrawBoundingBoxes(1);
402 fwl_set_StereoParameter(optarg);
405 fwl_set_AnaglyphParameter(optarg);
409 fwl_init_SideBySide();
421 fwl_set_KeyString(optarg);
425 fwl_set_ui_colorscheme(optarg);
428 fwl_set_ui_colors(optarg);
432 fwl_set_sbh_pin_option(optarg);
435 fwl_set_sbh_want_option(optarg);
439 int ival = optarg[0] -
'0';
440 fwl_setShadingStyle(max(min(ival,3),0));
444 sscanf(optarg,
"%d", &itmp);
445 fwl_set_target_fps(itmp);
451 sscanf(optarg,
"pipe:%d",&_fw_pipe);
452 isBrowserPlugin = TRUE;
456 sscanf(optarg,
"%d",&_fw_browser_plugin);
460 sscanf(optarg,
"%u",(
unsigned int *)(
void *)(&_fw_instance));
466 fwl_set_logfile(optarg);
468 ERROR_MSG(
"Option -L|--logfile: log filename required\n");
473 fwl_setJsEngine(optarg);
476#ifdef USE_SNAPSHOT_TESTING
479 fwl_set_modeRecord();
482 fwl_set_modeFixture();
485 fwl_set_modePlayback();
488 fwl_set_nameTest(optarg);
491 fwl_set_testPath(optarg);
502 ERROR_MSG(
"ERROR: getopt returned character code 0%o, unknown error.\n", c);
527 if (optind != (argc-1)) {
528 ERROR_MSG(
"FreeWRL accepts only one argument: we have %d\n", (argc-optind));
531 DEBUG_MSG(
"Start url: %s\n", argv[optind]);
539void fv_parseEnvVars()
542 fwl_set_strictParsing (getenv(
"FREEWRL_STRICT_PARSING") != NULL);
543 fwl_set_plugin_print (getenv(
"FREEWRL_DO_PLUGIN_PRINT") != NULL);
544 fwl_set_occlusion_disable (getenv(
"FREEWRL_NO_GL_ARB_OCCLUSION_QUERY") != NULL);
545 fwl_set_print_opengl_errors (getenv(
"FREEWRL_PRINT_OPENGL_ERRORS") != NULL);
546 fwl_set_trace_threads (getenv(
"FREEWRL_TRACE_THREADS") != NULL);
548 char *env_texture_size = getenv(
"FREEWRL_TEXTURE_SIZE");
549 if (env_texture_size) {
550 unsigned int local_texture_size ;
551 sscanf(env_texture_size,
"%u", &local_texture_size);
552 TRACE_MSG(
"Env: TEXTURE SIZE %u.\n", local_texture_size);
553 fwl_set_texture_size(local_texture_size);