How apardoo/so_22-23 works
Project type and purpose
• This is an educational, command-line interactive shell implemented in C, organized as four incremental lab assignments (P0–P3). Each “P#” directory contains headers, source files, a Makefile, and test harnesses or input files. The README confirms it’s a systems-programming teaching tool that builds a Unix-style shell with progressively added built-in commands and memory-management features.
File structure
• Top-level: .gitignore, LICENSE, README.md, and directories P0, P1, P2, P3.
• Each P# has:
• inc/ – public headers for that assignment
• src/ – implementation of the shell core and new commands
• makefile – build rules invoking gcc and valgrind targets
• info/ – specification PDFs and reference shells
• test/ (from P2 onward) – scripts or input files and expected outputs
• P3 adds a Sys_module for shared code, and test/delivery targets in the Makefile.
README for additional insights
• Core features introduced per lab:
• P0: basic prompt, history list, tokenization, and built-in commands (autores, pid, etc.)
• P1: file-system commands (create, stat, list, delete, deltree) using stat(), opendir(), readdir()
• P2: memory-management commands (allocate/free/mmap/shared), a linked-list of blocks, I/O commands, memdump/fill/memory/recurse
• P3: integrates all previous phases into a modular shell engine, using Sys_module.c/h for common logic and dispatching phases p0–p3
Main components and their interactions
a. Shell Core Engine
• Components: main loop (print prompt, read input), parser (TrocearCadena), dispatcher
• Lives in src/main.c (or p#.c for earlier labs)
b. Built-in Command Modules
• P0 commands (autores, pid, carpeta, fecha, hist, comando, infosis, ayuda, fin/salir/bye)
• P1 file commands (create, stat, list, delete, deltree)
• P2 memory commands (allocate, deallocate, i-o, memdump, memfill, memory, recurse)
• P3 consolidation: each practice’s commands invoked by dispatcher based on a phase parameter
c. Data Structures
• .c/h – generic singly linked list used for history (P0) and memory blocks (P2)
• Sys_module.c/h – abstraction layer in P3 for system errors and phase dispatch
d. System-call Interface
• stat(), mkdir(), open()/read()/write(), mmap()/munmap(), shmget()/shmat()/shmctl(), execvp() for pmap
e. Build & Test Infrastructure
• Makefiles per practice: “make”, “make memcheck” (valgrind), “make check” (diff against test inputs), “make delivery” (P3)
• test/test_in and test/differences to capture I/O validation
Relationships & Data Flows:
1. User types a command → Shell Core reads input → Parser tokenizes.
2. Dispatcher selects the correct Command Module based on first token and current practice phase.
3. Command Module executes: may invoke Data Structures API (linked list), perform System-calls, or fork/exec for external pmap.
4. Output printed to stdout; errors use errno and perror/strerror.
5. Test harness (if running make check) redirects input/output, diffs results.
Architectural patterns & design principles
• Modular layering: core engine at center, pluggable command handlers, a small shared library (List, Sys_module)
• Separation of concerns: parsing vs. execution vs. data management
• Incremental extension: each P# builds on previous code rather than rewriting a monolith