--- dclick.cpp.orig	2010-11-10 11:51:32.876000000 +0100
+++ dclick.cpp	2010-11-10 11:57:28.750000000 +0100
@@ -2,11 +2,15 @@
  * by Derek Bruening
  * May 2002
  *
+ * Updated 2010-11-10 by Thomas Perl <thp.io/about>:
+ *  - Make it compile on newer versions of Cygwin
+ *  - Convert "/" to "\" (so "dclick ../test.pdf" works)
+ *
  * equivalent of DOS shell "start" command: launches a file using the
  * shell as though it were double-clicked in explorer
  *
- * to build, must link in shell32.lib:
- * cl /nologo dclick.cpp shell32.lib
+ * To build using Cygwin's gcc, simply use:
+ *    gcc dclick.cpp -o dclick
  */
 /*
  * This program is free software; you can redistribute it and/or modify
@@ -26,7 +30,6 @@
  */
 
 #include <windows.h>
-#include <tchar.h>
 #include <stdio.h>
 #include <assert.h>
 
@@ -46,7 +49,7 @@
     int i;
     int len, left = (argc-1) * MAX_PATH;
     for (i = 2; i < argc; i++) {
-        len = _sntprintf(cur, left, "%s ", argv[i]);
+        len = snprintf(cur, left, "%s ", argv[i]);
         if (len < 0) {
             /* hit max */
             cur += left - 1;
@@ -56,11 +59,16 @@
         left -= len;
         cur += len;
     }
-    *cur = _T('\0');
+    *cur = '\0';
+
+    /* Replace the "/" path separator with "\" (in Cygwin) */
+    for (i=0, cur=argv[1]; cur[i]; i++) {
+        if (cur[i] == '/') cur[i] = '\\';
+    }
 
     fprintf(stderr, "Opening \"%s\" with parameters \"%s\"\n", argv[1], params);
     // tell explorer to "open" the file
-    HINSTANCE res = ShellExecute(NULL, _T("open"), 
+    HINSTANCE res = ShellExecute(NULL, "open", 
                                  argv[1], (LPCTSTR) params, cwd, SW_SHOWNORMAL);
 
     free(params);

