-
Notifications
You must be signed in to change notification settings - Fork 1
/
svndumpoblit.m
94 lines (81 loc) · 2.18 KB
/
svndumpoblit.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
function svndumpoblit(exsuff, filein, fileout)
% Input handling.
if nargin < 1 || isempty(exsuff)
exsuff = {'\.mexw32', '\.mexglx', '\.mexmac', '\.mexmaci64', '\.mexa64', 'mex\.dll'};
end
if nargin < 2
[fnamein, pathin] = uigetfile('*', 'Pick a dump file');
[fnameout, pathout] = uiputfile('*.dump', 'Select output file');
else
pathin = '';
pathout = '';
fnamein = filein;
fnameout = fileout;
end
% Build regular expression.
if iscell(exsuff)
testregexp = exsuff{1};
for k = 2:length(exsuff)
testregexp = [testregexp '|' exsuff{k}];
end
else
testregexp = exsuff;
end
% Setup tokens.
revtoken = 'Revision-number:';
nodetoken = 'Node-path:';
contoken = 'Content-length';
revtoklen = length(revtoken);
nodetoklen = length(nodetoken);
contoklen = length(contoken);
% Open files.
fin = fopen([pathin fnamein]);
fout = fopen([pathout fnameout], 'w');
% Cycle through file.
saved = 0;
nodes = 0;
copyflag = true; %#ok<*NASGU> % copy while true
changeflag = false;
contlen = 0;
if fin ~= -1
dline = fgets(fin);
while ischar(dline)
% Limited parsing.
if strncmp(dline, revtoken, revtoklen)
rev = str2double(dline(revtoklen+2:end-1));
fprintf('Revision: %d\n', rev);
copyflag = true;
elseif strncmp(dline, nodetoken, nodetoklen) % test for node
if isempty(regexp(dline, testregexp, 'once')) % test for file
copyflag = true;
else
fprintf('%s...\n', dline(nodetoklen+2:end-1));
copyflag = false;
end
elseif strncmp(dline, contoken, contoklen)
contlen = str2double(dline(contoklen+2:end-1)); % bytes
end
% Copy parsed line through?
if copyflag
fwrite(fout, dline, 'char');
end
% Fast forward?
if contlen > 0
if copyflag
block = fread(fin, contlen, 'char');
fwrite(fout, block, 'char');
else
saved = saved + ceil(contlen/1000);
nodes = nodes + 1;
fseek(fin, contlen, 'cof');
end
contlen = 0;
end
% Read in next line.
dline = fgets(fin);
end % read while loop
fclose(fin);
fclose(fout);
fprintf('Saved %d kB over %d nodes\n', saved, nodes)
end % if file opened
end % main function