/* depend: */
/* cflags: */
-/* linker: display.o function.o -lcurses */
-/* doslnk: display.o function.o -lpdc~1 */
-/* winlnk: display.o function.o -lpdcurses */
+/* linker: debug.o display.o function.o -lcurses */
+/* doslnk: debug.o display.o function.o -lpdc~1 */
+/* winlnk: debug.o display.o function.o -lpdcurses */
#include <curses.h>
#include <stdio.h>
while (!stop) {
char *ptr = NULL;
- boardwindow (current);
+ //boardwindow (current);
int ch = getch ();
switch (ch) {
case KEY_UP:
case 'i':
- dir = 0;
break;
case KEY_LEFT:
case 'j':
- dir = 3;
break;
case KEY_DOWN:
case 'k':
- dir = 2;
break;
case KEY_RIGHT:
case 'l':
- dir = 1;
break;
case KEY_ESC:
case 'q':
- if (askwindow (" Restart (Y/N) ", max (board->xoffset + (board->xsize - savelen) / 2, 1), board->yoffset + (board->ysize - 1) / 2, "Yy", "Nn") == 1) {
+ //if (askwindow (" Restart (Y/N) ", max (board->xoffset + (board->xsize - savelen) / 2, 1), board->yoffset + (board->ysize - 1) / 2, "Yy", "Nn") == 1) {
stop = 1;
- }
+ //}
break;
}
}
endwin ();
- freeboard (board);
+ //freeboard (board);
return 0;
}
+#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/stat.h>
+#include <sys/sysmacros.h>
#include "debug.h"
#include "type.h"
#include "function.h"
+#define SEPARATOR "/"
+
int strmaxlen (char *str, char ch)
{
int len = 0;
list_t *alloclist ()
{
- list_t *list = CHECKALLOC (list_t);
+ list_t *list = (list_t *) malloc (sizeof (list_t));
+ CHECKALLOC (list);
list->nb = 0;
list->tab = NULL;
return list;
}
-list_t *addelement (list_t *list, char *path)
+list_t *addelement (list_t *list, char *dirname, char *filename, type_t type)
{
+ size_t size = 0;
+
+ if ((type == type_unkn_e) || (type == type_reg_e)) {
+ char *name = (char *) calloc (1, strlen (dirname) + strlen (filename) + 1 + 1);
+ CHECKALLOC (name);
+ strcat (strcat(strcpy (name, dirname), SEPARATOR), filename);
+
+ struct stat sb;
+ if (lstat (name, &sb) == -1) {
+ VERBOSE (ERROR, fprintf (stderr, "can't stat on file '%s'\n", name));
+ exit (1);
+ }
+
+ switch (sb.st_mode & S_IFMT) {
+ case S_IFBLK:
+ type = type_block_e;
+ break;
+ case S_IFCHR:
+ type = type_char_e;
+ break;
+ case S_IFDIR:
+ type = type_dir_e;
+ break;
+ case S_IFIFO:
+ type = type_pipe_e;
+ break;
+ case S_IFLNK:
+ type = type_symb_e;
+ break;
+ case S_IFREG:
+ type = type_reg_e;
+ break;
+ case S_IFSOCK:
+ type = type_socket_e;
+ break;
+ }
+
+ if (type == type_reg_e) {
+ size = sb.st_size;
+ }
+
+ free (name);
+ }
+ list->nb++;
+ list->tab = (elem_t *) realloc (list->tab, list->nb * sizeof (elem_t));
+ CHECKALLOC (list->tab);
+ elem_t * elem = list->tab + list->nb - 1;
+ elem->name = strdup (filename);
+ elem->size = size;
+ elem->type = type;
+
+ return list;
}
list_t *exporedir (char *dirname)
struct dirent *dp = NULL;
while ((dp = readdir(dir)) != NULL) {
+ type_t type = type_unkn_e;
+ switch (dp->d_type) {
+ case DT_BLK:
+ type = type_block_e;
+ break;
+ case DT_CHR:
+ type = type_char_e;
+ break;
+ case DT_DIR:
+ type = type_dir_e;
+ break;
+ case DT_FIFO:
+ type = type_pipe_e;
+ break;
+ case DT_LNK:
+ type = type_symb_e;
+ break;
+ case DT_REG:
+ type = type_reg_e;
+ break;
+ case DT_SOCK:
+ type = type_socket_e;
+ break;
+ }
+ addelement (list, dirname, dp->d_name, type);
}
- closedir(dirp);
+ closedir(dir);
return list;
}