Skip to content

Instantly share code, notes, and snippets.

@msmshazan
Last active June 29, 2017 10:59
Show Gist options
  • Save msmshazan/863544700b4689e78648b2423d0a9e96 to your computer and use it in GitHub Desktop.
Save msmshazan/863544700b4689e78648b2423d0a9e96 to your computer and use it in GitHub Desktop.
HTML Templating progress
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
FILE * TemplateFile = fopen("../code/test.template.html","r");
size_t Size = 0;
fseek(TemplateFile,0,SEEK_END);
Size = ftell(TemplateFile);
fseek(TemplateFile,0,SEEK_SET);
printf("Size: %i bytes\n",Size);
void* Buf = malloc(Size + 1);
char * Buffer = (char *)Buf;
fread(Buf,1,Size,TemplateFile);
Buffer[Size] = 0;
fclose(TemplateFile);
char *Output = {};
int Length = strlen(Buffer);
for(unsigned int i=0;
i<Length;
)
{
if(Buffer[i] == '{' && Buffer[i+1] == '{')
{
int length = 0;
char * B=0;
i += 2;
while(Buffer[i] == ' ') i++;
if(!(Buffer[i] ==' ')){
B = (char *)&Buffer[i];
length++;
i++;
}
while(!(Buffer[i] == ' ')){
length++;
i++;
}
if((Buffer[i] ==' ')){
Output = (char *)malloc(length + 1);
strncpy(Output,B,length);
Output[length] = 0;
printf("Html Output {{ %s }} \n",Output);
free(Output);
i++;
}
while(Buffer[i] == ' ') i++;
if(Buffer[i] == '}' && Buffer[i+1] == '}'){
}
}
else
{
i++;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment