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
//! Help the user with command-line-arguments.

use crate::mission::ASCII_FILTER_ALIASSE;
use crate::mission::UNICODE_BLOCK_FILTER_ALIASSE;
use crate::mission::{Missions, MISSIONS};
use crate::options::ARGS;
use crate::options::ASCII_ENC_LABEL;
use crate::AUTHOR;
use crate::VERSION;
use std::process;
use std::str;

/// Function called at the beginning of `stringsext`. When help is printed to the
/// user, the program exits.

pub fn help() {
    if ARGS.version {
        println!("Version {}, {}", VERSION.unwrap_or("unknown"), AUTHOR);
        process::exit(0);
    };

    if ARGS.debug_option {
        println!("GIVEN COMMANDLINE-ARGUMENTS\n");
        println!("Input files\n-----------");
        for (n, name) in ARGS.inputs.iter().enumerate() {
            println!("{} = {:?}", char::from((n + 65) as u8), name);
        }

        println!("\nEncoding and filter definitions\n-------------------------------");
        for (n, name) in ARGS.encoding.iter().enumerate() {
            println!("{} = {}", char::from((n + 97) as u8), name);
        }

        println!("\n\nPARSED COMMANDLINE-ARGUMENTS\n");

        let ms: &'static Missions = &MISSIONS;
        for (i, m) in ms.v.iter().enumerate() {
            println!(
                "Scanner ({})\n-----------\n{:#?}\n",
                char::from((i + 97) as u8),
                m
            );
        }
        process::exit(0);
    };

    if ARGS.list_encodings {
        // Is there a way to programmatically query a list from `Encoding`?
        // This list is taken from the `Encoding` source file (2019-12-11)
        // and may  not be up to date.
        println!("LIST OF AVAILABLE ENCODINGS AND PREDEFINED FILTERS\n");
        println!("Format: --encoding=[ENC_NAME],[MIN],[AF,UBF],[GREP]\n\n");
        println!("ENC_NAME (Encoding)=");
        let list: [&'static str; 41] = [
            ASCII_ENC_LABEL,
            "Big5",
            "EUC-JP",
            "EUC-KR",
            "GBK",
            "IBM866",
            "ISO-2022-JP",
            "ISO-8859-10",
            "ISO-8859-13",
            "ISO-8859-14",
            "ISO-8859-15",
            "ISO-8859-16",
            "ISO-8859-2",
            "ISO-8859-3",
            "ISO-8859-4",
            "ISO-8859-5",
            "ISO-8859-6",
            "ISO-8859-7",
            "ISO-8859-8",
            "ISO-8859-8-I",
            "KOI8-R",
            "KOI8-U",
            "Shift_JIS",
            "UTF-16BE",
            "UTF-16LE",
            "UTF-8",
            "gb18030",
            "macintosh",
            "replacement",
            "windows-1250",
            "windows-1251",
            "windows-1252",
            "windows-1253",
            "windows-1254",
            "windows-1255",
            "windows-1256",
            "windows-1257",
            "windows-1258",
            "windows-874",
            "x-mac-cyrillic",
            "x-user-defined",
        ];

        // Available encodings
        for e in list.iter() {
            println!("\t{}", e);
        }
        println!("\tWarning: this list may be outdated.");
        println!(
            "\tPlease consult the library `encoding_rs` documentation \
             for more available encodings.\n\n"
        );

        println!("MIN = <number>");
        println!("\tOnly strings with at least <number> characters are printed.\n\n");

        println!("AF (ASCII-Filter) = <filter name> or <hexadecimal number>");
        for (e, b, c) in &ASCII_FILTER_ALIASSE {
            let b = format!("{:#x}", b);
            println!(
                "\t{} = {:>35} ({})",
                str::from_utf8(e).unwrap(),
                b,
                str::from_utf8(c).unwrap().trim()
            );
        }
        println!(
            "\tUse predefined filter names above or your own filter starting with `0x...`.\n\n"
        );

        println!("UBF (Unicode-Block-Filter) = <filter name> or <hexadecimal number>");
        for (e, b, c) in &UNICODE_BLOCK_FILTER_ALIASSE {
            let b = format!("{:#x}", b);
            println!(
                "\t{} = {:>18} ({})",
                str::from_utf8(e).unwrap(),
                b,
                str::from_utf8(c).unwrap().trim()
            );
        }
        println!(
            "\tUse predefined filter names above or your own filter starting with `0x...`.\n\n"
        );

        println!("GREP = <ASCII code>");
        println!("\tPrint only lines having at least one character with <ASCII-code>.");
        println!("\tUseful values are `47` (/) or `92` (\\) for path search.");
        println!("\t<ASCII code> can be decimal or hexadecimal and must be < 128.");

        process::exit(0);
    }
}