6d5ec0e0f34bcd6d62865ccd02ec6a565d077c48
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

1) /*
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

2)  * EtherPix library
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

3)  *
Stefan Schuermans update copyright year

Stefan Schuermans authored 7 years ago

4)  * Copyright 2010-2017 Stefan Schuermans <stefan schuermans info>
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

5)  *
6)  * This program is free software: you can redistribute it and/or modify
7)  * it under the terms of the GNU General Public License as published by
8)  * the Free Software Foundation, version 3 of the License.
9)  *
10)  *
11)  * This program is distributed in the hope that it will be useful,
12)  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13)  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14)  * GNU General Public License for more details.
15)  *
16)  * You should have received a copy of the GNU Lesser General Public License
17)  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18)  */
19) 
20) #include <errno.h>
21) #include <stdio.h>
22) #include <stdlib.h>
23) #include <string.h>
24) 
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

25) #include <etherpix/msg.h>
26) #include <etherpix/types.h>
Stefan Schuermans move internal includes

Stefan Schuermans authored 7 years ago

27) #include "const_data.h"
28) #include "constants.h"
29) #include "config.h"
30) #include "mapping.h"
31) #include "missing.h"
32) #include "net.h"
33) #include "parse.h"
34) #include "strtod_noloc.h"
35) #include "types.h"
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

36) 
37) /**
38)  * \brief process distributor from config file
39)  *
40)  * \param[in,out] p_ctx context information
41)  * \param[in] p_setting_part2 second half of setting to process
42)  * \param[in] p_value value of setting
43)  * \return 0 in case of success, -1 in case of error
44)  */
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

45) int etp_config_proc_distri(etp_config_ctx_t *p_ctx, char *p_setting_part2,
Stefan Schuermans value -> p_value for consis...

Stefan Schuermans authored 7 years ago

46)                            char *p_value)
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

47) {
48)   char *ptr;
49)   unsigned long val;
50)   unsigned int distri, out, pix, i;
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

51)   etp_distri_t *p_distri;
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

52) 
53)   /* get distributor number */
54)   val = strtoul(p_setting_part2, &ptr, 0);
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

55)   if (ptr == p_setting_part2 || *ptr != 0 || val >= ETP_DISTRI_MAX_CNT) {
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

56)     if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

57)       p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_err,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

58)                         "invalid distributor number \"%s\""
59)                         " in line %u of config file\n",
60)                         p_setting_part2, p_ctx->line_no);
61)     return -1;
62)   }
63)   distri = (unsigned int)val;
64) 
65)   /* get number of outputs and pixels */
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

66)   if (etp_parse_two_nos(p_value, &out, &pix, &ptr) || *ptr != 0) {
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

67)     if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

68)       p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_err,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

69)                         "invalid distributor size \"%s\""
70)                         " in line %u of config file\n",
Stefan Schuermans value -> p_value for consis...

Stefan Schuermans authored 7 years ago

71)                         p_value, p_ctx->line_no);
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

72)     return -1;
73)   }
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

74)   if (out >= ETP_OUTPUT_MAX_CNT) {
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

75)     if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

76)       p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_err,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

77)                         "invalid number of outputs \"%u\""
78)                         " in line %u of config file\n",
79)                         out, p_ctx->line_no);
80)     return -1;
81)   }
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

82)   if (pix >= ETP_PIXEL_MAX_CNT) {
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

83)     if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

84)       p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_err,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

85)                         "invalid number of pixels \"%u\""
86)                         " in line %u of config file\n",
87)                         pix, p_ctx->line_no);
88)     return -1;
89)   }
90) 
91)   /* check if distributor is already present */
92)   if (p_ctx->p_display->distri_ptrs[distri]) {
93)     if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

94)       p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_err,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

95)                         "duplicate definition of distributor \"%u\""
96)                         " in line %u of config file\n",
97)                         distri, p_ctx->line_no);
98)     return -1;
99)   }
100) 
101)   /* create a new distributor */
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

102)   p_distri = (etp_distri_t *)malloc(sizeof (etp_distri_t));
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

103)   if (!p_distri) {
104)     if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

105)       p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_err, "out of memory\n");
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

106)     return -1;
107)   }
108)   p_distri->distri = distri;
109)   p_distri->output_cnt = out;
110)   p_distri->pixel_cnt = pix;
Stefan Schuermans support multiple addresses...

Stefan Schuermans authored 7 years ago

111)   /* no network address yet */
112)   p_distri->addr_cnt = 0;
Stefan Schuermans add support for monochrome...

Stefan Schuermans authored 6 years ago

113)   /* RGB by default */
114)   p_distri->channels = 3;
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

115)   /* initialize mapping information */
116)   for (i = 0; i < 3; i++) {
117)     p_distri->mapping[i].base = 0.0;
118)     p_distri->mapping[i].gamma = 1.0;
119)     p_distri->mapping[i].factor = 1.0;
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

120)     etp_mapping_precalc(&p_distri->mapping[i]);
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

121)   }
122)   /* create and initialize pixel array */
123)   p_distri->p_pixels =
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

124)     (etp_pixel_t *)malloc(out * pix * sizeof (etp_pixel_t));
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

125)   if (!p_distri->p_pixels) {
126)     free(p_distri);
127)     if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

128)       p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_err, "out of memory\n");
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

129)     return -1;
130)   }
131)   for (i = 0; i < out * pix; i++) {
132)     p_distri->p_pixels[i].x = -1;
133)     p_distri->p_pixels[i].y = -1;
134)   }
Stefan Schuermans add support for monochrome...

Stefan Schuermans authored 6 years ago

135)   /* create and initialize message buffer (for up to 3 channels) */
136)   p_distri->msg_buf_len = ETP_MCUF_HDR_LEN + out * pix * 3;
137)   p_distri->p_msg_buf = (etp_u8_t *)malloc(p_distri->msg_buf_len);
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

138)   if (!p_distri->p_msg_buf) {
139)     free(p_distri->p_pixels);
140)     free(p_distri);
141)     if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

142)       p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_err, "out of memory\n");
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

143)     return -1;
144)   }
Stefan Schuermans add support for monochrome...

Stefan Schuermans authored 6 years ago

145)   memset(p_distri->p_msg_buf, 0, p_distri->msg_buf_len);
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

146)   memcpy(p_distri->p_msg_buf, etp_mcuf_hdr, ETP_MCUF_HDR_LEN);
Stefan Schuermans support more pixels per output

Stefan Schuermans authored 7 years ago

147)   p_distri->p_msg_buf[ETP_MCUF_HDR_OFS_OUTPUTS_U16 + 0] = (etp_u8_t)(out >> 8);
148)   p_distri->p_msg_buf[ETP_MCUF_HDR_OFS_OUTPUTS_U16 + 1] = (etp_u8_t)out;
149)   p_distri->p_msg_buf[ETP_MCUF_HDR_OFS_PIXELS_U16 + 0] = (etp_u8_t)(pix >> 8);
150)   p_distri->p_msg_buf[ETP_MCUF_HDR_OFS_PIXELS_U16 + 1] = (etp_u8_t)pix;
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

151)   /* store pointer to distributor */
152)   p_ctx->p_display->distri_ptrs[distri] = p_distri;
153) 
154)   /* count distributors */
155)   p_ctx->p_display->distri_cnt++;
156) 
157)   return 0;
158) }
159) 
Stefan Schuermans add support for configuring...

Stefan Schuermans authored 7 years ago

160) /**
161)  * \brief process distributor address from config file
162)  *
163)  * \param[in,out] p_ctx context information
164)  * \param[in] p_setting_part2 second half of setting to process
165)  * \param[in] p_value value of setting
166)  * \return 0 in case of success, -1 in case of error
167)  */
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

168) int etp_config_proc_distri_addr(etp_config_ctx_t *p_ctx, char *p_setting_part2,
Stefan Schuermans add support for configuring...

Stefan Schuermans authored 7 years ago

169)                                 char *p_value)
170) {
171)   char *ptr;
172)   unsigned long val;
173)   unsigned int distri;
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

174)   etp_distri_t *p_distri;
Stefan Schuermans add support for configuring...

Stefan Schuermans authored 7 years ago

175) 
176)   /* get distributor number */
177)   val = strtoul(p_setting_part2, &ptr, 0);
Stefan Schuermans stricter parsing for distri...

Stefan Schuermans authored 7 years ago

178)   if (ptr == p_setting_part2 || *ptr != 0) {
Stefan Schuermans add support for configuring...

Stefan Schuermans authored 7 years ago

179)     if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

180)       p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_err,
Stefan Schuermans add support for configuring...

Stefan Schuermans authored 7 years ago

181)                         "invalid mapping specifier \"%s\""
182)                         " in line %u of config file\n",
183)                         p_setting_part2, p_ctx->line_no);
184)     return -1;
185)   }
186)   distri = (unsigned int)val;
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

187)   if (distri >= ETP_DISTRI_MAX_CNT) {
Stefan Schuermans add support for configuring...

Stefan Schuermans authored 7 years ago

188)     if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

189)       p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_err,
Stefan Schuermans add support for configuring...

Stefan Schuermans authored 7 years ago

190)                         "invalid distributor number \"%u\""
191)                         " in line %u of config file\n",
192)                         distri, p_ctx->line_no);
193)     return -1;
194)   }
195) 
196)   /* get distributor */
197)   p_distri = p_ctx->p_display->distri_ptrs[distri];
198)   if (!p_distri) {
199)     if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

200)       p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_err,
Stefan Schuermans add support for configuring...

Stefan Schuermans authored 7 years ago

201)                         "no distributor with number \"%u\""
202)                         " in line %u of config file\n",
203)                         distri, p_ctx->line_no);
204)     return -1;
205)   }
206) 
Stefan Schuermans support multiple addresses...

Stefan Schuermans authored 7 years ago

207)   /* check if maximum number of addresses reached */
208)   if (p_distri->addr_cnt >= ETP_DISTRI_MAX_ADDRS) {
209)     if (p_ctx->p_msg_func)
210)       p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_err,
211)                         "too many addresses (\"%s\") for distributor with"
212)                         " number \"%u\" in line %u of config file\n",
213)                         p_value, distri, p_ctx->line_no);
214)     return -1;
215)   }
216) 
217)   /* get address and add it to distributor */
218)   if (etp_parse_addr(p_value, &p_distri->addrs[p_distri->addr_cnt])) {
Stefan Schuermans add support for configuring...

Stefan Schuermans authored 7 years ago

219)     if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

220)       p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_err,
Stefan Schuermans add support for configuring...

Stefan Schuermans authored 7 years ago

221)                         "invalid address \"%s\" for distributor with number"
222)                         " \"%u\" in line %u of config file\n",
223)                         p_value, distri, p_ctx->line_no);
224)     return -1;
225)   }
Stefan Schuermans support multiple addresses...

Stefan Schuermans authored 7 years ago

226)   ++p_distri->addr_cnt;
Stefan Schuermans add support for configuring...

Stefan Schuermans authored 7 years ago

227) 
228)   return 0;
229) }
230) 
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

231) /**
232)  * \brief process mapping from config file
233)  *
234)  * \param[in,out] p_ctx context information
235)  * \param[in] p_setting_part2 second half of setting to process
236)  * \param[in] p_value value of setting
237)  * \return 0 in case of success, -1 in case of error
238)  */
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

239) int etp_config_proc_mapping(etp_config_ctx_t *p_ctx, char *p_setting_part2,
Stefan Schuermans value -> p_value for consis...

Stefan Schuermans authored 7 years ago

240)                             char *p_value)
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

241) {
242)   char *ptr, *ptr2;
243)   unsigned long val;
Stefan Schuermans add support for monochrome...

Stefan Schuermans authored 6 years ago

244)   unsigned int distri, channels, chan;
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

245)   etp_distri_t *p_distri;
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

246)   double base, factor, gamma;
247) 
248)   /* get distributor number */
249)   val = strtoul(p_setting_part2, &ptr, 0);
250)   if (ptr == p_setting_part2
251)       || (*ptr != 0 && *ptr != ' ' && *ptr != '\t'
252)           && *ptr != '\r' && *ptr != '\n')) {
253)     if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

254)       p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_err,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

255)                         "invalid mapping specifier \"%s\""
256)                         " in line %u of config file\n",
257)                         p_setting_part2, p_ctx->line_no);
258)     return -1;
259)   }
260)   distri = (unsigned int)val;
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

261)   if (distri >= ETP_DISTRI_MAX_CNT) {
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

262)     if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

263)       p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_err,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

264)                         "invalid distributor number \"%u\""
265)                         " in line %u of config file\n",
266)                         distri, p_ctx->line_no);
267)     return -1;
268)   }
269) 
270)   /* get channel */
271)   while (*ptr == ' ' || *ptr == '\t' || *ptr == '\r' || *ptr == '\n')
272)     ptr++;
Stefan Schuermans add support for monochrome...

Stefan Schuermans authored 6 years ago

273)   if (!strcmp(ptr, "red")) {
274)     channels = 3;
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

275)     chan = 0;
Stefan Schuermans add support for monochrome...

Stefan Schuermans authored 6 years ago

276)   } else if (!strcmp(ptr, "green")) {
277)     channels = 3;
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

278)     chan = 1;
Stefan Schuermans add support for monochrome...

Stefan Schuermans authored 6 years ago

279)   } else if (!strcmp(ptr, "blue")) {
280)     channels = 3;
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

281)     chan = 2;
Stefan Schuermans add support for monochrome...

Stefan Schuermans authored 6 years ago

282)   } else if (!strcmp(ptr, "white")) {
283)     channels = 1;
284)     chan = 0;
285)   } else {
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

286)     if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

287)       p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_err,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

288)                         "invalid channel \"%s\""
289)                         " in line %u of config file\n", ptr,
290)                         p_ctx->line_no);
291)     return -1;
292)   }
293) 
294)   /* get distributor */
295)   p_distri = p_ctx->p_display->distri_ptrs[distri];
296)   if (!p_distri) {
297)     if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

298)       p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_err,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

299)                         "no distributor with number \"%u\""
300)                         " in line %u of config file\n",
301)                         distri, p_ctx->line_no);
302)     return -1;
303)   }
304) 
305)   /* get mapping parameters: base, factor, gamma */
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

306)   base = etp_strtod_noloc(p_value, &ptr);
Stefan Schuermans value -> p_value for consis...

Stefan Schuermans authored 7 years ago

307)   if (ptr == p_value
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

308)       || (*ptr != 0 && *ptr != ' ' && *ptr != '\t'
309)           && *ptr != '\r' && *ptr != '\n')) {
310)     if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

311)       p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_err,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

312)                         "invalid mapping parameters \"%s\""
313)                         " in line %u of config file\n",
Stefan Schuermans value -> p_value for consis...

Stefan Schuermans authored 7 years ago

314)                         p_value, p_ctx->line_no);
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

315)     return -1;
316)   }
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

317)   factor = etp_strtod_noloc(ptr, &ptr2);
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

318)   if (ptr2 == ptr
319)       || (*ptr2 != 0 && *ptr2 != ' ' && *ptr2 != '\t'
320)           && *ptr2 != '\r' && *ptr2 != '\n')) {
321)     if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

322)       p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_err,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

323)                         "invalid mapping parameters \"%s\""
324)                         " in line %u of config file\n",
Stefan Schuermans value -> p_value for consis...

Stefan Schuermans authored 7 years ago

325)                         p_value, p_ctx->line_no);
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

326)     return -1;
327)   }
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

328)   gamma = etp_strtod_noloc(ptr2, &ptr);
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

329)   if (ptr == ptr2
330)       || (*ptr != 0 && *ptr != ' ' && *ptr != '\t'
331)           && *ptr != '\r' && *ptr != '\n')) {
332)     if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

333)       p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_err,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

334)                         "invalid mapping parameters \"%s\""
335)                         " in line %u of config file\n",
Stefan Schuermans value -> p_value for consis...

Stefan Schuermans authored 7 years ago

336)                         p_value, p_ctx->line_no);
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

337)     return -1;
338)   }
339)   if (gamma <= 0.0) {
340)     if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

341)       p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_err,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

342)                         "invalid gamma value \"%f\""
343)                         " in line %u of config file\n",
344)                         gamma, p_ctx->line_no);
345)     return -1;
346)   }
347) 
Stefan Schuermans add support for monochrome...

Stefan Schuermans authored 6 years ago

348)   /* store number of channels as well as new mapping parameters
349)    * and re-calculate mapping table */
350)   p_distri->channels = channels;
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

351)   p_distri->mapping[chan].base = base;
352)   p_distri->mapping[chan].factor = factor;
353)   p_distri->mapping[chan].gamma = gamma;
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

354)   etp_mapping_precalc(&p_distri->mapping[chan]);
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

355) 
Stefan Schuermans add support for monochrome...

Stefan Schuermans authored 6 years ago

356)   /* update channel count in message buffer and message length
357)    * (buffer is allocated for 3 channels on distri creation, so this is ok) */
358)   p_distri->p_msg_buf[ETP_MCUF_HDR_OFS_CHANNELS_U16 + 0]
359)                                                   = (etp_u8_t)(channels >> 8);
360)   p_distri->p_msg_buf[ETP_MCUF_HDR_OFS_CHANNELS_U16 + 1] = (etp_u8_t)channels;
361)   p_distri->msg_len = ETP_MCUF_HDR_LEN +
362)                       p_distri->output_cnt * p_distri->pixel_cnt * channels;
363) 
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

364)   return 0;
365) }
366) 
367) /**
368)  * \brief process pixel from config file
369)  *
370)  * \param[in,out] p_ctx context information
371)  * \param[in] sz_pixel text of pixel to process
372)  * \param[in] distri number of distributor
373)  * \param[in] out number of output
374)  * \param[in] pix number of pixel
375)  * \return 0 in case of success, -1 in case of error
376)  */
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

377) int etp_config_proc_pixel(etp_config_ctx_t *p_ctx, char *sz_pixel,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

378)                           unsigned int distri, unsigned int out,
379)                           unsigned int pix)
380) {
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

381)   etp_distri_t *p_distri = p_ctx->p_display->distri_ptrs[distri];
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

382)   char *ptr;
383)   unsigned int x, y, idx;
384) 
385)   /* get coordinates of pixel */
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

386)   if (etp_parse_two_nos(sz_pixel, &x, &y, &ptr) || *ptr != 0
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

387)       || (int)x < 0 || (int)x >= p_ctx->p_display->size.x
388)       || (int)y < 0 || (int)y >= p_ctx->p_display->size.y) {
389)     if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

390)       p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_err,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

391)                         "invalid pixel \"%s\""
392)                         " in line %u of config file\n",
393)                         sz_pixel, p_ctx->line_no);
394)     return -1;
395)   }
396) 
397)   /* check pixel number */
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

398)   if (pix >= ETP_PIXEL_MAX_CNT || pix >= p_distri->pixel_cnt) {
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

399)     if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

400)       p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_err,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

401)                         "too many pixels (more than %u)"
402)                         " in line %u of config file\n",
403)                         p_distri->pixel_cnt, p_ctx->line_no);
404)     return -1;
405)   }
406) 
407)   /* check that pixel is not yet set */
408)   idx = out * p_distri->pixel_cnt + pix;
409)   if (p_distri->p_pixels[idx].x >= 0
410)       && p_distri->p_pixels[idx].y >= 0) {
411)     if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

412)       p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_err,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

413)                         "pixel %u of output %u of distributor %u already set"
414)                         " to pixel %u,%u in line %u of config file\n",
415)                         pix, out, distri, p_distri->p_pixels[idx].x,
416)                  p_distri->p_pixels[idx].y, p_ctx->line_no);
417)     return -1;
418)   }
419) 
420)   /* set pixel coordinates */
421)   p_distri->p_pixels[idx].x = x;
422)   p_distri->p_pixels[idx].y = y;
423) 
424)   /* count pixels in total */
425)   p_ctx->p_display->pixel_cnt++;
426) 
427)   return 0;
428) }
429) 
430) /**
431)  * \brief process output from config file
432)  *
433)  * \param[in,out] p_ctx context information
434)  * \param[in] p_setting_part2 second half of setting to process
435)  * \param[in] p_value value of setting
436)  * \return 0 in case of success, -1 in case of error
437)  */
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

438) int etp_config_proc_output(etp_config_ctx_t *p_ctx, char *p_setting_part2,
Stefan Schuermans value -> p_value for consis...

Stefan Schuermans authored 7 years ago

439)                            char *p_value)
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

440) {
441)   char *ptr, *p_pos, *p_white, white;
442)   unsigned int distri, out, pix;
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

443)   etp_distri_t *p_distri;
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

444)   int err;
445) 
446)   /* get number of distributor and output */
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

447)   if (etp_parse_two_nos(p_setting_part2, &distri, &out, &ptr) || *ptr != 0) {
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

448)     if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

449)       p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_err,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

450)                         "invalid output specifier \"%s\""
451)                         " in line %u of config file\n",
452)                         p_setting_part2, p_ctx->line_no);
453)     return -1;
454)   }
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

455)   if (distri >= ETP_DISTRI_MAX_CNT) {
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

456)     if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

457)       p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_err,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

458)                         "invalid distributor number \"%u\""
459)                         " in line %u of config file\n",
460)                         distri, p_ctx->line_no);
461)     return -1;
462)   }
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

463)   if (out >= ETP_OUTPUT_MAX_CNT) {
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

464)     if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

465)       p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_err,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

466)                         "invalid output number \"%u\""
467)                         " in line %u of config file\n",
468)                         out, p_ctx->line_no);
469)     return -1;
470)   }
471) 
472)   /* get distributor */
473)   p_distri = p_ctx->p_display->distri_ptrs[distri];
474)   if (!p_distri) {
475)     if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

476)       p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_err,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

477)                         "no distributor with number \"%u\""
478)                         " in line %u of config file\n",
479)                         distri, p_ctx->line_no);
480)     return -1;
481)   }
482)   /* check output number */
483)   if (out >= p_distri->output_cnt) {
484)     if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

485)       p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_err,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

486)                         "no output with output number \"%u\""
487)                         " in line %u of config file\n",
488)                         out, p_ctx->line_no);
489)     return -1;
490)   }
491) 
492)   /* count outputs */
493)   p_ctx->p_display->output_cnt++;
494) 
495)   /* process pixels */
496) 
497)   /* process all parts separated by whitespace */
Stefan Schuermans value -> p_value for consis...

Stefan Schuermans authored 7 years ago

498)   p_pos = p_value;
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

499)   err = 0;
500)   pix = 0;
501)   while (*p_pos != 0) {
502) 
503)     /* get end of item (first whitespace) */
504)     for (p_white = p_pos;
505)          *p_white && *p_white != ' ' && *p_white != '\t'
506)          && *p_white != '\r' && *p_white != '\n'; p_white++);
507) 
508)     /* process item: a pixel */
509)     white = *p_white; /* terminate item */
510)     *p_white = 0;
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

511)     if (etp_config_proc_pixel(p_ctx, p_pos, distri, out, pix)) /* process */
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

512)       err = -1;       /* remember errors */
513)     pix++;            /* count pixels */
514)     *p_white = white; /* undo termination */
515) 
516)     /* skip whitespace and continue after it */
517)     for (;
518)          *p_white == ' ' || *p_white == '\t'
519)          || *p_white == '\r' || *p_white == '\n'; p_white++);
520)     p_pos = p_white;
521) 
522)   } /* while (*p_pos != 0) */
523) 
524)   return err;
525) }
526) 
527) /**
528)  * \brief process setting from config file
529)  *
530)  * \param[in,out] p_ctx context information
531)  * \param[in] p_setting setting to process
532)  * \param[in] p_value value of setting
533)  * \return 0 in case of success, -1 in case of error
534)  */
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

535) int etp_config_proc_setting(etp_config_ctx_t *p_ctx, char *p_setting,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

536)                             char *p_value)
537) {
538)   char *ptr;
539)   unsigned int x, y;
540) 
541)   /* replace all whitespace with spaces in setting */
542)   while ((ptr = strchr(p_setting, '\t')))
543)     *ptr = ' ';
544)   while ((ptr = strchr(p_setting, '\r')))
545)     *ptr = ' ';
546)   while ((ptr = strchr(p_setting, '\n')))
547)     *ptr = ' ';
548) 
549)   /* bind address for UDP output */
550)   if (!strcmp(p_setting, "bindAddr")) {
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

551)     if (etp_parse_addr(p_value, &p_ctx->p_display->bind_addr)) {
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

552)       if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

553)         p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_err,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

554)                           "invalid address \"%s\" for \"%s\""
555)                           " in line %u of config file\n",
556)                           p_value, p_setting, p_ctx->line_no);
557)       return -1;
558)     }
559)     if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

560)       p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_info, "bind address: %s\n", p_value);
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

561)     return 0;
562)   }
563) 
564)   /* size of display */
565)   if (!strcmp(p_setting, "size")) {
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

566)     if (etp_parse_two_nos(p_value, &x, &y, &ptr)
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

567)         || (int)x <= 0 || (int)y <= 0) {
568)       if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

569)         p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_err,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

570)                           "invalid value \"%s\" for \"%s\""
571)                           " in line %u of config file\n",
572)                           p_value, p_setting, p_ctx->line_no);
573)       return -1;
574)     }
575)     p_ctx->p_display->size.x = x;
576)     p_ctx->p_display->size.y = y;
577)     return 0;
578)   }
579) 
580)   /* distributor */
581)   if (!strncmp(p_setting, "distributor ", 12))
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

582)     return etp_config_proc_distri(p_ctx, p_setting + 12, p_value);
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

583) 
Stefan Schuermans add support for configuring...

Stefan Schuermans authored 7 years ago

584)   /* distributor address */
585)   if (!strncmp(p_setting, "distributorAddr ", 16))
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

586)     return etp_config_proc_distri_addr(p_ctx, p_setting + 16, p_value);
Stefan Schuermans add support for configuring...

Stefan Schuermans authored 7 years ago

587) 
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

588)   /* mapping */
589)   if (!strncmp(p_setting, "mapping ", 8))
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

590)     return etp_config_proc_mapping(p_ctx, p_setting + 8, p_value);
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

591) 
592)   /* output */
593)   if (!strncmp(p_setting, "output ", 7))
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

594)     return etp_config_proc_output(p_ctx, p_setting + 7, p_value);
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

595) 
596)   /* unknown setting */
597)   if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

598)     p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_warn,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

599)                       "unknown setting \"%s\""
600)                       " in line %u of config file, ignored\n",
601)                       p_setting, p_ctx->line_no);
602)   return 0;
603) }
604) 
605) /**
606)  * \brief process line from config file
607)  *
608)  * \param[in,out] p_ctx context information
609)  * \param[in] p_line line to process
610)  * \return 0 in case of success, -1 in case of error
611)  */
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

612) int etp_config_proc_line(etp_config_ctx_t *p_ctx, char *p_line)
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

613) {
614)   char *p_hash, *p_equal, *p_setting, *p_value;
615)   int i;
616) 
617)   /* remove comment */
618)   p_hash = strchr(p_line, '#');
619)   if (p_hash)
620)     *p_hash = 0;
621) 
622)   /* remove trailing whitespace */
623)   for (i = strlen(p_line) - 1;
624)        i >= 0 && (p_line[i] == ' ' || p_line[i] == '\t'
625)                   || p_line[i] == '\r' || p_line[i] == '\n'); i--)
626)     p_line[i] = 0;
627) 
628)   /* remove leading whitespace */
629)   for (; *p_line == ' ' || *p_line == '\t'
630)          || *p_line == '\r' || *p_line == '\n'; p_line++);
631) 
632)   /* ignore empty line */
633)   if (!p_line[0])
634)     return 0;
635) 
636)   /* find equal sign */
637)   p_equal = strchr(p_line, '=');
638)   if (!p_equal) {               /* no equal sign found */
639)     if (p_ctx->p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

640)       p_ctx->p_msg_func(p_ctx->p_msg_ctx, etp_msg_type_warn,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

641)                         "invalid line %u in config file, ignored\n",
642)                         p_ctx->line_no);
643)     return 0;
644)   }
645) 
646)   /* split string at equal sign */
647)   *p_equal = 0;
648)   p_setting = p_line;
649)   p_value = p_equal + 1;
650) 
651)   /* remove trailing whitespaces in setting name */
652)   for (i = strlen(p_setting) - 1;
653)        i >= 0 && (p_setting[i] == ' ' || p_setting[i] == '\t'
654)                   || p_setting[i] == '\r' || p_setting[i] == '\n'); i--)
655)     p_setting[i] = 0;
656) 
657)   /* remove leading whitespaces in value */
658)   for (; *p_value == ' ' || *p_value == '\t'
659)          || *p_value == '\r' || *p_value == '\n'; p_value++);
660) 
661)   /* process setting */
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

662)   return etp_config_proc_setting(p_ctx, p_setting, p_value);
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

663) }
664) 
Stefan Schuermans support multiple addresses...

Stefan Schuermans authored 7 years ago

665) /**
666)  * \brief set default addresses of distributors
667)  * \param[in,out] p_ctx context information
668)  */
669) static void etp_config_set_def_distri_addrs(etp_config_ctx_t *p_ctx)
670) {
671)   unsigned int distri;
672)   etp_distri_t *p_distri;
673) 
674)   /* set default addresses of distributors */
675)   for (distri = 0; distri < ETP_DISTRI_MAX_CNT; distri++) {
676)     p_distri = p_ctx->p_display->distri_ptrs[distri];
677)     if (p_distri) {
678) 
679)       /* no address yet -> use default */
680)       if (p_distri->addr_cnt == 0) {
681)         p_distri->addr_cnt = 1;
682)         p_distri->addrs[0].sin_family = AF_INET;
683)         p_distri->addrs[0].sin_addr.s_addr =
684)             htonl(ETP_DEST_IP_BASE + p_distri->distri * ETP_DEST_IP_STEP);
685)         p_distri->addrs[0].sin_port = htons(ETP_DEST_PORT);
686)       }
687) 
688)     }  // if (p_distri)
689)   } // for (distri ...)
690) }
691) 
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

692) /**
693)  * \brief process config file
694)  *
695)  * \param[in,out] p_display display to configure
696)  * \param[in] sz_config_file name of config file to read
697)  * \param[in] p_msg_func message callback function or NULL
698)  * \param[in] p_msg_ctx user context for message callback
699)  * \return 0 in case of success, -1 in case of error
700)  */
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

701) int etp_config_proc_file(etp_display_t *p_display,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

702)                          const char *sz_config_file,
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

703)                          etp_msg_func_p_t p_msg_func, void *p_msg_ctx)
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

704) {
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

705)   etp_config_ctx_t ctx;
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

706)   FILE *file;
707) 
708)   /* set up context */
709)   ctx.p_display = p_display;
710)   ctx.p_msg_func = p_msg_func;
711)   ctx.p_msg_ctx = p_msg_ctx;
712) 
713)   /* check if file is present */
714)   if (!sz_config_file || !sz_config_file[0]) {
715)     if (p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

716)       p_msg_func(p_msg_ctx, etp_msg_type_err,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

717)                  "no config file specified\n");
718)     return -1;
719)   }
720) 
721)   if (p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

722)     p_msg_func(p_msg_ctx, etp_msg_type_info,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

723)                "using config file \"%s\"\n",
724)                sz_config_file);
725) 
726)   /* open file */
727)   file = fopen(sz_config_file, "rt");
728)   if (!file) {
Stefan Schuermans v1.0.2

Stefan Schuermans authored 13 years ago

729)     if (p_msg_func) {
730)       char errmsg[256];
731)       strerror_r(errno, errmsg, sizeof(errmsg));
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

732)       p_msg_func(p_msg_ctx, etp_msg_type_err,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

733)                  "cannot open config file \"%s\" for reading: %s\n",
Stefan Schuermans v1.0.2

Stefan Schuermans authored 13 years ago

734)                  sz_config_file, errmsg);
735)     }
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

736)     return -1;
737)   }
738) 
739)   /* process lines in file */
740)   ctx.line_no = 1;
741)   while (!feof(file)) {
742)     char line[4096], *p_lf;
743) 
744)     /* read a line */
745)     line[0] = 0;
Stefan Schuermans adaptions for gcc 5

Stefan Schuermans authored 7 years ago

746)     if (fgets(line, sizeof (line), file) == NULL)
747)       break;
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

748)     p_lf = strchr(line, '\n'); /* find LF in line in replace it with 0 */
749)     if (p_lf)
750)       *p_lf = 0;
751)     else {                     /* no LF in line */
752)       if (!feof(file)) {       /* not at end of file */
753)         char dummy[4096];
754)         if (p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

755)           p_msg_func(p_msg_ctx, etp_msg_type_warn,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

756)                      "line %u too long in config file, truncated\n",
757)                      ctx.line_no);
758)         /* jump over in rest of line */
759)         dummy[0] = 0;
760)         while (!feof(file) && !strchr(dummy, '\n'))
Stefan Schuermans adaptions for gcc 5

Stefan Schuermans authored 7 years ago

761)           if (fgets(dummy, sizeof (dummy), file) == NULL)
762)             break;
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

763)       }
764)     }
765) 
766)     /* process line from file */
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

767)     if (etp_config_proc_line(&ctx, line))
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

768)       return -1;
769) 
770)     ctx.line_no++;
771)   }
772) 
773)   /* close file */
774)   fclose(file);
775) 
Stefan Schuermans support multiple addresses...

Stefan Schuermans authored 7 years ago

776)   /* set default addresses of distributors */
777)   etp_config_set_def_distri_addrs(&ctx);
778) 
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

779)   if (p_msg_func)
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

780)     p_msg_func(p_msg_ctx, etp_msg_type_info,