chiark / gitweb /
css: ignore license blobs when postprocessing.
authorVladimír Vondruš <mosra@centrum.cz>
Mon, 23 Oct 2017 07:22:39 +0000 (09:22 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Mon, 23 Oct 2017 07:22:39 +0000 (09:22 +0200)
OTOH, put just a single one explicitly at the start.

css/postprocess.py

index dafcd2529a55d2fd7507e012ed98e340301649c3..555076f946c9ed5e0cbc3fecca939f0a272bcd4b 100755 (executable)
@@ -32,6 +32,8 @@ import_rx = re.compile("^@import url\\('(?P<file>[^']+)'\\);$")
 opening_brace_rx = re.compile("^\\s*:root\s*{\\s*$")
 closing_brace_rx = re.compile("^\\s*}\\s*$")
 comment_rx = re.compile("^\\s*(/\\*.*\\*/)?\\s*$")
+comment_start_rx = re.compile("^\\s*(/\\*.*)\\s*$")
+comment_end_rx = re.compile("^\\s*(.*\\*/)\\s*$")
 variable_declaration_rx = re.compile("^\\s*(?P<key>--[a-z-]+)\\s*:\\s*(?P<value>[^;]+)\\s*;\\s*$")
 variable_use_rx = re.compile("^(?P<before>.+)var\\((?P<key>--[a-z-]+)\\)(?P<after>.+)$")
 
@@ -46,13 +48,45 @@ def postprocess(files):
 
         not_just_variable_declarations = False
 
-        # Put a helper comment on top
-        out.write("/* Generated using `./postprocess.py {}`. Do not edit. */\n".format(' '.join(files)))
+        # Put a helper comment and a license blob on top
+        out.write("""/* Generated using `./postprocess.py {}`. Do not edit. */
+
+/*
+    This file is part of m.css.
+
+    Copyright © 2017 Vladimír Vondruš <mosra@centrum.cz>
+
+    Permission is hereby granted, free of charge, to any person obtaining a
+    copy of this software and associated documentation files (the "Software"),
+    to deal in the Software without restriction, including without limitation
+    the rights to use, copy, modify, merge, publish, distribute, sublicense,
+    and/or sell copies of the Software, and to permit persons to whom the
+    Software is furnished to do so, subject to the following conditions:
+
+    The above copyright notice and this permission notice shall be included
+    in all copies or substantial portions of the Software.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+    THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+    DEALINGS IN THE SOFTWARE.
+*/
+""".format(' '.join(files)))
 
         # Parse the top-level file
         with open(files[0]) as f:
             in_variable_declarations = False
+            in_comment = False
             for line in f:
+                # In comment and the comment is not ending yet, ignore
+                if in_comment:
+                    if comment_end_rx.match(line):
+                        in_comment = False
+                    continue
+
                 # Import statement: add the file at the beginning of th
                 match = import_rx.match(line)
                 if match:
@@ -75,6 +109,11 @@ def postprocess(files):
                 if comment_rx.match(line):
                     continue
 
+                # Comment start line, ignore this and the next lines
+                if comment_start_rx.match(line):
+                    in_comment = True
+                    continue
+
                 # Closing brace of variable declaration block. If it was not
                 # just variable declarations, put the closing brace to the
                 # output as well.
@@ -97,7 +136,14 @@ def postprocess(files):
             out.write('\n')
 
             with open(file) as f:
+                in_comment = False
                 for line in f:
+                    # In comment and the comment is not ending yet, ignore
+                    if in_comment:
+                        if comment_end_rx.match(line):
+                            in_comment = False
+                        continue
+
                     # Variable use, replace with actual value
                     # TODO: more variables on the same line?
                     match = variable_use_rx.match(line)
@@ -112,6 +158,11 @@ def postprocess(files):
                     if comment_rx.match(line):
                         continue
 
+                    # Comment start line, ignore this and the next lines
+                    if comment_start_rx.match(line):
+                        in_comment = True
+                        continue
+
                     # Something else, copy verbatim to the output
                     out.write(line)