Re: Command Line Interface

From: Mark Randall (markyr_at_REMOVETHISgoogle.ANDTHIScom)
Date: 02/07/05


Date: Mon, 7 Feb 2005 12:43:26 -0000

Hmm, fair read thanks for that

This is somewhat I am aiming for, to be honest my idea for this is Java
Netbean's 'console window' which it uses for user input and output. I
understand the problem is tho that Java is a interpretted language and I
wish to have compiled code.

I have a project I have written myself with between 10 and 15 thousand lines
of code and containing several configurable options, rather than creating a
GUI for them I wanted to impliment a streamed command line mode to edit them
in the apps GUI' instead of having to provide dialogs for all of them.

For example, I have a global defined class with some data in it, and I want
the user to be able to change some settings via a command-line like
interface for it, but in a structured way in my code, for example:

flw -config
flw> Enter Target: [user enters string]
flw> Enter Speed: [user enters string and conv to double]
[global class updated]

Now in a console application I would write this as

void SomeSub(void)
{
   char target[128] = { 0 };
   double speed = 0.0;
   char happy[8] = { 0 };

    cout << "Enter Target: ";
    cin >> target;
    cout << "Enter Speed";
    cin >> speed;

    cout << "You have selected" << target << " for speed" << speed << endl;
    cout << "Is this correct? Y / N: ";
    cin >> happy;

    if (!strcmp(happy, "y")) {
        if (checkTarget(target) == false)
            return;
        else
            gFlw.target = target
            gFlw.speed = speed;
    } else
        cout << "Changes aborted" << endl;
}

However, I want this to be implimented in a CEdit, or preferably, a
CRichEditCtrl... I can write functions to read a string from the end of a
line by using CString::Mid from the last length, to the new length once
return is pressed.

What I want my 'command line' like interface to do, is wait while the user
enters a string, and then it continues once return has been pressed, hence:

CConsoleHandler::ExecFLWMgr(void)
{
   char target[128] = { 0 };
   double speed = 0.0;
   char happy[8] = { 0 };

    PrintString("Enter Target: ");
    strcpy(target, (LPCTSTR)GetString());

    [...]
}

void PrintString(CString var)
{
    UpdateData(TRUE); // or less sledgehammer GetText
    Text+= var;
    UpdateData(FALSE);
}

CString GetString()
{
    [stop this function]
    [wait for user to press return]
    [continue this function]
    [return entered string]
}

Now my problem is how can I call GetString and stop it returning until a
string has been entered? Thats my problem. I presume if it never returns
until a return key, ExcelFLWMgr never gets control back until it finishes,
and as such the function can then continue using its own local variables,
this is my problem - I can't think of a way to stop GetString returning
before a return key is pressed. To point out the tolls of my folly, Ive also
never used multithreading (Which I presume would have to play a part - as i
want the rest of the dialog to be responsive while the 'console' is in the
middle of a function.

Basically, im lacking!!! (knowledge),

Does anyone have any futher ideas?

- MR

"Rodrigo Corral [MVP]" <corral_glez@hotmail.com> wrote in message
news:%23%23NBrbQDFHA.2676@TK2MSFTNGP12.phx.gbl...
> Read the second question in
> http://msdn.microsoft.com/msdnmag/issues/04/02/CQA/. It will help you!!!
>
>
> --
> Un saludo
> Rodrigo Corral González [MVP]
>
> FAQ de microsoft.public.es.vc++
> http://rcorral.mvps.org
>



Relevant Pages