Using KSAM/XL and KSAM 64 (32650-90886)

268 AppendixC
HP C/iX Example Program
FREAD(filenum, buffer, - sizeof buffer);
if ((save_ccode=ccode()) == CCG)
break;
assert(save_ccode==CCE);
printf(" %.5s %.20s %.3s-%.2s-%.4s "
"%.4s %.2s/%.2s/%.2s\n",
buffer, buffer+5, buffer+25, buffer+28, buffer+30,
buffer+34, buffer+40, buffer+42, buffer+38);
}
printf("\n");
}
static void list_sequential_primary(void)
{
/* List file in sequence on primary key */
printf("In sequence by primary key:\n");
lock_file();
/* Following call to FFINDN not necessary if this
is the first access since the file was opened */
FFINDN(filenum, -1, 0);
assert(ccode()==CCE);
list_sequential();
unlock_file();
}
static void list_sequential_secondary(const int location)
{
/* List file in sequence on specified secondary key */
printf("In sequence by secondary key in location %d:\n",
location);
lock_file();
FFINDN(filenum, -1, location);
assert(ccode()==CCE);
list_sequential();
unlock_file();
}
static void lock_file(void)
{
/* Lock the file unconditionally */
FLOCK(filenum, 1);
assert(ccode()==CCE);
}
static void open_file(void)
{
/* Open file for shared update access with locking */
int status;
const int old=1, update=5, lock=1, shr=3;
HPFOPEN(&filenum, &status,
2, "-" FILENAME "-",
3, &old,
11, &update,
12, &lock,
13, &shr);
assert(!status);
}
static void unlock_file(void)
{
/* Unlock the file */
FUNLOCK(filenum);
assert(ccode()==CCE);