[Arjen Markus] Part three of the tutorial [How to make a Tcl application] ---- '''8. Platform issues''' Tcl applications are highly portable in general: * Tcl itself deals gracefully with such trivial but annoying matters as line-endings (the two characters carriage, return line feed versus line feed versus ... for instance) * The Tcl commands that deal with the operating system hide almost all platform-specific issues - file names and directory names for instance via the [[file]] command * the Tk package works on all supported platforms in much the same way - you need not to be concerned about platform-specific issues like window decorations most of the time But despite of this, there are a few aspects that you do need to consider, when your application or library is to run on several platforms - and believe me: they will. This chapter is meant to introduce them and the means to solve the problems they cause. ''8.1 The tcl_platform array'' Tcl collects all information about the platform in a global array, called tcl_platform. Here is a typical listing of its contents: % parray tcl_platform tcl_platform(byteOrder) = littleEndian tcl_platform(machine) = intel tcl_platform(os) = Windows 95 tcl_platform(osVersion) = 4.0 tcl_platform(platform) = windows tcl_platform(user) = arjen tcl_platform(wordSize) = 4 (Note the use of the array printing command ''parray'' - very useful in an interactive shell) The most useful of these for distinguishing between platforms is tcl_platform(platform): it gives you a standard characterisation of the OS. Typical values: windows, unix and macos. ''Tip:'' Put everything that is platform-specific in a central place - do not scatter checks on the type of platform all over your code, as that makes it difficult to maintain it. Probably the best approach is to use one or two source files with platform-specific procedures whose interface is essentially platform-'''in'''dependent. Remember that in Tcl it is quite possible to use constructions like: if { $tcl_platform(platform) == "windows" } { proc getColours {} { ... } } if { $tcl_platform(platform) == "unix" } { proc getColours {} { ... } } if { $tcl_platform(platform) == "macos" } { proc getColours {} { ... } } This way there is no need to do any run-time checking. ''8.2 File and directory names'' ''8.3 Fonts and colours'' ''8.4 Interacting with the desktop'' ''8.5 Dealing with numbers'' ---- [[ [Category Tutorial] ]]