├── .gitignore ├── AUTHORS ├── CHANGELOG ├── CNAME ├── CONTRIBUTING ├── COPYING ├── README.md ├── cli ├── docs │ ├── Makefile │ └── source │ │ ├── compile.rst │ │ ├── conf.py │ │ ├── index.rst │ │ └── reference.rst └── src │ ├── Makefile.am │ ├── actions │ ├── action.cpp │ ├── action.h │ ├── assign_action.cpp │ ├── assign_action.h │ ├── print_action.cpp │ ├── print_action.h │ ├── remove_action.cpp │ ├── remove_action.h │ ├── set_title_action.cpp │ ├── set_title_action.h │ ├── tags_statistics_action.cpp │ ├── tags_statistics_action.h │ ├── unassign_action.cpp │ └── unassign_action.h │ ├── bootstrap │ ├── common │ ├── cmd_param.h │ └── exceptions │ │ ├── base_exception.cpp │ │ ├── base_exception.h │ │ ├── cmd_usage_exceptions.cpp │ │ └── cmd_usage_exceptions.h │ ├── configure.ac │ ├── engine │ ├── cmd_manager.cpp │ └── cmd_manager.h │ ├── initializer.cpp │ ├── main.cpp │ ├── selectors │ ├── id_selector.cpp │ ├── id_selector.h │ ├── import_file_selector.cpp │ ├── import_file_selector.h │ ├── query_selector.cpp │ ├── query_selector.h │ ├── selector.cpp │ └── selector.h │ └── utilities │ ├── cmd_parser.cpp │ ├── cmd_parser.h │ ├── errno_translator.cpp │ ├── errno_translator.h │ ├── string_utils.cpp │ └── string_utils.h ├── docs ├── Makefile ├── _themes │ └── alabaster │ │ ├── LICENSE │ │ ├── __init__.py │ │ ├── _version.py │ │ ├── about.html │ │ ├── donate.html │ │ ├── layout.html │ │ ├── navigation.html │ │ ├── static │ │ ├── alabaster.css_t │ │ └── bird_black_32_0.png │ │ ├── support.py │ │ └── theme.conf ├── source │ ├── _static │ │ └── gplv3.png │ ├── conf.py │ ├── contribution.rst │ ├── developers │ │ ├── coding_style.rst │ │ ├── index.rst │ │ └── workflow.rst │ ├── index.rst │ ├── manual │ │ └── index.rst │ └── uis.rst └── src │ ├── compiler │ ├── CompilerStateMachine.odg │ └── CompilerStateMachine.svg │ ├── design_overview │ ├── abstract.tex │ ├── images │ │ └── main_components.png │ └── main.tex │ └── templates │ ├── main_template_begin.tex │ └── main_template_end.tex ├── libtocc ├── docs │ ├── Makefile │ └── source │ │ ├── _static │ │ ├── design-overview.odg │ │ └── design-overview.png │ │ ├── api_reference.rst │ │ ├── compile.rst │ │ ├── conf.py │ │ ├── index.rst │ │ └── overview.rst ├── src │ ├── Makefile.am │ ├── bootstrap │ ├── configure.ac │ ├── libtocc.h │ ├── libtocc.pc.in │ └── libtocc │ │ ├── check_exists.cpp │ │ ├── common │ │ ├── base_exception.cpp │ │ ├── base_exception.h │ │ ├── database_exceptions.cpp │ │ ├── database_exceptions.h │ │ ├── expr_exceptions.cpp │ │ ├── expr_exceptions.h │ │ ├── file_system_exceptions.cpp │ │ ├── file_system_exceptions.h │ │ ├── int_file_info.cpp │ │ ├── int_file_info.h │ │ └── runtime_exceptions.h │ │ ├── database │ │ ├── base23.cpp │ │ ├── base23.h │ │ ├── database.cpp │ │ ├── database.h │ │ ├── funcs.cpp │ │ ├── funcs.h │ │ └── scripts.h │ │ ├── engine │ │ ├── files_engine.cpp │ │ ├── files_engine.h │ │ ├── tags_engine.cpp │ │ └── tags_engine.h │ │ ├── exprs │ │ ├── compiled_expr.cpp │ │ ├── compiled_expr.h │ │ ├── compiled_expr_types.h │ │ ├── compiler.cpp │ │ ├── compiler.h │ │ ├── connectives.cpp │ │ ├── connectives.h │ │ ├── expr.h │ │ ├── fields.cpp │ │ ├── fields.h │ │ ├── functions.cpp │ │ ├── functions.h │ │ ├── operations.cpp │ │ ├── operations.h │ │ ├── query.cpp │ │ └── query.h │ │ ├── file_system │ │ ├── file_manager.cpp │ │ ├── file_manager.h │ │ └── helpers.cpp │ │ ├── front_end │ │ ├── file_info.cpp │ │ ├── file_info.h │ │ ├── manager.cpp │ │ ├── manager.h │ │ ├── tag_statistics.cpp │ │ └── tag_statistics.h │ │ └── utilities │ │ ├── file_info_converter.cpp │ │ ├── file_info_converter.h │ │ ├── file_utils.cpp │ │ └── file_utils.h └── tests │ ├── Makefile.am │ ├── bootstrap │ ├── configure.ac │ ├── database │ ├── database_basic_tests.cpp │ ├── database_initializer.cpp │ ├── duplicated_traditional_path_tests.cpp │ ├── expr_tests.cpp │ ├── find_empty_id_tests.cpp │ ├── get_file_tests.cpp │ ├── tag_operation_tests.cpp │ └── wild_card_tests.cpp │ ├── engine │ ├── files_engine_tests.cpp │ └── tags_engine_tests.cpp │ ├── file_system │ └── file_system_basic_tests.cpp │ ├── front_end │ ├── file_info_tests.cpp │ ├── front_end_assign_tag_tests.cpp │ ├── front_end_assign_tag_wrong_tests.cpp │ ├── front_end_delete_file_tests.cpp │ ├── front_end_get_tests.cpp │ ├── front_end_import_file_tests.cpp │ ├── front_end_import_utf_file_tests.cpp │ ├── front_end_initializer.cpp │ ├── front_end_set_file_title.cpp │ ├── front_end_tag_statistics_tests.cpp │ └── query_files_tests.cpp │ ├── main.cpp │ └── utilities │ └── file_utils_tests.cpp └── toccfs ├── docs ├── Makefile └── source │ ├── compile.rst │ ├── conf.py │ └── index.rst └── src ├── Makefile.am ├── bootstrap ├── configure.ac ├── engine ├── fs_handler.cpp └── fs_handler.h ├── fuse ├── fuse_interface.cpp └── fuse_interface.h ├── main.cpp └── utils ├── string_utils.cpp └── string_utils.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | 6 | # Compiled Dynamic libraries 7 | *.so 8 | *.dylib 9 | 10 | # Compiled Static libraries 11 | *.lai 12 | *.la 13 | *.a 14 | 15 | # Build directories 16 | build/ 17 | bin/ 18 | 19 | # Backup files 20 | *~ 21 | 22 | # Auto tools generated files. 23 | .deps/ 24 | .libs/ 25 | Makefile 26 | Makefile.in 27 | aclocal.m4 28 | autom4te.cache/ 29 | config.guess 30 | config.log 31 | config.status 32 | config.sub 33 | configure 34 | depcomp 35 | install-sh 36 | libtool 37 | ltmain.sh 38 | missing 39 | compile 40 | libtocc/src/libtocc.pc 41 | libtocc/tests/libtocctests 42 | 43 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | 2 | This files lists people who contributed to the Tocc project. In order they join 3 | the project. 4 | 5 | Authors 6 | ------- 7 | 8 | + Aidin Gharibnavaz 9 | (Github profile: https://github.com/aidin36/) 10 | Developer and current maintainer of the project. 11 | 12 | + Yassine Hlioui 13 | (Github profile: https://github.com/hlyassine/) 14 | Developer 15 | 16 | + Rakina Zata Amni 17 | (Github profile: https://github.com/rakina) 18 | Developer 19 | 20 | + Ruoxi Wang 21 | (Github profile: https://github.com/hart-wang) 22 | Developer 23 | 24 | + Dick Thiebaud 25 | (Github profile: https://github.com/DThiebaud) 26 | Developer 27 | 28 | + Kevin Patrick 29 | (Github profile: https://github.com/kpmac92) 30 | Developer 31 | 32 | + Gaurav Pruthi 33 | (Github profile: https://github.com/gauravpruthi) 34 | Developer 35 | 36 | + John Olinda 37 | (Github profile: https://github.com/jackivan88) 38 | Reviewed documents 39 | 40 | 41 | Acknowledgment 42 | -------------- 43 | 44 | + Mehdi Sadeghi 45 | (Github profile: https://github.com/mehdix) 46 | Initial idea of the project born when Aidin and Mehdi were talking about 47 | classifying of files. 48 | 49 | + Nastaran Saffar 50 | She developed some of the basic ideas about User Interface and useful features. 51 | 52 | 53 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | 2 | v1.0.1 3 | * Bug fixed: Two process couldn't use libtocc::Manager at the same time. 4 | * Documentations improved. 5 | 6 | v1.0.0 7 | * API of libtocc's expressions cleaned up. 8 | * Not and WildCard added to expressions. 9 | * CLI uses wild card in its queries. 10 | * Better argument parsing in CLI (user don't have to hit space 11 | before and after operations in query, and she can user equal 12 | sign in command line arguments.) 13 | * Now user must initialize a directory before use it as 14 | Tocc Managed File System. 15 | * --all-tags renamed to --tags-statistics, and its behaviour 16 | improved. 17 | * tests of libtocc improved. 18 | * Toccfs is implemented. 19 | * Preventing duplicated traditional paths. 20 | * When importing a file, auto-title contains file's extension too. 21 | * Bug fix. 22 | 23 | v0.3.0: 24 | * --set-title added to CLI. 25 | * --remove added to CLI. 26 | * --print now accepts formatting. 27 | * --all-tags added to CLI. 28 | * `physical_path' property added to FileInfo class. 29 | * Better memory management in Query and Expr classes. 30 | 31 | v0.2.0: 32 | * A memory leak in libtocc fixed. 33 | * --assign added to CLI. 34 | * --query added to CLI. 35 | * Better build scripts. 36 | * Minor bug fixes. 37 | 38 | -- Aidin Gharibnavaz Sat, 5 Nov 2014 06:44:32 +0430 39 | 40 | -------------------------------------------------------------------------------- /CNAME: -------------------------------------------------------------------------------- 1 | t-o-c-c.com 2 | -------------------------------------------------------------------------------- /CONTRIBUTING: -------------------------------------------------------------------------------- 1 | If you're interest in contributing to Tocc project, there's a lot of things 2 | you can do. Please refer to this page for more information: 3 | 4 | https://tocc.aidinhut.com/contribution.html 5 | 6 | Also, there's Coding Style guid for developers that should be followed: 7 | 8 | https://tocc.aidinhut.com/developers/coding_style.html 9 | 10 | In case of any question, you can contact Aidin by the following e-mail address: 11 | 12 | aidin (AT) aidinhut.com 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Tocc, a Tool for Obsessive Compulsive Classifiers 2 | ================================================ 3 | 4 | Introduction 5 | ------------ 6 | 7 | Tocc is a tag-based file management system. It also includes a tag-based file 8 | system called Toccfs. The goal of Tocc is to provide a better system for 9 | classifying files which is more flexible than classic file systems based on a 10 | tree of files and directories. 11 | 12 | For more information about why Tocc was created, whether you need it, its vision, and 13 | what it can be used for, take a look at its web page: 14 | 15 | https://tocc.aidinhut.com 16 | 17 | Copyright 18 | --------- 19 | Tocc is free software and is released under the terms of Gnu General Public 20 | License version 3. Refer to COPYING file for the full license. 21 | 22 | Building Source 23 | --------------- 24 | Tocc consist of three components: ``libtocc``, ``cli`` and ``toccfs``. 25 | ``libtocc`` is the heart of the system. ``cli`` and ``toccfs`` are two 26 | interfaces for the Tocc system. 27 | 28 | [How to compile libtocc](https://tocc.aidinhut.com/libtocc/compile.html) 29 | 30 | [How to compile cli](https://tocc.aidinhut.com/cli/compile.html) 31 | 32 | [How to compile toccfs](https://tocc.aidinhut.com/toccfs/compile.html) 33 | 34 | Building Documents 35 | ------------------ 36 | If you get the source code from the Github repository, only the source of the 37 | documents is available. To build them, you need *Sphinx*. You can either 38 | install it from your distro's package manager, or get it from its website: 39 | 40 | http://sphinx-doc.org/ 41 | 42 | Then, go to `docs` directory in the root and inside each directory of the 43 | repository and run `make html`. Then, you can find the documentation as HTML 44 | files in the `build\html` directory inside the `docs`. 45 | 46 | Contact 47 | ------- 48 | Currently, Tocc is maintain by Aidin Gharibnavaz. You can contact him at the 49 | following e-mail address: 50 | 51 | aidin (at) aidinhut (dot) com 52 | 53 | You can find the development team by visiting Tocc's Github page: 54 | 55 | https://github.com/aidin36/tocc/ 56 | -------------------------------------------------------------------------------- /cli/docs/source/compile.rst: -------------------------------------------------------------------------------- 1 | 2 | 3 | .. toctree:: 4 | :hidden: 5 | 6 | 7 | How to Compile Tocc's Official CLI 8 | ================================== 9 | 10 | In order to compile CLI, you need first have ``libtocc`` compiled and 11 | installed. Follow the instructions in 12 | `How to Compile And Use libtocc `_ page. 13 | 14 | Source of the CLI is available in ``cli/src/`` directory. Change your 15 | current directory to it, and follow the instructions. 16 | 17 | Bootstrapping 18 | ------------- 19 | 20 | First step is to create a ``configure`` script. If you downloaded a released 21 | source package, this step already done. You can skip it. 22 | 23 | You need *Gnu Auto Tools*, e.g. *Libtool*, *Autoconf* and *Automake* installed. 24 | Then, simply invoke ``bootstrap`` script:: 25 | 26 | ./bootstrap 27 | 28 | Configuring 29 | ----------- 30 | 31 | Previous step created a ``configure`` script. Normally, you don't need to pass 32 | any options:: 33 | 34 | ./configure 35 | 36 | By default, CLI binary (``tocc``) will be installed in the default ``bin`` 37 | directory. Usually ``/usr/local/bin/``. If you want to install it into another 38 | directory, you can pass ``--prefix`` option to ``configure`` script:: 39 | 40 | ./configure --prefix=/opt/tocc/ 41 | 42 | Which installs binary in ``/opt/tocc/bin/``. 43 | 44 | Making 45 | ------ 46 | 47 | Now that you configured CLI, you can invoke ``make`` in order to compile the 48 | source:: 49 | 50 | make 51 | 52 | Installing 53 | ---------- 54 | 55 | If previous step goes without any error, simply invoke:: 56 | 57 | make install 58 | 59 | (Usually, you need super user access to invoke this command.) 60 | 61 | This will install ``tocc`` binary in the directory you specified using 62 | ``--prefix`` (or the default directory). 63 | 64 | 65 | -------------------------------------------------------------------------------- /cli/src/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Makefile.am -- Process this file with automake to produce Makefile.in 2 | 3 | # Output and source files. 4 | bin_PROGRAMS = tocc tocc-initialize 5 | 6 | tocc_SOURCES = common/exceptions/base_exception.cpp common/exceptions/cmd_usage_exceptions.cpp utilities/errno_translator.cpp utilities/cmd_parser.cpp utilities/string_utils.cpp selectors/selector.cpp selectors/id_selector.cpp selectors/import_file_selector.cpp selectors/query_selector.cpp actions/action.cpp actions/print_action.cpp actions/assign_action.cpp actions/unassign_action.cpp actions/tags_statistics_action.cpp actions/remove_action.cpp actions/set_title_action.cpp engine/cmd_manager.cpp main.cpp 7 | 8 | tocc_initialize_SOURCES = utilities/errno_translator.cpp initializer.cpp 9 | -------------------------------------------------------------------------------- /cli/src/actions/action.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include "actions/action.h" 20 | 21 | 22 | namespace tocccli 23 | { 24 | 25 | Action::~Action() 26 | { 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /cli/src/actions/action.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef TOCCCLI_ACTION_HANDLER_H_INCLUDED 20 | #define TOCCCLI_ACTION_HANDLER_H_INCLUDED 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | #include "common/cmd_param.h" 28 | 29 | namespace tocccli 30 | { 31 | 32 | /* 33 | * Base class for handlers of action parameters. 34 | */ 35 | class Action 36 | { 37 | public: 38 | 39 | virtual ~Action(); 40 | 41 | /* 42 | * Returns short form of the parameter. 43 | */ 44 | virtual std::string get_short_form() = 0; 45 | 46 | /* 47 | * Returns long form of the parameter. 48 | */ 49 | virtual std::string get_long_form() = 0; 50 | 51 | /* 52 | * Returns the help text of the parameter. 53 | * (Full help text, include parameter itself.) 54 | */ 55 | virtual std::string get_help_text() = 0; 56 | 57 | /* 58 | * Executes the action. 59 | * 60 | * @param files: Files to do the action on. 61 | * @param cmd_arguments: Arguments of this parameter that is passed to 62 | * command line. 63 | */ 64 | virtual void execute(std::vector files, std::vector cmd_arguments) = 0; 65 | }; 66 | } 67 | 68 | #endif /* TOCCCLI_ACTION_HANDLER_H_INCLUDED */ 69 | -------------------------------------------------------------------------------- /cli/src/actions/assign_action.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include "actions/assign_action.h" 20 | #include "common/exceptions/cmd_usage_exceptions.h" 21 | 22 | 23 | namespace tocccli 24 | { 25 | 26 | AssignAction::AssignAction(libtocc::Manager* manager) 27 | { 28 | this->libtocc_manager = manager; 29 | } 30 | 31 | AssignAction::~AssignAction() 32 | { 33 | } 34 | 35 | std::string AssignAction::get_short_form() 36 | { 37 | return "-a"; 38 | } 39 | 40 | std::string AssignAction::get_long_form() 41 | { 42 | return "--assign"; 43 | } 44 | 45 | std::string AssignAction::get_help_text() 46 | { 47 | return "-a, --assign=TAGS\tAssigns tags to files. TAGS is a list of tags\n"\ 48 | " \tseparated by space."; 49 | } 50 | 51 | void AssignAction::execute(std::vector files, std::vector cmd_arguments) 52 | { 53 | if (cmd_arguments.empty()) 54 | { 55 | throw InvalidParametersError("-a, --assign, must have at least one argument."); 56 | } 57 | 58 | // Converting files vector to array. 59 | const char* files_array[files.size()]; 60 | for (int i = 0; i < files.size(); i++) 61 | { 62 | files_array[i] = files[i].get_id(); 63 | } 64 | 65 | // Converting tags vector to a tags collection. 66 | libtocc::TagsCollection tags_collection(cmd_arguments.size()); 67 | std::vector::iterator args_iterator = cmd_arguments.begin(); 68 | for (; args_iterator != cmd_arguments.end(); args_iterator++) 69 | { 70 | tags_collection.add_tag(args_iterator->c_str()); 71 | } 72 | 73 | this->libtocc_manager->assign_tags(files_array, files.size(), &tags_collection); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /cli/src/actions/assign_action.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef TOCCCLI_ASSIGN_ACTION_H_INCLUDED 20 | #define TOCCCLI_ASSIGN_ACTION_H_INCLUDED 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | #include "common/cmd_param.h" 29 | #include "actions/action.h" 30 | 31 | 32 | namespace tocccli 33 | { 34 | 35 | /* 36 | * This action assign tags to files. 37 | */ 38 | class AssignAction : public Action 39 | { 40 | public: 41 | 42 | AssignAction(libtocc::Manager* manager); 43 | 44 | ~AssignAction(); 45 | 46 | /* 47 | * Returns short form of the parameter. 48 | */ 49 | virtual std::string get_short_form(); 50 | 51 | /* 52 | * Returns long form of the parameter. 53 | */ 54 | virtual std::string get_long_form(); 55 | 56 | /* 57 | * Returns the help text of the parameter. 58 | * (Full help text, include parameter itself.) 59 | */ 60 | virtual std::string get_help_text(); 61 | 62 | /* 63 | * Executes the action. 64 | * 65 | * @param files: Files to do the action on. 66 | * @param cmd_arguments: Arguments of this parameter that is passed to 67 | * command line. 68 | */ 69 | virtual void execute(std::vector files, std::vector cmd_arguments); 70 | 71 | private: 72 | 73 | libtocc::Manager* libtocc_manager; 74 | }; 75 | } 76 | 77 | #endif /* TOCCCLI_ASSIGN_ACTION_H_INCLUDED */ 78 | -------------------------------------------------------------------------------- /cli/src/actions/print_action.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef TOCCCLI_PRINT_ACTION_H_INCLUDED 20 | #define TOCCCLI_PRINT_ACTION_H_INCLUDED 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | #include "common/cmd_param.h" 29 | #include "actions/action.h" 30 | 31 | 32 | namespace tocccli 33 | { 34 | 35 | /* 36 | * This action prints a file on the output when executes. 37 | */ 38 | class PrintAction : public Action 39 | { 40 | public: 41 | PrintAction(libtocc::Manager* manager); 42 | 43 | virtual ~PrintAction(); 44 | 45 | /* 46 | * Returns short form of the parameter. 47 | */ 48 | virtual std::string get_short_form(); 49 | 50 | /* 51 | * Returns long form of the parameter. 52 | */ 53 | virtual std::string get_long_form(); 54 | 55 | /* 56 | * Returns the help text of the parameter. 57 | * (Full help text, include parameter itself.) 58 | */ 59 | virtual std::string get_help_text(); 60 | 61 | /* 62 | * Executes the action. 63 | * 64 | * @param files: Files to do the action on. 65 | * @param cmd_arguments: Arguments of this parameter that is passed to 66 | * command line. 67 | */ 68 | virtual void execute(std::vector files, std::vector cmd_arguments); 69 | 70 | private: 71 | libtocc::Manager* libtocc_manager; 72 | }; 73 | } 74 | 75 | #endif /* TOCCCLI_PRINT_ACTION_H_INCLUDED */ 76 | -------------------------------------------------------------------------------- /cli/src/actions/remove_action.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include "actions/remove_action.h" 20 | #include "common/exceptions/cmd_usage_exceptions.h" 21 | #include 22 | 23 | namespace tocccli 24 | { 25 | 26 | RemoveAction::RemoveAction(libtocc::Manager* manager) 27 | { 28 | libtocc_manager = manager; 29 | } 30 | 31 | RemoveAction::~RemoveAction() 32 | { 33 | } 34 | 35 | std::string RemoveAction::get_short_form() 36 | { 37 | return "-r"; 38 | } 39 | 40 | std::string RemoveAction::get_long_form() 41 | { 42 | return "--remove"; 43 | } 44 | 45 | std::string RemoveAction::get_help_text() 46 | { 47 | return "-r, --remove\tRemoves the giving file(s)."; 48 | } 49 | 50 | void RemoveAction::execute(std::vector files, std::vector cmd_arguments) 51 | { 52 | if(!cmd_arguments.empty()) 53 | { 54 | throw InvalidParametersError("-r, --remove, doesn't accept arguments."); 55 | } 56 | 57 | //Extracting files ids into an array 58 | const char* file_ids[files.size()]; 59 | for(int i = 0; i < files.size(); i++) 60 | { 61 | file_ids[i] = files[i].get_id(); 62 | } 63 | 64 | //Removing the files 65 | if(libtocc_manager != 0) 66 | { 67 | this->libtocc_manager->remove_files(file_ids, files.size()); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /cli/src/actions/remove_action.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef TOCCCLI_REMOVE_ACTION_HANDLER_H_INCLUDED 20 | #define TOCCCLI_REMOVE_ACTION_HANDLER_H_INCLUDED 21 | 22 | #include "actions/action.h" 23 | 24 | namespace libtocc 25 | { 26 | class Manager; 27 | } 28 | 29 | namespace tocccli 30 | { 31 | /* 32 | * This action removes files when executed 33 | */ 34 | class RemoveAction : public Action 35 | { 36 | public: 37 | 38 | RemoveAction(libtocc::Manager* manager); 39 | 40 | virtual ~RemoveAction(); 41 | 42 | /* 43 | * Returns short form of the parameter. 44 | */ 45 | virtual std::string get_short_form(); 46 | 47 | /* 48 | * Returns long form of the parameter. 49 | */ 50 | virtual std::string get_long_form(); 51 | 52 | /* 53 | * Returns the help text of the parameter. 54 | * (Full help text, include parameter itself.) 55 | */ 56 | virtual std::string get_help_text(); 57 | 58 | /* 59 | * Executes the action. 60 | * 61 | * @param files: Files to do the action on. 62 | * @param cmd_arguments: Arguments of this parameter that is passed to 63 | * command line. 64 | */ 65 | virtual void execute(std::vector files, std::vector cmd_arguments); 66 | 67 | private: 68 | libtocc::Manager* libtocc_manager; 69 | }; 70 | } 71 | 72 | #endif /* TOCCCLI_REMOVE_ACTION_HANDLER_H_INCLUDED */ 73 | -------------------------------------------------------------------------------- /cli/src/actions/set_title_action.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include "actions/set_title_action.h" 20 | 21 | #include 22 | 23 | #include "common/exceptions/cmd_usage_exceptions.h" 24 | #include 25 | 26 | 27 | namespace tocccli 28 | { 29 | 30 | SetTitleAction::SetTitleAction(libtocc::Manager* manager) 31 | { 32 | this->libtocc_manager = manager; 33 | } 34 | 35 | SetTitleAction::~SetTitleAction() 36 | { 37 | } 38 | 39 | std::string SetTitleAction::get_short_form() 40 | { 41 | return "-t"; 42 | } 43 | 44 | std::string SetTitleAction::get_long_form() 45 | { 46 | return "--set-title"; 47 | } 48 | 49 | std::string SetTitleAction::get_help_text() 50 | { 51 | return "-t, --set-title=TITLE\tSets the title of files."; 52 | } 53 | 54 | void SetTitleAction::execute(std::vector files, 55 | std::vector cmd_arguments) 56 | { 57 | if (cmd_arguments.empty() || cmd_arguments.size() > 1) 58 | { 59 | throw InvalidParametersError("-t, --set-title must have a title as an argument."); 60 | } 61 | 62 | //extract file ids to an array 63 | const char* file_ids[files.size()]; 64 | for(int i = 0; i < files.size(); i++) 65 | { 66 | file_ids[i] = files[i].get_id(); 67 | } 68 | 69 | this->libtocc_manager->set_titles(file_ids, files.size(), cmd_arguments.front().c_str()); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /cli/src/actions/set_title_action.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef TOCCCLI_SET_TITLE_ACTION_H_INCLUDED 20 | #define TOCCCLI_SET_TITLE_ACTION_H_INCLUDED 21 | 22 | #include 23 | #include 24 | 25 | #include "common/cmd_param.h" 26 | #include "actions/action.h" 27 | 28 | namespace libtocc 29 | { 30 | class Manager; 31 | } 32 | 33 | namespace tocccli 34 | { 35 | /* 36 | * This action sets the title of the files on the output, 37 | * it silently ignores the files that don't exist. 38 | */ 39 | class SetTitleAction : public Action 40 | { 41 | public: 42 | SetTitleAction(libtocc::Manager* manager); 43 | 44 | virtual ~SetTitleAction(); 45 | 46 | /* 47 | * Returns short form of the parameter. 48 | */ 49 | virtual std::string get_short_form(); 50 | 51 | /* 52 | * Returns long form of the parameter. 53 | */ 54 | virtual std::string get_long_form(); 55 | 56 | /* 57 | * Returns the help text of the parameter. 58 | * (Full help text, include parameter itself.) 59 | */ 60 | virtual std::string get_help_text(); 61 | 62 | /* 63 | * Executes the action. 64 | * 65 | * @param files: Files to do the action on. 66 | * @param cmd_arguments: Arguments of this parameter that is passed to 67 | * command line. 68 | */ 69 | virtual void execute(std::vector files, std::vector cmd_arguments); 70 | 71 | private: 72 | libtocc::Manager* libtocc_manager; 73 | }; 74 | } 75 | 76 | #endif /* TOCCCLI_SET_TITLE_ACTION_H_INCLUDED */ 77 | -------------------------------------------------------------------------------- /cli/src/actions/tags_statistics_action.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include "actions/tags_statistics_action.h" 20 | 21 | #include 22 | 23 | #include "libtocc/front_end/tag_statistics.h" 24 | #include "common/exceptions/cmd_usage_exceptions.h" 25 | 26 | 27 | namespace tocccli 28 | { 29 | 30 | TagsStatisticsAction::TagsStatisticsAction(libtocc::Manager* manager) 31 | { 32 | this->libtocc_manager = manager; 33 | } 34 | 35 | TagsStatisticsAction::~TagsStatisticsAction() 36 | { 37 | } 38 | 39 | std::string TagsStatisticsAction::get_short_form() 40 | { 41 | return "-s"; 42 | } 43 | 44 | std::string TagsStatisticsAction::get_long_form() 45 | { 46 | return "--tags-statistics"; 47 | } 48 | 49 | std::string TagsStatisticsAction::get_help_text() 50 | { 51 | return "-s, --tags-statistics\tPrints all tags, and\n"\ 52 | " \tnumber of files each tag assigned to."; 53 | } 54 | 55 | void TagsStatisticsAction::execute(std::vector files, 56 | std::vector cmd_arguments) 57 | { 58 | if (!cmd_arguments.empty()) 59 | { 60 | throw InvalidParametersError("--all-tags don't accept any arguments."); 61 | } 62 | 63 | libtocc::TagStatisticsCollection statistics_collection; 64 | 65 | // Getting statistics. 66 | if (files.empty()) 67 | { 68 | statistics_collection = this->libtocc_manager->get_tags_statistics(); 69 | } 70 | else 71 | { 72 | // Converting files vector to array of IDs. 73 | const char* files_array[files.size()]; 74 | for (int i = 0; i < files.size(); i++) 75 | { 76 | files_array[i] = files[i].get_id(); 77 | } 78 | 79 | statistics_collection = 80 | this->libtocc_manager->get_tags_statistics(files_array, files.size()); 81 | } 82 | 83 | // Print statistics in a pretty format. 84 | std::cout << "Assigned Files\tTag" << std::endl; 85 | std::cout << "--------------\t---" << std::endl; 86 | 87 | libtocc::TagStatisticsCollection::Iterator iterator(&statistics_collection); 88 | for (; !iterator.is_finished(); iterator.next()) 89 | { 90 | libtocc::TagStatistics tag_statistics = iterator.get(); 91 | std::cout << tag_statistics.get_assigned_files() << "\t\t"; 92 | std::cout << tag_statistics.get_tag() << std::endl; 93 | } 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /cli/src/actions/tags_statistics_action.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef TOCCCLI_ALL_TAGS_ACTION_H_INCLUDED 20 | #define TOCCCLI_ALL_TAGS_ACTION_H_INCLUDED 21 | 22 | #include "libtocc/front_end/manager.h" 23 | 24 | #include "actions/action.h" 25 | 26 | 27 | namespace tocccli 28 | { 29 | 30 | /* 31 | * Query statistics of all tags and prints them. 32 | */ 33 | class TagsStatisticsAction : public Action 34 | { 35 | public: 36 | 37 | TagsStatisticsAction(libtocc::Manager* manager); 38 | 39 | ~TagsStatisticsAction(); 40 | 41 | /* 42 | * Returns short form of the parameter. 43 | */ 44 | virtual std::string get_short_form(); 45 | 46 | /* 47 | * Returns long form of the parameter. 48 | */ 49 | virtual std::string get_long_form(); 50 | 51 | /* 52 | * Returns the help text of the parameter. 53 | * (Full help text, include parameter itself.) 54 | */ 55 | virtual std::string get_help_text(); 56 | 57 | /* 58 | * Executes the action. 59 | * 60 | * @param files: Files to do the action on. 61 | * @param cmd_arguments: Arguments of this parameter that is passed to 62 | * command line. 63 | */ 64 | virtual void execute(std::vector files, std::vector cmd_arguments); 65 | 66 | private: 67 | libtocc::Manager* libtocc_manager; 68 | }; 69 | } 70 | 71 | #endif /* TOCCCLI_ALL_TAGS_ACTION_H_INCLUDED */ 72 | -------------------------------------------------------------------------------- /cli/src/actions/unassign_action.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include "actions/unassign_action.h" 20 | #include "common/exceptions/cmd_usage_exceptions.h" 21 | 22 | 23 | namespace tocccli 24 | { 25 | 26 | UnassignAction::UnassignAction(libtocc::Manager* manager) 27 | { 28 | this->libtocc_manager = manager; 29 | } 30 | 31 | UnassignAction::~UnassignAction() 32 | { 33 | } 34 | 35 | std::string UnassignAction::get_short_form() 36 | { 37 | return "-u"; 38 | } 39 | 40 | std::string UnassignAction::get_long_form() 41 | { 42 | return "--unassign"; 43 | } 44 | 45 | std::string UnassignAction::get_help_text() 46 | { 47 | return "-u, --unassign=TAGS\tUnassigns tags from files. TAGS is a list of tags\n"\ 48 | " \tseparated by space."; 49 | } 50 | 51 | void UnassignAction::execute(std::vector files, std::vector cmd_arguments) 52 | { 53 | if (cmd_arguments.empty()) 54 | { 55 | throw InvalidParametersError("-u, --unassign, must have at least one argument."); 56 | } 57 | 58 | // Converting files vector to array. 59 | const char* files_array[files.size()]; 60 | for (int i = 0; i < files.size(); i++) 61 | { 62 | files_array[i] = files[i].get_id(); 63 | } 64 | 65 | // Converting tags vector to a tags collection. 66 | libtocc::TagsCollection tags_collection(cmd_arguments.size()); 67 | std::vector::iterator args_iterator = cmd_arguments.begin(); 68 | for (; args_iterator != cmd_arguments.end(); args_iterator++) 69 | { 70 | tags_collection.add_tag(args_iterator->c_str()); 71 | } 72 | 73 | this->libtocc_manager->unassign_tags(files_array, files.size(), &tags_collection); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /cli/src/actions/unassign_action.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef TOCCCLI_UNASSIGN_ACTION_H_INCLUDED 20 | #define TOCCCLI_UNASSIGN_ACTION_H_INCLUDED 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | #include "common/cmd_param.h" 29 | #include "actions/action.h" 30 | 31 | 32 | namespace tocccli 33 | { 34 | 35 | /* 36 | * This action unassign tags to files. 37 | */ 38 | class UnassignAction : public Action 39 | { 40 | public: 41 | 42 | UnassignAction(libtocc::Manager* manager); 43 | 44 | ~UnassignAction(); 45 | 46 | /* 47 | * Returns short form of the parameter. 48 | */ 49 | virtual std::string get_short_form(); 50 | 51 | /* 52 | * Returns long form of the parameter. 53 | */ 54 | virtual std::string get_long_form(); 55 | 56 | /* 57 | * Returns the help text of the parameter. 58 | * (Full help text, include parameter itself.) 59 | */ 60 | virtual std::string get_help_text(); 61 | 62 | /* 63 | * Executes the action. 64 | * 65 | * @param files: Files to do the action on. 66 | * @param cmd_arguments: Arguments of this parameter that is passed to 67 | * command line. 68 | */ 69 | virtual void execute(std::vector files, std::vector cmd_arguments); 70 | 71 | private: 72 | 73 | libtocc::Manager* libtocc_manager; 74 | }; 75 | } 76 | 77 | #endif /* TOCCCLI_UNASSIGN_ACTION_H_INCLUDED */ 78 | -------------------------------------------------------------------------------- /cli/src/bootstrap: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | aclocal 6 | autoconf -Wall 7 | automake -Wall --add-missing 8 | -------------------------------------------------------------------------------- /cli/src/common/cmd_param.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef TOCCCLI_CMD_PARAM_H_INCLUDED 20 | #define TOCCCLI_CMD_PARAM_H_INCLUDED 21 | 22 | #include 23 | #include 24 | 25 | namespace tocccli 26 | { 27 | 28 | /* 29 | * Represents a command line parameter. 30 | */ 31 | class CmdParam 32 | { 33 | public: 34 | 35 | /* 36 | * Command line option. 37 | */ 38 | std::string option; 39 | 40 | /* 41 | * List of arguments of the option. 42 | * It will be an empty vector if no argument pass 43 | * for this option. 44 | */ 45 | std::vector arguments; 46 | }; 47 | } 48 | 49 | #endif /* TOCCCLI_CMD_PARAM_H_INCLUDED */ 50 | -------------------------------------------------------------------------------- /cli/src/common/exceptions/base_exception.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include "common/exceptions/base_exception.h" 20 | 21 | 22 | namespace tocccli 23 | { 24 | BaseException::BaseException(std::string message) throw() 25 | { 26 | this->message = message; 27 | } 28 | 29 | BaseException::~BaseException() throw() 30 | { 31 | } 32 | 33 | const char* BaseException::what() const throw() 34 | { 35 | return this->message.c_str(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /cli/src/common/exceptions/base_exception.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef TOCCCLI_BASE_EXCEPTION_H_INCLUDED 20 | #define TOCCCLI_BASE_EXCEPTION_H_INCLUDED 21 | 22 | #include 23 | #include 24 | 25 | 26 | namespace tocccli 27 | { 28 | /* 29 | * Base class for all exceptions in tocccli. 30 | */ 31 | class BaseException : public std::exception 32 | { 33 | public: 34 | BaseException(std::string message) throw(); 35 | 36 | virtual ~BaseException() throw(); 37 | 38 | virtual const char* what() const throw(); 39 | 40 | private: 41 | std::string message; 42 | }; 43 | 44 | } 45 | 46 | #endif /* TOCCCLI_BASE_EXCEPTION_H_INCLUDED */ 47 | -------------------------------------------------------------------------------- /cli/src/common/exceptions/cmd_usage_exceptions.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include "common/exceptions/cmd_usage_exceptions.h" 20 | 21 | namespace tocccli 22 | { 23 | 24 | CmdUsageBaseException::CmdUsageBaseException(std::string message) throw() 25 | : BaseException(message) 26 | { 27 | } 28 | 29 | CmdUsageBaseException::~CmdUsageBaseException() throw() 30 | { 31 | } 32 | 33 | 34 | InvalidParametersError::InvalidParametersError(std::string message) throw() 35 | : CmdUsageBaseException(message) 36 | { 37 | } 38 | 39 | InvalidParametersError::~InvalidParametersError() throw() 40 | { 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /cli/src/common/exceptions/cmd_usage_exceptions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef TOCCCLI_CMD_USAGE_EXCEPTIONS_H_INCLUDED 20 | #define TOCCCLI_CMD_USAGE_EXCEPTIONS_H_INCLUDED 21 | 22 | #include "common/exceptions/base_exception.h" 23 | 24 | namespace tocccli 25 | { 26 | 27 | /* 28 | * Base class of all exceptions that are related to invocation of CLI command. 29 | */ 30 | class CmdUsageBaseException : public BaseException 31 | { 32 | public: 33 | CmdUsageBaseException(std::string message) throw(); 34 | 35 | virtual ~CmdUsageBaseException() throw(); 36 | 37 | }; 38 | 39 | /* 40 | * Throws when parameters that are passed to CLI is wrong. 41 | */ 42 | class InvalidParametersError : public CmdUsageBaseException 43 | { 44 | public: 45 | InvalidParametersError(std::string message) throw(); 46 | 47 | virtual ~InvalidParametersError() throw(); 48 | }; 49 | } 50 | 51 | #endif /* TOCCCLI_CMD_USAGE_EXCEPTIONS_H_INCLUDED */ 52 | -------------------------------------------------------------------------------- /cli/src/configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ([2.69]) 5 | AC_INIT([tocc-cli], [1.0.1], [tocc@aidinhut.com], [Official CLI of tocc], [https://tocc.aidinhut.com]) 6 | AC_CONFIG_SRCDIR([main.cpp]) 7 | #AC_CONFIG_HEADERS([config.h]) 8 | 9 | # Initializing Automake. 10 | # [foreign] added, so automake won't check for missing NEWS, README, etc. 11 | AM_INIT_AUTOMAKE([foreign]) 12 | 13 | # Checks for programs. 14 | AC_PROG_CXX 15 | AC_PROG_CC 16 | 17 | # Checks for header files. 18 | AC_CHECK_HEADERS([unistd.h]) 19 | 20 | # Checks for typedefs, structures, and compiler characteristics. 21 | AC_CHECK_HEADER_STDBOOL 22 | 23 | # Checks for library functions. 24 | AC_CHECK_FUNCS([getcwd]) 25 | 26 | # Checks for UnQlite 27 | # Since it's a C header, we need to set lang to C 28 | AC_LANG_PUSH(C) 29 | AC_CHECK_HEADER([unqlite.h], [], [AC_MSG_ERROR([Could not find unqlite.h header. Please make sure you have this header in your include path. Refer to documents for more info.])]) 30 | AC_SEARCH_LIBS([unqlite_open], [unqlite], [], [AC_MSG_ERROR([Could not find unqlite library. Please make sure you have this library in your libs path. Refer to documentations for more info.])]) 31 | 32 | # Checking for libtocc. 33 | # Setting lang to C++, because followings all are C++. 34 | AC_LANG_PUSH(C++) 35 | # The fourth argument is: don't try to compile this header. 36 | AC_CHECK_HEADER([libtocc/front_end/manager.h], [], [AC_MSG_ERROR([Could not find libtocc/front_end/manager.h header. Please make sure you have libtocc headers in your include path. Refer to documents for more info.])], [-]) 37 | # `libtocc_exists' function used to check for libtocc. See the documentation 38 | # about how to check for libtocc with Autoconf. 39 | AC_SEARCH_LIBS([libtocc_exists], [tocc], [], [AC_MSG_ERROR([Could not find libtocc library. Please make sure you have this library in your libs path. Refer to documentations for more info.])]) 40 | 41 | # Changing back the language to C 42 | AC_LANG_POP 43 | 44 | # Output files. 45 | AC_CONFIG_FILES([Makefile]) 46 | AC_OUTPUT 47 | -------------------------------------------------------------------------------- /cli/src/engine/cmd_manager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef TOCCCLI_CMD_MANAGER_H_INCLUDED 20 | #define TOCCCLI_CMD_MANAGER_H_INCLUDED 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | #include "common/cmd_param.h" 28 | #include "actions/action.h" 29 | #include "selectors/selector.h" 30 | 31 | namespace tocccli 32 | { 33 | 34 | /* 35 | * Manages command line. 36 | */ 37 | class CmdManager 38 | { 39 | public: 40 | /* 41 | * @param base_path: Absolute path to where Tocc files are stored. 42 | */ 43 | CmdManager(std::string base_path); 44 | 45 | ~CmdManager(); 46 | 47 | /* 48 | * Parses command line arguments and executes the required actions. 49 | * 50 | * @param cmd_parameters: A vector of parameters passed to command line. 51 | */ 52 | void execute(std::vector cmd_parameters); 53 | 54 | private: 55 | libtocc::Manager* libtocc_manager; 56 | std::vector actions; 57 | std::vector selectors; 58 | 59 | /* 60 | * Prints usage information on stdout. 61 | */ 62 | void print_usage(); 63 | 64 | /* 65 | * Prints version information on stdout. 66 | */ 67 | void print_version(); 68 | }; 69 | 70 | } 71 | 72 | #endif /* TOCCCLI_CMD_MANAGER_H_INCLUDED */ 73 | -------------------------------------------------------------------------------- /cli/src/initializer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | /* 20 | * This is a stand alone binary (tocc-initialize), which initialize a 21 | * Tocc Managed File System. 22 | */ 23 | 24 | #include 25 | #include // getcwd 26 | #include // FILENAME_MAX 27 | #include 28 | 29 | #include 30 | 31 | #include "utilities/errno_translator.h" 32 | 33 | 34 | int main(int argc, char* argv[]) 35 | { 36 | // Checking if arguments are correct. 37 | if (argc > 2) 38 | { 39 | std::cout << "Invalid number of arguments." << std::endl; 40 | std::cout << "You should provide a path as a single argument. i.e.:" << std::endl; 41 | std::cout << " tocc-initialize /opt/tocc-managed/" << std::endl; 42 | std::cout << "Or provide no argument, which initializes the current directory." << std::endl; 43 | 44 | return 101; 45 | } 46 | 47 | std::string base_path; 48 | 49 | if (argc == 2) 50 | { 51 | // Creating a standard string from the first argument. 52 | base_path = argv[1]; 53 | } 54 | else 55 | { 56 | // Using current directory as the base path. 57 | char path_buffer[FILENAME_MAX]; 58 | if (!getcwd(path_buffer, FILENAME_MAX)) 59 | { 60 | std::cout << tocccli::translate_errno(errno) << std::endl; 61 | return 201; 62 | } 63 | base_path = path_buffer; 64 | } 65 | 66 | try 67 | { 68 | // Initializing the path. 69 | libtocc::Manager libtocc_manager(base_path.c_str()); 70 | libtocc_manager.initialize(); 71 | } 72 | catch (std::exception& error) 73 | { 74 | std::cout << error.what() << std::endl; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /cli/src/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include // getcwd 23 | #include // FILENAME_MAX 24 | #include 25 | #include 26 | 27 | #include "common/cmd_param.h" 28 | #include "utilities/cmd_parser.h" 29 | #include "utilities/errno_translator.h" 30 | #include "engine/cmd_manager.h" 31 | #include "common/exceptions/cmd_usage_exceptions.h" 32 | 33 | 34 | using namespace tocccli; 35 | 36 | int main(int argc, char* argv[]) 37 | { 38 | 39 | std::vector cmd_parameters; 40 | try 41 | { 42 | // Parsing passed parameters. 43 | cmd_parameters = parse_cmd(argc, argv); 44 | } 45 | catch (const InvalidParametersError& e) 46 | { 47 | std::cout << "Invalid parameter" << std::endl; 48 | std::cout << e.what() << std::endl; 49 | } 50 | 51 | // Finding the current directory (default of Base Path). 52 | char path_buffer[FILENAME_MAX]; 53 | if (!getcwd(path_buffer, FILENAME_MAX)) 54 | { 55 | std::cout << translate_errno(errno) << std::endl; 56 | return 201; 57 | } 58 | std::string base_path(path_buffer); 59 | 60 | // Checking if user specified base path option. 61 | std::vector::iterator iterator = cmd_parameters.begin(); 62 | for (; iterator != cmd_parameters.end(); ++iterator) 63 | { 64 | if ((*iterator).option == "-b" || 65 | (*iterator).option == "--base-path") 66 | { 67 | if ((*iterator).arguments.empty()) 68 | { 69 | std::cout << "-b or --base-path must have an argument." << std::endl; 70 | return -101; 71 | } 72 | if ((*iterator).arguments.size() != 1) 73 | { 74 | std::cout << "-b or --base-path take exactly one argument." << std::endl; 75 | return -102; 76 | } 77 | 78 | base_path = (*iterator).arguments.front(); 79 | 80 | break; 81 | } 82 | } 83 | 84 | // Executing. 85 | CmdManager cmd_manager(base_path); 86 | try 87 | { 88 | cmd_manager.execute(cmd_parameters); 89 | } 90 | catch (const InvalidParametersError& e) 91 | { 92 | std::cout << "Invalid parameter" << std::endl; 93 | std::cout << e.what() << std::endl; 94 | } 95 | catch (const std::exception& ex) 96 | { 97 | // other exceptions 98 | std::cout << "Error" << std::endl; 99 | std::cout << ex.what() << std::endl; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /cli/src/selectors/id_selector.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include "selectors/id_selector.h" 20 | #include "common/exceptions/cmd_usage_exceptions.h" 21 | 22 | namespace tocccli 23 | { 24 | 25 | IDSelector::IDSelector(libtocc::Manager* manager) 26 | { 27 | this->libtocc_manager = manager; 28 | } 29 | 30 | IDSelector::~IDSelector() 31 | { 32 | } 33 | 34 | std::string IDSelector::get_short_form() 35 | { 36 | return "-d"; 37 | } 38 | 39 | std::string IDSelector::get_long_form() 40 | { 41 | return "--id"; 42 | } 43 | 44 | std::string IDSelector::get_help_text() 45 | { 46 | return "-d, --id=ID\tSelects a file by its ID."; 47 | } 48 | 49 | std::vector IDSelector::execute(std::vector cmd_arguments) 50 | { 51 | if (cmd_arguments.empty() || cmd_arguments.size() != 1) 52 | { 53 | throw InvalidParametersError("-d or --id takes exactly one argument."); 54 | } 55 | 56 | /* id must be 7 characters long and all 0-9 or A-M (base-23 digit) */ 57 | 58 | std::string id = cmd_arguments[0]; 59 | bool valid_id = true; 60 | if (id.size() == 7) 61 | { 62 | for (int i = 0; i < 7; i++) 63 | { 64 | if (!((id[i] >= '0' && id[i] <= '9') 65 | || (id[i] >= 'a' && id[i] <= 'm') 66 | || (id[i] >= 'A' && id[i] <= 'M'))) 67 | { 68 | valid_id = false; 69 | break; 70 | } 71 | } 72 | } 73 | else 74 | { 75 | valid_id = false; 76 | } 77 | if (! valid_id) 78 | { 79 | throw InvalidParametersError("ID must be seven characters, and only contain 0-9 and a-m"); 80 | } 81 | 82 | libtocc::FileInfo selected_file = 83 | this->libtocc_manager->get_file_info(cmd_arguments.front().c_str()); 84 | 85 | std::vector result; 86 | result.push_back(selected_file); 87 | return result; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /cli/src/selectors/id_selector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef TOCCCLI_ID_SELECTOR_H_INCLUDED 20 | #define TOCCCLI_ID_SELECTOR_H_INCLUDED 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | #include "selectors/selector.h" 29 | 30 | 31 | namespace tocccli 32 | { 33 | 34 | /* 35 | * Selects a file by its ID. 36 | */ 37 | class IDSelector : public Selector 38 | { 39 | public: 40 | IDSelector(libtocc::Manager* manager); 41 | 42 | virtual ~IDSelector(); 43 | 44 | /* 45 | * Returns short form of the parameter. 46 | */ 47 | virtual std::string get_short_form(); 48 | 49 | /* 50 | * Returns long form of the parameter. 51 | */ 52 | virtual std::string get_long_form(); 53 | 54 | /* 55 | * Returns the help text of the parameter. 56 | * (Full help text, include parameter itself.) 57 | */ 58 | virtual std::string get_help_text(); 59 | 60 | /* 61 | * Executes the selector. 62 | * 63 | * @param cmd_arguments: Arguments of this option that is passed to 64 | * command line. 65 | * 66 | * @return: List of founded files. 67 | */ 68 | virtual std::vector execute(std::vector cmd_arguments); 69 | 70 | private: 71 | libtocc::Manager* libtocc_manager; 72 | }; 73 | } 74 | 75 | #endif /* TOCCCLI_ID_SELECTOR_H_INCLUDED */ 76 | -------------------------------------------------------------------------------- /cli/src/selectors/import_file_selector.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include "selectors/import_file_selector.h" 20 | #include "common/exceptions/cmd_usage_exceptions.h" 21 | 22 | 23 | namespace tocccli 24 | { 25 | 26 | ImportFileSelector::ImportFileSelector(libtocc::Manager* manager) 27 | { 28 | this->libtocc_manager = manager; 29 | } 30 | 31 | ImportFileSelector::~ImportFileSelector() 32 | { 33 | } 34 | 35 | std::string ImportFileSelector::get_short_form() 36 | { 37 | return "-i"; 38 | } 39 | 40 | std::string ImportFileSelector::get_long_form() 41 | { 42 | return "--import"; 43 | } 44 | 45 | std::string ImportFileSelector::get_help_text() 46 | { 47 | return "-i, --import=PATH\tImports a file from the specified path to the \n" 48 | " \tTocc managed file system."; 49 | } 50 | 51 | std::vector ImportFileSelector::execute(std::vector cmd_arguments) 52 | { 53 | if (cmd_arguments.size() != 1) 54 | { 55 | throw InvalidParametersError("-i and --import accepts exactly one argument."); 56 | } 57 | 58 | libtocc::FileInfo new_file = this->libtocc_manager->import_file(cmd_arguments.front().c_str()); 59 | 60 | std::vector result; 61 | result.push_back(new_file); 62 | return result; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /cli/src/selectors/import_file_selector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef TOCCCLI_COPY_FILE_SELECTOR_H_INCLUDED 20 | #define TOCCCLI_COPY_FILE_SELECTOR_H_INCLUDED 21 | 22 | #include 23 | #include 24 | 25 | #include "selectors/selector.h" 26 | 27 | 28 | namespace tocccli 29 | { 30 | 31 | /* 32 | * Imports a file to the Tocc managed file system. 33 | */ 34 | class ImportFileSelector : public Selector 35 | { 36 | 37 | /* 38 | * Note: This class defined as a Selector rather than Action, because 39 | * usually user want to import a file, and do an action on it (import the 40 | * file and at the same time assign a tag to it). So ID of the newly 41 | * imported file should be among those that will passes to the actions. 42 | */ 43 | 44 | public: 45 | ImportFileSelector(libtocc::Manager* manager); 46 | 47 | ~ImportFileSelector(); 48 | 49 | /* 50 | * Returns short form of the parameter. 51 | */ 52 | virtual std::string get_short_form(); 53 | 54 | /* 55 | * Returns long form of the parameter. 56 | */ 57 | virtual std::string get_long_form(); 58 | 59 | /* 60 | * Returns the help text of the parameter. 61 | * (Full help text, include parameter itself.) 62 | */ 63 | virtual std::string get_help_text(); 64 | 65 | /* 66 | * Executes the selector. 67 | * 68 | * @param cmd_arguments: Arguments of this option that is passed to 69 | * command line. 70 | * 71 | * @return: List of founded files. 72 | */ 73 | virtual std::vector execute(std::vector cmd_arguments); 74 | 75 | private: 76 | libtocc::Manager* libtocc_manager; 77 | }; 78 | 79 | } 80 | 81 | #endif /* TOCCCLI_COPY_FILE_SELECTOR_H_INCLUDED */ 82 | -------------------------------------------------------------------------------- /cli/src/selectors/query_selector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef TOCCCLI_QUERY_SELECTOR_H_INCLUDED 20 | #define TOCCCLI_QUERY_SELECTOR_H_INCLUDED 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | #include "selectors/selector.h" 28 | 29 | 30 | namespace tocccli 31 | { 32 | 33 | /* 34 | * Selects files by query. 35 | */ 36 | class QuerySelector : public Selector 37 | { 38 | public: 39 | 40 | QuerySelector(libtocc::Manager* manager); 41 | 42 | ~QuerySelector(); 43 | 44 | /* 45 | * Returns short form of the parameter. 46 | */ 47 | virtual std::string get_short_form(); 48 | 49 | /* 50 | * Returns long form of the parameter. 51 | */ 52 | virtual std::string get_long_form(); 53 | 54 | /* 55 | * Returns the help text of the parameter. 56 | * (Full help text, include parameter itself.) 57 | */ 58 | virtual std::string get_help_text(); 59 | 60 | /* 61 | * Executes the selector. 62 | * 63 | * @param cmd_arguments: Arguments of this option that is passed to 64 | * command line. 65 | * 66 | * @return: List of founded files. 67 | */ 68 | virtual std::vector execute(std::vector cmd_arguments); 69 | 70 | private: 71 | libtocc::Manager* libtocc_manager; 72 | 73 | }; 74 | } 75 | 76 | #endif /* TOCCCLI_QUERY_SELECTOR_H_INCLUDED */ 77 | -------------------------------------------------------------------------------- /cli/src/selectors/selector.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include "selectors/selector.h" 20 | 21 | 22 | namespace tocccli 23 | { 24 | 25 | Selector::~Selector() 26 | { 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /cli/src/selectors/selector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef TOCCCLI_SELECTOR_HANDLER_H_INCLUDED 20 | #define TOCCCLI_SELECTOR_HANDLER_H_INCLUDED 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | namespace tocccli 28 | { 29 | 30 | /* 31 | * Base class for handlers of Selector parameters. 32 | */ 33 | class Selector 34 | { 35 | public: 36 | 37 | virtual ~Selector(); 38 | 39 | /* 40 | * Returns short form of the parameter. 41 | */ 42 | virtual std::string get_short_form() = 0; 43 | 44 | /* 45 | * Returns long form of the parameter. 46 | */ 47 | virtual std::string get_long_form() = 0; 48 | 49 | /* 50 | * Returns the help text of the parameter. 51 | * (Full help text, include parameter itself.) 52 | */ 53 | virtual std::string get_help_text() = 0; 54 | 55 | /* 56 | * Executes the selector. 57 | * 58 | * @param cmd_arguments: Arguments of this option that is passed to 59 | * command line. 60 | * 61 | * @return: List of founded files. 62 | */ 63 | virtual std::vector execute(std::vector cmd_arguments) = 0; 64 | }; 65 | } 66 | 67 | #endif /* TOCCCLI_SELECTOR_HANDLER_H_INCLUDED */ 68 | -------------------------------------------------------------------------------- /cli/src/utilities/cmd_parser.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | 20 | #include "utilities/cmd_parser.h" 21 | #include "utilities/string_utils.h" 22 | #include "common/exceptions/cmd_usage_exceptions.h" 23 | 24 | 25 | namespace tocccli 26 | { 27 | 28 | std::vector parse_cmd(int argc, char* argv[]) 29 | { 30 | std::vector result; 31 | 32 | // We started the loop from one, because zero is the name of the binary. 33 | for (int i = 1; i < argc; ++i) 34 | { 35 | if (argv[i][0] == '-') 36 | { 37 | // A new option. 38 | CmdParam new_param; 39 | 40 | // Checking if it is in form "--option=value". 41 | std::string arg(argv[i]); 42 | std::string double_dash("--"); 43 | if (string_starts_with(arg, double_dash)) 44 | { 45 | std::vector arg_parts = split_string(arg, '=', 1); 46 | if (arg_parts.size() == 2) 47 | { 48 | // Yes, it is in the form "--option=value". 49 | new_param.option = arg_parts[0]; 50 | new_param.arguments.push_back(arg_parts[1]); 51 | } 52 | } 53 | 54 | if (new_param.option.empty()) 55 | { 56 | // Previous check is failed. 57 | new_param.option = arg; 58 | } 59 | 60 | result.push_back(new_param); 61 | } 62 | else 63 | { 64 | if (result.empty()) 65 | { 66 | throw InvalidParametersError( 67 | "First parameter have to be an option (e.g. starts with a dash)"); 68 | } 69 | 70 | result.back().arguments.push_back(argv[i]); 71 | } 72 | } 73 | 74 | return result; 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /cli/src/utilities/cmd_parser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef TOCCCLI_CMD_PARSER_H_INCLUDED 20 | #define TOCCCLI_CMD_PARSER_H_INCLUDED 21 | 22 | #include 23 | 24 | #include "common/cmd_param.h" 25 | 26 | 27 | namespace tocccli 28 | { 29 | 30 | /* 31 | * Parses command line parameters. 32 | * 33 | * @param argc: Count of parameters. 34 | * @param argv: Array of parameters. 35 | * 36 | * @return: A vector of command line parameters. 37 | */ 38 | std::vector parse_cmd(int argc, char* argv[]); 39 | 40 | } 41 | 42 | #endif /* TOCCCLI_CMD_PARSER_H_INCLUDED */ 43 | -------------------------------------------------------------------------------- /cli/src/utilities/errno_translator.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | 23 | namespace tocccli 24 | { 25 | 26 | std::string translate_errno(int err_no) 27 | { 28 | if (err_no == EACCES) 29 | { 30 | return "Permission denied on the specified path."; 31 | } 32 | if (err_no == ENAMETOOLONG) 33 | { 34 | return "Path is too long."; 35 | } 36 | if (err_no == ENOENT) 37 | { 38 | return "The current working directory has been unlinked."; 39 | } 40 | 41 | std::ostringstream stream; 42 | stream << "Unknown error: " << err_no; 43 | return stream.str(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /cli/src/utilities/errno_translator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef TOCCCLI_ERRNO_TRANSLATOR_H_INCLUDED 20 | #define TOCCCLI_ERRNO_TRANSLATOR_H_INCLUDED 21 | 22 | #include 23 | 24 | 25 | namespace tocccli 26 | { 27 | 28 | std::string translate_errno(int err_no); 29 | } 30 | 31 | #endif /* TOCCCLI_ERRNO_TRANSLATOR_H_INCLUDED */ 32 | -------------------------------------------------------------------------------- /cli/src/utilities/string_utils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include "utilities/string_utils.h" 20 | #include 21 | 22 | namespace tocccli 23 | { 24 | 25 | bool string_starts_with(std::string& str, std::string& str_to_check) 26 | { 27 | if (str_to_check.size() > str.size()) 28 | { 29 | return false; 30 | } 31 | 32 | return str.compare(0, str_to_check.size(), str_to_check) == 0; 33 | } 34 | 35 | std::vector split_string(const std::string& string_to_split, 36 | char delimiter, 37 | int count) 38 | { 39 | std::vector result; 40 | 41 | std::stringstream stream(string_to_split); 42 | std::string item; 43 | 44 | while (std::getline(stream, item, delimiter)) 45 | { 46 | if (!item.empty()) 47 | { 48 | result.push_back(item); 49 | } 50 | 51 | if (count > 0 && result.size() == count) 52 | { 53 | // Getting the rest of stream without splitting. 54 | // (If anything remained.) 55 | if (std::getline(stream, item)) 56 | { 57 | if (!item.empty()) 58 | { 59 | result.push_back(item); 60 | } 61 | } 62 | break; 63 | } 64 | } 65 | 66 | return result; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /cli/src/utilities/string_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef TOCCCLI_STRING_UTILS_H_INCLUDED 20 | #define TOCCCLI_STRING_UTILS_H_INCLUDED 21 | 22 | #include 23 | #include 24 | 25 | 26 | namespace tocccli 27 | { 28 | 29 | /* 30 | * Checks if `str' starts with `str_to_check'. (i.e. `str_to_check' 31 | * is at the beginning of `str'.) 32 | */ 33 | bool string_starts_with(std::string& str, std::string& str_to_check); 34 | 35 | /* 36 | * Splits the specified string from the specified delimiter. 37 | * 38 | * @param string_to_split: String to split. 39 | * @param delimiter: Char to split the string from. 40 | * @param count: Stop if these many splits took place. 41 | * (Zero means no limit). 42 | */ 43 | std::vector split_string(const std::string& string_to_split, 44 | char delimiter, 45 | int count=0); 46 | } 47 | 48 | #endif /* TOCCCLI_STRING_UTILS_H_INCLUDED */ 49 | -------------------------------------------------------------------------------- /docs/_themes/alabaster/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Alabaster theme is not part of the Tocc. It downloaded from the following URL: 3 | 4 | https://github.com/bitprophet/alabaster 5 | 6 | License of the files contain in this directory is as follows. 7 | 8 | ------------------------------------------------------------------------------ 9 | 10 | Copyright (c) 2014 Jeff Forcier. 11 | 12 | Based on original work copyright (c) 2011 Kenneth Reitz and copyright (c) 2010 13 | Armin Ronacher. 14 | 15 | Some rights reserved. 16 | 17 | Redistribution and use in source and binary forms of the theme, with or 18 | without modification, are permitted provided that the following conditions 19 | are met: 20 | 21 | * Redistributions of source code must retain the above copyright 22 | notice, this list of conditions and the following disclaimer. 23 | 24 | * Redistributions in binary form must reproduce the above 25 | copyright notice, this list of conditions and the following 26 | disclaimer in the documentation and/or other materials provided 27 | with the distribution. 28 | 29 | * The names of the contributors may not be used to endorse or 30 | promote products derived from this software without specific 31 | prior written permission. 32 | 33 | THIS THEME IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 34 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 35 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 36 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 37 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 38 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 39 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 40 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 41 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 42 | ARISING IN ANY WAY OUT OF THE USE OF THIS THEME, EVEN IF ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | -------------------------------------------------------------------------------- /docs/_themes/alabaster/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from alabaster import _version as version 4 | 5 | 6 | def get_path(): 7 | """ 8 | Shortcut for users whose theme is next to their conf.py. 9 | """ 10 | # Theme directory is defined as our parent directory 11 | return os.path.abspath(os.path.dirname(os.path.dirname(__file__))) 12 | 13 | 14 | def update_context(app, pagename, templatename, context, doctree): 15 | context['alabaster_version'] = version.__version__ 16 | 17 | def setup(app): 18 | app.connect('html-page-context', update_context) 19 | -------------------------------------------------------------------------------- /docs/_themes/alabaster/_version.py: -------------------------------------------------------------------------------- 1 | __version_info__ = (0, 6, 0) 2 | __version__ = '.'.join(map(str, __version_info__)) 3 | -------------------------------------------------------------------------------- /docs/_themes/alabaster/about.html: -------------------------------------------------------------------------------- 1 | {% if theme_logo %} 2 |

{{ project }}

7 | {% endif %} 8 | 9 |

10 | {% else %} 11 |

{{ project }}

12 | {% endif %} 13 | 14 | {% if theme_description %} 15 |

{{ theme_description }}

16 | {% endif %} 17 | 18 | {% if theme_github_button|lower == 'true' %} 19 |

20 | 22 |

23 | {% endif %} 24 | 25 | {% if theme_travis_button|lower != 'false' %} 26 | {% if theme_travis_button|lower == 'true' %} 27 | {% set path = theme_github_user + '/' + theme_github_repo %} 28 | {% else %} 29 | {% set path = theme_travis_button %} 30 | {% endif %} 31 |

32 | 33 | https://secure.travis-ci.org/{{ path }}.png?branch=master 37 | 38 |

39 | {% endif %} 40 | -------------------------------------------------------------------------------- /docs/_themes/alabaster/donate.html: -------------------------------------------------------------------------------- 1 | {% if theme_gittip_user %} 2 |

Donate

3 |

4 | Consider supporting the authors on Gittip: 5 | 8 |

9 | {% endif %} 10 | -------------------------------------------------------------------------------- /docs/_themes/alabaster/layout.html: -------------------------------------------------------------------------------- 1 | {%- extends "basic/layout.html" %} 2 | {%- block extrahead %} 3 | {{ super() }} 4 | {% if theme_touch_icon %} 5 | 6 | {% endif %} 7 | 8 | {% endblock %} 9 | {%- block relbar2 %}{% endblock %} 10 | {%- block footer %} 11 | 24 | 25 | {% if theme_github_banner|lower == 'true' %} 26 | 27 | Fork me on GitHub 28 | 29 | {% endif %} 30 | 31 | {% if theme_analytics_id %} 32 | 47 | {% endif %} 48 | {%- endblock %} 49 | -------------------------------------------------------------------------------- /docs/_themes/alabaster/navigation.html: -------------------------------------------------------------------------------- 1 |

Follow @t_o_c_c_

2 | 3 |

Navigation

4 | {{ toctree(includehidden=theme_sidebar_includehidden) }} 5 | {% if theme_extra_nav_links %} 6 |
7 |
    8 | {% for text, uri in theme_extra_nav_links.items() %} 9 |
  • {{ text }}
  • 10 | {% endfor %} 11 |
12 | {% endif %} 13 | -------------------------------------------------------------------------------- /docs/_themes/alabaster/static/bird_black_32_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aidin36/tocc/bf00cf6becc52d320712f97247ae2b9594ee973f/docs/_themes/alabaster/static/bird_black_32_0.png -------------------------------------------------------------------------------- /docs/_themes/alabaster/theme.conf: -------------------------------------------------------------------------------- 1 | [theme] 2 | inherit = basic 3 | stylesheet = alabaster.css 4 | pygments_style = alabaster.support.Alabaster 5 | 6 | [options] 7 | logo = 8 | logo_name = false 9 | logo_text_align = left 10 | description = 11 | github_user = 12 | github_repo = 13 | github_button = true 14 | github_banner = false 15 | github_type = watch 16 | github_count = true 17 | travis_button = false 18 | gittip_user = 19 | analytics_id = 20 | touch_icon = 21 | extra_nav_links = 22 | sidebar_includehidden = true 23 | show_powered_by = true 24 | 25 | gray_1 = #444 26 | gray_2 = #EEE 27 | gray_3 = #AAA 28 | 29 | body_text = #3E4349 30 | footer_text = #888 31 | link = #004B6B 32 | link_hover = #6D4100 33 | sidebar_header = 34 | sidebar_text = #555 35 | sidebar_link = 36 | sidebar_link_underscore = #999 37 | sidebar_search_button = #CCC 38 | sidebar_list = #000 39 | sidebar_hr = 40 | anchor = #DDD 41 | anchor_hover_fg = 42 | anchor_hover_bg = #EAEAEA 43 | note_bg = 44 | note_border = #CCC 45 | footnote_bg = #FDFDFD 46 | footnote_border = 47 | pre_bg = 48 | narrow_sidebar_bg = #333 49 | narrow_sidebar_fg = #FFF 50 | narrow_sidebar_link = 51 | -------------------------------------------------------------------------------- /docs/source/_static/gplv3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aidin36/tocc/bf00cf6becc52d320712f97247ae2b9594ee973f/docs/source/_static/gplv3.png -------------------------------------------------------------------------------- /docs/source/contribution.rst: -------------------------------------------------------------------------------- 1 | Contribution 2 | ============ 3 | 4 | Tocc is a big project. Without the help of the community, it won't last long. 5 | 6 | Not just Tocc benefits from contribution, but the contributor itself also 7 | gain more experience. 8 | 9 | You don't have to be a developer. There are other tasks that should be handled. 10 | This page lists things you can help with. 11 | 12 | If you decided to contribute, contact Aidin at *aidin (AT) aidinhut.com* 13 | 14 | Development 15 | ----------- 16 | 17 | There are various parts of the project that you can help at as a developer. 18 | You don't have to be a professional. Any contribution is valuable. 19 | 20 | * **Tocc itself**: If you're a C++ developer, you can help with the Tocc project 21 | itself. Tocc project have three parts: main library (libtocc), official 22 | command line interface, and a file system (toccfs). Take a look at 23 | `issues `_ to find out what 24 | tasks are waiting to be done. Tasks that labeled *easy* are good points 25 | to start. 26 | 27 | * **UIs**: There can be different UIs for Tocc. CLIs, GUIs, plugins for different 28 | applications (i.e. file browsers like Nautilus of Dolphin). 29 | Each have their own features and usage. 30 | You can start developing a new UI for Tocc, as a separate project. 31 | 32 | * **libtocc wrappers**: *libtocc* is the main component of the Tocc. Its the 33 | engine of Tocc, and other components are just UIs for it. 34 | It written in C++. You can write wrappers for other languages. 35 | Doing that, you will learn more about underlying layers of the language your 36 | working with, in a fun way. 37 | 38 | Documentation and Website 39 | ------------------------- 40 | 41 | Documents are very important, both for the end users, and new developers that 42 | join the project. But they aren't as fun as playing with code. That's why 43 | developers don't write documents. And that's why documenters worth their weight 44 | in gold. 45 | 46 | Documents of Tocc are written using `Sphinx `_. 47 | The website is also some html files generated using Sphinx. 48 | 49 | Translation 50 | ^^^^^^^^^^^ 51 | 52 | It will help end users a lot if they have user manuals in their own native 53 | language. You can help the project by translating documentation to your 54 | language. 55 | 56 | Release Technician 57 | ------------------ 58 | 59 | In order to make it easy for users to install Tocc, we need to distribute 60 | packages for different OSes and Distros. Since there's many of them, we need 61 | people to handle the job. 62 | 63 | It won't take too much time, because it should be done just when Tocc releases 64 | a new version. 65 | 66 | If you have some free time every three or four months, you can be the Release 67 | Technician of you favorite OS. 68 | -------------------------------------------------------------------------------- /docs/source/developers/coding_style.rst: -------------------------------------------------------------------------------- 1 | 2 | .. highlight:: cpp 3 | :linenothreshold: 5 4 | 5 | .. toctree:: 6 | :hidden: 7 | 8 | 9 | Coding Style Guide 10 | ================== 11 | 12 | There are some rules that must be followed by developers of Tocc, in order to 13 | keep a cleaner and more maintainable code. 14 | 15 | And remember: Special cases are not special enough to break the rules. 16 | 17 | 18 | Appearance 19 | ---------- 20 | 21 | * Indents are two spaces. 22 | 23 | * Braces should be open in the next line. Example:: 24 | 25 | if (name == "test") 26 | { 27 | // Do some stuff. 28 | } 29 | 30 | * Never write a ``if``, ``for``, etc without braces:: 31 | 32 | // Illegal! Don't write like this. 33 | if (title.size() == 0) 34 | title = "default" 35 | 36 | * Put spaces around operators, assignments, commas, etc:: 37 | 38 | int x = 24; 39 | int y = 7; 40 | Point point(x, y * 2); 41 | 42 | * There shouldn't be any trailing space in the source file. You can 43 | use ``git diff --check`` before any commit to check that. 44 | 45 | 46 | Naming 47 | ------ 48 | 49 | * Never use abbreviation. Always use clear and meaningful name for variables, 50 | functions, classes, and everything else. 51 | 52 | * Name of classes must be in Camel Case. Like ``InvalidArgumentsError``. 53 | 54 | * Name of constants must be all in captal letters, and each word separated 55 | by underscore. Example: ``MAXIMUM_ALLOWED_TAGS = 100``. 56 | 57 | * Everything else (methods, variables, name spaces, file names, etc) must be 58 | all in lower case. Examples: ``tags_list``, ``get_absolute_path``. 59 | 60 | 61 | Unit Tests 62 | ---------- 63 | 64 | * Developers must write a Unit Test for every functionality they add. 65 | 66 | 67 | Commit Messages 68 | --------------- 69 | 70 | * Include related issue number (if any) in the commit message. In the form 71 | ``issue #52``. 72 | 73 | Headers 74 | ------- 75 | 76 | * First header that includes in a ``.cpp`` file, should be its header. For 77 | example, in ``expr.cpp``, the first include must be ``expr.h``. Then other 78 | headers. It will help us see dependency problems earlier. 79 | 80 | 81 | -------------------------------------------------------------------------------- /docs/source/developers/index.rst: -------------------------------------------------------------------------------- 1 | 2 | .. toctree:: 3 | :hidden: 4 | 5 | coding_style 6 | workflow 7 | 8 | 9 | Developers Documentation 10 | ======================== 11 | 12 | All developers of *Tocc* must follow the :doc:`coding_style`, to keep the code 13 | clear and maintainable. So, make sure you read and follow it. 14 | 15 | Also, read :doc:`workflow`, to get yourself familiar with workflow of Tocc's 16 | Development. 17 | 18 | For an overview of the design, take a look at 19 | `libtocc Design Overview <../libtocc/overview.html>`_ 20 | 21 | -------------------------------------------------------------------------------- /docs/source/developers/workflow.rst: -------------------------------------------------------------------------------- 1 | 2 | .. toctree:: 3 | :hidden: 4 | 5 | 6 | Workflow of Tocc Development 7 | ============================ 8 | 9 | Picking Up Issues 10 | ----------------- 11 | 12 | For each required change (Bug or Enhancement) there's an issue in 13 | `Tocc's Issue List `_. 14 | To start work on something, you need to pick one of the issues. 15 | 16 | Some issues labeled *easy*. If you are new to Tocc, we recommend to start with 17 | one of them. After you get familiar with Tocc's design, you can pick other 18 | issues. 19 | 20 | To pick up an issue, leave a comment like *I'm going to work on this* on that 21 | issue. Project's admin will add a label to that issue, so others know someone 22 | working on it. 23 | 24 | Cloning 25 | ------- 26 | First, you need to clone the *master* branch of the main repository 27 | (*aidin36*). To do so, go to the 28 | `Tocc's Github Page `_ and click on *Fork* 29 | button. 30 | 31 | Now clone it on your local machine:: 32 | 33 | git clone https://user@github.com/user/tocc.git 34 | 35 | Branching 36 | --------- 37 | You should create a branch for each issue you're working on. To do so, 38 | follow these steps. 39 | 40 | * Ensure your *master* branch is up to date:: 41 | 42 | git checkout master 43 | git pull https://github.com/aidin36/tocc.git master 44 | 45 | * Create a branch for the issue, and switch into it:: 46 | 47 | git checkout -b issue92 48 | 49 | * Do your changes, and commit them locally. (Don't forget to follow the 50 | :doc:`coding_style`.) 51 | 52 | Sending Pull Request 53 | -------------------- 54 | In order to merge your changes into main repository (*aidin36*), you need to 55 | send a *Pull Request* that contains your changes. In order to that, follow 56 | these steps. 57 | 58 | * Push your branch to your Github account:: 59 | 60 | git push origin issue92 61 | 62 | * Go to Github site, and navigate to your fork of Tocc. Click on *Branch* 63 | menu. You should see your *issue92* branch. Click on *Create Pull Request*. 64 | 65 | More Info 66 | --------- 67 | Take a look at `Github help page `_ if you want full 68 | info about how to work with Git and Github. 69 | 70 | 71 | -------------------------------------------------------------------------------- /docs/source/manual/index.rst: -------------------------------------------------------------------------------- 1 | 2 | Tocc Users Manual 3 | ================= 4 | 5 | Tocc comes with two official UIs: A Command Line Interface (CLI), 6 | and a read-only File System (toccfs). 7 | 8 | In order to learn how to work with Tocc, read 9 | `Official Tocc CLI Documentation <../cli/index.html>`_. 10 | After that, take a look at 11 | `Tocc File System Documentation <../toccfs/index.html>`_ 12 | to learn how you can integrate Tocc with other applications. 13 | 14 | Note that these are the Official UIs. There maybe some other UIs 15 | developed for Tocc, with different features. 16 | 17 | -------------------------------------------------------------------------------- /docs/source/uis.rst: -------------------------------------------------------------------------------- 1 | 2 | 3 | Third party UIs 4 | =============== 5 | 6 | Tocc have two official UIs: A CLI and a file system. Beside that, there's 7 | some other UIs that make it easier to work with Tocc. Some are extensions 8 | for other applications, and some are stand-alone UIs. 9 | 10 | * `Tocc extension for Nemo and Nautilus `_ 11 | * `A simple script that helps you import photos into Tocc `_ 12 | 13 | -------------------------------------------------------------------------------- /docs/src/compiler/CompilerStateMachine.odg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aidin36/tocc/bf00cf6becc52d320712f97247ae2b9594ee973f/docs/src/compiler/CompilerStateMachine.odg -------------------------------------------------------------------------------- /docs/src/design_overview/abstract.tex: -------------------------------------------------------------------------------- 1 | 2 | \section{How it works} 3 | User's files are store on a normal file system, with almost no structure (at least, not human-readable!) Each file has a unique ID. And in a database, each of these IDs will associates with one or more tags. 4 | 5 | User executes queries on these tags, and gets a list of files matching the query. 6 | 7 | \section{Components} 8 | 9 | \begin{figure} 10 | \includegraphics[width=0.9\textwidth]{images/main_components.png} 11 | \caption{main components} 12 | \label{fig:components} 13 | \end{figure} 14 | 15 | Everything is implemented in \emph{libtocc}. \emph{toccfs} and \emph{tocc} are two interfaces for the library (there can be more, e.g. a graphical interface). 16 | 17 | \emph{toccfs} is a file system written using FUSE\footnote{Filesystem in Userspace \url{http://fuse.sourceforge.net}}. User can interact with it as any other file systems. \emph{tocc} is a command line interface. (\emph{toccd} is there for better performance. It will be explained later.) 18 | 19 | 20 | \subsection{toccfs} 21 | \emph{toccfs} mounts as a file system in a mount point, and gets a path to were the real files stored. (something like \texttt{toccfs /path/to/files/ /mount/point}). User can use it as a normal file system, i.e. list files in directories, copy or move files, open them, and like that. Each of these commands will be translated into a query passes to \emph{libtocc}. 22 | 23 | For example, user may run \texttt{ls photo/abstract/}, and gets all files that tagged photo and abstract. Or, by coping a file to \texttt{black-and-white}, the file will be tagged black-and-white. 24 | 25 | \subsection{tocc} 26 | \emph{toccfs} is very limited. If user wants to execute more complicated queries, like searching with Regular Expression, she can use \emph{tocc} command. 27 | 28 | \emph{toccd} is a daemon exists for increasing the performance. Since \emph{libtocc} works with a database, each time \texttt{tocc} command executes, a new process will be started and loads database into the memory. If we set aside the time it takes to load the database, the database can't use improvements like caching its data in memory. To solve this, a daemon is running in the background and \emph{tocc} passes its queries to it. 29 | 30 | -------------------------------------------------------------------------------- /docs/src/design_overview/images/main_components.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aidin36/tocc/bf00cf6becc52d320712f97247ae2b9594ee973f/docs/src/design_overview/images/main_components.png -------------------------------------------------------------------------------- /docs/src/design_overview/main.tex: -------------------------------------------------------------------------------- 1 | 2 | \newcommand{\toccdoctitle}{Design Overview of Tocc} 3 | \newcommand{\toccdocauthor}{Aidin Gharibnavaz} 4 | 5 | \input{../templates/main_template_begin.tex} 6 | 7 | \chapter{Abstract View} 8 | \input{abstract.tex} 9 | 10 | \input{../templates/main_template_end.tex} 11 | 12 | -------------------------------------------------------------------------------- /docs/src/templates/main_template_begin.tex: -------------------------------------------------------------------------------- 1 | \documentclass[oneside]{book} 2 | \usepackage{fancyhdr} 3 | \usepackage{hyperref} 4 | \usepackage{graphicx} 5 | 6 | 7 | %\newcommand{\toccdoctitle}{None} 8 | %\newcommand{\toccdocauthor}{None} 9 | 10 | \hypersetup{extension={xetex}, pdftitle={\toccdoctitle}, pdfauthor={\toccdocauthor}, pdfsubject={}, pdfdisplaydoctitle=true, colorlinks=true, linkcolor={blue}, urlcolor={cyan}} 11 | 12 | \renewcommand{\familydefault}{\sfdefault} 13 | 14 | %Facny Header 15 | \pagestyle{fancy} 16 | \fancyhf{} 17 | \fancyhead[LE,RO]{\rightmark} 18 | \fancyhead[LO,RE]{\leftmark} 19 | \fancyfoot[C]{\thepage} 20 | \renewcommand{\headrulewidth}{0.4pt} 21 | \renewcommand{\footrulewidth}{0.4pt} 22 | %For plain pages: 23 | \fancypagestyle{plain}{% 24 | \fancyhf{} 25 | \fancyfoot[C]{\thepage} 26 | \renewcommand{\headrulewidth}{0pt} 27 | \renewcommand{\footrulewidth}{0.4pt} 28 | } 29 | %% 30 | 31 | %Set paragraphs spacing 32 | %\setlength{\parindent}{0pt} 33 | %\setlength{\parskip}{1ex plus 0.5ex minus 0.2ex} 34 | %% 35 | 36 | \begin{document} 37 | 38 | \title{\toccdoctitle} 39 | \author{\toccdocauthor} 40 | \date{} 41 | \maketitle 42 | 43 | \tableofcontents 44 | 45 | 46 | -------------------------------------------------------------------------------- /docs/src/templates/main_template_end.tex: -------------------------------------------------------------------------------- 1 | 2 | \end{document} 3 | -------------------------------------------------------------------------------- /libtocc/docs/source/_static/design-overview.odg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aidin36/tocc/bf00cf6becc52d320712f97247ae2b9594ee973f/libtocc/docs/source/_static/design-overview.odg -------------------------------------------------------------------------------- /libtocc/docs/source/_static/design-overview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aidin36/tocc/bf00cf6becc52d320712f97247ae2b9594ee973f/libtocc/docs/source/_static/design-overview.png -------------------------------------------------------------------------------- /libtocc/docs/source/overview.rst: -------------------------------------------------------------------------------- 1 | 2 | Design Overview 3 | =============== 4 | 5 | .. image:: _static/design-overview.png 6 | :alt: Design Overview of libtocc 7 | 8 | Engine of the Tocc is *libtocc*. Everything is implemented in it. Other 9 | components are interfaces that works with it. i.e. *tocc* CLI, *toccfs*, 10 | and other UIs that is written for Tocc. 11 | 12 | All the user's files store in a real file system (i.e. an Ext4 file system). 13 | Files will rename to codes, and will be store in a specific structure. 14 | There's a database that contains information about each file: Its tags, title, 15 | and other properties of the file. 16 | 17 | To understand it, consider the following scenario. 18 | 19 | When user wants to store a file in Tocc system, it will call ``import`` method 20 | of the *libtocc* API. The file itself copies to the real file system (Ext4 21 | in our example), and a record will be store in the database containing the file 22 | information. Then, user assign some tags to the file by calling ``assign_tag`` 23 | method. File's record in database will be updated and those tags will be added 24 | to it. Now, user can query files by calling ``query`` method of the API. 25 | *libtocc* will search its database to see which files will match with the query, 26 | and return them. 27 | -------------------------------------------------------------------------------- /libtocc/src/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Makefile.am -- Process this file with automake to produce Makefile.in 2 | 3 | # Output and source files. 4 | lib_LTLIBRARIES = libtocc.la 5 | # Refer to this chapter of Libtool Manual for understanding versioning rules: 6 | # http://www.gnu.org/software/libtool/manual/html_node/Versioning.html 7 | libtocc_la_LDFLAGS = -version-info 1:1:0 8 | libtocc_la_SOURCES = libtocc/check_exists.cpp libtocc/common/database_exceptions.cpp libtocc/common/expr_exceptions.cpp libtocc/common/base_exception.cpp libtocc/common/file_system_exceptions.cpp libtocc/common/int_file_info.cpp libtocc/utilities/file_info_converter.cpp libtocc/utilities/file_utils.cpp libtocc/database/base23.cpp libtocc/database/funcs.cpp libtocc/database/database.cpp libtocc/exprs/compiled_expr.cpp libtocc/exprs/compiler.cpp libtocc/exprs/connectives.cpp libtocc/exprs/fields.cpp libtocc/exprs/functions.cpp libtocc/exprs/operations.cpp libtocc/exprs/query.cpp libtocc/file_system/file_manager.cpp libtocc/engine/files_engine.cpp libtocc/engine/tags_engine.cpp libtocc/front_end/file_info.cpp libtocc/front_end/tag_statistics.cpp libtocc/front_end/manager.cpp 9 | 10 | # Installing headers 11 | libtocc_includedir = $(includedir) 12 | libtocc_include_HEADERS = libtocc.h 13 | front_end_includedir = $(includedir)/libtocc/front_end 14 | front_end_include_HEADERS = libtocc/front_end/file_info.h libtocc/front_end/manager.h libtocc/front_end/tag_statistics.h 15 | common_includedir = $(includedir)/libtocc/common/ 16 | common_include_HEADERS = libtocc/common/base_exception.h libtocc/common/database_exceptions.h libtocc/common/expr_exceptions.h libtocc/common/file_system_exceptions.h libtocc/common/runtime_exceptions.h 17 | exprs_includedir = $(includedir)/libtocc/exprs/ 18 | exprs_include_HEADERS = libtocc/exprs/expr.h libtocc/exprs/connectives.h libtocc/exprs/fields.h libtocc/exprs/functions.h libtocc/exprs/operations.h libtocc/exprs/query.h libtocc/exprs/compiled_expr_types.h 19 | 20 | pkgconfigdir = @pkgconfigdir@ 21 | pkgconfig_DATA = libtocc.pc 22 | 23 | # Libtool doesn't update ld's cache by default. This hook is added to ensure 24 | # that cache is updated after library is installed. Though it make the 25 | # installation a little slow. 26 | # Also, I ignored the errors. Because there maybe no `ldconfig' on the system 27 | # or corrent user don't have access to execute it. 28 | install-exec-hook: 29 | -ldconfig 30 | 31 | -------------------------------------------------------------------------------- /libtocc/src/bootstrap: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | libtoolize 6 | aclocal 7 | autoconf -Wall 8 | automake -Wall --add-missing 9 | -------------------------------------------------------------------------------- /libtocc/src/configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ([2.69]) 5 | AC_INIT([libtocc], [1.0.1], [tocc@aidinhut.com], [libtocc], [https://tocc.aidinhut.com]) 6 | AC_CONFIG_SRCDIR([libtocc/front_end/manager.h]) 7 | #AC_CONFIG_HEADERS([config.h]) 8 | 9 | # Initializing Libtool 10 | LT_INIT 11 | 12 | # Initializing Automake 13 | # [foreign] added, so automake won't check for missing NEWS, README, etc. 14 | AM_INIT_AUTOMAKE([foreign]) 15 | 16 | # Checks for programs. 17 | AC_PROG_CXX 18 | #AC_PROG_CC 19 | 20 | # Checks for header files. 21 | AC_CHECK_HEADERS([fcntl.h string.h unistd.h]) 22 | 23 | # Checks for typedefs, structures, and compiler characteristics. 24 | AC_CHECK_HEADER_STDBOOL 25 | AC_TYPE_MODE_T 26 | AC_TYPE_SIZE_T 27 | AC_CHECK_MEMBERS([struct stat.st_blksize]) 28 | 29 | # Checks for library functions. 30 | AC_CHECK_FUNCS([mkdir pow strerror sendfile]) 31 | 32 | # Checking for UnQlite 33 | AC_CHECK_HEADER([unqlite.h], [], [AC_MSG_ERROR([Could not find unqlite.h header. Please make sure you have this header in your include path. Refer to documentation for more info.])]) 34 | AC_SEARCH_LIBS([unqlite_open], [unqlite], [], [AC_MSG_ERROR([Could not find unqlite library. Please make sure you have this library in your libs path. Refer to documentation for more info.])]) 35 | 36 | # Option and variable for pkgconfig directory. 37 | AC_ARG_WITH(pkgconfigdir, 38 | [ --with-pkgconfigdir=DIR Where to install pkgconfig file. @<:@DIR/pkgconfig@:>@], 39 | [pkgconfigdir=$withval], 40 | [pkgconfigdir='${libdir}/pkgconfig']) 41 | AC_SUBST(pkgconfigdir) 42 | 43 | # Output files. 44 | AC_CONFIG_FILES([Makefile libtocc.pc]) 45 | AC_OUTPUT 46 | -------------------------------------------------------------------------------- /libtocc/src/libtocc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef LIBTOCC_LIBTOCC_H_INCLUDED 20 | #define LIBTOCC_LIBTOCC_H_INCLUDED 21 | 22 | /* 23 | * This header included all the other headers. Just to simplify usage. 24 | */ 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #endif /* LIBTOCC_LIBTOCC_H_INCLUDED */ 43 | -------------------------------------------------------------------------------- /libtocc/src/libtocc.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libtocc 7 | Description: Library of Tocc project. 8 | URL: https://tocc.aidinhut.com 9 | Version: @VERSION@ 10 | Libs: -L${libdir} -ltocc 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /libtocc/src/libtocc/check_exists.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | 20 | extern "C" 21 | { 22 | /* 23 | * This function is here to help Autoconf finds this library. 24 | * 25 | * By default, Autoconf uses C linker to find libraries and can't 26 | * detect C++ libraries. One trick is to add a C function to the 27 | * C++ library, so Autoconf can link against it. 28 | * That's why this empty function is here. 29 | */ 30 | void libtocc_exists() 31 | { 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /libtocc/src/libtocc/common/base_exception.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include "libtocc/common/base_exception.h" 20 | 21 | 22 | namespace libtocc 23 | { 24 | 25 | BaseException::~BaseException() throw() 26 | { 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /libtocc/src/libtocc/common/base_exception.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | 20 | #ifndef LIBTOCC_BASE_EXCEPTION_H_INCLUDED 21 | #define LIBTOCC_BASE_EXCEPTION_H_INCLUDED 22 | 23 | #include 24 | 25 | 26 | namespace libtocc 27 | { 28 | /* 29 | * Base class for all exceptions in libtocc. 30 | */ 31 | class BaseException : public std::exception 32 | { 33 | public: 34 | virtual ~BaseException() throw(); 35 | }; 36 | } 37 | 38 | #endif /* LIBTOCC_BASE_EXCEPTION_H_INCLUDED */ 39 | -------------------------------------------------------------------------------- /libtocc/src/libtocc/common/database_exceptions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef LIBTOCC_DATABASE_EXCEPTIONS_H_INCLUDED 20 | #define LIBTOCC_DATABASE_EXCEPTIONS_H_INCLUDED 21 | 22 | /* 23 | * Defines exceptions related to database layer. 24 | */ 25 | 26 | 27 | #include "libtocc/common/base_exception.h" 28 | 29 | namespace libtocc 30 | { 31 | /* 32 | * Base class of all the errors related to database layer. 33 | */ 34 | class BaseDatabaseException : public BaseException 35 | { 36 | public: 37 | BaseDatabaseException(const char* message) throw(); 38 | 39 | BaseDatabaseException(const BaseDatabaseException& source) throw(); 40 | 41 | BaseDatabaseException& operator=(const BaseDatabaseException& source) throw(); 42 | 43 | virtual ~BaseDatabaseException() throw(); 44 | 45 | virtual const char* what() const throw(); 46 | 47 | private: 48 | char* message; 49 | }; 50 | 51 | /* 52 | * Raises when any error occur during the initialization of the database. 53 | */ 54 | class DatabaseInitializationError : public BaseDatabaseException 55 | { 56 | public: 57 | DatabaseInitializationError(const char* message) throw(); 58 | 59 | DatabaseInitializationError(const DatabaseInitializationError& source) throw(); 60 | }; 61 | 62 | /* 63 | * Raises if any error happens during the compilation of a database script. 64 | */ 65 | class DatabaseScriptCompilationError : public BaseDatabaseException 66 | { 67 | public: 68 | DatabaseScriptCompilationError(const char* message) throw(); 69 | 70 | DatabaseScriptCompilationError(const DatabaseScriptCompilationError& source) throw(); 71 | }; 72 | 73 | /* 74 | * Raises if error occurs when executing a database script. 75 | */ 76 | class DatabaseScriptExecutionError : public BaseDatabaseException 77 | { 78 | public: 79 | DatabaseScriptExecutionError(const char* message) throw(); 80 | 81 | DatabaseScriptExecutionError(const DatabaseScriptExecutionError& source) throw(); 82 | }; 83 | 84 | /* 85 | * Raises if any logical error happened in database. i.e. a file ID 86 | * not found. 87 | */ 88 | class DatabaseScriptLogicalError : public BaseDatabaseException 89 | { 90 | public: 91 | DatabaseScriptLogicalError(const char* message) throw(); 92 | 93 | DatabaseScriptLogicalError(const DatabaseScriptLogicalError& source) throw(); 94 | }; 95 | } 96 | 97 | #endif /* LIBTOCC_DATABASE_EXCEPTIONS_H_INCLUDED */ 98 | -------------------------------------------------------------------------------- /libtocc/src/libtocc/common/expr_exceptions.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include "libtocc/common/expr_exceptions.h" 20 | 21 | namespace libtocc 22 | { 23 | 24 | BaseExprException::BaseExprException(const char* message) throw() 25 | { 26 | this->message = message; 27 | } 28 | 29 | BaseExprException::~BaseExprException() throw() 30 | { 31 | } 32 | 33 | const char* BaseExprException::what() const throw() 34 | { 35 | return this->message; 36 | } 37 | 38 | ExprCompilerError::ExprCompilerError(const char* message) throw() 39 | : BaseExprException(message) 40 | { 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /libtocc/src/libtocc/common/expr_exceptions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef LIBTOCC_EXPR_EXCEPTIONS_H_INCLUDED 20 | #define LIBTOCC_EXPR_EXCEPTIONS_H_INCLUDED 21 | 22 | #include "libtocc/common/base_exception.h" 23 | 24 | namespace libtocc 25 | { 26 | 27 | /* 28 | * Base class of all the errors related to expressions. 29 | */ 30 | class BaseExprException : public BaseException 31 | { 32 | public: 33 | BaseExprException(const char* message) throw(); 34 | 35 | virtual ~BaseExprException() throw(); 36 | 37 | virtual const char* what() const throw(); 38 | 39 | private: 40 | const char* message; 41 | }; 42 | 43 | /* 44 | * Raises if any errors occur during the compilation of expressions. 45 | */ 46 | class ExprCompilerError : public BaseExprException 47 | { 48 | public: 49 | ExprCompilerError(const char* message) throw(); 50 | }; 51 | } 52 | 53 | #endif /* LIBTOCC_EXPR_EXCEPTIONS_H_INCLUDED */ 54 | -------------------------------------------------------------------------------- /libtocc/src/libtocc/common/runtime_exceptions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef LIBTOCC_RUNTIME_EXCEPTIONS_H_INCLUDED 20 | #define LIBTOCC_RUNTIME_EXCEPTIONS_H_INCLUDED 21 | 22 | #include "libtocc/common/base_exception.h" 23 | 24 | namespace libtocc 25 | { 26 | class InvalidArgumentError : public BaseException 27 | { 28 | public: 29 | InvalidArgumentError(const char* message) throw() 30 | { 31 | this->message = message; 32 | } 33 | 34 | virtual ~InvalidArgumentError() throw() 35 | { 36 | } 37 | 38 | virtual const char* what() const throw() 39 | { 40 | return this->message; 41 | } 42 | 43 | private: 44 | const char* message; 45 | }; 46 | 47 | } 48 | 49 | 50 | #endif /* LIBTOCC_RUNTIME_EXCEPTIONS_H_INCLUDED */ 51 | -------------------------------------------------------------------------------- /libtocc/src/libtocc/database/base23.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include "libtocc/database/base23.h" 20 | 21 | #include 22 | #include 23 | 24 | 25 | const std::string DIGITS = "0123456789abcdefghijklmn"; 26 | 27 | std::string to_base23(unsigned long num) 28 | { 29 | assert(num <= 3404825447); 30 | 31 | std::string result = "0000000"; 32 | 33 | short index = 6; 34 | while (num > 0) 35 | { 36 | result[index] = DIGITS[num % 23]; 37 | num = num / 23; 38 | index--; 39 | } 40 | 41 | return result; 42 | } 43 | 44 | unsigned long from_base23(std::string num) 45 | { 46 | assert(num.length() == 7); 47 | 48 | unsigned long result = 0; 49 | for (short index = 6; index >= 0; index--) 50 | { 51 | result += DIGITS.find_first_of(num[index]) * pow(23, 6 - index); 52 | } 53 | 54 | return result; 55 | } 56 | -------------------------------------------------------------------------------- /libtocc/src/libtocc/database/base23.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef LIBTOCC_BASE_23_H_INCLUDED 20 | #define LIBTOCC_BASE_23_H_INCLUDED 21 | 22 | #include 23 | 24 | /* 25 | * Defines functions to converting from/to base 23. 26 | */ 27 | 28 | /* 29 | * Converts a base 10 number to base 23. 30 | * Note: num cannot be greater than 3404825447 31 | * Length of return string is 7. 32 | */ 33 | std::string to_base23(unsigned long num); 34 | 35 | /* 36 | * Converts a base 23 number to base 10. 37 | * Note: Length of num must be 7. 38 | */ 39 | unsigned long from_base23(std::string num); 40 | 41 | #endif /* LIBTOCC_BASE_23_H_INCLUDED */ 42 | -------------------------------------------------------------------------------- /libtocc/src/libtocc/database/funcs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef LIBTOCC_FUNCS_H_INCLUDED 20 | #define LIBTOCC_FUNCS_H_INCLUDED 21 | 22 | // `unqlite.h' is a C header, thus included inside a "C" scope. 23 | extern "C" 24 | { 25 | #include 26 | } 27 | 28 | namespace libtocc 29 | { 30 | 31 | /* 32 | * Compares pattern and string. Pattern can contain `*' as the wild card 33 | * character. 34 | * Returns true if two matches, false otherwise. 35 | */ 36 | bool wild_card_compare(const char* pattern, const char* string); 37 | 38 | /* 39 | * It's an adapter for calling `wild_card_compare' from Jx9 scripts. 40 | */ 41 | int wild_card_compare_unqlite_func(unqlite_context* context, 42 | int argc, 43 | unqlite_value** argv); 44 | } 45 | 46 | #endif /* LIBTOCC_FUNCS_H_INCLUDED */ 47 | -------------------------------------------------------------------------------- /libtocc/src/libtocc/engine/files_engine.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include "libtocc/engine/files_engine.h" 20 | 21 | #include 22 | 23 | #include"libtocc/utilities/file_utils.h" 24 | 25 | 26 | namespace libtocc 27 | { 28 | 29 | FilesEngine::FilesEngine(Database* database, 30 | FileManager* file_manager, 31 | TagsEngine* tags_engine) 32 | { 33 | this->database = database; 34 | this->file_manager = file_manager; 35 | this->tags_engine = tags_engine; 36 | } 37 | 38 | IntFileInfo FilesEngine::get(std::string file_id) 39 | { 40 | return this->database->get(file_id); 41 | } 42 | 43 | IntFileInfo FilesEngine::import_file(std::string source_path, 44 | std::string title, 45 | std::string traditional_path) 46 | { 47 | std::vector empty_tags_list; 48 | 49 | return this->import_file(source_path, 50 | title, 51 | traditional_path, 52 | empty_tags_list); 53 | } 54 | 55 | IntFileInfo FilesEngine::import_file(std::string source_path, 56 | std::string title, 57 | std::string traditional_path, 58 | std::vector tags) 59 | { 60 | if(title.empty()) 61 | { 62 | title = get_filename_from_path(source_path); 63 | } 64 | 65 | IntFileInfo new_file = this->database->create_file(tags, title, 66 | traditional_path); 67 | 68 | this->file_manager->copy(source_path, new_file.get_id()); 69 | 70 | return new_file; 71 | } 72 | 73 | void FilesEngine::remove_files(const std::vector& files_to_remove) 74 | { 75 | std::vector founded_files; 76 | 77 | this->database->remove_files(files_to_remove, founded_files); 78 | 79 | //Delete the founded files 80 | for(int i = 0; i < founded_files.size(); i++) 81 | { 82 | const std::string& file_id = std::string(founded_files[i].get_id()); 83 | this->file_manager->remove(file_id.c_str()); 84 | } 85 | } 86 | 87 | void FilesEngine::set_titles(const std::vector& file_ids, const std::string& new_title) 88 | { 89 | this->database->set_titles(file_ids, new_title); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /libtocc/src/libtocc/engine/tags_engine.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include "libtocc/engine/tags_engine.h" 20 | 21 | namespace libtocc 22 | { 23 | 24 | TagsEngine::TagsEngine(Database* database) 25 | { 26 | this->database = database; 27 | } 28 | 29 | void TagsEngine::assign_tags(std::string file_id, 30 | std::vector tags) 31 | { 32 | this->database->assign_tag(file_id, tags); 33 | } 34 | 35 | void TagsEngine::assign_tags(std::vector file_ids, 36 | std::vector tags) 37 | { 38 | this->database->assign_tag(file_ids, tags); 39 | } 40 | 41 | void TagsEngine::assign_tags(std::string file_id, std::string tag) 42 | { 43 | this->database->assign_tag(file_id, tag); 44 | } 45 | 46 | void TagsEngine::unassign_tag(const std::string& file_id, const std::string& tag) 47 | { 48 | this->database->unassign_tag(file_id, tag); 49 | } 50 | 51 | void TagsEngine::unassign_tags(const std::string& file_id, const std::vector& tags) 52 | { 53 | this->database->unassign_tags(file_id, tags); 54 | } 55 | 56 | void TagsEngine::unassign_tags(const std::vector& file_ids, const std::vector& tags) 57 | { 58 | this->database->unassign_tags(file_ids, tags); 59 | } 60 | 61 | TagStatisticsCollection TagsEngine::get_tags_statistics() 62 | { 63 | return this->database->get_tags_statistics(); 64 | } 65 | 66 | TagStatisticsCollection TagsEngine::get_tags_statistics(const std::vector& file_ids) 67 | { 68 | return this->database->get_tags_statistics(file_ids); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /libtocc/src/libtocc/exprs/compiled_expr.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include "libtocc/exprs/compiled_expr.h" 20 | 21 | namespace libtocc 22 | { 23 | CompiledExpr::CompiledExpr(compiled_expr::ExprType type, std::string value) 24 | { 25 | this->type = type; 26 | this->value = value; 27 | this->negative_expr = false; 28 | } 29 | 30 | CompiledExpr::CompiledExpr(compiled_expr::ExprType type, 31 | std::string value, 32 | bool negative_expr) 33 | { 34 | this->type = type; 35 | this->value = value; 36 | this->negative_expr = negative_expr; 37 | } 38 | 39 | compiled_expr::ExprType CompiledExpr::get_type() 40 | { 41 | return this->type; 42 | } 43 | 44 | std::string CompiledExpr::get_value() 45 | { 46 | return this->value; 47 | } 48 | 49 | bool CompiledExpr::is_negative_expr() 50 | { 51 | return this->negative_expr; 52 | } 53 | 54 | void CompiledExpr::set_is_negative_expr(bool value) 55 | { 56 | this->negative_expr = value; 57 | } 58 | }; 59 | -------------------------------------------------------------------------------- /libtocc/src/libtocc/exprs/compiled_expr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef LIBTOCC_COMPILED_EXPR_INCLUDED 20 | #define LIBTOCC_COMPILED_EXPR_INCLUDED 21 | 22 | #include 23 | #include 24 | 25 | #include "libtocc/exprs/compiled_expr_types.h" 26 | 27 | 28 | namespace libtocc 29 | { 30 | 31 | /* 32 | * When the expression compiles, it returns an instance 33 | * of this class. 34 | */ 35 | class CompiledExpr 36 | { 37 | public: 38 | /* 39 | * Construct a compiled expression. 40 | * 41 | * @param type: type of the expression that is compiled. 42 | * @param value: compiled expression. 43 | */ 44 | CompiledExpr(compiled_expr::ExprType type, std::string value); 45 | 46 | /* 47 | * Construct a compiled expression. 48 | * 49 | * @param type: type of the expression that is compiled. 50 | * @param value: compiled expression. 51 | * @param negative_expr: If set to true, it means that this expression 52 | * have negative effect: e.g. if it's a condition and is correct, the 53 | * final result should be false. 54 | */ 55 | CompiledExpr(compiled_expr::ExprType type, 56 | std::string value, 57 | bool negative_expr); 58 | 59 | /* 60 | * Returns the type of the compiled expression. 61 | */ 62 | compiled_expr::ExprType get_type(); 63 | 64 | /* 65 | * Returns the value of the compiled expression. 66 | */ 67 | std::string get_value(); 68 | 69 | /* 70 | * Returns true if this is a negative expression. 71 | * 72 | * Negative expression means that this expression 73 | * have negative effect: e.g. if it's a condition and is correct, the 74 | * final result should be false. 75 | */ 76 | bool is_negative_expr(); 77 | 78 | /* 79 | * Sets the `is_negative_expr' flag for this expression. 80 | */ 81 | void set_is_negative_expr(bool value); 82 | 83 | private: 84 | compiled_expr::ExprType type; 85 | std::string value; 86 | bool negative_expr; 87 | }; 88 | 89 | /* 90 | * Defines a list of compiled exprs. 91 | * It's simply a wrapper over `std::list', in order to hide it from API. 92 | */ 93 | class CompiledExprList 94 | { 95 | public: 96 | std::list list; 97 | }; 98 | 99 | }; 100 | 101 | #endif /* LIBTOCC_COMPILED_EXPR_INCLUDED */ 102 | -------------------------------------------------------------------------------- /libtocc/src/libtocc/exprs/compiled_expr_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef LIBTOCC_COMPILED_EXPR_TYPES_H_INCLUDED 20 | #define LIBTOCC_COMPILED_EXPR_TYPES_H_INCLUDED 21 | 22 | 23 | namespace libtocc 24 | { 25 | 26 | namespace compiled_expr 27 | { 28 | /* 29 | * Types of compiled expressions, used by CompiledExpr class. 30 | */ 31 | enum ExprType { CONNECTIVE, END_CONNECTIVE_GROUP, TAG, FIELD, NOPE }; 32 | }; 33 | 34 | } 35 | 36 | #endif /* LIBTOCC_COMPILED_EXPR_TYPES_H_INCLUDED */ 37 | -------------------------------------------------------------------------------- /libtocc/src/libtocc/exprs/compiler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef LIBTOCC_COMPILER_H_INCLUDED 20 | #define LIBTOCC_COMPILER_H_INCLUDED 21 | 22 | #include 23 | #include "libtocc/exprs/query.h" 24 | 25 | namespace libtocc 26 | { 27 | /* 28 | * Compiler of queries. 29 | */ 30 | class QueryCompiler 31 | { 32 | 33 | public: 34 | /* 35 | * Compiles a query object to a Jx9 script. 36 | * 37 | * @param query_to_compile: Query object to compile. 38 | * @param result_var_name: Variable name inside the Jx9 script that 39 | * keeps the result of the query. 40 | * 41 | * @return: Compiled Jx9 script. 42 | */ 43 | std::string compile(Query& query_to_compile, 44 | std::string result_var_name="fetched_records"); 45 | 46 | }; 47 | }; 48 | 49 | #endif /* LIBTOCC_COMPILER_H_INCLUDED */ 50 | -------------------------------------------------------------------------------- /libtocc/src/libtocc/exprs/expr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef LIBTOCC_EXPR_H_INCLUDED 20 | #define LIBTOCC_EXPR_H_INCLUDED 21 | 22 | namespace libtocc 23 | { 24 | 25 | /* 26 | * Defines base of all expressions. 27 | */ 28 | 29 | /* 30 | * Types of expressions available. 31 | */ 32 | namespace expr_type 33 | { 34 | enum ExprType { CONNECTIVE, FUNCTION, OPERATION, FIELD }; 35 | } 36 | 37 | /* 38 | * Abstract base class for all the expressions. 39 | */ 40 | class Expr 41 | { 42 | // To allow these classes delete a pointer to Expr. 43 | friend class ConnectiveExpr; 44 | 45 | public: 46 | 47 | virtual ~Expr() {} 48 | 49 | /* 50 | * Returns the type of the expression. 51 | */ 52 | virtual expr_type::ExprType get_type() = 0; 53 | 54 | /* 55 | * Returns a deep copy of this instance. 56 | */ 57 | virtual Expr* clone() = 0; 58 | 59 | }; 60 | 61 | }; 62 | 63 | #endif /* LIBTOCC_EXPR_H_INCLUDED */ 64 | -------------------------------------------------------------------------------- /libtocc/src/libtocc/exprs/functions.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include "libtocc/exprs/functions.h" 20 | 21 | #include 22 | 23 | 24 | namespace libtocc 25 | { 26 | class FunctionExpr::ProtectedData 27 | { 28 | public: 29 | std::string arg; 30 | }; 31 | 32 | FunctionExpr::FunctionExpr(const char* arg) 33 | { 34 | this->protected_data = new ProtectedData(); 35 | 36 | this->protected_data->arg = arg; 37 | } 38 | 39 | FunctionExpr::FunctionExpr(FunctionExpr& source) 40 | { 41 | this->protected_data = new ProtectedData(); 42 | 43 | this->protected_data->arg = source.protected_data->arg; 44 | } 45 | 46 | expr_type::ExprType FunctionExpr::get_type() 47 | { 48 | return expr_type::FUNCTION; 49 | } 50 | 51 | const char* FunctionExpr::compile(const char* second_arg) 52 | { 53 | std::string result(get_func_name()); 54 | result += "('" + this->protected_data->arg + "', "; 55 | result += second_arg; 56 | result += ")"; 57 | 58 | return result.c_str(); 59 | } 60 | 61 | Expr* FunctionExpr::clone() 62 | { 63 | return new FunctionExpr(*this); 64 | } 65 | 66 | const char* FunctionExpr::get_func_name() 67 | { 68 | return "NotImplementedFunc"; 69 | } 70 | 71 | WildCardExpr::WildCardExpr(const char* arg) 72 | : FunctionExpr(arg) 73 | { 74 | } 75 | 76 | WildCardExpr::WildCardExpr(WildCardExpr& source) 77 | : FunctionExpr(source) 78 | { 79 | } 80 | 81 | Expr* WildCardExpr::clone() 82 | { 83 | return new WildCardExpr(*this); 84 | } 85 | 86 | const char* WildCardExpr::get_func_name() 87 | { 88 | return "wild_card_compare"; 89 | } 90 | }; 91 | -------------------------------------------------------------------------------- /libtocc/src/libtocc/exprs/functions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef LIBTOCC_FUNCTION_H_INCLUDED 20 | #define LIBTOCC_FUNCTION_H_INCLUDED 21 | 22 | #include 23 | #include "libtocc/exprs/expr.h" 24 | 25 | namespace libtocc 26 | { 27 | 28 | /* 29 | * Defines base class of all function expressions. 30 | */ 31 | class FunctionExpr : public Expr 32 | { 33 | public: 34 | /* 35 | * @param arg: Argument of this function. For example: 36 | * WildCard("*book*") 37 | */ 38 | FunctionExpr(const char* arg); 39 | 40 | /* 41 | * Copy Constructor. 42 | */ 43 | FunctionExpr(FunctionExpr& source); 44 | 45 | virtual expr_type::ExprType get_type(); 46 | 47 | /* 48 | * Compiles the function. 49 | * 50 | * @param base_arg: Second argument of the function. 51 | * For example: 52 | * Regex.compile("record.tag") -> regex_compare("pattern", record.tag) 53 | */ 54 | virtual const char* compile(const char* second_arg); 55 | 56 | /* 57 | * Clones this instance. 58 | */ 59 | virtual Expr* clone(); 60 | 61 | protected: 62 | /* 63 | * Returns the function name as string. 64 | */ 65 | virtual const char* get_func_name(); 66 | 67 | class ProtectedData; 68 | ProtectedData* protected_data; 69 | }; 70 | 71 | class WildCardExpr : public FunctionExpr 72 | { 73 | public: 74 | /* 75 | * @param arg: Argument of this function. For example: 76 | * WildCard("*book*") 77 | */ 78 | WildCardExpr(const char* arg); 79 | 80 | /* 81 | * Copy Constructor. 82 | */ 83 | WildCardExpr(WildCardExpr& source); 84 | /* 85 | * Clones this instance. 86 | */ 87 | virtual Expr* clone(); 88 | 89 | protected: 90 | virtual const char* get_func_name(); 91 | }; 92 | 93 | }; 94 | 95 | #endif /* LIBTOCC_FUNCTION_H_INCLUDED */ 96 | -------------------------------------------------------------------------------- /libtocc/src/libtocc/exprs/operations.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | 20 | #include "libtocc/exprs/operations.h" 21 | 22 | #include 23 | 24 | #include "libtocc/exprs/compiled_expr.h" 25 | 26 | 27 | namespace libtocc 28 | { 29 | class OperationExpr::ProtectedData 30 | { 31 | public: 32 | FieldExpr* operand; 33 | }; 34 | 35 | OperationExpr::OperationExpr(FieldExpr& operand) 36 | { 37 | this->protected_data = new ProtectedData(); 38 | 39 | this->protected_data->operand = (FieldExpr*)operand.clone(); 40 | } 41 | 42 | OperationExpr::OperationExpr(const OperationExpr& source) 43 | { 44 | this->protected_data = new ProtectedData(); 45 | 46 | this->protected_data->operand = 47 | (FieldExpr*)source.protected_data->operand->clone(); 48 | } 49 | 50 | OperationExpr::~OperationExpr() 51 | { 52 | if (this->protected_data != NULL) 53 | { 54 | delete this->protected_data->operand; 55 | 56 | delete this->protected_data; 57 | this->protected_data = NULL; 58 | } 59 | } 60 | 61 | expr_type::ExprType OperationExpr::get_type() 62 | { 63 | return expr_type::OPERATION; 64 | } 65 | 66 | CompiledExpr OperationExpr::compile() 67 | { 68 | return this->protected_data->operand->compile(); 69 | } 70 | 71 | Expr* OperationExpr::clone() 72 | { 73 | return new OperationExpr(*this); 74 | } 75 | 76 | Not::Not(FieldExpr& operand) 77 | : OperationExpr(operand) 78 | { 79 | } 80 | 81 | Not::Not(const Not& source) 82 | : OperationExpr(source) 83 | { 84 | } 85 | 86 | CompiledExpr Not::compile() 87 | { 88 | CompiledExpr result = this->protected_data->operand->compile(); 89 | result.set_is_negative_expr(true); 90 | return result; 91 | } 92 | 93 | Expr* Not::clone() 94 | { 95 | return new Not(*this); 96 | } 97 | }; 98 | -------------------------------------------------------------------------------- /libtocc/src/libtocc/exprs/operations.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | 20 | #ifndef LIBTOCC_OPERAND_H_INCLUDED 21 | #define LIBTOCC_OPERAND_H_INCLUDED 22 | 23 | #include "libtocc/exprs/expr.h" 24 | #include "libtocc/exprs/fields.h" 25 | 26 | 27 | namespace libtocc 28 | { 29 | 30 | // Forward declaration: This shouldn't be exposed in the public headers. 31 | class CompiledExpr; 32 | 33 | 34 | /* 35 | * Base class of all operand expressions. 36 | */ 37 | class OperationExpr : public Expr 38 | { 39 | public: 40 | /* 41 | * @param operand: Operand of this operation. 42 | * For example: Not(Tag("bad-photo")) 43 | */ 44 | OperationExpr(FieldExpr& operand); 45 | 46 | /* 47 | * Copy constructor. 48 | */ 49 | OperationExpr(const OperationExpr& source); 50 | 51 | virtual ~OperationExpr(); 52 | 53 | /* 54 | * Gets the type of this expression. 55 | */ 56 | virtual expr_type::ExprType get_type(); 57 | 58 | /* 59 | * Compiles the expression. 60 | */ 61 | virtual CompiledExpr compile(); 62 | 63 | /* 64 | * Creates a copy of the expression. 65 | */ 66 | virtual Expr* clone(); 67 | 68 | protected: 69 | class ProtectedData; 70 | ProtectedData* protected_data; 71 | }; 72 | 73 | class Not : public OperationExpr 74 | { 75 | public: 76 | 77 | Not(FieldExpr& operand); 78 | 79 | Not(const Not& source); 80 | 81 | /* 82 | * Compiles the expression. 83 | */ 84 | virtual CompiledExpr compile(); 85 | 86 | /* 87 | * Creates a copy of the expression. 88 | */ 89 | virtual Expr* clone(); 90 | }; 91 | }; 92 | 93 | #endif /* LIBTOCC_OPERAND_H_INCLUDED */ 94 | -------------------------------------------------------------------------------- /libtocc/src/libtocc/exprs/query.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include "libtocc/exprs/query.h" 20 | 21 | namespace libtocc 22 | { 23 | 24 | Query::Query(ConnectiveExpr& expression) 25 | { 26 | this->expr = (ConnectiveExpr*)expression.clone(); 27 | } 28 | 29 | Query::~Query() 30 | { 31 | delete this->expr; 32 | this->expr = NULL; 33 | } 34 | 35 | ConnectiveExpr* Query::get_expr() 36 | { 37 | return this->expr; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /libtocc/src/libtocc/exprs/query.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef LIBTOCC_QUERY_H_INCLUDED 20 | #define LIBTOCC_QUERY_H_INCLUDED 21 | 22 | #include "libtocc/exprs/connectives.h" 23 | 24 | namespace libtocc 25 | { 26 | 27 | /* 28 | * Defines a Query object. 29 | * To execute a query on database, use need 30 | * an instance of this class. 31 | */ 32 | class Query 33 | { 34 | public: 35 | /* 36 | * @param expression: Expression of this query. 37 | * i.e. the expression that will be executed when 38 | * this query object executes. 39 | */ 40 | Query(ConnectiveExpr& expression); 41 | 42 | ~Query(); 43 | 44 | /* 45 | * Gets the internal expression. 46 | */ 47 | ConnectiveExpr* get_expr(); 48 | 49 | private: 50 | ConnectiveExpr* expr; 51 | }; 52 | } 53 | 54 | #endif /* LIBTOCC_QUERY_H_INCLUDED */ 55 | -------------------------------------------------------------------------------- /libtocc/src/libtocc/file_system/file_manager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef LIBTOCC_FILE_MANAGER_H_INCLUDED 20 | #define LIBTOCC_FILE_MANAGER_H_INCLUDED 21 | 22 | /* 23 | * Defines FileManager class. 24 | */ 25 | 26 | #include 27 | 28 | namespace libtocc 29 | { 30 | 31 | /* 32 | * A class for managing files on a file system. 33 | * 34 | * @note: Methods like create and copy will replace the existing 35 | * file without any notify or confirmation. It's because the 36 | * engine should check for duplicated before calling these 37 | * methods. 38 | */ 39 | class FileManager 40 | { 41 | public: 42 | /* 43 | * Constructor. 44 | * @param base_path: Path to work with. This is the root path of 45 | * where it keeps files. 46 | */ 47 | FileManager(std::string base_path); 48 | 49 | /* 50 | * Creates a file with the specified ID, and returns a file 51 | * descriptor. 52 | * Note that it replace the existing file silently. 53 | */ 54 | int create(std::string file_id); 55 | 56 | /* 57 | * Opens the file with the specified ID, and returns its 58 | * file descriptor. 59 | */ 60 | int open_file(std::string file_id, char mode); 61 | 62 | /* 63 | * Removes a file. 64 | * It silently ignores "file does not exists". 65 | */ 66 | void remove(std::string file_id); 67 | 68 | /* 69 | * Copies a file to the specified file ID. 70 | * Note that It replaces the existing file silently. 71 | * 72 | * @param source_path: Absolute path of the file to copy. 73 | * @param file_id: ID of the file to copy the source to. 74 | */ 75 | void copy(std::string source_path, std::string file_id); 76 | 77 | /* 78 | * Gets the path of the file on the Tocc-managed file system. 79 | */ 80 | std::string get_physical_path(std::string file_id); 81 | 82 | private: 83 | std::string base_path; 84 | 85 | /* 86 | * Creates the specified path recursively. 87 | */ 88 | void ensure_path_exists(std::string path); 89 | 90 | /* 91 | * Creates the specified path. 92 | */ 93 | void create_dir(std::string path); 94 | 95 | /* 96 | * Converts the specified file_id to a directory path. 97 | */ 98 | std::string id_to_dir_path(std::string id); 99 | 100 | /* 101 | * Converts the specified file_id to a file path. 102 | */ 103 | std::string id_to_file_path(std::string id); 104 | }; 105 | 106 | }; 107 | 108 | #endif /* LIBTOCC_FILE_MANAGER_H_INCLUDE */ 109 | -------------------------------------------------------------------------------- /libtocc/src/libtocc/file_system/helpers.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | /* 20 | * Defines some helper functions for the file system layer. 21 | */ 22 | 23 | #include 24 | 25 | #include "libtocc/common/file_system_exceptions.h" 26 | #include 27 | 28 | namespace libtocc 29 | { 30 | 31 | /* 32 | * Throws and exception according to the errno. 33 | * 34 | * @param errno: System's errno. 35 | * @param file_path: (optional) path of the file that this 36 | * error is happened for. 37 | */ 38 | void handle_errno(int err_no, std::string file_path="") 39 | { 40 | if (err_no == ENOSPC || err_no == EDQUOT) 41 | { 42 | throw InsufficientSpaceError(); 43 | } 44 | if (err_no == ENOTSUP) 45 | { 46 | throw XAttrsAreNotSupportedError(); 47 | } 48 | if (err_no == EACCES) 49 | { 50 | throw AccessDeniedError(file_path.c_str()); 51 | } 52 | if (err_no == EBADF) 53 | { 54 | throw BadFDError(file_path.c_str()); 55 | } 56 | if (err_no == EFAULT) 57 | { 58 | throw BadAddressError(file_path.c_str()); 59 | } 60 | if (err_no == ELOOP) 61 | { 62 | throw InfinitLinkLoopError(file_path.c_str()); 63 | } 64 | if (err_no == ENAMETOOLONG) 65 | { 66 | throw TooLongPathError(); 67 | } 68 | if (err_no == ENOENT) 69 | { 70 | throw BadPathError(file_path.c_str()); 71 | } 72 | if (err_no == ENOMEM) 73 | { 74 | throw OutOfMemoryError(); 75 | } 76 | if (err_no == ENOTDIR) 77 | { 78 | throw NotADirectoryError(); 79 | } 80 | if (err_no == ERANGE) 81 | { 82 | throw SizeOfBufferIsTooSmallError(file_path.c_str()); 83 | } 84 | if (err_no == EROFS) 85 | { 86 | throw ReadOnlyFileSystemError(); 87 | } 88 | if (err_no == EMFILE) 89 | { 90 | throw MaxOpenFilesReachedError(); 91 | } 92 | // If it was none of the above. 93 | throw OtherFileSystemError(err_no); 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /libtocc/src/libtocc/utilities/file_info_converter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef LIBTOCC_FILE_INFO_CONVERTER_H_INCLUDED 20 | #define LIBTOCC_FILE_INFO_CONVERTER_H_INCLUDED 21 | 22 | #include 23 | #include 24 | 25 | #include "libtocc/common/int_file_info.h" 26 | #include "libtocc/front_end/file_info.h" 27 | #include "libtocc/file_system/file_manager.h" 28 | 29 | 30 | namespace libtocc 31 | { 32 | FileInfo to_external_file_info(const IntFileInfo* internal_file_info, FileManager* file_manager); 33 | 34 | IntFileInfo to_internal_file_info(const FileInfo* external_file_info); 35 | 36 | FileInfoCollection to_external_file_infos(std::vector internal_file_infos, FileManager* file_manager); 37 | 38 | std::vector tags_to_vector(const TagsCollection* collection); 39 | 40 | TagsCollection vector_to_tags(const std::vector* vector); 41 | 42 | std::vector file_info_collection_to_vector_ids(const FileInfoCollection& file_info_collection); 43 | 44 | std::vector const_char_array_to_vector(const char* char_array[], int char_array_size); 45 | 46 | std::vector string_vector_to_ulong_vector(const std::vector vect_of_strings); 47 | } 48 | 49 | #endif /* LIBTOCC_FILE_INFO_CONVERTER_H_INCLUDED */ 50 | -------------------------------------------------------------------------------- /libtocc/src/libtocc/utilities/file_utils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include"libtocc/utilities/file_utils.h" 20 | 21 | namespace libtocc 22 | { 23 | std::string get_filename_from_path(std::string path) 24 | { 25 | std::string filename; 26 | 27 | //extract the file from path 28 | int last_slash_index = path.rfind("/"); 29 | 30 | if(last_slash_index != std::string::npos) 31 | { 32 | filename = path.substr(last_slash_index + 1, path.length()); 33 | } 34 | else 35 | { 36 | if(path.length()!=0) 37 | { 38 | filename = path; 39 | } 40 | } 41 | 42 | return filename; 43 | } 44 | 45 | bool is_path_parent_exists(std::string database_path) 46 | { 47 | DIR* directory_ptr = NULL; 48 | int pos = 0; 49 | 50 | pos = database_path.rfind('/'); 51 | std::string base_path = database_path.substr(0, pos); 52 | directory_ptr = opendir(base_path.c_str()); 53 | if(directory_ptr == NULL) 54 | { 55 | return false; 56 | } 57 | 58 | closedir(directory_ptr); 59 | return true; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /libtocc/src/libtocc/utilities/file_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef LIBTOCC_FILE_FILE_UTILS_H_INCLUDED 20 | #define LIBTOCC_FILE_FILE_UTILS_H_INCLUDED 21 | 22 | #include 23 | #include 24 | 25 | namespace libtocc 26 | { 27 | /* 28 | * Extract file name from the specified path, and returns it. 29 | * It returns file name with its extension. 30 | */ 31 | std::string get_filename_from_path(std::string path); 32 | 33 | /* 34 | * Checks if the parent directory of specified path exists. 35 | */ 36 | bool is_path_parent_exists(std::string path); 37 | } 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /libtocc/tests/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Makefile.am -- Process this file with automake to produce Makefile.in 2 | 3 | # Output and source files. 4 | bin_PROGRAMS = libtocctests 5 | libtocctests_SOURCES = database/database_initializer.cpp database/wild_card_tests.cpp database/expr_tests.cpp database/get_file_tests.cpp database/database_basic_tests.cpp database/tag_operation_tests.cpp database/find_empty_id_tests.cpp database/duplicated_traditional_path_tests.cpp engine/files_engine_tests.cpp engine/tags_engine_tests.cpp file_system/file_system_basic_tests.cpp front_end/front_end_initializer.cpp front_end/file_info_tests.cpp front_end/front_end_get_tests.cpp front_end/front_end_delete_file_tests.cpp front_end/front_end_assign_tag_tests.cpp front_end/front_end_import_file_tests.cpp front_end/front_end_import_utf_file_tests.cpp front_end/query_files_tests.cpp front_end/front_end_tag_statistics_tests.cpp front_end/front_end_set_file_title.cpp utilities/file_utils_tests.cpp main.cpp 6 | 7 | -------------------------------------------------------------------------------- /libtocc/tests/bootstrap: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | aclocal 6 | autoconf -Wall 7 | automake -Wall --add-missing 8 | -------------------------------------------------------------------------------- /libtocc/tests/configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ([2.69]) 5 | AC_INIT([libtocc-tests], [1.0.1], [tocc@aidinhut.com], [Tests of libtocc], [https://tocc.aidinhut.com]) 6 | AC_CONFIG_SRCDIR([main.cpp]) 7 | #AC_CONFIG_HEADERS([config.h]) 8 | 9 | # Initializing Automake 10 | # [foreign] added, so automake won't check for missing NEWS, README, etc. 11 | AM_INIT_AUTOMAKE([foreign]) 12 | 13 | # Checks for programs. 14 | AC_PROG_CXX 15 | AC_PROG_CC 16 | 17 | # Checks for header files. 18 | AC_CHECK_HEADERS([unistd.h]) 19 | 20 | # Checks for typedefs, structures, and compiler characteristics. 21 | AC_CHECK_HEADER_STDBOOL 22 | 23 | # Checks for UnQlite 24 | # Since it's a C header, we need to set lang to C 25 | AC_LANG_PUSH(C) 26 | AC_CHECK_HEADER([unqlite.h], [], [AC_MSG_ERROR([Could not find unqlite.h header. Please make sure you have this header in your include path. Refer to documents for more info.])]) 27 | AC_SEARCH_LIBS([unqlite_open], [unqlite], [], [AC_MSG_ERROR([Could not find unqlite library. Please make sure you have this library in your libs path. Refer to documentations for more info.])]) 28 | 29 | # Checking for libtocc. 30 | # Setting lang to C++, because followings all are C++. 31 | AC_LANG_PUSH(C++) 32 | # The fourth argument is: don't try to compile this header. 33 | AC_CHECK_HEADER([libtocc/exprs/compiler.h], [], [AC_MSG_ERROR([Could not find libtocc/exprs/compiler.h header. Tests included headers directly from the libtocc/src/ directory. Please make sure you have libtocc/src/ in you includes path. Refer to documents for more info.])], [-]) 34 | # `libtocc_exists' function used to check for libtocc. See the documentation 35 | # about how to check for libtocc with Autoconf. 36 | AC_SEARCH_LIBS([libtocc_exists], [tocc], [], [AC_MSG_ERROR([Could not find libtocc library. Please make sure you have this library in your libs path. Refer to documentations for more info.])]) 37 | 38 | # Checking for catch. 39 | AC_CHECK_HEADER([catch.hpp], [], [AC_MSG_ERROR([Could not find catch.hpp. Please download and install it from https://github.com/philsquared/Catch])]) 40 | 41 | # Changing back the language to C 42 | AC_LANG_POP 43 | 44 | # Output files. 45 | AC_CONFIG_FILES([Makefile]) 46 | AC_OUTPUT 47 | -------------------------------------------------------------------------------- /libtocc/tests/database/database_initializer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include 20 | 21 | #include "libtocc/database/database.h" 22 | 23 | 24 | // This should be run before all the other database tests, since it's 25 | // initialize an environment for tests. 26 | TEST_CASE("Database Initializer") 27 | { 28 | libtocc::Database db("/tmp/tocctests/tocc.test.db"); 29 | db.initialize(); 30 | } 31 | -------------------------------------------------------------------------------- /libtocc/tests/database/duplicated_traditional_path_tests.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include "catch.hpp" 20 | #include 21 | #include 22 | 23 | #include "libtocc/common/int_file_info.h" 24 | #include "libtocc/common/database_exceptions.h" 25 | #include "libtocc/database/database.h" 26 | 27 | 28 | TEST_CASE("database: duplicated traditional path tests") 29 | { 30 | // Creating the database. 31 | libtocc::Database db("/tmp/tocctests/tocc.test.db"); 32 | 33 | // Creating two files without traditional path 34 | libtocc::IntFileInfo new_file_1 = db.create_file("Title 1"); 35 | libtocc::IntFileInfo new_file_2 = db.create_file("Title 2"); 36 | 37 | // Should pass 38 | REQUIRE(new_file_1.get_title() == "Title 1"); 39 | REQUIRE(new_file_1.get_traditional_path() == ""); 40 | REQUIRE(new_file_2.get_title() == "Title 2"); 41 | REQUIRE(new_file_2.get_traditional_path() == ""); 42 | 43 | // Creating two files with different traditional path 44 | libtocc::IntFileInfo new_file_3 = 45 | db.create_file("Title 3", "/old/path/test_file_3"); 46 | libtocc::IntFileInfo new_file_4 = 47 | db.create_file("Title 4", "/old/path/test_file_4"); 48 | 49 | // Should pass 50 | REQUIRE(new_file_3.get_title() == "Title 3"); 51 | REQUIRE(new_file_3.get_traditional_path() == "/old/path/test_file_3"); 52 | REQUIRE(new_file_4.get_title() == "Title 4"); 53 | REQUIRE(new_file_4.get_traditional_path() == "/old/path/test_file_4"); 54 | 55 | // Creating two files with identical traditional path 56 | libtocc::IntFileInfo new_file_5 = 57 | db.create_file("Title 5", "/old/path/test_file"); 58 | 59 | // Should throw exception 60 | REQUIRE_THROWS_AS( 61 | db.create_file("Title 6", "/old/path/test_file"), 62 | libtocc::DatabaseScriptLogicalError); 63 | } 64 | -------------------------------------------------------------------------------- /libtocc/tests/database/expr_tests.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | #include "libtocc/exprs/query.h" 23 | #include "libtocc/exprs/connectives.h" 24 | #include "libtocc/exprs/fields.h" 25 | #include "libtocc/exprs/compiler.h" 26 | 27 | // TODO: Give generated Jx9 scripts to Unqlite, to check if their 28 | // syntactically correct. 29 | TEST_CASE("database: expr tests") 30 | { 31 | // Compiling a simple expression. 32 | libtocc::Tag book_tag("book"); 33 | libtocc::And all_expressions(book_tag); 34 | libtocc::Tag year_tag("2010"); 35 | all_expressions.add(year_tag); 36 | libtocc::Title title("Programming"); 37 | all_expressions.add(title); 38 | 39 | libtocc::Query query_object(all_expressions); 40 | 41 | libtocc::QueryCompiler compiler; 42 | 43 | std::string compiled_expression = compiler.compile(query_object); 44 | 45 | // Compiling a little more complex expression. 46 | libtocc::Tag photo_tag("photo"); 47 | libtocc::And main_and(photo_tag); 48 | libtocc::Tag bw_tag("b&w"); 49 | libtocc::Or first_or(bw_tag); 50 | libtocc::Tag abstract_tag("abstract"); 51 | first_or.add(abstract_tag); 52 | libtocc::Tag hdr_tag("hdr"); 53 | libtocc::Or second_or(hdr_tag); 54 | libtocc::Tag landscape_tag("landscape"); 55 | second_or.add(landscape_tag); 56 | libtocc::And internal_and(first_or); 57 | internal_and.add(second_or); 58 | main_and.add(internal_and); 59 | 60 | libtocc::Query complex_query_object(main_and); 61 | 62 | std::string complex_result = compiler.compile(complex_query_object); 63 | 64 | } 65 | -------------------------------------------------------------------------------- /libtocc/tests/database/find_empty_id_tests.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include "catch.hpp" 20 | #include 21 | #include 22 | #include 23 | 24 | #include "libtocc/common/int_file_info.h" 25 | #include "libtocc/database/database.h" 26 | 27 | 28 | TEST_CASE("database: find empty ID") 29 | { 30 | // Creating the database. 31 | libtocc::Database db("/tmp/tocctests/tocc.test.db"); 32 | 33 | // Creating files 34 | libtocc::IntFileInfo new_file_1 = db.create_file("file__1", "/old/path/file__1"); 35 | libtocc::IntFileInfo new_file_2 = db.create_file("file__2", "/old/path/file__2"); 36 | 37 | //delete file 1 38 | std::vector ids_to_delete; 39 | ids_to_delete.push_back(new_file_1.get_id()); 40 | std::vector founded_files; 41 | 42 | db.remove_files(ids_to_delete, founded_files); 43 | 44 | //create a new file 45 | libtocc::IntFileInfo new_file_3 = db.create_file("file__3", "/old/path/file__3"); 46 | 47 | REQUIRE(atoi(new_file_1.get_id().c_str()) == atoi(new_file_3.get_id().c_str())); 48 | 49 | //Delete a bunch of files 50 | ids_to_delete.clear(); 51 | ids_to_delete.push_back(new_file_2.get_id()); 52 | ids_to_delete.push_back(new_file_3.get_id()); 53 | 54 | db.remove_files(ids_to_delete, founded_files); 55 | 56 | //create new files 57 | // Note file__4 has the file__1 first id 58 | libtocc::IntFileInfo new_file_4 = db.create_file("file__4", "/old/path/file__4"); 59 | REQUIRE(atoi(new_file_4.get_id().c_str()) == atoi(new_file_3.get_id().c_str())); 60 | 61 | libtocc::IntFileInfo new_file_5 = db.create_file("file__5", "/old/path/file__5"); 62 | REQUIRE(atoi(new_file_5.get_id().c_str()) == atoi(new_file_2.get_id().c_str())); 63 | } 64 | -------------------------------------------------------------------------------- /libtocc/tests/database/get_file_tests.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include 20 | 21 | #include "libtocc/database/database.h" 22 | 23 | TEST_CASE("database: get file tests") 24 | { 25 | // Creating the database. 26 | libtocc::Database db("/tmp/tocctests/tocc.test.db"); 27 | 28 | // Getting a not-existed file. 29 | REQUIRE_THROWS(db.get("ffr98a0")); 30 | } 31 | -------------------------------------------------------------------------------- /libtocc/tests/database/wild_card_tests.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | 20 | #include 21 | 22 | #include "libtocc/database/funcs.h" 23 | 24 | 25 | TEST_CASE("database::wild_card_tests: no wild card match") 26 | { 27 | REQUIRE(libtocc::wild_card_compare("same thing", "same thing")); 28 | } 29 | 30 | TEST_CASE("database::wild_card_tests: simple match 1") 31 | { 32 | REQUIRE(libtocc::wild_card_compare("ha*", "happy")); 33 | } 34 | 35 | TEST_CASE("database::wild_card_tests: simple match 2") 36 | { 37 | REQUIRE(libtocc::wild_card_compare("ha*y", "happy")); 38 | } 39 | 40 | TEST_CASE("database::wild_card_tests: simple match 3") 41 | { 42 | REQUIRE(libtocc::wild_card_compare("*y", "happy")); 43 | } 44 | 45 | TEST_CASE("database::wild_card_tests: two cards match") 46 | { 47 | REQUIRE(libtocc::wild_card_compare("*ve*cc", "I love tocc")); 48 | } 49 | 50 | TEST_CASE("database::wild_card_tests: no wild card un-match") 51 | { 52 | REQUIRE(!libtocc::wild_card_compare("sad", "happy")); 53 | } 54 | 55 | TEST_CASE("database::wild_card_tests: no wild card un-match 2") 56 | { 57 | REQUIRE(!libtocc::wild_card_compare("random int", "random str")); 58 | } 59 | 60 | TEST_CASE("database::wild_card_tests: simple un-match 1") 61 | { 62 | REQUIRE(!libtocc::wild_card_compare("do*s", "don't match me")); 63 | } 64 | 65 | TEST_CASE("database::wild_card_tests: simple un-match 2") 66 | { 67 | REQUIRE(!libtocc::wild_card_compare("*mass", "don't match me")); 68 | } 69 | 70 | TEST_CASE("database::wild_card_tests: simple un-match 3") 71 | { 72 | REQUIRE(!libtocc::wild_card_compare("don't do*", "don't match me")); 73 | } 74 | 75 | TEST_CASE("database::wild_card_tests: empty pattern") 76 | { 77 | REQUIRE(!libtocc::wild_card_compare("", "don't match me")); 78 | } 79 | 80 | TEST_CASE("database::wild_card_tests: empty string") 81 | { 82 | REQUIRE(!libtocc::wild_card_compare("wild*", "")); 83 | } 84 | 85 | TEST_CASE("database::wild_card_tests: NULL pattern") 86 | { 87 | REQUIRE(!libtocc::wild_card_compare(NULL, "don't match me")); 88 | } 89 | 90 | TEST_CASE("database::wild_card_tests: NULL string") 91 | { 92 | REQUIRE(!libtocc::wild_card_compare("*wild", NULL)); 93 | } 94 | 95 | TEST_CASE("database::wild_card_tests: NULL NULL") 96 | { 97 | REQUIRE(!libtocc::wild_card_compare(NULL, NULL)); 98 | } 99 | -------------------------------------------------------------------------------- /libtocc/tests/engine/files_engine_tests.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | #include "libtocc/common/int_file_info.h" 23 | #include "libtocc/database/database.h" 24 | #include "libtocc/engine/tags_engine.h" 25 | #include "libtocc/engine/files_engine.h" 26 | #include "libtocc/engine/files_engine.h" 27 | 28 | 29 | TEST_CASE("engine: files engine tests") 30 | { 31 | /* 32 | * Creating instance of files engine. 33 | */ 34 | libtocc::Database db("/tmp/tocctests/tocc.test.db"); 35 | libtocc::FileManager file_manager("/tmp/tocctests/"); 36 | libtocc::TagsEngine tags_engine(&db); 37 | libtocc::FilesEngine files_engine(&db, &file_manager, &tags_engine); 38 | 39 | /* 40 | * Testing file import. 41 | */ 42 | // Creating a test file to import. 43 | std::ofstream file_stream; 44 | file_stream.open("/tmp/tocctests/tocc_a_file_to_import"); 45 | file_stream << "some data..."; 46 | file_stream.close(); 47 | 48 | // Copying the file. 49 | libtocc::IntFileInfo first_file = files_engine.import_file("/tmp/tocctests/tocc_a_file_to_import"); 50 | // Checking if it's OK. 51 | REQUIRE(first_file.get_title() == "tocc_a_file_to_import"); 52 | REQUIRE(first_file.get_traditional_path() == ""); 53 | REQUIRE(first_file.get_tags().size() == 0); 54 | 55 | /* 56 | * Getting the same file. 57 | */ 58 | libtocc::IntFileInfo fetched_first_file = files_engine.get(first_file.get_id()); 59 | // Checking if it's OK. 60 | REQUIRE(fetched_first_file.get_title() == "tocc_a_file_to_import"); 61 | REQUIRE(fetched_first_file.get_traditional_path() == ""); 62 | REQUIRE(fetched_first_file.get_tags().size() == 0); 63 | 64 | } 65 | -------------------------------------------------------------------------------- /libtocc/tests/engine/tags_engine_tests.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include "libtocc/database/database.h" 24 | #include "libtocc/engine/tags_engine.h" 25 | 26 | TEST_CASE("engine: tags engine tests") 27 | { 28 | // Creating instance of engine. 29 | libtocc::Database db("/tmp/tocctests/tocc.test.db"); 30 | libtocc::TagsEngine tags_engine(&db); 31 | 32 | // Assigning some tags. 33 | std::vector new_tags; 34 | new_tags.push_back("author: Mr.Pen"); 35 | new_tags.push_back("type: pdf"); 36 | tags_engine.assign_tags("0000001", new_tags); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /libtocc/tests/file_system/file_system_basic_tests.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | /* 20 | * Defines functions for testing FileManager class. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "libtocc/common/base_exception.h" 29 | #include "libtocc/file_system/file_manager.h" 30 | 31 | TEST_CASE("file_system: basic tests") 32 | { 33 | std::string base_path = "/tmp/tocctests/"; 34 | std::string file_id = "t00f4ia"; 35 | std::string equivalent_path = "/tmp/tocctests/t/00/fa/ia"; 36 | libtocc::FileManager file_manager(base_path); 37 | 38 | /* 39 | * Testing file creation. 40 | */ 41 | // Creating first file. 42 | int file_descriptor = file_manager.create(file_id); 43 | REQUIRE(file_descriptor > 0); 44 | 45 | // Creating second file. 46 | int file_descriptor_2 = file_manager.create("t00f501"); 47 | REQUIRE(file_descriptor_2 > 0); 48 | 49 | close(file_descriptor); 50 | close(file_descriptor_2); 51 | 52 | /* 53 | * Testing file open. 54 | */ 55 | // Openning file. 56 | file_descriptor = file_manager.open_file(file_id, 'a'); 57 | REQUIRE(file_descriptor > 0); 58 | 59 | // Writing to openned file. 60 | int write_result = write(file_descriptor, "Hi there!", 9); 61 | REQUIRE(write_result >= 0); 62 | close(file_descriptor); 63 | 64 | /* 65 | * Tesing file remove. 66 | */ 67 | // Removing a file. 68 | file_manager.remove(file_id); 69 | 70 | /* 71 | * Testing file copy. 72 | */ 73 | // Creating a test file to copy. 74 | std::ofstream file_stream; 75 | file_stream.open("/tmp/tocctests/tocc_test_file_to_copy"); 76 | file_stream << "some data..."; 77 | file_stream.close(); 78 | 79 | // Coping the file. 80 | file_manager.copy("/tmp/tocctests/tocc_test_file_to_copy", "ta59800"); 81 | } 82 | -------------------------------------------------------------------------------- /libtocc/tests/front_end/file_info_tests.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | 20 | #include 21 | #include 22 | #include "libtocc/front_end/file_info.h" 23 | 24 | 25 | TEST_CASE("File Info in Vector") 26 | { 27 | // Once upon a time, there was a Segfaul bug putting a FileInfo in a vector. 28 | 29 | std::vector v; 30 | 31 | { 32 | libtocc::FileInfo f(""); 33 | v.push_back(f); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /libtocc/tests/front_end/front_end_assign_tag_tests.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | 20 | #include 21 | 22 | #include "libtocc/front_end/manager.h" 23 | 24 | TEST_CASE("front_end: assign tag") 25 | { 26 | libtocc::Manager manager("/tmp/tocctests/"); 27 | 28 | manager.assign_tags("0000001", "author:Unknown"); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /libtocc/tests/front_end/front_end_assign_tag_wrong_tests.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | 20 | #include 21 | 22 | #include "libtocc/front_end/manager.h" 23 | #include "libtocc/common/database_exceptions.h" 24 | 25 | /* 26 | * Test cases for scenarios that must throw exception. 27 | */ 28 | TEST_CASE("front_end: assign tag wrong tests") 29 | { 30 | libtocc::Manager manager("/tmp/tocctests/"); 31 | 32 | REQUIRE_THROWS_AS(manager.assign_tags("f89ac3e", "author:Unknown"), 33 | libtocc::DatabaseScriptExecutionError); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /libtocc/tests/front_end/front_end_get_tests.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | #include "libtocc/front_end/manager.h" 26 | #include "libtocc/common/database_exceptions.h" 27 | 28 | 29 | TEST_CASE("front_end: get tests") 30 | { 31 | libtocc::Manager manager("/tmp/tocctests/"); 32 | 33 | SECTION("file not found error") 34 | { 35 | REQUIRE_THROWS_AS( 36 | manager.get_file_info("e31b6da"), 37 | libtocc::DatabaseScriptLogicalError); 38 | } 39 | } 40 | 41 | TEST_CASE("front_end: get_by_traditional_path tests") 42 | { 43 | libtocc::Manager manager("/tmp/tocctests/"); 44 | 45 | SECTION("existed file") 46 | { 47 | // Creating a file to import. 48 | std::ofstream file_stream; 49 | file_stream.open("/tmp/tocctests/axU87Ryds.txt"); 50 | file_stream << "some data..."; 51 | file_stream.close(); 52 | 53 | // Importing the file. 54 | libtocc::FileInfo test_file = 55 | manager.import_file("/tmp/tocctests/axU87Ryds.txt", 56 | "axU87Ryds.txt", 57 | "/old/path/of/test/file/axU87Ryds.txt"); 58 | 59 | libtocc::FileInfo got_test_file = 60 | manager.get_file_by_traditional_path("/old/path/of/test/file/axU87Ryds.txt"); 61 | 62 | REQUIRE(strcmp(got_test_file.get_id(), test_file.get_id()) == 0); 63 | REQUIRE(strcmp(got_test_file.get_title(), test_file.get_title()) == 0); 64 | REQUIRE(strcmp(got_test_file.get_traditional_path(), test_file.get_traditional_path()) == 0); 65 | } 66 | 67 | SECTION("not existed file") 68 | { 69 | REQUIRE_THROWS_AS( 70 | manager.get_file_by_traditional_path("/not/existed/traditional/path"), 71 | libtocc::DatabaseScriptLogicalError); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /libtocc/tests/front_end/front_end_initializer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include 20 | 21 | #include "libtocc/front_end/manager.h" 22 | 23 | 24 | // This should be run before all the other tests. Since it initialize an 25 | // environment for them. 26 | TEST_CASE("Front End Initializer") 27 | { 28 | libtocc::Manager manager("/tmp/tocctests/"); 29 | manager.initialize(); 30 | } 31 | -------------------------------------------------------------------------------- /libtocc/tests/front_end/front_end_set_file_title.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include "libtocc/front_end/manager.h" 24 | #include "libtocc/front_end/file_info.h" 25 | #include "libtocc/common/database_exceptions.h" 26 | 27 | 28 | 29 | TEST_CASE("front_end: set files title tests") 30 | { 31 | 32 | //Creating files 33 | 34 | std::ofstream file_stream1; 35 | file_stream1.open("/tmp/tocctests/tocc_test_random_file_1"); 36 | file_stream1 << "I'm file 1"; 37 | file_stream1.close(); 38 | 39 | // Creating a file to import. 40 | std::ofstream file_stream2; 41 | file_stream1.open("/tmp/tocctests/tocc_test_random_file_2"); 42 | file_stream1 << "I'm file 2"; 43 | file_stream1.close(); 44 | 45 | // Creating an instance of the manager. 46 | libtocc::Manager manager("/tmp/tocctests/"); 47 | 48 | // Creating 2 files with a title and a traditional path. 49 | libtocc::FileInfo new_file1 = manager.import_file("/tmp/tocctests/tocc_test_random_file_1"); 50 | libtocc::FileInfo new_file2 = manager.import_file("/tmp/tocctests/tocc_test_random_file_2"); 51 | 52 | //Setting the title of the first file 53 | manager.set_title(new_file1.get_id(), "new title 1"); 54 | 55 | //Test 56 | new_file1 = manager.get_file_info(new_file1.get_id()); 57 | REQUIRE(strcmp(new_file1.get_title(), "new title 1") == 0); 58 | 59 | //Setting the title of a the 2 files simultanously 60 | const char* file_ids[] = { new_file1.get_id(), new_file2.get_id() }; 61 | 62 | manager.set_titles(file_ids, 2, "new title 2"); 63 | 64 | //Test 65 | new_file1 = manager.get_file_info(new_file1.get_id()); 66 | new_file2 = manager.get_file_info(new_file2.get_id()); 67 | REQUIRE(strcmp(new_file1.get_title(), "new title 2") == 0); 68 | REQUIRE(strcmp(new_file2.get_title(), "new title 2") == 0); 69 | 70 | //Remove the first file 71 | manager.remove_file(new_file1); 72 | 73 | //Setting a title of a file that doesn't exist 74 | REQUIRE_THROWS_AS( 75 | manager.set_title(new_file1.get_id(), "new title 3"), 76 | libtocc::DatabaseScriptLogicalError); 77 | 78 | //Setting the title of a group of files where some files don't exist in the database 79 | const char* file_ids2[] = { new_file2.get_id(), new_file1.get_id(), "0000012" }; 80 | manager.set_titles(file_ids2, 3, "new title 3"); 81 | 82 | //Test 83 | new_file2 = manager.get_file_info(new_file2.get_id()); 84 | REQUIRE(strcmp(new_file2.get_title(), "new title 3") == 0); 85 | } 86 | -------------------------------------------------------------------------------- /libtocc/tests/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | /* 20 | * Defines main function, which starts all tests. 21 | */ 22 | 23 | // The following define causes the Catch to generate a main fucntion here. 24 | #define CATCH_CONFIG_MAIN 25 | #include "catch.hpp" 26 | 27 | #include 28 | 29 | /* 30 | ** Initialisation of Library 31 | */ 32 | class TestInitialiser 33 | { 34 | public: 35 | TestInitialiser() 36 | { 37 | // clean previous test files 38 | if (int status = system("rm -rf /tmp/tocctests")) 39 | { 40 | std::cout << "Test initialisation failed -\ 41 | Unable to delete files" << std::endl; 42 | exit(status); 43 | } 44 | else if (int status = system("mkdir /tmp/tocctests")) 45 | { 46 | std::cout << "Test initialisation failed -\ 47 | Unable to create base directory" << std::endl; 48 | exit(status); 49 | } 50 | }; 51 | }; 52 | 53 | TestInitialiser now; 54 | -------------------------------------------------------------------------------- /libtocc/tests/utilities/file_utils_tests.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include 20 | #include"libtocc/utilities/file_utils.h" 21 | 22 | TEST_CASE("utilities/file_utils: get file name from path") 23 | { 24 | REQUIRE( libtocc::get_filename_from_path("/home") == "home"); 25 | REQUIRE( libtocc::get_filename_from_path("/home/dummy.ext") == "dummy.ext"); 26 | REQUIRE( libtocc::get_filename_from_path("/home/dummy.dump.ext") == "dummy.dump.ext"); 27 | REQUIRE( libtocc::get_filename_from_path("/home.ext") == "home.ext"); 28 | REQUIRE( libtocc::get_filename_from_path("/home/.act.ext") == ".act.ext"); 29 | REQUIRE( libtocc::get_filename_from_path("/.home") == ".home"); 30 | } 31 | -------------------------------------------------------------------------------- /toccfs/docs/source/compile.rst: -------------------------------------------------------------------------------- 1 | 2 | .. toctree:: 3 | :hidden: 4 | 5 | 6 | Compiling Toccfs from Source 7 | ============================ 8 | 9 | Requirements 10 | ------------ 11 | *toccfs* wrote using FUSE (File System in User Environment) library. So, you 12 | need to have FUSE installed on your system. Usually, you can find a package 13 | like *libfuse-dev* among your distro's packages. If not, try get it from its 14 | web site: `fuse.sourceforge.net `_. 15 | 16 | You also need *libtocc* compiled and installed on you system. If you didn't 17 | do this already, see `How to Compile And Use libtocc `_. 18 | 19 | Bootstraping 20 | ------------ 21 | First step is to create a ``configure`` script. If you downloaded a released 22 | source package, this step already done. You can skip it. 23 | 24 | You need *Gnu Auto Tools*, e.g. *Libtool*, *Autoconf* and *Automake* installed. 25 | Then, simply invoke ``bootstrap`` script:: 26 | 27 | ./bootstrap 28 | 29 | Configuring 30 | ----------- 31 | Previous step created a ``configure`` script. Normally, you don't need to pass 32 | any options:: 33 | 34 | ./configure 35 | 36 | By default, *toccfs* binary (``toccfs``) will be installed in the default ``bin`` 37 | directory. Usually ``/usr/local/bin/``. If you want to install it into another 38 | directory, you can pass ``--prefix`` option to ``configure`` script:: 39 | 40 | ./configure --prefix=/opt/tocc/ 41 | 42 | Which installs binary in ``/opt/tocc/bin/``. 43 | 44 | Making 45 | ------ 46 | 47 | Now that you configured CLI, you can invoke ``make`` in order to compile the 48 | source:: 49 | 50 | make 51 | 52 | Installing 53 | ---------- 54 | 55 | If previous step goes without any error, simply invoke:: 56 | 57 | make install 58 | 59 | (Usually, you need super user access to invoke this command.) 60 | 61 | This will install ``toccfs`` binary in the directory you specified using 62 | ``--prefix`` (or the default directory). 63 | 64 | 65 | -------------------------------------------------------------------------------- /toccfs/src/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Makefile.am -- Process this file with automake to produce Makefile.in 2 | 3 | # Output and source files. 4 | bin_PROGRAMS = toccfs 5 | toccfs_SOURCES = utils/string_utils.cpp fuse/fuse_interface.cpp engine/fs_handler.cpp main.cpp 6 | toccfs_LDADD = @FUSE_LIBS@ 7 | toccfs_CXXFLAGS = @FUSE_CFLAGS@ 8 | 9 | -------------------------------------------------------------------------------- /toccfs/src/bootstrap: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | aclocal 6 | autoconf -Wall 7 | automake -Wall --add-missing 8 | -------------------------------------------------------------------------------- /toccfs/src/configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ([2.69]) 5 | AC_INIT([tocc-fs], [1.0.1], [tocc@aidinhut.com], [File System Interface for Tocc], [https://tocc.aidinhut.com]) 6 | AC_CONFIG_SRCDIR([main.cpp]) 7 | 8 | # Initializing Automake. 9 | # [foreign] added, so automake won't check for missing NEWS, README, etc. 10 | AM_INIT_AUTOMAKE([foreign]) 11 | 12 | # Checks for programs. 13 | AC_PROG_CXX 14 | AC_PROG_CC 15 | 16 | # Checks for typedefs, structures, and compiler characteristics. 17 | AC_CHECK_HEADER_STDBOOL 18 | AC_TYPE_OFF_T 19 | 20 | # Checks for library functions. 21 | AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK 22 | AC_CHECK_FUNCS([memset]) 23 | 24 | # Checks for UnQlite 25 | # Since it's a C header, we need to set lang to C 26 | AC_LANG_PUSH(C) 27 | AC_CHECK_HEADER([unqlite.h], [], [AC_MSG_ERROR([Could not find unqlite.h header. Please make sure you have this header in your include path. Refer to documents for more info.])]) 28 | AC_SEARCH_LIBS([unqlite_open], [unqlite], [], [AC_MSG_ERROR([Could not find unqlite library. Please make sure you have this library in your libs path. Refer to documentations for more info.])]) 29 | 30 | PKG_CHECK_MODULES([FUSE], [fuse >= 2.9.2]) 31 | 32 | # Checking for libtocc. 33 | # Setting lang to C++, because followings all are C++. 34 | AC_LANG_PUSH(C++) 35 | # The fourth argument is: don't try to compile this header. 36 | AC_CHECK_HEADER([libtocc/front_end/manager.h], [], [AC_MSG_ERROR([Could not find libtocc/front_end/manager.h header. Please make sure you have libtocc headers in your include path. Refer to documents for more info.])], [-]) 37 | # `libtocc_exists' function used to check for libtocc. See the documentation 38 | # about how to check for libtocc with Autoconf. 39 | AC_SEARCH_LIBS([libtocc_exists], [tocc], [], [AC_MSG_ERROR([Could not find libtocc library. Please make sure you have this library in your libs path. Refer to documentations for more info.])]) 40 | 41 | # Changing back the language to C 42 | AC_LANG_POP 43 | 44 | # Output files. 45 | AC_CONFIG_FILES([Makefile]) 46 | AC_OUTPUT 47 | 48 | -------------------------------------------------------------------------------- /toccfs/src/engine/fs_handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef TOCCFS_FS_HANDLER_H_INCLUDED 20 | #define TOCCFS_FS_HANDLER_H_INCLUDED 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | namespace toccfs 29 | { 30 | 31 | class FSHandler 32 | { 33 | public: 34 | FSHandler(std::string base_path); 35 | 36 | ~FSHandler(); 37 | 38 | /* 39 | * Returns the base path. 40 | */ 41 | std::string get_base_path(); 42 | 43 | /* 44 | * Gets a file by a path. 45 | * It assume the last element in the path is the file title, and 46 | * other elements are tags. 47 | */ 48 | libtocc::FileInfo get_by_path(std::string path); 49 | 50 | /* 51 | * Finds files using the specified path. 52 | * It converts the path to a Tocc query, and returns files founded 53 | * using that query. 54 | */ 55 | std::vector query_by_path(std::string path); 56 | 57 | /* 58 | * Returns tags that are associated with these files. 59 | */ 60 | std::vector get_related_tags(std::vector files); 61 | 62 | /* 63 | * Returns all of the tags. 64 | */ 65 | std::vector get_all_tags(); 66 | 67 | private: 68 | libtocc::Manager* libtocc_manager; 69 | 70 | std::string base_path; 71 | }; 72 | } 73 | 74 | #endif /* TOCCFS_FS_HANDLER_H_INCLUDED */ 75 | -------------------------------------------------------------------------------- /toccfs/src/fuse/fuse_interface.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef TOCCFS_FUSE_INTERFACE_H_INCLUDED 20 | #define TOCCFS_FUSE_INTERFACE_H_INCLUDED 21 | 22 | // Using latest FUSE API version. 23 | #define FUSE_USE_VERSION 26 24 | 25 | #include 26 | 27 | 28 | namespace toccfs 29 | { 30 | 31 | int toccfs_fuse_getattr(const char* path, struct stat* stbuf); 32 | 33 | int toccfs_fuse_readdir(const char* path, void* buffer, fuse_fill_dir_t filler, 34 | off_t offset, struct fuse_file_info* fileinfo); 35 | 36 | int toccfs_fuse_read(const char* path, char* buffer, size_t size, off_t offset, 37 | struct fuse_file_info* file_info); 38 | 39 | int toccfs_fuse_access(const char* path, int mask); 40 | 41 | int toccfs_fuse_statfs(const char* path, struct statvfs* stbuf); 42 | 43 | int toccfs_fuse_mkdir(const char* path, mode_t mode); 44 | 45 | int toccfs_fuse_rmdir(const char* path); 46 | 47 | int toccfs_fuse_unlink(const char* path); 48 | 49 | int toccfs_fuse_mknod(const char* path, mode_t mode, dev_t rdev); 50 | 51 | int toccfs_fuse_symlink(const char* from, const char* to); 52 | 53 | int toccfs_fuse_rename(const char* from, const char* to); 54 | 55 | int toccfs_fuse_link(const char* from, const char* to); 56 | 57 | int toccfs_fuse_chmod(const char* path, mode_t mode); 58 | 59 | int toccfs_fuse_chown(const char* path, uid_t uid, gid_t gid); 60 | 61 | int toccfs_fuse_truncate(const char* path, off_t size); 62 | 63 | int toccfs_fuse_write(const char* path, const char* buf, size_t size, 64 | off_t offset, struct fuse_file_info* fi); 65 | 66 | } 67 | 68 | #endif /* TOCCFS_FUSE_INTERFACE_H_INCLUDED */ 69 | -------------------------------------------------------------------------------- /toccfs/src/utils/string_utils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #include "utils/string_utils.h" 20 | 21 | #include 22 | 23 | 24 | namespace toccfs 25 | { 26 | 27 | std::vector split_string(const std::string& string_to_split, 28 | char delimiter) 29 | { 30 | std::vector result; 31 | 32 | std::stringstream stream(string_to_split); 33 | std::string item; 34 | while (std::getline(stream, item, delimiter)) 35 | { 36 | if (!item.empty()) 37 | { 38 | result.push_back(item); 39 | } 40 | } 41 | 42 | return result; 43 | } 44 | 45 | bool string_ends_with(const std::string& str, 46 | const std::string& str_to_check) 47 | { 48 | if (str.size() >= str_to_check.size()) 49 | { 50 | return false; 51 | } 52 | 53 | return str.compare(str.size() - str_to_check.size(), 54 | str_to_check.size(), str_to_check) == 0; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /toccfs/src/utils/string_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Tocc. (see ) 3 | * Copyright (C) 2013, 2014, Aidin Gharibnavaz 4 | * 5 | * Tocc is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * Tocc is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with Tocc. If not, see . 17 | */ 18 | 19 | #ifndef TOCCFS_STRING_UTILS_H_INCLUDED 20 | #define TOCCFS_STRING_UTILS_H_INCLUDED 21 | 22 | #include 23 | #include 24 | 25 | 26 | namespace toccfs 27 | { 28 | 29 | /* 30 | * Splits a string, by the specified delimiter. 31 | */ 32 | std::vector split_string(const std::string& string_to_split, 33 | char delimiter); 34 | 35 | /* 36 | * Checks if the specified string is ends with the other one. 37 | * (i.e. `str_to_check' is at the end of `str'. 38 | */ 39 | bool string_ends_with(const std::string& str, 40 | const std::string& str_to_check); 41 | } 42 | 43 | #endif /* TOCCFS_STRING_UTILS_H_INCLUDED */ 44 | --------------------------------------------------------------------------------