[an error occurred while processing this directive]

HP OpenVMS Systems

ask the wizard
Content starts here

C Programming on OpenVMS?

» close window

The Question is:

 
Hi,
I am trying to get symbol using lib$get_symbol.
 
But, I don't know how use this function from C program.
 
Unfortunatly, I am new to this.
 
 
 


The Answer is :

 
  The easiest way to use C to acquire a symbol value would be via the
  C getenv function.  This function will retrieve information from the
  CLI about a logical name or a symbol that matches the specified name.
  This call is also portable.
 
  It is however useful to know the basics of calling OpenVMS run-time
  library (RTL) functions such as LIB$GET_SYMBOL.  Details on calling
  OpenVMS RTL functions and system services can be found in the Compaq
  C User's Guide for OpenVMS Systems manual, and in the OpenVMS
  Programming Concepts manual, and in the OpenVMS FAQ (particularly
  for an introduction to string descriptors), and in numerous source
  code examples on the OpenVMS Freeware and on the OpenVMS website.
 
  The following C source code example has had the angle brackets replaced
  with square brackets for viewing via HTML (certain web browsers can
  misinterprete the angle brackets commonly found in C code as HTML tags),
  but otherwise shows how to call both LIB$GET_SYMBOL and getenv:
 
#include [descrip.h]
#include [lib$routines.h]
#include [stdio.h]
#include [stdlib.h]
#include [string.h]
#include [stsdef.h]
 
#define MAXSYM 255
main(int argc, char *argv[])
  {
  int status;
  unsigned short returned_length = 0;
  char returned_string[MAXSYM+1];
  struct dsc$descriptor_s output_descriptor = { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, NULL };
  $DESCRIPTOR(symbol_descriptor, "SYMBOL") ;
 
  output_descriptor.dsc$w_length = MAXSYM;
  output_descriptor.dsc$a_pointer = returned_string;
 
  status = lib$get_symbol( &symbol_descriptor, &output_descriptor, &returned_length ) ;
  if (!$VMS_STATUS_SUCCESS( status ))
    return status;
 
  if (returned_length)
    printf("The symbol value is %.*s\n", returned_length, returned_string);
 
  strcpy( returned_string, getenv( "SYMBOL" ));
 
  if (strlen( returned_string ))
    printf("The symbol (or logical name) value is %s\n", returned_string );
 
  return status ;
  }
 

answer written or last revised on ( 20-MAR-2001 )

» close window