1 /* $Id: dump_config.c,v 5.24 2009/09/19 06:41:56 lirc Exp $ */
2
3 /****************************************************************************
4 ** dump_config.c ***********************************************************
5 ****************************************************************************
6 *
7 * dump_config.c - dumps data structures into file
8 *
9 * Copyright (C) 1998 Pablo d'Angelo <pablo@ag-trek.allgaeu.org>
10 *
11 */
12
13 #ifdef HAVE_CONFIG_H
14 # include <config.h>
15 #endif
16
17 #ifdef TIME_WITH_SYS_TIME
18 # include <sys/time.h>
19 # include <time.h>
20 #else
21 # ifdef HAVE_SYS_TIME_H
22 # include <sys/time.h>
23 # else
24 # include <time.h>
25 # endif
26 #endif
27
28 #include "dump_config.h"
29 #include "config_file.h"
30
fprint_comment(FILE * f,struct ir_remote * rem)31 void fprint_comment(FILE * f, struct ir_remote *rem)
32 {
33 time_t timet;
34 struct tm *tmp;
35
36 timet = time(NULL);
37 tmp = localtime(&timet);
38 fprintf(f,
39 "#\n"
40 "# this config file was automatically generated\n"
41 "# using lirc-%s(%s) on %s" "#\n" "# contributed by \n" "#\n" "# brand: %s\n"
42 "# model no. of remote control: \n" "# devices being controlled by this remote:\n" "#\n\n", VERSION,
43 hw.name, asctime(tmp), rem->name);
44 }
45
fprint_flags(FILE * f,int flags)46 void fprint_flags(FILE * f, int flags)
47 {
48 int i;
49 int begin = 0;
50
51 for (i = 0; all_flags[i].flag; i++) {
52 if (flags & all_flags[i].flag) {
53 flags &= (~all_flags[i].flag);
54 if (begin == 0)
55 fprintf(f, " flags ");
56 else if (begin == 1)
57 fprintf(f, "|");
58 fprintf(f, "%s", all_flags[i].name);
59 begin = 1;
60 }
61 }
62 if (begin == 1)
63 fprintf(f, "\n");
64 }
65
fprint_remotes(FILE * f,struct ir_remote * all)66 void fprint_remotes(FILE * f, struct ir_remote *all)
67 {
68
69 while (all) {
70 fprint_remote(f, all);
71 fprintf(f, "\n\n");
72 all = all->next;
73 }
74 }
75
fprint_remote_gap(FILE * f,struct ir_remote * rem)76 void fprint_remote_gap(FILE * f, struct ir_remote *rem)
77 {
78 if (rem->gap2 != 0) {
79 fprintf(f, " gap %u %u\n", (__u32) rem->gap, (__u32) rem->gap2);
80 } else {
81 fprintf(f, " gap %u\n", (__u32) rem->gap);
82 }
83 }
84
fprint_remote_head(FILE * f,struct ir_remote * rem)85 void fprint_remote_head(FILE * f, struct ir_remote *rem)
86 {
87 fprintf(f, "begin remote\n\n");
88 fprintf(f, " name %s\n", rem->name);
89 if (!is_raw(rem)) {
90 fprintf(f, " bits %5d\n", rem->bits);
91 }
92 fprint_flags(f, rem->flags);
93 fprintf(f, " eps %5d\n", rem->eps);
94 fprintf(f, " aeps %5d\n\n", rem->aeps);
95 if (!is_raw(rem)) {
96 if (has_header(rem)) {
97 fprintf(f, " header %5u %5u\n", (__u32) rem->phead, (__u32) rem->shead);
98 }
99 if (rem->pthree != 0 || rem->sthree != 0)
100 fprintf(f, " three %5u %5u\n", (__u32) rem->pthree, (__u32) rem->sthree);
101 if (rem->ptwo != 0 || rem->stwo != 0)
102 fprintf(f, " two %5u %5u\n", (__u32) rem->ptwo, (__u32) rem->stwo);
103 fprintf(f, " one %5u %5u\n", (__u32) rem->pone, (__u32) rem->sone);
104 fprintf(f, " zero %5u %5u\n", (__u32) rem->pzero, (__u32) rem->szero);
105 }
106 if (rem->ptrail != 0) {
107 fprintf(f, " ptrail %5u\n", (__u32) rem->ptrail);
108 }
109 if (!is_raw(rem)) {
110 if (rem->plead != 0) {
111 fprintf(f, " plead %5u\n", (__u32) rem->plead);
112 }
113 if (has_foot(rem)) {
114 fprintf(f, " foot %5u %5u\n", (__u32) rem->pfoot, (__u32) rem->sfoot);
115 }
116 }
117 if (has_repeat(rem)) {
118 fprintf(f, " repeat %5u %5u\n", (__u32) rem->prepeat, (__u32) rem->srepeat);
119 }
120 if (!is_raw(rem)) {
121 if (rem->pre_data_bits > 0) {
122 fprintf(f, " pre_data_bits %d\n", rem->pre_data_bits);
123 fprintf(f, " pre_data 0x%llX\n", (unsigned long long)rem->pre_data);
124 }
125 if (rem->post_data_bits > 0) {
126 fprintf(f, " post_data_bits %d\n", rem->post_data_bits);
127 fprintf(f, " post_data 0x%llX\n", (unsigned long long)rem->post_data);
128 }
129 if (rem->pre_p != 0 && rem->pre_s != 0) {
130 fprintf(f, " pre %5u %5u\n", (__u32) rem->pre_p, (__u32) rem->pre_s);
131 }
132 if (rem->post_p != 0 && rem->post_s != 0) {
133 fprintf(f, " post %5u %5u\n", (__u32) rem->post_p, (__u32) rem->post_s);
134 }
135 }
136 fprint_remote_gap(f, rem);
137 if (has_repeat_gap(rem)) {
138 fprintf(f, " repeat_gap %u\n", (__u32) rem->repeat_gap);
139 }
140 if (rem->suppress_repeat > 0) {
141 fprintf(f, " suppress_repeat %d\n", rem->suppress_repeat);
142 }
143 if (rem->min_repeat > 0) {
144 fprintf(f, " min_repeat %d\n", rem->min_repeat);
145 if (rem->suppress_repeat == 0) {
146 fprintf(f, "# suppress_repeat %d\n", rem->min_repeat);
147 fprintf(f, "# uncomment to suppress unwanted repeats\n");
148 }
149 }
150 if (!is_raw(rem)) {
151 if (rem->min_code_repeat > 0) {
152 fprintf(f, " min_code_repeat %d\n", rem->min_code_repeat);
153 }
154 fprintf(f, " toggle_bit_mask 0x%llX\n", (unsigned long long)rem->toggle_bit_mask);
155 if (has_toggle_mask(rem)) {
156 fprintf(f, " toggle_mask 0x%llX\n", (unsigned long long)rem->toggle_mask);
157 }
158 if (rem->rc6_mask != 0) {
159 fprintf(f, " rc6_mask 0x%llX\n", (unsigned long long)rem->rc6_mask);
160 }
161 if (has_ignore_mask(rem)) {
162 fprintf(f, " ignore_mask 0x%llX\n", (unsigned long long)rem->ignore_mask);
163 }
164 if (is_serial(rem)) {
165 fprintf(f, " baud %d\n", rem->baud);
166 fprintf(f, " serial_mode %dN%d%s\n", rem->bits_in_byte, rem->stop_bits / 2,
167 rem->stop_bits % 2 ? ".5" : "");
168 }
169 }
170 if (rem->freq != 0) {
171 fprintf(f, " frequency %u\n", rem->freq);
172 }
173 if (rem->duty_cycle != 0) {
174 fprintf(f, " duty_cycle %u\n", rem->duty_cycle);
175 }
176 fprintf(f, "\n");
177 }
178
fprint_remote_foot(FILE * f,struct ir_remote * rem)179 void fprint_remote_foot(FILE * f, struct ir_remote *rem)
180 {
181 fprintf(f, "end remote\n");
182 }
183
fprint_remote_signal_head(FILE * f,struct ir_remote * rem)184 void fprint_remote_signal_head(FILE * f, struct ir_remote *rem)
185 {
186 if (!is_raw(rem))
187 fprintf(f, " begin codes\n");
188 else
189 fprintf(f, " begin raw_codes\n\n");
190 }
191
fprint_remote_signal_foot(FILE * f,struct ir_remote * rem)192 void fprint_remote_signal_foot(FILE * f, struct ir_remote *rem)
193 {
194 if (!is_raw(rem))
195 fprintf(f, " end codes\n\n");
196 else
197 fprintf(f, " end raw_codes\n\n");
198 }
199
fprint_remote_signal(FILE * f,struct ir_remote * rem,struct ir_ncode * codes)200 void fprint_remote_signal(FILE * f, struct ir_remote *rem, struct ir_ncode *codes)
201 {
202 int i, j;
203
204 if (!is_raw(rem)) {
205 char format[30];
206 struct ir_code_node *loop;
207
208 sprintf(format, " %%-24s 0x%%0%dllX", (rem->bits + 3) / 4);
209 fprintf(f, format, codes->name, codes->code);
210 sprintf(format, " 0x%%0%dlX", (rem->bits + 3) / 4);
211 for (loop = codes->next; loop != NULL; loop = loop->next) {
212 fprintf(f, format, loop->code);
213 }
214
215 fprintf(f, "\n");
216 } else {
217 fprintf(f, " name %s\n", codes->name);
218 j = 0;
219 for (i = 0; i < codes->length; i++) {
220 if (j == 0) {
221 fprintf(f, " %7u", (__u32) codes->signals[i]);
222 } else if (j < 5) {
223 fprintf(f, " %7u", (__u32) codes->signals[i]);
224 } else {
225 fprintf(f, " %7u\n", (__u32) codes->signals[i]);
226 j = -1;
227 }
228 j++;
229 }
230 codes++;
231 if (j == 0) {
232 fprintf(f, "\n");
233 } else {
234 fprintf(f, "\n\n");
235 j = 0;
236 }
237 }
238 }
239
fprint_remote_signals(FILE * f,struct ir_remote * rem)240 void fprint_remote_signals(FILE * f, struct ir_remote *rem)
241 {
242 struct ir_ncode *codes;
243
244 fprint_remote_signal_head(f, rem);
245 codes = rem->codes;
246 while (codes->name != NULL) {
247 fprint_remote_signal(f, rem, codes);
248 codes++;
249 }
250 fprint_remote_signal_foot(f, rem);
251 }
252
fprint_remote(FILE * f,struct ir_remote * rem)253 void fprint_remote(FILE * f, struct ir_remote *rem)
254 {
255 fprint_comment(f, rem);
256 fprint_remote_head(f, rem);
257 fprint_remote_signals(f, rem);
258 fprint_remote_foot(f, rem);
259 }
260