1 /* delta-window-test.h -- utilities for delta window output
3 * ====================================================================
4 * Copyright (c) 2000-2004 CollabNet. All rights reserved.
6 * This software is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at http://subversion.tigris.org/license-1.html.
9 * If newer versions of this license are posted there, you may use a
10 * newer version instead, at your option.
12 * This software consists of voluntary contributions made by many
13 * individuals. For exact contribution history, see the revision
14 * history and logs, available at http://subversion.tigris.org/.
15 * ====================================================================
18 #ifndef SVN_DELTA_WINDOW_TEST_H
19 #define SVN_DELTA_WINDOW_TEST_H
21 #define APR_WANT_STDIO
22 #define APR_WANT_STRFUNC
26 #include "svn_delta.h"
29 delta_window_size_estimate(const svn_txdelta_window_t
*window
)
37 /* Try to estimate the size of the delta. */
38 for (i
= 0, len
= 0; i
< window
->num_ops
; ++i
)
40 apr_size_t
const offset
= window
->ops
[i
].offset
;
41 apr_size_t
const length
= window
->ops
[i
].length
;
42 if (window
->ops
[i
].action_code
== svn_txdelta_new
)
44 len
+= 1; /* opcode */
45 len
+= (length
> 255 ? 2 : 1);
50 len
+= 1; /* opcode */
51 len
+= (offset
> 255 ? 2 : 1);
52 len
+= (length
> 255 ? 2 : 1);
61 delta_window_print(const svn_txdelta_window_t
*window
,
62 const char *tag
, FILE *stream
)
64 const apr_off_t len
= delta_window_size_estimate(window
);
65 apr_off_t op_offset
= 0;
71 fprintf(stream
, "%s: (WINDOW %" APR_OFF_T_FMT
, tag
, len
);
73 " (%" SVN_FILESIZE_T_FMT
74 " %" APR_SIZE_T_FMT
" %" APR_SIZE_T_FMT
")",
75 window
->sview_offset
, window
->sview_len
, window
->tview_len
);
76 for (i
= 0; i
< window
->num_ops
; ++i
)
78 apr_size_t
const offset
= window
->ops
[i
].offset
;
79 apr_size_t
const length
= window
->ops
[i
].length
;
81 switch (window
->ops
[i
].action_code
)
83 case svn_txdelta_source
:
84 fprintf(stream
, "\n%s: (%" APR_OFF_T_FMT
" SRC %" APR_SIZE_T_FMT
85 " %" APR_SIZE_T_FMT
")", tag
, op_offset
, offset
, length
);
87 case svn_txdelta_target
:
88 fprintf(stream
, "\n%s: (%" APR_OFF_T_FMT
" TGT %" APR_SIZE_T_FMT
89 " %" APR_SIZE_T_FMT
")", tag
, op_offset
, offset
, length
);
92 fprintf(stream
, "\n%s: (%" APR_OFF_T_FMT
" NEW %"
93 APR_SIZE_T_FMT
" \"", tag
, op_offset
, length
);
94 for (tmp
= offset
; tmp
< offset
+ length
; ++tmp
)
96 int const dat
= window
->new_data
->data
[tmp
];
97 if (apr_iscntrl(dat
) || !apr_isascii(dat
))
98 fprintf(stream
, "\\%3.3o", dat
& 0xff);
100 fputs("\\\\", stream
);
104 fputs("\")", stream
);
107 fprintf(stream
, "\n%s: (BAD-OP)", tag
);
112 fputs(")\n", stream
);
117 #endif /* SVN_DELTA_WINDOW_TEST_H */