44 while(section != NULL)
47 last_section = section;
57 if(section == NULL)
return;
61 if(name->
name != NULL)
delete [] name->
name;
67 if(section->
name != NULL)
delete [] section->
name;
74 if(line[0] !=
'[')
return;
75 while(line[i] !=
']' && line[i] !=
'\0')
87 while(line[i] !=
'\0' && (line[i] !=
'=' || (line[i] ==
'=' && line[i-1] ==
'\\')))
93 while(i>=0 && (buf[i] ==
' ' || buf[i] ==
'\t'))
101 const char *cptr = line;
105 cptr = strchr(cptr,
'=');
106 if(cptr == NULL)
return;
108 if(cptr[-2] !=
'\\')
break;
110 while((*cptr ==
' ' || *cptr ==
'\t') && *cptr !=
'\0') cptr++;
111 if(*cptr ==
'\0')
return;
112 while(*cptr !=
'\0' && *cptr !=
'\n') *buf++ = *cptr++;
144 if(fp == NULL)
return -1;
145 name_section[0] = name_name[0] = name_param[0] =
'\0';
146 while(fgets(line,
sizeof(line)-1,fp) != NULL)
148 cptr = strchr(line,0x0d);
149 if(cptr != NULL) *cptr =
'\0';
150 cptr = strchr(line,0x0a);
151 if(cptr != NULL) *cptr =
'\0';
155 setText(name_section, NULL, NULL);
157 else if(line[0] >
' ' && line[0] !=
'\t' && line[0] !=
'#')
161 setText(name_section, name_name, name_param);
165 setText(name_section, line, NULL);
179 if(fp == NULL)
return -1;
184 if (s->
name[0] ==
'#') fprintf(fp,
"%s\n",s->
name);
185 else if(s->
name[0] ==
'\0') ;
186 else fprintf(fp,
"[%s]\n",s->
name);
190 if (n->
name[0] ==
'#') fprintf(fp,
"%s\n",n->
name);
191 else if(n->
name[0] ==
'\0') fprintf(fp,
"\n");
192 else if(n->
param[0] ==
'\0') fprintf(fp,
"\n");
193 else fprintf(fp,
"%s=%s\n",n->
name,n->
param);
216 if(strcmp(section,s->
name) == 0)
221 if(n->
name != NULL && strcmp(name,n->
name) == 0)
239 if(section == NULL)
return;
245 if(strcmp(section,s->
name) == 0)
251 if(name != NULL && name[0] !=
'#' && name[0] !=
'\0' && strcmp(name,n->
name) == 0)
256 n->
param =
new char[1];
269 if(last_name == NULL)
281 n->
name =
new char[1];
286 n->
name =
new char[strlen(name)+1];
287 strcpy(n->
name,name);
291 n->
param =
new char[1];
305 if(last_section == NULL)
315 last_section->
name =
new char[strlen(section)+1];
316 strcpy(last_section->
name,section);
326 n->
name =
new char[strlen(name)+1];
327 strcpy(n->
name,name);
330 n->
param =
new char[1];
352 if(ret > 0)
setText(section, name, buf);
364 if(strcmp(section,s->
name) == 0)
386 if(strcmp(section,s->
name) == 0)
392 if(strcmp(name,n->
name) == 0)
394 if(n->
name != NULL)
delete [] n->
name;
444 if(strcmp(section,s->
name) == 0)
467 if(strcmp(section,s->
name) == 0)
496 if(strcmp(cptr,
null_string) == 0)
return default_text;
502 if(txt == NULL)
return "ERROR:txt=NULL";
503 char default_text[1024];
504 if(strlen(txt) < (
sizeof(default_text) - 40)) sprintf(default_text,
"tr_error:%s", txt);
505 else strcpy(default_text,
"tr_error:text too long");
506 return i18n(txt,default_text);
523 static const char *
fixquote(
const char *text,
char **mytext)
525 if(strchr(text,
'\\') == NULL)
return text;
526 int len = strlen(text);
527 if(*mytext != NULL)
delete [] *mytext;
528 *mytext =
new char[len+1];
529 char *temp = *mytext;
531 for(
int i=0; i<len; i++)
533 if (text[i] ==
'\\' && text[i+1] ==
'=') { temp[i2] =
'='; i++; }
534 else if(text[i] ==
'\\' && text[i+1] ==
'n') { temp[i2] =
'\n'; i++; }
535 else if(text[i] ==
'\\' && text[i+1] ==
't') { temp[i2] =
'\t'; i++; }
536 else if(text[i] ==
'\\' && text[i+1] ==
'\\') { temp[i2] =
'\\'; i++; }
537 else { temp[i2] = text[i]; }
549 if(strcmp(text,
"@") == 0)
return fixquote(txt,mytext);
553 const char *
rltranslate2(
const char *section,
const char *txt,
char **mytext)
557 if(*section ==
'\0')
return rltranslate(txt,mytext);
559 if(text[0] ==
'\0')
return fixquote(txt,mytext);
void copyName(char *buf, const char *line)
static rlIniFile * trIniFile
const char * nextSection()
const char * tr(const char *txt)
const char * i18n(const char *tag, const char *default_text="")
const char * text(const char *section, const char *name)
void copyIdentifier(char *buf, const char *line)
struct rlIniFile::_rlSectionName_ rlSectionName
int read(const char *filename)
const char * rltranslate(const char *txt, char **mytext)
int rlSetTranslator(const char *language, const char *inifile)
void deleteSectionNames(rlSection *section)
void setText(const char *section, const char *name, const char *text)
int rlvsnprintf(char *text, int len, const char *format, va_list ap)
void copyParam(char *buf, const char *line)
int setText(const char *text)
const char * firstSection()
rlSectionName * firstName
const char * defaultSection()
static const char * fixquote(const char *text, char **mytext)
static const char null_string[]
void setDefaultSection(const char *section)
_rlSection_ * nextSection
_rlSectionName_ * nextName
const char * rltranslate2(const char *section, const char *txt, char **mytext)
rlSection * _firstSection
int printf(const char *section, const char *name, const char *format,...)
struct rlIniFile::_rlSection_ rlSection
const char * nextName(const char *section)
const char * firstName(const char *section)
void remove(const char *section)
int write(const char *filename)