00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <config.h>
00021 #include <iostream>
00022 #include <stdio.h>
00023 #include "settings.hxx"
00024 #include "command_line.hxx"
00025
00026 void
00027 CommandLine::error (const std::string& msg)
00028 {
00029 std::cout << "CommandLine parse failure!" << std::endl;
00030 std::cout << "CommandLine: " << msg << std::endl;
00031 exit(EXIT_FAILURE);
00032 }
00033
00034 void
00035 CommandLine::parse (int argc, char** argv)
00036 {
00037 for (int i = 1; i < argc; ++i)
00038 {
00039
00040
00041 if (argv[i][0] == '-')
00042 {
00043 if (strcmp(argv[i], "--fullscreen") == 0
00044 || strcmp(argv[i], "-f") == 0)
00045 {
00046 settings.fullscreen = true;
00047 }
00048 else if (strcmp(argv[i], "--version") == 0
00049 || strcmp(argv[i], "-v") == 0)
00050 {
00051 print_version ();
00052 exit (EXIT_SUCCESS);
00053 }
00054 else if (strcmp(argv[i], "--help") == 0
00055 || strcmp(argv[i], "-h") == 0)
00056 {
00057 print_help ();
00058 exit (EXIT_SUCCESS);
00059 }
00060 else if (strcmp(argv[i], "--disable-alphablending") == 0)
00061 {
00062 settings.alphablending = false;
00063 }
00064 else if (strcmp(argv[i], "--disable-antialiasing") == 0)
00065 {
00066 settings.antialiasing = false;
00067 }
00068 else if (strcmp(argv[i], "--disable-doublebuffer") == 0
00069 || strcmp(argv[i], "-d") == 0)
00070 {
00071 settings.doublebuffer = false;
00072 }
00073 else if (strcmp(argv[i], "-g") == 0
00074 || strcmp(argv[i], "--geometry") == 0)
00075 {
00076 if (++i < argc)
00077 {
00078 char c;
00079 if (sscanf(argv[i], "%d%c%d",
00080 &settings.screen_width, &c, &settings.screen_height) != 3 && c != 'x')
00081 {
00082 error ("geometry string must WIDTHxHEIGHT");
00083 }
00084 }
00085 else
00086 {
00087 error ("-g/--geometry is missing an argument");
00088 }
00089 }
00090 else
00091 {
00092 error (std::string("Unknown option: ") + argv[i]);
00093 }
00094 }
00095 else
00096 {
00097 if (!settings.startup_file.empty())
00098 {
00099 error ("Only one filename can be given");
00100 }
00101 else
00102 {
00103 settings.startup_file = argv[i];
00104 }
00105 }
00106 }
00107 }
00108
00109 void
00110 CommandLine::print_help ()
00111 {
00112 std::cout << "Construo "VERSION"\n\n"
00113 << "Usage: construo [OPTIONS] [FILENAME]\n\n"
00114 << " -h, --help display this help text\n"
00115 << " -v,--version Print version number of the programm\n"
00116 << " -f, --fullscreen switch to fullscreen mode if available\n"
00117 << " -d, --disable-doublebuffer disable the double buffer (might cause flicker)\n"
00118 << " -g, --geometry WIDTHxHEIGHT switch resolution to WIDTH and HEIGHT\n"
00119 << " --disable-antialiasing Switch into non antialiased mode\n"
00120 << " --disable-alphablending Switch into non alphablended mode\n"
00121 << std::endl;
00122 }
00123
00124 void
00125 CommandLine::print_version ()
00126 {
00127 std::cout << "Construo "VERSION"\n"
00128 << "Written by Ingo Ruhnke <grumbel@gmx.de>\n\n"
00129 << "Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de>\n"
00130 << "This is free software; see the source for copying conditions. There is NO\n"
00131 << "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE\n";
00132 }
00133
00134
00135