1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770
|
<!doctype html public "-//W30//DTD W3 HTML 2.0//EN">
<HTML>
<!-- This file was generated using SDF 2.001 by
Ian Clatworthy (ianc@mincom.com). SDF is freely
available from http://www.mincom.com/mtr/sdf. -->
<HEAD>
<TITLE>SDF 2.001: SDF Guru Guide: app.pl - Application Framework Library</TITLE>
</HEAD>
<BODY BGCOLOR="ffffff">
<DIV CLASS="header">
<P><IMG SRC="../sdflogo.gif" ALIGN="Right"></P>
<DIV CLASS="navigate">
<P ALIGN="Center"><A HREF="gg_sdf.html">Contents</A> | <A HREF="in_api.html">Parent Topic</A> | <A HREF="in_api.html">Previous Topic</A> | <A HREF="dict.html">Next Topic</A> <BR><A HREF="../index.html">Home</A> | <A HREF="../catalog.html">Catalog</A></P>
</DIV>
<BR CLEAR="Right">
</DIV>
<DIV CLASS="main">
<H1><A NAME="app.pl">2.2. app.pl - Application Framework Library</A></H1>
<HR>
<H2><A NAME="Purpose">2.2.1. Purpose</A></H2>
<P>This library provides a common application framework for <A HREF="http://www.perl.com/perl/index.html">Perl</A> scripts.</P>
<HR>
<H2><A NAME="Interface">2.2.2. Interface</A></H2>
<PRE>
require "app.pl";
$<A HREF="#app_APP_STDIN_ARGS">APP_STDIN_ARGS</A> = ...
$<A HREF="#app_app_lib_dir">app_lib_dir</A> = ...
@<A HREF="#app_app_exit_routines">app_exit_routines</A> = ...
%<A HREF="#app_app_config">app_config</A> = ...
@<A HREF="#app_app_option_core">app_option_core</A> = ...
@<A HREF="#app_app_option">app_option</A> = ...
@<A HREF="#app_app_msg_table">app_msg_table</A> = ...
$<A HREF="#app_app_context">app_context</A> = ...
$<A HREF="#app_app_lineno">app_lineno</A> = ...
%<A HREF="#app_app_msg_index">app_msg_index</A> = ...
$<A HREF="#app_app_log_strm">app_log_strm</A> = ...
$<A HREF="#app_app_product_name">app_product_name</A> = ...
$<A HREF="#app_app_product_version">app_product_version</A> = ...
%<A HREF="#app_app_trace_level">app_trace_level</A> = ...
&<A HREF="#app_AppMsg">AppMsg</A>($type, $text, $calltree, $log_only);
%count =
&<A HREF="#app_AppMsgCounts">AppMsgCounts</A>($start_index);
$index =
&<A HREF="#app_AppMsgNextIndex">AppMsgNextIndex</A>();
&<A HREF="#app_AppExit">AppExit</A>($type, $text, $calltree, $log_only);
&<A HREF="#app_AppTrace">AppTrace</A>($group, $level, $msg, $log_only);
$ok =
&<A HREF="#app_AppInit">AppInit</A>($arguments, $purpose, $product, $ini_handler);
&<A HREF="#app_AppPrintUsage">AppPrintUsage</A>();
%values =
&<A HREF="#app_AppSectionValues">AppSectionValues</A>($strs);
&<A HREF="#app_AppShowParts">AppShowParts</A>();
&<A HREF="#app_AppShowCallTree">AppShowCallTree</A>();
$app_err =
&<A HREF="#app_AppProcess">AppProcess</A>($arg_process_fn, $arg_post_process_fn, $default_ext);
</PRE>
<HR>
<H2><A NAME="Description">2.2.3. Description</A></H2>
<H3><A NAME="Overview">2.2.3.1. Overview</A></H3>
<P>This library provides routines for:</P>
<UL>
<LI>option processing
<LI>argument processing
<LI>message handling
<LI>exiting a script</UL>
<P>In principle, scripts using this library have a consistent user interface and internal structure, making them easier to use and maintain. A typical script looks like:</P>
<PRE>
require "sdf/app.pl";
# define configuration
%app_config = (
'inifile', 'abc.ini',
);
# define options
push(@app_option, (
'str|STR|my string parameter',
));
# handle options
&AppInit('file ...', 'do things to files') || &AppExit();
# my post init stuff. e.g.
# * act on options
# * pop leading/trailing argument
&AppProcess('argProcess');
# my pre exit stuff. e.g.
# * print summary information
&AppExit();
</PRE>
<P>To summarise the framework:</P>
<UL>
<LI>%app_config is an optional set of configuration parameters
<LI>@app_option is the set of options supported
<LI>AppInit processes options and checks the argument count
<LI>AppProcess processes arguments (i.e. for each one, calls a user defined subroutine typically called <EM>argProcess</EM>)
<LI><EM>argProcess</EM> outputs messages using AppMsg
<LI>AppExit exits and returns an error code to the operating system based on the severity of the messages output via AppMsg</UL>
<H3><A NAME="Option Definitions">2.2.3.2. Option Definitions</A></H3>
<P>Each option is defined by the fields in the table below.</P>
<TABLE CLASS="columns" BORDER>
<TR CLASS="heading">
<TD>
<STRONG>Field</STRONG>
</TD>
<TD>
<STRONG>Description</STRONG>
</TD>
</TR>
<TR>
<TD>
Option
</TD>
<TD>
option name
</TD>
</TR>
<TR>
<TD>
Spec
</TD>
<TD>
option specification (type, etc.)
</TD>
</TR>
<TR>
<TD>
Help
</TD>
<TD>
short description of option
</TD>
</TR>
</TABLE>
<P>The name of the option is used in several ways:</P>
<UL>
<LI>as the name of the Perl variable (e.g. $help)
<LI>as the name of the long option (e.g. --help)</UL>
<P>If short format is enabled (e.g. -h), by default, the first character of the option name is used as the option code. Alternatively, the code to use can be explicitly specified using the <EM>Option</EM> syntax:</P>
<PRE>
name";"code
</PRE>
<P>This should be done if the default codes are not unique. To specify an option without a parameter, use the following <EM>Spec</EM> syntax:</P>
<PRE>
BOOL
</PRE>
<P>If no <EM>Spec</EM> field is specified, this is the default. The value of a parameter-less option is 1 if the option if supplied on the command-line.</P>
<P>To specify an option with a parameter, use the following <EM>Spec</EM> syntax:</P>
<PRE>
opt_type"-"validation";"initial_value";"default_value
</PRE>
<P>Only the <EM>opt_type</EM> field is mandatory. The second semi-colon must be present to nominate the parameter as optional. Otherwise, the parameter is assumed to be required. The list of supported opt_types is given in the table below.</P>
<TABLE CLASS="columns" BORDER>
<TR CLASS="heading">
<TD>
<STRONG>Type</STRONG>
</TD>
<TD>
<STRONG>Validation</STRONG>
</TD>
<TD>
<STRONG>Description</STRONG>
</TD>
</TR>
<TR>
<TD>
STR
</TD>
<TD>
value list
</TD>
<TD>
text string
</TD>
</TR>
<TR>
<TD>
INT
</TD>
<TD>
min,max
</TD>
<TD>
integer number
</TD>
</TR>
<TR>
<TD>
NUM
</TD>
<TD>
min,max
</TD>
<TD>
real number
</TD>
</TR>
</TABLE>
<P><EM>min</EM> and <EM>max</EM> are optional in the validation of numeric options. Typical STR definitions are given below.</P>
<PRE>
STR-(qwe,asd,zxc);qwe;asd # in-lining of codes
STR-@ok_array;qwe;asd # array lookup
STR-keys %ok_hash;qwe;asd # hash validate
STR-values %ok_hash;qwe;asd # hash validate
</PRE>
<P>An array of STR, INT or NUM can be requested by suffixing the type with 'LIST' or 'HASH'. LIST create a normal array and HASH create an associative array in Perl. Array options can be specified multiple times on the command-line and multiple items can be specified at once separated by commas. For a LIST, the values supplied are appended to the current list. For a HASH, values are treated as follows:</P>
<UL>
<LI>if the format is 'x=y', the result is: $optname{'x'} = 'y'
<LI>otherwise, the result is: $optname{'x'} = 1</UL>
<P>In some cases, it is useful to give an array option an initial value but permit the user to 'reset' the array back to empty. This can be done by defining the option as having an empty optional parameter. i.e. selecting the default value of a parameter-optional LIST or HASH does not append the default value - it initialises the array to the default value.</P>
<P>If finer control is required over processing an option, a routine can be nominated to process an option. To do this, use the following <EM>Spec</EM> syntax:</P>
<PRE>
ROUTINE"-"routine_name";"initial_value";"default_value
</PRE>
<P>The parameter type is specified by the number of semi-colons:</P>
<UL>
<LI>0 - no parameter
<LI>1 - required parameter
<LI>2 - optional parameter</UL>
<P>The parameter, if any, is passed as a string to the nominated routine.</P>
<H3><A NAME="Configuration Parameters">2.2.3.3. Configuration Parameters</A></H3>
<P>The configuration parameters supported are summarised below.</P>
<TABLE CLASS="columns" BORDER>
<TR CLASS="heading">
<TD>
<STRONG>Parameter</STRONG>
</TD>
<TD>
<STRONG>Description</STRONG>
</TD>
</TR>
<TR>
<TD>
inifile
</TD>
<TD>
the name of the initialisation file to use, if any
</TD>
</TR>
<TR>
<TD>
version
</TD>
<TD>
the script version
</TD>
</TR>
<TR>
<TD>
product
</TD>
<TD>
the product to which this script belongs, if any
</TD>
</TR>
<TR>
<TD>
parts
</TD>
<TD>
display name & version of components (and exit)
</TD>
</TR>
<TR>
<TD>
time
</TD>
<TD>
display execution time (when exiting)
</TD>
</TR>
<TR>
<TD>
calltree
</TD>
<TD>
display the sequence of function calls causing the exit
</TD>
</TR>
</TABLE>
<P>There are several ways to set configuration parameters:</P>
<OL>
<LI>by initialising %app_config before calling AppInit
<LI>by defining parameters in the '[Configuration]' section of an initialisation file
<LI>by setting parameters on the command line (using the . option)
<LI>for backwards compatibility, certain parameters can be set other ways:<UL>
<LI><EM>version</EM> can be set via $VERSION{'PUBLIC'}</UL><UL>
<LI><EM>product</EM> can be set via AppInit</UL></OL>
<H3><A NAME="Configuration Data">2.2.3.4. Configuration Data</A></H3>
<P>Configuration data can be stored in <EM>ini</EM> files and loaded during the initialisation stage (i.e. while AppInit is running). To do this, specify a subroutine as the <EM>ini_handler</EM> parameter for AppInit. The routine is passed the name of the ini file and an associative array containing the sections (after the standard ones like 'Configuration' have been removed). A warning will be produced for any sections not processed by your routine, so delete each section after you have finished processing it. A sample processing routine is given below.</P>
<PRE>
sub iniProcess {
local($fname, *data) = @_;
# local();
local($section);
local(@my_table, %my_values);
for $section (sort keys %data) {
if ($section eq 'MyTable') {
@my_table = &TableParse($data{$section});
delete $data{$section};
}
elsif ($section eq 'MyValues') {
%my_values = &AppIniValues($data{$section});
delete $data{$section};
}
}
}
</PRE>
<H3><A NAME="Component Descriptions">2.2.3.5. Component Descriptions</A></H3>
<P><STRONG><A NAME="app_APP_STDIN_ARGS">$APP_STDIN_ARGS</A></STRONG> is the pseudo argument (default '+') which causes standard input to be processed as a list of arguments. Some scripts may wish to use another symbol (i.e. '+' might be required as a genuine argument), or disable this behaviour altogether. See <STRONG><A NAME="app_AppProcess">AppProcess</A></STRONG>.</P>
<P><STRONG><A NAME="app_app_path">$app_path</A></STRONG>, <STRONG><A NAME="app_app_dir">$app_dir</A></STRONG> and <STRONG><A NAME="app_app_name">$app_name</A></STRONG> are the full pathname, directory and name of the application respectively.</P>
<P><STRONG><A NAME="app_app_lib_dir">$app_lib_dir</A></STRONG> is the library directory for this application, i.e. the directory containing configuration files. The default value is the <STRONG><A NAME="app_app_dir">$app_dir</A></STRONG>. This directory is typically set by searching the Perl library path for the <EM>libdir</EM> configuration parameter, if any.</P>
<P><STRONG><A NAME="app_app_exit_routines">@app_exit_routines</A></STRONG> is the stack of routines to be executed on program termination. If you want a routine to be called on termination (normal and abnormal), push the name of the routine onto this stack. These routines will be executed when <STRONG><A NAME="app_AppExit">AppExit</A></STRONG> is called. It is thus advisable to ensure that <STRONG><A NAME="app_AppExit">AppExit</A></STRONG> is NOT called within an exit routine.</P>
<P><STRONG><A NAME="app_app_config">%app_config</A></STRONG> contains the application's configuration parameters. <EM>@app_option</EM> defines the options supported by the application. The default options are <EM>help</EM>, <EM>out_ext</EM>, <EM>log_ext</EM> and <EM>out_dir</EM>. To append to these, push your arguments onto the array. For example:</P>
<PRE>
push(@app_option,
'report|STR|report file',
);
</PRE>
<P>If the script will never have a need for 'per file' output or errors, assign <STRONG><A NAME="app_app_option_core">@app_option_core</A></STRONG> to <STRONG><A NAME="app_app_option">@app_option</A></STRONG> before appending your script-specific options. For example:</P>
<PRE>
@app_option = @app_option_core;
push(@app_option,
'report|STR|report file',
);
</PRE>
<P>To obtain a concise description of each option, use the help option with no parameter. Alternatively, detailed help on a given option can be obtained by suppying the option name as a parameter.</P>
<P>By default, output goes to standard output and diagnostics goes to standard error. These rules can be changed by specifying the <EM>out_ext</EM> and <EM>log_ext</EM> options respectively (and calling <STRONG><A NAME="app_AppProcess">AppProcess</A></STRONG> to process arguments). If a string is supplied to these options, it is treated as the extension of the file to send things to for each file. If supplied without a parameter, the extensions default to <EM>out</EM> and <EM>log</EM> respectively. A minus character (-) or an equals character (=) can be used to indicate standard output or standard error respectively.</P>
<P>By default, output and log files are created in the current directory. To specify the same directory as the input file, specify the <EM>out_dir</EM> option without an argument. To specify an explicit directory, pass that directory as the argument to the <EM>out_dir</EM> option.</P>
<P><STRONG><A NAME="app_app_msg_table">app_msg_table</A></STRONG> defines the known message types. Each type is defined by the attributes in the table below.</P>
<TABLE CLASS="columns" BORDER>
<TR CLASS="heading">
<TD>
<STRONG>Attribute</STRONG>
</TD>
<TD>
<STRONG>Description</STRONG>
</TD>
</TR>
<TR>
<TD>
Type
</TD>
<TD>
message type name
</TD>
</TR>
<TR>
<TD>
Severity
</TD>
<TD>
application exit code caused by this message
</TD>
</TR>
<TR>
<TD>
Layout
</TD>
<TD>
format of message text
</TD>
</TR>
</TABLE>
<P><EM>Layout</EM> can include the symbols given in the table below.</P>
<TABLE CLASS="columns" BORDER>
<TR CLASS="heading">
<TD>
<STRONG>Symbol</STRONG>
</TD>
<TD>
<STRONG>Description</STRONG>
</TD>
</TR>
<TR>
<TD>
$text
</TD>
<TD>
user text
</TD>
</TR>
<TR>
<TD>
$type
</TD>
<TD>
message type
</TD>
</TR>
<TR>
<TD>
$app_name
</TD>
<TD>
application name
</TD>
</TR>
<TR>
<TD>
$ARGV
</TD>
<TD>
current argument name (usually a file name)
</TD>
</TR>
<TR>
<TD>
$app_context
</TD>
<TD>
current "context" (e.g. 'line ')
</TD>
</TR>
<TR>
<TD>
$.
</TD>
<TD>
current line number
</TD>
</TR>
<TR>
<TD>
$app_lineno
</TD>
<TD>
current line number (if $. is 0)
</TD>
</TR>
</TABLE>
<P>The standard message types are explained in the table below.</P>
<TABLE CLASS="columns" BORDER>
<TR CLASS="heading">
<TD>
<STRONG>Tag</STRONG>
</TD>
<TD>
<STRONG>Severity</STRONG>
</TD>
<TD>
<STRONG>Description</STRONG>
</TD>
</TR>
<TR CLASS="group">
<TD>
<STRONG>current object:</STRONG>
</TD>
<TD>
<STRONG> </STRONG>
</TD>
<TD>
<STRONG> </STRONG>
</TD>
</TR>
<TR>
<TD>
object
</TD>
<TD>
0
</TD>
<TD>
general information
</TD>
</TR>
<TR>
<TD>
warning
</TD>
<TD>
8
</TD>
<TD>
something you should know
</TD>
</TR>
<TR>
<TD>
error
</TD>
<TD>
16
</TD>
<TD>
something you should fix
</TD>
</TR>
<TR>
<TD>
abort
</TD>
<TD>
24
</TD>
<TD>
cannot precede processing
</TD>
</TR>
<TR CLASS="group">
<TD>
<STRONG>whole application:</STRONG>
</TD>
<TD>
<STRONG> </STRONG>
</TD>
<TD>
<STRONG> </STRONG>
</TD>
</TR>
<TR>
<TD>
app
</TD>
<TD>
0
</TD>
<TD>
general information
</TD>
</TR>
<TR>
<TD>
app_warning
</TD>
<TD>
10
</TD>
<TD>
something you should know
</TD>
</TR>
<TR>
<TD>
app_error
</TD>
<TD>
18
</TD>
<TD>
something you should fix
</TD>
</TR>
<TR>
<TD>
fatal
</TD>
<TD>
32
</TD>
<TD>
cannot precede processing
</TD>
</TR>
<TR CLASS="group">
<TD>
<STRONG>non-user messages:</STRONG>
</TD>
<TD>
<STRONG> </STRONG>
</TD>
<TD>
<STRONG> </STRONG>
</TD>
</TR>
<TR>
<TD>
debug
</TD>
<TD>
0
</TD>
<TD>
debugging diagnostics - ignore
</TD>
</TR>
<TR>
<TD>
failed
</TD>
<TD>
64
</TD>
<TD>
internal check failed - notify developer
</TD>
</TR>
</TABLE>
<P>All messages are output to the standard error stream with a newline appended and prefixed as follows:</P>
<UL>
<LI><EM>object</EM> messages by the current object name
<LI><EM>warning</EM>, <EM>error</EM> and <EM>abort</EM> by current object name, line number and message type
<LI><EM>app</EM> messages by the application name
<LI><EM>app_warning</EM> messages by the application name and 'warning'
<LI><EM>app_error</EM> messages by the application name and 'error'
<LI><EM>fatal</EM> messages by the application name and 'fatal'
<LI><EM>debug</EM> by application name and 'debug'
<LI><EM>failed</EM> by application name and 'internal failure'</UL>
<P>Most applications only use <EM>fatal</EM>, <EM>abort</EM>, <EM>error</EM> and <EM>warning</EM>. <EM>fatal</EM> is used when an application decides to terminate. (e.g. when an option is illegal.) <EM>abort</EM> is used when an application decides not be precede any further on the current object (e.g. too many errors encountered). <EM>error</EM> is used when a serious error is detected in processing the current object. <EM>warning</EM> is used when a minor error or possible error is detected. Typically, an application continues processing the current object when an error or warning is encountered but errors prevent further passes on the object while warnings do not.</P>
<P><STRONG><A NAME="app_app_context">app_context</A></STRONG> and <STRONG><A NAME="app_app_lineno">app_lineno</A></STRONG> are the context and line number used in error messages. <STRONG><A NAME="app_app_lineno">app_lineno</A></STRONG> is only used if $. is 0.</P>
<P><STRONG><A NAME="app_app_msg_index">%app_msg_index</A></STRONG> is the index into the message table. (Most programmers have no need for this, but it's provided in case someone does want it.)</P>
<P><STRONG><A NAME="app_app_log_strm">$app_log_strm</A></STRONG> is a stream on which all messages are logged to if it's set. If required, this stream is opened and provided by the user.</P>
<P><STRONG><A NAME="app_app_product_name">app_product_name</A></STRONG> and <STRONG><A NAME="app_app_product_version">app_product_version</A></STRONG> are the application name and version respectively. These are typically set during execution of the <EM>AppInit</EM> routine.)</P>
<P><STRONG><A NAME="app_app_trace_level">app_trace_level</A></STRONG> is the highest level of trace messages output by <STRONG><A NAME="app_AppTrace">AppTrace</A></STRONG> for each tracing group.</P>
<P><STRONG><A NAME="app_AppMsg">AppMsg</A></STRONG> outputs a message. The format of the message is determined by the <EM>type</EM> parameter which should be defined in <STRONG><A NAME="app_app_msg_table">app_msg_table</A></STRONG>. If the type is unknown, behaviour is undefined. If <EM>calltree</EM> is set, a call tree is dumped after the message is output. If <EM>log_only</EM> is set, the message is only output to the <EM>$app_log_strm</EM>, if any.</P>
<P>If a message layout includes the current line number ($.) and it is 0, <STRONG><A NAME="app_AppMsg">AppMsg</A></STRONG> uses the dot-version (e.g. ".error") of the message instead.</P>
<P>The messages output via <STRONG><A NAME="app_AppMsg">AppMsg</A></STRONG> influence the exit code returned to the operating system by <STRONG><A NAME="app_AppExit">AppExit</A></STRONG>. If you wish to influence this but not output a message, specify a <EM>type</EM> parameter without a <EM>text</EM> parameter.</P>
<P><STRONG><A NAME="app_AppMsgCounts">AppMsgCounts</A></STRONG> returns the number of each message type found. If you are interested in the message counts since a particular point in time, a starting index to begin the counting from can be specified.</P>
<P><STRONG><A NAME="app_AppMsgNextIndex">AppMsgNextIndex</A></STRONG> returns the next index to be used in the message log. The value returned can be used as the <EM>start_index</EM> parameter to the <STRONG><A NAME="app_AppMsgCounts">AppMsgCounts</A></STRONG> routine.</P>
<P><STRONG><A NAME="app_AppExit">AppExit</A></STRONG> exits the current application. If a message is specified, it is first output via <STRONG><A NAME="app_AppMsg">AppMsg</A></STRONG>. The exit code returned to the operating system is dependent on the messages output by <STRONG><A NAME="app_AppMsg">AppMsg</A></STRONG>. If <EM>calltree</EM> is set, a call tree is dumped after the message is output. If <EM>log_only</EM> is set, the message is only output to the <EM>$app_log_strm</EM>, if any.</P>
<P><STRONG><A NAME="app_AppTrace">AppTrace</A></STRONG> outputs a trace message if <EM>group</EM> tracing is supported and for that group, the trace level is >= <EM>level</EM>. The default group is called <EM>user</EM>. If <EM>log_only</EM> is set, the message is only output to the <EM>$app_log_strm</EM>, if any.</P>
<P><STRONG><A NAME="app_AppInit">AppInit</A></STRONG> processes options and checks the argument count for a perl script. The supported options are defined by @app_option. Options must occur before arguments and begin with a - character for the short format or -- for the long format. Option processing is terminated when either an argument or the -- symbol is detected. If an environment variable of the form <EM>app_name</EM>OPTS is found, options are first processed from there.</P>
<P>The expected number of arguments is derived from the format of the <EM>arguments</EM> parameter as illustrated by the table below.</P>
<TABLE CLASS="columns" BORDER>
<TR CLASS="heading">
<TD>
<STRONG>Expected</STRONG>
</TD>
<TD>
<STRONG>Format</STRONG>
</TD>
</TR>
<TR>
<TD>
0
</TD>
<TD>
""
</TD>
</TR>
<TR>
<TD>
0 or more
</TD>
<TD>
"..."
</TD>
</TR>
<TR>
<TD>
1
</TD>
<TD>
"file"
</TD>
</TR>
<TR>
<TD>
1 or more
</TD>
<TD>
"file ..."
</TD>
</TR>
<TR>
<TD>
2
</TD>
<TD>
"source destination"
</TD>
</TR>
<TR>
<TD>
2 or more
</TD>
<TD>
"pattern file ..."
</TD>
</TR>
<TR>
<TD>
2 or more
</TD>
<TD>
"file ... destination"
</TD>
</TR>
</TABLE>
<P>The pattern "..." is used to detect if a variable number of arguments is permitted. If no arguments are supplied and one or more are expected, then a concise usage message is output. If an application does not require an argument, there is no way to output only a concise usage (use the help option instead). <EM>purpose</EM> is displayed as part of the usage message. <EM>product</EM> is an optional parameter. If it is supplied and a product of that name exists in the internal product version lookup table, the product version is included in the usage too. Note that the usage message always includes a script version, regardless of whether a product version is displayed or not.</P>
<P>If <STRONG><A NAME="app_AppInit">AppInit</A></STRONG> encounters an error, it outputs a usage message and returns 0. Otherwise, it returns 1.</P>
<P><STRONG><A NAME="app_AppPrintUsage">AppPrintUsage</A></STRONG> outputs the usage header message build during the last call to <STRONG><A NAME="app_AppInit">AppInit</A></STRONG>. Only the first call to this routine (after <STRONG><A NAME="app_AppInit">AppInit</A></STRONG> is called) will print the message. This allows programmers to do additional validation after <STRONG><A NAME="app_AppInit">AppInit</A></STRONG> returns and know that only one usage header message will be output.</P>
<P><STRONG><A NAME="app_AppSectionValues">AppSectionValues</A></STRONG> converts an inifile section into a set of name-value pairs.</P>
<P><STRONG><A NAME="app_AppShowParts">AppShowParts</A></STRONG> displays the versions of components making up this application and exits. To support this facility, each library should include a line of the form:</P>
<UL>
$VERSION{__FILE__} = "x.y"</UL>
<P>Strings containing SCCS or RCS stuff have the baggage stripped. For example:</P>
<UL>
<LI>'@(#) 3.2' is displayed as '3.2'
<LI>'$Revision: 1.27 $' is displayed as '3.3'</UL>
<P><STRONG><A NAME="app_AppShowParts">AppShowParts</A></STRONG> is usually called via the '.parts' special help option. However, certain application code might have a need to call it directly.</P>
<P><STRONG><A NAME="app_AppShowCallTree">AppShowCallTree</A></STRONG> displays the call tree (excluding the call to itself). The routine is usually called indirectly:</P>
<UL>
<LI>via <STRONG><A NAME="app_AppMsg">AppMsg</A></STRONG> or <STRONG><A NAME="app_AppExit">AppExit</A></STRONG> (<EM>calltree</EM> parameter set), or
<LI>via the .calltree special help parameter</UL>
<P>Like <STRONG><A NAME="app_AppShowComponents">AppShowComponents</A></STRONG>, certain application code may wish to call <STRONG><A NAME="app_AppShowCallTree">AppShowCallTree</A></STRONG> directly.</P>
<P><STRONG><A NAME="app_AppProcess">AppProcess</A></STRONG> processes each argument on the command-line. In particular, it does the following for each argument:</P>
<UL>
<LI>if the argument is '+', processes each line of standard input as an argument
<LI>if a file matching an argument is not found, but <EM>default_ext</EM> is supplied and adding that extension results in a file being found, then <EM>default_ext</EM> is added as an extension to the argument
<LI>echos the argument to standard error if there is more than one
<LI>if $out_ext is set, opens an output file for the current argument and redirects STDOUT to it
<LI>if $log_ext is set, opens a log file for the current argument and redirects STDERR to it
<LI>calls <EM>arg_process_fn</EM>
<LI>close the output and log files, returning STDOUT and STDERR back to their initial state
<LI>calls <EM>arg_post_process_fn</EM>, if any</UL>
<P>Note that <EM>arg_post_process</EM> is optional - it is only used in scripts which need to do additional processing on an file <EM>after</EM> output streams have been closed.</P>
<P><EM>arg_process_fn</EM> has the following interface:</P>
<PRE>
$err = &arg_process_fn($arg)
</PRE>
<P><EM>arg_post_process_fn</EM> has the following interface:</P>
<PRE>
$err = &arg_post_process_fn($arg, $arg_err)
</PRE>
<P>where <EM>arg_err</EM> is the error code returned by <EM>arg_process_fn</EM>. <STRONG><A NAME="app_AppProcess">AppProcess</A></STRONG> returns the highest error code it encounters from the user processing functions it calls.</P>
<P>If you need to disable the special meaning of '+', set the <STRONG><A NAME="app_APP_STDIN_ARGS">APP_STDIN_ARGS</A></STRONG> configuration constant to an empty string. Likewise, you can change the character used by setting it to another value, although this is not recommended given the consistency implications.</P>
<HR>
<H2><A NAME="Limitations and future directions">2.2.4. Limitations and future directions</A></H2>
<P>On MS-DOS using BigPerl v2 or v3, redirecting STDOUT after <STRONG>AppProcess</STRONG> doesn't work.</P>
</DIV>
<DIV CLASS="footer">
<DIV CLASS="navigate">
<P ALIGN="Center"><A HREF="gg_sdf.html">Contents</A> | <A HREF="in_api.html">Parent Topic</A> | <A HREF="in_api.html">Previous Topic</A> | <A HREF="dict.html">Next Topic</A> <BR><A HREF="../index.html">Home</A> | <A HREF="../catalog.html">Catalog</A></P>
</DIV>
</DIV>
</BODY>
</HTML>
|