Back to index

radiance  4R0+20100331
setscan.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: setscan.c,v 2.4 2004/03/26 23:34:23 schorsch Exp $";
00003 #endif
00004 /*
00005  * Convert angle ranges of the form a-b:s,c to discrete values
00006  */
00007 
00008 #include <stdlib.h>
00009 #include <ctype.h>
00010 
00011 #include "setscan.h"
00012 
00013 int
00014 setscan(                    /* set up scan according to arg */
00015 register ANGLE  *ang,
00016 register char  *arg
00017 )
00018 {
00019        int  state = ',';
00020        int  start, finish, step;
00021 
00022        while (state) {
00023               switch (state) {
00024               case ',':
00025                      start = atoi(arg);
00026                      finish = start;
00027                      step = 1;
00028                      break;
00029               case '-':
00030                      finish = atoi(arg);
00031                      if (finish < start)
00032                             return(-1);
00033                      break;
00034               case ':':
00035                      step = atoi(arg);
00036                      break;
00037               default:
00038                      return(-1);
00039               }
00040               if (!isdigit(*arg))
00041                      return(-1);
00042               do
00043                      arg++;
00044               while (isdigit(*arg));
00045               state = *arg++;
00046               if (!state || state == ',')
00047                      while (start <= finish) {
00048                             *ang++ = start;
00049                             start += step;
00050                      }
00051        }
00052        *ang = AEND;
00053        return(0);
00054 }