1/*
2 * This program generates data for testing file locking
3 */
4
5#include <stdio.h>
6#include <stdlib.h>
7#include <unistd.h>
8
9int main(int argc, char **argv)
10{
11	int i, j, k, nlines, nchars, ctype;
12	char c, buf[BUFSIZ];
13	FILE *fp;
14
15	if (argc != 5) {
16		printf
17		    ("usage: <nfs_flock_dgen> <file> <char/line> <lines> <ctype>\n");
18		exit(2);
19	}
20
21	fp = fopen(argv[1], "w");
22
23	nchars = atoi(argv[2]);
24	if (nchars > BUFSIZ) {
25		printf("Exceeded the maximum limit of the buffer (%d)\n",
26		       BUFSIZ);
27		exit(3);
28	}
29	nlines = atoi(argv[3]);
30	ctype = atoi(argv[4]);
31
32	k = 0;
33	for (i = 1; i <= nlines; i++) {
34
35		if (ctype)
36			c = ((i % 2) ? '1' : '0');
37		else
38			c = 'A' + k;
39
40		for (j = 0; j < nchars; j++)
41
42			buf[j] = c;
43
44		fprintf(fp, "%s\n", buf);
45
46		if (!ctype) {
47			if (i != 1 && i % 26 == 0)
48				k = 0;
49			else
50				k++;
51		}
52
53	}
54
55	fclose(fp);
56	return (0);
57}
58