⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mdv.cpp

📁 An open source handwriting recongnition package!!!
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************************
* Copyright (c) 2007 Hewlett-Packard Development Company, L.P.
* Permission is hereby granted, free of charge, to any person obtaining a copy of 
* this software and associated documentation files (the "Software"), to deal in 
* the Software without restriction, including without limitation the rights to use, 
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the 
* Software, and to permit persons to whom the Software is furnished to do so, 
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
*****************************************************************************************/

/************************************************************************
 * SVN MACROS
 *
 * $LastChangedDate: 2008-09-02 17:10:10 +0530 (Tue, 02 Sep 2008) $
 * $Revision: 685 $
 * $Author: mnab $
 *
 ************************************************************************/

/***************************************************************************
 * FILE DESCR: Definitions of Model Data Viewer main function.
 *
 * CONTENTS:   
 *		main
 *		helpDisplay
 *		mapOptions
 *	
 *		
 *		 
 * AUTHOR:  Vijayakumara M
 *
 * DATE:    Aug 23, 2005
 * CHANGE HISTORY:
 * Author		Date			Description of change
 ****************************************************************************/
#pragma warning (disable : 4786)

#include "mdv.h"
#include "LTKCheckSumGenerate.h"
#include "LTKStringUtil.h"


/**********************************************************************************
* AUTHOR		: Vijayakumara M
* DATE			: 23 Aug 2005
* NAME			: main
* DESCRIPTION	: Model Data viewer main function - Takes file name as its argument
*				  and checks the integrity of the file and displays the options user
*				  entered in the command prompt.
* ARGUMENTS		: int argc, char *argv[]  ( file name and user desired options)
* RETURNS		: 0 on success and -1 on failure.
* NOTES			:
* CHANGE HISTROY
* Author			Date				Description of change
************************************************************************************/
int main(int argc, char* argv[])
{

	string m_strLipiRootPath    = "";
    string m_logFileName        = DEFAULT_LOG_FILE;
    string m_logLevelStr        = "ERROR";
    LTKLogger::EDebugLevel m_logLevel = DEFAULT_LOG_LEVEL;

	int index = 1;
	int tmp = 0;
	int str = 0;
    int filteredArgc = argc;
	
	bool filFlag = false;		// Flag to indicate the file name specified in the comman prompt.
	bool allFlag = false;		// Flag to indicate all options to be displayed or not.
	bool helpFlag = false;
    bool preprocFlag = false;   // Flag to indicate preproc fields to be displayed.
	
	stringStringMap headerSequence;	// Get the maped header tokenized stings.

	stringStructMap optMap;		// Gets the options and corresponding values.

    stringStructMap optPreProcMap; // Gets the Preprocessing options and corresponding values.
	
	string fileName;			// Model Data file Name.

	string description;			// Option description

	LTKCheckSumGenerate chFile;			// instance of checkSum class for checking file integrity.

	//Display order
	char optIndex[][20]={"-PROJNAME","-NUMSHAPES","-RECNAME","-RECVER","-CHECKSUM","-CREATETIME","-MODTIME","-HEADERLEN","-DATAOFFSET","-HEADERVER","-BYTEORDER", "-FEATEXTR"};
    
    if (argc == 1)
    {
        helpDisplay();
        return SUCCESS;
    }
	
	// Get the argument passed through command prompt.
	while(index < argc)
	{
		// If argument is equal to "-a" or "-all" set allFlag for to display all the options.
		if(LTKSTRCMP(argv[index], OPTION_ALL) == 0)
		{
			allFlag = true;
			index++;
			continue;
		}

        //Preproc
        if(LTKSTRCMP(argv[index], OPTION_PREPROC) == 0)
		{
			preprocFlag = true;
			index++;
			continue;
		}

		if(LTKSTRCMP(argv[index], OPTION_HELP) == 0)
		{
			// Call helpDisplay function for displaying the help notice.
			helpDisplay();
			return SUCCESS;
		}

        if(LTKSTRCMP(argv[index], OPTION_LIPI_ROOT) == 0)
		{
			if (index+1 >= argc)
            {
                cout << "Please specify LIPI_ROOT " << endl;
                return FAILURE;
            }

            m_strLipiRootPath = argv[index+1];
            index++;
		}

		if(LTKSTRCMP(argv[index], OPTION_INPUT) == 0)
		{
			//set filFlag if the file Name is spcified
			if(index+1 < argc)
			{
				filFlag = true;
				fileName = argv[index+1];
				index++;
			}
		}

		if(LTKSTRCMP(argv[index], OPTION_VER) == 0)
		{
			cout << SUPPORTED_MIN_VERSION << endl;
			return SUCCESS;
		}

        if(LTKSTRCMP(argv[index], OPTION_LOGFILE) == 0)
		{
			if (index+1 >= argc)
            {
                cout << "Please specify log file name " << endl;
                return FAILURE;
            }

            m_logFileName = argv[index+1];
            filteredArgc = argc-2;
            index++;
		}
		if(LTKSTRCMP(argv[index], OPTION_LOGLEVEL) == 0)
		{
			if (index+1 >= argc)
            {
                cout << "Please specify log level " << endl;
                return FAILURE;
            }

            m_logLevelStr = argv[index+1];

            int errorCode = mapLogLevel(m_logLevelStr, m_logLevel);
            
            if (errorCode != SUCCESS)
            {
                LTKReturnError(errorCode);
            }

            filteredArgc = argc-2;
            index++;
		}

		index++;
	}

    // If nothing specified except the file, display all
	if( (filteredArgc == 5 || filteredArgc == 3) && filFlag) 
    {   
		allFlag = true;
    }

	index = 1;

    if (m_strLipiRootPath.empty())
    {
		char* envstring = NULL;
		envstring = getenv(LIPIROOT_ENV_STRING);

		if(envstring == NULL )
		{
			cout << "Error, Environment variable is not set LIPI_ROOT" << endl;
			return FAILURE;
		}
		m_strLipiRootPath = envstring;
		envstring = NULL;
    }
    
    // Configure logger
    LTKLoggerUtil::createLogger(m_strLipiRootPath);
    LTKLoggerUtil::configureLogger(m_logFileName, m_logLevel);

	//if filFlag is set, display File name is not specified and display help
	if(filFlag == false)
	{
		cout <<endl<<endl<<"Model data file Name is not given " <<endl;
		cout <<"Please specify the file Name with \"-input\" option" << endl;

		cout << endl;
		//Display Help 
		helpDisplay();
		cout << endl;

		LTKLoggerUtil::destroyLogger();
		return FAILURE;
	}

	// Check file integrity. If file has been altered then set the chflag.
	if((tmp = chFile.readMDTHeader(fileName, headerSequence)) != SUCCESS)
	{
		if( tmp == EMODEL_DATA_FILE_OPEN)
		{
			cout << "Unable to open model data file" << endl;
			LTKLoggerUtil::destroyLogger();
			return FAILURE;
		}
		else if( tmp == EMODEL_DATA_FILE_FORMAT)
		{
			cout << "Incompatible model data file. The header is not in the desired format." << endl;
			LTKLoggerUtil::destroyLogger();
			return FAILURE;
		}
		else if( tmp == EINVALID_INPUT_FORMAT)
		{
			cout << endl << "Model data file is corrupted" << endl;
			LTKLoggerUtil::destroyLogger();
			return FAILURE;
		}
	}
	else
	{
			cout << endl << "Checksum successfully verified"<<endl<<endl;
	}

    if(preprocFlag)
	{
       	// Map preprocessing options with their values.
        mapPreprocOptions(optPreProcMap, headerSequence);
	    DisplayPreProc(optPreProcMap);
		LTKLoggerUtil::destroyLogger();
		return 0;
	}

   	// Map options with their values.
	mapOptions(optMap, headerSequence);

	// Iterator pointing at the begining of the option mapped address.
	map<string,  option>::iterator the_begiter = optMap.begin();


	if(allFlag)
	{
        str = 0;
		while (optIndex[str][0] != '\0')
		{
			if(!(optMap[optIndex[str]].description.empty()))
					cout << optMap[optIndex[str]].description << optMap[optIndex[str]].value << endl;
			str++;
		}

        // Map preprocessing options with their values.
        mapPreprocOptions(optPreProcMap, headerSequence);
	    DisplayPreProc(optPreProcMap);


		if( !(headerSequence[PLATFORM].empty()))
		{
			cout << "Platform		   - " << headerSequence[PLATFORM] << endl;			
			cout << "			     " << headerSequence[OSVERSION] << endl;
			cout << "			     " << headerSequence[PROCESSOR_ARCHITEC] << endl;
		}

		if( !(headerSequence[COMMENT].empty()))
		{
			cout << "Comment			   - " << headerSequence[COMMENT] << endl;
			cout << "Comment length		   - " << headerSequence[COMMENTLEN] << endl;	
		}

		if( !(headerSequence[DATASET].empty()))
		{
			cout << "Dataset name		   - " << headerSequence[DATASET] << endl;			
		}	

		LTKLoggerUtil::destroyLogger();
		return 0;
	}

    
	// Display the values if file is present and in the desired format
	while((index < argc))
	{
		if( (LTKSTRCMP(argv[index], "-INPUT") == 0) || 						

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -