CMDPROC.CPP

///////////////////////////////////////////////////////////////////////////// 
// cmdproc.cpp 
// Copyright (C) 1996 Microsoft Corp. 
// 
//  more flexible replacement for mfc CCommandLineInfo 
 
///////////////////////////////////////////////////////////////////////////// 
// CCommandLineProc 
 
#include "stdafx.h" 
#include "cmdproc.h" 
 
// NOTE: this member should be used from inside a set of try/catch 
// since there is a remote chance that some of the string handling 
// could throw memory exceptions 
BOOLEAN CCommandLineProc::ProcessCommandLine(int iSC, int &argc, _TCHAR **argv) 
{ 
    CString csSwitchChars; 
    csSwitchChars.LoadString(iSC); 
    CString csParam; 
 
    if (acapArgs[0].m_Cmd == NULL) { 
        return TRUE; 
    } 
  int i = 1; 
    while (i < argc) { 
        csParam = argv[i]; 
if (!_tcscspn(csParam, csSwitchChars)) 
{ 
            // its a switch 
// remove flag specifier 
csParam = csParam.Right(csParam.GetLength() - 1); 
            // find the function for this switch 
            CString csSwitch, csArg; 
             
            for (int j = 0; acapArgs[j].m_Cmd != NULL; j++) { 
                csSwitch.LoadString(acapArgs[j].m_iIDS); 
                if (!_tcsnccmp(csParam, csSwitch, csSwitch.GetLength())) {                     
                    break; 
                }             
            } 
            if (acapArgs[j].m_Cmd != NULL) { 
                csArg = csParam.Right(csParam.GetLength() - csSwitch.GetLength()); 
                (this->*(acapArgs[j].m_Cmd))(csArg); 
                DeleteArg(i, argc, argv); 
            } else { 
                i++;  // skip this one 
            } 
} else { 
            // its positional so skip it. 
            i++;             
        } 
 
} 
    return GetPositionalArgs(argc, argv); 
} 
 
BOOLEAN CCommandLineProc::GetPositionalArgs(int &argc, _TCHAR **argv) 
{ 
    // default implementation provides no positional args 
    return TRUE; 
}