Ticket #103: devtodo-path-recursive.patch

File devtodo-path-recursive.patch, 5.2 KB (added by anonymous, 13 months ago)

Patch implementing path recursivity on .todo location

  • doc/todorc.example

    a b  
    2121# Be generally paranoid about file ownerships and permissions 
    2222#paranoid 
    2323 
     24# Enable path recursivity 
     25path-recursive 
     26 
    2427# The database to use if --global or -G is specified 
    2528global-database $HOME/.todo_global 
    2629 
  • src/main.cc

    diff --git a/src/main.cc b/src/main.cc
    index f3cbafd..8892e1e 100644
    a b  
    22#include "support.h" 
    33#include "config.h" 
    44#include "todorl.h" 
     5#include "stdio.h" 
     6#include "unistd.h" 
    57 
    68void joinArgs(TodoDB &todo, vector<string> const &args, int argc, char const **argv) { 
    79char const *av[args.size() + argc]; 
     
    4042                                if (options.verbose > 1) 
    4143                                        cout << "todo: switched to global database '" << database << "'" << endl; 
    4244                        } 
    43                         if (options.verbose > 1) 
    44                                 cout << "todo: attempting load of '" << database << "'" << endl; 
    45                         todo.load(database); 
     45            // Switch to recursive database 
     46            else if (options.pathrecursive) { 
     47                // Grab current location 
     48                char cur_path[FILENAME_MAX]; 
     49                getcwd(cur_path, sizeof(cur_path)); 
     50 
     51                string local_path = cur_path; 
     52 
     53                // Flag for match in todo file 
     54                int invalid_todo = 1; 
     55                while (invalid_todo) { 
     56                    database = local_path + "/" + options.database; 
     57                    // Check if .todo exists in the local folder 
     58                    FILE* fp = fopen(database.c_str(), "r"); 
     59                    if (fp) { 
     60                        invalid_todo = 0; 
     61                    } else { 
     62                        if (options.verbose > 1) 
     63                            cout << "todo: no database found in path " << database << " , continuing" << endl; 
     64                        // file doesn't exist or is unreadable 
     65                        // remove the last folder and keep searching 
     66                        size_t match; 
     67                        match = local_path.rfind('/'); 
     68 
     69                        if (local_path.length()) { 
     70                            local_path.erase(match); 
     71                        } else { 
     72                            // Abort the while cycle if we have no match 
     73                            // or reached the root the second time 
     74                            break; 
     75                        } 
     76                    } 
     77                } 
     78            } 
     79 
     80            if (options.verbose > 1) 
     81                cout << "todo: attempting load of '" << database << "'" << endl; 
     82            todo.load(database); 
     83 
    4684                } catch (TodoDB::quit &e) { 
    4785                        // Quit is thrown if the .todo file can't be accessed 
    4886                        if (options.verbose > 1) 
  • src/support.cc

    diff --git a/src/support.cc b/src/support.cc
    index c7b4037..62be4ee 100644
    a b  
    1919 
    2020Options::Options() : 
    2121        verbose(0), purgeage(0), mono(false), paranoid(false), global(false), 
    22         summary(false), timeout(false), comment(false), 
     22        pathrecursive(false), summary(false), timeout(false), comment(false), 
    2323        database(".todo"), 
    2424        priority(Todo::None), 
    2525        mode(TodoDB::View), 
     
    224224        args.setHelp('D', "Mark the specified notes (and all children) as not done."); 
    225225        args.addArgument(GlobalDatabase, "global-database", CommandArgs::Required); 
    226226        args.setHelp(GlobalDatabase, "Specify the database to use if the -G (--global) parameter is used."); 
     227        args.addArgument('P', "path-recursive"); 
     228        args.setHelp('P', "Navigate the recursively the parent folders searching for a todo database."); 
    227229        args.addArgument('G', "global"); 
    228230        args.setHelp('G', "Use the database specified by the --global-database option. Defaults to ~/.todo_global."); 
    229231        args.addArgument(Database, "database", CommandArgs::Required); 
     
    352354                        case 's' : 
    353355                                options.summary = !options.summary; 
    354356                        break; 
     357                        case 'P' : 
     358                                options.pathrecursive = true; 
     359                        break; 
    355360                        case 'G' : 
    356361                                options.global = true; 
    357362                        break; 
     
    769774static bool rcvalid(string const &str) { 
    770775        return str == "verbose" || str == "filter" || str == "priority" || 
    771776                str == "TODO" || str == "colour" || str == "mono" || 
    772                 str == "global-database" || str == "global" || 
     777                str == "global-database" || str == "global" || str == "path-recursive" || 
    773778                str == "database" || str == "date-format" ||  
    774779                str == "sort" || str == "display-format" ||  
    775780                str == "generated-format" || str == "verbose-display-format" ||  
  • src/support.h

    diff --git a/src/support.h b/src/support.h
    index adadbda..bab6118 100644
    a b  
    1616        enum Dir { Negative = -1, Equal = 0, Positive = +1 }; 
    1717 
    1818        int verbose, purgeage; 
    19         bool mono, paranoid, global, summary, timeout, comment; 
     19        bool mono, paranoid, global, pathrecursive, summary, timeout, comment; 
    2020        string text, database, globaldatabase, filename, 
    2121                dateformat; 
    2222        map<string, string> format; 
  • src/todoterm.cc

    diff --git a/src/todoterm.cc b/src/todoterm.cc
    index a979d1b..40aa030 100644
    a b  
    22#include "todoterm.h" 
    33 
    44#ifdef USETERMCAP 
     5#include <cstdlib> 
    56#include <iostream> 
    67#include <string> 
    78#include <stdexcept>