OS/2, eCS & ArcaOS - Technical > Programming

different types of keyboard input in cmd.exe

(1/2) > >>

Martin Vieregg:
I have recognized another tricky problem for my cmd.exe frontend: The types of keyboard input

There are in my opinion three types of keyboard input which have to be handled different in my editor:

(1) Prompt: The user types input after a prompt, can edit it and sends the input to cmd.exe by pressing ENTER. Before pressing ENTER, cmd.exe does not see any input at all.

(2) program read input: A commandline program requests user input, e.g. a Y/N query, or a string. This input is also finished by pressing ENTER.

An important difference between (1) and (2): In (1), cmd.exe echos the input as stdout. (4os2 does not.)

(3) Collecting text lines via "COPY CON": The editor collects several lines of user input and the input is finished by typing Ctrl-Z. After pressing Ctrl-Z, all lines incl. line end characters (^M^J) are sent to cmd.exe in one step.

In type (3), both cmd.exe and 4os2.exe does not allow to edit the previous lines, you cannot use the up cursor key. (But I will manage this.)

Stdin/out programs always require ENTER after a user input. VIO programs also allow a single keyboard key to continue processing.

My PM editor frontend needs to know which of the three types of keyboard input is current. To distinguish between (1) and (2), I analyze the prompt string which is shown at the beginning of the line.

My question concerns the type (3) "COPY CON": I need to interpretate the command which the user types behind the prompt. My first idea is to search for "<space>CON<space>" ? Which example commands do you have where this type of edit mode gets activated?

Sergey Posokhov:
The only useful command I still remember is "print device driver report":
  copy ibms506$ con:
:)

Laurence Pithie:

--- Quote ---My question concerns the type (3) "COPY CON": I need to interpretate the command which the user types behind the prompt. My first idea is to search for "<space>CON<space>" ?
--- End quote ---
You'll need to search for COPY followed by CON because there are other contexts in which CON is used (redirection for example). Doing that in a robust way is going to require dealing with an arbitrary number of spaces and text (filenames for example)  between the COPY and the CON so I would suggest using a regular expression.

However the command shell expects line oriented input, so if you send a line containing COPY CON then the shell will then read input on stdin line by line and echo that input on stdout, up until  it receives an EOF, which you're writing and reading stdin and stdout already anyway.

If what you wish to do is send an arbitrary block of text, possibly containing newlines, as an argument to an arbitrary command then I would suggest using a separate command to do that. Something along the lines of a send marked block command.

If you are doing all this command line processing before sending a line to the command processor you're not really creating a command line front end, you are implementing half a command processor and  duplicating  functions that the shell already implements. If that's what you want to do then you should look at examples of scanners and parsers. In the C world there are tools for creating these, Lexx and Yacc (Flex and Bison) Free Pascal comes with Plex and Pyacc. Using specialised tools for this is advisable because, while creating a scanner and parser isn't complicated it's not trivial , and creating an efficient scanner and parser is definitely not an exercise for the faint of heart. 

Martin Vieregg:
Laurence,

yes, I have to distinguish between the two directions to CON or from CON, and there's the notation "CON:" with semicolon. So "COPY CON" should fit the purpose, and I will delete obsolete spaces before.


--- Quote ---However the command shell expects line oriented input, so if you send a line containing COPY CON then the shell will then read input on stdin line by line and echo that input on stdout, up until  it receives an EOF, which you're writing and reading stdin and stdout already anyway.
--- End quote ---

Yes, you are right and I was wrong. This simple test in cmd.exe shows the behaviour:


--- Code: ---[Z:\]copy con test.txt
one
two
three^C

[Z:\]type test.txt
one
two

[Z:\]
--- End code ---

But the behaviour in my editor when running cmd.exe as an "input to output compiler" without own window output is different:


--- Code: ---[Z:\]copy con test.txt
one
two
^Cree

[Z:\]one
SYS1041: The name one is not recognized as an internal or external command, operable program or batch file.

[Z:\]two
SYS1041: The name two is not recognized as an internal or external command, operable program or batch file.
[Z:\]

--- End code ---

I have no idea why the behaviour differs. I am sending "one" and "two" with carriage return + line feed to cmd.exe and nothing happens.


My intension is to have a behaviour close as possible to cmd.exe. It is a good idea to implement an editor functionality with a new unique command like "editz" , or you start an external editor.

Later, beta testing will find out the cases where the behaviour differs from cmd.exe and which I have not programmed yet. I can test it only for my own purpose, and everyone uses cmd.exe in a different way.

Laurence Pithie:
There's another case that you'll have to handle that COPY CON will not.

--- Code: ---COPY filename.txt CON

--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version