Project Documentation: TODO CLI Application
1. Introduction
The TODO CLI Application is a command-line interface (CLI) task management tool
developed in the C programming language. It allows users to manage daily tasks through a
terminal-based interface, supporting features such as adding tasks with priorities, listing
tasks, deleting tasks, marking tasks as complete, and generating reports.
The system utilizes file handling to persist data between sessions, storing incomplete tasks
in [Link] and completed tasks in [Link]. It emphasizes data structures (Structs,
Dynamic Memory Allocation) and file I/O operations.
2. Objectives
The primary objectives of this project are:
1. Task Management: To provide a simple interface for adding, listing, and deleting
tasks.
2. Priority Sorting: To organize tasks based on priority levels (ascending order).
3. Data Persistence: To save task data to text files so information is not lost when the
program exits.
4. Completion Tracking: To move completed tasks from the active list to a completed
list with completion dates.
5. Reporting: To provide statistics on pending and completed tasks.
3. System Requirements
3.1 Hardware Requirements
• Processor: Intel Core i3 or equivalent
• RAM: 256 MB or higher
• Storage: Minimal (Text files for task storage)
3.2 Software Requirements
• Operating System: Windows, Linux, or macOS
• Compiler: C Compiler (GCC, Clang, Turbo C, etc.)
• Language: C Programming Language (Standard C99 or later)
4. System Architecture
4.1 Data Structures
The system uses Structs to encapsulate data and Dynamic Memory Allocation for flexible
storage.
1. struct date: Stores the day, month, and year.
• Used for tracking when a task was completed.
2. struct task: Represents a single task item.
• priority: Integer value indicating task importance.
• text: Character array containing the task description.
3. struct completed_task: Extends the Task structure.
• Includes the Task data plus a Date of completion.
4. Task**: A pointer to an array of Task pointers, used to manage the list of tasks in
memory.
4.2 File Structure
The system relies on two text files for data persistence:
1. [Link]: Stores all incomplete (pending) tasks.
• Format: [ ] Task Text | Priority
2. [Link]: Stores all completed tasks.
• Format: [X] Task Text | Priority (Implicitly stored
via CompletedTask structure logic).
4.3 Modules
The application is divided into the following functional modules:
• Date Module: Handles date initialization and formatting.
• Task Module: Handles task creation, reading, writing, and sorting.
• Command Module: Parses user input and routes to specific functions
(add, ls, del, done, report).
• I/O Module: Handles file reading and writing operations.
5. Module Description
5.1 initialize_date() & get_current_local_date()
• Purpose: Manages date objects.
• Process: Allocates memory for a Date struct and populates it with current system
time or user-provided values.
5.2 initialize_task()
• Purpose: Creates a new task object.
• Input: Task text string and priority integer.
• Output: A pointer to a newly allocated Task struct.
5.3 read_all_tasks_from_file() & write_tasks_to_file()
• Purpose: Handles data persistence.
• Process:
• read: Opens [Link], parses lines into Task structs, and returns an array of
pointers.
• write: Iterates through the task array and writes formatted strings to the
file.
5.4 task_ls()
• Purpose: Lists all pending tasks.
• Process: Reads [Link], sorts tasks by priority using qsort(), and displays them with
indices.
5.5 task_add()
• Purpose: Adds a new task to the list.
• Input: Priority and Task Description (parsed from command line arguments).
• Process: Creates a new task and appends it to [Link].
5.6 task_del()
• Purpose: Removes a task by index.
• Process: Reads tasks, removes the item at the specified index, shifts remaining
items, and rewrites the file.
• Status: Implementation pending in current codebase.
5.7 task_done()
• Purpose: Marks a task as complete.
• Process: Reads task, moves it to [Link] with a completion date, and removes it
from [Link].
• Status: Implementation pending in current codebase.
5.8 task_report()
• Purpose: Displays statistics.
• Process: Counts tasks in [Link] (Pending) and [Link] (Completed) and displays
summaries.
5.9 task_menu()
• Purpose: Main command parser.
• Process: Analyzes argc and argv to determine which command
(add, ls, del, done, report, help) was executed and calls the corresponding function.
6. User Guide
6.1 Compilation
1. Save the code as task.c.
2. Compile using: gcc task.c -o task
3. Run using: ./task
6.2 Commands
Command Syntax Description
Help ./task help Displays usage instructions.
Add ./task add 2 "Walk the dog" Adds a task with priority 2.
List ./task ls Shows all incomplete tasks sorted by priority.
Delete ./task del 1 Deletes the task at index 1.
Done ./task done 1 Marks task at index 1 as complete.
Report ./task report Shows statistics of pending and completed tasks.
6.3 Example Workflow
1. Add a task:
bash
Copy code
$ ./task add 1 Buy groceries
2. List tasks:
bash
Copy code
$ ./task ls
1. [ ] Buy groceries | 1
3. Mark as done:
bash
Copy code
$ ./task done 1
4. Check report:
bash
Copy code
$ ./task report
Pending: 0
Completed: 1
7. Technical Implementation Details
7.1 Memory Management
• The application uses malloc() and free() (implied) to manage dynamic memory for
tasks.
• Note: The current code skeleton contains several // CODE-HERE comments
indicating areas where memory management logic (specifically free and array
resizing) needs to be completed to prevent memory leaks.
7.2 Sorting
• The qsort() function is utilized to sort tasks by priority.
• The compare_Task function is defined to handle the comparison logic for qsort.
7.3 File I/O
• Append Mode ("a"): Used when adding new tasks to ensure existing data is
preserved.
• Write Mode ("w"): Used when deleting or completing tasks to rewrite the file with
the updated list.
• Read Mode ("r"): Used for listing and reporting.
8. Limitations and Future Scope
8.1 Limitations
1. Incomplete Implementation: Several core functions
(task_del, task_done, task_add, task_report) contain placeholder comments (//
CODE-HERE) and are not fully functional in the provided code.
2. No Error Handling: Robust error handling for file I/O failures or invalid user input is
minimal.
3. Fixed String Size: Task text is limited to STD_STRING_SIZE (30 characters), which
may be too short for complex tasks.
4. No Undo Feature: Once a task is deleted or marked done, there is no built-in way to
recover it.
5. Single User: The system does not support multiple users or profiles.
8.2 Future Scope
1. Complete Implementation: Finalize the logic for task_del, task_done,
and task_add functions.
2. Dynamic String Size: Implement dynamic string allocation (e.g., strdup or realloc) to
support longer task descriptions.
3. Search Functionality: Add a command to search for tasks by keyword.
4. Due Dates: Extend the Date structure to support due dates for tasks, not just
completion dates.
5. GUI Version: Port the logic to a Graphical User Interface (GUI) using libraries like
GTK or Qt.
6. Database: Migrate from text files to a SQLite database for better data integrity and
querying.
9. Conclusion
The TODO CLI Application serves as an educational project demonstrating the core
concepts of the C programming language, including structures, pointers, file handling, and
command-line argument parsing. While the current codebase is a skeleton requiring
completion of specific logic blocks, the architecture provides a solid foundation for a fully
functional task management system. It effectively highlights the importance of data
persistence and memory management in system programming.