/* -------------------- */ /* example.c */ /* Simple example: */ /* - No function pointers. */ /* - Data type is already a pointer. */ /* use Algorithm::Loops qw( NestedLoops ); my $iter = NestedLoops( [ [ qw( apple banana coconut ) ], [ qw( asparagus brocoli cauliflower ) ], [ qw( beef chicken ) ], ], ); while (@list = $iter->()) { print(join(' ', @list), "\n"); } */ #include #include "nested_loops.h" void main() { /* This could be built dynamically. */ /* The args must remain accessible until done. */ /* NL's caller (i.e. us) handles cleanup of args. */ struct NestedLoop_Arg args[3]; char* fruits[3]; char* veggies[3]; char* meats[2]; fruits[0] = "apple"; fruits[1] = "banana"; fruits[2] = "coconut"; veggies[0] = "asparagus"; veggies[1] = "brocoli"; veggies[2] = "cauliflower"; meats[0] = "beef"; meats[1] = "chicken"; args[0].ptr_type = NestedLoop_PT_ARRAY; args[0].ptr.array.length = sizeof(fruits)/sizeof(fruits[0]); args[0].ptr.array.ptr = fruits; args[1].ptr_type = NestedLoop_PT_ARRAY; args[1].ptr.array.length = sizeof(veggies)/sizeof(veggies[0]); args[1].ptr.array.ptr = veggies; args[2].ptr_type = NestedLoop_PT_ARRAY; args[2].ptr.array.length = sizeof(meats)/sizeof(meats[0]); args[2].ptr.array.ptr = meats; { struct NestedLoop_Iter iter; NestedLoops_get_iter(&iter, sizeof(args)/sizeof(args[0]), args); while (NestedLoops_fetch(&iter)) { int i; /* Skip results without an element from each loop. */ if (iter.list.length != iter.num_loops) { continue; } for (i=0; i