-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnwsw_PromptExample.php
executable file
·62 lines (48 loc) · 1.65 KB
/
nwsw_PromptExample.php
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
<?php
/*******************************************************************************
nwsw_PromptExample.php Version 1.01
This script demonstrates the prompting mechanism in NWC2 User Tools.
Copyright © 2006 by NoteWorthy Software, Inc.
All Rights Reserved
HISTORY:
================================================================================
[2006-05-12] Version 1.01: Code format cleanup
[2004-12-12] Version 1.00: Initial release
*******************************************************************************/
require_once("lib/nwc2clips.inc");
$clip = new NWC2Clip('php://stdin');
$raw_argv = print_r($argv,true);
echo <<<___EOTEXT
This script demonstrates one method for passing command line
arguments into a user tool. This demonstration accepts three
options, each of which are prompted on the scripts behalf
by NWC2.
The built-in argc and argv variables are set as follows:
\$argc = $argc
\$argv = $raw_argv
The result of the example processing of the options is
shown below. To see how this was done, simply look at
the source for this script.
___EOTEXT;
// Below is an example of one technique for evaluating the arguments passed
// to the script
$opts = array();
foreach ($argv as $k => $v) {
if (!$k) continue;
if (preg_match('/^\/(opt[1-3])\=(.*)$/',$v,$m)) {
$optname = $m[1];
$optvalue = $m[2];
$opts[$optname] = $optvalue;
}
}
if (isset($opts["opt1"])) {
echo "\nOption 1 is set with the following data: $opts[opt1]\n";
}
if (isset($opts["opt2"])) {
echo "\nOption 2 is set with the following data: $opts[opt2]\n";
}
if (isset($opts["opt3"])) {
echo "\nOption 3 is set with the following data: $opts[opt3]\n";
}
exit(NWC2RC_REPORT);
?>