Initializing help system before first use

Working with models and accessing dynamic libraries in Mosel


Type: Programming
Rating: 4 (medium-difficult)
Description: mmexlib.c: Working with models and accessing dynamic libraries in Mosel (requires burglari.bim, chess2.bim, trans.bim)
  • load and unload BIM models
  • run a model in Mosel
  • display information about loaded models
  • display information about additional libraries required by the loaded models
mmdispmod.c: Display the contents of a model; the information is read from a bim file
  • display run-time parameters, requirements, symbols, package/module dependencies, annotations
mmdispdso.c: Display the contents of a module
  • display constants, types, control paramters, subroutines, I/O drivers
Note that these examples require the provided mos files to be pre-compiled.
File(s): mmexlib.c, mmdispmod.c, mmdispdso.c
Data file(s): burglari.mos, chess2.mos, trans.mos


mmexlib.c
/********************************************************/
/*  Mosel Library Examples                              */
/*  ======================                              */
/*                                                      */
/*  file mmexlib.c                                      */
/*  ``````````````                                      */
/*  Example for the use of the Mosel libraries          */
/*  (working with models and accessing the dynamic      */
/*  libraries loaded by Mosel)                          */
/*                                                      */
/*  (c) 2008 Fair Isaac Corporation                     */
/*      author: S. Heipcke, 2001                        */
/********************************************************/

#include <stdio.h>
#include "xprm_rt.h"

int main()
{
 XPRMmodel mod;
 XPRMdsolib dso;
 const char *name,*syscom,*usrcom;
 int version,vmaj,vmin,vrel;
 int number,i;
 size_t size;

 i=XPRMinit();
 if((i!=0)&&(i!=32))                                   /* Initialize Mosel */
  return 1;

 if(XPRMloadmod("Models/burglari.bim",NULL)==NULL)     /* Load the BIM file */
  return 3;
 
 if(XPRMloadmod("Models/chess2.bim",NULL)==NULL)       /* Load the BIM file */
  return 5;

 if(XPRMloadmod("Models/trans.bim",NULL)==NULL)        /* Load the BIM file */
  return 7;
 
 printf("Models loaded:\n");
 mod = NULL;
 while((mod=XPRMgetnextmod(mod)) != NULL) /* Enumerate all loaded models */
 {                                      /* Get information about the models */
  XPRMgetmodprop(mod,XPRM_PROP_NAME,(XPRMalltypes *)&name);
  XPRMgetmodprop(mod,XPRM_PROP_ID,(XPRMalltypes *)&number);
  XPRMgetmodprop(mod,XPRM_PROP_SYSCOM,(XPRMalltypes *)&syscom);
  XPRMgetmodprop(mod,XPRM_PROP_USRCOM,(XPRMalltypes *)&usrcom);
  XPRMgetmodprop(mod,XPRM_PROP_SIZE,(XPRMalltypes *)&size);
  if(syscom==NULL) syscom="";
  if(usrcom==NULL) usrcom="";
  printf("  %d: %s (%s, `%s') size: %lu\n",number, name, syscom, usrcom,
         (unsigned long)size);
 }

 printf("Additional libraries loaded:\n");
 dso = NULL;
 while((dso=XPRMgetnextdso(dso)) != NULL) /* Enumerate loaded libraries */
 {                                      /* Get information about libraries */
  XPRMgetdsoprop(dso,XPRM_PROP_NAME,(XPRMalltypes *)&name);
  XPRMgetdsoprop(dso,XPRM_PROP_VERSION,(XPRMalltypes *)&version);
  XPRMgetdsoprop(dso,XPRM_PROP_NBREF,(XPRMalltypes *)&number);
  vmaj=(int)(version/1000000);
  vrel=version%1000000;
  vmin=(int)(vrel/1000);
  vrel%=1000;
  printf("  %s (version %d.%d.%d) used by %d model(s)\n",
         name, vmaj,vmin,vrel,number);
 }

 mod = XPRMfindmod(NULL, 2);              /* Get model with sequence number 2 */
 XPRMunloadmod(mod);                      /* Unload the model */
 printf("Unload model 2.\n");

 XPRMflushdso();                          /* Unload unused libraries */
 
 printf("Models loaded:\n");
 mod = NULL;
 while((mod=XPRMgetnextmod(mod)) != NULL) /* Enumerate all loaded models */
 {                                      /* Get information about the models */
  XPRMgetmodprop(mod,XPRM_PROP_NAME,(XPRMalltypes *)&name);
  XPRMgetmodprop(mod,XPRM_PROP_ID,(XPRMalltypes *)&number);
  XPRMgetmodprop(mod,XPRM_PROP_SYSCOM,(XPRMalltypes *)&syscom);
  XPRMgetmodprop(mod,XPRM_PROP_USRCOM,(XPRMalltypes *)&usrcom);
  if(syscom==NULL) syscom="";
  if(usrcom==NULL) usrcom="";
  printf("  %d: %s (%s, `%s')\n",number, name, syscom, usrcom);
 }

 printf("Additional libraries loaded:\n");
 dso = NULL;
 while((dso=XPRMgetnextdso(dso)) != NULL) /* Enumerate loaded libraries */
 {                                      /* Get information about libraries */
  XPRMgetdsoprop(dso,XPRM_PROP_NAME,(XPRMalltypes *)&name);
  XPRMgetdsoprop(dso,XPRM_PROP_NBREF,(XPRMalltypes *)&number);
  printf("  %s used by %d model(s)\n", name,number);
 }
 
 return 0;
}

mmdispmod.c
/********************************************************/
/*  Mosel Library Examples                              */
/*  ======================                              */
/*                                                      */
/*  file mmdispmod.c                                    */
/*  ````````````````                                    */
/*  Example for the use of the Mosel libraries          */
/*  (display the contents of a model)                   */
/*                                                      */
/*  (c) 2021 Fair Isaac Corporation                     */
/*      author: Y. Colombani, 2006                      */
/********************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "xprm_rt.h"

/* To decode version number */
#define VMAJ(r) (int)(r/1000000)
#define VMIN(r) (int)((r%1000000)/1000)
#define VREL(r) (int)((r%1000000)%1000)

/* Maximum number of annotations */
#define MAXANN 64

void dispfulltype(XPRMmodel mod,int t);
void dispval(int type,XPRMalltypes *value,int rts);
void dispprocfct(XPRMmodel mod,const char *name,const char *parms, int type);
void disptyp(XPRMmodel mod,const char **c);
void dispannot(const char *symb,const char *ann[],int n);

int main(int argc,const char *argv[])
{
 XPRMmodel mod;
 XPRMproc proc;
 XPRMalltypes value;
 void *ref,*data;
 const char *symb,*parms;
 int type,nbpar;
 int i,n;
 const char *ann[MAXANN*2];

 if(argc!=2)
 {
  printf("Usage: %s modname.bim\n",argv[0]);
  return 0;
 }
 else
 {
  i=XPRMinit();
  if((i!=0)&&(i!=32))                    /* Initialize Mosel */
   return 1;
 
  if((mod=XPRMloadmod(argv[1],NULL))!=NULL)
  {
   XPRMgetmodprop(mod,XPRM_PROP_NAME,(XPRMalltypes *)&symb);
   XPRMgetmodprop(mod,XPRM_PROP_VERSION,(XPRMalltypes *)&i);
   XPRMgetmodprop(mod,XPRM_PROP_SYSCOM,(XPRMalltypes *)&parms);
   printf("%s `%s' version %d.%d.%d\n",
                            (strncmp("PKG",parms,3)==0)?"Package":"Model",
                            symb,VMAJ(i),VMIN(i),VREL(i));

   printf("Parameters:\n");              /* List of parameters */
   ref=NULL;
   while((symb=XPRMgetnextparam(mod,&ref))!=NULL)
    printf(" %s\n",symb);
   printf("\n");
 
   printf("Requirements:\n");            /* List of requirements */
   ref=NULL;
   while((ref=XPRMgetnextreq(mod,ref,&symb,&type,&data))!=NULL)
    switch(XPRM_STR(type))
    {
     case XPRM_STR_REF:                    /* Reference: display type */
     case XPRM_STR_SET:                    /* Set: display type */
     case XPRM_STR_LIST:                   /* List: display type */
        printf(" %s: ",symb);
        dispfulltype(mod,type);
        printf("\n");
        break;
     case XPRM_STR_ARR:                    /* Array: display type */
        printf(" %s: array(%s) of ",symb,(char *)data);
        dispfulltype(mod,XPRM_TYP(type));
        printf("\n");
        break;
     case XPRM_STR_PROC:                   /* Subroutine */
        XPRMgetprocinfo((XPRMproc)data,&parms,&nbpar,&type);
        dispprocfct(mod,symb,parms,type);/* Display prototype */
        break;
     default:
        printf(" %s: ?\n",symb);
    }
   printf("\n");
 
   printf("Symbols:\n");
   ref=NULL;                             /* List of symbols */
   while((symb=XPRMgetnextident(mod,&ref))!=NULL)
   {
    type=XPRMfindident(mod,symb,&value);   /* Get information for the symbol */
    switch(XPRM_STR(type))
    {
     case XPRM_STR_CONST:                  /* Constant: display value */
        printf(" %s=",symb);
        dispval(type,&value,1);
        break;
     case XPRM_STR_REF:                    /* Reference: display type */
     case XPRM_STR_ARR:                    /* Array: display type */
     case XPRM_STR_SET:                    /* Set: display type */
     case XPRM_STR_LIST:                   /* List: display type */
        printf(" %s: ",symb);
        dispfulltype(mod,type);
        printf("\n");
        break;
     case XPRM_STR_PROC:                   /* Subroutine */
        proc=value.proc;
        do                              /* Look for all overloading proc/func */
        {
         XPRMgetprocinfo(proc,&parms,&nbpar,&type);
         dispprocfct(mod,symb,parms,type); /* Display prototype */
        }while((proc=XPRMgetnextproc(proc))!=NULL);
        break;
     case XPRM_STR_UTYP:                   /* User type */
        if(symb[0]=='&') break;
        printf(" %s: ",symb);
        if(XPRM_STR(value.integer)==XPRM_STR_REC)
        {
         XPRMgettypeprop(mod,type,XPRM_TPROP_NAME,(mm_alltypes *)&parms);
         if(!strcmp(parms,symb))
         {
          void *ref2;

          ref2=XPRMgetnextfield(mod,NULL,type,&parms,&i,&nbpar);
          if(ref2!=NULL)
          {
           printf("a record type publishing:\n");
           while(ref2!=NULL)
           {
            printf("    %s:",parms);
            dispfulltype(mod,XPRM_TYP(i));
            printf("\n");
            ref2=XPRMgetnextfield(mod,ref2,type,&parms,&i,&nbpar);
           }
          }
          else
           printf("a record type\n");
         }
         else
          printf("a user defined type (=%s)\n",parms);
        }
        else
         if(XPRM_STR(value.integer)==XPRM_STR_UNION)
         {
          printf("a union type (=");
          dispfulltype(mod,XPRM_TYP(type));
          printf(")\n");
         }
        else
         if(XPRM_STR(value.integer)==XPRM_STR_PROB)
         {
          printf("a problem type (=");
          dispfulltype(mod,XPRM_TYP(type));
          printf(")\n");
         }
        else
         if(XPRM_STR(value.integer)==XPRM_STR_PROC)
         {
          printf("a subroutine type (=");
          dispfulltype(mod,XPRM_TYP(type));
          printf(")\n");
         }
         else
         {
          printf("a user defined type (=");
          dispfulltype(mod,value.integer);
          printf(")\n");
         }
        break;
     case XPRM_STR_NTYP:                   /* Native type */
        break;
     default:
        printf(" %s: ?\n",symb);
    }
   }
   printf("\n");
 
   printf("Dependencies:\n");            /* List of required pkgs/modules */
   ref=NULL;
   while((ref=XPRMgetnextdep(mod,ref,&symb,&i,&type))!=NULL)
   {
    printf(" %s %s (%d.%d.%d)\n",type?"package":"module",symb,
                                 VMAJ(i),VMIN(i),VREL(i));
   }
   printf("\n");

   printf("Annotations:\n");            /* List of annotations */
   n=XPRMgetannotations(mod,NULL,NULL,ann,MAXANN*2);
   if(n>0) dispannot("[global]",ann,n);
   ref=NULL;                             /* List of symbols */
   while((symb=XPRMgetnextanident(mod,&ref))!=NULL)
   {
    n=XPRMgetannotations(mod,symb,NULL,ann,MAXANN*2);
    dispannot(symb,ann,n);
   }
  }
 }
 return 0;
}

/***********************/
/* Display a type name */
/***********************/
void dispfulltype(XPRMmodel mod,int t)
{
 switch(XPRM_STR(t))
 {
  case XPRM_STR_CONST:
  case XPRM_STR_REF:
    switch(XPRM_TYP(t))
    {
      case XPRM_TYP_INT: printf("integer"); break;
      case XPRM_TYP_REAL: printf("real"); break;
      case XPRM_TYP_STRING: printf("string"); break;
      case XPRM_TYP_BOOL: printf("boolean"); break;
      case XPRM_TYP_MPVAR: printf("mpvar"); break;
      case XPRM_TYP_LINCTR: printf("linctr"); break;
      default:
        {
         XPRMalltypes expn;
         int pbid,tid,firstdone;
         void *ref;

         if(XPRMgettypeprop(mod,XPRM_TYP(t),XPRM_TPROP_EXP,&expn)||
            (XPRM_STR(expn.integer)==XPRM_STR_REC)||
            (XPRM_STR(expn.integer)==XPRM_STR_PROB)||
            (XPRM_STR(expn.integer)==XPRM_STR_UNION)||
            (XPRM_STR(expn.integer)==XPRM_STR_PROC))
         {
          XPRMgettypeprop(mod,t,XPRM_TPROP_PBID,(mm_alltypes *)&pbid);
          if(pbid>=0)                   /* this is a problem type */
          {
           ref=NULL;
           firstdone=0;
           while((ref=XPRMgetnextpbcomp(mod,ref,t,&tid))!=NULL)
            if(tid==0)
            {
             printf("mpproblem");
             firstdone=1;               /* this one is always the first */
            }
            else
            {
             if(firstdone)
              printf("+");
             else
              firstdone=1;
             XPRMgettypeprop(mod,XPRM_TYP(tid),XPRM_TPROP_NAME,&expn);
             printf("%s",expn.string);
            }
          }
          else
          if(XPRM_STR(expn.integer)==XPRM_STR_UNION)
          {
           ref=XPRMgetnextuncomptype(mod,NULL,t,&tid);
           dispfulltype(mod,XPRM_TYP(tid));
           while((ref=XPRMgetnextuncomptype(mod,ref,t,&tid))!=NULL)
           {
            printf(" or ");
            if(tid==0)
             printf("any");
            else
             dispfulltype(mod,XPRM_TYP(tid));
           }
          }
          else
          if(XPRM_STR(expn.integer)==XPRM_STR_PROC)
          {
           XPRMalltypes p,rt;

           XPRMgettypeprop(mod,XPRM_TYP(t),XPRM_TPROP_SIGN,&p);
           XPRMgettypeprop(mod,XPRM_TYP(t),XPRM_TPROP_EXP,&rt);
           dispprocfct(mod,NULL,p.string,XPRM_TYP(rt.integer));
          }
          else
          {
           XPRMgettypeprop(mod,XPRM_TYP(t),XPRM_TPROP_NAME,&expn);
           printf("%s",expn.string);
          }
         }
         else
          dispfulltype(mod,expn.integer);
        }
    }
    break;
  case XPRM_STR_ARR:
    printf("array of ");
    dispfulltype(mod,XPRM_TYP(t));
    break;
  case XPRM_STR_SET:
    printf("set of ");
    dispfulltype(mod,XPRM_TYP(t));
    break;
  case XPRM_STR_LIST:
    printf("list of ");
    dispfulltype(mod,XPRM_TYP(t));
    break;
  case XPRM_STR_CSREF:
    printf("constant ");
    dispfulltype(mod,XPRM_TYP(t));
    break;
  default:
    printf("?");
 }
}

/*******************/
/* Display a value */
/*******************/
void dispval(int type,XPRMalltypes *value,int rts)
{
 switch(XPRM_TYP(type))
 {
  case XPRM_TYP_INT: printf("%d",value->integer);break;
  case XPRM_TYP_REAL: printf("%g",value->real);break;
  case XPRM_TYP_STRING: printf("`%s'",value->string!=NULL?value->string:"");
                        break;
  case XPRM_TYP_BOOL: printf("%s",value->boolean==0?"false":"true");break;
  default: printf("?");
 }
 if(rts) printf("\n");
}

/***************************************/
/* Diplay a prototype from a signature */
/***************************************/
void dispprocfct(XPRMmodel mod,const char *name,const char *parms, int type)
{
 const char *c;

 if(name!=NULL)
 {
  if(XPRM_TYP(type)!=XPRM_TYP_NOT)
   printf(" function %s",name);
  else
   printf(" procedure %s",name);
 }
 else
  printf("%s",(XPRM_TYP(type)!=XPRM_TYP_NOT)?"function":"procedure");

 if((parms!=NULL)&&(parms[0]!='\0'))
 {
  printf("(");
  c=parms;
  while(*c!='\0')
  {
   if(c>parms) printf(",");
   disptyp(mod,&c);
   c++;
  }
  printf(")");
 }

 if(XPRM_TYP(type)!=XPRM_TYP_NOT)
 {
  printf(":");
  dispfulltype(mod,XPRM_TYP(type));
 }
 if(name!=NULL) printf("\n");
}

/****************************************/
/* Display a type name from a signature */
/****************************************/
void disptyp(XPRMmodel mod,const char **c)
{
 const char *s;

 switch(**c)
 {
  case 'i': printf("integer");break;
  case 'r': printf("real");break;
  case 's': printf("string");break;
  case 'b': printf("boolean");break;
  case 'v': printf("mpvar");break;
  case 'c': printf("linctr");break;
  case 'I': printf("range");break;
  case 'a': printf("array");break;
  case 'e': printf("set");break;
  case 'l': printf("list");break;
  case 'u': printf("any");break;
  case '%':
        {
         char tn[4];

         (*c)++;
         tn[0]=(*(*c)++);
         tn[1]=(*(*c)++);
         tn[2]=(*(*c));
         tn[3]='\0';
         dispfulltype(mod,(int)strtol(tn,NULL,16));
         break;
        }
  case '|':
        (*c)++;
        do
        {
         printf("%c",**c);
         (*c)++;
        } while(**c!='|');
        break;
  case '!':
        (*c)++;
        do
        {
         printf("%c",**c);
         (*c)++;
        } while(**c!='!');
        break;
  case 'A':
        printf("array (");
        s=++(*c);
        while(**c!='.')
        {
         if(s!=*c) printf(",");
         disptyp(mod,c);
         (*c)++;
        }
        printf(") of ");
        (*c)++;
        disptyp(mod,c);
        break;
  case 'E':
        printf("set of ");
        (*c)++;
        disptyp(mod,c);
        break;
  case 'L':
        printf("list of ");
        (*c)++;
        disptyp(mod,c);
        break;
  case '*':
        printf("...");
        break;
  default: printf("?");
 }
}

/*********************************/
/* Display a list of annotations */
/*********************************/
void dispannot(const char *symb,const char *ann[],int n)
{
 int i;

 printf(" %s->\n",symb);
 for(i=0;i<n && i<MAXANN;i+=2)
  printf("   %s:%s\n",ann[i],(ann[i+1]!=NULL)?ann[i+1]:"");
}

mmdispdso.c
/********************************************************/
/*  Mosel Library Examples                              */
/*  ======================                              */
/*                                                      */
/*  file mmdispdso.c                                    */
/*  ````````````````                                    */
/*  Example for the use of the Mosel libraries          */
/*  (display the contents of a module)                  */
/*                                                      */
/*  (c) 2008 Fair Isaac Corporation                     */
/*      author: Y. Colombani, 2001                      */
/********************************************************/

#include <stdio.h>
#include <string.h>
#include "xprm_rt.h"

/* To decode version number */
#define VMAJ(r) (int)(r/1000000)
#define VMIN(r) (int)((r%1000000)/1000)
#define VREL(r) (int)((r%1000000)%1000)

const char *rwstatus(int t);
const char *typnam(int t);
void dispval(int type,XPRMalltypes *value,int rts);
void dispprocfct(const char *name,const char *parms, int type);
void disptyp(const char **c);

int main(int argc,char *argv[])
{
 XPRMdsolib dsolib;
 void *ref;
 const char *name,*parms,*comm,*path;
 int nbpar,type,priority;
 XPRMalltypes value;
 int i;
 unsigned int flag;

 if(argc!=2)
 {
  printf("Usage: %s libname\n",argv[0]);
  return 0;
 }
 else
 {
  i=XPRMinit();
  if((i!=0)&&(i!=32))                   /* Initialize Mosel */
   return 1;
 
  if((dsolib=XPRMpreloaddso(argv[1]))!=NULL)
  {
   XPRMgetdsoprop(dsolib,XPRM_PROP_VERSION,(XPRMalltypes *)&i);
   XPRMgetdsoprop(dsolib,XPRM_PROP_SYSCOM,(XPRMalltypes *)&comm);
   XPRMgetdsoprop(dsolib,XPRM_PROP_PATH,(XPRMalltypes *)&path);
   XPRMgetdsoprop(dsolib,XPRM_PROP_PRIORITY,(XPRMalltypes *)&priority);
   printf("Module `%s' version %d.%d.%d (%s)\n",
          argv[1],VMAJ(i),VMIN(i),VREL(i),(comm!=NULL)?comm:"");
   printf("File: %s/%s.dso\n",path,argv[1]);
   printf("Priority: %d\n",priority);
   ref=NULL;
   printf("Constants:\n");              /* List of constants */
   while((ref=XPRMgetnextdsoconst(dsolib,ref,&name,&type,&value))!=NULL)
   {
    printf(" %s=",name);                /* Display the value */
    dispval(type,&value,1);
   }
   printf("\n");

   ref=NULL;
   printf("Types:\n");              /* List of types */
   while((ref=XPRMgetnextdsotype(dsolib,ref,&name,&flag))!=NULL)
   {
    printf(" %s (",name);                /* Display the name */
    if(flag&XPRM_MTP_CREAT) printf("create");
    if(flag&XPRM_MTP_DELET) printf(",delete");
    if(flag&XPRM_MTP_PROB) printf(",problem");
    if(flag&XPRM_MTP_RFCNT) printf(",refcnt");
    if(flag&XPRM_MTP_TOSTR) printf(",tostring");
    if(flag&XPRM_MTP_PRTBL) printf("+");
    if(flag&XPRM_MTP_FRSTR) printf(",fromstring");
    if(flag&XPRM_MTP_TFBIN) printf(",bin");
    if(flag&XPRM_MTP_SHARE) printf(",share");
    if(flag&XPRM_MTP_ORD)   printf(",ord");
    if(flag&XPRM_MTP_CONST) printf(",const");
    if(flag&XPRM_MTP_ORSET) printf(",reset");
    if(flag&XPRM_MTP_COPY)  printf(",copy");
    if(flag&XPRM_MTP_APPND) printf("+");
    printf(")\n");
   }
   printf("\n");

   ref=NULL;
   printf("Control Parameters:\n");     /* List of control parameters */
   while((ref=XPRMgetnextdsoparam(dsolib,ref,&name,&comm,&type))!=NULL)
    if((comm!=NULL)&&(comm[0]!='\0'))
     printf(" %s: %s (%s,%s)\n",name,typnam(type),comm,rwstatus(type));
    else                                /* Display type and access rights */
     printf(" %s: %s (%s)\n",name,typnam(type),rwstatus(type));
   printf("\n");

   ref=NULL;
   printf("Procedure and functions:\n");/* Subroutines: show the prototype */
   while((ref=XPRMgetnextdsoproc(dsolib,ref,&name,&parms,&nbpar,&type))!=NULL)
    dispprocfct(name,parms,type);
   printf("\n");

   ref=NULL;
   printf("I/O drivers:\n");            /* IO drivers */
   do
   {
    do
     ref=XPRMgetnextiodrv(ref,&name,&parms,&comm);
    while((ref!=NULL)&&((parms==NULL)||(strcmp(parms,argv[1]))));
    if(ref!=NULL)
     printf(" %s:%s\n",name,comm!=NULL?comm:"");
   }while(ref!=NULL);
  }
 }
 return 0;
}

/************************************************/
/* Return the r/w status of a control parameter */
/************************************************/
const char *rwstatus(int t)
{
 if(t&XPRM_CPAR_READ)
 {
  if(t&XPRM_CPAR_WRITE)
   return "r/w";
  else
   return "r";
 }
 else
  if(t&XPRM_CPAR_WRITE)
   return "w";
  else
   return "?";
}

/**********************/
/* Return a type name */
/**********************/
const char *typnam(int t)
{
 switch(XPRM_TYP(t))
 {
  case XPRM_TYP_INT: return "integer";
  case XPRM_TYP_REAL: return "real";
  case XPRM_TYP_STRING: return "string";
  case XPRM_TYP_BOOL: return "boolean";
  case XPRM_TYP_MPVAR: return "mpvar";
  case XPRM_TYP_LINCTR: return "linctr";
  default: return "?";
 }
}

/*******************/
/* Display a value */
/*******************/
void dispval(int type,XPRMalltypes *value,int rts)
{
 switch(XPRM_TYP(type))
 {
  case XPRM_TYP_INT: printf("%d",value->integer);break;
  case XPRM_TYP_REAL: printf("%g",value->real);break;
  case XPRM_TYP_STRING: printf("`%s'",value->string!=NULL?value->string:"");break;
  case XPRM_TYP_BOOL: printf("%s",value->boolean==0?"false":"true");break;
  default: printf("?");
 }
 if(rts) printf("\n");
}

/***************************************/
/* Diplay a prototype from a signature */
/***************************************/
void dispprocfct(const char *name,const char *parms, int type)
{
 const char *c;
 char ext_typnam[128];
 int i;

 if(XPRM_TYP(type)!=XPRM_TYP_NOT)
  printf(" function %s",name);
 else
  printf(" procedure %s",name);

 if((parms!=NULL)&&(parms[0]!='\0'))
 {
  c=parms;
  if(XPRM_TYP(type)==XPRM_TYP_EXTN)
  {
   i=0;
   do
   {
    ext_typnam[i++]=*c;
    c++;
   } while(*c!=':');
   ext_typnam[i]='\0';
   c++;
   parms=c;             /* Do not display the 1st ',' */
  }
  if(*c!='\0')
  {
   printf("(");
   while(*c!='\0')
   {
    if(c>parms) printf(",");
    disptyp(&c);
    c++;
   }
   printf(")");
  }
 }

 if(XPRM_TYP(type)!=XPRM_TYP_NOT)
  printf(":%s\n",(XPRM_TYP(type)==XPRM_TYP_EXTN)?ext_typnam:typnam(type));
 else
  printf("\n");
}

/****************************************/
/* Display a type name from a signature */
/****************************************/
void disptyp(const char **c)
{
 const char *s;

 switch(**c)
 {
  case 'i': printf("integer");break;
  case 'r': printf("real");break;
  case 'S':
  case 's': printf("string");break;
  case 'b': printf("boolean");break;
  case 'v': printf("mpvar");break;
  case 'c': printf("linctr");break;
  case 'I': printf("range");break;
  case 'a': printf("array");break;
  case 'e': printf("set");break;
  case 'l': printf("list");break;
  case '|':
        (*c)++;
        do
        {
         printf("%c",**c);
         (*c)++;
        } while(**c!='|');
        break;
  case '!':
        (*c)++;
        do
        {
         printf("%c",**c);
         (*c)++;
        } while(**c!='!');
        break;
  case 'A':
        printf("array (");
        s=++(*c);
        while(**c!='.')
        {
         if(s!=*c) printf(",");
         disptyp(c);
         (*c)++;
        }
        printf(") of ");
        (*c)++;
        disptyp(c);
        break;
  case 'E':
        printf("set of ");
        (*c)++;
        disptyp(c);
        break;
  case 'L':
        printf("list of ");
        (*c)++;
        disptyp(c);
        break;
  case '*':
        printf("...");
        break;
  default: printf("?");
 }
}


© 2001-2025 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.