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