terminology/src/bin/tyls.c

768 lines
20 KiB
C
Raw Normal View History

#include <Eina.h>
#include <Ecore.h>
#include <Evas.h>
#include <Ecore_Evas.h>
#include <Ecore_File.h>
#include <Edje.h>
#include <Emotion.h>
#include <termios.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fnmatch.h>
// this code sucks. just letting you know... in advance... in case you
// might be tempted to think otherwise... :)
enum {
SMALL,
MEDIUM,
LARGE
};
Ecore_Evas *ee = NULL;
Evas *evas = NULL;
Evas_Object *o = NULL;
struct termios told, tnew;
int tw = 0, th = 0, cw = 0, ch = 0;
#include "extns.h"
static int
echo_off(void)
{
if (tcgetattr(0, &told) != 0) return -1;
tnew = told;
tnew.c_lflag &= ~ECHO;
if (tcsetattr(0, TCSAFLUSH, &tnew) != 0) return -1;
return 0;
}
static int
echo_on(void)
{
return tcsetattr(0, TCSAFLUSH, &told);
}
static void
scaleterm(int w, int h, int *iw, int *ih)
{
if (w > (tw * cw))
{
*iw = tw;
*ih = ((h * (tw * cw) / w) + (ch - 1)) / ch;
}
else
{
*iw = (w + (cw - 1)) / cw;
*ih = (h + (ch - 1)) / ch;
}
}
static const char *
is_fmt(const char *f, const char **extn)
{
int i, len, l;
len = strlen(f);
for (i = 0; extn[i]; i++)
{
l = strlen(extn[i]);
if (len < l) continue;
if (!strcasecmp(extn[i], f + len - l)) return extn[i];
}
return NULL;
}
static void
size_print(char *buf, int bufsz, char *sz, unsigned long long size)
{
if (size < 1024LL)
{
snprintf(buf, bufsz, "%4lld", size);
*sz = ' ';
}
else if (size < (1024LL * 1024LL))
{
snprintf(buf, bufsz, "%4lld", size / (1024LL));
*sz = 'K';
}
else if (size < (1024LL * 1024LL * 1024LL))
{
snprintf(buf, bufsz, "%4lld", size / (1024LL * 1024LL));
*sz = 'M';
}
else if (size < (1024LL * 1024LL * 1024LL * 1024LL))
{
snprintf(buf, bufsz, "%4lld", size / (1024LL * 1024 * 1024LL));
*sz = 'G';
}
else if (size < (1024LL * 1024LL * 1024LL * 1024LL * 1024LL))
{
snprintf(buf, bufsz, "%4lld", size / (1024LL * 1024LL * 1024LL * 1024LL));
*sz = 'T';
}
else if (size < (1024LL * 1024LL * 1024LL * 1024LL * 1024LL * 1024LL))
{
snprintf(buf, bufsz, "%4lld", size / (1024LL * 1024LL * 1024LL * 1024LL * 1024LL));
*sz = 'P';
}
else
{
snprintf(buf, bufsz, "%4lld", size / (1024LL * 1024LL * 1024LL * 1024LL * 1024LL * 1024LL));
*sz = 'E';
}
}
#define RESET 0
#define CORE 1
#define CUBE 2
#define GRAY 3
#define BG 0
#define FG 1
#define BLACK 0
#define RED 1
#define GREEN 2
#define YELLOW 3
#define BLUE 4
#define PURPLE 5
#define CYAN 6
#define WHITE 7
#define BRIGHT 8
// #3399ff
// 51 153 355
// as 6x6x6
// 1.0 3.0 5.0
static void
colorprint(int mode, int fgbg, int r, int g, int b)
{
if (mode == RESET)
{
printf("%c[0m", 0x1b);
}
else if (mode == CORE) // 8 bg and 8 fg colors
{
int v = 0;
if (r & BRIGHT) printf("%c[01m", 0x1b);
else printf("%c[0m", 0x1b);
if (fgbg == FG) v = 30 + (r & 0x7);
else v = 40 + (r & 0x7);
printf("%c[%im", 0x1b, v);
}
else if (mode == CUBE) // 6x6x6 cube
{
int v = 0, c = 0;
if (fgbg == FG) v = 38;
else v = 48;
c = 16 + ((r * 6 * 6) + (g * 6) + b);
printf("%c[%i;5;%im", 0x1b, v, c);
}
else if (mode == GRAY) // 26 levels of grey
{
}
}
static void
sizeprint(char *sz, char szch)
{
colorprint(CUBE, FG, 1, 3, 5);
printf("%s", sz);
if (szch == 'K')
colorprint(CUBE, FG, 3, 4, 5);
else if (szch == 'M')
colorprint(CUBE, FG, 5, 5, 5);
else if (szch == 'G')
colorprint(CUBE, FG, 5, 3, 0);
else if (szch == 'T')
colorprint(CUBE, FG, 5, 1, 1);
else if (szch == 'P')
colorprint(CUBE, FG, 5, 0, 0);
else if (szch == 'E')
colorprint(CUBE, FG, 5, 5, 0);
printf("%c", szch);
colorprint(RESET, 0, 0, 0, 0);
}
typedef struct _Cmatch
{
short fr, fg, fb;
short br, bg, bb;
const char *match;
} Cmatch;
// for regular files
const Cmatch fmatch[] =
{
{ 5, 5, 5, 9, 9, 9, "*.jpg"},
{ 5, 5, 5, 9, 9, 9, "*.JPG"},
{ 5, 5, 5, 9, 9, 9, "*.jpeg"},
{ 5, 5, 5, 9, 9, 9, "*.JPEG"},
{ 5, 5, 5, 9, 9, 9, "*.jfif"},
{ 5, 5, 5, 9, 9, 9, "*.JFIF"},
{ 5, 5, 5, 9, 9, 9, "*.jfi"},
{ 5, 5, 5, 9, 9, 9, "*.JFI"},
{ 5, 5, 5, 9, 9, 9, "*.png"},
{ 5, 5, 5, 9, 9, 9, "*.PNG"},
{ 5, 5, 5, 9, 9, 9, "*.bmp"},
{ 5, 5, 5, 9, 9, 9, "*.BMP"},
{ 5, 5, 5, 9, 9, 9, "*.gif"},
{ 5, 5, 5, 9, 9, 9, "*.GIF"},
{ 5, 5, 5, 9, 9, 9, "*.xcf"},
{ 5, 5, 5, 9, 9, 9, "*.XCF"},
{ 5, 5, 5, 9, 9, 9, "*.xcf.gz"},
{ 5, 5, 5, 9, 9, 9, "*.XCF.gz"},
{ 5, 5, 5, 9, 9, 9, "*.svg"},
{ 5, 5, 5, 9, 9, 9, "*.SVG"},
{ 5, 5, 5, 9, 9, 9, "*.svgz"},
{ 5, 5, 5, 9, 9, 9, "*.SVGZ"},
{ 5, 5, 5, 9, 9, 9, "*.svg.gz"},
{ 5, 5, 5, 9, 9, 9, "*.SVG.GZ"},
{ 5, 5, 5, 9, 9, 9, "*.ppm"},
{ 5, 5, 5, 9, 9, 9, "*.PPM"},
{ 5, 5, 5, 9, 9, 9, "*.tif"},
{ 5, 5, 5, 9, 9, 9, "*.TIF"},
{ 5, 5, 5, 9, 9, 9, "*.tiff"},
{ 5, 5, 5, 9, 9, 9, "*.TIFF"},
{ 5, 5, 5, 9, 9, 9, "*.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ING"},
{ 3, 1, 5, 9, 9, 9, "NEWS"},
{ 3, 1, 5, 9, 9, 9, "ChangeLog"},
{ 3, 1, 5, 9, 9, 9, "AUTHORS"},
{ 3, 1, 5, 9, 9, 9, "TODO"},
{ 3, 1, 5, 9, 9, 9, "*.doc"},
{ 3, 1, 5, 9, 9, 9, "*.DOC"},
{ 3, 1, 5, 9, 9, 9, "*.docx"},
{ 3, 1, 5, 9, 9, 9, "*.DOCX"},
{ 3, 1, 5, 9, 9, 9, "*.html"},
{ 3, 1, 5, 9, 9, 9, "*.HTML"},
{ 3, 1, 5, 9, 9, 9, "*.htm"},
{ 3, 1, 5, 9, 9, 9, "*.HTM"},
{ 0, 0, 0, 0, 0, 0, NULL}
};
// for directories
const Cmatch dmatch[] =
{
{ 5, 3, 0, 9, 9, 9, "Desktop"},
{ 5, 3, 0, 9, 9, 9, "Desktop-*"},
{ 4, 1, 5, 9, 9, 9, "public_html"},
{ 0, 0, 0, 0, 0, 0, NULL}
};
// for exectuable files
const Cmatch xmatch[] =
{
{ 0, 0, 0, 0, 0, 0, NULL}
};
static Eina_Bool
printmatch(const char *name, const Cmatch *m)
{
int i;
for (i = 0; m[i].match; i++)
{
if (!fnmatch(m[i].match, name, 0))
{
if (m[i].fr <= 5) colorprint(CUBE, FG, m[i].fr, m[i].fg, m[i].fb);
if (m[i].br <= 5) colorprint(CUBE, BG, m[i].br, m[i].bg, m[i].bb);
printf("%s", name);
return EINA_TRUE;
}
}
return EINA_FALSE;
}
static void
fileprint(char *path, char *name, Eina_Bool type)
{
Eina_Bool isdir = EINA_FALSE;
Eina_Bool islink = EINA_FALSE;
if (name || type)
{
char *ts;
if (ecore_file_is_dir(path)) isdir = EINA_TRUE;
ts = ecore_file_readlink(path);
if (ts)
{
islink = EINA_TRUE;
free(ts);
}
}
if (name)
{
if (isdir)
{
if (!printmatch(name, dmatch))
{
colorprint(CUBE, FG, 1, 3, 5);
printf("%s", name);
}
}
else
{
if (!printmatch(name, fmatch))
{
printf("%s", name);
}
}
}
if (type)
{
if (islink)
{
colorprint(CUBE, FG, 3, 1, 5);
printf("@");
}
else if (isdir)
{
colorprint(CUBE, FG, 3, 4, 5);
printf("/");
}
else
printf(" ");
}
colorprint(RESET, 0, 0, 0, 0);
}
static void
list_dir(const char *dir, int mode)
{
Eina_List *files, *l;
char *s, **names;
int maxlen = 0, cols, c, rows, i, j, k, num, cw, stuff;
files = ecore_file_ls(dir);
if (!files) return;
names = calloc(eina_list_count(files) * 2, sizeof(char *));
if (!names) return;
i = 0;
EINA_LIST_FOREACH(files, l, s)
{
int len = eina_unicode_utf8_get_len(s);
if (s[0] == '.') continue;
if (len > maxlen) maxlen = len;
names[i] = s;
i++;
}
num = i;
stuff = 0;
if (mode == SMALL) stuff += 2;
else if (mode == MEDIUM) stuff += 4;
stuff += 5; // xxxx[ /K/M/G/T/P...]
stuff += 1; // spacer at start
// name
stuff += 1; // type [@/*/|/=...]
stuff += 1; // spacer
maxlen += stuff;
if (maxlen > 0)
{
cols = tw / maxlen;
if (cols < 1) cols = 1;
if (cols == 1)
{
maxlen--;
stuff--;
}
if (cols > num) cols = num;
rows = ((num + (cols - 1)) / cols);
for (i = 0; i < rows; i++)
{
if (mode == SMALL)
{
for (c = 0; c < cols; c++)
{
char buf[4096], sz[6], szch = ' ';
long long size;
s = names[(c * rows) + i];
if (!s) continue;
snprintf(buf, sizeof(buf), "%s/%s", dir, s);
int len = eina_unicode_utf8_get_len(s);
cw = tw / cols;
size = ecore_file_size(buf);
size_print(sz, sizeof(sz), &szch, size);
len += stuff;
printf("%c}it#%i;%i;%s%c", 0x1b, 2, 1, buf, 0);
printf("%c}ib%c", 0x1b, 0);
printf("##");
printf("%c}ie%c", 0x1b, 0);
sizeprint(sz, szch);
printf(" ");
fileprint(buf, s, EINA_TRUE);
for (j = 0; j < (cw - len); j++) printf(" ");
}
printf("\n");
}
else if (mode == MEDIUM)
{
for (c = 0; c < cols; c++)
{
char buf[4096];
s = names[(c * rows) + i];
if (!s) continue;
int len = eina_unicode_utf8_get_len(s);
snprintf(buf, sizeof(buf), "%s/%s", dir, s);
cw = tw / cols;
len += 4;
if (cols > 1) len += 1;
printf("%c}it%c%i;%i;%s%c", 0x1b, 33 + c, 4, 2, buf, 0);
printf("%c}ib%c", 0x1b, 0);
printf("%c%c%c%c", 33 + c, 33 + c, 33 + c, 33 + c);
printf("%c}ie%c", 0x1b, 0);
fileprint(buf, s, EINA_FALSE);
2013-02-01 23:39:47 -08:00
if (c < (cols - 1))
{
for (j = 0; j < (cw - len); j++) printf(" ");
}
}
printf("\n");
for (c = 0; c < cols; c++)
{
char buf[4096], sz[6], szch = ' ';
long long size;
int len;
s = names[(c * rows) + i];
if (!s) continue;
snprintf(buf, sizeof(buf), "%s/%s", dir, s);
cw = tw / cols;
size = ecore_file_size(buf);
size_print(sz, sizeof(sz), &szch, size);
2013-02-01 23:39:47 -08:00
len = eina_unicode_utf8_get_len(sz) + 2 + 4;
if (cols > 1) len += 1;
printf("%c}ib%c", 0x1b, 0);
printf("%c%c%c%c", 33 + c, 33 + c, 33 + c, 33 + c);
printf("%c}ie%c", 0x1b, 0);
sizeprint(sz, szch);
printf(" ");
fileprint(buf, NULL, EINA_TRUE);
2013-02-01 23:39:47 -08:00
if (c < (cols - 1))
{
for (j = 0; j < (cw - len); j++) printf(" ");
}
}
printf("\n");
}
}
}
free(names);
EINA_LIST_FREE(files, s) free(s);
}
int
main(int argc, char **argv)
{
char buf[64];
int w = 0, h = 0;
int iw = 0, ih = 0;
Eina_Bool listed = EINA_FALSE;
if (!getenv("TERMINOLOGY")) return 0;
if ((argc == 2) && (!strcmp(argv[1], "-h")))
{
printf("Usage: %s [-s|-m|-l] FILE1 [FILE2 ...]\n"
"\n"
" -s Small list mode\n"
" -m Medium list mode\n"
" -l Large list mode\n",
argv[0]);
return 0;
}
eina_init();
ecore_init();
ecore_file_init();
evas_init();
ecore_evas_init();
edje_init();
emotion_init();
ee = ecore_evas_buffer_new(1, 1);
if (ee)
{
int i, mode = SMALL;
char *rp;
evas = ecore_evas_get(ee);
echo_off();
snprintf(buf, sizeof(buf), "%c}qs", 0x1b);
if (write(0, buf, strlen(buf) + 1) < 0) perror("write");
if (scanf("%i;%i;%i;%i", &tw, &th, &cw, &ch) != 4)
{
echo_on();
return 0;
}
if ((tw <= 0) || (th <= 0) || (cw <= 1) || (ch <= 1))
{
echo_on();
return 0;
}
echo_on();
for (i = 1; i < argc; i++)
{
char *path;
if (!strcmp(argv[i], "-c"))
{
mode = SMALL;
i++;
if (i >= argc) break;
}
else if (!strcmp(argv[i], "-m"))
{
mode = MEDIUM;
i++;
if (i >= argc) break;
}
else if (!strcmp(argv[i], "-l"))
{
mode = LARGE;
i++;
if (i >= argc) break;;
}
path = argv[i];
rp = ecore_file_realpath(path);
if (rp)
{
if (ecore_file_is_dir(rp))
{
list_dir(rp, mode);
listed = EINA_TRUE;
}
free(rp);
}
}
if (!listed)
{
rp = ecore_file_realpath("./");
if (rp)
{
list_dir(rp, mode);
free(rp);
}
}
fflush(stdout);
exit(0);
// ecore_main_loop_begin();
ecore_evas_free(ee);
}
emotion_shutdown();
edje_shutdown();
ecore_evas_shutdown();
evas_shutdown();
ecore_file_shutdown();
ecore_shutdown();
eina_shutdown();
return 0;
}