Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

Commit

Permalink
Update precompiler.c
Browse files Browse the repository at this point in the history
  • Loading branch information
ntrupin committed Feb 7, 2019
1 parent 93a2f50 commit a034ea8
Showing 1 changed file with 81 additions and 18 deletions.
99 changes: 81 additions & 18 deletions experimental/precompiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <string.h>
#include <malloc.h>
#include <stdlib.h>
#include <ctype.h>

char *trimwhitespace(char *str)
{
Expand All @@ -17,7 +18,7 @@ char *trimwhitespace(char *str)

char* concat1(char *s1, char *s2, char *s3, char *s4, char *s5)
{
char *result = malloc(strlen(s1) + strlen(s2) + + strlen(s2) + strlen(s4) + strlen(s5) + strlen(s2) + strlen(s3));
char *result = malloc(strlen(s1) + strlen(s2) + strlen(s2) + strlen(s4) + strlen(s5) + strlen(s2) + strlen(s3));
strcpy(result, s1);
strcat(result, s2);
strcat(result, s3);
Expand All @@ -30,7 +31,7 @@ char* concat1(char *s1, char *s2, char *s3, char *s4, char *s5)

char* concat2(char *s1, char *s2, char *s3, char *s4)
{
char *result = malloc(strlen(s1) + strlen(s2) + + strlen(s3) + strlen(s4));
char *result = malloc(strlen(s1) + strlen(s2) + strlen(s3) + strlen(s4));
strcpy(result, s1);
strcat(result, s2);
strcat(result, s3);
Expand All @@ -40,7 +41,7 @@ char* concat2(char *s1, char *s2, char *s3, char *s4)

char* concat3(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6)
{
char *result = malloc(strlen(s1) + strlen(s2) + + strlen(s2) + strlen(s4) + strlen(s5) + strlen(s2) + strlen(s3) + strlen(s6));
char *result = malloc(strlen(s1) + strlen(s2) + strlen(s2) + strlen(s4) + strlen(s5) + strlen(s2) + strlen(s3) + strlen(s6));
strcpy(result, s1);
strcat(result, s2);
strcat(result, " ");
Expand All @@ -55,7 +56,7 @@ char* concat3(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6)

char* concat4(char *s1, char *s2, char *s3, char *s4)
{
char *result = malloc(strlen(s1) + strlen(s2) + + strlen(s3) + strlen(s4));
char *result = malloc(strlen(s1) + strlen(s2) + strlen(s3) + strlen(s4));
strcpy(result, s1);
strcat(result, s2);
strcat(result, " ");
Expand All @@ -64,6 +65,45 @@ char* concat4(char *s1, char *s2, char *s3, char *s4)
return result;
}

char* concat5(char *s1, char *s2, char *s3, char *s4, char *s5)
{
char *result = malloc(strlen(s1) + strlen(s2) + strlen(s3) + strlen(s4) + strlen(s5));
strcpy(result, s1);
strcat(result, s2);
strcat(result, " ");
strcat(result, s3);
strcat(result, s4);
strcat(result, s5);
strcat(result, s2);
strcat(result, s4);
return result;
}

char* concat7(char *s1, char *s2, char *s3, char *s4, char *s5)
{
char *result = malloc(strlen(s1) + strlen(s2) + strlen(s3) + strlen(s4) + strlen(s5));
strcpy(result, s1);
strcat(result, s2);
strcat(result, " src='");
strcat(result, s3);
strcat(result, "' ");
strcat(result, s4);
strcat(result, s5);
return result;
}

char* concat8(char *s1, char *s2, char *s3, char *s4)
{
char *result = malloc(strlen(s1) + strlen(s2) + strlen(s3) + strlen(s4) + strlen(s3) + strlen(s2));
strcpy(result, s1);
strcat(result, s2);
strcat(result, s3);
strcat(result, s4);
strcat(result, s2);
strcat(result, s3);
return result;
}

const char * parse(char * gotten) {
char *line = malloc(strlen(gotten));
strcpy(line,gotten);
Expand All @@ -73,7 +113,7 @@ const char * parse(char * gotten) {
char *array[3] = {NULL};
while (p != NULL)
{
//printf("%s\n",trimwhitespace(p));
printf("%s\n",trimwhitespace(p));
array[i++] = trimwhitespace(p);
p = strtok(NULL, delim);
}
Expand All @@ -95,7 +135,11 @@ const char * parse(char * gotten) {
|| strcmp(array[0], "s") == 0
|| strcmp(array[0], "strong") == 0) {
if (array[2] == NULL) {
return concat1("<", array[0], ">", array[1], "</");
if (array[1] == NULL) {
return concat8("<", array[0], ">", "</");
} else {
return concat1("<", array[0], ">", array[1], "</");
}
} else {
if (strcmp(array[2], "") == 0
|| strcmp(array[2], ".") == 0
Expand All @@ -119,19 +163,39 @@ const char * parse(char * gotten) {
|| strcmp(array[0], "tr") == 0
|| strcmp(array[0], "td") == 0
|| strcmp(array[0], "pre") == 0
|| strcmp(array[0], "code") == 0) {
|| strcmp(array[0], "code") == 0
|| strcmp(array[0], "ol") == 0
|| strcmp(array[0], "ul") == 0) {
if (array[2] == NULL) {
if (array[1] == NULL) {
return concat8("<", array[0], ">", "</");
} else {
return concat4("<", array[0], array[1], ">");
}
} else {
if (strcmp(array[2], "") == 0
|| strcmp(array[2], ".") == 0
|| strcmp(array[2], " ") == 0) {
return concat5("<", array[0], array[1], ">", "</");
} else {
return concat3("<", array[0], array[1], ">", array[2], "</");
}
}
} else if (strcmp(array[0], "img") == 0) {
if (array[2] == NULL) {
return concat4("<", array[0], array[1], ">");
} /*else {
if (strcmp(array[2], "") == 0
|| strcmp(array[2], ".") == 0
|| strcmp(array[2], " ") == 0) {
return concat4("<", array[0], array[1], ">", "</");
}
}*/
return concat4("<", array[0], array[1], " />");
} else {
return concat7("<", array[0], array[1], array[2], " />");
}
} else if (strcmp(array[0], "input") == 0) {
if (array[1] == NULL) {
return "";
} else {
return concat4("<", array[0], array[1], " />");
}
} else {
return "else";
};
//return array;
}
}

char* readLine() {
Expand All @@ -143,7 +207,6 @@ char* readLine() {
if (fp == NULL)
exit(EXIT_FAILURE);
while ((read = getline(&line, &len, fp)) != -1) {
//printf("Retrieved line of length %zu:\n", read);
printf("%s", parse(line));
}
fclose(fp);
Expand Down

0 comments on commit a034ea8

Please sign in to comment.