diff options
| author | lukeflo | 2024-09-23 23:55:04 +0200 |
|---|---|---|
| committer | lukeflo | 2024-09-23 23:55:04 +0200 |
| commit | 166bc53ac78be6219a63870447920c920734f640 (patch) | |
| tree | 5102bf131261f48c1fd311674da7ba94a792a06a /src/backend | |
| parent | 979b260f3e3b969e4da64c7e9bd9a4caaad24f9b (diff) | |
| download | bibiman-166bc53ac78be6219a63870447920c920734f640.tar.gz bibiman-166bc53ac78be6219a63870447920c920734f640.zip | |
add license informations
Diffstat (limited to 'src/backend')
| -rw-r--r-- | src/backend/bib.rs | 85 | ||||
| -rw-r--r-- | src/backend/cliargs.rs | 17 |
2 files changed, 64 insertions, 38 deletions
diff --git a/src/backend/bib.rs b/src/backend/bib.rs index aa7272f..6e913fd 100644 --- a/src/backend/bib.rs +++ b/src/backend/bib.rs @@ -1,51 +1,60 @@ +// bibiman - a TUI for managing BibLaTeX databases +// Copyright (C) 2024 lukeflo +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. +///// + use biblatex::Bibliography; -use regex::Regex; -use std::{ - fs, - path::{Path, PathBuf}, -}; +use std::{fs, path::PathBuf}; -use super::cliargs::{CLIArgs, PosArgs}; +use super::cliargs::PosArgs; // Set necessary fields // TODO: can surely be made more efficient/simpler -pub struct Bibi { - pub citekeys: Vec<String>, - // pub bibliography: Bibliography, -} - -pub fn get_bibfile(filename: impl AsRef<Path>) -> String { - let bibfile = fs::read_to_string(&filename).unwrap(); - bibfile -} - -pub fn get_citekeys(bibstring: &Bibliography) -> Vec<String> { - // let bib = Bibliography::parse(&get_bibfile(CLIArgs::parse_cli_args().bibfilearg)).unwrap(); - // // Define Regex to match citekeys - // let re = Regex::new(r"(?m)^\@[a-zA-Z]*\{(.*)\,").unwrap(); - // // Declare empty vector to fill with captured keys - // // Has to be Vec<&str> because of captures_iter method - // let mut keys = vec![]; - // for (_, [key]) in re.captures_iter(&bibfilestring).map(|c| c.extract()) { - // keys.push(key); - // } - // // Transform Vec<&str> to Vec<String> which is needed by the struct Bibi - // let mut citekeys: Vec<String> = keys.into_iter().map(String::from).collect(); - // // Sort vector items case-insensitive - // citekeys.sort_by_key(|name| name.to_lowercase()); - // citekeys - let mut citekeys: Vec<String> = bibstring.iter().map(|entry| entry.to_owned().key).collect(); - citekeys.sort_by_key(|name| name.to_lowercase()); - citekeys +pub struct BibiMain { + pub bibfile: PathBuf, // path to bibfile + pub bibfilestring: String, // content of bibfile as string + pub bibliography: Bibliography, // parsed bibliography + pub citekeys: Vec<String>, // list of all citekeys } -impl Bibi { +impl BibiMain { pub fn new() -> Self { // TODO: Needs check for config file path as soon as config file is impl - let bib = Bibliography::parse(&get_bibfile(PosArgs::parse_pos_args().bibfilearg)).unwrap(); + let bibfile = PosArgs::parse_pos_args().bibfilearg; + let bibfilestring = fs::read_to_string(&bibfile).unwrap(); + let bibliography = biblatex::Bibliography::parse(&bibfilestring).unwrap(); + let citekeys = Self::get_citekeys(&bibliography); Self { - citekeys: get_citekeys(&bib), - // bibliography: biblatex::Bibliography::parse(&bibfilestring).unwrap(), + bibfile, + bibfilestring, + bibliography, + citekeys, } } + + // get list of citekeys from the given bibfile + // this list is the base for further operations on the bibentries + // since it is the entry point of the biblatex crate. + pub fn get_citekeys(bibstring: &Bibliography) -> Vec<String> { + let mut citekeys: Vec<String> = + bibstring.iter().map(|entry| entry.to_owned().key).collect(); + citekeys.sort_by_key(|name| name.to_lowercase()); + citekeys + } +} + +pub struct BibiData { + pub citekey: Vec<String>, } diff --git a/src/backend/cliargs.rs b/src/backend/cliargs.rs index b820b6a..f3e9fcf 100644 --- a/src/backend/cliargs.rs +++ b/src/backend/cliargs.rs @@ -1,3 +1,20 @@ +// bibiman - a TUI for managing BibLaTeX databases +// Copyright (C) 2024 lukeflo +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. +///// + use core::panic; use std::path::{Path, PathBuf}; |
