view loto6.c @ 8:37a10fd62ea9

add programs for prototype generation checking
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Sat, 21 Feb 2015 21:19:46 +0900
parents 35d6eabeadb0
children 586096c45873
line wrap: on
line source

/*
 *  Nov 10, 2009
 *  created by gongo.
 *
 *  Nov 10, 2009
 *  modified by kent.
 */

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

#ifdef CLANG // for clang/LLVM
#define _CbC_return __return
#define _CbC_environment __environment
#endif

__code (*ret)(int, void*);
void *env;


__code
print(int *numbers)
{
  printf("%d-%d-%d-%d-%d-%d\n", numbers[0], numbers[1], numbers[2], numbers[3], numbers[4], numbers[5]);
  free(numbers);
  goto ret(0, env);
}

__code
take(int *array, int size, int length)
{
  int *taked = (int*)malloc(sizeof(int)*length);

  memcpy(taked, array, sizeof(int)*length);
  free(array);

  goto print(taked);
}

__code
shuffle(int *array, int size, int idx)
{
  int j = random() % size;
  int tmp = array[idx];
  array[idx] = array[j];
  array[j] = tmp;

  if (++idx < size) {
    goto shuffle(array, size, idx);
  } else {
    goto take(array, size, 6);
  }
}

__code
range_loop(int *array, int idx, int from, int to, int step, int size)
{
  array[idx] = from;

  if (from+step > to) {
    goto shuffle(array, size, 0);
  } else {
    goto range_loop(array, idx+1, from+step, to, step, size);
  }
}

__code
range(int from, int to, int step)
{
  int size = (to-from+1)/step;
  int *array = (int*)malloc(sizeof(int)*size);

  goto range_loop(array, 0, from, to, step, size);
}

int
main()
{
  srand(time(NULL));
  ret = _CbC_return;
  env = _CbC_environment;

  goto range(1, 43, 1);
}