Initial snark14m import
[snark14.git] / src / snark / getint.cpp
1 /*
2  ***********************************************************
3  $SNARK_Header: S N A R K  1 4 - A PICTURE RECONSTRUCTION PROGRAM $
4  $HeadURL: svn://dig.cs.gc.cuny.edu/snark/trunk/src/snark/getint.cpp $
5  $LastChangedRevision: 80 $
6  $Date: 2014-07-01 21:01:54 -0400 (Tue, 01 Jul 2014) $
7  $Author: agulati $
8  ***********************************************************
9
10  GETINT SCANS THE INPUT AREA FOR THE NEXT NUMBER AND RETURNS
11  THE INTERNAL INTEGER REPRESENTATION OF THE NUMBER.
12  IF THE INPUT AREA DOES NOT CONTAIN A NUMBER, ZERO IS
13  RETURNED AND EOL IS SET TO .TRUE.
14  */
15
16 #include <cstdlib>
17 #include <cstdio>
18 #include <cctype>
19
20 #include "blkdta.h"
21 #include "uiod.h"
22
23 #include "chtoin.h"
24
25 #include "inputfile.h" 
26
27 INTEGER InputFile_class::getint(BOOLEAN NewLine, BOOLEAN* eol)
28 {
29
30         INTEGER sign;
31         CHAR nextch;
32         INTEGER intvalue;
33         //BOOLEAN flag;
34         //bug 274 (there is no check for number of digits in the number,
35         //this should be <=9, fixed by Joanna Klukowska
36         INTEGER numOfDigits = 1; //bug 274, RD
37
38         int i;
39
40         *eol = FALSE;
41         if (NewLine)
42         {
43                 getnxt(FALSE);
44         }
45
46         intvalue = 0;
47
48         // FIND START OF NUMBER (FIRST DIGIT) AND SIGN
49
50         sign = 1;
51
52         for (;;)
53         {
54                 ptr++;
55                 if (ptr > DATASIZ)
56                 { // NO NUMBER FOUND  // bug 190 - swr - 12/09/05
57                         *eol = TRUE;
58                         return 0;
59                 }
60                 nextch = data[ptr];
61                 if (isdigit(nextch))
62                         break;
63                 if (nextch == '-')
64                 {
65                         sign = -1;
66                 }
67                 else
68                 {
69                         sign = 1;
70                 }
71         }
72
73         // PROCESS INTEGER PART
74
75         do
76         {
77                 intvalue = 10 * intvalue + (chtoin(nextch));
78                 ptr++;
79                 nextch = data[ptr];
80                 numOfDigits++;   //bug 274, jklukowska
81         } while (isdigit(nextch) && numOfDigits <= 9);  //bug 274, jklukowska
82
83         if (nextch != ' ')
84         {
85                 // ERROR - ILLEGAL REPRESENTATION OF NUMBER
86
87                 for (i = 0; i < DATASIZ; i++)
88                 {     // bug 190 - swr - 12/09/05
89                         data[i] = ' ';
90                 }
91
92                 data[ptr] = '*';
93                 fprintf(output,
94                                 "\n **** illegal integer modifier encountered\n **** program aborted\n");
95                 exit(-1);
96         }
97         return sign * intvalue;
98 }