[Info-vax] Example of random access by record number on an RMS fixed record size, relative organization file?
Dave Froble
davef at tsoft-inc.com
Wed Sep 20 00:02:30 EDT 2023
On 9/19/2023 8:50 PM, Arne Vajhøj wrote:
> On 9/19/2023 8:44 PM, Arne Vajhøj wrote:
>> On 9/16/2023 4:16 PM, Arne Vajhøj wrote:
>>> I don't think I have ever used ORG=REL.
>>
>> But then I could start now!
>
> C / RMS:
>
> $ type relwrt.c
> #include <stdio.h>
> #include <string.h>
>
> #include <starlet.h>
> #include <rms.h>
>
> #define FNM "rel.dat"
>
> int main(int argc, char *argv[])
> {
> long stat;
> struct FAB fab;
> struct RAB rab;
> int i;
> char buf[80];
> fab = cc$rms_fab;
> fab.fab$l_fna = (char *)FNM;
> fab.fab$b_fns = strlen(FNM);
> fab.fab$b_org = FAB$C_REL;
> fab.fab$b_rfm = FAB$C_VAR;
> fab.fab$l_fop = FAB$M_CIF;
> fab.fab$w_mrs = 512;
> fab.fab$b_fac = FAB$M_PUT;
> stat = sys$create(&fab, 0, 0);
> if(!(stat & 1)) {
> printf("sys$create stat = %d\n", stat);
> }
> rab = cc$rms_rab;
> rab.rab$l_fab = &fab;
> rab.rab$b_rac = RAB$C_KEY;
> stat = sys$connect(&rab, 0 ,0);
> if(!(stat & 1)) {
> printf("sys$connect stat = %d\n", stat);
> }
> for(i = 1; i <= 100; i++)
> {
> sprintf(buf, "This is line #%04d!", i);
> rab.rab$l_kbf = (char *)&i;
> rab.rab$b_ksz = sizeof(i);
> rab.rab$l_rbf = buf;
> rab.rab$w_rsz = strlen(buf);
> stat = sys$put(&rab, 0, 0);
> if(!(stat & 1)) {
> printf("sys$put stat = %d\n", stat);
> }
> }
> stat = sys$disconnect(&rab, 0, 0);
> if(!(stat & 1)) {
> printf("sys$disconnect stat = %d\n", stat);
> }
> stat = sys$close(&fab, 0, 0);
> if(!(stat & 1)) {
> printf("sys$close stat = %d\n", stat);
> }
> return 0;
> }
>
> $ cc relwrt
> $ link relwrt
> $ run relwrt
> $ type relrdseq.c
> #include <stdio.h>
> #include <string.h>
>
> #include <starlet.h>
> #include <rms.h>
>
> #define FNM "rel.dat"
>
> int main(int argc, char *argv[])
> {
> long stat;
> struct FAB fab;
> struct RAB rab;
> char buf[80];
> fab = cc$rms_fab;
> fab.fab$l_fna = (char *)FNM;
> fab.fab$b_fns = strlen(FNM);
> fab.fab$b_org = FAB$C_REL;
> fab.fab$b_rfm = FAB$C_VAR;
> fab.fab$w_mrs = 512;
> fab.fab$b_fac = FAB$M_GET;
> stat = sys$open(&fab, 0, 0);
> if(!(stat & 1)) {
> printf("sys$open stat = %d\n", stat);
> }
> rab = cc$rms_rab;
> rab.rab$l_fab = &fab;
> rab.rab$b_rac = RAB$C_SEQ;
> stat = sys$connect(&rab, 0 ,0);
> if(!(stat & 1)) {
> printf("sys$connect stat = %d\n", stat);
> }
> for(;;)
> {
> rab.rab$l_ubf = buf;
> rab.rab$w_usz = sizeof(buf);
> stat = sys$get(&rab, 0, 0);
> if(stat == RMS$_EOF) break;
> if(!(stat & 1)) {
> printf("sys$get stat = %d\n", stat);
> }
> buf[rab.rab$w_rsz] = 0;
> printf("|%s|\n", buf);
> }
> stat = sys$disconnect(&rab, 0, 0);
> if(!(stat & 1)) {
> printf("sys$disconnect stat = %d\n", stat);
> }
> stat = sys$close(&fab, 0, 0);
> if(!(stat & 1)) {
> printf("sys$close stat = %d\n", stat);
> }
> return 0;
> }
>
> $ cc relrdseq
> $ link relrdseq
> $ run relrdseq
> |This is line #0001!|
> |This is line #0002!|
> ...
> |This is line #0100!|
> $ type relrddir.c
> #include <stdio.h>
> #include <string.h>
>
> #include <starlet.h>
> #include <rms.h>
>
> #define FNM "rel.dat"
>
> int main(int argc, char *argv[])
> {
> long stat;
> struct FAB fab;
> struct RAB rab;
> int i;
> char buf[80];
> fab = cc$rms_fab;
> fab.fab$l_fna = (char *)FNM;
> fab.fab$b_fns = strlen(FNM);
> fab.fab$b_org = FAB$C_REL;
> fab.fab$b_rfm = FAB$C_VAR;
> fab.fab$w_mrs = 512;
> fab.fab$b_fac = FAB$M_GET;
> stat = sys$open(&fab, 0, 0);
> if(!(stat & 1)) {
> printf("sys$open stat = %d\n", stat);
> }
> rab = cc$rms_rab;
> rab.rab$l_fab = &fab;
> rab.rab$b_rac = RAB$C_KEY;
> stat = sys$connect(&rab, 0 ,0);
> if(!(stat & 1)) {
> printf("sys$connect stat = %d\n", stat);
> }
> for(i = 1; i <= 100; i++)
> {
> rab.rab$l_kbf = (char *)&i;
> rab.rab$b_ksz = sizeof(i);
> rab.rab$l_ubf = buf;
> rab.rab$w_usz = sizeof(buf);
> stat = sys$get(&rab, 0, 0);
> if(!(stat & 1)) {
> printf("sys$get stat = %d\n", stat);
> }
> buf[rab.rab$w_rsz] = 0;
> printf("|%s|\n", buf);
> }
> stat = sys$disconnect(&rab, 0, 0);
> if(!(stat & 1)) {
> printf("sys$disconnect stat = %d\n", stat);
> }
> stat = sys$close(&fab, 0, 0);
> if(!(stat & 1)) {
> printf("sys$close stat = %d\n", stat);
> }
> return 0;
> }
>
> $ cc relrddir
> $ link relrddir
> $ run relrddir
> |This is line #0001!|
> |This is line #0002!|
> ...
> |This is line #0100!|
>
> Arne
>
>
Is it just me, or, was my Basic example shorter and easier to read than your
Cobol, Fortran, and C examples?
--
David Froble Tel: 724-529-0450
Dave Froble Enterprises, Inc. E-Mail: davef at tsoft-inc.com
DFE Ultralights, Inc.
170 Grimplin Road
Vanderbilt, PA 15486
More information about the Info-vax
mailing list