/* -------------------- */ /* example2.c */ /* Example using a non-pointer type. */ /* use Algorithm::Loops qw( NestedLoops ); my $iter = NestedLoops( [ [ qw( a b c ) ], [ qw( ! @ # ) ], [ qw( 1 2 3 ) ], ], ); 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* chars = "abc!@#123"; args[0].ptr_type = NestedLoop_PT_ARRAY; args[0].ptr.array.length = 3; NestedLoops_to_ptr_array(&(args[0].ptr.array.ptr), chars+0*3, 3, sizeof(char)); args[1].ptr_type = NestedLoop_PT_ARRAY; args[1].ptr.array.length = 3; NestedLoops_to_ptr_array(&(args[1].ptr.array.ptr), chars+1*3, 3, sizeof(char)); args[2].ptr_type = NestedLoop_PT_ARRAY; args[2].ptr.array.length = 3; NestedLoops_to_ptr_array(&(args[2].ptr.array.ptr), chars+2*3, 3, sizeof(char)); { 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