mirror of https://github.com/xfarrow/dircomp.git
Indentation
This commit is contained in:
parent
244ff67d69
commit
d872d3ba96
116
dircomp.c
116
dircomp.c
|
@ -15,11 +15,11 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
struct arguments{
|
struct arguments{
|
||||||
char* directory1;
|
char* directory1;
|
||||||
char* directory2;
|
char* directory2;
|
||||||
bool r; // recursive
|
bool r; // recursive
|
||||||
bool n; // compare names only
|
bool n; // compare names only
|
||||||
bool s; // compare hashes only
|
bool s; // compare hashes only
|
||||||
bool v; // verbose (default, at the moment)
|
bool v; // verbose (default, at the moment)
|
||||||
bool h; // help
|
bool h; // help
|
||||||
};
|
};
|
||||||
|
|
||||||
struct arguments get_arguments(int, char**);
|
struct arguments get_arguments(int, char**);
|
||||||
|
@ -27,49 +27,49 @@ void print_help(void);
|
||||||
void print_files_in_directory(char*, struct arguments);
|
void print_files_in_directory(char*, struct arguments);
|
||||||
|
|
||||||
int main(int argc, char* argv[]){
|
int main(int argc, char* argv[]){
|
||||||
struct arguments arguments = get_arguments(argc, argv);
|
struct arguments arguments = get_arguments(argc, argv);
|
||||||
|
|
||||||
if(arguments.h == true)
|
if(arguments.h == true)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
print_files_in_directory("/home/user", arguments);
|
print_files_in_directory("/home/user", arguments);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct arguments get_arguments(int argc, char** argv){
|
struct arguments get_arguments(int argc, char** argv){
|
||||||
struct arguments provided_arguments = {"", "", false, false, false, true, false};
|
struct arguments provided_arguments = {"", "", false, false, false, true, false};
|
||||||
char option;
|
char option;
|
||||||
while((option = getopt(argc, argv, "rnsvh")) != -1){
|
while((option = getopt(argc, argv, "rnsvh")) != -1){
|
||||||
switch(option){
|
switch(option){
|
||||||
case 'r':
|
case 'r':
|
||||||
provided_arguments.r = true;
|
provided_arguments.r = true;
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
provided_arguments.n = true;
|
provided_arguments.n = true;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
provided_arguments.s = true;
|
provided_arguments.s = true;
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
provided_arguments.v = true;
|
provided_arguments.v = true;
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
provided_arguments.h = true;
|
provided_arguments.h = true;
|
||||||
print_help();
|
print_help();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return provided_arguments;
|
return provided_arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_help(void){
|
void print_help(void){
|
||||||
printf("Usage: dircomp directory1 directory2 [-r] [-n] [-s] [-v] [-h]\n\n");
|
printf("Usage: dircomp directory1 directory2 [-r] [-n] [-s] [-v] [-h]\n\n");
|
||||||
printf(" -r \t\t Recursive\n");
|
printf(" -r \t\t Recursive\n");
|
||||||
printf(" -n \t\t Compare file names only\n");
|
printf(" -n \t\t Compare file names only\n");
|
||||||
printf(" -s \t\t Compare file hashes only\n");
|
printf(" -s \t\t Compare file hashes only\n");
|
||||||
printf(" -v \t\t Verbose\n");
|
printf(" -v \t\t Verbose\n");
|
||||||
printf(" -h \t\t Print this help and quit\n\n");
|
printf(" -h \t\t Print this help and quit\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -77,28 +77,28 @@ void print_help(void){
|
||||||
* https://www.gnu.org/software/libc/manual/html_node/Directory-Entries.html
|
* https://www.gnu.org/software/libc/manual/html_node/Directory-Entries.html
|
||||||
*/
|
*/
|
||||||
void print_files_in_directory(char* directory, struct arguments arguments){
|
void print_files_in_directory(char* directory, struct arguments arguments){
|
||||||
printf("\nAnalyzing directory %s\n", directory);
|
printf("\nAnalyzing directory %s\n", directory);
|
||||||
DIR *d;
|
DIR *d;
|
||||||
struct dirent *dir;
|
struct dirent *dir;
|
||||||
d = opendir(directory);
|
d = opendir(directory);
|
||||||
if (d) {
|
if (d) {
|
||||||
while ((dir = readdir(d)) != NULL) {
|
while ((dir = readdir(d)) != NULL) {
|
||||||
|
|
||||||
// is file
|
// is file
|
||||||
if (dir -> d_type == DT_REG)
|
if (dir -> d_type == DT_REG)
|
||||||
{
|
{
|
||||||
if(arguments.v == true)
|
if(arguments.v == true)
|
||||||
printf("Analyzing file: %s\n", dir -> d_name);
|
printf("Analyzing file: %s\n", dir -> d_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// is directory
|
// is directory
|
||||||
if (dir -> d_type == DT_DIR)
|
if (dir -> d_type == DT_DIR)
|
||||||
{
|
{
|
||||||
if(arguments.r == true)
|
if(arguments.r == true)
|
||||||
print_files_in_directory(dir -> d_name, arguments); // todo, pass the pointer to reduce memory usage
|
print_files_in_directory(dir -> d_name, arguments); // todo, pass the pointer to reduce memory usage
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
closedir(d);
|
closedir(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue