67 lines
2.0 KiB
Plaintext
67 lines
2.0 KiB
Plaintext
10 rem ********************************
|
|
20 rem print words in columns
|
|
30 rem commodore basic 2.0
|
|
40 rem ********************************
|
|
50 print chr$(14) : rem change to upper/lower case set
|
|
60 gosub 140 : rem find length of longest word
|
|
70 algn$ = "left"
|
|
80 gosub 260 : rem print aligned text
|
|
90 algn$ = "center"
|
|
100 gosub 260
|
|
110 algn$ = "right"
|
|
120 gosub 260
|
|
130 end
|
|
140 rem *** find length of longest word
|
|
150 mx=0
|
|
160 for i=1 to 6
|
|
170 read a$
|
|
180 n=1
|
|
190 for j=1 to len(a$)
|
|
200 if mid$(a$,j,1)<>"$" then n=n+1: goto 230
|
|
210 if mx<n then mx=n
|
|
220 n=1
|
|
230 next
|
|
240 next
|
|
250 return
|
|
260 rem print aligned text
|
|
270 restore : rem reset data read pointer
|
|
280 s$ = " "
|
|
290 print : print algn$;"-aligned"
|
|
300 c=1 : rem column counter
|
|
310 for i=1 to 6
|
|
320 read a$
|
|
330 n=1
|
|
340 for j=1 to len(a$)
|
|
350 if mid$(a$,j,1)<>"$" then n=n+1 : goto 380
|
|
360 gosub 440 : rem print word
|
|
370 n=1
|
|
380 next
|
|
390 if n>1 then gosub 440
|
|
400 next
|
|
410 print
|
|
420 return
|
|
430 rem ********* print word **********
|
|
440 b$ = mid$(a$,j-n+1,n-1)
|
|
450 b = len(b$)
|
|
460 if algn$ = "center" then 520
|
|
470 if algn$ = "right" then 570
|
|
480 if c+b<40 and c+mx>40 then print b$: c=1: return
|
|
490 if c+mx>40 then print : c=1
|
|
500 print b$;left$(s$,mx-b);: c=c+mx
|
|
510 return
|
|
520 if c+mx>40 then print : c=1
|
|
530 bb=(mx-b)/2 : ba=bb
|
|
540 if bb>1 and int(bb)=bb then ba=bb-1
|
|
550 print left$(s$,ba);b$;left$(s$,bb);: c=c+mx
|
|
560 return
|
|
570 if c+mx>40 then print : c=1
|
|
580 print left$(s$,mx-b);b$;: c=c+mx
|
|
590 return
|
|
600 rem *********** the words *********
|
|
610 data "Given$a$text$file$of$many$lines,$where$fields$within$a$line$"
|
|
620 data "are$delineated$by$a$single$'dollar'$character,$write$a$program"
|
|
630 data "that$aligns$each$column$of$fields$by$ensuring$that$words$in$each$"
|
|
640 data "column$are$separated$by$at$least$one$space."
|
|
650 data "Further,$allow$for$each$word$in$a$column$to$be$either$left$"
|
|
660 data "justified,$right$justified,$or$center$justified$within$its$column"
|