#define TIME_PRINT(elem,marker)\
if (elem)\
{\
- sprintf(buf, " %d%s%n", elem, marker, &tmp);\
- buf+=tmp;\
+ buf+=sprintf(buf, " %d%s", elem, marker);\
}\
-
+/* This implementation might look a little evil but it does work */
const char *helpmod_strtime(int total_seconds)
{
- static char buffer[64];
- char *buf = buffer;
+ static int buffer_index = 0;
+ static char buffers[3][64];
+
+ char *buf = buffers[buffer_index];
+ char *buffer = buf;
+
+ int years, months, days, hours, minutes, seconds;
- int years, months, days, hours, minutes, seconds, tmp;
+ buffer_index = (buffer_index+1) % 3;
/* trivial case */
if (!total_seconds)
if (total_seconds < 0)
{
- *buf = '-';
- buf++;
+ *buf = '-';
+ buf++;
total_seconds = -total_seconds;
}
total_seconds %= HDEF_h;
minutes = total_seconds / HDEF_m;
- total_seconds %= 60;
+ total_seconds %= HDEF_m;
seconds = total_seconds;
TIME_PRINT(minutes, "m");
TIME_PRINT(seconds, "s");
- return buffer+1;
+ if (*buffer != '-')
+ return buffer+1;
+ else
+ return buffer;
}
int helpmod_read_strtime(const char *str)
{
- int sum = 0;
- int tmp_sum;
- int tmp;
-
+ int sum = 0, tmp_sum, tmp;
while (*str)
{
const char lamechars[] = {(char)2, (char)3, (char)22, (char)31, (char)0};
if (strpbrk(line, lamechars) != NULL)
return 1;
- /*
- if (strchr(line, (char)2)) bold
- return 1;
- if (strchr(line, (char)3)) colour
- return 1;
- if (strchr(line, (char)22)) reverse
- return 1;
- if (strchr(line, (char)31)) underline
- return 1;
-*/
- return 0;
+ else
+ return 0;
}
int strislower(const char *str)
count++;
return count;
}
+
+float helpmod_percentage(int larger, int smaller)
+{
+ if (larger == 0)
+ return 0.0;
+
+ return 100.0 * ((float)smaller / (float)larger);
+}
+
+int helpmod_select(const char *str, const char **strs, int *enums, int count)
+{
+ int i;
+
+ if (count == 0)
+ return -1;
+
+ for (i = 0;i < count;i++)
+ if (!ci_strcmp(strs[i], str))
+ return enums[i];
+
+ return -1;
+}