[Important] Extend main README. Write some more man entries.

This commit is contained in:
Enrico Fraccaroli
2022-12-12 22:21:39 -05:00
parent de9daa4a85
commit 45376a2bb3
10 changed files with 94 additions and 50 deletions
+1 -1
View File
@@ -19,7 +19,7 @@ int main(int argc, char **argv)
}
// Check if `--help` is provided.
for (int i = 1; i < argc; ++i) {
if (strcmp(argv[i], "--help") == 0) {
if ((strcmp(argv[i], "--help") == 0) || (strcmp(argv[i], "-h") == 0)) {
printf("Prints the content of the given file.\n");
printf("Usage:\n");
printf(" cat <file>\n\n");
+48 -29
View File
@@ -12,24 +12,15 @@
#define CTRL_KEY(k) ((k)&0x1f)
#define BUFFER_SIZE 4096
static struct termios _original_termios, _termios;
static inline void die(const char *s)
static inline void __set_echo(bool_t active)
{
printf("error: %s\n", s);
exit(1);
}
static inline void disable_raw_mode()
{
tcsetattr(STDIN_FILENO, 0, &_original_termios);
}
static inline void enable_raw_mode()
{
tcgetattr(STDIN_FILENO, &_original_termios);
_termios = _original_termios;
_termios.c_lflag &= ~(ICANON | ECHO | IEXTEN | ISIG);
struct termios _termios;
tcgetattr(STDIN_FILENO, &_termios);
if (active) {
_termios.c_lflag |= (ICANON | ECHO);
} else {
_termios.c_lflag &= ~(ICANON | ECHO);
}
tcsetattr(STDIN_FILENO, 0, &_termios);
}
@@ -72,33 +63,61 @@ int main(int argc, char *argv[])
// Close the file descriptor.
close(fd);
enable_raw_mode();
struct termios _termios;
tcgetattr(STDIN_FILENO, &_termios);
_termios.c_lflag &= ~ISIG;
tcsetattr(STDIN_FILENO, 0, &_termios);
__set_echo(false);
int c;
do {
c = getchar();
int c = getchar();
// Return Key
if (c == '\n') {
putchar('\n');
// Break the while loop.
continue;
} else if (c == '\033') {
c = getchar();
if (c == '[') {
c = getchar();
if (c == 'D') {
puts("\033[1D");
c = getchar(); // Get the char.
if ((c == 'A') || (c == 'B')) {
pr_debug("UP\n");
} else if (c == 'D') {
pr_debug("RIGHT\n");
} else if (c == 'C') {
puts("\033[1C");
pr_debug("LEFT\n");
} else if (c == 'H') {
printf("\033[%dD", 0);
pr_debug("HOME\n");
} else if (c == 'F') {
printf("\033[%dC", 60);
pr_debug("END\n");
} else if (c == '3') {
pr_debug("NO-IDEA\n");
}
}
} else {
} else if (c == '\b') {
putchar('\b');
} else if (c == '\t') {
pr_debug("TAB\n");
} else if (c == 127) {
pr_debug("127\n");
putchar(127);
} else if (iscntrl(c)) {
if (c == CTRL('C')) {
pr_debug("CTRL(C)\n");
break;
} else if (c == CTRL('U')) {
pr_debug("CTRL(U)\n");
} else if (c == CTRL('D')) {
pr_debug("CTRL(D)\n");
}
} else if ((c > 0) && (c != '\n')) {
putchar(c);
} else {
pr_debug("Unrecognized character %02x (%c)\n", c, c);
}
} while (c != 'q');
} while (true);
disable_raw_mode();
__set_echo(true);
return 0;
}
+5 -7
View File
@@ -122,18 +122,16 @@ int main(int argc, char *argv[])
uint32_t flags = 0;
// Check the number of arguments.
for (int i = 1; i < argc; ++i) {
if (strcmp(argv[i], "--help") == 0) {
if ((strcmp(argv[i], "--help") == 0) || (strcmp(argv[i], "-h") == 0)) {
printf("List information about files inside a given directory.\n");
printf("Usage:\n");
printf(" ls [options] [directory]\n\n");
return 0;
} else if (argv[i][0] == '-') {
for (int j = 0; j < strlen(argv[i]); ++j) {
if (argv[i][j] == 'l')
bitmask_set_assign(flags, FLAG_L);
else if (argv[i][j] == 'a')
bitmask_set_assign(flags, FLAG_A);
}
if ((strcmp(argv[i], "-l") == 0) || (strcmp(argv[i], "--long") == 0))
bitmask_set_assign(flags, FLAG_L);
else if ((strcmp(argv[i], "-a") == 0) || (strcmp(argv[i], "--all") == 0))
bitmask_set_assign(flags, FLAG_A);
}
}