43 #include <sys/types.h> 45 #if defined(WIN32) && !defined(__CYGWIN__) 50 # define access _access 67 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) 68 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) 69 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) 70 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) 71 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) 79 static void load_kde_icons(
const char *directory,
const char *icondir);
105 if (ext && strcmp(ext,
".fti") == 0)
112 Fl::warning(
"Fl_File_Icon::load(): Unable to load icon file \"%s\".",
f);
137 Fl::error(
"Fl_File_Icon::load_fti(): Unable to open \"%s\" - %s",
138 fti, strerror(errno));
145 while ((ch = getc(fp)) != EOF)
154 while ((ch = getc(fp)) != EOF)
167 Fl::error(
"Fl_File_Icon::load_fti(): Expected a letter at file position %ld (saw '%c')",
176 while ((ch = getc(fp)) != EOF)
189 Fl::error(
"Fl_File_Icon::load_fti(): Expected a ( at file position %ld (saw '%c')",
197 while ((ch = getc(fp)) != EOF)
201 else if (ptr < (params +
sizeof(params) - 1))
210 Fl::error(
"Fl_File_Icon::load_fti(): Expected a ) at file position %ld (saw '%c')",
216 if ((ch = getc(fp)) !=
';')
218 Fl::error(
"Fl_File_Icon::load_fti(): Expected a ; at file position %ld (saw '%c')",
224 if (strcmp(
command,
"color") == 0)
236 if (strcmp(params,
"iconcolor") == 0)
238 else if (strcmp(params,
"shadowcolor") == 0)
240 else if (strcmp(params,
"outlinecolor") == 0)
244 int c = atoi(params);
258 else if (strcmp(
command,
"bgnline") == 0)
260 else if (strcmp(
command,
"bgnclosedline") == 0)
262 else if (strcmp(
command,
"bgnpolygon") == 0)
264 else if (strcmp(
command,
"bgnoutlinepolygon") == 0)
270 else if (strcmp(
command,
"endoutlinepolygon") == 0 && outline)
275 if (strcmp(params,
"iconcolor") == 0)
277 else if (strcmp(params,
"shadowcolor") == 0)
279 else if (strcmp(params,
"outlinecolor") == 0)
283 int c = atoi(params);
297 data_[outline] = cval >> 16;
298 data_[outline + 1] = cval;
303 else if (strncmp(
command,
"end", 3) == 0)
305 else if (strcmp(
command,
"vertex") == 0)
310 if (sscanf(params,
"%f,%f", &
x, &
y) != 2)
313 add_vertex((
short)(
int)rint(
x * 100.0), (
short)(
int)rint(
y * 100.0));
317 Fl::error(
"Fl_File_Icon::load_fti(): Unknown command \"%s\" at file position %ld.",
327 printf(
"Icon File \"%s\":\n", fti);
329 printf(
" %d,\n",
data_[i]);
347 if (!img || !img->
count() || !img->
w() || !img->
h())
return -1;
349 if (img->
count() == 1) {
356 const int extra_data = img->
ld() ? (img->
ld()-img->
w()*img->
d()) : 0;
359 for (
y = 0, row = (
const uchar *)(*(img->
data()));
y < img->
h();
y ++, row += extra_data)
361 for (
x = 0, startx = 0, c = (
Fl_Color)-1;
363 x ++, row += img->
d())
393 add_vertex(startx * 9000 / img->
w() + 1000, 9500 -
y * 9000 / img->
h());
394 add_vertex(
x * 9000 / img->
w() + 1000, 9500 -
y * 9000 / img->
h());
395 add_vertex(
x * 9000 / img->
w() + 1000, 9500 - (
y + 1) * 9000 / img->
h());
396 add_vertex(startx * 9000 / img->
w() + 1000, 9500 - (
y + 1) * 9000 / img->
h());
409 add_vertex(startx * 9000 / img->
w() + 1000, 9500 -
y * 9000 / img->
h());
410 add_vertex(
x * 9000 / img->
w() + 1000, 9500 -
y * 9000 / img->
h());
411 add_vertex(
x * 9000 / img->
w() + 1000, 9500 - (
y + 1) * 9000 / img->
h());
412 add_vertex(startx * 9000 / img->
w() + 1000, 9500 - (
y + 1) * 9000 / img->
h());
427 int red, green, blue;
433 sscanf(*ptr,
"%*d%*d%d%d", &
ncolors, &chars_per_color);
435 colors =
new Fl_Color[1 << (chars_per_color * 8)];
438 memset(colors, 0,
sizeof(
Fl_Color) << (chars_per_color * 8));
445 const uchar *cmapptr;
449 for (i = 0, cmapptr = (
const uchar *)*ptr; i <
ncolors; i ++, cmapptr += 4)
450 colors[cmapptr[0]] =
fl_rgb_color(cmapptr[1], cmapptr[2], cmapptr[3]);
454 for (i = 0; i <
ncolors; i ++, ptr ++) {
459 if (chars_per_color > 1) ch = (ch << 8) | *lineptr++;
462 if ((lineptr = strstr(lineptr,
"c ")) ==
NULL) {
465 }
else if (lineptr[2] ==
'#') {
468 for (j = 0; j < 12; j ++)
469 if (!isxdigit(lineptr[j]))
476 red = green = blue = 0;
482 red = 255 * strtol(val,
NULL, 16) / 15;
486 green = 255 * strtol(val,
NULL, 16) / 15;
490 blue = 255 * strtol(val,
NULL, 16) / 15;
501 red = strtol(val,
NULL, 16);
503 val[0] = lineptr[j + 0];
504 val[1] = lineptr[j + 1];
506 green = strtol(val,
NULL, 16);
508 val[0] = lineptr[2 * j + 0];
509 val[1] = lineptr[2 * j + 1];
511 blue = strtol(val,
NULL, 16);
518 if (strncasecmp(lineptr + 2,
"white", 5) == 0) colors[ch] =
FL_WHITE;
519 else if (strncasecmp(lineptr + 2,
"black", 5) == 0) colors[ch] =
FL_BLACK;
520 else if (strncasecmp(lineptr + 2,
"none", 4) == 0) {
529 for (
y = 0;
y < img->
h();
y ++, ptr ++) {
534 for (
x = 0;
x < img->
w();
x ++) {
537 if (chars_per_color > 1) newch = (newch << 8) | *lineptr++;
543 add_vertex(startx * 9000 / img->
w() + 1000, 9500 -
y * 9000 / img->
h());
544 add_vertex(
x * 9000 / img->
w() + 1000, 9500 -
y * 9000 / img->
h());
545 add_vertex(
x * 9000 / img->
w() + 1000, 9500 - (
y + 1) * 9000 / img->
h());
546 add_vertex(startx * 9000 / img->
w() + 1000, 9500 - (
y + 1) * 9000 / img->
h());
558 add_vertex(startx * 9000 / img->
w() + 1000, 9500 -
y * 9000 / img->
h());
559 add_vertex(
x * 9000 / img->
w() + 1000, 9500 -
y * 9000 / img->
h());
560 add_vertex(
x * 9000 / img->
w() + 1000, 9500 - (
y + 1) * 9000 / img->
h());
561 add_vertex(startx * 9000 / img->
w() + 1000, 9500 - (
y + 1) * 9000 / img->
h());
575 printf(
"Icon File \"%s\":\n", ifile);
578 printf(
" %d,\n",
data_[i]);
602 const char *
const icondirs[] = {
609 static short plain[] = {
627 static short image[] = {
654 static short dir[] = {
680 if (!access(
"/opt/kde", F_OK))
kdedir =
"/opt/kde";
681 else if (!access(
"/usr/local/share/mimelnk", F_OK))
kdedir =
"/usr/local";
692 for (i = 0; icondirs[i]; i ++) {
696 if (!access(icondir, F_OK))
break;
718 }
else if (!access(
"/usr/share/icons/folder.xpm", F_OK)) {
721 icon->load_image(
"/usr/share/icons/page.xpm");
724 icon->load_image(
"/usr/share/icons/folder.xpm");
725 }
else if (!access(
"/usr/dt/appconfig/icons", F_OK)) {
728 icon->load_image(
"/usr/dt/appconfig/icons/C/Dtdata.m.pm");
731 icon->load_image(
"/usr/dt/appconfig/icons/C/DtdirB.m.pm");
734 icon->load_image(
"/usr/dt/appconfig/icons/C/Dtcore.m.pm");
737 icon->load_image(
"/usr/dt/appconfig/icons/C/Dtimage.m.pm");
740 icon->load_image(
"/usr/dt/appconfig/icons/C/Dtps.m.pm");
743 icon->load_image(
"/usr/dt/appconfig/icons/C/DtPrtpr.m.pm");
744 }
else if (!access(
"/usr/lib/filetype", F_OK)) {
747 icon->load_fti(
"/usr/lib/filetype/iconlib/generic.doc.fti");
750 icon->load_fti(
"/usr/lib/filetype/iconlib/generic.folder.closed.fti");
753 icon->load_fti(
"/usr/lib/filetype/default/iconlib/CoreFile.fti");
756 icon->load_fti(
"/usr/lib/filetype/system/iconlib/ImageFile.fti");
758 if (!access(
"/usr/lib/filetype/install/iconlib/acroread.doc.fti", F_OK)) {
760 icon->load_fti(
"/usr/lib/filetype/system/iconlib/PostScriptFile.closed.fti");
763 icon->load_fti(
"/usr/lib/filetype/install/iconlib/acroread.doc.fti");
766 icon->load_fti(
"/usr/lib/filetype/system/iconlib/PostScriptFile.closed.fti");
769 if (!access(
"/usr/lib/filetype/install/iconlib/html.fti", F_OK)) {
771 icon->load_fti(
"/usr/lib/filetype/iconlib/generic.doc.fti");
772 icon->load_fti(
"/usr/lib/filetype/install/iconlib/html.fti");
775 if (!access(
"/usr/lib/filetype/install/iconlib/color.ps.idle.fti", F_OK)) {
777 icon->load_fti(
"/usr/lib/filetype/install/iconlib/color.ps.idle.fti");
783 sizeof(image) /
sizeof(image[0]), image);
793 for (count = 0, temp =
first_; temp; temp = temp->
next_, count ++);
794 printf(
"count of Fl_File_Icon's is %d...\n", count);
806 const char *icondir) {
816 for (i = 0; i < n; i ++) {
817 if (entries[i]->d_name[0] !=
'.') {
818 snprintf(full,
sizeof(full),
"%s/%s", directory, entries[i]->d_name);
824 free((
void *)entries[i]);
827 free((
void*)entries);
837 const char *icondir) {
850 iconfilename[0] =
'\0';
853 while (fgets(tmp,
sizeof(tmp), fp)) {
855 strlcpy(iconfilename, val,
sizeof(iconfilename));
857 strlcpy(mimetype, val,
sizeof(mimetype));
859 strlcpy(pattern, val,
sizeof(pattern));
865 printf(
"%s: Icon=\"%s\", MimeType=\"%s\", Patterns=\"%s\"\n",
filename,
866 iconfilename, mimetype, pattern);
869 if (!pattern[0] && strncmp(mimetype,
"inode/", 6))
return;
871 if (iconfilename[0]) {
872 if (iconfilename[0] ==
'/') {
873 strlcpy(full_iconfilename, iconfilename,
sizeof(full_iconfilename));
874 }
else if (!access(icondir, F_OK)) {
877 static const char *paths[] = {
933 for (i = 0; i < (int)(
sizeof(paths) /
sizeof(paths[0])); i ++) {
934 snprintf(full_iconfilename,
sizeof(full_iconfilename),
935 "%s/%s/%s.png", icondir, paths[i], iconfilename);
937 if (!access(full_iconfilename, F_OK))
break;
940 if (i >= (
int)(
sizeof(paths) /
sizeof(paths[0])))
return;
943 snprintf(full_iconfilename,
sizeof(full_iconfilename),
944 "%s/%s", tmp, iconfilename);
946 if (access(full_iconfilename, F_OK))
return;
949 if (strncmp(mimetype,
"inode/", 6) == 0) {
950 if (!strcmp(mimetype + 6,
"directory"))
952 else if (!strcmp(mimetype + 6,
"blockdevice"))
954 else if (!strcmp(mimetype + 6,
"fifo"))
962 icon->load(full_iconfilename);
978 pattern = (
char *)
malloc(strlen(kdepattern) + 3);
979 strcpy(pattern,
"{");
980 strcpy(pattern + 1, kdepattern);
982 if (pattern[strlen(pattern) - 1] ==
';') pattern[strlen(pattern) - 1] =
'\0';
984 strcat(pattern,
"}");
986 for (patptr = pattern; *patptr; patptr ++) {
987 if (*patptr ==
';') *patptr =
'|';
1001 while (*str == *
key) {
1006 if (*
key ==
'\0' && *str ==
'=') {
1007 if (str[strlen(str) - 1] ==
'\n') str[strlen(str) - 1] =
'\0';