Skip blank lines in format_double_null().
authorIain Patterson <me@iain.cx>
Sat, 1 Mar 2014 12:58:55 +0000 (12:58 +0000)
committerIain Patterson <me@iain.cx>
Sun, 2 Mar 2014 18:22:54 +0000 (18:22 +0000)
Ignore blank lines when formatting, so the user doesn't need to worry
about entering environment variables or dependency names in the exactly
correct format.

registry.cpp

index 1e801ee..2b111c3 100644 (file)
@@ -392,6 +392,27 @@ int unformat_double_null(TCHAR *dn, unsigned long dnlen, TCHAR **unformatted, un
   }\r
 \r
   for (i = 0; i < dnlen; i++) if (dn[i] != _T('\r')) ++*newlen;\r
+\r
+  /* Skip blank lines. */\r
+  for (i = 0; i < dnlen; i++) {\r
+    if (dn[i] == _T('\r') && dn[i + 1] == _T('\n')) {\r
+      /* This is the last CRLF. */\r
+      if (i >= dnlen - 2) break;\r
+\r
+      /*\r
+        Strip at the start of the block or if the next characters are\r
+        CRLF too.\r
+      */\r
+      if (! i || (dn[i + 2] == _T('\r') && dn[i + 3] == _T('\n'))) {\r
+        for (j = i + 2; j < dnlen; j++) dn[j - 2] = dn[j];\r
+        dn[dnlen--] = _T('\0');\r
+        dn[dnlen--] = _T('\0');\r
+        i--;\r
+        --*newlen;\r
+      }\r
+    }\r
+  }\r
+\r
   /* Must end with two NULLs. */\r
   *newlen += 2;\r
 \r