Developing Unix programs
Developing with Stony Brook Modula-2 allows you to take advantage of "Unix"capabilities, including:
UNIX development information
UNIX cross development
The environment program name is m2e. The debugger program name is sbd. During installation you were given the option to have symbolic links to these programs created in the "/usr/bin" directory which is typically included in the command search path.
The core "Unix" APIs
|UNIX||The portable core UNIX APIs|
|PTHREADS||POSIX threads API, and other thread related APIs.|
|POSIX_REALTIME||Interface to the POSIX realtime APIs (timers, etc).|
|DLFCN||API to dynamically load shared objects|
|CURSES||A very minimal conversion of the "curses" API.|
|UnixSock||Interface to the "sockets" API|
|LINUX||APIs specific to the Linux system.|
The GTK+/Gnome API
In order to develop applications that provide your users with the menus, dialogs,windows and other features they will be expecting you will have to use the GTK+ and/orGnome Application Programming Interface(API). Gnome adds additional functionalityto GTK+. These APIs are provided in definition modules in the runtime library. You can call these API functions in the same way you call run time libraryfunctions.
Many of the API calls have been altered from their original C style to a stylethat is more natural for the Modula-2 programming language. The parameters that havebeen converted are pointer parameters. The Modula-2 language in many ways does notneed such parameters and Stony Brook Modula-2 takes this a bit further. The parametersare either value or VAR parameters depending on the function usage of the parameter.
String Parameters. (gchar *) are pointers to characters. In the Modula-2 API definitionsthese where converted to ARRAY OF gchar parameters without the implicit high bound.However, the API restriction that strings be null terminated still applies, so takecare that strings you pass are indeed null terminated.
RECORD type parameters. Pointers to RECORD types have been converted to valueor VAR parameters. This can be done because our compiler always passes RECORD typesby reference, even for value parameters.
ARRAY type parameters. Pointers to ARRAY types have been converted to value orVAR parameters. This can be done because our compiler always passes ARRAY types byreference, even for value parameters.
Pointers to scalar types. In these cases the API call is doing exactly what theModula-2 VAR parameter accomplishes. The VAR parameter is a cleaner and type safemechanism.
Explicit pointer types have been declared for each record type defined in theoriginal C headers. The pointer type has the name of the record type prefixed witha lower case letter p.
The GTK+/Gnome 1.x API set has been ported from C in such a was as to allow inheritingan original widget and extend it via Modula-2. Much of this information is unnecessaryto just "use" the widgets in an application. Generally you will treatthe contents of the returned pointer types as magic cookies unless you intend todo low level programming.
Here is a list of the GTK+ and Gnome API files provided and what they contain:
|GTK||This contains all GTK+ widgets in a single file.|
|GLADE||This is the libglade interface for creating glade user interface descriptions and creating them at runtime. glade itself normally generates source code.|
|GDK||This contains the API procedure of the GDK. This is a simplified encapsulation of the X window system. GTK uses the GDK for all operations. It provides graphics painting operations.|
|GDK_TYPES||This contains the type declarations for the GDK.|
|GDK_RGB||This contains types and functions for manipulating rgb images.|
|GDK_KEYSYMS||This contains the symbolic constant values identifying GDK keys|
|GLIB||This is a utility and portability library used by Gnome, GTK and GDK|
Exception Handlers on Exports
Procedures which are marked with the EXPORT attribute will automatically generatean exception handler if you do not supply one. The exception handler will terminatethe program if it is activated. This is to avoid the situation of an exceptionpropagating to other programs. We strongly recommend that you provide an explicitexception handler on all exported procedures and handle any exceptions in a way thatbest suits your program (Returning an error code for example).
A compiler directive is supplied to allow a procedure with the EXPORT attributeto propagate and exception. This should only be used when Modula-2 is calling Modula-2code and all of the code is using the same instance of the runtime system. If yourexported procedure is in a DLL then you should be linking to the DLL version of theModula-2 runtime library for all DLLs and programs.
Trapping access violations via exception handlers
Program access violations are trapped by default in main programs. In shared objectshowever the runtime system defers to the actions of the main program. This is dueto how Unix systems inform a process of an access violation. You can manually enabletrapping access violations in shared objects by calling the TrapAccesssViolationsprocedure imported from the SYSTEM module.
Access violations consist of the SIGSEGV, SIGBUS and SIGILL signals. Trappingan access violation means the violation is converted to a native language exception.
Note that it is still possible for code to override our runtime system signalhandlers used to trap the access violations. If this occurs, the access violationwill not be trapped by our runtime system.