@@ -213,7 +213,7 @@ fn stty(opts: &Options) -> UResult<()> {
213213 ) ) ;
214214 } ;
215215 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)
217217 {
218218 return Err ( USimpleError :: new (
219219 1 ,
@@ -489,7 +489,6 @@ fn apply_baud_rate_flag(termios: &mut Termios, input: &str) -> ControlFlow<bool>
489489
490490fn apply_char_mapping (
491491 termios : & mut Termios ,
492- cc : & str ,
493492 control_char_index : SpecialCharacterIndices ,
494493 new_cc : & str ,
495494) -> ControlFlow < bool > {
@@ -514,7 +513,31 @@ fn string_to_control_char(s: &str) -> Option<u8> {
514513 if s == "undef" || s == "^-" {
515514 return Some ( 0 ) ;
516515 }
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+ }
518541}
519542
520543pub fn uu_app ( ) -> Command {
0 commit comments