From: Svjatoslav Agejenko Date: Sun, 29 Jun 2025 16:07:31 +0000 (+0300) Subject: file name that is easier to parse in DOS X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=e1908e94698337f2278c6a3822197678275ef3bc;p=qbasicapps.git file name that is easier to parse in DOS --- diff --git a/Miscellaneous/Windowing system.bas b/Miscellaneous/Windowing system.bas deleted file mode 100755 index c5c9332..0000000 --- a/Miscellaneous/Windowing system.bas +++ /dev/null @@ -1,252 +0,0 @@ -' Text mode windowing system. Each window can display text file. -' Window content can be scrolled horizontally and vertically. -' Window can have arbitrary size and location on the screen. -' -' By Svjatoslav Agejenko. -' Email: svjatoslav@svjatoslav.eu -' Homepage: http://www.svjatoslav.eu - -' Changelog: -' 2003, Initial version -' 2024, Improved program readability using AI - -DECLARE SUB demo () -DECLARE FUNCTION getline$ (w%, l%) -DECLARE SUB loadfile (file$, d%) -DECLARE SUB sendline (w%, l%, newstring$) -DECLARE FUNCTION getflin% () -DECLARE SUB refresh () -DECLARE FUNCTION addpage% (x%, y%, xs%, ys%, title$) -DECLARE SUB box (x%, y%, xl%, yl%, e$) -DEFINT A-Z -DECLARE SUB shpage (a) -DECLARE SUB start () - -DIM SHARED stamo -stamo = 5000 -DIM SHARED st$(1 TO stamo) -DIM SHARED stpn - -DIM SHARED pag(1 TO 10, 1 TO 1000) -DIM SHARED pagx(1 TO 10), pagy(1 TO 10), pagxs(1 TO 10), pagys(1 TO 10) -DIM SHARED pagon(1 TO 10) -DIM SHARED pagtitle$(1 TO 10) - -DIM SHARED pagshx(1 TO 10) ' x & y shift -DIM SHARED pagshy(1 TO 10) - -DIM SHARED pageactive ' active page - -start - -demo - -FUNCTION addpage% (x, y, xs, ys, title$) - FOR a = 1 TO 10 - IF pagon(a) = 0 THEN - b = a - GOTO 1 - END IF - NEXT a -1 - - pagon(b) = 1 - pagx(b) = x - pagy(b) = y - pagxs(b) = xs - pagys(b) = ys - pagtitle$(b) = title$ - - addpage% = b -END FUNCTION - -SUB clrwnd (w) - FOR a = 1 TO 1000 - IF pag(w, a) > 0 THEN - st$(pag(w, a)) = "" - pag(w, a) = 0 - END IF - NEXT a -END SUB - -SUB demo - ' Create three windows with different sizes and titles - w1 = addpage%(1, 1, 30, 10, "window 1.") - w2 = addpage%(1, 12, 80, 30, "second window") - w3 = addpage%(31, 2, 30, 10, "last window") - - ' Load the same file into all windows - loadfile "wsystem.bas", w2 - loadfile "wsystem.bas", w1 - loadfile "wsystem.bas", w3 - -4 - pageactive = INT(RND * 3) + 1 - refresh - - ' Animate the windows by shifting their content - FOR a = 1 TO 100 - pagshx(pageactive) = SIN(a / 10) * 10 + 10 - pagshy(pageactive) = a - shpage (pageactive) - SOUND 0, 1 - IF INKEY$ <> "" THEN SYSTEM - NEXT a - - GOTO 4 -END SUB - -FUNCTION getflin% ' Get free line -2 - IF stpn > 1000 THEN - stpn = 1 - END IF - IF st$(stpn) = "" THEN - getflin% = stpn - stpn = stpn + 1 - ELSE - stpn = stpn + 1 - GOTO 2 - END IF -END FUNCTION - -FUNCTION getline$ (w, l) - ' Retrieve the line from the window memory - IF pag(w, l) = 0 THEN - getline$ = "" - ELSE - getline$ = st$(pag(w, l)) - END IF -END FUNCTION - -SUB loadfile (file$, d) - ' Load a file into the window memory - - OPEN file$ FOR INPUT AS #1 - FOR a = 1 TO 1000 - IF EOF(1) <> 0 THEN - GOTO 3 - END IF - LINE INPUT #1, a$ - sendline d, a, a$ - NEXT a -3 - - CLOSE #1 - - ' Fill the remaining lines with empty strings - FOR b = a TO 1000 - sendline d, b, "" - NEXT b -END SUB - -SUB refresh - ' Redraw all active windows - CLS - FOR a = 1 TO 10 - IF pagon(a) > 0 THEN - shpage (a) - END IF - NEXT a -END SUB - -SUB sendline (w, l, newstring$) ' window, lineNum, lineItself - ' send string into window memory - a$ = newstring$ - - ' Remove trailing spaces from the string - IF a$ = SPACE$(LEN(a$)) THEN - a$ = "" - END IF - - IF LEN(a$) > 0 THEN -5 - IF RIGHT$(a$, 1) = " " THEN - a$ = LEFT$(a$, LEN(a$) - 1) - GOTO 5 - END IF - END IF - - ' Update the window memory with the new string - IF a$ = "" THEN - IF pag(w, l) > 0 THEN - st$(pag(w, l)) = "": pag(w, l) = 0 - END IF - ELSE - IF pag(w, l) = 0 THEN - pag(w, l) = getflin% - END IF - st$(pag(w, l)) = a$ - END IF -END SUB - -SUB shpage (page) - ' Draw the specified window on the screen - - ' Determine background color based on active page - IF page = pageactive THEN - bg = 1 - ELSE - bg = 0 - END IF - - x = pagx(page) - y = pagy(page) - xl = pagxs(page) - yl = pagys(page) - e$ = pagtitle$(page) - - COLOR 11, bg - - ' Draw the window border - a$ = "" - d$ = "" - FOR a = 1 TO xl - 2 - a$ = a$ + CHR$(205) - NEXT a - b$ = CHR$(201) + a$ + CHR$(187) - c$ = CHR$(200) + a$ + CHR$(188) - - LOCATE y, x - PRINT b$ - LOCATE y + yl - 1, x - PRINT c$ - - ' Draw the window content - FOR a = 1 TO yl - 2 - LOCATE y + a, x - d$ = getline$(page, a + pagshy(page)) - d$ = d$ + SPACE$(300) - d$ = RIGHT$(d$, LEN(d$) - pagshx(page)) - d$ = LEFT$(d$, xl - 2) - PRINT CHR$(186) + d$ + CHR$(186) - NEXT a - - ' Draw the window title - xt = INT(x + (xl / 2) - (LEN(e$) / 2) - 2) - LOCATE y, xt - PRINT "[ " - xt = xt + 2 - - COLOR 10 - LOCATE y, xt - PRINT e$ - - xt = xt + LEN(e$) - COLOR 11 - LOCATE y, xt - PRINT " ]" - COLOR 7, 0 -END SUB - -SUB start - ' Initialize the screen and shared memory - WIDTH 80, 50 - VIEW PRINT 1 TO 50 - - FOR a = 1 TO stamo - st$(a) = "" - NEXT a - - stpn = 1 -END SUB \ No newline at end of file diff --git a/Miscellaneous/wsystem.bas b/Miscellaneous/wsystem.bas new file mode 100755 index 0000000..c5c9332 --- /dev/null +++ b/Miscellaneous/wsystem.bas @@ -0,0 +1,252 @@ +' Text mode windowing system. Each window can display text file. +' Window content can be scrolled horizontally and vertically. +' Window can have arbitrary size and location on the screen. +' +' By Svjatoslav Agejenko. +' Email: svjatoslav@svjatoslav.eu +' Homepage: http://www.svjatoslav.eu + +' Changelog: +' 2003, Initial version +' 2024, Improved program readability using AI + +DECLARE SUB demo () +DECLARE FUNCTION getline$ (w%, l%) +DECLARE SUB loadfile (file$, d%) +DECLARE SUB sendline (w%, l%, newstring$) +DECLARE FUNCTION getflin% () +DECLARE SUB refresh () +DECLARE FUNCTION addpage% (x%, y%, xs%, ys%, title$) +DECLARE SUB box (x%, y%, xl%, yl%, e$) +DEFINT A-Z +DECLARE SUB shpage (a) +DECLARE SUB start () + +DIM SHARED stamo +stamo = 5000 +DIM SHARED st$(1 TO stamo) +DIM SHARED stpn + +DIM SHARED pag(1 TO 10, 1 TO 1000) +DIM SHARED pagx(1 TO 10), pagy(1 TO 10), pagxs(1 TO 10), pagys(1 TO 10) +DIM SHARED pagon(1 TO 10) +DIM SHARED pagtitle$(1 TO 10) + +DIM SHARED pagshx(1 TO 10) ' x & y shift +DIM SHARED pagshy(1 TO 10) + +DIM SHARED pageactive ' active page + +start + +demo + +FUNCTION addpage% (x, y, xs, ys, title$) + FOR a = 1 TO 10 + IF pagon(a) = 0 THEN + b = a + GOTO 1 + END IF + NEXT a +1 + + pagon(b) = 1 + pagx(b) = x + pagy(b) = y + pagxs(b) = xs + pagys(b) = ys + pagtitle$(b) = title$ + + addpage% = b +END FUNCTION + +SUB clrwnd (w) + FOR a = 1 TO 1000 + IF pag(w, a) > 0 THEN + st$(pag(w, a)) = "" + pag(w, a) = 0 + END IF + NEXT a +END SUB + +SUB demo + ' Create three windows with different sizes and titles + w1 = addpage%(1, 1, 30, 10, "window 1.") + w2 = addpage%(1, 12, 80, 30, "second window") + w3 = addpage%(31, 2, 30, 10, "last window") + + ' Load the same file into all windows + loadfile "wsystem.bas", w2 + loadfile "wsystem.bas", w1 + loadfile "wsystem.bas", w3 + +4 + pageactive = INT(RND * 3) + 1 + refresh + + ' Animate the windows by shifting their content + FOR a = 1 TO 100 + pagshx(pageactive) = SIN(a / 10) * 10 + 10 + pagshy(pageactive) = a + shpage (pageactive) + SOUND 0, 1 + IF INKEY$ <> "" THEN SYSTEM + NEXT a + + GOTO 4 +END SUB + +FUNCTION getflin% ' Get free line +2 + IF stpn > 1000 THEN + stpn = 1 + END IF + IF st$(stpn) = "" THEN + getflin% = stpn + stpn = stpn + 1 + ELSE + stpn = stpn + 1 + GOTO 2 + END IF +END FUNCTION + +FUNCTION getline$ (w, l) + ' Retrieve the line from the window memory + IF pag(w, l) = 0 THEN + getline$ = "" + ELSE + getline$ = st$(pag(w, l)) + END IF +END FUNCTION + +SUB loadfile (file$, d) + ' Load a file into the window memory + + OPEN file$ FOR INPUT AS #1 + FOR a = 1 TO 1000 + IF EOF(1) <> 0 THEN + GOTO 3 + END IF + LINE INPUT #1, a$ + sendline d, a, a$ + NEXT a +3 + + CLOSE #1 + + ' Fill the remaining lines with empty strings + FOR b = a TO 1000 + sendline d, b, "" + NEXT b +END SUB + +SUB refresh + ' Redraw all active windows + CLS + FOR a = 1 TO 10 + IF pagon(a) > 0 THEN + shpage (a) + END IF + NEXT a +END SUB + +SUB sendline (w, l, newstring$) ' window, lineNum, lineItself + ' send string into window memory + a$ = newstring$ + + ' Remove trailing spaces from the string + IF a$ = SPACE$(LEN(a$)) THEN + a$ = "" + END IF + + IF LEN(a$) > 0 THEN +5 + IF RIGHT$(a$, 1) = " " THEN + a$ = LEFT$(a$, LEN(a$) - 1) + GOTO 5 + END IF + END IF + + ' Update the window memory with the new string + IF a$ = "" THEN + IF pag(w, l) > 0 THEN + st$(pag(w, l)) = "": pag(w, l) = 0 + END IF + ELSE + IF pag(w, l) = 0 THEN + pag(w, l) = getflin% + END IF + st$(pag(w, l)) = a$ + END IF +END SUB + +SUB shpage (page) + ' Draw the specified window on the screen + + ' Determine background color based on active page + IF page = pageactive THEN + bg = 1 + ELSE + bg = 0 + END IF + + x = pagx(page) + y = pagy(page) + xl = pagxs(page) + yl = pagys(page) + e$ = pagtitle$(page) + + COLOR 11, bg + + ' Draw the window border + a$ = "" + d$ = "" + FOR a = 1 TO xl - 2 + a$ = a$ + CHR$(205) + NEXT a + b$ = CHR$(201) + a$ + CHR$(187) + c$ = CHR$(200) + a$ + CHR$(188) + + LOCATE y, x + PRINT b$ + LOCATE y + yl - 1, x + PRINT c$ + + ' Draw the window content + FOR a = 1 TO yl - 2 + LOCATE y + a, x + d$ = getline$(page, a + pagshy(page)) + d$ = d$ + SPACE$(300) + d$ = RIGHT$(d$, LEN(d$) - pagshx(page)) + d$ = LEFT$(d$, xl - 2) + PRINT CHR$(186) + d$ + CHR$(186) + NEXT a + + ' Draw the window title + xt = INT(x + (xl / 2) - (LEN(e$) / 2) - 2) + LOCATE y, xt + PRINT "[ " + xt = xt + 2 + + COLOR 10 + LOCATE y, xt + PRINT e$ + + xt = xt + LEN(e$) + COLOR 11 + LOCATE y, xt + PRINT " ]" + COLOR 7, 0 +END SUB + +SUB start + ' Initialize the screen and shared memory + WIDTH 80, 50 + VIEW PRINT 1 TO 50 + + FOR a = 1 TO stamo + st$(a) = "" + NEXT a + + stpn = 1 +END SUB \ No newline at end of file