7 #define _FILE_OFFSET_BITS 64
18 #include <sys/types.h> 19 #include <sys/times.h> 50 # ifdef USE_SECURE_FUNCS
53 strerror_s (buff,
sizeof (buff), errorNo);
56 const char* buff = _sys_errlist[errorNo];
61 const char* buff = strerror (errorNo);
80 # ifdef USE_SECURE_FUNCS
81 fopen_s (&f, fileName, mode);
83 f = fopen (fileName, mode);
110 return _fseeki64(f, offset, origin);
112 return fseeko (f, offset, origin);
137 searchFields->PushOnBack (
new KKStr (
"*"));
141 # ifdef USE_SECURE_FUNCS
142 char* workStr = _strdup (searchSpec.Str ());
144 char* workStr = strdup (searchSpec.Str ());
149 char* startOfField = cp;
156 if (startOfField != cp)
157 searchFields->PushOnBack (
new KKStr (startOfField));
159 searchFields->PushOnBack (
new KKStr (
"*"));
160 startOfField = cp + 1;
165 if (cp != startOfField)
169 searchFields->PushOnBack (
new KKStr (startOfField));
181 KKStrListPtr searchFields
187 if (searchFields->QueueSize () < 1)
190 KKStrConstPtr field = searchFields->IdxToPtr (0);
192 if (searchFields->QueueSize () == 1)
197 if (*field == fileName)
203 bool lastFieldAStar =
false;
205 const char* cp = fileName
.Str ();
210 for (fieldNum = 0; fieldNum < searchFields->QueueSize (); fieldNum++)
212 const KKStr& field = *(searchFields->IdxToPtr (fieldNum));
216 lastFieldAStar =
true;
224 bool matchFound =
false;
226 while ((!matchFound) && (lenLeftToCheck >= field
.Len ()))
228 if (strncmp (cp, field.Str (), field.Len ()) == 0)
232 cp = cp + field.Len ();
233 if (field.Len() > lenLeftToCheck)
236 lenLeftToCheck = lenLeftToCheck - field.Len ();
255 if (lenLeftToCheck < field
.Len ())
261 if (strncmp (cp, field.Str (), field.Len ()) != 0)
269 cp = cp + field.Len ();
270 lenLeftToCheck = lenLeftToCheck - field.Len ();
274 lastFieldAStar =
false;
279 if (lenLeftToCheck > 0)
325 while (reqLen > buffLen)
332 buff =
new char[buffLen];
334 reqLen = GetCurrentDirectory (buffLen, buff);
350 KKStr KKB::osGetCurrentDirectory ()
359 buffLen = buffLen + 1000;
364 buff =
new char[buffLen];
366 result = getcwd (buff, buffLen);
384 DWORD returnCd = GetFileAttributes (name->Str ());
386 if (returnCd == 0xFFFFFFFF)
391 if ((FILE_ATTRIBUTE_DIRECTORY & returnCd) != FILE_ATTRIBUTE_DIRECTORY)
400 #define INVALID_FILE_ATTRIBUTES ((DWORD)-1
) 401 DWORD returnCd = GetFileAttributes (name.Str ());
407 if ((FILE_ATTRIBUTE_DIRECTORY & returnCd) != FILE_ATTRIBUTE_DIRECTORY)
415 bool KKB::osValidDirectory (KKStrConstPtr name)
417 DIR* openDir = opendir (name->Str ());
428 bool KKB::osValidDirectory (
const KKStr& name)
430 DIR* openDir = opendir (name.Str ());
460 const char* invalidChars =
"\\\" :<>!?*";
461 const char* invalidNames[] = {
"CON",
"PRN",
"AUX",
"NUL",
"COM1",
"COM2",
462 "COM3",
"COM4",
"COM5",
"COM6",
"COM7",
"COM8",
463 "COM9",
"LPT1",
"LPT2",
"LPT3",
"LPT4",
"LPT5",
464 "LPT6",
"LPT7",
"LPT8",
"LPT9",
471 errors->PushOnBack (
new KKStr (
"Blank names are invalid!"));
478 while (invalidNames[x] != NULL)
480 if (_name.EqualIgnoreCase (invalidNames[x]))
481 errors->PushOnBack (
new KKStr (
"Can not use \"" + _name +
"\""));
486 for (x = 0; x < _name
.Len (); ++x)
490 errors->PushOnBack (
new KKStr (
"Null character at position: " + StrFormatInt (x,
"##0")));
493 errors->PushOnBack (
new KKStr (
"No spaces allowed."));
497 errors->PushOnBack (
new KKStr (
"Character at position: " + StrFormatInt (x,
"##0") +
" has ordinal value of: " + StrFormatInt (c,
"##0")));
500 else if (strchr (invalidChars, c) != NULL)
502 KKStr invalidStr (2);
503 invalidStr.Append (c);
504 errors->PushOnBack (
new KKStr (
"Invalid character: " + invalidStr +
" at position: " + StrFormatInt (x,
"##0")));
509 if (errors->QueueSize () < 1)
527 const char* fileName = _fileName
.Str ();
529 if (DeleteFile (fileName))
535 DWORD fileAttributes = GetFileAttributes (fileName);
536 fileAttributes = FILE_ATTRIBUTE_NORMAL;
537 if (!SetFileAttributes (fileName, fileAttributes))
545 return (DeleteFile (fileName) != 0);
554 returnCd = unlink (_fileName.Str ());
555 return (returnCd == 0);
570 const char* fileName = _fileName
.Str ();
572 #define INVALID_FILE_ATTRIBUTES ((DWORD)-1
) 574 DWORD fileAttributes = GetFileAttributes (fileName);
578 DWORD lastErrorNum = GetLastError ();
579 if ((lastErrorNum == ERROR_FILE_NOT_FOUND) || (lastErrorNum == 3))
590 bool KKB::osFileExists (
const KKStr& _fileName)
595 result = stat (_fileName.Str (), &buff);
610 const KKStr& _srcDir,
611 const KKStr& _destDir
625 srcName << _fileName;
626 destName << _fileName;
628 return (MoveFile (srcName.Str (), destName.Str ()) != 0);
632 cerr <<
"*** osMoveFileBetweenDirectories ***" << std::endl;
634 cerr <<
"*** Not yet implemented ***" << std::endl;
644 const KKStr& _srcDir,
645 const KKStr& _destDir
649 KKStr destinationName
(_destDir
);
653 existingFile << _fileName;
656 destinationName << _fileName;
658 bool result = (CopyFile (existingFile.Str (),
659 destinationName.Str (),
670 bool KKB::osCopyFileBetweenDirectories (
const KKStr& _fileName,
671 const KKStr& _srcDir,
672 const KKStr& _destDir
676 cerr <<
"*** osCopyFileBetweenDirectories ***" << std::endl;
678 cerr <<
"*** Not yet implemented ***" << std::endl;
690 const KKStr& destFileName
695 bool result = (CopyFile (srcFileName.Str (),
707 DWORD lastError = GetLastError ();
709 KKStr errorMessage = StrFormatInt (lastError,
"#,###,##0");
712 <<
"osCopyFile *** ERROR ***" << std::endl
713 <<
" srcFileName [" << srcFileName <<
"]" << std::endl
714 <<
" destFileName[" << destFileName <<
"]" << std::endl
715 <<
" Error Code [" << lastError <<
"]" << std::endl
716 <<
" Error Msg [" << errorMessage <<
"]" << std::endl;
725 bool KKB::osCopyFile (
const KKStr& srcFileName,
726 const KKStr& destFileName
730 cerr <<
"*** osCopyFile ***" << std::endl;
732 cerr <<
"*** Not yet implemented ***" << std::endl;
747 bool returnCd = (MoveFile (oldName.Str (), newName.Str ()) != 0);
751 DWORD lastError = GetLastError ();
754 <<
"osRenameFile *** ERROR ***, Rename Failed" << std::endl
756 <<
" oldName[" << oldName <<
"] NewName[" << newName <<
"]" << std::endl
757 <<
" LastError[" << lastError <<
"]" << std::endl
768 bool KKB::osRenameFile (
const KKStr& oldName,
773 kkint32 returnCd = rename (oldName.Str (), newName.Str ());
778 kkint32 errorCode = errno;
781 <<
"osRenameFile *** ERROR ***, Rename Failed" << std::endl
782 <<
" oldName[" << oldName <<
"] NewName[" << newName <<
"]" << std::endl
783 <<
" errno[" << errorCode <<
"]" << std::endl
800 BOOL changeOk = SetCurrentDirectory(dirName.Str ());
807 kkint32 errorCd = chdir (dirName.Str ());
808 successful = (errorCd == 0);
812 cerr << std::endl << std::endl << std::endl
813 <<
"osChangeDir *** ERROR *** DirPath[" << dirName <<
"]" << std::endl
827 KKStr nextPartOfPath;
850 pathNameSoFar << nextPartOfPath;
855 if (!createdSucessfully)
858 <<
"osCreateDirectoryPath Error Creating Directory[" << pathNameSoFar <<
"]" 878 return (CreateDirectory (_dirName.Str (), NULL) != 0);
884 mode_t mode = S_IRWXU + S_IRWXG;
886 result = mkdir (_dirName.Str (), mode);
902 varLen = GetEnvironmentVariable (_varName.Str (), buff,
sizeof (buff));
910 return new KKStr (buff);
917 KKStrPtr KKB::osGetEnvVariable (
const KKStr& _varName)
919 char* envStrValue = NULL;
921 envStrValue = getenv (_varName.Str ());
924 return new KKStr (envStrValue);
953 int y = startIdx + 1;
955 const char* s = str
.Str ();
964 if ((s[y] ==
'(') || (s[y] ==
'{') || (s[y] ==
'['))
980 if (x < 0)
return src;
989 if (startChar ==
'(') endChar =
')';
990 else if (startChar ==
'{') endChar =
'}';
991 else if (startChar ==
'[') endChar =
']';
996 if (x < 0)
return src;
1002 if (envStrValue == NULL)
1003 envStrValue =
new KKStr (
"${" + envStrName
+ "}");
1006 str
= beforeEnvStr
+ (*envStrValue)
+ afterStrName;
1022 return Max (lastLeftSlash, lastRightSlash);
1032 if (firstForewardSlash < 0)
1033 return firstBackSlash;
1035 else if (firstBackSlash < 0)
1036 return firstForewardSlash;
1038 return Min (firstForewardSlash, firstBackSlash);
1049 if ((c !=
'\\') && (c !=
'/'))
1067 const KKStr& _fileName
1070 KKStr fullFileName
(_dirName
);
1074 fullFileName << _fileName;
1076 return fullFileName;
1086 KKStr path, root, ext;
1092 return root
+ "." + ext;
1122 _rootName
= _fileName;
1142 if (lastPeriodChar < lastSlashChar)
1143 return KKStr (_fullFileName);
1145 if (lastPeriodChar <= 1)
1146 return KKStr (_fullFileName);
1159 kkint32 lastSlashOrColon = Max (lastSlashChar, lastColon);
1162 if (lastSlashOrColon < 0)
1164 lastPart
= fullFileName;
1189 kkint32 lastSlashOrColon = Max (lastSlashChar, lastColon);
1192 if (lastSlashOrColon < 0)
1193 lastPart
= fullDirName;
1224 kkint32 lastSlashOrColon = Max (lastSlashChar, lastColon);
1227 if (lastSlashOrColon < 0)
1229 lastPart
= fullFileName;
1257 if (driveLetterPos >= 0)
1268 path
= fullFileName;
1278 fileName
= fullFileName;
1325 KKStr fileName, dirPath, rootName, extension;
1338 int x = Max (dirPath.LocateLastOccurrence (
'\\'), dirPath.LocateLastOccurrence (
'/'));
1358 DWORD buffSize =
sizeof (buff) - 1;
1359 memset (buff, 0,
sizeof(buff));
1361 KKStr compName =
"";
1364 BOOL returnCd = GetComputerNameA (buff, &buffSize);
1371 KKStrPtr compNameStr = osGetEnvVariable (
"COMPUTERNAME");
1374 compName = *compNameStr;
1390 memset (buff, 0,
sizeof (buff));
1391 kkint32 returnCd = gethostname (buff,
sizeof (buff) - 2);
1407 char filename[ MAX_PATH ];
1408 DWORD size = GetModuleFileNameA (NULL, filename, MAX_PATH);
1410 progName = filename;
1417 return "NotImplemented";
1429 TCHAR name [ UNLEN + 1 ];
1430 DWORD size = UNLEN + 1;
1432 KKStr userName =
"";
1433 if (GetUserName ((TCHAR*)name, &size))
1436 userName =
"***ERROR***";
1441 return "NoImplemented";
1454 if (numProcessorsStr)
1457 delete numProcessorsStr;
1458 numProcessorsStr = NULL;
1461 return numOfProcessors;
1481 return fullFileName;
1520 <<
"Press Enter To Continue" 1523 while (getchar () !=
'\n');
1533 WIN32_FIND_DATA wfd;
1535 HANDLE handle = FindFirstFile (fileSpec.Str (), &wfd);
1537 if (handle == INVALID_HANDLE_VALUE)
1544 BOOL moreFiles =
true;
1547 if ((wfd.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) == 0)
1549 if ((wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
1551 nameList->PushOnBack (
new KKStr (wfd.cFileName));
1555 moreFiles = FindNextFile (handle, &wfd);
1568 KKStrListPtr osDirectoryList (KKStr dirName)
1570 if (dirName.Empty ())
1572 dirName = osGetCurrentDirectory ();
1576 osAddLastSlash (dirName);
1579 KKStrListPtr nameList =
new KKB::KKStrList (
true);
1581 DIR* openDir = opendir (dirName.Str ());
1582 if (openDir == NULL)
1586 de = readdir (openDir);
1590 KKStr rootName (de->d_name);
1591 if ((rootName !=
".") && (rootName !=
".."))
1593 KKStr fullName (dirName);
1594 fullName << rootName;
1598 if ((fs.st_mode & S_IFDIR) == 0)
1600 nameList->PushOnBack (
new KKStr (rootName));
1604 de = readdir (openDir);
1616 KKStrListPtr KKB::osGetListOfFiles (
const KKStr& fileSpec)
1618 KKStr afterLastSlash;
1623 kkint32 lastSlash = osLocateLastSlashChar (fileSpec);
1627 dirPath = osGetCurrentDirectory ();
1628 afterLastSlash = fileSpec;
1632 dirPath = fileSpec.SubStrPart (0, lastSlash);
1633 afterLastSlash = fileSpec.SubStrPart (lastSlash + 1);
1636 osAddLastSlash (dirPath);
1638 KKStrListPtr allFilesInDirecory = osDirectoryList (dirPath);
1640 if (!allFilesInDirecory)
1643 KKStrListPtr searchSpecParms = osParseSearchSpec (afterLastSlash);
1645 KKStrListPtr resultList =
new KKStrList (
true);
1647 KKStrPtr name = NULL;
1648 KKStrList::iterator nameIDX;
1649 for (nameIDX = allFilesInDirecory->begin (); nameIDX != allFilesInDirecory->end (); ++nameIDX)
1652 if (osFileNameMatchesSearchFields (*name, searchSpecParms))
1653 resultList->PushOnBack (
new KKStr (*name));
1657 delete allFilesInDirecory;
1658 delete searchSpecParms;
1678 if (filesInThisDirectory)
1680 KKStrList::iterator idx;
1681 for (idx = filesInThisDirectory->begin (); idx != filesInThisDirectory->end (); idx++)
1685 fileNames.push_back (fullName);
1687 delete filesInThisDirectory; filesInThisDirectory = NULL;
1695 KKStrList::iterator idx;
1696 for (idx = subDirectories->begin (); idx != subDirectories->end (); idx++)
1698 KKStr subDirName = **idx;
1699 if ((subDirName
== ".") || (subDirName
== ".."))
1707 delete subDirectories; subDirectories = NULL;
1719 KKStrListPtr imageFileNames =
new KKStrList (true);
1724 KKStrList::iterator fnIDX;
1725 for (fnIDX = filesInDir->begin (); fnIDX != filesInDir->end (); ++fnIDX)
1727 KKStr fileName (**fnIDX);
1728 if (SupportedImageFileFormat (fileName))
1729 imageFileNames->PushOnBack (
new KKStr (fileName));
1736 return imageFileNames;
1745 WIN32_FIND_DATA wfd;
1757 fileSpec <<
"\\*.*";
1763 HANDLE handle = FindFirstFile (fileSpec.Str (), &wfd);
1765 if (handle == INVALID_HANDLE_VALUE)
1772 BOOL moreFiles =
true;
1775 if ((wfd.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) == 0)
1777 if ((wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
1779 KKStrPtr dirName =
new KKStr (wfd.cFileName);
1781 if ((*dirName !=
".") && (*dirName !=
".."))
1782 nameList->PushOnBack (dirName);
1788 moreFiles = FindNextFile (handle, &wfd);
1800 KKStrListPtr KKB::osGetListOfDirectories (KKStr fileSpec)
1804 kkint32 x = fileSpec.LocateCharacter (
'*');
1806 rootDirName = fileSpec.SubStrPart (0, x - 1);
1808 rootDirName = fileSpec;
1811 osAddLastSlash (rootDirName);
1813 KKStrListPtr nameList =
new KKStrList (
true);
1815 DIR* openDir = opendir (rootDirName.Str ());
1816 if (openDir == NULL)
1820 de = readdir (openDir);
1824 KKStr rootName (de->d_name);
1825 if ((rootName !=
".") && (rootName !=
".."))
1827 KKStr fullName (rootDirName);
1828 fullName << rootName;
1832 if ((fs.st_mode & S_IFDIR) != 0)
1834 nameList->PushOnBack (
new KKStr (rootName));
1838 de = readdir (openDir);
1857 HANDLE h = GetCurrentProcess ();
1859 FILETIME creationTime, exitTime, kernelTime, userTime;
1861 BOOL ok = GetProcessTimes (h, &creationTime, &exitTime, &kernelTime, &userTime);
1868 FileTimeToSystemTime(&kernelTime, &st);
1869 double kt = st.wHour * 3600 + st.wMinute * 60 + st.wSecond;
1870 kt += ((
double)st.wMilliseconds / 1000.0);
1872 FileTimeToSystemTime(&userTime, &st);
1873 double ut = st.wHour * 3600 + st.wMinute * 60 + st.wSecond;
1874 ut += ((
double)st.wMilliseconds / 1000.0);
1876 double numOfSecs = kt + ut;
1883 double KKB::osGetSystemTimeUsed ()
1887 double totalTime = (
double)(buff.tms_utime + buff.tms_stime);
1888 return (totalTime / (
double)(sysconf (_SC_CLK_TCK)));
1899 HANDLE h = GetCurrentProcess ();
1901 FILETIME creationTime, exitTime, kernelTime, userTime;
1903 BOOL ok = GetProcessTimes (h, &creationTime, &exitTime, &kernelTime, &userTime);
1911 FileTimeToSystemTime(&userTime, &st);
1912 double ut = st.wHour * 3600 +
1915 st.wMilliseconds / 1000.0;
1925 double KKB::osGetUserTimeUsed ()
1929 double totalTime = (
double)(buff.tms_utime);
1930 return (totalTime / (
double)(sysconf (_SC_CLK_TCK)));
1940 HANDLE h = GetCurrentProcess ();
1942 FILETIME creationTime, exitTime, kernelTime, userTime;
1944 BOOL ok = GetProcessTimes (h, &creationTime, &exitTime, &kernelTime, &userTime);
1951 FileTimeToSystemTime(&kernelTime, &st);
1952 double kt = st.wHour * 3600 +
1955 st.wMilliseconds / 1000.0;
1962 double KKB::osGetKernalTimeUsed ()
1966 double totalTime = (
double)(buff.tms_stime);
1967 return (totalTime / (
double)(sysconf (_SC_CLK_TCK)));
1978 return timeGetTime();
1982 kkuint64 KKB::osGetSystemTimeInMiliSecs ()
1985 gettimeofday(&now, NULL);
1986 return now.tv_usec/1000;
1997 GetLocalTime(&sysTime);
1999 DateTime dateTime ((
short)sysTime.wYear,
2000 (uchar)sysTime.wMonth,
2001 (uchar)sysTime.wDay,
2002 (uchar)sysTime.wHour,
2003 (uchar)sysTime.wMinute,
2004 (uchar)sysTime.wSecond
2014 DateTime KKB::osGetLocalDateTime ()
2020 curTime = localtime (&long_time);
2022 DateTime dateTime (curTime->tm_year + 1900,
2023 curTime->tm_mon + 1,
2039 WIN32_FIND_DATA wfd;
2041 HANDLE handle = FindFirstFile (fileName.Str (), &wfd);
2042 if (handle == INVALID_HANDLE_VALUE)
2044 return DateTime (0, 0, 0, 0 ,0 ,0);
2048 SYSTEMTIME fileTime;
2052 FileTimeToSystemTime (&(wfd.ftLastWriteTime), &fileTime);
2053 SystemTimeToTzSpecificLocalTime(NULL, &fileTime, &stLocal);
2055 return DateTime ((
short)stLocal.wYear,
2056 (uchar)stLocal.wMonth,
2057 (uchar)stLocal.wDay,
2058 (uchar)stLocal.wHour,
2059 (uchar)stLocal.wMinute,
2060 (uchar)stLocal.wSecond
2069 DateTime KKB::osGetFileDateTime (
const KKStr& fileName)
2073 kkint32 returnCd = stat (fileName.Str (), &buf);
2077 return DateTime (0, 0, 0, 0, 0, 0);
2081 struct tm* dt = localtime (&(buf.st_mtime));
2083 return DateTime (1900 + dt->tm_year,
2098 WIN32_FIND_DATA wfd;
2100 HANDLE handle = FindFirstFile (fileName.Str (), &wfd);
2101 if (handle == INVALID_HANDLE_VALUE)
2106 return (kkint64)(wfd.nFileSizeHigh) * (kkint64)MAXDWORD + (kkint64)(wfd.nFileSizeLow);
2112 KKB::kkint64 KKB::osGetFileSize (
const KKStr& fileName)
2116 kkint32 returnCd = stat (fileName.Str (), &buf);
2136 (MB_OK + MB_SETFOREGROUND)
2150 void KKB::osDisplayWarning (KKStr _message)
2153 <<
" *** WARNING ***" << std::endl
2155 << _message << std::endl
2158 if (!backGroundProcess)
2178 KKStr fileNameUpper
(fileName
);
2188 for (KKStrList::iterator nIDX = files->begin (); nIDX != files->end (); nIDX++)
2190 KKStrPtr fnPtr = *nIDX;
2205 for (KKStrList::iterator sdIDX = subDirs->begin (); sdIDX != subDirs->end (); sdIDX++)
2207 KKStr subDirName = osAddSlash (srcDir) + **sdIDX;
2217 delete subDirs; subDirs = NULL;
2229 fileName
= "Temp.txt";
2231 KKStr dirPath, rootName, extension;
2237 while (fileNameExists)
2266 KKStrPtr buff =
new KKStr (100
);
2272 char ch = fgetc (in);
2277 char nextCh = fgetc (in);
2279 ungetc (nextCh, in);
2283 else if (ch ==
'\n')
2302 const char* delimiters,
2311 kkint32 maxTokenLen =
sizeof (token) - 1;
2323 while ((!eof) && ((ch ==
' ') || (ch ==
'\r')) && (ch !=
'\n'))
2338 while ((!eof) && (!strchr (delimiters, ch)))
2347 token[tokenLen] = ch;
2350 if (tokenLen >= maxTokenLen)
2358 token[tokenLen] = 0;
2361 while (tokenLen > 0)
2363 if (strchr (
" \r", token[tokenLen - 1]) == 0)
2366 token[tokenLen] = 0;
2375 const char* delimiters,
2384 kkint32 maxTokenLen =
sizeof (token) - 1;
2386 kkint32 ch = fgetc (in); eof = (feof (in) != 0);
2395 while ((!eof) && ((ch ==
' ') || (ch ==
'\r')) && (ch !=
'\n'))
2396 {ch = fgetc (in); eof = (feof (in)!= 0);}
2407 while ((!eof) && (!strchr (delimiters, ch)))
2416 token[tokenLen] = ch;
2419 if (tokenLen >= maxTokenLen)
2422 ch = fgetc (in); eof = (feof (in)!= 0);
2426 token[tokenLen] = 0;
2430 while (tokenLen > 0)
2432 if (strchr (
" \r", token[tokenLen - 1]) == 0)
2435 token[tokenLen] = 0;
2445 const char* delimiters,
2451 kkint32 maxTokenLen =
sizeof (token) - 1;
2453 kkint32 ch = fgetc (in); eof = (feof (in) != 0);
2459 while ((!eof) && ((ch ==
' ') || (ch ==
'\r')) && (ch !=
'\n'))
2460 {ch = fgetc (in); eof = (feof (in)!= 0);}
2465 while ((!eof) && (!strchr (delimiters, ch)))
2467 token[tokenLen] = ch;
2470 if (tokenLen >= maxTokenLen)
2473 ch = fgetc (in); eof = (feof (in)!= 0);
2476 token[tokenLen] = 0;
2480 while (tokenLen > 0)
2482 if (strchr (
" \n\r", token[tokenLen - 1]) == 0)
2485 token[tokenLen] = 0;
2523 KKStrPtr result =
new KKStr (1024
);
2537 ch = in.get (); eof = in.eof ();
2556 eof = (feof (in) != 0);
2560 KKStrPtr result =
new KKStr(1024
);
2573 ch = fgetc (in); eof = (feof (in) != 0);
2599 const char* whiteSpaceCharacters,
2606 return KKStr::EmptyStr ();
2612 while ((!feof (in)) && (strchr (whiteSpaceCharacters, ch) != NULL))
2620 return KKStr::EmptyStr ();
2626 bool lookForTerminatingQuote =
false;
2632 lookForTerminatingQuote =
true;
2640 if (lookForTerminatingQuote)
2650 if (strchr (whiteSpaceCharacters, ch))
2657 if ((ch ==
'\\') && (lookForTerminatingQuote))
2664 case '"': result.Append (
'"');
break;
2665 case 't': result.Append (
'\t');
break;
2666 case 'n': result.Append (
'\n');
break;
2667 case 'r': result.Append (
'\r');
break;
2668 case '\\': result.Append (
'\\');
break;
2669 case '0': result.Append (
char (0));
break;
2671 default: result.Append (ch);
break;
2687 while ((!feof (in)) && (strchr (whiteSpaceCharacters, ch) != NULL))
2710 kkint32 ch = fgetc (in); eof = (feof (in) != 0);
2711 while ((ch !=
'\n') && (!eof))
2713 ch = fgetc (in); eof = (feof (in) != 0);
2727 while ((ch !=
'\n') && (!eof))
2740 DWORD processId = GetCurrentProcessId();
2744 pid_t processID = getpid ();
2756 DWORD threadId = GetCurrentThreadId();
2767 kkint32 miliSecsToSleep = (
kkint32)(1000.0f * secsToSleep + 0.5f);
2768 Sleep (miliSecsToSleep);
2770 kkint32 secsToSleepInt = (kkint32)(0.5f + secsToSleep);
2772 if (secsToSleepInt < 1)
2775 else if (secsToSleepInt > 3600)
2776 cout <<
"osSleep secsToSleep[" << secsToSleepInt <<
"]" << std::endl;
2778 sleep (secsToSleepInt);
2788 Sleep (numMiliSecs);
2790 int numSecsToSleep = (numMiliSecs / 1000);
2791 sleep (numSecsToSleep);
2808 parts.push_back (path.SubStrPart (0, 1));
2812 while (zed < path
.Len ())
2814 if (path
[zed] ==
'\\')
2816 parts.push_back (
"\\");
2819 else if (path
[zed] ==
'/')
2821 parts.push_back (
"/");
2828 while (zed < path
.Len ())
2830 if ((path
[zed] ==
'\\') || (path
[zed] ==
'/'))
2835 parts.push_back (path.SubStrPart (startPos, zed - 1));
2846 char szAppPath[MAX_PATH] =
"";
2847 DWORD result = ::GetModuleFileName (0, szAppPath, MAX_PATH);
2850 return KKStr::EmptyStr ();
__int16 kkint16
16 bit signed integer.
KKStr osGetFullPathOfApplication()
returns the name and path of the current running application.
char osGetDriveLetter(const KKStr &pathName)
Given a full drive with path and name return the drive letter specified.
KKStr(kkint32 size)
Creates a KKStr object that pre-allocates space for 'size' characters.
kkuint64 osGetSystemTimeInMiliSecs()
Returns mili-secs that system (Windows = has been started, Linux time in epoch).
bool osDeleteFile(KKStr _fileName)
bool osValidFileName(const KKStr &_name)
KKB::KKStr osReadNextToken(FILE *in, const char *delimiters, bool &eof, bool &eol)
Read the next logical token from a file using characters in 'delimiters' to separate tokens...
char operator[](kkint16 i) const
#define INVALID_FILE_ATTRIBUTES
KKStr & Trim(const char *whiteSpaceChars="\n\r\t ")
KKB::KKStr osReadNextQuotedStr(FILE *in, const char *whiteSpaceCharacters, bool &eof)
Read the next Quoted String from the file.
static bool StrEqualNoCase(const char *s1, const char *s2)
KKStr osRemoveExtension(const KKStr &_fullFileName)
KKB::DateTime osGetLocalDateTime()
Returned the current local date and time.
KKB::KKStrPtr osReadRestOfLine(std::istream &in, bool &eof)
Extracts text up to and including the next end-of-line character and returns pointer to dynamical all...
bool osValidDirectory(const KKStr &_name)
kkint32 osGetNumberOfProcessors()
returns the number of CPU's or number of simultaneous threads that you can have.
KKStr osGetParentDirPath(KKStr dirPath)
Returns the Parent directory path to 'dirPath'.
KKStr osGetPathPartOfFile(KKStr fullFileName)
Get the path part of a full file name specification.
kkint64 osFTELL(FILE *f)
Calls the appropriate 64 bit function for operating system.
KKStr & TrimRight(const char *whiteSpaceChars="\n\r\t ")
KKStr osCreateUniqueFileName(KKStr fileName)
Get a unique file name based off file spec 'fileName'.
KKStr osMakeFullFileName(const KKStr &_dirName, const KKStr &_fileName)
KKStrPtr osReadNextLine(FILE *in)
Read the next line from the file and return a c-String(NULL terminated).
KKStr ExtractToken(const char *delStr="\n\t\r ")
KKB::KKStr osReadNextToken(std::istream &in, const char *delimiters, bool &eof, bool &eol)
Read the next logical token from a file using characters in 'delimiters' to separate tokens...
void osGetListOfFilesInDirectoryTree(const KKStr &rootDir, KKStr fileSpec, VectorKKStr &fileNames)
void osSkipRestOfLine(std::istream &in, bool &eof)
Skips rest of the characters in the current line in the input stream.
KKStr & operator=(const char *src)
bool operator==(const char *rtStr) const
kkuint32 MaxLenSupported() const
KKStrListPtr osGetListOfImageFiles(KKStr fileSpec)
KKStrListPtr osGetListOfFiles(const KKStr &fileSpec)
Returns a list of files that match the provided file specification.
KKStr operator+(const char *right) const
double osGetKernalTimeUsed()
kkint32 osLocateLastSlashChar(const KKStr &fileSpec)
unsigned __int32 kkuint32
KKStr osReadNextToken(FILE *in, const char *delimiters, bool &eof)
Read the next logical token from a file using characters in 'delimiters' to separate tokens where ' '...
void osSleep(float numOfSecs)
KKStr osGetFileExtension(KKStr fullFileName)
bool osCopyFileBetweenDirectories(const KKStr &_fileName, const KKStr &_srcDir, const KKStr &_destDir)
char operator[](kkuint32 i) const
KKStr & operator=(KKStr &&src)
double osGetUserTimeUsed()
KKStrListPtr osValidFileNameErrors(const KKStr &_name)
Returns list of errors in '_name' with respect to it being a valid file name for the O/S...
KKB::KKStr osAddSlash(const KKStr &fileSpec)
KKB::KKStr osReadRestOfLine2(FILE *in, bool &eof)
kkuint32 Len() const
Returns the number of characters in the string.
void osParseFileName(KKStr _fileName, KKStr &_dirPath, KKStr &_rootName, KKStr &_extension)
KKStr osLookForFile(const KKStr &fileName, const KKStr &srcDir)
Look for a specified file in a sub-directory structure.
KKStr operator+(const char *left, const KKStr &right)
void osParseFileSpec(KKStr fullFileName, KKStr &driveLetter, KKStr &path, KKStr &root, KKStr &extension)
bool osFileNameMatchesSearchFields(const KKStr &fileName, KKStrListPtr searchFields)
KKStr(const KKStr &str)
Copy Constructor.
void osChangeDir(const KKStr &dirName, bool &successful)
kkint32 osLocateFirstSlashChar(const KKStr &fileSpec)
VectorKKStr osSplitDirectoryPathIntoParts(const KKStr &path)
KKStr SubStrPart(kkint32 firstChar, kkint32 lastChar) const
returns a SubString consisting of all characters starting at index 'firstChar' and ending at 'lastInd...
bool osValidDirectory(KKStrConstPtr _name)
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of 'std::string' strings.
void Upper()
Converts all characters in string to their Upper case equivalents via 'toupper'.
KKB::KKStr osReadRestOfLine2(std::istream &in, bool &eof)
kkint32 LocateLastOccurrence(char ch) const
Returns index of last occurrence of 'ch' otherwise -1.
void osSleepMiliSecs(kkuint32 numMiliSecs)
kkint32 LocateCharacter(char ch) const
Returns index of 1st occurrence of 'ch' otherwise -1.
static const KKStr & EmptyStr()
Static method that returns an Empty String.
KKStr osGetRootNameOfDirectory(KKStr fullDirName)
unsigned __int64 kkuint64
KKStr StrFormatInt(kkint32 val, const char *mask)
int osFSEEK(FILE *f, kkint64 offset, int origin)
KKStrPtr osGetEnvVariable(const KKStr &_varName)
KKStr operator+(const KKStr &right) const
bool osCreateDirectory(const KKStr &dirName)
const char * Str() const
Returns a pointer to a ascii string.
KKB::KKStr osSubstituteInEnvironmentVariables(const KKStr &src)
Substitute in the value of the environment variables into 'src'.
double osGetSystemTimeUsed()
Returns the number of CPU seconds used by current process.
bool osFileExists(const KKStr &_fileName)
KKStrListPtr osGetListOfDirectories(KKStr fileSpec)
FILE * osFOPEN(const char *fileName, const char *mode)
KKStr osGetParentDirectoryOfDirPath(KKStr path)
int osLocateEnvStrStart(const KKStr &str, kkint32 startIdx)
KKStr osGetFileNamePartOfFile(KKStr fullFileName)
osGetFileNamePartOfFile, retrieves the file name part of the file spec.
bool osCopyFile(const KKStr &srcFileName, const KKStr &destFileName)
bool osIsBackGroundProcess()
KKStr & operator=(const KKStr &src)
bool osMoveFileBetweenDirectories(const KKStr &_fileName, const KKStr &_srcDir, const KKStr &_destDir)
KKB::DateTime osGetFileDateTime(const KKStr &fileName)
KKStr osGetCurrentDirectory()
KKStr osGetRootNameWithExtension(const KKStr &fullFileName)
void osSkipRestOfLine(FILE *in, bool &eof)
Skips rest of the characters in the current line in the file.
bool osCreateDirectoryPath(KKStr _pathName)
Will create the whole Directory Path not just the final part of the path.
KKStr osGetDirNameFromPath(KKStr dirPath)
Extracts the final sub-directory name of the fill directory specification.
KKStr SubStrPart(kkint32 firstChar) const
returns a SubString consisting of all characters starting at index 'firstChar' until the end of the s...
KKStrListPtr osParseSearchSpec(const KKStr &searchSpec)
bool osRenameFile(const KKStr &oldName, const KKStr &newName)
char operator[](kkuint16 i) const
kkint64 osGetFileSize(const KKStr &fileName)
KKStr osGetErrorNoDesc(kkint32 errorNo)
KKB::KKStrPtr osReadRestOfLine(FILE *in, bool &eof)
KKStr osGetRootName(const KKStr &fullFileName)
void osDisplayWarning(KKStr _message)
void osAddLastSlash(KKStr &fileSpec)
Will add the appropriate Directory separator character to the end of fileSpec if one is not there alr...
void osRunAsABackGroundProcess()