1 /*-------------- Telecommunications & Signal Processing Lab ---------------
2 McGill University
3
4 Routine:
5 int STdecIfrac (const char String[], int *Ival1, int *Ival2)
6
7 Purpose:
8 Decode a ratio specification of two integer values
9
10 Description:
11 This routine decodes a string specifying a ratio of integer values. The
12 ratio is specified in the form "V" or "V1/V2", for example "-23 / 45".
13 Optional white-space (as defined by isspace) can surround the values. For
14 the case of a single value V, this is equivalent to the ratio "V/1". If an
15 error is encountered, neither output value is set.
16
17 Parameters:
18 <- int STdecIfrac
19 Error status, 0 for no error, 1 for error
20 -> const char String[]
21 Input string
22 <- int *Ival1
23 First value
24 <- int *Ival2
25 Second value
26
27 Author / revision:
28 P. Kabal Copyright (C) 2003
29 $Revision: 1.8 $ $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
STdecIfrac(const char String[],int * Ival1,int * Ival2)45 STdecIfrac (const char String[], int *Ival1, int *Ival2)
46
47 {
48 int status;
49 int ival1, ival2;
50
51 /* Decode the ratio values */
52 status = STdecPair (String, "/", 'I', (void *) (&ival1), (void *) (&ival2));
53
54 if (status == DP_LVAL) {
55 *Ival1 = ival1;
56 *Ival2 = 1;
57 }
58 else if (status == (DP_LVAL + DP_DELIM + DP_RVAL)) {
59 *Ival1 = ival1;
60 *Ival2 = ival2;
61 }
62 else if (status >= 0) {
63 UTwarn ("STdecIfrac - %s: \"%s\"", STM_DataErr, STstrDots (String, MAXC));
64 status = -1;
65 }
66
67 return (status < 0);
68 }
69