2 * wiggle - apply rejected patches
4 * Copyright (C) 2003 Neil Brown <neilb@cse.unsw.edu.au>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * Email: <neilb@cse.unsw.edu.au>
24 * School of Computer Science and Engineering
25 * The University of New South Wales
31 * split a stream into words or line
32 * When splitting into words we can either be approximate or precise.
33 * Precise mode includes every char in a word.
34 * Approximate mode excluses white-space words and might unite some special chars
36 * In general, a word is one of:
37 * string of [A-Za-z0-9_]
41 * A line is any string that ends with \n
43 * As a special case to allow proper aligning of multiple chunks
44 * in a patch, a word starting \0 will include 5 chars and a newline
47 * We make two passes through the stream.
48 * Firstly we count the number of item so an array can be allocated,
49 * then we store start and length of each item in the array
57 #define BITS_PER_LONG 32
61 static int split_internal(char *start
, char *end
, int type
, struct elmnt
*list
, int reverse
)
68 if (*cp
== '\0' && cp
+16 < end
&& cp
[18] == '\n') {
73 while (cp
< end
&& *cp
!= '\n')
79 if (isalnum(*cp
) || *cp
== '_') {
81 while (cp
<end
&& (isalnum(*cp
) || *cp
== '_'));
82 } else if (*cp
== ' ' || *cp
== '\t') {
84 while (cp
<end
&& (*cp
== ' ' || *cp
== '\t'));
89 if (type
!= ApproxWord
|| *start
=='\0' ||
90 (isalnum(*start
) || *start
== '_')) {
96 list
->hash
= hash_mem(start
, list
->len
, BITS_PER_LONG
);
98 list
->hash
= atoi(start
+1);
108 struct file
split_stream(struct stream s
, int type
, int reverse
)
118 cnt
= split_internal(c
, end
, type
, NULL
, reverse
);
119 /* fprintf(stderr, "cnt %d\n", cnt);*/
120 f
.list
= malloc(cnt
*sizeof(struct elmnt
));
122 f
.elcnt
= split_internal(c
, end
, type
, f
.list
+ reverse
*cnt
, reverse
);