summaryrefslogtreecommitdiff
path: root/src/cmdargs.cpp
blob: 955ea3865eefd6dece253fa41376539fbc2d1ab4 (plain)
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/***************************************************************************
 *   Copyright (C) 2008-2013 by Andrzej Rybczak                            *
 *   electricityispower@gmail.com                                          *
 *                                                                         *
 *   This program 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.                                   *
 *                                                                         *
 *   This program 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 this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.              *
 ***************************************************************************/

#include <cassert>
#include <cstring>
#include <boost/algorithm/string/replace.hpp>
#include <iostream>

#include "actions.h"
#include "charset.h"
#include "cmdargs.h"
#include "config.h"
#include "mpdpp.h"
#include "settings.h"

#include "help.h"
#include "playlist.h"
#include "browser.h"
#include "search_engine.h"
#include "media_library.h"
#include "playlist_editor.h"
#include "tag_editor.h"
#include "outputs.h"
#include "visualizer.h"
#include "clock.h"

void ParseArgv(int argc, char **argv)
{
	std::string now_playing_format = "{{{(%l) }{{%a - }%t}}|{%f}}";
	for (int i = 1; i < argc; ++i)
	{
		if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--host"))
		{
			if (++i >= argc)
				exit(1);
			Mpd.SetHostname(argv[i]);
			continue;
		}
		if (!strcmp(argv[i], "-p") || !strcmp(argv[i], "--port"))
		{
			if (++i >= argc)
				exit(1);
			Mpd.SetPort(atoi(argv[i]));
			continue;
		}
		else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--version"))
		{
			std::cout << "ncmpcpp " << VERSION << "\n\n"
			<< "optional screens compiled-in:\n"
#			ifdef HAVE_TAGLIB_H
			<< " - tag editor\n"
			<< " - tiny tag editor\n"
#			endif
#			ifdef HAVE_CURL_CURL_H
			<< " - artist info\n"
#			endif
#			ifdef ENABLE_OUTPUTS
			<< " - outputs\n"
#			endif
#			ifdef ENABLE_VISUALIZER
			<< " - visualizer\n"
#			endif
#			ifdef ENABLE_CLOCK
			<< " - clock\n"
#			endif
			<< "\nencoding detection: "
#			ifdef HAVE_LANGINFO_H
			<< "enabled"
#			else
			<< "disabled"
#			endif // HAVE_LANGINFO_H
			<< "\nbuilt with support for:"
#			ifdef HAVE_CURL_CURL_H
			<< " curl"
#			endif
#			ifdef HAVE_FFTW3_H
			<< " fftw"
#			endif
#			ifdef USE_PDCURSES
			<< " pdcurses"
#			else
			<< " ncurses"
#			endif
#			ifdef HAVE_TAGLIB_H
			<< " taglib"
#			endif
#			ifdef NCMPCPP_UNICODE
			<< " unicode"
#			endif
			<< std::endl;
			exit(0);
		}
		else if (!strcmp(argv[i], "-?") || !strcmp(argv[i], "--help"))
		{
			std::cout
			<< "Usage: ncmpcpp [OPTION]...\n"
			<< "  -h, --host                connect to server at host [localhost]\n"
			<< "  -p, --port                connect to server at port [6600]\n"
			<< "  -c, --config              use alternative configuration file\n"
			<< "  -s, --screen <name>       specify the startup screen\n"
			<< "  -?, --help                show help message\n"
			<< "  -v, --version             display version information\n"
			;
			exit(0);
		}
		
		if (!strcmp(argv[i], "-s") || !strcmp(argv[i], "--screen"))
		{
			if (++i == argc) {
				std::cerr << "No screen specified" << std::endl;
				exit(1);
			}
			if (!strcmp(argv[i], "help"))
				Config.startup_screen = myHelp;
			else if (!strcmp(argv[i], "playlist"))
				Config.startup_screen = myPlaylist;
			else if (!strcmp(argv[i], "browser"))
				Config.startup_screen = myBrowser;
			else if (!strcmp(argv[i], "search-engine"))
				Config.startup_screen = mySearcher;
			else if (!strcmp(argv[i], "media-library"))
				Config.startup_screen = myLibrary;
			else if (!strcmp(argv[i], "playlist-editor"))
				Config.startup_screen = myPlaylistEditor;
#			ifdef HAVE_TAGLIB_H
			else if (!strcmp(argv[i], "tag-editor"))
				Config.startup_screen = myTagEditor;
#			endif // HAVE_TAGLIB_H
#			ifdef ENABLE_OUTPUTS
			else if (!strcmp(argv[i], "outputs"))
				Config.startup_screen = myOutputs;
#			endif // ENABLE_OUTPUTS
#			ifdef ENABLE_VISUALIZER
			else if (!strcmp(argv[i], "visualizer"))
				Config.startup_screen = myVisualizer;
#			endif // ENABLE_VISUALIZER
#			ifdef ENABLE_CLOCK
			else if (!strcmp(argv[i], "clock"))
				Config.startup_screen = myClock;
#			endif // ENABLE_CLOCK
			else {
				std::cerr << "Invalid screen: " << argv[i] << std::endl;
				exit(1);
			}
		}
		else if (!strcmp(argv[i], "-c") || !strcmp(argv[i], "--config"))
		{
			// this is used in Configuration::CheckForCommandLineConfigFilePath, ignoring here.
			++i;
		}
		else
		{
			std::cerr << "Invalid option: " << argv[i] << std::endl;
			exit(1);
		}
	}
}