home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_10 / 9n10089a < prev    next >
Text File  |  1979-12-31  |  2KB  |  82 lines

  1. /*
  2.     listing 2 - type_check.c
  3. */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include "common.h"
  8.  
  9. FUNC type_check(struct field_definition *definitions, 
  10.         struct record *tran_start,
  11.         int transaction_size, 
  12.         char *user_keyword, 
  13.         char *user_value)
  14. {
  15.  
  16.   int i;            /* loop control  */
  17.   BOOL found=OFF;        /* switch if key was matched */
  18.  
  19.   int   integer;        /* integer value */
  20.   float floater;        /* float value */
  21.   char  *string;        /* string pointer */
  22.  
  23.  
  24.   /*
  25.     Loop through the tran_start array to match the 
  26.     key and obtain subject location.
  27.   */
  28.                                                            
  29.   for (i=0; strcmp(definitions[i].keyword, "last"); i++) {
  30.  
  31.     if ( !strcmp(definitions[i].keyword, user_keyword))
  32.         break;
  33.  
  34.   }
  35.     
  36.   if ( !strcmp(definitions[i].keyword, "last") ) {
  37.     printf ("Error: keyword '%s' not legal.\n", user_keyword);
  38.     return FAIL;
  39.   }
  40.  
  41.   /* 
  42.      Switch on the type of the subject. For each type, 
  43.      convert the user_value to the proper type and set 
  44.      the proper pointer. Then call the lookup routine. 
  45.   */
  46.  
  47.   switch (definitions[i].type) {
  48.  
  49.     case INT:
  50.     integer = atoi(user_value);        
  51.     if ( (lookup (INT, definitions[i].position_ptr, 
  52.         tran_start, transaction_size,     
  53.         (void *) &integer) ) == FAIL) {
  54.         printf ("No match\n");
  55.     }
  56.         break;
  57.    
  58.     case FLOAT:
  59.     floater = atof(user_value);        
  60.     if ( (lookup (FLOAT, definitions[i].position_ptr, 
  61.         tran_start, transaction_size, 
  62.         (void *) &floater) ) == FAIL) { 
  63.         printf ("No match\n");
  64.     }
  65.         break;
  66.  
  67.     case STRING:
  68.     string = user_value;
  69.     if ( (lookup (STRING, definitions[i].position_ptr, 
  70.         tran_start, transaction_size, 
  71.         (void *) string) ) == FAIL) { 
  72.         printf ("No match\n");
  73.     }
  74.         break;
  75.  
  76.   }
  77.  
  78.   return SUCCEED;
  79.  
  80. }
  81.  
  82.