📄 ecosconfig.cxx
字号:
//####COPYRIGHTBEGIN####// // ----------------------------------------------------------------------------// Copyright (C) 1998, 1999, 2000 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 "1.3.net"#define TOOL_COPYRIGHT "Copyright (c) 2000 Red Hat, Inc."#define DEFAULT_SAVE_FILE "ecos.ecc"static char* tool = "ecosconfig";int 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 help = false; // --help // 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, "--version")) { version = true; } else if (0 == strcmp(arg, "--no-resolve")) { no_resolve = true; } 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("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. if (version) { printf ("ecosconfig %s (%s %s)\n%s\n", TOOL_VERSION, __DATE__, __TIME__, TOOL_COPYRIGHT); if (command_index == argc) { return EXIT_SUCCESS; } } // Cope with --help and any user errors. If --help is used then // subsequent arguments should be ignored, as should any problems // with the arguments. This allows the user to type a partial // command, then switch to --help, and use shell history editing // to complete/correct the command. if (help || !args_ok || (command_index == argc)) { usage_message(); return help ? EXIT_SUCCESS : EXIT_FAILURE; } // set the default save file if (savefile.empty ()) { // if the save file was not specified on the command line
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -