+++ /dev/null
-#if WIN32\r
-#include <windows.h>\r
-#include <share.h>\r
-#endif\r
-\r
-#include "muscle.h"\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <stdarg.h>\r
-#include <string.h>\r
-#include <math.h>\r
-#include <assert.h>\r
-#include <time.h>\r
-#include <errno.h>\r
-\r
-#ifndef MAX_PATH\r
-#define MAX_PATH 260\r
-#endif\r
-\r
-static char g_strListFileName[MAX_PATH];\r
-static bool g_bListFileAppend = false;\r
-\r
-static SEQWEIGHT g_SeqWeight = SEQWEIGHT_Undefined;\r
-\r
-void SetSeqWeightMethod(SEQWEIGHT Method)\r
- {\r
- g_SeqWeight = Method;\r
- }\r
-\r
-SEQWEIGHT GetSeqWeightMethod()\r
- {\r
- return g_SeqWeight;\r
- }\r
-\r
-void SetListFileName(const char *ptrListFileName, bool bAppend)\r
- {\r
- assert(strlen(ptrListFileName) < MAX_PATH);\r
- strcpy(g_strListFileName, ptrListFileName);\r
- g_bListFileAppend = bAppend;\r
- }\r
-\r
-void Log(const char szFormat[], ...)\r
- {\r
- if (0 == g_strListFileName[0])\r
- return;\r
-\r
- static FILE *f = NULL;\r
- const char *mode;\r
- if (g_bListFileAppend)\r
- mode = "a";\r
- else\r
- mode = "w";\r
- if (NULL == f)\r
- f = _fsopen(g_strListFileName, mode, _SH_DENYNO);\r
- if (NULL == f)\r
- {\r
- perror(g_strListFileName);\r
- exit(EXIT_NotStarted);\r
- }\r
-\r
- char szStr[4096];\r
- va_list ArgList;\r
- va_start(ArgList, szFormat);\r
- vsprintf(szStr, szFormat, ArgList);\r
- fprintf(f, "%s", szStr);\r
- fflush(f);\r
- }\r
-\r
-const char *GetTimeAsStr()\r
- {\r
- static char szStr[32];\r
- time_t t;\r
- time(&t);\r
- struct tm *ptmCurrentTime = localtime(&t);\r
- strcpy(szStr, asctime(ptmCurrentTime));\r
- assert('\n' == szStr[24]);\r
- szStr[24] = 0;\r
- return szStr;\r
- }\r
-\r
-// Exit immediately with error message, printf-style.\r
-void Quit(const char szFormat[], ...)\r
- {\r
- va_list ArgList;\r
- char szStr[4096];\r
-\r
- va_start(ArgList, szFormat);\r
- vsprintf(szStr, szFormat, ArgList);\r
-\r
- fprintf(stderr, "\n*** ERROR *** %s\n", szStr);\r
-\r
- Log("\n*** FATAL ERROR *** ");\r
- Log("%s\n", szStr);\r
- Log("Stopped %s\n", GetTimeAsStr());\r
-\r
-#ifdef WIN32\r
- if (IsDebuggerPresent())\r
- {\r
- int iBtn = MessageBox(NULL, szStr, "muscle", MB_ICONERROR | MB_OKCANCEL);\r
- if (IDCANCEL == iBtn)\r
- Break();\r
- }\r
-#endif\r
- exit(EXIT_FatalError);\r
- }\r
-\r
-void Warning(const char szFormat[], ...)\r
- {\r
- va_list ArgList;\r
- char szStr[4096];\r
-\r
- va_start(ArgList, szFormat);\r
- vsprintf(szStr, szFormat, ArgList);\r
-\r
- fprintf(stderr, "\n*** WARNING *** %s\n", szStr);\r
- Log("\n*** WARNING *** %s\n", szStr);\r
- }\r
-\r
-// Remove leading and trailing blanks from string\r
-void TrimBlanks(char szStr[])\r
- {\r
- TrimLeadingBlanks(szStr);\r
- TrimTrailingBlanks(szStr);\r
- }\r
-\r
-void TrimLeadingBlanks(char szStr[])\r
- {\r
- size_t n = strlen(szStr);\r
- while (szStr[0] == ' ')\r
- {\r
- memmove(szStr, szStr+1, n);\r
- szStr[--n] = 0;\r
- }\r
- }\r
-\r
-void TrimTrailingBlanks(char szStr[])\r
- {\r
- size_t n = strlen(szStr);\r
- while (n > 0 && szStr[n-1] == ' ')\r
- szStr[--n] = 0;\r
- }\r
-\r
-bool Verbose()\r
- {\r
- return true;\r
- }\r
-\r
-SCORE StrToScore(const char *pszStr)\r
- {\r
- return (SCORE) atof(pszStr);\r
- }\r
-\r
-void StripWhitespace(char szStr[])\r
- {\r
- unsigned uOutPos = 0;\r
- unsigned uInPos = 0;\r
- while (char c = szStr[uInPos++])\r
- if (' ' != c && '\t' != c && '\n' != c && '\r' != c)\r
- szStr[uOutPos++] = c;\r
- szStr[uOutPos] = 0;\r
- }\r
-\r
-void StripGaps(char szStr[])\r
- {\r
- unsigned uOutPos = 0;\r
- unsigned uInPos = 0;\r
- while (char c = szStr[uInPos++])\r
- if ('-' != c)\r
- szStr[uOutPos++] = c;\r
- szStr[uOutPos] = 0;\r
- }\r
-\r
-bool IsValidSignedInteger(const char *Str)\r
- {\r
- if (0 == strlen(Str))\r
- return false;\r
- if ('+' == *Str || '-' == *Str)\r
- ++Str;\r
- while (char c = *Str++)\r
- if (!isdigit(c))\r
- return false;\r
- return true;\r
- }\r
-\r
-bool IsValidInteger(const char *Str)\r
- {\r
- if (0 == strlen(Str))\r
- return false;\r
- while (char c = *Str++)\r
- if (!isdigit(c))\r
- return false;\r
- return true;\r
- }\r
-\r
-// Is c valid as first character in an identifier?\r
-bool isidentf(char c)\r
- {\r
- return isalpha(c) || '_' == c;\r
- }\r
-\r
-// Is c valid character in an identifier?\r
-bool isident(char c)\r
- {\r
- return isalpha(c) || isdigit(c) || '_' == c;\r
- }\r
-\r
-bool IsValidIdentifier(const char *Str)\r
- {\r
- if (!isidentf(Str[0]))\r
- return false;\r
- while (char c = *Str++)\r
- if (!isident(c))\r
- return false;\r
- return true;\r
- }\r
-\r
-void SetLogFile()\r
- {\r
- const char *strFileName = ValueOpt("loga");\r
- if (0 != strFileName)\r
- g_bListFileAppend = true;\r
- else\r
- strFileName = ValueOpt("log");\r
- if (0 == strFileName)\r
- return;\r
- strcpy(g_strListFileName, strFileName);\r
- }\r
-\r
-// Get filename, stripping any extension and directory parts.\r
-void NameFromPath(const char szPath[], char szName[], unsigned uBytes)\r
- {\r
- if (0 == uBytes)\r
- return;\r
- const char *pstrLastSlash = strrchr(szPath, '/');\r
- const char *pstrLastBackslash = strrchr(szPath, '\\');\r
- const char *pstrLastDot = strrchr(szPath, '.');\r
- const char *pstrLastSep = pstrLastSlash > pstrLastBackslash ?\r
- pstrLastSlash : pstrLastBackslash;\r
- const char *pstrBegin = pstrLastSep ? pstrLastSep + 1 : szPath;\r
- const char *pstrEnd = pstrLastDot ? pstrLastDot - 1 : szPath + strlen(szPath);\r
- unsigned uNameLength = (unsigned) (pstrEnd - pstrBegin + 1);\r
- if (uNameLength > uBytes - 1)\r
- uNameLength = uBytes - 1;\r
- memcpy(szName, pstrBegin, uNameLength);\r
- szName[uNameLength] = 0;\r
- }\r
-\r
-char *strsave(const char *s)\r
- {\r
- char *ptrCopy = strdup(s);\r
- if (0 == ptrCopy)\r
- Quit("Out of memory");\r
- return ptrCopy;\r
- }\r
-\r
-bool IsValidFloatChar(char c)\r
- {\r
- return isdigit(c) || '.' == c || 'e' == c || 'E' == c || 'd' == c ||\r
- 'D' == c || '.' == c || '+' == c || '-' == c;\r
- }\r
-\r
-void Call_MY_ASSERT(const char *file, int line, bool b, const char *msg)\r
- {\r
- if (b)\r
- return;\r
- Quit("%s(%d): MY_ASSERT(%s)", file, line, msg);\r
- }\r
-\r
-static size_t g_MemTotal;\r
-\r
-void MemPlus(size_t Bytes, char *Where)\r
- {\r
- g_MemTotal += Bytes;\r
- Log("+%10u %6u %6u %s\n",\r
- (unsigned) Bytes,\r
- (unsigned) GetMemUseMB(),\r
- (unsigned) (g_MemTotal/1000000),\r
- Where);\r
- }\r
-\r
-void MemMinus(size_t Bytes, char *Where)\r
- {\r
- g_MemTotal -= Bytes;\r
- Log("-%10u %6u %6u %s\n",\r
- (unsigned) Bytes,\r
- (unsigned) GetMemUseMB(),\r
- (unsigned) (g_MemTotal/1000000),\r
- Where);\r
- }\r