Ironworks Gaming Forum

Ironworks Gaming Forum (http://www.ironworksforum.com/forum/index.php)
-   General Discussion (http://www.ironworksforum.com/forum/forumdisplay.php?f=36)
-   -   Writing Source Code with a Spreadsheet (http://www.ironworksforum.com/forum/showthread.php?t=102438)

Shadow Stranger 01-20-2014 06:20 AM

Writing Source Code with a Spreadsheet
 
Under certain circumstances, writing part of a computer program can be automated to a degree. The piece of source code must follow a pattern, have a fair amount of repetition inside itself. Here we see elements that are common from one for clause to another and we also see elements that are not:

printf("\n,");
for (i = 912; i < 2152; i++) {
if (i % 16 == 0)
printf("%d,",i);
printf("%d,",buffer[i]);
if (i % 16 == 15)
printf("\n,");
if (i == 2151)
printf("\n,");
}

printf("\n,");
for (i = 2152; i < 4000; i++) {
if (i % 16 == 8)
printf("%d,",i);
printf("%d,",buffer[i]);
if (i % 16 == 7)
printf("\n,");
if (i == 3999)
printf("\n,");
}

(A whole lot of lines have been omitted for brevity's sake.)

printf("\n,");
for (i = 32466; i < 32983; i++) {
if (i % 16 == 2)
printf("%d,",i);
printf("%d,",buffer[i]);
if (i % 16 == 1)
printf("\n,");
if (i == 32982)
printf("\n,");
}

printf("\n,");
for (i = 32983; i < 33100; i++) {
if (i % 16 == 7)
printf("%d,",i);
printf("%d,",buffer[i]);
if (i % 16 == 6)
printf("\n,");
if (i == 33099)
printf("\n,");
}

The for clause is a common element, but the numbers contained in each clause are not.

First, we create a specimen clause of code. If a number is surrounded on both sides by tab stops, when it is pasted into a spreadsheet it will be in a cell by itself. Below, "\t" represents an otherwise invisible tab stop. All paragraph marks are replaced by at symbols, "@". This means the clause now occupies only one line of code.
printf("\n,");@for (i = \t912\t; i < \t2152\t; i++) {@if (i % 16 == \t0\t)@printf("%d,";i);@printf("%d,";buffer[i]);@if (i % 16 == \t15\t)@printf("\n,");@if (i == \t2151\t)@printf("\n,");@}@

The specimen line of code is now copied into a spreadsheet.

Now the the Fill Down function is used:
printf("\n,");@for (i = \t912\t; i < \t2152\t; i++) {@if (i % 16 == \t0\t)@printf("%d,";i);@printf("%d,";buffer[i]);@if (i % 16 == \t15\t)@printf("\n,");@if (i == \t2151\t)@printf("\n,");}@
printf("\n,");@for (i = \t912\t; i < \t2152\t; i++) {@if (i % 16 == \t0\t)@printf("%d,";i);@printf("%d,";buffer[i]);@if (i % 16 == \t15\t)@printf("\n,");@if (i == \t2151\t)@printf("\n,");}@
printf("\n,");@for (i = \t912\t; i < \t2152\t; i++) {@if (i % 16 == \t0\t)@printf("%d,";i);@printf("%d,";buffer[i]);@if (i % 16 == \t15\t)@printf("\n,");@if (i == \t2151\t)@printf("\n,");}@

(A whole lot of lines have been omitted for brevity's sake.)

printf("\n,");@for (i = \t912\t; i < \t2152\t; i++) {@if (i % 16 == \t0\t)@printf("%d,";i);@printf("%d,";buffer[i]);@if (i % 16 == \t15\t)@printf("\n,");@if (i == \t2151\t)@printf("\n,");}@
printf("\n,");@for (i = \t912\t; i < \t2152\t; i++) {@if (i % 16 == \t0\t)@printf("%d,";i);@printf("%d,";buffer[i]);@if (i % 16 == \t15\t)@printf("\n,");@if (i == \t2151\t)@printf("\n,");}@
printf("\n,");@for (i = \t912\t; i < \t2152\t; i++) {@if (i % 16 == \t0\t)@printf("%d,";i);@printf("%d,";buffer[i]);@if (i % 16 == \t15\t)@printf("\n,");@if (i == \t2151\t)@printf("\n,");}@


Now all the variable parts are in columns by themselves, just copy in the relevant numbers and comments:
printf("\n,");@for (i = \t912\t; i < \t2152\t; i++) {@if (i % 16 == \t0\t)@printf("%d,";i);@printf("%d,";buffer[i]);@if (i % 16 == \t15\t)@printf("\n,");@if (i == \t2151\t)@printf("\n,");}@
printf("\n,");@for (i = \t2152\t; i < \t4000\t; i++) {@if (i % 16 == \t8\t)@printf("%d,";i);@printf("%d,";buffer[i]);@if (i % 16 == \t7\t)@printf("\n,");@if (i == \t3999\t)@printf("\n,");}@
printf("\n,");@for (i = \t4000\t; i < \t5976\t; i++) {@if (i % 16 == \t0\t)@printf("%d,";i);@printf("%d,";buffer[i]);@if (i % 16 == \t15\t)@printf("\n,");@if (i == \t5975\t)@printf("\n,");}@

(A whole lot of lines have been omitted for brevity's sake.)

printf("\n,");@for (i = \t31654\t; i < \t32466\t; i++) {@if (i % 16 == \t6\t)@printf("%d,";i);@printf("%d,";buffer[i]);@if (i % 16 == \t5\t)@printf("\n,");@if (i == \t32465\t)@printf("\n,");}@
printf("\n,");@for (i = \t32466\t; i < \t32983\t; i++) {@if (i % 16 == \t2\t)@printf("%d,";i);@printf("%d,";buffer[i]);@if (i % 16 == \t1\t)@printf("\n,");@if (i == \t32982\t)@printf("\n,");}@
printf("\n,");@for (i = \t32983\t; i < \t33100\t; i++) {@if (i % 16 == \t7\t)@printf("%d,";i);@printf("%d,";buffer[i]);@if (i % 16 == \t6\t)@printf("\n,");@if (i == \t33099\t)@printf("\n,");}@

The code is then copied to a file, which is saved. File is then opened in a hex editor.
All tab stops are deleted, in Windows they are all equal to 09h. Use Replace All to replace all of them with nothing, this has the effect of deleting all of them.
Now at symbols, @, need to be replaced by a paragraph mark and a tab. In Windows hex terms 40h needs to be replaced by 0D0A09h.

This method is valid for any brand of source code.

Luvian 01-21-2014 06:51 PM

Re: Writing Source Code with a Spreadsheet
 
Well that is interesting. What made you think of that?

Shadow Stranger 01-21-2014 09:07 PM

Re: Writing Source Code with a Spreadsheet
 
Need to draw up programs to decrypt the data structures of various computer games. Currently it is being used in Wizards and Warriors.


All times are GMT -4. The time now is 01:42 PM.

Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
©2024 Ironworks Gaming & ©2024 The Great Escape Studios TM - All Rights Reserved