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

/*  Module PNLXASCC.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          : Validation / Miscellaneous
            Source Language : C

    Modification History (Push-Down List):  

            27.12.85        : Convert to table-driven operation

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

#define VALXARG 1
#include <pnl4.h>

/*  Fields required for definition of field save areas for use when 'overlay'
    fields are displayed.  The fields are defined here so that you can extend
    the number if necessary.  The absolute maximum is 127.                  */

#ifdef AMIGA
#include <exec/types.h>
#include <graphics/gfx.h>
struct savearea {
uchar svao,svax,svay,sval,svah,sva1,sva2,sva3;
struct BitMap svbit; };
extern int PAFSVN;                  /* global containing maximum value < 128 */
extern struct savearea PAFSVA[];
#else

#define NSAVES 16                   /* maximum number of saved field areas */

int PAFSVN = NSAVES & 0x7f;         /* global containing maximum value < 128 */
uchar *PAFSVA[NSAVES] = {PANULL};   /* pointer array for save areas */

#endif

#define XASN 32         /* maximum number of substrings allowed */
#ifdef WSL
uchar *PAXASP[XASN] = 0;/* pointers to substrings of xa string */
#else
uchar *PAXASP[XASN];    /* pointers to substrings of xa string */
#endif
int PAXASN = 0;         /* current number of substrings */

static uchar *tempxa = PANULL;  /* temporary array for PAXAST */

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

int PAXASC(p)

/*  This routine scans an xa string to divide it into separate strings.  The
    first character is assumed to be a delimiter.  Pointers to the elements
    are placed in the array PAXASP.  If you need more than 32 substrings, you
    will need to recompile with a different value of XASN.

    There should be a delimiter at the end of the string, and after the first
    pass through this routine the delimiters will be changed to nulls.  The
    routine returns the number of substrings found, which is also placed in
    PAXASN.

    You can scan the same xa string twice, but on passes after the first an
    empty substring will terminate the list, because the second consecutive
    delimiter is indistinguishable from a terminating null.  Avoid this 
    problem by using PAXAST below.

    If you fail to place a delimiter after the last substring, note that this
    routine will ignore the 'incomplete' last substring.

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

uchar *p;
    
{
    uchar delim;
    int n;
    
    delim = *p;                 /* first char is delim */
    for (n = 0; n < XASN;)
        {
        *p++ = '\0';            /* set delim zero */
        if (*p == '\0') break;  /* empty substring */
        PAXASP[n++] = p;        /* point to start */
        while ( (*p != '\0') && (*p != delim) ) p++;    /* skip to delim */
        if ((delim != 0) && (*p == '\0')) {PAXASP[n--][0] = '\0'; break;} 
        }
    *p = '\0';                  /* in case more than XASN in string */
    return (PAXASN = n);        /* send back number found */
}

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

int PAXAST(p)

/*  This routine makes a temporary copy of an xa string and then scans it 
    using PAXASC.  This is useful when you do not want to have your delimiters
    replaced with nulls.
    
    Do not call PAXAST if you have already called PAXASC for the xa string, as
    the actual delimiters will have been replaced with nulls and the string
    will appear empty.
    
    Use PAXASC if you need to modify the 'real' xa string through the PAXASP
    pointers. 
    
    The PAXASP pointers cannot be saved and used past the next call to PAXAST.

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

uchar *p;
    
{
    uchar *malloc();
    
    if (tempxa != PANULL) free(tempxa);         /* one at a time */
    tempxa = malloc(strlen(p) + 1);             /* make a temp string */
    if (tempxa == PANULL) return PAXASC("");    /* no space */
    strcpy(tempxa,p);                           /* copy the actual to temp */
    return PAXASC(tempxa);                      /* do the scan */
}
