Merge branch 'master' of github.com:night0721/ccc
This commit is contained in:
commit
7ca0b4924a
3 changed files with 18 additions and 13 deletions
27
ccc.c
27
ccc.c
|
@ -409,13 +409,12 @@ void add_file_stat(char *filename, char *path, int ftype)
|
||||||
{
|
{
|
||||||
struct stat file_stat;
|
struct stat file_stat;
|
||||||
if (stat(path, &file_stat) == -1) {
|
if (stat(path, &file_stat) == -1) {
|
||||||
/* can't be triggered? */
|
perror("stat()");
|
||||||
if (errno == EACCES)
|
return;
|
||||||
arraylist_add(files, filename, path, NULL, REG, NULL, DEF_COLOR, 0, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int type;
|
int type = 0;
|
||||||
char icon_str[5];
|
char icon_str[8] = {0};
|
||||||
|
|
||||||
filename[strlen(filename)] = '\0';
|
filename[strlen(filename)] = '\0';
|
||||||
/* handle file without extension
|
/* handle file without extension
|
||||||
|
@ -427,17 +426,20 @@ void add_file_stat(char *filename, char *path, int ftype)
|
||||||
}
|
}
|
||||||
/* add file extension */
|
/* add file extension */
|
||||||
icon *ext_icon = hashtable_search(ext ? ext : filename);
|
icon *ext_icon = hashtable_search(ext ? ext : filename);
|
||||||
if (!ext_icon)
|
if (!ext_icon) {
|
||||||
memcpy(icon_str, "", 4);
|
char ch[] = "";
|
||||||
else
|
memcpy(icon_str, ch, sizeof(ch));
|
||||||
memcpy(icon_str, ext_icon->icon, 4);
|
} else {
|
||||||
|
strncpy(icon_str, ext_icon->icon, sizeof(icon_str));
|
||||||
|
}
|
||||||
|
|
||||||
int color = DEF_COLOR;
|
int color = DEF_COLOR;
|
||||||
|
|
||||||
if (S_ISDIR(file_stat.st_mode)) {
|
if (S_ISDIR(file_stat.st_mode)) {
|
||||||
type = DRY; /* dir */
|
type = DRY; /* dir */
|
||||||
color = DIR_COLOR;
|
color = DIR_COLOR;
|
||||||
memcpy(icon_str, "", 4);
|
char ch[] = "";
|
||||||
|
memcpy(icon_str, ch, sizeof(ch));
|
||||||
} else if (S_ISREG(file_stat.st_mode)) {
|
} else if (S_ISREG(file_stat.st_mode)) {
|
||||||
type = REG; /* regular file */
|
type = REG; /* regular file */
|
||||||
color = REG_COLOR;
|
color = REG_COLOR;
|
||||||
|
@ -544,8 +546,11 @@ void show_file_content(void)
|
||||||
|
|
||||||
move_cursor(1, half_width);
|
move_cursor(1, half_width);
|
||||||
if (current_file.type == DRY) {
|
if (current_file.type == DRY) {
|
||||||
ArrayList *files_visit;
|
ArrayList *files_visit = NULL;
|
||||||
populate_files(current_file.name, 0, &files_visit);
|
populate_files(current_file.name, 0, &files_visit);
|
||||||
|
if (!files_visit)
|
||||||
|
return;
|
||||||
|
|
||||||
for (long i = 0; i < files_visit->length && i < rows - 1; i++) {
|
for (long i = 0; i < files_visit->length && i < rows - 1; i++) {
|
||||||
char *line = get_line(files_visit, i, 0, show_icons);
|
char *line = get_line(files_visit, i, 0, show_icons);
|
||||||
int color = files_visit->items[i].color;
|
int color = files_visit->items[i].color;
|
||||||
|
|
2
file.c
2
file.c
|
@ -69,7 +69,7 @@ void arraylist_remove(ArrayList *list, long index)
|
||||||
void arraylist_add(ArrayList *list, char *name, char *path, char *stats, int type, char *icon, int color, int marked, int force)
|
void arraylist_add(ArrayList *list, char *name, char *path, char *stats, int type, char *icon, int color, int marked, int force)
|
||||||
{
|
{
|
||||||
file new_file = { name, path, type, stats, color };
|
file new_file = { name, path, type, stats, color };
|
||||||
strcpy(new_file.icon, icon);
|
strncpy(new_file.icon, icon, sizeof(new_file.icon) / sizeof(new_file.icon[0]));
|
||||||
|
|
||||||
if (list->capacity != list->length) {
|
if (list->capacity != list->length) {
|
||||||
if (marked) {
|
if (marked) {
|
||||||
|
|
2
file.h
2
file.h
|
@ -19,7 +19,7 @@ typedef struct {
|
||||||
int type;
|
int type;
|
||||||
char *stats;
|
char *stats;
|
||||||
int color;
|
int color;
|
||||||
char icon[5];
|
char icon[8];
|
||||||
} file;
|
} file;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
Loading…
Reference in a new issue