-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdictionary.c
91 lines (76 loc) · 1.64 KB
/
dictionary.c
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
//
// Created by root on 8/22/19.
//
#include "dvr2plex.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "dictionary.h"
tDictionary * createDictionary( const char * name )
{
tDictionary * result = (tDictionary *)calloc( 1, sizeof(tDictionary) );
result->name = name;
return result;
}
void emptyDictionary( tDictionary * dictionary )
{
tParam * p = dictionary->head;
dictionary->head = NULL;
while ( p != NULL)
{
if ( p->value != NULL )
{
free( (void *) p->value );
}
tParam * next = p->next;
free( p );
p = next;
}
}
void destroyDictionary( tDictionary * dictionary )
{
emptyDictionary( dictionary );
free( dictionary );
}
void printDictionary( tDictionary * dictionary )
{
if ( dictionary != NULL )
{
debugf( 3, "...%s dictionary...\n", dictionary->name);
tParam * p = dictionary->head;
while ( p != NULL )
{
debugf( 3, "%16s: \"%s\"\n", lookupHash(p->hash), p->value );
p = p->next;
}
}
}
int addParam( tDictionary * dictionary, tHash hash, const char * value )
{
int result = -1;
tParam * p = malloc( sizeof(tParam) );
if (p != NULL)
{
p->hash = hash;
p->value = strdup( value );
p->next = dictionary->head;
dictionary->head = p;
result = 0;
}
return result;
}
string findValue( tDictionary * dictionary, tHash hash )
{
string result = NULL;
tParam * p = dictionary->head;
while (p != NULL)
{
if ( p->hash == hash )
{
result = p->value;
break;
}
p = p->next;
}
return result;
}