
/*  PANEL(r) Roundhill Computer Systems Limited */

/*  Program to demonstrate how C code generated by PANGENC is combined 
    with an application progam.  To create the TESTC program, first
    use pangenc to generate code for the demo panel:
    
       pangenc -f demo
    
    The -f argument is necessary to enable the vertical scroll feature to
    be used.  Then compile this module and 'demo' and link them with the
    applicable PANEL system library.                                       */

                            /* select panel interface */
#include <pnli.h>
                            /* include generated demonstration file */
                            /* demo.h includes pnlc.h and pnl3.h */
                            /* (unless 'h' option used on PANGENC) */
#include <demo.h>
                            /* screen-level interface */
#include <pnl5.h>

#ifndef WSL
#ifdef AMIGA
#include <lattice\stdio.h>
#else
#include <stdio.h>
#endif
#endif

extern double PANUMD[];     /* global real numeric result area */
extern int PASCRO;          /* set to true for vertical scroll */
#ifndef MARKWILLIAMS
uchar *malloc();            /* included in MW stdio.h */
#endif

main()

{
char somewhere[16];         /* used to save field by name */
char elsewhere[16];         /* used to save field by number */
int menusel;                /* used to report menu selection */
panfcb *workptr;            /* needed by some compilers to avoid complexity */
uchar *newb;                /* spare area for name and address */

#ifdef OSINIT               /* operating system requires initialisation */
PAOSINIT();                 /* perform OS initialisation */
#endif

/*  If this program terminates silently, it indicates that PAINIT or PASCSE
    failed.  A real program would inform the user of this fact.            */
                      
if ( (PAINIT("") == 0) &&       /* read PANEL.VDU from default place */
     (PASCSE(3) != -1) ) {      /* enable save screen */
PAFUNC(1);                  /* send init sequence */
PAFUNC(3);                  /* clear screen */
PAUSEP(&pDEMO,0);           /* bring demo panel into use */

/*  The next section demonstrates the vertical scroll feature.  It first
    creates a new data area for the name and address field, then sets the
    data area height to 10.  If you wish to use a static area, it would
    be necessary to modify the generated code in demo.c and demo.h        */

newb = malloc(UCI(fNADR.datawidth) * 10);   /* make a new area for nadr */
if (newb != PANULL) {                       /* there was enough room */
fNADR.dataheight = 10;      /* try doubling the data area height */
fNADR.datablock = newb;     /* use the new area instead of the smaller one */
PANELF(ffild,&fNADR);       /* empty whole data area to fill */
PASCRO = 1; }               /* switch on the vertical scroll feature */

/*  If you have undefined structure members in the above, you have probably
    forgotten the -f option when generating code from the demo panel.       */

/*  The next section displays the screen and then reads the whole screen */

PANELS(pdisp);              /* display fixed data */
PANELS(pshow);              /* display input fields */
PAMSGE("Enter Details");    /* give instructions */
PANELS(pread);              /* read all fields */

/*  Next, read a single field by name and extract its entered data */

PAMSGE("Re-enter Contact Name");
PANELF(freadh,&fCONTACT);   /* read a single field again */
strcpy(somewhere,CONTACT);  /* move the input data somewhere (by name) */

/*  Extract data for a single field, this time by number */

workptr = PAFPT[2];         /* find field number two */
strcpy(elsewhere,workptr->datablock);   /* move numbered field's data */

/*  Now demonstrate the menu function with the field named VMENU */

PAMSGE("Use up/down arrows, then <cr>, or key initial letter");
menusel = PAMENU(&fVMENU,1,3,0);            /* do menu selection */
PAMSGE("Key any character to continue");    /* halt so user can see the */
PAGETF();                                   /* field has been lifted */

PAFUNC(3);                  /* clear the screen */
PAFUNC(2);                  /* send the termination sequence */

/*  Confirm entries made using normal C functions.  Note that the NF extended
    attribute for the SUBS field specified that it should use numeric value
    number one, from where we can get the result.                            */

#ifndef AMIGA
printf("You entered for 'Company'      : %s\n\r",elsewhere); 
printf("You entered for 'Contact'      : %s\n\r",somewhere); 
printf("You entered for 'Subscription' : %f\n\r",PANUMD[1]); /* NF #1 defined */
printf("You selected menu item         : %d\n\r",menusel); } 
#endif

#ifdef OSTERM               /* operating system requires exit process */
PAOSTERM();                 /* perform OS termination */
#endif

#ifdef AMIGA                /* smaller window, wait to see it */
printf("'Company'      : %s\n\r",elsewhere); 
printf("'Contact'      : %s\n\r",somewhere); 
printf("'Subscription' : %f\n\r",PANUMD[1]); /* NF #1 defined */
printf("Menu item      : %d\n\r",menusel); } 
printf("\nKey <return> to continue ");
getc(stdin);
#endif

}
