Changeset 457 in dev for trunk


Ignore:
Timestamp:
Mar 23, 2008, 1:24:09 AM (16 years ago)
Author:
dai_9181
Message:

コマンドライン解析モジュールをリファクタリング。

Location:
trunk/ab5.0
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/ab5.0/abdev/BasicCompiler32/stdafx.h

    r353 r457  
    1414#include <limits.h>
    1515#include <shlobj.h>
     16#include <iostream>
    1617
    1718//boost libraries
     
    2021#include <jenga/include/common/String.h>
    2122#include <jenga/include/common/File.h>
     23#include <jenga/include/common/CmdLine.h>
    2224
    2325#include "../BasicCompiler_Common/common.h"
  • trunk/ab5.0/abdev/BasicCompiler_Common/BasicCompiler.cpp

    r455 r457  
    569569}
    570570
     571bool AnalysisCommandLines( bool &isFromEditor )
     572{
     573    // 値を初期化
     574    isFromEditor = false;
     575
     576    // コマンドラインを解析
     577    const Jenga::Common::CmdLines cmdLines( PathGetArgs( GetCommandLine() ) );
     578    int cmdLineIndex = 0;
     579
     580    if( cmdLines.size() == 0 )
     581    {
     582        // 何も指定されていないとき
     583        return true;
     584    }
     585
     586    if( cmdLines[cmdLineIndex].IsNamelessCommand() )
     587    {
     588        // 先頭に無名コマンドがきた場合、ソースファイル名として認識する
     589        lstrcpy( SourceFileName, cmdLines[cmdLineIndex].GetParameter().c_str() );
     590
     591        cmdLineIndex ++;
     592
     593        if( cmdLines.size() == 1 )
     594        {
     595            // ソースファイル名のみの指定だったとき
     596            return true;
     597        }
     598
     599        // 出力ファイル名を取得
     600        if( cmdLines[cmdLineIndex].IsNamelessCommand() )
     601        {
     602            // 二番目にも無名コマンドがきた場合、ソースファイル名として認識する
     603            lstrcpy( OutputFileName, cmdLines[cmdLineIndex].GetParameter().c_str() );
     604
     605            cmdLineIndex ++;
     606        }
     607    }
     608
     609    for( ; cmdLineIndex < static_cast<int>(cmdLines.size()); cmdLineIndex++ )
     610    {
     611        const Jenga::Common::CmdLine &cmdLine = cmdLines[cmdLineIndex];
     612
     613        if( cmdLine.GetCommand() == "wnd" )
     614        {
     615            // 親エディタのウィンドウ ハンドル
     616            isFromEditor = true;
     617            sscanf( cmdLine.GetParameter().c_str(), "%08x", &hOwnerEditor );
     618        }
     619        else if( cmdLine.GetCommand() == "debug" )
     620        {
     621            // デバッグ ビルド
     622            bDebugCompile = 1;
     623        }
     624        else if( cmdLine.GetCommand() == "run" )
     625        {
     626            // デバッグ実行
     627            bDebugRun = 1;
     628        }
     629        else if( cmdLine.GetCommand() == "attach" )
     630        {
     631            // アタッチ
     632            bDebugRun=1;
     633            bAttach=1;
     634            sscanf( cmdLine.GetParameter().c_str(), "%08x", &dwAttachProcessId );
     635        }
     636        else if( cmdLine.GetCommand() == "dll" )
     637        {
     638            // DLLとしてビルド
     639            compiler.SetTargetModuleType( Compiler::Dll );
     640        }
     641        else if( cmdLine.GetCommand() == "static_library" )
     642        {
     643            // 静的リンクライブラリとしてビルド
     644            compiler.SetTargetModuleType( Compiler::StaticLibrary );
     645        }
     646        else if( cmdLine.GetCommand() == "unicode" )
     647        {
     648            // Unicode
     649            Smoothie::SetUnicodeMark( true );
     650            typeOfPtrChar = MAKE_PTR_TYPE(DEF_WORD,1);
     651            typeOfPtrUChar = MAKE_PTR_TYPE(DEF_WORD,1);
     652        }
     653        else if( cmdLine.GetCommand() == "clip_compile_view" )
     654        {
     655            //埋め込み型コンパイラビュー
     656            bClipCompileView = 1;
     657        }
     658        else if( cmdLine.GetCommand() == "include_dir" )
     659        {
     660            //インクルード ディレクトリ
     661            lstrcpy( szIncludeDir, cmdLine.GetParameter().c_str() );
     662        }
     663        else
     664        {
     665            // 不正なコマンド
     666            std::string keyword = cmdLine.GetCommand();
     667            if( keyword.size() == 0 )
     668            {
     669                keyword = cmdLine.GetParameter();
     670            }
     671            std::cout << keyword << " コマンドとして認識できません。" << std::endl;
     672            return false;
     673        }
     674    }
     675
     676    return true;
     677}
     678
    571679void _Test()
    572680{
     
    577685int main()
    578686{
    579     int i,i2;
     687    int i;
    580688    char temporary[1024],temp2[MAX_PATH];
    581689
    582690    hInst = GetModuleHandle( NULL );
    583     LPSTR lpCmdLine = PathGetArgs( GetCommandLine() );
    584691
    585692    //_Test();
     
    599706    pobj_nv->load();
    600707
    601     //ソースファイル名を取得
    602     i=0;
    603     if(lpCmdLine[0]!='/'){
    604         if(lpCmdLine[0]=='\"'){
    605             for(i=1,i2=0;;i++,i2++){
    606                 if(lpCmdLine[i]=='\"'){
    607                     SourceFileName[i2]=0;
    608                     break;
    609                 }
    610                 SourceFileName[i2]=lpCmdLine[i];
    611                 if(lpCmdLine[i]=='\0') break;
    612             }
    613             i++;
    614             while(lpCmdLine[i]==' ') i++;
    615         }
    616         else{
    617             for(i=0;;i++){
    618                 if(lpCmdLine[i]==' '){
    619                     SourceFileName[i]=0;
    620                     break;
    621                 }
    622                 SourceFileName[i]=lpCmdLine[i];
    623                 if(lpCmdLine[i]=='\0') break;
    624             }
    625             while(lpCmdLine[i]==' ') i++;
    626         }
    627     }
    628 
    629     BOOL bFromEditor=0;
    630     OutputFileName[0]=0;
    631     if(lpCmdLine[i]&&lpCmdLine[i]!='/'){
    632         if(lpCmdLine[i]=='\"'){
    633             for(i++,i2=0;;i++,i2++){
    634                 if(lpCmdLine[i]=='\"'){
    635                     OutputFileName[i2]=0;
    636                     break;
    637                 }
    638                 OutputFileName[i2]=lpCmdLine[i];
    639                 if(lpCmdLine[i]=='\0') break;
    640             }
    641             i++;
    642             while(lpCmdLine[i]==' ') i++;
    643         }
    644         else{
    645             for(i2=0;;i++,i2++){
    646                 if(lpCmdLine[i]==' '){
    647                     OutputFileName[i2]=0;
    648                     break;
    649                 }
    650                 OutputFileName[i2]=lpCmdLine[i];
    651                 if(lpCmdLine[i]=='\0') break;
    652             }
    653             while(lpCmdLine[i]==' ') i++;
    654         }
    655     }
    656 
    657     KillSpaces(lpCmdLine+i,temporary);
    658     i=0;
    659     while(temporary[i]=='/'){
    660         for(i++,i2=0;;i++,i2++){
    661             if(temporary[i]=='/'){
    662                 temp2[i2]=0;
    663                 break;
    664             }
    665             if(temporary[i]==':'){
    666                 temp2[i2]=0;
    667                 break;
    668             }
    669             temp2[i2]=temporary[i];
    670             if(temporary[i]=='\0') break;
    671         }
    672 
    673         char temp3[MAX_PATH];
    674         if(temporary[i]==':'){
    675             i++;
    676             if(temporary[i]=='\"'){
    677                 for(i++,i2=0;;i++,i2++){
    678                     if(temporary[i]=='\"'){
    679                         temp3[i2]=0;
    680                         RemoveStringQuotes(temp3);
    681                         i++;
    682                         break;
    683                     }
    684                     temp3[i2]=temporary[i];
    685                     if(temporary[i]=='\0') break;
    686                 }
    687             }
    688             else{
    689                 for(i2=0;;i++,i2++){
    690                     if(temporary[i]=='/'){
    691                         temp3[i2]=0;
    692                         break;
    693                     }
    694                     if(temporary[i]==':'){
    695                         temp3[i2]=0;
    696                         break;
    697                     }
    698                     temp3[i2]=temporary[i];
    699                     if(temporary[i]=='\0') break;
    700                 }
    701             }
    702         }
    703         else temp3[0]=0;
    704 
    705 
    706         /////////////////////////
    707         // コマンドラインを調査
    708         /////////////////////////
    709 
    710         //ウィンドウハンドル
    711         if(lstrcmp(temp2,"wnd")==0){
    712             bFromEditor=1;
    713 
    714             if(temp3[0]) sscanf(temp3,"%08x",&hOwnerEditor);
    715         }
    716 
    717         //デバッグコンパイル
    718         else if(lstrcmp(temp2,"debug")==0) bDebugCompile=1;
    719 
    720         //デバッグ実行
    721         else if(lstrcmp(temp2,"run")==0) bDebugRun=1;
    722 
    723         //デバッグ実行(アタッチする)
    724         else if(lstrcmp(temp2,"attach")==0){
    725             bDebugRun=1;
    726             bAttach=1;
    727 
    728             if(temp3[0]) sscanf(temp3,"%08x",&dwAttachProcessId);
    729         }
    730 
    731         //DLL生成
    732         else if(lstrcmp(temp2,"dll")==0)
    733         {
    734             compiler.SetTargetModuleType( Compiler::Dll );
    735         }
    736 
    737         // StaticLibrary生成
    738         else if( lstrcmp( temp2, "static_library" ) ==0 )
    739         {
    740             compiler.SetTargetModuleType( Compiler::StaticLibrary );
    741         }
    742 
    743         //Unicode
    744         else if( lstrcmp( temp2, "unicode" ) ==0 ){
    745             Smoothie::SetUnicodeMark( true );
    746             typeOfPtrChar = MAKE_PTR_TYPE(DEF_WORD,1);
    747             typeOfPtrUChar = MAKE_PTR_TYPE(DEF_WORD,1);
    748         }
    749 
    750         //埋め込み型コンパイラビュー
    751         else if(lstrcmp(temp2,"clip_compile_view")==0) bClipCompileView=1;
    752 
    753         //インクルードディレクトリ
    754         else if(lstrcmp(temp2,"include_dir")==0){
    755             lstrcpy(szIncludeDir,temp3);
    756         }
     708    bool isFromEditor;
     709    if( !AnalysisCommandLines( isFromEditor ) )
     710    {
     711        // コマンドラインが不正
     712        return 0;
    757713    }
    758714
     
    893849    SetWindowLongPtr(GetDlgItem(hMainDlg,IDC_DEBUGLIST),GWLP_WNDPROC,(LONG_PTR)DebugListProc);
    894850
    895     if(bFromEditor) SendMessage(hMainDlg,WM_COMMAND,IDOK,0);
     851    if( isFromEditor )
     852    {
     853        SendMessage(hMainDlg,WM_COMMAND,IDOK,0);
     854    }
    896855
    897856    MSG msg;
  • trunk/ab5.0/abdev/BasicCompiler_Common/error.cpp

    r455 r457  
    11#include "stdafx.h"
    2 
    3 #include <iostream>
    42
    53#include <Program.h>
  • trunk/ab5.0/jenga/include/common/CmdLine.h

    r291 r457  
    1818    }
    1919
     20    bool IsNamelessCommand() const
     21    {
     22        return ( command.size() == 0 );
     23    }
    2024    const std::string& GetCommand() const
    2125    {
  • trunk/ab5.0/jenga/src/common/CmdLine.cpp

    r291 r457  
    77CmdLines::CmdLines( const std::string &strCmdLine )
    88{
    9     for( int i=0; i<(int)strCmdLine.size() ; i++ )
     9    char temporary[8192];
     10    int i = 0;
     11    while( i<(int)strCmdLine.size() )
    1012    {
     13        while( strCmdLine[i] == ' ' )
     14        {
     15            i ++;
     16        }
     17
     18        if( strCmdLine[i] == '\0' )
     19        {
     20            break;
     21        }
     22
    1123        if( strCmdLine[i] == '/' )
    1224        {
    1325            i++;
    14 
    15             char temporary[255];
    1626
    1727            // コマンド文字列(オプション名)を抽出
     
    3545            if( (int)strCmdLine.size() > i && strCmdLine[i] != '/' )
    3646            {
     47                if( strCmdLine[i] == ':' )
     48                {
     49                    // ':'はコマンドとパラメータの区切り文字として認識する
     50                    i++;
     51                }
     52
    3753                // パラメータを抽出
    3854                if( strCmdLine[i] == '\"' )
     
    7086            this->push_back( CmdLine( command, parameter ) );
    7187        }
     88        else if( strCmdLine[i] == '\"' )
     89        {
     90            i++;
     91            //ダブルクォートの中身を取り出す
     92            for( int j=0; ; j++, i++ )
     93            {
     94                if( strCmdLine[i] == '\"' || strCmdLine[i] == '\0' )
     95                {
     96                    temporary[j] = 0;
     97
     98                    if( strCmdLine[i] == '\"' ) i++;
     99                    break;
     100                }
     101                temporary[j] = strCmdLine[i];
     102            }
     103
     104            this->push_back( CmdLine( "", temporary ) );
     105        }
     106        else
     107        {
     108            //空白またはヌル文字以前を取り出す
     109            for( int j=0; ; j++, i++ )
     110            {
     111                if( strCmdLine[i] == ' ' || strCmdLine[i] == '\0' )
     112                {
     113                    temporary[j] = 0;
     114                    break;
     115                }
     116                temporary[j] = strCmdLine[i];
     117            }
     118
     119            this->push_back( CmdLine( "", temporary ) );
     120        }
    72121    }
    73122}
Note: See TracChangeset for help on using the changeset viewer.