summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorKjell Wooding <kjell@cvs.openbsd.org>2005-10-14 06:41:48 +0000
committerKjell Wooding <kjell@cvs.openbsd.org>2005-10-14 06:41:48 +0000
commit27ade458e6688f238d0be65a6e9340e42c984aac (patch)
tree451cfb6c8460cadeeef1a19d39df7abfa9973570 /usr.bin
parent7bb21effa448a7201adeea9244dcdf9aa9caf151 (diff)
move the dired routines into dired.c where they belong.
ok cloder@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mg/def.h7
-rw-r--r--usr.bin/mg/dired.c94
-rw-r--r--usr.bin/mg/fileio.c87
3 files changed, 96 insertions, 92 deletions
diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h
index 724fe4dac4b..aa12298e260 100644
--- a/usr.bin/mg/def.h
+++ b/usr.bin/mg/def.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: def.h,v 1.70 2005/10/13 20:23:01 kjell Exp $ */
+/* $OpenBSD: def.h,v 1.71 2005/10/14 06:41:47 kjell Exp $ */
/* This file is in the public domain. */
@@ -321,6 +321,7 @@ void dirinit(void);
int changedir(int, int);
int showcwdir(int, int);
+#ifndef NO_DIRED
/* dired.c */
int dired(int, int);
int d_otherwindow(int, int);
@@ -334,6 +335,8 @@ int d_del(int, int);
int d_rename(int, int);
int d_shell_command(int, int);
int d_create_directory(int, int);
+BUFFER *dired_(char *);
+#endif /* !NO_DIRED */
/* file.c X */
int fileinsert(int, int);
@@ -426,8 +429,6 @@ int fbackupfile(const char *);
char *adjustname(const char *);
char *startupfile(char *);
int copy(char *, char *);
-BUFFER *dired_(char *);
-int d_makename(LINE *, char *, int);
LIST *make_file_list(char *);
int fisdir(const char *);
diff --git a/usr.bin/mg/dired.c b/usr.bin/mg/dired.c
index 77c6313de71..23849227396 100644
--- a/usr.bin/mg/dired.c
+++ b/usr.bin/mg/dired.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dired.c,v 1.23 2005/10/13 05:47:44 kjell Exp $ */
+/* $OpenBSD: dired.c,v 1.24 2005/10/14 06:41:47 kjell Exp $ */
/* This file is in the public domain. */
@@ -12,6 +12,7 @@
#include <sys/stat.h>
#include <sys/wait.h>
+#include <ctype.h>
#include <signal.h>
#include <fcntl.h>
#include <errno.h>
@@ -19,7 +20,8 @@
#ifndef NO_DIRED
-void dired_init(void);
+void dired_init(void);
+static int d_makename(LINE *, char *, int);
extern struct keymap_s helpmap, cXmap, metamap;
@@ -386,7 +388,6 @@ d_rename(int f, int n)
bp = dired_(curbp->b_fname);
return (showbuffer(bp, curwp, WFHARD | WFMODE));
}
-#endif
void
reaper(int signo __attribute__((unused)))
@@ -512,3 +513,90 @@ d_create_directory(int f, int n)
bp = dired_(curbp->b_fname);
return (showbuffer(bp, curwp, WFHARD | WFMODE));
}
+
+#define NAME_FIELD 8
+
+static int
+d_makename(LINE *lp, char *fn, int len)
+{
+ int i;
+ char *p, *ep;
+
+ strlcpy(fn, curbp->b_fname, len);
+ if ((p = lp->l_text) == NULL)
+ return (ABORT);
+ ep = lp->l_text + llength(lp);
+ p++; /* skip action letter, if any */
+ for (i = 0; i < NAME_FIELD; i++) {
+ while (p < ep && isspace(*p))
+ p++;
+ while (p < ep && !isspace(*p))
+ p++;
+ while (p < ep && isspace(*p))
+ p++;
+ if (p == ep)
+ return (ABORT);
+ }
+ strlcat(fn, p, len);
+ return ((lgetc(lp, 2) == 'd') ? TRUE : FALSE);
+}
+
+/*
+ * XXX dirname needs to have enough place to store an additional '/'.
+ */
+BUFFER *
+dired_(char *dirname)
+{
+ BUFFER *bp;
+ FILE *dirpipe;
+ char line[256];
+ int len;
+
+ if ((dirname = adjustname(dirname)) == NULL) {
+ ewprintf("Bad directory name");
+ return (NULL);
+ }
+ /* this should not be done, instead adjustname() should get a flag */
+ len = strlen(dirname);
+ if (dirname[len - 1] != '/') {
+ dirname[len++] = '/';
+ dirname[len] = '\0';
+ }
+ if ((bp = findbuffer(dirname)) == NULL) {
+ ewprintf("Could not create buffer");
+ return (NULL);
+ }
+ if (bclear(bp) != TRUE)
+ return (NULL);
+ bp->b_flag |= BFREADONLY;
+ if (snprintf(line, sizeof(line), "ls -al %s", dirname)
+ >= sizeof(line)) {
+ ewprintf("Path too long");
+ return (NULL);
+ }
+ if ((dirpipe = popen(line, "r")) == NULL) {
+ ewprintf("Problem opening pipe to ls");
+ return (NULL);
+ }
+ line[0] = line[1] = ' ';
+ while (fgets(&line[2], sizeof(line) - 2, dirpipe) != NULL) {
+ line[strlen(line) - 1] = '\0'; /* remove ^J */
+ (void) addline(bp, line);
+ }
+ if (pclose(dirpipe) == -1) {
+ ewprintf("Problem closing pipe to ls : %s",
+ strerror(errno));
+ return (NULL);
+ }
+ bp->b_dotp = lforw(bp->b_linep); /* go to first line */
+ (void) strlcpy(bp->b_fname, dirname, sizeof(bp->b_fname));
+ if ((bp->b_modes[1] = name_mode("dired")) == NULL) {
+ bp->b_modes[0] = name_mode("fundamental");
+ ewprintf("Could not find mode dired");
+ return (NULL);
+ }
+ bp->b_nmodes = 1;
+ return (bp);
+}
+
+#endif /* !NO_DIRED */
diff --git a/usr.bin/mg/fileio.c b/usr.bin/mg/fileio.c
index 8e36eaf759d..9481d16ab57 100644
--- a/usr.bin/mg/fileio.c
+++ b/usr.bin/mg/fileio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fileio.c,v 1.54 2005/10/13 20:23:01 kjell Exp $ */
+/* $OpenBSD: fileio.c,v 1.55 2005/10/14 06:41:47 kjell Exp $ */
/* This file is in the public domain. */
@@ -19,7 +19,6 @@
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
-#include <ctype.h>
static FILE *ffp;
@@ -400,90 +399,6 @@ copy(char *frname, char *toname)
return (TRUE);
}
-/*
- * dirname needs to have enough place to store an additional '/'.
- */
-BUFFER *
-dired_(char *dirname)
-{
- BUFFER *bp;
- FILE *dirpipe;
- char line[256];
- int len;
-
- if ((dirname = adjustname(dirname)) == NULL) {
- ewprintf("Bad directory name");
- return (NULL);
- }
- /* this should not be done, instead adjustname() should get a flag */
- len = strlen(dirname);
- if (dirname[len - 1] != '/') {
- dirname[len++] = '/';
- dirname[len] = '\0';
- }
- if ((bp = findbuffer(dirname)) == NULL) {
- ewprintf("Could not create buffer");
- return (NULL);
- }
- if (bclear(bp) != TRUE)
- return (NULL);
- bp->b_flag |= BFREADONLY;
- if (snprintf(line, sizeof(line), "ls -al %s", dirname)
- >= sizeof(line)) {
- ewprintf("Path too long");
- return (NULL);
- }
- if ((dirpipe = popen(line, "r")) == NULL) {
- ewprintf("Problem opening pipe to ls");
- return (NULL);
- }
- line[0] = line[1] = ' ';
- while (fgets(&line[2], sizeof(line) - 2, dirpipe) != NULL) {
- line[strlen(line) - 1] = '\0'; /* remove ^J */
- (void) addline(bp, line);
- }
- if (pclose(dirpipe) == -1) {
- ewprintf("Problem closing pipe to ls : %s",
- strerror(errno));
- return (NULL);
- }
- bp->b_dotp = lforw(bp->b_linep); /* go to first line */
- (void) strlcpy(bp->b_fname, dirname, sizeof(bp->b_fname));
- if ((bp->b_modes[1] = name_mode("dired")) == NULL) {
- bp->b_modes[0] = name_mode("fundamental");
- ewprintf("Could not find mode dired");
- return (NULL);
- }
- bp->b_nmodes = 1;
- return (bp);
-}
-
-#define NAME_FIELD 8
-
-int
-d_makename(LINE *lp, char *fn, int len)
-{
- int i;
- char *p, *ep;
-
- strlcpy(fn, curbp->b_fname, len);
- if ((p = lp->l_text) == NULL)
- return (ABORT);
- ep = lp->l_text + llength(lp);
- p++; /* skip action letter, if any */
- for (i = 0; i < NAME_FIELD; i++) {
- while (p < ep && isspace(*p))
- p++;
- while (p < ep && !isspace(*p))
- p++;
- while (p < ep && isspace(*p))
- p++;
- if (p == ep)
- return (ABORT);
- }
- strlcat(fn, p, len);
- return ((lgetc(lp, 2) == 'd') ? TRUE : FALSE);
-}
#endif /* NO_DIRED */
struct filelist {