clplaner.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Fri, 19 Nov 2010 16:43:20 +0100
changeset 161 36f763c8ab16
parent 78 e87e0fe4a7db
permissions -rw-r--r--
spell checking: 'cannot set the limit' sounds better... committer: Markus Bröker <mbroeker@largo.homelinux.org>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
75
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     1
/**
77
49e0babccb23 HEADER TAGS
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 75
diff changeset
     2
 * clplaner.c
75
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     3
 * Copyright (C) 2008 Markus Broeker
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     4
 */
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     5
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     6
#include <stdio.h>
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     7
#include <stdlib.h>
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     8
#include <string.h>
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     9
#include <time.h>
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    10
#include <limits.h>
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    11
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    12
#define MAXLOOP 25
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    13
#define MAXLINE 80
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    14
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    15
#ifndef MAXTEAM
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    16
#define MAXTEAM 32
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    17
#endif
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    18
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    19
#define getrandom(max) (1+(int)((float)(max)*rand()/RAND_MAX))
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    20
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    21
void swap (int *v, int i, int j)
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    22
{
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    23
    int temp;
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    24
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    25
    if (i == j)
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    26
        return;
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    27
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    28
    temp = v[i];
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    29
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    30
    v[i] = v[j];
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    31
    v[j] = temp;
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    32
}
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    33
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    34
void cleanup (char **first, char **second)
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    35
{
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    36
    int i;
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    37
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    38
    i = 0;
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    39
    while (first[i] != NULL)
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    40
        free (first[i++]);
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    41
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    42
    i = 0;
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    43
    while (second[i] != NULL)
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    44
        free (second[i++]);
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    45
}
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    46
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    47
unsigned int time_seed ()
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    48
{
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    49
    time_t now = time (NULL);
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    50
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    51
    unsigned char *p = (unsigned char *)&now;
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    52
    unsigned int seed = 0;
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    53
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    54
    size_t i;
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    55
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    56
    for (i = 0; i < sizeof (now); i++)
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    57
        seed = seed * (UCHAR_MAX + 2U) + p[i];
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    58
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    59
    return seed;
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    60
}
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    61
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    62
int getTeams (FILE * f, char **first, int *first_idx, char **second, int *second_idx)
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    63
{
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    64
    int i;
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    65
    char buffer[MAXLINE + 1];
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    66
    char *ptr;
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    67
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    68
    i = 0;
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    69
    while ((i < MAXTEAM) && fgets (buffer, MAXLINE, f) != NULL) {
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    70
        if ((first[i] = malloc (MAXLINE + 1)) == NULL) {
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    71
            perror ("malloc");
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    72
            break;
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    73
        }
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    74
        if ((ptr = strchr (buffer, '\n')))
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    75
            *ptr = '\0';
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    76
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    77
        strncpy (first[i], buffer, MAXLINE);
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    78
        first_idx[i] = i;
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    79
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    80
        if (fgets (buffer, MAXLINE, f) == NULL) {
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    81
            printf ("You need 2, 4, 6, ..., or %d teams in your file\n", 2 * MAXTEAM);
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    82
            second[i] = first[i + 1] = NULL;
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    83
            cleanup (first, second);
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    84
            fclose (f);
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    85
            exit (EXIT_FAILURE);
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    86
        }
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    87
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    88
        if ((second[i] = malloc (MAXLINE + 1)) == NULL) {
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    89
            perror ("malloc");
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    90
            break;
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    91
        }
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    92
        if ((ptr = strchr (buffer, '\n')))
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    93
            *ptr = '\0';
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    94
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    95
        strncpy (second[i], buffer, MAXLINE);
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    96
        second_idx[i] = i;
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    97
        i++;
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    98
    }
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    99
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   100
    first[i] = second[i] = NULL;
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   101
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   102
    return i;
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   103
}
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   104
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   105
void shakeTeamIdx (int *first_idx, int *second_idx, int teams)
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   106
{
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   107
    int i, j, k;
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   108
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   109
    /*
78
e87e0fe4a7db clplaner: Avoid a segfault on Wed May 27 20:00 CET 2009
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
   110
     * Who wins the Title?
e87e0fe4a7db clplaner: Avoid a segfault on Wed May 27 20:00 CET 2009
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
   111
     */
e87e0fe4a7db clplaner: Avoid a segfault on Wed May 27 20:00 CET 2009
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
   112
    if (teams == 1)
e87e0fe4a7db clplaner: Avoid a segfault on Wed May 27 20:00 CET 2009
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
   113
        return;
e87e0fe4a7db clplaner: Avoid a segfault on Wed May 27 20:00 CET 2009
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
   114
e87e0fe4a7db clplaner: Avoid a segfault on Wed May 27 20:00 CET 2009
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 77
diff changeset
   115
    /*
75
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   116
     * swap the index MAXLOOP times...
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   117
     */
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   118
    for (i = 0; i < MAXLOOP; i++) {
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   119
        for (j = 0; j < teams; j++) {
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   120
            k = getrandom (teams - 1);
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   121
            swap (second_idx, j, k);
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   122
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   123
            k = getrandom (teams - 1);
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   124
            swap (first_idx, j, k);
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   125
        }
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   126
    }
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   127
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   128
    /*
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   129
     * avoid group clashes
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   130
     */
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   131
    for (i = 0; i < teams - 1; i++) {
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   132
        if (first_idx[i] == second_idx[i])
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   133
            swap (first_idx, i, i + 1);
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   134
    }
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   135
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   136
    if (first_idx[i] == second_idx[i])
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   137
        swap (first_idx, i, i - 1);
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   138
}
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   139
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   140
int main (int argc, char **argv)
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   141
{
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   142
    FILE *f;
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   143
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   144
    char *first[MAXTEAM + 1];
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   145
    char *second[MAXTEAM + 1];
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   146
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   147
    int first_idx[MAXTEAM];
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   148
    int second_idx[MAXTEAM];
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   149
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   150
    int i, teams;
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   151
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   152
    if (argc != 2) {
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   153
        printf ("Usage: %s FILE\n\n", argv[0]);
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   154
        printf ("One Team per line, seperated by newline, n=2, 4, ..., or %d\n", 2 * MAXTEAM);
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   155
        printf ("Team n is the Groupwinner, n+1 is the Runners Up\n");
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   156
        printf ("Report bugs to mbroeker@largo.homelinux.org\n");
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   157
        return EXIT_FAILURE;
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   158
    }
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   159
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   160
    if ((f = fopen (argv[1], "r")) == NULL) {
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   161
        perror ("fopen");
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   162
        return EXIT_FAILURE;
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   163
    }
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   164
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   165
    srand (time_seed ());
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   166
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   167
    teams = getTeams (f, first, first_idx, second, second_idx);
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   168
    shakeTeamIdx (first_idx, second_idx, teams);
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   169
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   170
    for (i = 0; i < teams; i++)
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   171
        printf ("%30s vs %s\n", second[second_idx[i]], first[first_idx[i]]);
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   172
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   173
    cleanup (first, second);
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   174
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   175
    if (f != NULL)
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   176
        fclose (f);
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   177
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   178
    return EXIT_SUCCESS;
a2c32869d4d5 clplaner added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
   179
}