ソースを参照

Support archiving with default utils

master
Arun Prakash Jana 5年前
コミット
8e00d74259
この署名に対応する既知のキーがデータベースに存在しません GPGキーID: A75979F35C080412
1個のファイルの変更30行の追加7行の削除
  1. +30
    -7
      src/nnn.c

+ 30
- 7
src/nnn.c ファイルの表示

@@ -135,6 +135,7 @@
#define EXEC_ARGS_MAX 8
#define SCROLLOFF 3
#define LONG_SIZE sizeof(ulong)
#define ARCHIVE_CMD_LEN 12

/* Program return codes */
#define _SUCCESS 0
@@ -474,6 +475,7 @@ static int spawn(char *file, char *arg1, char *arg2, const char *dir, uchar flag
static int (*nftw_fn)(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf);
static int dentfind(const char *fname, int n);
static void move_cursor(int target, int ignore_scrolloff);
static bool getutil(const char *util);

/* Functions */

@@ -727,6 +729,20 @@ static size_t xstrlcpy(char *dest, const char *src, size_t n)
return len;
}

static bool is_suffix(const char *str, const char *suffix)
{
if (!str || !suffix)
return FALSE;

size_t lenstr = strlen(str);
size_t lensuffix = strlen(suffix);

if (lensuffix > lenstr)
return FALSE;

return (xstrcmp(str + (lenstr - lensuffix), suffix) == 0);
}

/*
* The poor man's implementation of memrchr(3).
* We are only looking for '/' in this program.
@@ -1263,6 +1279,18 @@ finish:
return ret;
}

static void get_archive_cmd(char *cmd, char *archive)
{
if (getutil(utils[ATOOL]))
xstrlcpy(cmd, "atool -a", ARCHIVE_CMD_LEN);
else if (getutil(utils[BSDTAR]))
xstrlcpy(cmd, "bsdtar -cvf", ARCHIVE_CMD_LEN);
else if (is_suffix(archive, ".zip"))
xstrlcpy(cmd, "zip -r", ARCHIVE_CMD_LEN);
else
xstrlcpy(cmd, "tar -cvf", ARCHIVE_CMD_LEN);
}

static void archive_selection(const char *cmd, const char *archive, const char *curpath)
{
char *buf = (char *)malloc(CMD_LEN_MAX * sizeof(char));
@@ -4141,14 +4169,9 @@ nochange:
switch (sel) {
case SEL_ARCHIVE:
{
char cmd[] = "bsdtar -cf";
char cmd[ARCHIVE_CMD_LEN];

if (getutil(utils[ATOOL]))
xstrlcpy(cmd, "atool -a", 10);
else if (!getutil(utils[BSDTAR])) {
printwait(messages[UTIL_MISSING], &presel);
goto nochange;
}
get_archive_cmd(cmd, tmp);

(r == 'y' || r == 'Y') ? archive_selection(cmd, tmp, path)
: spawn(cmd, tmp, dents[cur].name,


読み込み中…
キャンセル
保存