Romhacking.net

Romhacking => ROM Hacking Discussion => Topic started by: Jandazekon on April 04, 2014, 03:30:34 pm

Title: How text editors replace function works
Post by: Jandazekon on April 04, 2014, 03:30:34 pm
Step 1:         ORIGINAL
A
B
C
D
E
F
G



Step 2:         CHANGING A INTO B
B
B
C
D
E
F
G



Step 3:         CHANGING B INTO F (both a and b is changed into f)
F
F
C
D
E
F
G



Step 4:         CHANGING C INTO E
F
F
E
D
E
F
G



Step 5:         CHANGING E INTO B (both c and e is changed into b)
F
F
B
D
B
F
G
Title: Re: How text editors replace function works
Post by: FAST6191 on April 04, 2014, 05:14:13 pm
I do not follow.

Are you after a general discussion of search algorithms/techniques, a way to program a tool so as to handle it (possibly from a ROM hacking perspective) or something like a batch script to do what you describe there?

For the former that is probably basic programming, a basic means to do it (even if you have to check every character one by one it is probably not going to be too slow for a modern PC to do it) should be available in just about every programming language worth a damn.
You probably also want to read up on regular expressions.

Programming a tool.
What was covered before works. Here though you are going to have to filter it through tables and input checking of some form. I am not sure what there is for some of the hex editors out there, if text editors would have covered the last one then hex editors are good for this.

For the batch file thing you probably want the wonder combo of grep, sed and awk.
http://matt.might.net/articles/sculpting-text/
Title: Re: How text editors replace function works
Post by: Jandazekon on April 04, 2014, 05:21:54 pm
Original:
id 0 = A
id 1 = B
id 2 = C
id 3 = D
id 4 = E
id 5 = F
id 6 = G



Changing A into B:
id 0 = B <-
id 1 = B
id 2 = C
id 3 = D
id 4 = E
id 5 = F
id 6 = G



Changing B into F:
id 0 = B
id 1 = F <-
id 2 = C
id 3 = D
id 4 = E
id 5 = F
id 6 = G
Title: Re: How text editors replace function works
Post by: Gideon Zhi on April 04, 2014, 06:01:09 pm
You wot, mate?

But seriously, I'm not entirely sure what you're trying to accomplish by posting this. These sorts of data replacement concepts are, like, remedial computers for technophobes stuff.
Title: Re: How text editors replace function works
Post by: Jandazekon on April 05, 2014, 03:41:56 am
Is there a text editor which knows what letters was changed to what.
And know their original names so not merge with them with other letters which has the same name.
Title: Re: How text editors replace function works
Post by: BRPXQZME on April 05, 2014, 04:56:15 am
No, because most people would just add a step using a temporary replacement symbol.
Title: Re: How text editors replace function works
Post by: henke37 on April 05, 2014, 05:14:32 am
Or for bigger replacements, they just use a lookup table and do just one pass on the data.
Title: Re: How text editors replace function works
Post by: Jandazekon on April 05, 2014, 05:43:17 am
Or for bigger replacements, they just use a lookup table and do just one pass on the data.
A word search table?
Title: Re: How text editors replace function works
Post by: FAST6191 on April 05, 2014, 06:15:05 am
No.

The simple search and replace method involves starting at the top (or the cursor I guess) and checking every single character one by one, incrementing the compare function until you reach the end of the file. This is simple to do but not terribly quick. When your machine is screaming along at however many gigahertz though it tends not to matter so much.

The better, though slightly more memory intensive, method is to generate a list of every character in the document and note the locations. If you then know say the character b is at 0x35,0xed and 0xf0 then you can simply change the values at those locations if the program needs to change the character b (far quicker). Typically though programs will regenerate the table after every change/every function call making your desire to have the characters retain knowledge of their former state kind of hard. I guess you could alter the source to do such a thing (or have a disable updates and force redraw/regenerate option, be warned that adding new or removing characters/spaces/whatever would break things very fast). As BRPXQZME said though everybody that has to do this for anything will tend to add another stage and change the character to another previously unused one (#@[]{}.... the list goes on, if you are really hard pressed you can also use long runs of multiple characters that will also not turn up in the rest of your document).
Title: Re: How text editors replace function works
Post by: henke37 on April 05, 2014, 06:29:37 am
Single pass infinite length needle replacer:
Code: [Select]
var matchTreePos=matchTreeRoot;
var outBuff:String="";
for(var i:uint=0;i<inBuff.length;++i) {
var readChar=inBuff[i];

var nextTreePos=matchTreePos.lut[readChar];
if(!nextTreePos) {
outBuff+=matchTreePos.replacement;
matchTreePos=matchTreeRoot;
} else {
matchTreePos=nextTreePos;
}
}