1 /************************************************************************/
2 /*									*/
3 /*  Keep a trace of modifications to a document.			*/
4 /*									*/
5 /************************************************************************/
6 
7 #   ifndef	DOC_EDIT_TRACE_H
8 #   define	DOC_EDIT_TRACE_H
9 
10 #   include	<utilPagedList.h>
11 #   include	<utilMemoryBuffer.h>
12 #   include	<docEditRange.h>
13 #   include	<utilMD5.h>
14 #   include	<sioGeneral.h>
15 
16 struct EditStep;
17 struct BufferDocument;
18 
19 typedef struct TraceStep
20     {
21 			/**
22 			 *  The command executed in this step;
23 			 */
24     int			tsCommand;
25 
26 			/**
27 			 *  The kind of field that is affected.
28 			 */
29     int			tsFieldKind;
30 
31 			/**
32 			 *  The offset in the trace file where trace of the
33 			 *  command starts;
34 			 */
35     long		tsTraceOffset;
36     long		tsByteCount;
37     } TraceStep;
38 
39 typedef struct EditTrace
40     {
41 			/**
42 			 *  A list of trace steps;
43 			 */
44     PagedList		etTraceSteps;
45 			/**
46 			 *  Size of the list.
47 			 */
48     int			etCount;
49 			/**
50 			 *  Current position (<= etCount because of undos)
51 			 */
52     int			etIndex;
53 			/**
54 			 *  The position in the trace where the digest of the
55 			 *  base version is stored.
56 			 */
57     int			etBase;
58 
59 			/**
60 			 *  True if this is a recovery.
61 			 */
62     unsigned char	etIsRecovery;
63 
64 			/**
65 			 *   The current step. Only used while stepping
66 			 *   forward.
67 			 */
68     TraceStep		etThisStep;
69 
70 			/**
71 			 *  The name of the trace file. It is derived from the
72 			 *  name of the document.
73 			 */
74     MemoryBuffer	etTraceFileName;
75     int			etTraceFileHandle;
76     int			etTraceStatus;
77 #			define TRACING_NO	'-'
78 
79 #			define TRACING_ACCES	'a'
80 #			define TRACING_EXIST	'e'
81 
82 #			define TRACING_RELATIVE	'R'
83 #			define TRACING_TEMP	'T'
84 #			define TRACING_ANON	'A'
85 
86 			/**
87 			 *   Are we currently typing?
88 			 */
89     int			etTyping;
90 #			define	TYPING_NO	'-'
91 #			define	TYPING_START	'+'
92 #			define	TYPING_BLANK	' '
93 #			define	TYPING_NONBLANK	'X'
94 
95 			/**
96 			 *   The range we are typing
97 			 */
98     EditRange		etTypingOldRange;
99 
100 			/**
101 			 *   The MD5 digest of the last load/save of the
102 			 *   document.
103 			 */
104     char		etBaseMD5Digest64[MD5_DIGEST_SIZE_BASE64];
105     } EditTrace;
106 
107 typedef int (*HandleEditStep)(	const TraceStep *	ts,
108 				const struct EditStep *	es,
109 				int			step,
110 				void *			through );
111 
112 # define docEditIsTraced( s ) \
113 		    ( (s) == TRACING_RELATIVE	|| \
114 		      (s) == TRACING_TEMP	|| \
115 		      (s) == TRACING_ANON )
116 
117 /************************************************************************/
118 /*									*/
119 /*  Routine declarations.						*/
120 /*									*/
121 /************************************************************************/
122 
123 extern void docInitTraceStep(	TraceStep *	ts );
124 
125 extern void docInitEditTrace(	EditTrace *	et );
126 extern void docCleanEditTrace(	EditTrace *	et );
127 
128 extern int docEditTraceSetTempName(	EditTrace *		et,
129 					const char *		extension );
130 
131 extern int docEditTraceSetDocumentName(	EditTrace *		et,
132 					const MemoryBuffer *	documentName,
133 					const char *		extension );
134 
135 extern int docEditTraceOpenTrace(	EditTrace *		et,
136 					int			restart,
137 					int			exclusive );
138 
139 extern int docEditGetTraceStep(	const TraceStep **		pTs,
140 				int *				pIsRepeat,
141 				int				direction,
142 				const EditTrace *		et,
143 				int				from );
144 
145 extern int docRtfScanEditTrace(	const EditTrace *		et,
146 				SimpleInputStream *		sis,
147 				HandleEditStep			handleStep,
148 				void *				through,
149 				int				readOld,
150 				int				readNew,
151 				const struct BufferDocument *	bdRef );
152 
153 extern int docEditTraceTryRelative(	EditTrace *		et,
154 					const MemoryBuffer *	documentName,
155 					const char *		extension );
156 
157 extern int docEditTraceTryTemp(		EditTrace *		et,
158 					const char *		extension );
159 
160 extern int docEditTraceTryAnon(		EditTrace *		et,
161 					const char *		extension );
162 
163 #    endif	/*  DOC_EDIT_TRACE_H	*/
164