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++;
143 fp = fopen(filename,
"r");
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);
178 fp = fopen(filename,
"w");
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];
261 n->
param =
new char[strlen(text)+1];
262 strcpy(n->
param,text);
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];
296 n->
param =
new char[strlen(text)+1];
297 strcpy(n->
param,text);
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];
335 n->
param =
new char[strlen(text)+1];
336 strcpy(n->
param,text);
352 if(ret > 0)
setText(section, name, buf);
364 if(strcmp(section,s->
name) == 0)
384 if(strcmp(section,s->
name) == 0)
390 if(strcmp(name,n->
name) == 0)
392 if(n->
name != NULL)
delete [] n->
name;
440 if(strcmp(section,s->
name) == 0)
463 if(strcmp(section,s->
name) == 0)
492 if(strcmp(cptr,
null_string) == 0)
return default_text;
498 if(txt == NULL)
return "ERROR:txt=NULL";
499 char default_text[1024];
500 if(strlen(txt) < (
sizeof(default_text) - 40)) sprintf(default_text,
"tr_error:%s", txt);
501 else strcpy(default_text,
"tr_error:text too long");
502 return i18n(txt,default_text);
512 if(trIniFile == NULL) trIniFile =
new rlIniFile();
513 if(trIniFile->
read(inifile) < 0)
return -1;
519 static const char *
fixquote(
const char *text,
char **mytext)
521 if(strchr(text,
'\\') == NULL)
return text;
522 int len = strlen(text);
523 if(*mytext != NULL)
delete [] *mytext;
524 *mytext =
new char[len+1];
525 char *temp = *mytext;
527 for(
int i=0; i<len; i++)
529 if (text[i] ==
'\\' && text[i+1] ==
'=') { temp[i2] =
'='; i++; }
530 else if(text[i] ==
'\\' && text[i+1] ==
'n') { temp[i2] =
'\n'; i++; }
531 else if(text[i] ==
'\\' && text[i+1] ==
't') { temp[i2] =
'\t'; i++; }
532 else if(text[i] ==
'\\' && text[i+1] ==
'\\') { temp[i2] =
'\\'; i++; }
533 else { temp[i2] = text[i]; }
543 if(trIniFile == NULL)
return fixquote(txt,mytext);
544 const char *text = trIniFile->
i18n(txt,
"@");
545 if(strcmp(text,
"@") == 0)
return fixquote(txt,mytext);
549 const char *
rltranslate2(
const char *section,
const char *txt,
char **mytext)
552 if(trIniFile == NULL)
return fixquote(txt,mytext);
553 if(*section ==
'\0')
return rltranslate(txt,mytext);
554 const char *text = trIniFile->
text(section,txt);
555 if(text[0] ==
'\0')
return fixquote(txt,mytext);