home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 1 / RISC_DISC_1.iso / pd_share / code / desklib / Docs / ModuleNote / Msgs < prev    next >
Encoding:
Text File  |  1993-04-29  |  7.3 KB  |  199 lines

  1. Help on DeskLib format messages files
  2. =====================================
  3.  
  4. A Msgs file is a sequence of lines which may be blank, a comment, or a
  5. message.
  6.  
  7. A comment is started with a # character at the START of a line
  8.  
  9. A Msgs message is of the form:
  10. group.msg: message
  11.  
  12. i.e.
  13. quit.menu:     Quit
  14. quit.help:     This menu option allows you to quit the application
  15. quit.notsaved: Some files are not saved. Are you sure you want to quit?
  16. quit.yes:      QUIT
  17. quit.no:       No
  18.  
  19. info.menu:     Info
  20. info.help:     Follow the arrow to display information about this program
  21.  
  22. etc.
  23.  
  24.  
  25.  
  26. "group" and "msg" tags are text strings (leading blanks (newlines, spaces,
  27. tabs) are ignored) of up to 8 characters. (8 because I can then do a very
  28. quick word-word comparison to compare tags instead of up to 8 character
  29. comparisons, and because more than 8 characters simply encourages slight
  30. memory wastage and inefficiency). They can contain any characters except "."
  31. (for group) and ":" (for msg).
  32.  
  33. The message following the ":" is of the following format:
  34.   Leading blanks are ignored
  35.   The message is all characters from then on until the next newline
  36.    (character 10 - LF) character. (there is no need for a newline character
  37.    at the end of the file)
  38.  
  39.   The normal string will be fetched using Msgs_Lookup.
  40.   It can contain any of the following controls:
  41.       <group.msg>   insert the message with the given tag
  42.                     (note: no default string can be specified here)
  43.       <>            can be used to insert a single "<" character
  44.  
  45.     e.g.
  46.       quit.text: Quit
  47.       quit.Menu: <quit.text>
  48.       quit.help: The <quit.text> option allows you to quit the application
  49.  
  50.     would allow us to change quit.text to "Finish" without changing the
  51.     other messages in the file.
  52.     The main use for this is to do stuff like:
  53.  
  54.       error.file: File not found <msg.space>
  55.       error.open: File is open <msg.space>
  56.       msg.space:  - Press space or click mouse to continue
  57.  
  58.     so that repeated parts of messages may be defined seperately, or:
  59.  
  60.       data.type: bytes
  61.       mess.1: File counted, %d <data.type>
  62.  
  63.     where in some situations you might like to change the term "bytes" to
  64.     read "octets" or "samples" without having to edit hundreds of messages
  65.     in your messages files
  66.  
  67.     The string can also contain all the normal controls that you can put
  68.     into an sprintf format string.
  69.     This is used with Msgs_printf, which is identical to sprintf except
  70.     that you pass in a message tag, and the message produced is then used
  71.     in an sprintf command as the format string.
  72.     e.g.
  73.     the messages:
  74.  
  75.       data.type: bytes
  76.       msg.count: File counted: %d <data.type>.
  77.  
  78.     used with:
  79.  
  80.       Msgs_printf(outputstring, "msg.count", bytecount);
  81.  
  82.     will give the equivalent of
  83.  
  84.       sprintf(outputstring, "File counted: %d bytes.", bytecount);
  85.  
  86.     resulting in (bytecount == 37)
  87.  
  88.       outputstring == "File counted, 37 bytes."
  89.    
  90. ALL substitutions are carried out when the message is fetched (NOT when
  91. messages are loaded). This has a slight speed disadvantage, but the main
  92. reason for message including was to allow inclusion of long strings that are
  93. used repeatedly, in order to reduce memory usage.
  94.  
  95. As you can see, this is much nicer, and in some ways more powerful than
  96. msgtrans' simpler "tag: message" format, and also requires less processor
  97. work to find things (as things are grouped, so you don't have to search the
  98. whole file, only one subgroup) (note: this may be slower than msgtrans - I
  99. don't claim it's faster, just IMHO nicer - if you prefer msgtrans, then use
  100. msgtrans)
  101.  
  102.  
  103. Using Msgs
  104. ==========
  105.  
  106. To retrieve a message, simply pass in the group and msg tags to the
  107. appropriate function, as in the following:
  108. "group.msg"              (The message indicated)
  109. "group.msg:default"      (If the message can't be found, use default instead)
  110.  
  111. Msgs_Lookup() is similar to Acorn's msgs_lookup(), but it returns a
  112. TRUE/FALSE result to indicate whether you have ended up with a valid string
  113. to print (either the found message, or the default string you supplied)
  114.  
  115.  
  116. WildCards
  117. =========
  118.  
  119. the last powerful function that Msgs_ provides is the ability to *terminate*
  120. a message tag (in the messages file, or in calls to Msgs functions) with a
  121. "*", which matches any character or character sequence.
  122.  
  123. The comparison process (in Msgs_Lookup) is done as a two-pass process, first
  124. it attempts to match the tags with wildcards disabled - if this fails, then
  125. a second pass is made with wildcards enabled. Thus, you can mix wildcards
  126. and normal tags without odd effects.
  127.  
  128. Messages are read in and added to the front of a linked-list, so any
  129. wildcarded messages in the messages file should appear EARLIER in the file
  130. than any other similar wildcarded messages, as in:
  131.  
  132.   win*.*: This is any general icon in the window
  133.   window.3: Icon 3 allows you to clear the picture
  134.   window.10: Icon 10 is the "OK" icon. Click it to finish editing
  135.   window.*: This is another generalised message
  136.   window.7: Icon 7 beeps if you click it
  137.  
  138. This will attempt to match any message with "window.7", then "window.10"
  139. then "window.3", and if no match is found, it will try to match "window.*"
  140. and then "win*.*" (so "window.9" will match "window.*", but "winston.churchill"
  141. will match "win*.*".
  142.  
  143. That is, the most generalised messages should go first, and more specific
  144. messages follow on. The most commonly used messages (if you know which ones
  145. they are) should be put towards the end of the group/file in order to
  146. increase efficiency in fetching them.
  147.  
  148.   --This would be used for situations such as Help_'s automatic help in a
  149.   window, where a help message is generated by using the window's
  150.   template-name (window), and appending the icon number, so if the mouse
  151.   pointer is over icon 12, the tag "window.12" is generated, which does not
  152.   match window.7 (checked first), window.10, or window.3, but does match
  153.   window.*
  154.   This means that if help is not specifically available for a given icon, the
  155.   help will default back to a general "window" help message.
  156.   Only the first matching message is returned.
  157.  
  158. Wildcards can be used in the messages file as above, and can also be used
  159. when fetching messages - using the above example, the tag "window.*" would
  160. match window.7, returning "Icon 7 beeps if you click it" (window.7 is the
  161. last matching message defined in the file, which means it will be checked
  162. FIRST)
  163.  
  164. the tag "window.1*" will not match window.7, so will continue to window.10,
  165. at which point the match is found, etc.
  166.  
  167. Note: Wildcards are only implemented simply: A wildcard essentially means
  168. the end of the tag, as it matches ALL characters from that point on -
  169. characters following the wildcard are ignored.
  170.  
  171. i.e. matching
  172.   window.icon45     
  173.  
  174. will return TRUE for all the following cases:
  175.   window.icon45
  176.   window.i*
  177.   window.i*45
  178.   window.i*zot
  179.   window.icon*
  180.   w*.ic*
  181. i.e. ONLY use the wildcard at the END of a tag.
  182. (and remember that the group and msg tags are treated as SEPERATE tags
  183. here, so w*.zot will NOT match the above)
  184.  
  185.  
  186. Extra notes
  187. ===========
  188.  
  189. a blank group tag or msg tag can be used (though it's not recommended), but
  190. the delimiters must still be present, as in:
  191.  
  192. .:Message for blank group and blank name
  193. quit.:Quit's blank-message-tag message
  194. .quit:No group for the quit message!
  195.  
  196. You can also use the same group/tag name (e.g. a blank name) for all
  197. messages, but this is silly, as the only effect is to reduce the speed with
  198. which messages can be found.
  199.