File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -90,3 +90,11 @@ dpkey module steals key input processing from DOS and converts scan code to asci
9090about scan code: see [ PS/2 Keyboard - OSDev Wiki] ( https://wiki.osdev.org/PS/2_Keyboard ) .
9191
9292![ sample2] ( https://github.com/o8vm/rust_dos/blob/images/dpkey.gif )
93+
94+ ## Tests
95+
96+ To run the tests suite, you can type on your DOS emulator:
97+
98+ ``` shell
99+ rust_dos.com test
100+ ```
Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ pub mod error_code;
99pub mod panic;
1010pub mod math;
1111pub mod cooperative_multitasking;
12+ pub mod env;
13+
1214use core:: arch:: asm;
1315
1416pub use alloc:: string:: String as String ;
Original file line number Diff line number Diff line change 1+ use alloc:: vec:: Vec ;
2+ use core:: slice;
3+
4+ fn command_tail < ' a > ( ) -> & ' a [ u8 ] {
5+ unsafe {
6+ let ptr = 0x80 as * const u8 ;
7+ let len = * ptr as usize ;
8+ let bytes = slice:: from_raw_parts ( ptr. add ( 1 ) , len) ;
9+
10+ let trimmed = bytes. iter ( )
11+ . position ( |& b| b == 0x0D )
12+ . unwrap_or ( len) ;
13+
14+ & bytes[ ..trimmed]
15+ }
16+ }
17+
18+ /// Returns the command line arguments as a vector of string slices.
19+ /// Handles quoted arguments and whitespace separation.
20+ ///
21+ /// # Warning
22+ /// Unlike standard operating system, the first argument (index 0) is not the program name,
23+ /// but the first argument after the program name.
24+ pub fn args ( ) -> Vec < & ' static str > {
25+ let mut args = Vec :: new ( ) ;
26+ let line = command_tail ( ) ;
27+
28+ let s = unsafe { core:: str:: from_utf8_unchecked ( line) } ;
29+ let bytes = s. as_bytes ( ) ;
30+ let len = bytes. len ( ) ;
31+ let mut i = 0 ;
32+
33+ while i < len {
34+ while i < len && bytes[ i] . is_ascii_whitespace ( ) {
35+ i += 1 ;
36+ }
37+ if i >= len { break ; }
38+
39+ let start = i;
40+ let mut in_quotes = false ;
41+
42+ while i < len {
43+ let c = bytes[ i] ;
44+ if c == b'"' {
45+ in_quotes = !in_quotes;
46+ i += 1 ;
47+ continue ;
48+ }
49+ if !in_quotes && c. is_ascii_whitespace ( ) {
50+ break ;
51+ }
52+ i += 1 ;
53+ }
54+
55+ let end = i;
56+ let token = s[ start..end] . trim_matches ( '"' ) ;
57+ args. push ( token) ;
58+ }
59+
60+ args
61+ }
Original file line number Diff line number Diff line change 1+ #![ feature( abi_x86_interrupt) ]
12#![ no_std]
23#![ no_main]
34
45extern crate alloc;
56
67mod dos_tests;
78
8- use rust_dos:: * ;
99use crate :: dos_tests:: allocator_test:: allocator_test;
10+ use crate :: dos_tests:: cooperative_multitasking_test:: cooperative_multitasking_test;
1011use crate :: dos_tests:: datetime:: datetime_test;
1112use crate :: dos_tests:: file:: file_read_test;
12- use crate :: dos_tests :: cooperative_multitasking_test :: cooperative_multitasking_test ;
13+ use rust_dos :: * ;
1314
1415entry ! ( main) ;
1516
1617fn main ( ) {
17- allocator_test ( ) ;
18- file_read_test ( ) ;
19- datetime_test ( ) ;
20- cooperative_multitasking_test ( ) ;
21- println ! ( "Hello, World!" ) ;
18+ let args = dos:: env:: args ( ) ;
19+
20+ if args. len ( ) >= 1 && args[ 0 ] == "test" {
21+ allocator_test ( ) ;
22+ file_read_test ( ) ;
23+ datetime_test ( ) ;
24+ cooperative_multitasking_test ( ) ;
25+ } else {
26+ println ! ( "Hello, World!" ) ;
27+ }
2228}
29+
30+
31+
32+
You can’t perform that action at this time.
0 commit comments