int main()

in source/code/providers/support/logfilereader.cpp [88:253]


int main(int argc, char * const argv[])
{
    int exitStatus = 0;
    int c;

    bool fResetAllLogFileStates_onRead = false;

    // If no arguments, show brief usage help.

    if (1 == argc)
    {
        usage(argv[0], true, 0);
    }

    enum OperationType {
        UNSET,
        Marshal_Test,
        Reset_File,
        Reset_All_Files,
        Read_Log_File_Interactive,
        Read_Log_File,
        Show_Version
    } operation = UNSET;

    // Parse the arguments
    //
    // Illegal arguments are displayed slightly different across our platforms.
    // To help allow for consistent output, override error output and handle it
    // ourselves via the opterr variable.

    opterr = 0;                 // Disable printing errors for bad options
    while ((c = getopt(argc, argv, "hi?g:mprtv")) != -1) {
        const char * parameter = NULL;

        switch(c) {
            case 'h':                   /* Show extended help information */
                usage(argv[0], false, 0);
                /*NOTREACHED*/
                break;
            case 'g':                   /* Provider entry (reset all log file state files) */
                if (UNSET != operation)
                {
                    cerr << argv[0] << ": Parsing error - operation already specified (" << operation << ")" << endl;
                    usage(argv[0], true, EXIT_LOGIC_ERROR);
                }
                parameter = optarg;

                if ( !StrCompare(L"0", StrFromUTF8(parameter), true)
                     || !StrCompare(L"false", StrFromUTF8(parameter), true) )
                {
                    fResetAllLogFileStates_onRead = false;
                }
                else if ( !StrCompare(L"1", StrFromUTF8(parameter), true)
                          || !StrCompare(L"true", StrFromUTF8(parameter), true) )
                {
                    fResetAllLogFileStates_onRead = true;
                }
                else
                {
                    cerr << argv[0] << ": Parsing error - Invalid argument for -g (" << parameter << ")" << endl;
                    usage(argv[0], true, EXIT_LOGIC_ERROR);
                }
                operation = Reset_All_Files;
                break;
            case 'i':                   /* Interactive (prompted) use */
                if (UNSET != operation)
                {
                    cerr << argv[0] << ": Parsing error - operation already specified (" << operation << ")" << endl;
                    usage(argv[0], true, EXIT_LOGIC_ERROR);
                }
                operation = Read_Log_File_Interactive;
                break;
            case 'm':
                if (UNSET != operation)
                {
                    cerr << argv[0] << ": Parsing error - operation already specified (" << operation << ")" << endl;
                    usage(argv[0], true, EXIT_LOGIC_ERROR);
                }
                operation = Marshal_Test;
                break;
            case 'p':                   /* Provider entry (read log file) */
                if (UNSET != operation)
                {
                    cerr << argv[0] << ": Parsing error - operation already specified (" << operation << ")" << endl;
                    usage(argv[0], true, EXIT_LOGIC_ERROR);
                }
                operation = Read_Log_File;
                break;
            case 'r':                   /* Provider entry (reset log file state file) */
                if (UNSET != operation)
                {
                    cerr << argv[0] << ": Parsing error - operation already specified (" << operation << ")" << endl;
                    usage(argv[0], true, EXIT_LOGIC_ERROR);
                }
                operation = Reset_File;
                break;
            case 't':                   /* Test mode requested (check for testrunner) */
                s_fTestMode = true;
                break;
            case 'v':                   /* Show version info */
                if (UNSET != operation)
                {
                    cerr << argv[0] << ": Parsing error - operation already specified (" << operation << ")" << endl;
                    usage(argv[0], true, EXIT_LOGIC_ERROR);
                }
                operation = Show_Version;
                break;
            case '?':                   /* Show basic help information */
                // If invalid parameter, return error result
                if (0 != optopt && '\?' != optopt)
                {
                    cerr << argv[0]
                         << ": invalid option -- '"
                         << (char) optopt 
                         << "'" << endl;
                    usage(argv[0], true, EXIT_LOGIC_ERROR);
                }
                /*NOTREACHED*/
            default:
                usage(argv[0], true, 0);
                /*NOTREACHED*/
                break;
        }
    }

    // Since scxlogfilereader just uses the scx.log logfile, don't write header
    // each time we're called (makes log confusing thinking agent restarted)
    SCXCoreLib::SCXProductDependencies::SetLogFileHeaderSuppression(true);

    // Dispatch for the operation that was requested
    switch (operation)
    {
        case Marshal_Test:
            PerformMarshalTest();
            break;

        case Reset_File:
            exitStatus = ResetLogFileState();
            break;

        case Reset_All_Files:
            exitStatus = ResetAllLogFileStates(fResetAllLogFileStates_onRead);
            break;

        case Read_Log_File_Interactive:
            ReadLogFile_Interactive();
            break;

        case Read_Log_File:
            exitStatus = ReadLogFile_Provider();
            break;

        case Show_Version:
            show_version();
            break;

        case UNSET:
        default:
            // If invalid parameter, return error result
            cerr << argv[0] << ": Logic Error - invalid operation (" << operation << ")" << endl;
            exitStatus = EXIT_LOGIC_ERROR;
            break;
    }

    return exitStatus;
}