new translate code to use a dictionary of known phrases

This commit is contained in:
Martin Johnson 2018-10-12 14:32:46 +13:00
parent d15a69813b
commit 4741c395de
7 changed files with 266 additions and 8 deletions

View File

@ -2,13 +2,15 @@ CFLAGS=-std=c99
all: decode recode extractbmp makever fixbmpheader all: decode recode extractbmp makever fixbmpheader
decode: decode:
recode: recode.c recode: recode.c
gcc recode.c -o recode -l unistring gcc recode.c -o recode -l unistring
translate: translate.c
gcc translate.c -o translate -l unistring
extractbmp: extractbmp:
makever: makever:
fixbmpheader: fixbmpheader:
clean: clean:
rm -f fixbmpheader extractbmp recode decode makever rm -f fixbmpheader extractbmp recode decode makever
translate: PF090JPJPN.LNG PF110JPJPN.LNG PF090JPJPN_0047.LNG PF090JPJPN_0047_RU.LNG PF090JPJPN_RU.LNG trans: PF090JPJPN.LNG PF110JPJPN.LNG PF090JPJPN_0047.LNG PF090JPJPN_0047_RU.LNG PF090JPJPN_RU.LNG
PF090JPJPN.LNG: translated.txt recode PF090JPJPN.LNG: translated.txt recode
./recode translated.txt PF090JPJPN.LNG ./recode translated.txt PF090JPJPN.LNG
PF110JPJPN.LNG: translated_110.txt recode PF110JPJPN.LNG: translated_110.txt recode

Binary file not shown.

Binary file not shown.

View File

@ -18,17 +18,22 @@ int main(int argc,char *argv[]) {
offset=0; offset=0;
fread(&offset, 2, 1, f); fread(&offset, 2, 1, f);
offset=offset*2+0x40; offset=offset*2+0x40;
next=0; /* next=0;
fread(&next, 2, 1, f); fread(&next, 2, 1, f);
next=next*2+0x40; next=next*2+0x40;
*/
ch=1; ch=1;
putchar('"'); putchar('"');
putchar(0); putchar(0);
fseek(f,offset,SEEK_SET); fseek(f,offset,SEEK_SET);
while(offset<next-2) { int ch1=1;
while(1) {
fread(&ch,1,1,f); fread(&ch,1,1,f);
offset++; fread(&ch1,1,1,f);
if(ch==0 && ch1==0)
break;
putchar(ch&255); putchar(ch&255);
putchar(ch1&255);
} }
putchar('"'); putchar('"');
putchar(0); putchar(0);

185
translate.c Normal file
View File

@ -0,0 +1,185 @@
#include <stdio.h>
#include <string.h>
#include <unistr.h>
#include <stdlib.h>
#define MAX_STRING_LENGTH 2048
#define MAX_STRINGS 8192
void readstring(FILE *f, char *p) {
char c;
int i;
char *op=p;
c=fgetc(f);
if(feof(f)) return;
if(c!='\"') {
puts("ERROR: mismatched quotes");
exit(1);
}
for(i=0;i<MAX_STRING_LENGTH;i++) {
p[i]=fgetc(f);
if(i>0 && p[i]<15 && p[i-1]==34)
break;
}
if(i>0)
p[i-1]=0;
c=p[i];
if(c==13)
c=fgetc(f);
if(c!=10 && !feof(f)) {
printf("ERROR: mismatched eol quotes %d %s\n",c, op);
}
// printf("read(%s)\n",op);
}
unsigned short crc16(const unsigned char *data, int len) {
unsigned short crc = 0xFFFF;
int i;
if (len) do {
crc ^= *data++;
for (i=0; i<8; i++) {
if (crc & 1) crc = (crc >> 1) ^ 0x8408;
else crc >>= 1;
}
} while (--len);
return(~crc);
}
int nstrings=0;
char **original=0;
char **translation=0;
void load_dictionary(char *untran,char *tran) {
FILE *f,*g;
if(original==0) {
original=malloc(MAX_STRINGS*sizeof(char *));
translation=malloc(MAX_STRINGS*sizeof(char *));
}
g=fopen(untran,"rb");
f=fopen(tran,"rb");
char st[MAX_STRING_LENGTH],st1[MAX_STRING_LENGTH];
int j;
while(!feof(g)) {
readstring(g,st);
readstring(f,st1);
//printf("%s -> %s\n",st,st1);
for(j=0;j<nstrings;j++)
if(!strcmp(st,original[j]))
break;
if(j==nstrings) {
original[j]=malloc(strlen(st)+1);
translation[j]=malloc(strlen(st1)+1);
strcpy(original[j],st);
strcpy(translation[j],st1);
nstrings++;
}// else printf("Done Already %d\n",nstrings);
}
}
char *get_translation(char *s) {
int j;
for(j=0;j<nstrings;j++)
if(!strcmp(s,original[j]))
return translation[j];
printf("%s could not be translated\n",s);
return s;
}
int main(int argc,char *argv[]) {
char data[200000];
char st[MAX_STRING_LENGTH];
short st_u16[MAX_STRING_LENGTH];
char *infile="untranslated.txt",*outfile="PF090JPJPN.LNG";
FILE *f,*g;
int i;
unsigned *id=(unsigned *) data;
id[0]=0xa55a5aa5;
id[1]=0x01000001;
id[2]=0x39304650;
id[3]=0x45504a30;
id[4]=0;
id[5]=0;
id[6]=0;// len
id[7]=0x40;
id[8]=0;//last
id[9]=0xaaaaaa02;
id[10]=0xaaaaaaaa;
id[11]=0xaaaaaaaa;
id[12]=0xaaaaaaaa;
id[13]=0xaaaaaaaa;
id[14]=0xaaaaaaaa;
id[15]=0xaaaaaaaa;
if(argc>1)
infile=argv[1];
if(argc>2)
outfile=argv[2];
g=fopen(infile,"rb");
int start=0x40;
unsigned short *idx=(unsigned short *)(data+0x40);
short nstrings=0;
int offset=0;
int next=0;
short ch;
load_dictionary("untranslated.txt","translated.txt");
load_dictionary("untranslated_110.txt","translated_110.txt");
while(!feof(g)) {
readstring(g,st);
// printf("%d %s\n",nstrings,st);
nstrings++;
}
nstrings+=2;
rewind(g);
nstrings=nstrings-3;
printf("Found %d strings\n",nstrings);
unsigned short *strptr=idx+nstrings;
int off=0x40+(nstrings+3)*2;
int ntrans=0;
char *tr;
char **strings=malloc(sizeof(char *)*nstrings);
for(i=0;i<nstrings;i++) {
readstring(g,st);
tr=get_translation(st);
strings[i]=malloc(strlen(tr)+1);
strcpy(strings[i],tr);
int j;
for(j=0;j<i;j++)
if(!strcmp(tr,strings[j]))
break;
if(j<i) {
idx[i]=idx[j];
} else {
// puts(st);
idx[i]=(off-0x40)/2;
if((off-0x40)/2>65535) {
printf("ERROR: index too large %x\n",(off-0x40)/2);
exit(1);
}
size_t sz=512;
u8_to_u16(tr,strlen(tr),(short *)(data+off),&sz);
off+=sz*2;
data[off++]=0;
data[off++]=0;
}
}
idx[i]=(off-0x40)/2;
id[8]=off;
strcpy(data+off,"RG_VOICE_DATA");
off+=strlen("RG_VOICE_DATA");
data[off++]=0xf1; // this looks like a checksum at the end of the file but
data[off++]=0x8d; // it doesn't seem to matter if it's wrong
id[6]=off;
printf("%d strings\n",nstrings);
f=fopen(outfile,"wb");
fwrite(data,off,1,f);
fclose(f);
return(0);
}

View File

@ -12,8 +12,8 @@
"" ""
"Destination" "Destination"
"Configuration" "Configuration"
"communication" "Communication"
"info" "Info"
"Configuration" "Configuration"
"Edit" "Edit"
"Destination" "Destination"
@ -24,7 +24,7 @@
"Surroundings" "Surroundings"
"Registered" "Registered"
"Search history" "Search history"
"Return Home" "Home"
"Root erase" "Root erase"
"Info" "Info"
"Congestion info" "Congestion info"

View File

@ -4538,3 +4538,69 @@ Call %s?"
"No" "No"
"Delete probe, OK?" "Delete probe, OK?"
"AUX Volume with FM ref" "AUX Volume with FM ref"
"menu"
"This screen will not be displayed."
"Startup lock setting"
"When replacing the battery"
"When the engine switch is on"
"Not set"
"-"
"Password authentication timing"
"Change Password"
"When ON is selected,
A password input screen is displayed each time."
"Password changed."
"Please enter a new password."
"For confirmation, please re-enter the same password
Please enter. "
"Passwords do not match.
Please try again from the beginning. "
"Set startup lock.
Please enter the password.
* When setting for the first time
Please enter your initial password. "
"The password is in correct.
Letters of the alphabet are
Please check whether it is wrong. "
"Change Password"
"Password confirmation"
"The activation lock is on."
"Failed to unlock.
Whether the upper and lower case letters of the alphabet are incorrect
please confirm. "
"Reset the internal memory to the factory default settings.
Data such as registered location and password etc.
All setting contents are erased. Is it OK? "
"Password authentication"
"Startup lock setting"
"Destination search"
"(Outing Menu)"
"Data excluding home such as registered places and history,
The setting is deleted. Is it OK? "
"Data including registered places and history including home,
The setting is deleted. Is it OK? "
"Latitude longitude (Japan geodetic system)"
"Latitude and longitude (world geodetic system)"
"Northern latitude %c%c.%c%c%c%c%c%c degree east longitude %c%c%c.%c%c%c%c%c%c degrees"
"Degree input"
"Degrees minute and second"
"Datum"
"Data used%s
[Map data:%s]
[Search data:%s]
Model information Corporate model B1 "
"Data used%s
[Map data:%s]
[Search data:%s]
Model information Corporate model B2 "
"Data used%s
[Map data:%s]
[Search data:%s]
Model information Corporate model B3 "
"Data used%s
[Map data:%s]
[Search data:%s]
Model information Corporate model B4 "
"I did a route search without considering time regulation.
Please follow the actual road signs. "
"Destination search"