September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -0,0 +1,56 @@
DATA 6
DATA "Given$a$text$file$of$many$lines,$where$fields$within$a$line$"
DATA "are$delineated$by$a$single$'dollar'$character,$write$a$program"
DATA "that$aligns$each$column$of$fields$by$ensuring$that$words$in$each$"
DATA "column$are$separated$by$at$least$one$space."
DATA "Further,$allow$for$each$word$in$a$column$to$be$either$left$"
DATA "justified,$right$justified,$or$center$justified$within$its$column."
REM First find the maximum length of a 'word':
max% = 0
READ nlines%
FOR Line% = 1 TO nlines%
READ text$
REPEAT
word$ = FNword(text$, "$")
IF LEN(word$) > max% THEN max% = LEN(word$)
UNTIL word$ = ""
NEXT Line%
@% = max% : REM set column width
REM Now display the aligned text:
RESTORE
READ nlines%
FOR Line% = 1 TO nlines%
READ text$
REPEAT
word$ = FNword(text$, "$")
PRINT FNjustify(word$, max%, "left"),;
UNTIL word$ = ""
PRINT
NEXT Line%
END
DEF FNword(text$, delim$)
PRIVATE delim%
LOCAL previous%
IF delim% = 0 THEN
previous% = 1
ELSE
previous% = delim% + LEN(delim$)
ENDIF
delim% = INSTR(text$+delim$, delim$, previous%)
IF delim% = 0 THEN
= ""
ELSE
= MID$(text$, previous%, delim%-previous%) + " "
ENDIF
DEF FNjustify(word$, field%, mode$)
IF word$ = "" THEN = ""
CASE mode$ OF
WHEN "center": = STRING$((field%-LEN(word$)) DIV 2, " ") + word$
WHEN "right": = STRING$(field%-LEN(word$), " ") + word$
ENDCASE
= word$

View file

@ -0,0 +1,66 @@
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"