![]() |
Compilerbau htmlparser |
#include <stdio.h>
#include <string.h>
#define TOKEN_FLAG_IS_NOT_TAG 0
#define TOKEN_FLAG_IS_TAG_OPEN 1
#define TOKEN_FLAG_IS_TAG_CLOSE 2
#define TOKEN_FLAG_EOF 3
char tokenbuf[256];
int tokenflag;
char tagstack[256][256];
int sp = 0;
void push(char *str) {
strcpy(tagstack[sp], str);
sp++;
}
void pop(char *str) {
sp--;
strcpy(str, tagstack[sp]);
}
FILE *fp;
int gettoken(char *str) {
int i;
int tflag;
int ch;
if(feof(fp))
return TOKEN_FLAG_EOF;
while(((ch = fgetc(fp)) != '<') && (!feof(fp)));
if(feof(fp))
return TOKEN_FLAG_EOF;
i = 0;
str[i] = ch;
while((ch = fgetc(fp)) == ' ');
i = 1;
str[i] = ch;
if(ch == '/')
tflag = TOKEN_FLAG_IS_TAG_CLOSE;
else
tflag = TOKEN_FLAG_IS_TAG_OPEN;
i = 2;
while((ch = fgetc(fp)) != '>') {
str[i] = ch;
i++;
}
str[i] = ch;
i++;
str[i] = 0x00;
return tflag;
}
int tagcmp(char *tag1, char *tag2) {
int i, j;
if((tag1[0] != '<') && (tag2[0] != 0))
return -2;
i = 1;
j = 1;
while(tag1[i] == ' ') i++;
while(tag2[j] == ' ') j++;
if(tag2[j] != '/')
return -3;
j++;
while(tag2[j] == ' ') j++;
while((tag1[i] != ' ') && (tag1[i] != '>') && (tag2[j] != ' ') && (tag2[j] != '>')) {
if(tag1[i] != tag2[j])
return -1;
i++;
j++;
}
if((tag1[i] != ' ') && (tag1[i] != '>'))
return -1;
if((tag2[j] != ' ') && (tag2[j] != '>'))
return -1;
return 0;
}
void factor() {
char tokenbuf2[256];
tokenflag = gettoken(tokenbuf);
if(tokenflag == TOKEN_FLAG_EOF)
return;
else if(tokenflag == TOKEN_FLAG_IS_TAG_OPEN)
push(tokenbuf);
else if(tokenflag == TOKEN_FLAG_IS_TAG_CLOSE) {
pop(tokenbuf2);
tagcmp(tokenbuf2, tokenbuf);
while(tagcmp(tokenbuf2, tokenbuf) != 0) {
pop(tokenbuf2);
}
printf("%s %s\n", tokenbuf, tokenbuf2);
}
factor();
}
int main(void) {
if((fp = fopen("test.html", "r")) == NULL) {
perror("Can't open HTML-File");
return -2;
}
factor();
fclose(fp);
return 0;
}
<tag>
<tag1>
<tag2>
</tag2>
<tag2>
</tag2>
<tag1>
</tag1>
</tag1>
<tag2>
<tag1>
</tag1>
</tag2>
</tag>
Auch getestet, an dem:
<tag>
<tag1>
<tag2>
</tag2>
<tag2>
</tag2>
<tag1>
<br>
<br>
</tag1>
</tag1>
<tag2>
<tag1>
</tag1>
</tag2>
</tag>
#include <stdio.h>
#include <string.h>
#define TOKEN_FLAG_IS_NOT_TAG 0
#define TOKEN_FLAG_IS_TAG_OPEN 1
#define TOKEN_FLAG_IS_TAG_CLOSE 2
#define TOKEN_FLAG_EOF 3
char tokenbuf[256];
int tokenflag;
char tagstack[1024][256];
int sp = 0;
void push(char *str) {
strcpy(tagstack[sp], str);
sp++;
}
void pop(char *str) {
sp--;
strcpy(str, tagstack[sp]);
}
FILE *fp;
int gettoken(char *str) {
int i;
int tflag;
int ch;
if(feof(fp))
return TOKEN_FLAG_EOF;
while(((ch = fgetc(fp)) != '<') && (!feof(fp)));
if(feof(fp))
return TOKEN_FLAG_EOF;
i = 0;
str[i] = ch;
while((ch = fgetc(fp)) == ' ');
i = 1;
str[i] = ch;
if(ch == '/')
tflag = TOKEN_FLAG_IS_TAG_CLOSE;
else
tflag = TOKEN_FLAG_IS_TAG_OPEN;
i = 2;
while((ch = fgetc(fp)) != '>') {
str[i] = ch;
i++;
}
str[i] = ch;
i++;
str[i] = 0x00;
return tflag;
}
int tagcmp(char *tag1, char *tag2) {
int i, j;
if((tag1[0] != '<') && (tag2[0] != 0))
return -2;
i = 1;
j = 1;
while(tag1[i] == ' ') i++;
while(tag2[j] == ' ') j++;
if(tag2[j] != '/')
return -3;
j++;
while(tag2[j] == ' ') j++;
while((tag1[i] != ' ') && (tag1[i] != '>') && (tag2[j] != ' ') && (tag2[j] != '>')) {
if(tag1[i] != tag2[j])
return -1;
i++;
j++;
}
if((tag1[i] != ' ') && (tag1[i] != '>'))
return -1;
if((tag2[j] != ' ') && (tag2[j] != '>'))
return -1;
return 0;
}
void factor() {
char tokenbuf2[256];
while(1) {
tokenflag = gettoken(tokenbuf);
if(tokenflag == TOKEN_FLAG_EOF)
return;
else if(tokenflag == TOKEN_FLAG_IS_TAG_OPEN)
push(tokenbuf);
else if(tokenflag == TOKEN_FLAG_IS_TAG_CLOSE) {
pop(tokenbuf2);
tagcmp(tokenbuf2, tokenbuf);
while(tagcmp(tokenbuf2, tokenbuf) != 0) {
pop(tokenbuf2);
}
printf("%s %s\n", tokenbuf2, tokenbuf);
}
}
}
int main(void) {
if((fp = fopen("test.html", "r")) == NULL) {
perror("Can't open HTML-File");
return -2;
}
factor();
fclose(fp);
return 0;
}
Da kommt noch ein Fehler, weil das Ende der Datei wird nicht richtig erkannt und es kommt ein Fehler. Das märze ich als erstes aus.
<html>
<head> <title> </title> </head>
<body>
<br><br>
<ul>
<li> Hallo </li>
<li> Hallo </li>
<li> Hallo </li>
</ul>
</body>
</html>
Nachdem wir uns über diesen Fehler klar geworden sind, pushen wir alle Tags auf einen zweiten Stack, die nicht geschlossen werden.
#include <stdio.h>
#include <string.h>
#define TOKEN_FLAG_IS_NOT_TAG 0
#define TOKEN_FLAG_IS_TAG_OPEN 1
#define TOKEN_FLAG_IS_TAG_CLOSE 2
#define TOKEN_FLAG_EOF 3
char tokenbuf[256];
int tokenflag;
char tagstack[1024][256];
char tagqueuenotclosed[512][256];
int sp = 0;
int qptop = 0;
int qpbot = 0;
void push(char *str) {
strcpy(tagstack[sp], str);
sp++;
}
void pop(char *str) {
sp--;
strcpy(str, tagstack[sp]);
}
void put(char *str) {
strcpy(tagqueuenotclosed[qptop], str);
qptop++;
}
int get(char *str) {
if (qpbot < qptop) {
strcpy(str, tagqueuenotclosed[qpbot]);
qpbot++;
return 1;
}
return 0;
}
FILE *fp;
int gettoken(char *str) {
int i;
int tflag;
int ch;
if(feof(fp))
return TOKEN_FLAG_EOF;
while(((ch = fgetc(fp)) != '<') && (!feof(fp)));
/*if(feof(fp))
return TOKEN_FLAG_EOF;*/
i = 0;
str[i] = ch;
while((!feof(fp)) && ((ch = fgetc(fp)) == ' '));
i = 1;
str[i] = ch;
if(ch == '/')
tflag = TOKEN_FLAG_IS_TAG_CLOSE;
else
tflag = TOKEN_FLAG_IS_TAG_OPEN;
i = 2;
while((!feof(fp)) && ((ch = fgetc(fp)) != '>')) {
str[i] = ch;
i++;
}
str[i] = ch;
i++;
str[i] = 0x00;
return tflag;
}
int tagcmp(char *tag1, char *tag2) {
int i, j;
if((tag1[0] != '<') && (tag2[0] != 0))
return -2;
i = 1;
j = 1;
while(tag1[i] == ' ') i++;
while(tag2[j] == ' ') j++;
if(tag2[j] != '/')
return -3;
j++;
while(tag2[j] == ' ') j++;
while((tag1[i] != ' ') && (tag1[i] != '>') && (tag2[j] != ' ') && (tag2[j] != '>')) {
if(tag1[i] != tag2[j])
return -1;
i++;
j++;
}
if((tag1[i] != ' ') && (tag1[i] != '>'))
return -1;
if((tag2[j] != ' ') && (tag2[j] != '>'))
return -1;
return 0;
}
void factor() {
char tokenbuf2[256];
while(1) {
tokenflag = gettoken(tokenbuf);
if(tokenflag == TOKEN_FLAG_EOF) {
break;
}
else if(tokenflag == TOKEN_FLAG_IS_TAG_OPEN)
push(tokenbuf);
else if(tokenflag == TOKEN_FLAG_IS_TAG_CLOSE) {
pop(tokenbuf2);
tagcmp(tokenbuf2, tokenbuf);
while(tagcmp(tokenbuf2, tokenbuf) != 0) {
put(tokenbuf2);
pop(tokenbuf2);
}
while(get(tokenbuf2) != 0)
printf("%s\n", tokenbuf2);
printf("%s %s\n", tokenbuf2, tokenbuf);
}
}
return;
}
int main(void) {
if((fp = fopen("test6.html", "r")) == NULL) {
perror("Can't open HTML-File");
return -2;
}
factor();
fclose(fp);
return 0;
}
Und kommt damit klar:
<html>
<head> <title> </title> </head>
<body>
<br>
<br>
<ul>
<li> Hallo </li>
<li> Hallo </li>
<li> Hallo </li>
</ul>
</body>
</html>
#include <stdio.h>
#include <string.h>
#define TOKEN_FLAG_IS_NOT_TAG 0
#define TOKEN_FLAG_IS_TAG_OPEN 1
#define TOKEN_FLAG_IS_TAG_CLOSE 2
#define TOKEN_FLAG_EOF 3
char tokenbuf[256];
int tokenflag;
char tagstack[1024][256];
char tagqueuenotclosed[512][256];
int sp = 0;
int qptop = 0;
int qpbot = 0;
void push(char *str) {
strcpy(tagstack[sp], str);
sp++;
}
void pop(char *str) {
sp--;
strcpy(str, tagstack[sp]);
}
void put(char *str) {
strcpy(tagqueuenotclosed[qptop], str);
qptop++;
}
int get(char *str) {
if (qpbot < qptop) {
strcpy(str, tagqueuenotclosed[qpbot]);
qpbot++;
return 1;
}
return 0;
}
FILE *fp;
int gettoken(char *str) {
int i;
int tflag;
int ch;
if(feof(fp))
return TOKEN_FLAG_EOF;
while(((ch = fgetc(fp)) != '<') && (!feof(fp)));
/*if(feof(fp))
return TOKEN_FLAG_EOF;*/
i = 0;
str[i] = ch;
while((!feof(fp)) && ((ch = fgetc(fp)) == ' '));
i = 1;
str[i] = ch;
if(ch == '/')
tflag = TOKEN_FLAG_IS_TAG_CLOSE;
else
tflag = TOKEN_FLAG_IS_TAG_OPEN;
i = 2;
while((!feof(fp)) && ((ch = fgetc(fp)) != '>')) {
str[i] = ch;
i++;
}
str[i] = ch;
i++;
str[i] = 0x00;
return tflag;
}
int tagcmp(char *tag1, char *tag2) {
int i, j;
if((tag1[0] != '<') && (tag2[0] != 0))
return -2;
i = 1;
j = 1;
while(tag1[i] == ' ') i++;
while(tag2[j] == ' ') j++;
if(tag2[j] != '/')
return -3;
j++;
while(tag2[j] == ' ') j++;
while((tag1[i] != ' ') && (tag1[i] != '>') && (tag2[j] != ' ') && (tag2[j] != '>')) {
if(tag1[i] != tag2[j])
return -1;
i++;
j++;
}
if((tag1[i] != ' ') && (tag1[i] != '>'))
return -1;
if((tag2[j] != ' ') && (tag2[j] != '>'))
return -1;
return 0;
}
void factor() {
char tokenbuf2[256];
while(1) {
tokenflag = gettoken(tokenbuf);
if(tokenflag == TOKEN_FLAG_EOF) {
break;
}
else if(tokenflag == TOKEN_FLAG_IS_TAG_OPEN)
push(tokenbuf);
else if(tokenflag == TOKEN_FLAG_IS_TAG_CLOSE) {
pop(tokenbuf2);
tagcmp(tokenbuf2, tokenbuf);
while(tagcmp(tokenbuf2, tokenbuf) != 0) {
put(tokenbuf2);
pop(tokenbuf2);
}
while(get(tokenbuf2) != 0)
printf("%s\n", tokenbuf2);
printf("%s %s\n", tokenbuf2, tokenbuf);
}
}
return;
}
void factor2() {
char tokenbuf2[256];
int flag = 0;
char color[64];
int width = 100;
int i;
strcpy(color, "blue");
while(1) {
tokenflag = gettoken(tokenbuf);
if(tokenflag == TOKEN_FLAG_EOF) {
break;
}
else if(tokenflag == TOKEN_FLAG_IS_TAG_OPEN) {
flag = 0;
for(i = 0; i < qptop; i++) {
if(strcmp(tagqueuenotclosed[i], tokenbuf) == 0)
flag = 1;
}
if(flag) {
printf("<br><br>\n");
printf("%s\n", tokenbuf);
printf("<br><br>\n");
}
else {
printf("<div width=\"%i \%\" color=\"%s\">", width, color);
printf("%s\n", tokenbuf);
if(strcmp(color, "blue") == 0)
strcpy(color, "white");
else
strcpy(color, "blue");
width -= 4;
}
push(tokenbuf);
}
else if(tokenflag == TOKEN_FLAG_IS_TAG_CLOSE) {
pop(tokenbuf2);
tagcmp(tokenbuf2, tokenbuf);
while(tagcmp(tokenbuf2, tokenbuf) != 0) {
put(tokenbuf2);
pop(tokenbuf2);
}
while(get(tokenbuf2) != 0);
printf("%s", tokenbuf);
printf("</div>\n");
width += 4;
}
}
return;
}
int main(void) {
if((fp = fopen("test6.html", "r")) == NULL) {
perror("Can't open HTML-File");
return -2;
}
factor();
fclose(fp);
if((fp = fopen("test6.html", "r")) == NULL) {
perror("Can't open HTML-File");
return -2;
}
factor2();
fclose(fp);
return 0;
}
So, ich habe es hingekriegt!
#include <stdio.h>
#include <string.h>
#define TOKEN_FLAG_IS_NOT_TAG 0
#define TOKEN_FLAG_IS_TAG_OPEN 1
#define TOKEN_FLAG_IS_TAG_CLOSE 2
#define TOKEN_FLAG_EOF 3
char tokenbuf[256];
int tokenflag;
char tagstack[1024][256];
char tagqueuenotclosed[512][256];
int sp = 0;
int qptop = 0;
int qpbot = 0;
void push(char *str) {
strcpy(tagstack[sp], str);
sp++;
}
void pop(char *str) {
sp--;
strcpy(str, tagstack[sp]);
}
void put(char *str) {
strcpy(tagqueuenotclosed[qptop], str);
qptop++;
}
int get(char *str) {
if (qpbot < qptop) {
strcpy(str, tagqueuenotclosed[qpbot]);
qpbot++;
return 1;
}
return 0;
}
FILE *fp;
int gettoken(char *str) {
int i;
int tflag;
int ch;
if(feof(fp))
return TOKEN_FLAG_EOF;
while(((ch = fgetc(fp)) != '<') && (!feof(fp)));
/*if(feof(fp))
return TOKEN_FLAG_EOF;*/
i = 0;
str[i] = ch;
while((!feof(fp)) && ((ch = fgetc(fp)) == ' '));
i = 1;
str[i] = ch;
if(ch == '/')
tflag = TOKEN_FLAG_IS_TAG_CLOSE;
else
tflag = TOKEN_FLAG_IS_TAG_OPEN;
i = 2;
while((!feof(fp)) && ((ch = fgetc(fp)) != '>')) {
str[i] = ch;
i++;
}
str[i] = ch;
i++;
str[i] = 0x00;
return tflag;
}
int tagcmp(char *tag1, char *tag2) {
int i, j;
if((tag1[0] != '<') && (tag2[0] != 0))
return -2;
i = 1;
j = 1;
while(tag1[i] == ' ') i++;
while(tag2[j] == ' ') j++;
if(tag2[j] != '/')
return -3;
j++;
while(tag2[j] == ' ') j++;
while((tag1[i] != ' ') && (tag1[i] != '>') && (tag2[j] != ' ') && (tag2[j] != '>')) {
if(tag1[i] != tag2[j])
return -1;
i++;
j++;
}
if((tag1[i] != ' ') && (tag1[i] != '>'))
return -1;
if((tag2[j] != ' ') && (tag2[j] != '>'))
return -1;
return 0;
}
void factor() {
char tokenbuf2[256];
while(1) {
tokenflag = gettoken(tokenbuf);
if(tokenflag == TOKEN_FLAG_EOF) {
break;
}
else if(tokenflag == TOKEN_FLAG_IS_TAG_OPEN)
push(tokenbuf);
else if(tokenflag == TOKEN_FLAG_IS_TAG_CLOSE) {
pop(tokenbuf2);
tagcmp(tokenbuf2, tokenbuf);
while(tagcmp(tokenbuf2, tokenbuf) != 0) {
put(tokenbuf2);
pop(tokenbuf2);
}
while(get(tokenbuf2) != 0);
//printf("%s\n", tokenbuf2);
//printf("%s %s\n", tokenbuf2, tokenbuf);
}
}
return;
}
void maketagtohtmlentities(char *tag, char *out) {
int i;
int j;
int n;
n = strlen(tag);
for(i = 0, j = 0; j < n; j++) {
if(tag[j] == '<') {
out[i+0] = '&';
out[i+1] = 'l';
out[i+2] = 't';
out[i+3] = ';';
i += 4;
}
else if(tag[j] == '>') {
out[i+0] = '&';
out[i+1] = 'g';
out[i+2] = 't';
out[i+3] = ';';
i += 4;
}
else {
out[i] = tag[j];
i++;
}
}
out[i] = 0x00;
}
void factor2() {
char tokenbuf2[256];
char tokenbuf3[256];
int flag = 0;
char color[64];
int width = 100;
int i;
strcpy(color, "blue");
while(1) {
tokenflag = gettoken(tokenbuf);
if(tokenflag == TOKEN_FLAG_EOF) {
break;
}
else if(tokenflag == TOKEN_FLAG_IS_TAG_OPEN) {
flag = 0;
for(i = 0; i < qptop; i++) {
if(strcmp(tagqueuenotclosed[i], tokenbuf) == 0)
flag = 1;
}
if(flag) {
printf("<br><br>\n");
maketagtohtmlentities(tokenbuf, tokenbuf3);
printf("%s\n", tokenbuf3);
printf("<br><br>\n");
}
else {
printf("<div style=\"width: %i\%; background-color: %s; margin:2\%;\">", width, color);
maketagtohtmlentities(tokenbuf, tokenbuf3);
printf("%s\n", tokenbuf3);
if(strcmp(color, "blue") == 0)
strcpy(color, "white");
else
strcpy(color, "blue");
width -= 4;
}
push(tokenbuf);
}
else if(tokenflag == TOKEN_FLAG_IS_TAG_CLOSE) {
pop(tokenbuf2);
tagcmp(tokenbuf2, tokenbuf);
while(tagcmp(tokenbuf2, tokenbuf) != 0) {
put(tokenbuf2);
pop(tokenbuf2);
}
while(get(tokenbuf2) != 0);
maketagtohtmlentities(tokenbuf, tokenbuf3);
printf("%s\n", tokenbuf3);
printf("</div>\n");
width += 4;
}
}
return;
}
int main(void) {
if((fp = fopen("test6.html", "r")) == NULL) {
perror("Can't open HTML-File");
return -2;
}
factor();
fclose(fp);
if((fp = fopen("test6.html", "r")) == NULL) {
perror("Can't open HTML-File");
return -2;
}
factor2();
fclose(fp);
return 0;
}
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define TOKEN_FLAG_IS_NOT_TAG 0
#define TOKEN_FLAG_IS_TAG_OPEN 1
#define TOKEN_FLAG_IS_TAG_CLOSE 2
#define TOKEN_FLAG_EOF 3
char tokenbuf[256];
int tokenflag;
char tagstack[1024][256];
char tagqueuenotclosed[512][256];
int sp = 0;
int qptop = 0;
int qpbot = 0;
void push(char *str) {
strcpy(tagstack[sp], str);
sp++;
}
void pop(char *str) {
sp--;
strcpy(str, tagstack[sp]);
}
void put(char *str) {
strcpy(tagqueuenotclosed[qptop], str);
qptop++;
}
int get(char *str) {
if (qpbot < qptop) {
strcpy(str, tagqueuenotclosed[qpbot]);
qpbot++;
return 1;
}
return 0;
}
FILE *fp;
int gettoken(char *str) {
int i;
int tflag;
int ch;
if(feof(fp))
return TOKEN_FLAG_EOF;
while(((ch = fgetc(fp)) != '<') && (!feof(fp)));
/*if(feof(fp))
return TOKEN_FLAG_EOF;*/
i = 0;
str[i] = ch;
while((!feof(fp)) && ((ch = fgetc(fp)) == ' '));
i = 1;
str[i] = ch;
if(ch == '/')
tflag = TOKEN_FLAG_IS_TAG_CLOSE;
else
tflag = TOKEN_FLAG_IS_TAG_OPEN;
i = 2;
while((!feof(fp)) && ((ch = fgetc(fp)) != '>')) {
str[i] = ch;
i++;
}
str[i] = ch;
i++;
str[i] = 0x00;
return tflag;
}
int tagcmp(char *tag1, char *tag2) {
int i, j;
if((tag1[0] != '<') && (tag2[0] != 0))
return -2;
i = 1;
j = 1;
while(tag1[i] == ' ') i++;
while(tag2[j] == ' ') j++;
if(tag2[j] != '/')
return -3;
j++;
while(tag2[j] == ' ') j++;
while((tag1[i] != ' ') && (tag1[i] != '>') && (tag2[j] != ' ') && (tag2[j] != '>')) {
if(tag1[i] != tag2[j])
return -1;
i++;
j++;
}
if((tag1[i] != ' ') && (tag1[i] != '>'))
return -1;
if((tag2[j] != ' ') && (tag2[j] != '>'))
return -1;
return 0;
}
void factor() {
char tokenbuf2[256];
while(1) {
tokenflag = gettoken(tokenbuf);
if(tokenflag == TOKEN_FLAG_EOF) {
break;
}
else if(tokenflag == TOKEN_FLAG_IS_TAG_OPEN)
push(tokenbuf);
else if(tokenflag == TOKEN_FLAG_IS_TAG_CLOSE) {
pop(tokenbuf2);
tagcmp(tokenbuf2, tokenbuf);
while(tagcmp(tokenbuf2, tokenbuf) != 0) {
put(tokenbuf2);
pop(tokenbuf2);
}
while(get(tokenbuf2) != 0);
//printf("%s\n", tokenbuf2);
//printf("%s %s\n", tokenbuf2, tokenbuf);
}
}
return;
}
void maketagtohtmlentities(char *tag, char *out) {
int i;
int j;
int n;
n = strlen(tag);
for(i = 0, j = 0; j < n; j++) {
if(tag[j] == '<') {
out[i+0] = '&';
out[i+1] = 'l';
out[i+2] = 't';
out[i+3] = ';';
i += 4;
}
else if(tag[j] == '>') {
out[i+0] = '&';
out[i+1] = 'g';
out[i+2] = 't';
out[i+3] = ';';
i += 4;
}
else {
out[i] = tag[j];
i++;
}
}
out[i] = 0x00;
}
void factor2() {
char tokenbuf2[256];
char tokenbuf3[256];
int flag = 0;
char color[64];
int width = 100;
int i;
char color1, color2, color3;
strcpy(color, "deepskyblue");
while(1) {
tokenflag = gettoken(tokenbuf);
if(tokenflag == TOKEN_FLAG_EOF) {
break;
}
else if(tokenflag == TOKEN_FLAG_IS_TAG_OPEN) {
flag = 0;
for(i = 0; i < qptop; i++) {
if(strcmp(tagqueuenotclosed[i], tokenbuf) == 0)
flag = 1;
}
if(flag) {
printf("<br><br>\n");
maketagtohtmlentities(tokenbuf, tokenbuf3);
printf("%s\n", tokenbuf3);
printf("<br><br>\n");
}
else {
color1 = (rand() % 64)+64;
color2 = (rand() % 64)+64;
color3 = (rand() % 64)+64;
printf("<div style=\"width: %i\%; background-color: %X%X%X; margin:2\%;\">", width, color1, color2, color3);
maketagtohtmlentities(tokenbuf, tokenbuf3);
printf("%s\n", tokenbuf3);
if(strcmp(color, "deepskyblue") == 0)
strcpy(color, "white");
else
strcpy(color, "deepskyblue");
width -= 4;
}
push(tokenbuf);
}
else if(tokenflag == TOKEN_FLAG_IS_TAG_CLOSE) {
pop(tokenbuf2);
tagcmp(tokenbuf2, tokenbuf);
while(tagcmp(tokenbuf2, tokenbuf) != 0) {
put(tokenbuf2);
pop(tokenbuf2);
}
while(get(tokenbuf2) != 0);
maketagtohtmlentities(tokenbuf, tokenbuf3);
printf("%s\n", tokenbuf3);
printf("</div>\n");
width += 4;
}
}
return;
}
int main(void) {
if((fp = fopen("test6.html", "r")) == NULL) {
perror("Can't open HTML-File");
return -2;
}
factor();
fclose(fp);
if((fp = fopen("test6.html", "r")) == NULL) {
perror("Can't open HTML-File");
return -2;
}
factor2();
fclose(fp);
return 0;
}
David Vajda
Schickhardtstraße 5
D-72072, Tübingen
+491735807467
david@ituenix.de
http://www.ituenix.de