blob: c791ddf67ca8d90984ea8aa844258012b4c8e657 (
plain)
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
|
#include "emb-stitch.h"
#include "emb-logging.h"
#include <stdio.h>
#include <stdlib.h>
EmbStitchList* embStitchList_create(EmbStitch data)
{
EmbStitchList* heapStitchList = (EmbStitchList*)malloc(sizeof(EmbStitchList));
if(!heapStitchList) { embLog_error("emb-stitch.c embStitchList_create(), cannot allocate memory for heapStitchList\n"); return 0; }
heapStitchList->stitch = data;
heapStitchList->next = 0;
return heapStitchList;
}
EmbStitchList* embStitchList_add(EmbStitchList* pointer, EmbStitch data)
{
if(!pointer) { embLog_error("emb-stitch.c embStitchList_add(), pointer argument is null\n"); return 0; }
if(pointer->next) { embLog_error("emb-stitch.c embStitchList_add(), pointer->next should be null\n"); return 0; }
pointer->next = (EmbStitchList*)malloc(sizeof(EmbStitchList));
if(!pointer->next) { embLog_error("emb-stitch.c embStitchList_add(), cannot allocate memory for pointer->next\n"); return 0; }
pointer = pointer->next;
pointer->stitch = data;
pointer->next = 0;
return pointer;
}
EmbStitch embStitchList_getAt(EmbStitchList* pointer, int num)
{
/* TODO: pointer safety */
int i;
for(i = 0; i < num; i++)
{
pointer = pointer->next;
}
return pointer->stitch;
}
/* TODO: Add a default parameter to handle returning count based on stitch flags. Currently, it includes JUMP and TRIM stitches, maybe we just want NORMAL stitches only or vice versa */
int embStitchList_count(EmbStitchList* pointer)
{
int i = 1;
if(!pointer) return 0;
while(pointer->next)
{
pointer = pointer->next;
i++;
}
return i;
}
int embStitchList_empty(EmbStitchList* pointer)
{
if(!pointer)
return 1;
return 0;
}
void embStitchList_free(EmbStitchList* pointer)
{
EmbStitchList* tempPointer = pointer;
EmbStitchList* nextPointer = 0;
while(tempPointer)
{
nextPointer = tempPointer->next;
free(tempPointer);
tempPointer = nextPointer;
}
pointer = 0;
}
/* kate: bom off; indent-mode cstyle; indent-width 4; replace-trailing-space-save on; */
|