@@ -87,7 +87,6 @@ static const char * const ALIGN_VAL[] = {
8787#define MATCH_START (x ,y ) strncasecmp(x, y, sizeof(y)-1) == 0
8888#define MATCH_KEY (s ) strcasecmp(name, s) == 0
8989#define MATCH_VALUE (s ) strcasecmp(value, s) == 0
90- #define NUM_STR_ELEMS (s ) (sizeof(s) / sizeof(char *))
9190#define SET_FLAG (var , value , flag ) ((value) ? ((var) | (flag)) : ((var) & ~(flag)))
9291extern u8 FONT_GetFromString (const char * );
9392struct display_settings Display ;
@@ -107,6 +106,8 @@ static const struct struct_map _seclabel[] =
107106 {FONT_COLOR , OFFSET_COL (struct LabelDesc , font_color )},
108107 {BG_COLOR , OFFSET_COL (struct LabelDesc , fill_color )},
109108 {OUTLINE_COLOR , OFFSET_COL (struct LabelDesc , outline_color )},
109+ {ALIGN , OFFSET_STRLIST (struct LabelDesc , align , ALIGN_VAL , ARRAYSIZE (ALIGN_VAL ))},
110+ {BOX , OFFSET_STRLIST (struct LabelDesc , style , BOX_VAL , ARRAYSIZE (BOX_VAL ))}
110111};
111112
112113static const struct struct_map _secgeneral [] =
@@ -171,50 +172,16 @@ static const struct struct_map _secbackground[] =
171172};
172173#endif
173174
174- static int handle_label (struct LabelDesc * label , const char * name , const char * value )
175- {
176- if (assign_int (label , _seclabel , MAPSIZE (_seclabel ), name , value ) == 1 )
177- return 1 ;
178- if (MATCH_KEY (BOX )) {
179- u8 idx ;
180- for (idx = 0 ; idx < NUM_STR_ELEMS (BOX_VAL ); idx ++ ) {
181- if (BOX_VAL [idx ] && MATCH_VALUE (BOX_VAL [idx ])) {
182- label -> style = idx ;
183- // For compatibility reasons,
184- // use the old alignment values as default
185- // if the new one is not yet set:
186- if (label -> align == 0 ) {
187- switch (idx ) {
188- case LABEL_CENTER : label -> align = ALIGN_CENTER ; break ;
189- case LABEL_LEFT : label -> align = ALIGN_LEFT ; break ;
190- case LABEL_RIGHT : label -> align = ALIGN_RIGHT ; break ;
191- }
192- }
193- }
194- }
195- }
196- if (MATCH_KEY (ALIGN )) {
197- u8 idx ;
198- for (idx = 0 ; idx < NUM_STR_ELEMS (ALIGN_VAL ); idx ++ ) {
199- if (ALIGN_VAL [idx ] && MATCH_VALUE (ALIGN_VAL [idx ])) {
200- label -> align = idx ;
201- }
202- }
203- }
204- return 0 ;
205- }
206-
207175static int ini_handler (void * user , const char * section , const char * name , const char * value )
208176{
209177 u8 idx ;
210178 struct display_settings * d = (struct display_settings * )user ;
211179 int value_int = atoi (value );
212180
213181 if (MATCH_START (section , FONT ) && strlen (section ) > sizeof (FONT )) {
214- for (idx = 0 ; idx < NUM_STR_ELEMS (FONT_VAL ); idx ++ ) {
182+ for (idx = 0 ; idx < ARRAYSIZE (FONT_VAL ); idx ++ ) {
215183 if (FONT_VAL [idx ] && 0 == strcasecmp (section + sizeof (FONT ), FONT_VAL [idx ])) {
216- handle_label (& d -> font [idx ], name , value );
217- return 1 ;
184+ return assign_int (& d -> font [idx ], _seclabel , ARRAYSIZE (_seclabel ), name , value );
218185 }
219186 }
220187 printf ("Couldn't parse font: %s\n" , section );
@@ -231,36 +198,36 @@ static int ini_handler(void* user, const char* section, const char* name, const
231198#endif
232199 return 1 ;
233200 }
234- if (assign_int (& d -> metrics , _secgeneral , MAPSIZE (_secgeneral ), name , value ))
201+ if (assign_int (& d -> metrics , _secgeneral , ARRAYSIZE (_secgeneral ), name , value ))
235202 return 1 ;
236203 }
237204 if (MATCH_START (section , "select" )) {
238- if (assign_int (d , _secselect , MAPSIZE (_secselect ), name , value ))
205+ if (assign_int (d , _secselect , ARRAYSIZE (_secselect ), name , value ))
239206 return 1 ;
240207 }
241208 if (MATCH_START (section , "keyboard" )) {
242- if (assign_int (& d -> keyboard , _seckeybd , MAPSIZE (_seckeybd ), name , value ))
209+ if (assign_int (& d -> keyboard , _seckeybd , ARRAYSIZE (_seckeybd ), name , value ))
243210 return 1 ;
244211 }
245212 if (MATCH_START (section , "listbox" )) {
246- if (assign_int (& d -> listbox , _seclistbox , MAPSIZE (_seclistbox ), name , value ))
213+ if (assign_int (& d -> listbox , _seclistbox , ARRAYSIZE (_seclistbox ), name , value ))
247214 return 1 ;
248215 }
249216 if (MATCH_START (section , "scrollbar" )) {
250- if (assign_int (& d -> scrollbar , _secscroll , MAPSIZE (_secscroll ), name , value ))
217+ if (assign_int (& d -> scrollbar , _secscroll , ARRAYSIZE (_secscroll ), name , value ))
251218 return 1 ;
252219 }
253220 if (MATCH_SECTION ("xygraph" )) {
254- if (assign_int (& d -> xygraph , _secxygraph , MAPSIZE (_secxygraph ), name , value ))
221+ if (assign_int (& d -> xygraph , _secxygraph , ARRAYSIZE (_secxygraph ), name , value ))
255222 return 1 ;
256223 }
257224#if (LCD_WIDTH == 480 ) || (LCD_WIDTH == 320 )
258225 if (MATCH_SECTION ("background" )) {
259- if (assign_int (& d -> background , _secbackground , MAPSIZE (_secbackground ), name , value ))
226+ if (assign_int (& d -> background , _secbackground , ARRAYSIZE (_secbackground ), name , value ))
260227 return 1 ;
261228 }
262229#endif
263- for (idx = 0 ; idx < NUM_STR_ELEMS (BARGRAPH_VAL ); idx ++ ) {
230+ for (idx = 0 ; idx < ARRAYSIZE (BARGRAPH_VAL ); idx ++ ) {
264231 if (MATCH_SECTION (BARGRAPH_VAL [idx ])) {
265232 struct disp_bargraph * graph ;
266233 enum DispFlags flag ;
@@ -279,7 +246,7 @@ static int ini_handler(void* user, const char* section, const char* name, const
279246 graph -> fg_color_pos = graph -> fg_color_neg = graph -> fg_color_zero = get_color (value );
280247 return 1 ;
281248 }
282- assign_int (graph , _secbargraph , MAPSIZE (_secbargraph ), name , value );
249+ assign_int (graph , _secbargraph , ARRAYSIZE (_secbargraph ), name , value );
283250 return 1 ;
284251 }
285252 }
@@ -307,5 +274,24 @@ u8 CONFIG_ReadDisplay()
307274 #else
308275 char filename [] = "media/config.ini" ;
309276 #endif
310- return CONFIG_IniParse (filename , ini_handler , (void * )& Display );
277+ if (CONFIG_IniParse (filename , ini_handler , (void * )& Display )) {
278+ for (int i = 0 ; i < NUM_LABELS ; i ++ ) {
279+ struct LabelDesc * label = & Display .font [i ];
280+ // For compatibility reasons,
281+ // use the old alignment values as default
282+ // if the new one is not yet set:
283+ if (label -> align == 0 ) {
284+ switch (label -> style ) {
285+ case LABEL_CENTER : label -> align = ALIGN_CENTER ; break ;
286+ case LABEL_LEFT : label -> align = ALIGN_LEFT ; break ;
287+ case LABEL_RIGHT : label -> align = ALIGN_RIGHT ; break ;
288+ default : break ;
289+ }
290+ }
291+ }
292+
293+ return 1 ;
294+ }
295+
296+ return 0 ;
311297}
0 commit comments