Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 243589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:56:02+00:00 2026-05-11T20:56:02+00:00

I’ve got a large (read: nightmare) method which has grown over the years to

  • 0

I’ve got a large (read: nightmare) method which has grown over the years to support my project’s ever growing list of commandline arguments. I mean several pages of readme docs for brief blurbs per argument.

As I’ve added each feature, I’ve simply “registered” a way of handling that argument by adding a few lines to that method.

However, that method is now unsightly, bug prone, and difficult to understand. Here’s an example of the shorter of the two methods currently handling this:

//All double dash arguments modify global options of the program,
//such as --all --debug --timeout etc.
void consoleParser::wordArgParse(std::vector<criterion *> *results)
{
    TCHAR const *compareCurWordArg = curToken.c_str()+2;
    if (!_tcsicmp(compareCurWordArg,_T("all")))
    {
        globalOptions::showall = TRUE;
    } else if (!_tcsnicmp(compareCurWordArg,_T("custom"),6))
    {
        if (curToken[9] == L':')
        {
            globalOptions::display = curToken.substr(10,curToken.length()-11);
        } else
        {
            globalOptions::display = curToken.substr(9,curToken.length()-10);
        }
    } else if (*compareCurWordArg == L'c' || *compareCurWordArg == L'C')
    {
        if (curToken[3] == L':')
        {
            globalOptions::display = curToken.substr(5,curToken.length()-6);
        } else
        {
            globalOptions::display = curToken.substr(4,curToken.length()-5);
        }
    } else if (!_tcsicmp(compareCurWordArg,_T("debug")))
    {
        globalOptions::debug = TRUE;
    } else if (!_tcsicmp(compareCurWordArg,L"expand"))
    {
        globalOptions::expandRegex = false;
    } else if (!_tcsicmp(compareCurWordArg,L"fileLook"))
    {
        globalOptions::display = L"---- #f ----#nCompany: #d#nFile Description: #e#nFile Version: #g"
        L"#nProduct Name: #i#nCopyright: #j#nOriginal file name: #k#nFile Size: #u#nCreated Time: #c"
        L"#nModified Time: #m#nAccessed Time: #a#nMD5: #5#nSHA1: #1";
    } else if (!_tcsicmp(compareCurWordArg,_T("peinfo")))
    {
        globalOptions::display = _T("[#p] #f");
    } else if (!_tcsicmp(compareCurWordArg,L"enable-filesystem-redirector-64"))
    {
        globalOptions::disable64Redirector = false;
    } else if (!_tcsnicmp(compareCurWordArg,_T("encoding"),8))
    {
        //Performance enhancement -- encoding compare only done once.
        compareCurWordArg += 8;
        if (!_tcsicmp(compareCurWordArg,_T("acp")))
        {
            globalOptions::encoding = globalOptions::ENCODING_TYPE_ACP;
        } else if (!_tcsicmp(compareCurWordArg,_T("oem")))
        {
            globalOptions::encoding = globalOptions::ENCODING_TYPE_OEM;
        } else if (!_tcsicmp(compareCurWordArg,_T("utf8")))
        {
            globalOptions::encoding = globalOptions::ENCODING_TYPE_UTF8;
        } else if (!_tcsicmp(compareCurWordArg,_T("utf16")))
        {
            globalOptions::encoding = globalOptions::ENCODING_TYPE_UTF16;
        } else
        {
            throw eMsg(L"Unrecognised encoding word argument!\r\nValid choices are --encodingACP --encodingOEM --encodingUTF8 and --encodingUTF16. Terminate.");
        }
    } else if (!_tcsnicmp(compareCurWordArg,L"files",5))
    {
        compareCurWordArg += 5;
        if (*compareCurWordArg == L':') compareCurWordArg++;
        std::wstring filePath(compareCurWordArg);
        globalOptions::regexes.insert(globalOptions::regexes.end(), new filesRegexPlaceHolder);
        results->insert(results->end(),new filesRegexPlaceHolder);
        boost::algorithm::trim_if(filePath,std::bind2nd(std::equal_to<wchar_t>(),L'"'));
        loadFiles(filePath);
    } else if (!_tcsicmp(compareCurWordArg,_T("full")))
    {
        globalOptions::fullPath = TRUE;
    } else if (!_tcsicmp(compareCurWordArg,_T("fs32")))
    {
        globalOptions::disable64Redirector = false;
    } else if (!_tcsicmp(compareCurWordArg,_T("long")))
    {
        globalOptions::display = _T("#t #s #m  #f");
        globalOptions::summary = TRUE;
    } else if (!_tcsnicmp(compareCurWordArg,_T("limit"),5))
    {
        compareCurWordArg += 5;
        if (*compareCurWordArg == _T(':'))
            compareCurWordArg++;
        globalOptions::lineLimit = _tcstoui64(compareCurWordArg,NULL,10);
        if (!globalOptions::lineLimit)
        {
            std::wcerr << eMsg(L"Warning: You are limiting to infinity lines. Check one of your --limit options!\r\n");
        }
    } else if (!_tcsicmp(compareCurWordArg,_T("short")))
    {
        globalOptions::display = _T("#8");
    } else if (!_tcsicmp(compareCurWordArg,_T("summary")))
    {
        globalOptions::summary = TRUE;
    } else if (!_tcsicmp(compareCurWordArg,_T("norecursion")))
    {
        globalOptions::noSubDirs = TRUE;
    } else if (!_tcsnicmp(compareCurWordArg,_T("timeout"),7))
    {
        compareCurWordArg += 7;
        if (*compareCurWordArg == _T(':'))
            compareCurWordArg++;
        globalOptions::timeout = _tcstoul(compareCurWordArg,NULL,10);
        if (!globalOptions::timeout)
        {
            std::wcerr << eMsg(L"Warning: You are limiting to infinite time. Check one of your --timeout options!\r\n");
        }
    } else if (!_tcsnicmp(compareCurWordArg,_T("tx"),2))
    {
        compareCurWordArg += 2;
        if (*compareCurWordArg == _T(':'))
            compareCurWordArg++;
        globalOptions::timeout = _tcstoul(compareCurWordArg,NULL,10);
        if (!globalOptions::timeout)
        {
            std::wcerr << eMsg(L"Warning: You are limiting to infinite time. Check one of your --timeout options!\r\n");
        }
    } else
    {
        throw eMsg(L"Could not understand word argument! Ensure all of your directives are spelled correctly. Terminate.");
    }
}

I’d post the long one but it’s over 500 lines.

Are there better ways of handling this particular problem or should I just leave it as a long method?

EDIT: I’m not looking for a tokenizing library — I already did the dirty work on that. I’m curious if it would make sense to make stub methods out of the larger dirty method.

Billy3

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T20:56:02+00:00Added an answer on May 11, 2026 at 8:56 pm

    I’m sure that there’s an equivalent of getopt(3) function for Windows.
    Here’s the first hit from Google – Pete Wilson.
    Or you can look into Boost Program Options for a decent C++ library.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 152k
  • Answers 152k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can only eager load on a relation property. Not… May 12, 2026 at 10:11 am
  • Editorial Team
    Editorial Team added an answer The way this is generally done with SVN is to… May 12, 2026 at 10:11 am
  • Editorial Team
    Editorial Team added an answer InfTool is the closest that comes to mind. It allows… May 12, 2026 at 10:10 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.