updated listing/saving algos
This commit is contained in:
+12
-5
@@ -226,6 +226,16 @@ Run the program currently loaded into the working memory.
|
|||||||
|
|
||||||
Output program listing.
|
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`.
|
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.
|
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.
|
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`.
|
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.
|
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`.
|
3. Open a file handle `FH` for writing into the file under the path `FNAME`.
|
||||||
4. Set `I = 1`.
|
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. 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`.
|
5. Close the handle `FH` and notify the user about successful program saving.
|
||||||
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.
|
|
||||||
|
|
||||||
## Closing notes
|
## Closing notes
|
||||||
|
|
||||||
|
|||||||
@@ -245,8 +245,8 @@ proc lttb_EN {stmt} {
|
|||||||
|
|
||||||
proc int_LIST {} {
|
proc int_LIST {} {
|
||||||
global progmem
|
global progmem
|
||||||
loop i 1 32768 {
|
foreach i [lsort -integer [dict keys $progmem]] {
|
||||||
if {[dict exists $progmem $i] && [string length $progmem($i)]} {
|
if {$progmem($i) ne {}} {
|
||||||
puts [format "%d\t%s" $i $progmem($i)]
|
puts [format "%d\t%s" $i $progmem($i)]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -292,8 +292,8 @@ proc int_SAVE {} {
|
|||||||
stdout flush
|
stdout flush
|
||||||
stdin gets fname
|
stdin gets fname
|
||||||
set fh [open $fname w]
|
set fh [open $fname w]
|
||||||
loop i 1 32768 {
|
foreach i [lsort -integer [dict keys $progmem]] {
|
||||||
if {[dict exists $progmem $i]} {
|
if {$progmem($i) ne {}} {
|
||||||
$fh puts [format {%d %s} $i $progmem($i)]
|
$fh puts [format {%d %s} $i $progmem($i)]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user