43 return low+rand()%(high-low+1);
49 val = val < minval ? minval : val;
50 val = val > maxval ? maxval : val;
58 return val < minval ? minval : val;
65 return val > maxval ? maxval : val;
71 return val1>val2 ? val1 : val2;
77 return val1<val2 ? val1 : val2;
89 if ((c[i]==
'+') || (c[i]==
'-'))
91 while ((c[i] >=
'0') && (c[i] <=
'9')) {
97 while ((c[i] >=
'0') && (c[i] <=
'9')) {
102 if ((c[i]==
'e') || (c[i]==
'E')) {
105 if ((c[i]==
'+') || (c[i]==
'-'))
107 while ((c[i] >=
'0') && (c[i] <=
'9')) {
112 if ((c[i]==
'f') || (c[i]==
'F') || (c[i]==
'l') || (c[i]==
'L'))
115 if ((c[i]==
'\0') && isnum && wfe)
129 while( str[i] >=
'0' && str[i] <=
'9' )
138 while( str[i] >=
'0' && str[i] <=
'9' )
155 while( str[i] >=
'0' && str[i] <=
'9' )
172 while( str[i] >=
'0' && str[i] <=
'9' )
181 while( str[i] >=
'0' && str[i] <=
'9' )
193 return memmove (to, from, strlen (from) + 1);
197 char *
strins (
char *dest,
const char *ins)
199 strmove (dest + strlen (ins), dest);
200 memcpy (dest, ins, strlen (ins));
206 char *
strtrim(
char *str,
int (*left) (
int),
int (*right) (
int))
212 while (*p && left ((
int) *p))
221 char *p = strchr (str, 0);
223 while ((p - 1) - str && right ((
int) *(p - 1)))
235 return strtrim(str, isspace, NULL);
241 return strtrim (str, NULL, isspace);
245 int menu(
const char *menurow,
const int lo_sel,
const int hi_sel)
251 selection =
read_int(menurow, lo_sel, hi_sel);
257 int read_int(
const char *prompt,
const int lo_val,
const int hi_val)
259 int retval, input, val_ok;
266 printf(
"\n%s", prompt);
268 if (lo_val != hi_val)
269 printf(
"<%d-%d>+<Enter>: ", lo_val, hi_val);
272 retval = scanf(
"%d", &input);
276 if (lo_val != hi_val)
279 val_ok =
is_val_ok(input, lo_val, hi_val);
281 printf(
"Invalid selection - use <%d> to <%d>...!", lo_val, hi_val);
287 printf(
"Invalid input - integer only!");
292 }
while (retval == EOF || !val_ok);
298 int is_val_ok(
const int val,
const int lo_val,
const int hi_val)
300 return (val>=lo_val && val<=hi_val) ? TRUE : FALSE;
318 printf(
"%s", message);
319 printf(
" - Hit <Enter> to continue...");
326 int read_char(
const char *prompt,
const int lo_val,
const int hi_val,
int (*char_ok)(
int ch))
328 int retval, input, val_ok;
335 printf(
"\n%s", prompt);
337 if (lo_val != hi_val)
338 printf(
"<%c-%c>+<Enter>: ", lo_val, hi_val);
343 retval = char_ok(input);
347 if (lo_val != hi_val)
350 val_ok =
is_val_ok(input, lo_val, hi_val);
352 printf(
"Invalid selection - use <%c> to <%c>...!", lo_val, hi_val);
358 printf(
"Invalid character input!");
363 }
while (retval == FALSE || !val_ok);
374 while (ch != EOF && ch !=
'\n');