diff -ru gphoto-cvs-clean/gphoto/photopc/README gphoto-cvs/gphoto/photopc/README
--- gphoto-cvs-clean/gphoto/photopc/README	Thu May 27 18:32:05 1999
+++ gphoto-cvs/gphoto/photopc/README	Sun Jul  2 08:12:13 2000
@@ -1,10 +1,10 @@
 /*
-	$Id: README,v 1.1.1.1 1999/05/27 18:32:05 scottf Exp $
+	$Id: README,v 2.19 2000/01/24 20:25:23 crosser Exp $
 */
 
 /*
-	Copyright (c) 1997,1998 Eugene G. Crosser
-	Copyright (c) 1998 Bruce D. Lightner (DOS/Windows support)
+	Copyright (c) 1997-1999 Eugene G. Crosser
+	Copyright (c) 1998,1999 Bruce D. Lightner (DOS/Windows support)
 
 	You may distribute and/or use for any purpose modified or unmodified
 	copies of this software if you preserve the copyright notice above.
@@ -17,12 +17,41 @@
 
 /*
 	$Log: README,v $
-	Revision 1.1.1.1  1999/05/27 18:32:05  scottf
-	gPhoto- digital camera utility
+	Revision 2.19  2000/01/24 20:25:23  crosser
+	do better job in walking thru folder tree; credit to Sergey I. Panov
 	
-	Revision 1.1.1.1  1999/01/07 15:04:02  del
-	Imported 0.2 sources
+	Revision 2.18  1999/11/24 21:51:25  crosser
+	instruction about building from cvs source
 	
+	Revision 2.17  1999/09/19 12:33:11  crosser
+	Mention comlite32 in the README
+	
+	Revision 2.16  1999/08/26 16:11:57  crosser
+	Change README to reflect new directory structure
+	
+	Revision 2.15  1999/08/01 22:13:10  crosser
+	mention reltime priority things
+
+	Revision 2.14  1999/08/01 21:36:54  crosser
+	Modify source to suit ansi2knr
+	(I hate the style that ansi2knr requires but you don't expect me
+	to write another smarter ansi2knr implementation, right?)
+
+	Revision 2.13  1999/04/28 08:28:53  crosser
+	just don't like long copyrights
+
+	Revision 2.12  1999/04/27 20:55:35  lightner
+	Fix MS-DOS/Win32 makefile instructions
+
+	Revision 2.11  1999/03/22 05:59:31  lightner
+	Fix docs: Windows binaries go to win32/
+
+	Revision 2.10  1999/03/21 20:21:04  crosser
+	mention configure
+
+	Revision 2.9  1999/01/17 09:51:16  crosser
+	change Bruce's address
+
 	Revision 2.8  1998/10/18 13:18:27  crosser
 	Put RCS logs and I.D. into the source
 
@@ -67,39 +96,49 @@
 
 This is a library and a command-line frontend to manipulate digital
 still cameras based on Fujitsu chipset and Sierra Imaging firmware.  The
-program is known to work with Agfa, Epson, Olympus Sanyo and Nikon (at
-least CoolPix 900) cameras.
+program is known to work with Agfa, Epson, Olympus, Sanyo and Nikon (at
+least CoolPix 900, but not CoolPix 600!) cameras.
 
 The cameras typically come with software for Windows and for Mac, and no
 description of the protocol.  With this tool, they are managable from a
-UNIX box.  Bruce D. Lightner <lightner@metaflow.com> has added support
+UNIX box.  Bruce D. Lightner <lightner@lightner.net> has added support
 for Win32 and DOS platforms.  Note that the program does not have any
 GUI, it is plain command-line even on Windows.
 
-I tried it under Linux/x86, FreeBSD and Solaris 2.5.1/SPARC, and it
-should be straightforward for other UNIX systems.  Read the top of
-Makefile and edit OPTS according to your system.  For Windows and DOS,
-use Makefile.win and Makefile.dos respectively; no modification should
-be needed.
+I tried it under Linux/x86, FreeBSD and Solaris/SPARC, and it should be
+straightforward for other UNIX systems.
 
 Generally, UNIX system requirements are:
-- ANSI C compiler
+- ANSI C compiler (theoretically should work with K&R but unchecked)
 - select() system call
 - POSIX termios
 - presence of a 16bit integer type
 - serial port (with or without `modem control').
 
-First of all, edit the top portion of Makefile to suit your system.
+On UNIX, first run "./configure".  Then, typing `make' will result
+in building the library and executables in the current directory.
+`make install' will install the executables, library and manual pages.
+If your `make' supports VPATH (e.g. GNU make), it is possible to build
+objects and executables in a different directory; create target directory
+and run /path/to/photopc/configure.  If you are building from CVS source
+see instructions at the end of this file.
 
-Typing `make' will result in building the library and executables in the
-current directory.  `make install' will install the executables and
-manual pages.  `make install.lib' will install the library and the .h
-file.
+To build for DOS and WIN32, chdir to "dos" or "win32" directories
+respectively and there type "make".
 
 The executable parameters are rather clear (hopefully).  Running
-`photopc -h | more' will print the list of options and commands.  If you
-are going to use the library for your own application and need the docs,
-tell me and I will write them.
+`photopc -h | more' will print the list of options and commands.
+If you are going to use the library for your own application and need
+the docs, tell me and I will write them.
+
+On UNIX systems that have sched_setcheduler() function the program
+can set itself "realtime priority".  That makes it less vulnerable to
+possible timeouts caused by high system load, and, more important,
+use high-resolution mode of nanosleep() function.  That means that
+it may run a bit quicker (but you probably will not notice anyway).
+Make the progrem setuid root to use this mode.  There is hopefully no
+danger because it revokes root privileges really quickly (even before
+processing command-line options).
 
 Included file `protocol.htm' contains description of the protocol used
 by the camera.
@@ -107,23 +146,46 @@
 `usage.htm' is a "casual" user's guide, full description is in the man
 pages.
 
-If you run the program on a DOS box, you may want a JPEG viewer; I've
-been told that a good free viewer `LXPIC' can be found at
-http://home.t-online.de/home/stefan.peichl.
-
-Many commands may not be implemented, esp. those specific for newer
-models.  If you know how to do things that the program currently cannot
-do, please let me know.
+If you run the program on a DOS box, you may want a JPEG viewer;
+I've been told that a good free viewer `LXPIC' can be found at
+http://home.t-online.de/home/stefan.peichl.  Also, there is a
+tool that may help in discovering serial protocols (although
+*I* did not use it when I examined that camera's protocol):
+http://www.endymion.com/portfolio/software/comlite32.htm
+
+Many commands may be unimplemented, esp. those specific for newer models.
+If you know how to do things that the program currently cannot do,
+please let me know.
 
 I can be contacted at <crosser@average.org>, fresh version of this tool
 (if any) is at ftp://ftp.average.org/pub/photopc/, related information
 is at http://www.average.org/digicam/.  The same code accompanied by
 Win32 and DOS executables and archived in .zip format can be found at
-http://www.metaflow.com/lightner/bruce/photopc/
+http://www.lightner.net/lightner/bruce/photopc/
 
-Thanks to Jeff Tranter for contributing a man page and a few bugfixes,
+Thanks to Jeff Tranter for contributing the man page and a few bugfixes,
 Bruce Lightner for Windows and DOS support, Thierry Bousch for many
-details of the protocol and advice, and other people who helped me to
-track down problems and learn more about the protocol.
+details of the protocol and advice, Sergey I. Panov for invaluable
+investigation of the folder navigation means and other people who helped
+me to track down problems and learn more about the protocol.
+
 
 Trademarks are properties of their respective respected owners.
+---
+
+APPENDIX: Building from CVS source.
+
+You must have cvs, autoconf and automake installed on your system.
+
+$ cd $your_src_dir
+$ cvs -d :pserver:cvs@cvs.average.org:/var/cvs login
+Password: cvs
+$ cvs -d :pserver:cvs@cvs.average.org:/var/cvs checkout photopc
+$ cd photopc
+$ aclocal
+$ autoheader
+$ automake --add-missing
+$ autoconf
+$ ./configure --$various_options
+$ make
+
diff -ru gphoto-cvs-clean/gphoto/photopc/comio.c gphoto-cvs/gphoto/photopc/comio.c
--- gphoto-cvs-clean/gphoto/photopc/comio.c	Thu May 27 18:32:05 1999
+++ gphoto-cvs/gphoto/photopc/comio.c	Sun Jul  2 07:38:15 2000
@@ -1,15 +1,9 @@
+#ifndef LINT
+static char *rcsid="$Id: comio.c,v 1.3 1998/10/18 13:18:27 crosser Exp $";
+#endif
 
 /*
 	$Log: comio.c,v $
-	Revision 1.1.1.1  1999/05/27 18:32:05  scottf
-	gPhoto- digital camera utility
-	
-	Revision 1.2  1999/04/30 07:14:14  scottf
-	minor changes to remove compilation warnings. prepping for release.
-	
-	Revision 1.1.1.1  1999/01/07 15:04:02  del
-	Imported 0.2 sources
-	
 	Revision 1.3  1998/10/18 13:18:27  crosser
 	Put RCS logs and I.D. into the source
 
@@ -22,7 +16,7 @@
 */
 
 #include <stdio.h>
-/* #include <dos.h> */
+#include <dos.h>
 
 #define MDMDAT1 0x03F8            /* Address of modem port 1 data */
 #define MDMCOM1 0x03FB            /* Address of modem port 1 command */
diff -ru gphoto-cvs-clean/gphoto/photopc/comio.h gphoto-cvs/gphoto/photopc/comio.h
--- gphoto-cvs-clean/gphoto/photopc/comio.h	Thu May 27 18:32:05 1999
+++ gphoto-cvs/gphoto/photopc/comio.h	Sun Jul  2 07:38:15 2000
@@ -1,15 +1,9 @@
 /*
-	$Id: comio.h,v 1.1.1.1 1999/05/27 18:32:05 scottf Exp $
+	$Id: comio.h,v 1.2 1998/10/18 13:18:27 crosser Exp $
 */
 
 /*
 	$Log: comio.h,v $
-	Revision 1.1.1.1  1999/05/27 18:32:05  scottf
-	gPhoto- digital camera utility
-	
-	Revision 1.1.1.1  1999/01/07 15:04:02  del
-	Imported 0.2 sources
-	
 	Revision 1.2  1998/10/18 13:18:27  crosser
 	Put RCS logs and I.D. into the source
 
diff -ru gphoto-cvs-clean/gphoto/photopc/eph_cmd.c gphoto-cvs/gphoto/photopc/eph_cmd.c
--- gphoto-cvs-clean/gphoto/photopc/eph_cmd.c	Sun Jun 13 23:40:37 1999
+++ gphoto-cvs/gphoto/photopc/eph_cmd.c	Sun Jul  2 07:38:15 2000
@@ -1,3 +1,6 @@
+#ifndef LINT
+static char *rcsid="$Id: eph_cmd.c,v 1.16 2000/02/13 11:15:01 crosser Exp $";
+#endif
 
 /*
 	Copyright (c) 1997,1998 Eugene G. Crosser
@@ -14,19 +17,26 @@
 
 /*
 	$Log: eph_cmd.c,v $
-	Revision 1.2  1999/06/13 23:40:37  scottf
-	added update_progress functionality to the photopc library.
-		(GUI won't freeze now :)
-	
-	Revision 1.1.1.1  1999/05/27 18:32:05  scottf
-	gPhoto- digital camera utility
-	
-	Revision 1.2  1999/04/30 07:14:14  scottf
-	minor changes to remove compilation warnings. prepping for release.
-	
-	Revision 1.1.1.1  1999/01/07 15:04:02  del
-	Imported 0.2 sources
+	Revision 1.16  2000/02/13 11:15:01  crosser
+	Kludge null setint for Nikon
 	
+	Revision 1.15  1999/08/01 21:36:54  crosser
+	Modify source to suit ansi2knr
+	(I hate the style that ansi2knr requires but you don't expect me
+	to write another smarter ansi2knr implementation, right?)
+
+	Revision 1.14  1999/07/28 19:56:31  crosser
+	reorder includes
+
+	Revision 1.13  1999/03/21 20:22:09  crosser
+	change retry logic for first block (for Agfa 307)
+
+	Revision 1.12  1999/03/06 13:37:08  crosser
+	Convert to autoconf-style
+
+	Revision 1.11  1999/01/21 09:12:56  crosser
+	fix of retry logic from Richard Sharman
+
 	Revision 1.10  1998/10/18 13:18:27  crosser
 	Put RCS logs and I.D. into the source
 
@@ -60,25 +70,32 @@
 	
 */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include <stdio.h>
 #include "eph_io.h"
 #include "eph_priv.h"
-#include "../src/gphoto.h"
-#include "../src/util.h"
-#include <stdio.h>
 
 #define TMPBUF_SIZE (2048)
 
 #define MAYRETRY(rc) ((rc == -2) || (rc == NAK))
 
-int eph_writecmd(eph_iob *iob,char *data,size_t length) {
+int
+eph_writecmd(eph_iob *iob,char *data,size_t length)
+{
 	return eph_writepkt(iob,PKT_CMD,SEQ_CMD,data,length);
 }
 
-int eph_writeicmd(eph_iob *iob,char *data,size_t length) {
+int
+eph_writeicmd(eph_iob *iob,char *data,size_t length)
+{
 	return eph_writepkt(iob,PKT_CMD,SEQ_INITCMD,data,length);
 }
 
-int eph_setispeed(eph_iob *iob,long val) {
+int
+eph_setispeed(eph_iob *iob,long val)
+{
 	unsigned char buf[6];
 	int rc;
 	int count=0;
@@ -99,7 +116,9 @@
 	return rc;
 }
 
-int eph_setint(eph_iob *iob,int reg,long val) {
+int
+eph_setint(eph_iob *iob,int reg,long val)
+{
 	unsigned char buf[6];
 	int rc;
 	int count=0;
@@ -122,7 +141,30 @@
 	return rc;
 }
 
-int eph_getint(eph_iob *iob,int reg,long *val) {
+int
+eph_setnullint(eph_iob *iob,int reg)
+{
+	unsigned char buf[2];
+	int rc;
+	int count=0;
+
+	buf[0]=CMD_SETINT;
+	buf[1]=reg;
+
+writeagain:
+	if ((rc=eph_writecmd(iob,buf,2))) return rc;
+	rc=eph_waitack(iob,(reg == REG_FRAME)?BIGACKTIMEOUT:ACKTIMEOUT);
+	if (MAYRETRY(rc) && (count++ < RETRIES)) goto writeagain;
+	if (count >= RETRIES)
+		eph_error(iob,ERR_EXCESSIVE_RETRY,
+				"excessive retries on setnullint");
+
+	return rc;
+}
+
+int
+eph_getint(eph_iob *iob,int reg,long *val)
+{
 	unsigned char buf[4];
 	eph_pkthdr pkt;
 	int rc;
@@ -154,7 +196,9 @@
 	return rc;
 }
 
-int eph_action(eph_iob *iob,int reg,char *val,size_t length) {
+int
+eph_action(eph_iob *iob,int reg,char *val,size_t length)
+{
 	unsigned char buf[2050];
 	int rc;
 	int count=0;
@@ -182,7 +226,9 @@
 	return rc;
 }
 
-int eph_setvar(eph_iob *iob,int reg,char *val,off_t length) {
+int
+eph_setvar(eph_iob *iob,int reg,char *val,off_t length)
+{
 	unsigned char buf[2048];
 	int rc=0,seq=-1;
 	int count=0;
@@ -231,7 +277,9 @@
 	return rc;
 }
 
-int eph_getvar(eph_iob *iob,int reg,char **buffer,off_t *bufsize) {
+int
+eph_getvar(eph_iob *iob,int reg,char **buffer,off_t *bufsize)
+{
 	unsigned char buf[2];
 	eph_pkthdr pkt;
 	int rc;
@@ -242,9 +290,6 @@
 	char *ptr;
 	char *tmpbuf=NULL;
 	size_t tmpbufsize=0;
-	int oldbufsize;
-
-	oldbufsize = (int)*bufsize;
 
 	if ((buffer == NULL) && (iob->storecb == NULL)) {
 		eph_error(iob,ERR_BADARGS,
@@ -270,10 +315,6 @@
 	if ((rc=eph_writecmd(iob,buf,2))) return rc;
 	index=0;
 readagain:
-	if (reg == 0x0e)
-		/* gPhoto Call */
-		update_progress((float)index/(float)oldbufsize);
-
 	if (buffer) { /* read to memory reallocating it */
 		if (((*bufsize) - index) < 2048) {
 			if (iob->debug)
@@ -304,8 +345,11 @@
 	rc=eph_readpkt(iob,&pkt,ptr,&readsize,
 			(expect || ((reg != REG_IMG) || (reg != REG_TMN)))?
 						DATATIMEOUT:BIGDATATIMEOUT);
-	if (MAYRETRY(rc) && (expect == 0) && (count++ < RETRIES))
-		goto writeagain;
+	if (MAYRETRY(rc) && (expect == 0) && (count++ < RETRIES)) {
+		eph_writenak(iob);
+		if (rc == -2) goto readagain;
+		else goto writeagain;
+	}
 	if ((rc == 0) &&
 	    ((pkt.seq == expect) || (pkt.seq  == (expect-1)))) {
 		count=0;
@@ -338,7 +382,5 @@
 	if (count >= RETRIES)
 		eph_error(iob,ERR_EXCESSIVE_RETRY,
 				"excessive retries on getvar");
-	if (reg == 0x0e)
-		update_progress(0);
 	return rc;
 }
diff -ru gphoto-cvs-clean/gphoto/photopc/eph_err.c gphoto-cvs/gphoto/photopc/eph_err.c
--- gphoto-cvs-clean/gphoto/photopc/eph_err.c	Thu May 27 18:32:05 1999
+++ gphoto-cvs/gphoto/photopc/eph_err.c	Sun Jul  2 07:38:15 2000
@@ -1,3 +1,6 @@
+#ifndef LINT
+static char *rcsid="$Id: eph_err.c,v 2.6 1999/08/01 21:36:54 crosser Exp $";
+#endif
 
 /*
 	Copyright (c) 1997,1998 Eugene G. Crosser
@@ -14,15 +17,17 @@
 
 /*
 	$Log: eph_err.c,v $
-	Revision 1.1.1.1  1999/05/27 18:32:05  scottf
-	gPhoto- digital camera utility
-	
-	Revision 1.2  1999/04/30 07:14:14  scottf
-	minor changes to remove compilation warnings. prepping for release.
-	
-	Revision 1.1.1.1  1999/01/07 15:04:02  del
-	Imported 0.2 sources
-	
+	Revision 2.6  1999/08/01 21:36:54  crosser
+	Modify source to suit ansi2knr
+	(I hate the style that ansi2knr requires but you don't expect me
+	to write another smarter ansi2knr implementation, right?)
+
+	Revision 2.5  1999/07/28 19:57:52  crosser
+	reorder includes
+
+	Revision 2.4  1999/03/06 13:37:08  crosser
+	Convert to autoconf-style
+
 	Revision 2.3  1998/10/18 13:18:27  crosser
 	Put RCS logs and I.D. into the source
 
@@ -40,12 +45,15 @@
 	
 */
 
-#include "eph_io.h"
-#include "eph_priv.h"
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 #include <string.h>
 #include <errno.h>
 #include <stdarg.h>
 #include <stdio.h>
+#include "eph_io.h"
+#include "eph_priv.h"
 
 static char *eph_errmsg[] = {
 	/* 10001 */	"Data too long",
@@ -65,11 +73,21 @@
 	/* 10015 */	"",
 };
 
+#ifndef HAVE_STRERROR
+char *strerror(int err) {
+	static char buf[32];
+	sprintf(buf,"System error %d",err);
+	return buf;
+}
+#endif
+
 /*
   We do not do any buffer override checks here because we are sure
   that the function is called *only* from within our library.
 */
-void eph_error (eph_iob *iob,int err,char *fmt,...) {
+void
+eph_error (eph_iob *iob,int err,char *fmt,...)
+{
 	va_list ap;
 	char *msg=NULL;
 	char msgbuf[512];
diff -ru gphoto-cvs-clean/gphoto/photopc/eph_io.c gphoto-cvs/gphoto/photopc/eph_io.c
--- gphoto-cvs-clean/gphoto/photopc/eph_io.c	Sat Oct  2 23:41:37 1999
+++ gphoto-cvs/gphoto/photopc/eph_io.c	Sun Jul  2 07:38:15 2000
@@ -1,7 +1,10 @@
+#ifndef LINT
+static char *rcsid="$Id: eph_io.c,v 2.17 2000/02/17 21:29:54 crosser Exp $";
+#endif
 
 /*
-	Copyright (c) 1997,1998 Eugene G. Crosser
-	Copyright (c) 1998 Bruce D. Lightner (DOS/Windows support)
+	Copyright (c) 1997-1999 Eugene G. Crosser
+	Copyright (c) 1998,1999 Bruce D. Lightner (DOS/Windows support)
 
 	You may distribute and/or use for any purpose modified or unmodified
 	copies of this software if you preserve the copyright notice above.
@@ -14,18 +17,33 @@
 
 /*
 	$Log: eph_io.c,v $
-	Revision 1.2  1999/10/02 23:41:37  ole
-	FreeBSD (and Konica/Q-M200) patch by gphoto@fujisawa.gr.jp (Toshiki Fujisawa)
-	
-	Revision 1.1.1.1  1999/05/27 18:32:05  scottf
-	gPhoto- digital camera utility
-	
-	Revision 1.2  1999/04/30 07:14:14  scottf
-	minor changes to remove compilation warnings. prepping for release.
-	
-	Revision 1.1.1.1  1999/01/07 15:04:02  del
-	Imported 0.2 sources
+	Revision 2.17  2000/02/17 21:29:54  crosser
+	final cleanup for 3.04, change version
+	change debugging levels
 	
+	Revision 2.16  1999/08/01 21:36:54  crosser
+	Modify source to suit ansi2knr
+	(I hate the style that ansi2knr requires but you don't expect me
+	to write another smarter ansi2knr implementation, right?)
+
+	Revision 2.15  1999/07/28 19:29:18  crosser
+	resort includes
+
+	Revision 2.14  1999/04/22 04:14:54  crosser
+	avoid GCC-isms
+
+	Revision 2.13  1999/03/27 23:54:37  crosser
+	backed out adding WRTDELAY: already done in eph_priv.h
+
+	Revision 2.12  1999/03/22 05:59:31  lightner
+	Add WRTDELAY to SMART CHUNKED WRITE's WRITE()
+
+	Revision 2.11  1999/03/06 13:37:08  crosser
+	Convert to autoconf-style
+
+	Revision 2.10  1999/02/10 22:09:36  crosser
+	strerror needs string.h with glibc2
+
 	Revision 2.9  1998/10/18 13:18:27  crosser
 	Put RCS logs and I.D. into the source
 
@@ -67,20 +85,36 @@
 	
 */
 
-#include "eph_io.h"
-#include "eph_priv.h"
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 #include <sys/types.h>
 #ifdef UNIX
-#include <time.h>
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
+#endif
 #include <errno.h>
 #include <stdio.h>
+#include <string.h>
 
 #ifndef UNIX
 #include "usleep.h"
 #endif
 
+#include "eph_io.h"
+#include "eph_priv.h"
+
 #ifdef INT16
 typedef unsigned INT16 uint16;
 #endif
@@ -91,15 +125,15 @@
 #define ERRNO errno
 #endif
 
-#ifdef __FreeBSD__ /* by fujisawa */
-#undef HAVE_NANOSLEEP
-#endif
-
 #ifdef HAVE_NANOSLEEP
 
-void shortsleep(unsigned long useconds) {
-	struct timespec ts={tv_sec: (long int)(useconds/1000000),
-			tv_nsec: (long int)(useconds%1000000)*1000ul};
+void
+shortsleep(unsigned long useconds)
+{
+	struct timespec ts;
+
+	ts.tv_sec=(long int)(useconds/1000000);
+	ts.tv_nsec=(long int)(useconds%1000000)*1000ul;
 
 	nanosleep(&ts,NULL);
 }
@@ -133,7 +167,9 @@
 
 #define WRITE(x,y,z) (dos_write(x,y,z) != z)
 
-int dos_write(int fd, void *buf, int length) {
+int
+dos_write(int fd, void *buf, int length)
+{
 	int i;
 	unsigned char *p = buf;
 
@@ -148,7 +184,9 @@
 
 #define WRITE(x,y,z) win_write(x,y,z)
 
-int win_write(HANDLE fd,void *buf,DWORD length) {
+int
+win_write(HANDLE fd,void *buf,DWORD length)
+{
 	DWORD nwrit;
 
 	if (!WriteFile(fd,buf,length,&nwrit,NULL) || (nwrit != length))
@@ -162,10 +200,12 @@
 #define WRITE(x,y,z) (write(x,y,z) != z)
 
 #else
-#error "platform not defined"
+ # error "platform not defined"
 #endif
 
-int eph_writepkt(eph_iob *iob,int typ,int seq,char *data,size_t length) {
+int
+eph_writepkt(eph_iob *iob,int typ,int seq,char *data,size_t length)
+{
 	uint16 crc=0;
 	unsigned char buf[2054];
 	int i=0,j;
@@ -186,7 +226,7 @@
 	}
 	buf[i++]=crc&0xff;
 	buf[i++]=crc>>8;
-	if (iob->debug) {
+	if (iob->debug > 1) {
 		printf("> (%d)",i);
 		for (j=0;j<i;j++) {
 			printf(" %02x",buf[j]);
@@ -197,7 +237,7 @@
 #if defined(SINGLE_BURST_WRITE)
 	shortsleep(WRTPKTDELAY);
 	if (WRITE(iob->fd,buf,i)) {
-/*eph_error(iob,ERRNO,"pkt write error %s",strerror(ERRNO));*/
+		eph_error(iob,ERRNO,"pkt write error %s",strerror(ERRNO));
 		return -1;
 	}
 #elif defined(BYTE_BY_BYTE_WRITE)
@@ -210,7 +250,7 @@
 	for (j=0;j<i;j++) {
 		shortsleep(WRTDELAY);
 		if (WRITE(iob->fd,buf+j,1)) {
-/*eph_error(iob,ERRNO,"pkt write error %s",strerror(ERRNO));*/
+			eph_error(iob,ERRNO,"pkt write error %s",strerror(ERRNO));
 			return -1;
 		}
 /*
@@ -227,9 +267,8 @@
 						:(i-chunk[j].offset);
 		shortsleep(chunk[j].delay);
 		if (WRITE(iob->fd,buf+chunk[j].offset,sz)) {
-/*
-eph_error(iob,ERRNO,"pkt write chunk %d(%d) error %s", j,(int)sz,strerror(ERRNO));
-*/
+			eph_error(iob,ERRNO,"pkt write chunk %d(%d) error %s",
+					j,(int)sz,strerror(ERRNO));
 			return -1;
 		}
 	}
@@ -237,47 +276,56 @@
 	return 0;
 }
 
-void eph_writeinit(eph_iob *iob) {
+void
+eph_writeinit(eph_iob *iob)
+{
 	unsigned char init=0;
 
-	if (iob->debug) printf("> INIT 00\n");
+	if (iob->debug > 1) printf("> INIT 00\n");
 	shortsleep(WRTDELAY);
 	if (WRITE(iob->fd,&init,1)) {
-/*eph_error(iob,ERRNO,"init write error %s",strerror(ERRNO));*/
+		eph_error(iob,ERRNO,"init write error %s",strerror(ERRNO));
 	}
 }
 
-void eph_writeack(eph_iob *iob) {
+void
+eph_writeack(eph_iob *iob)
+{
 	unsigned char ack=ACK;
 
-	if (iob->debug) printf("> ACK 06\n");
+	if (iob->debug > 1) printf("> ACK 06\n");
 	shortsleep(WRTDELAY);
 	if (WRITE(iob->fd,&ack,1)) {
-/*eph_error(iob,ERRNO,"ack write errot %s",strerror(ERRNO));*/
+		eph_error(iob,ERRNO,"ack write errot %s",strerror(ERRNO));
 	}
 }
 
-void eph_writenak(eph_iob *iob) {
+void
+eph_writenak(eph_iob *iob)
+{
 	unsigned char nak=NAK;
 
-	if (iob->debug) printf("> NAK 11\n");
+	if (iob->debug > 1) printf("> NAK 11\n");
 	shortsleep(WRTDELAY);
 	if (WRITE(iob->fd,&nak,1)) {
-/*eph_error(iob,ERRNO,"nak write error %s",strerror(ERRNO));*/
+		eph_error(iob,ERRNO,"nak write error %s",strerror(ERRNO));
 	}
 }
 
-int eph_readpkt(eph_iob *iob,eph_pkthdr *pkthdr,char *buffer,size_t *bufsize,long timeout_usec) {
+int
+eph_readpkt(eph_iob *iob,eph_pkthdr *pkthdr,char *buffer,
+					size_t *bufsize,long timeout_usec)
+{
 	uint16 length,got;
 	uint16 crc1=0,crc2;
 	unsigned char buf[4];
 	int i,rc;
 
 	i=eph_readt(iob,buf,1,timeout_usec,&rc);
-	if (iob->debug)
+	if (iob->debug > 1)
 		printf ("pktstart: i=%d rc=%d char=0x%02x\n",i,rc,*buf);
 	if (i < 0) {
-/*eph_error(iob,ERRNO,"pkt start read error %s",strerror(ERRNO));*/
+		eph_error(iob,ERRNO,"pkt start read error %s",strerror(ERRNO));
 		return -1;
 	} else if ((i == 0) && (rc == 0)) {
 		eph_error(iob,ERR_TIMEOUT,"pkt start read timeout (%ld)",
@@ -299,7 +347,8 @@
 	}
 	if (got != 3) {
 		if (i < 0) {
-/*eph_error(iob,ERRNO,"pkt hdr read error %s (got %d)",strerror(ERRNO),got);*/
+			eph_error(iob,ERRNO,"pkt hdr read error %s (got %d)",
+					strerror(ERRNO),got);
 			return -1;
 		} else if ((i == 0) && (rc == 0)) {
 			eph_error(iob,ERR_TIMEOUT,"pkt hdr read timeout (%ld)",
@@ -311,7 +360,7 @@
 			return -1;
 		}
 	}
-	if (iob->debug) printf("header: %02x %02x %02x %02x\n",
+	if (iob->debug > 1) printf("header: %02x %02x %02x %02x\n",
 				buf[0],buf[1],buf[2],buf[3]);
 	pkthdr->seq=buf[1];
 	length=(buf[3]<<8)|buf[2];
@@ -328,7 +377,7 @@
 	}
 	if (got != length) {
 		if (i < 0) {
-/*eph_error(iob,ERRNO,"pkt data read error %s",strerror(ERRNO));*/
+			eph_error(iob,ERRNO,"pkt data read error %s",strerror(ERRNO));
 			return -1;
 		} else if ((i == 0) && (rc == 0)) {
 			eph_error(iob,ERR_TIMEOUT,"pkt data read timeout (%ld)",
@@ -349,11 +398,11 @@
 	while ((i=eph_readt(iob,buf+got,2-got,DATATIMEOUT,&rc)) > 0) {
 		got+=i;
 	}
-	if (iob->debug)
+	if (iob->debug > 1)
 		printf ("crc: %02x %02x i=%d rc=%d\n",buf[0],buf[1],i,rc);
 	if (got != 2) {
 		if (i < 0) {
-/*eph_error(iob,ERRNO,"pkt crc read error %s",strerror(ERRNO));*/
+			eph_error(iob,ERRNO,"pkt crc read error %s",strerror(ERRNO));
 			return -1;
 		} else if ((i == 0) && (rc == 0)) {
 			eph_error(iob,ERR_TIMEOUT,"pkt crc read timeout (%ld)",
@@ -373,16 +422,16 @@
 			"crc received=0x%04x counted=0x%04x",crc2,crc1);
 		return -1;
 	}
-	if (iob->debug) {
+	if (iob->debug > 1) {
 		int j;
 
 		printf("< %d,%d (%d)",pkthdr->typ,pkthdr->seq,length);
-		if (iob->debug > 1) for (j=0;j<length;j++) {
+		if (iob->debug > 2) for (j=0;j<length;j++) {
 			printf(" %02x",(unsigned char)buffer[j]);
 		} else printf(" ...");
 		printf("\n");
 		printf("< %d,%d (%d)",pkthdr->typ,pkthdr->seq,length);
-		if (iob->debug > 1) for (j=0;j<length;j++) {
+		if (iob->debug > 2) for (j=0;j<length;j++) {
 			printf(" %c ",(buffer[j] >= ' ' && buffer[j] < 127)
 							? buffer[j] : '.');
 		} else printf(" ...");
@@ -392,15 +441,17 @@
 	return 0;
 }
 
-int eph_flushinput(eph_iob *iob) {
+int
+eph_flushinput(eph_iob *iob)
+{
 	unsigned char buf;
 	int i,rc;
 
 	i=eph_readt(iob,&buf,1,0L,&rc);
-	if (iob->debug)
+	if (iob->debug > 1)
 		printf ("< %02x amount=%d rc=%d\n",buf,i,rc);
 	if (i < 0) {
-/*eph_error(iob,ERRNO,"flushinput read error %s",strerror(ERRNO));*/
+		eph_error(iob,ERRNO,"flushinput read error %s",strerror(ERRNO));
 		return -1;
 	} else if ((i == 0) && (rc == 0)) {
 		if (iob->debug)
@@ -412,15 +463,17 @@
 	}
 }
 
-int eph_waitchar(eph_iob *iob,unsigned long timeout_usec) {
+int
+eph_waitchar(eph_iob *iob,unsigned long timeout_usec)
+{
 	unsigned char buf;
 	int i,rc;
 
 	i=eph_readt(iob,&buf,1,timeout_usec,&rc);
-	if (iob->debug)
+	if (iob->debug > 1)
 		printf ("< %02x amount=%d rc=%d\n",buf,i,rc);
 	if (i < 0) {
-/*eph_error(iob,ERRNO,"waitchar read error %s",strerror(ERRNO));*/
+		eph_error(iob,ERRNO,"waitchar read error %s",strerror(ERRNO));
 		return -1;
 	} else if ((i == 0) && (rc == 0)) {
 		eph_error(iob,ERR_TIMEOUT,"waitchar read timeout (%ld)",
@@ -433,7 +486,9 @@
 	return buf;
 }
 
-int eph_waitack(eph_iob *iob,long timeout_usec) {
+int
+eph_waitack(eph_iob *iob,long timeout_usec)
+{
 	int rc;
 	if ((rc=eph_waitchar(iob,timeout_usec)) == ACK) return 0;
 	if ((rc != DC1) && (rc != NAK))
@@ -441,7 +496,9 @@
 	return rc;
 }
 
-int eph_waitcomplete(eph_iob *iob) {
+int
+eph_waitcomplete(eph_iob *iob)
+{
 	int rc;
 	if ((rc=eph_waitchar(iob,CMDTIMEOUT)) == 0x05) return 0;
 	if ((rc != DC1) && (rc != NAK))
@@ -449,7 +506,9 @@
 	return rc;
 }
 
-int eph_waitsig(eph_iob *iob) {
+int
+eph_waitsig(eph_iob *iob)
+{
 	int rc,count=SKIPNULS;
 	while (((rc=eph_waitchar(iob,INITTIMEOUT)) == 0) && (count-- > 0)) ;
 	if (rc == 0x15) return 0;
@@ -457,7 +516,9 @@
 	return rc;
 }
 
-int eph_waiteot(eph_iob *iob) {
+int
+eph_waiteot(eph_iob *iob)
+{
 	int rc;
 	if ((rc=eph_waitchar(iob,EODTIMEOUT)) == 0xff) return 0;
 	if ((rc != DC1) && (rc != NAK))
diff -ru gphoto-cvs-clean/gphoto/photopc/eph_io.h gphoto-cvs/gphoto/photopc/eph_io.h
--- gphoto-cvs-clean/gphoto/photopc/eph_io.h	Thu May 27 18:32:06 1999
+++ gphoto-cvs/gphoto/photopc/eph_io.h	Sun Jul  2 07:42:16 2000
@@ -1,5 +1,5 @@
 /*
-	$Id: eph_io.h,v 1.1.1.1 1999/05/27 18:32:06 scottf Exp $
+	$Id: eph_io.h,v 2.10 2000/02/13 11:15:01 crosser Exp $
 */
 
 /*
@@ -17,11 +17,15 @@
 
 /*
 	$Log: eph_io.h,v $
-	Revision 1.1.1.1  1999/05/27 18:32:06  scottf
-	gPhoto- digital camera utility
+	Revision 2.10  2000/02/13 11:15:01  crosser
+	Kludge null setint for Nikon
 	
-	Revision 1.1.1.1  1999/01/07 15:04:02  del
-	Imported 0.2 sources
+	Revision 2.9  1999/12/11 14:10:15  crosser
+	Support sgtty terminal control
+	Proper "fake speed" handling (needed two values)
+	
+	Revision 2.8  1999/12/01 21:41:23  crosser
+	add "pseudo" speed
 	
 	Revision 2.7  1998/10/18 13:18:27  crosser
 	Put RCS logs and I.D. into the source
@@ -55,12 +59,23 @@
 #ifndef _EPH_IO_H
 #define _EPH_IO_H
 
+#define USE_TERMIOS
+
 #include <sys/types.h>
 #ifdef DOS
 typedef long off_t;
 #endif
 #if defined(UNIX)
-#include <termios.h>
+#if defined(USE_TERMIOS)
+# include <termios.h>
+#elif defined(USE_SGTTY)
+# include <sgtty.h>
+#elif defined(USE_TERMIO)
+#include <termio.h>
+ # error "termio unsupported, sorry"
+#else
+ # error "no termios, sgtty or termio defined, no way to control the tty"
+#endif
 #elif defined(MSWINDOWS)
 #include <windows.h>
 #endif
@@ -80,7 +95,13 @@
 	int debug;
 #if defined(UNIX)
 	int fd;
+#if defined(USE_TERMIOS)
 	struct termios savetios;
+#elif defined(USE_SGTTY)
+	struct sgttyb savesgtty;
+#elif defined(USE_TERMIO)
+	struct termio savetio;
+#endif
 #elif defined(MSWINDOWS)
 	HANDLE fd;
 	DCB savedcb;
@@ -96,11 +117,13 @@
 		void (*runcb)(off_t count),
 		int (*storecb)(char *data,size_t size),
 		int debug);
-int eph_open(eph_iob *iob,char *device_name,long speed);
+int eph_open(eph_iob *iob,char *device_name,long speed,
+		long defttspeed,long ttspeed);
 int eph_close(eph_iob *iob,int newmodel);
 void eph_free(eph_iob *iob);
 
 int eph_setint(eph_iob *iob,int reg,long val);
+int eph_setnullint(eph_iob *iob,int reg);
 int eph_getint(eph_iob *iob,int reg,long *val);
 int eph_action(eph_iob *iob,int reg,char *val,size_t length);
 int eph_setvar(eph_iob *iob,int reg,char *val,off_t length);
diff -ru gphoto-cvs-clean/gphoto/photopc/eph_iob.c gphoto-cvs/gphoto/photopc/eph_iob.c
--- gphoto-cvs-clean/gphoto/photopc/eph_iob.c	Thu May 27 18:32:06 1999
+++ gphoto-cvs/gphoto/photopc/eph_iob.c	Sun Jul  2 07:38:15 2000
@@ -1,3 +1,6 @@
+#ifndef LINT
+static char *rcsid="$Id: eph_iob.c,v 2.7 1999/12/11 14:10:15 crosser Exp $";
+#endif
 
 /*
 	Copyright (c) 1997,1998 Eugene G. Crosser
@@ -14,15 +17,21 @@
 
 /*
 	$Log: eph_iob.c,v $
-	Revision 1.1.1.1  1999/05/27 18:32:06  scottf
-	gPhoto- digital camera utility
-	
-	Revision 1.2  1999/04/30 07:14:14  scottf
-	minor changes to remove compilation warnings. prepping for release.
-	
-	Revision 1.1.1.1  1999/01/07 15:04:02  del
-	Imported 0.2 sources
-	
+	Revision 2.7  1999/12/11 14:10:15  crosser
+	Support sgtty terminal control
+	Proper "fake speed" handling (needed two values)
+	
+	Revision 2.6  1999/08/01 21:36:54  crosser
+	Modify source to suit ansi2knr
+	(I hate the style that ansi2knr requires but you don't expect me
+	to write another smarter ansi2knr implementation, right?)
+
+	Revision 2.5  1999/07/28 19:58:59  crosser
+	reorder includes
+
+	Revision 2.4  1999/03/06 13:37:08  crosser
+	Convert to autoconf-style
+
 	Revision 2.3  1998/10/18 13:18:27  crosser
 	Put RCS logs and I.D. into the source
 
@@ -40,30 +49,42 @@
 	
 */
 
-#include "eph_io.h"
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#ifdef STDC_HEADERS
 #include <stdlib.h>
 #include <string.h>
+#endif
 #include <stdio.h>
+#include "eph_io.h"
 
-static void deferrorcb(int errcode,char *errstr) {
-	return;
-	// fprintf(stderr,"Error %d: %s\n",errcode,errstr);
+static void
+deferrorcb(int errcode,char *errstr)
+{
+	fprintf(stderr,"Error %d: %s\n",errcode,errstr);
 }
 
-static void *defrealloccb(void *old,size_t length) {
+static void *
+defrealloccb(void *old,size_t length)
+{
 	if (old) return realloc(old,length);
 	else return malloc(length);
 }
 
-static void defruncb(off_t count) {
+static void
+defruncb(off_t count)
+{
 	return;
 }
 
-eph_iob *eph_new(void (*errorcb)(int errcode,char *errstr),
+eph_iob *
+eph_new(void (*errorcb)(int errcode,char *errstr),
 		void *(*realloccb)(void *old,size_t length),
 		void (*runcb)(off_t count),
 		int (*storecb)(char *data,size_t size),
-		int debug) {
+		int debug)
+{
 	eph_iob *iob;
 
 	iob=(eph_iob *)malloc(sizeof(eph_iob));
@@ -83,15 +104,23 @@
 	memset((char*)&iob->savetimeouts,0,sizeof(iob->savetimeouts));
 #elif defined(UNIX)
 	iob->fd=-1;
+#if defined(USE_TERMIOS)
 	memset((char*)&iob->savetios,0,sizeof(iob->savetios));
+#elif defined(USE_SGTTY)
+	memset((char*)&iob->savesgtty,0,sizeof(iob->savesgtty));
+#elif defined(USE_TERMIO)
+	memset((char*)&iob->savetio,0,sizeof(iob->savetio));
+#endif
 #elif defined(DOS)
 	iob->fd=-1;
 #else
-#error "platform not defined"
+ # error "platform not defined"
 #endif
 	return iob;
 }
 
-void eph_free(eph_iob *iob) {
+void
+eph_free(eph_iob *iob)
+{
 	free(iob);
 }
diff -ru gphoto-cvs-clean/gphoto/photopc/eph_open.c gphoto-cvs/gphoto/photopc/eph_open.c
--- gphoto-cvs-clean/gphoto/photopc/eph_open.c	Thu May 27 18:32:06 1999
+++ gphoto-cvs/gphoto/photopc/eph_open.c	Sun Jul  2 07:38:15 2000
@@ -1,3 +1,6 @@
+#ifndef LINT
+static char *rcsid="$Id: eph_open.c,v 2.21 1999/12/13 23:26:52 crosser Exp $";
+#endif
 
 /*
 	Copyright (c) 1997,1998 Eugene G. Crosser
@@ -14,15 +17,30 @@
 
 /*
 	$Log: eph_open.c,v $
-	Revision 1.1.1.1  1999/05/27 18:32:06  scottf
-	gPhoto- digital camera utility
+	Revision 2.21  1999/12/13 23:26:52  crosser
+	Fix minor bugs in sgtty support, reported to work now.
 	
-	Revision 1.2  1999/04/30 07:14:14  scottf
-	minor changes to remove compilation warnings. prepping for release.
+	Revision 2.20  1999/12/11 14:10:15  crosser
+	Support sgtty terminal control
+	Proper "fake speed" handling (needed two values)
 	
-	Revision 1.1.1.1  1999/01/07 15:04:02  del
-	Imported 0.2 sources
+	Revision 2.19  1999/12/01 21:41:23  crosser
+	add "pseudo" speed
 	
+	Revision 2.18  1999/08/01 21:36:54  crosser
+	Modify source to suit ansi2knr
+	(I hate the style that ansi2knr requires but you don't expect me
+	to write another smarter ansi2knr implementation, right?)
+
+	Revision 2.17  1999/03/06 13:37:08  crosser
+	Convert to autoconf-style
+
+	Revision 2.16  1999/02/10 22:09:36  crosser
+	strerror needs string.h with glibc2
+
+	Revision 2.15  1998/12/20 21:49:38  crosser
+	move flushinput to more proper place
+
 	Revision 2.14  1998/10/18 13:18:27  crosser
 	Put RCS logs and I.D. into the source
 
@@ -84,23 +102,33 @@
 	
 */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 #include "eph_io.h"
 #include "eph_priv.h"
 #include <sys/types.h>
 #if defined(MSWINDOWS)
 #include "usleep.h"
 #elif defined(UNIX)
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
 #include <termios.h>
 #elif defined(DOS)
 #include "comio.h"
 #include "usleep.h"
 #else
-#error platform not defined
+ # error platform not defined
 #endif
 #include <stdio.h>
+#ifdef STDC_HEADERS
 #include <stdlib.h>
+#include <string.h>
+#endif
+#ifdef HAVE_FCNTL_H
 #include <fcntl.h>
+#endif
 #include <errno.h>
 
 #ifdef MSWINDOWS
@@ -109,28 +137,31 @@
 #define ERRNO errno
 #endif
 
+#define DEFSPEED 19200
+
 #if defined(MSWINDOWS)
 
-#define DEFSPEED 19200
 #define CLOSE CloseHandle
 
 #elif defined(UNIX)
 
-#define DEFSPEED EXTA
 #define CLOSE close
 
 #elif defined(DOS)
 
-#define DEFSPEED 19200
 #define CLOSE(x)  ttclose()
 
-void exit_cleanup(void) {
+void
+exit_cleanup(void)
+{
 	ttclose();
 }
 
 #define ABORT 0
 
-int c_break(void) {
+int
+c_break(void)
+{
 	printf("\naborting program...%c\n", 7);
 	ttclose();
 	exit(255);	/* will call any exit handlers */
@@ -138,70 +169,135 @@
 }
 
 #else
-#error platform not defined
+ # error platform not defined
 #endif
 
-int eph_open(eph_iob *iob,char *devname,long speed) {
-#if defined(MSWINDOWS)
-	DCB dcb = { 0 };
-	char commtext[80];
-#elif defined(UNIX)
-	struct termios tios;
+#ifdef UNIX
+speed_t
+speed2flag(long ttspeed)
+{
 	speed_t tspeed;
-#elif defined(DOS)
-	int port;
-#else
-#error platform not defined
-#endif
-	long ephspeed;
-	int rc;
-	int count=0;
 
-	if (speed == 0) speed=MAX_SPEED;
-
-	switch (speed) {
+	switch (ttspeed) {
+	case 50:
+		tspeed=B50;
+		break;
+	case 75:
+		tspeed=B75;
+		break;
+	case 150:
+		tspeed=B150;
+		break;
+	case 300:
+		tspeed=B300;
+		break;
+	case 600:
+		tspeed=B600;
+		break;
+	case 1200:
+		tspeed=B1200;
+		break;
+	case 2400:
+		tspeed=B2400;
+		break;
+	case 4800:
+		tspeed=B4800;
+		break;
 	case 9600:
-#ifdef UNIX
 		tspeed=B9600;
-#endif
-		ephspeed=1;	break;
+		break;
 	case 19200:
-#ifdef UNIX
+#ifdef B19200
+		tspeed=B19200;
+#else
 		tspeed=EXTA;
 #endif
-		ephspeed=2;	break;
+		break;
 	case 38400:
-#ifdef UNIX
+#ifdef B38400
+		tspeed=B38400;
+#else
 		tspeed=EXTB;
 #endif
-		ephspeed=3;	break;
+		break;
 	case 57600:
-#ifdef UNIX
 #ifdef B57600
 		tspeed=B57600;
 #else
-		eph_error(iob,ERR_BADSPEED,"specified speed %ld unsupported",
-									speed);
-		return -1;
+		tspeed=(speed_t)-1;
 #endif
-#endif
-		ephspeed=4;	break;
+		break;
 	case 115200:
-#ifdef UNIX
 #ifdef B115200
 		tspeed=B115200;
 #else
-		eph_error(iob,ERR_BADSPEED,"specified speed %ld unsupported",
-									speed);
-		return -1;
+		tspeed=(speed_t)-1;
 #endif
+		break;
+	default:
+		tspeed=(speed_t)-1;
+		break;
+	}
+	return tspeed;
+}
+#endif /* UNIX */
+
+int
+eph_open(eph_iob *iob,char *devname,long speed,long defttspeed,long ttspeed)
+{
+#if defined(MSWINDOWS)
+	DCB dcb = { 0 };
+	char commtext[80];
+#elif defined(UNIX)
+#if defined(USE_TERMIOS)
+	struct termios tios;
+#elif defined(USE_SGTTY)
+	struct sgttyb sgtty;
+#elif defined(USE_TERMIO)
+	struct termio tio;
+#endif
+	speed_t tspeed; /* representation of speed sutable for termios */
+	speed_t deftspeed;
+#elif defined(DOS)
+	int port;
+#else
+ # error platform not defined
 #endif
-		ephspeed=5;	break;
+	long ephspeed; /* representation of speed sutable for camera command */
+	int rc;
+	int count=0;
+
+	/* speed is real, tell it to the camera.  ttspeed is what you have
+	   to tell to the serial driver to make it set real speed */
+
+	if (speed == 0) speed=MAX_SPEED;
+	if (ttspeed == 0) ttspeed=speed;
+	if (defttspeed == 0) defttspeed=DEFSPEED;
+
+	switch (speed) {
+	case 9600:	ephspeed=1;	break;
+	case 19200:	ephspeed=2;	break;
+	case 38400:	ephspeed=3;	break;
+	case 57600:	ephspeed=4;	break;
+	case 115200:	ephspeed=5;	break;
 	default:
 		eph_error(iob,ERR_BADSPEED,"specified speed %ld invalid",speed);
 		return -1;
 	}
 
+#if defined(UNIX)
+	if ((tspeed=speed2flag(ttspeed)) == (speed_t)-1) {
+		eph_error(iob,ERR_BADSPEED,"specified speed %ld unsupported",
+				ttspeed);
+		return -1;
+	}
+	if ((deftspeed=speed2flag(defttspeed)) == (speed_t)-1) {
+		eph_error(iob,ERR_BADSPEED,"specified speed %ld unsupported",
+				defttspeed);
+		return -1;
+	}
+#endif /* UNIX */
+
 	iob->timeout=DATATIMEOUT+((2048000000L)/speed)*10;
 	if (iob->debug) printf("set timeout to %lu\n",DATATIMEOUT+iob->timeout);
 
@@ -241,11 +337,11 @@
 #endif
 	if ((iob->fd=open(devname,O_RDWR | O_NDELAY)) < 0) {
 #else
-#error platform not defined
+ # error platform not defined
 #endif
-/*		if (strlen(devname) < 400)
-eph_error(iob,ERRNO,"open %s error %s",devname,strerror(ERRNO));
-*/
+		if (strlen(devname) < 400) /* we have 512 byte buffer there */
+			eph_error(iob,ERRNO,"open %s error %s",
+						devname,strerror(ERRNO));
 		return -1;
 	}
 
@@ -283,15 +379,16 @@
 	iob->worktimeouts.WriteTotalTimeoutMultiplier=0;
 	iob->worktimeouts.WriteTotalTimeoutConstant=0;
 	if (!SetCommTimeouts(iob->fd, &iob->worktimeouts)) {
-/*eph_error(iob,ERRNO,"SetCommTimeouts initial attr error %s",strerror(ERRNO));*/
+		eph_error(iob,ERRNO,"SetCommTimeouts initial attr error %s",
+					strerror(ERRNO));
 		CLOSE(iob->fd);
 		return -1;
 	}
 
 #elif defined(UNIX)
-
+#if defined(USE_TERMIOS)
 	if (tcgetattr(iob->fd,&tios) < 0) {
-/*eph_error(iob,ERRNO,"tcgetattr error %s",strerror(ERRNO));*/
+		eph_error(iob,ERRNO,"tcgetattr error %s",strerror(ERRNO));
 		close(iob->fd);
 		return -1;
 	}
@@ -303,8 +400,8 @@
 	tios.c_oflag=0;
 	tios.c_lflag=0;
 #endif
-	cfsetospeed(&tios,DEFSPEED);
-	cfsetispeed(&tios,DEFSPEED);
+	cfsetospeed(&tios,deftspeed);
+	cfsetispeed(&tios,deftspeed);
 #ifdef USE_VMIN_AND_VTIME
 	tios.c_cc[VMIN]=127;
 	tios.c_cc[VTIME]=1;
@@ -329,14 +426,42 @@
 	tios.c_iflag&=~INPCK;
 	tios.c_iflag|=IGNBRK;
 	if (tcsetattr(iob->fd,TCSANOW,&tios)) {
-/*eph_error(iob,ERRNO,"tcsetattr initial attr error %s", strerror(ERRNO));*/
+		eph_error(iob,ERRNO,"tcsetattr initial attr error %s",
+					strerror(ERRNO));
 		close(iob->fd);
 		return -1;
 	}
+#elif defined(USE_SGTTY)
+	if (ioctl(iob->fd, TIOCGETP, &sgtty) < 0) {
+		eph_error(iob,ERRNO,"ioctl/TIOCGETP error %s",strerror(ERRNO));
+		close(iob->fd);
+		return -1;
+	}
+	memcpy(&iob->savesgtty,&sgtty,sizeof(sgtty));
+	sgtty.sg_ispeed = deftspeed;
+	sgtty.sg_ospeed = deftspeed;
+	sgtty.sg_erase = 0;
+	sgtty.sg_kill = 0;
+	sgtty.sg_flags = RAW;
+	if (ioctl(iob->fd, TIOCSETN, &sgtty) < 0) {
+		eph_error(iob,ERRNO,"ioctl/TIOCSETN initial attr error %s",
+					strerror(ERRNO));
+		close(iob->fd);
+		return -1;
+	}
+#elif defined(USE_TERMIO)
+ # error "termio not supported"
+#endif /* terminal control selection */
 
 #endif /* MSWINDOWS/UNIX; do nothing for DOS */
 
 	do {
+		if (eph_flushinput(iob)) {
+			eph_error(iob,ERRNO,"error flushing input: %s",
+					strerror(ERRNO));
+			CLOSE(iob->fd);
+			return -1;
+		}
 		eph_writeinit(iob);
 		rc=eph_waitsig(iob);
 		if (rc) usleep(3000000L);
@@ -346,45 +471,64 @@
 		return -1;
 	}
 
-	if (eph_flushinput(iob)) {
-/*eph_error(iob,ERRNO,"error flushing input: %s",strerror(ERRNO));*/
-		CLOSE(iob->fd);
-		return -1;
-	}
-
 	if (eph_setispeed(iob,ephspeed)) {
-/*eph_error(iob,ERRNO,"could not switch camera speed %d: %s",ephspeed,strerror(ERRNO));*/
+		eph_error(iob,ERRNO,"could not switch camera speed %d: %s",
+				ephspeed,strerror(ERRNO));
 		CLOSE(iob->fd);
 		return -1;
 	}
 
 #if defined(MSWINDOWS)
-	dcb.BaudRate = speed;
+	dcb.BaudRate = ttspeed;
 	if (!SetCommState(iob->fd, &dcb)) {
-/*eph_error(iob,ERRNO,"SetCommState working attr error %s", strerror(ERRNO));*/
+		eph_error(iob,ERRNO,"SetCommState working attr error %s",
+					strerror(ERRNO));
+		CLOSE(iob->fd);
+		return -1;
+	}
 #elif defined(UNIX)
+#if defined(USE_TERMIOS)
 	cfsetospeed(&tios,tspeed);
 	cfsetispeed(&tios,tspeed);
 	if (tcsetattr(iob->fd,TCSANOW,&tios)) {
-/*eph_error(iob,ERRNO,"tcsetattr working attr error %s",strerror(ERRNO));*/
+		eph_error(iob,ERRNO,"tcsetattr working attr error %s",
+					strerror(ERRNO));
+		close(iob->fd);
+		return -1;
+	}
+#elif defined(USE_SGTTY)
+	sgtty.sg_ispeed = tspeed;
+	sgtty.sg_ospeed = tspeed;
+	if (ioctl(iob->fd, TIOCSETN, &sgtty)) {
+		eph_error(iob,ERRNO,"ioctl/TIOCSETN cound not reset attr: %s",
+					strerror(ERRNO));
+		close(iob->fd);
+		return -1;
+	}
+#elif defined(USE_TERMIO)
+ # error "termio not supported"
+#endif
 #elif defined(DOS)
 	ttclose();
-	TTinit(port, speed);
+	TTinit(port, ttspeed);
 	if (ttopen()) {
 		errno = 0;
-/*eph_error(iob,ERRNO,"dobaud set working attr error %s",strerror(ERRNO));*/
-#else
-#error platform not defined
-#endif
+		eph_error(iob,ERRNO,"dobaud set working attr error %s",
+					strerror(ERRNO));
 		CLOSE(iob->fd);
 		return -1;
 	}
+#else
+ # error platform not defined
+#endif
 
 	usleep(SPEEDCHGDELAY);
 	return 0;
 }
 
-int eph_close(eph_iob *iob,int switchoff) {
+int
+eph_close(eph_iob *iob,int switchoff)
+{
 
 	if (switchoff) {
 		char zero=0;
@@ -397,17 +541,24 @@
 	}
 
 #if defined(MSWINDOWS)
-/*
 	if (!SetCommState(iob->fd, &iob->savedcb))
-eph_error(iob,ERRNO,"SetCommState reset attr error %s",strerror(ERRNO));
+		eph_error(iob,ERRNO,"SetCommState reset attr error %s",
+					strerror(ERRNO));
 	if (!SetCommTimeouts(iob->fd, &iob->savetimeouts))
 		eph_error(iob,ERRNO,"SetCommTimeouts reset attr error %s",
 					strerror(ERRNO));
-*/
 #elif defined(UNIX)
-	if (tcsetattr(iob->fd,TCSANOW,&iob->savetios)) {
-/*eph_error(iob,ERRNO,"tcsetattr cound not reset attr: %s",strerror(ERRNO));*/
-	}
+#if defined(USE_TERMIOS)
+	if (tcsetattr(iob->fd,TCSANOW,&iob->savetios))
+		eph_error(iob,ERRNO,"tcsetattr cound not reset attr: %s",
+					strerror(ERRNO));
+#elif defined(USE_SGTTY)
+	if (ioctl(iob->fd, TIOCSETN, &iob->savesgtty))
+		eph_error(iob,ERRNO,"tcsetattr cound not reset attr: %s",
+					strerror(ERRNO));
+#elif defined(USE_TERMIO)
+ # error "termio not supported"
+#endif
 #endif /* MSWINDOWS/UNIX; do nothing for DOS */
 
 	return CLOSE(iob->fd);
diff -ru gphoto-cvs-clean/gphoto/photopc/eph_priv.h gphoto-cvs/gphoto/photopc/eph_priv.h
--- gphoto-cvs-clean/gphoto/photopc/eph_priv.h	Thu May 27 18:32:06 1999
+++ gphoto-cvs/gphoto/photopc/eph_priv.h	Sun Jul  2 07:38:15 2000
@@ -1,5 +1,5 @@
 /*
-	$Id: eph_priv.h,v 1.1.1.1 1999/05/27 18:32:06 scottf Exp $
+	$Id: eph_priv.h,v 2.7 1999/01/17 09:50:55 crosser Exp $
 */
 
 /*
@@ -17,12 +17,12 @@
 
 /*
 	$Log: eph_priv.h,v $
-	Revision 1.1.1.1  1999/05/27 18:32:06  scottf
-	gPhoto- digital camera utility
-	
-	Revision 1.1.1.1  1999/01/07 15:04:02  del
-	Imported 0.2 sources
-	
+	Revision 2.7  1999/01/17 09:50:55  crosser
+	increase WRT*DELAYs
+
+	Revision 2.6  1998/12/06 08:40:34  crosser
+	chnage iniitimeout for Nikon
+
 	Revision 2.5  1998/10/18 13:18:27  crosser
 	Put RCS logs and I.D. into the source
 
@@ -68,7 +68,7 @@
 #define EODTIMEOUT     1100000L
 #define CMDTIMEOUT    15000000L
 #else
-#define INITTIMEOUT    1000000L
+#define INITTIMEOUT    3000000L
 #define DATATIMEOUT     200000L
 #define BIGDATATIMEOUT 1500000L
 #define ACKTIMEOUT      400000L
@@ -77,10 +77,19 @@
 #define CMDTIMEOUT    15000000L
 #endif
 
+/* Bruce and others say that adding 1ms delay before all writes is good.
+   I think that they should rather be fine-tuned. */
+#if 1
+#define WRTPKTDELAY       1250L
+#define WRTCMDDELAY       1250L
+#define WRTPRMDELAY       1500L
+#define WRTDELAY          2000L
+#else
 #define WRTPKTDELAY        250L
 #define WRTCMDDELAY        250L
 #define WRTPRMDELAY        500L
 #define WRTDELAY          1000L
+#endif
 #define SPEEDCHGDELAY   100000L
 
 #define SKIPNULS           200
diff -ru gphoto-cvs-clean/gphoto/photopc/eph_read.c gphoto-cvs/gphoto/photopc/eph_read.c
--- gphoto-cvs-clean/gphoto/photopc/eph_read.c	Thu May 27 18:32:06 1999
+++ gphoto-cvs/gphoto/photopc/eph_read.c	Sun Jul  2 07:38:15 2000
@@ -1,3 +1,6 @@
+#ifndef LINT
+static char *rcsid="$Id: eph_read.c,v 2.7 1999/08/01 21:36:54 crosser Exp $";
+#endif
 
 /*
 	Copyright (c) 1997,1998 Eugene G. Crosser
@@ -14,15 +17,14 @@
 
 /*
 	$Log: eph_read.c,v $
-	Revision 1.1.1.1  1999/05/27 18:32:06  scottf
-	gPhoto- digital camera utility
-	
-	Revision 1.2  1999/04/30 07:14:14  scottf
-	minor changes to remove compilation warnings. prepping for release.
-	
-	Revision 1.1.1.1  1999/01/07 15:04:02  del
-	Imported 0.2 sources
-	
+	Revision 2.7  1999/08/01 21:36:54  crosser
+	Modify source to suit ansi2knr
+	(I hate the style that ansi2knr requires but you don't expect me
+	to write another smarter ansi2knr implementation, right?)
+
+	Revision 2.6  1999/03/06 13:37:08  crosser
+	Convert to autoconf-style
+
 	Revision 2.5  1998/10/18 13:18:27  crosser
 	Put RCS logs and I.D. into the source
 
@@ -46,9 +48,14 @@
 	
 */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 #include <sys/types.h>
 #include <string.h>
+#ifdef HAVE_FCNTL_H
 #include <fcntl.h>
+#endif
 #include <errno.h>
 
 #include "eph_io.h"
@@ -72,7 +79,9 @@
 
 #define MIN_TIMEOUT (1000)  /* 1 second...doesn't change so often! */
 
-size_t eph_readt(eph_iob *iob,char *buf,size_t length,long timeout_usec,int *rc) {
+size_t
+eph_readt(eph_iob *iob,char *buf,size_t length,long timeout_usec,int *rc)
+{
 	BOOL stat;
 	DWORD rlen;
 	DWORD timeout_ms;
@@ -124,13 +133,27 @@
 
 #elif defined(UNIX)
 
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#ifdef HAVE_SELECT_H
+#endif
+#ifdef HAVE_SYS_SELECT_H
 #include <sys/select.h>
-#endif /* HAVE_SELECT_H */
-#include <sys/time.h>
+#endif /* HAVE_SYS_SELECT_H */
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
 
-size_t eph_readt(eph_iob *iob,char *buf,size_t length,long timeout_usec,int *rc) {
+size_t
+eph_readt(eph_iob *iob,char *buf,size_t length,long timeout_usec,int *rc)
+{
 	fd_set rfds,wfds,efds;
 	struct timeval timer;
 
@@ -161,7 +184,9 @@
 
 #define TO_USECS (1L * 1000000L)
 
-size_t eph_readt(eph_iob *iob,char *buf,size_t length,long timeout_usec,int *rc) {
+size_t
+eph_readt(eph_iob *iob,char *buf,size_t length,long timeout_usec,int *rc)
+{
 	int ch, reset = 0, rlen = 0;
 	unsigned char *p = buf;
 
@@ -194,5 +219,5 @@
 }
 
 #else
-#error platform not defined
+ # error platform not defined
 #endif
diff -ru gphoto-cvs-clean/gphoto/photopc/olympus.c gphoto-cvs/gphoto/photopc/olympus.c
--- gphoto-cvs-clean/gphoto/photopc/olympus.c	Fri Jun 25 00:25:46 1999
+++ gphoto-cvs/gphoto/photopc/olympus.c	Sun Jul  2 08:26:59 2000
@@ -8,6 +8,12 @@
 /* Olympus Camera Functions ----------------------------------
    ----------------------------------------------------------- */
 
+/*
+ * (2jul2000) Adam Fritzler (mid@auk.cx): Upgraded to latest
+ * version of photopc (3.04) and added in the descend function
+ * from there in order to get this working on my C-2500L.
+ */
+
 eph_iob   *iob;                /* Olympus/photoPC io-buffer    */
 
 int oly_initialize () {
@@ -16,16 +22,133 @@
 	return 1;
 }
 
+#define MAXPATH 256
+
+/*
+ * xchdir, descend, and nonempty are from photopc 3.04.  Modified
+ * for the context.  Cameras not supporting folders should not
+ * reach this code, but should still work if they do. -mid 
+ */
+static int xchdir(eph_iob *iob,char *where, int have_folders)
+{
+	char path[MAXPATH],*p;
+
+	if (!have_folders)
+		return -1;
+	
+	strncpy(path,where,sizeof(path)-1);
+	path[sizeof(path)-1]='\0';
+	for (p=path;*p;p++) if (*p == '/') *p='\\';
+	if (path[0] == '\\') {
+		if (eph_setvar(iob,84,"\\",1)) {
+			fprintf(stderr,"could not chdir to \"\\\"\n");
+			return -1;
+		}
+	}
+	for (p=strtok(path,"\\");p;p=strtok(NULL,"\\")) {
+		if (eph_setvar(iob,84,p,strlen(p))) {
+			fprintf(stderr,"could not chdir to \"%s\"\n",p);
+			return -1;
+		}
+	}
+	return 0;
+}
+
+static int descend(eph_iob *iob,int depth,char *root,int(*each)(eph_iob *iob,char *path), int have_folders)
+{
+	long nfolders=0L,i;
+	off_t f_size;
+	char *folder,*p;
+	char path[MAXPATH];
+	int rc;
+	int blah;
+
+	if (!have_folders) return (*each)(iob,root);
+
+	if (depth > 10) {
+		fprintf(stderr,"cannot be that deep (%d), error!\n",depth);
+		return -1;
+	}
+	if (xchdir(iob,root,have_folders)) {
+		fprintf(stderr,"chdir to \"%s\" failed\n",root);
+		return -1;
+	}
+
+	if ((rc=(*each)(iob,root)) != 0)
+		return rc;
+
+	eph_getint(iob,83,&nfolders);
+
+	if (nfolders == 0L) return 0;
+
+	folder=(char*)malloc(2048);
+	f_size=2048;
+	path[sizeof(path)-1]='\0';
+	for (i=1;i<=nfolders;i++) {
+		eph_setint(iob,83,i);
+		eph_getvar(iob,84,&folder,&f_size);
+
+		strncpy(path,root,sizeof(path)-2);
+		if (path[strlen(path)-1] != '\\')
+			strncat(path,"\\",sizeof(path)-2);
+		strncat(path,folder,sizeof(path)-2);
+		for (p=path+strlen(path)-1;(*p == ' ') && (p > path);p--)
+			*p='\0';
+		if ((rc=descend(iob,depth+1,path,each,have_folders))) {
+			free(folder);
+			return rc;
+		}
+		if (xchdir(iob,root,have_folders)) {
+			fprintf(stderr,"restore dir to \"%s\" failed\n",root);
+			return -1;
+		}
+	}
+	free(folder);
+
+	return 0;
+}
+
+static int
+nonempty(eph_iob *iob,char *path)
+{
+	unsigned long result;
+
+	if (eph_getint(iob,10,&result)) {
+		return -1;
+	}
+	if (result) {
+		return 1;
+	} else return 0;
+}
+
+int oly_init2(eph_iob *iob)
+{
+        long ret;
+        int rc;
+
+        if (eph_getint(iob,1,&ret)) return -1;
+        
+	eph_setnullint(iob,83);
+	
+	if (!eph_setvar(iob,84,"\\",1)) {
+		if (descend(iob, 0, "\\", nonempty, 1) < 0)
+			return -1;
+        }
+
+	return 0;
+}
+
 int oly_open_camera () {
 
 	/* Open the camera for reading/writing */
 
 	long ltemp;
 
-        if (eph_open(iob, serial_port, 115200) == -1)
+        if (eph_open(iob, serial_port, 115200, 0, 0) == -1)
 		return (0);
 	/* sleep(1); */
-        eph_getint(iob, 35, &ltemp);
+	
+	oly_init2(iob);
 	return (1);
 }
 
diff -ru gphoto-cvs-clean/gphoto/photopc/usleep.c gphoto-cvs/gphoto/photopc/usleep.c
--- gphoto-cvs-clean/gphoto/photopc/usleep.c	Thu May 27 18:32:06 1999
+++ gphoto-cvs/gphoto/photopc/usleep.c	Sun Jul  2 07:38:15 2000
@@ -1,7 +1,10 @@
+#ifndef LINT
+static char *rcsid="$Id: usleep.c,v 2.8 1999/08/01 21:36:54 crosser Exp $";
+#endif
 
 /*
-	Copyright (c) 1997,1998 Eugene G. Crosser
-	Copyright (c) 1998 Bruce D. Lightner (DOS/Windows support)
+	Copyright (c) 1997-1999 Eugene G. Crosser
+	Copyright (c) 1998,1999 Bruce D. Lightner (DOS/Windows support)
 
 	You may distribute and/or use for any purpose modified or unmodified
 	copies of this software if you preserve the copyright notice above.
@@ -14,15 +17,24 @@
 
 /*
 	$Log: usleep.c,v $
-	Revision 1.1.1.1  1999/05/27 18:32:06  scottf
-	gPhoto- digital camera utility
-	
-	Revision 1.2  1999/04/30 07:14:14  scottf
-	minor changes to remove compilation warnings. prepping for release.
-	
-	Revision 1.1.1.1  1999/01/07 15:04:02  del
-	Imported 0.2 sources
-	
+	Revision 2.8  1999/08/01 21:36:54  crosser
+	Modify source to suit ansi2knr
+	(I hate the style that ansi2knr requires but you don't expect me
+	to write another smarter ansi2knr implementation, right?)
+
+	Revision 2.7  1999/04/22 04:14:54  crosser
+	avoid GCC-isms
+
+	Revision 2.6  1999/04/10 16:33:05  lightner
+	Used calibrated spin loop for Win32 (like MSDOS) in place of Sleep()
+	Speed upspin loop calibrarion for MSDOS
+
+	Revision 2.5  1999/03/12 10:06:23  crosser
+	fix typo
+
+	Revision 2.4  1999/03/06 13:37:08  crosser
+	Convert to autoconf-style
+
 	Revision 2.3  1998/10/18 13:18:27  crosser
 	Put RCS logs and I.D. into the source
 
@@ -37,40 +49,146 @@
 	
 */
 
+#include <stdio.h>
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 #if defined(UNIX)
-#include <time.h>
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
 
 #ifdef HAVE_NANOSLEEP
-void usleep (unsigned int useconds) {
-  struct timespec ts = { tv_sec: (long int) (useconds / 1000000),
-			 tv_nsec: (long int) (useconds % 1000000) * 1000ul };
+void
+usleep(unsigned int useconds)
+{
+	struct timespec ts;
 
-  __nanosleep (&ts, NULL);
+	ts.tv_sec=(long int)(useconds/1000000);
+	ts.tv_nsec=(long int)(useconds%1000000)*1000ul;
+
+	nanosleep (&ts, NULL);
 }
-#else /* HAVE_NANOSLEEP */
-#ifdef HAVE_SELECT_H
+#elif HAVE_SELECT
+#ifdef HAVE_SYS_SELECT_H
 #include <sys/select.h>
 #endif
-void usleep(unsigned long usec) {
+void
+usleep (unsigned long usec)
+{
         struct timeval timeout;
 
         timeout.tv_sec = usec / 1000000;
         timeout.tv_usec = usec - 1000000 * timeout.tv_sec;
         select(1, NULL, NULL, NULL, &timeout);
 }
-#endif /* HAVE_NANOSLEEP */
+#else
+ # error "cannot sleep: neither nanosleep nor select"
+#endif /* HAVE_NANOSLEEP / HAVE_SELECT */
 
 #elif defined(MSWINDOWS)
 
 #include <windows.h>
+#include <stdio.h>
+#include <sys/timeb.h>
+#include <time.h>
 
-void usleep(long usecs) {
-	long msecs;
+static unsigned long start_secs;
+static unsigned long start_usecs;
+static unsigned long end_usecs;
+static int calibrated = 0;
+volatile unsigned long dummy = 0;
+static double delay_factor = 1;
+#define DELAY_MARGIN	1.5
 
-	msecs = usecs / 1000L;
-	if (msecs <= 0) msecs = 1;	/* minimum delay is 1 millisecond */
-	Sleep((DWORD)msecs);
+void
+start_time(void)
+{
+	struct _timeb t;
+
+	_ftime(&t);
+	start_secs = t.time;
+	start_usecs = 1000L * t.millitm;
+}
+
+unsigned
+long elasped_usecs(void)
+{
+	struct _timeb t;
+
+	_ftime(&t);
+	end_usecs = 1000L * t.millitm + 1000000L * (t.time - start_secs);
+	while (end_usecs < start_usecs)
+		end_usecs += 60L * 1000000L;
+	return end_usecs - start_usecs;
+}
+
+unsigned
+long spin_loop(double delay_factor)
+{
+	unsigned long delay = delay_factor;
+	unsigned long stop_usecs;
+
+#define CAL_TICKS 2
+	dummy = 0;
+	start_time();
+	if (delay == 0) {
+		/* sync with next clock tick */
+		while (elasped_usecs() == 0)
+			;
+		stop_usecs = CAL_TICKS * 55000L + 1000L;
+	} else {
+		elasped_usecs();
+		stop_usecs = -1;
+	}
+	while (--delay > 0) {
+		++dummy;
+		if (elasped_usecs() >= stop_usecs)
+			break;
+	}
+	return dummy / CAL_TICKS;
+}
+
+void
+calibrate_delay(void)
+{
+#	define MAX_LOOPS 3
+	int i;
+	unsigned long loops, trial_loops;
+
+	/* calibrate spin_loop() (returns loops per 18.2Hz PC timer tick */
+	loops = 0;
+        for (i = 0; i < MAX_LOOPS; ++i) {
+		trial_loops = spin_loop(0.0);
+		if (trial_loops > loops) loops = trial_loops;
+	}
+	delay_factor = ((double)loops / 55000.0) * DELAY_MARGIN;
+	calibrated = 1;
+	/* printf("loops = %ld, delay_factor = %g\n", loops, delay_factor); */
+}
+
+long
+usleep(long usecs)
+{
+	if (!calibrated)
+		calibrate_delay();
+	if (usecs > 1000000L) {
+		Sleep((DWORD)usecs / 1000L);
+
+	} else {
+		spin_loop(delay_factor * usecs + 1);
+	}
 }
 
 #elif defined(DOS)
@@ -82,6 +200,7 @@
 static int calibrated = 0;
 volatile unsigned long dummy = 0;
 double delay_factor = 1;
+#define DELAY_MARGIN	1.5
 
 #ifndef USE_DOS_TIME
 unsigned long stop_tick;
@@ -89,7 +208,8 @@
 #ifndef NO_TICKS_MACRO
 #define get_bios_ticks() (*((volatile unsigned long far *)(MK_FP(0, 0x46c))))
 #else /* !NO_TICKS_MACRO */
-unsigned long get_bios_ticks(void)
+unsigned long
+get_bios_ticks(void)
 {
 	static unsigned long far *p;
 
@@ -100,7 +220,9 @@
 #endif /* !NO_TICKS_MACRO */
 #endif /* !USE_DOS_TIME */
 
-void start_time(void) {
+void
+start_time(void)
+{
 #ifndef USE_DOS_TIME
 	unsigned long t;
 
@@ -114,7 +236,9 @@
 #endif
 }
 
-unsigned long elasped_usecs(void) {
+unsigned
+long elasped_usecs(void)
+{
 #ifndef USE_DOS_TIME
 	unsigned long t;
 
@@ -133,12 +257,13 @@
 	return end_usecs - start_usecs;
 }
 
-unsigned long spin_loop(double delay_factor)
+unsigned long
+spin_loop(double delay_factor)
 {
 	unsigned long delay = delay_factor;
 
 #ifndef USE_DOS_TIME
-#define CAL_TICKS 4
+#define CAL_TICKS 2
 	dummy = 0;
 	if (delay == 0) {
 		unsigned long end_tick;
@@ -164,23 +289,29 @@
 #else
 	return dummy;
 #endif
-};
+}
 
 #ifndef USE_DOS_TIME
-void calibrate_delay(void)
+void
+calibrate_delay(void)
 {
-	unsigned long loops, loops1, loops2;
+#	define MAX_LOOPS 3
+	int i;
+	unsigned long loops, trial_loops;
 
 	/* calibrate spin_loop() (returns loops per 18.2Hz PC timer tick */
-	loops1 = spin_loop(0.0);
-	loops2 = spin_loop(0.0);
-	/* use larger loop count for delay factor calculation*/
-	loops = (loops1 > loops2) ? loops1 : loops2;
-	delay_factor = (double)loops / 55000.0;
+	loops = 0;
+        for (i = 0; i < MAX_LOOPS; ++i) {
+		trial_loops = spin_loop(0.0);
+		if (trial_loops > loops) loops = trial_loops;
+	}
+	delay_factor = ((double)loops / 55000.0) * DELAY_MARGIN;
 	calibrated = 1;
+	/* printf("loops = %ld, delay_factor = %g\n", loops, delay_factor); */
 }
 #else /* USE_DOS_TIME */
-void calibrate_delay(void)
+void
+calibrate_delay(void)
 {
 	int i;
 	unsigned long usecs;
@@ -200,7 +331,8 @@
 }
 #endif /* USE_DOS_TIME */
 
-long usleep(long usecs)
+long
+usleep(long usecs)
 {
 	if (!calibrated)
 		calibrate_delay();
@@ -214,5 +346,5 @@
 }
 
 #else
-#error platform not defined
+ # error platform not defined
 #endif
diff -ru gphoto-cvs-clean/gphoto/photopc/usleep.h gphoto-cvs/gphoto/photopc/usleep.h
--- gphoto-cvs-clean/gphoto/photopc/usleep.h	Thu May 27 18:32:06 1999
+++ gphoto-cvs/gphoto/photopc/usleep.h	Sun Jul  2 07:38:15 2000
@@ -1,5 +1,5 @@
 /*
-	$Id: usleep.h,v 1.1.1.1 1999/05/27 18:32:06 scottf Exp $
+	$Id: usleep.h,v 2.2 1998/10/18 13:18:27 crosser Exp $
 */
 
 /*
@@ -17,12 +17,6 @@
 
 /*
 	$Log: usleep.h,v $
-	Revision 1.1.1.1  1999/05/27 18:32:06  scottf
-	gPhoto- digital camera utility
-	
-	Revision 1.1.1.1  1999/01/07 15:04:02  del
-	Imported 0.2 sources
-	
 	Revision 2.2  1998/10/18 13:18:27  crosser
 	Put RCS logs and I.D. into the source
 
diff -ru gphoto-cvs-clean/gphoto/src/cameras.h gphoto-cvs/gphoto/src/cameras.h
--- gphoto-cvs-clean/gphoto/src/cameras.h	Wed Jun  7 23:14:40 2000
+++ gphoto-cvs/gphoto/src/cameras.h	Sun Jul  2 08:28:59 2000
@@ -120,6 +120,7 @@
 	{"Olympus C-1000L", &olympus, 0, 0},
 	{"Olympus C-1400L", &olympus, 0, 0},
 	{"Olympus C-2000Z", &olympus, 0, 0},
+	{"Olympus C-2500L", &olympus, 0, 0},
 	{"Olympus C-3030Z", &olympus, 0, 0},
 	{"Panasonic Coolshot KXl-600A", &olympus, 0, 0},
 	{"Panasonic Cardshot NV-DCF5E", &olympus, 0, 0},
