📄 component.cpp
字号:
/* * TOPPERS/JSP Kernel * Toyohashi Open Platform for Embedded Real-Time Systems/ * Just Standard Profile Kernel * * Copyright (C) 2000-2002 by Embedded and Real-Time Systems Laboratory * Toyohashi Univ. of Technology, JAPAN * * 惧淡螟侯涪荚は·Free Software Foundation によって给山されている * GNU General Public License の Version 2 に淡揭されている掘凤か·笆 * 布の(1)×(4)の掘凤を塔たす眷圭に嘎り·塑ソフトウェア∈塑ソフトウェ * アを猖恃したものを崔むˉ笆布票じ∷を蝗脱ˇ剩澜ˇ猖恃ˇ浩芹邵∈笆布· * 网脱と钙ぶ∷することを痰浸で钓满するˉ * (1) 塑ソフトウェアをソ〖スコ〖ドの妨で网脱する眷圭には·惧淡の螟侯 * 涪山绩·この网脱掘凤および布淡の痰瘦沮惮年が·そのままの妨でソ〖 * スコ〖ド面に崔まれていることˉ * (2) 塑ソフトウェアを浩网脱材墙なバイナリコ〖ド∈リロケ〖タブルオブ * ジェクトファイルやライブラリなど∷の妨で网脱する眷圭には·网脱 * に燃うドキュメント∈网脱荚マニュアルなど∷に·惧淡の螟侯涪山绩· * この网脱掘凤および布淡の痰瘦沮惮年を非很することˉ * (3) 塑ソフトウェアを浩网脱稍材墙なバイナリコ〖ドの妨または怠达に寥 * み哈んだ妨で网脱する眷圭には·肌のいずれかの掘凤を塔たすことˉ * (a) 网脱に燃うドキュメント∈网脱荚マニュアルなど∷に·惧淡の螟侯 * 涪山绩·この网脱掘凤および布淡の痰瘦沮惮年を非很することˉ * (b) 网脱の妨轮を·侍に年める数恕によって·惧淡螟侯涪荚に鼠桂する * ことˉ * (4) 塑ソフトウェアの网脱により木儡弄または粗儡弄に栏じるいかなる禄 * 巢からも·惧淡螟侯涪荚を倘勒することˉ * * 塑ソフトウェアは·痰瘦沮で捏丁されているものであるˉ惧淡螟侯涪荚は· * 塑ソフトウェアに簇して·その努脱材墙拉も崔めて·いかなる瘦沮も乖わ * ないˉまた·塑ソフトウェアの网脱により木儡弄または粗儡弄に栏じたい * かなる禄巢に簇しても·その勒扦を砷わないˉ * * @(#) $Id: component.cpp,v 1.4 2002/04/11 07:26:37 takayuki Exp $ */// $Header: /home/CVS/configurator/component.cpp,v 1.4 2002/04/11 07:26:37 takayuki Exp $#include "component.h"#include <iostream>#include <algorithm>#include <fstream>using namespace std;list<Component *> Component::componentList;list<Component *> Component::activatedComponentList;int Component::barrierFlag = 0;Component::~Component(void){ list<Component *>::iterator scope; scope = componentList.begin(); while(scope != componentList.end()) { if(*scope == this) { componentList.erase(scope); break; } scope ++; }}void Component::activateComponent(bool allow_multiinstance){ if(allow_multiinstance || (find(activatedComponentList.begin(),activatedComponentList.end(), this) == activatedComponentList.end())) activatedComponentList.push_back(this); }Directory * Component::getOption(Directory & container, const char * id, const char * longId){ Directory * param; Directory * scope; string identifier; param = container.findChild("Parameter"); if( ((id != 0) && ((scope = param->findChild(id)) != 0)) || ((longId != 0) && ((scope = param->findChild(string("-") + longId)) != 0)) ) { return scope; } return NULL;}Directory * Component::mergeOption(Directory & container, const char * to, const char * from){ Directory * src; Directory * dest; Directory * node; src = container.findChild("Parameter",to,NULL); dest = container.findChild(string("Parameter/") + from); if(dest == 0) return src; if(src == 0) src = container.openChild("Parameter",to,NULL); node = dest->getFirstChild(); while(node != 0) { src->addChild(new Directory(node->toString())); node = node->getNext(); } dest->erase(); return src;} static void addOptionItem(Directory * parameter, const string & key, const string & item){ Directory * node; char buffer[32]; node = parameter->findChild(key); if(item.empty()) { if(node == 0) parameter->addChild(key, new Directory("")); else *node = ""; }else { if(node != 0) { sprintf(buffer,"%03d", node->size()); node->addChild(buffer, item.empty() ? new Directory("") : new Directory(item)); *node = item; }else parameter->addChild(key, new Directory(item))->addChild("000", new Directory(item)); }}void Component::parseOption(int argc, char ** argv, Directory & container){ list<Component *>::iterator scope; Directory * parameter; string work; string prevparam; string::size_type i,j; try{ parameter = container.addChild("Parameter"); for(i=1;*(argv+i)!=0;i++) { work += *(argv+i); work += ' '; } (*parameter)["#cmdline"] = work.substr(0,work.size()-1); //パラメ〖タをパ〖スする prevparam = DEFAULT_PARAMETER; while(*(++argv) != 0) { work.assign(*argv); if(work[0] == '-') { i = work.find_first_of('='); j = work.find_first_not_of('-'); if(i == j || j == string::npos) Exception(Exception::FATAL,"Wrong option [%s]","稍赖なオプション [%s]").format(work.c_str()); if(i != string::npos) { prevparam = DEFAULT_PARAMETER; addOptionItem(parameter, work.substr(1, i-1), work.substr(i+1)); } else { prevparam = work.substr(1); addOptionItem(parameter, prevparam, string("")); } }else addOptionItem(parameter, prevparam, work); } if(argc == 1) parameter->addChild("h"); { //グロ〖バルなオプションを借妄する //デバッグ借妄 if(findOption(container, "debug","debug")) { cout << "\n[debug-info] : Parameter" << endl; container.findChild("Parameter")->drawTree(&cout); } //咐胳废はエラ〖メッセ〖ジに逼读するので办戎呵介に借妄する if(findOption(container,"lj","japanese")) Message::selectCodepage(0x441); if(findOption(container,"le","english")) Message::selectCodepage(0); if(findOption(container, "debug","debug")) container.addChild("Debug"); if(findOption(container,"h","help")) cout << '\n' << Message( "Global option\n" " -lj, --japanese : Use Japanese as display language\n" " -le, --english : Use English as display language(default)\n" " -v, --verbose : Display verbose messages\n" " -ext, --extension : Enable extensions\n" " -no-ext, --no-extension : Restrict use of extensions (Override -ext)\n", "链挛のオプション\n" " -lj, --japanese : 泣塑胳で山绩します\n" " -le, --english : 毖胳で山绩します\n" " -v, --verbose : 庞面沸册などを山绩します\n" " -ext, --extension : 橙磨怠墙を铜跟にします\n" " -no-ext, --no-extension : 橙磨怠墙を痰跟にします\n"); if(findOption(container,"ext","extension")) enable(EXTENSION); if(findOption(container,"no-ext","no-extension")) disable(EXTENSION); if(findOption(container,"v","verbose")) VerboseMessage::setVerbose(true); } //コンポ〖ネントによるパラメ〖タ借妄 scope = componentList.begin(); while(scope != componentList.end()) {// VerboseMessage("Option parsing [%s]\n","オプション豺老 [%s]\n").format((*scope)->getIdentifier()); (*scope)->parseOption(container); scope++; } } catch(Exception * e) { Exception(Exception::FATAL, "Fatal error occured during command line parsing.\n %s","コマンドラインオプションの豺老面に米炭弄なエラ〖が斧つかりました\n %s").format((const char *)*e); }}void Component::dumpContainerSnapshot(Directory & container, bool forcedly){ string dump; if(forcedly || findOption(container, "D", "dump", &dump) || findOption(container,"debug","debug")) { if(dump.empty()) dump.assign("container.txt"); fstream f(dump.c_str(), ios::out); if(f.is_open()) { f << "Last configuration was finished successfully\n\n"; container.drawTree(&f); f.close(); } }}void Component::executeComponents(Directory & container){ Component * cmp; while(!activatedComponentList.empty()) { cmp = *activatedComponentList.begin(); activatedComponentList.pop_front(); try{ cmp->body(container); } catch(Exception * e) { dumpContainerSnapshot(container); if(e->isFatal()) throw e; cerr << *e << Message("(continue...)","(鲁乖します...)") << endl; } } dumpContainerSnapshot(container);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -