Integration of OCCT 6.5.0 from SVN
[occt.git] / src / IGESFile / igesread.c
1 /*  Regroupement des sources "C" pour compilation   */
2
3 #include <stdio.h>
4 #include "igesread.h"
5
6 /*
7 void IGESFile_Check21 (int mode,char * code, int num, char * str);
8 */
9 void IGESFile_Check3 (int mode,char * code);
10 void IGESFile_Check2 (int mode,char * code, int num, char * str);
11
12 /*  #include "structiges.c"    ...  fait par analiges qui en a l'usage  ...  */
13 void iges_initfile();
14 int  iges_lire (FILE* lefic, int *numsec, char ligne[100], int modefnes);
15 void iges_newparam(int typarg,int longval, char *parval);
16 void iges_param(int *Pstat,char *ligne,char c_separ,char c_fin,int lonlin);
17 void iges_Dsect (int *Dstat,int numsec,char* ligne);
18 void iges_Psect(int *Pstat,int numsec,char ligne[80]);
19
20
21
22 /*  Routine de lecture generale d'un fichier IGES
23     Assure l'enchainement des appels necessaires
24     Il en resulte un ensemble de donnees (struct C) interrogeables par
25     routines ad hoc  (cf igesread.h qui les recapitule pour appel par C++)
26
27     Retourne : 0 si OK, 1 si fichier pas pu etre ouvert
28   */
29
30
31 /* MGE 16/06/98*/
32 /* To use strcpy*/
33 /*#include <string.h>*/
34 /* To use Msg class */
35 /*#include <MoniTool_Msg.hxx>*/
36
37 static  char sects [] = " SGDPT ";
38
39
40 int igesread(nomfic,lesect,modefnes)
41 char* nomfic; int lesect[6]; int modefnes;
42 {
43   /* MGE 16/06/98 */
44
45   FILE* lefic; char ligne[100]; int numsec, numl;  int i; int i0;int j;
46   char str[2];
47
48   int Dstat = 0; int Pstat = 0; char c_separ = ','; char c_fin = ';';
49   iges_initfile();
50   lefic = stdin; i0 = numsec = 0;  numl = 0;
51   if (nomfic[1] != '\0') lefic = fopen(nomfic,"r");
52   if (lefic == NULL) return -1;    /*  fichier pas pu etre ouvert  */
53   for (i = 1; i < 6; i++) lesect[i] = 0;
54   for (j = 0; j < 100; j++) ligne[j] = 0;
55   while (1) {
56     numl ++;
57     i = iges_lire(lefic,&numsec,ligne,modefnes);
58     if (i <= 0) {
59       if (i  == 0) break;
60       /* Sending of message : Syntax error */
61       {
62         str[1] = '\0';
63         str[0] = sects[i0];
64         IGESFile_Check2 (0,"XSTEP_18",numl,str); /* //gka 15 Sep 98: str instead of sects[i0]); */
65       }
66     
67       if (i0 == 0) return -1;
68       lesect[i0] ++;
69       continue;
70     }
71     lesect[i] ++;  i0 = i;
72     if (numsec != lesect[i]) {
73       /* Sending of message : Syntax error */
74       str[1] = '\0';
75       str[0] = sects[i0];
76       IGESFile_Check2 (0,"XSTEP_19",numl,str); /* //gka 15 Sep 98: str instead of sects[i0]); */
77     }
78
79     if (i == 1) {                                   /* Start Section (comm.) */
80       ligne[72] = '\0';
81       iges_newparam (0,72,ligne);
82     }
83     if (i == 2) {                                   /* Header (Global sect) */
84       iges_setglobal();
85       for (;;) {
86         if (lesect[i] == 1) {    /* Separation specifique */
87           int n0 = 0;
88           if (ligne[0] != ',') {  c_separ = ligne[2]; n0 = 3;  }
89           if (ligne[n0+1] != c_separ) { c_fin = ligne[n0+3]; }
90         }
91         iges_param(&Pstat,ligne,c_separ,c_fin,72);
92         if (Pstat != 2) break;
93       }
94     }
95     if (i == 3) iges_Dsect(&Dstat,numsec,ligne);    /* Directory  (Dsect) */
96     if (i == 4) {                                   /* Parametres (Psect) */
97       iges_Psect(&Pstat,numsec,ligne);
98       for (;;) {
99         iges_param(&Pstat,ligne,c_separ,c_fin,64);
100         if (Pstat != 2) break;
101       }
102     }
103   }
104
105   /* Sending of message : No Terminal Section */
106   if (lesect[5] == 0) {
107     IGESFile_Check3 (0,"XSTEP_20");
108     return -1;
109   }
110   
111
112   fclose (lefic);
113
114   return 0;
115 }