Discussion:
C Examples of Calling SMG$ Routines?
(too old to reply)
Zane H. Healy
2021-06-27 17:13:04 UTC
Permalink
In looking at the "OpenVMS RTL Screen Management (SMG$) Manual" on the VSI
website, they give examples of every language supported, except C/C++. The
manual itself says it's new as of 2019, but also says it's for HP OpenVMS
VAX/Alpha 7.3. :-) Looking at my copy of the manual for v6, all they did
was remove the code for "RPG II".

Does anyone happen to have some basic examples of using the SMG$ Routines in
C? As it happens, the example does just what I need, since it shows how to
use SMG$READ_KEYSTROKE.

Thanks,
Zane
Stephen Hoffman
2021-06-27 18:30:06 UTC
Permalink
Post by Zane H. Healy
In looking at the "OpenVMS RTL Screen Management (SMG$) Manual" on the
VSI website, they give examples of every language supported, except
C/C++. The manual itself says it's new as of 2019, but also says it's
for HP OpenVMS VAX/Alpha 7.3. :-) Looking at my copy of the manual
for v6, all they did was remove the code for "RPG II".
Does anyone happen to have some basic examples of using the SMG$
Routines in C? As it happens, the example does just what I need, since
it shows how to use SMG$READ_KEYSTROKE.
Yeah, past whatever is in SYS$EXAMPLES, the OpenVMS doc tends to have
gaps. (The "the OpenVMS doc is great!" crowd always goes silent right
about now, too.)

If you have support, ask VSI. They're starting up a support database
offering with examples. Having just checked, they do not yet have an
example of smg$read_keystroke. The predecessor to the VSI database, the
DEC/Compaq/HP TIMA/STARS/AskQ database—which did have lots of source
code examples—is long gone.

The worst of that batch of SMG calls is probably the smg$create_menu
call, and the OpenVMS developers have yet to add an example of that
one, or an example of implementing command-line recall from what I can
find of it. That might be a starting point for you.

https://www.digiater.nl/openvms/decus/vax91b/bzl/smg_in_c/subprocess.c

As you don't indicate what you're looking for a keystroke read for, and
unless you're already using SMG (possibly for command recall or such,
though that's not well documented), a $qio call is the approach I'd use:

https://www.digiater.nl/openvms/freeware/v80/hoffman_examples/qio_extended_read_2.c

https://www.digiater.nl/openvms/freeware/v80/hoffman_examples/qio_extended_read_3.c


Here are some other SMG examples:

http://svn.csrri.iit.edu/mx/branches/1.4/motor/command.c
https://www.digiater.nl/openvms/decus/vax91b/bzl/smg_in_c/

Alas, I don't see a C example of smg$read_keystroke anywhere, and the
eight-cubed source code example coverage doesn't include SMG.
--
Pure Personal Opinion | HoffmanLabs LLC
Zane H. Healy
2021-06-27 19:07:46 UTC
Permalink
Post by Stephen Hoffman
Post by Zane H. Healy
In looking at the "OpenVMS RTL Screen Management (SMG$) Manual" on the
VSI website, they give examples of every language supported, except
C/C++. The manual itself says it's new as of 2019, but also says it's
for HP OpenVMS VAX/Alpha 7.3. :-) Looking at my copy of the manual
for v6, all they did was remove the code for "RPG II".
Does anyone happen to have some basic examples of using the SMG$
Routines in C? As it happens, the example does just what I need, since
it shows how to use SMG$READ_KEYSTROKE.
Yeah, past whatever is in SYS$EXAMPLES, the OpenVMS doc tends to have
gaps. (The "the OpenVMS doc is great!" crowd always goes silent right
about now, too.)
If you have support, ask VSI. They're starting up a support database
offering with examples. Having just checked, they do not yet have an
example of smg$read_keystroke. The predecessor to the VSI database, the
DEC/Compaq/HP TIMA/STARS/AskQ database?which did have lots of source
code examples?is long gone.
The worst of that batch of SMG calls is probably the smg$create_menu
call, and the OpenVMS developers have yet to add an example of that
one, or an example of implementing command-line recall from what I can
find of it. That might be a starting point for you.
https://www.digiater.nl/openvms/decus/vax91b/bzl/smg_in_c/subprocess.c
As you don't indicate what you're looking for a keystroke read for, and
unless you're already using SMG (possibly for command recall or such,
https://www.digiater.nl/openvms/freeware/v80/hoffman_examples/qio_extended_read_2.c
https://www.digiater.nl/openvms/freeware/v80/hoffman_examples/qio_extended_read_3.c
http://svn.csrri.iit.edu/mx/branches/1.4/motor/command.c
https://www.digiater.nl/openvms/decus/vax91b/bzl/smg_in_c/
Alas, I don't see a C example of smg$read_keystroke anywhere, and the
eight-cubed source code example coverage doesn't include SMG.
Thank you for the detailed writeup and list of links! Keith Halewood got me
the basic answer I needed, and it looks like your examples should take me
much further. The last link, with the example programs look especially
useful!

I was already reading SMGDEF.H, which gets me the rest of what I needed.

For someone looking for an smg$create_menu example, they might want to try
reading through the DX sourcecode. I'd been trying to use it to figure out
SMG$READ_KEYSTROKE command, and noticed the code for the menues.

Thanks,
Zane
David Jones
2021-06-27 22:14:16 UTC
Permalink
Post by Stephen Hoffman
Alas, I don't see a C example of smg$read_keystroke anywhere, and the
eight-cubed source code example coverage doesn't include SMG.
Thank you for the detailed writeup and list of links! Keith Halewood got me
the basic answer I needed, and it looks like your examples should take me
much further. The last link, with the example programs look especially
useful!
I've found in practice you need to tread carefully when trying to use SMG$READ_KEYSTROKE
as a drop in replacement for another OS's 'getch' type functions. By 'keystroke', it means it's
going to try to recognize escape sequences from keyboard function keys and such (e.g.
SMG$K_TRM_UP for the up arrow).

My linenoise() library emulation I use for the SQLite port calls SMG$READ_KEYSTROKE in
some situations (input lines > terminal width), but it's not a simple example. To do cursor
navigation, I have to get the starting screen position, but if there something in the typeahead
buffer is confuses SMG, so I precede that call with a flush of the typeahead buffer, saving
the contents. The read_keypress() returns the saved typeahead characters before it starts
calling SMG$READ_KEYSTROKE.
Zane H. Healy
2021-07-01 23:46:28 UTC
Permalink
Post by David Jones
I've found in practice you need to tread carefully when trying to use
SMG$READ_KEYSTROKE as a drop in replacement for another OS's 'getch' type
functions. By 'keystroke', it means it's going to try to recognize escape
sequences from keyboard function keys and such (e.g. SMG$K_TRM_UP for the
up arrow).
The program I'm writing only runs on VMS, so it should be fine. At least I
hope so. :-)

Zane

Jim Duff
2021-06-27 22:27:20 UTC
Permalink
[snip]
Does anyone happen to have some basic examples of using the SMG$
Routines in C?  As it happens, the example does just what I need,
since it shows how to use SMG$READ_KEYSTROKE.
[snip]
Alas, I don't see a C example of smg$read_keystroke anywhere, and the
eight-cubed source code example coverage doesn't include SMG.
Uhhh SMG$ routines. I don't cover MTH$/CLI$/BACKUP$/DCX$/CONV$/TPU$/etc
routines either :)

Jim
Craig A. Berry
2021-06-27 19:02:06 UTC
Permalink
Post by Zane H. Healy
In looking at the "OpenVMS RTL Screen Management (SMG$) Manual" on the VSI
website, they give examples of every language supported, except C/C++. The
manual itself says it's new as of 2019, but also says it's for HP OpenVMS
VAX/Alpha 7.3. :-) Looking at my copy of the manual for v6, all they did
was remove the code for "RPG II".
Does anyone happen to have some basic examples of using the SMG$ Routines in
C? As it happens, the example does just what I need, since it shows how to
use SMG$READ_KEYSTROKE.
I have a readpassphrase() implementation based on SMG$READ_COMPOSED_LINE:

https://github.com/FreeTDS/freetds/blob/master/vms/getpass.c

There is a Perl extension (necessarily implemented in C) that provides
SMG interfaces:

<https://metacpan.org/pod/smg>

This one doesn't look familiar to me. I think there was a different one
circulating at some point but I can't find it now.
Jilly
2021-06-28 14:39:20 UTC
Permalink
Post by Zane H. Healy
In looking at the "OpenVMS RTL Screen Management (SMG$) Manual" on the VSI
website, they give examples of every language supported, except C/C++. The
manual itself says it's new as of 2019, but also says it's for HP OpenVMS
VAX/Alpha 7.3. :-) Looking at my copy of the manual for v6, all they did
was remove the code for "RPG II".
Does anyone happen to have some basic examples of using the SMG$ Routines in
C? As it happens, the example does just what I need, since it shows how to
use SMG$READ_KEYSTROKE.
Thanks,
Zane
Lots of C examples at
http://www.eight-cubed.com and
http://www.eight-cubed.com/examples/framework.php?file=sys_hash_pwd.c has
SMG$READ_KEYSTROKE in it.
cao...@pitbulluk.org
2021-06-28 15:59:31 UTC
Permalink
Post by Zane H. Healy
In looking at the "OpenVMS RTL Screen Management (SMG$) Manual" on the VSI
website, they give examples of every language supported, except C/C++. The
manual itself says it's new as of 2019, but also says it's for HP OpenVMS
VAX/Alpha 7.3. :-) Looking at my copy of the manual for v6, all they did
was remove the code for "RPG II".
Does anyone happen to have some basic examples of using the SMG$ Routines in
C? As it happens, the example does just what I need, since it shows how to
use SMG$READ_KEYSTROKE.
Thanks,
Zane
For completeness from your cross-posting, here's a really minimal example:

#include <ssdef.h>
#include <descrip.h>
#include <smgdef.h>
#include <smg$routines.h>
#include <stdio.h>
#include <starlet.h>
#include <string.h>

main(void)
{
unsigned vkbd, stat;
short keycode;

stat = smg$create_virtual_keyboard(&vkbd,0,0,0,0);

stat = smg$read_keystroke(&vkbd,&keycode,0,0,0,0,0);
printf("%d\n",keycode);

stat = smg$delete_virtual_keyboard(&vkbd);

}

SYS$INPUT is assumed when the 2nd parameter of smg$create_virtual_keyboard is null (otherwise you need a string descriptor reference there).
smg$read_keystroke waits for a single keypress (single char or VT-style escape sequence representing PFx, keypad, etc., or a timeout indication) if you've specified a timeout longword reference for the 4th parameter.

The <smg$routines.h> are in the sys$library:sys$startlet_c.tlb as is everything else. It's interesting to note that all of the function prototypes have '__unknown_params' as their parameter so you really do need the documentation. This seems rather lazy of DEC.

I write a BLISS-32 macro library for SMG a while back if anybody is interested. I still prefer it to C.

Sorry.
Ian Miller
2021-07-01 14:15:17 UTC
Permalink
Post by Zane H. Healy
In looking at the "OpenVMS RTL Screen Management (SMG$) Manual" on the VSI
website, they give examples of every language supported, except C/C++. The
manual itself says it's new as of 2019, but also says it's for HP OpenVMS
VAX/Alpha 7.3. :-) Looking at my copy of the manual for v6, all they did
was remove the code for "RPG II".
Does anyone happen to have some basic examples of using the SMG$ Routines in
C? As it happens, the example does just what I need, since it shows how to
use SMG$READ_KEYSTROKE.
Thanks,
Zane
Many moons ago I wrote a small C program which you can find in rk.zip at http://eisner.decus.org/~miller/ which reads a key using SMG$READ_KEYSTROKE and puts the result in a DCL symbol.
Loading...