blob: 64c2d6e3d5bd9616c6cc15021d83c8243a4dd39a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
# Dose - DOS-Style Command Shell
**Dose** is a DOS-style command shell implementation written in Zig. Originally started in Rust, the project has been completely rewritten in Zig to provide a nostalgic DOS computing experience with modern systems programming capabilities.
This project faithfully reproduces classic MS-DOS command behaviors, syntax, and error messages while running on modern systems.
## Features
### Interactive REPL Shell
- DOS-style command prompt (`C:\PATH>`)
- Complete lexer/parser for DOS command syntax with quote support
- Authentic DOS behavior and error messages
### Built-in Commands
**Core File Operations:**
- **`COPY`** - File copying with overwrite prompts and device handling
- **`DIR`** - Directory listing with file sizes, counts, and free space display
- **`TYPE`** - Display file contents with binary character filtering
- **`CD/CHDIR`** - Directory navigation with path validation
**Extended File Operations:**
- **`MD/MKDIR`** - Directory creation with nested path support
- **`RD/RMDIR`** - Directory removal with safety checks
- **`REN/RENAME`** - File and directory renaming
- **`DEL/REMOVE`** - File deletion with wildcard support
- **`PATH`** - Environment PATH variable management (GET/SET)
- **`MOVE`** - File/directory moving (placeholder)
**Shell and System Commands:**
- **`ECHO`** (with ON/OFF variants) - Text output and echo state control
- **`CLS`** - Clear screen with ANSI escape sequences
- **`EXIT`** - Exit the shell
- **`VER`** - Version information display
- **`DATE`** - Current system date with proper calendar calculations
- **`TIME`** - Current system time display
- **`SORT`** - Alphabetical line sorting with input redirection support
### I/O Redirection System
- **Input redirection** (`<`): Read file content as command input
- **Output redirection** (`>`): Write command output to file (overwrite)
- **Append redirection** (`>>`): Append command output to file
- **Combined redirection**: Support for both input and output redirection simultaneously
- **Device handling**: Proper CON/LPT/PRN device recognition and error handling
### External Command Support
- Full process spawning with I/O redirection support
- Proper command-line argument handling
- DOS-compatible "command not found" messages
- Exit code propagation
### Path Formatting
- DOS-style path display with drive letters
- 8.3 filename conversion where applicable
- Converts `/` to `\` and uppercases drive letters and names
- Defaults to `C:` when no drive is present
## Technical Features
### Memory Management
- **Allocator-based**: Uses Zig's `GeneralPurposeAllocator` for all dynamic memory
- **RAII Pattern**: Proper resource cleanup with `defer` statements
- **Leak Detection**: Built-in memory leak detection in debug builds
### Error Handling
- **Zig Error Unions**: Native `!T` error handling instead of exceptions
- **DOS-Authentic Messages**: Faithful reproduction of classic DOS error text
- **Graceful Degradation**: Robust error recovery and user guidance
### Architecture
- **Type-Safe Commands**: Uses Zig unions and enums for command architecture
- **Modular Design**: Clean separation between parsing, execution, and I/O
- **Zero Dependencies**: Uses only Zig standard library
- **Cross-Platform**: Portable file system and process operations
## Build
Requirements:
- Zig (recent version)
Commands:
```bash
# Development
zig build # Build debug version
zig build run # Build and run in debug mode
zig build test # Run unit tests
zig build -Doptimize=ReleaseFast # Optimized build
```
This produces an executable in `zig-out/bin/dose`.
## Run
Start the shell:
```
zig-out/bin/dose
```
You’ll see a DOS-like prompt. Example interactions:
```
C:\> VER
DOSE Version 6.22
C:\> DIR
... directory listing ...
C:\> COPY CON hello.txt
Hello world!
^Z
1 File(s) copied
C:\> TYPE hello.txt
Hello world!
```
Redirection:
```
C:\> DIR > dir.txt
C:\> TYPE dir.txt
```
Change directory:
```
C:\> CD ..
C:\> DIR
```
## Project Structure
```
src/
├── cmd/ # Modular command implementations
│ ├── lib/
│ │ └── types.zig # Shared command types and interfaces
│ ├── chdir.zig # CD/CHDIR command
│ ├── cls.zig # CLS command
│ ├── copy.zig # COPY command
│ ├── date.zig # DATE command
│ ├── dir.zig # DIR command
│ ├── echo.zig # ECHO command variants
│ ├── mkdir.zig # MD/MKDIR command
│ ├── move.zig # MOVE command (placeholder)
│ ├── path.zig # PATH command (GET/SET)
│ ├── remove.zig # DEL/REMOVE command
│ ├── rename.zig # REN/RENAME command
│ ├── rmdir.zig # RD/RMDIR command
│ ├── sort.zig # SORT command
│ ├── time.zig # TIME command
│ └── type.zig # TYPE command
├── cmd.zig # Command type definitions and imports
├── eval.zig # Command execution engine
├── parser.zig # DOS command line parser
├── paths.zig # DOS path formatting utilities
├── syntax.zig # Command syntax structures
└── main.zig # Application entry point and REPL
```
## License
GNU AGPLv3.
|