version 1.49, 2007/03/01 21:48:32 |
version 1.50, 2007/05/29 18:24:56 |
|
|
#include <unistd.h> |
#include <unistd.h> |
|
|
#include "diff.h" |
#include "diff.h" |
|
#include "xmalloc.h" |
|
|
int aflag, bflag, dflag, iflag, lflag, Nflag, Pflag, pflag, rflag; |
int aflag, bflag, dflag, iflag, lflag, Nflag, Pflag, pflag, rflag; |
int sflag, tflag, Tflag, wflag; |
int sflag, tflag, Tflag, wflag; |
|
|
exit(status); |
exit(status); |
} |
} |
|
|
void * |
|
emalloc(size_t n) |
|
{ |
|
void *p; |
|
|
|
if ((p = malloc(n)) == NULL) |
|
err(2, NULL); |
|
return (p); |
|
} |
|
|
|
void * |
|
erealloc(void *p, size_t n) |
|
{ |
|
void *q; |
|
|
|
if ((q = realloc(p, n)) == NULL) |
|
err(2, NULL); |
|
return (q); |
|
} |
|
|
|
int |
|
easprintf(char **ret, const char *fmt, ...) |
|
{ |
|
int len; |
|
va_list ap; |
|
|
|
va_start(ap, fmt); |
|
len = vasprintf(ret, fmt, ap); |
|
va_end(ap); |
|
|
|
if (len == -1) |
|
err(2, NULL); |
|
return (len); |
|
} |
|
|
|
void |
void |
set_argstr(char **av, char **ave) |
set_argstr(char **av, char **ave) |
{ |
{ |
|
|
char **ap; |
char **ap; |
|
|
argsize = 4 + *ave - *av + 1; |
argsize = 4 + *ave - *av + 1; |
diffargs = emalloc(argsize); |
diffargs = xmalloc(argsize); |
strlcpy(diffargs, "diff", argsize); |
strlcpy(diffargs, "diff", argsize); |
for (ap = av + 1; ap < ave; ap++) { |
for (ap = av + 1; ap < ave; ap++) { |
if (strcmp(*ap, "--") != 0) { |
if (strcmp(*ap, "--") != 0) { |
|
|
while ((buf = fgetln(fp, &len)) != NULL) { |
while ((buf = fgetln(fp, &len)) != NULL) { |
if (buf[len - 1] == '\n') |
if (buf[len - 1] == '\n') |
len--; |
len--; |
pattern = emalloc(len + 1); |
pattern = xmalloc(len + 1); |
memcpy(pattern, buf, len); |
memcpy(pattern, buf, len); |
pattern[len] = '\0'; |
pattern[len] = '\0'; |
push_excludes(pattern); |
push_excludes(pattern); |
|
|
{ |
{ |
struct excludes *entry; |
struct excludes *entry; |
|
|
entry = emalloc(sizeof(*entry)); |
entry = xmalloc(sizeof(*entry)); |
entry->pattern = pattern; |
entry->pattern = pattern; |
entry->next = excludes_list; |
entry->next = excludes_list; |
excludes_list = entry; |
excludes_list = entry; |
|
|
{ |
{ |
size_t len; |
size_t len; |
|
|
if (ignore_pats == NULL) { |
if (ignore_pats == NULL) |
/* XXX: estrdup */ |
ignore_pats = xstrdup(pattern); |
len = strlen(pattern) + 1; |
else { |
ignore_pats = emalloc(len); |
|
strlcpy(ignore_pats, pattern, len); |
|
} else { |
|
/* old + "|" + new + NUL */ |
/* old + "|" + new + NUL */ |
len = strlen(ignore_pats) + strlen(pattern) + 2; |
len = strlen(ignore_pats) + strlen(pattern) + 2; |
ignore_pats = erealloc(ignore_pats, len); |
ignore_pats = xrealloc(ignore_pats, 1, len); |
strlcat(ignore_pats, "|", len); |
strlcat(ignore_pats, "|", len); |
strlcat(ignore_pats, pattern, len); |
strlcat(ignore_pats, pattern, len); |
} |
} |