1 // $Id: command_line.cxx,v 1.8 2003/07/26 14:43:56 grumbel Exp $
3 // Construo - A wire-frame construction gamee
4 // Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include "settings.hxx"
26 #include "command_line.hxx"
29 CommandLine::error (const std::string
& msg
)
31 std::cout
<< "CommandLine parse failure!" << std::endl
;
32 std::cout
<< "CommandLine: " << msg
<< std::endl
;
37 CommandLine::parse (int argc
, char** argv
)
39 // FIXME: Replace this with getopt_long() or argp()
40 for (int i
= 1; i
< argc
; ++i
) // Skip Programm name
42 //std::cout << "Arg: " << argv[i] << std::endl;
44 if (argv
[i
][0] == '-') // Argument is an option
46 if (strcmp(argv
[i
], "--fullscreen") == 0
47 || strcmp(argv
[i
], "-f") == 0)
49 settings
.fullscreen
= true;
51 else if (strcmp(argv
[i
], "--version") == 0
52 || strcmp(argv
[i
], "-v") == 0)
57 else if (strcmp(argv
[i
], "--help") == 0
58 || strcmp(argv
[i
], "-h") == 0)
63 else if (strcmp(argv
[i
], "--disable-alphablending") == 0)
65 settings
.alphablending
= false;
67 else if (strcmp(argv
[i
], "--disable-antialiasing") == 0
68 || strcmp(argv
[i
], "-d") == 0)
70 settings
.antialiasing
= false;
72 else if (strcmp(argv
[i
], "--disable-thicklines") == 0
73 || strcmp(argv
[i
], "-l") == 0)
75 settings
.thick_lines
= false;
77 else if (strcmp(argv
[i
], "--disable-doublebuffer") == 0)
79 settings
.doublebuffer
= false;
81 else if (strcmp(argv
[i
], "--datadir") == 0)
83 settings
.datadir
= argv
[++i
];
85 else if (strcmp(argv
[i
], "-g") == 0
86 || strcmp(argv
[i
], "--geometry") == 0)
91 if (sscanf(argv
[i
], "%d%c%d",
92 &settings
.screen_width
, &c
, &settings
.screen_height
) != 3 && c
!= 'x')
94 error ("geometry string must WIDTHxHEIGHT");
99 error ("-g/--geometry is missing an argument");
104 error (std::string("Unknown option: ") + argv
[i
]);
109 if (!settings
.startup_file
.empty())
111 error ("Only one filename can be given");
115 settings
.startup_file
= argv
[i
];
122 CommandLine::print_help ()
124 std::cout
<< "Construo "VERSION
"\n\n"
125 << "Usage: construo [OPTIONS] [FILENAME]\n\n"
126 << " -h, --help display this help text\n"
127 << " -v,--version Print version number of the programm\n"
128 << " -f, --fullscreen switch to fullscreen mode if available\n"
129 << " -g, --geometry WIDTHxHEIGHT switch resolution to WIDTH and HEIGHT\n"
130 << " -d, --disable-antialiasing Switch into non antialiased mode\n"
131 << " -l, --disable-thicklines Disable thick (slow) line drawing\n"
132 << " --disable-doublebuffer disable the double buffer (might cause flicker)\n"
133 << " --disable-alphablending Switch into non alphablended mode\n"
134 << " --datadir DIR Set the datadir of Construo to DIR\n"
139 CommandLine::print_version ()
141 std::cout
<< "Construo "VERSION
"\n"
142 << "Written by Ingo Ruhnke <grumbel@gmx.de>\n\n"
143 << "Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de>\n"
144 << "This is free software; see the source for copying conditions. There is NO\n"
145 << "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE\n";