From:	SMTP%"RELAY-INFO-VAX@CRVAX.SRI.COM" 26-AUG-1993 18:55:32.85
To:	EVERHART
CC:	
Subj:	Re: Examples using LBR$ routines.

Date: Thu, 26 Aug 1993 20:52:58 +0100
From: Arne Vajhøj <ARNE@kopc.hhs.dk>
Subject: Re: Examples using LBR$ routines.
To: grant@SITE.JCCBI.GOV, INFO-VAX@SRI.COM
Message-id: <01H27QQX8S3M9LVIRR@kopc.hhs.dk>
X-VMS-To: KOPC::IN%"grant@SITE.JCCBI.GOV"
X-VMS-Cc: IN::"INFO-VAX@SRI.COM"
MIME-version: 1.0
Content-type: TEXT/PLAIN; CHARSET=ISO-8859-1
Content-transfer-encoding: 8BIT

> I would like to see(have) some example programs in C using the
> LBR$ utility function.  :)

A week ago I posted the following example in FORTRAN:

      PROGRAM Z
      CALL TEXT_LOOKUP('SYS$LIBRARY:FORSYSDEF.TLB')
      END
C
      SUBROUTINE TEXT_LOOKUP(TLB)
      INCLUDE '($LBRDEF)'
      CHARACTER*(*) TLB
      EXTERNAL DOIT
      INTEGER*4 STAT,LIBIX
      INTEGER*4 LBR$INI_CONTROL,LBR$OPEN,LBR$GET_INDEX,LBR$CLOSE
      STAT=LBR$INI_CONTROL(LIBIX,LBR$C_READ,LBR$C_TYP_TXT,)
      STAT=LBR$OPEN(LIBIX,TLB,,,,,)
      STAT=LBR$GET_INDEX(LIBIX,1,DOIT,)
      STAT=LBR$CLOSE(LIBIX)
      RETURN
      END
C
      INTEGER*4 FUNCTION DOIT(KEY,RFA)
      INTEGER*4 RFA(2)
      CHARACTER*(*) KEY
      INCLUDE '($SSDEF)'
      WRITE(*,*) KEY
      DOIT=SS$_NORMAL
      RETURN
      END

In C the same example looks like:

#include <stdio.h>
#include <descrip.h>
#include <lbrdef.h>
#include <ssdef.h>
#include <string.h>

long lbr$ini_control();
long lbr$open();
long lbr$get_index();
long lbr$close();

int doit(struct dsc$descriptor_s *key,long rfa[2])
{
   char tmp[80];
   memcpy(&tmp,key->dsc$a_pointer,key->dsc$w_length);
   tmp[key->dsc$w_length] = '\0';
   printf("%s\n",tmp);
   return SS$_NORMAL;
}

void text_lookup(struct dsc$descriptor_s *tlbdesc)
{
   long c1 = LBR$C_READ, c2 = LBR$C_TYP_TXT, c3 = 1;
   long stat,libix;
   stat = lbr$ini_control(&libix,&c1,&c2);
   stat = lbr$open(&libix,tlbdesc,0,0,0,0,0);
   stat = lbr$get_index(&libix,&c3,doit,0);
   stat = lbr$close(&libix);
   return;
}

main()
{
   $DESCRIPTOR(tlbdesc,"SYS$LIBRARY:FORSYSDEF.TLB");
   text_lookup(&tlbdesc);
}

Hope it helps !

                                                          Arne

Arne Vajhøj                             local DECNET:  KO::ARNE
Computer Department                     PSI:           PSI%238310013040::ARNE
Business School of Southern Denmark     Internet:      ARNE@KO.HHS.DK


