Up: Classes   [Index]


Application

Application Class

Objects of Application class represent programs. This class provides basic methods for initializing and exiting programs, handling window size and placement for graphical programs, and starting subprograms, as well as other tasks.

Instance Variables

cmdLineArgc

An Integer that contains the value of the argc argument to main (). The value is normally set by the parseArgs method, below.

cmdLineArgs

An Array of Strings that contains each element of the argv parameter to main (). This is normally filled in by the parseArgs method, below.

exitHandler

A SignalHandler object that contains a user-installable signal handler. See SignalHandler.

geomFlags
winXOrg
winYOrg
winWidth
winHeight

Variables that specify the appication window’s dimensions, if any. These can be set by the parseX11Geometry method, below.

Instance Methods

__handleAppExit (__c_arg__ int signo)

A standard, user installable SIGINT (Ctrl-C) signal handler. If the application has enabled exception traces, print a stack trace and then call the default SIGINT handler. The signo argument contains the number of the signal that calls the method.

The application must first call the installExitHandler method (below) to define this method as a signal handler - then this method is called when the application receives a SIGINT, which is normally generated when the user presses Control-C.

This method does not return.

__handleSigAbrt (__c_arg__ int signo)

A standard, user installable SIGABRT handler. The application must first call installAbortHandler, below. If the application has enabled exception traces, print a stack trace before exiting. This method does not return.

classSearchPath (void)

Returns a String that contains Ctalk’s class library search path, with each directory separated by a colon (‘:’). The default is usually /usr/local/include/ctalk.

If there are any directories given as arguments to the ‘-I’ command line option, and any directories named in the ‘CLASSLIBDIRS’ environment variable, Ctalk includes those directories as well, and searches them first.

execC (String commandLine)
execC (String commandLine, String commandOutput)

Execute the command and arguments given by commandLine and wait for the program to finish. The method displays the standard output of the subprocess.

If a second argument is given, the program’s standard output is saved in the commandOutput object, which should normally be a String object. Here is a simple example program.


int main () {
  Application new myApp;
  String new str, output;
  
  str = "/bin/ls -l";
  myApp execC str, output;
  printf ("%s\n", output);
}

For any number of arguments, if the command redirects the standard outut, then the output is sent to the file that is the operand of a ‘>’ or ‘>>’ redirection operator.

If commandLine is the name of a shell script, the shell script is executed by a sub-shell using the system(3) library call.

getPID (void)

Returns an Integer with the program’s process ID.

installAbortHandlerBasic (void)

Installs a C handler for SIGABRT signals. The C handlers are more reliable, though less flexible, than handlers that use SignalHandler class.

This method catches a SIGABRT, and prints a walkback trace if tracing is enabled, before the application exits.

installExitHandler (void)

Install a SIGINT (C-c) handler in a Ctalk program that performs cleanup before exiting the application.

installExitHandlerBasic (void)

Installs a C handler for SIGINT signals (C-c or C-break for DJGPP) that is slightly more robust and reliable, though less flexible, than the SignalHandler classes.

This method causes the application to exit when receiving a signal, and prints a walkback trace if tracing is enabled.

installPrefix (void)

Returns a String with the name of the top-level directory where Ctalk’s various component subdirectories are located. For example, in relative terms, this is where Ctalk’s various components get installed.


Executables:            prefixdir/bin
Libraries:              prefixdir/lib
Class Libraries:        prefixdir/include/ctalk
Texinfo Manuals:        prefixdirshare/info
Manual Pages:           prefixdir/share/man
Searchable Docs:        prefixdir/share/ctalk

membervars (void)

Returns a String with the member variable declarations of the class named by the receiver. If the receiver is a String object, membervars returns the variables for the class given by the String's value. If the receiver is a class object, membervars returns the member variables for that class. For nany other type of object, membervars returns the variables declared in the object’s class. See ClassVariableKeyword.

Membervars returns the complete documentation of the instance or class variable, if the declaration also contains a documentation string. See VariableDocStrings.

methodDocString (String method-source)

Returns the documentation string from the source of the method given as the argument. See MethodDocStrings.

methodPrototypes (String input)

If input is a method’s source or a class library, returns a String containing the prototypes of the methods; that is, the declaration and the argument list.

methodSource (String className, String methodName)

Returns a String object with the source code of the method(s) that match the declarations, The methodSource method does not distinguish methods by the number of arguments, so it returns the code of any method in a class that matches the methodName arguement.


className instanceMethod methodName
className classMethod methodName

The method generates a SystemErrnoException if it can’t find the class file.

The methodSource method is built to be as fast as possible and has a rather simple minded view of what constitutes a method declaration.

The method only recognizes declarations that appear on a single line, in order to keep the regular expressions that do the matching as simple as possible, and it only matches spaces between tokens, and not tabs, at least at the moment. It can also be fooled by things that even look like a method declaration within the method body. For example, a phrase like,


className instanceMethod <some-method-name>

in the method’s documentation, causes methodSource to signal the start of the next method.

parseArgs (Integer argc, Array argv)

Takes the argv and argc parameters to main () and sets each element of the cmdLineArgs instance variable (above) to a String that contains each element of the system’s argv array.

parseX11Geometry (String geometryString)

Parses a X Window System geometry string. If the string specifies any of the x, y, width, or height values for a window, the method sets the winXOrg, winYOrg, winWidth, or winHeight instance variables. If the geometry string omits any of the values, the method sets the corresponding instance variable to zero. The method sets the geomFlags instance variable to the geometry flags provided by the window system.

This method only parses the geometry string. It does not make any adjustments for the display dimensions, or the window dimensions or placement.

For information about the format of a X geometry string, refer to the XParseGeometry(3) manual page.

spawnC (String command, Integer restrict)

Starts the program given by the argument command, and resumes execution of the main program. The method returns an Integer with the process ID of the child process.

The child process becomes a daemon process, which means it has no interaction with the parent process. If you want the parent process to handle the child processes’ output, refer to the execC method, above. Otherwise, communication between the parent and child process should be handled by UNIX’s interprocess communication facilities.

If the restrict argument is non-zero, the method also changes the child processes’ working directory to ‘/’ and its umask to ‘0’.

The spawnC method does not use a shell when executing the child process, which means that the method doesn’t handle shell facilities like IO redirection or file globbing. It’s also necessary to provide the full path name of the program to be launched in the background.

The process that handles the session management when the daemon process is launched remains executing until the parent process exits. This means there can be three entries in the system’s process table, but it helps minimize creating zombie processes in case any part of the program quits unexpectedly.

uSleep (long long int usecs)

Sleep for usecs microseconds.

useXRender (Boolean b)

If b is true, draw graphics using the X Render extension if it is available. If b is false, use Xlib for graphics drawing. The default is to draw using the X Render extension if it is available.

usingXRender (void)

Returns a Boolean value of True if the program is using the X Render extension for drawing, False otherwise.


Up: Classes   [Index]