joachim99@52
|
1 /* Shared definitions for GNU DIFF
|
joachim99@52
|
2
|
joachim99@52
|
3 Modified for KDiff3 by Joachim Eibl 2003.
|
joachim99@53
|
4 The original file was part of GNU DIFF.
|
joachim99@52
|
5
|
joachim99@52
|
6 Copyright (C) 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1998, 2001,
|
joachim99@52
|
7 2002 Free Software Foundation, Inc.
|
joachim99@52
|
8
|
joachim99@52
|
9 GNU DIFF is free software; you can redistribute it and/or modify
|
joachim99@52
|
10 it under the terms of the GNU General Public License as published by
|
joachim99@52
|
11 the Free Software Foundation; either version 2, or (at your option)
|
joachim99@52
|
12 any later version.
|
joachim99@52
|
13
|
joachim99@52
|
14 GNU DIFF is distributed in the hope that it will be useful,
|
joachim99@52
|
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
joachim99@52
|
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
joachim99@52
|
17 GNU General Public License for more details.
|
joachim99@52
|
18
|
joachim99@52
|
19 You should have received a copy of the GNU General Public License
|
joachim99@52
|
20 along with this program; see the file COPYING.
|
joachim99@52
|
21 If not, write to the Free Software Foundation,
|
joachim99@52
|
22 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
joachim99@52
|
23
|
joachim99@53
|
24 #ifndef GNUDIFF_DIFF_H
|
joachim99@53
|
25 #define GNUDIFF_DIFF_H
|
joachim99@53
|
26
|
joachim99@52
|
27 #include "gnudiff_system.h"
|
joachim99@52
|
28
|
joachim99@52
|
29 #include <stdio.h>
|
joachim99@52
|
30
|
joachim99@52
|
31 #define TAB_WIDTH 8
|
joachim99@52
|
32
|
joachim99@53
|
33 class GnuDiff
|
joachim99@52
|
34 {
|
joachim99@53
|
35 public:
|
joachim99@52
|
36 /* What kind of changes a hunk contains. */
|
joachim99@52
|
37 enum changes
|
joachim99@52
|
38 {
|
joachim99@52
|
39 /* No changes: lines common to both files. */
|
joachim99@52
|
40 UNCHANGED,
|
joachim99@52
|
41
|
joachim99@52
|
42 /* Deletes only: lines taken from just the first file. */
|
joachim99@52
|
43 OLD,
|
joachim99@52
|
44
|
joachim99@52
|
45 /* Inserts only: lines taken from just the second file. */
|
joachim99@52
|
46 NEW,
|
joachim99@52
|
47
|
joachim99@52
|
48 /* Both deletes and inserts: a hunk containing both old and new lines. */
|
joachim99@52
|
49 CHANGED
|
joachim99@52
|
50 };
|
joachim99@52
|
51
|
joachim99@52
|
52 /* Variables for command line options */
|
joachim99@52
|
53
|
joachim99@52
|
54 enum output_style
|
joachim99@52
|
55 {
|
joachim99@52
|
56 /* No output style specified. */
|
joachim99@52
|
57 OUTPUT_UNSPECIFIED,
|
joachim99@52
|
58
|
joachim99@52
|
59 /* Default output style. */
|
joachim99@52
|
60 OUTPUT_NORMAL,
|
joachim99@52
|
61
|
joachim99@52
|
62 /* Output the differences with lines of context before and after (-c). */
|
joachim99@52
|
63 OUTPUT_CONTEXT,
|
joachim99@52
|
64
|
joachim99@52
|
65 /* Output the differences in a unified context diff format (-u). */
|
joachim99@52
|
66 OUTPUT_UNIFIED,
|
joachim99@52
|
67
|
joachim99@52
|
68 /* Output the differences as commands suitable for `ed' (-e). */
|
joachim99@52
|
69 OUTPUT_ED,
|
joachim99@52
|
70
|
joachim99@52
|
71 /* Output the diff as a forward ed script (-f). */
|
joachim99@52
|
72 OUTPUT_FORWARD_ED,
|
joachim99@52
|
73
|
joachim99@52
|
74 /* Like -f, but output a count of changed lines in each "command" (-n). */
|
joachim99@52
|
75 OUTPUT_RCS,
|
joachim99@52
|
76
|
joachim99@52
|
77 /* Output merged #ifdef'd file (-D). */
|
joachim99@52
|
78 OUTPUT_IFDEF,
|
joachim99@52
|
79
|
joachim99@52
|
80 /* Output sdiff style (-y). */
|
joachim99@52
|
81 OUTPUT_SDIFF
|
joachim99@52
|
82 };
|
joachim99@52
|
83
|
joachim99@52
|
84 /* True for output styles that are robust,
|
joachim99@52
|
85 i.e. can handle a file that ends in a non-newline. */
|
joachim99@52
|
86 #define ROBUST_OUTPUT_STYLE(S) ((S) != OUTPUT_ED && (S) != OUTPUT_FORWARD_ED)
|
joachim99@52
|
87
|
joachim99@53
|
88 enum output_style output_style;
|
joachim99@52
|
89
|
joachim99@52
|
90 /* Nonzero if output cannot be generated for identical files. */
|
joachim99@53
|
91 bool no_diff_means_no_output;
|
joachim99@52
|
92
|
joachim99@52
|
93 /* Number of lines of context to show in each set of diffs.
|
joachim99@52
|
94 This is zero when context is not to be shown. */
|
joachim99@53
|
95 lin context;
|
joachim99@52
|
96
|
joachim99@52
|
97 /* Consider all files as text files (-a).
|
joachim99@52
|
98 Don't interpret codes over 0177 as implying a "binary file". */
|
joachim99@53
|
99 bool text;
|
joachim99@52
|
100
|
joachim99@52
|
101 /* Number of lines to keep in identical prefix and suffix. */
|
joachim99@53
|
102 lin horizon_lines;
|
joachim99@52
|
103
|
joachim99@52
|
104 /* The significance of white space during comparisons. */
|
joachim99@53
|
105 enum
|
joachim99@52
|
106 {
|
joachim99@52
|
107 /* All white space is significant (the default). */
|
joachim99@52
|
108 IGNORE_NO_WHITE_SPACE,
|
joachim99@52
|
109
|
joachim99@52
|
110 /* Ignore changes due to tab expansion (-E). */
|
joachim99@52
|
111 IGNORE_TAB_EXPANSION,
|
joachim99@52
|
112
|
joachim99@52
|
113 /* Ignore changes in horizontal white space (-b). */
|
joachim99@52
|
114 IGNORE_SPACE_CHANGE,
|
joachim99@52
|
115
|
joachim99@52
|
116 /* Ignore all horizontal white space (-w). */
|
joachim99@52
|
117 IGNORE_ALL_SPACE
|
joachim99@52
|
118 } ignore_white_space;
|
joachim99@52
|
119
|
joachim99@52
|
120 /* Ignore changes that affect only blank lines (-B). */
|
joachim99@53
|
121 bool ignore_blank_lines;
|
joachim99@52
|
122
|
joachim99@52
|
123 /* Ignore changes that affect only numbers. (J. Eibl) */
|
joachim99@53
|
124 bool bIgnoreNumbers;
|
joachim99@53
|
125 bool bIgnoreWhiteSpace;
|
joachim99@52
|
126
|
joachim99@52
|
127 /* Files can be compared byte-by-byte, as if they were binary.
|
joachim99@52
|
128 This depends on various options. */
|
joachim99@53
|
129 bool files_can_be_treated_as_binary;
|
joachim99@52
|
130
|
joachim99@52
|
131 /* Ignore differences in case of letters (-i). */
|
joachim99@53
|
132 bool ignore_case;
|
joachim99@52
|
133
|
joachim99@52
|
134 /* Ignore differences in case of letters in file names. */
|
joachim99@53
|
135 bool ignore_file_name_case;
|
joachim99@52
|
136
|
joachim99@52
|
137 /* File labels for `-c' output headers (--label). */
|
joachim99@53
|
138 char *file_label[2];
|
joachim99@52
|
139
|
joachim99@52
|
140 /* Regexp to identify function-header lines (-F). */
|
joachim99@53
|
141 //struct re_pattern_buffer function_regexp;
|
joachim99@52
|
142
|
joachim99@52
|
143 /* Ignore changes that affect only lines matching this regexp (-I). */
|
joachim99@53
|
144 //struct re_pattern_buffer ignore_regexp;
|
joachim99@52
|
145
|
joachim99@52
|
146 /* Say only whether files differ, not how (-q). */
|
joachim99@53
|
147 bool brief;
|
joachim99@52
|
148
|
joachim99@52
|
149 /* Expand tabs in the output so the text lines up properly
|
joachim99@52
|
150 despite the characters added to the front of each line (-t). */
|
joachim99@53
|
151 bool expand_tabs;
|
joachim99@52
|
152
|
joachim99@52
|
153 /* Use a tab in the output, rather than a space, before the text of an
|
joachim99@52
|
154 input line, so as to keep the proper alignment in the input line
|
joachim99@52
|
155 without changing the characters in it (-T). */
|
joachim99@53
|
156 bool initial_tab;
|
joachim99@52
|
157
|
joachim99@52
|
158 /* Remove trailing carriage returns from input. */
|
joachim99@53
|
159 bool strip_trailing_cr;
|
joachim99@52
|
160
|
joachim99@52
|
161 /* In directory comparison, specify file to start with (-S).
|
joachim99@52
|
162 This is used for resuming an aborted comparison.
|
joachim99@52
|
163 All file names less than this name are ignored. */
|
joachim99@53
|
164 char const *starting_file;
|
joachim99@52
|
165
|
joachim99@52
|
166 /* Pipe each file's output through pr (-l). */
|
joachim99@53
|
167 bool paginate;
|
joachim99@52
|
168
|
joachim99@52
|
169 /* Line group formats for unchanged, old, new, and changed groups. */
|
joachim99@53
|
170 char const *group_format[CHANGED + 1];
|
joachim99@52
|
171
|
joachim99@52
|
172 /* Line formats for unchanged, old, and new lines. */
|
joachim99@53
|
173 char const *line_format[NEW + 1];
|
joachim99@52
|
174
|
joachim99@52
|
175 /* If using OUTPUT_SDIFF print extra information to help the sdiff filter. */
|
joachim99@53
|
176 bool sdiff_merge_assist;
|
joachim99@52
|
177
|
joachim99@52
|
178 /* Tell OUTPUT_SDIFF to show only the left version of common lines. */
|
joachim99@53
|
179 bool left_column;
|
joachim99@52
|
180
|
joachim99@52
|
181 /* Tell OUTPUT_SDIFF to not show common lines. */
|
joachim99@53
|
182 bool suppress_common_lines;
|
joachim99@52
|
183
|
joachim99@52
|
184 /* The half line width and column 2 offset for OUTPUT_SDIFF. */
|
joachim99@53
|
185 unsigned int sdiff_half_width;
|
joachim99@53
|
186 unsigned int sdiff_column2_offset;
|
joachim99@52
|
187
|
joachim99@52
|
188 /* String containing all the command options diff received,
|
joachim99@52
|
189 with spaces between and at the beginning but none at the end.
|
joachim99@52
|
190 If there were no options given, this string is empty. */
|
joachim99@53
|
191 char *switch_string;
|
joachim99@52
|
192
|
joachim99@52
|
193 /* Use heuristics for better speed with large files with a small
|
joachim99@52
|
194 density of changes. */
|
joachim99@53
|
195 bool speed_large_files;
|
joachim99@52
|
196
|
joachim99@52
|
197 /* Patterns that match file names to be excluded. */
|
joachim99@53
|
198 struct exclude *excluded;
|
joachim99@52
|
199
|
joachim99@52
|
200 /* Don't discard lines. This makes things slower (sometimes much
|
joachim99@52
|
201 slower) but will find a guaranteed minimal set of changes. */
|
joachim99@53
|
202 bool minimal;
|
joachim99@52
|
203
|
joachim99@52
|
204 /* Name of program the user invoked (for error messages). */
|
joachim99@53
|
205 char *program_name;
|
joachim99@52
|
206
|
joachim99@52
|
207 /* The strftime format to use for time strings. */
|
joachim99@53
|
208 char const *time_format;
|
joachim99@52
|
209
|
joachim99@52
|
210 /* The result of comparison is an "edit script": a chain of `struct change'.
|
joachim99@52
|
211 Each `struct change' represents one place where some lines are deleted
|
joachim99@52
|
212 and some are inserted.
|
joachim99@52
|
213
|
joachim99@52
|
214 LINE0 and LINE1 are the first affected lines in the two files (origin 0).
|
joachim99@52
|
215 DELETED is the number of lines deleted here from file 0.
|
joachim99@52
|
216 INSERTED is the number of lines inserted here in file 1.
|
joachim99@52
|
217
|
joachim99@52
|
218 If DELETED is 0 then LINE0 is the number of the line before
|
joachim99@52
|
219 which the insertion was done; vice versa for INSERTED and LINE1. */
|
joachim99@52
|
220
|
joachim99@52
|
221 struct change
|
joachim99@52
|
222 {
|
joachim99@52
|
223 struct change *link; /* Previous or next edit command */
|
joachim99@52
|
224 lin inserted; /* # lines of file 1 changed here. */
|
joachim99@52
|
225 lin deleted; /* # lines of file 0 changed here. */
|
joachim99@52
|
226 lin line0; /* Line number of 1st deleted line. */
|
joachim99@52
|
227 lin line1; /* Line number of 1st inserted line. */
|
joachim99@52
|
228 bool ignore; /* Flag used in context.c. */
|
joachim99@52
|
229 };
|
joachim99@52
|
230
|
joachim99@52
|
231 /* Structures that describe the input files. */
|
joachim99@52
|
232
|
joachim99@52
|
233 /* Data on one input file being compared. */
|
joachim99@52
|
234
|
joachim99@52
|
235 struct file_data {
|
joachim99@52
|
236 #if 0
|
joachim99@52
|
237 int desc; /* File descriptor */
|
joachim99@52
|
238 char const *name; /* File name */
|
joachim99@52
|
239 struct stat stat; /* File status */
|
joachim99@52
|
240 #endif
|
joachim99@52
|
241 /* Buffer in which text of file is read. */
|
joachim99@52
|
242 word *buffer;
|
joachim99@52
|
243
|
joachim99@52
|
244 /* Allocated size of buffer, in bytes. Always a multiple of
|
joachim99@52
|
245 sizeof *buffer. */
|
joachim99@52
|
246 size_t bufsize;
|
joachim99@52
|
247
|
joachim99@52
|
248 /* Number of valid bytes now in the buffer. */
|
joachim99@52
|
249 size_t buffered;
|
joachim99@52
|
250
|
joachim99@52
|
251 /* Array of pointers to lines in the file. */
|
joachim99@52
|
252 char const **linbuf;
|
joachim99@52
|
253
|
joachim99@52
|
254 /* linbuf_base <= buffered_lines <= valid_lines <= alloc_lines.
|
joachim99@52
|
255 linebuf[linbuf_base ... buffered_lines - 1] are possibly differing.
|
joachim99@52
|
256 linebuf[linbuf_base ... valid_lines - 1] contain valid data.
|
joachim99@52
|
257 linebuf[linbuf_base ... alloc_lines - 1] are allocated. */
|
joachim99@52
|
258 lin linbuf_base, buffered_lines, valid_lines, alloc_lines;
|
joachim99@52
|
259
|
joachim99@52
|
260 /* Pointer to end of prefix of this file to ignore when hashing. */
|
joachim99@52
|
261 char const *prefix_end;
|
joachim99@52
|
262
|
joachim99@52
|
263 /* Count of lines in the prefix.
|
joachim99@52
|
264 There are this many lines in the file before linbuf[0]. */
|
joachim99@52
|
265 lin prefix_lines;
|
joachim99@52
|
266
|
joachim99@52
|
267 /* Pointer to start of suffix of this file to ignore when hashing. */
|
joachim99@52
|
268 char const *suffix_begin;
|
joachim99@52
|
269
|
joachim99@52
|
270 /* Vector, indexed by line number, containing an equivalence code for
|
joachim99@52
|
271 each line. It is this vector that is actually compared with that
|
joachim99@52
|
272 of another file to generate differences. */
|
joachim99@52
|
273 lin *equivs;
|
joachim99@52
|
274
|
joachim99@52
|
275 /* Vector, like the previous one except that
|
joachim99@52
|
276 the elements for discarded lines have been squeezed out. */
|
joachim99@52
|
277 lin *undiscarded;
|
joachim99@52
|
278
|
joachim99@52
|
279 /* Vector mapping virtual line numbers (not counting discarded lines)
|
joachim99@52
|
280 to real ones (counting those lines). Both are origin-0. */
|
joachim99@52
|
281 lin *realindexes;
|
joachim99@52
|
282
|
joachim99@52
|
283 /* Total number of nondiscarded lines. */
|
joachim99@52
|
284 lin nondiscarded_lines;
|
joachim99@52
|
285
|
joachim99@52
|
286 /* Vector, indexed by real origin-0 line number,
|
joachim99@52
|
287 containing TRUE for a line that is an insertion or a deletion.
|
joachim99@52
|
288 The results of comparison are stored here. */
|
joachim99@52
|
289 bool *changed;
|
joachim99@52
|
290
|
joachim99@52
|
291 /* 1 if file ends in a line with no final newline. */
|
joachim99@52
|
292 bool missing_newline;
|
joachim99@52
|
293
|
joachim99@52
|
294 /* 1 if at end of file. */
|
joachim99@52
|
295 bool eof;
|
joachim99@52
|
296
|
joachim99@52
|
297 /* 1 more than the maximum equivalence value used for this or its
|
joachim99@52
|
298 sibling file. */
|
joachim99@52
|
299 lin equiv_max;
|
joachim99@52
|
300 };
|
joachim99@52
|
301
|
joachim99@52
|
302 /* The file buffer, considered as an array of bytes rather than
|
joachim99@52
|
303 as an array of words. */
|
joachim99@52
|
304 #define FILE_BUFFER(f) ((char *) (f)->buffer)
|
joachim99@52
|
305
|
joachim99@52
|
306 /* Data on two input files being compared. */
|
joachim99@52
|
307
|
joachim99@52
|
308 struct comparison
|
joachim99@52
|
309 {
|
joachim99@52
|
310 struct file_data file[2];
|
joachim99@52
|
311 struct comparison const *parent; /* parent, if a recursive comparison */
|
joachim99@52
|
312 };
|
joachim99@52
|
313
|
joachim99@52
|
314 /* Describe the two files currently being compared. */
|
joachim99@52
|
315
|
joachim99@53
|
316 struct file_data files[2];
|
joachim99@52
|
317
|
joachim99@52
|
318 /* Stdio stream to output diffs to. */
|
joachim99@52
|
319
|
joachim99@53
|
320 FILE *outfile;
|
joachim99@52
|
321
|
joachim99@52
|
322 /* Declare various functions. */
|
joachim99@52
|
323
|
joachim99@52
|
324 /* analyze.c */
|
joachim99@52
|
325 struct change* diff_2_files (struct comparison *);
|
joachim99@52
|
326
|
joachim99@52
|
327 /* context.c */
|
joachim99@52
|
328 void print_context_header (struct file_data[], bool);
|
joachim99@52
|
329 void print_context_script (struct change *, bool);
|
joachim99@52
|
330
|
joachim99@52
|
331 /* dir.c */
|
joachim99@52
|
332 int diff_dirs (struct comparison const *, int (*) (struct comparison const *, char const *, char const *));
|
joachim99@52
|
333
|
joachim99@52
|
334 /* ed.c */
|
joachim99@52
|
335 void print_ed_script (struct change *);
|
joachim99@52
|
336 void pr_forward_ed_script (struct change *);
|
joachim99@52
|
337
|
joachim99@52
|
338 /* ifdef.c */
|
joachim99@52
|
339 void print_ifdef_script (struct change *);
|
joachim99@52
|
340
|
joachim99@52
|
341 /* io.c */
|
joachim99@52
|
342 void file_block_read (struct file_data *, size_t);
|
joachim99@52
|
343 bool read_files (struct file_data[], bool);
|
joachim99@52
|
344
|
joachim99@52
|
345 /* normal.c */
|
joachim99@52
|
346 void print_normal_script (struct change *);
|
joachim99@52
|
347
|
joachim99@52
|
348 /* rcs.c */
|
joachim99@52
|
349 void print_rcs_script (struct change *);
|
joachim99@52
|
350
|
joachim99@52
|
351 /* side.c */
|
joachim99@52
|
352 void print_sdiff_script (struct change *);
|
joachim99@52
|
353
|
joachim99@52
|
354 /* util.c */
|
joachim99@53
|
355 //extern char const change_letter[4];
|
joachim99@53
|
356 //extern char const pr_program[];
|
joachim99@52
|
357 char *concat (char const *, char const *, char const *);
|
joachim99@52
|
358 char *dir_file_pathname (char const *, char const *);
|
joachim99@52
|
359 bool lines_differ (char const *, char const *);
|
joachim99@52
|
360 lin translate_line_number (struct file_data const *, lin);
|
joachim99@52
|
361 struct change *find_change (struct change *);
|
joachim99@52
|
362 struct change *find_reverse_change (struct change *);
|
joachim99@52
|
363 void *zalloc (size_t);
|
joachim99@52
|
364 enum changes analyze_hunk (struct change *, lin *, lin *, lin *, lin *);
|
joachim99@52
|
365 void begin_output (void);
|
joachim99@52
|
366 void debug_script (struct change *);
|
joachim99@52
|
367 void fatal (char const *) __attribute__((noreturn));
|
joachim99@52
|
368 void finish_output (void);
|
joachim99@52
|
369 void message (char const *, char const *, char const *);
|
joachim99@52
|
370 void message5 (char const *, char const *, char const *, char const *, char const *);
|
joachim99@52
|
371 void output_1_line (char const *, char const *, char const *, char const *);
|
joachim99@52
|
372 void perror_with_name (char const *);
|
joachim99@52
|
373 void pfatal_with_name (char const *) __attribute__((noreturn));
|
joachim99@52
|
374 void print_1_line (char const *, char const * const *);
|
joachim99@52
|
375 void print_message_queue (void);
|
joachim99@52
|
376 void print_number_range (char, struct file_data *, lin, lin);
|
joachim99@52
|
377 void print_script (struct change *, struct change * (*) (struct change *), void (*) (struct change *));
|
joachim99@52
|
378 void setup_output (char const *, char const *, bool);
|
joachim99@52
|
379 void translate_range (struct file_data const *, lin, lin, long *, long *);
|
joachim99@52
|
380
|
joachim99@52
|
381 /* version.c */
|
joachim99@53
|
382 //extern char const version_string[];
|
joachim99@53
|
383
|
joachim99@53
|
384 private:
|
joachim99@53
|
385 // gnudiff_analyze.cpp
|
joachim99@53
|
386 lin diag (lin xoff, lin xlim, lin yoff, lin ylim, bool find_minimal, struct partition *part);
|
joachim99@53
|
387 void compareseq (lin xoff, lin xlim, lin yoff, lin ylim, bool find_minimal);
|
joachim99@53
|
388 void discard_confusing_lines (struct file_data filevec[]);
|
joachim99@53
|
389 void shift_boundaries (struct file_data filevec[]);
|
joachim99@53
|
390 struct change * add_change (lin line0, lin line1, lin deleted, lin inserted, struct change *old);
|
joachim99@53
|
391 struct change * build_reverse_script (struct file_data const filevec[]);
|
joachim99@53
|
392 struct change* build_script (struct file_data const filevec[]);
|
joachim99@53
|
393
|
joachim99@53
|
394 // gnudiff_io.cpp
|
joachim99@53
|
395 void find_and_hash_each_line (struct file_data *current);
|
joachim99@53
|
396 void prepare_text (struct file_data *current);
|
joachim99@53
|
397 void find_identical_ends (struct file_data filevec[]);
|
joachim99@53
|
398
|
joachim99@53
|
399 // gnudiff_xmalloc.cpp
|
joachim99@53
|
400 void *xmalloc (size_t n);
|
joachim99@53
|
401 void *xcalloc (size_t n, size_t s);
|
joachim99@53
|
402 void *xrealloc(void *p, size_t n);
|
joachim99@53
|
403 char *xstrdup (const char *str);
|
joachim99@53
|
404 void xalloc_die (void);
|
joachim99@53
|
405
|
joachim99@53
|
406 inline bool isWhite( char c )
|
joachim99@53
|
407 {
|
joachim99@53
|
408 return c==' ' || c=='\t' || c=='\r';
|
joachim99@53
|
409 }
|
joachim99@53
|
410 }; // class GnuDiff
|
joachim99@53
|
411
|
joachim99@53
|
412 # define XMALLOC(Type, N_items) ((Type *) xmalloc (sizeof (Type) * (N_items)))
|
joachim99@53
|
413 # define XCALLOC(Type, N_items) ((Type *) xcalloc (sizeof (Type), (N_items)))
|
joachim99@53
|
414 # define XREALLOC(Ptr, Type, N_items) \
|
joachim99@53
|
415 ((Type *) xrealloc ((void *) (Ptr), sizeof (Type) * (N_items)))
|
joachim99@53
|
416
|
joachim99@53
|
417 /* Declare and alloc memory for VAR of type TYPE. */
|
joachim99@53
|
418 # define NEW(Type, Var) Type *(Var) = XMALLOC (Type, 1)
|
joachim99@53
|
419
|
joachim99@53
|
420 /* Free VAR only if non NULL. */
|
joachim99@53
|
421 # define XFREE(Var) \
|
joachim99@53
|
422 do { \
|
joachim99@53
|
423 if (Var) \
|
joachim99@53
|
424 free (Var); \
|
joachim99@53
|
425 } while (0)
|
joachim99@53
|
426
|
joachim99@53
|
427 /* Return a pointer to a malloc'ed copy of the array SRC of NUM elements. */
|
joachim99@53
|
428 # define CCLONE(Src, Num) \
|
joachim99@53
|
429 (memcpy (xmalloc (sizeof (*Src) * (Num)), (Src), sizeof (*Src) * (Num)))
|
joachim99@53
|
430
|
joachim99@53
|
431 /* Return a malloc'ed copy of SRC. */
|
joachim99@53
|
432 # define CLONE(Src) CCLONE (Src, 1)
|
joachim99@53
|
433
|
joachim99@53
|
434 #endif
|