Skip to content

Commit

Permalink
Add version info
Browse files Browse the repository at this point in the history
  • Loading branch information
Sigmanificient committed Apr 19, 2024
1 parent 0fdc477 commit 00436f8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
17 changes: 16 additions & 1 deletion src/ls/ls_main.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "ls.h"

#define NAME "ls (canoutils)"
#define VERSION "1.0.0"
#define AUTHOR "Yohann Boniface (Sigmanificient)"

#define print_version() \
do { \
printf("%s\nversion: %s\nby: %s\n", NAME, VERSION, AUTHOR); \
} while (0)

static const char FLAGLIST[] = "alRdrt";
static char DEFAULT_LOCATION[] = ".";

Expand Down Expand Up @@ -47,9 +58,13 @@ static bool list_dirs(dirbuff_t *db, int argc, char **argv, char flags) {

int main(int argc, char **argv) {
dirbuff_t db = {.size = MIN_ALLOCATED_ENTRY};
char flags = compose_flaglist(argc, argv);
char flags;
int err = 0;

for (int i = 0; argv[i] != NULL; i++)
if (!strcmp(argv[i], "--version"))
return printf(VERSION), EXIT_SUCCESS;
flags = compose_flaglist(argc, argv);
db.entries = malloc(db.size * sizeof(*db.entries));
if (db.entries == NULL)
return EXIT_FAILURE;
Expand Down
24 changes: 13 additions & 11 deletions src/rmdir/rmdir.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include <dirent.h>
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <dirent.h>
#include <string.h>
#include <sys/stat.h>
#include <errno.h>

#define NAME "rmdir (canoutils)"
#define VERSION "1.0.0"
Expand Down Expand Up @@ -41,10 +41,11 @@ int rm_dir(char *dirname) {
int n = 0;
struct dirent *dent;
while ((dent = readdir(dir)) != NULL) {
if (++n > 2) break;
if (++n > 2)
break;
}
closedir(dir);

if (n <= 2) { // Directory is empty (the two entries are '.' and '..')
if (remove(dirname) != 0) {
fprintf(stderr, "Failed to remove '%s': %s\n", dirname, strerror(errno));
Expand All @@ -61,7 +62,8 @@ int rm_dir(char *dirname) {

int main(int argc, char **argv) {
if (argc <= 1) {
fprintf(stderr, "Not enough arguments.\nSee rmdir --help for more information.\n");
fprintf(stderr,
"Not enough arguments.\nSee rmdir --help for more information.\n");
return 1;
}

Expand All @@ -78,10 +80,11 @@ int main(int argc, char **argv) {
return rm_dir(argv[1]);
}

for (int i = 1; i < argc-1; ++i) {
for (int i = 1; i < argc - 1; ++i) {
if (strcmp(argv[i], "-p") == 0 || strcmp(argv[i], "--parents") == 0) {
parents = true;
} else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) {
} else if (strcmp(argv[i], "-v") == 0 ||
strcmp(argv[i], "--verbose") == 0) {
verbose = true;
} else if (strcmp(argv[i], "--ignore-fail-on-non-empty") == 0) {
ignore_fail = true;
Expand All @@ -92,7 +95,6 @@ int main(int argc, char **argv) {
// TODO: Implement -p|--parents flag
return 0;
} else {
return rm_dir(argv[argc-1]);
return rm_dir(argv[argc - 1]);
}
}

0 comments on commit 00436f8

Please sign in to comment.