Revise the amalgamation tool to allow 'duplicate' include files to be retained manually while still preserving the existing line numbers.

FossilOrigin-Name: aa48284637b954d63bcf77e19b25e75c7ad1a6d3
diff --git a/manifest b/manifest
index c623534..8d15520 100644
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Enhancements\sto\sthe\sWin32\sAPI\sdefinition\smacros.
-D 2013-08-31T17:01:56.739
+C Revise\sthe\samalgamation\stool\sto\sallow\s'duplicate'\sinclude\sfiles\sto\sbe\sretained\smanually\swhile\sstill\spreserving\sthe\sexisting\sline\snumbers.
+D 2013-08-31T18:06:52.923
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -203,7 +203,7 @@
 F src/os.h 4a46270a64e9193af4a0aaa3bc2c66dc07c29b3f
 F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04
 F src/os_unix.c 243fb37f47dc072fc59839ea241ff0a17c8d76e6
-F src/os_win.c 896581ee5a2ad261c3410fc84cfb0639ef2a1d56
+F src/os_win.c bb592dfb850e4ee3e4caecce461dca74dc40936d
 F src/pager.c 2aa4444ffe86e9282d03bc349a4a5e49bd77c0e8
 F src/pager.h f094af9f6ececfaa8a1e93876905a4f34233fb0c
 F src/parse.y 27c6b4138497d6f8360ba7847da6ed48033f957f
@@ -1079,7 +1079,7 @@
 F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e
 F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97
 F tool/mksqlite3c-noext.tcl 8bce31074e4cbe631bb7676526a048335f4c9f02
-F tool/mksqlite3c.tcl d8d51141424a0227aecfd7bd07a92304a946b8b2
+F tool/mksqlite3c.tcl d344cc3144a0271cd853c5e3df36e9f31d78d619
 F tool/mksqlite3h.tcl ba24038056f51fde07c0079c41885ab85e2cff12
 F tool/mksqlite3internalh.tcl 3dca7bb5374cee003379b8cbac73714f610ef795
 F tool/mkvsix.tcl 0be7f7a591f1e83f9199cb82911b66668ca484c9
@@ -1109,7 +1109,7 @@
 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae
 F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
-P 2fca6d784b000fd3a4d6890e38a0b087767f3a7f
-R 81d5e6e46adbe46f943b02ea53b00aff
+P b1811baab6e35ecb1ba920a7ed3302997758d309
+R c09e9aaa82ece462d9ada3bc7aee07de
 U mistachkin
-Z 8550f042a6eaddfa936a0e87c6856786
+Z 9761d739f96263a417653d62e6565ea2
diff --git a/manifest.uuid b/manifest.uuid
index 64c97df..f86d289 100644
--- a/manifest.uuid
+++ b/manifest.uuid
@@ -1 +1 @@
-b1811baab6e35ecb1ba920a7ed3302997758d309
\ No newline at end of file
+aa48284637b954d63bcf77e19b25e75c7ad1a6d3
\ No newline at end of file
diff --git a/src/os_win.c b/src/os_win.c
index 34b5834..72d6e8b 100644
--- a/src/os_win.c
+++ b/src/os_win.c
@@ -17,7 +17,7 @@
 
 #ifdef __CYGWIN__
 # include <sys/cygwin.h>
-# include <errno.h>
+# include <errno.h> /* amalgamator: keep */
 #endif
 
 /*
@@ -4020,6 +4020,7 @@
        "/var/tmp",
        "/usr/tmp",
        "/tmp",
+       ".",
        0        /* List terminator */
     };
     unsigned int i;
diff --git a/tool/mksqlite3c.tcl b/tool/mksqlite3c.tcl
index 8826f25..343f606 100644
--- a/tool/mksqlite3c.tcl
+++ b/tool/mksqlite3c.tcl
@@ -140,7 +140,7 @@
 # process them appropriately.
 #
 proc copy_file {filename} {
-  global available_hdr out addstatic linemacros
+  global seen_hdr available_hdr out addstatic linemacros
   set ln 0
   set tail [file tail $filename]
   section_comment "Begin file $tail"
@@ -166,12 +166,17 @@
           section_comment "Continuing where we left off in $tail"
           if {$linemacros} {puts $out "#line [expr {$ln+1}] \"$filename\""}
         }
-      } else {
-        set suffix [string toupper [string map [list / _ . _] $hdr]]
-        puts $out "#ifndef SQLITE_HEADER_$suffix"
-        puts $out "#define SQLITE_HEADER_$suffix"
+      } elseif {![info exists seen_hdr($hdr)]} {
+        set seen_hdr($hdr) 1
         puts $out $line
-        puts $out "#endif"
+      } elseif {[regexp {/\*\s+amalgamator:\s+keep\s+\*/} $line]} {
+        # This include file must be kept because there was a "keep"
+        # directive inside of a line comment.
+        puts $out $line
+      } else {
+        # Comment out the entire line, replacing any nested comment
+        # begin/end markers with the harmless substring "**".
+        puts $out "/* [string map [list /* ** */ **] $line] */"
       }
     } elseif {[regexp {^#ifdef __cplusplus} $line]} {
       puts $out "#if 0"