aboutsummaryrefslogtreecommitdiff
path: root/build.rs
diff options
context:
space:
mode:
authorTill Hoeppner2015-04-20 20:58:52 +0200
committerTill Hoeppner2015-04-20 20:58:52 +0200
commit91bb1a6ced7eb8a913c0150e3076d3a6a1ae99ef (patch)
tree3b26e204fe328529cc5b11018456bdcd5d76d423 /build.rs
parentcabbd084f89908e91b81300a776cbeb5034396b8 (diff)
downloadirsc-91bb1a6ced7eb8a913c0150e3076d3a6a1ae99ef.tar.gz
irsc-91bb1a6ced7eb8a913c0150e3076d3a6a1ae99ef.tar.xz
irsc-91bb1a6ced7eb8a913c0150e3076d3a6a1ae99ef.zip
Code to generate base of src/command.rs and replies seperated from RFC
Diffstat (limited to 'build.rs')
-rw-r--r--build.rs61
1 files changed, 61 insertions, 0 deletions
diff --git a/build.rs b/build.rs
new file mode 100644
index 0000000..53ab74c
--- /dev/null
+++ b/build.rs
@@ -0,0 +1,61 @@
+use std::env;
+use std::fs::File;
+use std::io::{ Read, Write };
+use std::path::Path;
+use std::borrow::ToOwned;
+
+#[derive(Debug)]
+struct Command {
+ command: String,
+ params: String,
+ doc: String
+}
+
+fn main() {
+ let mut f = File::open("rfc2812_commands.txt").unwrap();
+
+ let mut content = String::new();
+ f.read_to_string(&mut content).unwrap();
+
+ let mut lines = content.lines();
+ let mut line = lines.next();
+
+ let mut commands = Vec::new();
+
+ let mut command: Option<&str> = None;
+ let mut params: Option<&str> = None;
+ let mut doc = String::new();
+ while let Some(l) = line {
+ // if is new command
+ if l.chars().next().map(char::is_whitespace) == Some(false)
+ && command.is_some() && params.is_some() {
+ commands.push(Command {
+ command: command.unwrap().to_owned(),
+ params: params.unwrap().to_owned(),
+ doc: doc.clone()
+ });
+ command = None;
+ params = None;
+ doc.clear();
+ }
+ if l.trim().starts_with("Command:") {
+ command = Some(&l.trim()["Command: ".len()..]);
+ } else if l.trim().starts_with("Parameters:") {
+ params = Some(&l.trim()["Parameters: ".len()..]);
+ }
+ doc.push_str(l);
+ doc.push_str("\n");
+
+ line = lines.next();
+ }
+
+ println!("pub enum Command {{");
+ for c in commands {
+ for l in c.doc.lines() {
+ println!(" /// {}", l);
+ }
+
+ println!(" {}({}),\n", c.command, c.params);
+ }
+ println!("}}");
+}