Added removel of obsolete lines

SVN revision: 702
This commit is contained in:
Stefan Ritt 2004-01-21 16:24:34 +00:00
parent 5c740a12e0
commit f7a363d2c8

View File

@ -7,6 +7,9 @@
them into eloglang.xxxx
$Log$
Revision 1.3 2004/01/21 16:24:34 midas
Added removel of obsolete lines
Revision 1.2 2004/01/18 21:46:20 midas
Applied indent
@ -45,11 +48,12 @@ void read_buf(char *filename, char **buf)
size = lseek(fh, 0, SEEK_END);
lseek(fh, 0, SEEK_SET);
*buf = malloc(size);
*buf = malloc(size+1);
assert(*buf);
i = read(fh, *buf, size);
assert(i == size);
(*buf)[size] = 0;
close(fh);
}
@ -57,12 +61,13 @@ void read_buf(char *filename, char **buf)
int scan_file(char *infile, char *outfile)
{
int fho, size;
int i, fho, size, first;
char *buf, *bufout, *p, *p2, str[1000], line[1000];
read_buf(infile, &buf);
p = buf;
first = TRUE;
do {
p = strstr(p, "loc(\"");
@ -91,7 +96,7 @@ int scan_file(char *infile, char *outfile)
}
memset(str, 0, sizeof(str));
memcpy(str, p, size);
memcpy(str, p, min(size, sizeof(str)));
/* convert \" to " */
for (p2 = str; *p2; p2++)
@ -99,9 +104,9 @@ int scan_file(char *infile, char *outfile)
strcpy(p2, p2 + 1);
/* check if string exists in output file */
sprintf(line, "\n%s =", str);
read_buf(outfile, &bufout);
p2 = strstr(bufout, str);
free(bufout);
p2 = strstr(bufout, line);
if (p2 == NULL) {
/* append string to output file */
@ -111,6 +116,13 @@ int scan_file(char *infile, char *outfile)
return 1;
}
if (first) {
sprintf(line, "\r\n#\r\n#---------- please translate following items ----------#\r\n#\r\n");
write(fho, line, strlen(line));
first = FALSE;
}
sprintf(line, "%s = \r\n", str);
write(fho, line, strlen(line));
close(fho);
@ -119,9 +131,68 @@ int scan_file(char *infile, char *outfile)
puts(str);
}
free(bufout);
} while (1);
/* now remove obsolete strings */
read_buf(outfile, &bufout);
p = bufout;
do {
strncpy(line, p, sizeof(line));
p2 = p;
if (strchr(line, '\n'))
*strchr(line, '\n') = 0;
if (strchr(line, '\r'))
*strchr(line, '\r') = 0;
p += strlen(line);
while (*p == '\r' || *p == '\n')
p++;
if (line[0] == '#' || line[0] == ';')
continue;
if (strchr(line, '='))
*strchr(line, '=') = 0;
if (strlen(line) <= 1)
continue;
while (line[strlen(line)-1] == ' ')
line[strlen(line)-1] = 0;
/* change " to \" */
for (i=0 ; i<(int)strlen(line) ; i++)
if (line[i] == '"') {
strcpy(str, line+i);
line[i++] = '\\';
strcpy(line+i, str);
}
sprintf(str, "loc(\"%s\")", line);
if (strstr(buf, str))
continue;
printf("Removed string: ");
puts(line);
/* if not found, remove line */
strcpy(p2, p);
p = p2;
} while (*p);
fho = open(outfile, O_CREAT | O_WRONLY | O_BINARY | O_TRUNC);
if (fho < 0) {
printf("Cannot open file \"%s\" for output\n", outfile);
return 1;
}
write(fho, bufout, strlen(bufout));
close(fho);
free(bufout);
free(buf);
return 0;
}
@ -130,10 +201,13 @@ int scan_file(char *infile, char *outfile)
int main(int argc, char *argv[])
{
int status;
if (argc != 3) {
printf("Usage: %s <file.c> <language file>\n", argv[0]);
return 1;
}
return scan_file(argv[1], argv[2]);
status = scan_file(argv[1], argv[2]);
return status;
}