diff options
author | Michele Calgaro <[email protected]> | 2020-09-11 14:38:47 +0900 |
---|---|---|
committer | Michele Calgaro <[email protected]> | 2020-09-11 14:38:47 +0900 |
commit | 884c8093d63402a1ad0b502244b791e3c6782be3 (patch) | |
tree | a600d4ab0d431a2bdfe4c15b70df43c14fbd8dd0 /debian/fireflies/fireflies-2.08/libgfx/tests/t-script.cxx | |
parent | 14e1aa2006796f147f3f4811fb908a6b01e79253 (diff) | |
download | extra-dependencies-884c8093d63402a1ad0b502244b791e3c6782be3.tar.gz extra-dependencies-884c8093d63402a1ad0b502244b791e3c6782be3.zip |
Added debian extra dependency packages.
Signed-off-by: Michele Calgaro <[email protected]>
Diffstat (limited to 'debian/fireflies/fireflies-2.08/libgfx/tests/t-script.cxx')
-rw-r--r-- | debian/fireflies/fireflies-2.08/libgfx/tests/t-script.cxx | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/debian/fireflies/fireflies-2.08/libgfx/tests/t-script.cxx b/debian/fireflies/fireflies-2.08/libgfx/tests/t-script.cxx new file mode 100644 index 00000000..42b9ad83 --- /dev/null +++ b/debian/fireflies/fireflies-2.08/libgfx/tests/t-script.cxx @@ -0,0 +1,74 @@ +/************************************************************************ + + Test the libgfx scripting facility. + + by Michael Garland, 2000. + + $Id: t-script.cxx 426 2004-09-27 04:34:55Z garland $ + + ************************************************************************/ + +#include <gfx/gfx.h> +#include <gfx/script.h> +#include <gfx/vec3.h> + +using namespace std; + +// usage: add <x>* +// Adds all numbers listed on the line and prints the result +// +// usage: avg <x>* +// Averages all numbers listed on the line and prints the result +// +int proc_add(const CmdLine &cmd) +{ + std::vector<double> values; + double sum = 0.0; + + cmd.collect_as_numbers(values); + std::vector<double>::size_type count; + for(count=0; count<values.size(); count++) + sum += values[count]; + + if( cmd.opname() == "avg" && count>0 ) + sum /= (double)count; + + cout << sum << endl; + return SCRIPT_OK; +} + +// usage: vec3 <x> <y> <z> +// Constructs a 3-vector and prints the result +int proc_vec3(const CmdLine &cmd) +{ + if( cmd.argcount() != 3 ) return SCRIPT_ERR_SYNTAX; + + Vec3 v; + cmd.collect_as_numbers(v, 3); + + cout << v << endl; + return SCRIPT_OK; +} + +// usage: echo <msg> +// Prints all the text following the command name verbatim +int proc_echo(const CmdLine &cmd) +{ + cout << cmd.argline() << endl; + return SCRIPT_OK; +} + +int main(int argc, char *argv[]) +{ + CmdEnv env; + + env.register_command("add", proc_add); + env.register_command("avg", proc_add); + env.register_command("echo", proc_echo); + env.register_command("vec3", proc_vec3); + + for(int i=1; i<argc; i++) + env.do_file(argv[i]); + + return 0; +} |