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