-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmkproject_mpdefaults.mata
97 lines (85 loc) · 2.12 KB
/
mkproject_mpdefaults.mata
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
mata:
mata set matastrict on
void mpdefaults::new()
{
string scalar path
path = pathsubsysdir("PERSONAL")
if(!direxists(path)) {
mkdir(path)
}
path = pathjoin(path, "m")
if (!direxists(path)) {
mkdir(path)
}
}
void mpdefaults::read_defaults(| string scalar plus)
{
string scalar fn, EOF, line, first, second
transmorphic scalar t
EOF = J(0,0,"")
t = tokeninit(" ", "", "<>")
fn = find_file("defaults", "default", plus)
mpfread(fn)
read_header("defaults")
while ((line=mpfget())!= EOF) {
reading.lnr = reading.lnr+1
tokenset(t,line)
first = tokenget(t)
second = tokenget(t)
if (first == "<project>") {
defaults.project = second
}
else if (first == "<boilerplate>") {
defaults.boilerplate = second
}
}
mpfclose(reading.fh)
header_ok(defaults.project, "project")
header_ok(defaults.boilerplate, "boilerplate")
}
void mpdefaults::write_default(string scalar what, string scalar value)
{
string scalar fn
real scalar fh
read_defaults()
header_ok(value, what)
if (what == "project") {
defaults.project = value
}
else if (what == "boilerplate") {
defaults.boilerplate = value
}
else {
errprintf("{p}" + what + " is not a valid default type{p_end}")
exit(198)
}
fn = pathjoin(pathsubsysdir("PERSONAL"), "m/mp_defaults.mpd")
unlink(fn)
fh = mpfopen(fn, "w")
reading.type = "defaults"
reading.fversion = current_version
reading.label = "user specified defaults"
reading.description = J(0,1, "")
reading.reqs = J(0,1,"")
write_header(fh)
mpfput(fh, "<project> " + defaults.project)
mpfput(fh, "<boilerplate> " + defaults.boilerplate)
mpfclose(fh)
}
void mpdefaults::reset(string scalar what)
{
string scalar def
read_defaults("PLUS")
if (what == "boilerplate") {
def = defaults.boilerplate
}
else if (what == "project") {
def = defaults.project
}
else {
errprintf("{p}only boilerplate or project allowed in reset(){p_end}")
exit(198)
}
write_default(what, def)
}
end