Skip to content

Commit

Permalink
Merge pull request #153 from Gottox/improve/longopts
Browse files Browse the repository at this point in the history
tools: support longopts
  • Loading branch information
Gottox committed Oct 5, 2023
2 parents 3977ff2 + 5a0a742 commit 12eda2c
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 25 deletions.
4 changes: 2 additions & 2 deletions tools/man/sqsh-cat.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ output.

.SH OPTIONS
.TP
.BR \-o " " \fIOFFSET\fR
.BR \-o " " \fIOFFSET\fR ", " \-\-offset " " \fIOFFSET\fR
skip OFFSET bytes at start of FILESYSTEM.

.TP
.BR \-v
.BR \-v ", " \-\-version
Print the version of \fBsqsh-cat\fR and exit.

.SH ARGUMENTS
Expand Down
8 changes: 4 additions & 4 deletions tools/man/sqsh-ls.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ within the archive.

.SH OPTIONS
.TP
.BR \-o " " \fIOFFSET\fR
.BR \-o " " \fIOFFSET\fR ", " \fB\-\-offset " " \fIOFFSET\fR
skip OFFSET bytes at start of FILESYSTEM.

.TP
.BR \-r
.BR \-r ", " \fB\-\-recursive
Recursively list the contents of all subdirectories within the
specified path.

.TP
.BR \-l
.BR \-l ", " \fB\-\-long
Print a long format listing of files and directories, similar to the
output of the \fBls -l\fR command.

.TP
.BR \-v
.BR \-v ", " \fB\-\-version
Print the version of \fBsqsh-ls\fR and exit.

.SH ARGUMENTS
Expand Down
7 changes: 3 additions & 4 deletions tools/man/sqsh-stat.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ type.

.SH OPTIONS
.TP
.BR \-o " " \fIOFFSET\fR
.BR \-o " " \fIOFFSET\fR ", " \-\-offset " " \fIOFFSET\fR
skip OFFSET bytes at start of FILESYSTEM.

.TP
.BR \-v
.BR \-v ", " \-\-version
Print the version of \fBsqsh-stat\fR and exit.

.SH ARGUMENTS
Expand Down Expand Up @@ -62,8 +62,7 @@ archive:

To display information about multiple paths within the squashfs archive:

.BR sqsh-stat " " /path/to/filesystem.sqsh " " /path/to/file1
/path/to/directory/
.BR sqsh-stat " " /path/to/filesystem.sqsh " " /path/to/file1 " "/path/to/dir/

To print the version of \fBsqsh-stat\fR:

Expand Down
10 changes: 7 additions & 3 deletions tools/man/sqsh-unpack.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,20 @@ the archive.

.SH OPTIONS
.TP
.BR \-o " " \fIOFFSET\fR
.BR \-v ", " \-\-version
Print the version of \fBsqsh-stat\fR and exit.

.TP
.BR \-o " " \fIOFFSET\fR ", " \fB\-\-offset " " \fIOFFSET\fR
skip OFFSET bytes at start of FILESYSTEM.

.TP
.BR \-c
.BR \-c ", " \fB\-\-chown\fR
Change the owner and group of extracted files to match the user and
group ID of the current user.

.TP
.BR \-V
.BR \-V ", " \fB\-\-verbose\fR
Print more verbose output during unpacking.

.SH ARGUMENTS
Expand Down
6 changes: 3 additions & 3 deletions tools/man/sqsh-xattr.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ The command operates in read-only mode.

.SH OPTIONS
.TP
.BR \-v
Print the version of \fBsqsh-xattr\fR.
.BR \-v ", " \-\-version
Print the version of \fBsqsh-xattr\fR and exit.

.SH ARGUMENTS
.TP
.BR \-o " " \fIOFFSET\fR
.BR \-o " " \fIOFFSET\fR ", " \-\-offset " " \fIOFFSET\fR
skip OFFSET bytes at start of FILESYSTEM.

.TP
Expand Down
10 changes: 9 additions & 1 deletion tools/src/cat.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ cat_path(struct SqshArchive *archive, char *path) {
return rv;
}

static const char opts[] = "o:vh";
static const struct option long_opts[] = {
{"offset", required_argument, NULL, 'o'},
{"version", no_argument, NULL, 'v'},
{"help", no_argument, NULL, 'h'},
{0},
};

int
main(int argc, char *argv[]) {
int rv = 0;
Expand All @@ -79,7 +87,7 @@ main(int argc, char *argv[]) {
struct SqshArchive *sqsh = NULL;
uint64_t offset = 0;

while ((opt = getopt(argc, argv, "o:vh")) != -1) {
while ((opt = getopt_long(argc, argv, opts, long_opts, NULL)) != -1) {
switch (opt) {
case 'o':
offset = strtoull(optarg, NULL, 0);
Expand Down
7 changes: 3 additions & 4 deletions tools/src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@

#define TOOLS_COMMON_H

#ifndef _DEFAULT_SOURCE
# define _DEFAULT_SOURCE
#endif
#define _GNU_SOURCE

#include "../include/sqsh.h"
#include <ctype.h>
#include <getopt.h>
#include <sqsh.h>
#include <stdlib.h>
#include <string.h>

Expand Down
12 changes: 11 additions & 1 deletion tools/src/ls.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,16 @@ ls_path(struct SqshArchive *archive, char *path) {
return rv;
}

static const char opts[] = "o:vrhl";
static const struct option long_opts[] = {
{"offset", required_argument, NULL, 'o'},
{"version", no_argument, NULL, 'v'},
{"recursive", no_argument, NULL, 'r'},
{"help", no_argument, NULL, 'h'},
{"long", no_argument, NULL, 'l'},
{0},
};

int
main(int argc, char *argv[]) {
bool has_listed = false;
Expand All @@ -262,7 +272,7 @@ main(int argc, char *argv[]) {
struct SqshArchive *archive;
uint64_t offset = 0;

while ((opt = getopt(argc, argv, "o:vrhl")) != -1) {
while ((opt = getopt_long(argc, argv, opts, long_opts, NULL)) != -1) {
switch (opt) {
case 'o':
offset = strtoull(optarg, NULL, 0);
Expand Down
10 changes: 9 additions & 1 deletion tools/src/stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,14 @@ stat_file(struct SqshArchive *archive, const char *path) {
return rv;
}

static const char opts[] = "o:vh";
static const struct option long_opts[] = {
{"offset", required_argument, NULL, 'o'},
{"version", no_argument, NULL, 'v'},
{"help", no_argument, NULL, 'h'},
{0},
};

int
main(int argc, char *argv[]) {
int rv = 0;
Expand All @@ -327,7 +335,7 @@ main(int argc, char *argv[]) {
struct SqshArchive *archive;
uint64_t offset = 0;

while ((opt = getopt(argc, argv, "o:vh")) != -1) {
while ((opt = getopt_long(argc, argv, opts, long_opts, NULL)) != -1) {
switch (opt) {
case 'o':
offset = strtoull(optarg, NULL, 0);
Expand Down
12 changes: 11 additions & 1 deletion tools/src/unpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,16 @@ extract(const char *filename, struct SqshFile *file,
return rv;
}

static const char opts[] = "co:vVh";
static const struct option long_opts[] = {
{"chown", no_argument, NULL, 'c'},
{"offset", required_argument, NULL, 'o'},
{"version", no_argument, NULL, 'v'},
{"verbose", no_argument, NULL, 'V'},
{"help", no_argument, NULL, 'h'},
{0},
};

int
main(int argc, char *argv[]) {
int rv = 0;
Expand All @@ -339,7 +349,7 @@ main(int argc, char *argv[]) {
struct SqshFile *file = NULL;
uint64_t offset = 0;

while ((opt = getopt(argc, argv, "co:vVh")) != -1) {
while ((opt = getopt_long(argc, argv, opts, long_opts, NULL)) != -1) {
switch (opt) {
case 'c':
do_chown = true;
Expand Down
10 changes: 9 additions & 1 deletion tools/src/xattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ fattr_path(struct SqshArchive *archive, char *path) {
return rv;
}

static const char opts[] = "o:vh";
static const struct option long_opts[] = {
{"offset", required_argument, NULL, 'o'},
{"version", no_argument, NULL, 'v'},
{"help", no_argument, NULL, 'h'},
{0},
};

int
main(int argc, char *argv[]) {
int rv = 0;
Expand All @@ -111,7 +119,7 @@ main(int argc, char *argv[]) {
struct SqshArchive *archive;
uint64_t offset = 0;

while ((opt = getopt(argc, argv, "o:vh")) != -1) {
while ((opt = getopt_long(argc, argv, opts, long_opts, NULL)) != -1) {
switch (opt) {
case 'o':
offset = strtoull(optarg, NULL, 0);
Expand Down

0 comments on commit 12eda2c

Please sign in to comment.