mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-20 15:41:30 -07:00
Files

right from scratch without the slightest reference to any dialog templates (meaning that we get to figure out the layout and _then_ choose the window size). I'm rather pleased with that. Also introduced free_cfg(), which is why this checkin touched gtk.c as well. [originally from svn r4184]
36 lines
551 B
C
36 lines
551 B
C
/*
|
|
* misc.c: Miscellaneous helpful functions.
|
|
*/
|
|
|
|
#include <assert.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "puzzles.h"
|
|
|
|
int rand_upto(int limit)
|
|
{
|
|
unsigned long divisor = RAND_MAX / (unsigned)limit;
|
|
unsigned long max = divisor * (unsigned)limit;
|
|
unsigned long n;
|
|
|
|
assert(limit > 0);
|
|
|
|
do {
|
|
n = rand();
|
|
} while (n >= max);
|
|
|
|
n /= divisor;
|
|
|
|
return (int)n;
|
|
}
|
|
|
|
void free_cfg(config_item *cfg)
|
|
{
|
|
config_item *i;
|
|
|
|
for (i = cfg; i->type != C_END; i++)
|
|
if (i->type == C_STRING)
|
|
sfree(i->sval);
|
|
sfree(cfg);
|
|
}
|