Mapper
nextch.c
Go to the documentation of this file.
1 /*Translated by FOR_C, v3.4.2 (-), on 06/07/94 at 16:58:22 */
2 /*FOR_C Options SET: c=2 com=u do=r4 ftn=2ln6k op=iv s=dvn str=l sq=i */
3 
4 #define _POSIX_SOURCE
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <ctype.h>
8 #include <dirent.h>
9 #include <unistd.h>
10 #include <math.h>
11 #include <string.h>
12 #include <fcntl.h>
13 #include <sys/stat.h>
14 #include "shef_structs_external.h"
15 
16 /*---------------------------------------------------------------------
17 
18  NAME
19  SUBROUTINE NEXTCH(ICHAR,STATUS)
20 
21  PURPOSE
22  Read lines into a buffer and provide the next character.
23  IP points to the last char provided.
24  Anything after and including a colon is ignored.
25  Database comments are noted withing double quotes.
26 
27  VERSION and UPDATES
28  1.0 APR 82 Geoffrey M. Bonnin
29  Original Version
30  1.1 AUG 84
31  Allow colon as off/on switch on line scan.
32  Modify line output to error log.
33  1.2 JUN 89 David G. Brandon
34  Adapted to QNX NWS Hydromet
35  2.0 MAY 94 David G. Brandon
36  Also Translated to 'C' using FOR_C
37  2.1 APR 95 David G. Brandon
38  Changed some of the I/O created by the FORTRAN to C
39  translator to 'C' routines
40  Cast input string to all upper case.
41  2.2 OCT 95 DGB
42  Add iscore to t_codes array.
43  2.3 MAY 30 96 DGB
44  Add the capability to store the last line read into
45  a char buffer. This will be used in the option to
46  write out the current line if an error occurs.
47  This is refered to as the PARIAL_ERROR option.
48  2.4 SEP 10 97 DGB
49  Add the use of MAX_SHEF_INPUT so that the input line can
50  be longer than 80 characters.
51  Add code for database comments.
52  Add error checks for database comments.
53  2.5 JAN 27 98 DGB
54  Add capabilities for preprocessing .E lines.
55  Preprocessing consists of detecting NULL fields,
56  i.e., a slash followed by another slash or blanks
57  then a slash. { e.g. 12.2 / / 4 }. Also,
58  leading slash marks on continuation lines are
59  replaced by a blank.
60  2.5 JAN 29 1998 DGB
61  Change number of consecutive blanks from 15 to
62  NUM_BLANKS { set at 50 }
63  2.6 SEP 22 98 DGB
64  Add -r switch for preprocessing .E messages
65  2.7 APR 1 99 DGB
66  Change <cr> decimal 13 to blanks.
67  2.8 JAN 02 00 DGB
68  Reworked input so that a : could be part of a
69  retained or database comment.
70  2.9 DEC 06 00 DGB
71  Cast at tab ( ASCII 9 ) to a blank when reading
72  in data.
73  *--------------------------------------------------------------------- */
74 
75 
76 void nextch(ichar, status)
77 short int *ichar, *status;
78 {
79  static short int _fst, i, j, lchar, itemp; /* dgb:09/10/97 */
80  char buff_temp[MAX_SHEF_INPUT + 1]; /* dgb:09/10/97 */
81  int DEBUG1; /* dgb:10/19/97 */
82 
83  /* OFFSET Vectors w/subscript range: 1 to dimension */
84  short *const Ibuf = &buffer_.ibuf[0] - 1;
85 
86  *status = 0;
87 
88  DEBUG1 = 0;
89 
90  /* Update pointer and check it */
91 
92 L_10:
93  buffer_.ip = buffer_.ip + 1;
94  if( buffer_.ip == MAX_SHEF_INPUT + 1 ) /* dgb:09/10/97 */
95  goto L_910;
96  if( buffer_.ip > MAX_SHEF_INPUT ) /* dgb:09/10/97 */
97  goto L_40;
98 
99  /* Get the character and update last character */
100 
101  lchar = xchar_.ichar;
102  *ichar = Ibuf[buffer_.ip];
103  xchar_.ichar = *ichar;
104 
105  if ( DEBUG1 )
106  {
107  printf("\nxchar_.ichar = %c %d",xchar_.ichar,xchar_.ichar);
108  }
109  /* Test for NUM_BLANKS consecutive blanks, end of line */
110 
111  if( *ichar != codes_.iblnk )
112  goto L_30;
113  if( lchar != codes_.iblnk )
114  goto L_20;
115  buffer_.nblnk = buffer_.nblnk + 1;
116  if( buffer_.nblnk < NUM_BLANKS ) /* dgb:01/29/98 */
117  goto L_30;
118  buffer_.ip = MAX_SHEF_INPUT + 1; /* dgb:09/10/97 */
119  goto L_910;
120 
121 L_20:
122  buffer_.nblnk = 1;
123 
124  /* Check for a colon */
125 
126 L_30:
127  if( *ichar == codes_.icolon ) /* dgb:09/10/97 */
128  { /* dgb:09/10/97 */
129  comment_.colon_on = 1; /* dgb:09/10/97 */
130  goto L_35; /* dgb:09/10/97 */
131  } /* dgb:09/10/97 */
132 
133  if ( *ichar == codes_.dquote ) /* dgb:09/10/97 */
134  { /* dgb:09/10/97 */
135  comment_.dquote_on = 1; /* dgb:09/10/97 */
136  comment_.pos = 0; /* dgb:09/10/97 */
137  buffer_.nblnk = 0; /* dgb:09/10/97 */
138  goto L_35; /* dgb:09/10/97 */
139  } /* dgb:09/10/97 */
140 
141  i = 0; /* dgb:09/10/97 */
142  itemp = buffer_.ip; /* dgb:09/10/97 */
143  while( Ibuf[itemp+i] == codes_.iblnk ) /* dgb:09/10/97 */
144  { /* dgb:09/10/97 */
145  i++; /* dgb:09/10/97 */
146  if ( i > NUM_BLANKS ) break; /* dgb:01/29/98 */
147  } /* dgb:09/10/97 */
148 
149  if ( Ibuf[itemp+i] == codes_.dquote ) /* dgb:09/10/97 */
150  goto L_10; /* dgb:09/10/97 */
151 
152  if ( Ibuf[itemp+i] == codes_.icolon ) /* dgb:09/10/97 */
153  goto L_10; /* dgb:09/10/97 */
154 
155  goto L_900; /* dgb:09/10/97 */
156 
157 L_35:
158  buffer_.ip = buffer_.ip + 1;
159  if( buffer_.ip == MAX_SHEF_INPUT + 1 ) /* dgb:09/10/97 */
160  goto L_910;
161  *ichar = Ibuf[buffer_.ip];
162  if ( comment_.colon_on == 1 ) /* dgb:01/02/00 */
163  {
164  if ( *ichar == codes_.dquote ) /* dgb:01/02/00 */
165  goto L_930; /* dgb:01/02/00 */
166  if ( *ichar == codes_.icolon ) /* dgb:01/02/00 */
167  {
168  comment_.colon_on = 0; /* dgb:01/02/00 */
169  goto L_10; /* dgb:01/02/00 */
170  }
171  goto L_35; /* dgb:01/02/00 */
172  }
173 
174  if ( comment_.dquote_on ) /* dgb:01/02/00 */
175  {
176  if ( *ichar == codes_.dquote ) /* dgb:01/02/00 */
177  {
178  comment_.dquote_on = 0; /* dgb:01/02/00 */
179  goto L_10; /* dgb:01/02/00 */
180  }
181  }
182 
183  if ( comment_.dquote_on ) /* dgb:09/10/97 */
184  { /* dgb:09/10/97 */
185  if ( *ichar == codes_.iblnk ) /* dgb:09/10/97 */
186  { /* dgb:09/10/97 */
187  buffer_.nblnk = buffer_.nblnk + 1; /* dgb:09/10/97 */
188  if( buffer_.nblnk > 14 ) /* dgb:09/10/97 */
189  goto L_40; /* dgb:09/10/97 */
190  } /* dgb:09/10/97 */
191 
192  comment_.comment[comment_.pos] = *ichar; /* dgb:09/10/97 */
193  comment_.pos++; /* dgb:09/10/97 */
194  if ( comment_.pos > MAX_COMMENT_LENGTH ) /* dgb:09/10/97 */
195  goto L_940; /* dgb:09/10/97 */
196  } /* dgb:09/10/97 */
197 
198  goto L_35;
199 
200  /* Read the next line */
201 
202 L_40:
203 
204 
205  comment_.colon_on = 0;
206  comment_.dquote_on = 0;
207 
208  for( i = 1; i <= MAX_SHEF_INPUT; i++ ) /* dgb:09/10/97 */
209  {
210  Ibuf[i] = codes_.iblnk;
211  }
212 
213  if ( (fgets( buff_temp,sizeof(buff_temp),fp_.lchn)) == NULL )
214  goto L_920;
215  for ( i = strlen(buff_temp) - 1; i < MAX_SHEF_INPUT + 1; i++) /* dgb:09/10/97 */
216  buff_temp[i] = 32;
217 
218  for ( i = 0; i < MAX_SHEF_INPUT + 1; i++) /* dgb:09/10/97 */
219  {
220  if ( buff_temp[i] == 9 ) /* dgb:12/06/00 */
221  buff_temp[i] = 32; /* dgb:12/06/00 */
222  if ( buff_temp[i] == 13 )
223  buff_temp[i] = 32; /* dgb:/04/01/99 */
224  Ibuf[i+1] = toupper( buff_temp[i] );
225  tempfiles_.last_line_read[i] = Ibuf[i+1]; /* dgb:05/30/96 */
226  }
227 
228  for( i = MAX_SHEF_INPUT; i >= 1; i-- ) /* dgb:09/10/97 */
229  {
230  if( Ibuf[i] != codes_.iblnk )
231  goto L_70;
232  }
233 
234  goto L_75;
235 
236 L_70:
237 
238  if ( !PARTIAL_ERROR ) /* dgb:05/30/96 */
239  {
240  for( j = 1, _fst=1; (j <= i) || _fst; j++, _fst=0 )
241  {
242  fprintf( fp_.icher,"%c", Ibuf[j]);
243  }
244  if ( fp_.icher )
245  fprintf( fp_.icher, "\n");
246  }
247 
248  if ( DOTEPRE )
249  pre_process_dote(); /* dgb:01/27/98 */
250 
251 L_75:
252  buffer_.ip = 0;
253  goto L_10;
254 
255  /* Got it */
256 
257 L_900:
258  return;
259 
260  /* NUM_BLANKS Consecutive blanks, end of line */
261 
262 L_910:
263  buffer_.nblnk = 0;
264  *status = 1;
265  return;
266 
267  /* File read error */
268 
269 L_920:
270 
271  *status = 2;
272  return;
273 
274  /* Embedded comment error */
275 
276 L_930: /* dgb:09/10/97 */
277  buffer_.nblnk = 0; /* dgb:09/10/97 */
278  i = 39;
279  sherr(&i); /* dgb:09/10/97 */
280  *status = 1; /* dgb:09/10/97 */
281  return; /* dgb:09/10/97 */
282 
283  /* Database comment too long */
284 
285 L_940: /* dgb:09/10/97 */
286  buffer_.nblnk = 0; /* dgb:09/10/97 */
287  i = 40;
288  sherr(&i); /* dgb:09/10/97 */
289  *status = 1; /* dgb:09/10/97 */
290  return; /* dgb:09/10/97 */
291 
292 }
static int i
pre_process_dote()
Definition: dotepre.c:17
printf("fbuf is %s\n", fbuf)
fprintf(fp,"%d %d %d %d 1\n", iminx, iminy, maxi, maxj)
int j
Definition: mapp2h.h:48
void nextch(short int *ichar, short int *status)
Definition: nextch.c:76
#define MAX_COMMENT_LENGTH
Definition: shef.h:39
#define MAX_SHEF_INPUT
Definition: shef.h:38
#define NUM_BLANKS
Definition: shef.h:17
int PARTIAL_ERROR
Definition: shef_structs.h:248
struct t_pointers_ fp_
struct t_codes_ codes_
int DOTEPRE
Definition: shef_structs.h:248
struct t_buffer_ buffer_
struct t_tempfiles_ tempfiles_
struct t_xchar_ xchar_
struct t_comment comment_
void sherr(short int *ier)
Definition: sherr.c:44
short int ip
Definition: shef_structs.h:109
short int ibuf[MAX_SHEF_INPUT]
Definition: shef_structs.h:109
short int nblnk
Definition: shef_structs.h:109
short int iblnk
Definition: shef_structs.h:81
short int icolon
Definition: shef_structs.h:81
short int dquote
Definition: shef_structs.h:82
short int dquote_on
Definition: shef_structs.h:227
char comment[MAX_COMMENT_LENGTH]
Definition: shef_structs.h:228
short int pos
Definition: shef_structs.h:227
short int colon_on
Definition: shef_structs.h:227
FILE * lchn
Definition: shef_structs.h:72
FILE * icher
Definition: shef_structs.h:72
char last_line_read[MAX_SHEF_INPUT+1]
Definition: shef_structs.h:222
short int ichar
Definition: shef_structs.h:112