-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport.c
106 lines (87 loc) · 2.41 KB
/
export.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
/*
@file export.c
Copyright 2011, Paul Chambers. All Rights Reserved.
*/
#include "common.h"
#include <sys/param.h>
#include <errno.h>
#include <dirent.h>
#include "analyse-ir-codes.h"
#include "export.h"
int exportIRStream( FILE *file, const char prefix, tIRStream *stream)
{
tCount i, count;
char sep = prefix;
if (stream != NULL)
{
count = stream->count;
i = 0;
while ( i < count )
{
fprintf(file, "%c%lu", sep, stream->period[i++]);
if (ferror(file)) return 0;
sep = ',';
}
}
return 1;
}
int exportDB( FILE * file )
{
const char *repeatStr;
tIRCodeSet *codeSet;
tIRCode *code;
codeSet = gIRCodeSets;
if (codeSet != NULL)
code = codeSet->irCodes;
while ( codeSet != NULL )
{
/* dump this IR code */
switch (code->fingerprint.repeatType)
{
case kFullRepeat: repeatStr = "Full_Repeat"; break;
case kPartialRepeat: repeatStr = "Partial_Repeat"; break;
case kRepeat: repeatStr = "Repeat"; break;
case kToggleRepeat: repeatStr = "Toggle"; break;
default: repeatStr = "Unknown"; break;
}
fprintf( file, "%u|%lu|%s|%s",
codeSet->id,
code->fingerprint.carrierFreq,
repeatStr,
code->button.label);
if (ferror(file)) break;
if (code->first.a != NULL)
{
if ( !exportIRStream( file, '|', code->first.a ) ) break;
}
else putc('|', file);
if (code->first.b != NULL)
{
if ( !exportIRStream( file, '^', code->first.b ) ) break;
}
if (code->repeat.a != NULL)
{
if ( !exportIRStream( file, '|', code->repeat.a ) ) break;
}
else putc('|', file);
if (code->repeat.b != NULL)
{
if ( !exportIRStream( file, '^', code->repeat.b ) ) break;
}
fprintf(file, "|\r\n");
/* advance to the next IR code */
code = code->next;
if (code == NULL)
{
codeSet = codeSet->next;
if (codeSet != NULL)
code = codeSet->irCodes;
}
}
if (ferror(file))
{
logDebugErrno(0, "error writing to output");
return (-3);
}
return (0);
}