dprint("files are %s\n", s_to_c(files));
return files;
}
/* loop through the translation files */
static int
translate(char *name, char **namev, String *files, String *alias)
{
int n, rv;
String *file, **fullnamev;
/*
* very dumb conversion to bang format
*/
static String*
attobang(String *token)
{
char *p;
String *tok;
p = strchr(s_to_c(token), '@');
if(p == 0)
return token;
p++;
tok = s_copy(p);
s_append(tok, "!");
s_nappend(tok, s_to_c(token), p - s_to_c(token) - 1);
return tok;
}
/* Loop through the entries in a translation file looking for a match.
* Return 0 if found, -1 otherwise.
*/
#define compare(a, b) cistrcmp(s_to_c(a), b)
static int
lookup(String **namev, String *file, String *alias)
{
char *name;
int i, rv;
String *line, *token, *bangtoken;
Sinstack *sp;
rv = -1;
name = s_to_c(namev[0]);
line = s_new();
token = s_new();
s_reset(alias);
if ((sp = s_allocinstack(s_to_c(file))) == 0)
return -1;
/* look for a match */
while (s_rdinstack(sp, s_restart(line))!=0) {
dprint("line is %s\n", s_to_c(line));
s_restart(token);
if (s_parse(s_restart(line), token)==0)
continue;
if (compare(token, "#include")==0){
if(s_parse(line, s_restart(token))!=0) {
if(lookup(namev, line, alias) == 0)
break;
}
continue;
}
if (compare(token, name)!=0)
continue;
/* match found, get the alias */
while(s_parse(line, s_restart(token))!=0) {
bangtoken = attobang(token);