/*------------------------------------------------------------*/
/*            FLDFUNCS.C  -  Rev. VISIONS 1.20                */
/*                                                            */
/*  This file contains examples of field validation routines. */
/*------------------------------------------------------------*/



/*-----------------------------------------------------------*/
/*                        IntOnly                            */
/* This is a field input validation routine.  This routine   */
/* requires that all input for its string field be integers. */
/* Leadings spaces are allowed.                              */
/*-----------------------------------------------------------*/
FLAG IntOnly(string)
   TEXT *string;
{
   WORD leading_space = -1;   /* Have not seen first digit. */
   WORD i;

   for (i=0; i<strlen(string); i++)
   {
      if (string[i] == ' ')
      {
         if (leading_space == 0)  /* Seen first digit? */
            leading_space = 1;    /* Yes now must be spaces! */
      }
      else
      {
         if (leading_space == 1)  /* Digit after trailing space? */
            return(-1);           /* Yes, error */
         if (leading_space == -1)
            leading_space++;
         if (isdigit(string[i]) == 0)
            return(-1);
      }      
   }
   return(0);
}







/*-----------------------------------------------------------*/
/*                        HexOnly                            */
/* This is a field input validation routine.  This routine   */
/* requires that all input for its string field be           */
/* hexadecimal integers.  Leadings spaces are allowed.       */
/*-----------------------------------------------------------*/
FLAG HexOnly(string)
   TEXT *string;
{
   WORD leading_space = -1;   /* Have not seen first digit. */
   WORD i, charup;

   for (i=0; i<strlen(string); i++)
   {
      if (string[i] == ' ')
      {
         if (leading_space == 0)  /* Seen first digit? */
            leading_space = 1;    /* Yes now must be spaces! */
      }
      else
      {
         charup = toupper(string[i]);
         if (leading_space == 1)  /* Digit after trailing space? */
            return(-1);           /* Yes, error */
         if (leading_space == -1)
            leading_space++;
         if ((isdigit(string[i]) == 0) || (charup == 'A') ||
             (charup == 'B') || (charup == 'C')
             (charup == 'D') || (charup == 'E')
             (charup == 'F'))
            return(-1);
      }      
   }
   return(0);
}







/*-----------------------------------------------------------*/
/*                           MFOnly                          */
/* This is a field input validation routine.  This routine   */
/* requires that the input for its string field be either a  */
/* space or an f, or a m, either upper or lower case.  Lower */
/* case entry is converted to upper case.                    */
/*-----------------------------------------------------------*/
FLAG MFOnly(string)
TEXT *string;
{
   if (string[0] == 'm')
      string[0] = 'M';
   if (string[0] == 'f')
      string[0] = 'F';
   if ((string[0] == 'M') || (string[0] == 'F'))
      return(0);
   return(-1);
}
