OpenVMS Source Code Demos

HELLO_OPENVMS_WORLD_MORE.C

//================================================================================================
// title    : hello_openvms_world_more.c
// author   : Neil Rieck
// created  : 1999-09-30
// purpose  : test new DECC compiler on AlphaServer 4100
// vms build: cc   hello_openvms_world_more /warn=noinfo
//          : link hello_openvms_world_more
// DCL prep : test = f$environment("DEFAULT")
//          : yada = "$"+ test +"hello_openvms_world_more"
// DCL  run : yada 123 456 789
//================================================================================================
#define __NEW_STARLET	1			// enable new (strict) starlet for OpenVMS Alpha 7.0 and later
#include <stdio.h>				// standard i/o
#include <stdlib.h>				// standard library
#include <lib$routines.h>			// lib routines from starlet
#include <descrip.h>				// string descriptors
//
int main(int argc, char *argv[])		//
{   int counter;				//
    printf("Hello OpenVMS World!\n");		//
    for (counter=1;counter<=3;counter++){	// loop 1 to 3
	printf(" count: %d\n",counter);
    }
    printf("\nCommand Line Arguments:\n");	//
    printf("total number: %d\n",argc);		//
    for (counter=0;counter<argc;counter++){
	printf(" arg %d : %s\n",counter,argv[counter]);
    }
    //
    // "getenv" is a quick way to provide UNIX compatibility
    // "getenv" first checks the logical tables. If nothing
    // is found, then the CLI symbol tables are checked
    //
    printf("\nEnvironmentals (part 1):\n");	//
    printf("HOME: %s\n",getenv("HOME"));	//
    printf("TERM: %s\n",getenv("TERM"));	//
    printf("PATH: %s\n",getenv("PATH"));	//
    printf("USER: %s\n",getenv("USER"));	//
    printf("ABC : %s\n",getenv("ABC"));		//
    printf("abc : %s\n",getenv("abc"));		//
    //=========================================================================
    //	messing around with DCL symbols
    //=========================================================================
    printf("\nEnvironmentals (part 2):\n");	//
    //
    // String Notes:
    //
    //	"c" strings are a null-terminated sequence of characters
    //  vms strings are based upon a 64-bit string descriptor like so:
    //		16-bits: current string length
    //		 8-bits: atomic data type
    //		 8-bits: descriptor class
    //		32-bits: pointer to address of buffer
    //
    int rc;
    char my_buffer[255+1];		// reserve a byte for trailing null
    char my_symbol[255+1];		//
    char my_logical[255+1];		//
    int symbol_table_kind;		//
    my_buffer[0] = '\0';		// init
    //
    // LIB$GET_SYMBOL(symbol,resultant-string [,resultant-length] [,table-type-indicator]
    //
    struct dsc$descriptor_s my_buffer_dsc = {	sizeof (my_buffer) - 1,
						DSC$K_DTYPE_T,
						DSC$K_CLASS_S,
						my_buffer		};
    struct dsc$descriptor_s my_symbol_dsc = {	sizeof (my_symbol) - 1,
						DSC$K_DTYPE_T,
						DSC$K_CLASS_S,
						my_symbol		};
    //
    sprintf(my_symbol,"%s","ABC");
    my_symbol_dsc.dsc$w_length = (int) strlen(my_symbol);
    rc = lib$get_symbol(	&my_symbol_dsc,
				&my_buffer_dsc,
				&my_buffer_dsc.dsc$w_length,
				&symbol_table_kind);
    if ((rc & 7)==1){
	printf("%s : %s\n",my_symbol,my_buffer);
    }else{
	printf("%s : %s\n",my_symbol,"BLANK");
    }
    //=========================================================================
    //	messing around with logical names
    //=========================================================================
    printf("\nEnvironmentals (part 3):\n");	//
    struct dsc$descriptor_s my_logical_dsc = {	sizeof (my_logical) - 1,
						DSC$K_DTYPE_T,
						DSC$K_CLASS_S,
						my_logical		};
    //
    sprintf(my_logical,"%s","SYS$LOGIN");
    //
    // LIB$GET_LOGICAL  logical-name [,resultant-string] [,resultant-length]
    //		[,table-name] [,max-index] [,index] [,acmode] [,flags]
    //
    my_logical_dsc.dsc$w_length = strlen(my_logical);
    rc = lib$get_logical(	&my_logical_dsc,
				&my_buffer_dsc,
				&my_buffer_dsc.dsc$w_length );
    if ((rc & 7)==1){
	printf("%s : %s\n",my_logical,my_buffer);
    }else{
	printf("%s : %s\n",my_logical,"BLANK");
    }
    //
    //	the return code is stored in DCL symbol $STATUS ("$sho sym $STATUS")
    //
    // notes   : in the UNIX world, exiting with 0 means okay (anything else is usually an error)
    //           in the VMS world, the exit code is a little more complicated like so:
    //           0 000 warning
    //           1 001 success
    //           2 010 error
    //           3 011 informatinal
    //           4 100 fatal
    //           5 101 undefined
    //           6 110 undefined
    //           7 111 undefined
    return 1;					// exit with vms success
}