File: comparing.c

package info (click to toggle)
libproplist 0.7.1-4
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 684 kB
  • ctags: 452
  • sloc: ansic: 3,684; sh: 1,856; lex: 181; yacc: 118; makefile: 106; tcl: 40
file content (120 lines) | stat: -rw-r--r-- 2,199 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/* comparing.c: This is -*- c -*-

   This file implements the PLIs... functions

   */

#include "proplistP.h"

/* forward prototype */
BOOL PLStrCmp(proplist_t pl1, proplist_t pl2);

BOOL (*plStrCmp)(proplist_t, proplist_t) = &PLStrCmp;

void PLSetStringCmpHook(BOOL(*fn)(proplist_t, proplist_t))
{
  if(!fn)
    plStrCmp = &PLStrCmp;
  else
    plStrCmp = fn;
}

BOOL PLStrCmp(proplist_t pl1, proplist_t pl2)
{
  plptr_t int1, int2;

  int1 = pl1; int2 = pl2;
  if(!strcmp(int1->t.str.string, int2->t.str.string))
    return YES;
  else
    return NO;
}

BOOL PLIsString(proplist_t pl)
{
  if(((plptr_t)pl)->type == PLSTRING)
    return YES;
  return NO;
}

BOOL PLIsData(proplist_t pl)
{
  if(((plptr_t)pl)->type == PLDATA)
    return YES;
  return NO;
}

BOOL PLIsArray(proplist_t pl)
{
  if(((plptr_t)pl)->type == PLARRAY)
    return YES;
  return NO;
}

BOOL PLIsDictionary(proplist_t pl)
{
  if(((plptr_t)pl)->type == PLDICTIONARY)
    return YES;
  return NO;
}

BOOL PLIsSimple(proplist_t pl)
{
  if(PLIsString(pl)||PLIsData(pl))
    return YES;
  return NO;
}

BOOL PLIsCompound(proplist_t pl)
{
  if(PLIsArray(pl)||PLIsDictionary(pl))
    return YES;
  return NO;
}

BOOL PLIsEqual(proplist_t pl1, proplist_t pl2)
{
  plptr_t int1, int2;
  int i;
  
  int1 = pl1; int2 = pl2;
  
  if((int1->type != int2->type))
    return NO;

  switch(int1->type)
    {
    case PLSTRING:
      return (*plStrCmp)(pl1, pl2);
    case PLDATA:
      if(int1->t.data.length != int2->t.data.length)
	return NO;
      if(memcmp(int1->t.data.data, int2->t.data.data, int1->t.data.length)!=0)
	return NO;
      return YES;
    case PLARRAY:
      if(int1->t.array.number != int2->t.array.number)
	return NO;
      for(i=0;i<int1->t.array.number;i++)
	if(!PLIsEqual(int1->t.array.elements[i],
		      int2->t.array.elements[i]))
	  return NO;
      return YES;
    case PLDICTIONARY:
      if(int1->t.dict.number != int2->t.dict.number)
	return NO;
      for(i=0;i<int1->t.dict.number;i++)
	if(!PLIsEqual(int1->t.dict.keys[i],
		      int2->t.dict.keys[i]) ||
	   !PLIsEqual(int1->t.dict.values[i],
		      int2->t.dict.values[i]))
	  return NO;
      return YES;
    default:
      return NO;
    }
}