*
* Copyright (c) 1998
* Andrea Cocito (Nemesi).
+ * Copyright (c)
+ * Run (carlo@runaway.xs4all.nl) 1996
+ *
+ * mmatch/match/collapse
+ *
+ * Copyright (c)
+ * Run (carlo@runaway.xs4all.nl) 1996
*
* License follows:
*
register const char* u2 = s2;
while(ToLower(*u1) == ToLower(*u2)) {
- if(*u1++)
+ if(!*u1++)
return 0;
u2++;
return 0;
while(ToLower(*u1) == ToLower(*u2)) {
- if(*u1++ || !remaining--)
+ if(!*u1++ || !remaining--)
return 0;
u2++;
* Converts a long into a "p.q.r.s" IP address
*/
-const char *IPtostr(unsigned long IP) {
+const char *IPlongtostr(unsigned long IP) {
static char buf[16];
sprintf(buf,"%lu.%lu.%lu.%lu",(IP>>24),(IP>>16)&255,(IP>>8)&255,IP&255);
/*
* longtoduration:
* Converts a specified number of seconds into a duration string.
- * format: 0 for the "/stats u" compatible output, 1 for more human-friendly output.
+ * format: 0 for the "/stats u" compatible output, 1 for more
+ * human-friendly output (that is sometimes format 0), and
+ * 2 for a different human-friendly output.
*/
const char *longtoduration(unsigned long interval, int format) {
int days,hours,minutes,seconds;
- static char outstring[50];
+ static char outstring[100];
int pos=0;
seconds=interval%60;
hours=(interval%(3600*24))/3600;
days=interval/(3600*24);
- if (days>0 || format==0) {
- sprintf(outstring,"%d day%s, %02d:%02d:%02d",
- days,(days==1)?"":"s",hours,minutes,seconds);
+ if(format<2) {
+ if (format==0 || (days>0 && (hours||minutes||seconds))) {
+ sprintf(outstring,"%d day%s, %02d:%02d:%02d",
+ days,(days==1)?"":"s",hours,minutes,seconds);
+ } else if (days>0) {
+ sprintf(outstring, "%d day%s",days,(days==1)?"":"s");
+ } else {
+ if (hours>0) {
+ pos += sprintf(outstring+pos,"%d hour%s ",hours,hours==1?"":"s");
+ }
+ if (minutes>0 || (hours>0 && seconds>0)) {
+ pos += sprintf(outstring+pos,"%d minute%s ",minutes,minutes==1?"":"s");
+ }
+ if (seconds>0 || !interval) {
+ sprintf(outstring+pos,"%d second%s ",seconds,seconds==1?"":"s");
+ }
+ }
} else {
- if (hours>0) {
- pos += sprintf(outstring+pos,"%d hour%s ",hours,hours==1?"":"s");
+ if (days>0) {
+ pos += sprintf(outstring+pos, "%dd ",days);
+ }
+ if (hours>0 || (days>0 && (minutes>0 || seconds>0))) {
+ pos += sprintf(outstring+pos, "%dh ",hours);
}
- if (minutes>0 || (hours>0 && seconds>0)) {
- pos += sprintf(outstring+pos,"%d minute%s ",minutes,minutes==1?"":"s");
+ if (minutes>0 || ((days>0 || hours>0) && seconds>0)) {
+ pos += sprintf(outstring+pos, "%dm ",minutes);
}
- if (seconds>0) {
- pos += sprintf(outstring+pos,"%d second%s ",seconds,seconds==1?"":"s");
+ if (seconds>0 || !interval) {
+ sprintf(outstring+pos, "%ds ",seconds);
}
}
return total;
}
-/* @GPL
+/*
* mmatch()
*
* Written by Run (carlo@runaway.xs4all.nl), 25-10-96
* a '?' in `new_mask' does not match a '\?' in `old_mask'.
* And ofcourse... a '*' in `new_mask' does not match a '\*' in `old_mask'...
* And last but not least, '\?' and '\*' in `new_mask' now become one character.
+ *
+ * Kindly BSD licensed by Run for Newserv.
*/
int mmatch(const char *old_mask, const char *new_mask)