Path: utzoo!news-server.csri.toronto.edu!rutgers!uwm.edu!cs.utexas.edu!uunet!mcsun!ukc!warwick!maumg From: maumg@warwick.ac.uk (Pop Mobility Freak) Newsgroups: comp.sys.acorn Subject: MessageTrans Message-ID: <+GG&9-$@warwick.ac.uk> Date: 11 Mar 91 11:51:10 GMT References: Sender: news@warwick.ac.uk (Network news) Organization: Computing Services, Warwick University, UK Lines: 155 Nntp-Posting-Host: orchid Here is some information which I have worked out about the very useful MessageTrans module. This comes with the new printer drivers (ie versions 2.44 or later) in the !System directory. This module makes the use of Message files very easy. This is similar to the facility provided by C but allows parameter passing as well. There also appears to be an interface for creating menus but I cannot work out how this works. Before I explain the SWI's provided by these modules I will give an example of a message file ---------------------------- EXAMPLE MESSAGE FILE ---------------------------- NONE:This message take no parameters ONE:This message takes %0 as a parameter TWO:This message takes %0 and %1 as parameters THREE:This message has three parameters %0, %1 and %2 FOUR:The maximum number of parameters allowed is four %0, %1, %2, and %3 ------------------------- END OF EXAMPLE MESSAGE FILE ------------------------ As can be seen from the example above a message file consists of several lines each of which starts with a token followed by a colon and then the message. The %0, %1, %2 and %3 denote parameters which will be substituted for at the appropriate time. (They are similar to the % values in system variables. A parameter may be be used more than once in the same message. The SWI's provide by the module are &41500 MessageTrans_FileInfo &41501 MessageTrans_OpenFile &41502 MessageTrans_Lookup &41503 MessageTrans_MakeMenus &41504 MessageTrans_CloseFile I will now give a description of each SWI. The descriptions are in no way guarenteed as they are what I can have gained from experimenting with the module. MessageTrans_FileInfo (&41500) ------------------------------ Entry r1 -> filename of message file Exit r1 preserved r2 length of file + 4 Use All I can see that this SWI does is set r2 as shown above There may be some side effects I am not sure MessageTrans_OpenFile (&41501) ------------------------------ Entry r0 -> buffer of sixteen bytes r1 -> filename of message file Exit r0 preserved r1 preserved Use Loads the file into memory (probably the RMA) ready for use by MessageTrans_Lookup. The buffer is needed to be passed to the following SWI's. The final word in the buffer contains the pointer to filename passed in r1. So the filename may need to remain unchanged while the file is open. Things appear to work fine when the memory which contained the filename is changed but I would keep it unchanged for safety. MessageTrans_Lookup (&41502) ---------------------------- Entry r0 -> buffer passed to MessageTrans_OpenFile r1 -> token (eg pointer to "NONE") in the example above the tokens ARE case conscious r2 -> buffer for result r3 = length of buffer r4 -> first parameter \ r5 -> second parameter \ these are optional depending r6 -> third parameter / upon how many are required r7 -> forth parameter / Exit r2 -> the message after parameter substitution (assuming the token could be matched) the message is zero terminated r3 = length of message after substitution excluding the terminating zero Use Lookup a message from the message file. If a message matching the token is found then parameter substitution is performed on it and the result put into the buffer passed in r2. If a parameter is expected and the pointer is zero then the % is LEFT IN the message. So to not use a parameter the pointer must pointer to "". MessageTrans_MakeMenus (&41503) ------------------------------- Use I have no idea how to use this SWI. MessageTrans_CloseFile (&41504) ------------------------------- Entry r0 -> buffer passed to MessageTrans_OpenFile Exit None Use Free the memory used to store the message file. Finally here is an example program as how to use the module. To load it into Basic cut the file out and Load it from the supervisor prompt by doing Load of Basic -load . The program will be automatically given those annoying line numbers (long live TWINO8). The MessageTrans module must be loaded for the program to work (fairly obvious eh?) and the example message file shown above must be saved in the current directory under the filename Messages. ------------------------------- EXAMPLE PROGRAM ------------------------------ REM > MessageTst DIM space% 16, buffer% 256 SYS "MessageTrans_OpenFile",space%,"Messages" PRINT FNmessage0("NONE") PRINT FNmessage1("ONE" ,"Howard") PRINT FNmessage2("TWO" ,"Peter","Jane") PRINT FNmessage3("THREE","Pop","Mobility","Freak") PRINT FNmessage4("FOUR" ,"Joanne","Emma","Mary","Helen") SYS "MessageTrans_CloseFile",space% END DEF FNmessage0(token$) =FNmessage4(token$,"","","","") DEF FNmessage1(token$,param1$) =FNmessage4(token$,param1$,"","","") DEF FNmessage2(token$,param1$,param2$) =FNmessage4(token$,param1$,param2$,"","") DEF FNmessage3(token$,param1$,param2$,param3$) =FNmessage4(token$,param1$,param2$,param3$,"") DEF FNmessage4(token$,param1$,param2$,param3$,param4$) LOCAL length% SYS "MessageTrans_Lookup",space%,token$,buffer%,256,param1$,param2$,param3$,param4$ TO ,,,length% buffer%?length%=13 =$buffer% --------------------------- END OF EXAMPLE PROGRAM --------------------------- Yours PMF P.S. Perhaps someone in Acorn would like to fill in the blanks and correct any errors I made in the above.