[206] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
[467] | 3 | #include <shlwapi.h>
|
---|
| 4 |
|
---|
[168] | 5 | #include <jenga/include/common/Environment.h>
|
---|
| 6 |
|
---|
| 7 | #include <Program.h>
|
---|
| 8 |
|
---|
[206] | 9 | Jenga::Common::Logger Program::logger( Jenga::Common::Environment::GetAppDir() + "\\logger.log", true );
|
---|
[467] | 10 |
|
---|
| 11 | Program program;
|
---|
| 12 |
|
---|
| 13 | bool Program::AnalysisCommandLines()
|
---|
| 14 | {
|
---|
| 15 | // コマンドラインを解析
|
---|
| 16 | const Jenga::Common::CmdLines cmdLines( PathGetArgs( GetCommandLine() ) );
|
---|
| 17 | int cmdLineIndex = 0;
|
---|
| 18 |
|
---|
| 19 | if( cmdLines.size() == 0 )
|
---|
| 20 | {
|
---|
| 21 | // 何も指定されていないとき
|
---|
| 22 | return true;
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | if( cmdLines[cmdLineIndex].IsNamelessCommand() )
|
---|
| 26 | {
|
---|
| 27 | // 先頭に無名コマンドがきた場合、ソースファイル名として認識する
|
---|
[472] | 28 | std::string tempParam = cmdLines[cmdLineIndex].GetParameter();
|
---|
| 29 | Program::SetSourceFilePath( Jenga::Common::StringReplace( tempParam, "/", "\\" ) );
|
---|
[467] | 30 |
|
---|
| 31 | cmdLineIndex ++;
|
---|
| 32 |
|
---|
| 33 | if( cmdLines.size() == 1 )
|
---|
| 34 | {
|
---|
| 35 | // ソースファイル名のみの指定だったとき
|
---|
| 36 | return true;
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | // 出力ファイル名を取得
|
---|
| 40 | if( cmdLines[cmdLineIndex].IsNamelessCommand() )
|
---|
| 41 | {
|
---|
| 42 | // 二番目にも無名コマンドがきた場合、ソースファイル名として認識する
|
---|
[472] | 43 | std::string tempParam = cmdLines[cmdLineIndex].GetParameter();
|
---|
| 44 | SetOutputFilePath( Jenga::Common::StringReplace( tempParam, "/", "\\" ) );
|
---|
[467] | 45 |
|
---|
| 46 | cmdLineIndex ++;
|
---|
| 47 | }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | for( ; cmdLineIndex < static_cast<int>(cmdLines.size()); cmdLineIndex++ )
|
---|
| 51 | {
|
---|
| 52 | const Jenga::Common::CmdLine &cmdLine = cmdLines[cmdLineIndex];
|
---|
| 53 |
|
---|
| 54 | if( cmdLine.GetCommand() == "wnd" )
|
---|
| 55 | {
|
---|
| 56 | // 親エディタのウィンドウ ハンドル
|
---|
| 57 | isKickedFromEditor = true;
|
---|
| 58 | sscanf( cmdLine.GetParameter().c_str(), "%08x", &hOwnerEditor );
|
---|
| 59 | }
|
---|
[471] | 60 | else if( cmdLine.GetCommand() == "show_dlg" )
|
---|
| 61 | {
|
---|
| 62 | isShowDlg = true;
|
---|
| 63 | }
|
---|
[467] | 64 | else if( cmdLine.GetCommand() == "debug" )
|
---|
| 65 | {
|
---|
| 66 | // デバッグ ビルド
|
---|
| 67 | compiler.SetDebugMark( true );
|
---|
| 68 | }
|
---|
| 69 | else if( cmdLine.GetCommand() == "run" )
|
---|
| 70 | {
|
---|
| 71 | // デバッグ実行
|
---|
| 72 | isDebugRun = true;
|
---|
| 73 | }
|
---|
| 74 | else if( cmdLine.GetCommand() == "attach" )
|
---|
| 75 | {
|
---|
| 76 | // アタッチ
|
---|
| 77 | isDebugRun = true;
|
---|
| 78 | isAttach = true;
|
---|
| 79 | sscanf( cmdLine.GetParameter().c_str(), "%08x", &attachProcessId );
|
---|
| 80 | }
|
---|
| 81 | else if( cmdLine.GetCommand() == "dll" )
|
---|
| 82 | {
|
---|
| 83 | // DLLとしてビルド
|
---|
| 84 | compiler.SetTargetModuleType( Compiler::Dll );
|
---|
| 85 | }
|
---|
| 86 | else if( cmdLine.GetCommand() == "static_library" )
|
---|
| 87 | {
|
---|
| 88 | // 静的リンクライブラリとしてビルド
|
---|
| 89 | compiler.SetTargetModuleType( Compiler::StaticLibrary );
|
---|
| 90 | }
|
---|
| 91 | else if( cmdLine.GetCommand() == "unicode" )
|
---|
| 92 | {
|
---|
| 93 | // Unicode
|
---|
| 94 | compiler.SetUnicodeMark( true );
|
---|
| 95 | typeOfPtrChar = MAKE_PTR_TYPE(DEF_WORD,1);
|
---|
| 96 | typeOfPtrUChar = MAKE_PTR_TYPE(DEF_WORD,1);
|
---|
| 97 | }
|
---|
| 98 | else if( cmdLine.GetCommand() == "clip_compile_view" )
|
---|
| 99 | {
|
---|
| 100 | //埋め込み型コンパイラビュー
|
---|
| 101 | isClipCompileView = true;
|
---|
| 102 | }
|
---|
| 103 | else if( cmdLine.GetCommand() == "include_dir" )
|
---|
| 104 | {
|
---|
| 105 | //インクルード ディレクトリ
|
---|
[472] | 106 | includeDir = cmdLines[cmdLineIndex].GetParameter();
|
---|
| 107 |
|
---|
| 108 | // '/' があった場合は '\\' に置換
|
---|
| 109 | Jenga::Common::StringReplace( includeDir, "/", "\\" );
|
---|
[467] | 110 | }
|
---|
| 111 | else
|
---|
| 112 | {
|
---|
| 113 | // 不正なコマンド
|
---|
| 114 | std::string keyword = cmdLine.GetCommand();
|
---|
| 115 | if( keyword.size() == 0 )
|
---|
| 116 | {
|
---|
| 117 | keyword = cmdLine.GetParameter();
|
---|
| 118 | }
|
---|
| 119 | std::cout << keyword << " コマンドとして認識できません。" << std::endl;
|
---|
| 120 | return false;
|
---|
| 121 | }
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | return true;
|
---|
| 125 | }
|
---|
[472] | 126 |
|
---|
| 127 | int Program::GetExitCode() const
|
---|
| 128 | {
|
---|
| 129 | if( !compiler.IsBuildSuccessful() )
|
---|
| 130 | {
|
---|
| 131 | // ビルドに失敗
|
---|
| 132 | return 1;
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | // ビルドに成功
|
---|
| 136 | return 0;
|
---|
| 137 | }
|
---|