/* Listbox Server - DMS - Aug. '98 - by Marc BARILLEY */ /* Rev. June '01 - by Julien ZORKO */ defcom cAdd = add S;; defcom cDel = del S;; defcom cReset = reset;; defcom cSort = sort;; defcom cStartup = startup I S;; /* [errorcode item] gives the list of the startup items */ /* errorcode == 0 starts the sequence */ /* errorcode == 1 gives an item */ /* errorcode == 2 ends the sequence */ typeof startupItems = [S r1];; typeof items = [S r1];; typeof clients = [CLIENT r1];; var SendItems = 1;; var same = 0;; fun sstrcmp (a, b)=strcmp struppercase b struppercase a;; fun _strcmp (a, b)= !strcmp a b;; fun broad (cl, comm)= _DMSsend this cl comm;; fun broadnew (item, l)= apply_on_list l @broad cAdd [item];; fun broadstartup (item, cli)= _DMSsend this cli cStartup [1 item];; fun loadItems (l)= if l==nil then nil else let hd l -> [keyword [p _]] in if !strcmp keyword "item" then p::loadItems tl l else loadItems tl l;; fun activate (from, cli, action, param, rep)= if !strcmp action "start" then if _DMScreateClientDMI this cli (itoa SendItems) then { set clients = cli::clients; _DMSsend this cli cStartup [0 nil]; apply_on_list startupItems @broadstartup cli; _DMSsend this cli cStartup [2 nil]; if same then apply_on_list items @broadnew cli::nil else apply_on_list startupItems @broadnew cli::nil; _DMSevent this cli "started" nil nil; } else nil else if !strcmp action "kill" then if _DMSdelClientDMI this cli then _DMSevent this cli "killed" nil nil else nil else if !strcmp action "add" then if same then { set items = param::items; apply_on_list clients @broad cAdd [param] } else _DMSsend this cli cAdd [param] else if !strcmp action "del" then if same then let search_in_list items @_strcmp param -> p in if p==nil then nil else { set items = removef_from_list items @_strcmp param; apply_on_list clients @broad cDel [param] } else _DMSsend this cli cDel [param] else if !strcmp action "reset" then if same then { set items = nil; apply_on_list clients @broad cReset [] } else _DMSsend this cli cReset [] else if !strcmp action "sort" then if same then { apply_on_list clients @broad cReset []; set items = rquicksort @sstrcmp items; apply_on_list items @broadnew clients; } else _DMSsend this cli cSort [] else nil;; fun del (cli)= set clients = remove_from_list clients cli; _DMSevent this cli "killed" nil nil;; fun IniDMI (file)= _DMSregisterDMI this @activate nil @del nil; let strextr _getpack _checkpack file -> l in let atoi getInfo l "sendItems" -> sendItems in { set SendItems = if sendItems == nil then 1 else sendItems; set startupItems = mirror loadItems l; set items = listcat startupItems nil; set same = atoi getInfo l "same" };;