Skip to content

Commit

Permalink
docgen - a manpage generator
Browse files Browse the repository at this point in the history
  • Loading branch information
ticki committed Mar 3, 2016
1 parent 395e392 commit 4857985
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,17 @@ doc/std: libstd/src/lib.rs libstd/src/*.rs libstd/src/*/*.rs libstd/src/*/*/*.rs

doc: doc/kernel doc/std

man: filesystem/man

filesystem/man:
mkdir man \
rm -rf filesystem/man |& true \
cd crates/docgen \
cargo build --release \
cd ../../ \
./crates/docgen/target/release/docgen \
mv man filesystem

$(BUILD)/libcore.rlib: rust/src/libcore/lib.rs
$(MKDIR) -p $(BUILD)
$(RUSTC) $(RUSTCFLAGS) --cfg disable_float -o $@ $<
Expand Down
35 changes: 35 additions & 0 deletions crates/docgen/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions crates/docgen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "docgen"
version = "0.1.0"
authors = ["Ticki <Ticki@users.noreply.github.com>"]

[dependencies]
walkdir = "0.1"
42 changes: 42 additions & 0 deletions crates/docgen/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#![feature(unicode)]

extern crate walkdir;
extern crate rustc_unicode;

use walkdir::WalkDir;
use std::fs::File;
use std::io::prelude::*;

fn main() {
for entry in WalkDir::new(".").follow_links(true).into_iter().map(|x| x.expect("Couldn't walk dir.")).filter(|x| x.file_type().is_file()) {
let mut string = String::new();

File::open(entry.path()).expect("Could't open file.")
.read_to_string(&mut string)
.expect("Could't read file.");

for i in string.split("@MANSTART{").skip(1) {
let end_delimiter = i.find('}').expect("Unclosed '{'");
let name = &i[..end_delimiter];
assert!(name.lines().count() == 1, "malformed manpage name");

let mut man_page = &i[end_delimiter + 1..i.find("@MANEND")
.expect("Unclosed @MANSTART (use @MANEND).")].trim();

let mut string = String::with_capacity(man_page.len() + man_page.len() / 3);

for i in man_page.lines() {
string.push_str(i.trim_left_matches('\\')
.trim_left_matches("// ")
.trim_left_matches("//! ")
.trim_left_matches("/// ")
.trim_left_matches("->")
.trim_left_matches("<!-"));
string.push('\n')
}

let mut file = File::create("man/".to_owned() + name).expect("Couldn't create man page.");
file.write(&string.as_bytes()[1..string.len() - 1]).expect("Couldn't write man page.");
}
}
}
3 changes: 3 additions & 0 deletions crates/docgen/src/test/man/doc-ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test doc mode
myltiline
Oh, snap.
1 change: 1 addition & 0 deletions crates/docgen/src/test/man/test1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ere you go
1 change: 1 addition & 0 deletions crates/docgen/src/test/man/test2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eah test 2
17 changes: 17 additions & 0 deletions crates/docgen/src/test/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@MANSTART{test1}
here you go
@MANEND

@MANSTART{test2}
yeah test 2
@MANEND

/// <!- @MANSTART{doc} ->
/// test doc mode
/// <!- @MANEND ->

/// <!- @MANSTART{doc-ml} ->
/// test doc mode
/// myltiline
/// Oh, snap.
/// <!- @MANEND ->

0 comments on commit 4857985

Please sign in to comment.