Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: da1edaebdb
Fetching contributors…

Cannot retrieve contributors at this time

file 49 lines (39 sloc) 0.546 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49


#include "cf_it.h"

typedef struct st_cf_it {
  BASE_CF;
  unsigned n;
  int (*fun)(unsigned);
} *CFI;
#define cfi ((CFI)cf)

static int next_it(CF);

CF
new_it(int (*f)(unsigned))
{
  CFI cf = (CFI) new_cf(sizeof(struct st_cf_it));
  if (cf == 0) return 0;

  cf->n = 0;
  cf->fun = f;
  cf->next = next_it;

  return (CF)cf;
}

static int
next_it(CF cf)
{
  return cfi->fun(cfi->n++);
}

static int
ef(unsigned n)
{
  switch (n%3) {
  case 0:
  case 2:
    return 1;
  case 1:
    return 2*(n/3);
  }
}

CF
e(void)
{
  return new_it(ef);
}
Something went wrong with that request. Please try again.