Example #1
0
RtVoid PreWorld()
#endif
{
	if ( g_cl_fb )
	{
		RiDisplay( tokenCast("aqsis"), tokenCast("framebuffer"), tokenCast("rgb"), NULL );
	}
	else if ( !g_cl_type.empty() )
	{
		RiDisplay( tokenCast("aqsis"), tokenCast(g_cl_type.c_str()),
				   tokenCast(g_cl_mode.c_str()), NULL );
	}
	else if ( !g_cl_addtype.empty() )
	{
		RiDisplay( tokenCast("+aqsis"), tokenCast(g_cl_addtype.c_str()),
				   tokenCast(g_cl_mode.c_str()), NULL );
	}

	// Pass the statistics option onto Aqsis.
	if ( g_cl_endofframe >= 0 )
	{
		RiOption( tokenCast("statistics"), "endofframe", &g_cl_endofframe, RI_NULL );
	}

	// Pass the crop window onto Aqsis.
	if( g_cl_cropWindow.size() == 4 )
	{
		RiCropWindow(g_cl_cropWindow[0], g_cl_cropWindow[1], g_cl_cropWindow[2], g_cl_cropWindow[3]);
	}

	// Pass in specified resolution.
	if(g_cl_res.size() == 2)
	{
		RiFormat(g_cl_res[0], g_cl_res[1], 1.0f);
	}

#	if ENABLE_MPDUMP
	// Pass the statistics option onto Aqsis.
	if ( g_cl_mpdump )
	{
		RtInt enabled = 1;
		RiOption( "mpdump", "enabled", &enabled, RI_NULL );
	}
#	endif

	// Parse all the command line options with the RIB parser.
	for(TqInt i = 0, end = g_cl_options.size(); i < end; ++i)
	{
		std::istringstream inStream(g_cl_options[i]);
		Aqsis::QGetRenderContextI()->parseRibStream(inStream, "command_line_option");
	}
	return;
}
static bool checkArrays(const ArgParse::apintvec& foo,
                        const ArgParse::apfloatvec& bar,
                        const ArgParse::apstringvec& english,
                        const ArgParse::apstringvec& german)
{
	if (foo.size() != 4 || bar.size() != 4 ||
	        english.size() != 4 || german.size() != 4)
	{
		return false;
	}

	for (int i = 0; i < 4; i++)
	{
		ArgParse::apstring en, de;
		switch (i+1)
		{
				case 1:
				en = "one";
				de = "eins";
				break;
				case 2:
				en = "two";
				de = "zwei";
				break;
				case 3:
				en = "three";
				de = "drei";
				break;
				case 4:
				en = "four";
				de = "vier";
				break;
		}
		if (foo[i] != ArgParse::apint(i+1) ||
		        bar[i] != ArgParse::apfloat(i+1) ||
		        english[i] != en || german[i] != de)
		{
			return false;
		}
	}

	return true;
}
Example #3
0
int main( int argc, const char** argv )
{
	std::signal(SIGINT, aqsisSignalHandler);
	std::signal(SIGABRT, aqsisSignalHandler);
	RtInt returnCode = 0;

	StartMemoryDebugging();
	{
		ArgParse ap;
		ap.usageHeader( ArgParse::apstring( "Aqsis command line renderer\nUsage: " ) + argv[ 0 ] + " [options] [RIB file...]" );
		ap.argFlag( "help", "\aPrint this help and exit", &g_cl_help );
		ap.alias( "help" , "h" );
		ap.argFlag( "version", "\aPrint version information and exit", &g_cl_version );
		ap.argFlag( "pause", "\aWait for a keypress on completion", &g_cl_pause );
		ap.argFlag( "progress", "\aPrint progress information", &g_cl_progress );
		ap.argFlag( "Progress", "\aPrint PRMan-compatible progress information (ignores -progressformat)", &g_cl_Progress );
		ap.argString( "progressformat", "=string\aprintf-style format string for -progress", &g_cl_strprogress );
		ap.argInt( "endofframe", "=integer\aEquivalent to \"endofframe\" RIB option", &g_cl_endofframe );
		ap.argInt( "verbose", "=integer\aSet log output level\n"
		           "\a0 = errors\n"
		           "\a1 = warnings (default)\n"
		           "\a2 = information\n"
		           "\a3 = debug", &g_cl_verbose );
		ap.alias( "verbose", "v" );
		ap.argFlag( "echoapi", "\aEcho all RI API calls to the log output (experimental)", &g_cl_echoapi);

		ap.argInt( "priority", "=integer\aControl the priority class of aqsis.\n"
			"\a0 = idle\n"
			"\a1 = normal\n"
			"\a2 = high\n"
			"\a3 = RT", &g_cl_priority);
		ap.alias( "priority", "z");
		
		ap.argString( "type", "=string\aSpecify a display device type to use", &g_cl_type );
		ap.argString( "addtype", "=string\aSpecify a display device type to add", &g_cl_addtype );
		ap.argString( "mode", "=string\aSpecify a display device mode to use", &g_cl_mode );
		ap.argFlag( "fb", "\aSame as --type=\"framebuffer\" --mode=\"rgb\"", &g_cl_fb );
		ap.alias( "fb", "d" );
		ap.argFloats( "crop", " x1 x2 y1 y2\aSpecify a crop window, values are in screen space.", &g_cl_cropWindow, ArgParse::SEP_ARGV, 4);
		ap.argFlag( "nocolor", "\aDisable colored output", &g_cl_no_color );
		ap.argFlag( "beep", "\aBeep on completion of all ribs", &g_cl_beep );
		ap.alias( "nocolor", "nc" );
		ap.argInts( "res", " x y\aSpecify the resolution of the render.", &g_cl_res, ArgParse::SEP_ARGV, 2);
		ap.argStrings( "option", "=string\aA valid RIB Option string, can be specified multiple times.", &g_cl_options);
#		ifdef AQSIS_SYSTEM_POSIX
		ap.argFlag( "syslog", "\aLog messages to syslog", &g_cl_syslog );
#		endif // AQSIS_SYSTEM_POSIX
#		if ENABLE_MPDUMP
		ap.argFlag( "mpdump", "\aOutput MP list to a custom 'dump' file", &g_cl_mpdump );
#		endif // ENABLE_MPDUMP

		ap.argString( "shaders", "=string\aOverride the default shader searchpath(s)", &g_cl_shader_path );
		ap.argString( "archives", "=string\aOverride the default archive searchpath(s)", &g_cl_archive_path );
		ap.argString( "textures", "=string\aOverride the default texture searchpath(s)", &g_cl_texture_path );
		ap.argString( "displays", "=string\aOverride the default display searchpath(s)", &g_cl_display_path );
		ap.argString( "procedurals", "=string\aOverride the default procedural searchpath(s)", &g_cl_procedural_path );
		ap.allowUnrecognizedOptions();

		if ( argc > 1 && !ap.parse( argc - 1, argv + 1 ) )
		{
			Aqsis::log() << ap.errmsg() << std::endl << ap.usagemsg();
			return( 1 );
		}

		// Check that the number of arguments to crop are valid if specified.
		if ( g_cl_cropWindow.size() > 0 && g_cl_cropWindow.size() != 4 )
		{
			Aqsis::log() << Aqsis::error << "Invalid number of arguments to -crop, expected 4, got " << g_cl_cropWindow.size() << std::endl;
			g_cl_help = true;
		}

		if ( g_cl_help )
		{
			std::cout << ap.usagemsg();
			return( 0 );
		}

		if ( g_cl_version )
		{
			std::cout << "aqsis version " << AQSIS_VERSION_STR_FULL
#			ifdef _DEBUG
			<< " (debug build)"
#			endif
			<< "\n"
			<< "compiled " << __DATE__ << " " << __TIME__ << "\n";
			return( 0 );
		}

#		ifdef	AQSIS_SYSTEM_WIN32
		std::auto_ptr<std::streambuf> ansi( new Aqsis::ansi_buf(Aqsis::log()) );
#		endif

		std::auto_ptr<std::streambuf> reset_level( new Aqsis::reset_level_buf(Aqsis::log()) );
		std::auto_ptr<std::streambuf> show_timestamps( new Aqsis::timestamp_buf(Aqsis::log()) );
		std::auto_ptr<std::streambuf> fold_duplicates( new Aqsis::fold_duplicates_buf(Aqsis::log()) );
		std::auto_ptr<std::streambuf> color_level;
		if(!g_cl_no_color)
		{
			std::auto_ptr<std::streambuf> temp_color_level( new Aqsis::color_level_buf(Aqsis::log()) );
			color_level = temp_color_level;
		}
		std::auto_ptr<std::streambuf> show_level( new Aqsis::show_level_buf(Aqsis::log()) );
		Aqsis::log_level_t level = Aqsis::ERROR;
		if( g_cl_verbose > 0 )
			level = Aqsis::WARNING;
		if( g_cl_verbose > 1 )
			level = Aqsis::INFO;
		if( g_cl_verbose > 2 )
			level = Aqsis::DEBUG;
		std::auto_ptr<std::streambuf> filter_level( new Aqsis::filter_by_level_buf(level, Aqsis::log()) );
#		ifdef AQSIS_SYSTEM_POSIX
		if( g_cl_syslog )
			std::auto_ptr<std::streambuf> use_syslog( new Aqsis::syslog_buf(Aqsis::log()) );
#		endif // AQSIS_SYSTEM_POSIX

		if (g_cl_priority != 1)
		{
			// Set the priority on the main thread
			setPriority(g_cl_priority);
		}

		RiBegin(RI_NULL);
		setupOptions();
		try
		{
			if ( ap.leftovers().size() == 0 )
			{
				// If no files specified, take input from stdin.
				//
				// TODO: We'd like to turn off stdio synchronisation to allow fast
				// buffering... unfortunately this causes very odd problems with
				// the aqsis logging facility as of svn r2804
				//
				//std::ios_base::sync_with_stdio(false);
				Aqsis::QGetRenderContextI()->parseRibStream(std::cin, "stdin");
			}
			else
			{
				for(ArgParse::apstringvec::const_iterator fileName = ap.leftovers().begin();
						fileName != ap.leftovers().end(); fileName++)
				{
					std::ifstream inFile(fileName->c_str());
					if(inFile)
					{
						Aqsis::QGetRenderContextI()->parseRibStream(inFile, *fileName);
						returnCode = RiLastError;
					}
					else
					{
						Aqsis::log() << Aqsis::error
							<< "Cannot open file \"" << *fileName << "\"\n";
						returnCode = RIE_NOFILE;
					}
				}
			}
		}
		catch(const std::exception& e)
		{
			Aqsis::log() << Aqsis::error << e.what() << std::endl;
			returnCode = RIE_BUG;
		}
		catch(...)
		{
			Aqsis::log() << Aqsis::error
				<< "unknown exception has been encountered\n";
			returnCode = RIE_BUG;
		}
		RiEnd();
	}

	StopMemoryDebugging();

	if(g_cl_beep)
		std::cout << "\a" << std::ends;

	if(g_cl_pause)
	{
		std::cout << "Press any key..." << std::ends;
		std::cin.ignore(std::cin.rdbuf()->in_avail() + 1);
	}

	return returnCode;
}
int main(int argc, const char** argv)
{
	ArgParse::apflag showhelp = false;
	ArgParse::apint myint = 0;

	ArgParse ap;
	ap.allowOneCharOptionsToBeCombined();
	ap.usageHeader(ArgParse::apstring("Usage: ") + argv[0] + " [options]");
	ap.argFlag("help", "\aprint this help, then exit", &showhelp);
	ap.argInt("integer", "=value\aa random integer you can give for no reason",
	          &myint);
	ap.alias("help", "h");
	ap.alias("integer", "i");
	if (!ap.parse(argc-1, argv+1))
	{
		Aqsis::log() << ap.errmsg() << std::endl << ap.usagemsg();
		return 1;
	}

	if (ap.leftovers().size() > 0)
	{
		Aqsis::log() << "Extra crud \"" << ap.leftovers()[0] << "\" on command line";
		Aqsis::log() << std::endl << ap.usagemsg();
		return 1;
	}

	if (myint != 0)
	{
		cout << "Your favorite integer is " << myint << endl;
	}

	if (showhelp)
	{
		cout << ap.usagemsg();
		return 0;
	}

	int bad = 0;

	cout << "Testing flags and integers... ";
	myint = 3;
	showhelp = false;
	int ok = 0;
	const char* av[100];

	if (ap.parse(0, av) && !showhelp && myint == 3 && ap.leftovers().size() == 0)
		ok++;

	av[0] = "-h";
	if (ap.parse(1, av) && showhelp && myint == 3 && ap.leftovers().size() == 0)
		ok++;

	showhelp = false;
	av[0] = "--help";
	if (ap.parse(1, av) && showhelp && myint == 3 && ap.leftovers().size() == 0)
		ok++;

	showhelp = false;
	av[0] = "--integer";
	av[1] = "5";
	if (ap.parse(2, av) && !showhelp && myint == 5 && ap.leftovers().size() == 0)
		ok++;

	myint = 3;
	av[0] = "-i";
	if (ap.parse(2, av) && !showhelp && myint == 5 && ap.leftovers().size() == 0)
		ok++;

	myint = 3;
	av[2] = "--help";
	if (ap.parse(3, av) && showhelp && myint == 5 && ap.leftovers().size() == 0)
		ok++;

	av[0] = "-h";
	av[1] = "-i";
	av[2] = "5";
	myint = 3;
	showhelp = false;
	if (ap.parse(3, av) && showhelp && myint == 5 && ap.leftovers().size() == 0)
		ok++;

	av[0] = "-hi";
	av[1] = "5";
	myint = 3;
	showhelp = false;
	if (ap.parse(2, av) && showhelp && myint == 5 && ap.leftovers().size() == 0)
		ok++;

	av[0] = "-hi=5";
	myint = 3;
	showhelp = false;
	if (ap.parse(1, av) && showhelp && myint == 5 && ap.leftovers().size() == 0)
		ok++;

	av[0] = "-help";
	if (!ap.parse(1, av) &&
	        ap.errmsg() == "-help: 'e' is an unrecognized option")
		ok++;

	av[0] = "--integer=5";
	myint = 3;
	showhelp = false;
	if (ap.parse(1, av) && !showhelp && myint == 5 && ap.leftovers().size() == 0)
		ok++;

	av[0] = "--integer:5";
	myint = 3;
	if (ap.parse(1, av) && !showhelp && myint == 5 && ap.leftovers().size() == 0)
		ok++;

	av[0] = "-ih";
	av[1] = "5";
	if (!ap.parse(2, av) &&
	        ap.errmsg() == "-ih: 'i' requires an argument")
		ok++;

	av[0] = "--help=5";
	if (!ap.parse(1, av) &&
	        ap.errmsg() == "--help=5: doesn't take an argument")
		ok++;

	av[0] = "--nohelp";
	showhelp = true;
	myint = 3;
	if (ap.parse(1, av) && !showhelp && myint == 3 && ap.leftovers().size() == 0)
		ok++;

	av[1] = "--help";
	if (!ap.parse(2, av) &&
	        ap.errmsg() == "--help: negated flag used with non-negated flag")
		ok++;

	if (ok == 16)
	{
		cout << "PASS" << endl;
	}
	else
	{
		cout << "FAIL" << endl;
		bad++;
	}

	ok = 0;
	cout << "Testing strings and floats... ";

	ArgParse::apfloat tex;
	ArgParse::apfloat metafont;
	ArgParse::apstring kpathsea;
	ArgParse t1;
	t1.argFloat("tex", "\aversion of TeX", &tex);
	t1.argFloat("metafont", "\aversion of Metafont", &metafont);
	t1.argString("kpathsea", "\aversion of Kpathsea", &kpathsea);

	av[0] = "-tex";
	av[1] = "3.14159";
	av[2] = "--metafont=2.7182";
	av[3] = "--kpathsea";
	av[4] = "3.3.1";
	if (t1.parse(5, av) && t1.leftovers().size() == 0 &&
	        tex == 3.14159 && metafont == 2.7182 && kpathsea == "3.3.1")
		ok++;

	av[1] = "blech";
	if (!t1.parse(5, av) &&
	        t1.errmsg() ==  "-tex: \"blech\" is not a valid floating-point number")
		ok++;

	if (ok == 2)
	{
		cout << "PASS" << endl;
	}
	else
	{
		cout << "FAIL" << endl;
		bad++;
	}

	ok = 0;
	cout << "Testing usage message... ";

	ArgParse::apflag junkf;
	ArgParse t2;
	t2.usageHeader("GNU `tar' saves blah, blah, blah\n\n"
	               "Main operation mode:", 26);
	t2.argFlag("t", "\alist the contents of an archive", &junkf);
	t2.argFlag("x", "\aextract files from an archive", &junkf);
	t2.argFlag("delete",
	           "\adelete from the archive (not on mag tapes!)", &junkf);
	t2.alias("t", "list");
	t2.alias("x", "extract");
	t2.alias("x", "get");
	t2.usageHeader("\nOperation modifiers:", 29);
	t2.argFlag("G", "\ahandle old GNU-format incremental backup", &junkf);
	t2.argFlag("g", "=FILE\ahandle new GNU-format incremental backup", &junkf);
	t2.alias("G", "incremental");
	t2.alias("g", "listed-incremental");
	t2.usageHeader("\nArchive format selection:", 37);
	t2.argFlag("V", "=NAME\acreate archive with volume name NAME\n      "
	           "        PATTERN\aat list/extract time, a globbing PATTERN",
	           &junkf);
	t2.alias("V", "label");
	t2.allowOneCharOptionsToBeCombined();
	if (t2.usagemsg() ==
	        "GNU `tar' saves blah, blah, blah\n"
	        "\n"
	        "Main operation mode:\n"
	        "  -t, --list              list the contents of an archive\n"
	        "  -x, --get, --extract    extract files from an archive\n"
	        "      --delete            delete from the archive (not on mag tapes!)\n"
	        "\n"
	        "Operation modifiers:\n"
	        "  -G, --incremental          handle old GNU-format incremental backup\n"
	        "  -g, --listed-incremental=FILE\n"
	        "                             handle new GNU-format incremental backup\n"
	        "\n"
	        "Archive format selection:\n"
	        "  -V, --label=NAME                   create archive with volume name NAME\n"
	        "              PATTERN                at list/extract time, a globbing PATTERN\n")
		ok++;

	if (ok == 1)
	{
		cout << "PASS" << endl;
	}
	else
	{
		cout << "FAIL" << endl;
		bad++;
	}

	ok = 0;
	cout << "Testing arrays... ";
	ArgParse::apintvec foo;
	ArgParse::apfloatvec bar;
	ArgParse::apstringvec baz;
	ArgParse t3;
	t3.argInts("foo", "", &foo);
	t3.argFloats("bar", "", &bar);
	t3.argStrings("baz", "", &baz);

	av[0] = "eins";
	av[1] = "-baz=one";
	av[2] = "-foo=1";
	av[3] = "zwei";
	av[4] = "drei";
	av[5] = "-baz";
	av[6] = "two";
	av[7] = "vier";
	av[8] = "-foo=2";
	av[9] = "-bar=1";
	av[10] = "-bar=2";
	av[11] = "-bar";
	av[12] = "3";
	av[13] = "-bar:4";
	av[14] = "-foo=3";
	av[15] = "--baz=three";
	av[16] = "-baz:four";
	av[17] = "-foo=4";
	if (t3.parse(18, av) && checkArrays(foo, bar, baz, t3.leftovers()))
		ok++;

	foo.clear();
	bar.clear();
	baz.clear();
	ArgParse t4;
	t4.argInts("foo", "", &foo, ArgParse::SEP_ARGV);
	t4.argFloats("bar", "", &bar, ArgParse::SEP_ARGV);
	t4.argStrings("baz", "", &baz, ArgParse::SEP_ARGV);
	av[0] = "eins";
	av[1] = "zwei";
	av[2] = "-baz=one";
	av[3] = "two";
	av[4] = "-foo";
	av[5] = "1";
	av[6] = "2";
	av[7] = "3";
	av[8] = "-baz=three";
	av[9] = "-bar=1";
	av[10] = "-bar=2";
	av[11] = "-bar";
	av[12] = "3";
	av[13] = "4";
	av[14] = "-foo=4";
	av[15] = "--baz";
	av[16] = "four";
	av[17] = "--";
	av[18] = "drei";
	av[19] = "vier";
	if (t4.parse(20, av) && checkArrays(foo, bar, baz, t4.leftovers()))
		ok++;

	foo.clear();
	bar.clear();
	baz.clear();
	ArgParse t5;
	t5.argInts("foo", "", &foo, ',');
	t5.argFloats("bar", "", &bar, ',');
	t5.argStrings("baz", "", &baz, ',');
	av[0] = "-foo";
	av[1] = "1,2";
	av[2] = "eins";
	av[3] = "-baz=one,two,three";
	av[4] = "zwei";
	av[5] = "-bar:1,2,3,4";
	av[6] = "--baz=four";
	av[7] = "drei";
	av[8] = "-foo";
	av[9] = "3,4";
	av[10] = "vier";
	if (t5.parse(11, av) && checkArrays(foo, bar, baz, t5.leftovers()))
		ok++;

	if (ok == 3)
	{
		cout << "PASS" << endl;
	}
	else
	{
		cout << "FAIL" << endl;
		bad++;
	}

	return bad;
}