%% /llsrv public
// Create linked list just once for the life of the process
do-once
new-list t process-scope
end-do-once
// Get input parameters
get-param op
get-param key
get-param data
if-true op equal "add" // Add data to list
// Make a copy of key,data so they are Golf-allocated
write-list t key (key) value data append
@Added [<<print-out key>>] value [<<print-out data>>]
else-if op equal "delete" // Delete first data and obtain the value deleted
position-list t first
read-list t key (key) value val status st
if-true st equal GG_ERR_EXIST
@Not found
else-if
// If found, then delete key and value
@Deleted key [<<print-out key>>], [<<print-out val>>]
delete-list t
end-if
else-if op equal "next" // Position to next element
position-list t next status st
if-true st equal GG_OKAY
@Okay
else-if
@Not found
end-if
else-if op equal "last" // Position to last element
position-list t last status st
if-true st equal GG_OKAY
@Okay
else-if
@Not found
end-if
else-if op equal "previous" // Position to element
position-list t previous status st
if-true st equal GG_OKAY
@Okay
else-if
@Not found
end-if
else-if op equal "first" // Get first element
position-list t first status st
if-true st equal GG_OKAY
@Okay
else-if
@Not found
end-if
else-if op equal "query" // Get current element
read-list t key (key) value val status st
if-true st equal GG_ERR_EXIST
@Not found
else-if
@Key [<<print-out key>>], value [<<print-out val>>]
end-if
else-if op equal "purge" // remove all, keep the list
purge-list t
end-if
%%
Copied!