]>
jfr.im git - irc/quakenet/newserv.git/blob - helpmod2/hgen.c
9 int ci_strcmp(const char *str1
, const char *str2
)
13 if (tolower(*str1
) != tolower(*str2
))
14 return tolower(*str1
) - tolower(*str2
);
18 return tolower(*str1
) - tolower(*str2
);
21 /* can't even remember what this does, but it works */
22 static char *rstrchr(const char * str
, char chr
)
25 if (tolower(*str
) == tolower(chr
))
32 int strregexp(const char * str
, const char * pattern
)
36 while (*pattern
&& *str
)
40 else if (*pattern
== '*')
42 while (*(++pattern
) == '*');
48 if (strregexp(str
++, pattern
))
53 while ((str
= rstrchr(str
, *pattern
)))
54 if (strregexp(str
++, pattern
))
59 else if (tolower(*pattern
) != tolower(*str
))
65 while(*pattern
== '*')
68 if (!*pattern
&& !*str
)
74 #define TIME_PRINT(elem,marker)\
77 buf+=sprintf(buf, " %d%s", elem, marker);\
80 /* This implementation might look a little evil but it does work */
81 const char *helpmod_strtime(int total_seconds
)
83 static int buffer_index
= 0;
84 static char buffers
[3][64];
86 char *buf
= buffers
[buffer_index
];
89 int years
, months
, days
, hours
, minutes
, seconds
;
91 buffer_index
= (buffer_index
+1) % 3;
97 if (total_seconds
< 0)
101 total_seconds
= -total_seconds
;
104 years
= total_seconds
/ HDEF_y
;
105 total_seconds
%= HDEF_y
;
107 months
= total_seconds
/ HDEF_M
;
108 total_seconds
%= HDEF_M
;
110 days
= total_seconds
/ HDEF_d
;
111 total_seconds
%= HDEF_d
;
113 hours
= total_seconds
/ HDEF_h
;
114 total_seconds
%= HDEF_h
;
116 minutes
= total_seconds
/ HDEF_m
;
117 total_seconds
%= HDEF_m
;
119 seconds
= total_seconds
;
121 TIME_PRINT(years
, "y");
122 TIME_PRINT(months
, "M");
123 TIME_PRINT(days
, "d");
124 TIME_PRINT(hours
, "h");
125 TIME_PRINT(minutes
, "m");
126 TIME_PRINT(seconds
, "s");
134 int helpmod_read_strtime(const char *str
)
136 int sum
= 0, tmp_sum
, tmp
;
140 if (!sscanf(str
, "%d%n", &tmp_sum
, &tmp
))
166 default: /* includes '\0' */
172 if (tmp_sum
> 10 * HDEF_y
)
175 if (sum
> 10 * HDEF_y
)
181 int hword_count(const char *ptr
)
187 while (isspace(*ptr
) && *ptr
)
191 while (!isspace(*ptr
) && *ptr
)
198 int helpmod_is_lame_line(const char *line
)
200 const char lamechars
[] = {(char)2, (char)3, (char)22, (char)31, (char)0};
201 if (strpbrk(line
, lamechars
) != NULL
)
207 int strislower(const char *str
)
215 int strisupper(const char *str
)
223 int strisalpha(const char *str
)
231 int strnumcount(const char *str
)
240 float helpmod_percentage(int larger
, int smaller
)
245 return 100.0 * ((float)smaller
/ (float)larger
);
248 int helpmod_select(const char *str
, const char **strs
, int *enums
, int count
)
255 for (i
= 0;i
< count
;i
++)
256 if (!ci_strcmp(strs
[i
], str
))