2 Copyright (C) 2002 Ben Kibbey <bjk@arbornet.org>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <sys/types.h>
43 FILES
*filecmp(const char *filename
, FILES
* list
)
47 for (cur
= list
; cur
; cur
= next
) {
53 if (strcmp(filename
, cur
->filename
) == 0)
60 int duplicate(const char *filename
, FILES
* list
)
64 for (cur
= list
; cur
; cur
= next
) {
70 if (strcmp(filename
, cur
->filename
) == 0)
77 FILES
*loadfile(const char *filename
, FILES
* oldlist
)
80 char *cp
, buf
[LINE_MAX
];
81 int err
, oldtotal
= total
;
86 if (oldlist
&& (err
= is_file(filenamelist
)) != 0) {
88 logit("%s: %s", filenamelist
, strerror(errno
));
90 logit("%s: Not a regular file", filenamelist
);
95 if (!(fp
= fopen(filename
, "r"))) {
97 logit("%s: %s", filenamelist
, strerror(errno
));
99 warn("%s", filenamelist
);
104 fhead
= Calloc(1, sizeof(FILES
));
107 while ((cp
= fgets(buf
, sizeof(buf
), fp
)) != NULL
) {
110 char tmp
[FILENAME_MAX
];
112 cp
[strlen(cp
) - 1] = 0;
113 cp
= fullpath(wd
, cp
, tmp
, sizeof(tmp
));
115 /* make sure there are no duplicate files in the list*/
116 if (duplicate(cp
, fhead
)) {
120 logit("%s: Duplicate file", cp
);
122 warnx("%s: Duplicate file", cp
);
127 /* keep old stat() and bit data if filenames are the same*/
129 if ((cur
= filecmp(cp
, oldlist
)) != NULL
) {
130 bcopy(cur
, fptr
, sizeof(FILES
));
131 fptr
->filename
= strdup(cur
->filename
);
132 fptr
->next
= Calloc(1, sizeof(FILES
));
140 if (STAT(cp
, &st
) == -1) {
142 logit("%s: %s", cp
, strerror(errno
));
149 if (S_ISDIR(st
.st_mode
) && cp
[strlen(cp
) - 1] == '/') {
150 fptr
= recurse_directory(fptr
, cp
, (oldlist
) ? 1 : 0);
154 fptr
= add_file(fptr
, cp
, st
, (oldlist
) ? 1 : 0);
161 if (!total
&& oldlist
) {
163 logit("%s: No files", filenamelist
);