Initial snark14m import
[snark14.git] / src / snark / getnxt.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/getnxt.cpp $
5  $LastChangedRevision: 80 $
6  $Date: 2014-07-01 21:01:54 -0400 (Tue, 01 Jul 2014) $
7  $Author: agulati $
8  ***********************************************************
9
10  GETNXT READS THE NEXT CARD FROM 'FILE' INTO THE ARRAY 'DATA'
11  AND INITIALIZES 'PTR'. SET flag = .true.  IF AN ECHO OF INPUT
12  IS NOT NEEDED
13
14  */
15
16 #include <cstdlib>
17 #include <cstdio>
18
19 #include "blkdta.h"
20 #include "uiod.h"
21
22 #include "inputfile.h"
23
24 void InputFile_class::getnxt(BOOLEAN flag, BOOLEAN newline)
25 {
26
27         int i;
28         signed char ch;  // changed "char" to "signed char". lajos, Nov 18, 2004
29
30         while (true)
31         {
32                 // default value of parameter newline is TRUE
33                 if (newline)
34                         fprintf(output, "\n");
35
36                 // get line of characrers
37                 for (i = 0; i < DATASIZ; i++)     // bug 190 - swr - 12/09/05
38                 {
39                         if (((ch = fgetc(infile)) == '\n') || (ch == EOF))
40                                 break;
41                         data[i] = ch < ' ' ? ' ' : ch; // bug 197 - replace control characters with a space - swr - 1/17/06
42                 };
43
44                 if (ch == EOF)
45                 {
46                         // END OF FILE CONDITION
47                         fprintf(output,
48                                         "\n **** unexpected end of inputfile\n **** program aborted\n");
49                         exit(-1);
50                 }
51                 else
52                 {
53                         // read the rest of the line if more than DATASIZ characters
54                         while ((ch != '\n') && (ch != EOF))
55                                 ch = fgetc(infile);  // added check for EOF. lajos, Nov 18, 2004
56
57                         data[i] = 0;     // bug 190 - swr - 12/21/05
58                         if (data[0] == '*')
59                                 fprintf(output, "\n     <*> %s", &(data[1]));
60                         else
61                         {
62                                 if (!(flag))
63                                         fprintf(output, "\n     <#> %s", data);
64                         };
65                         // fil up the rest of the buffer with spaces
66                         for (; i < DATASIZ + 1; i++)
67                                 data[i] = ' ';  // bug 190 - swr - 12/09/05
68
69                         ptr = -1;
70                         data[DATASIZ + 1] = 0; // terminate string - bug 190 - swr - 12/09/05
71
72                 }
73
74                 if (data[0] != '*')
75                         break;
76         }
77 }