Mapper
shfor.c
Go to the documentation of this file.
1 /*Translated by FOR_C, v3.4.2 (-), on 06/07/94 at 17:02:25 */
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 SHFOR(ITYPE,IFLAG,STATUS)
20 
21  PURPOSE
22  This routine reads characters one at a time from the input
23  file and searches for a SHEF format specifier.
24  The format type is returned in ITYPE.
25  If IFLAG is set to zero, it looks at the last character read.
26 
27  SHEF FORMAT SPECIFIER ITYPE
28  .A 1
29  .AR 2
30  .B 3
31  .BR 4
32  .E 5
33  .ER 6
34 
35  VERSION and UPDATES
36  1.0 APR 82 Geoffrey M. Bonnin
37  Original Version
38  1.1 AUG 84 Geoffrey M. Bonnin
39  ALLOW ":" AS TURN ON/OFF
40  1.2 JUN 89 David G. Brandon
41  Adapted to QNX NWS Hydromet
42  2.0 MAY 94 David G. Brandon
43  Also Translated to 'C' using FOR_C
44  2.1 Add iscore to t_codes array.
45  2.2x SEP 10 97 DGB
46  Add the use of MAX_SHEF_INPUT so that the input line can
47  be longer than 80 characters.
48  2.3 AUG 2 98 DGB
49  Decode test 'Y' formats the same as 'A'.
50  2.4 MAR 03, 2002
51  Fix code to recognize more than one digit for a
52  continuation line, e.g., .E10, .E11, .A12
53  2.5 MAR 12, 2002
54  Fix at 2.4 still did not work correctly. It worked for
55  all numbers except 0. This was fixed.
56  *--------------------------------------------------------------------- */
57 
58 void shfor(itype, iflag, status)
59 short int *itype, *iflag, *status;
60 {
61  static short int flag;
62  short int staty; /* dgb 03/03/2002 */
63  /* OFFSET Vectors w/subscript range: 1 to dimension */
64  short *const Ibuf = &buffer_.ibuf[0] - 1;
65 
66  *status = 0;
67 
68  if( *iflag == 0 )
69  goto L_15;
70 
71  /* Read a Character */
72 
73 L_10:
74  buffer_.ip = MAX_SHEF_INPUT + 1; /* dgb:09/10/97 */
75 
76  /* Check for A '.' in column 1 */
77 
78  nextch( &xchar_.ichar, status );
79  if( *status == 1 )
80  {
81  *status = 0;
82  goto L_10;
83  }
84  else if( *status == 2 )
85  {
86  *status = 0;
87  goto L_9010;
88  }
89 L_15:
90  if( (xchar_.ichar == codes_.idot) && (buffer_.ip == 1) )
91  goto L_19;
92  goto L_10;
93 
94  /* Check for 'A', 'B' or 'E' */
95 
96 L_19:
97  nextch( &xchar_.ichar, status );
98  if( *status == 1 )
99  {
100  *status = 0;
101  goto L_10;
102  }
103  else if( *status == 2 )
104  {
105  *status = 0;
106  goto L_9010;
107  }
108 
109  if ( xchar_.ichar == codes_.ichy ) /* dgb:08/02/98 */
110  goto L_29;
111  if( xchar_.ichar != codes_.icha )
112  goto L_30; /* 'A' */
113 
114 L_29: *itype = 1;
115  goto L_50;
116 
117 L_30:
118  if( xchar_.ichar != codes_.ichb )
119  goto L_40; /* 'B' */
120  *itype = 3;
121  goto L_50;
122 
123 L_40:
124  if( xchar_.ichar != codes_.iche )
125  goto L_9020; /* 'E' */
126  *itype = 5;
127  goto L_50;
128 
129  /* Check for an 'R' .. Revision */
130 
131 L_50:
132  nextch( &xchar_.ichar, status );
133  if( *status == 1 )
134  {
135  *status = 0;
136  goto L_10;
137  }
138  else if( *status == 2 )
139  {
140  *status = 0;
141  goto L_9010;
142  }
143 
144  if( xchar_.ichar != codes_.ichr )
145  goto L_56;
146 
147  *itype = *itype + 1;
148 
149 
150  /* Check for a continuation */
151 
152  nextch( &xchar_.ichar, status );
153  if( *status == 1 )
154  {
155  *status = 0;
156  goto L_10;
157  }
158  else if( *status == 2 )
159  {
160  *status = 0;
161  goto L_9010;
162  }
163 
164 L_56:
165  irang( &xchar_.ichar, &codes_.ich0, &codes_.ich9, status ); /* dgb:03/12/02 */
166  if( *status == 1 ) /* changed codes_.ich1 to codes_.ich0 */
167  {
168  *status = 0;
169  goto L_60;
170  }
171  *itype = -*itype;
172  nextch( &xchar_.ichar, status );
173 
174  irang( &xchar_.ichar, &codes_.ich0, &codes_.ich9, &staty ); /* dgb:03/03/2002 */
175 
176  if ( staty == 0 ) /* dgb:03/03/2002 */
177  { /* dgb:03/03/2002 */
178  *itype = -*itype; /* dgb:03/03/2002 */
179  goto L_56; /* dgb:03/03/2002 */
180  } /* dgb:03/03/2002 */
181 
182  if( *status == 1 )
183  {
184  *status = 0;
185  goto L_10;
186  }
187  else if( *status == 2 )
188  {
189  *status = 0;
190  goto L_9010;
191  }
192  goto L_9000;
193 
194  /* Make sure we haven't picked up a '.END' */
195 
196 L_60:
197 
198  if( xchar_.ichar == codes_.ichn )
199  goto L_9020;
200 
201 
202  /* Got the format type */
203 
204 L_9000:
205  return;
206 
207  /* Handle file errors */
208 
209 L_9010:
210  *status = 1;
211  return;
212 
213 L_9020:
214  flag = 1;
215  sherr( &flag );
216  goto L_10;
217 
218 }
219 
void irang(short int *i, short int *min_, short int *max_, short int *status)
Definition: irang.c:33
void nextch(short int *ichar, short int *status)
Definition: nextch.c:76
#define MAX_SHEF_INPUT
Definition: shef.h:38
struct t_codes_ codes_
struct t_buffer_ buffer_
struct t_xchar_ xchar_
void sherr(short int *ier)
Definition: sherr.c:44
void shfor(short int *itype, short int *iflag, short int *status)
Definition: shfor.c:58
short int ip
Definition: shef_structs.h:109
short int ibuf[MAX_SHEF_INPUT]
Definition: shef_structs.h:109
short int iche
Definition: shef_structs.h:78
short int ichy
Definition: shef_structs.h:80
short int ich0
Definition: shef_structs.h:80
short int icha
Definition: shef_structs.h:78
short int ichr
Definition: shef_structs.h:79
short int ich9
Definition: shef_structs.h:81
short int ichn
Definition: shef_structs.h:79
short int ichb
Definition: shef_structs.h:78
short int idot
Definition: shef_structs.h:82
short int ichar
Definition: shef_structs.h:112