From 00c5e61d49b3390632a93051b4cc43f208e41cbc Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Mon, 15 Jun 2009 17:31:29 -0400 Subject: [PATCH] Bug Fix - rc:alternate - Fixed handling of rc: alternate rc file. - Reorganized Config.cpp regarding defaults. More work needed. --- src/Config.cpp | 155 +++++++++++++++++++++++++++++------------------- src/Config.h | 1 + src/Context.cpp | 23 ++++--- src/TDB.cpp | 17 ++++-- src/Task.cpp | 18 +++--- src/import.cpp | 49 ++++++--------- 6 files changed, 147 insertions(+), 116 deletions(-) diff --git a/src/Config.cpp b/src/Config.cpp index 822f40972..fb38d42ef 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -45,59 +45,7 @@ // upgrade program to make the change, or c) this. Config::Config () { - set ("report.long.description", "Lists all task, all data, matching the specified criteria"); // TODO i18n - set ("report.long.columns", "id,project,priority,entry,start,due,recur,age,tags,description"); // TODO i18n - set ("report.long.labels", "ID,Project,Pri,Added,Started,Due,Recur,Age,Tags,Description"); // TODO i18n - set ("report.long.sort", "due+,priority-,project+"); // TODO i18n - set ("report.long.filter", "status:pending"); // TODO i18n - - set ("report.list.description", "Lists all tasks matching the specified criteria"); // TODO i18n - set ("report.list.columns", "id,project,priority,due,active,age,description"); // TODO i18n - set ("report.list.labels", "ID,Project,Pri,Due,Active,Age,Description"); // TODO i18n - set ("report.list.sort", "due+,priority-,project+"); // TODO i18n - set ("report.list.filter", "status:pending"); // TODO i18n - - set ("report.ls.description", "Minimal listing of all tasks matching the specified criteria"); // TODO i18n - set ("report.ls.columns", "id,project,priority,description"); // TODO i18n - set ("report.ls.labels", "ID,Project,Pri,Description"); // TODO i18n - set ("report.ls.sort", "priority-,project+"); // TODO i18n - set ("report.ls.filter", "status:pending"); // TODO i18n - - set ("report.newest.description", "Shows the newest tasks"); // TODO i18n - set ("report.newest.columns", "id,project,priority,due,active,age,description"); // TODO i18n - set ("report.newest.labels", "ID,Project,Pri,Due,Active,Age,Description"); // TODO i18n - set ("report.newest.sort", "id-"); // TODO i18n - set ("report.newest.filter", "status:pending limit:10"); // TODO i18n - - set ("report.oldest.description", "Shows the oldest tasks"); // TODO i18n - set ("report.oldest.columns", "id,project,priority,due,active,age,description"); // TODO i18n - set ("report.oldest.labels", "ID,Project,Pri,Due,Active,Age,Description"); // TODO i18n - set ("report.oldest.sort", "id+"); // TODO i18n - set ("report.oldest.filter", "status:pending limit:10"); // TODO i18n - - set ("report.overdue.description", "Lists overdue tasks matching the specified criteria"); // TODO i18n - set ("report.overdue.columns", "id,project,priority,due,active,age,description"); // TODO i18n - set ("report.overdue.labels", "ID,Project,Pri,Due,Active,Age,Description"); // TODO i18n - set ("report.overdue.sort", "due+,priority-,project+"); // TODO i18n - set ("report.overdue.filter", "status:pending due.before:today"); // TODO i18n - - set ("report.active.description", "Lists active tasks matching the specified criteria"); // TODO i18n - set ("report.active.columns", "id,project,priority,due,active,age,description"); // TODO i18n - set ("report.active.labels", "ID,Project,Pri,Due,Active,Age,Description"); // TODO i18n - set ("report.active.sort", "due+,priority-,project+"); // TODO i18n - set ("report.active.filter", "status:pending start.any:"); // TODO i18n - - set ("report.completed.description", "Lists completed tasks matching the specified criteria"); // TODO i18n - set ("report.completed.columns", "end,project,priority,age,description"); // TODO i18n - set ("report.completed.labels", "Complete,Project,Pri,Age,Description"); // TODO i18n - set ("report.completed.sort", "end+,priority-,project+"); // TODO i18n - set ("report.completed.filter", "status:completed"); // TODO i18n - - set ("report.recurring.description", "Lists recurring tasks matching the specified criteria"); // TODO i18n - set ("report.recurring.columns", "id,project,priority,due,recur,active,age,description"); // TODO i18n - set ("report.recurring.labels", "ID,Project,Pri,Due,Recur,Active,Age,Description"); // TODO i18n - set ("report.recurring.sort", "due+,priority-,project+"); // TODO i18n - set ("report.recurring.filter", "status:pending parent.any:"); // TODO i18n + setDefaults (); } //////////////////////////////////////////////////////////////////////////////// @@ -215,31 +163,58 @@ void Config::createDefault (const std::string& home) fprintf (out, "# Limit: 10\n"); // TODO i18n fprintf (out, "report.long.description=Lists all task, all data, matching the specified criteria\n"); // TODO i18n - fprintf (out, "report.long.labels=ID,Project,Pri,Added,Started,Due,Recur,Age,Tags,Description\n"); // TODO i18n fprintf (out, "report.long.columns=id,project,priority,entry,start,due,recur,age,tags,description\n"); // TODO i18n + fprintf (out, "report.long.labels=ID,Project,Pri,Added,Started,Due,Recur,Age,Tags,Description\n"); // TODO i18n fprintf (out, "report.long.sort=due+,priority-,project+\n"); // TODO i18n + fprintf (out, "report.long.filter=status:pending\n"); // TODO i18n fprintf (out, "report.list.description=Lists all tasks matching the specified criteria\n"); // TODO i18n - fprintf (out, "report.list.labels=ID,Project,Pri,Due,Active,Age,Description\n"); // TODO i18n fprintf (out, "report.list.columns=id,project,priority,due,active,age,description\n"); // TODO i18n + fprintf (out, "report.list.labels=ID,Project,Pri,Due,Active,Age,Description\n"); // TODO i18n fprintf (out, "report.list.sort=due+,priority-,project+\n"); // TODO i18n - // TODO i18n + fprintf (out, "report.list.filter=status:pending\n"); // TODO i18n + fprintf (out, "report.ls.description=Minimal listing of all tasks matching the specified criteria\n"); // TODO i18n - fprintf (out, "report.ls.labels=ID,Project,Pri,Description\n"); // TODO i18n fprintf (out, "report.ls.columns=id,project,priority,description\n"); // TODO i18n + fprintf (out, "report.ls.labels=ID,Project,Pri,Description\n"); // TODO i18n fprintf (out, "report.ls.sort=priority-,project+\n"); // TODO i18n + fprintf (out, "report.ls.filter=status:pending\n"); // TODO i18n fprintf (out, "report.newest.description=Shows the newest tasks\n"); // TODO i18n - fprintf (out, "report.newest.labels=ID,Project,Pri,Due,Active,Age,Description\n"); // TODO i18n fprintf (out, "report.newest.columns=id,project,priority,due,active,age,description\n"); // TODO i18n + fprintf (out, "report.newest.labels=ID,Project,Pri,Due,Active,Age,Description\n"); // TODO i18n fprintf (out, "report.newest.sort=id-\n"); // TODO i18n - fprintf (out, "report.newest.limit=10\n"); // TODO i18n + fprintf (out, "report.newest.filter=status:pending limit:10\n"); // TODO i18n fprintf (out, "report.oldest.description=Shows the oldest tasks\n"); // TODO i18n - fprintf (out, "report.oldest.labels=ID,Project,Pri,Due,Active,Age,Description\n"); // TODO i18n fprintf (out, "report.oldest.columns=id,project,priority,due,active,age,description\n"); // TODO i18n + fprintf (out, "report.oldest.labels=ID,Project,Pri,Due,Active,Age,Description\n"); // TODO i18n fprintf (out, "report.oldest.sort=id+\n"); // TODO i18n - fprintf (out, "report.oldest.limit=10\n"); // TODO i18n + fprintf (out, "report.oldest.filter=status:pending limit:10\n"); // TODO i18n + + fprintf (out, "report.overdue.description=Lists overdue tasks matching the specified criteria\n"); // TODO i18n + fprintf (out, "report.overdue.columns=id,project,priority,due,active,age,description\n"); // TODO i18n + fprintf (out, "report.overdue.labels=ID,Project,Pri,Due,Active,Age,Description\n"); // TODO i18n + fprintf (out, "report.overdue.sort=due+,priority-,project+\n"); // TODO i18n + fprintf (out, "report.overdue.filter=status:pending due.before:today\n"); // TODO i18n + + fprintf (out, "report.active.description=Lists active tasks matching the specified criteria\n"); // TODO i18n + fprintf (out, "report.active.columns=id,project,priority,due,active,age,description\n"); // TODO i18n + fprintf (out, "report.active.labels=ID,Project,Pri,Due,Active,Age,Description\n"); // TODO i18n + fprintf (out, "report.active.sort=due+,priority-,project+\n"); // TODO i18n + fprintf (out, "report.active.filter=status:pending start.any:\n"); // TODO i18n + + fprintf (out, "report.completed.description=Lists completed tasks matching the specified criteria\n"); // TODO i18n + fprintf (out, "report.completed.columns=end,project,priority,age,description\n"); // TODO i18n + fprintf (out, "report.completed.labels=Complete,Project,Pri,Age,Description\n"); // TODO i18n + fprintf (out, "report.completed.sort=end+,priority-,project+\n"); // TODO i18n + fprintf (out, "report.completed.filter=status:completed\n"); // TODO i18n + + fprintf (out, "report.recurring.description=Lists recurring tasks matching the specified criteria\n"); // TODO i18n + fprintf (out, "report.recurring.columns=id,project,priority,due,recur,active,age,description\n"); // TODO i18n + fprintf (out, "report.recurring.labels=ID,Project,Pri,Due,Recur,Active,Age,Description\n"); // TODO i18n + fprintf (out, "report.recurring.sort=due+,priority-,project+\n"); // TODO i18n + fprintf (out, "report.recurring.filter=status:pending parent.any:\n"); // TODO i18n fclose (out); @@ -257,6 +232,64 @@ void Config::createDefault (const std::string& home) mkdir (dataDir.c_str (), S_IRWXU); } +//////////////////////////////////////////////////////////////////////////////// +void Config::setDefaults () +{ + set ("report.long.description", "Lists all task, all data, matching the specified criteria"); // TODO i18n + set ("report.long.columns", "id,project,priority,entry,start,due,recur,age,tags,description"); // TODO i18n + set ("report.long.labels", "ID,Project,Pri,Added,Started,Due,Recur,Age,Tags,Description"); // TODO i18n + set ("report.long.sort", "due+,priority-,project+"); // TODO i18n + set ("report.long.filter", "status:pending"); // TODO i18n + + set ("report.list.description", "Lists all tasks matching the specified criteria"); // TODO i18n + set ("report.list.columns", "id,project,priority,due,active,age,description"); // TODO i18n + set ("report.list.labels", "ID,Project,Pri,Due,Active,Age,Description"); // TODO i18n + set ("report.list.sort", "due+,priority-,project+"); // TODO i18n + set ("report.list.filter", "status:pending"); // TODO i18n + + set ("report.ls.description", "Minimal listing of all tasks matching the specified criteria"); // TODO i18n + set ("report.ls.columns", "id,project,priority,description"); // TODO i18n + set ("report.ls.labels", "ID,Project,Pri,Description"); // TODO i18n + set ("report.ls.sort", "priority-,project+"); // TODO i18n + set ("report.ls.filter", "status:pending"); // TODO i18n + + set ("report.newest.description", "Shows the newest tasks"); // TODO i18n + set ("report.newest.columns", "id,project,priority,due,active,age,description"); // TODO i18n + set ("report.newest.labels", "ID,Project,Pri,Due,Active,Age,Description"); // TODO i18n + set ("report.newest.sort", "id-"); // TODO i18n + set ("report.newest.filter", "status:pending limit:10"); // TODO i18n + + set ("report.oldest.description", "Shows the oldest tasks"); // TODO i18n + set ("report.oldest.columns", "id,project,priority,due,active,age,description"); // TODO i18n + set ("report.oldest.labels", "ID,Project,Pri,Due,Active,Age,Description"); // TODO i18n + set ("report.oldest.sort", "id+"); // TODO i18n + set ("report.oldest.filter", "status:pending limit:10"); // TODO i18n + + set ("report.overdue.description", "Lists overdue tasks matching the specified criteria"); // TODO i18n + set ("report.overdue.columns", "id,project,priority,due,active,age,description"); // TODO i18n + set ("report.overdue.labels", "ID,Project,Pri,Due,Active,Age,Description"); // TODO i18n + set ("report.overdue.sort", "due+,priority-,project+"); // TODO i18n + set ("report.overdue.filter", "status:pending due.before:today"); // TODO i18n + + set ("report.active.description", "Lists active tasks matching the specified criteria"); // TODO i18n + set ("report.active.columns", "id,project,priority,due,active,age,description"); // TODO i18n + set ("report.active.labels", "ID,Project,Pri,Due,Active,Age,Description"); // TODO i18n + set ("report.active.sort", "due+,priority-,project+"); // TODO i18n + set ("report.active.filter", "status:pending start.any:"); // TODO i18n + + set ("report.completed.description", "Lists completed tasks matching the specified criteria"); // TODO i18n + set ("report.completed.columns", "end,project,priority,age,description"); // TODO i18n + set ("report.completed.labels", "Complete,Project,Pri,Age,Description"); // TODO i18n + set ("report.completed.sort", "end+,priority-,project+"); // TODO i18n + set ("report.completed.filter", "status:completed"); // TODO i18n + + set ("report.recurring.description", "Lists recurring tasks matching the specified criteria"); // TODO i18n + set ("report.recurring.columns", "id,project,priority,due,recur,active,age,description"); // TODO i18n + set ("report.recurring.labels", "ID,Project,Pri,Due,Recur,Active,Age,Description"); // TODO i18n + set ("report.recurring.sort", "due+,priority-,project+"); // TODO i18n + set ("report.recurring.filter", "status:pending parent.any:"); // TODO i18n +} + //////////////////////////////////////////////////////////////////////////////// // Return the configuration value given the specified key. const std::string Config::get (const char* key) diff --git a/src/Config.h b/src/Config.h index a50d16150..6b7983df3 100644 --- a/src/Config.h +++ b/src/Config.h @@ -39,6 +39,7 @@ public: bool load (const std::string&); void createDefault (const std::string&); + void setDefaults (); const std::string get (const char*); const std::string get (const char*, const char*); diff --git a/src/Context.cpp b/src/Context.cpp index 4abdb60e6..a653d5a66 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -272,6 +272,8 @@ void Context::shadow () //////////////////////////////////////////////////////////////////////////////// void Context::loadCorrectConfigFile () { + bool needNewConfig = true; + foreach (arg, args) { if (arg->substr (0, 3) == "rc:") @@ -281,21 +283,26 @@ void Context::loadCorrectConfigFile () throw std::string ("Could not read configuration file '") + file + "'"; message (std::string ("Using alternate .taskrc file ") + file); // TODO i18n - config.load (file); + config.clear (); // Dump current values. + config.setDefaults (); // Add in the custom reports. + config.load (file); // Load new file. + needNewConfig = false; // No need to handle it again. args.erase (arg); } } - struct passwd* pw = getpwuid (getuid ()); - if (!pw) - throw std::string ( - stringtable.get (SHELL_READ_PASSWD, - "Could not read home directory from the passwd file.")); + if (needNewConfig) + { + struct passwd* pw = getpwuid (getuid ()); + if (!pw) + throw std::string ( + stringtable.get (SHELL_READ_PASSWD, + "Could not read home directory from the passwd file.")); - std::string file = pw->pw_dir; - config.createDefault (file); + config.createDefault (pw->pw_dir); + } // Apply overrides of type: "rc.name:value" foreach (arg, args) diff --git a/src/TDB.cpp b/src/TDB.cpp index 41e75b340..fe40816ad 100644 --- a/src/TDB.cpp +++ b/src/TDB.cpp @@ -197,7 +197,7 @@ int TDB::loadPending (std::vector & tasks, Filter& filter) catch (std::string& e) { std::stringstream s; - s << " int " << file << " at line " << line_number; + s << " in " << file << " at line " << line_number; throw e + s.str (); } @@ -228,10 +228,13 @@ int TDB::loadCompleted (std::vector & tasks, Filter& filter) while (fgets (line, T_LINE_MAX, location->completed)) { int length = ::strlen (line); - if (length > 1) + if (length > 2) { // TODO Add hidden attribute indicating source? - line[length - 1] = '\0'; // Kill \n + + if (line[length - 1] == '\n') + line[length - 1] = '\0'; + Task task (line); task.id = mId++; @@ -247,7 +250,7 @@ int TDB::loadCompleted (std::vector & tasks, Filter& filter) catch (std::string& e) { std::stringstream s; - s << " int " << file << " at line " << line_number; + s << " in " << file << " at line " << line_number; throw e + s.str (); } @@ -352,8 +355,10 @@ int TDB::gc () // completed list. Isn't garbage collection easy? foreach (task, pending) { - if (task->getStatus () == Task::completed || - task->getStatus () == Task::deleted) + std::string st = task->get ("status"); + Task::status s = task->getStatus (); + if (s == Task::completed || + s == Task::deleted) { completed.push_back (*task); pending.erase (task); diff --git a/src/Task.cpp b/src/Task.cpp index da2493296..d39cd5caf 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -89,21 +89,21 @@ Task::~Task () //////////////////////////////////////////////////////////////////////////////// Task::status Task::textToStatus (const std::string& input) { - if (input == "pending") return pending; - else if (input == "completed") return completed; - else if (input == "deleted") return deleted; - else if (input == "recurring") return recurring; + if (input == "pending") return Task::pending; + else if (input == "completed") return Task::completed; + else if (input == "deleted") return Task::deleted; + else if (input == "recurring") return Task::recurring; - return pending; + return Task::pending; } //////////////////////////////////////////////////////////////////////////////// std::string Task::statusToText (Task::status s) { - if (s == pending) return "pending"; - else if (s == completed) return "completed"; - else if (s == deleted) return "deleted"; - else if (s == recurring) return "recurring"; + if (s == Task::pending) return "pending"; + else if (s == Task::completed) return "completed"; + else if (s == Task::deleted) return "deleted"; + else if (s == Task::recurring) return "recurring"; return "pending"; } diff --git a/src/import.cpp b/src/import.cpp index 3a52cf409..77681e1b8 100644 --- a/src/import.cpp +++ b/src/import.cpp @@ -179,9 +179,7 @@ static void decorateTask (Task& task) } //////////////////////////////////////////////////////////////////////////////// -static std::string importTask_1_4_3 ( -// TDB& tdb, - const std::vector & lines) +static std::string importTask_1_4_3 (const std::vector & lines) { /* std::vector failed; @@ -337,9 +335,7 @@ static std::string importTask_1_4_3 ( } //////////////////////////////////////////////////////////////////////////////// -static std::string importTask_1_5_0 ( -// TDB& tdb, - const std::vector & lines) +static std::string importTask_1_5_0 (const std::vector & lines) { /* std::vector failed; @@ -501,9 +497,7 @@ static std::string importTask_1_5_0 ( } //////////////////////////////////////////////////////////////////////////////// -static std::string importTask_1_6_0 ( -// TDB& tdb, - const std::vector & lines) +static std::string importTask_1_6_0 (const std::vector & lines) { /* std::vector failed; @@ -664,9 +658,7 @@ static std::string importTask_1_6_0 ( } //////////////////////////////////////////////////////////////////////////////// -static std::string importTaskCmdLine ( -// TDB& tdb, - const std::vector & lines) +static std::string importTaskCmdLine (const std::vector & lines) { /* std::vector failed; @@ -715,9 +707,7 @@ static std::string importTaskCmdLine ( } //////////////////////////////////////////////////////////////////////////////// -static std::string importTodoSh_2_0 ( -// TDB& tdb, - const std::vector & lines) +static std::string importTodoSh_2_0 (const std::vector & lines) { /* std::vector failed; @@ -839,9 +829,7 @@ static std::string importTodoSh_2_0 ( } //////////////////////////////////////////////////////////////////////////////// -static std::string importText ( -// TDB& tdb, - const std::vector & lines) +static std::string importText (const std::vector & lines) { /* std::vector failed; @@ -904,9 +892,7 @@ static std::string importText ( } //////////////////////////////////////////////////////////////////////////////// -static std::string importCSV ( -// TDB& tdb, - const std::vector & lines) +static std::string importCSV (const std::vector & lines) { /* std::vector failed; @@ -1153,9 +1139,9 @@ static std::string importCSV ( std::string handleImport () { std::stringstream out; -#if 0 + // Use the description as a file name. - std::string file = trim (task.getDescription ()); + std::string file = trim (context.task.get ("description")); if (file.length () > 0) { // Load the file. @@ -1205,21 +1191,20 @@ std::string handleImport () // Determine which type it might be, then attempt an import. switch (type) { - case task_1_4_3: out << importTask_1_4_3 (tdb, lines); break; - case task_1_5_0: out << importTask_1_5_0 (tdb, lines); break; - case task_1_6_0: out << importTask_1_6_0 (tdb, lines); break; - case task_cmd_line: out << importTaskCmdLine (tdb, lines); break; - case todo_sh_2_0: out << importTodoSh_2_0 (tdb, lines); break; - case csv: out << importCSV (tdb, lines); break; - case text: out << importText (tdb, lines); break; + case task_1_4_3: out << importTask_1_4_3 (lines); break; + case task_1_5_0: out << importTask_1_5_0 (lines); break; + case task_1_6_0: out << importTask_1_6_0 (lines); break; + case task_cmd_line: out << importTaskCmdLine (lines); break; + case todo_sh_2_0: out << importTodoSh_2_0 (lines); break; + case csv: out << importCSV (lines); break; + case text: out << importText (lines); break; case not_a_clue: /* to stop the compiler from complaining. */ break; } } else throw std::string ("You must specify a file to import."); -#endif + return out.str (); } //////////////////////////////////////////////////////////////////////////////// -