OpenVMS Demos: Programmer's Corner (old)


This entire sub-domain is a private effort of free information.
There are no cookies, no advertisements, and nothing is for sale.

OpenVMS Resources (non-code) can be found here

Caveat:
  1. The programs and information presented on this web site are intended for educational use only for OpenVMS application developers.
  2. The programs and information presented on this web site are provided free of charge.
  3. The programs and information presented on this web site are presented to you as-is. I will not be held responsible in any way if they damage your computer system, business or organization (sounds like the warning from a Microsoft shrink-wrap seal, eh?)
  4. To the best of my knowledge, the programs presented on this web site compile, link and run properly. Please let me know if they don't work and I will attempt to fix them as soon as I find the time (I only support this stuff in my spare time).
  5. Is this text too small? You have two options:
    1. hold down the CTRL key while rolling the mouse wheel (zoom-in, zoom-out)
    2. use your keyboard like so:
      • hit: CTRL with "-" key to zoom smaller
      • hit: CTRL with "+" key to zoom larger
      • hit: CTRL with zero key to reset zoom


Quick Index

OpenVMS Application Demos

On 2011-04-14 I started converting my the zipped demo source code to HTML format. This will make it easier for humans to read AND allow Google to index this stuff (which may help promote OpenVMS programming). In many instances the replacement HTML file is based upon better (more up-to-date) code not previously published. Sometime this year I will be deleting all the zip files. A temporary index of the new files can be found here:
OpenVMS: Source Code in HTML
Click here to view a directory of my zipped files not yet converted

"HP-BASIC for OpenVMS Alpha"

(a.k.a. "Compaq-BASIC for OpenVMS Alpha", "DEC-BASIC")
(should work with no modifications on VAX or Itanium)

Topic Revised Zip
BASIC "File Related" Demos (RMS)  
HP-BASIC for OpenVMS is one of many DEC languages with built-in support for RMS (Record Management Services) which is an ISAM (Indexed Sequential Access Method) technology. Although RMS is not as cool as SQL compliant databases like Oracle, RMS is small, fast and free. I've even used HP-BASIC and RMS to implement quite a number of web-based applications. Click OpenVMS Notes: RMS / Oracle-RDB / MySQL for more information.  
rms_relative_demo.bas demonstrates "RMS based" relative record access with modern error handling. moved to HTML
rms_indexed_demo.bas demonstrates "RMS based" indexed record access with modern error handling. moved to HTML
rms_test_fsp.bas demos opening an unknown file, then uses FSP$ to get more information about it. moved to HTML
rms_test_useropen.bas demos opening an unknown file via a USEROPEN function. moved to HTML
Download a BASIC program to fix "FTP induced SAVESET corruption". Click here for a brief explanation of why this happens. 2001-01-12
sys_file_io_demo.bas demonstrates how to open, write, and read OpenVMS files using system calls like sys$open. moved to HTML
BASIC "File Related" Demos (Oracle-RDB)  
Download a zip containing over 43 files which include:

BASIC Oracle-RDB Demo 1 consists of two very simple BASIC applications to demonstrate how to call SQLMOD procedures to fetch individual RDB records via a cursor. One program uses SQLCODE while the other uses SQLSTATE. (Oracle recommends using SQLSTATE for all new program development)

BASIC Oracle-RDB Demo 2 consists of a more complicated BASIC application to demonstrate how to use "Dynamic SQL" to fetch individual RDB records via a cursor. This program declares then uses SQLDA (SQL Descriptor Area). Programmatically creating and executing SQL statements on the fly is a very powerful tool.

BASIC Oracle-RDB Demo 3 is a collection of programs which:
  1. a program to convert a simple RMS-based database into an RDB-based database (currently consists of only two tables
  2. a program (101) to fetch and display records from the RDB-based database. This demo will build and execute either in GREEN SCREEN mode or with FMS (Forms Management System)
  3. a program (102) which will allow records to be fetched and modified
Common:
  1. Each demo includes a DCL script to build a demo Oracle-RDB database
  2. Each demo includes a DCL script to compile and link the associated application
  3. Some miscellaneous help files and installation log files are included
    Links: Click OpenVMS Notes: RMS + Oracle-RDB + MySQL for more information about Oracle-RDB.
2006-06-27
BASIC Programs calling the I/P Stack (TCPware)
TCPware-ftp-sample.bas demonstrates how to call TCPware FTP Library functions moved to HTML
TCPware-telnet-sample.bas demonstrates how to call TCPware TELNET Library functions to do the following TCP activities:
  1. CHARGEN
  2. DAYTIME
  3. ECHO
  4. TELNET
    • includes an IAC handler to support in-channel NVT (network virtual terminal) handshakes during the TELNET session. These packets are based upon WILL-WONT-DO-DONT and look like this: "IAC DONT ECHO" and "IAC DO SUPPRESS_GA" etc.
    • note that this TELNET function can retrieve a web page if opened on port 80 rather than 23)

Uses: lib$get_ef  lib$free_ef  sys$asctim  sys$bintim  sys$setimr  sys$wflor (wait for any one of these event flags)

moved to HTML
TCPware_smtp_demo.bas to demo TCPware calls for interfacing with an SMTP server on port 23 moved to HTML
TCPware_pop3_demo.bas to demo TCPware calls for interfacing with an POP3 server on port 110 moved to HTML
BASIC Programs calling the I/P Stack (TCP/IP Services for OpenVMS) (a.k.a. UCX Services)  
These two programs demonstrate a sys$qio based TCP client/server application employing TCP/IP Services for OpenVMS (formerly "UCX Services"): Note: I developed these BASIC programs from TCP/IP example programs written in DEC-C, copyrighted in 1989 by "Digital Equipment Corporation" and again in 1998 by "Compaq Computer Corporation"
moved to HTML
BASIC Programs supporting requests from Apache (CSWS-1.3 and SWS-2.x)  
 a CGI program (written in BASIC) which can be used to sit between Apache and your application. Note that the name of all HTML form objects will be prefixed with the string "FORM_FLD_" before being converted to DCL symbols. moved to HTML
apache_demo.bas is a quick hack demo program that shows how to extract information from a web page submitted to Apache for OpenVMS (CSWS/SWS) using CGI (Common Gateway Interface). This program can run in four different modes:
  1. CRT (green screen)
  2. WEB=GET (get info from QUERY_STRING which came from the URI)
  3. WEB=POST (usually, but not always, associated with someone clicking a SUBMIT button)
  4. WEB=GET+POST
It shows how to submit HTML forms. It contains a small amount of RMS code to show how to interface RMS to the WEB. It also shows how to do a JavaScript pop-up window. Click "OpenVMS Notes: Apache" if you need to modify your Apache environment.
moved to HTML
New CGI (Common Gateway Interface) programs which will allow very large files to be uploaded from HTML forms like this:
<form method="post" enctype="multipart/form-data" action="/scripts/upload_test_neil">
  <input type="text"   name="textline">
  <input type="file"   name="datafile">
  <input type="submit" name="Send">
</form>
coming soon
www_password_change.bas is a program that allows OpenVMS passwords to be changed from a dynamically generated web page (HTML). This program will not work as-is until a small amount of code is removed (look for the word "chop"). Apache needs to be running with SYSPRV. (usually a bad thing unless your server is only exposed to a corporate intranet) moved to HTML
BASIC Data Conversion / Data Manipulation  
iso_8859_to_ascii.bas demos how to convert ISO-8859-1 (8-bit) string data to plain ASCII (7-bit) strings. moved to HTML
ebcdic_ascii.bas demos how to convert between EBCDIC and ASCII. moved to HTML
sort_demo.bas demos how to demo how to sort a sequential file using VMS system calls. moved to HTML
Article: Fun with Floating Point Data Types moved to HTML
BASIC "Miscellaneous Stuff"  
View a BASIC include (device_controls.inc) containing escape sequence definitions needed to controlling various devices (VT100, VT200, LA50). Normally you would do this by making calls to the terminal driver but there are times when this approach can be more efficient. moved to HTML
View a BASIC program (population_sim.bas) to generate simple population models based upon selectable parameters like: first age of reproduction, maximum age of population, maximum reproductions per couple, etc. China's one-child program will not shrink the size of their population as fast as many people believe.
Click here to view some sample runs.
moved to HTML
BASIC "Source Code Maintenance"  
Can't download my "Source Code Tools for OpenVMS BASIC" package which contains:
  1. my first attempt at a "source code formatter" for HP-BASIC programs. This program is a great starting point if you need take over maintenance of programs written by less disciplined programmers.
     
    Note: this program was created with the intention of reformatting some very badly written programs by someone who had just left our team (programs too large to rewrite at this time but we still need to be maintained). Now I know why smart companies doing software development have on-going code reviews!
     
    Warning: this program will only work properly if the source program can compile with no errors.
     
  2. my first attempt at a "source code reporter" for HP-BASIC programs. This program is used to extract "dated comments" from source code (we all document our source code, right?). Great for building progress reports destined for your project manager or client.
     
  3. my first attempt at a "source code mover" for HP-BASIC programs. All my programs have a filename of the form "Fancy_Application_1000.BAS" and after 5 updates the sixth one is named "Fancy_Application_1005.BAS". This program is used to move a desired number of old versions to an archive directory. { hopefully your employer has purchased a professionally written and supported "source code repository". I wish I had one. }. Note that the version number embedded in the file name does not need to be 4 digits wide but it does need to be present just before the period in the file extension.
Note: these 3 programs are crude first attempts but they work and I use them all the time. That said, use them at your own risk.
removed
 
BASIC Programs "Demonstrating OpenVMS System Calls"  
Link to another page on this site: Hacking the OpenVMS Starlet library moved to HTML
View two "include files" which will be necessary only if one of my demo programs will not compile on your system.
moved to HTML
dcl_symbols.bas a demo to create/read DCL symbols.
moved to HTML
Programs to demo how to implement programmed time delays like 100 ms and 900 ms.
moved to HTML
vms_mail_send_demo.bas demos how to send VMS MAIL programmatically without using DCL
moved to HTML
vms_mail_forward_demo.bas demos to how to inspect VMS MAIL forwarding moved to HTML
Programs to demo how to manipulate logical names.
moved to HTML
display_system_error.bas demos how to translate OpenVMS numeric return codes into "Message Text". moved to HTML
demo_lock_cef.bas demos how to use CEF (Common Event Flag) locks. moved to HTML
View four programs showing how to call DLM (Distributed Lock Manager)
demo_lock_dlm_100.bas creates a null lock then synchronously converts it to more restrictive forms
demo_lock_dlm_101.bas creates a null lock then synchronously converts it to more restrictive forms
demo_lock_dlm_102.bas asynchronously requests an exclusive lock then polls DLM to see if it was granted
demo_lock_dlm_103.bas asynchronously requests an exclusive lock, then arms a timer, then waits for one of two event flags
moved to HTML
peek_demo.bas is demo which uses a "BASIC function" to PEEK at memory (can be converted to POKE but I can't think why you'd want to). Great for exploring things like dynamic string structures, arrays, etc. Okay so in 2011 I needed to use BASIC to patch a linked-list and so wrote a POKE routine) moved to HTML
foreign_cmd.bas demos how to read command line parameters (similar to the way that "c" programs do) moved to HTML
getjpi_demo.bas a demo on calling lib$getjpi and sys$getjpi (note that sys$ calls require "more setup" than lib$ calls) moved to HTML
View a pair of simple client/server programs, to demo communication through an OpenVMS memory device known as a "mail box".
advocate_client.bas a client program with no-privs which will send DCL requests to the server program (via a VMS mailbox) which does have privs
advocate_server.bas a server program with privs which will receive DCL requests from a client (via a VMS mailbox) with no-privs
advocate_DCL_scripts support scripts to start the programs above

moved to HTML
download a demo program which shows how to call to the terminal driver to disable, then re-enable, the BROADCAST parameter. Can be used as a template for changing any other terminal parameter settings.
Uses: sys$qiow  sys$assign  sys$dassgn  io$_sensemode  io$_setmode  tt$m_nobrdcst  tty2$m_brdcstmbx
moved to HTML
download a demo on calling sys$getqui to do nested wildcard operations on queues. This program was my first attempt at writing a system health monitoring utility. The final version (which will not be put into the public domain) has many more features. moved to HTML 
watchdog.bas iss an inactive terminal watchdog. This program was my first attempt at writing software using OpenVMS system calls. moved to HTML
password_search.bas demos how to search SYSUAF for a lost password.
Note: Please read the following 5 notes on system passwords.
moved to HTML

System Password Notes:

  1. OpenVMS really is "open" because I wrote the afore mentioned program in a about an hour using two OpenVMS system calls (sys$getjpi and sys$hash_password) which are publicly documented here. You need to have system privileges in order to access someone else's hashed password, but nothing could prevent an unscrupulous system manager (or support staff) from using this technique to acquire someone else's password in order to commit a crime using that person's account. This is a big no-no in the world of Sarbanes-Oxley (SOX)
     
  2. My busy little AlphaServer-4100 (EV5/300MHz) averages 1 million guesses in 273 seconds. Since there are 38^6 "six character passwords", a worst case run would require 3,010,936,384 guesses. Divide this number by 1M and you get 3010.9 which then is multiplied by 273 then divided by 3600 to yield 228 hours or 9.5 days. Multiply this figure by 38 for every character added to the six character password, so a seven character password would require 361 days while an eight character password would require 37.5 years thus forcing criminals to look for another method.
     
  3. as a result of this experiment, I've decided to set the minimum password length to 8 on all of my OpenVMS systems via the following command in authorize:
     $set def sys$system
     $run authorize
     uaf>mod * /pwdminimum=8
     exit
     $

    which results in the total number of possible candidate minimum length passwords to be guessed changing from 38^6 (3.01e+9) to 38^8 (4.34e+12). Of course you could always use a larger password and I think I'll do this on my priv accounts. BTW, it might be a good idea to monitor unusual access to SYSUAF using ACL's and $SET AUDIT
     

  4. currently any password you enter is UPCASED before being tested and/or stored. Starting with OpenVMS-7.3-2 an authorize flag named "PWDMIX" to enable case-sensitive and extended-character passwords.
     
  5. password cracking can be sped up considerably by copying the SYSUAF to a PC (you still need OpenVMS system privs to do this) and running a standalone tool. Check out this link for more details (p.s. tools like this are one more reason to enforce longer passwords and enable the "case-sensitive password feature" which will be available with  OpenVMS-7.3-2)

HP-BASIC for OpenVMS VAX

(a.k.a. "Compaq-BASIC for OpenVMS VAX", "Compaq-BASIC for VAX", "VAX-BASIC")

HP-CXX for OpenVMS Alpha
HP-CXX for OpenVMS Itanium
HP-CXX for OpenVMS VAX

(a.k.a. "Compaq-CXX for OpenVMS Alpha", "Compaq-C++", "HP-C++")

HP-C for OpenVMS Alpha
HP-C for OpenVMS Itanium
HP-C for OpenVMS VAX

(a.k.a. "Compaq-C for OpenVMS Alpha", "Compaq-C for OpenVMS VAX", "DEC-C")

Note: VAX-C was phased out prior to VMS 6.0 and replaced with DEC-C. Don't do any new program development with VAX-C.

Noteworthy "C" demos at other sites (my "C" hacks are nowhere near professional quality):

Noteworthy "C" articles:

  • C Traps and Pitfalls :: Andrew Koenig :: AT&T Bell Laboratories
    • http://www.literateprogramming.com/ctraps.pdf
    • quote: The C language is like a carving knife: simple, sharp, and extremely useful in skilled hands. Like any sharp tool, C can injure people who don’t know how to handle it. This paper shows some of the ways C can injure the unwary, and how to avoid injury.
 
Topic revised
view four demo programs to experiment with LDAP
1) one demo is meant to test an unauthenticated LDAP connection
2) one demo is meant to test an authenticated LDAP connection
moved to HTML
Two demo programs from Process Software Corporation
1) smtp-check.c is a demo used to "test an SMTP" connection
2) http-check.c is a demo used to "test an HTTP" connection
moved to HTML
ebcdic-ascii-demo.c is a stub that demos data conversions from EBCDIC to ASCII and back moved to HTML
getuai.c is a stub that calls SYS$GETUAI moved to HTML
vms_lock_dlm.c is a DLM (Distributed Lock Manager) demo  
view two repaired versions of Compaq's QIO client/server examples (from TCPIP$EXAMPLES in  OpenVMS-7.2). The originals crash when run. moved to HTML
Web Page Hit Counter (2.4 + 2.6)
  • Muhammad Muquit is the author of a very cool multi-platform 'Hit Counter' which is currently run by many large ISPs in the world (if you don't believe me, just intercept a digit display GIF then look inside where you'll see his name and URL in the comments area)
  • Phil Ottewell ported Muhammad's Hit Counter v2.4 to OpenVMS for use with Ohio State University's  OSU DECthreads HTTP Server
  • I've modified Phil's code to work with Process Software Corp's Purveyor 2.x Encrypt Web Server and the code is available at here). BTW,  I also inserted calls to the OpenVMS Distributed Lock Manager to prevent the counter data file from becoming locked out due to multiple process requiring exclusive write access.
    • If you don't believe this can happen, set up a demo web page with 20 image references to the same counter like so:
                <img src="http://www.your-site.tld/cgi-bin/Count.cgi?dd=D|df=your-counter.dat|sh=1|incr=1" ><br>
    • now publish the web page to your ISP so you've got maximum CPU power and network bandwidth
    • now access the web page and watch the counters get displayed in your browser
    • now add another 10 images references and repeat the whole process. I've discovered that the counter data file will become permanently locked out by the ISP when the number of images exceeds 32 (according to www.netcraft.com one site was running Netscape-Enterprise/4.1 over Solaris while another was Microsoft-IIS/4.0 over Windows-NT4). BTW, before my patch you would never see a permanent lockout on an OpenVMS system; just the odd counter GIF not being displayed. My Distributed Lock Manager routines make sure that every request gets honored so the odd GIF will just pop in a few milliseconds late. No big deal but that is what's so neat about OpenVMS.
  • 2002-04-30: Hit Counter v2.6 for Purveyor and OSU DECthreads HTTP is available by anonymous FTP from ftp://ftp.pottsoft.com
  • 2003-05-23: I've got a pre-release of Hit Counter v2.6 for Compaq Secure Web Server version 1.3.26 (a.k.a. CSWS, or Apache for OpenVMS) working on my AlphaServer-DS20. It will be made public very soon.
 

DCL (Digital Control Language a.k.a. DEC Control Language)

Topic Revised
DECnet task-to-task communications  
moved to HTML
Uncategorized Stuff (will be categorized soon)  
  • download a DCL program which demos a way to quickly delete many files (since VMS directories are sorted, you do not want to delete from the beginning of the list)
     
  • download a DCL program ("ENV_CHECK.COM") to check environmental temperatures, fan speeds and power supplies on Alpha platforms. It uses undocumented DCL lexicals like:
    • f$getsyi("thermal_vector")
    • f$getsyi("fan_vector")
    • f$getsyi("power_vector")
    • f$getsyi("thermal_vector")
    Note: non-priv users aren't able to execute the DCL Lexical SYS$GETSYI
    I think this program will also run on Itanium platforms.
    Click here http://www.parsec.com/openvms/undocumented.php for more undocumented OpenVMS features.
     
  • download a DCL program ("ENV_CHECK_101.COM") to check environmental temperatures, fan speeds and power supplies on Alpha platforms. This program is a tweaked version of ("ENV_CHECK.COM") for use with your the LOGIN.COM scripts of your privileged users.
 

M32 (a.k.a. "Macro for OpenVMS VAX", "Macro-32")

M64 (a.k.a. "Macro for OpenVMS Alpha", "Macro for OpenVMS Itanium", "Macro-64")

My 2 cents worth about "HP-BASIC for OpenVMS Alpha"

Back in 1987 my employer selected VAX-BASIC as the programming language for our department. Although I would have been more comfortable with Pascal or Modula, I quickly discovered that VAX-BASIC is much more useful than I first thought. Even though the BASIC acronym still means "Beginner's All-purpose Symbolic Instruction Code", this product includes many features borrowed from Pascal and FORTRAN and has features that are well beyond most beginners. Here is a short list of features showing this BASIC implementation is better than most
  1. Native (built-in) support for RMS-based files including sequential, relative and indexed.
    Yes, you can develop non-SQL compliant databases.
     
  2. Like Pascal, run-time errors can (if desired) be handled locally with WHEN ERROR blocks rather than using a common handler like "ON ERROR GOTO". But you can use both methods if you desire.
     
  3. Enforced variable declaration can be achieved with the directive "OPTION TYPE=EXPLICIT"
     
  4. SELECT CASE statements seem much more readable than compound "IF THEN" - "ELSE" - "END IF"
     
  5. Line numbers are not required (unless you reference the BASIC function "ELN")
     
  6. Interpreter mode is only available on VAX
     
  7. When Microsoft shifted from VB6 to VB.net, their implementation of BASIC became more object-oriented. VMS-BASIC is still very procedural.

The Name Game

Some Really Neat Compiler Changes for Alpha:
  1. Compile mode only; no interpreter (I do not consider this a problem)
     
  2. The Alpha compiler does much better code optimization than VAX so if you weren't really careful while creating code for VAX just recompiling for Alpha will provide you with compile-time speed improvements. For example, the following two programs (example 2a and 2b) generate different object code on VAX but generate the same optimized object code on Alpha even when compiled with optimization=level=0 (none).
     			! example 2a (written by a careless VAX programmer).
    1000 a% = 3 ! the VAX compiler produces CISC code to convert 3 from real to integer at runtime
    b% = 4 ! the VAX compiler produces CISC code to convert 4 from real to integer at runtime
    print a% + b% ! end program 1 ! return -s- to DCL

    ! example 2b (written by a careful VAX programmer).
    1000 a% = 3% ! both compilers generate code which represents an integer 3
    b% = 4% ! both compilers generate code which represents an integer 4
    print a% + b% !
    end program 1 ! return -s- to DCL
  3. However, running the Alpha compiler with optimization=level=4 (full) would yield the following equivalent program:
     			! example 3 (why add the variables if you don't have to?)
    1000 print "7"		! the compiler added 3 to 4 "at compile time" so only this I/O statement was required
         end program 1	! return -s- to DCL
  4. Here's another example program which yields radically different object files on VAX compared to Alpha.
    1000 option type=explicit	! example 4
         declare long i%		!
         for i% = 1 to 100		! should be "1% to 100%" on VAX; Alpha doesn't care because long was declared
             print i%		!
         next i%			!
         end program 1		!

    If you compile with optimization=level=4 and used a smaller loop, the Alpha compiler might decide to just generate a series of PRINT statements. This is called "loop unrolling".

  5. So-called "DEC languages" targeted at Alpha and Itanium are based upon the "GEM Optimizing Compiler System". GEM is a project code-name rather than an acronym. Everything coming out of DEC in those days had names like GEM, Emerald, Opal, etc.
    A Few GEM links:
    1. http://www.hpl.hp.com/hpjournal/dtj/vol4num4/vol4num4art8.pdf
    2. http://h71000.www7.hp.com/openvms/journal/v5/portingmacrocompiler.html

Other Noteworthy Applications

Intercepting OpenVMS Mail Delivery (using DELIVER)

Intercepting OpenVMS Mail Delivery (using PMDF)

External Links:


Back to Home
Neil Rieck
Kitchener - Waterloo - Cambridge, Ontario, Canada.