summaryrefslogtreecommitdiff
path: root/corelib
diff options
context:
space:
mode:
authorAaron M. Ucko <ucko@debian.org>2005-03-24 18:46:06 +0000
committerAaron M. Ucko <ucko@debian.org>2005-03-24 18:46:06 +0000
commit63b21a5f6060202b6d5c888d203e78ba871abcc2 (patch)
tree03fb3548fb6902e89097d17630f910e220b420a8 /corelib
parentd5cd243f986e2366bd1dfe5f923d2ce7e1002f93 (diff)
Load ncbi (6.1.20041020) into ncbi-tools6/branches/upstream/current.
Diffstat (limited to 'corelib')
-rw-r--r--corelib/ncbienv.c207
-rw-r--r--corelib/ncbifile.c23
-rw-r--r--corelib/ncbilcl.fbd8
-rw-r--r--corelib/ncbimem.c27
-rw-r--r--corelib/ncbiopt.h7
5 files changed, 174 insertions, 98 deletions
diff --git a/corelib/ncbienv.c b/corelib/ncbienv.c
index 04b178ab..9b20295b 100644
--- a/corelib/ncbienv.c
+++ b/corelib/ncbienv.c
@@ -29,7 +29,7 @@
*
* Version Creation Date: 7/7/91
*
-* $Revision: 6.36 $
+* $Revision: 6.37 $
*
* File Description:
* portable environment functions, companions for ncbimain.c
@@ -37,6 +37,9 @@
* Modifications:
* --------------------------------------------------------------------------
* $Log: ncbienv.c,v $
+* Revision 6.37 2004/08/06 20:56:27 kans
+* G/SetAppParam on PC no longer uses PrivateProfileString functions - instead it checks USERPROFILE, SYSTEMROOT, and then NCBI environment variables
+*
* Revision 6.36 2004/02/11 18:40:00 kans
* enhanced GetOpSysString to report specific version of MS Windows
*
@@ -303,7 +306,6 @@ static void Nlm_TransientLogSetApp(const Nlm_Char* file, const Nlm_Char* section
static void Nlm_FreeEnvData(Nlm_env_sectPtr esp);
static void Nlm_FreeTransientData(void);
-#ifndef OS_MSWIN
static FILE* Nlm_OpenConfigFile(const Nlm_Char* file, Nlm_Boolean writeMode, Nlm_Boolean create);
static Nlm_Char* Nlm_TrimString(Nlm_Char* str);
static Nlm_Boolean Nlm_ReadConfigFile(FILE* fp);
@@ -681,6 +683,7 @@ static Nlm_Boolean Nlm_GetHome(Nlm_Char* buf, Nlm_Int2 buflen)
static FILE* Nlm_OpenConfigFile(const Nlm_Char* file, Nlm_Boolean writeMode, Nlm_Boolean create)
{
+ Nlm_Char ch;
FILE *fp;
Nlm_Int2 i;
Nlm_Int2 len;
@@ -703,7 +706,8 @@ static FILE* Nlm_OpenConfigFile(const Nlm_Char* file, Nlm_Boolean writeMode, Nlm
/* if the name isn't all lowercase, make it so now */
len = (Nlm_Int2) Nlm_StringLen (str);
for (i = 0; i < len; i++) {
- str [i] = TO_LOWER (str [i]);
+ ch = str [i];
+ str [i] = TO_LOWER (ch);
}
if (Nlm_GetHome (path, sizeof (path))) {
Nlm_FileBuildPath(path, "Library", NULL);
@@ -745,7 +749,8 @@ static FILE* Nlm_OpenConfigFile(const Nlm_Char* file, Nlm_Boolean writeMode, Nlm
}
len = (Nlm_Int2) Nlm_StringLen (str);
for (i = 0; i < len; i++) {
- str [i] = TO_LOWER (str [i]);
+ ch = str [i];
+ str [i] = TO_LOWER (ch);
}
Nlm_StringNCpy_0(path, str, sizeof(path));
@@ -796,6 +801,109 @@ static FILE* Nlm_OpenConfigFile(const Nlm_Char* file, Nlm_Boolean writeMode, Nlm
#endif /* OS_UNIX */
+#ifdef OS_MSWIN
+/*****************************************************************************
+*
+* Nlm_OpenConfigFile (file, writeMode, create)
+* returns a file pointer to the specified configuration file.
+* 1) looks in the current directory for "file.ini", but will not
+* create a new file in this directory.
+* 2) then looks in the home directory for ".filerc".
+* 3) then looks for an environment variable "NCBI" and takes its
+* value as a complete path to a directory containing the
+* configuration file "filerc" or ".filerc".
+*
+* Steps (1) and (2) above are omitted if the NCBI_DONT_USE_LOCAL_CONFIG
+* environment variable is set. This can be used to allow specific
+* production applications to avoid stray .ncbirc files which may have
+* been erroneously generated.
+*
+*****************************************************************************/
+
+static FILE* Nlm_OpenConfigFile(const Nlm_Char* file, Nlm_Boolean writeMode, Nlm_Boolean create)
+
+{
+ Nlm_Char ch;
+ FILE *fp;
+ Nlm_Int2 i;
+ Nlm_Int2 len;
+ FILE *newfp;
+ Nlm_Char path [PATH_MAX+1];
+ Nlm_Char str [FILENAME_MAX+1];
+ Nlm_CharPtr tmp;
+
+ fp = NULL;
+ newfp = NULL;
+
+ if (file != NULL) {
+
+ /* normalize file name */
+ Nlm_StringNCpy_0(str, file, sizeof(str) - 4);
+ if ( ! Nlm_Qualified (str) ) {
+ /* if the user has already supplied a name with .xxx use that name
+ * otherwise add the .ini here */
+ Nlm_StringCat(str, ".INI");
+ }
+ /* if the name isn't all uppercase, make it so now */
+ len = (Nlm_Int2) Nlm_StringLen (str);
+ for (i = 0; i < len; i++) {
+ ch = str [i];
+ str [i] = TO_UPPER (ch);
+ }
+
+ /* first try user directory */
+
+ tmp = getenv ("USERPROFILE");
+ if (tmp != NULL && *tmp != '\0') {
+ StringNCpy_0 (path, tmp, sizeof (path));
+ Nlm_FileBuildPath(path, NULL, str);
+ fp = Nlm_FileOpen (path, "r");
+ if (fp == NULL && create) {
+ newfp = Nlm_FileOpen (path, "w");
+ Nlm_FileClose (newfp);
+ newfp = Nlm_FileOpen (path, "r");
+ }
+ }
+
+ /* next try c:\winnt for backward compatibility - read only */
+
+ if (fp == NULL) {
+ tmp = getenv ("SYSTEMROOT");
+ if (tmp != NULL && *tmp != '\0') {
+ StringNCpy_0 (path, tmp, sizeof (path));
+ Nlm_FileBuildPath(path, NULL, str);
+ fp = Nlm_FileOpen (path, "r");
+ }
+ }
+
+ /* last try environment variable path - read only */
+
+ if (fp == NULL) {
+ tmp = getenv ("NCBI");
+ if (tmp != NULL && *tmp != '\0') {
+ StringNCpy_0 (path, tmp, sizeof (path));
+ Nlm_FileBuildPath(path, NULL, str);
+ fp = Nlm_FileOpen (path, "r");
+ }
+ }
+
+ if (newfp != NULL) {
+ if (fp != NULL) {
+ Nlm_FileClose (newfp);
+ newfp = NULL;
+ } else {
+ fp = newfp;
+ }
+ }
+ if (writeMode && fp != NULL) {
+ Nlm_FileClose (fp);
+ fp = Nlm_FileOpen (path, "w");
+ }
+ }
+ return fp;
+}
+#endif /* OS_MSWIN */
+
#if defined(OS_MAC) && !defined(OS_UNIX_DARWIN)
/*****************************************************************************
@@ -832,6 +940,7 @@ Nlm_OpenConfigFile(const Nlm_Char* file,
Nlm_Boolean writeMode,
Nlm_Boolean create )
{
+ Nlm_Char ch;
Nlm_Char str [FILENAME_MAX+1];
Nlm_Int2 len;
long gesResponse;
@@ -857,7 +966,8 @@ Nlm_OpenConfigFile(const Nlm_Char* file,
/* if the name isn't all lowercase, make it so now */
len = (Nlm_Int2) Nlm_StringLen (str);
for (i = 0; i < len; i++) {
- str [i] = TO_LOWER (str [i]);
+ ch = str [i];
+ str [i] = TO_LOWER (ch);
}
/* convert to pascal string for Mac toolbox */
@@ -956,6 +1066,7 @@ static Nlm_Boolean Nlm_GetHome(Nlm_Char* buf, Nlm_Int2 buflen)
static FILE* Nlm_OpenConfigFile(const Nlm_Char* file, Nlm_Boolean writeMode, Nlm_Boolean create)
{
+ Nlm_Char ch;
FILE *fp;
Nlm_Int2 i;
Nlm_Int2 len;
@@ -974,7 +1085,8 @@ static FILE* Nlm_OpenConfigFile(const Nlm_Char* file, Nlm_Boolean writeMode, Nlm
}
len = (Nlm_Int2) Nlm_StringLen (str);
for (i = 0; i < len; i++) {
- str [i] = TO_LOWER (str [i]);
+ ch = str [i];
+ str [i] = TO_LOWER (ch);
}
Nlm_StringNCpy_0(path, str, sizeof(path));
@@ -1407,89 +1519,6 @@ static void Nlm_PutComment(const Nlm_Char* s, FILE* fp)
fputs(s, fp);
}
-#else /* ndef OS_MSWIN */
-
-static void Nlm_FlushAppParam_ST(void) {}
-static Nlm_Boolean Nlm_CacheAppParam_ST(Nlm_Boolean value) { return TRUE; }
-
-/*****************************************************************************
-*
-* The "guts" of:
-* Nlm_GetAppParam (file, section, type, buf, buflen)
-* finds parameters from configuration files
-* if configuration file is found, trys to read the parameter from it.
-*
-*****************************************************************************/
-static Nlm_Int2 Nlm_WorkGetAppParam(const Nlm_Char* file, const Nlm_Char* section, const Nlm_Char* type, const Nlm_Char* dflt, Nlm_Char* buf, Nlm_Int2 buflen, Nlm_Boolean searchTransient)
-{
- static char _empty_string[] = "";
- Nlm_Char path[PATH_MAX + 1];
-
- if (buf == NULL || buflen <= 0)
- return 0;
-
- *buf = '\0';
- if (searchTransient &&
- Nlm_TransientLookup(file, section, type, dflt, buf, buflen))
- {
- return (Nlm_Int2)Nlm_StringLen(buf);
- }
-
- if ( dflt )
- Nlm_StringNCpy_0(buf, dflt, buflen);
-
- if (file != NULL && *file != '\0' && section != NULL && *section != '\0')
- {
- Nlm_StringNCpy_0(path, file, sizeof(path) - 4);
- if ( !Nlm_Qualified( path ) )
- Nlm_StringCat(path, ".INI");
- if (dflt == NULL)
- dflt = _empty_string; /* can't use NULL, must be empty string */
- return (Nlm_Int2)GetPrivateProfileString(section,
- type, dflt, buf, buflen, path);
- }
- else
- return (Nlm_Int2)Nlm_StringLen( buf );
-}
-
-/*****************************************************************************
-*
-* Nlm_SetAppParam (file, section, type, value)
-* finds paths for types of data and fills in path in buf
-* if configuration file is found, trys to write the parameter to it.
-*
-*****************************************************************************/
-
-static Nlm_Boolean Nlm_SetAppParam_ST(const Nlm_Char* file, const Nlm_Char* section, const Nlm_Char* type, const Nlm_Char* value)
-{
- Nlm_Char path [PATH_MAX+1];
- Nlm_Boolean rsult;
-
- rsult = FALSE;
- if (file != NULL && *file != '\0' && section != NULL && *section != '\0') {
- Nlm_StringNCpy_0(path, file, sizeof(path) - 4);
- if ( ! Nlm_Qualified (path) ) {
- Nlm_StringCat (path, ".INI");
- }
- Nlm_TransientLogSetApp (file, section, type, value);
- if (WritePrivateProfileString (section, type, value, path)) {
- rsult = TRUE;
- }
- }
- return rsult;
-}
-
-/*****************************************************************************
-* Nlm_FreeConfigStruct ()
-* frees parameter structure in memory
-*****************************************************************************/
-static void Nlm_FreeConfigStruct_ST(void)
-{
- Nlm_FreeTransientData ();
-}
-
-#endif /* else !OS_MSWIN */
-
/*****************************************************************************
* Nlm_Qualified ()
diff --git a/corelib/ncbifile.c b/corelib/ncbifile.c
index 1b881b88..f0c05cfa 100644
--- a/corelib/ncbifile.c
+++ b/corelib/ncbifile.c
@@ -29,7 +29,7 @@
*
* Version Creation Date: 3/4/91
*
-* $Revision: 6.35 $
+* $Revision: 6.37 $
*
* File Description:
* portable file routines
@@ -43,6 +43,12 @@
* 11-27-94 Ostell moved includes to ncbiwin.h to avoid conflict MSC
*
* $Log: ncbifile.c,v $
+* Revision 6.37 2004/07/21 18:08:30 kans
+* FileCacheSetup calls _setmode (_fileno (fp), _O_BINARY) if OS_MSWIN
+*
+* Revision 6.36 2004/07/20 19:37:30 kans
+* FileCacheSeek always initializes fields, calls fseek to keep file pointer in sync
+*
* Revision 6.35 2004/05/07 15:57:14 kans
* added FileCache functions for buffered read, graceful handing of Unix, Mac, and DOS line endings
*
@@ -1369,6 +1375,11 @@ NLM_EXTERN Nlm_CharPtr LIBCALL Nlm_TmpNam (Nlm_CharPtr s)
/* attach file pointer (text read mode expected) to cache object (usually on stack) */
+#ifdef OS_MSWIN
+#include <fcntl.h>
+#include <io.h>
+#endif
+
NLM_EXTERN Nlm_Boolean Nlm_FileCacheSetup (
Nlm_FileCache PNTR fcp,
FILE *fp
@@ -1377,6 +1388,10 @@ NLM_EXTERN Nlm_Boolean Nlm_FileCacheSetup (
{
if (fp == NULL || fcp == NULL) return FALSE;
+#ifdef OS_MSWIN
+ _setmode (_fileno (fp), _O_BINARY);
+#endif
+
MemSet ((Nlm_VoidPtr) fcp, 0, sizeof (Nlm_FileCache));
fcp->fp = fp;
@@ -1427,7 +1442,7 @@ static Nlm_Char Nlm_FileCacheGetChar (
Nlm_FileCacheReadBlock (fcp);
}
- /* get next Nlm_Character in buffer */
+ /* get next character in buffer */
if (fcp->ctr < fcp->total) {
ch = fcp->buf [(int) fcp->ctr];
@@ -1444,7 +1459,7 @@ static Nlm_Char Nlm_FileCacheGetChar (
nxt = fcp->buf [(int) fcp->ctr];
- /* advance past second Nlm_Character in cr/lf pair */
+ /* advance past second character in cr/lf pair */
if (ch == '\n' && nxt == '\r') {
(fcp->ctr)++;
@@ -1547,10 +1562,12 @@ NLM_EXTERN void Nlm_FileCacheSeek (
{
if (fcp == NULL || fcp->fp == NULL) return;
+ /*
if (fcp->offset <= pos && fcp->offset + (Nlm_Int4) fcp->total >= pos) {
fcp->ctr = (Nlm_Int2) (pos - fcp->offset);
return;
}
+ */
fcp->ctr = 0;
fcp->total = 0;
diff --git a/corelib/ncbilcl.fbd b/corelib/ncbilcl.fbd
index 53431e44..96b0d077 100644
--- a/corelib/ncbilcl.fbd
+++ b/corelib/ncbilcl.fbd
@@ -29,7 +29,7 @@
*
* Version Creation Date: 8/1/94
*
-* $Revision: 1.2 $
+* $Revision: 1.3 $
*
* File Description:
* system dependent header
@@ -41,6 +41,9 @@
* ------- ---------- ---------------------------------------------------
*
* $Log: ncbilcl.fbd,v $
+* Revision 1.3 2004/08/12 12:06:45 beloslyu
+* fix for FreeBSD 5.2.1
+*
* Revision 1.2 2002/11/22 20:05:04 lavr
* Configure HAVE_STRDUP and HAVE_STRCASECMP
*
@@ -66,7 +69,7 @@
/* Desired or available feature list */
/*----------------------------------------------------------------------*/
#define SYSV_IPC_AVAIL /* System V Interprocess Communication available */
-#define _POSIX_C_SOURCE 199309L
+/* #define _POSIX_C_SOURCE 199309L */
#define HAVE_STRCASECMP 1
#define HAVE_STRDUP 1
@@ -77,6 +80,7 @@
#include <limits.h>
#include <sys/stat.h>
#include <sys/param.h>
+#include <sys/select.h>
#include <stddef.h>
#include <stdio.h>
#include <ctype.h>
diff --git a/corelib/ncbimem.c b/corelib/ncbimem.c
index fbfbcf82..589871bb 100644
--- a/corelib/ncbimem.c
+++ b/corelib/ncbimem.c
@@ -29,7 +29,7 @@
*
* Version Creation Date: 6/4/91
*
-* $Revision: 6.25 $
+* $Revision: 6.26 $
*
* File Description:
* portable memory handlers for Mac, PC, Unix
@@ -37,6 +37,9 @@
* Modifications:
* --------------------------------------------------------------------------
* $Log: ncbimem.c,v $
+* Revision 6.26 2004/09/01 21:21:54 kans
+* if Windows but not DLL, handle functions now implemented with direct pointer
+*
* Revision 6.25 2003/08/11 19:43:27 rsmith
* Memory Handle functions apply to Mac OS Darwin (OSX) not just to OS_MAC (OS9)
*
@@ -549,7 +552,11 @@ NLM_EXTERN Nlm_Handle LIBCALL Nlm_HandGet (size_t size, Nlm_Boolean clear_out)
#endif
#ifdef OS_MSWIN
+#ifdef _DLL
hnd = (Nlm_Handle) GlobalAlloc (GMEM_MOVEABLE, size);
+#else
+ hnd = (Nlm_Handle) malloc (size);
+#endif
#endif
#ifdef MSC_VIRT
@@ -620,7 +627,11 @@ NLM_EXTERN Nlm_Handle LIBCALL Nlm_HandMore (Nlm_Handle hnd, size_t size)
#endif
#ifdef OS_MSWIN
- hnd2 = (Nlm_Handle) GlobalReAlloc ((HANDLE)hnd, size, GHND);
+#ifdef _DLL
+ hnd2 = (Nlm_Handle) GlobalReAlloc ((HANDLE) hnd, size, GHND);
+#else
+ hnd2 = (Nlm_Handle) realloc (hnd, size);
+#endif
#endif
#ifdef MSC_VIRT
@@ -653,7 +664,11 @@ NLM_EXTERN Nlm_Handle LIBCALL Nlm_HandFree (Nlm_Handle hnd)
#endif
#ifdef OS_MSWIN
+#ifdef _DLL
GlobalFree ((HANDLE) hnd);
+#else
+ free (hnd);
+#endif
#endif
#ifdef MSC_VIRT
@@ -691,7 +706,11 @@ NLM_EXTERN Nlm_VoidPtr LIBCALL Nlm_HandLock (Nlm_Handle hnd)
#endif
#ifdef OS_MSWIN
+#ifdef _DLL
ptr = GlobalLock ((HANDLE) hnd);
+#else
+ ptr = hnd;
+#endif
#endif
#ifdef MSC_VIRT
@@ -721,7 +740,11 @@ NLM_EXTERN Nlm_VoidPtr LIBCALL Nlm_HandUnlock (Nlm_Handle hnd)
#endif
#ifdef OS_MSWIN
+#ifdef _DLL
GlobalUnlock ((HANDLE) hnd);
+#else
+ /* nothing */
+#endif
#endif
#ifdef MSC_VIRT
diff --git a/corelib/ncbiopt.h b/corelib/ncbiopt.h
index 8693e881..d3f38828 100644
--- a/corelib/ncbiopt.h
+++ b/corelib/ncbiopt.h
@@ -1,7 +1,7 @@
#ifndef _NCBIOPT_
#define _NCBIOPT_
-/* $Id: ncbiopt.h,v 6.14 2004/03/25 17:10:57 lebedev Exp $
+/* $Id: ncbiopt.h,v 6.15 2004/07/15 15:11:45 ucko Exp $
* ==========================================================================
*
* PUBLIC DOMAIN NOTICE
@@ -34,6 +34,9 @@
*
* --------------------------------------------------------------------------
* $Log: ncbiopt.h,v $
+* Revision 6.15 2004/07/15 15:11:45 ucko
+* Disable workaround for Linux distributions (RH7?) that misdefine LONG_BIT.
+*
* Revision 6.14 2004/03/25 17:10:57 lebedev
* Include stdint.h for Darwin, so undef will work for UINT8_MAX
*
@@ -132,7 +135,7 @@ by including it first.
# endif
/* on 64-bit operating systems, the long data type is already 8 bytes */
-# if LONG_BIT==64 && !defined(OS_UNIX_LINUX)
+# if LONG_BIT==64 /* && !defined(OS_UNIX_LINUX) */
# define Int8 long
# define Uint8 unsigned long