-
Notifications
You must be signed in to change notification settings - Fork 6
/
pip_parseopts.ado
85 lines (67 loc) · 2 KB
/
pip_parseopts.ado
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
/*==================================================
project: Parse options of pip command to be use by mata
Author: R.Andres Castaneda
E-email: [email protected]
url:
Dependencies: The World Bank
----------------------------------------------------
Creation Date: 10 May 2023 - 17:45:53
Modification Date:
Do-file version: 01
References:
Output:
==================================================*/
/*==================================================
0: Program set up
==================================================*/
program define pip_parseopts, rclass
version 16.1
/*==================================================
1: parse subcommand
==================================================*/
gettoken subcmd opts: 0, parse(",")
if ("`subcmd'" == ",") {
local subcmd ""
}
else gettoken comma opts: opts, parse(",")
if (`"`subcmd'"' != `""') {
local returnnames "subcmd"
return local subcmd = trim(`"`subcmd'"')
}
/*==================================================
Parse options
==================================================*/
if (`"`opts'"' != "") {
return local pipoptions = `"`opts'"'
local returnnames "`returnnames' pipoptions"
}
gettoken opt opts: opts, bind
while (`"`opt'"' != `""') {
// identify type of option
if ustrregexm(`"`opt'"', "([a-zA-Z0-9_]+)\(.*") {
local optname = lower(ustrregexs(1))
}
else {
if ustrregexm(lower("`opt'"), "(^no)(.+)") {
local optname = ustrregexs(2)
}
else local optname = "`opt'"
}
// return option as local
return local `optname' = `"`opt'"'
local returnnames "`returnnames' `optname'"
local optnames "`optnames' `optname'"
// next iteration
gettoken opt opts: opts, bind
}
return local returnnames = ustrtrim("`returnnames'")
return local optnames = ustrtrim("`optnames'")
end
exit
/* End of do-file */
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
Notes:
1.
2.
3.
Version Control: