From: Svjatoslav Agejenko Date: Fri, 25 Oct 2024 22:24:22 +0000 (+0300) Subject: Improve utils readability. X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=51a1beb4491a1a42573ce62429614baa4c2b2988;p=fifth.git Improve utils readability. Add IntelliJ launcher. --- diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..85e7c1d --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1 @@ +/.idea/ diff --git a/tools/5th2src.bas b/tools/5th2src.bas index 2943f06..7293f46 100755 --- a/tools/5th2src.bas +++ b/tools/5th2src.bas @@ -1,18 +1,23 @@ -DECLARE SUB getline (a$) -DECLARE SUB start () +' Utility to convert given file from special FSCII encoding to ASCII encoding. + +DECLARE SUB getline (line$) +DECLARE SUB initializeProgram () DIM SHARED byte AS STRING * 1 -DIM SHARED endf +DIM SHARED endOfFile -start +initializeProgram OPEN COMMAND$ + ".5th" FOR BINARY AS #1 OPEN COMMAND$ + ".src" FOR OUTPUT AS #2 +' Start reading lines from the file 1 -getline a$ -IF endf = 1 THEN GOTO 2 -PRINT #2, a$ +getline line$ +IF endOfFile = 1 THEN GOTO 2 +PRINT #2, line$ GOTO 1 + +' End of file reached 2 CLOSE #2 @@ -20,12 +25,16 @@ CLOSE #1 SYSTEM -SUB getline (a$) +SUB getline (line$) + +line$ = "" -a$ = "" +' Start reading bytes from the file 3 -IF EOF(1) <> 0 THEN endf = 1: GOTO 4 +IF EOF(1) <> 0 THEN endOfFile = 1: GOTO 4 GET #1, , byte + +' Convert non-printable characters to printable ones IF ASC(byte) <= 9 THEN byte = CHR$(48 + ASC(byte)) END IF @@ -39,15 +48,21 @@ IF ASC(byte) = 253 THEN byte = CHR$(9) END IF +' Check for end of line character IF byte = CHR$(254) THEN GOTO 4 -a$ = a$ + byte + +line$ = line$ + byte GOTO 3 + +' End of line reached 4 END SUB -SUB start -endf = 0 +SUB initializeProgram +endOfFile = 0 + +' Check if the command-line argument is empty IF COMMAND$ = "" THEN END -END SUB +END SUB diff --git a/tools/insert.bas b/tools/insert.bas deleted file mode 100755 index b167c16..0000000 --- a/tools/insert.bas +++ /dev/null @@ -1,50 +0,0 @@ -DECLARE SUB getson (a$) -DECLARE SUB start () -DIM SHARED mitus, sona$(1 TO 50) -DIM SHARED byte AS STRING * 1 - -start - -OPEN sona$(1) FOR BINARY AS #1 -PRINT "Seeking to:" + sona$(3) -SEEK #1, VAL(sona$(3)) + 1 -OPEN sona$(2) FOR BINARY AS #2 -2 -IF EOF(2) <> 0 THEN GOTO 1 -GET #2, , byte -PUT #1, , byte -GOTO 2 -1 -CLOSE #2 -CLOSE #1 - -SYSTEM - -SUB getson (a$) -mitus = 0 - -d = 1 -FOR b = 1 TO LEN(a$) -c$ = RIGHT$(LEFT$(a$, b), 1) -IF c$ = " " THEN -d = 1 -ELSE -IF d = 1 THEN -mitus = mitus + 1 -sona$(mitus) = "" -d = 0 -END IF -sona$(mitus) = sona$(mitus) + c$ -END IF -NEXT b -END SUB - -SUB start - -IF COMMAND$ = "" THEN END - -getson COMMAND$ - - -END SUB - diff --git a/tools/open with IntelliJ IDEA b/tools/open with IntelliJ IDEA new file mode 100755 index 0000000..304bf94 --- /dev/null +++ b/tools/open with IntelliJ IDEA @@ -0,0 +1,54 @@ +#!/bin/bash + +# This script launches IntelliJ IDEA with the current project +# directory. The script is designed to be run by double-clicking it in +# the GNOME Nautilus file manager. + +# First, we change the current working directory to the directory of +# the script. + +# "${0%/*}" gives us the path of the script itself, without the +# script's filename. + +# This command basically tells the system "change the current +# directory to the directory containing this script". + +cd "${0%/*}" + +# Then, we move up one directory level. +# The ".." tells the system to go to the parent directory of the current directory. +# This is done because we assume that the project directory is one level up from the script. +cd .. + +# Now, we use the 'setsid' command to start a new session and run +# IntelliJ IDEA in the background. 'setsid' is a UNIX command that +# runs a program in a new session. + +# The command 'idea .' opens IntelliJ IDEA with the current directory +# as the project directory. The '&' at the end is a UNIX command that +# runs the process in the background. The '> /dev/null' part tells +# the system to redirect all output (both stdout and stderr, denoted +# by '&') that would normally go to the terminal to go to /dev/null +# instead, which is a special file that discards all data written to +# it. + +setsid idea . &>/dev/null & + +# The 'disown' command is a shell built-in that removes a shell job +# from the shell's active list. Therefore, the shell will not send a +# SIGHUP to this particular job when the shell session is terminated. + +# '-h' option specifies that if the shell receives a SIGHUP, it also +# doesn't send a SIGHUP to the job. + +# '$!' is a shell special parameter that expands to the process ID of +# the most recent background job. +disown -h $! + + +sleep 2 + +# Finally, we use the 'exit' command to terminate the shell script. +# This command tells the system to close the terminal window after +# IntelliJ IDEA has been opened. +exit diff --git a/tools/src25th.bas b/tools/src25th.bas index 8d79e0c..afab7df 100755 --- a/tools/src25th.bas +++ b/tools/src25th.bas @@ -1,65 +1,66 @@ -DECLARE SUB chl (a$, b$) -DECLARE SUB getline (a$) -DECLARE SUB start () -DIM SHARED byte AS STRING * 1 -DIM SHARED er +DECLARE SUB processLine (lineContent$, encodedString$) +DECLARE SUB readLine (fileLine$) +DECLARE SUB initializeProgram () +DIM SHARED byte AS STRING * 1 +DIM SHARED errorFlag -start +initializeProgram OPEN COMMAND$ + ".src" FOR INPUT AS #1 -IF er = 0 THEN KILL COMMAND$ + ".5th" +IF errorFlag = 0 THEN KILL COMMAND$ + ".5th" OPEN COMMAND$ + ".5th" FOR BINARY AS #2 -1 -IF EOF(1) <> 0 THEN GOTO 2 -LINE INPUT #1, a$ +ReadLoop: +IF EOF(1) <> 0 THEN GOTO EndOfFile +LINE INPUT #1, fileLine$ + +encodedString$ = "" +tempString$ = "" +FOR charIndex = 1 TO LEN(fileLine$) + currentChar$ = RIGHT$(LEFT$(fileLine$, charIndex), 1) + IF currentChar$ = " " THEN processLine tempString$, encodedString$: encodedString$ = encodedString$ + CHR$(255): GOTO NextChar + IF currentChar$ = CHR$(9) THEN processLine tempString$, encodedString$: encodedString$ = encodedString$ + CHR$(253): GOTO NextChar + tempString$ = tempString$ + currentChar$ + NextChar: +NEXT charIndex -c$ = "" -e$ = "" -FOR b = 1 TO LEN(a$) -d$ = RIGHT$(LEFT$(a$, b), 1) -IF d$ = " " THEN chl e$, c$: c$ = c$ + CHR$(255): GOTO 3 -IF d$ = CHR$(9) THEN chl e$, c$: c$ = c$ + CHR$(253): GOTO 3 -e$ = e$ + d$ -3 -NEXT b -chl e$, c$ -c$ = c$ + CHR$(254) -FOR b = 1 TO LEN(c$) - byte = RIGHT$(LEFT$(c$, b), 1) +processLine tempString$, encodedString$ +encodedString$ = encodedString$ + CHR$(254) + +FOR charIndex = 1 TO LEN(encodedString$) + byte = RIGHT$(LEFT$(encodedString$, charIndex), 1) PUT #2, , byte -NEXT b -GOTO 1 -2 +NEXT charIndex +GOTO ReadLoop +EndOfFile: CLOSE #2 CLOSE #1 SYSTEM +SUB processLine (lineContent$, encodedString$) -SUB chl (a$, b$) +tempEncoded$ = "" +FOR charPosition = 1 TO LEN(lineContent$) + asciiValue = ASC(RIGHT$(LEFT$(lineContent$, charPosition), 1)) + IF (asciiValue >= 48) AND (asciiValue <= 57) THEN asciiValue = asciiValue - 48: GOTO ValidChar + IF (asciiValue >= 65) AND (asciiValue <= 70) THEN asciiValue = asciiValue - 55: GOTO ValidChar + IF (asciiValue = 45) AND (charPosition = 1) THEN GOTO ValidChar + GOTO InvalidChar + ValidChar: + tempEncoded$ = tempEncoded$ + CHR$(asciiValue) +NEXT charPosition -e$ = "" -FOR c = 1 TO LEN(a$) -d = ASC(RIGHT$(LEFT$(a$, c), 1)) -IF (d >= 48) AND (d <= 57) THEN d = d - 48: GOTO 4 -IF (d >= 65) AND (d <= 70) THEN d = d - 55: GOTO 4 -IF (d = 45) AND (c = 1) THEN GOTO 4 -GOTO 5 -4 -e$ = e$ + CHR$(d) -NEXT c -a$ = e$ -5 +lineContent$ = tempEncoded$ +InvalidChar: -b$ = b$ + a$ -a$ = "" +encodedString$ = encodedString$ + lineContent$ +lineContent$ = "" END SUB -SUB start +SUB initializeProgram IF COMMAND$ = "" THEN END -er = 0 +errorFlag = 0 END SUB -