CHDK_DE Vorschauversion  Trunk Rev. 5663
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
makelang.c-Dateireferenz
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include "../core/gui_lang.h"
+ Include-Abhängigkeitsdiagramm für makelang.c:

gehe zum Quellcode dieser Datei

Funktionen

void load_conditions (char *file)
 
char * is_conditional (int id)
 
char * load_from_file (const char *filename)
 
void lang_load_from_mem (char *buf)
 
int main (int argc, char **argv)
 
char * skip_space (char *p)
 
char * next_token (char *p, char *buf)
 

Variablen

char ** lang_conditions
 
int num_lines =0
 
char ** langfile = 0
 

Dokumentation der Funktionen

char * is_conditional ( int  id)

Definiert in Zeile 274 der Datei makelang.c.

275 {
276  if (lang_conditions && (id>=1) && (id<=GUI_LANG_ITEMS) && lang_conditions[id])
277  {
278  return lang_conditions[id];
279  }
280  return 0;
281 }
void lang_load_from_mem ( char *  buf)

Definiert in Zeile 138 der Datei makelang.c.

139 {
140  char *p, *s, *e;
141  int i;
142 
143  if ( !buf )
144  return;
145 
146  e = buf-1;
147  while(e)
148  {
149  p = e+1;
150  while (*p && (*p=='\r' || *p=='\n')) ++p; //skip empty lines
151  i = strtol(p, &e, 0/*autodetect base oct-dec-hex*/); // convert "*p" to long "i" and return pointer beyond to e
152 
153  if ( !langfile ) {
154  if ( i >= num_lines ) {
155  num_lines = i;
156  }
157  e = strpbrk(p, "\r\n"); //find eol
158  continue;
159  }
160 
161  if (e!=p) {
162  p = e;
163  e = strpbrk(p, "\r\n"); //break string with zero on \r|\n
164  if (e) *e=0;
165 
166  while (*p && *p!='\"') ++p; // cut string from "" if it exists
167  if (*p) ++p;
168  s = p;
169  while (*p && (*p!='\"' || *(p-1)=='\\')) ++p;
170  *p=0;
171 
172  langfile[i]=s; // add string
173  }
174  else {
175  //skip invalid line
176  e = strpbrk(p, "\r\n");
177  if (e) *e=0;
178  }
179  }
180 }
void load_conditions ( char *  file)

Definiert in Zeile 223 der Datei makelang.c.

224 {
225  lang_conditions = 0;
226 
227  char *buf = load_from_file(file);
228 
229  if (!buf)
230  return;
231 
232  lang_conditions = malloc(sizeof(char*) * (GUI_LANG_ITEMS+1));
233  memset(lang_conditions, 0, sizeof(char*) * (GUI_LANG_ITEMS+1));
234 
235  char *p, *e;
236  char name[500];
237  char index[20];
238  char cond[200];
239  int i;
240 
241  e = buf;
242  while (e && *e)
243  {
244  p = e;
245  if (strncmp(p, "#define", 7) == 0)
246  {
247  p = next_token(p+7, name);
248  if (p)
249  {
250  p = next_token(p, index);
251  if (p)
252  {
253  p = next_token(p, cond);
254  if (p && (strcmp(cond, "//CONDITIONAL:") == 0))
255  {
256  p = next_token(p, cond);
257  if (p)
258  {
259  i = atoi(index);
260  lang_conditions[i] = malloc(strlen(cond)+1);
261  strcpy(lang_conditions[i], cond);
262  }
263  }
264  }
265  }
266  }
267  e = strpbrk(e, "\n");
268  if (e) e++;
269  }
270 
271  free(buf);
272 }
char* load_from_file ( const char *  filename)
int main ( int  argc,
char **  argv 
)

Definiert in Zeile 29 der Datei makelang.c.

30 {
31  int i;
32 
33  if ( argc < 3 )
34  {
35  printf("#error No arguments for language file parser. lang_str.h creation was failed\n");
36  exit(-1);
37  }
38 
39  num_lines=0;
40 
41  load_conditions(argv[1]);
42 
43  char* file1 = load_from_file(argv[2]);
44  char* file2 = 0;
45  if ( argc > 3 )
46  file2 = load_from_file(argv[3]);
47 
48  // Do calculation num of lang strings
49  lang_load_from_mem ( file1 );
50  lang_load_from_mem ( file2 );
51 
52  if ( num_lines <= 0 )
53  {
54  printf("#error No strings found by language file parser. lang_str.h creation was failed\n");
55  exit(-1);
56  }
57 
58  // Create array
59  langfile = malloc( sizeof(char*)*(num_lines+1) );
60  for ( i=0; i<=num_lines; i++ )
61  { langfile[i]=0; }
62 
63  // Load lang files
64  lang_load_from_mem ( file1 );
65  lang_load_from_mem ( file2 );
66 
67 
68  char* lng_filename = (argc>2 && file2) ? argv[2] : argv[1];
69 
70  int num_empty_lines=0;
71  char buf[500];
72 
73  printf("//Auto generated file. Do not edit the contents of this file.\n//Update the CHDK/LANG/*.lng files to make changes.\n//Generated from %s\n\n",lng_filename);
74 
75  // Extract the language name
76  char *s = strrchr(lng_filename,'/');
77  if (s == 0) s = lng_filename; else s++;
78  strcpy(buf,s);
79  s = strrchr(buf,'.');
80  if (s) *s = 0;
81 
82  printf("static char* gui_lang_default = \n");
83 
84  for ( i=1; i<=num_lines; i++ )
85  {
86  if ( !langfile[i])
87  {
88  printf("/*%3d*/ \"\\0\"\n", i);
89  num_empty_lines++;
90  }
91  else
92  {
93  {
94  // Do shielding of \ symbol
95  const char* from = langfile[i];
96  char* to = buf;
97 
98  while(*from)
99  {
100  *to=*from; to++;
101  if (*from=='\\' && from[1]!='"' && from[1]!='n')
102  { *to=*from; to++;}
103  from++;
104  }
105  *to=0;
106  }
107  char *iscond = is_conditional(i);
108  if (iscond)
109  {
110  if (iscond[0] == '!')
111  printf("#ifndef %s\n/*%3d*/ \"%s\"\n#endif\n \"\\0\"\n", iscond+1, i, buf);
112  else
113  printf("#ifdef %s\n/*%3d*/ \"%s\"\n#endif\n \"\\0\"\n", iscond, i, buf);
114  }
115  else
116  {
117  printf("/*%3d*/ \"%s\\0\"\n",i,buf);
118  }
119  }
120  }
121 
122  printf(";\n\n");
123 
124  if ( num_empty_lines > 50 )
125  printf("#warning Too many empty lines are detected. Please ensure that .lng files have serial numbers\n\n");
126 
127  printf("//Sanity check of GUI_LANG_ITEMS\n");
128  printf("#if (GUI_LANG_ITEMS != %d)\n",num_lines);
129  printf("#error GUI_LANG_ITEMS value have to be %d. Please fix at gui_lang.h\n", num_lines);
130  printf("#endif\n");
131 
132  return 0;
133 }
char* next_token ( char *  p,
char *  buf 
)

Definiert in Zeile 213 der Datei makelang.c.

214 {
215  *buf = 0;
216  p = skip_space(p);
217  if ((*p == '\r') || (*p == '\n')) return 0;
218  while (*p && (*p != ' ') && (*p != '\t') && (*p != '\r') && (*p != '\n')) *buf++ = *p++;
219  *buf = 0;
220  return p;
221 }
char* skip_space ( char *  p)

Definiert in Zeile 207 der Datei makelang.c.

208 {
209  while (*p && ((*p == ' ') || (*p == '\t'))) p++;
210  return p;
211 }

Variablen-Dokumentation

char** lang_conditions

Definiert in Zeile 12 der Datei makelang.c.

char** langfile = 0

Definiert in Zeile 19 der Datei makelang.c.

int num_lines =0

Definiert in Zeile 18 der Datei makelang.c.