[brlcad-commits] SF.net SVN: brlcad: [31457] brlcad/trunk/src/util/loop.c
Open Source Solid Modeling CAD
Brought to you by:
brlcad
From: <hom...@us...> - 2008-06-18 14:03:11
|
Revision: 31457 http://brlcad.svn.sourceforge.net/brlcad/?rev=31457&view=rev Author: homovulgaris Date: 2008-06-18 07:03:03 -0700 (Wed, 18 Jun 2008) Log Message: ----------- added -c argument to loop.c so as to support characters Modified Paths: -------------- brlcad/trunk/src/util/loop.c Modified: brlcad/trunk/src/util/loop.c =================================================================== --- brlcad/trunk/src/util/loop.c 2008-06-18 14:02:26 UTC (rev 31456) +++ brlcad/trunk/src/util/loop.c 2008-06-18 14:03:03 UTC (rev 31457) @@ -19,7 +19,7 @@ */ /** @file loop.c * - * Simple program to output integers or floats between + * Simple program to output integers or floats or chars between * "start" and "finish", inclusive. Default is an increment * of +1 if start < finish or -1 if start > finish. User may * specify an alternate increment. Also, user may left-pad @@ -45,6 +45,7 @@ #define INTEGER 0 #define REAL 1 +#define CHAR 2 int main(int argc, char **argv) @@ -57,10 +58,18 @@ register double d; register double dstart, dfinish, dincr; - if (argc < 3 || argc > 4) { - bu_exit(9, "Usage: loop start finish [incr]\n"); + register char c; + register char cstart, cfinish; + register int cincr; + + if (argc < 3 || argc > 5) { + bu_exit(9, "Usage: loop [-c|-n] start finish [incr] \n -n is the default option\n"); } + /* Check if -c is present in comandline argument*/ + + if(argv[1][0] == '-' && argv[1][1]) status = CHAR; + /* determine if any arguments are real */ for (i = 1; i < argc; i++) { if (atof(argv[i]) != ((double)atoi(argv[i]))) { @@ -88,7 +97,7 @@ else for (d = dstart; d >= dfinish; d += dincr) printf("%g\n", d); - } else { + } else if (status == INTEGER) { /* print out integer output */ char *cp; char fmt_string[50]; @@ -157,6 +166,24 @@ else for (i = start; i >= finish; i += incr) printf(fmt_string, i); + } else { + /* print out integer output */ + cstart = argv[2][0]; + cfinish = argv[3][0]; + + if (argc == 5) cincr = atoi(argv[4]); + else { + if (cstart > cfinish) + cincr = -1; + else + cincr = 1; + } + if (cincr >= 0) + for (c=cstart; c <= cfinish; c += cincr) + printf("%c\n",c); + else + for (c=cstart; c >= cfinish; c +=cincr) + printf("%c\n",c); } return 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |