/*
 * Generate csv test file
 */

#define _CRT_SECURE_NO_WARNINGS
#define _CRT_DISABLE_PERFCRIT_LOCKS

#include <stdlib.h>
#include <stdio.h>

#define LINES (100*1000)
#define COLS 45
#define LEN 20

void usage()
{
    printf("gen_csv [<lines>] [<length>] [columns] [use_rand_flag]\n");
    exit(1);
}

int main(int argc, char **argv)
{
    int lines = LINES, cols = COLS, len = LEN;
    int i, j, k, r, use_rand=1;

    if (argc > 1)
        lines = strtol(argv[1], NULL, 10);

    if (argc > 2)
        len = strtol(argv[2], NULL, 10);

    if (argc > 3)
        cols = strtol(argv[3], NULL, 10);

    if (argc > 4)
        use_rand = strtol(argv[4], NULL, 10);

    if (lines < 1 || len < 1 || cols < 1)
        usage();

    if (!freopen("list.txt", "wb", stdout))
        return -1;

    for (i = 0; i < lines; i++) {

        for (j = 0; j < cols; j++) {

            for (k = 0; k < len-1; k++)
                putchar('x');

            if (use_rand)
                r = rand() % 10;
            else
                r = i*j;

            printf("%d;", r);

            if (j == cols - 1)
                putchar('\n');
        }
    }

    return ferror(stdout)? 1 : 0;
}
