1/* Generate window size/position coordinates for -geometry switches */
2
3/*
4 * Copyright (C) 2003-2006 IBM
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 * 02111-1307, USA.
20 */
21
22#include <unistd.h>
23#include <limits.h>
24#include <fcntl.h>
25#include <stdio.h>
26#include <stdlib.h>
27
28int seed_random(void)
29{
30	int fp;
31	long seed;
32
33	fp = open("/dev/urandom", O_RDONLY);
34	if (fp < 0) {
35		perror("/dev/urandom");
36		return 0;
37	}
38
39	if (read(fp, &seed, sizeof(seed)) != sizeof(seed)) {
40		perror("read random seed");
41		return 0;
42	}
43
44	close(fp);
45	srand(seed);
46
47	return 1;
48}
49
50int main(int argc, char *argv[])
51{
52	unsigned long xmax, ymax;
53	unsigned long x, y;
54
55	if (argc < 3) {
56		fprintf(stderr, "Usage: %s xmax ymax\n", argv[0]);
57		return 2;
58	}
59
60	xmax = atoi(argv[1]);
61	ymax = atoi(argv[2]);
62
63	if (!seed_random()) {
64		return 1;
65	}
66
67	x = 1 + (unsigned long)((float)xmax * (rand() / (RAND_MAX + 1.0f)));
68	y = 1 + (unsigned long)((float)ymax * (rand() / (RAND_MAX + 1.0f)));
69
70	printf("+%lu+%lu\n", x, y);
71
72	return 0;
73}
74