31 #include <libFreeWRL.h>
41 #define min(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; })
45 #define max(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
48 void fv_print_version()
50 const char *libver, *progver;
52 libver = libFreeWRL_get_version();
53 progver = freewrl_get_version();
55 printf(
"Program version: %s\nLibrary version: %s\n", progver, libver);
56 printf(
"\nFreeWRL VRML/X3D browser from (http://freewrl.sf.net)\n");
57 printf(
" type \"man freewrl\" to view man pages\n\n");
62 printf(
"usage: freewrl [options] <VRML or X3D file|URL>\n\n"
63 " -h|--help This help.\n"
64 " -v|--version Print version.\n"
66 " -c|--fullscreen Set window fullscreen\n"
67 " -g|--geometry <WxH> Set window geometry (W width, H height).\n"
68 " -b|--big Set window size to 800x600.\n"
69 "\nGeneral options:\n"
70 " -e|--eai Enable EAI.\n"
71 " -f|--fast Set global texture size to -256 (fast).\n"
72 " -W|--linewidth <float> Set line width.\n"
73 " -Q|--nocollision Disable collision management.\n"
74 "\nSnapshot options:\n"
75 " -p|--gif Set file format to GIF (default is PNG).\n"
76 " -n|--snapfile <string> Set output file name pattern with <string>,\n"
77 " (use %%n for iteration number).\n"
78 " -o|--snaptmp <string> Set output directory for snap files.\n"
79 #
if defined(DOSNAPSEQUENCE)
80 "\nSnapshot sequence options:\n"
81 " -l|--seq Set snapshot sequence mode.\n"
82 " -m|--seqfile <string> Set sequence file name pattern.\n"
83 " -q|--maximg <number> Set maximum number of files in sequence.\n"
86 " -V|--eaiverbose Set EAI subsystem messages.\n"
87 " -r|--screendist <float> Set screen distance.\n"
88 " -y|--eyedist <float> Set eye distance.\n"
89 " -u|--shutter Set shutter glasses.\n"
90 " -t|--stereo <float> Set stereo parameter (angle factor).\n"
91 " -A|--anaglyph <string> Set anaglyph color pair ie: RB for left red, right blue. any of RGBCAM.\n"
92 " -B|--sidebyside Set side-by-side stereo.\n"
93 " -U|--updown Set updown stereo.\n"
94 " -K|--keypress <string> Set immediate key pressed when ready.\n"
95 " -R|--record Record to /recording/<scene>.fwplay.\n"
96 " -F|--fixture Playback from /recording/<scene>.fwplay to /fixture.\n"
97 " -P|--playback Playback from /recording/<scene>.fwplay to /playback\n"
98 " -N|--nametest <string> Set name of .fwplay test file\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"
107 " -N|--nametest <string> Set name of .fwplay test file\n"
108 "\nInternal options:\n"
109 " -i|--plugin <string> Called from plugin.\n"
110 " -j|--fd <number> Pipe to command the program.\n"
111 " -k|--instance <number> Instance of plugin.\n"
112 " -L|--logfile <filename> Log file where all messages should go.\n"
114 " -C|--curl Use libcurl instead of wget.\n"
120 const char * fv_validate_string_arg(
const char *optarg)
124 static struct option long_options[] = {
128 {
"help", no_argument, 0,
'h'},
129 {
"version", no_argument, 0,
'v'},
131 {
"fullscreen", no_argument, 0,
'c'},
132 {
"FPS", required_argument, 0,
'E'},
133 {
"pin", required_argument, 0,
'I'},
134 {
"want", required_argument, 0,
'w'},
135 {
"geometry", required_argument, 0,
'g'},
136 {
"big", no_argument, 0,
'b'},
138 {
"eai", no_argument, 0,
'e'},
139 {
"fast", no_argument, 0,
'f'},
140 {
"linewidth", required_argument, 0,
'W'},
141 {
"nocollision", no_argument, 0,
'Q'},
143 {
"gif", no_argument, 0,
'p'},
144 {
"snapfile", required_argument, 0,
'n'},
145 {
"snaptmp", required_argument, 0,
'o'},
147 #if defined(DOSNAPSEQUENCE)
148 {
"seq", no_argument, 0,
'l'},
149 {
"seqfile", required_argument, 0,
'm'},
150 {
"maximg", required_argument, 0,
'q'},
153 {
"eaiverbose", no_argument, 0,
'V'},
154 {
"screendist", required_argument, 0,
'r'},
155 {
"eyedist", required_argument, 0,
'y'},
156 {
"shutter", no_argument, 0,
'u'},
157 {
"stereo", required_argument, 0,
't'},
158 {
"anaglyph", required_argument, 0,
'A'},
159 {
"sidebyside", no_argument, 0,
'B'},
160 {
"updown", no_argument, 0,
'U'},
161 {
"keypress", required_argument, 0,
'K'},
162 {
"plugin", required_argument, 0,
'i'},
163 {
"fd", required_argument, 0,
'j'},
164 {
"instance", required_argument, 0,
'k'},
165 {
"logfile", required_argument, 0,
'L'},
167 {
"curl", no_argument, 0,
'C'},
169 {
"display", required_argument, 0,
'd'},
170 {
"record", no_argument, 0,
'R'},
171 {
"fixture", no_argument, 0,
'F'},
172 {
"playback", no_argument, 0,
'P'},
173 {
"nametest", required_argument, 0,
'N'},
174 {
"colorscheme", required_argument, 0,
'G'},
175 {
"colors", required_argument, 0,
'H'},
176 {
"shadingStyle",required_argument,0,
'^'},
180 int fv_find_opt_for_optopt(
char c) {
186 p = &(long_options[i]);
194 p = &(long_options[++i]);
201 int fv_parseCommandLine (
int argc,
char **argv,
freewrl_params_t *fv_params)
206 int option_index = 0;
207 int real_option_index;
208 const char *real_option_name;
212 #if defined(DOSNAPSEQUENCE)
213 static const char optstring[] =
"efg:hi:j:k:vVlpq:m:n:o:bsQW:K:Xcr:y:utCL:d:RFPN:";
215 static const char optstring[] =
"efg:hi:j:k:vVpn:o:bsQW:K:Xcr:y:utCL:d:RFPN:";
225 # if HAVE_GETOPT_LONG
227 #if defined(_MSC_VER)
228 #define strncasecmp _strnicmp
232 printf(
"argv[%d]=%s\n",c,argv[c]);
235 c = _getopt_internal (argc, argv, optstring, long_options, &option_index, 0);
237 c = getopt_long(argc, argv, optstring, long_options, &option_index);
241 c = getopt(argc, argv, optstring);
248 real_option_index = fv_find_opt_for_optopt(optopt);
250 real_option_index = fv_find_opt_for_optopt(c);
252 if (real_option_index < 0) {
253 real_option_name = argv[optind-1];
255 real_option_name = long_options[real_option_index].name;
257 DEBUG_ARGS(
"option_index=%d optopt=%c option=%s\n", real_option_index, c,
265 ERROR_MSG(
"ERROR: unknown option or missing argument to option: %c (%s)\n",
266 c, real_option_name);
288 fv_params->fullscreen = TRUE;
290 #if defined(HAVE_XF86_VMODE)
291 fv_params->fullscreen = TRUE;
293 printf(
"\nFullscreen mode is only available when xf86vmode extension is\n"
294 "supported by your X11 server: i.e. XFree86 version 4 or later,\n"
295 "Xorg version 1.0 or later.\n"
296 "Configure should autodetect it for you. If not please report"
297 "this problem to\n\t " PACKAGE_BUGREPORT
"\n");
298 fv_params->fullscreen = FALSE;
309 ERROR_MSG(
"Argument missing for option -g/--geometry\n");
312 if (!fwl_parse_geometry_string(optarg,
313 &fv_params->width, &fv_params->height,
314 &fv_params->xpos, &fv_params->ypos)) {
315 ERROR_MSG(
"Malformed geometry string: %s\n", optarg);
322 fv_params->width = 800;
323 fv_params->height = 600;
327 printf (
"Parameter --display = %s\n", optarg);
328 sscanf(optarg,
"%ld", (
long int *)&ldtmp);
329 fv_params->winToEmbedInto = ldtmp;
337 fv_params->enableEAI = TRUE;
345 sscanf(optarg,
"%g", &ftmp);
346 fwl_set_LineWidth(ftmp);
351 ConsoleMessage (
"ignoring collision off mode on command line");
361 fwl_set_SnapFile(optarg);
365 fwl_set_SnapTmp(optarg);
370 #if defined(DOSNAPSEQUENCE)
376 fwl_set_SeqFile(optarg);
380 sscanf(optarg,
"%d",&maxSnapImages);
381 fwl_set_MaxImages(maxSnapImages);
388 fwl_init_EaiVerbose();
389 fv_params->verbose = TRUE;
393 fwl_set_ScreenDist(optarg);
397 fwl_set_EyeDist(optarg);
406 fwl_set_StereoParameter(optarg);
409 fwl_set_AnaglyphParameter(optarg);
413 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 #ifdef USE_SNAPSHOT_TESTING
476 fwl_set_modeRecord();
479 fwl_set_modeFixture();
482 fwl_set_modePlayback();
485 fwl_set_nameTest(optarg);
496 ERROR_MSG(
"ERROR: getopt returned character code 0%o, unknown error.\n", c);
520 if (optind != (argc-1)) {
521 ERROR_MSG(
"FreeWRL accepts only one argument: we have %d\n", (argc-optind));
524 DEBUG_MSG(
"Start url: %s\n", argv[optind]);
525 start_url = STRDUP(argv[optind]);
531 void fv_parseEnvVars()
534 fwl_set_strictParsing (getenv(
"FREEWRL_STRICT_PARSING") != NULL);
535 fwl_set_plugin_print (getenv(
"FREEWRL_DO_PLUGIN_PRINT") != NULL);
536 fwl_set_occlusion_disable (getenv(
"FREEWRL_NO_GL_ARB_OCCLUSION_QUERY") != NULL);
537 fwl_set_print_opengl_errors (getenv(
"FREEWRL_PRINT_OPENGL_ERRORS") != NULL);
538 fwl_set_trace_threads (getenv(
"FREEWRL_TRACE_THREADS") != NULL);
540 char *env_texture_size = getenv(
"FREEWRL_TEXTURE_SIZE");
541 if (env_texture_size) {
542 unsigned int local_texture_size ;
543 sscanf(env_texture_size,
"%u", &local_texture_size);
544 TRACE_MSG(
"Env: TEXTURE SIZE %u.\n", local_texture_size);
545 fwl_set_texture_size(local_texture_size);