Tcl channel driver for a FTDI D2XX device. core-1-0-0
authorPat Thoyts <patthoyts@users.sourceforge.net>
Sat, 15 Mar 2008 02:59:05 +0000 (02:59 +0000)
committerPat Thoyts <patthoyts@users.sourceforge.net>
Sat, 15 Mar 2008 02:59:05 +0000 (02:59 +0000)
README [new file with mode: 0644]
license.terms [new file with mode: 0644]
makefile.vc [new file with mode: 0644]
nmakehlp.c [new file with mode: 0644]
rules.vc [new file with mode: 0644]
tclftd2xx.c [new file with mode: 0644]
tclftd2xx.rc [new file with mode: 0644]

diff --git a/README b/README
new file mode 100644 (file)
index 0000000..e3c233c
--- /dev/null
+++ b/README
@@ -0,0 +1,64 @@
+README                                                            -*- text -*-
+
+ftd2xx - a Tcl interface to the FTDI D2XX USB device library
+
+This package provides a Tcl interface to the Future Technology Devices
+International Ltd. D2XX driver library. This is a commonly used USB
+device driver. See http://www.ftdichip.com/ for more details about
+their products and the drivers themselves.
+
+This package is in no way affiliated with Future Tchnology Devices
+International Ltd.
+
+The package provides some access to the general commands exposed by
+the D2XX library and in particular provides a Tcl channel interface to
+the device over which you can send and receive data. The channel acts
+as a standard Tcl channel and supports fileevents and asynchonous
+reading (non-blocking). Via the fconfigure command some of the device
+settings can be read and controlled - these include the timeouts and
+latency values along with buffersize and blocking mode.
+
+FTDI provide a Linux driver for these devices and whilst this has not
+been tested there is no intrinsic reason why this package should not
+work fine as a Linux package with a small amount of porting.
+
+
+COMMANDS
+
+ftd2xx open ?-serial? ?-description? ?-location? name
+
+  open the named device and create a channel for it. The driver
+  supports naming devices using one of the serial number, a
+  descriptive device name or on windows a location (port number).
+
+ftd2xx list
+
+  list all the supported devices currently connected. Each list
+  element is itself a name-value list providing all the information
+  available on the device including the serial number, localtion,
+  description, device id, device handle and status.
+
+ftd2xx reset channel
+
+  this command resets the device identified by the given channel.
+  It is likely that after this call the channel will need to be
+  closed and the device re-opened. (untested)
+
+ftd2xx purge channel
+
+  purge the device buffers for the device identified by the channel
+
+INSTALLATION
+
+The FTDI D2XX driver package should be downloaded from the web-site
+(http://www.ftdichip.com/Drivers/D2XX.htm) and the Makefile.vc
+modified such that FTDI_INCLUDE points to the directory containing the
+ftdi2xx.h header and FTDI_LIB points to the directory containing the
+library files.
+
+Using MSVC (6 to 9) do:
+ nmake -f Makefile.vc TCLDIR=c:\Tcl
+ nmake -f Makefile.vc TCLDIR=c:\Tcl install
+
+If the ftd2xx.dll is not installed already, it should be manually
+copied to the installation folder (eg: c:\tcl\lib\tclftd2xx)
diff --git a/license.terms b/license.terms
new file mode 100644 (file)
index 0000000..4bda16e
--- /dev/null
@@ -0,0 +1,24 @@
+LICENSE ("MIT-style")
+
+This software is Copyright (C) 2003 Joe English and other parties.
+
+The following terms apply to all files associated with this software
+unless explicitly disclaimed in individual files.  
+
+The author(s) hereby grant permission to use, copy, modify, distribute,
+and license this software and its documentation for any purpose, provided
+that existing copyright notices are retained in all copies and that this
+notice is included in any distributions. No written agreement,
+license, or royalty fee is required for any of the authorized uses.
+Modifications to this software may be copyrighted by their authors
+and need not follow the licensing terms described here, provided that
+the new terms are clearly indicated on the first page of each file where
+they apply.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS for a PARTICULAR PURPOSE.  IN NO EVENT
+shall the AUTHORS of THIS SOFTWARE be LIABLE to ANY PARTY for
+DIRECT, INDIRECT, SPECIAL, INCIDENTAL, or CONSEQUENTIAL DAMAGES
+arising out of the USE of THIS SOFTWARE and its DOCUMENTATION.
+
diff --git a/makefile.vc b/makefile.vc
new file mode 100644 (file)
index 0000000..19a81bc
--- /dev/null
@@ -0,0 +1,469 @@
+# makefile.vc --                                               -*- Makefile -*-
+#
+# Microsoft Visual C++ makefile for use with nmake.exe v1.62+ (VC++ 5.0+)
+#
+# This makefile is based upon the Tcl 8.4 Makefile.vc and modified to 
+# make it suitable as a general package makefile. Look for the word EDIT
+# which marks sections that may need modification. As a minumum you will
+# need to change the PROJECT, DOTVERSION and DLLOBJS variables to values
+# relevant to your package.
+#
+# See the file "license.terms" for information on usage and redistribution
+# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+# 
+# Copyright (c) 1995-1996 Sun Microsystems, Inc.
+# Copyright (c) 1998-2000 Ajuba Solutions.
+# Copyright (c) 2001 ActiveState Corporation.
+# Copyright (c) 2001-2002 David Gravereaux.
+# Copyright (c) 2003-2006 Pat Thoyts
+#
+#-------------------------------------------------------------------------
+# RCS: @(#)$Id$
+#-------------------------------------------------------------------------
+
+# Check to see we are configured to build with MSVC (MSDEVDIR or MSVCDIR)
+# or with the MS Platform SDK (MSSDK). Visual Studio .NET 2003 and 2005 define
+# VCINSTALLDIR instead. The MSVC Toolkit release defines yet another.
+!if !defined(MSDEVDIR) && !defined(MSVCDIR) && !defined(MSSDK) && !defined(VCINSTALLDIR) && !defined(VCToolkitInstallDir)
+MSG = ^
+You need to run vcvars32.bat from Developer Studio or setenv.bat from the^
+Platform SDK first to setup the environment.  Jump to this line to read^
+the build instructions.
+!error $(MSG)
+!endif
+
+#------------------------------------------------------------------------------
+# HOW TO USE this makefile:
+#
+# 1)  It is now necessary to have %MSVCDir% set in the environment.  This is
+#     used  as a check to see if vcvars32.bat had been run prior to running
+#     nmake or during the installation of Microsoft Visual C++, MSVCDir had
+#     been set globally and the PATH adjusted.  Either way is valid.
+#
+#     You'll need to run vcvars32.bat contained in the MsDev's vc(98)/bin
+#     directory to setup the proper environment, if needed, for your current
+#     setup.  This is a needed bootstrap requirement and allows the swapping of
+#     different environments to be easier.
+#
+# 2)  To use the Platform SDK (not expressly needed), run setenv.bat after
+#     vcvars32.bat according to the instructions for it.  This can also turn on
+#     the 64-bit compiler, if your SDK has it.
+#
+# 3)  Targets are:
+#      all       -- Builds everything.
+#       <project> -- Builds the project (eg: nmake sample)
+#      test      -- Builds and runs the test suite.
+#      install   -- Installs the built binaries and libraries to $(INSTALLDIR)
+#                   in an appropriate subdirectory.
+#      clean/realclean/distclean -- varying levels of cleaning.
+#
+# 4)  Macros usable on the commandline:
+#      INSTALLDIR=<path>
+#              Sets where to install Tcl from the built binaries.
+#              C:\Progra~1\Tcl is assumed when not specified.
+#
+#      OPTS=static,msvcrt,staticpkg,threads,symbols,profile,loimpact,none
+#              Sets special options for the core.  The default is for none.
+#              Any combination of the above may be used (comma separated).
+#              'none' will over-ride everything to nothing.
+#
+#              static  =  Builds a static library of the core instead of a
+#                         dll.  The shell will be static (and large), as well.
+#              msvcrt  =  Effects the static option only to switch it from
+#                         using libcmt(d) as the C runtime [by default] to
+#                         msvcrt(d). This is useful for static embedding
+#                         support.
+#              staticpkg = Effects the static option only to switch
+#                         tclshXX.exe to have the dde and reg extension linked
+#                         inside it.
+#              nothreads = Turns off multithreading support (not recommended)
+#              thrdalloc = Use the thread allocator (shared global free pool).
+#              symbols =  Adds symbols for step debugging.
+#              profile =  Adds profiling hooks.  Map file is assumed.
+#              loimpact =  Adds a flag for how NT treats the heap to keep memory
+#                         in use, low.  This is said to impact alloc performance.
+#
+#      STATS=memdbg,compdbg,none
+#              Sets optional memory and bytecode compiler debugging code added
+#              to the core.  The default is for none.  Any combination of the
+#              above may be used (comma separated).  'none' will over-ride
+#              everything to nothing.
+#
+#              memdbg   = Enables the debugging memory allocator.
+#              compdbg  = Enables byte compilation logging.
+#
+#      MACHINE=(IX86|IA64|ALPHA|AMD64)
+#              Set the machine type used for the compiler, linker, and
+#              resource compiler.  This hook is needed to tell the tools
+#              when alternate platforms are requested.  IX86 is the default
+#              when not specified. If the CPU environment variable has been
+#              set (ie: recent Platform SDK) then MACHINE is set from CPU.
+#
+#      TMP_DIR=<path>
+#      OUT_DIR=<path>
+#              Hooks to allow the intermediate and output directories to be
+#              changed.  $(OUT_DIR) is assumed to be 
+#              $(BINROOT)\(Release|Debug) based on if symbols are requested.
+#              $(TMP_DIR) will de $(OUT_DIR)\<buildtype> by default.
+#
+#      TESTPAT=<file>
+#              Reads the tests requested to be run from this file.
+#
+#      CFG_ENCODING=encoding
+#              name of encoding for configuration information. Defaults
+#              to cp1252
+#
+# 5)  Examples:
+#
+#      Basic syntax of calling nmake looks like this:
+#      nmake [-nologo] -f makefile.vc [target|macrodef [target|macrodef] [...]]
+#
+#                        Standard (no frills)
+#       c:\tcl_src\win\>c:\progra~1\micros~1\vc98\bin\vcvars32.bat
+#       Setting environment for using Microsoft Visual C++ tools.
+#       c:\tcl_src\win\>nmake -f makefile.vc all
+#       c:\tcl_src\win\>nmake -f makefile.vc install INSTALLDIR=c:\progra~1\tcl
+#
+#                         Building for Win64
+#       c:\tcl_src\win\>c:\progra~1\micros~1\vc98\bin\vcvars32.bat
+#       Setting environment for using Microsoft Visual C++ tools.
+#       c:\tcl_src\win\>c:\progra~1\platfo~1\setenv.bat /pre64 /RETAIL
+#       Targeting Windows pre64 RETAIL
+#       c:\tcl_src\win\>nmake -f makefile.vc MACHINE=IA64
+#
+#------------------------------------------------------------------------------
+#==============================================================================
+###############################################################################
+#------------------------------------------------------------------------------
+
+!if !exist("makefile.vc")
+MSG = ^
+You must run this makefile only from the directory it is in.^
+Please `cd` to its location first.
+!error $(MSG)
+!endif
+
+#-------------------------------------------------------------------------
+# Project specific information (EDIT)
+#
+# You should edit this with the name and version of your project. This
+# information is used to generate the name of the package library and
+# it's install location.
+#
+# For example, the sample extension is  going to build sample04.dll and
+# would install it into $(INSTALLDIR)\lib\sample04
+#
+# You need to specify the object files that need to be linked into your
+# binary here.
+#
+#-------------------------------------------------------------------------
+
+PROJECT = tclftd2xx
+
+# Uncomment the following line if this is a Tk extension.
+#PROJECT_REQUIRES_TK=1
+!include "rules.vc"
+
+DOTVERSION      = 1.0.0
+VERSION         = $(DOTVERSION:.=)
+STUBPREFIX      = $(PROJECT)stub
+
+DLLOBJS = \
+       $(TMP_DIR)\tclftd2xx.obj \
+!if !$(STATIC_BUILD)
+       $(TMP_DIR)\tclftd2xx.res
+!endif
+
+# We need the location of the FTDI header and library files.
+FTDI_INCLUDES =-ID2XX\WHQL
+!if "$(MACHINE)" == "AMD64"
+FTDI_LIBS     =-libpath:D2XX\WHQL\amd64
+!else
+FTDI_LIBS     =-libpath:D2XX\WHQL\i386
+!endif
+
+#-------------------------------------------------------------------------
+# Target names and paths ( shouldn't need changing )
+#-------------------------------------------------------------------------
+
+BINROOT                = .
+ROOT            = .
+
+PRJIMPLIB      = $(OUT_DIR)\$(PROJECT)$(SUFX).lib
+PRJLIBNAME     = $(PROJECT)$(SUFX).$(EXT)
+PRJLIB         = $(OUT_DIR)\$(PRJLIBNAME)
+
+PRJSTUBLIBNAME = $(STUBPREFIX).lib
+PRJSTUBLIB     = $(OUT_DIR)\$(PRJSTUBLIBNAME)
+
+### Make sure we use backslash only.
+PRJ_INSTALL_DIR         = $(_INSTALLDIR)\$(PROJECT)$(DOTVERSION)
+LIB_INSTALL_DIR                = $(PRJ_INSTALL_DIR)
+BIN_INSTALL_DIR                = $(PRJ_INSTALL_DIR)
+DOC_INSTALL_DIR                = $(PRJ_INSTALL_DIR)
+SCRIPT_INSTALL_DIR     = $(PRJ_INSTALL_DIR)
+INCLUDE_INSTALL_DIR    = $(_TCLDIR)\include
+
+### The following paths CANNOT have spaces in them.
+GENERICDIR     = $(ROOT)\generic
+WINDIR         = $(ROOT)
+LIBDIR          = $(ROOT)\library
+DOCDIR         = $(ROOT)\doc
+TOOLSDIR       = $(ROOT)\tools
+COMPATDIR      = $(ROOT)\compat
+
+#---------------------------------------------------------------------
+# Compile flags
+#---------------------------------------------------------------------
+
+!if !$(DEBUG)
+!if $(OPTIMIZING)
+### This cranks the optimization level to maximize speed
+cdebug = $(OPTIMIZATIONS)
+!else
+cdebug =
+!endif
+!else if "$(MACHINE)" == "IA64" || "$(MACHINE)" == "AMD64"
+### Warnings are too many, can't support warnings into errors.
+cdebug = -Zi -Od $(DEBUGFLAGS)
+!else
+cdebug = -Zi -WX $(DEBUGFLAGS)
+!endif
+
+### Declarations common to all compiler options
+cwarn = $(WARNINGS) -D _CRT_SECURE_NO_DEPRECATE -D _CRT_NONSTDC_NO_DEPRECATE
+cflags = -nologo -c $(COMPILERFLAGS) $(cwarn) -Fp$(TMP_DIR)^\
+
+!if $(MSVCRT)
+!if $(DEBUG) && !$(UNCHECKED)
+crt = -MDd
+!else
+crt = -MD
+!endif
+!else
+!if $(DEBUG) && !$(UNCHECKED)
+crt = -MTd
+!else
+crt = -MT
+!endif
+!endif
+
+!if !$(STATIC_BUILD)
+cflags = $(cflags) -DUSE_TCL_STUBS
+!if defined(TKSTUBLIB)
+cflags = $(cflags) -DUSE_TK_STUBS
+!endif
+!endif
+
+INCLUDES       = $(TCL_INCLUDES) -I"$(WINDIR)" -I"$(GENERICDIR)" $(FTDI_INCLUDES)
+BASE_CFLAGS    = $(cflags) $(cdebug) $(crt) $(INCLUDES)
+CON_CFLAGS     = $(cflags) $(cdebug) $(crt) -DCONSOLE
+TCL_CFLAGS     = -DPACKAGE_NAME="\"$(PROJECT)\"" \
+                 -DPACKAGE_VERSION="\"$(DOTVERSION)\"" \
+                 -DBUILD_$(PROJECT) \
+                 $(BASE_CFLAGS) $(OPTDEFINES)
+
+#---------------------------------------------------------------------
+# Link flags
+#---------------------------------------------------------------------
+
+!if $(DEBUG)
+ldebug = -debug:full -debugtype:cv
+!if $(MSVCRT)
+ldebug = $(ldebug) -nodefaultlib:msvcrt
+!endif
+!else
+ldebug = -release -opt:ref -opt:icf,3
+!endif
+
+### Declarations common to all linker options
+lflags = -nologo -machine:$(MACHINE) $(LINKERFLAGS) $(ldebug)
+
+!if $(PROFILE)
+lflags = $(lflags) -profile
+!endif
+
+!if $(ALIGN98_HACK) && !$(STATIC_BUILD)
+### Align sections for PE size savings.
+lflags = $(lflags) -opt:nowin98
+!else if !$(ALIGN98_HACK) && $(STATIC_BUILD)
+### Align sections for speed in loading by choosing the virtual page size.
+lflags = $(lflags) -align:4096
+!endif
+
+!if $(LOIMPACT)
+lflags = $(lflags) -ws:aggressive
+!endif
+
+dlllflags = $(lflags) -dll
+conlflags = $(lflags) -subsystem:console
+guilflags = $(lflags) -subsystem:windows
+!if !$(STATIC_BUILD)
+baselibs  = $(TCLSTUBLIB)
+!if defined(TKSTUBLIB)
+baselibs  = $(baselibs) $(TKSTUBLIB)
+!endif
+!endif
+
+# Avoid 'unresolved external symbol __security_cookie' errors.
+# c.f. http://support.microsoft.com/?id=894573
+!if "$(MACHINE)" == "IA64" || "$(MACHINE)" == "AMD64"
+!if $(VCVERSION) >= 1400 && $(VCVERSION) < 1500
+baselibs   = $(baselibs) bufferoverflowU.lib
+!endif
+!endif
+
+baselibs   = $(baselibs) $(FTDI_LIBS)
+
+#---------------------------------------------------------------------
+# TclTest flags
+#---------------------------------------------------------------------
+
+!IF "$(TESTPAT)" != ""
+TESTFLAGS = $(TESTFLAGS) -file $(TESTPAT)
+!ENDIF
+
+#---------------------------------------------------------------------
+# Project specific targets (EDIT)
+#---------------------------------------------------------------------
+
+all:       setup $(PROJECT)
+$(PROJECT): setup $(OUT_DIR)\pkgIndex.tcl $(PRJLIB)
+install:    install-binaries install-libraries install-docs
+
+test: setup $(PROJECT)
+       @set TCL_LIBRARY=$(TCL_LIBRARY:\=/)
+       @set TCLLIBPATH=$(OUT_DIR:\=/)
+!if $(TCLINSTALL)
+       @set PATH=$(_TCLDIR)\bin;$(PATH)
+!else
+       @set PATH=$(_TCLDIR)\win\$(BUILDDIRTOP);$(PATH)
+!endif
+!if "$(OS)" == "Windows_NT"  || "$(MSVCDIR)" == "IDE"
+       $(DEBUGGER) $(TCLSH) "$(ROOT)/tests/all.tcl" $(TESTFLAGS)
+!else
+       @echo Please wait while the tests are collected...
+       $(TCLSH) "$(ROOT)/tests/all.tcl" $(TESTFLAGS) > tests.log
+       type tests.log | more
+!endif
+
+shell: setup $(PROJECT)
+       @set TCL_LIBRARY=$(TCL_LIBRARY:\=/)
+       @set TCLLIBPATH=$(OUT_DIR:\=/)
+!if $(TCLINSTALL)
+       @set PATH=$(_TCLDIR)\bin;$(PATH)
+!else
+       @set PATH=$(_TCLDIR)\win\$(BUILDDIRTOP);$(PATH)
+!endif
+       $(DEBUGGER) $(TCLSH)
+
+setup:
+       @if not exist $(OUT_DIR)\nul mkdir $(OUT_DIR)
+       @if not exist $(TMP_DIR)\nul mkdir $(TMP_DIR)
+
+$(PRJLIB): $(DLLOBJS)
+!if $(STATIC_BUILD)
+       $(lib32) -nologo -out:$@ @<<
+$**
+<<
+!else
+       $(link32) $(dlllflags) -base:0x1EA00000 -out:$@ $(baselibs) @<<
+$**
+<<
+       $(_VC_MANIFEST_EMBED_DLL)
+       -@del $*.exp
+!endif
+
+$(PRJSTUBLIB): $(PRJSTUBOBJS)
+       $(lib32) -nologo -out:$@ $(PRJSTUBOBJS)
+
+#---------------------------------------------------------------------
+# Implicit rules
+#---------------------------------------------------------------------
+
+{$(WINDIR)}.c{$(TMP_DIR)}.obj::
+    $(cc32) $(TCL_CFLAGS) -DBUILD_$(PROJECT) -Fo$(TMP_DIR)\ @<<
+$<
+<<
+
+{$(GENERICDIR)}.c{$(TMP_DIR)}.obj::
+    $(cc32) $(TCL_CFLAGS) -DBUILD_$(PROJECT) -Fo$(TMP_DIR)\ @<<
+$<
+<<
+
+{$(COMPATDIR)}.c{$(TMP_DIR)}.obj::
+    $(cc32) $(TCL_CFLAGS) -DBUILD_$(PROJECT) -Fo$(TMP_DIR)\ @<<
+$<
+<<
+
+{$(WINDIR)}.rc{$(TMP_DIR)}.res:
+       $(rc32) -fo $@ -r -i "$(GENERICDIR)" -D__WIN32__ \
+               -DCOMMAVERSION=$(DOTVERSION:.=,),0 \
+               -DDOTVERSION=\"$(DOTVERSION)\" \
+               -DVERSION=\"$(VERSION)$(SUFX)\" \
+!if $(DEBUG)
+       -d DEBUG \
+!endif
+!if $(TCL_THREADS)
+       -d TCL_THREADS \
+!endif
+!if $(STATIC_BUILD)
+       -d STATIC_BUILD \
+!endif
+       $<
+
+.SUFFIXES:
+.SUFFIXES:.c .rc
+
+#-------------------------------------------------------------------------
+# Explicit dependency rules
+#
+#-------------------------------------------------------------------------
+
+.PHONY: $(OUT_DIR)\pkgIndex.tcl
+
+$(OUT_DIR)\pkgIndex.tcl: 
+       @type << > $@
+package ifneeded ftd2xx $(DOTVERSION) [list load [file join $$dir $(PRJLIBNAME)] Ftd2xx]
+<<
+
+#---------------------------------------------------------------------
+# Installation. (EDIT)
+#
+# You may need to modify this section to reflect the final distribution
+# of your files and possibly to generate documentation.
+#
+#---------------------------------------------------------------------
+
+install-binaries:
+       @echo Installing binaries to '$(SCRIPT_INSTALL_DIR)'
+       @if not exist "$(SCRIPT_INSTALL_DIR)\" mkdir "$(SCRIPT_INSTALL_DIR)" #"
+       @$(CPY) $(PRJLIB) "$(SCRIPT_INSTALL_DIR)" > NUL
+
+install-libraries:
+       @echo Installing libraries to '$(SCRIPT_INSTALL_DIR)'
+       @if exist $(LIBDIR)\nul $(CPY) $(LIBDIR)\*.tcl "$(SCRIPT_INSTALL_DIR)" >NUL
+       @echo Installing package index in '$(SCRIPT_INSTALL_DIR)'
+       @$(CPY) $(OUT_DIR)\pkgIndex.tcl "$(SCRIPT_INSTALL_DIR)"
+
+install-docs:
+       @echo Installing documentation files to '$(DOC_INSTALL_DIR)'
+       @if exist $(DOCDIR) $(CPY) $(DOCDIR)\*.n "$(DOC_INSTALL_DIR)"
+
+#---------------------------------------------------------------------
+# Clean up
+#---------------------------------------------------------------------
+
+clean:
+       @if exist $(TMP_DIR)\nul $(RMDIR) $(TMP_DIR)
+       @if exist $(WINDIR)\version.vc del $(WINDIR)\version.vc
+       @if exist $(WINDIR)\vercl.i del $(WINDIR)\vercl.i
+       @if exist $(WINDIR)\vercl.x del $(WINDIR)\vercl.x
+       @if exist $(WINDIR)\_junk.pch del $(WINDIR)\_junk.pch
+
+realclean: clean
+       @if exist $(OUT_DIR)\nul $(RMDIR) $(OUT_DIR)
+
+distclean: realclean
+       @if exist $(WINDIR)\nmakehlp.exe del $(WINDIR)\nmakehlp.exe
+       @if exist $(WINDIR)\nmakehlp.obj del $(WINDIR)\nmakehlp.obj
diff --git a/nmakehlp.c b/nmakehlp.c
new file mode 100644 (file)
index 0000000..35b35e5
--- /dev/null
@@ -0,0 +1,726 @@
+/*
+ * ----------------------------------------------------------------------------
+ * nmakehlp.c --
+ *
+ *     This is used to fix limitations within nmake and the environment.
+ *
+ * Copyright (c) 2002 by David Gravereaux.
+ * Copyright (c) 2006 by Pat Thoyts
+ *
+ * See the file "license.terms" for information on usage and redistribution of
+ * this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ *
+ * ----------------------------------------------------------------------------
+ * RCS: @(#) $Id$
+ * ----------------------------------------------------------------------------
+ */
+
+#define _CRT_SECURE_NO_DEPRECATE
+#include <windows.h>
+#pragma comment (lib, "user32.lib")
+#pragma comment (lib, "kernel32.lib")
+#include <stdio.h>
+#include <math.h>
+
+/*
+ * This library is required for x64 builds with _some_ versions of MSVC
+ */
+#if defined(_M_IA64) || defined(_M_AMD64)
+#if _MSC_VER >= 1400 && _MSC_VER < 1500
+#pragma comment(lib, "bufferoverflowU")
+#endif
+#endif
+
+/* ISO hack for dumb VC++ */
+#ifdef _MSC_VER
+#define   snprintf     _snprintf
+#endif
+
+
+
+/* protos */
+
+int            CheckForCompilerFeature(const char *option);
+int            CheckForLinkerFeature(const char *option);
+int            IsIn(const char *string, const char *substring);
+int            GrepForDefine(const char *file, const char *string);
+int            SubstituteFile(const char *substs, const char *filename);
+const char *    GetVersionFromFile(const char *filename, const char *match);
+DWORD WINAPI   ReadFromPipe(LPVOID args);
+
+/* globals */
+
+#define CHUNK  25
+#define STATICBUFFERSIZE    1000
+typedef struct {
+    HANDLE pipe;
+    char buffer[STATICBUFFERSIZE];
+} pipeinfo;
+
+pipeinfo Out = {INVALID_HANDLE_VALUE, '\0'};
+pipeinfo Err = {INVALID_HANDLE_VALUE, '\0'};
+\f
+/*
+ * exitcodes: 0 == no, 1 == yes, 2 == error
+ */
+
+int
+main(
+    int argc,
+    char *argv[])
+{
+    char msg[300];
+    DWORD dwWritten;
+    int chars;
+
+    /*
+     * Make sure children (cl.exe and link.exe) are kept quiet.
+     */
+
+    SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
+
+    /*
+     * Make sure the compiler and linker aren't effected by the outside world.
+     */
+
+    SetEnvironmentVariable("CL", "");
+    SetEnvironmentVariable("LINK", "");
+
+    if (argc > 1 && *argv[1] == '-') {
+       switch (*(argv[1]+1)) {
+       case 'c':
+           if (argc != 3) {
+               chars = snprintf(msg, sizeof(msg) - 1,
+                       "usage: %s -c <compiler option>\n"
+                       "Tests for whether cl.exe supports an option\n"
+                       "exitcodes: 0 == no, 1 == yes, 2 == error\n", argv[0]);
+               WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
+                       &dwWritten, NULL);
+               return 2;
+           }
+           return CheckForCompilerFeature(argv[2]);
+       case 'l':
+           if (argc != 3) {
+               chars = snprintf(msg, sizeof(msg) - 1,
+                       "usage: %s -l <linker option>\n"
+                       "Tests for whether link.exe supports an option\n"
+                       "exitcodes: 0 == no, 1 == yes, 2 == error\n", argv[0]);
+               WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
+                       &dwWritten, NULL);
+               return 2;
+           }
+           return CheckForLinkerFeature(argv[2]);
+       case 'f':
+           if (argc == 2) {
+               chars = snprintf(msg, sizeof(msg) - 1,
+                       "usage: %s -f <string> <substring>\n"
+                       "Find a substring within another\n"
+                       "exitcodes: 0 == no, 1 == yes, 2 == error\n", argv[0]);
+               WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
+                       &dwWritten, NULL);
+               return 2;
+           } else if (argc == 3) {
+               /*
+                * If the string is blank, there is no match.
+                */
+
+               return 0;
+           } else {
+               return IsIn(argv[2], argv[3]);
+           }
+       case 'g':
+           if (argc == 2) {
+               chars = snprintf(msg, sizeof(msg) - 1,
+                       "usage: %s -g <file> <string>\n"
+                       "grep for a #define\n"
+                       "exitcodes: integer of the found string (no decimals)\n",
+                       argv[0]);
+               WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
+                       &dwWritten, NULL);
+               return 2;
+           }
+           return GrepForDefine(argv[2], argv[3]);
+       case 's':
+           if (argc == 2) {
+               chars = snprintf(msg, sizeof(msg) - 1,
+                       "usage: %s -s <substitutions file> <file>\n"
+                       "Perform a set of string map type substutitions on a file\n"
+                       "exitcodes: 0\n",
+                       argv[0]);
+               WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
+                       &dwWritten, NULL);
+               return 2;
+           }
+           return SubstituteFile(argv[2], argv[3]);
+       case 'V':
+           if (argc != 4) {
+               chars = snprintf(msg, sizeof(msg) - 1,
+                   "usage: %s -V filename matchstring\n"
+                   "Extract a version from a file:\n"
+                   "eg: pkgIndex.tcl \"package ifneeded http\"",
+                   argv[0]);
+               WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
+                   &dwWritten, NULL);
+               return 0;
+           }
+           printf("%s\n", GetVersionFromFile(argv[2], argv[3]));
+           return 0;
+       }
+    }
+    chars = snprintf(msg, sizeof(msg) - 1,
+           "usage: %s -c|-l|-f|-g|-V ...\n"
+           "This is a little helper app to equalize shell differences between WinNT and\n"
+           "Win9x and get nmake.exe to accomplish its job.\n",
+           argv[0]);
+    WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars, &dwWritten, NULL);
+    return 2;
+}
+\f
+int
+CheckForCompilerFeature(
+    const char *option)
+{
+    STARTUPINFO si;
+    PROCESS_INFORMATION pi;
+    SECURITY_ATTRIBUTES sa;
+    DWORD threadID;
+    char msg[300];
+    BOOL ok;
+    HANDLE hProcess, h, pipeThreads[2];
+    char cmdline[100];
+
+    hProcess = GetCurrentProcess();
+
+    ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
+    ZeroMemory(&si, sizeof(STARTUPINFO));
+    si.cb = sizeof(STARTUPINFO);
+    si.dwFlags   = STARTF_USESTDHANDLES;
+    si.hStdInput = INVALID_HANDLE_VALUE;
+
+    ZeroMemory(&sa, sizeof(SECURITY_ATTRIBUTES));
+    sa.nLength = sizeof(SECURITY_ATTRIBUTES);
+    sa.lpSecurityDescriptor = NULL;
+    sa.bInheritHandle = FALSE;
+
+    /*
+     * Create a non-inheritible pipe.
+     */
+
+    CreatePipe(&Out.pipe, &h, &sa, 0);
+
+    /*
+     * Dupe the write side, make it inheritible, and close the original.
+     */
+
+    DuplicateHandle(hProcess, h, hProcess, &si.hStdOutput, 0, TRUE,
+           DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
+
+    /*
+     * Same as above, but for the error side.
+     */
+
+    CreatePipe(&Err.pipe, &h, &sa, 0);
+    DuplicateHandle(hProcess, h, hProcess, &si.hStdError, 0, TRUE,
+           DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
+
+    /*
+     * Base command line.
+     */
+
+    lstrcpy(cmdline, "cl.exe -nologo -c -TC -Zs -X -Fp.\\_junk.pch ");
+
+    /*
+     * Append our option for testing
+     */
+
+    lstrcat(cmdline, option);
+
+    /*
+     * Filename to compile, which exists, but is nothing and empty.
+     */
+
+    lstrcat(cmdline, " .\\nul");
+
+    ok = CreateProcess(
+           NULL,           /* Module name. */
+           cmdline,        /* Command line. */
+           NULL,           /* Process handle not inheritable. */
+           NULL,           /* Thread handle not inheritable. */
+           TRUE,           /* yes, inherit handles. */
+           DETACHED_PROCESS, /* No console for you. */
+           NULL,           /* Use parent's environment block. */
+           NULL,           /* Use parent's starting directory. */
+           &si,            /* Pointer to STARTUPINFO structure. */
+           &pi);           /* Pointer to PROCESS_INFORMATION structure. */
+
+    if (!ok) {
+       DWORD err = GetLastError();
+       int chars = snprintf(msg, sizeof(msg) - 1,
+               "Tried to launch: \"%s\", but got error [%u]: ", cmdline, err);
+
+       FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS|
+               FORMAT_MESSAGE_MAX_WIDTH_MASK, 0L, err, 0, (LPVOID)&msg[chars],
+               (300-chars), 0);
+       WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg,lstrlen(msg), &err,NULL);
+       return 2;
+    }
+
+    /*
+     * Close our references to the write handles that have now been inherited.
+     */
+
+    CloseHandle(si.hStdOutput);
+    CloseHandle(si.hStdError);
+
+    WaitForInputIdle(pi.hProcess, 5000);
+    CloseHandle(pi.hThread);
+
+    /*
+     * Start the pipe reader threads.
+     */
+
+    pipeThreads[0] = CreateThread(NULL, 0, ReadFromPipe, &Out, 0, &threadID);
+    pipeThreads[1] = CreateThread(NULL, 0, ReadFromPipe, &Err, 0, &threadID);
+
+    /*
+     * Block waiting for the process to end.
+     */
+
+    WaitForSingleObject(pi.hProcess, INFINITE);
+    CloseHandle(pi.hProcess);
+
+    /*
+     * Wait for our pipe to get done reading, should it be a little slow.
+     */
+
+    WaitForMultipleObjects(2, pipeThreads, TRUE, 500);
+    CloseHandle(pipeThreads[0]);
+    CloseHandle(pipeThreads[1]);
+
+    /*
+     * Look for the commandline warning code in both streams.
+     *  - in MSVC 6 & 7 we get D4002, in MSVC 8 we get D9002.
+     */
+
+    return !(strstr(Out.buffer, "D4002") != NULL
+             || strstr(Err.buffer, "D4002") != NULL
+             || strstr(Out.buffer, "D9002") != NULL
+             || strstr(Err.buffer, "D9002") != NULL
+             || strstr(Out.buffer, "D2021") != NULL
+             || strstr(Err.buffer, "D2021") != NULL);
+}
+\f
+int
+CheckForLinkerFeature(
+    const char *option)
+{
+    STARTUPINFO si;
+    PROCESS_INFORMATION pi;
+    SECURITY_ATTRIBUTES sa;
+    DWORD threadID;
+    char msg[300];
+    BOOL ok;
+    HANDLE hProcess, h, pipeThreads[2];
+    char cmdline[100];
+
+    hProcess = GetCurrentProcess();
+
+    ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
+    ZeroMemory(&si, sizeof(STARTUPINFO));
+    si.cb = sizeof(STARTUPINFO);
+    si.dwFlags   = STARTF_USESTDHANDLES;
+    si.hStdInput = INVALID_HANDLE_VALUE;
+
+    ZeroMemory(&sa, sizeof(SECURITY_ATTRIBUTES));
+    sa.nLength = sizeof(SECURITY_ATTRIBUTES);
+    sa.lpSecurityDescriptor = NULL;
+    sa.bInheritHandle = TRUE;
+
+    /*
+     * Create a non-inheritible pipe.
+     */
+
+    CreatePipe(&Out.pipe, &h, &sa, 0);
+
+    /*
+     * Dupe the write side, make it inheritible, and close the original.
+     */
+
+    DuplicateHandle(hProcess, h, hProcess, &si.hStdOutput, 0, TRUE,
+           DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
+
+    /*
+     * Same as above, but for the error side.
+     */
+
+    CreatePipe(&Err.pipe, &h, &sa, 0);
+    DuplicateHandle(hProcess, h, hProcess, &si.hStdError, 0, TRUE,
+           DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
+
+    /*
+     * Base command line.
+     */
+
+    lstrcpy(cmdline, "link.exe -nologo ");
+
+    /*
+     * Append our option for testing.
+     */
+
+    lstrcat(cmdline, option);
+
+    ok = CreateProcess(
+           NULL,           /* Module name. */
+           cmdline,        /* Command line. */
+           NULL,           /* Process handle not inheritable. */
+           NULL,           /* Thread handle not inheritable. */
+           TRUE,           /* yes, inherit handles. */
+           DETACHED_PROCESS, /* No console for you. */
+           NULL,           /* Use parent's environment block. */
+           NULL,           /* Use parent's starting directory. */
+           &si,            /* Pointer to STARTUPINFO structure. */
+           &pi);           /* Pointer to PROCESS_INFORMATION structure. */
+
+    if (!ok) {
+       DWORD err = GetLastError();
+       int chars = snprintf(msg, sizeof(msg) - 1,
+               "Tried to launch: \"%s\", but got error [%u]: ", cmdline, err);
+
+       FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS|
+               FORMAT_MESSAGE_MAX_WIDTH_MASK, 0L, err, 0, (LPVOID)&msg[chars],
+               (300-chars), 0);
+       WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg,lstrlen(msg), &err,NULL);
+       return 2;
+    }
+
+    /*
+     * Close our references to the write handles that have now been inherited.
+     */
+
+    CloseHandle(si.hStdOutput);
+    CloseHandle(si.hStdError);
+
+    WaitForInputIdle(pi.hProcess, 5000);
+    CloseHandle(pi.hThread);
+
+    /*
+     * Start the pipe reader threads.
+     */
+
+    pipeThreads[0] = CreateThread(NULL, 0, ReadFromPipe, &Out, 0, &threadID);
+    pipeThreads[1] = CreateThread(NULL, 0, ReadFromPipe, &Err, 0, &threadID);
+
+    /*
+     * Block waiting for the process to end.
+     */
+
+    WaitForSingleObject(pi.hProcess, INFINITE);
+    CloseHandle(pi.hProcess);
+
+    /*
+     * Wait for our pipe to get done reading, should it be a little slow.
+     */
+
+    WaitForMultipleObjects(2, pipeThreads, TRUE, 500);
+    CloseHandle(pipeThreads[0]);
+    CloseHandle(pipeThreads[1]);
+
+    /*
+     * Look for the commandline warning code in the stderr stream.
+     */
+
+    return !(strstr(Out.buffer, "LNK1117") != NULL ||
+           strstr(Err.buffer, "LNK1117") != NULL ||
+           strstr(Out.buffer, "LNK4044") != NULL ||
+           strstr(Err.buffer, "LNK4044") != NULL);
+}
+\f
+DWORD WINAPI
+ReadFromPipe(
+    LPVOID args)
+{
+    pipeinfo *pi = (pipeinfo *) args;
+    char *lastBuf = pi->buffer;
+    DWORD dwRead;
+    BOOL ok;
+
+  again:
+    if (lastBuf - pi->buffer + CHUNK > STATICBUFFERSIZE) {
+       CloseHandle(pi->pipe);
+       return (DWORD)-1;
+    }
+    ok = ReadFile(pi->pipe, lastBuf, CHUNK, &dwRead, 0L);
+    if (!ok || dwRead == 0) {
+       CloseHandle(pi->pipe);
+       return 0;
+    }
+    lastBuf += dwRead;
+    goto again;
+
+    return 0;  /* makes the compiler happy */
+}
+\f
+int
+IsIn(
+    const char *string,
+    const char *substring)
+{
+    return (strstr(string, substring) != NULL);
+}
+\f
+/*
+ * Find a specified #define by name.
+ *
+ * If the line is '#define TCL_VERSION "8.5"', it returns 85 as the result.
+ */
+
+int
+GrepForDefine(
+    const char *file,
+    const char *string)
+{
+    char s1[51], s2[51], s3[51];
+    FILE *f = fopen(file, "rt");
+
+    if (f == NULL) {
+       return 0;
+    }
+
+    do {
+       int r = fscanf(f, "%50s", s1);
+
+       if (r == 1 && !strcmp(s1, "#define")) {
+           /*
+            * Get next two words.
+            */
+
+           r = fscanf(f, "%50s %50s", s2, s3);
+           if (r != 2) {
+               continue;
+           }
+
+           /*
+            * Is the first word what we're looking for?
+            */
+
+           if (!strcmp(s2, string)) {
+               double d1;
+
+               fclose(f);
+
+               /*
+                * Add 1 past first double quote char. "8.5"
+                */
+
+               d1 = atof(s3 + 1);                /*    8.5  */
+               while (floor(d1) != d1) {
+                   d1 *= 10.0;
+               }
+               return ((int) d1);                /*    85   */
+           }
+       }
+    } while (!feof(f));
+
+    fclose(f);
+    return 0;
+}
+\f
+/*
+ * GetVersionFromFile --
+ *     Looks for a match string in a file and then returns the version
+ *     following the match where a version is anything acceptable to
+ *     package provide or package ifneeded.
+ */
+
+const char *
+GetVersionFromFile(
+    const char *filename,
+    const char *match)
+{
+    size_t cbBuffer = 100;
+    static char szBuffer[100];
+    char *szResult = NULL;
+    FILE *fp = fopen(filename, "rt");
+
+    if (fp != NULL) {
+       /*
+        * Read data until we see our match string.
+        */
+
+       while (fgets(szBuffer, cbBuffer, fp) != NULL) {
+           LPSTR p, q;
+
+           p = strstr(szBuffer, match);
+           if (p != NULL) {
+               /*
+                * Skip to first digit.
+                */
+
+               while (*p && !isdigit(*p)) {
+                   ++p;
+               }
+
+               /*
+                * Find ending whitespace.
+                */
+
+               q = p;
+               while (*q && (isalnum(*q) || *q == '.')) {
+                   ++q;
+               }
+
+               memcpy(szBuffer, p, q - p);
+               szBuffer[q-p] = 0;
+               szResult = szBuffer;
+               break;
+           }
+       }
+       fclose(fp);
+    }
+    return szResult;
+}
+\f
+/*
+ * List helpers for the SubstituteFile function
+ */
+
+typedef struct list_item_t {
+    struct list_item_t *nextPtr;
+    char * key;
+    char * value;
+} list_item_t;
+
+/* insert a list item into the list (list may be null) */
+static list_item_t *
+list_insert(list_item_t **listPtrPtr, const char *key, const char *value)
+{
+    list_item_t *itemPtr = malloc(sizeof(list_item_t));
+    if (itemPtr) {
+       itemPtr->key = strdup(key);
+       itemPtr->value = strdup(value);
+       itemPtr->nextPtr = NULL;
+
+       while(*listPtrPtr) {
+           listPtrPtr = &(*listPtrPtr)->nextPtr;
+       }
+       *listPtrPtr = itemPtr;
+    }
+    return itemPtr;
+}
+
+static void
+list_free(list_item_t **listPtrPtr)
+{
+    list_item_t *tmpPtr, *listPtr = *listPtrPtr;
+    while (listPtr) {
+       tmpPtr = listPtr;
+       listPtr = listPtr->nextPtr;
+       free(tmpPtr->key);
+       free(tmpPtr->value);
+       free(tmpPtr);
+    }
+}
+\f
+/*
+ * SubstituteFile --
+ *     As windows doesn't provide anything useful like sed and it's unreliable
+ *     to use the tclsh you are building against (consider x-platform builds -
+ *     eg compiling AMD64 target from IX86) we provide a simple substitution
+ *     option here to handle autoconf style substitutions.
+ *     The substitution file is whitespace and line delimited. The file should
+ *     consist of lines matching the regular expression:
+ *       \s*\S+\s+\S*$
+ *
+ *     Usage is something like:
+ *       nmakehlp -S << $** > $@
+ *        @PACKAGE_NAME@ $(PACKAGE_NAME)
+ *        @PACKAGE_VERSION@ $(PACKAGE_VERSION)
+ *        <<
+ */
+
+int
+SubstituteFile(
+    const char *substitutions,
+    const char *filename)
+{
+    size_t cbBuffer = 1024;
+    static char szBuffer[1024], szCopy[1024];
+    char *szResult = NULL;
+    list_item_t *substPtr = NULL;
+    FILE *fp, *sp;
+
+    fp = fopen(filename, "rt");
+    if (fp != NULL) {
+
+       /*
+        * Build a list of substutitions from the first filename
+        */
+
+       sp = fopen(substitutions, "rt");
+       if (sp != NULL) {
+           while (fgets(szBuffer, cbBuffer, sp) != NULL) {
+               char *ks, *ke, *vs, *ve;
+               ks = szBuffer;
+               while (ks && *ks && isspace(*ks)) ++ks;
+               ke = ks;
+               while (ke && *ke && !isspace(*ke)) ++ke;
+               vs = ke;
+               while (vs && *vs && isspace(*vs)) ++vs;
+               ve = vs;
+               while (ve && *ve && !(*ve == '\r' || *ve == '\n')) ++ve;
+               *ke = 0, *ve = 0;
+               list_insert(&substPtr, ks, vs);
+           }
+           fclose(sp);
+       }
+
+       /* debug: dump the list */
+#ifdef _DEBUG
+       {
+           int n = 0;
+           list_item_t *p = NULL;
+           for (p = substPtr; p != NULL; p = p->nextPtr, ++n) {
+               fprintf(stderr, "% 3d '%s' => '%s'\n", n, p->key, p->value);
+           }
+       }
+#endif
+       
+       /*
+        * Run the substitutions over each line of the input
+        */
+       
+       while (fgets(szBuffer, cbBuffer, fp) != NULL) {
+           list_item_t *p = NULL;
+           for (p = substPtr; p != NULL; p = p->nextPtr) {
+               char *m = strstr(szBuffer, p->key);
+               if (m) {
+                   char *cp, *op, *sp;
+                   cp = szCopy;
+                   op = szBuffer;
+                   while (op != m) *cp++ = *op++;
+                   sp = p->value;
+                   while (sp && *sp) *cp++ = *sp++;
+                   op += strlen(p->key);
+                   while (*op) *cp++ = *op++;
+                   *cp = 0;
+                   memcpy(szBuffer, szCopy, sizeof(szCopy));
+               }
+           }
+           printf(szBuffer);
+       }
+       
+       list_free(&substPtr);
+    }
+    fclose(fp);
+    return 0;
+}
+
+/*
+ * Local variables:
+ *   mode: c
+ *   c-basic-offset: 4
+ *   fill-column: 78
+ *   indent-tabs-mode: t
+ *   tab-width: 8
+ * End:
+ */
diff --git a/rules.vc b/rules.vc
new file mode 100644 (file)
index 0000000..8a2d227
--- /dev/null
+++ b/rules.vc
@@ -0,0 +1,612 @@
+#------------------------------------------------------------------------------
+# rules.vc --
+#
+#      Microsoft Visual C++ makefile include for decoding the commandline
+#      macros.  This file does not need editing to build Tcl.
+#
+#      This version is modified from the Tcl source version to support
+#      building extensions using nmake.
+#
+# See the file "license.terms" for information on usage and redistribution
+# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+# 
+# Copyright (c) 2001-2002 David Gravereaux.
+# Copyright (c) 2003-2008 Patrick Thoyts
+#
+#------------------------------------------------------------------------------
+# RCS: @(#) $Id$
+#------------------------------------------------------------------------------
+
+!ifndef _RULES_VC
+_RULES_VC = 1
+
+cc32           = $(CC)   # built-in default.
+link32         = link
+lib32          = lib
+rc32           = $(RC)   # built-in default.
+
+!ifndef INSTALLDIR
+### Assume the normal default.
+_INSTALLDIR    = C:\Program Files\Tcl
+!else
+### Fix the path separators.
+_INSTALLDIR    = $(INSTALLDIR:/=\)
+!endif
+
+!ifndef MACHINE
+!if "$(CPU)" == "" || "$(CPU)" == "i386"
+MACHINE         = IX86
+!else
+MACHINE         = $(CPU)
+!endif
+!endif
+
+!ifndef CFG_ENCODING
+CFG_ENCODING   = \"cp1252\"
+!endif
+
+#----------------------------------------------------------
+# Set the proper copy method to avoid overwrite questions
+# to the user when copying files and selecting the right
+# "delete all" method.
+#----------------------------------------------------------
+
+!if "$(OS)" == "Windows_NT"
+RMDIR  = rmdir /S /Q
+ERRNULL  = 2>NUL
+!if ![ver | find "4.0" > nul]
+CPY    = echo y | xcopy /i >NUL
+COPY   = copy >NUL
+!else
+CPY    = xcopy /i /y >NUL
+COPY   = copy /y >NUL
+!endif
+!else # "$(OS)" != "Windows_NT"
+CPY    = xcopy /i >_JUNK.OUT # On Win98 NUL does not work here.
+COPY   = copy >_JUNK.OUT # On Win98 NUL does not work here.
+RMDIR  = deltree /Y
+NULL    = \NUL # Used in testing directory existence
+ERRNULL = >NUL # Win9x shell cannot redirect stderr
+!endif
+MKDIR   = mkdir
+
+!message ===============================================================================
+
+#----------------------------------------------------------
+# build the helper app we need to overcome nmake's limiting
+# environment.
+#----------------------------------------------------------
+
+!if !exist(nmakehlp.exe)
+!if [$(cc32) -nologo nmakehlp.c -link -subsystem:console > nul]
+!endif
+!endif
+
+#----------------------------------------------------------
+# Test for compiler features
+#----------------------------------------------------------
+
+### test for optimizations
+!if [nmakehlp -c -Ot]
+!message *** Compiler has 'Optimizations'
+OPTIMIZING     = 1
+!else
+!message *** Compiler does not have 'Optimizations'
+OPTIMIZING     = 0
+!endif
+
+OPTIMIZATIONS  =
+
+!if [nmakehlp -c -Ot]
+OPTIMIZATIONS  = $(OPTIMIZATIONS) -Ot
+!endif
+
+!if [nmakehlp -c -Oi]
+OPTIMIZATIONS  = $(OPTIMIZATIONS) -Oi
+!endif
+
+!if [nmakehlp -c -Op]
+OPTIMIZATIONS  = $(OPTIMIZATIONS) -Op
+!endif
+
+!if [nmakehlp -c -fp:strict]
+OPTIMIZATIONS  = $(OPTIMIZATIONS) -fp:strict
+!endif
+
+!if [nmakehlp -c -Gs]
+OPTIMIZATIONS  = $(OPTIMIZATIONS) -Gs
+!endif
+
+!if [nmakehlp -c -GS]
+OPTIMIZATIONS  = $(OPTIMIZATIONS) -GS
+!endif
+
+!if [nmakehlp -c -GL]
+OPTIMIZATIONS  = $(OPTIMIZATIONS) -GL
+!endif
+
+DEBUGFLAGS     =
+
+!if [nmakehlp -c -RTC1]
+DEBUGFLAGS     = $(DEBUGFLAGS) -RTC1
+!elseif [nmakehlp -c -GZ]
+DEBUGFLAGS     = $(DEBUGFLAGS) -GZ
+!endif
+
+COMPILERFLAGS  =-W3
+
+# In v13 -GL and -YX are incompatible.
+!if [nmakehlp -c -YX]
+!if ![nmakehlp -c -GL]
+OPTIMIZATIONS  = $(OPTIMIZATIONS) -YX
+!endif
+!endif
+
+!if "$(MACHINE)" == "IX86"
+### test for pentium errata
+!if [nmakehlp -c -QI0f]
+!message *** Compiler has 'Pentium 0x0f fix'
+COMPILERFLAGS  = $(COMPILERFLAGSS) -QI0f
+!else
+!message *** Compiler does not have 'Pentium 0x0f fix'
+!endif
+!endif
+
+!if "$(MACHINE)" == "IA64"
+### test for Itanium errata
+!if [nmakehlp -c -QIA64_Bx]
+!message *** Compiler has 'B-stepping errata workarounds'
+COMPILERFLAGS   = $(COMPILERFLAGS) -QIA64_Bx
+!else
+!message *** Compiler does not have 'B-stepping errata workarounds'
+!endif
+!endif
+
+!if "$(MACHINE)" == "IX86"
+### test for -align:4096, when align:512 will do.
+!if [nmakehlp -l -opt:nowin98]
+!message *** Linker has 'Win98 alignment problem'
+ALIGN98_HACK   = 1
+!else
+!message *** Linker does not have 'Win98 alignment problem'
+ALIGN98_HACK   = 0
+!endif
+!else
+ALIGN98_HACK   = 0
+!endif
+
+LINKERFLAGS     =
+
+!if [nmakehlp -l -ltcg]
+LINKERFLAGS     =-ltcg
+!endif
+
+#----------------------------------------------------------
+# MSVC8 (ships with Visual Studio 2005) generates a manifest
+# file that we should link into the binaries. This is how.
+#----------------------------------------------------------
+
+_VC_MANIFEST_EMBED_EXE=
+_VC_MANIFEST_EMBED_DLL=
+VCVER=0
+!if ![echo VCVERSION=_MSC_VER > vercl.x] \
+    && ![cl -nologo -TC -P vercl.x $(ERRNULL)]
+!include vercl.i
+!if $(VCVERSION) >= 1500
+VCVER=9
+!elseif $(VCVERSION) >= 1400
+VCVER=8
+!elseif $(VCVERSION) >= 1300
+VCVER=7
+!elseif $(VCVERSION) >= 1200
+VCVER=6
+!endif
+!endif
+
+# Since MSVC8 we must deal with manifest resources.
+!if $(VCVERSION) >= 1400
+_VC_MANIFEST_EMBED_EXE=if exist $@.manifest mt -nologo -manifest $@.manifest -outputresource:$@;1
+_VC_MANIFEST_EMBED_DLL=if exist $@.manifest mt -nologo -manifest $@.manifest -outputresource:$@;2
+!endif
+
+#----------------------------------------------------------
+# Decode the options requested.
+#----------------------------------------------------------
+
+!if "$(OPTS)" == "" || [nmakehlp -f "$(OPTS)" "none"]
+STATIC_BUILD   = 0
+TCL_THREADS    = 1
+DEBUG          = 0
+PROFILE                = 0
+MSVCRT         = 0
+LOIMPACT       = 0
+TCL_USE_STATIC_PACKAGES        = 0
+USE_THREAD_ALLOC = 1
+USE_THREAD_STORAGE = 1
+UNCHECKED       = 0
+!else
+!if [nmakehlp -f $(OPTS) "static"]
+!message *** Doing static
+STATIC_BUILD   = 1
+!else
+STATIC_BUILD   = 0
+!endif
+!if [nmakehlp -f $(OPTS) "msvcrt"]
+!message *** Doing msvcrt
+MSVCRT         = 1
+!else
+MSVCRT         = 0
+!endif
+!if [nmakehlp -f $(OPTS) "staticpkg"]
+!message *** Doing staticpkg
+TCL_USE_STATIC_PACKAGES        = 1
+!else
+TCL_USE_STATIC_PACKAGES        = 0
+!endif
+!if [nmakehlp -f $(OPTS) "nothreads"]
+!message *** Compile explicitly for non-threaded tcl
+TCL_THREADS    = 0
+!else
+TCL_THREADS     = 1
+!endif
+!if [nmakehlp -f $(OPTS) "symbols"]
+!message *** Doing symbols
+DEBUG          = 1
+!else
+DEBUG          = 0
+!endif
+!if [nmakehlp -f $(OPTS) "profile"]
+!message *** Doing profile
+PROFILE                = 1
+!else
+PROFILE                = 0
+!endif
+!if [nmakehlp -f $(OPTS) "loimpact"]
+!message *** Doing loimpact
+LOIMPACT       = 1
+!else
+LOIMPACT       = 0
+!endif
+!if [nmakehlp -f $(OPTS) "thrdalloc"]
+!message *** Doing thrdalloc
+USE_THREAD_ALLOC = 1
+!else
+USE_THREAD_ALLOC = 0
+!endif
+!if [nmakehlp -f $(OPTS) "thrdstorage"]
+!message *** Doing thrdstorage
+USE_THREAD_STORAGE = 1
+!else
+USE_THREAD_STORAGE = 0
+!endif
+!if [nmakehlp -f $(OPTS) "unchecked"]
+!message *** Doing unchecked
+UNCHECKED = 1
+!else
+UNCHECKED = 0
+!endif
+!endif
+
+
+!if !$(STATIC_BUILD)
+# Make sure we don't build overly fat DLLs.
+MSVCRT         = 1
+# We shouldn't statically put the extensions inside the shell when dynamic.
+TCL_USE_STATIC_PACKAGES = 0
+!endif
+
+
+#----------------------------------------------------------
+# Figure-out how to name our intermediate and output directories.
+# We wouldn't want different builds to use the same .obj files
+# by accident.
+#----------------------------------------------------------
+
+#----------------------------------------
+# Naming convention:
+#   t = full thread support.
+#   s = static library (as opposed to an
+#      import library)
+#   g = linked to the debug enabled C
+#      run-time.
+#   x = special static build when it
+#      links to the dynamic C run-time.
+#----------------------------------------
+SUFX       = sgx
+
+!if $(DEBUG)
+BUILDDIRTOP = Debug
+!else
+BUILDDIRTOP = Release
+!endif
+
+!if "$(MACHINE)" != "IX86"
+BUILDDIRTOP =$(BUILDDIRTOP)_$(MACHINE)
+!endif
+!if $(VCVER) > 6
+BUILDDIRTOP =$(BUILDDIRTOP)_VC$(VCVER)
+!endif
+
+!if !$(DEBUG) || $(DEBUG) && $(UNCHECKED)
+SUFX       = $(SUFX:g=)
+!endif
+
+TMP_DIRFULL = .\$(BUILDDIRTOP)\$(PROJECT)_ThreadedDynamicStaticX
+
+!if !$(STATIC_BUILD)
+TMP_DIRFULL = $(TMP_DIRFULL:Static=)
+SUFX       = $(SUFX:s=)
+EXT        = dll
+!if $(MSVCRT)
+TMP_DIRFULL = $(TMP_DIRFULL:X=)
+SUFX       = $(SUFX:x=)
+!endif
+!else
+TMP_DIRFULL = $(TMP_DIRFULL:Dynamic=)
+EXT        = lib
+!if !$(MSVCRT)
+TMP_DIRFULL = $(TMP_DIRFULL:X=)
+SUFX       = $(SUFX:x=)
+!endif
+!endif
+
+!if !$(TCL_THREADS)
+TMP_DIRFULL = $(TMP_DIRFULL:Threaded=)
+SUFX       = $(SUFX:t=)
+!endif
+
+!ifndef TMP_DIR
+TMP_DIR            = $(TMP_DIRFULL)
+!ifndef OUT_DIR
+OUT_DIR            = .\$(BUILDDIRTOP)
+!endif
+!else
+!ifndef OUT_DIR
+OUT_DIR            = $(TMP_DIR)
+!endif
+!endif
+
+
+#----------------------------------------------------------
+# Decode the statistics requested.
+#----------------------------------------------------------
+
+!if "$(STATS)" == "" || [nmakehlp -f "$(STATS)" "none"]
+TCL_MEM_DEBUG      = 0
+TCL_COMPILE_DEBUG   = 0
+!else
+!if [nmakehlp -f $(STATS) "memdbg"]
+!message *** Doing memdbg
+TCL_MEM_DEBUG      = 1
+!else
+TCL_MEM_DEBUG      = 0
+!endif
+!if [nmakehlp -f $(STATS) "compdbg"]
+!message *** Doing compdbg
+TCL_COMPILE_DEBUG   = 1
+!else
+TCL_COMPILE_DEBUG   = 0
+!endif
+!endif
+
+
+#----------------------------------------------------------
+# Decode the checks requested.
+#----------------------------------------------------------
+
+!if "$(CHECKS)" == "" || [nmakehlp -f "$(CHECKS)" "none"]
+TCL_NO_DEPRECATED          = 0
+WARNINGS                   = -W3
+!else
+!if [nmakehlp -f $(CHECKS) "nodep"]
+!message *** Doing nodep check
+TCL_NO_DEPRECATED          = 1
+!else
+TCL_NO_DEPRECATED          = 0
+!endif
+!if [nmakehlp -f $(CHECKS) "fullwarn"]
+!message *** Doing full warnings check
+WARNINGS                   = -W4
+!if [nmakehlp -l -warn:3]
+LINKERFLAGS                = $(LINKERFLAGS) -warn:3
+!endif
+!else
+WARNINGS                   = -W3
+!endif
+!if [nmakehlp -f $(CHECKS) "64bit"] && [nmakehlp -c -Wp64]
+!message *** Doing 64bit portability warnings
+WARNINGS                   = $(WARNINGS) -Wp64
+!endif
+!endif
+
+#----------------------------------------------------------
+# Set our defines now armed with our options.
+#----------------------------------------------------------
+
+OPTDEFINES     = -DTCL_CFGVAL_ENCODING=$(CFG_ENCODING) -DSTDC_HEADERS
+
+!if $(TCL_MEM_DEBUG)
+OPTDEFINES     = $(OPTDEFINES) -DTCL_MEM_DEBUG
+!endif
+!if $(TCL_COMPILE_DEBUG)
+OPTDEFINES     = $(OPTDEFINES) -DTCL_COMPILE_DEBUG -DTCL_COMPILE_STATS
+!endif
+!if $(TCL_THREADS)
+OPTDEFINES     = $(OPTDEFINES) -DTCL_THREADS=1
+!if $(USE_THREAD_ALLOC)
+OPTDEFINES     = $(OPTDEFINES) -DUSE_THREAD_ALLOC=1
+!endif
+!if $(USE_THREAD_STORAGE)
+OPTDEFINES     = $(OPTDEFINES) -DUSE_THREAD_STORAGE=1
+!endif
+!endif
+!if $(STATIC_BUILD)
+OPTDEFINES     = $(OPTDEFINES) -DSTATIC_BUILD
+!endif
+!if $(TCL_NO_DEPRECATED)
+OPTDEFINES     = $(OPTDEFINES) -DTCL_NO_DEPRECATED
+!endif
+
+!if $(DEBUG)
+OPTDEFINES     = $(OPTDEFINES) -DTCL_CFG_DEBUG
+!elseif $(OPTIMIZING)
+OPTDEFINES     = $(OPTDEFINES) -DTCL_CFG_OPTIMIZED
+!endif
+!if $(PROFILE)
+OPTDEFINES     = $(OPTDEFINES) -DTCL_CFG_PROFILED
+!endif
+!if "$(MACHINE)" == "IA64" || "$(MACHINE)" == "AMD64"
+OPTDEFINES     = $(OPTDEFINES) -DTCL_CFG_DO64BIT
+!endif
+
+
+#----------------------------------------------------------
+# Get common info used when building extensions.
+#----------------------------------------------------------
+
+!if "$(PROJECT)" != "tcl"
+
+# If INSTALLDIR set to tcl root dir then reset to the lib dir.
+!if exist("$(_INSTALLDIR)\include\tcl.h")
+_INSTALLDIR=$(_INSTALLDIR)\lib
+!endif
+
+!if !defined(TCLDIR)
+!if exist("$(_INSTALLDIR)\..\include\tcl.h")
+TCLINSTALL     = 1
+_TCLDIR                = $(_INSTALLDIR)\..
+_TCL_H          = $(_INSTALLDIR)\..\include\tcl.h
+TCLDIR          = $(_INSTALLDIR)\..
+!else
+MSG=^
+Failed to find tcl.h.  Set the TCLDIR macro.
+!error $(MSG)
+!endif
+!else
+_TCLDIR        = $(TCLDIR:/=\)
+!if exist("$(_TCLDIR)\include\tcl.h")
+TCLINSTALL     = 1
+_TCL_H          = $(_TCLDIR)\include\tcl.h
+!elseif exist("$(_TCLDIR)\generic\tcl.h")
+TCLINSTALL     = 0
+_TCL_H          = $(_TCLDIR)\generic\tcl.h
+!else
+MSG =^
+Failed to find tcl.h.  The TCLDIR macro does not appear correct.
+!error $(MSG)
+!endif
+!endif
+
+!if [echo REM = This file is generated from rules.vc > version.vc]
+!endif
+!if exist("$(_TCL_H)")
+!if [echo TCL_DOTVERSION = \>> version.vc] \
+   && [nmakehlp -V "$(_TCL_H)" TCL_VERSION >> version.vc]
+!endif
+!endif
+!include version.vc
+TCL_VERSION    = $(TCL_DOTVERSION:.=)
+
+!if $(TCLINSTALL)
+TCLSH          = "$(_TCLDIR)\bin\tclsh$(TCL_VERSION)$(SUFX).exe"
+!if !exist($(TCLSH)) && $(TCL_THREADS)
+TCLSH           = "$(_TCLDIR)\bin\tclsh$(TCL_VERSION)t$(SUFX).exe"
+!endif
+TCLSTUBLIB     = "$(_TCLDIR)\lib\tclstub$(TCL_VERSION).lib"
+TCLIMPLIB      = "$(_TCLDIR)\lib\tcl$(TCL_VERSION)$(SUFX).lib"
+TCL_LIBRARY    = $(_TCLDIR)\lib
+TCL_INCLUDES    = -I"$(_TCLDIR)\include"
+!else
+TCLSH          = "$(_TCLDIR)\win\$(BUILDDIRTOP)\tclsh$(TCL_VERSION)$(SUFX).exe"
+!if !exist($(TCLSH)) && $(TCL_THREADS)
+TCLSH          = "$(_TCLDIR)\win\$(BUILDDIRTOP)\tclsh$(TCL_VERSION)t$(SUFX).exe"
+!endif
+TCLSTUBLIB     = "$(_TCLDIR)\win\$(BUILDDIRTOP)\tclstub$(TCL_VERSION).lib"
+TCLIMPLIB      = "$(_TCLDIR)\win\$(BUILDDIRTOP)\tcl$(TCL_VERSION)$(SUFX).lib"
+TCL_LIBRARY    = $(_TCLDIR)\library
+TCL_INCLUDES   = -I"$(_TCLDIR)\generic" -I"$(_TCLDIR)\win"
+!endif
+
+!endif
+
+#----------------------------------------------------------
+# Optionally check for Tk info for building extensions.
+#----------------------------------------------------------
+
+!ifdef PROJECT_REQUIRES_TK
+!if "$(PROJECT)" != "tcl" && "$(PROJECT)" != "tk"
+
+!if !defined(TKDIR)
+!if exist("$(_INSTALLDIR)\..\include\tk.h")
+TKINSTALL      = 1
+_TKDIR         = $(_INSTALLDIR)\..
+_TK_H          = $(_TKDIR)\include\tk.h
+TKDIR          = $(_TKDIR)
+!elseif exist("$(_TCLDIR)\include\tk.h")
+TKINSTALL      = 1
+_TKDIR         = $(_TCLDIR)
+_TK_H          = $(_TKDIR)\include\tk.h
+TKDIR          = $(_TKDIR)
+!endif
+!else
+_TKDIR = $(TKDIR:/=\)
+!if exist("$(_TKDIR)\include\tk.h")
+TKINSTALL      = 1
+_TK_H          = $(_TKDIR)\include\tk.h
+!elseif exist("$(_TKDIR)\generic\tk.h")
+TKINSTALL      = 0
+_TK_H          = $(_TKDIR)\generic\tk.h
+!else
+MSG =^
+Failed to find tk.h. The TKDIR macro does not appear correct.
+!error $(MSG)
+!endif
+!endif
+
+!if defined(TKDIR)
+TK_DOTVERSION = 8.4
+!if exist("$(_TK_H)")
+!if [echo TK_DOTVERSION = \>> version.vc] \
+   && [nmakehlp -V "$(_TK_H)" TK_VERSION >> version.vc]
+!endif
+!endif
+!include version.vc
+TK_VERSION = $(TK_DOTVERSION:.=)
+
+!if $(TKINSTALL)
+WISH           = "$(_TKDIR)\bin\wish$(TK_VERSION)$(SUFX).exe"
+!if !exist($(WISH)) && $(TCL_THREADS)
+WISH           = "$(_TKDIR)\bin\wish$(TK_VERSION)t$(SUFX).exe"
+!endif
+TKSTUBLIB      = "$(_TKDIR)\lib\tkstub$(TK_VERSION).lib"
+TKIMPLIB       = "$(_TKDIR)\lib\tk$(TK_VERSION)$(SUFX).lib"
+TK_INCLUDES     = -I"$(_TKDIR)\include"
+TK_LIBRARY     = $(_TKDIR)\lib
+!else
+WISH           = "$(_TKDIR)\win\$(BUILDDIRTOP)\wish$(TCL_VERSION)$(SUFX).exe"
+!if !exist($(WISH)) && $(TCL_THREADS)
+WISH           = "$(_TKDIR)\win\$(BUILDDIRTOP)\wish$(TCL_VERSION)t$(SUFX).exe"
+!endif
+TKSTUBLIB      = "$(_TKDIR)\win\$(BUILDDIRTOP)\tkstub$(TCL_VERSION).lib"
+TKIMPLIB       = "$(_TKDIR)\win\$(BUILDDIRTOP)\tk$(TCL_VERSION)$(SUFX).lib"
+TK_INCLUDES     = -I"$(_TKDIR)\generic" -I"$(_TKDIR)\win" -I"$(_TKDIR)\xlib"
+TK_LIBRARY     = $(_TKDIR)\library
+!endif
+
+!endif
+!endif
+!endif
+
+#----------------------------------------------------------
+# Display stats being used.
+#----------------------------------------------------------
+
+!message *** Intermediate directory will be '$(TMP_DIR)'
+!message *** Output directory will be '$(OUT_DIR)'
+!message *** Suffix for binaries will be '$(SUFX)'
+!message *** Optional defines are '$(OPTDEFINES)'
+!message *** Compiler version $(VCVER). Target machine is $(MACHINE)
+!message *** Compiler options '$(COMPILERFLAGS) $(OPTIMIZATIONS) $(DEBUGFLAGS) $(WARNINGS)'
+!message *** Link options '$(LINKERFLAGS)'
+
+!endif
diff --git a/tclftd2xx.c b/tclftd2xx.c
new file mode 100644 (file)
index 0000000..a344131
--- /dev/null
@@ -0,0 +1,660 @@
+/* tclftd2xx.c - Copyright (C) 2008 Pat Thoyts <patthoyts@users.sourceforge.net>
+ *
+ *     FTDI D2XX USB Device driver Tcl interface.
+ *
+ * ----------------------------------------------------------------------
+ *     See the accompanying file 'licence.terms' for the software license.
+ *     In essence - this is MIT licencensed code.
+ * ----------------------------------------------------------------------
+ */
+
+#define STRICT
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <tcl.h>
+#include <errno.h>
+#include "ftd2xx.h"
+
+#if _MSC_VER >= 1000
+#pragma comment(lib, "ftd2xx.lib")
+#endif
+
+#define FTD2XX_ASYNC   (1<<1)
+#define FTD2XX_PENDING (1<<2)
+
+struct Package;
+
+typedef struct Channel {
+    Tcl_Channel channel;
+    struct Channel *nextPtr;
+    struct Package *pkgPtr;
+    int flags;
+    int watchmask;
+    int validmask;
+    unsigned long rxtimeout;
+    unsigned long txtimeout;
+    FT_HANDLE handle;
+} Channel;
+
+typedef struct ChannelEvent {
+    Tcl_Event header;
+    Channel *instPtr;
+    int flags;
+} ChannelEvent;
+
+typedef struct Package {
+    struct Channel *headPtr;
+    unsigned long uid;
+} Package;
+
+static const char *ConvertError(FT_STATUS fts);
+
+static Tcl_DriverCloseProc ChannelClose;
+static Tcl_DriverInputProc ChannelInput;
+static Tcl_DriverOutputProc ChannelOutput;
+static Tcl_DriverSetOptionProc ChannelSetOption;
+static Tcl_DriverGetOptionProc ChannelGetOption;
+static Tcl_DriverWatchProc ChannelWatch;
+static Tcl_DriverGetHandleProc ChannelGetHandle;
+static Tcl_DriverBlockModeProc ChannelBlockMode;
+
+static Tcl_ChannelType Ftd2xxChannelType = {
+    "ftd2xx",
+    (Tcl_ChannelTypeVersion)TCL_CHANNEL_VERSION_3,
+    ChannelClose,
+    ChannelInput,
+    ChannelOutput,
+    NULL /*ChannelSeek*/,
+    ChannelSetOption,
+    ChannelGetOption,
+    ChannelWatch,
+    ChannelGetHandle,
+    NULL /*ChannelClose2*/,
+    ChannelBlockMode,
+    NULL /*ChannelFlush*/,
+    NULL /*ChannelHandler*/,
+    NULL /*ChannelWideSeek*/
+};
+
+static int
+ChannelClose(ClientData instance, Tcl_Interp *interp)
+{
+    Channel *instPtr = instance;
+    Package *pkgPtr = instPtr->pkgPtr;
+    Channel **tmpPtrPtr;
+    int r = TCL_OK;
+    FT_STATUS fts;
+
+    OutputDebugString("ChannelClose\n");
+    fts = FT_Purge(instPtr->handle, FT_PURGE_RX | FT_PURGE_TX);
+    fts = FT_Close(instPtr->handle);
+    if (fts != FT_OK) {
+       Tcl_AppendResult(interp, "error closing device: ",
+                        ConvertError(fts), NULL);
+       r = TCL_ERROR;
+    }
+    /* remove this channel from the package list */
+    tmpPtrPtr = &pkgPtr->headPtr;
+    while (*tmpPtrPtr && *tmpPtrPtr != instPtr) {
+       tmpPtrPtr = &(*tmpPtrPtr)->nextPtr;
+    }
+    *tmpPtrPtr = instPtr->nextPtr;
+
+    ckfree((char *)instPtr);
+    return r;
+}
+
+static int
+ChannelInput(ClientData instance, char *buffer, int toRead, int *errorCodePtr)
+{
+    Channel *instPtr = instance;
+    DWORD cbRead = 0;
+    FT_STATUS fts = FT_OK;
+
+    if (instPtr->flags & FTD2XX_ASYNC) {
+       /*
+        * Non-blocking: only read data that is available
+        */
+       DWORD rx = 0, tx = 0, ev = 0;
+       if ((fts = FT_GetStatus(instPtr->handle, &rx, &tx, &ev)) == FT_OK) {
+           if ((int)rx < toRead) {
+               toRead = rx;
+           }
+       } else {
+           OutputDebugString(ConvertError(fts));
+       }
+    }
+    if (FT_Read(instPtr->handle, buffer, toRead, &cbRead) != FT_OK) {
+       OutputDebugString(ConvertError(fts));
+       *errorCodePtr = EINVAL;
+    }
+    return (int)cbRead;
+}
+
+static int
+ChannelOutput(ClientData instance, const char *buffer, int toWrite, int *errorCodePtr)
+{
+    Channel *instPtr = instance;
+    char sz[80];
+    DWORD cbWrote = 0;
+    DWORD dwStart = GetTickCount();
+    if (FT_Write(instPtr->handle, (void *)buffer, toWrite, &cbWrote) != FT_OK) {
+       *errorCodePtr = EINVAL;
+    }
+    sprintf(sz, "ChannelOutput %ld ms\n", GetTickCount()-dwStart);
+    OutputDebugString(sz);
+    return (int)cbWrote;
+}
+
+static int
+ChannelSetOption(ClientData instance, Tcl_Interp *interp,
+                const char *optionName, const char *newValue)
+{
+    Channel *instPtr = instance;
+    FT_STATUS fts = FT_OK;
+    int r = TCL_OK, changeTimeouts = 0;
+
+    if (!strcmp("-readtimeout", optionName)) {
+       int tmp = 1;
+       r = Tcl_GetInt(interp, newValue, &tmp);
+       if (r == TCL_OK) {
+           fts = FT_SetTimeouts(instPtr->handle, (DWORD)tmp, instPtr->txtimeout);
+           if (fts == FT_OK) {
+               instPtr->rxtimeout = (unsigned long)tmp;
+           }
+       }
+    } else if (!strcmp("-writetimeout", optionName)) {
+       int tmp = 1;
+       r = Tcl_GetInt(interp, newValue, &tmp);
+       if (r == TCL_OK) {
+           fts = FT_SetTimeouts(instPtr->handle, instPtr->rxtimeout, (DWORD)tmp);
+           if (fts == FT_OK) {
+               instPtr->txtimeout = (unsigned long)tmp;
+           }
+       }
+    } else if (!strcmp("-latency", optionName)) {
+       int tmp = 1;
+       r = Tcl_GetInt(interp, newValue, &tmp);
+       if (r == TCL_OK) {
+           fts = FT_SetLatencyTimer(instPtr->handle, (UCHAR)tmp);
+       }
+    }
+
+    if (fts != FT_OK) {
+       Tcl_AppendResult(interp, "error setting ", optionName,
+                        ": ", ConvertError(fts), NULL);
+       r = TCL_ERROR;
+    }
+
+    return TCL_OK;
+}
+
+static int
+ChannelGetOption(ClientData instance, Tcl_Interp *interp, 
+                const char *optionName, Tcl_DString *optionValue)
+{
+    Channel *instPtr = instance;
+    const char *options[] = {"readtimeout", "writetimeout", "latency", NULL};
+    int r = TCL_OK;
+
+    if (optionName == NULL) {
+       Tcl_DString ds;
+       const char **p;
+
+       Tcl_DStringInit(&ds);
+       for (p = options; *p != NULL; ++p) {
+           char op[16];
+           sprintf(op, "-%s", *p);
+           Tcl_DStringSetLength(&ds, 0);
+           ChannelGetOption(instance, interp, op, &ds);
+           Tcl_DStringAppend(optionValue, " ", 1);
+           Tcl_DStringAppend(optionValue, op, -1);
+           Tcl_DStringAppend(optionValue, " ", 1);
+           Tcl_DStringAppendElement(optionValue, Tcl_DStringValue(&ds));
+       }
+       Tcl_DStringFree(&ds);
+    } else {
+       FT_STATUS fts = FT_OK;
+       Tcl_DString ds;
+       Tcl_DStringInit(&ds);
+
+       if (!strcmp("-readtimeout", optionName)) {
+           Tcl_DStringSetLength(&ds, TCL_INTEGER_SPACE);
+           sprintf(Tcl_DStringValue(&ds), "%lu", instPtr->rxtimeout);
+       } else if (!strcmp("-writetimeout", optionName)) {
+           Tcl_DStringSetLength(&ds, TCL_INTEGER_SPACE);
+           sprintf(Tcl_DStringValue(&ds), "%lu", instPtr->txtimeout);
+       } else if (!strcmp("-latency", optionName)) {
+           UCHAR timer = 0;
+           Tcl_DStringSetLength(&ds, TCL_INTEGER_SPACE);
+           fts = FT_GetLatencyTimer(instPtr->handle, &timer);
+           if (fts == FT_OK) {
+               sprintf(Tcl_DStringValue(&ds), "%d", timer);
+           } else {
+               Tcl_AppendResult(interp, "failed to read ", optionName, ": ",
+                                ConvertError(fts), NULL);
+               r = TCL_ERROR;
+           }
+       } else {
+           const char **p;
+           for (p = options; *p != NULL; ++p) {
+               Tcl_DStringAppendElement(&ds, *p);
+           }
+           r = Tcl_BadChannelOption(interp, optionName, Tcl_DStringValue(&ds));
+       }
+
+       if (r == TCL_OK) {
+           Tcl_DStringAppend(optionValue, Tcl_DStringValue(&ds), -1);
+       }
+       Tcl_DStringFree(&ds);
+    }
+
+    return r;
+}
+
+static void
+ChannelWatch(ClientData instance, int mask)
+{
+    Channel *instPtr = instance;
+    Tcl_Time blockTime = {0, 10000}; /* 10 msec */
+    char sz[80];
+    sprintf(sz, "ChannelWatch %s 0x%08x\n",
+           Tcl_GetChannelName(instPtr->channel), mask);
+    OutputDebugString(sz);
+    instPtr->watchmask = mask & instPtr->validmask;
+    if (instPtr->watchmask) {
+       Tcl_SetMaxBlockTime(&blockTime);
+    }
+}
+
+static int
+ChannelGetHandle(ClientData instance, int direction, ClientData *handlePtr)
+{
+    Channel *instPtr = instance;
+    OutputDebugString("ChannelGetHandle\n");
+    *handlePtr = instPtr->handle;
+    return TCL_OK;
+}
+
+static int
+ChannelBlockMode(ClientData instance, int mode)
+{
+    Channel *instPtr = instance;
+    OutputDebugString("ChannelBlockMode\n");
+    if (mode == TCL_MODE_NONBLOCKING) {
+       instPtr->flags  |= FTD2XX_ASYNC;
+    } else {
+       instPtr->flags &= ~FTD2XX_ASYNC;
+    }
+    return TCL_OK;
+}
+
+static int
+EventProc(Tcl_Event *evPtr, int flags)
+{
+    ChannelEvent *eventPtr = (ChannelEvent *)evPtr;
+    Channel *chanPtr = eventPtr->instPtr;
+    char sz[80];
+
+    if (!(flags & TCL_FILE_EVENTS)) {
+       return 0;
+    }
+
+    chanPtr->flags &= ~FTD2XX_PENDING;
+    sprintf(sz, "EventProc mask 0x%08x\n", chanPtr->watchmask & eventPtr->flags);
+    OutputDebugString(sz);
+    Tcl_NotifyChannel(chanPtr->channel, chanPtr->watchmask & eventPtr->flags);
+    return 1;
+}
+
+static void
+SetupProc(ClientData clientData, int flags)
+{
+    Package *pkgPtr = clientData;
+    Channel *chanPtr = NULL;
+    int msec = 10000;
+    Tcl_Time blockTime = {0, 0};
+
+    if (!(flags & TCL_FILE_EVENTS)) {
+       return;
+    }
+
+    for (chanPtr = pkgPtr->headPtr; chanPtr != NULL; chanPtr = chanPtr->nextPtr) {
+       msec = 10;
+    }
+    blockTime.sec = msec / 1000;
+    blockTime.usec = (msec % 1000) * 1000;
+    Tcl_SetMaxBlockTime(&blockTime);
+}
+
+static void
+CheckProc(ClientData clientData, int flags)
+{
+    Package *pkgPtr = clientData;
+    Channel *chanPtr = NULL;
+
+    if (!(flags & TCL_FILE_EVENTS)) {
+       return;
+    }
+
+    for (chanPtr = pkgPtr->headPtr; chanPtr != NULL; chanPtr = chanPtr->nextPtr) {
+       DWORD rx = 0, tx = 0, ev = 0;
+       FT_STATUS fts = FT_OK;
+
+       if (chanPtr->flags & FTD2XX_PENDING) {
+           continue;
+       }
+
+       /* Only test if there are active watches on this channel */
+       if (chanPtr->watchmask == 0) {
+           continue;
+       }
+
+       if ((fts = FT_GetStatus(chanPtr->handle, &rx, &tx, &ev)) == FT_OK) {
+           if (rx != 0 || tx != 0 || ev != 0) {
+               int mask = 0;
+
+               mask = TCL_WRITABLE | ((rx)?TCL_READABLE:0);
+               //if (ev != 0) evPtr->flags |= TCL_EXCEPTION;
+               if (chanPtr->watchmask & mask) {
+                   ChannelEvent *evPtr = (ChannelEvent *)ckalloc(sizeof(ChannelEvent));
+                   chanPtr->flags |= FTD2XX_PENDING;
+                   evPtr->header.proc = EventProc;
+                   evPtr->instPtr = chanPtr;
+                   evPtr->flags = mask;
+                   Tcl_QueueEvent((Tcl_Event *)evPtr, TCL_QUEUE_TAIL);
+               }
+           }
+       }
+    }
+}
+
+static void
+DeleteProc(ClientData clientData)
+{
+    Package *pkgPtr = clientData;
+    OutputDebugString("Deleted FTD2xx command\n");
+    Tcl_DeleteEventSource(SetupProc, CheckProc, pkgPtr);
+    ckfree((char *)pkgPtr);
+}
+
+static const char *
+ConvertError(FT_STATUS fts)
+{
+    const char *s;
+    switch (fts) {
+       case FT_OK: s = "no error"; break;
+       case FT_INVALID_HANDLE: s = "invalid handle"; break;
+       case FT_DEVICE_NOT_FOUND: s = "device not found"; break;
+       case FT_DEVICE_NOT_OPENED: s = "device not opened"; break;
+       case FT_IO_ERROR: s = "io error"; break;
+       case FT_INSUFFICIENT_RESOURCES: s = "insufficient resources"; break;
+       case FT_INVALID_PARAMETER: s = "invalid parameter"; break;
+       case FT_INVALID_BAUD_RATE: s = "invalid baud rate"; break;
+       case FT_DEVICE_NOT_OPENED_FOR_ERASE: s = "device not opened for erase"; break;
+       case FT_DEVICE_NOT_OPENED_FOR_WRITE: s = "device not opened for write"; break;
+       case FT_FAILED_TO_WRITE_DEVICE: s = "failed to write device"; break;
+       /* some EEPROM errors skipped */
+       case FT_INVALID_ARGS: s = "invalid args"; break;
+       case FT_NOT_SUPPORTED: s = "not supported"; break;
+       default: s = "other error"; break;
+    }
+    return s;
+}
+
+static int
+OpenCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
+{
+    Package *pkgPtr = clientData;
+    const char *name = NULL;
+    FT_HANDLE handle = 0;
+    FT_STATUS fts = FT_OK;
+    int r = TCL_OK, index, nameindex = 2, ftmode = FT_OPEN_BY_SERIAL_NUMBER;
+    const unsigned long rxtimeout = 500, txtimeout = 500;
+    enum {OPT_SERIAL, OPT_DESC, OPT_LOC};
+    const char *options[] = {
+       "-serial", "-description", "-location", NULL
+    };
+
+    if (objc < 3 || objc > 4) {
+        Tcl_WrongNumArgs(interp, 1, objv, 
+                        "?-serial? ?-description? ?-location? string");
+        return TCL_ERROR;
+    }
+    
+    if (objc == 4) {
+       if (Tcl_GetIndexFromObj(interp, objv[2], options, 
+                               "option", 0, &index) != TCL_OK) {
+           return TCL_ERROR;
+       }
+       switch (index) {
+           case OPT_SERIAL: ftmode = FT_OPEN_BY_SERIAL_NUMBER; break;
+           case OPT_DESC: ftmode = FT_OPEN_BY_DESCRIPTION; break;
+           case OPT_LOC: ftmode = FT_OPEN_BY_LOCATION; break;
+       }
+       ++nameindex;
+    }
+    name = Tcl_GetString(objv[nameindex]);
+
+    fts = FT_OpenEx((void *)name, ftmode, &handle);
+    if (fts == FT_OK)
+       fts = FT_SetTimeouts(handle, rxtimeout, txtimeout);
+    if (fts == FT_OK) {
+        Channel *instPtr;
+        char name[6+TCL_INTEGER_SPACE];
+
+        sprintf(name, "ftd2xx%ld", pkgPtr->uid++);
+        instPtr = (Channel *)ckalloc(sizeof(Channel));
+       instPtr->flags = 0;
+        instPtr->watchmask = 0;
+        instPtr->validmask = TCL_READABLE | TCL_WRITABLE;
+       instPtr->rxtimeout = rxtimeout;
+       instPtr->txtimeout = txtimeout;
+        instPtr->handle = handle;
+        instPtr->channel = Tcl_CreateChannel(&Ftd2xxChannelType, name,
+                                            instPtr, instPtr->validmask);
+       Tcl_SetChannelOption(interp, instPtr->channel, "-encoding", "binary");
+       Tcl_SetChannelOption(interp, instPtr->channel, "-translation", "binary");
+        Tcl_RegisterChannel(interp, instPtr->channel);
+
+       /* insert at head of channels list */
+       instPtr->pkgPtr = pkgPtr;
+       instPtr->nextPtr = pkgPtr->headPtr;
+       pkgPtr->headPtr = instPtr;
+
+        Tcl_SetObjResult(interp, Tcl_NewStringObj(name, -1));
+        r = TCL_OK;
+    } else {
+        Tcl_AppendResult(interp, "failed to open device: \"",
+                        name, "\": ", ConvertError(fts), NULL);
+        r = TCL_ERROR;
+    }
+    return r;
+}
+
+static int
+PurgeCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
+{
+    Tcl_Channel channel;
+    Channel *instPtr;
+    FT_STATUS fts;
+
+    if (objc != 3) {
+       Tcl_WrongNumArgs(interp, 2, objv, "channel");
+       return TCL_ERROR;
+    }
+
+    channel = Tcl_GetChannel(interp, Tcl_GetString(objv[2]), NULL);
+    if (channel == NULL) {
+       return TCL_ERROR;
+    }
+    if (Tcl_GetChannelType(channel) != &Ftd2xxChannelType) {
+       Tcl_AppendResult(interp, "wrong channel type: \"", Tcl_GetString(objv[2]),
+                        "\" must be a ftd2xx channel", NULL);
+       return TCL_ERROR;
+    }
+
+    instPtr = (Channel *)Tcl_GetChannelInstanceData(channel);
+    if ((fts = FT_Purge(instPtr->handle, FT_PURGE_RX | FT_PURGE_TX)) != FT_OK) {
+       Tcl_AppendResult(interp, "error purging channel: ", ConvertError(fts), NULL);
+       return TCL_ERROR;
+    }
+
+    return TCL_OK;
+}
+
+static int
+ResetCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
+{
+    Tcl_Channel channel;
+    Channel *instPtr;
+    FT_STATUS fts;
+
+    if (objc != 3) {
+       Tcl_WrongNumArgs(interp, 2, objv, "channel");
+       return TCL_ERROR;
+    }
+
+    channel = Tcl_GetChannel(interp, Tcl_GetString(objv[2]), NULL);
+    if (channel == NULL) {
+       return TCL_ERROR;
+    }
+    if (Tcl_GetChannelType(channel) != &Ftd2xxChannelType) {
+       Tcl_AppendResult(interp, "wrong channel type: \"", Tcl_GetString(objv[2]),
+                        "\" must be a ftd2xx channel", NULL);
+       return TCL_ERROR;
+    }
+
+    instPtr = (Channel *)Tcl_GetChannelInstanceData(channel);
+    if ((fts = FT_ResetPort(instPtr->handle)) != FT_OK) {
+       Tcl_AppendResult(interp, "error resetting channel: ", ConvertError(fts), NULL);
+       return TCL_ERROR;
+    }
+
+    return TCL_OK;
+}
+
+static int
+ListCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
+{
+    DWORD count = 0, node = 0;
+    Tcl_Obj *listObj = NULL;
+    FT_DEVICE_LIST_INFO_NODE *nodesPtr = NULL;
+    FT_STATUS fts;
+    const char *typeName;
+    const char *typeNames[] = { "BM", "AM", "100AX", "UNKNOWN", "2232C", "232R"};
+
+    if ((fts = FT_CreateDeviceInfoList(&count)) != FT_OK) {
+       Tcl_AppendResult(interp, "failed to enumerate devices: ",
+                        ConvertError(fts), NULL);
+       return TCL_ERROR;
+    }
+
+    nodesPtr = (FT_DEVICE_LIST_INFO_NODE*)
+       ckalloc(sizeof(FT_DEVICE_LIST_INFO_NODE) * count);
+    
+    if ((fts = FT_GetDeviceInfoList(nodesPtr, &count)) != FT_OK) {
+       Tcl_AppendResult(interp, "failed to get device list: ",
+                        ConvertError(fts), NULL);
+       ckfree((char *)nodesPtr);
+       return TCL_ERROR;
+    }
+
+    listObj = Tcl_NewListObj(0, NULL);
+    for (node = 0; node < count; ++node) {
+       Tcl_Obj *devObj = Tcl_NewListObj(0, NULL);
+       
+       Tcl_ListObjAppendElement(interp, devObj, Tcl_NewStringObj("id", -1));
+       Tcl_ListObjAppendElement(interp, devObj, Tcl_NewLongObj(nodesPtr[node].ID));
+       Tcl_ListObjAppendElement(interp, devObj, Tcl_NewStringObj("location", -1));
+       Tcl_ListObjAppendElement(interp, devObj, Tcl_NewLongObj(nodesPtr[node].LocId));
+       Tcl_ListObjAppendElement(interp, devObj, Tcl_NewStringObj("serial", -1));
+       Tcl_ListObjAppendElement(interp, devObj, 
+                                Tcl_NewStringObj(nodesPtr[node].SerialNumber, -1));
+       Tcl_ListObjAppendElement(interp, devObj, Tcl_NewStringObj("description", -1));
+       Tcl_ListObjAppendElement(interp, devObj, 
+                                Tcl_NewStringObj(nodesPtr[node].Description, -1));
+       Tcl_ListObjAppendElement(interp, devObj, Tcl_NewStringObj("type", -1));
+       typeName = typeNames[FT_DEVICE_UNKNOWN];
+       if (nodesPtr[node].Type < sizeof(typeNames)/sizeof(typeNames[0])) {
+           typeName = typeNames[nodesPtr[node].Type];
+       }
+       Tcl_ListObjAppendElement(interp, devObj, Tcl_NewStringObj(typeName, -1));
+       Tcl_ListObjAppendElement(interp, devObj, Tcl_NewStringObj("handle", -1));
+       Tcl_ListObjAppendElement(interp, devObj,
+                                Tcl_NewLongObj((long)nodesPtr[node].ftHandle));
+       Tcl_ListObjAppendElement(interp, devObj, Tcl_NewStringObj("opened", -1));
+       Tcl_ListObjAppendElement(interp, devObj,
+                                Tcl_NewBooleanObj(nodesPtr[node].Flags & 1));
+       Tcl_ListObjAppendElement(interp, listObj, devObj);
+    }
+    ckfree((char*)nodesPtr);
+    Tcl_SetObjResult(interp, listObj);
+    return TCL_OK;
+}
+
+typedef struct Ensemble {
+    const char *name;
+    Tcl_ObjCmdProc *command;
+    struct Ensemble *ensemble;
+} Ensemble;
+
+static Ensemble Ftd2xxEnsemble[] = {
+    { "open", OpenCmd, NULL },
+    { "list", ListCmd, NULL },
+    { "purge", PurgeCmd, NULL },
+    { "reset", ResetCmd, NULL },
+    { NULL, NULL, NULL }
+};
+
+static int
+EnsembleCmd(ClientData clientData, Tcl_Interp *interp,
+    int objc, Tcl_Obj *const objv[])
+{
+    Ensemble *ensemble = Ftd2xxEnsemble;
+    int option = 1, index;
+    while (option < objc) {
+        if (Tcl_GetIndexFromObjStruct(interp, objv[option], ensemble, 
+            sizeof(ensemble[0]), "command", 0, &index) != TCL_OK) 
+        {
+            return TCL_ERROR;
+        }
+        if (ensemble[index].command) {
+            return ensemble[index].command(clientData, interp, objc, objv);
+        }
+        ensemble = ensemble[index].ensemble;
+        ++option;
+    }
+    Tcl_WrongNumArgs(interp, option, objv, "option ?arg arg ...?");
+    return TCL_ERROR;
+}
+
+int DLLEXPORT
+Ftd2xx_Init(Tcl_Interp *interp)
+{
+    Package *pkgPtr;
+
+#ifdef USE_TCL_STUBS
+    if (Tcl_InitStubs(interp, "8.0", 0) == NULL) {
+        return TCL_ERROR;
+    }
+#endif
+
+    pkgPtr = (Package *)ckalloc(sizeof(Package));
+    pkgPtr->headPtr = NULL;
+    pkgPtr->uid = 0;
+    Tcl_CreateEventSource(SetupProc, CheckProc, pkgPtr);
+    Tcl_CreateObjCommand(interp, "ftd2xx", EnsembleCmd, pkgPtr, DeleteProc);
+    return Tcl_PkgProvide(interp, "ftd2xx", PACKAGE_VERSION);
+}
+
+/*
+ * Local variables:
+ *   mode: c
+ *   c-basic-offset: 4
+ *   fill-column: 78
+ *   indent-tabs-mode: t
+ *   tab-width: 8
+ * End:
+ */
+
diff --git a/tclftd2xx.rc b/tclftd2xx.rc
new file mode 100644 (file)
index 0000000..eda22a3
--- /dev/null
@@ -0,0 +1,38 @@
+// tclftd2xx.rc - Copyright (C) 2008 Pat Thoyts <patthoyts@users.sourceforge.net>
+//
+// There is no need to modify this file.
+//
+
+#include <winver.h>
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION   COMMAVERSION
+ PRODUCTVERSION        COMMAVERSION
+ FILEFLAGSMASK 0x3fL
+#ifdef DEBUG
+ FILEFLAGS     VS_FF_DEBUG
+#else
+ FILEFLAGS     0x0L
+#endif
+ FILEOS                VOS__WINDOWS32
+ FILETYPE      VFT_DLL
+ FILESUBTYPE   0x0L
+BEGIN
+    BLOCK "StringFileInfo"
+    BEGIN
+        BLOCK "040904b0"
+        BEGIN
+            VALUE "FileDescription",  "Tcl FTDI D2XX Interface " DOTVERSION "\0"
+            VALUE "OriginalFilename", "tclftd2xx" VERSION ".dll\0"
+            VALUE "CompanyName",      "Pat Thoyts\0"
+            VALUE "FileVersion",      DOTVERSION "\0"
+            VALUE "LegalCopyright",   "Copyright \251 2008 Pat Thoyts\0"
+            VALUE "ProductName",      "Tcl FTDI D2XX Interface " DOTVERSION "\0"
+            VALUE "ProductVersion",   DOTVERSION "\0"
+        END
+    END
+    BLOCK "VarFileInfo"
+    BEGIN
+        VALUE "Translation", 0x409, 1200
+    END
+END