Subversion Repositories spk

Rev

Rev 341 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 341 Rev 344
Line 38... Line 38...
38
			_file = std::make_shared<CFileIO>(argv[0]);
38
			_file = std::make_shared<CFileIO>(argv[0]);
39
 
39
 
40
			for (int i = 1; i < argc; i++)
40
			for (int i = 1; i < argc; i++)
41
			{
41
			{
42
				Utils::WString arg(argv[i]);
42
				Utils::WString arg(argv[i]);
43
				if (arg.startsWith(L"--"))
-
 
44
				{
-
 
45
					arg = arg.substr(2);
-
 
46
 
-
 
47
					if (arg.contains(L":"))
-
 
48
					{
-
 
49
						Utils::WString a = arg.token(L":", 1);
-
 
50
						Utils::WString b = arg.tokens(L":", 2);
-
 
51
						_options.pushBack(a, b);
-
 
52
					}
-
 
53
					else
-
 
54
						_options.pushBack(arg);
-
 
55
				}
-
 
56
				else
-
 
57
				{
-
 
58
					if (doFlags)
-
 
59
					{
-
 
60
						if (arg.startsWith(L"-") && !arg.startsWith(L"--"))
-
 
61
						{
-
 
62
							Utils::WString flags = arg.substr(1);
-
 
63
							for(size_t is = 0; is < flags.length(); is++)
-
 
64
							{
-
 
65
								unsigned char flag = std::toupper(flags[is]);
-
 
66
								if (flag >= 'a' && flag <= 'z')
-
 
67
									flag -= 32; // convert to uppercase
-
 
68
								if (flag >= 'A' && flag <= 'Z')
-
 
69
								{
-
 
70
									if (_flags.size() < 256)
-
 
71
										_flags.insert(flag);
43
				doCommandLine(arg, doFlags);
72
									else
-
 
73
										wprintf(L"Warning: Too many flags, ignoring %c\n", flag);
-
 
74
								}
-
 
75
							}
-
 
76
							continue;
-
 
77
						}
-
 
78
					}
-
 
79
					_args.push_back(arg);
-
 
80
				}
-
 
81
			}
44
			}
82
 
45
 
83
			if (_file->dir().empty() || !_file->dir().contains("/"))
46
			finaliseCommandLine();
84
			{
47
		}
85
				Utils::WString d;
-
 
86
#ifdef _WIN32
-
 
87
				d = Utils::WString(_getcwd(NULL, 0));
48
		CommandLine(int argc, wchar_t* argv[], bool doFlags = false)
88
#else
49
		{
89
				d = Utils::WString(getcwd(NULL, 0));
50
			_file = std::make_shared<CFileIO>(argv[0]);
90
#endif
-
 
91
				if (d.empty())
-
 
92
					d = L"./";
-
 
93
				_file->setDir(d);
-
 
94
			}
-
 
95
 
51
 
96
			Utils::WString myDoc = L".";
52
			for (int i = 1; i < argc; i++)
97
#ifdef _WIN32
-
 
98
			TCHAR pszPath[MAX_PATH];
-
 
99
			if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, pszPath)))
-
 
100
			{
53
			{
-
 
54
				Utils::WString arg(argv[i]);
101
				myDoc = pszPath;
55
				doCommandLine(arg, doFlags);
102
			}
56
			}
103
#endif
-
 
104
			_myDoc.setDir(myDoc);
-
 
105
			_tempDir.setDir(L".");
-
 
106
 
57
 
107
#ifdef _WIN32
-
 
108
			TCHAR szPath[MAX_PATH + 1];
-
 
109
			DWORD result = GetTempPath(MAX_PATH + 1, szPath);
-
 
110
			if (result > 0)
-
 
111
				_tempDir.setDir(szPath);
58
			finaliseCommandLine();
112
#endif
-
 
113
 
-
 
114
			_p.startup(L".", _tempDir.dir(), _myDoc.dir());
-
 
115
		}
59
		}
116
 
60
 
117
		const std::shared_ptr<CFileIO> file() const
61
		const std::shared_ptr<CFileIO> file() const
118
		{
62
		{
119
			return _file;
63
			return _file;
Line 194... Line 138...
194
 
138
 
195
		Utils::WString fullFilename(const Utils::WString& s) const
139
		Utils::WString fullFilename(const Utils::WString& s) const
196
		{
140
		{
197
			return (s.contains(L":")) ? s : _file->dirIO().file(s);
141
			return (s.contains(L":")) ? s : _file->dirIO().file(s);
198
		}
142
		}
-
 
143
 
-
 
144
	private:
-
 
145
		void doCommandLine(Utils::WString& arg, bool doFlags)
-
 
146
		{
-
 
147
			if (arg.startsWith(L"--"))
-
 
148
			{
-
 
149
				arg = arg.substr(2);
-
 
150
 
-
 
151
				if (arg.contains(L":"))
-
 
152
				{
-
 
153
					Utils::WString a = arg.token(L":", 1);
-
 
154
					Utils::WString b = arg.tokens(L":", 2);
-
 
155
					_options.pushBack(a, b);
-
 
156
				}
-
 
157
				else
-
 
158
					_options.pushBack(arg);
-
 
159
			}
-
 
160
			else
-
 
161
			{
-
 
162
				if (doFlags)
-
 
163
				{
-
 
164
					if (arg.startsWith(L"-") && !arg.startsWith(L"--"))
-
 
165
					{
-
 
166
						Utils::WString flags = arg.substr(1);
-
 
167
						for (size_t is = 0; is < flags.length(); is++)
-
 
168
						{
-
 
169
							unsigned char flag = std::toupper(flags[static_cast<int>(is)]);
-
 
170
							if (flag >= 'a' && flag <= 'z')
-
 
171
								flag -= 32; // convert to uppercase
-
 
172
							if (flag >= 'A' && flag <= 'Z')
-
 
173
							{
-
 
174
								if (_flags.size() < 256)
-
 
175
									_flags.insert(flag);
-
 
176
								else
-
 
177
									wprintf(L"Warning: Too many flags, ignoring %c\n", flag);
-
 
178
							}
-
 
179
						}
-
 
180
						return;
-
 
181
					}
-
 
182
				}
-
 
183
				_args.push_back(arg);
-
 
184
			}
-
 
185
		}
-
 
186
 
-
 
187
		void finaliseCommandLine()
-
 
188
		{
-
 
189
			if (_file->dir().empty() || !_file->dir().contains("/"))
-
 
190
			{
-
 
191
				Utils::WString d;
-
 
192
#ifdef _WIN32
-
 
193
				d = Utils::WString(_getcwd(NULL, 0));
-
 
194
#else
-
 
195
				d = Utils::WString(getcwd(NULL, 0));
-
 
196
#endif
-
 
197
				if (d.empty())
-
 
198
					d = L"./";
-
 
199
				_file->setDir(d);
-
 
200
			}
-
 
201
 
-
 
202
			Utils::WString myDoc = L".";
-
 
203
#ifdef _WIN32
-
 
204
			TCHAR pszPath[MAX_PATH];
-
 
205
			if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, pszPath)))
-
 
206
			{
-
 
207
				myDoc = pszPath;
-
 
208
			}
-
 
209
#endif
-
 
210
			_myDoc.setDir(myDoc);
-
 
211
			_tempDir.setDir(L".");
-
 
212
 
-
 
213
#ifdef _WIN32
-
 
214
			TCHAR szPath[MAX_PATH + 1];
-
 
215
			DWORD result = GetTempPath(MAX_PATH + 1, szPath);
-
 
216
			if (result > 0)
-
 
217
				_tempDir.setDir(szPath);
-
 
218
#endif
-
 
219
 
-
 
220
			_p.startup(L".", _tempDir.dir(), _myDoc.dir());
-
 
221
		}
199
	};
222
	};
200
}
223
}
201
224