]>
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 sprintf(buf, " %d%s%n", elem, marker, &tmp);\
81 /* This implementation might look a little evil but it does work */
82 const char *helpmod_strtime(int total_seconds
)
84 static int buffer_index
= 0;
85 static char buffers
[3][64];
87 char *buf
= buffers
[buffer_index
];
90 int years
, months
, days
, hours
, minutes
, seconds
, tmp
;
92 buffer_index
= (buffer_index
+1) % 3;
98 if (total_seconds
< 0)
102 total_seconds
= -total_seconds
;
105 years
= total_seconds
/ HDEF_y
;
106 total_seconds
%= HDEF_y
;
108 months
= total_seconds
/ HDEF_M
;
109 total_seconds
%= HDEF_M
;
111 days
= total_seconds
/ HDEF_d
;
112 total_seconds
%= HDEF_d
;
114 hours
= total_seconds
/ HDEF_h
;
115 total_seconds
%= HDEF_h
;
117 minutes
= total_seconds
/ HDEF_m
;
118 total_seconds
%= HDEF_m
;
120 seconds
= total_seconds
;
122 TIME_PRINT(years
, "y");
123 TIME_PRINT(months
, "M");
124 TIME_PRINT(days
, "d");
125 TIME_PRINT(hours
, "h");
126 TIME_PRINT(minutes
, "m");
127 TIME_PRINT(seconds
, "s");
135 int helpmod_read_strtime(const char *str
)
137 int sum
= 0, tmp_sum
, tmp
;
141 if (!sscanf(str
, "%d%n", &tmp_sum
, &tmp
))
167 default: /* includes '\0' */
173 if (tmp_sum
> 10 * HDEF_y
)
176 if (sum
> 10 * HDEF_y
)
182 int hword_count(const char *ptr
)
188 while (isspace(*ptr
) && *ptr
)
192 while (!isspace(*ptr
) && *ptr
)
199 int helpmod_is_lame_line(const char *line
)
201 const char lamechars
[] = {(char)2, (char)3, (char)22, (char)31, (char)0};
202 if (strpbrk(line
, lamechars
) != NULL
)
208 int strislower(const char *str
)
216 int strisupper(const char *str
)
224 int strisalpha(const char *str
)
232 int strnumcount(const char *str
)
241 float helpmod_percentage(int larger
, int smaller
)
246 return 100.0 * ((float)smaller
/ (float)larger
);
249 int helpmod_select(const char *str
, const char **strs
, int *enums
, int count
)
256 for (i
= 0;i
< count
;i
++)
257 if (!ci_strcmp(strs
[i
], str
))