4b00b23e64aa9dbb9a361ec90ac2406a9340d352
[occt.git] / src / IGESFile / igesread.c
1 /*
2  Copyright (c) 1999-2012 OPEN CASCADE SAS
3
4  The content of this file is subject to the Open CASCADE Technology Public
5  License Version 6.5 (the "License"). You may not use the content of this file
6  except in compliance with the License. Please obtain a copy of the License
7  at http://www.opencascade.org and read it completely before using this file.
8
9  The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10  main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11
12  The Original Code and all software distributed under the License is
13  distributed on an "AS IS" basis, without warranty of any kind, and the
14  Initial Developer hereby disclaims all such warranties, including without
15  limitation, any warranties of merchantability, fitness for a particular
16  purpose or non-infringement. Please see the License for the specific terms
17  and conditions governing the rights and limitations under the License.
18
19 */
20
21 /*  Regroupement des sources "C" pour compilation   */ 
22 #include <stdio.h>
23 #include "igesread.h"
24
25 /*
26 void IGESFile_Check21 (int mode,char * code, int num, char * str);
27 */
28 void IGESFile_Check3 (int mode,char * code);
29 void IGESFile_Check2 (int mode,char * code, int num, char * str);
30
31 /*  #include "structiges.c"    ...  fait par analiges qui en a l'usage  ...  */
32 void iges_initfile();
33 int  iges_lire (FILE* lefic, int *numsec, char ligne[100], int modefnes);
34 void iges_newparam(int typarg,int longval, char *parval);
35 void iges_param(int *Pstat,char *ligne,char c_separ,char c_fin,int lonlin);
36 void iges_Dsect (int *Dstat,int numsec,char* ligne);
37 void iges_Psect(int *Pstat,int numsec,char ligne[80]);
38
39
40
41 /*  Routine de lecture generale d'un fichier IGES
42     Assure l'enchainement des appels necessaires
43     Il en resulte un ensemble de donnees (struct C) interrogeables par
44     routines ad hoc  (cf igesread.h qui les recapitule pour appel par C++)
45
46     Retourne : 0 si OK, 1 si fichier pas pu etre ouvert
47   */
48
49
50 /* MGE 16/06/98*/
51 /* To use strcpy*/
52 /*#include <string.h>*/
53 /* To use Msg class */
54 /*#include <MoniTool_Msg.hxx>*/
55
56 static  char sects [] = " SGDPT ";
57
58
59 int igesread(nomfic,lesect,modefnes)
60 char* nomfic; int lesect[6]; int modefnes;
61 {
62   /* MGE 16/06/98 */
63
64   FILE* lefic; char ligne[100]; int numsec, numl;  int i; int i0;int j;
65   char str[2];
66
67   int Dstat = 0; int Pstat = 0; char c_separ = ','; char c_fin = ';';
68   iges_initfile();
69   lefic = stdin; i0 = numsec = 0;  numl = 0;
70   if (nomfic[1] != '\0') lefic = fopen(nomfic,"r");
71   if (lefic == NULL) return -1;    /*  fichier pas pu etre ouvert  */
72   for (i = 1; i < 6; i++) lesect[i] = 0;
73   for (j = 0; j < 100; j++) ligne[j] = 0;
74   for(;;) {
75     numl ++;
76     i = iges_lire(lefic,&numsec,ligne,modefnes);
77     if (i <= 0) {
78       if (i  == 0) break;
79       /* Sending of message : Syntax error */
80       {
81         str[1] = '\0';
82         str[0] = sects[i0];
83         IGESFile_Check2 (0,"XSTEP_18",numl,str); /* //gka 15 Sep 98: str instead of sects[i0]); */
84       }
85     
86       if (i0 == 0) return -1;
87       lesect[i0] ++;
88       continue;
89     }
90     lesect[i] ++;  i0 = i;
91     if (numsec != lesect[i]) {
92       /* Sending of message : Syntax error */
93       str[1] = '\0';
94       str[0] = sects[i0];
95       IGESFile_Check2 (0,"XSTEP_19",numl,str); /* //gka 15 Sep 98: str instead of sects[i0]); */
96     }
97
98     if (i == 1) {                                   /* Start Section (comm.) */
99       ligne[72] = '\0';
100       iges_newparam (0,72,ligne);
101     }
102     if (i == 2) {                                   /* Header (Global sect) */
103       iges_setglobal();
104       for (;;) {
105         if (lesect[i] == 1) {    /* Separation specifique */
106           int n0 = 0;
107           if (ligne[0] != ',') {  c_separ = ligne[2]; n0 = 3;  }
108           if (ligne[n0+1] != c_separ) { c_fin = ligne[n0+3]; }
109         }
110         iges_param(&Pstat,ligne,c_separ,c_fin,72);
111         if (Pstat != 2) break;
112       }
113     }
114     if (i == 3) iges_Dsect(&Dstat,numsec,ligne);    /* Directory  (Dsect) */
115     if (i == 4) {                                   /* Parametres (Psect) */
116       iges_Psect(&Pstat,numsec,ligne);
117       for (;;) {
118         iges_param(&Pstat,ligne,c_separ,c_fin,64);
119         if (Pstat != 2) break;
120       }
121     }
122   }
123
124   /* Sending of message : No Terminal Section */
125   if (lesect[5] == 0) {
126     IGESFile_Check3 (1, "XSTEP_20");
127     //return -1;
128   }
129   
130
131   fclose (lefic);
132
133   return 0;
134 }