[build-path-prefix-map-spec] 29/50: Tidy up language examples, including whitespace

Ximin Luo infinity0 at debian.org
Fri Mar 10 15:17:21 UTC 2017


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch master
in repository build-path-prefix-map-spec.

commit b99d1aa65042e85bc31a7cdccfbb70dc7f3ecb51
Author: Ximin Luo <infinity0 at debian.org>
Date:   Mon Feb 13 17:13:47 2017 +0100

    Tidy up language examples, including whitespace
---
 consume/pecsplit.c   |  4 ++--
 consume/pecsplit.js  | 39 +++++++++++++++++++++++----------------
 consume/pecsplit.py  | 28 +++++++++++++++-------------
 consume/pecsplit.rs  |  8 +++++++-
 consume/prefix_map.h |  3 ++-
 5 files changed, 49 insertions(+), 33 deletions(-)

diff --git a/consume/pecsplit.c b/consume/pecsplit.c
index bc4d955..ede8ece 100644
--- a/consume/pecsplit.c
+++ b/consume/pecsplit.c
@@ -1,7 +1,7 @@
 #include "prefix_map.h"
 
-/* Parsing the variable. */
-/* For Applying the variable, see prefix_map.h. */
+/** Parsing the variable. */
+/* For Applying the variable, and Main program, see prefix_map.h. */
 
 int
 unquote (char *src)
diff --git a/consume/pecsplit.js b/consume/pecsplit.js
index d22f22a..aa659aa 100755
--- a/consume/pecsplit.js
+++ b/consume/pecsplit.js
@@ -1,32 +1,39 @@
 #!/usr/bin/nodejs
 
+// Parsing the variable
+
 var unquote = function(x) {
-    if (x.search(/%[^pec]|%$/) >= 0) throw "invalid value: bad escape: " + x;
-    return x.replace(/%c/g, ':').replace(/%e/g, '=').replace(/%p/g, '%');
+  if (x.search(/%[^pec]|%$/) >= 0)
+    throw "invalid value: bad escape: " + x;
+  return x.replace(/%c/g, ':').replace(/%e/g, '=').replace(/%p/g, '%');
 };
 
 var parse_prefix_map = function(x) {
-    return (x || "").split(/:/g).filter(Boolean).map(function(part) {
-        var tuples = part.split(/=/g).map(unquote);
-        if (tuples.length !== 2) throw "invalid value: not a pair: " + pair;
-        return tuples;
-    });
+  return (x || "").split(/:/g).filter(Boolean).map(function(part) {
+    var tuples = part.split(/=/g).map(unquote);
+    if (tuples.length !== 2)
+      throw "invalid value: not a pair: " + pair;
+    return tuples;
+  });
 };
 
+// Applying the variable
+
 var map_prefix = function(string, pm) {
-    for (var i = pm.length - 1; i >= 0; --i) {;
-        var src = pm[i][0];
-        var dst = pm[i][1];
-        if (string.indexOf(src) === 0) {
-            return dst + string.substr(src.length);
-        }
+  for (var i = pm.length - 1; i >= 0; --i) {;
+    var src = pm[i][0];
+    var dst = pm[i][1];
+    if (string.indexOf(src) === 0) {
+      return dst + string.substr(src.length);
     }
-    return string;
+  }
+  return string;
 };
 
-var pm = parse_prefix_map(process.env["BUILD_PATH_PREFIX_MAP"]);
+// Main program
 
+var pm = parse_prefix_map(process.env["BUILD_PATH_PREFIX_MAP"]);
 // var i = 2 is just how nodejs yolos its way through common conventions
 for (var i = 2, l = process.argv.length; i < l; ++i) {
-    console.log(map_prefix(process.argv[i], pm));
+  console.log(map_prefix(process.argv[i], pm));
 }
diff --git a/consume/pecsplit.py b/consume/pecsplit.py
index b04a79d..c9a1f1a 100755
--- a/consume/pecsplit.py
+++ b/consume/pecsplit.py
@@ -7,24 +7,26 @@ import sys
 # Parsing the variable
 
 def _dequote(part):
-    if re.search(r"%[^pec]|%$", part): raise ValueError("bad escape: %s" % part)
-    return part.replace("%c", ':').replace("%e", '=').replace("%p", '%');
+  if re.search(r"%[^pec]|%$", part):
+    raise ValueError("bad escape: %s" % part)
+  return part.replace("%c", ':').replace("%e", '=').replace("%p", '%');
 
 def decode(prefix_str):
-    tuples = (part.split("=") for part in prefix_str.split(":") if part)
-    # Will raise if any tuple can't be destructured into a pair
-    return [(_dequote(src), _dequote(dst)) for src, dst in tuples]
-
-pm = decode(os.getenv("BUILD_PATH_PREFIX_MAP", ""))
+  tuples = (part.split("=") for part in prefix_str.split(":") if part)
+  # Will raise if any tuple can't be destructured into a pair
+  return [(_dequote(src), _dequote(dst)) for src, dst in tuples]
 
 # Applying the variable
 
 def map_prefix(string, pm):
-    for src, dst in reversed(pm):
-        if string.startswith(src):
-            return dst + string[len(src):]
-    return string
+  for src, dst in reversed(pm):
+    if string.startswith(src):
+      return dst + string[len(src):]
+  return string
 
+# Main program
+
+pm = decode(os.getenv("BUILD_PATH_PREFIX_MAP", ""))
 for v in sys.argv[1:]:
-    # print() tries to auto-encode its args without surrogateescape
-    sys.stdout.buffer.write(map_prefix(v, pm).encode("utf-8", errors="surrogateescape") + b"\n")
+  # print() tries to auto-encode its args without surrogateescape
+  sys.stdout.buffer.write(map_prefix(v, pm).encode("utf-8", errors="surrogateescape") + b"\n")
diff --git a/consume/pecsplit.rs b/consume/pecsplit.rs
index 82da677..633c4d6 100644
--- a/consume/pecsplit.rs
+++ b/consume/pecsplit.rs
@@ -8,6 +8,8 @@ fn pathbuf_to_u8(path: &PathBuf) -> &[u8] {
   path.as_os_str().as_bytes() // TODO: windows
 }
 
+/** Parsing the variable */
+
 /* the polymorphism is to handle u8 (POSIX) and u16 (windows) */
 fn dequote<T>(s: &[T]) -> Result<Vec<T>, &'static str> where u16: From<T>, T: From<u8>, T: Copy {
   // unfortunately we can't do sting-replace on arbitrary Vecs
@@ -60,12 +62,14 @@ fn decode(prefix_str: Option<OsString>) -> Result<Vec<(PathBuf, PathBuf)>, &'sta
     .collect::<Result<Vec<_>, _>>()
 }
 
+/** Applying the variable */
+
 fn map_prefix(path: PathBuf, pm: &Vec<(PathBuf, PathBuf)>) -> PathBuf {
   for pair in pm.iter().rev() {
     let (ref src, ref dst) = *pair;
     if path.starts_with(src) {
       /* FIXME: this is different from what our other language examples do;
-       * rust's PathBuf.starts_with only matches whole components. however
+       * rust's [PathBuf.starts_with] only matches whole components. however
        * these all behave the same for our test cases.
        */
       return dst.join(path.strip_prefix(src).unwrap())
@@ -74,6 +78,8 @@ fn map_prefix(path: PathBuf, pm: &Vec<(PathBuf, PathBuf)>) -> PathBuf {
   path
 }
 
+/** Main program */
+
 fn main() {
   use std::env;
   use std::io::{Write, stdout, stderr};
diff --git a/consume/prefix_map.h b/consume/prefix_map.h
index a7ad036..1149189 100644
--- a/consume/prefix_map.h
+++ b/consume/prefix_map.h
@@ -17,7 +17,7 @@ xstrdup (const char *s)
   return (char *) memcpy (ret, s, len);
 }
 
-/* Rest of it, including Applying the variable */
+/** Applying the variable */
 
 struct prefix_map
 {
@@ -152,6 +152,7 @@ remap_prefix (const char *filename, struct prefix_maps *maps)
   return remap_prefix_alloc (filename, maps, malloc);
 }
 
+/** Main program */
 
 #include <stdlib.h>
 #include <stdio.h>

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/build-path-prefix-map-spec.git



More information about the Reproducible-commits mailing list