0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[occt.git] / src / IGESFile / liriges.c
CommitLineData
b311480e 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
7fd59977 21#include "igesread.h"
22#include <string.h>
23/* Routine de base de lecture d'un fichier IGES
24
25 Cette routine lit une ligne, sauf si le statut "relire sur place" est mis
26 (utilise pour changement de section) : il est reannule ensuite
27
28 Cette routine retourne :
29 - statut (retour fonction) : no de section : S,G,D,P,T (car 73) ou
30 0 (EOF) ou -1 (tacher de sauter) ou -2 (car. 73 faux)
31 - un numero de ligne dans la section (car. 74 a 80)
32 - la ligne tronquee a 72 caracteres (0 binaire dans le 73ieme)
33 Il faut lui fournir (buffer) une ligne reservee a 81 caracteres
34
35 Cas d erreur : ligne fausse des le debut -> abandon. Sinon tacher d enjamber
36*/
37
38static int iges_fautrelire = 0;
39int iges_lire (FILE* lefic, int *numsec, char ligne[100], int modefnes)
40/*int iges_lire (lefic,numsec,ligne,modefnes)*/
41/*FILE* lefic; int *numsec; char ligne[100]; int modefnes;*/
42{
43 int i,result; char typesec;
44/* int length;*/
45 if (iges_fautrelire == 0) {
46 if (*numsec == 0) ligne[72] = ligne[79] = ' ';
47 ligne[0] = '\0';
48 if(modefnes)
49 fgets(ligne,99,lefic); /*for kept compatibility with fnes*/
50 else {
51 /* PTV: 21.03.2002 it is neccessary for files that have only `\r` but no `\n`
52 examle file is 919-001-T02-04-CP-VL.iges */
53 while ( fgets ( ligne, 2, lefic ) && ( ligne[0] == '\r' || ligne[0] == '\n' ) )
54 {
55 }
56 fgets(&ligne[1],80,lefic);
57/* fgets(ligne,81,lefic); */
58 }
59 if (*numsec == 0 && ligne[72] != 'S' && ligne[79] == ' ') {
60/* ON A DU FNES : Sauter la 1re ligne */
61 ligne[0] = '\0';
62 if(modefnes)
63 fgets(ligne,99,lefic);/*for kept compatibility with fnes*/
64 else {
65 while ( fgets ( ligne, 2, lefic ) && ( ligne[0] == '\r' || ligne[0] == '\n' ) )
66 {
67 }
68 fgets(&ligne[1],80,lefic);
69/* fgets(ligne,81,lefic); */
70 }
71 }
72 if ((ligne[0] & 128)&&modefnes) {
008aef40 73 for (i = 0; i < 80; i ++)
74 ligne[i] = (char)(ligne[i] ^ (150 + (i & 3)));
7fd59977 75 }
76 }
77 if (feof(lefic)) return 0;
78 iges_fautrelire = 0;
79 if (ligne[0] == '\0' || ligne[0] == '\n' || ligne[0] == '\r')
80 return iges_lire(lefic,numsec,ligne,modefnes); /* 0 */
81 if (sscanf(&ligne[73],"%d",&result) == 0) return -1;
82/* { printf("Erreur, ligne n0.%d :\n%s\n",*numl,ligne); return (*numsec > 0 ? -1 : -2); } */
83 *numsec = result;
84 typesec = ligne[72];
85 switch (typesec) {
86 case 'S' : ligne[72] = '\0'; return (1);
87 case 'G' : ligne[72] = '\0'; return (2);
88 case 'D' : ligne[72] = '\0'; return (3);
89 case 'P' : ligne[72] = '\0'; return (4);
90 case 'T' : ligne[72] = '\0'; return (5);
91 default :; /* printf("Ligne incorrecte, ignoree n0.%d :\n%s\n",*numl,ligne); */
92 }
93 /* the column 72 is empty, try to check the neghbour*/
94 if(strlen(ligne)==80
95 && (ligne[79]=='\n' || ligne[79]=='\r') && (ligne[0]<='9' && ligne[0]>='0')) {
96 /*check if the case of losted .*/
97 int index;
98 for(index = 1; ligne[index]<='9' && ligne[index]>='0'; index++);
99 if (ligne[index]=='D' || ligne[index]=='d') {
100 for(index = 79; index > 0; index--)
101 ligne[index] = ligne[index-1];
102 ligne[0]='.';
103 }
104
105 typesec = ligne[72];
106 switch (typesec) {
107 case 'S' : ligne[72] = '\0'; return (1);
108 case 'G' : ligne[72] = '\0'; return (2);
109 case 'D' : ligne[72] = '\0'; return (3);
110 case 'P' : ligne[72] = '\0'; return (4);
111 case 'T' : ligne[72] = '\0'; return (5);
112 default :; /* printf("Ligne incorrecte, ignoree n0.%d :\n%s\n",*numl,ligne); */
113 }
114 }
115
116 return -1;
117}
118
119/* Pour commander la relecture sur place */
120
121void iges_arelire()
122{ iges_fautrelire = 1; }