From d1b71d1c8eb07743a5a1073448cbcb6eee0d84fc Mon Sep 17 00:00:00 2001 From: Alexander Regueiro Date: Sun, 13 Jan 2019 02:25:53 +0000 Subject: [PATCH] Removed copyright notices & made cosmetic improvements. --- 2018-edition/convert-quotes.sh | 9 ------ 2018-edition/nostarch.sh | 19 +++--------- 2018-edition/tools/src/bin/concat_chapters.rs | 10 ------ 2018-edition/tools/src/bin/convert_quotes.rs | 11 ------- 2018-edition/tools/src/bin/lfp.rs | 15 ++------- 2018-edition/tools/src/bin/link2print.rs | 31 +++++-------------- 2018-edition/tools/src/bin/remove_links.rs | 24 +++++--------- 2018-edition/tools/src/bin/remove_markup.rs | 19 +++--------- ci/build.sh | 12 ++----- ci/spellcheck.sh | 23 +++++--------- ci/stable-check/src/main.rs | 10 ------ convert-quotes.sh | 9 ------ nostarch.sh | 19 +++--------- second-edition/convert-quotes.sh | 9 ------ second-edition/doc-to-md.sh | 31 +++++++------------ second-edition/nostarch.sh | 19 +++--------- .../tools/src/bin/concat_chapters.rs | 10 ------ .../tools/src/bin/convert_quotes.rs | 19 +++--------- second-edition/tools/src/bin/lfp.rs | 10 ------ second-edition/tools/src/bin/link2print.rs | 27 ++++------------ second-edition/tools/src/bin/remove_links.rs | 22 ++++--------- second-edition/tools/src/bin/remove_markup.rs | 19 +++--------- tools/src/bin/concat_chapters.rs | 10 ------ tools/src/bin/convert_quotes.rs | 18 +++-------- tools/src/bin/lfp.rs | 15 ++------- tools/src/bin/link2print.rs | 31 +++++-------------- tools/src/bin/remove_links.rs | 26 +++++----------- tools/src/bin/remove_markup.rs | 19 +++--------- 28 files changed, 107 insertions(+), 389 deletions(-) diff --git a/2018-edition/convert-quotes.sh b/2018-edition/convert-quotes.sh index 229be889..aa51dcbd 100755 --- a/2018-edition/convert-quotes.sh +++ b/2018-edition/convert-quotes.sh @@ -1,13 +1,4 @@ #!/bin/bash -# Copyright 2017 The Rust Project Developers. See the COPYRIGHT -# file at the top-level directory of this distribution and at -# http://rust-lang.org/COPYRIGHT. -# -# Licensed under the Apache License, Version 2.0 or the MIT license -# , at your -# option. This file may not be copied, modified, or distributed -# except according to those terms. set -eu diff --git a/2018-edition/nostarch.sh b/2018-edition/nostarch.sh index 432add59..6c4173a0 100755 --- a/2018-edition/nostarch.sh +++ b/2018-edition/nostarch.sh @@ -1,13 +1,4 @@ #!/bin/bash -# Copyright 2016 The Rust Project Developers. See the COPYRIGHT -# file at the top-level directory of this distribution and at -# http://rust-lang.org/COPYRIGHT. -# -# Licensed under the Apache License, Version 2.0 or the MIT license -# , at your -# option. This file may not be copied, modified, or distributed -# except according to those terms. set -eu @@ -16,18 +7,18 @@ cargo build --release mkdir -p tmp rm -rf tmp/*.md -# Get all the markdown files in the src dir, +# Get all the Markdown files in the src dir, ls src/${1:-""}*.md | \ -# except for SUMMARY.md. +# except for `SUMMARY.md`. grep -v SUMMARY.md | \ # Extract just the filename so we can reuse it easily. xargs -n 1 basename | \ -# Remove all links followed by , then -# Change all remaining links from markdown to italicized inline text. +# Remove all links followed by ```, then +# Change all remaining links from Markdown to italicized inline text. while IFS= read -r filename; do < "src/$filename" ./target/release/remove_links \ | ./target/release/link2print \ | ./target/release/remove_markup > "tmp/$filename" done -# Concat the files into the nostarch dir. +# Concatenate the files into the `nostarch` dir. ./target/release/concat_chapters tmp nostarch diff --git a/2018-edition/tools/src/bin/concat_chapters.rs b/2018-edition/tools/src/bin/concat_chapters.rs index accb2d3d..da02dd34 100644 --- a/2018-edition/tools/src/bin/concat_chapters.rs +++ b/2018-edition/tools/src/bin/concat_chapters.rs @@ -1,13 +1,3 @@ -// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - #[macro_use] extern crate lazy_static; extern crate regex; diff --git a/2018-edition/tools/src/bin/convert_quotes.rs b/2018-edition/tools/src/bin/convert_quotes.rs index 2d8e5e92..b151ae7e 100644 --- a/2018-edition/tools/src/bin/convert_quotes.rs +++ b/2018-edition/tools/src/bin/convert_quotes.rs @@ -1,13 +1,3 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - use std::io; use std::io::{Read, Write}; @@ -22,7 +12,6 @@ fn main() { } for line in buffer.lines() { - if line.is_empty() { is_in_inline_code = false; } diff --git a/2018-edition/tools/src/bin/lfp.rs b/2018-edition/tools/src/bin/lfp.rs index c7d9e54e..f475df08 100644 --- a/2018-edition/tools/src/bin/lfp.rs +++ b/2018-edition/tools/src/bin/lfp.rs @@ -1,20 +1,11 @@ -// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - // We have some long regex literals, so: // ignore-tidy-linelength -extern crate rustc_serialize; extern crate docopt; -use docopt::Docopt; +extern crate rustc_serialize; extern crate walkdir; + +use docopt::Docopt; use std::{path, fs, io}; use std::io::{BufRead, Write}; diff --git a/2018-edition/tools/src/bin/link2print.rs b/2018-edition/tools/src/bin/link2print.rs index 071c7802..4fe4477b 100644 --- a/2018-edition/tools/src/bin/link2print.rs +++ b/2018-edition/tools/src/bin/link2print.rs @@ -1,15 +1,4 @@ -// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - - -// FIXME: We have some long lines that could be refactored, but it's not a big deal. +// FIXME: we have some long lines that could be refactored, but it's not a big deal. // ignore-tidy-linelength extern crate regex; @@ -20,7 +9,6 @@ use std::io::{Read, Write}; use regex::{Regex, Captures}; fn main() { - write_md(parse_links(parse_references(read_md()))); } @@ -38,7 +26,7 @@ fn write_md(output: String) { fn parse_references(buffer: String) -> (String, HashMap) { let mut ref_map = HashMap::new(); - // FIXME: Currently doesn't handle "title" in following line + // FIXME: currently doesn't handle "title" in following line. let re = Regex::new(r###"(?m)\n?^ {0,3}\[([^]]+)\]:[[:blank:]]*(.*)$"###).unwrap(); let output = re.replace_all(&buffer, |caps: &Captures| { let key = caps.at(1).unwrap().to_owned().to_uppercase(); @@ -52,7 +40,7 @@ fn parse_references(buffer: String) -> (String, HashMap) { } fn parse_links((buffer, ref_map): (String, HashMap)) -> String { - // FIXME: check which punctuation is allowed by spec + // FIXME: check which punctuation is allowed by spec. let re = Regex::new(r###"(?:(?P
(?:```(?:[^`]|`[^`])*`?\n```\n)|(?:[^[]`[^`\n]+[\n]?[^`\n]*`))|(?:\[(?P[^]]+)\](?:(?:\([[:blank:]]*(?P[^")]*[^ ])(?:[[:blank:]]*"[^"]*")?\))|(?:\[(?P[^]]*)\]))?))"###).expect("could not create regex");
     let error_code = Regex::new(r###"^E\d{4}$"###).expect("could not create regex");
     let output = re.replace_all(&buffer, |caps: &Captures| {
@@ -62,7 +50,7 @@ fn parse_links((buffer, ref_map): (String, HashMap)) -> String {
                 let name = caps.name("name").expect("could not get name").to_owned();
                 // Really we should ignore text inside code blocks,
                 // this is a hack to not try to treat `#[derive()]`,
-                // `[profile]`, `[test]`, or `[E\d\d\d\d]` like a link
+                // `[profile]`, `[test]`, or `[E\d\d\d\d]` like a link.
                 if name.starts_with("derive(") ||
                    name.starts_with("profile") ||
                    name.starts_with("test") ||
@@ -71,19 +59,19 @@ fn parse_links((buffer, ref_map): (String, HashMap)) -> String {
                 }
 
                 let val = match caps.name("val") {
-                    // [name](link)
+                    // `[name](link)`
                     Some(value) => value.to_owned(),
                     None => {
                         match caps.name("key") {
                             Some(key) => {
                                 match key {
-                                    // [name][]
+                                    // `[name][]`
                                     "" => format!("{}", ref_map.get(&name.to_uppercase()).expect(&format!("could not find url for the link text `{}`", name))),
-                                    // [name][reference]
+                                    // `[name][reference]`
                                     _ => format!("{}", ref_map.get(&key.to_uppercase()).expect(&format!("could not find url for the link text `{}`", key))),
                                 }
                             }
-                            // [name] as reference
+                            // `[name]` as reference
                             None => format!("{}", ref_map.get(&name.to_uppercase()).expect(&format!("could not find url for the link text `{}`", name))),
                         }
                     }
@@ -415,7 +403,4 @@ Some text to show that the reference links can follow later.
             .to_string();
         assert_eq!(parse(source), target);
     }
-
-
-
 }
diff --git a/2018-edition/tools/src/bin/remove_links.rs b/2018-edition/tools/src/bin/remove_links.rs
index 9add24ec..71c38610 100644
--- a/2018-edition/tools/src/bin/remove_links.rs
+++ b/2018-edition/tools/src/bin/remove_links.rs
@@ -1,19 +1,9 @@
-// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0  or the MIT license
-// , at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
 extern crate regex;
 
+use std::collections::HashSet;
 use std::io;
 use std::io::{Read, Write};
 use regex::{Regex, Captures};
-use std::collections::HashSet;
 
 fn main () {
     let mut buffer = String::new();
@@ -23,31 +13,31 @@ fn main () {
 
     let mut refs = HashSet::new();
 
-    // capture all links and link references
+    // Capture all links and link references.
     let regex = r"\[([^\]]+)\](?:(?:\[([^\]]+)\])|(?:\([^\)]+\)))(?i)";
     let link_regex = Regex::new(regex).unwrap();
     let first_pass = link_regex.replace_all(&buffer, |caps: &Captures| {
 
-        // save the link reference we want to delete
+        // Save the link reference we want to delete.
         if let Some(reference) = caps.at(2) {
             refs.insert(reference.to_owned());
         }
 
-        // put the link title back
+        // Put the link title back.
         caps.at(1).unwrap().to_owned()
     });
 
-    // search for the references we need to delete
+    // Search for the references we need to delete.
     let ref_regex = Regex::new(r"\n\[([^\]]+)\]:\s.*\n").unwrap();
     let out = ref_regex.replace_all(&first_pass, |caps: &Captures| {
         let capture = caps.at(1).unwrap().to_owned();
 
-        // check if we've marked this reference for deletion...
+        // Check if we've marked this reference for deletion ...
         if refs.contains(capture.as_str()) {
             return "".to_string();
         }
 
-        //... else we put back everything we captured
+        // ... else we put back everything we captured.
         caps.at(0).unwrap().to_owned()
     });
 
diff --git a/2018-edition/tools/src/bin/remove_markup.rs b/2018-edition/tools/src/bin/remove_markup.rs
index c8cbc1c1..be444bfd 100644
--- a/2018-edition/tools/src/bin/remove_markup.rs
+++ b/2018-edition/tools/src/bin/remove_markup.rs
@@ -1,14 +1,5 @@
-// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0  or the MIT license
-// , at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
 extern crate regex;
+
 use std::io;
 use std::io::{Read, Write};
 use regex::{Regex, Captures};
@@ -31,23 +22,23 @@ fn write_md(output: String) {
 
 fn remove_markup(input: String) -> String {
     let filename_regex = Regex::new(r#"\A(.*)\z"#).unwrap();
-    // Captions sometimes take up multiple lines
+    // Captions sometimes take up multiple lines.
     let caption_start_regex = Regex::new(r#"\A(.*)\z"#).unwrap();
     let caption_end_regex = Regex::new(r#"(.*)\z"#).unwrap();
     let regexen = vec![filename_regex, caption_start_regex, caption_end_regex];
 
     let lines: Vec<_> = input.lines().flat_map(|line| {
-        // Remove our figure and caption markup
+        // Remove our figure and caption markup.
         if line == "
" || line == "
" || line == "
" || line == "
" { None - // Remove our syntax highlighting and rustdoc markers + // Remove our syntax highlighting and rustdoc markers. } else if line.starts_with("```") { Some(String::from("```")) - // Remove the span around filenames and captions + // Remove the span around filenames and captions. } else { let result = regexen.iter().fold(line.to_string(), |result, regex| { regex.replace_all(&result, |caps: &Captures| { diff --git a/ci/build.sh b/ci/build.sh index ef3dadbd..9ad17813 100644 --- a/ci/build.sh +++ b/ci/build.sh @@ -1,18 +1,10 @@ -# Copyright 2016 The Rust Project Developers. See the COPYRIGHT -# file at the top-level directory of this distribution and at -# http://rust-lang.org/COPYRIGHT. -# -# Licensed under the Apache License, Version 2.0 or the MIT license -# , at your -# option. This file may not be copied, modified, or distributed -# except according to those terms. +#!/bin/bash set -e export PATH=$PATH:/home/travis/.cargo/bin; -# feature check +# Feature check cd ci/stable-check cargo run -- ../../src diff --git a/ci/spellcheck.sh b/ci/spellcheck.sh index ac5351ec..f1c84a5f 100755 --- a/ci/spellcheck.sh +++ b/ci/spellcheck.sh @@ -1,17 +1,8 @@ #!/bin/bash -# Copyright 2016 The Rust Project Developers. See the COPYRIGHT -# file at the top-level directory of this distribution and at -# http://rust-lang.org/COPYRIGHT. -# -# Licensed under the Apache License, Version 2.0 or the MIT license -# , at your -# option. This file may not be copied, modified, or distributed -# except according to those terms. aspell --version -# Checks project markdown files for spell errors +# Checks project Markdown files for spelling mistakes. # Notes: @@ -45,8 +36,8 @@ dict_filename=./ci/dictionary.txt markdown_sources=(./src/*.md) mode="check" -# aspell repeatedly modifies personal dictionary for some purpose, -# so we should use a copy of our dictionary +# aspell repeatedly modifies the personal dictionary for some reason, +# so we should use a copy of our dictionary. dict_path="/tmp/dictionary.txt" if [[ "$1" == "list" ]]; then @@ -70,7 +61,7 @@ if [[ ! -f "$dict_filename" ]]; then echo "personal_ws-1.1 en 0 utf-8" > "$dict_filename" cat "${markdown_sources[@]}" | aspell --ignore 3 list | sort -u >> "$dict_filename" elif [[ "$mode" == "list" ]]; then - # List (default) mode: scan all files, report errors + # List (default) mode: scan all files, report errors. declare -i retval=0 cp "$dict_filename" "$dict_path" @@ -84,9 +75,9 @@ elif [[ "$mode" == "list" ]]; then command=$(aspell --ignore 3 --personal="$dict_path" "$mode" < "$fname") if [[ -n "$command" ]]; then for error in $command; do - # FIXME: Find more correct way to get line number + # FIXME: find more correct way to get line number # (ideally from aspell). Now it can make some false positives, - # because it is just a grep + # because it is just a grep. grep --with-filename --line-number --color=always "$error" "$fname" done retval=1 @@ -94,7 +85,7 @@ elif [[ "$mode" == "list" ]]; then done exit "$retval" elif [[ "$mode" == "check" ]]; then - # Interactive mode: fix typos + # Interactive mode: fix typos. cp "$dict_filename" "$dict_path" if [ ! -f $dict_path ]; then diff --git a/ci/stable-check/src/main.rs b/ci/stable-check/src/main.rs index fafc1015..167f1f88 100644 --- a/ci/stable-check/src/main.rs +++ b/ci/stable-check/src/main.rs @@ -1,13 +1,3 @@ -// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - use std::error::Error; use std::env; use std::fs; diff --git a/convert-quotes.sh b/convert-quotes.sh index 229be889..aa51dcbd 100755 --- a/convert-quotes.sh +++ b/convert-quotes.sh @@ -1,13 +1,4 @@ #!/bin/bash -# Copyright 2017 The Rust Project Developers. See the COPYRIGHT -# file at the top-level directory of this distribution and at -# http://rust-lang.org/COPYRIGHT. -# -# Licensed under the Apache License, Version 2.0 or the MIT license -# , at your -# option. This file may not be copied, modified, or distributed -# except according to those terms. set -eu diff --git a/nostarch.sh b/nostarch.sh index 432add59..6c4173a0 100755 --- a/nostarch.sh +++ b/nostarch.sh @@ -1,13 +1,4 @@ #!/bin/bash -# Copyright 2016 The Rust Project Developers. See the COPYRIGHT -# file at the top-level directory of this distribution and at -# http://rust-lang.org/COPYRIGHT. -# -# Licensed under the Apache License, Version 2.0 or the MIT license -# , at your -# option. This file may not be copied, modified, or distributed -# except according to those terms. set -eu @@ -16,18 +7,18 @@ cargo build --release mkdir -p tmp rm -rf tmp/*.md -# Get all the markdown files in the src dir, +# Get all the Markdown files in the src dir, ls src/${1:-""}*.md | \ -# except for SUMMARY.md. +# except for `SUMMARY.md`. grep -v SUMMARY.md | \ # Extract just the filename so we can reuse it easily. xargs -n 1 basename | \ -# Remove all links followed by , then -# Change all remaining links from markdown to italicized inline text. +# Remove all links followed by ```, then +# Change all remaining links from Markdown to italicized inline text. while IFS= read -r filename; do < "src/$filename" ./target/release/remove_links \ | ./target/release/link2print \ | ./target/release/remove_markup > "tmp/$filename" done -# Concat the files into the nostarch dir. +# Concatenate the files into the `nostarch` dir. ./target/release/concat_chapters tmp nostarch diff --git a/second-edition/convert-quotes.sh b/second-edition/convert-quotes.sh index 229be889..aa51dcbd 100644 --- a/second-edition/convert-quotes.sh +++ b/second-edition/convert-quotes.sh @@ -1,13 +1,4 @@ #!/bin/bash -# Copyright 2017 The Rust Project Developers. See the COPYRIGHT -# file at the top-level directory of this distribution and at -# http://rust-lang.org/COPYRIGHT. -# -# Licensed under the Apache License, Version 2.0 or the MIT license -# , at your -# option. This file may not be copied, modified, or distributed -# except according to those terms. set -eu diff --git a/second-edition/doc-to-md.sh b/second-edition/doc-to-md.sh index 259d6f02..170727db 100644 --- a/second-edition/doc-to-md.sh +++ b/second-edition/doc-to-md.sh @@ -1,29 +1,20 @@ #!/bin/bash -# Copyright 2016 The Rust Project Developers. See the COPYRIGHT -# file at the top-level directory of this distribution and at -# http://rust-lang.org/COPYRIGHT. -# -# Licensed under the Apache License, Version 2.0 or the MIT license -# , at your -# option. This file may not be copied, modified, or distributed -# except according to those terms. set -eu -# Get all the docx files in the tmp dir, +# Get all the docx files in the tmp dir. ls tmp/*.docx | \ # Extract just the filename so we can reuse it easily. xargs -n 1 basename -s .docx | \ while IFS= read -r filename; do - # Make a directory to put the XML in - mkdir -p "tmp/$filename" - # Unzip the docx to get at the xml - unzip -o "tmp/$filename.docx" -d "tmp/$filename" - # Convert to markdown with XSL - xsltproc tools/docx-to-md.xsl "tmp/$filename/word/document.xml" | \ - # Hard wrap at 80 chars at word bourdaries - fold -w 80 -s | \ - # Remove trailing whitespace & save in the nostarch dir for comparison - sed -e "s/ *$//" > "nostarch/$filename.md" + # Make a directory to put the XML in. + mkdir -p "tmp/$filename" + # Unzip the docx to get at the XML. + unzip -o "tmp/$filename.docx" -d "tmp/$filename" + # Convert to markdown with XSL. + xsltproc tools/docx-to-md.xsl "tmp/$filename/word/document.xml" | \ + # Hard wrap at 80 chars at word bourdaries. + fold -w 80 -s | \ + # Remove trailing whitespace and save in the `nostarch` dir for comparison. + sed -e "s/ *$//" > "nostarch/$filename.md" done diff --git a/second-edition/nostarch.sh b/second-edition/nostarch.sh index 432add59..6c4173a0 100644 --- a/second-edition/nostarch.sh +++ b/second-edition/nostarch.sh @@ -1,13 +1,4 @@ #!/bin/bash -# Copyright 2016 The Rust Project Developers. See the COPYRIGHT -# file at the top-level directory of this distribution and at -# http://rust-lang.org/COPYRIGHT. -# -# Licensed under the Apache License, Version 2.0 or the MIT license -# , at your -# option. This file may not be copied, modified, or distributed -# except according to those terms. set -eu @@ -16,18 +7,18 @@ cargo build --release mkdir -p tmp rm -rf tmp/*.md -# Get all the markdown files in the src dir, +# Get all the Markdown files in the src dir, ls src/${1:-""}*.md | \ -# except for SUMMARY.md. +# except for `SUMMARY.md`. grep -v SUMMARY.md | \ # Extract just the filename so we can reuse it easily. xargs -n 1 basename | \ -# Remove all links followed by , then -# Change all remaining links from markdown to italicized inline text. +# Remove all links followed by ```, then +# Change all remaining links from Markdown to italicized inline text. while IFS= read -r filename; do < "src/$filename" ./target/release/remove_links \ | ./target/release/link2print \ | ./target/release/remove_markup > "tmp/$filename" done -# Concat the files into the nostarch dir. +# Concatenate the files into the `nostarch` dir. ./target/release/concat_chapters tmp nostarch diff --git a/second-edition/tools/src/bin/concat_chapters.rs b/second-edition/tools/src/bin/concat_chapters.rs index accb2d3d..da02dd34 100644 --- a/second-edition/tools/src/bin/concat_chapters.rs +++ b/second-edition/tools/src/bin/concat_chapters.rs @@ -1,13 +1,3 @@ -// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - #[macro_use] extern crate lazy_static; extern crate regex; diff --git a/second-edition/tools/src/bin/convert_quotes.rs b/second-edition/tools/src/bin/convert_quotes.rs index 2d8e5e92..c1e38dac 100644 --- a/second-edition/tools/src/bin/convert_quotes.rs +++ b/second-edition/tools/src/bin/convert_quotes.rs @@ -1,13 +1,3 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - use std::io; use std::io::{Read, Write}; @@ -22,7 +12,6 @@ fn main() { } for line in buffer.lines() { - if line.is_empty() { is_in_inline_code = false; } @@ -39,11 +28,11 @@ fn main() { let mut chars_in_line = line.chars(); while let Some(possible_match) = chars_in_line.next() { - // check if inside inline code + // Check if inside inline code. if possible_match == '`' { is_in_inline_code = !is_in_inline_code; } - // check if inside html tag + // Check if inside HTML tag. if possible_match == '<' && !is_in_inline_code { is_in_html_tag = true; } @@ -51,7 +40,7 @@ fn main() { is_in_html_tag = false; } - // replace with right/left apostrophe/quote + // Replace with right/left apostrophe/quote. let char_to_push = if possible_match == '\'' && !is_in_inline_code && !is_in_html_tag { if (previous_char != std::char::REPLACEMENT_CHARACTER && @@ -72,7 +61,7 @@ fn main() { '“' } } else { - // leave untouched + // Leave untouched. possible_match }; modified_line.push(char_to_push); diff --git a/second-edition/tools/src/bin/lfp.rs b/second-edition/tools/src/bin/lfp.rs index c7d9e54e..06fa6e42 100644 --- a/second-edition/tools/src/bin/lfp.rs +++ b/second-edition/tools/src/bin/lfp.rs @@ -1,13 +1,3 @@ -// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - // We have some long regex literals, so: // ignore-tidy-linelength diff --git a/second-edition/tools/src/bin/link2print.rs b/second-edition/tools/src/bin/link2print.rs index 071c7802..26f40c84 100644 --- a/second-edition/tools/src/bin/link2print.rs +++ b/second-edition/tools/src/bin/link2print.rs @@ -1,15 +1,4 @@ -// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - - -// FIXME: We have some long lines that could be refactored, but it's not a big deal. +// FIXME: we have some long lines that could be refactored, but it's not a big deal. // ignore-tidy-linelength extern crate regex; @@ -20,7 +9,6 @@ use std::io::{Read, Write}; use regex::{Regex, Captures}; fn main() { - write_md(parse_links(parse_references(read_md()))); } @@ -38,7 +26,7 @@ fn write_md(output: String) { fn parse_references(buffer: String) -> (String, HashMap) { let mut ref_map = HashMap::new(); - // FIXME: Currently doesn't handle "title" in following line + // FIXME: currently doesn't handle "title" in following line. let re = Regex::new(r###"(?m)\n?^ {0,3}\[([^]]+)\]:[[:blank:]]*(.*)$"###).unwrap(); let output = re.replace_all(&buffer, |caps: &Captures| { let key = caps.at(1).unwrap().to_owned().to_uppercase(); @@ -52,7 +40,7 @@ fn parse_references(buffer: String) -> (String, HashMap) { } fn parse_links((buffer, ref_map): (String, HashMap)) -> String { - // FIXME: check which punctuation is allowed by spec + // FIXME: check which punctuation is allowed by spec. let re = Regex::new(r###"(?:(?P
(?:```(?:[^`]|`[^`])*`?\n```\n)|(?:[^[]`[^`\n]+[\n]?[^`\n]*`))|(?:\[(?P[^]]+)\](?:(?:\([[:blank:]]*(?P[^")]*[^ ])(?:[[:blank:]]*"[^"]*")?\))|(?:\[(?P[^]]*)\]))?))"###).expect("could not create regex");
     let error_code = Regex::new(r###"^E\d{4}$"###).expect("could not create regex");
     let output = re.replace_all(&buffer, |caps: &Captures| {
@@ -62,7 +50,7 @@ fn parse_links((buffer, ref_map): (String, HashMap)) -> String {
                 let name = caps.name("name").expect("could not get name").to_owned();
                 // Really we should ignore text inside code blocks,
                 // this is a hack to not try to treat `#[derive()]`,
-                // `[profile]`, `[test]`, or `[E\d\d\d\d]` like a link
+                // `[profile]`, `[test]`, or `[E\d\d\d\d]` like a link.
                 if name.starts_with("derive(") ||
                    name.starts_with("profile") ||
                    name.starts_with("test") ||
@@ -71,7 +59,7 @@ fn parse_links((buffer, ref_map): (String, HashMap)) -> String {
                 }
 
                 let val = match caps.name("val") {
-                    // [name](link)
+                    // `[name](link)`
                     Some(value) => value.to_owned(),
                     None => {
                         match caps.name("key") {
@@ -83,7 +71,7 @@ fn parse_links((buffer, ref_map): (String, HashMap)) -> String {
                                     _ => format!("{}", ref_map.get(&key.to_uppercase()).expect(&format!("could not find url for the link text `{}`", key))),
                                 }
                             }
-                            // [name] as reference
+                            // `[name]` as reference
                             None => format!("{}", ref_map.get(&name.to_uppercase()).expect(&format!("could not find url for the link text `{}`", name))),
                         }
                     }
@@ -415,7 +403,4 @@ Some text to show that the reference links can follow later.
             .to_string();
         assert_eq!(parse(source), target);
     }
-
-
-
 }
diff --git a/second-edition/tools/src/bin/remove_links.rs b/second-edition/tools/src/bin/remove_links.rs
index 9add24ec..0ea88639 100644
--- a/second-edition/tools/src/bin/remove_links.rs
+++ b/second-edition/tools/src/bin/remove_links.rs
@@ -1,13 +1,3 @@
-// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0  or the MIT license
-// , at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
 extern crate regex;
 
 use std::io;
@@ -23,31 +13,31 @@ fn main () {
 
     let mut refs = HashSet::new();
 
-    // capture all links and link references
+    // Capture all links and link references.
     let regex = r"\[([^\]]+)\](?:(?:\[([^\]]+)\])|(?:\([^\)]+\)))(?i)";
     let link_regex = Regex::new(regex).unwrap();
     let first_pass = link_regex.replace_all(&buffer, |caps: &Captures| {
 
-        // save the link reference we want to delete
+        // Save the link reference we want to delete.
         if let Some(reference) = caps.at(2) {
             refs.insert(reference.to_owned());
         }
 
-        // put the link title back
+        // Put the link title back.
         caps.at(1).unwrap().to_owned()
     });
 
-    // search for the references we need to delete
+    // Search for the references we need to delete.
     let ref_regex = Regex::new(r"\n\[([^\]]+)\]:\s.*\n").unwrap();
     let out = ref_regex.replace_all(&first_pass, |caps: &Captures| {
         let capture = caps.at(1).unwrap().to_owned();
 
-        // check if we've marked this reference for deletion...
+        // Check if we've marked this reference for deletion ...
         if refs.contains(capture.as_str()) {
             return "".to_string();
         }
 
-        //... else we put back everything we captured
+        // ... else we put back everything we captured.
         caps.at(0).unwrap().to_owned()
     });
 
diff --git a/second-edition/tools/src/bin/remove_markup.rs b/second-edition/tools/src/bin/remove_markup.rs
index c8cbc1c1..be444bfd 100644
--- a/second-edition/tools/src/bin/remove_markup.rs
+++ b/second-edition/tools/src/bin/remove_markup.rs
@@ -1,14 +1,5 @@
-// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0  or the MIT license
-// , at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
 extern crate regex;
+
 use std::io;
 use std::io::{Read, Write};
 use regex::{Regex, Captures};
@@ -31,23 +22,23 @@ fn write_md(output: String) {
 
 fn remove_markup(input: String) -> String {
     let filename_regex = Regex::new(r#"\A(.*)\z"#).unwrap();
-    // Captions sometimes take up multiple lines
+    // Captions sometimes take up multiple lines.
     let caption_start_regex = Regex::new(r#"\A(.*)\z"#).unwrap();
     let caption_end_regex = Regex::new(r#"(.*)\z"#).unwrap();
     let regexen = vec![filename_regex, caption_start_regex, caption_end_regex];
 
     let lines: Vec<_> = input.lines().flat_map(|line| {
-        // Remove our figure and caption markup
+        // Remove our figure and caption markup.
         if line == "
" || line == "
" || line == "
" || line == "
" { None - // Remove our syntax highlighting and rustdoc markers + // Remove our syntax highlighting and rustdoc markers. } else if line.starts_with("```") { Some(String::from("```")) - // Remove the span around filenames and captions + // Remove the span around filenames and captions. } else { let result = regexen.iter().fold(line.to_string(), |result, regex| { regex.replace_all(&result, |caps: &Captures| { diff --git a/tools/src/bin/concat_chapters.rs b/tools/src/bin/concat_chapters.rs index 62b34610..ed992ec9 100644 --- a/tools/src/bin/concat_chapters.rs +++ b/tools/src/bin/concat_chapters.rs @@ -1,13 +1,3 @@ -// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - #[macro_use] extern crate lazy_static; diff --git a/tools/src/bin/convert_quotes.rs b/tools/src/bin/convert_quotes.rs index e302fa14..027d458d 100644 --- a/tools/src/bin/convert_quotes.rs +++ b/tools/src/bin/convert_quotes.rs @@ -1,13 +1,3 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - use std::io; use std::io::{Read, Write}; @@ -39,11 +29,11 @@ fn main() { let mut chars_in_line = line.chars(); while let Some(possible_match) = chars_in_line.next() { - // check if inside inline code + // Check if inside inline code. if possible_match == '`' { is_in_inline_code = !is_in_inline_code; } - // check if inside html tag + // Check if inside HTML tag. if possible_match == '<' && !is_in_inline_code { is_in_html_tag = true; } @@ -51,7 +41,7 @@ fn main() { is_in_html_tag = false; } - // replace with right/left apostrophe/quote + // Replace with right/left apostrophe/quote. let char_to_push = if possible_match == '\'' && !is_in_inline_code && !is_in_html_tag { if (previous_char != std::char::REPLACEMENT_CHARACTER && @@ -72,7 +62,7 @@ fn main() { '“' } } else { - // leave untouched + // Leave untouched. possible_match }; modified_line.push(char_to_push); diff --git a/tools/src/bin/lfp.rs b/tools/src/bin/lfp.rs index 21dc5b13..f475df08 100644 --- a/tools/src/bin/lfp.rs +++ b/tools/src/bin/lfp.rs @@ -1,20 +1,11 @@ -// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - // We have some long regex literals, so: // ignore-tidy-linelength - +extern crate docopt; +extern crate rustc_serialize; +extern crate walkdir; use docopt::Docopt; -use walkdir; use std::{path, fs, io}; use std::io::{BufRead, Write}; diff --git a/tools/src/bin/link2print.rs b/tools/src/bin/link2print.rs index b24ecbdb..c2dcd56f 100644 --- a/tools/src/bin/link2print.rs +++ b/tools/src/bin/link2print.rs @@ -1,15 +1,4 @@ -// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - - -// FIXME: We have some long lines that could be refactored, but it's not a big deal. +// FIXME: we have some long lines that could be refactored, but it's not a big deal. // ignore-tidy-linelength @@ -20,7 +9,6 @@ use std::io::{Read, Write}; use regex::{Regex, Captures}; fn main() { - write_md(parse_links(parse_references(read_md()))); } @@ -38,7 +26,7 @@ fn write_md(output: String) { fn parse_references(buffer: String) -> (String, HashMap) { let mut ref_map = HashMap::new(); - // FIXME: Currently doesn't handle "title" in following line + // FIXME: currently doesn't handle "title" in following line. let re = Regex::new(r###"(?m)\n?^ {0,3}\[([^]]+)\]:[[:blank:]]*(.*)$"###).unwrap(); let output = re.replace_all(&buffer, |caps: &Captures<'_>| { let key = caps.at(1).unwrap().to_owned().to_uppercase(); @@ -52,7 +40,7 @@ fn parse_references(buffer: String) -> (String, HashMap) { } fn parse_links((buffer, ref_map): (String, HashMap)) -> String { - // FIXME: check which punctuation is allowed by spec + // FIXME: check which punctuation is allowed by spec. let re = Regex::new(r###"(?:(?P
(?:```(?:[^`]|`[^`])*`?\n```\n)|(?:[^[]`[^`\n]+[\n]?[^`\n]*`))|(?:\[(?P[^]]+)\](?:(?:\([[:blank:]]*(?P[^")]*[^ ])(?:[[:blank:]]*"[^"]*")?\))|(?:\[(?P[^]]*)\]))?))"###).expect("could not create regex");
     let error_code = Regex::new(r###"^E\d{4}$"###).expect("could not create regex");
     let output = re.replace_all(&buffer, |caps: &Captures<'_>| {
@@ -62,7 +50,7 @@ fn parse_links((buffer, ref_map): (String, HashMap)) -> String {
                 let name = caps.name("name").expect("could not get name").to_owned();
                 // Really we should ignore text inside code blocks,
                 // this is a hack to not try to treat `#[derive()]`,
-                // `[profile]`, `[test]`, or `[E\d\d\d\d]` like a link
+                // `[profile]`, `[test]`, or `[E\d\d\d\d]` like a link.
                 if name.starts_with("derive(") ||
                    name.starts_with("profile") ||
                    name.starts_with("test") ||
@@ -71,19 +59,19 @@ fn parse_links((buffer, ref_map): (String, HashMap)) -> String {
                 }
 
                 let val = match caps.name("val") {
-                    // [name](link)
+                    // `[name](link)`
                     Some(value) => value.to_owned(),
                     None => {
                         match caps.name("key") {
                             Some(key) => {
                                 match key {
-                                    // [name][]
+                                    // `[name][]`
                                     "" => format!("{}", ref_map.get(&name.to_uppercase()).expect(&format!("could not find url for the link text `{}`", name))),
-                                    // [name][reference]
+                                    // `[name][reference]`
                                     _ => format!("{}", ref_map.get(&key.to_uppercase()).expect(&format!("could not find url for the link text `{}`", key))),
                                 }
                             }
-                            // [name] as reference
+                            // `[name]` as reference
                             None => format!("{}", ref_map.get(&name.to_uppercase()).expect(&format!("could not find url for the link text `{}`", name))),
                         }
                     }
@@ -415,7 +403,4 @@ Some text to show that the reference links can follow later.
             .to_string();
         assert_eq!(parse(source), target);
     }
-
-
-
 }
diff --git a/tools/src/bin/remove_links.rs b/tools/src/bin/remove_links.rs
index 9dad4e87..870088cd 100644
--- a/tools/src/bin/remove_links.rs
+++ b/tools/src/bin/remove_links.rs
@@ -1,19 +1,9 @@
-// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0  or the MIT license
-// , at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-
+extern crate regex;
 
+use std::collections::HashSet;
 use std::io;
 use std::io::{Read, Write};
 use regex::{Regex, Captures};
-use std::collections::HashSet;
 
 fn main () {
     let mut buffer = String::new();
@@ -23,31 +13,31 @@ fn main () {
 
     let mut refs = HashSet::new();
 
-    // capture all links and link references
+    // Capture all links and link references.
     let regex = r"\[([^\]]+)\](?:(?:\[([^\]]+)\])|(?:\([^\)]+\)))(?i)";
     let link_regex = Regex::new(regex).unwrap();
     let first_pass = link_regex.replace_all(&buffer, |caps: &Captures<'_>| {
 
-        // save the link reference we want to delete
+        // Save the link reference we want to delete.
         if let Some(reference) = caps.at(2) {
             refs.insert(reference.to_owned());
         }
 
-        // put the link title back
+        // Put the link title back.
         caps.at(1).unwrap().to_owned()
     });
 
-    // search for the references we need to delete
+    // Search for the references we need to delete.
     let ref_regex = Regex::new(r"\n\[([^\]]+)\]:\s.*\n").unwrap();
     let out = ref_regex.replace_all(&first_pass, |caps: &Captures<'_>| {
         let capture = caps.at(1).unwrap().to_owned();
 
-        // check if we've marked this reference for deletion...
+        // Check if we've marked this reference for deletion ...
         if refs.contains(capture.as_str()) {
             return "".to_string();
         }
 
-        //... else we put back everything we captured
+        // ... else we put back everything we captured.
         caps.at(0).unwrap().to_owned()
     });
 
diff --git a/tools/src/bin/remove_markup.rs b/tools/src/bin/remove_markup.rs
index 8e686221..2c285b9a 100644
--- a/tools/src/bin/remove_markup.rs
+++ b/tools/src/bin/remove_markup.rs
@@ -1,13 +1,4 @@
-// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0  or the MIT license
-// , at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
+extern crate regex;
 
 use std::io;
 use std::io::{Read, Write};
@@ -31,23 +22,23 @@ fn write_md(output: String) {
 
 fn remove_markup(input: String) -> String {
     let filename_regex = Regex::new(r#"\A(.*)\z"#).unwrap();
-    // Captions sometimes take up multiple lines
+    // Captions sometimes take up multiple lines.
     let caption_start_regex = Regex::new(r#"\A(.*)\z"#).unwrap();
     let caption_end_regex = Regex::new(r#"(.*)\z"#).unwrap();
     let regexen = vec![filename_regex, caption_start_regex, caption_end_regex];
 
     let lines: Vec<_> = input.lines().flat_map(|line| {
-        // Remove our figure and caption markup
+        // Remove our figure and caption markup.
         if line == "
" || line == "
" || line == "
" || line == "
" { None - // Remove our syntax highlighting and rustdoc markers + // Remove our syntax highlighting and rustdoc markers. } else if line.starts_with("```") { Some(String::from("```")) - // Remove the span around filenames and captions + // Remove the span around filenames and captions. } else { let result = regexen.iter().fold(line.to_string(), |result, regex| { regex.replace_all(&result, |caps: &Captures<'_>| {