7 function q_insert(q, s)
12 return q.first >= q.last
24 return q.last - q.first
26 function q_length(q, f)
27 local l, i = 0, q.first
35 local blanks = MAX - q_length(q)
36 local skips = q_card(q) - 1
37 local line = q_remove(q)
38 local quotient = floor(blanks/skips)
39 local reminder = blanks/skips - quotient
42 error = error + reminder
45 line = line .. strrep(" ", quotient+1)
47 line = line .. strrep(" ", quotient)
49 line = line .. q_remove(q)
55 local line = q_remove(q)
56 while not q_empty(q) do
57 line = line .. " " .. q_remove(q)
62 if not arg or getn(arg) < 1 then
65 MAX = tonumber(arg[1])
66 if not MAX or MAX < 0 then
73 _, n = gsub(line, "(%S+)", function (s) q_insert(%text, s) end)
84 if not q_empty(line) then
85 write(catenate(line), "\n\n")
90 elseif size + strlen(word) > MAX then
91 write(justify(line), "\n")
96 size = size + strlen(word) + 1
100 write(catenate(line), "\n")