/* */ /* Copyright (c) 2003, organization : Scol Technologies Association, owner : Sylvain Huet */ /* For conditions of distribution and use, see copyright notice in dms/l/license.txt */ /* or on 'www.scol-technologies.org' */ /* KitLocalisation Client - Aug 99 - by Sebastien DENEUX */ /* last update : 12/07/00 */ /*--------------*/ /*div functions*/ /*--------------*/ fun listcat (p, q)= if p==nil then q else let p -> [h nxt] in h::listcat nxt q;; fun reverse_aux(list,res)= if list == nil then res else reverse_aux (tl list) ((hd list)::res);; fun mirror (list)= reverse_aux list nil;; /*-----------------*/ /*end div functions*/ /*-----------------*/ /*------------*/ /*fonction de hachage*/ fun hachage(ref)= let ((nth_char ref 0)+(nth_char ref 1))&255 -> x in if x==nil then 0 else x;; /*------------*/ fun rebuild(l)= if l==nil then nil else let l->[a b] in if b==nil then a::nil else a::" "::rebuild b;; /*------------*/ /*add all texts of the list res in the hashtable*/ fun parcoursListe(res,tableLangue)= if res==nil then tableLangue else let res->[[ref suite] queue] in let strcatn rebuild suite -> txt in (if (ref==nil)||(txt==nil)||((nth_char ref 0)=='#) then nil else let hachage ref -> i in set tableLangue.(i) = [ref txt]::tableLangue.(i); /*we add the reference*/ parcoursListe queue tableLangue);; /*------------*/ /*search for the reference ref in the list l [[S S] r1]*/ /*returns the value of the reference*/ /*returns !!ERR_REF!! if reference not found*/ fun chercheRef(ref,l)= if l==nil then "!!ERR_REF!!" else let l->[[refCourante texte] queue] in (if !strcmp refCourante ref then texte else chercheRef ref queue);; /*------------*/ /*returns the parameter of the list param in function of the number no*/ /*returns !!ERR_PARAM!! if not found*/ fun getParam(param, no)= let nth_list param no -> p in if p==nil then "!!ERR_PARAM!!" else p;; /*------------*/ /*first param = list of all words of the text*/ /*2nd param = list of all parameters*/ /*returns msg as a string with all parameters inserted*/ fun parcoursMessage(messageParamNonInseres,param,NewListe)= let messageParamNonInseres -> [premier suite] in if (premier)!=nil then let "" -> resultat in ( let (strfind "<#" premier 0) -> resOpen in ( while resOpen!=nil do /*loop on all parameters*/ ( if resOpen!=0 then ( set resultat = strcat resultat substr premier 0 (resOpen); /*add char before param*/ set premier = substr premier resOpen ((strlen premier)); /*delete char before param*/ ) else nil; /*premier begins with <#*/ let strfind ">" premier 0 -> resClose in let strfind ":" premier 0 -> resFinNo in ( let substr premier 2 (resFinNo - 2) -> no in /*extract parameter number*/ set resultat = strcat resultat (getParam param atoi no); /*add parameter*/ set premier = substr premier (resClose + 1) ((strlen premier) - resClose + 1); /*delete parameter*/ set resOpen = strfind "<#" premier 0; /*search for next parameter*/ ); ) /*while*/ ); /*let strfind*/ if premier !=nil then set resultat = strcat resultat premier else nil; /*add char after last parameter*/ if NewListe==nil then parcoursMessage suite param (resultat) else if (nth_char NewListe ((strlen NewListe)-1)) == 10 then parcoursMessage suite param strcatn NewListe::resultat::nil else parcoursMessage suite param strcatn NewListe::" "::resultat::nil ) /*let resultat*/ else NewListe;; /*------------*/ /*returns a hashtable (tab [[S S] r1]) created with s (format strbuild)*/ fun createHashtable(s)= let strextr s -> res in let mktab 256 nil->tableLangue in parcoursListe res tableLangue;; /*------------*/ /*called to initialize DMI*/ fun iniDMIloc(myDmi,filename)= let _getpack _checkpack filename -> s in set myDmi.locDMI=createHashtable s;; /*------------*/ fun rebuild2(l)= if l==nil then nil else let l->[a b] in let mirror a -> ltemp in if b==nil then (mirror (hd ltemp)::(tl ltemp)) else listcat (mirror (strcat hd ltemp "\n")::(tl ltemp)) (rebuild2 b);; /*------------*/ /*returns the translation of the reference ref with its parameters param*/ /*returns !!ERR_REF!! if reference not found*/ fun _loc(myDmi,ref,param)= let hachage ref -> i in let myDmi.locDMI.(i)-> l in if l==nil then "!!ERR_REF!!" else if param==nil then chercheRef ref l else let chercheRef ref l -> s in let rebuild2 strextr s -> l2 in if (nth_char s ((strlen s)-1))==10 then strcat parcoursMessage l2 param nil "\n" else parcoursMessage l2 param nil;;