📄 ecosconfig.cxx
字号:
//####COPYRIGHTBEGIN####// // ----------------------------------------------------------------------------// Copyright (C) 2003 Bart Veer// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.//// This program is part of the eCos host tools.//// 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., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.//// ----------------------------------------------------------------------------// //####COPYRIGHTEND####//==========================================================================//// ecosconfig.cxx//// The implementation of ecosconfig command line processing////==========================================================================//==========================================================================//#####DESCRIPTIONBEGIN#### //// Author(s): jld// Date: 1999-11-08////####DESCRIPTIONEND####//==========================================================================#ifndef _MSC_VER#include <sys/param.h>#include <unistd.h> /* for realpath() */#endif#ifdef __CYGWIN__#include <windows.h>#include <sys/cygwin.h> /* for cygwin_conv_to_win32_path() */#endif#include "cdl_exec.hxx"#include "ecosconfig.hxx"#define TOOL_VERSION "2.0"#define TOOL_COPYRIGHT "Copyright (c) 2002 Red Hat, Inc."#define DEFAULT_SAVE_FILE "ecos.ecc"static char* tool = "ecosconfig";// When running under cygwin there may be confusion between cygwin and// Windows paths. Some paths will be passed on to the Tcl library,// which sometimes will accept a cygwin path and sometimes not. This// does not affect the VC++ build which only accepts Windows paths,// and obviously it does not affect any Unix platfom.#ifdef __CYGWIN__static std::stringtranslate_path(std::string& path){ std::string result; char buffer [MAXPATHLEN + 1]; if ("" == path) { result = path; } else { cygwin_conv_to_win32_path (path.c_str (), buffer); result = std::string(buffer); } return result;}# define TRANSLATE_PATH(a) translate_path(a)#else# define TRANSLATE_PATH(a) (a)#endifint main (int argc, char * argv []) { // process command qualifiers std::string repository; // --srcdir= std::string savefile; // --config= std::string install_prefix; // --prefix= bool version = false; // --version bool no_resolve = false; // --no-resolve bool quiet = false; // -q, --quiet bool verbose = false; // -v, --verbose bool ignore_errors = false; // -i, --ignore-errors bool no_updates = false; // -n, --no-updates, bool help = false; // --help bool enable_debug_set = false; // --enable-debug or --disable-debug int debug_level = 0; // --enable-debug=[0|1|2] Tcl_FindExecutable(argv[0]); // getopt() cannot easily be used here since this code has to // build with VC++ as well. bool args_ok = true; int command_index; for (command_index = 1; command_index < argc; command_index++) { // for each command line argument char* arg = argv[command_index]; if (0 == strcmp(arg, "--help")) { help = true; } else if ((0 == strcmp(arg, "-q")) || (0 == strcmp(arg, "--quiet"))) { // Allow repeated use of -q and -v to override each other. // This is useful in conjunction with shell aliases. quiet = true; verbose = false; } else if ((0 == strcmp(arg, "-v")) || (0 == strcmp(arg, "--verbose"))) { verbose = true; quiet = false; } else if ((0 == strcmp(arg, "-i")) || (0 == strcmp(arg, "--ignore-errors"))) { // Duplicate use of -i and the other flags is harmless. ignore_errors = true; } else if ((0 == strcmp(arg, "-n")) || (0 == strcmp(arg, "--no-updates"))) { no_updates = true; } else if (0 == strcmp(arg, "--version")) { version = true; } else if (0 == strcmp(arg, "--no-resolve")) { no_resolve = true; } else if (0 == strcmp(arg, "--enable-debug")) { enable_debug_set = true; debug_level = 1; } else if (0 == strcmp(arg, "--disable-debug")) { enable_debug_set = true; debug_level = 0; } else if (0 == strncmp(arg, "--srcdir", 8)) { // Duplicate use of --srcdir and other data-containing options should // be marked as an error. if ("" != repository) { fprintf(stderr, "%s: the `--srcdir' option should be used only once.\n", tool); args_ok = false; } else { if ('=' == arg[8]) { repository = std::string(arg + 9); if ("" == repository) { fprintf(stderr, "%s: missing component repository after `--srcdir='\n", tool); args_ok = false; } } else if ('\0' == arg[8]) { command_index++; if (command_index == argc) { fprintf(stderr, "%s: missing component repository after `--srcdir'\n", tool); args_ok = false; } else { repository = argv[command_index]; } } else { fprintf(stderr, "%s: invalid option `%s'\n", tool, arg); args_ok = false; } } } else if (0 == strncmp(arg, "--config", 8)) { if ("" != savefile) { fprintf(stderr, "%s: the `--config' option should be used only once.\n", tool); args_ok = false; } else { if ('=' == arg[8]) { savefile = std::string(arg + 9); if ("" == savefile) { fprintf(stderr, "%s: missing configuration savefile after `--config='\n", tool); args_ok = false; } } else if ('\0' == arg[8]) { command_index++; if (command_index == argc) { fprintf(stderr, "%s: missing configuration savefile after `--config'\n", tool); args_ok = false; } else { savefile = argv[command_index]; } } else { fprintf(stderr, "%s: invalid option `%s'\n", tool, arg); args_ok = false; } } } else if (0 == strncmp(arg, "--prefix", 8)) { if ("" != install_prefix) { fprintf(stderr, "%s: the `--prefix' option should be used only once.\n", tool); args_ok = false; } else { if ('=' == arg[8]) { install_prefix = std::string(arg + 9); if ("" == install_prefix) { fprintf(stderr, "%s: missing install prefix after `--prefix='\n", tool); args_ok = false; } } else if ('\0' == arg[8]) { command_index++; if (command_index == argc) { fprintf(stderr, "%s: missing install prefix after `--prefix'\n", tool); args_ok = false; } else { install_prefix = argv[command_index]; } } else { fprintf(stderr, "%s: invalid option `%s'\n", tool, arg); args_ok = false; } } } else { // The argument is not a qualifier // However, none of the sub-commands begin with a - if ('-' == arg[0]) { fprintf(stderr, "%s: unknown option `%s'\n", tool, arg); args_ok = false; } break; // end of qualifiers } }#if 0 printf("args_ok is %d\n", args_ok); printf("help is %d\n", help); printf("version is %d\n", version); printf("no_resolve is %d\n", no_resolve); printf("quiet is %d\n", quiet); printf("verbose is %d\n", verbose); printf("no-updates is %d\n", no_updates); printf("ignore_errors is %d\n", ignore_errors); printf("repository is %s\n", repository.c_str()); printf("savefile is %s\n", savefile.c_str()); printf("install_prefix is %s\n", install_prefix.c_str()); exit(EXIT_SUCCESS);#endif // Usually argv[command_index] will be a sub-command, unless // --help or --version has been used. // Always output the version number, irrespective of subsequent // commands or any problems. This can be useful in batch jobs.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -