/* enum: enumerate a range of digits or symbols. * * for use with a shell programming environment. * * examples: * % foreach i (`enum 1 9`) * % foreach i (`enum 00 99`) # future * * Author: Dave Bakken * * Wish list for extensions: * 1) make it work for letter loops, too (with no real error checking) * $ for i in `enum a z` # Bourne shell syntax * % foreach i (`enum A Z`) # csh syntax * * 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 #include "foo.h" /* needed for external declaration of foo() */ #include "bar.h" /* needed for external declaration of bar() */ /* stupid main() comment */ 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); } foo(); bar(); /* simple logic, not bullet proof here... */ /* assumes parameters are digits, not letters, and are well-formed (no errors) * It also assume that lo and hi have the same number of digits on the command line*/ 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 of the output */ }