mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
- Enhanced split algorithm to be non-destrutive, and therefore faster
- Added autoconf testing to detect Solaris - Added Solaris-specific flock implementation
This commit is contained in:
parent
50ccb67185
commit
3d4beaf41f
5 changed files with 73 additions and 28 deletions
12
configure.ac
12
configure.ac
|
@ -4,7 +4,6 @@
|
|||
AC_PREREQ(2.61)
|
||||
AC_INIT(task, 1.5.0, bugs@beckingham.net)
|
||||
|
||||
|
||||
CFLAGS="${CFLAGS=}"
|
||||
CXXFLAGS="${CXXFLAGS=}"
|
||||
# this macro is used to get the arguments supplied
|
||||
|
@ -25,6 +24,15 @@ CXXFLAGS="$CFLAGS -O3"
|
|||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
|
||||
# Check for OS.
|
||||
OS=`uname|sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
|
||||
if test "$OS" = "sunos"; then
|
||||
AC_MSG_NOTICE([OS Solaris detected])
|
||||
AC_DEFINE([SOLARIS], [], [Compiling on Solaris])
|
||||
else
|
||||
AC_MSG_NOTICE([OS Non-Solaris detected])
|
||||
AC_DEFINE([LINUX], [], [Compiling on Non-Solaris])
|
||||
fi
|
||||
|
||||
AM_INIT_AUTOMAKE
|
||||
AC_CONFIG_SRCDIR([src/task.cpp])
|
||||
|
@ -58,7 +66,7 @@ AC_STRUCT_TM
|
|||
AC_FUNC_MKTIME
|
||||
AC_FUNC_SELECT_ARGTYPES
|
||||
AC_CHECK_FUNCS([select])
|
||||
AC_CHECK_FUNC(flock, [AC_DEFINE([HAVE_FLOCK], [1], [Found flock])])
|
||||
#AC_CHECK_FUNC(flock, [AC_DEFINE([HAVE_FLOCK], [1], [Found flock])])
|
||||
AC_CHECK_FUNC(uuid_unparse_lower, [AC_DEFINE([HAVE_UUID], [1], [Found uuid_unparse_lower])])
|
||||
AC_CHECK_FUNC(random, [AC_DEFINE([HAVE_RANDOM], [1], [Found random])])
|
||||
AC_CHECK_FUNC(srandom, [AC_DEFINE([HAVE_SRANDOM], [1], [Found srandom])])
|
||||
|
|
12
src/TDB.cpp
12
src/TDB.cpp
|
@ -289,11 +289,7 @@ bool TDB::modifyT (const T& t)
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool TDB::lock (FILE* file) const
|
||||
{
|
||||
#ifdef HAVE_FLOCK
|
||||
return flock (fileno (file), LOCK_EX) ? false : true;
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -303,11 +299,9 @@ bool TDB::overwritePending (std::vector <T>& all)
|
|||
FILE* out;
|
||||
if ((out = fopen (mPendingFile.c_str (), "w")))
|
||||
{
|
||||
#ifdef HAVE_FLOCK
|
||||
int retry = 0;
|
||||
while (flock (fileno (out), LOCK_EX) && ++retry <= 3)
|
||||
delay (0.25);
|
||||
#endif
|
||||
|
||||
std::vector <T>::iterator it;
|
||||
for (it = all.begin (); it != all.end (); ++it)
|
||||
|
@ -328,11 +322,9 @@ bool TDB::writePending (const T& t)
|
|||
FILE* out;
|
||||
if ((out = fopen (mPendingFile.c_str (), "a")))
|
||||
{
|
||||
#ifdef HAVE_FLOCK
|
||||
int retry = 0;
|
||||
while (flock (fileno (out), LOCK_EX) && ++retry <= 3)
|
||||
delay (0.25);
|
||||
#endif
|
||||
|
||||
fputs (t.compose ().c_str (), out);
|
||||
|
||||
|
@ -351,11 +343,9 @@ bool TDB::writeCompleted (const T& t)
|
|||
FILE* out;
|
||||
if ((out = fopen (mCompletedFile.c_str (), "a")))
|
||||
{
|
||||
#ifdef HAVE_FLOCK
|
||||
int retry = 0;
|
||||
while (flock (fileno (out), LOCK_EX) && ++retry <= 3)
|
||||
delay (0.25);
|
||||
#endif
|
||||
|
||||
fputs (t.compose ().c_str (), out);
|
||||
|
||||
|
@ -380,11 +370,9 @@ bool TDB::readLockedFile (
|
|||
FILE* in;
|
||||
if ((in = fopen (file.c_str (), "r")))
|
||||
{
|
||||
#ifdef HAVE_FLOCK
|
||||
int retry = 0;
|
||||
while (flock (fileno (in), LOCK_EX) && ++retry <= 3)
|
||||
delay (0.25);
|
||||
#endif
|
||||
|
||||
char line[T_LINE_MAX];
|
||||
while (fgets (line, T_LINE_MAX, in))
|
||||
|
|
|
@ -130,6 +130,15 @@ const char* optionalBlankLine (Config&);
|
|||
int convertDuration (std::string&);
|
||||
std::string expandPath (const std::string&);
|
||||
|
||||
#ifdef SOLARIS
|
||||
#define LOCK_SH 1
|
||||
#define LOCK_EX 2
|
||||
#define LOCK_NB 4
|
||||
#define LOCK_UN 8
|
||||
|
||||
int flock (int, int);
|
||||
#endif
|
||||
|
||||
// rules.cpp
|
||||
void initializeColorRules (Config&);
|
||||
void autoColorize (T&, Text::color&, Text::color&);
|
||||
|
|
34
src/text.cpp
34
src/text.cpp
|
@ -49,33 +49,39 @@ void wrapText (
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void split (std::vector<std::string>& results, const std::string& input, const char delimiter)
|
||||
void split (
|
||||
std::vector<std::string>& results,
|
||||
const std::string& input,
|
||||
const char delimiter)
|
||||
{
|
||||
std::string temp = input;
|
||||
std::string::size_type start = 0;
|
||||
std::string::size_type i;
|
||||
while ((i = temp.find (delimiter)) != std::string::npos)
|
||||
while ((i = input.find (delimiter, start)) != std::string::npos)
|
||||
{
|
||||
std::string token = temp.substr (0, i);
|
||||
results.push_back (token);
|
||||
temp.erase (0, i + 1);
|
||||
results.push_back (input.substr (start, i - start));
|
||||
start = i + 1;
|
||||
}
|
||||
|
||||
if (temp.length ()) results.push_back (temp);
|
||||
results.push_back (input.substr (start, std::string::npos));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void split (std::vector<std::string>& results, const std::string& input, const std::string& delimiter)
|
||||
void split (
|
||||
std::vector<std::string>& results,
|
||||
const std::string& input,
|
||||
const std::string& delimiter)
|
||||
{
|
||||
std::string temp = input;
|
||||
std::string::size_type length = delimiter.length ();
|
||||
|
||||
std::string::size_type start = 0;
|
||||
std::string::size_type i;
|
||||
while ((i = temp.find (delimiter)) != std::string::npos)
|
||||
while ((i = input.find (delimiter, start)) != std::string::npos)
|
||||
{
|
||||
std::string token = temp.substr (0, i);
|
||||
results.push_back (token);
|
||||
temp.erase (0, i + delimiter.length ());
|
||||
results.push_back (input.substr (start, i - start));
|
||||
start = i + length;
|
||||
}
|
||||
|
||||
if (temp.length ()) results.push_back (temp);
|
||||
results.push_back (input.substr (start, std::string::npos));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
34
src/util.cpp
34
src/util.cpp
|
@ -331,3 +331,37 @@ std::string expandPath (const std::string& in)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// On Solaris no flock function exists.
|
||||
#ifdef SOLARIS
|
||||
int flock (int fd, int operation)
|
||||
{
|
||||
struct flock flock;
|
||||
|
||||
switch (operation & ~LOCK_NB)
|
||||
{
|
||||
case LOCK_SH:
|
||||
flock.l_type = F_RDLCK;
|
||||
break;
|
||||
|
||||
case LOCK_EX:
|
||||
flock.l_type = F_WRLCK;
|
||||
break;
|
||||
|
||||
case LOCK_UN:
|
||||
flock.l_type = F_UNLCK;
|
||||
break;
|
||||
|
||||
default:
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
flock.l_whence = 0;
|
||||
flock.l_start = 0;
|
||||
flock.l_len = 0;
|
||||
|
||||
return fcntl (fd, (operation & LOCK_NB) ? F_SETLK : F_SETLKW, &flock);
|
||||
}
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue