XML/Output: Difference between revisions

Content added Content deleted
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
(Added Commodore BASIC)
Line 697: Line 697:
380 NEXT N
380 NEXT N
390 RETURN</lang>
390 RETURN</lang>


==={{header|Commodore BASIC}}===

Not terribly different from the Applesoft BASIC example above, but this allows for a few more character/entity translations.

<lang gwbasic>1 rem xml/output - commodore basic
2 rem rosetta code
5 print chr$(147);chr$(14):gosub 900
10 rem set up array structure for data
11 rem we'll use a multi-dimensional array:
12 rem c$(x,y) where x is the rows and y is the fields
13 rem two fields: 0 = character name, 1 = remarks
15 dim c$(10,1):x=0:q$=chr$(34)
19 rem now read the data to populate the structure
20 for y=0 to 1
25 read t$
30 if t$="[end]" then x=x-1:goto 45
35 c$(x,y)=t$:print t$
40 next y:x=x+1:print:goto 20
45 rem need to sanitize for html entities
50 gosub 500
55 rem now we parse it out to xml format
60 print:print:gosub 150
70 end
75 :
150 print "<CharacterRemarks>"
155 for i=0 to x
160 t$="<Character name="+q$+c$(i,0)+q$+">"
165 t$=t$+c$(i,1)+"</Character>"
170 print " ";t$
175 next i
180 print "</CharacterRemarks>"
185 print
190 return
195 :
500 rem code html entities
505 for i=0 to x
510 for j=0 to 1
515 tm$=c$(i,j):tl=len(tm$):zz$=""
520 for tc=1 to tl
525 tc$=mid$(tm$,tc,1):cv=asc(tc$) and 127
530 zz$=zz$+et$(cv)
535 next tc
540 c$(i,j)=zz$
545 next j,i
550 return
555 :
900 rem set up entity lookup table
905 dim et$(127):for i=0 to 127:et$(i)=chr$(i):next
910 for i=1 to 15:read ci,et$(ci):next i:return
915 data 34,"&quot;",63,"&quest;",35,"&num;",64,"&commat;",47,"&sol;"
920 data 60,"&lt;",62,"&gt;",91,"&lsqb;",93,"rsqb;",92,"&pound;"
925 data 36,"&dollar;",37,"&percnt;",94,"&uarr;",95,"&larr;"
930 data 38,"&amp;"
935 :
1000 data "April","Bubble: I'm > Tam and <= Emily"
1005 data "Tam O'Shanter","Burns: 'When chapman billies leave the street...'"
1010 data "Emily","Short & shrift"
1015 data "Joey","Always look ^."
1999 data "[end]","[end]"</lang>

{{out}}

<pre>April
Bubble: I'm > Tam and <= Emily
Tam O'Shanter
Burns: 'When chapman billies leave the street...'
Emily
Short & shrift
Joey
Always look &uarr;.

<CharacterRemarks>
<Character name="April">Bubble: I'm &gt; Tam and &lt;= Emily</Character>
<Character name="Tam O'Shanter">Burns: 'When chapman billies leave the street...'</Character>
<Character name="Emily">Short &amp; shrift</Character>
<Character name="Joey">Always look &uarr;.</Character>
</CharacterRemarks>
ready.
&#9608;</pre>


=={{header|Bracmat}}==
=={{header|Bracmat}}==