Moved argument processing to driver.

This commit is contained in:
Camilla Berglund
2012-01-23 21:56:57 +01:00
parent 2049cb92f8
commit f2012c256a
4 changed files with 47 additions and 31 deletions
+3
View File
@@ -5,6 +5,9 @@ Maintained since version 0.3.1.
2012-01-23 Camilla Berglund <elmindreda@elmindreda.org>
* duffdriver.c (process_args): Added function.
* duffdriver.c (process_path, report_clusters): Made private to duffdriver.
* duff.c duffdriver.c: Moved argument processing to duffdriver.
* duffentry.c (fill_entry): Renamed function from make_entry.
* duffdriver.c (free_entry_list): Removed function.
* duffdriver.c: Replaced doubly linked lists with List.
+2 -22
View File
@@ -195,10 +195,9 @@ static void bugs(void)
*/
int main(int argc, char** argv)
{
int i, ch;
int ch;
char* temp;
off_t limit;
char path[PATH_MAX];
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
@@ -293,26 +292,7 @@ int main(int argc, char** argv)
if (thorough_flag && header_uses_digest)
error(_("Digest (%%d) is not calculated in thorough mode (-t)"));
if (argc)
{
/* Read file names from command line */
for (i = 0; i < argc; i++)
{
kill_trailing_slashes(argv[i]);
process_path(argv[i], 0);
}
}
else
{
/* Read file names from stdin */
while (read_path(stdin, path, sizeof(path)) == 0)
{
kill_trailing_slashes(path);
process_path(path, 0);
}
}
report_clusters();
process_args(argc, argv);
exit(EXIT_SUCCESS);
}
+1 -2
View File
@@ -146,6 +146,5 @@ void print_cluster_header(const char* format,
const uint8_t* digest);
/* These are defined and documented in duffdriver.c */
void process_path(const char* path, int depth);
void report_clusters(void);
void process_args(int argc, char** argv);
+41 -7
View File
@@ -99,7 +99,7 @@ extern int header_uses_digest;
/* List of collected entries.
*/
static List files = { NULL, 0, 0 };
static List files;
/* List head for traversed directories.
*/
static Directory* directories = NULL;
@@ -112,7 +112,9 @@ static void recurse_directory(const char* path,
const struct stat* sb,
int depth);
static void process_file(const char* path, struct stat* sb);
static void process_path(const char* path, int depth);
static void report_cluster(List* duplicates, unsigned int index);
static void report_clusters(void);
/* Stat:s a file according to the specified options.
*/
@@ -275,6 +277,43 @@ static void process_file(const char* path, struct stat* sb)
fill_entry(entry_list_alloc(&files), path, sb);
}
/* Initializes the driver, processes the specified arguments and reports the
* clusters found.
*/
void process_args(int argc, char** argv)
{
size_t i;
char path[PATH_MAX];
entry_list_init(&files);
if (argc)
{
/* Read file names from command line */
for (i = 0; i < argc; i++)
{
kill_trailing_slashes(argv[i]);
process_path(argv[i], 0);
}
}
else
{
/* Read file names from stdin */
while (read_path(stdin, path, sizeof(path)) == 0)
{
kill_trailing_slashes(path);
process_path(path, 0);
}
}
report_clusters();
for (i = 0; i < files.allocated; i++)
free_entry(&files.entries[i]);
entry_list_free(&files);
}
/* Processes a path name, whether from the command line or from
* directory recursion, according to its type.
*/
@@ -401,7 +440,7 @@ static void report_cluster(List* duplicates, unsigned int index)
/* Finds and reports all duplicate clusters among the collected entries.
*/
void report_clusters(void)
static void report_clusters(void)
{
size_t i, first, second, index;
List duplicates;
@@ -443,10 +482,5 @@ void report_clusters(void)
}
entry_list_free(&duplicates);
for (i = 0; i < files.allocated; i++)
free_entry(&files.entries[i]);
entry_list_free(&files);
}