1 /*-------------- Telecommunications & Signal Processing Lab ---------------
2                              McGill University
3 
4 Routine:
5   int STdecLrange (const char String[], long int *Lval1, long int *Lval2)
6 
7 Purpose:
8   Decode a range specification for long integer values
9 
10 Description:
11   This routine decodes a string specifying a range of long integer values.  The
12   range is specified in the form "Lv" or "Lv1:Lv2", for example "-23 : 45".
13   Optional white-space (as defined by isspace) can surround the values.  For
14   the case of a single value Lv, this is equivalent to the range "Lv:Lv".  If
15   an error is encountered, neither output value is set.
16 
17 Parameters:
18   <-  int STdecIrange
19       Error status, 0 for no error, 1 for error
20    -> const char String[]
21       Input string
22   <-  long int *Lval1
23       First value
24   <-  long int *Lval2
25       Second value
26 
27 Author / revision:
28   P. Kabal  Copyright (C) 2003
29   $Revision: 1.7 $  $Date: 2003/05/09 03:02:44 $
30 
31 -------------------------------------------------------------------------*/
32 
33 #include <libtsp.h>
34 #include <libtsp/nucleus.h>
35 #include <libtsp/STmsg.h>
36 
37 #define MAXC	23
38 #define DP_EMPTY		0
39 #define DP_LVAL			1
40 #define DP_DELIM		2
41 #define DP_RVAL			4
42 
43 
44 int
STdecLrange(const char String[],long int * Lval1,long int * Lval2)45 STdecLrange (const char String[], long int *Lval1, long int *Lval2)
46 
47 {
48   int status;
49   long int lval1, lval2;
50 
51   /* Decode the range values */
52   status = STdecPair (String, ":", 'L', (void *) (&lval1), (void *) (&lval2));
53 
54   if (status == DP_LVAL) {
55     *Lval1 = lval1;
56     *Lval2 = lval1;
57   }
58   else if (status == (DP_LVAL + DP_DELIM + DP_RVAL)) {
59     *Lval1 = lval1;
60     *Lval2 = lval2;
61   }
62   else if (status >= 0) {
63     UTwarn ("STdecLrange - %s: \"%s\"", STM_DataErr, STstrDots (String, MAXC));
64     status = -1;
65   }
66 
67   return (status < 0);
68 }
69