0023024: Update headers of OCCT files
[occt.git] / src / StepFile / stepread.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 /* pdn PRO16162: do restart in order to restore after possible crash or wrong data
22 */ 
23 /*rln 10.01.99 - transmission of define's into this file
24 */ 
25 /**
26 */ 
27 # include <stdlib.h>
28 # include <stdio.h>
29 # include <string.h>
30 # include "recfile.ph"
31
32 /*    StepFile_Error.c
33
34       Ce programme substitue au yyerror standard, qui fait "exit" (brutal !)
35       une action plus adaptee a un fonctionnement en process :
36
37       Affichage de la ligne qui a provoque l' erreur,
38       Preparation d'un eventuel appel suivant (vu qu on ne fait plus exit),
39       en pour le retour, on s'arrange pour lever une exception
40       (c-a-d qu on provoque un plantage)
41
42       Adaptation pour flex (flex autorise d avoir plusieurs lex dans un meme
43       executable) : les fonctions et variables sont renommees; et la
44       continuation a change
45 */
46
47 static int   lastno;
48 extern int   steplineno;
49
50 extern void StepFile_Interrupt (char* nomfic); /* rln 13.09.00 port on HP*/
51 int stepparse(void);
52 void  rec_debfile();
53 void steprestart(FILE *input_file);
54 void rec_finfile();
55
56 void steperror (char *mess)
57 {
58   char newmess[80];
59   if (steplineno == lastno) return;
60   lastno = steplineno;
61   sprintf    (newmess,"At line %d, %s",steplineno+1,mess);
62
63 /*  yysbuf[0] = '\0';
64     yysptr    = yysbuf;
65  *  yylineno  = 0;  */
66
67   StepFile_Interrupt(newmess);
68 }
69
70 /*   But de ce mini-programme : appeler yyparse et si besoin preciser un
71      fichier d'entree
72      StepFile_Error  redefinit yyerror pour ne pas stopper (s'y reporter)
73 */
74
75 extern FILE* stepin ;  /*  input de yyparse (executeur de lex-yacc)  */
76 extern int   steplineno;  /*  compteur de ligne lex  (pour erreurs)  */
77
78
79 /*   Designation d'un fichier de lecture
80     (par defaut, c'est l'entree standard)
81
82     Appel :  iflag = stepread_setinput ("...") ou (char[] ...) ;
83                      stepread_setinput ("") [longueur nulle] laisse en standard
84      iflag retourne vaut 0 si c'est OK, 1 sinon
85 */
86
87 FILE* stepread_setinput (char* nomfic)
88 {
89   FILE* newin ;
90   if (strlen(nomfic) == 0) return stepin ;
91   newin = fopen(nomfic,"r") ;
92   if (newin == NULL) {
93     return NULL ;
94   } else {
95     stepin = newin ; return newin ;
96   }
97 }
98
99 void stepread_endinput (FILE* infic, char* nomfic)
100 {
101   if (!infic) return;
102   if (strlen(nomfic) == 0) return;
103   fclose (infic);
104 }
105
106 /*  Lecture d'un fichier ia grammaire lex-yacc
107     Appel : i = stepread() ;  i est la valeur retournee par yyparse
108     (0 si OK, 1 si erreur)
109 */
110 int stepread ()
111 {
112   int letat;
113   lastno = 0;
114   steplineno = 0;
115   rec_debfile() ;
116   steprestart(stepin);
117   letat = stepparse() ;
118   rec_finfile() ;
119   return letat;
120 }
121
122 int stepwrap ()  {  return 1;  }