Jump to content

Using Spreadsheets to Create Source Code


Ishad Nha

Recommended Posts

Under certain circumstances, writing part of a program can be automated to a degree. The piece of 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("\n0,,,");
for (i = 0; i < 2; i++) { // Town Number
printf("%s,",buffer[i]);
}
printf("\n2,,,");
for (i = 2; i < 28; i++) { // Town Name
printf("%s,",buffer[i]);
 if (i == 27)
printf("\n28,,,");
}
for (i = 28; i < 48; i++) { // Town Script Name
printf("%s,",buffer[i]);
 if (i == 47)
printf("\n");
}

for (i = 48; i < 4144; i++) { // Floor 1 mapping [64][64]
if (i % 64 == 48)
printf("%d,,,",i);
printf("%s,",buffer[i]);
if (i % 64 == 47)
printf("\n");
}

&&&&&&&&

 

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

 

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.

for (i = \t0\t; i < \t2\t; i++) { // \tTown Number\t@if (i % 16 == 8)@printf("%d,,,",i);@printf("%s,",buffer);@if (i % 16 == 7)@printf("\n");@}@

 

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

 

Now the the Fill Down function is used:

for (i = \t0\t; i < \t2\t; i++) { // \tTown Number\t@if (i % 16 == 8)@printf("%d,,,",i);@printf("%s,",buffer);@if (i % 16 == 7)@printf("\n");@}@

for (i = \t0\t; i < \t2\t; i++) { // \tTown Number\t@if (i % 16 == 8)@printf("%d,,,",i);@printf("%s,",buffer);@if (i % 16 == 7)@printf("\n");@}@

for (i = \t0\t; i < \t2\t; i++) { // \tTown Number\t@if (i % 16 == 8)@printf("%d,,,",i);@printf("%s,",buffer);@if (i % 16 == 7)@printf("\n");@}@

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

for (i = \t0\t; i < \t2\t; i++) { // \tTown Number\t@if (i % 16 == 8)@printf("%d,,,",i);@printf("%s,",buffer);@if (i % 16 == 7)@printf("\n");@}@

for (i = \t0\t; i < \t2\t; i++) { // \tTown Number\t@if (i % 16 == 8)@printf("%d,,,",i);@printf("%s,",buffer);@if (i % 16 == 7)@printf("\n");@}@

for (i = \t0\t; i < \t2\t; i++) { // \tTown Number\t@if (i % 16 == 8)@printf("%d,,,",i);@printf("%s,",buffer);@if (i % 16 == 7)@printf("\n");@}@

 

Now all the variable parts are in columns by themselves, just copy in the relevant numbers and comments:

for (i = \t0\t; i < \t2\t; i++) { // \tTown Number\t@if (i % 16 == 8)@printf("%d,,,",i);@printf("%s,",buffer);@if (i % 16 == 7)@printf("\n");@}@

for (i = \t2\t; i < \t28\t; i++) { // \tTown Name\t@if (i % 16 == 8)@printf("%d,,,",i);@printf("%s,",buffer);@if (i % 16 == 7)@printf("\n");@}@

for (i = \t28\t; i < \t48\t; i++) { // \tTown Script Name\t@if (i % 16 == 8)@printf("%d,,,",i);@printf("%s,",buffer);@if (i % 16 == 7)@printf("\n");@}@

for (i = \t48\t; i < \t4144\t; i++) { // \tFloor 1 mapping [64][64]\t@if (i % 16 == 8)@printf("%d,,,",i);@printf("%s,",buffer);@if (i % 16 == 7)@printf("\n");@}@

 

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

 

for (i = 108384; i < 108416; i++) { // Town Entrances: N,W,S,E@if (i % 16 == 8)@printf("%d,,,",i);@printf("%s,",buffer);@if (i % 16 == 7)@printf("\n");@}@

for (i = 108416; i < 108448; i++) { // Exit Town Locations@if (i % 16 == 8)@printf("%d,,,",i);@printf("%s,",buffer);@if (i % 16 == 7)@printf("\n");@}@

for (i = 108448; i < 108488; i++) { // Unclear@if (i % 16 == 8)@printf("%d,,,",i);@printf("%s,",buffer);@if (i % 16 == 7)@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, here 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 hex terms 40h needs to be replaced by 0D0A09h.

 

Finally, not all for functions have the same modulus for placing paragraph marks, some have no modulus at all, you would need to go through the clauses one at a time and alter them.

 

This method is valid for Avernumscript or anything that handles code.

Edited by Ishad Nha
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...