Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F175709506
D57322.id178882.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D57322.id178882.diff
View Options
diff --git a/bin/ls/ls.h b/bin/ls/ls.h
--- a/bin/ls/ls.h
+++ b/bin/ls/ls.h
@@ -62,6 +62,8 @@
#ifdef COLORLS
extern int f_color; /* add type in color for non-regular files */
#endif
+extern int f_dired; /* dired mode */
+extern off_t dired_begin; /* begin offset of the current file */
typedef struct {
FTSENT *list;
diff --git a/bin/ls/ls.c b/bin/ls/ls.c
--- a/bin/ls/ls.c
+++ b/bin/ls/ls.c
@@ -96,7 +96,8 @@
enum {
BIN_OPT = CHAR_MAX,
COLOR_OPT,
- GROUP_OPT
+ GROUP_OPT,
+ DIRED_OPT,
};
static const struct option long_opts[] =
@@ -104,6 +105,7 @@
{"color", optional_argument, NULL, COLOR_OPT},
{"group-directories", optional_argument, NULL, GROUP_OPT},
{"group-directories-first", no_argument, NULL, GROUP_OPT},
+ {"dired", no_argument, NULL, DIRED_OPT},
{NULL, no_argument, NULL, 0}
};
@@ -162,6 +164,8 @@
char *enter_bold; /* ANSI sequence to set color to bold mode */
char *enter_underline; /* ANSI sequence to enter underline mode */
#endif
+int f_dired;
+off_t dired_begin;
static int rval;
@@ -276,7 +280,7 @@
colorflag = COLORFLAG_AUTO;
#endif
while ((ch = getopt_long(argc, argv,
- "+1ABCD:FGHILPRSTUWXZabcdfghiklmnopqrstuvwxy,", long_opts,
+ "+1ABCD:FGHILPRSTUWXZNabcdfghiklmnopqrstuvwxy,", long_opts,
NULL)) != -1) {
switch (ch) {
/*
@@ -486,6 +490,12 @@
#else
warnx("color support not compiled in");
#endif
+ case DIRED_OPT:
+ f_longform = 1;
+ f_singlecol = 0;
+ f_stream = 0;
+ f_dired = 1;
+ break;
default:
case '?':
usage();
@@ -657,6 +667,8 @@
if ((ftsp =
fts_open(argv, options, f_nosort ? NULL : mastercmp)) == NULL)
err(1, "fts_open");
+ if (f_dired)
+ dired_begin = ftell(stdout);
/*
* We ignore errors from fts_children here since they will be
diff --git a/bin/ls/print.c b/bin/ls/print.c
--- a/bin/ls/print.c
+++ b/bin/ls/print.c
@@ -36,6 +36,7 @@
#include <sys/stat.h>
#include <sys/acl.h>
+#include <assert.h>
#include <err.h>
#include <errno.h>
#include <fts.h>
@@ -204,6 +205,8 @@
FTSENT *p;
NAMES *np;
char buf[20];
+ off_t *offsets;
+ int offsets_idx = 0;
#ifdef COLORLS
int color_printed = 0;
#endif
@@ -220,6 +223,9 @@
}
}
+ if (f_dired)
+ offsets = calloc(sizeof(*offsets), dp->entries * 2);
+
for (p = dp->list; p; p = p->fts_link) {
if (IS_NOPRINT(p))
continue;
@@ -258,7 +264,11 @@
if (f_color)
color_printed = colortype(sp->st_mode);
#endif
+ if (f_dired)
+ offsets[offsets_idx++] = ftell(stdout);
(void)printname(p->fts_name);
+ if (f_dired)
+ offsets[offsets_idx++] = ftell(stdout);
#ifdef COLORLS
if (f_color && color_printed)
endcolor(0);
@@ -269,6 +279,16 @@
printlink(p);
(void)putchar('\n');
}
+
+ if (f_dired) {
+ assert(offsets_idx == dp->entries * 2);
+ printf("//DIRED//");
+ for (offsets_idx = 0; offsets_idx < dp->entries * 2;
+ offsets_idx++)
+ printf(" %ld", offsets[offsets_idx] - dired_begin);
+ putchar('\n');
+ free(offsets);
+ }
}
void
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Oct 13, 4:46 PM (3 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
40761724
Default Alt Text
D57322.id178882.diff (2 KB)
Attached To
Mode
D57322: ls: Support dired mode
Attached
Detach File
Event Timeline
Log In to Comment