If the programmer wants to store a collection of data for later use, or use in another program, he packes the data in a single string (called a "package"), gives it a short key, and store the package with its key on the clipboard.
When needed, he can retrieve the package using the key, leaving it on the clipboard, or delete it there, and use the SPLIT command to unpack the package into the original data.
In the first version hereafter, there are 3 commands :
clip_board$ ("+",key$,package$) -> store the package on the clipboard
package$ = clip_board$ ("=",key$,"") -> retrieve a package and leave it
package$ = clip_board$ ("-",key$,"") -> retrieve a package and delete it
Initialization of the clipboard is automatic, as is the storage capacity.
Maybe there are suggestions for additional clipboard functions?
Code: Select all
' test program for clipboard function
'
option base 1
clip_board$("+","single_var","12345") ' single value to clipboard
print clip_board$("=","single_var","") ' print it
a$="monday" ! b$="tuesday" ' package with 2 strings to clipboard
pack$ = a$ & "," & b$
clip_board$("+","2str",pack$)
ret$ = clip_board$("=","2str","") ' retrieve and print it
if ret$ ="not found" then ! print ret$ ! stop ! end if
split ret$ to m$,n with ","
print m$(1),m$(2)
end
' versatile clipboard, version may 17, 2019
' using the "dictionary" file type
' self initializing, dynamic sizing
' package$ = collection of data, packed into a string
' by the application programmer
' key$ = key under which the packaged can be retrieved
' opcode$ = action to be performed:
' "+" = store the package on the clipboard
' "=" = retrieve the package and leave it
' "-" = retrieve the package and delete it
'
def clip_board$(opcode$,key$,package$)
changed=0 ! a$=""
if init=0 then
init=1 ! table$("init","","clipboard.data")
end if
if opcode$="+" then
table$("add",key$,package$) ! changed=1
end if
if opcode$="=" then return table$("get",key$,"")
if opcode$="-" then
a$=table$("get",key$,"") ! table$("del",key$,"") ! changed=1
end if
if changed then table$("save","","")
if a$<>"" then return a$
end def
{dictionary}