/* This is an example of a license authorization system service call for a
product licensed with an activity license. The SYS$GRANT_LICENSE checks
whether the current users of the license in the system number more than the
license units. If the current number of users is less than the license units,
the system returns the success status SS$_NORMAL. If the current number
of users of the license in the system is greater than the license units, the
system returns the error status LICENSE$_EXCEEDED. If the license is not
authorized, the system returns the error status LICENSE$_NOLICENSE.
*/

#include <descrip.h>
#include <lib$routines.h>
#include <lmfdef.h>
#include <ssdef.h>
#include <starlet.h>
#include <stddef.h>
#include <stdio.h>
#include <stsdef.h>

#include descrip
#include stsdef

#define LMF$_PROD_DATE 4
#define LMF$_PROD_TOKEN 1

typedef struct _quad_word {
	long int upper_long;
	long int lower_long;
} quad_word;

main()

{
long status;
quad_word product_date;
short *tokenlen;
char prtoken[31];

struct {
 short itm$w_buflen ;
 short itm$w_code ;
 char *itm$a_addr ;
 short *itm$a_lenaddr ;
} grant_license_items[] = {
sizeof (quad_word), LMF$_PROD_DATE, (char *)&product_date, 0,
31, LMF$_PROD_TOKEN, prtoken, &tokenlen,
0, 0, 0, 0
};

static $DESCRIPTOR (product_name, "FORTRAN");
static $DESCRIPTOR (product_owner, "DEC");
static $DESCRIPTOR (product_date_string, "1-APR-1998 0:0:0.0");

/* Use SYS$BINTIM to convert the ASCII string representing the
the date to an absolute or delta time value. */

status = SYS$BINTIM(&product_date_string, &product_date);
if ((status & 1) != 1) return (status);

/* Call the SYS$GRANT_LICENSE system service and store
the return status. */

status = SYS$GRANT_LICENSE(&product_name, &product_owner, 0,
	&grant_license_items);

	/* Test whether the current number of license users in the system
	is greater than the license units. */

	if (status == LICENSE$_EXCEEDED)
	  { /* process the busy condition */
	    /* if desired */
	  }
	else
	  if (!status)
		return (status);

	/* otherwise it is authorized, use product token... */
}
