00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <stdio.h>
00028 #include <strings.h>
00029 #include <string.h>
00030
00031 #include "tags.h"
00032 #include "filetypes.h"
00033
00034 static const struct {
00035 char *tag;
00036 char *special_dir;
00037 char *exts[32];
00038 } extension_tag_map[] = {
00039 { "personal", "Personal Documents", { NULL } },
00040 { "help", "Help", { NULL } },
00041 {"book", "Books", {"pdf", "epub", "pdb",
00042 #if MACHINE_HAS_ACSM
00043 "acsm",
00044 #endif
00045 NULL}},
00046 { "image", "Images", { "jpg", "jpeg", "png", "bmp", "tiff", "gif", NULL } },
00047 { "news", "News", { "np", "inp", NULL } },
00048 { "note", "Notes", { "note" } },
00049 { NULL, NULL, {} }
00050 };
00051
00052
00053 static const char* get_tag_for_extension(const char* ext)
00054 {
00055 int i, j;
00056 for (i = 0; extension_tag_map[i].tag; i++)
00057 {
00058 for (j = 0; extension_tag_map[i].exts[j]; j++)
00059 {
00060 if (strcasecmp(extension_tag_map[i].exts[j], ext) == 0)
00061 {
00062 return extension_tag_map[i].tag;
00063 }
00064 }
00065 }
00066 return NULL;
00067 }
00068
00069
00070 static const char* get_tag_for_dir(const char* dir, const char* basedir)
00071 {
00072 char fulldir[256];
00073 int i;
00074 for (i=0; extension_tag_map[i].tag; i++)
00075 {
00076 snprintf(fulldir, sizeof(fulldir), "%s/%s", basedir, extension_tag_map[i].special_dir);
00077 int len = strlen(fulldir);
00078 if (strncasecmp(fulldir, dir, len) == 0) {
00079 if (dir[len] == 0 || dir[len] == '/') {
00080 return extension_tag_map[i].tag;
00081 }
00082 }
00083 }
00084 return NULL;
00085 }
00086
00087
00088 const gchar* get_tag_for_file(const gchar* filename,
00089 const gchar* dir,
00090 const char* basedir)
00091 {
00092 static const char* empty = "";
00093
00094 const char *ctag = get_tag_for_dir(dir, basedir);
00095 if (ctag) return ctag;
00096
00097 const char *ext = g_extension_pointer(filename);
00098 ctag = get_tag_for_extension(ext);
00099 if (ctag) return ctag;
00100
00101 return empty;
00102 }
00103