updated listing/saving algos

This commit is contained in:
Luxferre
2026-06-14 09:28:29 +03:00
parent 48c63cac8f
commit 910159f7ab
2 changed files with 16 additions and 9 deletions
+12 -5
View File
@@ -226,6 +226,16 @@ Run the program currently loaded into the working memory.
Output program listing.
Two algorithms are provided: for the platforms that can extract associative array keys and for those that cannot.
Algorithm 1:
1. Extract key list `LNOS` from `PROGMEM` associative array. Sort the list in the integer numeric order.
2. Fetch the next key `LNO` from `LNOS`. Upon exhaustion, return from the routine.
3. If `PROGMEM[LNO]` is not empty, output the value of `LNO`, TAB character (ASCII 9) and `PROGMEM[LNO]` with a newline at the end. Go to step 2.
Algorithm 2:
1. Set `I = 1`.
2. If `PROGMEM[I]` exists and is not empty, output the value of `I`, TAB character (ASCII 9) and `PROGMEM[I]` with a newline at the end.
3. Increment `I` by 1.
@@ -263,11 +273,8 @@ Program saving routine into external storage media. The provided algorithm works
1. Prompt the user for a file name/path `FNAME`.
2. If the file name/path isn't writable, notify the user about this error and return.
3. Open a file handle `FH` for writing into the file under the path `FNAME`.
4. Set `I = 1`.
5. If `PROGMEM[I]` exists and is not empty, write the value of `I`, space character (ASCII 32) and `PROGMEM[I]` with a newline at the end to the file handle `FH`.
6. Increment `I` by 1.
7. If `I > 0` and `I < 32768`, go to step 5.
8. Close the handle `FH` and notify the user about successful program saving.
4. Perform the algorithm described for the `LIST` routine, but using the specified file handle instead of standard output and space character (ASCII 32) instead of TAB character (ASCII 9).
5. Close the handle `FH` and notify the user about successful program saving.
## Closing notes
+4 -4
View File
@@ -245,8 +245,8 @@ proc lttb_EN {stmt} {
proc int_LIST {} {
global progmem
loop i 1 32768 {
if {[dict exists $progmem $i] && [string length $progmem($i)]} {
foreach i [lsort -integer [dict keys $progmem]] {
if {$progmem($i) ne {}} {
puts [format "%d\t%s" $i $progmem($i)]
}
}
@@ -292,8 +292,8 @@ proc int_SAVE {} {
stdout flush
stdin gets fname
set fh [open $fname w]
loop i 1 32768 {
if {[dict exists $progmem $i]} {
foreach i [lsort -integer [dict keys $progmem]] {
if {$progmem($i) ne {}} {
$fh puts [format {%d %s} $i $progmem($i)]
}
}