BCX Console Demonstration Program s153.bas |
TYPE LIST Cnt AS INTEGER b[32] AS CHAR nxt AS LIST PTR prv AS LIST PTR END TYPE MACRO sp = 0 DIM Head AS LIST PTR DIM a$, buffer$[40], i, j a$ = "this is a test" i = SPLIT(buffer$, a$, " ", sp) FOR j = 0 TO i - 1 CALL AddString(buffer$[j]) NEXT a$ = "the quick brown fox jumped over the lazy dog" i = SPLIT(buffer$, a$, " ", sp) FOR j = 0 TO i - 1 CALL AddString(buffer$[j]) NEXT a$ = "to error is human to really screw up requires a computer" i = SPLIT(buffer$, a$, " ", sp) FOR j = 0 TO i - 1 CALL AddString(buffer$[j]) NEXT a$ = "if a function takes up more space than can fit on a screen it has an error in it" i = SPLIT(buffer$, a$, " ", sp) FOR j = 0 TO i - 1 CALL AddString(buffer$[j]) NEXT CALL OutPutData() !fflush(stdout); getchar(); SUB OutPutData IF Head THEN WHILE Head->prv Head = Head->prv WEND WHILE Head PRINT Head->b$; Head->Cnt Head = Head->nxt WEND END IF END SUB SUB AddString(bufstr$) DIM RAW PHead AS LIST PTR DIM RAW CHead AS LIST PTR DIM RAW NHead AS LIST PTR IF !(Head) THEN Head = MakeRecord() Head->b$ = bufstr$ Head->Cnt = 1 EXIT SUB END IF CHead = Head WHILE CHead->b$ < bufstr$ IF CHead->nxt THEN CHead = CHead->nxt ELSE PHead = CHead CHead->nxt = MakeRecord() CHead = CHead->nxt CHead->b$ = bufstr$ CHead->Cnt = 1 CHead->prv = PHead EXIT SUB END IF WEND IF CHead->b$ = bufstr$ THEN CHead->Cnt++ EXIT SUB END IF WHILE CHead->b$ > bufstr$ IF CHead->prv THEN CHead = CHead->prv ELSE PHead = CHead CHead->prv = MakeRecord() CHead = CHead->prv CHead->b$ = bufstr$ CHead->Cnt = 1 CHead->nxt = PHead EXIT SUB END IF WEND IF CHead->b$ = bufstr$ THEN CHead->Cnt++ EXIT SUB END IF NHead = MakeRecord() NHead->b$ = bufstr$ NHead->Cnt = 1 PHead = CHead->nxt CHead->nxt = NHead NHead->nxt = PHead NHead->prv = CHead PHead->prv = NHead END SUB FUNCTION MakeRecord() AS LIST PTR ! return (LIST*)(calloc(1, sizeof(LIST))); END FUNCTION
Result:
a 4 an 1 brown 1 can 1 computer 1 dog 1 error 2 fit 1 fox 1 function 1 has 1 human 1 if 1 in 1 is 2 it 2 jumped 1 lazy 1 more 1 on 1 over 1 quick 1 really 1 requires 1 screen 1 screw 1 space 1 takes 1 test 1 than 1 the 2 this 1 to 2 up 2