use std::old_io::fs::PathExtensions;
use std::env;
use std::os;
pub fn get_dbpath_for_term(term: &str) -> Option<Path> {
if term.len() == 0 {
return None;
}
let homedir = os::homedir();
let mut dirs_to_search = Vec::new();
let first_char = term.char_at(0);
match env::var("TERMINFO") {
Ok(dir) => dirs_to_search.push(Path::new(dir)),
Err(..) => {
if homedir.is_some() {
dirs_to_search.push(homedir.unwrap().join(".terminfo"))
}
match env::var("TERMINFO_DIRS") {
Ok(dirs) => for i in dirs.split(':') {
if i == "" {
dirs_to_search.push(Path::new("/usr/share/terminfo"));
} else {
dirs_to_search.push(Path::new(i));
}
},
Err(..) => {
dirs_to_search.push(Path::new("/etc/terminfo"));
dirs_to_search.push(Path::new("/lib/terminfo"));
dirs_to_search.push(Path::new("/usr/share/terminfo"));
}
}
}
};
for p in dirs_to_search.iter() {
if p.exists() {
let f: &str = &first_char.to_string();
let newp = p.join_many(&[f, term]);
if newp.exists() {
return Some(newp);
}
let f: &str = &format!("{:x}", first_char as uint);
let newp = p.join_many(&[f, term]);
if newp.exists() {
return Some(newp);
}
}
}
None
}