Skip to content
This repository has been archived by the owner on Dec 29, 2023. It is now read-only.

Commit

Permalink
prepare v17.0.0
Browse files Browse the repository at this point in the history
- Rename project to "revelio".
- Refactor macros and names used in the source code.
- Update manual description and examples.
  • Loading branch information
skippyr committed Dec 16, 2023
1 parent 961f477 commit 38e67f6
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 84 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# Reveal (rvl)
# revelio
A program that reveals info about file system entries on Linux, such as:
contents, type, permissions, ownership and modified date.

## Requirements
In order to build it, you will only need a C90 compiler, like `tcc`.
In order to build it, you will only need a C compiler, like `tcc`.

## Installation
- Compile the file `rvl.c`.
- Compile the file `revelio.c`.

```bash
mkdir -p ~/.local/bin
tcc -o ~/.local/bin/rvl rvl.c
tcc -o ~/.local/bin/revelio revelio.c
```

- Install the manual page `rvl.1`.
- Install the manual page `revelio.1`.

```bash
mkdir -p ~/.local/share/man/man1
cp rvl.1 ~/.local/share/man/man1
cp revelio.1 ~/.local/share/man/man1
```

If necessary, add the `~/.local/bin` and `~/.local/share/man/man1` directories
Expand All @@ -33,7 +33,7 @@ export MANPATH=${MANPATH}:~/.local/share/man/man1
Once installed, you can read its manual.

```bash
man rvl.1
man revelio.1
```

## Copyright
Expand Down
33 changes: 16 additions & 17 deletions rvl.1 → revelio.1
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
.TH RVL 1 v16.2.1 RVL
.TH REVELIO 1 v17.0.0 REVELIO
.SH NAME
rvl - reveals info about file system entries.
revelio - reveals info about file system entries.

.SH SYNOPSIS
rvl [\fIOPTION\fP | \fIPATH\fP]...
revelio [\fIOPTION\fP | \fIPATH\fP]...

.SH DESCRIPTION
It reveals info about each entry PATH(s) given as arguments. Use its OPTION(s)
before them for custom readings. Mix them together to obtain various results at
once.
Reveals one or multiple info types about the entry \fIPATH\fP(s) given as
arguments based on the \fIOPTION\fP(s) placed before each of them.

.SH DATA TYPE OPTIONS
Use these options before entry paths to set the data type to be retrieved. If
.SH INFO TYPE OPTIONS
Use these options before entry paths to set the info type to be retrieved. If
none is used, the one marked as default is considered.

.TP
.B \-c
(default) reveal its contents. For files, it will be their contents; For
directories, their entries; and for unfollowed symlinks, what it points to.
directories, their entries; and for unfollowed symlinks, what they point to.
.TP
.B \-t
reveals its type: regular (r), directory (d), symlink (l), character (c),
Expand Down Expand Up @@ -66,32 +65,32 @@ follows symlinks.

# reveals the entries in the current directory.
.br
rvl .
revelio .

# reveals the type of some unknown entries.
.br
rvl -t ../entry{1,2}
revelio -t ../entry{1,2}

# reveals the permissions of a file and current directory.
.br
rvl -p file.txt -op .
revelio -p file.txt -op .

# combine it with wildcards and utilities.
.br
rvl -t ~/.*
revelio -t ~/.*
.br
rvl /usr/bin | fmt
revelio /usr/bin | fmt
.br
date --date="$(rvl -md file.conf)" +"%H:%M"
date --date="$(revelio -md file.conf)" +"%H:%M"

.SH EXIT STATUS
It returns 0 on success, and 1 otherwise.

.SH SOURCE CODE
Its source code is available at <https://github.com/skippyr/rvl>.
Its source code is available at <https://github.com/skippyr/revelio>.

.SH BUGS
Report bugs at <https://github.com/skippyr/rvl/issues>.
Report bugs at <https://github.com/skippyr/revelio/issues>.

.SH SEE ALSO
.BR cat (1),
Expand Down
120 changes: 60 additions & 60 deletions rvl.c → revelio.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@
#include <time.h>
#include <unistd.h>

#define PARSEDTFLAG(flag, dtval) PARSEFLAG(flag, dt = dtval; continue);
#define PARSEITFLAG(flag, itval) PARSEFLAG(flag, it = itval; continue);
#define PARSEFLAG(flag, act)\
if (!strcmp("-" flag, argv[i])) {\
act;\
}
#define PARSELFLAG(flag, isflval) PARSEFLAG(flag, isfl = isflval; continue);
#define PARSEMETAFLAG(flag, act) PARSEFLAG(flag, act; return 0);

enum {DT_CTTS, DT_TYPE, DT_SIZE, DT_HSIZE, DT_PERMS, DT_OPERMS, DT_USR, DT_UID,
DT_GRP, DT_GID, DT_MDATE};
enum {IT_CTTS, IT_TYPE, IT_SIZE, IT_HSIZE, IT_PERMS, IT_OPERMS, IT_USR, IT_UID,
IT_GRP, IT_GID, IT_MDATE};

static int alphacmp(const void *str0, const void *str1);
static void *emalloc(size_t len);
static void die(char *fmt, ...);
static void rvl(char *path);
static void rvldir(char *path);
static void rvlgrp(char *path, struct stat *s);
static void rvlhsize(struct stat *s);
static void rvllnk(char *path);
static void rvlmdate(struct stat *s);
static void rvlperms(struct stat *s);
static void rvlreg(char *path);
static void rvltype(struct stat *s);
static void rvlusr(char *path, struct stat *s);
static void reveal(char *path);
static void revealdir(char *path);
static void revealgrp(char *path, struct stat *s);
static void revealhsize(struct stat *s);
static void reveallnk(char *path);
static void revealmdate(struct stat *s);
static void revealperms(struct stat *s);
static void revealreg(char *path);
static void revealtype(struct stat *s);
static void revealusr(char *path, struct stat *s);

static int dt = DT_CTTS;
static int it = IT_CTTS;
static int isfl = 0;

static int
Expand All @@ -59,54 +59,54 @@ die(char *fmt, ...)
{
va_list args;
va_start(args, fmt);
fprintf(stderr, "rvl: ");
fprintf(stderr, "revelio: ");
vfprintf(stderr, fmt, args);
va_end(args);
exit(1);
}

static void
rvl(char *path)
reveal(char *path)
{
struct stat s;
if (isfl ? stat(path, &s) : lstat(path, &s)) {
die("can't stat \"%s\".\n", path);
} else if (dt == DT_CTTS && S_ISREG(s.st_mode)) {
rvlreg(path);
} else if (dt == DT_CTTS && S_ISDIR(s.st_mode)) {
rvldir(path);
} else if (dt == DT_CTTS && S_ISLNK(s.st_mode)) {
rvllnk(path);
} else if (dt == DT_CTTS) {
} else if (it == IT_CTTS && S_ISREG(s.st_mode)) {
revealreg(path);
} else if (it == IT_CTTS && S_ISDIR(s.st_mode)) {
revealdir(path);
} else if (it == IT_CTTS && S_ISLNK(s.st_mode)) {
reveallnk(path);
} else if (it == IT_CTTS) {
die("can't reveal contents of \"%s\".\n", path);
} else if (dt == DT_TYPE) {
rvltype(&s);
} else if (dt == DT_SIZE) {
} else if (it == IT_TYPE) {
revealtype(&s);
} else if (it == IT_SIZE) {
printf("%ld\n", s.st_size);
} else if (dt == DT_HSIZE) {
rvlhsize(&s);
} else if (dt == DT_PERMS) {
rvlperms(&s);
} else if (dt == DT_OPERMS) {
} else if (it == IT_HSIZE) {
revealhsize(&s);
} else if (it == IT_PERMS) {
revealperms(&s);
} else if (it == IT_OPERMS) {
printf("%o\n",
s.st_mode & (S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP |
S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH |
S_IXOTH));
} else if (dt == DT_USR) {
rvlusr(path, &s);
} else if (dt == DT_UID) {
} else if (it == IT_USR) {
revealusr(path, &s);
} else if (it == IT_UID) {
printf("%u\n", s.st_uid);
} else if (dt == DT_GRP) {
rvlgrp(path, &s);
} else if (dt == DT_GID) {
} else if (it == IT_GRP) {
revealgrp(path, &s);
} else if (it == IT_GID) {
printf("%u\n", s.st_gid);
} else if (dt == DT_MDATE) {
rvlmdate(&s);
} else if (it == IT_MDATE) {
revealmdate(&s);
}
}

static void
rvldir(char *path)
revealdir(char *path)
{
DIR *d = opendir(path);
char **entnames;
Expand Down Expand Up @@ -146,7 +146,7 @@ rvldir(char *path)
}

static void
rvlgrp(char *path, struct stat *s)
revealgrp(char *path, struct stat *s)
{
char buf[255];
struct group *res;
Expand All @@ -158,7 +158,7 @@ rvlgrp(char *path, struct stat *s)
}

static void
rvlhsize(struct stat *s)
revealhsize(struct stat *s)
{
char pref[] = {'G', 'M', 'k'};
float mult[] = {1e9, 1e6, 1e3};
Expand All @@ -174,23 +174,23 @@ rvlhsize(struct stat *s)
}

static void
rvllnk(char *path)
reveallnk(char *path)
{
char buf[100];
buf[readlink(path, buf, sizeof(buf))] = 0;
printf("%s\n", buf);
}

static void
rvlmdate(struct stat *s)
revealmdate(struct stat *s)
{
char buf[29];
strftime(buf, sizeof(buf),"%a %b %d %T %Z %Y", localtime(&s->st_mtime));
printf("%s\n", buf);
}

static void
rvlperms(struct stat *s)
revealperms(struct stat *s)
{
char permchars[] = {'r', 'w', 'x'};
unsigned long permflags[] = {S_IRUSR, S_IWUSR, S_IXUSR, S_IRGRP,
Expand All @@ -205,7 +205,7 @@ rvlperms(struct stat *s)
}

static void
rvlreg(char *path)
revealreg(char *path)
{
FILE *f = fopen(path, "r");
char c;
Expand All @@ -217,15 +217,15 @@ rvlreg(char *path)
}

static void
rvltype(struct stat *s)
revealtype(struct stat *s)
{
printf("%c\n", S_ISREG(s->st_mode) ? 'r' : S_ISDIR(s->st_mode) ? 'd' :
S_ISLNK(s->st_mode) ? 'l' : S_ISCHR(s->st_mode) ? 'c' :
S_ISBLK(s->st_mode) ? 'b' : S_ISFIFO(s->st_mode) ? 'f' : 's');
}

static void
rvlusr(char *path, struct stat *s)
revealusr(char *path, struct stat *s)
{
char buf[255];
struct passwd *res;
Expand All @@ -241,20 +241,20 @@ main(int argc, char *argv[])
{
int i;
for (i = 1; i < argc; i++) {
PARSEDTFLAG("c", DT_CTTS);
PARSEDTFLAG("t", DT_TYPE);
PARSEDTFLAG("s", DT_SIZE);
PARSEDTFLAG("hs", DT_HSIZE);
PARSEDTFLAG("p", DT_PERMS);
PARSEDTFLAG("op", DT_OPERMS);
PARSEDTFLAG("u", DT_USR);
PARSEDTFLAG("ui", DT_UID);
PARSEDTFLAG("g", DT_GRP);
PARSEDTFLAG("gi", DT_GID);
PARSEDTFLAG("md", DT_MDATE);
PARSEITFLAG("c", IT_CTTS);
PARSEITFLAG("t", IT_TYPE);
PARSEITFLAG("s", IT_SIZE);
PARSEITFLAG("hs", IT_HSIZE);
PARSEITFLAG("p", IT_PERMS);
PARSEITFLAG("op", IT_OPERMS);
PARSEITFLAG("u", IT_USR);
PARSEITFLAG("ui", IT_UID);
PARSEITFLAG("g", IT_GRP);
PARSEITFLAG("gi", IT_GID);
PARSEITFLAG("md", IT_MDATE);
PARSELFLAG("ul", 0);
PARSELFLAG("fl", 1);
rvl(argv[i]);
reveal(argv[i]);
}
return 0;
}

0 comments on commit 38e67f6

Please sign in to comment.