Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

Example

The following C program has the functions listed below:

  1. Open a subroutine access (INIT)

  2. Incorporate a file as a member (ADD)

  3. Search the directory for a member (TOCPRIM)

  4. Open a member (OPENGET)

  5. Read a member record by record (GET)

  6. Close the member (CLOSE)

  7. Terminate a subroutine access (END)

To make the example easier to understand, comments have been included.

/* ********************************************************************* */
/*                                                                       */
/*                    EXAMPLE OF LMS AS A SUBROUTINE                     */
/*                                                                       */
/* ********************************************************************* */
#include <stdlib.h>
#include <stdio.h> 
#include <string.h>    /* INCLUDE member for copy and other functions */
#include <lms.h>       /* INCLUDE member for LMS structures */
main()
{
  /* Assign and initialize parameter structures */
   struct lmsc_cb cb;  /* Assign parameter structures for cb */
   struct lmsc_ed ed;  /* Assign parameter structures for ed */
   struct lmsc_em em;  /* Assign parameter structures for em */
   struct lmsc_ei ei;  /* Assign parameter structures for ei */
   struct lmsc_fd fd;  /* Assign parameter structures for fd */
   struct lmsc_ld ld;  /* Assign parameter structures for ld */
   struct lmsc_rd rd;  /* Assign parameter structures for rd */
   int tid=1;           /* Initialize the TOC identification */
   char buffer[200];    /* Buffer length of ER; required for GET */
   char temp[100];      /* Buffer for copying for output */
   char * ptemp;        /* Pointer to this buffer */
   cb = lmsc_cb_proto;   /* Initialize control block CB */
   ed = lmsc_ed_proto;   /* Initialize member description */
   em = lmsc_em_proto;   /* Initialize member mask */
   ei = lmsc_ei_proto;   /* Initialize member information */
   fd = lmsc_fd_proto;   /* Initialize file information */
   ld = lmsc_ld_proto;   /* Initialize library description */
   rd = lmsc_rd_proto;   /* Initialize record description */
/* ******************************************************************** */
/*                                                                      */
/*  1. Open a subroutine access with INIT                               */
/*                                                                      */
/* ******************************************************************** */
   cb.function = LMSUP_INIT ;
   cb.subcode  = LMSUP_UNUSED ;
   lmsup1(&cb);
    /* Evaluate return code */
    if (cb.retcode != LMSUP_OK)
      {
       /* An error has occurred -  issue message and terminate program */
         printf("Error during initialization \n");
         exit(1);
      }
    else
         printf("Initialization successfully terminated \n");
/* ******************************************************************** */
/*                                                                      */
/*  2. Incorporate a file with ADD                                      */
/*                                                                      */
/* ******************************************************************** */
   cb.function=LMSUP_ADD;
   cb.subcode =LMSUP_UNUSED;
   /*     Assign the necessary values for ADD                        */
   /*                                                                */
   /* Note that the arguments to be copied must end with a blank     */
   /* if they are shorter than the target field.                     */
    strfill(ld.name,"#BSP.LIB.C",sizeof(ld.name));
                               /* Assign library name            */
    strfill(fd.name,"#BSP.IN.INPUT",sizeof(fd.name));
                               /* Assign file name               */
    strfill(ed.name,"BSP.ELEMENT",sizeof(ed.name));
                               /* Assign member name             */
    strfill(ed.version,"001",sizeof(ed.version));
                               /* Assign member version          */
    strfill(ed.typ,"S",sizeof(ed.typ));
                               /* Assign member type             */
    /* Program call */
    lmsup1(&cb,&fd,&ld,&ed);
    /* Evaluate return code */
    if (cb.retcode != LMSUP_OK)
     {
       /* An error has occurred - issue message and terminate program */
        printf("Error when incorporating member \n");
        exit(1);
     }
    else
         printf("Member incorporated \n");
/* ******************************************************************** */
/*                                                                      */
/*  3. Search for a member in the directory with TOCPRIM                */
/*                                                                      */
/* ******************************************************************** */
    cb.function = LMSUP_TOCPRIM;
    cb.subcode = LMSUP_LONG;
    cb.overwrite =LMSUP_YES;
    /*     Assign the necessary values for TOCPRIM                    */
    /*                                                                */
    /* Note that the arguments to be copied must end with a blank     */
    /* if they are shorter than the target field.                     */
     strfill(em.name,"BSP.ELEMENT",sizeof(em.name));
                                    /* Assign member name             */
     strfill(em.version,"001",sizeof(em.version));
                                    /* Assign member version          */
     strfill(em.typ,"S",sizeof(em.typ));
                                    /* Assign member type             */
     /* Program call */
     lmsup1(&cb,&tid,&ei,&ld,&em);
     /* Evaluate return code */
     if (cb.retcode != LMSUP_OK)
      {
        /* An error has occurred - issue message and terminate program */
         printf("Error when searching for member \n");
         exit(1);
      }
     else
      {
          printf("Member found:\n"); 
                                                   /* Display type      */
          strncpy(temp,ei.typ,sizeof(ei.typ));
          ptemp = index(temp,' ');
          if (ptemp) *ptemp = '\0';
          printf("typ          %s\n",temp);
                                                   /* Display name      */
          strncpy(temp,ei.name,sizeof(ei.name));
          ptemp = index(temp,' ');
          if (ptemp) *ptemp = '\0';
          printf("name         %s\n",temp);
                                                   /* Display version   */
          strncpy(temp,ei.version,sizeof(ei.version));
          ptemp = index(temp,' ');
          if (ptemp) *ptemp = '\0';
          printf("version      %s\n",temp);
                                                   /* Display date      */
          strncpy(temp,ei.user_date,sizeof(ei.user_date));
          ptemp = index(temp,' ');
          if (ptemp) *ptemp = '\0';
          printf("user-date    %s\n\n",temp);
      } 
/* ******************************************************************** */
/*                                                                      */
/*  4. Open a member with OPENGET                                       */
/*                                                                      */
/* ******************************************************************** */
    cb.function = LMSUP_OPEN_GET;
    cb.subcode  = LMSUP_UNUSED ;
    /*     Assign the necessary values for TOCPRIM                    */
    /*                                                                */
    /* Note that the arguments to be copied must end with a blank     */
    /* if they are shorter than the target field.                     */
     strfill(ld.name,"#BSP.LIB.C",sizeof(ld.name));
                                    /* Assign library name            */
     strfill(ed.name,"BSP.ELEMENT",sizeof(ed.name));
                                    /* Assign member name             */
     strfill(ed.version,"001",sizeof(ed.version));
                                    /* Assign member version          */
     strfill(ed.typ,"S",sizeof(ed.typ));
                                    /* Assign member type             */
     /* Program call */
     lmsup1(&cb,&rd,&ld,&ed);
     /* Evaluate return code */
     if (cb.retcode != LMSUP_OK)
      {
        /* An error has occurred - issue message and terminate program */
         printf("Error when opening member \n");
         exit(1);
      }
     else
          printf("Member opened \n"); 
/* ******************************************************************** */
/*                                                                      */
/*  5. Read a record with GET                                           */
/*                                                                      */
/* ******************************************************************** */
     do
      {
       cb.function = LMSUP_GET;
       cb.subcode = LMSUP_SEQ;
       /* Assign the necessary values for GET  */
        rd.buffer_len = sizeof(buffer)-1;
        /* Program call */
        lmsup1(&cb,&rd,buffer);
        switch (cb.retcode)    /* Evaluate return code */
         {
          case LMSUP_OK:       /* Output record */
                         buffer[rd.record_len]='\0';
                         printf("%s\n",buffer+4);
                         break; 
          case LMSUP_TRUNC:    /* Record truncated */
                         printf("Record buffer too short\n");
                         break;
          case LMSUP_EOF:      /* Member end */
                         break;
          default:             /* An error has occurred - issue message */
                         printf("Error when reading record \n");
                         break;
         }
      } 
     while (cb.retcode == LMSUP_OK);
/* ******************************************************************** */
/*                                                                      */
/*  6. Close a member with CLOSE                                        */
/*                                                                      */
/* ******************************************************************** */
    cb.function = LMSUP_CLOSE;
    cb.subcode = LMSUP_UNUSED;
     /* Program call */
     lmsup1(&cb,&rd);
     /* Evaluate return code */
     if (cb.retcode != LMSUP_OK)
      {
        /* An error has occurred - issue message and terminate program */
         printf("Error when closing member \n");
         exit(1);
      }
     else
          printf("Member closed \n");
/* ******************************************************************** */
/*                                                                      */
/*  7. Terminate subroutine access with END                             */
/*                                                                      */
/* ******************************************************************** */
    cb.function = LMSUP_END;
    cb.subcode  = LMSUP_UNUSED ;
     /* Program call */
     lmsup1(&cb);
     /* Evaluate return code */
     if (cb.retcode != LMSUP_OK)
      {
        /* An error has occurred - issue message and terminate program */
         printf("Error during termination \n");
         exit(1);
      }
    else
         printf("Subroutine access terminated \n");
}   /* End of the main program */