4727e0251c76f69905d0748adab43484166d6870
angie
  Fri Mar 14 16:42:14 2014 -0700
In code review, Max pointed out that it's non-standard to conditionallyinclude header files in the middle of a .c file.  While looking at it,
I realized that there were a lot of unnecessary #ifdef's for KNETFILE_HOOKS
in general, all because there was not yet an #else implementation of
knetUdcInstall, which can be a no-op if KNETFILE_HOOKS is not used.
So I yanked out a lot of unnecessary old stuff, and tested basic bam and
vcf track operations with a few settings:

USE_SAMTABIX   USE_BAM   USE_TABIX   KNETFILE_HOOKS
1     (these tree are all implied by USE_SAMTABIX)
0        1          0       0
0        1          0       1
0        0          1       1
USE_TABIX without KNETFILE_HOOKS doesn't work because the tabix lib
wants to download .tbi files into the current working directory,
cgi-bin, and we don't allow that (and shouldn't!).  If we were going
to support that, we could add a change-dir solution as in bamFile.c,
but I don't think we need to support it now that there's samtabix.

refs #6235, refs #12850

diff --git src/lib/knetUdc.c src/lib/knetUdc.c
index fdba740..87f6d8c 100644
--- src/lib/knetUdc.c
+++ src/lib/knetUdc.c
@@ -1,86 +1,94 @@
 /* knetUdc -- install udc i/o functions in knetfile interface in samtools. */
 /* As of 2/23/10, the KNETFILE_HOOKS extension is a UCSC-local modification of samtools. */
 
 #if ((defined USE_BAM || defined USE_TABIX) && defined KNETFILE_HOOKS)
 
 #include "common.h"
 #include "udc.h"
 #include "knetUdc.h"
 #include "knetfile.h"
 
 
 struct knetFile_s {
     struct udcFile *udcf;
 }; // typedef'd to knetFile in knetfile.h
 
 static char *udcCacheDir = NULL;
 
 static knetFile *kuOpen(const char *filename, const char *mode)
 /* Open the given filename with mode which must be "r". */
 {
 if (!sameOk((char *)mode, "r"))
     errAbort("mode passed to kuOpen must be 'r' not '%s'", mode);
 struct udcFile *udcf = udcFileMayOpen((char *)filename, udcCacheDir);
 if (udcf == NULL)
     return NULL;
 knetFile *kf = NULL;
 AllocVar(kf);
 kf->udcf = udcf;
 verbose(2, "kuOpen: returning %lu\n", (unsigned long)(kf->udcf));
 return kf;
 }
 
 static knetFile *kuDopen(int fd, const char *mode)
 /* Open from a file descriptor -- not necessary for our use of samtools. */
 {
 errAbort("kuDopen not implemented");
 return NULL;
 }
 
 static off_t kuRead(knetFile *fp, void *buf, off_t len)
 /* Read len bytes into buf, return amount actually read. */
 {
 verbose(2, "udcRead(%lu, buf, %lld)\n", (unsigned long)(fp->udcf), (long long)len);
 return (off_t)udcRead(fp->udcf, buf, (int)len);
 }
 
 static off_t kuSeek(knetFile *fp, int64_t off, int whence)
 /* Seek to off according to whence (but don't waste time with samtools' SEEK_END to
  * check empty record at end of file.  Don't be fooled by the off_t return type --
  * it's 0 for OK, non-0 for fail. */
 {
 bits64 offset;
 if (whence == SEEK_SET)
     offset = off;
 else if (whence == SEEK_CUR)
     offset = off+ udcTell(fp->udcf);
 else
     return -1;
 verbose(2, "udcSeek(%lu, %lld)\n", (unsigned long)(fp->udcf), offset);
 udcSeek(fp->udcf, offset);
 return 0;
 }
 
 static off_t kuTell(knetFile *fp)
 /* Tell current offset in file. */
 {
 verbose(2, "udcTell(%lu)\n", (unsigned long)(fp->udcf));
 return udcTell(fp->udcf);
 }
 
 static int kuClose(knetFile *fp)
 /* Close and free fp->udcf. */
 {
 verbose(2, "udcClose(%lu)\n", (unsigned long)(fp->udcf));
 udcFileClose(&(fp->udcf));
 return 0;
 }
 
 void knetUdcInstall()
 /* install udc i/o functions in knetfile interface in Heng Li's samtools lib. */
 {
 // maybe init udcCacheDir from hg.conf?
 knet_init_alt(kuOpen, kuDopen, kuRead, kuSeek, kuTell, kuClose);
 }
 
-#endif//def (USE_BAM || USE_TABIX) && KNETFILE_HOOKS
+
+#else// no (USE_BAM || USE_TABIX) && KNETFILE_HOOKS
+
+void knetUdcInstall()
+/* Required libs aren't installed; do nothing. */
+{
+}
+
+#endif