/* * $Id$ * Copyright (C) 2011 gingko - http://gingko.homeip.net/ * * This file is part of Pouchin TV Mod, a free DVB-T viewer. * See http://www.pouchintv.fr/ for updates. * * Pouchin TV Mod 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. * * Pouchin TV Mod 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 Street, Fifth Floor, Boston, MA 02110-1301 USA */ // ==================================================================================== #include "stdafx.h" #include "cmdline.h" #include "shellapi.h" // ==================================================================================== bool CCmdLine::Next(tstring & strArg) { if (itArgs == itEnd) return false; strArg = *itArgs; return true; } tstring CCmdLine::Next() { if (itArgs != itEnd) return *itArgs++; return TEXT(""); } CCmdLine & CCmdLine::Load(int argc, LPSTR argv[]) { int nInx; if (argc > 0) strcpy_T(strCommand, argv[0]); for (nInx=1; nInx < argc; ++nInx) { vCmdArgs.push_back(tstring()); strcpy_T(*vCmdArgs.rbegin(), argv[nInx]); } return *this; } CCmdLine & CCmdLine::Load(int argc, LPWSTR argv[]) { int nInx; if (argc > 0) strcpy_T(strCommand, argv[0]); for (nInx=1; nInx < argc; ++nInx) { vCmdArgs.push_back(tstring()); strcpy_T(*vCmdArgs.rbegin(), argv[nInx]); } return *this; } CCmdLine & CCmdLine::Load(LPCWSTR pszCmdLine) { int argc; LPWSTR * argv = CommandLineToArgvW(pszCmdLine, &argc); if (argv) { Load(argc, argv); LocalFree(argv); } return *this; } CCmdLine & CCmdLine::Load(LPCSTR pszCmdLine) { wstring strCmdLine; strcpy_T(strCmdLine, pszCmdLine); return Load(strCmdLine.c_str()); } /** * \brief Traitement de tous les paramètres chargés * * Appel de la méthode virtuelle pure \p ProcessArg pour chaque paramètre, un par un. * Tient compte de la possibilité que cette fonction appelle \p Next en interne pour * acquérir des paramètres en tant qu'argument : dans ce cas, ces paramètres seront sautés. **/ bool CCmdLine::ProcessAll() { Reset(); while (itArgs != itEnd) { tstring & strArg = *itArgs++; if (!ProcessArg(strArg)) { bParamError = true; return false; } } PostProcess(); return true; } // ====================================================================================