/* sample VIEWS program */
#include stdio.h>
#include "fml.h"
#include "custdb.flds.h" /* field header file shown in */
/* ���Sample Header File Produced by viewc��� listing */
#include "custdb.h" /* C structure header file produced by */
/* viewc shown in ���Sample Field Table��� listing */
#define NF 800
#define NV 400
extern Ferror;
main()
{
/* declare needed program variables and FML functions */
FBFR *fbfr,*Falloc();
void F_error();
char *str, *cstruct, buff[100];
struct custdb cust;
/* allocate a fielded buffer */
if ((fbfr = Falloc(NF,NV)) == NULL) {
F_error("sample.program");
exit(1);
}
/* initialize str pointer to point to buff */
/* copy string values into buff, and */
/* Fadd values into some of the fields in fbfr */
str = &buff;
strcpy(str,"13579");
if (Fadd(fbfr,ACTION,str,(FLDLEN)6) < 0)
F_error("Fadd");
strcpy(str,"act11");
if (Fadd(fbfr,ACTION,str,(FLDLEN)6) < 0)
F_error("Fadd");
strcpy(str,"This is a one test.");
if (Fadd(fbfr,BUG_CURS,str,(FLDLEN)19) < 0)
F_error("Fadd");
strcpy(str,"This is a two test.");
if (Fadd(fbfr,BUG_CURS,str,(FLDLEN)19) < 0)
F_error("Fadd");
strcpy(str,"This is a three test.");
if (Fadd(fbfr,BUG_CURS,str,(FLDLEN)21) < 0)
F_error("Fadd");
/* Print out the current contents of the fbfr */
printf("fielded buffer before:\n"); Fprint(fbfr);
/* Put values in the C structure */
cust.tape = 12345;
cust.super = 999;
cust.youid = 80;
cust.custid[0] = -1; cust.custid[1] = 75;
str = cust.bug[0][0];
strncpy(str,"no bugs12345",12);
str = cust.bug[1][0];
strncpy(str,"yesbugs01234",12);
str = cust.bug[2][0];
strncpy(str,"no bugsights",12);
str = cust.bug[3][0];
strncpy(str,"no bugsysabc",12);
str = cust.action[0][0];
strcpy(str,"yesaction");
str = cust.action[1][0];
strcpy(str,"no action");
str = cust.action[2][0];
strcpy(str,"222action");
str = cust.action[3][0];
strcpy(str,"no action");
cust.ch = '0';
cstruct = (char *)&cust;
/* Update the fbfr with the values in the C structure */
/* using the custdb view description. */
if (Fvstof(fbfr,cstruct,FUPDATE,"custdb") < 0) {
F_error("custdb");
Ffree(fbfr);
exit(1);
}
/* Note that the following would transfer */
/* data from fbfr to cstruct */
/*
if (Fvftos(fbfr,cstruct,"custdb") < 0) {
F_error("custdb");
Ffree(fbfr);
exit(1);
} */
/* print out the values in the C structure and */
/* the values in the fbfr */
printf("cstruct contains:\en");
printf("action=:%s:\n",cust.action[0][0]);
printf("action=:%s:\n",cust.action[1][0]);
printf("action=:%s:\n",cust.action[2][0]);
printf("action=:%s:\n",cust.action[3][0]);
printf("custid=%ld\n",cust.custid[0]);
printf("custid=%ld\n",cust.custid[1]);
printf("youid=%ld\n",cust.youid);
printf("tape=%f\n",cust.tape);
printf("super=%d\n",cust.super);
printf("bug=:%.12s:\n",cust.bug[0][0]);
printf("bug=:%.12s:\n",cust.bug[1][0]);
printf("bug=:%.12s:\n",cust.bug[2][0]);
printf("bug=:%.12s:\en",cust.bug[3][0]);
printf("ch=:%c:\n\n",cust.ch);
printf("fielded buffer after:\n");
Fprint(fbfr);
Ffree(fbfr);
exit(0);
}