OpenVMS Source-Code Demos

VT_SMG_DEMO

//==============================================================================================================================
// title    : vt_smg_demo_100.c
// author   : Neil Rieck  ( http://neilrieck.net/ )
// created  : 2015-05-03
// purpose  : to demo old "school i/o" to a vt-terminal
// reference: http://h41379.www4.hpe.com/doc/73final/5935/5935pro.html -- OpenVMS RTL Screen Management (SMG$) Manual
//	    : sys$library:c$starlet.txt (search for: smgdef)
// caveat   : learning to write programs employing 100+ "SMG$ calls" may be as difficult as learning to program with 200+ "FDV$
//		calls" (and may not be worth the investment of your time in 2015). SMG-based programming is procedural which may
//		add an undesired amount of per-user overhead to your system. Unless you need to support fancy smaller scrolling
//		sections or line graphics, you may wish to consider embedding escape sequences directly into your output data
//		stream.
// build    : cc   vt_smg_demo_100
//	    : link vt_smg_demo_100
// run-1    : run  vt_smg_demo_100
// run-2    : $'f$environment("default")'VT_SMG_DEMO_100
//	    : yada 0.25
// history  :
// ver who when   what
// --- --- ------ --------------------------------------------------------------------------------------------------------------
// 100 NSR 150503 original effort
//==============================================================================================================================
//
//	stuff for OpenVMS
//
#if defined(VMS)								// for VMS and OpenVMS only
#define __NEW_STARLET	1							// enable strict for OpenVMS Alpha 7.0 and later
#include <starlet.h>								// OpenVMS stuff
#include <lib$routines.h>							// defines functions like: lib$wait
#include <libwaitdef.h>								// defines constants like: lib$k_vax_f
#include <stddef.h>								//
#include <smg$routines.h>							//
#include <smgdef.h>								//
#include <smgmsg.h>								//
#include <descrip.h>								// vms string descriptors
#endif
//
//	common stuff
//
#include <stdio.h>								//
#include <stdlib.h>								// atof
#include <string.h>								//
//
//	define a few constants
//
static $DESCRIPTOR(lab1des, "SMG EXAMPLE 1");
static $DESCRIPTOR(lab2des, "SMG EXAMPLE 2");
static $DESCRIPTOR(msg1des, "Normal text: abcdefghijklmnopqrstuvwxyz");
static $DESCRIPTOR(msg2des, "Text with CR: \r, LF: \n, VT: \v, FF: \f");
//
//	decterm colors
//
#define DTC$M_BLACK    SMG$M_USER1
#define DTC$M_BLUE     SMG$M_USER2
#define DTC$M_CYAN     SMG$M_USER3
#define DTC$M_GREEN    SMG$M_USER4
#define DTC$M_MAGENTA  SMG$M_USER5
#define DTC$M_ORANGE   SMG$M_USER6
#define DTC$M_WHITE    SMG$M_USER7
#define DTC$M_YELLOW   SMG$M_USER8
//
//	forward declarations
//
void nsr_delay(float);								//
//
//==============================================================================
//
//	main()	"the big kahuna"
//
//==============================================================================
void main(int argc, char *argv[]) {
    int			rc;
    unsigned int	pasteboard1, display1;
    struct		dsc$descriptor_s byedes;
    float		delay;
    //--------------------------------------------------------------------------
    printf("pgm: %s\n",argv[0]);
    printf(" 1) assuming your terminal driver is vt300 or higher with color enabled\n");
    printf(" 2) $ set term/device=vt300\n");
    printf(" 3) $ set term/color\n");
    printf(" 4) assuming color is enabled on your terminal or terminal emulator\n");
    delay = 0.25;
    if (argc==1){
	printf("-i- arg#1 not found so defaulting delay to 0.25\n");
    }else{
	delay = atof(argv[1]);
	printf("-i- delay set to %.2f seconds\n",delay);
    }
    nsr_delay(2.0);
    //--------------------------------------------------------------------------
    printf("starting...\n");
    rc = SMG$CREATE_PASTEBOARD(&pasteboard1);
    //
    //	create virtual display1 (12 lines by 40 characters)
    //
    rc = SMG$CREATE_VIRTUAL_DISPLAY(&12, &40, &display1,&(SMG$M_BLOCK_BORDER|SMG$M_DISPLAY_CONTROLS));
    nsr_delay(delay);
    //
    rc = SMG$PASTE_VIRTUAL_DISPLAY(&display1, &pasteboard1, &2, &2);
    nsr_delay(delay);
    //
    rc = SMG$LABEL_BORDER(&display1, &lab1des, &SMG$K_TOP, NULL,&DTC$M_YELLOW);
    nsr_delay(delay);
    //
    rc = SMG$PUT_LINE(&display1, &msg1des, NULL, &DTC$M_GREEN);	//
    nsr_delay(delay);
    //
    rc = SMG$PUT_LINE(&display1, &msg2des, NULL, &DTC$M_BLUE);	//
    nsr_delay(delay);
    //
    /* Build descriptor at run-time */
    byedes.dsc$w_length = 3;
    byedes.dsc$b_dtype = DSC$K_DTYPE_T;
    byedes.dsc$b_class = DSC$K_CLASS_S;
    byedes.dsc$a_pointer = "Bye";
    rc = SMG$PUT_CHARS_WIDE(&display1, &byedes, &3, &8, &(SMG$M_BLINK|DTC$M_YELLOW));
    nsr_delay(delay);
    //
    /* Re-use by changing length and pointer (only):- */
    byedes.dsc$w_length = 4;
    byedes.dsc$a_pointer = "-bye";
    rc = SMG$PUT_CHARS_HIGHWIDE(&display1, &byedes, &4, &11,&(SMG$M_BLINK|SMG$M_BOLD|DTC$M_CYAN));
    nsr_delay(delay);
    //
    rc = SMG$SET_CURSOR_ABS(&display1, &10, &1);
    nsr_delay(delay);
}

//======================================================================
//	nsr_delay(float)
//======================================================================
//
#if defined(VMS)							// for VMS and OpenVMS
//----------------------------------------------------------------------
//	this next bit of voodoo ensures we are using the correct float type on
//	various hardware platforms: VAX, Alpha, Itanium
//
#if __G_FLOAT != 0
#	define  FLOAT_TYPE  LIB$K_VAX_F
#elif __D_FLOAT != 0
#	define  FLOAT_TYPE  LIB$K_VAX_D
#elif __IEEE_FLOAT != 0
#	define  FLOAT_TYPE  LIB$K_IEEE_S
#else
#	error "Try specifying a floating point qualifier on the compile"
#endif
//
//	delay for the desired number of milliseconds
//
void nsr_delay(float fp_delay) {					//
    int rc;								//
    rc = lib$wait(&fp_delay,0,&FLOAT_TYPE);				//
}
#else									// for non-VMS systems
//
void nsr_delay(float fp_delay) {					//
    sleep(1);								//
}									//
#endif
//======================================================================