To all interested in accessing externally described file in C program:

1) you can have the C compiler put automatically create a structure for the
database file like this:

  #pragma mapinc("sesn", "alsrvr(*all)", "both key", "d")
  #include "sesn"

Check out the #pragma mapinc doucmentation for more information. the "both
key" option will create two structures: one for all of the fields in the
file, and one for the key.

2) In your code you use the _Rxxx() functions to acess the file. They are
roughly equivalent to standard fxxx() C I/O functions. Here is an example of
opening, reading a file, and closing it:

_RIOFB_T   *riofb;
int        opts;

 /* open the file */

 gLogInfo->LOGOptions = _Ropen("ALLTCP120/ALLOGO", "rr+");
 if ( gLogInfo->LOGOptions == NULL )
 {
     printf("ERROR: Failed to open LOG options file ALLOGO.");
     return((short)1);
 }

  /* set the read options */

  opts = __KEY_EQ;

  /* read the record by key */

  memset(&gLogInfo->logo, 0, sizeof(gLogInfo->logo));
  memset(&gLogInfo->logokey, 0, sizeof(gLogInfo->logokey));
  memcpy(gLogInfo->logokey.LORECK, "LOGOP", 5);

  riofb = _Rreadk( gLogInfo->LOGOptions, &gLogInfo->logo,
     sizeof(gLogInfo->logo),
     opts, &gLogInfo->logokey, sizeof(gLogInfo->logokey));

  /* handle record not retrieved */

  if ( riofb->num_bytes == 0 )
  {
     printf("ERROR: LOG options record not found. Error and return.");
     _Rclose(gLogInfo->LOGOptions);
     return((short)1);
  }

  /* some logic occurs here to update fields */

  /* update the record */

  riofb = _Rupdate(gLogInfo->LOGOptions,
        &gLogInfo->logo, sizeof(gLogInfo->logo));

  /* close the file */

  _Rclose(gLogInfo->LOGOptions);

Hope this helps,
Patrick


----- Original Message -----
From: "Oludare" <oludare@ix.netcom.com>
To: <midrange-l@midrange.com>
Cc: <patownsend@patownsend.com>
Sent: Monday, January 14, 2002 5:07 AM
Subject: Re: Accessing externally described file in a C program


> I'm interested too
>
> ----- Original Message -----
> From: "Patrick Townsend" <patownsend@patownsend.com>
> To: <midrange-l@midrange.com>
> Sent: Monday, January 14, 2002 12:01 AM
> Subject: Re: Accessing externally described file in a C program
>
>
> > Larry,
> >
> > I'll be glad to provide some code if you would like.
> > Patrick
> >
> >
> > ----- Original Message -----
> > From: <Larryt222@aol.com>
> > To: <midrange-l@midrange.com>
> > Sent: Tuesday, January 08, 2002 5:22 PM
> > Subject: Accessing externally described file in a C program
> >
> >
> > > --
> > > [ Picked text/plain from multipart/alternative ]
> > > Can someone help me here.
> > >
> > >  What I need is a C program that reads an externally described DB file
> and
> > > does something (anything) with a field in that file.  The C
programmers
> > guide
> > > doesn't have an example that is very helpful.
> > >
> > > I can read a file and I know how to create a structure I'm just not
sure
> > how
> > > to combine them.  I'm sure it's very simple and I'm just missing it.
> > >
> > > Thanks,
> > >
> > > Larry
> > > _______________________________________________
> > > This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
> > list
> > > To post a message email: MIDRANGE-L@midrange.com
> > > To subscribe, unsubscribe, or change list options,
> > > visit: http://lists.midrange.com/cgi-bin/listinfo/midrange-l
> > > or email: MIDRANGE-L-request@midrange.com
> > > Before posting, please take a moment to review the archives
> > > at http://archive.midrange.com/midrange-l.
> > >
> > >
> >
> > _______________________________________________
> > This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
> list
> > To post a message email: MIDRANGE-L@midrange.com
> > To subscribe, unsubscribe, or change list options,
> > visit: http://lists.midrange.com/cgi-bin/listinfo/midrange-l
> > or email: MIDRANGE-L-request@midrange.com
> > Before posting, please take a moment to review the archives
> > at http://archive.midrange.com/midrange-l.
> >
> >
>
>



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2022 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.