Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2015-07

Interactive command recognition & mapping to program functions & other 'cli' features as a unit

7 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Lukasz Sokol

Hi,

I tried piecing something like in $topic together,

intended as an 'interactive' command interpreter for my program. (which will in time grow an 'embedded' web server and intended to run as a (windows) service, but it's too early for that at the moment)

(I hooked some events of a TMemo to my interpreter, which currently recognizes commands by a static map/array of record of string and function pointers; and passes the rest of command line to the called function as string, then the function is a shim/wrapper over the deeper program functions; the entire parameter sanitizing and conversion from string to what the 'deeper' function expects, is done in the 'wrapper' function layer,
and so is the function output converted back to string and spat out to the TMemo.

It's growing too complicated to maintain for the purpose, day by day, and has problems with some more interactive commands or tab completion...

Is there something I could use for the purpose that is ready-made, tested, free and open source AND of course in FreePascal ? (I can share my changes back if I do any, can't open the entire application though)

Any hints,
Any keywords,
any lmgtfy's
are welcome :)

Kind Regards
el es

Reply by email

Mark Morgan Lloyd
to Lukasz Sokol
Lukasz Sokol wrote 26 lines
Hi, I tried piecing something like in $topic together, intended as an 'interactive' command interpreter for my program. (which will in time grow an 'embedded' web server and intended to run as a (windows) service, but it's too early for that at the moment) (I hooked some events of a TMemo to my interpreter, which currently recognizes commands by a static map/array of record of string and function pointers; and passes the rest of command line to the called function as string, then the function is a shim/wrapper over the deeper program functions; the entire parameter sanitizing and conversion from string to what the 'deeper' function expects, is done in the 'wrapper' function layer, and so is the function output converted back to string and spat out to the TMemo. It's growing too complicated to maintain for the purpose, day by day, and has problems with some more interactive commands or tab completion... Is there something I could use for the purpose that is ready-made, tested, free and open source AND of course in FreePascal ? (I can share my changes back if I do any, can't open the entire application though) Any hints, Any keywords, any lmgtfy's are welcome :)

This might be better in the Lazarus mailing list.

I've knocked together a special-purpose terminal emulator, it's actually an IBM 2741 terminal which uses totally non-standard codes internally and I wanted something for APL, early ALGOL implementations and so on. This is obviously character-by-character, and I was just about able to get something working for TMemo, TRichMemo and TListBox. Somebody else mentioned TCmdBox (?) but I wasn't able to get it working adequately and in the end discarded most of my attempts, it might be worth looking at if you're trying to process lines rather than characters.

I think this was discussed a few months ago, and consensus was that there wasn't an adequate terminal emulator component. See below.

http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-Xterm-konsole-etc-td4031905.html

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Lukasz Sokol
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 9 lines
Lukasz Sokol wrote: > Hi, > > I tried piecing something like in $topic together, > > intended as an 'interactive' command interpreter for my program. > (which will in time grow an 'embedded' web server and intended to > run as a (windows) service, but it's too early for that at the > moment)

[...]

> Any hints, Any keywords, any lmgtfy's are welcome :) This might be better in the Lazarus mailing list.

Thanks, I'll post there too, however I though i start here...

Show quoted text 10 lines
I've knocked together a special-purpose terminal emulator, it's actually an IBM 2741 terminal which uses totally non-standard codes internally and I wanted something for APL, early ALGOL implementations and so on. This is obviously character-by-character, and I was just about able to get something working for TMemo, TRichMemo and TListBox. Somebody else mentioned TCmdBox (?) but I wasn't able to get it working adequately and in the end discarded most of my attempts, it might be worth looking at if you're trying to process lines rather than characters.

Will check TCmdBox... thanks!

Show quoted text 8 lines
I think this was discussed a few months ago, and consensus was that there wasn't an adequate terminal emulator component. See below. http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-Xterm-konsole-etc-td4031905.html From the above thread, http://wiki.freepascal.org/CmdLine popped up which I think of looking at.

Thanks again,

el es

Reply by email

Mark Morgan Lloyd
to Lukasz Sokol
Lukasz Sokol wrote 10 lines
On 31/07/15 14:46, Mark Morgan Lloyd wrote: > Lukasz Sokol wrote: >> Hi, >> >> I tried piecing something like in $topic together, >> >> intended as an 'interactive' command interpreter for my program. >> (which will in time grow an 'embedded' web server and intended to >> run as a (windows) service, but it's too early for that at the >> moment)

Looking at your question another way, I suppose that you also have the issue of parsing a command as well as handling the data entry. I think that there's various possibilities here depending on what you're trying to handle:

* A simple sequence of names/numbers.

* A unix-style command line, with leading options.

* A sequence of email/HTTP headers.

* XML.

* Any of the above but with macro and/or numeric evaluation.

I note in particular that PostgreSQL uses Flex and Bison, and if they'll parse (a fairly comprehensively extended) SQL I guess they'll parse about anything. Apart from that I've hacked something together for my own use based on Smalltalk (as an outer parser) with various evaluation possibilities (as an inner parser), this was intended as a way for programs to talk to each other and has its good points.

I'm not sure whether getopts from the RTL provides a facility for you to feed it an arbitrary string for processing, but it would probably be a good place to start.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Lukasz Sokol
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 19 lines
Lukasz Sokol wrote: > On 31/07/15 14:46, Mark Morgan Lloyd wrote: >> Lukasz Sokol wrote: >>> Hi, >>> >>> I tried piecing something like in $topic together, >>> >>> intended as an 'interactive' command interpreter for my program. (which will in time grow an 'embedded' web server and intended to >>> run as a (windows) service, but it's too early for that at the >>> moment) Looking at your question another way, I suppose that you also have the issue of parsing a command as well as handling the data entry. I think that there's various possibilities here depending on what you're trying to handle: * A simple sequence of names/numbers.

Supposedly this would do, parameters mostly are numbers (but when parsing through a TStringList everything is a string first anyway, so I can define some rules as to which parameter is what type)

* A unix-style command line, with leading options.

Would be nice, however I don't need 'if' or explicitly defined looping instructions...

Show quoted text 6 lines
* A sequence of email/HTTP headers. * XML. * Any of the above but with macro and/or numeric evaluation.

This would be nice to have, some commands could 'substitute' a variable prefixed with a '$' that they find in the rest of cmdline, for their own output (like, running other commands in a sequence, but without explicit conditional commands)

Show quoted text 7 lines
I note in particular that PostgreSQL uses Flex and Bison, and if they'll parse (a fairly comprehensively extended) SQL I guess they'll parse about anything. Apart from that I've hacked something together for my own use based on Smalltalk (as an outer parser) with various evaluation possibilities (as an inner parser), this was intended as a way for programs to talk to each other and has its good points.

Hmm seems way too complicated for my purpose(s) ;) But we'll see,

I'm not sure whether getopts from the RTL provides a facility for you to feed it an arbitrary string for processing, but it would probably be a good place to start.

I'll have a look.

Thank you,

Kind Regards,
el es

Reply by email

Mark Morgan Lloyd
to Lukasz Sokol
Lukasz Sokol wrote 22 lines
On 31/07/15 16:41, Mark Morgan Lloyd wrote: > Lukasz Sokol wrote: >> On 31/07/15 14:46, Mark Morgan Lloyd wrote: >>> Lukasz Sokol wrote: >>>> Hi, >>>> >>>> I tried piecing something like in $topic together, >>>> >>>> intended as an 'interactive' command interpreter for my program. (which will in time grow an 'embedded' web server and intended to >>>> run as a (windows) service, but it's too early for that at the >>>> moment) > Looking at your question another way, I suppose that you also have > the issue of parsing a command as well as handling the data entry. I > think that there's various possibilities here depending on what > you're trying to handle: > > * A simple sequence of names/numbers. > Supposedly this would do, parameters mostly are numbers (but when parsing through a TStringList everything is a string first anyway, so I can define some rules as to which parameter is what type)

Parse the first word to an enumeration, feed that to a case. Leave options for terminating characters, case sensitivity and so on.

> * A unix-style command line, with leading options. Would be nice, however I don't need 'if' or explicitly defined looping instructions...

No, I mean parsing of options starting - or -- together with their parameters. 'if' etc. are part of the shell, so are a distinct issue.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Lukasz Sokol
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 26 lines
Lukasz Sokol wrote: > On 31/07/15 16:41, Mark Morgan Lloyd wrote: >> Lukasz Sokol wrote: >>> On 31/07/15 14:46, Mark Morgan Lloyd wrote: >>>> Lukasz Sokol wrote: >>>>> Hi, >>>>> >>>>> I tried piecing something like in $topic together, >>>>> >>>>> intended as an 'interactive' command interpreter for my program. (which will in time grow an 'embedded' web server and intended to >>>>> run as a (windows) service, but it's too early for that at the >>>>> moment) > >> Looking at your question another way, I suppose that you also have >> the issue of parsing a command as well as handling the data entry. I >> think that there's various possibilities here depending on what >> you're trying to handle: >> >> * A simple sequence of names/numbers. >> > Supposedly this would do, parameters mostly are numbers (but when parsing > through a TStringList everything is a string first anyway, so I can define > some rules as to which parameter is what type) Parse the first word to an enumeration, feed that to a case. Leave options for terminating characters, case sensitivity and so on.

Hmm, yeah, guess I complicated my case 'a bit' by keeping the command/function mapping in a static array... Back to the drawing board ;J

Show quoted text 6 lines
>> * A unix-style command line, with leading options. > > Would be nice, however I don't need 'if' or explicitly defined looping instructions... No, I mean parsing of options starting - or -- together with their parameters. 'if' etc. are part of the shell, so are a distinct issue.

Ah, ok. So , no, that's not needed in my case.

Thanks,
el es

Reply by email