interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / drafts / rosettacode / word-wrap.wiki

87 lines · 2775 bytes Raw Blame History
1=={{header|Omegese}}==
2{{works with|omc|sha256 2c824805, aien-dev/omega-mv e5b32567, Linux AArch64}}
3Omega has no imports, so the small output helpers (<code>emit</code> and friends) are part of the program.
4<syntaxhighlight lang="text">
5om2
6text nl "\n"
7text sp " "
8text rule "----\n"
9text para "In olden times when wishing still helped one, there lived a king whose daughters were all beautiful, but the youngest was so beautiful that the sun itself, which has seen so much, was astonished whenever it shone in her face. Close by the king's castle lay a great dark forest, and under an old lime-tree in the forest was a well, and when the day was very warm, the king's child went out into the forest and sat down by the side of the cool fountain, and when she was bored she took a golden ball, and threw it up on high and caught it, and this ball was her favorite plaything."
10note emit writes every byte of a to stdout; a short write is retried, an error exits 1
11fn emit a view uchar * to void
12o = ulong 0
13while lt o len a bound 4096
14k = write 1 a o sub len a o
15if le k 0
16exit 1
17end
18o = add o ulong k
19end
20end
21note greedy wrap: a word goes on the current line when it still fits in width w, else starts a new one
22fn wrap a view uchar * w ulong to void
23cur = ulong 0
24i = ulong 0
25while lt i len a bound 4096
26if eq get a i 32
27i = add i 1
28else
29j = i
30while lt j len a bound 4096
31if eq get a j 32
32break
33end
34j = add j 1
35end
36l = sub j i
37if eq cur 0
38cur = l
39else
40if le add add cur 1 l w
41emit sp
42cur = add add cur 1 l
43else
44emit nl
45cur = l
46end
47end
48emit part a i l
49i = j
50end
51end
52emit nl
53end
54fn main to int
55wrap para 72
56emit rule
57wrap para 40
58ret 0
59end
60</syntaxhighlight>
61{{out}}
62<pre>
63In olden times when wishing still helped one, there lived a king whose
64daughters were all beautiful, but the youngest was so beautiful that the
65sun itself, which has seen so much, was astonished whenever it shone in
66her face. Close by the king's castle lay a great dark forest, and under
67an old lime-tree in the forest was a well, and when the day was very
68warm, the king's child went out into the forest and sat down by the side
69of the cool fountain, and when she was bored she took a golden ball, and
70threw it up on high and caught it, and this ball was her favorite
71plaything.
72----
73In olden times when wishing still helped
74one, there lived a king whose daughters
75were all beautiful, but the youngest was
76so beautiful that the sun itself, which
77has seen so much, was astonished
78...
79forest, and under an old lime-tree in
80the forest was a well, and when the day
81was very warm, the king's child went out
82into the forest and sat down by the side
83of the cool fountain, and when she was
84bored she took a golden ball, and threw
85it up on high and caught it, and this
86ball was her favorite plaything.
87</pre>