-
Notifications
You must be signed in to change notification settings - Fork 0
/
html.c
73 lines (71 loc) · 1.07 KB
/
html.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* Convert text file into html */
void fix(char *o, char *i)
{
for (; *i; ++i)
if (*i=='&')
{
*o++ = '&';
*o++ = 'a';
*o++ = 'm';
*o++ = 'p';
*o++ = ';';
}
else if (*i=='<')
{
*o++ = '&';
*o++ = 'l';
*o++ = 't';
*o++ = ';';
}
else if (*i=='>')
{
*o++ = '&';
*o++ = 'g';
*o++ = 't';
*o++ = ';';
}
else
*o++ = *i;
*o = 0;
}
main()
{
char buf[1024];
char fixed[1024];
int inpara = 0;
while(gets(buf))
{
int x;
int isblank = 1;
fix(fixed, buf);
for (x = 0; buf[x]; ++x)
if(buf[x] != ' ' && buf[x] != '\t')
isblank = 0;
if (!inpara)
{
if (isblank)
{
printf("\n");
}
else
{
inpara = 1;
printf("<p>%s\n",fixed);
}
}
else
{
if (isblank)
{
printf("</p>\n");
inpara = 0;
}
else
{
printf("%s\n",fixed);
}
}
}
if (inpara)
printf("</p>\n");
}