mbgtools-lx  4.2.8
ctry.c
Go to the documentation of this file.
1 
2 /**************************************************************************
3  *
4  * $Id: ctry.c 1.7 2010/07/15 08:26:57 martin REL_M $
5  *
6  * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
7  *
8  * Description:
9  * Functions providing support for different country settings
10  * and languages.
11  *
12  * Some OS dependent functions may be required which can be found
13  * in the OS dependent modules ctry_xxx.c.
14  *
15  * -----------------------------------------------------------------------
16  * $Log: ctry.c $
17  * Revision 1.7 2010/07/15 08:26:57 martin
18  * Added clstr_lng() implemented by stefan returning a translated string
19  * by giving the different strings as function arguments.
20  * Revision 1.6 2007/03/29 12:21:51 martin
21  * New functions lstr_idx() and lstr_array_idx().
22  * Revision 1.5 2004/10/26 07:39:37Z martin
23  * Use C99 fixed-size definitions where appropriate.
24  * Revision 1.4 2001/09/14 12:02:12 MARTIN
25  * Modified parameters for lstr_lng().
26  * Revision 1.3 2000/11/27 14:09:24 MARTIN
27  * Replaced lstr() by lstr_lng() with takes a language paramter to allow
28  * retrieval of strings for another than the current language.
29  * A new macro _lstr() has been added to ctry.h which calls lstr_lng()
30  * passing the current language.
31  * The functions ctry_fmt_dt() and ctry_fmt_times() and associated
32  * definitions have been moved to a new module ctry_fmt.c/ctry_fmt.h.
33  * Revision 1.2 2000/07/21 10:00:08 MARTIN
34  * Initial revision
35  *
36  **************************************************************************/
37 
38 #define _CTRY
39  #include <ctry.h>
40 #undef _CTRY
41 
42 #include <stdio.h>
43 #include <stdarg.h>
44 #include <string.h>
45 
46 
47 // Return the index of a CLSTR component for a
48 // certain language lng
49 
50 /*HDR*/
51 int lstr_idx( CLSTR s, int lng )
52 {
53  if ( lng >= N_LNG ) // if lng out of range
54  return 0; // use default index
55 
56  // If there are duplicate strings for several languages
57  // then the duplicate strings may be NULL, in which case
58  // the string at index 0 must be used.
59  return s[lng] ? lng : 0;
60 
61 } // lstr_idx
62 
63 
64 
65 // Return the index of a CLSTR component for a
66 // certain language lng out of an array of CLSTRs.
67 // CLSTR s: the array of CLSTRs
68 // int idx: the index of the array element
69 // int n_lng: the number of supported languages
70 // int lng: the language for which the inex shall be retrieved
71 
72 /*HDR*/
73 int lstr_array_idx( CLSTR s, int idx, int n_lng, int lng )
74 {
75  int str_idx = n_lng * idx;
76  return str_idx + lstr_idx( &s[str_idx], lng );
77 
78 } // lstr_array_idx
79 
80 
81 
82 /*HDR*/
83 const char *lstr_lng( CLSTR s, int lng )
84 {
85  return s[lstr_idx( s, lng)];
86 
87 } // lstr_lng
88 
89 
90 
91 /*HDR*/
92 void ctry_setup( CTRY_CODE code )
93 {
95  ctry.code = code;
96 
97  switch ( code )
98  {
99  case CTRY_US:
104  break;
105 
106 
107  case CTRY_UK:
112  break;
113 
114 
115  default:
118 
123 
124  } /* switch */
125 
126 
127 } /* ctry_setup */
128 
129 
130 
131 /*HDR*/
132 void ctry_next( void )
133 {
134  switch ( ctry.code )
135  {
136  case CTRY_GERMANY:
137  ctry_setup( CTRY_US );
138  break;
139 
140  case CTRY_US:
141  ctry_setup( CTRY_UK );
142  break;
143 
144  default:
146  break;
147 
148  } // switch
149 
150 } // ctry_next
151 
152 
153 
154 /*HDR*/
155 const char *clstr_lng( int index, ... )
156 {
157  const char *ret;
158  const char *default_ret;
159  int i;
160  typedef char *MY_LSTR;
161 
162  va_list ap;
163  va_start( ap, index );
164 
165  ret = va_arg( ap, MY_LSTR );
166  default_ret = ret;
167 
168  for ( i = 1; ( i <= index ) && ( ret != NULL ); i++ )
169  ret = va_arg( ap, MY_LSTR );
170 
171  va_end( ap );
172 
173  return ret ? ret : default_ret;
174 
175 } // clstr_lng
176 
uint16_t CTRY_CODE
Definition: ctry.h:98
const char * clstr_lng(int index,...)
Definition: ctry.c:155
void ctry_next(void)
Definition: ctry.c:132
#define CTRY_GERMANY
Definition: ctry.h:138
const char *const CLSTR[N_LNG]
Definition: ctry.h:118
void ctry_setup(CTRY_CODE code)
Definition: ctry.c:92
LANGUAGE language
Definition: mbgstatus.c:125
#define TM_SEP_COLON
Definition: ctry.h:173
#define DT_SEP_MINUS
Definition: ctry.h:165
int lstr_idx(CLSTR s, int lng)
Definition: ctry.c:51
char tm_sep
Definition: ctry.h:131
CTRY_CODE code
Definition: ctry.h:126
int lstr_array_idx(CLSTR s, int idx, int n_lng, int lng)
Definition: ctry.c:73
uint8_t tm_fmt
Definition: ctry.h:129
unsigned idx
Definition: cfg_hlp.h:735
const char * lstr_lng(CLSTR s, int lng)
Definition: ctry.c:83
#define CTRY_US
Definition: ctry.h:136
uint8_t dt_fmt
Definition: ctry.h:128
Definition: ctry.h:106
CTRY ctry
Definition: mbgstatus.c:126
#define DT_SEP_DOT
Definition: ctry.h:164
#define CTRY_UK
Definition: ctry.h:137
char dt_sep
Definition: ctry.h:130
#define DT_SEP_SLASH
Definition: ctry.h:166