298 return rl ? rl : PyErr_NoMemory(); |
298 return rl ? rl : PyErr_NoMemory(); |
299 } |
299 } |
300 |
300 |
301 static PyObject *bdiff(PyObject *self, PyObject *args) |
301 static PyObject *bdiff(PyObject *self, PyObject *args) |
302 { |
302 { |
303 PyObject *sa, *sb, *result = NULL; |
303 char *sa, *sb; |
|
304 PyObject *result = NULL; |
304 struct line *al, *bl; |
305 struct line *al, *bl; |
305 struct hunklist l = {NULL, NULL}; |
306 struct hunklist l = {NULL, NULL}; |
306 struct hunk *h; |
307 struct hunk *h; |
307 char encode[12], *rb; |
308 char encode[12], *rb; |
308 int an, bn, len = 0, la = 0, lb = 0; |
309 int an, bn, len = 0, la, lb; |
309 |
310 |
310 if (!PyArg_ParseTuple(args, "SS:bdiff", &sa, &sb)) |
311 if (!PyArg_ParseTuple(args, "t#t#:bdiff", &sa, &la, &sb, &lb)) |
311 return NULL; |
312 return NULL; |
312 |
313 |
313 an = splitlines(PyString_AsString(sa), PyString_Size(sa), &al); |
314 an = splitlines(sa, la, &al); |
314 bn = splitlines(PyString_AsString(sb), PyString_Size(sb), &bl); |
315 bn = splitlines(sb, lb, &bl); |
315 if (!al || !bl) |
316 if (!al || !bl) |
316 goto nomem; |
317 goto nomem; |
317 |
318 |
318 l = diff(al, an, bl, bn); |
319 l = diff(al, an, bl, bn); |
319 if (!l.head) |
320 if (!l.head) |
320 goto nomem; |
321 goto nomem; |
321 |
322 |
322 /* calculate length of output */ |
323 /* calculate length of output */ |
|
324 la = lb = 0; |
323 for (h = l.base; h != l.head; h++) { |
325 for (h = l.base; h != l.head; h++) { |
324 if (h->a1 != la || h->b1 != lb) |
326 if (h->a1 != la || h->b1 != lb) |
325 len += 12 + bl[h->b1].l - bl[lb].l; |
327 len += 12 + bl[h->b1].l - bl[lb].l; |
326 la = h->a2; |
328 la = h->a2; |
327 lb = h->b2; |
329 lb = h->b2; |