CSV to HTML translation: Difference between revisions
Content added Content deleted
m (→{{header|Powershell}}: Fix case) |
|||
Line 101: | Line 101: | ||
</tr> |
</tr> |
||
</table></lang> |
</table></lang> |
||
=={{header|ALGOL 68}}== |
|||
{{works with|ALGOL 68|Revision 1 - no extensions to language used.}} |
|||
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/algol68g-1.18.0-9h.tiny.el5.centos.fc11.i386.rpm/download 1.18.0-9h.tiny].}} |
|||
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d] - due to extensive use of '''format'''[ted] ''transput''.}} |
|||
<lang algol68>#!/usr/local/bin/a68g --script # |
|||
[6]STRING lines := []STRING( |
|||
"Character,Speech ", |
|||
"The multitude,The messiah! Show us the messiah! ", |
|||
"Brians mother,<angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry> ", |
|||
"The multitude,Who are you? ", |
|||
"Brians mother,I'm his mother; that's who! ", |
|||
"The multitude,Behold his mother! Behold his mother! " |
|||
); |
|||
[max abs char]STRING encoded; FOR i TO UPB encoded DO encoded[i]:=REPR i OD; |
|||
encoded[ABS""""] := """; |
|||
encoded[ABS "&"] := "&"; |
|||
encoded[ABS "<"] := "<"; |
|||
encoded[ABS ">"] := ">"; |
|||
OP ENCODE = (STRING s)STRING: ( |
|||
STRING out := ""; |
|||
FOR i TO UPB s DO out+:= encoded[ABS s[i]] OD; |
|||
out |
|||
); |
|||
PROC head = VOID: |
|||
printf(($gl$, |
|||
"<HEAD>", |
|||
"<TITLE>CSV to HTML translation - Extra Credit</TITLE>", |
|||
"<STYLE type=""text/css"">", |
|||
"TD {background-color:#ddddff; }", |
|||
"thead TD {background-color:#ddffdd; text-align:center; }", |
|||
"</STYLE>", |
|||
"</HEAD>" |
|||
)); |
|||
# define HTML tags using Algol68's "reverent" block structuring # |
|||
PROC html = VOID: print(("<HTML>", new line)), |
|||
body = VOID: print(("<BODY>", new line)), |
|||
table = VOID: print(("<TABLE>", new line)), |
|||
table row = VOID: print(("<TR>")), |
|||
th = (STRING s)VOID: printf(($"<TH>"g"</TH>"$, s)), |
|||
td = (STRING s)VOID: printf(($"<TD>"g"</TD>"$, s)), |
|||
elbat row = VOID: print(("</TR>", new line)), |
|||
elbat = VOID: print(("</TABLE>", new line)), |
|||
ydob = VOID: print(("</BODY>", new line)), |
|||
lmth = VOID: print(("</HTML>", new line)); |
|||
FILE input; STRING line; CHAR ifs = ","; |
|||
associate(input, line); |
|||
make term(input, ifs); |
|||
html; |
|||
head; |
|||
body; |
|||
table; |
|||
FOR nr TO UPB lines DO |
|||
line := lines[nr]; |
|||
table row; |
|||
on logical file end(input, (REF FILE input)BOOL: line end); |
|||
DO |
|||
STRING s; get(input,s); |
|||
(nr=1|th|td)(ENCODE s); |
|||
get(input, space) |
|||
OD; |
|||
line end: reset(input); |
|||
elbat row |
|||
OD; |
|||
elbat; |
|||
ydob; |
|||
lmth</lang> |
|||
Output: |
|||
<lang html5> |
|||
<HTML> |
|||
<HEAD> |
|||
<TITLE>CSV to HTML translation - Extra Credit</TITLE> |
|||
<STYLE type="text/css"> |
|||
TD {background-color:#ddddff; } |
|||
thead TD {background-color:#ddffdd; text-align:center; } |
|||
</STYLE> |
|||
</HEAD> |
|||
<BODY> |
|||
<TABLE> |
|||
<TR><TH>Character</TH><TH>Speech </TH></TR> |
|||
<TR><TD>The multitude</TD><TD>The messiah! Show us the messiah! </TD></TR> |
|||
<TR><TD>Brians mother</TD><TD><angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry> </TD></TR> |
|||
<TR><TD>The multitude</TD><TD>Who are you? </TD></TR> |
|||
<TR><TD>Brians mother</TD><TD>I'm his mother; that's who! </TD></TR> |
|||
<TR><TD>The multitude</TD><TD>Behold his mother! Behold his mother! </TD></TR> |
|||
</TABLE> |
|||
</BODY> |
|||
</HTML> |
|||
</lang> |
|||
=={{header|C}}== |
=={{header|C}}== |