/* enum: enumerate a range of digits or symbols. * * for use with a shell programming environment. * * examples: * % foreach i (`enum 1 9`) * * author: Dave Bekken * * Wish list for extensions: * 1) make it work for letter loops, too (with no real error checking) * $ for i in `enum a z` * % foreach i (`enum A Z`) * 2) make integer params be auto-formatted to the right number of * digits: `enum 1 99` generates 01 02 03 04 ... * 3) same as #2, but for letters. Harder... * `enum a zzz` generates __a __b .... zzy zzz * 4) catch more errors, e.g. `enum 5 3` complains rather than * generating nothing. */ #include #include "foo.h" #include "bar.h" main(argc,argv) int argc; char *argv[]; { int lo, hi, i; if (argc != 3) { fprintf(stderr,"enum: bad # of parameters\n\tusage: enum low high\n"); exit(1); } /* simple logic, not bullet proof here... */ /* assumes parameters are digits, not letters */ lo=atoi(argv[1]); hi=atoi(argv[2]); for (i=lo; i <= hi; i++) { printf("%d", i); if (i < hi) printf(" "); /* put space between enumerated values */ } /* note that we do NOT put a carriage return at the end */ }