/[pspp]/pspp/src/case.c
ViewVC logotype

Diff of /pspp/src/case.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by blp, Tue Mar 1 08:16:15 2005 UTC revision 1.4 by blp, Tue Apr 26 06:32:02 2005 UTC
# Line 24  Line 24 
24  #include "val.h"  #include "val.h"
25  #include "alloc.h"  #include "alloc.h"
26  #include "str.h"  #include "str.h"
27    #include "var.h"
28    
29  #ifdef GLOBAL_DEBUGGING  #ifdef GLOBAL_DEBUGGING
30  #undef NDEBUG  #undef NDEBUG
# Line 349  case_data_rw (struct ccase *c, size_t id Line 350  case_data_rw (struct ccase *c, size_t id
350  }  }
351  #endif /* GLOBAL_DEBUGGING */  #endif /* GLOBAL_DEBUGGING */
352    
353    /* Compares the values of the VAR_CNT variables in VP
354       in cases A and B and returns a strcmp()-type result. */
355    int
356    case_compare (const struct ccase *a, const struct ccase *b,
357                  struct variable *const *vp, size_t var_cnt)
358    {
359      for (; var_cnt-- > 0; vp++)
360        {
361          struct variable *v = *vp;
362    
363          if (v->width == 0)
364            {
365              double af = case_num (a, v->fv);
366              double bf = case_num (b, v->fv);
367    
368              if (af != bf)
369                return af > bf ? 1 : -1;
370            }
371          else
372            {
373              const char *as = case_str (a, v->fv);
374              const char *bs = case_str (b, v->fv);
375              int cmp = memcmp (as, bs, v->width);
376    
377              if (cmp != 0)
378                return cmp;
379            }
380        }
381      return 0;
382    }
383    
384    
385    /* Compares the values of the VAR_CNT variables in VAP in case CA
386       to the values of the VAR_CNT variables in VBP in CB
387       and returns a strcmp()-type result. */
388    int
389    case_compare_2dict (const struct ccase *ca, const struct ccase *cb,
390                        struct variable *const *vap, struct variable *const *vbp,
391                        size_t var_cnt)
392    {
393      for (; var_cnt-- > 0; vap++, vbp++)
394        {
395          const struct variable *va = *vap;
396          const struct variable *vb = *vbp;
397    
398          assert (va->type == vb->type);
399          assert (va->width == vb->width);
400          
401          if (va->width == 0)
402            {
403              double af = case_num (ca, va->fv);
404              double bf = case_num (cb, vb->fv);
405    
406              if (af != bf)
407                return af > bf ? 1 : -1;
408            }
409          else
410            {
411              const char *as = case_str (ca, va->fv);
412              const char *bs = case_str (cb, vb->fv);
413              int cmp = memcmp (as, bs, va->width);
414    
415              if (cmp != 0)
416                return cmp;
417            }
418        }
419      return 0;
420    }
421    
422  /* Returns a pointer to the array of `union value's used for C.  /* Returns a pointer to the array of `union value's used for C.
423     The caller must *not* modify the returned data.     The caller must *not* modify the returned data.
424    

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26