Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / lib / site_perl / 5.8.0 / sun4-solaris / Tk / CmdLine.pod
CommitLineData
86530b38
AT
1=head1 NAME
2
3Tk::CmdLine - Process standard X11 command line options and set initial resources
4
5=for pm Tk/CmdLine.pm
6
7=for category Creating and Configuring Widgets
8
9=head1 SYNOPSIS
10
11 Tk::CmdLine::SetArguments([@argument]);
12
13 my $value = Tk::CmdLine::cget([$option]);
14
15 Tk::CmdLine::SetResources((\@resource | $resource) [, $priority]);
16
17 Tk::CmdLine::LoadResources(
18 [ -symbol => $symbol ]
19 [ -file => $fileSpec ]
20 [ -priority => $priority ]
21 [ -echo => $fileHandle ] );
22
23=head1 DESCRIPTION
24
25Process standard X11 command line options and set initial resources.
26
27The X11R5 man page for X11 says: "Most X programs attempt to use the same names
28for command line options and arguments. All applications written with the
29X Toolkit Intrinsics automatically accept the following options: ...".
30This module processes these command line options for perl/Tk applications
31using the C<SetArguments> function.
32
33This module can optionally be used to load initial resources explicitly via
34function C<SetResources>, or from specified files (default: the standard X11
35application-specific resource files) via function C<LoadResources>.
36
37=head2 Command Line Options
38
39=over 4
40
41=item B<-background> I<Color> | B<-bg> I<Color>
42
43Specifies the color to be used for the window background.
44
45=item B<-class> I<Class>
46
47Specifies the class under which resources for the application should be found.
48This option is useful in shell aliases to distinguish between invocations
49of an application, without resorting to creating links to alter the executable
50file name.
51
52=item B<-display> I<Display> | B<-screen> I<Display>
53
54Specifies the name of the X server to be used.
55
56=item B<-font> I<Font> | B<-fn> I<Font>
57
58Specifies the font to be used for displaying text.
59
60=item B<-foreground> I<Color> | B<-fg> I<Color>
61
62Specifies the color to be used for text or graphics.
63
64=item B<-geometry> I<Geometry>
65
66Specifies the initial size and location of the I<first>
67L<MainWindow|Tk::MainWindow>.
68
69=item B<-iconic>
70
71Indicates that the user would prefer that the application's windows initially
72not be visible as if the windows had been immediately iconified by the user.
73Window managers may choose not to honor the application's request.
74
75=item B<-motif>
76
77Specifies that the application should adhere as closely as possible to Motif
78look-and-feel standards. For example, active elements such as buttons and
79scrollbar sliders will not change color when the pointer passes over them.
80
81=item B<-name> I<Name>
82
83Specifies the name under which resources for the application should be found.
84This option is useful in shell aliases to distinguish between invocations
85of an application, without resorting to creating links to alter the executable
86file name.
87
88=item B<-synchronous>
89
90Indicates that requests to the X server should be sent synchronously, instead of
91asynchronously. Since Xlib normally buffers requests to the server, errors do
92do not necessarily get reported immediately after they occur. This option turns
93off the buffering so that the application can be debugged. It should never
94be used with a working program.
95
96=item B<-title> I<TitleString>
97
98This option specifies the title to be used for this window. This information is
99sometimes used by a window manager to provide some sort of header identifying
100the window.
101
102=item B<-xrm> I<ResourceString>
103
104Specifies a resource pattern and value to override any defaults. It is also
105very useful for setting resources that do not have explicit command line
106arguments.
107
108The I<ResourceString> is of the form E<lt>I<pattern>E<gt>:E<lt>I<value>E<gt>,
109that is (the first) ':' is used to determine which part is pattern and which
110part is value. The (E<lt>I<pattern>E<gt>, E<lt>I<value>E<gt>) pair is entered
111into the options database with B<optionAdd> (for each
112L<MainWindow|Tk::MainWindow> configured), with I<interactive> priority.
113
114=back
115
116=head2 Initial Resources
117
118There are several mechanism for initializing the resource database to be used
119by an X11 application. Resources may be defined in a $C<HOME>/.Xdefaults file,
120a system application defaults file (e.g.
121/usr/lib/X11/app-defaults/E<lt>B<CLASS>E<gt>),
122or a user application defaults file (e.g. $C<HOME>/E<lt>B<CLASS>E<gt>).
123The Tk::CmdLine functionality for setting initial resources concerns itself
124with the latter two.
125
126Resource files contain data lines of the form
127E<lt>I<pattern>E<gt>:E<lt>I<value>E<gt>.
128They may also contain blank lines and comment lines (denoted
129by a ! character as the first non-blank character). Refer to L<option|Tk::option>
130for a description of E<lt>I<pattern>E<gt>:E<lt>I<value>E<gt>.
131
132=over 4
133
134=item System Application Defaults Files
135
136System application defaults files may be specified via environment variable
137$C<XFILESEARCHPATH> which, if set, contains a colon-separated list of file
138patterns.
139
140=item User Application Defaults Files
141
142User application defaults files may be specified via environment variables
143$C<XUSERFILESEARCHPATH>, $C<XAPPLRESDIR> or $C<HOME>.
144
145=back
146
147=head1 METHODS
148
149=over 4
150
151=item B<SetArguments>
152
153Extract the X11 options contained in a specified array (@ARGV by default).
154
155 Tk::CmdLine::SetArguments([@argument])
156
157The X11 options may be specified using a single dash I<-> as per the X11
158convention, or using two dashes I<--> as per the POSIX standard (e.g.
159B<-geometry> I<100x100>, B<-geometry> I<100x100> or B<-geometry=>I<100x100>).
160The options may be interspersed with other options or arguments.
161A I<--> by itself terminates option processing.
162
163By default, command line options are extracted from @ARGV the first time
164a MainWindow is created. The Tk::MainWindow constructor indirectly invokes
165C<SetArguments> to do this.
166
167=item B<cget>
168
169Get the value of a configuration option specified via C<SetArguments>.
170(C<cget> first invokes C<SetArguments> if it has not already been invoked.)
171
172 Tk::CmdLine::cget([$option])
173
174The valid options are: B<-class>, B<-name>, B<-screen> and B<-title>.
175If no option is specified, B<-class> is implied.
176
177A typical use of C<cget> might be to obtain the application class in order
178to define the name of a resource file to be loaded in via C<LoadResources>.
179
180 my $class = Tk::CmdLine::cget(); # process command line and return class
181
182=item B<SetResources>
183
184Set the initial resources.
185
186 Tk::CmdLine::SetResources((\@resource | $resource) [, $priority])
187
188A single resource may be specified using a string of the form
189'E<lt>I<pattern>E<gt>:E<lt>I<value>E<gt>'. Multiple resources may be specified
190by passing an array reference whose elements are either strings of the above
191form, and/or anonymous arrays of the form [ E<lt>I<pattern>E<gt>,
192E<lt>I<value>E<gt> ]. The optional second argument specifies the priority,
193as defined in L<option|Tk::option>, to be associated with the resources
194(default: I<userDefault>).
195
196Note that C<SetResources> first invokes C<SetArguments> if it has not already
197been invoked.
198
199=item B<LoadResources>
200
201Load initial resources from one or more files.
202
203 Tk::CmdLine::LoadResources(
204 [ -symbol => $symbol ]
205 [ -file => $fileSpec ]
206 [ -priority => $priority ]
207 [ -echo => $fileHandle ] );
208
209[ B<-symbol> =E<gt> $symbol ] specifies the name of an environment variable
210that, if set, defines a colon-separated list of one or more directories and/or
211file patterns. $C<XUSERFILESEARCHPATH> is a special case.
212If $C<XUSERFILESEARCHPATH> is not set, $C<XAPPLRESDIR> is checked instead.
213If $C<XAPPLRESDIR> is not set, $C<HOME> is checked instead.
214
215An item is identified as a file pattern if it contains one or more /%[A-Za-z]/
216patterns. Only patterns B<%L>, B<%T> and B<%N> are currently recognized. All
217others are replaced with the null string. Pattern B<%L> is translated into
218$C<LANG>. Pattern B<%T> is translated into I<app-defaults>. Pattern B<%N> is
219translated into the application class name.
220
221Each file pattern, after substitutions are applied, is assumed to define a
222FileSpec to be examined.
223
224When a directory is specified, FileSpecs
225E<lt>B<DIRECTORY>E<gt>/E<lt>B<LANG>E<gt>/E<lt>B<CLASS>E<gt>
226and E<lt>B<DIRECTORY>E<gt>/E<lt>B<CLASS>E<gt> are defined, in that order.
227
228[ B<-file> =E<gt> $fileSpec ] specifies a resource file to be loaded in.
229The file is silently skipped if if does not exist, or if it is not readable.
230
231[ B<-priority> =E<gt> $priority ] specifies the priority, as defined in
232L<option|Tk::option>, to be associated with the resources
233(default: I<userDefault>).
234
235[ B<-echo> =E<gt> $fileHandle ] may be used to specify that a line should be
236printed to the corresponding FileHandle (default: \*STDOUT) everytime a file
237is examined / loaded.
238
239If no B<-symbol> or B<-file> options are specified, C<LoadResources>
240processes symbol $C<XFILESEARCHPATH> with priority I<startupFile> and
241$C<XUSERFILESEARCHPATH> with priority I<userDefault>.
242(Note that $C<XFILESEARCHPATH> and $C<XUSERFILESEARCHPATH> are supposed to
243contain only patterns. $C<XAPPLRESDIR> and $C<HOME> are supposed to be a single
244directory. C<LoadResources> does not check/care whether this is the case.)
245
246For each set of FileSpecs, C<LoadResources> examines each FileSpec to
247determine if the file exists and is readable. The first file that meets this
248criteria is read in and C<SetResources> is invoked.
249
250Note that C<LoadResources> first invokes C<SetArguments> if it has not already
251been invoked.
252
253=back
254
255=head1 NOTES
256
257This module is an object-oriented module whose methods can be invoked as object
258methods, class methods or regular functions. This is accomplished via an
259internally-maintained object reference which is created as necessary, and which
260always points to the last object used. C<SetArguments>, C<SetResources> and
261C<LoadResources> return the object reference.
262
263=head1 EXAMPLES
264
265=over
266
267=item 1
268
269@ARGV is processed by Tk::CmdLine at MainWindow creation.
270
271 use Tk;
272
273 # <Process @ARGV - ignoring all X11-specific options>
274
275 my $mw = MainWindow->new();
276
277 MainLoop();
278
279=item 2
280
281@ARGV is processed by Tk::CmdLine before MainWindow creation.
282An @ARGV of (--geometry=100x100 -opt1 a b c -bg red)
283is equal to (-opt1 a b c) after C<SetArguments> is invoked.
284
285 use Tk;
286
287 Tk::CmdLine::SetArguments(); # Tk::CmdLine->SetArguments() works too
288
289 # <Process @ARGV - not worrying about X11-specific options>
290
291 my $mw = MainWindow->new();
292
293 MainLoop();
294
295=item 3
296
297Just like 2) except that default arguments are loaded first.
298
299 use Tk;
300
301 Tk::CmdLine::SetArguments(qw(-name test -iconic));
302 Tk::CmdLine::SetArguments();
303
304 # <Process @ARGV - not worrying about X11-specific options>
305
306 my $mw = MainWindow->new();
307
308 MainLoop();
309
310=item 4
311
312@ARGV is processed by Tk::CmdLine before MainWindow creation.
313Standard resource files are loaded in before MainWindow creation.
314
315 use Tk;
316
317 Tk::CmdLine::SetArguments();
318
319 # <Process @ARGV - not worrying about X11-specific options>
320
321 Tk::CmdLine::LoadResources();
322
323 my $mw = MainWindow->new();
324
325 MainLoop();
326
327=item 5
328
329@ARGV is processed by Tk::CmdLine before MainWindow creation.
330Standard resource files are loaded in before MainWindow creation
331using non-default priorities.
332
333 use Tk;
334
335 Tk::CmdLine::SetArguments();
336
337 # <Process @ARGV - not worrying about X11-specific options>
338
339 Tk::CmdLine::LoadResources(-echo => \*STDOUT,
340 -priority => 65, -symbol => 'XFILESEARCHPATH' );
341 Tk::CmdLine::LoadResources(-echo => \*STDOUT,
342 -priority => 75, -symbol => 'XUSERFILESEARCHPATH' );
343
344 my $mw = MainWindow->new();
345
346 MainLoop();
347
348=item 6
349
350@ARGV is processed by Tk::CmdLine before MainWindow creation.
351Standard resource files are loaded in before MainWindow creation.
352Individual resources are also loaded in before MainWindow creation.
353
354 use Tk;
355
356 Tk::CmdLine::SetArguments();
357
358 # <Process @ARGV - not worrying about X11-specific options>
359
360 Tk::CmdLine::LoadResources();
361
362 Tk::CmdLine::SetResources( # set a single resource
363 '*Button*background: red',
364 'widgetDefault' );
365
366 Tk::CmdLine::SetResources( # set multiple resources
367 [ '*Button*background: red', '*Button*foreground: blue' ],
368 'widgetDefault' );
369
370 my $mw = MainWindow->new();
371
372 MainLoop();
373
374=back
375
376=head1 ENVIRONMENT
377
378=over 4
379
380=item B<HOME> (optional)
381
382Home directory which may contain user application defaults files as
383$C<HOME>/$C<LANG>/E<lt>B<CLASS>E<gt> or $C<HOME>/E<lt>B<CLASS>E<gt>.
384
385=item B<LANG> (optional)
386
387The current language (default: I<C>).
388
389=item B<XFILESEARCHPATH> (optional)
390
391Colon-separated list of FileSpec patterns used in defining
392system application defaults files.
393
394=item B<XUSERFILESEARCHPATH> (optional)
395
396Colon-separated list of FileSpec patterns used in defining
397user application defaults files.
398
399=item B<XAPPLRESDIR> (optional)
400
401Directory containing user application defaults files as
402$C<XAPPLRESDIR>/$C<LANG>/E<lt>B<CLASS>E<gt> or
403$C<XAPPLRESDIR>/E<lt>B<CLASS>E<gt>.
404
405=back
406
407=head1 SEE ALSO
408
409L<MainWindow|Tk::MainWindow>
410L<option|Tk::option>
411
412=head1 HISTORY
413
414=over 4
415
416=item *
417
4181999.03.04 Ben Pavon E<lt>ben.pavon@hsc.hac.comE<gt>
419
420Rewritten as an object-oriented module.
421
422Allow one to process command line options in a specified array (@ARGV by default).
423Eliminate restrictions on the format and location of the options within the array
424(previously the X11 options could not be specified in POSIX format and had to be
425at the beginning of the array).
426
427Added the C<SetResources> and C<LoadResources> functions to allow the definition
428of resources prior to MainWindow creation.
429
430=back
431
432=cut