
/****************************************************************************/

/*  Module PNLLVALC.C 

    Copyright 1986 Roundhill Computer Systems Limited
    All rights reserved

    Use and disclosure of this code are prohibited unless in accordance
    with the terms of the PANEL software licence.

    ************************************************************************
    *** THE OBJECT CODE VERSION OF THIS MODULE IS INCLUDED IN THE PANEL  ***
    *** LIBRARY.  IF YOU AMEND AND COMPILE THIS MODULE AND LINK IT WITH  ***
    *** YOUR APPLICATION IT WILL SUPERSEDE THE LIBRARY VERSION.          ***
    ************************************************************************

    PANEL:  Type 4          : Line Validation
            Source Language : C

    Modification History (Push-Down List):  

            27.12.85        : Convert to table-driven operation

******************************************************************************/

#define VALLARG 1
#include <pnl4.h>

uchar *PVLINP = PANULL;     /* pointer to start of current line */
uchar *PVWRKP = PANULL;     /* working pointer to current line */
uint  PVLCTR  = 0;          /* element counter */
uchar PVWSTR[133] = "";     /* working string for line validation */
int   PVLARG;               /* code arg for line validation */

#define MAXLONG 16              /* size of PANUML array of longs */
#define MAXDOUB 16              /* size of PANUMD array of doubles */

int PAMAXL = MAXLONG;
int PAMAXD = MAXDOUB;

long   PANUML[MAXLONG] = {0};
double PANUMD[MAXDOUB] = {0.0};
                                                          
extern int (*PALVTB[])();   /* character validation function table */
extern int PALVPM;          /* max index into function table */

/*****************************************************************************/

int PALVAL(code)

/*    Line Validation Base Module
      
      Calling conventions:
    
      On entry, 
            - PACRF is the FCB of the field being input
            - code is zero for real validation, 1 for 'line operation'
            - code is -1 to signify vertical scroll just performed

      On exit, 
            - no change should be made to PACRF
            - the field's data area should be altered as required
            - the PALVAL return code will be interpreted as follows:
    
               0:  Line is valid and has not been altered in this routine
               1:  Line is valid: redisplay
               2:  Line is bad but does not require redisplay: restart entry
               3:  Line is bad: redisplay

               the return code is ignored unless the input 'code' is 0

    If the validation number is higher than the table maximum, use the default

******************************************************************************/

int code;

{
int lv;
int t1,t2,t3;               /* expression was 'too complex' for one compiler */    

/*  If special code of -1 is present to indicate that a vertical scroll 
    operation has just been performed,  you can use this routine to
    scroll any other fields that need to be kept in step.  Use PACRF to
    find where you are in the field (i.e. whether scroll was up or down).    */

if ( (PVLARG = code) == -1)
    return 0;

/*  First, we must find the start of this line in the field's data area.
    This is saved in PVLINP (line pointer), and also used to initialise 
    PVWRKP (working pointer).  We recommend that you leave PVLINP alone as 
    a 'base point' and work with PVWRKP in any line validation routines 
    you write.       */

t1 = UCI(PACRF.fj) + UCI(PACRF.dj);             /* line number in field data */
t2 = UCI(PACRF.datawidth);                      /* times data area width */
t3 = UCI(PACRF.di);                             /* plus field home position */
PVLINP = &(PACRF.datablock[(t1 * t2) + t3]);    /* start of displayed line */
PVWRKP = PVLINP;                                /* working copy */

PVLCTR = 0;                           /* init line position counter */
lv = UCI(PACRF.linevaln);
return (*PALVTB[(lv>PALVPM)?0:lv])();  
}
