Commit 18de1fdc authored by dragontamer lance's avatar dragontamer lance

initial commit of awful code

parents
horrible C programs that convert FSPosessionSave files to something resembling
a sane format for editing.
Total WIP and probably badly written. But I can convert to and from the
original format and arrive with the exact same checksum, so I'm doing
something right I guess.
Notes:
Each of the comma separated numbers is actually just a single character of
an ascii string, represented in decimal form for some reason.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
FILE *infile=fopen(argv[1], "r");
int achar=0;
int i=0;
/* copy header verbatim */
/* (two lines) */
while(i<2)
{
achar=fgetc(infile);
if(achar == EOF || achar == 0)
{
return -1;
}
else
{
if(achar == '\n')
{
i++;
}
printf("%c",(char)achar);
}
}
// ungetc('\n', infile);
/* translate back into stupid integer format */
while(achar != EOF)
{
achar = fgetc(infile);
if(achar != EOF)
{
printf("S");
}
else
{
return 0;
}
while(achar != ';' && achar != EOF)
{
if(achar != 0)
{
printf("%d,",achar);
}
else
{
printf("%d",achar);
}
achar = fgetc(infile);
}
printf(";");
achar=fgetc(infile);
while(achar != '\n' && achar != EOF)
{
printf("%c",achar);
achar = fgetc(infile);
}
printf("\n");
fgetc(infile);
// ungetc('\n', infile);
}
}
#include <stdio.h> /* printf */
#include <stdlib.h> /* atoi */
#include <ctype.h> /* isdigit */
int main(int argc, char **argv)
{
FILE *infile=fopen(argv[1], "r");
int achar=0;
int i=0;
/* copy header verbatim */
while(i<2)
{
achar=fgetc(infile);
if(achar == NULL)
{
return -1;
}
else
{
printf("%c",(char)achar);
if(achar == '\n')
i++;
}
}
/* now we are at first inv line */
/* each line starts with a letter S so we need to skip that */
char str[4]; /* ascii is limited in size */
str[3]='\0';
i=0;
if(fgetc(infile) == 'S') /* progress ahead of 'S' */
{
while(achar != EOF)
{
while(achar != ';' && achar != EOF)
{
while(isdigit(achar=fgetc(infile)) && i < 3)
{
str[i]=achar;
i++;
}
printf("%c",(char)atoi(str));
str[0]='\0';
str[1]='\0';
str[2]='\0';
i=0;
} /* ';' reached */
if(achar == ';')
printf(";");
/* print out rest of line since we don't know what it is yet */
while(achar != '\n' && achar != EOF && achar != 'S')
{
printf("%c",(achar=fgetc(infile)));
}
} /* != EOF */
}
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment