-
Notifications
You must be signed in to change notification settings - Fork 2
/
dscd.m
executable file
·72 lines (70 loc) · 1.97 KB
/
dscd.m
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
% Author: Carl Doersch (cdoersch at cs dot cmu dot edu)
%
% change the current working directory-struct that dswork is using.
% dspath can be an absolute or relative path. For example, if the
% ds currently contains (where '-' means a field):
%
% ds - struct1
% - struct2 - field1
% - field2
%
% Then dscd('ds.struct2') will result in a ds that looks like:
%
% ds - field1
% - field2
%
% and so a call to ds.field1 will succeed. You can no longer access
% ds.struct1 directly; you must either use dscd('.ds'), or use functions
% that recognize absolute paths.
function dscd(dspath)
global ds;
targ=dsabspath(dspath);
targ=targ(4:end);
rootpath=['ds.sys.root' targ];
varpath=dsfindvar(dspath);
if(dsfield(varpath))
if(~eval(['isstruct(' varpath ')']))
throw MException('ds:cantcd','Cannot cd into field ' dspath ' that is not a struct');
end
else
eval([rootpath '=struct();']);
end
if(dsfield(ds,'conf'))
newconf=ds.conf;
end
%try
if(dsfield(ds,'sys'))
sys=ds.sys;
ds2=rmfield(ds,'sys');
else
sys=struct();
ds2=ds;
end
if(~dsfield(sys,'currpath'))
sys.currpath='';
end
eval(['sys.root' sys.currpath '=ds2;']);
if(~dsfield(sys,['root' targ]))
%if(dsfield(sys,['savestate' sys.currpath]))
eval(['sys.root' targ '=struct();']);
%else
% throw MException('ds:cantcd','Cannot cd into fieldi ' dspath ' that does not exist.');
%end
end
eval(['ds2=sys.root' targ ';']);
eval(['sys.root' targ '=struct();']);
%if(~dsfield(['sys.savestate' targ])) %don't actually want to create a savestate, or we'll think we have it on disk
% eval(['sys.savestate' targ '=struct();']);
%end
sys.currpath=targ;
ds2.sys=sys;
ds=ds2;
%catch someexception
% ex=MException('dswork:cantcd','cannot cd')
% ex=addCause(ex,someexception);
% throw(ex);
%end
if(~dsfield(ds,'conf')&&exist('newconf','var'))
ds.conf=newconf;
end
end