0024624: Lost word in license statement in source files
[occt.git] / src / IGESFile / analiges.c
CommitLineData
b311480e 1/*
973c2be1 2 Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3
973c2be1 4 This file is part of Open CASCADE Technology software library.
b311480e 5
d5f74e42 6 This library is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 8 by the Free Software Foundation, with special exception defined in the file
9 OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 distribution for complete text of the license and disclaimer of any warranty.
b311480e 11
973c2be1 12 Alternatively, this file may be used under the terms of Open CASCADE
13 commercial license or contractual agreement.
b311480e 14*/
15
7fd59977 16#include <stdlib.h>
17#include "igesread.h"
18
19void iges_newparam(int typarg,int longval, char *parval);
20void iges_newpart(int numsec);
498ce76b 21void iges_curpart(int dnum);
7fd59977 22void iges_addparam(int longval, char* parval);
23
24#define ArgVide 0
25#define ArgQuid 1
26#define ArgChar 2
27#define ArgInt 3 /* Entier non signe : peut evoluer vers Real ou Char */
28#define ArgSign 4 /* Entier signe : peut evoluer vers Real */
29#define ArgReal 5
30#define ArgExp 6 /* Real + lettre E : attendre confirmation */
31#define ArgRexp 7 /* Real + Exposant : se ramene a Real */
32#define ArgMexp 8 /* Real + Exposant INCOMPLET (pas de point decimal) */
33
34/* les structures de travail de structiges sont connues :
35 a savoir declarations + curp */
36/* #define VERIFPRINT */
37
38/* Lecture section D
39 Chaque entite tient sur deux lignes
40
41 Dstat demarre a zero "on lit une nouvelle entite"
42 et bascule avec un "deuxieme ligne de l'entite"
43*/
44
45
46static int bases[] =
47 { 1,10,100,1000,10000,100000,1000000, 10000000,100000000,1000000000 };
48
49/* DECODAGE : parce que scanf ne fait pas vraiment ce qu'il faut */
50/* Utilitaire decodant un nombre en format fixe dans une ligne
51 Il part de "depuis" inclus (debut ligne = 0) et prend "tant" caracteres
52 Valeur lue en retour de fonction */
498ce76b 53static int IGES_decode (char* ligne, int depuis, int tant)
7fd59977 54{
55 int val = 0; int i;
56 int depart = depuis+tant-1;
57 for (i = 0; i < tant; i ++) {
58 char uncar = ligne[depart-i];
59 if (uncar == ' ') break;
60 else if (uncar == '+') continue;
61 else if (uncar == '-') val = -val;
62 else if (uncar != '0') val += (uncar - 48)*bases[i];
63 }
64 return val;
65}
66
67/* Recopie d'une chaine de caracteres de longueur fixe (close par \0) */
498ce76b 68void IGES_copstr(char *ligne, int depuis, int tant, char* dans)
7fd59977 69{
70 int i;
71 for (i = 0; i < tant; i ++) { dans[i] = ligne[depuis+i]; }
72 dans[tant] = '\0';
73}
74
75/* Analyse section D */
498ce76b 76void iges_Dsect (int *Dstat, int numsec, char* ligne)
7fd59977 77{
78 struct dirpart *curp;
79 if (*Dstat == 0) {
80 iges_newpart(numsec);
81 curp = iges_get_curp();
82 curp->typ = IGES_decode(ligne, 0,8);
83 curp->poi = IGES_decode(ligne, 8,8);
84 curp->pdef = IGES_decode(ligne,16,8);
85 curp->tra = IGES_decode(ligne,24,8);
86 curp->niv = IGES_decode(ligne,32,8);
87 curp->vue = IGES_decode(ligne,40,8);
88 curp->trf = IGES_decode(ligne,48,8);
89 curp->aff = IGES_decode(ligne,56,8);
90 curp->blk = IGES_decode(ligne,64,2);
91 curp->sub = IGES_decode(ligne,66,2);
92 curp->use = IGES_decode(ligne,68,2);
93 curp->her = IGES_decode(ligne,70,2);
94#ifdef VERIFPRINT
95 printf("Entite %d : type %d ->P %d\n",numsec,typ,poi);
96#endif
97 *Dstat = 1;
98 } else if (*Dstat == 1) {
99 curp = iges_get_curp();
100 curp->typ2 = IGES_decode(ligne, 0,8);
101 curp->epa = IGES_decode(ligne, 8,8);
102 curp->col = IGES_decode(ligne,16,8);
103 curp->nbl = IGES_decode(ligne,24,8);
104 curp->form = IGES_decode(ligne,32,8);
105 IGES_copstr (ligne,40,8,curp->res1);
106 IGES_copstr (ligne,48,8,curp->res2);
107 IGES_copstr (ligne,56,8,curp->nom);
108 IGES_copstr (ligne,64,8,curp->num);
109#ifdef VERIFPRINT
110 printf("Entite %d : type %d (redite) form %d\n",numsec,typ2,form);
111#endif
112 *Dstat = 0;
113 }
114}
115
116
117/* Lecture section P : preanalyse
118 Extraction du numero D et troncature a 64 caracteres */
119
498ce76b 120void iges_Psect (int numsec, char ligne[80])
7fd59977 121{
122 int dnum;
123 dnum = atoi(&ligne[65]);
124 ligne[64] = '\0';
498ce76b 125 iges_curpart(dnum);
7fd59977 126#ifdef VERIFPRINT
127 printf("Entite P:%d ->D:%d,soit %s\n",numsec,dnum,ligne);
498ce76b 128#else
129 (void)numsec; // just to avoid warning
7fd59977 130#endif
131}
132
133
134/* Depiautage ligne section P (ou G)
135 Fractionnement en parametres
136 Separes par Separateur courant (c_separ), de fin (c_fin), plus
137 traitement des caracteres sous forme Hollerith ... (nnnH...)
138
139 Pstat entree : 0 debut entite, 1 debut ligne, 2 courant, 3 pas fini(H)
140 Pstat retour : 0 fin entite, 1 fin ligne, 2 courant (en voila un), 3
141 pas fini (un nnnH... pas termine)
142*/
143
144static int nbcarH = 0; static int numcar = 0; static int reste = 0;
145/* reste : 0 cas normal; 1 completer parametre; -1 le sauter */
146static int typarg;
147/* + definitions des types de parametres en tete */
148
149
498ce76b 150void iges_param (int *Pstat, char *ligne, char c_separ, char c_fin, int lonlin)
7fd59977 151{
152 int i,i0,j; char param[80]; char unpar;
153 if (*Pstat == 0) reste = 0;
154 if (*Pstat != 2) numcar = 0;
155 if (*Pstat < 3) nbcarH = 0;
156 else {
157 numcar = nbcarH;
158 if (numcar > lonlin) {
159 iges_addparam(lonlin,ligne);
160 nbcarH -= lonlin; /* ??? enregistrer ... ??? */
161 return;
162 } else {
163 iges_addparam(nbcarH,ligne);
164 nbcarH = 0;
165 }
166 }
167 i0 = 0; /* debut param utile (apres blancs eventuels), par defaut a 0 */
168 typarg = ArgVide;
169 for (i = 0; (unpar = ligne[numcar+i]) != '\0'; i ++) {
170 if (unpar == c_separ) {
171 *Pstat = 2; param[i] = '\0';
172#ifdef VERIFPRINT
173 printf("numcar = %d type %d param: %s ",numcar,typarg,&param[i0]);
174#endif
175 if (reste == 0) iges_newparam(typarg,i-i0+1,&param[i0]);
176 else if (reste > 0) iges_addparam(i-i0+1,&param[i0]);
177 reste = 0;
178 for (j = i+1; (unpar = ligne[numcar+j]) != '\0'; j++) {
179 if (unpar != ' ') { numcar += i+1; return; }
180 }
181 *Pstat = 1; return;
182 }
183 if (unpar == c_fin) {
184 *Pstat = 1; param[i] = '\0';
185#ifdef VERIFPRINT
186 printf("numcar = %d type %d param: %s ",numcar,typarg,&param[i0]);
187#endif
188 if (reste == 0) iges_newparam(typarg,i-i0+1,&param[i0]);
189 else if (reste > 0) iges_addparam(i-i0+1,&param[i0]);
190 reste = 0;
191 return;
192 }
193 param[i] = unpar;
194
195/* Type du parametre ? */
196
197 if (unpar > 47 && unpar < 58) {
198 if (typarg == ArgInt) continue;
199 if (typarg == ArgVide) typarg = ArgInt;
200 else if (typarg == ArgExp) typarg = ArgRexp;
201 }
202
203 else if (unpar == '+' || unpar == '-') {
204 if (typarg == ArgVide) typarg = ArgSign;
205 else if (typarg != ArgExp && typarg != ArgMexp) typarg = ArgQuid;
206 }
207
208 else if (unpar == '.') {
209 if (typarg == ArgVide) typarg = ArgReal;
210 else if (typarg == ArgInt || typarg == ArgSign) typarg = ArgReal;
211 else typarg = ArgQuid;
212 }
213
214 else if (unpar == 'E' || unpar == 'e' || unpar == 'D' || unpar == 'd') {
215 if (typarg == ArgReal) typarg = ArgExp;
216 else if (typarg == ArgInt || typarg == ArgSign) typarg = ArgMexp;
217 else typarg = ArgQuid;
218 }
219
220 else if (unpar == 'H') { /* format Hollerith ? */
221 if (typarg != ArgInt) { typarg = ArgQuid; continue; }
222 typarg = ArgChar;
223 nbcarH = 0;
224 for (j = i0; j < i; j++) {
225 if (param[j] > 47 && param[j] < 58) nbcarH = nbcarH*10 + (param[j]-48);
226 else { nbcarH = 0; break; }
227 }
228 if (numcar+i+nbcarH >= lonlin) { /* texte a cheval sur +ieurs lignes */
229 for (j = 1; j < lonlin-numcar-i; j++) param[i+j] = ligne[numcar+i+j];
230 param[lonlin-numcar] = '\0';
231 nbcarH = (numcar+i +nbcarH+1 -lonlin);
232 *Pstat =3;
233#ifdef VERIFPRINT
234 printf("numcar = %d param: %s ",numcar,param);
235#endif
236 iges_newparam(typarg,lonlin-i0,&param[i0]);
237 reste = 1;
238 return;
239 } else {
240 for (j = 1; j <= nbcarH; j++) param[i+j] = ligne[numcar+i+j];
241 i += nbcarH;
242 }
243 }
244
245/* blanc : leading (facile) ou trailing (chercher la suite), sinon mauvais */
246 else if (unpar == ' ') {
247 if (typarg == ArgVide) i0 = i+1;
248 else {
249 for (j = i+1; (unpar = ligne[numcar+j]) != '\0' ; j ++) {
250 if (unpar == c_separ || unpar == c_fin) break;
251 if (unpar != ' ') { typarg = ArgQuid; break; }
252 }
253 }
254 }
255
256 else typarg = ArgQuid; /* caractere non reconnu */
257 }
258/* Ici, fin de ligne sans separateur : noter parametre en cours ! */
259 *Pstat = 1; param[i] = '\0'; reste = -1;
260#ifdef VERIFPRINT
261 printf ("Fin de ligne sans separateur, numcar,i : %d %d\n",numcar,i);
262 if (i > i0) printf("numcar = %d type %d param: %s ",numcar,typarg,&param[i0]);
263#endif
264 if (i > i0) iges_newparam(typarg,i-i0+1,&param[i0]);
265}