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.
23 #include "settings.hxx"
24 #include "command_line.hxx"
27 CommandLine::error (const std::string
& msg
)
29 std::cout
<< "CommandLine parse failure!" << std::endl
;
30 std::cout
<< "CommandLine: " << msg
<< std::endl
;
35 CommandLine::parse (int argc
, char** argv
)
37 // FIXME: Replace this with getopt_long() or argp()
38 for (int i
= 1; i
< argc
; ++i
) // Skip Programm name
40 //std::cout << "Arg: " << argv[i] << std::endl;
42 if (argv
[i
][0] == '-') // Argument is an option
44 if (strcmp(argv
[i
], "--fullscreen") == 0
45 || strcmp(argv
[i
], "-f") == 0)
47 settings
.fullscreen
= true;
49 else if (strcmp(argv
[i
], "--version") == 0
50 || strcmp(argv
[i
], "-v") == 0)
55 else if (strcmp(argv
[i
], "--help") == 0
56 || strcmp(argv
[i
], "-h") == 0)
61 else if (strcmp(argv
[i
], "--disable-alphablending") == 0)
63 settings
.alphablending
= false;
65 else if (strcmp(argv
[i
], "--disable-antialiasing") == 0
66 || strcmp(argv
[i
], "-d") == 0)
68 settings
.antialiasing
= false;
70 else if (strcmp(argv
[i
], "--disable-thicklines") == 0
71 || strcmp(argv
[i
], "-l") == 0)
73 settings
.thick_lines
= false;
75 else if (strcmp(argv
[i
], "--disable-doublebuffer") == 0)
77 settings
.doublebuffer
= false;
79 else if (strcmp(argv
[i
], "--datadir") == 0)
81 settings
.datadir
= argv
[++i
];
83 else if (strcmp(argv
[i
], "-g") == 0
84 || strcmp(argv
[i
], "--geometry") == 0)
89 if (sscanf(argv
[i
], "%d%c%d",
90 &settings
.screen_width
, &c
, &settings
.screen_height
) != 3 && c
!= 'x')
92 error ("geometry string must WIDTHxHEIGHT");
97 error ("-g/--geometry is missing an argument");
102 error (std::string("Unknown option: ") + argv
[i
]);
107 if (!settings
.startup_file
.empty())
109 error ("Only one filename can be given");
113 settings
.startup_file
= argv
[i
];
120 CommandLine::print_help ()
122 std::cout
<< "Construo "VERSION
"\n\n"
123 << "Usage: construo [OPTIONS] [FILENAME]\n\n"
124 << " -h, --help display this help text\n"
125 << " -v,--version Print version number of the programm\n"
126 << " -f, --fullscreen switch to fullscreen mode if available\n"
127 << " -g, --geometry WIDTHxHEIGHT switch resolution to WIDTH and HEIGHT\n"
128 << " -d, --disable-antialiasing Switch into non antialiased mode\n"
129 << " -l, --disable-thicklines Disable thick (slow) line drawing\n"
130 << " --disable-doublebuffer disable the double buffer (might cause flicker)\n"
131 << " --disable-alphablending Switch into non alphablended mode\n"
132 << " --datadir DIR Set the datadir of Construo to DIR\n"
137 CommandLine::print_version ()
139 std::cout
<< "Construo "VERSION
"\n"
140 << "Written by Ingo Ruhnke <grumbel@gmx.de>\n\n"
141 << "Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de>\n"
142 << "This is free software; see the source for copying conditions. There is NO\n"
143 << "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE\n";