summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--loader2/Makefile3
-rw-r--r--loader2/dirbrowser.c49
-rw-r--r--loader2/dirbrowser.h2
3 files changed, 40 insertions, 14 deletions
diff --git a/loader2/Makefile b/loader2/Makefile
index f59f2c92d..0fae6a689 100644
--- a/loader2/Makefile
+++ b/loader2/Makefile
@@ -20,6 +20,7 @@ METHOBJS = method.o cdinstall.o hdinstall.o nfsinstall.o urlinstall.o
OBJS = log.o moduleinfo.o loadermisc.o modules.o moduledeps.o windows.o \
lang.o kbd.o modstubs.o driverdisk.o selinux.o \
md5.o mediacheck.o kickstart.o driverselect.o \
+ getparts.o dirbrowser.o \
$(HWOBJS) $(METHOBJS)
LOADEROBJS = loader.o loader-pcmcia.o
NETOBJS = net.o urls.o ftp.o telnet.o telnetd.o
@@ -144,7 +145,7 @@ install: all
install -m 644 module-info $(DESTDIR)/$(RUNTIMEDIR)/loader
install -m 644 font.bgf.gz $(DESTDIR)/$(RUNTIMEDIR)/loader
-dirbrowser:
+dirbrowser: dirbrowser.c
gcc -DSTANDALONE -Wall -Werror -ggdb -o dirbrowser dirbrowser.c -lnewt -lslang
ifeq (.depend,$(wildcard .depend))
diff --git a/loader2/dirbrowser.c b/loader2/dirbrowser.c
index 153607240..6ebaa4323 100644
--- a/loader2/dirbrowser.c
+++ b/loader2/dirbrowser.c
@@ -24,6 +24,13 @@
#include <string.h>
#include <sys/stat.h>
+#ifndef STANDALONE
+#include "log.h"
+#include "loader.h"
+#include "loadermisc.h"
+#include "lang.h"
+#endif
+
#ifdef STANDALONE
#define _(x) x
@@ -84,6 +91,7 @@ static char ** get_file_list(char * dirname,
}
}
files[i] = NULL;
+ closedir(dir);
qsort(files, i, sizeof(*files), simpleStringCmp);
return files;
@@ -101,15 +109,17 @@ static char ** get_file_list(char * dirname,
* Function should take arguments of the directory name and
* the dirent for the file.
*/
-char * newt_select_file(char * title, char * dirname,
+char * newt_select_file(char * title, char * text, char * dirname,
int (*filterfunc)(char *, struct dirent *)) {
char ** files;
char * fn = NULL;
int i, done = 0;
char * topdir = dirname;
char * dir = malloc(PATH_MAX);
+ char * path = NULL;
newtGrid grid, buttons;
- newtComponent f, listbox, ok, cancel;
+ newtComponent f, tb, listbox, ok, cancel;
+ struct stat sb;
struct newtExitStruct es;
dir = realpath(dirname, dir);
@@ -118,22 +128,39 @@ char * newt_select_file(char * title, char * dirname,
files = get_file_list(dir, filterfunc);
f = newtForm(NULL, NULL, 0);
- grid = newtCreateGrid(1, 3);
- listbox = newtListbox(15, 65, 10, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
+ grid = newtCreateGrid(1, 4);
+
+ tb = newtTextboxReflowed(-1, -1, text, 60, 0, 10, 0);
+
+ listbox = newtListbox(12, 65, 10,
+ NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
+
newtListboxSetWidth(listbox, 55);
buttons = newtButtonBar(_("OK"), &ok, _("Cancel"), &cancel, NULL);
- newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, listbox,
+ newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, tb,
+ 0, 0, 0, 1, 0, 0);
+ newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, listbox,
0, 0, 0, 1, 0, 0);
- newtGridSetField(grid, 0, 1, NEWT_GRID_SUBGRID, buttons,
+ newtGridSetField(grid, 0, 3, NEWT_GRID_SUBGRID, buttons,
0, 0, 0, 0, 0, NEWT_GRID_FLAG_GROWX);
/* if this isn't our topdir, we want to let them go up a dir */
if (strcmp(topdir, dir))
- newtListboxAppendEntry(listbox, "..", "..");
+ newtListboxAppendEntry(listbox, "../", "..");
for (i = 0; (files[i] != NULL); i++) {
if ((files[i] == NULL) || (strlen(files[i]) == 0)) continue;
- newtListboxAppendEntry(listbox, files[i], files[i]);
+ path = malloc(strlen(files[i]) + strlen(dir) + 2);
+ sprintf(path, "%s/%s", dir, files[i]);
+ stat(path, &sb);
+ free(path);
+ if (S_ISDIR(sb.st_mode)) {
+ char *dir = malloc(strlen(files[i]) + 2);
+ sprintf(dir, "%s/", files[i]);
+ newtListboxAppendEntry(listbox, dir, files[i]);
+ } else {
+ newtListboxAppendEntry(listbox, files[i], files[i]);
+ }
}
newtGridWrappedWindow(grid, title);
@@ -144,9 +171,6 @@ char * newt_select_file(char * title, char * dirname,
fn = NULL;
done = -1;
} else {
- char * path;
- struct stat sb;
-
fn = (char *) newtListboxGetCurrent(listbox);
path = malloc(strlen(fn) + strlen(dir) + 2);
sprintf(path, "%s/%s", dir, fn);
@@ -176,7 +200,8 @@ int main(int argc, char ** argv) {
newtInit();
newtCls();
- foo = newt_select_file("Get File Name", "/etc", NULL);
+ foo = newt_select_file("Get File Name", "foo, blah blah blah",
+ "/etc", NULL);
newtFinished();
printf("got %s\n", foo);
return 0;
diff --git a/loader2/dirbrowser.h b/loader2/dirbrowser.h
index dce389170..104809be8 100644
--- a/loader2/dirbrowser.h
+++ b/loader2/dirbrowser.h
@@ -1,7 +1,7 @@
#ifndef DIRBROWSER_H
#define DIRBROWSER_H
-char * newt_select_file(char * title, char * dirname,
+char * newt_select_file(char * title, char * text, char * dirname,
int (*filterfunc)(char *, struct dirent *));
#endif