@@ -213,7 +213,7 @@ fn stty(opts: &Options) -> UResult<()> {
213
213
) ) ;
214
214
} ;
215
215
if let ControlFlow :: Break ( false ) =
216
- apply_char_mapping ( & mut termios, setting , char_index, new_cc)
216
+ apply_char_mapping ( & mut termios, char_index, new_cc)
217
217
{
218
218
return Err ( USimpleError :: new (
219
219
1 ,
@@ -489,7 +489,6 @@ fn apply_baud_rate_flag(termios: &mut Termios, input: &str) -> ControlFlow<bool>
489
489
490
490
fn apply_char_mapping (
491
491
termios : & mut Termios ,
492
- cc : & str ,
493
492
control_char_index : SpecialCharacterIndices ,
494
493
new_cc : & str ,
495
494
) -> ControlFlow < bool > {
@@ -514,7 +513,31 @@ fn string_to_control_char(s: &str) -> Option<u8> {
514
513
if s == "undef" || s == "^-" {
515
514
return Some ( 0 ) ;
516
515
}
517
- None
516
+
517
+ // try to parse integer (hex, octal, or decimal)
518
+ if let Some ( hex) = s. strip_prefix ( "0x" ) {
519
+ return u8:: from_str_radix ( hex, 16 ) . ok ( ) ;
520
+ } else if let Some ( octal) = s. strip_prefix ( "0" ) {
521
+ return u8:: from_str_radix ( octal, 8 ) . ok ( ) ;
522
+ } else if let Ok ( decimal) = s. parse :: < u8 > ( ) {
523
+ return Some ( decimal) ;
524
+ }
525
+
526
+ // try to parse ^<char> or just <char>
527
+ let mut chars = s. chars ( ) ;
528
+ match ( chars. next ( ) , chars. next ( ) ) {
529
+ ( Some ( '^' ) , Some ( c) ) if c. is_ascii_alphabetic ( ) => {
530
+ // subract by '@' to turn the char into the ascii value of '^<char>'
531
+ if c == '?' {
532
+ println ! ( "{}" , ( c. to_ascii_uppercase( ) as u8 ) . wrapping_sub( b'@' ) ) ;
533
+ }
534
+ Some ( ( c. to_ascii_uppercase ( ) as u8 ) . wrapping_sub ( b'@' ) )
535
+ }
536
+ ( Some ( c) , None ) => {
537
+ Some ( c as u8 )
538
+ }
539
+ _ => None ,
540
+ }
518
541
}
519
542
520
543
pub fn uu_app ( ) -> Command {
0 commit comments