forked from dmtx/libdmtx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dmtxbytelist.c
142 lines (126 loc) · 2.45 KB
/
dmtxbytelist.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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/**
* libdmtx - Data Matrix Encoding/Decoding Library
* Copyright 2010 Mike Laughton. All rights reserved.
* Copyright 2012-2016 Vadim A. Misbakh-Soloviov. All rights reserved.
*
* See LICENSE file in the main project directory for full
* terms of use and distribution.
*
* Contact:
* Vadim A. Misbakh-Soloviov <[email protected]>
* Mike Laughton <[email protected]>
*
* \file file.c
*/
/**
*
*
*/
extern DmtxByteList
dmtxByteListBuild(DmtxByte *storage, int capacity)
{
DmtxByteList list;
list.b = storage;
list.capacity = capacity;
list.length = 0;
return list;
}
/**
*
*
*/
extern void
dmtxByteListInit(DmtxByteList *list, int length, DmtxByte value, DmtxPassFail *passFail)
{
if(length > list->capacity)
{
*passFail = DmtxFail;
}
else
{
list->length = length;
memset(list->b, value, sizeof(DmtxByte) * list->capacity);
*passFail = DmtxPass;
}
}
/**
*
*
*/
extern void
dmtxByteListClear(DmtxByteList *list)
{
memset(list->b, 0x00, sizeof(DmtxByte) * list->capacity);
list->length = 0;
}
/**
*
*
*/
extern DmtxBoolean
dmtxByteListHasCapacity(DmtxByteList *list)
{
return (list->length < list->capacity) ? DmtxTrue : DmtxFalse;
}
/**
*
*
*/
extern void
dmtxByteListCopy(DmtxByteList *dst, const DmtxByteList *src, DmtxPassFail *passFail)
{
int length;
if(dst->capacity < src->length)
{
*passFail = DmtxFail; /* dst must be large enough to hold src data */
}
else
{
/* Copy as many bytes as dst can hold or src can provide (smaller of two) */
length = (dst->capacity < src->capacity) ? dst->capacity : src->capacity;
dst->length = src->length;
memcpy(dst->b, src->b, sizeof(unsigned char) * length);
*passFail = DmtxPass;
}
}
/**
*
*
*/
extern void
dmtxByteListPush(DmtxByteList *list, DmtxByte value, DmtxPassFail *passFail)
{
if(list->length >= list->capacity)
{
*passFail = DmtxFail;
}
else
{
list->b[list->length++] = value;
*passFail = DmtxPass;
}
}
/**
*
*
*/
extern DmtxByte
dmtxByteListPop(DmtxByteList *list, DmtxPassFail *passFail)
{
*passFail = (list->length > 0) ? DmtxPass : DmtxFail;
return list->b[--(list->length)];
}
/**
*
*
*/
extern void
dmtxByteListPrint(DmtxByteList *list, char *prefix)
{
int i;
if(prefix != NULL)
fprintf(stdout, "%s", prefix);
for(i = 0; i < list->length; i++)
fprintf(stdout, " %d", list->b[i]);
fputc('\n', stdout);
}