File: commandline.cpp

package info (click to toggle)
stax 1.37-1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 1,768 kB
  • ctags: 809
  • sloc: cpp: 8,151; makefile: 30
file content (127 lines) | stat: -rw-r--r-- 3,910 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
 * Copyright 1999-2006 Trent Gamblin
 *
 * This file is part of Stax.
 *
 * Stax is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Stax is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Stax; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <iostream>
#include "stax.h"

void ProcessCommandLine(int argc, char** argv)
{
	high_score_filename = GetHighScoresFilename(argv[0]);
	ReadHighScores(high_score_filename);
	ReadConfiguration(argv[0]);

	for (int i = 1; i < argc; i++) {
		if (!stricmp(argv[i], "-windowed"))
			configuration.graphics_driver = GFX_AUTODETECT_WINDOWED;
		else if (!stricmp(argv[i], "-fullscreen"))
			configuration.graphics_driver = GFX_AUTODETECT_FULLSCREEN;
		else if (!stricmp(argv[i], "-sw")) {
			if (i+1 < argc) {
				i++;
				if (!isdigit(argv[i][0])) {
					std::cout << "Expected a number after -w." << std::endl;
					allegro_exit();
					exit(1);
				}
				configuration.screen_width = atoi(argv[i]);
			}
		}
		else if (!stricmp(argv[i], "-sh")) {
			if (i+1 < argc) {
				i++;
				if (!isdigit(argv[i][0])) {
					std::cout << "Expected a number after -h." << std::endl;
					allegro_exit();
					exit(1);
				}
				configuration.screen_height = atoi(argv[i]);
			}
		}
		else if (!stricmp(argv[i], "-bpp")) {
			if (i+1 < argc) {
				i++;
				if (!isdigit(argv[i][0])) {
					std::cout << "Expected a number after -bpp." << std::endl;
					allegro_exit();
					exit(1);
				}
				configuration.color_depth = atoi(argv[i]);
				if (!IsSupportedColorDepth(configuration.color_depth)) {
					std::cout << "Unsupported color depth." << std::endl;
					allegro_exit();
					exit(1);
				}
			}
		}
		else if (!stricmp(argv[i], "-blocks")) {
			if (i+1 < argc) {
				i++;
				if (!isdigit(argv[i][0])) {
					std::cout << "Expected a number after -blocks." << std::endl;
					allegro_exit();
					exit(1);
				}
				int blocks = atoi(argv[i]);
				if (blocks < 2 || blocks > NUMBER_OF_BLOCK_BITMAPS) {
					std::cout << "Number of block types must be from 2 to 5." << std::endl;
					allegro_exit();
					exit(1);
				}
				configuration.number_of_block_types = blocks;
			}
		}
		else if (!stricmp(argv[i], "-height")) {
			if (i+1 < argc) {
				i++;
				if (!isdigit(argv[i][0])) {
					std::cout << "Expected a number after -height." << std::endl;
					allegro_exit();
					exit(1);
				}
				configuration.initial_height = atoi(argv[i]);
				if (configuration.initial_height < 0) {
					std::cout << "Initial height must be 0 or greater." << std::endl;
					allegro_exit();
					exit(1);
				}
				else if (configuration.initial_height >= PANEL_HEIGHT) {
					std::cout << "Maximum initial height is " << PANEL_HEIGHT-1 << "." << std::endl;
					allegro_exit();
					exit(1);
				}
			}
		}
		else {
			std::cout << "Unrecognized command line option: " <<
				argv[i] << std::endl;
			std::cout << "Supported options are:" << std::endl;
			std::cout << "-windowed   -- Run in windowed mode" << std::endl;
			std::cout << "-fullscreen -- Run in fullscreen mode" << std::endl;
			std::cout << "-sw ###     -- Screen width" << std::endl;
			std::cout << "-sh ###     -- Screen height" << std::endl;
			std::cout << "-bpp ##     -- Color depth" << std::endl;
			std::cout << "-blocks #   -- Number of block types" << std::endl;
			std::cout << "-height ##  -- Initial height of blocks" << std::endl;
			allegro_exit();
			exit(1);
		}
	}
}