mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-21 06:45:39 -06:00
Adding uppdev....
git-svn-id: svn://ultimatepp.org/upp/trunk@328 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
dc9f782ba5
commit
4a1c627474
2823 changed files with 619073 additions and 0 deletions
80
uppdev/mimetab/mimetab.cpp
Normal file
80
uppdev/mimetab/mimetab.cpp
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
#include <Core/Core.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
struct ExtToMime {
|
||||
Index<String> major;
|
||||
Index<String> minor;
|
||||
VectorMap<String, dword> map;
|
||||
|
||||
void Load(const char *file);
|
||||
void Refresh();
|
||||
bool GetMime(const String& ext, String& maj, String& min);
|
||||
};
|
||||
|
||||
void ExtToMime::Load(const char *fn)
|
||||
{
|
||||
FileIn in(fn);
|
||||
if(in)
|
||||
while(!in.IsEof()) {
|
||||
String ln = TrimLeft(TrimRight(in.GetLine()));
|
||||
if(ln[0] != '#') {
|
||||
int q = ln.Find(':');
|
||||
if(q >= 0) {
|
||||
String h = ln.Mid(0, q);
|
||||
int w = h.Find('/');
|
||||
if(w >= 0) {
|
||||
int x = ln.Find("*.", q);
|
||||
if(x >= 0) {
|
||||
String ext = ln.Mid(x + 2);
|
||||
if(ext.GetCount() && map.Find(ext) < 0)
|
||||
map.Add(ext, MAKELONG(minor.FindAdd(h.Mid(w + 1)), major.FindAdd(h.Mid(0, w))));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ExtToMime::Refresh()
|
||||
{
|
||||
major.Clear();
|
||||
minor.Clear();
|
||||
map.Clear();
|
||||
Load("/usr/local/share/mime/globs");
|
||||
Load("/usr/share/mime/globs");
|
||||
}
|
||||
|
||||
bool ExtToMime::GetMime(const String& ext, String& maj, String& min)
|
||||
{
|
||||
ONCELOCK {
|
||||
Refresh();
|
||||
}
|
||||
int q = map.Find(ext);
|
||||
if(q < 0)
|
||||
return false;
|
||||
dword x = map[q];
|
||||
maj = major[HIWORD(x)];
|
||||
min = minor[LOWORD(x)];
|
||||
}
|
||||
|
||||
String GetMime(const String& ext)
|
||||
{
|
||||
String a, b;
|
||||
if(Single<ExtToMime>().GetMime(ext, a, b))
|
||||
return a + '/' + b;
|
||||
else
|
||||
return Null;
|
||||
}
|
||||
|
||||
CONSOLE_APP_MAIN
|
||||
{
|
||||
DUMP(GetMime("skr"));
|
||||
DUMP(GetMime("ai"));
|
||||
DUMP(GetMime("jpg"));
|
||||
DUMP(GetMime("bcpio"));
|
||||
DUMP(GetMime("jpeg"));
|
||||
DUMP(GetMime("zip"));
|
||||
DUMP(GetMime("xyz"));
|
||||
DUMP(GetMime("basdf"));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue