.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "CmdLine 3" .TH CmdLine 3 2023-07-25 "perl v5.38.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Tk::CmdLine \- Process standard X11 command line options and set initial resources .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& Tk::CmdLine::SetArguments([@argument]); \& \& my $value = Tk::CmdLine::cget([$option]); \& \& Tk::CmdLine::SetResources((\e@resource | $resource) [, $priority]); \& \& Tk::CmdLine::LoadResources( \& [ \-symbol => $symbol ] \& [ \-file => $fileSpec ] \& [ \-priority => $priority ] \& [ \-echo => $fileHandle ] ); .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" Process standard X11 command line options and set initial resources. .PP The X11R5 man page for X11 says: "Most X programs attempt to use the same names for command line options and arguments. All applications written with the X Toolkit Intrinsics automatically accept the following options: ...". This module processes these command line options for perl/Tk applications using the \f(CW\*(C`SetArguments\*(C'\fR() function. .PP This module can optionally be used to load initial resources explicitly via function \f(CW\*(C`SetResources\*(C'\fR(), or from specified files (default: the standard X11 application-specific resource files) via function \f(CW\*(C`LoadResources\*(C'\fR(). .SS "Command Line Options" .IX Subsection "Command Line Options" .IP "\fB\-background\fR \fIColor\fR | \fB\-bg\fR \fIColor\fR" 4 .IX Item "-background Color | -bg Color" Specifies the color to be used for the window background. .IP "\fB\-class\fR \fIClass\fR" 4 .IX Item "-class Class" Specifies the class under which resources for the application should be found. This option is useful in shell aliases to distinguish between invocations of an application, without resorting to creating links to alter the executable file name. .IP "\fB\-display\fR \fIDisplay\fR | \fB\-screen\fR \fIDisplay\fR" 4 .IX Item "-display Display | -screen Display" Specifies the name of the X server to be used. .IP "\fB\-font\fR \fIFont\fR | \fB\-fn\fR \fIFont\fR" 4 .IX Item "-font Font | -fn Font" Specifies the font to be used for displaying text. .IP "\fB\-foreground\fR \fIColor\fR | \fB\-fg\fR \fIColor\fR" 4 .IX Item "-foreground Color | -fg Color" Specifies the color to be used for text or graphics. .IP "\fB\-geometry\fR \fIGeometry\fR" 4 .IX Item "-geometry Geometry" Specifies the initial size and location of the \fIfirst\fR MainWindow. .IP \fB\-iconic\fR 4 .IX Item "-iconic" Indicates that the user would prefer that the application's windows initially not be visible as if the windows had been immediately iconified by the user. Window managers may choose not to honor the application's request. .IP \fB\-motif\fR 4 .IX Item "-motif" Specifies that the application should adhere as closely as possible to Motif look-and-feel standards. For example, active elements such as buttons and scrollbar sliders will not change color when the pointer passes over them. .IP "\fB\-name\fR \fIName\fR" 4 .IX Item "-name Name" Specifies the name under which resources for the application should be found. This option is useful in shell aliases to distinguish between invocations of an application, without resorting to creating links to alter the executable file name. .IP \fB\-synchronous\fR 4 .IX Item "-synchronous" Indicates that requests to the X server should be sent synchronously, instead of asynchronously. Since Xlib normally buffers requests to the server, errors do do not necessarily get reported immediately after they occur. This option turns off the buffering so that the application can be debugged. It should never be used with a working program. .IP "\fB\-title\fR \fITitleString\fR" 4 .IX Item "-title TitleString" This option specifies the title to be used for this window. This information is sometimes used by a window manager to provide some sort of header identifying the window. .IP "\fB\-xrm\fR \fIResourceString\fR" 4 .IX Item "-xrm ResourceString" Specifies a resource pattern and value to override any defaults. It is also very useful for setting resources that do not have explicit command line arguments. .Sp The \fIResourceString\fR is of the form <\fIpattern\fR>:<\fIvalue\fR>, that is (the first) ':' is used to determine which part is pattern and which part is value. The (<\fIpattern\fR>, <\fIvalue\fR>) pair is entered into the options database with \fBoptionAdd\fR (for each MainWindow configured), with \fIinteractive\fR priority. .SS "Initial Resources" .IX Subsection "Initial Resources" There are several mechanism for initializing the resource database to be used by an X11 application. Resources may be defined in a $\f(CW\*(C`HOME\*(C'\fR/.Xdefaults file, a system application defaults file (e.g. /usr/lib/X11/app\-defaults/<\fBCLASS\fR>), or a user application defaults file (e.g. $\f(CW\*(C`HOME\*(C'\fR/<\fBCLASS\fR>). The Tk::CmdLine functionality for setting initial resources concerns itself with the latter two. .PP Resource files contain data lines of the form <\fIpattern\fR>:<\fIvalue\fR>. They may also contain blank lines and comment lines (denoted by a ! character as the first non-blank character). Refer to option for a description of <\fIpattern\fR>:<\fIvalue\fR>. .IP "System Application Defaults Files" 4 .IX Item "System Application Defaults Files" System application defaults files may be specified via environment variable $\f(CW\*(C`XFILESEARCHPATH\*(C'\fR which, if set, contains a list of file patterns (joined using the OS-dependent path delimiter, e.g. colon on \fBUNIX\fR). .IP "User Application Defaults Files" 4 .IX Item "User Application Defaults Files" User application defaults files may be specified via environment variables $\f(CW\*(C`XUSERFILESEARCHPATH\*(C'\fR, $\f(CW\*(C`XAPPLRESDIR\*(C'\fR or $\f(CW\*(C`HOME\*(C'\fR. .SH METHODS .IX Header "METHODS" .IP "\fBSetArguments\fR \- Tk::CmdLine::SetArguments([@argument])" 4 .IX Item "SetArguments - Tk::CmdLine::SetArguments([@argument])" Extract the X11 options contained in a specified array (@ARGV by default). .Sp .Vb 1 \& Tk::CmdLine::SetArguments([@argument]) .Ve .Sp The X11 options may be specified using a single dash \fI\-\fR as per the X11 convention, or using two dashes \fI\-\-\fR as per the POSIX standard (e.g. \&\fB\-geometry\fR \fI100x100\fR, \fB\-geometry\fR \fI100x100\fR or \fB\-geometry=\fR\fI100x100\fR). The options may be interspersed with other options or arguments. A \fI\-\-\fR by itself terminates option processing. .Sp By default, command line options are extracted from \f(CW@ARGV\fR the first time a MainWindow is created. The Tk::MainWindow constructor indirectly invokes \&\f(CW\*(C`SetArguments\*(C'\fR() to do this. .IP "\fBGetArguments\fR \- \fBTk::CmdLine::GetArguments()\fR" 4 .IX Item "GetArguments - Tk::CmdLine::GetArguments()" Get a list of the X11 options that have been processed by \f(CW\*(C`SetArguments\*(C'\fR(). (\f(CW\*(C`GetArguments\*(C'\fR() first invokes \f(CW\*(C`SetArguments\*(C'\fR() if it has not already been invoked.) .IP "\fBcget\fR \- Tk::CmdLine::cget([$option])" 4 .IX Item "cget - Tk::CmdLine::cget([$option])" Get the value of a configuration option specified via \f(CW\*(C`SetArguments\*(C'\fR(). (\f(CW\*(C`cget\*(C'\fR() first invokes \f(CW\*(C`SetArguments\*(C'\fR() if it has not already been invoked.) .Sp .Vb 1 \& Tk::CmdLine::cget([$option]) .Ve .Sp The valid options are: \fB\-class\fR, \fB\-name\fR, \fB\-screen\fR and \fB\-title\fR. If no option is specified, \fB\-class\fR is implied. .Sp A typical use of \f(CW\*(C`cget\*(C'\fR() might be to obtain the application class in order to define the name of a resource file to be loaded in via \f(CW\*(C`LoadResources\*(C'\fR(). .Sp .Vb 1 \& my $class = Tk::CmdLine::cget(); # process command line and return class .Ve .ie n .IP "\fBSetResources\fR \- Tk::CmdLine::SetResources((\e@resource | $resource) [, $priority])" 4 .el .IP "\fBSetResources\fR \- Tk::CmdLine::SetResources((\e@resource | \f(CW$resource\fR) [, \f(CW$priority\fR])" 4 .IX Item "SetResources - Tk::CmdLine::SetResources((@resource | $resource) [, $priority])" Set the initial resources. .Sp .Vb 1 \& Tk::CmdLine::SetResources((\e@resource | $resource) [, $priority]) .Ve .Sp A single resource may be specified using a string of the form \&'<\fIpattern\fR>:<\fIvalue\fR>'. Multiple resources may be specified by passing an array reference whose elements are either strings of the above form, and/or anonymous arrays of the form [ <\fIpattern\fR>, <\fIvalue\fR> ]. The optional second argument specifies the priority, as defined in option, to be associated with the resources (default: \fIuserDefault\fR). .Sp Note that \f(CW\*(C`SetResources\*(C'\fR() first invokes \f(CW\*(C`SetArguments\*(C'\fR() if it has not already been invoked. .IP "\fBLoadResources\fR \- Tk::CmdLine::LoadResources([%options])" 4 .IX Item "LoadResources - Tk::CmdLine::LoadResources([%options])" Load initial resources from one or more files. .Sp .Vb 5 \& Tk::CmdLine::LoadResources( \& [ \-symbol => $symbol ] \& [ \-file => $fileSpec ] \& [ \-priority => $priority ] \& [ \-echo => $fileHandle ] ); .Ve .Sp [ \fB\-symbol\fR => \f(CW$symbol\fR ] specifies the name of an environment variable that, if set, defines a list of one or more directories and/or file patterns (joined using the OS-dependent path delimiter, e.g. colon on \fBUNIX\fR). $\f(CW\*(C`XUSERFILESEARCHPATH\*(C'\fR is a special case. If $\f(CW\*(C`XUSERFILESEARCHPATH\*(C'\fR is not set, $\f(CW\*(C`XAPPLRESDIR\*(C'\fR is checked instead. If $\f(CW\*(C`XAPPLRESDIR\*(C'\fR is not set, $\f(CW\*(C`HOME\*(C'\fR is checked instead. .Sp An item is identified as a file pattern if it contains one or more /%[A\-Za\-z]/ patterns. Only patterns \fR\f(CB%L\fR\fB\fR, \fB\fR\f(CB%T\fR\fB\fR and \fB\fR\f(CB%N\fR\fB\fR are currently recognized. All others are replaced with the null string. Pattern \fB\fR\f(CB%L\fR\fB\fR is translated into $\f(CW\*(C`LANG\*(C'\fR. Pattern \fB\fR\f(CB%T\fR\fB\fR is translated into \fIapp-defaults\fR. Pattern \fB\fR\f(CB%N\fR\fB\fR is translated into the application class name. .Sp Each file pattern, after substitutions are applied, is assumed to define a FileSpec to be examined. .Sp When a directory is specified, FileSpecs <\fBDIRECTORY\fR>/<\fBLANG\fR>/<\fBCLASS\fR> and <\fBDIRECTORY\fR>/<\fBCLASS\fR> are defined, in that order. .Sp [ \fB\-file\fR => \f(CW$fileSpec\fR ] specifies a resource file to be loaded in. The file is silently skipped if if does not exist, or if it is not readable. .Sp [ \fB\-priority\fR => \f(CW$priority\fR ] specifies the priority, as defined in option, to be associated with the resources (default: \fIuserDefault\fR). .Sp [ \fB\-echo\fR => \f(CW$fileHandle\fR ] may be used to specify that a line should be printed to the corresponding FileHandle (default: \e*STDOUT) everytime a file is examined / loaded. .Sp If no \fB\-symbol\fR or \fB\-file\fR options are specified, \f(CW\*(C`LoadResources\*(C'\fR() processes symbol $\f(CW\*(C`XFILESEARCHPATH\*(C'\fR with priority \fIstartupFile\fR and $\f(CW\*(C`XUSERFILESEARCHPATH\*(C'\fR with priority \fIuserDefault\fR. (Note that $\f(CW\*(C`XFILESEARCHPATH\*(C'\fR and $\f(CW\*(C`XUSERFILESEARCHPATH\*(C'\fR are supposed to contain only patterns. $\f(CW\*(C`XAPPLRESDIR\*(C'\fR and $\f(CW\*(C`HOME\*(C'\fR are supposed to be a single directory. \f(CW\*(C`LoadResources\*(C'\fR() does not check/care whether this is the case.) .Sp For each set of FileSpecs, \f(CW\*(C`LoadResources\*(C'\fR() examines each FileSpec to determine if the file exists and is readable. The first file that meets this criteria is read in and \f(CW\*(C`SetResources\*(C'\fR() is invoked. .Sp Note that \f(CW\*(C`LoadResources\*(C'\fR() first invokes \f(CW\*(C`SetArguments\*(C'\fR() if it has not already been invoked. .SH NOTES .IX Header "NOTES" This module is an object-oriented module whose methods can be invoked as object methods, class methods or regular functions. This is accomplished via an internally-maintained object reference which is created as necessary, and which always points to the last object used. \f(CW\*(C`SetArguments\*(C'\fR(), \f(CW\*(C`SetResources\*(C'\fR() and \&\f(CW\*(C`LoadResources\*(C'\fR() return the object reference. .SH EXAMPLES .IX Header "EXAMPLES" .IP 1. 4 \&\f(CW@ARGV\fR is processed by Tk::CmdLine at MainWindow creation. .Sp .Vb 1 \& use Tk; \& \& # \& \& my $mw = MainWindow\->new(); \& \& MainLoop(); .Ve .IP 2. 4 \&\f(CW@ARGV\fR is processed by Tk::CmdLine before MainWindow creation. An \f(CW@ARGV\fR of (\-\-geometry=100x100 \-opt1 a b c \-bg red) is equal to (\-opt1 a b c) after \f(CW\*(C`SetArguments\*(C'\fR() is invoked. .Sp .Vb 1 \& use Tk; \& \& Tk::CmdLine::SetArguments(); # Tk::CmdLine\->SetArguments() works too \& \& # \& \& my $mw = MainWindow\->new(); \& \& MainLoop(); .Ve .IP 3. 4 Just like 2) except that default arguments are loaded first. .Sp .Vb 1 \& use Tk; \& \& Tk::CmdLine::SetArguments(qw(\-name test \-iconic)); \& Tk::CmdLine::SetArguments(); \& \& # \& \& my $mw = MainWindow\->new(); \& \& MainLoop(); .Ve .IP 4. 4 \&\f(CW@ARGV\fR is processed by Tk::CmdLine before MainWindow creation. Standard resource files are loaded in before MainWindow creation. .Sp .Vb 1 \& use Tk; \& \& Tk::CmdLine::SetArguments(); \& \& # \& \& Tk::CmdLine::LoadResources(); \& \& my $mw = MainWindow\->new(); \& \& MainLoop(); .Ve .IP 5. 4 \&\f(CW@ARGV\fR is processed by Tk::CmdLine before MainWindow creation. Standard resource files are loaded in before MainWindow creation using non-default priorities. .Sp .Vb 1 \& use Tk; \& \& Tk::CmdLine::SetArguments(); \& \& # \& \& Tk::CmdLine::LoadResources(\-echo => \e*STDOUT, \& \-priority => 65, \-symbol => \*(AqXFILESEARCHPATH\*(Aq ); \& Tk::CmdLine::LoadResources(\-echo => \e*STDOUT, \& \-priority => 75, \-symbol => \*(AqXUSERFILESEARCHPATH\*(Aq ); \& \& my $mw = MainWindow\->new(); \& \& MainLoop(); .Ve .IP 6. 4 \&\f(CW@ARGV\fR is processed by Tk::CmdLine before MainWindow creation. Standard resource files are loaded in before MainWindow creation. Individual resources are also loaded in before MainWindow creation. .Sp .Vb 1 \& use Tk; \& \& Tk::CmdLine::SetArguments(); \& \& # \& \& Tk::CmdLine::LoadResources(); \& \& Tk::CmdLine::SetResources( # set a single resource \& \*(Aq*Button*background: red\*(Aq, \& \*(AqwidgetDefault\*(Aq ); \& \& Tk::CmdLine::SetResources( # set multiple resources \& [ \*(Aq*Button*background: red\*(Aq, \*(Aq*Button*foreground: blue\*(Aq ], \& \*(AqwidgetDefault\*(Aq ); \& \& my $mw = MainWindow\->new(); \& \& MainLoop(); .Ve .SH ENVIRONMENT .IX Header "ENVIRONMENT" .IP "\fBHOME\fR (optional)" 4 .IX Item "HOME (optional)" Home directory which may contain user application defaults files as $\f(CW\*(C`HOME\*(C'\fR/$\f(CW\*(C`LANG\*(C'\fR/<\fBCLASS\fR> or $\f(CW\*(C`HOME\*(C'\fR/<\fBCLASS\fR>. .IP "\fBLANG\fR (optional)" 4 .IX Item "LANG (optional)" The current language (default: \fIC\fR). .IP "\fBXFILESEARCHPATH\fR (optional)" 4 .IX Item "XFILESEARCHPATH (optional)" List of FileSpec patterns (joined using the OS-dependent path delimiter, e.g. colon on \fBUNIX\fR) used in defining system application defaults files. .IP "\fBXUSERFILESEARCHPATH\fR (optional)" 4 .IX Item "XUSERFILESEARCHPATH (optional)" List of FileSpec patterns (joined using the OS-dependent path delimiter, e.g. colon on \fBUNIX\fR) used in defining user application defaults files. .IP "\fBXAPPLRESDIR\fR (optional)" 4 .IX Item "XAPPLRESDIR (optional)" Directory containing user application defaults files as $\f(CW\*(C`XAPPLRESDIR\*(C'\fR/$\f(CW\*(C`LANG\*(C'\fR/<\fBCLASS\fR> or $\f(CW\*(C`XAPPLRESDIR\*(C'\fR/<\fBCLASS\fR>. .SH "SEE ALSO" .IX Header "SEE ALSO" MainWindow option .SH HISTORY .IX Header "HISTORY" .IP \(bu 4 1999.03.04 Ben Pavon .Sp Rewritten as an object-oriented module. .Sp Allow one to process command line options in a specified array (@ARGV by default). Eliminate restrictions on the format and location of the options within the array (previously the X11 options could not be specified in POSIX format and had to be at the beginning of the array). .Sp Added the \f(CW\*(C`SetResources\*(C'\fR() and \f(CW\*(C`LoadResources\*(C'\fR() functions to allow the definition of resources prior to MainWindow creation. .IP \(bu 4 2000.08.31 Ben Pavon .Sp Added the \f(CW\*(C`GetArguments\*(C'\fR() method which returns the list of arguments that have been processed by \f(CW\*(C`SetArguments\*(C'\fR(). .Sp Modified \f(CW\*(C`LoadResources\*(C'\fR() to split the symbols using the OS-dependent path delimiter defined in the \fBConfig\fR module. .Sp Modified \f(CW\*(C`LoadResources\*(C'\fR() to eliminate a warning message when processing patterns \fR\f(CB%l\fR\fB\fR, \fB\fR\f(CB%C\fR\fB\fR, \fB\fR\f(CB%S\fR\fB\fR.