Skip to content

Commit

Permalink
Use shared macro for print_version
Browse files Browse the repository at this point in the history
  • Loading branch information
Sigmanificient committed Apr 19, 2024
1 parent 2fbc191 commit 96a628d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion commons.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CFLAGS := @$/compile_flags.txt

CFLAGS += -ffunction-sections -fdata-sections
CFLAGS += -Wp,-U_FORTIFY_SOURCE
CFLAGS += -iquote src
CFLAGS += -iquote $/src

LDFLAGS := -fwhole-program -flto
LDFLAGS += -Wl,--gc-sections
Expand Down
5 changes: 1 addition & 4 deletions src/echo/echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
#define VERSION "1.0.0"
#define AUTHOR "Hoorad Farrokh (proh14)"

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

int isoctal(int c) { return (c >= '0' && c <= '7'); }

Expand Down
11 changes: 5 additions & 6 deletions src/ls/ls_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
#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)
#include "version_info.h"

static const char FLAGLIST[] = "alRdrt";
static char DEFAULT_LOCATION[] = ".";
Expand Down Expand Up @@ -62,8 +59,10 @@ int main(int argc, char **argv) {
int err = 0;

for (int i = 0; argv[i] != NULL; i++)
if (!strcmp(argv[i], "--version"))
return printf(VERSION), EXIT_SUCCESS;
if (!strcmp(argv[i], "--version")) {
print_version();
return EXIT_SUCCESS;
}
flags = compose_flaglist(argc, argv);
db.entries = malloc(db.size * sizeof(*db.entries));
if (db.entries == NULL)
Expand Down
5 changes: 1 addition & 4 deletions src/rmdir/rmdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
#define VERSION "1.0.0"
#define AUTHOR "tim-tm"

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

bool ignore_fail = false;
bool parents = false;
Expand Down
13 changes: 13 additions & 0 deletions src/version_info.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef VERSION_INFO_H
#define VERSION_INFO_H

#if !defined(NAME) || !defined(VERSION) || !defined(AUTHOR)
#error "missing NAME, VERSION or AUTHOR definition"
#endif

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

#endif

0 comments on commit 96a628d

Please sign in to comment.